dsh-latex-formula-editor 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.en.md ADDED
@@ -0,0 +1,38 @@
1
+ # dsh-latex-formula-editor
2
+
3
+ > A LaTeX formula editor for the DSH sidebar: offline rendering, tile-based symbol input, formula templates, favourites, image/document OCR, multi-format export and sharing.
4
+
5
+ ![Plugin UI](docs/img/editor.png)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ git clone https://github.com/jiahui-huang1/dsh-latex-formula-editor.git
11
+ pnpm dsh plugin add ./dsh-latex-formula-editor
12
+ ```
13
+
14
+ Enable **LaTeX Formula Editor** in the DSH sidebar (entry id `latex-editor`).
15
+
16
+ ## Features
17
+
18
+ - **Quick tools** — ten tiles (common symbols, Greek, fractions/calculus, roots, limits & logs, trigonometry, integrals, large operators, brackets, matrices); hover to expand the grouped symbol panel, click to insert.
19
+ - **Templates** — algebra, geometry, inequalities, integrals, matrices, trigonometry, statistics, sequences, physics, chemistry.
20
+ - **Format row** — colour picker, rendered font menu, rendered size menu, environment wrapper (align/aligned/gathered/cases/split/array/eqnarray/none), clear, undo, import, favourite.
21
+ - **Export** — images (SVG/PNG/JPG), code (LaTeX/AsciiMath/Typst/SVG Code/HTML inline & display/MathML variants/OMML), escaping (backslash, `$…$`, `$$…$$`, `\(…\)`, `\[…\]`, JSON) and share links.
22
+ - **Favourites** — title, timestamp, render and source per entry; rename, copy, delete, insert; searchable; configurable cap (10 by default).
23
+ - **Recognition** — image OCR (drag & paste) and document OCR (page by page, download as Word/LaTeX/Markdown, results kept for 15 days).
24
+ - **UI** — 150% default scale, light/dark theme, 简体中文 / 繁體中文 / English.
25
+
26
+ ![Document OCR](docs/img/doc-ocr.png)
27
+
28
+ ## Settings
29
+
30
+ Settings → OCR service: use the Harness model or an OpenAI-compatible endpoint. Rendering and export are fully offline; only OCR sends an image.
31
+
32
+ ## Requirements
33
+
34
+ DSH ≥ 1.0 (`dsh.bundle.patch` + `dsh.client`). No build step; MathJax 3 and PDF.js ship with the plugin.
35
+
36
+ ## Licence
37
+
38
+ MIT
package/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # dsh-latex-formula-editor
2
+
3
+ > LaTeX 公式编辑器 —— DSH 侧栏插件:离线渲染、磁贴取符号、公式模板、收藏夹、图片/文档识别、多格式导出与分享。
4
+
5
+ ![插件界面](docs/img/editor.png)
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ # 1. 取仓库
11
+ git clone https://github.com/jiahui-huang1/dsh-latex-formula-editor.git
12
+ # 2. 以本地插件方式安装(DSH 会自动读取 package.json 里的 dsh.bundle.patch / dsh.client)
13
+ pnpm dsh plugin add ./dsh-latex-formula-editor
14
+ ```
15
+
16
+ 安装后在 DSH 左侧栏启用 **公式编辑器**(入口 id `latex-editor`)。
17
+
18
+ ## 功能
19
+
20
+ - **快捷工具**:常用符号 / 希腊字母 / 分数微分 / 根式角标 / 极限对数 / 三角函数 / 积分运算 / 大型运算 / 括号取整 / 数组矩阵,悬停磁贴展开分组符号面板,点击插入光标处
21
+ - **公式模板**:代数 / 几何 / 不等式 / 积分 / 矩阵 / 三角 / 统计 / 数列 / 物理 / 化学,展开即可整条插入
22
+ - **格式行**:取色器、真实字体预览、真实字号预览、环境包裹(align / aligned / gathered / cases / split / array / eqnarray / 无环境)、清空、撤销、导入、收藏
23
+ - **输出**:输出图片(SVG / PNG / JPG)、输出代码(LaTeX / AsciiMath / Typst / SVG Code / HTML 内联与独立 / MathML / MathML mml: / m: / attr: / OMML)、转义(反斜杠、`$…$`、`$$…$$`、`\(…\)`、`\[…\]`、JSON)、分享链接
24
+ - **收藏夹**:标题、时间、渲染结果、源码;可改名 / 复制 / 删除 / 插入;按标题或源码搜索;上限可配(默认 10)
25
+ - **识别**:图片识别(拖拽 / 粘贴)、文档识别(逐页 OCR,支持下载 Word / LaTeX / Markdown,最近 15 天记录可重新下载)
26
+ - **界面**:默认 150% 缩放、浅色/深色主题、简体中文 / 繁體中文 / English
27
+
28
+ ![文档识别](docs/img/doc-ocr.png)
29
+
30
+ ## 配置
31
+
32
+ 设置 → 识别服务:可选 Harness 内置模型或自建 OpenAI 兼容端点;渲染与导出完全离线,仅识别会发送图片。
33
+
34
+ ## 兼容性
35
+
36
+ - DSH ≥ 1.0(Cordis 插件规范:`dsh.bundle.patch` + `dsh.client`)
37
+ - 浏览器侧无构建步骤,MathJax 3 与 PDF.js 已随插件内置
38
+
39
+ ## 许可
40
+
41
+ MIT
package/README.zh.md ADDED
@@ -0,0 +1,41 @@
1
+ # dsh-latex-formula-editor
2
+
3
+ > LaTeX 公式编辑器 —— DSH 侧栏插件:离线渲染、磁贴取符号、公式模板、收藏夹、图片/文档识别、多格式导出与分享。
4
+
5
+ ![插件界面](docs/img/editor.png)
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ # 1. 取仓库
11
+ git clone https://github.com/jiahui-huang1/dsh-latex-formula-editor.git
12
+ # 2. 以本地插件方式安装(DSH 会自动读取 package.json 里的 dsh.bundle.patch / dsh.client)
13
+ pnpm dsh plugin add ./dsh-latex-formula-editor
14
+ ```
15
+
16
+ 安装后在 DSH 左侧栏启用 **公式编辑器**(入口 id `latex-editor`)。
17
+
18
+ ## 功能
19
+
20
+ - **快捷工具**:常用符号 / 希腊字母 / 分数微分 / 根式角标 / 极限对数 / 三角函数 / 积分运算 / 大型运算 / 括号取整 / 数组矩阵,悬停磁贴展开分组符号面板,点击插入光标处
21
+ - **公式模板**:代数 / 几何 / 不等式 / 积分 / 矩阵 / 三角 / 统计 / 数列 / 物理 / 化学,展开即可整条插入
22
+ - **格式行**:取色器、真实字体预览、真实字号预览、环境包裹(align / aligned / gathered / cases / split / array / eqnarray / 无环境)、清空、撤销、导入、收藏
23
+ - **输出**:输出图片(SVG / PNG / JPG)、输出代码(LaTeX / AsciiMath / Typst / SVG Code / HTML 内联与独立 / MathML / MathML mml: / m: / attr: / OMML)、转义(反斜杠、`$…$`、`$$…$$`、`\(…\)`、`\[…\]`、JSON)、分享链接
24
+ - **收藏夹**:标题、时间、渲染结果、源码;可改名 / 复制 / 删除 / 插入;按标题或源码搜索;上限可配(默认 10)
25
+ - **识别**:图片识别(拖拽 / 粘贴)、文档识别(逐页 OCR,支持下载 Word / LaTeX / Markdown,最近 15 天记录可重新下载)
26
+ - **界面**:默认 150% 缩放、浅色/深色主题、简体中文 / 繁體中文 / English
27
+
28
+ ![文档识别](docs/img/doc-ocr.png)
29
+
30
+ ## 配置
31
+
32
+ 设置 → 识别服务:可选 Harness 内置模型或自建 OpenAI 兼容端点;渲染与导出完全离线,仅识别会发送图片。
33
+
34
+ ## 兼容性
35
+
36
+ - DSH ≥ 1.0(Cordis 插件规范:`dsh.bundle.patch` + `dsh.client`)
37
+ - 浏览器侧无构建步骤,MathJax 3 与 PDF.js 已随插件内置
38
+
39
+ ## 许可
40
+
41
+ MIT
package/client.js ADDED
@@ -0,0 +1,210 @@
1
+ /**
2
+ * @local/dsh-latex-editor — Client entry.
3
+ *
4
+ * The bundle's `dsh.client` declaration loads this file as the browser half. It
5
+ * - loads the workbench modules from the Host (`/plugins/latex-editor/lib/*.js`,
6
+ * in filename order, cached for the page lifetime),
7
+ * - registers the merged zh/en dictionaries with the harness locale service,
8
+ * - registers the left-column entry (`sidebar.panellist`) and the panel it opens
9
+ * (`main`, keyed by the same id).
10
+ */
11
+ window.__ModuleLoader__.load({
12
+ id: '@local/dsh-latex-editor',
13
+ factory(require) {
14
+ const React = require('react')
15
+ const h = React.createElement
16
+ const { useEffect, useState } = React
17
+
18
+ window.__LX_REACT__ = React
19
+
20
+ const NS = 'latex-editor'
21
+ const ASSET = '/plugins/latex-editor/lib/'
22
+ const MODULES = ['00-core', '10-latex', '20-render', '30-visual', '35-tiles', '40-recognition', '45-convert', '50-app', '56-recognition-panels', '60-settings-help', '90-skin']
23
+ const NAV_LABEL = { zh: '公式编辑器', en: 'Formula Editor' }
24
+
25
+ const MARK_PATH =
26
+ 'M643.015111 128c9.557333 0 18.773333 3.811556 25.486222 10.581333l0.398223 0.398223 88.974222 91.989333a36.010667 36.010667 0 0 1-51.313778 50.460444l-0.455111-0.398222-78.392889-81.009778H167.025778l196.835555 293.432889a36.010667 36.010667 0 0 1 0.227556 39.822222l-0.284445 0.455112-196.892444 290.247111h460.8l78.392889-81.009778a36.010667 36.010667 0 0 1 50.517333-1.251556l0.398222 0.398223c14.165333 13.653333 14.677333 36.181333 1.251556 50.460444l-0.398222 0.455111-88.974222 91.989333a36.010667 36.010667 0 0 1-25.372445 10.979556H98.986667a36.010667 36.010667 0 0 1-30.264889-55.466667l0.512-0.739555 221.297778-326.428445-220.899556-329.329777a36.010667 36.010667 0 0 1 29.013333-56.035556h544.369778z m306.460445 262.542222c13.880889 13.937778 14.051556 36.408889 0.398222 50.517334L878.876444 512l70.542223 70.542222a36.010667 36.010667 0 0 1-50.460445 51.313778l-0.398222-0.398222-70.542222-70.599111-70.542222 70.599111a36.010667 36.010667 0 0 1-51.370667-50.517334L777.102222 512l-70.542222-70.542222a36.010667 36.010667 0 0 1 50.460444-51.313778l70.940445 70.940444 70.542222-70.542222a36.010667 36.010667 0 0 1 50.972445 0z'
27
+
28
+
29
+ const loaded = new Map()
30
+ let chain = null
31
+
32
+ function loadOne(name) {
33
+ const src = ASSET + name + '.js'
34
+ const cached = loaded.get(src)
35
+ if (cached) return cached
36
+ const promise = new Promise(function (resolve, reject) {
37
+ const script = document.createElement('script')
38
+ script.src = src
39
+ script.async = true
40
+ script.onload = function () {
41
+ resolve(true)
42
+ }
43
+ script.onerror = function () {
44
+ loaded.delete(src)
45
+ reject(new Error('failed to load ' + src))
46
+ }
47
+ document.head.appendChild(script)
48
+ })
49
+ loaded.set(src, promise)
50
+ return promise
51
+ }
52
+
53
+ /** Resolves once every workbench module has executed. Idempotent. */
54
+ function loadWorkbench() {
55
+ if (chain === null) {
56
+ chain = MODULES.reduce(function (previous, name) {
57
+ return previous.then(function () {
58
+ return loadOne(name).catch(function (error) {
59
+ /* A missing optional module degrades one feature, not the panel. */
60
+ if (name === '00-core') throw error
61
+ console.error('[latex-editor] module ' + name + ' did not load', error)
62
+ })
63
+ })
64
+ }, Promise.resolve())
65
+ chain.catch(function () {
66
+ chain = null
67
+ })
68
+ }
69
+ return chain
70
+ }
71
+
72
+ function guessLanguage() {
73
+ const raw = (document.documentElement.getAttribute('lang') || navigator.language || 'en').toLowerCase()
74
+ return raw.startsWith('zh') ? 'zh' : 'en'
75
+ }
76
+
77
+ function navLabel() {
78
+ const LX = window.__LX
79
+ if (LX && LX.t) {
80
+ const text = LX.t('nav.label')
81
+ if (text && text !== 'nav.label') return text
82
+ }
83
+ return NAV_LABEL[guessLanguage()]
84
+ }
85
+
86
+ /* -------------------------------------------------------- sidebar icon */
87
+
88
+ function NavIcon(props) {
89
+ const size = (props && props.size) || 20
90
+ return h(
91
+ 'svg',
92
+ {
93
+ viewBox: '0 0 1024 1024',
94
+ width: size,
95
+ height: size,
96
+ fill: 'currentColor',
97
+ 'aria-hidden': true,
98
+ focusable: false,
99
+ style: { display: 'block' },
100
+ },
101
+ h('path', { d: MARK_PATH }),
102
+ )
103
+ }
104
+
105
+ /* ----------------------------------------------------------- panel body */
106
+
107
+ function Skeleton(props) {
108
+ const text = props.error ? props.error : NAV_LABEL[guessLanguage()] + '…'
109
+ return h(
110
+ 'div',
111
+ {
112
+ style: {
113
+ display: 'flex',
114
+ flexDirection: 'column',
115
+ alignItems: 'center',
116
+ justifyContent: 'center',
117
+ gap: 10,
118
+ height: '100%',
119
+ minHeight: 240,
120
+ color: 'var(--dsw-alias-label-secondary)',
121
+ fontSize: 13,
122
+ padding: 24,
123
+ textAlign: 'center',
124
+ },
125
+ },
126
+ props.error ? null : h('span', { className: 'lx-spinner', style: { width: 18, height: 18, borderWidth: 2 } }),
127
+ h('span', null, text),
128
+ )
129
+ }
130
+
131
+ function WorkbenchPanel() {
132
+ const [state, setState] = useState({ ready: false, error: null })
133
+
134
+ useEffect(function () {
135
+ let alive = true
136
+ loadWorkbench().then(
137
+ function () {
138
+ if (alive) setState({ ready: true, error: null })
139
+ },
140
+ function (error) {
141
+ if (alive) setState({ ready: false, error: String((error && error.message) || error) })
142
+ },
143
+ )
144
+ return function () {
145
+ alive = false
146
+ }
147
+ }, [])
148
+
149
+ if (state.error) return h(Skeleton, { error: state.error })
150
+ const LX = window.__LX
151
+ if (!state.ready || !LX || !LX.app || typeof LX.app.Workbench !== 'function') return h(Skeleton, {})
152
+ return h(LX.app.Workbench)
153
+ }
154
+
155
+ return {
156
+ inject: ['slots', 'locale'],
157
+ apply: function apply(ctx) {
158
+ let disposed = false
159
+
160
+ const ready = loadWorkbench()
161
+ ctx.effect(
162
+ function () {
163
+ disposed = false
164
+ ready
165
+ .then(function () {
166
+ if (disposed) return
167
+ const LX = window.__LX
168
+ if (!LX) return
169
+ ctx.locale.register(NS, { zh: LX.dicts.zh, en: LX.dicts.en })
170
+ LX.setTranslator(ctx.locale.bind(NS))
171
+ LX.setLanguage(LX.lang())
172
+ })
173
+ .catch(function (error) {
174
+ console.error('[latex-editor] workbench modules failed to load', error)
175
+ })
176
+ return function () {
177
+ disposed = true
178
+ }
179
+ },
180
+ 'latex-editor: locale dictionaries',
181
+ )
182
+
183
+ ctx.effect(
184
+ function () {
185
+ return ctx.slots.inject('sidebar.panellist', function () {
186
+ return ctx.slots.register(
187
+ { name: 'sidebar.panellist', id: 'latex-editor', order: 16, label: navLabel, locale: NS },
188
+ function (props) {
189
+ return h(NavIcon, { size: props && props.size })
190
+ },
191
+ )
192
+ })
193
+ },
194
+ 'latex-editor: sidebar entry',
195
+ )
196
+
197
+ ctx.effect(
198
+ function () {
199
+ return ctx.slots.inject('main', function () {
200
+ return ctx.slots.register({ name: 'main', key: 'latex-editor', locale: NS }, function () {
201
+ return h(WorkbenchPanel)
202
+ })
203
+ })
204
+ },
205
+ 'latex-editor: main panel',
206
+ )
207
+ },
208
+ }
209
+ },
210
+ })
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/icon.svg ADDED
@@ -0,0 +1,6 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" width="32" height="32" role="img" aria-label="LaTeX formula workbench">
2
+ <rect width="1024" height="1024" rx="232" fill="#2563eb"/>
3
+ <g>
4
+ <path d="M643.015111 128c9.557333 0 18.773333 3.811556 25.486222 10.581333l0.398223 0.398223 88.974222 91.989333a36.010667 36.010667 0 0 1-51.313778 50.460444l-0.455111-0.398222-78.392889-81.009778H167.025778l196.835555 293.432889a36.010667 36.010667 0 0 1 0.227556 39.822222l-0.284445 0.455112-196.892444 290.247111h460.8l78.392889-81.009778a36.010667 36.010667 0 0 1 50.517333-1.251556l0.398222 0.398223c14.165333 13.653333 14.677333 36.181333 1.251556 50.460444l-0.398222 0.455111-88.974222 91.989333a36.010667 36.010667 0 0 1-25.372445 10.979556H98.986667a36.010667 36.010667 0 0 1-30.264889-55.466667l0.512-0.739555 221.297778-326.428445-220.899556-329.329777a36.010667 36.010667 0 0 1 29.013333-56.035556h544.369778z m306.460445 262.542222c13.880889 13.937778 14.051556 36.408889 0.398222 50.517334L878.876444 512l70.542223 70.542222a36.010667 36.010667 0 0 1-50.460445 51.313778l-0.398222-0.398222-70.542222-70.599111-70.542222 70.599111a36.010667 36.010667 0 0 1-51.370667-50.517334L777.102222 512l-70.542222-70.542222a36.010667 36.010667 0 0 1 50.460444-51.313778l70.940445 70.940444 70.542222-70.542222a36.010667 36.010667 0 0 1 50.972445 0z" fill="#ffffff"/>
5
+ </g>
6
+ </svg>