{"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":["import 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\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","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, context) {\n const {mappedArgs, nonGlamorClassNames} = handleStyles(\n styles,\n props,\n theme,\n context,\n )\n const {\n mappedArgs: cssOverridesArgs,\n nonGlamorClassNames: cssOverridesClassNames,\n } = handleStyles([cssOverrides], props, theme, context)\n const {\n glamorStyles: parentGlamorStyles,\n glamorlessClassName,\n } = extractGlamorStyles(props.className)\n\n const glamorClassName = css(\n ...mappedArgs,\n ...parentGlamorStyles,\n ...cssOverridesArgs,\n ).toString()\n const extras = nonGlamorClassNames.concat(cssOverridesClassNames).join(' ')\n return `${glamorlessClassName} ${glamorClassName} ${extras}`.trim()\n}\n\nfunction handleStyles(styles, props, theme, 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, theme, context)\n if (typeof result === 'string') {\n processStringClass(result, mappedArgs, nonGlamorClassNames)\n } else {\n mappedArgs.push(result)\n }\n } else if (typeof current === 'string') {\n processStringClass(current, mappedArgs, nonGlamorClassNames)\n } else {\n mappedArgs.push(current)\n }\n }\n return {mappedArgs, nonGlamorClassNames}\n}\n\nfunction processStringClass(str, mappedArgs, nonGlamorClassNames) {\n const className = getGlamorStylesFromClassName(str)\n if (className) {\n mappedArgs.push(className)\n } else {\n nonGlamorClassNames.push(str)\n }\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 createGlamorous\n\nfunction createGlamorous(splitProps) {\n // TODO: in a breaking version, make this default to true\n glamorous.config = {useDisplayNameInClassName: false}\n\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(comp, {rootEl, displayName, forwardProps = []} = {}) {\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\n // create className to apply\n const fullClassName = getGlamorClassName(\n GlamorousComponent.styles,\n props,\n cssOverrides,\n theme,\n this.context,\n )\n const debugClassName = glamorous.config.useDisplayNameInClassName ?\n cleanClassname(GlamorousComponent.displayName) :\n ''\n const className = `${fullClassName} ${debugClassName}`.trim()\n\n return React.createElement(GlamorousComponent.comp, {\n ref: props.innerRef,\n ...toForward,\n className,\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 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(GlamorousComponent, '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 function withComponent(newComp, options = {}) {\n return glamorous(newComp, {\n forwardProps: GlamorousComponent.forwardProps,\n ...options,\n })(GlamorousComponent.styles)\n }\n\n Object.assign(\n GlamorousComponent,\n getGlamorousComponentMetadata({\n comp,\n styles,\n rootEl,\n forwardProps,\n displayName,\n }),\n {withComponent},\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\nfunction cleanClassname(className) {\n return className.replace(/ /g, '-').replace(/[^A-Za-z0-9\\-_]/g, '_')\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","context","handleStyles","mappedArgs","nonGlamorClassNames","cssOverridesArgs","cssOverridesClassNames","parentGlamorStyles","glamorClassName","css","extras","concat","join","current","i","length","result","processStringClass","str","id","styleSheet","registered","createGlamorous","splitProps","config","useDisplayNameInClassName","glamorous","comp","rootEl","displayName","forwardProps","glamorousComponentFactory","GlamorousComponent","state","setTheme","setState","getState","nextProps","unsubscribe","subscribe","toForward","Object","freeze","fullClassName","debugClassName","cleanClassname","createElement","innerRef","Component","propTypes","string","object","func","defaultContextTypes","userDefinedContextTypes","defineProperty","value","withComponent","newComp","options","assign","getGlamorousComponentMetadata","componentsComp","when","getDisplayName","prop","replace","glam","rest"],"mappings":";;;;;;;;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;;AAEA;;;;;;;;;ACjBO,IAAMM,UAAU,eAAhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACCP;;;;;;;;;;;AAWA,SAASC,mBAAT,GAA6C;MAAhBC,SAAgB,uEAAJ,EAAI;;SACpCA,UAAUC,QAAV,GAAqBC,KAArB,CAA2B,GAA3B,EAAgCC,MAAhC,CAAuC,UAACC,MAAD,EAASC,IAAT,EAAkB;QAC1DA,KAAKC,OAAL,C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