@gct-paas/core 0.1.5-dev.6 → 0.1.5-dev.8
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/index.esm.min.js +1 -1
- package/es/enums/app-designer/index.d.ts +11 -0
- package/es/enums/app-designer/index.mjs +14 -1
- package/es/enums/appEnum.d.ts +8 -0
- package/es/enums/appEnum.mjs +10 -1
- package/es/enums/page-designer/designer.d.ts +13 -13
- package/es/index.mjs +10 -6
- package/es/interface/i-popover-options/i-popover-options.d.ts +98 -0
- package/es/interface/index.d.ts +2 -0
- package/es/interface/index.mjs +1 -0
- package/es/interface/model-designer/serial.d.ts +22 -0
- package/es/interface/model-designer/serial.mjs +49 -0
- package/es/interface/open-util/i-app-full-screen-container-options/i-app-full-screen-container-options.d.ts +26 -0
- package/es/interface/open-util/i-overlay-controller/i-overlay-controller.d.ts +52 -0
- package/es/interface/open-util/i-overlay-popover-container/i-overlay-popover-container.d.ts +21 -0
- package/es/interface/open-util/index.d.ts +3 -1
- package/es/modules/mqtt/enums/mqtt-status.enum.d.ts +1 -0
- package/es/modules/mqtt/enums/mqtt-status.enum.mjs +2 -1
- package/es/modules/mqtt/mqtt-manager.d.ts +1 -1
- package/es/modules/mqtt/mqtt-manager.mjs +2 -1
- package/es/router/index.mjs +1 -1
- package/es/setup-app.mjs +3 -1
- package/es/utils/i18n/index.mjs +3 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.mjs +2 -0
- package/es/utils/openUtil/index.d.ts +1 -0
- package/es/utils/openUtil/index.mjs +1 -0
- package/es/utils/openUtil/overlay-popover-container/overlay-popover-container.d.ts +15 -0
- package/es/utils/openUtil/overlay-popover-container/overlay-popover-container.mjs +19 -0
- package/es/utils/style/index.d.ts +8 -0
- package/es/utils/style/index.mjs +67 -1
- package/es/utils/text-measure/text-measure.d.ts +141 -0
- package/es/utils/text-measure/text-measure.mjs +191 -0
- package/es/utils/util.d.ts +1 -0
- package/es/utils/util.mjs +9 -1
- package/package.json +4 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OverlayContainer } from "../overlay-container/overlay-container.mjs";
|
|
2
|
+
//#region src/utils/openUtil/overlay-popover-container/overlay-popover-container.ts
|
|
3
|
+
/**
|
|
4
|
+
* 飘窗组件呈现容器
|
|
5
|
+
*
|
|
6
|
+
* @author zhanghanrui
|
|
7
|
+
* @date 2024-04-08 09:04:42
|
|
8
|
+
* @export
|
|
9
|
+
* @class OverlayPopoverContainer
|
|
10
|
+
* @extends {OverlayContainer<IPopoverOptions>}
|
|
11
|
+
* @implements {IOverlayPopoverContainer}
|
|
12
|
+
*/
|
|
13
|
+
var OverlayPopoverContainer = class extends OverlayContainer {
|
|
14
|
+
present(target) {
|
|
15
|
+
return this.modal.present(target);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { OverlayPopoverContainer };
|
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
8
|
export declare const calcStyle: (data: IData, ignoringStyle?: string[]) => IObject;
|
|
9
|
+
/**
|
|
10
|
+
* 计算配置样式 补充px
|
|
11
|
+
*
|
|
12
|
+
* @param data
|
|
13
|
+
* @param ignoringStyle 忽略计算的样式
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const calcStylePX: (data: IData, ignoringStyle?: string[]) => IObject;
|
|
9
17
|
/**
|
|
10
18
|
* 计算字体样式
|
|
11
19
|
*
|
package/es/utils/style/index.mjs
CHANGED
|
@@ -71,6 +71,72 @@ var calcStyle = (data, ignoringStyle = []) => {
|
|
|
71
71
|
return style;
|
|
72
72
|
};
|
|
73
73
|
/**
|
|
74
|
+
* 计算配置样式 补充px
|
|
75
|
+
*
|
|
76
|
+
* @param data
|
|
77
|
+
* @param ignoringStyle 忽略计算的样式
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
var calcStylePX = (data, ignoringStyle = []) => {
|
|
81
|
+
if (!data) return {};
|
|
82
|
+
const style = {};
|
|
83
|
+
if (data.paddingTop && data.paddingTop != "0" && !ignoringStyle.includes("paddingTop")) style["padding-top"] = `${data.paddingTop}px`;
|
|
84
|
+
if (data.paddingRight && data.paddingRight != "0" && !ignoringStyle.includes("paddingRight")) style["padding-right"] = `${data.paddingRight}px`;
|
|
85
|
+
if (data.paddingBottom && data.paddingBottom != "0" && !ignoringStyle.includes("paddingBottom")) style["padding-bottom"] = `${data.paddingBottom}px`;
|
|
86
|
+
if (data.paddingLeft && data.paddingLeft != "0" && !ignoringStyle.includes("paddingLeft")) style["padding-left"] = `${data.paddingLeft}px`;
|
|
87
|
+
if (data.marginTop && data.marginTop != "0" && !ignoringStyle.includes("marginTop")) style["margin-top"] = `${data.marginTop}px`;
|
|
88
|
+
if (data.marginRight && data.marginRight != "0" && !ignoringStyle.includes("marginRight")) style["margin-right"] = `${data.marginRight}px`;
|
|
89
|
+
if (data.marginBottom && data.marginBottom != "0" && !ignoringStyle.includes("marginBottom")) style["margin-bottom"] = `${data.marginBottom}px`;
|
|
90
|
+
if (data.marginLeft && data.marginLeft != "0" && !ignoringStyle.includes("marginLeft")) style["margin-left"] = `${data.marginLeft}px`;
|
|
91
|
+
if (data.backgroundColor && !ignoringStyle.includes("backgroundColor")) style["background-color"] = data.backgroundColor;
|
|
92
|
+
if (data.width != null && data.width != "" && !ignoringStyle.includes("width")) style.width = `${data.width}px`;
|
|
93
|
+
if (data.height != null && data.height != "" && !ignoringStyle.includes("height")) {
|
|
94
|
+
style.height = `${data.height}px`;
|
|
95
|
+
style.overflowX = "hidden";
|
|
96
|
+
style.overflowY = "auto";
|
|
97
|
+
}
|
|
98
|
+
const position = data.position;
|
|
99
|
+
if (position && !ignoringStyle.includes("zIndex")) {
|
|
100
|
+
style.position = position;
|
|
101
|
+
style["z-index"] = 1;
|
|
102
|
+
}
|
|
103
|
+
if (data.top && !ignoringStyle.includes("top")) style.top = `${data.top}px`;
|
|
104
|
+
if (data.right && !ignoringStyle.includes("right")) style.right = `${data.right}px`;
|
|
105
|
+
if (data.bottom && !ignoringStyle.includes("bottom")) style.bottom = `${data.bottom}px`;
|
|
106
|
+
if (data.left && !ignoringStyle.includes("left")) style.left = `${data.left}px`;
|
|
107
|
+
if (data.borderBottomLeftRadius && !ignoringStyle.includes("borderBottomLeftRadius")) style["border-top-left-radius"] = `${data.borderBottomLeftRadius}px`;
|
|
108
|
+
if (data.borderTopRightRadius && !ignoringStyle.includes("borderTopRightRadius")) style["border-top-right-radius"] = `${data.borderTopRightRadius}px`;
|
|
109
|
+
if (data.borderBottomLeftRadius && !ignoringStyle.includes("borderBottomLeftRadius")) style["border-bottom-left-radius"] = `${data.borderBottomLeftRadius}px`;
|
|
110
|
+
if (data.borderBottomRightRadius && !ignoringStyle.includes("borderBottomRightRadius")) style["border-bottom-right-radius"] = `${data.borderBottomRightRadius}px`;
|
|
111
|
+
{
|
|
112
|
+
const top = data.borderTop;
|
|
113
|
+
if (top) {
|
|
114
|
+
if (top.borderColor && !ignoringStyle.includes("borderTopColor")) style["border-top-color"] = top.borderColor;
|
|
115
|
+
if (top.borderWidth && !ignoringStyle.includes("borderTopWidth")) style["border-top-width"] = `${top.borderWidth}px`;
|
|
116
|
+
if (top.borderStyle && !ignoringStyle.includes("borderTopStyle")) style["border-top-style"] = top.borderStyle;
|
|
117
|
+
}
|
|
118
|
+
const right = data.borderRight;
|
|
119
|
+
if (right) {
|
|
120
|
+
if (right.borderColor && !ignoringStyle.includes("borderRightColor")) style["border-right-color"] = right.borderColor;
|
|
121
|
+
if (right.borderWidth && !ignoringStyle.includes("borderRightWidth")) style["border-right-width"] = `${right.borderWidth}px`;
|
|
122
|
+
if (right.borderStyle && !ignoringStyle.includes("borderRightStyle")) style["border-right-style"] = right.borderStyle;
|
|
123
|
+
}
|
|
124
|
+
const bottom = data.borderBottom;
|
|
125
|
+
if (bottom) {
|
|
126
|
+
if (bottom.borderColor && !ignoringStyle.includes("borderBottomColor")) style["border-bottom-color"] = bottom.borderColor;
|
|
127
|
+
if (bottom.borderWidth && !ignoringStyle.includes("borderBottomWidth")) style["border-bottom-width"] = `${bottom.borderWidth}px`;
|
|
128
|
+
if (bottom.borderStyle && !ignoringStyle.includes("borderBottomStyle")) style["border-bottom-style"] = bottom.borderStyle;
|
|
129
|
+
}
|
|
130
|
+
const left = data.borderLeft;
|
|
131
|
+
if (left) {
|
|
132
|
+
if (left.borderColor && !ignoringStyle.includes("borderLeftColor")) style["border-left-color"] = left.borderColor;
|
|
133
|
+
if (left.borderWidth && !ignoringStyle.includes("borderLeftWidth")) style["border-left-width"] = `${left.borderWidth}px`;
|
|
134
|
+
if (left.borderStyle && !ignoringStyle.includes("borderLeftStyle")) style["border-left-style"] = left.borderStyle;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return style;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
74
140
|
* 计算字体样式
|
|
75
141
|
*
|
|
76
142
|
* @param data
|
|
@@ -94,4 +160,4 @@ var calcFontStyle = (data, ignoringStyle = []) => {
|
|
|
94
160
|
return style;
|
|
95
161
|
};
|
|
96
162
|
//#endregion
|
|
97
|
-
export { calcFontStyle, calcStyle };
|
|
163
|
+
export { calcFontStyle, calcStyle, calcStylePX };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本测量工具类
|
|
3
|
+
* 使用 Canvas 测量文本宽度,支持批量测量
|
|
4
|
+
*/
|
|
5
|
+
interface TextMeasureOptions {
|
|
6
|
+
/** 字体大小,默认 14px */
|
|
7
|
+
fontSize?: string | number;
|
|
8
|
+
/** 字体族,默认 'Arial, sans-serif' */
|
|
9
|
+
fontFamily?: string;
|
|
10
|
+
/** 字体粗细,默认 'normal' */
|
|
11
|
+
fontWeight?: string | number;
|
|
12
|
+
/** 字体样式,默认 'normal' */
|
|
13
|
+
fontStyle?: string;
|
|
14
|
+
}
|
|
15
|
+
interface TextMeasureResult {
|
|
16
|
+
/** 文本内容 */
|
|
17
|
+
text: string;
|
|
18
|
+
/** 计算得到的宽度 */
|
|
19
|
+
width: number;
|
|
20
|
+
}
|
|
21
|
+
declare class TextMeasureUtil {
|
|
22
|
+
private canvas;
|
|
23
|
+
private ctx;
|
|
24
|
+
/**
|
|
25
|
+
* 获取 Canvas 上下文,懒加载创建
|
|
26
|
+
*/
|
|
27
|
+
private getContext;
|
|
28
|
+
/**
|
|
29
|
+
* 设置字体样式
|
|
30
|
+
*/
|
|
31
|
+
private setFont;
|
|
32
|
+
/**
|
|
33
|
+
* 测量单个文本的宽度
|
|
34
|
+
*
|
|
35
|
+
* @param text 要测量的文本
|
|
36
|
+
* @param options 字体选项
|
|
37
|
+
* @returns 文本宽度(像素)
|
|
38
|
+
*/
|
|
39
|
+
measureText(text: string, options?: TextMeasureOptions): number;
|
|
40
|
+
/**
|
|
41
|
+
* 批量测量多段文本的宽度
|
|
42
|
+
*
|
|
43
|
+
* @param texts 要测量的文本数组
|
|
44
|
+
* @param options 字体选项
|
|
45
|
+
* @returns 包含每段文本和对应宽度的结果数组
|
|
46
|
+
*/
|
|
47
|
+
measureTexts(texts: string[], options?: TextMeasureOptions): TextMeasureResult[];
|
|
48
|
+
/**
|
|
49
|
+
* 获取文本的最大宽度
|
|
50
|
+
*
|
|
51
|
+
* @param texts 要测量的文本数组
|
|
52
|
+
* @param options 字体选项
|
|
53
|
+
* @returns 最大宽度(像素)
|
|
54
|
+
*/
|
|
55
|
+
getMaxWidth(texts: string[], options?: TextMeasureOptions): number;
|
|
56
|
+
/**
|
|
57
|
+
* 获取文本的最小宽度
|
|
58
|
+
*
|
|
59
|
+
* @param texts 要测量的文本数组
|
|
60
|
+
* @param options 字体选项
|
|
61
|
+
* @returns 最小宽度(像素)
|
|
62
|
+
*/
|
|
63
|
+
getMinWidth(texts: string[], options?: TextMeasureOptions): number;
|
|
64
|
+
/**
|
|
65
|
+
* 计算文本的总宽度(用于水平排列的文本)
|
|
66
|
+
*
|
|
67
|
+
* @param texts 要测量的文本数组
|
|
68
|
+
* @param options 字体选项
|
|
69
|
+
* @param spacing 文本间的间距,默认 0
|
|
70
|
+
* @returns 总宽度(像素)
|
|
71
|
+
*/
|
|
72
|
+
getTotalWidth(texts: string[], options?: TextMeasureOptions, spacing?: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* 根据最大宽度截断文本,添加省略号
|
|
75
|
+
*
|
|
76
|
+
* @param text 原始文本
|
|
77
|
+
* @param maxWidth 最大宽度
|
|
78
|
+
* @param options 字体选项
|
|
79
|
+
* @param ellipsis 省略号,默认 '...'
|
|
80
|
+
* @param minChars 最少显示字符数,默认 0
|
|
81
|
+
* @returns 截断后的文本
|
|
82
|
+
*/
|
|
83
|
+
truncateText(text: string, maxWidth: number, options?: TextMeasureOptions, ellipsis?: string, minChars?: number): string;
|
|
84
|
+
/**
|
|
85
|
+
* 销毁资源
|
|
86
|
+
*/
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 测量单个文本的宽度
|
|
91
|
+
*
|
|
92
|
+
* @param text 要测量的文本
|
|
93
|
+
* @param options 字体选项
|
|
94
|
+
* @returns 文本宽度(像素)
|
|
95
|
+
*/
|
|
96
|
+
export declare function measureText(text: string, options?: TextMeasureOptions): number;
|
|
97
|
+
/**
|
|
98
|
+
* 批量测量多段文本的宽度
|
|
99
|
+
*
|
|
100
|
+
* @param texts 要测量的文本数组
|
|
101
|
+
* @param options 字体选项
|
|
102
|
+
* @returns 包含每段文本和对应宽度的结果数组
|
|
103
|
+
*/
|
|
104
|
+
export declare function measureTexts(texts: string[], options?: TextMeasureOptions): TextMeasureResult[];
|
|
105
|
+
/**
|
|
106
|
+
* 获取文本的最大宽度
|
|
107
|
+
*
|
|
108
|
+
* @param texts 要测量的文本数组
|
|
109
|
+
* @param options 字体选项
|
|
110
|
+
* @returns 最大宽度(像素)
|
|
111
|
+
*/
|
|
112
|
+
export declare function getMaxTextWidth(texts: string[], options?: TextMeasureOptions): number;
|
|
113
|
+
/**
|
|
114
|
+
* 获取文本的最小宽度
|
|
115
|
+
*
|
|
116
|
+
* @param texts 要测量的文本数组
|
|
117
|
+
* @param options 字体选项
|
|
118
|
+
* @returns 最小宽度(像素)
|
|
119
|
+
*/
|
|
120
|
+
export declare function getMinTextWidth(texts: string[], options?: TextMeasureOptions): number;
|
|
121
|
+
/**
|
|
122
|
+
* 计算文本的总宽度(用于水平排列的文本)
|
|
123
|
+
*
|
|
124
|
+
* @param texts 要测量的文本数组
|
|
125
|
+
* @param options 字体选项
|
|
126
|
+
* @param spacing 文本间的间距,默认 0
|
|
127
|
+
* @returns 总宽度(像素)
|
|
128
|
+
*/
|
|
129
|
+
export declare function getTotalTextWidth(texts: string[], options?: TextMeasureOptions, spacing?: number): number;
|
|
130
|
+
/**
|
|
131
|
+
* 根据最大宽度截断文本,添加省略号
|
|
132
|
+
*
|
|
133
|
+
* @param text 原始文本
|
|
134
|
+
* @param maxWidth 最大宽度
|
|
135
|
+
* @param options 字体选项
|
|
136
|
+
* @param ellipsis 省略号,默认 '...'
|
|
137
|
+
* @param minChars 最少显示字符数,默认 0
|
|
138
|
+
* @returns 截断后的文本
|
|
139
|
+
*/
|
|
140
|
+
export declare function truncateText(text: string, maxWidth: number, options?: TextMeasureOptions, ellipsis?: string, minChars?: number): string;
|
|
141
|
+
export { TextMeasureUtil, type TextMeasureOptions, type TextMeasureResult };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
//#region src/utils/text-measure/text-measure.ts
|
|
2
|
+
var TextMeasureUtil = class {
|
|
3
|
+
canvas = null;
|
|
4
|
+
ctx = null;
|
|
5
|
+
/**
|
|
6
|
+
* 获取 Canvas 上下文,懒加载创建
|
|
7
|
+
*/
|
|
8
|
+
getContext() {
|
|
9
|
+
if (!this.canvas) {
|
|
10
|
+
this.canvas = document.createElement("canvas");
|
|
11
|
+
this.ctx = this.canvas.getContext("2d");
|
|
12
|
+
if (!this.ctx) throw new Error("无法创建 Canvas 2D 上下文");
|
|
13
|
+
}
|
|
14
|
+
return this.ctx;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 设置字体样式
|
|
18
|
+
*/
|
|
19
|
+
setFont(options = {}) {
|
|
20
|
+
const { fontSize = 14, fontFamily = "Arial, sans-serif", fontWeight = "normal", fontStyle = "normal" } = options;
|
|
21
|
+
const ctx = this.getContext();
|
|
22
|
+
ctx.font = `${fontStyle} ${fontWeight} ${typeof fontSize === "number" ? `${fontSize}px` : fontSize} ${fontFamily}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 测量单个文本的宽度
|
|
26
|
+
*
|
|
27
|
+
* @param text 要测量的文本
|
|
28
|
+
* @param options 字体选项
|
|
29
|
+
* @returns 文本宽度(像素)
|
|
30
|
+
*/
|
|
31
|
+
measureText(text, options = {}) {
|
|
32
|
+
if (!text) return 0;
|
|
33
|
+
this.setFont(options);
|
|
34
|
+
const metrics = this.getContext().measureText(text);
|
|
35
|
+
return Math.ceil(metrics.width);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 批量测量多段文本的宽度
|
|
39
|
+
*
|
|
40
|
+
* @param texts 要测量的文本数组
|
|
41
|
+
* @param options 字体选项
|
|
42
|
+
* @returns 包含每段文本和对应宽度的结果数组
|
|
43
|
+
*/
|
|
44
|
+
measureTexts(texts, options = {}) {
|
|
45
|
+
if (!texts || texts.length === 0) return [];
|
|
46
|
+
this.setFont(options);
|
|
47
|
+
const ctx = this.getContext();
|
|
48
|
+
return texts.map((text) => ({
|
|
49
|
+
text,
|
|
50
|
+
width: text ? Math.ceil(ctx.measureText(text).width) : 0
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 获取文本的最大宽度
|
|
55
|
+
*
|
|
56
|
+
* @param texts 要测量的文本数组
|
|
57
|
+
* @param options 字体选项
|
|
58
|
+
* @returns 最大宽度(像素)
|
|
59
|
+
*/
|
|
60
|
+
getMaxWidth(texts, options = {}) {
|
|
61
|
+
const results = this.measureTexts(texts, options);
|
|
62
|
+
return Math.max(...results.map((result) => result.width), 0);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 获取文本的最小宽度
|
|
66
|
+
*
|
|
67
|
+
* @param texts 要测量的文本数组
|
|
68
|
+
* @param options 字体选项
|
|
69
|
+
* @returns 最小宽度(像素)
|
|
70
|
+
*/
|
|
71
|
+
getMinWidth(texts, options = {}) {
|
|
72
|
+
const results = this.measureTexts(texts, options);
|
|
73
|
+
return Math.min(...results.map((result) => result.width), 0);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 计算文本的总宽度(用于水平排列的文本)
|
|
77
|
+
*
|
|
78
|
+
* @param texts 要测量的文本数组
|
|
79
|
+
* @param options 字体选项
|
|
80
|
+
* @param spacing 文本间的间距,默认 0
|
|
81
|
+
* @returns 总宽度(像素)
|
|
82
|
+
*/
|
|
83
|
+
getTotalWidth(texts, options = {}, spacing = 0) {
|
|
84
|
+
return this.measureTexts(texts, options).reduce((sum, result) => sum + result.width, 0) + Math.max(0, texts.length - 1) * spacing;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 根据最大宽度截断文本,添加省略号
|
|
88
|
+
*
|
|
89
|
+
* @param text 原始文本
|
|
90
|
+
* @param maxWidth 最大宽度
|
|
91
|
+
* @param options 字体选项
|
|
92
|
+
* @param ellipsis 省略号,默认 '...'
|
|
93
|
+
* @param minChars 最少显示字符数,默认 0
|
|
94
|
+
* @returns 截断后的文本
|
|
95
|
+
*/
|
|
96
|
+
truncateText(text, maxWidth, options = {}, ellipsis = "...", minChars = 0) {
|
|
97
|
+
if (!text) return "";
|
|
98
|
+
if (this.measureText(text, options) <= maxWidth) return text;
|
|
99
|
+
const availableWidth = maxWidth - this.measureText(ellipsis, options);
|
|
100
|
+
if (availableWidth <= 0) {
|
|
101
|
+
if (minChars > 0) return text.substring(0, minChars) + ellipsis;
|
|
102
|
+
return ellipsis;
|
|
103
|
+
}
|
|
104
|
+
let left = minChars;
|
|
105
|
+
let right = text.length;
|
|
106
|
+
let result = minChars > 0 ? text.substring(0, minChars) : "";
|
|
107
|
+
while (left <= right) {
|
|
108
|
+
const mid = Math.floor((left + right) / 2);
|
|
109
|
+
const substring = text.substring(0, mid);
|
|
110
|
+
if (this.measureText(substring, options) <= availableWidth) {
|
|
111
|
+
result = substring;
|
|
112
|
+
left = mid + 1;
|
|
113
|
+
} else right = mid - 1;
|
|
114
|
+
}
|
|
115
|
+
return result + ellipsis;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 销毁资源
|
|
119
|
+
*/
|
|
120
|
+
destroy() {
|
|
121
|
+
this.canvas = null;
|
|
122
|
+
this.ctx = null;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var textMeasureUtil = new TextMeasureUtil();
|
|
126
|
+
/**
|
|
127
|
+
* 测量单个文本的宽度
|
|
128
|
+
*
|
|
129
|
+
* @param text 要测量的文本
|
|
130
|
+
* @param options 字体选项
|
|
131
|
+
* @returns 文本宽度(像素)
|
|
132
|
+
*/
|
|
133
|
+
function measureText(text, options) {
|
|
134
|
+
return textMeasureUtil.measureText(text, options);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 批量测量多段文本的宽度
|
|
138
|
+
*
|
|
139
|
+
* @param texts 要测量的文本数组
|
|
140
|
+
* @param options 字体选项
|
|
141
|
+
* @returns 包含每段文本和对应宽度的结果数组
|
|
142
|
+
*/
|
|
143
|
+
function measureTexts(texts, options) {
|
|
144
|
+
return textMeasureUtil.measureTexts(texts, options);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 获取文本的最大宽度
|
|
148
|
+
*
|
|
149
|
+
* @param texts 要测量的文本数组
|
|
150
|
+
* @param options 字体选项
|
|
151
|
+
* @returns 最大宽度(像素)
|
|
152
|
+
*/
|
|
153
|
+
function getMaxTextWidth(texts, options) {
|
|
154
|
+
return textMeasureUtil.getMaxWidth(texts, options);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* 获取文本的最小宽度
|
|
158
|
+
*
|
|
159
|
+
* @param texts 要测量的文本数组
|
|
160
|
+
* @param options 字体选项
|
|
161
|
+
* @returns 最小宽度(像素)
|
|
162
|
+
*/
|
|
163
|
+
function getMinTextWidth(texts, options) {
|
|
164
|
+
return textMeasureUtil.getMinWidth(texts, options);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 计算文本的总宽度(用于水平排列的文本)
|
|
168
|
+
*
|
|
169
|
+
* @param texts 要测量的文本数组
|
|
170
|
+
* @param options 字体选项
|
|
171
|
+
* @param spacing 文本间的间距,默认 0
|
|
172
|
+
* @returns 总宽度(像素)
|
|
173
|
+
*/
|
|
174
|
+
function getTotalTextWidth(texts, options, spacing) {
|
|
175
|
+
return textMeasureUtil.getTotalWidth(texts, options, spacing);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* 根据最大宽度截断文本,添加省略号
|
|
179
|
+
*
|
|
180
|
+
* @param text 原始文本
|
|
181
|
+
* @param maxWidth 最大宽度
|
|
182
|
+
* @param options 字体选项
|
|
183
|
+
* @param ellipsis 省略号,默认 '...'
|
|
184
|
+
* @param minChars 最少显示字符数,默认 0
|
|
185
|
+
* @returns 截断后的文本
|
|
186
|
+
*/
|
|
187
|
+
function truncateText(text, maxWidth, options, ellipsis, minChars) {
|
|
188
|
+
return textMeasureUtil.truncateText(text, maxWidth, options, ellipsis, minChars);
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
export { TextMeasureUtil, getMaxTextWidth, getMinTextWidth, getTotalTextWidth, measureText, measureTexts, truncateText };
|
package/es/utils/util.d.ts
CHANGED
|
@@ -37,3 +37,4 @@ export declare function genUrl(url: string, data: IObject): string;
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
export declare function openWindow(url: string, options?: IOpenWindowOptions): Window | null;
|
|
40
|
+
export declare const deleteAndInsertArr: (arr: IObject[], deleteIndex: number, insertIndex: number) => void;
|
package/es/utils/util.mjs
CHANGED
|
@@ -56,5 +56,13 @@ function openWindow(url, options) {
|
|
|
56
56
|
if (optionStr) featuresStr = featuresStr ? `${featuresStr},${optionStr}` : optionStr;
|
|
57
57
|
return window.open(finalUrl, target, featuresStr);
|
|
58
58
|
}
|
|
59
|
+
var deleteAndInsertArr = (arr, deleteIndex, insertIndex) => {
|
|
60
|
+
if (deleteIndex < 0 || deleteIndex >= arr.length || insertIndex < 0 || insertIndex > arr.length) {
|
|
61
|
+
console.log("下标超出数组范围");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const deletedElement = arr.splice(deleteIndex, 1)[0];
|
|
65
|
+
arr.splice(insertIndex, 0, deletedElement);
|
|
66
|
+
};
|
|
59
67
|
//#endregion
|
|
60
|
-
export { genUrl, openWindow };
|
|
68
|
+
export { deleteAndInsertArr, genUrl, openWindow };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/core",
|
|
3
|
-
"version": "0.1.5-dev.
|
|
3
|
+
"version": "0.1.5-dev.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "paas 平台核心包",
|
|
6
6
|
"loader": "dist/index.esm.min.js",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"author": "gct",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fingerprintjs/fingerprintjs": "^5.1.0",
|
|
35
|
-
"@
|
|
35
|
+
"@floating-ui/dom": "^1.7.6",
|
|
36
|
+
"@gct-paas/api": "0.1.4-dev.3",
|
|
36
37
|
"@module-federation/runtime": "^2.2.3",
|
|
37
38
|
"@vueuse/core": "^14.1.0",
|
|
38
39
|
"async-validator": "^4.2.5",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"playwright": "^1.58.0"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
|
-
"@gct-paas/api": "0.1.4-dev.
|
|
61
|
+
"@gct-paas/api": "0.1.4-dev.3",
|
|
61
62
|
"vue": ">=3",
|
|
62
63
|
"vue-i18n": ">=11",
|
|
63
64
|
"vue-router": ">=4"
|