@ly-js/ui
Version:
`@ly-js/ui` 是基于`vue3`常用库,会在`@ly-js/element`、`@ly-js/vant`中引入
59 lines (56 loc) • 1.76 kB
JavaScript
import { defineComponent, createVNode } from 'vue';
import { createNamespace } from '../../../utils/create.mjs';
const customCache = /* @__PURE__ */ new Set();
function isValidCustomScriptUrl(scriptUrl) {
return !!(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);
}
}
const loadIconScripts = (scriptUrl) => {
if (typeof document !== "undefined" && typeof window !== "undefined" && typeof document.createElement === "function") {
if (Array.isArray(scriptUrl)) {
createScriptUrlElements(scriptUrl.reverse());
} else {
createScriptUrlElements([scriptUrl]);
}
} else {
console.warn("[ly-icon] loadIconScripts faild");
}
};
const [name] = createNamespace("icon");
const iconProps = {
type: {
type: String,
require: true,
default: ""
}
};
var _Icon = defineComponent({
name,
props: iconProps,
setup(props) {
return () => createVNode("svg", {
"class": "ly-icon",
"aria-hidden": "true"
}, [createVNode("use", {
"xlink:href": `#${props.type}`
}, null)]);
}
});
export { _Icon as default, loadIconScripts };