@fangzhongya/vue-components 0.1.29 → 0.1.30

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.
Files changed (61) hide show
  1. package/dist/archive.cjs +190 -340
  2. package/dist/archive.d.cts +5 -4
  3. package/dist/archive.d.ts +5 -4
  4. package/dist/archive.js +190 -341
  5. package/dist/chunk-J7CICTHH-DzD10422.cjs +25 -0
  6. package/dist/chunk-J7CICTHH-Ikr5rmAQ.js +20 -0
  7. package/dist/component-B-5G8Yjc.js +431 -0
  8. package/dist/component-CVkcT_sw.cjs +459 -0
  9. package/dist/component.cjs +2 -8
  10. package/dist/component.d.cts +14 -14
  11. package/dist/component.d.ts +15 -14
  12. package/dist/component.js +2 -8
  13. package/dist/config.cjs +59 -6
  14. package/dist/config.d.cts +134 -133
  15. package/dist/config.d.ts +134 -133
  16. package/dist/config.js +57 -5
  17. package/dist/import.cjs +18 -25
  18. package/dist/import.d.cts +5 -4
  19. package/dist/import.d.ts +5 -4
  20. package/dist/import.js +18 -26
  21. package/dist/imports-Cl3zPCxJ.cjs +971 -0
  22. package/dist/imports-DLu2DPCK.js +966 -0
  23. package/dist/imports.cjs +2 -8
  24. package/dist/imports.d.cts +14 -14
  25. package/dist/imports.d.ts +15 -14
  26. package/dist/imports.js +2 -8
  27. package/dist/index-5NuL-vgA.d.ts +5609 -0
  28. package/dist/index-DORWvPc3.d.cts +5609 -0
  29. package/dist/index.cjs +8 -17
  30. package/dist/index.d.cts +7 -8
  31. package/dist/index.d.ts +7 -8
  32. package/dist/index.js +6 -17
  33. package/dist/library.cjs +32 -48
  34. package/dist/library.d.cts +7 -6
  35. package/dist/library.d.ts +7 -6
  36. package/dist/library.js +32 -49
  37. package/dist/resolver.cjs +25 -10
  38. package/dist/resolver.d.cts +5 -4
  39. package/dist/resolver.d.ts +5 -4
  40. package/dist/resolver.js +24 -10
  41. package/dist/types-CZdqb5KI-T7Ielv5Y.d.cts +134 -0
  42. package/dist/types-CZdqb5KI-T7Ielv5Y.d.ts +134 -0
  43. package/dist/util-Ddld3oFr.js +93 -0
  44. package/dist/util-DtBzae46.cjs +116 -0
  45. package/dist/util.cjs +8 -16
  46. package/dist/util.d.cts +104 -5
  47. package/dist/util.d.ts +104 -5
  48. package/dist/util.js +3 -16
  49. package/package.json +10 -10
  50. package/dist/chunk-2SBJQUCI.cjs +0 -1238
  51. package/dist/chunk-3XFEJIQP.js +0 -135
  52. package/dist/chunk-6PYVVU7E.cjs +0 -581
  53. package/dist/chunk-7JRVVHVI.cjs +0 -33
  54. package/dist/chunk-AKNB7BKJ.cjs +0 -25
  55. package/dist/chunk-DURXCSNX.js +0 -62
  56. package/dist/chunk-HFFYPZA3.js +0 -1238
  57. package/dist/chunk-IXN2F3IJ.js +0 -581
  58. package/dist/chunk-NLSI7A24.cjs +0 -135
  59. package/dist/chunk-RRQV2YXW.js +0 -33
  60. package/dist/chunk-TVGK2KRP.js +0 -25
  61. package/dist/chunk-UNBQUEQ4.cjs +0 -62
