react-voodoo 2.3.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "react-voodoo",
3
- "version": "2.3.0",
4
- "license": "MIT",
3
+ "version": "2.4.1",
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",
12
12
  "test": "echo ok",
13
- "testAuto": "nodemon --watch ./dist/react-voodoo.js --watch ./etc/tests/**/*.js --exec \"npm test\""
13
+ "testAuto": "nodemon --watch ./dist/react-voodoo.js --watch ./etc/tests/**/*.js --exec \"npm test\"",
14
+ "setupLayers": "lpack-setup"
14
15
  },
15
16
  "peerDependencies": {
16
17
  "react": "^16.0.0 || ^17.0.1",
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>
@@ -11,10 +11,13 @@ ___
11
11
  <a href="https://travis-ci.org/react-voodoo/react-voodoo">
12
12
  <img src="https://travis-ci.org/react-voodoo/react-voodoo.svg?branch=master" alt="Build Status" /></a>
13
13
  <img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat" />
14
+ <br/>
15
+ <a href="http://creativecommons.org/licenses/by-nd/4.0">
16
+ <img src="https://img.shields.io/badge/License-CC%20BY--ND%204.0-lightgrey.svg" alt="License: CC BY-ND 4.0" /></a>
17
+ <a href="http://www.gnu.org/licenses/agpl-3.0">
18
+ <img src="https://img.shields.io/badge/License-AGPL%20v3-blue.svg" alt="License: AGPL v3" /></a>
14
19
  </p>
15
20
 
16
-
17
-
18
21
  ## Why another animation engine ?
19
22
 
20
23
  To have some advanced functionalities :
@@ -31,12 +34,13 @@ To have some advanced functionalities :
31
34
  - Automatically deal with multiple units using css "calc( ... )"
32
35
  - etc...
33
36
 
34
- ## Some live demo & codesandbox [here](https://react-voodoo.github.io/react-voodoo-samples/)
35
- <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)
36
38
 
37
- ## 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/)
38
40
 
39
- ## 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)
40
44
 
41
45
  ## Note
42
46
 
@@ -55,186 +59,218 @@ react-voodoo still miss some interpolator ( like background or borders ).<br/>
55
59
  "all in one" example :
56
60
 
