dsh-pdf-workbench 1.3.4 → 1.4.1
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 +143 -117
- package/assets/screenshot-attachments.jpg +0 -0
- package/assets/screenshot-canvas.jpg +0 -0
- package/assets/screenshot-questions.jpg +0 -0
- package/assets/screenshot-settings-data.jpg +0 -0
- package/assets/screenshot-settings-mode.jpg +0 -0
- package/assets/screenshot-settings-reading.jpg +0 -0
- package/client.js +6243 -974
- package/docs/DETAIL.md +1 -69
- package/docs/RELEASE.md +207 -58
- package/docs/SIDE-PREVIEW.md +5 -1
- package/docs/boss-handover.md +84 -0
- package/docs/ci.md +159 -0
- package/docs/copy/templates.md +110 -0
- package/docs/copy/terms.md +62 -0
- package/docs/decisions.md +325 -0
- package/docs/features.md +55 -0
- package/docs/feedback/.gitkeep +0 -0
- package/docs/preview.svg +86 -0
- package/docs/requirements/.gitkeep +0 -0
- package/docs/reviews/.gitkeep +0 -0
- package/docs/reviews/T-20261124-01.md +180 -0
- package/docs/reviews/T-20261124-03.md +85 -0
- package/docs/reviews/T-20261124-04.md +106 -0
- package/docs/reviews/T-20261124-05.md +94 -0
- package/docs/reviews/T-20261124-07.md +115 -0
- package/docs/reviews/T-20261124-08.md +292 -0
- package/docs/reviews/T-20261124-09.md +112 -0
- package/docs/reviews/T-20261124-10.md +112 -0
- package/docs/roles/auditor.md +123 -0
- package/docs/roles/boss.md +162 -0
- package/docs/roles/code-reviewer.md +132 -0
- package/docs/roles/feature-inventory.md +119 -0
- package/docs/roles/feedback-collector.md +105 -0
- package/docs/roles/programmer.md +112 -0
- package/docs/roles/release-manager.md +108 -0
- package/docs/roles/tester.md +140 -0
- package/docs/roles/ui-copywriter.md +122 -0
- package/docs/tests/.gitkeep +0 -0
- package/docs/tests/T-20261124-01.md +146 -0
- package/docs/tests/T-20261124-03.md +81 -0
- package/docs/tests/T-20261124-04.md +51 -0
- package/docs/tests/T-20261124-05.md +51 -0
- package/docs/tests/T-20261124-07.md +60 -0
- package/docs/tests/T-20261124-08.md +61 -0
- package/docs/tests/T-20261124-09.md +60 -0
- package/docs/tests/T-20261124-10.md +61 -0
- package/docs/todo.md +277 -0
- package/icon.svg +6 -5
- package/index.js +8 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
- package/screenshots.json +6 -1
- package/src/host/artifacts.js +31 -3
- package/src/host/attachments.js +159 -0
- package/src/host/backup.js +457 -0
- package/src/host/base-session.js +146 -0
- package/src/host/book-import.js +98 -0
- package/src/host/chapter-sessions.js +154 -0
- package/src/host/chapter-text.js +91 -0
- package/src/host/fonts.js +190 -0
- package/src/host/pdf-stream.js +168 -0
- package/src/host/ppt.js +153 -0
- package/src/host/print.js +191 -0
- package/src/host/questions.js +186 -0
- package/src/host/routes.js +661 -25
- package/src/host/state.js +1 -1
- package/src/host/zip.js +186 -0
- package/tools/pdf_text.py +34 -0
- package/vendor/fonts/zhhand/Xiaolai-Regular.ttf +0 -0
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "PDF reading · ask as you read",
|
|
4
|
-
"description": "A PDF reading
|
|
4
|
+
"description": "A workbench for close reading of full-page PDFs, opened from the “PDF reading” sidebar entry. Libraries and shelves are organised as book → chapter; the reader supports single/continuous pages, ink and marquee annotations, an off-page canvas, bilingual view and translation overlays. Each chapter can start extract, Q&A and exercise conversations, and also carries attachments, printing and machine-to-machine migration. Libraries and notes stay on this machine; PDFs are never pushed into model context automatically. Translation needs Python + a DeepSeek API key; PPT-to-PDF optionally uses local Office or LibreOffice.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "PDF 阅读 · 随时问答",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "面向整页 PDF 精读的工作台,从左侧栏「PDF 阅读」进入。书库与书架按「书 → 章」组织;阅读器支持单页/连续、手写与框选批注、页外画布、双语对照和覆盖层;每章可直接提取、答疑、习题,并带附件、打印与整机数据迁移。所有书库与笔记保存在本机,PDF 不会自动进入模型上下文;翻译需要 Python + DeepSeek API Key,PPT 转 PDF 可选本机 Office/LibreOffice。",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
package/screenshots.json
CHANGED
|
@@ -4,5 +4,10 @@
|
|
|
4
4
|
"assets/screenshot-reader.jpg",
|
|
5
5
|
"assets/screenshot-bilingual.jpg",
|
|
6
6
|
"assets/screenshot-overlay.jpg",
|
|
7
|
-
"assets/screenshot-qa.jpg"
|
|
7
|
+
"assets/screenshot-qa.jpg",
|
|
8
|
+
"assets/screenshot-settings-reading.jpg",
|
|
9
|
+
"assets/screenshot-settings-data.jpg",
|
|
10
|
+
"assets/screenshot-attachments.jpg",
|
|
11
|
+
"assets/screenshot-canvas.jpg",
|
|
12
|
+
"assets/screenshot-questions.jpg"
|
|
8
13
|
]
|
package/src/host/artifacts.js
CHANGED
|
@@ -43,19 +43,46 @@ const TEXT_EXTENSIONS = new Set([
|
|
|
43
43
|
/** Extensions shown as an image badge; the reader does not draw them yet. */
|
|
44
44
|
const IMAGE_EXTENSIONS = new Set(['png', 'jpg', 'jpeg', 'webp', 'gif', 'bmp', 'avif'])
|
|
45
45
|
|
|
46
|
+
/** Word documents: listed, but previewed by DSH/Office rather than in this plugin. */
|
|
47
|
+
const OFFICE_EXTENSIONS = new Set(['doc', 'docx'])
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Products the workbench lists. This is a whitelist on purpose: a chapter
|
|
51
|
+
* directory also holds build intermediates (`tex`, `aox`/`aux`/`log`/`out`/
|
|
52
|
+
* `bbl`/`blg`/`synctex` …), spreadsheets, slides and scratch files. None of
|
|
53
|
+
* them are reading material here, and an extension nobody thought of must not
|
|
54
|
+
* leak into the list. The files stay on disk untouched; only the listing
|
|
55
|
+
* ignores them.
|
|
56
|
+
*/
|
|
57
|
+
const VISIBLE_EXTENSIONS = new Set([
|
|
58
|
+
'pdf', 'md', 'markdown', 'doc', 'docx',
|
|
59
|
+
'png', 'jpg', 'jpeg', 'webp', 'gif', 'bmp', 'avif',
|
|
60
|
+
])
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether one produced file belongs in the list.
|
|
64
|
+
* @param {string} name - file name.
|
|
65
|
+
* @returns {boolean} true when the row should be shown.
|
|
66
|
+
*/
|
|
67
|
+
function visibleName(name) {
|
|
68
|
+
const extension = extname(name).replace(/^\./, '').toLowerCase()
|
|
69
|
+
return VISIBLE_EXTENSIONS.has(extension)
|
|
70
|
+
}
|
|
71
|
+
|
|
46
72
|
/** Decoders tried in order for a preview; UTF-8 first, then the common Chinese Windows code page. */
|
|
47
73
|
const DECODERS = ['utf-8', 'gb18030']
|
|
48
74
|
|
|
49
75
|
/**
|
|
50
76
|
* The kind shown as a badge and used to decide whether the reader can draw it.
|
|
51
77
|
* @param {string} name - file name.
|
|
52
|
-
* @returns {'pdf' | 'text' | 'image' | 'other'} the kind.
|
|
78
|
+
* @returns {'pdf' | 'text' | 'image' | 'office' | 'other'} the kind.
|
|
53
79
|
*/
|
|
54
80
|
export function kindOf(name) {
|
|
55
81
|
const extension = extname(name).replace(/^\./, '').toLowerCase()
|
|
56
82
|
if (extension === 'pdf') return 'pdf'
|
|
57
83
|
if (TEXT_EXTENSIONS.has(extension)) return 'text'
|
|
58
84
|
if (IMAGE_EXTENSIONS.has(extension)) return 'image'
|
|
85
|
+
if (OFFICE_EXTENSIONS.has(extension)) return 'office'
|
|
59
86
|
return 'other'
|
|
60
87
|
}
|
|
61
88
|
|
|
@@ -202,8 +229,9 @@ async function readingNames(dir) {
|
|
|
202
229
|
return entries
|
|
203
230
|
.filter(entry => entry.isFile() || entry.isSymbolicLink())
|
|
204
231
|
.map(entry => entry.name)
|
|
205
|
-
// Office lock files and editor droppings are noise in a reading list
|
|
206
|
-
|
|
232
|
+
// Office lock files and editor droppings are noise in a reading list; TeX
|
|
233
|
+
// sources, spreadsheets and slides are not reading material for this plugin.
|
|
234
|
+
.filter(name => !name.startsWith('.') && !name.startsWith('~$') && visibleName(name))
|
|
207
235
|
.sort((left, right) => left.localeCompare(right, 'zh'))
|
|
208
236
|
}
|
|
209
237
|
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chapter attachments: user-supplied files kept beside the chapter, outside the
|
|
3
|
+
* PDF reader. A first version accepts PDFs and images; the manifest records what
|
|
4
|
+
* was copied so the browser can list it without rescanning metadata.
|
|
5
|
+
* @module dsh-pdf-workbench/attachments
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { copyFile, mkdir, readFile, readdir, rename, stat, unlink, writeFile } from 'node:fs/promises'
|
|
9
|
+
import { basename, extname, join } from 'node:path'
|
|
10
|
+
|
|
11
|
+
/** Extensions the first version accepts, with the kind shown in the UI. */
|
|
12
|
+
export const ATTACHMENT_KINDS = {
|
|
13
|
+
pdf: 'pdf',
|
|
14
|
+
png: 'image',
|
|
15
|
+
jpg: 'image',
|
|
16
|
+
jpeg: 'image',
|
|
17
|
+
webp: 'image',
|
|
18
|
+
gif: 'image',
|
|
19
|
+
bmp: 'image',
|
|
20
|
+
avif: 'image',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Per-file ceiling for a copied attachment. */
|
|
24
|
+
export const MAX_ATTACHMENT_BYTES = 50 * 1024 * 1024
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Where one chapter's attachments live.
|
|
28
|
+
* @param {string} libraryDir - the library root.
|
|
29
|
+
* @param {string} book - book id.
|
|
30
|
+
* @param {string} code - chapter code.
|
|
31
|
+
* @returns {string} the absolute directory.
|
|
32
|
+
*/
|
|
33
|
+
export function attachmentsDir(libraryDir, book, code) {
|
|
34
|
+
return join(libraryDir, '.pdfdesk', 'attachments', book, code)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The manifest beside the files.
|
|
39
|
+
* @param {string} libraryDir - the library root.
|
|
40
|
+
* @param {string} book - book id.
|
|
41
|
+
* @param {string} code - chapter code.
|
|
42
|
+
* @returns {string} the manifest path.
|
|
43
|
+
*/
|
|
44
|
+
export function attachmentManifestPath(libraryDir, book, code) {
|
|
45
|
+
return join(attachmentsDir(libraryDir, book, code), 'manifest.json')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Strip directories and characters Windows or the browser would misread.
|
|
50
|
+
* @param {string} value - proposed file name.
|
|
51
|
+
* @returns {string} a safe base name (never empty).
|
|
52
|
+
*/
|
|
53
|
+
export function safeAttachmentName(value) {
|
|
54
|
+
const base = basename(String(value ?? '')).replace(/[<>:"/\\|?*\u0000-\u001f]/g, '_').trim()
|
|
55
|
+
return base === '' || base === '.' || base === '..' ? 'attachment' : base.slice(0, 120)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Read the manifest, tolerating a missing or broken file.
|
|
60
|
+
* @param {string} dir - the chapter's attachment directory.
|
|
61
|
+
* @returns {Promise<{ version: number, items: object[] }>} parsed manifest.
|
|
62
|
+
*/
|
|
63
|
+
async function readManifest(dir) {
|
|
64
|
+
const raw = await readFile(join(dir, 'manifest.json'), 'utf8').catch(() => null)
|
|
65
|
+
if (raw === null) return { version: 1, items: [] }
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(raw)
|
|
68
|
+
const items = Array.isArray(parsed.items) ? parsed.items.filter(item => item !== null && typeof item === 'object' && typeof item.name === 'string') : []
|
|
69
|
+
return { version: 1, items }
|
|
70
|
+
} catch {
|
|
71
|
+
return { version: 1, items: [] }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Write the manifest atomically.
|
|
77
|
+
* @param {string} dir - the chapter's attachment directory.
|
|
78
|
+
* @param {{ version: number, items: object[] }} manifest - the value.
|
|
79
|
+
* @returns {Promise<void>} completion.
|
|
80
|
+
*/
|
|
81
|
+
async function writeManifest(dir, manifest) {
|
|
82
|
+
const path = join(dir, 'manifest.json')
|
|
83
|
+
const temporary = `${path}.${process.pid}.tmp`
|
|
84
|
+
await writeFile(temporary, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8')
|
|
85
|
+
await copyFile(temporary, path)
|
|
86
|
+
await unlink(temporary).catch(() => {})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* List one chapter's attachments, including files the manifest does not know
|
|
91
|
+
* about yet (a copy interrupted before the manifest write).
|
|
92
|
+
* @param {string} libraryDir - the library root.
|
|
93
|
+
* @param {string} book - book id.
|
|
94
|
+
* @param {string} code - chapter code.
|
|
95
|
+
* @returns {Promise<{ dir: string, items: object[] }>} the manifest items.
|
|
96
|
+
*/
|
|
97
|
+
export async function listAttachments(libraryDir, book, code) {
|
|
98
|
+
const dir = attachmentsDir(libraryDir, book, code)
|
|
99
|
+
const manifest = await readManifest(dir)
|
|
100
|
+
const known = new Set(manifest.items.map(item => item.name))
|
|
101
|
+
const names = await readdir(dir).catch(() => [])
|
|
102
|
+
const extra = []
|
|
103
|
+
for (const name of names) {
|
|
104
|
+
if (name === 'manifest.json' || known.has(name)) continue
|
|
105
|
+
const info = await stat(join(dir, name)).catch(() => null)
|
|
106
|
+
if (info === null || !info.isFile()) continue
|
|
107
|
+
const extension = extname(name).slice(1).toLowerCase()
|
|
108
|
+
if (ATTACHMENT_KINDS[extension] === undefined) continue
|
|
109
|
+
extra.push({ name, kind: ATTACHMENT_KINDS[extension], bytes: info.size, addedAt: info.mtimeMs })
|
|
110
|
+
}
|
|
111
|
+
return { dir, items: [...manifest.items, ...extra] }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Copy one local file into the chapter's attachments.
|
|
116
|
+
* @param {{ libraryDir: string, book: string, code: string, sourcePath: string, name?: string }} options - the library, chapter and source.
|
|
117
|
+
* @returns {Promise<{ name: string, kind: string, bytes: number, addedAt: number }>} the stored item.
|
|
118
|
+
*/
|
|
119
|
+
export async function addAttachment(options) {
|
|
120
|
+
const extension = extname(String(options.sourcePath ?? '')).slice(1).toLowerCase()
|
|
121
|
+
const kind = ATTACHMENT_KINDS[extension]
|
|
122
|
+
if (kind === undefined) throw Object.assign(new Error('只支持 PDF 与图片附件'), { code: 'bad-type' })
|
|
123
|
+
const info = await stat(options.sourcePath)
|
|
124
|
+
if (!info.isFile()) throw Object.assign(new Error('附件必须是文件'), { code: 'not-file' })
|
|
125
|
+
if (info.size > MAX_ATTACHMENT_BYTES) throw Object.assign(new Error('附件超过 50 MB'), { code: 'too-large' })
|
|
126
|
+
const dir = attachmentsDir(options.libraryDir, options.book, options.code)
|
|
127
|
+
await mkdir(dir, { recursive: true })
|
|
128
|
+
const manifest = await readManifest(dir)
|
|
129
|
+
const wanted = safeAttachmentName(options.name ?? options.sourcePath)
|
|
130
|
+
const stem = wanted.slice(0, Math.max(1, wanted.length - extension.length - 1))
|
|
131
|
+
let name = wanted
|
|
132
|
+
let counter = 0
|
|
133
|
+
const taken = new Set([...manifest.items.map(item => item.name), 'manifest.json'])
|
|
134
|
+
while (taken.has(name)) {
|
|
135
|
+
counter += 1
|
|
136
|
+
name = `${stem}-${counter}.${extension}`
|
|
137
|
+
}
|
|
138
|
+
await copyFile(options.sourcePath, join(dir, name))
|
|
139
|
+
const item = { name, kind, bytes: info.size, addedAt: Date.now() }
|
|
140
|
+
manifest.items.push(item)
|
|
141
|
+
await writeManifest(dir, manifest)
|
|
142
|
+
return item
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Delete one attachment and drop it from the manifest.
|
|
147
|
+
* @param {{ libraryDir: string, book: string, code: string, name: string }} options - the library, chapter and file.
|
|
148
|
+
* @returns {Promise<{ removed: boolean }>} whether a file was deleted.
|
|
149
|
+
*/
|
|
150
|
+
export async function removeAttachment(options) {
|
|
151
|
+
const dir = attachmentsDir(options.libraryDir, options.book, options.code)
|
|
152
|
+
const name = safeAttachmentName(options.name)
|
|
153
|
+
const manifest = await readManifest(dir)
|
|
154
|
+
const index = manifest.items.findIndex(item => item.name === name)
|
|
155
|
+
if (index >= 0) manifest.items.splice(index, 1)
|
|
156
|
+
const result = await unlink(join(dir, name)).then(() => true).catch(() => false)
|
|
157
|
+
if (index >= 0 || result) await writeManifest(dir, manifest)
|
|
158
|
+
return { removed: result || index >= 0 }
|
|
159
|
+
}
|