nova-biz-ui 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,367 @@
1
+ import { defineComponent, mergeDefaults, computed, openBlock, createElementBlock, normalizeClass, renderSlot, inject, createBlock, resolveDynamicComponent, normalizeStyle, withCtx } from "vue";
2
+ function defaultButtonProps() {
3
+ return {
4
+ type: "",
5
+ plain: false,
6
+ disabled: false
7
+ };
8
+ }
9
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
10
+ __name: "button",
11
+ props: /* @__PURE__ */ mergeDefaults({
12
+ type: {},
13
+ plain: { type: Boolean },
14
+ disabled: { type: Boolean }
15
+ }, defaultButtonProps()),
16
+ setup(__props) {
17
+ const props = __props;
18
+ const classes = computed(() => {
19
+ const result = [];
20
+ if (props.type) {
21
+ result.push(`op-button--${props.type}`);
22
+ }
23
+ if (props.plain) {
24
+ result.push("op-button--plain");
25
+ }
26
+ if (props.disabled) {
27
+ result.push("op-button--disabled");
28
+ }
29
+ return result;
30
+ });
31
+ return (_ctx, _cache) => {
32
+ return openBlock(), createElementBlock("button", {
33
+ class: normalizeClass(["op-button", classes.value])
34
+ }, [
35
+ renderSlot(_ctx.$slots, "default", { type: _ctx.type })
36
+ ], 2);
37
+ };
38
+ }
39
+ });
40
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
41
+ __name: "input",
42
+ setup(__props) {
43
+ return (_ctx, _cache) => {
44
+ return openBlock(), createElementBlock("div", null, "123");
45
+ };
46
+ }
47
+ });
48
+ function defaultInputProps() {
49
+ return {
50
+ ...defaultButtonProps(),
51
+ modelValue: ""
52
+ };
53
+ }
54
+ function hello(to = "World") {
55
+ const txt = `Hello ${to}!`;
56
+ alert(txt);
57
+ return txt;
58
+ }
59
+ function isObjectLike(val) {
60
+ return val !== null && typeof val === "object";
61
+ }
62
+ function isFunction(val) {
63
+ return typeof val === "function";
64
+ }
65
+ const themeColors = {
66
+ "color-primary": "#c7000b",
67
+ "color-success": "#50d4ab",
68
+ "color-warning": "#fbb175",
69
+ "color-danger": "#f66f6a",
70
+ "color-info": "#526ecc",
71
+ "color-transparent": "transparent",
72
+ "color-black": "#000",
73
+ "color-white": "#fff",
74
+ // 背景色
75
+ "color-page": "#f5f5f6",
76
+ "color-card": "#fff",
77
+ // 文字主色
78
+ "color-header": "#252b3a",
79
+ "color-regular": "#575d6c",
80
+ "color-secondary": "#8a8e99",
81
+ "color-placeholder": "#abb0b8",
82
+ "color-disabled": "#c0c4cc",
83
+ "color-reverse": "#fff",
84
+ // 边框主色
85
+ "color-bd_darker": "#cdd0d6",
86
+ "color-bd_dark": "#d4d7de",
87
+ "color-bd_base": "#dcdfe6",
88
+ "color-bd_light": "#dfe1e6",
89
+ "color-bd_lighter": "#ebeff5",
90
+ "color-bd_lightest": "#f2f6fc"
91
+ };
92
+ const themeColorLevelsEnabledKeys = [
93
+ "color-primary",
94
+ "color-success",
95
+ "color-warning",
96
+ "color-danger",
97
+ "color-info"
98
+ ];
99
+ const themeSpacing = {
100
+ "spacing-xs": "8px",
101
+ "spacing-sm": "12px",
102
+ "spacing-md": "16px",
103
+ "spacing-lg": "24px",
104
+ "spacing-xl": "32px"
105
+ };
106
+ const themeVars = {
107
+ ...themeColors,
108
+ ...themeSpacing
109
+ };
110
+ function toRgba(str) {
111
+ return hexToRgba(str) || parseCssFunc(str);
112
+ }
113
+ function hexToRgba(str) {
114
+ if (str.charAt(0) !== "#") {
115
+ return null;
116
+ }
117
+ if (str.length !== 4 && str.length !== 7) {
118
+ return null;
119
+ }
120
+ let colorStr = str.slice(1);
121
+ if (colorStr.length === 3) {
122
+ colorStr = colorStr[0] + colorStr[0] + colorStr[1] + colorStr[1] + colorStr[2] + colorStr[2];
123
+ }
124
+ const r = parseInt(colorStr.slice(0, 2), 16);
125
+ const g = parseInt(colorStr.slice(2, 4), 16);
126
+ const b = parseInt(colorStr.slice(4, 6), 16);
127
+ return createRgbaColor(r, g, b, 1);
128
+ }
129
+ const cssColorFunctions = ["rgb", "rgba"];
130
+ function parseCssFunc(str) {
131
+ const match = str.match(/^(.*)\((.+)\)$/i);
132
+ if (!match) {
133
+ return null;
134
+ }
135
+ const [, func, argsTxt] = match;
136
+ if (!cssColorFunctions.includes(func)) {
137
+ return null;
138
+ }
139
+ let argsArr = argsTxt.split(",");
140
+ if (argsArr.length === 1) {
141
+ argsArr = argsTxt.split(" ");
142
+ }
143
+ const args = argsArr.map(parseFloat).filter((item) => item);
144
+ if (func === "rgb" || func === "rgba") {
145
+ const [r, g, b, a] = args;
146
+ return createRgbaColor(r, g, b, a || 1);
147
+ }
148
+ return null;
149
+ }
150
+ function createRgbaColor(r, g, b, a = 1) {
151
+ return {
152
+ args: [r, g, b, a],
153
+ get rgbTxt() {
154
+ const [rr, gg, bb] = this.args;
155
+ return `${rr}, ${gg}, ${bb}`;
156
+ },
157
+ get rgba() {
158
+ return `rgba(${this.rgbTxt}, ${this.args[3] || 1})`;
159
+ }
160
+ };
161
+ }
162
+ function mixRgbColor(source, target, percent) {
163
+ const res = [
164
+ source.args[0] + (target.args[0] - source.args[0]) * (percent / 100),
165
+ source.args[1] + (target.args[1] - source.args[1]) * (percent / 100),
166
+ source.args[2] + (target.args[2] - source.args[2]) * (percent / 100)
167
+ ].map((item) => Math.round(item));
168
+ const [rr, gg, bb] = res;
169
+ return createRgbaColor(rr, gg, bb, source.args[3] || 1);
170
+ }
171
+ function generateRgbColorLevels(color, levels = 9) {
172
+ const result = {
173
+ light: [],
174
+ dark: []
175
+ };
176
+ if (color.rgbTxt === "0, 0, 0" || color.rgbTxt === "255, 255, 255") {
177
+ return result;
178
+ }
179
+ const percent = 100 / (levels + 1);
180
+ for (let i = 1; i < levels + 1; i++) {
181
+ result.light.push(
182
+ mixRgbColor(color, createRgbaColor(255, 255, 255), i * percent)
183
+ );
184
+ result.dark.push(
185
+ mixRgbColor(color, createRgbaColor(0, 0, 0), i * percent)
186
+ );
187
+ }
188
+ return result;
189
+ }
190
+ const DEFAULT_PREFIX = "op-";
191
+ function generateCssVars(origin, options) {
192
+ const {
193
+ prefix = DEFAULT_PREFIX,
194
+ colorLevelsEnabledKeys = [],
195
+ colorLevels = 9
196
+ } = options || {};
197
+ const result = {};
198
+ Object.entries(origin).forEach(([key, value]) => {
199
+ const cssKey = `--${prefix}${key}`;
200
+ const valueToRgba = toRgba(value);
201
+ const finalValue = valueToRgba ? valueToRgba.rgbTxt : value;
202
+ result[cssKey] = finalValue;
203
+ if (valueToRgba && colorLevelsEnabledKeys.includes(key)) {
204
+ const rgbLevels = generateRgbColorLevels(valueToRgba, colorLevels);
205
+ rgbLevels.light.forEach((light, index) => {
206
+ const dark = rgbLevels.dark[index];
207
+ result[`${cssKey}-light-${index + 1}`] = light.rgbTxt;
208
+ result[`${cssKey}-dark-${index + 1}`] = dark.rgbTxt;
209
+ });
210
+ }
211
+ });
212
+ return result;
213
+ }
214
+ function cssVarsToString(cssVars, selector = ":root") {
215
+ let result = `${selector}{`;
216
+ Object.entries(cssVars).forEach(([key, value]) => {
217
+ result += `${key}: ${value};`;
218
+ });
219
+ result += "}";
220
+ return result;
221
+ }
222
+ function getCssVar(name, prefix = DEFAULT_PREFIX) {
223
+ return `var(--${prefix}${name})`;
224
+ }
225
+ function cssVarToRgba(name, alpha = 1, prefix = DEFAULT_PREFIX) {
226
+ return `rgba(${getCssVar(name, prefix)},${alpha})`;
227
+ }
228
+ function toTheme(origin, options) {
229
+ const {
230
+ type = "color",
231
+ prefix = DEFAULT_PREFIX,
232
+ colorLevelsEnabledKeys = [],
233
+ colorLevels = 9
234
+ } = options || {};
235
+ const themeReg = new RegExp(`^${type}-(.*)$`);
236
+ const keys = Object.keys(origin).filter((key) => themeReg.test(key)).map((key) => key.replace(themeReg, "$1"));
237
+ const result = {};
238
+ keys.forEach((key) => {
239
+ result[key] = `rgb(${getCssVar(`${type}-${key}`, prefix)})`;
240
+ if (type === "color" && colorLevelsEnabledKeys.includes(`${type}-${key}`)) {
241
+ const lightColors = {};
242
+ const darkColors = {};
243
+ for (let i = 1; i < colorLevels + 1; i++) {
244
+ lightColors[`${i}`] = `rgb(${getCssVar(`${type}-${key}-light-${i}`, prefix)})`;
245
+ darkColors[`${i}`] = `rgb(${getCssVar(`${type}-${key}-dark-${i}`, prefix)})`;
246
+ }
247
+ result[`${key}_light`] = lightColors;
248
+ result[`${key}_dark`] = darkColors;
249
+ }
250
+ });
251
+ return result;
252
+ }
253
+ const buttonVars = {
254
+ "button-color": cssVarToRgba("color-regular"),
255
+ "button-bg-color": cssVarToRgba("color-card"),
256
+ "button-border-color": cssVarToRgba("color-bd_base"),
257
+ "button-hover-color": cssVarToRgba("color-primary"),
258
+ "button-hover-bg-color": cssVarToRgba("color-primary-light-9"),
259
+ "button-hover-border-color": cssVarToRgba("color-primary-light-7"),
260
+ "button-active-color": cssVarToRgba("color-primary"),
261
+ "button-active-bg-color": cssVarToRgba("color-primary-light-9"),
262
+ "button-active-border-color": cssVarToRgba("color-primary"),
263
+ "button-disabled-color": cssVarToRgba("color-placeholder"),
264
+ "button-disabled-bg-color": cssVarToRgba("color-card"),
265
+ "button-disabled-border-color": cssVarToRgba("color-bd_light"),
266
+ "button-padding-x": getCssVar("spacing-md"),
267
+ "button-padding-y": getCssVar("spacing-xs")
268
+ };
269
+ const tinyThemeVars = {
270
+ "color-primary": "#5e7ce0",
271
+ "color-success": "#50d4ab",
272
+ "color-warning": "#fa9841",
273
+ "color-error": "#c7000b",
274
+ "color-info": "#252b3a"
275
+ };
276
+ const THEME_PROVIDE_KEY = "__NovaUiTheme__";
277
+ function useGlobalTheme(app, options) {
278
+ function setTheme(styleObj) {
279
+ const cssVars = generateCssVars(styleObj, {
280
+ colorLevelsEnabledKeys: themeColorLevelsEnabledKeys,
281
+ colorLevels: 9
282
+ });
283
+ Object.entries(cssVars).forEach(([k, v]) => {
284
+ document.documentElement.style.setProperty(k, v);
285
+ });
286
+ }
287
+ const result = { setTheme };
288
+ app.provide(THEME_PROVIDE_KEY, result);
289
+ if (isObjectLike(options) && Object.keys(options).length > 0) {
290
+ setTheme(options);
291
+ }
292
+ return result;
293
+ }
294
+ function useTheme() {
295
+ const result = inject(THEME_PROVIDE_KEY);
296
+ if (!result) {
297
+ throw new Error("useTheme() must be used after app.use(Theme)!");
298
+ }
299
+ return result;
300
+ }
301
+ const Theme = {
302
+ install: (app, ...options) => {
303
+ const finalOptions = {};
304
+ options.forEach((item) => {
305
+ Object.assign(finalOptions, item);
306
+ });
307
+ useGlobalTheme(app, finalOptions);
308
+ }
309
+ };
310
+ function defaultConfigProviderProps() {
311
+ return {
312
+ tag: "div",
313
+ themeVars: () => ({})
314
+ };
315
+ }
316
+ const _sfc_main = /* @__PURE__ */ defineComponent({
317
+ __name: "config-provider",
318
+ props: /* @__PURE__ */ mergeDefaults({
319
+ tag: {},
320
+ themeVars: {}
321
+ }, defaultConfigProviderProps()),
322
+ setup(__props) {
323
+ const props = __props;
324
+ const cssVars = computed(() => generateCssVars(props.themeVars, {
325
+ colorLevelsEnabledKeys: themeColorLevelsEnabledKeys,
326
+ colorLevels: 9
327
+ }));
328
+ return (_ctx, _cache) => {
329
+ return openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), {
330
+ style: normalizeStyle(cssVars.value)
331
+ }, {
332
+ default: withCtx(() => [
333
+ renderSlot(_ctx.$slots, "default")
334
+ ]),
335
+ _: 3
336
+ }, 8, ["style"]);
337
+ };
338
+ }
339
+ });
340
+ export {
341
+ _sfc_main$2 as Button,
342
+ _sfc_main as ConfigProvider,
343
+ DEFAULT_PREFIX,
344
+ _sfc_main$1 as Input,
345
+ Theme,
346
+ buttonVars,
347
+ cssVarToRgba,
348
+ cssVarsToString,
349
+ defaultButtonProps,
350
+ defaultConfigProviderProps,
351
+ defaultInputProps,
352
+ generateCssVars,
353
+ generateRgbColorLevels,
354
+ getCssVar,
355
+ hello,
356
+ isFunction,
357
+ isObjectLike,
358
+ mixRgbColor,
359
+ themeColorLevelsEnabledKeys,
360
+ themeColors,
361
+ themeSpacing,
362
+ themeVars,
363
+ tinyThemeVars,
364
+ toRgba,
365
+ toTheme,
366
+ useTheme
367
+ };