{"version":3,"file":"glamorous.umd.tiny.min.js","sources":["../src/get-glamor-classname.js","../src/tiny.js","../src/react-compat.js","../src/constants.js","../src/create-glamorous.js"],"sourcesContent":["import {css, styleSheet} 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 return className.toString().split(' ').reduce((groups, name) => {\n if (name.indexOf('css-') === 0) {\n const style = getGlamorStylesFromClassName(name)\n groups.glamorStyles.push(style)\n } else {\n // eslint-disable-next-line max-len\n groups.glamorlessClassName = `${groups.glamorlessClassName} ${name}`.trim()\n }\n return groups\n }, {glamorlessClassName: '', glamorStyles: []})\n}\n\nexport default getGlamorClassName\n\nfunction getGlamorClassName(styles, props, cssOverrides, theme) {\n let className, 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 mappedArgs.push(current(props, theme))\n } else if (typeof current === 'string') {\n className = getGlamorStylesFromClassName(current)\n if (className) {\n mappedArgs.push(className)\n } else {\n nonGlamorClassNames.push(current)\n }\n } else {\n mappedArgs.push(current)\n }\n }\n const {\n glamorStyles: parentGlamorStyles,\n glamorlessClassName,\n } = extractGlamorStyles(props.className)\n const glamorClassName = css(\n ...mappedArgs,\n ...parentGlamorStyles,\n cssOverrides,\n ).toString()\n const extras = nonGlamorClassNames.join(' ')\n return `${glamorlessClassName} ${glamorClassName} ${extras}`.trim()\n}\n\nfunction getGlamorStylesFromClassName(className) {\n const id = className.slice('css-'.length)\n if (styleSheet.registered[id]) {\n return styleSheet.registered[id].style\n } else {\n return null\n }\n}\n","/* eslint no-unused-vars:0 */\nimport createGlamorous from './create-glamorous'\n\nfunction splitProps({\n css: cssOverrides = {},\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, cssOverrides}\n}\n\nconst glamorous = createGlamorous(splitProps)\n\nexport default glamorous\n","/* eslint import/no-mutable-exports:0, import/prefer-default-export:0 */\nimport React from 'react'\n\nlet PropTypes\n\n/* istanbul ignore next */\nif (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","export const CHANNEL = '__glamorous__'\n","/*\n * This is a relatively small abstraction that's ripe for open sourcing.\n * Documentation is in the README.md\n */\nimport React, {Component} from 'react'\nimport {PropTypes} from './react-compat'\nimport {CHANNEL} from './constants'\nimport getGlamorClassName from './get-glamor-classname'\n\nexport default function createGlamorous(splitProps) {\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 return function glamorous(\n comp,\n {rootEl, displayName, forwardProps = []} = {},\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 * @param {Object} theme the theme object\n * @return {ReactElement} React.createElement\n */\n class GlamorousComponent extends Component {\n state = {theme: null}\n setTheme = theme => this.setState({theme})\n\n componentWillMount() {\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.unsubscribe = this.context[CHANNEL].subscribe(this.setTheme)\n }\n }\n\n componentWillUnmount() {\n // cleanup subscription\n this.unsubscribe && this.unsubscribe()\n }\n\n render() {\n // in this function, we're willing to sacrafice a little on\n // readability to get better performance because it actually\n // matters.\n const props = this.props\n const {toForward, cssOverrides} = splitProps(\n props,\n GlamorousComponent,\n )\n\n // freeze the theme object in dev mode\n const theme = process.env.NODE_ENV === 'production' ?\n this.state.theme :\n Object.freeze(this.state.theme)\n // create className to apply\n const fullClassName = getGlamorClassName(\n GlamorousComponent.styles,\n props,\n cssOverrides,\n theme,\n )\n\n return React.createElement(GlamorousComponent.comp, {\n ref: props.innerRef,\n ...toForward,\n className: fullClassName,\n })\n }\n }\n\n GlamorousComponent.propTypes = {\n className: PropTypes.string,\n cssOverrides: PropTypes.object,\n theme: PropTypes.object,\n innerRef: PropTypes.func,\n glam: PropTypes.object,\n }\n\n GlamorousComponent.contextTypes = {\n [CHANNEL]: PropTypes.object,\n }\n\n Object.assign(\n GlamorousComponent,\n getGlamorousComponentMetadata({\n comp,\n styles,\n rootEl,\n forwardProps,\n displayName,\n }),\n )\n return GlamorousComponent\n }\n }\n\n function getGlamorousComponentMetadata({\n comp,\n styles,\n rootEl,\n forwardProps,\n displayName,\n }) {\n const componentsComp = comp.comp ? comp.comp : comp\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 }\n }\n\n function when(comp, prop) {\n return comp ? comp.concat(prop) : prop\n }\n\n function getDisplayName(comp) {\n return typeof comp === 'string' ?\n comp :\n comp.displayName || comp.name || 'unknown'\n }\n}\n"],"names":["extractGlamorStyles","toString","split","reduce","groups","name","indexOf","style","getGlamorStylesFromClassName","glamorStyles","push","glamorlessClassName","trim","getGlamorClassName","styles","props","cssOverrides","theme","className","current","mappedArgs","nonGlamorClassNames","i","length","parentGlamorStyles","css","join","id","slice","styleSheet","registered","splitProps","innerRef","glam","toForward","PropTypes","React","version","require","error","CHANNEL","getGlamorousComponentMetadata","comp","rootEl","forwardProps","displayName","componentsComp","when","getDisplayName","prop","concat","glamorousComponentFactory","GlamorousComponent","state","setTheme","_this","setState","this","context","getState","nextProps","unsubscribe","subscribe","fullClassName","createElement","Component","propTypes","string","object","func","contextTypes","assign"],"mappings":"4PAYA,SAASA,mEAAgC,IACtBC,WAAWC,MAAM,KAAKC,OAAO,SAACC,EAAQC,MACxB,IAAzBA,EAAKC,QAAQ,QAAe,IACxBC,GAAQC,EAA6BH,KACpCI,aAAaC,KAAKH,UAGlBI,qBAAyBP,EAAOO,wBAAuBN,GAAOO,aAEhER,KACLO,oBAAqB,GAAIF,kBAG/B,QAESI,GAAmBC,EAAQC,EAAOC,EAAcC,OAIlD,GAHDC,UAAWC,SACTC,KACAC,KACGC,EAAI,EAAGA,EAAIR,EAAOS,OAAQD,MACvBR,EAAOQ,GACM,kBAAZH,KACET,KAAKS,EAAQJ,EAAOE,IACH,gBAAZE,MACJX,EAA6BW,GACrCD,IACSR,KAAKQ,KAEIR,KAAKS,MAGhBT,KAAKS,SAMhBnB,EAAoBe,EAAMG,WAFdM,IAAdf,sBACAE,wBAEsBc,mBACnBL,WACAI,IACHR,KACAf,eACaoB,EAAoBK,KAAK,MACqBd,O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