@fangzhongya/icons 0.0.14 → 0.0.15
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.
- package/dist/chunk-6UMRW5ES.cjs +226 -0
- package/dist/chunk-Y2JUP3JH.js +226 -0
- package/dist/iconify.cjs +5 -114
- package/dist/iconify.d.cts +100 -1
- package/dist/iconify.d.ts +100 -1
- package/dist/iconify.js +8 -117
- package/dist/index.json +1 -1
- package/dist/vite/index2.cjs +179 -65
- package/dist/vite/index2.d.cts +24 -5
- package/dist/vite/index2.d.ts +24 -5
- package/dist/vite/index2.js +178 -64
- package/package.json +1 -1
package/dist/iconify.d.cts
CHANGED
|
@@ -2,6 +2,105 @@ import * as vue from 'vue';
|
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
import { InstallOptions } from './config.cjs';
|
|
4
4
|
|
|
5
|
+
declare const icons: {
|
|
6
|
+
prefix: string;
|
|
7
|
+
info: {};
|
|
8
|
+
lastModified: number;
|
|
9
|
+
icons: {
|
|
10
|
+
bar: {
|
|
11
|
+
body: string;
|
|
12
|
+
};
|
|
13
|
+
below: {
|
|
14
|
+
body: string;
|
|
15
|
+
};
|
|
16
|
+
bicycle: {
|
|
17
|
+
body: string;
|
|
18
|
+
};
|
|
19
|
+
bottom: {
|
|
20
|
+
body: string;
|
|
21
|
+
};
|
|
22
|
+
"bottom-left": {
|
|
23
|
+
body: string;
|
|
24
|
+
};
|
|
25
|
+
"bottom-right": {
|
|
26
|
+
body: string;
|
|
27
|
+
};
|
|
28
|
+
"cascader-field": {
|
|
29
|
+
body: string;
|
|
30
|
+
};
|
|
31
|
+
catalogue: {
|
|
32
|
+
body: string;
|
|
33
|
+
};
|
|
34
|
+
clear: {
|
|
35
|
+
body: string;
|
|
36
|
+
};
|
|
37
|
+
close: {
|
|
38
|
+
body: string;
|
|
39
|
+
};
|
|
40
|
+
crl: {
|
|
41
|
+
body: string;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
};
|
|
45
|
+
delete: {
|
|
46
|
+
body: string;
|
|
47
|
+
};
|
|
48
|
+
document: {
|
|
49
|
+
body: string;
|
|
50
|
+
};
|
|
51
|
+
down: {
|
|
52
|
+
body: string;
|
|
53
|
+
};
|
|
54
|
+
download: {
|
|
55
|
+
body: string;
|
|
56
|
+
};
|
|
57
|
+
edit: {
|
|
58
|
+
body: string;
|
|
59
|
+
};
|
|
60
|
+
enter: {
|
|
61
|
+
body: string;
|
|
62
|
+
};
|
|
63
|
+
frame: {
|
|
64
|
+
body: string;
|
|
65
|
+
};
|
|
66
|
+
left: {
|
|
67
|
+
body: string;
|
|
68
|
+
};
|
|
69
|
+
mute: {
|
|
70
|
+
body: string;
|
|
71
|
+
};
|
|
72
|
+
pause: {
|
|
73
|
+
body: string;
|
|
74
|
+
};
|
|
75
|
+
play: {
|
|
76
|
+
body: string;
|
|
77
|
+
};
|
|
78
|
+
plus: {
|
|
79
|
+
body: string;
|
|
80
|
+
};
|
|
81
|
+
retreat: {
|
|
82
|
+
body: string;
|
|
83
|
+
};
|
|
84
|
+
right: {
|
|
85
|
+
body: string;
|
|
86
|
+
};
|
|
87
|
+
sound: {
|
|
88
|
+
body: string;
|
|
89
|
+
};
|
|
90
|
+
star: {
|
|
91
|
+
body: string;
|
|
92
|
+
};
|
|
93
|
+
up: {
|
|
94
|
+
body: string;
|
|
95
|
+
};
|
|
96
|
+
views: {
|
|
97
|
+
body: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
aliases: {};
|
|
101
|
+
width: number;
|
|
102
|
+
height: number;
|
|
103
|
+
};
|
|
5
104
|
/**
|
|
6
105
|
* 将图标配置转换为Vue组件并注册到应用中
|
|
7
106
|
* @param app - Vue应用实例,用于注册组件
|
|
@@ -39,4 +138,4 @@ type Iconify = {
|
|
|
39
138
|
declare function iconifySVG(obj: Iconify, name: string): vue.DefineComponent<{}, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
40
139
|
declare function getIconifySVG(obj: Iconify, name: string, str?: string): string;
|
|
41
140
|
|
|
42
|
-
export { getIconifySVG, iconify, iconifySVG };
|
|
141
|
+
export { getIconifySVG, iconify, iconifySVG, icons };
|
package/dist/iconify.d.ts
CHANGED
|
@@ -2,6 +2,105 @@ import * as vue from 'vue';
|
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
import { InstallOptions } from './config.js';
|
|
4
4
|
|
|
5
|
+
declare const icons: {
|
|
6
|
+
prefix: string;
|
|
7
|
+
info: {};
|
|
8
|
+
lastModified: number;
|
|
9
|
+
icons: {
|
|
10
|
+
bar: {
|
|
11
|
+
body: string;
|
|
12
|
+
};
|
|
13
|
+
below: {
|
|
14
|
+
body: string;
|
|
15
|
+
};
|
|
16
|
+
bicycle: {
|
|
17
|
+
body: string;
|
|
18
|
+
};
|
|
19
|
+
bottom: {
|
|
20
|
+
body: string;
|
|
21
|
+
};
|
|
22
|
+
"bottom-left": {
|
|
23
|
+
body: string;
|
|
24
|
+
};
|
|
25
|
+
"bottom-right": {
|
|
26
|
+
body: string;
|
|
27
|
+
};
|
|
28
|
+
"cascader-field": {
|
|
29
|
+
body: string;
|
|
30
|
+
};
|
|
31
|
+
catalogue: {
|
|
32
|
+
body: string;
|
|
33
|
+
};
|
|
34
|
+
clear: {
|
|
35
|
+
body: string;
|
|
36
|
+
};
|
|
37
|
+
close: {
|
|
38
|
+
body: string;
|
|
39
|
+
};
|
|
40
|
+
crl: {
|
|
41
|
+
body: string;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
};
|
|
45
|
+
delete: {
|
|
46
|
+
body: string;
|
|
47
|
+
};
|
|
48
|
+
document: {
|
|
49
|
+
body: string;
|
|
50
|
+
};
|
|
51
|
+
down: {
|
|
52
|
+
body: string;
|
|
53
|
+
};
|
|
54
|
+
download: {
|
|
55
|
+
body: string;
|
|
56
|
+
};
|
|
57
|
+
edit: {
|
|
58
|
+
body: string;
|
|
59
|
+
};
|
|
60
|
+
enter: {
|
|
61
|
+
body: string;
|
|
62
|
+
};
|
|
63
|
+
frame: {
|
|
64
|
+
body: string;
|
|
65
|
+
};
|
|
66
|
+
left: {
|
|
67
|
+
body: string;
|
|
68
|
+
};
|
|
69
|
+
mute: {
|
|
70
|
+
body: string;
|
|
71
|
+
};
|
|
72
|
+
pause: {
|
|
73
|
+
body: string;
|
|
74
|
+
};
|
|
75
|
+
play: {
|
|
76
|
+
body: string;
|
|
77
|
+
};
|
|
78
|
+
plus: {
|
|
79
|
+
body: string;
|
|
80
|
+
};
|
|
81
|
+
retreat: {
|
|
82
|
+
body: string;
|
|
83
|
+
};
|
|
84
|
+
right: {
|
|
85
|
+
body: string;
|
|
86
|
+
};
|
|
87
|
+
sound: {
|
|
88
|
+
body: string;
|
|
89
|
+
};
|
|
90
|
+
star: {
|
|
91
|
+
body: string;
|
|
92
|
+
};
|
|
93
|
+
up: {
|
|
94
|
+
body: string;
|
|
95
|
+
};
|
|
96
|
+
views: {
|
|
97
|
+
body: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
aliases: {};
|
|
101
|
+
width: number;
|
|
102
|
+
height: number;
|
|
103
|
+
};
|
|
5
104
|
/**
|
|
6
105
|
* 将图标配置转换为Vue组件并注册到应用中
|
|
7
106
|
* @param app - Vue应用实例,用于注册组件
|
|
@@ -39,4 +138,4 @@ type Iconify = {
|
|
|
39
138
|
declare function iconifySVG(obj: Iconify, name: string): vue.DefineComponent<{}, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
40
139
|
declare function getIconifySVG(obj: Iconify, name: string, str?: string): string;
|
|
41
140
|
|
|
42
|
-
export { getIconifySVG, iconify, iconifySVG };
|
|
141
|
+
export { getIconifySVG, iconify, iconifySVG, icons };
|
package/dist/iconify.js
CHANGED
|
@@ -1,123 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
getIconifySVG,
|
|
3
|
+
iconify,
|
|
4
|
+
iconifySVG,
|
|
5
|
+
icons
|
|
6
|
+
} from "./chunk-Y2JUP3JH.js";
|
|
7
|
+
import "./chunk-MOHILOKE.js";
|
|
4
8
|
import "./chunk-MLKGABMK.js";
|
|
5
|
-
|
|
6
|
-
// packages/iconify.ts
|
|
7
|
-
import { defineComponent, h } from "vue";
|
|
8
|
-
|
|
9
|
-
// node_modules/.pnpm/@fangzhongya+utils@0.0.72/node_modules/@fangzhongya/utils/dist/chunk-EWJJKQIO.js
|
|
10
|
-
function firstUpper(str) {
|
|
11
|
-
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// node_modules/.pnpm/@fangzhongya+utils@0.0.72/node_modules/@fangzhongya/utils/dist/chunk-XCDKXZFR.js
|
|
15
|
-
function lineToLargeHump(name) {
|
|
16
|
-
let arr = name.split("-");
|
|
17
|
-
arr = arr.map((vs) => {
|
|
18
|
-
return firstUpper(vs);
|
|
19
|
-
});
|
|
20
|
-
return arr.join("");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// packages/iconify.ts
|
|
24
|
-
function createSVG(obj) {
|
|
25
|
-
const viewBox = [
|
|
26
|
-
obj.left || 0,
|
|
27
|
-
obj.top || 0,
|
|
28
|
-
obj.width || 24,
|
|
29
|
-
obj.height || 24
|
|
30
|
-
].join(" ");
|
|
31
|
-
const name = "icon-" + obj.name;
|
|
32
|
-
return defineComponent({
|
|
33
|
-
name: lineToLargeHump(name),
|
|
34
|
-
props: {},
|
|
35
|
-
render() {
|
|
36
|
-
return h("svg", {
|
|
37
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
38
|
-
"aria-hidden": true,
|
|
39
|
-
id: name,
|
|
40
|
-
ctype: "hcom",
|
|
41
|
-
role: "img",
|
|
42
|
-
class: "iconify iconify-" + obj.prefix,
|
|
43
|
-
viewBox,
|
|
44
|
-
innerHTML: obj.body
|
|
45
|
-
// 直接使用innerHTML
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
var iconify = (app, ify, { prefix = defaultPrefix } = {}) => {
|
|
51
|
-
const obj = {
|
|
52
|
-
prefix: ify.prefix,
|
|
53
|
-
width: ify.width,
|
|
54
|
-
height: ify.height
|
|
55
|
-
};
|
|
56
|
-
const icons = ify.icons;
|
|
57
|
-
for (const key of Object.keys(icons)) {
|
|
58
|
-
app.component(
|
|
59
|
-
prefix + lineToLargeHump(key),
|
|
60
|
-
createSVG({
|
|
61
|
-
...obj,
|
|
62
|
-
name: key,
|
|
63
|
-
...icons[key]
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
const aliases = ify.aliases;
|
|
68
|
-
for (const key of Object.keys(aliases)) {
|
|
69
|
-
const a = aliases[key];
|
|
70
|
-
app.component(
|
|
71
|
-
prefix + lineToLargeHump(key),
|
|
72
|
-
createSVG({
|
|
73
|
-
...obj,
|
|
74
|
-
name: key,
|
|
75
|
-
...icons[a.parent]
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
function iconifySVG(obj, name) {
|
|
81
|
-
var _a;
|
|
82
|
-
const icons = obj.icons;
|
|
83
|
-
const aliases = obj.aliases;
|
|
84
|
-
const ap = (_a = aliases[name]) == null ? void 0 : _a.parent;
|
|
85
|
-
const n = icons[name] ?? (ap ? icons[ap] : void 0);
|
|
86
|
-
if (n) {
|
|
87
|
-
return createSVG({
|
|
88
|
-
prefix: obj.prefix,
|
|
89
|
-
name,
|
|
90
|
-
width: obj.width,
|
|
91
|
-
height: obj.height,
|
|
92
|
-
...n
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function getIconifySVG(obj, name, str = "") {
|
|
97
|
-
var _a;
|
|
98
|
-
const icons = obj.icons;
|
|
99
|
-
const aliases = obj.aliases;
|
|
100
|
-
const ap = (_a = aliases[name]) == null ? void 0 : _a.parent;
|
|
101
|
-
const n = icons[name] ?? (ap ? icons[ap] : void 0);
|
|
102
|
-
if (n) {
|
|
103
|
-
const v = {
|
|
104
|
-
prefix: obj.prefix,
|
|
105
|
-
name,
|
|
106
|
-
width: obj.width,
|
|
107
|
-
height: obj.height,
|
|
108
|
-
...n
|
|
109
|
-
};
|
|
110
|
-
const viewBox = [
|
|
111
|
-
v.left || 0,
|
|
112
|
-
v.top || 0,
|
|
113
|
-
v.width || 1024,
|
|
114
|
-
v.height || 1024
|
|
115
|
-
].join(" ");
|
|
116
|
-
return `<svg ${str} xmlns="http://www.w3.org/2000/svg" viewBox="${viewBox}">${n.body}</svg>`;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
9
|
export {
|
|
120
10
|
getIconifySVG,
|
|
121
11
|
iconify,
|
|
122
|
-
iconifySVG
|
|
12
|
+
iconifySVG,
|
|
13
|
+
icons
|
|
123
14
|
};
|
package/dist/index.json
CHANGED
package/dist/vite/index2.cjs
CHANGED
|
@@ -1,77 +1,191 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk6UMRW5EScjs = require('../chunk-6UMRW5ES.cjs');
|
|
5
|
+
require('../chunk-IIVF4KK5.cjs');
|
|
6
|
+
require('../chunk-75ZPJI57.cjs');
|
|
2
7
|
|
|
3
8
|
// packages/vite/index2.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
name
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
function parseAttributes(attrString) {
|
|
10
|
+
const attributes = { name: "" };
|
|
11
|
+
const attrRegex = /(?:@|:|v-bind:)?([\w-]+)(?:="([^"]*)"|='([^']*)')/g;
|
|
12
|
+
let match;
|
|
13
|
+
while ((match = attrRegex.exec(attrString)) !== null) {
|
|
14
|
+
const name = match[1];
|
|
15
|
+
if (name) {
|
|
16
|
+
const value = match[2] || match[3] || "";
|
|
17
|
+
if (name === "name") {
|
|
18
|
+
attributes.name = value;
|
|
19
|
+
} else if (value === "true" || value === "false") {
|
|
20
|
+
attributes[name] = value === "true";
|
|
21
|
+
} else if (!isNaN(Number(value)) && value !== "") {
|
|
22
|
+
attributes[name] = Number(value);
|
|
23
|
+
} else {
|
|
24
|
+
attributes[name] = value;
|
|
13
25
|
}
|
|
14
|
-
return void 0;
|
|
15
|
-
},
|
|
16
|
-
load(id) {
|
|
17
|
-
if (id === resolvedVirtualModuleId) {
|
|
18
|
-
return `
|
|
19
|
-
import { defineComponent, h, defineAsyncComponent, resolveComponent, computed } from 'vue'
|
|
20
|
-
import FangIcon from '@fangzhongya/icons/icon/index'
|
|
21
|
-
|
|
22
|
-
export default defineComponent({
|
|
23
|
-
props: {
|
|
24
|
-
name: {
|
|
25
|
-
type: [String, Object],
|
|
26
|
-
required: true
|
|
27
|
-
},
|
|
28
|
-
type: {
|
|
29
|
-
type: String,
|
|
30
|
-
default: '${type}'
|
|
31
|
-
},
|
|
32
|
-
directory: {
|
|
33
|
-
type: String,
|
|
34
|
-
default: '${directory}'
|
|
35
26
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
27
|
+
}
|
|
28
|
+
return attributes;
|
|
29
|
+
}
|
|
30
|
+
function hasStringNameAttribute(attrString) {
|
|
31
|
+
const nameRegex = /(?:^|\s)name="[^"]*"/i;
|
|
32
|
+
const singleQuoteRegex = /(?:^|\s)name='[^']*'/i;
|
|
33
|
+
return nameRegex.test(attrString) || singleQuoteRegex.test(attrString);
|
|
34
|
+
}
|
|
35
|
+
function isOnlyWhitespace(content) {
|
|
36
|
+
return !content || /^\s*$/.test(content);
|
|
37
|
+
}
|
|
38
|
+
function findComponents(code, name) {
|
|
39
|
+
const components = [];
|
|
40
|
+
for (const componentName of name) {
|
|
41
|
+
let currentIndex = 0;
|
|
42
|
+
while (currentIndex < code.length) {
|
|
43
|
+
const startTagIndex = code.indexOf(
|
|
44
|
+
`<${componentName}`,
|
|
45
|
+
currentIndex
|
|
46
|
+
);
|
|
47
|
+
if (startTagIndex === -1) break;
|
|
48
|
+
let tagEndIndex = code.indexOf(">", startTagIndex);
|
|
49
|
+
if (tagEndIndex === -1) break;
|
|
50
|
+
const startTag = code.slice(startTagIndex, tagEndIndex + 1);
|
|
51
|
+
const attrString = startTag.slice(componentName.length + 1, -1).trim();
|
|
52
|
+
if (!hasStringNameAttribute(attrString)) {
|
|
53
|
+
currentIndex = startTagIndex + 1;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const attributes = parseAttributes(attrString);
|
|
57
|
+
if (!attributes.name) {
|
|
58
|
+
currentIndex = startTagIndex + 1;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const isSelfClosing = startTag.endsWith("/>");
|
|
62
|
+
let endIndex;
|
|
63
|
+
let fullMatch;
|
|
64
|
+
if (isSelfClosing) {
|
|
65
|
+
endIndex = tagEndIndex + 1;
|
|
66
|
+
fullMatch = startTag;
|
|
67
|
+
} else {
|
|
68
|
+
const endTag = `</${componentName}>`;
|
|
69
|
+
let endTagIndex = code.indexOf(endTag, tagEndIndex + 1);
|
|
70
|
+
if (endTagIndex === -1) {
|
|
71
|
+
currentIndex = startTagIndex + 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const content = code.slice(tagEndIndex + 1, endTagIndex);
|
|
75
|
+
if (!isOnlyWhitespace(content)) {
|
|
76
|
+
currentIndex = startTagIndex + 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
endIndex = endTagIndex + endTag.length;
|
|
80
|
+
fullMatch = code.slice(startTagIndex, endIndex);
|
|
58
81
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
name: IconComponent.value,
|
|
67
|
-
directory: props.directory
|
|
82
|
+
components.push({
|
|
83
|
+
componentName,
|
|
84
|
+
fullMatch,
|
|
85
|
+
start: startTagIndex,
|
|
86
|
+
end: endIndex,
|
|
87
|
+
attributes,
|
|
88
|
+
isSelfClosing
|
|
68
89
|
});
|
|
69
|
-
|
|
90
|
+
currentIndex = endIndex;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return components;
|
|
94
|
+
}
|
|
95
|
+
function getText(iconName, match) {
|
|
96
|
+
const svg = _chunk6UMRW5EScjs.getIconifySVG.call(void 0, _chunk6UMRW5EScjs.icons, iconName, 'v-bind="scope"');
|
|
97
|
+
const s = match.fullMatch.replace(`name="${iconName}"`, "").replace(`name='${iconName}'`, "").replace(`</${match.componentName}>`, "");
|
|
98
|
+
const text = `${s}<template #default="scope">${svg}</template></${match.componentName}>`;
|
|
99
|
+
return { text, imptext: "" };
|
|
100
|
+
}
|
|
101
|
+
function replaceComponent(match, customReplacement) {
|
|
102
|
+
const { attributes } = match;
|
|
103
|
+
const iconName = attributes.name;
|
|
104
|
+
if (customReplacement) {
|
|
105
|
+
return customReplacement(iconName, attributes);
|
|
106
|
+
}
|
|
107
|
+
let svgContent = _chunk6UMRW5EScjs.icons.icons[iconName];
|
|
108
|
+
if (!svgContent) {
|
|
109
|
+
return { text: match.fullMatch, imptext: "" };
|
|
110
|
+
}
|
|
111
|
+
if (!attributes.type || attributes.type === "svg") {
|
|
112
|
+
if (true) {
|
|
113
|
+
return getText(iconName, match);
|
|
114
|
+
} else {
|
|
115
|
+
return getVue(iconName, match);
|
|
116
|
+
}
|
|
70
117
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
118
|
+
return { text: match.fullMatch, imptext: "" };
|
|
119
|
+
}
|
|
120
|
+
function shouldProcess(id) {
|
|
121
|
+
const validExtensions = [".vue", ".jsx", ".tsx", ".js", ".ts"];
|
|
122
|
+
const hasValidExtension = validExtensions.some((ext) => id.endsWith(ext));
|
|
123
|
+
if (!hasValidExtension) return false;
|
|
124
|
+
if (id.includes("/node_modules/")) return false;
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
function simpleFangIcon(options) {
|
|
128
|
+
const { name = ["FangIcon"], customReplacement } = options;
|
|
129
|
+
const targetComponents = Array.isArray(name) ? name : [name];
|
|
130
|
+
return {
|
|
131
|
+
name: "vite-plugin-fang-icon-replacer",
|
|
132
|
+
// 使用 enforce 确保在 Vue 插件之前执行
|
|
133
|
+
enforce: "pre",
|
|
134
|
+
// 转换代码
|
|
135
|
+
transform(code, id) {
|
|
136
|
+
if (!shouldProcess(id)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const components = findComponents(code, targetComponents);
|
|
141
|
+
if (components.length === 0) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
let transformedCode = code;
|
|
145
|
+
let replacedCount = 0;
|
|
146
|
+
const imports = /* @__PURE__ */ new Set();
|
|
147
|
+
for (let i = components.length - 1; i >= 0; i--) {
|
|
148
|
+
const component = components[i];
|
|
149
|
+
if (component) {
|
|
150
|
+
const { text, imptext } = replaceComponent(
|
|
151
|
+
component,
|
|
152
|
+
customReplacement
|
|
153
|
+
);
|
|
154
|
+
imports.add(imptext);
|
|
155
|
+
if (text !== component.fullMatch) {
|
|
156
|
+
transformedCode = transformedCode.slice(0, component.start) + text + transformedCode.slice(component.end);
|
|
157
|
+
replacedCount++;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (/.vue$/.test(id)) {
|
|
162
|
+
const i = transformedCode.indexOf("</script>");
|
|
163
|
+
transformedCode = transformedCode.slice(0, i) + [...imports].join(";") + transformedCode.slice(i);
|
|
164
|
+
} else {
|
|
165
|
+
transformedCode = [...imports].join(";") + transformedCode;
|
|
166
|
+
}
|
|
167
|
+
if (replacedCount > 0) {
|
|
168
|
+
return {
|
|
169
|
+
code: transformedCode,
|
|
170
|
+
map: null
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error(`\u5904\u7406\u6587\u4EF6 ${id} \u65F6\u51FA\u9519:`, error);
|
|
73
175
|
}
|
|
74
176
|
return null;
|
|
177
|
+
},
|
|
178
|
+
// 处理热更新
|
|
179
|
+
handleHotUpdate({
|
|
180
|
+
file,
|
|
181
|
+
server
|
|
182
|
+
}) {
|
|
183
|
+
if (shouldProcess(file)) {
|
|
184
|
+
server.ws.send({
|
|
185
|
+
type: "full-reload"
|
|
186
|
+
});
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
75
189
|
}
|
|
76
190
|
};
|
|
77
191
|
}
|
package/dist/vite/index2.d.cts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
interface
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
interface ComponentAttributes {
|
|
4
|
+
name: string;
|
|
5
|
+
[key: string]: string | boolean | number;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
interface ComponentMatchInfo {
|
|
8
|
+
componentName: string;
|
|
9
|
+
fullMatch: string;
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
attributes: ComponentAttributes;
|
|
13
|
+
isSelfClosing: boolean;
|
|
14
|
+
}
|
|
15
|
+
type IconReplacement = (iconName: string, attributes: ComponentAttributes) => {
|
|
16
|
+
text: string;
|
|
17
|
+
imptext: string;
|
|
18
|
+
};
|
|
19
|
+
interface FangIconReplacerOptions {
|
|
20
|
+
name?: string | string[];
|
|
21
|
+
customReplacement?: IconReplacement;
|
|
22
|
+
include?: string[];
|
|
23
|
+
exclude?: string[];
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
|
26
|
+
declare function simpleFangIcon(options: FangIconReplacerOptions): Plugin;
|
|
8
27
|
|
|
9
|
-
export { simpleFangIcon };
|
|
28
|
+
export { type ComponentAttributes, type ComponentMatchInfo, type FangIconReplacerOptions, type IconReplacement, simpleFangIcon };
|
package/dist/vite/index2.d.ts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
interface
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
interface ComponentAttributes {
|
|
4
|
+
name: string;
|
|
5
|
+
[key: string]: string | boolean | number;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
interface ComponentMatchInfo {
|
|
8
|
+
componentName: string;
|
|
9
|
+
fullMatch: string;
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
attributes: ComponentAttributes;
|
|
13
|
+
isSelfClosing: boolean;
|
|
14
|
+
}
|
|
15
|
+
type IconReplacement = (iconName: string, attributes: ComponentAttributes) => {
|
|
16
|
+
text: string;
|
|
17
|
+
imptext: string;
|
|
18
|
+
};
|
|
19
|
+
interface FangIconReplacerOptions {
|
|
20
|
+
name?: string | string[];
|
|
21
|
+
customReplacement?: IconReplacement;
|
|
22
|
+
include?: string[];
|
|
23
|
+
exclude?: string[];
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
}
|
|
26
|
+
declare function simpleFangIcon(options: FangIconReplacerOptions): Plugin;
|
|
8
27
|
|
|
9
|
-
export { simpleFangIcon };
|
|
28
|
+
export { type ComponentAttributes, type ComponentMatchInfo, type FangIconReplacerOptions, type IconReplacement, simpleFangIcon };
|