cc1-ui 0.0.8 → 0.0.10

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.
@@ -45,6 +45,7 @@ const log = (str, time = false) => {
45
45
  btime = new Date().getTime();
46
46
  };
47
47
  const tagList = ["VButton", "VSwitch", "VScale", "VMask", "VCircle", "VIcon", "VSelect", "VSIcon"];
48
+ const directiveList = ["dominfo"];
48
49
  const extractTags = (str) => {
49
50
  const regex = /<([a-zA-Z\-]+)(?=\s|>|\/>)/g;
50
51
  const tags = [];
@@ -59,6 +60,16 @@ const extractTags = (str) => {
59
60
  }))
60
61
  ];
61
62
  };
63
+ const getDirectiveList = (ctx) => {
64
+ const vDirectiveRegex = /v-([a-zA-Z0-9_-]+)\s*=/g;
65
+ let vMatches = [];
66
+ let match;
67
+ while ((match = vDirectiveRegex.exec(ctx)) !== null) {
68
+ vMatches.push(match[1]);
69
+ }
70
+ vMatches = [...new Set(vMatches)];
71
+ return vMatches;
72
+ };
62
73
  const getTagList = (str, name) => {
63
74
  const re = new RegExp(`<${name}(.*?)<\/${name}>`, 'gs');
64
75
  return Array.from(re[Symbol.matchAll](str)).map((item) => {
@@ -69,6 +80,7 @@ const cmddir = path.resolve('./');
69
80
  const conf = {
70
81
  src: path.resolve(path.join(cmddir, './src')),
71
82
  use: [],
83
+ useDR: [],
72
84
  config: {},
73
85
  diy: {
74
86
  tablecolumn: {
@@ -104,6 +116,11 @@ const init = async () => {
104
116
  if (tagList.includes(tag))
105
117
  conf.use.push(tag);
106
118
  });
119
+ const vDirectiveList = getDirectiveList(ctx);
120
+ vDirectiveList.forEach((v) => {
121
+ if (directiveList.includes(v))
122
+ conf.useDR.push(v);
123
+ });
107
124
  if (ctx.indexOf('VTableColumn') != -1 && !conf.diy.tablecolumn.fixed) {
108
125
  const _tarr = getTagList(ctx, 'VTableColumn');
109
126
  for (let i = 0; i < _tarr.length; i++) {
@@ -122,7 +139,18 @@ const init = async () => {
122
139
  conf.use = conf.use.concat(inludeList.filter((_item) => tagList.includes(_item)));
123
140
  }
124
141
  conf.use = [...new Set(conf.use)];
125
- log(`🥰🥰【${getName()}】:使用组件列表 => ${conf.use.join(',')}`);
142
+ if (conf.use.length > 0) {
143
+ log(`🥰🥰【${getName()}】:使用组件列表 => ${conf.use.join(',')}`);
144
+ }
145
+ else {
146
+ log(`🥰🥰【${getName()}】:没有使用组件`);
147
+ }
148
+ if (conf.useDR.length > 0) {
149
+ log(`🥰🥰【${getName()}】:使用指令列表 => ${conf.useDR.join(',')}`);
150
+ }
151
+ else {
152
+ log(`🥰🥰【${getName()}】:没有使用指令`);
153
+ }
126
154
  };
127
155
  export function UIAuto(config) {
128
156
  conf.config = config;
@@ -144,12 +172,19 @@ export function UIAuto(config) {
144
172
  let res = code.split('\n');
145
173
  for (let i = 0; i < res.length; i++) {
146
174
  if (res[i].includes('defineAsyncComponent(') || res[i].includes('app.component(')) {
147
- if (!conf.use.includes(res[i])) {
175
+ if (!conf.use.some((tag) => res[i].includes(tag))) {
176
+ res[i] = '';
177
+ }
178
+ }
179
+ else if (res[i].includes('const DR') || res[i].includes('installDR(')) {
180
+ if (!conf.useDR.some((tag) => res[i].includes('DR' + tag))) {
148
181
  res[i] = '';
149
182
  }
150
183
  }
151
184
  }
152
- return res.join('\n');
185
+ res = res.filter((v) => v.length > 0);
186
+ res = res.join('\n');
187
+ return res;
153
188
  }
154
189
  else if (comImport.indexOf('cc1-ui#dist#index.css') != -1) {
155
190
  return conf.use.map((v) => `@import url('./components/${v.substring(1)}/style.css');`).join('\n');
package/dist/cc1-ui.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defineAsyncComponent } from 'vue';
2
2
 
3
+ const DRdominfo = () => import('./dominfo-FpTvKs8K.js');
3
4
  const VButton = () => defineAsyncComponent(() => import('./index-lDlR9NjA.js'));
4
5
  const VSwitch = () => defineAsyncComponent(() => import('./index-BvvdDtUd.js'));
5
6
  const VScale = () => defineAsyncComponent(() => import('./index-l4J1-e0K.js'));
@@ -8,6 +9,9 @@ const VCircle = () => defineAsyncComponent(() => import('./index-ti4E-Nv5.js'));
8
9
  const VIcon = () => defineAsyncComponent(() => import('./index-BGzY32VF.js'));
9
10
  const VSelect = () => defineAsyncComponent(() => import('./index-CpyM3z5X.js'));
10
11
  const VSIcon = () => defineAsyncComponent(() => import('./index-mrAwG3J3.js'));
12
+ const installDR = (fun, app) => {
13
+ fun().then((module) => module.install(app));
14
+ };
11
15
  const install = async (app) => {
12
16
  app.component("VButton", VButton());
13
17
  app.component("VSwitch", VSwitch());
@@ -17,6 +21,7 @@ const install = async (app) => {
17
21
  app.component("VIcon", VIcon());
18
22
  app.component("VSelect", VSelect());
19
23
  app.component("VSIcon", VSIcon());
24
+ installDR(DRdominfo, app);
20
25
  };
21
26
  if (!window.VConf) {
22
27
  const getLoad = (obj) => {
@@ -138,6 +138,10 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
138
138
  default: any;
139
139
  };
140
140
  }>> & Readonly<{}>, {
141
+ /**
142
+ * 大小
143
+ */
144
+ size: "middle" | "large" | "small";
141
145
  /**
142
146
  * 图标的class样式
143
147
  */
@@ -153,11 +157,7 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
153
157
  /**
154
158
  * 样式类型
155
159
  */
156
- type: "primary" | "success" | "error" | "warning";
157
- /**
158
- * 大小
159
- */
160
- size: "middle" | "large" | "small";
160
+ type: "error" | "primary" | "success" | "warning";
161
161
  /**
162
162
  * 铺满
163
163
  */
@@ -302,6 +302,10 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
302
302
  default: any;
303
303
  };
304
304
  }>> & Readonly<{}>, {
305
+ /**
306
+ * 大小
307
+ */
308
+ size: "middle" | "large" | "small";
305
309
  /**
306
310
  * 图标的class样式
307
311
  */
@@ -317,11 +321,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
317
321
  /**
318
322
  * 样式类型
319
323
  */
320
- type: "primary" | "success" | "error" | "warning";
321
- /**
322
- * 大小
323
- */
324
- size: "middle" | "large" | "small";
324
+ type: "error" | "primary" | "success" | "warning";
325
325
  /**
326
326
  * 铺满
327
327
  */
@@ -129,14 +129,14 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
129
129
  default: number;
130
130
  };
131
131
  }>> & Readonly<{}>, {
132
- /**
133
- * 进度,0-100
134
- */
135
- length: number;
136
132
  /**
137
133
  * 进度条宽度
138
134
  */
139
135
  width: number;
136
+ /**
137
+ * 进度,0-100
138
+ */
139
+ length: number;
140
140
  /**
141
141
  * 背景色
142
142
  */
@@ -277,14 +277,14 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
277
277
  default: number;
278
278
  };
279
279
  }>> & Readonly<{}>, {
280
- /**
281
- * 进度,0-100
282
- */
283
- length: number;
284
280
  /**
285
281
  * 进度条宽度
286
282
  */
287
283
  width: number;
284
+ /**
285
+ * 进度,0-100
286
+ */
287
+ length: number;
288
288
  /**
289
289
  * 背景色
290
290
  */
@@ -124,17 +124,17 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
124
124
  };
125
125
  }>> & Readonly<{}>, {
126
126
  /**
127
- * 使用的图标大小,默认为'20'
127
+ * 图标大小-高
128
128
  */
129
- size: any;
129
+ height: any;
130
130
  /**
131
131
  * 图标大小-宽
132
132
  */
133
133
  width: any;
134
134
  /**
135
- * 图标大小-高
135
+ * 使用的图标大小,默认为'20'
136
136
  */
137
- height: any;
137
+ size: any;
138
138
  /**
139
139
  * 使用的图标名称,默认为'up',对应[域名或static]/vsicon/up.svg @p 如果lib存在值比如wx,则对应[域名或static]/vsicon/wx/up.svg
140
140
  */
@@ -0,0 +1,2 @@
1
+ import { type App } from 'vue';
2
+ export declare const install: (app: App) => void;
@@ -0,0 +1,90 @@
1
+ import { reactive } from 'vue';
2
+
3
+ const install = (app) => {
4
+ app.directive("dominfo", {
5
+ mounted(el, binding) {
6
+ const value = binding.value;
7
+ if (typeof value !== "object") {
8
+ console.error("dominfo 指令的值必须是一个对象");
9
+ return;
10
+ }
11
+ const debounce = (fn, delay) => {
12
+ let timeoutId;
13
+ return (...args) => {
14
+ clearTimeout(timeoutId);
15
+ timeoutId = setTimeout(() => fn.apply(null, args), delay);
16
+ };
17
+ };
18
+ const dimensions = reactive({
19
+ height: 0,
20
+ width: 0,
21
+ scrollTop: 0,
22
+ scrollLeft: 0,
23
+ clientHeight: 0,
24
+ clientWidth: 0,
25
+ scrollHeight: 0,
26
+ scrollWidth: 0,
27
+ isScrollTop: false,
28
+ isScrollBottom: false,
29
+ isScrollLeft: false,
30
+ isScrollRight: false,
31
+ el
32
+ });
33
+ value.dominfo = dimensions;
34
+ let resizeObserver = null;
35
+ const updateInfo = (rect, target) => {
36
+ dimensions.height = rect?.height ?? target.offsetHeight;
37
+ dimensions.width = rect?.width ?? target.offsetWidth;
38
+ dimensions.scrollTop = target.scrollTop;
39
+ dimensions.scrollLeft = target.scrollLeft;
40
+ dimensions.clientHeight = target.clientHeight;
41
+ dimensions.clientWidth = target.clientWidth;
42
+ dimensions.scrollHeight = target.scrollHeight;
43
+ dimensions.scrollWidth = target.scrollWidth;
44
+ dimensions.isScrollTop = dimensions.scrollTop === 0;
45
+ dimensions.isScrollBottom = Math.abs(dimensions.scrollTop + dimensions.clientHeight - dimensions.scrollHeight) < 1;
46
+ dimensions.isScrollLeft = dimensions.scrollLeft === 0;
47
+ dimensions.isScrollRight = Math.abs(dimensions.scrollLeft + dimensions.clientWidth - dimensions.scrollWidth) < 1;
48
+ };
49
+ const debouncedUpdate = debounce((rect) => {
50
+ updateInfo(rect || el.getBoundingClientRect(), el);
51
+ }, 16);
52
+ const handleScroll = () => {
53
+ debouncedUpdate();
54
+ };
55
+ const initObservers = () => {
56
+ debouncedUpdate();
57
+ el.addEventListener("scroll", handleScroll, { passive: true });
58
+ resizeObserver = new ResizeObserver((entries) => {
59
+ for (const entry of entries) {
60
+ debouncedUpdate(entry.contentRect);
61
+ }
62
+ });
63
+ resizeObserver.observe(el);
64
+ };
65
+ const cleanup = () => {
66
+ if (resizeObserver) {
67
+ resizeObserver.disconnect();
68
+ resizeObserver = null;
69
+ }
70
+ el.removeEventListener("scroll", handleScroll);
71
+ if (value.dominfo) {
72
+ value.dominfo = null;
73
+ }
74
+ };
75
+ el._dominfoCleanup = cleanup;
76
+ initObservers();
77
+ },
78
+ unmounted(el, binding) {
79
+ if (typeof el._dominfoCleanup === "function") {
80
+ el._dominfoCleanup();
81
+ delete el._dominfoCleanup;
82
+ }
83
+ if (binding.value?.dominfo) {
84
+ binding.value.dominfo = null;
85
+ }
86
+ }
87
+ });
88
+ };
89
+
90
+ export { install };
package/dist/index.d.ts CHANGED
@@ -14,12 +14,12 @@ declare module 'vue' {
14
14
  export interface GlobalComponents {
15
15
  VButton:typeof import('./components/Button/index.vue')['default']
16
16
  VCircle:typeof import('./components/Circle/index.vue')['default']
17
- VIcon:typeof import('./components/Icon/index.vue')['default']
18
17
  VMask:typeof import('./components/Mask/index.vue')['default']
19
18
  VSIcon:typeof import('./components/SIcon/index.vue')['default']
20
- VSelect:typeof import('./components/Select/index.vue')['default']
21
19
  VSwitch:typeof import('./components/Switch/index.vue')['default']
22
20
  VScale:typeof import('./components/Scale/index.vue')['default']
21
+ VIcon:typeof import('./components/Icon/index.vue')['default']
22
+ VSelect:typeof import('./components/Select/index.vue')['default']
23
23
  }
24
24
  export interface ComponentCustomProperties {
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc1-ui",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "我来助你-Vue3UI库",
5
5
  "repository": {
6
6
  "type": "git",