{"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 id = name.slice('css-'.length)\n const {style} = styleSheet.registered[id]\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 const mappedArgs = styles.slice()\n for (let i = mappedArgs.length; i--;) {\n if (typeof mappedArgs[i] === 'function') {\n mappedArgs[i] = mappedArgs[i](props, theme)\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 return `${glamorlessClassName} ${glamorClassName}`.trim()\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: comp.styles ? comp.styles.concat(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 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 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","id","slice","length","style","styleSheet","registered","glamorStyles","push","glamorlessClassName","trim","getGlamorClassName","styles","props","cssOverrides","theme","mappedArgs","i","className","parentGlamorStyles","css","splitProps","innerRef","glam","toForward","PropTypes","React","version","require","error","CHANNEL","getGlamorousComponentMetadata","comp","rootEl","forwardProps","displayName","componentsComp","concat","getDisplayName","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,GAAKF,EAAKG,MAAM,OAAOC,QACtBC,EAASC,aAAWC,WAAWL,GAA/BG,QACAG,aAAaC,KAAKJ,UAGlBK,qBAAyBX,EAAOW,wBAAuBV,GAAOW,aAEhEZ,KACLW,oBAAqB,GAAIF,kBAG/B,QAESI,GAAmBC,EAAQC,EAAOC,EAAcC,OAElD,GADCC,GAAaJ,EAAOV,QACjBe,EAAID,EAAWb,OAAQc,KACD,kBAAlBD,GAAWC,OACTA,GAAKD,EAAWC,GAAGJ,EAAOE,UAMrCrB,EAAoBmB,EAAMK,WAFdC,IAAdZ,sBACAE,wBAEsBW,qBACnBJ,YACAG,IACHL,KACAnB,YACiDe,OC3CrD,QAESW,cACPD,IAAKN,oBAELC,QACAG,YACAI,WACAC,YAIQC,6DAAiBV,gDCVvBW,QAGJ,IAAkC,SAA9BC,EAAMC,QAAQzB,MAAM,EAAG,SAGX0B,QAAQ,cAEpB,MAAOC,IAKXJ,EAAYA,GAAaC,EAAMD,SChBxB,IAAMK,GAAU,01CCIvB,UAKwCT,WA2H7BU,SACPC,KAAAA,KACApB,IAAAA,OACAqB,IAAAA,OACAC,IAAAA,aACAC,IAAAA,YAEMC,EAAiBJ,EAAKA,KAAOA,EAAKA,KAAOA,gBAGrCA,EAAKpB,OAASoB,EAAKpB,OAAOyB,OAAOzB,GAAUA,OAK7CwB,SACEH,GAAUG,6BAILD,gBAA4BG,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