UNPKG

40 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
7require('./slicedToArray-0711941d.js');
8require('./unsupportedIterableToArray-68db1d3b.js');
9var React = require('react');
10var React__default = _interopDefault(React);
11var _commonjsHelpers = require('./_commonjsHelpers-72d386ba.js');
12var index = require('./index-b0606964.js');
13var defineProperty = require('./defineProperty-0921a47c.js');
14var toConsumableArray = require('./toConsumableArray-d8a4a2c3.js');
15var _styled = require('styled-components');
16var _styled__default = _interopDefault(_styled);
17var getPrototypeOf = require('./getPrototypeOf-2a661a20.js');
18require('./color.js');
19var components = require('./components.js');
20require('./contains-component.js');
21require('./css.js');
22require('./dayjs.min-e07657bf.js');
23require('./date.js');
24require('./miscellaneous.js');
25require('./environment.js');
26require('./font.js');
27require('./math-f4029164.js');
28require('./characters.js');
29require('./format.js');
30require('./keycodes.js');
31require('./url.js');
32require('./web3.js');
33var constants = require('./constants.js');
34require('./breakpoints.js');
35var springs = require('./springs.js');
36var textStyles = require('./text-styles.js');
37require('./theme-dark.js');
38require('./theme-light.js');
39var Theme = require('./Theme.js');
40var _extends = require('./extends-40571110.js');
41var objectWithoutProperties = require('./objectWithoutProperties-35db8ab0.js');
42require('./isObject-ec755c87.js');
43var Viewport = require('./Viewport-15101437.js');
44require('./objectWithoutPropertiesLoose-1af20ad0.js');
45require('react-dom');
46var web = require('./web-d0294535.js');
47require('./index-0db71dc1.js');
48var RootPortal = require('./RootPortal.js');
49
50var runtime_1 = _commonjsHelpers.createCommonjsModule(function (module) {
51/**
52 * Copyright (c) 2014-present, Facebook, Inc.
53 *
54 * This source code is licensed under the MIT license found in the
55 * LICENSE file in the root directory of this source tree.
56 */
57
58var runtime = (function (exports) {
59
60 var Op = Object.prototype;
61 var hasOwn = Op.hasOwnProperty;
62 var undefined$1; // More compressible than void 0.
63 var $Symbol = typeof Symbol === "function" ? Symbol : {};
64 var iteratorSymbol = $Symbol.iterator || "@@iterator";
65 var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
66 var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
67
68 function wrap(innerFn, outerFn, self, tryLocsList) {
69 // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
70 var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
71 var generator = Object.create(protoGenerator.prototype);
72 var context = new Context(tryLocsList || []);
73
74 // The ._invoke method unifies the implementations of the .next,
75 // .throw, and .return methods.
76 generator._invoke = makeInvokeMethod(innerFn, self, context);
77
78 return generator;
79 }
80 exports.wrap = wrap;
81
82 // Try/catch helper to minimize deoptimizations. Returns a completion
83 // record like context.tryEntries[i].completion. This interface could
84 // have been (and was previously) designed to take a closure to be
85 // invoked without arguments, but in all the cases we care about we
86 // already have an existing method we want to call, so there's no need
87 // to create a new function object. We can even get away with assuming
88 // the method takes exactly one argument, since that happens to be true
89 // in every case, so we don't have to touch the arguments object. The
90 // only additional allocation required is the completion record, which
91 // has a stable shape and so hopefully should be cheap to allocate.
92 function tryCatch(fn, obj, arg) {
93 try {
94 return { type: "normal", arg: fn.call(obj, arg) };
95 } catch (err) {
96 return { type: "throw", arg: err };
97 }
98 }
99
100 var GenStateSuspendedStart = "suspendedStart";
101 var GenStateSuspendedYield = "suspendedYield";
102 var GenStateExecuting = "executing";
103 var GenStateCompleted = "completed";
104
105 // Returning this object from the innerFn has the same effect as
106 // breaking out of the dispatch switch statement.
107 var ContinueSentinel = {};
108
109 // Dummy constructor functions that we use as the .constructor and
110 // .constructor.prototype properties for functions that return Generator
111 // objects. For full spec compliance, you may wish to configure your
112 // minifier not to mangle the names of these two functions.
113 function Generator() {}
114 function GeneratorFunction() {}
115 function GeneratorFunctionPrototype() {}
116
117 // This is a polyfill for %IteratorPrototype% for environments that
118 // don't natively support it.
119 var IteratorPrototype = {};
120 IteratorPrototype[iteratorSymbol] = function () {
121 return this;
122 };
123
124 var getProto = Object.getPrototypeOf;
125 var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
126 if (NativeIteratorPrototype &&
127 NativeIteratorPrototype !== Op &&
128 hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
129 // This environment has a native %IteratorPrototype%; use it instead
130 // of the polyfill.
131 IteratorPrototype = NativeIteratorPrototype;
132 }
133
134 var Gp = GeneratorFunctionPrototype.prototype =
135 Generator.prototype = Object.create(IteratorPrototype);
136 GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
137 GeneratorFunctionPrototype.constructor = GeneratorFunction;
138 GeneratorFunctionPrototype[toStringTagSymbol] =
139 GeneratorFunction.displayName = "GeneratorFunction";
140
141 // Helper for defining the .next, .throw, and .return methods of the
142 // Iterator interface in terms of a single ._invoke method.
143 function defineIteratorMethods(prototype) {
144 ["next", "throw", "return"].forEach(function(method) {
145 prototype[method] = function(arg) {
146 return this._invoke(method, arg);
147 };
148 });
149 }
150
151 exports.isGeneratorFunction = function(genFun) {
152 var ctor = typeof genFun === "function" && genFun.constructor;
153 return ctor
154 ? ctor === GeneratorFunction ||
155 // For the native GeneratorFunction constructor, the best we can
156 // do is to check its .name property.
157 (ctor.displayName || ctor.name) === "GeneratorFunction"
158 : false;
159 };
160
161 exports.mark = function(genFun) {
162 if (Object.setPrototypeOf) {
163 Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
164 } else {
165 genFun.__proto__ = GeneratorFunctionPrototype;
166 if (!(toStringTagSymbol in genFun)) {
167 genFun[toStringTagSymbol] = "GeneratorFunction";
168 }
169 }
170 genFun.prototype = Object.create(Gp);
171 return genFun;
172 };
173
174 // Within the body of any async function, `await x` is transformed to
175 // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
176 // `hasOwn.call(value, "__await")` to determine if the yielded value is
177 // meant to be awaited.
178 exports.awrap = function(arg) {
179 return { __await: arg };
180 };
181
182 function AsyncIterator(generator, PromiseImpl) {
183 function invoke(method, arg, resolve, reject) {
184 var record = tryCatch(generator[method], generator, arg);
185 if (record.type === "throw") {
186 reject(record.arg);
187 } else {
188 var result = record.arg;
189 var value = result.value;
190 if (value &&
191 typeof value === "object" &&
192 hasOwn.call(value, "__await")) {
193 return PromiseImpl.resolve(value.__await).then(function(value) {
194 invoke("next", value, resolve, reject);
195 }, function(err) {
196 invoke("throw", err, resolve, reject);
197 });
198 }
199
200 return PromiseImpl.resolve(value).then(function(unwrapped) {
201 // When a yielded Promise is resolved, its final value becomes
202 // the .value of the Promise<{value,done}> result for the
203 // current iteration.
204 result.value = unwrapped;
205 resolve(result);
206 }, function(error) {
207 // If a rejected Promise was yielded, throw the rejection back
208 // into the async generator function so it can be handled there.
209 return invoke("throw", error, resolve, reject);
210 });
211 }
212 }
213
214 var previousPromise;
215
216 function enqueue(method, arg) {
217 function callInvokeWithMethodAndArg() {
218 return new PromiseImpl(function(resolve, reject) {
219 invoke(method, arg, resolve, reject);
220 });
221 }
222
223 return previousPromise =
224 // If enqueue has been called before, then we want to wait until
225 // all previous Promises have been resolved before calling invoke,
226 // so that results are always delivered in the correct order. If
227 // enqueue has not been called before, then it is important to
228 // call invoke immediately, without waiting on a callback to fire,
229 // so that the async generator function has the opportunity to do
230 // any necessary setup in a predictable way. This predictability
231 // is why the Promise constructor synchronously invokes its
232 // executor callback, and why async functions synchronously
233 // execute code before the first await. Since we implement simple
234 // async functions in terms of async generators, it is especially
235 // important to get this right, even though it requires care.
236 previousPromise ? previousPromise.then(
237 callInvokeWithMethodAndArg,
238 // Avoid propagating failures to Promises returned by later
239 // invocations of the iterator.
240 callInvokeWithMethodAndArg
241 ) : callInvokeWithMethodAndArg();
242 }
243
244 // Define the unified helper method that is used to implement .next,
245 // .throw, and .return (see defineIteratorMethods).
246 this._invoke = enqueue;
247 }
248
249 defineIteratorMethods(AsyncIterator.prototype);
250 AsyncIterator.prototype[asyncIteratorSymbol] = function () {
251 return this;
252 };
253 exports.AsyncIterator = AsyncIterator;
254
255 // Note that simple async functions are implemented on top of
256 // AsyncIterator objects; they just return a Promise for the value of
257 // the final result produced by the iterator.
258 exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
259 if (PromiseImpl === void 0) PromiseImpl = Promise;
260
261 var iter = new AsyncIterator(
262 wrap(innerFn, outerFn, self, tryLocsList),
263 PromiseImpl
264 );
265
266 return exports.isGeneratorFunction(outerFn)
267 ? iter // If outerFn is a generator, return the full iterator.
268 : iter.next().then(function(result) {
269 return result.done ? result.value : iter.next();
270 });
271 };
272
273 function makeInvokeMethod(innerFn, self, context) {
274 var state = GenStateSuspendedStart;
275
276 return function invoke(method, arg) {
277 if (state === GenStateExecuting) {
278 throw new Error("Generator is already running");
279 }
280
281 if (state === GenStateCompleted) {
282 if (method === "throw") {
283 throw arg;
284 }
285
286 // Be forgiving, per 25.3.3.3.3 of the spec:
287 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
288 return doneResult();
289 }
290
291 context.method = method;
292 context.arg = arg;
293
294 while (true) {
295 var delegate = context.delegate;
296 if (delegate) {
297 var delegateResult = maybeInvokeDelegate(delegate, context);
298 if (delegateResult) {
299 if (delegateResult === ContinueSentinel) continue;
300 return delegateResult;
301 }
302 }
303
304 if (context.method === "next") {
305 // Setting context._sent for legacy support of Babel's
306 // function.sent implementation.
307 context.sent = context._sent = context.arg;
308
309 } else if (context.method === "throw") {
310 if (state === GenStateSuspendedStart) {
311 state = GenStateCompleted;
312 throw context.arg;
313 }
314
315 context.dispatchException(context.arg);
316
317 } else if (context.method === "return") {
318 context.abrupt("return", context.arg);
319 }
320
321 state = GenStateExecuting;
322
323 var record = tryCatch(innerFn, self, context);
324 if (record.type === "normal") {
325 // If an exception is thrown from innerFn, we leave state ===
326 // GenStateExecuting and loop back for another invocation.
327 state = context.done
328 ? GenStateCompleted
329 : GenStateSuspendedYield;
330
331 if (record.arg === ContinueSentinel) {
332 continue;
333 }
334
335 return {
336 value: record.arg,
337 done: context.done
338 };
339
340 } else if (record.type === "throw") {
341 state = GenStateCompleted;
342 // Dispatch the exception by looping back around to the
343 // context.dispatchException(context.arg) call above.
344 context.method = "throw";
345 context.arg = record.arg;
346 }
347 }
348 };
349 }
350
351 // Call delegate.iterator[context.method](context.arg) and handle the
352 // result, either by returning a { value, done } result from the
353 // delegate iterator, or by modifying context.method and context.arg,
354 // setting context.delegate to null, and returning the ContinueSentinel.
355 function maybeInvokeDelegate(delegate, context) {
356 var method = delegate.iterator[context.method];
357 if (method === undefined$1) {
358 // A .throw or .return when the delegate iterator has no .throw
359 // method always terminates the yield* loop.
360 context.delegate = null;
361
362 if (context.method === "throw") {
363 // Note: ["return"] must be used for ES3 parsing compatibility.
364 if (delegate.iterator["return"]) {
365 // If the delegate iterator has a return method, give it a
366 // chance to clean up.
367 context.method = "return";
368 context.arg = undefined$1;
369 maybeInvokeDelegate(delegate, context);
370
371 if (context.method === "throw") {
372 // If maybeInvokeDelegate(context) changed context.method from
373 // "return" to "throw", let that override the TypeError below.
374 return ContinueSentinel;
375 }
376 }
377
378 context.method = "throw";
379 context.arg = new TypeError(
380 "The iterator does not provide a 'throw' method");
381 }
382
383 return ContinueSentinel;
384 }
385
386 var record = tryCatch(method, delegate.iterator, context.arg);
387
388 if (record.type === "throw") {
389 context.method = "throw";
390 context.arg = record.arg;
391 context.delegate = null;
392 return ContinueSentinel;
393 }
394
395 var info = record.arg;
396
397 if (! info) {
398 context.method = "throw";
399 context.arg = new TypeError("iterator result is not an object");
400 context.delegate = null;
401 return ContinueSentinel;
402 }
403
404 if (info.done) {
405 // Assign the result of the finished delegate to the temporary
406 // variable specified by delegate.resultName (see delegateYield).
407 context[delegate.resultName] = info.value;
408
409 // Resume execution at the desired location (see delegateYield).
410 context.next = delegate.nextLoc;
411
412 // If context.method was "throw" but the delegate handled the
413 // exception, let the outer generator proceed normally. If
414 // context.method was "next", forget context.arg since it has been
415 // "consumed" by the delegate iterator. If context.method was
416 // "return", allow the original .return call to continue in the
417 // outer generator.
418 if (context.method !== "return") {
419 context.method = "next";
420 context.arg = undefined$1;
421 }
422
423 } else {
424 // Re-yield the result returned by the delegate method.
425 return info;
426 }
427
428 // The delegate iterator is finished, so forget it and continue with
429 // the outer generator.
430 context.delegate = null;
431 return ContinueSentinel;
432 }
433
434 // Define Generator.prototype.{next,throw,return} in terms of the
435 // unified ._invoke helper method.
436 defineIteratorMethods(Gp);
437
438 Gp[toStringTagSymbol] = "Generator";
439
440 // A Generator should always return itself as the iterator object when the
441 // @@iterator function is called on it. Some browsers' implementations of the
442 // iterator prototype chain incorrectly implement this, causing the Generator
443 // object to not be returned from this call. This ensures that doesn't happen.
444 // See https://github.com/facebook/regenerator/issues/274 for more details.
445 Gp[iteratorSymbol] = function() {
446 return this;
447 };
448
449 Gp.toString = function() {
450 return "[object Generator]";
451 };
452
453 function pushTryEntry(locs) {
454 var entry = { tryLoc: locs[0] };
455
456 if (1 in locs) {
457 entry.catchLoc = locs[1];
458 }
459
460 if (2 in locs) {
461 entry.finallyLoc = locs[2];
462 entry.afterLoc = locs[3];
463 }
464
465 this.tryEntries.push(entry);
466 }
467
468 function resetTryEntry(entry) {
469 var record = entry.completion || {};
470 record.type = "normal";
471 delete record.arg;
472 entry.completion = record;
473 }
474
475 function Context(tryLocsList) {
476 // The root entry object (effectively a try statement without a catch
477 // or a finally block) gives us a place to store values thrown from
478 // locations where there is no enclosing try statement.
479 this.tryEntries = [{ tryLoc: "root" }];
480 tryLocsList.forEach(pushTryEntry, this);
481 this.reset(true);
482 }
483
484 exports.keys = function(object) {
485 var keys = [];
486 for (var key in object) {
487 keys.push(key);
488 }
489 keys.reverse();
490
491 // Rather than returning an object with a next method, we keep
492 // things simple and return the next function itself.
493 return function next() {
494 while (keys.length) {
495 var key = keys.pop();
496 if (key in object) {
497 next.value = key;
498 next.done = false;
499 return next;
500 }
501 }
502
503 // To avoid creating an additional object, we just hang the .value
504 // and .done properties off the next function object itself. This
505 // also ensures that the minifier will not anonymize the function.
506 next.done = true;
507 return next;
508 };
509 };
510
511 function values(iterable) {
512 if (iterable) {
513 var iteratorMethod = iterable[iteratorSymbol];
514 if (iteratorMethod) {
515 return iteratorMethod.call(iterable);
516 }
517
518 if (typeof iterable.next === "function") {
519 return iterable;
520 }
521
522 if (!isNaN(iterable.length)) {
523 var i = -1, next = function next() {
524 while (++i < iterable.length) {
525 if (hasOwn.call(iterable, i)) {
526 next.value = iterable[i];
527 next.done = false;
528 return next;
529 }
530 }
531
532 next.value = undefined$1;
533 next.done = true;
534
535 return next;
536 };
537
538 return next.next = next;
539 }
540 }
541
542 // Return an iterator with no values.
543 return { next: doneResult };
544 }
545 exports.values = values;
546
547 function doneResult() {
548 return { value: undefined$1, done: true };
549 }
550
551 Context.prototype = {
552 constructor: Context,
553
554 reset: function(skipTempReset) {
555 this.prev = 0;
556 this.next = 0;
557 // Resetting context._sent for legacy support of Babel's
558 // function.sent implementation.
559 this.sent = this._sent = undefined$1;
560 this.done = false;
561 this.delegate = null;
562
563 this.method = "next";
564 this.arg = undefined$1;
565
566 this.tryEntries.forEach(resetTryEntry);
567
568 if (!skipTempReset) {
569 for (var name in this) {
570 // Not sure about the optimal order of these conditions:
571 if (name.charAt(0) === "t" &&
572 hasOwn.call(this, name) &&
573 !isNaN(+name.slice(1))) {
574 this[name] = undefined$1;
575 }
576 }
577 }
578 },
579
580 stop: function() {
581 this.done = true;
582
583 var rootEntry = this.tryEntries[0];
584 var rootRecord = rootEntry.completion;
585 if (rootRecord.type === "throw") {
586 throw rootRecord.arg;
587 }
588
589 return this.rval;
590 },
591
592 dispatchException: function(exception) {
593 if (this.done) {
594 throw exception;
595 }
596
597 var context = this;
598 function handle(loc, caught) {
599 record.type = "throw";
600 record.arg = exception;
601 context.next = loc;
602
603 if (caught) {
604 // If the dispatched exception was caught by a catch block,
605 // then let that catch block handle the exception normally.
606 context.method = "next";
607 context.arg = undefined$1;
608 }
609
610 return !! caught;
611 }
612
613 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
614 var entry = this.tryEntries[i];
615 var record = entry.completion;
616
617 if (entry.tryLoc === "root") {
618 // Exception thrown outside of any try block that could handle
619 // it, so set the completion value of the entire function to
620 // throw the exception.
621 return handle("end");
622 }
623
624 if (entry.tryLoc <= this.prev) {
625 var hasCatch = hasOwn.call(entry, "catchLoc");
626 var hasFinally = hasOwn.call(entry, "finallyLoc");
627
628 if (hasCatch && hasFinally) {
629 if (this.prev < entry.catchLoc) {
630 return handle(entry.catchLoc, true);
631 } else if (this.prev < entry.finallyLoc) {
632 return handle(entry.finallyLoc);
633 }
634
635 } else if (hasCatch) {
636 if (this.prev < entry.catchLoc) {
637 return handle(entry.catchLoc, true);
638 }
639
640 } else if (hasFinally) {
641 if (this.prev < entry.finallyLoc) {
642 return handle(entry.finallyLoc);
643 }
644
645 } else {
646 throw new Error("try statement without catch or finally");
647 }
648 }
649 }
650 },
651
652 abrupt: function(type, arg) {
653 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
654 var entry = this.tryEntries[i];
655 if (entry.tryLoc <= this.prev &&
656 hasOwn.call(entry, "finallyLoc") &&
657 this.prev < entry.finallyLoc) {
658 var finallyEntry = entry;
659 break;
660 }
661 }
662
663 if (finallyEntry &&
664 (type === "break" ||
665 type === "continue") &&
666 finallyEntry.tryLoc <= arg &&
667 arg <= finallyEntry.finallyLoc) {
668 // Ignore the finally entry if control is not jumping to a
669 // location outside the try/catch block.
670 finallyEntry = null;
671 }
672
673 var record = finallyEntry ? finallyEntry.completion : {};
674 record.type = type;
675 record.arg = arg;
676
677 if (finallyEntry) {
678 this.method = "next";
679 this.next = finallyEntry.finallyLoc;
680 return ContinueSentinel;
681 }
682
683 return this.complete(record);
684 },
685
686 complete: function(record, afterLoc) {
687 if (record.type === "throw") {
688 throw record.arg;
689 }
690
691 if (record.type === "break" ||
692 record.type === "continue") {
693 this.next = record.arg;
694 } else if (record.type === "return") {
695 this.rval = this.arg = record.arg;
696 this.method = "return";
697 this.next = "end";
698 } else if (record.type === "normal" && afterLoc) {
699 this.next = afterLoc;
700 }
701
702 return ContinueSentinel;
703 },
704
705 finish: function(finallyLoc) {
706 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
707 var entry = this.tryEntries[i];
708 if (entry.finallyLoc === finallyLoc) {
709 this.complete(entry.completion, entry.afterLoc);
710 resetTryEntry(entry);
711 return ContinueSentinel;
712 }
713 }
714 },
715
716 "catch": function(tryLoc) {
717 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
718 var entry = this.tryEntries[i];
719 if (entry.tryLoc === tryLoc) {
720 var record = entry.completion;
721 if (record.type === "throw") {
722 var thrown = record.arg;
723 resetTryEntry(entry);
724 }
725 return thrown;
726 }
727 }
728
729 // The context.catch method must only be called with a location
730 // argument that corresponds to a known catch block.
731 throw new Error("illegal catch attempt");
732 },
733
734 delegateYield: function(iterable, resultName, nextLoc) {
735 this.delegate = {
736 iterator: values(iterable),
737 resultName: resultName,
738 nextLoc: nextLoc
739 };
740
741 if (this.method === "next") {
742 // Deliberately forget the last sent value so that we don't
743 // accidentally pass it on to the delegate.
744 this.arg = undefined$1;
745 }
746
747 return ContinueSentinel;
748 }
749 };
750
751 // Regardless of whether this script is executing as a CommonJS module
752 // or not, return the runtime object so that we can declare the variable
753 // regeneratorRuntime in the outer scope, which allows this module to be
754 // injected easily by `bin/regenerator --include-runtime script.js`.
755 return exports;
756
757}(
758 // If this script is executing as a CommonJS module, use module.exports
759 // as the regeneratorRuntime namespace. Otherwise create a new empty
760 // object. Either way, the resulting object will be used to initialize
761 // the regeneratorRuntime variable at the top of this file.
762 module.exports
763));
764
765try {
766 regeneratorRuntime = runtime;
767} catch (accidentalStrictMode) {
768 // This module should not be running in strict mode, so the above
769 // assignment should always work unless something is misconfigured. Just
770 // in case runtime.js accidentally runs in strict mode, we can escape
771 // strict mode using a global Function call. This could conceivably fail
772 // if a Content Security Policy forbids using Function, but in that case
773 // the proper solution is to fix the accidental strict mode problem. If
774 // you've misconfigured your bundler to force strict mode and applied a
775 // CSP to forbid Function, and you're not willing to fix either of those
776 // problems, please detail your unique predicament in a GitHub issue.
777 Function("r", "regeneratorRuntime = r")(runtime);
778}
779});
780
781var regenerator = runtime_1;
782
783function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
784 try {
785 var info = gen[key](arg);
786 var value = info.value;
787 } catch (error) {
788 reject(error);
789 return;
790 }
791
792 if (info.done) {
793 resolve(value);
794 } else {
795 Promise.resolve(value).then(_next, _throw);
796 }
797}
798
799function _asyncToGenerator(fn) {
800 return function () {
801 var self = this,
802 args = arguments;
803 return new Promise(function (resolve, reject) {
804 var gen = fn.apply(self, args);
805
806 function _next(value) {
807 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
808 }
809
810 function _throw(err) {
811 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
812 }
813
814 _next(undefined);
815 });
816 };
817}
818
819var asyncToGenerator = _asyncToGenerator;
820
821function _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); }; }
822
823function _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; } }
824var id = 0;
825
826var move = function move(pixel) {
827 return "translate3d(0,".concat(pixel, "px,0)");
828};
829
830var ToastContext = React__default.createContext(function () {
831 throw new Error("For Toast to work it needs to be part of a ToastHub's tree, which has to be declared at an upper level!");
832});
833
834var ToastHubProvider = /*#__PURE__*/function (_React$PureComponent) {
835 getPrototypeOf._inherits(ToastHubProvider, _React$PureComponent);
836
837 var _super = _createSuper(ToastHubProvider);
838
839 function ToastHubProvider() {
840 var _this;
841
842 getPrototypeOf._classCallCheck(this, ToastHubProvider);
843
844 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
845 args[_key] = arguments[_key];
846 }
847
848 _this = _super.call.apply(_super, [this].concat(args));
849
850 defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "state", {
851 items: [],
852 leaving: [],
853 preLeaving: []
854 });
855
856 defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "cancelMap", new WeakMap());
857
858 defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "add", function (msg) {
859 var threshold = _this.props.threshold;
860
861 _this.setState(function (state) {
862 // This calls cancel on all leaving animations that stack up too much
863 if (threshold !== Infinity) {
864 state.leaving.slice(threshold - 1).forEach(function (item) {
865 return _this.cancel(item, true);
866 });
867 }
868
869 return {
870 items: [].concat(toConsumableArray._toConsumableArray(state.items), [{
871 key: id++,
872 msg: msg
873 }]),
874 preLeaving: []
875 };
876 });
877 });
878
879 defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "remove", function (item) {
880 _this.setState(function (state) {
881 return {
882 items: state.items.filter(function (i) {
883 return i.key !== item.key;
884 }),
885 leaving: state.leaving.includes(item) ? state.leaving : [item].concat(toConsumableArray._toConsumableArray(state.leaving))
886 };
887 });
888 });
889
890 defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "config", function (item, state) {
891 var config = springs.springs.lazy; // Return custom configs on leave (includes the life-line duration)
892
893 return state === 'leave' ? [{
894 duration: _this.props.timeout
895 }, config, config] : config;
896 });
897
898 defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "cancel", function (item) {
899 var secondPass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
900
901 if (_this.cancelMap.has(item)) {
902 var fn = _this.cancelMap.get(item);
903
904 fn(); // There are 3 passes: lifeline, opacity->0, height->0
905
906 if (secondPass) fn();
907 }
908 });
909
910 defineProperty._defineProperty(getPrototypeOf._assertThisInitialized(_this), "leave", function (item) {
911 return /*#__PURE__*/function () {
912 var _ref = asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(next, cancel) {
913 return regenerator.wrap(function _callee$(_context) {
914 while (1) {
915 switch (_context.prev = _context.next) {
916 case 0:
917 // Save cancel so that it can be used interactively
918 _this.cancelMap.set(item, cancel); // Lifeline first
919
920
921 _context.next = 3;
922 return next({
923 to: {
924 life: '0%'
925 }
926 });
927
928 case 3:
929 // Add to the pre-leaving list, to know when there are no more toasts
930 // displayed even though they are still finishing their leaving transition.
931 _this.setState(function (state) {
932 return {
933 preLeaving: [].concat(toConsumableArray._toConsumableArray(state.preLeaving), [item])
934 };
935 }); // Then fade out
936
937
938 _context.next = 6;
939 return next({
940 to: {
941 opacity: 0
942 }
943 });
944
945 case 6:
946 _context.next = 8;
947 return next({
948 to: {
949 height: 0
950 }
951 }, true);
952
953 case 8:
954 _this.setState(function (state) {
955 return {
956 leaving: state.leaving.filter(function (i) {
957 return i.key !== item.key;
958 }),
959 preLeaving: state.preLeaving.filter(function (i) {
960 return i.key !== item.key;
961 })
962 };
963 });
964
965 case 9:
966 case "end":
967 return _context.stop();
968 }
969 }
970 }, _callee);
971 }));
972
973 return function (_x, _x2) {
974 return _ref.apply(this, arguments);
975 };
976 }();
977 });
978
979 return _this;
980 }
981
982 getPrototypeOf._createClass(ToastHubProvider, [{
983 key: "render",
984 value: function render() {
985 var _this$props = this.props,
986 children = _this$props.children,
987 showIndicator = _this$props.showIndicator,
988 position = _this$props.position,
989 top = _this$props.top,
990 shift = _this$props.shift;
991 var _this$state = this.state,
992 items = _this$state.items,
993 leaving = _this$state.leaving,
994 preLeaving = _this$state.preLeaving;
995 var renderList = items.length > 0 || leaving.length > 0;
996 var itemsVisible = leaving.length === preLeaving.length && leaving.length > 0 ? false : renderList;
997 return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ToastContext.Provider, {
998 value: {
999 itemsVisible: itemsVisible,
1000 add: this.add
1001 }
1002 }, children), renderList && /*#__PURE__*/React__default.createElement(RootPortal.default, null, /*#__PURE__*/React__default.createElement(ToastList, _extends._extends({
1003 config: this.config,
1004 items: items,
1005 leave: this.leave,
1006 position: position,
1007 remove: this.remove,
1008 showIndicator: showIndicator,
1009 top: top
1010 }, components.stylingProps(this), {
1011 shift: shift
1012 }))));
1013 }
1014 }]);
1015
1016 return ToastHubProvider;
1017}(React__default.PureComponent); // ToastList is separated from ToastHubProvider so we can skip its rendering
1018
1019
1020defineProperty._defineProperty(ToastHubProvider, "propTypes", {
1021 children: index.PropTypes.node,
1022 position: index.PropTypes.PropTypes.oneOf(['left', 'center', 'right']),
1023 shift: index.PropTypes.number,
1024 showIndicator: index.PropTypes.bool,
1025 threshold: index.PropTypes.number,
1026 timeout: index.PropTypes.number,
1027 top: index.PropTypes.bool
1028});
1029
1030defineProperty._defineProperty(ToastHubProvider, "defaultProps", {
1031 position: 'right',
1032 showIndicator: false,
1033 threshold: Infinity,
1034 timeout: 4000,
1035 top: false
1036});
1037
1038var _StyledDiv = _styled__default("div").withConfig({
1039 displayName: "ToastHub___StyledDiv",
1040 componentId: "sc-1y0i8xl-0"
1041})(["position:fixed;z-index:1000;top:", ";bottom:", ";left:", "px;right:", "px;display:flex;margin:0 auto;flex-direction:", ";pointer-events:none;align-items:", ";"], function (p) {
1042 return p._css;
1043}, function (p) {
1044 return p._css2;
1045}, function (p) {
1046 return p._css3;
1047}, function (p) {
1048 return p._css4;
1049}, function (p) {
1050 return p._css5;
1051}, function (p) {
1052 return p._css6;
1053});
1054
1055var _StyledAnimatedDiv = _styled__default(web.extendedAnimated.div).withConfig({
1056 displayName: "ToastHub___StyledAnimatedDiv",
1057 componentId: "sc-1y0i8xl-1"
1058})(["box-sizing:border-box;position:relative;width:", ";"], function (p) {
1059 return p._css7;
1060});
1061
1062var _StyledDiv2 = _styled__default("div").withConfig({
1063 displayName: "ToastHub___StyledDiv2",
1064 componentId: "sc-1y0i8xl-2"
1065})(["display:grid;grid-template-columns:1fr;grid-gap:10px;height:", "px;padding:", "px ", "px;overflow:hidden;margin-top:", ";margin-bottom:", ";", ";color:", ";background:", ";border-radius:", "px;"], function (p) {
1066 return p._css8;
1067}, function (p) {
1068 return p._css9;
1069}, function (p) {
1070 return p._css10;
1071}, function (p) {
1072 return p._css11;
1073}, function (p) {
1074 return p._css12;
1075}, function (p) {
1076 return p._css13;
1077}, function (p) {
1078 return p._css14;
1079}, function (p) {
1080 return p._css15;
1081}, constants.RADIUS);
1082
1083var _StyledAnimatedDiv2 = _styled__default(web.extendedAnimated.div).withConfig({
1084 displayName: "ToastHub___StyledAnimatedDiv2",
1085 componentId: "sc-1y0i8xl-3"
1086})(["position:absolute;bottom:", ";left:0;width:auto;height:5px;background-image:linear-gradient( 130deg,#00b4e6,#00f0e0 );"], function (p) {
1087 return p._css16;
1088});
1089
1090var ToastList = React__default.memo(function ToastList(_ref2) {
1091 var config = _ref2.config,
1092 items = _ref2.items,
1093 leave = _ref2.leave,
1094 position = _ref2.position,
1095 remove = _ref2.remove,
1096 showIndicator = _ref2.showIndicator,
1097 top = _ref2.top,
1098 shift = _ref2.shift,
1099 props = objectWithoutProperties._objectWithoutProperties(_ref2, ["config", "items", "leave", "position", "remove", "showIndicator", "top", "shift"]);
1100
1101 var theme = Theme.useTheme();
1102
1103 var _useViewport = Viewport.useViewport(),
1104 below = _useViewport.below;
1105
1106 var spacing = below('medium') ? 2 * constants.GU : 3 * constants.GU;
1107 return /*#__PURE__*/React__default.createElement(_StyledDiv, _extends._extends({}, props, {
1108 _css: top ? "".concat(spacing, "px") : 'unset',
1109 _css2: top ? 'unset' : "".concat(spacing, "px"),
1110 _css3: spacing + (shift || 0),
1111 _css4: spacing + (shift || 0),
1112 _css5: top ? 'column-reverse' : 'column',
1113 _css6: function () {
1114 if (below('medium')) return 'center';
1115 if (position === 'left') return 'flex-start';
1116 if (position === 'right') return 'flex-end';
1117 return 'center';
1118 }()
1119 }), /*#__PURE__*/React__default.createElement(web.Transition, {
1120 native: true,
1121 items: items,
1122 keys: function keys(item) {
1123 return item.key;
1124 },
1125 from: {
1126 opacity: 0,
1127 height: 0,
1128 life: '100%',
1129 transform: move(30)
1130 },
1131 enter: {
1132 opacity: 1,
1133 height: 'auto',
1134 transform: move(0)
1135 },
1136 leave: leave,
1137 onRest: remove,
1138 config: config
1139 }, function (item) {
1140 return (
1141 /* eslint-disable react/prop-types */
1142 function (_ref3) {
1143 var life = _ref3.life,
1144 props = objectWithoutProperties._objectWithoutProperties(_ref3, ["life"]);
1145
1146 return /*#__PURE__*/React__default.createElement(_StyledAnimatedDiv, {
1147 style: props,
1148 _css7: below('medium') ? '100%' : '42ch'
1149 }, /*#__PURE__*/React__default.createElement(_StyledDiv2, {
1150 _css8: 6 * constants.GU,
1151 _css9: 2 * constants.GU,
1152 _css10: 2.5 * constants.GU,
1153 _css11: top ? '0' : "".concat(1.25 * constants.GU, "px"),
1154 _css12: top ? "".concat(1.25 * constants.GU, "px") : '0',
1155 _css13: textStyles.textStyle('body3'),
1156 _css14: theme.floatingContent,
1157 _css15: theme.floating.alpha(0.95)
1158 }, showIndicator && /*#__PURE__*/React__default.createElement(_StyledAnimatedDiv2, {
1159 style: {
1160 right: life
1161 },
1162 _css16: top ? "".concat(1.25 * constants.GU, "px") : '0'
1163 }), /*#__PURE__*/React__default.createElement("p", null, item.msg)));
1164 }
1165 );
1166 }
1167 /* eslint-enable react/prop-types */
1168 ));
1169});
1170ToastList.propTypes = {
1171 config: index.PropTypes.func,
1172 items: index.PropTypes.array,
1173 leave: index.PropTypes.func,
1174 position: index.PropTypes.PropTypes.oneOf(['left', 'center', 'right']),
1175 remove: index.PropTypes.func,
1176 shift: index.PropTypes.number,
1177 showIndicator: index.PropTypes.bool,
1178 top: index.PropTypes.bool
1179};
1180
1181var useToast = function useToast() {
1182 return React.useContext(ToastContext).add;
1183};
1184
1185var Toast = function Toast(props) {
1186 return props.children(useToast());
1187};
1188
1189exports.Toast = Toast;
1190exports.ToastContext = ToastContext;
1191exports.default = ToastHubProvider;
1192exports.useToast = useToast;
1193//# sourceMappingURL=ToastHub.js.map