@fangzhongya/icons 0.0.20 → 0.0.22
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/async.cjs +21 -21
- package/dist/async.d.cts +18 -18
- package/dist/async.d.ts +18 -18
- package/dist/async.js +21 -21
- package/dist/{chunk-7HXPUNMG.js → chunk-E432JW5M.js} +1 -1
- package/dist/{chunk-3WRUG7G2.cjs → chunk-S7ZK22ZV.cjs} +1 -1
- package/dist/index.cjs +24 -24
- package/dist/index.js +27 -27
- package/dist/index.json +1 -1
- package/dist/json.cjs +2 -2
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/json.js +1 -1
- package/dist/vite/index.cjs +947 -23
- package/dist/vite/index.js +945 -21
- package/dist/vue/index.cjs +23 -23
- package/dist/vue/index.js +27 -27
- package/package.json +1 -1
- package/dist/chunk-BKYM5ZD6.js +0 -909
- package/dist/chunk-V6F7B2R3.cjs +0 -909
- package/dist/vite/index2.cjs +0 -219
- package/dist/vite/index2.d.cts +0 -29
- package/dist/vite/index2.d.ts +0 -29
- package/dist/vite/index2.js +0 -219
- package/dist/vite/index3.cjs +0 -130
- package/dist/vite/index3.d.cts +0 -12
- package/dist/vite/index3.d.ts +0 -12
- package/dist/vite/index3.js +0 -130
- package/dist/{chunk-KXZN54UH.cjs → chunk-5ATJRRFS.cjs} +22 -22
- package/dist/{chunk-54HT4HDM.js → chunk-SRJ74PQ7.js} +26 -26
package/dist/vite/index2.cjs
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkOSHAEKZLcjs = require('../chunk-OSHAEKZL.cjs');
|
|
5
|
-
require('../chunk-IIVF4KK5.cjs');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunk3WRUG7G2cjs = require('../chunk-3WRUG7G2.cjs');
|
|
9
|
-
require('../chunk-75ZPJI57.cjs');
|
|
10
|
-
|
|
11
|
-
// packages/vite/index2.ts
|
|
12
|
-
function parseAttributes(attrString) {
|
|
13
|
-
const attributes = { name: "" };
|
|
14
|
-
const attrRegex = /(?:@|:|v-bind:)?([\w-]+)(?:="([^"]*)"|='([^']*)')/g;
|
|
15
|
-
let match;
|
|
16
|
-
while ((match = attrRegex.exec(attrString)) !== null) {
|
|
17
|
-
const name = match[1];
|
|
18
|
-
if (name) {
|
|
19
|
-
const value = match[2] || match[3] || "";
|
|
20
|
-
if (name === "name") {
|
|
21
|
-
attributes.name = value;
|
|
22
|
-
} else if (value === "true" || value === "false") {
|
|
23
|
-
attributes[name] = value === "true";
|
|
24
|
-
} else if (!isNaN(Number(value)) && value !== "") {
|
|
25
|
-
attributes[name] = Number(value);
|
|
26
|
-
} else {
|
|
27
|
-
attributes[name] = value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return attributes;
|
|
32
|
-
}
|
|
33
|
-
function hasStringNameAttribute(attrString) {
|
|
34
|
-
const nameRegex = /(?:^|\s)name="[^"]*"/i;
|
|
35
|
-
const singleQuoteRegex = /(?:^|\s)name='[^']*'/i;
|
|
36
|
-
return nameRegex.test(attrString) || singleQuoteRegex.test(attrString);
|
|
37
|
-
}
|
|
38
|
-
function isOnlyWhitespace(content) {
|
|
39
|
-
return !content || /^\s*$/.test(content);
|
|
40
|
-
}
|
|
41
|
-
function findComponents(code, name) {
|
|
42
|
-
const components = [];
|
|
43
|
-
for (const componentName of name) {
|
|
44
|
-
let currentIndex = 0;
|
|
45
|
-
while (currentIndex < code.length) {
|
|
46
|
-
const startTagIndex = code.indexOf(
|
|
47
|
-
`<${componentName}`,
|
|
48
|
-
currentIndex
|
|
49
|
-
);
|
|
50
|
-
if (startTagIndex === -1) break;
|
|
51
|
-
let tagEndIndex = code.indexOf(">", startTagIndex);
|
|
52
|
-
if (tagEndIndex === -1) break;
|
|
53
|
-
const startTag = code.slice(startTagIndex, tagEndIndex + 1);
|
|
54
|
-
const attrString = startTag.slice(componentName.length + 1, -1).trim();
|
|
55
|
-
if (!hasStringNameAttribute(attrString)) {
|
|
56
|
-
currentIndex = startTagIndex + 1;
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const attributes = parseAttributes(attrString);
|
|
60
|
-
if (!attributes.name) {
|
|
61
|
-
currentIndex = startTagIndex + 1;
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const isSelfClosing = startTag.endsWith("/>");
|
|
65
|
-
let endIndex;
|
|
66
|
-
let fullMatch;
|
|
67
|
-
if (isSelfClosing) {
|
|
68
|
-
endIndex = tagEndIndex + 1;
|
|
69
|
-
fullMatch = startTag;
|
|
70
|
-
} else {
|
|
71
|
-
const endTag = `</${componentName}>`;
|
|
72
|
-
let endTagIndex = code.indexOf(endTag, tagEndIndex + 1);
|
|
73
|
-
if (endTagIndex === -1) {
|
|
74
|
-
currentIndex = startTagIndex + 1;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
const content = code.slice(tagEndIndex + 1, endTagIndex);
|
|
78
|
-
if (!isOnlyWhitespace(content)) {
|
|
79
|
-
currentIndex = startTagIndex + 1;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
endIndex = endTagIndex + endTag.length;
|
|
83
|
-
fullMatch = code.slice(startTagIndex, endIndex);
|
|
84
|
-
}
|
|
85
|
-
components.push({
|
|
86
|
-
componentName,
|
|
87
|
-
fullMatch,
|
|
88
|
-
start: startTagIndex,
|
|
89
|
-
end: endIndex,
|
|
90
|
-
attributes,
|
|
91
|
-
isSelfClosing
|
|
92
|
-
});
|
|
93
|
-
currentIndex = endIndex;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return components;
|
|
97
|
-
}
|
|
98
|
-
function getText(iconName, match) {
|
|
99
|
-
const svg = _chunkOSHAEKZLcjs.getIconifySVG.call(void 0, _chunk3WRUG7G2cjs.json_default, iconName, 'v-bind="scope"');
|
|
100
|
-
const s = match.fullMatch.replace(`name="${iconName}"`, "").replace(`name='${iconName}'`, "").replace(`</${match.componentName}>`, "");
|
|
101
|
-
const text = `${s}<template #default="scope">${svg}</template></${match.componentName}>`;
|
|
102
|
-
return { text, imptext: "" };
|
|
103
|
-
}
|
|
104
|
-
function getImportName(iconName) {
|
|
105
|
-
return _chunkOSHAEKZLcjs.lineToLargeHump.call(void 0, "fang-icon-" + iconName);
|
|
106
|
-
}
|
|
107
|
-
function getVue(iconName, match) {
|
|
108
|
-
const text = match.fullMatch.replace(`name="${iconName}"`, `:name="${getImportName(iconName)}"`).replace(`name='${iconName}'`, `:name='${getImportName(iconName)}'`);
|
|
109
|
-
return {
|
|
110
|
-
text,
|
|
111
|
-
imptext: `import ${getImportName(
|
|
112
|
-
iconName
|
|
113
|
-
)} from '@fangzhongya/icons/vue/${iconName}'`
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function replaceComponent(match, type, dynamic, customReplacement) {
|
|
117
|
-
const { attributes } = match;
|
|
118
|
-
const iconName = attributes.name;
|
|
119
|
-
if (customReplacement) {
|
|
120
|
-
return customReplacement(iconName, attributes);
|
|
121
|
-
}
|
|
122
|
-
let svgContent = _chunk3WRUG7G2cjs.json_default.icons[iconName];
|
|
123
|
-
if (!svgContent) {
|
|
124
|
-
return { text: match.fullMatch, imptext: "" };
|
|
125
|
-
}
|
|
126
|
-
if (!attributes.type && type == "svg" || attributes.type === "svg") {
|
|
127
|
-
if (dynamic) {
|
|
128
|
-
return getVue(iconName, match);
|
|
129
|
-
} else {
|
|
130
|
-
return getText(iconName, match);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return { text: match.fullMatch, imptext: "" };
|
|
134
|
-
}
|
|
135
|
-
function shouldProcess(id) {
|
|
136
|
-
const validExtensions = [".vue", ".jsx", ".tsx", ".js", ".ts"];
|
|
137
|
-
const hasValidExtension = validExtensions.some((ext) => id.endsWith(ext));
|
|
138
|
-
if (!hasValidExtension) return false;
|
|
139
|
-
if (id.includes("/node_modules/")) return false;
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
function simpleFangIcon(options) {
|
|
143
|
-
const {
|
|
144
|
-
name = "FangIcon",
|
|
145
|
-
type = "svg",
|
|
146
|
-
dynamic = true,
|
|
147
|
-
customReplacement
|
|
148
|
-
} = options;
|
|
149
|
-
const targetComponents = Array.isArray(name) ? name : [name];
|
|
150
|
-
return {
|
|
151
|
-
name: "vite-plugin-fang-icon-replacer",
|
|
152
|
-
// 使用 enforce 确保在 Vue 插件之前执行
|
|
153
|
-
enforce: "pre",
|
|
154
|
-
// 转换代码
|
|
155
|
-
transform(code, id) {
|
|
156
|
-
if (!shouldProcess(id)) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
const components = findComponents(code, targetComponents);
|
|
161
|
-
if (components.length === 0) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
let transformedCode = code;
|
|
165
|
-
let replacedCount = 0;
|
|
166
|
-
const imports = /* @__PURE__ */ new Set();
|
|
167
|
-
imports.add(
|
|
168
|
-
`import ${name} from '@fangzhongya/icons/icon/index'`
|
|
169
|
-
);
|
|
170
|
-
for (let i = components.length - 1; i >= 0; i--) {
|
|
171
|
-
const component = components[i];
|
|
172
|
-
if (component) {
|
|
173
|
-
const { text, imptext } = replaceComponent(
|
|
174
|
-
component,
|
|
175
|
-
type,
|
|
176
|
-
dynamic,
|
|
177
|
-
customReplacement
|
|
178
|
-
);
|
|
179
|
-
imports.add(imptext);
|
|
180
|
-
if (text !== component.fullMatch) {
|
|
181
|
-
transformedCode = transformedCode.slice(0, component.start) + text + transformedCode.slice(component.end);
|
|
182
|
-
replacedCount++;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (/.vue$/.test(id)) {
|
|
187
|
-
const i = transformedCode.indexOf("</script>");
|
|
188
|
-
transformedCode = transformedCode.slice(0, i) + [...imports].join(";") + transformedCode.slice(i);
|
|
189
|
-
} else {
|
|
190
|
-
transformedCode = [...imports].join(";") + transformedCode;
|
|
191
|
-
}
|
|
192
|
-
if (replacedCount > 0) {
|
|
193
|
-
return {
|
|
194
|
-
code: transformedCode,
|
|
195
|
-
map: null
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
} catch (error) {
|
|
199
|
-
console.error(`\u5904\u7406\u6587\u4EF6 ${id} \u65F6\u51FA\u9519:`, error);
|
|
200
|
-
}
|
|
201
|
-
return null;
|
|
202
|
-
},
|
|
203
|
-
// 处理热更新
|
|
204
|
-
handleHotUpdate({
|
|
205
|
-
file,
|
|
206
|
-
server
|
|
207
|
-
}) {
|
|
208
|
-
if (shouldProcess(file)) {
|
|
209
|
-
server.ws.send({
|
|
210
|
-
type: "full-reload"
|
|
211
|
-
});
|
|
212
|
-
return [];
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
exports.simpleFangIcon = simpleFangIcon;
|
package/dist/vite/index2.d.cts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
interface ComponentAttributes {
|
|
4
|
-
name: string;
|
|
5
|
-
[key: string]: string | boolean | number;
|
|
6
|
-
}
|
|
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 PluginOptions {
|
|
20
|
-
name?: string;
|
|
21
|
-
type?: string;
|
|
22
|
-
customReplacement?: IconReplacement;
|
|
23
|
-
directory?: string;
|
|
24
|
-
mobile?: boolean;
|
|
25
|
-
dynamic?: boolean;
|
|
26
|
-
}
|
|
27
|
-
declare function simpleFangIcon(options: PluginOptions): Plugin;
|
|
28
|
-
|
|
29
|
-
export { type ComponentAttributes, type ComponentMatchInfo, type IconReplacement, type PluginOptions, simpleFangIcon };
|
package/dist/vite/index2.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
interface ComponentAttributes {
|
|
4
|
-
name: string;
|
|
5
|
-
[key: string]: string | boolean | number;
|
|
6
|
-
}
|
|
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 PluginOptions {
|
|
20
|
-
name?: string;
|
|
21
|
-
type?: string;
|
|
22
|
-
customReplacement?: IconReplacement;
|
|
23
|
-
directory?: string;
|
|
24
|
-
mobile?: boolean;
|
|
25
|
-
dynamic?: boolean;
|
|
26
|
-
}
|
|
27
|
-
declare function simpleFangIcon(options: PluginOptions): Plugin;
|
|
28
|
-
|
|
29
|
-
export { type ComponentAttributes, type ComponentMatchInfo, type IconReplacement, type PluginOptions, simpleFangIcon };
|
package/dist/vite/index2.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getIconifySVG,
|
|
3
|
-
lineToLargeHump
|
|
4
|
-
} from "../chunk-HSJ3RNOH.js";
|
|
5
|
-
import "../chunk-MOHILOKE.js";
|
|
6
|
-
import {
|
|
7
|
-
json_default
|
|
8
|
-
} from "../chunk-7HXPUNMG.js";
|
|
9
|
-
import "../chunk-MLKGABMK.js";
|
|
10
|
-
|
|
11
|
-
// packages/vite/index2.ts
|
|
12
|
-
function parseAttributes(attrString) {
|
|
13
|
-
const attributes = { name: "" };
|
|
14
|
-
const attrRegex = /(?:@|:|v-bind:)?([\w-]+)(?:="([^"]*)"|='([^']*)')/g;
|
|
15
|
-
let match;
|
|
16
|
-
while ((match = attrRegex.exec(attrString)) !== null) {
|
|
17
|
-
const name = match[1];
|
|
18
|
-
if (name) {
|
|
19
|
-
const value = match[2] || match[3] || "";
|
|
20
|
-
if (name === "name") {
|
|
21
|
-
attributes.name = value;
|
|
22
|
-
} else if (value === "true" || value === "false") {
|
|
23
|
-
attributes[name] = value === "true";
|
|
24
|
-
} else if (!isNaN(Number(value)) && value !== "") {
|
|
25
|
-
attributes[name] = Number(value);
|
|
26
|
-
} else {
|
|
27
|
-
attributes[name] = value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return attributes;
|
|
32
|
-
}
|
|
33
|
-
function hasStringNameAttribute(attrString) {
|
|
34
|
-
const nameRegex = /(?:^|\s)name="[^"]*"/i;
|
|
35
|
-
const singleQuoteRegex = /(?:^|\s)name='[^']*'/i;
|
|
36
|
-
return nameRegex.test(attrString) || singleQuoteRegex.test(attrString);
|
|
37
|
-
}
|
|
38
|
-
function isOnlyWhitespace(content) {
|
|
39
|
-
return !content || /^\s*$/.test(content);
|
|
40
|
-
}
|
|
41
|
-
function findComponents(code, name) {
|
|
42
|
-
const components = [];
|
|
43
|
-
for (const componentName of name) {
|
|
44
|
-
let currentIndex = 0;
|
|
45
|
-
while (currentIndex < code.length) {
|
|
46
|
-
const startTagIndex = code.indexOf(
|
|
47
|
-
`<${componentName}`,
|
|
48
|
-
currentIndex
|
|
49
|
-
);
|
|
50
|
-
if (startTagIndex === -1) break;
|
|
51
|
-
let tagEndIndex = code.indexOf(">", startTagIndex);
|
|
52
|
-
if (tagEndIndex === -1) break;
|
|
53
|
-
const startTag = code.slice(startTagIndex, tagEndIndex + 1);
|
|
54
|
-
const attrString = startTag.slice(componentName.length + 1, -1).trim();
|
|
55
|
-
if (!hasStringNameAttribute(attrString)) {
|
|
56
|
-
currentIndex = startTagIndex + 1;
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const attributes = parseAttributes(attrString);
|
|
60
|
-
if (!attributes.name) {
|
|
61
|
-
currentIndex = startTagIndex + 1;
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const isSelfClosing = startTag.endsWith("/>");
|
|
65
|
-
let endIndex;
|
|
66
|
-
let fullMatch;
|
|
67
|
-
if (isSelfClosing) {
|
|
68
|
-
endIndex = tagEndIndex + 1;
|
|
69
|
-
fullMatch = startTag;
|
|
70
|
-
} else {
|
|
71
|
-
const endTag = `</${componentName}>`;
|
|
72
|
-
let endTagIndex = code.indexOf(endTag, tagEndIndex + 1);
|
|
73
|
-
if (endTagIndex === -1) {
|
|
74
|
-
currentIndex = startTagIndex + 1;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
const content = code.slice(tagEndIndex + 1, endTagIndex);
|
|
78
|
-
if (!isOnlyWhitespace(content)) {
|
|
79
|
-
currentIndex = startTagIndex + 1;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
endIndex = endTagIndex + endTag.length;
|
|
83
|
-
fullMatch = code.slice(startTagIndex, endIndex);
|
|
84
|
-
}
|
|
85
|
-
components.push({
|
|
86
|
-
componentName,
|
|
87
|
-
fullMatch,
|
|
88
|
-
start: startTagIndex,
|
|
89
|
-
end: endIndex,
|
|
90
|
-
attributes,
|
|
91
|
-
isSelfClosing
|
|
92
|
-
});
|
|
93
|
-
currentIndex = endIndex;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return components;
|
|
97
|
-
}
|
|
98
|
-
function getText(iconName, match) {
|
|
99
|
-
const svg = getIconifySVG(json_default, iconName, 'v-bind="scope"');
|
|
100
|
-
const s = match.fullMatch.replace(`name="${iconName}"`, "").replace(`name='${iconName}'`, "").replace(`</${match.componentName}>`, "");
|
|
101
|
-
const text = `${s}<template #default="scope">${svg}</template></${match.componentName}>`;
|
|
102
|
-
return { text, imptext: "" };
|
|
103
|
-
}
|
|
104
|
-
function getImportName(iconName) {
|
|
105
|
-
return lineToLargeHump("fang-icon-" + iconName);
|
|
106
|
-
}
|
|
107
|
-
function getVue(iconName, match) {
|
|
108
|
-
const text = match.fullMatch.replace(`name="${iconName}"`, `:name="${getImportName(iconName)}"`).replace(`name='${iconName}'`, `:name='${getImportName(iconName)}'`);
|
|
109
|
-
return {
|
|
110
|
-
text,
|
|
111
|
-
imptext: `import ${getImportName(
|
|
112
|
-
iconName
|
|
113
|
-
)} from '@fangzhongya/icons/vue/${iconName}'`
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function replaceComponent(match, type, dynamic, customReplacement) {
|
|
117
|
-
const { attributes } = match;
|
|
118
|
-
const iconName = attributes.name;
|
|
119
|
-
if (customReplacement) {
|
|
120
|
-
return customReplacement(iconName, attributes);
|
|
121
|
-
}
|
|
122
|
-
let svgContent = json_default.icons[iconName];
|
|
123
|
-
if (!svgContent) {
|
|
124
|
-
return { text: match.fullMatch, imptext: "" };
|
|
125
|
-
}
|
|
126
|
-
if (!attributes.type && type == "svg" || attributes.type === "svg") {
|
|
127
|
-
if (dynamic) {
|
|
128
|
-
return getVue(iconName, match);
|
|
129
|
-
} else {
|
|
130
|
-
return getText(iconName, match);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return { text: match.fullMatch, imptext: "" };
|
|
134
|
-
}
|
|
135
|
-
function shouldProcess(id) {
|
|
136
|
-
const validExtensions = [".vue", ".jsx", ".tsx", ".js", ".ts"];
|
|
137
|
-
const hasValidExtension = validExtensions.some((ext) => id.endsWith(ext));
|
|
138
|
-
if (!hasValidExtension) return false;
|
|
139
|
-
if (id.includes("/node_modules/")) return false;
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
function simpleFangIcon(options) {
|
|
143
|
-
const {
|
|
144
|
-
name = "FangIcon",
|
|
145
|
-
type = "svg",
|
|
146
|
-
dynamic = true,
|
|
147
|
-
customReplacement
|
|
148
|
-
} = options;
|
|
149
|
-
const targetComponents = Array.isArray(name) ? name : [name];
|
|
150
|
-
return {
|
|
151
|
-
name: "vite-plugin-fang-icon-replacer",
|
|
152
|
-
// 使用 enforce 确保在 Vue 插件之前执行
|
|
153
|
-
enforce: "pre",
|
|
154
|
-
// 转换代码
|
|
155
|
-
transform(code, id) {
|
|
156
|
-
if (!shouldProcess(id)) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
const components = findComponents(code, targetComponents);
|
|
161
|
-
if (components.length === 0) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
let transformedCode = code;
|
|
165
|
-
let replacedCount = 0;
|
|
166
|
-
const imports = /* @__PURE__ */ new Set();
|
|
167
|
-
imports.add(
|
|
168
|
-
`import ${name} from '@fangzhongya/icons/icon/index'`
|
|
169
|
-
);
|
|
170
|
-
for (let i = components.length - 1; i >= 0; i--) {
|
|
171
|
-
const component = components[i];
|
|
172
|
-
if (component) {
|
|
173
|
-
const { text, imptext } = replaceComponent(
|
|
174
|
-
component,
|
|
175
|
-
type,
|
|
176
|
-
dynamic,
|
|
177
|
-
customReplacement
|
|
178
|
-
);
|
|
179
|
-
imports.add(imptext);
|
|
180
|
-
if (text !== component.fullMatch) {
|
|
181
|
-
transformedCode = transformedCode.slice(0, component.start) + text + transformedCode.slice(component.end);
|
|
182
|
-
replacedCount++;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (/.vue$/.test(id)) {
|
|
187
|
-
const i = transformedCode.indexOf("</script>");
|
|
188
|
-
transformedCode = transformedCode.slice(0, i) + [...imports].join(";") + transformedCode.slice(i);
|
|
189
|
-
} else {
|
|
190
|
-
transformedCode = [...imports].join(";") + transformedCode;
|
|
191
|
-
}
|
|
192
|
-
if (replacedCount > 0) {
|
|
193
|
-
return {
|
|
194
|
-
code: transformedCode,
|
|
195
|
-
map: null
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
} catch (error) {
|
|
199
|
-
console.error(`\u5904\u7406\u6587\u4EF6 ${id} \u65F6\u51FA\u9519:`, error);
|
|
200
|
-
}
|
|
201
|
-
return null;
|
|
202
|
-
},
|
|
203
|
-
// 处理热更新
|
|
204
|
-
handleHotUpdate({
|
|
205
|
-
file,
|
|
206
|
-
server
|
|
207
|
-
}) {
|
|
208
|
-
if (shouldProcess(file)) {
|
|
209
|
-
server.ws.send({
|
|
210
|
-
type: "full-reload"
|
|
211
|
-
});
|
|
212
|
-
return [];
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
export {
|
|
218
|
-
simpleFangIcon
|
|
219
|
-
};
|
package/dist/vite/index3.cjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkV6F7B2R3cjs = require('../chunk-V6F7B2R3.cjs');
|
|
4
|
-
require('../chunk-75ZPJI57.cjs');
|
|
5
|
-
|
|
6
|
-
// packages/vite/index3.ts
|
|
7
|
-
var _path = require('path');
|
|
8
|
-
var virtualModuleId = "virtual:fang-icon";
|
|
9
|
-
function simpleFangIcon(options = {}) {
|
|
10
|
-
const { name = "FangIcon", type = "svg", directory = "./svg" } = options;
|
|
11
|
-
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
12
|
-
if (type === "pub" && options.mobile) {
|
|
13
|
-
const outDir = _path.join.call(void 0, "./public/", directory);
|
|
14
|
-
console.log("outDir", outDir);
|
|
15
|
-
_chunkV6F7B2R3cjs.runDev.call(void 0, {
|
|
16
|
-
issort: true,
|
|
17
|
-
dir: "./node_modules/@fangzhongya/icons/dist/svg",
|
|
18
|
-
outDir,
|
|
19
|
-
extensions: ["svg"],
|
|
20
|
-
read: true,
|
|
21
|
-
fileCover: true,
|
|
22
|
-
isNeader: false
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const pub = `
|
|
26
|
-
import { defineComponent, h,} from 'vue'
|
|
27
|
-
import FangIcon from '@fangzhongya/icons/icon/index'
|
|
28
|
-
const component = defineComponent({
|
|
29
|
-
name: '${name}',
|
|
30
|
-
props: {
|
|
31
|
-
name: {
|
|
32
|
-
type: [String, Object],
|
|
33
|
-
},
|
|
34
|
-
default: {
|
|
35
|
-
type: String,
|
|
36
|
-
default: '${type}'
|
|
37
|
-
},
|
|
38
|
-
directory: {
|
|
39
|
-
type: String,
|
|
40
|
-
default: '${directory}'
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
setup(props, { attrs }) {
|
|
44
|
-
return () => {
|
|
45
|
-
return h(FangIcon, {
|
|
46
|
-
...attrs,
|
|
47
|
-
name: props.name,
|
|
48
|
-
default: props.default,
|
|
49
|
-
directory: props.directory
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
// \u5BFC\u51FA\u5B89\u88C5\u51FD\u6570
|
|
55
|
-
export const install = (app) => {
|
|
56
|
-
app.component('${name}', component)
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default component;`;
|
|
60
|
-
const svg = `
|
|
61
|
-
import { defineComponent, h, computed} from 'vue'
|
|
62
|
-
import FangIcon from '@fangzhongya/icons/icon/index'
|
|
63
|
-
import icons from '@fangzhongya/icons/async'
|
|
64
|
-
const component = defineComponent({
|
|
65
|
-
name: '${name}',
|
|
66
|
-
props: {
|
|
67
|
-
name: {
|
|
68
|
-
type: [String, Object],
|
|
69
|
-
},
|
|
70
|
-
type: {
|
|
71
|
-
type: String,
|
|
72
|
-
},
|
|
73
|
-
default: {
|
|
74
|
-
type: String,
|
|
75
|
-
default: '${type}'
|
|
76
|
-
},
|
|
77
|
-
directory: {
|
|
78
|
-
type: String,
|
|
79
|
-
default: '${directory}'
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
setup(props, { attrs }) {
|
|
83
|
-
const iconName = computed(() => {
|
|
84
|
-
const name = props.name;
|
|
85
|
-
if (typeof name === 'string' && (props.type === 'svg' ||
|
|
86
|
-
(!props.type && props.default === 'svg'))) {
|
|
87
|
-
const icon = icons[name];
|
|
88
|
-
if(icon){
|
|
89
|
-
return icon;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return name;
|
|
93
|
-
});
|
|
94
|
-
return () => {
|
|
95
|
-
return h(FangIcon, {
|
|
96
|
-
...attrs,
|
|
97
|
-
name: iconName.value,
|
|
98
|
-
type: props.type,
|
|
99
|
-
default: props.default,
|
|
100
|
-
directory: props.directory
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
// \u5BFC\u51FA\u5B89\u88C5\u51FD\u6570
|
|
106
|
-
export const install = (app) => {
|
|
107
|
-
app.component('${name}', component)
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export default component;`;
|
|
111
|
-
const text = type === "svg" ? svg : pub;
|
|
112
|
-
return {
|
|
113
|
-
name: "simple-fang-icon",
|
|
114
|
-
resolveId(id) {
|
|
115
|
-
if (id === virtualModuleId) {
|
|
116
|
-
return resolvedVirtualModuleId;
|
|
117
|
-
}
|
|
118
|
-
return void 0;
|
|
119
|
-
},
|
|
120
|
-
load(id) {
|
|
121
|
-
if (id === resolvedVirtualModuleId) {
|
|
122
|
-
return text;
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
exports.simpleFangIcon = simpleFangIcon;
|
package/dist/vite/index3.d.cts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
interface PluginOptions {
|
|
4
|
-
name?: string;
|
|
5
|
-
type?: string;
|
|
6
|
-
directory?: string;
|
|
7
|
-
mobile?: boolean;
|
|
8
|
-
dynamic?: boolean;
|
|
9
|
-
}
|
|
10
|
-
declare function simpleFangIcon(options?: PluginOptions): Plugin;
|
|
11
|
-
|
|
12
|
-
export { simpleFangIcon };
|
package/dist/vite/index3.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
interface PluginOptions {
|
|
4
|
-
name?: string;
|
|
5
|
-
type?: string;
|
|
6
|
-
directory?: string;
|
|
7
|
-
mobile?: boolean;
|
|
8
|
-
dynamic?: boolean;
|
|
9
|
-
}
|
|
10
|
-
declare function simpleFangIcon(options?: PluginOptions): Plugin;
|
|
11
|
-
|
|
12
|
-
export { simpleFangIcon };
|