UNPKG

y-design-ssr

Version:

SSR component library of YUI with Vue3

142 lines (141 loc) 3.67 kB
import { ref as $, reactive as g, getCurrentInstance as b, provide as N, isVNode as S, defineComponent as x, computed as p, createVNode as E } from "vue"; const f = (e, t) => t ? typeof t == "string" ? ` ${e}--${t}` : Array.isArray(t) ? t.reduce((r, n) => r + f(e, n), "") : Object.keys(t).reduce( (r, n) => r + (t[n] ? f(e, n) : ""), "" ) : "", _ = (e) => (t, r) => { let n = t, s = r; return n && typeof n != "string" && (s = n, n = ""), n = n ? `${e}__${n}` : e, `${n}${f(n, s)}`; }, O = () => (e, t) => t ? `${f(`y-${e}`, t)}` : `y-${e}`, A = { "pull-refresh": { pulling: "下拉刷新...", loosing: "释放刷新...", loading: "数据加载中...", success: "数据已更新", failed: "数据跟新失败,请稍后再试" }, "form-item": { validateMessage: "请输入正确内容" } }; $("zh-CN"); g({ "zh-CN": A }); const P = (e) => { const t = `y-${e}`; return [t, _(t), O()]; }; var h = /* @__PURE__ */ ((e) => (e.Top = "top", e.Middle = "middle", e.Bottom = "bottom", e))(h || {}), m = /* @__PURE__ */ ((e) => (e.Start = "start", e.Center = "center", e.End = "end", e.SpaceBetween = "space-between", e.SpaceAround = "space-around", e))(m || {}); const T = (e) => { const t = [], r = (n) => { Array.isArray(n) && n.forEach((s) => { var u; S(s) && (t.push(s), (u = s.component) != null && u.subTree && r(s.component.subTree.children), s.children && r(s.children)); }); }; return r(e), t; }, j = (e, t) => { const r = T(t.subTree.children); e.sort((n, s) => r.indexOf(n.vnode) - r.indexOf(s.vnode)); }, B = (e) => { const t = b(), r = g([]); return { children: r, initProvide: (s) => { N(e, { addChild: (o) => { o.proxy && (r.push(o), t && j(r, t)); }, removeChild: (o) => { const c = r.indexOf(o); r.splice(c, 1); }, children: r, ...s }); } }; }, [y, M] = P("row"), I = y, L = /* @__PURE__ */ x({ name: y, props: { type: { type: String, default: "" }, // 列元素之间的间距(单位为 px) gutter: { type: [Number, String], default: 0 }, align: { type: String, default: h.Top }, justify: { type: String, default: m.Start } }, setup(e, { slots: t }) { const { children: r, initProvide: n } = B(I), s = p(() => { const i = [[]]; let o = 0; return r.forEach((c, a) => { var d; o += Number((d = c.proxy) == null ? void 0 : d.span), o > 24 ? (i.push([a]), o -= 24) : i[i.length - 1].push(a); }), i; }), u = p(() => { const i = Number(e.gutter), o = []; return i && s.value.forEach((c) => { const a = i * (c.length - 1) / c.length; c.forEach((d, v) => { if (v === 0) o.push({ right: a, left: 0 }); else { const l = i - o[d - 1].right, C = a - l; o.push({ left: l, right: C }); } }); }), o; }); return n({ spaceList: u }), () => { var a; const { type: i, align: o, justify: c } = e; return E("div", { class: M({ [i]: i, [`align-${o}`]: i && o, [`justify-${c}`]: i && c }) }, [(a = t.default) == null ? void 0 : a.call(t)]); }; } }); function w(e) { const t = e; return t.install = (r) => { const { name: n } = e; n && r.component(n, e); }, t; } const D = w(L); export { D as default };