react-voodoo 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "react-voodoo",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
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": "Additive & swipeable animation engine for React",
8
+ "description": "Faster, simplier, additive, swipeable & multidimentional animation engine for React",
9
9
  "scripts": {
10
10
  "build": "lpack",
11
11
  "devLib": "lpack :staging -w",
@@ -20,12 +20,12 @@
20
20
  "dependencies": {
21
21
  "@babel/runtime": "^7.12.5",
22
22
  "color-rgba": "^2.1.0",
23
- "d3-ease": "^1.0.5",
23
+ "d3-ease": "^3.0.1",
24
24
  "deep-extend": "^0.6.0",
25
25
  "fast-deep-equal": "^2.0.1",
26
26
  "shortid": "^2.2.15",
27
27
  "is": "^3.2.1",
28
- "tween-axis": "^1.2.15"
28
+ "tween-axis": "^2.0.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@babel/register": "^7.12.10",
package/readme.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <h1 align="center">react-voodoo</h1>
2
- <p align="center">Fast, SSR compatible, additive & swipeable, tween composition engine for React</p>
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
- ## Some live demo & codesandbox [here](https://react-voodoo.github.io/react-voodoo-samples/)
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
- ## Draft & minimalist samples [here](https://github.com/react-voodoo/react-voodoo-samples)
39
+ ## Live demo & codesandbox [here](https://react-voodoo.github.io/react-voodoo-samples/)
43
40
 
44
- ## Draft & minimalist doc [here](doc/readme.md)
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 React from "react";
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
- height : "50%",
70
-
71
- // the tweener deal with multiple units
72
- // it will use css calc fn if there's more than 1 unit used
73
- width : ["50%", "10vw", "-50px", ".2box"],
74
-
75
- // transform can use multiple "layers"
76
- transform: [
77
- {
78
- // use rotate(X|Y|Z) & translate(X|Y|Z)
79
- rotateX:"25deg"
80
- },
81
- {
82
- translateZ: "-.2box"
83
- }
84
- ],
85
-
86
- filter:
87
- {
88
- blur:"5px"
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
- target: "someTweenRefId", // target tween ref id ( optional if used as tweenAxis on a TweenRef )
94
- from : 0, // tween start position
95
- duration: 100, // tween duration
96
- easeFn : "easeCircleIn", // function or easing fn id from [d3-ease](https://github.com/d3/d3-ease)
97
-
98
- apply : {// relative css values to be applied
99
- // Same syntax as the styles
100
- transform: [{}, {
101
- translateZ: "-.2box"
102
- }]
103
- }
104
- },
105
- {
106
- from : 40,
107
- duration : 20,
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
- const //[parentTweener] = Voodoo.hook(true),
126
- [tweener, ViewBox] = Voodoo.hook();
127
-
128
- // Voodoo.hook({name:"root"}) // tweener instance can be nammed like this
129
- // Voodoo.hook("root") // we can then get theirs ref like this
130
-
131
- React.useEffect(
132
- e => tweener?.watchAxis("scrollY", (pos)=>doSomething()),
133
- [tweener]
134
- )
135
-
136
- // once drawn :
137
- // tweener.axes.(axisId).scrollPos
138
- // tweener.axes.(axisId).scrollTo(targetPos, duration, easeFn)
139
- // tweener.scrollTo(targetPos, duration, axisId, easeFn)
140
-
141
- return <ViewBox className={ "container" }>
142
- <Voodoo.Axis
143
-
144
- id={"scrollY"} // Tween axis Id
145
- defaultPosition={100} // default start position
146
-
147
- // Global scrollable tween with theirs TweenRef target ids
148
- items={tweenArrayWithTargets}
149
-
150
- // size of the scrollable window for drag synchronisation
151
- scrollableWindow={ 200 }
152
-
153
- // default length of this scrollable axis
154
- size={ 1000 }
155
-
156
- // optional bounds ( inertia will target them if target pos is out )
157
- bounds={ { min : 100, max : 900 } }
158
-
159
- // inertia cfg ( false to disable it )
160
- inertia={
161
- {
162
- // called when inertia is updated
163
- // should return instantaneous move to do if wanted
164
- shouldLoop: ( currentPos ) => ( currentPos > 500 ? -500 : null ),
165
-
166
- // called when inertia know where it will end ( when the user stop dragging )
167
- willEnd : ( targetPos, targetDelta, duration ) => {},
168
-
169
- // called when inertia know where it will snap ( when the user stop dragging )
170
- willSnap : ( currentSnapIndex, targetWayPointObj ) => {},
171
-
172
- // called when inertia end
173
- onStop : ( pos, targetWayPointObj ) => {},
174
-
175
- // called when inertia end on a snap
176
- onSnap : ( snapIndex, targetWayPointObj ) => {},
177
-
178
- // list of waypoints object ( only support auto snap 50/50 for now )
179
- wayPoints : [{ at: 100 }, { at: 200 }]
180
- }
181
- }
182
- />
183
-
184
- <Voodoo.Node
185
- id={"testItem"} // optional id
186
-
187
- style={styleSample}// initial styles : css syntax + voodoo tweener units & transform management
188
-
189
- // Scrollable tween with no target node id required ( it will be ignored )
190
- axes={{ scrollY : sampleAxis }}
191
-
192
- onClick={// all unknow props are passed to the child node
193
- (e)=>{
194
- // start playing an anim
195
- tweener.pushAnim(
196
- // make all tween target "testItem"
197
- Voodoo.tools.target(pushIn, "testItem")
198
- ).then(
199
- (tweenAxis) => {
200
- // doSomething next
201
- }
202
- );
203
- }
204
- }
205
- >
206
- <Voodoo.Draggable
207
- // make drag y move the scrollAnAxis axis
208
- // xAxis={ "scrollAnAxis" }
209
-
210
- // scale / inverse dispatched delta
211
- // xHook={(delta)=>modify(delta)}
212
-
213
- // React ref to the box, default to the parent ViewBox
214
- // scale is as follow : (delta / ((xBoxRef||ViewBox).offsetWidth)) * ( axis.scrollableWindow || axis.duration )
215
- // xBoxRef={ref}
216
-
217
- yAxis={ "scrollY" }// make drag y move the scrollY axis
218
- // yHook={(delta)=>modify(delta)}
219
- // yBoxRef={ref}
220
-
221
- // mouseDrag={true} // listen for mouse drag ( default to false )
222
- // touchDrag={false} // listen for touch drag ( default to true )
223
-
224
- // button={1-3} // limit mouse drag to the specified event.button === ( default to 1; the left btn )
225
-
226
- // * actually Draggable create it's own div node
227
- >
228
- <div>
229
- Some content to tween
230
- </div>
231
- </Voodoo.Draggable>
232
- </Voodoo.Node>
233
- </ViewBox>;
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-NC, you can use it in commercial apps, but you can't distribute modified versions.<br/>
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
  [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#)