@@ -0,0 +1,431 @@
1
+ import { i as styleLog, t as getComponentNames } from "./util-Ddld3oFr.js";
2
+ import { t as humpToLine } from "./chunk-J7CICTHH-Ikr5rmAQ.js";
3
+ import fastGlob from "fast-glob";
4
+ import { resolve } from "path";
5
+ //#region node_modules/.pnpm/@fangzhongya+utils@0.0.80/node_modules/@fangzhongya/utils/dist/chunk-YNOFNHEK.js
6
+ function matchsEnd(key, matchs) {
7
+ if (matchs && matchs.length > 0) {
8
+ for (const value of matchs) if (typeof value == "string") {
9
+ if (key.endsWith(value)) return true;
10
+ } else if (value.test(key)) return true;
11
+ return false;
12
+ } else return true;
13
+ }
14
+ //#endregion
15
+ //#region node_modules/.pnpm/@fangzhongya+utils@0.0.80/node_modules/@fangzhongya/utils/dist/chunk-S6JRKYPY.js
16
+ function matchsStart(key, matchs) {
17
+ if (matchs && matchs.length > 0) {
18
+ for (const value of matchs) if (typeof value == "string") {
19
+ if (key.startsWith(value)) return true;
20
+ } else if (value.test(key)) return true;
21
+ return false;
22
+ } else return true;
23
+ }
24
+ //#endregion
25
+ //#region packages/component.ts
26
+ /**
27
+ *
28
+ * | com-page | ComPage | comPage | compage | 注册名称
29
+ * | :------: | :------: | :------: | :------: |
30
+ * | com-page | com-page | com-page | :------: | 组件写法
31
+ * | :------: | ComPage | :------: | :------: |
32
+ * | :------: | comPage | comPage | :------: |
33
+ * | :------: | :------: | :------: | compage |
34
+ *
35
+ */
36
+ function checkSuffixBeforeMatch(str, regex, suffix) {
37
+ regex.lastIndex = 0;
38
+ const match = regex.exec(str);
39
+ if (!match) return false;
40
+ const matchStartIndex = match.index;
41
+ return str.substring(0, matchStartIndex).endsWith(suffix);
42
+ }
43
+ /**
44
+ * 判断是否匹配
45
+ */
46
+ function isUrlsMatchi(key, arr, matchs) {
47
+ for (const name of arr) {
48
+ const t = "/" + name;
49
+ if (matchs && matchs.length > 0) {
50
+ for (const value of matchs) if (typeof value == "string") {
51
+ if (key.endsWith(t + value)) return true;
52
+ } else if (checkSuffixBeforeMatch(key, value, t)) return true;
53
+ } else if (key.includes(name)) return true;
54
+ }
55
+ return false;
56
+ }
57
+ /**
58
+ * 自动注册组件和指令的方法
59
+ */
60
+ var FangComponent = class {
61
+ config;
62
+ #comUrls;
63
+ #dirUrls;
64
+ #cssUrls;
65
+ #cacheObj;
66
+ #curDir;
67
+ constructor(config) {
68
+ this.config = config || {};
69
+ this.#setConfigValue();
70
+ }
71
+ /**
72
+ * 初始化数据
73
+ */
74
+ #setConfigValue() {
75
+ /**
76
+ * 组件的地址
77
+ */
78
+ this.#comUrls = [];
79
+ /**
80
+ * 指令的地址
81
+ */
82
+ this.#dirUrls = [];
83
+ this.#cssUrls = [];
84
+ /**
85
+ * 缓存的数据
86
+ */
87
+ this.#cacheObj = {};
88
+ /**
89
+ * 当前完整的地址
90
+ */
91
+ this.#curDir = "";
92
+ if (this.config.dir) {
93
+ this.config.dir = this.config.dir + "/";
94
+ this.config.dir = this.config.dir.replace(/\/\/$/, "/");
95
+ this.#curDir = resolve(process.cwd(), this.config.dir).replace(/\\/g, "/") + "/";
96
+ }
97
+ this.#getUrls();
98
+ }
99
+ /**
100
+ * 别名数组
101
+ */
102
+ #getNames() {
103
+ if (this.config.getAliass) return this.config.getAliass;
104
+ else return function(name, _type, c) {
105
+ const arr = getComponentNames(name);
106
+ if (c.alias) return [...getComponentNames(c.alias + "-" + name), ...arr];
107
+ else return arr;
108
+ };
109
+ }
110
+ #isMatchFile(url, arr, matchexts, nomatchexts) {
111
+ const is = isUrlsMatchi(url, arr, matchexts);
112
+ if (is && nomatchexts && nomatchexts.length > 0) if (matchsEnd(url, nomatchexts)) return false;
113
+ else return true;
114
+ else return is;
115
+ }
116
+ #isMatchDir(url) {
117
+ const is = matchsStart(url, this.config.matchs);
118
+ const nomatchs = this.config.nomatchs;
119
+ if (is && nomatchs && nomatchs.length > 0) if (matchsStart(url, nomatchs)) return false;
120
+ else return true;
121
+ else return is;
122
+ }
123
+ /**
124
+ * 读取url地址列表
125
+ */
126
+ #getUrls() {
127
+ const url = this.#getFgUrl();
128
+ const reg = new RegExp("^" + this.#curDir);
129
+ let isUrl = (key) => {
130
+ const uk = key.replace(reg, "");
131
+ return this.#isMatchDir(uk);
132
+ };
133
+ if (url) {
134
+ const globs = fastGlob.sync(url, {
135
+ onlyFiles: false,
136
+ absolute: true
137
+ }) || [];
138
+ this.#comUrls = globs.filter((key) => {
139
+ return isUrl(key);
140
+ });
141
+ }
142
+ if (this.config.directives) {
143
+ const durl = this.config.dir + "**/" + this.config.directives + "/**/*.{js,ts}";
144
+ const globs = fastGlob.sync(durl, {
145
+ onlyFiles: false,
146
+ absolute: true
147
+ }) || [];
148
+ this.#dirUrls = globs.filter((key) => {
149
+ return isUrl(key);
150
+ });
151
+ }
152
+ if (this.config.csss !== "") {
153
+ const cs = this.config.csssuffixs ?? ["css", "scss"];
154
+ let uf = cs.join();
155
+ if (cs.length > 1) uf = "{" + cs.join(",") + "}";
156
+ let curl = this.config.dir + "**/*." + uf;
157
+ if (this.config.csss) curl = this.config.dir + "**/" + this.config.csss + "/**/*." + uf;
158
+ const globs = fastGlob.sync(curl, {
159
+ onlyFiles: false,
160
+ absolute: true
161
+ }) || [];
162
+ this.#cssUrls = globs.filter((key) => {
163
+ return isUrl(key);
164
+ });
165
+ }
166
+ if (this.config.urlprefix) {
167
+ if (this.config.dir) {
168
+ const dir = this.config.dir;
169
+ const urls = [];
170
+ const dirUrls = [];
171
+ const cssUrls = [];
172
+ this.#comUrls?.forEach((key) => {
173
+ urls.push(key.replace(reg, dir));
174
+ });
175
+ this.#dirUrls?.forEach((key) => {
176
+ dirUrls.push(key.replace(reg, dir));
177
+ });
178
+ this.#cssUrls?.forEach((key) => {
179
+ cssUrls.push(key.replace(reg, dir));
180
+ });
181
+ /**
182
+ * 格式化的组件的地址
183
+ */
184
+ this.config.urls = urls;
185
+ /**
186
+ * 格式化的指令的地址
187
+ */
188
+ this.config.dirUrls = dirUrls;
189
+ /**
190
+ * 格式化的样式的地址
191
+ */
192
+ this.config.cssUrls = cssUrls;
193
+ }
194
+ }
195
+ }
196
+ /**
197
+ * 获取components 的匹配路径
198
+ * @returns { String } 匹配路径
199
+ */
200
+ #getFgUrl() {
201
+ if (this.config.extensions) {
202
+ if (this.config.extensions.length > 1) return this.config.dir + "**/*.{" + this.config.extensions.join(",") + "}";
203
+ else if (this.config.extensions.length == 1) return this.config.dir + "**/*." + this.config.extensions[0];
204
+ } else return this.config.dir + "**/*.*";
205
+ }
206
+ /**
207
+ * 获取当前缓存数
208
+ * @param {String} name 名称
209
+ * @param {String} type 类型
210
+ * @returns { Object } 注册的对象
211
+ */
212
+ #getCache(name, type) {
213
+ if (this.#cacheObj) return (this.#cacheObj[type] || {})[name];
214
+ }
215
+ /**
216
+ * 设置缓存数据
217
+ * @param {String} name 名称
218
+ * @param {String} type 类型
219
+ * @param { Object } 注册的对象
220
+ */
221
+ #setCache(name, type, obj) {
222
+ const cach = this.#cacheObj || {};
223
+ const co = cach[type] || {};
224
+ co[name] = obj;
225
+ cach[type] = co;
226
+ }
227
+ /**
228
+ * 是否要替换
229
+ * @param { String } name 名称
230
+ * @returns { Boolean } 是否要替换
231
+ */
232
+ #namefilter(name) {
233
+ name = humpToLine(name);
234
+ if (this.config.startss) for (let index = 0; index < this.config.startss.length; index++) {
235
+ const element = this.config.startss[index] + "-";
236
+ if (name.startsWith(element)) return false;
237
+ }
238
+ if (this.config.filtes) for (let index = 0; index < this.config.filtes.length; index++) {
239
+ const element = this.config.filtes[index];
240
+ if (name === element) return false;
241
+ }
242
+ return true;
243
+ }
244
+ /**
245
+ * 返回对应的值
246
+ * @param {String} from 文件地址
247
+ * @param {String} name 名称
248
+ * @param {String} type 类型
249
+ * @returns { Object } 注册的对象
250
+ */
251
+ #getNameFromUrl(from, name, type, sideEffects) {
252
+ let dname = "";
253
+ if (this.config.getFromName) dname = this.config.getFromName(from, name, type);
254
+ return {
255
+ name: dname || "default",
256
+ from,
257
+ sideEffects
258
+ };
259
+ }
260
+ /**
261
+ * 通过名称匹配对应路径
262
+ * @param {String} name 名称
263
+ * @param {String} type 类型
264
+ * @returns { Object } 注册的对象
265
+ */
266
+ #setNameFrom(name, type) {
267
+ const from = this.#getMatchUrl(name, type);
268
+ if (from) {
269
+ let sideEffects = void 0;
270
+ if (type == "component") sideEffects = this.#getMatchUrl(name, "sideEffects");
271
+ return this.#getNameFromUrl(from, name, type, sideEffects);
272
+ }
273
+ }
274
+ /**
275
+ * 匹配到url地址
276
+ * @param {string} arr 需要匹配的地址名称数组
277
+ * @param {String} type 类型
278
+ * @returns {Array} 匹配到的地址数组
279
+ */
280
+ #getUrlsMatchi(name, type) {
281
+ const arr = this.#getNames()(name, type, this.config);
282
+ const as = [];
283
+ if (type == "directive") {
284
+ const isMatchurl = this.config.isMatchDir;
285
+ if (isMatchurl) this.#dirUrls?.forEach((key) => {
286
+ if (isMatchurl(key, name, arr, this.config)) as.push(key);
287
+ });
288
+ else this.#dirUrls?.forEach((key) => {
289
+ if (this.#isMatchFile(key, arr, this.config.matchDirexts, this.config.nomatchDirexts)) as.push(key);
290
+ });
291
+ } else if (type == "sideEffects") {
292
+ const isMatchurl = this.config.isMatchCss;
293
+ if (isMatchurl) this.#dirUrls?.forEach((key) => {
294
+ if (isMatchurl(key, name, arr, this.config)) as.push(key);
295
+ });
296
+ else this.#cssUrls?.forEach((key) => {
297
+ if (this.#isMatchFile(key, arr, this.config.matchCsss, this.config.nomatchCsss)) as.push(key);
298
+ });
299
+ } else {
300
+ const isMatchurl = this.config.isMatch;
301
+ if (isMatchurl) this.#dirUrls?.forEach((key) => {
302
+ if (isMatchurl(key, name, arr, this.config)) as.push(key);
303
+ });
304
+ else this.#comUrls?.forEach((key) => {
305
+ if (this.#isMatchFile(key, arr, this.config.matchexts, this.config.nomatchexts)) as.push(key);
306
+ });
307
+ }
308
+ return as;
309
+ }
310
+ /**
311
+ * 获取对应的url
312
+ * @param {Array} urls 匹配到的地址数组
313
+ * @param {String} name 名称
314
+ * @param {String} type 类型
315
+ * @returns { String } 文件地址
316
+ */
317
+ #getCorrespondUrl(urls, name, type) {
318
+ const arr = this.#getNames()(name, type, this.config);
319
+ if (type == "directive") {
320
+ const vs = this.#dirUrls || [];
321
+ const getUrl = this.config.getMatchDirs;
322
+ if (getUrl) return getUrl(vs, name, type, this.config);
323
+ else {
324
+ const ms = [];
325
+ const m = this.config.matchDirextss;
326
+ if (m) ms.push(m);
327
+ return urls.filter((key) => {
328
+ return isUrlsMatchi(key, arr, ms);
329
+ })[0] || vs.filter((key) => {
330
+ return isUrlsMatchi(key, arr, ms);
331
+ })[0];
332
+ }
333
+ } else if (type == "sideEffects") {
334
+ const vs = this.#cssUrls || [];
335
+ const getUrl = this.config.getMatchCsss;
336
+ if (getUrl) return getUrl(vs, name, type, this.config);
337
+ else {
338
+ const ms = [];
339
+ const m = this.config.matchCssss;
340
+ if (m) ms.push(m);
341
+ return urls.filter((key) => {
342
+ return isUrlsMatchi(key, arr, ms);
343
+ })[0] || vs.filter((key) => {
344
+ return isUrlsMatchi(key, arr, ms);
345
+ })[0];
346
+ }
347
+ } else {
348
+ const vs = this.#comUrls || [];
349
+ const getUrl = this.config.getMatchs;
350
+ if (getUrl) return getUrl(vs, name, type, this.config);
351
+ else {
352
+ const ms = [];
353
+ const m = this.config.matchextss;
354
+ if (m) ms.push(m);
355
+ return urls.filter((key) => {
356
+ return isUrlsMatchi(key, arr, ms);
357
+ })[0] || vs.filter((key) => {
358
+ return isUrlsMatchi(key, arr, ms);
359
+ })[0];
360
+ }
361
+ }
362
+ }
363
+ /**
364
+ * 无前缀匹配
365
+ * @param {String} name 名称
366
+ * @param {String} type 类型
367
+ * @returns { String } 文件地址
368
+ */
369
+ #getMatchUrl(name, type) {
370
+ const urls = this.#getUrlsMatchi(name, type);
371
+ return this.#getCorrespondUrl(urls, name, type);
372
+ }
373
+ /**
374
+ * 输出日志
375
+ * @param name
376
+ * @param type
377
+ * @param obj
378
+ * @param is
379
+ */
380
+ #setLog(name, type, obj, is) {
381
+ if (this.config.log) {
382
+ const texts = {
383
+ component: 2,
384
+ directive: 4,
385
+ sideEffects: 5
386
+ };
387
+ const arr = [];
388
+ arr.push(styleLog("[@fangzhongya/vue-components]", { text: 3 }));
389
+ if (obj && obj.from) {
390
+ let sfrom = styleLog(obj?.from, {
391
+ text: 4,
392
+ revert: true
393
+ });
394
+ arr.push(styleLog(type, { text: texts[type] }));
395
+ arr.push(styleLog(name, { bold: true }));
396
+ if (!is) sfrom = styleLog("+", { text: 2 }) + sfrom;
397
+ arr.push(sfrom);
398
+ if (obj.sideEffects) arr.push(styleLog(obj.sideEffects.toString(), { text: texts["sideEffects"] }));
399
+ } else {
400
+ arr.push(styleLog(type, { text: texts[type] }));
401
+ arr.push(styleLog(name, {
402
+ bold: true,
403
+ text: 1
404
+ }));
405
+ }
406
+ console.log(arr.join(" "));
407
+ }
408
+ }
409
+ /**
410
+ * 自动按需匹配注册
411
+ * @param {String} name 名称
412
+ * @param {String} type 类型
413
+ * @returns { Object } 注册的对象
414
+ */
415
+ resolve(name, type) {
416
+ const cache = this.#getCache(name, type);
417
+ if (this.config.isCache && cache) {
418
+ this.#setLog(name, type, cache, true);
419
+ return cache;
420
+ } else if (this.#namefilter(name)) {
421
+ let obj = this.#setNameFrom(name, type);
422
+ if (obj) {
423
+ this.#setLog(name, type, obj);
424
+ this.#setCache(name, type, obj);
425
+ return obj;
426
+ }
427
+ }
428
+ }
429
+ };
430
+ //#endregion
431
+ export { FangComponent as t };