@jacobbubu/md-to-lark 1.0.0

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.
Files changed (58) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +171 -0
  3. package/dist/btt/build-tree.js +79 -0
  4. package/dist/btt/index.js +1 -0
  5. package/dist/btt/types.js +1 -0
  6. package/dist/cli/publish-md-to-lark.js +15 -0
  7. package/dist/commands/publish-md/args.js +224 -0
  8. package/dist/commands/publish-md/command.js +97 -0
  9. package/dist/commands/publish-md/index.js +1 -0
  10. package/dist/commands/publish-md/input-resolver.js +48 -0
  11. package/dist/commands/publish-md/mermaid-render.js +17 -0
  12. package/dist/commands/publish-md/pipeline-transform.js +4 -0
  13. package/dist/commands/publish-md/preset-loader.js +113 -0
  14. package/dist/commands/publish-md/presets/medium.js +7 -0
  15. package/dist/commands/publish-md/presets/zh-format.js +8 -0
  16. package/dist/commands/publish-md/title-policy.js +93 -0
  17. package/dist/index.js +1 -0
  18. package/dist/interop/btt-to-last.js +79 -0
  19. package/dist/interop/codec-btt-to-last.js +435 -0
  20. package/dist/interop/codec-last-to-btt.js +383 -0
  21. package/dist/interop/codec-shared.js +722 -0
  22. package/dist/interop/index.js +2 -0
  23. package/dist/interop/last-to-btt.js +17 -0
  24. package/dist/lark/block-types.js +42 -0
  25. package/dist/lark/client.js +36 -0
  26. package/dist/lark/docx/ops.js +596 -0
  27. package/dist/lark/docx/render-btt.js +156 -0
  28. package/dist/lark/docx/render-models.js +1 -0
  29. package/dist/lark/docx/render-payload.js +338 -0
  30. package/dist/lark/docx/render-post-process.js +98 -0
  31. package/dist/lark/docx/render-table.js +87 -0
  32. package/dist/lark/docx/render-types.js +7 -0
  33. package/dist/lark/index.js +2 -0
  34. package/dist/lark/types.js +1 -0
  35. package/dist/last/api.js +1687 -0
  36. package/dist/last/index.js +3 -0
  37. package/dist/last/preview-terminal.js +296 -0
  38. package/dist/last/textual-block-types.js +19 -0
  39. package/dist/last/to-markdown.js +303 -0
  40. package/dist/last/types.js +11 -0
  41. package/dist/pipeline/hast-to-last.js +946 -0
  42. package/dist/pipeline/index.js +3 -0
  43. package/dist/pipeline/markdown/md-to-hast.js +34 -0
  44. package/dist/pipeline/markdown/prepare-markdown.js +1049 -0
  45. package/dist/preview/index.js +1 -0
  46. package/dist/preview/markdown-terminal.js +350 -0
  47. package/dist/publish/asset-adapter.js +123 -0
  48. package/dist/publish/btt-patch.js +65 -0
  49. package/dist/publish/common.js +139 -0
  50. package/dist/publish/ids.js +9 -0
  51. package/dist/publish/index.js +7 -0
  52. package/dist/publish/last-normalize.js +327 -0
  53. package/dist/publish/process-file.js +228 -0
  54. package/dist/publish/runtime.js +133 -0
  55. package/dist/publish/stage-cache.js +56 -0
  56. package/dist/shared/rate-limiter.js +18 -0
  57. package/dist/shared/retry.js +141 -0
  58. package/package.json +78 -0
