utils.js 3.4 KB

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