UNPKG

81.4 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (global = global || self, factory(global.aphrodite = {}));
5}(this, function (exports) { 'use strict';
6
7 function _typeof(obj) {
8 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
9 _typeof = function (obj) {
10 return typeof obj;
11 };
12 } else {
13 _typeof = function (obj) {
14 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
15 };
16 }
17
18 return _typeof(obj);
19 }
20
21 function _defineProperty(obj, key, value) {
22 if (key in obj) {
23 Object.defineProperty(obj, key, {
24 value: value,
25 enumerable: true,
26 configurable: true,
27 writable: true
28 });
29 } else {
30 obj[key] = value;
31 }
32
33 return obj;
34 }
35
36 function _objectSpread(target) {
37 for (var i = 1; i < arguments.length; i++) {
38 var source = arguments[i] != null ? arguments[i] : {};
39 var ownKeys = Object.keys(source);
40
41 if (typeof Object.getOwnPropertySymbols === 'function') {
42 ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
43 return Object.getOwnPropertyDescriptor(source, sym).enumerable;
44 }));
45 }
46
47 ownKeys.forEach(function (key) {
48 _defineProperty(target, key, source[key]);
49 });
50 }
51
52 return target;
53 }
54
55 function _toConsumableArray(arr) {
56 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
57 }
58
59 function _arrayWithoutHoles(arr) {
60 if (Array.isArray(arr)) {
61 for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
62
63 return arr2;
64 }
65 }
66
67 function _iterableToArray(iter) {
68 if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
69 }
70
71 function _nonIterableSpread() {
72 throw new TypeError("Invalid attempt to spread non-iterable instance");
73 }
74
75 function hash(str) {
76 var hash = 5381,
77 i = str.length;
78
79 while(i) {
80 hash = (hash * 33) ^ str.charCodeAt(--i);
81 }
82
83 /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
84 * integers. Since we want the results to be always positive, convert the
85 * signed int to an unsigned by doing an unsigned bitshift. */
86 return hash >>> 0;
87 }
88
89 var stringHash = hash;
90
91 /* @flow */
92 /* ::
93 type ObjectMap = { [id:string]: any };
94 */
95
96 var UPPERCASE_RE = /([A-Z])/g;
97
98 var UPPERCASE_RE_TO_KEBAB = function UPPERCASE_RE_TO_KEBAB(match
99 /* : string */
100 ) {
101 return (
102 /* : string */
103 "-".concat(match.toLowerCase())
104 );
105 };
106
107 var kebabifyStyleName = function kebabifyStyleName(string
108 /* : string */
109 )
110 /* : string */
111 {
112 var result = string.replace(UPPERCASE_RE, UPPERCASE_RE_TO_KEBAB);
113
114 if (result[0] === 'm' && result[1] === 's' && result[2] === '-') {
115 return "-".concat(result);
116 }
117
118 return result;
119 };
120 /**
121 * CSS properties which accept numbers but are not in units of "px".
122 * Taken from React's CSSProperty.js
123 */
124
125 var isUnitlessNumber = {
126 animationIterationCount: true,
127 borderImageOutset: true,
128 borderImageSlice: true,
129 borderImageWidth: true,
130 boxFlex: true,
131 boxFlexGroup: true,
132 boxOrdinalGroup: true,
133 columnCount: true,
134 flex: true,
135 flexGrow: true,
136 flexPositive: true,
137 flexShrink: true,
138 flexNegative: true,
139 flexOrder: true,
140 gridRow: true,
141 gridColumn: true,
142 fontWeight: true,
143 lineClamp: true,
144 lineHeight: true,
145 opacity: true,
146 order: true,
147 orphans: true,
148 tabSize: true,
149 widows: true,
150 zIndex: true,
151 zoom: true,
152 // SVG-related properties
153 fillOpacity: true,
154 floodOpacity: true,
155 stopOpacity: true,
156 strokeDasharray: true,
157 strokeDashoffset: true,
158 strokeMiterlimit: true,
159 strokeOpacity: true,
160 strokeWidth: true
161 };
162 /**
163 * Taken from React's CSSProperty.js
164 *
165 * @param {string} prefix vendor-specific prefix, eg: Webkit
166 * @param {string} key style name, eg: transitionDuration
167 * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
168 * WebkitTransitionDuration
169 */
170
171 function prefixKey(prefix, key) {
172 return prefix + key.charAt(0).toUpperCase() + key.substring(1);
173 }
174 /**
175 * Support style names that may come passed in prefixed by adding permutations
176 * of vendor prefixes.
177 * Taken from React's CSSProperty.js
178 */
179
180
181 var prefixes = ['Webkit', 'ms', 'Moz', 'O']; // Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
182 // infinite loop, because it iterates over the newly added props too.
183 // Taken from React's CSSProperty.js
184
185 Object.keys(isUnitlessNumber).forEach(function (prop) {
186 prefixes.forEach(function (prefix) {
187 isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
188 });
189 });
190 var stringifyValue = function stringifyValue(key
191 /* : string */
192 , prop
193 /* : any */
194 )
195 /* : string */
196 {
197 if (typeof prop === "number") {
198 if (isUnitlessNumber[key]) {
199 return "" + prop;
200 } else {
201 return prop + "px";
202 }
203 } else {
204 return '' + prop;
205 }
206 };
207 var stringifyAndImportantifyValue = function stringifyAndImportantifyValue(key
208 /* : string */
209 , prop
210 /* : any */
211 ) {
212 return (
213 /* : string */
214 importantify(stringifyValue(key, prop))
215 );
216 }; // Turn a string into a hash string of base-36 values (using letters and numbers)
217 // eslint-disable-next-line no-unused-vars
218
219 var hashString = function hashString(string
220 /* : string */
221 , key
222 /* : ?string */
223 ) {
224 return (
225 /* string */
226 stringHash(string).toString(36)
227 );
228 }; // Hash a javascript object using JSON.stringify. This is very fast, about 3
229 // microseconds on my computer for a sample object:
230 // http://jsperf.com/test-hashfnv32a-hash/5
231 //
232 // Note that this uses JSON.stringify to stringify the objects so in order for
233 // this to produce consistent hashes browsers need to have a consistent
234 // ordering of objects. Ben Alpert says that Facebook depends on this, so we
235 // can probably depend on this too.
236
237 var hashObject = function hashObject(object
238 /* : ObjectMap */
239 ) {
240 return (
241 /* : string */
242 hashString(JSON.stringify(object))
243 );
244 }; // Given a single style value string like the "b" from "a: b;", adds !important
245 // to generate "b !important".
246
247 var importantify = function importantify(string
248 /* : string */
249 ) {
250 return (
251 /* : string */
252 // Bracket string character access is very fast, and in the default case we
253 // normally don't expect there to be "!important" at the end of the string
254 // so we can use this simple check to take an optimized path. If there
255 // happens to be a "!" in this position, we follow up with a more thorough
256 // check.
257 string[string.length - 10] === '!' && string.slice(-11) === ' !important' ? string : "".concat(string, " !important")
258 );
259 };
260
261 var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
262
263 function unwrapExports (x) {
264 return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x;
265 }
266
267 function createCommonjsModule(fn, module) {
268 return module = { exports: {} }, fn(module, module.exports), module.exports;
269 }
270
271 // Use the fastest means possible to execute a task in its own turn, with
272 // priority over other events including IO, animation, reflow, and redraw
273 // events in browsers.
274 //
275 // An exception thrown by a task will permanently interrupt the processing of
276 // subsequent tasks. The higher level `asap` function ensures that if an
277 // exception is thrown by a task, that the task queue will continue flushing as
278 // soon as possible, but if you use `rawAsap` directly, you are responsible to
279 // either ensure that no exceptions are thrown from your task, or to manually
280 // call `rawAsap.requestFlush` if an exception is thrown.
281 var browserRaw = rawAsap;
282 function rawAsap(task) {
283 if (!queue.length) {
284 requestFlush();
285 }
286 // Equivalent to push, but avoids a function call.
287 queue[queue.length] = task;
288 }
289
290 var queue = [];
291 // `requestFlush` is an implementation-specific method that attempts to kick
292 // off a `flush` event as quickly as possible. `flush` will attempt to exhaust
293 // the event queue before yielding to the browser's own event loop.
294 var requestFlush;
295 // The position of the next task to execute in the task queue. This is
296 // preserved between calls to `flush` so that it can be resumed if
297 // a task throws an exception.
298 var index = 0;
299 // If a task schedules additional tasks recursively, the task queue can grow
300 // unbounded. To prevent memory exhaustion, the task queue will periodically
301 // truncate already-completed tasks.
302 var capacity = 1024;
303
304 // The flush function processes all tasks that have been scheduled with
305 // `rawAsap` unless and until one of those tasks throws an exception.
306 // If a task throws an exception, `flush` ensures that its state will remain
307 // consistent and will resume where it left off when called again.
308 // However, `flush` does not make any arrangements to be called again if an
309 // exception is thrown.
310 function flush() {
311 while (index < queue.length) {
312 var currentIndex = index;
313 // Advance the index before calling the task. This ensures that we will
314 // begin flushing on the next task the task throws an error.
315 index = index + 1;
316 queue[currentIndex].call();
317 // Prevent leaking memory for long chains of recursive calls to `asap`.
318 // If we call `asap` within tasks scheduled by `asap`, the queue will
319 // grow, but to avoid an O(n) walk for every task we execute, we don't
320 // shift tasks off the queue after they have been executed.
321 // Instead, we periodically shift 1024 tasks off the queue.
322 if (index > capacity) {
323 // Manually shift all values starting at the index back to the
324 // beginning of the queue.
325 for (var scan = 0, newLength = queue.length - index; scan < newLength; scan++) {
326 queue[scan] = queue[scan + index];
327 }
328 queue.length -= index;
329 index = 0;
330 }
331 }
332 queue.length = 0;
333 index = 0;
334 }
335
336 // `requestFlush` is implemented using a strategy based on data collected from
337 // every available SauceLabs Selenium web driver worker at time of writing.
338 // https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
339
340 // Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
341 // have WebKitMutationObserver but not un-prefixed MutationObserver.
342 // Must use `global` or `self` instead of `window` to work in both frames and web
343 // workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
344
345 /* globals self */
346 var scope = typeof commonjsGlobal !== "undefined" ? commonjsGlobal : self;
347 var BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
348
349 // MutationObservers are desirable because they have high priority and work
350 // reliably everywhere they are implemented.
351 // They are implemented in all modern browsers.
352 //
353 // - Android 4-4.3
354 // - Chrome 26-34
355 // - Firefox 14-29
356 // - Internet Explorer 11
357 // - iPad Safari 6-7.1
358 // - iPhone Safari 7-7.1
359 // - Safari 6-7
360 if (typeof BrowserMutationObserver === "function") {
361 requestFlush = makeRequestCallFromMutationObserver(flush);
362
363 // MessageChannels are desirable because they give direct access to the HTML
364 // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
365 // 11-12, and in web workers in many engines.
366 // Although message channels yield to any queued rendering and IO tasks, they
367 // would be better than imposing the 4ms delay of timers.
368 // However, they do not work reliably in Internet Explorer or Safari.
369
370 // Internet Explorer 10 is the only browser that has setImmediate but does
371 // not have MutationObservers.
372 // Although setImmediate yields to the browser's renderer, it would be
373 // preferrable to falling back to setTimeout since it does not have
374 // the minimum 4ms penalty.
375 // Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
376 // Desktop to a lesser extent) that renders both setImmediate and
377 // MessageChannel useless for the purposes of ASAP.
378 // https://github.com/kriskowal/q/issues/396
379
380 // Timers are implemented universally.
381 // We fall back to timers in workers in most engines, and in foreground
382 // contexts in the following browsers.
383 // However, note that even this simple case requires nuances to operate in a
384 // broad spectrum of browsers.
385 //
386 // - Firefox 3-13
387 // - Internet Explorer 6-9
388 // - iPad Safari 4.3
389 // - Lynx 2.8.7
390 } else {
391 requestFlush = makeRequestCallFromTimer(flush);
392 }
393
394 // `requestFlush` requests that the high priority event queue be flushed as
395 // soon as possible.
396 // This is useful to prevent an error thrown in a task from stalling the event
397 // queue if the exception handled by Node.js’s
398 // `process.on("uncaughtException")` or by a domain.
399 rawAsap.requestFlush = requestFlush;
400
401 // To request a high priority event, we induce a mutation observer by toggling
402 // the text of a text node between "1" and "-1".
403 function makeRequestCallFromMutationObserver(callback) {
404 var toggle = 1;
405 var observer = new BrowserMutationObserver(callback);
406 var node = document.createTextNode("");
407 observer.observe(node, {characterData: true});
408 return function requestCall() {
409 toggle = -toggle;
410 node.data = toggle;
411 };
412 }
413
414 // The message channel technique was discovered by Malte Ubl and was the
415 // original foundation for this library.
416 // http://www.nonblocking.io/2011/06/windownexttick.html
417
418 // Safari 6.0.5 (at least) intermittently fails to create message ports on a
419 // page's first load. Thankfully, this version of Safari supports
420 // MutationObservers, so we don't need to fall back in that case.
421
422 // function makeRequestCallFromMessageChannel(callback) {
423 // var channel = new MessageChannel();
424 // channel.port1.onmessage = callback;
425 // return function requestCall() {
426 // channel.port2.postMessage(0);
427 // };
428 // }
429
430 // For reasons explained above, we are also unable to use `setImmediate`
431 // under any circumstances.
432 // Even if we were, there is another bug in Internet Explorer 10.
433 // It is not sufficient to assign `setImmediate` to `requestFlush` because
434 // `setImmediate` must be called *by name* and therefore must be wrapped in a
435 // closure.
436 // Never forget.
437
438 // function makeRequestCallFromSetImmediate(callback) {
439 // return function requestCall() {
440 // setImmediate(callback);
441 // };
442 // }
443
444 // Safari 6.0 has a problem where timers will get lost while the user is
445 // scrolling. This problem does not impact ASAP because Safari 6.0 supports
446 // mutation observers, so that implementation is used instead.
447 // However, if we ever elect to use timers in Safari, the prevalent work-around
448 // is to add a scroll event listener that calls for a flush.
449
450 // `setTimeout` does not call the passed callback if the delay is less than
451 // approximately 7 in web workers in Firefox 8 through 18, and sometimes not
452 // even then.
453
454 function makeRequestCallFromTimer(callback) {
455 return function requestCall() {
456 // We dispatch a timeout with a specified delay of 0 for engines that
457 // can reliably accommodate that request. This will usually be snapped
458 // to a 4 milisecond delay, but once we're flushing, there's no delay
459 // between events.
460 var timeoutHandle = setTimeout(handleTimer, 0);
461 // However, since this timer gets frequently dropped in Firefox
462 // workers, we enlist an interval handle that will try to fire
463 // an event 20 times per second until it succeeds.
464 var intervalHandle = setInterval(handleTimer, 50);
465
466 function handleTimer() {
467 // Whichever timer succeeds will cancel both timers and
468 // execute the callback.
469 clearTimeout(timeoutHandle);
470 clearInterval(intervalHandle);
471 callback();
472 }
473 };
474 }
475
476 // This is for `asap.js` only.
477 // Its name will be periodically randomized to break any code that depends on
478 // its existence.
479 rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer;
480
481 // rawAsap provides everything we need except exception management.
482
483 // RawTasks are recycled to reduce GC churn.
484 var freeTasks = [];
485 // We queue errors to ensure they are thrown in right order (FIFO).
486 // Array-as-queue is good enough here, since we are just dealing with exceptions.
487 var pendingErrors = [];
488 var requestErrorThrow = browserRaw.makeRequestCallFromTimer(throwFirstError);
489
490 function throwFirstError() {
491 if (pendingErrors.length) {
492 throw pendingErrors.shift();
493 }
494 }
495
496 /**
497 * Calls a task as soon as possible after returning, in its own event, with priority
498 * over other events like animation, reflow, and repaint. An error thrown from an
499 * event will not interrupt, nor even substantially slow down the processing of
500 * other events, but will be rather postponed to a lower priority event.
501 * @param {{call}} task A callable object, typically a function that takes no
502 * arguments.
503 */
504 var browserAsap = asap;
505 function asap(task) {
506 var rawTask;
507 if (freeTasks.length) {
508 rawTask = freeTasks.pop();
509 } else {
510 rawTask = new RawTask();
511 }
512 rawTask.task = task;
513 browserRaw(rawTask);
514 }
515
516 // We wrap tasks with recyclable task objects. A task object implements
517 // `call`, just like a function.
518 function RawTask() {
519 this.task = null;
520 }
521
522 // The sole purpose of wrapping the task is to catch the exception and recycle
523 // the task object after its single use.
524 RawTask.prototype.call = function () {
525 try {
526 this.task.call();
527 } catch (error) {
528 if (asap.onerror) {
529 // This hook exists purely for testing purposes.
530 // Its name will be periodically randomized to break any code that
531 // depends on its existence.
532 asap.onerror(error);
533 } else {
534 // In a web browser, exceptions are not fatal. However, to avoid
535 // slowing down the queue of pending tasks, we rethrow the error in a
536 // lower priority turn.
537 pendingErrors.push(error);
538 requestErrorThrow();
539 }
540 } finally {
541 this.task = null;
542 freeTasks[freeTasks.length] = this;
543 }
544 };
545
546 /* @flow */
547 var MAP_EXISTS = typeof Map !== 'undefined';
548
549 var OrderedElements =
550 /*#__PURE__*/
551 function () {
552 /* ::
553 elements: {[string]: any};
554 keyOrder: string[];
555 */
556 function OrderedElements() {
557 this.elements = {};
558 this.keyOrder = [];
559 }
560
561 var _proto = OrderedElements.prototype;
562
563 _proto.forEach = function forEach(callback
564 /* : (string, any) => void */
565 ) {
566 for (var i = 0; i < this.keyOrder.length; i++) {
567 // (value, key) to match Map's API
568 callback(this.elements[this.keyOrder[i]], this.keyOrder[i]);
569 }
570 };
571
572 _proto.set = function set(key
573 /* : string */
574 , value
575 /* : any */
576 , shouldReorder
577 /* : ?boolean */
578 ) {
579 if (!this.elements.hasOwnProperty(key)) {
580 this.keyOrder.push(key);
581 } else if (shouldReorder) {
582 var index = this.keyOrder.indexOf(key);
583 this.keyOrder.splice(index, 1);
584 this.keyOrder.push(key);
585 }
586
587 if (value == null) {
588 this.elements[key] = value;
589 return;
590 }
591
592 if (MAP_EXISTS && value instanceof Map || value instanceof OrderedElements) {
593 // We have found a nested Map, so we need to recurse so that all
594 // of the nested objects and Maps are merged properly.
595 var nested = this.elements.hasOwnProperty(key) ? this.elements[key] : new OrderedElements();
596 value.forEach(function (value, key) {
597 nested.set(key, value, shouldReorder);
598 });
599 this.elements[key] = nested;
600 return;
601 }
602
603 if (!Array.isArray(value) && _typeof(value) === 'object') {
604 // We have found a nested object, so we need to recurse so that all
605 // of the nested objects and Maps are merged properly.
606 var _nested = this.elements.hasOwnProperty(key) ? this.elements[key] : new OrderedElements();
607
608 var keys = Object.keys(value);
609
610 for (var i = 0; i < keys.length; i += 1) {
611 _nested.set(keys[i], value[keys[i]], shouldReorder);
612 }
613
614 this.elements[key] = _nested;
615 return;
616 }
617
618 this.elements[key] = value;
619 };
620
621 _proto.get = function get(key
622 /* : string */
623 )
624 /* : any */
625 {
626 return this.elements[key];
627 };
628
629 _proto.has = function has(key
630 /* : string */
631 )
632 /* : boolean */
633 {
634 return this.elements.hasOwnProperty(key);
635 };
636
637 _proto.addStyleType = function addStyleType(styleType
638 /* : any */
639 )
640 /* : void */
641 {
642 var _this = this;
643
644 if (MAP_EXISTS && styleType instanceof Map || styleType instanceof OrderedElements) {
645 styleType.forEach(function (value, key) {
646 _this.set(key, value, true);
647 });
648 } else {
649 var keys = Object.keys(styleType);
650
651 for (var i = 0; i < keys.length; i++) {
652 this.set(keys[i], styleType[keys[i]], true);
653 }
654 }
655 };
656
657 return OrderedElements;
658 }();
659
660 var capitalizeString_1 = createCommonjsModule(function (module, exports) {
661
662 Object.defineProperty(exports, "__esModule", {
663 value: true
664 });
665 exports.default = capitalizeString;
666 function capitalizeString(str) {
667 return str.charAt(0).toUpperCase() + str.slice(1);
668 }
669 });
670
671 unwrapExports(capitalizeString_1);
672
673 var prefixProperty_1 = createCommonjsModule(function (module, exports) {
674
675 Object.defineProperty(exports, "__esModule", {
676 value: true
677 });
678 exports.default = prefixProperty;
679
680
681
682 var _capitalizeString2 = _interopRequireDefault(capitalizeString_1);
683
684 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
685
686 function prefixProperty(prefixProperties, property, style) {
687 if (prefixProperties.hasOwnProperty(property)) {
688 var newStyle = {};
689 var requiredPrefixes = prefixProperties[property];
690 var capitalizedProperty = (0, _capitalizeString2.default)(property);
691 var keys = Object.keys(style);
692 for (var i = 0; i < keys.length; i++) {
693 var styleProperty = keys[i];
694 if (styleProperty === property) {
695 for (var j = 0; j < requiredPrefixes.length; j++) {
696 newStyle[requiredPrefixes[j] + capitalizedProperty] = style[property];
697 }
698 }
699 newStyle[styleProperty] = style[styleProperty];
700 }
701 return newStyle;
702 }
703 return style;
704 }
705 });
706
707 unwrapExports(prefixProperty_1);
708
709 var prefixValue_1 = createCommonjsModule(function (module, exports) {
710
711 Object.defineProperty(exports, "__esModule", {
712 value: true
713 });
714 exports.default = prefixValue;
715 function prefixValue(plugins, property, value, style, metaData) {
716 for (var i = 0, len = plugins.length; i < len; ++i) {
717 var processedValue = plugins[i](property, value, style, metaData);
718
719 // we can stop processing if a value is returned
720 // as all plugin criteria are unique
721 if (processedValue) {
722 return processedValue;
723 }
724 }
725 }
726 });
727
728 unwrapExports(prefixValue_1);
729
730 var addNewValuesOnly_1 = createCommonjsModule(function (module, exports) {
731
732 Object.defineProperty(exports, "__esModule", {
733 value: true
734 });
735 exports.default = addNewValuesOnly;
736 function addIfNew(list, value) {
737 if (list.indexOf(value) === -1) {
738 list.push(value);
739 }
740 }
741
742 function addNewValuesOnly(list, values) {
743 if (Array.isArray(values)) {
744 for (var i = 0, len = values.length; i < len; ++i) {
745 addIfNew(list, values[i]);
746 }
747 } else {
748 addIfNew(list, values);
749 }
750 }
751 });
752
753 unwrapExports(addNewValuesOnly_1);
754
755 var isObject_1 = createCommonjsModule(function (module, exports) {
756
757 Object.defineProperty(exports, "__esModule", {
758 value: true
759 });
760 exports.default = isObject;
761 function isObject(value) {
762 return value instanceof Object && !Array.isArray(value);
763 }
764 });
765
766 unwrapExports(isObject_1);
767
768 var createPrefixer_1 = createCommonjsModule(function (module, exports) {
769
770 Object.defineProperty(exports, "__esModule", {
771 value: true
772 });
773 exports.default = createPrefixer;
774
775
776
777 var _prefixProperty2 = _interopRequireDefault(prefixProperty_1);
778
779
780
781 var _prefixValue2 = _interopRequireDefault(prefixValue_1);
782
783
784
785 var _addNewValuesOnly2 = _interopRequireDefault(addNewValuesOnly_1);
786
787
788
789 var _isObject2 = _interopRequireDefault(isObject_1);
790
791 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
792
793 function createPrefixer(_ref) {
794 var prefixMap = _ref.prefixMap,
795 plugins = _ref.plugins;
796
797 return function prefix(style) {
798 for (var property in style) {
799 var value = style[property];
800
801 // handle nested objects
802 if ((0, _isObject2.default)(value)) {
803 style[property] = prefix(value);
804 // handle array values
805 } else if (Array.isArray(value)) {
806 var combinedValue = [];
807
808 for (var i = 0, len = value.length; i < len; ++i) {
809 var processedValue = (0, _prefixValue2.default)(plugins, property, value[i], style, prefixMap);
810 (0, _addNewValuesOnly2.default)(combinedValue, processedValue || value[i]);
811 }
812
813 // only modify the value if it was touched
814 // by any plugin to prevent unnecessary mutations
815 if (combinedValue.length > 0) {
816 style[property] = combinedValue;
817 }
818 } else {
819 var _processedValue = (0, _prefixValue2.default)(plugins, property, value, style, prefixMap);
820
821 // only modify the value if it was touched
822 // by any plugin to prevent unnecessary mutations
823 if (_processedValue) {
824 style[property] = _processedValue;
825 }
826
827 style = (0, _prefixProperty2.default)(prefixMap, property, style);
828 }
829 }
830
831 return style;
832 };
833 }
834 });
835
836 var createPrefixer = unwrapExports(createPrefixer_1);
837
838 var backgroundClip_1 = createCommonjsModule(function (module, exports) {
839
840 Object.defineProperty(exports, "__esModule", {
841 value: true
842 });
843 exports.default = backgroundClip;
844
845 // https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip#Browser_compatibility
846 function backgroundClip(property, value) {
847 if (typeof value === 'string' && value === 'text') {
848 return ['-webkit-text', 'text'];
849 }
850 }
851 });
852
853 var backgroundClip = unwrapExports(backgroundClip_1);
854
855 var isPrefixedValue_1 = createCommonjsModule(function (module, exports) {
856
857 Object.defineProperty(exports, "__esModule", {
858 value: true
859 });
860 exports.default = isPrefixedValue;
861 var regex = /-webkit-|-moz-|-ms-/;
862
863 function isPrefixedValue(value) {
864 return typeof value === 'string' && regex.test(value);
865 }
866 module.exports = exports['default'];
867 });
868
869 unwrapExports(isPrefixedValue_1);
870
871 var calc_1 = createCommonjsModule(function (module, exports) {
872
873 Object.defineProperty(exports, "__esModule", {
874 value: true
875 });
876 exports.default = calc;
877
878
879
880 var _isPrefixedValue2 = _interopRequireDefault(isPrefixedValue_1);
881
882 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
883
884 var prefixes = ['-webkit-', '-moz-', ''];
885 function calc(property, value) {
886 if (typeof value === 'string' && !(0, _isPrefixedValue2.default)(value) && value.indexOf('calc(') > -1) {
887 return prefixes.map(function (prefix) {
888 return value.replace(/calc\(/g, prefix + 'calc(');
889 });
890 }
891 }
892 });
893
894 var calc = unwrapExports(calc_1);
895
896 var crossFade_1 = createCommonjsModule(function (module, exports) {
897
898 Object.defineProperty(exports, "__esModule", {
899 value: true
900 });
901 exports.default = crossFade;
902
903
904
905 var _isPrefixedValue2 = _interopRequireDefault(isPrefixedValue_1);
906
907 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
908
909 // http://caniuse.com/#search=cross-fade
910 var prefixes = ['-webkit-', ''];
911 function crossFade(property, value) {
912 if (typeof value === 'string' && !(0, _isPrefixedValue2.default)(value) && value.indexOf('cross-fade(') > -1) {
913 return prefixes.map(function (prefix) {
914 return value.replace(/cross-fade\(/g, prefix + 'cross-fade(');
915 });
916 }
917 }
918 });
919
920 var crossFade = unwrapExports(crossFade_1);
921
922 var cursor_1 = createCommonjsModule(function (module, exports) {
923
924 Object.defineProperty(exports, "__esModule", {
925 value: true
926 });
927 exports.default = cursor;
928 var prefixes = ['-webkit-', '-moz-', ''];
929
930 var values = {
931 'zoom-in': true,
932 'zoom-out': true,
933 grab: true,
934 grabbing: true
935 };
936
937 function cursor(property, value) {
938 if (property === 'cursor' && values.hasOwnProperty(value)) {
939 return prefixes.map(function (prefix) {
940 return prefix + value;
941 });
942 }
943 }
944 });
945
946 var cursor = unwrapExports(cursor_1);
947
948 var filter_1 = createCommonjsModule(function (module, exports) {
949
950 Object.defineProperty(exports, "__esModule", {
951 value: true
952 });
953 exports.default = filter;
954
955
956
957 var _isPrefixedValue2 = _interopRequireDefault(isPrefixedValue_1);
958
959 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
960
961 // http://caniuse.com/#feat=css-filter-function
962 var prefixes = ['-webkit-', ''];
963 function filter(property, value) {
964 if (typeof value === 'string' && !(0, _isPrefixedValue2.default)(value) && value.indexOf('filter(') > -1) {
965 return prefixes.map(function (prefix) {
966 return value.replace(/filter\(/g, prefix + 'filter(');
967 });
968 }
969 }
970 });
971
972 var filter = unwrapExports(filter_1);
973
974 var flex_1 = createCommonjsModule(function (module, exports) {
975
976 Object.defineProperty(exports, "__esModule", {
977 value: true
978 });
979 exports.default = flex;
980 var values = {
981 flex: ['-webkit-box', '-moz-box', '-ms-flexbox', '-webkit-flex', 'flex'],
982 'inline-flex': ['-webkit-inline-box', '-moz-inline-box', '-ms-inline-flexbox', '-webkit-inline-flex', 'inline-flex']
983 };
984
985 function flex(property, value) {
986 if (property === 'display' && values.hasOwnProperty(value)) {
987 return values[value];
988 }
989 }
990 });
991
992 var flex = unwrapExports(flex_1);
993
994 var flexboxIE_1 = createCommonjsModule(function (module, exports) {
995
996 Object.defineProperty(exports, "__esModule", {
997 value: true
998 });
999 exports.default = flexboxIE;
1000 var alternativeValues = {
1001 'space-around': 'distribute',
1002 'space-between': 'justify',
1003 'flex-start': 'start',
1004 'flex-end': 'end'
1005 };
1006 var alternativeProps = {
1007 alignContent: 'msFlexLinePack',
1008 alignSelf: 'msFlexItemAlign',
1009 alignItems: 'msFlexAlign',
1010 justifyContent: 'msFlexPack',
1011 order: 'msFlexOrder',
1012 flexGrow: 'msFlexPositive',
1013 flexShrink: 'msFlexNegative',
1014 flexBasis: 'msFlexPreferredSize'
1015 // Full expanded syntax is flex-grow | flex-shrink | flex-basis.
1016 };var flexShorthandMappings = {
1017 auto: '1 1 auto',
1018 inherit: 'inherit',
1019 initial: '0 1 auto',
1020 none: '0 0 auto',
1021 unset: 'unset'
1022 };
1023 var isUnitlessNumber = /^\d+(\.\d+)?$/;
1024
1025 function flexboxIE(property, value, style) {
1026 if (Object.prototype.hasOwnProperty.call(alternativeProps, property)) {
1027 style[alternativeProps[property]] = alternativeValues[value] || value;
1028 }
1029 if (property === 'flex') {
1030 // For certain values we can do straight mappings based on the spec
1031 // for the expansions.
1032 if (Object.prototype.hasOwnProperty.call(flexShorthandMappings, value)) {
1033 style.msFlex = flexShorthandMappings[value];
1034 return;
1035 }
1036 // Here we have no direct mapping, so we favor looking for a
1037 // unitless positive number as that will be the most common use-case.
1038 if (isUnitlessNumber.test(value)) {
1039 style.msFlex = value + ' 1 0%';
1040 return;
1041 }
1042
1043 // The next thing we can look for is if there are multiple values.
1044 var flexValues = value.split(/\s/);
1045 // If we only have a single value that wasn't a positive unitless
1046 // or a pre-mapped value, then we can assume it is a unit value.
1047 switch (flexValues.length) {
1048 case 1:
1049 style.msFlex = '1 1 ' + value;
1050 return;
1051 case 2:
1052 // If we have 2 units, then we expect that the first will
1053 // always be a unitless number and represents flex-grow.
1054 // The second unit will represent flex-shrink for a unitless
1055 // value, or flex-basis otherwise.
1056 if (isUnitlessNumber.test(flexValues[1])) {
1057 style.msFlex = flexValues[0] + ' ' + flexValues[1] + ' 0%';
1058 } else {
1059 style.msFlex = flexValues[0] + ' 1 ' + flexValues[1];
1060 }
1061 return;
1062 default:
1063 style.msFlex = value;
1064 }
1065 }
1066 }
1067 });
1068
1069 var flexboxIE = unwrapExports(flexboxIE_1);
1070
1071 var flexboxOld_1 = createCommonjsModule(function (module, exports) {
1072
1073 Object.defineProperty(exports, "__esModule", {
1074 value: true
1075 });
1076 exports.default = flexboxOld;
1077 var alternativeValues = {
1078 'space-around': 'justify',
1079 'space-between': 'justify',
1080 'flex-start': 'start',
1081 'flex-end': 'end',
1082 'wrap-reverse': 'multiple',
1083 wrap: 'multiple'
1084 };
1085
1086 var alternativeProps = {
1087 alignItems: 'WebkitBoxAlign',
1088 justifyContent: 'WebkitBoxPack',
1089 flexWrap: 'WebkitBoxLines',
1090 flexGrow: 'WebkitBoxFlex'
1091 };
1092
1093 function flexboxOld(property, value, style) {
1094 if (property === 'flexDirection' && typeof value === 'string') {
1095 if (value.indexOf('column') > -1) {
1096 style.WebkitBoxOrient = 'vertical';
1097 } else {
1098 style.WebkitBoxOrient = 'horizontal';
1099 }
1100 if (value.indexOf('reverse') > -1) {
1101 style.WebkitBoxDirection = 'reverse';
1102 } else {
1103 style.WebkitBoxDirection = 'normal';
1104 }
1105 }
1106 if (alternativeProps.hasOwnProperty(property)) {
1107 style[alternativeProps[property]] = alternativeValues[value] || value;
1108 }
1109 }
1110 });
1111
1112 var flexboxOld = unwrapExports(flexboxOld_1);
1113
1114 var gradient_1 = createCommonjsModule(function (module, exports) {
1115
1116 Object.defineProperty(exports, "__esModule", {
1117 value: true
1118 });
1119 exports.default = gradient;
1120
1121
1122
1123 var _isPrefixedValue2 = _interopRequireDefault(isPrefixedValue_1);
1124
1125 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1126
1127 var prefixes = ['-webkit-', '-moz-', ''];
1128
1129 var values = /linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient/gi;
1130
1131 function gradient(property, value) {
1132 if (typeof value === 'string' && !(0, _isPrefixedValue2.default)(value) && values.test(value)) {
1133 return prefixes.map(function (prefix) {
1134 return value.replace(values, function (grad) {
1135 return prefix + grad;
1136 });
1137 });
1138 }
1139 }
1140 });
1141
1142 var gradient = unwrapExports(gradient_1);
1143
1144 var grid_1 = createCommonjsModule(function (module, exports) {
1145
1146 Object.defineProperty(exports, "__esModule", {
1147 value: true
1148 });
1149
1150 var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
1151
1152 exports.default = grid;
1153 function isSimplePositionValue(value) {
1154 return typeof value === 'number' && !isNaN(value);
1155 }
1156
1157 var alignmentValues = ['center', 'end', 'start', 'stretch'];
1158
1159 var displayValues = {
1160 'inline-grid': ['-ms-inline-grid', 'inline-grid'],
1161 grid: ['-ms-grid', 'grid']
1162 };
1163
1164 var propertyConverters = {
1165 alignSelf: function alignSelf(value, style) {
1166 if (alignmentValues.indexOf(value) > -1) {
1167 style.msGridRowAlign = value;
1168 }
1169 },
1170
1171 gridColumn: function gridColumn(value, style) {
1172 if (isSimplePositionValue(value)) {
1173 style.msGridColumn = value;
1174 } else {
1175 var _value$split$map = value.split('/').map(function (position) {
1176 return +position;
1177 }),
1178 _value$split$map2 = _slicedToArray(_value$split$map, 2),
1179 start = _value$split$map2[0],
1180 end = _value$split$map2[1];
1181
1182 propertyConverters.gridColumnStart(start, style);
1183 propertyConverters.gridColumnEnd(end, style);
1184 }
1185 },
1186
1187 gridColumnEnd: function gridColumnEnd(value, style) {
1188 var msGridColumn = style.msGridColumn;
1189
1190 if (isSimplePositionValue(value) && isSimplePositionValue(msGridColumn)) {
1191 style.msGridColumnSpan = value - msGridColumn;
1192 }
1193 },
1194
1195 gridColumnStart: function gridColumnStart(value, style) {
1196 if (isSimplePositionValue(value)) {
1197 style.msGridColumn = value;
1198 }
1199 },
1200
1201 gridRow: function gridRow(value, style) {
1202 if (isSimplePositionValue(value)) {
1203 style.msGridRow = value;
1204 } else {
1205 var _value$split$map3 = value.split('/').map(function (position) {
1206 return +position;
1207 }),
1208 _value$split$map4 = _slicedToArray(_value$split$map3, 2),
1209 start = _value$split$map4[0],
1210 end = _value$split$map4[1];
1211
1212 propertyConverters.gridRowStart(start, style);
1213 propertyConverters.gridRowEnd(end, style);
1214 }
1215 },
1216
1217 gridRowEnd: function gridRowEnd(value, style) {
1218 var msGridRow = style.msGridRow;
1219
1220 if (isSimplePositionValue(value) && isSimplePositionValue(msGridRow)) {
1221 style.msGridRowSpan = value - msGridRow;
1222 }
1223 },
1224
1225 gridRowStart: function gridRowStart(value, style) {
1226 if (isSimplePositionValue(value)) {
1227 style.msGridRow = value;
1228 }
1229 },
1230
1231 gridTemplateColumns: function gridTemplateColumns(value, style) {
1232 style.msGridColumns = value;
1233 },
1234
1235 gridTemplateRows: function gridTemplateRows(value, style) {
1236 style.msGridRows = value;
1237 },
1238
1239 justifySelf: function justifySelf(value, style) {
1240 if (alignmentValues.indexOf(value) > -1) {
1241 style.msGridColumnAlign = value;
1242 }
1243 }
1244 };
1245
1246 function grid(property, value, style) {
1247 if (property === 'display' && value in displayValues) {
1248 return displayValues[value];
1249 }
1250
1251 if (property in propertyConverters) {
1252 var propertyConverter = propertyConverters[property];
1253 propertyConverter(value, style);
1254 }
1255 }
1256 });
1257
1258 var grid = unwrapExports(grid_1);
1259
1260 var imageSet_1 = createCommonjsModule(function (module, exports) {
1261
1262 Object.defineProperty(exports, "__esModule", {
1263 value: true
1264 });
1265 exports.default = imageSet;
1266
1267
1268
1269 var _isPrefixedValue2 = _interopRequireDefault(isPrefixedValue_1);
1270
1271 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1272
1273 // http://caniuse.com/#feat=css-image-set
1274 var prefixes = ['-webkit-', ''];
1275 function imageSet(property, value) {
1276 if (typeof value === 'string' && !(0, _isPrefixedValue2.default)(value) && value.indexOf('image-set(') > -1) {
1277 return prefixes.map(function (prefix) {
1278 return value.replace(/image-set\(/g, prefix + 'image-set(');
1279 });
1280 }
1281 }
1282 });
1283
1284 var imageSet = unwrapExports(imageSet_1);
1285
1286 var logical_1 = createCommonjsModule(function (module, exports) {
1287
1288 Object.defineProperty(exports, "__esModule", {
1289 value: true
1290 });
1291 exports.default = logical;
1292 var alternativeProps = {
1293 marginBlockStart: ['WebkitMarginBefore'],
1294 marginBlockEnd: ['WebkitMarginAfter'],
1295 marginInlineStart: ['WebkitMarginStart', 'MozMarginStart'],
1296 marginInlineEnd: ['WebkitMarginEnd', 'MozMarginEnd'],
1297 paddingBlockStart: ['WebkitPaddingBefore'],
1298 paddingBlockEnd: ['WebkitPaddingAfter'],
1299 paddingInlineStart: ['WebkitPaddingStart', 'MozPaddingStart'],
1300 paddingInlineEnd: ['WebkitPaddingEnd', 'MozPaddingEnd'],
1301 borderBlockStart: ['WebkitBorderBefore'],
1302 borderBlockStartColor: ['WebkitBorderBeforeColor'],
1303 borderBlockStartStyle: ['WebkitBorderBeforeStyle'],
1304 borderBlockStartWidth: ['WebkitBorderBeforeWidth'],
1305 borderBlockEnd: ['WebkitBorderAfter'],
1306 borderBlockEndColor: ['WebkitBorderAfterColor'],
1307 borderBlockEndStyle: ['WebkitBorderAfterStyle'],
1308 borderBlockEndWidth: ['WebkitBorderAfterWidth'],
1309 borderInlineStart: ['WebkitBorderStart', 'MozBorderStart'],
1310 borderInlineStartColor: ['WebkitBorderStartColor', 'MozBorderStartColor'],
1311 borderInlineStartStyle: ['WebkitBorderStartStyle', 'MozBorderStartStyle'],
1312 borderInlineStartWidth: ['WebkitBorderStartWidth', 'MozBorderStartWidth'],
1313 borderInlineEnd: ['WebkitBorderEnd', 'MozBorderEnd'],
1314 borderInlineEndColor: ['WebkitBorderEndColor', 'MozBorderEndColor'],
1315 borderInlineEndStyle: ['WebkitBorderEndStyle', 'MozBorderEndStyle'],
1316 borderInlineEndWidth: ['WebkitBorderEndWidth', 'MozBorderEndWidth']
1317 };
1318
1319 function logical(property, value, style) {
1320 if (Object.prototype.hasOwnProperty.call(alternativeProps, property)) {
1321 var alternativePropList = alternativeProps[property];
1322 for (var i = 0, len = alternativePropList.length; i < len; ++i) {
1323 style[alternativePropList[i]] = value;
1324 }
1325 }
1326 }
1327 });
1328
1329 var logical = unwrapExports(logical_1);
1330
1331 var position_1 = createCommonjsModule(function (module, exports) {
1332
1333 Object.defineProperty(exports, "__esModule", {
1334 value: true
1335 });
1336 exports.default = position;
1337 function position(property, value) {
1338 if (property === 'position' && value === 'sticky') {
1339 return ['-webkit-sticky', 'sticky'];
1340 }
1341 }
1342 });
1343
1344 var position = unwrapExports(position_1);
1345
1346 var sizing_1 = createCommonjsModule(function (module, exports) {
1347
1348 Object.defineProperty(exports, "__esModule", {
1349 value: true
1350 });
1351 exports.default = sizing;
1352 var prefixes = ['-webkit-', '-moz-', ''];
1353
1354 var properties = {
1355 maxHeight: true,
1356 maxWidth: true,
1357 width: true,
1358 height: true,
1359 columnWidth: true,
1360 minWidth: true,
1361 minHeight: true
1362 };
1363 var values = {
1364 'min-content': true,
1365 'max-content': true,
1366 'fill-available': true,
1367 'fit-content': true,
1368 'contain-floats': true
1369 };
1370
1371 function sizing(property, value) {
1372 if (properties.hasOwnProperty(property) && values.hasOwnProperty(value)) {
1373 return prefixes.map(function (prefix) {
1374 return prefix + value;
1375 });
1376 }
1377 }
1378 });
1379
1380 var sizing = unwrapExports(sizing_1);
1381
1382 /* eslint-disable no-var, prefer-template */
1383 var uppercasePattern = /[A-Z]/g;
1384 var msPattern = /^ms-/;
1385 var cache = {};
1386
1387 function toHyphenLower(match) {
1388 return '-' + match.toLowerCase()
1389 }
1390
1391 function hyphenateStyleName(name) {
1392 if (cache.hasOwnProperty(name)) {
1393 return cache[name]
1394 }
1395
1396 var hName = name.replace(uppercasePattern, toHyphenLower);
1397 return (cache[name] = msPattern.test(hName) ? '-' + hName : hName)
1398 }
1399
1400 var hyphenateProperty_1 = createCommonjsModule(function (module, exports) {
1401
1402 Object.defineProperty(exports, "__esModule", {
1403 value: true
1404 });
1405 exports.default = hyphenateProperty;
1406
1407
1408
1409 var _hyphenateStyleName2 = _interopRequireDefault(hyphenateStyleName);
1410
1411 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1412
1413 function hyphenateProperty(property) {
1414 return (0, _hyphenateStyleName2.default)(property);
1415 }
1416 module.exports = exports['default'];
1417 });
1418
1419 unwrapExports(hyphenateProperty_1);
1420
1421 var transition_1 = createCommonjsModule(function (module, exports) {
1422
1423 Object.defineProperty(exports, "__esModule", {
1424 value: true
1425 });
1426 exports.default = transition;
1427
1428
1429
1430 var _hyphenateProperty2 = _interopRequireDefault(hyphenateProperty_1);
1431
1432
1433
1434 var _isPrefixedValue2 = _interopRequireDefault(isPrefixedValue_1);
1435
1436
1437
1438 var _capitalizeString2 = _interopRequireDefault(capitalizeString_1);
1439
1440 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1441
1442 var properties = {
1443 transition: true,
1444 transitionProperty: true,
1445 WebkitTransition: true,
1446 WebkitTransitionProperty: true,
1447 MozTransition: true,
1448 MozTransitionProperty: true
1449 };
1450
1451
1452 var prefixMapping = {
1453 Webkit: '-webkit-',
1454 Moz: '-moz-',
1455 ms: '-ms-'
1456 };
1457
1458 function prefixValue(value, propertyPrefixMap) {
1459 if ((0, _isPrefixedValue2.default)(value)) {
1460 return value;
1461 }
1462
1463 // only split multi values, not cubic beziers
1464 var multipleValues = value.split(/,(?![^()]*(?:\([^()]*\))?\))/g);
1465
1466 for (var i = 0, len = multipleValues.length; i < len; ++i) {
1467 var singleValue = multipleValues[i];
1468 var values = [singleValue];
1469 for (var property in propertyPrefixMap) {
1470 var dashCaseProperty = (0, _hyphenateProperty2.default)(property);
1471
1472 if (singleValue.indexOf(dashCaseProperty) > -1 && dashCaseProperty !== 'order') {
1473 var prefixes = propertyPrefixMap[property];
1474 for (var j = 0, pLen = prefixes.length; j < pLen; ++j) {
1475 // join all prefixes and create a new value
1476 values.unshift(singleValue.replace(dashCaseProperty, prefixMapping[prefixes[j]] + dashCaseProperty));
1477 }
1478 }
1479 }
1480
1481 multipleValues[i] = values.join(',');
1482 }
1483
1484 return multipleValues.join(',');
1485 }
1486
1487 function transition(property, value, style, propertyPrefixMap) {
1488 // also check for already prefixed transitions
1489 if (typeof value === 'string' && properties.hasOwnProperty(property)) {
1490 var outputValue = prefixValue(value, propertyPrefixMap);
1491 // if the property is already prefixed
1492 var webkitOutput = outputValue.split(/,(?![^()]*(?:\([^()]*\))?\))/g).filter(function (val) {
1493 return !/-moz-|-ms-/.test(val);
1494 }).join(',');
1495
1496 if (property.indexOf('Webkit') > -1) {
1497 return webkitOutput;
1498 }
1499
1500 var mozOutput = outputValue.split(/,(?![^()]*(?:\([^()]*\))?\))/g).filter(function (val) {
1501 return !/-webkit-|-ms-/.test(val);
1502 }).join(',');
1503
1504 if (property.indexOf('Moz') > -1) {
1505 return mozOutput;
1506 }
1507
1508 style['Webkit' + (0, _capitalizeString2.default)(property)] = webkitOutput;
1509 style['Moz' + (0, _capitalizeString2.default)(property)] = mozOutput;
1510 return outputValue;
1511 }
1512 }
1513 });
1514
1515 var transition = unwrapExports(transition_1);
1516
1517 var w = ["Webkit"];
1518 var m = ["Moz"];
1519 var ms = ["ms"];
1520 var wm = ["Webkit", "Moz"];
1521 var wms = ["Webkit", "ms"];
1522 var wmms = ["Webkit", "Moz", "ms"];
1523 var staticData = {
1524 plugins: [backgroundClip, calc, crossFade, cursor, filter, flex, flexboxIE, flexboxOld, gradient, grid, imageSet, logical, position, sizing, transition],
1525 prefixMap: {
1526 "transform": wms,
1527 "transformOrigin": wms,
1528 "transformOriginX": wms,
1529 "transformOriginY": wms,
1530 "backfaceVisibility": w,
1531 "perspective": w,
1532 "perspectiveOrigin": w,
1533 "transformStyle": w,
1534 "transformOriginZ": w,
1535 "animation": w,
1536 "animationDelay": w,
1537 "animationDirection": w,
1538 "animationFillMode": w,
1539 "animationDuration": w,
1540 "animationIterationCount": w,
1541 "animationName": w,
1542 "animationPlayState": w,
1543 "animationTimingFunction": w,
1544 "appearance": wm,
1545 "userSelect": wmms,
1546 "fontKerning": w,
1547 "textEmphasisPosition": w,
1548 "textEmphasis": w,
1549 "textEmphasisStyle": w,
1550 "textEmphasisColor": w,
1551 "boxDecorationBreak": w,
1552 "clipPath": w,
1553 "maskImage": w,
1554 "maskMode": w,
1555 "maskRepeat": w,
1556 "maskPosition": w,
1557 "maskClip": w,
1558 "maskOrigin": w,
1559 "maskSize": w,
1560 "maskComposite": w,
1561 "mask": w,
1562 "maskBorderSource": w,
1563 "maskBorderMode": w,
1564 "maskBorderSlice": w,
1565 "maskBorderWidth": w,
1566 "maskBorderOutset": w,
1567 "maskBorderRepeat": w,
1568 "maskBorder": w,
1569 "maskType": w,
1570 "textDecorationStyle": wm,
1571 "textDecorationSkip": wm,
1572 "textDecorationLine": wm,
1573 "textDecorationColor": wm,
1574 "filter": w,
1575 "fontFeatureSettings": wm,
1576 "breakAfter": wmms,
1577 "breakBefore": wmms,
1578 "breakInside": wmms,
1579 "columnCount": wm,
1580 "columnFill": wm,
1581 "columnGap": wm,
1582 "columnRule": wm,
1583 "columnRuleColor": wm,
1584 "columnRuleStyle": wm,
1585 "columnRuleWidth": wm,
1586 "columns": wm,
1587 "columnSpan": wm,
1588 "columnWidth": wm,
1589 "writingMode": wms,
1590 "flex": wms,
1591 "flexBasis": w,
1592 "flexDirection": wms,
1593 "flexGrow": w,
1594 "flexFlow": wms,
1595 "flexShrink": w,
1596 "flexWrap": wms,
1597 "alignContent": w,
1598 "alignItems": w,
1599 "alignSelf": w,
1600 "justifyContent": w,
1601 "order": w,
1602 "transitionDelay": w,
1603 "transitionDuration": w,
1604 "transitionProperty": w,
1605 "transitionTimingFunction": w,
1606 "backdropFilter": w,
1607 "scrollSnapType": wms,
1608 "scrollSnapPointsX": wms,
1609 "scrollSnapPointsY": wms,
1610 "scrollSnapDestination": wms,
1611 "scrollSnapCoordinate": wms,
1612 "shapeImageThreshold": w,
1613 "shapeImageMargin": w,
1614 "shapeImageOutside": w,
1615 "hyphens": wmms,
1616 "flowInto": wms,
1617 "flowFrom": wms,
1618 "regionFragment": wms,
1619 "textOrientation": w,
1620 "boxSizing": m,
1621 "textAlignLast": m,
1622 "tabSize": m,
1623 "wrapFlow": ms,
1624 "wrapThrough": ms,
1625 "wrapMargin": ms,
1626 "touchAction": ms,
1627 "textSizeAdjust": wms,
1628 "borderImage": w,
1629 "borderImageOutset": w,
1630 "borderImageRepeat": w,
1631 "borderImageSlice": w,
1632 "borderImageSource": w,
1633 "borderImageWidth": w
1634 }
1635 };
1636
1637 var prefixAll = createPrefixer(staticData);
1638 /* ::
1639 import type { SheetDefinition } from './index.js';
1640 type StringHandlers = { [id:string]: Function };
1641 type SelectorCallback = (selector: string) => string[];
1642 export type SelectorHandler = (
1643 selector: string,
1644 baseSelector: string,
1645 callback: SelectorCallback
1646 ) => string[] | string | null;
1647 */
1648
1649 /**
1650 * `selectorHandlers` are functions which handle special selectors which act
1651 * differently than normal style definitions. These functions look at the
1652 * current selector and can generate CSS for the styles in their subtree by
1653 * calling the callback with a new selector.
1654 *
1655 * For example, when generating styles with a base selector of '.foo' and the
1656 * following styles object:
1657 *
1658 * {
1659 * ':nth-child(2n)': {
1660 * ':hover': {
1661 * color: 'red'
1662 * }
1663 * }
1664 * }
1665 *
1666 * when we reach the ':hover' style, we would call our selector handlers like
1667 *
1668 * handler(':hover', '.foo:nth-child(2n)', callback)
1669 *
1670 * Since our `pseudoSelectors` handles ':hover' styles, that handler would call
1671 * the callback like
1672 *
1673 * callback('.foo:nth-child(2n):hover')
1674 *
1675 * to generate its subtree `{ color: 'red' }` styles with a
1676 * '.foo:nth-child(2n):hover' selector. The callback would return an array of CSS
1677 * rules like
1678 *
1679 * ['.foo:nth-child(2n):hover{color:red !important;}']
1680 *
1681 * and the handler would then return that resulting CSS.
1682 *
1683 * `defaultSelectorHandlers` is the list of default handlers used in a call to
1684 * `generateCSS`.
1685 *
1686 * @name SelectorHandler
1687 * @function
1688 * @param {string} selector: The currently inspected selector. ':hover' in the
1689 * example above.
1690 * @param {string} baseSelector: The selector of the parent styles.
1691 * '.foo:nth-child(2n)' in the example above.
1692 * @param {function} generateSubtreeStyles: A function which can be called to
1693 * generate CSS for the subtree of styles corresponding to the selector.
1694 * Accepts a new baseSelector to use for generating those styles.
1695 * @returns {string[] | string | null} The generated CSS for this selector, or
1696 * null if we don't handle this selector.
1697 */
1698
1699 var defaultSelectorHandlers
1700 /* : SelectorHandler[] */
1701 = [// Handle pseudo-selectors, like :hover and :nth-child(3n)
1702 function pseudoSelectors(selector, baseSelector, generateSubtreeStyles) {
1703 if (selector[0] !== ":") {
1704 return null;
1705 }
1706
1707 return generateSubtreeStyles(baseSelector + selector);
1708 }, // Handle media queries (or font-faces)
1709 function mediaQueries(selector, baseSelector, generateSubtreeStyles) {
1710 if (selector[0] !== "@") {
1711 return null;
1712 } // Generate the styles normally, and then wrap them in the media query.
1713
1714
1715 var generated = generateSubtreeStyles(baseSelector);
1716 return ["".concat(selector, "{").concat(generated.join(''), "}")];
1717 }];
1718 /**
1719 * Generate CSS for a selector and some styles.
1720 *
1721 * This function handles the media queries and pseudo selectors that can be used
1722 * in aphrodite styles.
1723 *
1724 * @param {string} selector: A base CSS selector for the styles to be generated
1725 * with.
1726 * @param {Object} styleTypes: A list of properties of the return type of
1727 * StyleSheet.create, e.g. [styles.red, styles.blue].
1728 * @param {Array.<SelectorHandler>} selectorHandlers: A list of selector
1729 * handlers to use for handling special selectors. See
1730 * `defaultSelectorHandlers`.
1731 * @param stringHandlers: See `generateCSSRuleset`
1732 * @param useImportant: See `generateCSSRuleset`
1733 *
1734 * To actually generate the CSS special-construct-less styles are passed to
1735 * `generateCSSRuleset`.
1736 *
1737 * For instance, a call to
1738 *
1739 * generateCSS(".foo", [{
1740 * color: "red",
1741 * "@media screen": {
1742 * height: 20,
1743 * ":hover": {
1744 * backgroundColor: "black"
1745 * }
1746 * },
1747 * ":active": {
1748 * fontWeight: "bold"
1749 * }
1750 * }], defaultSelectorHandlers);
1751 *
1752 * with the default `selectorHandlers` will make 5 calls to
1753 * `generateCSSRuleset`:
1754 *
1755 * generateCSSRuleset(".foo", { color: "red" }, ...)
1756 * generateCSSRuleset(".foo:active", { fontWeight: "bold" }, ...)
1757 * // These 2 will be wrapped in @media screen {}
1758 * generateCSSRuleset(".foo", { height: 20 }, ...)
1759 * generateCSSRuleset(".foo:hover", { backgroundColor: "black" }, ...)
1760 */
1761
1762 var generateCSS = function generateCSS(selector
1763 /* : string */
1764 , styleTypes
1765 /* : SheetDefinition[] */
1766 , selectorHandlers
1767 /* : SelectorHandler[] */
1768 , stringHandlers
1769 /* : StringHandlers */
1770 , useImportant
1771 /* : boolean */
1772 )
1773 /* : string[] */
1774 {
1775 var merged = new OrderedElements();
1776
1777 for (var i = 0; i < styleTypes.length; i++) {
1778 merged.addStyleType(styleTypes[i]);
1779 }
1780
1781 var plainDeclarations = new OrderedElements();
1782 var generatedStyles = []; // TODO(emily): benchmark this to see if a plain for loop would be faster.
1783
1784 merged.forEach(function (val, key) {
1785 // For each key, see if one of the selector handlers will handle these
1786 // styles.
1787 var foundHandler = selectorHandlers.some(function (handler) {
1788 var result = handler(key, selector, function (newSelector) {
1789 return generateCSS(newSelector, [val], selectorHandlers, stringHandlers, useImportant);
1790 });
1791
1792 if (result != null) {
1793 // If the handler returned something, add it to the generated
1794 // CSS and stop looking for another handler.
1795 if (Array.isArray(result)) {
1796 generatedStyles.push.apply(generatedStyles, _toConsumableArray(result));
1797 } else {
1798 // eslint-disable-next-line
1799 console.warn('WARNING: Selector handlers should return an array of rules.' + 'Returning a string containing multiple rules is deprecated.', handler);
1800 generatedStyles.push("@media all {".concat(result, "}"));
1801 }
1802
1803 return true;
1804 }
1805 }); // If none of the handlers handled it, add it to the list of plain
1806 // style declarations.
1807
1808 if (!foundHandler) {
1809 plainDeclarations.set(key, val, true);
1810 }
1811 });
1812 var generatedRuleset = generateCSSRuleset(selector, plainDeclarations, stringHandlers, useImportant, selectorHandlers);
1813
1814 if (generatedRuleset) {
1815 generatedStyles.unshift(generatedRuleset);
1816 }
1817
1818 return generatedStyles;
1819 };
1820 /**
1821 * Helper method of generateCSSRuleset to facilitate custom handling of certain
1822 * CSS properties. Used for e.g. font families.
1823 *
1824 * See generateCSSRuleset for usage and documentation of paramater types.
1825 */
1826
1827 var runStringHandlers = function runStringHandlers(declarations
1828 /* : OrderedElements */
1829 , stringHandlers
1830 /* : StringHandlers */
1831 , selectorHandlers
1832 /* : SelectorHandler[] */
1833 )
1834 /* : void */
1835 {
1836 if (!stringHandlers) {
1837 return;
1838 }
1839
1840 var stringHandlerKeys = Object.keys(stringHandlers);
1841
1842 for (var i = 0; i < stringHandlerKeys.length; i++) {
1843 var key = stringHandlerKeys[i];
1844
1845 if (declarations.has(key)) {
1846 // A declaration exists for this particular string handler, so we
1847 // need to let the string handler interpret the declaration first
1848 // before proceeding.
1849 //
1850 // TODO(emily): Pass in a callback which generates CSS, similar to
1851 // how our selector handlers work, instead of passing in
1852 // `selectorHandlers` and have them make calls to `generateCSS`
1853 // themselves. Right now, this is impractical because our string
1854 // handlers are very specialized and do complex things.
1855 declarations.set(key, stringHandlers[key](declarations.get(key), selectorHandlers), // Preserve order here, since we are really replacing an
1856 // unprocessed style with a processed style, not overriding an
1857 // earlier style
1858 false);
1859 }
1860 }
1861 };
1862
1863 var transformRule = function transformRule(key
1864 /* : string */
1865 , value
1866 /* : string */
1867 , transformValue
1868 /* : function */
1869 ) {
1870 return (
1871 /* : string */
1872 "".concat(kebabifyStyleName(key), ":").concat(transformValue(key, value), ";")
1873 );
1874 };
1875
1876 var arrayToObjectKeysReducer = function arrayToObjectKeysReducer(acc, val) {
1877 acc[val] = true;
1878 return acc;
1879 };
1880 /**
1881 * Generate a CSS ruleset with the selector and containing the declarations.
1882 *
1883 * This function assumes that the given declarations don't contain any special
1884 * children (such as media queries, pseudo-selectors, or descendant styles).
1885 *
1886 * Note that this method does not deal with nesting used for e.g.
1887 * psuedo-selectors or media queries. That responsibility is left to the
1888 * `generateCSS` function.
1889 *
1890 * @param {string} selector: the selector associated with the ruleset
1891 * @param {Object} declarations: a map from camelCased CSS property name to CSS
1892 * property value.
1893 * @param {Object.<string, function>} stringHandlers: a map from camelCased CSS
1894 * property name to a function which will map the given value to the value
1895 * that is output.
1896 * @param {bool} useImportant: A boolean saying whether to append "!important"
1897 * to each of the CSS declarations.
1898 * @returns {string} A string of raw CSS.
1899 *
1900 * Examples:
1901 *
1902 * generateCSSRuleset(".blah", { color: "red" })
1903 * -> ".blah{color: red !important;}"
1904 * generateCSSRuleset(".blah", { color: "red" }, {}, false)
1905 * -> ".blah{color: red}"
1906 * generateCSSRuleset(".blah", { color: "red" }, {color: c => c.toUpperCase})
1907 * -> ".blah{color: RED}"
1908 * generateCSSRuleset(".blah:hover", { color: "red" })
1909 * -> ".blah:hover{color: red}"
1910 */
1911
1912
1913 var generateCSSRuleset = function generateCSSRuleset(selector
1914 /* : string */
1915 , declarations
1916 /* : OrderedElements */
1917 , stringHandlers
1918 /* : StringHandlers */
1919 , useImportant
1920 /* : boolean */
1921 , selectorHandlers
1922 /* : SelectorHandler[] */
1923 )
1924 /* : string */
1925 {
1926 // Mutates declarations
1927 runStringHandlers(declarations, stringHandlers, selectorHandlers);
1928 var originalElements = Object.keys(declarations.elements).reduce(arrayToObjectKeysReducer, Object.create(null)); // NOTE(emily): This mutates handledDeclarations.elements.
1929
1930 var prefixedElements = prefixAll(declarations.elements);
1931 var elementNames = Object.keys(prefixedElements);
1932
1933 if (elementNames.length !== declarations.keyOrder.length) {
1934 // There are some prefixed values, so we need to figure out how to sort
1935 // them.
1936 //
1937 // Loop through prefixedElements, looking for anything that is not in
1938 // sortOrder, which means it was added by prefixAll. This means that we
1939 // need to figure out where it should appear in the sortOrder.
1940 for (var i = 0; i < elementNames.length; i++) {
1941 if (!originalElements[elementNames[i]]) {
1942 // This element is not in the sortOrder, which means it is a prefixed
1943 // value that was added by prefixAll. Let's try to figure out where it
1944 // goes.
1945 var originalStyle = void 0;
1946
1947 if (elementNames[i][0] === 'W') {
1948 // This is a Webkit-prefixed style, like "WebkitTransition". Let's
1949 // find its original style's sort order.
1950 originalStyle = elementNames[i][6].toLowerCase() + elementNames[i].slice(7);
1951 } else if (elementNames[i][1] === 'o') {
1952 // This is a Moz-prefixed style, like "MozTransition". We check
1953 // the second character to avoid colliding with Ms-prefixed
1954 // styles. Let's find its original style's sort order.
1955 originalStyle = elementNames[i][3].toLowerCase() + elementNames[i].slice(4);
1956 } else {
1957 // if (elementNames[i][1] === 's') {
1958 // This is a Ms-prefixed style, like "MsTransition".
1959 originalStyle = elementNames[i][2].toLowerCase() + elementNames[i].slice(3);
1960 }
1961
1962 if (originalStyle && originalElements[originalStyle]) {
1963 var originalIndex = declarations.keyOrder.indexOf(originalStyle);
1964 declarations.keyOrder.splice(originalIndex, 0, elementNames[i]);
1965 } else {
1966 // We don't know what the original style was, so sort it to
1967 // top. This can happen for styles that are added that don't
1968 // have the same base name as the original style.
1969 declarations.keyOrder.unshift(elementNames[i]);
1970 }
1971 }
1972 }
1973 }
1974
1975 var transformValue = useImportant === false ? stringifyValue : stringifyAndImportantifyValue;
1976 var rules = [];
1977
1978 for (var _i = 0; _i < declarations.keyOrder.length; _i++) {
1979 var key = declarations.keyOrder[_i];
1980 var value = prefixedElements[key];
1981
1982 if (Array.isArray(value)) {
1983 // inline-style-prefixer returns an array when there should be
1984 // multiple rules for the same key. Here we flatten to multiple
1985 // pairs with the same key.
1986 for (var j = 0; j < value.length; j++) {
1987 rules.push(transformRule(key, value[j], transformValue));
1988 }
1989 } else {
1990 rules.push(transformRule(key, value, transformValue));
1991 }
1992 }
1993
1994 if (rules.length) {
1995 return "".concat(selector, "{").concat(rules.join(""), "}");
1996 } else {
1997 return "";
1998 }
1999 };
2000
2001 /* ::
2002 import type { SheetDefinition, SheetDefinitions } from './index.js';
2003 import type { MaybeSheetDefinition } from './exports.js';
2004 import type { SelectorHandler } from './generate.js';
2005 */
2006 // The current <style> tag we are inserting into, or null if we haven't
2007 // inserted anything yet. We could find this each time using
2008 // `document.querySelector("style[data-aphrodite"])`, but holding onto it is
2009 // faster.
2010
2011 var styleTag
2012 /* : ?HTMLStyleElement */
2013 = null; // Inject a set of rules into a <style> tag in the head of the document. This
2014 // will automatically create a style tag and then continue to use it for
2015 // multiple injections. It will also use a style tag with the `data-aphrodite`
2016 // tag on it if that exists in the DOM. This could be used for e.g. reusing the
2017 // same style tag that server-side rendering inserts.
2018
2019 var injectStyleTag = function injectStyleTag(cssRules
2020 /* : string[] */
2021 ) {
2022 if (styleTag == null) {
2023 // Try to find a style tag with the `data-aphrodite` attribute first.
2024 styleTag = document.querySelector("style[data-aphrodite]")
2025 /* : any */
2026 ; // If that doesn't work, generate a new style tag.
2027
2028 if (styleTag == null) {
2029 // Taken from
2030 // http://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript
2031 var head = document.head || document.getElementsByTagName('head')[0];
2032 styleTag = document.createElement('style');
2033 styleTag.type = 'text/css';
2034 styleTag.setAttribute("data-aphrodite", "");
2035 head.appendChild(styleTag);
2036 }
2037 } // $FlowFixMe
2038
2039
2040 var sheet = styleTag.styleSheet || styleTag.sheet
2041 /* : any */
2042 ;
2043
2044 if (sheet.insertRule) {
2045 var numRules = sheet.cssRules.length;
2046 cssRules.forEach(function (rule) {
2047 try {
2048 sheet.insertRule(rule, numRules);
2049 numRules += 1;
2050 } catch (e) {// The selector for this rule wasn't compatible with the browser
2051 }
2052 });
2053 } else {
2054 styleTag.innerText = (styleTag.innerText || '') + cssRules.join('');
2055 }
2056 }; // Custom handlers for stringifying CSS values that have side effects
2057 // (such as fontFamily, which can cause @font-face rules to be injected)
2058
2059
2060 var stringHandlers = {
2061 // With fontFamily we look for objects that are passed in and interpret
2062 // them as @font-face rules that we need to inject. The value of fontFamily
2063 // can either be a string (as normal), an object (a single font face), or
2064 // an array of objects and strings.
2065 fontFamily: function fontFamily(val) {
2066 if (Array.isArray(val)) {
2067 var nameMap = {};
2068 val.forEach(function (v) {
2069 nameMap[fontFamily(v)] = true;
2070 });
2071 return Object.keys(nameMap).join(",");
2072 } else if (_typeof(val) === "object") {
2073 injectStyleOnce(val.src, "@font-face", [val], false);
2074 return "\"".concat(val.fontFamily, "\"");
2075 } else {
2076 return val;
2077 }
2078 },
2079 // With animationName we look for an object that contains keyframes and
2080 // inject them as an `@keyframes` block, returning a uniquely generated
2081 // name. The keyframes object should look like
2082 // animationName: {
2083 // from: {
2084 // left: 0,
2085 // top: 0,
2086 // },
2087 // '50%': {
2088 // left: 15,
2089 // top: 5,
2090 // },
2091 // to: {
2092 // left: 20,
2093 // top: 20,
2094 // }
2095 // }
2096 // TODO(emily): `stringHandlers` doesn't let us rename the key, so I have
2097 // to use `animationName` here. Improve that so we can call this
2098 // `animation` instead of `animationName`.
2099 animationName: function animationName(val, selectorHandlers) {
2100 if (Array.isArray(val)) {
2101 return val.map(function (v) {
2102 return animationName(v, selectorHandlers);
2103 }).join(",");
2104 } else if (_typeof(val) === "object") {
2105 // Generate a unique name based on the hash of the object. We can't
2106 // just use the hash because the name can't start with a number.
2107 // TODO(emily): this probably makes debugging hard, allow a custom
2108 // name?
2109 var name = "keyframe_".concat(hashObject(val)); // Since keyframes need 3 layers of nesting, we use `generateCSS` to
2110 // build the inner layers and wrap it in `@keyframes` ourselves.
2111
2112 var finalVal = "@keyframes ".concat(name, "{"); // TODO see if we can find a way where checking for OrderedElements
2113 // here is not necessary. Alternatively, perhaps we should have a
2114 // utility method that can iterate over either a plain object, an
2115 // instance of OrderedElements, or a Map, and then use that here and
2116 // elsewhere.
2117
2118 if (val instanceof OrderedElements) {
2119 val.forEach(function (valVal, valKey) {
2120 finalVal += generateCSS(valKey, [valVal], selectorHandlers, stringHandlers, false).join('');
2121 });
2122 } else {
2123 Object.keys(val).forEach(function (key) {
2124 finalVal += generateCSS(key, [val[key]], selectorHandlers, stringHandlers, false).join('');
2125 });
2126 }
2127
2128 finalVal += '}';
2129 injectGeneratedCSSOnce(name, [finalVal]);
2130 return name;
2131 } else {
2132 return val;
2133 }
2134 }
2135 }; // This is a map from Aphrodite's generated class names to `true` (acting as a
2136 // set of class names)
2137
2138 var alreadyInjected = {}; // This is the buffer of styles which have not yet been flushed.
2139
2140 var injectionBuffer
2141 /* : string[] */
2142 = []; // A flag to tell if we are already buffering styles. This could happen either
2143 // because we scheduled a flush call already, so newly added styles will
2144 // already be flushed, or because we are statically buffering on the server.
2145
2146 var isBuffering = false;
2147
2148 var injectGeneratedCSSOnce = function injectGeneratedCSSOnce(key, generatedCSS) {
2149 var _injectionBuffer;
2150
2151 if (alreadyInjected[key]) {
2152 return;
2153 }
2154
2155 if (!isBuffering) {
2156 // We should never be automatically buffering on the server (or any
2157 // place without a document), so guard against that.
2158 if (typeof document === "undefined") {
2159 throw new Error("Cannot automatically buffer without a document");
2160 } // If we're not already buffering, schedule a call to flush the
2161 // current styles.
2162
2163
2164 isBuffering = true;
2165 browserAsap(flushToStyleTag);
2166 }
2167
2168 (_injectionBuffer = injectionBuffer).push.apply(_injectionBuffer, _toConsumableArray(generatedCSS));
2169
2170 alreadyInjected[key] = true;
2171 };
2172
2173 var injectStyleOnce = function injectStyleOnce(key
2174 /* : string */
2175 , selector
2176 /* : string */
2177 , definitions
2178 /* : SheetDefinition[] */
2179 , useImportant
2180 /* : boolean */
2181 ) {
2182 var selectorHandlers
2183 /* : SelectorHandler[] */
2184 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
2185
2186 if (alreadyInjected[key]) {
2187 return;
2188 }
2189
2190 var generated = generateCSS(selector, definitions, selectorHandlers, stringHandlers, useImportant);
2191 injectGeneratedCSSOnce(key, generated);
2192 };
2193 var reset = function reset() {
2194 injectionBuffer = [];
2195 alreadyInjected = {};
2196 isBuffering = false;
2197 styleTag = null;
2198 };
2199 var resetInjectedStyle = function resetInjectedStyle(key
2200 /* : string */
2201 ) {
2202 delete alreadyInjected[key];
2203 };
2204 var startBuffering = function startBuffering() {
2205 if (isBuffering) {
2206 throw new Error("Cannot buffer while already buffering");
2207 }
2208
2209 isBuffering = true;
2210 };
2211
2212 var flushToArray = function flushToArray() {
2213 isBuffering = false;
2214 var ret = injectionBuffer;
2215 injectionBuffer = [];
2216 return ret;
2217 };
2218
2219 var flushToString = function flushToString() {
2220 return flushToArray().join('');
2221 };
2222 var flushToStyleTag = function flushToStyleTag() {
2223 var cssRules = flushToArray();
2224
2225 if (cssRules.length > 0) {
2226 injectStyleTag(cssRules);
2227 }
2228 };
2229 var getRenderedClassNames = function getRenderedClassNames()
2230 /* : string[] */
2231 {
2232 return Object.keys(alreadyInjected);
2233 };
2234 var addRenderedClassNames = function addRenderedClassNames(classNames
2235 /* : string[] */
2236 ) {
2237 classNames.forEach(function (className) {
2238 alreadyInjected[className] = true;
2239 });
2240 };
2241
2242 var isValidStyleDefinition = function isValidStyleDefinition(def
2243 /* : Object */
2244 ) {
2245 return "_definition" in def && "_name" in def && "_len" in def;
2246 };
2247
2248 var processStyleDefinitions = function processStyleDefinitions(styleDefinitions
2249 /* : any[] */
2250 , classNameBits
2251 /* : string[] */
2252 , definitionBits
2253 /* : Object[] */
2254 , length
2255 /* : number */
2256 )
2257 /* : number */
2258 {
2259 for (var i = 0; i < styleDefinitions.length; i += 1) {
2260 // Filter out falsy values from the input, to allow for
2261 // `css(a, test && c)`
2262 if (styleDefinitions[i]) {
2263 if (Array.isArray(styleDefinitions[i])) {
2264 // We've encountered an array, so let's recurse
2265 length += processStyleDefinitions(styleDefinitions[i], classNameBits, definitionBits, length);
2266 } else if (isValidStyleDefinition(styleDefinitions[i])) {
2267 classNameBits.push(styleDefinitions[i]._name);
2268 definitionBits.push(styleDefinitions[i]._definition);
2269 length += styleDefinitions[i]._len;
2270 } else {
2271 throw new Error("Invalid Style Definition: Styles should be defined using the StyleSheet.create method.");
2272 }
2273 }
2274 }
2275
2276 return length;
2277 };
2278 /**
2279 * Inject styles associated with the passed style definition objects, and return
2280 * an associated CSS class name.
2281 *
2282 * @param {boolean} useImportant If true, will append !important to generated
2283 * CSS output. e.g. {color: red} -> "color: red !important".
2284 * @param {(Object|Object[])[]} styleDefinitions style definition objects, or
2285 * arbitrarily nested arrays of them, as returned as properties of the
2286 * return value of StyleSheet.create().
2287 */
2288
2289
2290 var injectAndGetClassName = function injectAndGetClassName(useImportant
2291 /* : boolean */
2292 , styleDefinitions
2293 /* : MaybeSheetDefinition[] */
2294 , selectorHandlers
2295 /* : SelectorHandler[] */
2296 )
2297 /* : string */
2298 {
2299 var classNameBits = [];
2300 var definitionBits = []; // Mutates classNameBits and definitionBits and returns a length which we
2301 // will append to the hash to decrease the chance of hash collisions.
2302
2303 var length = processStyleDefinitions(styleDefinitions, classNameBits, definitionBits, 0); // Break if there aren't any valid styles.
2304
2305 if (classNameBits.length === 0) {
2306 return "";
2307 }
2308
2309 var className;
2310
2311 {
2312 className = classNameBits.length === 1 ? "_".concat(classNameBits[0]) : "_".concat(hashString(classNameBits.join())).concat((length % 36).toString(36));
2313 }
2314
2315 injectStyleOnce(className, ".".concat(className), definitionBits, useImportant, selectorHandlers);
2316 return className;
2317 };
2318
2319 /* ::
2320 import type { SelectorHandler } from './generate.js';
2321 export type SheetDefinition = { [id:string]: any };
2322 export type SheetDefinitions = SheetDefinition | SheetDefinition[];
2323 type RenderFunction = () => string;
2324 type Extension = {
2325 selectorHandler: SelectorHandler
2326 };
2327 export type MaybeSheetDefinition = SheetDefinition | false | null | void
2328 */
2329
2330 var unminifiedHashFn = function unminifiedHashFn(str
2331 /* : string */
2332 , key
2333 /* : string */
2334 ) {
2335 return "".concat(key, "_").concat(hashString(str));
2336 }; // StyleSheet.create is in a hot path so we want to keep as much logic out of it
2337 // as possible. So, we figure out which hash function to use once, and only
2338 // switch it out via minify() as necessary.
2339 //
2340 // This is in an exported function to make it easier to test.
2341
2342
2343 var initialHashFn = function initialHashFn() {
2344 return hashString;
2345 };
2346 var hashFn = initialHashFn();
2347 var StyleSheet = {
2348 create: function create(sheetDefinition
2349 /* : SheetDefinition */
2350 )
2351 /* : Object */
2352 {
2353 var mappedSheetDefinition = {};
2354 var keys = Object.keys(sheetDefinition);
2355
2356 for (var i = 0; i < keys.length; i += 1) {
2357 var key = keys[i];
2358 var val = sheetDefinition[key];
2359 var stringVal = JSON.stringify(val);
2360 mappedSheetDefinition[key] = {
2361 _len: stringVal.length,
2362 _name: hashFn(stringVal, key),
2363 _definition: val
2364 };
2365 }
2366
2367 return mappedSheetDefinition;
2368 },
2369 rehydrate: function rehydrate() {
2370 var renderedClassNames
2371 /* : string[] */
2372 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2373 addRenderedClassNames(renderedClassNames);
2374 }
2375 };
2376 /**
2377 * Utilities for using Aphrodite server-side.
2378 *
2379 * This can be minified out in client-only bundles by replacing `typeof window`
2380 * with `"object"`, e.g. via Webpack's DefinePlugin:
2381 *
2382 * new webpack.DefinePlugin({
2383 * "typeof window": JSON.stringify("object")
2384 * })
2385 */
2386
2387 var StyleSheetServer = typeof window !== 'undefined' ? null : {
2388 renderStatic: function renderStatic(renderFunc
2389 /* : RenderFunction */
2390 ) {
2391 reset();
2392 startBuffering();
2393 var html = renderFunc();
2394 var cssContent = flushToString();
2395 return {
2396 html: html,
2397 css: {
2398 content: cssContent,
2399 renderedClassNames: getRenderedClassNames()
2400 }
2401 };
2402 }
2403 };
2404 /**
2405 * Utilities for using Aphrodite in tests.
2406 *
2407 * Not meant to be used in production.
2408 */
2409
2410 var StyleSheetTestUtils = null;
2411 /**
2412 * Generate the Aphrodite API exports, with given `selectorHandlers` and
2413 * `useImportant` state.
2414 */
2415
2416 function makeExports(useImportant
2417 /* : boolean */
2418 ) {
2419 var selectorHandlers
2420 /* : SelectorHandler[] */
2421 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultSelectorHandlers;
2422 return {
2423 StyleSheet: _objectSpread({}, StyleSheet, {
2424 /**
2425 * Returns a version of the exports of Aphrodite (i.e. an object
2426 * with `css` and `StyleSheet` properties) which have some
2427 * extensions included.
2428 *
2429 * @param {Array.<Object>} extensions: An array of extensions to
2430 * add to this instance of Aphrodite. Each object should have a
2431 * single property on it, defining which kind of extension to
2432 * add.
2433 * @param {SelectorHandler} [extensions[].selectorHandler]: A
2434 * selector handler extension. See `defaultSelectorHandlers` in
2435 * generate.js.
2436 *
2437 * @returns {Object} An object containing the exports of the new
2438 * instance of Aphrodite.
2439 */
2440 extend: function extend(extensions
2441 /* : Extension[] */
2442 ) {
2443 var extensionSelectorHandlers = extensions // Pull out extensions with a selectorHandler property
2444 .map(function (extension) {
2445 return extension.selectorHandler;
2446 }) // Remove nulls (i.e. extensions without a selectorHandler property).
2447 .filter(function (handler) {
2448 return handler;
2449 });
2450 return makeExports(useImportant, selectorHandlers.concat(extensionSelectorHandlers));
2451 }
2452 }),
2453 StyleSheetServer: StyleSheetServer,
2454 StyleSheetTestUtils: StyleSheetTestUtils,
2455 minify: function minify(shouldMinify
2456 /* : boolean */
2457 ) {
2458 hashFn = shouldMinify ? hashString : unminifiedHashFn;
2459 },
2460 css: function css()
2461 /* : MaybeSheetDefinition[] */
2462 {
2463 for (var _len = arguments.length, styleDefinitions = new Array(_len), _key = 0; _key < _len; _key++) {
2464 styleDefinitions[_key] = arguments[_key];
2465 }
2466
2467 return injectAndGetClassName(useImportant, styleDefinitions, selectorHandlers);
2468 },
2469 flushToStyleTag: flushToStyleTag,
2470 injectAndGetClassName: injectAndGetClassName,
2471 defaultSelectorHandlers: defaultSelectorHandlers,
2472 reset: reset,
2473 resetInjectedStyle: resetInjectedStyle
2474 };
2475 }
2476
2477 var useImportant = true; // Add !important to all style definitions
2478
2479 var Aphrodite = makeExports(useImportant);
2480 var StyleSheet$1 = Aphrodite.StyleSheet,
2481 StyleSheetServer$1 = Aphrodite.StyleSheetServer,
2482 StyleSheetTestUtils$1 = Aphrodite.StyleSheetTestUtils,
2483 css = Aphrodite.css,
2484 minify = Aphrodite.minify,
2485 flushToStyleTag$1 = Aphrodite.flushToStyleTag,
2486 injectAndGetClassName$1 = Aphrodite.injectAndGetClassName,
2487 defaultSelectorHandlers$1 = Aphrodite.defaultSelectorHandlers,
2488 reset$1 = Aphrodite.reset,
2489 resetInjectedStyle$1 = Aphrodite.resetInjectedStyle;
2490
2491 exports.StyleSheet = StyleSheet$1;
2492 exports.StyleSheetServer = StyleSheetServer$1;
2493 exports.StyleSheetTestUtils = StyleSheetTestUtils$1;
2494 exports.css = css;
2495 exports.minify = minify;
2496 exports.flushToStyleTag = flushToStyleTag$1;
2497 exports.injectAndGetClassName = injectAndGetClassName$1;
2498 exports.defaultSelectorHandlers = defaultSelectorHandlers$1;
2499 exports.reset = reset$1;
2500 exports.resetInjectedStyle = resetInjectedStyle$1;
2501
2502 Object.defineProperty(exports, '__esModule', { value: true });
2503
2504}));
2505//# sourceMappingURL=aphrodite.umd.js.map