@walavave/cc98-cli 0.2.3 → 0.2.4
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/CHANGELOG.md +19 -2
- package/README.md +6 -1
- package/dist/api/client.d.ts +9 -2
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +42 -4
- package/dist/api/client.js.map +1 -1
- package/dist/api/endpoints.d.ts +6 -0
- package/dist/api/endpoints.d.ts.map +1 -1
- package/dist/api/endpoints.js +6 -0
- package/dist/api/endpoints.js.map +1 -1
- package/dist/tui/app-data.d.ts +7 -26
- package/dist/tui/app-data.d.ts.map +1 -1
- package/dist/tui/app-data.js +7 -1100
- package/dist/tui/app-data.js.map +1 -1
- package/dist/tui/app-runtime/content/list.d.ts +5 -0
- package/dist/tui/app-runtime/content/list.d.ts.map +1 -0
- package/dist/tui/app-runtime/content/list.js +115 -0
- package/dist/tui/app-runtime/content/list.js.map +1 -0
- package/dist/tui/app-runtime/content/navigation.d.ts +5 -0
- package/dist/tui/app-runtime/content/navigation.d.ts.map +1 -0
- package/dist/tui/app-runtime/content/navigation.js +104 -0
- package/dist/tui/app-runtime/content/navigation.js.map +1 -0
- package/dist/tui/app-runtime/content/search.d.ts +4 -0
- package/dist/tui/app-runtime/content/search.d.ts.map +1 -0
- package/dist/tui/app-runtime/content/search.js +122 -0
- package/dist/tui/app-runtime/content/search.js.map +1 -0
- package/dist/tui/app-runtime/content.d.ts +3 -8
- package/dist/tui/app-runtime/content.d.ts.map +1 -1
- package/dist/tui/app-runtime/content.js +3 -286
- package/dist/tui/app-runtime/content.js.map +1 -1
- package/dist/tui/app-runtime/interactions.d.ts.map +1 -1
- package/dist/tui/app-runtime/interactions.js +5 -17
- package/dist/tui/app-runtime/interactions.js.map +1 -1
- package/dist/tui/app-runtime/keyboard.d.ts.map +1 -1
- package/dist/tui/app-runtime/keyboard.js +32 -10
- package/dist/tui/app-runtime/keyboard.js.map +1 -1
- package/dist/tui/app-runtime/me.d.ts +5 -0
- package/dist/tui/app-runtime/me.d.ts.map +1 -0
- package/dist/tui/app-runtime/me.js +83 -0
- package/dist/tui/app-runtime/me.js.map +1 -0
- package/dist/tui/app-runtime/modals.d.ts.map +1 -1
- package/dist/tui/app-runtime/modals.js +27 -11
- package/dist/tui/app-runtime/modals.js.map +1 -1
- package/dist/tui/app-runtime/mouse.d.ts.map +1 -1
- package/dist/tui/app-runtime/mouse.js +8 -2
- package/dist/tui/app-runtime/mouse.js.map +1 -1
- package/dist/tui/app-runtime/state.d.ts.map +1 -1
- package/dist/tui/app-runtime/state.js +3 -1
- package/dist/tui/app-runtime/state.js.map +1 -1
- package/dist/tui/app-runtime/topic.d.ts.map +1 -1
- package/dist/tui/app-runtime/topic.js +41 -1
- package/dist/tui/app-runtime/topic.js.map +1 -1
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/app.js +5 -1
- package/dist/tui/app.js.map +1 -1
- package/dist/tui/cached-client.d.ts +11 -0
- package/dist/tui/cached-client.d.ts.map +1 -1
- package/dist/tui/cached-client.js +47 -0
- package/dist/tui/cached-client.js.map +1 -1
- package/dist/tui/data/accounts.d.ts +6 -0
- package/dist/tui/data/accounts.d.ts.map +1 -0
- package/dist/tui/data/accounts.js +30 -0
- package/dist/tui/data/accounts.js.map +1 -0
- package/dist/tui/data/content.d.ts +9 -0
- package/dist/tui/data/content.d.ts.map +1 -0
- package/dist/tui/data/content.js +196 -0
- package/dist/tui/data/content.js.map +1 -0
- package/dist/tui/data/feed-status.d.ts +3 -0
- package/dist/tui/data/feed-status.d.ts.map +1 -0
- package/dist/tui/data/feed-status.js +37 -0
- package/dist/tui/data/feed-status.js.map +1 -0
- package/dist/tui/data/items.d.ts +6 -0
- package/dist/tui/data/items.d.ts.map +1 -0
- package/dist/tui/data/items.js +67 -0
- package/dist/tui/data/items.js.map +1 -0
- package/dist/tui/data/me.d.ts +8 -0
- package/dist/tui/data/me.d.ts.map +1 -0
- package/dist/tui/data/me.js +167 -0
- package/dist/tui/data/me.js.map +1 -0
- package/dist/tui/data/navigation-state.d.ts +12 -0
- package/dist/tui/data/navigation-state.d.ts.map +1 -0
- package/dist/tui/data/navigation-state.js +118 -0
- package/dist/tui/data/navigation-state.js.map +1 -0
- package/dist/tui/data/search.d.ts +5 -0
- package/dist/tui/data/search.d.ts.map +1 -0
- package/dist/tui/data/search.js +89 -0
- package/dist/tui/data/search.js.map +1 -0
- package/dist/tui/data/topic.d.ts +8 -0
- package/dist/tui/data/topic.d.ts.map +1 -0
- package/dist/tui/data/topic.js +406 -0
- package/dist/tui/data/topic.js.map +1 -0
- package/dist/tui/data/utils.d.ts +10 -0
- package/dist/tui/data/utils.d.ts.map +1 -0
- package/dist/tui/data/utils.js +49 -0
- package/dist/tui/data/utils.js.map +1 -0
- package/dist/tui/data/view-items.d.ts +16 -0
- package/dist/tui/data/view-items.d.ts.map +1 -0
- package/dist/tui/data/view-items.js +179 -0
- package/dist/tui/data/view-items.js.map +1 -0
- package/dist/tui/data/view-loader.d.ts +10 -0
- package/dist/tui/data/view-loader.d.ts.map +1 -0
- package/dist/tui/data/view-loader.js +157 -0
- package/dist/tui/data/view-loader.js.map +1 -0
- package/dist/tui/keymap.d.ts +1 -1
- package/dist/tui/keymap.d.ts.map +1 -1
- package/dist/tui/keymap.js +2 -0
- package/dist/tui/keymap.js.map +1 -1
- package/dist/tui/renderer.d.ts +2 -0
- package/dist/tui/renderer.d.ts.map +1 -1
- package/dist/tui/renderer.js +132 -34
- package/dist/tui/renderer.js.map +1 -1
- package/dist/tui/tui-model.d.ts +22 -0
- package/dist/tui/tui-model.d.ts.map +1 -1
- package/dist/tui/tui-model.js.map +1 -1
- package/dist/tui/ubb-renderer.d.ts.map +1 -1
- package/dist/tui/ubb-renderer.js +7 -2
- package/dist/tui/ubb-renderer.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export function createSearchState() {
|
|
2
|
+
return {
|
|
3
|
+
title: "搜索",
|
|
4
|
+
query: "",
|
|
5
|
+
draft: "",
|
|
6
|
+
loaded: 0,
|
|
7
|
+
size: 10,
|
|
8
|
+
hasMore: false,
|
|
9
|
+
searched: false,
|
|
10
|
+
focus: "input"
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function restorePreviousView(state) {
|
|
14
|
+
const snapshot = state.history.pop();
|
|
15
|
+
if (!snapshot) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (snapshot.kind === "topic") {
|
|
19
|
+
applyTopicSnapshot(state, snapshot.value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
applyListSnapshot(state, snapshot.value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function prepareListView(state, options) {
|
|
26
|
+
if (options.pushParent) {
|
|
27
|
+
state.history.push(snapshotCurrentView(state));
|
|
28
|
+
if (state.history.length > state.historyLimit) {
|
|
29
|
+
state.history = [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
state.mode = "list";
|
|
33
|
+
state.focus = "content";
|
|
34
|
+
state.loading = true;
|
|
35
|
+
state.loadingMore = false;
|
|
36
|
+
state.error = undefined;
|
|
37
|
+
state.itemIndex = 0;
|
|
38
|
+
state.scroll = 0;
|
|
39
|
+
state.topic = undefined;
|
|
40
|
+
state.imageViewer = undefined;
|
|
41
|
+
state.currentBoard = options.currentBoard;
|
|
42
|
+
state.currentFeed = undefined;
|
|
43
|
+
state.currentChat = options.currentChat;
|
|
44
|
+
state.currentUser = options.currentUser;
|
|
45
|
+
state.currentSearch = undefined;
|
|
46
|
+
state.viewTitle = options.title;
|
|
47
|
+
state.items = [];
|
|
48
|
+
state.status = options.status;
|
|
49
|
+
}
|
|
50
|
+
function snapshotCurrentView(state) {
|
|
51
|
+
if (state.mode === "topic" && state.topic) {
|
|
52
|
+
return {
|
|
53
|
+
kind: "topic",
|
|
54
|
+
value: {
|
|
55
|
+
viewTitle: state.viewTitle,
|
|
56
|
+
status: state.status,
|
|
57
|
+
scroll: state.scroll,
|
|
58
|
+
topic: state.topic,
|
|
59
|
+
list: snapshotCurrentList(state)
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
kind: "list",
|
|
65
|
+
value: snapshotCurrentList(state)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function snapshotCurrentList(state) {
|
|
69
|
+
return {
|
|
70
|
+
title: state.viewTitle,
|
|
71
|
+
items: state.items,
|
|
72
|
+
itemIndex: state.itemIndex,
|
|
73
|
+
status: state.status,
|
|
74
|
+
currentBoard: state.currentBoard,
|
|
75
|
+
currentFeed: state.currentFeed,
|
|
76
|
+
currentChat: state.currentChat,
|
|
77
|
+
currentSearch: state.currentSearch,
|
|
78
|
+
currentUser: state.currentUser
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function applyListSnapshot(state, snapshot) {
|
|
82
|
+
state.mode = "list";
|
|
83
|
+
state.focus = "content";
|
|
84
|
+
state.loading = false;
|
|
85
|
+
state.loadingMore = false;
|
|
86
|
+
state.error = undefined;
|
|
87
|
+
state.topic = undefined;
|
|
88
|
+
state.imageViewer = undefined;
|
|
89
|
+
state.currentBoard = snapshot.currentBoard;
|
|
90
|
+
state.currentFeed = snapshot.currentFeed;
|
|
91
|
+
state.currentChat = snapshot.currentChat;
|
|
92
|
+
state.currentSearch = snapshot.currentSearch;
|
|
93
|
+
state.currentUser = snapshot.currentUser;
|
|
94
|
+
state.viewTitle = snapshot.title;
|
|
95
|
+
state.items = snapshot.items;
|
|
96
|
+
state.itemIndex = snapshot.itemIndex;
|
|
97
|
+
state.status = snapshot.status;
|
|
98
|
+
}
|
|
99
|
+
function applyTopicSnapshot(state, snapshot) {
|
|
100
|
+
state.mode = "topic";
|
|
101
|
+
state.focus = "content";
|
|
102
|
+
state.loading = false;
|
|
103
|
+
state.loadingMore = false;
|
|
104
|
+
state.error = undefined;
|
|
105
|
+
state.items = snapshot.list.items;
|
|
106
|
+
state.itemIndex = snapshot.list.itemIndex;
|
|
107
|
+
state.scroll = snapshot.scroll;
|
|
108
|
+
state.topic = snapshot.topic;
|
|
109
|
+
state.imageViewer = undefined;
|
|
110
|
+
state.currentBoard = snapshot.list.currentBoard;
|
|
111
|
+
state.currentFeed = snapshot.list.currentFeed;
|
|
112
|
+
state.currentChat = snapshot.list.currentChat;
|
|
113
|
+
state.currentUser = snapshot.list.currentUser;
|
|
114
|
+
state.currentSearch = snapshot.list.currentSearch;
|
|
115
|
+
state.viewTitle = snapshot.viewTitle;
|
|
116
|
+
state.status = snapshot.status;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=navigation-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-state.js","sourceRoot":"","sources":["../../../src/tui/data/navigation-state.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,iBAAiB;IAC/B,OAAO;QACL,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,CAAC;QACT,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,KAAK;QACd,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,OAAO;KACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAe;IACjD,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IACrC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO;IACT,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC9B,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;SAAM,CAAC;QACN,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,MAAM,UAA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AAI,CAAC,aAAa,CAAC;IAClD,KAAK,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;IACrC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CachedCc98Client } from "../cached-client.js";
|
|
2
|
+
import type { TuiState } from "../tui-model.js";
|
|
3
|
+
export declare function executeSearch(client: CachedCc98Client, state: TuiState, render: () => void, force?: boolean, signal?: AbortSignal): Promise<void>;
|
|
4
|
+
export declare function loadNextSearchPage(client: CachedCc98Client, state: TuiState, render: () => void, signal?: AbortSignal): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/tui/data/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIhD,wBAAsB,aAAa,CACjC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,IAAI,EAClB,KAAK,UAAQ,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAqDf;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,IAAI,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAiCf"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { topicItem } from "./items.js";
|
|
2
|
+
import { asArray, isAbortError } from "./utils.js";
|
|
3
|
+
export async function executeSearch(client, state, render, force = false, signal) {
|
|
4
|
+
const search = state.currentSearch;
|
|
5
|
+
if (!search) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const query = search.draft.trim();
|
|
9
|
+
search.query = query;
|
|
10
|
+
state.error = undefined;
|
|
11
|
+
state.itemIndex = 0;
|
|
12
|
+
state.scroll = 0;
|
|
13
|
+
state.imageViewer = undefined;
|
|
14
|
+
if (!query) {
|
|
15
|
+
search.loaded = 0;
|
|
16
|
+
search.hasMore = false;
|
|
17
|
+
search.searched = false;
|
|
18
|
+
search.focus = "input";
|
|
19
|
+
state.items = [];
|
|
20
|
+
state.loading = false;
|
|
21
|
+
state.loadingMore = false;
|
|
22
|
+
state.status = "搜索:输入关键词后 Enter 执行 j 进入结果 h 返回左栏";
|
|
23
|
+
render();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
state.loading = true;
|
|
27
|
+
state.loadingMore = false;
|
|
28
|
+
state.status = `正在搜索 “${query}”...`;
|
|
29
|
+
render();
|
|
30
|
+
try {
|
|
31
|
+
const topics = asArray(await client.searchTopics(query, 0, search.size, force, signal));
|
|
32
|
+
state.items = topics.map((topic) => topicItem(topic));
|
|
33
|
+
search.loaded = topics.length;
|
|
34
|
+
search.hasMore = topics.length === search.size;
|
|
35
|
+
search.searched = true;
|
|
36
|
+
search.focus = state.items.length > 0 ? "results" : "input";
|
|
37
|
+
state.status = state.items.length === 0
|
|
38
|
+
? `未找到 “${query}” 的相关帖子`
|
|
39
|
+
: search.hasMore
|
|
40
|
+
? `搜索结果:${state.items.length} 项 j/k 选择 Enter 打开 n/Space 继续加载`
|
|
41
|
+
: `搜索结果:${state.items.length} 项 j/k 选择 Enter 打开`;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (isAbortError(error)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
state.error = error instanceof Error ? error.message : String(error);
|
|
48
|
+
state.status = "搜索失败;Enter 重试 h 返回左栏";
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
state.loading = false;
|
|
52
|
+
render();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export async function loadNextSearchPage(client, state, render, signal) {
|
|
56
|
+
const search = state.currentSearch;
|
|
57
|
+
if (!search || !search.query || state.loading || state.loadingMore || !search.hasMore) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
state.loadingMore = true;
|
|
61
|
+
state.error = undefined;
|
|
62
|
+
state.status = `正在加载 “${search.query}” 的更多结果...`;
|
|
63
|
+
render();
|
|
64
|
+
try {
|
|
65
|
+
const topics = asArray(await client.searchTopics(search.query, search.loaded, search.size, false, signal));
|
|
66
|
+
const nextItems = topics.map((topic) => topicItem(topic));
|
|
67
|
+
state.items = [...state.items, ...nextItems];
|
|
68
|
+
search.loaded += topics.length;
|
|
69
|
+
search.hasMore = topics.length === search.size;
|
|
70
|
+
if (state.items.length > 0) {
|
|
71
|
+
search.focus = "results";
|
|
72
|
+
}
|
|
73
|
+
state.status = search.hasMore
|
|
74
|
+
? `搜索结果:${state.items.length} 项 j/k 选择 Enter 打开 n/Space 继续加载`
|
|
75
|
+
: `搜索结果:${state.items.length} 项 已全部加载`;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (isAbortError(error)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
state.error = error instanceof Error ? error.message : String(error);
|
|
82
|
+
state.status = "加载更多搜索结果失败;n/Space 重试";
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
state.loadingMore = false;
|
|
86
|
+
render();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../../src/tui/data/search.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAwB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E,CAAC;YACxB,OAAO;QACT,CAAC;QACD,KAAK,CAAC,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrE,KAAK,CAAC,MAAM,GAAG,uBAAuB,CAAC;IACzC,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;QAC1B,MAAM,EAAE,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type TuiState } from "../tui-model.js";
|
|
2
|
+
import { CachedCc98Client } from "../cached-client.js";
|
|
3
|
+
import type { TuiConfig } from "../../config.js";
|
|
4
|
+
export declare function openTopic(client: CachedCc98Client, state: TuiState, topicId: number, render: () => void, config: TuiConfig, force?: boolean, signal?: AbortSignal): Promise<void>;
|
|
5
|
+
export declare function loadNextTopicPage(client: CachedCc98Client, state: TuiState, render: () => void, config: TuiConfig, signal?: AbortSignal, advanceAfterLoad?: boolean): Promise<void>;
|
|
6
|
+
export declare function jumpToTopicFloor(client: CachedCc98Client, state: TuiState, floor: number, render: () => void, config: TuiConfig, signal?: AbortSignal, force?: boolean): Promise<void>;
|
|
7
|
+
export declare function jumpRelativeTopicFloor(state: TuiState, delta: number): void;
|
|
8
|
+
//# sourceMappingURL=topic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topic.d.ts","sourceRoot":"","sources":["../../../src/tui/data/topic.ts"],"names":[],"mappings":"AAIA,OAAO,EAML,KAAK,QAAQ,EACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,wBAAsB,SAAS,CAC7B,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,IAAI,EAClB,MAAM,EAAE,SAAS,EACjB,KAAK,UAAQ,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAqDf;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,IAAI,EAClB,MAAM,EAAE,SAAS,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,gBAAgB,UAAQ,GACvB,OAAO,CAAC,IAAI,CAAC,CAwCf;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,QAAQ,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,IAAI,EAClB,MAAM,EAAE,SAAS,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,KAAK,UAAQ,GACZ,OAAO,CAAC,IAAI,CAAC,CAiDf;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAW3E"}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { emotionPreviewRows, isEmotionAssetPath, loadEmotionPreview, measureEmotionPreview } from "../emotion-preview.js";
|
|
2
|
+
import { imagePreviewRows, loadImagePreview, measureImagePreview, supportsImagePreview } from "../image-preview.js";
|
|
3
|
+
import { getSidebarWidth } from "../renderer.js";
|
|
4
|
+
import { theme } from "../theme.js";
|
|
5
|
+
import { currentTopicPost, getStatus } from "../tui-model.js";
|
|
6
|
+
import { renderMarkdownToLines, renderUbbToLines } from "../ubb-renderer.js";
|
|
7
|
+
import { asArray, asBoolean, asNumber, asObject, isAbortError, normalizeInlineText } from "./utils.js";
|
|
8
|
+
export async function openTopic(client, state, topicId, render, config, force = false, signal) {
|
|
9
|
+
state.mode = "topic";
|
|
10
|
+
state.loading = true;
|
|
11
|
+
state.loadingMore = false;
|
|
12
|
+
state.error = undefined;
|
|
13
|
+
state.scroll = 0;
|
|
14
|
+
state.imageViewer = undefined;
|
|
15
|
+
state.topic = {
|
|
16
|
+
topicId,
|
|
17
|
+
title: `#${topicId}`,
|
|
18
|
+
meta: "",
|
|
19
|
+
isFavorite: false,
|
|
20
|
+
forceRefresh: force,
|
|
21
|
+
lines: [],
|
|
22
|
+
posts: [],
|
|
23
|
+
loaded: 0,
|
|
24
|
+
size: 10,
|
|
25
|
+
hasMore: true,
|
|
26
|
+
imageCount: 0,
|
|
27
|
+
linkCount: 0,
|
|
28
|
+
floorInput: ""
|
|
29
|
+
};
|
|
30
|
+
state.status = "正在打开帖子...";
|
|
31
|
+
render();
|
|
32
|
+
try {
|
|
33
|
+
const [topicRaw, postsRaw, favoriteRaw] = await Promise.all([
|
|
34
|
+
client.getTopic(topicId, force, signal),
|
|
35
|
+
client.getTopicPosts(topicId, 0, 10, force, signal),
|
|
36
|
+
client.getTopicFavoriteState(topicId, force)
|
|
37
|
+
]);
|
|
38
|
+
const topic = asObject(topicRaw);
|
|
39
|
+
const posts = asArray(postsRaw);
|
|
40
|
+
const reader = buildTopicReader(topicId, topic, posts, 10, config, asBoolean(favoriteRaw) ?? false);
|
|
41
|
+
reader.forceRefresh = force;
|
|
42
|
+
state.topic = reader;
|
|
43
|
+
state.viewTitle = reader.title;
|
|
44
|
+
void loadTopicImagePreviews(state, render, config, state.sidebarWidth);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (isAbortError(error)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
state.error = error instanceof Error ? error.message : String(error);
|
|
51
|
+
state.status = state.history.length > 0
|
|
52
|
+
? "版面读取失败;Esc/Backspace 返回版面列表 h 返回左栏 r 重试"
|
|
53
|
+
: "版面读取失败;h 返回左栏 r 重试";
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
state.loading = false;
|
|
57
|
+
if (!state.error && state.mode === "topic" && state.topic) {
|
|
58
|
+
state.status = getStatus(state);
|
|
59
|
+
}
|
|
60
|
+
render();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export async function loadNextTopicPage(client, state, render, config, signal, advanceAfterLoad = false) {
|
|
64
|
+
if (!state.topic || state.loadingMore || !state.topic.hasMore) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
state.loadingMore = true;
|
|
68
|
+
state.status = "正在加载下一页...";
|
|
69
|
+
render();
|
|
70
|
+
try {
|
|
71
|
+
const previousPostCount = state.topic.posts.length;
|
|
72
|
+
const posts = asArray(await client.getTopicPosts(state.topic.topicId, state.topic.loaded, state.topic.size, state.topic.forceRefresh, signal));
|
|
73
|
+
appendTopicPosts(state.topic, posts, config, state.sidebarWidth);
|
|
74
|
+
void loadTopicImagePreviews(state, render, config, state.sidebarWidth);
|
|
75
|
+
state.topic.loaded += posts.length;
|
|
76
|
+
state.topic.hasMore = posts.length === state.topic.size;
|
|
77
|
+
if (advanceAfterLoad && posts.length > 0) {
|
|
78
|
+
const nextPost = state.topic.posts[previousPostCount];
|
|
79
|
+
if (nextPost) {
|
|
80
|
+
state.scroll = nextPost.lineStart;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (isAbortError(error)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
state.error = error instanceof Error ? error.message : String(error);
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
state.loadingMore = false;
|
|
92
|
+
if (!state.error && state.mode === "topic" && state.topic) {
|
|
93
|
+
state.status = getStatus(state);
|
|
94
|
+
}
|
|
95
|
+
render();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export async function jumpToTopicFloor(client, state, floor, render, config, signal, force = false) {
|
|
99
|
+
const topic = state.topic;
|
|
100
|
+
if (!topic) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const loaded = findTopicPostByFloor(topic, floor);
|
|
104
|
+
if (loaded) {
|
|
105
|
+
state.scroll = loaded.lineStart;
|
|
106
|
+
state.status = getStatus(state);
|
|
107
|
+
render();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const from = Math.floor((floor - 1) / topic.size) * topic.size;
|
|
111
|
+
state.loadingMore = true;
|
|
112
|
+
state.status = `正在读取 ${floor} 楼...`;
|
|
113
|
+
render();
|
|
114
|
+
try {
|
|
115
|
+
const posts = asArray(await client.getTopicPosts(topic.topicId, from, topic.size, topic.forceRefresh || force, signal));
|
|
116
|
+
appendTopicPosts(topic, posts, config, state.sidebarWidth);
|
|
117
|
+
topic.posts.sort((left, right) => (left.floor ?? 0) - (right.floor ?? 0));
|
|
118
|
+
void loadTopicImagePreviews(state, render, config, state.sidebarWidth);
|
|
119
|
+
topic.loaded = Math.max(topic.loaded, from + posts.length);
|
|
120
|
+
topic.hasMore = posts.length === topic.size;
|
|
121
|
+
const target = findTopicPostByFloor(topic, floor);
|
|
122
|
+
if (target) {
|
|
123
|
+
state.scroll = target.lineStart;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
state.status = `未找到 ${floor} 楼`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (!isAbortError(error)) {
|
|
131
|
+
state.error = error instanceof Error ? error.message : String(error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
state.loadingMore = false;
|
|
136
|
+
if (!state.error && findTopicPostByFloor(topic, floor)) {
|
|
137
|
+
state.status = getStatus(state);
|
|
138
|
+
}
|
|
139
|
+
render();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function jumpRelativeTopicFloor(state, delta) {
|
|
143
|
+
const topic = state.topic;
|
|
144
|
+
if (!topic || topic.posts.length === 0) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const current = currentTopicPost(topic, state.scroll);
|
|
148
|
+
const currentIndex = current ? topic.posts.indexOf(current) : 0;
|
|
149
|
+
const next = topic.posts[Math.min(topic.posts.length - 1, Math.max(0, currentIndex + delta))];
|
|
150
|
+
if (next) {
|
|
151
|
+
state.scroll = next.lineStart;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function currentTopicWidthEstimate(sidebarWidthOverride) {
|
|
155
|
+
const width = process.stdout.columns || Number(process.env.COLUMNS) || 80;
|
|
156
|
+
const sidebarWidth = getSidebarWidth(width, sidebarWidthOverride);
|
|
157
|
+
const sidebarRuleWidth = sidebarWidth > 0 ? 1 : 0;
|
|
158
|
+
return Math.max(24, width - sidebarWidth - sidebarRuleWidth);
|
|
159
|
+
}
|
|
160
|
+
async function loadTopicImagePreviews(state, render, config, sidebarWidthOverride) {
|
|
161
|
+
const topic = state.topic;
|
|
162
|
+
if (!topic || !config.previewImages) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const width = Math.max(12, currentTopicWidthEstimate(sidebarWidthOverride) - 4);
|
|
166
|
+
const imageLines = topic.posts
|
|
167
|
+
.flatMap((post) => post.lines)
|
|
168
|
+
.filter((line) => line.kind === "image" &&
|
|
169
|
+
line.imageUrl);
|
|
170
|
+
const previewEnabled = supportsImagePreview();
|
|
171
|
+
for (const line of imageLines) {
|
|
172
|
+
try {
|
|
173
|
+
if (state.topic !== topic) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const maxRows = isEmotionAssetPath(line.imageUrl ?? "") ? emotionPreviewRows : imagePreviewRows;
|
|
177
|
+
if (!line.imagePreviewRows) {
|
|
178
|
+
const measured = isEmotionAssetPath(line.imageUrl ?? "")
|
|
179
|
+
? await measureEmotionPreview(line.imageUrl ?? "", width)
|
|
180
|
+
: await measureImagePreview(line.imageUrl ?? "", width, maxRows);
|
|
181
|
+
if (state.topic !== topic) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (measured) {
|
|
185
|
+
line.imagePreviewRows = measured.rows;
|
|
186
|
+
adjustTopicImageBlockHeight(topic, line, measured.rows, state);
|
|
187
|
+
render();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!previewEnabled || line.imagePreview) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const rows = Math.max(1, Math.min(maxRows, line.imagePreviewRows ?? line.imageBlockRows ?? maxRows));
|
|
194
|
+
const preview = isEmotionAssetPath(line.imageUrl ?? "")
|
|
195
|
+
? await loadEmotionPreview(line.imageUrl ?? "", width)
|
|
196
|
+
: await loadImagePreview(line.imageUrl ?? "", width, rows);
|
|
197
|
+
if (state.topic !== topic) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (preview) {
|
|
201
|
+
line.imagePreview = preview.token;
|
|
202
|
+
line.imagePreviewRows = preview.size.rows;
|
|
203
|
+
adjustTopicImageBlockHeight(topic, line, preview.size.rows, state);
|
|
204
|
+
render();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// Keep the textual image placeholder if preview loading fails.
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function buildTopicReader(topicId, topic, posts, size, config, isFavorite) {
|
|
213
|
+
const title = normalizeInlineText(String(topic.title ?? `#${topicId}`));
|
|
214
|
+
const meta = [
|
|
215
|
+
topic.userName,
|
|
216
|
+
topic.replyCount !== undefined ? `${topic.replyCount} 回复` : undefined,
|
|
217
|
+
topic.hitCount !== undefined ? `${topic.hitCount} 浏览` : undefined
|
|
218
|
+
].filter(Boolean).join(" · ");
|
|
219
|
+
const rendered = renderPosts(posts, currentTopicWidthEstimate(), config);
|
|
220
|
+
return {
|
|
221
|
+
topicId,
|
|
222
|
+
title,
|
|
223
|
+
meta,
|
|
224
|
+
isFavorite,
|
|
225
|
+
forceRefresh: false,
|
|
226
|
+
lines: rendered.lines,
|
|
227
|
+
posts: rendered.posts,
|
|
228
|
+
loaded: posts.length,
|
|
229
|
+
size,
|
|
230
|
+
hasMore: posts.length === size,
|
|
231
|
+
imageCount: rendered.imageCount,
|
|
232
|
+
linkCount: rendered.linkCount,
|
|
233
|
+
floorInput: ""
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function appendTopicPosts(topic, posts, config, sidebarWidthOverride) {
|
|
237
|
+
const next = renderPosts(posts, Math.max(36, currentTopicWidthEstimate(sidebarWidthOverride)), config, topic.lines.length);
|
|
238
|
+
topic.lines.push(...next.lines);
|
|
239
|
+
topic.posts.push(...next.posts);
|
|
240
|
+
topic.imageCount += next.imageCount;
|
|
241
|
+
topic.linkCount += next.linkCount;
|
|
242
|
+
}
|
|
243
|
+
function renderPosts(posts, width, config, lineOffset = 0) {
|
|
244
|
+
const lines = [];
|
|
245
|
+
const entries = [];
|
|
246
|
+
let imageCount = 0;
|
|
247
|
+
let linkCount = 0;
|
|
248
|
+
posts.forEach((postRaw) => {
|
|
249
|
+
const post = asObject(postRaw);
|
|
250
|
+
const lineStart = lineOffset + lines.length;
|
|
251
|
+
const postLines = [];
|
|
252
|
+
const floorNumber = asNumber(post.floor);
|
|
253
|
+
const floor = floorNumber !== undefined ? `#${floorNumber}` : "#?";
|
|
254
|
+
const author = String(post.userName ?? "匿名");
|
|
255
|
+
const time = typeof post.time === "string" ? post.time.replace("T", " ").slice(0, 16) : "";
|
|
256
|
+
const likeCount = asNumber(post.likeCount) ?? 0;
|
|
257
|
+
const dislikeCount = asNumber(post.dislikeCount) ?? 0;
|
|
258
|
+
const likeState = normalizeLikeState(post.likeState);
|
|
259
|
+
const reactions = ` · ${likeCount} 赞 · ${dislikeCount} 踩`;
|
|
260
|
+
const push = (text, kind, extra = {}) => {
|
|
261
|
+
const line = lineOffset + lines.length;
|
|
262
|
+
lines.push(text);
|
|
263
|
+
postLines.push({
|
|
264
|
+
line,
|
|
265
|
+
row: postLines.length,
|
|
266
|
+
floor: floorNumber,
|
|
267
|
+
kind,
|
|
268
|
+
text,
|
|
269
|
+
...extra
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
push(`${floor} ${author}${time ? ` · ${time}` : ""}${reactions}`, "header");
|
|
273
|
+
const contentWidth = Math.max(8, width - 2);
|
|
274
|
+
push(theme.border.horizontal.repeat(contentWidth), "divider");
|
|
275
|
+
const content = typeof post.content === "string" ? post.content : "";
|
|
276
|
+
const contentType = asNumber(post.contentType) ?? 0;
|
|
277
|
+
const rendered = contentType === 1
|
|
278
|
+
? renderMarkdownToLines(content, contentWidth, {
|
|
279
|
+
imagePreviewRows: config.previewImages ? imagePreviewRows : 0
|
|
280
|
+
})
|
|
281
|
+
: renderUbbToLines(content, contentWidth, {
|
|
282
|
+
imagePreviewRows: config.previewImages ? imagePreviewRows : 0
|
|
283
|
+
});
|
|
284
|
+
rendered.lines.forEach((renderedLine, index) => {
|
|
285
|
+
const imageIndex = parseBracketIndex(renderedLine, "image");
|
|
286
|
+
const linkIndex = parseBracketIndex(renderedLine, "link");
|
|
287
|
+
const imageBlockRows = imageIndex !== undefined ? imageBlockHeight(rendered.lines, index) : undefined;
|
|
288
|
+
const kind = renderedLine.trim() === ""
|
|
289
|
+
? "blank"
|
|
290
|
+
: imageIndex !== undefined
|
|
291
|
+
? "image"
|
|
292
|
+
: linkIndex !== undefined
|
|
293
|
+
? "link"
|
|
294
|
+
: renderedLine.startsWith(theme.quote.prefix)
|
|
295
|
+
? "quote"
|
|
296
|
+
: "text";
|
|
297
|
+
push(renderedLine, kind, {
|
|
298
|
+
imageIndex,
|
|
299
|
+
imageUrl: imageIndex !== undefined ? rendered.images[imageIndex - 1] : undefined,
|
|
300
|
+
imageBlockRows,
|
|
301
|
+
linkIndex,
|
|
302
|
+
linkUrl: linkIndex !== undefined ? rendered.links[linkIndex - 1] : undefined
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
push("", "blank");
|
|
306
|
+
const preview = rendered.lines.find((value) => value.trim() &&
|
|
307
|
+
!value.startsWith("[image ") &&
|
|
308
|
+
!value.startsWith("[link ")) ?? "";
|
|
309
|
+
entries.push({
|
|
310
|
+
id: asNumber(post.id),
|
|
311
|
+
userId: asNumber(post.userId),
|
|
312
|
+
floor: floorNumber,
|
|
313
|
+
author,
|
|
314
|
+
time,
|
|
315
|
+
likeCount,
|
|
316
|
+
dislikeCount,
|
|
317
|
+
likeState,
|
|
318
|
+
rating: formatRating(post),
|
|
319
|
+
preview,
|
|
320
|
+
lineStart,
|
|
321
|
+
lineEnd: lineOffset + lines.length - 1,
|
|
322
|
+
imageCount: rendered.images.length,
|
|
323
|
+
linkCount: rendered.links.length,
|
|
324
|
+
images: rendered.images,
|
|
325
|
+
links: rendered.links,
|
|
326
|
+
lines: postLines
|
|
327
|
+
});
|
|
328
|
+
imageCount += rendered.images.length;
|
|
329
|
+
linkCount += rendered.links.length;
|
|
330
|
+
});
|
|
331
|
+
return { lines, posts: entries, imageCount, linkCount };
|
|
332
|
+
}
|
|
333
|
+
function normalizeLikeState(value) {
|
|
334
|
+
return value === 1 || value === 2 ? value : 0;
|
|
335
|
+
}
|
|
336
|
+
function findTopicPostByFloor(topic, floor) {
|
|
337
|
+
return topic.posts.find((entry) => entry.floor === floor);
|
|
338
|
+
}
|
|
339
|
+
function imageBlockHeight(lines, start) {
|
|
340
|
+
let height = 1;
|
|
341
|
+
for (let index = start + 1; index < lines.length; index += 1) {
|
|
342
|
+
const line = lines[index] ?? "";
|
|
343
|
+
if (line.startsWith("[image ") || line.trim() !== "") {
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
height += 1;
|
|
347
|
+
}
|
|
348
|
+
return height;
|
|
349
|
+
}
|
|
350
|
+
function adjustTopicImageBlockHeight(topic, line, nextRows, state) {
|
|
351
|
+
const post = topic.posts.find((entry) => entry.lines.includes(line));
|
|
352
|
+
if (!post) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const startRow = line.row;
|
|
356
|
+
const currentRows = Math.max(1, line.imageBlockRows ?? 1);
|
|
357
|
+
const targetRows = Math.max(1, nextRows);
|
|
358
|
+
if (currentRows === targetRows) {
|
|
359
|
+
line.imageBlockRows = targetRows;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const originalLine = line.line;
|
|
363
|
+
const removeCount = Math.min(currentRows, Math.max(1, post.lines.length - startRow));
|
|
364
|
+
const delta = targetRows - currentRows;
|
|
365
|
+
const filler = Array.from({ length: targetRows - 1 }, () => ({
|
|
366
|
+
line: 0,
|
|
367
|
+
row: 0,
|
|
368
|
+
floor: line.floor,
|
|
369
|
+
kind: "blank",
|
|
370
|
+
text: ""
|
|
371
|
+
}));
|
|
372
|
+
line.imageBlockRows = targetRows;
|
|
373
|
+
post.lines.splice(startRow, removeCount, line, ...filler);
|
|
374
|
+
rebuildTopicLines(topic);
|
|
375
|
+
if (originalLine < state.scroll) {
|
|
376
|
+
state.scroll = Math.max(0, state.scroll + delta);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function rebuildTopicLines(topic) {
|
|
380
|
+
const lines = [];
|
|
381
|
+
topic.posts.forEach((post) => {
|
|
382
|
+
post.lineStart = lines.length;
|
|
383
|
+
post.lines.forEach((entry, row) => {
|
|
384
|
+
entry.row = row;
|
|
385
|
+
entry.line = lines.length;
|
|
386
|
+
lines.push(entry.text);
|
|
387
|
+
});
|
|
388
|
+
post.lineEnd = Math.max(post.lineStart, lines.length - 1);
|
|
389
|
+
});
|
|
390
|
+
topic.lines = lines;
|
|
391
|
+
}
|
|
392
|
+
function parseBracketIndex(value, label) {
|
|
393
|
+
const match = new RegExp(`\\[${label} (\\d+)`).exec(value);
|
|
394
|
+
return match ? Number(match[1]) : undefined;
|
|
395
|
+
}
|
|
396
|
+
function formatRating(post) {
|
|
397
|
+
const value = post.rating ?? post.ratingCount ?? post.wealth ?? post.score;
|
|
398
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
399
|
+
return String(value);
|
|
400
|
+
}
|
|
401
|
+
if (typeof value === "string" && value.trim()) {
|
|
402
|
+
return value.trim();
|
|
403
|
+
}
|
|
404
|
+
return undefined;
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=topic.js.map
|