Skip to content

Commit c99e915

Browse files
authored
Merge pull request #1 from GenomeUS/ssr-fix
Ssr fix
2 parents bee56af + d7a2544 commit c99e915

29 files changed

+1658
-8
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/.cache
22
/build
3-
/cjs
43
/coverage
54
/dist
65
/esm
76
/node_modules
87
/yarn-error.log
98

109
npm-debug.log
11-
.DS_STORE
10+
.DS_STORE

cjs/classes/Bounds.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.default = void 0;
7+
8+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9+
10+
var Bounds = function Bounds(rect, offsets, view) {
11+
_classCallCheck(this, Bounds);
12+
13+
var y0 = offsets.y0,
14+
y1 = offsets.y1,
15+
x1 = offsets.x1,
16+
x0 = offsets.x0; // Y offsets
17+
18+
var yPercent = y1.unit === '%' && y0.unit === '%';
19+
var y0Px = y0.value;
20+
var y1Px = y1.value;
21+
22+
if (yPercent) {
23+
var h100 = rect.height / 100;
24+
y0Px = y0.value * h100;
25+
y1Px = y1.value * h100;
26+
} // X offsets
27+
28+
29+
var xPercent = x1.unit === '%' && x0.unit === '%';
30+
var x0Px = x0.value;
31+
var x1Px = x1.value;
32+
33+
if (xPercent) {
34+
var _h = rect.width / 100;
35+
36+
x0Px = x0.value * _h;
37+
x1Px = x1.value * _h;
38+
}
39+
40+
var totalAbsOffY = Math.abs(y0Px) + Math.abs(y1Px);
41+
this.totalDistY = view.height + rect.height + totalAbsOffY;
42+
var totalDistTrueY = view.height + rect.height + (y1Px > y0Px ? totalAbsOffY * -1 : totalAbsOffY);
43+
var totalAbsOffX = Math.abs(x0Px) + Math.abs(x1Px);
44+
this.totalDistX = view.width + rect.width + totalAbsOffX;
45+
var totalDistTrueX = view.width + rect.width + (x1Px > x0Px ? totalAbsOffX * -1 : totalAbsOffX); // const speed = totalDistTrueY / originTotalDistY;
46+
47+
var multiplierY = rect.originTotalDistY / totalDistTrueY;
48+
var multiplierX = rect.originTotalDistX / totalDistTrueX;
49+
this.top = rect.top;
50+
this.bottom = rect.bottom;
51+
52+
if (y0Px < 0) {
53+
this.top = this.top + y0Px * multiplierY;
54+
}
55+
56+
if (y1Px > 0) {
57+
this.bottom = this.bottom + y1Px * multiplierY;
58+
}
59+
60+
this.left = rect.left;
61+
this.right = rect.right;
62+
63+
if (x0Px < 0) {
64+
this.left = this.left + x0Px * multiplierX;
65+
}
66+
67+
if (x1Px > 0) {
68+
this.right = this.right + x1Px * multiplierX;
69+
}
70+
};
71+
72+
var _default = Bounds;
73+
exports.default = _default;

cjs/classes/Element.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.Element = void 0;
7+
8+
var _index = require("../utils/index");
9+
10+
var _index2 = require("../helpers/index");
11+
12+
var _constants = require("../constants");
13+
14+
var _Bounds = _interopRequireDefault(require("./Bounds"));
15+
16+
var _Rect = _interopRequireDefault(require("./Rect"));
17+
18+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19+
20+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
21+
22+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23+
24+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25+
26+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27+
28+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
29+
30+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
31+
32+
var Element = /*#__PURE__*/function () {
33+
function Element(options) {
34+
_classCallCheck(this, Element);
35+
36+
this.elInner = options.elInner;
37+
this.elOuter = options.elOuter;
38+
this.props = options.props;
39+
this.scrollAxis = options.scrollAxis;
40+
this.id = (0, _index.createId)();
41+
this.offsets = (0, _index2.getOffsets)(this.props);
42+
this.isInView = null;
43+
this.percent = 0;
44+
this.updatePosition = options.scrollAxis === _constants.VERTICAL ? this._updatePositionVertical : this._updatePositionHorizontal;
45+
}
46+
47+
_createClass(Element, [{
48+
key: "updateProps",
49+
value: function updateProps(nextProps) {
50+
this.props = _objectSpread(_objectSpread({}, this.props), nextProps);
51+
this.offsets = (0, _index2.getOffsets)(nextProps);
52+
return this;
53+
}
54+
}, {
55+
key: "setCachedAttributes",
56+
value: function setCachedAttributes(view, scroll) {
57+
this.rect = new _Rect.default(this.elOuter, view, scroll);
58+
this.bounds = new _Bounds.default(this.rect, this.offsets, view);
59+
return this;
60+
}
61+
}, {
62+
key: "_updatePositionHorizontal",
63+
value: function _updatePositionHorizontal(view, scroll) {
64+
this.isInView = (0, _index2.isElementInView)(this.bounds.left, this.bounds.right, view.width, scroll.x);
65+
if (!this.isInView) return this;
66+
this.percent = (0, _index2.percentMoved)(this.rect.left, this.rect.originTotalDistX, view.width, scroll.x);
67+
(0, _index2.setParallaxStyles)(this.elInner, this.offsets, this.percent);
68+
return this;
69+
}
70+
}, {
71+
key: "_updatePositionVertical",
72+
value: function _updatePositionVertical(view, scroll) {
73+
this.isInView = (0, _index2.isElementInView)(this.bounds.top, this.bounds.bottom, view.height, scroll.y);
74+
if (!this.isInView) return this;
75+
this.percent = (0, _index2.percentMoved)(this.rect.top, this.rect.originTotalDistY, view.height, scroll.y);
76+
(0, _index2.setParallaxStyles)(this.elInner, this.offsets, this.percent);
77+
return this;
78+
}
79+
}]);
80+
81+
return Element;
82+
}();
83+
84+
exports.Element = Element;

0 commit comments

Comments
 (0)