styled-components 6.0.0-beta.12 → 6.0.0-beta.14

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.
Files changed (47) hide show
  1. package/dist/base.d.ts +1 -7
  2. package/dist/models/ComponentStyle.d.ts +0 -1
  3. package/dist/models/StyleSheetManager.d.ts +6 -7
  4. package/dist/models/ThemeProvider.d.ts +1 -0
  5. package/dist/native/index.d.ts +1 -2
  6. package/dist/sheet/GroupedTag.d.ts +1 -1
  7. package/dist/styled-components.browser.cjs.js +1 -1859
  8. package/dist/styled-components.browser.cjs.js.map +1 -1
  9. package/dist/styled-components.browser.esm.js +1 -1833
  10. package/dist/styled-components.browser.esm.js.map +1 -1
  11. package/dist/styled-components.cjs.js +1 -1880
  12. package/dist/styled-components.cjs.js.map +1 -1
  13. package/dist/styled-components.esm.js +1 -1854
  14. package/dist/styled-components.esm.js.map +1 -1
  15. package/dist/styled-components.js +199 -196
  16. package/dist/styled-components.js.map +1 -1
  17. package/dist/styled-components.min.js +1 -1
  18. package/dist/styled-components.min.js.map +1 -1
  19. package/dist/tsconfig.tsbuildinfo +1 -1
  20. package/dist/types.d.ts +1 -1
  21. package/dist/utils/determineTheme.d.ts +4 -2
  22. package/dist/utils/domElements.d.ts +1 -1
  23. package/dist/utils/flatten.d.ts +1 -1
  24. package/dist/utils/isFunction.d.ts +1 -1
  25. package/dist/utils/isPlainObject.d.ts +1 -1
  26. package/dist/utils/isStatelessFunction.d.ts +1 -1
  27. package/dist/utils/joinStrings.d.ts +2 -1
  28. package/native/dist/base.d.ts +1 -7
  29. package/native/dist/models/ComponentStyle.d.ts +0 -1
  30. package/native/dist/models/StyleSheetManager.d.ts +6 -7
  31. package/native/dist/models/ThemeProvider.d.ts +1 -0
  32. package/native/dist/native/index.d.ts +1 -2
  33. package/native/dist/sheet/GroupedTag.d.ts +1 -1
  34. package/native/dist/styled-components.native.cjs.js +1 -1324
  35. package/native/dist/styled-components.native.cjs.js.map +1 -1
  36. package/native/dist/styled-components.native.esm.js +1 -1306
  37. package/native/dist/styled-components.native.esm.js.map +1 -1
  38. package/native/dist/types.d.ts +1 -1
  39. package/native/dist/utils/determineTheme.d.ts +4 -2
  40. package/native/dist/utils/domElements.d.ts +1 -1
  41. package/native/dist/utils/flatten.d.ts +1 -1
  42. package/native/dist/utils/isFunction.d.ts +1 -1
  43. package/native/dist/utils/isPlainObject.d.ts +1 -1
  44. package/native/dist/utils/isStatelessFunction.d.ts +1 -1
  45. package/native/dist/utils/joinStrings.d.ts +2 -1
  46. package/package.json +1 -12
  47. package/dist/hooks/useTheme.d.ts +0 -3
@@ -8,7 +8,7 @@
8
8
  'data-styled';
9
9
  var SC_ATTR_ACTIVE = 'active';
10
10
  var SC_ATTR_VERSION = 'data-styled-version';
11
- var SC_VERSION = "6.0.0-beta.12";
11
+ var SC_VERSION = "6.0.0-beta.14";
12
12
  var SPLITTER = '/*!sc*/\n';
13
13
  var IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
14
14
  var DISABLE_SPEEDY = Boolean(typeof SC_DISABLE_SPEEDY === 'boolean'
@@ -160,17 +160,10 @@
160
160
  }
161
161
  }
162
162
  var ruleIndex = this.indexOfGroup(group + 1);
163
- if (Array.isArray(rules)) {
164
- for (var i = 0, l = rules.length; i < l; i++) {
165
- if (this.tag.insertRule(ruleIndex, rules[i])) {
166
- this.groupSizes[group]++;
167
- ruleIndex++;
168
- }
169
- }
170
- }
171
- else {
172
- if (this.tag.insertRule(ruleIndex, rules)) {
163
+ for (var i = 0, l = rules.length; i < l; i++) {
164
+ if (this.tag.insertRule(ruleIndex, rules[i])) {
173
165
  this.groupSizes[group]++;
166
+ ruleIndex++;
174
167
  }
175
168
  }
176
169
  };
@@ -372,10 +365,10 @@
372
365
  };