57
61
  ```jsx harmony
58
-
59
- import React from "react";
60
- import Voodoo from "react-voodoo";
62
+ import React from "react";
63
+ import Voodoo from "react-voodoo";
61
64
  import {itemTweenAxis, tweenArrayWithTargets} from "./somewhere";
62
65
 
63
66
  const styleSample = {
64
- height : "50%",
65
-
66
- // the tweener deal with multiple units
67
- // it will use css calc fn if there's more than 1 unit used
68
- width : ["50%", "10vw", "-50px", ".2box"],
69
-
70
- // transform can use multiple "layers"
71
- transform: [
72
- {
73
- // use rotate(X|Y|Z) & translate(X|Y|Z)
74
- rotateX:"25deg"
75
- },
76
- {
77
- translateZ: "-.2box"
78
- }
79
- ],
80
-
81
- filter:
82
- {
83
- blur:"5px"
84
- }
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
+ }
85
93
  };
86
- 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
+ },
87
108
  {
88
- target: "someTweenRefId", // target tween ref id ( optional if used as tweenAxis on a TweenRef )
89
- from : 0, // tween start position
90
- duration: 100, // tween duration
91
- easeFn : "easeCircleIn", // function or easing fn id from [d3-ease](https://github.com/d3/d3-ease)
92
-
93
- apply : {// relative css values to be applied
94
- // Same syntax as the styles
95
- transform: [{}, {
96
- translateZ: "-.2box"
97
- }]
98
- }
99
- },
100
- {
101
- from : 40,
102
- duration : 20,
103
-
104
- // triggered when axis has scrolled in the Event period
105
- // delta : [-1,1] is the update inside the Event period
106
- entering:(delta)=>false,
107
-
108
- // triggered when axis has scrolled in the Event period
109
- // newPos, precPos : [0,1] position inside the Event period
110
- // delta : [-1,1] is the update inside the Event period
111
- moving:(newPos, precPos, delta)=>false,
112
-
113
- // triggered when axis has scrolled out the Event period
114
- // delta : [-1,1] is the update inside the Event period
115
- leaving:(delta)=>false
116
- }
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
+ }
117
125
  ];
118
126
 
119
127
  const Sample = ( {} ) => {
120
- const //[parentTweener] = Voodoo.hook(true),
121
- [tweener, ViewBox] = Voodoo.hook();
122
-
123
- // Voodoo.hook({name:"root"}) // tweener instance can be nammed like this
124
- // Voodoo.hook("root") // we can then get theirs ref like this
125
-
126
- React.useEffect(
127
- e => tweener?.watchAxis("scrollY", (pos)=>doSomething()),
128
- [tweener]
129
- )
130
-
131
- // once drawn :
132
- // tweener.axes.(axisId).scrollPos
133
- // tweener.axes.(axisId).scrollTo(targetPos, duration, easeFn)
134
- // tweener.scrollTo(targetPos, duration, axisId, easeFn)
135
-
136
- return <ViewBox className={ "container" }>
137
- <Voodoo.Axis
138
-
139
- id={"scrollY"} // Tween axis Id
140
- defaultPosition={100} // default start position
141
-
142
- // Global scrollable tween with theirs TweenRef target ids
143
- items={tweenArrayWithTargets}
144
-
145
- // size of the scrollable window for drag synchronisation
146
- scrollableWindow={ 200 }
147
-
148
- // default length of this scrollable axis
149
- size={ 1000 }
150
-
151
- // optional bounds ( inertia will target them if target pos is out )
152
- bounds={ { min : 100, max : 900 } }
153
-
154
- // inertia cfg ( false to disable it )
155
- inertia={
156
- {
157
- // called when inertia is updated
158
- // should return instantaneous move to do if wanted
159
- shouldLoop: ( currentPos ) => ( currentPos > 500 ? -500 : null ),
160
-
161
- // called when inertia know where it will end ( when the user stop dragging )
162
- willEnd : ( targetPos, targetDelta, duration ) => {},
163
-
164
- // called when inertia know where it will snap ( when the user stop dragging )
165
- willSnap : ( currentSnapIndex, targetWayPointObj ) => {},
166
-
167
- // called when inertia end
168
- onStop : ( pos, targetWayPointObj ) => {},
169
-
170
- // called when inertia end on a snap
171
- onSnap : ( snapIndex, targetWayPointObj ) => {},
172
-
173
- // list of waypoints object ( only support auto snap 50/50 for now )
174
- wayPoints : [{ at: 100 }, { at: 200 }]
175
- }
176
- }
177
- />
178
-
179
- <Voodoo.Node
180
- id={"testItem"} // optional id
181
-
182
- style={styleSample}// initial styles : css syntax + voodoo tweener units & transform management
183
-
184
- // Scrollable tween with no target node id required ( it will be ignored )
185
- axes={{ scrollY : sampleAxis }}
186
-
187
- onClick={// all unknow props are passed to the child node
188
- (e)=>{
189
- // start playing an anim
190
- tweener.pushAnim(
191
- // make all tween target "testItem"
192
- Voodoo.tools.target(pushIn, "testItem")
193
- ).then(
194
- (tweenAxis) => {
195
- // doSomething next
196
- }
197
- );
198
- }
199
- }
200
- >
201
- <Voodoo.Draggable
202
- // make drag y move the scrollAnAxis axis
203
- // xAxis={ "scrollAnAxis" }
204
-
205
- // scale / inverse dispatched delta
206
- // xHook={(delta)=>modify(delta)}
207
-
208
- // React ref to the box, default to the parent ViewBox
209
- // scale is as follow : (delta / ((xBoxRef||ViewBox).offsetWidth)) * ( axis.scrollableWindow || axis.duration )
210
- // xBoxRef={ref}
211
-
212
- yAxis={ "scrollY" }// make drag y move the scrollY axis
213
- // yHook={(delta)=>modify(delta)}
214
- // yBoxRef={ref}
215
-
216
- // mouseDrag={true} // listen for mouse drag ( default to false )
217
- // touchDrag={false} // listen for touch drag ( default to true )
218
-
219
- // button={1-3} // limit mouse drag to the specified event.button === ( default to 1; the left btn )
220
-
221
- // * actually Draggable create it's own div node
222
- >
223
- <div>
224
- Some content to tween
225
- </div>
226
- </Voodoo.Draggable>
227
- </Voodoo.Node>
228
- </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>;
229
267
  }
230
268
  ```
231
269
 
232
- ## todo ?
270
+ ## License ?
233
271
 
234
- - add missing interpolator / strategy ( background, borders, ... )
235
- - Doc, tests & code cleaning
236
- - lot of various simple and/or smart optims / recycling
237
- - SVG support
272
+ Using CC BY-ND, you can use it in commercial apps, but you can't distribute modified versions.<br/>
273
+ Using AGPL, you can distribute modified versions but theses versions must be AGPL too.
238
274
 
239
275
  [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#)
240
276
  [![*](https://www.google-analytics.com/collect?v=1&tid=UA-82058889-1&cid=555&t=event&ec=project&ea=view&dp=%2Fproject%2Freact-voodoo&dt=readme)](#)
package/LICENSE.MD DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Braun Nathanael
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.