@hb-hellotech/hb-ui 2.4.3 → 2.5.0
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/App.d.ts.map +1 -1
- package/dist/components/func_comp/hb_func_comp_tree/src/tree.d.ts.map +1 -1
- package/dist/components/func_comp/hb_func_file_preview/index.d.ts +280 -85
- package/dist/components/func_comp/hb_func_file_preview/index.d.ts.map +1 -1
- package/dist/components/func_comp/hb_func_file_preview/src/file_preview.d.ts +173 -39
- package/dist/components/func_comp/hb_func_file_preview/src/file_preview.d.ts.map +1 -1
- package/dist/components/func_comp/hb_func_icon_list/constants.d.ts +11 -0
- package/dist/components/func_comp/hb_func_icon_list/constants.d.ts.map +1 -0
- package/dist/components/func_comp/hb_func_icon_list/index.d.ts +9 -0
- package/dist/components/func_comp/hb_func_icon_list/index.d.ts.map +1 -0
- package/dist/components/func_comp/hb_func_icon_list/src/icon_list.d.ts +38 -0
- package/dist/components/func_comp/hb_func_icon_list/src/icon_list.d.ts.map +1 -0
- package/dist/components/func_comp/hb_ui_config/constants.d.ts +2 -0
- package/dist/components/func_comp/hb_ui_config/constants.d.ts.map +1 -0
- package/dist/components/func_comp/hb_ui_config/index.d.ts +1 -1
- package/dist/components/func_comp/hb_ui_config/index.d.ts.map +1 -1
- package/dist/components/func_comp/hb_ui_config/src/hbUiConfig.d.ts.map +1 -1
- package/dist/components/func_comp/index.d.ts +2 -1
- package/dist/components/func_comp/index.d.ts.map +1 -1
- package/dist/components/hooks/index.d.ts +1 -0
- package/dist/components/hooks/index.d.ts.map +1 -1
- package/dist/components/hooks/useFilePreview.d.ts +123 -3
- package/dist/components/hooks/useFilePreview.d.ts.map +1 -1
- package/dist/components/hooks/useIconfont.d.ts +27 -0
- package/dist/components/hooks/useIconfont.d.ts.map +1 -0
- package/dist/components/hooks/useListFormItem.d.ts.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/demo/HbLibIcon.d.ts +4 -0
- package/dist/demo/HbLibIcon.d.ts.map +1 -0
- package/dist/demo/hb_file_preview.d.ts.map +1 -1
- package/dist/hb_component_lib.css +1 -1
- package/dist/hb_component_lib.js +2592 -2612
- package/dist/hb_component_lib.umd.cjs +345 -2
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/main.d.ts +52 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/vue-office-docx-D0zFkT1M.js +5857 -0
- package/dist/vue-office-excel-B9GbNr16.js +64322 -0
- package/dist/vue-office-pdf-CaEuSE8g.js +2012 -0
- package/dist/vue-office-pptx-BeWGEYJM.js +52572 -0
- package/hooks/useIconfont.ts +149 -0
- package/package.json +17 -7
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
toValue,
|
|
4
|
+
watch,
|
|
5
|
+
type MaybeRefOrGetter,
|
|
6
|
+
type Ref,
|
|
7
|
+
} from 'vue';
|
|
8
|
+
|
|
9
|
+
export interface UseIconfontResult {
|
|
10
|
+
/** iconfont @font-face 中声明的 font-family,通常也是渲染图标时需要挂载的基础 class */
|
|
11
|
+
iconBaseClass: Ref<string>;
|
|
12
|
+
/** 所有图标 class 的公共前缀,例如 full class 为 `strong-user` 时,公共前缀可能是 `strong-` */
|
|
13
|
+
iconPrefix: Ref<string>;
|
|
14
|
+
/** 去掉公共前缀后的图标名称列表,可直接用于图标选择器或组件的 name 属性 */
|
|
15
|
+
iconClasses: Ref<string[]>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface IconfontParseResult {
|
|
19
|
+
baseClass: string;
|
|
20
|
+
prefix: string;
|
|
21
|
+
names: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 解析 iconfont 的 CSS 文本,提取组件渲染和图标选择所需的信息。
|
|
26
|
+
*
|
|
27
|
+
* 解析规则:
|
|
28
|
+
* 1. 从 @font-face 中取 font-family 作为基础 class,例如 "strongQ"。
|
|
29
|
+
* 2. 读取所有 `.xxx:before { content: "\eXXX" }` 规则中的 xxx,作为完整图标 class。
|
|
30
|
+
* 3. 计算完整图标 class 的最长公共前缀,例如 "strong-"。
|
|
31
|
+
* 4. 将公共前缀从完整 class 中移除,得到更适合使用者传入的图标 name。
|
|
32
|
+
*
|
|
33
|
+
* 示例:
|
|
34
|
+
* - CSS 中存在 `.strong-user:before`、`.strong-home:before`
|
|
35
|
+
* - 返回 prefix 为 `strong-`
|
|
36
|
+
* - 返回 names 为 `['user', 'home']`
|
|
37
|
+
*/
|
|
38
|
+
function parseIconfontCss(css: string): IconfontParseResult {
|
|
39
|
+
const fontFaceMatch = css.match(
|
|
40
|
+
/@font-face\s*\{[\s\S]*?font-family\s*:\s*["']([^"']+)["']/
|
|
41
|
+
);
|
|
42
|
+
const baseClass = fontFaceMatch?.[1] ?? '';
|
|
43
|
+
|
|
44
|
+
const iconClassRegex =
|
|
45
|
+
/\.([\w-]+)\s*:before\s*\{\s*content\s*:\s*["']\\[\da-fA-F]+["']\s*;?\s*\}/g;
|
|
46
|
+
const fullClasses: string[] = [];
|
|
47
|
+
let match: RegExpExecArray | null;
|
|
48
|
+
while ((match = iconClassRegex.exec(css)) !== null) {
|
|
49
|
+
fullClasses.push(match[1]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const prefix = findCommonPrefix(fullClasses);
|
|
53
|
+
const names = prefix
|
|
54
|
+
? fullClasses.map((className) => className.slice(prefix.length))
|
|
55
|
+
: fullClasses.slice();
|
|
56
|
+
|
|
57
|
+
return { baseClass, prefix, names };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 计算字符串数组的最长公共前缀。
|
|
62
|
+
*
|
|
63
|
+
* iconfont 生成的 class 通常会共享同一个业务前缀,例如 `strong-user`、`strong-home`。
|
|
64
|
+
* 将该前缀单独提取出来后,外部使用时只需要关心 `user`、`home` 这类图标名。
|
|
65
|
+
*/
|
|
66
|
+
function findCommonPrefix(list: string[]): string {
|
|
67
|
+
if (list.length === 0) return '';
|
|
68
|
+
let prefix = list[0];
|
|
69
|
+
for (let i = 1; i < list.length; i++) {
|
|
70
|
+
while (prefix && !list[i].startsWith(prefix)) {
|
|
71
|
+
prefix = prefix.slice(0, -1);
|
|
72
|
+
}
|
|
73
|
+
if (!prefix) break;
|
|
74
|
+
}
|
|
75
|
+
return prefix;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 将 iconfont CSS 注入到页面,确保 @font-face 字体和 class 规则可以被浏览器识别。
|
|
80
|
+
*
|
|
81
|
+
* 同一个 key 只会注入一次,避免响应式 url 重复触发时创建多份相同 style。
|
|
82
|
+
* SSR 环境没有 document,因此会直接跳过注入。
|
|
83
|
+
*/
|
|
84
|
+
function injectCss(cssText: string, key: string) {
|
|
85
|
+
if (typeof document === 'undefined' || document.getElementById(key)) return;
|
|
86
|
+
|
|
87
|
+
const style = document.createElement('style');
|
|
88
|
+
style.id = key;
|
|
89
|
+
style.textContent = cssText;
|
|
90
|
+
document.head.appendChild(style);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 加载并解析 iconfont CSS 的组合式函数。
|
|
95
|
+
*
|
|
96
|
+
* @param cssUrl iconfont 的 CSS 地址,支持普通字符串、ref 或 getter。
|
|
97
|
+
* @returns iconfont 的基础 class、公共前缀,以及去掉公共前缀后的图标名称列表。
|
|
98
|
+
*
|
|
99
|
+
* 使用方式:
|
|
100
|
+
* ```ts
|
|
101
|
+
* const { iconBaseClass, iconPrefix, iconClasses } = useIconfont(cssUrl);
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* 典型用途:
|
|
105
|
+
* - 将 `iconBaseClass` 和 `iconPrefix + name` 组合成真实图标 class。
|
|
106
|
+
* - 使用 `iconClasses` 渲染图标选择器的可选项。
|
|
107
|
+
* - 当 `cssUrl` 是响应式数据时,地址变化会自动重新加载并解析。
|
|
108
|
+
*/
|
|
109
|
+
export function useIconfont(cssUrl: MaybeRefOrGetter<string>): UseIconfontResult {
|
|
110
|
+
const iconBaseClass = ref('');
|
|
111
|
+
const iconPrefix = ref('');
|
|
112
|
+
const iconClasses = ref<string[]>([]);
|
|
113
|
+
let requestId = 0;
|
|
114
|
+
|
|
115
|
+
const loadIconfont = async (url: string) => {
|
|
116
|
+
const currentRequestId = ++requestId;
|
|
117
|
+
if (!url) {
|
|
118
|
+
iconBaseClass.value = '';
|
|
119
|
+
iconPrefix.value = '';
|
|
120
|
+
iconClasses.value = [];
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const res = await fetch(url);
|
|
126
|
+
const cssText = await res.text();
|
|
127
|
+
injectCss(cssText, 'hb-iconfont-' + url);
|
|
128
|
+
|
|
129
|
+
const { baseClass, prefix, names } = parseIconfontCss(cssText);
|
|
130
|
+
// 避免较早的慢请求覆盖较新的 cssUrl 解析结果。
|
|
131
|
+
if (currentRequestId !== requestId) return;
|
|
132
|
+
|
|
133
|
+
iconBaseClass.value = baseClass;
|
|
134
|
+
iconPrefix.value = prefix;
|
|
135
|
+
iconClasses.value = names;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error('[HbLibIcon] 加载 iconfont 失败:', url, err);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
watch(() => toValue(cssUrl), loadIconfont, { immediate: true });
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
iconBaseClass,
|
|
145
|
+
iconPrefix,
|
|
146
|
+
iconClasses,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hb-hellotech/hb-ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/hb_component_lib.umd.cjs",
|
|
6
6
|
"module": "dist/hb_component_lib.js",
|
|
@@ -32,8 +32,9 @@
|
|
|
32
32
|
"build": "vite build",
|
|
33
33
|
"lint": "eslint ./src/**/*.{ts,vue}",
|
|
34
34
|
"lint:fix": "eslint ./src/**/*.{ts,vue} --fix",
|
|
35
|
-
"docs:
|
|
36
|
-
"docs:
|
|
35
|
+
"docs:gen": "node scripts/generate-docs.mjs",
|
|
36
|
+
"docs:dev": "npm run docs:gen && vitepress dev docs --port 3001",
|
|
37
|
+
"docs:build": "npm run docs:gen && vitepress build docs",
|
|
37
38
|
"docs:preview": "vitepress preview docs"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
@@ -45,7 +46,12 @@
|
|
|
45
46
|
"vue": "^3.5.22",
|
|
46
47
|
"vue-i18n": "^9.2.2",
|
|
47
48
|
"vue-router": "^4.1.6",
|
|
48
|
-
"vuedraggable": "4.1.0"
|
|
49
|
+
"vuedraggable": "4.1.0",
|
|
50
|
+
"@vue-office/docx": "^1.6.3",
|
|
51
|
+
"@vue-office/excel": "^1.7.14",
|
|
52
|
+
"@vue-office/pdf": "^2.0.10",
|
|
53
|
+
"@vue-office/pptx": "^1.0.1",
|
|
54
|
+
"vue-demi": "0.14.6"
|
|
49
55
|
},
|
|
50
56
|
"dependencies": {
|
|
51
57
|
"@hb-hellotech/hb-ui": "1.2.5-beta.5",
|
|
@@ -57,8 +63,7 @@
|
|
|
57
63
|
"lodash-es": "^4.17.23",
|
|
58
64
|
"rollup-plugin-external-globals": "^0.8.0",
|
|
59
65
|
"throttle-debounce": "^5.0.0",
|
|
60
|
-
"vite-plugin-libcss": "^1.0.5"
|
|
61
|
-
"vue-files-preview": "^1.0.43"
|
|
66
|
+
"vite-plugin-libcss": "^1.0.5"
|
|
62
67
|
},
|
|
63
68
|
"devDependencies": {
|
|
64
69
|
"@ant-design/icons-vue": "^6.1.0",
|
|
@@ -92,6 +97,11 @@
|
|
|
92
97
|
"vue-i18n": "^9.2.2",
|
|
93
98
|
"vue-router": "^4.1.6",
|
|
94
99
|
"vue-tsc": "^2.1.10",
|
|
95
|
-
"vuedraggable": "4.1.0"
|
|
100
|
+
"vuedraggable": "4.1.0",
|
|
101
|
+
"@vue-office/docx": "^1.6.3",
|
|
102
|
+
"@vue-office/excel": "^1.7.14",
|
|
103
|
+
"@vue-office/pdf": "^2.0.10",
|
|
104
|
+
"@vue-office/pptx": "^1.0.1",
|
|
105
|
+
"vue-demi": "0.14.6"
|
|
96
106
|
}
|
|
97
107
|
}
|