@fangzhongya/icons 0.0.15 → 0.0.17

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 (38) hide show
  1. package/dist/{vue.cjs → async.cjs} +23 -23
  2. package/dist/{vue.d.cts → async.d.cts} +20 -20
  3. package/dist/{vue.d.ts → async.d.ts} +20 -20
  4. package/dist/{vue.js → async.js} +23 -23
  5. package/dist/chunk-BKYM5ZD6.js +909 -0
  6. package/dist/{chunk-Y2JUP3JH.js → chunk-CDXRU53D.js} +4 -123
  7. package/dist/chunk-HSJ3RNOH.js +124 -0
  8. package/dist/chunk-OSHAEKZL.cjs +124 -0
  9. package/dist/{chunk-6UMRW5ES.cjs → chunk-P3DB3N7Y.cjs} +5 -124
  10. package/dist/chunk-V6F7B2R3.cjs +909 -0
  11. package/dist/iconify.cjs +2 -4
  12. package/dist/iconify.d.cts +1 -100
  13. package/dist/iconify.d.ts +1 -100
  14. package/dist/iconify.js +3 -5
  15. package/dist/index.cjs +17 -17
  16. package/dist/index.js +19 -19
  17. package/dist/index.json +1 -1
  18. package/dist/json.cjs +7 -0
  19. package/dist/json.d.cts +110 -0
  20. package/dist/json.d.ts +110 -0
  21. package/dist/json.js +7 -0
  22. package/dist/vite/index.cjs +293 -988
  23. package/dist/vite/index.d.cts +20 -1
  24. package/dist/vite/index.d.ts +20 -1
  25. package/dist/vite/index.js +298 -993
  26. package/dist/vite/index2.cjs +31 -9
  27. package/dist/vite/index2.d.cts +8 -7
  28. package/dist/vite/index2.d.ts +8 -7
  29. package/dist/vite/index2.js +32 -10
  30. package/dist/vite/index3.cjs +130 -0
  31. package/dist/vite/index3.d.cts +12 -0
  32. package/dist/vite/index3.d.ts +12 -0
  33. package/dist/vite/index3.js +130 -0
  34. package/dist/vue/index.cjs +16 -16
  35. package/dist/vue/index.js +19 -19
  36. package/package.json +2 -2
  37. package/dist/{chunk-3YRVWHZK.js → chunk-54HT4HDM.js} +18 -18
  38. package/dist/{chunk-BWFROGEZ.cjs → chunk-KXZN54UH.cjs} +15 -15
@@ -1,1033 +1,338 @@
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
-
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
50
2
 
3
+ var _chunkV6F7B2R3cjs = require('../chunk-V6F7B2R3.cjs');
51
4
 
52
5
 
53
6
 
7
+ var _chunkOSHAEKZLcjs = require('../chunk-OSHAEKZL.cjs');
8
+ require('../chunk-IIVF4KK5.cjs');
54
9
 
55
10
 
11
+ var _chunkP3DB3N7Ycjs = require('../chunk-P3DB3N7Y.cjs');
12
+ require('../chunk-75ZPJI57.cjs');
56
13
 
57
-
58
- var _fs = require('fs');
14
+ // packages/vite/index.ts
59
15
  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];
