Skip to content

Commit 480a3fe

Browse files
committed
fix #42
1 parent 5012e10 commit 480a3fe

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-tween-one",
3-
"version": "2.2.5",
3+
"version": "2.2.6",
44
"description": "tween-one anim component for react",
55
"keywords": [
66
"react",

src/easing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import easingTypes from 'tween-functions';
2-
import { parsePath } from './util';
2+
import { windowIsUndefined, parsePath } from './util';
33

44
easingTypes.path = (_path, _param) => {
55
const param = _param || {};
6-
if (typeof window === 'undefined') {
6+
if (windowIsUndefined) {
77
return 'linear';
88
}
99
const pathNode = parsePath(_path);

src/plugin/PathPlugin.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import {
33
getTransform,
44
createMatrix,
55
} from 'style-utils';
6-
import { parsePath, getTransformValue } from '../util';
6+
import { windowIsUndefined, parsePath, getTransformValue } from '../util';
77

88
function PathPlugin(target, vars) {
99
this.target = target;
1010
const path = typeof vars === 'string' ? vars : vars.x || vars.y || vars.rotate;
1111
this.vars = vars;
12-
this.path = parsePath(path);
12+
this.path = windowIsUndefined ? null : parsePath(path);
1313
this.start = {};
14-
this.pathLength = this.path.getTotalLength();
14+
this.pathLength = this.path ? this.path.getTotalLength() : 0;
1515
}
1616

1717
PathPlugin.prototype = {
@@ -20,7 +20,7 @@ PathPlugin.prototype = {
2020
getPoint(offset) {
2121
const o = offset || 0;
2222
const p = this.pathLength * this.progress + o;
23-
return this.path.getPointAtLength(p);
23+
return this.path ? this.path.getPointAtLength(p) : 0;
2424
},
2525
getAnimStart(computedStyle, isSvg) {
2626
const transform = getTransform(computedStyle[isSvg ?

src/util.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import React from 'react';
22
import deepEql from 'deep-eql';
33

4+
export const windowIsUndefined = !(
5+
typeof window !== 'undefined' &&
6+
window.document &&
7+
window.document.createElement
8+
);
9+
410
export function toArrayChildren(children) {
511
const ret = [];
612
React.Children.forEach(children, (c) => {
@@ -152,6 +158,9 @@ export function startConvertToEndUnit(
152158
target, computedStyle, style, num,
153159
unit, dataUnit, fixed, isOriginWidth
154160
) {
161+
if (windowIsUndefined) {
162+
return num;
163+
}
155164
let horiz = /(?:Left|Right|Width|X)/i.test(style) || isOriginWidth;
156165
horiz = style === 'padding' || style === 'marign' ? true : horiz;
157166
let t = style.indexOf('border') !== -1 || style.indexOf('translate') !== -1 ?

0 commit comments

Comments
 (0)