{"version":3,"file":"glamorous.umd.tiny.min.js","sources":["../src/get-glamor-classname.js","../src/create-glamorous.js","../src/tiny.js","../src/react-compat.js","../src/constants.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({\n styles,\n props,\n cssOverrides,\n cssProp,\n theme,\n context,\n}) {\n const {\n glamorStyles: parentGlamorStyles,\n glamorlessClassName,\n } = extractGlamorStyles(props.className)\n const {mappedArgs, nonGlamorClassNames} = handleStyles(\n [...styles, parentGlamorStyles, cssOverrides, cssProp],\n props,\n theme,\n context,\n )\n const glamorClassName = css(...mappedArgs).toString()\n const extras = [...nonGlamorClassNames, glamorlessClassName].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, 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 if (Array.isArray(current)) {\n const recursed = handleStyles(current, props, theme, 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\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, cssProp} = 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 styles: GlamorousComponent.styles,\n props,\n cssOverrides,\n cssProp,\n theme,\n context: 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: 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","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"],"names":["extractGlamorStyles","toString","split","reduce","groups","name","indexOf","style","getGlamorStylesFromClassName","glamorStyles","push","glamorlessClassName","trim","getGlamorClassName","styles","props","cssOverrides","cssProp","theme","context","className","parentGlamorStyles","handleStyles","mappedArgs","nonGlamorClassNames","css","join","current","i","length","result","Array","isArray","recursed","processStringClass","str","id","slice","styleSheet","registered","cleanClassname","replace","splitProps","innerRef","glam","toForward","PropTypes","React","version","require","error","CHANNEL","glamorous","comp","glamorousComponentFactory","withComponent","newComp","options","GlamorousComponent","forwardProps","state","setTheme","_this","setState","this","getState","nextProps","unsubscribe","subscribe","config","useDisplayNameInClassName","displayName","createElement","Component","propTypes","string","object","func","defaultContextTypes","userDefinedContextTypes","defineProperty","value","assign","getGlamorousComponentMetadata","rootEl","componentsComp","when","getDisplayName","prop","concat"],"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,SACPC,KAAAA,OACAC,IAAAA,MACAC,IAAAA,aACAC,IAAAA,QACAC,IAAAA,MACAC,IAAAA,UAKInB,EAAoBe,EAAMK,WAFdC,IAAdZ,aACAE,IAAAA,sBAEwCW,cACpCR,IAAQO,EAAoBL,EAAcC,IAC9CF,EACAG,EACAC,GAJKI,IAAAA,WAAYC,IAAAA,2BAMKC,qBAAOF,IAAYtB,2BACxBuB,IAAqBb,IAAqBe,KAAK,KAAKd,QACjCA,OAMxC,QAASU,GAAaR,EAAQC,EAAOG,EAAOC,OAIrC,GAHD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