@waterwx/dsh-novel-forge 0.1.0 → 1.0.0-alpha

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 (180) hide show
  1. package/README.md +162 -111
  2. package/cordis.patch.yml +1 -1
  3. package/lib/client.js +54165 -2666
  4. package/lib/index.js +11895 -2211
  5. package/lib/types/ai-scan.d.ts +36 -0
  6. package/lib/types/assets.d.ts +19 -4
  7. package/lib/types/assistant.d.ts +6 -0
  8. package/lib/types/author-assets.d.ts +25 -0
  9. package/lib/types/bookshelf.d.ts +8 -1
  10. package/lib/types/client/api.d.ts +235 -3
  11. package/lib/types/client/index.d.ts +1 -1
  12. package/lib/types/client/llmLive.d.ts +33 -0
  13. package/lib/types/client/locales.d.ts +101 -28
  14. package/lib/types/client/panel/AdaptModeView.d.ts +5 -0
  15. package/lib/types/client/panel/AssetsTab.d.ts +6 -1
  16. package/lib/types/client/panel/AuthorAssetsView.d.ts +4 -0
  17. package/lib/types/client/panel/AuthorHome.d.ts +34 -0
  18. package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
  19. package/lib/types/client/panel/CreateBookView.d.ts +13 -0
  20. package/lib/types/client/panel/DirectorView.d.ts +7 -0
  21. package/lib/types/client/panel/FlowGuide.d.ts +22 -0
  22. package/lib/types/client/panel/GlobalAssetLibraryView.d.ts +4 -0
  23. package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
  24. package/lib/types/client/panel/ImportModal.d.ts +7 -0
  25. package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
  26. package/lib/types/client/panel/LiveFeedLog.d.ts +5 -0
  27. package/lib/types/client/panel/MangaRoleLibrary.d.ts +20 -0
  28. package/lib/types/client/panel/MangaWorkspace.d.ts +12 -0
  29. package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
  30. package/lib/types/client/panel/ModelManager.d.ts +14 -0
  31. package/lib/types/client/panel/ModelPicker.d.ts +11 -0
  32. package/lib/types/client/panel/NovelPanel.d.ts +1 -1
  33. package/lib/types/client/panel/ProgressConsole.d.ts +17 -0
  34. package/lib/types/client/panel/ProgressHomeView.d.ts +5 -0
  35. package/lib/types/client/panel/PropLibrary.d.ts +8 -0
  36. package/lib/types/client/panel/ReaderView.d.ts +8 -0
  37. package/lib/types/client/panel/ReasoningSection.d.ts +10 -0
  38. package/lib/types/client/panel/RunPanel.d.ts +5 -0
  39. package/lib/types/client/panel/SceneLibrary.d.ts +16 -0
  40. package/lib/types/client/panel/SettingsView.d.ts +16 -0
  41. package/lib/types/client/panel/ShelfView.d.ts +15 -0
  42. package/lib/types/client/panel/StoryboardTab.d.ts +19 -0
  43. package/lib/types/client/panel/StyleCard.d.ts +8 -0
  44. package/lib/types/client/panel/StyleGallery.d.ts +1 -0
  45. package/lib/types/client/panel/WorldTab.d.ts +10 -0
  46. package/lib/types/client/panel/helpers.d.ts +10 -0
  47. package/lib/types/client/panel/views.d.ts +77 -0
  48. package/lib/types/client/run-status.d.ts +19 -0
  49. package/lib/types/client/text.d.ts +9 -0
  50. package/lib/types/comic-presets.d.ts +12 -0
  51. package/lib/types/engine.d.ts +250 -8
  52. package/lib/types/global-assets.d.ts +6 -0
  53. package/lib/types/index.d.ts +24 -2
  54. package/lib/types/llm-live.d.ts +44 -0
  55. package/lib/types/manga-genre-rules.d.ts +22 -0
  56. package/lib/types/market-radar-scan.d.ts +19 -0
  57. package/lib/types/market-radar-sources.d.ts +31 -0
  58. package/lib/types/novel-context.d.ts +80 -0
  59. package/lib/types/prompt-utils.d.ts +35 -0
  60. package/lib/types/prompting.d.ts +35 -0
  61. package/lib/types/protocol.d.ts +1453 -5
  62. package/lib/types/review-policy.d.ts +97 -0
  63. package/lib/types/run.d.ts +32 -0
  64. package/lib/types/shot-language.d.ts +46 -0
  65. package/lib/types/src/ai-scan.d.ts +36 -0
  66. package/lib/types/src/assets.d.ts +37 -0
  67. package/lib/types/src/assistant.d.ts +45 -0
  68. package/lib/types/src/author-assets.d.ts +25 -0
  69. package/lib/types/src/bookshelf.d.ts +42 -0
  70. package/lib/types/src/client/api.d.ts +234 -0
  71. package/lib/types/src/client/docx.d.ts +15 -0
  72. package/lib/types/src/client/index.d.ts +14 -0
  73. package/lib/types/src/client/locales.d.ts +212 -0
  74. package/lib/types/src/client/mount.d.ts +9 -0
  75. package/lib/types/src/client/panel/AdaptModeView.d.ts +5 -0
  76. package/lib/types/src/client/panel/AssetsTab.d.ts +12 -0
  77. package/lib/types/src/client/panel/AssistantTab.d.ts +7 -0
  78. package/lib/types/src/client/panel/AuthorAssetsView.d.ts +4 -0
  79. package/lib/types/src/client/panel/AuthorHome.d.ts +32 -0
  80. package/lib/types/src/client/panel/BookshelfBar.d.ts +11 -0
  81. package/lib/types/src/client/panel/CreateBookView.d.ts +9 -0
  82. package/lib/types/src/client/panel/FlowGuide.d.ts +22 -0
  83. package/lib/types/src/client/panel/GlobalAssetLibraryView.d.ts +4 -0
  84. package/lib/types/src/client/panel/ImportModal.d.ts +7 -0
  85. package/lib/types/src/client/panel/MangaRoleLibrary.d.ts +20 -0
  86. package/lib/types/src/client/panel/MangaWorkspace.d.ts +12 -0
  87. package/lib/types/src/client/panel/ModelManager.d.ts +14 -0
  88. package/lib/types/src/client/panel/NovelPanel.d.ts +13 -0
  89. package/lib/types/src/client/panel/ProgressConsole.d.ts +17 -0
  90. package/lib/types/src/client/panel/ProgressHomeView.d.ts +5 -0
  91. package/lib/types/src/client/panel/PropLibrary.d.ts +8 -0
  92. package/lib/types/src/client/panel/ReaderView.d.ts +8 -0
  93. package/lib/types/src/client/panel/ReasoningSection.d.ts +10 -0
  94. package/lib/types/src/client/panel/RunPanel.d.ts +5 -0
  95. package/lib/types/src/client/panel/SceneLibrary.d.ts +16 -0
  96. package/lib/types/src/client/panel/SettingsView.d.ts +16 -0
  97. package/lib/types/src/client/panel/ShelfView.d.ts +15 -0
  98. package/lib/types/src/client/panel/StoryboardTab.d.ts +19 -0
  99. package/lib/types/src/client/panel/StyleCard.d.ts +8 -0
  100. package/lib/types/src/client/panel/StyleGallery.d.ts +1 -0
  101. package/lib/types/src/client/panel/WorldTab.d.ts +10 -0
  102. package/lib/types/src/client/panel/controller.d.ts +19 -0
  103. package/lib/types/src/client/panel/helpers.d.ts +18 -0
  104. package/lib/types/src/client/panel/views.d.ts +77 -0
  105. package/lib/types/src/client/sidebar-entry.d.ts +13 -0
  106. package/lib/types/src/client/text.d.ts +9 -0
  107. package/lib/types/src/comic-presets.d.ts +12 -0
  108. package/lib/types/src/docx.d.ts +19 -0
  109. package/lib/types/src/engine.d.ts +402 -0
  110. package/lib/types/src/index.d.ts +79 -0
  111. package/lib/types/src/manga-genre-rules.d.ts +22 -0
  112. package/lib/types/src/novel-context.d.ts +80 -0
  113. package/lib/types/src/prompt-utils.d.ts +35 -0
  114. package/lib/types/src/protocol.d.ts +2176 -0
  115. package/lib/types/src/review-policy.d.ts +97 -0
  116. package/lib/types/src/routes.d.ts +29 -0
  117. package/lib/types/src/run.d.ts +32 -0
  118. package/lib/types/src/shot-language.d.ts +46 -0
  119. package/lib/types/src/story-beat-language.d.ts +35 -0
  120. package/lib/types/src/style-library.d.ts +33 -0
  121. package/lib/types/story-beat-language.d.ts +35 -0
  122. package/lib/types/style-library.d.ts +33 -0
  123. package/package.json +57 -42
  124. package/scripts/patch-schemastery.mjs +47 -0
  125. package/src/ai-scan.ts +179 -0
  126. package/src/assets.ts +1774 -518
  127. package/src/assistant.ts +915 -547
  128. package/src/author-assets.ts +147 -0
  129. package/src/bookshelf.ts +32 -2
  130. package/src/client/api.ts +666 -254
  131. package/src/client/index.ts +3 -1
  132. package/src/client/llmLive.ts +101 -0
  133. package/src/client/locales.ts +178 -31
  134. package/src/client/mount.tsx +1 -1
  135. package/src/client/panel/AdaptModeView.tsx +535 -0
  136. package/src/client/panel/AssetsTab.tsx +168 -51
  137. package/src/client/panel/AssistantTab.tsx +339 -188
  138. package/src/client/panel/AuthorAssetsView.tsx +208 -0
  139. package/src/client/panel/AuthorHome.tsx +234 -0
  140. package/src/client/panel/BookAnalysisView.tsx +60 -0
  141. package/src/client/panel/BookshelfBar.tsx +63 -9
  142. package/src/client/panel/CreateBookView.tsx +371 -0
  143. package/src/client/panel/DirectorView.tsx +200 -0
  144. package/src/client/panel/GlobalAssetLibraryView.tsx +172 -0
  145. package/src/client/panel/IdeaInspirationView.tsx +71 -0
  146. package/src/client/panel/ImportModal.tsx +303 -0
  147. package/src/client/panel/KnowledgeBaseView.tsx +73 -0
  148. package/src/client/panel/LiveFeedLog.tsx +67 -0
  149. package/src/client/panel/MarketRadarView.tsx +374 -0
  150. package/src/client/panel/ModelManager.tsx +205 -0
  151. package/src/client/panel/NovelPanel.tsx +4713 -990
  152. package/src/client/panel/ProgressConsole.tsx +63 -0
  153. package/src/client/panel/ProgressHomeView.tsx +87 -0
  154. package/src/client/panel/ReaderView.tsx +306 -0
  155. package/src/client/panel/ReasoningSection.tsx +31 -0
  156. package/src/client/panel/RunPanel.tsx +204 -0
  157. package/src/client/panel/SettingsView.tsx +265 -0
  158. package/src/client/panel/ShelfView.tsx +242 -0
  159. package/src/client/panel/WorldTab.tsx +202 -0
  160. package/src/client/panel/helpers.ts +50 -0
  161. package/src/client/panel/panel.module.css +4325 -526
  162. package/src/client/panel/views.tsx +346 -0
  163. package/src/client/run-status.ts +100 -0
  164. package/src/client/sidebar-entry.ts +1 -1
  165. package/src/client/text.ts +28 -0
  166. package/src/engine.ts +4230 -1019
  167. package/src/global-assets.ts +59 -0
  168. package/src/index.ts +123 -9
  169. package/src/llm-live.ts +68 -0
  170. package/src/market-radar-scan.ts +41 -0
  171. package/src/market-radar-sources.ts +173 -0
  172. package/src/novel-context.ts +287 -0
  173. package/src/prompt-utils.ts +73 -0
  174. package/src/prompting.ts +159 -0
  175. package/src/protocol.ts +1998 -539
  176. package/src/review-policy.ts +161 -0
  177. package/src/routes.ts +3277 -955
  178. package/src/run.ts +338 -0
  179. package/lib/client.js.map +0 -1
  180. package/lib/index.js.map +0 -1
