UNPKG

vue-amazing-ui

Version:

An Amazing Vue3 UI Components Library, Using TypeScript.

198 lines (197 loc) 4.6 kB
import { defineComponent as M, reactive as p, provide as g, computed as b, watch as S, renderSlot as B, createBlock as x, openBlock as A, resolveDynamicComponent as I, withCtx as D } from "vue"; import { TinyColor as a } from "@ctrl/tinycolor"; import { generate as G } from "@ant-design/colors"; const E = /* @__PURE__ */ M({ __name: "ConfigProvider", props: { theme: { default: () => ({}) }, abstract: { type: Boolean, default: !0 }, tag: { default: "div" } }, setup(s) { const c = s, n = p({ colorPalettes: [], shadowColor: "" }), d = p({ Alert: { colorPalettes: [], shadowColor: "" }, BackTop: { colorPalettes: [], shadowColor: "" }, Button: { colorPalettes: [], shadowColor: "" }, Calendar: { colorPalettes: [], shadowColor: "" }, Carousel: { colorPalettes: [], shadowColor: "" }, Checkbox: { colorPalettes: [], shadowColor: "" }, ColorPicker: { colorPalettes: [], shadowColor: "" }, DatePicker: { colorPalettes: [], shadowColor: "" }, FloatButton: { colorPalettes: [], shadowColor: "" }, Image: { colorPalettes: [], shadowColor: "" }, Input: { colorPalettes: [], shadowColor: "" }, InputNumber: { colorPalettes: [], shadowColor: "" }, InputSearch: { colorPalettes: [], shadowColor: "" }, LoadingBar: { colorPalettes: [], shadowColor: "" }, Message: { colorPalettes: [], shadowColor: "" }, Modal: { colorPalettes: [], shadowColor: "" }, Notification: { colorPalettes: [], shadowColor: "" }, Pagination: { colorPalettes: [], shadowColor: "" }, Popconfirm: { colorPalettes: [], shadowColor: "" }, Progress: { colorPalettes: [], shadowColor: "" }, Radio: { colorPalettes: [], shadowColor: "" }, Select: { colorPalettes: [], shadowColor: "" }, Slider: { colorPalettes: [], shadowColor: "" }, Spin: { colorPalettes: [], shadowColor: "" }, Steps: { colorPalettes: [], shadowColor: "" }, Swiper: { colorPalettes: [], shadowColor: "" }, Switch: { colorPalettes: [], shadowColor: "" }, Tabs: { colorPalettes: [], shadowColor: "" }, Textarea: { colorPalettes: [], shadowColor: "" }, TextScroll: { colorPalettes: [], shadowColor: "" }, Upload: { colorPalettes: [], shadowColor: "" } }); g("common", n), g("components", d); const i = b(() => "common" in c.theme ? c.theme.common : null), T = b(() => { const o = { ...c.theme }; return "common" in o && delete o.common, o; }); S( i, (o) => { const e = C(o?.primaryColor || "#1677ff"); n.colorPalettes = e, n.shadowColor = m(e[0]); }, { immediate: !0 } ), S( T, (o) => { Object.keys(o).forEach((e) => { const l = o[e]?.primaryColor || i.value?.primaryColor || "#1677ff", r = C(l); d[e].colorPalettes = r, d[e].shadowColor = m(r[0]); }); }, { immediate: !0 } ); function C(o) { return G(o); } function h(o) { return o >= 0 && o <= 255; } function m(o, e = "#ffffff") { const { r: l, g: r, b: w, a: y } = new a(o).toRgb(); if (y < 1) return o; const { r: k, g: v, b: R } = new a(e).toRgb(); for (let t = 0.01; t <= 1; t += 0.01) { const P = Math.round((l - k * (1 - t)) / t), f = Math.round((r - v * (1 - t)) / t), u = Math.round((w - R * (1 - t)) / t); if (h(P) && h(f) && h(u)) return new a({ r: P, g: f, b: u, a: Math.round(t * 100) / 100 }).toRgbString(); } return new a({ r: l, g: r, b: w, a: 1 }).toRgbString(); } return (o, e) => s.abstract ? B(o.$slots, "default", { key: 0 }) : (A(), x(I(s.tag), { key: 1, class: "config-provider-wrap" }, { default: D(() => [ B(o.$slots, "default") ]), _: 3 })); } }); export { E as default };