@mdit/plugin-mathjax-slim 0.26.1 → 1.0.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/dist/sync.d.ts DELETED
@@ -1,430 +0,0 @@
1
- import { MarkdownItTexOptions } from "@mdit/plugin-tex";
2
- import { LiteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
3
- import { TeX } from "@mathjax/src/js/input/tex.js";
4
- import { CHTML } from "@mathjax/src/js/output/chtml.js";
5
- import { SVG } from "@mathjax/src/js/output/svg.js";
6
- import MarkdownIt from "markdown-it";
7
- import { LiteElement } from "@mathjax/src/js/adaptors/lite/Element.js";
8
- import { MmlNode } from "@mathjax/src/js/core/MmlTree/MmlNode.js";
9
- import TexError from "@mathjax/src/js/input/tex/TexError.js";
10
- import { ChtmlFontData } from "@mathjax/src/js/output/chtml/FontData.js";
11
- import { SvgFontData } from "@mathjax/src/js/output/svg/FontData.js";
12
- import { MathItem } from "@mathjax/src/js/core/MathItem.js";
13
- import { MathDocument } from "@mathjax/src/js/core/MathDocument.js";
14
- import { CssStyles } from "@mathjax/src/js/ui/menu/mj-context-menu.js";
15
- import { LinebreakVisitor } from "@mathjax/src/js/output/common/LinebreakVisitor.js";
16
- import { SvgWrapperFactory } from "@mathjax/src/js/output/svg/WrapperFactory.js";
17
- import { ChtmlWrapperFactory } from "@mathjax/src/js/output/chtml/WrapperFactory.js";
18
-
19
- //#region src/mathjax.d.ts
20
- 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";
21
- interface MathJaxTexInputOptions {
22
- /**
23
- * extensions to use
24
- *
25
- * @default [
26
- * 'action',
27
- * 'ams',
28
- * 'amscd',
29
- * 'bbm',
30
- * 'bboldx',
31
- * 'bbox',
32
- * 'begingroup',
33
- * 'boldsymbol',
34
- * 'braket',
35
- * 'bussproofs',
36
- * 'cancel',
37
- * 'cases',
38
- * 'centernot',
39
- * 'color',
40
- * 'colortbl',
41
- * 'colorv2',
42
- * 'configmacros',
43
- * 'dsfont',
44
- * 'empheq',
45
- * 'enclose',
46
- * 'extpfeil',
47
- * 'gensymb',
48
- * 'html',
49
- * 'mathtools',
50
- * 'mhchem',
51
- * 'newcommand',
52
- * 'noerrors',
53
- * 'noundefined',
54
- * 'physics',
55
- * 'require',
56
- * 'setoptions',
57
- * 'tagformat',
58
- * 'texhtml',
59
- * 'textcomp',
60
- * 'textmacros',
61
- * 'unicode',
62
- * 'units',
63
- * 'upgreek',
64
- * 'verb',
65
- * ]
66
- */
67
- packages?: TexPackage[];
68
- /**
69
- * pattern for recognizing numbers
70
- *
71
- * @default /^(?:[0-9]+(?:\{,\}[0-9]{3})*(?:\.[0-9]*)?|\.[0-9]+)/
72
- */
73
- digits?: RegExp;
74
- tags?: "ams" | "all" | "none";
75
- /**
76
- * side for `\tag` macros
77
- */
78
- tagSide?: "left" | "right";
79
- /**
80
- * amount to indent tags
81
- *
82
- * @default "0.8em"
83
- */
84
- tagIndent?: "0.8em";
85
- /**
86
- * use label name rather than tag for ids
87
- *
88
- * @default true;
89
- */
90
- useLabelIds?: boolean;
91
- /**
92
- * maximum number of macro substitutions per expression
93
- *
94
- * @default 1000
95
- */
96
- maxMacros?: number;
97
- /**
98
- * maximum size for the internal TeX string (in bytes)
99
- *
100
- * @default 5120
101
- */
102
- maxBuffer?: number;
103
- formatError?: (jax: TeX<unknown, unknown, unknown>, error: typeof TexError) => MmlNode;
104
- }
105
- /**
106
- * Data passed to MathJax filters
107
- */
108
- interface MathjaxFilterData {
109
- math: MathItem<LiteElement, string, HTMLElement>;
110
- document: MathDocument<LiteElement, string, HTMLElement>;
111
- data: any;
112
- }
113
- /**
114
- * MathJax filter function
115
- */
116
- type MathjaxFilter = (data: MathjaxFilterData) => void;
117
- /**
118
- * @see https://docs.mathjax.org/en/latest/options/output/index.html#option-descriptions
119
- */
120
- interface MathjaxCommonOutputOptions {
121
- /**
122
- * Global scaling factor for all expressions
123
- *
124
- * @default 1
125
- */
126
- scale?: number;
127
- /**
128
- * smallest scaling factor to use
129
- *
130
- * @default 0.5
131
- */
132
- minScale?: number;
133
- /**
134
- * make mtext elements use surrounding font
135
- *
136
- * @default false
137
- */
138
- mtextInheritFont?: boolean;
139
- /**
140
- * make merror text use surrounding font
141
- *
142
- * @default true
143
- */
144
- merrorInheritFont?: boolean;
145
- /**
146
- * font to use for mtext, if not inheriting (empty means use MathJax fonts)
147
- *
148
- * @default ""
149
- */
150
- mtextFont?: string;
151
- /**
152
- * font to use for merror, if not inheriting (empty means use MathJax fonts)
153
- *
154
- * @default "serif"
155
- */
156
- merrorFont?: string;
157
- /**
158
- * font to use for character that aren’t in MathJax's fonts
159
- *
160
- * @default "serif"
161
- */
162
- unknownFamily?: string;
163
- /**
164
- * - `true` for MathML spacing rules
165
- * - `false` for TeX rules
166
- *
167
- * @default false
168
- */
169
- mathmlSpacing?: boolean;
170
- /**
171
- * RFDa and other attributes NOT to copy to the output
172
- */
173
- skipAttributes?: Record<string, boolean>;
174
- /**
175
- * default size of ex in em units
176
- *
177
- * @default 0.5
178
- */
179
- exFactor?: number;
180
- /**
181
- * default for indentalign when set to 'auto'
182
- *
183
- * @default "center"
184
- */
185
- displayAlign?: "left" | "center" | "right";
186
- /**
187
- * default for indentshift when set to 'auto'
188
- *
189
- * @default 0
190
- */
191
- displayIndent?: string;
192
- /**
193
- * default for overflow
194
- *
195
- * @default "overflow"
196
- */
197
- displayOverflow?: "scroll" | "scale" | "truncate" | "elide" | "linebreak" | "overflow";
198
- /**
199
- * options for when overflow is linebreak
200
- */
201
- linebreaks?: {
202
- /**
203
- * true for browser-based breaking of inline equations
204
- *
205
- * @default true
206
- */
207
- inline?: boolean;
208
- /**
209
- * a fixed size or a percentage of the container width
210
- *
211
- * @default "100%"
212
- */
213
- width?: string;
214
- /**
215
- * the default lineleading in em units
216
- *
217
- * @default 0.2
218
- */
219
- lineleading?: number;
220
- /**
221
- * for developers only
222
- */
223
- LinebreakVisitor?: typeof LinebreakVisitor;
224
- };
225
- /**
226
- * the font component to load
227
- *
228
- * @default ""
229
- */
230
- font?: string;
231
- /**
232
- * The path to the font definitions
233
- *
234
- * @default "https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/"
235
- */
236
- fontPath?: string;
237
- /**
238
- * The font extensions to load
239
- *
240
- * @default []
241
- */
242
- fontExtensions?: string[];
243
- /**
244
- * 'use', 'force', or 'ignore' data-mjx-hdw attributes
245
- *
246
- * @default "auto"
247
- */
248
- htmlHDW?: "use" | "force" | "ignore";
249
- /**
250
- * A list of pre-filters to add to the output jax
251
- *
252
- * @default []
253
- */
254
- preFilters?: MathjaxFilter[];
255
- /**
256
- * A list of post-filters to add to the output jax
257
- *
258
- * @default []
259
- */
260
- postFilters?: MathjaxFilter[];
261
- /**
262
- * for developers only
263
- */
264
- cssStyles?: typeof CssStyles;
265
- }
266
- interface MathjaxCommonHTMLOutputOptions extends MathjaxCommonOutputOptions {
267
- /**
268
- * Whether match ex-height of surrounding font
269
- *
270
- * @default true
271
- */
272
- matchFontHeight?: boolean;
273
- /**
274
- * Font data to use
275
- *
276
- * @default font data from `@mathjax/mathjax-newcm-font`
277
- */
278
- fontData?: typeof ChtmlFontData;
279
- /**
280
- * The URL where the fonts are found
281
- *
282
- * @default jsdelivr CDN links for `@mathjax/mathjax-newcm-font`
283
- */
284
- fontURL?: string;
285
- /**
286
- * location where MathJax should look for font data that has to be loaded dynamically.
287
- *
288
- * @default jsdelivr CDN links for `@mathjax/mathjax-newcm-font`
289
- */
290
- dynamicPrefix?: string;
291
- /**
292
- * Whether only produce CSS that is used in the processed equations
293
- *
294
- * @default true
295
- */
296
- adaptiveCSS?: boolean;
297
- /**
298
- * for developers only
299
- */
300
- wrapperFactory?: typeof ChtmlWrapperFactory;
301
- }
302
- interface MathjaxSVGOutputOptions extends MathjaxCommonOutputOptions {
303
- /**
304
- * stroke-width to use for SVG character paths in units that are 1/1000 of an em
305
- *
306
- * @default 3
307
- */
308
- blacker?: number;
309
- /**
310
- * @see https://docs.mathjax.org/en/latest/options/output/svg.html#option-descriptions
311
- * @default "local"
312
- */
313
- fontCache?: "local" | "global" | "none";
314
- /**
315
- * Font data to use
316
- *
317
- * @default font data from `@mathjax/mathjax-newcm-font`
318
- */
319
- fontData?: typeof SvgFontData;
320
- /**
321
- * Whether the xlink namespace should be included in the href attributes or not
322
- *
323
- * @default true
324
- */
325
- useXlink?: boolean;
326
- /**
327
- * ID to use for local font cache (for single equation processing)
328
- */
329
- localID?: string | null;
330
- /**
331
- * for developers only
332
- */
333
- wrapperFactory?: typeof SvgWrapperFactory;
334
- }
335
- //#endregion
336
- //#region src/options.d.ts
337
- type TeXTransformer = (content: string, displayMode: boolean) => string;
338
- interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInlineWithSpace" | "delimiters" | "mathFence"> {
339
- /**
340
- * Output syntax
341
- *
342
- * 输出格式
343
- *
344
- * @default 'svg'
345
- */
346
- output?: "chtml" | "svg";
347
- /**
348
- * Enable A11y
349
- *
350
- * 是否启用无障碍
351
- *
352
- * @default true
353
- */
354
- a11y?: boolean;
355
- /**
356
- * TeX input options
357
- *
358
- * TeX 输入选项
359
- */
360
- tex?: MathJaxTexInputOptions;
361
- /**
362
- * Common HTML output options
363
- *
364
- * 通用 HTML 输出选项
365
- */
366
- chtml?: MathjaxCommonHTMLOutputOptions;
367
- /**
368
- * SVG output options
369
- *
370
- * SVG 输出选项
371
- */
372
- svg?: MathjaxSVGOutputOptions;
373
- /**
374
- * transformer on output content
375
- *
376
- * 输出内容的转换器
377
- */
378
- transformer?: TeXTransformer;
379
- }
380
- interface DocumentOptions {
381
- InputJax: TeX<LiteElement, string, HTMLElement>;
382
- OutputJax: CHTML<LiteElement, string, HTMLElement> | SVG<LiteElement, string, HTMLElement>;
383
- enableAssistiveMml: boolean;
384
- }
385
- /**
386
- * Mathjax instance common options
387
- */
388
- interface MathjaxInstance<Sync extends boolean = false> extends Required<Pick<MarkdownItMathjaxOptions, "allowInlineWithSpace" | "delimiters" | "mathFence">> {
389
- /**
390
- * Mathjax adaptor
391
- */
392
- adaptor: LiteAdaptor;
393
- /**
394
- * Mathjax document options
395
- */
396
- documentOptions: DocumentOptions;
397
- /**
398
- * Output style for rendered content and clears it
399
- *
400
- * @returns style
401
- */
402
- outputStyle: () => Sync extends true ? string : Promise<string>;
403
- /**
404
- * Reset tex (including labels)
405
- */
406
- reset: () => void;
407
- /**
408
- * Clear style cache
409
- */
410
- clearStyle: () => void;
411
- /**
412
- * Output content transformer
413
- */
414
- transformer: TeXTransformer | null;
415
- }
416
- //#endregion
417
- //#region src/sync.d.ts
418
- declare const getDocumentOptions: (options: MarkdownItMathjaxOptions) => DocumentOptions;
419
- declare const createMathjaxInstance: (options?: MarkdownItMathjaxOptions) => MathjaxInstance<true> | null;
420
- declare const mathjax: (md: MarkdownIt, {
421
- allowInlineWithSpace,
422
- adaptor,
423
- delimiters,
424
- documentOptions,
425
- mathFence,
426
- transformer
427
- }: MathjaxInstance) => void;
428
- //#endregion
429
- export { createMathjaxInstance, getDocumentOptions, mathjax };
430
- //# sourceMappingURL=sync.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sync.d.ts","names":[],"sources":["../src/mathjax.ts","../src/options.ts","../src/sync.ts"],"mappings":";;;;;;;;;;;;;;;;;;;KAaY,UAAA;AAAA,UAwCK,sBAAA;;;;;;AAxCjB;;;;;AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA;;;;;;;EAlDE,QAAA,GAAW,UAAA;;;;;;EAOX,MAAA,GAAS,MAAA;EAET,IAAA;;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AM/C,OAAA;;;;;EAMA,SAAA;;;;;;EAOA,QAAA,UAAkB,WAAA;;;;;;EAOlB,QAAA;;;;EAKA,OAAA;;;;EAKA,cAAA,UAAwB,iBAAA;AAAA;;;KC/Yd,cAAA,IAAkB,OAAA,UAAiB,WAAA;AAAA,UAE9B,wBAAA,SAAiC,IAAA,CAChD,oBAAA;;;;;;;;EAWA,MAAA;;;ADdF;;;;;ECuBE,IAAA;EDiBe;;;;;ECVf,GAAA,GAAM,sBAAA;;;;;;EAON,KAAA,GAAQ,8BAAA;;;;;;EAOR,GAAA,GAAM,uBAAA;;;;;;EAON,WAAA,GAAc,cAAA;AAAA;AAAA,UAGC,eAAA;EACf,QAAA,EAAU,GAAA,CAAI,WAAA,UAAqB,WAAA;EACnC,SAAA,EAAW,KAAA,CAAM,WAAA,UAAqB,WAAA,IAAe,GAAA,CAAI,WAAA,UAAqB,WAAA;EAC9E,kBAAA;AAAA;;;;UAMe,eAAA,uCAAsD,QAAA,CACrE,IAAA,CAAK,wBAAA;;;;EAKL,OAAA,EAAS,WAAA;;;;EAKT,eAAA,EAAiB,eAAA;;;;;;EAOjB,WAAA,QAAmB,IAAA,yBAA6B,OAAA;ED2DhD;AAMF;;EC5DE,KAAA;ED4DiC;;AAKnC;EC5DE,UAAA;;;;EAKA,WAAA,EAAa,cAAA;AAAA;;;cC3CF,kBAAA,GAAsB,OAAA,EAAS,wBAAA,KAA2B,eAAA;AAAA,cAqC1D,qBAAA,GACX,OAAA,GAAS,wBAAA,KACR,eAAA;AAAA,cAiDU,OAAA,GACX,EAAA,EAAI,UAAA;EAEF,oBAAA;EACA,OAAA;EACA,UAAA;EACA,eAAA;EACA,SAAA;EACA;AAAA,GACC,eAAA"}
package/dist/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/js/mathjax.js`)),{TeX:a}=await import(`@mathjax/src/js/input/tex.js`),{CHTML:o}=await import(`@mathjax/src/js/output/chtml.js`),{SVG:s}=await import(`@mathjax/src/js/output/svg.js`),{liteAdaptor:c}=await import(`@mathjax/src/js/adaptors/liteAdaptor.js`),{RegisterHTMLHandler:l}=await import(`@mathjax/src/js/handlers/html.js`),{AssistiveMmlHandler:u}=await import(`@mathjax/src/js/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/js/chtml.js`)).MathJaxNewcmFont,p=(await import(`@mathjax/mathjax-newcm-font/js/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/js/${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!=null&&(r.reset(),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/dist/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 */\n// oxlint-disable-next-line import/no-nodejs-modules\nimport { createRequire } from \"node:module\";\n\nimport type { MathJaxNewcmFont as MathJaxNewcmHTMLFont } from \"@mathjax/mathjax-newcm-font/js/chtml.js\";\nimport type { MathJaxNewcmFont as MathJaxNewcmSVGFont } from \"@mathjax/mathjax-newcm-font/js/svg.js\";\nimport type { AssistiveMmlHandler as AssistiveMmlHandlerType } from \"@mathjax/src/js/a11y/assistive-mml.js\";\nimport type { LiteDocument } from \"@mathjax/src/js/adaptors/lite/Document.js\";\nimport type { LiteElement, LiteNode } from \"@mathjax/src/js/adaptors/lite/Element.js\";\nimport type { LiteText } from \"@mathjax/src/js/adaptors/lite/Text.js\";\nimport type { liteAdaptor as liteAdaptorType } from \"@mathjax/src/js/adaptors/liteAdaptor.js\";\nimport type { MathDocument } from \"@mathjax/src/js/core/MathDocument.js\";\nimport type { RegisterHTMLHandler as RegisterHTMLHandlerType } from \"@mathjax/src/js/handlers/html.js\";\nimport type { TeX as TeXType } from \"@mathjax/src/js/input/tex.js\";\nimport type { mathjax as mathjaxType } from \"@mathjax/src/js/mathjax.js\";\nimport type { CHTML as CHTMLType } from \"@mathjax/src/js/output/chtml.js\";\nimport type { SVG as SVGType } from \"@mathjax/src/js/output/svg.js\";\nimport { tex } from \"@mdit/plugin-tex\";\nimport type MarkdownIt from \"markdown-it\";\n\nimport type { MarkdownItMathjaxOptions, DocumentOptions, MathjaxInstance } from \"./options.js\";\nimport { texPackages } from \"./tex/index.js\";\n\nlet isMathJaxInstalled = 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/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 await import(\"./importer.js\");\n\n const require = createRequire(import.meta.url);\n\n mathjaxLib.asyncLoad = (file): void => {\n // oxlint-disable-next-line import/no-dynamic-require\n require(file);\n };\n mathjaxLib.asyncIsSynchronous = true;\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxInstalled = false;\n}\n\ntry {\n chtmlFont = (await import(\"@mathjax/mathjax-newcm-font/js/chtml.js\")).MathJaxNewcmFont;\n svgFont = (await import(\"@mathjax/mathjax-newcm-font/js/svg.js\")).MathJaxNewcmFont;\n} catch {\n /* istanbul ignore next -- @preserve */\n isMathJaxNewcmFontInstalled = false;\n}\nexport const getDocumentOptions = (options: MarkdownItMathjaxOptions): DocumentOptions => {\n /* istanbul ignore if -- @preserve */\n if (!isMathJaxInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/src\" is not installed!');\n\n const isCHTML = options.output === \"chtml\";\n const userOptions = (isCHTML ? options.chtml : options.svg) ?? {};\n\n /* istanbul ignore if -- @preserve */\n if (!userOptions.fontData && !isMathJaxNewcmFontInstalled)\n throw new Error('[@mdit/plugin-mathjax-slim] \"@mathjax/mathjax-newcm-font\" is not installed!');\n\n const outputOptions = Object.assign(\n {\n fontData: isCHTML ? chtmlFont : svgFont,\n },\n // fontURL can be set to undefined if you want to bundle the fonts yourself\n // both fontURL and dynamicPrefix shall be synced with fontData, so set it to undefined if fontData is customized\n userOptions?.fontData\n ? {}\n : { dynamicPrefix: `@mathjax/mathjax-newcm-font/js/${isCHTML ? \"chtml\" : \"svg\"}/dynamic` },\n isCHTML && !userOptions.fontData\n ? { fontURL: \"https://cdn.jsdelivr.net/npm/@mathjax/mathjax-newcm-font/chtml/woff2\" }\n : {},\n userOptions,\n );\n\n return {\n InputJax: new TeX<LiteElement, string, HTMLElement>({\n packages: [\"base\", ...texPackages],\n ...options.tex,\n }),\n OutputJax: new (isCHTML ? CHTML : SVG)<LiteElement, string, HTMLElement>(outputOptions),\n enableAssistiveMml: options.a11y !== false,\n };\n};\n\nexport const createMathjaxInstance = (\n options: MarkdownItMathjaxOptions = {},\n): MathjaxInstance<true> | null => {\n const documentOptions = getDocumentOptions(options);\n const { OutputJax, InputJax } = documentOptions;\n\n const adaptor = liteAdaptor();\n // oxlint-disable-next-line new-cap\n const handler = RegisterHTMLHandler(adaptor);\n // oxlint-disable-next-line new-cap\n if (options.a11y !== false) AssistiveMmlHandler<LiteNode, LiteText, LiteDocument>(handler);\n\n const clearStyle = (): void => {\n // if there is no adaptor, output jax is not initialized yet, so nothing to clear\n if (OutputJax.adaptor == null) return;\n\n InputJax.reset();\n OutputJax.reset();\n };\n\n const reset = (): void => {\n InputJax.reset();\n };\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};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