antd-omi-icons
Version:
Ant Design Icons for Omi
118 lines (117 loc) • 4.88 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var omi_1 = require("omi");
var omi_tools_1 = require("omi-tools");
require("./Icon");
var customCache = new Set();
function isValidCustomScriptUrl(scriptUrl) {
return !!(typeof scriptUrl === 'string' && scriptUrl.length && !customCache.has(scriptUrl));
}
function createScriptUrlElements(scriptUrls, index) {
if (index === void 0) { index = 0; }
var currentScriptUrl = scriptUrls[index];
if (isValidCustomScriptUrl(currentScriptUrl)) {
var script = document.createElement('script');
script.setAttribute('src', currentScriptUrl);
script.setAttribute('data-namespace', currentScriptUrl);
if (scriptUrls.length > index + 1) {
script.onload = function () {
createScriptUrlElements(scriptUrls, index + 1);
};
script.onerror = function () {
createScriptUrlElements(scriptUrls, index + 1);
};
}
customCache.add(currentScriptUrl);
document.body.appendChild(script);
}
}
function create(options) {
var _a;
if (options === void 0) { options = {}; }
var _b = options.scriptUrl, scriptUrl = _b === void 0 ? '' : _b, _c = options.extraCommonProps, extraCommonProps = _c === void 0 ? {} : _c;
/**
* 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 (typeof document !== 'undefined' &&
typeof window !== 'undefined' &&
typeof document.createElement === 'function') {
if (Array.isArray(scriptUrl)) {
// 因为iconfont资源会把svg插入before,所以前加载相同type会覆盖后加载,为了数组覆盖顺序,倒叙插入
createScriptUrlElements(scriptUrl.reverse());
}
else {
createScriptUrlElements([scriptUrl]);
}
}
return _a = /** @class */ (function (_super) {
__extends(Iconfont, _super);
function Iconfont() {
return _super !== null && _super.apply(this, arguments) || this;
}
Iconfont.prototype.render = function (props) {
var type = props.type, children = props.children, restProps = __rest(props, ["type", "children"]);
// children > type
var content = null;
if (type) {
content = (0, omi_1.h)("use", { xlinkHref: "#".concat(type) });
}
if (children && Array.isArray(children) && children.length) {
content = children;
}
var iconProps = __assign(__assign({}, extraCommonProps), (0, omi_tools_1.rmIEFP)(restProps));
return (0, omi_1.h)("o-icon", __assign({}, iconProps), content);
};
;
return Iconfont;
}(omi_1.Component)),
_a.propTypes = {
spin: Boolean,
rotate: Number,
type: String,
},
_a.inheritAttrs = false,
_a.displayName = 'Iconfont',
_a;
}
exports.default = create;