UNPKG

8.56 kBJavaScriptView Raw
1module.exports =
2/******/ (function(modules) { // webpackBootstrap
3/******/ // The module cache
4/******/ var installedModules = {};
5/******/
6/******/ // The require function
7/******/ function __webpack_require__(moduleId) {
8/******/
9/******/ // Check if module is in cache
10/******/ if(installedModules[moduleId]) {
11/******/ return installedModules[moduleId].exports;
12/******/ }
13/******/ // Create a new module (and put it into the cache)
14/******/ var module = installedModules[moduleId] = {
15/******/ i: moduleId,
16/******/ l: false,
17/******/ exports: {}
18/******/ };
19/******/
20/******/ // Execute the module function
21/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22/******/
23/******/ // Flag the module as loaded
24/******/ module.l = true;
25/******/
26/******/ // Return the exports of the module
27/******/ return module.exports;
28/******/ }
29/******/
30/******/
31/******/ // expose the modules object (__webpack_modules__)
32/******/ __webpack_require__.m = modules;
33/******/
34/******/ // expose the module cache
35/******/ __webpack_require__.c = installedModules;
36/******/
37/******/ // define getter function for harmony exports
38/******/ __webpack_require__.d = function(exports, name, getter) {
39/******/ if(!__webpack_require__.o(exports, name)) {
40/******/ Object.defineProperty(exports, name, {
41/******/ configurable: false,
42/******/ enumerable: true,
43/******/ get: getter
44/******/ });
45/******/ }
46/******/ };
47/******/
48/******/ // getDefaultExport function for compatibility with non-harmony modules
49/******/ __webpack_require__.n = function(module) {
50/******/ var getter = module && module.__esModule ?
51/******/ function getDefault() { return module['default']; } :
52/******/ function getModuleExports() { return module; };
53/******/ __webpack_require__.d(getter, 'a', getter);
54/******/ return getter;
55/******/ };
56/******/
57/******/ // Object.prototype.hasOwnProperty.call
58/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
59/******/
60/******/ // __webpack_public_path__
61/******/ __webpack_require__.p = "";
62/******/
63/******/ // Load entry module and return exports
64/******/ return __webpack_require__(__webpack_require__.s = 0);
65/******/ })
66/************************************************************************/
67/******/ ([
68/* 0 */
69/***/ (function(module, exports, __webpack_require__) {
70
71"use strict";
72
73
74Object.defineProperty(exports, "__esModule", {
75 value: true
76});
77exports.Anime = undefined;
78
79var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
80
81var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
82
83var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
84
85var _react = __webpack_require__(1);
86
87var _react2 = _interopRequireDefault(_react);
88
89var _lodash = __webpack_require__(2);
90
91var _lodash2 = _interopRequireDefault(_lodash);
92
93function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
94
95function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
96
97function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
98
99function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
100
101function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
102
103var anime = typeof window !== 'undefined' ? __webpack_require__(3) : function (_) {
104 return _;
105};
106
107var Anime = exports.Anime = function (_Component) {
108 _inherits(Anime, _Component);
109
110 function Anime(props) {
111 _classCallCheck(this, Anime);
112
113 // Current Anime DOM Targets
114 var _this = _possibleConstructorReturn(this, (Anime.__proto__ || Object.getPrototypeOf(Anime)).call(this, props));
115
116 _initialiseProps.call(_this);
117
118 _this.targets = [];
119
120 // Time based children store
121 var children = props.children;
122
123 if (!Array.isArray(children)) children = [children];
124 _this.children = {
125 cur: children,
126 prev: [],
127 next: []
128 };
129 return _this;
130 }
131
132 _createClass(Anime, [{
133 key: 'componentDidMount',
134 value: function componentDidMount() {
135 this.createAnime();
136 }
137 }, {
138 key: 'componentWillReceiveProps',
139 value: function componentWillReceiveProps(nextProps) {
140 var children = nextProps.children;
141
142 var prevChildren = this.props.children;
143
144 if (!Array.isArray(children)) children = [children];
145 if (!Array.isArray(prevChildren)) prevChildren = [prevChildren];
146
147 // Determine diff children
148 var difChildren = children.filter(function (v) {
149 return !prevChildren.reduce(function (prev, cur) {
150 return prev || (0, _lodash2.default)(v, cur);
151 }, false);
152 });
153
154 // Determine if children are added/removed
155 var childrenWereRemoved = difChildren.reduce(function (prev, cur) {
156 return prev || prevChildren.indexOf(cur) > -1;
157 }, false);
158
159 // Split children to current, old, and new
160 this.children = {
161 cur: children.filter(function (c) {
162 return difChildren.indexOf(c) < 0;
163 }),
164 prev: childrenWereRemoved ? difChildren : this.children.prev,
165 next: !childrenWereRemoved ? difChildren : this.children.next
166 };
167
168 this.createAnime(nextProps);
169 }
170 }, {
171 key: 'render',
172
173
174 /**
175 * Render children, and their diffs until promise of anime finishes.
176 */
177 value: function render() {
178 var _this2 = this;
179
180 var style = this.props.style;
181 var _children = this.children,
182 cur = _children.cur,
183 prev = _children.prev,
184 next = _children.next;
185
186
187 return _react2.default.createElement(
188 _react.Fragment,
189 null,
190 cur.map(function (child, i) {
191 return _react2.default.cloneElement(child, { key: i, ref: _this2.addTarget });
192 })
193 );
194 }
195 }]);
196
197 return Anime;
198}(_react.Component);
199
200var _initialiseProps = function _initialiseProps() {
201 var _this3 = this;
202
203 this.createAnime = function () {
204 var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this3.props;
205
206
207 var animeProps = _extends({ targets: _this3.targets }, props);
208
209 anime.remove(_this3.targets);
210 delete animeProps.children;
211
212 if (_typeof(_this3.anime) === undefined) _this3.anime = anime(animeProps);else {
213 _this3.anime = anime(animeProps);
214 }
215 };
216
217 this.addTarget = function (newTarget) {
218 _this3.targets = [].concat(_toConsumableArray(_this3.targets), [newTarget]);
219 };
220};
221
222exports.default = Anime;
223
224/***/ }),
225/* 1 */
226/***/ (function(module, exports) {
227
228module.exports = require("react");
229
230/***/ }),
231/* 2 */
232/***/ (function(module, exports) {
233
234module.exports = require("lodash.isequal");
235
236/***/ }),
237/* 3 */
238/***/ (function(module, exports) {
239
240module.exports = require("animejs");
241
242/***/ })
243/******/ ]);
\No newline at end of file