dsh-cait 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +410 -352
- package/LICENSE +201 -201
- package/README.ja.md +55 -14
- package/README.md +466 -423
- package/README.zh-CN.md +429 -390
- package/client/components.js +2408 -2377
- package/client/helpers.js +103 -103
- package/client/locales.js +751 -730
- package/client/rpc.js +93 -93
- package/client/styles.js +258 -258
- package/client.js +3608 -3556
- package/icon.svg +8 -8
- package/index.js +45 -45
- package/lib/api.js +223 -223
- package/lib/docx.js +392 -389
- package/lib/epub.js +355 -0
- package/lib/errors.js +8 -8
- package/lib/formats.js +972 -917
- package/lib/glossary.js +178 -178
- package/lib/html.js +271 -0
- package/lib/import-export.js +650 -605
- package/lib/libraries.js +183 -183
- package/lib/markdown.js +28 -28
- package/lib/mt.js +152 -152
- package/lib/persistence.js +341 -321
- package/lib/pptx.js +89 -89
- package/lib/preprocess.js +65 -0
- package/lib/segmenter.js +84 -84
- package/lib/similarity.js +113 -113
- package/lib/store-utils.js +342 -339
- package/lib/store.js +746 -734
- package/lib/tm.js +160 -160
- package/lib/tmx.js +85 -85
- package/lib/tools.js +472 -472
- package/lib/xlsx.js +218 -218
- package/lib/xml.js +31 -31
- package/locale/en.json +11 -11
- package/locale/zh.json +11 -11
- package/package.json +83 -83
- package/scripts/build-client.mjs +13 -13
package/client/rpc.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
class RpcError extends Error {
|
|
2
|
-
constructor(message, code) {
|
|
3
|
-
super(message)
|
|
4
|
-
this.name = 'RpcError'
|
|
5
|
-
this.code = code
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async function rpc(method, params = {}) {
|
|
10
|
-
let response
|
|
11
|
-
try {
|
|
12
|
-
response = await fetch(API, {
|
|
13
|
-
method: 'POST',
|
|
14
|
-
credentials: 'same-origin',
|
|
15
|
-
cache: 'no-store',
|
|
16
|
-
headers: { 'Content-Type': 'application/json' },
|
|
17
|
-
body: JSON.stringify({ method, params }),
|
|
18
|
-
})
|
|
19
|
-
} catch (error) {
|
|
20
|
-
throw new RpcError(`无法连接 CAIT 服务:${error?.message ?? error}`, 'NETWORK')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let payload = null
|
|
24
|
-
try {
|
|
25
|
-
payload = await response.json()
|
|
26
|
-
} catch {
|
|
27
|
-
payload = null
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!response.ok || !payload?.ok) {
|
|
31
|
-
const message = payload?.error?.message || `CAIT 服务返回 HTTP ${response.status}`
|
|
32
|
-
throw new RpcError(message, payload?.error?.code || 'HTTP')
|
|
33
|
-
}
|
|
34
|
-
return payload.data
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function escapeRegExp(value) {
|
|
38
|
-
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function formatBytes(bytes) {
|
|
42
|
-
if (!Number.isFinite(bytes)) return ''
|
|
43
|
-
if (bytes < 1024) return `${bytes} B`
|
|
44
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
|
|
45
|
-
return `${(bytes / 1024 / 1024).toFixed(1)} MB`
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function stripExtension(name) {
|
|
49
|
-
return String(name || '').replace(/\.[^.]+$/, '')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function filePayload(file) {
|
|
53
|
-
const extension = (file.name.match(/\.([a-z0-9]+)$/i)?.[1] || '').toLowerCase()
|
|
54
|
-
if (extension === 'docx' || extension === 'xlsx' || extension === 'pptx') {
|
|
55
|
-
return file.arrayBuffer().then((buffer) => {
|
|
56
|
-
const bytes = new Uint8Array(buffer)
|
|
57
|
-
let binary = ''
|
|
58
|
-
const chunk = 0x8000
|
|
59
|
-
for (let offset = 0; offset < bytes.length; offset += chunk) {
|
|
60
|
-
binary += String.fromCharCode.apply(null, bytes.subarray(offset, offset + chunk))
|
|
61
|
-
}
|
|
62
|
-
return { name: file.name, base64: btoa(binary) }
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
return file.text().then((text) => ({ name: file.name, text }))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function downloadFile(filename, content, mime) {
|
|
69
|
-
const blob = new Blob([content], { type: mime || 'application/octet-stream' })
|
|
70
|
-
const url = URL.createObjectURL(blob)
|
|
71
|
-
const link = document.createElement('a')
|
|
72
|
-
link.href = url
|
|
73
|
-
link.download = filename || 'cait-export'
|
|
74
|
-
link.rel = 'noopener'
|
|
75
|
-
document.body.appendChild(link)
|
|
76
|
-
link.click()
|
|
77
|
-
link.remove()
|
|
78
|
-
setTimeout(() => URL.revokeObjectURL(url), 2000)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function decodeBase64(value) {
|
|
82
|
-
const binary = atob(String(value ?? ''))
|
|
83
|
-
const bytes = new Uint8Array(binary.length)
|
|
84
|
-
for (let index = 0; index < binary.length; index += 1) {
|
|
85
|
-
bytes[index] = binary.charCodeAt(index)
|
|
86
|
-
}
|
|
87
|
-
return bytes
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async function copyText(value) {
|
|
91
|
-
if (!navigator.clipboard?.writeText) throw new Error('当前环境不支持剪贴板。')
|
|
92
|
-
await navigator.clipboard.writeText(value)
|
|
93
|
-
}
|
|
1
|
+
class RpcError extends Error {
|
|
2
|
+
constructor(message, code) {
|
|
3
|
+
super(message)
|
|
4
|
+
this.name = 'RpcError'
|
|
5
|
+
this.code = code
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function rpc(method, params = {}) {
|
|
10
|
+
let response
|
|
11
|
+
try {
|
|
12
|
+
response = await fetch(API, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
credentials: 'same-origin',
|
|
15
|
+
cache: 'no-store',
|
|
16
|
+
headers: { 'Content-Type': 'application/json' },
|
|
17
|
+
body: JSON.stringify({ method, params }),
|
|
18
|
+
})
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw new RpcError(`无法连接 CAIT 服务:${error?.message ?? error}`, 'NETWORK')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let payload = null
|
|
24
|
+
try {
|
|
25
|
+
payload = await response.json()
|
|
26
|
+
} catch {
|
|
27
|
+
payload = null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!response.ok || !payload?.ok) {
|
|
31
|
+
const message = payload?.error?.message || `CAIT 服务返回 HTTP ${response.status}`
|
|
32
|
+
throw new RpcError(message, payload?.error?.code || 'HTTP')
|
|
33
|
+
}
|
|
34
|
+
return payload.data
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function escapeRegExp(value) {
|
|
38
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function formatBytes(bytes) {
|
|
42
|
+
if (!Number.isFinite(bytes)) return ''
|
|
43
|
+
if (bytes < 1024) return `${bytes} B`
|
|
44
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
|
|
45
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function stripExtension(name) {
|
|
49
|
+
return String(name || '').replace(/\.[^.]+$/, '')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function filePayload(file) {
|
|
53
|
+
const extension = (file.name.match(/\.([a-z0-9]+)$/i)?.[1] || '').toLowerCase()
|
|
54
|
+
if (extension === 'docx' || extension === 'xlsx' || extension === 'pptx' || extension === 'epub') {
|
|
55
|
+
return file.arrayBuffer().then((buffer) => {
|
|
56
|
+
const bytes = new Uint8Array(buffer)
|
|
57
|
+
let binary = ''
|
|
58
|
+
const chunk = 0x8000
|
|
59
|
+
for (let offset = 0; offset < bytes.length; offset += chunk) {
|
|
60
|
+
binary += String.fromCharCode.apply(null, bytes.subarray(offset, offset + chunk))
|
|
61
|
+
}
|
|
62
|
+
return { name: file.name, base64: btoa(binary) }
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
return file.text().then((text) => ({ name: file.name, text }))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function downloadFile(filename, content, mime) {
|
|
69
|
+
const blob = new Blob([content], { type: mime || 'application/octet-stream' })
|
|
70
|
+
const url = URL.createObjectURL(blob)
|
|
71
|
+
const link = document.createElement('a')
|
|
72
|
+
link.href = url
|
|
73
|
+
link.download = filename || 'cait-export'
|
|
74
|
+
link.rel = 'noopener'
|
|
75
|
+
document.body.appendChild(link)
|
|
76
|
+
link.click()
|
|
77
|
+
link.remove()
|
|
78
|
+
setTimeout(() => URL.revokeObjectURL(url), 2000)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function decodeBase64(value) {
|
|
82
|
+
const binary = atob(String(value ?? ''))
|
|
83
|
+
const bytes = new Uint8Array(binary.length)
|
|
84
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
85
|
+
bytes[index] = binary.charCodeAt(index)
|
|
86
|
+
}
|
|
87
|
+
return bytes
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function copyText(value) {
|
|
91
|
+
if (!navigator.clipboard?.writeText) throw new Error('当前环境不支持剪贴板。')
|
|
92
|
+
await navigator.clipboard.writeText(value)
|
|
93
|
+
}
|