vadivam 0.0.80 → 0.0.81
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/README.md +4 -2
- package/dist/createIcons.js +7 -10
- package/dist/elements.js +4072 -4057
- package/dist/font/vadivam-solid.woff2 +0 -0
- package/dist/font/vadivam.woff2 +0 -0
- package/dist/lucide-aliases.js +1 -0
- package/dist/manifest.js +4684 -9368
- package/dist/migrate-lucide.js +22 -41
- package/dist/package-exports.js +392 -0
- package/dist/solid/createIcons.js +7 -10
- package/package.json +1 -1
package/dist/migrate-lucide.js
CHANGED
|
@@ -1,33 +1,19 @@
|
|
|
1
1
|
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { lucideAliases } from "./lucide-aliases.js";
|
|
3
|
+
import { lucideAliases, lucideComponentAliases } from "./lucide-aliases.js";
|
|
4
4
|
import { icons } from "./manifest.js";
|
|
5
|
+
import { lucidePackages, manualLucidePackages, packageExports, siteUrl } from "./package-exports.js";
|
|
5
6
|
|
|
6
7
|
// Every Vadivam icon keeps its Lucide name, and each framework package mirrors
|
|
7
8
|
// the matching Lucide package's API with Lucide renamed to Vadivam. So moving
|
|
8
9
|
// over is a package rename plus `Lucide` -> `Vadivam` in imported identifiers.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"lucide-react": "vadivam-react",
|
|
12
|
-
"lucide-react-native": "vadivam-react-native",
|
|
13
|
-
"lucide-vue-next": "vadivam-vue",
|
|
14
|
-
"@lucide/vue": "vadivam-vue",
|
|
15
|
-
"lucide-svelte": "vadivam-svelte",
|
|
16
|
-
"@lucide/svelte": "vadivam-svelte",
|
|
17
|
-
"lucide-solid": "vadivam-solid",
|
|
18
|
-
"lucide-preact": "vadivam-preact",
|
|
19
|
-
"@lucide/astro": "vadivam-astro",
|
|
20
|
-
};
|
|
10
|
+
// The package names come from scripts/packages.mjs, through package-exports.js.
|
|
11
|
+
export const packageMap = lucidePackages;
|
|
21
12
|
|
|
22
13
|
// Packages whose API differs enough that they need a hand migration.
|
|
23
|
-
const manualPackages =
|
|
24
|
-
"lucide-angular": "vadivam-angular uses one standalone directive per icon",
|
|
25
|
-
"@lucide/angular": "vadivam-angular uses one standalone directive per icon",
|
|
26
|
-
"lucide-static": "use vadivam/icons/<name>.svg, vadivam/strings/<name>, the sprite, or the font",
|
|
27
|
-
"lucide-vue": "Vue 2 is not supported; vadivam-vue targets Vue 3",
|
|
28
|
-
};
|
|
14
|
+
const manualPackages = manualLucidePackages;
|
|
29
15
|
|
|
30
|
-
export const guideUrl =
|
|
16
|
+
export const guideUrl = `${siteUrl}/docs/migrate-from-lucide`;
|
|
31
17
|
|
|
32
18
|
const sourceExtensions = new Set([
|
|
33
19
|
".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts",
|
|
@@ -41,24 +27,18 @@ const skippedDirectories = new Set([
|
|
|
41
27
|
const dependencyFields = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
|
|
42
28
|
|
|
43
29
|
const iconNames = new Set(icons.map((icon) => icon.name));
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
30
|
+
// Every name each package exports, from the lists its generator wrote.
|
|
31
|
+
const componentNames = icons.map((icon) => icon.componentName);
|
|
32
|
+
const exportsByPackage = new Map(
|
|
33
|
+
Object.entries(packageExports).map(([packageName, { names, iconAliases }]) => [
|
|
34
|
+
packageName,
|
|
35
|
+
new Set([
|
|
36
|
+
"default",
|
|
37
|
+
...names,
|
|
38
|
+
...iconAliases.flatMap(([prefix, suffix]) => componentNames.map((name) => `${prefix}${name}${suffix}`)),
|
|
39
|
+
]),
|
|
40
|
+
]),
|
|
49
41
|
);
|
|
50
|
-
const iconExports = new Set(
|
|
51
|
-
icons.flatMap(({ componentName }) => [componentName, `${componentName}Icon`, `Vadivam${componentName}`]),
|
|
52
|
-
);
|
|
53
|
-
// The non-icon exports across the core and framework packages.
|
|
54
|
-
const apiExports = new Set([
|
|
55
|
-
"Icon", "createIcon", "createVadivamIcon", "icons", "iconNames", "dynamicIconImports", "DynamicIcon",
|
|
56
|
-
"VadivamProvider", "useVadivamContext", "provideVadivam", "VadivamContext", "VADIVAM_CONTEXT",
|
|
57
|
-
"getVadivamContext", "setVadivamProps", "createElement", "createIcons", "manifest", "iconsByName",
|
|
58
|
-
"categories", "IconName", "IconNode", "Icons", "SVGElementType", "SVGAttributes", "SVGProps",
|
|
59
|
-
"VadivamProps", "VadivamIcon", "IconDefinition", "CreateIconsOptions", "IconCategoryId",
|
|
60
|
-
"VadivamIconCategory", "VadivamIconMetadata", "default",
|
|
61
|
-
]);
|
|
62
42
|
|
|
63
43
|
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\.mock\s*\(\s*)(["'])([^"'\n]+)\2/g;
|
|
64
44
|
// Named bindings taken from a Vadivam package: imports, re-exports, and
|
|
@@ -98,7 +78,7 @@ export function mapSpecifier(specifier) {
|
|
|
98
78
|
/** The canonical export for a deprecated Lucide one: AlertCircleIcon -> CircleExclamationPointIcon. */
|
|
99
79
|
function canonicalExport(name) {
|
|
100
80
|
const [, prefix, base, suffix] = name.match(/^(Vadivam)?(\w+?)(Icon)?$/) ?? [];
|
|
101
|
-
const canonical = base &&
|
|
81
|
+
const canonical = base && Object.prototype.hasOwnProperty.call(lucideComponentAliases, base) && lucideComponentAliases[base];
|
|
102
82
|
return canonical ? `${prefix ?? ""}${canonical}${suffix ?? ""}` : name;
|
|
103
83
|
}
|
|
104
84
|
|
|
@@ -195,10 +175,11 @@ export function migrateSource(text, { styles = false } = {}) {
|
|
|
195
175
|
});
|
|
196
176
|
for (const { pattern } of bindingLists) {
|
|
197
177
|
for (const [, names, packageName] of output.matchAll(pattern)) {
|
|
198
|
-
|
|
178
|
+
const exported = exportsByPackage.get(packageName);
|
|
179
|
+
if (!exported) continue;
|
|
199
180
|
for (const [, , imported] of names.matchAll(bindingEntry)) {
|
|
200
|
-
if (
|
|
201
|
-
warnings.push(`${imported} from ${packageName}: not a Vadivam export; search
|
|
181
|
+
if (exported.has(imported)) continue;
|
|
182
|
+
warnings.push(`${imported} from ${packageName}: not a Vadivam export; search ${siteUrl}/?q=${encodeURIComponent(imported)}`);
|
|
202
183
|
}
|
|
203
184
|
}
|
|
204
185
|
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
// Generated with each package: its non-icon exports and the aliases ([prefix, suffix]) each icon is exported under,
|
|
2
|
+
// the Lucide packages it replaces, and the ones that need a hand migration.
|
|
3
|
+
export const packageExports = {
|
|
4
|
+
"vadivam": {
|
|
5
|
+
"names": [
|
|
6
|
+
"createElement",
|
|
7
|
+
"createIcons",
|
|
8
|
+
"icons",
|
|
9
|
+
"manifest",
|
|
10
|
+
"iconNames",
|
|
11
|
+
"iconsByName",
|
|
12
|
+
"categories",
|
|
13
|
+
"styles",
|
|
14
|
+
"CreateIconsOptions",
|
|
15
|
+
"IconCategoryId",
|
|
16
|
+
"VadivamIconCategory",
|
|
17
|
+
"VadivamIconMetadata",
|
|
18
|
+
"VadivamIconStyle",
|
|
19
|
+
"VadivamIconStyleId",
|
|
20
|
+
"IconName",
|
|
21
|
+
"IconNode",
|
|
22
|
+
"Icons",
|
|
23
|
+
"SVGElementType",
|
|
24
|
+
"SVGProps"
|
|
25
|
+
],
|
|
26
|
+
"iconAliases": [
|
|
27
|
+
[
|
|
28
|
+
"",
|
|
29
|
+
""
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"vadivam-react": {
|
|
34
|
+
"names": [
|
|
35
|
+
"Icon",
|
|
36
|
+
"createIcon",
|
|
37
|
+
"createVadivamIcon",
|
|
38
|
+
"icons",
|
|
39
|
+
"VadivamProvider",
|
|
40
|
+
"useVadivamContext",
|
|
41
|
+
"IconName",
|
|
42
|
+
"IconNode",
|
|
43
|
+
"SVGAttributes",
|
|
44
|
+
"SVGElementType",
|
|
45
|
+
"VadivamIcon",
|
|
46
|
+
"VadivamProps",
|
|
47
|
+
"IconProps",
|
|
48
|
+
"VadivamProviderProps",
|
|
49
|
+
"DynamicIcon",
|
|
50
|
+
"DynamicIconProps",
|
|
51
|
+
"dynamicIconImports",
|
|
52
|
+
"iconNames",
|
|
53
|
+
"DynamicIconModule",
|
|
54
|
+
"IconName"
|
|
55
|
+
],
|
|
56
|
+
"iconAliases": [
|
|
57
|
+
[
|
|
58
|
+
"",
|
|
59
|
+
""
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
"",
|
|
63
|
+
"Icon"
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
"Vadivam",
|
|
67
|
+
""
|
|
68
|
+
]
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
"vadivam-react-native": {
|
|
72
|
+
"names": [
|
|
73
|
+
"Icon",
|
|
74
|
+
"IconProps",
|
|
75
|
+
"createVadivamIcon",
|
|
76
|
+
"VadivamProvider",
|
|
77
|
+
"useVadivamContext",
|
|
78
|
+
"VadivamProviderProps",
|
|
79
|
+
"dynamicIconImports",
|
|
80
|
+
"iconNames",
|
|
81
|
+
"IconName",
|
|
82
|
+
"IconNode",
|
|
83
|
+
"SVGElementType",
|
|
84
|
+
"VadivamIcon",
|
|
85
|
+
"VadivamProps",
|
|
86
|
+
"DynamicIcon",
|
|
87
|
+
"DynamicIconProps",
|
|
88
|
+
"dynamicIconImports",
|
|
89
|
+
"iconNames"
|
|
90
|
+
],
|
|
91
|
+
"iconAliases": [
|
|
92
|
+
[
|
|
93
|
+
"",
|
|
94
|
+
""
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
"",
|
|
98
|
+
"Icon"
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
"Vadivam",
|
|
102
|
+
""
|
|
103
|
+
]
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
"vadivam-vue": {
|
|
107
|
+
"names": [
|
|
108
|
+
"Icon",
|
|
109
|
+
"createVadivamIcon",
|
|
110
|
+
"icons",
|
|
111
|
+
"VADIVAM_CONTEXT",
|
|
112
|
+
"VadivamProvider",
|
|
113
|
+
"provideVadivam",
|
|
114
|
+
"useVadivamContext",
|
|
115
|
+
"dynamicIconImports",
|
|
116
|
+
"iconNames",
|
|
117
|
+
"IconName",
|
|
118
|
+
"IconNode",
|
|
119
|
+
"SVGElementType",
|
|
120
|
+
"VadivamIcon",
|
|
121
|
+
"VadivamProps",
|
|
122
|
+
"DynamicIcon",
|
|
123
|
+
"DynamicIconProps",
|
|
124
|
+
"dynamicIconImports",
|
|
125
|
+
"iconNames"
|
|
126
|
+
],
|
|
127
|
+
"iconAliases": [
|
|
128
|
+
[
|
|
129
|
+
"",
|
|
130
|
+
""
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
"",
|
|
134
|
+
"Icon"
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
"Vadivam",
|
|
138
|
+
""
|
|
139
|
+
]
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
"vadivam-svelte": {
|
|
143
|
+
"names": [
|
|
144
|
+
"Icon",
|
|
145
|
+
"VadivamProvider",
|
|
146
|
+
"createVadivamIcon",
|
|
147
|
+
"icons",
|
|
148
|
+
"VADIVAM_CONTEXT",
|
|
149
|
+
"getVadivamContext",
|
|
150
|
+
"setVadivamProps",
|
|
151
|
+
"dynamicIconImports",
|
|
152
|
+
"iconNames",
|
|
153
|
+
"IconDefinition",
|
|
154
|
+
"IconName",
|
|
155
|
+
"IconNode",
|
|
156
|
+
"SVGElementType",
|
|
157
|
+
"VadivamIcon",
|
|
158
|
+
"VadivamProps"
|
|
159
|
+
],
|
|
160
|
+
"iconAliases": [
|
|
161
|
+
[
|
|
162
|
+
"",
|
|
163
|
+
""
|
|
164
|
+
],
|
|
165
|
+
[
|
|
166
|
+
"",
|
|
167
|
+
"Icon"
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
"Vadivam",
|
|
171
|
+
""
|
|
172
|
+
]
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
"vadivam-solid": {
|
|
176
|
+
"names": [
|
|
177
|
+
"Icon",
|
|
178
|
+
"createVadivamIcon",
|
|
179
|
+
"icons",
|
|
180
|
+
"VadivamContext",
|
|
181
|
+
"VadivamProvider",
|
|
182
|
+
"useVadivamContext",
|
|
183
|
+
"dynamicIconImports",
|
|
184
|
+
"iconNames",
|
|
185
|
+
"IconName",
|
|
186
|
+
"IconNode",
|
|
187
|
+
"SVGElementType",
|
|
188
|
+
"VadivamIcon",
|
|
189
|
+
"VadivamProps",
|
|
190
|
+
"VadivamProviderProps",
|
|
191
|
+
"DynamicIcon",
|
|
192
|
+
"DynamicIconProps",
|
|
193
|
+
"dynamicIconImports",
|
|
194
|
+
"iconNames"
|
|
195
|
+
],
|
|
196
|
+
"iconAliases": [
|
|
197
|
+
[
|
|
198
|
+
"",
|
|
199
|
+
""
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
"",
|
|
203
|
+
"Icon"
|
|
204
|
+
],
|
|
205
|
+
[
|
|
206
|
+
"Vadivam",
|
|
207
|
+
""
|
|
208
|
+
]
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
"vadivam-preact": {
|
|
212
|
+
"names": [
|
|
213
|
+
"Icon",
|
|
214
|
+
"createVadivamIcon",
|
|
215
|
+
"icons",
|
|
216
|
+
"VadivamContext",
|
|
217
|
+
"VadivamProvider",
|
|
218
|
+
"useVadivamContext",
|
|
219
|
+
"dynamicIconImports",
|
|
220
|
+
"iconNames",
|
|
221
|
+
"IconName",
|
|
222
|
+
"IconNode",
|
|
223
|
+
"SVGElementType",
|
|
224
|
+
"VadivamIcon",
|
|
225
|
+
"VadivamProps",
|
|
226
|
+
"VadivamProviderProps",
|
|
227
|
+
"DynamicIcon",
|
|
228
|
+
"DynamicIconProps",
|
|
229
|
+
"dynamicIconImports",
|
|
230
|
+
"iconNames"
|
|
231
|
+
],
|
|
232
|
+
"iconAliases": [
|
|
233
|
+
[
|
|
234
|
+
"",
|
|
235
|
+
""
|
|
236
|
+
],
|
|
237
|
+
[
|
|
238
|
+
"",
|
|
239
|
+
"Icon"
|
|
240
|
+
],
|
|
241
|
+
[
|
|
242
|
+
"Vadivam",
|
|
243
|
+
""
|
|
244
|
+
]
|
|
245
|
+
]
|
|
246
|
+
},
|
|
247
|
+
"vadivam-astro": {
|
|
248
|
+
"names": [
|
|
249
|
+
"Icon",
|
|
250
|
+
"createVadivamIcon",
|
|
251
|
+
"icons",
|
|
252
|
+
"dynamicIconImports",
|
|
253
|
+
"iconNames",
|
|
254
|
+
"IconDefinition",
|
|
255
|
+
"IconName",
|
|
256
|
+
"IconNode",
|
|
257
|
+
"SVGElementType",
|
|
258
|
+
"VadivamIcon",
|
|
259
|
+
"VadivamProps"
|
|
260
|
+
],
|
|
261
|
+
"iconAliases": [
|
|
262
|
+
[
|
|
263
|
+
"",
|
|
264
|
+
""
|
|
265
|
+
],
|
|
266
|
+
[
|
|
267
|
+
"",
|
|
268
|
+
"Icon"
|
|
269
|
+
],
|
|
270
|
+
[
|
|
271
|
+
"Vadivam",
|
|
272
|
+
""
|
|
273
|
+
]
|
|
274
|
+
]
|
|
275
|
+
},
|
|
276
|
+
"vadivam-angular": {
|
|
277
|
+
"names": [
|
|
278
|
+
"IconNode",
|
|
279
|
+
"SVGElementType",
|
|
280
|
+
"VadivamIconData",
|
|
281
|
+
"VadivamConfig",
|
|
282
|
+
"IconName",
|
|
283
|
+
"VADIVAM_CONFIG",
|
|
284
|
+
"provideVadivamConfig",
|
|
285
|
+
"createVadivamIcon",
|
|
286
|
+
"VadivamIconBase",
|
|
287
|
+
"Icon",
|
|
288
|
+
"icons",
|
|
289
|
+
"DynamicIconModule",
|
|
290
|
+
"dynamicIconImports",
|
|
291
|
+
"iconNames",
|
|
292
|
+
"DynamicIcon"
|
|
293
|
+
],
|
|
294
|
+
"iconAliases": [
|
|
295
|
+
[
|
|
296
|
+
"",
|
|
297
|
+
""
|
|
298
|
+
],
|
|
299
|
+
[
|
|
300
|
+
"",
|
|
301
|
+
"Icon"
|
|
302
|
+
],
|
|
303
|
+
[
|
|
304
|
+
"Vadivam",
|
|
305
|
+
""
|
|
306
|
+
],
|
|
307
|
+
[
|
|
308
|
+
"",
|
|
309
|
+
"Node"
|
|
310
|
+
]
|
|
311
|
+
]
|
|
312
|
+
},
|
|
313
|
+
"vadivam-qwik": {
|
|
314
|
+
"names": [
|
|
315
|
+
"Icon",
|
|
316
|
+
"createVadivamIcon",
|
|
317
|
+
"icons",
|
|
318
|
+
"IconProps",
|
|
319
|
+
"IconName",
|
|
320
|
+
"IconNode",
|
|
321
|
+
"SVGElementType",
|
|
322
|
+
"VadivamIcon",
|
|
323
|
+
"VadivamProps"
|
|
324
|
+
],
|
|
325
|
+
"iconAliases": [
|
|
326
|
+
[
|
|
327
|
+
"",
|
|
328
|
+
""
|
|
329
|
+
],
|
|
330
|
+
[
|
|
331
|
+
"",
|
|
332
|
+
"Icon"
|
|
333
|
+
],
|
|
334
|
+
[
|
|
335
|
+
"Vadivam",
|
|
336
|
+
""
|
|
337
|
+
]
|
|
338
|
+
]
|
|
339
|
+
},
|
|
340
|
+
"vadivam-lit": {
|
|
341
|
+
"names": [
|
|
342
|
+
"Icon",
|
|
343
|
+
"createVadivamIcon",
|
|
344
|
+
"icons",
|
|
345
|
+
"dynamicIconImports",
|
|
346
|
+
"iconNames",
|
|
347
|
+
"IconProps",
|
|
348
|
+
"IconName",
|
|
349
|
+
"IconNode",
|
|
350
|
+
"SVGElementType",
|
|
351
|
+
"VadivamIcon",
|
|
352
|
+
"VadivamProps",
|
|
353
|
+
"DynamicIcon",
|
|
354
|
+
"DynamicIconProps",
|
|
355
|
+
"dynamicIconImports",
|
|
356
|
+
"iconNames"
|
|
357
|
+
],
|
|
358
|
+
"iconAliases": [
|
|
359
|
+
[
|
|
360
|
+
"",
|
|
361
|
+
""
|
|
362
|
+
],
|
|
363
|
+
[
|
|
364
|
+
"",
|
|
365
|
+
"Icon"
|
|
366
|
+
],
|
|
367
|
+
[
|
|
368
|
+
"Vadivam",
|
|
369
|
+
""
|
|
370
|
+
]
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
export const lucidePackages = {
|
|
375
|
+
"lucide": "vadivam",
|
|
376
|
+
"lucide-react": "vadivam-react",
|
|
377
|
+
"lucide-react-native": "vadivam-react-native",
|
|
378
|
+
"lucide-vue-next": "vadivam-vue",
|
|
379
|
+
"@lucide/vue": "vadivam-vue",
|
|
380
|
+
"lucide-svelte": "vadivam-svelte",
|
|
381
|
+
"@lucide/svelte": "vadivam-svelte",
|
|
382
|
+
"lucide-solid": "vadivam-solid",
|
|
383
|
+
"lucide-preact": "vadivam-preact",
|
|
384
|
+
"@lucide/astro": "vadivam-astro"
|
|
385
|
+
};
|
|
386
|
+
export const manualLucidePackages = {
|
|
387
|
+
"lucide-static": "use vadivam/icons/<name>.svg, vadivam/strings/<name>, the sprite, or the font",
|
|
388
|
+
"lucide-vue": "Vue 2 is not supported; vadivam-vue targets Vue 3",
|
|
389
|
+
"lucide-angular": "vadivam-angular uses one standalone directive per icon",
|
|
390
|
+
"@lucide/angular": "vadivam-angular uses one standalone directive per icon"
|
|
391
|
+
};
|
|
392
|
+
export const siteUrl = "https://vadivam.praveenjuge.com";
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import createElement from "./createElement.js";
|
|
2
2
|
import defaultAttributes from "./defaultAttributes.js";
|
|
3
|
+
import { sanitizeRootAttributes } from "../runtimePolicy.js";
|
|
3
4
|
|
|
4
5
|
function attributes(element) {
|
|
5
6
|
return Object.fromEntries(Array.from(element.attributes, ({ name, value }) => [name, value]));
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
return typeof value === "string" ? value.split(/\s+/).filter(Boolean) : [];
|
|
10
|
-
}
|
|
11
|
-
function hasAccessibleName(attrs) {
|
|
12
|
-
return Object.keys(attrs).some((name) => name.startsWith("aria-") || name === "role" || name === "title");
|
|
13
|
-
}
|
|
8
|
+
function mergeClasses(...values) { return values.flatMap((value) => typeof value === "string" ? value.split(/\s+/) : []).filter((value, index, all) => value && all.indexOf(value) === index).join(" "); }
|
|
9
|
+
function isLabelled(title, attributeNames) { return Boolean(title) || attributeNames.some((name) => name.startsWith("aria-") || name === "role" || name === "title"); }
|
|
14
10
|
function replaceElement(element, { nameAttr, icons, attrs }) {
|
|
15
11
|
const name = element.getAttribute(nameAttr);
|
|
16
12
|
if (!name) return;
|
|
@@ -21,8 +17,8 @@ function replaceElement(element, { nameAttr, icons, attrs }) {
|
|
|
21
17
|
return;
|
|
22
18
|
}
|
|
23
19
|
const elementAttrs = attributes(element);
|
|
24
|
-
const iconAttrs = { ...defaultAttributes, [nameAttr]: name, ...(
|
|
25
|
-
iconAttrs.class =
|
|
20
|
+
const iconAttrs = { ...defaultAttributes, [nameAttr]: name, ...(isLabelled(null, Object.keys(sanitizeRootAttributes({ ...attrs, ...elementAttrs }))) ? {} : { "aria-hidden": "true" }), ...attrs, ...elementAttrs };
|
|
21
|
+
iconAttrs.class = mergeClasses("vadivam", `vadivam-${name}`, elementAttrs.class, ...[attrs.class].flat());
|
|
26
22
|
element.parentNode?.replaceChild(createElement(iconNode, iconAttrs), element);
|
|
27
23
|
}
|
|
28
24
|
|
|
@@ -30,7 +26,8 @@ export function createIcons({ icons = {}, nameAttr = "data-vadivam", attrs = {},
|
|
|
30
26
|
if (!Object.keys(icons).length) throw new Error("Please provide an icons object to createIcons().");
|
|
31
27
|
if (!root) throw new Error("createIcons() only works in a browser environment.");
|
|
32
28
|
if (!/^[A-Za-z_:][A-Za-z0-9_.:-]*$/.test(nameAttr)) throw new Error("createIcons() received an invalid nameAttr.");
|
|
33
|
-
|
|
29
|
+
// A valid attribute name may hold "." or ":", which a selector must escape.
|
|
30
|
+
for (const element of root.querySelectorAll(`[${nameAttr.replace(/[.:]/g, "\\$&")}]`)) replaceElement(element, { nameAttr, icons, attrs });
|
|
34
31
|
if (inTemplates) {
|
|
35
32
|
for (const template of root.querySelectorAll("template")) createIcons({ icons, nameAttr, attrs, root: template.content, inTemplates });
|
|
36
33
|
}
|