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