dsh-half-page 0.3.23 → 0.3.25

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 (2) hide show
  1. package/client.js +40 -5
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -60,7 +60,35 @@ window.__ModuleLoader__.load({
60
60
  return out
61
61
  }
62
62
 
63
- function Panel() {
63
+ const CN_DIGIT = { 零: 0, 〇: 0, 一: 1, 二: 2, 两: 2, 三: 3, 四: 4, 五: 5, 六: 6, 七: 7, 八: 8, 九: 9 }
64
+ const cnNum = (s) => {
65
+ const t = String(s || '').replace(/[0-9]/g, (d) => String.fromCharCode(d.charCodeAt(0) - 65248))
66
+ if (/^[0-9]+$/.test(t)) return Number(t)
67
+ let n = 0
68
+ let cur = 0
69
+ for (const ch of t) {
70
+ if (ch === '十') { n += (cur || 1) * 10; cur = 0 }
71
+ else if (ch === '百') { n += (cur || 1) * 100; cur = 0 }
72
+ else if (ch === '千') { n += (cur || 1) * 1000; cur = 0 }
73
+ else if (CN_DIGIT[ch] !== undefined) cur = CN_DIGIT[ch]
74
+ else return NaN
75
+ }
76
+ return n + cur
77
+ }
78
+ const chapterNo = (title) => {
79
+ const m = String(title || '').match(/第([0-90-9零〇一二三四五六七八九十百千两]+)章/)
80
+ return m ? cnNum(m[1]) : NaN
81
+ }
82
+ // 有几章、从第几章到第几章(章名认不出数字就不显示范围)
83
+ const chapterRange = (chapters) => {
84
+ const nos = (chapters || []).map((c) => chapterNo(c && c.title)).filter((n) => Number.isFinite(n))
85
+ if (!nos.length) return ''
86
+ const a = Math.min.apply(null, nos)
87
+ const b = Math.max.apply(null, nos)
88
+ return a === b ? ('第 ' + a + ' 章') : ('第 ' + a + '–' + b + ' 章')
89
+ }
90
+
91
+ function Panel() {
64
92
  const [state, setState] = useState(null)
65
93
  const [confirmId, setConfirmId] = useState('')
66
94
  const [tab, setTab] = useState('read')
@@ -202,7 +230,7 @@ window.__ModuleLoader__.load({
202
230
 
203
231
  const tabs = h('div', { style: S.row },
204
232
  ['read', 'works', 'fav', 'set'].map((k) => h('div', {
205
- key: k, style: S.tab(tab === k), onClick: () => { setTab(k); if (k === 'works' && !works) loadWorks() },
233
+ key: k, style: S.tab(tab === k), onClick: () => { setTab(k); if ((k === 'works' || k === 'fav') && !works) loadWorks() },
206
234
  }, k === 'read' ? '读书' : k === 'works' ? '她的作品' : k === 'fav' ? '收藏' : '设置')),
207
235
  h('div', { style: { flex: 1 } }),
208
236
  msg ? h('div', { style: { ...S.dim, color: C.ok } }, msg) : null,
@@ -297,7 +325,7 @@ window.__ModuleLoader__.load({
297
325
  return h('div', { key: bi, style: { marginBottom: 10 } },
298
326
  h('div', { style: { ...S.row, marginBottom: 4 } },
299
327
  h('div', { style: { fontWeight: 600 } }, bk.book),
300
- h('div', { style: S.dim }, total + ' 章'),
328
+ h('div', { style: S.dim }, total + ' 章' + (chapterRange(bk.chapters) ? ' · ' + chapterRange(bk.chapters) : '')),
301
329
  h('div', { style: { flex: 1 } }),
302
330
  paged ? h('button', { style: S.btn, disabled: page <= 0, onClick: () => setView({ page: page - 1 }) }, '‹') : null,
303
331
  paged ? h('div', { style: { ...S.dim, minWidth: 46, textAlign: 'center' } }, all ? '全部' : ((page + 1) + ' / ' + pages)) : null,
@@ -456,14 +484,21 @@ window.__ModuleLoader__.load({
456
484
  const favTab = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
457
485
  h('div', { style: S.card },
458
486
  h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '收藏'),
459
- favs.length ? favs.map((f, i) => h('div', { key: i, style: S.item },
487
+ favs.length ? favs.map((f, i) => {
488
+ const isFile = String(f).startsWith('file:')
489
+ const fpath = isFile ? f.slice(5) : ''
490
+ const w = isFile && works && (works.files || []).find((x) => x.path === fpath)
491
+ const who = w ? w.author : ''
492
+ return h('div', { key: i, style: S.item },
460
493
  h('div', {
461
494
  style: { flex: 1, cursor: 'pointer', borderTop: i ? '1px solid ' + C.line : 'none', paddingTop: i ? 8 : 0 },
462
495
  onClick: () => openFav(f),
463
496
  }, String(f).startsWith('file:') ? f.slice(5) : f.replace('|', ' · ')),
497
+ isFile ? h('div', { style: who ? S.dim : { ...S.dim, color: C.warn } }, who ? ('署名 · ' + who) : '未署名') : null,
464
498
  h('button', { style: S.btn, onClick: () => copyFav(f) }, '复制'),
465
499
  h('button', { style: S.btn, onClick: () => toggleFav(f) }, '取消收藏'),
466
- )) : h('div', { style: S.dim }, '在读后感或作品上点 ☆,收藏的东西会出现在这儿。'),
500
+ )
501
+ }) : h('div', { style: S.dim }, '在读后感或作品上点 ☆,收藏的东西会出现在这儿。'),
467
502
  ),
468
503
  opened && String(opened.path || '').startsWith('fav:')
469
504
  ? h('div', { style: { ...S.text, marginTop: 0 } }, (opened.title ? opened.title + '\n\n' : '') + opened.text)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-half-page",
3
- "version": "0.3.23",
3
+ "version": "0.3.25",
4
4
  "private": false,
5
5
  "author": "鹿野 <luye@dsh.local>",
6
6
  "license": "MIT",