UNPKG

@ly-js/ui

Version:

`@ly-js/ui` 是基于`vue3`常用库,会在`@ly-js/element`、`@ly-js/vant`中引入

64 lines (59 loc) 1.85 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var create = require('../../../utils/create.js'); 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] = create.createNamespace("icon"); const iconProps = { type: { type: String, require: true, default: "" } }; var _Icon = vue.defineComponent({ name, props: iconProps, setup(props) { return () => vue.createVNode("svg", { "class": "ly-icon", "aria-hidden": "true" }, [vue.createVNode("use", { "xlink:href": `#${props.type}` }, null)]); } }); exports["default"] = _Icon; exports.loadIconScripts = loadIconScripts;