styled-components 6.0.0-beta.13 → 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 -2
  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 -1862
  8. package/dist/styled-components.browser.cjs.js.map +1 -1
  9. package/dist/styled-components.browser.esm.js +1 -1836
  10. package/dist/styled-components.browser.esm.js.map +1 -1
  11. package/dist/styled-components.cjs.js +1 -1886
  12. package/dist/styled-components.cjs.js.map +1 -1
  13. package/dist/styled-components.esm.js +1 -1860
  14. package/dist/styled-components.esm.js.map +1 -1
  15. package/dist/styled-components.js +185 -185
  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 -2
  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 -1
  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.13";
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 () {
@@ -1481,7 +1492,7 @@
1481
1492
  });
1482
1493
 
1483
1494
  // Thanks to ReactDOMFactories for this handy list!
1484
- var domElements = [
1495
+ var domElements = new Set([
1485
1496
  'a',
1486
1497
  'abbr',
1487
1498
  'address',
@@ -1617,7 +1628,7 @@
1617
1628
  'svg',
1618
1629
  'text',
1619
1630
  'tspan',
1620
- ];
1631
+ ]);
1621
1632
 
1622
1633
  // Source: https://www.w3.org/TR/cssom-1/#serialize-an-identifier
1623
1634
  // Control characters and non-letter first symbols are not supported
@@ -1643,17 +1654,6 @@
1643
1654
  return isTag(target) ? "styled.".concat(target) : "Styled(".concat(getComponentName(target), ")");
1644
1655
  }
1645
1656
 
1646
- /**
1647
- * Convenience function for joining strings to form className chains
1648
- */
1649
- function joinStrings() {
1650
- var args = [];
1651
- for (var _i = 0; _i < arguments.length; _i++) {
1652
- args[_i] = arguments[_i];
1653
- }
1654
- return args.filter(Boolean).join(' ');
1655
- }
1656
-
1657
1657
  function mixinRecursively(target, source, forceMerge) {
1658
1658
  if (forceMerge === void 0) { forceMerge = false; }
1659
1659
  /* only merge into POJOs, Arrays, but for top level objects only
@@ -1696,74 +1696,61 @@
1696
1696
  */
1697
1697
  var ComponentStyle = /** @class */ (function () {
1698
1698
  function ComponentStyle(rules, componentId, baseStyle) {
1699
- this.names = [];
1700
1699
  this.rules = rules;
1701
1700
  this.staticRulesId = '';
1702
1701
  this.isStatic =
1703
1702
  "development" === 'production' ;
1704
1703
  this.componentId = componentId;
1705
- // SC_VERSION gives us isolation between multiple runtimes on the page at once
1706
- // this is improved further with use of the babel plugin "namespace" feature
1707
1704
  this.baseHash = phash(SEED, componentId);
1708
1705
  this.baseStyle = baseStyle;
1709
1706
  // NOTE: This registers the componentId, which ensures a consistent order
1710
1707
  // for this component's styles compared to others
1711
1708
  StyleSheet.registerId(componentId);
1712
1709
  }
1713
- /*
1714
- * Flattens a rule set into valid CSS
1715
- * Hashes it, wraps the whole chunk in a .hash1234 {}
1716
- * Returns the hash to be injected on render()
1717
- * */
1718
1710
  ComponentStyle.prototype.generateAndInjectStyles = function (executionContext, styleSheet, stylis) {
1719
- var componentId = this.componentId;
1720
- this.names.length = 0;
1721
- if (this.baseStyle) {
1722
- this.names.push(this.baseStyle.generateAndInjectStyles(executionContext, styleSheet, stylis));
1723
- }
1711
+ var names = this.baseStyle
1712
+ ? this.baseStyle.generateAndInjectStyles(executionContext, styleSheet, stylis)
1713
+ : '';
1724
1714
  // force dynamic classnames if user-supplied stylis plugins are in use
1725
1715
  if (this.isStatic && !stylis.hash) {
1726
- if (this.staticRulesId && styleSheet.hasNameForId(componentId, this.staticRulesId)) {
1727
- this.names.push(this.staticRulesId);
1716
+ if (this.staticRulesId && styleSheet.hasNameForId(this.componentId, this.staticRulesId)) {
1717
+ names = joinStrings(names, this.staticRulesId);
1728
1718
  }
1729
1719
  else {
1730
- var cssStatic = flatten(this.rules, executionContext, styleSheet, stylis).join('');
1720
+ var cssStatic = joinStringArray(flatten(this.rules, executionContext, styleSheet, stylis));
1731
1721
  var name_1 = generateAlphabeticName(phash(this.baseHash, cssStatic) >>> 0);
1732
- if (!styleSheet.hasNameForId(componentId, name_1)) {
1733
- var cssStaticFormatted = stylis(cssStatic, ".".concat(name_1), undefined, componentId);
1734
- 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);
1735
1725
  }
1736
- this.names.push(name_1);
1726
+ names = joinStrings(names, name_1);
1737
1727
  this.staticRulesId = name_1;
1738
1728
  }
1739
1729
  }
1740
1730
  else {
1741
- var length_1 = this.rules.length;
1742
1731
  var dynamicHash = phash(this.baseHash, stylis.hash);
1743
1732
  var css = '';
1744
- for (var i = 0; i < length_1; i++) {
1733
+ for (var i = 0; i < this.rules.length; i++) {
1745
1734
  var partRule = this.rules[i];
1746
1735
  if (typeof partRule === 'string') {
1747
1736
  css += partRule;
1748
1737
  dynamicHash = phash(dynamicHash, partRule);
1749
1738
  }
1750
1739
  else if (partRule) {
1751
- var partChunk = flatten(partRule, executionContext, styleSheet, stylis);
1752
- var partString = Array.isArray(partChunk) ? partChunk.join('') : partChunk;
1740
+ var partString = joinStringArray(flatten(partRule, executionContext, styleSheet, stylis));
1753
1741
  dynamicHash = phash(dynamicHash, partString);
1754
1742
  css += partString;
1755
1743
  }
1756
1744
  }
1757
1745
  if (css) {
1758
1746
  var name_2 = generateAlphabeticName(dynamicHash >>> 0);
1759
- if (!styleSheet.hasNameForId(componentId, name_2)) {
1760
- var cssFormatted = stylis(css, ".".concat(name_2), undefined, componentId);
1761
- 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));
1762
1749
  }
1763
- this.names.push(name_2);
1750
+ names = joinStrings(names, name_2);
1764
1751
  }
1765
1752
  }
1766
- return this.names.join(' ');
1753
+ return names;
1767
1754
  };
1768
1755
  return ComponentStyle;
1769
1756
  }());
