@flexem/fc-gui 3.0.0-alpha.117 → 3.0.0-alpha.118
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/bundles/@flexem/fc-gui.umd.js +39 -61
- package/bundles/@flexem/fc-gui.umd.js.map +1 -1
- package/bundles/@flexem/fc-gui.umd.min.js +1 -1
- package/bundles/@flexem/fc-gui.umd.min.js.map +1 -1
- package/elements/shared/text/text-state-element.d.ts +0 -1
- package/elements/shared/text/text-state-element.js +39 -61
- package/elements/shared/text/text-state-element.metadata.json +1 -1
- package/package.json +1 -1
|
@@ -16,7 +16,6 @@ export declare class TextStateElement {
|
|
|
16
16
|
constructor(textStates: TextState[], width: number, height: number, logger: LoggerService, version?: number, faultFlickers?: IndicatorLightFaultFlicker[]);
|
|
17
17
|
switchToState(stateId: number): void;
|
|
18
18
|
private getforeignObjectElement;
|
|
19
|
-
private createNewForeignObjectText;
|
|
20
19
|
private removeForeignObjectlement;
|
|
21
20
|
private doFaultFlicker;
|
|
22
21
|
private clearFlickerInterval;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Flicker } from '../../../model';
|
|
2
|
-
import { isNil } from 'lodash';
|
|
3
2
|
export class TextStateElement {
|
|
4
3
|
constructor(textStates, width, height, logger, version, faultFlickers) {
|
|
5
4
|
this.textStates = textStates;
|
|
@@ -23,7 +22,7 @@ export class TextStateElement {
|
|
|
23
22
|
return;
|
|
24
23
|
}
|
|
25
24
|
const content = textState.text.content;
|
|
26
|
-
if (content === '') {
|
|
25
|
+
if (content === '' || content == null) {
|
|
27
26
|
this.removeForeignObjectlement();
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
@@ -33,72 +32,51 @@ export class TextStateElement {
|
|
|
33
32
|
this.logger.debug('The font is undefined.');
|
|
34
33
|
return;
|
|
35
34
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const textElement = this.getforeignObjectElement();
|
|
36
|
+
// 清空旧内容
|
|
37
|
+
textElement.textContent = '';
|
|
38
|
+
// 设置 text-anchor 和 dominant-baseline
|
|
39
|
+
textElement.setAttribute('text-anchor', 'middle');
|
|
40
|
+
textElement.setAttribute('dominant-baseline', 'middle');
|
|
41
|
+
textElement.setAttribute('pointer-events', 'auto');
|
|
42
|
+
// 拆分换行
|
|
43
|
+
const lines = content.split('\n');
|
|
44
|
+
const fontSize = parseInt(font.fontSize, 10);
|
|
45
|
+
const lineHeight = fontSize + 4;
|
|
46
|
+
// 总高度 = 行数 * 行高
|
|
47
|
+
const totalHeight = lines.length * lineHeight;
|
|
48
|
+
// 调整文本整体垂直居中(通过 dy)
|
|
49
|
+
const startY = (this.height / 2) - (totalHeight / 2) + (lineHeight / 2);
|
|
50
|
+
// 添加每行文本
|
|
51
|
+
for (let i = 0; i < lines.length; i++) {
|
|
52
|
+
const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
|
|
53
|
+
tspan.setAttribute('x', (this.width / 2).toString());
|
|
54
|
+
tspan.setAttribute('y', startY + i * lineHeight + 'px');
|
|
55
|
+
tspan.textContent = lines[i].replace(/ /g, '\u00A0');
|
|
56
|
+
tspan.setAttribute('font-size', font.fontSize);
|
|
57
|
+
tspan.setAttribute('fill', font.color);
|
|
58
|
+
tspan.setAttribute('font-family', font.fontFamily);
|
|
59
|
+
tspan.setAttribute('font-weight', font.isBold ? 'bold' : 'normal');
|
|
60
|
+
tspan.setAttribute('font-style', font.isItalic ? 'italic' : 'normal');
|
|
61
|
+
tspan.setAttribute('text-decoration', font.isUnderline ? 'underline' : 'none');
|
|
62
|
+
tspan.setAttribute('text-anchor', 'middle');
|
|
63
|
+
tspan.setAttribute('dominant-baseline', 'middle');
|
|
64
|
+
textElement.appendChild(tspan);
|
|
65
|
+
}
|
|
66
|
+
this.doFaultFlicker(textElement, stateId);
|
|
41
67
|
}
|
|
42
68
|
getforeignObjectElement() {
|
|
43
69
|
if (!this.textElement) {
|
|
44
|
-
this.textElement = document.createElementNS('http://www.w3.org/2000/svg', '
|
|
45
|
-
this.textElement.setAttribute('
|
|
46
|
-
this.textElement.setAttribute('
|
|
70
|
+
this.textElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
71
|
+
this.textElement.setAttribute('x', (this.width / 2).toString());
|
|
72
|
+
this.textElement.setAttribute('y', (this.height / 2).toString());
|
|
73
|
+
this.textElement.setAttribute('text-anchor', 'middle');
|
|
74
|
+
this.textElement.setAttribute('dominant-baseline', 'middle');
|
|
75
|
+
this.textElement.setAttribute('pointer-events', 'auto'); // 确保能接收事件
|
|
47
76
|
this._element.appendChild(this.textElement);
|
|
48
77
|
}
|
|
49
78
|
return this.textElement;
|
|
50
79
|
}
|
|
51
|
-
createNewForeignObjectText(content, font) {
|
|
52
|
-
if (font && !font.fontFamily.includes(',msyh')) {
|
|
53
|
-
font.fontFamily += ',msyh';
|
|
54
|
-
}
|
|
55
|
-
const bodyDiv = document.createElement('div');
|
|
56
|
-
bodyDiv.style.textAlign = font.textAlign ? font.textAlign : 'center';
|
|
57
|
-
bodyDiv.style.userSelect = 'none';
|
|
58
|
-
bodyDiv.style.display = 'table-cell';
|
|
59
|
-
bodyDiv.style.verticalAlign = 'middle';
|
|
60
|
-
if (isNil(content)) {
|
|
61
|
-
content = '';
|
|
62
|
-
}
|
|
63
|
-
let textArray = content.toString().split('\n');
|
|
64
|
-
textArray = textArray.map(item => {
|
|
65
|
-
return item.toString().replace(/\s/g, ' ');
|
|
66
|
-
});
|
|
67
|
-
const fragment = document.createDocumentFragment();
|
|
68
|
-
for (let index = 0; index < textArray.length; index++) {
|
|
69
|
-
const textDiv = document.createElement('div');
|
|
70
|
-
textDiv.innerHTML = textArray[index] ? textArray[index] : ' ';
|
|
71
|
-
let fontString = '';
|
|
72
|
-
if (font.isItalic) {
|
|
73
|
-
fontString += 'italic ';
|
|
74
|
-
}
|
|
75
|
-
if (font.isBold) {
|
|
76
|
-
fontString += 'bold ';
|
|
77
|
-
}
|
|
78
|
-
textDiv.style.wordBreak = 'break-word';
|
|
79
|
-
textDiv.style.color = font.color;
|
|
80
|
-
let lineHeight = 0;
|
|
81
|
-
lineHeight = parseInt(font.fontSize, 10) + 5;
|
|
82
|
-
fontString += font.fontSize + 'px/' + lineHeight + 'px ' + font.fontFamily;
|
|
83
|
-
textDiv.style.font = fontString;
|
|
84
|
-
if (font.isUnderline) {
|
|
85
|
-
textDiv.style.textDecoration = 'underline';
|
|
86
|
-
}
|
|
87
|
-
fragment.appendChild(textDiv);
|
|
88
|
-
}
|
|
89
|
-
bodyDiv.appendChild(fragment);
|
|
90
|
-
const contentDiv = document.createElement('div');
|
|
91
|
-
contentDiv.style.display = 'table';
|
|
92
|
-
contentDiv.style.width = '100%';
|
|
93
|
-
contentDiv.style.height = '100%';
|
|
94
|
-
contentDiv.appendChild(bodyDiv);
|
|
95
|
-
const containerDiv = document.createElement('div');
|
|
96
|
-
containerDiv.style.overflow = 'hidden';
|
|
97
|
-
containerDiv.style.width = this.width.toString() + 'px';
|
|
98
|
-
containerDiv.style.height = this.height.toString() + 'px';
|
|
99
|
-
containerDiv.appendChild(contentDiv);
|
|
100
|
-
return containerDiv;
|
|
101
|
-
}
|
|
102
80
|
removeForeignObjectlement() {
|
|
103
81
|
if (this.textElement) {
|
|
104
82
|
this._element.removeChild(this.textElement);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"__symbolic":"module","version":4,"metadata":{"TextStateElement":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","module":"./text-state.model","name":"TextState","line":
|
|
1
|
+
[{"__symbolic":"module","version":4,"metadata":{"TextStateElement":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","module":"./text-state.model","name":"TextState","line":17,"character":45}]},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","module":"../../../logger","name":"LoggerService","line":20,"character":33},{"__symbolic":"reference","name":"number"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","module":"../../../model/switch-indicator-light/indicator-light-fault-flicker","name":"IndicatorLightFaultFlicker","line":22,"character":41}]}]}],"switchToState":[{"__symbolic":"method"}],"getforeignObjectElement":[{"__symbolic":"method"}],"removeForeignObjectlement":[{"__symbolic":"method"}],"doFaultFlicker":[{"__symbolic":"method"}],"clearFlickerInterval":[{"__symbolic":"method"}]}}}}]
|