@8btc/mditor 0.0.32 → 0.0.34

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/method.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.32 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.34 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -45,7 +45,7 @@ return /******/ (() => { // webpackBootstrap
45
45
  /* harmony export */ "g": () => (/* binding */ Constants)
46
46
  /* harmony export */ });
47
47
  /* unused harmony export VDITOR_VERSION */
48
- var _VDITOR_VERSION = (/* unused pure expression or super */ null && ("0.0.32"));
48
+ var _VDITOR_VERSION = (/* unused pure expression or super */ null && ("0.0.34"));
49
49
 
50
50
  var Constants = /** @class */ (function () {
51
51
  function Constants() {
@@ -347,7 +347,7 @@ var Constants = /** @class */ (function () {
347
347
  "c#",
348
348
  "bat",
349
349
  ];
350
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.32");
350
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.34");
351
351
  Constants.MARKDOWN_OPTIONS = {
352
352
  autoSpace: false,
353
353
  gfmAutoLink: true,
@@ -2581,8 +2581,8 @@ var normalizeTex = function (tex) {
2581
2581
  /**
2582
2582
  * 数学公式渲染入口
2583
2583
  *
2584
- * 默认使用 MathJax 渲染(SVG 输出),并在需要时按需加载相关脚本与样式。
2585
- * 支持通过 options.math.engine 切换为 KaTeX
2584
+ * 默认使用 KaTeX 渲染,并在需要时按需加载相关脚本与样式。
2585
+ * 支持通过 options.math.engine 切换为 MathJax
2586
2586
  *
2587
2587
  * 参数说明:
2588
2588
  * - element: 需要进行数学渲染的根容器(默认 document)
@@ -2597,7 +2597,7 @@ var mathRender = function (element, options) {
2597
2597
  var defaultOptions = {
2598
2598
  cdn: _constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants.CDN */ .g.CDN,
2599
2599
  math: {
2600
- engine: "MathJax",
2600
+ engine: "KaTeX",
2601
2601
  inlineDigit: true,
2602
2602
  macros: {},
2603
2603
  },
@@ -2669,80 +2669,22 @@ var mathRender = function (element, options) {
2669
2669
  next();
2670
2670
  };
2671
2671
  if (!window.MathJax) {
2672
- // typeset 设为 true 以正常完成公式渲染;elements 限定为传入的容器,外部使用本包时仅处理该容器,不影响编辑器以外的公式。
2673
- // 渲染时会将 startup.elements 临时设为传入的 element(当前预览/编辑容器),再 clear/updateDocument。
2674
2672
  window.MathJax = {
2675
2673
  loader: {
2676
2674
  paths: { mathjax: "".concat(options.cdn, "/dist/js/mathjax") },
2677
2675
  },
2678
2676
  startup: {
2679
- typeset: true,
2677
+ typeset: false,
2680
2678
  elements: element instanceof HTMLElement ? [element] : [],
2681
2679
  },
2682
2680
  tex: {
2683
- inlineMath: [
2684
- ["$", "$"],
2685
- ["\\(", "\\)"],
2686
- ],
2687
- displayMath: [
2688
- ["$$", "$$"],
2689
- ["\\[", "\\]"],
2690
- ],
2691
- processEscapes: true,
2692
2681
  macros: options.math.macros,
2693
- // 启用 ams 与 unicode,支持 \unicode 宏以渲染 ∯(oiint)
2694
- packages: { "[+]": ["ams", "unicode", "noerrors"] },
2695
- },
2696
- // 关闭 MathJax 自带右键菜单,使用自定义菜单
2697
- options: {
2698
- enableMenu: false,
2699
2682
  },
2700
2683
  };
2701
- // https://github.com/Vanessa219/vditor/issues/1453
2684
+ // https://github.com/Vanessa219/vditor/issues/1453 额外配置(packages、inlineMath、displayMath 等)由调用方通过 mathJaxOptions 传入
2702
2685
  Object.assign(window.MathJax, options.math.mathJaxOptions);
2703
2686
  }
2704
- var mathJaxScriptUrl = "".concat(options.cdn, "/dist/js/mathjax/tex-svg-full.js");
2705
- var mathJaxScriptId = "protyleMathJaxScript";
2706
- // Qt WebView 中同步 XHR 被限制,addScriptSync 无法加载脚本,改为异步 addScript
2707
- var isQtWebView_1 = typeof navigator !== "undefined" &&
2708
- /Qt|QtWebEngine/i.test(navigator.userAgent);
2709
- var runRenderChain = function () {
2710
- window.MathJax.startup.promise.then(function () {
2711
- if (window.MathJax.startup) {
2712
- window.MathJax.startup.typeset = true;
2713
- window.MathJax.startup.elements =
2714
- element instanceof HTMLElement ? [element] : [];
2715
- }
2716
- var chains = [];
2717
- var _loop_1 = function (i) {
2718
- var mathElement = mathElements[i];
2719
- if (!mathElement.parentElement.classList.contains("vditor-wysiwyg__pre") &&
2720
- !mathElement.parentElement.classList.contains("vditor-ir__marker--pre") &&
2721
- !mathElement.getAttribute("data-math") &&
2722
- (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_5__/* .code160to32 */ .X)(mathElement.textContent).trim()) {
2723
- chains.push(function (next) {
2724
- if (i === mathElements.length - 1) {
2725
- renderMath_1(mathElement);
2726
- }
2727
- else {
2728
- renderMath_1(mathElement, next);
2729
- }
2730
- });
2731
- }
2732
- };
2733
- for (var i = 0; i < mathElements.length; i++) {
2734
- _loop_1(i);
2735
- }
2736
- chainAsync_1(chains);
2737
- });
2738
- };
2739
- if (isQtWebView_1) {
2740
- (0,_util_addScript__WEBPACK_IMPORTED_MODULE_4__/* .addScript */ .G)(mathJaxScriptUrl, mathJaxScriptId).then(runRenderChain);
2741
- }
2742
- else {
2743
- (0,_util_addScript__WEBPACK_IMPORTED_MODULE_4__/* .addScriptSync */ .J)(mathJaxScriptUrl, mathJaxScriptId);
2744
- runRenderChain();
2745
- }
2687
+ (0,_util_addScript__WEBPACK_IMPORTED_MODULE_4__/* .addScriptSync */ .J)("".concat(options.cdn, "/dist/js/mathjax/tex-svg-full.js"), "protyleMathJaxScript");
2746
2688
  var renderMath_1 = function (mathElement, next) {
2747
2689
  var rawText = (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_5__/* .code160to32 */ .X)(mathElement.textContent).trim();
2748
2690
  var math = normalizeTex(rawText);
@@ -2751,7 +2693,6 @@ var mathRender = function (element, options) {
2751
2693
  var mathOptions = window.MathJax.getMetricsFor(mathElement);
2752
2694
  mathOptions.display = inPreviewPre || mathElement.tagName === "DIV";
2753
2695
  window.MathJax.tex2svgPromise(math, mathOptions).then(function (node) {
2754
- var _a, _b;
2755
2696
  mathElement.innerHTML = "";
2756
2697
  mathElement.setAttribute("data-math", math);
2757
2698
  mathElement.append(node);
@@ -2759,40 +2700,57 @@ var mathRender = function (element, options) {
2759
2700
  var pre = mathElement.parentElement;
2760
2701
  pre.classList.add("vditor-wysiwyg__preview--math");
2761
2702
  }
2762
- // 绑定自定义右键菜单(编辑区生效,预览区自动跳过)
2763
2703
  (0,_mathContextMenu__WEBPACK_IMPORTED_MODULE_2__/* .bindMathContextMenu */ .xX)(mathElement);
2764
- // 限定 document 范围为当前容器后再 clear/updateDocument,避免处理整页导致编辑器外的 $...$ 被重新渲染;不调用会导致同一公式被渲染 2 次
2765
- // Qt WebView 中 clear/updateDocument 可能清掉刚插入的节点或抛错,故跳过
2766
- if (!isQtWebView_1) {
2767
- try {
2768
- var startup = window.MathJax.startup;
2769
- var prevElements = startup.elements;
2770
- if (element instanceof HTMLElement) {
2771
- startup.elements = [element];
2772
- }
2773
- startup.document.clear();
2774
- startup.document.updateDocument();
2775
- startup.elements =
2776
- prevElements !== undefined ? prevElements : [];
2777
- }
2778
- catch (_) {
2779
- if (((_b = (_a = window.MathJax) === null || _a === void 0 ? void 0 : _a.startup) === null || _b === void 0 ? void 0 : _b.elements) !== undefined) {
2780
- window.MathJax.startup.elements = [];
2781
- }
2782
- }
2704
+ var startup = window.MathJax.startup;
2705
+ var prevElements = startup.elements;
2706
+ if (element instanceof HTMLElement) {
2707
+ startup.elements = [element];
2783
2708
  }
2709
+ startup.document.clear();
2710
+ startup.document.updateDocument();
2711
+ startup.elements =
2712
+ prevElements !== undefined ? prevElements : [];
2784
2713
  var errorTextElement = node.querySelector('[data-mml-node="merror"]');
2785
2714
  if (errorTextElement &&
2786
2715
  errorTextElement.textContent.trim() !== "") {
2787
- // 渲染失败时按普通文本展示原始内容
2788
- mathElement.textContent = rawText;
2789
- mathElement.className = "language-math";
2716
+ mathElement.innerHTML =
2717
+ errorTextElement.textContent.trim();
2718
+ mathElement.className =
2719
+ "language-math vditor-reset--error";
2790
2720
  }
2791
2721
  if (next) {
2792
2722
  next();
2793
2723
  }
2794
2724
  });
2795
2725
  };
2726
+ window.MathJax.startup.promise.then(function () {
2727
+ if (window.MathJax.startup) {
2728
+ window.MathJax.startup.typeset = true;
2729
+ window.MathJax.startup.elements =
2730
+ element instanceof HTMLElement ? [element] : [];
2731
+ }
2732
+ var chains = [];
2733
+ var _loop_1 = function (i) {
2734
+ var mathElement = mathElements[i];
2735
+ if (!mathElement.parentElement.classList.contains("vditor-wysiwyg__pre") &&
2736
+ !mathElement.parentElement.classList.contains("vditor-ir__marker--pre") &&
2737
+ !mathElement.getAttribute("data-math") &&
2738
+ (0,_util_code160to32__WEBPACK_IMPORTED_MODULE_5__/* .code160to32 */ .X)(mathElement.textContent).trim()) {
2739
+ chains.push(function (next) {
2740
+ if (i === mathElements.length - 1) {
2741
+ renderMath_1(mathElement);
2742
+ }
2743
+ else {
2744
+ renderMath_1(mathElement, next);
2745
+ }
2746
+ });
2747
+ }
2748
+ };
2749
+ for (var i = 0; i < mathElements.length; i++) {
2750
+ _loop_1(i);
2751
+ }
2752
+ chainAsync_1(chains);
2753
+ });
2796
2754
  }
2797
2755
  };
2798
2756