@pixui-dev/pixui-richtext-helper 0.2.17 → 0.2.19

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.
@@ -16,6 +16,11 @@ export declare const RichText: {
16
16
  * @see RichTextCore.bindLinkClickEvents
17
17
  */
18
18
  bindLinkClickEvents: typeof RichTextCore.bindLinkClickEvents;
19
+ /**
20
+ * 统一转换已解析的 html 中的所有 px 单位为 em 单位
21
+ * @see RichTextCore.convertAllPxToEm
22
+ */
23
+ convertAllPxToEm: typeof RichTextCore.convertAllPxToEm;
19
24
  };
20
25
  export type { LinkClickParams };
21
26
  export { LinkNodeType };
package/dist/RichText.js CHANGED
@@ -20,5 +20,10 @@ exports.RichText = {
20
20
  * @see RichTextCore.bindLinkClickEvents
21
21
  */
22
22
  bindLinkClickEvents: RichTextCore_1.RichTextCore.bindLinkClickEvents,
23
+ /**
24
+ * 统一转换已解析的 html 中的所有 px 单位为 em 单位
25
+ * @see RichTextCore.convertAllPxToEm
26
+ */
27
+ convertAllPxToEm: RichTextCore_1.RichTextCore.convertAllPxToEm,
23
28
  };
24
29
  exports.default = exports.RichText;
@@ -37,6 +37,12 @@ export declare class RichTextCore {
37
37
  * 绑定链接点击事件
38
38
  */
39
39
  static bindLinkClickEvents(linkClickHandler: (params: LinkClickParams) => void): void;
40
+ /**
41
+ * 统一转换HTML中的所有px单位为em单位
42
+ * @param html 原始HTML字符串
43
+ * @returns 转换后的HTML字符串
44
+ */
45
+ static convertAllPxToEm(html: string): string;
40
46
  /*****************************************************
41
47
  * 内部流程函数
42
48
  *****************************************************/
@@ -49,12 +55,6 @@ export declare class RichTextCore {
49
55
  * 处理单个段落片段,返回转换后的片段 HTML
50
56
  */
51
57
  private static processSegment;
52
- /**
53
- * 统一转换HTML中的所有px单位为em单位
54
- * @param html 原始HTML字符串
55
- * @returns 转换后的HTML字符串
56
- */
57
- private static convertAllPxToEm;
58
58
  private static preprocess;
59
59
  private static fixImgSizeUnit;
60
60
  /** 合并 img 标签的 width 和 height 属性 */
@@ -92,6 +92,10 @@ export declare class RichTextCore {
92
92
  private static adjustLineHeightAndLetterSpacing;
93
93
  /** 把 div 的 text-align 转移到子 text 上 */
94
94
  private static transferTextAlign;
95
+ /**
96
+ * 对设置了 direction 的 text 下 key 追加 U+061C(仅处理 rtl)
97
+ */
98
+ private static ensureArabicOrUrduMarkForDirectedTextKeys;
95
99
  /** 删除空 text 节点;并在安全场景下清理空 key 节点(不影响占位/换行) */
96
100
  private static removeEmptyText;
97
101
  /** 补默认 heading 字体大小 */
@@ -297,6 +297,19 @@ var RichTextCore = /** @class */ (function () {
297
297
  });
298
298
  }, 100);
299
299
  };
300
+ /**
301
+ * 统一转换HTML中的所有px单位为em单位
302
+ * @param html 原始HTML字符串
303
+ * @returns 转换后的HTML字符串
304
+ */
305
+ RichTextCore.convertAllPxToEm = function (html) {
306
+ // 转换style属性中的px
307
+ html = html.replace(/style="([^"]*?)"/g, function (match, styleContent) {
308
+ var convertedStyle = convertStylePxToEm(styleContent);
309
+ return "style=\"".concat(convertedStyle, "\"");
310
+ });
311
+ return html;
312
+ };
300
313
  /*****************************************************
301
314
  * 内部流程函数
302
315
  *****************************************************/
@@ -426,6 +439,8 @@ var RichTextCore = /** @class */ (function () {
426
439
  this.adjustLineHeightAndLetterSpacing($, config);
427
440
  // 文本对齐与方向:从 div 下沉至子 <text>
428
441
  this.transferTextAlign($);
442
+ // 对设置了 direction: rtl 的 text 下的 key 检查是否有单独的不带阿语乌语字符的文字节点,没有的话附加一个阿语空格,绕过pixui排版问题
443
+ this.ensureArabicOrUrduMarkForDirectedTextKeys($);
429
444
  // 清理空 <text>
430
445
  this.removeEmptyText($);
431
446
  // this.fixHeadingFontSize($);
@@ -443,19 +458,6 @@ var RichTextCore = /** @class */ (function () {
443
458
  }
444
459
  return res;
445
460
  };
446
- /**
447
- * 统一转换HTML中的所有px单位为em单位
448
- * @param html 原始HTML字符串
449
- * @returns 转换后的HTML字符串
450
- */
451
- RichTextCore.convertAllPxToEm = function (html) {
452
- // 转换style属性中的px
453
- html = html.replace(/style="([^"]*?)"/g, function (match, styleContent) {
454
- var convertedStyle = convertStylePxToEm(styleContent);
455
- return "style=\"".concat(convertedStyle, "\"");
456
- });
457
- return html;
458
- };
459
461
  // ------------------------------
460
462
  // 各独立处理步骤实现
461
463
  // ------------------------------
@@ -1165,6 +1167,32 @@ var RichTextCore = /** @class */ (function () {
1165
1167
  });
1166
1168
  });
1167
1169
  };
1170
+ /**
1171
+ * 对设置了 direction 的 text 下 key 追加 U+061C(仅处理 rtl)
1172
+ */
1173
+ RichTextCore.ensureArabicOrUrduMarkForDirectedTextKeys = function ($) {
1174
+ var ARABIC_URDU_REGEX = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;
1175
+ $("text").each(function () {
1176
+ var styleObj = parseStyleString($(this).attr("style") || "");
1177
+ var dir = (styleObj["direction"] || "").trim().toLowerCase();
1178
+ if (dir !== "rtl")
1179
+ return;
1180
+ $(this)
1181
+ .find("key")
1182
+ .each(function () {
1183
+ var $key = $(this);
1184
+ var textContent = $key.text() || "";
1185
+ if (!textContent.trim())
1186
+ return;
1187
+ if (textContent.includes("\u061C"))
1188
+ return;
1189
+ if (ARABIC_URDU_REGEX.test(textContent))
1190
+ return;
1191
+ var html = $key.html() || "";
1192
+ $key.html(html + "\u061C");
1193
+ });
1194
+ });
1195
+ };
1168
1196
  /** 删除空 text 节点;并在安全场景下清理空 key 节点(不影响占位/换行) */
1169
1197
  RichTextCore.removeEmptyText = function ($) {
1170
1198
  $("text").each(function () {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "0.2.17";
1
+ export declare const LIB_VERSION = "0.2.19";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LIB_VERSION = void 0;
4
4
  /* Auto-generated by scripts/generate-version.js */
5
- exports.LIB_VERSION = "0.2.17";
5
+ exports.LIB_VERSION = "0.2.19";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixui-dev/pixui-richtext-helper",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "description": "pixui richtext helper",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",