@lynx-js/motion-canary 0.0.0 → 0.0.2-canary-20260129-d02a6062
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/CHANGELOG.md +10 -0
- package/LICENSE +1 -1
- package/NOTICE +35 -0
- package/README.md +105 -0
- package/dist/animation/index.d.ts +48 -0
- package/dist/animation/index.js +65 -0
- package/dist/hooks/useMotionEvent.d.ts +10 -0
- package/dist/hooks/useMotionEvent.js +21 -0
- package/dist/hooks/useMotionValueRef.d.ts +7 -0
- package/dist/hooks/useMotionValueRef.js +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/mini/core/MotionValue.d.ts +29 -0
- package/dist/mini/core/MotionValue.js +73 -0
- package/dist/mini/core/animate.d.ts +22 -0
- package/dist/mini/core/animate.js +93 -0
- package/dist/mini/core/easings.d.ts +11 -0
- package/dist/mini/core/easings.js +71 -0
- package/dist/mini/core/spring.d.ts +2 -0
- package/dist/mini/core/spring.js +9 -0
- package/dist/mini/index.d.ts +16 -0
- package/dist/mini/index.js +13 -0
- package/dist/polyfill/MotionValue.d.ts +1 -0
- package/dist/polyfill/MotionValue.js +5 -0
- package/dist/polyfill/element.d.ts +50 -0
- package/dist/polyfill/element.js +138 -0
- package/dist/polyfill/shim.d.ts +1 -0
- package/dist/polyfill/shim.js +38 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/elementHelper.d.ts +3 -0
- package/dist/utils/elementHelper.js +18 -0
- package/dist/utils/isMainThreadElement.d.ts +3 -0
- package/dist/utils/isMainThreadElement.js +10 -0
- package/dist/utils/noop.d.ts +2 -0
- package/dist/utils/noop.js +5 -0
- package/dist/utils/registeredFunction.d.ts +5 -0
- package/dist/utils/registeredFunction.js +12 -0
- package/package.json +62 -4
- package/index.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @lynx-js/motion
|
|
2
|
+
|
|
3
|
+
## 0.0.2-canary-20260129083254-d02a60626d6cbad44bb9cffcb470c99ed0356649
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add initial support for `@lynx-js/motion` ([#1062](https://github.com/lynx-family/lynx-stack/pull/1062))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`35f520a`](https://github.com/lynx-family/lynx-stack/commit/35f520a560c4d498ab3617f63a600239602f371c), [`1fa1ddc`](https://github.com/lynx-family/lynx-stack/commit/1fa1ddc77447704d6865509a884aa71ea72cd56e)]:
|
|
10
|
+
- @lynx-js/react@0.116.2-canary-20260129083254-d02a60626d6cbad44bb9cffcb470c99ed0356649
|
package/LICENSE
CHANGED
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
same "printed page" as the copyright notice for easier
|
|
188
188
|
identification within third-party archives.
|
|
189
189
|
|
|
190
|
-
Copyright
|
|
190
|
+
Copyright 2025 The Lynx Authors.
|
|
191
191
|
|
|
192
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
193
|
you may not use this file except in compliance with the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Copyright 2025 The Lynx Authors. All rights reserved.
|
|
2
|
+
|
|
3
|
+
@lynx-js/motion
|
|
4
|
+
|
|
5
|
+
This product includes software developed by the Framer team and contributors.
|
|
6
|
+
|
|
7
|
+
The following packages are adapted or used:
|
|
8
|
+
- framer-motion (MIT License)
|
|
9
|
+
- motion-dom (MIT License)
|
|
10
|
+
- motion-utils (MIT License)
|
|
11
|
+
- motion-canvas (MIT License, where applicable)
|
|
12
|
+
|
|
13
|
+
--------------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
The MIT License (MIT)
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2018 Framer B.V.
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
in the Software without restriction, including without limitation the rights
|
|
22
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
furnished to do so, subject to the following conditions:
|
|
25
|
+
|
|
26
|
+
The above copyright notice and this permission notice shall be included in all
|
|
27
|
+
copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @lynx-js/motion
|
|
2
|
+
|
|
3
|
+
A powerful animation library for Lynx, ported from [Motion for React (framer-motion)](https://motion.dev/). It brings declarative animations and gesture handling to the Lynx ecosystem.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @lynx-js/motion
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Basic Animation
|
|
14
|
+
|
|
15
|
+
Currently, `@lynx-js/motion` supports imperative animations using the `animate` function on the main thread.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { animate } from '@lynx-js/motion';
|
|
19
|
+
import { useMainThreadRef, runOnMainThread, useEffect } from '@lynx-js/react';
|
|
20
|
+
import type { MainThread } from '@lynx-js/types';
|
|
21
|
+
|
|
22
|
+
export function MyComponent() {
|
|
23
|
+
const elementRef = useMainThreadRef<MainThread.Element>(null);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
runOnMainThread(() => {
|
|
27
|
+
'main thread';
|
|
28
|
+
if (elementRef.current) {
|
|
29
|
+
animate(
|
|
30
|
+
elementRef.current,
|
|
31
|
+
{ opacity: 1, x: 100 },
|
|
32
|
+
{ duration: 1 },
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<view
|
|
40
|
+
main-thread:ref={elementRef}
|
|
41
|
+
style={{ opacity: 0, width: 100, height: 100, backgroundColor: 'blue' }}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For more comprehensive examples, please refer to the [examples/motion](https://github.com/lynx-family/lynx-stack/tree/main/examples/motion) directory in this repository.
|
|
48
|
+
|
|
49
|
+
## Motion Mini (`@lynx-js/motion/mini`)
|
|
50
|
+
|
|
51
|
+
Motion Mini is a lightweight, **main-thread-optimized** version of the library. It provides a core subset of animation capabilities designed for high performance and low bundle size.
|
|
52
|
+
|
|
53
|
+
To use it, import from `@lynx-js/motion/mini`:
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { animate, createMotionValue } from '@lynx-js/motion/mini';
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Key Features
|
|
60
|
+
|
|
61
|
+
- **Main Thread Animation**: Runs directly on the main thread, bypassing the JS thread for smoother performance.
|
|
62
|
+
- **Small Bundle Size**: Includes only essential animation logic.
|
|
63
|
+
- **Optimized for Numbers**: Primarily designed for animating numeric values.
|
|
64
|
+
|
|
65
|
+
### Differences from Standard Motion
|
|
66
|
+
|
|
67
|
+
| Feature | Standard Motion | Motion Mini |
|
|
68
|
+
| :-------------------- | :------------------------------------------------ | :------------------------ |
|
|
69
|
+
| **Animation Targets** | Numbers, Strings (colors, units), Objects, Arrays | **Numbers only** (mostly) |
|
|
70
|
+
| **Keyframes** | Full support | Limited support |
|
|
71
|
+
| **Layout Animations** | Supported | Not supported |
|
|
72
|
+
| **Gesture Handlers** | Full suite (drag, pan, hover, etc.) | Not included |
|
|
73
|
+
|
|
74
|
+
> **Note**: `MotionValue` in Mini primarily works with numbers.
|
|
75
|
+
|
|
76
|
+
### CLI Reference for Mini
|
|
77
|
+
|
|
78
|
+
#### `createMotionValue<T>(initial: T)`
|
|
79
|
+
|
|
80
|
+
Creates a `MotionValue` that tracks state and velocity.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const mv = createMotionValue(0);
|
|
84
|
+
mv.set(100);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### `animate(value, target, options)`
|
|
88
|
+
|
|
89
|
+
Animates a `MotionValue` or number.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
animate(mv, 100, {
|
|
93
|
+
type: 'spring',
|
|
94
|
+
stiffness: 300,
|
|
95
|
+
damping: 30,
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## License & Attribution
|
|
100
|
+
|
|
101
|
+
This package is licensed under the Apache-2.0 License.
|
|
102
|
+
|
|
103
|
+
It adapts code from [Motion for React (framer-motion)](https://motion.dev/), [motion-dom](https://github.com/motiondivision/motion/tree/main/packages/motion-dom), and [motion-utils](https://github.com/motiondivision/motion/tree/main/packages/motion-utils) which are licensed under the MIT License.
|
|
104
|
+
|
|
105
|
+
See [LICENSE](./LICENSE), [NOTICE](./NOTICE) for details.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import '../polyfill/shim.js';
|
|
2
|
+
import { stagger as stagger_ } from 'framer-motion/dom';
|
|
3
|
+
import type { AnimationSequence, ObjectTarget, SequenceOptions } from 'framer-motion/dom';
|
|
4
|
+
import { spring as spring_ } from 'motion-dom';
|
|
5
|
+
import type { AnimationOptions, AnimationPlaybackControlsWithThen, AnyResolvedKeyframe, DOMKeyframesDefinition, MapInputRange, Mixer, MotionValue, MotionValueOptions, SpringOptions, TransformOptions, UnresolvedValueKeyframe, ValueAnimationTransition } from 'motion-dom';
|
|
6
|
+
import { useMotionValueRefEvent } from '../hooks/useMotionEvent.js';
|
|
7
|
+
import type { ElementOrElements } from '../types/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Animate a sequence
|
|
10
|
+
*/
|
|
11
|
+
declare function animate(sequence: AnimationSequence, options?: SequenceOptions): AnimationPlaybackControlsWithThen;
|
|
12
|
+
/**
|
|
13
|
+
* Animate a string
|
|
14
|
+
*/
|
|
15
|
+
declare function animate(value: string, keyframes: DOMKeyframesDefinition, options?: AnimationOptions): AnimationPlaybackControlsWithThen;
|
|
16
|
+
/**
|
|
17
|
+
* Animate a string
|
|
18
|
+
*/
|
|
19
|
+
declare function animate(value: string | MotionValue<string>, keyframes: string | UnresolvedValueKeyframe<string>[], options?: ValueAnimationTransition<string>): AnimationPlaybackControlsWithThen;
|
|
20
|
+
/**
|
|
21
|
+
* Animate a number
|
|
22
|
+
*/
|
|
23
|
+
declare function animate(value: number | MotionValue<number>, keyframes: number | UnresolvedValueKeyframe<number>[], options?: ValueAnimationTransition<number>): AnimationPlaybackControlsWithThen;
|
|
24
|
+
/**
|
|
25
|
+
* Animate a generic motion value
|
|
26
|
+
*/
|
|
27
|
+
declare function animate<V extends string | number>(value: V | MotionValue<V>, keyframes: V | UnresolvedValueKeyframe<V>[], options?: ValueAnimationTransition<V>): AnimationPlaybackControlsWithThen;
|
|
28
|
+
/**
|
|
29
|
+
* Animate an object
|
|
30
|
+
*/
|
|
31
|
+
declare function animate<O extends {}>(object: O | O[], keyframes: ObjectTarget<O>, options?: AnimationOptions): AnimationPlaybackControlsWithThen;
|
|
32
|
+
/**
|
|
33
|
+
* Animate a main thread element
|
|
34
|
+
*/
|
|
35
|
+
declare function animate(value: ElementOrElements, keyframes: DOMKeyframesDefinition, options?: AnimationOptions): AnimationPlaybackControlsWithThen;
|
|
36
|
+
declare function stagger(...args: Parameters<typeof stagger_>): ReturnType<typeof stagger_>;
|
|
37
|
+
declare function motionValue<V>(init: V, options?: MotionValueOptions): MotionValue<V>;
|
|
38
|
+
declare function spring(...args: Parameters<typeof spring_>): ReturnType<typeof spring_>;
|
|
39
|
+
declare function springValue<T extends AnyResolvedKeyframe>(source: T | MotionValue<T>, options?: SpringOptions): MotionValue<T>;
|
|
40
|
+
declare function mix<T>(from: T, to: T): Mixer<T>;
|
|
41
|
+
declare function mix(from: number, to: number, p: number): number;
|
|
42
|
+
declare function progress(from: number, to: number, value: number): number;
|
|
43
|
+
declare function clamp(min: number, max: number, v: number): number;
|
|
44
|
+
declare function mapValue<O>(inputValue: MotionValue<number>, inputRange: MapInputRange, outputRange: O[], options?: TransformOptions<O>): MotionValue<O>;
|
|
45
|
+
declare function transformValue<O>(transform: () => O): MotionValue<O>;
|
|
46
|
+
declare function styleEffect(subject: string | ElementOrElements, values: Record<string, MotionValue>): () => void;
|
|
47
|
+
export { animate, stagger, motionValue, spring, springValue, mix, progress, mapValue, clamp, transformValue, styleEffect, };
|
|
48
|
+
export { useMotionValueRefEvent };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import "../polyfill/shim.js";
|
|
2
|
+
import { animate, clamp, progress, stagger } from "framer-motion/dom" with {
|
|
3
|
+
runtime: "shared"
|
|
4
|
+
};
|
|
5
|
+
import { mapValue, mix, spring, springValue, styleEffect, transformValue } from "motion-dom" with {
|
|
6
|
+
runtime: "shared"
|
|
7
|
+
};
|
|
8
|
+
import { useMotionValueRefEvent } from "../hooks/useMotionEvent.js";
|
|
9
|
+
import { motionValue } from "../polyfill/MotionValue.js" with {
|
|
10
|
+
runtime: "shared"
|
|
11
|
+
};
|
|
12
|
+
import { elementOrSelector2Dom } from "../utils/elementHelper.js";
|
|
13
|
+
import { noopMT } from "../utils/noop.js";
|
|
14
|
+
function animation_animate(subjectOrSequence, optionsOrKeyframes, options) {
|
|
15
|
+
'main thread';
|
|
16
|
+
const isStringSubject = 'string' == typeof subjectOrSequence;
|
|
17
|
+
const isKeyframesObject = 'object' == typeof optionsOrKeyframes && null !== optionsOrKeyframes && !Array.isArray(optionsOrKeyframes);
|
|
18
|
+
const isKeyframesArray = Array.isArray(optionsOrKeyframes) && optionsOrKeyframes.every((k)=>'object' == typeof k && null !== k && !Array.isArray(k));
|
|
19
|
+
let realSubjectOrSequence = subjectOrSequence;
|
|
20
|
+
if (!isStringSubject || isKeyframesObject || isKeyframesArray) realSubjectOrSequence = elementOrSelector2Dom(subjectOrSequence) ?? subjectOrSequence;
|
|
21
|
+
return animate(realSubjectOrSequence, optionsOrKeyframes, options);
|
|
22
|
+
}
|
|
23
|
+
function animation_stagger(...args) {
|
|
24
|
+
'main thread';
|
|
25
|
+
return stagger(...args);
|
|
26
|
+
}
|
|
27
|
+
function animation_motionValue(init, options) {
|
|
28
|
+
'main thread';
|
|
29
|
+
return motionValue(init, options);
|
|
30
|
+
}
|
|
31
|
+
function animation_spring(...args) {
|
|
32
|
+
'main thread';
|
|
33
|
+
return spring(...args);
|
|
34
|
+
}
|
|
35
|
+
function animation_springValue(source, options) {
|
|
36
|
+
'main thread';
|
|
37
|
+
return springValue(source, options);
|
|
38
|
+
}
|
|
39
|
+
function animation_mix(from, to, p) {
|
|
40
|
+
'main thread';
|
|
41
|
+
return mix(from, to, p);
|
|
42
|
+
}
|
|
43
|
+
function animation_progress(from, to, value) {
|
|
44
|
+
'main thread';
|
|
45
|
+
return progress(from, to, value);
|
|
46
|
+
}
|
|
47
|
+
function animation_clamp(min, max, v) {
|
|
48
|
+
'main thread';
|
|
49
|
+
return clamp(min, max, v);
|
|
50
|
+
}
|
|
51
|
+
function animation_mapValue(inputValue, inputRange, outputRange, options) {
|
|
52
|
+
'main thread';
|
|
53
|
+
return mapValue(inputValue, inputRange, outputRange, options);
|
|
54
|
+
}
|
|
55
|
+
function animation_transformValue(transform) {
|
|
56
|
+
'main thread';
|
|
57
|
+
return transformValue(transform);
|
|
58
|
+
}
|
|
59
|
+
function animation_styleEffect(subject, values) {
|
|
60
|
+
'main thread';
|
|
61
|
+
const elements = elementOrSelector2Dom(subject);
|
|
62
|
+
if (!elements) return noopMT;
|
|
63
|
+
return styleEffect(elements, values);
|
|
64
|
+
}
|
|
65
|
+
export { animation_animate as animate, animation_clamp as clamp, animation_mapValue as mapValue, animation_mix as mix, animation_motionValue as motionValue, animation_progress as progress, animation_spring as spring, animation_springValue as springValue, animation_stagger as stagger, animation_styleEffect as styleEffect, animation_transformValue as transformValue, useMotionValueRefEvent };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MotionValueEventCallbacks } from 'motion-dom';
|
|
2
|
+
import type { MainThreadRef } from '@lynx-js/react';
|
|
3
|
+
interface Listenable<V> {
|
|
4
|
+
on(event: 'change', callback: (v: V) => void): () => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @experimental useMotionValueEvent, but only accepts motionValueRef format, highly experimental, subject to change
|
|
8
|
+
*/
|
|
9
|
+
export declare function useMotionValueRefEvent<V, EventName extends keyof MotionValueEventCallbacks<V>>(valueRef: MainThreadRef<Listenable<V>>, event: 'change', callback: MotionValueEventCallbacks<V>[EventName]): void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { runOnMainThread, useEffect, useMainThreadRef } from "@lynx-js/react";
|
|
2
|
+
function useMotionValueRefEvent(valueRef, event, callback) {
|
|
3
|
+
const unListenRef = useMainThreadRef();
|
|
4
|
+
useEffect(()=>{
|
|
5
|
+
runOnMainThread(()=>{
|
|
6
|
+
'main thread';
|
|
7
|
+
unListenRef.current = valueRef.current.on(event, callback);
|
|
8
|
+
})();
|
|
9
|
+
return ()=>{
|
|
10
|
+
runOnMainThread(()=>{
|
|
11
|
+
'main thread';
|
|
12
|
+
unListenRef.current?.();
|
|
13
|
+
})();
|
|
14
|
+
};
|
|
15
|
+
}, [
|
|
16
|
+
valueRef,
|
|
17
|
+
event,
|
|
18
|
+
callback
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
export { useMotionValueRefEvent };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MotionValue } from 'motion-dom';
|
|
2
|
+
import type { MainThreadRef } from '@lynx-js/react';
|
|
3
|
+
export declare function useMotionValueRefCore<T, MV>(value: T, make: (v: T) => MV): MainThreadRef<MV>;
|
|
4
|
+
/**
|
|
5
|
+
* @experimental useMotionValue, but in MainThreadRef format, highly experimental, subject to change
|
|
6
|
+
*/
|
|
7
|
+
export declare function useMotionValueRef<T>(value: T): MainThreadRef<MotionValue<T>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { runOnMainThread, useMainThreadRef, useMemo } from "@lynx-js/react";
|
|
2
|
+
import { runWorkletCtx } from "@lynx-js/react/worklet-runtime/bindings";
|
|
3
|
+
import { motionValue } from "../animation/index.js";
|
|
4
|
+
function useMotionValueRefCore(value, make) {
|
|
5
|
+
const motionValueRef = useMainThreadRef();
|
|
6
|
+
useMemo(()=>{
|
|
7
|
+
function setMotionValue(value) {
|
|
8
|
+
'main thread';
|
|
9
|
+
if (!motionValueRef.current) motionValueRef.current = make(value);
|
|
10
|
+
}
|
|
11
|
+
if (__BACKGROUND__) runOnMainThread(setMotionValue)(value);
|
|
12
|
+
else runWorkletCtx(setMotionValue, [
|
|
13
|
+
value
|
|
14
|
+
]);
|
|
15
|
+
}, []);
|
|
16
|
+
return motionValueRef;
|
|
17
|
+
}
|
|
18
|
+
function useMotionValueRef(value) {
|
|
19
|
+
return useMotionValueRefCore(value, motionValue);
|
|
20
|
+
}
|
|
21
|
+
export { useMotionValueRef, useMotionValueRefCore };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { animate, stagger, motionValue, spring, springValue, mix, progress, mapValue, clamp, transformValue, styleEffect, useMotionValueRefEvent, } from './animation/index.js';
|
|
2
|
+
export { useMotionValueRef } from './hooks/useMotionValueRef.js';
|
|
3
|
+
export type { MotionValue } from 'motion-dom';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { animate, clamp, mapValue, mix, motionValue, progress, spring, springValue, stagger, styleEffect, transformValue, useMotionValueRefEvent } from "./animation/index.js";
|
|
2
|
+
import { useMotionValueRef } from "./hooks/useMotionValueRef.js";
|
|
3
|
+
export { animate, clamp, mapValue, mix, motionValue, progress, spring, springValue, stagger, styleEffect, transformValue, useMotionValueRef, useMotionValueRefEvent };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface MotionValue<T> {
|
|
2
|
+
get(): T;
|
|
3
|
+
set(v: T): void;
|
|
4
|
+
getVelocity(): number;
|
|
5
|
+
jump(v: T): void;
|
|
6
|
+
onChange(callback: (v: T) => void): () => void;
|
|
7
|
+
on(event: 'change', callback: (v: T) => void): () => void;
|
|
8
|
+
/**
|
|
9
|
+
* Internal method to update velocity, usually called by the animation loop.
|
|
10
|
+
*/
|
|
11
|
+
updateVelocity(v: number): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Check if this MotionValue is currently animating.
|
|
15
|
+
*/
|
|
16
|
+
isAnimating(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Clear all change listeners.
|
|
19
|
+
*/
|
|
20
|
+
clearListeners(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Destroy this MotionValue, stopping all animations and clearing all listeners.
|
|
23
|
+
*/
|
|
24
|
+
destroy(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function createMotionValue<T>(initial: T): MotionValue<T>;
|
|
27
|
+
export interface MotionValueEventCallbacks<V> {
|
|
28
|
+
change: (v: V) => void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
function createMotionValue(initial) {
|
|
2
|
+
'main thread';
|
|
3
|
+
class MotionValueImpl {
|
|
4
|
+
v;
|
|
5
|
+
velocity = 0;
|
|
6
|
+
listeners = new Set();
|
|
7
|
+
activeAnimations = new Set();
|
|
8
|
+
lastUpdated = 0;
|
|
9
|
+
constructor(initial){
|
|
10
|
+
this.v = initial;
|
|
11
|
+
}
|
|
12
|
+
get() {
|
|
13
|
+
return this.v;
|
|
14
|
+
}
|
|
15
|
+
set(v) {
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
if ('number' == typeof v && 'number' == typeof this.v) {
|
|
18
|
+
const delta = v - this.v;
|
|
19
|
+
const timeDelta = (now - this.lastUpdated) / 1000;
|
|
20
|
+
if (timeDelta > 0) this.velocity = delta / timeDelta;
|
|
21
|
+
}
|
|
22
|
+
this.lastUpdated = now;
|
|
23
|
+
this.v = v;
|
|
24
|
+
this.notify();
|
|
25
|
+
}
|
|
26
|
+
updateVelocity(v) {
|
|
27
|
+
this.velocity = v;
|
|
28
|
+
}
|
|
29
|
+
getVelocity() {
|
|
30
|
+
return this.velocity;
|
|
31
|
+
}
|
|
32
|
+
jump(v) {
|
|
33
|
+
this.v = v;
|
|
34
|
+
this.velocity = 0;
|
|
35
|
+
this.lastUpdated = Date.now();
|
|
36
|
+
this.notify();
|
|
37
|
+
}
|
|
38
|
+
onChange(callback) {
|
|
39
|
+
this.listeners.add(callback);
|
|
40
|
+
return ()=>this.listeners.delete(callback);
|
|
41
|
+
}
|
|
42
|
+
on(event, callback) {
|
|
43
|
+
if ('change' === event) return this.onChange(callback);
|
|
44
|
+
throw new Error("mini animate() does not support event type other than 'change'");
|
|
45
|
+
}
|
|
46
|
+
notify() {
|
|
47
|
+
for (const cb of this.listeners)cb(this.v);
|
|
48
|
+
}
|
|
49
|
+
attach(cancel) {
|
|
50
|
+
this.activeAnimations.add(cancel);
|
|
51
|
+
return ()=>this.activeAnimations.delete(cancel);
|
|
52
|
+
}
|
|
53
|
+
stop() {
|
|
54
|
+
for (const cancel of this.activeAnimations)cancel();
|
|
55
|
+
this.activeAnimations.clear();
|
|
56
|
+
}
|
|
57
|
+
isAnimating() {
|
|
58
|
+
return this.activeAnimations.size > 0;
|
|
59
|
+
}
|
|
60
|
+
clearListeners() {
|
|
61
|
+
this.listeners.clear();
|
|
62
|
+
}
|
|
63
|
+
destroy() {
|
|
64
|
+
this.stop();
|
|
65
|
+
this.clearListeners();
|
|
66
|
+
}
|
|
67
|
+
toJSON() {
|
|
68
|
+
return String(this.v);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return new MotionValueImpl(initial);
|
|
72
|
+
}
|
|
73
|
+
export { createMotionValue };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, easeIn, easeInOut, easeOut, linear } from './easings.js';
|
|
2
|
+
import type { MotionValue } from './MotionValue.js';
|
|
3
|
+
export type Easing = (t: number) => number;
|
|
4
|
+
export interface AnimationOptions {
|
|
5
|
+
type?: 'spring' | 'keyframes' | 'decay';
|
|
6
|
+
stiffness?: number;
|
|
7
|
+
damping?: number;
|
|
8
|
+
mass?: number;
|
|
9
|
+
duration?: number;
|
|
10
|
+
ease?: Easing;
|
|
11
|
+
from?: number;
|
|
12
|
+
to?: number;
|
|
13
|
+
velocity?: number;
|
|
14
|
+
onUpdate?: (v: number) => void;
|
|
15
|
+
onComplete?: () => void;
|
|
16
|
+
}
|
|
17
|
+
export { anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, easeIn, easeInOut, easeOut, linear, };
|
|
18
|
+
export declare function animate(value: MotionValue<number> | number | ((v: number) => void), target: number, options?: AnimationOptions): {
|
|
19
|
+
stop: () => void;
|
|
20
|
+
then: (cb: () => void) => Promise<void>;
|
|
21
|
+
onFinish: () => void;
|
|
22
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, easeIn, easeInOut, easeOut, linear } from "./easings.js";
|
|
2
|
+
import { spring } from "./spring.js";
|
|
3
|
+
function animate(value, target, options = {}) {
|
|
4
|
+
'main thread';
|
|
5
|
+
let currentV = 0;
|
|
6
|
+
let startVelocity = options.velocity ?? 0;
|
|
7
|
+
if ('number' == typeof value) currentV = value;
|
|
8
|
+
else if ('function' == typeof value) currentV = options.from ?? 0;
|
|
9
|
+
else {
|
|
10
|
+
currentV = value.get();
|
|
11
|
+
if (null == options.velocity) startVelocity = value.getVelocity();
|
|
12
|
+
if (value.stop) value.stop();
|
|
13
|
+
}
|
|
14
|
+
if ('decay' === options.type || 'keyframes' === options.type) throw new Error('mini animate() does not support type=decay/keyframes yet');
|
|
15
|
+
const isSpring = 'spring' === options.type || !options.ease && !options.duration && null == options.type;
|
|
16
|
+
const { from: _from, to: _to, ...springOptions } = options;
|
|
17
|
+
const solver = isSpring ? spring({
|
|
18
|
+
...springOptions,
|
|
19
|
+
keyframes: [
|
|
20
|
+
currentV,
|
|
21
|
+
target
|
|
22
|
+
],
|
|
23
|
+
velocity: startVelocity
|
|
24
|
+
}) : null;
|
|
25
|
+
const startTime = Date.now();
|
|
26
|
+
let canceled = false;
|
|
27
|
+
let resolvePromise;
|
|
28
|
+
let settled = false;
|
|
29
|
+
const completionPromise = new Promise((resolve)=>{
|
|
30
|
+
resolvePromise = resolve;
|
|
31
|
+
});
|
|
32
|
+
const settle = ()=>{
|
|
33
|
+
if (settled) return;
|
|
34
|
+
settled = true;
|
|
35
|
+
controls.onFinish();
|
|
36
|
+
resolvePromise?.();
|
|
37
|
+
};
|
|
38
|
+
let detach;
|
|
39
|
+
const controls = {
|
|
40
|
+
stop: ()=>{
|
|
41
|
+
canceled = true;
|
|
42
|
+
detach?.();
|
|
43
|
+
settle();
|
|
44
|
+
},
|
|
45
|
+
then: (cb)=>{
|
|
46
|
+
controls.onFinish = cb;
|
|
47
|
+
if (settled) cb();
|
|
48
|
+
return completionPromise;
|
|
49
|
+
},
|
|
50
|
+
onFinish: ()=>{}
|
|
51
|
+
};
|
|
52
|
+
const duration = options.duration ?? 0.3;
|
|
53
|
+
const ease = options.ease ?? easeOut;
|
|
54
|
+
if ('object' == typeof value && value && 'attach' in value && 'function' == typeof value.attach) detach = value.attach(controls.stop);
|
|
55
|
+
const tick = ()=>{
|
|
56
|
+
if (canceled) return;
|
|
57
|
+
const now = Date.now();
|
|
58
|
+
const elapsed = (now - startTime) / 1000;
|
|
59
|
+
const elapsedMs = now - startTime;
|
|
60
|
+
let finished = false;
|
|
61
|
+
let current = 0;
|
|
62
|
+
if (isSpring && solver) {
|
|
63
|
+
const state = solver.next(elapsedMs);
|
|
64
|
+
current = state.value;
|
|
65
|
+
finished = state.done;
|
|
66
|
+
} else if (elapsed >= duration) {
|
|
67
|
+
finished = true;
|
|
68
|
+
current = target;
|
|
69
|
+
} else {
|
|
70
|
+
const p = elapsed / duration;
|
|
71
|
+
const eased = ease(p);
|
|
72
|
+
current = currentV + (target - currentV) * eased;
|
|
73
|
+
}
|
|
74
|
+
if ('function' == typeof value) value(current);
|
|
75
|
+
else if ('object' == typeof value && value.set) value.set(current);
|
|
76
|
+
if (options.onUpdate) options.onUpdate(current);
|
|
77
|
+
if (finished) {
|
|
78
|
+
if (!isSpring) {
|
|
79
|
+
if ('function' == typeof value) value(target);
|
|
80
|
+
else if ('object' == typeof value && value.set) {
|
|
81
|
+
value.set(target);
|
|
82
|
+
value.updateVelocity(0);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (options.onComplete) options.onComplete();
|
|
86
|
+
settle();
|
|
87
|
+
detach?.();
|
|
88
|
+
} else requestAnimationFrame(tick);
|
|
89
|
+
};
|
|
90
|
+
requestAnimationFrame(tick);
|
|
91
|
+
return controls;
|
|
92
|
+
}
|
|
93
|
+
export { animate, anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, easeIn, easeInOut, easeOut, linear };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function anticipate(t: number): number;
|
|
2
|
+
export declare function backIn(t: number): number;
|
|
3
|
+
export declare function backInOut(t: number): number;
|
|
4
|
+
export declare function backOut(t: number): number;
|
|
5
|
+
export declare function circIn(t: number): number;
|
|
6
|
+
export declare function circInOut(t: number): number;
|
|
7
|
+
export declare function circOut(t: number): number;
|
|
8
|
+
export declare function easeIn(t: number): number;
|
|
9
|
+
export declare function easeInOut(t: number): number;
|
|
10
|
+
export declare function easeOut(t: number): number;
|
|
11
|
+
export declare function linear(t: number): number;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, easeIn, easeInOut, easeOut, noop } from "motion-utils";
|
|
2
|
+
import { registerCallable } from "../../utils/registeredFunction.js";
|
|
3
|
+
let anticipateHandle = 'anticipateHandle';
|
|
4
|
+
let backInHandle = 'backInHandle';
|
|
5
|
+
let backInOutHandle = 'backInOutHandle';
|
|
6
|
+
let backOutHandle = 'backOutHandle';
|
|
7
|
+
let circInHandle = 'circInHandle';
|
|
8
|
+
let circInOutHandle = 'circInOutHandle';
|
|
9
|
+
let circOutHandle = 'circOutHandle';
|
|
10
|
+
let easeInHandle = 'easeInHandle';
|
|
11
|
+
let easeInOutHandle = 'easeInOutHandle';
|
|
12
|
+
let easeOutHandle = 'easeOutHandle';
|
|
13
|
+
let linearHandle = 'linearHandle';
|
|
14
|
+
if (__MAIN_THREAD__) {
|
|
15
|
+
anticipateHandle = registerCallable(anticipate, 'anticipateHandle');
|
|
16
|
+
backInHandle = registerCallable(backIn, 'backInHandle');
|
|
17
|
+
backInOutHandle = registerCallable(backInOut, 'backInOutHandle');
|
|
18
|
+
backOutHandle = registerCallable(backOut, 'backOutHandle');
|
|
19
|
+
circInHandle = registerCallable(circIn, 'circInHandle');
|
|
20
|
+
circInOutHandle = registerCallable(circInOut, 'circInOutHandle');
|
|
21
|
+
circOutHandle = registerCallable(circOut, 'circOutHandle');
|
|
22
|
+
easeInHandle = registerCallable(easeIn, 'easeInHandle');
|
|
23
|
+
easeInOutHandle = registerCallable(easeInOut, 'easeInOutHandle');
|
|
24
|
+
easeOutHandle = registerCallable(easeOut, 'easeOutHandle');
|
|
25
|
+
linearHandle = registerCallable(noop, 'linearHandle');
|
|
26
|
+
}
|
|
27
|
+
function easings_anticipate(t) {
|
|
28
|
+
'main thread';
|
|
29
|
+
return globalThis.runOnRegistered(anticipateHandle)(t);
|
|
30
|
+
}
|
|
31
|
+
function easings_backIn(t) {
|
|
32
|
+
'main thread';
|
|
33
|
+
return globalThis.runOnRegistered(backInHandle)(t);
|
|
34
|
+
}
|
|
35
|
+
function easings_backInOut(t) {
|
|
36
|
+
'main thread';
|
|
37
|
+
return globalThis.runOnRegistered(backInOutHandle)(t);
|
|
38
|
+
}
|
|
39
|
+
function easings_backOut(t) {
|
|
40
|
+
'main thread';
|
|
41
|
+
return globalThis.runOnRegistered(backOutHandle)(t);
|
|
42
|
+
}
|
|
43
|
+
function easings_circIn(t) {
|
|
44
|
+
'main thread';
|
|
45
|
+
return globalThis.runOnRegistered(circInHandle)(t);
|
|
46
|
+
}
|
|
47
|
+
function easings_circInOut(t) {
|
|
48
|
+
'main thread';
|
|
49
|
+
return globalThis.runOnRegistered(circInOutHandle)(t);
|
|
50
|
+
}
|
|
51
|
+
function easings_circOut(t) {
|
|
52
|
+
'main thread';
|
|
53
|
+
return globalThis.runOnRegistered(circOutHandle)(t);
|
|
54
|
+
}
|
|
55
|
+
function easings_easeIn(t) {
|
|
56
|
+
'main thread';
|
|
57
|
+
return globalThis.runOnRegistered(easeInHandle)(t);
|
|
58
|
+
}
|
|
59
|
+
function easings_easeInOut(t) {
|
|
60
|
+
'main thread';
|
|
61
|
+
return globalThis.runOnRegistered(easeInOutHandle)(t);
|
|
62
|
+
}
|
|
63
|
+
function easings_easeOut(t) {
|
|
64
|
+
'main thread';
|
|
65
|
+
return globalThis.runOnRegistered(easeOutHandle)(t);
|
|
66
|
+
}
|
|
67
|
+
function linear(t) {
|
|
68
|
+
'main thread';
|
|
69
|
+
return globalThis.runOnRegistered(linearHandle)(t);
|
|
70
|
+
}
|
|
71
|
+
export { easings_anticipate as anticipate, easings_backIn as backIn, easings_backInOut as backInOut, easings_backOut as backOut, easings_circIn as circIn, easings_circInOut as circInOut, easings_circOut as circOut, easings_easeIn as easeIn, easings_easeInOut as easeInOut, easings_easeOut as easeOut, linear };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { spring } from "motion-dom";
|
|
2
|
+
import { registerCallable } from "../../utils/registeredFunction.js";
|
|
3
|
+
let springHandle = 'springHandle';
|
|
4
|
+
if (__MAIN_THREAD__) springHandle = registerCallable(spring, 'springHandle');
|
|
5
|
+
function spring_spring(...args) {
|
|
6
|
+
'main thread';
|
|
7
|
+
return globalThis.runOnRegistered(springHandle)(...args);
|
|
8
|
+
}
|
|
9
|
+
export { spring_spring as spring };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MainThreadRef } from '@lynx-js/react';
|
|
2
|
+
import '../polyfill/shim.js';
|
|
3
|
+
import type { MotionValue, MotionValueEventCallbacks } from './core/MotionValue.js';
|
|
4
|
+
export { animate, anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, easeIn, easeInOut, easeOut, linear, } from './core/animate.js';
|
|
5
|
+
export type { AnimationOptions, Easing } from './core/animate.js';
|
|
6
|
+
export { createMotionValue } from './core/MotionValue.js';
|
|
7
|
+
export type { MotionValue, MotionValueEventCallbacks, } from './core/MotionValue.js';
|
|
8
|
+
export { spring } from './core/spring.js';
|
|
9
|
+
/**
|
|
10
|
+
* @experimental useMotionValue, but in MainThreadRef format, highly experimental, subject to change
|
|
11
|
+
*/
|
|
12
|
+
export declare function useMotionValueRef<T>(value: T): MainThreadRef<MotionValue<T>>;
|
|
13
|
+
/**
|
|
14
|
+
* @experimental useMotionValueEvent, but only accepts motionValueRef format, highly experimental, subject to change
|
|
15
|
+
*/
|
|
16
|
+
export declare function useMotionValueRefEvent<V, EventName extends keyof MotionValueEventCallbacks<V>>(valueRef: MainThreadRef<MotionValue<V>>, event: 'change', callback: MotionValueEventCallbacks<V>[EventName]): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "../polyfill/shim.js";
|
|
2
|
+
import { useMotionValueRefEvent } from "../hooks/useMotionEvent.js";
|
|
3
|
+
import { useMotionValueRefCore } from "../hooks/useMotionValueRef.js";
|
|
4
|
+
import { createMotionValue } from "./core/MotionValue.js";
|
|
5
|
+
import { animate, anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, easeIn, easeInOut, easeOut, linear } from "./core/animate.js";
|
|
6
|
+
import { spring } from "./core/spring.js";
|
|
7
|
+
function useMotionValueRef(value) {
|
|
8
|
+
return useMotionValueRefCore(value, createMotionValue);
|
|
9
|
+
}
|
|
10
|
+
function mini_useMotionValueRefEvent(valueRef, event, callback) {
|
|
11
|
+
return useMotionValueRefEvent(valueRef, event, callback);
|
|
12
|
+
}
|
|
13
|
+
export { animate, anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, createMotionValue, easeIn, easeInOut, easeOut, linear, spring, useMotionValueRef, mini_useMotionValueRefEvent as useMotionValueRefEvent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { motionValue } from 'motion-dom';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { MainThread } from '@lynx-js/types';
|
|
2
|
+
interface StyleObject {
|
|
3
|
+
[key: string]: string | ((property: string, value: string) => void);
|
|
4
|
+
setProperty(property: string, value: string): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class ElementCompt {
|
|
7
|
+
private element;
|
|
8
|
+
constructor(element: MainThread.Element);
|
|
9
|
+
getComputedStyle(): Record<string, string>;
|
|
10
|
+
get style(): StyleObject;
|
|
11
|
+
set style(styles: Record<string, string>);
|
|
12
|
+
private getStyleProperty;
|
|
13
|
+
get backgroundColor(): string;
|
|
14
|
+
set backgroundColor(value: string);
|
|
15
|
+
get color(): string;
|
|
16
|
+
set color(value: string);
|
|
17
|
+
get fontSize(): string;
|
|
18
|
+
set fontSize(value: string);
|
|
19
|
+
get width(): string;
|
|
20
|
+
set width(value: string);
|
|
21
|
+
get height(): string;
|
|
22
|
+
set height(value: string);
|
|
23
|
+
get margin(): string;
|
|
24
|
+
set margin(value: string);
|
|
25
|
+
get padding(): string;
|
|
26
|
+
set padding(value: string);
|
|
27
|
+
get display(): string;
|
|
28
|
+
set display(value: string);
|
|
29
|
+
get position(): string;
|
|
30
|
+
set position(value: string);
|
|
31
|
+
get top(): string;
|
|
32
|
+
set top(value: string);
|
|
33
|
+
get left(): string;
|
|
34
|
+
set left(value: string);
|
|
35
|
+
get right(): string;
|
|
36
|
+
set right(value: string);
|
|
37
|
+
get bottom(): string;
|
|
38
|
+
set bottom(value: string);
|
|
39
|
+
getBoundingClientRect(): {
|
|
40
|
+
left: number;
|
|
41
|
+
top: number;
|
|
42
|
+
right: number;
|
|
43
|
+
bottom: number;
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
class ElementCompt {
|
|
2
|
+
element;
|
|
3
|
+
constructor(element){
|
|
4
|
+
this.element = element;
|
|
5
|
+
}
|
|
6
|
+
getComputedStyle() {
|
|
7
|
+
const styleObject = {};
|
|
8
|
+
return new Proxy(styleObject, {
|
|
9
|
+
get: (_target, prop)=>__GetComputedStyleByKey(this.element.element, prop)
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
get style() {
|
|
13
|
+
const styleObject = {};
|
|
14
|
+
styleObject.setProperty = (property, value)=>{
|
|
15
|
+
if ('transform' === property && 'none' === value) return this.element.setStyleProperty('transform', 'scale(1, 1)');
|
|
16
|
+
this.element.setStyleProperty(property, value);
|
|
17
|
+
};
|
|
18
|
+
return new Proxy(styleObject, {
|
|
19
|
+
set: (target, prop, value)=>{
|
|
20
|
+
if ('string' == typeof prop && 'setProperty' !== prop) {
|
|
21
|
+
if ('transform' === prop && 'none' === value) {
|
|
22
|
+
this.element.setStyleProperty('transform', 'scale(1, 1)');
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
this.element.setStyleProperty(prop, String(value));
|
|
26
|
+
target[prop] = value;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
get: (_target, prop)=>{
|
|
31
|
+
if ('string' == typeof prop && 'setProperty' !== prop) return this.getStyleProperty(prop);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
set style(styles) {
|
|
36
|
+
this.element.setStyleProperties(styles);
|
|
37
|
+
}
|
|
38
|
+
getStyleProperty(name) {
|
|
39
|
+
return __GetComputedStyleByKey(this.element.element, name);
|
|
40
|
+
}
|
|
41
|
+
get backgroundColor() {
|
|
42
|
+
return this.getStyleProperty('backgroundColor');
|
|
43
|
+
}
|
|
44
|
+
set backgroundColor(value) {
|
|
45
|
+
this.element.setStyleProperty('backgroundColor', value);
|
|
46
|
+
}
|
|
47
|
+
get color() {
|
|
48
|
+
return this.getStyleProperty('color');
|
|
49
|
+
}
|
|
50
|
+
set color(value) {
|
|
51
|
+
this.element.setStyleProperty('color', value);
|
|
52
|
+
}
|
|
53
|
+
get fontSize() {
|
|
54
|
+
return this.getStyleProperty('fontSize');
|
|
55
|
+
}
|
|
56
|
+
set fontSize(value) {
|
|
57
|
+
this.element.setStyleProperty('fontSize', value);
|
|
58
|
+
}
|
|
59
|
+
get width() {
|
|
60
|
+
return this.getStyleProperty('width');
|
|
61
|
+
}
|
|
62
|
+
set width(value) {
|
|
63
|
+
this.element.setStyleProperty('width', value);
|
|
64
|
+
}
|
|
65
|
+
get height() {
|
|
66
|
+
return this.getStyleProperty('height');
|
|
67
|
+
}
|
|
68
|
+
set height(value) {
|
|
69
|
+
this.element.setStyleProperty('height', value);
|
|
70
|
+
}
|
|
71
|
+
get margin() {
|
|
72
|
+
return this.getStyleProperty('margin');
|
|
73
|
+
}
|
|
74
|
+
set margin(value) {
|
|
75
|
+
this.element.setStyleProperty('margin', value);
|
|
76
|
+
}
|
|
77
|
+
get padding() {
|
|
78
|
+
return this.getStyleProperty('padding');
|
|
79
|
+
}
|
|
80
|
+
set padding(value) {
|
|
81
|
+
this.element.setStyleProperty('padding', value);
|
|
82
|
+
}
|
|
83
|
+
get display() {
|
|
84
|
+
return this.getStyleProperty('display');
|
|
85
|
+
}
|
|
86
|
+
set display(value) {
|
|
87
|
+
this.element.setStyleProperty('display', value);
|
|
88
|
+
}
|
|
89
|
+
get position() {
|
|
90
|
+
return this.getStyleProperty('position');
|
|
91
|
+
}
|
|
92
|
+
set position(value) {
|
|
93
|
+
this.element.setStyleProperty('position', value);
|
|
94
|
+
}
|
|
95
|
+
get top() {
|
|
96
|
+
return this.getStyleProperty('top');
|
|
97
|
+
}
|
|
98
|
+
set top(value) {
|
|
99
|
+
this.element.setStyleProperty('top', value);
|
|
100
|
+
}
|
|
101
|
+
get left() {
|
|
102
|
+
return this.getStyleProperty('left');
|
|
103
|
+
}
|
|
104
|
+
set left(value) {
|
|
105
|
+
this.element.setStyleProperty('left', value);
|
|
106
|
+
}
|
|
107
|
+
get right() {
|
|
108
|
+
return this.getStyleProperty('right');
|
|
109
|
+
}
|
|
110
|
+
set right(value) {
|
|
111
|
+
this.element.setStyleProperty('right', value);
|
|
112
|
+
}
|
|
113
|
+
get bottom() {
|
|
114
|
+
return this.getStyleProperty('bottom');
|
|
115
|
+
}
|
|
116
|
+
set bottom(value) {
|
|
117
|
+
this.element.setStyleProperty('bottom', value);
|
|
118
|
+
}
|
|
119
|
+
getBoundingClientRect() {
|
|
120
|
+
const width = Number.parseFloat(this.getStyleProperty('width')) || 0;
|
|
121
|
+
const height = Number.parseFloat(this.getStyleProperty('height')) || 0;
|
|
122
|
+
const left = Number.parseFloat(this.getStyleProperty('left')) || 0;
|
|
123
|
+
const top = Number.parseFloat(this.getStyleProperty('top')) || 0;
|
|
124
|
+
const right = left + width;
|
|
125
|
+
const bottom = top + height;
|
|
126
|
+
return {
|
|
127
|
+
left,
|
|
128
|
+
top,
|
|
129
|
+
right,
|
|
130
|
+
bottom,
|
|
131
|
+
width,
|
|
132
|
+
height,
|
|
133
|
+
x: left,
|
|
134
|
+
y: top
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export { ElementCompt };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ElementCompt } from "./element.js";
|
|
2
|
+
const timeOrigin = "u" > typeof performance && performance.timeOrigin ? performance.timeOrigin : Date.now();
|
|
3
|
+
function shimQueueMicroTask() {
|
|
4
|
+
if (!globalThis.queueMicrotask) if ("u" > typeof lynx && lynx.queueMicrotask) globalThis.queueMicrotask = lynx.queueMicrotask;
|
|
5
|
+
else {
|
|
6
|
+
const resolved = globalThis.Promise.resolve();
|
|
7
|
+
globalThis.queueMicrotask = (fn)=>{
|
|
8
|
+
resolved.then(fn).catch((err)=>{
|
|
9
|
+
setTimeout(()=>{
|
|
10
|
+
throw err;
|
|
11
|
+
}, 0);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function shimGlobals() {
|
|
17
|
+
if (!globalThis.document) globalThis.document = {};
|
|
18
|
+
if (!globalThis.performance) globalThis.performance = {
|
|
19
|
+
now: ()=>Date.now() - timeOrigin
|
|
20
|
+
};
|
|
21
|
+
document.querySelector ??= lynx.querySelector;
|
|
22
|
+
document.querySelectorAll ??= lynx.querySelectorAll;
|
|
23
|
+
if (!globalThis.NodeList) globalThis.NodeList = class {
|
|
24
|
+
};
|
|
25
|
+
if (!globalThis.SVGElement) globalThis.SVGElement = class {
|
|
26
|
+
};
|
|
27
|
+
if (!globalThis.HTMLElement) globalThis.HTMLElement = class {
|
|
28
|
+
};
|
|
29
|
+
if (!globalThis.window) globalThis.window = {
|
|
30
|
+
getComputedStyle: (ele)=>ele.getComputedStyle()
|
|
31
|
+
};
|
|
32
|
+
globalThis.Element ??= ElementCompt;
|
|
33
|
+
globalThis.EventTarget ??= ElementCompt;
|
|
34
|
+
if (!globalThis.getComputedStyle && globalThis.window?.getComputedStyle) globalThis.getComputedStyle = globalThis.window.getComputedStyle;
|
|
35
|
+
shimQueueMicroTask();
|
|
36
|
+
}
|
|
37
|
+
if (__MAIN_THREAD__) shimGlobals();
|
|
38
|
+
else if (__DEV__) shimQueueMicroTask();
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isMainThreadElement, isMainThreadElementArray } from "./isMainThreadElement.js";
|
|
2
|
+
import { ElementCompt } from "../polyfill/element.js" with {
|
|
3
|
+
runtime: "shared"
|
|
4
|
+
};
|
|
5
|
+
function elementOrSelector2Dom(nodesOrSelector) {
|
|
6
|
+
'main thread';
|
|
7
|
+
let domElements;
|
|
8
|
+
if ('string' == typeof nodesOrSelector || isMainThreadElement(nodesOrSelector) || isMainThreadElementArray(nodesOrSelector)) {
|
|
9
|
+
let elementNodes;
|
|
10
|
+
if ('string' == typeof nodesOrSelector) {
|
|
11
|
+
elementNodes = lynx.querySelectorAll(nodesOrSelector);
|
|
12
|
+
if (!elementNodes || Array.isArray(elementNodes) && 0 === elementNodes.length) return;
|
|
13
|
+
} else elementNodes = nodesOrSelector;
|
|
14
|
+
domElements = Array.isArray(elementNodes) ? elementNodes.map((el)=>new ElementCompt(el)) : new ElementCompt(elementNodes);
|
|
15
|
+
}
|
|
16
|
+
return domElements;
|
|
17
|
+
}
|
|
18
|
+
export { elementOrSelector2Dom };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function isMainThreadElement(ele) {
|
|
2
|
+
'main thread';
|
|
3
|
+
if (ele && 'element' in ele) return true;
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
function isMainThreadElementArray(eleArr) {
|
|
7
|
+
'main thread';
|
|
8
|
+
return Array.isArray(eleArr) && eleArr.every((ele)=>isMainThreadElement(ele));
|
|
9
|
+
}
|
|
10
|
+
export { isMainThreadElement, isMainThreadElementArray };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function registerCallable(func: CallableFunction, id: string): string;
|
|
2
|
+
export declare function runOnRegistered<T extends CallableFunction = CallableFunction>(id: string): T;
|
|
3
|
+
declare global {
|
|
4
|
+
var runOnRegistered: <T extends CallableFunction = CallableFunction>(id: string) => T;
|
|
5
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { noop } from "./noop.js";
|
|
2
|
+
const registeredCallableMap = new Map();
|
|
3
|
+
function registerCallable(func, id) {
|
|
4
|
+
registeredCallableMap.set(id, func);
|
|
5
|
+
return id;
|
|
6
|
+
}
|
|
7
|
+
function runOnRegistered(id) {
|
|
8
|
+
const func = registeredCallableMap.get(id) ?? noop;
|
|
9
|
+
return func;
|
|
10
|
+
}
|
|
11
|
+
globalThis.runOnRegistered = runOnRegistered;
|
|
12
|
+
export { registerCallable, runOnRegistered };
|
package/package.json
CHANGED
|
@@ -1,9 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/motion-canary",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-canary-20260129-d02a6062",
|
|
4
|
+
"private": false,
|
|
4
5
|
"description": "This is a motion adapter for Lynx.js",
|
|
5
|
-
"keywords": [
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"lynx",
|
|
9
|
+
"motion",
|
|
10
|
+
"framer-motion"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/lynx-family/lynx-stack.git",
|
|
15
|
+
"directory": "packages/motion"
|
|
16
|
+
},
|
|
6
17
|
"license": "Apache-2.0",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./dist/polyfill/shim.js"
|
|
20
|
+
],
|
|
7
21
|
"type": "module",
|
|
8
|
-
"
|
|
9
|
-
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./mini": {
|
|
29
|
+
"types": "./dist/mini/index.d.ts",
|
|
30
|
+
"import": "./dist/mini/index.js",
|
|
31
|
+
"default": "./dist/mini/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"main": "dist/index.js",
|
|
35
|
+
"types": "dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"NOTICE",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"CHANGELOG.md"
|
|
42
|
+
],
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"framer-motion": "12.23.12",
|
|
45
|
+
"motion-dom": "12.23.12",
|
|
46
|
+
"motion-utils": "12.23.6"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@lynx-js/types": "3.6.0",
|
|
50
|
+
"rsbuild-plugin-publint": "0.3.3",
|
|
51
|
+
"@lynx-js/react": "npm:@lynx-js/react-canary@0.116.2-canary-20260129-d02a6062"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@lynx-js/react": "*",
|
|
55
|
+
"@lynx-js/types": "*"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"@lynx-js/types": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "rslib build",
|
|
64
|
+
"dev": "rslib build --watch",
|
|
65
|
+
"test": "vitest run"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|