styled-components 5.2.0 → 5.2.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/dist/styled-components.browser.cjs.js +1 -1
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +1 -1
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +1 -1
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +1 -1
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +1 -1
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +1 -1
- package/dist/styled-components.min.js.map +1 -1
- package/native/dist/styled-components.native.cjs.js +203 -204
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js +203 -204
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/package.json +2 -2
- package/primitives/dist/styled-components-primitives.cjs.js +203 -204
- package/primitives/dist/styled-components-primitives.cjs.js.map +1 -1
- package/primitives/dist/styled-components-primitives.esm.js +203 -204
- package/primitives/dist/styled-components-primitives.esm.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled-components.min.js","sources":["../src/sheet/Tag.js","../src/sheet/Sheet.js","../src/models/StyleSheetManager.js","../src/models/Keyframes.js","../src/utils/isStaticRules.js","../src/models/GlobalStyle.js","../src/models/ServerStyleSheet.js","../src/models/StyledComponent.js"],"sourcesContent":["// @flow\n/* eslint-disable no-use-before-define */\n\nimport { makeStyleTag, getSheet } from './dom';\nimport type { SheetOptions, Tag } from './types';\n\n/** Create a CSSStyleSheet-like tag depending on the environment */\nexport const makeTag = ({ isServer, useCSSOMInjection, target }: SheetOptions): Tag => {\n if (isServer) {\n return new VirtualTag(target);\n } else if (useCSSOMInjection) {\n return new CSSOMTag(target);\n } else {\n return new TextTag(target);\n }\n};\n\nexport class CSSOMTag implements Tag {\n element: HTMLStyleElement;\n\n sheet: CSSStyleSheet;\n\n length: number;\n\n constructor(target?: HTMLElement) {\n const element = (this.element = makeStyleTag(target));\n\n // Avoid Edge bug where empty style elements don't create sheets\n element.appendChild(document.createTextNode(''));\n\n this.sheet = getSheet(element);\n this.length = 0;\n }\n\n insertRule(index: number, rule: string): boolean {\n try {\n this.sheet.insertRule(rule, index);\n this.length++;\n return true;\n } catch (_error) {\n return false;\n }\n }\n\n deleteRule(index: number): void {\n this.sheet.deleteRule(index);\n this.length--;\n }\n\n getRule(index: number): string {\n const rule = this.sheet.cssRules[index];\n // Avoid IE11 quirk where cssText is inaccessible on some invalid rules\n if (rule !== undefined && typeof rule.cssText === 'string') {\n return rule.cssText;\n } else {\n return '';\n }\n }\n}\n\n/** A Tag that emulates the CSSStyleSheet API but uses text nodes */\nexport class TextTag implements Tag {\n element: HTMLStyleElement;\n\n nodes: NodeList<Node>;\n\n length: number;\n\n constructor(target?: HTMLElement) {\n const element = (this.element = makeStyleTag(target));\n this.nodes = element.childNodes;\n this.length = 0;\n }\n\n insertRule(index: number, rule: string): boolean {\n if (index <= this.length && index >= 0) {\n const node = document.createTextNode(rule);\n const refNode = this.nodes[index];\n this.element.insertBefore(node, refNode || null);\n this.length++;\n return true;\n } else {\n return false;\n }\n }\n\n deleteRule(index: number): void {\n this.element.removeChild(this.nodes[index]);\n this.length--;\n }\n\n getRule(index: number): string {\n if (index < this.length) {\n return this.nodes[index].textContent;\n } else {\n return '';\n }\n }\n}\n\n/** A completely virtual (server-side) Tag that doesn't manipulate the DOM */\nexport class VirtualTag implements Tag {\n rules: string[];\n\n length: number;\n\n constructor(_target?: HTMLElement) {\n this.rules = [];\n this.length = 0;\n }\n\n insertRule(index: number, rule: string): boolean {\n if (index <= this.length) {\n this.rules.splice(index, 0, rule);\n this.length++;\n return true;\n } else {\n return false;\n }\n }\n\n deleteRule(index: number): void {\n this.rules.splice(index, 1);\n this.length--;\n }\n\n getRule(index: number): string {\n if (index < this.length) {\n return this.rules[index];\n } else {\n return '';\n }\n }\n}\n","// @flow\nimport { DISABLE_SPEEDY, IS_BROWSER } from '../constants';\nimport type { GroupedTag, Sheet, SheetOptions } from './types';\nimport { makeTag } from './Tag';\nimport { makeGroupedTag } from './GroupedTag';\nimport { getGroupForId } from './GroupIDAllocator';\nimport { outputSheet, rehydrateSheet } from './Rehydration';\n\nlet SHOULD_REHYDRATE = IS_BROWSER;\n\ntype SheetConstructorArgs = {\n isServer?: boolean,\n useCSSOMInjection?: boolean,\n target?: HTMLElement,\n};\n\ntype GlobalStylesAllocationMap = { [key: string]: number };\ntype NamesAllocationMap = Map<string, Set<string>>;\n\nconst defaultOptions = {\n isServer: !IS_BROWSER,\n useCSSOMInjection: !DISABLE_SPEEDY,\n};\n\n/** Contains the main stylesheet logic for stringification and caching */\nexport default class StyleSheet implements Sheet {\n gs: GlobalStylesAllocationMap;\n\n names: NamesAllocationMap;\n\n options: SheetOptions;\n\n tag: void | GroupedTag;\n\n /** Register a group ID to give it an index */\n static registerId(id: string): number {\n return getGroupForId(id);\n }\n\n constructor(\n options: SheetConstructorArgs = defaultOptions,\n globalStyles?: GlobalStylesAllocationMap = {},\n names?: NamesAllocationMap\n ) {\n this.options = {\n ...defaultOptions,\n ...options,\n };\n\n this.gs = globalStyles;\n this.names = new Map(names);\n\n // We rehydrate only once and use the sheet that is created first\n if (!this.options.isServer && IS_BROWSER && SHOULD_REHYDRATE) {\n SHOULD_REHYDRATE = false;\n rehydrateSheet(this);\n }\n }\n\n reconstructWithOptions(options: SheetConstructorArgs, withNames?: boolean = true) {\n return new StyleSheet(\n { ...this.options, ...options },\n this.gs,\n (withNames && this.names) || undefined\n );\n }\n\n allocateGSInstance(id: string) {\n return (this.gs[id] = (this.gs[id] || 0) + 1);\n }\n\n /** Lazily initialises a GroupedTag for when it's actually needed */\n getTag(): GroupedTag {\n return this.tag || (this.tag = makeGroupedTag(makeTag(this.options)));\n }\n\n /** Check whether a name is known for caching */\n hasNameForId(id: string, name: string): boolean {\n return this.names.has(id) && (this.names.get(id): any).has(name);\n }\n\n /** Mark a group's name as known for caching */\n registerName(id: string, name: string) {\n getGroupForId(id);\n\n if (!this.names.has(id)) {\n const groupNames = new Set();\n groupNames.add(name);\n this.names.set(id, groupNames);\n } else {\n (this.names.get(id): any).add(name);\n }\n }\n\n /** Insert new rules which also marks the name as known */\n insertRules(id: string, name: string, rules: string[]) {\n this.registerName(id, name);\n this.getTag().insertRules(getGroupForId(id), rules);\n }\n\n /** Clears all cached names for a given group ID */\n clearNames(id: string) {\n if (this.names.has(id)) {\n (this.names.get(id): any).clear();\n }\n }\n\n /** Clears all rules for a given group ID */\n clearRules(id: string) {\n this.getTag().clearGroup(getGroupForId(id));\n this.clearNames(id);\n }\n\n /** Clears the entire tag which deletes all rules but not its names */\n clearTag() {\n // NOTE: This does not clear the names, since it's only used during SSR\n // so that we can continuously output only new rules\n this.tag = undefined;\n }\n\n /** Outputs the current sheet as a CSS string with markers for SSR */\n toString(): string {\n return outputSheet(this);\n }\n}\n","// @flow\nimport React, { useContext, useEffect, useMemo, useState, type Node, type Context } from 'react';\nimport shallowequal from 'shallowequal';\nimport StyleSheet from '../sheet';\nimport createStylisInstance, { type Stringifier } from '../utils/stylis';\n\ntype Props = {\n children?: Node,\n disableCSSOMInjection?: boolean,\n disableVendorPrefixes?: boolean,\n sheet?: StyleSheet,\n stylisPlugins?: Array<Function>,\n target?: HTMLElement,\n};\n\nexport const StyleSheetContext: Context<StyleSheet | void> = React.createContext();\nexport const StyleSheetConsumer = StyleSheetContext.Consumer;\nexport const StylisContext: Context<Stringifier | void> = React.createContext();\nexport const StylisConsumer = StylisContext.Consumer;\n\nexport const masterSheet: StyleSheet = new StyleSheet();\nexport const masterStylis: Stringifier = createStylisInstance();\n\nexport function useStyleSheet(): StyleSheet {\n return useContext(StyleSheetContext) || masterSheet;\n}\n\nexport function useStylis(): Stringifier {\n return useContext(StylisContext) || masterStylis;\n}\n\nexport default function StyleSheetManager(props: Props) {\n const [plugins, setPlugins] = useState(props.stylisPlugins);\n const contextStyleSheet = useStyleSheet();\n\n const styleSheet = useMemo(() => {\n let sheet = contextStyleSheet;\n\n if (props.sheet) {\n // eslint-disable-next-line prefer-destructuring\n sheet = props.sheet;\n } else if (props.target) {\n sheet = sheet.reconstructWithOptions({ target: props.target }, false);\n }\n\n if (props.disableCSSOMInjection) {\n sheet = sheet.reconstructWithOptions({ useCSSOMInjection: false });\n }\n\n return sheet;\n }, [props.disableCSSOMInjection, props.sheet, props.target]);\n\n const stylis = useMemo(\n () =>\n createStylisInstance({\n options: { prefix: !props.disableVendorPrefixes },\n plugins,\n }),\n [props.disableVendorPrefixes, plugins]\n );\n\n useEffect(() => {\n if (!shallowequal(plugins, props.stylisPlugins)) setPlugins(props.stylisPlugins);\n }, [props.stylisPlugins]);\n\n return (\n <StyleSheetContext.Provider value={styleSheet}>\n <StylisContext.Provider value={stylis}>\n {process.env.NODE_ENV !== 'production'\n ? React.Children.only(props.children)\n : props.children}\n </StylisContext.Provider>\n </StyleSheetContext.Provider>\n );\n}\n","// @flow\nimport StyleSheet from '../sheet';\nimport { type Stringifier } from '../types';\nimport throwStyledError from '../utils/error';\nimport { masterStylis } from './StyleSheetManager';\n\nexport default class Keyframes {\n id: string;\n\n name: string;\n\n rules: string;\n\n constructor(name: string, rules: string) {\n this.name = name;\n this.id = `sc-keyframes-${name}`;\n this.rules = rules;\n }\n\n inject = (styleSheet: StyleSheet, stylisInstance: Stringifier = masterStylis) => {\n const resolvedName = this.name + stylisInstance.hash;\n\n if (!styleSheet.hasNameForId(this.id, resolvedName)) {\n styleSheet.insertRules(\n this.id,\n resolvedName,\n stylisInstance(this.rules, resolvedName, '@keyframes')\n );\n }\n };\n\n toString = () => {\n return throwStyledError(12, String(this.name));\n };\n\n getName(stylisInstance: Stringifier = masterStylis) {\n return this.name + stylisInstance.hash;\n }\n}\n","// @flow\nimport isFunction from './isFunction';\nimport isStyledComponent from './isStyledComponent';\nimport type { RuleSet } from '../types';\n\nexport default function isStaticRules(rules: RuleSet): boolean {\n for (let i = 0; i < rules.length; i += 1) {\n const rule = rules[i];\n\n if (isFunction(rule) && !isStyledComponent(rule)) {\n // functions are allowed to be static if they're just being\n // used to get the classname of a nested styled component\n return false;\n }\n }\n\n return true;\n}\n","// @flow\nimport StyleSheet from '../sheet';\nimport type { RuleSet, Stringifier } from '../types';\nimport flatten from '../utils/flatten';\nimport isStaticRules from '../utils/isStaticRules';\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);\n\n // pre-register the first instance to ensure global styles\n // load before component ones\n StyleSheet.registerId(this.componentId + 1);\n }\n\n createStyles(\n instance: number,\n executionContext: Object,\n styleSheet: StyleSheet,\n stylis: Stringifier\n ) {\n const flatCSS = flatten(this.rules, executionContext, styleSheet, stylis);\n const css = stylis(flatCSS.join(''), '');\n const id = this.componentId + instance;\n\n // NOTE: We use the id as a name as well, since these rules never change\n styleSheet.insertRules(id, id, css);\n }\n\n removeStyles(instance: number, styleSheet: StyleSheet) {\n styleSheet.clearRules(this.componentId + instance);\n }\n\n renderStyles(\n instance: number,\n executionContext: Object,\n styleSheet: StyleSheet,\n stylis: Stringifier\n ) {\n if (instance > 2) StyleSheet.registerId(this.componentId + instance);\n\n // NOTE: Remove old styles, then inject the new ones\n this.removeStyles(instance, styleSheet);\n this.createStyles(instance, executionContext, styleSheet, stylis);\n }\n}\n","// @flow\n/* eslint-disable no-underscore-dangle */\nimport React from 'react';\nimport { IS_BROWSER, SC_ATTR, SC_ATTR_VERSION, SC_VERSION } from '../constants';\nimport throwStyledError from '../utils/error';\nimport getNonce from '../utils/nonce';\nimport StyleSheet from '../sheet';\nimport StyleSheetManager from './StyleSheetManager';\n\ndeclare var __SERVER__: boolean;\n\nconst CLOSING_TAG_R = /^\\s*<\\/[a-z]/i;\n\nexport default class ServerStyleSheet {\n isStreaming: boolean;\n\n instance: StyleSheet;\n\n sealed: boolean;\n\n constructor() {\n this.instance = new StyleSheet({ isServer: true });\n this.sealed = false;\n }\n\n _emitSheetCSS = (): string => {\n const css = this.instance.toString();\n const nonce = getNonce();\n const attrs = [nonce && `nonce=\"${nonce}\"`, `${SC_ATTR}=\"true\"`, `${SC_ATTR_VERSION}=\"${SC_VERSION}\"`];\n const htmlAttr = attrs.filter(Boolean).join(' ');\n\n return `<style ${htmlAttr}>${css}</style>`;\n };\n\n collectStyles(children: any) {\n if (this.sealed) {\n return throwStyledError(2);\n }\n\n return <StyleSheetManager sheet={this.instance}>{children}</StyleSheetManager>;\n }\n\n getStyleTags = (): string => {\n if (this.sealed) {\n return throwStyledError(2);\n }\n\n return this._emitSheetCSS();\n };\n\n getStyleElement = () => {\n if (this.sealed) {\n return throwStyledError(2);\n }\n\n const props = {\n [SC_ATTR]: '',\n [SC_ATTR_VERSION]: SC_VERSION,\n dangerouslySetInnerHTML: {\n __html: this.instance.toString(),\n },\n };\n\n const nonce = getNonce();\n if (nonce) {\n (props: any).nonce = nonce;\n }\n\n // v4 returned an array for this fn, so we'll do the same for v5 for backward compat\n return [<style {...props} key=\"sc-0-0\" />];\n };\n\n // eslint-disable-next-line consistent-return\n interleaveWithNodeStream(input: any) {\n if (!__SERVER__ || IS_BROWSER) {\n return throwStyledError(3);\n } else if (this.sealed) {\n return throwStyledError(2);\n }\n\n if (__SERVER__) {\n this.seal();\n\n // eslint-disable-next-line global-require\n const { Readable, Transform } = require('stream');\n\n const readableStream: Readable = input;\n const { instance: sheet, _emitSheetCSS } = this;\n\n const transformer = new Transform({\n transform: function appendStyleChunks(chunk, /* encoding */ _, callback) {\n // Get the chunk and retrieve the sheet's CSS as an HTML chunk,\n // then reset its rules so we get only new ones for the next chunk\n const renderedHtml = chunk.toString();\n const html = _emitSheetCSS();\n\n sheet.clearTag();\n\n // prepend style html to chunk, unless the start of the chunk is a\n // closing tag in which case append right after that\n if (CLOSING_TAG_R.test(renderedHtml)) {\n const endOfClosingTag = renderedHtml.indexOf('>') + 1;\n const before = renderedHtml.slice(0, endOfClosingTag);\n const after = renderedHtml.slice(endOfClosingTag);\n\n this.push(before + html + after);\n } else {\n this.push(html + renderedHtml);\n }\n\n callback();\n },\n });\n\n readableStream.on('error', err => {\n // forward the error to the transform stream\n transformer.emit('error', err);\n });\n\n return readableStream.pipe(transformer);\n }\n }\n\n seal = () => {\n this.sealed = true;\n };\n}\n","// @flow\nimport validAttr from '@emotion/is-prop-valid';\nimport React, {\n createElement,\n useContext,\n useDebugValue,\n type AbstractComponent,\n type Ref,\n} from 'react';\nimport hoist from 'hoist-non-react-statics';\nimport { SC_VERSION } from '../constants';\nimport merge from '../utils/mixinDeep';\nimport ComponentStyle from './ComponentStyle';\nimport createWarnTooManyClasses from '../utils/createWarnTooManyClasses';\nimport { checkDynamicCreation } from '../utils/checkDynamicCreation';\nimport determineTheme from '../utils/determineTheme';\nimport escape from '../utils/escape';\nimport generateDisplayName from '../utils/generateDisplayName';\nimport getComponentName from '../utils/getComponentName';\nimport generateComponentId from '../utils/generateComponentId';\nimport isFunction from '../utils/isFunction';\nimport isStyledComponent from '../utils/isStyledComponent';\nimport isTag from '../utils/isTag';\nimport joinStrings from '../utils/joinStrings';\nimport { ThemeContext } from './ThemeProvider';\nimport { useStyleSheet, useStylis } from './StyleSheetManager';\nimport { EMPTY_ARRAY, EMPTY_OBJECT } from '../utils/empties';\n\nimport type { Attrs, RuleSet, Target } from '../types';\n\n/* global $Call */\n\nconst identifiers = {};\n\n/* We depend on components having unique IDs */\nfunction generateId(displayName: string, parentComponentId: string) {\n const name = typeof displayName !== 'string' ? 'sc' : escape(displayName);\n // Ensure that no displayName can lead to duplicate componentIds\n identifiers[name] = (identifiers[name] || 0) + 1;\n\n const componentId = `${name}-${generateComponentId(\n // SC_VERSION gives us isolation between multiple runtimes on the page at once\n // this is improved further with use of the babel plugin \"namespace\" feature\n SC_VERSION + name + identifiers[name]\n )}`;\n\n return parentComponentId ? `${parentComponentId}-${componentId}` : componentId;\n}\n\nfunction useResolvedAttrs<Config>(theme: any = EMPTY_OBJECT, props: Config, attrs: Attrs) {\n // NOTE: can't memoize this\n // returns [context, resolvedAttrs]\n // where resolvedAttrs is only the things injected by the attrs themselves\n const context = { ...props, theme };\n const resolvedAttrs = {};\n\n attrs.forEach(attrDef => {\n let resolvedAttrDef = attrDef;\n let key;\n\n if (isFunction(resolvedAttrDef)) {\n resolvedAttrDef = resolvedAttrDef(context);\n }\n\n /* eslint-disable guard-for-in */\n for (key in resolvedAttrDef) {\n context[key] = resolvedAttrs[key] =\n key === 'className'\n ? joinStrings(resolvedAttrs[key], resolvedAttrDef[key])\n : resolvedAttrDef[key];\n }\n /* eslint-enable guard-for-in */\n });\n\n return [context, resolvedAttrs];\n}\n\ninterface StyledComponentWrapperProperties {\n attrs: Attrs;\n componentStyle: ComponentStyle;\n displayName: string;\n foldedComponentIds: Array<string>;\n target: Target;\n shouldForwardProp: ?(prop: string, isValidAttr: (prop: string) => boolean) => boolean;\n styledComponentId: string;\n warnTooManyClasses: $Call<typeof createWarnTooManyClasses, string, string>;\n}\n\ntype StyledComponentWrapper<Config, Instance> = AbstractComponent<Config, Instance> &\n StyledComponentWrapperProperties;\n\nfunction useInjectedStyle<T>(\n componentStyle: ComponentStyle,\n hasAttrs: boolean,\n resolvedAttrs: T,\n warnTooManyClasses?: $Call<typeof createWarnTooManyClasses, string, string>\n) {\n const styleSheet = useStyleSheet();\n const stylis = useStylis();\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 const isStatic = componentStyle.isStatic && !hasAttrs;\n\n const className = isStatic\n ? componentStyle.generateAndInjectStyles(EMPTY_OBJECT, styleSheet, stylis)\n : componentStyle.generateAndInjectStyles(resolvedAttrs, styleSheet, stylis);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n if (process.env.NODE_ENV !== 'production') useDebugValue(className);\n\n if (process.env.NODE_ENV !== 'production' && !isStatic && warnTooManyClasses) {\n warnTooManyClasses(className);\n }\n\n return className;\n}\n\nfunction useStyledComponentImpl<Config: {}, Instance>(\n forwardedComponent: StyledComponentWrapper<Config, Instance>,\n props: Object,\n forwardedRef: Ref<any>\n) {\n const {\n attrs: componentAttrs,\n componentStyle,\n // $FlowFixMe\n defaultProps,\n foldedComponentIds,\n // $FlowFixMe\n shouldForwardProp,\n styledComponentId,\n target,\n } = forwardedComponent;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n if (process.env.NODE_ENV !== 'production') useDebugValue(styledComponentId);\n\n // NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,\n // but that'd be against the rules-of-hooks. We could be naughty and do it anyway as it\n // should be an immutable value, but behave for now.\n const theme = determineTheme(props, useContext(ThemeContext), defaultProps);\n\n const [context, attrs] = useResolvedAttrs(theme || EMPTY_OBJECT, props, componentAttrs);\n\n const generatedClassName = useInjectedStyle(\n componentStyle,\n componentAttrs.length > 0,\n context,\n process.env.NODE_ENV !== 'production' ? forwardedComponent.warnTooManyClasses : undefined\n );\n\n const refToForward = forwardedRef;\n\n const elementToBeCreated: Target = attrs.$as || props.$as || attrs.as || props.as || target;\n\n const isTargetTag = isTag(elementToBeCreated);\n const computedProps = attrs !== props ? { ...props, ...attrs } : props;\n const propFilterFn = shouldForwardProp || (isTargetTag && validAttr);\n const propsForElement = {};\n\n // eslint-disable-next-line guard-for-in\n for (const key in computedProps) {\n if (key[0] === '$' || key === 'as') continue;\n else if (key === 'forwardedAs') {\n propsForElement.as = computedProps[key];\n } else if (!propFilterFn || propFilterFn(key, validAttr)) {\n // Don't pass through non HTML tags through to HTML elements\n propsForElement[key] = computedProps[key];\n }\n }\n\n if (props.style && attrs.style !== props.style) {\n propsForElement.style = { ...props.style, ...attrs.style };\n }\n\n propsForElement.className = Array.prototype\n .concat(\n foldedComponentIds,\n styledComponentId,\n generatedClassName !== styledComponentId ? generatedClassName : null,\n props.className,\n attrs.className\n )\n .filter(Boolean)\n .join(' ');\n\n propsForElement.ref = refToForward;\n\n return createElement(elementToBeCreated, propsForElement);\n}\n\nexport default function createStyledComponent(\n target: Target | StyledComponentWrapper<*, *>,\n options: Object,\n rules: RuleSet\n) {\n const isTargetStyledComp = isStyledComponent(target);\n const isCompositeComponent = !isTag(target);\n\n const {\n displayName = generateDisplayName(target),\n componentId = generateId(options.displayName, options.parentComponentId),\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 // eslint-disable-next-line prefer-destructuring\n let shouldForwardProp = options.shouldForwardProp;\n\n // $FlowFixMe\n if (isTargetStyledComp && target.shouldForwardProp) {\n if (shouldForwardProp) {\n // compose nested shouldForwardProp calls\n shouldForwardProp = (prop, filterFn) =>\n // $FlowFixMe\n target.shouldForwardProp(prop, filterFn) && options.shouldForwardProp(prop, filterFn);\n } else {\n // eslint-disable-next-line prefer-destructuring\n shouldForwardProp = target.shouldForwardProp;\n }\n }\n\n const componentStyle = new ComponentStyle(\n rules,\n styledComponentId,\n isTargetStyledComp ? ((target: Object).componentStyle: ComponentStyle) : undefined\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\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const forwardRef = (props, ref) => useStyledComponentImpl(WrappedStyledComponent, props, ref);\n\n forwardRef.displayName = displayName;\n\n // $FlowFixMe this is a forced cast to merge it StyledComponentWrapperProperties\n WrappedStyledComponent = (React.forwardRef(forwardRef): StyledComponentWrapper<*, *>);\n\n WrappedStyledComponent.attrs = finalAttrs;\n WrappedStyledComponent.componentStyle = componentStyle;\n WrappedStyledComponent.displayName = displayName;\n WrappedStyledComponent.shouldForwardProp = shouldForwardProp;\n\n // this static is used to preserve the cascade of static classes for component selector\n // purposes; this is especially important with usage of the css prop\n WrappedStyledComponent.foldedComponentIds = isTargetStyledComp\n ? // $FlowFixMe\n Array.prototype.concat(target.foldedComponentIds, target.styledComponentId)\n : EMPTY_ARRAY;\n\n WrappedStyledComponent.styledComponentId = styledComponentId;\n\n // fold the underlying StyledComponent target up since we folded the styles\n WrappedStyledComponent.target = isTargetStyledComp\n ? // $FlowFixMe\n target.target\n : 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 };\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 checkDynamicCreation(displayName, styledComponentId);\n\n WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(\n displayName,\n styledComponentId\n );\n }\n\n // $FlowFixMe\n WrappedStyledComponent.toString = () => `.${WrappedStyledComponent.styledComponentId}`;\n\n if (isCompositeComponent) {\n hoist(WrappedStyledComponent, (target: any), {\n // all SC-specific things should not be hoisted\n attrs: true,\n componentStyle: true,\n displayName: true,\n foldedComponentIds: true,\n shouldForwardProp: true,\n self: true,\n styledComponentId: true,\n target: true,\n withComponent: true,\n });\n }\n\n return WrappedStyledComponent;\n}\n"],"names":["nodes","insertRule","names","id","stylisPlugins","flatten","React","isCompositeComponent"],"mappings":"u1FAsF0BA,gHAgBxBC,WAAA,44DC5DQC,yxBAmC8BC,iOAkBVA,mxTChEiBC,ujCCZGD,6+DCdG,sOCoBjCE,kCAEVF,kjCCsCEG,u2QCgIJC,kxCAvCkB"}
|
|
1
|
+
{"version":3,"file":"styled-components.min.js","sources":["../src/sheet/Tag.js","../src/sheet/Sheet.js","../src/utils/isStaticRules.js","../src/models/Keyframes.js","../src/models/GlobalStyle.js","../src/models/ServerStyleSheet.js","../src/models/StyledComponent.js"],"sourcesContent":["// @flow\n/* eslint-disable no-use-before-define */\n\nimport { makeStyleTag, getSheet } from './dom';\nimport type { SheetOptions, Tag } from './types';\n\n/** Create a CSSStyleSheet-like tag depending on the environment */\nexport const makeTag = ({ isServer, useCSSOMInjection, target }: SheetOptions): Tag => {\n if (isServer) {\n return new VirtualTag(target);\n } else if (useCSSOMInjection) {\n return new CSSOMTag(target);\n } else {\n return new TextTag(target);\n }\n};\n\nexport class CSSOMTag implements Tag {\n element: HTMLStyleElement;\n\n sheet: CSSStyleSheet;\n\n length: number;\n\n constructor(target?: HTMLElement) {\n const element = (this.element = makeStyleTag(target));\n\n // Avoid Edge bug where empty style elements don't create sheets\n element.appendChild(document.createTextNode(''));\n\n this.sheet = getSheet(element);\n this.length = 0;\n }\n\n insertRule(index: number, rule: string): boolean {\n try {\n this.sheet.insertRule(rule, index);\n this.length++;\n return true;\n } catch (_error) {\n return false;\n }\n }\n\n deleteRule(index: number): void {\n this.sheet.deleteRule(index);\n this.length--;\n }\n\n getRule(index: number): string {\n const rule = this.sheet.cssRules[index];\n // Avoid IE11 quirk where cssText is inaccessible on some invalid rules\n if (rule !== undefined && typeof rule.cssText === 'string') {\n return rule.cssText;\n } else {\n return '';\n }\n }\n}\n\n/** A Tag that emulates the CSSStyleSheet API but uses text nodes */\nexport class TextTag implements Tag {\n element: HTMLStyleElement;\n\n nodes: NodeList<Node>;\n\n length: number;\n\n constructor(target?: HTMLElement) {\n const element = (this.element = makeStyleTag(target));\n this.nodes = element.childNodes;\n this.length = 0;\n }\n\n insertRule(index: number, rule: string): boolean {\n if (index <= this.length && index >= 0) {\n const node = document.createTextNode(rule);\n const refNode = this.nodes[index];\n this.element.insertBefore(node, refNode || null);\n this.length++;\n return true;\n } else {\n return false;\n }\n }\n\n deleteRule(index: number): void {\n this.element.removeChild(this.nodes[index]);\n this.length--;\n }\n\n getRule(index: number): string {\n if (index < this.length) {\n return this.nodes[index].textContent;\n } else {\n return '';\n }\n }\n}\n\n/** A completely virtual (server-side) Tag that doesn't manipulate the DOM */\nexport class VirtualTag implements Tag {\n rules: string[];\n\n length: number;\n\n constructor(_target?: HTMLElement) {\n this.rules = [];\n this.length = 0;\n }\n\n insertRule(index: number, rule: string): boolean {\n if (index <= this.length) {\n this.rules.splice(index, 0, rule);\n this.length++;\n return true;\n } else {\n return false;\n }\n }\n\n deleteRule(index: number): void {\n this.rules.splice(index, 1);\n this.length--;\n }\n\n getRule(index: number): string {\n if (index < this.length) {\n return this.rules[index];\n } else {\n return '';\n }\n }\n}\n","// @flow\nimport { DISABLE_SPEEDY, IS_BROWSER } from '../constants';\nimport { EMPTY_OBJECT } from '../utils/empties';\nimport { makeGroupedTag } from './GroupedTag';\nimport { getGroupForId } from './GroupIDAllocator';\nimport { outputSheet, rehydrateSheet } from './Rehydration';\nimport { makeTag } from './Tag';\nimport type { GroupedTag, Sheet, SheetOptions } from './types';\n\nlet SHOULD_REHYDRATE = IS_BROWSER;\n\ntype SheetConstructorArgs = {\n isServer?: boolean,\n useCSSOMInjection?: boolean,\n target?: HTMLElement,\n};\n\ntype GlobalStylesAllocationMap = { [key: string]: number };\ntype NamesAllocationMap = Map<string, Set<string>>;\n\nconst defaultOptions: SheetOptions = {\n isServer: !IS_BROWSER,\n useCSSOMInjection: !DISABLE_SPEEDY,\n};\n\n/** Contains the main stylesheet logic for stringification and caching */\nexport default class StyleSheet implements Sheet {\n gs: GlobalStylesAllocationMap;\n\n names: NamesAllocationMap;\n\n options: SheetOptions;\n\n tag: void | GroupedTag;\n\n /** Register a group ID to give it an index */\n static registerId(id: string): number {\n return getGroupForId(id);\n }\n\n constructor(\n options: SheetConstructorArgs = EMPTY_OBJECT,\n globalStyles?: GlobalStylesAllocationMap = {},\n names?: NamesAllocationMap\n ) {\n this.options = {\n ...defaultOptions,\n ...options,\n };\n\n this.gs = globalStyles;\n this.names = new Map(names);\n\n // We rehydrate only once and use the sheet that is created first\n if (!this.options.isServer && IS_BROWSER && SHOULD_REHYDRATE) {\n SHOULD_REHYDRATE = false;\n rehydrateSheet(this);\n }\n }\n\n reconstructWithOptions(options: SheetConstructorArgs, withNames?: boolean = true) {\n return new StyleSheet(\n { ...this.options, ...options },\n this.gs,\n (withNames && this.names) || undefined\n );\n }\n\n allocateGSInstance(id: string) {\n return (this.gs[id] = (this.gs[id] || 0) + 1);\n }\n\n /** Lazily initialises a GroupedTag for when it's actually needed */\n getTag(): GroupedTag {\n return this.tag || (this.tag = makeGroupedTag(makeTag(this.options)));\n }\n\n /** Check whether a name is known for caching */\n hasNameForId(id: string, name: string): boolean {\n return this.names.has(id) && (this.names.get(id): any).has(name);\n }\n\n /** Mark a group's name as known for caching */\n registerName(id: string, name: string) {\n getGroupForId(id);\n\n if (!this.names.has(id)) {\n const groupNames = new Set();\n groupNames.add(name);\n this.names.set(id, groupNames);\n } else {\n (this.names.get(id): any).add(name);\n }\n }\n\n /** Insert new rules which also marks the name as known */\n insertRules(id: string, name: string, rules: string[]) {\n this.registerName(id, name);\n this.getTag().insertRules(getGroupForId(id), rules);\n }\n\n /** Clears all cached names for a given group ID */\n clearNames(id: string) {\n if (this.names.has(id)) {\n (this.names.get(id): any).clear();\n }\n }\n\n /** Clears all rules for a given group ID */\n clearRules(id: string) {\n this.getTag().clearGroup(getGroupForId(id));\n this.clearNames(id);\n }\n\n /** Clears the entire tag which deletes all rules but not its names */\n clearTag() {\n // NOTE: This does not clear the names, since it's only used during SSR\n // so that we can continuously output only new rules\n this.tag = undefined;\n }\n\n /** Outputs the current sheet as a CSS string with markers for SSR */\n toString(): string {\n return outputSheet(this);\n }\n}\n","// @flow\nimport isFunction from './isFunction';\nimport isStyledComponent from './isStyledComponent';\nimport type { RuleSet } from '../types';\n\nexport default function isStaticRules(rules: RuleSet): boolean {\n for (let i = 0; i < rules.length; i += 1) {\n const rule = rules[i];\n\n if (isFunction(rule) && !isStyledComponent(rule)) {\n // functions are allowed to be static if they're just being\n // used to get the classname of a nested styled component\n return false;\n }\n }\n\n return true;\n}\n","// @flow\nimport StyleSheet from '../sheet';\nimport { type Stringifier } from '../types';\nimport throwStyledError from '../utils/error';\nimport { masterStylis } from './StyleSheetManager';\n\nexport default class Keyframes {\n id: string;\n\n name: string;\n\n rules: string;\n\n constructor(name: string, rules: string) {\n this.name = name;\n this.id = `sc-keyframes-${name}`;\n this.rules = rules;\n }\n\n inject = (styleSheet: StyleSheet, stylisInstance: Stringifier = masterStylis) => {\n const resolvedName = this.name + stylisInstance.hash;\n\n if (!styleSheet.hasNameForId(this.id, resolvedName)) {\n styleSheet.insertRules(\n this.id,\n resolvedName,\n stylisInstance(this.rules, resolvedName, '@keyframes')\n );\n }\n };\n\n toString = () => {\n return throwStyledError(12, String(this.name));\n };\n\n getName(stylisInstance: Stringifier = masterStylis) {\n return this.name + stylisInstance.hash;\n }\n}\n","// @flow\nimport StyleSheet from '../sheet';\nimport type { RuleSet, Stringifier } from '../types';\nimport flatten from '../utils/flatten';\nimport isStaticRules from '../utils/isStaticRules';\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);\n\n // pre-register the first instance to ensure global styles\n // load before component ones\n StyleSheet.registerId(this.componentId + 1);\n }\n\n createStyles(\n instance: number,\n executionContext: Object,\n styleSheet: StyleSheet,\n stylis: Stringifier\n ) {\n const flatCSS = flatten(this.rules, executionContext, styleSheet, stylis);\n const css = stylis(flatCSS.join(''), '');\n const id = this.componentId + instance;\n\n // NOTE: We use the id as a name as well, since these rules never change\n styleSheet.insertRules(id, id, css);\n }\n\n removeStyles(instance: number, styleSheet: StyleSheet) {\n styleSheet.clearRules(this.componentId + instance);\n }\n\n renderStyles(\n instance: number,\n executionContext: Object,\n styleSheet: StyleSheet,\n stylis: Stringifier\n ) {\n if (instance > 2) StyleSheet.registerId(this.componentId + instance);\n\n // NOTE: Remove old styles, then inject the new ones\n this.removeStyles(instance, styleSheet);\n this.createStyles(instance, executionContext, styleSheet, stylis);\n }\n}\n","// @flow\n/* eslint-disable no-underscore-dangle */\nimport React from 'react';\nimport { IS_BROWSER, SC_ATTR, SC_ATTR_VERSION, SC_VERSION } from '../constants';\nimport throwStyledError from '../utils/error';\nimport getNonce from '../utils/nonce';\nimport StyleSheet from '../sheet';\nimport StyleSheetManager from './StyleSheetManager';\n\ndeclare var __SERVER__: boolean;\n\nconst CLOSING_TAG_R = /^\\s*<\\/[a-z]/i;\n\nexport default class ServerStyleSheet {\n isStreaming: boolean;\n\n instance: StyleSheet;\n\n sealed: boolean;\n\n constructor() {\n this.instance = new StyleSheet({ isServer: true });\n this.sealed = false;\n }\n\n _emitSheetCSS = (): string => {\n const css = this.instance.toString();\n const nonce = getNonce();\n const attrs = [nonce && `nonce=\"${nonce}\"`, `${SC_ATTR}=\"true\"`, `${SC_ATTR_VERSION}=\"${SC_VERSION}\"`];\n const htmlAttr = attrs.filter(Boolean).join(' ');\n\n return `<style ${htmlAttr}>${css}</style>`;\n };\n\n collectStyles(children: any) {\n if (this.sealed) {\n return throwStyledError(2);\n }\n\n return <StyleSheetManager sheet={this.instance}>{children}</StyleSheetManager>;\n }\n\n getStyleTags = (): string => {\n if (this.sealed) {\n return throwStyledError(2);\n }\n\n return this._emitSheetCSS();\n };\n\n getStyleElement = () => {\n if (this.sealed) {\n return throwStyledError(2);\n }\n\n const props = {\n [SC_ATTR]: '',\n [SC_ATTR_VERSION]: SC_VERSION,\n dangerouslySetInnerHTML: {\n __html: this.instance.toString(),\n },\n };\n\n const nonce = getNonce();\n if (nonce) {\n (props: any).nonce = nonce;\n }\n\n // v4 returned an array for this fn, so we'll do the same for v5 for backward compat\n return [<style {...props} key=\"sc-0-0\" />];\n };\n\n // eslint-disable-next-line consistent-return\n interleaveWithNodeStream(input: any) {\n if (!__SERVER__ || IS_BROWSER) {\n return throwStyledError(3);\n } else if (this.sealed) {\n return throwStyledError(2);\n }\n\n if (__SERVER__) {\n this.seal();\n\n // eslint-disable-next-line global-require\n const { Readable, Transform } = require('stream');\n\n const readableStream: Readable = input;\n const { instance: sheet, _emitSheetCSS } = this;\n\n const transformer = new Transform({\n transform: function appendStyleChunks(chunk, /* encoding */ _, callback) {\n // Get the chunk and retrieve the sheet's CSS as an HTML chunk,\n // then reset its rules so we get only new ones for the next chunk\n const renderedHtml = chunk.toString();\n const html = _emitSheetCSS();\n\n sheet.clearTag();\n\n // prepend style html to chunk, unless the start of the chunk is a\n // closing tag in which case append right after that\n if (CLOSING_TAG_R.test(renderedHtml)) {\n const endOfClosingTag = renderedHtml.indexOf('>') + 1;\n const before = renderedHtml.slice(0, endOfClosingTag);\n const after = renderedHtml.slice(endOfClosingTag);\n\n this.push(before + html + after);\n } else {\n this.push(html + renderedHtml);\n }\n\n callback();\n },\n });\n\n readableStream.on('error', err => {\n // forward the error to the transform stream\n transformer.emit('error', err);\n });\n\n return readableStream.pipe(transformer);\n }\n }\n\n seal = () => {\n this.sealed = true;\n };\n}\n","// @flow\nimport validAttr from '@emotion/is-prop-valid';\nimport hoist from 'hoist-non-react-statics';\nimport React, { createElement, type Ref, useContext, useDebugValue } from 'react';\nimport { SC_VERSION } from '../constants';\nimport type {\n Attrs,\n IStyledComponent,\n IStyledStatics,\n RuleSet,\n ShouldForwardProp,\n Target,\n} from '../types';\nimport { checkDynamicCreation } from '../utils/checkDynamicCreation';\nimport createWarnTooManyClasses from '../utils/createWarnTooManyClasses';\nimport determineTheme from '../utils/determineTheme';\nimport { EMPTY_ARRAY, EMPTY_OBJECT } from '../utils/empties';\nimport escape from '../utils/escape';\nimport generateComponentId from '../utils/generateComponentId';\nimport generateDisplayName from '../utils/generateDisplayName';\nimport getComponentName from '../utils/getComponentName';\nimport isFunction from '../utils/isFunction';\nimport isStyledComponent from '../utils/isStyledComponent';\nimport isTag from '../utils/isTag';\nimport joinStrings from '../utils/joinStrings';\nimport merge from '../utils/mixinDeep';\nimport ComponentStyle from './ComponentStyle';\nimport { useStyleSheet, useStylis } from './StyleSheetManager';\nimport { ThemeContext } from './ThemeProvider';\n\nconst identifiers = {};\n\n/* We depend on components having unique IDs */\nfunction generateId(displayName?: string, parentComponentId?: string) {\n const name = typeof displayName !== 'string' ? 'sc' : escape(displayName);\n // Ensure that no displayName can lead to duplicate componentIds\n identifiers[name] = (identifiers[name] || 0) + 1;\n\n const componentId = `${name}-${generateComponentId(\n // SC_VERSION gives us isolation between multiple runtimes on the page at once\n // this is improved further with use of the babel plugin \"namespace\" feature\n SC_VERSION + name + identifiers[name]\n )}`;\n\n return parentComponentId ? `${parentComponentId}-${componentId}` : componentId;\n}\n\nfunction useResolvedAttrs<Config>(theme: any = EMPTY_OBJECT, props: Config, attrs: Attrs) {\n // NOTE: can't memoize this\n // returns [context, resolvedAttrs]\n // where resolvedAttrs is only the things injected by the attrs themselves\n const context = { ...props, theme };\n const resolvedAttrs = {};\n\n attrs.forEach(attrDef => {\n let resolvedAttrDef = attrDef;\n let key;\n\n if (isFunction(resolvedAttrDef)) {\n resolvedAttrDef = resolvedAttrDef(context);\n }\n\n /* eslint-disable guard-for-in */\n for (key in resolvedAttrDef) {\n context[key] = resolvedAttrs[key] =\n key === 'className'\n ? joinStrings(resolvedAttrs[key], resolvedAttrDef[key])\n : resolvedAttrDef[key];\n }\n /* eslint-enable guard-for-in */\n });\n\n return [context, resolvedAttrs];\n}\n\nfunction useInjectedStyle<T>(\n componentStyle: ComponentStyle,\n isStatic: boolean,\n resolvedAttrs: T,\n warnTooManyClasses?: $Call<typeof createWarnTooManyClasses, string, string>\n) {\n const styleSheet = useStyleSheet();\n const stylis = useStylis();\n\n const className = isStatic\n ? componentStyle.generateAndInjectStyles(EMPTY_OBJECT, styleSheet, stylis)\n : componentStyle.generateAndInjectStyles(resolvedAttrs, styleSheet, stylis);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n if (process.env.NODE_ENV !== 'production') useDebugValue(className);\n\n if (process.env.NODE_ENV !== 'production' && !isStatic && warnTooManyClasses) {\n warnTooManyClasses(className);\n }\n\n return className;\n}\n\nfunction useStyledComponentImpl(\n forwardedComponent: IStyledComponent,\n props: Object,\n forwardedRef: Ref<any>,\n isStatic: boolean\n) {\n const {\n attrs: componentAttrs,\n componentStyle,\n defaultProps,\n foldedComponentIds,\n shouldForwardProp,\n styledComponentId,\n target,\n } = forwardedComponent;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n if (process.env.NODE_ENV !== 'production') useDebugValue(styledComponentId);\n\n // NOTE: the non-hooks version only subscribes to this when !componentStyle.isStatic,\n // but that'd be against the rules-of-hooks. We could be naughty and do it anyway as it\n // should be an immutable value, but behave for now.\n const theme = determineTheme(props, useContext(ThemeContext), defaultProps);\n\n const [context, attrs] = useResolvedAttrs(theme || EMPTY_OBJECT, props, componentAttrs);\n\n const generatedClassName = useInjectedStyle(\n componentStyle,\n isStatic,\n context,\n process.env.NODE_ENV !== 'production' ? forwardedComponent.warnTooManyClasses : undefined\n );\n\n const refToForward = forwardedRef;\n\n const elementToBeCreated: Target = attrs.$as || props.$as || attrs.as || props.as || target;\n\n const isTargetTag = isTag(elementToBeCreated);\n const computedProps = attrs !== props ? { ...props, ...attrs } : props;\n const propsForElement = {};\n\n // eslint-disable-next-line guard-for-in\n for (const key in computedProps) {\n if (key[0] === '$' || key === 'as') continue;\n else if (key === 'forwardedAs') {\n propsForElement.as = computedProps[key];\n } else if (\n shouldForwardProp ? shouldForwardProp(key, validAttr) : isTargetTag ? validAttr(key) : true\n ) {\n // Don't pass through non HTML tags through to HTML elements\n propsForElement[key] = computedProps[key];\n }\n }\n\n if (props.style && attrs.style !== props.style) {\n propsForElement.style = { ...props.style, ...attrs.style };\n }\n\n propsForElement.className = Array.prototype\n .concat(\n foldedComponentIds,\n styledComponentId,\n generatedClassName !== styledComponentId ? generatedClassName : null,\n props.className,\n attrs.className\n )\n .filter(Boolean)\n .join(' ');\n\n propsForElement.ref = refToForward;\n\n return createElement(elementToBeCreated, propsForElement);\n}\n\nexport default function createStyledComponent(\n target: $PropertyType<IStyledComponent, 'target'>,\n options: {\n attrs?: Attrs,\n componentId: string,\n displayName?: string,\n parentComponentId?: string,\n shouldForwardProp?: ShouldForwardProp,\n },\n rules: RuleSet\n) {\n const isTargetStyledComp = isStyledComponent(target);\n const isCompositeComponent = !isTag(target);\n\n const {\n attrs = EMPTY_ARRAY,\n componentId = generateId(options.displayName, options.parentComponentId),\n displayName = generateDisplayName(target),\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 isTargetStyledComp && ((target: any): IStyledComponent).attrs\n ? Array.prototype.concat(((target: any): IStyledComponent).attrs, attrs).filter(Boolean)\n : attrs;\n\n // eslint-disable-next-line prefer-destructuring\n let shouldForwardProp = options.shouldForwardProp;\n\n if (isTargetStyledComp && target.shouldForwardProp) {\n if (options.shouldForwardProp) {\n // compose nested shouldForwardProp calls\n shouldForwardProp = (prop, filterFn) =>\n ((((target: any): IStyledComponent).shouldForwardProp: any): ShouldForwardProp)(\n prop,\n filterFn\n ) && ((options.shouldForwardProp: any): ShouldForwardProp)(prop, filterFn);\n } else {\n // eslint-disable-next-line prefer-destructuring\n shouldForwardProp = ((target: any): IStyledComponent).shouldForwardProp;\n }\n }\n\n const componentStyle = new ComponentStyle(\n rules,\n styledComponentId,\n isTargetStyledComp ? ((target: Object).componentStyle: ComponentStyle) : undefined\n );\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 const isStatic = componentStyle.isStatic && attrs.length === 0;\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: IStyledComponent;\n\n const forwardRef = (props, ref) =>\n // eslint-disable-next-line\n useStyledComponentImpl(WrappedStyledComponent, props, ref, isStatic);\n\n forwardRef.displayName = displayName;\n\n WrappedStyledComponent = ((React.forwardRef(forwardRef): any): IStyledComponent);\n WrappedStyledComponent.attrs = finalAttrs;\n WrappedStyledComponent.componentStyle = componentStyle;\n WrappedStyledComponent.displayName = displayName;\n WrappedStyledComponent.shouldForwardProp = shouldForwardProp;\n\n // this static is used to preserve the cascade of static classes for component selector\n // purposes; this is especially important with usage of the css prop\n WrappedStyledComponent.foldedComponentIds = isTargetStyledComp\n ? Array.prototype.concat(\n ((target: any): IStyledComponent).foldedComponentIds,\n ((target: any): IStyledComponent).styledComponentId\n )\n : EMPTY_ARRAY;\n\n WrappedStyledComponent.styledComponentId = styledComponentId;\n\n // fold the underlying StyledComponent target up since we folded the styles\n WrappedStyledComponent.target = isTargetStyledComp\n ? ((target: any): IStyledComponent).target\n : target;\n\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 };\n\n return createStyledComponent(tag, newOptions, rules);\n };\n\n Object.defineProperty(WrappedStyledComponent, 'defaultProps', {\n get() {\n return this._foldedDefaultProps;\n },\n\n set(obj) {\n this._foldedDefaultProps = isTargetStyledComp\n ? merge({}, ((target: any): IStyledComponent).defaultProps, obj)\n : obj;\n },\n });\n\n if (process.env.NODE_ENV !== 'production') {\n checkDynamicCreation(displayName, styledComponentId);\n\n WrappedStyledComponent.warnTooManyClasses = createWarnTooManyClasses(\n displayName,\n styledComponentId\n );\n }\n\n WrappedStyledComponent.toString = () => `.${WrappedStyledComponent.styledComponentId}`;\n\n if (isCompositeComponent) {\n hoist<\n IStyledStatics,\n $PropertyType<IStyledComponent, 'target'>,\n { [key: $Keys<IStyledStatics>]: true }\n >(WrappedStyledComponent, ((target: any): $PropertyType<IStyledComponent, 'target'>), {\n // all SC-specific things should not be hoisted\n attrs: true,\n componentStyle: true,\n displayName: true,\n foldedComponentIds: true,\n shouldForwardProp: true,\n styledComponentId: true,\n target: true,\n withComponent: true,\n });\n }\n\n return WrappedStyledComponent;\n}\n"],"names":["nodes","insertRule","names","id","flatten","React","options"],"mappings":"mqJAsF0BA,gHAgBxBC,WAAA,yWC3DQC,yxBAmC8BC,iOAkBVA,6xBC3FuB,gxWCcHA,4nECM9BC,kCAEVD,s3BCsCEE,owSCuMuDC,qJAAAA"}
|
|
@@ -154,17 +154,14 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
154
154
|
var SC_ATTR = typeof process !== 'undefined' && (process.env.REACT_APP_SC_ATTR || process.env.SC_ATTR) || 'data-styled';
|
|
155
155
|
var SC_ATTR_ACTIVE = 'active';
|
|
156
156
|
var SC_ATTR_VERSION = 'data-styled-version';
|
|
157
|
-
var SC_VERSION = "5.2.
|
|
157
|
+
var SC_VERSION = "5.2.1";
|
|
158
158
|
var SPLITTER = '/*!sc*/\n';
|
|
159
159
|
var IS_BROWSER = typeof window !== 'undefined' && 'HTMLElement' in window;
|
|
160
|
-
var DISABLE_SPEEDY = typeof SC_DISABLE_SPEEDY === 'boolean'
|
|
160
|
+
var DISABLE_SPEEDY = Boolean(typeof SC_DISABLE_SPEEDY === 'boolean' ? SC_DISABLE_SPEEDY : typeof process !== 'undefined' && typeof process.env.REACT_APP_SC_DISABLE_SPEEDY !== 'undefined' && process.env.REACT_APP_SC_DISABLE_SPEEDY !== '' ? process.env.REACT_APP_SC_DISABLE_SPEEDY === 'false' ? false : process.env.REACT_APP_SC_DISABLE_SPEEDY : typeof process !== 'undefined' && typeof process.env.SC_DISABLE_SPEEDY !== 'undefined' && process.env.SC_DISABLE_SPEEDY !== '' ? process.env.SC_DISABLE_SPEEDY === 'false' ? false : process.env.SC_DISABLE_SPEEDY : process.env.NODE_ENV !== 'production'); // Shared empty execution context when generating static styles
|
|
161
161
|
|
|
162
162
|
//
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
var getNonce = function getNonce() {
|
|
166
|
-
return typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;
|
|
167
|
-
};
|
|
163
|
+
var EMPTY_ARRAY = Object.freeze([]);
|
|
164
|
+
var EMPTY_OBJECT = Object.freeze({});
|
|
168
165
|
|
|
169
166
|
var errorMap = {
|
|
170
167
|
"1": "Cannot create styled-component for component: %s.\n\n",
|
|
@@ -223,192 +220,6 @@ function throwStyledComponentsError(code) {
|
|
|
223
220
|
}
|
|
224
221
|
}
|
|
225
222
|
|
|
226
|
-
//
|
|
227
|
-
var ELEMENT_TYPE = 1;
|
|
228
|
-
/* Node.ELEMENT_TYPE */
|
|
229
|
-
|
|
230
|
-
/** Find last style element if any inside target */
|
|
231
|
-
|
|
232
|
-
var findLastStyleTag = function findLastStyleTag(target) {
|
|
233
|
-
var childNodes = target.childNodes;
|
|
234
|
-
|
|
235
|
-
for (var i = childNodes.length; i >= 0; i--) {
|
|
236
|
-
var child = childNodes[i];
|
|
237
|
-
|
|
238
|
-
if (child && child.nodeType === ELEMENT_TYPE && child.hasAttribute(SC_ATTR)) {
|
|
239
|
-
return child;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return undefined;
|
|
244
|
-
};
|
|
245
|
-
/** Create a style element inside `target` or <head> after the last */
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
var makeStyleTag = function makeStyleTag(target) {
|
|
249
|
-
var head = document.head;
|
|
250
|
-
var parent = target || head;
|
|
251
|
-
var style = document.createElement('style');
|
|
252
|
-
var prevStyle = findLastStyleTag(parent);
|
|
253
|
-
var nextSibling = prevStyle !== undefined ? prevStyle.nextSibling : null;
|
|
254
|
-
style.setAttribute(SC_ATTR, SC_ATTR_ACTIVE);
|
|
255
|
-
style.setAttribute(SC_ATTR_VERSION, SC_VERSION);
|
|
256
|
-
var nonce = getNonce();
|
|
257
|
-
if (nonce) style.setAttribute('nonce', nonce);
|
|
258
|
-
parent.insertBefore(style, nextSibling);
|
|
259
|
-
return style;
|
|
260
|
-
};
|
|
261
|
-
/** Get the CSSStyleSheet instance for a given style element */
|
|
262
|
-
|
|
263
|
-
var getSheet = function getSheet(tag) {
|
|
264
|
-
if (tag.sheet) {
|
|
265
|
-
return tag.sheet;
|
|
266
|
-
} // Avoid Firefox quirk where the style element might not have a sheet property
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
var _document = document,
|
|
270
|
-
styleSheets = _document.styleSheets;
|
|
271
|
-
|
|
272
|
-
for (var i = 0, l = styleSheets.length; i < l; i++) {
|
|
273
|
-
var sheet = styleSheets[i];
|
|
274
|
-
|
|
275
|
-
if (sheet.ownerNode === tag) {
|
|
276
|
-
return sheet;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
throwStyledComponentsError(17);
|
|
281
|
-
return undefined;
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
//
|
|
285
|
-
/** Create a CSSStyleSheet-like tag depending on the environment */
|
|
286
|
-
|
|
287
|
-
var makeTag = function makeTag(_ref) {
|
|
288
|
-
var isServer = _ref.isServer,
|
|
289
|
-
useCSSOMInjection = _ref.useCSSOMInjection,
|
|
290
|
-
target = _ref.target;
|
|
291
|
-
|
|
292
|
-
if (isServer) {
|
|
293
|
-
return new VirtualTag(target);
|
|
294
|
-
} else if (useCSSOMInjection) {
|
|
295
|
-
return new CSSOMTag(target);
|
|
296
|
-
} else {
|
|
297
|
-
return new TextTag(target);
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
var CSSOMTag = /*#__PURE__*/function () {
|
|
301
|
-
function CSSOMTag(target) {
|
|
302
|
-
var element = this.element = makeStyleTag(target); // Avoid Edge bug where empty style elements don't create sheets
|
|
303
|
-
|
|
304
|
-
element.appendChild(document.createTextNode(''));
|
|
305
|
-
this.sheet = getSheet(element);
|
|
306
|
-
this.length = 0;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
var _proto = CSSOMTag.prototype;
|
|
310
|
-
|
|
311
|
-
_proto.insertRule = function insertRule(index, rule) {
|
|
312
|
-
try {
|
|
313
|
-
this.sheet.insertRule(rule, index);
|
|
314
|
-
this.length++;
|
|
315
|
-
return true;
|
|
316
|
-
} catch (_error) {
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
_proto.deleteRule = function deleteRule(index) {
|
|
322
|
-
this.sheet.deleteRule(index);
|
|
323
|
-
this.length--;
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
_proto.getRule = function getRule(index) {
|
|
327
|
-
var rule = this.sheet.cssRules[index]; // Avoid IE11 quirk where cssText is inaccessible on some invalid rules
|
|
328
|
-
|
|
329
|
-
if (rule !== undefined && typeof rule.cssText === 'string') {
|
|
330
|
-
return rule.cssText;
|
|
331
|
-
} else {
|
|
332
|
-
return '';
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
return CSSOMTag;
|
|
337
|
-
}();
|
|
338
|
-
/** A Tag that emulates the CSSStyleSheet API but uses text nodes */
|
|
339
|
-
|
|
340
|
-
var TextTag = /*#__PURE__*/function () {
|
|
341
|
-
function TextTag(target) {
|
|
342
|
-
var element = this.element = makeStyleTag(target);
|
|
343
|
-
this.nodes = element.childNodes;
|
|
344
|
-
this.length = 0;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
var _proto2 = TextTag.prototype;
|
|
348
|
-
|
|
349
|
-
_proto2.insertRule = function insertRule(index, rule) {
|
|
350
|
-
if (index <= this.length && index >= 0) {
|
|
351
|
-
var node = document.createTextNode(rule);
|
|
352
|
-
var refNode = this.nodes[index];
|
|
353
|
-
this.element.insertBefore(node, refNode || null);
|
|
354
|
-
this.length++;
|
|
355
|
-
return true;
|
|
356
|
-
} else {
|
|
357
|
-
return false;
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
_proto2.deleteRule = function deleteRule(index) {
|
|
362
|
-
this.element.removeChild(this.nodes[index]);
|
|
363
|
-
this.length--;
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
_proto2.getRule = function getRule(index) {
|
|
367
|
-
if (index < this.length) {
|
|
368
|
-
return this.nodes[index].textContent;
|
|
369
|
-
} else {
|
|
370
|
-
return '';
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
return TextTag;
|
|
375
|
-
}();
|
|
376
|
-
/** A completely virtual (server-side) Tag that doesn't manipulate the DOM */
|
|
377
|
-
|
|
378
|
-
var VirtualTag = /*#__PURE__*/function () {
|
|
379
|
-
function VirtualTag(_target) {
|
|
380
|
-
this.rules = [];
|
|
381
|
-
this.length = 0;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
var _proto3 = VirtualTag.prototype;
|
|
385
|
-
|
|
386
|
-
_proto3.insertRule = function insertRule(index, rule) {
|
|
387
|
-
if (index <= this.length) {
|
|
388
|
-
this.rules.splice(index, 0, rule);
|
|
389
|
-
this.length++;
|
|
390
|
-
return true;
|
|
391
|
-
} else {
|
|
392
|
-
return false;
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
_proto3.deleteRule = function deleteRule(index) {
|
|
397
|
-
this.rules.splice(index, 1);
|
|
398
|
-
this.length--;
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
_proto3.getRule = function getRule(index) {
|
|
402
|
-
if (index < this.length) {
|
|
403
|
-
return this.rules[index];
|
|
404
|
-
} else {
|
|
405
|
-
return '';
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
return VirtualTag;
|
|
410
|
-
}();
|
|
411
|
-
|
|
412
223
|
//
|
|
413
224
|
/** Create a GroupedTag with an underlying Tag implementation */
|
|
414
225
|
|
|
@@ -513,6 +324,10 @@ var getGroupForId = function getGroupForId(id) {
|
|
|
513
324
|
return groupIDRegister.get(id);
|
|
514
325
|
}
|
|
515
326
|
|
|
327
|
+
while (reverseRegister.has(nextFreeGroup)) {
|
|
328
|
+
nextFreeGroup++;
|
|
329
|
+
}
|
|
330
|
+
|
|
516
331
|
var group = nextFreeGroup++;
|
|
517
332
|
|
|
518
333
|
if (process.env.NODE_ENV !== 'production' && ((group | 0) < 0 || group > MAX_SMI)) {
|
|
@@ -527,10 +342,6 @@ var getIdForGroup = function getIdForGroup(group) {
|
|
|
527
342
|
return reverseRegister.get(group);
|
|
528
343
|
};
|
|
529
344
|
var setGroupForId = function setGroupForId(id, group) {
|
|
530
|
-
if (group >= nextFreeGroup) {
|
|
531
|
-
nextFreeGroup = group + 1;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
345
|
groupIDRegister.set(id, group);
|
|
535
346
|
reverseRegister.set(group, id);
|
|
536
347
|
};
|
|
@@ -625,6 +436,199 @@ var rehydrateSheet = function rehydrateSheet(sheet) {
|
|
|
625
436
|
}
|
|
626
437
|
};
|
|
627
438
|
|
|
439
|
+
//
|
|
440
|
+
|
|
441
|
+
/* eslint-disable camelcase, no-undef */
|
|
442
|
+
var getNonce = function getNonce() {
|
|
443
|
+
return typeof __webpack_nonce__ !== 'undefined' ? __webpack_nonce__ : null;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
//
|
|
447
|
+
var ELEMENT_TYPE = 1;
|
|
448
|
+
/* Node.ELEMENT_TYPE */
|
|
449
|
+
|
|
450
|
+
/** Find last style element if any inside target */
|
|
451
|
+
|
|
452
|
+
var findLastStyleTag = function findLastStyleTag(target) {
|
|
453
|
+
var childNodes = target.childNodes;
|
|
454
|
+
|
|
455
|
+
for (var i = childNodes.length; i >= 0; i--) {
|
|
456
|
+
var child = childNodes[i];
|
|
457
|
+
|
|
458
|
+
if (child && child.nodeType === ELEMENT_TYPE && child.hasAttribute(SC_ATTR)) {
|
|
459
|
+
return child;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return undefined;
|
|
464
|
+
};
|
|
465
|
+
/** Create a style element inside `target` or <head> after the last */
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
var makeStyleTag = function makeStyleTag(target) {
|
|
469
|
+
var head = document.head;
|
|
470
|
+
var parent = target || head;
|
|
471
|
+
var style = document.createElement('style');
|
|
472
|
+
var prevStyle = findLastStyleTag(parent);
|
|
473
|
+
var nextSibling = prevStyle !== undefined ? prevStyle.nextSibling : null;
|
|
474
|
+
style.setAttribute(SC_ATTR, SC_ATTR_ACTIVE);
|
|
475
|
+
style.setAttribute(SC_ATTR_VERSION, SC_VERSION);
|
|
476
|
+
var nonce = getNonce();
|
|
477
|
+
if (nonce) style.setAttribute('nonce', nonce);
|
|
478
|
+
parent.insertBefore(style, nextSibling);
|
|
479
|
+
return style;
|
|
480
|
+
};
|
|
481
|
+
/** Get the CSSStyleSheet instance for a given style element */
|
|
482
|
+
|
|
483
|
+
var getSheet = function getSheet(tag) {
|
|
484
|
+
if (tag.sheet) {
|
|
485
|
+
return tag.sheet;
|
|
486
|
+
} // Avoid Firefox quirk where the style element might not have a sheet property
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
var _document = document,
|
|
490
|
+
styleSheets = _document.styleSheets;
|
|
491
|
+
|
|
492
|
+
for (var i = 0, l = styleSheets.length; i < l; i++) {
|
|
493
|
+
var sheet = styleSheets[i];
|
|
494
|
+
|
|
495
|
+
if (sheet.ownerNode === tag) {
|
|
496
|
+
return sheet;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
throwStyledComponentsError(17);
|
|
501
|
+
return undefined;
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
//
|
|
505
|
+
/** Create a CSSStyleSheet-like tag depending on the environment */
|
|
506
|
+
|
|
507
|
+
var makeTag = function makeTag(_ref) {
|
|
508
|
+
var isServer = _ref.isServer,
|
|
509
|
+
useCSSOMInjection = _ref.useCSSOMInjection,
|
|
510
|
+
target = _ref.target;
|
|
511
|
+
|
|
512
|
+
if (isServer) {
|
|
513
|
+
return new VirtualTag(target);
|
|
514
|
+
} else if (useCSSOMInjection) {
|
|
515
|
+
return new CSSOMTag(target);
|
|
516
|
+
} else {
|
|
517
|
+
return new TextTag(target);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
var CSSOMTag = /*#__PURE__*/function () {
|
|
521
|
+
function CSSOMTag(target) {
|
|
522
|
+
var element = this.element = makeStyleTag(target); // Avoid Edge bug where empty style elements don't create sheets
|
|
523
|
+
|
|
524
|
+
element.appendChild(document.createTextNode(''));
|
|
525
|
+
this.sheet = getSheet(element);
|
|
526
|
+
this.length = 0;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
var _proto = CSSOMTag.prototype;
|
|
530
|
+
|
|
531
|
+
_proto.insertRule = function insertRule(index, rule) {
|
|
532
|
+
try {
|
|
533
|
+
this.sheet.insertRule(rule, index);
|
|
534
|
+
this.length++;
|
|
535
|
+
return true;
|
|
536
|
+
} catch (_error) {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
_proto.deleteRule = function deleteRule(index) {
|
|
542
|
+
this.sheet.deleteRule(index);
|
|
543
|
+
this.length--;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
_proto.getRule = function getRule(index) {
|
|
547
|
+
var rule = this.sheet.cssRules[index]; // Avoid IE11 quirk where cssText is inaccessible on some invalid rules
|
|
548
|
+
|
|
549
|
+
if (rule !== undefined && typeof rule.cssText === 'string') {
|
|
550
|
+
return rule.cssText;
|
|
551
|
+
} else {
|
|
552
|
+
return '';
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
return CSSOMTag;
|
|
557
|
+
}();
|
|
558
|
+
/** A Tag that emulates the CSSStyleSheet API but uses text nodes */
|
|
559
|
+
|
|
560
|
+
var TextTag = /*#__PURE__*/function () {
|
|
561
|
+
function TextTag(target) {
|
|
562
|
+
var element = this.element = makeStyleTag(target);
|
|
563
|
+
this.nodes = element.childNodes;
|
|
564
|
+
this.length = 0;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
var _proto2 = TextTag.prototype;
|
|
568
|
+
|
|
569
|
+
_proto2.insertRule = function insertRule(index, rule) {
|
|
570
|
+
if (index <= this.length && index >= 0) {
|
|
571
|
+
var node = document.createTextNode(rule);
|
|
572
|
+
var refNode = this.nodes[index];
|
|
573
|
+
this.element.insertBefore(node, refNode || null);
|
|
574
|
+
this.length++;
|
|
575
|
+
return true;
|
|
576
|
+
} else {
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
_proto2.deleteRule = function deleteRule(index) {
|
|
582
|
+
this.element.removeChild(this.nodes[index]);
|
|
583
|
+
this.length--;
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
_proto2.getRule = function getRule(index) {
|
|
587
|
+
if (index < this.length) {
|
|
588
|
+
return this.nodes[index].textContent;
|
|
589
|
+
} else {
|
|
590
|
+
return '';
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
return TextTag;
|
|
595
|
+
}();
|
|
596
|
+
/** A completely virtual (server-side) Tag that doesn't manipulate the DOM */
|
|
597
|
+
|
|
598
|
+
var VirtualTag = /*#__PURE__*/function () {
|
|
599
|
+
function VirtualTag(_target) {
|
|
600
|
+
this.rules = [];
|
|
601
|
+
this.length = 0;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
var _proto3 = VirtualTag.prototype;
|
|
605
|
+
|
|
606
|
+
_proto3.insertRule = function insertRule(index, rule) {
|
|
607
|
+
if (index <= this.length) {
|
|
608
|
+
this.rules.splice(index, 0, rule);
|
|
609
|
+
this.length++;
|
|
610
|
+
return true;
|
|
611
|
+
} else {
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
_proto3.deleteRule = function deleteRule(index) {
|
|
617
|
+
this.rules.splice(index, 1);
|
|
618
|
+
this.length--;
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
_proto3.getRule = function getRule(index) {
|
|
622
|
+
if (index < this.length) {
|
|
623
|
+
return this.rules[index];
|
|
624
|
+
} else {
|
|
625
|
+
return '';
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
return VirtualTag;
|
|
630
|
+
}();
|
|
631
|
+
|
|
628
632
|
var SHOULD_REHYDRATE = IS_BROWSER;
|
|
629
633
|
var defaultOptions = {
|
|
630
634
|
isServer: !IS_BROWSER,
|
|
@@ -640,7 +644,7 @@ var StyleSheet = /*#__PURE__*/function () {
|
|
|
640
644
|
|
|
641
645
|
function StyleSheet(options, globalStyles, names) {
|
|
642
646
|
if (options === void 0) {
|
|
643
|
-
options =
|
|
647
|
+
options = EMPTY_OBJECT;
|
|
644
648
|
}
|
|
645
649
|
|
|
646
650
|
if (globalStyles === void 0) {
|
|
@@ -736,10 +740,6 @@ var StyleSheet = /*#__PURE__*/function () {
|
|
|
736
740
|
return StyleSheet;
|
|
737
741
|
}();
|
|
738
742
|
|
|
739
|
-
//
|
|
740
|
-
var EMPTY_ARRAY = Object.freeze([]);
|
|
741
|
-
var EMPTY_OBJECT = Object.freeze({});
|
|
742
|
-
|
|
743
743
|
/**
|
|
744
744
|
* MIT License
|
|
745
745
|
*
|
|
@@ -955,7 +955,7 @@ var Keyframes = /*#__PURE__*/function () {
|
|
|
955
955
|
* https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/hyphenateStyleName.js
|
|
956
956
|
*/
|
|
957
957
|
var uppercaseCheck = /([A-Z])/;
|
|
958
|
-
var uppercasePattern =
|
|
958
|
+
var uppercasePattern = /([A-Z])/g;
|
|
959
959
|
var msPattern = /^ms-/;
|
|
960
960
|
|
|
961
961
|
var prefixAndLowerCase = function prefixAndLowerCase(_char) {
|
|
@@ -5877,7 +5877,6 @@ function isTag(target) {
|
|
|
5877
5877
|
|
|
5878
5878
|
//
|
|
5879
5879
|
function generateDisplayName(target) {
|
|
5880
|
-
// $FlowFixMe
|
|
5881
5880
|
return isTag(target) ? "styled." + target : "Styled(" + getComponentName(target) + ")";
|
|
5882
5881
|
}
|
|
5883
5882
|
|