styled-components 6.0.0-beta.5 → 6.0.0-beta.7

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 (38) hide show
  1. package/dist/base.d.ts +2 -2
  2. package/dist/constructors/constructWithOptions.d.ts +2 -2
  3. package/dist/constructors/styled.d.ts +1 -1
  4. package/dist/index.d.ts +2 -2
  5. package/dist/models/StyleSheetManager.d.ts +38 -13
  6. package/dist/native/index.d.ts +27 -27
  7. package/dist/styled-components-macro.cjs.js +2 -7
  8. package/dist/styled-components-macro.cjs.js.map +1 -1
  9. package/dist/styled-components.browser.cjs.js +36 -40
  10. package/dist/styled-components.browser.cjs.js.map +1 -1
  11. package/dist/styled-components.browser.esm.js +17 -16
  12. package/dist/styled-components.browser.esm.js.map +1 -1
  13. package/dist/styled-components.cjs.js +35 -39
  14. package/dist/styled-components.cjs.js.map +1 -1
  15. package/dist/styled-components.esm.js +17 -16
  16. package/dist/styled-components.esm.js.map +1 -1
  17. package/dist/styled-components.js +33 -131
  18. package/dist/styled-components.js.map +1 -1
  19. package/dist/styled-components.min.js +1 -1
  20. package/dist/styled-components.min.js.map +1 -1
  21. package/dist/test/utils.d.ts +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/dist/types.d.ts +15 -5
  24. package/dist/utils/stylis.d.ts +3 -3
  25. package/native/dist/base.d.ts +2 -2
  26. package/native/dist/constructors/constructWithOptions.d.ts +2 -2
  27. package/native/dist/constructors/styled.d.ts +1 -1
  28. package/native/dist/index.d.ts +2 -2
  29. package/native/dist/models/StyleSheetManager.d.ts +38 -13
  30. package/native/dist/native/index.d.ts +27 -27
  31. package/native/dist/styled-components.native.cjs.js +24 -25
  32. package/native/dist/styled-components.native.cjs.js.map +1 -1
  33. package/native/dist/styled-components.native.esm.js +13 -9
  34. package/native/dist/styled-components.native.esm.js.map +1 -1
  35. package/native/dist/test/utils.d.ts +1 -1
  36. package/native/dist/types.d.ts +15 -5
  37. package/native/dist/utils/stylis.d.ts +3 -3
  38. package/package.json +32 -33
@@ -8,17 +8,11 @@ var shallowequal = require('shallowequal');
8
8
  var stylis = require('stylis');
9
9
  var unitless = require('@emotion/unitless');
10
10
 
11
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
-
13
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
14
- var shallowequal__default = /*#__PURE__*/_interopDefaultLegacy(shallowequal);
15
- var unitless__default = /*#__PURE__*/_interopDefaultLegacy(unitless);
16
-
17
11
  var SC_ATTR = (typeof process !== 'undefined' && (process.env.REACT_APP_SC_ATTR || process.env.SC_ATTR)) ||
18
12
  'data-styled';
19
13
  var SC_ATTR_ACTIVE = 'active';
20
14
  var SC_ATTR_VERSION = 'data-styled-version';
21
- var SC_VERSION = "6.0.0-beta.5";
15
+ var SC_VERSION = "6.0.0-beta.7";
22
16
  var SPLITTER = '/*!sc*/\n';
23
17
  var IS_BROWSER = typeof undefined !== 'undefined' ;
24
18
  var DISABLE_SPEEDY = Boolean(typeof SC_DISABLE_SPEEDY === 'boolean'
@@ -1026,7 +1020,11 @@ function createStylisInstance(_a) {
1026
1020
  props[0] = props[0].replace(_selectorRegexp, selfReferenceReplacer);
1027
1021
  }
1028
1022
  };
