Skip to content

Commit 25620ac

Browse files
committed
add d.ts and svg strokeDasharray
1 parent c906a76 commit 25620ac

File tree

8 files changed

+249
-5
lines changed

8 files changed

+249
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ React.render(<TweenOneGroup>
100100
| reverseDelay | number | 0 | animate revers start delay |
101101
| repeat | number | 0 | `animation` all data repeat, To repeat indefinitely, use -1 |
102102
| yoyo | boolean | false | `animation` all data alternating backward and forward on each repeat. |
103-
| onChange | func | null | when the animation change called, callback({ moment, item, tween, index, mode, timelineMode }) |
103+
| onChange | func | null | when the animation change called, callback({ moment, target, index, mode, timelineMode }) |
104104
| moment | number | null | set the current frame |
105105
| attr | string | `style` | `style` or `attr`, `attr` is tag attribute. when morph SVG must be `attr`. |
106106
| resetStyle | boolean | false | update animation data, reset init style |

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"lib",
3434
"assets/*.css",
3535
"dist",
36-
"es"
36+
"es",
37+
"index.d.ts"
3738
],
3839
"licenses": "MIT",
3940
"main": "./lib/index",
@@ -62,15 +63,18 @@
6263
"coverage": "rc-test run coverage"
6364
},
6465
"devDependencies": {
66+
"@types/react": "^16.0.0",
6567
"core-js": "^2.5.7",
6668
"expect.js": "0.3.x",
6769
"pre-commit": "1.x",
70+
"precommit-hook": "1.x",
6871
"rc-test": "6.x",
6972
"rc-tools": "8.x",
7073
"react": "^16.4.0",
7174
"react-dom": "^16.4.0",
7275
"rc-queue-anim": "^1.6.1",
73-
"rc-scroll-anim": "2.x"
76+
"rc-scroll-anim": "2.x",
77+
"typescript": "3.x"
7478
},
7579
"pre-commit": [
7680
"lint"
@@ -82,5 +86,6 @@
8286
"raf": "~3.4.0",
8387
"style-utils": "~0.1.13",
8488
"tween-functions": "~1.2.0"
85-
}
89+
},
90+
"types": "typeings/index.d.ts"
8691
}

