43a142dd3b5cce0be8962671b1fb070c.json
12.6 KB
{"ast":null,"code":"var _interopRequireWildcard=require(\"@babel/runtime/helpers/interopRequireWildcard\");var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.default=createMultiStyleIconSet;var _classCallCheck2=_interopRequireDefault(require(\"@babel/runtime/helpers/classCallCheck\"));var _createClass2=_interopRequireDefault(require(\"@babel/runtime/helpers/createClass\"));var _possibleConstructorReturn2=_interopRequireDefault(require(\"@babel/runtime/helpers/possibleConstructorReturn\"));var _getPrototypeOf2=_interopRequireDefault(require(\"@babel/runtime/helpers/getPrototypeOf\"));var _inherits2=_interopRequireDefault(require(\"@babel/runtime/helpers/inherits\"));var _defineProperty2=_interopRequireDefault(require(\"@babel/runtime/helpers/defineProperty\"));var _react=_interopRequireWildcard(require(\"react\"));var _propTypes=_interopRequireDefault(require(\"prop-types\"));var _createIconSet=_interopRequireDefault(require(\"./createIconSet\"));function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(source,true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(source).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}function createMultiStyleIconSet(styles){var optionsInput=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var styleNames=Object.keys(styles);if(styleNames.length===0){throw new Error('You need to add at least one style');}var options=_objectSpread({defaultStyle:styleNames[0],fallbackFamily:function fallbackFamily(_unused){return styleNames[0];},glyphValidator:function glyphValidator(_unused,__unused){return true;}},optionsInput);var iconSets=styleNames.reduce(function(acc,name){var style=styles[name];acc[name]=(0,_createIconSet.default)(style.glyphMap||{},style.fontFamily||'',style.fontFile||'',style.fontStyle||{});return acc;},{});function styleFromProps(props){return Object.keys(props).reduce(function(result,propName){return styleNames.indexOf(propName)!==-1&&props[propName]===true?propName:result;},options.defaultStyle);}function getIconSetForProps(props){var name=props.name;var style=styleFromProps(props);if(options.glyphValidator(name,style))return iconSets[style];var family=options.fallbackFamily(name);if(styleNames.indexOf(family)===-1){return options.defaultStyle;}return iconSets[family];}function selectIconClass(iconSet,iconClass){return iconClass.length>0?iconSet[iconClass]:iconSet;}function reduceProps(props){return Object.keys(props).reduce(function(acc,prop){if(styleNames.indexOf(prop)===-1){acc[prop]=props[prop];}return acc;},{});}function getStyledIconSet(style){var name=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'';if(styleNames.indexOf(style)===-1){return iconSets[options.defaultStyle];}return!name?iconSets[styleFromProps((0,_defineProperty2.default)({},style,true))]:getIconSetForProps((0,_defineProperty2.default)({name:name},style,true));}function getFontFamily(){var style=arguments.length>0&&arguments[0]!==undefined?arguments[0]:options.defaultStyle;return getStyledIconSet(style).getFontFamily();}function getRawGlyphMap(){var style=arguments.length>0&&arguments[0]!==undefined?arguments[0]:options.defaultStyle;return getStyledIconSet(style).getRawGlyphMap();}function hasIcon(name){var style=arguments.length>1&&arguments[1]!==undefined?arguments[1]:options.defaultStyle;return options.glyphValidator(name,style);}function createStyledIconClass(){var selectClass=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';var IconClass=function(_PureComponent){(0,_inherits2.default)(IconClass,_PureComponent);function IconClass(){(0,_classCallCheck2.default)(this,IconClass);return(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(IconClass).apply(this,arguments));}(0,_createClass2.default)(IconClass,[{key:\"render\",value:function render(){var selectedIconSet=getIconSetForProps(this.props);var SelectedIconClass=selectIconClass(selectedIconSet,selectClass);var props=reduceProps(this.props);return _react.default.createElement(SelectedIconClass,props);}}]);return IconClass;}(_react.PureComponent);IconClass.propTypes=styleNames.reduce(function(acc,name){acc[name]=_propTypes.default.bool;return acc;},{});IconClass.defaultProps=styleNames.reduce(function(acc,name){acc[name]=false;return acc;},{});IconClass.font=Object.values(styles).reduce(function(acc,style){acc[style.fontFamily]=style.fontFile;return acc;},{});IconClass.StyledIconSet=getStyledIconSet;IconClass.getFontFamily=getFontFamily;IconClass.getRawGlyphMap=getRawGlyphMap;IconClass.hasIcon=hasIcon;return IconClass;}var Icon=createStyledIconClass();Icon.Button=createStyledIconClass('Button');return Icon;}","map":{"version":3,"sources":["../src/createMultiStyleIconSet.ts"],"names":[],"mappings":"i0BAAA,qDACA,6DAEA,sE,yxBAac,QAAU,CAAA,uBAAV,CACZ,MADY,CAEK,IAAjB,CAAA,YAAiB,2DAAF,EAAE,CAEjB,GAAM,CAAA,UAAU,CAAG,MAAM,CAAC,IAAP,CAAY,MAAZ,CAAnB,CAEA,GAAI,UAAU,CAAC,MAAX,GAAsB,CAA1B,CAA6B,CAC3B,KAAM,IAAI,CAAA,KAAJ,CAAU,oCAAV,CAAN,CACD,CAED,GAAM,CAAA,OAAO,gBACX,YAAY,CAAE,UAAU,CAAC,CAAD,CADb,CAEX,cAAc,CAAE,wBAAC,OAAD,QAAkB,CAAA,UAAU,CAAC,CAAD,CAA5B,EAFL,CAGX,cAAc,CAAE,wBAAC,OAAD,CAAe,QAAf,QAAiC,KAAjC,EAHL,EAIR,YAJQ,CAAb,CAOA,GAAM,CAAA,QAAQ,CAAG,UAAU,CAAC,MAAX,CAAkB,SAAC,GAAD,CAAM,IAAN,CAAc,CAC/C,GAAM,CAAA,KAAK,CAAG,MAAM,CAAC,IAAD,CAApB,CAEA,GAAG,CAAC,IAAD,CAAH,CAAY,2BACV,KAAK,CAAC,QAAN,EAAkB,EADR,CAEV,KAAK,CAAC,UAAN,EAAoB,EAFV,CAGV,KAAK,CAAC,QAAN,EAAkB,EAH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GAAM,CAAA,KAAK,CAAG,WAAW,CAAC,KAAK,KAAN,CAAzB,CAEA,MAAO,gBAAM,aAAN,CAAoB,iBAApB,CAAuC,KAAvC,CAAP,CACD,CA9B0C,uBACrB,oBADqB,EAEpC,SAAA,CAAA,SAAA,CAAY,UAAU,CAAC,MAAX,CAAkB,SAAC,GAAD,CAAM,IAAN,CAAc,CACjD,GAAG,CAAC,IAAD,CAAH,CAAY,mBAAU,IAAtB,CACA,MAAO,CAAA,GAAP,CACD,CAHkB,CAGhB,EAHgB,CAAZ,CAKA,SAAA,CAAA,YAAA,CAAe,UAAU,CAAC,MAAX,CAAkB,SAAC,GAAD,CAAM,IAAN,CAAc,CACpD,GAAG,CAAC,IAAD,CAAH,CAAY,KAAZ,CACA,MAAO,CAAA,GAAP,CACD,CAHqB,CAGnB,EAHmB,CAAf,CAKA,SAAA,CAAA,IAAA,CAAO,MAAM,CAAC,MAAP,CAAc,MAAd,EAAsB,MAAtB,CAA6B,SAAC,GAAD,CAAM,KAAN,CAAe,CACxD,GAAG,CAAC,KAAK,CAAC,UAAP,CAAH,CAAwB,KAAK,CAAC,QAA9B,CACA,MAAO,CAAA,GAAP,CACD,CAHa,CAGX,EAHW,CAAP,CAOA,SAAA,CAAA,aAAA,CAAgB,gBAAhB,CACA,SAAA,CAAA,aAAA,CAAgB,aAAhB,CACA,SAAA,CAAA,cAAA,CAAiB,cAAjB,CACA,SAAA,CAAA,OAAA,CAAU,OAAV,CAWT,MAAO,CAAA,SAAP,CACD,CAED,GAAM,CAAA,IAAI,CAAG,qBAAqB,EAAlC,CACA,IAAI,CAAC,MAAL,CAAc,qBAAqB,CAAC,QAAD,CAAnC,CACA,MAAO,CAAA,IAAP,CACD","sourcesContent":["import React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\n\nimport createIconSet from './createIconSet';\n\ntype FontStyle = {\n fontFamily: string;\n fontFile: any;\n glyphMap: any;\n fontStyle: any;\n};\n\ntype FontStyles = {\n [key: string]: FontStyle;\n};\n\nexport default function createMultiStyleIconSet(\n styles: FontStyles,\n optionsInput = {}\n): any {\n const styleNames = Object.keys(styles);\n\n if (styleNames.length === 0) {\n throw new Error('You need to add at least one style');\n }\n\n const options = {\n defaultStyle: styleNames[0],\n fallbackFamily: (_unused: any) => styleNames[0],\n glyphValidator: (_unused: any, __unused: any) => true,\n ...optionsInput,\n };\n\n const iconSets = styleNames.reduce((acc, name) => {\n const style = styles[name];\n\n acc[name] = createIconSet(\n style.glyphMap || {},\n style.fontFamily || '',\n style.fontFile || '',\n style.fontStyle || {}\n );\n\n return acc;\n }, {});\n\n function styleFromProps(props) {\n return Object.keys(props).reduce(\n (result, propName) =>\n styleNames.indexOf(propName) !== -1 && props[propName] === true\n ? propName\n : result,\n options.defaultStyle\n );\n }\n\n function getIconSetForProps(props) {\n const { name } = props;\n const style = styleFromProps(props);\n\n if (options.glyphValidator(name, style)) return iconSets[style];\n\n const family = options.fallbackFamily(name);\n\n if (styleNames.indexOf(family) === -1) {\n return options.defaultStyle;\n }\n\n return iconSets[family];\n }\n\n function selectIconClass(iconSet, iconClass) {\n return iconClass.length > 0 ? iconSet[iconClass] : iconSet;\n }\n\n function reduceProps(props) {\n return Object.keys(props).reduce((acc, prop) => {\n if (styleNames.indexOf(prop) === -1) {\n acc[prop] = props[prop];\n }\n\n return acc;\n }, {});\n }\n\n function getStyledIconSet(style, name = '') {\n if (styleNames.indexOf(style) === -1) {\n return iconSets[options.defaultStyle];\n }\n\n return !name\n ? iconSets[styleFromProps({ [style]: true })]\n : getIconSetForProps({ name, [style]: true });\n }\n\n function getFontFamily(style = options.defaultStyle) {\n return getStyledIconSet(style).getFontFamily();\n }\n\n function getRawGlyphMap(style = options.defaultStyle) {\n return getStyledIconSet(style).getRawGlyphMap();\n }\n\n function hasIcon(name, style = options.defaultStyle) {\n return options.glyphValidator(name, style);\n }\n\n function createStyledIconClass(selectClass = '') {\n class IconClass extends PureComponent {\n static propTypes = styleNames.reduce((acc, name) => {\n acc[name] = PropTypes.bool;\n return acc;\n }, {});\n\n static defaultProps = styleNames.reduce((acc, name) => {\n acc[name] = false;\n return acc;\n }, {});\n\n static font = Object.values(styles).reduce((acc, style) => {\n acc[style.fontFamily] = style.fontFile;\n return acc;\n }, {});\n\n static Button: any;\n\n static StyledIconSet = getStyledIconSet;\n static getFontFamily = getFontFamily;\n static getRawGlyphMap = getRawGlyphMap;\n static hasIcon = hasIcon;\n\n render() {\n const selectedIconSet = getIconSetForProps(this.props);\n const SelectedIconClass = selectIconClass(selectedIconSet, selectClass);\n const props = reduceProps(this.props);\n\n return React.createElement(SelectedIconClass, props);\n }\n }\n\n return IconClass;\n }\n\n const Icon = createStyledIconClass();\n Icon.Button = createStyledIconClass('Button');\n return Icon;\n}\n"],"sourceRoot":""},"metadata":{},"sourceType":"script"}