@fangzhongya/icons 0.0.14 → 0.0.16

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.
@@ -1,921 +1,32 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-75ZPJI57.cjs');
2
-
3
- // node_modules/.pnpm/@fangzhongya+create@0.2.49/node_modules/@fangzhongya/create/dist/chunk-4CBOJSDB.js
4
- function getStartSames(str, val) {
5
- let s = "";
6
- const vs = [...val];
7
- let index = 0;
8
- for (; index < vs.length; index++) {
9
- const element = vs[index];
10
- if (element === str.charAt(index)) {
11
- s += element;
12
- } else {
13
- break;
14
- }
15
- }
16
- return [s, str.substring(index), val.substring(index)];
17
- }
18
- function getImportUrl(url, imp) {
19
- const arr = getStartSames(url, imp);
20
- const ts = arr[0];
21
- if (!/[\\|\/]$/.test(ts)) {
22
- const regs = ts.match(/[\\|\/]([^\\|\/]*)$/);
23
- if (regs && regs.length > 0) {
24
- const a = regs[1];
25
- arr[0] = ts.substring(0, regs.index + 1);
26
- arr[1] = a + arr[1];
27
- arr[2] = a + arr[2];
28
- }
29
- }
30
- const l = arr[1].split(/\\|\//).length - 1;
31
- let ds = ["./"];
32
- if (l > 0) {
33
- ds = [];
34
- for (let index = 0; index < l; index++) {
35
- ds.push("../");
36
- }
37
- }
38
- return ds.join("") + arr[2].replace(/\\/g, "/");
39
- }
40
-
41
- // node_modules/.pnpm/@fangzhongya+create@0.2.49/node_modules/@fangzhongya/create/dist/chunk-3GUX6LOY.js
42
- function getImportUrlSuffix(url, imp) {
43
- return getImportUrl(url, imp).replace(/\.([a-z|A-Z][a-z|A-Z|0-9]*)$/, "");
44
- }
45
-
46
- // node_modules/.pnpm/@fangzhongya+create@0.2.49/node_modules/@fangzhongya/create/dist/chunk-I5KYQX4M.js
47
-
48
-
49
-
50
-
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
51
2
 
3
+ var _chunkV6F7B2R3cjs = require('../chunk-V6F7B2R3.cjs');
52
4
 
53
5
 
54
6
 
7
+ var _chunkOSHAEKZLcjs = require('../chunk-OSHAEKZL.cjs');
8
+ require('../chunk-IIVF4KK5.cjs');
55
9
 
56
10
 
57
-
58
- var _fs = require('fs');
59
- var _path = require('path');
60
- function getUrlCatalogueObj(str) {
61
- const reg = /(\\|\/)([^\\|\/]+)\.([a-z|A-Z][a-z|A-Z|0-9]*)$/g;
62
- const ml = str.replace(reg, "");
63
- let name = "";
64
- let suffix = "";
65
- let apart = "";
66
- const arr = reg.exec(str);
67
- if (arr) {
68
- apart = arr[1];
69
- name = arr[2];
70
- suffix = arr[3];
71
- }
72
- return {
73
- catalogue: ml,
74
- name,
75
- suffix,
76
- apart
77
- };
78
- }
79
- function getNewFileName(url) {
80
- const obj = getUrlCatalogueObj(url);
81
- let wb = obj.name;
82
- if (wb) {
83
- const reg = /([0-9]+)$/g;
84
- const regs = reg.exec(wb);
85
- if (regs && regs.length > 0) {
86
- const sl = Number(regs[1]) + 1;
87
- const reg1 = new RegExp(regs[1] + "$");
88
- wb = wb.replace(reg1, (sl + "").padStart(regs[1].length, "0"));
89
- } else {
90
- wb = wb + "1";
91
- }
92
- return obj.catalogue + obj.apart + wb + "." + obj.suffix;
93
- } else {
94
- return "";
95
- }
96
- }
97
- function fsReadFile(url, type) {
98
- if (!type || type === true) {
99
- type = "utf-8";
100
- }
101
- return new Promise((resolve3, reject) => {
102
- _fs.readFile.call(void 0, url, type, (err, dataStr) => {
103
- if (err) {
104
- console.log("2", err);
105
- reject("");
106
- } else {
107
- resolve3(dataStr);
108
- }
109
- });
110
- });
111
- }
112
- function fsCreateReadStream(url, type) {
113
- if (!type || type === true) {
114
- type = "utf-8";
115
- }
116
- return new Promise((resolve3) => {
117
- const stream = _fs.createReadStream.call(void 0, url, {
118
- start: 0,
119
- end: 100,
120
- encoding: type
121
- });
122
- let st = "";
123
- stream.on("data", (data) => {
124
- st += data;
125
- });
126
- stream.on("end", () => {
127
- resolve3(st);
128
- });
129
- stream.on("error", () => {
130
- resolve3("");
131
- });
132
- });
133
- }
134
- function fsAccess(reaPath) {
135
- return new Promise((resolve3) => {
136
- try {
137
- _fs.access.call(void 0, reaPath, _fs.constants.F_OK, (err) => {
138
- if (err) {
139
- resolve3(false);
140
- } else {
141
- resolve3(true);
142
- }
143
- });
144
- } catch (e) {
145
- resolve3(false);
146
- }
147
- });
148
- }
149
- function fsReaddir(filePath) {
150
- return new Promise((resolve3, reject) => {
151
- _fs.readdir.call(void 0, filePath, (err, files) => {
152
- if (err) {
153
- reject(err);
154
- } else {
155
- const lg = files.length;
156
- const dirs = [];
157
- const file = [];
158
- if (lg) {
159
- let i = 0;
160
- files.forEach((filename) => {
161
- const filedir = _path.join.call(void 0, filePath, filename);
162
- _fs.stat.call(void 0, filedir, (err2, stats) => {
163
- i++;
164
- if (err2) {
165
- console.log("4", err2);
166
- } else {
167
- const isFile = stats.isFile();
168
- const isDir = stats.isDirectory();
169
- if (isFile) {
170
- file.push(filename);
171
- }
172
- if (isDir) {
173
- dirs.push(filename);
174
- }
175
- }
176
- if (i >= lg) {
177
- resolve3({
178
- file,
179
- dirs
180
- });
181
- }
182
- });
183
- });
184
- } else {
185
- resolve3({
186
- file,
187
- dirs
188
- });
189
- }
190
- }
191
- });
192
- });
193
- }
194
- function fsOpenStream(path, json, type = 0, cover, callback) {
195
- _fs.open.call(void 0, path, "wx", async (err, fd) => {
196
- if (err) {
197
- if (err.code === "EEXIST") {
198
- if (type == 1 || type == 0) {
199
- const fwrite = () => {
200
- _fs.writeFile.call(void 0, path, json, "utf-8", (err2) => {
201
- if (err2) {
202
- console.log("6", err2);
203
- if (callback) {
204
- callback(path, cover ? 3 : 2, false, type);
205
- }
206
- } else {
207
- if (callback) {
208
- callback(path, cover ? 3 : 2, true, type);
209
- }
210
- }
211
- });
212
- };
213
- if (cover) {
214
- const st = await fsCreateReadStream(path);
215
- if (!st.includes("@config cover=true")) {
216
- fwrite();
217
- } else {
218
- if (callback) callback(path, 3, false, type);
219
- }
220
- } else {
221
- fwrite();
222
- }
223
- } else if (type == 3) {
224
- path = getNewFileName(path);
225
- if (path) {
226
- fsOpenStream(path, json, type, cover, callback);
227
- } else {
228
- if (callback) {
229
- callback(path, 3, false, type);
230
- }
231
- }
232
- } else {
233
- if (callback) {
234
- callback(path, 2, false, type);
235
- }
236
- }
237
- } else {
238
- if (callback) {
239
- callback(path, 0, false, type);
240
- }
241
- }
242
- } else {
243
- if (type != 1) {
244
- _fs.write.call(void 0, fd, json, (err2) => {
245
- if (err2) {
246
- console.log("8", err2);
247
- if (callback) {
248
- callback(path, 1, false, type);
249
- }
250
- } else {
251
- if (callback) {
252
- callback(path, 1, true, type);
253
- }
254
- }
255
- });
256
- } else {
257
- if (callback) {
258
- callback(path, 1, false, type);
259
- }
260
- }
261
- }
262
- });
263
- }
264
- function fsMkdir(reaPath, callback) {
265
- _fs.mkdir.call(void 0, reaPath, { recursive: true }, (err, path) => {
266
- if (err) {
267
- console.log("0", err);
268
- if (callback) {
269
- callback(reaPath, false);
270
- }
271
- } else {
272
- if (callback) {
273
- callback(reaPath, true, path);
274
- }
275
- }
276
- });
277
- }
278
- function writeInit(url, callback, isDirs, isFile, issynch) {
279
- return new Promise(async (resolve3) => {
280
- if (url) {
281
- const data = await fsReaddir(url);
282
- const arr = await writeFileUrl(
283
- url,
284
- data,
285
- callback,
286
- isDirs,
287
- isFile,
288
- issynch
289
- );
290
- resolve3(arr);
291
- } else {
292
- resolve3([]);
293
- }
294
- });
295
- }
296
- function writeFileUrl(url, files, callback, isDirs, isFile, issynch) {
297
- return new Promise(async (resolve3) => {
298
- const arr = [];
299
- const dirs = [];
300
- if (files.dirs.length > 0) {
301
- for (let i = 0; i < files.dirs.length; i++) {
302
- const dir = files.dirs[i];
303
- let is = true;
304
- if (isDirs) {
305
- is = isDirs(url, dir);
306
- }
307
- if (is) {
308
- dirs.push(dir);
309
- const urls = await writeInit(
310
- _path.join.call(void 0, url, dir),
311
- callback,
312
- isDirs,
313
- isFile,
314
- issynch
315
- );
316
- arr.push(...urls);
317
- }
318
- }
319
- }
320
- files.dirs = dirs;
321
- const file = [];
322
- if (files.file.length > 0) {
323
- files.file.forEach((name) => {
324
- let is = true;
325
- if (isFile) {
326
- is = isFile(url, name);
327
- }
328
- if (is) {
329
- file.push(name);
330
- arr.push(_path.join.call(void 0, url, name));
331
- }
332
- });
333
- }
334
- files.file = file;
335
- if (callback) {
336
- if (issynch) {
337
- await callback(url, files, arr);
338
- } else {
339
- callback(url, files, arr);
340
- }
341
- }
342
- resolve3(arr);
343
- });
344
- }
345
-
346
- // node_modules/.pnpm/@fangzhongya+create@0.2.49/node_modules/@fangzhongya/create/dist/chunk-FWEGYLR7.js
347
-
348
- function styleLog(msg = "", obj) {
349
- const arr = ["\x1B[0m"];
350
- if (obj == null ? void 0 : obj.revert) {
351
- arr.push("\x1B[4m");
352
- }
353
- if (obj == null ? void 0 : obj.lineThrough) {
354
- arr.push("\x1B[9m");
355
- }
356
- if (obj == null ? void 0 : obj.italic) {
357
- arr.push("\x1B[3m");
358
- }
359
- if (obj == null ? void 0 : obj.bold) {
360
- arr.push("\x1B[1m");
361
- }
362
- if (obj == null ? void 0 : obj.bag) {
363
- arr.push(`\x1B[4${obj == null ? void 0 : obj.bag}m`);
364
- } else {
365
- arr.push("\x1B[40m");
366
- }
367
- if (obj == null ? void 0 : obj.text) {
368
- arr.push(`\x1B[3${obj == null ? void 0 : obj.text}m`);
369
- } else {
370
- arr.push("\x1B[30m");
371
- }
372
- arr.push(msg);
373
- arr.push("\x1B[0m");
374
- return arr.join("");
375
- }
376
- function getSuffix(url) {
377
- const reg = /\.([a-z|A-Z][a-z|A-Z|0-9]*)$/;
378
- const regs = reg.exec(url);
379
- if (regs && regs.length > 0) {
380
- return regs[1];
381
- }
382
- return "";
383
- }
384
- function matchsEnd(key, matchs) {
385
- if (matchs && matchs.length > 0) {
386
- for (const value of matchs) {
387
- if (typeof value == "string") {
388
- if (key.endsWith(value)) {
389
- return true;
390
- }
391
- } else {
392
- if (value.test(key)) {
393
- return true;
394
- }
395
- }
396
- }
397
- return false;
398
- } else {
399
- return true;
400
- }
401
- }
402
- function matchsStart(key, matchs) {
403
- if (matchs && matchs.length > 0) {
404
- for (const value of matchs) {
405
- if (typeof value == "string") {
406
- if (key.startsWith(value)) {
407
- return true;
408
- }
409
- } else {
410
- if (value.test(key)) {
411
- return true;
412
- }
413
- }
414
- }
415
- return false;
416
- } else {
417
- return true;
418
- }
419
- }
420
- function getUrlCatalogue(str) {
421
- const reg = /((\\|\/)([^\\|\/]+)(\.[a-z|A-Z][a-z|A-Z|0-9]*))?$/g;
422
- return str.replace(reg, "");
423
- }
424
- var defaultSuffixReg = /\\.[a-z|A-Z]+$/;
425
- var defaultConfig = {
426
- name: "com",
427
- /**
428
- * 打包的文件地址
429
- */
430
- dir: "./packages/",
431
- /**
432
- * 文件后缀
433
- */
434
- extensions: ["js", "ts"],
435
- suffixReg: defaultSuffixReg,
436
- fileTongre: false,
437
- /**
438
- * 是否替换文件
439
- */
440
- fileCover: false,
441
- /**
442
- * 判断当前文件100个字节内存在 @config cover=true 就不写入
443
- */
444
- coverConfig: false,
445
- /**
446
- * 写入注释
447
- */
448
- writeNotes: false,
449
- /**
450
- * 读取当前文件,文件的编码类型,默认utf-8
451
- */
452
- read: false,
453
- /**
454
- * 匹配目录数组
455
- * 从头开始匹配
456
- */
457
- matchs: [],
458
- /**
459
- * 匹配文件路径
460
- * 从尾部开始匹配
461
- */
462
- matchexts: [],
463
- forceUpdate: [],
464
- /**
465
- * 不匹配目录数组
466
- * 从头开始匹配
467
- */
468
- nomatchs: [],
469
- /**
470
- * 不匹配文件路径
471
- * 从尾部开始匹配
472
- */
473
- nomatchexts: [],
474
- issort: false,
475
- issynch: false
476
- };
477
- function getSuffixReg(ex = []) {
478
- if (ex.length == 0) {
479
- return defaultSuffixReg;
480
- }
481
- return new RegExp(`\\.(${ex.join("|")})$`);
482
- }
483
- var FangCom = class {
484
-
485
-
486
-
487
- constructor(config, callback) {
488
- this.config = {};
489
- this._configCallback = callback;
490
- this._defaultConfig = defaultConfig;
491
- this.initConfig(config);
492
- }
493
- async runDev(callback, configCallback, config, nosort) {
494
- this.initConfig(config);
495
- const call = configCallback || this._configCallback;
496
- if (call) {
497
- const c = call(this.config);
498
- if (c) {
499
- this.initConfig(c);
500
- }
501
- }
502
- return await this.handle(callback, nosort);
503
- }
504
- /**
505
- * 初始化
506
- * @param config
507
- * @returns
508
- */
509
- initConfig(config) {
510
- if (config) {
511
- this.config = config;
512
- this.setDefaultConfig();
513
- this.config.suffixReg = getSuffixReg(this.config.extensions);
514
- if (!this.config.matchexts || this.config.matchexts.length == 0) {
515
- this.config.matchexts = [this.config.suffixReg];
516
- }
517
- }
518
- return this.config;
519
- }
520
- setDefaultConfig() {
521
- Object.keys(this._defaultConfig).forEach((key) => {
522
- if (typeof this.config[key] == "undefined") {
523
- this.config[key] = this._defaultConfig[key];
524
- }
525
- });
526
- }
527
- getFileName(name) {
528
- if (this.config.suffixReg) {
529
- return name.replace(this.config.suffixReg, "");
530
- } else {
531
- return name.replace(defaultSuffixReg, "");
532
- }
533
- }
534
- /**
535
- * 获取当前位置
536
- * @param dir
537
- * @returns
538
- */
539
- getDirUrl(dir) {
540
- const str = dir || this.config.dir;
541
- if (str) {
542
- return _path.resolve.call(void 0, process.cwd(), str);
543
- } else {
544
- return "";
545
- }
546
- }
547
- isForceUpdate(url) {
548
- if (this.config.forceUpdate && this.config.forceUpdate.length > 0) {
549
- return matchsEnd(url.replace(/\\/g, "/"), this.config.forceUpdate);
550
- } else {
551
- return false;
552
- }
553
- }
554
- isMatchFile(url, name) {
555
- const dirUrl = this.getDirUrl();
556
- const dir = _path.join.call(void 0, url, name).replace(dirUrl, "").replace(/\\/g, "/");
557
- const is = matchsEnd(dir, this.config.matchexts);
558
- const nomatchexts = this.config.nomatchexts;
559
- if (is && nomatchexts && nomatchexts.length > 0) {
560
- if (matchsEnd(dir, nomatchexts)) {
561
- return false;
562
- } else {
563
- return true;
564
- }
565
- } else {
566
- return is;
567
- }
568
- }
569
- isMatchDir(url, name) {
570
- const dirUrl = this.getDirUrl();
571
- const dir = _path.join.call(void 0, url, name).replace(dirUrl, "").replace(/\\/g, "/");
572
- const is = matchsStart(dir, this.config.matchs);
573
- const nomatchs = this.config.nomatchs;
574
- if (is && nomatchs && nomatchs.length > 0) {
575
- if (matchsStart(dir, nomatchs)) {
576
- return false;
577
- } else {
578
- return true;
579
- }
580
- } else {
581
- return is;
582
- }
583
- }
584
- /**
585
- * 处理方法
586
- * @param callback
587
- */
588
- handle(callback, nosort) {
589
- return new Promise(async (resolve22) => {
590
- const url = this.getDirUrl();
591
- if (url) {
592
- const rarr = await writeInit(
593
- url,
594
- async (...arr) => {
595
- if (callback) {
596
- await callback(...arr);
597
- }
598
- return await this.writeCallback(...arr, nosort);
599
- },
600
- (...arr) => {
601
- return this.isMatchDir(...arr);
602
- },
603
- (...arr) => {
604
- return this.isMatchFile(...arr);
605
- },
606
- this.config.issynch
607
- );
608
- resolve22(rarr);
609
- } else {
610
- resolve22([]);
611
- }
612
- });
613
- }
614
- getFileNotes(url) {
615
- const suffix = getSuffix(url);
616
- const sz = [
617
- `@config cover=false`,
618
- `cover \u662F\u5426\u8986\u76D6\u5F53\u524D\u6587\u4EF6\uFF0C\u9ED8\u8BA4\u662Ffalse\uFF0C true \u8868\u793A\u4E0D\u8986\u76D6`,
619
- `\u5F53\u524D\u5DF2\u7ECF\u7531@fangzhongya/create\u81EA\u52A8\u751F\u6210`,
620
- `${(/* @__PURE__ */ new Date()).toString()}`
621
- ];
622
- const hy = ["md", "html", "vue"];
623
- if (hy.includes(suffix)) {
624
- const arr = ["<!--"];
625
- sz.forEach((v) => {
626
- arr.push(" - " + v);
627
- });
628
- arr.push("-->");
629
- return arr;
630
- } else {
631
- const arr = ["/**"];
632
- sz.forEach((v) => {
633
- arr.push(" * " + v);
634
- });
635
- arr.push(" */");
636
- return arr;
637
- }
638
- }
639
- /**
640
- * 输出文件,判断目录是否存在
641
- * @param url
642
- * @param sts
643
- */
644
- fileOpen(url, sts, fileUrls, type) {
645
- fsMkdir(getUrlCatalogue(url), (reaPath, is, ml) => {
646
- const logs = this.getLogs();
647
- logs.push(styleLog("dir", {}));
648
- if (is) {
649
- if (ml) {
650
- logs.push(
651
- styleLog("add", {
652
- text: 2,
653
- italic: true
654
- })
655
- );
656
- logs.push(
657
- styleLog(reaPath, {
658
- text: 2,
659
- revert: true
660
- })
661
- );
662
- console.log(logs.join(" "));
663
- }
664
- } else {
665
- logs.push(
666
- styleLog(reaPath, {
667
- text: 1,
668
- revert: true
669
- })
670
- );
671
- console.log(logs.join(" "));
672
- }
673
- this.setOpen(url, sts, type, (kurl, _type, is2, _tn) => {
674
- if (is2 && fileUrls) {
675
- fileUrls.push(kurl);
676
- }
677
- });
678
- });
679
- }
680
- /**
681
- * 输出文件
682
- * @param url
683
- * @param str
684
- * @param callback
685
- */
686
- setOpen(url, str, type, callback) {
687
- let tn = this.config.fileTongre ? 3 : 2;
688
- if (this.config.fileCover) {
689
- tn = 0;
690
- }
691
- if (tn == 2) {
692
- if (this.isForceUpdate(url)) {
693
- tn = 0;
694
- }
695
- }
696
- if (typeof type != "undefined") {
697
- tn = type;
698
- }
699
- if (this.config.writeNotes && !/\.json$/.test(url)) {
700
- str = this.getFileNotes(url).join("\n") + "\n" + str;
701
- }
702
- fsOpenStream(
703
- url,
704
- str,
705
- tn,
706
- this.config.coverConfig,
707
- (kurl, type2, is) => {
708
- if (!(tn == 2 && type2 == 2)) {
709
- const logs = this.getLogs();
710
- logs.push(styleLog("file", {}));
711
- if (type2 == 1) {
712
- logs.push(
713
- styleLog("add", {
714
- text: 2,
715
- italic: true
716
- })
717
- );
718
- } else if (type2 == 2) {
719
- logs.push(
720
- styleLog("update", {
721
- italic: true,
722
- text: 4
723
- })
724
- );
725
- }
726
- if (is) {
727
- logs.push(
728
- styleLog(kurl, {
729
- text: 2,
730
- revert: true
731
- })
732
- );
733
- } else {
734
- logs.push(
735
- styleLog(kurl, {
736
- text: 1,
737
- revert: true
738
- })
739
- );
740
- }
741
- console.log(logs.join(" "));
742
- }
743
- if (callback) {
744
- callback(kurl, type2, is, tn);
745
- }
746
- }
747
- );
748
- }
749
- /**
750
- * 获取日志头
751
- */
752
- getLogs() {
753
- const logs = [];
754
- logs.push(
755
- styleLog("[@fangzhongya/create]", {
756
- text: 3
757
- })
758
- );
759
- logs.push(
760
- styleLog(this._defaultConfig.name, {
761
- text: 4
762
- })
763
- );
764
- return logs;
765
- }
766
- };
767
-
768
- // node_modules/.pnpm/@fangzhongya+create@0.2.49/node_modules/@fangzhongya/create/dist/chunk-IMEZSVK5.js
769
-
770
- var defaultConfig2 = Object.assign({}, defaultConfig, {
771
- name: "file",
772
- /**
773
- * 生成的文件名称
774
- */
775
- gene: void 0,
776
- /**
777
- * 文件生成方法
778
- */
779
- fileSet: void 0
780
- });
781
- var FangFile = class extends FangCom {
782
- constructor(config, callback) {
783
- super();
784
- this.config = {};
785
- this._configCallback = callback;
786
- this._defaultConfig = defaultConfig2;
787
- this.initConfig(config || this.config);
788
- }
789
- getDefaultGene(name, url, _wj) {
790
- return _path.join.call(void 0, url, name);
791
- }
792
- getDefaultFileSet(_name, _url, _text, _wjm, _imp, _surl) {
793
- return [];
794
- }
795
- getGeneObj(url, name, outDir) {
796
- return getUrlCatalogueObj(
797
- _path.join.call(void 0,
798
- _path.resolve.call(void 0, process.cwd(), outDir),
799
- _path.join.call(void 0, url, name).replace(this.getDirUrl(), "")
800
- )
801
- );
802
- }
803
- /**
804
- * 获取输出地址方法
805
- * @param gene
806
- * @returns
807
- */
808
- getGene(gene) {
809
- gene = gene || this.config.gene;
810
- if (!gene) {
811
- return (...arr) => {
812
- return this.getDefaultGene(...arr);
813
- };
814
- } else {
815
- return gene;
816
- }
817
- }
818
- fileRead(url, type) {
819
- return new Promise((resolve22) => {
820
- fsAccess(url).then(() => {
821
- resolve22(fsReadFile(url, type));
822
- });
823
- });
824
- }
825
- getFileSet(fileSet) {
826
- fileSet = fileSet || this.config.fileSet;
827
- if (!fileSet) {
828
- return (...arr) => {
829
- return this.getDefaultFileSet(...arr);
830
- };
831
- } else {
832
- return fileSet;
833
- }
834
- }
835
- /**
836
- * 回调方法
837
- * @param url
838
- * @param file
839
- * @param urls
840
- */
841
- async writeCallback(url, readdir2, fileUrls) {
842
- const gene = this.getGene();
843
- const fileSet = this.getFileSet();
844
- const read = this.config.read;
845
- if (readdir2.file) {
846
- for (let i = 0; i < readdir2.file.length; i++) {
847
- const name = readdir2.file[i];
848
- const furl = _path.join.call(void 0, url, name);
849
- const wjmc = this.getFileName(name);
850
- const gu = gene(name, url, wjmc);
851
- const imp = getImportUrlSuffix(gu, furl);
852
- const arr = [];
853
- if (fileSet) {
854
- let text = "";
855
- if (read) {
856
- text = await fsReadFile(furl, read);
857
- }
858
- arr.push(...fileSet(name, url, text, wjmc, imp, gu));
859
- }
860
- if (arr.length > 0) {
861
- this.fileOpen(gu, arr.join("\n"), fileUrls);
862
- }
863
- }
864
- }
865
- return true;
866
- }
867
- };
868
-
869
- // node_modules/.pnpm/@fangzhongya+create@0.2.49/node_modules/@fangzhongya/create/dist/chunk-3VPCYJWK.js
870
-
871
- var defaultConfig22 = Object.assign({}, defaultConfig2, {
872
- name: "out",
873
- outDir: "./",
874
- isNeader: true
875
- });
876
- var FangOut = class extends FangFile {
877
- constructor(config, callback) {
878
- super();
879
- this.config = {};
880
- this._configCallback = callback;
881
- this._defaultConfig = defaultConfig22;
882
- this.initConfig(config || this.config);
883
- }
884
- getFileNeader(name, url) {
885
- return [`/**`, ` * ${_path.join.call(void 0, url, name).replace(/\\/g, "/")}`, " */"];
886
- }
887
- /**
888
- * 获取输出地址方法
889
- * @param gene
890
- * @returns
891
- */
892
- getDefaultGene(name, url, _wj) {
893
- const obj = this.getGeneObj(url, name, this.config.outDir);
894
- return _path.join.call(void 0, obj.catalogue, obj.name + "." + obj.suffix);
895
- }
896
- getDefaultFileSet(name, url, text, _wjm, _imp) {
897
- const arr = [text];
898
- if (this.config.isNeader) {
899
- return [...this.getFileNeader(name, url), ...arr];
900
- }
901
- return arr;
902
- }
903
- };
904
- function runDev(config, configCallback, callback) {
905
- const fang = new FangOut(config);
906
- fang.runDev(callback, configCallback);
907
- }
11
+ var _chunk5NH4G6UJcjs = require('../chunk-5NH4G6UJ.cjs');
12
+ require('../chunk-75ZPJI57.cjs');
908
13
 
909
14
  // packages/vite/index.ts
910
-
15
+ var _path = require('path');
911
16
  var virtualModuleId = "virtual:fang-icon";
912
17
  function simpleFangIcon(options = {}) {
913
- const { name = "FangIcon", type = "svg", directory = "./svg" } = options;
18
+ const {
19
+ name = "FangIcon",
20
+ type = "svg",
21
+ directory = "./svg",
22
+ dynamic = true,
23
+ customReplacement
24
+ } = options;
914
25
  const resolvedVirtualModuleId = "\0" + virtualModuleId;
915
26
  if (type === "pub" && options.mobile) {
916
27
  const outDir = _path.join.call(void 0, "./public/", directory);
917
28
  console.log("outDir", outDir);
918
- runDev({
29
+ _chunkV6F7B2R3cjs.runDev.call(void 0, {
919
30
  issort: true,
920
31
  dir: "./node_modules/@fangzhongya/icons/dist/svg",
921
32
  outDir,
@@ -925,6 +36,7 @@ function simpleFangIcon(options = {}) {
925
36
  isNeader: false
926
37
  });
927
38
  }
39
+ const targetComponents = Array.isArray(name) ? name : [name];
928
40
  const pub = `
929
41
  import { defineComponent, h,} from 'vue'
930
42
  import FangIcon from '@fangzhongya/icons/icon/index'
@@ -963,7 +75,7 @@ export default component;`;
963
75
  const svg = `
964
76
  import { defineComponent, h, computed} from 'vue'
965
77
  import FangIcon from '@fangzhongya/icons/icon/index'
966
- import { icons } from '@fangzhongya/icons/vue'
78
+ import icons from '@fangzhongya/icons/async'
967
79
  const component = defineComponent({
968
80
  name: '${name}',
969
81
  props: {
@@ -986,7 +98,7 @@ const component = defineComponent({
986
98
  const iconName = computed(() => {
987
99
  const name = props.name;
988
100
  if (typeof name === 'string' && (props.type === 'svg' ||
989
- (props.type === undefined && props.default === 'svg'))) {
101
+ (!props.type && props.default === 'svg'))) {
990
102
  const icon = icons[name];
991
103
  if(icon){
992
104
  return icon;
@@ -1025,9 +137,199 @@ export default component;`;
1025
137
  return text;
1026
138
  }
1027
139
  return null;
140
+ },
141
+ // 使用 enforce 确保在 Vue 插件之前执行
142
+ enforce: "pre",
143
+ // 转换代码
144
+ transform(code, id) {
145
+ if (!shouldProcess(id)) {
146
+ return null;
147
+ }
148
+ try {
149
+ const components = findComponents(code, targetComponents);
150
+ if (components.length === 0) {
151
+ return null;
152
+ }
153
+ let transformedCode = code;
154
+ let replacedCount = 0;
155
+ const imports = /* @__PURE__ */ new Set();
156
+ for (let i = components.length - 1; i >= 0; i--) {
157
+ const component = components[i];
158
+ if (component) {
159
+ const { text: text2, imptext } = replaceComponent(
160
+ component,
161
+ type,
162
+ dynamic,
163
+ customReplacement
164
+ );
165
+ imports.add(imptext);
166
+ if (text2 !== component.fullMatch) {
167
+ transformedCode = transformedCode.slice(0, component.start) + text2 + transformedCode.slice(component.end);
168
+ replacedCount++;
169
+ }
170
+ }
171
+ }
172
+ if (/.vue$/.test(id)) {
173
+ const i = transformedCode.indexOf("</script>");
174
+ transformedCode = transformedCode.slice(0, i) + [...imports].join(";") + transformedCode.slice(i);
175
+ } else {
176
+ transformedCode = [...imports].join(";") + transformedCode;
177
+ }
178
+ if (replacedCount > 0) {
179
+ return {
180
+ code: transformedCode,
181
+ map: null
182
+ };
183
+ }
184
+ } catch (error) {
185
+ console.error(`\u5904\u7406\u6587\u4EF6 ${id} \u65F6\u51FA\u9519:`, error);
186
+ }
187
+ return null;
188
+ },
189
+ // 处理热更新
190
+ handleHotUpdate({
191
+ file,
192
+ server
193
+ }) {
194
+ if (shouldProcess(file)) {
195
+ server.ws.send({
196
+ type: "full-reload"
197
+ });
198
+ return [];
199
+ }
200
+ }
201
+ };
202
+ }
203
+ function parseAttributes(attrString) {
204
+ const attributes = { name: "" };
205
+ const attrRegex = /(?:@|:|v-bind:)?([\w-]+)(?:="([^"]*)"|='([^']*)')/g;
206
+ let match;
207
+ while ((match = attrRegex.exec(attrString)) !== null) {
208
+ const name = match[1];
209
+ if (name) {
210
+ const value = match[2] || match[3] || "";
211
+ if (name === "name") {
212
+ attributes.name = value;
213
+ } else if (value === "true" || value === "false") {
214
+ attributes[name] = value === "true";
215
+ } else if (!isNaN(Number(value)) && value !== "") {
216
+ attributes[name] = Number(value);
217
+ } else {
218
+ attributes[name] = value;
219
+ }
220
+ }
221
+ }
222
+ return attributes;
223
+ }
224
+ function hasStringNameAttribute(attrString) {
225
+ const nameRegex = /(?:^|\s)name="[^"]*"/i;
226
+ const singleQuoteRegex = /(?:^|\s)name='[^']*'/i;
227
+ return nameRegex.test(attrString) || singleQuoteRegex.test(attrString);
228
+ }
229
+ function isOnlyWhitespace(content) {
230
+ return !content || /^\s*$/.test(content);
231
+ }
232
+ function findComponents(code, name) {
233
+ const components = [];
234
+ for (const componentName of name) {
235
+ let currentIndex = 0;
236
+ while (currentIndex < code.length) {
237
+ const startTagIndex = code.indexOf(
238
+ `<${componentName}`,
239
+ currentIndex
240
+ );
241
+ if (startTagIndex === -1) break;
242
+ let tagEndIndex = code.indexOf(">", startTagIndex);
243
+ if (tagEndIndex === -1) break;
244
+ const startTag = code.slice(startTagIndex, tagEndIndex + 1);
245
+ const attrString = startTag.slice(componentName.length + 1, -1).trim();
246
+ if (!hasStringNameAttribute(attrString)) {
247
+ currentIndex = startTagIndex + 1;
248
+ continue;
249
+ }
250
+ const attributes = parseAttributes(attrString);
251
+ if (!attributes.name) {
252
+ currentIndex = startTagIndex + 1;
253
+ continue;
254
+ }
255
+ const isSelfClosing = startTag.endsWith("/>");
256
+ let endIndex;
257
+ let fullMatch;
258
+ if (isSelfClosing) {
259
+ endIndex = tagEndIndex + 1;
260
+ fullMatch = startTag;
261
+ } else {
262
+ const endTag = `</${componentName}>`;
263
+ let endTagIndex = code.indexOf(endTag, tagEndIndex + 1);
264
+ if (endTagIndex === -1) {
265
+ currentIndex = startTagIndex + 1;
266
+ continue;
267
+ }
268
+ const content = code.slice(tagEndIndex + 1, endTagIndex);
269
+ if (!isOnlyWhitespace(content)) {
270
+ currentIndex = startTagIndex + 1;
271
+ continue;
272
+ }
273
+ endIndex = endTagIndex + endTag.length;
274
+ fullMatch = code.slice(startTagIndex, endIndex);
275
+ }
276
+ components.push({
277
+ componentName,
278
+ fullMatch,
279
+ start: startTagIndex,
280
+ end: endIndex,
281
+ attributes,
282
+ isSelfClosing
283
+ });
284
+ currentIndex = endIndex;
1028
285
  }
286
+ }
287
+ return components;
288
+ }
289
+ function getText(iconName, match) {
290
+ const svg = _chunkOSHAEKZLcjs.getIconifySVG.call(void 0, _chunk5NH4G6UJcjs.json_default, iconName, 'v-bind="scope"');
291
+ const s = match.fullMatch.replace(`name="${iconName}"`, "").replace(`name='${iconName}'`, "").replace(`</${match.componentName}>`, "");
292
+ const text = `${s}<template #default="scope">${svg}</template></${match.componentName}>`;
293
+ return { text, imptext: "" };
294
+ }
295
+ function getImportName(iconName) {
296
+ return _chunkOSHAEKZLcjs.lineToLargeHump.call(void 0, "fang-icon-" + iconName);
297
+ }
298
+ function getVue(iconName, match) {
299
+ const text = match.fullMatch.replace(`name="${iconName}"`, `:name="${getImportName(iconName)}"`).replace(`name='${iconName}'`, `:name='${getImportName(iconName)}'`);
300
+ return {
301
+ text,
302
+ imptext: `import ${getImportName(
303
+ iconName
304
+ )} from '@fangzhongya/icons/vue/${iconName}'`
1029
305
  };
1030
306
  }
307
+ function replaceComponent(match, type, dynamic, customReplacement) {
308
+ const { attributes } = match;
309
+ const iconName = attributes.name;
310
+ if (customReplacement) {
311
+ return customReplacement(iconName, attributes);
312
+ }
313
+ let svgContent = _chunk5NH4G6UJcjs.json_default.icons[iconName];
314
+ if (!svgContent) {
315
+ return { text: match.fullMatch, imptext: "" };
316
+ }
317
+ if (!attributes.type && type == "svg" || attributes.type === "svg") {
318
+ if (dynamic) {
319
+ return getVue(iconName, match);
320
+ } else {
321
+ return getText(iconName, match);
322
+ }
323
+ }
324
+ return { text: match.fullMatch, imptext: "" };
325
+ }
326
+ function shouldProcess(id) {
327
+ const validExtensions = [".vue", ".jsx", ".tsx", ".js", ".ts"];
328
+ const hasValidExtension = validExtensions.some((ext) => id.endsWith(ext));
329
+ if (!hasValidExtension) return false;
330
+ if (id.includes("/node_modules/")) return false;
331
+ return true;
332
+ }
1031
333
 
1032
334
 
1033
335
  exports.simpleFangIcon = simpleFangIcon;