@octanejs/styled-components 0.1.0

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +103 -0
  3. package/package.json +60 -0
  4. package/src/constants.ts +46 -0
  5. package/src/constructors/constructWithOptions.ts +171 -0
  6. package/src/constructors/createGlobalStyle.ts +165 -0
  7. package/src/constructors/createTheme.ts +233 -0
  8. package/src/constructors/css.ts +64 -0
  9. package/src/constructors/keyframes.ts +36 -0
  10. package/src/constructors/styled.ts +52 -0
  11. package/src/hoc/withTheme.ts +40 -0
  12. package/src/index.ts +111 -0
  13. package/src/models/ComponentStyle.ts +171 -0
  14. package/src/models/GlobalStyle.ts +129 -0
  15. package/src/models/Keyframes.ts +66 -0
  16. package/src/models/ServerStyleSheet.ts +92 -0
  17. package/src/models/StyleSheetManager.ts +210 -0
  18. package/src/models/StyledComponent.ts +346 -0
  19. package/src/models/ThemeProvider.ts +124 -0
  20. package/src/secretInternals.ts +7 -0
  21. package/src/sheet/GroupIDAllocator.ts +45 -0
  22. package/src/sheet/GroupedTag.ts +125 -0
  23. package/src/sheet/Rehydration.ts +188 -0
  24. package/src/sheet/RuleOutput.ts +66 -0
  25. package/src/sheet/Sheet.ts +162 -0
  26. package/src/sheet/Tag.ts +135 -0
  27. package/src/sheet/dom.ts +64 -0
  28. package/src/sheet/index.ts +2 -0
  29. package/src/sheet/octaneChannel.ts +57 -0
  30. package/src/sheet/types.ts +56 -0
  31. package/src/types.ts +294 -0
  32. package/src/utils/addUnitIfNeeded.ts +59 -0
  33. package/src/utils/charCodes.ts +18 -0
  34. package/src/utils/checkDynamicCreation.ts +28 -0
  35. package/src/utils/createWarnTooManyClasses.ts +33 -0
  36. package/src/utils/cssTagged.ts +3 -0
  37. package/src/utils/determineTheme.ts +10 -0
  38. package/src/utils/domElements.ts +7 -0
  39. package/src/utils/empties.ts +4 -0
  40. package/src/utils/error.ts +41 -0
  41. package/src/utils/errors.ts +20 -0
  42. package/src/utils/escape.ts +11 -0
  43. package/src/utils/flatten.ts +175 -0
  44. package/src/utils/generateAlphabeticName.ts +21 -0
  45. package/src/utils/generateComponentId.ts +6 -0
  46. package/src/utils/generateDisplayName.ts +7 -0
  47. package/src/utils/getComponentName.ts +10 -0
  48. package/src/utils/hash.ts +26 -0
  49. package/src/utils/hoist.ts +83 -0
  50. package/src/utils/hyphenateStyleName.ts +33 -0
  51. package/src/utils/interleave.ts +14 -0
  52. package/src/utils/isFunction.ts +3 -0
  53. package/src/utils/isKeyframes.ts +9 -0
  54. package/src/utils/isPlainObject.ts +11 -0
  55. package/src/utils/isStatelessFunction.ts +5 -0
  56. package/src/utils/isStaticRules.ts +17 -0
  57. package/src/utils/isStyledComponent.ts +19 -0
  58. package/src/utils/isTag.ts +10 -0
  59. package/src/utils/joinStrings.ts +26 -0
  60. package/src/utils/mixinDeep.ts +34 -0
  61. package/src/utils/nonce.ts +33 -0
  62. package/src/utils/setToString.ts +19 -0
  63. package/src/utils/stylis.ts +378 -0