src/plugin/StylePlugin.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ p.getTweenData = function (key, vars) {
3737
if (key.match(/colo|fill|storker/i)) {
3838
data.data[key] = parseColor(vars);
3939
data.dataType[key] = 'color';
40+
} else if (key === 'strokeDasharray'){
41+
data.data[key] = vars.split(',');
42+
data.dataType[key] = 'strokeDasharray';
4043
} else if (key.match(/shadow/i)) {
4144
data.data[key] = parseShadow(vars);
4245
data.dataType[key] = 'shadow';
@@ -155,7 +158,7 @@ p.getAnimStart = function (computedStyle, tween, isSvg) {
155158
startData = startData.map(this.convertToMarksArray.bind(this, computedStyle, endUnit, key));
156159
style[cssName] = startData;
157160
} else if (Array.isArray(this.propsData.data[key])) {
158-
startData = startData.split(/[\s|,]/);
161+
startData = startData.split(/[\s|,]/).filter(c => (c || c === 0));
159162
endUnit = this.propsData.dataUnit[key];
160163
startData = startData.map(this.convertToMarksArray.bind(this, computedStyle, endUnit, key));
161164
style[cssName] = startData;

tests/index.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as React from 'react';
2+
3+
import TweenOne from '../typings';
4+
5+
const path = 'M0,100 C30,60 0,20 50,50 C70,70 60,0 100,0';
6+
const ease = TweenOne.easing.path(path, { rect: 100, lengthPixel: 200 });
7+
const Group = TweenOne.TweenOneGroup;
8+
export default () => (
9+
<div>
10+
<TweenOne
11+
animation={{
12+
x: 100,
13+
ease: 'easeInBounce',
14+
onStart: ({ index, target }) => { },
15+
}}
16+
>
17+
test
18+
</TweenOne>
19+
<TweenOne
20+
animation={[{
21+
x: 100,
22+
ease,
23+
onStart: ({ index, target }) => { },
24+
}, {
25+
x: 200,
26+
ease,
27+
onComplete: ({ index, target }) => { },
28+
}]}
29+
>
30+
test
31+
</TweenOne>
32+
<Group enter={{ x: 100, opacity: 0, type: 'from' }} leave={[{ y: 100, opacity: 0 }]} appear={false}>
33+
<div key="0">test</div>
34+
</Group>
35+
</div>
36+
);

tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"strictNullChecks": true,
4+
"moduleResolution": "node",
5+
"jsx": "react",
6+
"target": "es6",
7+
"noImplicitAny": true
8+
}
9+
}

typings/AnimObject.d.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
type IEaseCallBack = ((t: number, b: number, c: number, d: number) => number);
2+
3+
export declare type IAnimTyope = 'to' | 'from';
4+
5+
export declare type IEaseType = 'linear' |
6+
'easeInSine' | 'easeOutSine' | 'easeInOutSine' |
7+
'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' |
8+
'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic' |
9+
'easeInQuart' | 'easeOutQuart' | 'easeInOutQuart' |
10+
'easeInQuint' | 'easeOutQuint' | 'easeInOutQuint' |
11+
'easeInExpo' | 'easeInOutExpo' | 'easeInOutExpo' |
12+
'easeInCirc' | 'easeOutCirc' | 'easeInOutCirc' |
13+
'easeInBack' | 'easeOutBack' | 'easeInOutBack' |
14+
'easeInElastic' | 'easeOutElastic' | 'easeInOutElastic' |
15+
'easeInBounce' | 'easeOutBounce' | 'easeInOutBounce' |
16+
IEaseCallBack; // TweenOne ease path;
17+
18+
export interface IBezier {
19+
type?: string;
20+
autoRotate?: boolean;
21+
vars: { x: number, y: number }[];
22+
}
23+
24+
export interface IChildrenProps {
25+
value: number;
26+
floatLength?: number;
27+
formatMoney?: { thousand: string, decimal: string };
28+
}
29+
30+
export interface IStyleAnimProps {
31+
[key: string]: any;
32+
bezier?: IBezier;
33+
SVGDraw?: number | string;// DrawPlugin
34+
// Children
35+
Children?: IChildrenProps;
36+
// path
37+
path?: string;
38+
// transform
39+
x?: number | string;
40+
y?: number | string;
41+
z?: number | string;
42+
translateX?: number | string;
43+
translateY?: number | string;
44+
translateZ?: number | string;
45+
rotate?: number | string;
46+
rotateX?: number | string;
47+
rotateY?: number | string;
48+
scale?: number | string;
49+
scaleX?: number | string;
50+
scaleY?: number | string;
51+
transformOrigin?: number | string;
52+
// filter
53+
grayScale?: number;
54+
sepia?: number;
55+
hueRotate?: string;
56+
invert?: number;
57+
brightness?: number;
58+
contrast?: number;
59+
saturate?: number;
60+
blur?: string;
61+
// basic
62+
width?: number | string;
63+
maxWidth?: number | string;
64+
minWidth?: number | string;
65+
height?: number | string;
66+
maxHeight?: number | string;
67+
minHeight?: number | string;
68+
lineHeight?: number | string;
69+
opacity?: number | string;
70+
top?: number | string;
71+
right?: number | string;
72+
bottom?: number | string;
73+
left?: number | string;
74+
marginTop?: number | string;
75+
marginRight?: number | string;
76+
marginBottom?: number | string;
77+
marginLeft?: number | string;
78+
paddingTop?: number | string;
79+
paddingRight?: number | string;
80+
paddingBottom?: number | string;
81+
paddingLeft?: number | string;
82+
color?: string;
83+
backgroundColor?: string;
84+
borderWidth?: number | string;
85+
borderRadius?: number | string;
86+
borderColor?: string;
87+
boxShadow?: string;
88+
textShadow?: string;
89+
// svg style
90+
storkeWidth?: number;
91+
fill?: string;
92+
stroke?: string;
93+
strokeDashoffset?: number;
94+
strokeDasharray?: string;
95+
}
96+
97+
export interface IAnimObject extends IStyleAnimProps {
98+
type?: IAnimTyope;
99+
duration?: number;
100+
delay?: number;
101+
repeat?: number;
102+
repeatDelay?: number;
103+
appearTo?: number;
104+
yoyo?: boolean;
105+
ease?: IEaseType;
106+
style?: IStyleAnimProps;
107+
// morphPlugin
108+
points?: string;
109+
d?: string;
110+
// attr svg
111+
cx?: number;
112+
cy?: number;
113+
r?: number;
114+
x1?: number;
115+
y1?: number;
116+
x2?: number;
117+
y2?: number;
118+
rx?: number;
119+
ry?: number;
120+
dx?: number;
121+
dy?: number;
122+
offset?: number | string;
123+
stdDeviation?: number | string;
124+
stopColor?: string;
125+
stopOpacity?: number;
126+
onStart?: (e: { index: number, target: HTMLElement }) => void;
127+
onUpdate?: (e: { index: number, target: HTMLElement, ratio: number }) => void;
128+
onComplete?: (e: { index: number, target: HTMLElement }) => void;
129+
onRepeat?: (e: { index: number, target: HTMLElement }) => void;
130+
}

typings/TweenOneGroup.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
3+
import { IAnimObject, IEaseCallBack } from './AnimObject';
4+
5+
export interface IGroupProps {
6+
appear?: boolean;
7+
enter?: IAnimObject | IAnimObject[] | ((key: string, index: number) => IAnimObject);
8+
leave?: IAnimObject | IAnimObject[] | ((key: string, index: number) => IAnimObject);
9+
animatingClassName?: [string, string];
10+
exclusive?: boolean;
11+
onEnd?: (e: { key: string, type: string }) => void;
12+
component?: string | React.ReactNode;
13+
componentProps?: {};
14+
}
15+
16+
export default class RcTweenOneGroup extends React.Component<IGroupProps>{ }

typings/index.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Type definitions for rc-tween-one 2.2
2+
// Project: https://github.com/react-component/tween-one
3+
// Definitions by: jljsj33 <https://github.com/jljsj33>
4+
// Definitions: https://github.com/react-component/tween-one
5+
import * as React from 'react';
6+
7+
import Group from './TweenOneGroup';
8+
import { IAnimObject, IEaseCallBack } from './AnimObject';
9+
10+
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
11+
12+
export declare type IAttrType = 'style' | 'attr';
13+
14+
export interface IChangeProps {
15+
moment?: number;
16+
target?: HTMLElement;
17+
index?: number;
18+
mode?: string;
19+
timelineMode?: string;
20+
}
21+
22+
export interface IProps<T> extends Omit<React.HTMLAttributes<T>, 'onChange'> {
23+
animation?: IAnimObject | IAnimObject[];
24+
paused?: boolean;
25+
reverse?: boolean;
26+
reverseDelay?: number;
27+
repeat?: number;
28+
yoyo?: boolean;
29+
onChange?: (e: IChangeProps) => void;
30+
moment?: number;
31+
attr?: IAttrType,
32+
resetStyle?: boolean,
33+
component?: string | React.ReactNode;
34+
componentProps?: {};
35+
}
36+
37+
export default class RcTweenOne<T> extends React.Component<IProps<T>> {
38+
static easing: {
39+
path(path: string, parame?: { rect?: number, lengthPixel?: number }): IEaseCallBack;
40+
};
41+
static plugins: {
42+
push(plugin: any): void;
43+
}
44+
static TweenOneGroup: typeof Group;
45+
}

0 commit comments

Comments
 (0)