1029
- var stringifyRules = function (css, selector, prefix, componentId) {
1023
+ var stringifyRules = function (css, selector,
1024
+ /**
1025
+ * This "prefix" referes to a _selector_ prefix.
1026
+ */
1027
+ prefix, componentId) {
1030
1028
  if (selector === void 0) { selector = ''; }
1031
1029
  if (prefix === void 0) { prefix = ''; }
1032
1030
  if (componentId === void 0) { componentId = '&'; }
@@ -1039,11 +1037,16 @@ function createStylisInstance(_a) {
1039
1037
  _selectorRegexp = new RegExp("\\".concat(_selector, "\\b"), 'g');
1040
1038
  _consecutiveSelfRefRegExp = new RegExp("(\\".concat(_selector, "\\b){2,}"));
1041
1039
  var middlewares = plugins.slice();
1040
+ /**
1041
+ * Enables automatic vendor-prefixing for styles.
1042
+ */
1042
1043
  if (options.prefix || options.prefix === undefined) {
1043
1044
  middlewares.unshift(stylis.prefixer);
1044
1045
  }
1045
1046
  middlewares.push(selfReferenceReplacementPlugin, stylis.stringify);
1046
- return serialize(stylis.compile(prefix || selector ? "".concat(prefix, " ").concat(selector, " { ").concat(flatCSS, " }") : flatCSS), stylis.middleware(middlewares));
1047
+ return serialize(stylis.compile(options.namespace || prefix || selector
1048
+ ? "".concat(options.namespace ? options.namespace + ' ' : '').concat(prefix, " ").concat(selector, " { ").concat(flatCSS, " }")
1049
+ : flatCSS), stylis.middleware(middlewares));
1047
1050
  };
1048
1051
  stringifyRules.hash = plugins.length
1049
1052
  ? plugins
@@ -1058,9 +1061,9 @@ function createStylisInstance(_a) {
1058
1061
  return stringifyRules;
1059
1062
  }
1060
1063
 
1061
- var StyleSheetContext = React__default["default"].createContext(undefined);
1064
+ var StyleSheetContext = React.createContext(undefined);
1062
1065
  var StyleSheetConsumer = StyleSheetContext.Consumer;
1063
- var StylisContext = React__default["default"].createContext(undefined);
1066
+ var StylisContext = React.createContext(undefined);
1064
1067
  StylisContext.Consumer;
1065
1068
  var mainSheet = new StyleSheet();
1066
1069
  var mainStylis = createStylisInstance();
@@ -1089,17 +1092,17 @@ function StyleSheetManager(props) {
1089
1092
  }, [props.disableCSSOMInjection, props.sheet, props.target]);
1090
1093
  var stylis = React.useMemo(function () {
1091
1094
  return createStylisInstance({
1092
- options: { prefix: !props.disableVendorPrefixes },
1095
+ options: { namespace: props.namespace, prefix: !props.disableVendorPrefixes },
1093
1096
  plugins: plugins,
1094
1097
  });
1095
- }, [props.disableVendorPrefixes, plugins]);
1098
+ }, [props.disableVendorPrefixes, props.namespace, plugins]);
1096
1099
  React.useEffect(function () {
1097
- if (!shallowequal__default["default"](plugins, props.stylisPlugins))
1100
+ if (!shallowequal(plugins, props.stylisPlugins))
1098
1101
  setPlugins(props.stylisPlugins);
1099
1102
  }, [props.stylisPlugins]);
