@flexem/fc-gui 3.0.0-alpha.143 → 3.0.0-alpha.145
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 +19 -10
- 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-element.js +1 -1
- package/elements/shared/text/text-state-element.js +15 -7
- package/elements/view-operation/view-operation.element.js +3 -2
- package/package.json +1 -1
|
@@ -69,7 +69,7 @@ export class TextElementModal {
|
|
|
69
69
|
const minFontSize = 12;
|
|
70
70
|
lineHeight = parseInt(font.fontSize, 10) + 5;
|
|
71
71
|
fontString += font.fontSize + '/' + lineHeight.toString() + 'px ' + font.fontFamily;
|
|
72
|
-
textDiv.style.cssText = `color: ${font.color};word-break: break-all;font: ${fontString};`;
|
|
72
|
+
textDiv.style.cssText = `color: ${font.color};word-break: break-all;font: ${fontString};text-align: ${textAlign};`;
|
|
73
73
|
if (font.isUnderline) {
|
|
74
74
|
textDiv.style.textDecoration = 'underline';
|
|
75
75
|
}
|
|
@@ -43,8 +43,6 @@ export class TextStateElement {
|
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
const textElement = this.getforeignObjectElement();
|
|
46
|
-
// 清空旧内容
|
|
47
|
-
textElement.textContent = '';
|
|
48
46
|
// 设置 text-anchor 和 dominant-baseline
|
|
49
47
|
textElement.setAttribute('text-anchor', 'middle');
|
|
50
48
|
textElement.setAttribute('dominant-baseline', 'middle');
|
|
@@ -57,9 +55,15 @@ export class TextStateElement {
|
|
|
57
55
|
const totalHeight = lines.length * lineHeight;
|
|
58
56
|
// 调整文本整体垂直居中(通过 dy)
|
|
59
57
|
const startY = (this.height / 2) - (totalHeight / 2) + (lineHeight / 2);
|
|
60
|
-
//
|
|
58
|
+
// 复用已有 tspan,不足则新建,多余则隐藏——避免删除 touch 目标节点导致 touchend 丢失
|
|
59
|
+
const existingTspans = Array.from(textElement.children);
|
|
61
60
|
for (let i = 0; i < lines.length; i++) {
|
|
62
|
-
|
|
61
|
+
let tspan = existingTspans[i];
|
|
62
|
+
if (!tspan) {
|
|
63
|
+
tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
|
|
64
|
+
textElement.appendChild(tspan);
|
|
65
|
+
}
|
|
66
|
+
tspan.setAttribute('display', 'inline');
|
|
63
67
|
tspan.setAttribute('x', (this.width / 2).toString());
|
|
64
68
|
tspan.setAttribute('y', startY + i * lineHeight + 'px');
|
|
65
69
|
tspan.textContent = lines[i].replace(/ /g, '\u00A0');
|
|
@@ -71,7 +75,10 @@ export class TextStateElement {
|
|
|
71
75
|
tspan.setAttribute('text-decoration', font.isUnderline ? 'underline' : 'none');
|
|
72
76
|
tspan.setAttribute('text-anchor', 'middle');
|
|
73
77
|
tspan.setAttribute('dominant-baseline', 'middle');
|
|
74
|
-
|
|
78
|
+
}
|
|
79
|
+
// 隐藏多余的 tspan(不删除)
|
|
80
|
+
for (let i = lines.length; i < existingTspans.length; i++) {
|
|
81
|
+
existingTspans[i].setAttribute('display', 'none');
|
|
75
82
|
}
|
|
76
83
|
this.doFaultFlicker(textElement, stateId);
|
|
77
84
|
}
|
|
@@ -114,12 +121,13 @@ export class TextStateElement {
|
|
|
114
121
|
this.textElement.setAttribute('pointer-events', 'auto'); // 确保能接收事件
|
|
115
122
|
this._element.appendChild(this.textElement);
|
|
116
123
|
}
|
|
124
|
+
this.textElement.setAttribute('display', 'block');
|
|
117
125
|
return this.textElement;
|
|
118
126
|
}
|
|
119
127
|
removeForeignObjectlement() {
|
|
120
128
|
if (this.textElement) {
|
|
121
|
-
this.
|
|
122
|
-
|
|
129
|
+
this.textElement.setAttribute('display', 'none');
|
|
130
|
+
this.textElement.textContent = '';
|
|
123
131
|
}
|
|
124
132
|
}
|
|
125
133
|
doFaultFlicker(textElement, stateId) {
|
|
@@ -32,10 +32,11 @@ export class ViewOperationElement extends ConditionalEnableElement {
|
|
|
32
32
|
initElement() {
|
|
33
33
|
const width = this.model.size.width;
|
|
34
34
|
const height = this.model.size.height;
|
|
35
|
+
// 在 initGraph 之前移除模板原有的 SVG <text>(改用 foreignObject 渲染,支持换行居中)
|
|
36
|
+
// 必须在 initGraph 前执行,否则会误删图形状态内部后续添加的文字节点
|
|
37
|
+
this.$element.find('text').remove();
|
|
35
38
|
this.initGraph(width, height);
|
|
36
39
|
this.rootElement.append('rect').attr('id', 'StateFrame').attr('width', width).attr('height', height).attr('fill', 'transparent');
|
|
37
|
-
// 移除模板中原有的 SVG <text> 元素,改用 TextElementModal(foreignObject)渲染,支持换行
|
|
38
|
-
this.$element.find('text').last().remove();
|
|
39
40
|
const font = Object.assign(Object.assign({}, this.model.label.font), { fontFamily: this.model.label.font.fontFamily || 'msyh' });
|
|
40
41
|
this.textElementModal = new TextElementModal(this.getDisplayText(), font, width, height);
|
|
41
42
|
this.$element.append(this.textElementModal.Element);
|