@@ -0,0 +1,722 @@
1
+ import { LAST_TEXTUAL_BLOCK_TYPE_SET } from '../last/textual-block-types.js';
2
+ export const LAST_TO_LARK_BLOCK_TYPE = {
3
+ page: 1,
4
+ text: 2,
5
+ heading1: 3,
6
+ heading2: 4,
7
+ heading3: 5,
8
+ heading4: 6,
9
+ heading5: 7,
10
+ heading6: 8,
11
+ heading7: 9,
12
+ heading8: 10,
13
+ heading9: 11,
14
+ bullet: 12,
15
+ ordered: 13,
16
+ code: 14,
17
+ quote: 15,
18
+ todo: 17,
19
+ bitable: 18,
20
+ callout: 19,
21
+ chat_card: 20,
22
+ diagram: 21,
23
+ divider: 22,
24
+ file: 23,
25
+ grid: 24,
26
+ grid_column: 25,
27
+ iframe: 26,
28
+ image: 27,
29
+ table: 31,
30
+ table_cell: 32,
31
+ view: 33,
32
+ quote_container: 34,
33
+ board: 43,
34
+ mindnote: 29,
35
+ sheet: 30,
36
+ synced_block: 999,
37
+ };
38
+ export const LARK_TO_LAST_BLOCK_TYPE = Object.freeze(Object.fromEntries(Object.entries(LAST_TO_LARK_BLOCK_TYPE).map(([lastType, larkType]) => [larkType, lastType])));
39
+ const TEXTUAL_PAYLOAD_KEY = {
40
+ page: 'page',
41
+ text: 'text',
42
+ heading1: 'heading1',
43
+ heading2: 'heading2',
44
+ heading3: 'heading3',
45
+ heading4: 'heading4',
46
+ heading5: 'heading5',
47
+ heading6: 'heading6',
48
+ heading7: 'heading7',
49
+ heading8: 'heading8',
50
+ heading9: 'heading9',
51
+ bullet: 'bullet',
52
+ ordered: 'ordered',
53
+ code: 'code',
54
+ quote: 'quote',
55
+ todo: 'todo',
56
+ };
57
+ const ALIGN_TO_NUM = {
58
+ left: 1,
59
+ center: 2,
60
+ right: 3,
61
+ };
62
+ const NUM_TO_ALIGN = {
63
+ 1: 'left',
64
+ 2: 'center',
65
+ 3: 'right',
66
+ };
67
+ const BLOCK_BG_TO_API = {
68
+ LightGrayBackground: 'LightGrayBackground',
69
+ LightRedBackground: 'LightRedBackground',
70
+ LightOrangeBackground: 'LightOrangeBackground',
71
+ LightYellowBackground: 'LightYellowBackground',
72
+ LightGreenBackground: 'LightGreenBackground',
73
+ LightBlueBackground: 'LightBlueBackground',
74
+ LightPurpleBackground: 'LightPurpleBackground',
75
+ PaleGrayBackground: 'PaleGrayBackground',
76
+ DarkGrayBackground: 'DarkGrayBackground',
77
+ DarkRedBackground: 'DarkRedBackground',
78
+ DarkOrangeBackground: 'DarkOrangeBackground',
79
+ DarkYellowBackground: 'DarkYellowBackground',
80
+ DarkGreenBackground: 'DarkGreenBackground',
81
+ DarkBlueBackground: 'DarkBlueBackground',
82
+ DarkPurpleBackground: 'DarkPurpleBackground',
83
+ };
84
+ const API_TO_BLOCK_BG = Object.freeze(Object.fromEntries(Object.keys(BLOCK_BG_TO_API).map((token) => [BLOCK_BG_TO_API[token], token])));
85
+ const INDENT_TO_API = {
86
+ NoIndent: 'NoIndent',
87
+ OneLevelIndent: 'OneLevelIndent',
88
+ };
89
+ const API_TO_INDENT = Object.freeze(Object.fromEntries(Object.keys(INDENT_TO_API).map((k) => [INDENT_TO_API[k], k])));
90
+ const COLOR_TO_NUM = {
91
+ light_pink: 1,
92
+ light_orange: 2,
93
+ light_yellow: 3,
94
+ light_green: 4,
95
+ light_blue: 5,
96
+ light_purple: 6,
97
+ light_gray: 7,
98
+ dark_pink: 8,
99
+ dark_orange: 9,
100
+ dark_yellow: 10,
101
+ dark_green: 11,
102
+ dark_blue: 12,
103
+ dark_purple: 13,
104
+ dark_gray: 14,
105
+ dark_silver_gray: 15,
106
+ };
107
+ const NUM_TO_COLOR = {
108
+ 1: 'light_pink',
109
+ 2: 'light_orange',
110
+ 3: 'light_yellow',
111
+ 4: 'light_green',
112
+ 5: 'light_blue',
113
+ 6: 'light_purple',
114
+ 7: 'light_gray',
115
+ 8: 'dark_pink',
116
+ 9: 'dark_orange',
117
+ 10: 'dark_yellow',
118
+ 11: 'dark_green',
119
+ 12: 'dark_blue',
120
+ 13: 'dark_purple',
121
+ 14: 'dark_gray',
122
+ 15: 'dark_silver_gray',
123
+ };
124
+ export const CALLOUT_BG_TO_NUM = {
125
+ light_red: 1,
126
+ light_orange: 2,
127
+ light_yellow: 3,
128
+ light_green: 4,
129
+ light_blue: 5,
130
+ light_purple: 6,
131
+ light_gray: 7,
132
+ dark_red: 8,
133
+ dark_orange: 9,
134
+ dark_yellow: 10,
135
+ dark_green: 11,
136
+ dark_blue: 12,
137
+ dark_purple: 13,
138
+ dark_gray: 14,
139
+ };
140
+ export const NUM_TO_CALLOUT_BG = {
141
+ 1: 'light_red',
142
+ 2: 'light_orange',
143
+ 3: 'light_yellow',
144
+ 4: 'light_green',
145
+ 5: 'light_blue',
146
+ 6: 'light_purple',
147
+ 7: 'light_gray',
148
+ 8: 'dark_red',
149
+ 9: 'dark_orange',
150
+ 10: 'dark_yellow',
151
+ 11: 'dark_green',
152
+ 12: 'dark_blue',
153
+ 13: 'dark_purple',
154
+ 14: 'dark_gray',
155
+ };
156
+ export const CALLOUT_BORDER_TO_NUM = {
157
+ red: 1,
158
+ orange: 2,
159
+ yellow: 3,
160
+ green: 4,
161
+ blue: 5,
162
+ purple: 6,
163
+ gray: 7,
164
+ };
165
+ export const NUM_TO_CALLOUT_BORDER = {
166
+ 1: 'red',
167
+ 2: 'orange',
168
+ 3: 'yellow',
169
+ 4: 'green',
170
+ 5: 'blue',
171
+ 6: 'purple',
172
+ 7: 'gray',
173
+ };
174
+ const OBJ_TYPE_TO_NUM = {
175
+ doc: 1,
176
+ sheet: 3,
177
+ bitable: 8,
178
+ mindnote: 11,
179
+ file: 12,
180
+ slide: 15,
181
+ wiki: 16,
182
+ docx: 22,
183
+ };
184
+ export const NUM_TO_OBJ_TYPE = {
185
+ 1: 'doc',
186
+ 3: 'sheet',
187
+ 8: 'bitable',
188
+ 11: 'mindnote',
189
+ 12: 'file',
190
+ 15: 'slide',
191
+ 16: 'wiki',
192
+ 22: 'docx',
193
+ };
194
+ export const IFRAME_TYPE_TO_NUM = {
195
+ bilibili: 1,
196
+ xigua: 2,
197
+ youku: 3,
198
+ airtable: 4,
199
+ baidu_map: 5,
200
+ gaode_map: 6,
201
+ figma: 8,
202
+ modao: 9,
203
+ canva: 10,
204
+ codepen: 11,
205
+ feishu_wenjuan: 12,
206
+ jinshuju: 13,
207
+ };
208
+ export const NUM_TO_IFRAME_TYPE = {
209
+ 1: 'bilibili',
210
+ 2: 'xigua',
211
+ 3: 'youku',
212
+ 4: 'airtable',
213
+ 5: 'baidu_map',
214
+ 6: 'gaode_map',
215
+ 8: 'figma',
216
+ 9: 'modao',
217
+ 10: 'canva',
218
+ 11: 'codepen',
219
+ 12: 'feishu_wenjuan',
220
+ 13: 'jinshuju',
221
+ };
222
+ const KNOWN_CODE_LANG_TO_NUM = {
223
+ text: 1,
224
+ plaintext: 1,
225
+ plain_text: 1,
226
+ assembly: 6,
227
+ bash: 7,
228
+ shell: 7,
229
+ csharp: 8,
230
+ cpp: 9,
231
+ c: 10,
232
+ css: 12,
233
+ coffee: 13,
234
+ go: 24,
235
+ html: 26,
236
+ json: 31,
237
+ java: 32,
238
+ javascript: 33,
239
+ js: 33,
240
+ kotlin: 35,
241
+ markdown: 42,
242
+ md: 42,
243
+ objectivec: 44,
244
+ php: 46,
245
+ perl: 47,
246
+ powershell: 49,
247
+ protobuf: 51,
248
+ python: 52,
249
+ r: 53,
250
+ ruby: 55,
251
+ rust: 56,
252
+ sql: 60,
253
+ scala: 61,
254
+ swift: 64,
255
+ typescript: 66,
256
+ ts: 66,
257
+ xml: 69,
258
+ yaml: 70,
259
+ toml: 77,
260
+ };
261
+ export function deepClone(value) {
262
+ return JSON.parse(JSON.stringify(value));
263
+ }
264
+ export function isTextualType(type) {
265
+ return LAST_TEXTUAL_BLOCK_TYPE_SET.has(type);
266
+ }
267
+ function toCodeLanguageNumber(language) {
268
+ if (language == null)
269
+ return undefined;
270
+ if (/^\d+$/.test(language)) {
271
+ return Number(language);
272
+ }
273
+ const normalized = language.toLowerCase();
274
+ return KNOWN_CODE_LANG_TO_NUM[normalized];
275
+ }
276
+ function fromCodeLanguageValue(raw) {
277
+ if (raw == null)
278
+ return null;
279
+ if (typeof raw === 'number' && Number.isFinite(raw)) {
280
+ return String(raw);
281
+ }
282
+ if (typeof raw === 'string') {
283
+ return raw;
284
+ }
285
+ return null;
286
+ }
287
+ export function toAlignNumber(align) {
288
+ if (typeof align === 'number' && Number.isFinite(align)) {
289
+ return align;
290
+ }
291
+ if (typeof align === 'string' && Object.prototype.hasOwnProperty.call(ALIGN_TO_NUM, align)) {
292
+ return ALIGN_TO_NUM[align];
293
+ }
294
+ return undefined;
295
+ }
296
+ export function fromAlignNumber(raw) {
297
+ if (typeof raw !== 'number' || !Number.isFinite(raw)) {
298
+ return undefined;
299
+ }
300
+ return NUM_TO_ALIGN[raw] ?? raw;
301
+ }
302
+ function toTextElementStyle(marks) {
303
+ const style = {};
304
+ if (Object.prototype.hasOwnProperty.call(marks, 'bold')) {
305
+ style.bold = Boolean(marks.bold);
306
+ }
307
+ if (Object.prototype.hasOwnProperty.call(marks, 'italic')) {
308
+ style.italic = Boolean(marks.italic);
309
+ }
310
+ if (Object.prototype.hasOwnProperty.call(marks, 'strikethrough')) {
311
+ style.strikethrough = Boolean(marks.strikethrough);
312
+ }
313
+ if (Object.prototype.hasOwnProperty.call(marks, 'underline')) {
314
+ style.underline = Boolean(marks.underline);
315
+ }
316
+ if (Object.prototype.hasOwnProperty.call(marks, 'inlineCode')) {
317
+ style.inline_code = Boolean(marks.inlineCode);
318
+ }
319
+ if (marks.backgroundColor) {
320
+ style.background_color = COLOR_TO_NUM[marks.backgroundColor];
321
+ }
322
+ if (marks.textColor) {
323
+ style.text_color = COLOR_TO_NUM[marks.textColor];
324
+ }
325
+ if (marks.link) {
326
+ style.link = { url: marks.link.url };
327
+ }
328
+ if (Array.isArray(marks.commentIds) && marks.commentIds.length > 0) {
329
+ style.comment_ids = [...marks.commentIds];
330
+ }
331
+ return style;
332
+ }
333
+ function fromTextElementStyle(raw) {
334
+ const style = (raw ?? {});
335
+ const marks = {};
336
+ if (Object.prototype.hasOwnProperty.call(style, 'bold')) {
337
+ marks.bold = Boolean(style.bold);
338
+ }
339
+ if (Object.prototype.hasOwnProperty.call(style, 'italic')) {
340
+ marks.italic = Boolean(style.italic);
341
+ }
342
+ if (Object.prototype.hasOwnProperty.call(style, 'strikethrough')) {
343
+ marks.strikethrough = Boolean(style.strikethrough);
344
+ }
345
+ if (Object.prototype.hasOwnProperty.call(style, 'underline')) {
346
+ marks.underline = Boolean(style.underline);
347
+ }
348
+ if (Object.prototype.hasOwnProperty.call(style, 'inline_code')) {
349
+ marks.inlineCode = Boolean(style.inline_code);
350
+ }
351
+ if (Object.prototype.hasOwnProperty.call(style, 'background_color')) {
352
+ if (typeof style.background_color === 'number') {
353
+ marks.backgroundColor = NUM_TO_COLOR[style.background_color] ?? null;
354
+ }
355
+ else {
356
+ marks.backgroundColor = null;
357
+ }
358
+ }
359
+ if (Object.prototype.hasOwnProperty.call(style, 'text_color')) {
360
+ if (typeof style.text_color === 'number') {
361
+ marks.textColor = NUM_TO_COLOR[style.text_color] ?? null;
362
+ }
363
+ else {
364
+ marks.textColor = null;
365
+ }
366
+ }
367
+ if (Object.prototype.hasOwnProperty.call(style, 'link')) {
368
+ const linkRaw = style.link;
369
+ marks.link =
370
+ linkRaw && typeof linkRaw.url === 'string'
371
+ ? {
372
+ url: linkRaw.url,
373
+ }
374
+ : null;
375
+ }
376
+ if (Array.isArray(style.comment_ids)) {
377
+ marks.commentIds = style.comment_ids.filter((item) => typeof item === 'string');
378
+ }
379
+ return marks;
380
+ }
381
+ function resolveLASTBlockRefToBTTId(lastBlockId, lastToBttBlockId) {
382
+ return lastToBttBlockId[lastBlockId] ?? String(lastBlockId);
383
+ }
384
+ function lastInlinesToLarkElements(inlines, lastToBttBlockId) {
385
+ const elements = [];
386
+ for (const inline of inlines) {
387
+ const textElementStyle = toTextElementStyle(inline.marks);
388
+ const stylePart = Object.keys(textElementStyle).length > 0
389
+ ? {
390
+ text_element_style: textElementStyle,
391
+ }
392
+ : {};
393
+ if (inline.kind === 'text_run') {
394
+ const textRun = {
395
+ ...stylePart,
396
+ };
397
+ if (inline.text !== undefined) {
398
+ textRun.content = inline.text;
399
+ }
400
+ elements.push({
401
+ text_run: textRun,
402
+ });
403
+ continue;
404
+ }
405
+ if (inline.kind === 'mention_user') {
406
+ const mentionUser = {
407
+ ...stylePart,
408
+ };
409
+ if (inline.userId !== undefined) {
410
+ mentionUser.user_id = inline.userId;
411
+ }
412
+ elements.push({
413
+ mention_user: mentionUser,
414
+ });
415
+ continue;
416
+ }
417
+ if (inline.kind === 'equation') {
418
+ const equation = {
419
+ ...stylePart,
420
+ };
421
+ if (inline.latex !== undefined) {
422
+ equation.content = inline.latex;
423
+ }
424
+ elements.push({
425
+ equation,
426
+ });
427
+ continue;
428
+ }
429
+ if (inline.kind === 'mention_doc') {
430
+ const mentionDoc = {
431
+ ...stylePart,
432
+ };
433
+ if (inline.token !== undefined) {
434
+ mentionDoc.token = inline.token;
435
+ }
436
+ if (inline.url !== undefined) {
437
+ mentionDoc.url = inline.url;
438
+ }
439
+ if (inline.title !== undefined) {
440
+ mentionDoc.title = inline.title;
441
+ }
442
+ if (Object.prototype.hasOwnProperty.call(inline, 'objType') && typeof inline.objType === 'number') {
443
+ mentionDoc.obj_type = inline.objType;
444
+ }
445
+ else if (Object.prototype.hasOwnProperty.call(inline, 'objType') && typeof inline.objType === 'string') {
446
+ mentionDoc.obj_type = OBJ_TYPE_TO_NUM[inline.objType];
447
+ }
448
+ if (inline.fallbackType) {
449
+ mentionDoc.fallback_type = inline.fallbackType;
450
+ }
451
+ elements.push({
452
+ mention_doc: mentionDoc,
453
+ });
454
+ continue;
455
+ }
456
+ if (inline.kind === 'reminder') {
457
+ const reminder = { ...stylePart };
458
+ if (inline.createUserId !== undefined) {
459
+ reminder.create_user_id = inline.createUserId;
460
+ }
461
+ if (inline.expireTime !== undefined) {
462
+ reminder.expire_time = inline.expireTime;
463
+ }
464
+ if (inline.notifyTime !== undefined) {
465
+ reminder.notify_time = inline.notifyTime;
466
+ }
467
+ if (inline.isNotify !== undefined) {
468
+ reminder.is_notify = inline.isNotify;
469
+ }
470
+ if (inline.isWholeDay !== undefined) {
471
+ reminder.is_whole_day = inline.isWholeDay;
472
+ }
473
+ elements.push({
474
+ reminder,
475
+ });
476
+ continue;
477
+ }
478
+ if (inline.kind === 'inline_block') {
479
+ const inlineBlock = {
480
+ ...stylePart,
481
+ };
482
+ if (inline.blockId !== undefined) {
483
+ inlineBlock.block_id = resolveLASTBlockRefToBTTId(inline.blockId, lastToBttBlockId);
484
+ }
485
+ elements.push({
486
+ inline_block: inlineBlock,
487
+ });
488
+ continue;
489
+ }
490
+ if (inline.kind === 'inline_file') {
491
+ const file = {
492
+ ...stylePart,
493
+ };
494
+ if (inline.fileToken !== undefined) {
495
+ file.file_token = inline.fileToken;
496
+ }
497
+ if (inline.sourceBlockId !== undefined) {
498
+ file.source_block_id = resolveLASTBlockRefToBTTId(inline.sourceBlockId, lastToBttBlockId);
499
+ }
500
+ const inlineBlock = {
501
+ ...stylePart,
502
+ };
503
+ if (inline.inlineBlock.blockId !== undefined) {
504
+ inlineBlock.block_id = resolveLASTBlockRefToBTTId(inline.inlineBlock.blockId, lastToBttBlockId);
505
+ }
506
+ file.inline_block = inlineBlock;
507
+ elements.push({
508
+ file,
509
+ });
510
+ continue;
511
+ }
512
+ if (inline.kind === 'link_preview') {
513
+ const linkPreview = { ...stylePart };
514
+ if (inline.url !== undefined) {
515
+ linkPreview.url = inline.url;
516
+ }
517
+ if (inline.title !== undefined) {
518
+ linkPreview.title = inline.title;
519
+ }
520
+ if (inline.urlType !== undefined) {
521
+ linkPreview.url_type = inline.urlType;
522
+ }
523
+ elements.push({ link_preview: linkPreview });
524
+ }
525
+ }
526
+ return elements;
527
+ }
528
+ function larkElementsToLastInlines(elements, nextInlineId, blockBttId, bttToLastBlockId) {
529
+ const list = Array.isArray(elements) ? elements : [];
530
+ const inlines = [];
531
+ for (let elementIndex = 0; elementIndex < list.length; elementIndex += 1) {
532
+ const item = list[elementIndex];
533
+ if (!item || typeof item !== 'object') {
534
+ continue;
535
+ }
536
+ const bttId = `${blockBttId}/elements/${elementIndex}`;
537
+ const textRun = item.text_run;
538
+ if (textRun) {
539
+ inlines.push({
540
+ id: nextInlineId(),
541
+ bttId,
542
+ kind: 'text_run',
543
+ marks: fromTextElementStyle(textRun.text_element_style),
544
+ ...(typeof textRun.content === 'string' ? { text: textRun.content } : {}),
545
+ });
546
+ continue;
547
+ }
548
+ const mentionUser = item.mention_user;
549
+ if (mentionUser) {
550
+ inlines.push({
551
+ id: nextInlineId(),
552
+ bttId,
553
+ kind: 'mention_user',
554
+ marks: fromTextElementStyle(mentionUser.text_element_style),
555
+ ...(typeof mentionUser.user_id === 'string' ? { userId: mentionUser.user_id } : {}),
556
+ });
557
+ continue;
558
+ }
559
+ const equation = item.equation;
560
+ if (equation) {
561
+ inlines.push({
562
+ id: nextInlineId(),
563
+ bttId,
564
+ kind: 'equation',
565
+ marks: fromTextElementStyle(equation.text_element_style),
566
+ ...(typeof equation.content === 'string' ? { latex: equation.content } : {}),
567
+ });
568
+ continue;
569
+ }
570
+ const mentionDoc = item.mention_doc;
571
+ if (mentionDoc) {
572
+ const objTypeNum = typeof mentionDoc.obj_type === 'number' ? mentionDoc.obj_type : undefined;
573
+ inlines.push({
574
+ id: nextInlineId(),
575
+ bttId,
576
+ kind: 'mention_doc',
577
+ marks: fromTextElementStyle(mentionDoc.text_element_style),
578
+ ...(typeof mentionDoc.token === 'string' ? { token: mentionDoc.token } : {}),
579
+ ...(objTypeNum == null ? {} : { objType: NUM_TO_OBJ_TYPE[objTypeNum] ?? objTypeNum }),
580
+ ...(typeof mentionDoc.url === 'string' ? { url: mentionDoc.url } : {}),
581
+ ...(typeof mentionDoc.title === 'string' ? { title: mentionDoc.title } : {}),
582
+ ...(mentionDoc.fallback_type === 'FallbackToLink' || mentionDoc.fallback_type === 'FallbackToText'
583
+ ? { fallbackType: mentionDoc.fallback_type }
584
+ : {}),
585
+ });
586
+ continue;
587
+ }
588
+ const reminder = item.reminder;
589
+ if (reminder) {
590
+ inlines.push({
591
+ id: nextInlineId(),
592
+ bttId,
593
+ kind: 'reminder',
594
+ marks: fromTextElementStyle(reminder.text_element_style),
595
+ ...(typeof reminder.create_user_id === 'string' ? { createUserId: reminder.create_user_id } : {}),
596
+ ...(typeof reminder.expire_time === 'string' ? { expireTime: reminder.expire_time } : {}),
597
+ ...(typeof reminder.notify_time === 'string' ? { notifyTime: reminder.notify_time } : {}),
598
+ ...(Object.prototype.hasOwnProperty.call(reminder, 'is_notify')
599
+ ? { isNotify: Boolean(reminder.is_notify) }
600
+ : {}),
601
+ ...(Object.prototype.hasOwnProperty.call(reminder, 'is_whole_day')
602
+ ? { isWholeDay: Boolean(reminder.is_whole_day) }
603
+ : {}),
604
+ });
605
+ continue;
606
+ }
607
+ const inlineBlock = item.inline_block;
608
+ if (inlineBlock) {
609
+ const rawBlockId = String(inlineBlock.block_id ?? '');
610
+ inlines.push({
611
+ id: nextInlineId(),
612
+ bttId,
613
+ kind: 'inline_block',
614
+ marks: fromTextElementStyle(inlineBlock.text_element_style),
615
+ ...(Object.prototype.hasOwnProperty.call(inlineBlock, 'block_id')
616
+ ? {
617
+ blockId: (bttToLastBlockId[rawBlockId] ?? rawBlockId),
618
+ }
619
+ : {}),
620
+ });
621
+ continue;
622
+ }
623
+ const file = item.file;
624
+ if (file) {
625
+ const rawInlineBlock = file.inline_block;
626
+ const sourceRawBlockId = String(file.source_block_id ?? '');
627
+ const inlineRawBlockId = String(rawInlineBlock?.block_id ?? '');
628
+ inlines.push({
629
+ id: nextInlineId(),
630
+ bttId,
631
+ kind: 'inline_file',
632
+ marks: fromTextElementStyle(file.text_element_style),
633
+ ...(typeof file.file_token === 'string' ? { fileToken: file.file_token } : {}),
634
+ ...(Object.prototype.hasOwnProperty.call(file, 'source_block_id')
635
+ ? {
636
+ sourceBlockId: (bttToLastBlockId[sourceRawBlockId] ?? sourceRawBlockId),
637
+ }
638
+ : {}),
639
+ inlineBlock: {
640
+ ...(Object.prototype.hasOwnProperty.call(rawInlineBlock ?? {}, 'block_id')
641
+ ? {
642
+ blockId: (bttToLastBlockId[inlineRawBlockId] ?? inlineRawBlockId),
643
+ }
644
+ : {}),
645
+ },
646
+ });
647
+ continue;
648
+ }
649
+ const linkPreview = item.link_preview;
650
+ if (linkPreview) {
651
+ inlines.push({
652
+ id: nextInlineId(),
653
+ bttId,
654
+ kind: 'link_preview',
655
+ marks: fromTextElementStyle(linkPreview.text_element_style),
656
+ ...(typeof linkPreview.url === 'string' ? { url: linkPreview.url } : {}),
657
+ ...(linkPreview.url_type === 'Project' || linkPreview.url_type === 'Undefined'
658
+ ? { urlType: linkPreview.url_type }
659
+ : {}),
660
+ ...(typeof linkPreview.title === 'string' ? { title: linkPreview.title } : {}),
661
+ });
662
+ }
663
+ }
664
+ return inlines;
665
+ }
666
+ export function lastTextPayloadToLark(type, payload, lastToBttBlockId) {
667
+ const style = {};
668
+ const align = toAlignNumber(payload.style.align);
669
+ if (align !== undefined) {
670
+ style.align = align;
671
+ }
672
+ if (payload.style.done !== undefined) {
673
+ style.done = payload.style.done;
674
+ }
675
+ if (payload.style.folded !== undefined) {
676
+ style.folded = payload.style.folded;
677
+ }
678
+ if (payload.style.wrap !== undefined) {
679
+ style.wrap = payload.style.wrap;
680
+ }
681
+ if (payload.style.backgroundColor) {
682
+ style.background_color = BLOCK_BG_TO_API[payload.style.backgroundColor];
683
+ }
684
+ if (payload.style.indentationLevel) {
685
+ style.indentation_level = INDENT_TO_API[payload.style.indentationLevel];
686
+ }
687
+ if (payload.style.sequence !== undefined) {
688
+ style.sequence = payload.style.sequence;
689
+ }
690
+ const language = toCodeLanguageNumber(payload.style.language ?? null);
691
+ if (language != null) {
692
+ style.language = language;
693
+ }
694
+ return {
695
+ [TEXTUAL_PAYLOAD_KEY[type]]: {
696
+ ...(Object.keys(style).length > 0 ? { style } : {}),
697
+ elements: lastInlinesToLarkElements(payload.inlines, lastToBttBlockId),
698
+ },
699
+ };
700
+ }
701
+ export function larkTextPayloadToLast(rawBlock, type, nextInlineId, bttToLastBlockId) {
702
+ const key = TEXTUAL_PAYLOAD_KEY[type];
703
+ const raw = (rawBlock[key] ?? {});
704
+ const styleRaw = (raw.style ?? {});
705
+ const bgRaw = typeof styleRaw.background_color === 'string' ? styleRaw.background_color : undefined;
706
+ const indentRaw = typeof styleRaw.indentation_level === 'string' ? styleRaw.indentation_level : undefined;
707
+ const align = fromAlignNumber(styleRaw.align);
708
+ const language = fromCodeLanguageValue(styleRaw.language);
709
+ return {
710
+ style: {
711
+ ...(align === undefined ? {} : { align }),
712
+ ...(language === null ? {} : { language }),
713
+ ...(Object.prototype.hasOwnProperty.call(styleRaw, 'done') ? { done: Boolean(styleRaw.done) } : {}),
714
+ ...(Object.prototype.hasOwnProperty.call(styleRaw, 'folded') ? { folded: Boolean(styleRaw.folded) } : {}),
715
+ ...(Object.prototype.hasOwnProperty.call(styleRaw, 'wrap') ? { wrap: Boolean(styleRaw.wrap) } : {}),
716
+ ...(bgRaw && API_TO_BLOCK_BG[bgRaw] ? { backgroundColor: API_TO_BLOCK_BG[bgRaw] } : {}),
717
+ ...(indentRaw && API_TO_INDENT[indentRaw] ? { indentationLevel: API_TO_INDENT[indentRaw] } : {}),
718
+ ...(typeof styleRaw.sequence === 'string' ? { sequence: styleRaw.sequence } : {}),
719
+ },
720
+ inlines: larkElementsToLastInlines(raw.elements, nextInlineId, String(rawBlock.block_id), bttToLastBlockId),
721
+ };
722
+ }