@fangzhongya/icons 0.0.13 → 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 +101 -2
- package/dist/iconify.d.ts +101 -2
- 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/vite/index2.js
CHANGED
|
@@ -1,77 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getIconifySVG,
|
|
3
|
+
icons
|
|
4
|
+
} from "../chunk-Y2JUP3JH.js";
|
|
5
|
+
import "../chunk-MOHILOKE.js";
|
|
1
6
|
import "../chunk-MLKGABMK.js";
|
|
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;
|
|
58
55
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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);
|
|
81
|
+
}
|
|
82
|
+
components.push({
|
|
83
|
+
componentName,
|
|
84
|
+
fullMatch,
|
|
85
|
+
start: startTagIndex,
|
|
86
|
+
end: endIndex,
|
|
87
|
+
attributes,
|
|
88
|
+
isSelfClosing
|
|
68
89
|
});
|
|
69
|
-
|
|
90
|
+
currentIndex = endIndex;
|
|
91
|
+
}
|
|
70
92
|
}
|
|
71
|
-
|
|
72
|
-
|
|
93
|
+
return components;
|
|
94
|
+
}
|
|
95
|
+
function getText(iconName, match) {
|
|
96
|
+
const svg = getIconifySVG(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 = 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
|
+
}
|
|
117
|
+
}
|
|
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
|
}
|