rollex 1.0.0.pre.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1527 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory(require("React"), require("ReactDOM"));
4
+ else if(typeof define === 'function' && define.amd)
5
+ define("Rollex", ["React", "ReactDOM"], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["Rollex"] = factory(require("React"), require("ReactDOM"));
8
+ else
9
+ root["Rollex"] = factory(root["React"], root["ReactDOM"]);
10
+ })(this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_10__) {
11
+ return /******/ (function(modules) { // webpackBootstrap
12
+ /******/ // The module cache
13
+ /******/ var installedModules = {};
14
+
15
+ /******/ // The require function
16
+ /******/ function __webpack_require__(moduleId) {
17
+
18
+ /******/ // Check if module is in cache
19
+ /******/ if(installedModules[moduleId])
20
+ /******/ return installedModules[moduleId].exports;
21
+
22
+ /******/ // Create a new module (and put it into the cache)
23
+ /******/ var module = installedModules[moduleId] = {
24
+ /******/ i: moduleId,
25
+ /******/ l: false,
26
+ /******/ exports: {}
27
+ /******/ };
28
+
29
+ /******/ // Execute the module function
30
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
+
32
+ /******/ // Flag the module as loaded
33
+ /******/ module.l = true;
34
+
35
+ /******/ // Return the exports of the module
36
+ /******/ return module.exports;
37
+ /******/ }
38
+
39
+
40
+ /******/ // expose the modules object (__webpack_modules__)
41
+ /******/ __webpack_require__.m = modules;
42
+
43
+ /******/ // expose the module cache
44
+ /******/ __webpack_require__.c = installedModules;
45
+
46
+ /******/ // identity function for calling harmony imports with the correct context
47
+ /******/ __webpack_require__.i = function(value) { return value; };
48
+
49
+ /******/ // define getter function for harmony exports
50
+ /******/ __webpack_require__.d = function(exports, name, getter) {
51
+ /******/ if(!__webpack_require__.o(exports, name)) {
52
+ /******/ Object.defineProperty(exports, name, {
53
+ /******/ configurable: false,
54
+ /******/ enumerable: true,
55
+ /******/ get: getter
56
+ /******/ });
57
+ /******/ }
58
+ /******/ };
59
+
60
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
61
+ /******/ __webpack_require__.n = function(module) {
62
+ /******/ var getter = module && module.__esModule ?
63
+ /******/ function getDefault() { return module['default']; } :
64
+ /******/ function getModuleExports() { return module; };
65
+ /******/ __webpack_require__.d(getter, 'a', getter);
66
+ /******/ return getter;
67
+ /******/ };
68
+
69
+ /******/ // Object.prototype.hasOwnProperty.call
70
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
71
+
72
+ /******/ // __webpack_public_path__
73
+ /******/ __webpack_require__.p = "";
74
+
75
+ /******/ // Load entry module and return exports
76
+ /******/ return __webpack_require__(__webpack_require__.s = 11);
77
+ /******/ })
78
+ /************************************************************************/
79
+ /******/ ([
80
+ /* 0 */
81
+ /***/ (function(module, exports) {
82
+
83
+ module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
84
+
85
+ /***/ }),
86
+ /* 1 */
87
+ /***/ (function(module, exports, __webpack_require__) {
88
+
89
+ "use strict";
90
+
91
+
92
+ Object.defineProperty(exports, "__esModule", {
93
+ value: true
94
+ });
95
+
96
+ var _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; }; }();
97
+
98
+ var _react = __webpack_require__(0);
99
+
100
+ var _react2 = _interopRequireDefault(_react);
101
+
102
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
103
+
104
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
105
+
106
+ function _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; }
107
+
108
+ function _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; }
109
+
110
+ var _React$PropTypes = _react2.default.PropTypes,
111
+ objectOf = _React$PropTypes.objectOf,
112
+ any = _React$PropTypes.any,
113
+ number = _React$PropTypes.number,
114
+ string = _React$PropTypes.string,
115
+ func = _React$PropTypes.func;
116
+
117
+ /**
118
+ * Common logic for {@link StaticCounterDigit} and {@link AnimatedCounterDigit}.
119
+ */
120
+
121
+ var AbstractCounterDigit = function (_React$Component) {
122
+ _inherits(AbstractCounterDigit, _React$Component);
123
+
124
+ function AbstractCounterDigit() {
125
+ _classCallCheck(this, AbstractCounterDigit);
126
+
127
+ return _possibleConstructorReturn(this, (AbstractCounterDigit.__proto__ || Object.getPrototypeOf(AbstractCounterDigit)).apply(this, arguments));
128
+ }
129
+
130
+ _createClass(AbstractCounterDigit, [{
131
+ key: 'decorateDigit',
132
+
133
+
134
+ /**
135
+ * Decorates given digit according to radix, digit map and digit wrapper.
136
+ * @param {number} digit
137
+ * @return {string} decoratedDigit
138
+ */
139
+ value: function decorateDigit(digit) {
140
+ var digitString = digit.toString(this.props.radix);
141
+ return this.props.digitWrapper(this.props.digitMap[digitString] || digitString);
142
+ }
143
+ /**
144
+ * @property {string} digit - digit to display
145
+ * @property {number} radix
146
+ * @property {Object} digitMap - a map for transforming particular digits
147
+ * @property {function(digit: number)} digitWrapper - a function for wrapping mapped digits
148
+ */
149
+
150
+ }]);
151
+
152
+ return AbstractCounterDigit;
153
+ }(_react2.default.Component);
154
+
155
+ AbstractCounterDigit.propTypes = {
156
+ digit: string.isRequired,
157
+ radix: number.isRequired,
158
+ digitMap: objectOf(any).isRequired,
159
+ digitWrapper: func.isRequired
160
+ };
161
+ exports.default = AbstractCounterDigit;
162
+
163
+ /***/ }),
164
+ /* 2 */
165
+ /***/ (function(module, exports, __webpack_require__) {
166
+
167
+ "use strict";
168
+
169
+
170
+ Object.defineProperty(exports, "__esModule", {
171
+ value: true
172
+ });
173
+
174
+ var _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; };
175
+
176
+ 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; }
177
+
178
+ /**
179
+ * @type {Object}
180
+ * Durations for available periods (in milliseconds).
181
+ */
182
+ var PERIOD_DURATIONS = {
183
+ 'days': 86400000,
184
+ 'hours': 3600000,
185
+ 'minutes': 60000,
186
+ 'seconds': 1000
187
+ };
188
+
189
+ /**
190
+ * @type {Object}
191
+ * Time calculation functions for available periods.
192
+ */
193
+ var PERIOD_DURATION_FUNCTIONS = {
194
+ 'hours': 'getUTCHours',
195
+ 'minutes': 'getMinutes',
196
+ 'seconds': 'getSeconds'
197
+ };
198
+
199
+ /**
200
+ * Handles period number calculations.
201
+ */
202
+ var NumberCalculator = {
203
+ /**
204
+ * Calculates numbers for each period for a given timestamp.
205
+ * @param {string[]} periods - periods to calculate numbers for
206
+ * @param {number} timestamp - timestamp to calculate numbers for
207
+ * @return {Map<string, number>} numbers - a map from periods to corresponding numbers
208
+ */
209
+ calculateNumbers: function calculateNumbers(periods, timestamp) {
210
+ var numbers = {};
211
+ var maxPeriod = periods[0];
212
+ var _iteratorNormalCompletion = true;
213
+ var _didIteratorError = false;
214
+ var _iteratorError = undefined;
215
+
216
+ try {
217
+ for (var _iterator = periods[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
218
+ var period = _step.value;
219
+
220
+ numbers = _extends({}, numbers, _defineProperty({}, period, this.getPeriodNumberAt(period, maxPeriod, timestamp)));
221
+ }
222
+ } catch (err) {
223
+ _didIteratorError = true;
224
+ _iteratorError = err;
225
+ } finally {
226
+ try {
227
+ if (!_iteratorNormalCompletion && _iterator.return) {
228
+ _iterator.return();
229
+ }
230
+ } finally {
231
+ if (_didIteratorError) {
232
+ throw _iteratorError;
233
+ }
234
+ }
235
+ }
236
+
237
+ return numbers;
238
+ },
239
+
240
+ /**
241
+ * Calculates number for given period and timestamp.
242
+ * @param {string} period
243
+ * @param {string} maxPeriod
244
+ * @param {number} timestamp
245
+ * @return {number}
246
+ */
247
+ getPeriodNumberAt: function getPeriodNumberAt(period, maxPeriod, timestamp) {
248
+ var date = new Date(timestamp);
249
+ if (maxPeriod === period) {
250
+ return Math.floor(timestamp / PERIOD_DURATIONS[period]);
251
+ } else {
252
+ return date[PERIOD_DURATION_FUNCTIONS[period]]();
253
+ }
254
+ }
255
+ };
256
+
257
+ exports.default = NumberCalculator;
258
+
259
+ /***/ }),
260
+ /* 3 */
261
+ /***/ (function(module, exports, __webpack_require__) {
262
+
263
+ "use strict";
264
+
265
+
266
+ Object.defineProperty(exports, "__esModule", {
267
+ value: true
268
+ });
269
+
270
+ var _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; }; }();
271
+
272
+ var _react = __webpack_require__(0);
273
+
274
+ var _react2 = _interopRequireDefault(_react);
275
+
276
+ var _CounterSegment = __webpack_require__(5);
277
+
278
+ var _CounterSegment2 = _interopRequireDefault(_CounterSegment);
279
+
280
+ var _CounterSegmentSeparator = __webpack_require__(6);
281
+
282
+ var _CounterSegmentSeparator2 = _interopRequireDefault(_CounterSegmentSeparator);
283
+
284
+ var _globalIntervals = __webpack_require__(9);
285
+
286
+ var _globalIntervals2 = _interopRequireDefault(_globalIntervals);
287
+
288
+ var _counterBuilder = __webpack_require__(8);
289
+
290
+ var _counterBuilder2 = _interopRequireDefault(_counterBuilder);
291
+
292
+ var _numberCalculator = __webpack_require__(2);
293
+
294
+ var _numberCalculator2 = _interopRequireDefault(_numberCalculator);
295
+
296
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
297
+
298
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
299
+
300
+ function _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; }
301
+
302
+ function _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; }
303
+
304
+ var _React$PropTypes = _react2.default.PropTypes,
305
+ number = _React$PropTypes.number,
306
+ string = _React$PropTypes.string,
307
+ bool = _React$PropTypes.bool,
308
+ objectOf = _React$PropTypes.objectOf,
309
+ object = _React$PropTypes.object,
310
+ oneOfType = _React$PropTypes.oneOfType,
311
+ oneOf = _React$PropTypes.oneOf,
312
+ func = _React$PropTypes.func,
313
+ any = _React$PropTypes.any;
314
+
315
+ /**
316
+ * Main counter component.
317
+ * @example
318
+ * <Counter seconds={98} />
319
+ */
320
+
321
+ var Counter = function (_React$Component) {
322
+ _inherits(Counter, _React$Component);
323
+
324
+ /**
325
+ * constructor
326
+ * @param {Object} props
327
+ */
328
+
329
+ /**
330
+ * @property {number} from - timestamp to count from
331
+ * @property {number} to - timestamp to count to
332
+ * @property {number} seconds - a number of seconds to count
333
+ * @property {number} interval - update interval
334
+ * @property {string} direction - direction to count in
335
+ * @property {number|object} digits - number of digits per segment
336
+ * @property {string} minPeriod - smallest period to create a segment for
337
+ * @property {string} maxPeriod - largest period to create a segment for
338
+ * @property {boolean} frozen - determines if counter is frozen
339
+ * @property {boolean} syncTime - determines if counter should try to synchronize with client
340
+ * time.
341
+ * @property {string} easingFunction - easing function to use for rolling digits
342
+ * @property {number} easingDuration - easing duration in milliseconds
343
+ * @property {number} radix - numeral base to use
344
+ * @property {Object} digitMap - a map to use when transforming digit symbols
345
+ * @property {function(digit: number)} digitWrapper - a wrapping function for mapped digits
346
+ * @property {Map<string, string>|function(period: string, number: number)} labels - a map or a
347
+ * function that returns labels for given period and number
348
+ * @property separator - what to separate segments with
349
+ */
350
+ function Counter(props) {
351
+ _classCallCheck(this, Counter);
352
+
353
+ _counterBuilder2.default.validateProps(props);
354
+
355
+ /**
356
+ * @type {object}
357
+ * @property {number} timeDiff - current amount of time to count from in milliseconds
358
+ * @property {number} initialTimeDiff - original time diff
359
+ * @property {Map<string, number>} digits - a map from periods to theis segment sizes
360
+ * @property {Map<string, number>} numbers - a map from periods to their corresponding numbers
361
+ * @property {number} startTime - a timestamp of current moment
362
+ * @property {number} from - timestamp to count from
363
+ * @property {string[]} periods - an array of periods to create segments for
364
+ */
365
+ var _this = _possibleConstructorReturn(this, (Counter.__proto__ || Object.getPrototypeOf(Counter)).call(this, props));
366
+
367
+ _this.state = new _counterBuilder2.default(_this).buildInitialState();
368
+
369
+ /**
370
+ * Creates a function bound to "this"
371
+ * for subscribing to and unsubscribing from global Rollex tick event.
372
+ */
373
+ _this.boundTick = _this.tick.bind(_this);
374
+ return _this;
375
+ }
376
+
377
+ _createClass(Counter, [{
378
+ key: 'componentDidMount',
379
+ value: function componentDidMount() {
380
+ if (!this.props.frozen) this.start();
381
+ }
382
+ }, {
383
+ key: 'componentWillUnmount',
384
+ value: function componentWillUnmount() {
385
+ if (!this.props.frozen && !this.state.stopped) this.stop();
386
+ }
387
+
388
+ /**
389
+ * Handles prop updates.
390
+ * @param {Object} nextProps - new props
391
+ */
392
+
393
+ }, {
394
+ key: 'componentWillReceiveProps',
395
+ value: function componentWillReceiveProps(nextProps) {
396
+ if (this.props.frozen !== nextProps.frozen) {
397
+ if (nextProps.frozen) {
398
+ this.stop();
399
+ } else {
400
+ this.start();
401
+ }
402
+ }
403
+ }
404
+
405
+ /**
406
+ * Starts the countdown.
407
+ */
408
+
409
+ }, {
410
+ key: 'start',
411
+ value: function start() {
412
+ _globalIntervals2.default.ensureExistence(this.props.interval);
413
+ _globalIntervals2.default.subscribe(this.props.interval, this.boundTick);
414
+ this.setState({ stopped: false });
415
+ }
416
+
417
+ /**
418
+ * Pauses the countdown.
419
+ */
420
+
421
+ }, {
422
+ key: 'stop',
423
+ value: function stop() {
424
+ _globalIntervals2.default.unsubscribe(this.props.interval, this.boundTick);
425
+ _globalIntervals2.default.cleanup(this.props.interval);
426
+ this.setState({ stopped: true });
427
+ }
428
+
429
+ /**
430
+ * Handles counter ticks.
431
+ */
432
+
433
+ }, {
434
+ key: 'tick',
435
+ value: function tick() {
436
+ var newTimeDiff = this.getTimeDiff();
437
+ if (newTimeDiff < 0) {
438
+ return this.stop();
439
+ }
440
+
441
+ var timestamp = this.props.direction === 'down' ? newTimeDiff : this.state.initialTimeDiff - newTimeDiff;
442
+
443
+ /**
444
+ * @type {object}
445
+ * @property {number} timeDiff - current amount of time to count from in milliseconds
446
+ * @property {Object} numbers - a map from periods to their corresponding numbers
447
+ */
448
+ this.setState({
449
+ timeDiff: newTimeDiff,
450
+ numbers: _numberCalculator2.default.calculateNumbers(this.state.periods, timestamp)
451
+ });
452
+ }
453
+
454
+ /**
455
+ * Gets current amount of time to count from.
456
+ * @return {number} timestamp
457
+ */
458
+
459
+ }, {
460
+ key: 'getTimeDiff',
461
+ value: function getTimeDiff() {
462
+ if (this.props.syncTime) {
463
+ return this.props.to - this.state.from - new Date().getTime() + this.state.startTime;
464
+ } else {
465
+ return this.state.timeDiff - this.props.interval;
466
+ }
467
+ }
468
+
469
+ /**
470
+ * Gets correct digits for given period accounting for counter's radix and periods's segment size.
471
+ * @param {string} period
472
+ * @return {string[]} digits
473
+ */
474
+
475
+ }, {
476
+ key: 'getDigits',
477
+ value: function getDigits(period) {
478
+ var number = this.state.numbers[period];
479
+ var digits = this.state.digits[period];
480
+ var radix = this.props.radix;
481
+
482
+ if (digits && number >= Math.pow(radix, digits)) {
483
+ var maxValueArray = [];
484
+ for (var i = 0; i < digits; i++) {
485
+ maxValueArray.push((radix - 1).toString());
486
+ }return maxValueArray;
487
+ }
488
+
489
+ number = number.toString(radix);
490
+ var zeroArray = [];
491
+ for (var _i = 0; _i < digits - number.length; _i++) {
492
+ zeroArray.push('0');
493
+ }return (zeroArray.join('') + number).split('');
494
+ }
495
+
496
+ /**
497
+ * Gets a label for given period and number.
498
+ * @param {string} period
499
+ * @param {number} number
500
+ * @return {string} label
501
+ */
502
+
503
+ }, {
504
+ key: 'getLabel',
505
+ value: function getLabel(period, number) {
506
+ if (!this.props.labels) {
507
+ return period;
508
+ } else if (typeof this.props.labels === 'function') {
509
+ return this.props.labels(period, number);
510
+ } else {
511
+ return this.props.labels[period];
512
+ }
513
+ }
514
+
515
+ /**
516
+ * Gets CSS classes for the counter.
517
+ * @return {string} cssClasses
518
+ */
519
+
520
+ }, {
521
+ key: 'getCSSClasses',
522
+ value: function getCSSClasses() {
523
+ var type = this.props.easingFunction ? 'animated' : 'static';
524
+ var cssClasses = 'rollex rollex-' + type;
525
+ if (this.props.frozen) cssClasses += ' rollex-frozen';
526
+ return cssClasses;
527
+ }
528
+
529
+ /**
530
+ * Renders the counter.
531
+ * @return {ReactElement} counter
532
+ */
533
+
534
+ }, {
535
+ key: 'render',
536
+ value: function render() {
537
+ var _this2 = this;
538
+
539
+ var segments = this.state.periods.map(function (period, index) {
540
+ var separator = index < _this2.state.periods.length - 1 ? _react2.default.createElement(_CounterSegmentSeparator2.default, { content: _this2.props.separator }) : null;
541
+ return _react2.default.createElement(
542
+ 'div',
543
+ { key: index, className: 'rollex-segment-wrapper' },
544
+ _react2.default.createElement(_CounterSegment2.default, {
545
+ period: period,
546
+ digits: _this2.getDigits(period),
547
+ radix: _this2.props.radix,
548
+ direction: _this2.props.direction,
549
+ easingFunction: _this2.props.easingFunction,
550
+ easingDuration: _this2.props.easingDuration,
551
+ digitMap: _this2.props.digitMap,
552
+ digitWrapper: _this2.props.digitWrapper,
553
+ label: _this2.getLabel(period, _this2.state.numbers[period])
554
+ }),
555
+ separator
556
+ );
557
+ });
558
+ return _react2.default.createElement(
559
+ 'div',
560
+ { className: this.getCSSClasses() },
561
+ segments
562
+ );
563
+ }
564
+ }]);
565
+
566
+ return Counter;
567
+ }(_react2.default.Component);
568
+
569
+ Counter.propTypes = {
570
+ from: number,
571
+ to: number,
572
+ seconds: number,
573
+ interval: number,
574
+ direction: oneOf(['up', 'down']),
575
+ digits: oneOfType([number, object]),
576
+ minPeriod: string,
577
+ maxPeriod: string,
578
+ frozen: bool,
579
+ syncTime: bool,
580
+ easingFunction: string,
581
+ easingDuration: number,
582
+ radix: number,
583
+ digitMap: object,
584
+ digitWrapper: func,
585
+ labels: oneOfType([objectOf(string), func]),
586
+ separator: any
587
+ };
588
+ Counter.defaultProps = {
589
+ interval: 1000,
590
+ frozen: false,
591
+ direction: 'down',
592
+ minPeriod: 'seconds',
593
+ maxPeriod: 'days',
594
+ easingFunction: null,
595
+ easingDuration: 300,
596
+ radix: 10,
597
+ digitMap: {},
598
+ digitWrapper: function digitWrapper(digit) {
599
+ return _react2.default.createElement(
600
+ 'span',
601
+ null,
602
+ digit
603
+ );
604
+ }
605
+ };
606
+ exports.default = Counter;
607
+
608
+ /***/ }),
609
+ /* 4 */
610
+ /***/ (function(module, exports, __webpack_require__) {
611
+
612
+ "use strict";
613
+
614
+
615
+ Object.defineProperty(exports, "__esModule", {
616
+ value: true
617
+ });
618
+
619
+ var _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; };
620
+
621
+ var _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; }; }();
622
+
623
+ var _react = __webpack_require__(0);
624
+
625
+ var _react2 = _interopRequireDefault(_react);
626
+
627
+ var _reactDom = __webpack_require__(10);
628
+
629
+ var _reactDom2 = _interopRequireDefault(_reactDom);
630
+
631
+ var _AbstractCounterDigit2 = __webpack_require__(1);
632
+
633
+ var _AbstractCounterDigit3 = _interopRequireDefault(_AbstractCounterDigit2);
634
+
635
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
636
+
637
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
638
+
639
+ function _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; }
640
+
641
+ function _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; }
642
+
643
+ var _React$PropTypes = _react2.default.PropTypes,
644
+ number = _React$PropTypes.number,
645
+ string = _React$PropTypes.string;
646
+
647
+ /**
648
+ * Forces reflow of a given element.
649
+ * @param {Element} element
650
+ */
651
+
652
+ function forceReflow(element) {
653
+ element.offsetHeight; // eslint-disable-line no-unused-expressions
654
+ }
655
+
656
+ /**
657
+ * Animated digit component.
658
+ * Used when counter has an easing function.
659
+ * @example
660
+ * <AnimatedCounterDigit
661
+ * digit='5'
662
+ * radix={10}
663
+ * direction='down'
664
+ * digitMap={{}}
665
+ * digitWrapper={(digit) => digit}
666
+ * maxValue={9}
667
+ * easingFunction='ease-in'
668
+ * easingDuration={200}
669
+ * />
670
+ */
671
+
672
+ var AnimatedCounterDigit = function (_AbstractCounterDigit) {
673
+ _inherits(AnimatedCounterDigit, _AbstractCounterDigit);
674
+
675
+ function AnimatedCounterDigit(props) {
676
+ _classCallCheck(this, AnimatedCounterDigit);
677
+
678
+ // e.x.: 0..9 and another 0 => 9+2 = 11 digits total (see reset method)
679
+ var _this = _possibleConstructorReturn(this, (AnimatedCounterDigit.__proto__ || Object.getPrototypeOf(AnimatedCounterDigit)).call(this, props));
680
+
681
+ _this.reset = function (event) {
682
+ if (_this.props.digit === '0') {
683
+ event.target.style.transitionProperty = 'none';
684
+ event.target.style.transform = 'translate3D(0, ' + _this.state.initialZeroPosition + '%, 0)';
685
+ forceReflow(event.target);
686
+ event.target.style.transitionProperty = '';
687
+ }
688
+ };
689
+
690
+ var singleDigitHeight = 100 / (_this.props.maxValue + 2);
691
+ var upperZeroPosition = -singleDigitHeight * (_this.props.radix - _this.props.maxValue - 1);
692
+ var lowerZeroPosition = -singleDigitHeight * _this.props.radix;
693
+ var initialZeroPosition = _this.props.direction === 'down' ? lowerZeroPosition : upperZeroPosition;
694
+ var finalZeroPosition = _this.props.direction === 'down' ? upperZeroPosition : lowerZeroPosition;
695
+
696
+ _this.state = {
697
+ initialZeroPosition: initialZeroPosition,
698
+ finalZeroPosition: finalZeroPosition,
699
+ singleDigitHeight: singleDigitHeight,
700
+ digitLane: _this.buildDigitLane()
701
+ };
702
+ return _this;
703
+ }
704
+ /**
705
+ * @property {string} direction - counting direction
706
+ * @property {number} maxValue - maximum value used to build a digit lane
707
+ * @property {string} easingFunction - easing function for transitions
708
+ * @property {number} easingDuration - duration for digit transitions in milliseconds
709
+ */
710
+
711
+
712
+ _createClass(AnimatedCounterDigit, [{
713
+ key: 'componentDidMount',
714
+ value: function componentDidMount() {
715
+ this.reset({ target: _reactDom2.default.findDOMNode(this) });
716
+ }
717
+
718
+ /**
719
+ * Changes vertical position of digit lane without triggering a transition.
720
+ * In a lane like [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] goes from first zero to last zero instantly.
721
+ * @param {SyntheticEvent} event
722
+ */
723
+
724
+ }, {
725
+ key: 'buildDigitDiv',
726
+
727
+
728
+ /**
729
+ * Creates a div for a digit lane member.
730
+ * @param {string} digit
731
+ * @param {number} key - index to use for React's key property
732
+ * @return {ReactElement}
733
+ */
734
+ value: function buildDigitDiv(digit, key) {
735
+ return _react2.default.createElement(
736
+ 'div',
737
+ { key: key || digit, className: 'rollex-digit-lane-label' },
738
+ this.decorateDigit(digit)
739
+ );
740
+ }
741
+
742
+ /**
743
+ * Builds the digit lane.
744
+ * Digit lane contains all available digits.
745
+ * It changes its vertical position in order to emulate counter rolling.
746
+ * @return {ReactElement[]}
747
+ */
748
+
749
+ }, {
750
+ key: 'buildDigitLane',
751
+ value: function buildDigitLane() {
752
+ var digitLane = [];
753
+ for (var i = 0; i <= this.props.maxValue; i++) {
754
+ digitLane.push(this.buildDigitDiv(i));
755
+ }
756
+ digitLane.push(this.buildDigitDiv(0, this.props.radix + 1));
757
+ return digitLane;
758
+ }
759
+
760
+ /**
761
+ * Calculates Y position for the digit.
762
+ * @return {number} yPosition
763
+ */
764
+
765
+ }, {
766
+ key: 'getDigitPositionY',
767
+ value: function getDigitPositionY() {
768
+ var digitIndex = parseInt(this.props.digit, this.props.radix);
769
+ if (digitIndex === 0) {
770
+ return this.state.finalZeroPosition;
771
+ } else {
772
+ return -this.state.singleDigitHeight * (digitIndex + (this.props.radix - this.props.maxValue - 1));
773
+ }
774
+ }
775
+
776
+ /**
777
+ * Renders the digit.
778
+ * @return {ReactElement} digit
779
+ */
780
+
781
+ }, {
782
+ key: 'render',
783
+ value: function render() {
784
+ var transform = 'translate3D(0, ' + this.getDigitPositionY() + '%, 0)';
785
+ var style = {
786
+ transform: transform,
787
+ WebkitTransform: transform,
788
+ MsTransform: transform,
789
+ transitionTimingFunction: this.props.easingFunction,
790
+ transitionDuration: this.props.easingDuration + 'ms',
791
+ transitionProperty: 'transform',
792
+ willChange: 'transform'
793
+ };
794
+
795
+ return _react2.default.createElement(
796
+ 'div',
797
+ { className: 'rollex-digit', onTransitionEnd: this.reset, style: style },
798
+ this.state.digitLane
799
+ );
800
+ }
801
+ }]);
802
+
803
+ return AnimatedCounterDigit;
804
+ }(_AbstractCounterDigit3.default);
805
+
806
+ AnimatedCounterDigit.propTypes = _extends({}, _AbstractCounterDigit3.default.propTypes, {
807
+ direction: string.isRequired,
808
+ maxValue: number.isRequired,
809
+ easingFunction: string.isRequired,
810
+ easingDuration: number.isRequired
811
+ });
812
+ exports.default = AnimatedCounterDigit;
813
+
814
+ /***/ }),
815
+ /* 5 */
816
+ /***/ (function(module, exports, __webpack_require__) {
817
+
818
+ "use strict";
819
+
820
+
821
+ Object.defineProperty(exports, "__esModule", {
822
+ value: true
823
+ });
824
+
825
+ var _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; }; }();
826
+
827
+ var _react = __webpack_require__(0);
828
+
829
+ var _react2 = _interopRequireDefault(_react);
830
+
831
+ var _AnimatedCounterDigit = __webpack_require__(4);
832
+
833
+ var _AnimatedCounterDigit2 = _interopRequireDefault(_AnimatedCounterDigit);
834
+
835
+ var _StaticCounterDigit = __webpack_require__(7);
836
+
837
+ var _StaticCounterDigit2 = _interopRequireDefault(_StaticCounterDigit);
838
+
839
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
840
+
841
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
842
+
843
+ function _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; }
844
+
845
+ function _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; }
846
+
847
+ var _React$PropTypes = _react2.default.PropTypes,
848
+ arrayOf = _React$PropTypes.arrayOf,
849
+ object = _React$PropTypes.object,
850
+ number = _React$PropTypes.number,
851
+ string = _React$PropTypes.string,
852
+ func = _React$PropTypes.func;
853
+
854
+ /**
855
+ * @type {Object}
856
+ * Maximum decimal values for available periods' numbers.
857
+ */
858
+
859
+ var PERIOD_LIMITS = {
860
+ 'seconds': 59,
861
+ 'minutes': 59,
862
+ 'hours': 23,
863
+ 'days': 0
864
+ };
865
+
866
+ /**
867
+ * Counter segment component.
868
+ * @example
869
+ * <CounterSegment
870
+ * digits={['0', '0']}
871
+ * period='days'
872
+ * radix={10}
873
+ * direction='down'
874
+ * easingDuration={300}
875
+ * digitMap={{ '0' => 'o' }}
876
+ * digitWrapper={(digit) => digit}
877
+ * />
878
+ */
879
+
880
+ var CounterSegment = function (_React$Component) {
881
+ _inherits(CounterSegment, _React$Component);
882
+
883
+ function CounterSegment() {
884
+ _classCallCheck(this, CounterSegment);
885
+
886
+ return _possibleConstructorReturn(this, (CounterSegment.__proto__ || Object.getPrototypeOf(CounterSegment)).apply(this, arguments));
887
+ }
888
+
889
+ _createClass(CounterSegment, [{
890
+ key: 'getMaxValue',
891
+
892
+
893
+ /**
894
+ * OPTIMIZE: this probably shouldn't be done in buildDigits. Perhaps we could perform calculations
895
+ * for each possible index it in the constructor, but only for animated counters.
896
+ *
897
+ * Gets maximum value for period's digit with account for radix.
898
+ * Used for building digit lanes in {@link AnimatedCounterDigit}.
899
+ * @param {number} index - digit's index in number
900
+ * @return {number} maxValue
901
+ */
902
+ value: function getMaxValue(index) {
903
+ var maxValue = PERIOD_LIMITS[this.props.period];
904
+ if (!maxValue) return this.props.radix - 1;
905
+
906
+ var maxValueString = maxValue.toString(this.props.radix);
907
+ var maxDigitPos = maxValueString.length;
908
+ return index === this.props.digits.length - maxDigitPos ? parseInt(maxValueString[0]) : this.props.radix - 1;
909
+ }
910
+
911
+ /**
912
+ * Maps digits to corresponding components according to easing function.
913
+ * @return {ReactElement[]}
914
+ */
915
+
916
+ /**
917
+ * @property {string[]} digits - digits to display
918
+ * @property {string} period
919
+ * @property {number} radix
920
+ * @property {string} direction - counting direction
921
+ * @property {string} easingFunction - easing function to use for digit transitions
922
+ * @property {number} easingDuration - duration of digit transitions
923
+ * @property {Object} digitMap - a map for transforming particular digits
924
+ * @property {function(digit: number)} digitWrapper - a function for wrapping mapped digits
925
+ * @property {string} label
926
+ */
927
+
928
+ }, {
929
+ key: 'buildDigits',
930
+ value: function buildDigits() {
931
+ var _this2 = this;
932
+
933
+ return this.props.digits.map(function (digit, index) {
934
+ if (_this2.props.easingFunction) {
935
+ return _react2.default.createElement(_AnimatedCounterDigit2.default, {
936
+ key: index,
937
+ digit: digit,
938
+ maxValue: _this2.getMaxValue(index),
939
+ radix: _this2.props.radix,
940
+ direction: _this2.props.direction,
941
+ easingFunction: _this2.props.easingFunction,
942
+ easingDuration: _this2.props.easingDuration,
943
+ digitMap: _this2.props.digitMap,
944
+ digitWrapper: _this2.props.digitWrapper
945
+ });
946
+ } else {
947
+ return _react2.default.createElement(_StaticCounterDigit2.default, {
948
+ key: index,
949
+ digit: digit,
950
+ radix: _this2.props.radix,
951
+ digitMap: _this2.props.digitMap,
952
+ digitWrapper: _this2.props.digitWrapper
953
+ });
954
+ }
955
+ });
956
+ }
957
+
958
+ /**
959
+ * Renders the segment.
960
+ * @return {ReactElement} counter segment
961
+ */
962
+
963
+ }, {
964
+ key: 'render',
965
+ value: function render() {
966
+ return _react2.default.createElement(
967
+ 'div',
968
+ { className: 'rollex-segment' },
969
+ _react2.default.createElement(
970
+ 'div',
971
+ { className: 'rollex-digits', style: { overflow: 'hidden' } },
972
+ this.buildDigits()
973
+ ),
974
+ _react2.default.createElement(
975
+ 'div',
976
+ { className: 'rollex-label' },
977
+ this.props.label
978
+ )
979
+ );
980
+ }
981
+ }]);
982
+
983
+ return CounterSegment;
984
+ }(_react2.default.Component);
985
+
986
+ CounterSegment.propTypes = {
987
+ digits: arrayOf(string).isRequired,
988
+ period: string.isRequired,
989
+ radix: number.isRequired,
990
+ direction: string.isRequired,
991
+ easingFunction: string,
992
+ easingDuration: number.isRequired,
993
+ digitMap: object.isRequired,
994
+ digitWrapper: func.isRequired,
995
+ label: string
996
+ };
997
+ exports.default = CounterSegment;
998
+
999
+ /***/ }),
1000
+ /* 6 */
1001
+ /***/ (function(module, exports, __webpack_require__) {
1002
+
1003
+ "use strict";
1004
+
1005
+
1006
+ Object.defineProperty(exports, "__esModule", {
1007
+ value: true
1008
+ });
1009
+
1010
+ var _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; }; }();
1011
+
1012
+ var _react = __webpack_require__(0);
1013
+
1014
+ var _react2 = _interopRequireDefault(_react);
1015
+
1016
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1017
+
1018
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1019
+
1020
+ function _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; }
1021
+
1022
+ function _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; }
1023
+
1024
+ var any = _react2.default.PropTypes.any;
1025
+
1026
+ /**
1027
+ * Separator between {@link CounterSegment} elements.
1028
+ * @example
1029
+ * <CounterSegmentSeparator content=':' />
1030
+ */
1031
+
1032
+ var CounterSegmentSeparator = function (_React$Component) {
1033
+ _inherits(CounterSegmentSeparator, _React$Component);
1034
+
1035
+ function CounterSegmentSeparator() {
1036
+ _classCallCheck(this, CounterSegmentSeparator);
1037
+
1038
+ return _possibleConstructorReturn(this, (CounterSegmentSeparator.__proto__ || Object.getPrototypeOf(CounterSegmentSeparator)).apply(this, arguments));
1039
+ }
1040
+
1041
+ _createClass(CounterSegmentSeparator, [{
1042
+ key: 'render',
1043
+
1044
+
1045
+ /**
1046
+ * Renders the separator.
1047
+ * @return {ReactElement} separator
1048
+ */
1049
+ value: function render() {
1050
+ if (this.props.content === undefined) return null;
1051
+ return _react2.default.createElement(
1052
+ 'div',
1053
+ { className: 'rollex-separator' },
1054
+ this.props.content
1055
+ );
1056
+ }
1057
+ /**
1058
+ * @property content
1059
+ */
1060
+
1061
+ }]);
1062
+
1063
+ return CounterSegmentSeparator;
1064
+ }(_react2.default.Component);
1065
+
1066
+ CounterSegmentSeparator.propTypes = {
1067
+ content: any
1068
+ };
1069
+ exports.default = CounterSegmentSeparator;
1070
+
1071
+ /***/ }),
1072
+ /* 7 */
1073
+ /***/ (function(module, exports, __webpack_require__) {
1074
+
1075
+ "use strict";
1076
+
1077
+
1078
+ Object.defineProperty(exports, "__esModule", {
1079
+ value: true
1080
+ });
1081
+
1082
+ var _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; }; }();
1083
+
1084
+ var _react = __webpack_require__(0);
1085
+
1086
+ var _react2 = _interopRequireDefault(_react);
1087
+
1088
+ var _AbstractCounterDigit2 = __webpack_require__(1);
1089
+
1090
+ var _AbstractCounterDigit3 = _interopRequireDefault(_AbstractCounterDigit2);
1091
+
1092
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1093
+
1094
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1095
+
1096
+ function _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; }
1097
+
1098
+ function _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; }
1099
+
1100
+ /**
1101
+ * Static digit component.
1102
+ * Used when no easing function is set for a counter.
1103
+ * @example
1104
+ * <StaticCounterDigit
1105
+ * digit='5'
1106
+ * radix={10}
1107
+ * digitMap={{}}
1108
+ * digitWrapper={(digit) => digit}
1109
+ * />
1110
+ */
1111
+ var StaticCounterDigit = function (_AbstractCounterDigit) {
1112
+ _inherits(StaticCounterDigit, _AbstractCounterDigit);
1113
+
1114
+ function StaticCounterDigit() {
1115
+ _classCallCheck(this, StaticCounterDigit);
1116
+
1117
+ return _possibleConstructorReturn(this, (StaticCounterDigit.__proto__ || Object.getPrototypeOf(StaticCounterDigit)).apply(this, arguments));
1118
+ }
1119
+
1120
+ _createClass(StaticCounterDigit, [{
1121
+ key: 'render',
1122
+
1123
+ /**
1124
+ * Renders the digit.
1125
+ * @return {ReactElement} digit
1126
+ */
1127
+ value: function render() {
1128
+ return _react2.default.createElement(
1129
+ 'div',
1130
+ { className: 'rollex-digit' },
1131
+ this.decorateDigit(this.props.digit)
1132
+ );
1133
+ }
1134
+ }]);
1135
+
1136
+ return StaticCounterDigit;
1137
+ }(_AbstractCounterDigit3.default);
1138
+
1139
+ exports.default = StaticCounterDigit;
1140
+
1141
+ /***/ }),
1142
+ /* 8 */
1143
+ /***/ (function(module, exports, __webpack_require__) {
1144
+
1145
+ "use strict";
1146
+
1147
+
1148
+ Object.defineProperty(exports, "__esModule", {
1149
+ value: true
1150
+ });
1151
+
1152
+ var _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; };
1153
+
1154
+ var _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; };
1155
+
1156
+ var _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; }; }();
1157
+
1158
+ var _numberCalculator = __webpack_require__(2);
1159
+
1160
+ var _numberCalculator2 = _interopRequireDefault(_numberCalculator);
1161
+
1162
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1163
+
1164
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1165
+
1166
+ /**
1167
+ * @type {string[]}
1168
+ * Names for available periods.
1169
+ */
1170
+ var PERIODS = ['days', 'hours', 'minutes', 'seconds'];
1171
+
1172
+ /**
1173
+ * Handles much of Counter initialization
1174
+ */
1175
+
1176
+ var CounterBuilder = function () {
1177
+ _createClass(CounterBuilder, null, [{
1178
+ key: 'validateProps',
1179
+
1180
+ /**
1181
+ * Validates counter's props.
1182
+ * @param {Object} props - props to validate
1183
+ */
1184
+ value: function validateProps(props) {
1185
+ if (props.seconds !== undefined) {
1186
+ if (props.to !== undefined || props.from !== undefined) {
1187
+ throw new Error('cannot use "to" and "from" with "seconds"');
1188
+ } else if (props.seconds < 0) {
1189
+ throw new Error('"seconds" must be greater than or equal to zero');
1190
+ }
1191
+ } else if (props.to === undefined) {
1192
+ throw new Error('provide either "seconds" or "to"');
1193
+ } else if (props.to < props.from) {
1194
+ throw new Error('"to" must be bigger than "from"');
1195
+ }
1196
+ if (props.digits !== undefined && props.digits < 0) {
1197
+ throw new Error('"digits" must not be negative');
1198
+ }
1199
+ if (props.minPeriod && PERIODS.indexOf(props.minPeriod) < 0) {
1200
+ throw new Error('"minPeriod" must be one of: ' + PERIODS.join(', ') + '\'');
1201
+ }
1202
+ if (props.maxPeriod && PERIODS.indexOf(props.maxPeriod) < 0) {
1203
+ throw new Error('"maxPeriod" must be one of: ' + PERIODS.join(', '));
1204
+ }
1205
+ if (props.syncTime && props.to === undefined) {
1206
+ throw new Error('"syncTime" must be used with "to"');
1207
+ }
1208
+ if (props.radix < 2 || props.radix > 36) {
1209
+ throw new Error('"radix" must be between 2 and 36');
1210
+ }
1211
+ if (typeof props.digitWrapper !== 'function') {
1212
+ throw new Error('"digitWrapper" must be a function');
1213
+ }
1214
+ if (_typeof(props.digitMap) !== 'object') {
1215
+ throw new Error('"digitMap" must be an object');
1216
+ }
1217
+ if (props.direction !== 'up' && props.direction !== 'down') {
1218
+ throw new Error('"direction" must be either up or down');
1219
+ }
1220
+ }
1221
+
1222
+ /**
1223
+ * @param {Counter} counter
1224
+ */
1225
+
1226
+ }]);
1227
+
1228
+ function CounterBuilder(counter) {
1229
+ _classCallCheck(this, CounterBuilder);
1230
+
1231
+ this.counter = counter;
1232
+ this.props = counter.props;
1233
+ this.state = {};
1234
+ }
1235
+
1236
+ /**
1237
+ * Calculates initial state of the counter.
1238
+ * @return {object} state
1239
+ */
1240
+
1241
+
1242
+ _createClass(CounterBuilder, [{
1243
+ key: 'buildInitialState',
1244
+ value: function buildInitialState() {
1245
+ this.buildTimeProps();
1246
+ this.buildPeriods();
1247
+ this.buildDigitLimits();
1248
+ this.buildInitialNumbers();
1249
+ return this.state;
1250
+ }
1251
+
1252
+ /**
1253
+ * Sets initial time parameters.
1254
+ */
1255
+
1256
+ }, {
1257
+ key: 'buildTimeProps',
1258
+ value: function buildTimeProps() {
1259
+ var startTime = new Date().getTime();
1260
+ var from = this.props.from === undefined ? startTime : this.props.from;
1261
+ var timeDiff = this.props.seconds === undefined ? this.props.to - from : this.props.seconds * 1000;
1262
+ this.state = _extends({}, this.state, {
1263
+ startTime: startTime,
1264
+ from: from,
1265
+ timeDiff: timeDiff,
1266
+ initialTimeDiff: timeDiff
1267
+ });
1268
+ }
1269
+
1270
+ /**
1271
+ * Gets an array of periods to create segments for.
1272
+ */
1273
+
1274
+ }, {
1275
+ key: 'buildPeriods',
1276
+ value: function buildPeriods() {
1277
+ var periods = PERIODS.slice(PERIODS.indexOf(this.props.maxPeriod), PERIODS.indexOf(this.props.minPeriod) + 1);
1278
+ this.state = _extends({}, this.state, {
1279
+ periods: periods
1280
+ });
1281
+ }
1282
+
1283
+ /**
1284
+ * Builds "digits" state property.
1285
+ */
1286
+
1287
+ }, {
1288
+ key: 'buildDigitLimits',
1289
+ value: function buildDigitLimits() {
1290
+ var digits = this.getDigitLimitsFromProps();
1291
+ this.state = _extends({}, this.state, this.normalizeDigitLimits(digits));
1292
+ }
1293
+
1294
+ /**
1295
+ * Gets digit limits from props specified by the user.
1296
+ * @return {Map<string, number>}
1297
+ */
1298
+
1299
+ }, {
1300
+ key: 'getDigitLimitsFromProps',
1301
+ value: function getDigitLimitsFromProps() {
1302
+ var digits = {};
1303
+
1304
+ if (typeof this.props.digits === 'number') {
1305
+ var _iteratorNormalCompletion = true;
1306
+ var _didIteratorError = false;
1307
+ var _iteratorError = undefined;
1308
+
1309
+ try {
1310
+ for (var _iterator = this.state.periods[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
1311
+ var period = _step.value;
1312
+ digits[period] = this.props.digits;
1313
+ }
1314
+ } catch (err) {
1315
+ _didIteratorError = true;
1316
+ _iteratorError = err;
1317
+ } finally {
1318
+ try {
1319
+ if (!_iteratorNormalCompletion && _iterator.return) {
1320
+ _iterator.return();
1321
+ }
1322
+ } finally {
1323
+ if (_didIteratorError) {
1324
+ throw _iteratorError;
1325
+ }
1326
+ }
1327
+ }
1328
+ } else if (_typeof(this.props.digits) === 'object') {
1329
+ digits = this.props.digits;
1330
+ }
1331
+ return digits;
1332
+ }
1333
+
1334
+ /**
1335
+ * Normalizes "digits" property.
1336
+ * @param {object} digits
1337
+ * @return {object}
1338
+ */
1339
+
1340
+ }, {
1341
+ key: 'normalizeDigitLimits',
1342
+ value: function normalizeDigitLimits(digits) {
1343
+ var normalizedDigits = {};
1344
+
1345
+ var _iteratorNormalCompletion2 = true;
1346
+ var _didIteratorError2 = false;
1347
+ var _iteratorError2 = undefined;
1348
+
1349
+ try {
1350
+ for (var _iterator2 = this.state.periods[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
1351
+ var period = _step2.value;
1352
+
1353
+ if (digits[period]) {
1354
+ normalizedDigits[period] = digits[period];
1355
+ } else {
1356
+ var limited = digits[period] === undefined;
1357
+ normalizedDigits[period] = this.getMinSegmentSize(period, limited);
1358
+ }
1359
+ }
1360
+ } catch (err) {
1361
+ _didIteratorError2 = true;
1362
+ _iteratorError2 = err;
1363
+ } finally {
1364
+ try {
1365
+ if (!_iteratorNormalCompletion2 && _iterator2.return) {
1366
+ _iterator2.return();
1367
+ }
1368
+ } finally {
1369
+ if (_didIteratorError2) {
1370
+ throw _iteratorError2;
1371
+ }
1372
+ }
1373
+ }
1374
+
1375
+ return { digits: normalizedDigits };
1376
+ }
1377
+
1378
+ /**
1379
+ * Calculates number of digits for current radix and given period.
1380
+ * @param {string} period - period to calculate digits for
1381
+ * @param {boolean} limited
1382
+ * @return {number}
1383
+ */
1384
+
1385
+ }, {
1386
+ key: 'getMinSegmentSize',
1387
+ value: function getMinSegmentSize(period, limited) {
1388
+ var maxValue = this.getPeriodMaxValue(period, limited);
1389
+ return maxValue.toString(this.props.radix).length;
1390
+ }
1391
+
1392
+ /**
1393
+ * Calculates maximum value for given period.
1394
+ * @param {string} period
1395
+ * @param {boolean} limited
1396
+ * @return {number}
1397
+ */
1398
+
1399
+ }, {
1400
+ key: 'getPeriodMaxValue',
1401
+ value: function getPeriodMaxValue(period, limited) {
1402
+ if (!limited && period === this.props.maxPeriod) {
1403
+ return _numberCalculator2.default.getPeriodNumberAt(period, this.props.maxPeriod, this.state.initialTimeDiff);
1404
+ }
1405
+ switch (period) {
1406
+ case 'seconds':
1407
+ case 'minutes':
1408
+ return 59;
1409
+ case 'hours':
1410
+ return 23;
1411
+ case 'days':
1412
+ return Math.pow(this.props.radix, 2) - 1; // 99 for decimal
1413
+ }
1414
+ }
1415
+
1416
+ /**
1417
+ * Calculates initial numbers for all periods.
1418
+ */
1419
+
1420
+ }, {
1421
+ key: 'buildInitialNumbers',
1422
+ value: function buildInitialNumbers() {
1423
+ var timestamp = this.props.direction === 'down' ? this.state.initialTimeDiff : 0;
1424
+ this.state = _extends({}, this.state, {
1425
+ numbers: _numberCalculator2.default.calculateNumbers(this.state.periods, timestamp)
1426
+ });
1427
+ }
1428
+ }]);
1429
+
1430
+ return CounterBuilder;
1431
+ }();
1432
+
1433
+ exports.default = CounterBuilder;
1434
+
1435
+ /***/ }),
1436
+ /* 9 */
1437
+ /***/ (function(module, exports, __webpack_require__) {
1438
+
1439
+ "use strict";
1440
+
1441
+
1442
+ Object.defineProperty(exports, "__esModule", {
1443
+ value: true
1444
+ });
1445
+ /**
1446
+ * Helper object with global interval management functions.
1447
+ */
1448
+ var GlobalIntervals = {
1449
+ /**
1450
+ * Ensures existence of an interval.
1451
+ * @param {!number} duration - interval duration in milliseconds
1452
+ */
1453
+ ensureExistence: function ensureExistence(duration) {
1454
+ if (!window.rollexIntervals) window.rollexIntervals = {};
1455
+ if (!window.rollexIntervals[duration]) {
1456
+ window.rollexIntervals[duration] = {
1457
+ interval: setInterval(function () {
1458
+ window.dispatchEvent(new CustomEvent("rollex:tick:" + duration));
1459
+ }, duration, false),
1460
+ counterCount: 0
1461
+ };
1462
+ }
1463
+ },
1464
+
1465
+ /**
1466
+ * Cleans up an interval.
1467
+ * @param {!number} duration - interval duration in milliseconds
1468
+ */
1469
+ cleanup: function cleanup(duration) {
1470
+ if (window.rollexIntervals[duration].counterCount === 0) {
1471
+ clearInterval(window.rollexIntervals[duration].interval);
1472
+ delete window.rollexIntervals[duration];
1473
+ }
1474
+ },
1475
+
1476
+ /**
1477
+ * Adds a subscriber to an interval.
1478
+ * @param {!number} duration - interval duration in milliseconds
1479
+ * @param {!Object|function} subscriber
1480
+ */
1481
+ subscribe: function subscribe(duration, subscriber) {
1482
+ window.rollexIntervals[duration].counterCount += 1;
1483
+ window.addEventListener("rollex:tick:" + duration, subscriber, false);
1484
+ },
1485
+
1486
+ /**
1487
+ * Removes a subscriber from an interval.
1488
+ * @param {!number} duration - interval duration in milliseconds
1489
+ * @param {!Object|function} subscriber
1490
+ */
1491
+ unsubscribe: function unsubscribe(duration, subscriber) {
1492
+ window.removeEventListener("rollex:tick:" + duration, subscriber, false);
1493
+ window.rollexIntervals[duration].counterCount -= 1;
1494
+ }
1495
+ };
1496
+
1497
+ exports.default = GlobalIntervals;
1498
+
1499
+ /***/ }),
1500
+ /* 10 */
1501
+ /***/ (function(module, exports) {
1502
+
1503
+ module.exports = __WEBPACK_EXTERNAL_MODULE_10__;
1504
+
1505
+ /***/ }),
1506
+ /* 11 */
1507
+ /***/ (function(module, exports, __webpack_require__) {
1508
+
1509
+ "use strict";
1510
+
1511
+
1512
+ Object.defineProperty(exports, "__esModule", {
1513
+ value: true
1514
+ });
1515
+ exports.Counter = undefined;
1516
+
1517
+ var _Counter = __webpack_require__(3);
1518
+
1519
+ var _Counter2 = _interopRequireDefault(_Counter);
1520
+
1521
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1522
+
1523
+ exports.Counter = _Counter2.default;
1524
+
1525
+ /***/ })
1526
+ /******/ ]);
1527
+ });