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CAAC,CAAC;;AAEtD,uBAAe,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC/C;;;;;;;;AAAA,AAQD,YAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;;AAElC,QAAI,gBAAM,cAAc,CAAC,QAAQ,CAAC,EAAE;AAChC,mBAAW,GAAG,SAAS,CAAC,gBAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;KACjF,MAAM,IAAI,uBAAU,QAAQ,CAAC,IAAI,0BAAW,QAAQ,CAAC,EAAE;;AAEpD,mBAAW,GAAG,gBAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAC,IAAI,EAAK;;AAEjD,gBAAI,gBAAM,cAAc,CAAC,IAAI,CAAC,EAAE;AAC5B,uBAAO,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;aACjD,MAAM;AACH,uBAAO,IAAI,CAAC;aACf;SACJ,CAAC;;;;;;AAAC,KAMN;;AAED,QAAI,eAAe,EAAE;AACjB,YAAI,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE;AACzB,2BAAe,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,GAAG,eAAe,CAAC;SACrE;;AAED,gBAAQ,GAAG;AACP,qBAAS,EAAE,eAAe;SAC7B,CAAC;KACL;;AAED,QAAI,WAAW,EAAE;AACb,qBAAa,GAAG,gBAAM,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;KACtE,MAAM;AACH,qBAAa,GAAG,gBAAM,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;KACzD;;AAED,WAAO,aAAa,CAAC;CACxB,CAAC;;kBAEa,SAAS","file":"linkClass.js","sourcesContent":["import React from 'react';\nimport makeConfiguration from './makeConfiguration';\nimport isIterable from './isIterable';\nimport _ from 'lodash';\n\nlet linkClass;\n\n/**\n * @param {ReactElement} element\n * @param {Object} styles CSS modules class map.\n * @param {CSSModules~Options} userConfiguration\n * @return {ReactElement}\n */\nlinkClass = (element, styles = {}, userConfiguration) => {\n let appendClassName,\n children,\n clonedElement,\n configuration,\n newChildren,\n newProps,\n styleNames;\n\n // @see https://github.com/gajus/react-css-modules/pull/30\n if (!element) {\n return element;\n }\n\n configuration = makeConfiguration(userConfiguration);\n\n styleNames = element.props.styleName;\n\n if (styleNames) {\n styleNames = styleNames.split(' ');\n styleNames = _.filter(styleNames);\n\n if (configuration.allowMultiple === false && styleNames.length > 1) {\n throw new Error('ReactElement styleName property defines multiple module names (\"' + element.props.styleName + '\").');\n }\n\n appendClassName = _.map(styleNames, (styleName) => {\n if (styles[styleName]) {\n return styles[styleName];\n } else {\n if (configuration.errorWhenNotFound === true) {\n throw new Error('\"' + styleName + '\" CSS module is undefined.');\n }\n\n return '';\n }\n });\n\n appendClassName = _.filter(appendClassName, 'length');\n\n appendClassName = appendClassName.join(' ');\n }\n\n // element.props.children can be one of the following:\n // 'text'\n // ['text']\n // [ReactElement, 'text']\n // ReactElement\n\n children = element.props.children;\n\n if (React.isValidElement(children)) {\n newChildren = linkClass(React.Children.only(children), styles, configuration);\n } else if (_.isArray(children) || isIterable(children)) {\n /* eslint-disable lodash3/prefer-lodash-method */\n newChildren = React.Children.map(children, (node) => {\n /* eslint-enable lodash3/prefer-lodash-method */\n if (React.isValidElement(node)) {\n return linkClass(node, styles, configuration);\n } else {\n return node;\n }\n });\n\n // https://github.com/facebook/react/issues/4723#issuecomment-135555277\n // Forcing children into an array produces the following error:\n // Warning: A ReactFragment is an opaque type. Accessing any of its properties is deprecated. Pass it to one of the React.Children helpers.\n // newChildren = _.values(newChildren);\n }\n\n if (appendClassName) {\n if (element.props.className) {\n appendClassName = element.props.className + ' ' + appendClassName;\n }\n\n newProps = {\n className: appendClassName\n };\n }\n\n if (newChildren) {\n clonedElement = React.cloneElement(element, newProps, newChildren);\n } else {\n clonedElement = React.cloneElement(element, newProps);\n }\n\n return clonedElement;\n};\n\nexport default linkClass;\n"],"sourceRoot":"/source/"}
\No newline at end of file