styled-components 6.4.0-prerelease.7 → 6.4.0-prerelease.9

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 (49) hide show
  1. package/README.md +4 -0
  2. package/dist/constructors/createGlobalStyle.d.ts +10 -0
  3. package/dist/constructors/css.d.ts +12 -0
  4. package/dist/constructors/keyframes.d.ts +11 -0
  5. package/dist/constructors/styled.d.ts +8 -0
  6. package/dist/hoc/withTheme.d.ts +1 -0
  7. package/dist/models/InlineStyle.d.ts +11 -0
  8. package/dist/models/ServerStyleSheet.d.ts +10 -0
  9. package/dist/models/StyleSheetManager.d.ts +1 -0
  10. package/dist/native/index.d.ts +18 -2
  11. package/dist/styled-components.browser.cjs.js +1 -1
  12. package/dist/styled-components.browser.cjs.js.map +1 -1
  13. package/dist/styled-components.browser.esm.js +2 -2
  14. package/dist/styled-components.browser.esm.js.map +1 -1
  15. package/dist/styled-components.cjs.js +1 -1
  16. package/dist/styled-components.cjs.js.map +1 -1
  17. package/dist/styled-components.esm.js +1 -1
  18. package/dist/styled-components.esm.js.map +1 -1
  19. package/dist/styled-components.js +58 -7
  20. package/dist/styled-components.js.map +1 -1
  21. package/dist/styled-components.min.js +2 -2
  22. package/dist/styled-components.min.js.map +1 -1
  23. package/dist/utils/isStyledComponent.d.ts +1 -0
  24. package/native/dist/constructors/createGlobalStyle.d.ts +10 -0
  25. package/native/dist/constructors/css.d.ts +12 -0
  26. package/native/dist/constructors/keyframes.d.ts +11 -0
  27. package/native/dist/constructors/styled.d.ts +8 -0
  28. package/native/dist/dist/constructors/createGlobalStyle.d.ts +10 -0
  29. package/native/dist/dist/constructors/css.d.ts +12 -0
  30. package/native/dist/dist/constructors/keyframes.d.ts +11 -0
  31. package/native/dist/dist/constructors/styled.d.ts +8 -0
  32. package/native/dist/dist/hoc/withTheme.d.ts +1 -0
  33. package/native/dist/dist/models/InlineStyle.d.ts +11 -0
  34. package/native/dist/dist/models/ServerStyleSheet.d.ts +10 -0
  35. package/native/dist/dist/models/StyleSheetManager.d.ts +1 -0
  36. package/native/dist/dist/native/index.d.ts +18 -2
  37. package/native/dist/dist/utils/isStyledComponent.d.ts +1 -0
  38. package/native/dist/hoc/withTheme.d.ts +1 -0
  39. package/native/dist/models/InlineStyle.d.ts +11 -0
  40. package/native/dist/models/ServerStyleSheet.d.ts +10 -0
  41. package/native/dist/models/StyleSheetManager.d.ts +1 -0
  42. package/native/dist/native/index.d.ts +18 -2
  43. package/native/dist/styled-components.native.cjs.js +1 -1
  44. package/native/dist/styled-components.native.cjs.js.map +1 -1
  45. package/native/dist/styled-components.native.esm.js +1 -1
  46. package/native/dist/styled-components.native.esm.js.map +1 -1
  47. package/native/dist/utils/isStyledComponent.d.ts +1 -0
  48. package/native/package.json +7 -2
  49. package/package.json +4 -5
@@ -11,7 +11,7 @@
11
11
  'data-styled';
12
12
  const SC_ATTR_ACTIVE = 'active';
13
13
  const SC_ATTR_VERSION = 'data-styled-version';
14
- const SC_VERSION = "6.4.0-prerelease.7";
14
+ const SC_VERSION = "6.4.0-prerelease.9";
15
15
  const SPLITTER = '/*!sc*/\n';
16
16
  const IS_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';
17
17
  function readSpeedyFlag(name) {
@@ -723,6 +723,7 @@
723
723
  return isFunction(test) && !(test.prototype && test.prototype.isReactComponent);
724
724
  }
725
725
 
726
+ /** Type guard that returns true if the target is a styled component. */
726
727
  function isStyledComponent(target) {
727
728
  return typeof target === 'object' && 'styledComponentId' in target;
728
729
  }
@@ -1292,6 +1293,7 @@
1292
1293
  function useStyleSheetContext() {
1293
1294
  return React.useContext(StyleSheetContext);
1294
1295
  }
