@pixui-dev/pixui-richtext-helper 0.2.8 → 0.2.10
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/richtext/RichTextCore.d.ts +2 -2
- package/dist/richtext/RichTextCore.js +37 -14
- package/index.js +5 -5
- package/package.json +28 -28
- package/readme.md +7 -1
|
@@ -81,9 +81,9 @@ export declare class RichTextCore {
|
|
|
81
81
|
private static convertSiblingTextToDiv;
|
|
82
82
|
/** text-indent 首行缩进处理 */
|
|
83
83
|
private static handleTextIndent;
|
|
84
|
-
/** line-height / letter-spacing
|
|
84
|
+
/** 处理 line-height / letter-spacing 属性 */
|
|
85
85
|
private static adjustLineHeightAndLetterSpacing;
|
|
86
|
-
/** 把 div 的 text-align 转移到子 text
|
|
86
|
+
/** 把 div 的 text-align 转移到子 text 上,如果出现ql-align-right的class,认为是text-align:right,优先级比style的低 */
|
|
87
87
|
private static transferTextAlign;
|
|
88
88
|
/** 删除空 text 节点 */
|
|
89
89
|
private static removeEmptyText;
|
|
@@ -133,6 +133,18 @@ var mergeStyles = function () {
|
|
|
133
133
|
});
|
|
134
134
|
return serializeStyleObject(mergedStyleObj);
|
|
135
135
|
};
|
|
136
|
+
var CLASS_STYLE_MAP = {
|
|
137
|
+
"ql-direction-rtl": function (old) { return mergeStyles("direction: rtl;", old); },
|
|
138
|
+
"ql-align-right": function (old) { return mergeStyles("text-align: right;", old); },
|
|
139
|
+
};
|
|
140
|
+
var _loop_1 = function (i) {
|
|
141
|
+
var cls = "ql-indent-".concat(i);
|
|
142
|
+
CLASS_STYLE_MAP[cls] = function (old) { return mergeStyles("padding-left: ".concat(i * 2, "em"), old); };
|
|
143
|
+
};
|
|
144
|
+
// 动态生成段落缩进 ql-indent-1 ~ ql-indent-10
|
|
145
|
+
for (var i = 1; i <= 10; i++) {
|
|
146
|
+
_loop_1(i);
|
|
147
|
+
}
|
|
136
148
|
/*****************************************************
|
|
137
149
|
* RichTextCore 主类
|
|
138
150
|
*****************************************************/
|
|
@@ -167,7 +179,7 @@ var RichTextCore = /** @class */ (function () {
|
|
|
167
179
|
var processedSegments = segments.map(function (seg) { return RichTextCore.processSegment(seg, config); });
|
|
168
180
|
// ---------- 第 4 步:拼装 ----------
|
|
169
181
|
var Result = processedSegments.join("");
|
|
170
|
-
|
|
182
|
+
console.log(Result);
|
|
171
183
|
return Result;
|
|
172
184
|
};
|
|
173
185
|
/**
|
|
@@ -371,18 +383,29 @@ var RichTextCore = /** @class */ (function () {
|
|
|
371
383
|
// 各独立处理步骤实现
|
|
372
384
|
// ------------------------------
|
|
373
385
|
RichTextCore.preprocess = function ($) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
var
|
|
377
|
-
$(
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
386
|
+
// 根据映射表统一处理 class → style
|
|
387
|
+
$("*").each(function () {
|
|
388
|
+
var _this = this;
|
|
389
|
+
var classStr = $(this).attr("class") || "";
|
|
390
|
+
if (!classStr)
|
|
391
|
+
return;
|
|
392
|
+
var classArr = classStr.split(/\s+/).filter(Boolean);
|
|
393
|
+
if (classArr.length === 0)
|
|
394
|
+
return;
|
|
395
|
+
var styleStr = $(this).attr("style") || "";
|
|
396
|
+
var changed = false;
|
|
397
|
+
classArr.forEach(function (cls) {
|
|
398
|
+
var mapper = CLASS_STYLE_MAP[cls];
|
|
399
|
+
if (mapper) {
|
|
400
|
+
styleStr = mapper(styleStr, $(_this));
|
|
401
|
+
$(_this).removeClass(cls);
|
|
402
|
+
changed = true;
|
|
403
|
+
}
|
|
381
404
|
});
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
405
|
+
if (changed) {
|
|
406
|
+
$(this).attr("style", styleStr);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
386
409
|
// 在所有标题标签后插入换行 <br>
|
|
387
410
|
$("h1, h2, h3, h4, h5, h6").each(function () {
|
|
388
411
|
// 若标题后紧跟已有换行则不再追加
|
|
@@ -826,7 +849,7 @@ var RichTextCore = /** @class */ (function () {
|
|
|
826
849
|
}
|
|
827
850
|
});
|
|
828
851
|
};
|
|
829
|
-
/** line-height / letter-spacing
|
|
852
|
+
/** 处理 line-height / letter-spacing 属性 */
|
|
830
853
|
RichTextCore.adjustLineHeightAndLetterSpacing = function ($, config) {
|
|
831
854
|
$("text").each(function () {
|
|
832
855
|
var $text = $(this);
|
|
@@ -869,7 +892,7 @@ var RichTextCore = /** @class */ (function () {
|
|
|
869
892
|
}
|
|
870
893
|
});
|
|
871
894
|
};
|
|
872
|
-
/** 把 div 的 text-align 转移到子 text
|
|
895
|
+
/** 把 div 的 text-align 转移到子 text 上,如果出现ql-align-right的class,认为是text-align:right,优先级比style的低 */
|
|
873
896
|
RichTextCore.transferTextAlign = function ($) {
|
|
874
897
|
$("div").each(function () {
|
|
875
898
|
var ta = $(this).css("text-align") || "";
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { RichText } = require("./dist/index");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
RichText,
|
|
5
|
-
};
|
|
1
|
+
const { RichText } = require("./dist/index");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
RichText,
|
|
5
|
+
};
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pixui-dev/pixui-richtext-helper",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "pixui richtext helper",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist/**/*",
|
|
9
|
-
"index.js",
|
|
10
|
-
"readme.md"
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
-
"build": "rm -rf dist && tsc"
|
|
15
|
-
},
|
|
16
|
-
"publishConfig": {
|
|
17
|
-
"access": "public"
|
|
18
|
-
},
|
|
19
|
-
"author": "jnjnjnzhang",
|
|
20
|
-
"license": "ISC",
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"@types/node": "^22.15.33",
|
|
23
|
-
"typescript": "^5.8.3"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"cheerio": "1.0.0-rc.10"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pixui-dev/pixui-richtext-helper",
|
|
3
|
+
"version": "0.2.10",
|
|
4
|
+
"description": "pixui richtext helper",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/**/*",
|
|
9
|
+
"index.js",
|
|
10
|
+
"readme.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
+
"build": "rm -rf dist && tsc"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"author": "jnjnjnzhang",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.15.33",
|
|
23
|
+
"typescript": "^5.8.3"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"cheerio": "1.0.0-rc.10"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/readme.md
CHANGED
|
@@ -109,4 +109,10 @@ componentDidMount() { // 在节点渲染后绑定点击事件
|
|
|
109
109
|
3. 增加将富文本中的px单位的属性统一替换为em单位的选项
|
|
110
110
|
|
|
111
111
|
0.2.7
|
|
112
|
-
1. 增加addCosUrlImageMogr2_w参数
|
|
112
|
+
1. 增加addCosUrlImageMogr2_w参数
|
|
113
|
+
|
|
114
|
+
0.2.8
|
|
115
|
+
1. 补充首行缩进占位符的class
|
|
116
|
+
|
|
117
|
+
0.2.9
|
|
118
|
+
1. 增加对class ql-direction-rtl -> style="direction: rtl;"和class ql-align-right -> style="text-align: right;"的转换支持
|