1100
- return (React__default["default"].createElement(StyleSheetContext.Provider, { value: styleSheet },
1101
- React__default["default"].createElement(StylisContext.Provider, { value: stylis }, process.env.NODE_ENV !== 'production'
1102
- ? React__default["default"].Children.only(props.children)
1103
+ return (React.createElement(StyleSheetContext.Provider, { value: styleSheet },
1104
+ React.createElement(StylisContext.Provider, { value: stylis }, process.env.NODE_ENV !== 'production'
1105
+ ? React.Children.only(props.children)
1103
1106
  : props.children)));
1104
1107
  }
1105
1108
 
@@ -1133,7 +1136,7 @@ function addUnitIfNeeded(name, value) {
1133
1136
  if (value == null || typeof value === 'boolean' || value === '') {
1134
1137
  return '';
1135
1138
  }
1136
- if (typeof value === 'number' && value !== 0 && !(name in unitless__default["default"])) {
1139
+ if (typeof value === 'number' && value !== 0 && !(name in unitless)) {
1137
1140
  return "".concat(value, "px"); // Presumes implicit 'px' suffix for unitless numbers
1138
1141
  }
1139
1142
  return String(value).trim();
@@ -1340,7 +1343,7 @@ var ComponentStyle = /** @class */ (function () {
1340
1343
  return ComponentStyle;
1341
1344
  }());
1342
1345
 
1343
- var ThemeContext = React__default["default"].createContext(undefined);
1346
+ var ThemeContext = React.createContext(undefined);
1344
1347
  var ThemeConsumer = ThemeContext.Consumer;
1345
1348
  function mergeTheme(theme, outerTheme) {
1346
1349
  if (!theme) {
@@ -1369,7 +1372,7 @@ function ThemeProvider(props) {
1369
1372
  if (!props.children) {
1370
1373
  return null;
1371
1374
  }
1372
- return React__default["default"].createElement(ThemeContext.Provider, { value: themeContext }, props.children);
1375
+ return React.createElement(ThemeContext.Provider, { value: themeContext }, props.children);
1373
1376
  }
1374
1377
 
1375
1378
  var identifiers = {};
@@ -1491,7 +1494,7 @@ function createStyledComponent(target, options, rules) {
1491
1494
  * forwardRef creates a new interim component, which we'll take advantage of
1492
1495
  * instead of extending ParentComponent to create _another_ interim class
1493
1496
  */
1494
- var WrappedStyledComponent = React__default["default"].forwardRef(forwardRef);
1497
+ var WrappedStyledComponent = React.forwardRef(forwardRef);
1495
1498
  WrappedStyledComponent.attrs = finalAttrs;
1496
1499
  WrappedStyledComponent.componentStyle = componentStyle;
1497
1500
  WrappedStyledComponent.displayName = displayName;
@@ -1504,13 +1507,6 @@ function createStyledComponent(target, options, rules) {
1504
1507
  WrappedStyledComponent.styledComponentId = styledComponentId;
1505
1508
  // fold the underlying StyledComponent target up since we folded the styles
1506
1509
  WrappedStyledComponent.target = isTargetStyledComp ? styledComponentTarget.target : target;
1507
- WrappedStyledComponent.withComponent = function withComponent(tag) {
1508
- var previousComponentId = options.componentId, optionsToCopy = tslib.__rest(options, ["componentId"]);
1509
- var newComponentId = previousComponentId &&
1510
- "".concat(previousComponentId, "-").concat(isTag(tag) ? tag : escape(getComponentName(tag)));
1511
- var newOptions = tslib.__assign(tslib.__assign({}, optionsToCopy), { attrs: finalAttrs, componentId: newComponentId });
1512
- return createStyledComponent(tag, newOptions, rules);
1513
- };
1514
1510
  Object.defineProperty(WrappedStyledComponent, 'defaultProps', {
1515
1511
  get: function () {
1516
1512
  return this._foldedDefaultProps;
@@ -1537,7 +1533,6 @@ function createStyledComponent(target, options, rules) {
1537
1533
  shouldForwardProp: true,
1538
1534
  styledComponentId: true,
1539
1535
  target: true,
1540
- withComponent: true,
1541
1536
  });
1542
1537
  }
1543
1538
  return WrappedStyledComponent;
@@ -1660,10 +1655,10 @@ function createGlobalStyle(strings) {
1660
1655
  var GlobalStyleComponent = function (props) {
1661
1656
  var styleSheet = useStyleSheet();
1662
1657
  var stylis = useStylis();
1663
- var theme = React__default["default"].useContext(ThemeContext);
1664
- var instanceRef = React__default["default"].useRef(styleSheet.allocateGSInstance(styledComponentId));
1658
+ var theme = React.useContext(ThemeContext);
1659
+ var instanceRef = React.useRef(styleSheet.allocateGSInstance(styledComponentId));
1665
1660
  var instance = instanceRef.current;
1666
- if (process.env.NODE_ENV !== 'production' && React__default["default"].Children.count(props.children)) {
1661
+ if (process.env.NODE_ENV !== 'production' && React.Children.count(props.children)) {
1667
1662
  // eslint-disable-next-line no-console
1668
1663
  console.warn("The global style component ".concat(styledComponentId, " was given child JSX. createGlobalStyle does not render children."));
1669
1664
  }
@@ -1686,7 +1681,7 @@ function createGlobalStyle(strings) {
1686
1681
  globalStyle.renderStyles(instance, context, styleSheet, stylis);
1687
1682
  }
1688
1683
  }
1689
- return React__default["default"].memo(GlobalStyleComponent);
1684
+ return React.memo(GlobalStyleComponent);
1690
1685
  }
1691
1686
 
1692
1687
  function keyframes(strings) {
@@ -1707,14 +1702,14 @@ function keyframes(strings) {
1707
1702
  }
1708
1703
 
1709
1704
  function withTheme(Component) {
1710
- var WithTheme = React__default["default"].forwardRef(function (props, ref) {
1711
- var theme = React__default["default"].useContext(ThemeContext);
1705
+ var WithTheme = React.forwardRef(function (props, ref) {
1706
+ var theme = React.useContext(ThemeContext);
1712
1707
  var themeProp = determineTheme(props, theme, Component.defaultProps);
1713
1708
  if (process.env.NODE_ENV !== 'production' && themeProp === undefined) {
1714
1709
  // eslint-disable-next-line no-console
1715
1710
  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), "\""));
1716
1711
  }
1717
- return React__default["default"].createElement(Component, tslib.__assign({}, props, { theme: themeProp, ref: ref }));
1712
+ return React.createElement(Component, tslib.__assign({}, props, { theme: themeProp, ref: ref }));
1718
1713
  });
1719
1714
  WithTheme.displayName = "WithTheme(".concat(getComponentName(Component), ")");
1720
1715
  return hoistNonReactStatics(WithTheme, Component);
@@ -1760,7 +1755,7 @@ var ServerStyleSheet = /** @class */ (function () {
1760
1755
  props.nonce = nonce;
1761
1756
  }
1762
1757
  // v4 returned an array for this fn, so we'll do the same for v5 for backward compat
1763
- return [React__default["default"].createElement("style", tslib.__assign({}, props, { key: "sc-0-0" }))];
1758
+ return [React.createElement("style", tslib.__assign({}, props, { key: "sc-0-0" }))];
1764
1759
  };
1765
1760
  this.seal = function () {
1766
1761
  _this.sealed = true;
@@ -1772,7 +1767,7 @@ var ServerStyleSheet = /** @class */ (function () {
1772
1767
  if (this.sealed) {
1773
1768
  throw throwStyledComponentsError(2);
1774
1769
  }
1775
- return React__default["default"].createElement(StyleSheetManager, { sheet: this.instance }, children);
1770
+ return React.createElement(StyleSheetManager, { sheet: this.instance }, children);
1776
1771
  };
1777
1772
  // eslint-disable-next-line consistent-return
1778
1773
  // @ts-expect-error alternate return types are not possible due to code transformation
@@ -1854,9 +1849,10 @@ exports.ThemeProvider = ThemeProvider;
1854
1849
  exports.__PRIVATE__ = __PRIVATE__;
1855
1850
  exports.createGlobalStyle = createGlobalStyle;
1856
1851
  exports.css = css;
1857
- exports["default"] = styled;
1852
+ exports.default = styled;
1858
1853
  exports.isStyledComponent = isStyledComponent;
1859
1854
  exports.keyframes = keyframes;
1855
+ exports.styled = styled;
1860
1856
  exports.useTheme = useTheme;
1861
1857
  exports.version = SC_VERSION;
1862
1858
  exports.withTheme = withTheme;