reburn-ui 0.3.2 → 0.3.4
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function icon_plugin():
|
|
1
|
+
import type { PreprocessorGroup } from 'svelte/compiler';
|
|
2
|
+
export declare function icon_plugin(): PreprocessorGroup;
|
|
@@ -6,113 +6,105 @@ import { parse } from 'svelte-parse-markup';
|
|
|
6
6
|
import { walk } from 'zimmerframe';
|
|
7
7
|
import { getAttrValue } from '../utils/getAttrValue.js';
|
|
8
8
|
import { isSvelteFile } from '../utils/isSvelteFile.js';
|
|
9
|
-
import { resolveConfig } from '../utils/resolveConfig.js';
|
|
10
9
|
import { generateComponentName } from './utils/generateComponentName.js';
|
|
11
10
|
import { generateIconComponent } from './utils/generateIconComponent.js';
|
|
12
11
|
import { serializeIconAttributes } from './utils/serializeIconAttributes.js';
|
|
13
|
-
const NAME = 'vite-plugin-icon
|
|
12
|
+
const NAME = 'vite-plugin-icon';
|
|
14
13
|
function isInstalledAsPackage() {
|
|
15
14
|
const local = process.env.LOCAL_REBURN_UI_INSTALLED;
|
|
16
|
-
return !
|
|
15
|
+
return !local;
|
|
17
16
|
}
|
|
18
17
|
const asPackage = isInstalledAsPackage();
|
|
18
|
+
const INCLUDES_ICON_TAG = /<icon/g;
|
|
19
19
|
export function icon_plugin() {
|
|
20
20
|
// Icon name to component name cache
|
|
21
21
|
const iconCache = new Map();
|
|
22
|
-
|
|
22
|
+
return {
|
|
23
23
|
name: NAME,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const imports = new Map();
|
|
40
|
-
async function update_element(node, nameAttribute) {
|
|
41
|
-
const iconName = nameAttribute.raw.trim();
|
|
42
|
-
if (!iconName.includes(':')) {
|
|
43
|
-
console.warn(`Icon "${iconName}" is not a valid icon name`);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
// Generate component name from icon name
|
|
47
|
-
const componentName = generateComponentName(iconName);
|
|
48
|
-
// Check if we already have this icon cached
|
|
49
|
-
let cached_component = iconCache.get(iconName);
|
|
50
|
-
if (!cached_component) {
|
|
51
|
-
try {
|
|
52
|
-
// Get icon data from Iconify
|
|
53
|
-
const [collection, icon] = iconName.split(':');
|
|
54
|
-
const filename = locate(collection);
|
|
55
|
-
const iconSet = JSON.parse(await readFile(filename, 'utf8'));
|
|
56
|
-
const iconData = getIconData(iconSet, icon);
|
|
57
|
-
if (!iconData) {
|
|
58
|
-
throw new Error(`Icon "${iconName}" not found`);
|
|
59
|
-
}
|
|
60
|
-
// Generate the component code
|
|
61
|
-
const import_statement = await generateIconComponent(iconName, iconData, asPackage);
|
|
62
|
-
imports.set(import_statement.importName, import_statement.path);
|
|
63
|
-
cached_component = componentName;
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
console.error(`Failed to load icon "${iconName}":`, error);
|
|
67
|
-
// Fallback to a simple div with error message
|
|
68
|
-
s.update(node.start, node.end, `<div>Icon "${iconName}" not found</div>`);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// Replace the icon tag with the component
|
|
73
|
-
let props = serializeIconAttributes(content, node.attributes);
|
|
74
|
-
s.update(node.start, node.end, `<${componentName} ${props} />`);
|
|
24
|
+
markup: async ({ content, filename }) => {
|
|
25
|
+
if (!filename || !isSvelteFile(filename) || !INCLUDES_ICON_TAG.test(content))
|
|
26
|
+
return { code: content };
|
|
27
|
+
const s = new MagicString(content);
|
|
28
|
+
const ast = parse(content, { filename, modern: true });
|
|
29
|
+
/**
|
|
30
|
+
* Import path to import name
|
|
31
|
+
* e.g. TablerChevronUp => __IMPORTED_ICON_0__
|
|
32
|
+
*/
|
|
33
|
+
const imports = new Map();
|
|
34
|
+
async function update_element(node, nameAttribute) {
|
|
35
|
+
const iconName = nameAttribute.raw.trim();
|
|
36
|
+
if (!iconName.includes(':')) {
|
|
37
|
+
console.warn(`Icon "${iconName}" is not a valid icon name`);
|
|
38
|
+
return;
|
|
75
39
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
40
|
+
// Generate component name from icon name
|
|
41
|
+
const componentName = generateComponentName(iconName);
|
|
42
|
+
// Check if we already have this icon cached
|
|
43
|
+
let cached_component = iconCache.get(iconName);
|
|
44
|
+
if (!cached_component) {
|
|
45
|
+
try {
|
|
46
|
+
// Get icon data from Iconify
|
|
47
|
+
const [collection, icon] = iconName.split(':');
|
|
48
|
+
const filename = locate(collection);
|
|
49
|
+
const iconSet = JSON.parse(await readFile(filename, 'utf8'));
|
|
50
|
+
const iconData = getIconData(iconSet, icon);
|
|
51
|
+
if (!iconData) {
|
|
52
|
+
throw new Error(`Icon "${iconName}" not found`);
|
|
86
53
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (typeof update === 'function') {
|
|
92
|
-
await update();
|
|
54
|
+
// Generate the component code
|
|
55
|
+
const import_statement = await generateIconComponent(iconName, iconData, asPackage);
|
|
56
|
+
imports.set(import_statement.importName, import_statement.path);
|
|
57
|
+
cached_component = componentName;
|
|
93
58
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
for (const [import_name, path] of imports.entries()) {
|
|
100
|
-
text += `\timport ${import_name} from "${path}";\n`;
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error(`Failed to load icon "${iconName}":`, error);
|
|
61
|
+
// Fallback to a simple div with error message
|
|
62
|
+
s.update(node.start, node.end, `<div>Icon "${iconName}" not found</div>`);
|
|
63
|
+
return;
|
|
101
64
|
}
|
|
102
65
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
66
|
+
// Replace the icon tag with the component
|
|
67
|
+
const props = serializeIconAttributes(content, node.attributes);
|
|
68
|
+
s.update(node.start, node.end, `<${componentName} ${props} />`);
|
|
69
|
+
}
|
|
70
|
+
const pending_ast_updates = [];
|
|
71
|
+
walk(ast, null, {
|
|
72
|
+
RegularElement(node, { next }) {
|
|
73
|
+
if ('name' in node && node.name === 'icon') {
|
|
74
|
+
// Get the name attribute
|
|
75
|
+
const nameAttr = getAttrValue(node, 'name');
|
|
76
|
+
if (!nameAttr || typeof nameAttr === 'boolean')
|
|
77
|
+
return;
|
|
78
|
+
pending_ast_updates.push(update_element(node, nameAttr));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
next();
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
for await (const update of pending_ast_updates) {
|
|
85
|
+
if (typeof update === 'function') {
|
|
86
|
+
// @ts-expect-error update is a function
|
|
87
|
+
await update();
|
|
106
88
|
}
|
|
107
|
-
|
|
108
|
-
|
|
89
|
+
}
|
|
90
|
+
// await Promise.all(pending_ast_updates);
|
|
91
|
+
// add imports
|
|
92
|
+
let text = '';
|
|
93
|
+
if (imports.size) {
|
|
94
|
+
for (const [import_name, path] of imports.entries()) {
|
|
95
|
+
text += `\timport ${import_name} from "${path}";\n`;
|
|
109
96
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
97
|
+
}
|
|
98
|
+
if (ast.instance) {
|
|
99
|
+
// @ts-expect-error instance.content.start is defined
|
|
100
|
+
s.appendLeft(ast.instance.content.start, text);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
s.prepend(`<script>${text}</script>\n`);
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
code: s.toString(),
|
|
107
|
+
};
|
|
115
108
|
},
|
|
116
109
|
};
|
|
117
|
-
return plugin;
|
|
118
110
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reburn-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"analyze": "ANALYZE=true bun run build",
|
|
8
8
|
"dev": "LOCAL_REBURN_UI_INSTALLED=true vite dev",
|
|
9
|
-
"build": "LOCAL_REBURN_UI_INSTALLED=true vite build",
|
|
9
|
+
"build": "bun run build-icon-tool && LOCAL_REBURN_UI_INSTALLED=true vite build",
|
|
10
10
|
"preview": "vite preview",
|
|
11
11
|
"prepare": "svelte-kit sync || echo ''",
|
|
12
|
-
"prepack": "LOCAL_REBURN_UI_INSTALLED=true bun vite build && bun svelte-kit sync && bun svelte-package && bun publint",
|
|
12
|
+
"prepack": "LOCAL_REBURN_UI_INSTALLED=true bun vite build && bun svelte-kit sync && PREPACK=true bun svelte-package && bun publint",
|
|
13
13
|
"transform-css-files": "bun run scripts/transform-css-files.ts",
|
|
14
|
-
"lint": "eslint ."
|
|
14
|
+
"lint": "eslint .",
|
|
15
|
+
"build-icon-tool": "bun run scripts/build-icon-tool.ts"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"dist",
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
54
|
"@floating-ui/dom": "^1.7.3",
|
|
54
|
-
"@iconify/json": "^2.2.
|
|
55
|
+
"@iconify/json": "^2.2.366",
|
|
55
56
|
"@iconify/tools": "^4.1.2",
|
|
56
57
|
"@iconify/types": "^2.0.0",
|
|
57
58
|
"@iconify/utils": "^2.3.0",
|
|
@@ -84,10 +85,10 @@
|
|
|
84
85
|
"publint": "^0.3.12",
|
|
85
86
|
"sass-embedded": "^1.89.2",
|
|
86
87
|
"sonda": "^0.9.0",
|
|
87
|
-
"svelte": "^5.37.
|
|
88
|
-
"svelte-check": "^4.3.
|
|
88
|
+
"svelte": "^5.37.3",
|
|
89
|
+
"svelte-check": "^4.3.1",
|
|
89
90
|
"typescript": "^5.9.2",
|
|
90
|
-
"typescript-eslint": "^8.
|
|
91
|
+
"typescript-eslint": "^8.39.0",
|
|
91
92
|
"vite": "^7.0.6"
|
|
92
93
|
},
|
|
93
94
|
"keywords": [
|