@quecue/dev-notify 0.1.3 → 0.1.5

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.
@@ -1,3 +1,5 @@
1
+ // 先解析为独立文本块,再在渲染后的可见文本上分段,不切断 HTML 实体或标签。
2
+ import { t } from './i18n.js';
1
3
  export const escapeHtml = (text) => text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
2
4
  export const partTitle = (title, index, total) => total > 1 ? `${title} (${index + 1}/${total})` : title;
3
5
  function inline(text, tags = [], depth = 0) {
@@ -104,7 +106,7 @@ export function visibleText(blocks) {
104
106
  }
105
107
  function cut(text, budget, measure) {
106
108
  if (budget < 1)
107
- throw new Error('可用空间不足,无法分段。');
109
+ throw new Error(t('format.noSpace'));
108
110
  let used = 0, end = 0;
109
111
  for (const ch of text) {
110
112
  const size = measure(ch);
@@ -114,7 +116,7 @@ function cut(text, budget, measure) {
114
116
  end += ch.length;
115
117
  }
116
118
  if (!end && text)
117
- throw new Error('可用空间连一个字符都放不下。');
119
+ throw new Error(t('format.oneChar'));
118
120
  if (end < text.length) {
119
121
  for (const boundary of ['\n\n', '\n', ' ']) {
120
122
  const offset = text.slice(0, end).lastIndexOf(boundary);
@@ -128,7 +130,7 @@ function cut(text, budget, measure) {
128
130
  }
129
131
  export function telegramParts(blocks, budget) {
130
132
  if (budget < 2)
131
- throw new Error('Telegram 标题或底部信息太长,没有剩余空间放正文。');
133
+ throw new Error(t('format.telegramHeader'));
132
134
  const output = [];
133
135
  let html = '', plain = '';
134
136
  const flush = () => { if (plain)
@@ -156,7 +158,7 @@ export function telegramParts(blocks, budget) {
156
158
  }
157
159
  export function feishuParts(blocks, budget) {
158
160
  if (budget < 128)
159
- throw new Error('飞书标题或底部信息太长,没有剩余空间放正文。');
161
+ throw new Error(t('format.feishuHeader'));
160
162
  const output = [];
161
163
  let current = '';
162
164
  const size = (text) => Buffer.byteLength(text, 'utf8');