16
+ var virtualModuleId = "virtual:fang-icon";
17
+ function simpleFangIcon(options = {}) {
18
+ const {
19
+ name = "FangIcon",
20
+ type = "svg",
21
+ directory = "./svg",
22
+ dynamic = true,
23
+ virtual = false,
24
+ replaced = true,
25
+ customReplacement
26
+ } = options;
27
+ if (type === "pub" && options.mobile) {
28
+ const outDir = _path.join.call(void 0, "./public/", directory);
29
+ _chunkV6F7B2R3cjs.runDev.call(void 0, {
30
+ issort: true,
31
+ dir: "./node_modules/@fangzhongya/icons/dist/svg",
32
+ outDir,
33
+ extensions: ["svg"],
34
+ read: true,
35
+ fileCover: true,
36
+ isNeader: false
37
+ });
71
38
  }
72
- return {
73
- catalogue: ml,
74
- name,
75
- suffix,
76
- apart
39
+ const plugin = {
40
+ name: "simple-fang-icon"
77
41
  };
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);
42
+ if (virtual) {
43
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
44
+ const pub = `
45
+ import { defineComponent, h,} from 'vue'
46
+ import FangIcon from '@fangzhongya/icons/icon/index'
47
+ const component = defineComponent({
48
+ name: '${name}',
49
+ props: {
50
+ name: {
51
+ type: [String, Object],
52
+ },
53
+ default: {
54
+ type: String,
55
+ default: '${type}'
56
+ },
57
+ directory: {
58
+ type: String,
59
+ default: '${directory}'
60
+ }
61
+ },
62
+ setup(props, { attrs }) {
63
+ return () => {
64
+ return h(FangIcon, {
65
+ ...attrs,
66
+ name: props.name,
67
+ default: props.default,
68
+ directory: props.directory
69
+ });
70
+ };
71
+ }
72
+ });
73
+ // \u5BFC\u51FA\u5B89\u88C5\u51FD\u6570
74
+ export const install = (app) => {
75
+ app.component('${name}', component)
76
+ };
77
+
78
+ export default component;`;
79
+ const svg = `
80
+ import { defineComponent, h, computed} from 'vue'
81
+ import FangIcon from '@fangzhongya/icons/icon/index'
82
+ import icons from '@fangzhongya/icons/async'
83
+ const component = defineComponent({
84
+ name: '${name}',
85
+ props: {
86
+ name: {
87
+ type: [String, Object],
88
+ },
89
+ type: {
90
+ type: String,
91
+ },
92
+ default: {
93
+ type: String,
94
+ default: '${type}'
95
+ },
96
+ directory: {
97
+ type: String,
98
+ default: '${directory}'
99
+ }
100
+ },
101
+ setup(props, { attrs }) {
102
+ const iconName = computed(() => {
103
+ const name = props.name;
104
+ if (typeof name === 'string' && (props.type === 'svg' ||
105
+ (!props.type && props.default === 'svg'))) {
106
+ const icon = icons[name];
107
+ if(icon){
108
+ return icon;
109
+ }
110
+ }
111
+ return name;
112
+ });
113
+ return () => {
114
+ return h(FangIcon, {
115
+ ...attrs,
116
+ name: iconName.value,
117
+ type: props.type,
118
+ default: props.default,
119
+ directory: props.directory
120
+ });
121
+ };
122
+ }
123
+ });
124
+ // \u5BFC\u51FA\u5B89\u88C5\u51FD\u6570
125
+ export const install = (app) => {
126
+ app.component('${name}', component)
127
+ };
128
+
129
+ export default component;`;
130
+ const text = type === "svg" ? svg : pub;
131
+ plugin.resolveId = function(id) {
132
+ if (id === virtualModuleId) {
133
+ return resolvedVirtualModuleId;
108
134
  }
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
- }
135
+ return void 0;
136
+ };
137
+ plugin.load = function(id) {
138
+ if (id === resolvedVirtualModuleId) {
139
+ return text;
190
140
  }
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
- }
141
+ return null;
142
+ };
143
+ }
144
+ if (replaced) {
145
+ const targetComponents = Array.isArray(name) ? name : [name];
146
+ plugin.enforce = "pre";
147
+ plugin.transform = function(code, id) {
148
+ if (!shouldProcess(id)) {
149
+ return null;
241
150
  }
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);
151
+ try {
152
+ const components = findComponents(code, targetComponents);
153
+ if (components.length === 0) {
154
+ return null;
155
+ }
156
+ let transformedCode = code;
157
+ let replacedCount = 0;
158
+ const imports = /* @__PURE__ */ new Set();
159
+ for (let i = components.length - 1; i >= 0; i--) {
160
+ const component = components[i];
161
+ if (component) {
162
+ const { text, imptext } = replaceComponent(
163
+ component,
164
+ type,
165
+ dynamic,
166
+ customReplacement
167
+ );
168
+ imports.add(imptext);
169
+ if (text !== component.fullMatch) {
170
+ transformedCode = transformedCode.slice(0, component.start) + text + transformedCode.slice(component.end);
171
+ replacedCount++;
253
172
  }
254
173
  }
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
174
  }
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);
175
+ if (/.vue$/.test(id)) {
176
+ const i = transformedCode.indexOf("</script>");
177
+ transformedCode = transformedCode.slice(0, i) + [...imports].join(";") + transformedCode.slice(i);
178
+ } else {
179
+ transformedCode = [...imports].join(";") + transformedCode;
327
180
  }
328
- if (is) {
329
- file.push(name);
330
- arr.push(_path.join.call(void 0, url, name));
181
+ if (replacedCount > 0) {
182
+ return {
183
+ code: transformedCode,
184
+ map: null
185
+ };
331
186
  }
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);
187
+ } catch (error) {
188
+ console.error(`\u5904\u7406\u6587\u4EF6 ${id} \u65F6\u51FA\u9519:`, error);
340
189
  }
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
- }
190
+ return null;
191
+ };
192
+ plugin.handleHotUpdate = function({
193
+ file,
194
+ server
195
+ }) {
196
+ if (shouldProcess(file)) {
197
+ server.ws.send({
198
+ type: "full-reload"
199
+ });
200
+ return [];
395
201
  }
396
- }
397
- return false;
398
- } else {
399
- return true;
202
+ };
400
203
  }
