styled-components 4.4.0 → 4.4.1
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.
- package/README.md +24 -2
- package/dist/styled-components.browser.cjs.js +6 -22
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +6 -22
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +6 -22
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +6 -22
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +6 -22
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +1 -1
- package/native/dist/styled-components.native.cjs.js +11 -8
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js +32 -28
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/package.json +1 -1
- package/primitives/dist/styled-components-primitives.cjs.js +4 -4
- package/primitives/dist/styled-components-primitives.esm.js +4 -4
package/README.md
CHANGED
|
@@ -20,17 +20,39 @@
|
|
|
20
20
|
<br />
|
|
21
21
|
|
|
22
22
|
> ⚠️ **CANARY:** This is the `canary` branch of `styled-components`. It is published under the
|
|
23
|
-
> `@
|
|
23
|
+
> `@beta` tag on npm and contains new features and changes for the next major version.
|
|
24
24
|
|
|
25
25
|
Utilising [tagged template literals](https://www.styled-components.com/docs/advanced#tagged-template-literals) (a recent addition to JavaScript) and the [power of CSS](https://www.styled-components.com/docs/api#supported-css), `styled-components` allows you to write actual CSS code to style your components. It also removes the mapping between components and styles – using components as a low-level styling construct could not be easier!
|
|
26
26
|
|
|
27
|
+
```jsx
|
|
28
|
+
const Button = styled.button`
|
|
29
|
+
color: grey;
|
|
30
|
+
`;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Alternatively, you may use [style objects](https://www.styled-components.com/docs/advanced#style-objects). This allows for easy porting of CSS from inline styles, while still supporting the more advanced styled-components capabilities like component selectors and media queries.
|
|
34
|
+
|
|
35
|
+
```jsx
|
|
36
|
+
const Button = styled.button({
|
|
37
|
+
color: 'grey',
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Equivalent to:
|
|
42
|
+
|
|
43
|
+
```jsx
|
|
44
|
+
const Button = styled.button`
|
|
45
|
+
color: grey;
|
|
46
|
+
`;
|
|
47
|
+
```
|
|
48
|
+
|
|
27
49
|
`styled-components` is compatible with both React (for web) and React Native – meaning it's the perfect choice even for truly universal apps! See the [documentation about React Native](https://www.styled-components.com/docs/basics#react-native) for more information.
|
|
28
50
|
|
|
29
51
|
_Supported by [Front End Center](https://frontend.center). Thank you for making this possible!_
|
|
30
52
|
|
|
31
53
|
## Upgrading from v4
|
|
32
54
|
|
|
33
|
-
1. `npm install styled-components@
|
|
55
|
+
1. `npm install styled-components@beta react@^16.8 react-dom@^16.8 react-is@^16.8`
|
|
34
56
|
1. ??
|
|
35
57
|
1. Profit!
|
|
36
58
|
|
|
@@ -468,7 +468,7 @@ var makeStyleTag = function makeStyleTag(target, tagEl, insertBefore) {
|
|
|
468
468
|
|
|
469
469
|
var el = targetDocument.createElement('style');
|
|
470
470
|
el.setAttribute(SC_ATTR, '');
|
|
471
|
-
el.setAttribute(SC_VERSION_ATTR, "4.4.
|
|
471
|
+
el.setAttribute(SC_VERSION_ATTR, "4.4.1");
|
|
472
472
|
|
|
473
473
|
var nonce = getNonce();
|
|
474
474
|
if (nonce) {
|
|
@@ -497,7 +497,7 @@ var makeStyleTag = function makeStyleTag(target, tagEl, insertBefore) {
|
|
|
497
497
|
var wrapAsHtmlTag = function wrapAsHtmlTag(css, names) {
|
|
498
498
|
return function (additionalAttrs) {
|
|
499
499
|
var nonce = getNonce();
|
|
500
|
-
var attrs = [nonce && 'nonce="' + nonce + '"', SC_ATTR + '="' + stringifyNames(names) + '"', SC_VERSION_ATTR + '="' + "4.4.
|
|
500
|
+
var attrs = [nonce && 'nonce="' + nonce + '"', SC_ATTR + '="' + stringifyNames(names) + '"', SC_VERSION_ATTR + '="' + "4.4.1" + '"', additionalAttrs];
|
|
501
501
|
|
|
502
502
|
var htmlAttr = attrs.filter(Boolean).join(' ');
|
|
503
503
|
return '<style ' + htmlAttr + '>' + css() + '</style>';
|
|
@@ -509,7 +509,7 @@ var wrapAsElement = function wrapAsElement(css, names) {
|
|
|
509
509
|
return function () {
|
|
510
510
|
var _props;
|
|
511
511
|
|
|
512
|
-
var props = (_props = {}, _props[SC_ATTR] = stringifyNames(names), _props[SC_VERSION_ATTR] = "4.4.
|
|
512
|
+
var props = (_props = {}, _props[SC_ATTR] = stringifyNames(names), _props[SC_VERSION_ATTR] = "4.4.1", _props);
|
|
513
513
|
|
|
514
514
|
var nonce = getNonce();
|
|
515
515
|
if (nonce) {
|
|
@@ -918,7 +918,7 @@ var StyleSheet = function () {
|
|
|
918
918
|
var isStreamed = false;
|
|
919
919
|
|
|
920
920
|
/* retrieve all of our SSR style elements from the DOM */
|
|
921
|
-
var nodes = document.querySelectorAll('style[' + SC_ATTR + '][' + SC_VERSION_ATTR + '="' + "4.4.
|
|
921
|
+
var nodes = document.querySelectorAll('style[' + SC_ATTR + '][' + SC_VERSION_ATTR + '="' + "4.4.1" + '"]');
|
|
922
922
|
|
|
923
923
|
var nodesSize = nodes.length;
|
|
924
924
|
|
|
@@ -1922,7 +1922,6 @@ process.env.NODE_ENV !== "production" ? StyleSheetManager.propTypes = {
|
|
|
1922
1922
|
|
|
1923
1923
|
//
|
|
1924
1924
|
|
|
1925
|
-
var THEME_PROP_REGEX = /\.theme[.[]/;
|
|
1926
1925
|
var identifiers = {};
|
|
1927
1926
|
|
|
1928
1927
|
/* We depend on components having unique IDs */
|
|
@@ -2011,24 +2010,14 @@ var StyledComponent = function (_Component) {
|
|
|
2011
2010
|
displayName = _props$forwardedCompo.displayName,
|
|
2012
2011
|
foldedComponentIds = _props$forwardedCompo.foldedComponentIds,
|
|
2013
2012
|
styledComponentId = _props$forwardedCompo.styledComponentId,
|
|
2014
|
-
target = _props$forwardedCompo.target
|
|
2015
|
-
usesTheme = _props$forwardedCompo.usesTheme;
|
|
2013
|
+
target = _props$forwardedCompo.target;
|
|
2016
2014
|
|
|
2017
2015
|
|
|
2018
2016
|
var generatedClassName = void 0;
|
|
2019
|
-
var rawTheme = void 0;
|
|
2020
|
-
|
|
2021
2017
|
if (componentStyle.isStatic) {
|
|
2022
2018
|
generatedClassName = this.generateAndInjectStyles(EMPTY_OBJECT, this.props);
|
|
2023
2019
|
} else {
|
|
2024
|
-
|
|
2025
|
-
generatedClassName = this.generateAndInjectStyles(rawTheme || EMPTY_OBJECT, this.props);
|
|
2026
|
-
|
|
2027
|
-
if (process.env.NODE_ENV !== 'production' && usesTheme && !rawTheme) {
|
|
2028
|
-
console.error('Component \'' +
|
|
2029
|
-
// $FlowFixMe
|
|
2030
|
-
displayName + '\' (.' + styledComponentId + ') references the \'theme\' prop in its styles but no theme was provided via prop or <ThemeProvider>.');
|
|
2031
|
-
}
|
|
2020
|
+
generatedClassName = this.generateAndInjectStyles(determineTheme(this.props, theme, defaultProps) || EMPTY_OBJECT, this.props);
|
|
2032
2021
|
}
|
|
2033
2022
|
|
|
2034
2023
|
var elementToBeCreated = this.props.as || this.attrs.as || target;
|
|
@@ -2215,11 +2204,6 @@ function createStyledComponent(target, options, rules) {
|
|
|
2215
2204
|
});
|
|
2216
2205
|
|
|
2217
2206
|
if (process.env.NODE_ENV !== 'production') {
|
|
2218
|
-
// $FlowFixMe
|
|
2219
|
-
WrappedStyledComponent.usesTheme = componentStyle.rules.some(function (x) {
|
|
2220
|
-
return isFunction(x) && THEME_PROP_REGEX.test(x.toString());
|
|
2221
|
-
});
|
|
2222
|
-
|
|
2223
2207
|
// $FlowFixMe
|
|
2224
2208
|
WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName);
|
|
2225
2209
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled-components.browser.cjs.js","sources":["../src/models/StyleTags.js","../src/models/ThemeProvider.js","../src/models/StyleSheetManager.js","../src/models/StyledComponent.js","../src/models/GlobalStyle.js"],"sourcesContent":["// @flow\n/* eslint-disable flowtype/object-type-delimiter */\n/* eslint-disable react/prop-types */\n\nimport React, { type Element } from 'react';\nimport { IS_BROWSER, DISABLE_SPEEDY, SC_ATTR, SC_VERSION_ATTR } from '../constants';\nimport StyledError from '../utils/error';\nimport { type ExtractedComp } from '../utils/extractCompsFromCSS';\nimport { splitByRules } from '../utils/stringifyRules';\nimport getNonce from '../utils/nonce';\n\nimport {\n type Names,\n addNameForId,\n resetIdNames,\n hasNameForId,\n stringifyNames,\n cloneNames,\n} from '../utils/styleNames';\n\nimport { sheetForTag, safeInsertRule, deleteRules } from '../utils/insertRuleHelpers';\n\ndeclare var __VERSION__: string;\n\nexport interface Tag<T> {\n // $FlowFixMe: Doesn't seem to accept any combination w/ HTMLStyleElement for some reason\n styleTag: HTMLStyleElement | null;\n /* lists all ids of the tag */\n getIds(): string[];\n /* checks whether `name` is already injected for `id` */\n hasNameForId(id: string, name: string): boolean;\n /* inserts a marker to ensure the id's correct position in the sheet */\n insertMarker(id: string): T;\n /* inserts rules according to the ids markers */\n insertRules(id: string, cssRules: string[], name: ?string): void;\n /* removes all rules belonging to the id, keeping the marker around */\n removeRules(id: string): void;\n css(): string;\n toHTML(additionalAttrs: ?string): string;\n toElement(): Element<*>;\n clone(): Tag<T>;\n /* used in server side rendering to indicate that the rules in the tag have been flushed to HTML */\n sealed: boolean;\n}\n\n/* this marker separates component styles and is important for rehydration */\nconst makeTextMarker = id => `\\n/* sc-component-id: ${id} */\\n`;\n\n/* add up all numbers in array up until and including the index */\nconst addUpUntilIndex = (sizes: number[], index: number): number => {\n let totalUpToIndex = 0;\n for (let i = 0; i <= index; i += 1) {\n totalUpToIndex += sizes[i];\n }\n\n return totalUpToIndex;\n};\n\n/* create a new style tag after lastEl */\nconst makeStyleTag = (target: ?HTMLElement, tagEl: ?Node, insertBefore: ?boolean) => {\n let targetDocument = document;\n if(target) targetDocument = target.ownerDocument;\n else if(tagEl) targetDocument = tagEl.ownerDocument;\n\n const el = targetDocument.createElement('style');\n el.setAttribute(SC_ATTR, '');\n el.setAttribute(SC_VERSION_ATTR, __VERSION__);\n\n const nonce = getNonce();\n if (nonce) {\n el.setAttribute('nonce', nonce);\n }\n\n /* Work around insertRule quirk in EdgeHTML */\n el.appendChild(targetDocument.createTextNode(''));\n\n if (target && !tagEl) {\n /* Append to target when no previous element was passed */\n target.appendChild(el);\n } else {\n if (!tagEl || !target || !tagEl.parentNode) {\n throw new StyledError(6);\n }\n\n /* Insert new style tag after the previous one */\n tagEl.parentNode.insertBefore(el, insertBefore ? tagEl : tagEl.nextSibling);\n }\n\n return el;\n};\n\n/* takes a css factory function and outputs an html styled tag factory */\nconst wrapAsHtmlTag = (css: () => string, names: Names) => (additionalAttrs: ?string): string => {\n const nonce = getNonce();\n const attrs = [\n nonce && `nonce=\"${nonce}\"`,\n `${SC_ATTR}=\"${stringifyNames(names)}\"`,\n `${SC_VERSION_ATTR}=\"${__VERSION__}\"`,\n additionalAttrs,\n ];\n\n const htmlAttr = attrs.filter(Boolean).join(' ');\n return `<style ${htmlAttr}>${css()}</style>`;\n};\n\n/* takes a css factory function and outputs an element factory */\nconst wrapAsElement = (css: () => string, names: Names) => () => {\n const props = {\n [SC_ATTR]: stringifyNames(names),\n [SC_VERSION_ATTR]: __VERSION__,\n };\n\n const nonce = getNonce();\n if (nonce) {\n // $FlowFixMe\n props.nonce = nonce;\n }\n\n // eslint-disable-next-line react/no-danger\n return <style {...props} dangerouslySetInnerHTML={{ __html: css() }} />;\n};\n\nconst getIdsFromMarkersFactory = (markers: Object) => (): string[] => Object.keys(markers);\n\n/* speedy tags utilise insertRule */\nconst makeSpeedyTag = (el: HTMLStyleElement, getImportRuleTag: ?() => Tag<any>): Tag<number> => {\n const names: Names = (Object.create(null): Object);\n const markers = Object.create(null);\n const sizes: number[] = [];\n\n const extractImport = getImportRuleTag !== undefined;\n /* indicates whether getImportRuleTag was called */\n let usedImportRuleTag = false;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n markers[id] = sizes.length;\n sizes.push(0);\n resetIdNames(names, id);\n\n return markers[id];\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n const sheet = sheetForTag(el);\n const insertIndex = addUpUntilIndex(sizes, marker);\n\n let injectedRules = 0;\n const importRules = [];\n const cssRulesSize = cssRules.length;\n\n for (let i = 0; i < cssRulesSize; i += 1) {\n const cssRule = cssRules[i];\n let mayHaveImport = extractImport; /* @import rules are reordered to appear first */\n if (mayHaveImport && cssRule.indexOf('@import') !== -1) {\n importRules.push(cssRule);\n } else if (safeInsertRule(sheet, cssRule, insertIndex + injectedRules)) {\n mayHaveImport = false;\n injectedRules += 1;\n }\n }\n\n if (extractImport && importRules.length > 0) {\n usedImportRuleTag = true;\n // $FlowFixMe\n getImportRuleTag().insertRules(`${id}-import`, importRules);\n }\n\n sizes[marker] += injectedRules; /* add up no of injected rules */\n addNameForId(names, id, name);\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n // $FlowFixMe\n if (el.isConnected === false) return;\n\n const size = sizes[marker];\n const sheet = sheetForTag(el);\n const removalIndex = addUpUntilIndex(sizes, marker) - 1;\n deleteRules(sheet, removalIndex, size);\n sizes[marker] = 0;\n resetIdNames(names, id);\n\n if (extractImport && usedImportRuleTag) {\n // $FlowFixMe\n getImportRuleTag().removeRules(`${id}-import`);\n }\n };\n\n const css = () => {\n const { cssRules } = sheetForTag(el);\n let str = '';\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n str += makeTextMarker(id);\n const marker = markers[id];\n const end = addUpUntilIndex(sizes, marker);\n const size = sizes[marker];\n for (let i = end - size; i < end; i += 1) {\n const rule = cssRules[i];\n if (rule !== undefined) {\n str += rule.cssText;\n }\n }\n }\n\n return str;\n };\n\n return {\n clone() {\n throw new StyledError(5);\n },\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: el,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n};\n\nconst makeTextNode = (targetDocument, id) => targetDocument.createTextNode(makeTextMarker(id));\n\nconst makeBrowserTag = (el: HTMLStyleElement, getImportRuleTag: ?() => Tag<any>): Tag<Text> => {\n const names = (Object.create(null): Object);\n const markers = Object.create(null);\n\n const extractImport = getImportRuleTag !== undefined;\n\n /* indicates whether getImportRuleTag was called */\n let usedImportRuleTag = false;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n markers[id] = makeTextNode(el.ownerDocument, id);\n el.appendChild(markers[id]);\n names[id] = Object.create(null);\n\n return markers[id];\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n const importRules = [];\n const cssRulesSize = cssRules.length;\n\n for (let i = 0; i < cssRulesSize; i += 1) {\n const rule = cssRules[i];\n let mayHaveImport = extractImport;\n if (mayHaveImport && rule.indexOf('@import') !== -1) {\n importRules.push(rule);\n } else {\n mayHaveImport = false;\n const separator = i === cssRulesSize - 1 ? '' : ' ';\n marker.appendData(`${rule}${separator}`);\n }\n }\n\n addNameForId(names, id, name);\n\n if (extractImport && importRules.length > 0) {\n usedImportRuleTag = true;\n // $FlowFixMe\n getImportRuleTag().insertRules(`${id}-import`, importRules);\n }\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n\n /* create new empty text node and replace the current one */\n const newMarker = makeTextNode(el.ownerDocument, id);\n el.replaceChild(newMarker, marker);\n markers[id] = newMarker;\n resetIdNames(names, id);\n\n if (extractImport && usedImportRuleTag) {\n // $FlowFixMe\n getImportRuleTag().removeRules(`${id}-import`);\n }\n };\n\n const css = () => {\n let str = '';\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n str += markers[id].data;\n }\n\n return str;\n };\n\n return {\n clone() {\n throw new StyledError(5);\n },\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: el,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n};\n\nconst makeServerTag = (namesArg, markersArg): Tag<[string]> => {\n const names = namesArg === undefined ? (Object.create(null): Object) : namesArg;\n const markers = markersArg === undefined ? Object.create(null) : markersArg;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n return (markers[id] = ['']);\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n marker[0] += cssRules.join(' ');\n addNameForId(names, id, name);\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n marker[0] = '';\n resetIdNames(names, id);\n };\n\n const css = () => {\n let str = '';\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n const cssForId = markers[id][0];\n if (cssForId) {\n str += makeTextMarker(id) + cssForId;\n }\n }\n return str;\n };\n\n const clone = () => {\n const namesClone = cloneNames(names);\n const markersClone = Object.create(null);\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n markersClone[id] = [markers[id][0]];\n }\n\n return makeServerTag(namesClone, markersClone);\n };\n\n const tag = {\n clone,\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: null,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n\n return tag;\n};\n\nexport const makeTag = (\n target: ?HTMLElement,\n tagEl: ?HTMLStyleElement,\n forceServer?: boolean,\n insertBefore?: boolean,\n getImportRuleTag?: () => Tag<any>\n): Tag<any> => {\n if (IS_BROWSER && !forceServer) {\n const el = makeStyleTag(target, tagEl, insertBefore);\n\n if (DISABLE_SPEEDY) {\n return makeBrowserTag(el, getImportRuleTag);\n } else {\n return makeSpeedyTag(el, getImportRuleTag);\n }\n }\n\n return makeServerTag();\n};\n\nexport const rehydrate = (\n tag: Tag<any>,\n els: HTMLStyleElement[],\n extracted: ExtractedComp[]\n): void => {\n /* add all extracted components to the new tag */\n for (let i = 0, len = extracted.length; i < len; i += 1) {\n const { componentId, cssFromDOM } = extracted[i];\n const cssRules = splitByRules(cssFromDOM);\n tag.insertRules(componentId, cssRules);\n }\n\n /* remove old HTMLStyleElements, since they have been rehydrated */\n for (let i = 0, len = els.length; i < len; i += 1) {\n const el = els[i];\n if (el.parentNode) {\n el.parentNode.removeChild(el);\n }\n }\n};\n","// @flow\nimport React, { createContext, Component, type Element } from 'react';\nimport memoize from 'memoize-one';\nimport StyledError from '../utils/error';\nimport isFunction from '../utils/isFunction';\n\nexport type Theme = { [key: string]: mixed };\n\ntype Props = {\n children?: Element<any>,\n theme: Theme | ((outerTheme: Theme) => void),\n};\n\nexport const ThemeContext = createContext();\n\nexport const ThemeConsumer = ThemeContext.Consumer;\n\n/**\n * Provide a theme to an entire react component tree via context\n */\nexport default class ThemeProvider extends Component<Props> {\n getContext: (theme: Theme | ((outerTheme: Theme) => void), outerTheme?: Theme) => Theme;\n\n renderInner: Function;\n\n constructor(props: Props) {\n super(props);\n this.getContext = memoize(this.getContext.bind(this));\n this.renderInner = this.renderInner.bind(this);\n }\n\n render() {\n if (!this.props.children) return null;\n\n return <ThemeContext.Consumer>{this.renderInner}</ThemeContext.Consumer>;\n }\n\n renderInner(outerTheme?: Theme) {\n const context = this.getContext(this.props.theme, outerTheme);\n\n return (\n <ThemeContext.Provider value={context}>\n {this.props.children}\n </ThemeContext.Provider>\n );\n }\n\n /**\n * Get the theme from the props, supporting both (outerTheme) => {}\n * as well as object notation\n */\n getTheme(theme: (outerTheme: ?Theme) => void, outerTheme: ?Theme) {\n if (isFunction(theme)) {\n const mergedTheme = theme(outerTheme);\n\n if (\n process.env.NODE_ENV !== 'production' &&\n (mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')\n ) {\n throw new StyledError(7);\n }\n\n return mergedTheme;\n }\n\n if (theme === null || Array.isArray(theme) || typeof theme !== 'object') {\n throw new StyledError(8);\n }\n\n return { ...outerTheme, ...theme };\n }\n\n getContext(theme: (outerTheme: ?Theme) => void, outerTheme?: Theme) {\n return this.getTheme(theme, outerTheme);\n }\n}\n","// @flow\nimport React, { createContext, Component, type Element } from 'react';\nimport PropTypes from 'prop-types';\nimport memoize from 'memoize-one';\nimport StyleSheet from './StyleSheet';\nimport ServerStyleSheet from './ServerStyleSheet';\nimport StyledError from '../utils/error';\n\ntype Props = {\n children?: Element<any>,\n sheet?: StyleSheet,\n target?: HTMLElement,\n};\n\nexport const StyleSheetContext = createContext();\nexport const StyleSheetConsumer = StyleSheetContext.Consumer;\n\nexport default class StyleSheetManager extends Component<Props> {\n static propTypes = {\n sheet: PropTypes.oneOfType([\n PropTypes.instanceOf(StyleSheet),\n PropTypes.instanceOf(ServerStyleSheet),\n ]),\n\n target: PropTypes.shape({\n appendChild: PropTypes.func.isRequired,\n }),\n };\n\n getContext: (sheet: ?StyleSheet, target: ?HTMLElement) => StyleSheet;\n\n constructor(props: Props) {\n super(props);\n this.getContext = memoize(this.getContext);\n }\n\n getContext(sheet: ?StyleSheet, target: ?HTMLElement) {\n if (sheet) {\n return sheet;\n } else if (target) {\n return new StyleSheet(target);\n } else {\n throw new StyledError(4);\n }\n }\n\n render() {\n const { children, sheet, target } = this.props;\n\n return (\n <StyleSheetContext.Provider value={this.getContext(sheet, target)}>\n {process.env.NODE_ENV !== 'production' ? React.Children.only(children) : children}\n </StyleSheetContext.Provider>\n );\n }\n}\n","// @flow\nimport validAttr from '@emotion/is-prop-valid';\nimport merge from 'merge-anything';\nimport React, { createElement, Component } from 'react';\nimport ComponentStyle from './ComponentStyle';\nimport createWarnTooManyClasses from '../utils/createWarnTooManyClasses';\nimport determineTheme from '../utils/determineTheme';\nimport escape from '../utils/escape';\nimport generateDisplayName from '../utils/generateDisplayName';\nimport getComponentName from '../utils/getComponentName';\nimport hoist from '../utils/hoist';\nimport isFunction from '../utils/isFunction';\nimport isTag from '../utils/isTag';\nimport isDerivedReactComponent from '../utils/isDerivedReactComponent';\nimport isStyledComponent from '../utils/isStyledComponent';\nimport once from '../utils/once';\nimport StyleSheet from './StyleSheet';\nimport { ThemeConsumer, type Theme } from './ThemeProvider';\nimport { StyleSheetConsumer } from './StyleSheetManager';\nimport { EMPTY_ARRAY, EMPTY_OBJECT } from '../utils/empties';\n\nimport type { Attrs, RuleSet, Target } from '../types';\n\nconst THEME_PROP_REGEX = /\\.theme[.[]/;\nconst identifiers = {};\n\n/* We depend on components having unique IDs */\nfunction generateId(_ComponentStyle: Function, _displayName: string, parentComponentId: string) {\n const displayName = typeof _displayName !== 'string' ? 'sc' : escape(_displayName);\n\n /**\n * This ensures uniqueness if two components happen to share\n * the same displayName.\n */\n const nr = (identifiers[displayName] || 0) + 1;\n identifiers[displayName] = nr;\n\n const componentId = `${displayName}-${_ComponentStyle.generateName(displayName + nr)}`;\n\n return parentComponentId ? `${parentComponentId}-${componentId}` : componentId;\n}\n\n// $FlowFixMe\nclass StyledComponent extends Component<*> {\n renderOuter: Function;\n\n renderInner: Function;\n\n styleSheet: ?StyleSheet;\n\n warnInnerRef: Function;\n\n warnAttrsFnObjectKeyDeprecated: Function;\n\n warnNonStyledComponentAttrsObjectKey: Function;\n\n attrs = {};\n\n constructor() {\n super();\n this.renderOuter = this.renderOuter.bind(this);\n this.renderInner = this.renderInner.bind(this);\n\n if (process.env.NODE_ENV !== 'production') {\n this.warnInnerRef = once(displayName =>\n // eslint-disable-next-line no-console\n console.warn(\n `The \"innerRef\" API has been removed in styled-components v4 in favor of React 16 ref forwarding, use \"ref\" instead like a typical component. \"innerRef\" was detected on component \"${displayName}\".`\n )\n );\n\n this.warnAttrsFnObjectKeyDeprecated = once(\n (key, displayName): void =>\n // eslint-disable-next-line no-console\n console.warn(\n `Functions as object-form attrs({}) keys are now deprecated and will be removed in a future version of styled-components. Switch to the new attrs(props => ({})) syntax instead for easier and more powerful composition. The attrs key in question is \"${key}\" on component \"${displayName}\".`,\n `\\n ${new Error().stack}`\n )\n );\n\n this.warnNonStyledComponentAttrsObjectKey = once(\n (key, displayName): void =>\n // eslint-disable-next-line no-console\n console.warn(\n `It looks like you've used a non styled-component as the value for the \"${key}\" prop in an object-form attrs constructor of \"${displayName}\".\\n` +\n 'You should use the new function-form attrs constructor which avoids this issue: attrs(props => ({ yourStuff }))\\n' +\n \"To continue using the deprecated object syntax, you'll need to wrap your component prop in a function to make it available inside the styled component (you'll still get the deprecation warning though.)\\n\" +\n `For example, { ${key}: () => InnerComponent } instead of { ${key}: InnerComponent }`\n )\n );\n }\n }\n\n render() {\n return <StyleSheetConsumer>{this.renderOuter}</StyleSheetConsumer>;\n }\n\n renderOuter(styleSheet?: StyleSheet = StyleSheet.master) {\n this.styleSheet = styleSheet;\n\n // No need to subscribe a static component to theme changes, it won't change anything\n if (this.props.forwardedComponent.componentStyle.isStatic) return this.renderInner();\n\n return <ThemeConsumer>{this.renderInner}</ThemeConsumer>;\n }\n\n renderInner(theme?: Theme) {\n const {\n componentStyle,\n defaultProps,\n displayName,\n foldedComponentIds,\n styledComponentId,\n target,\n usesTheme,\n } = this.props.forwardedComponent;\n\n let generatedClassName;\n let rawTheme;\n\n if (componentStyle.isStatic) {\n generatedClassName = this.generateAndInjectStyles(EMPTY_OBJECT, this.props);\n } else {\n rawTheme = determineTheme(this.props, theme, defaultProps);\n generatedClassName = this.generateAndInjectStyles(rawTheme || EMPTY_OBJECT, this.props);\n\n if (process.env.NODE_ENV !== 'production' && usesTheme && !rawTheme) {\n console.error(\n `Component '${\n // $FlowFixMe\n displayName\n }' (.${styledComponentId}) references the 'theme' prop in its styles but no theme was provided via prop or <ThemeProvider>.`\n );\n }\n }\n\n const elementToBeCreated = this.props.as || this.attrs.as || target;\n const isTargetTag = isTag(elementToBeCreated);\n\n const propsForElement = {};\n const computedProps = { ...this.props, ...this.attrs };\n\n let key;\n // eslint-disable-next-line guard-for-in\n for (key in computedProps) {\n if (process.env.NODE_ENV !== 'production' && key === 'innerRef' && isTargetTag) {\n this.warnInnerRef(displayName);\n }\n\n if (key === 'forwardedComponent' || key === 'as') {\n continue;\n } else if (key === 'forwardedRef') propsForElement.ref = computedProps[key];\n else if (key === 'forwardedAs') propsForElement.as = computedProps[key];\n else if (!isTargetTag || validAttr(key)) {\n // Don't pass through non HTML tags through to HTML elements\n propsForElement[key] = computedProps[key];\n }\n }\n\n if (this.props.style && this.attrs.style) {\n propsForElement.style = { ...this.attrs.style, ...this.props.style };\n }\n\n propsForElement.className = Array.prototype\n .concat(\n foldedComponentIds,\n styledComponentId,\n generatedClassName !== styledComponentId ? generatedClassName : null,\n this.props.className,\n this.attrs.className\n )\n .filter(Boolean)\n .join(' ');\n\n return createElement(elementToBeCreated, propsForElement);\n }\n\n buildExecutionContext(theme: ?Object, props: Object, attrs: Attrs) {\n const context = { ...props, theme };\n\n if (!attrs.length) return context;\n\n this.attrs = {};\n\n attrs.forEach(attrDef => {\n let resolvedAttrDef = attrDef;\n let attrDefWasFn = false;\n let attr;\n let key;\n\n if (isFunction(resolvedAttrDef)) {\n // $FlowFixMe\n resolvedAttrDef = resolvedAttrDef(context);\n attrDefWasFn = true;\n }\n\n /* eslint-disable guard-for-in */\n // $FlowFixMe\n for (key in resolvedAttrDef) {\n attr = resolvedAttrDef[key];\n\n if (!attrDefWasFn) {\n if (isFunction(attr) && !isDerivedReactComponent(attr) && !isStyledComponent(attr)) {\n if (process.env.NODE_ENV !== 'production') {\n this.warnAttrsFnObjectKeyDeprecated(key, props.forwardedComponent.displayName);\n }\n\n attr = attr(context);\n\n if (process.env.NODE_ENV !== 'production' && React.isValidElement(attr)) {\n this.warnNonStyledComponentAttrsObjectKey(key, props.forwardedComponent.displayName);\n }\n }\n }\n\n this.attrs[key] = attr;\n context[key] = attr;\n }\n /* eslint-enable */\n });\n\n return context;\n }\n\n generateAndInjectStyles(theme: any, props: any) {\n const { attrs, componentStyle, warnTooManyClasses } = props.forwardedComponent;\n\n // statically styled-components don't need to build an execution context object,\n // and shouldn't be increasing the number of class names\n if (componentStyle.isStatic && !attrs.length) {\n return componentStyle.generateAndInjectStyles(EMPTY_OBJECT, this.styleSheet);\n }\n\n const className = componentStyle.generateAndInjectStyles(\n this.buildExecutionContext(theme, props, attrs),\n this.styleSheet\n );\n\n if (process.env.NODE_ENV !== 'production' && warnTooManyClasses) warnTooManyClasses(className);\n\n return className;\n }\n}\n\nexport default function createStyledComponent(target: Target, options: Object, rules: RuleSet) {\n const isTargetStyledComp = isStyledComponent(target);\n const isClass = !isTag(target);\n\n const {\n displayName = generateDisplayName(target),\n componentId = generateId(ComponentStyle, options.displayName, options.parentComponentId),\n ParentComponent = StyledComponent,\n attrs = EMPTY_ARRAY,\n } = options;\n\n const styledComponentId =\n options.displayName && options.componentId\n ? `${escape(options.displayName)}-${options.componentId}`\n : options.componentId || componentId;\n\n // fold the underlying StyledComponent attrs up (implicit extend)\n const finalAttrs =\n // $FlowFixMe\n isTargetStyledComp && target.attrs\n ? Array.prototype.concat(target.attrs, attrs).filter(Boolean)\n : attrs;\n\n const componentStyle = new ComponentStyle(\n isTargetStyledComp\n ? // fold the underlying StyledComponent rules up (implicit extend)\n // $FlowFixMe\n target.componentStyle.rules.concat(rules)\n : rules,\n finalAttrs,\n styledComponentId\n );\n\n /**\n * forwardRef creates a new interim component, which we'll take advantage of\n * instead of extending ParentComponent to create _another_ interim class\n */\n let WrappedStyledComponent;\n const forwardRef = (props, ref) => (\n <ParentComponent {...props} forwardedComponent={WrappedStyledComponent} forwardedRef={ref} />\n );\n forwardRef.displayName = displayName;\n WrappedStyledComponent = React.forwardRef(forwardRef);\n WrappedStyledComponent.displayName = displayName;\n\n // $FlowFixMe\n WrappedStyledComponent.attrs = finalAttrs;\n // $FlowFixMe\n WrappedStyledComponent.componentStyle = componentStyle;\n\n // $FlowFixMe\n WrappedStyledComponent.foldedComponentIds = isTargetStyledComp\n ? // $FlowFixMe\n Array.prototype.concat(target.foldedComponentIds, target.styledComponentId)\n : EMPTY_ARRAY;\n\n // $FlowFixMe\n WrappedStyledComponent.styledComponentId = styledComponentId;\n\n // fold the underlying StyledComponent target up since we folded the styles\n // $FlowFixMe\n WrappedStyledComponent.target = isTargetStyledComp ? target.target : target;\n\n // $FlowFixMe\n WrappedStyledComponent.withComponent = function withComponent(tag: Target) {\n const { componentId: previousComponentId, ...optionsToCopy } = options;\n\n const newComponentId =\n previousComponentId &&\n `${previousComponentId}-${isTag(tag) ? tag : escape(getComponentName(tag))}`;\n\n const newOptions = {\n ...optionsToCopy,\n attrs: finalAttrs,\n componentId: newComponentId,\n ParentComponent,\n };\n\n return createStyledComponent(tag, newOptions, rules);\n };\n\n // $FlowFixMe\n Object.defineProperty(WrappedStyledComponent, 'defaultProps', {\n get() {\n return this._foldedDefaultProps;\n },\n\n set(obj) {\n // $FlowFixMe\n this._foldedDefaultProps = isTargetStyledComp ? merge(target.defaultProps, obj) : obj;\n },\n });\n\n if (process.env.NODE_ENV !== 'production') {\n // $FlowFixMe\n WrappedStyledComponent.usesTheme = componentStyle.rules.some(\n x => isFunction(x) && THEME_PROP_REGEX.test(x.toString())\n );\n\n // $FlowFixMe\n WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName);\n }\n\n // $FlowFixMe\n WrappedStyledComponent.toString = () => `.${WrappedStyledComponent.styledComponentId}`;\n\n if (isClass) {\n hoist(WrappedStyledComponent, target, {\n // all SC-specific things should not be hoisted\n attrs: true,\n componentStyle: true,\n displayName: true,\n foldedComponentIds: true,\n styledComponentId: true,\n target: true,\n withComponent: true,\n });\n }\n\n return WrappedStyledComponent;\n}\n","// @flow\nimport { EMPTY_ARRAY } from '../utils/empties';\nimport flatten from '../utils/flatten';\nimport isStaticRules from '../utils/isStaticRules';\nimport stringifyRules from '../utils/stringifyRules';\nimport StyleSheet from './StyleSheet';\n\nimport type { RuleSet } from '../types';\n\nexport default class GlobalStyle {\n componentId: string;\n\n isStatic: boolean;\n\n rules: RuleSet;\n\n constructor(rules: RuleSet, componentId: string) {\n this.rules = rules;\n this.componentId = componentId;\n this.isStatic = isStaticRules(rules, EMPTY_ARRAY);\n\n if (!StyleSheet.master.hasId(componentId)) {\n StyleSheet.master.deferredInject(componentId, []);\n }\n }\n\n createStyles(executionContext: Object, styleSheet: StyleSheet) {\n const flatCSS = flatten(this.rules, executionContext, styleSheet);\n const css = stringifyRules(flatCSS, '');\n\n styleSheet.inject(this.componentId, css);\n }\n\n removeStyles(styleSheet: StyleSheet) {\n const { componentId } = this;\n if (styleSheet.hasId(componentId)) {\n styleSheet.remove(componentId);\n }\n }\n\n // TODO: overwrite in-place instead of remove+create?\n renderStyles(executionContext: Object, styleSheet: StyleSheet) {\n this.removeStyles(styleSheet);\n this.createStyles(executionContext, styleSheet);\n }\n}\n"],"names":["i"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CC;;CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iEA+EuD;;;;;;;;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file":"styled-components.browser.cjs.js","sources":["../src/models/StyleTags.js","../src/models/ThemeProvider.js","../src/models/StyleSheetManager.js","../src/models/StyledComponent.js","../src/models/GlobalStyle.js"],"sourcesContent":["// @flow\n/* eslint-disable flowtype/object-type-delimiter */\n/* eslint-disable react/prop-types */\n\nimport React, { type Element } from 'react';\nimport { IS_BROWSER, DISABLE_SPEEDY, SC_ATTR, SC_VERSION_ATTR } from '../constants';\nimport StyledError from '../utils/error';\nimport { type ExtractedComp } from '../utils/extractCompsFromCSS';\nimport { splitByRules } from '../utils/stringifyRules';\nimport getNonce from '../utils/nonce';\n\nimport {\n type Names,\n addNameForId,\n resetIdNames,\n hasNameForId,\n stringifyNames,\n cloneNames,\n} from '../utils/styleNames';\n\nimport { sheetForTag, safeInsertRule, deleteRules } from '../utils/insertRuleHelpers';\n\ndeclare var __VERSION__: string;\n\nexport interface Tag<T> {\n // $FlowFixMe: Doesn't seem to accept any combination w/ HTMLStyleElement for some reason\n styleTag: HTMLStyleElement | null;\n /* lists all ids of the tag */\n getIds(): string[];\n /* checks whether `name` is already injected for `id` */\n hasNameForId(id: string, name: string): boolean;\n /* inserts a marker to ensure the id's correct position in the sheet */\n insertMarker(id: string): T;\n /* inserts rules according to the ids markers */\n insertRules(id: string, cssRules: string[], name: ?string): void;\n /* removes all rules belonging to the id, keeping the marker around */\n removeRules(id: string): void;\n css(): string;\n toHTML(additionalAttrs: ?string): string;\n toElement(): Element<*>;\n clone(): Tag<T>;\n /* used in server side rendering to indicate that the rules in the tag have been flushed to HTML */\n sealed: boolean;\n}\n\n/* this marker separates component styles and is important for rehydration */\nconst makeTextMarker = id => `\\n/* sc-component-id: ${id} */\\n`;\n\n/* add up all numbers in array up until and including the index */\nconst addUpUntilIndex = (sizes: number[], index: number): number => {\n let totalUpToIndex = 0;\n for (let i = 0; i <= index; i += 1) {\n totalUpToIndex += sizes[i];\n }\n\n return totalUpToIndex;\n};\n\n/* create a new style tag after lastEl */\nconst makeStyleTag = (target: ?HTMLElement, tagEl: ?Node, insertBefore: ?boolean) => {\n let targetDocument = document;\n if(target) targetDocument = target.ownerDocument;\n else if(tagEl) targetDocument = tagEl.ownerDocument;\n\n const el = targetDocument.createElement('style');\n el.setAttribute(SC_ATTR, '');\n el.setAttribute(SC_VERSION_ATTR, __VERSION__);\n\n const nonce = getNonce();\n if (nonce) {\n el.setAttribute('nonce', nonce);\n }\n\n /* Work around insertRule quirk in EdgeHTML */\n el.appendChild(targetDocument.createTextNode(''));\n\n if (target && !tagEl) {\n /* Append to target when no previous element was passed */\n target.appendChild(el);\n } else {\n if (!tagEl || !target || !tagEl.parentNode) {\n throw new StyledError(6);\n }\n\n /* Insert new style tag after the previous one */\n tagEl.parentNode.insertBefore(el, insertBefore ? tagEl : tagEl.nextSibling);\n }\n\n return el;\n};\n\n/* takes a css factory function and outputs an html styled tag factory */\nconst wrapAsHtmlTag = (css: () => string, names: Names) => (additionalAttrs: ?string): string => {\n const nonce = getNonce();\n const attrs = [\n nonce && `nonce=\"${nonce}\"`,\n `${SC_ATTR}=\"${stringifyNames(names)}\"`,\n `${SC_VERSION_ATTR}=\"${__VERSION__}\"`,\n additionalAttrs,\n ];\n\n const htmlAttr = attrs.filter(Boolean).join(' ');\n return `<style ${htmlAttr}>${css()}</style>`;\n};\n\n/* takes a css factory function and outputs an element factory */\nconst wrapAsElement = (css: () => string, names: Names) => () => {\n const props = {\n [SC_ATTR]: stringifyNames(names),\n [SC_VERSION_ATTR]: __VERSION__,\n };\n\n const nonce = getNonce();\n if (nonce) {\n // $FlowFixMe\n props.nonce = nonce;\n }\n\n // eslint-disable-next-line react/no-danger\n return <style {...props} dangerouslySetInnerHTML={{ __html: css() }} />;\n};\n\nconst getIdsFromMarkersFactory = (markers: Object) => (): string[] => Object.keys(markers);\n\n/* speedy tags utilise insertRule */\nconst makeSpeedyTag = (el: HTMLStyleElement, getImportRuleTag: ?() => Tag<any>): Tag<number> => {\n const names: Names = (Object.create(null): Object);\n const markers = Object.create(null);\n const sizes: number[] = [];\n\n const extractImport = getImportRuleTag !== undefined;\n /* indicates whether getImportRuleTag was called */\n let usedImportRuleTag = false;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n markers[id] = sizes.length;\n sizes.push(0);\n resetIdNames(names, id);\n\n return markers[id];\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n const sheet = sheetForTag(el);\n const insertIndex = addUpUntilIndex(sizes, marker);\n\n let injectedRules = 0;\n const importRules = [];\n const cssRulesSize = cssRules.length;\n\n for (let i = 0; i < cssRulesSize; i += 1) {\n const cssRule = cssRules[i];\n let mayHaveImport = extractImport; /* @import rules are reordered to appear first */\n if (mayHaveImport && cssRule.indexOf('@import') !== -1) {\n importRules.push(cssRule);\n } else if (safeInsertRule(sheet, cssRule, insertIndex + injectedRules)) {\n mayHaveImport = false;\n injectedRules += 1;\n }\n }\n\n if (extractImport && importRules.length > 0) {\n usedImportRuleTag = true;\n // $FlowFixMe\n getImportRuleTag().insertRules(`${id}-import`, importRules);\n }\n\n sizes[marker] += injectedRules; /* add up no of injected rules */\n addNameForId(names, id, name);\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n // $FlowFixMe\n if (el.isConnected === false) return;\n\n const size = sizes[marker];\n const sheet = sheetForTag(el);\n const removalIndex = addUpUntilIndex(sizes, marker) - 1;\n deleteRules(sheet, removalIndex, size);\n sizes[marker] = 0;\n resetIdNames(names, id);\n\n if (extractImport && usedImportRuleTag) {\n // $FlowFixMe\n getImportRuleTag().removeRules(`${id}-import`);\n }\n };\n\n const css = () => {\n const { cssRules } = sheetForTag(el);\n let str = '';\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n str += makeTextMarker(id);\n const marker = markers[id];\n const end = addUpUntilIndex(sizes, marker);\n const size = sizes[marker];\n for (let i = end - size; i < end; i += 1) {\n const rule = cssRules[i];\n if (rule !== undefined) {\n str += rule.cssText;\n }\n }\n }\n\n return str;\n };\n\n return {\n clone() {\n throw new StyledError(5);\n },\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: el,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n};\n\nconst makeTextNode = (targetDocument, id) => targetDocument.createTextNode(makeTextMarker(id));\n\nconst makeBrowserTag = (el: HTMLStyleElement, getImportRuleTag: ?() => Tag<any>): Tag<Text> => {\n const names = (Object.create(null): Object);\n const markers = Object.create(null);\n\n const extractImport = getImportRuleTag !== undefined;\n\n /* indicates whether getImportRuleTag was called */\n let usedImportRuleTag = false;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n markers[id] = makeTextNode(el.ownerDocument, id);\n el.appendChild(markers[id]);\n names[id] = Object.create(null);\n\n return markers[id];\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n const importRules = [];\n const cssRulesSize = cssRules.length;\n\n for (let i = 0; i < cssRulesSize; i += 1) {\n const rule = cssRules[i];\n let mayHaveImport = extractImport;\n if (mayHaveImport && rule.indexOf('@import') !== -1) {\n importRules.push(rule);\n } else {\n mayHaveImport = false;\n const separator = i === cssRulesSize - 1 ? '' : ' ';\n marker.appendData(`${rule}${separator}`);\n }\n }\n\n addNameForId(names, id, name);\n\n if (extractImport && importRules.length > 0) {\n usedImportRuleTag = true;\n // $FlowFixMe\n getImportRuleTag().insertRules(`${id}-import`, importRules);\n }\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n\n /* create new empty text node and replace the current one */\n const newMarker = makeTextNode(el.ownerDocument, id);\n el.replaceChild(newMarker, marker);\n markers[id] = newMarker;\n resetIdNames(names, id);\n\n if (extractImport && usedImportRuleTag) {\n // $FlowFixMe\n getImportRuleTag().removeRules(`${id}-import`);\n }\n };\n\n const css = () => {\n let str = '';\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n str += markers[id].data;\n }\n\n return str;\n };\n\n return {\n clone() {\n throw new StyledError(5);\n },\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: el,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n};\n\nconst makeServerTag = (namesArg, markersArg): Tag<[string]> => {\n const names = namesArg === undefined ? (Object.create(null): Object) : namesArg;\n const markers = markersArg === undefined ? Object.create(null) : markersArg;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n return (markers[id] = ['']);\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n marker[0] += cssRules.join(' ');\n addNameForId(names, id, name);\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n marker[0] = '';\n resetIdNames(names, id);\n };\n\n const css = () => {\n let str = '';\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n const cssForId = markers[id][0];\n if (cssForId) {\n str += makeTextMarker(id) + cssForId;\n }\n }\n return str;\n };\n\n const clone = () => {\n const namesClone = cloneNames(names);\n const markersClone = Object.create(null);\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n markersClone[id] = [markers[id][0]];\n }\n\n return makeServerTag(namesClone, markersClone);\n };\n\n const tag = {\n clone,\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: null,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n\n return tag;\n};\n\nexport const makeTag = (\n target: ?HTMLElement,\n tagEl: ?HTMLStyleElement,\n forceServer?: boolean,\n insertBefore?: boolean,\n getImportRuleTag?: () => Tag<any>\n): Tag<any> => {\n if (IS_BROWSER && !forceServer) {\n const el = makeStyleTag(target, tagEl, insertBefore);\n\n if (DISABLE_SPEEDY) {\n return makeBrowserTag(el, getImportRuleTag);\n } else {\n return makeSpeedyTag(el, getImportRuleTag);\n }\n }\n\n return makeServerTag();\n};\n\nexport const rehydrate = (\n tag: Tag<any>,\n els: HTMLStyleElement[],\n extracted: ExtractedComp[]\n): void => {\n /* add all extracted components to the new tag */\n for (let i = 0, len = extracted.length; i < len; i += 1) {\n const { componentId, cssFromDOM } = extracted[i];\n const cssRules = splitByRules(cssFromDOM);\n tag.insertRules(componentId, cssRules);\n }\n\n /* remove old HTMLStyleElements, since they have been rehydrated */\n for (let i = 0, len = els.length; i < len; i += 1) {\n const el = els[i];\n if (el.parentNode) {\n el.parentNode.removeChild(el);\n }\n }\n};\n","// @flow\nimport React, { createContext, Component, type Element } from 'react';\nimport memoize from 'memoize-one';\nimport StyledError from '../utils/error';\nimport isFunction from '../utils/isFunction';\n\nexport type Theme = { [key: string]: mixed };\n\ntype Props = {\n children?: Element<any>,\n theme: Theme | ((outerTheme: Theme) => void),\n};\n\nexport const ThemeContext = createContext();\n\nexport const ThemeConsumer = ThemeContext.Consumer;\n\n/**\n * Provide a theme to an entire react component tree via context\n */\nexport default class ThemeProvider extends Component<Props> {\n getContext: (theme: Theme | ((outerTheme: Theme) => void), outerTheme?: Theme) => Theme;\n\n renderInner: Function;\n\n constructor(props: Props) {\n super(props);\n this.getContext = memoize(this.getContext.bind(this));\n this.renderInner = this.renderInner.bind(this);\n }\n\n render() {\n if (!this.props.children) return null;\n\n return <ThemeContext.Consumer>{this.renderInner}</ThemeContext.Consumer>;\n }\n\n renderInner(outerTheme?: Theme) {\n const context = this.getContext(this.props.theme, outerTheme);\n\n return (\n <ThemeContext.Provider value={context}>\n {this.props.children}\n </ThemeContext.Provider>\n );\n }\n\n /**\n * Get the theme from the props, supporting both (outerTheme) => {}\n * as well as object notation\n */\n getTheme(theme: (outerTheme: ?Theme) => void, outerTheme: ?Theme) {\n if (isFunction(theme)) {\n const mergedTheme = theme(outerTheme);\n\n if (\n process.env.NODE_ENV !== 'production' &&\n (mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')\n ) {\n throw new StyledError(7);\n }\n\n return mergedTheme;\n }\n\n if (theme === null || Array.isArray(theme) || typeof theme !== 'object') {\n throw new StyledError(8);\n }\n\n return { ...outerTheme, ...theme };\n }\n\n getContext(theme: (outerTheme: ?Theme) => void, outerTheme?: Theme) {\n return this.getTheme(theme, outerTheme);\n }\n}\n","// @flow\nimport React, { createContext, Component, type Element } from 'react';\nimport PropTypes from 'prop-types';\nimport memoize from 'memoize-one';\nimport StyleSheet from './StyleSheet';\nimport ServerStyleSheet from './ServerStyleSheet';\nimport StyledError from '../utils/error';\n\ntype Props = {\n children?: Element<any>,\n sheet?: StyleSheet,\n target?: HTMLElement,\n};\n\nexport const StyleSheetContext = createContext();\nexport const StyleSheetConsumer = StyleSheetContext.Consumer;\n\nexport default class StyleSheetManager extends Component<Props> {\n static propTypes = {\n sheet: PropTypes.oneOfType([\n PropTypes.instanceOf(StyleSheet),\n PropTypes.instanceOf(ServerStyleSheet),\n ]),\n\n target: PropTypes.shape({\n appendChild: PropTypes.func.isRequired,\n }),\n };\n\n getContext: (sheet: ?StyleSheet, target: ?HTMLElement) => StyleSheet;\n\n constructor(props: Props) {\n super(props);\n this.getContext = memoize(this.getContext);\n }\n\n getContext(sheet: ?StyleSheet, target: ?HTMLElement) {\n if (sheet) {\n return sheet;\n } else if (target) {\n return new StyleSheet(target);\n } else {\n throw new StyledError(4);\n }\n }\n\n render() {\n const { children, sheet, target } = this.props;\n\n return (\n <StyleSheetContext.Provider value={this.getContext(sheet, target)}>\n {process.env.NODE_ENV !== 'production' ? React.Children.only(children) : children}\n </StyleSheetContext.Provider>\n );\n }\n}\n","// @flow\nimport validAttr from '@emotion/is-prop-valid';\nimport merge from 'merge-anything';\nimport React, { createElement, Component } from 'react';\nimport ComponentStyle from './ComponentStyle';\nimport createWarnTooManyClasses from '../utils/createWarnTooManyClasses';\nimport determineTheme from '../utils/determineTheme';\nimport escape from '../utils/escape';\nimport generateDisplayName from '../utils/generateDisplayName';\nimport getComponentName from '../utils/getComponentName';\nimport hoist from '../utils/hoist';\nimport isFunction from '../utils/isFunction';\nimport isTag from '../utils/isTag';\nimport isDerivedReactComponent from '../utils/isDerivedReactComponent';\nimport isStyledComponent from '../utils/isStyledComponent';\nimport once from '../utils/once';\nimport StyleSheet from './StyleSheet';\nimport { ThemeConsumer, type Theme } from './ThemeProvider';\nimport { StyleSheetConsumer } from './StyleSheetManager';\nimport { EMPTY_ARRAY, EMPTY_OBJECT } from '../utils/empties';\n\nimport type { Attrs, RuleSet, Target } from '../types';\n\nconst identifiers = {};\n\n/* We depend on components having unique IDs */\nfunction generateId(_ComponentStyle: Function, _displayName: string, parentComponentId: string) {\n const displayName = typeof _displayName !== 'string' ? 'sc' : escape(_displayName);\n\n /**\n * This ensures uniqueness if two components happen to share\n * the same displayName.\n */\n const nr = (identifiers[displayName] || 0) + 1;\n identifiers[displayName] = nr;\n\n const componentId = `${displayName}-${_ComponentStyle.generateName(displayName + nr)}`;\n\n return parentComponentId ? `${parentComponentId}-${componentId}` : componentId;\n}\n\n// $FlowFixMe\nclass StyledComponent extends Component<*> {\n renderOuter: Function;\n\n renderInner: Function;\n\n styleSheet: ?StyleSheet;\n\n warnInnerRef: Function;\n\n warnAttrsFnObjectKeyDeprecated: Function;\n\n warnNonStyledComponentAttrsObjectKey: Function;\n\n attrs = {};\n\n constructor() {\n super();\n this.renderOuter = this.renderOuter.bind(this);\n this.renderInner = this.renderInner.bind(this);\n\n if (process.env.NODE_ENV !== 'production') {\n this.warnInnerRef = once(displayName =>\n // eslint-disable-next-line no-console\n console.warn(\n `The \"innerRef\" API has been removed in styled-components v4 in favor of React 16 ref forwarding, use \"ref\" instead like a typical component. \"innerRef\" was detected on component \"${displayName}\".`\n )\n );\n\n this.warnAttrsFnObjectKeyDeprecated = once(\n (key, displayName): void =>\n // eslint-disable-next-line no-console\n console.warn(\n `Functions as object-form attrs({}) keys are now deprecated and will be removed in a future version of styled-components. Switch to the new attrs(props => ({})) syntax instead for easier and more powerful composition. The attrs key in question is \"${key}\" on component \"${displayName}\".`,\n `\\n ${new Error().stack}`\n )\n );\n\n this.warnNonStyledComponentAttrsObjectKey = once(\n (key, displayName): void =>\n // eslint-disable-next-line no-console\n console.warn(\n `It looks like you've used a non styled-component as the value for the \"${key}\" prop in an object-form attrs constructor of \"${displayName}\".\\n` +\n 'You should use the new function-form attrs constructor which avoids this issue: attrs(props => ({ yourStuff }))\\n' +\n \"To continue using the deprecated object syntax, you'll need to wrap your component prop in a function to make it available inside the styled component (you'll still get the deprecation warning though.)\\n\" +\n `For example, { ${key}: () => InnerComponent } instead of { ${key}: InnerComponent }`\n )\n );\n }\n }\n\n render() {\n return <StyleSheetConsumer>{this.renderOuter}</StyleSheetConsumer>;\n }\n\n renderOuter(styleSheet?: StyleSheet = StyleSheet.master) {\n this.styleSheet = styleSheet;\n\n // No need to subscribe a static component to theme changes, it won't change anything\n if (this.props.forwardedComponent.componentStyle.isStatic) return this.renderInner();\n\n return <ThemeConsumer>{this.renderInner}</ThemeConsumer>;\n }\n\n renderInner(theme?: Theme) {\n const {\n componentStyle,\n defaultProps,\n displayName,\n foldedComponentIds,\n styledComponentId,\n target,\n } = this.props.forwardedComponent;\n\n let generatedClassName;\n if (componentStyle.isStatic) {\n generatedClassName = this.generateAndInjectStyles(EMPTY_OBJECT, this.props);\n } else {\n generatedClassName = this.generateAndInjectStyles(\n determineTheme(this.props, theme, defaultProps) || EMPTY_OBJECT,\n this.props\n );\n }\n\n const elementToBeCreated = this.props.as || this.attrs.as || target;\n const isTargetTag = isTag(elementToBeCreated);\n\n const propsForElement = {};\n const computedProps = { ...this.props, ...this.attrs };\n\n let key;\n // eslint-disable-next-line guard-for-in\n for (key in computedProps) {\n if (process.env.NODE_ENV !== 'production' && key === 'innerRef' && isTargetTag) {\n this.warnInnerRef(displayName);\n }\n\n if (key === 'forwardedComponent' || key === 'as') {\n continue;\n } else if (key === 'forwardedRef') propsForElement.ref = computedProps[key];\n else if (key === 'forwardedAs') propsForElement.as = computedProps[key];\n else if (!isTargetTag || validAttr(key)) {\n // Don't pass through non HTML tags through to HTML elements\n propsForElement[key] = computedProps[key];\n }\n }\n\n if (this.props.style && this.attrs.style) {\n propsForElement.style = { ...this.attrs.style, ...this.props.style };\n }\n\n propsForElement.className = Array.prototype\n .concat(\n foldedComponentIds,\n styledComponentId,\n generatedClassName !== styledComponentId ? generatedClassName : null,\n this.props.className,\n this.attrs.className\n )\n .filter(Boolean)\n .join(' ');\n\n return createElement(elementToBeCreated, propsForElement);\n }\n\n buildExecutionContext(theme: ?Object, props: Object, attrs: Attrs) {\n const context = { ...props, theme };\n\n if (!attrs.length) return context;\n\n this.attrs = {};\n\n attrs.forEach(attrDef => {\n let resolvedAttrDef = attrDef;\n let attrDefWasFn = false;\n let attr;\n let key;\n\n if (isFunction(resolvedAttrDef)) {\n // $FlowFixMe\n resolvedAttrDef = resolvedAttrDef(context);\n attrDefWasFn = true;\n }\n\n /* eslint-disable guard-for-in */\n // $FlowFixMe\n for (key in resolvedAttrDef) {\n attr = resolvedAttrDef[key];\n\n if (!attrDefWasFn) {\n if (isFunction(attr) && !isDerivedReactComponent(attr) && !isStyledComponent(attr)) {\n if (process.env.NODE_ENV !== 'production') {\n this.warnAttrsFnObjectKeyDeprecated(key, props.forwardedComponent.displayName);\n }\n\n attr = attr(context);\n\n if (process.env.NODE_ENV !== 'production' && React.isValidElement(attr)) {\n this.warnNonStyledComponentAttrsObjectKey(key, props.forwardedComponent.displayName);\n }\n }\n }\n\n this.attrs[key] = attr;\n context[key] = attr;\n }\n /* eslint-enable */\n });\n\n return context;\n }\n\n generateAndInjectStyles(theme: any, props: any) {\n const { attrs, componentStyle, warnTooManyClasses } = props.forwardedComponent;\n\n // statically styled-components don't need to build an execution context object,\n // and shouldn't be increasing the number of class names\n if (componentStyle.isStatic && !attrs.length) {\n return componentStyle.generateAndInjectStyles(EMPTY_OBJECT, this.styleSheet);\n }\n\n const className = componentStyle.generateAndInjectStyles(\n this.buildExecutionContext(theme, props, attrs),\n this.styleSheet\n );\n\n if (process.env.NODE_ENV !== 'production' && warnTooManyClasses) warnTooManyClasses(className);\n\n return className;\n }\n}\n\nexport default function createStyledComponent(target: Target, options: Object, rules: RuleSet) {\n const isTargetStyledComp = isStyledComponent(target);\n const isClass = !isTag(target);\n\n const {\n displayName = generateDisplayName(target),\n componentId = generateId(ComponentStyle, options.displayName, options.parentComponentId),\n ParentComponent = StyledComponent,\n attrs = EMPTY_ARRAY,\n } = options;\n\n const styledComponentId =\n options.displayName && options.componentId\n ? `${escape(options.displayName)}-${options.componentId}`\n : options.componentId || componentId;\n\n // fold the underlying StyledComponent attrs up (implicit extend)\n const finalAttrs =\n // $FlowFixMe\n isTargetStyledComp && target.attrs\n ? Array.prototype.concat(target.attrs, attrs).filter(Boolean)\n : attrs;\n\n const componentStyle = new ComponentStyle(\n isTargetStyledComp\n ? // fold the underlying StyledComponent rules up (implicit extend)\n // $FlowFixMe\n target.componentStyle.rules.concat(rules)\n : rules,\n finalAttrs,\n styledComponentId\n );\n\n /**\n * forwardRef creates a new interim component, which we'll take advantage of\n * instead of extending ParentComponent to create _another_ interim class\n */\n let WrappedStyledComponent;\n const forwardRef = (props, ref) => (\n <ParentComponent {...props} forwardedComponent={WrappedStyledComponent} forwardedRef={ref} />\n );\n forwardRef.displayName = displayName;\n WrappedStyledComponent = React.forwardRef(forwardRef);\n WrappedStyledComponent.displayName = displayName;\n\n // $FlowFixMe\n WrappedStyledComponent.attrs = finalAttrs;\n // $FlowFixMe\n WrappedStyledComponent.componentStyle = componentStyle;\n\n // $FlowFixMe\n WrappedStyledComponent.foldedComponentIds = isTargetStyledComp\n ? // $FlowFixMe\n Array.prototype.concat(target.foldedComponentIds, target.styledComponentId)\n : EMPTY_ARRAY;\n\n // $FlowFixMe\n WrappedStyledComponent.styledComponentId = styledComponentId;\n\n // fold the underlying StyledComponent target up since we folded the styles\n // $FlowFixMe\n WrappedStyledComponent.target = isTargetStyledComp ? target.target : target;\n\n // $FlowFixMe\n WrappedStyledComponent.withComponent = function withComponent(tag: Target) {\n const { componentId: previousComponentId, ...optionsToCopy } = options;\n\n const newComponentId =\n previousComponentId &&\n `${previousComponentId}-${isTag(tag) ? tag : escape(getComponentName(tag))}`;\n\n const newOptions = {\n ...optionsToCopy,\n attrs: finalAttrs,\n componentId: newComponentId,\n ParentComponent,\n };\n\n return createStyledComponent(tag, newOptions, rules);\n };\n\n // $FlowFixMe\n Object.defineProperty(WrappedStyledComponent, 'defaultProps', {\n get() {\n return this._foldedDefaultProps;\n },\n\n set(obj) {\n // $FlowFixMe\n this._foldedDefaultProps = isTargetStyledComp ? merge(target.defaultProps, obj) : obj;\n },\n });\n\n if (process.env.NODE_ENV !== 'production') {\n // $FlowFixMe\n WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName);\n }\n\n // $FlowFixMe\n WrappedStyledComponent.toString = () => `.${WrappedStyledComponent.styledComponentId}`;\n\n if (isClass) {\n hoist(WrappedStyledComponent, target, {\n // all SC-specific things should not be hoisted\n attrs: true,\n componentStyle: true,\n displayName: true,\n foldedComponentIds: true,\n styledComponentId: true,\n target: true,\n withComponent: true,\n });\n }\n\n return WrappedStyledComponent;\n}\n","// @flow\nimport { EMPTY_ARRAY } from '../utils/empties';\nimport flatten from '../utils/flatten';\nimport isStaticRules from '../utils/isStaticRules';\nimport stringifyRules from '../utils/stringifyRules';\nimport StyleSheet from './StyleSheet';\n\nimport type { RuleSet } from '../types';\n\nexport default class GlobalStyle {\n componentId: string;\n\n isStatic: boolean;\n\n rules: RuleSet;\n\n constructor(rules: RuleSet, componentId: string) {\n this.rules = rules;\n this.componentId = componentId;\n this.isStatic = isStaticRules(rules, EMPTY_ARRAY);\n\n if (!StyleSheet.master.hasId(componentId)) {\n StyleSheet.master.deferredInject(componentId, []);\n }\n }\n\n createStyles(executionContext: Object, styleSheet: StyleSheet) {\n const flatCSS = flatten(this.rules, executionContext, styleSheet);\n const css = stringifyRules(flatCSS, '');\n\n styleSheet.inject(this.componentId, css);\n }\n\n removeStyles(styleSheet: StyleSheet) {\n const { componentId } = this;\n if (styleSheet.hasId(componentId)) {\n styleSheet.remove(componentId);\n }\n }\n\n // TODO: overwrite in-place instead of remove+create?\n renderStyles(executionContext: Object, styleSheet: StyleSheet) {\n this.removeStyles(styleSheet);\n this.createStyles(executionContext, styleSheet);\n }\n}\n"],"names":["i"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CC;;CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iEA+EuD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCCQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCCyI2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BC1J3B,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -461,7 +461,7 @@ var makeStyleTag = function makeStyleTag(target, tagEl, insertBefore) {
|
|
|
461
461
|
|
|
462
462
|
var el = targetDocument.createElement('style');
|
|
463
463
|
el.setAttribute(SC_ATTR, '');
|
|
464
|
-
el.setAttribute(SC_VERSION_ATTR, "4.4.
|
|
464
|
+
el.setAttribute(SC_VERSION_ATTR, "4.4.1");
|
|
465
465
|
|
|
466
466
|
var nonce = getNonce();
|
|
467
467
|
if (nonce) {
|
|
@@ -490,7 +490,7 @@ var makeStyleTag = function makeStyleTag(target, tagEl, insertBefore) {
|
|
|
490
490
|
var wrapAsHtmlTag = function wrapAsHtmlTag(css, names) {
|
|
491
491
|
return function (additionalAttrs) {
|
|
492
492
|
var nonce = getNonce();
|
|
493
|
-
var attrs = [nonce && 'nonce="' + nonce + '"', SC_ATTR + '="' + stringifyNames(names) + '"', SC_VERSION_ATTR + '="' + "4.4.
|
|
493
|
+
var attrs = [nonce && 'nonce="' + nonce + '"', SC_ATTR + '="' + stringifyNames(names) + '"', SC_VERSION_ATTR + '="' + "4.4.1" + '"', additionalAttrs];
|
|
494
494
|
|
|
495
495
|
var htmlAttr = attrs.filter(Boolean).join(' ');
|
|
496
496
|
return '<style ' + htmlAttr + '>' + css() + '</style>';
|
|
@@ -502,7 +502,7 @@ var wrapAsElement = function wrapAsElement(css, names) {
|
|
|
502
502
|
return function () {
|
|
503
503
|
var _props;
|
|
504
504
|
|
|
505
|
-
var props = (_props = {}, _props[SC_ATTR] = stringifyNames(names), _props[SC_VERSION_ATTR] = "4.4.
|
|
505
|
+
var props = (_props = {}, _props[SC_ATTR] = stringifyNames(names), _props[SC_VERSION_ATTR] = "4.4.1", _props);
|
|
506
506
|
|
|
507
507
|
var nonce = getNonce();
|
|
508
508
|
if (nonce) {
|
|
@@ -911,7 +911,7 @@ var StyleSheet = function () {
|
|
|
911
911
|
var isStreamed = false;
|
|
912
912
|
|
|
913
913
|
/* retrieve all of our SSR style elements from the DOM */
|
|
914
|
-
var nodes = document.querySelectorAll('style[' + SC_ATTR + '][' + SC_VERSION_ATTR + '="' + "4.4.
|
|
914
|
+
var nodes = document.querySelectorAll('style[' + SC_ATTR + '][' + SC_VERSION_ATTR + '="' + "4.4.1" + '"]');
|
|
915
915
|
|
|
916
916
|
var nodesSize = nodes.length;
|
|
917
917
|
|
|
@@ -1915,7 +1915,6 @@ process.env.NODE_ENV !== "production" ? StyleSheetManager.propTypes = {
|
|
|
1915
1915
|
|
|
1916
1916
|
//
|
|
1917
1917
|
|
|
1918
|
-
var THEME_PROP_REGEX = /\.theme[.[]/;
|
|
1919
1918
|
var identifiers = {};
|
|
1920
1919
|
|
|
1921
1920
|
/* We depend on components having unique IDs */
|
|
@@ -2004,24 +2003,14 @@ var StyledComponent = function (_Component) {
|
|
|
2004
2003
|
displayName = _props$forwardedCompo.displayName,
|
|
2005
2004
|
foldedComponentIds = _props$forwardedCompo.foldedComponentIds,
|
|
2006
2005
|
styledComponentId = _props$forwardedCompo.styledComponentId,
|
|
2007
|
-
target = _props$forwardedCompo.target
|
|
2008
|
-
usesTheme = _props$forwardedCompo.usesTheme;
|
|
2006
|
+
target = _props$forwardedCompo.target;
|
|
2009
2007
|
|
|
2010
2008
|
|
|
2011
2009
|
var generatedClassName = void 0;
|
|
2012
|
-
var rawTheme = void 0;
|
|
2013
|
-
|
|
2014
2010
|
if (componentStyle.isStatic) {
|
|
2015
2011
|
generatedClassName = this.generateAndInjectStyles(EMPTY_OBJECT, this.props);
|
|
2016
2012
|
} else {
|
|
2017
|
-
|
|
2018
|
-
generatedClassName = this.generateAndInjectStyles(rawTheme || EMPTY_OBJECT, this.props);
|
|
2019
|
-
|
|
2020
|
-
if (process.env.NODE_ENV !== 'production' && usesTheme && !rawTheme) {
|
|
2021
|
-
console.error('Component \'' +
|
|
2022
|
-
// $FlowFixMe
|
|
2023
|
-
displayName + '\' (.' + styledComponentId + ') references the \'theme\' prop in its styles but no theme was provided via prop or <ThemeProvider>.');
|
|
2024
|
-
}
|
|
2013
|
+
generatedClassName = this.generateAndInjectStyles(determineTheme(this.props, theme, defaultProps) || EMPTY_OBJECT, this.props);
|
|
2025
2014
|
}
|
|
2026
2015
|
|
|
2027
2016
|
var elementToBeCreated = this.props.as || this.attrs.as || target;
|
|
@@ -2208,11 +2197,6 @@ function createStyledComponent(target, options, rules) {
|
|
|
2208
2197
|
});
|
|
2209
2198
|
|
|
2210
2199
|
if (process.env.NODE_ENV !== 'production') {
|
|
2211
|
-
// $FlowFixMe
|
|
2212
|
-
WrappedStyledComponent.usesTheme = componentStyle.rules.some(function (x) {
|
|
2213
|
-
return isFunction(x) && THEME_PROP_REGEX.test(x.toString());
|
|
2214
|
-
});
|
|
2215
|
-
|
|
2216
2200
|
// $FlowFixMe
|
|
2217
2201
|
WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName);
|
|
2218
2202
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled-components.browser.esm.js","sources":["../src/models/StyleTags.js","../src/models/ThemeProvider.js","../src/models/StyleSheetManager.js","../src/models/StyledComponent.js","../src/models/GlobalStyle.js"],"sourcesContent":["// @flow\n/* eslint-disable flowtype/object-type-delimiter */\n/* eslint-disable react/prop-types */\n\nimport React, { type Element } from 'react';\nimport { IS_BROWSER, DISABLE_SPEEDY, SC_ATTR, SC_VERSION_ATTR } from '../constants';\nimport StyledError from '../utils/error';\nimport { type ExtractedComp } from '../utils/extractCompsFromCSS';\nimport { splitByRules } from '../utils/stringifyRules';\nimport getNonce from '../utils/nonce';\n\nimport {\n type Names,\n addNameForId,\n resetIdNames,\n hasNameForId,\n stringifyNames,\n cloneNames,\n} from '../utils/styleNames';\n\nimport { sheetForTag, safeInsertRule, deleteRules } from '../utils/insertRuleHelpers';\n\ndeclare var __VERSION__: string;\n\nexport interface Tag<T> {\n // $FlowFixMe: Doesn't seem to accept any combination w/ HTMLStyleElement for some reason\n styleTag: HTMLStyleElement | null;\n /* lists all ids of the tag */\n getIds(): string[];\n /* checks whether `name` is already injected for `id` */\n hasNameForId(id: string, name: string): boolean;\n /* inserts a marker to ensure the id's correct position in the sheet */\n insertMarker(id: string): T;\n /* inserts rules according to the ids markers */\n insertRules(id: string, cssRules: string[], name: ?string): void;\n /* removes all rules belonging to the id, keeping the marker around */\n removeRules(id: string): void;\n css(): string;\n toHTML(additionalAttrs: ?string): string;\n toElement(): Element<*>;\n clone(): Tag<T>;\n /* used in server side rendering to indicate that the rules in the tag have been flushed to HTML */\n sealed: boolean;\n}\n\n/* this marker separates component styles and is important for rehydration */\nconst makeTextMarker = id => `\\n/* sc-component-id: ${id} */\\n`;\n\n/* add up all numbers in array up until and including the index */\nconst addUpUntilIndex = (sizes: number[], index: number): number => {\n let totalUpToIndex = 0;\n for (let i = 0; i <= index; i += 1) {\n totalUpToIndex += sizes[i];\n }\n\n return totalUpToIndex;\n};\n\n/* create a new style tag after lastEl */\nconst makeStyleTag = (target: ?HTMLElement, tagEl: ?Node, insertBefore: ?boolean) => {\n let targetDocument = document;\n if(target) targetDocument = target.ownerDocument;\n else if(tagEl) targetDocument = tagEl.ownerDocument;\n\n const el = targetDocument.createElement('style');\n el.setAttribute(SC_ATTR, '');\n el.setAttribute(SC_VERSION_ATTR, __VERSION__);\n\n const nonce = getNonce();\n if (nonce) {\n el.setAttribute('nonce', nonce);\n }\n\n /* Work around insertRule quirk in EdgeHTML */\n el.appendChild(targetDocument.createTextNode(''));\n\n if (target && !tagEl) {\n /* Append to target when no previous element was passed */\n target.appendChild(el);\n } else {\n if (!tagEl || !target || !tagEl.parentNode) {\n throw new StyledError(6);\n }\n\n /* Insert new style tag after the previous one */\n tagEl.parentNode.insertBefore(el, insertBefore ? tagEl : tagEl.nextSibling);\n }\n\n return el;\n};\n\n/* takes a css factory function and outputs an html styled tag factory */\nconst wrapAsHtmlTag = (css: () => string, names: Names) => (additionalAttrs: ?string): string => {\n const nonce = getNonce();\n const attrs = [\n nonce && `nonce=\"${nonce}\"`,\n `${SC_ATTR}=\"${stringifyNames(names)}\"`,\n `${SC_VERSION_ATTR}=\"${__VERSION__}\"`,\n additionalAttrs,\n ];\n\n const htmlAttr = attrs.filter(Boolean).join(' ');\n return `<style ${htmlAttr}>${css()}</style>`;\n};\n\n/* takes a css factory function and outputs an element factory */\nconst wrapAsElement = (css: () => string, names: Names) => () => {\n const props = {\n [SC_ATTR]: stringifyNames(names),\n [SC_VERSION_ATTR]: __VERSION__,\n };\n\n const nonce = getNonce();\n if (nonce) {\n // $FlowFixMe\n props.nonce = nonce;\n }\n\n // eslint-disable-next-line react/no-danger\n return <style {...props} dangerouslySetInnerHTML={{ __html: css() }} />;\n};\n\nconst getIdsFromMarkersFactory = (markers: Object) => (): string[] => Object.keys(markers);\n\n/* speedy tags utilise insertRule */\nconst makeSpeedyTag = (el: HTMLStyleElement, getImportRuleTag: ?() => Tag<any>): Tag<number> => {\n const names: Names = (Object.create(null): Object);\n const markers = Object.create(null);\n const sizes: number[] = [];\n\n const extractImport = getImportRuleTag !== undefined;\n /* indicates whether getImportRuleTag was called */\n let usedImportRuleTag = false;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n markers[id] = sizes.length;\n sizes.push(0);\n resetIdNames(names, id);\n\n return markers[id];\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n const sheet = sheetForTag(el);\n const insertIndex = addUpUntilIndex(sizes, marker);\n\n let injectedRules = 0;\n const importRules = [];\n const cssRulesSize = cssRules.length;\n\n for (let i = 0; i < cssRulesSize; i += 1) {\n const cssRule = cssRules[i];\n let mayHaveImport = extractImport; /* @import rules are reordered to appear first */\n if (mayHaveImport && cssRule.indexOf('@import') !== -1) {\n importRules.push(cssRule);\n } else if (safeInsertRule(sheet, cssRule, insertIndex + injectedRules)) {\n mayHaveImport = false;\n injectedRules += 1;\n }\n }\n\n if (extractImport && importRules.length > 0) {\n usedImportRuleTag = true;\n // $FlowFixMe\n getImportRuleTag().insertRules(`${id}-import`, importRules);\n }\n\n sizes[marker] += injectedRules; /* add up no of injected rules */\n addNameForId(names, id, name);\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n // $FlowFixMe\n if (el.isConnected === false) return;\n\n const size = sizes[marker];\n const sheet = sheetForTag(el);\n const removalIndex = addUpUntilIndex(sizes, marker) - 1;\n deleteRules(sheet, removalIndex, size);\n sizes[marker] = 0;\n resetIdNames(names, id);\n\n if (extractImport && usedImportRuleTag) {\n // $FlowFixMe\n getImportRuleTag().removeRules(`${id}-import`);\n }\n };\n\n const css = () => {\n const { cssRules } = sheetForTag(el);\n let str = '';\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n str += makeTextMarker(id);\n const marker = markers[id];\n const end = addUpUntilIndex(sizes, marker);\n const size = sizes[marker];\n for (let i = end - size; i < end; i += 1) {\n const rule = cssRules[i];\n if (rule !== undefined) {\n str += rule.cssText;\n }\n }\n }\n\n return str;\n };\n\n return {\n clone() {\n throw new StyledError(5);\n },\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: el,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n};\n\nconst makeTextNode = (targetDocument, id) => targetDocument.createTextNode(makeTextMarker(id));\n\nconst makeBrowserTag = (el: HTMLStyleElement, getImportRuleTag: ?() => Tag<any>): Tag<Text> => {\n const names = (Object.create(null): Object);\n const markers = Object.create(null);\n\n const extractImport = getImportRuleTag !== undefined;\n\n /* indicates whether getImportRuleTag was called */\n let usedImportRuleTag = false;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n markers[id] = makeTextNode(el.ownerDocument, id);\n el.appendChild(markers[id]);\n names[id] = Object.create(null);\n\n return markers[id];\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n const importRules = [];\n const cssRulesSize = cssRules.length;\n\n for (let i = 0; i < cssRulesSize; i += 1) {\n const rule = cssRules[i];\n let mayHaveImport = extractImport;\n if (mayHaveImport && rule.indexOf('@import') !== -1) {\n importRules.push(rule);\n } else {\n mayHaveImport = false;\n const separator = i === cssRulesSize - 1 ? '' : ' ';\n marker.appendData(`${rule}${separator}`);\n }\n }\n\n addNameForId(names, id, name);\n\n if (extractImport && importRules.length > 0) {\n usedImportRuleTag = true;\n // $FlowFixMe\n getImportRuleTag().insertRules(`${id}-import`, importRules);\n }\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n\n /* create new empty text node and replace the current one */\n const newMarker = makeTextNode(el.ownerDocument, id);\n el.replaceChild(newMarker, marker);\n markers[id] = newMarker;\n resetIdNames(names, id);\n\n if (extractImport && usedImportRuleTag) {\n // $FlowFixMe\n getImportRuleTag().removeRules(`${id}-import`);\n }\n };\n\n const css = () => {\n let str = '';\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n str += markers[id].data;\n }\n\n return str;\n };\n\n return {\n clone() {\n throw new StyledError(5);\n },\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: el,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n};\n\nconst makeServerTag = (namesArg, markersArg): Tag<[string]> => {\n const names = namesArg === undefined ? (Object.create(null): Object) : namesArg;\n const markers = markersArg === undefined ? Object.create(null) : markersArg;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n return (markers[id] = ['']);\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n marker[0] += cssRules.join(' ');\n addNameForId(names, id, name);\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n marker[0] = '';\n resetIdNames(names, id);\n };\n\n const css = () => {\n let str = '';\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n const cssForId = markers[id][0];\n if (cssForId) {\n str += makeTextMarker(id) + cssForId;\n }\n }\n return str;\n };\n\n const clone = () => {\n const namesClone = cloneNames(names);\n const markersClone = Object.create(null);\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n markersClone[id] = [markers[id][0]];\n }\n\n return makeServerTag(namesClone, markersClone);\n };\n\n const tag = {\n clone,\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: null,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n\n return tag;\n};\n\nexport const makeTag = (\n target: ?HTMLElement,\n tagEl: ?HTMLStyleElement,\n forceServer?: boolean,\n insertBefore?: boolean,\n getImportRuleTag?: () => Tag<any>\n): Tag<any> => {\n if (IS_BROWSER && !forceServer) {\n const el = makeStyleTag(target, tagEl, insertBefore);\n\n if (DISABLE_SPEEDY) {\n return makeBrowserTag(el, getImportRuleTag);\n } else {\n return makeSpeedyTag(el, getImportRuleTag);\n }\n }\n\n return makeServerTag();\n};\n\nexport const rehydrate = (\n tag: Tag<any>,\n els: HTMLStyleElement[],\n extracted: ExtractedComp[]\n): void => {\n /* add all extracted components to the new tag */\n for (let i = 0, len = extracted.length; i < len; i += 1) {\n const { componentId, cssFromDOM } = extracted[i];\n const cssRules = splitByRules(cssFromDOM);\n tag.insertRules(componentId, cssRules);\n }\n\n /* remove old HTMLStyleElements, since they have been rehydrated */\n for (let i = 0, len = els.length; i < len; i += 1) {\n const el = els[i];\n if (el.parentNode) {\n el.parentNode.removeChild(el);\n }\n }\n};\n","// @flow\nimport React, { createContext, Component, type Element } from 'react';\nimport memoize from 'memoize-one';\nimport StyledError from '../utils/error';\nimport isFunction from '../utils/isFunction';\n\nexport type Theme = { [key: string]: mixed };\n\ntype Props = {\n children?: Element<any>,\n theme: Theme | ((outerTheme: Theme) => void),\n};\n\nexport const ThemeContext = createContext();\n\nexport const ThemeConsumer = ThemeContext.Consumer;\n\n/**\n * Provide a theme to an entire react component tree via context\n */\nexport default class ThemeProvider extends Component<Props> {\n getContext: (theme: Theme | ((outerTheme: Theme) => void), outerTheme?: Theme) => Theme;\n\n renderInner: Function;\n\n constructor(props: Props) {\n super(props);\n this.getContext = memoize(this.getContext.bind(this));\n this.renderInner = this.renderInner.bind(this);\n }\n\n render() {\n if (!this.props.children) return null;\n\n return <ThemeContext.Consumer>{this.renderInner}</ThemeContext.Consumer>;\n }\n\n renderInner(outerTheme?: Theme) {\n const context = this.getContext(this.props.theme, outerTheme);\n\n return (\n <ThemeContext.Provider value={context}>\n {this.props.children}\n </ThemeContext.Provider>\n );\n }\n\n /**\n * Get the theme from the props, supporting both (outerTheme) => {}\n * as well as object notation\n */\n getTheme(theme: (outerTheme: ?Theme) => void, outerTheme: ?Theme) {\n if (isFunction(theme)) {\n const mergedTheme = theme(outerTheme);\n\n if (\n process.env.NODE_ENV !== 'production' &&\n (mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')\n ) {\n throw new StyledError(7);\n }\n\n return mergedTheme;\n }\n\n if (theme === null || Array.isArray(theme) || typeof theme !== 'object') {\n throw new StyledError(8);\n }\n\n return { ...outerTheme, ...theme };\n }\n\n getContext(theme: (outerTheme: ?Theme) => void, outerTheme?: Theme) {\n return this.getTheme(theme, outerTheme);\n }\n}\n","// @flow\nimport React, { createContext, Component, type Element } from 'react';\nimport PropTypes from 'prop-types';\nimport memoize from 'memoize-one';\nimport StyleSheet from './StyleSheet';\nimport ServerStyleSheet from './ServerStyleSheet';\nimport StyledError from '../utils/error';\n\ntype Props = {\n children?: Element<any>,\n sheet?: StyleSheet,\n target?: HTMLElement,\n};\n\nexport const StyleSheetContext = createContext();\nexport const StyleSheetConsumer = StyleSheetContext.Consumer;\n\nexport default class StyleSheetManager extends Component<Props> {\n static propTypes = {\n sheet: PropTypes.oneOfType([\n PropTypes.instanceOf(StyleSheet),\n PropTypes.instanceOf(ServerStyleSheet),\n ]),\n\n target: PropTypes.shape({\n appendChild: PropTypes.func.isRequired,\n }),\n };\n\n getContext: (sheet: ?StyleSheet, target: ?HTMLElement) => StyleSheet;\n\n constructor(props: Props) {\n super(props);\n this.getContext = memoize(this.getContext);\n }\n\n getContext(sheet: ?StyleSheet, target: ?HTMLElement) {\n if (sheet) {\n return sheet;\n } else if (target) {\n return new StyleSheet(target);\n } else {\n throw new StyledError(4);\n }\n }\n\n render() {\n const { children, sheet, target } = this.props;\n\n return (\n <StyleSheetContext.Provider value={this.getContext(sheet, target)}>\n {process.env.NODE_ENV !== 'production' ? React.Children.only(children) : children}\n </StyleSheetContext.Provider>\n );\n }\n}\n","// @flow\nimport validAttr from '@emotion/is-prop-valid';\nimport merge from 'merge-anything';\nimport React, { createElement, Component } from 'react';\nimport ComponentStyle from './ComponentStyle';\nimport createWarnTooManyClasses from '../utils/createWarnTooManyClasses';\nimport determineTheme from '../utils/determineTheme';\nimport escape from '../utils/escape';\nimport generateDisplayName from '../utils/generateDisplayName';\nimport getComponentName from '../utils/getComponentName';\nimport hoist from '../utils/hoist';\nimport isFunction from '../utils/isFunction';\nimport isTag from '../utils/isTag';\nimport isDerivedReactComponent from '../utils/isDerivedReactComponent';\nimport isStyledComponent from '../utils/isStyledComponent';\nimport once from '../utils/once';\nimport StyleSheet from './StyleSheet';\nimport { ThemeConsumer, type Theme } from './ThemeProvider';\nimport { StyleSheetConsumer } from './StyleSheetManager';\nimport { EMPTY_ARRAY, EMPTY_OBJECT } from '../utils/empties';\n\nimport type { Attrs, RuleSet, Target } from '../types';\n\nconst THEME_PROP_REGEX = /\\.theme[.[]/;\nconst identifiers = {};\n\n/* We depend on components having unique IDs */\nfunction generateId(_ComponentStyle: Function, _displayName: string, parentComponentId: string) {\n const displayName = typeof _displayName !== 'string' ? 'sc' : escape(_displayName);\n\n /**\n * This ensures uniqueness if two components happen to share\n * the same displayName.\n */\n const nr = (identifiers[displayName] || 0) + 1;\n identifiers[displayName] = nr;\n\n const componentId = `${displayName}-${_ComponentStyle.generateName(displayName + nr)}`;\n\n return parentComponentId ? `${parentComponentId}-${componentId}` : componentId;\n}\n\n// $FlowFixMe\nclass StyledComponent extends Component<*> {\n renderOuter: Function;\n\n renderInner: Function;\n\n styleSheet: ?StyleSheet;\n\n warnInnerRef: Function;\n\n warnAttrsFnObjectKeyDeprecated: Function;\n\n warnNonStyledComponentAttrsObjectKey: Function;\n\n attrs = {};\n\n constructor() {\n super();\n this.renderOuter = this.renderOuter.bind(this);\n this.renderInner = this.renderInner.bind(this);\n\n if (process.env.NODE_ENV !== 'production') {\n this.warnInnerRef = once(displayName =>\n // eslint-disable-next-line no-console\n console.warn(\n `The \"innerRef\" API has been removed in styled-components v4 in favor of React 16 ref forwarding, use \"ref\" instead like a typical component. \"innerRef\" was detected on component \"${displayName}\".`\n )\n );\n\n this.warnAttrsFnObjectKeyDeprecated = once(\n (key, displayName): void =>\n // eslint-disable-next-line no-console\n console.warn(\n `Functions as object-form attrs({}) keys are now deprecated and will be removed in a future version of styled-components. Switch to the new attrs(props => ({})) syntax instead for easier and more powerful composition. The attrs key in question is \"${key}\" on component \"${displayName}\".`,\n `\\n ${new Error().stack}`\n )\n );\n\n this.warnNonStyledComponentAttrsObjectKey = once(\n (key, displayName): void =>\n // eslint-disable-next-line no-console\n console.warn(\n `It looks like you've used a non styled-component as the value for the \"${key}\" prop in an object-form attrs constructor of \"${displayName}\".\\n` +\n 'You should use the new function-form attrs constructor which avoids this issue: attrs(props => ({ yourStuff }))\\n' +\n \"To continue using the deprecated object syntax, you'll need to wrap your component prop in a function to make it available inside the styled component (you'll still get the deprecation warning though.)\\n\" +\n `For example, { ${key}: () => InnerComponent } instead of { ${key}: InnerComponent }`\n )\n );\n }\n }\n\n render() {\n return <StyleSheetConsumer>{this.renderOuter}</StyleSheetConsumer>;\n }\n\n renderOuter(styleSheet?: StyleSheet = StyleSheet.master) {\n this.styleSheet = styleSheet;\n\n // No need to subscribe a static component to theme changes, it won't change anything\n if (this.props.forwardedComponent.componentStyle.isStatic) return this.renderInner();\n\n return <ThemeConsumer>{this.renderInner}</ThemeConsumer>;\n }\n\n renderInner(theme?: Theme) {\n const {\n componentStyle,\n defaultProps,\n displayName,\n foldedComponentIds,\n styledComponentId,\n target,\n usesTheme,\n } = this.props.forwardedComponent;\n\n let generatedClassName;\n let rawTheme;\n\n if (componentStyle.isStatic) {\n generatedClassName = this.generateAndInjectStyles(EMPTY_OBJECT, this.props);\n } else {\n rawTheme = determineTheme(this.props, theme, defaultProps);\n generatedClassName = this.generateAndInjectStyles(rawTheme || EMPTY_OBJECT, this.props);\n\n if (process.env.NODE_ENV !== 'production' && usesTheme && !rawTheme) {\n console.error(\n `Component '${\n // $FlowFixMe\n displayName\n }' (.${styledComponentId}) references the 'theme' prop in its styles but no theme was provided via prop or <ThemeProvider>.`\n );\n }\n }\n\n const elementToBeCreated = this.props.as || this.attrs.as || target;\n const isTargetTag = isTag(elementToBeCreated);\n\n const propsForElement = {};\n const computedProps = { ...this.props, ...this.attrs };\n\n let key;\n // eslint-disable-next-line guard-for-in\n for (key in computedProps) {\n if (process.env.NODE_ENV !== 'production' && key === 'innerRef' && isTargetTag) {\n this.warnInnerRef(displayName);\n }\n\n if (key === 'forwardedComponent' || key === 'as') {\n continue;\n } else if (key === 'forwardedRef') propsForElement.ref = computedProps[key];\n else if (key === 'forwardedAs') propsForElement.as = computedProps[key];\n else if (!isTargetTag || validAttr(key)) {\n // Don't pass through non HTML tags through to HTML elements\n propsForElement[key] = computedProps[key];\n }\n }\n\n if (this.props.style && this.attrs.style) {\n propsForElement.style = { ...this.attrs.style, ...this.props.style };\n }\n\n propsForElement.className = Array.prototype\n .concat(\n foldedComponentIds,\n styledComponentId,\n generatedClassName !== styledComponentId ? generatedClassName : null,\n this.props.className,\n this.attrs.className\n )\n .filter(Boolean)\n .join(' ');\n\n return createElement(elementToBeCreated, propsForElement);\n }\n\n buildExecutionContext(theme: ?Object, props: Object, attrs: Attrs) {\n const context = { ...props, theme };\n\n if (!attrs.length) return context;\n\n this.attrs = {};\n\n attrs.forEach(attrDef => {\n let resolvedAttrDef = attrDef;\n let attrDefWasFn = false;\n let attr;\n let key;\n\n if (isFunction(resolvedAttrDef)) {\n // $FlowFixMe\n resolvedAttrDef = resolvedAttrDef(context);\n attrDefWasFn = true;\n }\n\n /* eslint-disable guard-for-in */\n // $FlowFixMe\n for (key in resolvedAttrDef) {\n attr = resolvedAttrDef[key];\n\n if (!attrDefWasFn) {\n if (isFunction(attr) && !isDerivedReactComponent(attr) && !isStyledComponent(attr)) {\n if (process.env.NODE_ENV !== 'production') {\n this.warnAttrsFnObjectKeyDeprecated(key, props.forwardedComponent.displayName);\n }\n\n attr = attr(context);\n\n if (process.env.NODE_ENV !== 'production' && React.isValidElement(attr)) {\n this.warnNonStyledComponentAttrsObjectKey(key, props.forwardedComponent.displayName);\n }\n }\n }\n\n this.attrs[key] = attr;\n context[key] = attr;\n }\n /* eslint-enable */\n });\n\n return context;\n }\n\n generateAndInjectStyles(theme: any, props: any) {\n const { attrs, componentStyle, warnTooManyClasses } = props.forwardedComponent;\n\n // statically styled-components don't need to build an execution context object,\n // and shouldn't be increasing the number of class names\n if (componentStyle.isStatic && !attrs.length) {\n return componentStyle.generateAndInjectStyles(EMPTY_OBJECT, this.styleSheet);\n }\n\n const className = componentStyle.generateAndInjectStyles(\n this.buildExecutionContext(theme, props, attrs),\n this.styleSheet\n );\n\n if (process.env.NODE_ENV !== 'production' && warnTooManyClasses) warnTooManyClasses(className);\n\n return className;\n }\n}\n\nexport default function createStyledComponent(target: Target, options: Object, rules: RuleSet) {\n const isTargetStyledComp = isStyledComponent(target);\n const isClass = !isTag(target);\n\n const {\n displayName = generateDisplayName(target),\n componentId = generateId(ComponentStyle, options.displayName, options.parentComponentId),\n ParentComponent = StyledComponent,\n attrs = EMPTY_ARRAY,\n } = options;\n\n const styledComponentId =\n options.displayName && options.componentId\n ? `${escape(options.displayName)}-${options.componentId}`\n : options.componentId || componentId;\n\n // fold the underlying StyledComponent attrs up (implicit extend)\n const finalAttrs =\n // $FlowFixMe\n isTargetStyledComp && target.attrs\n ? Array.prototype.concat(target.attrs, attrs).filter(Boolean)\n : attrs;\n\n const componentStyle = new ComponentStyle(\n isTargetStyledComp\n ? // fold the underlying StyledComponent rules up (implicit extend)\n // $FlowFixMe\n target.componentStyle.rules.concat(rules)\n : rules,\n finalAttrs,\n styledComponentId\n );\n\n /**\n * forwardRef creates a new interim component, which we'll take advantage of\n * instead of extending ParentComponent to create _another_ interim class\n */\n let WrappedStyledComponent;\n const forwardRef = (props, ref) => (\n <ParentComponent {...props} forwardedComponent={WrappedStyledComponent} forwardedRef={ref} />\n );\n forwardRef.displayName = displayName;\n WrappedStyledComponent = React.forwardRef(forwardRef);\n WrappedStyledComponent.displayName = displayName;\n\n // $FlowFixMe\n WrappedStyledComponent.attrs = finalAttrs;\n // $FlowFixMe\n WrappedStyledComponent.componentStyle = componentStyle;\n\n // $FlowFixMe\n WrappedStyledComponent.foldedComponentIds = isTargetStyledComp\n ? // $FlowFixMe\n Array.prototype.concat(target.foldedComponentIds, target.styledComponentId)\n : EMPTY_ARRAY;\n\n // $FlowFixMe\n WrappedStyledComponent.styledComponentId = styledComponentId;\n\n // fold the underlying StyledComponent target up since we folded the styles\n // $FlowFixMe\n WrappedStyledComponent.target = isTargetStyledComp ? target.target : target;\n\n // $FlowFixMe\n WrappedStyledComponent.withComponent = function withComponent(tag: Target) {\n const { componentId: previousComponentId, ...optionsToCopy } = options;\n\n const newComponentId =\n previousComponentId &&\n `${previousComponentId}-${isTag(tag) ? tag : escape(getComponentName(tag))}`;\n\n const newOptions = {\n ...optionsToCopy,\n attrs: finalAttrs,\n componentId: newComponentId,\n ParentComponent,\n };\n\n return createStyledComponent(tag, newOptions, rules);\n };\n\n // $FlowFixMe\n Object.defineProperty(WrappedStyledComponent, 'defaultProps', {\n get() {\n return this._foldedDefaultProps;\n },\n\n set(obj) {\n // $FlowFixMe\n this._foldedDefaultProps = isTargetStyledComp ? merge(target.defaultProps, obj) : obj;\n },\n });\n\n if (process.env.NODE_ENV !== 'production') {\n // $FlowFixMe\n WrappedStyledComponent.usesTheme = componentStyle.rules.some(\n x => isFunction(x) && THEME_PROP_REGEX.test(x.toString())\n );\n\n // $FlowFixMe\n WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName);\n }\n\n // $FlowFixMe\n WrappedStyledComponent.toString = () => `.${WrappedStyledComponent.styledComponentId}`;\n\n if (isClass) {\n hoist(WrappedStyledComponent, target, {\n // all SC-specific things should not be hoisted\n attrs: true,\n componentStyle: true,\n displayName: true,\n foldedComponentIds: true,\n styledComponentId: true,\n target: true,\n withComponent: true,\n });\n }\n\n return WrappedStyledComponent;\n}\n","// @flow\nimport { EMPTY_ARRAY } from '../utils/empties';\nimport flatten from '../utils/flatten';\nimport isStaticRules from '../utils/isStaticRules';\nimport stringifyRules from '../utils/stringifyRules';\nimport StyleSheet from './StyleSheet';\n\nimport type { RuleSet } from '../types';\n\nexport default class GlobalStyle {\n componentId: string;\n\n isStatic: boolean;\n\n rules: RuleSet;\n\n constructor(rules: RuleSet, componentId: string) {\n this.rules = rules;\n this.componentId = componentId;\n this.isStatic = isStaticRules(rules, EMPTY_ARRAY);\n\n if (!StyleSheet.master.hasId(componentId)) {\n StyleSheet.master.deferredInject(componentId, []);\n }\n }\n\n createStyles(executionContext: Object, styleSheet: StyleSheet) {\n const flatCSS = flatten(this.rules, executionContext, styleSheet);\n const css = stringifyRules(flatCSS, '');\n\n styleSheet.inject(this.componentId, css);\n }\n\n removeStyles(styleSheet: StyleSheet) {\n const { componentId } = this;\n if (styleSheet.hasId(componentId)) {\n styleSheet.remove(componentId);\n }\n }\n\n // TODO: overwrite in-place instead of remove+create?\n renderStyles(executionContext: Object, styleSheet: StyleSheet) {\n this.removeStyles(styleSheet);\n this.createStyles(executionContext, styleSheet);\n }\n}\n"],"names":["i"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"styled-components.browser.esm.js","sources":["../src/models/StyleTags.js","../src/models/ThemeProvider.js","../src/models/StyleSheetManager.js","../src/models/StyledComponent.js","../src/models/GlobalStyle.js"],"sourcesContent":["// @flow\n/* eslint-disable flowtype/object-type-delimiter */\n/* eslint-disable react/prop-types */\n\nimport React, { type Element } from 'react';\nimport { IS_BROWSER, DISABLE_SPEEDY, SC_ATTR, SC_VERSION_ATTR } from '../constants';\nimport StyledError from '../utils/error';\nimport { type ExtractedComp } from '../utils/extractCompsFromCSS';\nimport { splitByRules } from '../utils/stringifyRules';\nimport getNonce from '../utils/nonce';\n\nimport {\n type Names,\n addNameForId,\n resetIdNames,\n hasNameForId,\n stringifyNames,\n cloneNames,\n} from '../utils/styleNames';\n\nimport { sheetForTag, safeInsertRule, deleteRules } from '../utils/insertRuleHelpers';\n\ndeclare var __VERSION__: string;\n\nexport interface Tag<T> {\n // $FlowFixMe: Doesn't seem to accept any combination w/ HTMLStyleElement for some reason\n styleTag: HTMLStyleElement | null;\n /* lists all ids of the tag */\n getIds(): string[];\n /* checks whether `name` is already injected for `id` */\n hasNameForId(id: string, name: string): boolean;\n /* inserts a marker to ensure the id's correct position in the sheet */\n insertMarker(id: string): T;\n /* inserts rules according to the ids markers */\n insertRules(id: string, cssRules: string[], name: ?string): void;\n /* removes all rules belonging to the id, keeping the marker around */\n removeRules(id: string): void;\n css(): string;\n toHTML(additionalAttrs: ?string): string;\n toElement(): Element<*>;\n clone(): Tag<T>;\n /* used in server side rendering to indicate that the rules in the tag have been flushed to HTML */\n sealed: boolean;\n}\n\n/* this marker separates component styles and is important for rehydration */\nconst makeTextMarker = id => `\\n/* sc-component-id: ${id} */\\n`;\n\n/* add up all numbers in array up until and including the index */\nconst addUpUntilIndex = (sizes: number[], index: number): number => {\n let totalUpToIndex = 0;\n for (let i = 0; i <= index; i += 1) {\n totalUpToIndex += sizes[i];\n }\n\n return totalUpToIndex;\n};\n\n/* create a new style tag after lastEl */\nconst makeStyleTag = (target: ?HTMLElement, tagEl: ?Node, insertBefore: ?boolean) => {\n let targetDocument = document;\n if(target) targetDocument = target.ownerDocument;\n else if(tagEl) targetDocument = tagEl.ownerDocument;\n\n const el = targetDocument.createElement('style');\n el.setAttribute(SC_ATTR, '');\n el.setAttribute(SC_VERSION_ATTR, __VERSION__);\n\n const nonce = getNonce();\n if (nonce) {\n el.setAttribute('nonce', nonce);\n }\n\n /* Work around insertRule quirk in EdgeHTML */\n el.appendChild(targetDocument.createTextNode(''));\n\n if (target && !tagEl) {\n /* Append to target when no previous element was passed */\n target.appendChild(el);\n } else {\n if (!tagEl || !target || !tagEl.parentNode) {\n throw new StyledError(6);\n }\n\n /* Insert new style tag after the previous one */\n tagEl.parentNode.insertBefore(el, insertBefore ? tagEl : tagEl.nextSibling);\n }\n\n return el;\n};\n\n/* takes a css factory function and outputs an html styled tag factory */\nconst wrapAsHtmlTag = (css: () => string, names: Names) => (additionalAttrs: ?string): string => {\n const nonce = getNonce();\n const attrs = [\n nonce && `nonce=\"${nonce}\"`,\n `${SC_ATTR}=\"${stringifyNames(names)}\"`,\n `${SC_VERSION_ATTR}=\"${__VERSION__}\"`,\n additionalAttrs,\n ];\n\n const htmlAttr = attrs.filter(Boolean).join(' ');\n return `<style ${htmlAttr}>${css()}</style>`;\n};\n\n/* takes a css factory function and outputs an element factory */\nconst wrapAsElement = (css: () => string, names: Names) => () => {\n const props = {\n [SC_ATTR]: stringifyNames(names),\n [SC_VERSION_ATTR]: __VERSION__,\n };\n\n const nonce = getNonce();\n if (nonce) {\n // $FlowFixMe\n props.nonce = nonce;\n }\n\n // eslint-disable-next-line react/no-danger\n return <style {...props} dangerouslySetInnerHTML={{ __html: css() }} />;\n};\n\nconst getIdsFromMarkersFactory = (markers: Object) => (): string[] => Object.keys(markers);\n\n/* speedy tags utilise insertRule */\nconst makeSpeedyTag = (el: HTMLStyleElement, getImportRuleTag: ?() => Tag<any>): Tag<number> => {\n const names: Names = (Object.create(null): Object);\n const markers = Object.create(null);\n const sizes: number[] = [];\n\n const extractImport = getImportRuleTag !== undefined;\n /* indicates whether getImportRuleTag was called */\n let usedImportRuleTag = false;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n markers[id] = sizes.length;\n sizes.push(0);\n resetIdNames(names, id);\n\n return markers[id];\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n const sheet = sheetForTag(el);\n const insertIndex = addUpUntilIndex(sizes, marker);\n\n let injectedRules = 0;\n const importRules = [];\n const cssRulesSize = cssRules.length;\n\n for (let i = 0; i < cssRulesSize; i += 1) {\n const cssRule = cssRules[i];\n let mayHaveImport = extractImport; /* @import rules are reordered to appear first */\n if (mayHaveImport && cssRule.indexOf('@import') !== -1) {\n importRules.push(cssRule);\n } else if (safeInsertRule(sheet, cssRule, insertIndex + injectedRules)) {\n mayHaveImport = false;\n injectedRules += 1;\n }\n }\n\n if (extractImport && importRules.length > 0) {\n usedImportRuleTag = true;\n // $FlowFixMe\n getImportRuleTag().insertRules(`${id}-import`, importRules);\n }\n\n sizes[marker] += injectedRules; /* add up no of injected rules */\n addNameForId(names, id, name);\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n // $FlowFixMe\n if (el.isConnected === false) return;\n\n const size = sizes[marker];\n const sheet = sheetForTag(el);\n const removalIndex = addUpUntilIndex(sizes, marker) - 1;\n deleteRules(sheet, removalIndex, size);\n sizes[marker] = 0;\n resetIdNames(names, id);\n\n if (extractImport && usedImportRuleTag) {\n // $FlowFixMe\n getImportRuleTag().removeRules(`${id}-import`);\n }\n };\n\n const css = () => {\n const { cssRules } = sheetForTag(el);\n let str = '';\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n str += makeTextMarker(id);\n const marker = markers[id];\n const end = addUpUntilIndex(sizes, marker);\n const size = sizes[marker];\n for (let i = end - size; i < end; i += 1) {\n const rule = cssRules[i];\n if (rule !== undefined) {\n str += rule.cssText;\n }\n }\n }\n\n return str;\n };\n\n return {\n clone() {\n throw new StyledError(5);\n },\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: el,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n};\n\nconst makeTextNode = (targetDocument, id) => targetDocument.createTextNode(makeTextMarker(id));\n\nconst makeBrowserTag = (el: HTMLStyleElement, getImportRuleTag: ?() => Tag<any>): Tag<Text> => {\n const names = (Object.create(null): Object);\n const markers = Object.create(null);\n\n const extractImport = getImportRuleTag !== undefined;\n\n /* indicates whether getImportRuleTag was called */\n let usedImportRuleTag = false;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n markers[id] = makeTextNode(el.ownerDocument, id);\n el.appendChild(markers[id]);\n names[id] = Object.create(null);\n\n return markers[id];\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n const importRules = [];\n const cssRulesSize = cssRules.length;\n\n for (let i = 0; i < cssRulesSize; i += 1) {\n const rule = cssRules[i];\n let mayHaveImport = extractImport;\n if (mayHaveImport && rule.indexOf('@import') !== -1) {\n importRules.push(rule);\n } else {\n mayHaveImport = false;\n const separator = i === cssRulesSize - 1 ? '' : ' ';\n marker.appendData(`${rule}${separator}`);\n }\n }\n\n addNameForId(names, id, name);\n\n if (extractImport && importRules.length > 0) {\n usedImportRuleTag = true;\n // $FlowFixMe\n getImportRuleTag().insertRules(`${id}-import`, importRules);\n }\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n\n /* create new empty text node and replace the current one */\n const newMarker = makeTextNode(el.ownerDocument, id);\n el.replaceChild(newMarker, marker);\n markers[id] = newMarker;\n resetIdNames(names, id);\n\n if (extractImport && usedImportRuleTag) {\n // $FlowFixMe\n getImportRuleTag().removeRules(`${id}-import`);\n }\n };\n\n const css = () => {\n let str = '';\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n str += markers[id].data;\n }\n\n return str;\n };\n\n return {\n clone() {\n throw new StyledError(5);\n },\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: el,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n};\n\nconst makeServerTag = (namesArg, markersArg): Tag<[string]> => {\n const names = namesArg === undefined ? (Object.create(null): Object) : namesArg;\n const markers = markersArg === undefined ? Object.create(null) : markersArg;\n\n const insertMarker = id => {\n const prev = markers[id];\n if (prev !== undefined) {\n return prev;\n }\n\n return (markers[id] = ['']);\n };\n\n const insertRules = (id, cssRules, name) => {\n const marker = insertMarker(id);\n marker[0] += cssRules.join(' ');\n addNameForId(names, id, name);\n };\n\n const removeRules = id => {\n const marker = markers[id];\n if (marker === undefined) return;\n marker[0] = '';\n resetIdNames(names, id);\n };\n\n const css = () => {\n let str = '';\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n const cssForId = markers[id][0];\n if (cssForId) {\n str += makeTextMarker(id) + cssForId;\n }\n }\n return str;\n };\n\n const clone = () => {\n const namesClone = cloneNames(names);\n const markersClone = Object.create(null);\n\n // eslint-disable-next-line guard-for-in\n for (const id in markers) {\n markersClone[id] = [markers[id][0]];\n }\n\n return makeServerTag(namesClone, markersClone);\n };\n\n const tag = {\n clone,\n css,\n getIds: getIdsFromMarkersFactory(markers),\n hasNameForId: hasNameForId(names),\n insertMarker,\n insertRules,\n removeRules,\n sealed: false,\n styleTag: null,\n toElement: wrapAsElement(css, names),\n toHTML: wrapAsHtmlTag(css, names),\n };\n\n return tag;\n};\n\nexport const makeTag = (\n target: ?HTMLElement,\n tagEl: ?HTMLStyleElement,\n forceServer?: boolean,\n insertBefore?: boolean,\n getImportRuleTag?: () => Tag<any>\n): Tag<any> => {\n if (IS_BROWSER && !forceServer) {\n const el = makeStyleTag(target, tagEl, insertBefore);\n\n if (DISABLE_SPEEDY) {\n return makeBrowserTag(el, getImportRuleTag);\n } else {\n return makeSpeedyTag(el, getImportRuleTag);\n }\n }\n\n return makeServerTag();\n};\n\nexport const rehydrate = (\n tag: Tag<any>,\n els: HTMLStyleElement[],\n extracted: ExtractedComp[]\n): void => {\n /* add all extracted components to the new tag */\n for (let i = 0, len = extracted.length; i < len; i += 1) {\n const { componentId, cssFromDOM } = extracted[i];\n const cssRules = splitByRules(cssFromDOM);\n tag.insertRules(componentId, cssRules);\n }\n\n /* remove old HTMLStyleElements, since they have been rehydrated */\n for (let i = 0, len = els.length; i < len; i += 1) {\n const el = els[i];\n if (el.parentNode) {\n el.parentNode.removeChild(el);\n }\n }\n};\n","// @flow\nimport React, { createContext, Component, type Element } from 'react';\nimport memoize from 'memoize-one';\nimport StyledError from '../utils/error';\nimport isFunction from '../utils/isFunction';\n\nexport type Theme = { [key: string]: mixed };\n\ntype Props = {\n children?: Element<any>,\n theme: Theme | ((outerTheme: Theme) => void),\n};\n\nexport const ThemeContext = createContext();\n\nexport const ThemeConsumer = ThemeContext.Consumer;\n\n/**\n * Provide a theme to an entire react component tree via context\n */\nexport default class ThemeProvider extends Component<Props> {\n getContext: (theme: Theme | ((outerTheme: Theme) => void), outerTheme?: Theme) => Theme;\n\n renderInner: Function;\n\n constructor(props: Props) {\n super(props);\n this.getContext = memoize(this.getContext.bind(this));\n this.renderInner = this.renderInner.bind(this);\n }\n\n render() {\n if (!this.props.children) return null;\n\n return <ThemeContext.Consumer>{this.renderInner}</ThemeContext.Consumer>;\n }\n\n renderInner(outerTheme?: Theme) {\n const context = this.getContext(this.props.theme, outerTheme);\n\n return (\n <ThemeContext.Provider value={context}>\n {this.props.children}\n </ThemeContext.Provider>\n );\n }\n\n /**\n * Get the theme from the props, supporting both (outerTheme) => {}\n * as well as object notation\n */\n getTheme(theme: (outerTheme: ?Theme) => void, outerTheme: ?Theme) {\n if (isFunction(theme)) {\n const mergedTheme = theme(outerTheme);\n\n if (\n process.env.NODE_ENV !== 'production' &&\n (mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')\n ) {\n throw new StyledError(7);\n }\n\n return mergedTheme;\n }\n\n if (theme === null || Array.isArray(theme) || typeof theme !== 'object') {\n throw new StyledError(8);\n }\n\n return { ...outerTheme, ...theme };\n }\n\n getContext(theme: (outerTheme: ?Theme) => void, outerTheme?: Theme) {\n return this.getTheme(theme, outerTheme);\n }\n}\n","// @flow\nimport React, { createContext, Component, type Element } from 'react';\nimport PropTypes from 'prop-types';\nimport memoize from 'memoize-one';\nimport StyleSheet from './StyleSheet';\nimport ServerStyleSheet from './ServerStyleSheet';\nimport StyledError from '../utils/error';\n\ntype Props = {\n children?: Element<any>,\n sheet?: StyleSheet,\n target?: HTMLElement,\n};\n\nexport const StyleSheetContext = createContext();\nexport const StyleSheetConsumer = StyleSheetContext.Consumer;\n\nexport default class StyleSheetManager extends Component<Props> {\n static propTypes = {\n sheet: PropTypes.oneOfType([\n PropTypes.instanceOf(StyleSheet),\n PropTypes.instanceOf(ServerStyleSheet),\n ]),\n\n target: PropTypes.shape({\n appendChild: PropTypes.func.isRequired,\n }),\n };\n\n getContext: (sheet: ?StyleSheet, target: ?HTMLElement) => StyleSheet;\n\n constructor(props: Props) {\n super(props);\n this.getContext = memoize(this.getContext);\n }\n\n getContext(sheet: ?StyleSheet, target: ?HTMLElement) {\n if (sheet) {\n return sheet;\n } else if (target) {\n return new StyleSheet(target);\n } else {\n throw new StyledError(4);\n }\n }\n\n render() {\n const { children, sheet, target } = this.props;\n\n return (\n <StyleSheetContext.Provider value={this.getContext(sheet, target)}>\n {process.env.NODE_ENV !== 'production' ? React.Children.only(children) : children}\n </StyleSheetContext.Provider>\n );\n }\n}\n","// @flow\nimport validAttr from '@emotion/is-prop-valid';\nimport merge from 'merge-anything';\nimport React, { createElement, Component } from 'react';\nimport ComponentStyle from './ComponentStyle';\nimport createWarnTooManyClasses from '../utils/createWarnTooManyClasses';\nimport determineTheme from '../utils/determineTheme';\nimport escape from '../utils/escape';\nimport generateDisplayName from '../utils/generateDisplayName';\nimport getComponentName from '../utils/getComponentName';\nimport hoist from '../utils/hoist';\nimport isFunction from '../utils/isFunction';\nimport isTag from '../utils/isTag';\nimport isDerivedReactComponent from '../utils/isDerivedReactComponent';\nimport isStyledComponent from '../utils/isStyledComponent';\nimport once from '../utils/once';\nimport StyleSheet from './StyleSheet';\nimport { ThemeConsumer, type Theme } from './ThemeProvider';\nimport { StyleSheetConsumer } from './StyleSheetManager';\nimport { EMPTY_ARRAY, EMPTY_OBJECT } from '../utils/empties';\n\nimport type { Attrs, RuleSet, Target } from '../types';\n\nconst identifiers = {};\n\n/* We depend on components having unique IDs */\nfunction generateId(_ComponentStyle: Function, _displayName: string, parentComponentId: string) {\n const displayName = typeof _displayName !== 'string' ? 'sc' : escape(_displayName);\n\n /**\n * This ensures uniqueness if two components happen to share\n * the same displayName.\n */\n const nr = (identifiers[displayName] || 0) + 1;\n identifiers[displayName] = nr;\n\n const componentId = `${displayName}-${_ComponentStyle.generateName(displayName + nr)}`;\n\n return parentComponentId ? `${parentComponentId}-${componentId}` : componentId;\n}\n\n// $FlowFixMe\nclass StyledComponent extends Component<*> {\n renderOuter: Function;\n\n renderInner: Function;\n\n styleSheet: ?StyleSheet;\n\n warnInnerRef: Function;\n\n warnAttrsFnObjectKeyDeprecated: Function;\n\n warnNonStyledComponentAttrsObjectKey: Function;\n\n attrs = {};\n\n constructor() {\n super();\n this.renderOuter = this.renderOuter.bind(this);\n this.renderInner = this.renderInner.bind(this);\n\n if (process.env.NODE_ENV !== 'production') {\n this.warnInnerRef = once(displayName =>\n // eslint-disable-next-line no-console\n console.warn(\n `The \"innerRef\" API has been removed in styled-components v4 in favor of React 16 ref forwarding, use \"ref\" instead like a typical component. \"innerRef\" was detected on component \"${displayName}\".`\n )\n );\n\n this.warnAttrsFnObjectKeyDeprecated = once(\n (key, displayName): void =>\n // eslint-disable-next-line no-console\n console.warn(\n `Functions as object-form attrs({}) keys are now deprecated and will be removed in a future version of styled-components. Switch to the new attrs(props => ({})) syntax instead for easier and more powerful composition. The attrs key in question is \"${key}\" on component \"${displayName}\".`,\n `\\n ${new Error().stack}`\n )\n );\n\n this.warnNonStyledComponentAttrsObjectKey = once(\n (key, displayName): void =>\n // eslint-disable-next-line no-console\n console.warn(\n `It looks like you've used a non styled-component as the value for the \"${key}\" prop in an object-form attrs constructor of \"${displayName}\".\\n` +\n 'You should use the new function-form attrs constructor which avoids this issue: attrs(props => ({ yourStuff }))\\n' +\n \"To continue using the deprecated object syntax, you'll need to wrap your component prop in a function to make it available inside the styled component (you'll still get the deprecation warning though.)\\n\" +\n `For example, { ${key}: () => InnerComponent } instead of { ${key}: InnerComponent }`\n )\n );\n }\n }\n\n render() {\n return <StyleSheetConsumer>{this.renderOuter}</StyleSheetConsumer>;\n }\n\n renderOuter(styleSheet?: StyleSheet = StyleSheet.master) {\n this.styleSheet = styleSheet;\n\n // No need to subscribe a static component to theme changes, it won't change anything\n if (this.props.forwardedComponent.componentStyle.isStatic) return this.renderInner();\n\n return <ThemeConsumer>{this.renderInner}</ThemeConsumer>;\n }\n\n renderInner(theme?: Theme) {\n const {\n componentStyle,\n defaultProps,\n displayName,\n foldedComponentIds,\n styledComponentId,\n target,\n } = this.props.forwardedComponent;\n\n let generatedClassName;\n if (componentStyle.isStatic) {\n generatedClassName = this.generateAndInjectStyles(EMPTY_OBJECT, this.props);\n } else {\n generatedClassName = this.generateAndInjectStyles(\n determineTheme(this.props, theme, defaultProps) || EMPTY_OBJECT,\n this.props\n );\n }\n\n const elementToBeCreated = this.props.as || this.attrs.as || target;\n const isTargetTag = isTag(elementToBeCreated);\n\n const propsForElement = {};\n const computedProps = { ...this.props, ...this.attrs };\n\n let key;\n // eslint-disable-next-line guard-for-in\n for (key in computedProps) {\n if (process.env.NODE_ENV !== 'production' && key === 'innerRef' && isTargetTag) {\n this.warnInnerRef(displayName);\n }\n\n if (key === 'forwardedComponent' || key === 'as') {\n continue;\n } else if (key === 'forwardedRef') propsForElement.ref = computedProps[key];\n else if (key === 'forwardedAs') propsForElement.as = computedProps[key];\n else if (!isTargetTag || validAttr(key)) {\n // Don't pass through non HTML tags through to HTML elements\n propsForElement[key] = computedProps[key];\n }\n }\n\n if (this.props.style && this.attrs.style) {\n propsForElement.style = { ...this.attrs.style, ...this.props.style };\n }\n\n propsForElement.className = Array.prototype\n .concat(\n foldedComponentIds,\n styledComponentId,\n generatedClassName !== styledComponentId ? generatedClassName : null,\n this.props.className,\n this.attrs.className\n )\n .filter(Boolean)\n .join(' ');\n\n return createElement(elementToBeCreated, propsForElement);\n }\n\n buildExecutionContext(theme: ?Object, props: Object, attrs: Attrs) {\n const context = { ...props, theme };\n\n if (!attrs.length) return context;\n\n this.attrs = {};\n\n attrs.forEach(attrDef => {\n let resolvedAttrDef = attrDef;\n let attrDefWasFn = false;\n let attr;\n let key;\n\n if (isFunction(resolvedAttrDef)) {\n // $FlowFixMe\n resolvedAttrDef = resolvedAttrDef(context);\n attrDefWasFn = true;\n }\n\n /* eslint-disable guard-for-in */\n // $FlowFixMe\n for (key in resolvedAttrDef) {\n attr = resolvedAttrDef[key];\n\n if (!attrDefWasFn) {\n if (isFunction(attr) && !isDerivedReactComponent(attr) && !isStyledComponent(attr)) {\n if (process.env.NODE_ENV !== 'production') {\n this.warnAttrsFnObjectKeyDeprecated(key, props.forwardedComponent.displayName);\n }\n\n attr = attr(context);\n\n if (process.env.NODE_ENV !== 'production' && React.isValidElement(attr)) {\n this.warnNonStyledComponentAttrsObjectKey(key, props.forwardedComponent.displayName);\n }\n }\n }\n\n this.attrs[key] = attr;\n context[key] = attr;\n }\n /* eslint-enable */\n });\n\n return context;\n }\n\n generateAndInjectStyles(theme: any, props: any) {\n const { attrs, componentStyle, warnTooManyClasses } = props.forwardedComponent;\n\n // statically styled-components don't need to build an execution context object,\n // and shouldn't be increasing the number of class names\n if (componentStyle.isStatic && !attrs.length) {\n return componentStyle.generateAndInjectStyles(EMPTY_OBJECT, this.styleSheet);\n }\n\n const className = componentStyle.generateAndInjectStyles(\n this.buildExecutionContext(theme, props, attrs),\n this.styleSheet\n );\n\n if (process.env.NODE_ENV !== 'production' && warnTooManyClasses) warnTooManyClasses(className);\n\n return className;\n }\n}\n\nexport default function createStyledComponent(target: Target, options: Object, rules: RuleSet) {\n const isTargetStyledComp = isStyledComponent(target);\n const isClass = !isTag(target);\n\n const {\n displayName = generateDisplayName(target),\n componentId = generateId(ComponentStyle, options.displayName, options.parentComponentId),\n ParentComponent = StyledComponent,\n attrs = EMPTY_ARRAY,\n } = options;\n\n const styledComponentId =\n options.displayName && options.componentId\n ? `${escape(options.displayName)}-${options.componentId}`\n : options.componentId || componentId;\n\n // fold the underlying StyledComponent attrs up (implicit extend)\n const finalAttrs =\n // $FlowFixMe\n isTargetStyledComp && target.attrs\n ? Array.prototype.concat(target.attrs, attrs).filter(Boolean)\n : attrs;\n\n const componentStyle = new ComponentStyle(\n isTargetStyledComp\n ? // fold the underlying StyledComponent rules up (implicit extend)\n // $FlowFixMe\n target.componentStyle.rules.concat(rules)\n : rules,\n finalAttrs,\n styledComponentId\n );\n\n /**\n * forwardRef creates a new interim component, which we'll take advantage of\n * instead of extending ParentComponent to create _another_ interim class\n */\n let WrappedStyledComponent;\n const forwardRef = (props, ref) => (\n <ParentComponent {...props} forwardedComponent={WrappedStyledComponent} forwardedRef={ref} />\n );\n forwardRef.displayName = displayName;\n WrappedStyledComponent = React.forwardRef(forwardRef);\n WrappedStyledComponent.displayName = displayName;\n\n // $FlowFixMe\n WrappedStyledComponent.attrs = finalAttrs;\n // $FlowFixMe\n WrappedStyledComponent.componentStyle = componentStyle;\n\n // $FlowFixMe\n WrappedStyledComponent.foldedComponentIds = isTargetStyledComp\n ? // $FlowFixMe\n Array.prototype.concat(target.foldedComponentIds, target.styledComponentId)\n : EMPTY_ARRAY;\n\n // $FlowFixMe\n WrappedStyledComponent.styledComponentId = styledComponentId;\n\n // fold the underlying StyledComponent target up since we folded the styles\n // $FlowFixMe\n WrappedStyledComponent.target = isTargetStyledComp ? target.target : target;\n\n // $FlowFixMe\n WrappedStyledComponent.withComponent = function withComponent(tag: Target) {\n const { componentId: previousComponentId, ...optionsToCopy } = options;\n\n const newComponentId =\n previousComponentId &&\n `${previousComponentId}-${isTag(tag) ? tag : escape(getComponentName(tag))}`;\n\n const newOptions = {\n ...optionsToCopy,\n attrs: finalAttrs,\n componentId: newComponentId,\n ParentComponent,\n };\n\n return createStyledComponent(tag, newOptions, rules);\n };\n\n // $FlowFixMe\n Object.defineProperty(WrappedStyledComponent, 'defaultProps', {\n get() {\n return this._foldedDefaultProps;\n },\n\n set(obj) {\n // $FlowFixMe\n this._foldedDefaultProps = isTargetStyledComp ? merge(target.defaultProps, obj) : obj;\n },\n });\n\n if (process.env.NODE_ENV !== 'production') {\n // $FlowFixMe\n WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName);\n }\n\n // $FlowFixMe\n WrappedStyledComponent.toString = () => `.${WrappedStyledComponent.styledComponentId}`;\n\n if (isClass) {\n hoist(WrappedStyledComponent, target, {\n // all SC-specific things should not be hoisted\n attrs: true,\n componentStyle: true,\n displayName: true,\n foldedComponentIds: true,\n styledComponentId: true,\n target: true,\n withComponent: true,\n });\n }\n\n return WrappedStyledComponent;\n}\n","// @flow\nimport { EMPTY_ARRAY } from '../utils/empties';\nimport flatten from '../utils/flatten';\nimport isStaticRules from '../utils/isStaticRules';\nimport stringifyRules from '../utils/stringifyRules';\nimport StyleSheet from './StyleSheet';\n\nimport type { RuleSet } from '../types';\n\nexport default class GlobalStyle {\n componentId: string;\n\n isStatic: boolean;\n\n rules: RuleSet;\n\n constructor(rules: RuleSet, componentId: string) {\n this.rules = rules;\n this.componentId = componentId;\n this.isStatic = isStaticRules(rules, EMPTY_ARRAY);\n\n if (!StyleSheet.master.hasId(componentId)) {\n StyleSheet.master.deferredInject(componentId, []);\n }\n }\n\n createStyles(executionContext: Object, styleSheet: StyleSheet) {\n const flatCSS = flatten(this.rules, executionContext, styleSheet);\n const css = stringifyRules(flatCSS, '');\n\n styleSheet.inject(this.componentId, css);\n }\n\n removeStyles(styleSheet: StyleSheet) {\n const { componentId } = this;\n if (styleSheet.hasId(componentId)) {\n styleSheet.remove(componentId);\n }\n }\n\n // TODO: overwrite in-place instead of remove+create?\n renderStyles(executionContext: Object, styleSheet: StyleSheet) {\n this.removeStyles(styleSheet);\n this.createStyles(executionContext, styleSheet);\n }\n}\n"],"names":["i"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CC;;CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iEA+EuD;;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tagEl, insertBefore) {
|
|
|
469
469
|
|
|
470
470
|
var el = targetDocument.createElement('style');
|
|
471
471
|
el.setAttribute(SC_ATTR, '');
|
|
472
|
-
el.setAttribute(SC_VERSION_ATTR, "4.4.
|
|
472
|
+
el.setAttribute(SC_VERSION_ATTR, "4.4.1");
|
|
473
473
|
|
|
474
474
|
var nonce = getNonce();
|
|
475
475
|
if (nonce) {
|
|
@@ -498,7 +498,7 @@ var makeStyleTag = function makeStyleTag(target, tagEl, insertBefore) {
|
|
|
498
498
|
var wrapAsHtmlTag = function wrapAsHtmlTag(css, names) {
|
|
499
499
|
return function (additionalAttrs) {
|
|
500
500
|
var nonce = getNonce();
|
|
501
|
-
var attrs = [nonce && 'nonce="' + nonce + '"', SC_ATTR + '="' + stringifyNames(names) + '"', SC_VERSION_ATTR + '="' + "4.4.
|
|
501
|
+
var attrs = [nonce && 'nonce="' + nonce + '"', SC_ATTR + '="' + stringifyNames(names) + '"', SC_VERSION_ATTR + '="' + "4.4.1" + '"', additionalAttrs];
|
|
502
502
|
|
|
503
503
|
var htmlAttr = attrs.filter(Boolean).join(' ');
|
|
504
504
|
return '<style ' + htmlAttr + '>' + css() + '</style>';
|
|
@@ -510,7 +510,7 @@ var wrapAsElement = function wrapAsElement(css, names) {
|
|
|
510
510
|
return function () {
|
|
511
511
|
var _props;
|
|
512
512
|
|
|
513
|
-
var props = (_props = {}, _props[SC_ATTR] = stringifyNames(names), _props[SC_VERSION_ATTR] = "4.4.
|
|
513
|
+
var props = (_props = {}, _props[SC_ATTR] = stringifyNames(names), _props[SC_VERSION_ATTR] = "4.4.1", _props);
|
|
514
514
|
|
|
515
515
|
var nonce = getNonce();
|
|
516
516
|
if (nonce) {
|
|
@@ -919,7 +919,7 @@ var StyleSheet = function () {
|
|
|
919
919
|
var isStreamed = false;
|
|
920
920
|
|
|
921
921
|
/* retrieve all of our SSR style elements from the DOM */
|
|
922
|
-
var nodes = document.querySelectorAll('style[' + SC_ATTR + '][' + SC_VERSION_ATTR + '="' + "4.4.
|
|
922
|
+
var nodes = document.querySelectorAll('style[' + SC_ATTR + '][' + SC_VERSION_ATTR + '="' + "4.4.1" + '"]');
|
|
923
923
|
|
|
924
924
|
var nodesSize = nodes.length;
|
|
925
925
|
|
|
@@ -1923,7 +1923,6 @@ process.env.NODE_ENV !== "production" ? StyleSheetManager.propTypes = {
|
|
|
1923
1923
|
|
|
1924
1924
|
//
|
|
1925
1925
|
|
|
1926
|
-
var THEME_PROP_REGEX = /\.theme[.[]/;
|
|
1927
1926
|
var identifiers = {};
|
|
1928
1927
|
|
|
1929
1928
|
/* We depend on components having unique IDs */
|
|
@@ -2012,24 +2011,14 @@ var StyledComponent = function (_Component) {
|
|
|
2012
2011
|
displayName = _props$forwardedCompo.displayName,
|
|
2013
2012
|
foldedComponentIds = _props$forwardedCompo.foldedComponentIds,
|
|
2014
2013
|
styledComponentId = _props$forwardedCompo.styledComponentId,
|
|
2015
|
-
target = _props$forwardedCompo.target
|
|
2016
|
-
usesTheme = _props$forwardedCompo.usesTheme;
|
|
2014
|
+
target = _props$forwardedCompo.target;
|
|
2017
2015
|
|
|
2018
2016
|
|
|
2019
2017
|
var generatedClassName = void 0;
|
|
2020
|
-
var rawTheme = void 0;
|
|
2021
|
-
|
|
2022
2018
|
if (componentStyle.isStatic) {
|
|
2023
2019
|
generatedClassName = this.generateAndInjectStyles(EMPTY_OBJECT, this.props);
|
|
2024
2020
|
} else {
|
|
2025
|
-
|
|
2026
|
-
generatedClassName = this.generateAndInjectStyles(rawTheme || EMPTY_OBJECT, this.props);
|
|
2027
|
-
|
|
2028
|
-
if (process.env.NODE_ENV !== 'production' && usesTheme && !rawTheme) {
|
|
2029
|
-
console.error('Component \'' +
|
|
2030
|
-
// $FlowFixMe
|
|
2031
|
-
displayName + '\' (.' + styledComponentId + ') references the \'theme\' prop in its styles but no theme was provided via prop or <ThemeProvider>.');
|
|
2032
|
-
}
|
|
2021
|
+
generatedClassName = this.generateAndInjectStyles(determineTheme(this.props, theme, defaultProps) || EMPTY_OBJECT, this.props);
|
|
2033
2022
|
}
|
|
2034
2023
|
|
|
2035
2024
|
var elementToBeCreated = this.props.as || this.attrs.as || target;
|
|
@@ -2216,11 +2205,6 @@ function createStyledComponent(target, options, rules) {
|
|
|
2216
2205
|
});
|
|
2217
2206
|
|
|
2218
2207
|
if (process.env.NODE_ENV !== 'production') {
|
|
2219
|
-
// $FlowFixMe
|
|
2220
|
-
WrappedStyledComponent.usesTheme = componentStyle.rules.some(function (x) {
|
|
2221
|
-
return isFunction(x) && THEME_PROP_REGEX.test(x.toString());
|
|
2222
|
-
});
|
|
2223
|
-
|
|
2224
2208
|
// $FlowFixMe
|
|
2225
2209
|
WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(displayName);
|
|
2226
2210
|
}
|