@pie-element/shared-math-rendering-mathjax 0.1.0 → 0.1.1-next.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/adapter.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Loads MathJax v4 from CDN and provides math rendering functionality.
5
5
  * Supports LaTeX and MathML with full accessibility features.
6
6
  */
7
- import type { MathjaxOptions } from './types';
7
+ import type { MathjaxOptions } from './types.js';
8
8
  interface MathJaxTexConfig {
9
9
  inlineMath?: [string, string][];
10
10
  displayMath?: [string, string][];
@@ -12,16 +12,23 @@ interface MathJaxTexConfig {
12
12
  packages?: string[];
13
13
  macros?: Record<string, string>;
14
14
  }
15
+ interface MathJaxDocument {
16
+ assistiveMml?: () => {
17
+ updateDocument?: () => unknown;
18
+ };
19
+ }
15
20
  interface MathJaxInstance {
16
21
  version?: string;
17
22
  tex?: MathJaxTexConfig;
18
23
  options?: {
19
24
  enableMenu?: boolean;
20
25
  enableExplorer?: boolean;
26
+ enableAssistiveMml?: boolean;
21
27
  };
22
28
  startup: {
23
29
  ready?: () => void;
24
30
  defaultReady: () => void;
31
+ document?: MathJaxDocument;
25
32
  };
26
33
  typesetPromise?: (elements?: Element[]) => Promise<void>;
27
34
  }
@@ -57,4 +64,3 @@ export declare function createMathjaxRenderer(options?: MathjaxOptions): (elemen
57
64
  */
58
65
  export declare function getMathjaxCssUrls(): string[];
59
66
  export {};
60
- //# sourceMappingURL=adapter.d.ts.map
package/dist/index.d.ts CHANGED
@@ -15,7 +15,6 @@
15
15
  * renderer(document.body);
16
16
  * ```
17
17
  */
18
- export { createMathjaxRenderer, getMathjaxCssUrls } from './adapter';
19
- export type { MathjaxOptions } from './types';
20
- export { renderMath, wrapMath, unWrapMath, mmlToLatex } from './render-math';
21
- //# sourceMappingURL=index.d.ts.map
18
+ export { createMathjaxRenderer, getMathjaxCssUrls } from './adapter.js';
19
+ export type { MathRenderer, MathRenderingAPI, MathjaxOptions } from './types.js';
20
+ export { renderMath, wrapMath, unWrapMath, mmlToLatex } from './render-math.js';
package/dist/index.js CHANGED
@@ -1,71 +1,110 @@
1
- const c = "https://cdn.jsdelivr.net/npm/mathjax@4/tex-chtml.js";
2
- let o = null;
3
- function p(t) {
4
- return typeof window > "u" || window.MathJax?.version ? Promise.resolve() : o || (o = new Promise((e, r) => {
5
- const { useSingleDollar: d = !1, accessibility: s = !0, loadFonts: l = !0, srcUrl: u } = t, n = {
6
- tex: {
7
- packages: ["base", "ams", "autoload"],
8
- macros: {
9
- parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
10
- overarc: "\\overparen",
11
- napprox: "\\not\\approx",
12
- longdiv: "\\enclose{longdiv}"
13
- }
14
- },
15
- options: {
16
- enableMenu: s,
17
- enableExplorer: s
18
- },
19
- startup: {
20
- ready: () => {
21
- window.MathJax?.startup.defaultReady && (window.MathJax.startup.defaultReady(), e());
22
- },
23
- defaultReady: () => {
24
- }
25
- }
26
- };
27
- d && n.tex && (n.tex.inlineMath = [
28
- ["$", "$"],
29
- ["\\(", "\\)"]
30
- ], n.tex.processEscapes = !0), l || (n.chtml = { fontURL: "" }), window.MathJax = n;
31
- const a = document.createElement("script");
32
- a.src = u || c, a.async = !0, a.onload = () => {
33
- setTimeout(e, 100);
34
- }, a.onerror = () => {
35
- r(new Error("Failed to load MathJax"));
36
- }, document.head.appendChild(a);
37
- }), o);
1
+ //#region src/adapter.ts
2
+ var e = null;
3
+ function t(t) {
4
+ return typeof window > "u" || window.MathJax?.typesetPromise ? Promise.resolve() : e || (e = new Promise((e, n) => {
5
+ let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: a = !0, srcUrl: o } = t, s = {
6
+ loader: { load: i ? ["a11y/assistive-mml"] : [] },
7
+ tex: {
8
+ packages: [
9
+ "base",
10
+ "ams",
11
+ "autoload"
12
+ ],
13
+ macros: {
14
+ parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
15
+ overarc: "\\overparen",
16
+ napprox: "\\not\\approx",
17
+ longdiv: "\\enclose{longdiv}"
18
+ }
19
+ },
20
+ options: {
21
+ enableMenu: i,
22
+ enableExplorer: i,
23
+ enableAssistiveMml: i
24
+ },
25
+ startup: {
26
+ ready: () => {
27
+ window.MathJax?.startup.defaultReady && (window.MathJax.startup.defaultReady(), e());
28
+ },
29
+ defaultReady: () => {}
30
+ }
31
+ };
32
+ r && s.tex && (s.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], s.tex.processEscapes = !0), a || (s.chtml = { fontURL: "" }), window.MathJax = s;
33
+ let c = document.createElement("script");
34
+ c.src = o || "https://cdn.jsdelivr.net/npm/mathjax@4/tex-chtml.js", c.async = !0, c.onload = () => {
35
+ setTimeout(e, 100);
36
+ }, c.onerror = () => {
37
+ n(/* @__PURE__ */ Error("Failed to load MathJax"));
38
+ }, document.head.appendChild(c);
39
+ }), e);
38
40
  }
39
- function m(t = {}) {
40
- return async (e) => {
41
- if (await p(t), !window.MathJax?.typesetPromise) {
42
- console.warn("[mathjax-renderer] MathJax not loaded or missing typesetPromise.");
43
- return;
44
- }
45
- await window.MathJax.typesetPromise([e]);
46
- };
41
+ function n() {
42
+ let e = window.MathJax?.startup?.document;
43
+ if (typeof e?.assistiveMml == "function") try {
44
+ e.assistiveMml().updateDocument?.();
45
+ } catch (e) {
46
+ console.warn("[mathjax-renderer] Failed to attach assistive MathML:", e);
47
+ }
47
48
  }
48
- function h() {
49
- return [];
49
+ function r(e = {}) {
50
+ return async (r) => {
51
+ if (await t(e), !window.MathJax?.typesetPromise) {
52
+ console.warn("[mathjax-renderer] MathJax not loaded or missing typesetPromise.");
53
+ return;
54
+ }
55
+ await window.MathJax.typesetPromise([r]), n();
56
+ };
50
57
  }
51
- let i = null;
52
- function w() {
53
- return i || (i = m({ accessibility: !0, useSingleDollar: !0 })), i;
58
+ function i() {
59
+ return [];
54
60
  }
55
- const f = async (t) => {
56
- if (typeof window > "u") return;
57
- const e = typeof t == "string";
58
- let r;
59
- return e ? (r = document.createElement("div"), r.innerHTML = t) : r = t || document.body, await w()(r), e ? r.innerHTML : void 0;
60
- }, x = (t) => t, M = (t) => {
61
- const e = t.trim();
62
- return e.startsWith("\\[") && e.endsWith("\\]") ? { unwrapped: e.slice(2, -2).trim(), wrapper: { open: "\\[", close: "\\]" } } : e.startsWith("\\(") && e.endsWith("\\)") ? { unwrapped: e.slice(2, -2).trim(), wrapper: { open: "\\(", close: "\\)" } } : e.startsWith("$$") && e.endsWith("$$") ? { unwrapped: e.slice(2, -2).trim(), wrapper: { open: "$$", close: "$$" } } : e.startsWith("$") && e.endsWith("$") ? { unwrapped: e.slice(1, -1).trim(), wrapper: { open: "$", close: "$" } } : { unwrapped: e };
63
- }, y = (t) => t;
64
- export {
65
- m as createMathjaxRenderer,
66
- h as getMathjaxCssUrls,
67
- y as mmlToLatex,
68
- f as renderMath,
69
- M as unWrapMath,
70
- x as wrapMath
71
- };
61
+ //#endregion
62
+ //#region src/render-math.ts
63
+ var a = null;
64
+ function o() {
65
+ return a ||= r({
66
+ accessibility: !0,
67
+ useSingleDollar: !0
68
+ }), a;
69
+ }
70
+ function s() {
71
+ if (typeof window > "u") return null;
72
+ let e = window["@pie-lib/math-rendering"];
73
+ return typeof e?.renderMath == "function" ? e : null;
74
+ }
75
+ var c = async (e) => {
76
+ if (typeof window > "u") return;
77
+ let t = typeof e == "string", n;
78
+ t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
79
+ let r = s();
80
+ return r ? await r.renderMath?.(n) : await o()(n), t ? n.innerHTML : void 0;
81
+ }, l = (e) => s()?.wrapMath?.(e) ?? e, u = (e) => {
82
+ let t = e.trim();
83
+ return t.startsWith("\\[") && t.endsWith("\\]") ? {
84
+ unwrapped: t.slice(2, -2).trim(),
85
+ wrapper: {
86
+ open: "\\[",
87
+ close: "\\]"
88
+ }
89
+ } : t.startsWith("\\(") && t.endsWith("\\)") ? {
90
+ unwrapped: t.slice(2, -2).trim(),
91
+ wrapper: {
92
+ open: "\\(",
93
+ close: "\\)"
94
+ }
95
+ } : t.startsWith("$$") && t.endsWith("$$") ? {
96
+ unwrapped: t.slice(2, -2).trim(),
97
+ wrapper: {
98
+ open: "$$",
99
+ close: "$$"
100
+ }
101
+ } : t.startsWith("$") && t.endsWith("$") ? {
102
+ unwrapped: t.slice(1, -1).trim(),
103
+ wrapper: {
104
+ open: "$",
105
+ close: "$"
106
+ }
107
+ } : { unwrapped: t };
108
+ }, d = (e) => s()?.mmlToLatex?.(e) ?? e;
109
+ //#endregion
110
+ export { r as createMathjaxRenderer, i as getMathjaxCssUrls, d as mmlToLatex, c as renderMath, u as unWrapMath, l as wrapMath };
@@ -26,4 +26,3 @@ export declare const unWrapMath: (latex: string) => {
26
26
  * MathML to LaTeX - MathJax renders MathML natively, so just pass through
27
27
  */
28
28
  export declare const mmlToLatex: (mathml: string) => string;
29
- //# sourceMappingURL=render-math.d.ts.map
package/dist/types.d.ts CHANGED
@@ -22,4 +22,13 @@ export interface MathjaxOptions {
22
22
  */
23
23
  srcUrl?: string;
24
24
  }
25
- //# sourceMappingURL=types.d.ts.map
25
+ /**
26
+ * Shared renderer contract used by players.
27
+ */
28
+ export type MathRenderer = (element: HTMLElement) => void | Promise<void>;
29
+ export interface MathRenderingAPI {
30
+ renderMath: MathRenderer;
31
+ wrapMath?: (latex: string) => string;
32
+ unWrapMath?: (wrapped: string) => string;
33
+ mmlToLatex?: (mathml: string) => string;
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-math-rendering-mathjax",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-next.1",
4
4
  "description": "MathJax adapter for PIE math rendering",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,11 +21,6 @@
21
21
  "clean": "rm -rf dist"
22
22
  },
23
23
  "dependencies": {},
24
- "devDependencies": {
25
- "typescript": "^5.9.3",
26
- "vite": "^7.2.2",
27
- "vitest": "^4.0.17"
28
- },
29
24
  "publishConfig": {
30
25
  "access": "public"
31
26
  },
@@ -36,5 +31,14 @@
36
31
  "rendering",
37
32
  "latex"
38
33
  ],
39
- "license": "MIT"
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/pie-framework/pie-elements-ng.git",
38
+ "directory": "packages/shared/math-rendering-mathjax"
39
+ },
40
+ "homepage": "https://github.com/pie-framework/pie-elements-ng#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/pie-framework/pie-elements-ng/issues"
43
+ }
40
44
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACjC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAiBD,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,gBAAgB,CAAC;IACvB,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,CAAC;IACF,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;QACnB,YAAY,EAAE,MAAM,IAAI,CAAC;KAC1B,CAAC;IACF,cAAc,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,CAAC,EAAE,eAAe,CAAC;KAC3B;CACF;AA4ED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,cAAmB,GAC3B,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAWzC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAG5C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACrE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"render-math.d.ts","sourceRoot":"","sources":["../src/render-math.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH;;GAEG;AACH,eAAO,MAAM,UAAU,GAAU,KAAK,OAAO,GAAG,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAgBlF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,MAAe,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,MAAM,KACZ;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAiBhE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,KAAG,MAAgB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}