@8btc/mditor 0.0.37 → 0.0.39
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/dist/index.css +2 -2
- package/dist/index.js +19 -19
- package/dist/index.min.js +1 -1
- package/dist/js/mathjax/tex-svg-full.js +89129 -1
- package/dist/method.js +19 -19
- package/dist/method.min.js +1 -1
- package/dist/ts/markdown/mathRender.d.ts +0 -5
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/ts/markdown/mathContextMenu.ts +27 -17
- package/src/ts/markdown/mathRender.ts +12 -18
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -174,8 +174,8 @@ class MathContextMenu {
|
|
|
174
174
|
displayMode: display,
|
|
175
175
|
output: "mathml",
|
|
176
176
|
});
|
|
177
|
-
} else if ((window as any).
|
|
178
|
-
mml = (window as any).
|
|
177
|
+
} else if ((window as any).VditorMathJax?.tex2mml) {
|
|
178
|
+
mml = (window as any).VditorMathJax.tex2mml(tex, {
|
|
179
179
|
display,
|
|
180
180
|
});
|
|
181
181
|
}
|
|
@@ -224,7 +224,7 @@ class MathContextMenu {
|
|
|
224
224
|
* - 不存在:按需加载 `/js/mathjax/tex-svg-full.js`,加载完成后返回 MathJax
|
|
225
225
|
*/
|
|
226
226
|
private async ensureMathJaxSvg(): Promise<any> {
|
|
227
|
-
const MJ = (window as any).
|
|
227
|
+
const MJ = (window as any).VditorMathJax;
|
|
228
228
|
if (MJ?.tex2svg) {
|
|
229
229
|
return MJ;
|
|
230
230
|
}
|
|
@@ -232,7 +232,7 @@ class MathContextMenu {
|
|
|
232
232
|
`/js/mathjax/tex-svg-full.js`,
|
|
233
233
|
"protyleMathJaxSvgScript"
|
|
234
234
|
);
|
|
235
|
-
return (window as any).
|
|
235
|
+
return (window as any).VditorMathJax;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
/**
|
|
@@ -353,7 +353,9 @@ export const bindMathContextMenu = (mathEl: HTMLElement): void => {
|
|
|
353
353
|
* - 在预览模式或分屏预览(SV)模式下禁用自定义右键
|
|
354
354
|
* - 避免重复绑定:通过 data-context-menu 标记
|
|
355
355
|
*/
|
|
356
|
-
const inPreview = !!(
|
|
356
|
+
const inPreview = !!(
|
|
357
|
+
mathEl.closest(".vditor-preview") || mathEl.closest(".vditor-sv")
|
|
358
|
+
);
|
|
357
359
|
if (inPreview) {
|
|
358
360
|
return;
|
|
359
361
|
}
|
|
@@ -361,16 +363,20 @@ export const bindMathContextMenu = (mathEl: HTMLElement): void => {
|
|
|
361
363
|
return;
|
|
362
364
|
}
|
|
363
365
|
menu.init();
|
|
364
|
-
mathEl.addEventListener(
|
|
365
|
-
|
|
366
|
-
e
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
366
|
+
mathEl.addEventListener(
|
|
367
|
+
"contextmenu",
|
|
368
|
+
(e: MouseEvent) => {
|
|
369
|
+
e.preventDefault();
|
|
370
|
+
e.stopPropagation();
|
|
371
|
+
if (typeof (e as any).stopImmediatePropagation === "function") {
|
|
372
|
+
(e as any).stopImmediatePropagation();
|
|
373
|
+
}
|
|
374
|
+
const x = e.clientX;
|
|
375
|
+
const y = e.clientY;
|
|
376
|
+
menu.show(x, y, mathEl);
|
|
377
|
+
},
|
|
378
|
+
{ capture: true }
|
|
379
|
+
);
|
|
374
380
|
mathEl.setAttribute("data-context-menu", "true");
|
|
375
381
|
};
|
|
376
382
|
|
|
@@ -411,11 +417,15 @@ export const bindMathCopyInterceptor = (mathEl: HTMLElement): void => {
|
|
|
411
417
|
* - 自动避免重复绑定
|
|
412
418
|
* @param container 扫描范围容器(例如 vditor.ir.element 或 vditor.wysiwyg.element)
|
|
413
419
|
*/
|
|
414
|
-
export const bindMathInteractionsInContainer = (
|
|
420
|
+
export const bindMathInteractionsInContainer = (
|
|
421
|
+
container: HTMLElement
|
|
422
|
+
): void => {
|
|
415
423
|
const nodes = container.querySelectorAll(".language-math");
|
|
416
424
|
nodes.forEach((el) => {
|
|
417
425
|
const mathEl = el as HTMLElement;
|
|
418
|
-
const inPreview = !!(
|
|
426
|
+
const inPreview = !!(
|
|
427
|
+
mathEl.closest(".vditor-preview") || mathEl.closest(".vditor-sv")
|
|
428
|
+
);
|
|
419
429
|
if (inPreview) return;
|
|
420
430
|
bindMathContextMenu(mathEl);
|
|
421
431
|
bindMathCopyInterceptor(mathEl);
|
|
@@ -16,12 +16,6 @@ declare const katex: {
|
|
|
16
16
|
): string;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
declare global {
|
|
20
|
-
interface Window {
|
|
21
|
-
MathJax: any;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
19
|
/**
|
|
26
20
|
* 规范化 TeX 字符串,避免因控制序列与后续字母粘连导致解析失败。
|
|
27
21
|
* 例如 "\\vdotsa" 会被视作未知命令,将其修正为 "\\vdots{}a"。
|
|
@@ -70,7 +64,7 @@ export const mathRender = (
|
|
|
70
64
|
const defaultOptions = {
|
|
71
65
|
cdn: Constants.CDN,
|
|
72
66
|
math: {
|
|
73
|
-
engine: "
|
|
67
|
+
engine: "KaTeX",
|
|
74
68
|
inlineDigit: true,
|
|
75
69
|
macros: {},
|
|
76
70
|
},
|
|
@@ -179,21 +173,21 @@ export const mathRender = (
|
|
|
179
173
|
};
|
|
180
174
|
next();
|
|
181
175
|
};
|
|
182
|
-
if (!window.
|
|
183
|
-
window.
|
|
176
|
+
if (!window.VditorMathJax) {
|
|
177
|
+
window.VditorMathJax = {
|
|
184
178
|
loader: {
|
|
185
179
|
paths: { mathjax: `${options.cdn}/dist/js/mathjax` },
|
|
186
180
|
},
|
|
187
181
|
startup: {
|
|
188
182
|
typeset: false,
|
|
189
|
-
|
|
183
|
+
elements: element instanceof HTMLElement ? [element] : [],
|
|
190
184
|
},
|
|
191
185
|
tex: {
|
|
192
186
|
macros: options.math.macros,
|
|
193
187
|
},
|
|
194
188
|
};
|
|
195
189
|
// https://github.com/Vanessa219/vditor/issues/1453 额外配置(packages、inlineMath、displayMath 等)由调用方通过 mathJaxOptions 传入
|
|
196
|
-
Object.assign(window.
|
|
190
|
+
Object.assign(window.VditorMathJax, options.math.mathJaxOptions);
|
|
197
191
|
}
|
|
198
192
|
addScriptSync(
|
|
199
193
|
`${options.cdn}/dist/js/mathjax/tex-svg-full.js`,
|
|
@@ -205,9 +199,9 @@ export const mathRender = (
|
|
|
205
199
|
const inPreviewPre =
|
|
206
200
|
mathElement.parentElement &&
|
|
207
201
|
mathElement.parentElement.tagName === "PRE";
|
|
208
|
-
const mathOptions = window.
|
|
202
|
+
const mathOptions = window.VditorMathJax.getMetricsFor(mathElement);
|
|
209
203
|
mathOptions.display = inPreviewPre || mathElement.tagName === "DIV";
|
|
210
|
-
window.
|
|
204
|
+
window.VditorMathJax.tex2svgPromise(math, mathOptions).then(
|
|
211
205
|
(node: Element) => {
|
|
212
206
|
mathElement.innerHTML = "";
|
|
213
207
|
mathElement.setAttribute("data-math", math);
|
|
@@ -217,7 +211,7 @@ export const mathRender = (
|
|
|
217
211
|
pre.classList.add("vditor-wysiwyg__preview--math");
|
|
218
212
|
}
|
|
219
213
|
bindMathContextMenu(mathElement as HTMLElement);
|
|
220
|
-
const startup = window.
|
|
214
|
+
const startup = window.VditorMathJax.startup;
|
|
221
215
|
const prevElements = startup.elements;
|
|
222
216
|
if (element instanceof HTMLElement) {
|
|
223
217
|
startup.elements = [element];
|
|
@@ -244,10 +238,10 @@ export const mathRender = (
|
|
|
244
238
|
}
|
|
245
239
|
);
|
|
246
240
|
};
|
|
247
|
-
window.
|
|
248
|
-
if (window.
|
|
249
|
-
window.
|
|
250
|
-
window.
|
|
241
|
+
window.VditorMathJax.startup.promise.then(() => {
|
|
242
|
+
if (window.VditorMathJax.startup) {
|
|
243
|
+
window.VditorMathJax.startup.typeset = true;
|
|
244
|
+
window.VditorMathJax.startup.elements =
|
|
251
245
|
element instanceof HTMLElement ? [element] : [];
|
|
252
246
|
}
|
|
253
247
|
const chains: any[] = [];
|