UNPKG

@icon-park/svg

Version:

Pure Svg Icons for IconPark

106 lines (94 loc) 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_ICON_CONFIGS = void 0; exports.IconConverter = IconConverter; exports.IconWrapper = IconWrapper; exports.getConfig = getConfig; exports.setConfig = setConfig; var DEFAULT_ICON_CONFIGS = { size: '1em', strokeWidth: 4, strokeLinecap: 'round', strokeLinejoin: 'round', theme: 'outline', colors: { outline: { fill: '#333', background: 'transparent' }, filled: { fill: '#333', background: '#FFF' }, twoTone: { fill: '#333', twoTone: '#2F88FF' }, multiColor: { outStrokeColor: '#333', outFillColor: '#2F88FF', innerStrokeColor: '#FFF', innerFillColor: '#43CCF8' } }, prefix: 'i' }; exports.DEFAULT_ICON_CONFIGS = DEFAULT_ICON_CONFIGS; function guid() { return 'icon-' + ((1 + Math.random()) * 0x100000000 | 0).toString(16).substring(1); } function IconConverter(id, icon, config) { var fill = typeof icon.fill === 'string' ? [icon.fill] : icon.fill || []; var colors = []; var theme = icon.theme || config.theme; switch (theme) { case 'outline': colors.push(typeof fill[0] === 'string' ? fill[0] : 'currentColor'); colors.push('none'); colors.push(typeof fill[0] === 'string' ? fill[0] : 'currentColor'); colors.push('none'); break; case 'filled': colors.push(typeof fill[0] === 'string' ? fill[0] : 'currentColor'); colors.push(typeof fill[0] === 'string' ? fill[0] : 'currentColor'); colors.push('#FFF'); colors.push('#FFF'); break; case 'two-tone': colors.push(typeof fill[0] === 'string' ? fill[0] : 'currentColor'); colors.push(typeof fill[1] === 'string' ? fill[1] : config.colors.twoTone.twoTone); colors.push(typeof fill[0] === 'string' ? fill[0] : 'currentColor'); colors.push(typeof fill[1] === 'string' ? fill[1] : config.colors.twoTone.twoTone); break; case 'multi-color': colors.push(typeof fill[0] === 'string' ? fill[0] : 'currentColor'); colors.push(typeof fill[1] === 'string' ? fill[1] : config.colors.multiColor.outFillColor); colors.push(typeof fill[2] === 'string' ? fill[2] : config.colors.multiColor.innerStrokeColor); colors.push(typeof fill[3] === 'string' ? fill[3] : config.colors.multiColor.innerFillColor); break; } return { size: icon.size || config.size, strokeWidth: icon.strokeWidth || config.strokeWidth, strokeLinecap: icon.strokeLinecap || config.strokeLinecap, strokeLinejoin: icon.strokeLinejoin || config.strokeLinejoin, colors: colors, id: id }; } var currentConfig = DEFAULT_ICON_CONFIGS; function setConfig(config) { currentConfig = config; } function getConfig() { return currentConfig; } function IconWrapper(name, render) { return function (props) { var config = getConfig(); var svgProps = IconConverter(guid(), props, config); return render(svgProps); }; }