@@ -1780,64 +1767,75 @@
1780
1767
  SC_VERSION + name + identifiers[name]));
1781
1768
  return parentComponentId ? "".concat(parentComponentId, "-").concat(componentId) : componentId;
1782
1769
  }
1783
- function useInjectedStyle(componentStyle, isStatic, resolvedAttrs, warnTooManyClasses) {
1784
- var styleSheet = useStyleSheet();
1785
- var stylis = useStylis();
1786
- 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);
1787
1773
  React.useDebugValue(className);
1788
- if (!isStatic && warnTooManyClasses) {
1789
- warnTooManyClasses(className);
1790
- }
1791
1774
  return className;
1792
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
+ }
1793
1798
  function useStyledComponentImpl(forwardedComponent, props, forwardedRef, isStatic) {
1794
1799
  var componentAttrs = forwardedComponent.attrs, componentStyle = forwardedComponent.componentStyle, defaultProps = forwardedComponent.defaultProps, foldedComponentIds = forwardedComponent.foldedComponentIds, styledComponentId = forwardedComponent.styledComponentId, target = forwardedComponent.target;
1795
- var defaultShouldForwardProp = useShouldForwardProp();
1796
- var shouldForwardProp = forwardedComponent.shouldForwardProp || defaultShouldForwardProp;
1800
+ var contextTheme = useTheme();
1801
+ var ssc = useStyleSheetContext();
1802
+ var shouldForwardProp = forwardedComponent.shouldForwardProp || ssc.shouldForwardProp;
1797
1803
  React.useDebugValue(styledComponentId);
1798
1804
  // NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,
1799
1805
  // but that'd be against the rules-of-hooks. We could be naughty and do it anyway as it
1800
1806
  // should be an immutable value, but behave for now.
1801
- var theme = determineTheme(props, React.useContext(ThemeContext), defaultProps) || EMPTY_OBJECT;
1802
- var context = componentAttrs.reduce(function (p, attrDef) {
1803
- var resolvedAttrDef = typeof attrDef === 'function' ? attrDef(p) : attrDef;
1804
- for (var key in resolvedAttrDef) {
1805
- // @ts-expect-error bad types
1806
- p[key] =
1807
- key === 'className'
1808
- ? joinStrings(p[key], resolvedAttrDef[key])
1809
- : key === 'style'
1810
- ? __assign(__assign({}, p[key]), resolvedAttrDef[key]) : resolvedAttrDef[key];
1811
- }
1812
- return p;
1813
- }, __assign(__assign({}, props), { theme: theme }));
1814
- var generatedClassName = useInjectedStyle(componentStyle, isStatic, context, forwardedComponent.warnTooManyClasses );
1815
- var refToForward = forwardedRef;
1807
+ var theme = determineTheme(props, contextTheme, defaultProps) || EMPTY_OBJECT;
1808
+ var context = resolveContext(componentAttrs, props, theme);
1816
1809
  var elementToBeCreated = context.as || target;
1817
- var isTargetTag = isTag(elementToBeCreated);
1818
1810
  var propsForElement = {};
1819
1811
  for (var key in context) {
1820
- // @ts-expect-error for..in iterates strings instead of keyof
1821
1812
  if (context[key] === undefined) ;
1822
1813
  else if (key[0] === '$' || key === 'as' || key === 'theme') ;
1823
1814
  else if (key === 'forwardedAs') {
1824
1815
  propsForElement.as = context.forwardedAs;
1825
1816
  }
1826
1817
  else if (!shouldForwardProp || shouldForwardProp(key, elementToBeCreated)) {
1827
- // @ts-expect-error for..in iterates strings instead of keyof
1828
1818
  propsForElement[key] = context[key];
1829
1819
  }
1830
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
+ }
1831
1832
  propsForElement[
1832
1833
  // handle custom elements which React doesn't properly alias
1833
- isTargetTag &&
1834
- domElements.indexOf(elementToBeCreated) === -1
1834
+ isTag(elementToBeCreated) &&
1835
+ !domElements.has(elementToBeCreated)
1835
1836
  ? 'class'
1836
- : 'className'] = foldedComponentIds
1837
- .concat(styledComponentId, generatedClassName !== styledComponentId ? generatedClassName : '', context.className || '')
1838
- .filter(Boolean)
1839
- .join(' ');
1840
- propsForElement.ref = refToForward;
1837
+ : 'className'] = classString;
1838
+ propsForElement.ref = forwardedRef;
1841
1839
  return React.createElement(elementToBeCreated, propsForElement);
