{"version":3,"file":"styled-components-no-parser.esm.js","sources":["../src/no-parser/flatten.js","../src/models/StyleTags.js","../src/models/StyleSheetManager.js","../src/models/ThemeProvider.js","../src/models/StyledComponent.js","../src/models/ComponentStyle.js","../src/constructors/styled.js","../src/constructors/keyframes.js","../src/constructors/injectGlobal.js"],"sourcesContent":["// @flow\nimport type { Interpolation } from '../types'\nimport _flatten, { objToCss } from '../utils/flatten'\nimport isPlainObject from '../utils/isPlainObject'\n\nconst isRuleSet = (interpolation: Interpolation): boolean =>\n !!(\n interpolation &&\n Array.isArray(interpolation) &&\n interpolation.length > 0 &&\n interpolation[0] &&\n Array.isArray(interpolation[0])\n )\n\nconst flatten = (\n chunks: Array,\n executionContext: ?Object\n): Array => {\n /* Fall back to old flattener for non-rule-set chunks */\n if (!isRuleSet(chunks)) {\n return _flatten(chunks, executionContext)\n }\n\n return chunks.reduce(\n (\n ruleSet: Array,\n chunk: ?Interpolation\n ): Array => {\n if (!Array.isArray(chunk)) {\n return ruleSet\n }\n\n let appendChunks = []\n\n const newChunk = chunk.reduce(\n (\n rules: Array,\n rule: ?Interpolation\n ): Array => {\n /* Remove falsey values */\n if (\n rule === undefined ||\n rule === null ||\n rule === false ||\n rule === ''\n ) {\n return rules\n }\n\n /* Flatten nested rule set */\n if (isRuleSet(rule)) {\n // $FlowFixMe Don't know what's wrong here\n appendChunks = [...appendChunks, ...flatten(rule, executionContext)]\n return rules\n }\n\n /* Stringify unexpected array */\n if (Array.isArray(rule)) {\n return [...rules, ..._flatten(rule, executionContext)]\n }\n\n /* Either execute or defer the function */\n if (typeof rule === 'function') {\n if (executionContext) {\n const res = rule(executionContext)\n\n if (isRuleSet(res)) {\n appendChunks = [\n ...appendChunks,\n // $FlowFixMe Don't know what's wrong here\n ...flatten(res, executionContext),\n ]\n return rules\n }\n\n /* Flatten non-ruleset values */\n return [...rules, ...flatten([res], executionContext)]\n } else {\n return [...rules, rule]\n }\n }\n\n /* Handle other components */\n if (\n typeof rule === 'object' &&\n rule.hasOwnProperty('styledComponentId')\n ) {\n return [...rules, `.${rule.styledComponentId}`]\n }\n\n /* Convert object to css string */\n if (typeof rule === 'object' && isPlainObject(rule)) {\n return [...rules, objToCss(rule)]\n }\n\n return [...rules, rule.toString()]\n },\n []\n )\n\n if (executionContext) {\n const newChunkStr = newChunk.join('')\n if (appendChunks.length) {\n return [...ruleSet, newChunkStr, ...appendChunks]\n }\n\n return [...ruleSet, newChunkStr]\n }\n\n return [...ruleSet, newChunk, ...appendChunks]\n },\n []\n )\n}\n\nexport default flatten\n","// @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 } from '../constants'\nimport StyledError from '../utils/error'\nimport { type ExtractedComp } from '../utils/extractCompsFromCSS'\nimport { splitByRules } from '../utils/stringifyRules'\nimport getNonce from '../utils/nonce'\nimport once from '../utils/once'\n\nimport {\n type Names,\n addNameForId,\n resetIdNames,\n hasNameForId,\n stringifyNames,\n cloneNames,\n} from '../utils/styleNames'\n\nimport {\n sheetForTag,\n safeInsertRule,\n deleteRules,\n} from '../utils/insertRuleHelpers'\n\nexport interface Tag {\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;\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 = (\n target: ?HTMLElement,\n tagEl: ?Node,\n insertBefore: ?boolean\n) => {\n const el = document.createElement('style')\n el.setAttribute(SC_ATTR, '')\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(document.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) => (\n additionalAttrs: ?string\n): string => {\n const nonce = getNonce()\n const attrs = [\n nonce && `nonce=\"${nonce}\"`,\n `${SC_ATTR}=\"${stringifyNames(names)}\"`,\n additionalAttrs,\n ]\n\n const htmlAttr = attrs.filter(Boolean).join(' ')\n return ``\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 }\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