react-voodoo 2.4.0 → 2.4.1
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/package.json +2 -2
- package/readme.md +205 -172
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-voodoo",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"license": "(CC-BY-ND-4.0 OR AGPL-3.0-only)",
|
|
5
5
|
"main": "./dist/react-voodoo.js",
|
|
6
6
|
"author": "Nathan Braun <n8tz.js@gmail.com>",
|
|
7
7
|
"repository": "https://github.com/react-voodoo/react-voodoo",
|
|
8
|
-
"description": "
|
|
8
|
+
"description": "Faster, simplier, additive, swipeable & multidimentional animation engine for React",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "lpack",
|
|
11
11
|
"devLib": "lpack :staging -w",
|
package/readme.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<h1 align="center">react-voodoo</h1>
|
|
2
|
-
<p align="center">Fast, SSR
|
|
2
|
+
<p align="center">Fast, SSR ready, additive & swipeable, tween composition engine for React</p>
|
|
3
3
|
|
|
4
4
|
___
|
|
5
5
|
<p align="center"><img width="192" src ="https://github.com/react-voodoo/react-voodoo/raw/master/doc/assets/logo-v0.png?sanitize=true" /></p>
|
|
@@ -18,8 +18,6 @@ ___
|
|
|
18
18
|
<img src="https://img.shields.io/badge/License-AGPL%20v3-blue.svg" alt="License: AGPL v3" /></a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
21
|
## Why another animation engine ?
|
|
24
22
|
|
|
25
23
|
To have some advanced functionalities :
|
|
@@ -36,12 +34,13 @@ To have some advanced functionalities :
|
|
|
36
34
|
- Automatically deal with multiple units using css "calc( ... )"
|
|
37
35
|
- etc...
|
|
38
36
|
|
|
39
|
-
##
|
|
40
|
-
<p align="center"><img src ="https://github.com/react-voodoo/react-voodoo/raw/master/doc/assets/demo.gif?sanitize=true" /></p>
|
|
37
|
+
## Basic documentation [here](doc/readme.md)
|
|
41
38
|
|
|
42
|
-
##
|
|
39
|
+
## Live demo & codesandbox [here](https://react-voodoo.github.io/react-voodoo-samples/)
|
|
43
40
|
|
|
44
|
-
|
|
41
|
+
<p align="center"><img src ="https://github.com/react-voodoo/react-voodoo/raw/master/doc/assets/demo.gif?sanitize=true" /></p>
|
|
42
|
+
|
|
43
|
+
## Samples sources [here](https://github.com/react-voodoo/react-voodoo-samples)
|
|
45
44
|
|
|
46
45
|
## Note
|
|
47
46
|
|
|
@@ -60,183 +59,217 @@ react-voodoo still miss some interpolator ( like background or borders ).<br/>
|
|
|
60
59
|
"all in one" example :
|
|
61
60
|
|
|
62
61
|
```jsx harmony
|
|
63
|
-
|
|
64
|
-
import
|
|
65
|
-
import Voodoo from "react-voodoo";
|
|
62
|
+
import React from "react";
|
|
63
|
+
import Voodoo from "react-voodoo";
|
|
66
64
|
import {itemTweenAxis, tweenArrayWithTargets} from "./somewhere";
|
|
67
65
|
|
|
68
66
|
const styleSample = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Voodoo.Node style property and the tween descriptors use classic CSS-in-JS declaration
|
|
69
|
+
* exept we can specify values using the "box" unit which is a [0-1] ratio of the parent ViewBox height / width
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
height: "50%",
|
|
73
|
+
|
|
74
|
+
// the tweener deal with multiple units
|
|
75
|
+
// it will use css calc fn to add them if there's more than 1 unit used
|
|
76
|
+
width: ["50%", "10vw", "-50px", ".2box"],
|
|
77
|
+
|
|
78
|
+
// transform can use multiple "layers"
|
|
79
|
+
transform: [
|
|
80
|
+
{
|
|
81
|
+
// use rotate(X|Y|Z) & translate(X|Y|Z)
|
|
82
|
+
rotateX: "25deg"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
translateZ: "-.2box"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
|
|
89
|
+
filter:
|
|
90
|
+
{
|
|
91
|
+
blur: "5px"
|
|
92
|
+
}
|
|
90
93
|
};
|
|
91
|
-
const axisSample
|
|
94
|
+
const axisSample = [// Examples of tween descriptors
|
|
95
|
+
{
|
|
96
|
+
target : "someTweenRefId", // target Voodoo.Node id ( optional if used as parameter on a Voodoo.Node as it will target it )
|
|
97
|
+
from : 0, // tween start position
|
|
98
|
+
duration: 100, // tween duration
|
|
99
|
+
easeFn : "easeCircleIn", // function or easing fn id from [d3-ease](https://github.com/d3/d3-ease)
|
|
100
|
+
|
|
101
|
+
apply: {// relative css values to be applied
|
|
102
|
+
// Same syntax as the styles
|
|
103
|
+
transform: [{}, {
|
|
104
|
+
translateZ: "-.2box"
|
|
105
|
+
}]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
92
108
|
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// triggered when axis has scrolled in the Event period
|
|
110
|
-
// delta : [-1,1] is the update inside the Event period
|
|
111
|
-
entering:(delta)=>false,
|
|
112
|
-
|
|
113
|
-
// triggered when axis has scrolled in the Event period
|
|
114
|
-
// newPos, precPos : [0,1] position inside the Event period
|
|
115
|
-
// delta : [-1,1] is the update inside the Event period
|
|
116
|
-
moving:(newPos, precPos, delta)=>false,
|
|
117
|
-
|
|
118
|
-
// triggered when axis has scrolled out the Event period
|
|
119
|
-
// delta : [-1,1] is the update inside the Event period
|
|
120
|
-
leaving:(delta)=>false
|
|
121
|
-
}
|
|
109
|
+
from : 40,
|
|
110
|
+
duration: 20,
|
|
111
|
+
|
|
112
|
+
// triggered when axis has scrolled in the Event period
|
|
113
|
+
// delta : a float value between [-1,1] is the update inside the Event period
|
|
114
|
+
entering: ( delta ) => false,
|
|
115
|
+
|
|
116
|
+
// triggered when axis has scrolled in the Event period
|
|
117
|
+
// newPos, precPos : float values between [0,1] position inside the Event period
|
|
118
|
+
// delta : a float value between [-1,1] is the update inside the Event period
|
|
119
|
+
moving: ( newPos, precPos, delta ) => false,
|
|
120
|
+
|
|
121
|
+
// triggered when axis has scrolled out the Event period
|
|
122
|
+
// delta : a float value between [-1,1] is the update inside the Event period
|
|
123
|
+
leaving: ( delta ) => false
|
|
124
|
+
}
|
|
122
125
|
];
|
|
123
126
|
|
|
124
127
|
const Sample = ( {} ) => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Voodoo tweener instanciation
|
|
131
|
+
*/
|
|
132
|
+
// Classic minimal method
|
|
133
|
+
const [tweener, ViewBox] = Voodoo.hook();
|
|
134
|
+
// get the first tweener in parents
|
|
135
|
+
const [parentTweener] = Voodoo.hook(true);
|
|
136
|
+
// Create a tweener with options
|
|
137
|
+
const [twenerWithNameAndOptions, ViewBox2] = Voodoo.hook(
|
|
138
|
+
{
|
|
139
|
+
// Give an id to this tweener so we can access it's axes in the childs components
|
|
140
|
+
name: "root",
|
|
141
|
+
// max click tm in ms before a click become a drag
|
|
142
|
+
maxClickTm: 200,
|
|
143
|
+
// max drag offset in px before a click become a drag
|
|
144
|
+
maxClickOffset: 100,
|
|
145
|
+
// lock to only 1 drag direction
|
|
146
|
+
dragDirectionLock: false,
|
|
147
|
+
// allow dragging with mouse
|
|
148
|
+
enableMouseDrag: false
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
// get a named parent tweener
|
|
152
|
+
const [nammedParentTweener] = Voodoo.hook("root")
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* once first render done, axes expose the following values & functions :
|
|
156
|
+
*/
|
|
157
|
+
// Theirs actual position in :
|
|
158
|
+
// tweener.axes.(axisId).scrollPos
|
|
159
|
+
|
|
160
|
+
// The "scrollTo" function allowing to manually move the axes positions :
|
|
161
|
+
// tweener.axes.(axisId).scrollTo(targetPos, duration, easeFn)
|
|
162
|
+
// tweener.scrollTo(targetPos, duration, axisId, easeFn)
|
|
163
|
+
|
|
164
|
+
// They can also be watched using the "watchAxis" function;
|
|
165
|
+
// When called, the returned function will disable the listener if executed :
|
|
166
|
+
React.useEffect(
|
|
167
|
+
e => tweener?.watchAxis("scrollY", ( pos ) => doSomething()),
|
|
168
|
+
[tweener]
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
return <ViewBox className={"container"}>
|
|
172
|
+
<Voodoo.Axis
|
|
173
|
+
|
|
174
|
+
id={"scrollY"} // Tween axis Id
|
|
175
|
+
defaultPosition={100} // optional initial position ( default : 0 )
|
|
176
|
+
|
|
177
|
+
// optional Array of tween descriptors with theirs Voodoo.Node target ids ( see axisSample )
|
|
178
|
+
items={tweenArrayWithTargets}
|
|
179
|
+
|
|
180
|
+
// optional size of the scrollable window for drag synchronisation
|
|
181
|
+
scrollableWindow={200}
|
|
182
|
+
|
|
183
|
+
// optional length of this scrollable axis (default to last tween desciptor position+duration)
|
|
184
|
+
size={1000}
|
|
185
|
+
|
|
186
|
+
// optional bounds ( inertia will target them if target pos is out )
|
|
187
|
+
bounds={{ min: 100, max: 900 }}
|
|
188
|
+
|
|
189
|
+
// optional inertia cfg ( false to disable it )
|
|
190
|
+
inertia={
|
|
191
|
+
{
|
|
192
|
+
// called when inertia is updated
|
|
193
|
+
// should return instantaneous move to do if wanted
|
|
194
|
+
shouldLoop: ( currentPos ) => (currentPos > 500 ? -500 : null),
|
|
195
|
+
|
|
196
|
+
// called when inertia know where it will end ( when the user stop dragging )
|
|
197
|
+
willEnd: ( targetPos, targetDelta, duration ) => {
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
// called when inertia know where it will snap ( when the user stop dragging )
|
|
201
|
+
willSnap: ( currentSnapIndex, targetWayPointObj ) => {
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
// called when inertia end
|
|
205
|
+
onStop: ( pos, targetWayPointObj ) => {
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
// called when inertia end on a snap
|
|
209
|
+
onSnap: ( snapIndex, targetWayPointObj ) => {
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
// list of waypoints object ( only support auto snap 50/50 for now )
|
|
213
|
+
wayPoints: [{ at: 100 }, { at: 200 }]
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/>
|
|
217
|
+
|
|
218
|
+
<Voodoo.Node
|
|
219
|
+
id={"testItem"} // optional id
|
|
220
|
+
|
|
221
|
+
style={styleSample}// optional styles applied before any style coming from axes : css syntax + voodoo tweener units & transform management
|
|
222
|
+
|
|
223
|
+
axes={{ scrollY: axisSample }} // optional Array of tween by axis Id with no target node id required ( it will be ignored )
|
|
224
|
+
|
|
225
|
+
onClick={// all unknow props are passed to the child node
|
|
226
|
+
( e ) => {
|
|
227
|
+
// start playing an anim ( prefer scrolling Axes )
|
|
228
|
+
tweener.pushAnim(
|
|
229
|
+
// make all tween target "testItem"
|
|
230
|
+
Voodoo.tools.target(pushIn, "testItem")
|
|
231
|
+
).then(
|
|
232
|
+
( tweenAxis ) => {
|
|
233
|
+
// doSomething next
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
>
|
|
239
|
+
<Voodoo.Draggable
|
|
240
|
+
// make drag y move the scrollAnAxis axis
|
|
241
|
+
// xAxis={ "scrollAnAxis" }
|
|
242
|
+
|
|
243
|
+
// scale / inverse dispatched delta
|
|
244
|
+
// xHook={(delta)=>modify(delta)}
|
|
245
|
+
|
|
246
|
+
// React ref to the box, default to the parent ViewBox
|
|
247
|
+
// scale is as follow : (delta / ((xBoxRef||ViewBox).offsetWidth)) * ( axis.scrollableWindow || axis.duration )
|
|
248
|
+
// xBoxRef={ref}
|
|
249
|
+
|
|
250
|
+
yAxis={"scrollY"}// make drag y move the scrollY axis
|
|
251
|
+
// yHook={(delta)=>modify(delta)}
|
|
252
|
+
// yBoxRef={ref}
|
|
253
|
+
|
|
254
|
+
// mouseDrag={true} // listen for mouse drag ( default to false )
|
|
255
|
+
// touchDrag={false} // listen for touch drag ( default to true )
|
|
256
|
+
|
|
257
|
+
// button={1-3} // limit mouse drag to the specified event.button === ( default to 1; the left btn )
|
|
258
|
+
|
|
259
|
+
// * actually Draggable create it's own div node
|
|
260
|
+
>
|
|
261
|
+
<div>
|
|
262
|
+
Some content to tween
|
|
263
|
+
</div>
|
|
264
|
+
</Voodoo.Draggable>
|
|
265
|
+
</Voodoo.Node>
|
|
266
|
+
</ViewBox>;
|
|
234
267
|
}
|
|
235
268
|
```
|
|
236
269
|
|
|
237
|
-
## License
|
|
270
|
+
## License ?
|
|
238
271
|
|
|
239
|
-
Using CC BY-
|
|
272
|
+
Using CC BY-ND, you can use it in commercial apps, but you can't distribute modified versions.<br/>
|
|
240
273
|
Using AGPL, you can distribute modified versions but theses versions must be AGPL too.
|
|
241
274
|
|
|
242
275
|
[](#)
|