1842
1840
  }
1843
1841
  function createStyledComponent(target, options, rules) {
@@ -1889,8 +1887,8 @@
1889
1887
  // this static is used to preserve the cascade of static classes for component selector
1890
1888
  // purposes; this is especially important with usage of the css prop
1891
1889
  WrappedStyledComponent.foldedComponentIds = isTargetStyledComp
1892
- ? styledComponentTarget.foldedComponentIds.concat(styledComponentTarget.styledComponentId)
1893
- : EMPTY_ARRAY;
1890
+ ? joinStrings(styledComponentTarget.foldedComponentIds, styledComponentTarget.styledComponentId)
1891
+ : '';
1894
1892
  WrappedStyledComponent.styledComponentId = styledComponentId;
1895
1893
  // fold the underlying StyledComponent target up since we folded the styles
1896
1894
  WrappedStyledComponent.target = isTargetStyledComp ? styledComponentTarget.target : target;
@@ -1912,7 +1910,9 @@
1912
1910
  // cannot have the property changed using an assignment. If using strict mode, attempting that will cause an error. If not using strict
1913
1911
  // mode, attempting that will be silently ignored.
1914
1912
  // However, we can still explicitly shadow the prototype's "toString" property by defining a new "toString" property on this object.
1915
- Object.defineProperty(WrappedStyledComponent, 'toString', { value: function () { return ".".concat(WrappedStyledComponent.styledComponentId); } });
1913
+ Object.defineProperty(WrappedStyledComponent, 'toString', {
1914
+ value: function () { return ".".concat(WrappedStyledComponent.styledComponentId); },
1915
+ });
1916
1916
  if (isCompositeComponent) {
1917
1917
  var compositeComponentTarget = target;
1918
1918
  hoistNonReactStatics(WrappedStyledComponent, compositeComponentTarget, {