1 | 'use strict';
|
2 |
|
3 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
4 |
|
5 | require('./slicedToArray-0711941d.js');
|
6 | require('./unsupportedIterableToArray-68db1d3b.js');
|
7 | var React = require('react');
|
8 | var React__default = _interopDefault(React);
|
9 | var index = require('./index-b0606964.js');
|
10 | var defineProperty = require('./defineProperty-0921a47c.js');
|
11 | require('styled-components');
|
12 | var getPrototypeOf = require('./getPrototypeOf-2a661a20.js');
|
13 | require('./miscellaneous.js');
|
14 | require('./environment.js');
|
15 | require('./font.js');
|
16 | require('./constants.js');
|
17 | var breakpoints = require('./breakpoints.js');
|
18 | require('./springs.js');
|
19 | require('./text-styles.js');
|
20 | var isObject = require('./isObject-ec755c87.js');
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var now = function() {
|
39 | return isObject.root.Date.now();
|
40 | };
|
41 |
|
42 | var now_1 = now;
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | function isObjectLike(value) {
|
69 | return value != null && typeof value == 'object';
|
70 | }
|
71 |
|
72 | var isObjectLike_1 = isObjectLike;
|
73 |
|
74 |
|
75 | var symbolTag = '[object Symbol]';
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | function isSymbol(value) {
|
95 | return typeof value == 'symbol' ||
|
96 | (isObjectLike_1(value) && isObject.baseGetTag(value) == symbolTag);
|
97 | }
|
98 |
|
99 | var isSymbol_1 = isSymbol;
|
100 |
|
101 |
|
102 | var NAN = 0 / 0;
|
103 |
|
104 |
|
105 | var reTrim = /^\s+|\s+$/g;
|
106 |
|
107 |
|
108 | var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
109 |
|
110 |
|
111 | var reIsBinary = /^0b[01]+$/i;
|
112 |
|
113 |
|
114 | var reIsOctal = /^0o[0-7]+$/i;
|
115 |
|
116 |
|
117 | var freeParseInt = parseInt;
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | function toNumber(value) {
|
143 | if (typeof value == 'number') {
|
144 | return value;
|
145 | }
|
146 | if (isSymbol_1(value)) {
|
147 | return NAN;
|
148 | }
|
149 | if (isObject.isObject(value)) {
|
150 | var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
|
151 | value = isObject.isObject(other) ? (other + '') : other;
|
152 | }
|
153 | if (typeof value != 'string') {
|
154 | return value === 0 ? value : +value;
|
155 | }
|
156 | value = value.replace(reTrim, '');
|
157 | var isBinary = reIsBinary.test(value);
|
158 | return (isBinary || reIsOctal.test(value))
|
159 | ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
160 | : (reIsBadHex.test(value) ? NAN : +value);
|
161 | }
|
162 |
|
163 | var toNumber_1 = toNumber;
|
164 |
|
165 |
|
166 | var FUNC_ERROR_TEXT = 'Expected a function';
|
167 |
|
168 |
|
169 | var nativeMax = Math.max,
|
170 | nativeMin = Math.min;
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | function debounce(func, wait, options) {
|
227 | var lastArgs,
|
228 | lastThis,
|
229 | maxWait,
|
230 | result,
|
231 | timerId,
|
232 | lastCallTime,
|
233 | lastInvokeTime = 0,
|
234 | leading = false,
|
235 | maxing = false,
|
236 | trailing = true;
|
237 |
|
238 | if (typeof func != 'function') {
|
239 | throw new TypeError(FUNC_ERROR_TEXT);
|
240 | }
|
241 | wait = toNumber_1(wait) || 0;
|
242 | if (isObject.isObject(options)) {
|
243 | leading = !!options.leading;
|
244 | maxing = 'maxWait' in options;
|
245 | maxWait = maxing ? nativeMax(toNumber_1(options.maxWait) || 0, wait) : maxWait;
|
246 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
247 | }
|
248 |
|
249 | function invokeFunc(time) {
|
250 | var args = lastArgs,
|
251 | thisArg = lastThis;
|
252 |
|
253 | lastArgs = lastThis = undefined;
|
254 | lastInvokeTime = time;
|
255 | result = func.apply(thisArg, args);
|
256 | return result;
|
257 | }
|
258 |
|
259 | function leadingEdge(time) {
|
260 |
|
261 | lastInvokeTime = time;
|
262 |
|
263 | timerId = setTimeout(timerExpired, wait);
|
264 |
|
265 | return leading ? invokeFunc(time) : result;
|
266 | }
|
267 |
|
268 | function remainingWait(time) {
|
269 | var timeSinceLastCall = time - lastCallTime,
|
270 | timeSinceLastInvoke = time - lastInvokeTime,
|
271 | timeWaiting = wait - timeSinceLastCall;
|
272 |
|
273 | return maxing
|
274 | ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
|
275 | : timeWaiting;
|
276 | }
|
277 |
|
278 | function shouldInvoke(time) {
|
279 | var timeSinceLastCall = time - lastCallTime,
|
280 | timeSinceLastInvoke = time - lastInvokeTime;
|
281 |
|
282 |
|
283 |
|
284 |
|
285 | return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
|
286 | (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
|
287 | }
|
288 |
|
289 | function timerExpired() {
|
290 | var time = now_1();
|
291 | if (shouldInvoke(time)) {
|
292 | return trailingEdge(time);
|
293 | }
|
294 |
|
295 | timerId = setTimeout(timerExpired, remainingWait(time));
|
296 | }
|
297 |
|
298 | function trailingEdge(time) {
|
299 | timerId = undefined;
|
300 |
|
301 |
|
302 |
|
303 | if (trailing && lastArgs) {
|
304 | return invokeFunc(time);
|
305 | }
|
306 | lastArgs = lastThis = undefined;
|
307 | return result;
|
308 | }
|
309 |
|
310 | function cancel() {
|
311 | if (timerId !== undefined) {
|
312 | clearTimeout(timerId);
|
313 | }
|
314 | lastInvokeTime = 0;
|
315 | lastArgs = lastCallTime = lastThis = timerId = undefined;
|
316 | }
|
317 |
|
318 | function flush() {
|
319 | return timerId === undefined ? result : trailingEdge(now_1());
|
320 | }
|
321 |
|
322 | function debounced() {
|
323 | var time = now_1(),
|
324 | isInvoking = shouldInvoke(time);
|
325 |
|
326 | lastArgs = arguments;
|
327 | lastThis = this;
|
328 | lastCallTime = time;
|
329 |
|
330 | if (isInvoking) {
|
331 | if (timerId === undefined) {
|
332 | return leadingEdge(lastCallTime);
|
333 | }
|
334 | if (maxing) {
|
335 |
|
336 | clearTimeout(timerId);
|
337 | timerId = setTimeout(timerExpired, wait);
|
338 | return invokeFunc(lastCallTime);
|
339 | }
|
340 | }
|
341 | if (timerId === undefined) {
|
342 | timerId = setTimeout(timerExpired, wait);
|
343 | }
|
344 | return result;
|
345 | }
|
346 | debounced.cancel = cancel;
|
347 | debounced.flush = flush;
|
348 | return debounced;
|
349 | }
|
350 |
|
351 | var debounce_1 = debounce;
|
352 |
|
353 |
|
354 | var FUNC_ERROR_TEXT$1 = 'Expected a function';
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 | function throttle(func, wait, options) {
|
401 | var leading = true,
|
402 | trailing = true;
|
403 |
|
404 | if (typeof func != 'function') {
|
405 | throw new TypeError(FUNC_ERROR_TEXT$1);
|
406 | }
|
407 | if (isObject.isObject(options)) {
|
408 | leading = 'leading' in options ? !!options.leading : leading;
|
409 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
410 | }
|
411 | return debounce_1(func, wait, {
|
412 | 'leading': leading,
|
413 | 'maxWait': wait,
|
414 | 'trailing': trailing
|
415 | });
|
416 | }
|
417 |
|
418 | var throttle_1 = throttle;
|
419 |
|
420 | function _createSuper(Derived) { return function () { var Super = getPrototypeOf._getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = getPrototypeOf._getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return getPrototypeOf._possibleConstructorReturn(this, result); }; }
|
421 |
|
422 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
423 |
|
424 | 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; }
|
425 |
|
426 | 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._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; }
|
427 | var NO_DOM_WINDOW_SIZE = {
|
428 | width: 0,
|
429 | height: 0
|
430 | };
|
431 |
|
432 | var WINDOW_SIZE_BASE = _objectSpread({
|
433 | breakpoints: breakpoints.BREAKPOINTS
|
434 | }, getCurrentWindowSize());
|
435 |
|
436 | var ViewportContext = React__default.createContext(WINDOW_SIZE_BASE);
|
437 |
|
438 | function getCurrentWindowSize() {
|
439 | return typeof window === 'undefined' ? NO_DOM_WINDOW_SIZE : {
|
440 | width: window.innerWidth,
|
441 | height: window.innerHeight
|
442 | };
|
443 | }
|
444 |
|
445 | var ViewportProvider = function (_React$Component) {
|
446 | getPrototypeOf._inherits(ViewportProvider, _React$Component);
|
447 |
|
448 | var _super = _createSuper(ViewportProvider);
|
449 |
|
450 | function ViewportProvider() {
|
451 | var _this;
|
452 |
|
453 | getPrototypeOf._classCallCheck(this, ViewportProvider);
|
454 |
|
455 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
456 | args[_key] = arguments[_key];
|
457 | }
|
458 |
|
459 | _this = _super.call.apply(_super, [this].concat(args));
|
460 |
|
461 | defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "state", {
|
462 | windowSize: _this.getWindowSize()
|
463 | });
|
464 |
|
465 | defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "updateWindowSize", function () {
|
466 | _this.setState({
|
467 | windowSize: _this.getWindowSize()
|
468 | });
|
469 | });
|
470 |
|
471 | defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "within", function (min, max) {
|
472 | var width = _this.state.windowSize.width;
|
473 |
|
474 | if (min === '') min = -1;
|
475 | if (max === '') max = -1;
|
476 |
|
477 | if (typeof min === 'string') min = breakpoints.BREAKPOINTS[min];
|
478 | if (typeof max === 'string') max = breakpoints.BREAKPOINTS[max];
|
479 |
|
480 | if (typeof min !== 'number') {
|
481 | throw new Error("Viewport: invalid minimum value (".concat(min, ")."));
|
482 | }
|
483 |
|
484 | if (typeof max !== 'number') {
|
485 | throw new Error("Viewport: invalid maximum value (".concat(max, ")."));
|
486 | }
|
487 |
|
488 | return (min === -1 || width >= min) && (max === -1 || width < max);
|
489 | });
|
490 |
|
491 | defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "above", function (value) {
|
492 | return _this.within(value, -1);
|
493 | });
|
494 |
|
495 | defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "below", function (value) {
|
496 | return _this.within(-1, value);
|
497 | });
|
498 |
|
499 | return _this;
|
500 | }
|
501 |
|
502 | getPrototypeOf._createClass(ViewportProvider, [{
|
503 | key: "componentDidMount",
|
504 | value: function componentDidMount() {
|
505 | this.resizeStart();
|
506 | }
|
507 | }, {
|
508 | key: "componentWillUnmount",
|
509 | value: function componentWillUnmount() {
|
510 | this.resizeStop();
|
511 | }
|
512 | }, {
|
513 | key: "componentDidUpdate",
|
514 | value: function componentDidUpdate(prevProps) {
|
515 | var throttle = this.props.throttle;
|
516 |
|
517 | if (prevProps.throttle !== throttle) {
|
518 | this.resizeStop();
|
519 | this.resizeStart();
|
520 | }
|
521 | }
|
522 | }, {
|
523 | key: "resizeStart",
|
524 | value: function resizeStart() {
|
525 | this._handleResize = throttle_1(this.updateWindowSize, this.props.throttle);
|
526 | this.updateWindowSize();
|
527 |
|
528 | if (typeof window !== 'undefined') {
|
529 | window.addEventListener('resize', this._handleResize);
|
530 | }
|
531 | }
|
532 | }, {
|
533 | key: "resizeStop",
|
534 | value: function resizeStop() {
|
535 | if (!this._handleResize) {
|
536 | return;
|
537 | }
|
538 |
|
539 | if (typeof window !== 'undefined') {
|
540 | window.removeEventListener('resize', this._handleResize);
|
541 | }
|
542 |
|
543 | this._handleResize.cancel();
|
544 |
|
545 | delete this._handleResize;
|
546 | }
|
547 | }, {
|
548 | key: "getWindowSize",
|
549 | value: function getWindowSize() {
|
550 | return _objectSpread({}, WINDOW_SIZE_BASE, {}, getCurrentWindowSize());
|
551 | }
|
552 |
|
553 |
|
554 |
|
555 | }, {
|
556 | key: "render",
|
557 | value: function render() {
|
558 | var windowSize = this.state.windowSize;
|
559 | var children = this.props.children;
|
560 | var within = this.within,
|
561 | above = this.above,
|
562 | below = this.below;
|
563 | return React__default.createElement(ViewportContext.Provider, {
|
564 | value: _objectSpread({}, windowSize, {
|
565 | within: within,
|
566 | above: above,
|
567 | below: below
|
568 | })
|
569 | }, children);
|
570 | }
|
571 | }]);
|
572 |
|
573 | return ViewportProvider;
|
574 | }(React__default.Component);
|
575 |
|
576 |
|
577 |
|
578 | defineProperty._defineProperty(ViewportProvider, "propTypes", {
|
579 | children: index.PropTypes.node,
|
580 | throttle: index.PropTypes.number
|
581 | });
|
582 |
|
583 | defineProperty._defineProperty(ViewportProvider, "defaultProps", {
|
584 | throttle: 100
|
585 | });
|
586 |
|
587 | var Viewport = function Viewport(props) {
|
588 | return React__default.createElement(ViewportContext.Consumer, props);
|
589 | };
|
590 |
|
591 | Viewport.Provider = ViewportProvider;
|
592 | var useViewport = function useViewport() {
|
593 | return React__default.useContext(ViewportContext);
|
594 | };
|
595 |
|
596 | exports.Viewport = Viewport;
|
597 | exports.useViewport = useViewport;
|
598 |
|