{"version":3,"file":"glamorous.umd.tiny.js","sources":["../src/react-compat.js","../src/constants.js","../src/get-glamor-classname.js","../src/create-glamorous.js","../src/tiny.js"],"sourcesContent":["/* 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","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","/*\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","/* 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"],"names":["PropTypes","React","version","slice","require","error","CHANNEL","extractGlamorStyles","className","toString","split","reduce","groups","name","indexOf","style","getGlamorStylesFromClassName","glamorStyles","push","glamorlessClassName","trim","getGlamorClassName","styles","props","cssOverrides","theme","current","mappedArgs","nonGlamorClassNames","i","length","parentGlamorStyles","glamorClassName","css","extras","join","id","styleSheet","registered","createGlamorous","splitProps","glamorous","comp","rootEl","displayName","forwardProps","glamorousComponentFactory","GlamorousComponent","state","setTheme","setState","context","getState","nextProps","unsubscribe","subscribe","toForward","Object","freeze","fullClassName","createElement","innerRef","Component","propTypes","string","object","func","contextTypes","assign","getGlamorousComponentMetadata","componentsComp","when","getDisplayName","prop","concat","glam","rest"],"mappings":";;;;;;;;AAAA;AACA,AAEA,IAAIA,kBAAJ;;;AAGA,IAAIC,eAAMC,OAAN,CAAcC,KAAd,CAAoB,CAApB,EAAuB,CAAvB,MAA8B,MAAlC,EAA0C;;MAEpC;gBACUC,QAAQ,YAAR,CAAZ;;GADF,CAGE,OAAOC,KAAP,EAAc;;;;;AAKlBL,YAAYA,aAAaC,eAAMD,SAA/B,CAEA;;AClBO,IAAMM,UAAU,eAAhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACCP;;;;;;;;;;;AAWA,SAASC,mBAAT,GAA6C;MAAhBC,SAAgB,uEAAJ,EAAI;;SACpCA,UAAUC,QAAV,GAAqBC,KAArB,CAA2B,GAA3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