@mdit/plugin-mathjax-slim 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/sync.d.ts DELETED
@@ -1,432 +0,0 @@
1
- import { MarkdownItTexOptions } from "@mdit/plugin-tex";
2
- import { LiteAdaptor } from "@mathjax/src/cjs/adaptors/liteAdaptor.js";
3
- import { TeX } from "@mathjax/src/cjs/input/tex.js";
4
- import { CHTML } from "@mathjax/src/cjs/output/chtml.js";
5
- import { SVG } from "@mathjax/src/cjs/output/svg.js";
6
- import { LiteElement } from "@mathjax/src/cjs/adaptors/lite/Element.js";
7
- import MarkdownIt from "markdown-it";
8
- import { MmlNode } from "@mathjax/src/js/core/MmlTree/MmlNode.js";
9
- import TexError from "@mathjax/src/js/input/tex/TexError.js";
10
- import { TeX as TeX$1 } from "@mathjax/src/js/input/tex.js";
11
- import { ChtmlFontData } from "@mathjax/src/js/output/chtml/FontData.js";
12
- import { SvgFontData } from "@mathjax/src/js/output/svg/FontData.js";
13
- import { MathItem } from "@mathjax/src/js/core/MathItem.js";
14
- import { LiteElement as LiteElement$1 } from "@mathjax/src/js/adaptors/lite/Element.js";
15
- import { MathDocument } from "@mathjax/src/js/core/MathDocument.js";
16
- import { CssStyles } from "@mathjax/src/js/ui/menu/mj-context-menu.js";
17
- import { LinebreakVisitor } from "@mathjax/src/js/output/common/LinebreakVisitor.js";
18
- import { SvgWrapperFactory } from "@mathjax/src/js/output/svg/WrapperFactory.js";
19
- import { ChtmlWrapperFactory } from "@mathjax/src/js/output/chtml/WrapperFactory.js";
20
-
21
- //#region src/mathjax.d.ts
22
- type TexPackage = "action" | "ams" | "amscd" | "bbm" | "bboldx" | "bbox" | "begingroup" | "boldsymbol" | "braket" | "bussproofs" | "cancel" | "cases" | "centernot" | "color" | "colortbl" | "colorv2" | "configmacros" | "dsfont" | "empheq" | "enclose" | "extpfeil" | "gensymb" | "html" | "mathtools" | "mhchem" | "newcommand" | "noerrors" | "noundefined" | "physics" | "setoptions" | "tagformat" | "texhtml" | "textcomp" | "textmacros" | "unicode" | "units" | "upgreek" | "verb";
23
- interface MathJaxTexInputOptions {
24
- /**
25
- * extensions to use
26
- *
27
- * @default [
28
- * 'action',
29
- * 'ams',
30
- * 'amscd',
31
- * 'bbm',
32
- * 'bboldx',
33
- * 'bbox',
34
- * 'begingroup',
35
- * 'boldsymbol',
36
- * 'braket',
37
- * 'bussproofs',
38
- * 'cancel',
39
- * 'cases',
40
- * 'centernot',
41
- * 'color',
42
- * 'colortbl',
43
- * 'colorv2',
44
- * 'configmacros',
45
- * 'dsfont',
46
- * 'empheq',
47
- * 'enclose',
48
- * 'extpfeil',
49
- * 'gensymb',
50
- * 'html',
51
- * 'mathtools',
52
- * 'mhchem',
53
- * 'newcommand',
54
- * 'noerrors',
55
- * 'noundefined',
56
- * 'physics',
57
- * 'require',
58
- * 'setoptions',
59
- * 'tagformat',
60
- * 'texhtml',
61
- * 'textcomp',
62
- * 'textmacros',
63
- * 'unicode',
64
- * 'units',
65
- * 'upgreek',
66
- * 'verb',
67
- * ]
68
- */
69
- packages?: TexPackage[];
70
- /**
71
- * pattern for recognizing numbers
72
- *
73
- * @default /^(?:[0-9]+(?:\{,\}[0-9]{3})*(?:\.[0-9]*)?|\.[0-9]+)/
74
- */
75
- digits?: RegExp;
76
- tags?: "ams" | "all" | "none";
77
- /**
78
- * side for `\tag` macros
79
- */
80
- tagSide?: "left" | "right";
81
- /**
82
- * amount to indent tags
83
- *
84
- * @default "0.8em"
85
- */
86
- tagIndent?: "0.8em";
87
- /**
88
- * use label name rather than tag for ids
89
- *
90
- * @default true;
91
- */
92
- useLabelIds?: boolean;
93
- /**
94
- * maximum number of macro substitutions per expression
95
- *
96
- * @default 1000
97
- */
98
- maxMacros?: number;
99
- /**
100
- * maximum size for the internal TeX string (in bytes)
101
- *
102
- * @default 5120
103
- */
104
- maxBuffer?: number;
105
- formatError?: (jax: TeX$1<unknown, unknown, unknown>, error: typeof TexError) => MmlNode;
106
- }
107
- /**
108
- * Data passed to MathJax filters
109
- */
110
- interface MathjaxFilterData {
111
- math: MathItem<LiteElement$1, string, HTMLElement>;
112
- document: MathDocument<LiteElement$1, string, HTMLElement>;
113
- data: any;
114
- }
115
- /**
116
- * MathJax filter function
117
- */
118
- type MathjaxFilter = (data: MathjaxFilterData) => void;
119
- /**
120
- * @see https://docs.mathjax.org/en/latest/options/output/index.html#option-descriptions
121
- */
122
- interface MathjaxCommonOutputOptions {
123
- /**
124
- * Global scaling factor for all expressions
125
- *
126
- * @default 1
127
- */
128
- scale?: number;
129
- /**
130
- * smallest scaling factor to use
131
- *
132
- * @default 0.5
133
- */
134
- minScale?: number;
135
- /**
136
- * make mtext elements use surrounding font
137
- *
138
- * @default false
139
- */
140
- mtextInheritFont?: boolean;
141
- /**
142
- * make merror text use surrounding font
143
- *
144
- * @default true
145
- */
146
- merrorInheritFont?: boolean;
147
- /**
148
- * font to use for mtext, if not inheriting (empty means use MathJax fonts)
149
- *
150
- * @default ""
151
- */
152
- mtextFont?: string;
153
- /**
154
- * font to use for merror, if not inheriting (empty means use MathJax fonts)
155
- *
156
- * @default "serif"
157
- */
158
- merrorFont?: string;
159
- /**
160
- * font to use for character that aren’t in MathJax's fonts
161
- *
162
- * @default "serif"
163
- */
164
- unknownFamily?: string;
165
- /**
166
- * - `true` for MathML spacing rules
167
- * - `false` for TeX rules
168
- *
169
- * @default false
170
- */
171
- mathmlSpacing?: boolean;
172
- /**
173
- * RFDa and other attributes NOT to copy to the output
174
- */
175
- skipAttributes?: Record<string, boolean>;
176
- /**
177
- * default size of ex in em units
178
- *
179
- * @default 0.5
180
- */
181
- exFactor?: number;
182
- /**
183
- * default for indentalign when set to 'auto'
184
- *
185
- * @default "center"
186
- */
187
- displayAlign?: "left" | "center" | "right";
188
- /**
189
- * default for indentshift when set to 'auto'
190
- *
191
- * @default 0
192
- */
193
- displayIndent?: string;
194
- /**
195
- * default for overflow
196
- *
197
- * @default "overflow"
198
- */
199
- displayOverflow?: "scroll" | "scale" | "truncate" | "elide" | "linebreak" | "overflow";
200
- /**
201
- * options for when overflow is linebreak
202
- */
203
- linebreaks?: {
204
- /**
205
- * true for browser-based breaking of inline equations
206
- *
207
- * @default true
208
- */
209
- inline?: boolean;
210
- /**
211
- * a fixed size or a percentage of the container width
212
- *
213
- * @default "100%"
214
- */
215
- width?: string;
216
- /**
217
- * the default lineleading in em units
218
- *
219
- * @default 0.2
220
- */
221
- lineleading?: number;
222
- /**
223
- * for developers only
224
- */
225
- LinebreakVisitor?: typeof LinebreakVisitor;
226
- };
227
- /**
228
- * the font component to load
229
- *
230
- * @default ""
231
- */
232
- font?: string;
233
- /**
234
- * The path to the font definitions
235
- *
236
- * @default "https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/"
237
- */
238
- fontPath?: string;
239
- /**
240
- * The font extensions to load
241
- *
242
- * @default []
243
- */
244
- fontExtensions?: string[];
245
- /**
246
- * 'use', 'force', or 'ignore' data-mjx-hdw attributes
247
- *
248
- * @default "auto"
249
- */
250
- htmlHDW?: "use" | "force" | "ignore";
251
- /**
252
- * A list of pre-filters to add to the output jax
253
- *
254
- * @default []
255
- */
256
- preFilters?: MathjaxFilter[];
257
- /**
258
- * A list of post-filters to add to the output jax
259
- *
260
- * @default []
261
- */
262
- postFilters?: MathjaxFilter[];
263
- /**
264
- * for developers only
265
- */
266
- cssStyles?: typeof CssStyles;
267
- }
268
- interface MathjaxCommonHTMLOutputOptions extends MathjaxCommonOutputOptions {
269
- /**
270
- * Whether match ex-height of surrounding font
271
- *
272
- * @default true
273
- */
274
- matchFontHeight?: boolean;
275
- /**
276
- * Font data to use
277
- *
278
- * @default font data from `@mathjax/mathjax-newcm-font`
279
- */
280
- fontData?: typeof ChtmlFontData;
281
- /**
282
- * The URL where the fonts are found
283
- *
284
- * @default jsdelivr CDN links for `@mathjax/mathjax-newcm-font`
285
- */
286
- fontURL?: string;
287
- /**
288
- * location where MathJax should look for font data that has to be loaded dynamically.
289
- *
290
- * @default jsdelivr CDN links for `@mathjax/mathjax-newcm-font`
291
- */
292
- dynamicPrefix?: string;
293
- /**
294
- * Whether only produce CSS that is used in the processed equations
295
- *
296
- * @default true
297
- */
298
- adaptiveCSS?: boolean;
299
- /**
300
- * for developers only
301
- */
302
- wrapperFactory?: typeof ChtmlWrapperFactory;
303
- }
304
- interface MathjaxSVGOutputOptions extends MathjaxCommonOutputOptions {
305
- /**
306
- * stroke-width to use for SVG character paths in units that are 1/1000 of an em
307
- *
308
- * @default 3
309
- */
310
- blacker?: number;
311
- /**
312
- * @see https://docs.mathjax.org/en/latest/options/output/svg.html#option-descriptions
313
- * @default "local"
314
- */
315
- fontCache?: "local" | "global" | "none";
316
- /**
317
- * Font data to use
318
- *
319
- * @default font data from `@mathjax/mathjax-newcm-font`
320
- */
321
- fontData?: typeof SvgFontData;
322
- /**
323
- * Whether the xlink namespace should be included in the href attributes or not
324
- *
325
- * @default true
326
- */
327
- useXlink?: boolean;
328
- /**
329
- * ID to use for local font cache (for single equation processing)
330
- */
331
- localID?: string | null;
332
- /**
333
- * for developers only
334
- */
335
- wrapperFactory?: typeof SvgWrapperFactory;
336
- }
337
- //#endregion
338
- //#region src/options.d.ts
339
- type TeXTransformer = (content: string, displayMode: boolean) => string;
340
- interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInlineWithSpace" | "delimiters" | "mathFence"> {
341
- /**
342
- * Output syntax
343
- *
344
- * 输出格式
345
- *
346
- * @default 'svg'
347
- */
348
- output?: "chtml" | "svg";
349
- /**
350
- * Enable A11y
351
- *
352
- * 是否启用无障碍
353
- *
354
- * @default true
355
- */
356
- a11y?: boolean;
357
- /**
358
- * TeX input options
359
- *
360
- * TeX 输入选项
361
- */
362
- tex?: MathJaxTexInputOptions;
363
- /**
364
- * Common HTML output options
365
- *
366
- * 通用 HTML 输出选项
367
- */
368
- chtml?: MathjaxCommonHTMLOutputOptions;
369
- /**
370
- * SVG output options
371
- *
372
- * SVG 输出选项
373
- */
374
- svg?: MathjaxSVGOutputOptions;
375
- /**
376
- * transformer on output content
377
- *
378
- * 输出内容的转换器
379
- */
380
- transformer?: TeXTransformer;
381
- }
382
- //#endregion
383
- //#region src/sync.d.ts
384
- interface DocumentOptions {
385
- InputJax: TeX<LiteElement, string, HTMLElement>;
386
- OutputJax: CHTML<LiteElement, string, HTMLElement> | SVG<LiteElement, string, HTMLElement>;
387
- enableAssistiveMml: boolean;
388
- }
389
- declare const getDocumentOptions: (options: MarkdownItMathjaxOptions) => DocumentOptions;
390
- /**
391
- * Mathjax instance
392
- */
393
- interface MathjaxInstance extends Required<Pick<MarkdownItMathjaxOptions, "allowInlineWithSpace" | "delimiters" | "mathFence">> {
394
- /**
395
- * Mathjax adaptor
396
- */
397
- adaptor: LiteAdaptor;
398
- /**
399
- * Mathjax document options
400
- */
401
- documentOptions: DocumentOptions;
402
- /**
403
- * Clear style cache
404
- */
405
- clearStyle: () => void;
406
- /**
407
- * Output style for rendered content and clears it
408
- *
409
- * @returns style
410
- */
411
- outputStyle: () => string;
412
- /**
413
- * Reset tex (including labels)
414
- */
415
- reset: () => void;
416
- /**
417
- * Output content transformer
418
- */
419
- transformer: TeXTransformer | null;
420
- }
421
- declare const createMathjaxInstance: (options?: MarkdownItMathjaxOptions) => MathjaxInstance | null;
422
- declare const mathjax: (md: MarkdownIt, {
423
- allowInlineWithSpace,
424
- adaptor,
425
- delimiters,
426
- documentOptions,
427
- mathFence,
428
- transformer
429
- }: MathjaxInstance) => void;
430
- //#endregion
431
- export { DocumentOptions, MathjaxInstance, createMathjaxInstance, getDocumentOptions, mathjax };
432
- //# sourceMappingURL=sync.d.ts.map
package/lib/sync.js DELETED
@@ -1,2 +0,0 @@
1
- import{createRequire as e}from"node:module";import{tex as t}from"@mdit/plugin-tex";const n=`action.ams.amscd.bbm.bboldx.bbox.begingroup.boldsymbol.braket.bussproofs.cancel.cases.centernot.color.colortbl.colorv2.configmacros.dsfont.empheq.enclose.extpfeil.gensymb.html.mathtools.mhchem.newcommand.noerrors.noundefined.physics.setoptions.tagformat.texhtml.textcomp.textmacros.unicode.units.upgreek.verb`.split(`.`);let r=!0,i,a,o,s,c,l,u,d=!0,f,p;try{({mathjax:i}=await import(`@mathjax/src/cjs/mathjax.js`)),{TeX:a}=await import(`@mathjax/src/cjs/input/tex.js`),{CHTML:o}=await import(`@mathjax/src/cjs/output/chtml.js`),{SVG:s}=await import(`@mathjax/src/cjs/output/svg.js`),{liteAdaptor:c}=await import(`@mathjax/src/cjs/adaptors/liteAdaptor.js`),{RegisterHTMLHandler:l}=await import(`@mathjax/src/cjs/handlers/html.js`),{AssistiveMmlHandler:u}=await import(`@mathjax/src/cjs/a11y/assistive-mml.js`),await import(`./importer-N3BdKsx_.js`);let t=e(import.meta.url);i.asyncLoad=e=>{t(e)},i.asyncIsSynchronous=!0}catch{r=!1}try{f=(await import(`@mathjax/mathjax-newcm-font/cjs/chtml.js`)).MathJaxNewcmFont,p=(await import(`@mathjax/mathjax-newcm-font/cjs/svg.js`)).MathJaxNewcmFont}catch{d=!1}const m=e=>{if(!r)throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/src" is not installed!`);let t=e.output===`chtml`,i=(t?e.chtml:e.svg)??{};if(!i.fontData&&!d)throw Error(`[@mdit/plugin-mathjax-slim] "@mathjax/mathjax-newcm-font" is not installed!`);let c=Object.assign({fontData:t?f:p},i?.fontData?{}:{dynamicPrefix:`@mathjax/mathjax-newcm-font/cjs/${t?`chtml`:`svg`}/dynamic`},t&&!i.fontData?{fontURL:`https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2`}:{},i);return{InputJax:new a({packages:[`base`,...n],...e.tex}),OutputJax:new(t?o:s)(c),enableAssistiveMml:e.a11y!==!1}},h=(e={})=>{let t=m(e),{OutputJax:n,InputJax:r}=t,a=c(),o=l(a);e.a11y!==!1&&u(o);let s=()=>{n.adaptor&&n.reset()};return{adaptor:a,documentOptions:t,allowInlineWithSpace:e.allowInlineWithSpace??!1,delimiters:e.delimiters??`dollars`,mathFence:e.mathFence??!1,clearStyle:s,reset:()=>{r.reset()},outputStyle:()=>{n.font.loadDynamicFilesSync();let e=a.cssText(n.styleSheet(i.document(``,t)));return s(),e},transformer:e.transformer??null}},g=(e,{allowInlineWithSpace:n,adaptor:r,delimiters:a,documentOptions:o,mathFence:s,transformer:c})=>{e.use(t,{allowInlineWithSpace:n,delimiters:a,mathFence:s,render:(e,t)=>{let n=i.document(e,o).convert(e,{display:t}),a=r.outerHTML(n);return c?.(a,t)??a}})};export{h as createMathjaxInstance,m as getDocumentOptions,g as mathjax};
2
- //# sourceMappingURL=sync.js.map
package/lib/sync.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"sync.js","names":[],"sources":["../src/tex/packages.ts","../src/sync.ts"],"sourcesContent":["import type { TexPackage } from \"../mathjax.js\";\n\nexport const texPackages: TexPackage[] = [\n \"action\",\n \"ams\",\n \"amscd\",\n \"bbm\",\n \"bboldx\",\n \"bbox\",\n \"begingroup\",\n \"boldsymbol\",\n \"braket\",\n \"bussproofs\",\n \"cancel\",\n \"cases\",\n \"centernot\",\n \"color\",\n \"colortbl\",\n \"colorv2\",\n \"configmacros\",\n \"dsfont\",\n \"empheq\",\n \"enclose\",\n \"extpfeil\",\n \"gensymb\",\n \"html\",\n \"mathtools\",\n \"mhchem\",\n \"newcommand\",\n \"noerrors\",\n \"noundefined\",\n \"physics\",\n \"setoptions\",\n \"tagformat\",\n \"texhtml\",\n \"textcomp\",\n \"textmacros\",\n \"unicode\",\n \"units\",\n \"upgreek\",\n \"verb\",\n];\n","/**\n * Forked from https://github.com/tani/markdown-it-mathjax3/blob/master/index.ts\n */\nimport type { MathJaxNewcmFont as MathJaxNewcmHTMLFont } from \"@mathjax/mathjax-newcm-font/cjs/chtml.js\";\nimport type { MathJaxNewcmFont as MathJaxNewcmSVGFont } from \"@mathjax/mathjax-newcm-font/cjs/svg.js\";\nimport type { AssistiveMmlHandler as AssistiveMmlHandlerType } from \"@mathjax/src/cjs/a11y/assistive-mml.js\";\nimport type { LiteDocument } from \"@mathjax/src/cjs/adaptors/lite/Document.js\";\nimport type { LiteElement, LiteNode } from \"@mathjax/src/cjs/adaptors/lite/Element.js\";\nimport type { LiteText } from \"@mathjax/src/cjs/adaptors/lite/Text.js\";\nimport type {\n LiteAdaptor,\n liteAdaptor as liteAdaptorType,\n} from \"@mathjax/src/cjs/adaptors/liteAdaptor.js\";\nimport type { MathDocument } from \"@mathjax/src/cjs/core/MathDocument.js\";\nimport type { RegisterHTMLHandler as RegisterHTMLHandlerType } from \"@mathjax/src/cjs/handlers/html.js\";\nimport type { TeX as TeXType } from \"@mathjax/src/cjs/input/tex.js\";\nimport type { mathjax as mathjaxType } from \"@mathjax/src/cjs/mathjax.js\";\nimport type { CHTML as CHTMLType } from \"@mathjax/src/cjs/output/chtml.js\";\nimport type { SVG as SVGType } from \"@mathjax/src/cjs/output/svg.js\";\nimport { tex } from \"@mdit/plugin-tex\";\nimport type MarkdownIt from \"markdown-it\";\n\nimport type { MarkdownItMathjaxOptions, TeXTransformer } from \"./options.js\";\nimport { texPackages } from \"./tex/index.js\";\n\n// oxlint-disable-next-line import/no-unassigned-import\nimport \"./tex/importer.js\";\nimport { createRequire } from \"node:module\";\n\nlet isMathJaxFullInstalled = true;\nlet mathjaxLib: typeof mathjaxType;\nlet TeX: typeof TeXType;\nlet CHTML: typeof CHTMLType;\nlet SVG: typeof SVGType;\nlet liteAdaptor: typeof liteAdaptorType;\nlet RegisterHTMLHandler: typeof RegisterHTMLHandlerType;\nlet AssistiveMmlHandler: typeof AssistiveMmlHandlerType;\nlet isMathJaxNewcmFontInstalled = true;\nlet chtmlFont: typeof MathJaxNewcmHTMLFont;\nlet svgFont: typeof MathJaxNewcmSVGFont;\n\ntry {\n ({ mathjax: mathjaxLib } = await import(\"@mathjax/src/cjs/mathjax.js\"));\n ({ TeX } = await import(\"@mathjax/src/cjs/input/tex.js\"));\n ({ CHTML } = await import(\"@mathjax/src/cjs/output/chtml.js\"));\n ({ SVG } = await import(\"@mathjax/src/cjs/output/svg.js\"));\n ({ liteAdaptor } = await import(\"@mathjax/src/cjs/adaptors/liteAdaptor.js\"));\n ({ RegisterHTMLHandler } = await import(\"@mathjax/src/cjs/handlers/html.js\"));\n ({ AssistiveMmlHandler } = await import(\"@mathjax/src/cjs/a11y/assistive-mml.js\"));\n await import(\"./tex/importer.js\");\n\n const require = createRequire(import.meta.url);\n\n mathjaxLib.asyncLoad = (file) => {\n require(file);\n };\n mathjaxLib.asyncIsSynchronous = true;\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxFullInstalled = false;\n}\n\ntry {\n // oxlint-disable-next-line unicorn/no-await-expression-member\n chtmlFont = (await import(\"@mathjax/mathjax-newcm-font/cjs/chtml.js\")).MathJaxNewcmFont;\n // oxlint-disable-next-line unicorn/no-await-expression-member\n svgFont = (await import(\"@mathjax/mathjax-newcm-font/cjs/svg.js\")).MathJaxNewcmFont;\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxNewcmFontInstalled = false;\n}\n\nexport interface DocumentOptions {\n InputJax: TeXType<LiteElement, string, HTMLElement>;\n OutputJax:\n | CHTMLType<LiteElement, string, HTMLElement>\n | SVGType<LiteElement, string, HTMLElement>;\n enableAssistiveMml: boolean;\n}\n\nexport const getDocumentOptions = (options: MarkdownItMathjaxOptions): DocumentOptions => {\n /* istanbul ignore if -- @preserve */\n if (!isMathJaxFullInstalled)\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/cjs/${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 return {\n InputJax: new TeX<LiteElement, string, HTMLElement>({\n packages: [\"base\", ...texPackages],\n ...options.tex,\n }),\n OutputJax: new (isCHTML ? CHTML : SVG)<LiteElement, string, HTMLElement>(outputOptions),\n\n enableAssistiveMml: options.a11y !== false,\n };\n};\n\n/**\n * Mathjax instance\n */\nexport interface MathjaxInstance extends Required<\n Pick<MarkdownItMathjaxOptions, \"allowInlineWithSpace\" | \"delimiters\" | \"mathFence\">\n> {\n /**\n * Mathjax adaptor\n */\n adaptor: LiteAdaptor;\n\n /**\n * Mathjax document options\n */\n documentOptions: DocumentOptions;\n\n /**\n * Clear style cache\n */\n clearStyle: () => void;\n\n /**\n * Output style for rendered content and clears it\n *\n * @returns style\n */\n outputStyle: () => string;\n\n /**\n * Reset tex (including labels)\n */\n reset: () => void;\n\n /**\n * Output content transformer\n */\n transformer: TeXTransformer | null;\n}\n\nexport const createMathjaxInstance = (\n options: MarkdownItMathjaxOptions = {},\n): MathjaxInstance | null => {\n const documentOptions = getDocumentOptions(options);\n\n const { OutputJax, InputJax } = documentOptions;\n\n const adaptor = liteAdaptor();\n // oxlint-disable-next-line new-cap\n const handler = RegisterHTMLHandler(adaptor);\n\n // oxlint-disable-next-line new-cap\n if (options.a11y !== false) AssistiveMmlHandler<LiteNode, LiteText, LiteDocument>(handler);\n\n const clearStyle = (): void => {\n // if there is no adaptor, output jax is not initialized yet, so nothing to clear\n if (!OutputJax.adaptor) return;\n\n OutputJax.reset();\n };\n\n const reset = (): void => {\n InputJax.reset();\n };\n\n const outputStyle = (): string => {\n OutputJax.font.loadDynamicFilesSync();\n\n const style = adaptor.cssText(\n OutputJax.styleSheet(\n mathjaxLib.document(\"\", documentOptions) as MathDocument<LiteElement, string, HTMLElement>,\n ),\n );\n\n clearStyle();\n\n return style;\n };\n\n return {\n adaptor,\n documentOptions,\n allowInlineWithSpace: options.allowInlineWithSpace ?? false,\n delimiters: options.delimiters ?? \"dollars\",\n mathFence: options.mathFence ?? false,\n clearStyle,\n reset,\n outputStyle,\n transformer: options.transformer ?? null,\n };\n};\n\nexport const mathjax = (\n md: MarkdownIt,\n {\n allowInlineWithSpace,\n adaptor,\n delimiters,\n documentOptions,\n mathFence,\n transformer,\n }: MathjaxInstance,\n): void => {\n md.use(tex, {\n allowInlineWithSpace,\n delimiters,\n mathFence,\n render: (content, displayMode) => {\n const mathDocument = mathjaxLib.document(content, documentOptions).convert(content, {\n display: displayMode,\n }) as LiteElement;\n\n const result = adaptor.outerHTML(mathDocument);\n\n return transformer?.(result, displayMode) ?? result;\n },\n });\n};\n"],"mappings":"mFAEA,MAAa,EAA4B,iUAuCxC,CCZD,IAAI,EAAyB,GACzB,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EAA8B,GAC9B,EACA,EAEJ,GAAI,EACD,CAAE,QAAS,GAAe,MAAM,OAAO,gCACvC,QAAU,MAAM,OAAO,iCACvB,UAAY,MAAM,OAAO,oCACzB,QAAU,MAAM,OAAO,kCACvB,gBAAkB,MAAM,OAAO,4CAC/B,wBAA0B,MAAM,OAAO,qCACvC,wBAA0B,MAAM,OAAO,0CACxC,MAAM,OAAO,0BAEb,IAAM,EAAU,EAAc,OAAO,KAAK,IAAI,CAE9C,EAAW,UAAa,GAAS,CAC/B,EAAQ,EAAK,EAEf,EAAW,mBAAqB,QAC1B,CAEN,EAAyB,GAG3B,GAAI,CAEF,GAAa,MAAM,OAAO,6CAA6C,iBAEvE,GAAW,MAAM,OAAO,2CAA2C,sBAC7D,CAEN,EAA8B,GAWhC,MAAa,EAAsB,GAAuD,CAExF,GAAI,CAAC,EACH,MAAU,MAAM,+DAA+D,CAEjF,IAAM,EAAU,EAAQ,SAAW,QAC7B,GAAe,EAAU,EAAQ,MAAQ,EAAQ,MAAQ,EAAE,CAGjE,GAAI,CAAC,EAAY,UAAY,CAAC,EAC5B,MAAU,MAAM,8EAA8E,CAEhG,IAAM,EAAgB,OAAO,OAC3B,CACE,SAAU,EAAU,EAAY,EACjC,CAGD,GAAa,SACT,EAAE,CACF,CAAE,cAAe,mCAAmC,EAAU,QAAU,MAAM,UAAW,CAC7F,GAAW,CAAC,EAAY,SACpB,CAAE,QAAS,uEAAwE,CACnF,EAAE,CACN,EACD,CAED,MAAO,CACL,SAAU,IAAI,EAAsC,CAClD,SAAU,CAAC,OAAQ,GAAG,EAAY,CAClC,GAAG,EAAQ,IACZ,CAAC,CACF,UAAW,IAAK,EAAU,EAAQ,GAAuC,EAAc,CAEvF,mBAAoB,EAAQ,OAAS,GACtC,EA0CU,GACX,EAAoC,EAAE,GACX,CAC3B,IAAM,EAAkB,EAAmB,EAAQ,CAE7C,CAAE,YAAW,YAAa,EAE1B,EAAU,GAAa,CAEvB,EAAU,EAAoB,EAAQ,CAGxC,EAAQ,OAAS,IAAO,EAAsD,EAAQ,CAE1F,IAAM,MAAyB,CAExB,EAAU,SAEf,EAAU,OAAO,EAqBnB,MAAO,CACL,UACA,kBACA,qBAAsB,EAAQ,sBAAwB,GACtD,WAAY,EAAQ,YAAc,UAClC,UAAW,EAAQ,WAAa,GAChC,aACA,UAzBwB,CACxB,EAAS,OAAO,EAyBhB,gBAtBgC,CAChC,EAAU,KAAK,sBAAsB,CAErC,IAAM,EAAQ,EAAQ,QACpB,EAAU,WACR,EAAW,SAAS,GAAI,EAAgB,CACzC,CACF,CAID,OAFA,GAAY,CAEL,GAYP,YAAa,EAAQ,aAAe,KACrC,EAGU,GACX,EACA,CACE,uBACA,UACA,aACA,kBACA,YACA,iBAEO,CACT,EAAG,IAAI,EAAK,CACV,uBACA,aACA,YACA,QAAS,EAAS,IAAgB,CAChC,IAAM,EAAe,EAAW,SAAS,EAAS,EAAgB,CAAC,QAAQ,EAAS,CAClF,QAAS,EACV,CAAC,CAEI,EAAS,EAAQ,UAAU,EAAa,CAE9C,OAAO,IAAc,EAAQ,EAAY,EAAI,GAEhD,CAAC"}
File without changes