utils.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import _extends from 'babel-runtime/helpers/extends';
  2. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  3. import _createClass from 'babel-runtime/helpers/createClass';
  4. import { generate as generateColor } from '@ant-design/colors';
  5. export function log(message) {
  6. if (!(process && process.env && process.env.NODE_ENV === 'production')) {
  7. console.error('[@ant-design/icons-vue]: ' + message + '.');
  8. }
  9. }
  10. export function isIconDefinition(target) {
  11. return typeof target === 'object' && typeof target.name === 'string' && typeof target.theme === 'string' && (typeof target.icon === 'object' || typeof target.icon === 'function');
  12. }
  13. export function normalizeAttrs() {
  14. var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15. return Object.keys(attrs).reduce(function (acc, key) {
  16. var val = attrs[key];
  17. switch (key) {
  18. case 'class':
  19. acc.className = val;
  20. delete acc['class'];
  21. break;
  22. default:
  23. acc[key] = val;
  24. }
  25. return acc;
  26. }, {});
  27. }
  28. export var MiniMap = function () {
  29. function MiniMap() {
  30. _classCallCheck(this, MiniMap);
  31. this.collection = {};
  32. }
  33. _createClass(MiniMap, [{
  34. key: 'clear',
  35. value: function clear() {
  36. this.collection = {};
  37. }
  38. }, {
  39. key: 'delete',
  40. value: function _delete(key) {
  41. return delete this.collection[key];
  42. }
  43. }, {
  44. key: 'get',
  45. value: function get(key) {
  46. return this.collection[key];
  47. }
  48. }, {
  49. key: 'has',
  50. value: function has(key) {
  51. return Boolean(this.collection[key]);
  52. }
  53. }, {
  54. key: 'set',
  55. value: function set(key, value) {
  56. this.collection[key] = value;
  57. return this;
  58. }
  59. }, {
  60. key: 'size',
  61. get: function get() {
  62. return Object.keys(this.collection).length;
  63. }
  64. }]);
  65. return MiniMap;
  66. }();
  67. export function generate(h, node, key, rootProps) {
  68. if (!rootProps) {
  69. return h(node.tag, { key: key, attrs: _extends({}, normalizeAttrs(node.attrs)) }, (node.children || []).map(function (child, index) {
  70. return generate(h, child, key + '-' + node.tag + '-' + index);
  71. }));
  72. }
  73. return h(node.tag, _extends({
  74. key: key
  75. }, rootProps, {
  76. attrs: _extends({}, normalizeAttrs(node.attrs), rootProps.attrs)
  77. }), (node.children || []).map(function (child, index) {
  78. return generate(h, child, key + '-' + node.tag + '-' + index);
  79. }));
  80. }
  81. export function getSecondaryColor(primaryColor) {
  82. // choose the second color
  83. return generateColor(primaryColor)[0];
  84. }
  85. export function withSuffix(name, theme) {
  86. switch (theme) {
  87. case 'fill':
  88. return name + '-fill';
  89. case 'outline':
  90. return name + '-o';
  91. case 'twotone':
  92. return name + '-twotone';
  93. default:
  94. throw new TypeError('Unknown theme type: ' + theme + ', name: ' + name);
  95. }
  96. }