cc-ui-plus
Version:
654 lines (652 loc) • 18 kB
JavaScript
import { defineComponent as w, openBlock as g, createElementBlock as $, createElementVNode as d, provide as G, renderSlot as O, inject as J, computed as k, onBeforeMount as Q, h as X, createBlock as v, unref as f, withCtx as p, ref as T, Transition as Y, withDirectives as ee, normalizeStyle as te, normalizeClass as S, createVNode as _, createCommentVNode as b, toDisplayString as ne, withModifiers as re, vShow as oe, createApp as se, watch as F } from "vue";
function ce(e, t) {
return e.install = (n) => {
n.component(t, e);
}, e;
}
const le = (e, t) => (e.install = (n) => {
e._context = n._context, n.config.globalProperties[t] = e;
}, e);
function A(e, t, n) {
let r = e;
return t && (r += `__${t}`), n && (r += `--${n}`), r;
}
function ie(e) {
const t = `cc-${e}`;
return {
b: () => A(t),
e: (o) => o ? A(t, o) : "",
m: (o) => o ? A(t, "", o) : "",
em: (o, l) => o && l ? A(t, o, l) : ""
};
}
const ue = {
xmlns: "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
viewBox: "0 0 1024 1024"
}, fe = /* @__PURE__ */ d(
"path",
{
d: "M699 353h-46.9c-10.2 0-19.9 4.9-25.9 13.3L469 584.3l-71.2-98.8c-6-8.3-15.6-13.3-25.9-13.3H325c-6.5 0-10.3 7.4-6.5 12.7l124.6 172.8a31.8 31.8 0 0 0 51.7 0l210.6-292c3.9-5.3.1-12.7-6.4-12.7z",
fill: "currentColor"
},
null,
-1
), ae = /* @__PURE__ */ d(
"path",
{
d: "M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",
fill: "currentColor"
},
null,
-1
), de = [fe, ae], he = w({
name: "CheckCircleOutlined",
render: function(t, n) {
return g(), $("svg", ue, de);
}
}), ge = {
xmlns: "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
viewBox: "0 0 1024 1024"
}, me = /* @__PURE__ */ d(
"path",
{
d: "M685.4 354.8c0-4.4-3.6-8-8-8l-66 .3L512 465.6l-99.3-118.4l-66.1-.3c-4.4 0-8 3.5-8 8c0 1.9.7 3.7 1.9 5.2l130.1 155L340.5 670a8.32 8.32 0 0 0-1.9 5.2c0 4.4 3.6 8 8 8l66.1-.3L512 564.4l99.3 118.4l66 .3c4.4 0 8-3.5 8-8c0-1.9-.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z",
fill: "currentColor"
},
null,
-1
), xe = /* @__PURE__ */ d(
"path",
{
d: "M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448s448-200.6 448-448S759.4 65 512 65zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",
fill: "currentColor"
},
null,
-1
), we = [me, xe], pe = w({
name: "CloseCircleOutlined",
render: function(t, n) {
return g(), $("svg", ge, we);
}
}), ye = {
xmlns: "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
viewBox: "0 0 1024 1024"
}, Ce = /* @__PURE__ */ d(
"path",
{
d: "M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8L295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512L196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1l216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z",
fill: "currentColor"
},
null,
-1
), _e = [Ce], ve = w({
name: "CloseOutlined",
render: function(t, n) {
return g(), $("svg", ye, _e);
}
}), $e = {
xmlns: "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
viewBox: "0 0 1024 1024"
}, be = /* @__PURE__ */ d(
"path",
{
d: "M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",
fill: "currentColor"
},
null,
-1
), ze = /* @__PURE__ */ d(
"path",
{
d: "M464 336a48 48 0 1 0 96 0a48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z",
fill: "currentColor"
},
null,
-1
), Ae = [be, ze], Ee = w({
name: "InfoCircleOutlined",
render: function(t, n) {
return g(), $("svg", $e, Ae);
}
}), ke = {
xmlns: "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
viewBox: "0 0 32 32"
}, Te = /* @__PURE__ */ d(
"path",
{
d: "M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2zm0 26a12 12 0 1 1 12-12a12 12 0 0 1-12 12z",
fill: "currentColor"
},
null,
-1
), Se = /* @__PURE__ */ d(
"path",
{
d: "M15 8h2v11h-2z",
fill: "currentColor"
},
null,
-1
), Me = /* @__PURE__ */ d(
"path",
{
d: "M16 22a1.5 1.5 0 1 0 1.5 1.5A1.5 1.5 0 0 0 16 22z",
fill: "currentColor"
},
null,
-1
), Be = [Te, Se, Me], Ie = w({
name: "Warning",
render: function(t, n) {
return g(), $("svg", ke, Be);
}
});
function Le(e) {
let t = 0;
for (let n = 0; n < e.length; ++n)
e[n] === "&" && ++t;
return t;
}
const P = /\s*,(?![^(]*\))\s*/g, Oe = /\s+/g;
function je(e, t) {
const n = [];
return t.split(P).forEach((r) => {
let s = Le(r);
if (s) {
if (s === 1) {
e.forEach((o) => {
n.push(r.replace("&", o));
});
return;
}
} else {
e.forEach((o) => {
n.push(
(o && o + " ") + r
);
});
return;
}
let c = [
r
];
for (; s--; ) {
const o = [];
c.forEach((l) => {
e.forEach((i) => {
o.push(l.replace("&", i));
});
}), c = o;
}
c.forEach((o) => n.push(o));
}), n;
}
function Re(e, t) {
const n = [];
return t.split(P).forEach((r) => {
e.forEach((s) => {
n.push((s && s + " ") + r);
});
}), n;
}
function Ne(e) {
let t = [""];
return e.forEach((n) => {
n = n && n.trim(), n && (n.includes("&") ? t = je(t, n) : t = Re(t, n));
}), t.join(", ").replace(Oe, " ");
}
const Ve = /[A-Z]/g;
function q(e) {
return e.replace(Ve, (t) => "-" + t.toLowerCase());
}
function Fe(e, t = " ") {
return typeof e == "object" && e !== null ? ` {
` + Object.entries(e).map((n) => t + ` ${q(n[0])}: ${n[1]};`).join(`
`) + `
` + t + "}" : `: ${e};`;
}
function Pe(e, t, n) {
return typeof e == "function" ? e({
context: t.context,
props: n
}) : e;
}
function R(e, t, n, r) {
if (!t)
return "";
const s = Pe(t, n, r);
if (!s)
return "";
if (typeof s == "string")
return `${e} {
${s}
}`;
const c = Object.keys(s);
if (c.length === 0)
return n.config.keepEmptyBlock ? e + ` {
}` : "";
const o = e ? [
e + " {"
] : [];
return c.forEach((l) => {
const i = s[l];
if (l === "raw") {
o.push(`
` + i + `
`);
return;
}
l = q(l), i != null && o.push(` ${l}${Fe(i)}`);
}), e && o.push("}"), o.join(`
`);
}
function I(e, t, n) {
!e || e.forEach((r) => {
if (Array.isArray(r))
I(r, t, n);
else if (typeof r == "function") {
const s = r(t);
Array.isArray(s) ? I(s, t, n) : s && n(s);
} else
r && n(r);
});
}
function W(e, t, n, r, s, c) {
const o = e.$;
!o || typeof o == "string" ? t.push(o) : typeof o == "function" ? t.push(o({
context: r.context,
props: s
})) : (o.before && o.before(r.context), !o.$ || typeof o.$ == "string" ? t.push(o.$) : o.$ && t.push(o.$({
context: r.context,
props: s
})));
const l = Ne(t), i = R(l, e.props, r, s);
c && i && c.insertRule(i), !c && i.length && n.push(i), e.children && I(e.children, {
context: r.context,
props: s
}, (a) => {
if (typeof a == "string") {
const C = R(l, { raw: a }, r, s);
c ? c.insertRule(C) : n.push(C);
} else
W(a, t, n, r, s, c);
}), t.pop(), o && o.after && o.after(r.context);
}
function D(e, t, n, r = !1) {
const s = [];
return W(e, [], s, t, n, r ? e.instance.__styleSheet : void 0), r ? "" : s.join(`
`);
}
function qe(e) {
for (var t = 0, n, r = 0, s = e.length; s >= 4; ++r, s -= 4)
n = e.charCodeAt(r) & 255 | (e.charCodeAt(++r) & 255) << 8 | (e.charCodeAt(++r) & 255) << 16 | (e.charCodeAt(++r) & 255) << 24, n = (n & 65535) * 1540483477 + ((n >>> 16) * 59797 << 16), n ^= n >>> 24, t = (n & 65535) * 1540483477 + ((n >>> 16) * 59797 << 16) ^ (t & 65535) * 1540483477 + ((t >>> 16) * 59797 << 16);
switch (s) {
case 3:
t ^= (e.charCodeAt(r + 2) & 255) << 16;
case 2:
t ^= (e.charCodeAt(r + 1) & 255) << 8;
case 1:
t ^= e.charCodeAt(r) & 255, t = (t & 65535) * 1540483477 + ((t >>> 16) * 59797 << 16);
}
return t ^= t >>> 13, t = (t & 65535) * 1540483477 + ((t >>> 16) * 59797 << 16), ((t ^ t >>> 15) >>> 0).toString(36);
}
function M(e) {
if (!e)
return;
const t = e.parentElement;
t && t.removeChild(e);
}
function j(e) {
return document.querySelector(`style[cssr-id="${e}"]`);
}
function We(e) {
const t = document.createElement("style");
return t.setAttribute("cssr-id", e), t;
}
window && (window.__cssrContext = {});
function H(e) {
const t = e.getAttribute("mount-count");
return t === null ? null : Number(t);
}
function L(e, t) {
e.setAttribute("mount-count", String(t));
}
function N(e, t, n, r) {
const { els: s } = t;
if (n === void 0)
s.forEach(M), t.els = [];
else {
const c = j(n);
if (c && s.includes(c)) {
const o = H(c);
r ? o === null ? console.error(`[css-render/unmount]: The style with target='${n}' is mounted in count mode.`) : o <= 1 ? (M(c), t.els = s.filter((l) => l !== c)) : L(c, o - 1) : o !== null ? console.error(`[css-render/unmount]: The style with target='${n}' is mounted in no-count mode.`) : (M(c), t.els = s.filter((l) => l !== c));
}
}
}
function De(e, t) {
e.push(t);
}
function He(e, t, n, r, s, c, o, l, i) {
if (o && !i) {
if (n === void 0) {
console.error("[css-render/mount]: `id` is required in `boost` mode.");
return;
}
const m = window.__cssrContext;
m[n] || (m[n] = !0, D(t, e, r, o));
return;
}
let a;
const { els: C } = t;
let x;
if (n === void 0 && (x = t.render(r), n = qe(x)), i) {
i(n, x != null ? x : t.render(r));
return;
}
const u = j(n);
if (l || u === null) {
if (a = u === null ? We(n) : u, x === void 0 && (x = t.render(r)), a.textContent = x, u !== null)
return;
if (s) {
const m = document.head.getElementsByTagName("style")[0] || null;
document.head.insertBefore(a, m);
} else
document.head.appendChild(a);
c && L(a, 1), De(C, a);
} else {
const m = H(u);
c ? m === null ? console.error(`[css-render/mount]: The style with id='${n}' has been mounted in no-count mode.`) : L(u, m + 1) : m !== null && console.error(`[css-render/mount]: The style with id='${n}' has been mounted in count mode.`);
}
return u != null ? u : a;
}
function Ke(e) {
return D(this, this.instance, e);
}
function Ue(e = {}) {
const { target: t, id: n, ssr: r, props: s, count: c = !1, head: o = !1, boost: l = !1, force: i = !1 } = e;
return He(this.instance, this, n != null ? n : t, s, o, c, l, i, r);
}
function Ze(e = {}) {
const { id: t, target: n, delay: r = 0, count: s = !1 } = e;
r === 0 ? N(this.instance, this, t != null ? t : n, s) : setTimeout(() => N(this.instance, this, t != null ? t : n, s), r);
}
const E = function(e, t, n, r) {
return {
instance: e,
$: t,
props: n,
children: r,
els: [],
render: Ke,
mount: Ue,
unmount: Ze
};
}, Ge = function(e, t, n, r) {
return Array.isArray(t) ? E(e, { $: null }, null, t) : Array.isArray(n) ? E(e, t, null, n) : Array.isArray(r) ? E(e, t, n, r) : E(e, t, n, null);
};
function Je(e = {}) {
let t = null;
const n = {
c: (...r) => Ge(n, ...r),
use: (r, ...s) => r.install(n, ...s),
find: j,
context: {},
config: e,
get __styleSheet() {
if (!t) {
const r = document.createElement("style");
return document.head.appendChild(r), t = document.styleSheets[document.styleSheets.length - 1], t;
}
return t;
}
};
return n;
}
const { c: B } = Je(), Qe = B(".xicon", {
width: "1em",
height: "1em",
display: "inline-flex"
}, [
B("svg", {
width: "1em",
height: "1em"
}),
B("svg:not([fill])", {
fill: "currentColor"
})
]), Xe = () => {
Qe.mount({ id: "xicons-icon" });
}, K = {
size: [String, Number],
color: String,
tag: String
}, U = Symbol("IconConfigInjection");
w({
name: "IconConfigProvider",
props: K,
setup(e, { slots: t }) {
return G(U, e), () => O(t, "default");
}
});
const Ye = "span", et = w({
name: "Icon",
props: K,
setup(e, { slots: t }) {
const n = J(U, null), r = k(() => {
var o;
const l = (o = e.size) !== null && o !== void 0 ? o : n == null ? void 0 : n.size;
if (l !== void 0)
return typeof l == "number" || /^\d+$/.test(l) ? `${l}px` : l;
}), s = k(() => {
const { color: o } = e;
return o === void 0 ? n ? n.color : void 0 : o;
}), c = k(() => {
var o;
const { tag: l } = e;
return l === void 0 ? (o = n == null ? void 0 : n.tag) !== null && o !== void 0 ? o : Ye : l;
});
return Q(() => {
Xe();
}), () => X(c.value, {
class: "xicon",
style: {
color: s.value,
fontSize: r.value
}
}, [
O(t, "default")
]);
}
}), tt = /* @__PURE__ */ w({
__name: "icon",
props: {
color: { default: "inherit" },
size: { default: 16 },
tag: { default: "span" }
},
setup(e) {
return (t, n) => (g(), v(f(et), {
size: e.size,
color: e.color,
tag: e.tag
}, {
default: p(() => [
O(t.$slots, "default")
]),
_: 3
}, 8, ["size", "color", "tag"]));
}
}), z = ce(tt, "cc-icon"), nt = ["onClick"], rt = /* @__PURE__ */ w({
__name: "message",
props: {
message: { default: "" },
type: { default: "info" },
center: { type: Boolean, default: !1 },
showClose: { type: Boolean, default: !1 },
offset: { default: 20 }
},
setup(e, { expose: t }) {
const n = e, r = ie("message"), s = T(!1), c = T(!1), o = T(n.offset), l = (u, m = 300) => new Promise((Z) => {
s.value = u, setTimeout(() => {
Z("");
}, m);
}), i = (u) => {
o.value = u;
}, a = (u) => {
c.value = u;
}, C = () => {
a(!0), l(!1, 0);
};
t({
setVisible: l,
setTop: i,
setCloseFlag: a,
closeFlag: c
});
const x = k(() => n.type === "success" ? "bg-success" : n.type === "info" ? "bg-info" : n.type === "danger" ? "bg-danger" : n.type === "warning" ? "bg-warning" : "");
return (u, m) => (g(), v(Y, { name: "cc-message" }, {
default: p(() => [
ee(d("div", {
style: te({ top: o.value + "px" }),
class: S([f(r).b(), f(x), e.center ? f(r).m("center") : ""])
}, [
d("div", {
class: S([f(r).e("icon")])
}, [
e.type === "success" ? (g(), v(f(z), {
key: 0,
color: "var(--cc-color-success)"
}, {
default: p(() => [
_(f(he))
]),
_: 1
})) : b("", !0),
e.type === "warning" ? (g(), v(f(z), {
key: 1,
color: "var(--cc-color-warning)"
}, {
default: p(() => [
_(f(Ie))
]),
_: 1
})) : b("", !0),
e.type === "info" ? (g(), v(f(z), {
key: 2,
color: "var(--cc-color-info)"
}, {
default: p(() => [
_(f(Ee))
]),
_: 1
})) : b("", !0),
e.type === "danger" ? (g(), v(f(z), {
key: 3,
color: "var(--cc-color-danger)"
}, {
default: p(() => [
_(f(pe))
]),
_: 1
})) : b("", !0)
], 2),
d("div", null, ne(e.message), 1),
e.showClose ? (g(), $("div", {
key: 0,
class: S([f(r).e("close-btn")]),
onClick: re(C, ["stop"])
}, [
_(f(z), {
color: "var(--cc-message-close-icon-color)",
size: "var(--cc-message-close-icon-size)"
}, {
default: p(() => [
_(f(ve))
]),
_: 1
})
], 10, nt)) : b("", !0)
], 6), [
[oe, s.value]
])
]),
_: 1
}));
}
}), ot = 60, st = 28, y = T([]), h = (e) => {
typeof e == "string" && (e = {
message: e,
duration: 3e3
});
const t = se(rt, e);
ct(t, e.duration);
}, ct = (e, t = 3e3) => {
const n = document.createDocumentFragment(), r = e.mount(n);
y.value.push(r), V(r), r.setVisible(!0), F(
() => y.value,
() => V(r)
), document.body.appendChild(n), lt(e, r, t);
}, lt = (e, t, n = 3e3) => {
F(
() => t.closeFlag,
(r) => {
r && (t.closeTimer = setTimeout(() => {
e.unmount(), y.value = y.value.filter((s) => s !== t), clearTimeout(t.closeTimer), t.closeTimer = null, t.closeFlag = !1;
}, 300));
}
), t.timer = setTimeout(async () => {
await t.setVisible(!1), e.unmount(), y.value = y.value.filter((r) => r !== t), clearTimeout(t.timer), t.timer = null;
}, n);
}, V = (e) => {
const t = y.value.indexOf(e);
e.setTop(ot * t + st);
};
h.success = (e) => {
h(typeof e == "string" ? {
type: "success",
message: e
} : {
type: "success",
message: e.message,
...e
});
};
h.info = (e) => {
h(typeof e == "string" ? {
type: "info",
message: e
} : {
type: "info",
message: e.message,
...e
});
};
h.warning = (e) => {
h(typeof e == "string" ? {
type: "warning",
message: e
} : {
type: "warning",
message: e.message,
...e
});
};
h.error = (e) => {
h(typeof e == "string" ? {
type: "danger",
message: e
} : {
type: "danger",
message: e.message,
...e
});
};
const ut = le(h, "$message");
export {
ut as default
};