unis_crm/frontend1/node_modules/@ant-design/icons/es/components/IconFont.js

69 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import * as React from 'react';
import Icon from "./Icon";
const customCache = new Set();
function isValidCustomScriptUrl(scriptUrl) {
return Boolean(typeof scriptUrl === 'string' && scriptUrl.length && !customCache.has(scriptUrl));
}
function createScriptUrlElements(scriptUrls, index = 0) {
const currentScriptUrl = scriptUrls[index];
if (isValidCustomScriptUrl(currentScriptUrl)) {
const script = document.createElement('script');
script.setAttribute('src', currentScriptUrl);
script.setAttribute('data-namespace', currentScriptUrl);
if (scriptUrls.length > index + 1) {
script.onload = () => {
createScriptUrlElements(scriptUrls, index + 1);
};
script.onerror = () => {
createScriptUrlElements(scriptUrls, index + 1);
};
}
customCache.add(currentScriptUrl);
document.body.appendChild(script);
}
}
export default function create(options = {}) {
const {
scriptUrl,
extraCommonProps = {}
} = options;
/**
* DOM API required.
* Make sure in browser environment.
* The Custom Icon will create a <script/>
* that loads SVG symbols and insert the SVG Element into the document body.
*/
if (scriptUrl && typeof document !== 'undefined' && typeof window !== 'undefined' && typeof document.createElement === 'function') {
if (Array.isArray(scriptUrl)) {
// 因为iconfont资源会把svg插入before所以前加载相同type会覆盖后加载为了数组覆盖顺序倒叙插入
createScriptUrlElements(scriptUrl.reverse());
} else {
createScriptUrlElements([scriptUrl]);
}
}
const Iconfont = /*#__PURE__*/React.forwardRef((props, ref) => {
const {
type,
children,
...restProps
} = props;
// children > type
let content = null;
if (props.type) {
content = /*#__PURE__*/React.createElement("use", {
xlinkHref: `#${type}`
});
}
if (children) {
content = children;
}
return /*#__PURE__*/React.createElement(Icon, _extends({}, extraCommonProps, restProps, {
ref: ref
}), content);
});
Iconfont.displayName = 'Iconfont';
return Iconfont;
}