@yyds-dudu/dsh-novel-reader 0.0.0-stage → 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.
- package/README.md +88 -2
- package/client.js +981 -0
- package/cordis.patch.yml +8 -0
- package/docs/DETAIL.md +1 -0
- package/docs/preview.svg +15 -0
- package/docs/screenshot-1.png +0 -0
- package/docs/screenshot-2.png +0 -0
- package/docs/screenshot-3.png +0 -0
- package/icon.svg +7 -0
- package/index.js +2 -0
- package/locale/en.json +71 -0
- package/locale/zh.json +71 -0
- package/package.json +59 -4
package/client.js
ADDED
|
@@ -0,0 +1,981 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: '@local/dsh-novel-reader',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
const { useState, useEffect, useMemo, useRef } = React;
|
|
7
|
+
|
|
8
|
+
const NS = '@local/dsh-novel-reader';
|
|
9
|
+
const STORE_KEY = NS + ':state';
|
|
10
|
+
const TEXT_KEY = NS + ':text'; // 全文单独存:大文件下翻页只写轻量元数据,避免每页重复序列化整本小说
|
|
11
|
+
const PROFILES_KEY = NS + ':profiles'; // 多套样式配置:{ 名称: style对象 }
|
|
12
|
+
|
|
13
|
+
// 给任意颜色套上透明度:alpha>=1 原样返回;支持 #rgb/#rrggbb 与 rgb()/rgba()
|
|
14
|
+
function withOpacity(color, alpha) {
|
|
15
|
+
if (alpha == null || alpha >= 1) return color;
|
|
16
|
+
const a = Math.max(0, Math.min(1, alpha));
|
|
17
|
+
if (typeof color !== 'string') return color;
|
|
18
|
+
const hex = color.match(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/);
|
|
19
|
+
if (hex) {
|
|
20
|
+
let h = hex[1];
|
|
21
|
+
if (h.length === 3) h = h.split('').map(c => c + c).join('');
|
|
22
|
+
const r = parseInt(h.slice(0, 2), 16), g = parseInt(h.slice(2, 4), 16), b = parseInt(h.slice(4, 6), 16);
|
|
23
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
24
|
+
}
|
|
25
|
+
const m = color.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i);
|
|
26
|
+
if (m) return `rgba(${m[1]}, ${m[2]}, ${m[3]}, ${a})`;
|
|
27
|
+
return color;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 空值 = 跟随输入框真实样式。字体/尺寸/配色全部从输入框计算样式读取,做到完美隐蔽。
|
|
31
|
+
const DEFAULT_STYLE = {
|
|
32
|
+
fontSize: 0, lineHeight: 0, fontFamily: '',
|
|
33
|
+
textColor: '', bgColor: '', bgOpacity: 1, width: 0, height: 0, customRegex: '',
|
|
34
|
+
// 设置面板独立样式(与阅读区一一对应,互不干扰)。空值 = 跟随输入框真实样式。
|
|
35
|
+
panelFontSize: 0, panelLineHeight: 0, panelFontFamily: '',
|
|
36
|
+
panelTextColor: '', panelBgColor: '', panelWidth: 0, panelHeight: 0,
|
|
37
|
+
panelRadiusValue: '', // 设置面板圆角;空字符串 = 跟随输入框
|
|
38
|
+
panelBorderVisible: true, // 设置面板边框开关
|
|
39
|
+
radiusValue: '', // 阅读区圆角像素值;空字符串 = 跟随输入框真实圆角
|
|
40
|
+
borderVisible: true, // 阅读区是否显示窗口边框
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const DICT = {
|
|
44
|
+
en: {
|
|
45
|
+
name: 'Novel', import: 'Import txt', importing: 'Importing...', settings: 'Settings', close: 'Close',
|
|
46
|
+
prevChapter: 'Prev ch.', nextChapter: 'Next ch.', prevPage: '‹', nextPage: '›',
|
|
47
|
+
chapterPlaceholder: 'Select a chapter',
|
|
48
|
+
noBook: 'No book imported', importHint: 'Click Import txt or drop a .txt file here (UTF-8 / GBK)',
|
|
49
|
+
settingsTitle: 'Reading settings', followInput: 'Follow input style',
|
|
50
|
+
followInputHint: 'Match the input box size, colors and font',
|
|
51
|
+
panelStyleGroup: 'Appearance', readerStyleGroup: 'Reading area',
|
|
52
|
+
panelGroup: 'Settings panel style', readerGroup: 'Reading area style',
|
|
53
|
+
readerTextGroup: 'Text & layout', readerSizeGroup: 'Window size', chapterGroup: 'Chapter detection', actionGroup: 'Actions',
|
|
54
|
+
panelTextGroup: 'Panel text & font', panelSizeGroup: 'Panel size',
|
|
55
|
+
readerFollowLabel: 'Reading area follows input', panelFollowLabel: 'Panel follows input',
|
|
56
|
+
panelFontSize: 'Font size', panelLineHeight: 'Line height', panelFontFamily: 'Font',
|
|
57
|
+
panelTextColor: 'Panel text', panelBgColor: 'Panel background',
|
|
58
|
+
fontSize: 'Font size', lineHeight: 'Line height', fontFamily: 'Font',
|
|
59
|
+
textColor: 'Text color', backgroundColor: 'Background', bgOpacity: 'Background opacity', windowWidth: 'Panel width',
|
|
60
|
+
windowHeight: 'Panel height', customChapterRegex: 'Chapter regex',
|
|
61
|
+
borderStyleGroup: 'Border', borderRadius: 'Corner radius', borderVisible: 'Show border',
|
|
62
|
+
readerBorderGroup: 'Reading area border', panelBorderGroup: 'Settings panel border',
|
|
63
|
+
pin: 'Pin open', unpin: 'Unpin',
|
|
64
|
+
profileGroup: 'Saved profiles', profileName: 'Profile name', profileSave: 'Save current',
|
|
65
|
+
profileSelect: 'Apply', profileDelete: 'Delete', profileNone: 'No saved profiles yet',
|
|
66
|
+
profileSaved: 'Saved: {name}', profileDeleted: 'Deleted: {name}', profileApplied: 'Applied: {name}',
|
|
67
|
+
profileEmptyName: 'Enter a profile name first', profileConfirmDelete: 'Delete profile "{name}"?',
|
|
68
|
+
regexHint: 'One regex per line; empty uses built-in rules', reset: 'Reset', resetPos: 'Reset position', done: 'Done',
|
|
69
|
+
chapterCount: 'ch', page: 'p', noChapters: 'No chapter detected; reading the whole file as one',
|
|
70
|
+
decodeError: 'Cannot decode this file (tried UTF-8 and GBK)', importFailed: 'Import failed',
|
|
71
|
+
byteUnavailable: 'Browser cannot read raw bytes and UTF-8 decoding failed. Re-save the file as UTF-8.',
|
|
72
|
+
styleTip: 'Click 📖 to open · Mouse out closes · Click again to reopen · Drag the bar to move · Drop a .txt to import',
|
|
73
|
+
resizeHint: 'Drag the window edge to resize; changes are saved automatically',
|
|
74
|
+
reopenHint: 'Book data was cleared by the browser; please re-import the same file to resume.',
|
|
75
|
+
imported: 'Imported: {name} · {chapters} chapters',
|
|
76
|
+
},
|
|
77
|
+
zh: {
|
|
78
|
+
name: '小说', import: '导入 txt', importing: '导入中…', settings: '设置', close: '收起',
|
|
79
|
+
prevChapter: '上一章', nextChapter: '下一章', prevPage: '‹', nextPage: '›',
|
|
80
|
+
chapterPlaceholder: '选择章节',
|
|
81
|
+
noBook: '尚未导入小说', importHint: '点击「导入 txt」或把 .txt 文件拖到这里(支持 UTF-8 / GBK)',
|
|
82
|
+
settingsTitle: '阅读设置', followInput: '跟随输入框样式',
|
|
83
|
+
followInputHint: '自动匹配输入框的尺寸、配色和字体',
|
|
84
|
+
panelStyleGroup: '外观', readerStyleGroup: '阅读区域',
|
|
85
|
+
panelGroup: '设置面板样式', readerGroup: '阅读区样式',
|
|
86
|
+
readerTextGroup: '阅读区文字与排版', readerSizeGroup: '阅读区尺寸', chapterGroup: '章节识别', actionGroup: '操作',
|
|
87
|
+
panelTextGroup: '面板文字与字体', panelSizeGroup: '面板尺寸',
|
|
88
|
+
readerFollowLabel: '阅读区跟随输入框', panelFollowLabel: '面板跟随输入框',
|
|
89
|
+
panelFontSize: '字号', panelLineHeight: '行距', panelFontFamily: '字体',
|
|
90
|
+
panelTextColor: '面板文字颜色', panelBgColor: '面板背景颜色',
|
|
91
|
+
fontSize: '字号', lineHeight: '行距', fontFamily: '字体',
|
|
92
|
+
textColor: '文字颜色', backgroundColor: '背景颜色', bgOpacity: '背景透明度', windowWidth: '面板宽度',
|
|
93
|
+
windowHeight: '面板高度', customChapterRegex: '章节识别正则',
|
|
94
|
+
borderStyleGroup: '窗口边框', borderRadius: '圆角大小', borderVisible: '显示边框',
|
|
95
|
+
readerBorderGroup: '阅读区边框', panelBorderGroup: '设置面板边框',
|
|
96
|
+
pin: '钉住常开', unpin: '取消钉住',
|
|
97
|
+
profileGroup: '已保存配置', profileName: '配置名称', profileSave: '保存当前配置',
|
|
98
|
+
profileSelect: '应用', profileDelete: '删除', profileNone: '暂无保存的配置',
|
|
99
|
+
profileSaved: '已保存:{name}', profileDeleted: '已删除:{name}', profileApplied: '已应用:{name}',
|
|
100
|
+
profileEmptyName: '请先输入配置名称', profileConfirmDelete: '确定删除配置「{name}」?',
|
|
101
|
+
regexHint: '每行一条正则;留空用内置规则', reset: '恢复默认', resetPos: '重置位置', done: '完成',
|
|
102
|
+
chapterCount: '章', page: '页', noChapters: '未识别到章节,整本作为一章阅读',
|
|
103
|
+
decodeError: '无法解码该文件(已尝试 UTF-8 与 GBK)', importFailed: '导入失败',
|
|
104
|
+
byteUnavailable: '浏览器无法读取原始字节且 UTF-8 解码失败,请将文件另存为 UTF-8。',
|
|
105
|
+
styleTip: '点击 📖 打开 · 鼠标移出收起 · 再点图标重开 · 拖动底部条移动 · 拖入 .txt 导入',
|
|
106
|
+
resizeHint: '拖动窗口边缘可调整大小,改动会自动保存',
|
|
107
|
+
reopenHint: '书籍正文已被浏览器清理,请重新导入同一文件继续阅读。',
|
|
108
|
+
imported: '已导入:{name} · 共 {chapters} 章',
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// ---- 章节识别 ----
|
|
113
|
+
const BUILTIN_PATTERNS = [
|
|
114
|
+
/^\s*第[零一二三四五六七八九十百千两0-9]+[章节回卷部篇集][^\n]{0,40}$/gm,
|
|
115
|
+
/^\s*(Chapter|CHAPTER|chapter)\s+[0-9零一二三四五六七八九十]+[^\n]{0,40}$/gm,
|
|
116
|
+
];
|
|
117
|
+
function detectChapters(text, custom) {
|
|
118
|
+
const patterns = BUILTIN_PATTERNS.slice();
|
|
119
|
+
if (custom) for (const line of custom.split('\n')) {
|
|
120
|
+
const s = line.trim(); if (!s) continue;
|
|
121
|
+
try { patterns.push(new RegExp(s, 'gm')); } catch (e) { /* 非法正则忽略 */ }
|
|
122
|
+
}
|
|
123
|
+
const points = [];
|
|
124
|
+
for (const re of patterns) {
|
|
125
|
+
re.lastIndex = 0; let m;
|
|
126
|
+
while ((m = re.exec(text)) !== null) {
|
|
127
|
+
points.push({ start: m.index, title: m[0].trim().slice(0, 40) || '开篇' });
|
|
128
|
+
if (m[0].length === 0) re.lastIndex++;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
points.sort((a, b) => a.start - b.start);
|
|
132
|
+
const uniq = [];
|
|
133
|
+
for (const p of points) if (!uniq.length || p.start - uniq[uniq.length - 1].start > 8) uniq.push(p);
|
|
134
|
+
if (!uniq.length) return [{ title: '开篇', start: 0, end: text.length }];
|
|
135
|
+
const chapters = [];
|
|
136
|
+
if (uniq[0].start > Math.min(2000, text.length * 0.05)) {
|
|
137
|
+
chapters.push({ title: '开篇', start: 0, end: uniq[0].start });
|
|
138
|
+
}
|
|
139
|
+
for (let i = 0; i < uniq.length; i++) {
|
|
140
|
+
chapters.push({ title: uniq[i].title, start: uniq[i].start, end: i + 1 < uniq.length ? uniq[i + 1].start : text.length });
|
|
141
|
+
}
|
|
142
|
+
return chapters.length ? chapters : [{ title: '开篇', start: 0, end: text.length }];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ---- 排版优化:不沿用 txt 原排版,自动识别段落、合并硬换行、便于阅读 ----
|
|
146
|
+
function normalizeText(raw) {
|
|
147
|
+
const lines = raw.replace(/\r\n?/g, '\n').split('\n');
|
|
148
|
+
// 探测原文件排版风格:是否用「首行缩进两格」标记段落
|
|
149
|
+
const hasIndent = lines.some(l => /^[\u3000 ]{2,}/.test(l));
|
|
150
|
+
const out = [];
|
|
151
|
+
const isHeading = (s) => /^(第[零一二三四五六七八九十百千两0-9]+[章节回卷部篇集]|Chapter\s+\d|序章|楔子|番外|尾声|后记|PROLOGUE|EPILOGUE)/i.test(s);
|
|
152
|
+
for (let line of lines) {
|
|
153
|
+
const indented = /^[\u3000 ]{2,}/.test(line);
|
|
154
|
+
const content = line.replace(/^[\s\u3000]+|[\s\u3000]+$/g, '');
|
|
155
|
+
if (!content) {
|
|
156
|
+
if (out.length && out[out.length - 1] !== '') out.push(''); // 连续空行压成一个
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
// 有缩进标记时:带缩进/标题/空行后首行 = 新段,无缩进行 = 硬换行并入当前段
|
|
160
|
+
// 无缩进标记时:每行本就是作者分段,逐行独立,绝不合并成一整块
|
|
161
|
+
const newPara = isHeading(content) || (hasIndent ? indented : true) || !out.length || out[out.length - 1] === '';
|
|
162
|
+
if (newPara) out.push(content);
|
|
163
|
+
else out[out.length - 1] += content;
|
|
164
|
+
}
|
|
165
|
+
// 统一用空行分隔段落,阅读时段间距清晰
|
|
166
|
+
return out.filter((l, i) => l !== '' || (i > 0 && out[i - 1] !== '')).join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ---- 分页:按窗口高度自适应,以「物理行」为单位切分 ----
|
|
170
|
+
// 不再按字符数估算(中英文混排会估偏,导致一页文字超出高度被裁掉看不到)。
|
|
171
|
+
// 每页最多放 lpp 个物理行,正好适配阅读区高度,放不下的整行移到下一页。
|
|
172
|
+
function layoutPages(text, eff) {
|
|
173
|
+
const fs = eff.fontSize || 14;
|
|
174
|
+
// 每行可容纳的字符数:中文按 1 个全角宽,英文/数字/半角标点按 0.55 宽估算
|
|
175
|
+
const cpl = Math.max(8, Math.floor((eff.width - 28) / fs));
|
|
176
|
+
// 每页行数:由阅读区高度决定(减去工具栏与内边距占用的高度)
|
|
177
|
+
const lpp = Math.max(2, Math.floor((eff.height - 40) / (fs * (eff.lineHeight || 1.6))));
|
|
178
|
+
const physical = [];
|
|
179
|
+
for (const line of String(text).split('\n')) {
|
|
180
|
+
if (line === '') { physical.push(''); continue; } // 空行(段落间距)单独占一行
|
|
181
|
+
let cur = '', w = 0;
|
|
182
|
+
for (const ch of line) {
|
|
183
|
+
const cw = /[\x00-\xff]/.test(ch) ? 0.55 : 1;
|
|
184
|
+
if (w + cw > cpl && cur) { physical.push(cur); cur = ''; w = 0; }
|
|
185
|
+
cur += ch; w += cw;
|
|
186
|
+
}
|
|
187
|
+
physical.push(cur);
|
|
188
|
+
}
|
|
189
|
+
const pages = [];
|
|
190
|
+
for (let i = 0; i < physical.length; i += lpp) {
|
|
191
|
+
pages.push(physical.slice(i, i + lpp).join('\n'));
|
|
192
|
+
}
|
|
193
|
+
return pages.length ? pages : [''];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ---- 共享 store ----
|
|
197
|
+
function createStore(initial) {
|
|
198
|
+
let state = initial; const ls = new Set();
|
|
199
|
+
return {
|
|
200
|
+
get: () => state,
|
|
201
|
+
set(patch) {
|
|
202
|
+
state = { ...state, ...(typeof patch === 'function' ? patch(state) : patch) };
|
|
203
|
+
for (const l of Array.from(ls)) l();
|
|
204
|
+
},
|
|
205
|
+
subscribe(l) { ls.add(l); return () => ls.delete(l); },
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function useStore(store) {
|
|
209
|
+
const [s, setS] = useState(store.get());
|
|
210
|
+
useEffect(() => store.subscribe(() => setS(store.get())), [store]);
|
|
211
|
+
return s;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
inject: ['slots', 'locale'],
|
|
216
|
+
apply(ctx) {
|
|
217
|
+
let tr = (k) => (DICT.zh[k] || DICT.en[k] || k);
|
|
218
|
+
// 按 DSH 现有插件写法:register(ns, { zh, en }),再 bind(ns) 取翻译函数
|
|
219
|
+
try {
|
|
220
|
+
ctx.locale.register(NS, { zh: DICT.zh, en: DICT.en });
|
|
221
|
+
const bound = ctx.locale.bind(NS);
|
|
222
|
+
tr = (k) => {
|
|
223
|
+
try { const v = bound(k); if (typeof v === 'string' && v) return v; } catch (e) { /* 回退本地字典 */ }
|
|
224
|
+
return DICT.zh[k] || DICT.en[k] || k;
|
|
225
|
+
};
|
|
226
|
+
} catch (e) { /* 本地字典回退 */ }
|
|
227
|
+
const t = (k, vars) => {
|
|
228
|
+
let v = tr(k);
|
|
229
|
+
if (vars) for (const key of Object.keys(vars)) v = String(v).replace('{' + key + '}', vars[key]);
|
|
230
|
+
return v;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// 多套样式配置:从独立 key 读取,损坏时回退空集
|
|
234
|
+
function loadProfiles() {
|
|
235
|
+
try {
|
|
236
|
+
const raw = localStorage.getItem(PROFILES_KEY);
|
|
237
|
+
const d = raw ? JSON.parse(raw) : null;
|
|
238
|
+
return d && typeof d === 'object' && !Array.isArray(d) ? d : {};
|
|
239
|
+
} catch (e) { return {}; }
|
|
240
|
+
}
|
|
241
|
+
function saveProfiles(p) {
|
|
242
|
+
try { localStorage.setItem(PROFILES_KEY, JSON.stringify(p)); } catch (e) { /* 存储不可用 */ }
|
|
243
|
+
store.set({ profiles: p });
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const store = createStore({
|
|
247
|
+
open: false, pinned: false, book: null, chapterIndex: 0, pageIndex: 0,
|
|
248
|
+
style: { ...DEFAULT_STYLE }, pos: null, settingsOpen: false, notice: '',
|
|
249
|
+
profiles: loadProfiles(), profileName: '', // 多套样式配置
|
|
250
|
+
});
|
|
251
|
+
// 点击图标打开;未钉住时鼠标移出阅读区即收起,需重新点击图标才能再次打开。
|
|
252
|
+
// 钉住后只能点工具栏「收起」关闭,移出不会收起。
|
|
253
|
+
// 用短延迟避免鼠标在图标与阅读区之间移动时闪烁;进入阅读区即取消收起。
|
|
254
|
+
let hideTimer = null;
|
|
255
|
+
let dragActive = false; // 正在拖动面板时暂停自动收起
|
|
256
|
+
function cancelHide() { if (hideTimer) { clearTimeout(hideTimer); hideTimer = null; } }
|
|
257
|
+
function scheduleHide() {
|
|
258
|
+
cancelHide();
|
|
259
|
+
hideTimer = setTimeout(() => {
|
|
260
|
+
hideTimer = null;
|
|
261
|
+
const st = store.get();
|
|
262
|
+
// 钉住、设置面板打开、或正在拖动时不自动收起
|
|
263
|
+
if (st.open && !st.pinned && !st.settingsOpen && !dragActive) store.set({ open: false, notice: '' });
|
|
264
|
+
}, 200);
|
|
265
|
+
}
|
|
266
|
+
let fullText = '';
|
|
267
|
+
let canStoreText = true; // 大文件超过配额后关闭全文持久化,仍保留进度
|
|
268
|
+
let savedProgress = null; // { name, chapterIndex, pageIndex }
|
|
269
|
+
let anchorEl = null; // 触发图标的 DOM 节点,用于向上定位真实输入框
|
|
270
|
+
|
|
271
|
+
// 从图标向上找到真实编辑器,再读取它的矩形与计算样式(配色/字体/圆角)
|
|
272
|
+
function findEditorInfo() {
|
|
273
|
+
if (!anchorEl || typeof document === 'undefined') return null;
|
|
274
|
+
// 常见编辑器形态:原生 textarea / contenteditable / ProseMirror / CodeMirror / role=textbox
|
|
275
|
+
const EDIT_SEL = 'textarea, [contenteditable="true"], [contenteditable]:not([contenteditable="false"]), [role="textbox"], .ProseMirror, .cm-content';
|
|
276
|
+
const isEditor = (n) => n && (
|
|
277
|
+
n.tagName === 'TEXTAREA' ||
|
|
278
|
+
(n.getAttribute && n.getAttribute('contenteditable') === 'true') ||
|
|
279
|
+
(n.getAttribute && n.getAttribute('role') === 'textbox') ||
|
|
280
|
+
(n.matches && n.matches(EDIT_SEL))
|
|
281
|
+
);
|
|
282
|
+
let editor = null;
|
|
283
|
+
let node = anchorEl;
|
|
284
|
+
while (node && node !== document.body) {
|
|
285
|
+
if (isEditor(node)) { editor = node; break; }
|
|
286
|
+
if (node.querySelector) { const inner = node.querySelector(EDIT_SEL); if (inner) { editor = inner; break; } }
|
|
287
|
+
node = node.parentElement;
|
|
288
|
+
}
|
|
289
|
+
// 兜底:从图标向上没找到时,全局查找第一个可见编辑器
|
|
290
|
+
if ((!editor || !editor.getBoundingClientRect) && document.querySelectorAll) {
|
|
291
|
+
const cands = document.querySelectorAll(EDIT_SEL);
|
|
292
|
+
for (const c of cands) {
|
|
293
|
+
if (c.getBoundingClientRect && c.getBoundingClientRect().width) { editor = c; break; }
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (!editor || !editor.getBoundingClientRect) return null;
|
|
297
|
+
const cs = window.getComputedStyle ? window.getComputedStyle(editor) : null;
|
|
298
|
+
// 背景向上找第一个非透明色,保证取到输入框卡片的底色
|
|
299
|
+
let bg = ''; let bgNode = editor;
|
|
300
|
+
while (bgNode && bgNode !== document.body) {
|
|
301
|
+
const c = window.getComputedStyle ? window.getComputedStyle(bgNode) : null;
|
|
302
|
+
const v = c && c.backgroundColor;
|
|
303
|
+
if (v && v !== 'rgba(0, 0, 0, 0)' && v !== 'transparent' && v !== 'rgba(0,0,0,0)') { bg = v; break; }
|
|
304
|
+
bgNode = bgNode.parentElement;
|
|
305
|
+
}
|
|
306
|
+
// 圆角/边框/阴影:输入框卡片往往把这些画在外层容器上,向上找第一个「有效值」
|
|
307
|
+
// (textarea 自身常是 0px 圆角、无边框,直接取它会导致圆角/边框丢失)
|
|
308
|
+
let radius = '', border = '', shadow = '';
|
|
309
|
+
let bnode = editor;
|
|
310
|
+
while (bnode && bnode !== document.body) {
|
|
311
|
+
const c = window.getComputedStyle ? window.getComputedStyle(bnode) : null;
|
|
312
|
+
if (c) {
|
|
313
|
+
const br = c.borderRadius || '';
|
|
314
|
+
if (!radius && br && parseFloat(br) > 0) radius = br;
|
|
315
|
+
const bw = parseFloat(c.borderTopWidth) || 0;
|
|
316
|
+
const bs = c.borderTopStyle;
|
|
317
|
+
if (!border && bw > 0 && bs && bs !== 'none') {
|
|
318
|
+
border = c.borderTopWidth + ' ' + bs + ' ' + c.borderTopColor;
|
|
319
|
+
}
|
|
320
|
+
if (!shadow && c.boxShadow && c.boxShadow !== 'none') shadow = c.boxShadow;
|
|
321
|
+
}
|
|
322
|
+
if (radius && border && shadow) break;
|
|
323
|
+
bnode = bnode.parentElement;
|
|
324
|
+
}
|
|
325
|
+
// 定位基准:用提供背景的「视觉卡片」矩形,而非内部 textarea 的矩形。
|
|
326
|
+
// 用户看到的“输入框”是这张卡片;textarea 通常有内边距、与卡片存在偏移,
|
|
327
|
+
// 用卡片矩形才能让 XY / 宽高与输入框完全对齐,消除像素偏移。
|
|
328
|
+
const boxEl = (bgNode && bgNode !== document.body && bgNode.getBoundingClientRect) ? bgNode : editor;
|
|
329
|
+
const r = boxEl.getBoundingClientRect();
|
|
330
|
+
if (!r || !r.width) return null;
|
|
331
|
+
return {
|
|
332
|
+
x: r.left, y: r.top, width: r.width, height: r.height,
|
|
333
|
+
bg, color: (cs && cs.color) || '', fontFamily: (cs && cs.fontFamily) || '',
|
|
334
|
+
fontSize: cs ? (parseFloat(cs.fontSize) || 0) : 0,
|
|
335
|
+
lineHeight: cs && cs.lineHeight && cs.lineHeight !== 'normal' ? (parseFloat(cs.lineHeight) || 0) : 0,
|
|
336
|
+
radius: radius || '8px', border, shadow,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// 翻页只写轻量状态;全文单独、按需写入
|
|
341
|
+
function persist() {
|
|
342
|
+
const s = store.get();
|
|
343
|
+
const base = {
|
|
344
|
+
style: s.style, pos: s.pos, pinned: s.pinned,
|
|
345
|
+
book: s.book ? { name: s.book.name, chapters: s.book.chapters, length: s.book.length } : null,
|
|
346
|
+
chapterIndex: s.chapterIndex, pageIndex: s.pageIndex,
|
|
347
|
+
};
|
|
348
|
+
try { localStorage.setItem(STORE_KEY, JSON.stringify(base)); } catch (e) { /* 存储不可用 */ }
|
|
349
|
+
}
|
|
350
|
+
function persistText() {
|
|
351
|
+
if (!canStoreText) return;
|
|
352
|
+
try { localStorage.setItem(TEXT_KEY, fullText); }
|
|
353
|
+
catch (e) { canStoreText = false; try { localStorage.removeItem(TEXT_KEY); } catch (e2) {} }
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
const raw = localStorage.getItem(STORE_KEY);
|
|
357
|
+
if (raw) {
|
|
358
|
+
const d = JSON.parse(raw);
|
|
359
|
+
const stored = localStorage.getItem(TEXT_KEY) || (typeof d.text === 'string' ? d.text : '');
|
|
360
|
+
fullText = stored ? normalizeText(stored) : ''; // 旧数据也套用统一排版
|
|
361
|
+
savedProgress = d.book ? { name: d.book.name, chapterIndex: d.chapterIndex || 0, pageIndex: d.pageIndex || 0 } : null;
|
|
362
|
+
store.set({
|
|
363
|
+
book: d.book || null,
|
|
364
|
+
style: { ...DEFAULT_STYLE, ...(d.style || {}) },
|
|
365
|
+
pos: null, // 不使用旧位置,每次打开都重新贴合输入框,避免框跑偏超出范围
|
|
366
|
+
pinned: !!d.pinned,
|
|
367
|
+
chapterIndex: d.chapterIndex || 0, pageIndex: d.pageIndex || 0,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
} catch (e) { /* 忽略损坏的本地数据 */ }
|
|
371
|
+
|
|
372
|
+
// 读取文件:显式按钮 / 拖放共用
|
|
373
|
+
async function readFile(file) {
|
|
374
|
+
if (!file) return;
|
|
375
|
+
store.set({ notice: tr('importing') });
|
|
376
|
+
try {
|
|
377
|
+
let text = '';
|
|
378
|
+
const buf = await file.arrayBuffer();
|
|
379
|
+
const bytes = new Uint8Array(buf);
|
|
380
|
+
if (bytes[0] === 0xEF && bytes[1] === 0xBB && bytes[2] === 0xBF) {
|
|
381
|
+
text = new TextDecoder('utf-8').decode(bytes.subarray(3));
|
|
382
|
+
} else {
|
|
383
|
+
try { text = new TextDecoder('utf-8', { fatal: true }).decode(bytes); }
|
|
384
|
+
catch (err) {
|
|
385
|
+
try { text = new TextDecoder('gbk').decode(bytes); }
|
|
386
|
+
catch (err2) { throw new Error(tr('decodeError')); }
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
fullText = normalizeText(text); // 统一排版:不沿用原 txt 的缩进与硬换行
|
|
390
|
+
const chapters = detectChapters(fullText, store.get().style.customRegex);
|
|
391
|
+
let ci = 0, pi = 0;
|
|
392
|
+
if (savedProgress && savedProgress.name === file.name) {
|
|
393
|
+
ci = Math.min(savedProgress.chapterIndex, chapters.length - 1); pi = savedProgress.pageIndex;
|
|
394
|
+
}
|
|
395
|
+
store.set({
|
|
396
|
+
book: { name: file.name, chapters, length: text.length },
|
|
397
|
+
chapterIndex: ci, pageIndex: pi,
|
|
398
|
+
notice: t('imported', { name: file.name, chapters: chapters.length }),
|
|
399
|
+
});
|
|
400
|
+
persistText();
|
|
401
|
+
persist();
|
|
402
|
+
} catch (err) {
|
|
403
|
+
store.set({ notice: (err && err.message) || tr('importFailed') });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// ---- 触发图标:只保留一个图标,无文字 ----
|
|
408
|
+
function Trigger() {
|
|
409
|
+
const s = useStore(store);
|
|
410
|
+
return h('button', {
|
|
411
|
+
type: 'button', title: tr('name'),
|
|
412
|
+
ref: (node) => { anchorEl = node; },
|
|
413
|
+
// 只有点击才打开/关闭阅读区;悬浮不触发打开
|
|
414
|
+
onClick: (e) => {
|
|
415
|
+
e.stopPropagation();
|
|
416
|
+
cancelHide();
|
|
417
|
+
const cur = store.get();
|
|
418
|
+
// 钉住状态下图标不能关闭阅读区,只能点工具栏「收起」关闭
|
|
419
|
+
if (cur.open && cur.pinned) return;
|
|
420
|
+
// 打开时清除旧位置:未钉住的阅读区每次都精确贴合输入框当前位置
|
|
421
|
+
store.set({ open: !cur.open, settingsOpen: false, notice: '', pos: cur.open ? cur.pos : null });
|
|
422
|
+
},
|
|
423
|
+
style: {
|
|
424
|
+
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
425
|
+
width: 26, height: 26, padding: 0,
|
|
426
|
+
border: '1px solid var(--dsw-alias-border-l2, #d6dde7)', borderRadius: 7,
|
|
427
|
+
background: s.open ? 'var(--dsw-alias-bg-layer-2, #e8eef7)' : 'transparent',
|
|
428
|
+
cursor: 'pointer', fontSize: 15, lineHeight: 1,
|
|
429
|
+
},
|
|
430
|
+
}, '📖');
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// ---- 伪输入框覆盖层 ----
|
|
434
|
+
function InlineReader() {
|
|
435
|
+
const s = useStore(store);
|
|
436
|
+
const fileRef = useRef(null);
|
|
437
|
+
const [info, setInfo] = useState(null); // 真实输入框的矩形与计算样式
|
|
438
|
+
const dragRef = useRef(null);
|
|
439
|
+
const [dragging, setDragging] = useState(false);
|
|
440
|
+
const resizeRef = useRef(null); // 边缘缩放:起始鼠标位置 / 起始宽高 / 方向
|
|
441
|
+
const [resizing, setResizing] = useState(false);
|
|
442
|
+
const [chapterMenuOpen, setChapterMenuOpen] = useState(false); // 章节下拉菜单开合
|
|
443
|
+
|
|
444
|
+
// 读取真实输入框的矩形与配色,作为覆盖层的默认样式
|
|
445
|
+
useEffect(() => {
|
|
446
|
+
if (!s.open) return;
|
|
447
|
+
const measure = () => setInfo(findEditorInfo());
|
|
448
|
+
measure();
|
|
449
|
+
const t1 = setTimeout(measure, 60); // 渲染时序兜底
|
|
450
|
+
const t2 = setTimeout(measure, 320);
|
|
451
|
+
window.addEventListener('resize', measure);
|
|
452
|
+
return () => { clearTimeout(t1); clearTimeout(t2); window.removeEventListener('resize', measure); };
|
|
453
|
+
}, [s.open]);
|
|
454
|
+
|
|
455
|
+
useEffect(() => {
|
|
456
|
+
if (!dragging) return;
|
|
457
|
+
function move(e) {
|
|
458
|
+
const d = dragRef.current; if (!d) return;
|
|
459
|
+
store.set({ pos: { x: Math.max(0, e.clientX - d.dx), y: Math.max(0, e.clientY - d.dy) } });
|
|
460
|
+
}
|
|
461
|
+
function up() { setDragging(false); dragActive = false; dragRef.current = null; persist(); }
|
|
462
|
+
document.addEventListener('mousemove', move);
|
|
463
|
+
document.addEventListener('mouseup', up);
|
|
464
|
+
return () => { document.removeEventListener('mousemove', move); document.removeEventListener('mouseup', up); };
|
|
465
|
+
}, [dragging]);
|
|
466
|
+
|
|
467
|
+
// 边缘拖拽缩放:移动鼠标实时改写宽高,正文按新尺寸自动重新分页
|
|
468
|
+
useEffect(() => {
|
|
469
|
+
if (!resizing) return;
|
|
470
|
+
function move(e) {
|
|
471
|
+
const r = resizeRef.current; if (!r) return;
|
|
472
|
+
const minW = 120, minH = 80;
|
|
473
|
+
let w = r.w, hh = r.h;
|
|
474
|
+
if (r.dir.indexOf('e') >= 0) w = Math.max(minW, r.w + (e.clientX - r.x));
|
|
475
|
+
if (r.dir.indexOf('s') >= 0) hh = Math.max(minH, r.h + (e.clientY - r.y));
|
|
476
|
+
store.set({ style: { ...store.get().style, width: w, height: hh } });
|
|
477
|
+
}
|
|
478
|
+
function up() {
|
|
479
|
+
resizeRef.current = null; setResizing(false); dragActive = false;
|
|
480
|
+
persist(); // 缩放结束自动保存样式,下次打开无需重设
|
|
481
|
+
}
|
|
482
|
+
document.addEventListener('mousemove', move);
|
|
483
|
+
document.addEventListener('mouseup', up);
|
|
484
|
+
return () => { document.removeEventListener('mousemove', move); document.removeEventListener('mouseup', up); };
|
|
485
|
+
}, [resizing]);
|
|
486
|
+
|
|
487
|
+
// 有效样式:用户显式设置优先,否则跟随输入框,再否则用安全兜底
|
|
488
|
+
const st = s.style;
|
|
489
|
+
const eff = {
|
|
490
|
+
// pos 为拖拽后的自定义位置;否则精确贴合输入框矩形(保留亚像素,取整数值会引入 1px 偏移)
|
|
491
|
+
x: s.pos ? s.pos.x : (info ? info.x : 24),
|
|
492
|
+
y: s.pos ? s.pos.y : (info ? info.y : Math.max(8, (typeof window !== 'undefined' ? window.innerHeight : 800) - 200)),
|
|
493
|
+
width: st.width || (info ? info.width : 640),
|
|
494
|
+
height: st.height || (info ? info.height : 160),
|
|
495
|
+
bg: st.bgColor || (info && info.bg) || 'rgba(127,127,127,0.08)',
|
|
496
|
+
color: st.textColor || (info && info.color) || 'inherit',
|
|
497
|
+
fontFamily: st.fontFamily || (info && info.fontFamily) || 'inherit',
|
|
498
|
+
fontSize: st.fontSize || (info && info.fontSize) || 14,
|
|
499
|
+
lineHeight: st.lineHeight || (info && info.lineHeight && info.lineHeight / info.fontSize < 4 ? info.lineHeight / info.fontSize : 1.6),
|
|
500
|
+
radius: info ? info.radius : '8px',
|
|
501
|
+
border: info ? info.border : '',
|
|
502
|
+
shadow: info ? info.shadow : '',
|
|
503
|
+
};
|
|
504
|
+
// 设置面板有效样式:与阅读区 eff 一一对应、完全独立。空值 = 跟随输入框。
|
|
505
|
+
// 必须在所有使用处之前定义,避免 TDZ。
|
|
506
|
+
const peff = {
|
|
507
|
+
width: st.panelWidth || 520,
|
|
508
|
+
height: st.panelHeight || Math.min(560, (typeof window !== 'undefined' ? window.innerHeight : 800) - 60),
|
|
509
|
+
bg: st.panelBgColor || (info && info.bg) || 'rgba(127,127,127,0.08)',
|
|
510
|
+
color: st.panelTextColor || (info && info.color) || 'inherit',
|
|
511
|
+
fontFamily: st.panelFontFamily || (info && info.fontFamily) || 'inherit',
|
|
512
|
+
fontSize: st.panelFontSize || 13,
|
|
513
|
+
lineHeight: st.panelLineHeight || 1.6,
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const chapter = s.book && s.book.chapters[s.chapterIndex] || null;
|
|
517
|
+
const pages = useMemo(
|
|
518
|
+
() => chapter ? layoutPages(fullText.slice(chapter.start, chapter.end), eff) : [],
|
|
519
|
+
[chapter && chapter.start, chapter && chapter.end, eff.width, eff.height, eff.fontSize, eff.lineHeight, fullText]
|
|
520
|
+
);
|
|
521
|
+
const pageCount = pages.length;
|
|
522
|
+
const pageIndex = Math.min(s.pageIndex, Math.max(0, pageCount - 1));
|
|
523
|
+
const pageText = pages[pageIndex] || '';
|
|
524
|
+
|
|
525
|
+
function goPage(delta) {
|
|
526
|
+
const next = pageIndex + delta;
|
|
527
|
+
if (next < 0) { goChapter(-1); return; }
|
|
528
|
+
if (next >= pageCount) { goChapter(1); return; }
|
|
529
|
+
store.set({ pageIndex: next }); persist();
|
|
530
|
+
}
|
|
531
|
+
function goChapter(delta) {
|
|
532
|
+
if (!s.book) return;
|
|
533
|
+
const next = s.chapterIndex + delta;
|
|
534
|
+
if (next < 0 || next >= s.book.chapters.length) return;
|
|
535
|
+
store.set({ chapterIndex: next, pageIndex: 0 }); persist();
|
|
536
|
+
}
|
|
537
|
+
// 开始边缘缩放:记录初始宽高与鼠标位置、当前面板左上角
|
|
538
|
+
function startResize(e, dir) {
|
|
539
|
+
e.preventDefault(); e.stopPropagation();
|
|
540
|
+
resizeRef.current = {
|
|
541
|
+
x: e.clientX, y: e.clientY, w: eff.width, h: eff.height, dir: dir,
|
|
542
|
+
};
|
|
543
|
+
dragActive = true; cancelHide(); setResizing(true);
|
|
544
|
+
}
|
|
545
|
+
function onFile(e) { readFile(e.target.files && e.target.files[0]); e.target.value = ''; }
|
|
546
|
+
function onDrop(e) {
|
|
547
|
+
e.preventDefault();
|
|
548
|
+
const file = e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files[0];
|
|
549
|
+
if (file && /\.txt$/i.test(file.name)) readFile(file);
|
|
550
|
+
else store.set({ notice: tr('importHint') });
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (!s.open) return null;
|
|
554
|
+
const isSettings = !!s.settingsOpen;
|
|
555
|
+
// 设置面板配色直接取自 peff(与阅读区 eff 完全独立),改一边不影响另一边。
|
|
556
|
+
const panelBg = peff.bg;
|
|
557
|
+
const panelColor = peff.color;
|
|
558
|
+
// 阅读区渲染背景:在基础背景色上叠加透明度(跟随开关/取色器仍用 eff.bg 原值,不受影响)
|
|
559
|
+
const readerBg = withOpacity(eff.bg, st.bgOpacity);
|
|
560
|
+
// 设置模式用 peff 尺寸(可自定义),超出滚动;阅读模式用 eff 精确贴合输入框尺寸
|
|
561
|
+
const panelW = isSettings ? peff.width : eff.width;
|
|
562
|
+
const panelH = isSettings ? peff.height : eff.height;
|
|
563
|
+
const panelTop = isSettings && typeof window !== 'undefined'
|
|
564
|
+
? Math.max(8, Math.min(eff.y, window.innerHeight - panelH - 20)) : eff.y;
|
|
565
|
+
// 边框样式:设置面板与阅读区各自独立(圆角/显示开关分开存),默认都跟随输入框。
|
|
566
|
+
// 边框颜色源随模式取对应背景所属元素,避免串色。必须在 wrapStyle 之前定义,避免 TDZ。
|
|
567
|
+
function borderOf(radiusRaw, visible, baseBorder) {
|
|
568
|
+
const radius = radiusRaw !== '' && radiusRaw != null ? radiusRaw + 'px' : (baseBorder && baseBorder.radius) || eff.radius;
|
|
569
|
+
const border = visible !== false ? ((baseBorder && baseBorder.border) || eff.border || '1px solid rgba(120,140,170,0.55)') : 'none';
|
|
570
|
+
return { radius, border };
|
|
571
|
+
}
|
|
572
|
+
const readerBorder = borderOf(st.radiusValue, st.borderVisible, { radius: eff.radius, border: eff.border });
|
|
573
|
+
const panelBorder = borderOf(st.panelRadiusValue, st.panelBorderVisible, { radius: eff.radius, border: eff.border });
|
|
574
|
+
const borderOn = isSettings ? (st.panelBorderVisible !== false) : (st.borderVisible !== false);
|
|
575
|
+
const finalRadius = isSettings ? panelBorder.radius : readerBorder.radius;
|
|
576
|
+
const finalBorder = isSettings ? panelBorder.border : readerBorder.border;
|
|
577
|
+
// 当前模式的字体/字号/行距:设置面板用 peff,阅读区用 eff
|
|
578
|
+
const curFont = isSettings ? peff.fontFamily : eff.fontFamily;
|
|
579
|
+
const curFontSize = isSettings ? peff.fontSize : eff.fontSize;
|
|
580
|
+
const wrapStyle = {
|
|
581
|
+
position: 'fixed', left: eff.x, top: panelTop, width: panelW, height: panelH,
|
|
582
|
+
// border-box:让宽高包含边框与内边距,精确覆盖输入框而不多出像素
|
|
583
|
+
boxSizing: 'border-box',
|
|
584
|
+
zIndex: 100000, display: 'flex', flexDirection: 'column', overflow: 'hidden',
|
|
585
|
+
background: isSettings ? panelBg : readerBg,
|
|
586
|
+
color: isSettings ? panelColor : eff.color,
|
|
587
|
+
fontFamily: curFont, fontSize: curFontSize,
|
|
588
|
+
border: finalBorder, borderRadius: finalRadius,
|
|
589
|
+
boxShadow: eff.shadow || undefined,
|
|
590
|
+
};
|
|
591
|
+
const toolBtn = (label, fn, disabled) => h('button', {
|
|
592
|
+
type: 'button', onClick: fn, disabled: !!disabled,
|
|
593
|
+
style: {
|
|
594
|
+
border: 'none', background: 'transparent', color: 'inherit', fontSize: 12,
|
|
595
|
+
padding: '2px 6px', cursor: disabled ? 'default' : 'pointer', opacity: disabled ? 0.35 : 1,
|
|
596
|
+
},
|
|
597
|
+
}, label);
|
|
598
|
+
|
|
599
|
+
function onReadClick(e) {
|
|
600
|
+
if (s.settingsOpen) return;
|
|
601
|
+
const sel = window.getSelection && window.getSelection();
|
|
602
|
+
if (sel && String(sel).length > 0) return; // 选中文本时不翻页
|
|
603
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
604
|
+
const rel = (e.clientX - r.left) / r.width;
|
|
605
|
+
if (rel < 0.28) goPage(-1); else if (rel > 0.72) goPage(1);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// 两套「跟随输入框」状态:各自只看自己那组字段是否全空,互不干扰
|
|
609
|
+
const readerFollow = !st.fontSize && !st.lineHeight && !st.fontFamily && !st.bgColor && !st.textColor && !st.width && !st.height && !st.radiusValue && (st.bgOpacity == null || st.bgOpacity >= 1) && st.borderVisible !== false;
|
|
610
|
+
const panelFollow = !st.panelFontSize && !st.panelLineHeight && !st.panelFontFamily && !st.panelBgColor && !st.panelTextColor && !st.panelWidth && !st.panelHeight && !st.panelRadiusValue && st.panelBorderVisible !== false;
|
|
611
|
+
// 各自「跟随」开关切换时只改自己那组字段,绝不碰对方
|
|
612
|
+
const READER_CLEAR = { fontSize: 0, lineHeight: 0, fontFamily: '', textColor: '', bgColor: '', bgOpacity: 1, width: 0, height: 0, radiusValue: '', borderVisible: true };
|
|
613
|
+
const PANEL_CLEAR = { panelFontSize: 0, panelLineHeight: 0, panelFontFamily: '', panelTextColor: '', panelBgColor: '', panelWidth: 0, panelHeight: 0, panelRadiusValue: '', panelBorderVisible: true };
|
|
614
|
+
const READER_FILL = {
|
|
615
|
+
fontSize: eff.fontSize, lineHeight: eff.lineHeight, fontFamily: eff.fontFamily,
|
|
616
|
+
textColor: eff.color, bgColor: eff.bg, bgOpacity: 1, width: Math.round(eff.width), height: Math.round(eff.height),
|
|
617
|
+
radiusValue: Math.round(parseFloat(eff.radius) || 0), borderVisible: st.borderVisible !== false,
|
|
618
|
+
};
|
|
619
|
+
const PANEL_FILL = {
|
|
620
|
+
panelFontSize: peff.fontSize, panelLineHeight: peff.lineHeight, panelFontFamily: peff.fontFamily,
|
|
621
|
+
panelTextColor: peff.color, panelBgColor: peff.bg, panelWidth: Math.round(peff.width), panelHeight: Math.round(peff.height),
|
|
622
|
+
panelRadiusValue: Math.round(parseFloat(eff.radius) || 0), panelBorderVisible: st.panelBorderVisible !== false,
|
|
623
|
+
};
|
|
624
|
+
function updateStyle(patch) {
|
|
625
|
+
store.set({ style: { ...store.get().style, ...patch } }); persist();
|
|
626
|
+
}
|
|
627
|
+
// 数字输入框统一样式(宽/高用),必须在 return 之前定义避免 TDZ
|
|
628
|
+
const numberInputStyle = {
|
|
629
|
+
width: 76, border: '1px solid rgba(120,140,170,0.4)', borderRadius: 5,
|
|
630
|
+
background: 'transparent', color: 'inherit', fontSize: 12, padding: '2px 4px',
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
// 工具栏:置于窗口底部(用户要求),拖动它仍可移动整个面板
|
|
634
|
+
const toolbar = h('div', {
|
|
635
|
+
onMouseDown: (e) => {
|
|
636
|
+
if (e.target.closest('button,select,input,textarea')) return;
|
|
637
|
+
dragRef.current = { dx: e.clientX - eff.x, dy: e.clientY - panelTop };
|
|
638
|
+
dragActive = true; cancelHide(); setDragging(true);
|
|
639
|
+
},
|
|
640
|
+
style: {
|
|
641
|
+
position: 'relative', zIndex: 3,
|
|
642
|
+
display: 'flex', alignItems: 'center', gap: 4, padding: '2px 8px', flexWrap: 'wrap',
|
|
643
|
+
background: isSettings ? panelBg : readerBg,
|
|
644
|
+
borderTop: borderOn ? '1px solid rgba(120,140,170,0.25)' : 'none',
|
|
645
|
+
color: isSettings ? panelColor : eff.color,
|
|
646
|
+
cursor: dragging ? 'grabbing' : 'grab', flexShrink: 0, fontSize: 12,
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
toolBtn('⚙ ' + tr('settings'), () => store.set({ settingsOpen: !s.settingsOpen })),
|
|
650
|
+
toolBtn(s.pinned ? '📌 ' + tr('unpin') : '📍 ' + tr('pin'), () => {
|
|
651
|
+
cancelHide();
|
|
652
|
+
store.set({ pinned: !s.pinned }); persist();
|
|
653
|
+
}),
|
|
654
|
+
toolBtn(tr('prevChapter'), () => goChapter(-1), !s.book || s.chapterIndex <= 0),
|
|
655
|
+
// 章节下拉:固定高度的可滚动列表,章节再多也不会撑高窗口
|
|
656
|
+
h('div', { style: { position: 'relative' } },
|
|
657
|
+
h('button', {
|
|
658
|
+
type: 'button', disabled: !s.book,
|
|
659
|
+
onClick: () => setChapterMenuOpen(!chapterMenuOpen),
|
|
660
|
+
style: {
|
|
661
|
+
maxWidth: 150, border: '1px solid rgba(120,140,170,0.4)', borderRadius: 6,
|
|
662
|
+
background: 'transparent', color: 'inherit', fontSize: 12, padding: '2px 6px',
|
|
663
|
+
cursor: s.book ? 'pointer' : 'default', opacity: s.book ? 1 : 0.4,
|
|
664
|
+
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
665
|
+
},
|
|
666
|
+
}, s.book && s.book.chapters[s.chapterIndex] ? s.book.chapters[s.chapterIndex].title : tr('chapterPlaceholder'), ' ▾'),
|
|
667
|
+
chapterMenuOpen && s.book ? h('div', {
|
|
668
|
+
style: {
|
|
669
|
+
position: 'absolute', left: 0, bottom: '100%', zIndex: 5,
|
|
670
|
+
maxHeight: 220, overflowY: 'auto', minWidth: 160,
|
|
671
|
+
border: '1px solid rgba(120,140,170,0.45)', borderRadius: 6,
|
|
672
|
+
background: isSettings ? panelBg : readerBg, color: isSettings ? panelColor : eff.color,
|
|
673
|
+
boxShadow: '0 2px 10px rgba(0,0,0,0.25)',
|
|
674
|
+
},
|
|
675
|
+
}, s.book.chapters.map((c, i) => h('button', {
|
|
676
|
+
key: i, type: 'button',
|
|
677
|
+
onClick: () => { store.set({ chapterIndex: i, pageIndex: 0 }); persist(); setChapterMenuOpen(false); },
|
|
678
|
+
style: {
|
|
679
|
+
display: 'block', width: '100%', textAlign: 'left', border: 'none',
|
|
680
|
+
background: i === s.chapterIndex ? 'rgba(120,140,170,0.22)' : 'transparent',
|
|
681
|
+
color: 'inherit', fontSize: 12, padding: '4px 8px', cursor: 'pointer',
|
|
682
|
+
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
683
|
+
},
|
|
684
|
+
}, c.title))) : null
|
|
685
|
+
),
|
|
686
|
+
toolBtn(tr('nextChapter'), () => goChapter(1), !s.book || s.chapterIndex >= s.book.chapters.length - 1),
|
|
687
|
+
h('span', { style: { flex: 1, minWidth: 4 } }),
|
|
688
|
+
h('span', { style: { opacity: 0.75, whiteSpace: 'nowrap' } },
|
|
689
|
+
s.book ? `${s.chapterIndex + 1}/${s.book.chapters.length}${tr('chapterCount')} · ${pageIndex + 1}/${pageCount}${tr('page')}` : ''),
|
|
690
|
+
toolBtn(tr('import'), () => fileRef.current && fileRef.current.click()),
|
|
691
|
+
toolBtn('✕ ' + tr('close'), () => {
|
|
692
|
+
cancelHide();
|
|
693
|
+
store.set({ open: false, pinned: false, settingsOpen: false, notice: '' }); persist();
|
|
694
|
+
})
|
|
695
|
+
);
|
|
696
|
+
|
|
697
|
+
return h('div', {
|
|
698
|
+
style: wrapStyle,
|
|
699
|
+
onMouseEnter: () => cancelHide(), // 鼠标进入阅读区,取消收起
|
|
700
|
+
onMouseLeave: () => scheduleHide(), // 鼠标移出阅读区即收起,需重新点击图标打开
|
|
701
|
+
onDragOver: (e) => e.preventDefault(),
|
|
702
|
+
onDrop: onDrop,
|
|
703
|
+
},
|
|
704
|
+
// 正文区:左 28% 上一页,右 28% 下一页,中间可选中
|
|
705
|
+
!s.settingsOpen ? h('div', {
|
|
706
|
+
onClick: onReadClick,
|
|
707
|
+
style: {
|
|
708
|
+
position: 'relative', flex: 1, overflow: 'hidden', padding: '2px 14px',
|
|
709
|
+
fontSize: eff.fontSize, lineHeight: eff.lineHeight, cursor: 'pointer',
|
|
710
|
+
},
|
|
711
|
+
},
|
|
712
|
+
!s.book
|
|
713
|
+
? h('div', { style: { opacity: 0.7, fontSize: 13, lineHeight: 1.6 } }, tr('importHint'))
|
|
714
|
+
: (!fullText
|
|
715
|
+
? h('div', null,
|
|
716
|
+
h('div', { style: { opacity: 0.7, fontSize: 12, marginBottom: 4 } }, tr('reopenHint')),
|
|
717
|
+
h('button', {
|
|
718
|
+
type: 'button', onClick: () => fileRef.current && fileRef.current.click(),
|
|
719
|
+
style: { border: '1px solid rgba(120,140,170,0.4)', background: 'transparent', color: 'inherit', borderRadius: 6, fontSize: 12, padding: '2px 8px', cursor: 'pointer' },
|
|
720
|
+
}, tr('import'))
|
|
721
|
+
)
|
|
722
|
+
: h('div', { style: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', userSelect: 'text' } }, pageText)),
|
|
723
|
+
h('div', { style: { position: 'absolute', left: 0, top: 0, bottom: 0, width: '28%', display: 'flex', alignItems: 'center', pointerEvents: 'none' } },
|
|
724
|
+
h('span', { style: { opacity: 0.15, fontSize: 22, paddingLeft: 4 } }, tr('prevPage'))),
|
|
725
|
+
h('div', { style: { position: 'absolute', right: 0, top: 0, bottom: 0, width: '28%', display: 'flex', alignItems: 'center', justifyContent: 'flex-end', pointerEvents: 'none' } },
|
|
726
|
+
h('span', { style: { opacity: 0.15, fontSize: 22, paddingRight: 4 } }, tr('nextPage'))),
|
|
727
|
+
// 边缘缩放手柄:右边缘调宽、下边缘调高、右下角同时调
|
|
728
|
+
h('div', { title: tr('resizeHint'), onMouseDown: e => startResize(e, 'e'), onClick: e => e.stopPropagation(), style: { position: 'absolute', right: 0, top: 10, bottom: 10, width: 6, cursor: 'ew-resize', zIndex: 4 } }),
|
|
729
|
+
h('div', { title: tr('resizeHint'), onMouseDown: e => startResize(e, 's'), onClick: e => e.stopPropagation(), style: { position: 'absolute', bottom: 0, left: 10, right: 10, height: 6, cursor: 'ns-resize', zIndex: 4 } }),
|
|
730
|
+
h('div', { title: tr('resizeHint'), onMouseDown: e => startResize(e, 'se'), onClick: e => e.stopPropagation(), style: { position: 'absolute', right: 0, bottom: 0, width: 16, height: 16, cursor: 'nwse-resize', zIndex: 5 } })
|
|
731
|
+
) : null,
|
|
732
|
+
// 隐藏的文件选择 input
|
|
733
|
+
h('input', { ref: fileRef, type: 'file', accept: '.txt,text/plain', style: { display: 'none' }, onChange: onFile }),
|
|
734
|
+
// 设置面板:独立大面板完整展示
|
|
735
|
+
s.settingsOpen ? h('div', {
|
|
736
|
+
style: {
|
|
737
|
+
position: 'relative', flex: 1, minHeight: 0, background: panelBg, color: panelColor,
|
|
738
|
+
padding: '12px 16px 16px', overflowY: 'auto',
|
|
739
|
+
fontFamily: peff.fontFamily, fontSize: peff.fontSize, lineHeight: peff.lineHeight,
|
|
740
|
+
},
|
|
741
|
+
},
|
|
742
|
+
h('div', { style: { position: 'sticky', top: 0, zIndex: 1, display: 'flex', alignItems: 'center', justifyContent: 'space-between', fontWeight: 600, marginBottom: 4, padding: '2px 0 8px', background: panelBg } },
|
|
743
|
+
h('span', null, tr('settingsTitle')),
|
|
744
|
+
h('button', {
|
|
745
|
+
type: 'button', onClick: () => store.set({ settingsOpen: false }),
|
|
746
|
+
style: { border: 'none', background: 'transparent', color: 'inherit', cursor: 'pointer', fontSize: 13, padding: 0 },
|
|
747
|
+
}, '✕ ' + tr('done'))
|
|
748
|
+
),
|
|
749
|
+
// ---- 分组1:多套样式配置(保存当前 / 应用 / 删除)----
|
|
750
|
+
group(tr('profileGroup'),
|
|
751
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, marginBottom: 6 } },
|
|
752
|
+
h('input', {
|
|
753
|
+
type: 'text', value: s.profileName || '', placeholder: tr('profileName'),
|
|
754
|
+
onChange: e => store.set({ profileName: e.target.value }),
|
|
755
|
+
style: { flex: 1, minWidth: 0, border: '1px solid rgba(120,140,170,0.4)', borderRadius: 5, background: 'transparent', color: 'inherit', fontSize: 12, padding: '3px 6px' },
|
|
756
|
+
}),
|
|
757
|
+
toolBtn(tr('profileSave'), () => {
|
|
758
|
+
const name = String(store.get().profileName || '').trim();
|
|
759
|
+
if (!name) { store.set({ notice: tr('profileEmptyName') }); return; }
|
|
760
|
+
const p = { ...loadProfiles(), [name]: { ...store.get().style } };
|
|
761
|
+
saveProfiles(p);
|
|
762
|
+
store.set({ notice: t('profileSaved', { name }) });
|
|
763
|
+
})
|
|
764
|
+
),
|
|
765
|
+
Object.keys(s.profiles || {}).length === 0
|
|
766
|
+
? h('div', { style: { opacity: 0.6, fontSize: 12, marginBottom: 8 } }, tr('profileNone'))
|
|
767
|
+
: h('div', { style: { marginBottom: 8 } }, Object.keys(s.profiles).map(name =>
|
|
768
|
+
h('div', { key: name, style: { display: 'flex', alignItems: 'center', gap: 6, marginBottom: 4 } },
|
|
769
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, name),
|
|
770
|
+
toolBtn(tr('profileSelect'), () => {
|
|
771
|
+
updateStyle({ ...DEFAULT_STYLE, ...(s.profiles[name] || {}) });
|
|
772
|
+
store.set({ pos: null });
|
|
773
|
+
if (s.book) store.set({ book: { ...s.book, chapters: detectChapters(fullText, store.get().style.customRegex) }, chapterIndex: 0, pageIndex: 0 });
|
|
774
|
+
store.set({ notice: t('profileApplied', { name }) });
|
|
775
|
+
persist();
|
|
776
|
+
}),
|
|
777
|
+
toolBtn(tr('profileDelete'), () => {
|
|
778
|
+
if (typeof window !== 'undefined' && window.confirm && !window.confirm(t('profileConfirmDelete', { name }))) return;
|
|
779
|
+
const p = { ...loadProfiles() }; delete p[name];
|
|
780
|
+
saveProfiles(p);
|
|
781
|
+
store.set({ notice: t('profileDeleted', { name }) });
|
|
782
|
+
})
|
|
783
|
+
)
|
|
784
|
+
))),
|
|
785
|
+
divider(),
|
|
786
|
+
// ===== 大分组A:设置面板样式(内含外观/边框/尺寸小分组)=====
|
|
787
|
+
bigGroup(tr('panelGroup'),
|
|
788
|
+
// ---- 小分组2a:设置面板外观(完全独立于阅读区)----
|
|
789
|
+
group(tr('panelStyleGroup'),
|
|
790
|
+
h('label', { style: { display: 'flex', alignItems: 'flex-start', gap: 6, marginBottom: 10, cursor: 'pointer' } },
|
|
791
|
+
h('input', {
|
|
792
|
+
type: 'checkbox', checked: panelFollow,
|
|
793
|
+
onChange: e => { updateStyle(e.target.checked ? PANEL_CLEAR : PANEL_FILL); persist(); },
|
|
794
|
+
}),
|
|
795
|
+
h('span', null, h('span', null, tr('panelFollowLabel')), h('span', { style: { display: 'block', opacity: 0.65, fontSize: 11 } }, tr('followInputHint')))
|
|
796
|
+
),
|
|
797
|
+
// 设置面板独立文字与配色(与阅读区分开)
|
|
798
|
+
settingRow(tr('panelFontSize'), h('input', { type: 'range', min: 11, max: 24, value: peff.fontSize, onChange: e => updateStyle({ panelFontSize: Number(e.target.value) }) }), peff.fontSize),
|
|
799
|
+
settingRow(tr('panelLineHeight'), h('input', { type: 'range', min: 1.2, max: 2.4, step: 0.1, value: peff.lineHeight, onChange: e => updateStyle({ panelLineHeight: Number(e.target.value) }) }), peff.lineHeight.toFixed(1)),
|
|
800
|
+
settingRow(tr('panelFontFamily'), h('select', { value: st.panelFontFamily || 'default', onChange: e => updateStyle({ panelFontFamily: e.target.value === 'default' ? '' : e.target.value }) },
|
|
801
|
+
h('option', { value: 'default' }, '跟随输入框'),
|
|
802
|
+
h('option', { value: 'system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", serif' }, '系统字体'),
|
|
803
|
+
h('option', { value: '"Songti SC", SimSun, serif' }, '宋体'),
|
|
804
|
+
h('option', { value: '"PingFang SC", "Microsoft YaHei", sans-serif' }, '黑体'),
|
|
805
|
+
h('option', { value: 'Menlo, Consolas, monospace' }, '等宽')
|
|
806
|
+
)),
|
|
807
|
+
settingRow(tr('panelTextColor'), h('input', { type: 'color', value: toHex(panelColor, '#888888'), onChange: e => updateStyle({ panelTextColor: e.target.value }) })),
|
|
808
|
+
settingRow(tr('panelBgColor'), h('input', { type: 'color', value: toHex(panelBg, '#ffffff'), onChange: e => updateStyle({ panelBgColor: e.target.value }) })),
|
|
809
|
+
),
|
|
810
|
+
divider(),
|
|
811
|
+
// ---- 分组3:设置面板边框(与阅读区独立)----
|
|
812
|
+
group(tr('panelBorderGroup'),
|
|
813
|
+
settingRow(tr('borderRadius'), h('input', {
|
|
814
|
+
type: 'range', min: 0, max: 40, step: 1,
|
|
815
|
+
value: st.panelRadiusValue !== '' && st.panelRadiusValue != null ? Number(st.panelRadiusValue) : Math.round(parseFloat(eff.radius) || 0),
|
|
816
|
+
onChange: e => updateStyle({ panelRadiusValue: String(e.target.value) }),
|
|
817
|
+
}), (st.panelRadiusValue !== '' && st.panelRadiusValue != null ? st.panelRadiusValue : (parseFloat(eff.radius) || 0)) + 'px'),
|
|
818
|
+
settingRow(tr('borderVisible'), h('input', {
|
|
819
|
+
type: 'checkbox', checked: st.panelBorderVisible !== false,
|
|
820
|
+
onChange: e => updateStyle({ panelBorderVisible: e.target.checked }),
|
|
821
|
+
})),
|
|
822
|
+
),
|
|
823
|
+
divider(),
|
|
824
|
+
// ---- 分组3c:设置面板尺寸(与阅读区独立)----
|
|
825
|
+
group(tr('panelSizeGroup'),
|
|
826
|
+
settingRow(tr('windowWidth'), h('input', {
|
|
827
|
+
type: 'number', min: 200, step: 1, value: Math.round(peff.width),
|
|
828
|
+
onChange: e => { const v = Number(e.target.value); if (v > 0) updateStyle({ panelWidth: v }); },
|
|
829
|
+
style: numberInputStyle,
|
|
830
|
+
}), 'px'),
|
|
831
|
+
settingRow(tr('windowHeight'), h('input', {
|
|
832
|
+
type: 'number', min: 200, step: 1, value: Math.round(peff.height),
|
|
833
|
+
onChange: e => { const v = Number(e.target.value); if (v > 0) updateStyle({ panelHeight: v }); },
|
|
834
|
+
style: numberInputStyle,
|
|
835
|
+
}), 'px'),
|
|
836
|
+
),
|
|
837
|
+
), // 关闭大分组A:设置面板样式
|
|
838
|
+
// ===== 大分组B:阅读区样式(内含文字/边框/尺寸小分组)=====
|
|
839
|
+
bigGroup(tr('readerGroup'),
|
|
840
|
+
// ---- 小分组4a:阅读区文字与排版 ----
|
|
841
|
+
group(tr('readerTextGroup'),
|
|
842
|
+
h('label', { style: { display: 'flex', alignItems: 'flex-start', gap: 6, marginBottom: 10, cursor: 'pointer' } },
|
|
843
|
+
h('input', {
|
|
844
|
+
type: 'checkbox', checked: readerFollow,
|
|
845
|
+
onChange: e => { updateStyle(e.target.checked ? READER_CLEAR : READER_FILL); store.set({ pos: null }); persist(); },
|
|
846
|
+
}),
|
|
847
|
+
h('span', null, h('span', null, tr('readerFollowLabel')), h('span', { style: { display: 'block', opacity: 0.65, fontSize: 11 } }, tr('followInputHint')))
|
|
848
|
+
),
|
|
849
|
+
settingRow(tr('fontSize'), h('input', { type: 'range', min: 12, max: 36, value: eff.fontSize, onChange: e => updateStyle({ fontSize: Number(e.target.value) }) }), eff.fontSize),
|
|
850
|
+
settingRow(tr('lineHeight'), h('input', { type: 'range', min: 1.2, max: 2.6, step: 0.1, value: eff.lineHeight, onChange: e => updateStyle({ lineHeight: Number(e.target.value) }) }), eff.lineHeight.toFixed(1)),
|
|
851
|
+
settingRow(tr('fontFamily'), h('select', { value: st.fontFamily || 'default', onChange: e => updateStyle({ fontFamily: e.target.value === 'default' ? '' : e.target.value }) },
|
|
852
|
+
h('option', { value: 'default' }, '跟随输入框'),
|
|
853
|
+
h('option', { value: 'system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", serif' }, '系统字体'),
|
|
854
|
+
h('option', { value: '"Songti SC", SimSun, serif' }, '宋体'),
|
|
855
|
+
h('option', { value: '"PingFang SC", "Microsoft YaHei", sans-serif' }, '黑体'),
|
|
856
|
+
h('option', { value: 'Menlo, Consolas, monospace' }, '等宽')
|
|
857
|
+
)),
|
|
858
|
+
settingRow(tr('textColor'), h('input', { type: 'color', value: toHex(eff.color, '#888888'), onChange: e => updateStyle({ textColor: e.target.value }) })),
|
|
859
|
+
settingRow(tr('backgroundColor'), h('input', { type: 'color', value: toHex(eff.bg, '#ffffff'), onChange: e => updateStyle({ bgColor: e.target.value }) })),
|
|
860
|
+
settingRow(tr('bgOpacity'), h('input', {
|
|
861
|
+
type: 'range', min: 0.1, max: 1, step: 0.05,
|
|
862
|
+
value: st.bgOpacity == null ? 1 : st.bgOpacity,
|
|
863
|
+
onChange: e => updateStyle({ bgOpacity: Number(e.target.value) }),
|
|
864
|
+
}), Math.round((st.bgOpacity == null ? 1 : st.bgOpacity) * 100) + '%'),
|
|
865
|
+
),
|
|
866
|
+
divider(),
|
|
867
|
+
// ---- 小分组4b:阅读区边框(与设置面板独立)----
|
|
868
|
+
group(tr('readerBorderGroup'),
|
|
869
|
+
settingRow(tr('borderRadius'), h('input', {
|
|
870
|
+
type: 'range', min: 0, max: 40, step: 1,
|
|
871
|
+
value: st.radiusValue !== '' && st.radiusValue != null ? Number(st.radiusValue) : Math.round(parseFloat(eff.radius) || 0),
|
|
872
|
+
onChange: e => updateStyle({ radiusValue: String(e.target.value) }),
|
|
873
|
+
}), (st.radiusValue !== '' && st.radiusValue != null ? st.radiusValue : (parseFloat(eff.radius) || 0)) + 'px'),
|
|
874
|
+
settingRow(tr('borderVisible'), h('input', {
|
|
875
|
+
type: 'checkbox', checked: st.borderVisible !== false,
|
|
876
|
+
onChange: e => updateStyle({ borderVisible: e.target.checked }),
|
|
877
|
+
})),
|
|
878
|
+
),
|
|
879
|
+
divider(),
|
|
880
|
+
// ---- 小分组4c:窗口尺寸(宽高用数字输入框,允许自由输入精确值)----
|
|
881
|
+
group(tr('readerSizeGroup'),
|
|
882
|
+
settingRow(tr('windowWidth'), h('input', {
|
|
883
|
+
type: 'number', min: 80, step: 1, value: Math.round(eff.width),
|
|
884
|
+
onChange: e => { const v = Number(e.target.value); if (v > 0) updateStyle({ width: v }); },
|
|
885
|
+
style: numberInputStyle,
|
|
886
|
+
}), 'px'),
|
|
887
|
+
settingRow(tr('windowHeight'), h('input', {
|
|
888
|
+
type: 'number', min: 40, step: 1, value: Math.round(eff.height),
|
|
889
|
+
onChange: e => { const v = Number(e.target.value); if (v > 0) updateStyle({ height: v }); },
|
|
890
|
+
style: numberInputStyle,
|
|
891
|
+
}), 'px'),
|
|
892
|
+
),
|
|
893
|
+
), // 关闭大分组B:阅读区样式
|
|
894
|
+
divider(),
|
|
895
|
+
// ---- 分组6:章节识别 ----
|
|
896
|
+
group(tr('chapterGroup'),
|
|
897
|
+
h('div', { style: { fontSize: 12, marginTop: 2, opacity: 0.8 } }, tr('regexHint')),
|
|
898
|
+
h('textarea', {
|
|
899
|
+
value: st.customRegex, rows: 2, placeholder: tr('customChapterRegex'),
|
|
900
|
+
onChange: e => updateStyle({ customRegex: e.target.value }),
|
|
901
|
+
style: { width: '100%', marginTop: 4, fontSize: 12, fontFamily: 'monospace', boxSizing: 'border-box' },
|
|
902
|
+
}),
|
|
903
|
+
),
|
|
904
|
+
divider(),
|
|
905
|
+
// ---- 分组7:操作 ----
|
|
906
|
+
group(tr('actionGroup'),
|
|
907
|
+
h('div', { style: { display: 'flex', gap: 8, marginTop: 2, flexWrap: 'wrap' } },
|
|
908
|
+
toolBtn(tr('reset'), () => {
|
|
909
|
+
updateStyle({ ...DEFAULT_STYLE });
|
|
910
|
+
store.set({ pos: null });
|
|
911
|
+
if (s.book) store.set({ book: { ...s.book, chapters: detectChapters(fullText, '') }, chapterIndex: 0, pageIndex: 0 });
|
|
912
|
+
}),
|
|
913
|
+
toolBtn(tr('resetPos'), () => { store.set({ pos: null }); persist(); }),
|
|
914
|
+
toolBtn(tr('done'), () => {
|
|
915
|
+
if (s.book) store.set({ book: { ...s.book, chapters: detectChapters(fullText, store.get().style.customRegex) } });
|
|
916
|
+
store.set({ settingsOpen: false }); persist();
|
|
917
|
+
})
|
|
918
|
+
),
|
|
919
|
+
)
|
|
920
|
+
) : null,
|
|
921
|
+
// 工具栏固定在窗口最下方
|
|
922
|
+
toolbar
|
|
923
|
+
);
|
|
924
|
+
|
|
925
|
+
function settingRow(label, control, value) {
|
|
926
|
+
return h('div', {
|
|
927
|
+
style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, marginBottom: 6 },
|
|
928
|
+
}, h('span', null, label), h('span', { style: { display: 'flex', alignItems: 'center', gap: 6 } }, control, value !== undefined ? h('span', { style: { minWidth: 28, textAlign: 'right', opacity: 0.7 } }, value) : null));
|
|
929
|
+
}
|
|
930
|
+
// 分组标题:带小色块,便于快速定位
|
|
931
|
+
function groupTitle(label) {
|
|
932
|
+
return h('div', {
|
|
933
|
+
style: { display: 'flex', alignItems: 'center', gap: 6, fontWeight: 600, fontSize: 12, margin: '2px 0 8px' },
|
|
934
|
+
}, h('span', { style: { width: 3, height: 12, borderRadius: 2, background: 'currentColor', opacity: 0.55 } }), h('span', null, label));
|
|
935
|
+
}
|
|
936
|
+
// 分组间的分割线
|
|
937
|
+
function divider() {
|
|
938
|
+
return h('div', { style: { height: 1, background: 'currentColor', opacity: 0.15, margin: '12px 0' } });
|
|
939
|
+
}
|
|
940
|
+
// 一组:标题 + 若干控件,组间由 divider 分隔
|
|
941
|
+
function group(label, ...children) {
|
|
942
|
+
return h('div', null, groupTitle(label), ...children);
|
|
943
|
+
}
|
|
944
|
+
// 大分组:把同类小分组收进一个带外框的容器(如「设置面板样式」「阅读区样式」)
|
|
945
|
+
function bigGroup(label, ...children) {
|
|
946
|
+
return h('div', {
|
|
947
|
+
style: {
|
|
948
|
+
border: '1px solid rgba(120,140,170,0.28)', borderRadius: 8,
|
|
949
|
+
padding: '10px 12px 4px', margin: '10px 0 4px',
|
|
950
|
+
},
|
|
951
|
+
},
|
|
952
|
+
h('div', {
|
|
953
|
+
style: {
|
|
954
|
+
display: 'flex', alignItems: 'center', gap: 8, fontWeight: 700,
|
|
955
|
+
fontSize: 13, marginBottom: 10, paddingBottom: 6,
|
|
956
|
+
borderBottom: '1px solid rgba(120,140,170,0.22)',
|
|
957
|
+
},
|
|
958
|
+
}, h('span', { style: { width: 4, height: 14, borderRadius: 2, background: 'currentColor', opacity: 0.65 } }), h('span', null, label)),
|
|
959
|
+
...children
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
function toHex(color, fallback) {
|
|
963
|
+
if (typeof color !== 'string') return fallback;
|
|
964
|
+
if (/^#[0-9a-fA-F]{6}$/.test(color)) return color;
|
|
965
|
+
const m = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
966
|
+
if (!m) return fallback;
|
|
967
|
+
return '#' + [1, 2, 3].map(i => Number(m[i]).toString(16).padStart(2, '0')).join('');
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
ctx.slots.inject('conversation.input.left', () => ctx.slots.register({
|
|
972
|
+
name: 'conversation.input.left', id: 'novel-reader-trigger', order: 6, label: () => tr('name'), locale: NS,
|
|
973
|
+
}, Trigger));
|
|
974
|
+
|
|
975
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
976
|
+
name: 'shell.overlay', id: 'novel-reader-overlay', order: 50, label: () => tr('name'), locale: NS,
|
|
977
|
+
}, InlineReader));
|
|
978
|
+
},
|
|
979
|
+
};
|
|
980
|
+
},
|
|
981
|
+
});
|