UNPKG

vue-amazing-ui

Version:

An Amazing Vue3 UI Components Library, Using TypeScript.

199 lines (198 loc) 4.7 kB
import { defineComponent as M, reactive as p, provide as g, computed as b, watch as S, renderSlot as B, createBlock as A, openBlock as I, resolveDynamicComponent as _, withCtx as x } from "vue"; import { TinyColor as c } from "@ctrl/tinycolor"; import { generate as D } from "@ant-design/colors"; const j = /* @__PURE__ */ M({ __name: "ConfigProvider", props: { theme: { default: () => ({}) }, abstract: { type: Boolean, default: !0 }, tag: { default: "div" } }, setup(T) { const n = T, d = p({ colorPalettes: [], shadowColor: "" }), h = 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", d), g("components", h); const C = b(() => "common" in n.theme ? n.theme.common : null), y = b(() => { const o = { ...n.theme }; return "common" in o && delete o.common, o; }); S( C, (o) => { const e = m((o == null ? void 0 : o.primaryColor) || "#1677ff"); d.colorPalettes = e, d.shadowColor = P(e[0]); }, { immediate: !0 } ), S( y, (o) => { Object.keys(o).forEach((e) => { var l, s; const a = ((l = o[e]) == null ? void 0 : l.primaryColor) || ((s = C.value) == null ? void 0 : s.primaryColor) || "#1677ff", r = m(a); h[e].colorPalettes = r, h[e].shadowColor = P(r[0]); }); }, { immediate: !0 } ); function m(o) { return D(o); } function i(o) { return o >= 0 && o <= 255; } function P(o, e = "#ffffff") { const { r: a, g: r, b: l, a: s } = new c(o).toRgb(); if (s < 1) return o; const { r: k, g: v, b: R } = new c(e).toRgb(); for (let t = 0.01; t <= 1; t += 0.01) { const w = Math.round((a - k * (1 - t)) / t), f = Math.round((r - v * (1 - t)) / t), u = Math.round((l - R * (1 - t)) / t); if (i(w) && i(f) && i(u)) return new c({ r: w, g: f, b: u, a: Math.round(t * 100) / 100 }).toRgbString(); } return new c({ r: a, g: r, b: l, a: 1 }).toRgbString(); } return (o, e) => o.abstract ? B(o.$slots, "default", { key: 0 }) : (I(), A(_(o.tag), { key: 1, class: "m-config-provider" }, { default: x(() => [ B(o.$slots, "default") ]), _: 3 })); } }); export { j as default };