@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.
@@ -38894,7 +38894,6 @@ class text_element_TextElement extends conditional_dynamic_display_element_Condi
38894
38894
 
38895
38895
  // CONCATENATED MODULE: ./.tmp/elements/shared/text/text-state-element.ts
38896
38896
 
38897
-
38898
38897
  class text_state_element_TextStateElement {
38899
38898
  constructor(textStates, width, height, logger, version, faultFlickers) {
38900
38899
  this.textStates = textStates;
@@ -38918,7 +38917,7 @@ class text_state_element_TextStateElement {
38918
38917
  return;
38919
38918
  }
38920
38919
  const content = textState.text.content;
38921
- if (content === '') {
38920
+ if (content === '' || content == null) {
38922
38921
  this.removeForeignObjectlement();
38923
38922
  return;
38924
38923
  }
@@ -38928,72 +38927,51 @@ class text_state_element_TextStateElement {
38928
38927
  this.logger.debug('The font is undefined.');
38929
38928
  return;
38930
38929
  }
38931
- const foreignObjectElement = this.getforeignObjectElement();
38932
- foreignObjectElement.innerHTML = '';
38933
- const text = this.createNewForeignObjectText(content, font);
38934
- foreignObjectElement.appendChild(text);
38935
- this.doFaultFlicker(foreignObjectElement, stateId);
38930
+ const textElement = this.getforeignObjectElement();
38931
+ // 清空旧内容
38932
+ textElement.textContent = '';
38933
+ // 设置 text-anchor 和 dominant-baseline
38934
+ textElement.setAttribute('text-anchor', 'middle');
38935
+ textElement.setAttribute('dominant-baseline', 'middle');
38936
+ textElement.setAttribute('pointer-events', 'auto');
38937
+ // 拆分换行
38938
+ const lines = content.split('\n');
38939
+ const fontSize = parseInt(font.fontSize, 10);
38940
+ const lineHeight = fontSize + 4;
38941
+ // 总高度 = 行数 * 行高
38942
+ const totalHeight = lines.length * lineHeight;
38943
+ // 调整文本整体垂直居中(通过 dy)
38944
+ const startY = (this.height / 2) - (totalHeight / 2) + (lineHeight / 2);
38945
+ // 添加每行文本
38946
+ for (let i = 0; i < lines.length; i++) {
38947
+ const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
38948
+ tspan.setAttribute('x', (this.width / 2).toString());
38949
+ tspan.setAttribute('y', startY + i * lineHeight + 'px');
38950
+ tspan.textContent = lines[i].replace(/ /g, '\u00A0');
38951
+ tspan.setAttribute('font-size', font.fontSize);
38952
+ tspan.setAttribute('fill', font.color);
38953
+ tspan.setAttribute('font-family', font.fontFamily);
38954
+ tspan.setAttribute('font-weight', font.isBold ? 'bold' : 'normal');
38955
+ tspan.setAttribute('font-style', font.isItalic ? 'italic' : 'normal');
38956
+ tspan.setAttribute('text-decoration', font.isUnderline ? 'underline' : 'none');
38957
+ tspan.setAttribute('text-anchor', 'middle');
38958
+ tspan.setAttribute('dominant-baseline', 'middle');
38959
+ textElement.appendChild(tspan);
38960
+ }
38961
+ this.doFaultFlicker(textElement, stateId);
38936
38962
  }
38937
38963
  getforeignObjectElement() {
38938
38964
  if (!this.textElement) {
38939
- this.textElement = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
38940
- this.textElement.setAttribute('width', this.width.toString());
38941
- this.textElement.setAttribute('height', this.height.toString());
38965
+ this.textElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');
38966
+ this.textElement.setAttribute('x', (this.width / 2).toString());
38967
+ this.textElement.setAttribute('y', (this.height / 2).toString());
38968
+ this.textElement.setAttribute('text-anchor', 'middle');
38969
+ this.textElement.setAttribute('dominant-baseline', 'middle');
38970
+ this.textElement.setAttribute('pointer-events', 'auto'); // 确保能接收事件
38942
38971
  this._element.appendChild(this.textElement);
38943
38972
  }
38944
38973
  return this.textElement;
38945
38974
  }
38946
- createNewForeignObjectText(content, font) {
38947
- if (font && !font.fontFamily.includes(',msyh')) {
38948
- font.fontFamily += ',msyh';
38949
- }
38950
- const bodyDiv = document.createElement('div');
38951
- bodyDiv.style.textAlign = font.textAlign ? font.textAlign : 'center';
38952
- bodyDiv.style.userSelect = 'none';
38953
- bodyDiv.style.display = 'table-cell';
38954
- bodyDiv.style.verticalAlign = 'middle';
38955
- if (Object(lodash["isNil"])(content)) {
38956
- content = '';
38957
- }
38958
- let textArray = content.toString().split('\n');
38959
- textArray = textArray.map(item => {
38960
- return item.toString().replace(/\s/g, '&nbsp;');
38961
- });
38962
- const fragment = document.createDocumentFragment();
38963
- for (let index = 0; index < textArray.length; index++) {
38964
- const textDiv = document.createElement('div');
38965
- textDiv.innerHTML = textArray[index] ? textArray[index] : '&nbsp;';
38966
- let fontString = '';
38967
- if (font.isItalic) {
38968
- fontString += 'italic ';
38969
- }
38970
- if (font.isBold) {
38971
- fontString += 'bold ';
38972
- }
38973
- textDiv.style.wordBreak = 'break-word';
38974
- textDiv.style.color = font.color;
38975
- let lineHeight = 0;
38976
- lineHeight = parseInt(font.fontSize, 10) + 5;
38977
- fontString += font.fontSize + 'px/' + lineHeight + 'px ' + font.fontFamily;
38978
- textDiv.style.font = fontString;
38979
- if (font.isUnderline) {
38980
- textDiv.style.textDecoration = 'underline';
38981
- }
38982
- fragment.appendChild(textDiv);
38983
- }
38984
- bodyDiv.appendChild(fragment);
38985
- const contentDiv = document.createElement('div');
38986
- contentDiv.style.display = 'table';
38987
- contentDiv.style.width = '100%';
38988
- contentDiv.style.height = '100%';
38989
- contentDiv.appendChild(bodyDiv);
38990
- const containerDiv = document.createElement('div');
38991
- containerDiv.style.overflow = 'hidden';
38992
- containerDiv.style.width = this.width.toString() + 'px';
38993
- containerDiv.style.height = this.height.toString() + 'px';
38994
- containerDiv.appendChild(contentDiv);
38995
- return containerDiv;
38996
- }
38997
38975
  removeForeignObjectlement() {
38998
38976
  if (this.textElement) {
38999
38977
  this._element.removeChild(this.textElement);