styled-components 5.0.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,7 +59,7 @@ var interleave = (function (strings, interpolations) {
59
59
 
60
60
  //
61
61
  var isPlainObject = (function (x) {
62
- return typeof x === 'object' && x.constructor === Object;
62
+ return x !== null && typeof x === 'object' && (x.toString ? x.toString() : Object.prototype.toString.call(x)) === '[object Object]' && !reactIs.typeOf(x);
63
63
  });
64
64
 
65
65
  //
@@ -92,7 +92,8 @@ function isStyledComponent(target) {
92
92
  var SC_ATTR = typeof process !== 'undefined' && (process.env.REACT_APP_SC_ATTR || process.env.SC_ATTR) || 'data-styled';
93
93
  var SC_ATTR_ACTIVE = 'active';
94
94
  var SC_ATTR_VERSION = 'data-styled-version';
95
- var SC_VERSION = "5.0.0";
95
+ var SC_VERSION = "5.1.1";
96
+ var SPLITTER = '/*!sc*/\n';
96
97
  var IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
97
98
  var DISABLE_SPEEDY = typeof SC_DISABLE_SPEEDY === 'boolean' && SC_DISABLE_SPEEDY || typeof process !== 'undefined' && (process.env.REACT_APP_SC_DISABLE_SPEEDY || process.env.SC_DISABLE_SPEEDY) || process.env.NODE_ENV !== 'production'; // Shared empty execution context when generating static styles
98
99
 
@@ -105,6 +106,63 @@ var getNonce = function getNonce() {
105
106
  return typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;
106
107
  };
107
108
 
109
+ var errorMap = {
110
+ "1": "Cannot create styled-component for component: %s.\n\n",
111
+ "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",
112
+ "3": "Streaming SSR is only supported in a Node.js environment; Please do not try to call this method in the browser.\n\n",
113
+ "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",
114
+ "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",
115
+ "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",
116
+ "7": "ThemeProvider: Please return an object from your \"theme\" prop function, e.g.\n\n```js\ntheme={() => ({})}\n```\n\n",
117
+ "8": "ThemeProvider: Please make your \"theme\" prop an object.\n\n",
118
+ "9": "Missing document `<head>`\n\n",
119
+ "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",
120
+ "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",
121
+ "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 which ensures the styles are injected correctly. See https://www.styled-components.com/docs/api#css\n\n",
122
+ "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\n",
123
+ "14": "ThemeProvider: \"theme\" prop is required.\n\n",
124
+ "15": "A stylis plugin has been supplied that is not named. We need a name for each plugin to be able to prevent styling collisions between different stylis configurations within the same app. Before you pass your plugin to `<StyleSheetManager stylisPlugins={[]}>`, please make sure each plugin is uniquely-named, e.g.\n\n```js\nObject.defineProperty(importedPlugin, 'name', { value: 'some-unique-name' });\n```\n\n",
125
+ "16": "Reached the limit of how many styled components may be created at group %s.\nYou may only create up to 1,073,741,824 components. If you're creating components dynamically,\nas for instance in your render method then you may be running into this limitation.\n\n",
126
+ "17": "CSSStyleSheet could not be found on HTMLStyleElement.\nHas styled-components' style tag been unmounted or altered by another script?\n"
127
+ };
128
+
129
+ //
130
+ var ERRORS = process.env.NODE_ENV !== 'production' ? errorMap : {};
131
+ /**
132
+ * super basic version of sprintf
133
+ */
134
+
135
+ function format() {
136
+ var a = arguments.length <= 0 ? undefined : arguments[0];
137
+ var b = [];
138
+
139
+ for (var c = 1, len = arguments.length; c < len; c += 1) {
140
+ b.push(c < 0 || arguments.length <= c ? undefined : arguments[c]);
141
+ }
142
+
143
+ b.forEach(function (d) {
144
+ a = a.replace(/%[a-z]/, d);
145
+ });
146
+ return a;
147
+ }
148
+ /**
149
+ * Create an error file out of errors.md for development and a simple web link to the full errors
150
+ * in production mode.
151
+ */
152
+
153
+
154
+ function throwStyledComponentsError(code) {
155
+ for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
156
+ interpolations[_key - 1] = arguments[_key];
157
+ }
158
+
159
+ if (process.env.NODE_ENV === 'production') {
160
+ throw new Error("An error occurred. See https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/utils/errors.md#" + code + " for more information." + (interpolations.length > 0 ? " Additional arguments: " + interpolations.join(', ') : ''));
161
+ } else {
162
+ throw new Error(format.apply(void 0, [ERRORS[code]].concat(interpolations)).trim());
163
+ }
164
+ }
165
+
108
166
  //
109
167
  var ELEMENT_TYPE = 1;
110
168
  /* Node.ELEMENT_TYPE */
@@ -159,7 +217,8 @@ var getSheet = function getSheet(tag) {
159
217
  }
160
218
  }
161
219
 
162
- throw new TypeError("CSSStyleSheet could not be found on HTMLStyleElement");
220
+ throwStyledComponentsError(17);
221
+ return undefined;
163
222
  };
