@pixui-dev/pixui-richtext-helper 0.2.19 → 0.2.20
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/RichTextCore.d.ts +4 -0
- package/dist/RichTextCore.js +46 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/readme.md +8 -0
package/dist/RichTextCore.d.ts
CHANGED
|
@@ -86,6 +86,10 @@ export declare class RichTextCore {
|
|
|
86
86
|
private static flattenNestedText;
|
|
87
87
|
/** 将同一行的 text 节点转为 div 并外包一层 text */
|
|
88
88
|
private static convertSiblingTextToDiv;
|
|
89
|
+
/**
|
|
90
|
+
* 将首尾的空格替换为透明占位 key,避免被 PixUI trim 掉。
|
|
91
|
+
*/
|
|
92
|
+
private static ensureKeyEdgeSpacesPreserved;
|
|
89
93
|
/** text-indent 首行缩进处理 */
|
|
90
94
|
private static handleTextIndent;
|
|
91
95
|
/** 处理 line-height / letter-spacing 属性 */
|
package/dist/RichTextCore.js
CHANGED
|
@@ -402,6 +402,7 @@ var RichTextCore = /** @class */ (function () {
|
|
|
402
402
|
* 处理单个段落片段,返回转换后的片段 HTML
|
|
403
403
|
*/
|
|
404
404
|
RichTextCore.processSegment = function (segmentHtml, config) {
|
|
405
|
+
segmentHtml = segmentHtml.replaceAll(/ /g, " ");
|
|
405
406
|
var $ = cheerio.load(segmentHtml, null, false);
|
|
406
407
|
// 预处理:data-list → class、class → style、margin→padding 合并
|
|
407
408
|
this.preprocess($);
|
|
@@ -433,6 +434,8 @@ var RichTextCore = /** @class */ (function () {
|
|
|
433
434
|
this.flattenNestedText($);
|
|
434
435
|
// 同级文本:拆分为 <key> 片段并统一包入父 <text>
|
|
435
436
|
this.convertSiblingTextToDiv($);
|
|
437
|
+
// 保留 key 节点首尾空格,转为透明占位-,避免被 PixUI trim
|
|
438
|
+
this.ensureKeyEdgeSpacesPreserved($);
|
|
436
439
|
// 首行缩进:text-indent 转透明占位
|
|
437
440
|
this.handleTextIndent($);
|
|
438
441
|
// 行高与字间距:聚合到父 <text> 并按配置缩放 line-height
|
|
@@ -444,13 +447,10 @@ var RichTextCore = /** @class */ (function () {
|
|
|
444
447
|
// 清理空 <text>
|
|
445
448
|
this.removeEmptyText($);
|
|
446
449
|
// this.fixHeadingFontSize($);
|
|
447
|
-
// 最后:修正 img 结束标签、nbsp
|
|
448
450
|
var res = $.html();
|
|
449
451
|
res = res
|
|
450
452
|
.replaceAll(/<img([^>]+)>/g, "<img$1 />")
|
|
451
453
|
.replaceAll(/ /g, " ")
|
|
452
|
-
.replaceAll(/&/g, "&")
|
|
453
|
-
.replaceAll(/"/g, '"')
|
|
454
454
|
.replaceAll("\"", "\"");
|
|
455
455
|
// 统一进行px到em转换
|
|
456
456
|
if (config === null || config === void 0 ? void 0 : config.convertPxToEm) {
|
|
@@ -857,8 +857,8 @@ var RichTextCore = /** @class */ (function () {
|
|
|
857
857
|
if (brParent.length > 0)
|
|
858
858
|
return;
|
|
859
859
|
if (this.type === "text") {
|
|
860
|
-
var text = this.data
|
|
861
|
-
if (text.length > 0) {
|
|
860
|
+
var text = this.data;
|
|
861
|
+
if (text.trim().length > 0) {
|
|
862
862
|
$(this).replaceWith("<text style=\"".concat(mergeStyles("flex-shrink: 0", "flex-direction: row", "word-break: break-word"), "\">").concat(text, "</text>"));
|
|
863
863
|
}
|
|
864
864
|
}
|
|
@@ -1066,6 +1066,47 @@ var RichTextCore = /** @class */ (function () {
|
|
|
1066
1066
|
}
|
|
1067
1067
|
});
|
|
1068
1068
|
};
|
|
1069
|
+
/**
|
|
1070
|
+
* 将首尾的空格替换为透明占位 key,避免被 PixUI trim 掉。
|
|
1071
|
+
*/
|
|
1072
|
+
RichTextCore.ensureKeyEdgeSpacesPreserved = function ($) {
|
|
1073
|
+
var placeholderStyle = mergeStyles("color: transparent", "flex-shrink: 0", "font-size: 1em");
|
|
1074
|
+
$("text").each(function () {
|
|
1075
|
+
$(this)
|
|
1076
|
+
.find("key")
|
|
1077
|
+
.each(function () {
|
|
1078
|
+
var $key = $(this);
|
|
1079
|
+
var nodes = $key.contents().toArray();
|
|
1080
|
+
var textNodes = nodes.filter(function (n) { return n && n.type === "text"; });
|
|
1081
|
+
if (textNodes.length === 0)
|
|
1082
|
+
return;
|
|
1083
|
+
//节点的字号1/2或者0.5em
|
|
1084
|
+
var fontSize = $key.css("font-size");
|
|
1085
|
+
var fontSizeRes = "0.5em";
|
|
1086
|
+
if (fontSize) {
|
|
1087
|
+
fontSizeRes = "".concat(parseFloat(fontSize) / 2).concat(fontSize.replace(/(\d+)/g, ""));
|
|
1088
|
+
}
|
|
1089
|
+
// 处理前导空格
|
|
1090
|
+
var firstTextNode = textNodes[0];
|
|
1091
|
+
var firstData = (firstTextNode.data || "");
|
|
1092
|
+
var leadingMatch = firstData.match(/^( +)/);
|
|
1093
|
+
if (leadingMatch && leadingMatch[1].length > 0) {
|
|
1094
|
+
var n = leadingMatch[1].length;
|
|
1095
|
+
$key.before("<key style=\"".concat(mergeStyles(placeholderStyle, "font-size: ".concat(fontSizeRes)), "\">").concat("-".repeat(n), "</key>"));
|
|
1096
|
+
firstTextNode.data = firstData.slice(n);
|
|
1097
|
+
}
|
|
1098
|
+
// 处理后缀空格
|
|
1099
|
+
var lastTextNode = textNodes[textNodes.length - 1];
|
|
1100
|
+
var lastData = (lastTextNode.data || "");
|
|
1101
|
+
var trailingMatch = lastData.match(/( +)$/);
|
|
1102
|
+
if (trailingMatch && trailingMatch[1].length > 0) {
|
|
1103
|
+
var n = trailingMatch[1].length;
|
|
1104
|
+
$key.after("<key style=\"".concat(mergeStyles(placeholderStyle, "font-size: ".concat(fontSizeRes)), "\">").concat("-".repeat(n), "</key>"));
|
|
1105
|
+
lastTextNode.data = lastData.slice(0, lastData.length - n);
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
});
|
|
1109
|
+
};
|
|
1069
1110
|
/** text-indent 首行缩进处理 */
|
|
1070
1111
|
RichTextCore.handleTextIndent = function ($) {
|
|
1071
1112
|
$("*").each(function () {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "0.2.
|
|
1
|
+
export declare const LIB_VERSION = "0.2.20";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -149,3 +149,11 @@ componentDidMount() { // 在节点渲染后绑定点击事件
|
|
|
149
149
|
0.2.14(f196abf819a64d9b762137512560261e1742c4d4)
|
|
150
150
|
|
|
151
151
|
1. 修复:段落缩进距离过长
|
|
152
|
+
|
|
153
|
+
0.2.19
|
|
154
|
+
|
|
155
|
+
1. 手动补充阿语空格,绕过pixui在阿语rtl节点下key节点内容不带阿语的时候有可能排版错误的问题
|
|
156
|
+
|
|
157
|
+
0.2.20
|
|
158
|
+
|
|
159
|
+
1. 直接填充透明占位符规避行内多个节点的时候空格被pixui trim的问题
|