UNPKG

cc-ui-plus

Version:

433 lines (431 loc) 11.6 kB
import { defineComponent as C, provide as D, renderSlot as v, inject as O, computed as m, onBeforeMount as W, h as K, openBlock as p, createBlock as $, unref as d, withCtx as _, createElementBlock as T, normalizeClass as U, withModifiers as V, resolveDynamicComponent as Z, createCommentVNode as k, normalizeStyle as F } from "vue"; function j(n, e) { return n.install = (t) => { t.component(e, n); }, n; } function y(n, e, t) { let r = n; return e && (r += `__${e}`), t && (r += `--${t}`), r; } function G(n) { const e = `cc-${n}`; return { b: () => y(e), e: (o) => o ? y(e, o) : "", m: (o) => o ? y(e, "", o) : "", em: (o, s) => o && s ? y(e, o, s) : "" }; } const H = (n, e) => { if (e.value === "") return ""; if (e.value === "small") return n.m("small"); if (e.value === "large") return n.m("large"); }, J = (n, e) => { if (e.value === "") return n.m("default"); if (e.value === "primary") return n.m("primary"); if (e.value === "success") return n.m("success"); if (e.value === "warning") return n.m("warning"); if (e.value === "danger") return n.m("danger"); if (e.value === "info") return n.m("info"); }; function Q(n) { let e = 0; for (let t = 0; t < n.length; ++t) n[t] === "&" && ++e; return e; } const R = /\s*,(?![^(]*\))\s*/g, X = /\s+/g; function Y(n, e) { const t = []; return e.split(R).forEach((r) => { let u = Q(r); if (u) { if (u === 1) { n.forEach((o) => { t.push(r.replace("&", o)); }); return; } } else { n.forEach((o) => { t.push( (o && o + " ") + r ); }); return; } let i = [ r ]; for (; u--; ) { const o = []; i.forEach((s) => { n.forEach((l) => { o.push(s.replace("&", l)); }); }), i = o; } i.forEach((o) => t.push(o)); }), t; } function ee(n, e) { const t = []; return e.split(R).forEach((r) => { n.forEach((u) => { t.push((u && u + " ") + r); }); }), t; } function ne(n) { let e = [""]; return n.forEach((t) => { t = t && t.trim(), t && (t.includes("&") ? e = Y(e, t) : e = ee(e, t)); }), e.join(", ").replace(X, " "); } const te = /[A-Z]/g; function I(n) { return n.replace(te, (e) => "-" + e.toLowerCase()); } function re(n, e = " ") { return typeof n == "object" && n !== null ? ` { ` + Object.entries(n).map((t) => e + ` ${I(t[0])}: ${t[1]};`).join(` `) + ` ` + e + "}" : `: ${n};`; } function oe(n, e, t) { return typeof n == "function" ? n({ context: e.context, props: t }) : n; } function z(n, e, t, r) { if (!e) return ""; const u = oe(e, t, r); if (!u) return ""; if (typeof u == "string") return `${n} { ${u} }`; const i = Object.keys(u); if (i.length === 0) return t.config.keepEmptyBlock ? n + ` { }` : ""; const o = n ? [ n + " {" ] : []; return i.forEach((s) => { const l = u[s]; if (s === "raw") { o.push(` ` + l + ` `); return; } s = I(s), l != null && o.push(` ${s}${re(l)}`); }), n && o.push("}"), o.join(` `); } function E(n, e, t) { !n || n.forEach((r) => { if (Array.isArray(r)) E(r, e, t); else if (typeof r == "function") { const u = r(e); Array.isArray(u) ? E(u, e, t) : u && t(u); } else r && t(r); }); } function N(n, e, t, r, u, i) { const o = n.$; !o || typeof o == "string" ? e.push(o) : typeof o == "function" ? e.push(o({ context: r.context, props: u })) : (o.before && o.before(r.context), !o.$ || typeof o.$ == "string" ? e.push(o.$) : o.$ && e.push(o.$({ context: r.context, props: u }))); const s = ne(e), l = z(s, n.props, r, u); i && l && i.insertRule(l), !i && l.length && t.push(l), n.children && E(n.children, { context: r.context, props: u }, (f) => { if (typeof f == "string") { const g = z(s, { raw: f }, r, u); i ? i.insertRule(g) : t.push(g); } else N(f, e, t, r, u, i); }), e.pop(), o && o.after && o.after(r.context); } function q(n, e, t, r = !1) { const u = []; return N(n, [], u, e, t, r ? n.instance.__styleSheet : void 0), r ? "" : u.join(` `); } function ue(n) { for (var e = 0, t, r = 0, u = n.length; u >= 4; ++r, u -= 4) t = n.charCodeAt(r) & 255 | (n.charCodeAt(++r) & 255) << 8 | (n.charCodeAt(++r) & 255) << 16 | (n.charCodeAt(++r) & 255) << 24, t = (t & 65535) * 1540483477 + ((t >>> 16) * 59797 << 16), t ^= t >>> 24, e = (t & 65535) * 1540483477 + ((t >>> 16) * 59797 << 16) ^ (e & 65535) * 1540483477 + ((e >>> 16) * 59797 << 16); switch (u) { case 3: e ^= (n.charCodeAt(r + 2) & 255) << 16; case 2: e ^= (n.charCodeAt(r + 1) & 255) << 8; case 1: e ^= n.charCodeAt(r) & 255, e = (e & 65535) * 1540483477 + ((e >>> 16) * 59797 << 16); } return e ^= e >>> 13, e = (e & 65535) * 1540483477 + ((e >>> 16) * 59797 << 16), ((e ^ e >>> 15) >>> 0).toString(36); } function b(n) { if (!n) return; const e = n.parentElement; e && e.removeChild(n); } function S(n) { return document.querySelector(`style[cssr-id="${n}"]`); } function ie(n) { const e = document.createElement("style"); return e.setAttribute("cssr-id", n), e; } window && (window.__cssrContext = {}); function L(n) { const e = n.getAttribute("mount-count"); return e === null ? null : Number(e); } function A(n, e) { n.setAttribute("mount-count", String(e)); } function B(n, e, t, r) { const { els: u } = e; if (t === void 0) u.forEach(b), e.els = []; else { const i = S(t); if (i && u.includes(i)) { const o = L(i); r ? o === null ? console.error(`[css-render/unmount]: The style with target='${t}' is mounted in count mode.`) : o <= 1 ? (b(i), e.els = u.filter((s) => s !== i)) : A(i, o - 1) : o !== null ? console.error(`[css-render/unmount]: The style with target='${t}' is mounted in no-count mode.`) : (b(i), e.els = u.filter((s) => s !== i)); } } } function se(n, e) { n.push(e); } function le(n, e, t, r, u, i, o, s, l) { if (o && !l) { if (t === void 0) { console.error("[css-render/mount]: `id` is required in `boost` mode."); return; } const h = window.__cssrContext; h[t] || (h[t] = !0, q(e, n, r, o)); return; } let f; const { els: g } = e; let c; if (t === void 0 && (c = e.render(r), t = ue(c)), l) { l(t, c != null ? c : e.render(r)); return; } const a = S(t); if (s || a === null) { if (f = a === null ? ie(t) : a, c === void 0 && (c = e.render(r)), f.textContent = c, a !== null) return; if (u) { const h = document.head.getElementsByTagName("style")[0] || null; document.head.insertBefore(f, h); } else document.head.appendChild(f); i && A(f, 1), se(g, f); } else { const h = L(a); i ? h === null ? console.error(`[css-render/mount]: The style with id='${t}' has been mounted in no-count mode.`) : A(a, h + 1) : h !== null && console.error(`[css-render/mount]: The style with id='${t}' has been mounted in count mode.`); } return a != null ? a : f; } function fe(n) { return q(this, this.instance, n); } function ce(n = {}) { const { target: e, id: t, ssr: r, props: u, count: i = !1, head: o = !1, boost: s = !1, force: l = !1 } = n; return le(this.instance, this, t != null ? t : e, u, o, i, s, l, r); } function ae(n = {}) { const { id: e, target: t, delay: r = 0, count: u = !1 } = n; r === 0 ? B(this.instance, this, e != null ? e : t, u) : setTimeout(() => B(this.instance, this, e != null ? e : t, u), r); } const x = function(n, e, t, r) { return { instance: n, $: e, props: t, children: r, els: [], render: fe, mount: ce, unmount: ae }; }, de = function(n, e, t, r) { return Array.isArray(e) ? x(n, { $: null }, null, e) : Array.isArray(t) ? x(n, e, null, t) : Array.isArray(r) ? x(n, e, t, r) : x(n, e, t, null); }; function me(n = {}) { let e = null; const t = { c: (...r) => de(t, ...r), use: (r, ...u) => r.install(t, ...u), find: S, context: {}, config: n, get __styleSheet() { if (!e) { const r = document.createElement("style"); return document.head.appendChild(r), e = document.styleSheets[document.styleSheets.length - 1], e; } return e; } }; return t; } const { c: w } = me(), he = w(".xicon", { width: "1em", height: "1em", display: "inline-flex" }, [ w("svg", { width: "1em", height: "1em" }), w("svg:not([fill])", { fill: "currentColor" }) ]), ge = () => { he.mount({ id: "xicons-icon" }); }, P = { size: [String, Number], color: String, tag: String }, M = Symbol("IconConfigInjection"); C({ name: "IconConfigProvider", props: P, setup(n, { slots: e }) { return D(M, n), () => v(e, "default"); } }); const pe = "span", ye = C({ name: "Icon", props: P, setup(n, { slots: e }) { const t = O(M, null), r = m(() => { var o; const s = (o = n.size) !== null && o !== void 0 ? o : t == null ? void 0 : t.size; if (s !== void 0) return typeof s == "number" || /^\d+$/.test(s) ? `${s}px` : s; }), u = m(() => { const { color: o } = n; return o === void 0 ? t ? t.color : void 0 : o; }), i = m(() => { var o; const { tag: s } = n; return s === void 0 ? (o = t == null ? void 0 : t.tag) !== null && o !== void 0 ? o : pe : s; }); return W(() => { ge(); }), () => K(i.value, { class: "xicon", style: { color: u.value, fontSize: r.value } }, [ v(e, "default") ]); } }), xe = /* @__PURE__ */ C({ __name: "icon", props: { color: { default: "inherit" }, size: { default: 16 }, tag: { default: "span" } }, setup(n) { return (e, t) => (p(), $(d(ye), { size: n.size, color: n.color, tag: n.tag }, { default: _(() => [ v(e.$slots, "default") ]), _: 3 }, 8, ["size", "color", "tag"])); } }), Ce = j(xe, "cc-icon"), ve = ["nativeType", "onClick"], be = /* @__PURE__ */ C({ __name: "button", props: { size: { default: "" }, type: { default: "" }, plain: { type: Boolean, default: !1 }, round: { type: Boolean, default: !1 }, circle: { type: Boolean, default: !1 }, disabled: { type: Boolean, default: !1 }, nativeType: { default: "button" }, icon: null }, emits: ["click"], setup(n, { emit: e }) { const t = n, r = G("button"), u = (c) => { t.disabled || e("click", c); }, i = H( r, m(() => t.size) ), o = J( r, m(() => t.type) ), s = m(() => t.plain ? "is-plain" : ""), l = m(() => t.round ? "is-round" : ""), f = m(() => t.disabled ? "is-disabled" : ""), g = m(() => t.circle ? "is-circle" : ""); return (c, a) => (p(), T("button", { nativeType: n.nativeType, class: U([ d(r).b(), d(i), d(o), d(s), d(l), d(f), d(g) ]), onClick: V(u, ["prevent", "stop"]) }, [ n.icon ? (p(), $(d(Ce), { key: 0 }, { default: _(() => [ (p(), $(Z(n.icon), { color: n.type ? "#fff" : "#000" }, null, 8, ["color"])) ]), _: 1 })) : k("", !0), c.$slots.default ? (p(), T("span", { key: 1, style: F({ marginLeft: n.icon ? "8px" : "0" }) }, [ v(c.$slots, "default") ], 4)) : k("", !0) ], 10, ve)); } }), $e = j(be, "cc-button"); export { $e as default };