@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.
@@ -1,8 +1,3 @@
1
- declare global {
2
- interface Window {
3
- MathJax: any;
4
- }
5
- }
6
1
  /**
7
2
  * 数学公式渲染入口
8
3
  *
@@ -17,6 +17,7 @@ type TWYSISYGToolbar =
17
17
  | "block";
18
18
 
19
19
  interface Window {
20
+ VditorMathJax?: any;
20
21
  VditorI18n: ITips;
21
22
  hljs: {
22
23
  listLanguages(): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8btc/mditor",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "description": "mditor, Md编辑器",
5
5
  "author": "wujie-vditor",
6
6
  "jsdelivr": "dist/index.min.js",
@@ -174,8 +174,8 @@ class MathContextMenu {
174
174
  displayMode: display,
175
175
  output: "mathml",
176
176
  });
177
- } else if ((window as any).MathJax?.tex2mml) {
178
- mml = (window as any).MathJax.tex2mml(tex, {
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).MathJax;
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).MathJax;
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 = !!(mathEl.closest(".vditor-preview") || mathEl.closest(".vditor-sv"));
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("contextmenu", (e: MouseEvent) => {
365
- e.preventDefault();
366
- e.stopPropagation();
367
- if (typeof (e as any).stopImmediatePropagation === "function") {
368
- (e as any).stopImmediatePropagation();
369
- }
370
- const x = e.clientX;
371
- const y = e.clientY;
372
- menu.show(x, y, mathEl);
373
- }, { capture: true });
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 = (container: HTMLElement): void => {
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 = !!(mathEl.closest(".vditor-preview") || mathEl.closest(".vditor-sv"));
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: "MathJax",
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.MathJax) {
183
- window.MathJax = {
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
- // elements: element instanceof HTMLElement ? [element] : [],
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.MathJax, options.math.mathJaxOptions);
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.MathJax.getMetricsFor(mathElement);
202
+ const mathOptions = window.VditorMathJax.getMetricsFor(mathElement);
209
203
  mathOptions.display = inPreviewPre || mathElement.tagName === "DIV";
210
- window.MathJax.tex2svgPromise(math, mathOptions).then(
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.MathJax.startup;
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.MathJax.startup.promise.then(() => {
248
- if (window.MathJax.startup) {
249
- window.MathJax.startup.typeset = true;
250
- window.MathJax.startup.elements =
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[] = [];