@mdit/plugin-mathjax-slim 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async/index.d.ts +45 -0
- package/dist/async/index.js +8 -5
- package/dist/async/index.js.map +1 -1
- package/dist/index.d.ts +45 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/async/index.d.ts
CHANGED
|
@@ -364,6 +364,51 @@ interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInli
|
|
|
364
364
|
* @default false
|
|
365
365
|
*/
|
|
366
366
|
debug?: boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Custom loader for the asynchronous files requested by MathJax.
|
|
369
|
+
*
|
|
370
|
+
* By default, Node.js imports the files from `@mathjax/mathjax-newcm-font`, while browsers load
|
|
371
|
+
* the font class, its dynamic files, and the MathJax runtime from unpkg. The plugin routes each
|
|
372
|
+
* file to the loader registered for its SVG or CHTML output, so two async instances do not
|
|
373
|
+
* overwrite each other's loader. A custom loader must return modules from the same font-class and
|
|
374
|
+
* MathJax copies that are used as `fontData` and the output jax; otherwise MathJax installs
|
|
375
|
+
* glyphs on a class the renderer does not use. MathJax's `asyncLoad` is still process-global, so
|
|
376
|
+
* the last custom loader registered for the same output wins.
|
|
377
|
+
*
|
|
378
|
+
* Only used by the async entry.
|
|
379
|
+
*
|
|
380
|
+
* 自定义 MathJax 请求的异步文件的加载器。
|
|
381
|
+
*
|
|
382
|
+
* 默认情况下,Node.js 从 `@mathjax/mathjax-newcm-font` 导入文件,浏览器则从 unpkg 加载字体类、动态文件与 MathJax
|
|
383
|
+
* 运行时。插件会按文件所属的 SVG 或 CHTML 输出分发到对应加载器,因此两个异步实例不会互相覆盖。自定义加载器必须返回与 `fontData` 和输出 jax 相同的字体类及
|
|
384
|
+
* MathJax 副本; 否则 MathJax 会把字形安装到渲染器不使用的类上。MathJax 的 `asyncLoad` 仍是进程级全局设置,后注册的同一输出加载器会覆盖先前的值。
|
|
385
|
+
*
|
|
386
|
+
* 仅异步入口使用。
|
|
387
|
+
*
|
|
388
|
+
* @param file - File name or specifier requested by MathJax / MathJax 请求的文件名或说明符
|
|
389
|
+
* @returns The loaded module / 加载的模块
|
|
390
|
+
*/
|
|
391
|
+
asyncLoad?: (file: string) => Promise<unknown>;
|
|
392
|
+
/**
|
|
393
|
+
* Whether to preload all dynamic font files when the instance is created.
|
|
394
|
+
*
|
|
395
|
+
* `render()` is synchronous, so dynamic glyphs such as `\mathbb` fail with MathJax's retry error
|
|
396
|
+
* unless their font files are already loaded. Keep this enabled unless you provide a custom
|
|
397
|
+
* loader that resolves these files synchronously or you only render glyphs from preloaded font
|
|
398
|
+
* groups.
|
|
399
|
+
*
|
|
400
|
+
* Only used by the async entry.
|
|
401
|
+
*
|
|
402
|
+
* 是否在创建实例时预加载所有动态字体文件。
|
|
403
|
+
*
|
|
404
|
+
* `render()` 是同步的,因此除非字体文件已经加载,`\mathbb` 等动态字形会触发 MathJax 的 retry
|
|
405
|
+
* 错误。除非你提供了能同步解析这些文件的自定义加载器,或只渲染已预加载字体组中的字形,否则请保持开启。
|
|
406
|
+
*
|
|
407
|
+
* 仅异步入口使用。
|
|
408
|
+
*
|
|
409
|
+
* @default true
|
|
410
|
+
*/
|
|
411
|
+
preloadDynamicFonts?: boolean;
|
|
367
412
|
}
|
|
368
413
|
/**
|
|
369
414
|
* Mathjax document options
|
package/dist/async/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
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
|
|
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=/@mathjax\/src@(?<version>\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)\//,l=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;let u=``;const d=async()=>{if(u)return u;try{let e=await fetch(`https://unpkg.com/@mathjax/src@latest/mjs/mathjax.js?module`,{method:`HEAD`,signal:AbortSignal.timeout(5e3)});if(!e.ok)return null;let t=c.exec(e.url)?.groups?.version;return!t||!l.test(t)?null:(u=t,t)}catch{return null}},f=async()=>{try{return(await import(`@mathjax/mathjax-newcm-font/package.json`,{with:{type:`json`}})).default.version}catch{return null}},p=e=>import(
|
|
2
|
+
/* @vite-ignore */
|
|
3
|
+
/* webpackIgnore: true */
|
|
4
|
+
e),m=(e,t,n)=>{let r=`https://unpkg.com/@mathjax/mathjax-newcm-font@${e}/mjs`;return{font:`${r}/${t}.js?module`,mathjax:`https://unpkg.com/@mathjax/src@${n}/mjs/mathjax.js?module`,dynamic:e=>`${r}/${t}/dynamic/${e}.js?module`}},h=()=>typeof window<`u`&&typeof document<`u`,g=async(e,t,n=p)=>{let r=await d();if(!r)throw Error("[@mdit/plugin-mathjax-slim] could not resolve the MathJax runtime version from unpkg. Check the network and Content Security Policy, or provide a custom `fontData` and `asyncLoad`.");let i=await f()??e,a=m(i,t,r);try{let e=await n(a.font),t=await n(a.mathjax);return{fontData:e.MathJaxNewcmFont,mathjax:t.mathjax,fontVersion:i,runtimeVersion:r,dynamic:a.dynamic}}catch(e){throw Error(`[@mdit/plugin-mathjax-slim] failed to load the browser font files from unpkg (${a.font}). Check the network and Content Security Policy, or provide a custom \`fontData\` and \`asyncLoad\`.`,{cause:e})}},_=/\/(?<output>svg|chtml)\//,v=/* @__PURE__ */ new Map,y=e=>{let t=_.exec(e)?.groups?.output;return t===`svg`||t===`chtml`?t:null},b=(e,t)=>{v.set(e,t)},x=e=>{let t=y(e),n=t?v.get(t):null;if(!n)throw Error(`[@mdit/plugin-mathjax-slim] no dynamic font loader is registered for "${e}". Create the MathJax instance before rendering dynamic glyphs.`);return n(e)},S=/* @__PURE__ */ new WeakMap,C=/* @__PURE__ */ new WeakSet,w=(e,t)=>{let n=S.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 T,E,D,O,k,A,j,M,N,P=!0,F=!0;try{({mathjax:M}=await import(`@mathjax/src/js/mathjax.js`)),{TeX:k}=await import(`@mathjax/src/js/input/tex.js`),{CHTML:E}=await import(`@mathjax/src/js/output/chtml.js`),{SVG:O}=await import(`@mathjax/src/js/output/svg.js`),{liteAdaptor:j}=await import(`@mathjax/src/js/adaptors/liteAdaptor.js`),{RegisterHTMLHandler:D}=await import(`@mathjax/src/js/handlers/html.js`),{AssistiveMmlHandler:T}=await import(`@mathjax/src/js/a11y/assistive-mml.js`)}catch{
|
|
2
5
|
/* istanbul ignore next -- @preserve */
|
|
3
|
-
|
|
6
|
+
P=!1}try{A=(await import(`@mathjax/mathjax-newcm-font/js/chtml.js`)).MathJaxNewcmFont,N=(await import(`@mathjax/mathjax-newcm-font/js/svg.js`)).MathJaxNewcmFont}catch{
|
|
4
7
|
/* istanbul ignore next -- @preserve */
|
|
5
|
-
|
|
8
|
+
F=!1}const I=async e=>{
|
|
6
9
|
/* istanbul ignore if -- @preserve */
|
|
7
|
-
if(!
|
|
10
|
+
if(!P)throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/src" is not installed!`);let t=e.output===`chtml`,n=t?`chtml`:`svg`,r=(t?e.chtml:e.svg)??{},o=h(),s=t=>(e.debug&&console.debug(`[MathJax]: loading ${t}...`),x(t));
|
|
8
11
|
/* istanbul ignore if -- @preserve */
|
|
9
|
-
if(!
|
|
12
|
+
if(!o&&!r.fontData&&!F)throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/mathjax-newcm-font" is not installed!`);let c=t?A:N;if(o&&!r.fontData){let t=await g(M.version,n);c=t.fontData,(t.fontVersion!==M.version||t.runtimeVersion!==M.version)&&console.warn(`[@mdit/plugin-mathjax-slim] browser fonts use @mathjax/mathjax-newcm-font ${t.fontVersion} and the unpkg runtime ${t.runtimeVersion}, while this package uses @mathjax/src ${M.version}. Dynamic glyphs may differ; keep the font package and MathJax versions aligned, or self-host them.`),b(n,n=>{if(e.asyncLoad)return e.asyncLoad(n);let r=n.slice(n.lastIndexOf(`/`)+1).replace(/\.js$/,``);return p(t.dynamic(r))}),t.mathjax.asyncLoad=s}let l=Object.assign({fontData:r.fontData??c},r.fontData||o?{}:{dynamicPrefix:`@mathjax/mathjax-newcm-font/js/${n}/dynamic`},t&&!r.fontData?{fontURL:`https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2`}:{},r);o?r.fontData&&e.asyncLoad&&b(n,e.asyncLoad):b(n,t=>e.asyncLoad?.(t)??import(t)),M.asyncLoad=s;let u=e.tex?.packages;return await a([...i(u),`html`,`texhtml`]),{InputJax:new k({...e.tex,packages:i(u)}),OutputJax:new(t?E:O)(l),enableAssistiveMml:e.a11y!==!1}},L=async(e={})=>{let t=await I(e),{OutputJax:n}=t,r=e.preloadDynamicFonts!==!1,a=async()=>{if(r)try{await n.font.loadDynamicFiles()}catch{}};await a();let o=j(),c=D(o);T(c);let l=()=>{n.adaptor!=null&&(t.InputJax.reset(),n.reset())},u={adaptor:o,documentOptions:t,allowInlineWithSpace:e.allowInlineWithSpace??!1,delimiters:e.delimiters??`dollars`,mathFence:e.mathFence??!1,clearStyle:l,render:(e,n)=>{let r=M.document(e,t).convert(e,{display:n});return o.outerHTML(r)},reset:()=>{t.InputJax.reset(),s(t.InputJax)},outputStyle:async()=>{await a();let e=o.cssText(n.styleSheet(M.document(``,t)));return l(),e},transformer:e.transformer??null};return S.set(u,{enableHtml:!1,createInputJax:t=>new k({...e.tex,packages:i(e.tex?.packages,t)})}),u},R=(t,n)=>{if(C.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");w(n,t.options.html),C.add(n);let{allowInlineWithSpace:r,delimiters:i,mathFence:a,render:o,reset:s,transformer:c}=n,l=t.render.bind(t),u=t.renderInline.bind(t);t.render=(e,t)=>{try{return l(e,t)}finally{s()}},t.renderInline=(e,t)=>{try{return u(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{L as createMathjaxInstance,I as getDocumentOptions,R as mathjax};
|
|
10
13
|
//# sourceMappingURL=index.js.map
|
package/dist/async/index.js.map
CHANGED
|
@@ -1 +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,UAAa,OAAO,yDACpB,YAAe,OAAO,6DACtB,SAAY,OAAO,sDACrB,EC7BMC,EAA8B,CAAC,OAAQ,SAAS,EAmB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ACtC,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"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["texPackages","texLoaders","HTML_PACKAGES","resolveTexPackages","packages","userPackages","pkg","enableHtml","loadTexPackages","USER_MAP_NAMES","clearUserState","name","InputJax","CDN_MATHJAX_VERSION_RE","SEMVER_RE","cachedCdnMathJaxVersion","resolveCdnMathJaxVersion","response","version","getFontPackageVersion","importCdnModule","url","getCdnFontUrls","base","fontVersion","output","runtimeVersion","isBrowserRuntime","loadBrowserFonts","urls","fontModule","importModule","runtimeModule","err","DYNAMIC_FONT_OUTPUT_RE","dynamicFontLoaders","getDynamicFontOutput","file","registerDynamicFontLoader","loader","loadDynamicFontFile","instanceTexStates","installedInstances","applyHtmlPackages","state","instance","AssistiveMmlHandler","CHTML","RegisterHTMLHandler","SVG","TeX","chtmlFont","liteAdaptor","mathjaxLib","svgFont","isMathJaxInstalled","isMathJaxNewcmFontInstalled","getDocumentOptions","isCHTML","options","userOptions","isBrowser","loadDynamicFont","fontData","browserFonts","outputOptions","createMathjaxInstance","documentOptions","shouldPreload","preloadDynamicFonts","OutputJax","adaptor","handler","clearStyle","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/cdn.ts","../../src/async/runtime.ts","../../src/async/browser.ts","../../src/async/loader.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","/**\n * URL used to discover the MathJax version that unpkg resolves for the font package.\n *\n * 用于查询 unpkg 为字体包解析出的 MathJax 版本的 URL。\n */\nconst CDN_MATHJAX_LATEST_URL = \"https://unpkg.com/@mathjax/src@latest/mjs/mathjax.js?module\";\nconst CDN_MATHJAX_VERSION_RE = /@mathjax\\/src@(?<version>\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?)\\//;\nconst SEMVER_RE = /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/;\nconst CDN_HEAD_TIMEOUT_MS = 5000;\n\nlet cachedCdnMathJaxVersion = \"\";\n\n/**\n * URLs of the browser font files served by unpkg.\n *\n * 由 unpkg 提供的浏览器字体文件 URL。\n */\nexport interface CdnFontUrls {\n /** Font class module URL / 字体类模块 URL */\n font: string;\n /** MathJax runtime module URL / MathJax 运行时模块 URL */\n mathjax: string;\n /** Dynamic font file URL / 动态字体文件 URL */\n dynamic: (name: string) => string;\n}\n\n/**\n * Clear the cached MathJax runtime version.\n *\n * 清除缓存的 MathJax 运行时版本。\n */\nexport const clearCdnMathJaxVersionCache = (): void => {\n cachedCdnMathJaxVersion = \"\";\n};\n\n/**\n * Resolve the exact `@mathjax/src` version that unpkg uses for the font package's imports.\n *\n * 解析 unpkg 为字体包导入所使用的确切 `@mathjax/src` 版本。\n *\n * Unpkg rewrites the font package's bare `@mathjax/src` imports to `@latest`, which redirects to a\n * concrete version. The runtime must be imported from that same concrete URL; importing `@latest`\n * directly creates a second module instance and its `asyncLoad` never reaches the font class.\n *\n * Unpkg 会把字体包中裸写的 `@mathjax/src` 导入重写为 `@latest`,再重定向到具体版本。运行时必须从同一个具体 URL 导入; 直接导入 `@latest`\n * 会创建第二个模块实例,它的 `asyncLoad` 不会作用到字体类上。\n *\n * @returns The resolved MathJax version, or `null` when it cannot be determined / 解析出的 MathJax\n * 版本;无法确定时返回 `null`\n */\nexport const resolveCdnMathJaxVersion = async (): Promise<string | null> => {\n if (cachedCdnMathJaxVersion) return cachedCdnMathJaxVersion;\n\n try {\n const response = await fetch(CDN_MATHJAX_LATEST_URL, {\n method: \"HEAD\",\n signal: AbortSignal.timeout(CDN_HEAD_TIMEOUT_MS),\n });\n\n if (!response.ok) return null;\n\n const match = CDN_MATHJAX_VERSION_RE.exec(response.url);\n const version = match?.groups?.version;\n\n if (!version || !SEMVER_RE.test(version)) return null;\n\n cachedCdnMathJaxVersion = version;\n\n return version;\n } catch {\n return null;\n }\n};\n\n/**\n * Read the version of the installed NewCM font package.\n *\n * 读取已安装的 NewCM 字体包版本。\n *\n * The font package is an independent peer dependency. Its version, not the MathJax runtime version,\n * decides which font files exist on unpkg.\n *\n * 字体包是独立的 peer 依赖。决定 unpkg 上存在哪些字体文件的是它的版本,而不是 MathJax 运行时版本。\n *\n * @returns The font package version, or `null` when the package cannot be read / 字体包版本;无法读取时返回\n * `null`\n */\nexport const getFontPackageVersion = async (): Promise<string | null> => {\n try {\n const fontPackage = (await import(\"@mathjax/mathjax-newcm-font/package.json\", {\n with: { type: \"json\" },\n })) as { default: { version: string } };\n\n return fontPackage.default.version;\n } catch {\n return null;\n }\n};\n\n/**\n * Import a module from an absolute URL.\n *\n * 从绝对 URL 导入模块。\n *\n * @param url - Module URL / 模块 URL\n * @returns The imported module / 导入的模块\n */\nexport const importCdnModule = (url: string): Promise<unknown> =>\n import(/* @vite-ignore */ /* webpackIgnore: true */ url);\n\n/**\n * Create the unpkg URLs used to load MathJax fonts in browsers.\n *\n * 创建浏览器中加载 MathJax 字体所用的 unpkg URL。\n *\n * The font class and dynamic files use the installed font package version. The runtime uses the\n * concrete version unpkg resolves for the font package's internal imports, so `asyncLoad` and the\n * font class share one module instance.\n *\n * 字体类与动态文件使用已安装字体包的版本。运行时使用 unpkg 为字体包内部导入解析出的具体版本,这样 `asyncLoad` 与字体类属于同一个模块实例。\n *\n * @param fontVersion - Installed NewCM font package version / 已安装的 NewCM 字体包版本\n * @param output - Output format / 输出格式\n * @param runtimeVersion - Runtime version resolved from unpkg / 从 unpkg 解析出的运行时版本\n * @returns Font, runtime, and dynamic-file URLs / 字体、运行时和动态文件 URL\n */\nexport const getCdnFontUrls = (\n fontVersion: string,\n output: \"svg\" | \"chtml\",\n runtimeVersion: string,\n): CdnFontUrls => {\n const base = `https://unpkg.com/@mathjax/mathjax-newcm-font@${fontVersion}/mjs`;\n\n return {\n font: `${base}/${output}.js?module`,\n mathjax: `https://unpkg.com/@mathjax/src@${runtimeVersion}/mjs/mathjax.js?module`,\n dynamic: (name: string) => `${base}/${output}/dynamic/${name}.js?module`,\n };\n};\n","/**\n * Whether the current runtime has a browser DOM.\n *\n * 当前运行时是否具有浏览器 DOM。\n *\n * Workers and DOM shims can expose `self` without providing a real document. The async entry only\n * uses the CDN loader when both `window` and `document` exist.\n *\n * Worker 与 DOM shim 可能只提供 `self` 而没有真实 document。异步入口仅在 `window` 与 `document` 都存在时使用 CDN 加载器。\n *\n * @returns Whether the runtime is a browser / 是否为浏览器运行时\n */\nexport const isBrowserRuntime = (): boolean =>\n typeof window !== \"undefined\" && typeof document !== \"undefined\";\n","import 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 { mathjax as mathjaxType } from \"@mathjax/src/js/mathjax.js\";\n\nimport {\n importCdnModule,\n getCdnFontUrls,\n getFontPackageVersion,\n resolveCdnMathJaxVersion,\n} from \"./cdn.js\";\n\n/**\n * Font class and runtime loaded from unpkg for a browser output format.\n *\n * 浏览器输出格式从 unpkg 加载的字体类与运行时。\n */\nexport interface BrowserFonts {\n /** Font class used as `fontData` / 作为 `fontData` 的字体类 */\n fontData: typeof chtmlFontType | typeof svgFontType;\n /** MathJax runtime that owns `asyncLoad` / 持有 `asyncLoad` 的 MathJax 运行时 */\n mathjax: typeof mathjaxType;\n /** Installed NewCM font package version / 已安装的 NewCM 字体包版本 */\n fontVersion: string;\n /** Runtime version resolved from unpkg / 从 unpkg 解析出的运行时版本 */\n runtimeVersion: string;\n /** Build a dynamic font file URL / 构建动态字体文件 URL */\n dynamic: (name: string) => string;\n}\n\n/**\n * Load the font class and MathJax runtime from unpkg in a browser.\n *\n * 在浏览器中从 unpkg 加载字体类与 MathJax 运行时。\n *\n * @param version - MathJax version used by this package / 插件使用的 MathJax 版本\n * @param output - Output format / 输出格式\n * @param importModule - Module importer, injectable for tests / 模块导入函数,测试时可注入\n * @returns The browser font class and runtime / 浏览器字体类与运行时\n */\nexport const loadBrowserFonts = async (\n version: string,\n output: \"svg\" | \"chtml\",\n importModule: (url: string) => Promise<unknown> = importCdnModule,\n): Promise<BrowserFonts> => {\n const runtimeVersion = await resolveCdnMathJaxVersion();\n\n if (!runtimeVersion) {\n throw new Error(\n \"[@mdit/plugin-mathjax-slim] could not resolve the MathJax runtime version from unpkg. Check the network and Content Security Policy, or provide a custom `fontData` and `asyncLoad`.\",\n );\n }\n\n const fontVersion = (await getFontPackageVersion()) ?? version;\n\n const urls = getCdnFontUrls(fontVersion, output, runtimeVersion);\n\n try {\n const fontModule = (await importModule(urls.font)) as {\n MathJaxNewcmFont: typeof chtmlFontType | typeof svgFontType;\n };\n const runtimeModule = (await importModule(urls.mathjax)) as { mathjax: typeof mathjaxType };\n\n return {\n fontData: fontModule.MathJaxNewcmFont,\n mathjax: runtimeModule.mathjax,\n fontVersion,\n runtimeVersion,\n dynamic: urls.dynamic,\n };\n } catch (err) {\n throw new Error(\n `[@mdit/plugin-mathjax-slim] failed to load the browser font files from unpkg (${urls.font}). Check the network and Content Security Policy, or provide a custom \\`fontData\\` and \\`asyncLoad\\`.`,\n { cause: err },\n );\n }\n};\n\nexport { isBrowserRuntime } from \"./runtime.js\";\n","type DynamicFontOutput = \"svg\" | \"chtml\";\ntype DynamicFontLoader = (file: string) => Promise<unknown>;\n\nconst DYNAMIC_FONT_OUTPUT_RE = /\\/(?<output>svg|chtml)\\//;\nconst dynamicFontLoaders = new Map<DynamicFontOutput, DynamicFontLoader>();\n\n/**\n * Detect the output format from a dynamic font file name.\n *\n * 从动态字体文件名中识别输出格式。\n *\n * @param file - File name or specifier requested by MathJax / MathJax 请求的文件名或说明符\n * @returns The output format, or `null` when it cannot be detected / 输出格式;无法识别时返回 `null`\n */\nexport const getDynamicFontOutput = (file: string): DynamicFontOutput | null => {\n const output = DYNAMIC_FONT_OUTPUT_RE.exec(file)?.groups?.output;\n\n return output === \"svg\" || output === \"chtml\" ? output : null;\n};\n\n/**\n * Register the loader for one output format.\n *\n * 为一种输出格式注册加载器。\n *\n * MathJax exposes `asyncLoad` globally. The dispatcher uses this registry to route each requested\n * file to the loader of its own output, so SVG and CHTML instances do not overwrite each other.\n *\n * MathJax 的 `asyncLoad` 是全局的。分发器通过此注册表把每个请求文件交给对应输出格式的加载器,避免 SVG 与 CHTML 实例互相覆盖。\n *\n * @param output - Output format / 输出格式\n * @param loader - Loader for that output / 该输出格式的加载器\n */\nexport const registerDynamicFontLoader = (\n output: DynamicFontOutput,\n loader: DynamicFontLoader,\n): void => {\n dynamicFontLoaders.set(output, loader);\n};\n\n/**\n * Clear all registered dynamic font loaders.\n *\n * 清除所有已注册的动态字体加载器。\n */\nexport const clearDynamicFontLoaders = (): void => {\n dynamicFontLoaders.clear();\n};\n\n/**\n * Load a dynamic font file with the loader registered for its output.\n *\n * 使用对应输出格式注册的加载器加载动态字体文件。\n *\n * @param file - File name or specifier requested by MathJax / MathJax 请求的文件名或说明符\n * @returns The loaded module / 加载的模块\n */\nexport const loadDynamicFontFile = (file: string): Promise<unknown> => {\n const output = getDynamicFontOutput(file);\n const loader = output ? dynamicFontLoaders.get(output) : null;\n\n if (!loader) {\n throw new Error(\n `[@mdit/plugin-mathjax-slim] no dynamic font loader is registered for \"${file}\". Create the MathJax instance before rendering dynamic glyphs.`,\n );\n }\n\n return loader(file);\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\";\nimport { isBrowserRuntime, loadBrowserFonts } from \"./browser.js\";\nimport { importCdnModule } from \"./cdn.js\";\nimport { loadDynamicFontFile, registerDynamicFontLoader } from \"./loader.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 output = isCHTML ? \"chtml\" : \"svg\";\n const userOptions = (isCHTML ? options.chtml : options.svg) ?? {};\n const isBrowser = isBrowserRuntime();\n const loadDynamicFont = (file: string): Promise<unknown> => {\n if (options.debug)\n // oxlint-disable-next-line no-console\n console.debug(`[MathJax]: loading ${file}...`);\n\n return loadDynamicFontFile(file);\n };\n\n /* istanbul ignore if -- @preserve */\n if (!isBrowser && !userOptions.fontData && !isMathJaxNewcmFontInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/mathjax-newcm-font\" is not installed!');\n\n // Node.js can resolve the font package directly. Browsers cannot resolve the package's bare\n // `@mathjax/src` imports, so load the font class from a CDN that rewrites them (`unpkg?module`).\n // The font data installs dynamic glyphs on the class it was loaded with, so keep the local output\n // jax but use the same CDN copy for the font and its dynamic files.\n let fontData: typeof chtmlFontType | typeof svgFontType = isCHTML ? chtmlFont : svgFont;\n\n if (isBrowser && !userOptions.fontData) {\n const browserFonts = await loadBrowserFonts(mathjaxLib.version, output);\n fontData = browserFonts.fontData;\n\n if (\n browserFonts.fontVersion !== mathjaxLib.version ||\n browserFonts.runtimeVersion !== mathjaxLib.version\n ) {\n // oxlint-disable-next-line no-console\n console.warn(\n `[@mdit/plugin-mathjax-slim] browser fonts use @mathjax/mathjax-newcm-font ${browserFonts.fontVersion} and the unpkg runtime ${browserFonts.runtimeVersion}, while this package uses @mathjax/src ${mathjaxLib.version}. Dynamic glyphs may differ; keep the font package and MathJax versions aligned, or self-host them.`,\n );\n }\n\n registerDynamicFontLoader(output, (file) => {\n if (options.asyncLoad) return options.asyncLoad(file);\n\n const name = file.slice(file.lastIndexOf(\"/\") + 1).replace(/\\.js$/, \"\");\n\n return importCdnModule(browserFonts.dynamic(name));\n });\n\n browserFonts.mathjax.asyncLoad = loadDynamicFont;\n }\n\n const outputOptions = Object.assign(\n { fontData: userOptions.fontData ?? fontData },\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 || isBrowser\n ? {}\n : { dynamicPrefix: `@mathjax/mathjax-newcm-font/js/${output}/dynamic` },\n isCHTML && !userOptions.fontData\n ? { fontURL: \"https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2\" }\n : {},\n userOptions,\n );\n\n if (!isBrowser)\n registerDynamicFontLoader(output, (file) => options.asyncLoad?.(file) ?? import(file));\n else if (userOptions.fontData && options.asyncLoad)\n registerDynamicFontLoader(output, options.asyncLoad);\n\n mathjaxLib.asyncLoad = loadDynamicFont;\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 // MathJax 4 loads glyph data for commands such as `\\mathbb` on demand and throws a retry error\n // when that happens during a synchronous `convert()`. Preload every dynamic font file before the\n // instance is used so that `render()` can stay synchronous.\n //\n // A failed file is marked as failed by MathJax itself; retrying it would reject every later\n // `loadDynamicFiles()` call. Keep the instance usable for the files that did load instead.\n const shouldPreload = options.preloadDynamicFonts !== false;\n const preloadDynamicFonts = async (): Promise<void> => {\n if (!shouldPreload) return;\n\n try {\n await OutputJax.font.loadDynamicFiles();\n } catch {\n // MathJax already warned about the file and marked it as failed.\n }\n };\n\n await preloadDynamicFonts();\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 preloadDynamicFonts();\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,iBAA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AC/C,MAAME,EAAoB,EAE1B,IAAMQ,EAAQN,EAAQ,QACpBD,EAAU,WACRjB,EAAW,SAAS,GAAIc,CAAe,CACzC,CACF,EAIA,OAFAM,EAAW,EAEJI,CACT,EAYE,YAAalB,EAAQ,aAAe,IACtC,EAWA,OATAlB,EAAkB,IAAII,EAAU,CAC9B,WAAY,GACZ,eAAiB,GACf,IAAIK,EAAsC,CACxC,GAAGS,EAAQ,IACX,SAAUxD,EAAmBwD,EAAQ,KAAK,SAAUpD,CAAU,CAChE,CAAC,CACL,CAAC,EAEMsC,CACT,EAEaiC,GAAW,EAAgB,IAAoC,CAC1E,GAAIpC,EAAmB,IAAIG,CAAQ,EACjC,MAAU,MACR,wLACF,EAQFF,EAAkBE,EAAUkC,EAAG,QAAQ,IAAI,EAE3CrC,EAAmB,IAAIG,CAAQ,EAE/B,GAAM,CACJ,uBACA,aACA,YACA,OAAQmC,EACR,QACA,eACEnC,EAGEoC,EAASF,EAAG,OAAO,KAAKA,CAAE,EAC1BG,EAAeH,EAAG,aAAa,KAAKA,CAAE,EAE5C,EAAG,QAAU,EAAK,IAAgB,CAChC,GAAI,CACF,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
|
@@ -364,6 +364,51 @@ interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInli
|
|
|
364
364
|
* @default false
|
|
365
365
|
*/
|
|
366
366
|
debug?: boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Custom loader for the asynchronous files requested by MathJax.
|
|
369
|
+
*
|
|
370
|
+
* By default, Node.js imports the files from `@mathjax/mathjax-newcm-font`, while browsers load
|
|
371
|
+
* the font class, its dynamic files, and the MathJax runtime from unpkg. The plugin routes each
|
|
372
|
+
* file to the loader registered for its SVG or CHTML output, so two async instances do not
|
|
373
|
+
* overwrite each other's loader. A custom loader must return modules from the same font-class and
|
|
374
|
+
* MathJax copies that are used as `fontData` and the output jax; otherwise MathJax installs
|
|
375
|
+
* glyphs on a class the renderer does not use. MathJax's `asyncLoad` is still process-global, so
|
|
376
|
+
* the last custom loader registered for the same output wins.
|
|
377
|
+
*
|
|
378
|
+
* Only used by the async entry.
|
|
379
|
+
*
|
|
380
|
+
* 自定义 MathJax 请求的异步文件的加载器。
|
|
381
|
+
*
|
|
382
|
+
* 默认情况下,Node.js 从 `@mathjax/mathjax-newcm-font` 导入文件,浏览器则从 unpkg 加载字体类、动态文件与 MathJax
|
|
383
|
+
* 运行时。插件会按文件所属的 SVG 或 CHTML 输出分发到对应加载器,因此两个异步实例不会互相覆盖。自定义加载器必须返回与 `fontData` 和输出 jax 相同的字体类及
|
|
384
|
+
* MathJax 副本; 否则 MathJax 会把字形安装到渲染器不使用的类上。MathJax 的 `asyncLoad` 仍是进程级全局设置,后注册的同一输出加载器会覆盖先前的值。
|
|
385
|
+
*
|
|
386
|
+
* 仅异步入口使用。
|
|
387
|
+
*
|
|
388
|
+
* @param file - File name or specifier requested by MathJax / MathJax 请求的文件名或说明符
|
|
389
|
+
* @returns The loaded module / 加载的模块
|
|
390
|
+
*/
|
|
391
|
+
asyncLoad?: (file: string) => Promise<unknown>;
|
|
392
|
+
/**
|
|
393
|
+
* Whether to preload all dynamic font files when the instance is created.
|
|
394
|
+
*
|
|
395
|
+
* `render()` is synchronous, so dynamic glyphs such as `\mathbb` fail with MathJax's retry error
|
|
396
|
+
* unless their font files are already loaded. Keep this enabled unless you provide a custom
|
|
397
|
+
* loader that resolves these files synchronously or you only render glyphs from preloaded font
|
|
398
|
+
* groups.
|
|
399
|
+
*
|
|
400
|
+
* Only used by the async entry.
|
|
401
|
+
*
|
|
402
|
+
* 是否在创建实例时预加载所有动态字体文件。
|
|
403
|
+
*
|
|
404
|
+
* `render()` 是同步的,因此除非字体文件已经加载,`\mathbb` 等动态字形会触发 MathJax 的 retry
|
|
405
|
+
* 错误。除非你提供了能同步解析这些文件的自定义加载器,或只渲染已预加载字体组中的字形,否则请保持开启。
|
|
406
|
+
*
|
|
407
|
+
* 仅异步入口使用。
|
|
408
|
+
*
|
|
409
|
+
* @default true
|
|
410
|
+
*/
|
|
411
|
+
preloadDynamicFonts?: boolean;
|
|
367
412
|
}
|
|
368
413
|
/**
|
|
369
414
|
* Mathjax document options
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import{tex as e}from"@mdit/plugin-tex";import{createSyncFn as t}from"synckit";
|
|
2
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}]});
|
|
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=[];typeof e.asyncLoad==`function`&&t.push(`asyncLoad`),typeof e.preloadDynamicFonts==`boolean`&&t.push(`preloadDynamicFonts`),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
4
|
/* istanbul ignore next -- defensive: the worker always returns html for a render request */
|
|
5
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
6
|
/* istanbul ignore next -- defensive: the worker always returns html for a render request */
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,GAA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B,CAAE,EAErC,GAAI,CAACkB,EACH,MAAU,MACR,yHACF,EAGF,OAAOA,CACT,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 (typeof options.asyncLoad === \"function\") names.push(\"asyncLoad\");\n if (typeof options.preloadDynamicFonts === \"boolean\") names.push(\"preloadDynamicFonts\");\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,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O,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit/plugin-mathjax-slim",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Mathjax plugin for MarkdownIt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"engines": {
|
|
73
73
|
"node": ">=22"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "cb814cb40a5d92c7e5525ab6a4bc25116f02a619"
|
|
76
76
|
}
|