@mdit/plugin-mathjax-slim 1.2.3 → 2.1.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.md +14 -2
- package/dist/{sync-node.d.ts → async/index.d.ts} +40 -29
- package/dist/async/index.js +10 -0
- package/dist/async/index.js.map +1 -0
- package/dist/index.d.ts +151 -29
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +8 -0
- package/dist/worker.js.map +1 -0
- package/package.json +8 -7
- package/dist/sync-node.js +0 -10
- package/dist/sync-node.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[  ](https://www.npmjs.com/package/@mdit/plugin-mathjax-slim)
|
|
4
4
|
|
|
5
|
-
Mathjax plugin for MarkdownIt.
|
|
5
|
+
Mathjax plugin for MarkdownIt.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`@mathjax/src` is declared as an optional peer dependency here.
|
|
8
|
+
|
|
9
|
+
The synchronous main entry requires Node.js (`worker_threads`). In browsers or runtimes without worker threads, use `@mdit/plugin-mathjax-slim/async` instead.
|
|
8
10
|
|
|
9
11
|
## [Docs](https://mdit-plugins.github.io/mathjax.html) | [文档](https://mdit-plugins.github.io/zh/mathjax.html)
|
|
10
12
|
|
|
@@ -18,3 +20,13 @@ npm i -D @mdit/plugin-mathjax-slim @mathjax/src
|
|
|
18
20
|
# yarn
|
|
19
21
|
yarn add -D @mdit/plugin-mathjax-slim @mathjax/src
|
|
20
22
|
```
|
|
23
|
+
|
|
24
|
+
## Comparison / 对比
|
|
25
|
+
|
|
26
|
+
Compared against the upstream [`markdown-it-mathjax3`](https://www.npmjs.com/package/markdown-it-mathjax3) package `5.2.0`.
|
|
27
|
+
|
|
28
|
+
- Correctness: **8/25** cases match the reference exactly (11 matching after normalization, 3 reference errors, 1 differences).
|
|
29
|
+
- Throughput: **1.15×** the reference (geometric mean across 6 benchmark cases; above 1× means faster).
|
|
30
|
+
- Entry gzip: **1.7 kB** versus **1.7 kB** for the reference (import cost).
|
|
31
|
+
|
|
32
|
+
See the full comparison report: [English](https://mdit-plugins.github.io/compare.html) · [中文](https://mdit-plugins.github.io/zh/compare.html).
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { MarkdownItTexOptions } from "@mdit/plugin-tex";
|
|
2
|
-
import { MarkdownIt } from "markdown-it";
|
|
3
2
|
import { LiteElement } from "@mathjax/src/js/adaptors/lite/Element.js";
|
|
4
|
-
import { LiteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
|
|
5
|
-
import { TeX } from "@mathjax/src/js/input/tex.js";
|
|
6
|
-
import { CHTML } from "@mathjax/src/js/output/chtml.js";
|
|
7
|
-
import { SVG } from "@mathjax/src/js/output/svg.js";
|
|
8
3
|
import { MathDocument } from "@mathjax/src/js/core/MathDocument.js";
|
|
9
4
|
import { MathItem } from "@mathjax/src/js/core/MathItem.js";
|
|
10
5
|
import { MmlNode } from "@mathjax/src/js/core/MmlTree/MmlNode.js";
|
|
6
|
+
import { TeX } from "@mathjax/src/js/input/tex.js";
|
|
11
7
|
import TexError from "@mathjax/src/js/input/tex/TexError.js";
|
|
12
8
|
import { ChtmlFontData } from "@mathjax/src/js/output/chtml/FontData.js";
|
|
13
9
|
import { ChtmlWrapperFactory } from "@mathjax/src/js/output/chtml/WrapperFactory.js";
|
|
@@ -15,12 +11,23 @@ import { LinebreakVisitor } from "@mathjax/src/js/output/common/LinebreakVisitor
|
|
|
15
11
|
import { SvgFontData } from "@mathjax/src/js/output/svg/FontData.js";
|
|
16
12
|
import { SvgWrapperFactory } from "@mathjax/src/js/output/svg/WrapperFactory.js";
|
|
17
13
|
import { CssStyles } from "@mathjax/src/js/ui/menu/mj-context-menu.js";
|
|
18
|
-
|
|
14
|
+
import { LiteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
|
|
15
|
+
import { CHTML } from "@mathjax/src/js/output/chtml.js";
|
|
16
|
+
import { SVG } from "@mathjax/src/js/output/svg.js";
|
|
17
|
+
import { MarkdownIt } from "markdown-it";
|
|
19
18
|
type TexPackage = "action" | "ams" | "amscd" | "bbm" | "bboldx" | "bbox" | "begingroup" | "boldsymbol" | "braket" | "bussproofs" | "cancel" | "cases" | "centernot" | "color" | "colortbl" | "colorv2" | "configmacros" | "dsfont" | "empheq" | "enclose" | "extpfeil" | "gensymb" | "html" | "mathtools" | "mhchem" | "newcommand" | "noerrors" | "noundefined" | "physics" | "setoptions" | "tagformat" | "texhtml" | "textcomp" | "textmacros" | "unicode" | "units" | "upgreek" | "verb";
|
|
20
19
|
interface MathJaxTexInputOptions {
|
|
21
20
|
/**
|
|
22
21
|
* Extensions to use
|
|
23
22
|
*
|
|
23
|
+
* The default list never contains the HTML-related packages (`html` and `texhtml`); they are
|
|
24
|
+
* added to the default list when the plugin is installed on a markdown-it instance that enables
|
|
25
|
+
* the `html` option. An explicit `packages` list is trusted developer configuration and used
|
|
26
|
+
* as-is.
|
|
27
|
+
*
|
|
28
|
+
* 默认列表从不包含 HTML 相关包(`html` 与 `texhtml`);仅当插件安装到开启 `html` 选项的 markdown-it 实例时才加入默认列表。显式提供的
|
|
29
|
+
* `packages` 列表视为可信的开发者配置并原样使用。
|
|
30
|
+
*
|
|
24
31
|
* @default [
|
|
25
32
|
* 'action',
|
|
26
33
|
* 'ams',
|
|
@@ -44,17 +51,14 @@ interface MathJaxTexInputOptions {
|
|
|
44
51
|
* 'enclose',
|
|
45
52
|
* 'extpfeil',
|
|
46
53
|
* 'gensymb',
|
|
47
|
-
* 'html',
|
|
48
54
|
* 'mathtools',
|
|
49
55
|
* 'mhchem',
|
|
50
56
|
* 'newcommand',
|
|
51
57
|
* 'noerrors',
|
|
52
58
|
* 'noundefined',
|
|
53
59
|
* 'physics',
|
|
54
|
-
* 'require',
|
|
55
60
|
* 'setoptions',
|
|
56
61
|
* 'tagformat',
|
|
57
|
-
* 'texhtml',
|
|
58
62
|
* 'textcomp',
|
|
59
63
|
* 'textmacros',
|
|
60
64
|
* 'unicode',
|
|
@@ -309,8 +313,6 @@ interface MathjaxSVGOutputOptions extends MathjaxCommonOutputOptions {
|
|
|
309
313
|
/** For developers only */
|
|
310
314
|
wrapperFactory?: typeof SvgWrapperFactory;
|
|
311
315
|
}
|
|
312
|
-
//#endregion
|
|
313
|
-
//#region src/options.d.ts
|
|
314
316
|
type TeXTransformer = (content: string, displayMode: boolean) => string;
|
|
315
317
|
interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInlineWithSpace" | "delimiters" | "mathFence"> {
|
|
316
318
|
/**
|
|
@@ -322,9 +324,10 @@ interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInli
|
|
|
322
324
|
*/
|
|
323
325
|
output?: "chtml" | "svg";
|
|
324
326
|
/**
|
|
325
|
-
*
|
|
327
|
+
* Whether to include assistive MathML for screen readers. When disabled, math is still rendered
|
|
328
|
+
* but the hidden `<mjx-assistive-mml>` output is omitted.
|
|
326
329
|
*
|
|
327
|
-
*
|
|
330
|
+
* 是否包含供屏幕阅读器使用的辅助 MathML。关闭后数学公式仍会渲染,但不再输出隐藏的 `<mjx-assistive-mml>`。
|
|
328
331
|
*
|
|
329
332
|
* @default true
|
|
330
333
|
*/
|
|
@@ -362,35 +365,43 @@ interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInli
|
|
|
362
365
|
*/
|
|
363
366
|
debug?: boolean;
|
|
364
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Mathjax document options
|
|
370
|
+
*
|
|
371
|
+
* Mathjax 文档选项
|
|
372
|
+
*/
|
|
365
373
|
interface DocumentOptions {
|
|
374
|
+
/** Input jax / 输入 jax */
|
|
366
375
|
InputJax: TeX<LiteElement, string, HTMLElement>;
|
|
376
|
+
/** Output jax / 输出 jax */
|
|
367
377
|
OutputJax: CHTML<LiteElement, string, HTMLElement> | SVG<LiteElement, string, HTMLElement>;
|
|
378
|
+
/** Whether to enable assistive MML / 是否启用辅助 MML */
|
|
368
379
|
enableAssistiveMml: boolean;
|
|
369
380
|
}
|
|
370
|
-
/** Mathjax instance common options */
|
|
381
|
+
/** Mathjax instance common options / Mathjax 实例通用选项 */
|
|
371
382
|
interface MathjaxInstance<Sync extends boolean = false> extends Required<Pick<MarkdownItMathjaxOptions, "allowInlineWithSpace" | "delimiters" | "mathFence">> {
|
|
372
|
-
/** Mathjax adaptor */
|
|
383
|
+
/** Mathjax adaptor / Mathjax 适配器 */
|
|
373
384
|
adaptor: LiteAdaptor;
|
|
374
|
-
/** Mathjax document options */
|
|
385
|
+
/** Mathjax document options / Mathjax 文档选项 */
|
|
375
386
|
documentOptions: DocumentOptions;
|
|
376
387
|
/**
|
|
377
|
-
* Output style for rendered content
|
|
388
|
+
* Output style for rendered content; clears the style cache afterwards
|
|
389
|
+
*
|
|
390
|
+
* 已渲染内容的输出样式,返回后会清空样式缓存
|
|
378
391
|
*
|
|
379
|
-
* @returns Style
|
|
392
|
+
* @returns Style content / 样式内容
|
|
380
393
|
*/
|
|
381
394
|
outputStyle: () => Sync extends true ? string : Promise<string>;
|
|
382
|
-
/**
|
|
395
|
+
/** Render one formula synchronously / 同步渲染单个公式 */
|
|
396
|
+
render: (content: string, displayMode: boolean) => string;
|
|
397
|
+
/** Reset tex (including labels) / 重置 TeX(包含标签) */
|
|
383
398
|
reset: () => void;
|
|
384
|
-
/** Clear style cache */
|
|
399
|
+
/** Clear the style cache and reset both input and output jax / 清除样式缓存并重置输入与输出 jax */
|
|
385
400
|
clearStyle: () => void;
|
|
386
|
-
/** Output content transformer */
|
|
401
|
+
/** Output content transformer / 输出内容转换器 */
|
|
387
402
|
transformer: TeXTransformer | null;
|
|
388
403
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
export declare const
|
|
392
|
-
export
|
|
393
|
-
export declare const mathjax: (md: MarkdownIt, { allowInlineWithSpace, adaptor, delimiters, documentOptions, mathFence, reset, transformer }: MathjaxInstance<true>) => void;
|
|
394
|
-
//#endregion
|
|
395
|
-
export {};
|
|
396
|
-
//# sourceMappingURL=sync-node.d.ts.map
|
|
404
|
+
export declare const getDocumentOptions: (options: MarkdownItMathjaxOptions) => Promise<DocumentOptions>;
|
|
405
|
+
export declare const createMathjaxInstance: (options?: MarkdownItMathjaxOptions) => Promise<MathjaxInstance | null>;
|
|
406
|
+
export declare const mathjax: (md: MarkdownIt, instance: MathjaxInstance) => void;
|
|
407
|
+
export type { DocumentOptions, MarkdownItMathjaxOptions, MathJaxTexInputOptions, MathjaxCommonHTMLOutputOptions, MathjaxCommonOutputOptions, MathjaxFilter, MathjaxFilterData, MathjaxInstance, MathjaxSVGOutputOptions, TeXTransformer, TexPackage };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{tex as e}from"@mdit/plugin-tex";const t=/* @__PURE__ */ `action.ams.amscd.bbox.begingroup.boldsymbol.braket.bussproofs.cancel.cases.centernot.color.colortbl.colorv2.configmacros.empheq.enclose.extpfeil.gensymb.mathtools.mhchem.newcommand.noerrors.noundefined.physics.setoptions.tagformat.textcomp.textmacros.unicode.units.upgreek.verb`.split(`.`),n={action:()=>import(`@mathjax/src/js/input/tex/action/ActionConfiguration.js`),ams:()=>import(`@mathjax/src/js/input/tex/ams/AmsConfiguration.js`),amscd:()=>import(`@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js`),bbm:()=>import(`@mathjax/src/js/input/tex/bbm/BbmConfiguration.js`),bboldx:()=>import(`@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js`),bbox:()=>import(`@mathjax/src/js/input/tex/bbox/BboxConfiguration.js`),begingroup:()=>import(`@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js`),boldsymbol:()=>import(`@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js`),braket:()=>import(`@mathjax/src/js/input/tex/braket/BraketConfiguration.js`),bussproofs:()=>import(`@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js`),cancel:()=>import(`@mathjax/src/js/input/tex/cancel/CancelConfiguration.js`),cases:()=>import(`@mathjax/src/js/input/tex/cases/CasesConfiguration.js`),centernot:()=>import(`@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js`),color:()=>import(`@mathjax/src/js/input/tex/color/ColorConfiguration.js`),colortbl:()=>import(`@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js`),colorv2:()=>import(`@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js`),configmacros:()=>import(`@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js`),dsfont:()=>import(`@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js`),empheq:()=>import(`@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js`),enclose:()=>import(`@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js`),extpfeil:()=>import(`@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js`),gensymb:()=>import(`@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js`),html:()=>import(`@mathjax/src/js/input/tex/html/HtmlConfiguration.js`),mathtools:()=>import(`@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js`),mhchem:()=>import(`@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js`),newcommand:()=>import(`@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js`),noerrors:()=>import(`@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js`),noundefined:()=>import(`@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js`),physics:()=>import(`@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js`),setoptions:()=>import(`@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js`),tagformat:()=>import(`@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js`),texhtml:()=>import(`@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js`),textcomp:()=>import(`@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js`),textmacros:()=>import(`@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js`),unicode:()=>import(`@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js`),units:()=>import(`@mathjax/src/js/input/tex/units/UnitsConfiguration.js`),upgreek:()=>import(`@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js`),verb:()=>import(`@mathjax/src/js/input/tex/verb/VerbConfiguration.js`)},r=[`html`,`texhtml`],i=(e,n=!1)=>{let i=/* @__PURE__ */ new Set([`base`]);if(e)for(let t of e)i.add(t);else{for(let e of t)i.add(e);if(n)for(let e of r)i.add(e)}return[...i]},a=async(e=t)=>{await import(`@mathjax/src/js/input/tex/base/BaseConfiguration.js`),await Promise.all(e.filter(e=>Object.hasOwn(n,e)).map(e=>n[e]()))},o=[`new-Command`,`new-Environment`,`new-Delimiter`],s=e=>{for(let t of o)e.parseOptions.handlers.retrieve(t)?.map.clear()},c=/* @__PURE__ */ new WeakMap,l=/* @__PURE__ */ new WeakSet,u=(e,t)=>{let n=c.get(e);if(!n)throw Error("[@mdit/plugin-mathjax-slim] the given instance was not created by `createMathjaxInstance` from this package");n.enableHtml!==t&&(e.documentOptions.InputJax=n.createInputJax(t),n.enableHtml=t)};let d,f,p,m,h,g,_,v,y,b=!0,x=!0;try{({mathjax:v}=await import(`@mathjax/src/js/mathjax.js`)),{TeX:h}=await import(`@mathjax/src/js/input/tex.js`),{CHTML:f}=await import(`@mathjax/src/js/output/chtml.js`),{SVG:m}=await import(`@mathjax/src/js/output/svg.js`),{liteAdaptor:_}=await import(`@mathjax/src/js/adaptors/liteAdaptor.js`),{RegisterHTMLHandler:p}=await import(`@mathjax/src/js/handlers/html.js`),{AssistiveMmlHandler:d}=await import(`@mathjax/src/js/a11y/assistive-mml.js`)}catch{
|
|
2
|
+
/* istanbul ignore next -- @preserve */
|
|
3
|
+
b=!1}try{g=(await import(`@mathjax/mathjax-newcm-font/js/chtml.js`)).MathJaxNewcmFont,y=(await import(`@mathjax/mathjax-newcm-font/js/svg.js`)).MathJaxNewcmFont}catch{
|
|
4
|
+
/* istanbul ignore next -- @preserve */
|
|
5
|
+
x=!1}const S=async e=>{
|
|
6
|
+
/* istanbul ignore if -- @preserve */
|
|
7
|
+
if(!b)throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/src" is not installed!`);let t=e.output===`chtml`,n=(t?e.chtml:e.svg)??{};
|
|
8
|
+
/* istanbul ignore if -- @preserve */
|
|
9
|
+
if(!n.fontData&&!x)throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/mathjax-newcm-font" is not installed!`);let r=Object.assign({fontData:t?g:y},n?.fontData?{}:{dynamicPrefix:`@mathjax/mathjax-newcm-font/js/${t?`chtml`:`svg`}/dynamic`},t&&!n.fontData?{fontURL:`https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2`}:{},n);v.asyncLoad=t=>(e.debug&&console.debug(`[MathJax]: loading ${t}...`),import(t));let o=e.tex?.packages;return await a([...i(o),`html`,`texhtml`]),{InputJax:new h({...e.tex,packages:i(o)}),OutputJax:new(t?f:m)(r),enableAssistiveMml:e.a11y!==!1}},C=async(e={})=>{let t=await S(e),{OutputJax:n}=t,r=_(),a=p(r);d(a);let o=()=>{n.adaptor!=null&&(t.InputJax.reset(),n.reset())},l={adaptor:r,documentOptions:t,allowInlineWithSpace:e.allowInlineWithSpace??!1,delimiters:e.delimiters??`dollars`,mathFence:e.mathFence??!1,clearStyle:o,render:(e,n)=>{let i=v.document(e,t).convert(e,{display:n});return r.outerHTML(i)},reset:()=>{t.InputJax.reset(),s(t.InputJax)},outputStyle:async()=>{await n.font.loadDynamicFiles();let e=r.cssText(n.styleSheet(v.document(``,t)));return o(),e},transformer:e.transformer??null};return c.set(l,{enableHtml:!1,createInputJax:t=>new h({...e.tex,packages:i(e.tex?.packages,t)})}),l},w=(t,n)=>{if(l.has(n))throw Error("[@mdit/plugin-mathjax-slim] the instance is already installed on a MarkdownIt instance. Create a separate MathJax instance with `createMathjaxInstance` for each `MarkdownIt` instance");u(n,t.options.html),l.add(n);let{allowInlineWithSpace:r,delimiters:i,mathFence:a,render:o,reset:s,transformer:c}=n,d=t.render.bind(t),f=t.renderInline.bind(t);t.render=(e,t)=>{try{return d(e,t)}finally{s()}},t.renderInline=(e,t)=>{try{return f(e,t)}finally{s()}},t.use(e,{allowInlineWithSpace:r,delimiters:i,mathFence:a,render:(e,t)=>{let n=o(e,t);return c?.(n,t)??n}})};export{C as createMathjaxInstance,S as getDocumentOptions,w as mathjax};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["texPackages","texLoaders","HTML_PACKAGES","resolveTexPackages","packages","userPackages","pkg","enableHtml","loadTexPackages","USER_MAP_NAMES","clearUserState","name","InputJax","instanceTexStates","installedInstances","applyHtmlPackages","state","instance","AssistiveMmlHandler","CHTML","RegisterHTMLHandler","SVG","TeX","chtmlFont","liteAdaptor","mathjaxLib","svgFont","isMathJaxInstalled","isMathJaxNewcmFontInstalled","getDocumentOptions","isCHTML","options","userOptions","outputOptions","file","createMathjaxInstance","documentOptions","adaptor","handler","clearStyle","OutputJax","mathDocument","content","displayMode","style","mathjax","md","renderMath","render","renderInline","src","env","reset","tex","result","transformer"],"sources":["../../src/tex/packages.ts","../../src/tex/loader.ts","../../src/tex/utils.ts","../../src/utils.ts","../../src/async/plugin.ts"],"sourcesContent":["import type { TexPackage } from \"../mathjax.js\";\n\n/**\n * Default TeX packages.\n *\n * The HTML-related packages (`html`, which provides `\\href`, `\\class`, `\\style` and `\\cssId`, and\n * `texhtml`, which registers the `<tex-html>` handler) are intentionally excluded. They are added\n * to the default list when the markdown-it instance enables raw HTML (`new MarkdownIt({ html: true\n * })`), or can be enabled explicitly through `tex.packages`, see `resolveTexPackages` in\n * `./utils.ts`.\n *\n * The font-extension packages (`bbm`, `bboldx` and `dsfont`) are also excluded: the bundled\n * `@mathjax/mathjax-newcm-font` font does not ship their extension data, so loading them would\n * replace standard macros (e.g. `\\mathbb`) with missing font variants and fall back with an\n * `Invalid variant` warning. They can still be enabled explicitly through `tex.packages`.\n *\n * 默认 TeX 包。\n *\n * 提供 `\\href`、`\\class`、`\\style`、`\\cssId` 等能力的 HTML 相关包(`html`)与注册 `<tex-html>` 处理器的 `texhtml`\n * 默认不启用:仅在 markdown-it 实例开启 `html: true` 时加入默认列表,或通过 `tex.packages` 显式启用, 见 `./utils.ts` 的\n * `resolveTexPackages`。\n *\n * 依赖字体扩展数据的 `bbm`、`bboldx`、`dsfont` 同样默认不启用:随包的 `@mathjax/mathjax-newcm-font`\n * 字体不包含这些扩展数据,加载后会用缺失的字体变体替换标准宏(如 `\\mathbb`)并触发 `Invalid variant` 警告后回退。 仍可通过 `tex.packages` 显式启用。\n */\nexport const texPackages: TexPackage[] = [\n \"action\",\n \"ams\",\n \"amscd\",\n \"bbox\",\n \"begingroup\",\n \"boldsymbol\",\n \"braket\",\n \"bussproofs\",\n \"cancel\",\n \"cases\",\n \"centernot\",\n \"color\",\n \"colortbl\",\n \"colorv2\",\n \"configmacros\",\n \"empheq\",\n \"enclose\",\n \"extpfeil\",\n \"gensymb\",\n \"mathtools\",\n \"mhchem\",\n \"newcommand\",\n \"noerrors\",\n \"noundefined\",\n \"physics\",\n \"setoptions\",\n \"tagformat\",\n \"textcomp\",\n \"textmacros\",\n \"unicode\",\n \"units\",\n \"upgreek\",\n \"verb\",\n];\n","import type { TexPackage } from \"../mathjax.js\";\n\nexport const texLoaders: Record<TexPackage, () => Promise<unknown>> = {\n action: () => import(\"@mathjax/src/js/input/tex/action/ActionConfiguration.js\"),\n ams: () => import(\"@mathjax/src/js/input/tex/ams/AmsConfiguration.js\"),\n amscd: () => import(\"@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js\"),\n bbm: () => import(\"@mathjax/src/js/input/tex/bbm/BbmConfiguration.js\"),\n bboldx: () => import(\"@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js\"),\n bbox: () => import(\"@mathjax/src/js/input/tex/bbox/BboxConfiguration.js\"),\n begingroup: () => import(\"@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js\"),\n boldsymbol: () => import(\"@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js\"),\n braket: () => import(\"@mathjax/src/js/input/tex/braket/BraketConfiguration.js\"),\n bussproofs: () => import(\"@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js\"),\n cancel: () => import(\"@mathjax/src/js/input/tex/cancel/CancelConfiguration.js\"),\n cases: () => import(\"@mathjax/src/js/input/tex/cases/CasesConfiguration.js\"),\n centernot: () => import(\"@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js\"),\n color: () => import(\"@mathjax/src/js/input/tex/color/ColorConfiguration.js\"),\n colortbl: () => import(\"@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js\"),\n colorv2: () => import(\"@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js\"),\n configmacros: () => import(\"@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js\"),\n dsfont: () => import(\"@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js\"),\n empheq: () => import(\"@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js\"),\n enclose: () => import(\"@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js\"),\n extpfeil: () => import(\"@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js\"),\n gensymb: () => import(\"@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js\"),\n html: () => import(\"@mathjax/src/js/input/tex/html/HtmlConfiguration.js\"),\n mathtools: () => import(\"@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js\"),\n mhchem: () => import(\"@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js\"),\n newcommand: () => import(\"@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js\"),\n noerrors: () => import(\"@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js\"),\n noundefined: () => import(\"@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js\"),\n physics: () => import(\"@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js\"),\n setoptions: () => import(\"@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js\"),\n tagformat: () => import(\"@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js\"),\n texhtml: () => import(\"@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js\"),\n textcomp: () => import(\"@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js\"),\n textmacros: () => import(\"@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js\"),\n unicode: () => import(\"@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js\"),\n units: () => import(\"@mathjax/src/js/input/tex/units/UnitsConfiguration.js\"),\n upgreek: () => import(\"@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js\"),\n verb: () => import(\"@mathjax/src/js/input/tex/verb/VerbConfiguration.js\"),\n};\n","import type { TexPackage } from \"../mathjax.js\";\nimport { texLoaders } from \"./loader.js\";\nimport { texPackages } from \"./packages.js\";\n\n/**\n * TeX packages that provide HTML-related capabilities: `html` adds `\\href`, `\\class`, `\\style` and\n * `\\cssId`, and `texhtml` registers the `<tex-html>` handler (inert unless MathJax's `allowTexHTML`\n * option is enabled).\n *\n * 提供 HTML 相关能力的 TeX 包:`html` 提供 `\\href`、`\\class`、`\\style`、`\\cssId`;`texhtml` 注册 `<tex-html>`\n * 处理器(除非开启 MathJax 的 `allowTexHTML` 选项,否则不生效)。\n */\nconst HTML_PACKAGES: TexPackage[] = [\"html\", \"texhtml\"];\n\n/**\n * Resolve the TeX packages to load.\n *\n * The default package list never contains the HTML-related packages; they are only added to that\n * default list when the markdown-it instance enables raw HTML. An explicit `tex.packages` list is\n * treated as trusted developer configuration and used as-is, so enabling the HTML-related packages\n * is possible even when markdown-it itself has raw HTML disabled.\n *\n * 解析需要加载的 TeX 包。\n *\n * 默认包列表从不包含 HTML 相关包;仅当 markdown-it 实例开启原始 HTML 时才会把它们加入默认列表。 显式提供的 `tex.packages`\n * 视为可信的开发者配置并原样使用,因此即使 markdown-it 关闭原始 HTML,也可以启用 HTML 相关包。\n *\n * @param userPackages - User-defined packages / 用户定义的包\n * @param enableHtml - Whether markdown-it enables HTML / markdown-it 是否开启 HTML\n * @returns Resolved package list with `base` first / 解析后的包列表(`base` 在最前)\n */\nexport const resolveTexPackages = (\n userPackages?: TexPackage[],\n enableHtml = false,\n): TexPackage[] => {\n // `base` is always loaded and is not part of the public `TexPackage` union.\n // `base` 总会加载,且不在公开的 `TexPackage` 联合类型中。\n const packages = new Set<string>([\"base\"]);\n\n if (userPackages) {\n // Trusted developer configuration: use the list as-is.\n // 可信的开发者配置:原样使用该列表。\n for (const pkg of userPackages) packages.add(pkg);\n } else {\n for (const pkg of texPackages) packages.add(pkg);\n\n // The markdown-it `html` option only decides the default package list.\n // markdown-it 的 `html` 选项只决定默认包列表。\n if (enableHtml) for (const pkg of HTML_PACKAGES) packages.add(pkg);\n }\n\n return [...packages] as TexPackage[];\n};\n\n/**\n * Load the given TeX packages with MathJax's official async API.\n *\n * 使用 MathJax 官方异步 API 加载指定的 TeX 包。\n *\n * @param packages - Packages to load / 需要加载的包\n * @returns Promise resolved when all packages are loaded / 所有包加载完成时 resolve 的 Promise\n */\nexport const loadTexPackages = async (packages: TexPackage[] = texPackages): Promise<void> => {\n await import(\"@mathjax/src/js/input/tex/base/BaseConfiguration.js\");\n\n await Promise.all(\n packages.filter((pkg) => Object.hasOwn(texLoaders, pkg)).map((pkg) => texLoaders[pkg]()),\n );\n};\n","import type { LiteElement } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type { TeX } from \"@mathjax/src/js/input/tex.js\";\n\ninterface TeXMacroMap {\n map: Map<string, unknown>;\n}\n\n// MathJax keeps user-defined macros, environments and delimiters in the internal `new-*` maps of\n// the `newcommand` package. Their names are unique across handler types, so they can be looked up\n// by name, which avoids importing the `HandlerType` enum: a value import would add a runtime import\n// of the optional `@mathjax/src` peer to the `worker` and `async/index` entries.\nconst USER_MAP_NAMES = [\"new-Command\", \"new-Environment\", \"new-Delimiter\"] as const;\n\n/**\n * Clear user-defined TeX state (macros/environments/delimiters) on a MathJax TeX input jax.\n *\n * MathJax stores user-defined macros, environments and delimiters in dedicated `new-*` maps that\n * are separate from the built-in maps, and `InputJax.reset()` does not clear them, so they would\n * leak across documents rendered by the same instance. This reaches into the internal maps to\n * remove only user-defined entries.\n *\n * 清除 MathJax TeX 输入 jax 上由 `\\newcommand`/`\\def`/`\\newenvironment` 等定义的用户状态。\n *\n * MathJax 将用户自定义的宏、环境与分隔符存放在独立的 `new-*` 映射中,与内置映射分离,且 `InputJax.reset()`\n * 不会清除它们,因此同一实例渲染多篇文档时状态会跨文档泄漏。此处直接访问内部映射,仅移除用户自定义条目。\n *\n * @param InputJax - MathJax TeX input jax / MathJax TeX 输入 jax\n */\nexport const clearUserState = (InputJax: TeX<LiteElement, string, HTMLElement>): void => {\n for (const name of USER_MAP_NAMES) {\n const userMap = InputJax.parseOptions.handlers.retrieve(name) as unknown as TeXMacroMap | null;\n\n userMap?.map.clear();\n }\n};\n","/** Forked from https://github.com/tani/markdown-it-mathjax3/blob/master/index.ts */\n\nimport type { MathJaxNewcmFont as chtmlFontType } from \"@mathjax/mathjax-newcm-font/js/chtml.js\";\nimport type { MathJaxNewcmFont as svgFontType } from \"@mathjax/mathjax-newcm-font/js/svg.js\";\nimport type { AssistiveMmlHandler as AssistiveMmlHandlerType } from \"@mathjax/src/js/a11y/assistive-mml.js\";\nimport type { LiteDocument } from \"@mathjax/src/js/adaptors/lite/Document.js\";\nimport type { LiteElement, LiteNode } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type { LiteText } from \"@mathjax/src/js/adaptors/lite/Text.js\";\nimport type { liteAdaptor as liteAdaptorType } from \"@mathjax/src/js/adaptors/liteAdaptor.js\";\nimport type { MathDocument } from \"@mathjax/src/js/core/MathDocument.js\";\nimport type { RegisterHTMLHandler as RegisterHTMLHandlerType } from \"@mathjax/src/js/handlers/html.js\";\nimport type { TeX as TeXType } from \"@mathjax/src/js/input/tex.js\";\nimport type { mathjax as mathjaxType } from \"@mathjax/src/js/mathjax.js\";\nimport type { CHTML as CHTMLType } from \"@mathjax/src/js/output/chtml.js\";\nimport type { SVG as SVGType } from \"@mathjax/src/js/output/svg.js\";\nimport { tex } from \"@mdit/plugin-tex\";\nimport type { MarkdownIt } from \"markdown-it\";\n\nimport type { MarkdownItMathjaxOptions, DocumentOptions, MathjaxInstance } from \"../options.js\";\nimport { loadTexPackages, resolveTexPackages } from \"../tex/index.js\";\nimport { clearUserState } from \"../utils.js\";\n\ntype InputJax = DocumentOptions[\"InputJax\"];\n\ninterface InstanceTexState {\n /** Whether HTML-related TeX packages are enabled / 是否启用 HTML 相关 TeX 包 */\n enableHtml: boolean;\n\n /** Create a TeX input jax with the given HTML capability / 创建具有指定 HTML 能力的 TeX 输入 jax */\n createInputJax: (enableHtml: boolean) => InputJax;\n}\n\nconst instanceTexStates = new WeakMap<MathjaxInstance, InstanceTexState>();\n\n/**\n * MathJax instances that are already installed on a markdown-it instance.\n *\n * A MathJax instance owns shared TeX state, so it must not be shared by multiple markdown-it\n * instances with different trust levels.\n *\n * 已安装到 markdown-it 实例上的 MathJax 实例。\n *\n * MathJax 实例持有共享的 TeX 状态,因此同一个实例不能被多个信任级别不同的 markdown-it 实例共用。\n */\nconst installedInstances = new WeakSet<MathjaxInstance>();\n\n/**\n * Match the HTML-related TeX packages of an instance with the markdown-it `html` option.\n *\n * 让实例的 HTML 相关 TeX 包与 markdown-it 的 `html` 选项保持一致。\n *\n * @param instance - MathJax instance / MathJax 实例\n * @param enableHtml - Whether HTML is enabled / 是否启用 HTML\n */\nconst applyHtmlPackages = (instance: MathjaxInstance, enableHtml: boolean): void => {\n const state = instanceTexStates.get(instance);\n\n if (!state) {\n throw new Error(\n \"[@mdit/plugin-mathjax-slim] the given instance was not created by `createMathjaxInstance` from this package\",\n );\n }\n\n if (state.enableHtml === enableHtml) return;\n\n instance.documentOptions.InputJax = state.createInputJax(enableHtml);\n state.enableHtml = enableHtml;\n};\n\nlet AssistiveMmlHandler: typeof AssistiveMmlHandlerType,\n CHTML: typeof CHTMLType,\n RegisterHTMLHandler: typeof RegisterHTMLHandlerType,\n SVG: typeof SVGType,\n TeX: typeof TeXType,\n chtmlFont: typeof chtmlFontType,\n liteAdaptor: typeof liteAdaptorType,\n mathjaxLib: typeof mathjaxType,\n svgFont: typeof svgFontType;\nlet isMathJaxInstalled = true;\nlet isMathJaxNewcmFontInstalled = true;\n\ntry {\n ({ mathjax: mathjaxLib } = await import(\"@mathjax/src/js/mathjax.js\"));\n ({ TeX } = await import(\"@mathjax/src/js/input/tex.js\"));\n ({ CHTML } = await import(\"@mathjax/src/js/output/chtml.js\"));\n ({ SVG } = await import(\"@mathjax/src/js/output/svg.js\"));\n ({ liteAdaptor } = await import(\"@mathjax/src/js/adaptors/liteAdaptor.js\"));\n ({ RegisterHTMLHandler } = await import(\"@mathjax/src/js/handlers/html.js\"));\n ({ AssistiveMmlHandler } = await import(\"@mathjax/src/js/a11y/assistive-mml.js\"));\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxInstalled = false;\n}\n\ntry {\n chtmlFont = (await import(\"@mathjax/mathjax-newcm-font/js/chtml.js\")).MathJaxNewcmFont;\n svgFont = (await import(\"@mathjax/mathjax-newcm-font/js/svg.js\")).MathJaxNewcmFont;\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxNewcmFontInstalled = false;\n}\n\nexport const getDocumentOptions = async (\n options: MarkdownItMathjaxOptions,\n): Promise<DocumentOptions> => {\n /* istanbul ignore if -- @preserve */\n if (!isMathJaxInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/src\" is not installed!');\n\n const isCHTML = options.output === \"chtml\";\n const userOptions = (isCHTML ? options.chtml : options.svg) ?? {};\n\n /* istanbul ignore if -- @preserve */\n if (!userOptions.fontData && !isMathJaxNewcmFontInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/mathjax-newcm-font\" is not installed!');\n\n const outputOptions = Object.assign(\n {\n fontData: isCHTML ? chtmlFont : svgFont,\n },\n // fontURL can be set to undefined if you want to bundle the fonts yourself\n // both fontURL and dynamicPrefix shall be synced with fontData, so set it to undefined if fontData is customized\n userOptions?.fontData\n ? {}\n : { dynamicPrefix: `@mathjax/mathjax-newcm-font/js/${isCHTML ? \"chtml\" : \"svg\"}/dynamic` },\n isCHTML && !userOptions.fontData\n ? { fontURL: \"https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2\" }\n : {},\n userOptions,\n );\n\n mathjaxLib.asyncLoad = (file): Promise<unknown> => {\n if (options.debug)\n // oxlint-disable-next-line no-console\n console.debug(`[MathJax]: loading ${file}...`);\n\n return import(file);\n };\n\n const userPackages = options.tex?.packages;\n\n // Load the HTML-related packages eagerly: `mathjax()` decides about them synchronously once the\n // markdown-it instance is available, so their configurations must already be registered.\n await loadTexPackages([...resolveTexPackages(userPackages), \"html\", \"texhtml\"]);\n\n return {\n InputJax: new TeX<LiteElement, string, HTMLElement>({\n ...options.tex,\n packages: resolveTexPackages(userPackages),\n }),\n OutputJax: new (isCHTML ? CHTML : SVG)<LiteElement, string, HTMLElement>(outputOptions),\n enableAssistiveMml: options.a11y !== false,\n };\n};\n\nexport const createMathjaxInstance = async (\n options: MarkdownItMathjaxOptions = {},\n): Promise<MathjaxInstance | null> => {\n const documentOptions = await getDocumentOptions(options);\n\n const { OutputJax } = documentOptions;\n\n const adaptor = liteAdaptor();\n // oxlint-disable-next-line new-cap\n const handler = RegisterHTMLHandler(adaptor);\n\n // Always mix in the a11y document: `enableAssistiveMml` is a document option that only exists\n // once the assistive-mml mixin is applied. The option itself decides whether assistive MathML is\n // produced. Applying the mixin conditionally would leak the first registered handler's choice to\n // later instances (MathJax uses the first global handler for an adaptor) and makes MathJax warn\n // about an unknown `enableAssistiveMml` option when a11y is disabled.\n // oxlint-disable-next-line new-cap\n AssistiveMmlHandler<LiteNode, LiteText, LiteDocument>(handler);\n\n const clearStyle = (): void => {\n // if there is no adaptor, output jax is not initialized yet, so nothing to clear\n if (OutputJax.adaptor == null) return;\n\n documentOptions.InputJax.reset();\n OutputJax.reset();\n };\n\n const reset = (): void => {\n documentOptions.InputJax.reset();\n clearUserState(documentOptions.InputJax);\n };\n\n const render = (content: string, displayMode: boolean): string => {\n const mathDocument = mathjaxLib\n .document(content, documentOptions)\n .convert(content, { display: displayMode }) as LiteElement;\n\n return adaptor.outerHTML(mathDocument);\n };\n\n const outputStyle = async (): Promise<string> => {\n await OutputJax.font.loadDynamicFiles();\n\n const style = adaptor.cssText(\n OutputJax.styleSheet(\n mathjaxLib.document(\"\", documentOptions) as MathDocument<LiteElement, string, HTMLElement>,\n ),\n );\n\n clearStyle();\n\n return style;\n };\n\n const instance: MathjaxInstance = {\n adaptor,\n documentOptions,\n allowInlineWithSpace: options.allowInlineWithSpace ?? false,\n delimiters: options.delimiters ?? \"dollars\",\n mathFence: options.mathFence ?? false,\n clearStyle,\n render,\n reset,\n outputStyle,\n transformer: options.transformer ?? null,\n };\n\n instanceTexStates.set(instance, {\n enableHtml: false,\n createInputJax: (enableHtml: boolean): InputJax =>\n new TeX<LiteElement, string, HTMLElement>({\n ...options.tex,\n packages: resolveTexPackages(options.tex?.packages, enableHtml),\n }),\n });\n\n return instance;\n};\n\nexport const mathjax = (md: MarkdownIt, instance: MathjaxInstance): void => {\n if (installedInstances.has(instance)) {\n throw new Error(\n \"[@mdit/plugin-mathjax-slim] the instance is already installed on a MarkdownIt instance. Create a separate MathJax instance with `createMathjaxInstance` for each `MarkdownIt` instance\",\n );\n }\n\n // The markdown-it `html` option is read when the plugin is installed; later changes through\n // `md.set()` are intentionally not observed, so a single MathJax instance always maps to a single\n // trust level.\n // markdown-it 的 `html` 选项在插件安装时读取;之后通过 `md.set()` 的修改不会生效,从而保证一个\n // MathJax 实例只对应一个信任级别。\n applyHtmlPackages(instance, md.options.html);\n\n installedInstances.add(instance);\n\n const {\n allowInlineWithSpace,\n delimiters,\n mathFence,\n render: renderMath,\n reset,\n transformer,\n } = instance;\n // Reset the shared TeX input state (macros/labels) after each render so that\n // state does not leak across documents rendered by the same instance.\n const render = md.render.bind(md);\n const renderInline = md.renderInline.bind(md);\n\n md.render = (src, env): string => {\n try {\n return render(src, env);\n } finally {\n reset();\n }\n };\n md.renderInline = (src, env): string => {\n try {\n return renderInline(src, env);\n } finally {\n reset();\n }\n };\n\n md.use(tex, {\n allowInlineWithSpace,\n delimiters,\n mathFence,\n render: (content, displayMode) => {\n const result = renderMath(content, displayMode);\n\n return transformer?.(result, displayMode) ?? result;\n },\n });\n};\n"],"mappings":"A,uCAyBA,MAAaA,EAA4B,iTAkCzC,ECzDaC,EAAyD,CACpE,WAAc,OAAO,2DACrB,QAAW,OAAO,qDAClB,UAAa,OAAO,yDACpB,QAAW,OAAO,qDAClB,WAAc,OAAO,2DACrB,SAAY,OAAO,uDACnB,eAAkB,OAAO,mEACzB,eAAkB,OAAO,mEACzB,WAAc,OAAO,2DACrB,eAAkB,OAAO,mEACzB,WAAc,OAAO,2DACrB,UAAa,OAAO,yDACpB,cAAiB,OAAO,iEACxB,UAAa,OAAO,yDACpB,aAAgB,OAAO,+DACvB,YAAe,OAAO,6DACtB,iBAAoB,OAAO,uEAC3B,WAAc,OAAO,2DACrB,WAAc,OAAO,2DACrB,YAAe,OAAO,6DACtB,aAAgB,OAAO,+DACvB,YAAe,OAAO,6DACtB,SAAY,OAAO,uDACnB,cAAiB,OAAO,iEACxB,WAAc,OAAO,2DACrB,eAAkB,OAAO,mEACzB,aAAgB,OAAO,+DACvB,gBAAmB,OAAO,qEAC1B,YAAe,OAAO,6DACtB,eAAkB,OAAO,mEACzB,cAAiB,OAAO,iEACxB,YAAe,OAAO,6DACtB,aAAgB,OAAO,+DACvB,eAAkB,OAAO,mEACzB,YAAe,OAAO,6DACtB,U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F,OAAOE,EAAOE,EAAKC,CAAG,CACxB,QAAU,CACRC,EAAM,CACR,CACF,EACA,EAAG,cAAgB,EAAK,IAAgB,CACtC,GAAI,CACF,OAAOH,EAAaC,EAAKC,CAAG,CAC9B,QAAU,CACRC,EAAM,CACR,CACF,EAEAN,EAAG,IAAIO,EAAK,CACV,uBACA,aACA,YACA,QAAS,EAAS,IAAgB,CAChC,IAAMC,EAASP,EAAWL,EAASC,CAAW,EAE9C,OAAOY,IAAcD,EAAQX,CAAW,GAAKW,CAC/C,CACF,CAAC,CACH,E"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { MarkdownItTexOptions } from "@mdit/plugin-tex";
|
|
2
|
+
import { MarkdownIt } from "markdown-it";
|
|
2
3
|
import { LiteElement } from "@mathjax/src/js/adaptors/lite/Element.js";
|
|
4
|
+
import { LiteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
|
|
5
|
+
import { TeX } from "@mathjax/src/js/input/tex.js";
|
|
6
|
+
import { CHTML } from "@mathjax/src/js/output/chtml.js";
|
|
7
|
+
import { SVG } from "@mathjax/src/js/output/svg.js";
|
|
3
8
|
import { MathDocument } from "@mathjax/src/js/core/MathDocument.js";
|
|
4
9
|
import { MathItem } from "@mathjax/src/js/core/MathItem.js";
|
|
5
10
|
import { MmlNode } from "@mathjax/src/js/core/MmlTree/MmlNode.js";
|
|
6
|
-
import { TeX } from "@mathjax/src/js/input/tex.js";
|
|
7
11
|
import TexError from "@mathjax/src/js/input/tex/TexError.js";
|
|
8
12
|
import { ChtmlFontData } from "@mathjax/src/js/output/chtml/FontData.js";
|
|
9
13
|
import { ChtmlWrapperFactory } from "@mathjax/src/js/output/chtml/WrapperFactory.js";
|
|
@@ -11,16 +15,19 @@ import { LinebreakVisitor } from "@mathjax/src/js/output/common/LinebreakVisitor
|
|
|
11
15
|
import { SvgFontData } from "@mathjax/src/js/output/svg/FontData.js";
|
|
12
16
|
import { SvgWrapperFactory } from "@mathjax/src/js/output/svg/WrapperFactory.js";
|
|
13
17
|
import { CssStyles } from "@mathjax/src/js/ui/menu/mj-context-menu.js";
|
|
14
|
-
import { LiteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
|
|
15
|
-
import { CHTML } from "@mathjax/src/js/output/chtml.js";
|
|
16
|
-
import { SVG } from "@mathjax/src/js/output/svg.js";
|
|
17
|
-
import { MarkdownIt } from "markdown-it";
|
|
18
|
-
//#region src/mathjax.d.ts
|
|
19
18
|
type TexPackage = "action" | "ams" | "amscd" | "bbm" | "bboldx" | "bbox" | "begingroup" | "boldsymbol" | "braket" | "bussproofs" | "cancel" | "cases" | "centernot" | "color" | "colortbl" | "colorv2" | "configmacros" | "dsfont" | "empheq" | "enclose" | "extpfeil" | "gensymb" | "html" | "mathtools" | "mhchem" | "newcommand" | "noerrors" | "noundefined" | "physics" | "setoptions" | "tagformat" | "texhtml" | "textcomp" | "textmacros" | "unicode" | "units" | "upgreek" | "verb";
|
|
20
19
|
interface MathJaxTexInputOptions {
|
|
21
20
|
/**
|
|
22
21
|
* Extensions to use
|
|
23
22
|
*
|
|
23
|
+
* The default list never contains the HTML-related packages (`html` and `texhtml`); they are
|
|
24
|
+
* added to the default list when the plugin is installed on a markdown-it instance that enables
|
|
25
|
+
* the `html` option. An explicit `packages` list is trusted developer configuration and used
|
|
26
|
+
* as-is.
|
|
27
|
+
*
|
|
28
|
+
* 默认列表从不包含 HTML 相关包(`html` 与 `texhtml`);仅当插件安装到开启 `html` 选项的 markdown-it 实例时才加入默认列表。显式提供的
|
|
29
|
+
* `packages` 列表视为可信的开发者配置并原样使用。
|
|
30
|
+
*
|
|
24
31
|
* @default [
|
|
25
32
|
* 'action',
|
|
26
33
|
* 'ams',
|
|
@@ -44,17 +51,14 @@ interface MathJaxTexInputOptions {
|
|
|
44
51
|
* 'enclose',
|
|
45
52
|
* 'extpfeil',
|
|
46
53
|
* 'gensymb',
|
|
47
|
-
* 'html',
|
|
48
54
|
* 'mathtools',
|
|
49
55
|
* 'mhchem',
|
|
50
56
|
* 'newcommand',
|
|
51
57
|
* 'noerrors',
|
|
52
58
|
* 'noundefined',
|
|
53
59
|
* 'physics',
|
|
54
|
-
* 'require',
|
|
55
60
|
* 'setoptions',
|
|
56
61
|
* 'tagformat',
|
|
57
|
-
* 'texhtml',
|
|
58
62
|
* 'textcomp',
|
|
59
63
|
* 'textmacros',
|
|
60
64
|
* 'unicode',
|
|
@@ -309,8 +313,6 @@ interface MathjaxSVGOutputOptions extends MathjaxCommonOutputOptions {
|
|
|
309
313
|
/** For developers only */
|
|
310
314
|
wrapperFactory?: typeof SvgWrapperFactory;
|
|
311
315
|
}
|
|
312
|
-
//#endregion
|
|
313
|
-
//#region src/options.d.ts
|
|
314
316
|
type TeXTransformer = (content: string, displayMode: boolean) => string;
|
|
315
317
|
interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInlineWithSpace" | "delimiters" | "mathFence"> {
|
|
316
318
|
/**
|
|
@@ -322,9 +324,10 @@ interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInli
|
|
|
322
324
|
*/
|
|
323
325
|
output?: "chtml" | "svg";
|
|
324
326
|
/**
|
|
325
|
-
*
|
|
327
|
+
* Whether to include assistive MathML for screen readers. When disabled, math is still rendered
|
|
328
|
+
* but the hidden `<mjx-assistive-mml>` output is omitted.
|
|
326
329
|
*
|
|
327
|
-
*
|
|
330
|
+
* 是否包含供屏幕阅读器使用的辅助 MathML。关闭后数学公式仍会渲染,但不再输出隐藏的 `<mjx-assistive-mml>`。
|
|
328
331
|
*
|
|
329
332
|
* @default true
|
|
330
333
|
*/
|
|
@@ -362,35 +365,154 @@ interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInli
|
|
|
362
365
|
*/
|
|
363
366
|
debug?: boolean;
|
|
364
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Mathjax document options
|
|
370
|
+
*
|
|
371
|
+
* Mathjax 文档选项
|
|
372
|
+
*/
|
|
365
373
|
interface DocumentOptions {
|
|
374
|
+
/** Input jax / 输入 jax */
|
|
366
375
|
InputJax: TeX<LiteElement, string, HTMLElement>;
|
|
376
|
+
/** Output jax / 输出 jax */
|
|
367
377
|
OutputJax: CHTML<LiteElement, string, HTMLElement> | SVG<LiteElement, string, HTMLElement>;
|
|
378
|
+
/** Whether to enable assistive MML / 是否启用辅助 MML */
|
|
368
379
|
enableAssistiveMml: boolean;
|
|
369
380
|
}
|
|
370
|
-
/** Mathjax instance common options */
|
|
381
|
+
/** Mathjax instance common options / Mathjax 实例通用选项 */
|
|
371
382
|
interface MathjaxInstance<Sync extends boolean = false> extends Required<Pick<MarkdownItMathjaxOptions, "allowInlineWithSpace" | "delimiters" | "mathFence">> {
|
|
372
|
-
/** Mathjax adaptor */
|
|
383
|
+
/** Mathjax adaptor / Mathjax 适配器 */
|
|
373
384
|
adaptor: LiteAdaptor;
|
|
374
|
-
/** Mathjax document options */
|
|
385
|
+
/** Mathjax document options / Mathjax 文档选项 */
|
|
375
386
|
documentOptions: DocumentOptions;
|
|
376
387
|
/**
|
|
377
|
-
* Output style for rendered content
|
|
388
|
+
* Output style for rendered content; clears the style cache afterwards
|
|
389
|
+
*
|
|
390
|
+
* 已渲染内容的输出样式,返回后会清空样式缓存
|
|
378
391
|
*
|
|
379
|
-
* @returns Style
|
|
392
|
+
* @returns Style content / 样式内容
|
|
380
393
|
*/
|
|
381
394
|
outputStyle: () => Sync extends true ? string : Promise<string>;
|
|
382
|
-
/**
|
|
395
|
+
/** Render one formula synchronously / 同步渲染单个公式 */
|
|
396
|
+
render: (content: string, displayMode: boolean) => string;
|
|
397
|
+
/** Reset tex (including labels) / 重置 TeX(包含标签) */
|
|
383
398
|
reset: () => void;
|
|
384
|
-
/** Clear style cache */
|
|
399
|
+
/** Clear the style cache and reset both input and output jax / 清除样式缓存并重置输入与输出 jax */
|
|
385
400
|
clearStyle: () => void;
|
|
386
|
-
/** Output content transformer */
|
|
401
|
+
/** Output content transformer / 输出内容转换器 */
|
|
387
402
|
transformer: TeXTransformer | null;
|
|
388
403
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
404
|
+
/**
|
|
405
|
+
* Options of the experimental synchronous plugin.
|
|
406
|
+
*
|
|
407
|
+
* 同步插件选项。
|
|
408
|
+
*/
|
|
409
|
+
export interface MarkdownItSyncMathjaxOptions extends MarkdownItMathjaxOptions {
|
|
410
|
+
/**
|
|
411
|
+
* How formulas of a markdown document are converted.
|
|
412
|
+
*
|
|
413
|
+
* - `"batch"`: collect all formulas of the document and convert them in one worker round-trip when
|
|
414
|
+
* the outermost render finishes. Nested `md.render()` / `md.renderInline()` calls return
|
|
415
|
+
* internal placeholders until that flush.
|
|
416
|
+
* - `"immediate"`: convert every formula as soon as it is encountered, so nested render calls
|
|
417
|
+
* return final HTML immediately, at the cost of one worker round-trip per formula.
|
|
418
|
+
*
|
|
419
|
+
* 文档中公式的转换方式。
|
|
420
|
+
*
|
|
421
|
+
* - `"batch"`:收集整篇文档的公式,在最外层 render 结束时用一次 worker 往返转换;嵌套的 `md.render()` / `md.renderInline()` 在
|
|
422
|
+
* flush 前返回内部占位符。
|
|
423
|
+
* - `"immediate"`:遇到公式立即转换,嵌套 render 会立即返回最终 HTML,代价是每个公式一次 worker 往返。
|
|
424
|
+
*
|
|
425
|
+
* @default "batch"
|
|
426
|
+
*/
|
|
427
|
+
renderStrategy?: "batch" | "immediate";
|
|
428
|
+
/**
|
|
429
|
+
* Timeout of a single synchronous worker call in milliseconds.
|
|
430
|
+
*
|
|
431
|
+
* 单次同步 worker 调用的超时时间(毫秒)。
|
|
432
|
+
*
|
|
433
|
+
* @default 30000
|
|
434
|
+
*/
|
|
435
|
+
workerTimeout?: number;
|
|
436
|
+
/**
|
|
437
|
+
* Custom worker entry, used internally to test the source implementation against the built
|
|
438
|
+
* worker.
|
|
439
|
+
*
|
|
440
|
+
* 自定义 worker 入口,仅用于让源码实现对接构建后的 worker。
|
|
441
|
+
*
|
|
442
|
+
* @internal
|
|
443
|
+
*/
|
|
444
|
+
workerPath?: URL | string;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Synchronous MathJax methods, retrieved with `getMathjax(md)`.
|
|
448
|
+
*
|
|
449
|
+
* 同步 MathJax 方法集合,通过 `getMathjax(md)` 获取。
|
|
450
|
+
*/
|
|
451
|
+
export interface MathjaxMethods {
|
|
452
|
+
/** Clear the style cache and reset both input and output jax / 清除样式缓存并重置输入输出 jax */
|
|
453
|
+
clearStyle: () => void;
|
|
454
|
+
/** Terminate the worker-side session / 终止 worker 侧 session */
|
|
455
|
+
dispose: () => void;
|
|
456
|
+
/**
|
|
457
|
+
* Return the CSS content collected from all rendered formulas synchronously.
|
|
458
|
+
*
|
|
459
|
+
* 同步返回所有已渲染公式收集到的 CSS。
|
|
460
|
+
*/
|
|
461
|
+
outputStyle: () => string;
|
|
462
|
+
/** Reset TeX state (macros / labels) / 重置 TeX 状态(宏与标签) */
|
|
463
|
+
reset: () => void;
|
|
464
|
+
/**
|
|
465
|
+
* Initialize the worker and MathJax session synchronously, moving the one-time initialization
|
|
466
|
+
* cost (~100ms) away from the first document.
|
|
467
|
+
*
|
|
468
|
+
* 同步初始化 worker 与 MathJax session,把一次性初始化开销(约 100ms)从首篇文档移走。
|
|
469
|
+
*
|
|
470
|
+
* @param options - Warmup options / 预热选项
|
|
471
|
+
*/
|
|
472
|
+
warmup: (options?: WarmupOptions) => void;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Options of `getMathjax(md).warmup()`.
|
|
476
|
+
*
|
|
477
|
+
* `getMathjax(md).warmup()` 的选项。
|
|
478
|
+
*/
|
|
479
|
+
export interface WarmupOptions {
|
|
480
|
+
/**
|
|
481
|
+
* Also load all dynamic font files (adds ~73ms for SVG / ~35ms for CHTML on the first call).
|
|
482
|
+
*
|
|
483
|
+
* 同时加载全部动态字体文件(首次调用会增加 SVG 约 73ms / CHTML 约 35ms)。
|
|
484
|
+
*
|
|
485
|
+
* @default false
|
|
486
|
+
*/
|
|
487
|
+
preloadFonts?: boolean;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Create a synchronous MathJax plugin, sharing the MathJax state of the given markdown-it instance.
|
|
491
|
+
*
|
|
492
|
+
* 创建同步 MathJax 插件,并共享给定 markdown-it 实例的 MathJax 状态。
|
|
493
|
+
*
|
|
494
|
+
* @param md - MarkdownIt instance / MarkdownIt 实例
|
|
495
|
+
* @param options - Plugin options / 插件选项
|
|
496
|
+
*/
|
|
497
|
+
export declare const installSyncMathjax: (md: MarkdownIt, options?: MarkdownItSyncMathjaxOptions) => void;
|
|
498
|
+
/**
|
|
499
|
+
* Get the synchronous MathJax methods of a markdown-it instance.
|
|
500
|
+
*
|
|
501
|
+
* Unlike a `md.mathjax` property, this helper keeps the type augmentation local and avoids
|
|
502
|
+
* polluting the global `MarkdownIt` type for users that do not use this plugin.
|
|
503
|
+
*
|
|
504
|
+
* 获取某个 markdown-it 实例上的同步 MathJax 方法。相比挂 `md.mathjax` 属性,该 helper 不会污染全局 `MarkdownIt`
|
|
505
|
+
* 类型,也不会让所有实例多出一个可选属性。
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```ts
|
|
509
|
+
* const md = new MarkdownIt().use(mathjax, { output: "svg" });
|
|
510
|
+
* const { outputStyle } = getMathjax(md);
|
|
511
|
+
* const css = outputStyle();
|
|
512
|
+
* ```;
|
|
513
|
+
*
|
|
514
|
+
* @param md - MarkdownIt instance / MarkdownIt 实例
|
|
515
|
+
* @returns MathJax methods / MathJax 方法集合
|
|
516
|
+
*/
|
|
517
|
+
export declare const getMathjax: (md: MarkdownIt) => MathjaxMethods;
|
|
518
|
+
export { type DocumentOptions, type MarkdownItMathjaxOptions, type MathJaxTexInputOptions, type MathjaxCommonHTMLOutputOptions, type MathjaxCommonOutputOptions, type MathjaxFilter, type MathjaxFilterData, type MathjaxInstance, type MathjaxSVGOutputOptions, type TeXTransformer, type TexPackage, installSyncMathjax as mathjax };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{tex as e}from"@mdit/plugin-tex";
|
|
2
|
-
/* istanbul ignore next --
|
|
3
|
-
|
|
4
|
-
/* istanbul ignore next --
|
|
5
|
-
|
|
6
|
-
/* istanbul ignore
|
|
7
|
-
if(!
|
|
8
|
-
/* istanbul ignore
|
|
9
|
-
if(!
|
|
1
|
+
import{tex as e}from"@mdit/plugin-tex";import{createSyncFn as t}from"synckit";
|
|
2
|
+
/* istanbul ignore next -- the `.ts` branch only exists for in-repo tests; published entries are `.js` */
|
|
3
|
+
const n=import.meta.url.endsWith(`.ts`)?new URL(`../dist/worker.js`,import.meta.url):new URL(`worker.js`,import.meta.url),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new WeakMap,a=(e,n)=>{let i=e.toString(),a=r.get(i);if(a)return a;let o=t(e,{timeout:n});return r.set(i,o),o},o=[`fontData`,`wrapperFactory`,`cssStyles`,`preFilters`,`postFilters`],s=e=>{let t=[];e.tex?.formatError&&t.push(`tex.formatError`);for(let n of[`chtml`,`svg`]){let r=e[n];if(r){for(let e of o)e in r&&t.push(`${n}.${e}`);`linebreaks`in r&&r.linebreaks&&`LinebreakVisitor`in r.linebreaks&&t.push(`${n}.linebreaks.LinebreakVisitor`)}}return t},c=(e,t)=>{let r=s(e);if(r.length>0)throw TypeError(`[@mdit/plugin-mathjax-slim] the following options cannot be sent to the worker: ${r.join(`, `)}. Use "@mdit/plugin-mathjax-slim/async" instead.`);let{renderStrategy:i,transformer:a,workerPath:o,workerTimeout:c,...l}=e;try{structuredClone(l)}catch(e){throw TypeError(`[@mdit/plugin-mathjax-slim] options are not serializable: ${e.message}. Use "@mdit/plugin-mathjax-slim/async" instead.`,{cause:e})}return{depth:0,dirty:!1,disposed:!1,initialized:!1,items:[],nonce:crypto.randomUUID().replaceAll(`-`,``),sessionId:crypto.randomUUID(),options:l,enableHtml:t,renderStrategy:i??`batch`,transformer:a??null,timeout:c??3e4,workerUrl:o??n}},l=(e,t)=>{if(e.disposed)throw Error(`[@mdit/plugin-mathjax-slim] the instance has already been disposed`);let n=a(e.workerUrl,e.timeout);return e.initialized||=(n({type:`create`,sessionId:e.sessionId,options:e.options,enableHtml:e.enableHtml}),!0),n(t)},u=(e,t,n)=>{let r=l(e,{type:`render`,sessionId:e.sessionId,items:[{content:t,display:n}]});
|
|
4
|
+
/* istanbul ignore next -- defensive: the worker always returns html for a render request */
|
|
5
|
+
if(!(`html`in r))throw TypeError(`[@mdit/plugin-mathjax-slim] unexpected worker response for render`);let i=r.html[0];return e.transformer?e.transformer(i,n):i},d=(t,n={})=>{if(i.has(t))throw Error(`[@mdit/plugin-mathjax-slim] the mathjax plugin is already installed on this MarkdownIt instance`);let r=c(n,t.options.html),a=new RegExp(String.raw`\u0002mjx-${r.nonce}-(\d+)\u0003`,`g`),o=e=>`\u0002mjx-${r.nonce}-${e}\u0003`,s=e=>{let t=r.items;if(r.items=[],t.length===0)return e;let n=l(r,{type:`render`,sessionId:r.sessionId,items:t});
|
|
6
|
+
/* istanbul ignore next -- defensive: the worker always returns html for a render request */
|
|
7
|
+
if(!(`html`in n))throw TypeError(`[@mdit/plugin-mathjax-slim] unexpected worker response for render`);let i=n.html;return e.replaceAll(a,(e,n)=>{let a=Number(n),o=i[a];return r.transformer?r.transformer(o,t[a].display):o})};t.use(e,{allowInlineWithSpace:n.allowInlineWithSpace,delimiters:n.delimiters,mathFence:n.mathFence,render:(e,t)=>{if(r.dirty=!0,r.renderStrategy===`immediate`)return u(r,e,t);let n=r.items.length;return r.items.push({content:e,display:t}),o(n)}});let d=t.renderer.render.bind(t.renderer);t.renderer.render=function(e,t,n){r.depth+=1;try{let i=d(e,t,n);return r.renderStrategy===`immediate`?i:r.depth===1?s(i):i}catch(e){throw r.depth===1&&(r.items=[]),e}finally{--r.depth,r.depth===0&&r.initialized&&r.dirty&&(r.dirty=!1,l(r,{type:`reset`,sessionId:r.sessionId}))}},i.set(t,{clearStyle:()=>{r.initialized&&l(r,{type:`clearStyle`,sessionId:r.sessionId})},dispose:()=>{r.disposed||(r.initialized&&l(r,{type:`dispose`,sessionId:r.sessionId}),r.disposed=!0,i.delete(t))},outputStyle:()=>{let e=l(r,{type:`style`,sessionId:r.sessionId});
|
|
8
|
+
/* istanbul ignore next -- defensive: the worker always returns style for a style request */
|
|
9
|
+
if(!(`style`in e))throw TypeError(`[@mdit/plugin-mathjax-slim] unexpected worker response for style`);return e.style},reset:()=>{r.initialized&&l(r,{type:`reset`,sessionId:r.sessionId})},warmup:e=>{l(r,{type:`warmup`,sessionId:r.sessionId,preloadFonts:e?.preloadFonts??!1})}})},f=e=>{let t=i.get(e);if(!t)throw Error("[@mdit/plugin-mathjax-slim] mathjax is not installed on this MarkdownIt instance. Use `md.use(mathjax, options)` first.");return t};export{f as getMathjax,d as installSyncMathjax,d as mathjax};
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["texPackages","texLoaders","loadTexPackages","packages","pkg","USER_MAPS","clearUserState","InputJax","handler","name","AssistiveMmlHandler","CHTML","RegisterHTMLHandler","SVG","TeX","chtmlFont","liteAdaptor","mathjaxLib","svgFont","isMathJaxInstalled","isMathJaxNewcmFontInstalled","getDocumentOptions","isCHTML","options","userOptions","outputOptions","file","createMathjaxInstance","documentOptions","adaptor","clearStyle","OutputJax","style","mathjax","render","md","renderInline","src","env","reset","tex","mathDocument","content","displayMode","result","transformer"],"sources":["../src/tex/packages.ts","../src/tex/loader.ts","../src/tex/utils.ts","../src/utils.ts","../src/plugin.ts"],"sourcesContent":["import type { TexPackage } from \"../mathjax.js\";\n\nexport const texPackages: TexPackage[] = [\n \"action\",\n \"ams\",\n \"amscd\",\n \"bbm\",\n \"bboldx\",\n \"bbox\",\n \"begingroup\",\n \"boldsymbol\",\n \"braket\",\n \"bussproofs\",\n \"cancel\",\n \"cases\",\n \"centernot\",\n \"color\",\n \"colortbl\",\n \"colorv2\",\n \"configmacros\",\n \"dsfont\",\n \"empheq\",\n \"enclose\",\n \"extpfeil\",\n \"gensymb\",\n \"html\",\n \"mathtools\",\n \"mhchem\",\n \"newcommand\",\n \"noerrors\",\n \"noundefined\",\n \"physics\",\n \"setoptions\",\n \"tagformat\",\n \"texhtml\",\n \"textcomp\",\n \"textmacros\",\n \"unicode\",\n \"units\",\n \"upgreek\",\n \"verb\",\n];\n","import type { TexPackage } from \"../mathjax.js\";\n\nexport const texLoaders: Record<TexPackage, () => Promise<unknown>> = {\n action: () => import(\"@mathjax/src/js/input/tex/action/ActionConfiguration.js\"),\n ams: () => import(\"@mathjax/src/js/input/tex/ams/AmsConfiguration.js\"),\n amscd: () => import(\"@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js\"),\n bbm: () => import(\"@mathjax/src/js/input/tex/bbm/BbmConfiguration.js\"),\n bboldx: () => import(\"@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js\"),\n bbox: () => import(\"@mathjax/src/js/input/tex/bbox/BboxConfiguration.js\"),\n begingroup: () => import(\"@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js\"),\n boldsymbol: () => import(\"@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js\"),\n braket: () => import(\"@mathjax/src/js/input/tex/braket/BraketConfiguration.js\"),\n bussproofs: () => import(\"@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js\"),\n cancel: () => import(\"@mathjax/src/js/input/tex/cancel/CancelConfiguration.js\"),\n cases: () => import(\"@mathjax/src/js/input/tex/cases/CasesConfiguration.js\"),\n centernot: () => import(\"@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js\"),\n color: () => import(\"@mathjax/src/js/input/tex/color/ColorConfiguration.js\"),\n colortbl: () => import(\"@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js\"),\n colorv2: () => import(\"@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js\"),\n configmacros: () => import(\"@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js\"),\n dsfont: () => import(\"@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js\"),\n empheq: () => import(\"@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js\"),\n enclose: () => import(\"@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js\"),\n extpfeil: () => import(\"@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js\"),\n gensymb: () => import(\"@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js\"),\n html: () => import(\"@mathjax/src/js/input/tex/html/HtmlConfiguration.js\"),\n mathtools: () => import(\"@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js\"),\n mhchem: () => import(\"@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js\"),\n newcommand: () => import(\"@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js\"),\n noerrors: () => import(\"@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js\"),\n noundefined: () => import(\"@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js\"),\n physics: () => import(\"@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js\"),\n setoptions: () => import(\"@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js\"),\n tagformat: () => import(\"@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js\"),\n texhtml: () => import(\"@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js\"),\n textcomp: () => import(\"@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js\"),\n textmacros: () => import(\"@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js\"),\n unicode: () => import(\"@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js\"),\n units: () => import(\"@mathjax/src/js/input/tex/units/UnitsConfiguration.js\"),\n upgreek: () => import(\"@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js\"),\n verb: () => import(\"@mathjax/src/js/input/tex/verb/VerbConfiguration.js\"),\n};\n","import type { TexPackage } from \"../mathjax.js\";\nimport { texLoaders } from \"./loader.js\";\nimport { texPackages } from \"./packages.js\";\n\nexport const loadTexPackages = async (packages: TexPackage[] = texPackages): Promise<void> => {\n await import(\"@mathjax/src/js/input/tex/base/BaseConfiguration.js\");\n\n await Promise.all(\n packages.filter((pkg) => texPackages.includes(pkg)).map((pkg) => texLoaders[pkg]()),\n );\n};\n","import type { LiteElement } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type { TeX } from \"@mathjax/src/js/input/tex.js\";\nimport type { HandlerType } from \"@mathjax/src/js/input/tex/HandlerTypes.js\";\n\ninterface TeXMacroMap {\n map: Map<string, unknown>;\n}\n\nconst USER_MAPS: { handler: HandlerType; name: string }[] = [\n { handler: \"macro\" as HandlerType.MACRO, name: \"new-Command\" },\n { handler: \"environment\" as HandlerType.ENVIRONMENT, name: \"new-Environment\" },\n { handler: \"delimiter\" as HandlerType.DELIMITER, name: \"new-Delimiter\" },\n];\n\n/**\n * Clear user-defined TeX state (macros/environments/delimiters) on a MathJax TeX input jax.\n *\n * MathJax stores user-defined macros, environments and delimiters in dedicated `new-*` maps that\n * are separate from the built-in maps, and `InputJax.reset()` does not clear them, so they would\n * leak across documents rendered by the same instance. This reaches into the internal maps to\n * remove only user-defined entries.\n *\n * 清除 MathJax TeX 输入 jax 上由 `\\newcommand`/`\\def`/`\\newenvironment` 等定义的用户状态。\n *\n * MathJax 将用户自定义的宏、环境与分隔符存放在独立的 `new-*` 映射中,与内置映射分离,且 `InputJax.reset()`\n * 不会清除它们,因此同一实例渲染多篇文档时状态会跨文档泄漏。此处直接访问内部映射,仅移除用户自定义条目。\n *\n * @param InputJax - MathJax TeX input jax / MathJax TeX 输入 jax\n */\nexport const clearUserState = (InputJax: TeX<LiteElement, string, HTMLElement>): void => {\n for (const { handler, name } of USER_MAPS) {\n const handlerMap = InputJax.parseOptions.handlers.get(handler);\n const userMap = handlerMap.retrieve(name) as unknown as TeXMacroMap | null;\n\n userMap?.map.clear();\n }\n};\n","/** Forked from https://github.com/tani/markdown-it-mathjax3/blob/master/index.ts */\n\nimport type { MathJaxNewcmFont as chtmlFontType } from \"@mathjax/mathjax-newcm-font/js/chtml.js\";\nimport type { MathJaxNewcmFont as svgFontType } from \"@mathjax/mathjax-newcm-font/js/svg.js\";\nimport type { AssistiveMmlHandler as AssistiveMmlHandlerType } from \"@mathjax/src/js/a11y/assistive-mml.js\";\nimport type { LiteDocument } from \"@mathjax/src/js/adaptors/lite/Document.js\";\nimport type { LiteElement, LiteNode } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type { LiteText } from \"@mathjax/src/js/adaptors/lite/Text.js\";\nimport type { liteAdaptor as liteAdaptorType } from \"@mathjax/src/js/adaptors/liteAdaptor.js\";\nimport type { MathDocument } from \"@mathjax/src/js/core/MathDocument.js\";\nimport type { RegisterHTMLHandler as RegisterHTMLHandlerType } from \"@mathjax/src/js/handlers/html.js\";\nimport type { TeX as TeXType } from \"@mathjax/src/js/input/tex.js\";\nimport type { mathjax as mathjaxType } from \"@mathjax/src/js/mathjax.js\";\nimport type { CHTML as CHTMLType } from \"@mathjax/src/js/output/chtml.js\";\nimport type { SVG as SVGType } from \"@mathjax/src/js/output/svg.js\";\nimport { tex } from \"@mdit/plugin-tex\";\nimport type { MarkdownIt } from \"markdown-it\";\n\nimport type { MarkdownItMathjaxOptions, DocumentOptions, MathjaxInstance } from \"./options.js\";\nimport { loadTexPackages, texPackages } from \"./tex/index.js\";\nimport { clearUserState } from \"./utils.js\";\n\nlet AssistiveMmlHandler: typeof AssistiveMmlHandlerType,\n CHTML: typeof CHTMLType,\n RegisterHTMLHandler: typeof RegisterHTMLHandlerType,\n SVG: typeof SVGType,\n TeX: typeof TeXType,\n chtmlFont: typeof chtmlFontType,\n liteAdaptor: typeof liteAdaptorType,\n mathjaxLib: typeof mathjaxType,\n svgFont: typeof svgFontType;\nlet isMathJaxInstalled = true;\nlet isMathJaxNewcmFontInstalled = true;\n\ntry {\n ({ mathjax: mathjaxLib } = await import(\"@mathjax/src/js/mathjax.js\"));\n ({ TeX } = await import(\"@mathjax/src/js/input/tex.js\"));\n ({ CHTML } = await import(\"@mathjax/src/js/output/chtml.js\"));\n ({ SVG } = await import(\"@mathjax/src/js/output/svg.js\"));\n ({ liteAdaptor } = await import(\"@mathjax/src/js/adaptors/liteAdaptor.js\"));\n ({ RegisterHTMLHandler } = await import(\"@mathjax/src/js/handlers/html.js\"));\n ({ AssistiveMmlHandler } = await import(\"@mathjax/src/js/a11y/assistive-mml.js\"));\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxInstalled = false;\n}\n\ntry {\n chtmlFont = (await import(\"@mathjax/mathjax-newcm-font/js/chtml.js\")).MathJaxNewcmFont;\n svgFont = (await import(\"@mathjax/mathjax-newcm-font/js/svg.js\")).MathJaxNewcmFont;\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxNewcmFontInstalled = false;\n}\n\nexport const getDocumentOptions = async (\n options: MarkdownItMathjaxOptions,\n): Promise<DocumentOptions> => {\n /* istanbul ignore if -- @preserve */\n if (!isMathJaxInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/src\" is not installed!');\n\n const isCHTML = options.output === \"chtml\";\n const userOptions = (isCHTML ? options.chtml : options.svg) ?? {};\n\n /* istanbul ignore if -- @preserve */\n if (!userOptions.fontData && !isMathJaxNewcmFontInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/mathjax-newcm-font\" is not installed!');\n\n const outputOptions = Object.assign(\n {\n fontData: isCHTML ? chtmlFont : svgFont,\n },\n // fontURL can be set to undefined if you want to bundle the fonts yourself\n // both fontURL and dynamicPrefix shall be synced with fontData, so set it to undefined if fontData is customized\n userOptions?.fontData\n ? {}\n : { dynamicPrefix: `@mathjax/mathjax-newcm-font/js/${isCHTML ? \"chtml\" : \"svg\"}/dynamic` },\n isCHTML && !userOptions.fontData\n ? { fontURL: \"https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2\" }\n : {},\n userOptions,\n );\n\n mathjaxLib.asyncLoad = (file): Promise<unknown> => {\n if (options.debug)\n // oxlint-disable-next-line no-console\n console.debug(`[MathJax]: loading ${file}...`);\n\n return import(file);\n };\n\n await loadTexPackages(options.tex?.packages);\n\n return {\n InputJax: new TeX<LiteElement, string, HTMLElement>({\n packages: [\"base\", ...texPackages],\n ...options.tex,\n }),\n OutputJax: new (isCHTML ? CHTML : SVG)<LiteElement, string, HTMLElement>(outputOptions),\n enableAssistiveMml: options.a11y !== false,\n };\n};\n\nexport const createMathjaxInstance = async (\n options: MarkdownItMathjaxOptions = {},\n): Promise<MathjaxInstance | null> => {\n const documentOptions = await getDocumentOptions(options);\n\n const { OutputJax, InputJax } = documentOptions;\n\n const adaptor = liteAdaptor();\n // oxlint-disable-next-line new-cap\n const handler = RegisterHTMLHandler(adaptor);\n\n // oxlint-disable-next-line new-cap\n if (options.a11y !== false) AssistiveMmlHandler<LiteNode, LiteText, LiteDocument>(handler);\n\n const clearStyle = (): void => {\n // if there is no adaptor, output jax is not initialized yet, so nothing to clear\n if (OutputJax.adaptor == null) return;\n\n InputJax.reset();\n OutputJax.reset();\n };\n\n const reset = (): void => {\n InputJax.reset();\n clearUserState(InputJax);\n };\n\n const outputStyle = async (): Promise<string> => {\n await OutputJax.font.loadDynamicFiles();\n\n const style = adaptor.cssText(\n OutputJax.styleSheet(\n mathjaxLib.document(\"\", documentOptions) as MathDocument<LiteElement, string, HTMLElement>,\n ),\n );\n\n clearStyle();\n\n return style;\n };\n\n return {\n adaptor,\n documentOptions,\n allowInlineWithSpace: options.allowInlineWithSpace ?? false,\n delimiters: options.delimiters ?? \"dollars\",\n mathFence: options.mathFence ?? false,\n clearStyle,\n reset,\n outputStyle,\n transformer: options.transformer ?? null,\n };\n};\n\nexport const mathjax = (\n md: MarkdownIt,\n {\n allowInlineWithSpace,\n adaptor,\n delimiters,\n documentOptions,\n mathFence,\n reset,\n transformer,\n }: MathjaxInstance,\n): void => {\n // Reset the shared TeX input state (macros/labels) after each render so that\n // state does not leak across documents rendered by the same instance.\n const render = md.render.bind(md);\n const renderInline = md.renderInline.bind(md);\n\n md.render = (src, env): string => {\n try {\n return render(src, env);\n } finally {\n reset();\n }\n };\n md.renderInline = (src, env): string => {\n try {\n return renderInline(src, env);\n } finally {\n reset();\n }\n };\n\n md.use(tex, {\n allowInlineWithSpace,\n delimiters,\n mathFence,\n render: (content, displayMode) => {\n const mathDocument = mathjaxLib.document(content, documentOptions).convert(content, {\n display: displayMode,\n }) as LiteElement;\n\n const result = adaptor.outerHTML(mathDocument);\n\n return transformer?.(result, displayMode) ?? result;\n },\n });\n};\n"],"mappings":"A,uCAEA,MAAaA,EAA4B,gVAuCzC,ECvCaC,EAAyD,CACpE,WAAc,OAAO,2DACrB,QAAW,OAAO,qDAClB,UAAa,OAAO,yDACpB,QAAW,OAAO,qDAClB,WAAc,OAAO,2DACrB,SAAY,OAAO,uDACnB,eAAkB,OAAO,mEACzB,eAAkB,OAAO,mEACzB,WAAc,OAAO,2DACrB,eAAkB,OAAO,mEACzB,WAAc,OAAO,2DACrB,UAAa,OAAO,yDACpB,cAAiB,OAAO,iEACxB,UAAa,OAAO,yDACpB,aAAgB,OAAO,+DACvB,YAAe,OAAO,6DACtB,iBAAoB,OAAO,uEAC3B,WAAc,OAAO,2DACrB,WAAc,OAAO,2DACrB,YAAe,OAAO,6DACtB,aAAgB,OAAO,+DACvB,YAAe,OAAO,6DACtB,SAAY,OAAO,uDACnB,cAAiB,OAAO,iEACxB,WAAc,OAAO,2DACrB,eAAkB,OAAO,mEACzB,aAAgB,OAAO,+DACvB,gBAAmB,OAAO,qEAC1B,YAAe,OAAO,6DACtB,eAAkB,OAAO,mEACzB,cAAiB,OAAO,iEACxB,YAAe,OAAO,6DACtB,aAAgB,OAAO,+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T,EAWE,YAAaT,EAAQ,aAAe,IACtC,CACF,EAEaU,GACX,EACA,CACE,uBACA,UACA,aACA,kBACA,YACA,QACA,iBAEO,CAGT,IAAMC,EAASC,EAAG,OAAO,KAAKA,CAAE,EAC1BC,EAAeD,EAAG,aAAa,KAAKA,CAAE,EAE5C,EAAG,QAAU,EAAK,IAAgB,CAChC,GAAI,CACF,OAAOD,EAAOG,EAAKC,CAAG,CACxB,QAAU,CACRC,EAAM,CACR,CACF,EACA,EAAG,cAAgB,EAAK,IAAgB,CACtC,GAAI,CACF,OAAOH,EAAaC,EAAKC,CAAG,CAC9B,QAAU,CACRC,EAAM,CACR,CACF,EAEAJ,EAAG,IAAIK,EAAK,CACV,uBACA,aACA,YACA,QAAS,EAAS,IAAgB,CAChC,IAAMC,EAAexB,EAAW,SAASyB,EAASd,CAAe,CAAC,CAAC,QAAQc,EAAS,CAClF,QAASC,CACX,CAAC,EAEKC,EAASf,EAAQ,UAAUY,CAAY,EAE7C,OAAOI,IAAcD,EAAQD,CAAW,GAAKC,CAC/C,CACF,CAAC,CACH,E"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["WORKER_URL","syncFnCache","mathjaxMethods","getSyncFn","key","workerPath","cached","syncFn","createSyncFn","FORBIDDEN_OUTPUT_OPTION_KEYS","collectUnsupportedOptions","names","options","outputName","outputOptions","createRuntime","unsupported","serializableOptions","err","renderStrategy","transformer","workerTimeout","requestWorker","state","worker","request","convertImmediate","response","value","display","installSyncMathjax","md","placeholderRegExp","placeholderFor","index","flush","items","html","rendered","itemIndex","tex","content","originalRender","result","tokens","renderOptions","env","warmupOptions","getMathjax","methods"],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * Synchronous MathJax plugin, used like every other markdown-it plugin:\n *\n * ```ts\n * const md = new MarkdownIt().use(mathjax, { output: \"svg\" });\n * const html = md.render(\"$x$\"); // fully synchronous\n * const { outputStyle } = getMathjax(md);\n * const css = outputStyle(); // fully synchronous\n * ```\n *\n * Node.js implementation: MathJax's official async API runs in a worker thread and `synckit` blocks\n * the main thread on the results. One IPC round-trip is made per markdown-it render pass (formulas\n * are collected through placeholders and flushed together); everything else (e.g. `transformer`)\n * stays on the main thread.\n *\n * 同步 MathJax 插件:像普通 markdown-it 插件一样使用,渲染全同步。 Node 侧用 synckit + worker 执行 MathJax 官方异步 API,每篇文档一次\n * IPC 批量往返。\n */\n\nimport { tex } from \"@mdit/plugin-tex\";\nimport type { MarkdownIt } from \"markdown-it\";\nimport { createSyncFn } from \"synckit\";\nimport type { Syncify } from \"synckit\";\n\nimport type { MarkdownItMathjaxOptions, TeXTransformer } from \"./options.js\";\nimport type {\n MathjaxItem,\n SerializableMathjaxOptions,\n WorkerRequest,\n WorkerResponse,\n} from \"./protocol.js\";\n\n/**\n * Options of the experimental synchronous plugin.\n *\n * 同步插件选项。\n */\nexport interface MarkdownItSyncMathjaxOptions extends MarkdownItMathjaxOptions {\n /**\n * How formulas of a markdown document are converted.\n *\n * - `\"batch\"`: collect all formulas of the document and convert them in one worker round-trip when\n * the outermost render finishes. Nested `md.render()` / `md.renderInline()` calls return\n * internal placeholders until that flush.\n * - `\"immediate\"`: convert every formula as soon as it is encountered, so nested render calls\n * return final HTML immediately, at the cost of one worker round-trip per formula.\n *\n * 文档中公式的转换方式。\n *\n * - `\"batch\"`:收集整篇文档的公式,在最外层 render 结束时用一次 worker 往返转换;嵌套的 `md.render()` / `md.renderInline()` 在\n * flush 前返回内部占位符。\n * - `\"immediate\"`:遇到公式立即转换,嵌套 render 会立即返回最终 HTML,代价是每个公式一次 worker 往返。\n *\n * @default \"batch\"\n */\n renderStrategy?: \"batch\" | \"immediate\";\n\n /**\n * Timeout of a single synchronous worker call in milliseconds.\n *\n * 单次同步 worker 调用的超时时间(毫秒)。\n *\n * @default 30000\n */\n workerTimeout?: number;\n\n /**\n * Custom worker entry, used internally to test the source implementation against the built\n * worker.\n *\n * 自定义 worker 入口,仅用于让源码实现对接构建后的 worker。\n *\n * @internal\n */\n workerPath?: URL | string;\n}\n\n/**\n * Synchronous MathJax methods, retrieved with `getMathjax(md)`.\n *\n * 同步 MathJax 方法集合,通过 `getMathjax(md)` 获取。\n */\nexport interface MathjaxMethods {\n /** Clear the style cache and reset both input and output jax / 清除样式缓存并重置输入输出 jax */\n clearStyle: () => void;\n\n /** Terminate the worker-side session / 终止 worker 侧 session */\n dispose: () => void;\n\n /**\n * Return the CSS content collected from all rendered formulas synchronously.\n *\n * 同步返回所有已渲染公式收集到的 CSS。\n */\n outputStyle: () => string;\n\n /** Reset TeX state (macros / labels) / 重置 TeX 状态(宏与标签) */\n reset: () => void;\n\n /**\n * Initialize the worker and MathJax session synchronously, moving the one-time initialization\n * cost (~100ms) away from the first document.\n *\n * 同步初始化 worker 与 MathJax session,把一次性初始化开销(约 100ms)从首篇文档移走。\n *\n * @param options - Warmup options / 预热选项\n */\n warmup: (options?: WarmupOptions) => void;\n}\n\n/**\n * Options of `getMathjax(md).warmup()`.\n *\n * `getMathjax(md).warmup()` 的选项。\n */\nexport interface WarmupOptions {\n /**\n * Also load all dynamic font files (adds ~73ms for SVG / ~35ms for CHTML on the first call).\n *\n * 同时加载全部动态字体文件(首次调用会增加 SVG 约 73ms / CHTML 约 35ms)。\n *\n * @default false\n */\n preloadFonts?: boolean;\n}\n\ntype WorkerFn = (request: WorkerRequest) => WorkerResponse | Promise<WorkerResponse>;\n\ninterface RuntimeState {\n depth: number;\n dirty: boolean;\n disposed: boolean;\n initialized: boolean;\n items: MathjaxItem[];\n nonce: string;\n sessionId: string;\n options: SerializableMathjaxOptions;\n enableHtml: boolean;\n renderStrategy: \"batch\" | \"immediate\";\n transformer: TeXTransformer | null;\n timeout: number;\n workerUrl: URL | string;\n}\n\n// Source mode (`vitest` importing `src/index.ts`) has no built worker next to it, so fall\n// back to the package build output. The published entry always resolves `dist/worker.js`.\n/* istanbul ignore next -- the `.ts` branch only exists for in-repo tests; published entries are `.js` */\nconst WORKER_URL = import.meta.url.endsWith(\".ts\")\n ? new URL(\"../dist/worker.js\", import.meta.url)\n : new URL(\"worker.js\", import.meta.url);\nconst DEFAULT_WORKER_TIMEOUT = 30_000;\n\nconst syncFnCache = new Map<string, Syncify<WorkerFn>>();\n\n/**\n * Registered MathJax runtimes, keyed by the markdown-it instance.\n *\n * 已注册的 MathJax 运行时,以 markdown-it 实例为键。\n */\nconst mathjaxMethods = new WeakMap<MarkdownIt, MathjaxMethods>();\n\nconst getSyncFn = (workerPath: URL | string, timeout: number): Syncify<WorkerFn> => {\n const key = workerPath.toString();\n const cached = syncFnCache.get(key);\n\n if (cached) return cached;\n\n const syncFn = createSyncFn<WorkerFn>(workerPath, { timeout });\n\n syncFnCache.set(key, syncFn);\n\n return syncFn;\n};\n\nconst FORBIDDEN_OUTPUT_OPTION_KEYS = [\n \"fontData\",\n \"wrapperFactory\",\n \"cssStyles\",\n \"preFilters\",\n \"postFilters\",\n] as const;\n\nconst collectUnsupportedOptions = (options: MarkdownItSyncMathjaxOptions): string[] => {\n const names: string[] = [];\n\n if (options.tex?.formatError) names.push(\"tex.formatError\");\n\n for (const outputName of [\"chtml\", \"svg\"] as const) {\n const outputOptions = options[outputName];\n\n if (!outputOptions) continue;\n\n for (const key of FORBIDDEN_OUTPUT_OPTION_KEYS)\n if (key in outputOptions) names.push(`${outputName}.${key}`);\n\n if (\n \"linebreaks\" in outputOptions &&\n outputOptions.linebreaks &&\n \"LinebreakVisitor\" in outputOptions.linebreaks\n )\n names.push(`${outputName}.linebreaks.LinebreakVisitor`);\n }\n\n return names;\n};\n\nconst createRuntime = (\n options: MarkdownItSyncMathjaxOptions,\n enableHtml: boolean,\n): RuntimeState => {\n const unsupported = collectUnsupportedOptions(options);\n\n if (unsupported.length > 0) {\n throw new TypeError(\n `[@mdit/plugin-mathjax-slim] the following options cannot be sent to the worker: ${unsupported.join(\", \")}. Use \"@mdit/plugin-mathjax-slim/async\" instead.`,\n );\n }\n\n const { renderStrategy, transformer, workerPath, workerTimeout, ...serializableOptions } =\n options;\n\n try {\n // Fail early with a clear error instead of a DataCloneError inside the worker.\n structuredClone(serializableOptions);\n } catch (err) {\n throw new TypeError(\n `[@mdit/plugin-mathjax-slim] options are not serializable: ${(err as Error).message}. Use \"@mdit/plugin-mathjax-slim/async\" instead.`,\n { cause: err },\n );\n }\n\n const nonce = crypto.randomUUID().replaceAll(\"-\", \"\");\n\n return {\n depth: 0,\n dirty: false,\n disposed: false,\n initialized: false,\n items: [],\n nonce,\n sessionId: crypto.randomUUID(),\n options: serializableOptions,\n enableHtml,\n renderStrategy: renderStrategy ?? \"batch\",\n transformer: transformer ?? null,\n timeout: workerTimeout ?? DEFAULT_WORKER_TIMEOUT,\n workerUrl: workerPath ?? WORKER_URL,\n };\n};\n\nconst requestWorker = (state: RuntimeState, request: WorkerRequest): WorkerResponse => {\n if (state.disposed)\n throw new Error(\"[@mdit/plugin-mathjax-slim] the instance has already been disposed\");\n\n const worker = getSyncFn(state.workerUrl, state.timeout);\n\n if (!state.initialized) {\n worker({\n type: \"create\",\n sessionId: state.sessionId,\n options: state.options,\n enableHtml: state.enableHtml,\n });\n\n state.initialized = true;\n }\n\n return worker(request);\n};\n\n/**\n * Convert one formula immediately in the worker (used by the `immediate` render strategy).\n *\n * 立即在 worker 中转换单个公式(用于 `immediate` 渲染策略)。\n *\n * @param state - Runtime state / 运行时状态\n * @param content - TeX content / TeX 内容\n * @param display - Whether it is display math / 是否行间公式\n * @returns Rendered HTML / 渲染后的 HTML\n */\nconst convertImmediate = (state: RuntimeState, content: string, display: boolean): string => {\n const response = requestWorker(state, {\n type: \"render\",\n sessionId: state.sessionId,\n items: [{ content, display }],\n });\n\n /* istanbul ignore next -- defensive: the worker always returns html for a render request */\n if (!(\"html\" in response))\n throw new TypeError(\"[@mdit/plugin-mathjax-slim] unexpected worker response for render\");\n\n const value = response.html[0];\n\n return state.transformer ? state.transformer(value, display) : value;\n};\n\n/**\n * Create a synchronous MathJax plugin, sharing the MathJax state of the given markdown-it instance.\n *\n * 创建同步 MathJax 插件,并共享给定 markdown-it 实例的 MathJax 状态。\n *\n * @param md - MarkdownIt instance / MarkdownIt 实例\n * @param options - Plugin options / 插件选项\n */\nexport const installSyncMathjax = (\n md: MarkdownIt,\n options: MarkdownItSyncMathjaxOptions = {},\n): void => {\n if (mathjaxMethods.has(md)) {\n throw new Error(\n \"[@mdit/plugin-mathjax-slim] the mathjax plugin is already installed on this MarkdownIt instance\",\n );\n }\n\n const state = createRuntime(options, md.options.html);\n const placeholderRegExp = new RegExp(String.raw`\\u0002mjx-${state.nonce}-(\\d+)\\u0003`, \"g\");\n\n const placeholderFor = (index: number): string => `\\u0002mjx-${state.nonce}-${index}\\u0003`;\n\n const flush = (html: string): string => {\n const items = state.items;\n\n state.items = [];\n\n if (items.length === 0) return html;\n\n const response = requestWorker(state, {\n type: \"render\",\n sessionId: state.sessionId,\n items,\n });\n\n /* istanbul ignore next -- defensive: the worker always returns html for a render request */\n if (!(\"html\" in response))\n throw new TypeError(\"[@mdit/plugin-mathjax-slim] unexpected worker response for render\");\n\n const rendered = response.html;\n\n return html.replaceAll(placeholderRegExp, (_, index: string) => {\n const itemIndex = Number(index);\n const value = rendered[itemIndex];\n\n return state.transformer ? state.transformer(value, items[itemIndex].display) : value;\n });\n };\n\n md.use(tex, {\n allowInlineWithSpace: options.allowInlineWithSpace,\n delimiters: options.delimiters,\n mathFence: options.mathFence,\n render: (content, display) => {\n state.dirty = true;\n\n if (state.renderStrategy === \"immediate\") return convertImmediate(state, content, display);\n\n const index = state.items.length;\n\n state.items.push({ content, display });\n\n return placeholderFor(index);\n },\n });\n\n // `batch` collects formulas for the whole render pass and flushes them in one worker round-trip\n // at the outermost return; `immediate` has nothing left to do here besides the document reset.\n const originalRender = md.renderer.render.bind(md.renderer);\n\n md.renderer.render = function render(tokens, renderOptions, env): string {\n state.depth += 1;\n\n try {\n const result = originalRender(tokens, renderOptions, env);\n\n if (state.renderStrategy === \"immediate\") return result;\n\n return state.depth === 1 ? flush(result) : result;\n } catch (err) {\n // A failed render pass never reaches the worker, but its collected items\n // would otherwise be flushed with the next document and leak TeX state\n // (e.g. \\newcommand) into it.\n /* istanbul ignore next -- a nested render throwing is covered by the outer pass */\n if (state.depth === 1) state.items = [];\n\n throw err;\n } finally {\n state.depth -= 1;\n\n // Reset TeX/macro state once per document (and only when math was rendered), not once per\n // formula, so documents without math do not pay a worker round-trip at all.\n if (state.depth === 0 && state.initialized && state.dirty) {\n state.dirty = false;\n requestWorker(state, { type: \"reset\", sessionId: state.sessionId });\n }\n }\n };\n\n const methods: MathjaxMethods = {\n clearStyle: (): void => {\n if (!state.initialized) return;\n\n requestWorker(state, { type: \"clearStyle\", sessionId: state.sessionId });\n },\n dispose: (): void => {\n if (state.disposed) return;\n\n if (state.initialized) requestWorker(state, { type: \"dispose\", sessionId: state.sessionId });\n\n state.disposed = true;\n mathjaxMethods.delete(md);\n },\n outputStyle: (): string => {\n const response = requestWorker(state, { type: \"style\", sessionId: state.sessionId });\n\n /* istanbul ignore next -- defensive: the worker always returns style for a style request */\n if (!(\"style\" in response))\n throw new TypeError(\"[@mdit/plugin-mathjax-slim] unexpected worker response for style\");\n\n return response.style;\n },\n reset: (): void => {\n if (!state.initialized) return;\n\n requestWorker(state, { type: \"reset\", sessionId: state.sessionId });\n },\n warmup: (warmupOptions?: WarmupOptions): void => {\n requestWorker(state, {\n type: \"warmup\",\n sessionId: state.sessionId,\n preloadFonts: warmupOptions?.preloadFonts ?? false,\n });\n },\n };\n\n mathjaxMethods.set(md, methods);\n};\n\n/**\n * Get the synchronous MathJax methods of a markdown-it instance.\n *\n * Unlike a `md.mathjax` property, this helper keeps the type augmentation local and avoids\n * polluting the global `MarkdownIt` type for users that do not use this plugin.\n *\n * 获取某个 markdown-it 实例上的同步 MathJax 方法。相比挂 `md.mathjax` 属性,该 helper 不会污染全局 `MarkdownIt`\n * 类型,也不会让所有实例多出一个可选属性。\n *\n * @example\n * ```ts\n * const md = new MarkdownIt().use(mathjax, { output: \"svg\" });\n * const { outputStyle } = getMathjax(md);\n * const css = outputStyle();\n * ```;\n *\n * @param md - MarkdownIt instance / MarkdownIt 实例\n * @returns MathJax methods / MathJax 方法集合\n */\nexport const getMathjax = (md: MarkdownIt): MathjaxMethods => {\n const methods = mathjaxMethods.get(md);\n\n if (!methods) {\n throw new Error(\n \"[@mdit/plugin-mathjax-slim] mathjax is not installed on this MarkdownIt instance. Use `md.use(mathjax, options)` first.\",\n );\n }\n\n return methods;\n};\n"],"mappings":";;AAmJA,MAAMA,EAAa,YAAY,IAAI,SAAS,KAAK,EAC7C,IAAI,IAAI,oBAAqB,YAAY,GAAG,EAC5C,IAAI,IAAI,YAAa,YAAY,GAAG,EAGlCC,kBAAc,IAAI,IAOlBC,kBAAiB,IAAI,QAErBC,GAAa,EAA0B,IAAuC,CAClF,IAAMC,EAAMC,EAAW,SAAS,EAC1BC,EAASL,EAAY,IAAIG,CAAG,EAElC,GAAIE,EAAQ,OAAOA,EAEnB,IAAMC,EAASC,EAAuBH,EAAY,CAAE,SAAQ,CAAC,EAI7D,OAFAJ,EAAY,IAAIG,EAAKG,CAAM,EAEpBA,CACT,EAEME,EAA+B,CACnC,WACA,iBACA,YACA,aACA,aACF,EAEMC,EAA6B,GAAoD,CACrF,IAAMC,EAAkB,CAAC,EAErBC,EAAQ,KAAK,aAAaD,EAAM,KAAK,iBAAiB,EAE1D,IAAK,IAAME,IAAc,CAAC,QAAS,KAAK,EAAY,CAClD,IAAMC,EAAgBF,EAAQC,GAE9B,GAAKC,EAEL,KAAK,IAAMV,KAAOK,EACZL,KAAOU,GAAeH,EAAM,KAAK,GAAGE,EAAW,GAAGT,GAAK,EAG3D,eAAgBU,GAChBA,EAAc,YACd,qBAAsBA,EAAc,YAEpCH,EAAM,KAAK,GAAGE,EAAW,6BAA6B,CAPK,CAQ/D,CAEA,OAAOF,CACT,EAEMI,GACJ,EACA,IACiB,CACjB,IAAMC,EAAcN,EAA0BE,CAAO,EAErD,GAAII,EAAY,OAAS,EACvB,MAAU,UACR,mFAAmFA,EAAY,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AFIK,EAAM,QAAU,IAAG,EAAM,MAAQ,CAAC,GAEhCL,CACR,QAAU,CACR,IAAM,MAIFK,EAAM,QAAU,GAAKA,EAAM,aAAeA,EAAM,QAClD,EAAM,MAAQ,GACdD,EAAcC,EAAO,CAAE,KAAM,QAAS,UAAWA,EAAM,SAAU,CAAC,EAEtE,CACF,EAuCArB,EAAe,IAAI6B,EAAI,CApCrB,eAAwB,CACjBR,EAAM,aAEXD,EAAcC,EAAO,CAAE,KAAM,aAAc,UAAWA,EAAM,SAAU,CAAC,CACzE,EACA,YAAqB,CACfA,EAAM,WAENA,EAAM,aAAaD,EAAcC,EAAO,CAAE,KAAM,UAAW,UAAWA,EAAM,SAAU,CAAC,EAE3F,EAAM,SAAW,GACjBrB,EAAe,OAAO6B,CAAE,EAC1B,EACA,gBAA2B,CACzB,IAAMJ,EAAWL,EAAcC,EAAO,CAAE,KAAM,QAAS,UAAWA,EAAM,SAAU,CAAC;;AAGnF,GAAI,EAAE,UAAWI,GACf,MAAU,UAAU,kEAAkE,EAExF,OAAOA,EAAS,KAClB,EACA,UAAmB,CACZJ,EAAM,aAEXD,EAAcC,EAAO,CAAE,KAAM,QAAS,UAAWA,EAAM,SAAU,CAAC,CACpE,EACA,OAAS,GAAwC,CAC/CD,EAAcC,EAAO,CACnB,KAAM,SACN,UAAWA,EAAM,UACjB,aAAcwB,GAAe,cAAgB,EAC/C,CAAC,CACH,CAG2B,CAAC,CAChC,EAqBaC,EAAc,GAAmC,CAC5D,IAAMC,EAAU/C,EAAe,IAAI6B,CAAE,EAErC,GAAI,CAACkB,EACH,MAAU,MACR,yHACF,EAGF,OAAOA,CACT,E"}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{runAsWorker as e}from"synckit";const t={action:()=>import(`@mathjax/src/js/input/tex/action/ActionConfiguration.js`),ams:()=>import(`@mathjax/src/js/input/tex/ams/AmsConfiguration.js`),amscd:()=>import(`@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js`),bbm:()=>import(`@mathjax/src/js/input/tex/bbm/BbmConfiguration.js`),bboldx:()=>import(`@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js`),bbox:()=>import(`@mathjax/src/js/input/tex/bbox/BboxConfiguration.js`),begingroup:()=>import(`@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js`),boldsymbol:()=>import(`@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js`),braket:()=>import(`@mathjax/src/js/input/tex/braket/BraketConfiguration.js`),bussproofs:()=>import(`@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js`),cancel:()=>import(`@mathjax/src/js/input/tex/cancel/CancelConfiguration.js`),cases:()=>import(`@mathjax/src/js/input/tex/cases/CasesConfiguration.js`),centernot:()=>import(`@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js`),color:()=>import(`@mathjax/src/js/input/tex/color/ColorConfiguration.js`),colortbl:()=>import(`@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js`),colorv2:()=>import(`@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js`),configmacros:()=>import(`@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js`),dsfont:()=>import(`@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js`),empheq:()=>import(`@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js`),enclose:()=>import(`@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js`),extpfeil:()=>import(`@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js`),gensymb:()=>import(`@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js`),html:()=>import(`@mathjax/src/js/input/tex/html/HtmlConfiguration.js`),mathtools:()=>import(`@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js`),mhchem:()=>import(`@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js`),newcommand:()=>import(`@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js`),noerrors:()=>import(`@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js`),noundefined:()=>import(`@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js`),physics:()=>import(`@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js`),setoptions:()=>import(`@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js`),tagformat:()=>import(`@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js`),texhtml:()=>import(`@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js`),textcomp:()=>import(`@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js`),textmacros:()=>import(`@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js`),unicode:()=>import(`@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js`),units:()=>import(`@mathjax/src/js/input/tex/units/UnitsConfiguration.js`),upgreek:()=>import(`@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js`),verb:()=>import(`@mathjax/src/js/input/tex/verb/VerbConfiguration.js`)},n=/* @__PURE__ */ `action.ams.amscd.bbox.begingroup.boldsymbol.braket.bussproofs.cancel.cases.centernot.color.colortbl.colorv2.configmacros.empheq.enclose.extpfeil.gensymb.mathtools.mhchem.newcommand.noerrors.noundefined.physics.setoptions.tagformat.textcomp.textmacros.unicode.units.upgreek.verb`.split(`.`),r=[`html`,`texhtml`],i=(e,t=!1)=>{let i=/* @__PURE__ */ new Set([`base`]);if(e)for(let t of e)i.add(t);else{for(let e of n)i.add(e);if(t)for(let e of r)i.add(e)}return[...i]},a=[`new-Command`,`new-Environment`,`new-Delimiter`],o=e=>{for(let t of a)e.parseOptions.handlers.retrieve(t)?.map.clear()};let s=null,c=null;const l=async()=>(s??=(async()=>{try{let[e,t,n,r,i,a,o]=await Promise.all([import(`@mathjax/src/js/mathjax.js`),import(`@mathjax/src/js/input/tex.js`),import(`@mathjax/src/js/output/chtml.js`),import(`@mathjax/src/js/output/svg.js`),import(`@mathjax/src/js/adaptors/liteAdaptor.js`),import(`@mathjax/src/js/handlers/html.js`),import(`@mathjax/src/js/a11y/assistive-mml.js`)]);return{AssistiveMmlHandler:o.AssistiveMmlHandler,CHTML:n.CHTML,RegisterHTMLHandler:a.RegisterHTMLHandler,SVG:r.SVG,TeX:t.TeX,liteAdaptor:i.liteAdaptor,mathjax:e.mathjax}}catch{
|
|
2
|
+
/* istanbul ignore next -- @preserve */
|
|
3
|
+
throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/src" is not installed!`)}})(),s),u=async()=>(c??=(async()=>{try{let[e,t]=await Promise.all([import(`@mathjax/mathjax-newcm-font/js/chtml.js`),import(`@mathjax/mathjax-newcm-font/js/svg.js`)]);return{chtml:e.MathJaxNewcmFont,svg:t.MathJaxNewcmFont}}catch{
|
|
4
|
+
/* istanbul ignore next -- @preserve */
|
|
5
|
+
throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/mathjax-newcm-font" is not installed!`)}})(),c),d=async e=>{await import(`@mathjax/src/js/input/tex/base/BaseConfiguration.js`),await Promise.all(e.filter(e=>Object.hasOwn(t,e)).map(e=>t[e]()))},f=async(e,t=!1)=>{let{AssistiveMmlHandler:n,CHTML:r,RegisterHTMLHandler:a,SVG:s,TeX:c,liteAdaptor:f,mathjax:p}=await l(),m=e.output===`chtml`,h=(m?e.chtml:e.svg)??{},g=h.fontData??(m?(await u()).chtml:(await u()).svg),_=Object.assign({fontData:g},h.fontData?{}:{dynamicPrefix:`@mathjax/mathjax-newcm-font/js/${m?`chtml`:`svg`}/dynamic`},m&&!h.fontData?{fontURL:`https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2`}:{},h);p.asyncLoad=e=>import(e);let{packages:v,...y}=e.tex??{},b=i(v,t);await d(b);let x=new c({...y,packages:b}),S=new(m?r:s)(_),C=f();n(a(C));let w={InputJax:x,OutputJax:S,enableAssistiveMml:e.a11y!==!1},T=()=>{S.adaptor!=null&&(x.reset(),S.reset())},E=()=>{x.reset(),o(x)},D=null,O=()=>D??=p.document(``,w);return{adaptor:C,documentOptions:w,InputJax:x,OutputJax:S,clearStyle:T,preloadFonts:async()=>{await S.font.loadDynamicFiles()},reset:E,async render(e){let t=O(),n=[];for(let r of e){let e=await t.convertPromise(r.content,{display:r.display});n.push(C.outerHTML(e))}return n},async style(){await S.font.loadDynamicFiles();let e=C.cssText(S.styleSheet(p.document(``,w)));return T(),e}}},p=/* @__PURE__ */ new Map,m=e=>{
|
|
6
|
+
/* istanbul ignore file -- executed in a worker_thread, not instrumented by vitest/istanbul */
|
|
7
|
+
let t=p.get(e);if(!t)throw Error(`[@mdit/plugin-mathjax-slim] unknown session: ${e}`);return t};e(async e=>{switch(e.type){case`create`:return p.set(e.sessionId,await f(e.options,e.enableHtml)),{ok:!0};case`render`:return{html:await m(e.sessionId).render(e.items)};case`warmup`:return e.preloadFonts&&await m(e.sessionId).preloadFonts(),{ok:!0};case`style`:return{style:await m(e.sessionId).style()};case`reset`:return m(e.sessionId).reset(),{ok:!0};case`clearStyle`:return m(e.sessionId).clearStyle(),{ok:!0};case`dispose`:return p.delete(e.sessionId),{ok:!0};default:throw Error(`[@mdit/plugin-mathjax-slim] unknown request: ${String(e)}`)}});
|
|
8
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","names":["texLoaders","texPackages","HTML_PACKAGES","resolveTexPackages","packages","userPackages","pkg","enableHtml","USER_MAP_NAMES","clearUserState","name","InputJax","coreModulesPromise","fontModulesPromise","loadCoreModules","mathjaxModule","TeXModule","CHTMLModule","SVGModule","adaptorModule","handlerModule","a11yModule","loadFontModules","chtmlModule","svgModule","loadTexPackage","createSession","mathjaxLib","isCHTML","options","userOptions","fontData","outputOptions","file","texOptions","TeX","OutputJax","CHTML","SVG","adaptor","liteAdaptor","AssistiveMmlHandler","RegisterHTMLHandler","documentOptions","clearStyle","reset","mathDocument","getDocument","document","html","item","items","node","style","sessions","getSession","session","sessionId","runAsWorker","request"],"sources":["../src/tex/loader.ts","../src/tex/packages.ts","../src/tex/utils.ts","../src/utils.ts","../src/session.ts","../src/worker.ts"],"sourcesContent":["import type { TexPackage } from \"../mathjax.js\";\n\nexport const texLoaders: Record<TexPackage, () => Promise<unknown>> = {\n action: () => import(\"@mathjax/src/js/input/tex/action/ActionConfiguration.js\"),\n ams: () => import(\"@mathjax/src/js/input/tex/ams/AmsConfiguration.js\"),\n amscd: () => import(\"@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js\"),\n bbm: () => import(\"@mathjax/src/js/input/tex/bbm/BbmConfiguration.js\"),\n bboldx: () => import(\"@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js\"),\n bbox: () => import(\"@mathjax/src/js/input/tex/bbox/BboxConfiguration.js\"),\n begingroup: () => import(\"@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js\"),\n boldsymbol: () => import(\"@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js\"),\n braket: () => import(\"@mathjax/src/js/input/tex/braket/BraketConfiguration.js\"),\n bussproofs: () => import(\"@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js\"),\n cancel: () => import(\"@mathjax/src/js/input/tex/cancel/CancelConfiguration.js\"),\n cases: () => import(\"@mathjax/src/js/input/tex/cases/CasesConfiguration.js\"),\n centernot: () => import(\"@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js\"),\n color: () => import(\"@mathjax/src/js/input/tex/color/ColorConfiguration.js\"),\n colortbl: () => import(\"@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js\"),\n colorv2: () => import(\"@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js\"),\n configmacros: () => import(\"@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js\"),\n dsfont: () => import(\"@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js\"),\n empheq: () => import(\"@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js\"),\n enclose: () => import(\"@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js\"),\n extpfeil: () => import(\"@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js\"),\n gensymb: () => import(\"@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js\"),\n html: () => import(\"@mathjax/src/js/input/tex/html/HtmlConfiguration.js\"),\n mathtools: () => import(\"@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js\"),\n mhchem: () => import(\"@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js\"),\n newcommand: () => import(\"@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js\"),\n noerrors: () => import(\"@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js\"),\n noundefined: () => import(\"@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js\"),\n physics: () => import(\"@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js\"),\n setoptions: () => import(\"@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js\"),\n tagformat: () => import(\"@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js\"),\n texhtml: () => import(\"@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js\"),\n textcomp: () => import(\"@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js\"),\n textmacros: () => import(\"@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js\"),\n unicode: () => import(\"@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js\"),\n units: () => import(\"@mathjax/src/js/input/tex/units/UnitsConfiguration.js\"),\n upgreek: () => import(\"@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js\"),\n verb: () => import(\"@mathjax/src/js/input/tex/verb/VerbConfiguration.js\"),\n};\n","import type { TexPackage } from \"../mathjax.js\";\n\n/**\n * Default TeX packages.\n *\n * The HTML-related packages (`html`, which provides `\\href`, `\\class`, `\\style` and `\\cssId`, and\n * `texhtml`, which registers the `<tex-html>` handler) are intentionally excluded. They are added\n * to the default list when the markdown-it instance enables raw HTML (`new MarkdownIt({ html: true\n * })`), or can be enabled explicitly through `tex.packages`, see `resolveTexPackages` in\n * `./utils.ts`.\n *\n * The font-extension packages (`bbm`, `bboldx` and `dsfont`) are also excluded: the bundled\n * `@mathjax/mathjax-newcm-font` font does not ship their extension data, so loading them would\n * replace standard macros (e.g. `\\mathbb`) with missing font variants and fall back with an\n * `Invalid variant` warning. They can still be enabled explicitly through `tex.packages`.\n *\n * 默认 TeX 包。\n *\n * 提供 `\\href`、`\\class`、`\\style`、`\\cssId` 等能力的 HTML 相关包(`html`)与注册 `<tex-html>` 处理器的 `texhtml`\n * 默认不启用:仅在 markdown-it 实例开启 `html: true` 时加入默认列表,或通过 `tex.packages` 显式启用, 见 `./utils.ts` 的\n * `resolveTexPackages`。\n *\n * 依赖字体扩展数据的 `bbm`、`bboldx`、`dsfont` 同样默认不启用:随包的 `@mathjax/mathjax-newcm-font`\n * 字体不包含这些扩展数据,加载后会用缺失的字体变体替换标准宏(如 `\\mathbb`)并触发 `Invalid variant` 警告后回退。 仍可通过 `tex.packages` 显式启用。\n */\nexport const texPackages: TexPackage[] = [\n \"action\",\n \"ams\",\n \"amscd\",\n \"bbox\",\n \"begingroup\",\n \"boldsymbol\",\n \"braket\",\n \"bussproofs\",\n \"cancel\",\n \"cases\",\n \"centernot\",\n \"color\",\n \"colortbl\",\n \"colorv2\",\n \"configmacros\",\n \"empheq\",\n \"enclose\",\n \"extpfeil\",\n \"gensymb\",\n \"mathtools\",\n \"mhchem\",\n \"newcommand\",\n \"noerrors\",\n \"noundefined\",\n \"physics\",\n \"setoptions\",\n \"tagformat\",\n \"textcomp\",\n \"textmacros\",\n \"unicode\",\n \"units\",\n \"upgreek\",\n \"verb\",\n];\n","import type { TexPackage } from \"../mathjax.js\";\nimport { texLoaders } from \"./loader.js\";\nimport { texPackages } from \"./packages.js\";\n\n/**\n * TeX packages that provide HTML-related capabilities: `html` adds `\\href`, `\\class`, `\\style` and\n * `\\cssId`, and `texhtml` registers the `<tex-html>` handler (inert unless MathJax's `allowTexHTML`\n * option is enabled).\n *\n * 提供 HTML 相关能力的 TeX 包:`html` 提供 `\\href`、`\\class`、`\\style`、`\\cssId`;`texhtml` 注册 `<tex-html>`\n * 处理器(除非开启 MathJax 的 `allowTexHTML` 选项,否则不生效)。\n */\nconst HTML_PACKAGES: TexPackage[] = [\"html\", \"texhtml\"];\n\n/**\n * Resolve the TeX packages to load.\n *\n * The default package list never contains the HTML-related packages; they are only added to that\n * default list when the markdown-it instance enables raw HTML. An explicit `tex.packages` list is\n * treated as trusted developer configuration and used as-is, so enabling the HTML-related packages\n * is possible even when markdown-it itself has raw HTML disabled.\n *\n * 解析需要加载的 TeX 包。\n *\n * 默认包列表从不包含 HTML 相关包;仅当 markdown-it 实例开启原始 HTML 时才会把它们加入默认列表。 显式提供的 `tex.packages`\n * 视为可信的开发者配置并原样使用,因此即使 markdown-it 关闭原始 HTML,也可以启用 HTML 相关包。\n *\n * @param userPackages - User-defined packages / 用户定义的包\n * @param enableHtml - Whether markdown-it enables HTML / markdown-it 是否开启 HTML\n * @returns Resolved package list with `base` first / 解析后的包列表(`base` 在最前)\n */\nexport const resolveTexPackages = (\n userPackages?: TexPackage[],\n enableHtml = false,\n): TexPackage[] => {\n // `base` is always loaded and is not part of the public `TexPackage` union.\n // `base` 总会加载,且不在公开的 `TexPackage` 联合类型中。\n const packages = new Set<string>([\"base\"]);\n\n if (userPackages) {\n // Trusted developer configuration: use the list as-is.\n // 可信的开发者配置:原样使用该列表。\n for (const pkg of userPackages) packages.add(pkg);\n } else {\n for (const pkg of texPackages) packages.add(pkg);\n\n // The markdown-it `html` option only decides the default package list.\n // markdown-it 的 `html` 选项只决定默认包列表。\n if (enableHtml) for (const pkg of HTML_PACKAGES) packages.add(pkg);\n }\n\n return [...packages] as TexPackage[];\n};\n\n/**\n * Load the given TeX packages with MathJax's official async API.\n *\n * 使用 MathJax 官方异步 API 加载指定的 TeX 包。\n *\n * @param packages - Packages to load / 需要加载的包\n * @returns Promise resolved when all packages are loaded / 所有包加载完成时 resolve 的 Promise\n */\nexport const loadTexPackages = async (packages: TexPackage[] = texPackages): Promise<void> => {\n await import(\"@mathjax/src/js/input/tex/base/BaseConfiguration.js\");\n\n await Promise.all(\n packages.filter((pkg) => Object.hasOwn(texLoaders, pkg)).map((pkg) => texLoaders[pkg]()),\n );\n};\n","import type { LiteElement } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type { TeX } from \"@mathjax/src/js/input/tex.js\";\n\ninterface TeXMacroMap {\n map: Map<string, unknown>;\n}\n\n// MathJax keeps user-defined macros, environments and delimiters in the internal `new-*` maps of\n// the `newcommand` package. Their names are unique across handler types, so they can be looked up\n// by name, which avoids importing the `HandlerType` enum: a value import would add a runtime import\n// of the optional `@mathjax/src` peer to the `worker` and `async/index` entries.\nconst USER_MAP_NAMES = [\"new-Command\", \"new-Environment\", \"new-Delimiter\"] as const;\n\n/**\n * Clear user-defined TeX state (macros/environments/delimiters) on a MathJax TeX input jax.\n *\n * MathJax stores user-defined macros, environments and delimiters in dedicated `new-*` maps that\n * are separate from the built-in maps, and `InputJax.reset()` does not clear them, so they would\n * leak across documents rendered by the same instance. This reaches into the internal maps to\n * remove only user-defined entries.\n *\n * 清除 MathJax TeX 输入 jax 上由 `\\newcommand`/`\\def`/`\\newenvironment` 等定义的用户状态。\n *\n * MathJax 将用户自定义的宏、环境与分隔符存放在独立的 `new-*` 映射中,与内置映射分离,且 `InputJax.reset()`\n * 不会清除它们,因此同一实例渲染多篇文档时状态会跨文档泄漏。此处直接访问内部映射,仅移除用户自定义条目。\n *\n * @param InputJax - MathJax TeX input jax / MathJax TeX 输入 jax\n */\nexport const clearUserState = (InputJax: TeX<LiteElement, string, HTMLElement>): void => {\n for (const name of USER_MAP_NAMES) {\n const userMap = InputJax.parseOptions.handlers.retrieve(name) as unknown as TeXMacroMap | null;\n\n userMap?.map.clear();\n }\n};\n","/**\n * Synckit-based synchronous MathJax runtime for `@mdit/plugin-mathjax-slim`.\n *\n * This module is only imported from the worker entry (`worker.ts`) and from tests. It is the single\n * source of truth for MathJax setup and uses **only** the official async APIs: `mathjax.asyncLoad =\n * (file) => import(file)`, `loadTexPackages()`, `document.convertPromise()` and\n * `font.loadDynamicFiles()`.\n *\n * `@mathjax/src` and `@mathjax/mathjax-newcm-font` are optional peer dependencies of this package,\n * so every MathJax module is imported dynamically and cached. A missing dependency raises a\n * descriptive error, which synckit forwards from the worker to the main thread.\n *\n * 同步 MathJax 运行时,只在 worker 入口导入,完整走官方异步 API。由于 `@mathjax/src` 与 `@mathjax/mathjax-newcm-font`\n * 是本包的可选 peer 依赖,所有 MathJax 模块均动态导入并缓存;缺失依赖时抛出 清晰错误,并由 synckit 从 worker 传回主线程。\n */\n\nimport type { MathJaxNewcmFont as ChtmlFontType } from \"@mathjax/mathjax-newcm-font/js/chtml.js\";\nimport type { MathJaxNewcmFont as SvgFontType } from \"@mathjax/mathjax-newcm-font/js/svg.js\";\nimport type { AssistiveMmlHandler as AssistiveMmlHandlerType } from \"@mathjax/src/js/a11y/assistive-mml.js\";\nimport type { LiteElement } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type {\n LiteAdaptor,\n liteAdaptor as liteAdaptorType,\n} from \"@mathjax/src/js/adaptors/liteAdaptor.js\";\nimport type { MathDocument } from \"@mathjax/src/js/core/MathDocument.js\";\nimport type { RegisterHTMLHandler as RegisterHTMLHandlerType } from \"@mathjax/src/js/handlers/html.js\";\nimport type { TeX as TeXType } from \"@mathjax/src/js/input/tex.js\";\nimport type { mathjax as mathjaxType } from \"@mathjax/src/js/mathjax.js\";\nimport type { CHTML as CHTMLType } from \"@mathjax/src/js/output/chtml.js\";\nimport type { SVG as SVGType } from \"@mathjax/src/js/output/svg.js\";\n\nimport type { DocumentOptions } from \"./options.js\";\nimport type { MathjaxItem, SerializableMathjaxOptions } from \"./protocol.js\";\nimport { texLoaders } from \"./tex/loader.js\";\nimport { resolveTexPackages } from \"./tex/utils.js\";\nimport { clearUserState } from \"./utils.js\";\n\ntype InputJax = TeXType<LiteElement, string, HTMLElement>;\ntype OutputJax =\n | CHTMLType<LiteElement, string, HTMLElement>\n | SVGType<LiteElement, string, HTMLElement>;\n\ninterface Session {\n adaptor: LiteAdaptor;\n documentOptions: DocumentOptions;\n InputJax: InputJax;\n OutputJax: OutputJax;\n clearStyle: () => void;\n preloadFonts: () => Promise<void>;\n render: (items: MathjaxItem[]) => Promise<string[]>;\n reset: () => void;\n style: () => Promise<string>;\n}\n\ninterface MathjaxModules {\n AssistiveMmlHandler: typeof AssistiveMmlHandlerType;\n CHTML: typeof CHTMLType;\n RegisterHTMLHandler: typeof RegisterHTMLHandlerType;\n SVG: typeof SVGType;\n TeX: typeof TeXType;\n liteAdaptor: typeof liteAdaptorType;\n mathjax: typeof mathjaxType;\n}\n\ninterface MathjaxFontModules {\n chtml: typeof ChtmlFontType;\n svg: typeof SvgFontType;\n}\n\nconst MATHJAX_SRC_MISSING = '[@mdit/plugin-mathjax-slim] \"@mathjax/src\" is not installed!';\nconst MATHJAX_FONT_MISSING =\n '[@mdit/plugin-mathjax-slim] \"@mathjax/mathjax-newcm-font\" is not installed!';\n\nlet coreModulesPromise: Promise<MathjaxModules> | null = null;\nlet fontModulesPromise: Promise<MathjaxFontModules> | null = null;\n\nconst loadCoreModules = async (): Promise<MathjaxModules> => {\n coreModulesPromise ??= (async (): Promise<MathjaxModules> => {\n try {\n const [\n mathjaxModule,\n TeXModule,\n CHTMLModule,\n SVGModule,\n adaptorModule,\n handlerModule,\n a11yModule,\n ] = await Promise.all([\n import(\"@mathjax/src/js/mathjax.js\"),\n import(\"@mathjax/src/js/input/tex.js\"),\n import(\"@mathjax/src/js/output/chtml.js\"),\n import(\"@mathjax/src/js/output/svg.js\"),\n import(\"@mathjax/src/js/adaptors/liteAdaptor.js\"),\n import(\"@mathjax/src/js/handlers/html.js\"),\n import(\"@mathjax/src/js/a11y/assistive-mml.js\"),\n ]);\n\n return {\n AssistiveMmlHandler: a11yModule.AssistiveMmlHandler,\n CHTML: CHTMLModule.CHTML,\n RegisterHTMLHandler: handlerModule.RegisterHTMLHandler,\n SVG: SVGModule.SVG,\n TeX: TeXModule.TeX,\n liteAdaptor: adaptorModule.liteAdaptor,\n mathjax: mathjaxModule.mathjax,\n };\n } catch {\n /* istanbul ignore next -- @preserve */\n throw new Error(MATHJAX_SRC_MISSING);\n }\n })();\n\n return coreModulesPromise;\n};\n\nconst loadFontModules = async (): Promise<MathjaxFontModules> => {\n fontModulesPromise ??= (async (): Promise<MathjaxFontModules> => {\n try {\n const [chtmlModule, svgModule] = await Promise.all([\n import(\"@mathjax/mathjax-newcm-font/js/chtml.js\"),\n import(\"@mathjax/mathjax-newcm-font/js/svg.js\"),\n ]);\n\n return {\n chtml: chtmlModule.MathJaxNewcmFont,\n svg: svgModule.MathJaxNewcmFont,\n };\n } catch {\n /* istanbul ignore next -- @preserve */\n throw new Error(MATHJAX_FONT_MISSING);\n }\n })();\n\n return fontModulesPromise;\n};\n\nconst loadTexPackage = async (packages: string[]): Promise<void> => {\n await import(\"@mathjax/src/js/input/tex/base/BaseConfiguration.js\");\n\n await Promise.all(\n packages\n .filter((pkg) => Object.hasOwn(texLoaders, pkg))\n .map((pkg) => texLoaders[pkg as keyof typeof texLoaders]()),\n );\n};\n\nexport const createSession = async (\n options: SerializableMathjaxOptions,\n enableHtml = false,\n): Promise<Session> => {\n const modules = await loadCoreModules();\n const {\n AssistiveMmlHandler,\n CHTML,\n RegisterHTMLHandler,\n SVG,\n TeX,\n liteAdaptor,\n mathjax: mathjaxLib,\n } = modules;\n\n const isCHTML = options.output === \"chtml\";\n const userOptions = (isCHTML ? options.chtml : options.svg) ?? {};\n const fontData =\n userOptions.fontData ??\n (isCHTML ? (await loadFontModules()).chtml : (await loadFontModules()).svg);\n const outputOptions = Object.assign(\n { fontData },\n userOptions.fontData\n ? {}\n : { dynamicPrefix: `@mathjax/mathjax-newcm-font/js/${isCHTML ? \"chtml\" : \"svg\"}/dynamic` },\n isCHTML && !userOptions.fontData\n ? { fontURL: \"https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2\" }\n : {},\n userOptions,\n );\n\n // Official async loading contract. Everything the worker pulls in is a real\n // dynamic import; no `createRequire`, no `asyncIsSynchronous`.\n mathjaxLib.asyncLoad = (file): Promise<unknown> => import(file);\n\n const { packages: userPackages, ...texOptions } = options.tex ?? {};\n const packages = resolveTexPackages(userPackages, enableHtml);\n\n await loadTexPackage(packages);\n\n const InputJax = new TeX<LiteElement, string, HTMLElement>({\n ...texOptions,\n packages,\n });\n const OutputJax = new (isCHTML ? CHTML : SVG)<LiteElement, string, HTMLElement>(outputOptions);\n\n const adaptor = liteAdaptor();\n // oxlint-disable-next-line new-cap\n const handler = RegisterHTMLHandler(adaptor);\n // Always mix in the a11y document so that `enableAssistiveMml` can be decided\n // per document (MathJax picks the first registered global handler, so making\n // it conditional per session would leak the first session's choice).\n // oxlint-disable-next-line new-cap\n AssistiveMmlHandler(handler);\n\n const documentOptions: DocumentOptions = {\n InputJax,\n OutputJax,\n enableAssistiveMml: options.a11y !== false,\n };\n\n const clearStyle = (): void => {\n // if there is no adaptor, output jax is not initialized yet, so nothing to clear\n if (OutputJax.adaptor == null) return;\n\n InputJax.reset();\n OutputJax.reset();\n };\n\n const reset = (): void => {\n InputJax.reset();\n clearUserState(InputJax);\n };\n\n // Reuse one MathJax document for the whole session lifetime: MathJax's document API supports\n // repeated conversions, and reusing it avoids rebuilding handlers/factories for every document.\n let mathDocument: MathDocument<LiteElement, string, HTMLElement> | null = null;\n\n const getDocument = (): MathDocument<LiteElement, string, HTMLElement> =>\n (mathDocument ??= mathjaxLib.document(\"\", documentOptions) as MathDocument<\n LiteElement,\n string,\n HTMLElement\n >);\n\n return {\n adaptor,\n documentOptions,\n InputJax,\n OutputJax,\n clearStyle,\n preloadFonts: async (): Promise<void> => {\n await OutputJax.font.loadDynamicFiles();\n },\n reset,\n async render(items: MathjaxItem[]): Promise<string[]> {\n const document = getDocument();\n const html: string[] = [];\n\n for (const item of items) {\n // oxlint-disable-next-line no-await-in-loop\n const node = await document.convertPromise(item.content, { display: item.display });\n\n html.push(adaptor.outerHTML(node as LiteElement));\n }\n\n return html;\n },\n async style(): Promise<string> {\n // Official async font loading (no sync hack).\n await OutputJax.font.loadDynamicFiles();\n\n const style = adaptor.cssText(\n OutputJax.styleSheet(\n mathjaxLib.document(\"\", documentOptions) as MathDocument<\n LiteElement,\n string,\n HTMLElement\n >,\n ),\n );\n\n clearStyle();\n\n return style;\n },\n };\n};\n\nexport type { Session };\n","/* istanbul ignore file -- executed in a worker_thread, not instrumented by vitest/istanbul */\n/**\n * Worker entry for the synchronous MathJax plugin of `@mdit/plugin-mathjax-slim`.\n *\n * The worker owns all MathJax state and runs the official async flow (`convertPromise` /\n * `loadDynamicFiles`). The main thread talks to it through synckit and blocks synchronously.\n *\n * `@mathjax/src` and `@mathjax/mathjax-newcm-font` are optional peer dependencies, so the worker\n * loads them dynamically in `session.ts`; a missing dependency is reported back to the main thread\n * as a regular synckit error.\n *\n * 同步 MathJax 插件的 worker 入口:worker 内持有 MathJax 状态并完整走官方异步流程, 主线程通过 synckit 同步阻塞调用。 MathJax 相关包为可选\n * peer 依赖,由 session.ts 动态加载,缺失时错误会经 synckit 传回主线程。\n */\n\nimport { runAsWorker } from \"synckit\";\n\nimport type { WorkerRequest, WorkerResponse } from \"./protocol.js\";\nimport type { Session } from \"./session.js\";\nimport { createSession } from \"./session.js\";\n\nconst sessions = new Map<string, Session>();\n\nconst getSession = (sessionId: string): Session => {\n const session = sessions.get(sessionId);\n\n if (!session) throw new Error(`[@mdit/plugin-mathjax-slim] unknown session: ${sessionId}`);\n\n return session;\n};\n\nrunAsWorker(async (request: WorkerRequest): Promise<WorkerResponse> => {\n switch (request.type) {\n case \"create\": {\n sessions.set(request.sessionId, await createSession(request.options, request.enableHtml));\n\n return { ok: true };\n }\n\n case \"render\": {\n return { html: await getSession(request.sessionId).render(request.items) };\n }\n\n case \"warmup\": {\n if (request.preloadFonts) await getSession(request.sessionId).preloadFonts();\n\n return { ok: true };\n }\n\n case \"style\": {\n return { style: await getSession(request.sessionId).style() };\n }\n\n case \"reset\": {\n getSession(request.sessionId).reset();\n\n return { ok: true };\n }\n\n case \"clearStyle\": {\n getSession(request.sessionId).clearStyle();\n\n return { ok: true };\n }\n\n case \"dispose\": {\n sessions.delete(request.sessionId);\n\n return { ok: true };\n }\n\n default: {\n throw new Error(`[@mdit/plugin-mathjax-slim] unknown request: ${String(request)}`);\n }\n }\n});\n"],"mappings":"A,sCAEA,MAAaA,EAAyD,CACpE,WAAc,OAAO,2DACrB,QAAW,OAAO,qDAClB,UAAa,OAAO,yDACpB,QAAW,OAAO,qDAClB,WAAc,OAAO,2DACrB,SAAY,OAAO,uDACnB,eAAkB,OAAO,mEACzB,eAAkB,OAAO,mEACzB,WAAc,OAAO,2DACrB,eAAkB,OAAO,mEACzB,WAAc,OAAO,2DACrB,UAAa,OAAO,yDACpB,cAAiB,OAAO,iEACxB,UAAa,OAAO,yDACpB,aAAgB,OAAO,+DACvB,YAAe,OAAO,6DACtB,iBAAoB,OAAO,uEAC3B,WAAc,OAAO,2DACrB,WAAc,OAAO,2DACrB,YAAe,OAAO,6DACtB,aAAgB,OAAO,+DACvB,YAAe,OAAO,6DACtB,SAAY,OAAO,uDACnB,cAAiB,OAAO,iEACxB,WAAc,OAAO,2DACrB,eAAkB,OAAO,mEACzB,aAAgB,OAAO,+DACvB,gBAAmB,OAAO,qEAC1B,YAAe,OAAO,6DACtB,eAAkB,OAAO,mEACzB,cAAiB,OAAO,iEACxB,YAAe,OAAO,6DACtB,aAAgB,OAAO,+DACvB,eAAkB,OAAO,mEACzB,YAAe,OAAO,6DACtB,UAAa,OAAO,yDACpB,YAAe,OAAO,6DACtB,SAAY,OAAO,sDACrB,EChBaC,EAA4B,iTAkCzC,EC/CMC,EAA8B,CAAC,OAAQ,SAAS,EAmBz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,EAG9D,IAAK,QAGH,OAFAJ,EAAWI,EAAQ,SAAS,CAAC,CAAC,MAAM,EAE7B,CAAE,GAAI,EAAK,EAGpB,IAAK,aAGH,OAFAJ,EAAWI,EAAQ,SAAS,CAAC,CAAC,WAAW,EAElC,CAAE,GAAI,EAAK,EAGpB,IAAK,UAGH,OAFAL,EAAS,OAAOK,EAAQ,SAAS,EAE1B,CAAE,GAAI,EAAK,EAGpB,QACE,MAAU,MAAM,gDAAgD,OAAOA,CAAO,GAAG,CAErF,CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit/plugin-mathjax-slim",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Mathjax plugin for MarkdownIt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
7
7
|
"markdown-it-plugin",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
33
|
"default": "./dist/index.js"
|
|
34
34
|
},
|
|
35
|
-
"./
|
|
36
|
-
"types": "./dist/
|
|
37
|
-
"default": "./dist/
|
|
35
|
+
"./async": {
|
|
36
|
+
"types": "./dist/async/index.d.ts",
|
|
37
|
+
"default": "./dist/async/index.js"
|
|
38
38
|
},
|
|
39
39
|
"./package.json": "./package.json"
|
|
40
40
|
},
|
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
"clean": "rimraf ./dist"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@mdit/plugin-tex": "1.
|
|
49
|
+
"@mdit/plugin-tex": "1.3.0",
|
|
50
|
+
"synckit": "^0.12.3"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@mathjax/mathjax-tex-font": "^4.1.3",
|
|
@@ -71,5 +72,5 @@
|
|
|
71
72
|
"engines": {
|
|
72
73
|
"node": ">=22"
|
|
73
74
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "9f02fe8110ff5ea45f89e24605f9abfba59aefeb"
|
|
75
76
|
}
|
package/dist/sync-node.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import{tex as t}from"@mdit/plugin-tex";const n=/* @__PURE__ */ `action.ams.amscd.bbm.bboldx.bbox.begingroup.boldsymbol.braket.bussproofs.cancel.cases.centernot.color.colortbl.colorv2.configmacros.dsfont.empheq.enclose.extpfeil.gensymb.html.mathtools.mhchem.newcommand.noerrors.noundefined.physics.setoptions.tagformat.texhtml.textcomp.textmacros.unicode.units.upgreek.verb`.split(`.`),r=[{handler:`macro`,name:`new-Command`},{handler:`environment`,name:`new-Environment`},{handler:`delimiter`,name:`new-Delimiter`}],i=e=>{for(let{handler:t,name:n}of r)e.parseOptions.handlers.get(t).retrieve(n)?.map.clear()};let a=!0,o,s,c,l,u,d,f,p=!0,m,h;const g=e(import.meta.url);try{({mathjax:f}=await import(`@mathjax/src/js/mathjax.js`)),[{TeX:u},{CHTML:s},{SVG:l},{liteAdaptor:d},{RegisterHTMLHandler:c},{AssistiveMmlHandler:o}]=await Promise.all([import(`@mathjax/src/js/input/tex.js`),import(`@mathjax/src/js/output/chtml.js`),import(`@mathjax/src/js/output/svg.js`),import(`@mathjax/src/js/adaptors/liteAdaptor.js`),import(`@mathjax/src/js/handlers/html.js`),import(`@mathjax/src/js/a11y/assistive-mml.js`),import(`@mathjax/src/js/input/tex/action/ActionConfiguration.js`),import(`@mathjax/src/js/input/tex/ams/AmsConfiguration.js`),import(`@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js`),import(`@mathjax/src/js/input/tex/base/BaseConfiguration.js`),import(`@mathjax/src/js/input/tex/bbm/BbmConfiguration.js`),import(`@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js`),import(`@mathjax/src/js/input/tex/bbox/BboxConfiguration.js`),import(`@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js`),import(`@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js`),import(`@mathjax/src/js/input/tex/braket/BraketConfiguration.js`),import(`@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js`),import(`@mathjax/src/js/input/tex/cancel/CancelConfiguration.js`),import(`@mathjax/src/js/input/tex/cases/CasesConfiguration.js`),import(`@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js`),import(`@mathjax/src/js/input/tex/color/ColorConfiguration.js`),import(`@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js`),import(`@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js`),import(`@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js`),import(`@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js`),import(`@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js`),import(`@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js`),import(`@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js`),import(`@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js`),import(`@mathjax/src/js/input/tex/html/HtmlConfiguration.js`),import(`@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js`),import(`@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js`),import(`@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js`),import(`@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js`),import(`@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js`),import(`@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js`),import(`@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js`),import(`@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js`),import(`@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js`),import(`@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js`),import(`@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js`),import(`@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js`),import(`@mathjax/src/js/input/tex/units/UnitsConfiguration.js`),import(`@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js`),import(`@mathjax/src/js/input/tex/verb/VerbConfiguration.js`)]),f.asyncIsSynchronous=!0}catch{
|
|
2
|
-
/* istanbul ignore next -- @preserve */
|
|
3
|
-
a=!1}try{m=(await import(`@mathjax/mathjax-newcm-font/js/chtml.js`)).MathJaxNewcmFont,h=(await import(`@mathjax/mathjax-newcm-font/js/svg.js`)).MathJaxNewcmFont}catch{
|
|
4
|
-
/* istanbul ignore next -- @preserve */
|
|
5
|
-
p=!1}const _=e=>{
|
|
6
|
-
/* istanbul ignore if -- @preserve */
|
|
7
|
-
if(!a)throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/src" is not installed!`);let t=e.output===`chtml`,r=(t?e.chtml:e.svg)??{};
|
|
8
|
-
/* istanbul ignore if -- @preserve */
|
|
9
|
-
if(!r.fontData&&!p)throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/mathjax-newcm-font" is not installed!`);let i=Object.assign({fontData:t?m:h},r?.fontData?{}:{dynamicPrefix:`@mathjax/mathjax-newcm-font/js/${t?`chtml`:`svg`}/dynamic`},t&&!r.fontData?{fontURL:`https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2`}:{},r);return f.asyncLoad=t=>{e.debug&&console.debug(`[MathJax]: sync loading ${t}...`),g(t)},{InputJax:new u({packages:[`base`,...n],...e.tex}),OutputJax:new(t?s:l)(i),enableAssistiveMml:e.a11y!==!1}},v=(e={})=>{let t=_(e),{OutputJax:n,InputJax:r}=t,a=d(),s=c(a);e.a11y!==!1&&o(s);let l=()=>{n.adaptor!=null&&(r.reset(),n.reset())};return{adaptor:a,documentOptions:t,allowInlineWithSpace:e.allowInlineWithSpace??!1,delimiters:e.delimiters??`dollars`,mathFence:e.mathFence??!1,clearStyle:l,reset:()=>{r.reset(),i(r)},outputStyle:()=>{n.font.loadDynamicFilesSync();let e=a.cssText(n.styleSheet(f.document(``,t)));return l(),e},transformer:e.transformer??null}},y=(e,{allowInlineWithSpace:n,adaptor:r,delimiters:i,documentOptions:a,mathFence:o,reset:s,transformer:c})=>{let l=e.render.bind(e),u=e.renderInline.bind(e);e.render=(e,t)=>{try{return l(e,t)}finally{s()}},e.renderInline=(e,t)=>{try{return u(e,t)}finally{s()}},e.use(t,{allowInlineWithSpace:n,delimiters:i,mathFence:o,render:(e,t)=>{let n=f.document(e,a).convert(e,{display:t}),i=r.outerHTML(n);return c?.(i,t)??i}})};export{v as createMathjaxInstance,_ as getDocumentOptions,y as mathjax};
|
|
10
|
-
//# sourceMappingURL=sync-node.js.map
|
package/dist/sync-node.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-node.js","names":["texPackages","USER_MAPS","clearUserState","InputJax","handler","name","isMathJaxInstalled","AssistiveMmlHandler","CHTML","RegisterHTMLHandler","SVG","TeX","liteAdaptor","mathjaxLib","isMathJaxNewcmFontInstalled","chtmlFont","svgFont","require","createRequire","getDocumentOptions","isCHTML","options","userOptions","outputOptions","file","createMathjaxInstance","documentOptions","adaptor","clearStyle","OutputJax","style","mathjax","render","md","renderInline","src","env","reset","tex","mathDocument","content","displayMode","result","transformer"],"sources":["../src/tex/packages.ts","../src/utils.ts","../src/sync.ts"],"sourcesContent":["import type { TexPackage } from \"../mathjax.js\";\n\nexport const texPackages: TexPackage[] = [\n \"action\",\n \"ams\",\n \"amscd\",\n \"bbm\",\n \"bboldx\",\n \"bbox\",\n \"begingroup\",\n \"boldsymbol\",\n \"braket\",\n \"bussproofs\",\n \"cancel\",\n \"cases\",\n \"centernot\",\n \"color\",\n \"colortbl\",\n \"colorv2\",\n \"configmacros\",\n \"dsfont\",\n \"empheq\",\n \"enclose\",\n \"extpfeil\",\n \"gensymb\",\n \"html\",\n \"mathtools\",\n \"mhchem\",\n \"newcommand\",\n \"noerrors\",\n \"noundefined\",\n \"physics\",\n \"setoptions\",\n \"tagformat\",\n \"texhtml\",\n \"textcomp\",\n \"textmacros\",\n \"unicode\",\n \"units\",\n \"upgreek\",\n \"verb\",\n];\n","import type { LiteElement } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type { TeX } from \"@mathjax/src/js/input/tex.js\";\nimport type { HandlerType } from \"@mathjax/src/js/input/tex/HandlerTypes.js\";\n\ninterface TeXMacroMap {\n map: Map<string, unknown>;\n}\n\nconst USER_MAPS: { handler: HandlerType; name: string }[] = [\n { handler: \"macro\" as HandlerType.MACRO, name: \"new-Command\" },\n { handler: \"environment\" as HandlerType.ENVIRONMENT, name: \"new-Environment\" },\n { handler: \"delimiter\" as HandlerType.DELIMITER, name: \"new-Delimiter\" },\n];\n\n/**\n * Clear user-defined TeX state (macros/environments/delimiters) on a MathJax TeX input jax.\n *\n * MathJax stores user-defined macros, environments and delimiters in dedicated `new-*` maps that\n * are separate from the built-in maps, and `InputJax.reset()` does not clear them, so they would\n * leak across documents rendered by the same instance. This reaches into the internal maps to\n * remove only user-defined entries.\n *\n * 清除 MathJax TeX 输入 jax 上由 `\\newcommand`/`\\def`/`\\newenvironment` 等定义的用户状态。\n *\n * MathJax 将用户自定义的宏、环境与分隔符存放在独立的 `new-*` 映射中,与内置映射分离,且 `InputJax.reset()`\n * 不会清除它们,因此同一实例渲染多篇文档时状态会跨文档泄漏。此处直接访问内部映射,仅移除用户自定义条目。\n *\n * @param InputJax - MathJax TeX input jax / MathJax TeX 输入 jax\n */\nexport const clearUserState = (InputJax: TeX<LiteElement, string, HTMLElement>): void => {\n for (const { handler, name } of USER_MAPS) {\n const handlerMap = InputJax.parseOptions.handlers.get(handler);\n const userMap = handlerMap.retrieve(name) as unknown as TeXMacroMap | null;\n\n userMap?.map.clear();\n }\n};\n","/** Forked from https://github.com/tani/markdown-it-mathjax3/blob/master/index.ts */\n// oxlint-disable-next-line import/no-nodejs-modules\nimport { createRequire } from \"node:module\";\n\nimport type { MathJaxNewcmFont as MathJaxNewcmHTMLFont } from \"@mathjax/mathjax-newcm-font/js/chtml.js\";\nimport type { MathJaxNewcmFont as MathJaxNewcmSVGFont } from \"@mathjax/mathjax-newcm-font/js/svg.js\";\nimport type { AssistiveMmlHandler as AssistiveMmlHandlerType } from \"@mathjax/src/js/a11y/assistive-mml.js\";\nimport type { LiteDocument } from \"@mathjax/src/js/adaptors/lite/Document.js\";\nimport type { LiteElement, LiteNode } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type { LiteText } from \"@mathjax/src/js/adaptors/lite/Text.js\";\nimport type { liteAdaptor as liteAdaptorType } from \"@mathjax/src/js/adaptors/liteAdaptor.js\";\nimport type { MathDocument } from \"@mathjax/src/js/core/MathDocument.js\";\nimport type { RegisterHTMLHandler as RegisterHTMLHandlerType } from \"@mathjax/src/js/handlers/html.js\";\nimport type { TeX as TeXType } from \"@mathjax/src/js/input/tex.js\";\nimport type { mathjax as mathjaxType } from \"@mathjax/src/js/mathjax.js\";\nimport type { CHTML as CHTMLType } from \"@mathjax/src/js/output/chtml.js\";\nimport type { SVG as SVGType } from \"@mathjax/src/js/output/svg.js\";\nimport { tex } from \"@mdit/plugin-tex\";\nimport type { MarkdownIt } from \"markdown-it\";\n\nimport type { MarkdownItMathjaxOptions, DocumentOptions, MathjaxInstance } from \"./options.js\";\nimport { texPackages } from \"./tex/index.js\";\nimport { clearUserState } from \"./utils.js\";\n\nlet isMathJaxInstalled = true;\nlet AssistiveMmlHandler: typeof AssistiveMmlHandlerType,\n CHTML: typeof CHTMLType,\n RegisterHTMLHandler: typeof RegisterHTMLHandlerType,\n SVG: typeof SVGType,\n TeX: typeof TeXType,\n liteAdaptor: typeof liteAdaptorType,\n mathjaxLib: typeof mathjaxType;\nlet isMathJaxNewcmFontInstalled = true;\nlet chtmlFont: typeof MathJaxNewcmHTMLFont, svgFont: typeof MathJaxNewcmSVGFont;\n\nconst require = createRequire(import.meta.url);\n\ntry {\n ({ mathjax: mathjaxLib } = await import(\"@mathjax/src/js/mathjax.js\"));\n [{ TeX }, { CHTML }, { SVG }, { liteAdaptor }, { RegisterHTMLHandler }, { AssistiveMmlHandler }] =\n await Promise.all([\n import(\"@mathjax/src/js/input/tex.js\"),\n import(\"@mathjax/src/js/output/chtml.js\"),\n import(\"@mathjax/src/js/output/svg.js\"),\n import(\"@mathjax/src/js/adaptors/liteAdaptor.js\"),\n import(\"@mathjax/src/js/handlers/html.js\"),\n import(\"@mathjax/src/js/a11y/assistive-mml.js\"),\n import(\"@mathjax/src/js/input/tex/action/ActionConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/ams/AmsConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/base/BaseConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/bbm/BbmConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/bbox/BboxConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/braket/BraketConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/cancel/CancelConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/cases/CasesConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/color/ColorConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js\"),\n import(\"@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/html/HtmlConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/units/UnitsConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js\"),\n import(\"@mathjax/src/js/input/tex/verb/VerbConfiguration.js\"),\n ]);\n\n mathjaxLib.asyncIsSynchronous = true;\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxInstalled = false;\n}\n\ntry {\n chtmlFont = (await import(\"@mathjax/mathjax-newcm-font/js/chtml.js\")).MathJaxNewcmFont;\n svgFont = (await import(\"@mathjax/mathjax-newcm-font/js/svg.js\")).MathJaxNewcmFont;\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxNewcmFontInstalled = false;\n}\nexport const getDocumentOptions = (options: MarkdownItMathjaxOptions): DocumentOptions => {\n /* istanbul ignore if -- @preserve */\n if (!isMathJaxInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/src\" is not installed!');\n\n const isCHTML = options.output === \"chtml\";\n const userOptions = (isCHTML ? options.chtml : options.svg) ?? {};\n\n /* istanbul ignore if -- @preserve */\n if (!userOptions.fontData && !isMathJaxNewcmFontInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/mathjax-newcm-font\" is not installed!');\n\n const outputOptions = Object.assign(\n {\n fontData: isCHTML ? chtmlFont : svgFont,\n },\n // fontURL can be set to undefined if you want to bundle the fonts yourself\n // both fontURL and dynamicPrefix shall be synced with fontData, so set it to undefined if fontData is customized\n userOptions?.fontData\n ? {}\n : { dynamicPrefix: `@mathjax/mathjax-newcm-font/js/${isCHTML ? \"chtml\" : \"svg\"}/dynamic` },\n isCHTML && !userOptions.fontData\n ? { fontURL: \"https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2\" }\n : {},\n userOptions,\n );\n\n mathjaxLib.asyncLoad = (file): void => {\n if (options.debug)\n // oxlint-disable-next-line no-console\n console.debug(`[MathJax]: sync loading ${file}...`);\n // oxlint-disable-next-line import/no-dynamic-require\n require(file);\n };\n\n return {\n InputJax: new TeX<LiteElement, string, HTMLElement>({\n packages: [\"base\", ...texPackages],\n ...options.tex,\n }),\n OutputJax: new (isCHTML ? CHTML : SVG)<LiteElement, string, HTMLElement>(outputOptions),\n enableAssistiveMml: options.a11y !== false,\n };\n};\n\nexport const createMathjaxInstance = (\n options: MarkdownItMathjaxOptions = {},\n): MathjaxInstance<true> | null => {\n const documentOptions = getDocumentOptions(options);\n const { OutputJax, InputJax } = documentOptions;\n\n const adaptor = liteAdaptor();\n // oxlint-disable-next-line new-cap\n const handler = RegisterHTMLHandler(adaptor);\n // oxlint-disable-next-line new-cap\n if (options.a11y !== false) AssistiveMmlHandler<LiteNode, LiteText, LiteDocument>(handler);\n\n const clearStyle = (): void => {\n // if there is no adaptor, output jax is not initialized yet, so nothing to clear\n if (OutputJax.adaptor == null) return;\n\n InputJax.reset();\n OutputJax.reset();\n };\n\n const reset = (): void => {\n InputJax.reset();\n clearUserState(InputJax);\n };\n\n const outputStyle = (): string => {\n OutputJax.font.loadDynamicFilesSync();\n\n const style = adaptor.cssText(\n OutputJax.styleSheet(\n mathjaxLib.document(\"\", documentOptions) as MathDocument<LiteElement, string, HTMLElement>,\n ),\n );\n\n clearStyle();\n\n return style;\n };\n\n return {\n adaptor,\n documentOptions,\n allowInlineWithSpace: options.allowInlineWithSpace ?? false,\n delimiters: options.delimiters ?? \"dollars\",\n mathFence: options.mathFence ?? false,\n clearStyle,\n reset,\n outputStyle,\n transformer: options.transformer ?? null,\n };\n};\n\nexport const mathjax = (\n md: MarkdownIt,\n {\n allowInlineWithSpace,\n adaptor,\n delimiters,\n documentOptions,\n mathFence,\n reset,\n transformer,\n }: MathjaxInstance<true>,\n): void => {\n // Reset the shared TeX input state (macros/labels) after each render so that\n // state does not leak across documents rendered by the same instance.\n const render = md.render.bind(md);\n const renderInline = md.renderInline.bind(md);\n\n md.render = (src, env): string => {\n try {\n return render(src, env);\n } finally {\n reset();\n }\n };\n md.renderInline = (src, env): string => {\n try {\n return renderInline(src, env);\n } finally {\n reset();\n }\n };\n\n md.use(tex, {\n allowInlineWithSpace,\n delimiters,\n mathFence,\n render: (content, displayMode) => {\n const mathDocument = mathjaxLib.document(content, documentOptions).convert(content, {\n display: displayMode,\n }) as LiteElement;\n\n const result = adaptor.outerHTML(mathDocument);\n\n return transformer?.(result, displayMode) ?? result;\n },\n });\n};\n"],"mappings":"A,mFAEA,MAAaA,EAA4B,gVAuCzC,ECjCMC,EAAsD,CAC1D,CAAE,QAAS,QAA8B,KAAM,aAAc,EAC7D,CAAE,QAAS,cAA0C,KAAM,iBAAkB,EAC7E,CAAE,QAAS,YAAsC,KAAM,eAAgB,CACzE,EAiBaC,EAAkB,GAA0D,CACvF,IAAK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