{"version":3,"file":"glamorous.umd.tiny.min.js","sources":["../src/with-theme.js","../src/get-glamor-classname.js","../src/create-glamorous.js","../src/react-compat.js","../src/constants.js","../src/tiny.js"],"sourcesContent":["import React, {Component} from 'react'\n\nimport {CHANNEL} from './constants'\nimport {PropTypes} from './react-compat'\n\nfunction generateWarningMessage(Comp) {\n const componentName = Comp.displayName || Comp.name || 'FunctionComponent'\n // eslint-disable-next-line max-len\n return `glamorous warning: Expected component called \"${componentName}\" which uses withTheme to be within a ThemeProvider but none was found.`\n}\n\nexport default function withTheme(\n ComponentToTheme,\n {noWarn = false, createElement = true} = {},\n) {\n class ThemedComponent extends Component {\n static propTypes = {\n theme: PropTypes.object,\n }\n warned = noWarn\n state = {theme: {}}\n setTheme = theme => this.setState({theme})\n\n // eslint-disable-next-line complexity\n componentWillMount() {\n if (!this.context[CHANNEL]) {\n if (process.env.NODE_ENV !== 'production' && !this.warned) {\n this.warned = true\n // eslint-disable-next-line no-console\n console.warn(generateWarningMessage(ComponentToTheme))\n }\n }\n const {theme} = this.props\n if (this.context[CHANNEL]) {\n // if a theme is provided via props,\n // it takes precedence over context\n this.setTheme(theme ? theme : this.context[CHANNEL].getState())\n } else {\n this.setTheme(theme || {})\n }\n }\n\n componentWillReceiveProps(nextProps) {\n if (this.props.theme !== nextProps.theme) {\n this.setTheme(nextProps.theme)\n }\n }\n\n componentDidMount() {\n if (this.context[CHANNEL] && !this.props.theme) {\n // subscribe to future theme changes\n this.subscriptionId = this.context[CHANNEL].subscribe(this.setTheme)\n }\n }\n\n componentWillUnmount() {\n // cleanup subscription\n this.subscriptionId &&\n this.context[CHANNEL].unsubscribe(this.subscriptionId)\n }\n\n render() {\n if (createElement) {\n return \n } else {\n // this allows us to effectively use the GlamorousComponent\n // as our `render` method without going through lifecycle hooks.\n // Also allows us to forward the context in the scenario where\n // a user wants to add more context.\n // eslint-disable-next-line babel/new-cap\n return ComponentToTheme.call(\n this,\n {...this.props, ...this.state},\n this.context,\n )\n }\n }\n }\n\n const defaultContextTypes = {\n [CHANNEL]: PropTypes.object,\n }\n\n let userDefinedContextTypes = null\n\n // configure the contextTypes to be settable by the user,\n // however also retaining the glamorous channel.\n Object.defineProperty(ThemedComponent, 'contextTypes', {\n enumerable: true,\n configurable: true,\n set(value) {\n userDefinedContextTypes = value\n },\n get() {\n // if the user has provided a contextTypes definition,\n // merge the default context types with the provided ones.\n if (userDefinedContextTypes) {\n return {\n ...defaultContextTypes,\n ...userDefinedContextTypes,\n }\n }\n return defaultContextTypes\n },\n })\n\n return ThemedComponent\n}\n","import {css} from 'glamor'\n/**\n * This function takes a className string and gets all the\n * associated glamor styles. It's used to merge glamor styles\n * from a className to make sure that specificity is not\n * a problem when passing a className to a component.\n * @param {String} [className=''] the className string\n * @return {Object} { glamorStyles, glamorlessClassName }\n * - glamorStyles is an array of all the glamor styles objects\n * - glamorlessClassName is the rest of the className string\n * without the glamor classNames\n */\nfunction extractGlamorStyles(className) {\n const glamorlessClassName = []\n const glamorStyles = []\n className.toString().split(' ').forEach(name => {\n if (name.indexOf('css-') === 0) {\n const style = buildGlamorSrcFromClassName(name)\n glamorStyles.push(style)\n } else {\n glamorlessClassName.push(name)\n }\n })\n\n return {glamorlessClassName, glamorStyles}\n}\n\n/** Glamor's css function returns an object with the shape\n *\n * {\n * [`data-css-${hash}`]: '',\n * toString() { return `css-${hash}` }\n * }\n *\n * Whenever glamor's build function encounters an object with\n * this shape it just pulls the resulting styles from the cache.\n *\n * note: the toString method is not needed to qualify the shape\n**/\nfunction buildGlamorSrcFromClassName(className) {\n return {[`data-${className}`]: ''}\n}\n\nexport default getGlamorClassName\n\nfunction getGlamorClassName({\n styles,\n props,\n cssOverrides,\n cssProp,\n context,\n displayName,\n}) {\n const {mappedArgs, nonGlamorClassNames} = handleStyles(\n [...styles, props.className, cssOverrides, cssProp],\n props,\n context,\n )\n // eslint-disable-next-line max-len\n const isDev = process.env.NODE_ENV === 'development' || !process.env.NODE_ENV\n const devRules = isDev ? {label: displayName} : null\n const glamorClassName = css(devRules, ...mappedArgs).toString()\n const extras = nonGlamorClassNames.join(' ').trim()\n return `${glamorClassName} ${extras}`.trim()\n}\n\n// this next function is on a \"hot\" code-path\n// so it's pretty complex to make sure it's fast.\n// eslint-disable-next-line complexity\nfunction handleStyles(styles, props, context) {\n let current\n const mappedArgs = []\n const nonGlamorClassNames = []\n for (let i = 0; i < styles.length; i++) {\n current = styles[i]\n if (typeof current === 'function') {\n const result = current(props, context)\n if (typeof result === 'string') {\n const {glamorStyles, glamorlessClassName} = extractGlamorStyles(result)\n mappedArgs.push(...glamorStyles)\n nonGlamorClassNames.push(...glamorlessClassName)\n } else {\n mappedArgs.push(result)\n }\n } else if (typeof current === 'string') {\n const {glamorStyles, glamorlessClassName} = extractGlamorStyles(current)\n mappedArgs.push(...glamorStyles)\n nonGlamorClassNames.push(...glamorlessClassName)\n } else if (Array.isArray(current)) {\n const recursed = handleStyles(current, props, context)\n mappedArgs.push(...recursed.mappedArgs)\n nonGlamorClassNames.push(...recursed.nonGlamorClassNames)\n } else {\n mappedArgs.push(current)\n }\n }\n return {mappedArgs, nonGlamorClassNames}\n}\n","/*\n * This is a relatively small abstraction that's ripe for open sourcing.\n * Documentation is in the README.md\n */\nimport React from 'react'\nimport {PropTypes} from './react-compat'\nimport withTheme from './with-theme'\nimport getGlamorClassName from './get-glamor-classname'\n\nexport default createGlamorous\n\nfunction createGlamorous(splitProps) {\n return glamorous\n\n /**\n * This is the main export and the function that people\n * interact with most directly.\n *\n * It accepts a component which can be a string or\n * a React Component and returns\n * a \"glamorousComponentFactory\"\n * @param {String|ReactComponent} comp the component to render\n * @param {Object} options helpful info for the GlamorousComponents\n * @return {Function} the glamorousComponentFactory\n */\n function glamorous(\n comp,\n {\n rootEl,\n displayName,\n shouldClassNameUpdate,\n forwardProps = [],\n propsAreCssOverrides = comp.propsAreCssOverrides,\n withProps: basePropsToApply,\n } = {},\n ) {\n return glamorousComponentFactory\n\n /**\n * This returns a React Component that renders the comp (closure)\n * with a className based on the given glamor styles object(s)\n * @param {...Object|Function} styles the styles to create with glamor.\n * If any of these are functions, they are invoked with the component\n * props and the return value is used.\n * @return {ReactComponent} the ReactComponent function\n */\n function glamorousComponentFactory(...styles) {\n /**\n * This is a component which will render the comp (closure)\n * with the glamorous styles (closure). Forwards any valid\n * props to the underlying component.\n */\n const GlamorousComponent = withTheme(\n function GlamorousInnerComponent(props, context) {\n props = getPropsToApply(\n GlamorousComponent.propsToApply,\n {},\n props,\n context,\n )\n const updateClassName = shouldUpdate(props, context, this.previous)\n\n if (shouldClassNameUpdate) {\n this.previous = {props, context}\n }\n\n const {toForward, cssOverrides, cssProp} = splitProps(\n props,\n GlamorousComponent,\n )\n\n // create className to apply\n this.className = updateClassName ?\n getGlamorClassName({\n styles: GlamorousComponent.styles,\n props,\n cssOverrides,\n cssProp,\n context,\n displayName: GlamorousComponent.displayName,\n }) :\n this.className\n\n return React.createElement(GlamorousComponent.comp, {\n ref: props.innerRef,\n ...toForward,\n className: this.className,\n })\n },\n {noWarn: true, createElement: false},\n )\n\n GlamorousComponent.propTypes = {\n className: PropTypes.string,\n cssOverrides: PropTypes.object,\n innerRef: PropTypes.func,\n glam: PropTypes.object,\n }\n\n function withComponent(newComp, options = {}) {\n return glamorous(newComp, {\n forwardProps: GlamorousComponent.forwardProps,\n ...options,\n })(GlamorousComponent.styles)\n }\n\n function withProps(...propsToApply) {\n return glamorous(GlamorousComponent, {withProps: propsToApply})()\n }\n\n function shouldUpdate(props, context, previous) {\n // exiting early so components which do not use this\n // optimization are not penalized by hanging onto\n // references to previous props and context\n if (!shouldClassNameUpdate) {\n return true\n }\n let update = true\n if (previous) {\n if (\n !shouldClassNameUpdate(\n previous.props,\n props,\n previous.context,\n context,\n )\n ) {\n update = false\n }\n }\n\n return update\n }\n\n Object.assign(\n GlamorousComponent,\n getGlamorousComponentMetadata({\n comp,\n styles,\n rootEl,\n forwardProps,\n displayName,\n propsToApply: basePropsToApply,\n }),\n {\n withComponent,\n isGlamorousComponent: true,\n propsAreCssOverrides,\n withProps,\n },\n )\n return GlamorousComponent\n }\n }\n\n function getGlamorousComponentMetadata({\n comp,\n styles,\n rootEl,\n forwardProps,\n displayName,\n propsToApply: basePropsToApply,\n }) {\n const componentsComp = comp.comp ? comp.comp : comp\n const propsToApply = comp.propsToApply ?\n [...comp.propsToApply, ...arrayify(basePropsToApply)] :\n arrayify(basePropsToApply)\n return {\n // join styles together (for anyone doing: glamorous(glamorous.a({}), {}))\n styles: when(comp.styles, styles),\n // keep track of the ultimate rootEl to render (we never\n // actually render anything but\n // the base component, even when people wrap a glamorous\n // component in glamorous\n comp: componentsComp,\n rootEl: rootEl || componentsComp,\n // join forwardProps (for anyone doing: glamorous(glamorous.a({}), {}))\n forwardProps: when(comp.forwardProps, forwardProps),\n // set the displayName to something that's slightly more\n // helpful than `GlamorousComponent` :)\n displayName: displayName || `glamorous(${getDisplayName(comp)})`,\n // these are props that should be applied to the component at render time\n propsToApply,\n }\n }\n}\n\n/**\n * reduces the propsToApply given to a single props object\n * @param {Array} propsToApply an array of propsToApply objects:\n * - object\n * - array of propsToApply items\n * - function that accepts the accumulated props and the context\n * @param {Object} accumulator an object to apply props onto\n * @param {Object} props the props that should ultimately take precedence\n * @param {*} context the context object\n * @return {Object} the reduced props\n */\nfunction getPropsToApply(propsToApply, accumulator, props, context) {\n // using forEach rather than reduce here because the reduce solution\n // effectively did the same thing because we manipulate the `accumulator`\n propsToApply.forEach(propsToApplyItem => {\n if (typeof propsToApplyItem === 'function') {\n return Object.assign(\n accumulator,\n propsToApplyItem(Object.assign({}, accumulator, props), context),\n )\n } else if (Array.isArray(propsToApplyItem)) {\n return Object.assign(\n accumulator,\n getPropsToApply(propsToApplyItem, accumulator, props, context),\n )\n }\n return Object.assign(accumulator, propsToApplyItem)\n })\n // props wins\n return Object.assign(accumulator, props)\n}\n\nfunction arrayify(x = []) {\n return Array.isArray(x) ? x : [x]\n}\n\nfunction when(comp, prop) {\n return comp ? comp.concat(prop) : prop\n}\n\nfunction getDisplayName(comp) {\n return typeof comp === 'string' ?\n comp :\n comp.displayName || comp.name || 'unknown'\n}\n","import React from 'react'\n\nlet PropTypes\n\n/* istanbul ignore next */\nif (parseFloat(React.version.slice(0, 4)) >= 15.5) {\n /* istanbul ignore next */\n try {\n PropTypes = require('prop-types')\n /* istanbul ignore next */\n } catch (error) {\n // ignore\n }\n}\n/* istanbul ignore next */\nPropTypes = PropTypes || React.PropTypes\n\nexport {PropTypes}\n\n/*\neslint\n import/no-mutable-exports:0,\n import/prefer-default-export:0,\n react/no-deprecated:0\n */\n","export const CHANNEL = '__glamorous__'\n","/* eslint no-unused-vars:0 */\nimport createGlamorous from './create-glamorous'\n\nfunction splitProps({\n css: cssProp,\n // these are plucked off\n theme, // because they\n className, // should never\n innerRef, // be forwarded\n glam, // to the lower\n // component ever\n ...rest\n}) {\n return {toForward: rest, cssProp}\n}\n\nconst glamorous = createGlamorous(splitProps)\n\nexport default glamorous\n"],"names":["withTheme","ComponentToTheme","noWarn","createElement","ThemedComponent","warned","state","theme","setTheme","_this","setState","this","context","CHANNEL","props","getState","nextProps","subscriptionId","subscribe","unsubscribe","React","call","Component","propTypes","PropTypes","object","defaultContextTypes","userDefinedContextTypes","defineProperty","value","extractGlamorStyles","className","glamorlessClassName","glamorStyles","toString","split","forEach","name","indexOf","style","buildGlamorSrcFromClassName","push","getGlamorClassName","styles","cssOverrides","cssProp","displayName","handleStyles","mappedArgs","nonGlamorClassNames","css","join","trim","current","i","length","result","Array","isArray","recursed","getPropsToApply","propsToApply","accumulator","propsToApplyItem","Object","assign","arrayify","x","when","comp","prop","concat","getDisplayName","parseFloat","version","slice","require","error","splitProps","glamorous","rootEl","shouldClassNameUpdate","forwardProps","propsAreCssOverrides","basePropsToApply","withProps","shouldUpdate","previous","update","GlamorousComponent","updateClassName","toForward","innerRef","string","func","getGlamorousComponentMetadata","newComp","options","componentsComp","createGlamorous","glam"],"mappings":"6PAWA,SAAwBA,EACtBC,uEACCC,OAAAA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