@@ -0,0 +1,346 @@
1
+ /**
2
+ * 纯展示组件(views):所有状态与事件处理器都留在 NovelPanel,
3
+ * 这里只接收 props 渲染。便于单独维护与复用。
4
+ */
5
+ import type { ReactElement } from 'react'
6
+ import type { AuditIssue, Plotline, PlotlineHealthReport, PlotlinePlan, RoleRecord, RoleStatusCard } from '../../protocol.ts'
7
+ import { tt, ROLE_LABELS, roleColor, kindLabel, plotlineStatusLabel, plotlineStatusColor } from './helpers.ts'
8
+ import css from './panel.module.css'
9
+
10
+ /** 统计格:状态摘要条 / 资产健康通用。 */
11
+ export function StatCell(props: {
12
+ label: string
13
+ value: string
14
+ detail: string
15
+ /** 值颜色(可选)。 */
16
+ valueColor?: string
17
+ /** 值字号覆盖(如长文本用 13)。 */
18
+ valueFontSize?: number
19
+ /** detail 悬浮提示(可选)。 */
20
+ detailTitle?: string
21
+ }): ReactElement {
22
+ return (
23
+ <div className={css.assetStat}>
24
+ <span className={css.assetStatLabel}>{props.label}</span>
25
+ <span className={css.assetStatValue} style={{ color: props.valueColor, fontSize: props.valueFontSize }}>
26
+ {props.value}
27
+ </span>
28
+ <span className={css.assetStatDetail} title={props.detailTitle}>{props.detail}</span>
29
+ </div>
30
+ )
31
+ }
32
+
33
+ /** 待办队列行。 */
34
+ export function TodoRow(props: {
35
+ tone: 'danger' | 'warning' | 'info' | 'success'
36
+ title: string
37
+ description: string
38
+ actionLabel: string
39
+ disabled: boolean
40
+ onAction: () => void
41
+ }): ReactElement {
42
+ return (
43
+ <div className={`${css.todoItem} ${props.tone === 'danger' ? css.todoDanger : props.tone === 'warning' ? css.todoWarning : css.todoInfo}`}>
44
+ <span className={css.todoText}>
45
+ {props.title}
46
+ {props.description !== '' && <span className={css.meta}> — {props.description}</span>}
47
+ </span>
48
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onAction}>
49
+ {props.actionLabel}
50
+ </button>
51
+ </div>
52
+ )
53
+ }
54
+
55
+ /** 全书质检问题行。 */
56
+ export function AuditIssueRow(props: {
57
+ issue: AuditIssue
58
+ disabled: boolean
59
+ onFix: () => void
60
+ }): ReactElement {
61
+ const { issue } = props
62
+ return (
63
+ <div className={`${css.todoItem} ${issue.severity === 'high' ? css.todoDanger : issue.severity === 'medium' ? css.todoWarning : css.todoInfo}`}>
64
+ <span className={css.todoText}>
65
+ <span>
66
+ {issue.chapterNo > 0 ? `第 ${issue.chapterNo} 章` : '未定位章节'} · [{issue.severity}] {issue.item}
67
+ </span>
68
+ {issue.suggestion !== '' && <span className={css.meta}>建议:{issue.suggestion}</span>}
69
+ </span>
70
+ {issue.chapterNo > 0 && (
71
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onFix}>
72
+ 去修订
73
+ </button>
74
+ )}
75
+ </div>
76
+ )
77
+ }
78
+
79
+ /** 剧情线卡片(列表主体)。 */
80
+ export function PlotlineCard(props: {
81
+ line: Plotline
82
+ disabled: boolean
83
+ onRefresh: () => void
84
+ onEdit: () => void
85
+ onRemove: () => void
86
+ }): ReactElement {
87
+ const { line } = props
88
+ return (
89
+ <div key={line.id} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-10)', padding: 'var(--nf-space-8) var(--nf-space-12)', fontSize: 'var(--nf-fs-12)', display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-4)' }}>
90
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
91
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
92
+ <b>{line.name}</b>
93
+ <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(line.kind)}</span>
94
+ <span className={css.badge} style={{ borderColor: plotlineStatusColor(line.status), color: plotlineStatusColor(line.status) }}>{plotlineStatusLabel(line.status)}</span>
95
+ </span>
96
+ <span style={{ display: 'flex', gap: 'var(--nf-space-6)' }}>
97
+ <button
98
+ type="button"
99
+ className={`${css.button} ${css.buttonSmall}`}
100
+ disabled={props.disabled}
101
+ onClick={props.onRefresh}
102
+ title="AI 结合编年录与章节摘要,自动更新这条线的当前进度"
103
+ >
104
+ ↻ AI 刷新进度
105
+ </button>
106
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit}>
107
+ {tt('plotlines.edit')}
108
+ </button>
109
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onRemove}>
110
+ {tt('plotlines.remove')}
111
+ </button>
112
+ </span>
113
+ </div>
114
+ {line.goal !== '' && <div className={css.meta}><b>{tt('plotlines.goal')}:</b>{line.goal}</div>}
115
+ {line.progress !== '' && <div className={css.meta}><b>{tt('plotlines.progress')}:</b>{line.progress}</div>}
116
+ <div className={css.meta}>
117
+ {tt('plotlines.chapters')}:{line.chapters.length > 0 ? line.chapters.map(n => `第${n}章`).join('、') : '—'}
118
+ </div>
119
+ </div>
120
+ )
121
+ }
122
+
123
+ /** AI 候选角色行(提炼结果,可采纳/修改后采纳)。 */
124
+ export function RoleCandidateRow(props: {
125
+ candidate: RoleRecord
126
+ disabled: boolean
127
+ onAdopt: () => void
128
+ onEdit: () => void
129
+ }): ReactElement {
130
+ const { candidate: r } = props
131
+ const label = ROLE_LABELS[r.roleLabel] ?? r.roleLabel
132
+ const color = roleColor(r.roleLabel)
133
+ return (
134
+ <div key={r.name} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-8)', padding: 'var(--nf-space-6) var(--nf-space-10)', fontSize: 'var(--nf-fs-12)' }}>
135
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
136
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
137
+ <b>{r.name}</b>
138
+ <span className={css.badge} style={{ borderColor: color, color }}>{label}</span>
139
+ {r.identity !== '' && <span className={css.meta}>{r.identity}</span>}
140
+ </span>
141
+ <span style={{ display: 'flex', gap: 'var(--nf-space-6)' }}>
142
+ <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={props.onAdopt}>
143
+ + 采纳
144
+ </button>
145
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit} title="修改后再采纳(候选列表保留)">
146
+ ✏️ 修改后采纳
147
+ </button>
148
+ </span>
149
+ </div>
150
+ {r.goals !== '' && <div className={css.meta}>目标:{r.goals}</div>}
151
+ {r.relations.length > 0 && <div className={css.meta}>关系:{r.relations.join('、')}</div>}
152
+ </div>
153
+ )
154
+ }
155
+
156
+ /** 已收录角色卡(含从编年录刷新的当前状态行)。 */
157
+ export function RoleCard(props: {
158
+ role: RoleRecord
159
+ status?: RoleStatusCard
160
+ disabled: boolean
161
+ onEdit: () => void
162
+ onRemove: () => void
163
+ }): ReactElement {
164
+ const { role: r, status: st } = props
165
+ const label = ROLE_LABELS[r.roleLabel] ?? r.roleLabel
166
+ const color = roleColor(r.roleLabel)
167
+ return (
168
+ <div key={r.name} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-8)', padding: 'var(--nf-space-6) var(--nf-space-10)', fontSize: 'var(--nf-fs-12)' }}>
169
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
170
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
171
+ <b>{r.name}</b>
172
+ <span className={css.badge} style={{ borderColor: color, color }}>{label}</span>
173
+ {r.identity !== '' && <span className={css.meta}>{r.identity}</span>}
174
+ </span>
175
+ <span style={{ display: 'flex', gap: 'var(--nf-space-6)' }}>
176
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit}>编辑</button>
177
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onRemove}>删除</button>
178
+ </span>
179
+ </div>
180
+ {r.goals !== '' && <div className={css.meta}>目标:{r.goals}</div>}
181
+ {st !== undefined && (
182
+ <div className={css.meta} style={{ color: 'var(--nf-accent)' }}>
183
+ <b>当前状态:</b>{st.status !== '' ? st.status : '(编年录暂无该角色记录)'}
184
+ {' · 出场 '}{st.appearances} 次 · 最近 第 {st.lastChapter} 章
185
+ </div>
186
+ )}
187
+ {r.relations.length > 0 && <div className={css.meta}>关系:{r.relations.join('、')}</div>}
188
+ {r.arc.length > 0 && <div className={css.meta}>成长线:{r.arc.join(' → ')}</div>}
189
+ {r.knowledge.length > 0 && <div className={css.meta}>知情度:{r.knowledge.join(';')}</div>}
190
+ </div>
191
+ )
192
+ }
193
+
194
+ /** 🩺 剧情健康检查报告面板。 */
195
+ export function PlotlineHealthPanel(props: {
196
+ report: PlotlineHealthReport
197
+ disabled: boolean
198
+ onPlan: () => void
199
+ onClose: () => void
200
+ }): ReactElement {
201
+ const { report } = props
202
+ return (
203
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-6)', border: '1px solid var(--nf-info)', borderRadius: 'var(--nf-radius-12)', padding: 'var(--nf-space-10)' }}>
204
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
205
+ <b>🩺 剧情健康检查</b>
206
+ <span style={{ display: 'flex', gap: 'var(--nf-space-8)' }}>
207
+ <button
208
+ type="button"
209
+ className={`${css.button} ${css.buttonSmall}`}
210
+ disabled={props.disabled}
211
+ onClick={props.onPlan}
212
+ title="基于本次诊断生成下一阶段剧情方案"
213
+ >
214
+ ✨ 基于此设计方案
215
+ </button>
216
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
217
+ </span>
218
+ </div>
219
+ <div style={{ fontSize: 'var(--nf-fs-12)', fontWeight: 700, color: 'var(--nf-accent)' }}>判定:{report.verdict}</div>
220
+ {report.timing !== '' && <div className={css.meta}><b>建议时机:</b>{report.timing}</div>}
221
+ {report.reasons.length > 0 && (
222
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-2)', fontSize: 'var(--nf-fs-12)' }}>
223
+ {report.reasons.map((r, i) => <div key={i} className={css.meta}>· {r}</div>)}
224
+ </div>
225
+ )}
226
+ {report.lines.length > 0 && (
227
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-4)', fontSize: 'var(--nf-fs-12)' }}>
228
+ {report.lines.map((l, i) => {
229
+ const color = l.health === 'ok' ? 'var(--nf-success)' : l.health === 'warning' ? 'var(--nf-warn)' : 'var(--nf-error)'
230
+ const label = l.health === 'ok' ? '健康' : l.health === 'warning' ? '预警' : '搁置过久'
231
+ return (
232
+ <div key={i} style={{ display: 'flex', gap: 'var(--nf-space-8)', alignItems: 'flex-start' }}>
233
+ <span className={css.badge} style={{ borderColor: color, color, flex: 'none', marginTop: 'var(--nf-space-2)' }}>{label}</span>
234
+ <span className={css.meta}><b>{l.name}</b>:{l.note}</span>
235
+ </div>
236
+ )
237
+ })}
238
+ </div>
239
+ )}
240
+ </div>
241
+ )
242
+ }
243
+
244
+ /** ✨ AI 剧情方案面板。 */
245
+ export function PlotlinePlanPanel(props: {
246
+ plan: PlotlinePlan
247
+ disabled: boolean
248
+ onAdopt: (suggestion: Plotline) => void
249
+ onClose: () => void
250
+ }): ReactElement {
251
+ const { plan } = props
252
+ return (
253
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-6)', border: '1px solid var(--nf-accent)', borderRadius: 'var(--nf-radius-12)', padding: 'var(--nf-space-10)' }}>
254
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
255
+ <b>✨ AI 剧情方案</b>
256
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
257
+ </div>
258
+ {plan.direction !== '' && (
259
+ <div className={css.meta} style={{ fontSize: 'var(--nf-fs-12)' }}><b>下一阶段方向:</b>{plan.direction}</div>
260
+ )}
261
+ {plan.suggestions.length > 0 && (
262
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-4)', fontSize: 'var(--nf-fs-12)' }}>
263
+ {plan.suggestions.map((s, i) => (
264
+ <div key={i} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-8)', padding: 'var(--nf-space-6) var(--nf-space-10)' }}>
265
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
266
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
267
+ <b>{s.name}</b>
268
+ <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(s.kind)}</span>
269
+ </span>
270
+ <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={() => { props.onAdopt(s) }}>
271
+ + 采纳
272
+ </button>
273
+ </div>
274
+ {s.goal !== '' && <div className={css.meta}>{s.goal}</div>}
275
+ {s.progress !== '' && <div className={css.meta}>初始进度:{s.progress}</div>}
276
+ </div>
277
+ ))}
278
+ </div>
279
+ )}
280
+ </div>
281
+ )
282
+ }
283
+
284
+ /** ✨ AI 建议剧情线面板。 */
285
+ export function PlotlineSuggestionPanel(props: {
286
+ suggestions: Plotline[]
287
+ disabled: boolean
288
+ onAdopt: (suggestion: Plotline) => void
289
+ onClose: () => void
290
+ }): ReactElement {
291
+ return (
292
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-6)', border: '1px solid var(--nf-info)', borderRadius: 'var(--nf-radius-12)', padding: 'var(--nf-space-10)' }}>
293
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
294
+ <b>✨ AI 建议({props.suggestions.length} 条)</b>
295
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
296
+ </div>
297
+ {props.suggestions.length === 0 && <span className={css.meta}>没有候选线。</span>}
298
+ {props.suggestions.map((s, i) => (
299
+ <div key={i} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-8)', padding: 'var(--nf-space-6) var(--nf-space-10)', fontSize: 'var(--nf-fs-12)' }}>
300
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
301
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
302
+ <b>{s.name}</b>
303
+ <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(s.kind)}</span>
304
+ </span>
305
+ <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={() => { props.onAdopt(s) }}>
306
+ + 采纳
307
+ </button>
308
+ </div>
309
+ {s.goal !== '' && <div className={css.meta}>{s.goal}</div>}
310
+ </div>
311
+ ))}
312
+ </div>
313
+ )
314
+ }
315
+
316
+ /** 空状态基元:图标 + 标题 + 可选提示。compact 变体用于列表/卡片内嵌场景。 */
317
+ export function EmptyState(props: {
318
+ icon?: string
319
+ title: string
320
+ hint?: string
321
+ compact?: boolean
322
+ }): ReactElement {
323
+ return (
324
+ <div className={css.emptyState} data-compact={props.compact === true ? 'true' : undefined}>
325
+ {props.icon !== undefined && <span className={css.emptyStateIcon}>{props.icon}</span>}
326
+ <span className={css.emptyStateTitle}>{props.title}</span>
327
+ {props.hint !== undefined && <span className={css.emptyStateHint}>{props.hint}</span>}
328
+ </div>
329
+ )
330
+ }
331
+
332
+ /** 骨架屏基元:rows 条微光占位行;widths 指定各行宽度档位,循环取用。 */
333
+ export function SkeletonLines(props: {
334
+ rows?: number
335
+ widths?: Array<'full' | 'wide' | 'half'>
336
+ }): ReactElement {
337
+ const rows = props.rows ?? 3
338
+ const widths = props.widths ?? ['full', 'wide', 'half']
339
+ return (
340
+ <div className={css.skeletonLines} aria-hidden="true">
341
+ {Array.from({ length: rows }, (_, i) => (
342
+ <span key={i} className={css.skeletonLine} data-w={widths[i % widths.length]} />
343
+ ))}
344
+ </div>
345
+ )
346
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * 运行状态芯片:固定在页面顶部的「小说工坊生成状态」小徽标。
3
+ * 轮询 /run/status,实时显示 生成中/暂停/完成/停止/出错 + 当前章号;
4
+ * 点击可打开/关闭小说工坊面板。独立 DOM 注入,不触碰主面板逻辑,挂载失败静默降级。
5
+ *
6
+ * P0 重写说明(原实现的三个问题):
7
+ * 1. 整块背景染状态色 + 固定白字 → 浅色主题下「白字配亮底」对比度崩坏。
8
+ * 现在改为「玻璃底 + 主题前景色文字 + 左侧状态色点」,状态只由色点承载,
9
+ * 文字永远跟随主题,任何深浅色下都可读。
10
+ * 2. 样式写死在 JS 的 inline style 里,切主题纹丝不动。
11
+ * 现在改用 CSS Module class,配色走 --nf-chip-* 令牌,
12
+ * 由 body[data-ds-dark-theme] 跟随宿主深浅色。
13
+ * 3. role="button" 却没有 tabindex、没有键盘处理,键盘用户完全用不了。
14
+ * 现在补 tabindex + Enter/Space 激活 + aria-label/live。
15
+ */
16
+ import type { NovelApi } from './api.ts'
17
+ import type { PanelController } from './panel/controller.ts'
18
+ import type { RunState } from '../protocol.ts'
19
+ import css from './panel/panel.module.css'
20
+
21
+ const REFRESH_MS = 4000
22
+
23
+ /** 状态文案。状态语义由左侧色点承载,这里不再放 emoji(避免与色点重复表意)。 */
24
+ function label(s: RunState): string {
25
+ const no = s.currentNo
26
+ switch (s.status) {
27
+ case 'running': return `小说工坊 生成中 · 第${no}章`
28
+ case 'paused': return `小说工坊 已暂停 · 第${no}章`
29
+ case 'done': return `小说工坊 批完成 ${s.startNo}–${s.endNo}`
30
+ case 'stopped': return `小说工坊 已停止 · 第${no}章`
31
+ case 'error': return `小说工坊 出错 · 第${no}章`
32
+ default: return '小说工坊'
33
+ }
34
+ }
35
+
36
+ /** 生成一个固定顶部的状态芯片并开始轮询。返回 dispose。 */
37
+ export function mountRunStatus(controller: PanelController, api: NovelApi): () => void {
38
+ const chip = document.createElement('div')
39
+ chip.className = css.runChip
40
+ chip.setAttribute('role', 'button')
41
+ // P0: role="button" 必须可聚焦、可键盘激活,否则对键盘/读屏用户等同不存在。
42
+ chip.setAttribute('tabindex', '0')
43
+ chip.setAttribute('title', '小说工坊生成状态(点击打开工坊)')
44
+ // 状态是异步轮询出来的,用 aria-live 让读屏用户也能感知变化。
45
+ chip.setAttribute('aria-live', 'polite')
46
+
47
+ const dot = document.createElement('span')
48
+ dot.className = css.runChipDot
49
+ // 纯装饰,颜色信息已由文字表达,不要让读屏重复播报。
50
+ dot.setAttribute('aria-hidden', 'true')
51
+
52
+ const text = document.createElement('span')
53
+ text.className = css.runChipText
54
+
55
+ chip.append(dot, text)
56
+
57
+ const toggle = (): void => { controller.toggle() }
58
+ chip.addEventListener('click', toggle)
59
+ chip.addEventListener('keydown', (e) => {
60
+ if (e.key === 'Enter' || e.key === ' ' || e.key === 'Spacebar') {
61
+ e.preventDefault()
62
+ toggle()
63
+ }
64
+ })
65
+
66
+ document.body.appendChild(chip)
67
+
68
+ let disposed = false
69
+ let timer: number | undefined
70
+
71
+ const render = (s: RunState | null): void => {
72
+ if (s === null) {
73
+ chip.dataset.visible = 'false'
74
+ return
75
+ }
76
+ let body = label(s)
77
+ if (s.status === 'running' && s.stats.error > 0) body += ` · ⚠×${s.stats.error}`
78
+ text.textContent = body
79
+ chip.dataset.status = s.status
80
+ chip.dataset.visible = 'true'
81
+ chip.setAttribute('aria-label', body)
82
+ }
83
+
84
+ const tick = async (): Promise<void> => {
85
+ if (disposed) return
86
+ try {
87
+ const s = await api.runStatus()
88
+ render(s)
89
+ } catch { /* best-effort */ }
90
+ if (!disposed) timer = window.setTimeout(() => { void tick() }, REFRESH_MS)
91
+ }
92
+
93
+ void tick()
94
+
95
+ return () => {
96
+ disposed = true
97
+ if (timer !== undefined) window.clearTimeout(timer)
98
+ chip.remove()
99
+ }
100
+ }
@@ -11,7 +11,7 @@ import css from './panel/panel.module.css'
11
11
  export const ENTRY_SELECTOR = '[data-dsh-novelforge-entry]'
12
12
 
13
13
  /** Inline icon: an open book / writing glyph. */
14
- const ICON = '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 3.5h4a2 2 0 0 1 2 2v7a2 2 0 0 0-2-2h-4z"/><path d="M13.5 3.5h-4a2 2 0 0 0-2 2v7a2 2 0 0 1 2-2h4z"/><path d="M8 5.5v7"/></svg>'
14
+ const ICON = '<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12.67 19a2 2 0 0 0 1.416-.588l6.154-6.172a6 6 0 0 0-8.49-8.49L5.586 9.914A2 2 0 0 0 5 11.328V18a1 1 0 0 0 1 1z"/><path d="M16 8 2 22"/><path d="M17.5 15H9"/></svg>'
15
15
 
16
16
  /** Find the sidebar shell root element. */
17
17
  function sidebarRoot(): HTMLElement | undefined {
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 客户端文件文本智能解码:兼容 UTF-8 BOM / UTF-16 / UTF-8 / GB18030(GBK)。
3
+ * 浏览器 File.text() 固定按 UTF-8 解码,GBK 中文网文 txt 会乱码,这里兜底。
4
+ */
5
+
6
+ /**
7
+ * 读取一个 File 的文本,按编码探测兜底解码。
8
+ * @returns 解码后的文本。
9
+ */
10
+ export async function readFileTextSmart(file: File): Promise<string> {
11
+ const buf = await file.arrayBuffer()
12
+ const u8 = new Uint8Array(buf)
13
+ // UTF-8 BOM
14
+ if (u8.length >= 3 && u8[0] === 0xEF && u8[1] === 0xBB && u8[2] === 0xBF) {
15
+ return new TextDecoder('utf-8').decode(u8.subarray(3))
16
+ }
17
+ // UTF-16 LE / BE
18
+ if (u8.length >= 2 && u8[0] === 0xFF && u8[1] === 0xFE) return new TextDecoder('utf-16le').decode(u8.subarray(2))
19
+ if (u8.length >= 2 && u8[0] === 0xFE && u8[1] === 0xFF) return new TextDecoder('utf-16be').decode(u8.subarray(2))
20
+ // UTF-8(宽松),含替换符则回退 GB18030
21
+ const utf8 = new TextDecoder('utf-8', { fatal: false }).decode(u8)
22
+ if (!utf8.includes('\uFFFD')) return utf8
23
+ try {
24
+ return new TextDecoder('gb18030').decode(u8)
25
+ } catch {
26
+ return utf8
27
+ }
28
+ }