373
366
  var CSSOMTag = /** @class */ (function () {
374
367
  function CSSOMTag(target) {
375
- var element = (this.element = makeStyleTag(target));
368
+ this.element = makeStyleTag(target);
376
369
  // Avoid Edge bug where empty style elements don't create sheets
377
- element.appendChild(document.createTextNode(''));
378
- this.sheet = getSheet(element);
370
+ this.element.appendChild(document.createTextNode(''));
371
+ this.sheet = getSheet(this.element);
379
372
  this.length = 0;
380
373
  }
381
374
  CSSOMTag.prototype.insertRule = function (index, rule) {
@@ -395,7 +388,7 @@
395
388
  CSSOMTag.prototype.getRule = function (index) {
396
389
  var rule = this.sheet.cssRules[index];
397
390
  // Avoid IE11 quirk where cssText is inaccessible on some invalid rules
398
- if (rule !== undefined && typeof rule.cssText === 'string') {
391
+ if (rule && rule.cssText) {
399
392
  return rule.cssText;
400
393
  }
401
394
  else {
@@ -407,8 +400,8 @@
407
400
  /** A Tag that emulates the CSSStyleSheet API but uses text nodes */
408
401
  var TextTag = /** @class */ (function () {
409
402
  function TextTag(target) {
410
- var element = (this.element = makeStyleTag(target));
411
- this.nodes = element.childNodes;
403
+ this.element = makeStyleTag(target);
404
+ this.nodes = this.element.childNodes;
412
405
  this.length = 0;
413
406
  }
414
407
  TextTag.prototype.insertRule = function (index, rule) {
@@ -620,7 +613,13 @@
620
613
  * separated when using CSSOM injection.
621
614
  */
622
615
  function serialize(children, callback) {
623
- return children.map(function (c, i) { return callback(c, i, children, callback); }).filter(Boolean);
616
+ var ret = [];
617
+ for (var i = 0, result = void 0; i < children.length; i += 1) {
618
+ result = callback(children[i], i, children, callback);
619
+ if (result)
620
+ ret.push(result);
621
+ }
622
+ return ret;
624
623
  }
625
624
  /**
626
625
  * Takes an element and recurses through it's rules added the namespace to the start of each selector.
@@ -673,10 +672,17 @@
673
672
  */
674
673
  var selfReferenceReplacementPlugin = function (element) {
675
674
  if (element.type === c && element.value.includes('&')) {
676
- var props = element.props;
677
- props[0] = props[0].replace(_selectorRegexp, selfReferenceReplacer);
675
+ element.props[0] = element.props[0].replace(_selectorRegexp, selfReferenceReplacer);
678
676
  }
679
677
  };
678
+ var middlewares = plugins.slice();
679
+ /**
680
+ * Enables automatic vendor-prefixing for styles.
681
+ */
682
+ if (options.prefix) {
683
+ middlewares.unshift(pe);
684
+ }
685
+ middlewares.push(selfReferenceReplacementPlugin, oe);
680
686
  var stringifyRules = function (css, selector,
681
687
  /**
682
688
  * This "prefix" referes to a _selector_ prefix.
@@ -685,7 +691,6 @@
685
691
  if (selector === void 0) { selector = ''; }
686
692
  if (prefix === void 0) { prefix = ''; }
687
693
  if (componentId === void 0) { componentId = '&'; }
688
- var flatCSS = css.replace(COMMENT_REGEX, '');
689
694
  // stylis has no concept of state to be passed to plugins
690
695
  // but since JS is single-threaded, we can rely on that to ensure
691
696
  // these properties stay in sync with the current stylis run
@@ -693,14 +698,7 @@
693
698
  _selector = selector;
694
699
  _selectorRegexp = new RegExp("\\".concat(_selector, "\\b"), 'g');
695
700
  _consecutiveSelfRefRegExp = new RegExp("(\\".concat(_selector, "\\b){2,}"));
696
- var middlewares = plugins.slice();
697
- /**
698
- * Enables automatic vendor-prefixing for styles.
699
- */
700
- if (options.prefix || options.prefix === undefined) {
701
- middlewares.unshift(pe);
702
- }
703
- middlewares.push(selfReferenceReplacementPlugin, oe);
701
+ var flatCSS = css.replace(COMMENT_REGEX, '');
704
702
  var compiled = ne(prefix || selector ? "".concat(prefix, " ").concat(selector, " { ").concat(flatCSS, " }") : flatCSS);
705
703
  if (options.namespace) {
706
704
  compiled = recursivelySetNamepace(compiled, options.namespace);
@@ -720,28 +718,23 @@
720
718
  return stringifyRules;
721
719
  }
722
720
 
721
+ var mainSheet = new StyleSheet();
722
+ var mainStylis = createStylisInstance();
723
723
  var StyleSheetContext = React.createContext({
724
724
  shouldForwardProp: undefined,
725
- styleSheet: undefined,
725
+ styleSheet: mainSheet,
726
+ stylis: mainStylis,
726
727
  });
727
728
  var StyleSheetConsumer = StyleSheetContext.Consumer;
728
729
  var StylisContext = React.createContext(undefined);
729
- var mainSheet = new StyleSheet();
730
- var mainStylis = createStylisInstance();
731
- function useShouldForwardProp() {
732
- return React.useContext(StyleSheetContext).shouldForwardProp;
733
- }
734
- function useStyleSheet() {
735
- return React.useContext(StyleSheetContext).styleSheet || mainSheet;
736
- }
737
- function useStylis() {
738
- return React.useContext(StylisContext) || mainStylis;
730
+ function useStyleSheetContext() {
731
+ return React.useContext(StyleSheetContext);
739
732
  }
740
733
  function StyleSheetManager(props) {
741
734
  var _a = React.useState(props.stylisPlugins), plugins = _a[0], setPlugins = _a[1];
742
- var contextStyleSheet = useStyleSheet();
743
- var styleSheet = React.useMemo(function () {
744
- var sheet = contextStyleSheet;
735
+ var styleSheet = useStyleSheetContext().styleSheet;
736
+ var resolvedStyleSheet = React.useMemo(function () {
737
+ var sheet = styleSheet;
745
738
  if (props.sheet) {
746
739
  sheet = props.sheet;
747
740
  }
@@ -752,20 +745,19 @@
752
745
  sheet = sheet.reconstructWithOptions({ useCSSOMInjection: false });
753
746
  }
754
747
  return sheet;
755
- }, [props.disableCSSOMInjection, props.sheet, props.target]);
748
+ }, [props.disableCSSOMInjection, props.sheet, props.target, styleSheet]);
756
749
  var stylis = React.useMemo(function () {
757
750
  return createStylisInstance({
758
- options: { namespace: props.namespace, prefix: !props.disableVendorPrefixes },
751
+ options: { namespace: props.namespace, prefix: props.enableVendorPrefixes },
759
752
  plugins: plugins,
760
753
  });
761
- }, [props.disableVendorPrefixes, props.namespace, plugins]);
754
+ }, [props.enableVendorPrefixes, props.namespace, plugins]);
762
755
  React.useEffect(function () {
763
756
  if (!shallowequal(plugins, props.stylisPlugins))
764
757
  setPlugins(props.stylisPlugins);
765
758
  }, [props.stylisPlugins]);
766
- return (React.createElement(StyleSheetContext.Provider, { value: { shouldForwardProp: props.shouldForwardProp, styleSheet: styleSheet } },
767
- React.createElement(StylisContext.Provider, { value: stylis }, React.Children.only(props.children)
768
- )));
759
+ return (React.createElement(StyleSheetContext.Provider, { value: { shouldForwardProp: props.shouldForwardProp, styleSheet: resolvedStyleSheet, stylis: stylis } },
760
+ React.createElement(StylisContext.Provider, { value: stylis }, props.children)));
769
761
  }
770
762
 
771
763
  var Keyframes = /** @class */ (function () {
@@ -860,14 +852,7 @@
860
852
  'Component');
861
853
  }
862
854
 
863
- /**
864
- * inlined version of
865
- * https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/hyphenateStyleName.js
866
- */
867
- var uppercaseCheck = /[A-Z]/;
868
- var uppercasePattern = /[A-Z]/g;
869
- var msPattern = /^ms-/;
870
- var prefixAndLowerCase = function (char) { return "-".concat(char.toLowerCase()); };
855
+ var isUpper = function (c) { return c >= 'A' && c <= 'Z'; };
871
856
  /**
872
857
  * Hyphenates a camelcased CSS property name, for example:
873
858
  *
@@ -882,9 +867,21 @@
882
867
  * is converted to `-ms-`.
883
868
  */
884
869
  function hyphenateStyleName(string) {
885
- return uppercaseCheck.test(string) && !string.startsWith('--')
886
- ? string.replace(uppercasePattern, prefixAndLowerCase).replace(msPattern, '-ms-')
887
- : string;
870
+ var output = '';
871
+ for (var i = 0; i < string.length; i++) {
872
+ var c = string[i];
873
+ // Check for CSS variable prefix
874
+ if (i === 1 && c === '-' && string[0] === '-') {
875
+ return string;
876
+ }
877
+ if (isUpper(c)) {
878
+ output += '-' + c.toLowerCase();
879
+ }
880
+ else {
881
+ output += c;
882
+ }
883
+ }
884
+ return output.startsWith('ms-') ? '-' + output : output;
888
885
  }
889
886
 
890
887
  function isFunction(test) {
@@ -894,16 +891,13 @@
894
891
  function isPlainObject(x) {
895
892
  return (x !== null &&
896
893
  typeof x === 'object' &&
897
- /* a check for empty prototype would be more typical, but that
898
- doesn't play well with objects created in different vm contexts */
899
- (!x.constructor || x.constructor.name === 'Object') &&
900
- (x.toString ? x.toString() : Object.prototype.toString.call(x)) === '[object Object]' &&
894
+ x.constructor.name === Object.name &&
901
895
  /* check for reasonable markers that the object isn't an element for react & preact/compat */
902
- !('props' in x && (x.$$typeof || x.constructor === undefined)));
896
+ !('props' in x && x.$$typeof));
903
897
  }
904
898
 
905
899
  function isStatelessFunction(test) {
906
- return typeof test === 'function' && !(test.prototype && test.prototype.isReactComponent);
900
+ return isFunction(test) && !(test.prototype && test.prototype.isReactComponent);
907
901
  }
908
902
 
909
903
  function isStyledComponent(target) {
@@ -916,34 +910,26 @@
916
910
  var isFalsish = function (chunk) {
917
911
  return chunk === undefined || chunk === null || chunk === false || chunk === '';
918
912
  };
919
- var objToCssArray = function (obj, prevKey) {
913
+ var objToCssArray = function (obj) {
920
914
  var rules = [];
921
915
  for (var key in obj) {
922
- if (!obj.hasOwnProperty(key) || isFalsish(obj[key]))
916
+ var val = obj[key];
917
+ if (!obj.hasOwnProperty(key) || isFalsish(val))
923
918
  continue;
924
- if ((Array.isArray(obj[key]) && obj[key].isCss) || isFunction(obj[key])) {
925
- rules.push("".concat(hyphenateStyleName(key), ":"), obj[key], ';');
919
+ // @ts-expect-error Property 'isCss' does not exist on type 'any[]'
920
+ if ((Array.isArray(val) && val.isCss) || isFunction(val)) {
921
+ rules.push("".concat(hyphenateStyleName(key), ":"), val, ';');
926
922
  }
927
- else if (isPlainObject(obj[key])) {
928
- rules.push.apply(rules, objToCssArray(obj[key], key));
923
+ else if (isPlainObject(val)) {
924
+ rules.push.apply(rules, __spreadArray(__spreadArray(["".concat(key, " {")], objToCssArray(val), false), ['}'], false));
929
925
  }
930
926
  else {
931
- rules.push("".concat(hyphenateStyleName(key), ": ").concat(addUnitIfNeeded(key, obj[key]), ";"));
927
+ rules.push("".concat(hyphenateStyleName(key), ": ").concat(addUnitIfNeeded(key, val), ";"));
932
928
  }
933
929
  }
934
- return prevKey ? __spreadArray(__spreadArray(["".concat(prevKey, " {")], rules, true), ['}'], false) : rules;
930
+ return rules;
935
931
  };
936
932
  function flatten(chunk, executionContext, styleSheet, stylisInstance) {
937
- if (Array.isArray(chunk)) {
938
- var ruleSet = [];
939
- for (var i = 0, len = chunk.length, result = void 0; i < len; i += 1) {
940
- result = flatten(chunk[i], executionContext, styleSheet, stylisInstance);
941
- if (result.length === 0)
942
- continue;
943
- ruleSet.push.apply(ruleSet, result);
944
- }
945
- return ruleSet;
946
- }
947
933
  if (isFalsish(chunk)) {
948
934
  return [];
949
935
  }
@@ -954,14 +940,13 @@
954
940
  /* Either execute or defer the function */
955
941
  if (isFunction(chunk)) {
956
942
  if (isStatelessFunction(chunk) && executionContext) {
957
- var chunkFn = chunk;
958
- var result = chunkFn(executionContext);
943
+ var result = chunk(executionContext);
959
944
  if (typeof result === 'object' &&
960
945
  !Array.isArray(result) &&
961
946
  !(result instanceof Keyframes) &&
962
947
  !isPlainObject(result) &&
963
948
  result !== null) {
964
- console.error("".concat(getComponentName(chunkFn), " 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."));
949
+ console.error("".concat(getComponentName(chunk), " is not a styled component and cannot be referred to via component selector. See https://www.styled-components.com/docs/advanced#referring-to-other-components for more details."));
965
950
  }
966
951
  return flatten(result, executionContext, styleSheet, stylisInstance);
967
952
  }
@@ -979,7 +964,16 @@
979
964
  }
980
965
  }
981
966
  /* Handle objects */
982
- return isPlainObject(chunk) ? objToCssArray(chunk) : [chunk.toString()];
967
+ if (isPlainObject(chunk)) {
968
+ return objToCssArray(chunk);
969
+ }
970
+ if (!Array.isArray(chunk)) {
971
+ return [chunk.toString()];
972
+ }
973
+ /* Handle objects */
974
+ return chunk.flatMap(function (chunklet) {
975
+ return flatten(chunklet, executionContext, styleSheet, stylisInstance);
976
+ });
983
977
  }
984
978
 
985
979
  function isStaticRules(rules) {
@@ -994,6 +988,23 @@
994
988
  return true;
995
989
  }
996
990
 
991
+ /**
992
+ * Convenience function for joining strings to form className chains
993
+ */
994
+ function joinStrings(a, b) {
995
+ return a && b ? "".concat(a, " ").concat(b) : a || b || '';
996
+ }
997
+ function joinStringArray(arr, sep) {
998
+ if (arr.length === 0) {
999
+ return '';
1000
+ }
1001
+ var result = arr[0];
1002
+ for (var i = 1; i < arr.length; i++) {
1003
+ result += sep ? sep + arr[i] : arr[i];
1004
+ }
1005
+ return result;
1006
+ }
1007
+
997
1008
  var GlobalStyle = /** @class */ (function () {
998
1009
  function GlobalStyle(rules, componentId) {
999
1010
  this.rules = rules;
@@ -1004,8 +1015,8 @@
1004
1015
  StyleSheet.registerId(this.componentId + 1);
1005
1016
  }
1006
1017
  GlobalStyle.prototype.createStyles = function (instance, executionContext, styleSheet, stylis) {
1007
- var flatCSS = flatten(this.rules, executionContext, styleSheet, stylis);
1008
- var css = stylis(flatCSS.join(''), '');
1018
+ var flatCSS = joinStringArray(flatten(this.rules, executionContext, styleSheet, stylis));
1019
+ var css = stylis(flatCSS, '');
1009
1020
  var id = this.componentId + instance;
1010
1021
  // NOTE: We use the id as a name as well, since these rules never change
1011
1022
  styleSheet.insertRules(id, id, css);
@@ -1042,11 +1053,14 @@
1042
1053
  }
1043
1054
  return outerTheme ? __assign(__assign({}, outerTheme), theme) : theme;
1044
1055
  }
1056
+ function useTheme() {
1057
+ return React.useContext(ThemeContext);
1058
+ }
1045
1059
  /**
1046
1060
  * Provide a theme to an entire react component tree via context
1047
1061
  */
1048
1062
  function ThemeProvider(props) {
1049
- var outerTheme = React.useContext(ThemeContext);
1063
+ var outerTheme = useTheme();
1050
1064
  var themeContext = React.useMemo(function () { return mergeTheme(props.theme, outerTheme); }, [props.theme, outerTheme]);
1051
1065
  if (!props.children) {
1052
1066
  return null;
@@ -1179,10 +1193,9 @@
1179
1193
  checkDynamicCreation(styledComponentId);
1180
1194
  }
1181
1195
  var GlobalStyleComponent = function (props) {
1182
- var styleSheet = useStyleSheet();
1183
- var stylis = useStylis();
1184
- var theme = React.useContext(ThemeContext);
1185
- var instanceRef = React.useRef(styleSheet.allocateGSInstance(styledComponentId));
1196
+ var ssc = useStyleSheetContext();
1197
+ var theme = useTheme();
1198
+ var instanceRef = React.useRef(ssc.styleSheet.allocateGSInstance(styledComponentId));
1186
1199
  var instance = instanceRef.current;
1187
1200
  if (React.Children.count(props.children)) {
1188
1201
  console.warn("The global style component ".concat(styledComponentId, " was given child JSX. createGlobalStyle does not render children."));
@@ -1190,17 +1203,17 @@
1190
1203
  if (rules.some(function (rule) { return typeof rule === 'string' && rule.indexOf('@import') !== -1; })) {
1191
1204
  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.");
1192
1205
  }
1193
- if (styleSheet.server) {
1194
- renderStyles(instance, props, styleSheet, theme, stylis);
1206
+ if (ssc.styleSheet.server) {
1207
+ renderStyles(instance, props, ssc.styleSheet, theme, ssc.stylis);
1195
1208
  }
1196
1209
  {
1197
1210
  // @ts-expect-error still using React 17 types for the time being
1198
1211
  (React.useInsertionEffect || React.useLayoutEffect)(function () {
1199
- if (!styleSheet.server) {
1200
- renderStyles(instance, props, styleSheet, theme, stylis);
1201
- return function () { return globalStyle.removeStyles(instance, styleSheet); };
1212
+ if (!ssc.styleSheet.server) {
1213
+ renderStyles(instance, props, ssc.styleSheet, theme, ssc.stylis);
1214
+ return function () { return globalStyle.removeStyles(instance, ssc.styleSheet); };
1202
1215
  }
1203
- }, [instance, props, styleSheet, theme, stylis]);
1216
+ }, [instance, props, ssc.styleSheet, theme, ssc.stylis]);
1204
1217
  }
1205
1218
  return null;
1206
1219
  };
@@ -1226,7 +1239,7 @@
1226
1239
  navigator.product === 'ReactNative') {
1227
1240
  console.warn('`keyframes` cannot be used on ReactNative, only on the web. To do animation in ReactNative please use Animated.');
1228
1241
  }
1229
- var rules = css.apply(void 0, __spreadArray([strings], interpolations, false)).join('');
1242
+ var rules = joinStringArray(css.apply(void 0, __spreadArray([strings], interpolations, false)));
1230
1243
  var name = generateComponentId(rules);
1231
1244
  return new Keyframes(name, rules);
1232
1245
  }
@@ -1338,7 +1351,7 @@
1338
1351
 
1339
1352
  function withTheme(Component) {
1340
1353
  var WithTheme = React.forwardRef(function (props, ref) {
1341
- var theme = React.useContext(ThemeContext);
1354
+ var theme = useTheme();
1342
1355
  var themeProp = determineTheme(props, theme, Component.defaultProps);
1343
1356
  if (themeProp === undefined) {
1344
1357
  console.warn("[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class \"".concat(getComponentName(Component), "\""));
@@ -1349,8 +1362,6 @@
1349
1362
  return hoistNonReactStatics(WithTheme, Component);
1350
1363
  }
1351
1364
 
1352
- var useTheme = function () { return React.useContext(ThemeContext); };
1353
-
1354
1365
  var ServerStyleSheet = /** @class */ (function () {
1355
1366
  function ServerStyleSheet() {
1356
1367
  var _this = this;
@@ -1362,7 +1373,7 @@
1362
1373
  "".concat(SC_ATTR, "=\"true\""),
1363
1374
  "".concat(SC_ATTR_VERSION, "=\"").concat(SC_VERSION, "\""),
1364
1375
  ];
1365
- var htmlAttr = attrs.filter(Boolean).join(' ');
1376
+ var htmlAttr = joinStringArray(attrs.filter(Boolean), ' ');
1366
1377
  return "<style ".concat(htmlAttr, ">").concat(css, "</style>");
1367
1378
  };
1368
1379
  this.getStyleTags = function () {
@@ -1420,20 +1431,19 @@
1420
1431
  /* Warning if you've imported this file on React Native */
1421
1432
  if (typeof navigator !== 'undefined' &&
1422
1433
  navigator.product === 'ReactNative') {
1423
- console.warn("It looks like you've imported 'styled-components' on React Native.\n" +
1424
- "Perhaps you're looking to import 'styled-components/native'?\n" +
1425
- 'Read more about this at https://www.styled-components.com/docs/basics#react-native');
1434
+ console.warn("It looks like you've imported 'styled-components' on React Native.\nPerhaps you're looking to import 'styled-components/native'?\nRead more about this at https://www.styled-components.com/docs/basics#react-native");
1426
1435
  }
1436
+ var windowGlobalKey = "__sc-".concat(SC_ATTR, "__");
1427
1437
  /* Warning if there are several instances of styled-components */
1428
1438
  if (typeof window !== 'undefined') {
1429
- window['__styled-components-init__'] || (window['__styled-components-init__'] = 0);
1430
- if (window['__styled-components-init__'] === 1) {
1431
- console.warn("It looks like there are several instances of 'styled-components' initialized in this application. " +
1432
- 'This may cause dynamic styles to not render properly, errors during the rehydration process, ' +
1433
- 'a missing theme prop, and makes your application bigger without good reason.\n\n' +
1434
- 'See https://s-c.sh/2BAXzed for more info.');
1435
- }
1436
- window['__styled-components-init__'] += 1;
1439
+ // @ts-expect-error dynamic key not in window object
1440
+ window[windowGlobalKey] || (window[windowGlobalKey] = 0);
1441
+ // @ts-expect-error dynamic key not in window object
1442
+ if (window[windowGlobalKey] === 1) {
1443
+ console.warn("It looks like there are several instances of 'styled-components' initialized in this application. This may cause dynamic styles to not render properly, errors during the rehydration process, a missing theme prop, and makes your application bigger without good reason.\n\nSee https://s-c.sh/2BAXzed for more info.");
1444
+ }
1445
+ // @ts-expect-error dynamic key not in window object
1446
+ window[windowGlobalKey] += 1;
1437
1447
  }
1438
1448
 
1439
1449
  var secondary = /*#__PURE__*/Object.freeze({
@@ -1482,7 +1492,7 @@
1482
1492
  });
1483
1493
 
1484
1494
  // Thanks to ReactDOMFactories for this handy list!
1485
- var domElements = [
1495
+ var domElements = new Set([
1486
1496
  'a',
1487
1497
  'abbr',
1488
1498
  'address',
@@ -1618,7 +1628,7 @@
1618
1628
  'svg',
1619
1629
  'text',
1620
1630
  'tspan',
1621
- ];
1631
+ ]);
1622
1632
 
1623
1633
  // Source: https://www.w3.org/TR/cssom-1/#serialize-an-identifier
1624
1634
  // Control characters and non-letter first symbols are not supported
@@ -1644,17 +1654,6 @@
1644
1654
  return isTag(target) ? "styled.".concat(target) : "Styled(".concat(getComponentName(target), ")");
1645
1655
  }
1646
1656
 
1647
- /**
1648
- * Convenience function for joining strings to form className chains
1649
- */
1650
- function joinStrings() {
1651
- var args = [];
1652
- for (var _i = 0; _i < arguments.length; _i++) {
1653
- args[_i] = arguments[_i];
1654
- }
1655
- return args.filter(Boolean).join(' ');
1656
- }
1657
-
1658
1657
  function mixinRecursively(target, source, forceMerge) {
1659
1658
  if (forceMerge === void 0) { forceMerge = false; }
1660
1659
  /* only merge into POJOs, Arrays, but for top level objects only
@@ -1697,74 +1696,61 @@
1697
1696
  */
1698
1697
  var ComponentStyle = /** @class */ (function () {
1699
1698
  function ComponentStyle(rules, componentId, baseStyle) {
1700
- this.names = [];
1701
1699
  this.rules = rules;
1702
1700
  this.staticRulesId = '';
1703
1701
  this.isStatic =
1704
1702
  "development" === 'production' ;
1705
1703
  this.componentId = componentId;
1706
- // SC_VERSION gives us isolation between multiple runtimes on the page at once
1707
- // this is improved further with use of the babel plugin "namespace" feature
1708
1704
  this.baseHash = phash(SEED, componentId);
1709
1705
  this.baseStyle = baseStyle;
1710
1706
  // NOTE: This registers the componentId, which ensures a consistent order
1711
1707
  // for this component's styles compared to others
1712
1708
  StyleSheet.registerId(componentId);
1713
1709
  }
1714
- /*
1715
- * Flattens a rule set into valid CSS
1716
- * Hashes it, wraps the whole chunk in a .hash1234 {}
1717
- * Returns the hash to be injected on render()
1718
- * */
1719
1710
  ComponentStyle.prototype.generateAndInjectStyles = function (executionContext, styleSheet, stylis) {
1720
- var componentId = this.componentId;
1721
- this.names.length = 0;
1722
- if (this.baseStyle) {
1723
- this.names.push(this.baseStyle.generateAndInjectStyles(executionContext, styleSheet, stylis));
1724
- }
1711
+ var names = this.baseStyle
1712
+ ? this.baseStyle.generateAndInjectStyles(executionContext, styleSheet, stylis)
1713
+ : '';
1725
1714
  // force dynamic classnames if user-supplied stylis plugins are in use
1726
1715
  if (this.isStatic && !stylis.hash) {
1727
- if (this.staticRulesId && styleSheet.hasNameForId(componentId, this.staticRulesId)) {
1728
- this.names.push(this.staticRulesId);
1716
+ if (this.staticRulesId && styleSheet.hasNameForId(this.componentId, this.staticRulesId)) {
1717
+ names = joinStrings(names, this.staticRulesId);
1729
1718
  }
1730
1719
  else {
1731
- var cssStatic = flatten(this.rules, executionContext, styleSheet, stylis).join('');
1720
+ var cssStatic = joinStringArray(flatten(this.rules, executionContext, styleSheet, stylis));
1732
1721
  var name_1 = generateAlphabeticName(phash(this.baseHash, cssStatic) >>> 0);
1733
- if (!styleSheet.hasNameForId(componentId, name_1)) {
1734
- var cssStaticFormatted = stylis(cssStatic, ".".concat(name_1), undefined, componentId);
1735
- styleSheet.insertRules(componentId, name_1, cssStaticFormatted);
1722
+ if (!styleSheet.hasNameForId(this.componentId, name_1)) {
1723
+ var cssStaticFormatted = stylis(cssStatic, ".".concat(name_1), undefined, this.componentId);
1724
+ styleSheet.insertRules(this.componentId, name_1, cssStaticFormatted);
1736
1725
  }
1737
- this.names.push(name_1);
1726
+ names = joinStrings(names, name_1);
1738
1727
  this.staticRulesId = name_1;
1739
1728
  }
1740
1729
  }
1741
1730
  else {
1742
- var length_1 = this.rules.length;
1743
1731
  var dynamicHash = phash(this.baseHash, stylis.hash);
1744
1732
  var css = '';
1745
- for (var i = 0; i < length_1; i++) {
1733
+ for (var i = 0; i < this.rules.length; i++) {
1746
1734
  var partRule = this.rules[i];
1747
1735
  if (typeof partRule === 'string') {
1748
1736
  css += partRule;
1749
1737
  dynamicHash = phash(dynamicHash, partRule);
1750
1738
  }
1751
1739
  else if (partRule) {
1752
- var partChunk = flatten(partRule, executionContext, styleSheet, stylis);
1753
- var partString = Array.isArray(partChunk) ? partChunk.join('') : partChunk;
1740
+ var partString = joinStringArray(flatten(partRule, executionContext, styleSheet, stylis));
1754
1741
  dynamicHash = phash(dynamicHash, partString);
1755
1742
  css += partString;
1756
1743
  }
1757
1744
  }
1758
1745
  if (css) {
1759
1746
  var name_2 = generateAlphabeticName(dynamicHash >>> 0);
1760
- if (!styleSheet.hasNameForId(componentId, name_2)) {
1761
- var cssFormatted = stylis(css, ".".concat(name_2), undefined, componentId);
1762
- styleSheet.insertRules(componentId, name_2, cssFormatted);
1747
+ if (!styleSheet.hasNameForId(this.componentId, name_2)) {
1748
+ styleSheet.insertRules(this.componentId, name_2, stylis(css, ".".concat(name_2), undefined, this.componentId));
1763
1749
  }
1764
- this.names.push(name_2);
1750
+ names = joinStrings(names, name_2);
1765
1751
  }
1766
1752
  }
1767
- return this.names.join(' ');
1753
+ return names;
1768
1754
  };
1769
1755
  return ComponentStyle;
1770
1756
  }());
@@ -1781,64 +1767,75 @@
1781
1767
  SC_VERSION + name + identifiers[name]));
1782
1768
  return parentComponentId ? "".concat(parentComponentId, "-").concat(componentId) : componentId;
1783
1769
  }
1784
- function useInjectedStyle(componentStyle, isStatic, resolvedAttrs, warnTooManyClasses) {
1785
- var styleSheet = useStyleSheet();
1786
- var stylis = useStylis();
1787
- var className = componentStyle.generateAndInjectStyles(isStatic ? EMPTY_OBJECT : resolvedAttrs, styleSheet, stylis);
1770
+ function useInjectedStyle(componentStyle, isStatic, resolvedAttrs) {
1771
+ var ssc = useStyleSheetContext();
1772
+ var className = componentStyle.generateAndInjectStyles(isStatic ? EMPTY_OBJECT : resolvedAttrs, ssc.styleSheet, ssc.stylis);
1788
1773
  React.useDebugValue(className);
1789
- if (!isStatic && warnTooManyClasses) {
1790
- warnTooManyClasses(className);
1791
- }
1792
1774
  return className;
1793
1775
  }
1776
+ function resolveContext(attrs, props, theme) {
1777
+ var context = __assign(__assign({}, props), {
1778
+ // unset, add `props.className` back at the end so props always "wins"
1779
+ className: undefined, theme: theme });
1780
+ var attrDef;
1781
+ for (var i = 0; i < attrs.length; i += 1) {
1782
+ attrDef = attrs[i];
1783
+ var resolvedAttrDef = isFunction(attrDef) ? attrDef(context) : attrDef;
1784
+ for (var key in resolvedAttrDef) {
1785
+ // @ts-expect-error bad types
1786
+ context[key] =
1787
+ key === 'className'
1788
+ ? joinStrings(context[key], resolvedAttrDef[key])
1789
+ : key === 'style'
1790
+ ? __assign(__assign({}, context[key]), resolvedAttrDef[key]) : resolvedAttrDef[key];
1791
+ }
1792
+ }
1793
+ if (props.className) {
1794
+ context.className = joinStrings(context.className, props.className);
1795
+ }
1796
+ return context;
1797
+ }
1794
1798
  function useStyledComponentImpl(forwardedComponent, props, forwardedRef, isStatic) {
1795
1799
  var componentAttrs = forwardedComponent.attrs, componentStyle = forwardedComponent.componentStyle, defaultProps = forwardedComponent.defaultProps, foldedComponentIds = forwardedComponent.foldedComponentIds, styledComponentId = forwardedComponent.styledComponentId, target = forwardedComponent.target;
1796
- var defaultShouldForwardProp = useShouldForwardProp();
1797
- var shouldForwardProp = forwardedComponent.shouldForwardProp || defaultShouldForwardProp;
1800
+ var contextTheme = useTheme();
1801
+ var ssc = useStyleSheetContext();
1802
+ var shouldForwardProp = forwardedComponent.shouldForwardProp || ssc.shouldForwardProp;
1798
1803
  React.useDebugValue(styledComponentId);
1799
1804
  // NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,
1800
1805
  // but that'd be against the rules-of-hooks. We could be naughty and do it anyway as it
1801
1806
  // should be an immutable value, but behave for now.
1802
- var theme = determineTheme(props, React.useContext(ThemeContext), defaultProps) || EMPTY_OBJECT;
1803
- var context = componentAttrs.reduce(function (p, attrDef) {
1804
- var resolvedAttrDef = typeof attrDef === 'function' ? attrDef(p) : attrDef;
1805
- for (var key in resolvedAttrDef) {
1806
- // @ts-expect-error bad types
1807
- p[key] =
1808
- key === 'className'
1809
- ? joinStrings(p[key], resolvedAttrDef[key])
1810
- : key === 'style'
1811
- ? __assign(__assign({}, p[key]), resolvedAttrDef[key]) : resolvedAttrDef[key];
1812
- }
1813
- return p;
1814
- }, __assign(__assign({}, props), { theme: theme }));
1815
- var generatedClassName = useInjectedStyle(componentStyle, isStatic, context, forwardedComponent.warnTooManyClasses );
1816
- var refToForward = forwardedRef;
1807
+ var theme = determineTheme(props, contextTheme, defaultProps) || EMPTY_OBJECT;
1808
+ var context = resolveContext(componentAttrs, props, theme);
1817
1809
  var elementToBeCreated = context.as || target;
1818
- var isTargetTag = isTag(elementToBeCreated);
1819
1810
  var propsForElement = {};
1820
1811
  for (var key in context) {
1821
- // @ts-expect-error for..in iterates strings instead of keyof
1822
1812
  if (context[key] === undefined) ;
1823
1813
  else if (key[0] === '$' || key === 'as' || key === 'theme') ;
1824
1814
  else if (key === 'forwardedAs') {
1825
1815
  propsForElement.as = context.forwardedAs;
1826
1816
  }
1827
1817
  else if (!shouldForwardProp || shouldForwardProp(key, elementToBeCreated)) {
1828
- // @ts-expect-error for..in iterates strings instead of keyof
1829
1818
  propsForElement[key] = context[key];
1830
1819
  }
1831
1820
  }
1821
+ var generatedClassName = useInjectedStyle(componentStyle, isStatic, context);
1822
+ if (!isStatic && forwardedComponent.warnTooManyClasses) {
1823
+ forwardedComponent.warnTooManyClasses(generatedClassName);
1824
+ }
1825
+ var classString = joinStrings(foldedComponentIds, styledComponentId);
1826
+ if (generatedClassName) {
1827
+ classString += ' ' + generatedClassName;
1828
+ }
1829
+ if (context.className) {
1830
+ classString += ' ' + context.className;
1831
+ }
1832
1832
  propsForElement[
1833
1833
  // handle custom elements which React doesn't properly alias
1834
- isTargetTag &&
1835
- domElements.indexOf(elementToBeCreated) === -1
1834
+ isTag(elementToBeCreated) &&
1835
+ !domElements.has(elementToBeCreated)
1836
1836
  ? 'class'
1837
- : 'className'] = foldedComponentIds
1838
- .concat(styledComponentId, generatedClassName !== styledComponentId ? generatedClassName : '', context.className || '')
1839
- .filter(Boolean)
1840
- .join(' ');
1841
- propsForElement.ref = refToForward;
1837
+ : 'className'] = classString;
1838
+ propsForElement.ref = forwardedRef;
1842
1839
  return React.createElement(elementToBeCreated, propsForElement);
1843
1840
  }
1844
1841
  function createStyledComponent(target, options, rules) {
@@ -1890,8 +1887,8 @@
1890
1887
  // this static is used to preserve the cascade of static classes for component selector
1891
1888
  // purposes; this is especially important with usage of the css prop
1892
1889
  WrappedStyledComponent.foldedComponentIds = isTargetStyledComp
1893
- ? styledComponentTarget.foldedComponentIds.concat(styledComponentTarget.styledComponentId)
1894
- : EMPTY_ARRAY;
1890
+ ? joinStrings(styledComponentTarget.foldedComponentIds, styledComponentTarget.styledComponentId)
1891
+ : '';
1895
1892
  WrappedStyledComponent.styledComponentId = styledComponentId;
1896
1893
  // fold the underlying StyledComponent target up since we folded the styles
1897
1894
  WrappedStyledComponent.target = isTargetStyledComp ? styledComponentTarget.target : target;
@@ -1909,7 +1906,13 @@
1909
1906
  checkDynamicCreation(displayName, styledComponentId);
1910
1907
  WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName, styledComponentId);
1911
1908
  }
1912
- WrappedStyledComponent.toString = function () { return ".".concat(WrappedStyledComponent.styledComponentId); };
1909
+ // If the Object prototype is frozen, the "toString" property is non-writable. This means that any objects which inherit this property
1910
+ // cannot have the property changed using an assignment. If using strict mode, attempting that will cause an error. If not using strict
1911
+ // mode, attempting that will be silently ignored.
1912
+ // However, we can still explicitly shadow the prototype's "toString" property by defining a new "toString" property on this object.
1913
+ Object.defineProperty(WrappedStyledComponent, 'toString', {
1914
+ value: function () { return ".".concat(WrappedStyledComponent.styledComponentId); },
1915
+ });
1913
1916
  if (isCompositeComponent) {
1914
1917
  var compositeComponentTarget = target;
1915
1918
  hoistNonReactStatics(WrappedStyledComponent, compositeComponentTarget, {