164
223
 
165
224
  //
@@ -178,9 +237,7 @@ var makeTag = function makeTag(_ref) {
178
237
  return new TextTag(target);
179
238
  }
180
239
  };
181
- var CSSOMTag =
182
- /*#__PURE__*/
183
- function () {
240
+ var CSSOMTag = /*#__PURE__*/function () {
184
241
  function CSSOMTag(target) {
185
242
  var element = this.element = makeStyleTag(target); // Avoid Edge bug where empty style elements don't create sheets
186
243
 
@@ -220,9 +277,7 @@ function () {
220
277
  }();
221
278
  /** A Tag that emulates the CSSStyleSheet API but uses text nodes */
222
279
 
223
- var TextTag =
224
- /*#__PURE__*/
225
- function () {
280
+ var TextTag = /*#__PURE__*/function () {
226
281
  function TextTag(target) {
227
282
  var element = this.element = makeStyleTag(target);
228
283
  this.nodes = element.childNodes;
@@ -260,9 +315,7 @@ function () {
260
315
  }();
261
316
  /** A completely virtual (server-side) Tag that doesn't manipulate the DOM */
262
317
 
263
- var VirtualTag =
264
- /*#__PURE__*/
265
- function () {
318
+ var VirtualTag = /*#__PURE__*/function () {
266
319
  function VirtualTag(_target) {
267
320
  this.rules = [];
268
321
  this.length = 0;
@@ -297,18 +350,14 @@ function () {
297
350
  }();
298
351
 
299
352
  //
300
-
301
- /* eslint-disable no-use-before-define */
302
-
303
353
  /** Create a GroupedTag with an underlying Tag implementation */
354
+
304
355
  var makeGroupedTag = function makeGroupedTag(tag) {
305
356
  return new DefaultGroupedTag(tag);
306
357
  };
307
- var BASE_SIZE = 1 << 8;
358
+ var BASE_SIZE = 1 << 9;
308
359
 
309
- var DefaultGroupedTag =
310
- /*#__PURE__*/
311
- function () {
360
+ var DefaultGroupedTag = /*#__PURE__*/function () {
312
361
  function DefaultGroupedTag(tag) {
313
362
  this.groupSizes = new Uint32Array(BASE_SIZE);
314
363
  this.length = BASE_SIZE;
@@ -331,7 +380,16 @@ function () {
331
380
  if (group >= this.groupSizes.length) {
332
381
  var oldBuffer = this.groupSizes;
333
382
  var oldSize = oldBuffer.length;
334
- var newSize = BASE_SIZE << (group / BASE_SIZE | 0);
383
+ var newSize = oldSize;
384
+
385
+ while (group >= newSize) {
386
+ newSize <<= 1;
387
+
388
+ if (newSize < 0) {
389
+ throwStyledComponentsError(16, "" + group);
390
+ }
391
+ }
392
+
335
393
  this.groupSizes = new Uint32Array(newSize);
336
394
  this.groupSizes.set(oldBuffer);
337
395
  this.length = newSize;
@@ -376,7 +434,7 @@ function () {
376
434
  var endIndex = startIndex + length;
377
435
 
378
436
  for (var i = startIndex; i < endIndex; i++) {
379
- css += this.tag.getRule(i) + "\n";
437
+ css += "" + this.tag.getRule(i) + SPLITTER;
380
438
  }
381
439
 
382
440
  return css;
@@ -386,6 +444,7 @@ function () {
386
444
  }();
387
445
 
388
446
  //
447
+ var MAX_SMI = 1 << 31 - 1;
389
448
  var groupIDRegister = new Map();
390
449
  var reverseRegister = new Map();
391
450
  var nextFreeGroup = 1;
@@ -395,6 +454,11 @@ var getGroupForId = function getGroupForId(id) {
395
454
  }
396
455
 
397
456
  var group = nextFreeGroup++;
457
+
458
+ if (process.env.NODE_ENV !== 'production' && ((group | 0) < 0 || group > MAX_SMI)) {
459
+ throwStyledComponentsError(16, "" + group);
460
+ }
461
+
398
462
  groupIDRegister.set(id, group);
399
463
  reverseRegister.set(group, id);
400
464
  return group;
@@ -413,8 +477,7 @@ var setGroupForId = function setGroupForId(id, group) {
413
477
 
414
478
  //
415
479
  var SELECTOR = "style[" + SC_ATTR + "][" + SC_ATTR_VERSION + "=\"" + SC_VERSION + "\"]";
416
- var RULE_RE = /(?:\s*)?(.*?){((?:{[^}]*}|(?!{).*?)*)}/g;
417
- var MARKER_RE = new RegExp("^" + SC_ATTR + "\\.g(\\d+)\\[id=\"([\\w\\d-]+)\"\\]");
480
+ var MARKER_RE = new RegExp("^" + SC_ATTR + "\\.g(\\d+)\\[id=\"([\\w\\d-]+)\"\\].*?\"([^\"]*)");
418
481
  var outputSheet = function outputSheet(sheet) {
419
482
  var tag = sheet.getTag();
420
483
  var length = tag.length;
@@ -439,7 +502,7 @@ var outputSheet = function outputSheet(sheet) {
439
502
  // after the actual rules to simplify the rehydration
440
503
 
441
504
 
442
- css += "" + rules + selector + "{content:\"" + content + "\"}\n";
505
+ css += "" + rules + selector + "{content:\"" + content + "\"}" + SPLITTER;
443
506
  }
444
507
 
445
508
  return css;
@@ -458,13 +521,13 @@ var rehydrateNamesFromContent = function rehydrateNamesFromContent(sheet, id, co
458
521
  };
459
522
 
460
523
  var rehydrateSheetFromTag = function rehydrateSheetFromTag(sheet, style) {
461
- var rawHTML = style.innerHTML;
524
+ var parts = style.innerHTML.split(SPLITTER);
462
525
  var rules = [];
463
- var parts; // parts = [match, selector, content]
464
- // eslint-disable-next-line no-cond-assign
465
526
 
466
- while (parts = RULE_RE.exec(rawHTML)) {
467
- var marker = parts[1].match(MARKER_RE);
527
+ for (var i = 0, l = parts.length; i < l; i++) {
528
+ var part = parts[i].trim();
529
+ if (!part) continue;
530
+ var marker = part.match(MARKER_RE);
468
531
 
469
532
  if (marker) {
470
533
  var group = parseInt(marker[1], 10) | 0;
@@ -475,13 +538,13 @@ var rehydrateSheetFromTag = function rehydrateSheetFromTag(sheet, style) {
475
538
  setGroupForId(id, group); // Rehydrate names and rules
476
539
  // looks like: data-styled.g11[id="idA"]{content:"nameA,"}
477
540
 
478
- rehydrateNamesFromContent(sheet, id, parts[2].split('"')[1]);
541
+ rehydrateNamesFromContent(sheet, id, marker[3]);
479
542
  sheet.getTag().insertRules(group, rules);
480
543
  }
481
544
 
482
545
  rules.length = 0;
483
546
  } else {
484
- rules.push(parts[0].trim());
547
+ rules.push(part);
485
548
  }
486
549
  }
487
550
  };
@@ -509,9 +572,7 @@ var defaultOptions = {
509
572
  };
510
573
  /** Contains the main stylesheet logic for stringification and caching */
511
574
 
512
- var StyleSheet =
513
- /*#__PURE__*/
514
- function () {
575
+ var StyleSheet = /*#__PURE__*/function () {
515
576
  /** Register a group ID to give it an index */
516
577
  StyleSheet.registerId = function registerId(id) {
517
578
  return getGroupForId(id);
@@ -526,7 +587,7 @@ function () {
526
587
  globalStyles = {};
527
588
  }
528
589
 
529
- this.options = _extends({}, defaultOptions, options);
590
+ this.options = _extends({}, defaultOptions, {}, options);
530
591
  this.gs = globalStyles;
531
592
  this.names = new Map(names); // We rehydrate only once and use the sheet that is created first
532
593
 
@@ -539,7 +600,7 @@ function () {
539
600
  var _proto = StyleSheet.prototype;
540
601
 
541
602
  _proto.reconstructWithOptions = function reconstructWithOptions(options) {
542
- return new StyleSheet(_extends({}, this.options, options), this.gs, this.names);
603
+ return new StyleSheet(_extends({}, this.options, {}, options), this.gs, this.names);
543
604
  };
544
605
 
545
606
  _proto.allocateGSInstance = function allocateGSInstance(id) {
@@ -611,82 +672,25 @@ function () {
611
672
  return StyleSheet;
612
673
  }();
613
674
 
614
- //
615
-
616
- var errorMap = {
617
- "1": "Cannot create styled-component for component: %s.\n\n",
618
- "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",
619
- "3": "Streaming SSR is only supported in a Node.js environment; Please do not try to call this method in the browser.\n\n",
620
- "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",
621
- "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",
622
- "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",
623
- "7": "ThemeProvider: Please return an object from your \"theme\" prop function, e.g.\n\n```js\ntheme={() => ({})}\n```\n\n",
624
- "8": "ThemeProvider: Please make your \"theme\" prop an object.\n\n",
625
- "9": "Missing document `<head>`\n\n",
626
- "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",
627
- "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",
628
- "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 which ensures the styles are injected correctly. See https://www.styled-components.com/docs/api#css\n\n",
629
- "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\n",
630
- "14": "ThemeProvider: \"theme\" prop is required.\n\n",
631
- "15": "A stylis plugin has been supplied that is not named. We need a name for each plugin to be able to prevent styling collisions between different stylis configurations within the same app. Before you pass your plugin to `<StyleSheetManager stylisPlugins={[]}>`, please make sure each plugin is uniquely-named, e.g.\n\n```js\nObject.defineProperty(importedPlugin, 'name', { value: 'some-unique-name' });\n```\n"
632
- };
633
-
634
- //
635
- var ERRORS = process.env.NODE_ENV !== 'production' ? errorMap : {};
636
- /**
637
- * super basic version of sprintf
638
- */
639
-
640
- function format() {
641
- var a = arguments.length <= 0 ? undefined : arguments[0];
642
- var b = [];
643
-
644
- for (var c = 1, len = arguments.length; c < len; c += 1) {
645
- b.push(c < 0 || arguments.length <= c ? undefined : arguments[c]);
646
- }
647
-
648
- b.forEach(function (d) {
649
- a = a.replace(/%[a-z]/, d);
650
- });
651
- return a;
652
- }
653
- /**
654
- * Create an error file out of errors.md for development and a simple web link to the full errors
655
- * in production mode.
656
- */
657
-
658
-
659
- function throwStyledComponentsError(code) {
660
- for (var _len = arguments.length, interpolations = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
661
- interpolations[_key - 1] = arguments[_key];
662
- }
663
-
664
- if (process.env.NODE_ENV === 'production') {
665
- throw new Error("An error occurred. See https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/utils/errors.md#" + code + " for more information." + (interpolations.length > 0 ? " Additional arguments: " + interpolations.join(', ') : ''));
666
- } else {
667
- throw new Error(format.apply(void 0, [ERRORS[code]].concat(interpolations)).trim());
668
- }
669
- }
670
-
671
675
  //
672
676
 
673
677
  /* eslint-disable */
674
- var SEED = 5381 | 0; // When we have separate strings it's useful to run a progressive
678
+ var SEED = 5381; // When we have separate strings it's useful to run a progressive
675
679
  // version of djb2 where we pretend that we're still looping over
676
680
  // the same string
677
681
 
678
682
  var phash = function phash(h, x) {
679
- h |= 0;
683
+ var i = x.length;
680
684
 
681
- for (var i = 0, l = x.length | 0; i < l; i++) {
682
- h = (h << 5) + h + x.charCodeAt(i);
685
+ while (i) {
686
+ h = h * 33 ^ x.charCodeAt(--i);
683
687
  }
684
688
 
685
689
  return h;
686
690
  }; // This is a djb2 hashing function
687
691
 
688
692
  var hash = function hash(x) {
689
- return phash(SEED, x) >>> 0;
693
+ return phash(SEED, x);
690
694
  };
691
695
 
692
696
  /**
@@ -709,6 +713,8 @@ var hash = function hash(x) {
709
713
  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
710
714
  * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
711
715
  */
716
+
717
+ /* eslint-disable */
712
718
  function insertRulePlugin (insertRule) {
713
719
  var delimiter = '/*|*/';
714
720
  var needle = delimiter + "}";
@@ -834,13 +840,13 @@ function createStylisInstance(_temp) {
834
840
  return stylis(prefix || !selector ? '' : selector, cssStr);
835
841
  }
836
842
 
837
- stringifyRules.hash = plugins.reduce(function (acc, plugin) {
843
+ stringifyRules.hash = plugins.length ? plugins.reduce(function (acc, plugin) {
838
844
  if (!plugin.name) {
839
845
  throwStyledComponentsError(15);
840
846
  }
841
847
 
842
848
  return phash(acc, plugin.name);
843
- }, SEED).toString();
849
+ }, SEED).toString() : '';
844
850
  return stringifyRules;
845
851
  }
846
852
 
@@ -894,18 +900,16 @@ function StyleSheetManager(props) {
894
900
  React.useEffect(function () {
895
901
  if (!shallowequal(plugins, props.stylisPlugins)) setPlugins(props.stylisPlugins);
896
902
  }, [props.stylisPlugins]);
897
- return React__default.createElement(StyleSheetContext.Provider, {
903
+ return /*#__PURE__*/React__default.createElement(StyleSheetContext.Provider, {
898
904
  value: styleSheet
899
- }, React__default.createElement(StylisContext.Provider, {
905
+ }, /*#__PURE__*/React__default.createElement(StylisContext.Provider, {
900
906
  value: stylis
901
907
  }, process.env.NODE_ENV !== 'production' ? React__default.Children.only(props.children) : props.children));
902
908
  }
903
909
 
904
910
  //
905
911
 
906
- var Keyframes =
907
- /*#__PURE__*/
908
- function () {
912
+ var Keyframes = /*#__PURE__*/function () {
909
913
  function Keyframes(name, stringifyArgs) {
910
914
  var _this = this;
911
915
 
@@ -1095,7 +1099,7 @@ function constructWithOptions(componentConstructor, tag, options) {
1095
1099
 
1096
1100
 
1097
1101
  templateFunction.withConfig = function (config) {
1098
- return constructWithOptions(componentConstructor, tag, _extends({}, options, config));
1102
+ return constructWithOptions(componentConstructor, tag, _extends({}, options, {}, config));
1099
1103
  };
1100
1104
  /* Modify/inject new props at runtime */
1101
1105
 
@@ -1224,9 +1228,7 @@ function isStaticRules(rules) {
1224
1228
  the React-specific stuff.
1225
1229
  */
1226
1230
 
1227
- var ComponentStyle =
1228
- /*#__PURE__*/
1229
- function () {
1231
+ var ComponentStyle = /*#__PURE__*/function () {
1230
1232
  function ComponentStyle(rules, componentId) {
1231
1233
  this.rules = rules;
1232
1234
  this.staticRulesId = '';
@@ -1319,6 +1321,36 @@ var createWarnTooManyClasses = (function (displayName, componentId) {
1319
1321
  };
1320
1322
  });
1321
1323
 
1324
+ //
1325
+ var invalidHookCallRe = /invalid hook call/i;
1326
+ var seen = new Set();
1327
+ var checkDynamicCreation = function checkDynamicCreation(displayName, componentId) {
1328
+ if (process.env.NODE_ENV !== 'production') {
1329
+ var parsedIdString = componentId ? " with the id of \"" + componentId + "\"" : '';
1330
+ var message = "The component " + displayName + parsedIdString + " has been created dynamically.\n" + 'You may see this warning because you\'ve called styled inside another component.\n' + 'To resolve this only create new StyledComponents outside of any render method and function component.';
1331
+
1332
+ try {
1333
+ // We purposefully call `useRef` outside of a component and expect it to throw
1334
+ // If it doesn't, then we're inside another component.
1335
+ // eslint-disable-next-line react-hooks/rules-of-hooks
1336
+ React.useRef();
1337
+
1338
+ if (!seen.has(message)) {
1339
+ // eslint-disable-next-line no-console
1340
+ console.warn(message);
1341
+ seen.add(message);
1342
+ }
1343
+ } catch (error) {
1344
+ // The error here is expected, since we're expecting anything that uses `checkDynamicCreation` to
1345
+ // be called outside of a React component.
1346
+ if (invalidHookCallRe.test(error.message)) {
1347
+ // This shouldn't happen, but resets `warningSeen` if we had this error happen intermittently
1348
+ seen["delete"](message);
1349
+ }
1350
+ }
1351
+ }
1352
+ };
1353
+
1322
1354
  //
1323
1355
  var determineTheme = (function (props, providedTheme, defaultProps) {
1324
1356
  if (defaultProps === void 0) {
@@ -1329,7 +1361,9 @@ var determineTheme = (function (props, providedTheme, defaultProps) {
1329
1361
  });
1330
1362
 
1331
1363
  //
1332
- var escapeRegex = /[[\].#*$><+~=|^:(),"'`-]+/g;
1364
+ // Source: https://www.w3.org/TR/cssom-1/#serialize-an-identifier
1365
+ // Control characters and non-letter first symbols are not supported
1366
+ var escapeRegex = /[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~-]+/g;
1333
1367
  var dashesAtEnds = /(^-|-$)/g;
1334
1368
  /**
1335
1369
  * TODO: Explore using CSS.escape when it becomes more available
@@ -1355,7 +1389,7 @@ function generateDisplayName(target) {
1355
1389
 
1356
1390
  //
1357
1391
  var generateComponentId = (function (str) {
1358
- return generateAlphabeticName(hash(str));
1392
+ return generateAlphabeticName(hash(str) >>> 0);
1359
1393
  });
1360
1394
 
1361
1395
  /**
@@ -1387,7 +1421,7 @@ function mergeTheme(theme, outerTheme) {
1387
1421
  return throwStyledComponentsError(8);
1388
1422
  }
1389
1423
 
1390
- return outerTheme ? _extends({}, outerTheme, theme) : theme;
1424
+ return outerTheme ? _extends({}, outerTheme, {}, theme) : theme;
1391
1425
  }
1392
1426
  /**
1393
1427
  * Provide a theme to an entire react component tree via context
@@ -1404,7 +1438,7 @@ function ThemeProvider(props) {
1404
1438
  return null;
1405
1439
  }
1406
1440
 
1407
- return React__default.createElement(ThemeContext.Provider, {
1441
+ return /*#__PURE__*/React__default.createElement(ThemeContext.Provider, {
1408
1442
  value: themeContext
1409
1443
  }, props.children);
1410
1444
  }
@@ -1475,6 +1509,7 @@ function useStyledComponentImpl(forwardedComponent, props, forwardedRef) {
1475
1509
  componentStyle = forwardedComponent.componentStyle,
1476
1510
  defaultProps = forwardedComponent.defaultProps,
1477
1511
  foldedComponentIds = forwardedComponent.foldedComponentIds,
1512
+ shouldForwardProp = forwardedComponent.shouldForwardProp,
1478
1513
  styledComponentId = forwardedComponent.styledComponentId,
1479
1514
  target = forwardedComponent.target;
1480
1515
  React.useDebugValue(styledComponentId); // NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,
@@ -1489,26 +1524,23 @@ function useStyledComponentImpl(forwardedComponent, props, forwardedRef) {
1489
1524
 
1490
1525
  var generatedClassName = useInjectedStyle(componentStyle, componentAttrs.length > 0, context, process.env.NODE_ENV !== 'production' ? forwardedComponent.warnTooManyClasses : undefined);
1491
1526
  var refToForward = forwardedRef;
1492
- var elementToBeCreated = attrs.as || props.as || target;
1527
+ var elementToBeCreated = attrs.$as || props.$as || attrs.as || props.as || target;
1493
1528
  var isTargetTag = isTag(elementToBeCreated);
1494
- var computedProps = attrs !== props ? _extends({}, props, attrs) : props;
1495
- var shouldFilterProps = isTargetTag || 'as' in computedProps || 'forwardedAs' in computedProps;
1496
- var propsForElement = shouldFilterProps ? {} : _extends({}, computedProps);
1497
-
1498
- if (shouldFilterProps) {
1499
- // eslint-disable-next-line guard-for-in
1500
- for (var key in computedProps) {
1501
- if (key === 'forwardedAs') {
1502
- propsForElement.as = computedProps[key];
1503
- } else if (key !== 'as' && key !== 'forwardedAs' && (!isTargetTag || validAttr(key))) {
1504
- // Don't pass through non HTML tags through to HTML elements
1505
- propsForElement[key] = computedProps[key];
1506
- }
1529
+ var computedProps = attrs !== props ? _extends({}, props, {}, attrs) : props;
1530
+ var propFilterFn = shouldForwardProp || isTargetTag && validAttr;
1531
+ var propsForElement = {}; // eslint-disable-next-line guard-for-in
1532
+
1533
+ for (var key in computedProps) {
1534
+ if (key[0] === '$' || key === 'as') continue;else if (key === 'forwardedAs') {
1535
+ propsForElement.as = computedProps[key];
1536
+ } else if (!propFilterFn || propFilterFn(key, validAttr)) {
1537
+ // Don't pass through non HTML tags through to HTML elements
1538
+ propsForElement[key] = computedProps[key];
1507
1539
  }
1508
1540
  }
1509
1541
 
1510
1542
  if (props.style && attrs.style !== props.style) {
1511
- propsForElement.style = _extends({}, props.style, attrs.style);
1543
+ propsForElement.style = _extends({}, props.style, {}, attrs.style);
1512
1544
  }
1513
1545
 
1514
1546
  propsForElement.className = Array.prototype.concat(foldedComponentIds, styledComponentId, generatedClassName !== styledComponentId ? generatedClassName : null, props.className, attrs.className).filter(Boolean).join(' ');
@@ -1528,7 +1560,24 @@ function createStyledComponent(target, options, rules) {
1528
1560
  var styledComponentId = options.displayName && options.componentId ? escape(options.displayName) + "-" + options.componentId : options.componentId || componentId; // fold the underlying StyledComponent attrs up (implicit extend)
1529
1561
 
1530
1562
  var finalAttrs = // $FlowFixMe
1531
- isTargetStyledComp && target.attrs ? Array.prototype.concat(target.attrs, attrs).filter(Boolean) : attrs;
1563
+ isTargetStyledComp && target.attrs ? Array.prototype.concat(target.attrs, attrs).filter(Boolean) : attrs; // eslint-disable-next-line prefer-destructuring
1564
+
1565
+ var shouldForwardProp = options.shouldForwardProp; // $FlowFixMe
1566
+
1567
+ if (isTargetStyledComp && target.shouldForwardProp) {
1568
+ if (shouldForwardProp) {
1569
+ // compose nested shouldForwardProp calls
1570
+ shouldForwardProp = function shouldForwardProp(prop, filterFn) {
1571
+ return (// $FlowFixMe
1572
+ target.shouldForwardProp(prop, filterFn) && options.shouldForwardProp(prop, filterFn)
1573
+ );
1574
+ };
1575
+ } else {
1576
+ // eslint-disable-next-line prefer-destructuring
1577
+ shouldForwardProp = target.shouldForwardProp;
1578
+ }
1579
+ }
1580
+
1532
1581
  var componentStyle = new ComponentStyle(isTargetStyledComp ? // fold the underlying StyledComponent rules up (implicit extend)
1533
1582
  // $FlowFixMe
1534
1583
  target.componentStyle.rules.concat(rules) : rules, styledComponentId);
@@ -1548,7 +1597,8 @@ function createStyledComponent(target, options, rules) {
1548
1597
  WrappedStyledComponent = React__default.forwardRef(forwardRef);
1549
1598
  WrappedStyledComponent.attrs = finalAttrs;
1550
1599
  WrappedStyledComponent.componentStyle = componentStyle;
1551
- WrappedStyledComponent.displayName = displayName; // this static is used to preserve the cascade of static classes for component selector
1600
+ WrappedStyledComponent.displayName = displayName;
1601
+ WrappedStyledComponent.shouldForwardProp = shouldForwardProp; // this static is used to preserve the cascade of static classes for component selector
1552
1602
  // purposes; this is especially important with usage of the css prop
1553
1603
 
1554
1604
  WrappedStyledComponent.foldedComponentIds = isTargetStyledComp ? // $FlowFixMe
@@ -1584,6 +1634,7 @@ function createStyledComponent(target, options, rules) {
1584
1634
  });
1585
1635
 
1586
1636
  if (process.env.NODE_ENV !== 'production') {
1637
+ checkDynamicCreation(displayName, styledComponentId);
1587
1638
  WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName, styledComponentId);
1588
1639
  } // $FlowFixMe
1589
1640
 
@@ -1599,6 +1650,7 @@ function createStyledComponent(target, options, rules) {
1599
1650
  componentStyle: true,
1600
1651
  displayName: true,
1601
1652
  foldedComponentIds: true,
1653
+ shouldForwardProp: true,
1602
1654
  self: true,
1603
1655
  styledComponentId: true,
1604
1656
  target: true,
@@ -1627,9 +1679,7 @@ domElements.forEach(function (domElement) {
1627
1679
 
1628
1680
  //
1629
1681
 
1630
- var GlobalStyle =
1631
- /*#__PURE__*/
1632
- function () {
1682
+ var GlobalStyle = /*#__PURE__*/function () {
1633
1683
  function GlobalStyle(rules, componentId) {
1634
1684
  this.rules = rules;
1635
1685
  this.componentId = componentId;
@@ -1669,6 +1719,10 @@ function createGlobalStyle(strings) {
1669
1719
  var styledComponentId = "sc-global-" + generateComponentId(JSON.stringify(rules));
1670
1720
  var globalStyle = new GlobalStyle(rules, styledComponentId);
1671
1721
 
1722
+ if (process.env.NODE_ENV !== 'production') {
1723
+ checkDynamicCreation(styledComponentId);
1724
+ }
1725
+
1672
1726
  function GlobalStyleComponent(props) {
1673
1727
  var styleSheet = useStyleSheet();
1674
1728
  var stylis = useStylis();
@@ -1686,6 +1740,12 @@ function createGlobalStyle(strings) {
1686
1740
  console.warn("The global style component " + styledComponentId + " was given child JSX. createGlobalStyle does not render children.");
1687
1741
  }
1688
1742
 
1743
+ if (process.env.NODE_ENV !== 'production' && rules.some(function (rule) {
1744
+ return typeof rule === 'string' && rule.indexOf('@import') !== -1;
1745
+ })) {
1746
+ console.warn("Please do not use @import CSS syntax in createGlobalStyle at this time, as the CSSOM APIs we use in production do not handle it well. Instead, we recommend using a library such as react-helmet to inject a typical <link> meta tag to the stylesheet, or simply embedding it manually in your index.html <head> section for a simpler app.");
1747
+ }
1748
+
1689
1749
  if (globalStyle.isStatic) {
1690
1750
  globalStyle.renderStyles(instance, STATIC_EXECUTION_CONTEXT, styleSheet, stylis);
1691
1751
  } else {
@@ -1725,9 +1785,7 @@ function keyframes(strings) {
1725
1785
  return new Keyframes(name, [rules, name, '@keyframes']);
1726
1786
  }
1727
1787
 
1728
- var ServerStyleSheet =
1729
- /*#__PURE__*/
1730
- function () {
1788
+ var ServerStyleSheet = /*#__PURE__*/function () {
1731
1789
  function ServerStyleSheet() {
1732
1790
  var _this = this;
1733
1791
 
@@ -1735,7 +1793,7 @@ function () {
1735
1793
  var css = _this.instance.toString();
1736
1794
 
1737
1795
  var nonce = getNonce();
1738
- var attrs = [nonce && "nonce=\"" + nonce + "\"", SC_ATTR, SC_ATTR_VERSION + "=\"" + SC_VERSION + "\""];
1796
+ var attrs = [nonce && "nonce=\"" + nonce + "\"", SC_ATTR + "=\"true\"", SC_ATTR_VERSION + "=\"" + SC_VERSION + "\""];
1739
1797
  var htmlAttr = attrs.filter(Boolean).join(' ');
1740
1798
  return "<style " + htmlAttr + ">" + css + "</style>";
1741
1799
  };
@@ -1765,7 +1823,7 @@ function () {
1765
1823
  } // v4 returned an array for this fn, so we'll do the same for v5 for backward compat
1766
1824
 
1767
1825
 
1768
- return [React__default.createElement("style", _extends({}, props, {
1826
+ return [/*#__PURE__*/React__default.createElement("style", _extends({}, props, {
1769
1827
  key: "sc-0-0"
1770
1828
  }))];
1771
1829
  };
@@ -1787,7 +1845,7 @@ function () {
1787
1845
  return throwStyledComponentsError(2);
1788
1846
  }
1789
1847
 
1790
- return React__default.createElement(StyleSheetManager, {
1848
+ return /*#__PURE__*/React__default.createElement(StyleSheetManager, {
1791
1849
  sheet: this.instance
1792
1850
  }, children);
1793
1851
  };
@@ -1821,7 +1879,7 @@ var withTheme = (function (Component) {
1821
1879
  console.warn("[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class \"" + getComponentName(Component) + "\"");
1822
1880
  }
1823
1881
 
1824
- return React__default.createElement(Component, _extends({}, props, {
1882
+ return /*#__PURE__*/React__default.createElement(Component, _extends({}, props, {
1825
1883
  theme: themeProp,
1826
1884
  ref: ref
1827
1885
  }));
@@ -1846,7 +1904,7 @@ var __PRIVATE__ = {
1846
1904
  //
1847
1905
  /* Define bundle version for export */
1848
1906
 
1849
- var version = "5.0.0";
1907
+ var version = "5.1.1";
1850
1908
  /* Warning if you've imported this file on React Native */
1851
1909
 
1852
1910
  if (process.env.NODE_ENV !== 'production' && typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
@@ -1856,7 +1914,7 @@ if (process.env.NODE_ENV !== 'production' && typeof navigator !== 'undefined' &&
1856
1914
  /* Warning if there are several instances of styled-components */
1857
1915
 
1858
1916
 
1859
- if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
1917
+ if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test' && typeof window !== 'undefined') {
1860
1918
  window['__styled-components-init__'] = window['__styled-components-init__'] || 0;
1861
1919
 
1862
1920
  if (window['__styled-components-init__'] === 1) {
@@ -1867,8 +1925,6 @@ if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
1867
1925
  window['__styled-components-init__'] += 1;
1868
1926
  }
1869
1927
 
1870
- //
1871
-
1872
1928
  exports.ServerStyleSheet = ServerStyleSheet;
1873
1929
  exports.StyleSheetConsumer = StyleSheetConsumer;
1874
1930
  exports.StyleSheetContext = StyleSheetContext;