1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var Stylis = _interopDefault(require('stylis/stylis.min'));
|
8 | var _insertRulePlugin = _interopDefault(require('stylis-rule-sheet'));
|
9 | var React = require('react');
|
10 | var React__default = _interopDefault(React);
|
11 | var reactIs = require('react-is');
|
12 | var memoize = _interopDefault(require('memoize-one'));
|
13 | var stream = _interopDefault(require('stream'));
|
14 | var PropTypes = _interopDefault(require('prop-types'));
|
15 | var ReactDOM = _interopDefault(require('react-dom'));
|
16 | var validAttr = _interopDefault(require('@emotion/is-prop-valid'));
|
17 |
|
18 |
|
19 |
|
20 | var interleave = (function (strings, interpolations) {
|
21 | var result = [strings[0]];
|
22 |
|
23 | for (var i = 0, len = interpolations.length; i < len; i += 1) {
|
24 | result.push(interpolations[i], strings[i + 1]);
|
25 | }
|
26 |
|
27 | return result;
|
28 | });
|
29 |
|
30 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
31 | return typeof obj;
|
32 | } : function (obj) {
|
33 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
34 | };
|
35 |
|
36 | var classCallCheck = function (instance, Constructor) {
|
37 | if (!(instance instanceof Constructor)) {
|
38 | throw new TypeError("Cannot call a class as a function");
|
39 | }
|
40 | };
|
41 |
|
42 | var createClass = function () {
|
43 | function defineProperties(target, props) {
|
44 | for (var i = 0; i < props.length; i++) {
|
45 | var descriptor = props[i];
|
46 | descriptor.enumerable = descriptor.enumerable || false;
|
47 | descriptor.configurable = true;
|
48 | if ("value" in descriptor) descriptor.writable = true;
|
49 | Object.defineProperty(target, descriptor.key, descriptor);
|
50 | }
|
51 | }
|
52 |
|
53 | return function (Constructor, protoProps, staticProps) {
|
54 | if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
55 | if (staticProps) defineProperties(Constructor, staticProps);
|
56 | return Constructor;
|
57 | };
|
58 | }();
|
59 |
|
60 | var _extends = Object.assign || function (target) {
|
61 | for (var i = 1; i < arguments.length; i++) {
|
62 | var source = arguments[i];
|
63 |
|
64 | for (var key in source) {
|
65 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
66 | target[key] = source[key];
|
67 | }
|
68 | }
|
69 | }
|
70 |
|
71 | return target;
|
72 | };
|
73 |
|
74 | var inherits = function (subClass, superClass) {
|
75 | if (typeof superClass !== "function" && superClass !== null) {
|
76 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
77 | }
|
78 |
|
79 | subClass.prototype = Object.create(superClass && superClass.prototype, {
|
80 | constructor: {
|
81 | value: subClass,
|
82 | enumerable: false,
|
83 | writable: true,
|
84 | configurable: true
|
85 | }
|
86 | });
|
87 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
88 | };
|
89 |
|
90 | var objectWithoutProperties = function (obj, keys) {
|
91 | var target = {};
|
92 |
|
93 | for (var i in obj) {
|
94 | if (keys.indexOf(i) >= 0) continue;
|
95 | if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
|
96 | target[i] = obj[i];
|
97 | }
|
98 |
|
99 | return target;
|
100 | };
|
101 |
|
102 | var possibleConstructorReturn = function (self, call) {
|
103 | if (!self) {
|
104 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
105 | }
|
106 |
|
107 | return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
108 | };
|
109 |
|
110 |
|
111 | var isPlainObject = (function (x) {
|
112 | return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x.constructor === Object;
|
113 | });
|
114 |
|
115 |
|
116 | var EMPTY_ARRAY = Object.freeze([]);
|
117 | var EMPTY_OBJECT = Object.freeze({});
|
118 |
|
119 |
|
120 | function isFunction(test) {
|
121 | return typeof test === 'function';
|
122 | }
|
123 |
|
124 |
|
125 |
|
126 | function getComponentName(target) {
|
127 | return target.displayName || target.name || 'Component';
|
128 | }
|
129 |
|
130 |
|
131 | function isStyledComponent(target) {
|
132 | return target && typeof target.styledComponentId === 'string';
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | var SC_ATTR = typeof process !== 'undefined' && process.env.SC_ATTR || 'data-styled';
|
139 |
|
140 | var SC_VERSION_ATTR = 'data-styled-version';
|
141 |
|
142 | var SC_STREAM_ATTR = 'data-styled-streamed';
|
143 |
|
144 | var IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
|
145 |
|
146 | var DISABLE_SPEEDY = process.env.NODE_ENV !== 'production';
|
147 |
|
148 |
|
149 | var STATIC_EXECUTION_CONTEXT = {};
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | var ERRORS = process.env.NODE_ENV !== 'production' ? {
|
158 | "1": "Cannot create styled-component for component: %s.\n\n",
|
159 | "2": "Can't collect styles once you've consumed a `ServerStyleSheet`'s styles! `ServerStyleSheet` is a one off instance for each server-side render cycle.\n\n- Are you trying to reuse it across renders?\n- Are you accidentally calling collectStyles twice?\n\n",
|
160 | "3": "Streaming SSR is only supported in a Node.js environment; Please do not try to call this method in the browser.\n\n",
|
161 | "4": "The `StyleSheetManager` expects a valid target or sheet prop!\n\n- Does this error occur on the client and is your target falsy?\n- Does this error occur on the server and is the sheet falsy?\n\n",
|
162 | "5": "The clone method cannot be used on the client!\n\n- Are you running in a client-like environment on the server?\n- Are you trying to run SSR on the client?\n\n",
|
163 | "6": "Trying to insert a new style tag, but the given Node is unmounted!\n\n- Are you using a custom target that isn't mounted?\n- Does your document not have a valid head element?\n- Have you accidentally removed a style tag manually?\n\n",
|
164 | "7": "ThemeProvider: Please return an object from your \"theme\" prop function, e.g.\n\n```js\ntheme={() => ({})}\n```\n\n",
|
165 | "8": "ThemeProvider: Please make your \"theme\" prop an object.\n\n",
|
166 | "9": "Missing document `<head>`\n\n",
|
167 | "10": "Cannot find a StyleSheet instance. Usually this happens if there are multiple copies of styled-components loaded at once. Check out this issue for how to troubleshoot and fix the common cases where this situation can happen: https://github.com/styled-components/styled-components/issues/1941#issuecomment-417862021\n\n",
|
168 | "11": "_This error was replaced with a dev-time warning, it will be deleted for v4 final._ [createGlobalStyle] received children which will not be rendered. Please use the component without passing children elements.\n\n",
|
169 | "12": "It seems you are interpolating a keyframe declaration (%s) into an untagged string. This was supported in styled-components v3, but is not longer supported in v4 as keyframes are now injected on-demand. Please wrap your string in the css\\`\\` helper (see https://www.styled-components.com/docs/api#css), which ensures the styles are injected correctly.\n"
|
170 | } : {};
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | function format() {
|
176 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
177 | args[_key] = arguments[_key];
|
178 | }
|
179 |
|
180 | var a = args[0];
|
181 | var b = [];
|
182 | var c = void 0;
|
183 |
|
184 | for (c = 1; c < args.length; c += 1) {
|
185 | b.push(args[c]);
|
186 | }
|
187 |
|
188 | b.forEach(function (d) {
|
189 | a = a.replace(/%[a-z]/, d);
|
190 | });
|
191 |
|
192 | return a;
|
193 | }
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | var StyledComponentsError = function (_Error) {
|
201 | inherits(StyledComponentsError, _Error);
|
202 |
|
203 | function StyledComponentsError(code) {
|
204 | classCallCheck(this, StyledComponentsError);
|
205 |
|
206 | for (var _len2 = arguments.length, interpolations = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
207 | interpolations[_key2 - 1] = arguments[_key2];
|
208 | }
|
209 |
|
210 | if (process.env.NODE_ENV === 'production') {
|
211 | var _this = possibleConstructorReturn(this, _Error.call(this, 'An error occurred. See https://github.com/styled-components/styled-components/blob/master/src/utils/errors.md#' + code + ' for more information. ' + (interpolations ? 'Additional arguments: ' + interpolations.join(', ') : '')));
|
212 | } else {
|
213 | var _this = possibleConstructorReturn(this, _Error.call(this, format.apply(undefined, [ERRORS[code]].concat(interpolations)).trim()));
|
214 | }
|
215 | return possibleConstructorReturn(_this);
|
216 | }
|
217 |
|
218 | return StyledComponentsError;
|
219 | }(Error);
|
220 |
|
221 |
|
222 | var SC_COMPONENT_ID = /^[^\S\n]*?\/\* sc-component-id:\s*(\S+)\s+\*\//gm;
|
223 |
|
224 | var extractComps = (function (maybeCSS) {
|
225 | var css = '' + (maybeCSS || '');
|
226 | var existingComponents = [];
|
227 | css.replace(SC_COMPONENT_ID, function (match, componentId, matchIndex) {
|
228 | existingComponents.push({ componentId: componentId, matchIndex: matchIndex });
|
229 | return match;
|
230 | });
|
231 | return existingComponents.map(function (_ref, i) {
|
232 | var componentId = _ref.componentId,
|
233 | matchIndex = _ref.matchIndex;
|
234 |
|
235 | var nextComp = existingComponents[i + 1];
|
236 | var cssFromDOM = nextComp ? css.slice(matchIndex, nextComp.matchIndex) : css.slice(matchIndex);
|
237 | return { componentId: componentId, cssFromDOM: cssFromDOM };
|
238 | });
|
239 | });
|
240 |
|
241 |
|
242 |
|
243 | var COMMENT_REGEX = /^\s*\/\/.*$/gm;
|
244 |
|
245 |
|
246 | var stylisSplitter = new Stylis({
|
247 | global: false,
|
248 | cascade: true,
|
249 | keyframe: false,
|
250 | prefix: false,
|
251 | compress: false,
|
252 | semicolon: true
|
253 | });
|
254 |
|
255 | var stylis = new Stylis({
|
256 | global: false,
|
257 | cascade: true,
|
258 | keyframe: false,
|
259 | prefix: true,
|
260 | compress: false,
|
261 | semicolon: false
|
262 | });
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 | var parsingRules = [];
|
269 |
|
270 |
|
271 | var returnRulesPlugin = function returnRulesPlugin(context) {
|
272 | if (context === -2) {
|
273 | var parsedRules = parsingRules;
|
274 | parsingRules = [];
|
275 | return parsedRules;
|
276 | }
|
277 | };
|
278 |
|
279 | var parseRulesPlugin = _insertRulePlugin(function (rule) {
|
280 | parsingRules.push(rule);
|
281 | });
|
282 |
|
283 | var _componentId = void 0;
|
284 | var _selector = void 0;
|
285 | var _selectorRegexp = void 0;
|
286 |
|
287 | var selfReferenceReplacer = function selfReferenceReplacer(match, offset, string) {
|
288 | if (
|
289 |
|
290 | offset > 0 &&
|
291 |
|
292 | string.slice(0, offset).indexOf(_selector) !== -1 &&
|
293 |
|
294 | string.slice(offset - _selector.length, offset) !== _selector) {
|
295 | return '.' + _componentId;
|
296 | }
|
297 |
|
298 | return match;
|
299 | };
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | var selfReferenceReplacementPlugin = function selfReferenceReplacementPlugin(context, _, selectors) {
|
312 | if (context === 2 && selectors.length && selectors[0].lastIndexOf(_selector) > 0) {
|
313 |
|
314 | selectors[0] = selectors[0].replace(_selectorRegexp, selfReferenceReplacer);
|
315 | }
|
316 | };
|
317 |
|
318 | stylis.use([selfReferenceReplacementPlugin, parseRulesPlugin, returnRulesPlugin]);
|
319 | stylisSplitter.use([parseRulesPlugin, returnRulesPlugin]);
|
320 |
|
321 | var splitByRules = function splitByRules(css) {
|
322 | return stylisSplitter('', css);
|
323 | };
|
324 |
|
325 | function stringifyRules(rules, selector, prefix) {
|
326 | var componentId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '&';
|
327 |
|
328 | var flatCSS = rules.join('').replace(COMMENT_REGEX, '');
|
329 |
|
330 | var cssStr = selector && prefix ? prefix + ' ' + selector + ' { ' + flatCSS + ' }' : flatCSS;
|
331 |
|
332 |
|
333 |
|
334 |
|
335 | _componentId = componentId;
|
336 | _selector = selector;
|
337 | _selectorRegexp = new RegExp('\\' + _selector + '\\b', 'g');
|
338 |
|
339 | return stylis(prefix || !selector ? '' : selector, cssStr);
|
340 | }
|
341 |
|
342 |
|
343 |
|
344 |
|
345 | var getNonce = (function () {
|
346 | return typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;
|
347 | });
|
348 |
|
349 |
|
350 |
|
351 | var once = (function (cb) {
|
352 | var called = false;
|
353 |
|
354 | return function () {
|
355 | if (!called) {
|
356 | called = true;
|
357 | cb();
|
358 | }
|
359 | };
|
360 | });
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 | var addNameForId = function addNameForId(names, id, name) {
|
371 | if (name) {
|
372 |
|
373 | var namesForId = names[id] || (names[id] = Object.create(null));
|
374 | namesForId[name] = true;
|
375 | }
|
376 | };
|
377 |
|
378 |
|
379 | var resetIdNames = function resetIdNames(names, id) {
|
380 |
|
381 | names[id] = Object.create(null);
|
382 | };
|
383 |
|
384 |
|
385 | var hasNameForId = function hasNameForId(names) {
|
386 | return function (id, name) {
|
387 | return names[id] !== undefined && names[id][name];
|
388 | };
|
389 | };
|
390 |
|
391 |
|
392 | var stringifyNames = function stringifyNames(names) {
|
393 | var str = '';
|
394 |
|
395 | for (var id in names) {
|
396 | str += Object.keys(names[id]).join(' ') + ' ';
|
397 | }
|
398 | return str.trim();
|
399 | };
|
400 |
|
401 |
|
402 | var cloneNames = function cloneNames(names) {
|
403 | var clone = Object.create(null);
|
404 |
|
405 | for (var id in names) {
|
406 | clone[id] = _extends({}, names[id]);
|
407 | }
|
408 | return clone;
|
409 | };
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | var sheetForTag = function sheetForTag(tag) {
|
419 |
|
420 | if (tag.sheet) return tag.sheet;
|
421 |
|
422 |
|
423 | var size = document.styleSheets.length;
|
424 | for (var i = 0; i < size; i += 1) {
|
425 | var sheet = document.styleSheets[i];
|
426 |
|
427 | if (sheet.ownerNode === tag) return sheet;
|
428 | }
|
429 |
|
430 |
|
431 | throw new StyledComponentsError(10);
|
432 | };
|
433 |
|
434 |
|
435 | var safeInsertRule = function safeInsertRule(sheet, cssRule, index) {
|
436 |
|
437 | if (!cssRule) return false;
|
438 |
|
439 | var maxIndex = sheet.cssRules.length;
|
440 |
|
441 | try {
|
442 |
|
443 | sheet.insertRule(cssRule, index <= maxIndex ? index : maxIndex);
|
444 | } catch (err) {
|
445 |
|
446 | return false;
|
447 | }
|
448 |
|
449 | return true;
|
450 | };
|
451 |
|
452 |
|
453 | var deleteRules = function deleteRules(sheet, removalIndex, size) {
|
454 | var lowerBound = removalIndex - size;
|
455 | for (var i = removalIndex; i > lowerBound; i -= 1) {
|
456 | sheet.deleteRule(i);
|
457 | }
|
458 | };
|
459 |
|
460 |
|
461 |
|
462 |
|
463 | var makeTextMarker = function makeTextMarker(id) {
|
464 | return '\n/* sc-component-id: ' + id + ' */\n';
|
465 | };
|
466 |
|
467 |
|
468 | var addUpUntilIndex = function addUpUntilIndex(sizes, index) {
|
469 | var totalUpToIndex = 0;
|
470 | for (var i = 0; i <= index; i += 1) {
|
471 | totalUpToIndex += sizes[i];
|
472 | }
|
473 |
|
474 | return totalUpToIndex;
|
475 | };
|
476 |
|
477 |
|
478 | var makeStyleTag = function makeStyleTag(target, tagEl, insertBefore) {
|
479 | var el = document.createElement('style');
|
480 | el.setAttribute(SC_ATTR, '');
|
481 | el.setAttribute(SC_VERSION_ATTR, "4.0.2");
|
482 |
|
483 | var nonce = getNonce();
|
484 | if (nonce) {
|
485 | el.setAttribute('nonce', nonce);
|
486 | }
|
487 |
|
488 |
|
489 | el.appendChild(document.createTextNode(''));
|
490 |
|
491 | if (target && !tagEl) {
|
492 |
|
493 | target.appendChild(el);
|
494 | } else {
|
495 | if (!tagEl || !target || !tagEl.parentNode) {
|
496 | throw new StyledComponentsError(6);
|
497 | }
|
498 |
|
499 |
|
500 | tagEl.parentNode.insertBefore(el, insertBefore ? tagEl : tagEl.nextSibling);
|
501 | }
|
502 |
|
503 | return el;
|
504 | };
|
505 |
|
506 |
|
507 | var wrapAsHtmlTag = function wrapAsHtmlTag(css, names) {
|
508 | return function (additionalAttrs) {
|
509 | var nonce = getNonce();
|
510 | var attrs = [nonce && 'nonce="' + nonce + '"', SC_ATTR + '="' + stringifyNames(names) + '"', SC_VERSION_ATTR + '="' + "4.0.2" + '"', additionalAttrs];
|
511 |
|
512 | var htmlAttr = attrs.filter(Boolean).join(' ');
|
513 | return '<style ' + htmlAttr + '>' + css() + '</style>';
|
514 | };
|
515 | };
|
516 |
|
517 |
|
518 | var wrapAsElement = function wrapAsElement(css, names) {
|
519 | return function () {
|
520 | var _props;
|
521 |
|
522 | var props = (_props = {}, _props[SC_ATTR] = stringifyNames(names), _props[SC_VERSION_ATTR] = "4.0.2", _props);
|
523 |
|
524 | var nonce = getNonce();
|
525 | if (nonce) {
|
526 |
|
527 | props.nonce = nonce;
|
528 | }
|
529 |
|
530 |
|
531 | return React__default.createElement('style', _extends({}, props, { dangerouslySetInnerHTML: { __html: css() } }));
|
532 | };
|
533 | };
|
534 |
|
535 | var getIdsFromMarkersFactory = function getIdsFromMarkersFactory(markers) {
|
536 | return function () {
|
537 | return Object.keys(markers);
|
538 | };
|
539 | };
|
540 |
|
541 |
|
542 | var makeSpeedyTag = function makeSpeedyTag(el, getImportRuleTag) {
|
543 | var names = Object.create(null);
|
544 | var markers = Object.create(null);
|
545 | var sizes = [];
|
546 |
|
547 | var extractImport = getImportRuleTag !== undefined;
|
548 |
|
549 | var usedImportRuleTag = false;
|
550 |
|
551 | var insertMarker = function insertMarker(id) {
|
552 | var prev = markers[id];
|
553 | if (prev !== undefined) {
|
554 | return prev;
|
555 | }
|
556 |
|
557 | markers[id] = sizes.length;
|
558 | sizes.push(0);
|
559 | resetIdNames(names, id);
|
560 |
|
561 | return markers[id];
|
562 | };
|
563 |
|
564 | var insertRules = function insertRules(id, cssRules, name) {
|
565 | var marker = insertMarker(id);
|
566 | var sheet = sheetForTag(el);
|
567 | var insertIndex = addUpUntilIndex(sizes, marker);
|
568 |
|
569 | var injectedRules = 0;
|
570 | var importRules = [];
|
571 | var cssRulesSize = cssRules.length;
|
572 |
|
573 | for (var i = 0; i < cssRulesSize; i += 1) {
|
574 | var cssRule = cssRules[i];
|
575 | var mayHaveImport = extractImport;
|
576 | if (mayHaveImport && cssRule.indexOf('@import') !== -1) {
|
577 | importRules.push(cssRule);
|
578 | } else if (safeInsertRule(sheet, cssRule, insertIndex + injectedRules)) {
|
579 | mayHaveImport = false;
|
580 | injectedRules += 1;
|
581 | }
|
582 | }
|
583 |
|
584 | if (extractImport && importRules.length > 0) {
|
585 | usedImportRuleTag = true;
|
586 |
|
587 | getImportRuleTag().insertRules(id + '-import', importRules);
|
588 | }
|
589 |
|
590 | sizes[marker] += injectedRules;
|
591 | addNameForId(names, id, name);
|
592 | };
|
593 |
|
594 | var removeRules = function removeRules(id) {
|
595 | var marker = markers[id];
|
596 | if (marker === undefined) return;
|
597 |
|
598 | var size = sizes[marker];
|
599 | var sheet = sheetForTag(el);
|
600 | var removalIndex = addUpUntilIndex(sizes, marker) - 1;
|
601 | deleteRules(sheet, removalIndex, size);
|
602 | sizes[marker] = 0;
|
603 | resetIdNames(names, id);
|
604 |
|
605 | if (extractImport && usedImportRuleTag) {
|
606 |
|
607 | getImportRuleTag().removeRules(id + '-import');
|
608 | }
|
609 | };
|
610 |
|
611 | var css = function css() {
|
612 | var _sheetForTag = sheetForTag(el),
|
613 | cssRules = _sheetForTag.cssRules;
|
614 |
|
615 | var str = '';
|
616 |
|
617 |
|
618 | for (var id in markers) {
|
619 | str += makeTextMarker(id);
|
620 | var marker = markers[id];
|
621 | var end = addUpUntilIndex(sizes, marker);
|
622 | var size = sizes[marker];
|
623 | for (var i = end - size; i < end; i += 1) {
|
624 | var rule = cssRules[i];
|
625 | if (rule !== undefined) {
|
626 | str += rule.cssText;
|
627 | }
|
628 | }
|
629 | }
|
630 |
|
631 | return str;
|
632 | };
|
633 |
|
634 | return {
|
635 | clone: function clone() {
|
636 | throw new StyledComponentsError(5);
|
637 | },
|
638 |
|
639 | css: css,
|
640 | getIds: getIdsFromMarkersFactory(markers),
|
641 | hasNameForId: hasNameForId(names),
|
642 | insertMarker: insertMarker,
|
643 | insertRules: insertRules,
|
644 | removeRules: removeRules,
|
645 | sealed: false,
|
646 | styleTag: el,
|
647 | toElement: wrapAsElement(css, names),
|
648 | toHTML: wrapAsHtmlTag(css, names)
|
649 | };
|
650 | };
|
651 |
|
652 | var makeTextNode = function makeTextNode(id) {
|
653 | return document.createTextNode(makeTextMarker(id));
|
654 | };
|
655 |
|
656 | var makeBrowserTag = function makeBrowserTag(el, getImportRuleTag) {
|
657 | var names = Object.create(null);
|
658 | var markers = Object.create(null);
|
659 |
|
660 | var extractImport = getImportRuleTag !== undefined;
|
661 |
|
662 |
|
663 | var usedImportRuleTag = false;
|
664 |
|
665 | var insertMarker = function insertMarker(id) {
|
666 | var prev = markers[id];
|
667 | if (prev !== undefined) {
|
668 | return prev;
|
669 | }
|
670 |
|
671 | markers[id] = makeTextNode(id);
|
672 | el.appendChild(markers[id]);
|
673 | names[id] = Object.create(null);
|
674 |
|
675 | return markers[id];
|
676 | };
|
677 |
|
678 | var insertRules = function insertRules(id, cssRules, name) {
|
679 | var marker = insertMarker(id);
|
680 | var importRules = [];
|
681 | var cssRulesSize = cssRules.length;
|
682 |
|
683 | for (var i = 0; i < cssRulesSize; i += 1) {
|
684 | var rule = cssRules[i];
|
685 | var mayHaveImport = extractImport;
|
686 | if (mayHaveImport && rule.indexOf('@import') !== -1) {
|
687 | importRules.push(rule);
|
688 | } else {
|
689 | mayHaveImport = false;
|
690 | var separator = i === cssRulesSize - 1 ? '' : ' ';
|
691 | marker.appendData('' + rule + separator);
|
692 | }
|
693 | }
|
694 |
|
695 | addNameForId(names, id, name);
|
696 |
|
697 | if (extractImport && importRules.length > 0) {
|
698 | usedImportRuleTag = true;
|
699 |
|
700 | getImportRuleTag().insertRules(id + '-import', importRules);
|
701 | }
|
702 | };
|
703 |
|
704 | var removeRules = function removeRules(id) {
|
705 | var marker = markers[id];
|
706 | if (marker === undefined) return;
|
707 |
|
708 |
|
709 | var newMarker = makeTextNode(id);
|
710 | el.replaceChild(newMarker, marker);
|
711 | markers[id] = newMarker;
|
712 | resetIdNames(names, id);
|
713 |
|
714 | if (extractImport && usedImportRuleTag) {
|
715 |
|
716 | getImportRuleTag().removeRules(id + '-import');
|
717 | }
|
718 | };
|
719 |
|
720 | var css = function css() {
|
721 | var str = '';
|
722 |
|
723 |
|
724 | for (var id in markers) {
|
725 | str += markers[id].data;
|
726 | }
|
727 |
|
728 | return str;
|
729 | };
|
730 |
|
731 | return {
|
732 | clone: function clone() {
|
733 | throw new StyledComponentsError(5);
|
734 | },
|
735 |
|
736 | css: css,
|
737 | getIds: getIdsFromMarkersFactory(markers),
|
738 | hasNameForId: hasNameForId(names),
|
739 | insertMarker: insertMarker,
|
740 | insertRules: insertRules,
|
741 | removeRules: removeRules,
|
742 | sealed: false,
|
743 | styleTag: el,
|
744 | toElement: wrapAsElement(css, names),
|
745 | toHTML: wrapAsHtmlTag(css, names)
|
746 | };
|
747 | };
|
748 |
|
749 | var makeServerTag = function makeServerTag(namesArg, markersArg) {
|
750 | var names = namesArg === undefined ? Object.create(null) : namesArg;
|
751 | var markers = markersArg === undefined ? Object.create(null) : markersArg;
|
752 |
|
753 | var insertMarker = function insertMarker(id) {
|
754 | var prev = markers[id];
|
755 | if (prev !== undefined) {
|
756 | return prev;
|
757 | }
|
758 |
|
759 | return markers[id] = [''];
|
760 | };
|
761 |
|
762 | var insertRules = function insertRules(id, cssRules, name) {
|
763 | var marker = insertMarker(id);
|
764 | marker[0] += cssRules.join(' ');
|
765 | addNameForId(names, id, name);
|
766 | };
|
767 |
|
768 | var removeRules = function removeRules(id) {
|
769 | var marker = markers[id];
|
770 | if (marker === undefined) return;
|
771 | marker[0] = '';
|
772 | resetIdNames(names, id);
|
773 | };
|
774 |
|
775 | var css = function css() {
|
776 | var str = '';
|
777 |
|
778 | for (var id in markers) {
|
779 | var cssForId = markers[id][0];
|
780 | if (cssForId) {
|
781 | str += makeTextMarker(id) + cssForId;
|
782 | }
|
783 | }
|
784 | return str;
|
785 | };
|
786 |
|
787 | var clone = function clone() {
|
788 | var namesClone = cloneNames(names);
|
789 | var markersClone = Object.create(null);
|
790 |
|
791 |
|
792 | for (var id in markers) {
|
793 | markersClone[id] = [markers[id][0]];
|
794 | }
|
795 |
|
796 | return makeServerTag(namesClone, markersClone);
|
797 | };
|
798 |
|
799 | var tag = {
|
800 | clone: clone,
|
801 | css: css,
|
802 | getIds: getIdsFromMarkersFactory(markers),
|
803 | hasNameForId: hasNameForId(names),
|
804 | insertMarker: insertMarker,
|
805 | insertRules: insertRules,
|
806 | removeRules: removeRules,
|
807 | sealed: false,
|
808 | styleTag: null,
|
809 | toElement: wrapAsElement(css, names),
|
810 | toHTML: wrapAsHtmlTag(css, names)
|
811 | };
|
812 |
|
813 | return tag;
|
814 | };
|
815 |
|
816 | var makeTag = function makeTag(target, tagEl, forceServer, insertBefore, getImportRuleTag) {
|
817 | if (IS_BROWSER && !forceServer) {
|
818 | var el = makeStyleTag(target, tagEl, insertBefore);
|
819 |
|
820 | if (DISABLE_SPEEDY) {
|
821 | return makeBrowserTag(el, getImportRuleTag);
|
822 | } else {
|
823 | return makeSpeedyTag(el, getImportRuleTag);
|
824 | }
|
825 | }
|
826 |
|
827 | return makeServerTag();
|
828 | };
|
829 |
|
830 |
|
831 | var makeRehydrationTag = function makeRehydrationTag(tag, els, extracted, immediateRehydration) {
|
832 |
|
833 | var rehydrate = once(function () {
|
834 |
|
835 | for (var i = 0, len = extracted.length; i < len; i += 1) {
|
836 | var _extracted$i = extracted[i],
|
837 | componentId = _extracted$i.componentId,
|
838 | cssFromDOM = _extracted$i.cssFromDOM;
|
839 |
|
840 | var cssRules = splitByRules(cssFromDOM);
|
841 | tag.insertRules(componentId, cssRules);
|
842 | }
|
843 |
|
844 |
|
845 | for (var _i = 0, _len = els.length; _i < _len; _i += 1) {
|
846 | var el = els[_i];
|
847 | if (el.parentNode) {
|
848 | el.parentNode.removeChild(el);
|
849 | }
|
850 | }
|
851 | });
|
852 |
|
853 | if (immediateRehydration) rehydrate();
|
854 |
|
855 | return _extends({}, tag, {
|
856 |
|
857 |
|
858 | insertMarker: function insertMarker(id) {
|
859 | rehydrate();
|
860 | return tag.insertMarker(id);
|
861 | },
|
862 |
|
863 | insertRules: function insertRules(id, cssRules, name) {
|
864 | rehydrate();
|
865 | return tag.insertRules(id, cssRules, name);
|
866 | },
|
867 |
|
868 | removeRules: function removeRules(id) {
|
869 | rehydrate();
|
870 | return tag.removeRules(id);
|
871 | }
|
872 | });
|
873 | };
|
874 |
|
875 |
|
876 |
|
877 | var SPLIT_REGEX = /\s+/;
|
878 |
|
879 |
|
880 | var MAX_SIZE = void 0;
|
881 | if (IS_BROWSER) {
|
882 |
|
883 | MAX_SIZE = DISABLE_SPEEDY ? 40 : 1000;
|
884 | } else {
|
885 |
|
886 | MAX_SIZE = -1;
|
887 | }
|
888 |
|
889 | var sheetRunningId = 0;
|
890 | var master = void 0;
|
891 |
|
892 | var StyleSheet = function () {
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 | function StyleSheet() {
|
911 | var _this = this;
|
912 |
|
913 | var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : IS_BROWSER ? document.head : null;
|
914 | var forceServer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
915 | classCallCheck(this, StyleSheet);
|
916 |
|
917 | this.getImportRuleTag = function () {
|
918 | var importRuleTag = _this.importRuleTag;
|
919 |
|
920 | if (importRuleTag !== undefined) {
|
921 | return importRuleTag;
|
922 | }
|
923 |
|
924 | var firstTag = _this.tags[0];
|
925 | var insertBefore = true;
|
926 |
|
927 | return _this.importRuleTag = makeTag(_this.target, firstTag ? firstTag.styleTag : null, _this.forceServer, insertBefore);
|
928 | };
|
929 |
|
930 | sheetRunningId += 1;
|
931 | this.id = sheetRunningId;
|
932 | this.forceServer = forceServer;
|
933 | this.target = forceServer ? null : target;
|
934 | this.tagMap = {};
|
935 | this.deferred = {};
|
936 | this.rehydratedNames = {};
|
937 | this.ignoreRehydratedNames = {};
|
938 | this.tags = [];
|
939 | this.capacity = 1;
|
940 | this.clones = [];
|
941 | }
|
942 |
|
943 |
|
944 |
|
945 |
|
946 | StyleSheet.prototype.rehydrate = function rehydrate() {
|
947 | if (!IS_BROWSER || this.forceServer) {
|
948 | return this;
|
949 | }
|
950 | var els = [];
|
951 | var extracted = [];
|
952 | var isStreamed = false;
|
953 |
|
954 |
|
955 | var nodes = document.querySelectorAll('style[' + SC_ATTR + '][' + SC_VERSION_ATTR + '="' + "4.0.2" + '"]');
|
956 | var nodesSize = nodes.length;
|
957 |
|
958 |
|
959 | if (nodesSize === 0) {
|
960 | return this;
|
961 | }
|
962 |
|
963 | for (var i = 0; i < nodesSize; i += 1) {
|
964 |
|
965 | var el = nodes[i];
|
966 |
|
967 |
|
968 | if (!isStreamed) isStreamed = !!el.getAttribute(SC_STREAM_ATTR);
|
969 |
|
970 |
|
971 | var elNames = (el.getAttribute(SC_ATTR) || '').trim().split(SPLIT_REGEX);
|
972 | var elNamesSize = elNames.length;
|
973 | for (var j = 0; j < elNamesSize; j += 1) {
|
974 | var name = elNames[j];
|
975 |
|
976 | this.rehydratedNames[name] = true;
|
977 | }
|
978 |
|
979 |
|
980 | extracted.push.apply(extracted, extractComps(el.textContent));
|
981 |
|
982 |
|
983 | els.push(el);
|
984 | }
|
985 |
|
986 |
|
987 | var extractedSize = extracted.length;
|
988 | if (extractedSize === 0) {
|
989 | return this;
|
990 | }
|
991 |
|
992 |
|
993 | var tag = this.makeTag(null);
|
994 | var rehydrationTag = makeRehydrationTag(tag, els, extracted, isStreamed);
|
995 |
|
996 |
|
997 | this.capacity = Math.max(1, MAX_SIZE - extractedSize);
|
998 | this.tags.push(rehydrationTag);
|
999 |
|
1000 |
|
1001 | for (var _j = 0; _j < extractedSize; _j += 1) {
|
1002 | this.tagMap[extracted[_j].componentId] = rehydrationTag;
|
1003 | }
|
1004 |
|
1005 | return this;
|
1006 | };
|
1007 |
|
1008 | |
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 | StyleSheet.reset = function reset() {
|
1015 | var forceServer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
1016 |
|
1017 | master = new StyleSheet(undefined, forceServer).rehydrate();
|
1018 | };
|
1019 |
|
1020 | |
1021 |
|
1022 |
|
1023 |
|
1024 | StyleSheet.prototype.clone = function clone() {
|
1025 | var sheet = new StyleSheet(this.target, this.forceServer);
|
1026 |
|
1027 |
|
1028 | this.clones.push(sheet);
|
1029 |
|
1030 |
|
1031 | sheet.tags = this.tags.map(function (tag) {
|
1032 | var ids = tag.getIds();
|
1033 | var newTag = tag.clone();
|
1034 |
|
1035 |
|
1036 | for (var i = 0; i < ids.length; i += 1) {
|
1037 | sheet.tagMap[ids[i]] = newTag;
|
1038 | }
|
1039 |
|
1040 | return newTag;
|
1041 | });
|
1042 |
|
1043 |
|
1044 | sheet.rehydratedNames = _extends({}, this.rehydratedNames);
|
1045 | sheet.deferred = _extends({}, this.deferred);
|
1046 |
|
1047 | return sheet;
|
1048 | };
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 | StyleSheet.prototype.sealAllTags = function sealAllTags() {
|
1054 | this.capacity = 1;
|
1055 |
|
1056 | this.tags.forEach(function (tag) {
|
1057 |
|
1058 | tag.sealed = true;
|
1059 | });
|
1060 | };
|
1061 |
|
1062 | StyleSheet.prototype.makeTag = function makeTag$$1(tag) {
|
1063 | var lastEl = tag ? tag.styleTag : null;
|
1064 | var insertBefore = false;
|
1065 |
|
1066 | return makeTag(this.target, lastEl, this.forceServer, insertBefore, this.getImportRuleTag);
|
1067 | };
|
1068 |
|
1069 |
|
1070 | StyleSheet.prototype.getTagForId = function getTagForId(id) {
|
1071 |
|
1072 | var prev = this.tagMap[id];
|
1073 | if (prev !== undefined && !prev.sealed) {
|
1074 | return prev;
|
1075 | }
|
1076 |
|
1077 | var tag = this.tags[this.tags.length - 1];
|
1078 |
|
1079 |
|
1080 | this.capacity -= 1;
|
1081 |
|
1082 | if (this.capacity === 0) {
|
1083 | this.capacity = MAX_SIZE;
|
1084 | tag = this.makeTag(tag);
|
1085 | this.tags.push(tag);
|
1086 | }
|
1087 |
|
1088 | return this.tagMap[id] = tag;
|
1089 | };
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 | StyleSheet.prototype.hasId = function hasId(id) {
|
1095 | return this.tagMap[id] !== undefined;
|
1096 | };
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 | StyleSheet.prototype.hasNameForId = function hasNameForId(id, name) {
|
1102 |
|
1103 | if (this.ignoreRehydratedNames[id] === undefined && this.rehydratedNames[name]) {
|
1104 | return true;
|
1105 | }
|
1106 |
|
1107 | var tag = this.tagMap[id];
|
1108 | return tag !== undefined && tag.hasNameForId(id, name);
|
1109 | };
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 | StyleSheet.prototype.deferredInject = function deferredInject(id, cssRules) {
|
1115 |
|
1116 | if (this.tagMap[id] !== undefined) return;
|
1117 |
|
1118 | var clones = this.clones;
|
1119 |
|
1120 | for (var i = 0; i < clones.length; i += 1) {
|
1121 | clones[i].deferredInject(id, cssRules);
|
1122 | }
|
1123 |
|
1124 | this.getTagForId(id).insertMarker(id);
|
1125 | this.deferred[id] = cssRules;
|
1126 | };
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 | StyleSheet.prototype.inject = function inject(id, cssRules, name) {
|
1132 | var clones = this.clones;
|
1133 |
|
1134 |
|
1135 | for (var i = 0; i < clones.length; i += 1) {
|
1136 | clones[i].inject(id, cssRules, name);
|
1137 | }
|
1138 |
|
1139 | var tag = this.getTagForId(id);
|
1140 |
|
1141 |
|
1142 | if (this.deferred[id] !== undefined) {
|
1143 |
|
1144 |
|
1145 |
|
1146 | var rules = this.deferred[id].concat(cssRules);
|
1147 | tag.insertRules(id, rules, name);
|
1148 |
|
1149 | this.deferred[id] = undefined;
|
1150 | } else {
|
1151 | tag.insertRules(id, cssRules, name);
|
1152 | }
|
1153 | };
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 | StyleSheet.prototype.remove = function remove(id) {
|
1159 | var tag = this.tagMap[id];
|
1160 | if (tag === undefined) return;
|
1161 |
|
1162 | var clones = this.clones;
|
1163 |
|
1164 | for (var i = 0; i < clones.length; i += 1) {
|
1165 | clones[i].remove(id);
|
1166 | }
|
1167 |
|
1168 |
|
1169 | tag.removeRules(id);
|
1170 |
|
1171 |
|
1172 | this.ignoreRehydratedNames[id] = true;
|
1173 |
|
1174 |
|
1175 | this.deferred[id] = undefined;
|
1176 | };
|
1177 |
|
1178 | StyleSheet.prototype.toHTML = function toHTML() {
|
1179 | return this.tags.map(function (tag) {
|
1180 | return tag.toHTML();
|
1181 | }).join('');
|
1182 | };
|
1183 |
|
1184 | StyleSheet.prototype.toReactElements = function toReactElements() {
|
1185 | var id = this.id;
|
1186 |
|
1187 |
|
1188 | return this.tags.map(function (tag, i) {
|
1189 | var key = 'sc-' + id + '-' + i;
|
1190 | return React.cloneElement(tag.toElement(), { key: key });
|
1191 | });
|
1192 | };
|
1193 |
|
1194 | createClass(StyleSheet, null, [{
|
1195 | key: 'master',
|
1196 | get: function get$$1() {
|
1197 | return master || (master = new StyleSheet().rehydrate());
|
1198 | }
|
1199 |
|
1200 |
|
1201 |
|
1202 | }, {
|
1203 | key: 'instance',
|
1204 | get: function get$$1() {
|
1205 | return StyleSheet.master;
|
1206 | }
|
1207 | }]);
|
1208 | return StyleSheet;
|
1209 | }();
|
1210 |
|
1211 |
|
1212 |
|
1213 | var Keyframes = function () {
|
1214 | function Keyframes(name, rules) {
|
1215 | var _this = this;
|
1216 |
|
1217 | classCallCheck(this, Keyframes);
|
1218 |
|
1219 | this.inject = function (styleSheet) {
|
1220 | if (!styleSheet.hasNameForId(_this.id, _this.name)) {
|
1221 | styleSheet.inject(_this.id, _this.rules, _this.name);
|
1222 | }
|
1223 | };
|
1224 |
|
1225 | this.toString = function () {
|
1226 | throw new StyledComponentsError(12, String(_this.name));
|
1227 | };
|
1228 |
|
1229 | this.name = name;
|
1230 | this.rules = rules;
|
1231 |
|
1232 | this.id = 'sc-keyframes-' + name;
|
1233 | }
|
1234 |
|
1235 | Keyframes.prototype.getName = function getName() {
|
1236 | return this.name;
|
1237 | };
|
1238 |
|
1239 | return Keyframes;
|
1240 | }();
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 | var uppercasePattern = /([A-Z])/g;
|
1250 | var msPattern = /^ms-/;
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 | function hyphenateStyleName(string) {
|
1269 | return string.replace(uppercasePattern, '-$1').toLowerCase().replace(msPattern, '-ms-');
|
1270 | }
|
1271 |
|
1272 |
|
1273 |
|
1274 | var objToCss = function objToCss(obj, prevKey) {
|
1275 | var css = Object.keys(obj).filter(function (key) {
|
1276 | var chunk = obj[key];
|
1277 | return chunk !== undefined && chunk !== null && chunk !== false && chunk !== '';
|
1278 | }).map(function (key) {
|
1279 | if (isPlainObject(obj[key])) return objToCss(obj[key], key);
|
1280 | return hyphenateStyleName(key) + ': ' + obj[key] + ';';
|
1281 | }).join(' ');
|
1282 | return prevKey ? prevKey + ' {\n ' + css + '\n}' : css;
|
1283 | };
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 | var isFalsish = function isFalsish(chunk) {
|
1289 | return chunk === undefined || chunk === null || chunk === false || chunk === '';
|
1290 | };
|
1291 |
|
1292 | function flatten(chunk, executionContext, styleSheet) {
|
1293 | if (Array.isArray(chunk)) {
|
1294 | var ruleSet = [];
|
1295 |
|
1296 | for (var i = 0, len = chunk.length, result; i < len; i += 1) {
|
1297 | result = flatten(chunk[i], executionContext, styleSheet);
|
1298 |
|
1299 | if (result === null) continue;else if (Array.isArray(result)) ruleSet.push.apply(ruleSet, result);else ruleSet.push(result);
|
1300 | }
|
1301 |
|
1302 | return ruleSet;
|
1303 | }
|
1304 |
|
1305 | if (isFalsish(chunk)) {
|
1306 | return null;
|
1307 | }
|
1308 |
|
1309 |
|
1310 | if (isStyledComponent(chunk)) {
|
1311 | return '.' + chunk.styledComponentId;
|
1312 | }
|
1313 |
|
1314 |
|
1315 | if (isFunction(chunk)) {
|
1316 | if (executionContext) {
|
1317 | if (process.env.NODE_ENV !== 'production') {
|
1318 |
|
1319 | try {
|
1320 |
|
1321 | if (reactIs.isElement(new chunk(executionContext))) {
|
1322 | console.warn(getComponentName(chunk) + ' is not a styled component and cannot be referred to via component selector. See https://www.styled-components.com/docs/advanced#referring-to-other-components for more details.');
|
1323 | }
|
1324 |
|
1325 | } catch (e) {}
|
1326 | }
|
1327 |
|
1328 | return flatten(chunk(executionContext), executionContext, styleSheet);
|
1329 | } else return chunk;
|
1330 | }
|
1331 |
|
1332 | if (chunk instanceof Keyframes) {
|
1333 | if (styleSheet) {
|
1334 | chunk.inject(styleSheet);
|
1335 | return chunk.getName();
|
1336 | } else return chunk;
|
1337 | }
|
1338 |
|
1339 |
|
1340 | return isPlainObject(chunk) ? objToCss(chunk) : chunk.toString();
|
1341 | }
|
1342 |
|
1343 |
|
1344 |
|
1345 | function css(styles) {
|
1346 | for (var _len = arguments.length, interpolations = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
1347 | interpolations[_key - 1] = arguments[_key];
|
1348 | }
|
1349 |
|
1350 | if (isFunction(styles) || isPlainObject(styles)) {
|
1351 |
|
1352 | return flatten(interleave(EMPTY_ARRAY, [styles].concat(interpolations)));
|
1353 | }
|
1354 |
|
1355 |
|
1356 | return flatten(interleave(styles, interpolations));
|
1357 | }
|
1358 |
|
1359 |
|
1360 |
|
1361 | function constructWithOptions(componentConstructor, tag) {
|
1362 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EMPTY_OBJECT;
|
1363 |
|
1364 | if (!reactIs.isValidElementType(tag)) {
|
1365 | throw new StyledComponentsError(1, String(tag));
|
1366 | }
|
1367 |
|
1368 |
|
1369 |
|
1370 | var templateFunction = function templateFunction() {
|
1371 | return componentConstructor(tag, options, css.apply(undefined, arguments));
|
1372 | };
|
1373 |
|
1374 |
|
1375 | templateFunction.withConfig = function (config) {
|
1376 | return constructWithOptions(componentConstructor, tag, _extends({}, options, config));
|
1377 | };
|
1378 | templateFunction.attrs = function (attrs) {
|
1379 | return constructWithOptions(componentConstructor, tag, _extends({}, options, {
|
1380 | attrs: _extends({}, options.attrs || EMPTY_OBJECT, attrs)
|
1381 | }));
|
1382 | };
|
1383 |
|
1384 | return templateFunction;
|
1385 | }
|
1386 |
|
1387 |
|
1388 |
|
1389 | function murmurhash(c) {
|
1390 | for (var e = c.length | 0, a = e | 0, d = 0, b; e >= 4;) {
|
1391 | b = c.charCodeAt(d) & 255 | (c.charCodeAt(++d) & 255) << 8 | (c.charCodeAt(++d) & 255) << 16 | (c.charCodeAt(++d) & 255) << 24, b = 1540483477 * (b & 65535) + ((1540483477 * (b >>> 16) & 65535) << 16), b ^= b >>> 24, b = 1540483477 * (b & 65535) + ((1540483477 * (b >>> 16) & 65535) << 16), a = 1540483477 * (a & 65535) + ((1540483477 * (a >>> 16) & 65535) << 16) ^ b, e -= 4, ++d;
|
1392 | }
|
1393 | switch (e) {
|
1394 | case 3:
|
1395 | a ^= (c.charCodeAt(d + 2) & 255) << 16;
|
1396 | case 2:
|
1397 | a ^= (c.charCodeAt(d + 1) & 255) << 8;
|
1398 | case 1:
|
1399 | a ^= c.charCodeAt(d) & 255, a = 1540483477 * (a & 65535) + ((1540483477 * (a >>> 16) & 65535) << 16);
|
1400 | }
|
1401 | a ^= a >>> 13;
|
1402 | a = 1540483477 * (a & 65535) + ((1540483477 * (a >>> 16) & 65535) << 16);
|
1403 | return (a ^ a >>> 15) >>> 0;
|
1404 | }
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 | var charsLength = 52;
|
1412 |
|
1413 |
|
1414 | var getAlphabeticChar = function getAlphabeticChar(code) {
|
1415 | return String.fromCharCode(code + (code > 25 ? 39 : 97));
|
1416 | };
|
1417 |
|
1418 |
|
1419 | function generateAlphabeticName(code) {
|
1420 | var name = '';
|
1421 | var x = void 0;
|
1422 |
|
1423 |
|
1424 | for (x = code; x > charsLength; x = Math.floor(x / charsLength)) {
|
1425 | name = getAlphabeticChar(x % charsLength) + name;
|
1426 | }
|
1427 |
|
1428 | return getAlphabeticChar(x % charsLength) + name;
|
1429 | }
|
1430 |
|
1431 |
|
1432 |
|
1433 | function isStaticRules(rules, attrs) {
|
1434 | for (var i = 0; i < rules.length; i += 1) {
|
1435 | var rule = rules[i];
|
1436 |
|
1437 |
|
1438 | if (Array.isArray(rule) && !isStaticRules(rule)) {
|
1439 | return false;
|
1440 | } else if (isFunction(rule) && !isStyledComponent(rule)) {
|
1441 |
|
1442 |
|
1443 | return false;
|
1444 | }
|
1445 | }
|
1446 |
|
1447 | if (attrs !== undefined) {
|
1448 |
|
1449 | for (var key in attrs) {
|
1450 | var value = attrs[key];
|
1451 | if (isFunction(value)) {
|
1452 | return false;
|
1453 | }
|
1454 | }
|
1455 | }
|
1456 |
|
1457 | return true;
|
1458 | }
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 | var isHMREnabled = process.env.NODE_ENV !== 'production' && typeof module !== 'undefined' && module.hot;
|
1465 |
|
1466 |
|
1467 | var hasher = function hasher(str) {
|
1468 | return generateAlphabeticName(murmurhash(str));
|
1469 | };
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 | var ComponentStyle = function () {
|
1477 | function ComponentStyle(rules, attrs, componentId) {
|
1478 | classCallCheck(this, ComponentStyle);
|
1479 |
|
1480 | this.rules = rules;
|
1481 | this.isStatic = !isHMREnabled && isStaticRules(rules, attrs);
|
1482 | this.componentId = componentId;
|
1483 |
|
1484 | if (!StyleSheet.master.hasId(componentId)) {
|
1485 | var placeholder = process.env.NODE_ENV !== 'production' ? ['.' + componentId + ' {}'] : [];
|
1486 |
|
1487 | StyleSheet.master.deferredInject(componentId, placeholder);
|
1488 | }
|
1489 | }
|
1490 |
|
1491 | |
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 | ComponentStyle.prototype.generateAndInjectStyles = function generateAndInjectStyles(executionContext, styleSheet) {
|
1499 | var isStatic = this.isStatic,
|
1500 | componentId = this.componentId,
|
1501 | lastClassName = this.lastClassName;
|
1502 |
|
1503 | if (IS_BROWSER && isStatic && lastClassName !== undefined && styleSheet.hasNameForId(componentId, lastClassName)) {
|
1504 | return lastClassName;
|
1505 | }
|
1506 |
|
1507 | var flatCSS = flatten(this.rules, executionContext, styleSheet);
|
1508 | var name = hasher(this.componentId + flatCSS.join(''));
|
1509 | if (!styleSheet.hasNameForId(componentId, name)) {
|
1510 | styleSheet.inject(this.componentId, stringifyRules(flatCSS, '.' + name, undefined, componentId), name);
|
1511 | }
|
1512 |
|
1513 | this.lastClassName = name;
|
1514 | return name;
|
1515 | };
|
1516 |
|
1517 | ComponentStyle.generateName = function generateName(str) {
|
1518 | return hasher(str);
|
1519 | };
|
1520 |
|
1521 | return ComponentStyle;
|
1522 | }();
|
1523 |
|
1524 |
|
1525 |
|
1526 | var LIMIT = 200;
|
1527 |
|
1528 | var createWarnTooManyClasses = (function (displayName) {
|
1529 | var generatedClasses = {};
|
1530 | var warningSeen = false;
|
1531 |
|
1532 | return function (className) {
|
1533 | if (!warningSeen) {
|
1534 | generatedClasses[className] = true;
|
1535 | if (Object.keys(generatedClasses).length >= LIMIT) {
|
1536 |
|
1537 |
|
1538 | console.warn('Over ' + LIMIT + ' classes were generated for component ' + displayName + '. \n' + 'Consider using the attrs method, together with a style object for frequently changed styles.\n' + 'Example:\n' + ' const Component = styled.div.attrs({\n' + ' style: ({ background }) => ({\n' + ' background,\n' + ' }),\n' + ' })`width: 100%;`\n\n' + ' <Component />');
|
1539 | warningSeen = true;
|
1540 | generatedClasses = {};
|
1541 | }
|
1542 | }
|
1543 | };
|
1544 | });
|
1545 |
|
1546 |
|
1547 |
|
1548 | var determineTheme = (function (props, fallbackTheme) {
|
1549 | var defaultProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EMPTY_OBJECT;
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 | var isDefaultTheme = defaultProps ? props.theme === defaultProps.theme : false;
|
1556 | var theme = props.theme && !isDefaultTheme ? props.theme : fallbackTheme || defaultProps.theme;
|
1557 |
|
1558 |
|
1559 | return theme;
|
1560 | });
|
1561 |
|
1562 |
|
1563 | var escapeRegex = /[[\].#*$><+~=|^:(),"'`-]+/g;
|
1564 | var dashesAtEnds = /(^-|-$)/g;
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 | function escape(str) {
|
1571 | return str
|
1572 |
|
1573 | .replace(escapeRegex, '-')
|
1574 |
|
1575 |
|
1576 | .replace(dashesAtEnds, '');
|
1577 | }
|
1578 |
|
1579 |
|
1580 |
|
1581 | function isTag(target) /* : %checks */{
|
1582 | return typeof target === 'string';
|
1583 | }
|
1584 |
|
1585 |
|
1586 |
|
1587 | function generateDisplayName(target) {
|
1588 | return isTag(target) ? 'styled.' + target : 'Styled(' + getComponentName(target) + ')';
|
1589 | }
|
1590 |
|
1591 | var _TYPE_STATICS;
|
1592 |
|
1593 | var REACT_STATICS = {
|
1594 | childContextTypes: true,
|
1595 | contextTypes: true,
|
1596 | defaultProps: true,
|
1597 | displayName: true,
|
1598 | getDerivedStateFromProps: true,
|
1599 | propTypes: true,
|
1600 | type: true
|
1601 | };
|
1602 |
|
1603 | var KNOWN_STATICS = {
|
1604 | name: true,
|
1605 | length: true,
|
1606 | prototype: true,
|
1607 | caller: true,
|
1608 | callee: true,
|
1609 | arguments: true,
|
1610 | arity: true
|
1611 | };
|
1612 |
|
1613 | var TYPE_STATICS = (_TYPE_STATICS = {}, _TYPE_STATICS[reactIs.ForwardRef] = {
|
1614 | $$typeof: true,
|
1615 | render: true
|
1616 | }, _TYPE_STATICS);
|
1617 |
|
1618 | var defineProperty$1 = Object.defineProperty,
|
1619 | getOwnPropertyNames = Object.getOwnPropertyNames,
|
1620 | _Object$getOwnPropert = Object.getOwnPropertySymbols,
|
1621 | getOwnPropertySymbols = _Object$getOwnPropert === undefined ? function () {
|
1622 | return [];
|
1623 | } : _Object$getOwnPropert,
|
1624 | getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor,
|
1625 | getPrototypeOf = Object.getPrototypeOf,
|
1626 | objectPrototype = Object.prototype;
|
1627 | var arrayPrototype = Array.prototype;
|
1628 |
|
1629 |
|
1630 | function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
|
1631 | if (typeof sourceComponent !== 'string') {
|
1632 |
|
1633 |
|
1634 | var inheritedComponent = getPrototypeOf(sourceComponent);
|
1635 |
|
1636 | if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
1637 | hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
|
1638 | }
|
1639 |
|
1640 | var keys = arrayPrototype.concat(getOwnPropertyNames(sourceComponent),
|
1641 |
|
1642 | getOwnPropertySymbols(sourceComponent));
|
1643 |
|
1644 | var targetStatics = TYPE_STATICS[targetComponent.$$typeof] || REACT_STATICS;
|
1645 |
|
1646 | var sourceStatics = TYPE_STATICS[sourceComponent.$$typeof] || REACT_STATICS;
|
1647 |
|
1648 | var i = keys.length;
|
1649 | var descriptor = void 0;
|
1650 | var key = void 0;
|
1651 |
|
1652 |
|
1653 | while (i--) {
|
1654 | key = keys[i];
|
1655 |
|
1656 | if (
|
1657 |
|
1658 | !KNOWN_STATICS[key] && !(blacklist && blacklist[key]) && !(sourceStatics && sourceStatics[key]) &&
|
1659 |
|
1660 | !(targetStatics && targetStatics[key])) {
|
1661 | descriptor = getOwnPropertyDescriptor(sourceComponent, key);
|
1662 |
|
1663 | if (descriptor) {
|
1664 | try {
|
1665 |
|
1666 | defineProperty$1(targetComponent, key, descriptor);
|
1667 | } catch (e) {
|
1668 |
|
1669 | }
|
1670 | }
|
1671 | }
|
1672 | }
|
1673 |
|
1674 | return targetComponent;
|
1675 | }
|
1676 |
|
1677 | return targetComponent;
|
1678 | }
|
1679 |
|
1680 |
|
1681 | function isDerivedReactComponent(fn) {
|
1682 | return !!(fn && fn.prototype && fn.prototype.isReactComponent);
|
1683 | }
|
1684 |
|
1685 |
|
1686 |
|
1687 | var ThemeContext = React.createContext();
|
1688 |
|
1689 | var ThemeConsumer = ThemeContext.Consumer;
|
1690 |
|
1691 |
|
1692 |
|
1693 |
|
1694 |
|
1695 | var ThemeProvider = function (_Component) {
|
1696 | inherits(ThemeProvider, _Component);
|
1697 |
|
1698 | function ThemeProvider(props) {
|
1699 | classCallCheck(this, ThemeProvider);
|
1700 |
|
1701 | var _this = possibleConstructorReturn(this, _Component.call(this, props));
|
1702 |
|
1703 | _this.getContext = memoize(_this.getContext.bind(_this));
|
1704 | _this.renderInner = _this.renderInner.bind(_this);
|
1705 | return _this;
|
1706 | }
|
1707 |
|
1708 | ThemeProvider.prototype.render = function render() {
|
1709 | if (!this.props.children) return null;
|
1710 |
|
1711 | return React__default.createElement(
|
1712 | ThemeContext.Consumer,
|
1713 | null,
|
1714 | this.renderInner
|
1715 | );
|
1716 | };
|
1717 |
|
1718 | ThemeProvider.prototype.renderInner = function renderInner(outerTheme) {
|
1719 | var context = this.getContext(this.props.theme, outerTheme);
|
1720 |
|
1721 | return React__default.createElement(
|
1722 | ThemeContext.Provider,
|
1723 | { value: context },
|
1724 | React__default.Children.only(this.props.children)
|
1725 | );
|
1726 | };
|
1727 |
|
1728 | |
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 | ThemeProvider.prototype.getTheme = function getTheme(theme, outerTheme) {
|
1735 | if (isFunction(theme)) {
|
1736 | var mergedTheme = theme(outerTheme);
|
1737 |
|
1738 | if (process.env.NODE_ENV !== 'production' && (mergedTheme === null || Array.isArray(mergedTheme) || (typeof mergedTheme === 'undefined' ? 'undefined' : _typeof(mergedTheme)) !== 'object')) {
|
1739 | throw new StyledComponentsError(7);
|
1740 | }
|
1741 |
|
1742 | return mergedTheme;
|
1743 | }
|
1744 |
|
1745 | if (theme === null || Array.isArray(theme) || (typeof theme === 'undefined' ? 'undefined' : _typeof(theme)) !== 'object') {
|
1746 | throw new StyledComponentsError(8);
|
1747 | }
|
1748 |
|
1749 | return _extends({}, outerTheme, theme);
|
1750 | };
|
1751 |
|
1752 | ThemeProvider.prototype.getContext = function getContext(theme, outerTheme) {
|
1753 | return this.getTheme(theme, outerTheme);
|
1754 | };
|
1755 |
|
1756 | return ThemeProvider;
|
1757 | }(React.Component);
|
1758 |
|
1759 |
|
1760 |
|
1761 | var ServerStyleSheet = function () {
|
1762 | function ServerStyleSheet() {
|
1763 | classCallCheck(this, ServerStyleSheet);
|
1764 |
|
1765 |
|
1766 | this.masterSheet = StyleSheet.master;
|
1767 | this.instance = this.masterSheet.clone();
|
1768 | this.sealed = false;
|
1769 | }
|
1770 |
|
1771 | |
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 | ServerStyleSheet.prototype.seal = function seal() {
|
1778 | if (!this.sealed) {
|
1779 |
|
1780 | var index = this.masterSheet.clones.indexOf(this.instance);
|
1781 | this.masterSheet.clones.splice(index, 1);
|
1782 | this.sealed = true;
|
1783 | }
|
1784 | };
|
1785 |
|
1786 | ServerStyleSheet.prototype.collectStyles = function collectStyles(children) {
|
1787 | if (this.sealed) {
|
1788 | throw new StyledComponentsError(2);
|
1789 | }
|
1790 |
|
1791 | return React__default.createElement(
|
1792 | StyleSheetManager,
|
1793 | { sheet: this.instance },
|
1794 | children
|
1795 | );
|
1796 | };
|
1797 |
|
1798 | ServerStyleSheet.prototype.getStyleTags = function getStyleTags() {
|
1799 | this.seal();
|
1800 | return this.instance.toHTML();
|
1801 | };
|
1802 |
|
1803 | ServerStyleSheet.prototype.getStyleElement = function getStyleElement() {
|
1804 | this.seal();
|
1805 | return this.instance.toReactElements();
|
1806 | };
|
1807 |
|
1808 | ServerStyleSheet.prototype.interleaveWithNodeStream = function interleaveWithNodeStream(readableStream) {
|
1809 | var _this = this;
|
1810 |
|
1811 | if (IS_BROWSER) {
|
1812 | throw new StyledComponentsError(3);
|
1813 | }
|
1814 |
|
1815 |
|
1816 | var instance = this.instance;
|
1817 |
|
1818 | var instanceTagIndex = 0;
|
1819 |
|
1820 | var streamAttr = SC_STREAM_ATTR + '="true"';
|
1821 |
|
1822 | var transformer = new stream.Transform({
|
1823 | transform: function appendStyleChunks(chunk, /* encoding */_, callback) {
|
1824 | var tags = instance.tags;
|
1825 |
|
1826 | var html = '';
|
1827 |
|
1828 |
|
1829 | for (; instanceTagIndex < tags.length; instanceTagIndex += 1) {
|
1830 | var tag = tags[instanceTagIndex];
|
1831 | html += tag.toHTML(streamAttr);
|
1832 | }
|
1833 |
|
1834 |
|
1835 | instance.sealAllTags();
|
1836 |
|
1837 |
|
1838 | this.push(html + chunk);
|
1839 | callback();
|
1840 | }
|
1841 | });
|
1842 |
|
1843 | readableStream.on('end', function () {
|
1844 | return _this.seal();
|
1845 | });
|
1846 | readableStream.on('error', function (err) {
|
1847 | _this.seal();
|
1848 |
|
1849 |
|
1850 | transformer.emit('error', err);
|
1851 | });
|
1852 |
|
1853 | return readableStream.pipe(transformer);
|
1854 | };
|
1855 |
|
1856 | return ServerStyleSheet;
|
1857 | }();
|
1858 |
|
1859 |
|
1860 |
|
1861 | var StyleSheetContext = React.createContext();
|
1862 |
|
1863 | var StyleSheetConsumer = StyleSheetContext.Consumer;
|
1864 |
|
1865 | var StyleSheetManager = function (_Component) {
|
1866 | inherits(StyleSheetManager, _Component);
|
1867 |
|
1868 | function StyleSheetManager(props) {
|
1869 | classCallCheck(this, StyleSheetManager);
|
1870 |
|
1871 | var _this = possibleConstructorReturn(this, _Component.call(this, props));
|
1872 |
|
1873 | _this.getContext = memoize(_this.getContext);
|
1874 | return _this;
|
1875 | }
|
1876 |
|
1877 | StyleSheetManager.prototype.getContext = function getContext(sheet, target) {
|
1878 | if (sheet) {
|
1879 | return sheet;
|
1880 | } else if (target) {
|
1881 | return new StyleSheet(target);
|
1882 | } else {
|
1883 | throw new StyledComponentsError(4);
|
1884 | }
|
1885 | };
|
1886 |
|
1887 | StyleSheetManager.prototype.render = function render() {
|
1888 | var _props = this.props,
|
1889 | children = _props.children,
|
1890 | sheet = _props.sheet,
|
1891 | target = _props.target;
|
1892 |
|
1893 | var context = this.getContext(sheet, target);
|
1894 | return React__default.createElement(
|
1895 | StyleSheetContext.Provider,
|
1896 | { value: context },
|
1897 | React__default.Children.only(children)
|
1898 | );
|
1899 | };
|
1900 |
|
1901 | return StyleSheetManager;
|
1902 | }(React.Component);
|
1903 | process.env.NODE_ENV !== "production" ? StyleSheetManager.propTypes = {
|
1904 | sheet: PropTypes.oneOfType([PropTypes.instanceOf(StyleSheet), PropTypes.instanceOf(ServerStyleSheet)]),
|
1905 |
|
1906 | target: PropTypes.shape({
|
1907 | appendChild: PropTypes.func.isRequired
|
1908 | })
|
1909 | } : void 0;
|
1910 |
|
1911 |
|
1912 |
|
1913 | var classNameUseCheckInjector = (function (target) {
|
1914 | var elementClassName = '';
|
1915 |
|
1916 | var targetCDM = target.componentDidMount;
|
1917 |
|
1918 |
|
1919 | target.componentDidMount = function componentDidMount() {
|
1920 | if (typeof targetCDM === 'function') {
|
1921 | targetCDM.call(this);
|
1922 | }
|
1923 |
|
1924 | var classNames = elementClassName.replace(/ +/g, ' ').trim().split(' ');
|
1925 |
|
1926 | var node = ReactDOM.findDOMNode(this);
|
1927 | var selector = classNames.map(function (s) {
|
1928 | return '.' + s;
|
1929 | }).join('');
|
1930 |
|
1931 | if (node && node.nodeType === 1 && !classNames.every(function (className) {
|
1932 | return node.classList && node.classList.contains(className);
|
1933 | }) && !node.querySelector(selector)) {
|
1934 | console.warn('It looks like you\'ve wrapped styled() around your React component (' + getComponentName(this.props.forwardedClass.target) + '), but the className prop is not being passed down to a child. No styles will be rendered unless className is composed within your React component.');
|
1935 | }
|
1936 | };
|
1937 |
|
1938 | var prevRenderInner = target.renderInner;
|
1939 |
|
1940 |
|
1941 | target.renderInner = function renderInner() {
|
1942 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1943 | args[_key] = arguments[_key];
|
1944 | }
|
1945 |
|
1946 | var element = prevRenderInner.apply(this, args);
|
1947 |
|
1948 | elementClassName = element.props.className;
|
1949 |
|
1950 | return element;
|
1951 | };
|
1952 | });
|
1953 |
|
1954 |
|
1955 |
|
1956 | var identifiers = {};
|
1957 |
|
1958 |
|
1959 | function generateId(_ComponentStyle, _displayName, parentComponentId) {
|
1960 | var displayName = typeof _displayName !== 'string' ? 'sc' : escape(_displayName);
|
1961 |
|
1962 | |
1963 |
|
1964 |
|
1965 |
|
1966 | var nr = (identifiers[displayName] || 0) + 1;
|
1967 | identifiers[displayName] = nr;
|
1968 |
|
1969 | var componentId = displayName + '-' + _ComponentStyle.generateName(displayName + nr);
|
1970 |
|
1971 | return parentComponentId ? parentComponentId + '-' + componentId : componentId;
|
1972 | }
|
1973 |
|
1974 | var warnInnerRef = once(function () {
|
1975 | return (
|
1976 |
|
1977 | console.warn('The "innerRef" API has been removed in styled-components v4 in favor of React 16 ref forwarding, use "ref" instead like a typical component.')
|
1978 | );
|
1979 | });
|
1980 |
|
1981 |
|
1982 |
|
1983 | var StyledComponent = function (_Component) {
|
1984 | inherits(StyledComponent, _Component);
|
1985 |
|
1986 | function StyledComponent() {
|
1987 | classCallCheck(this, StyledComponent);
|
1988 |
|
1989 | var _this = possibleConstructorReturn(this, _Component.call(this));
|
1990 |
|
1991 | _this.attrs = {};
|
1992 |
|
1993 | _this.renderOuter = _this.renderOuter.bind(_this);
|
1994 | _this.renderInner = _this.renderInner.bind(_this);
|
1995 |
|
1996 | if (process.env.NODE_ENV !== 'production' && IS_BROWSER) {
|
1997 | classNameUseCheckInjector(_this);
|
1998 | }
|
1999 | return _this;
|
2000 | }
|
2001 |
|
2002 | StyledComponent.prototype.render = function render() {
|
2003 | return React__default.createElement(
|
2004 | StyleSheetConsumer,
|
2005 | null,
|
2006 | this.renderOuter
|
2007 | );
|
2008 | };
|
2009 |
|
2010 | StyledComponent.prototype.renderOuter = function renderOuter(styleSheet) {
|
2011 | this.styleSheet = styleSheet;
|
2012 |
|
2013 | return React__default.createElement(
|
2014 | ThemeConsumer,
|
2015 | null,
|
2016 | this.renderInner
|
2017 | );
|
2018 | };
|
2019 |
|
2020 | StyledComponent.prototype.renderInner = function renderInner(theme) {
|
2021 | var _props$forwardedClass = this.props.forwardedClass,
|
2022 | componentStyle = _props$forwardedClass.componentStyle,
|
2023 | defaultProps = _props$forwardedClass.defaultProps,
|
2024 | styledComponentId = _props$forwardedClass.styledComponentId,
|
2025 | target = _props$forwardedClass.target;
|
2026 |
|
2027 |
|
2028 | var generatedClassName = void 0;
|
2029 | if (componentStyle.isStatic) {
|
2030 | generatedClassName = this.generateAndInjectStyles(EMPTY_OBJECT, this.props, this.styleSheet);
|
2031 | } else if (theme !== undefined) {
|
2032 | generatedClassName = this.generateAndInjectStyles(determineTheme(this.props, theme, defaultProps), this.props, this.styleSheet);
|
2033 | } else {
|
2034 | generatedClassName = this.generateAndInjectStyles(this.props.theme || EMPTY_OBJECT, this.props, this.styleSheet);
|
2035 | }
|
2036 | var elementToBeCreated = this.props.as || this.attrs.as || target;
|
2037 | var isTargetTag = isTag(elementToBeCreated);
|
2038 |
|
2039 | var propsForElement = _extends({}, this.attrs);
|
2040 |
|
2041 | var key = void 0;
|
2042 |
|
2043 | for (key in this.props) {
|
2044 | if (process.env.NODE_ENV !== 'production' && key === 'innerRef') {
|
2045 | warnInnerRef();
|
2046 | }
|
2047 |
|
2048 | if (key === 'forwardedClass' || key === 'as') continue;else if (key === 'forwardedRef') propsForElement.ref = this.props[key];else if (!isTargetTag || validAttr(key)) {
|
2049 |
|
2050 | propsForElement[key] = key === 'style' && key in this.attrs ? _extends({}, this.attrs[key], this.props[key]) : this.props[key];
|
2051 | }
|
2052 | }
|
2053 |
|
2054 | propsForElement.className = [this.props.className, styledComponentId, this.attrs.className, generatedClassName].filter(Boolean).join(' ');
|
2055 |
|
2056 | return React.createElement(elementToBeCreated, propsForElement);
|
2057 | };
|
2058 |
|
2059 | StyledComponent.prototype.buildExecutionContext = function buildExecutionContext(theme, props, attrs) {
|
2060 | var context = _extends({}, props, { theme: theme });
|
2061 |
|
2062 | if (attrs === undefined) return context;
|
2063 |
|
2064 | this.attrs = {};
|
2065 |
|
2066 | var attr = void 0;
|
2067 | var key = void 0;
|
2068 |
|
2069 |
|
2070 | for (key in attrs) {
|
2071 | attr = attrs[key];
|
2072 |
|
2073 | this.attrs[key] = isFunction(attr) && !isDerivedReactComponent(attr) && !isStyledComponent(attr) ? attr(context) : attr;
|
2074 | }
|
2075 |
|
2076 |
|
2077 | return _extends({}, context, this.attrs);
|
2078 | };
|
2079 |
|
2080 | StyledComponent.prototype.generateAndInjectStyles = function generateAndInjectStyles(theme, props) {
|
2081 | var styleSheet = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : StyleSheet.master;
|
2082 | var _props$forwardedClass2 = props.forwardedClass,
|
2083 | attrs = _props$forwardedClass2.attrs,
|
2084 | componentStyle = _props$forwardedClass2.componentStyle,
|
2085 | warnTooManyClasses = _props$forwardedClass2.warnTooManyClasses;
|
2086 |
|
2087 |
|
2088 |
|
2089 |
|
2090 | if (componentStyle.isStatic && attrs === undefined) {
|
2091 | return componentStyle.generateAndInjectStyles(EMPTY_OBJECT, styleSheet);
|
2092 | }
|
2093 |
|
2094 | var className = componentStyle.generateAndInjectStyles(this.buildExecutionContext(theme, props, props.forwardedClass.attrs), styleSheet);
|
2095 |
|
2096 | if (warnTooManyClasses) {
|
2097 | warnTooManyClasses(className);
|
2098 | }
|
2099 |
|
2100 | return className;
|
2101 | };
|
2102 |
|
2103 | return StyledComponent;
|
2104 | }(React.Component);
|
2105 |
|
2106 | function createStyledComponent(target, options, rules) {
|
2107 | var isTargetStyledComp = isStyledComponent(target);
|
2108 | var isClass = !isTag(target);
|
2109 |
|
2110 | var _options$displayName = options.displayName,
|
2111 | displayName = _options$displayName === undefined ? generateDisplayName(target) : _options$displayName,
|
2112 | _options$componentId = options.componentId,
|
2113 | componentId = _options$componentId === undefined ? generateId(ComponentStyle, options.displayName, options.parentComponentId) : _options$componentId,
|
2114 | _options$ParentCompon = options.ParentComponent,
|
2115 | ParentComponent = _options$ParentCompon === undefined ? StyledComponent : _options$ParentCompon,
|
2116 | attrs = options.attrs;
|
2117 |
|
2118 |
|
2119 | var styledComponentId = options.displayName && options.componentId ? escape(options.displayName) + '-' + options.componentId : options.componentId || componentId;
|
2120 |
|
2121 |
|
2122 | var finalAttrs =
|
2123 |
|
2124 | isTargetStyledComp && target.attrs ? _extends({}, target.attrs, attrs) : attrs;
|
2125 |
|
2126 | var componentStyle = new ComponentStyle(isTargetStyledComp ?
|
2127 |
|
2128 | target.componentStyle.rules.concat(rules) : rules, finalAttrs, styledComponentId);
|
2129 |
|
2130 | |
2131 |
|
2132 |
|
2133 |
|
2134 | var WrappedStyledComponent = React__default.forwardRef(function (props, ref) {
|
2135 | return React__default.createElement(ParentComponent, _extends({}, props, { forwardedClass: WrappedStyledComponent, forwardedRef: ref }));
|
2136 | });
|
2137 |
|
2138 |
|
2139 | WrappedStyledComponent.attrs = finalAttrs;
|
2140 |
|
2141 | WrappedStyledComponent.componentStyle = componentStyle;
|
2142 | WrappedStyledComponent.displayName = displayName;
|
2143 |
|
2144 | WrappedStyledComponent.styledComponentId = styledComponentId;
|
2145 |
|
2146 |
|
2147 |
|
2148 | WrappedStyledComponent.target = isTargetStyledComp ? target.target : target;
|
2149 |
|
2150 |
|
2151 | WrappedStyledComponent.withComponent = function withComponent(tag) {
|
2152 | var previousComponentId = options.componentId,
|
2153 | optionsToCopy = objectWithoutProperties(options, ['componentId']);
|
2154 |
|
2155 |
|
2156 | var newComponentId = previousComponentId && previousComponentId + '-' + (isTag(tag) ? tag : escape(getComponentName(tag)));
|
2157 |
|
2158 | var newOptions = _extends({}, optionsToCopy, {
|
2159 | attrs: finalAttrs,
|
2160 | componentId: newComponentId,
|
2161 | ParentComponent: ParentComponent
|
2162 | });
|
2163 |
|
2164 | return createStyledComponent(tag, newOptions, rules);
|
2165 | };
|
2166 |
|
2167 | if (process.env.NODE_ENV !== 'production') {
|
2168 |
|
2169 | WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName);
|
2170 | }
|
2171 |
|
2172 | if (isClass) {
|
2173 | hoistNonReactStatics(WrappedStyledComponent, target, {
|
2174 |
|
2175 | attrs: true,
|
2176 | componentStyle: true,
|
2177 | displayName: true,
|
2178 | styledComponentId: true,
|
2179 | target: true,
|
2180 | warnTooManyClasses: true,
|
2181 | withComponent: true
|
2182 | });
|
2183 | }
|
2184 |
|
2185 | return WrappedStyledComponent;
|
2186 | }
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 | var domElements = ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'big', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr',
|
2192 |
|
2193 |
|
2194 | 'circle', 'clipPath', 'defs', 'ellipse', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'mask', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'stop', 'svg', 'text', 'tspan'];
|
2195 |
|
2196 |
|
2197 |
|
2198 | var styled = function styled(tag) {
|
2199 | return constructWithOptions(createStyledComponent, tag);
|
2200 | };
|
2201 |
|
2202 |
|
2203 | domElements.forEach(function (domElement) {
|
2204 | styled[domElement] = styled(domElement);
|
2205 | });
|
2206 |
|
2207 |
|
2208 |
|
2209 | var GlobalStyle = function () {
|
2210 | function GlobalStyle(rules, componentId) {
|
2211 | classCallCheck(this, GlobalStyle);
|
2212 |
|
2213 | this.rules = rules;
|
2214 | this.componentId = componentId;
|
2215 | this.isStatic = isStaticRules(rules);
|
2216 |
|
2217 | if (!StyleSheet.master.hasId(componentId)) {
|
2218 | StyleSheet.master.deferredInject(componentId, []);
|
2219 | }
|
2220 | }
|
2221 |
|
2222 | GlobalStyle.prototype.createStyles = function createStyles(executionContext, styleSheet) {
|
2223 | var flatCSS = flatten(this.rules, executionContext, styleSheet);
|
2224 | var css = stringifyRules(flatCSS, '');
|
2225 |
|
2226 | styleSheet.inject(this.componentId, css);
|
2227 | };
|
2228 |
|
2229 | GlobalStyle.prototype.removeStyles = function removeStyles(styleSheet) {
|
2230 | var componentId = this.componentId;
|
2231 |
|
2232 | if (styleSheet.hasId(componentId)) {
|
2233 | styleSheet.remove(componentId);
|
2234 | }
|
2235 | };
|
2236 |
|
2237 |
|
2238 |
|
2239 |
|
2240 | GlobalStyle.prototype.renderStyles = function renderStyles(executionContext, styleSheet) {
|
2241 | this.removeStyles(styleSheet);
|
2242 | this.createStyles(executionContext, styleSheet);
|
2243 | };
|
2244 |
|
2245 | return GlobalStyle;
|
2246 | }();
|
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 | if (IS_BROWSER) {
|
2252 | window.scCGSHMRCache = {};
|
2253 | }
|
2254 |
|
2255 | function createGlobalStyle(strings) {
|
2256 | for (var _len = arguments.length, interpolations = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
2257 | interpolations[_key - 1] = arguments[_key];
|
2258 | }
|
2259 |
|
2260 | var rules = css.apply(undefined, [strings].concat(interpolations));
|
2261 | var id = 'sc-global-' + murmurhash(JSON.stringify(rules));
|
2262 | var style = new GlobalStyle(rules, id);
|
2263 |
|
2264 | var GlobalStyleComponent = function (_React$Component) {
|
2265 | inherits(GlobalStyleComponent, _React$Component);
|
2266 |
|
2267 | function GlobalStyleComponent() {
|
2268 | classCallCheck(this, GlobalStyleComponent);
|
2269 |
|
2270 | var _this = possibleConstructorReturn(this, _React$Component.call(this));
|
2271 |
|
2272 | var _this$constructor = _this.constructor,
|
2273 | globalStyle = _this$constructor.globalStyle,
|
2274 | styledComponentId = _this$constructor.styledComponentId;
|
2275 |
|
2276 |
|
2277 | if (IS_BROWSER) {
|
2278 | window.scCGSHMRCache[styledComponentId] = (window.scCGSHMRCache[styledComponentId] || 0) + 1;
|
2279 | }
|
2280 |
|
2281 | |
2282 |
|
2283 |
|
2284 |
|
2285 |
|
2286 | _this.state = {
|
2287 | globalStyle: globalStyle,
|
2288 | styledComponentId: styledComponentId
|
2289 | };
|
2290 | return _this;
|
2291 | }
|
2292 |
|
2293 | GlobalStyleComponent.prototype.componentDidMount = function componentDidMount() {
|
2294 | if (process.env.NODE_ENV !== 'production' && IS_BROWSER && window.scCGSHMRCache[this.state.styledComponentId] > 1 && !this.props.suppressMultiMountWarning) {
|
2295 | console.warn('The global style component ' + this.state.styledComponentId + ' was composed and rendered multiple times in your React component tree. Only the last-rendered copy will have its styles remain in <head> (or your StyleSheetManager target.)');
|
2296 | }
|
2297 | };
|
2298 |
|
2299 | GlobalStyleComponent.prototype.componentWillUnmount = function componentWillUnmount() {
|
2300 | if (window.scCGSHMRCache[this.state.styledComponentId]) {
|
2301 | window.scCGSHMRCache[this.state.styledComponentId] -= 1;
|
2302 | }
|
2303 | |
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 | if (window.scCGSHMRCache[this.state.styledComponentId] === 0) {
|
2309 | this.state.globalStyle.removeStyles(this.styleSheet);
|
2310 | }
|
2311 | };
|
2312 |
|
2313 | GlobalStyleComponent.prototype.render = function render() {
|
2314 | var _this2 = this;
|
2315 |
|
2316 | if (process.env.NODE_ENV !== 'production' && React__default.Children.count(this.props.children)) {
|
2317 | console.warn('The global style component ' + this.state.styledComponentId + ' was given child JSX. createGlobalStyle does not render children.');
|
2318 | }
|
2319 |
|
2320 | return React__default.createElement(
|
2321 | StyleSheetConsumer,
|
2322 | null,
|
2323 | function (styleSheet) {
|
2324 | _this2.styleSheet = styleSheet || StyleSheet.master;
|
2325 |
|
2326 | var globalStyle = _this2.state.globalStyle;
|
2327 |
|
2328 |
|
2329 | if (globalStyle.isStatic) {
|
2330 | globalStyle.renderStyles(STATIC_EXECUTION_CONTEXT, _this2.styleSheet);
|
2331 |
|
2332 | return null;
|
2333 | } else {
|
2334 | return React__default.createElement(
|
2335 | ThemeConsumer,
|
2336 | null,
|
2337 | function (theme) {
|
2338 | var defaultProps = _this2.constructor.defaultProps;
|
2339 |
|
2340 |
|
2341 | var context = _extends({}, _this2.props);
|
2342 |
|
2343 | if (typeof theme !== 'undefined') {
|
2344 | context.theme = determineTheme(_this2.props, theme, defaultProps);
|
2345 | }
|
2346 |
|
2347 | globalStyle.renderStyles(context, _this2.styleSheet);
|
2348 |
|
2349 | return null;
|
2350 | }
|
2351 | );
|
2352 | }
|
2353 | }
|
2354 | );
|
2355 | };
|
2356 |
|
2357 | return GlobalStyleComponent;
|
2358 | }(React__default.Component);
|
2359 |
|
2360 | GlobalStyleComponent.defaultProps = {
|
2361 | suppressMultiMountWarning: false
|
2362 | };
|
2363 | GlobalStyleComponent.globalStyle = style;
|
2364 | GlobalStyleComponent.styledComponentId = id;
|
2365 | process.env.NODE_ENV !== "production" ? GlobalStyleComponent.propTypes = {
|
2366 | suppressMultiMountWarning: PropTypes.bool
|
2367 | } : void 0;
|
2368 |
|
2369 |
|
2370 | return GlobalStyleComponent;
|
2371 | }
|
2372 |
|
2373 |
|
2374 |
|
2375 | var replaceWhitespace = function replaceWhitespace(str) {
|
2376 | return str.replace(/\s|\\n/g, '');
|
2377 | };
|
2378 |
|
2379 | function keyframes(strings) {
|
2380 |
|
2381 | if (process.env.NODE_ENV !== 'production' && typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
2382 | console.warn('`keyframes` cannot be used on ReactNative, only on the web. To do animation in ReactNative please use Animated.');
|
2383 | }
|
2384 |
|
2385 | for (var _len = arguments.length, interpolations = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
2386 | interpolations[_key - 1] = arguments[_key];
|
2387 | }
|
2388 |
|
2389 | var rules = css.apply(undefined, [strings].concat(interpolations));
|
2390 |
|
2391 | var name = generateAlphabeticName(murmurhash(replaceWhitespace(JSON.stringify(rules))));
|
2392 |
|
2393 | return new Keyframes(name, stringifyRules(rules, name, '@keyframes'));
|
2394 | }
|
2395 |
|
2396 |
|
2397 |
|
2398 | var withTheme = (function (Component) {
|
2399 | var WithTheme = React__default.forwardRef(function (props, ref) {
|
2400 | return React__default.createElement(
|
2401 | ThemeConsumer,
|
2402 | null,
|
2403 | function (theme) {
|
2404 |
|
2405 | var defaultProps = Component.defaultProps;
|
2406 |
|
2407 | var themeProp = determineTheme(props, theme, defaultProps);
|
2408 |
|
2409 | if (process.env.NODE_ENV !== 'production' && themeProp === undefined) {
|
2410 |
|
2411 | console.warn('[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class ' + getComponentName(Component));
|
2412 | }
|
2413 |
|
2414 | return React__default.createElement(Component, _extends({}, props, { theme: themeProp, ref: ref }));
|
2415 | }
|
2416 | );
|
2417 | });
|
2418 |
|
2419 | hoistNonReactStatics(WithTheme, Component);
|
2420 |
|
2421 | WithTheme.displayName = 'WithTheme(' + getComponentName(Component) + ')';
|
2422 |
|
2423 | return WithTheme;
|
2424 | });
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 | var __DO_NOT_USE_OR_YOU_WILL_BE_HAUNTED_BY_SPOOKY_GHOSTS = {
|
2430 | StyleSheet: StyleSheet
|
2431 | };
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 | if (process.env.NODE_ENV !== 'production' && typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
2437 |
|
2438 | console.warn("It looks like you've imported 'styled-components' on React Native.\n" + "Perhaps you're looking to import 'styled-components/native'?\n" + 'Read more about this at https://www.styled-components.com/docs/basics#react-native');
|
2439 | }
|
2440 |
|
2441 |
|
2442 | if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test' && typeof window !== 'undefined' && typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Node.js') === -1 && navigator.userAgent.indexOf('jsdom') === -1) {
|
2443 | window['__styled-components-init__'] = window['__styled-components-init__'] || 0;
|
2444 |
|
2445 | if (window['__styled-components-init__'] === 1) {
|
2446 |
|
2447 | console.warn("It looks like there are several instances of 'styled-components' initialized in this application. " + 'This may cause dynamic styles not rendering properly, errors happening during rehydration process ' + 'and makes your application bigger without a good reason.\n\n' + 'See https://s-c.sh/2BAXzed for more info.');
|
2448 | }
|
2449 |
|
2450 | window['__styled-components-init__'] += 1;
|
2451 | }
|
2452 |
|
2453 |
|
2454 |
|
2455 | exports.default = styled;
|
2456 | exports.css = css;
|
2457 | exports.keyframes = keyframes;
|
2458 | exports.createGlobalStyle = createGlobalStyle;
|
2459 | exports.isStyledComponent = isStyledComponent;
|
2460 | exports.ThemeConsumer = ThemeConsumer;
|
2461 | exports.ThemeProvider = ThemeProvider;
|
2462 | exports.withTheme = withTheme;
|
2463 | exports.ServerStyleSheet = ServerStyleSheet;
|
2464 | exports.StyleSheetManager = StyleSheetManager;
|
2465 | exports.__DO_NOT_USE_OR_YOU_WILL_BE_HAUNTED_BY_SPOOKY_GHOSTS = __DO_NOT_USE_OR_YOU_WILL_BE_HAUNTED_BY_SPOOKY_GHOSTS;
|
2466 |
|