107 lines
5.0 KiB
JavaScript
107 lines
5.0 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.generate = generate;
|
|
exports.getSecondaryColor = getSecondaryColor;
|
|
exports.iconStyles = void 0;
|
|
exports.isIconDefinition = isIconDefinition;
|
|
exports.normalizeAttrs = normalizeAttrs;
|
|
exports.normalizeTwoToneColors = normalizeTwoToneColors;
|
|
exports.useInsertStyles = exports.svgBaseProps = void 0;
|
|
exports.warning = warning;
|
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
var _colors = require("@ant-design/colors");
|
|
var _dynamicCSS = require("rc-util/lib/Dom/dynamicCSS");
|
|
var _shadow = require("rc-util/lib/Dom/shadow");
|
|
var _warning = _interopRequireDefault(require("rc-util/lib/warning"));
|
|
var _react = _interopRequireWildcard(require("react"));
|
|
var _Context = _interopRequireDefault(require("./components/Context"));
|
|
function camelCase(input) {
|
|
return input.replace(/-(.)/g, function (match, g) {
|
|
return g.toUpperCase();
|
|
});
|
|
}
|
|
function warning(valid, message) {
|
|
(0, _warning.default)(valid, "[@ant-design/icons] ".concat(message));
|
|
}
|
|
function isIconDefinition(target) {
|
|
return (0, _typeof2.default)(target) === 'object' && typeof target.name === 'string' && typeof target.theme === 'string' && ((0, _typeof2.default)(target.icon) === 'object' || typeof target.icon === 'function');
|
|
}
|
|
function normalizeAttrs() {
|
|
var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
return Object.keys(attrs).reduce(function (acc, key) {
|
|
var val = attrs[key];
|
|
switch (key) {
|
|
case 'class':
|
|
acc.className = val;
|
|
delete acc.class;
|
|
break;
|
|
default:
|
|
delete acc[key];
|
|
acc[camelCase(key)] = val;
|
|
}
|
|
return acc;
|
|
}, {});
|
|
}
|
|
function generate(node, key, rootProps) {
|
|
if (!rootProps) {
|
|
return /*#__PURE__*/_react.default.createElement(node.tag, (0, _objectSpread2.default)({
|
|
key: key
|
|
}, normalizeAttrs(node.attrs)), (node.children || []).map(function (child, index) {
|
|
return generate(child, "".concat(key, "-").concat(node.tag, "-").concat(index));
|
|
}));
|
|
}
|
|
return /*#__PURE__*/_react.default.createElement(node.tag, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
key: key
|
|
}, normalizeAttrs(node.attrs)), rootProps), (node.children || []).map(function (child, index) {
|
|
return generate(child, "".concat(key, "-").concat(node.tag, "-").concat(index));
|
|
}));
|
|
}
|
|
function getSecondaryColor(primaryColor) {
|
|
// choose the second color
|
|
return (0, _colors.generate)(primaryColor)[0];
|
|
}
|
|
function normalizeTwoToneColors(twoToneColor) {
|
|
if (!twoToneColor) {
|
|
return [];
|
|
}
|
|
return Array.isArray(twoToneColor) ? twoToneColor : [twoToneColor];
|
|
}
|
|
|
|
// These props make sure that the SVG behaviours like general text.
|
|
// Reference: https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4
|
|
var svgBaseProps = exports.svgBaseProps = {
|
|
width: '1em',
|
|
height: '1em',
|
|
fill: 'currentColor',
|
|
'aria-hidden': 'true',
|
|
focusable: 'false'
|
|
};
|
|
var iconStyles = exports.iconStyles = "\n.anticon {\n display: inline-flex;\n align-items: center;\n color: inherit;\n font-style: normal;\n line-height: 0;\n text-align: center;\n text-transform: none;\n vertical-align: -0.125em;\n text-rendering: optimizeLegibility;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\n.anticon > * {\n line-height: 1;\n}\n\n.anticon svg {\n display: inline-block;\n}\n\n.anticon::before {\n display: none;\n}\n\n.anticon .anticon-icon {\n display: block;\n}\n\n.anticon[tabindex] {\n cursor: pointer;\n}\n\n.anticon-spin::before,\n.anticon-spin {\n display: inline-block;\n -webkit-animation: loadingCircle 1s infinite linear;\n animation: loadingCircle 1s infinite linear;\n}\n\n@-webkit-keyframes loadingCircle {\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n}\n\n@keyframes loadingCircle {\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg);\n }\n}\n";
|
|
var useInsertStyles = exports.useInsertStyles = function useInsertStyles(eleRef) {
|
|
var _useContext = (0, _react.useContext)(_Context.default),
|
|
csp = _useContext.csp,
|
|
prefixCls = _useContext.prefixCls,
|
|
layer = _useContext.layer;
|
|
var mergedStyleStr = iconStyles;
|
|
if (prefixCls) {
|
|
mergedStyleStr = mergedStyleStr.replace(/anticon/g, prefixCls);
|
|
}
|
|
if (layer) {
|
|
mergedStyleStr = "@layer ".concat(layer, " {\n").concat(mergedStyleStr, "\n}");
|
|
}
|
|
(0, _react.useEffect)(function () {
|
|
var ele = eleRef.current;
|
|
var shadowRoot = (0, _shadow.getShadowRoot)(ele);
|
|
(0, _dynamicCSS.updateCSS)(mergedStyleStr, '@ant-design-icons', {
|
|
prepend: !layer,
|
|
csp: csp,
|
|
attachTo: shadowRoot
|
|
});
|
|
}, []);
|
|
}; |