1296
+ /** Configure style injection for descendant styled components (target element, stylis plugins, prop forwarding). */
1295
1297
  function StyleSheetManager(props) {
1296
1298
  // In RSC environments without context support, StyleSheetManager becomes a no-op
1297
1299
  if (!React.useMemo) {
@@ -1482,6 +1484,16 @@
1482
1484
  return addTag(flatten(interleave(styleStringArray, interpolations)));
1483
1485
  }
1484
1486
 
1487
+ /**
1488
+ * Create a component that injects global CSS when mounted. Supports theming and dynamic props.
1489
+ *
1490
+ * ```tsx
1491
+ * const GlobalStyle = createGlobalStyle`
1492
+ * body { margin: 0; font-family: system-ui; }
1493
+ * `;
1494
+ * // Render <GlobalStyle /> at the root of your app
1495
+ * ```
1496
+ */
1485
1497
  function createGlobalStyle(strings, ...interpolations) {
1486
1498
  const rules = css(strings, ...interpolations);
1487
1499
  const styledComponentId = `sc-global-${generateComponentId(JSON.stringify(rules))}`;
@@ -1527,16 +1539,23 @@
1527
1539
  // Client-side lifecycle: render styles in effect and clean up on unmount.
1528
1540
  // false and IS_RSC are build/module-level constants, so this doesn't violate rules of hooks.
1529
1541
  {
1530
- // For static global styles, renderStyles exits early after the first injection
1531
- // (via hasNameForId check in GlobalStyle.renderStyles). We still need the effect
1532
- // for initial injection and unmount cleanup, but we use a narrow deps array
1533
- // to avoid unnecessary effect re-runs on every render.
1542
+ // globalStyle is included in deps so HMR-induced module re-evaluation
1543
+ // (which creates a new GlobalStyle instance) triggers effect re-run.
1544
+ // For static rules, renderStyles exits early after the first injection
1545
+ // (via hasNameForId check), so the extra dep is effectively free at runtime.
1534
1546
  // eslint-disable-next-line react-hooks/exhaustive-deps
1535
1547
  const effectDeps = globalStyle.isStatic
1536
- ? [instance, ssc.styleSheet]
1537
- : [instance, props, ssc.styleSheet, theme, ssc.stylis];
1548
+ ? [instance, ssc.styleSheet, globalStyle]
1549
+ : [instance, props, ssc.styleSheet, theme, ssc.stylis, globalStyle];
1550
+ const prevGlobalStyleRef = React.useRef(globalStyle);
1538
1551
  React.useLayoutEffect(() => {
1539
1552
  if (!ssc.styleSheet.server) {
1553
+ // HMR creates a new globalStyle instance but the componentId stays stable
1554
+ // (SWC plugin assigns by file location), so stale hasNameForId hits skip injection.
1555
+ if (prevGlobalStyleRef.current !== globalStyle) {
1556
+ ssc.styleSheet.clearRules(styledComponentId);
1557
+ prevGlobalStyleRef.current = globalStyle;
1558
+ }
1540
1559
  renderStyles(instance, props, ssc.styleSheet, theme, ssc.stylis);
1541
1560
  }
1542
1561
  return () => {
@@ -1713,6 +1732,17 @@
1713
1732
  }
1714
1733
  _a = KEYFRAMES_SYMBOL;
1715
1734
 
1735
+ /**
1736
+ * Define a CSS `@keyframes` animation with an automatically scoped name.
1737
+ *
1738
+ * ```tsx
1739
+ * const rotate = keyframes`
1740
+ * from { transform: rotate(0deg); }
1741
+ * to { transform: rotate(360deg); }
1742
+ * `;
1743
+ * const Spinner = styled.div`animation: ${rotate} 1s linear infinite;`;
1744
+ * ```
1745
+ */
1716
1746
  function keyframes(strings, ...interpolations) {
1717
1747
  /* Warning if you've used keyframes on React Native */
1718
1748
  if (typeof navigator !== 'undefined' &&
@@ -1818,6 +1848,7 @@
1818
1848
  return targetComponent;
1819
1849
  }
1820
1850
 
1851
+ /** Higher-order component that injects the current theme as a prop. Prefer `useTheme` in function components. */
1821
1852
  function withTheme(Component) {
1822
1853
  const WithTheme = React.forwardRef((props, ref) => {
1823
1854
  const theme = React.useContext(ThemeContext) ;
@@ -1831,6 +1862,16 @@
1831
1862
  return hoistNonReactStatics(WithTheme, Component);
1832
1863
  }
1833
1864
 
1865
+ /**
1866
+ * Collect styled-components CSS during server-side rendering.
1867
+ *
1868
+ * ```tsx
1869
+ * const sheet = new ServerStyleSheet();
1870
+ * const html = renderToString(sheet.collectStyles(<App />));
1871
+ * const styleTags = sheet.getStyleTags();
1872
+ * sheet.seal();
1873
+ * ```
1874
+ */
1834
1875
  class ServerStyleSheet {
1835
1876
  constructor({ nonce } = {}) {
1836
1877
  this._emitSheetCSS = () => {
@@ -2226,6 +2267,7 @@
2226
2267
  prev[1] === theme &&
2227
2268
  prev[2] === ssc.styleSheet &&
2228
2269
  prev[3] === ssc.stylis &&
2270
+ prev[7] === componentStyle &&
2229
2271
  shallowEqualContext(prev[0], props, prev[4])) {
2230
2272
  context = prev[5];
2231
2273
  generatedClassName = prev[6];
@@ -2246,6 +2288,7 @@
2246
2288
  propsKeyCount,
2247
2289
  context,
2248
2290
  generatedClassName,
2291
+ componentStyle,
2249
2292
  ];
2250
2293
  }
2251
2294
  }
@@ -2377,6 +2420,14 @@
2377
2420
  return templateFunction;
2378
2421
  }
2379
2422
 
2423
+ /**
2424
+ * Create a styled component from an HTML element or React component.
2425
+ *
2426
+ * ```tsx
2427
+ * const Button = styled.button`color: red;`;
2428
+ * const Link = styled(RouterLink)`text-decoration: none;`;
2429
+ * ```
2430
+ */
2380
2431
  const baseStyled = (tag) => constructWithOptions(createStyledComponent, tag);
2381
2432
  const styled = baseStyled;
2382
2433
  // Shorthands for all valid HTML Elements