@@ -0,0 +1,233 @@
1
+ import { IS_BROWSER } from '../constants';
2
+ import createGlobalStyle from './createGlobalStyle';
3
+
4
+ type ThemeLeaf = string | number;
5
+
6
+ /**
7
+ * Recursively maps a theme object so every leaf value becomes
8
+ * a `var(--sc-path, fallback)` CSS string.
9
+ */
10
+ type CSSVarTheme<T> = {
11
+ [K in keyof T]: T[K] extends ThemeLeaf ? string : CSSVarTheme<T[K]>;
12
+ };
13
+
14
+ /**
15
+ * The object returned by `createTheme`. Same shape as the input theme but
16
+ * every leaf is a CSS `var()` reference. Also carries a `GlobalStyle`
17
+ * component and the original `raw` theme object.
18
+ */
19
+ type ThemeContract<T> = CSSVarTheme<T> & {
20
+ /**
21
+ * A `createGlobalStyle` component that emits `:root` CSS custom properties
22
+ * from the current ThemeProvider context. Mount this once at the root of
23
+ * your app so RSC components can consume theme values via CSS variables.
24
+ */
25
+ GlobalStyle: ReturnType<typeof createGlobalStyle>;
26
+ /** The original theme object, for passing to `ThemeProvider`. */
27
+ raw: T;
28
+ /**
29
+ * Same shape as the theme but every leaf is the bare CSS custom property
30
+ * name (e.g. `"--sc-colors-primary"`). Useful for building dark mode
31
+ * overrides without hand-writing variable names.
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * const { vars } = createTheme({ colors: { bg: '#fff', text: '#000' } });
36
+ * vars.colors.bg // "--sc-colors-bg"
37
+ *
38
+ * const DarkMode = createGlobalStyle`
39
+ * .dark {
40
+ * ${vars.colors.bg}: #111;
41
+ * ${vars.colors.text}: #eee;
42
+ * }
43
+ * `;
44
+ * ```
45
+ */
46
+ vars: CSSVarTheme<T>;
47
+ /**
48
+ * Read the current resolved CSS variable values from the DOM and return
49
+ * an object with the same shape as the original theme. Each leaf is the
50
+ * computed value (e.g. `"#0070f3"`), not the `var()` reference.
51
+ *
52
+ * Optionally pass a target element to read scoped variables from
53
+ * (defaults to `document.documentElement`).
54
+ *
55
+ * Client-only - throws if called on the server.
56
+ */
57
+ resolve(el?: Element): T;
58
+ };
59
+
60
+ /** Shared recursive traversal - calls `leafFn` for each leaf, recurses for objects. */
61
+ function walkTheme(
62
+ obj: Record<string, any>,
63
+ varPrefix: string,
64
+ result: Record<string, any>,
65
+ leafFn: (fullPath: string, val: any, key: string) => any,
66
+ path?: string,
67
+ ): void {
68
+ for (const key in obj) {
69
+ const val = obj[key];
70
+ const fullPath = path ? path + '-' + key : key;
71
+ if (typeof val === 'object' && val !== null) {
72
+ const nested: Record<string, any> = {};
73
+ walkTheme(val, varPrefix, nested, leafFn, fullPath);
74
+ result[key] = nested;
75
+ } else {
76
+ result[key] = leafFn(fullPath, val, key);
77
+ }
78
+ }
79
+ }
80
+
81
+ /** Build bare CSS custom property names: `--prefix-a-b` */
82
+ function buildVarNames<T extends Record<string, any>>(obj: T, varPrefix: string): CSSVarTheme<T> {
83
+ const result: Record<string, any> = {};
84
+ walkTheme(obj, varPrefix, result, (fullPath) => '--' + varPrefix + fullPath);
85
+ return result as CSSVarTheme<T>;
86
+ }
87
+
88
+ /** Build `var(--prefix-a-b, fallback)` references with dev-mode parenthesis validation */
89
+ function buildVarRefs<T extends Record<string, any>>(obj: T, varPrefix: string): CSSVarTheme<T> {
90
+ const result: Record<string, any> = {};
91
+ walkTheme(obj, varPrefix, result, (fullPath, val) => {
92
+ if (process.env.NODE_ENV !== 'production') {
93
+ const str = String(val);
94
+ let depth = 0;
95
+ for (let i = 0; i < str.length; i++) {
96
+ if (str.charCodeAt(i) === 40) depth++;
97
+ else if (str.charCodeAt(i) === 41) depth--;
98
+ if (depth < 0) break;
99
+ }
100
+ if (depth !== 0) {
101
+ console.warn(
102
+ `createTheme: value "${str}" at "${fullPath}" contains unbalanced parentheses and may break the var() fallback`,
103
+ );
104
+ }
105
+ }
106
+ return 'var(--' + varPrefix + fullPath + ', ' + val + ')';
107
+ });
108
+ return result as CSSVarTheme<T>;
109
+ }
110
+
111
+ /** Read computed CSS variable values from the DOM */
112
+ function resolveVars<T extends Record<string, any>>(
113
+ obj: T,
114
+ varPrefix: string,
115
+ styles: CSSStyleDeclaration,
116
+ ): T {
117
+ const result: Record<string, any> = {};
118
+ walkTheme(obj, varPrefix, result, (fullPath, val) => {
119
+ const resolved = styles.getPropertyValue('--' + varPrefix + fullPath).trim();
120
+ return resolved || val;
121
+ });
122
+ return result as T;
123
+ }
124
+
125
+ /**
126
+ * Emit CSS var declarations by walking `shape` for structure and reading
127
+ * values from `theme`. This avoids hardcoded skip lists - only keys
128
+ * present in the original theme shape are traversed.
129
+ */
130
+ function emitVarDeclarations(
131
+ shape: Record<string, any>,
132
+ theme: Record<string, any>,
133
+ varPrefix: string,
134
+ path?: string,
135
+ ): string {
136
+ let css = '';
137
+ for (const key in shape) {
138
+ const shapeVal = shape[key];
139
+ const themeVal = theme[key];
140
+ const fullPath = path ? path + '-' + key : key;
141
+ if (typeof shapeVal === 'object' && shapeVal !== null) {
142
+ if (typeof themeVal === 'object' && themeVal !== null) {
143
+ css += emitVarDeclarations(shapeVal, themeVal, varPrefix, fullPath);
144
+ }
145
+ } else if (themeVal !== undefined && typeof themeVal !== 'function') {
146
+ css += '--' + varPrefix + fullPath + ':' + themeVal + ';';
147
+ }
148
+ }
149
+ return css;
150
+ }
151
+
152
+ interface CreateThemeOptions {
153
+ /**
154
+ * Prefix for CSS variable names. Defaults to `"sc"`.
155
+ * Useful for isolation when multiple design systems or microfrontends
156
+ * coexist on the same page.
157
+ *
158
+ * @example
159
+ * createTheme(theme, { prefix: 'ds' })
160
+ * // → var(--ds-colors-primary, #0070f3)
161
+ */
162
+ prefix?: string;
163
+
164
+ /**
165
+ * CSS selector for the variable declarations. Defaults to `":root"`.
166
+ * Use `":host"` for web components / Shadow DOM, or a class selector
167
+ * for scoped theming.
168
+ *
169
+ * @example
170
+ * createTheme(theme, { selector: ':host' })
171
+ * // → :host { --sc-colors-primary: #0070f3; }
172
+ */
173
+ selector?: string;
174
+ }
175
+
176
+ /**
177
+ * Create a theme backed by CSS custom properties, bridging `ThemeProvider` and CSS variables.
178
+ *
179
+ * Returns an object with the same shape as the input theme, but every leaf value
180
+ * is a `var(--prefix-*, fallback)` CSS string. Use these in styled component
181
+ * templates - they work in both client and RSC contexts.
182
+ *
183
+ * Mount the returned `GlobalStyle` component inside your `ThemeProvider` to emit
184
+ * the CSS variables. When the theme changes (e.g. light → dark), the variables
185
+ * update automatically.
186
+ *
187
+ * @example
188
+ * ```tsx
189
+ * const theme = createTheme({
190
+ * colors: { primary: '#0070f3', text: '#111' },
191
+ * });
192
+ *
193
+ * // Root layout (client):
194
+ * <ThemeProvider theme={themes[preset]}>
195
+ * <theme.GlobalStyle />
196
+ * {children}
197
+ * </ThemeProvider>
198
+ *
199
+ * // Any RSC file:
200
+ * const Card = styled.div`
201
+ * color: ${theme.colors.primary};
202
+ * // → "var(--sc-colors-primary, #0070f3)"
203
+ * `;
204
+ * ```
205
+ */
206
+ export default function createTheme<T extends Record<string, any>>(
207
+ defaultTheme: T,
208
+ options?: CreateThemeOptions,
209
+ ): ThemeContract<T> {
210
+ const pfx = (options?.prefix ?? 'sc') + '-';
211
+ const sel = options?.selector ?? ':root';
212
+ const varNames = buildVarNames(defaultTheme, pfx);
213
+ const varRefs = buildVarRefs(defaultTheme, pfx);
214
+
215
+ const GlobalStyle = createGlobalStyle`
216
+ ${sel} {
217
+ ${(p: { theme: Record<string, any> }) => emitVarDeclarations(defaultTheme, p.theme, pfx)}
218
+ }
219
+ `;
220
+
221
+ return Object.assign(varRefs, {
222
+ GlobalStyle,
223
+ raw: defaultTheme,
224
+ vars: varNames,
225
+ resolve(el?: Element): T {
226
+ if (!IS_BROWSER) {
227
+ throw new Error('createTheme.resolve() is client-only');
228
+ }
229
+ const target = el ?? document.documentElement;
230
+ return resolveVars(defaultTheme, pfx, getComputedStyle(target));
231
+ },
232
+ }) as ThemeContract<T>;
233
+ }
@@ -0,0 +1,64 @@
1
+ import { BaseObject, Interpolation, RuleSet, StyledObject, StyleFunction, Styles } from '../types';
2
+ import { EMPTY_ARRAY } from '../utils/empties';
3
+ import flatten from '../utils/flatten';
4
+ import interleave from '../utils/interleave';
5
+ import isFunction from '../utils/isFunction';
6
+ import isPlainObject from '../utils/isPlainObject';
7
+
8
+ import { cssTagged } from '../utils/cssTagged';
9
+
10
+ const addTag = <T extends RuleSet<any>>(arg: T): T & { isCss: true } => {
11
+ cssTagged.add(arg);
12
+ return arg as T & { isCss: true };
13
+ };
14
+
15
+ /**
16
+ * Tag a CSS template literal for use in styled components, createGlobalStyle, or attrs.
17
+ * Enables interpolation type-checking and shared style blocks.
18
+ *
19
+ * ```tsx
20
+ * const truncate = css`
21
+ * white-space: nowrap;
22
+ * overflow: hidden;
23
+ * text-overflow: ellipsis;
24
+ * `;
25
+ * ```
26
+ */
27
+ function css(styles: Styles<object>, ...interpolations: Interpolation<object>[]): RuleSet<object>;
28
+ function css<Props extends object>(
29
+ styles: Styles<NoInfer<Props>>,
30
+ ...interpolations: Interpolation<NoInfer<Props>>[]
31
+ ): RuleSet<NoInfer<Props>>;
32
+ function css<Props extends object = BaseObject>(
33
+ styles: Styles<NoInfer<Props>>,
34
+ ...interpolations: Interpolation<NoInfer<Props>>[]
35
+ ): RuleSet<NoInfer<Props>> {
36
+ if (isFunction(styles) || isPlainObject(styles)) {
37
+ const styleFunctionOrObject = styles as StyleFunction<Props> | StyledObject<Props>;
38
+
39
+ return addTag(
40
+ flatten<Props>(
41
+ interleave<Props>(EMPTY_ARRAY, [
42
+ styleFunctionOrObject,
43
+ ...interpolations,
44
+ ]) as Interpolation<object>,
45
+ ),
46
+ );
47
+ }
48
+
49
+ const styleStringArray = styles as TemplateStringsArray;
50
+
51
+ if (
52
+ interpolations.length === 0 &&
53
+ styleStringArray.length === 1 &&
54
+ typeof styleStringArray[0] === 'string'
55
+ ) {
56
+ return flatten<Props>(styleStringArray);
57
+ }
58
+
59
+ return addTag(
60
+ flatten<Props>(interleave<Props>(styleStringArray, interpolations) as Interpolation<object>),
61
+ );
62
+ }
63
+
64
+ export default css;
@@ -0,0 +1,36 @@
1
+ import Keyframes from '../models/Keyframes';
2
+ import { Interpolation, Styles } from '../types';
3
+ import generateComponentId from '../utils/generateComponentId';
4
+ import { joinStringArray } from '../utils/joinStrings';
5
+ import css from './css';
6
+
7
+ /**
8
+ * Define a CSS `@keyframes` animation with an automatically scoped name.
9
+ *
10
+ * ```tsx
11
+ * const rotate = keyframes`
12
+ * from { transform: rotate(0deg); }
13
+ * to { transform: rotate(360deg); }
14
+ * `;
15
+ * const Spinner = styled.div`animation: ${rotate} 1s linear infinite;`;
16
+ * ```
17
+ */
18
+ export default function keyframes<Props extends object = {}>(
19
+ strings: Styles<Props>,
20
+ ...interpolations: Array<Interpolation<Props>>
21
+ ): Keyframes {
22
+ /* Warning if you've used keyframes on React Native */
23
+ if (
24
+ process.env.NODE_ENV !== 'production' &&
25
+ typeof navigator !== 'undefined' &&
26
+ navigator.product === 'ReactNative'
27
+ ) {
28
+ console.warn(
29
+ '`keyframes` cannot be used on ReactNative, only on the web. To do animation in ReactNative please use Animated.',
30
+ );
31
+ }
32
+
33
+ const rules = joinStringArray(css<Props>(strings, ...interpolations) as string[]);
34
+ const name = generateComponentId(rules);
35
+ return new Keyframes(name, rules);
36
+ }
@@ -0,0 +1,52 @@
1
+ // Ported from styled-components 6.4.3 (MIT), adapted for octane: component
2
+ // targets infer props from their function signature (`TargetProps`) instead of
3
+ // `React.ComponentPropsWithRef`, and host tags rely on the permissive
4
+ // polymorphic call surface (octane has no `JSX.IntrinsicElements` map).
5
+ import createStyledComponent from '../models/StyledComponent';
6
+ import { BaseObject, KnownTarget, TargetProps, WebTarget } from '../types';
7
+ import domElements, { SupportedHTMLElements } from '../utils/domElements';
8
+ import constructWithOptions, { Styled as StyledInstance } from './constructWithOptions';
9
+
10
+ /**
11
+ * Create a styled component from an HTML element or octane component.
12
+ *
13
+ * ```tsx
14
+ * const Button = styled.button`color: red;`;
15
+ * const Link = styled(RouterLink)`text-decoration: none;`;
16
+ * ```
17
+ */
18
+ const baseStyled = <Target extends WebTarget, InjectedProps extends object = BaseObject>(
19
+ tag: Target,
20
+ ) =>
21
+ constructWithOptions<
22
+ 'web',
23
+ Target,
24
+ Target extends KnownTarget ? TargetProps<Target> & InjectedProps : InjectedProps
25
+ >(createStyledComponent, tag);
26
+
27
+ const styled = baseStyled as typeof baseStyled & {
28
+ [E in SupportedHTMLElements]: StyledInstance<'web', E, BaseObject>;
29
+ };
30
+
31
+ // Shorthands for all valid HTML Elements.
32
+ // The type assertion avoids 120 Styled<> instantiations during type checking -
33
+ // the correct types are declared on the `styled` const above via the mapped type.
34
+ domElements.forEach((domElement) => {
35
+ (styled as any)[domElement] = baseStyled(domElement);
36
+ });
37
+
38
+ export default styled;
39
+ export type { StyledInstance };
40
+
41
+ /**
42
+ * This is the type of the `styled` HOC.
43
+ */
44
+ export type Styled = typeof styled;
45
+
46
+ /**
47
+ * Use this higher-order type for scenarios where you are wrapping `styled`
48
+ * and providing extra props as a third-party library.
49
+ */
50
+ export type LibraryStyled<LibraryProps extends object = BaseObject> = <Target extends WebTarget>(
51
+ tag: Target,
52
+ ) => typeof baseStyled<Target, LibraryProps>;
@@ -0,0 +1,40 @@
1
+ // Ported from styled-components 6.4.3 (MIT), adapted for octane: no
2
+ // forwardRef — the wrapper is a plain component and any `ref` prop flows
3
+ // through the spread to the wrapped component (octane refs are plain props).
4
+ import { createElement, useContext } from 'octane';
5
+
6
+ import { ThemeContext } from '../models/ThemeProvider';
7
+ import { AnyComponent, ExecutionProps } from '../types';
8
+ import determineTheme from '../utils/determineTheme';
9
+ import getComponentName from '../utils/getComponentName';
10
+ import hoist, { NonOctaneStatics } from '../utils/hoist';
11
+
12
+ /** Higher-order component that injects the current theme as a prop. Prefer `useTheme` in function components. */
13
+ export default function withTheme<T extends AnyComponent>(
14
+ Component: T,
15
+ ): ((props: ExecutionProps & { [key: string]: any }) => unknown) & NonOctaneStatics<T> {
16
+ const WithTheme = (props: ExecutionProps & { [key: string]: any }, _scope?: any) => {
17
+ const theme = useContext(ThemeContext);
18
+ const themeProp = determineTheme(props, theme, (Component as any).defaultProps);
19
+
20
+ if (process.env.NODE_ENV !== 'production' && themeProp === undefined) {
21
+ console.warn(
22
+ `[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps in component class "${getComponentName(
23
+ Component,
24
+ )}"`,
25
+ );
26
+ }
27
+
28
+ return createElement(Component as any, {
29
+ ...props,
30
+ theme: themeProp,
31
+ });
32
+ };
33
+
34
+ WithTheme.displayName = `WithTheme(${getComponentName(Component)})`;
35
+
36
+ return hoist(WithTheme as any, Component) as ((
37
+ props: ExecutionProps & { [key: string]: any },
38
+ ) => unknown) &
39
+ NonOctaneStatics<T>;
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,111 @@
1
+ // @octanejs/styled-components — styled-components 6.4.3 (MIT) ported to the
2
+ // octane renderer. The React Native surface and the RSC-only
3
+ // `stylisPluginRSC` are intentionally not ported.
4
+ import { SC_ATTR, SC_VERSION } from './constants';
5
+ import createGlobalStyle from './constructors/createGlobalStyle';
6
+ import createTheme from './constructors/createTheme';
7
+ import css from './constructors/css';
8
+ import keyframes from './constructors/keyframes';
9
+ import withTheme from './hoc/withTheme';
10
+ import ServerStyleSheet from './models/ServerStyleSheet';
11
+ import {
12
+ IStyleSheetContext,
13
+ IStyleSheetManager,
14
+ IStylisContext,
15
+ mainSheet,
16
+ StyleSheetConsumer,
17
+ StyleSheetContext,
18
+ StyleSheetManager,
19
+ } from './models/StyleSheetManager';
20
+ import ThemeProvider, { ThemeConsumer, ThemeContext, useTheme } from './models/ThemeProvider';
21
+ import styled from './constructors/styled';
22
+ import isStyledComponent from './utils/isStyledComponent';
23
+
24
+ export * from './secretInternals';
25
+ export type {
26
+ Attrs,
27
+ BaseObject,
28
+ CSSKeyframes,
29
+ CSSObject,
30
+ CSSProp,
31
+ CSSProperties,
32
+ CSSPropertiesWithVars,
33
+ CSSPseudos,
34
+ DataAttributes,
35
+ DefaultTheme,
36
+ Dict,
37
+ ExecutionContext,
38
+ ExecutionProps,
39
+ IStyledComponent,
40
+ IStyledComponentFactory,
41
+ IStyledStatics,
42
+ Interpolation,
43
+ Keyframes,
44
+ KnownTarget,
45
+ PolymorphicComponent,
46
+ PolymorphicCallProps,
47
+ RuleSet,
48
+ Runtime,
49
+ ShouldForwardProp,
50
+ StyledObject,
51
+ StyledOptions,
52
+ StyleFunction,
53
+ Styles,
54
+ StyledTarget,
55
+ Stringifier,
56
+ SupportedHTMLElements,
57
+ TargetProps,
58
+ WebTarget,
59
+ } from './types';
60
+ export type { Styled, LibraryStyled, StyledInstance } from './constructors/styled';
61
+ export type { IStyleSheetContext, IStyleSheetManager, IStylisContext };
62
+ export {
63
+ createGlobalStyle,
64
+ createTheme,
65
+ css,
66
+ isStyledComponent,
67
+ keyframes,
68
+ ServerStyleSheet,
69
+ StyleSheetConsumer,
70
+ StyleSheetContext,
71
+ StyleSheetManager,
72
+ styled,
73
+ ThemeConsumer,
74
+ ThemeContext,
75
+ ThemeProvider,
76
+ useTheme,
77
+ withTheme,
78
+ };
79
+ export default styled;
80
+
81
+ export const version = SC_VERSION;
82
+
83
+ if (process.env.NODE_ENV !== 'production' && typeof navigator !== 'undefined') {
84
+ if ((navigator as any).product === 'ReactNative') {
85
+ console.warn(
86
+ "It looks like you've imported '@octanejs/styled-components' on React Native.\n" +
87
+ 'The octane port only supports the web surface; the React Native runtime is not ported.',
88
+ );
89
+ }
90
+ }
91
+
92
+ const windowGlobalKey = `__sc-${SC_ATTR}__`;
93
+ if (
94
+ process.env.NODE_ENV !== 'production' &&
95
+ process.env.NODE_ENV !== 'test' &&
96
+ typeof window !== 'undefined'
97
+ ) {
98
+ const anyWindow = window as any;
99
+ if (!anyWindow[windowGlobalKey]) anyWindow[windowGlobalKey] = 0;
100
+
101
+ if (anyWindow[windowGlobalKey] === 1) {
102
+ console.warn(
103
+ "It looks like there are several instances of 'styled-components' initialized in this application. " +
104
+ 'This may cause dynamic styles to not render properly, errors during the rehydration process, ' +
105
+ 'a missing theme prop, and makes your application bigger without good reason.\n\n' +
106
+ 'See https://styled-components.com/docs/faqs#why-am-i-getting-a-warning-about-several-instances-of-module-on-the-page for more info.',
107
+ );
108
+ }
109
+
110
+ anyWindow[windowGlobalKey] += 1;
111
+ }