204
+ return plugin;
401
205
  }
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
- }
206
+ function parseAttributes(attrString) {
207
+ const attributes = { name: "" };
208
+ const attrRegex = /(?:@|:|v-bind:)?([\w-]+)(?:="([^"]*)"|='([^']*)')/g;
209
+ let match;
210
+ while ((match = attrRegex.exec(attrString)) !== null) {
211
+ const name = match[1];
212
+ if (name) {
213
+ const value = match[2] || match[3] || "";
214
+ if (name === "name") {
215
+ attributes.name = value;
216
+ } else if (value === "true" || value === "false") {
217
+ attributes[name] = value === "true";
218
+ } else if (!isNaN(Number(value)) && value !== "") {
219
+ attributes[name] = Number(value);
409
220
  } else {
410
- if (value.test(key)) {
411
- return true;
412
- }
221
+ attributes[name] = value;
413
222
  }
414
223
  }
415
- return false;
416
- } else {
417
- return true;
418
224
  }
225
+ return attributes;
419
226
  }
420
- function getUrlCatalogue(str) {
421
- const reg = /((\\|\/)([^\\|\/]+)(\.[a-z|A-Z][a-z|A-Z|0-9]*))?$/g;
422
- return str.replace(reg, "");
227
+ function hasStringNameAttribute(attrString) {
228
+ const nameRegex = /(?:^|\s)name="[^"]*"/i;
229
+ const singleQuoteRegex = /(?:^|\s)name='[^']*'/i;
230
+ return nameRegex.test(attrString) || singleQuoteRegex.test(attrString);
423
231
  }
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("|")})$`);
232
+ function isOnlyWhitespace(content) {
233
+ return !content || /^\s*$/.test(content);
482
234
  }
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;
235
+ function findComponents(code, name) {
236
+ const components = [];
237
+ for (const componentName of name) {
238
+ let currentIndex = 0;
239
+ while (currentIndex < code.length) {
240
+ const startTagIndex = code.indexOf(
241
+ `<${componentName}`,
242
+ currentIndex
243
+ );
244
+ if (startTagIndex === -1) break;
245
+ let tagEndIndex = code.indexOf(">", startTagIndex);
246
+ if (tagEndIndex === -1) break;
247
+ const startTag = code.slice(startTagIndex, tagEndIndex + 1);
248
+ const attrString = startTag.slice(componentName.length + 1, -1).trim();
249
+ if (!hasStringNameAttribute(attrString)) {
250
+ currentIndex = startTagIndex + 1;
251
+ continue;
579
252
  }
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([]);
253
+ const attributes = parseAttributes(attrString);
254
+ if (!attributes.name) {
255
+ currentIndex = startTagIndex + 1;
256
+ continue;
611
257
  }
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
- }
258
+ const isSelfClosing = startTag.endsWith("/>");
259
+ let endIndex;
260
+ let fullMatch;
261
+ if (isSelfClosing) {
262
+ endIndex = tagEndIndex + 1;
263
+ fullMatch = startTag;
664
264
  } 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(" "));
265
+ const endTag = `</${componentName}>`;
266
+ let endTagIndex = code.indexOf(endTag, tagEndIndex + 1);
267
+ if (endTagIndex === -1) {
268
+ currentIndex = startTagIndex + 1;
269
+ continue;
742
270
  }
743
- if (callback) {
744
- callback(kurl, type2, is, tn);
271
+ const content = code.slice(tagEndIndex + 1, endTagIndex);
272
+ if (!isOnlyWhitespace(content)) {
273
+ currentIndex = startTagIndex + 1;
274
+ continue;
745
275
  }
276
+ endIndex = endTagIndex + endTag.length;
277
+ fullMatch = code.slice(startTagIndex, endIndex);
746
278
  }
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));
279
+ components.push({
280
+ componentName,
281
+ fullMatch,
282
+ start: startTagIndex,
283
+ end: endIndex,
284
+ attributes,
285
+ isSelfClosing
822
286
  });
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];
287
+ currentIndex = endIndex;
900
288
  }
901
- return arr;
902
289
  }
903
- };
904
- function runDev(config, configCallback, callback) {
905
- const fang = new FangOut(config);
906
- fang.runDev(callback, configCallback);
290
+ return components;
907
291
  }
908
-
909
- // packages/vite/index.ts
910
-
911
- var virtualModuleId = "virtual:fang-icon";
912
- function simpleFangIcon(options = {}) {
913
- const { name = "FangIcon", type = "svg", directory = "./svg" } = options;
914
- const resolvedVirtualModuleId = "\0" + virtualModuleId;
915
- if (type === "pub" && options.mobile) {
916
- const outDir = _path.join.call(void 0, "./public/", directory);
917
- console.log("outDir", outDir);
918
- runDev({
919
- issort: true,
920
- dir: "./node_modules/@fangzhongya/icons/dist/svg",
921
- outDir,
922
- extensions: ["svg"],
923
- read: true,
924
- fileCover: true,
925
- isNeader: false
926
- });
927
- }
928
- const pub = `
929
- import { defineComponent, h,} from 'vue'
930
- import FangIcon from '@fangzhongya/icons/icon/index'
931
- const component = defineComponent({
932
- name: '${name}',
933
- props: {
934
- name: {
935
- type: [String, Object],
936
- },
937
- default: {
938
- type: String,
939
- default: '${type}'
940
- },
941
- directory: {
942
- type: String,
943
- default: '${directory}'
944
- }
945
- },
946
- setup(props, { attrs }) {
947
- return () => {
948
- return h(FangIcon, {
949
- ...attrs,
950
- name: props.name,
951
- default: props.default,
952
- directory: props.directory
953
- });
954
- };
955
- }
956
- });
957
- // \u5BFC\u51FA\u5B89\u88C5\u51FD\u6570
958
- export const install = (app) => {
959
- app.component('${name}', component)
960
- };
961
-
962
- export default component;`;
963
- const svg = `
964
- import { defineComponent, h, computed} from 'vue'
965
- import FangIcon from '@fangzhongya/icons/icon/index'
966
- import { icons } from '@fangzhongya/icons/vue'
967
- const component = defineComponent({
968
- name: '${name}',
969
- props: {
970
- name: {
971
- type: [String, Object],
972
- },
973
- type: {
974
- type: String,
975
- },
976
- default: {
977
- type: String,
978
- default: '${type}'
979
- },
980
- directory: {
981
- type: String,
982
- default: '${directory}'
983
- }
984
- },
985
- setup(props, { attrs }) {
986
- const iconName = computed(() => {
987
- const name = props.name;
988
- if (typeof name === 'string' && (props.type === 'svg' ||
989
- (props.type === undefined && props.default === 'svg'))) {
990
- const icon = icons[name];
991
- if(icon){
992
- return icon;
993
- }
994
- }
995
- return name;
996
- });
997
- return () => {
998
- return h(FangIcon, {
999
- ...attrs,
1000
- name: iconName.value,
1001
- type: props.type,
1002
- default: props.default,
1003
- directory: props.directory
1004
- });
1005
- };
1006
- }
1007
- });
1008
- // \u5BFC\u51FA\u5B89\u88C5\u51FD\u6570
1009
- export const install = (app) => {
1010
- app.component('${name}', component)
1011
- };
1012
-
1013
- export default component;`;
1014
- const text = type === "svg" ? svg : pub;
292
+ function getText(iconName, match) {
293
+ const svg = _chunkOSHAEKZLcjs.getIconifySVG.call(void 0, _chunkP3DB3N7Ycjs.json_default, iconName, 'v-bind="scope"');
294
+ const s = match.fullMatch.replace(`name="${iconName}"`, "").replace(`name='${iconName}'`, "").replace(`</${match.componentName}>`, "");
295
+ const text = `${s}<template #default="scope">${svg}</template></${match.componentName}>`;
296
+ return { text, imptext: "" };
297
+ }
298
+ function getImportName(iconName) {
299
+ return _chunkOSHAEKZLcjs.lineToLargeHump.call(void 0, "fang-icon-" + iconName);
300
+ }
301
+ function getVue(iconName, match) {
302
+ const text = match.fullMatch.replace(`name="${iconName}"`, `:name="${getImportName(iconName)}"`).replace(`name='${iconName}'`, `:name='${getImportName(iconName)}'`);
1015
303
  return {
1016
- name: "simple-fang-icon",
1017
- resolveId(id) {
1018
- if (id === virtualModuleId) {
1019
- return resolvedVirtualModuleId;
1020
- }
1021
- return void 0;
1022
- },
1023
- load(id) {
1024
- if (id === resolvedVirtualModuleId) {
1025
- return text;
1026
- }
1027
- return null;
1028
- }
304
+ text,
305
+ imptext: `import ${getImportName(
306
+ iconName
307
+ )} from '@fangzhongya/icons/vue/${iconName}'`
1029
308
  };
1030
309
  }
310
+ function replaceComponent(match, type, dynamic, customReplacement) {
311
+ const { attributes } = match;
312
+ const iconName = attributes.name;
313
+ if (customReplacement) {
314
+ return customReplacement(iconName, attributes);
315
+ }
316
+ let svgContent = _chunkP3DB3N7Ycjs.json_default.icons[iconName];
317
+ if (!svgContent) {
318
+ return { text: match.fullMatch, imptext: "" };
319
+ }
320
+ if (!attributes.type && type == "svg" || attributes.type === "svg") {
321
+ if (dynamic) {
322
+ return getVue(iconName, match);
323
+ } else {
324
+ return getText(iconName, match);
325
+ }
326
+ }
327
+ return { text: match.fullMatch, imptext: "" };
328
+ }
329
+ function shouldProcess(id) {
330
+ const validExtensions = [".vue", ".jsx", ".tsx", ".js", ".ts"];
331
+ const hasValidExtension = validExtensions.some((ext) => id.endsWith(ext));
332
+ if (!hasValidExtension) return false;
333
+ if (id.includes("/node_modules/")) return false;
334
+ return true;
335
+ }
1031
336
 
1032
337
 
1033
338
  exports.simpleFangIcon = simpleFangIcon;