cdui-js 1.0.3 → 1.0.5
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/build/icons.ts +8 -8
- package/package.json +3 -4
- package/src/components/Switch.tsx +7 -7
- package/src/ssr/render.ts +22 -19
- package/src/ssr/window/storage.ts +25 -21
package/build/icons.ts
CHANGED
|
@@ -2,12 +2,12 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* 从指定 svg
|
|
5
|
+
* 从指定 svg 文件加载 symbol 内容
|
|
6
6
|
*
|
|
7
7
|
* @param svgFile 指定 svg 文件
|
|
8
8
|
* @param removeColor 去色标记 fill: 去填充色 stroke:去描边色 both:都去
|
|
9
9
|
*/
|
|
10
|
-
export const
|
|
10
|
+
export const loadIconFile = (svgFile: string, removeColor?: 'fill' | 'stroke' | 'both'): string => {
|
|
11
11
|
let name = path.basename(svgFile).replace('.svg', '');
|
|
12
12
|
let svg = fs.readFileSync(svgFile, 'utf8');
|
|
13
13
|
let index = svg.indexOf(' viewBox="');
|
|
@@ -46,7 +46,7 @@ export const readIconFile = (svgFile: string, removeColor?: 'fill' | 'stroke' |
|
|
|
46
46
|
* @param svgDirectory 指定 svg 目录
|
|
47
47
|
* @param removeColor 去色标记 fill: 去填充色 stroke:去描边色 both:都去
|
|
48
48
|
*/
|
|
49
|
-
export const
|
|
49
|
+
export const loadIconsDirectory = (svgDirectory: string, removeColor?: 'fill' | 'stroke' | 'both'): string => {
|
|
50
50
|
const outputs = [];
|
|
51
51
|
const files = fs.readdirSync(svgDirectory);
|
|
52
52
|
|
|
@@ -54,7 +54,7 @@ export const readIconsDirectory = (svgDirectory: string, removeColor?: 'fill' |
|
|
|
54
54
|
let file = path.join(svgDirectory, files[i]);
|
|
55
55
|
|
|
56
56
|
if (path.extname(file) === '.svg') {
|
|
57
|
-
outputs.push(
|
|
57
|
+
outputs.push(loadIconFile(file, removeColor));
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -62,12 +62,12 @@ export const readIconsDirectory = (svgDirectory: string, removeColor?: 'fill' |
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
* 把图标 symbol
|
|
65
|
+
* 把图标 symbol 内容保存到 html 文件中
|
|
66
66
|
*
|
|
67
67
|
* @param htmlFile html 文件路径
|
|
68
68
|
* @param symbols 图标 symbol 集合
|
|
69
69
|
*/
|
|
70
|
-
export const
|
|
70
|
+
export const saveIconsToHtml = (htmlFile: string, symbols: string) => {
|
|
71
71
|
let html = fs.readFileSync(htmlFile, 'utf8');
|
|
72
72
|
let index = html.indexOf('<svg id="ICONS" ');
|
|
73
73
|
|
|
@@ -91,12 +91,12 @@ export const writeIconsToHtml = (htmlFile: string, symbols: string) => {
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
*
|
|
94
|
+
* 把 svg 图标保存到模块文件中
|
|
95
95
|
*
|
|
96
96
|
* @param moduleFile 模块文件名
|
|
97
97
|
* @param symbols svg 图标内容
|
|
98
98
|
*/
|
|
99
|
-
export const
|
|
99
|
+
export const saveIconsModule = (moduleFile: string, symbols: string) => {
|
|
100
100
|
fs.writeFileSync(
|
|
101
101
|
moduleFile,
|
|
102
102
|
`import { loadSvgIcons } from 'cdui-js';
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cdui-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"bin": {
|
|
7
7
|
"cdui-js": "./cli/bin.js"
|
|
8
8
|
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
},
|
|
9
|
+
"scripts": {},
|
|
11
10
|
"dependencies": {
|
|
12
11
|
"chalk": "^5.6.2",
|
|
13
12
|
"commander": "^14.0.3",
|
|
@@ -21,4 +20,4 @@
|
|
|
21
20
|
"@types/node": "^25.3.3",
|
|
22
21
|
"typescript": "~5.6.2"
|
|
23
22
|
}
|
|
24
|
-
}
|
|
23
|
+
}
|
|
@@ -10,9 +10,9 @@ export interface SwitchProps {
|
|
|
10
10
|
*/
|
|
11
11
|
component: () => JSX.Element;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* 缓存 id
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
id?: string;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -30,14 +30,14 @@ export const Switch = (props: SwitchProps) => {
|
|
|
30
30
|
|
|
31
31
|
return createMemo(() => {
|
|
32
32
|
let branch = props.case;
|
|
33
|
-
let
|
|
33
|
+
let id;
|
|
34
34
|
|
|
35
35
|
if (branch) {
|
|
36
|
-
if ((
|
|
36
|
+
if ((id = branch.id)) {
|
|
37
37
|
return (
|
|
38
|
-
roots[
|
|
39
|
-
(roots[
|
|
40
|
-
disposes[
|
|
38
|
+
roots[id] ||
|
|
39
|
+
(roots[id] = createRoot((dispose) => {
|
|
40
|
+
disposes[id] = dispose;
|
|
41
41
|
return branch.component();
|
|
42
42
|
}))
|
|
43
43
|
);
|
package/src/ssr/render.ts
CHANGED
|
@@ -144,32 +144,35 @@ export const renderSSRPages = async (
|
|
|
144
144
|
template: string,
|
|
145
145
|
pages: SSRRenderPage[],
|
|
146
146
|
) => {
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
// @ts-ignore
|
|
148
|
+
if (import.meta.env.SSR) {
|
|
149
|
+
for (let i = 0, l = pages.length; i < l; i++) {
|
|
150
|
+
let page = pages[i];
|
|
149
151
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
try {
|
|
153
|
+
let now = Date.now();
|
|
152
154
|
|
|
153
|
-
|
|
155
|
+
console.log(`rendering:${language} ${page.path}`);
|
|
154
156
|
|
|
155
|
-
|
|
157
|
+
await renderPage(App, languages, language, root, template, page);
|
|
156
158
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
console.log(`rendered: ${language} ${page.path} time: ${Date.now() - now}`);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.error(err);
|
|
162
|
+
SSR_ERRORS.push(err.message + ': ' + (err.cause || { message: '...' }).message);
|
|
161
163
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
// 页面渲染失败终止渲染
|
|
165
|
+
if (page.abort) {
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
|
-
}
|
|
168
170
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
if (SSR_ERRORS[0]) {
|
|
172
|
+
return Promise.reject({
|
|
173
|
+
language,
|
|
174
|
+
errors: SSR_ERRORS,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
174
177
|
}
|
|
175
178
|
};
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
|
-
|
|
2
|
+
if (import.meta.env.SSR) {
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
const localStorage = new Map();
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
global.localStorage = global.sessionStorage = {
|
|
8
|
+
get length() {
|
|
9
|
+
return localStorage.size;
|
|
10
|
+
},
|
|
11
|
+
key(index) {
|
|
12
|
+
return localStorage.keys()[index];
|
|
13
|
+
},
|
|
14
|
+
getItem(key) {
|
|
15
|
+
return localStorage.get(key) || '';
|
|
16
|
+
},
|
|
17
|
+
setItem(key, value) {
|
|
18
|
+
localStorage.set('' + key, '' + value);
|
|
19
|
+
},
|
|
20
|
+
removeItem(key) {
|
|
21
|
+
localStorage.delete(key);
|
|
22
|
+
},
|
|
23
|
+
clear() {
|
|
24
|
+
localStorage.clear();
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|