@podlite/formula 0.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @podlite/formula
2
+
3
+ ## Upcoming
4
+
5
+ ## 0.0.1
6
+
7
+ - initial import
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2024 Aliaksandr Zahatski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @podlite/formula
2
+
3
+ Example of using formulas in text (`F<>`) and as `=formula` blocks:
4
+
5
+ ```
6
+ =for formula :caption('The Cauchy-Schwarz Inequality')
7
+ \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)
8
+
9
+
10
+
11
+ This is an inline example: F< y = \sqrt{3x-1}+(1+x)^2 >
12
+ ```
13
+
14
+ Formulas can be input in Markdown mode.
15
+
16
+ ```
17
+ =begin markdown
18
+
19
+ * this is a example of `formula` inside markdown: $y = \sqrt{3x-1}+(1+x)^2$
20
+
21
+ and block:
22
+
23
+ $$
24
+ \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)
25
+ $$
26
+
27
+ or
28
+
29
+ $$
30
+ \operatorname{ker} f=\{g\in G:f(g)=e_{H}\}{\mbox{.}}
31
+ $$
32
+
33
+ =end markdown
34
+ ```
35
+
36
+ [example at pod6.in](http://pod6.in/#p=%3Dfor+formula+%3Acaption%28%27The+Cauchy-Schwarz+Inequality%27%29%0A+++%5Cleft%28+%5Csum_%7Bk%3D1%7D%5En+a_k+b_k+%5Cright%29%5E2+%5Cleq+%5Cleft%28+%5Csum_%7Bk%3D1%7D%5En+a_k%5E2+%5Cright%29+%5Cleft%28+%5Csum_%7Bk%3D1%7D%5En+b_k%5E2+%5Cright%29%0A%0A%0A%0AThis+is+an+inline++example%3A+F%3C+y+%3D+%5Csqrt%7B3x-1%7D%2B%281%2Bx%29%5E2+%3E%0A%0A%3Dbegin+markdown%0A%0A++*+this+is+a+example+of+%60formula%60+inside+markdown%3A+%24y+%3D+%5Csqrt%7B3x-1%7D%2B%281%2Bx%29%5E2%24%0A++%0A++and+block%3A+%0A++%0A++%24%24%0A++%5Cleft%28+%5Csum_%7Bk%3D1%7D%5En+a_k+b_k+%5Cright%29%5E2+%5Cleq+%5Cleft%28+%5Csum_%7Bk%3D1%7D%5En+a_k%5E2+%5Cright%29+%5Cleft%28+%5Csum_%7Bk%3D1%7D%5En+b_k%5E2+%5Cright%29%0A++%24%24%0A++%0A++%0A%0A%3Dend+markdown%0A%0A)
37
+
38
+ <div align="center">
39
+ <table border=0><tr><td valign=top><div align="center">
40
+
41
+ ##### specification
42
+
43
+ </div>
44
+
45
+ - [Source](https://github.com/podlite/podlite-specs)
46
+ - [in HTML](https://podlite.org/specification)
47
+ - [Discussions](https://github.com/podlite/podlite-specs/discussions)
48
+ - [Implementation](https://github.com/podlite/podlite)
49
+
50
+ </td><td valign=top><div align="center">
51
+
52
+ ##### publishing system
53
+
54
+ </div>
55
+
56
+ - [Podlite-web](https://github.com/podlite/podlite-web)
57
+ - [How-to article](https://zahatski.com/2022/8/23/1/start-you-own-blog-site-with-podlite-for-web)
58
+ - [Issues](https://github.com/podlite/podlite-specs/issues)
59
+
60
+ </td><td valign=top><div align="center">
61
+
62
+ ##### desktop viewer/editor
63
+
64
+ </div>
65
+
66
+ - [Podlite-desktop](https://github.com/podlite/podlite-desktop)
67
+ - [Releases](https://github.com/podlite/podlite-desktop/releases)
68
+ - [Issues](https://github.com/podlite/podlite-desktop/issues)
69
+
70
+ </td><td valign=top><div align="center">
71
+
72
+ ##### online resurces
73
+
74
+ </div>
75
+
76
+ - [podlite.org](https://podlite.org)
77
+ - [pod6.in](https://pod6.in/)
78
+ - [github.com/podlite](https://github.com/podlite/)
79
+
80
+ </td></tr></table>
81
+ </div>
82
+
83
+ ## AUTHOR
84
+
85
+ Copyright (c) 2024 Aliaksandr Zahatski
86
+
87
+ ## License
88
+
89
+ Released under a MIT License.
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ declare global {
3
+ interface Window {
4
+ MathJax: {
5
+ [key: string]: any;
6
+ };
7
+ }
8
+ }
9
+ export declare type ContextProps = {
10
+ options?: {};
11
+ src?: string;
12
+ };
13
+ export declare function useTexSVG({ latex, onSuccess, onError, }?: {
14
+ latex?: string;
15
+ onSuccess?: (html: HTMLElement) => void;
16
+ onError?: (html: HTMLElement) => void;
17
+ }): [HTMLElement | null, {
18
+ error: boolean;
19
+ isLoading: boolean;
20
+ }];
21
+ export declare type Tex2SVGProps = {
22
+ [key: string]: any;
23
+ } & {
24
+ latex: string;
25
+ onError?: (html: HTMLElement) => void;
26
+ onSuccess?: (html: HTMLElement) => void;
27
+ inline?: boolean;
28
+ };
29
+ export declare const Tex2SVG: React.FC<Tex2SVGProps>;
30
+ export declare const Tex2SVGWithProvider: React.FC<Tex2SVGProps>;
31
+ export declare const MathJaxProvider: React.FC<ContextProps>;
32
+ export declare function useTexChtml({ latex, inline, onSuccess, onError, }?: {
33
+ latex?: string;
34
+ inline?: boolean;
35
+ onSuccess?: (html: HTMLElement) => void;
36
+ onError?: (html: HTMLElement) => void;
37
+ }): [HTMLElement | null, {
38
+ error: boolean;
39
+ isLoading: boolean;
40
+ }];
41
+ export declare const Tex2Chtml: React.FC<Tex2SVGProps>;
42
+ export declare const Tex2ChtmlWithProvider: React.FC<Tex2SVGProps>;
43
+ export default Tex2SVGWithProvider;
package/esm/MathJax.js ADDED
@@ -0,0 +1,156 @@
1
+ import React, { createContext, useContext, useEffect, useRef, useState } from 'react';
2
+ const MathJaxContext = createContext({});
3
+ export function useTexSVG({ latex = '', onSuccess = (html) => { }, onError = (html) => { }, } = {}) {
4
+ const mathJax = useContext(MathJaxContext) || null;
5
+ const [html, setHtml] = useState(null);
6
+ const [isLoading, setIsLoading] = useState(false);
7
+ const error = !!html?.outerHTML.match(/data-mjx-error/);
8
+ useEffect(() => {
9
+ async function setMathJaxHTML() {
10
+ const isReady = mathJax?.tex2svgPromise || (await mathJax?.loader?.ready?.());
11
+ if (isReady) {
12
+ try {
13
+ setIsLoading(true);
14
+ const mathJaxElement = await mathJax.tex2svgPromise(latex);
15
+ setHtml(mathJaxElement);
16
+ }
17
+ catch (e) {
18
+ console.error('[podlite/formula] Something went really wrong, if this problem persists then please open an issue', e);
19
+ }
20
+ finally {
21
+ setIsLoading(false);
22
+ }
23
+ }
24
+ }
25
+ setMathJaxHTML();
26
+ }, [mathJax, latex]);
27
+ useEffect(() => {
28
+ if (html && error)
29
+ onError(html);
30
+ if (html && !error)
31
+ onSuccess(html);
32
+ }, [html]);
33
+ return [html, { error, isLoading }];
34
+ }
35
+ export const Tex2SVG = ({ latex = '', onError = (html) => { }, onSuccess = (html) => { }, ...props }) => {
36
+ const ref = useRef(null);
37
+ const [html, { error }] = useTexSVG({ latex, onError, onSuccess });
38
+ useEffect(() => {
39
+ if (html && !error) {
40
+ Object.keys(props).map(key => html.setAttribute(key, props[key]));
41
+ ref.current?.appendChild(html);
42
+ return () => {
43
+ ref.current?.removeChild(html);
44
+ };
45
+ }
46
+ return () => { };
47
+ }, [props, html]);
48
+ return React.createElement("span", { ref: ref });
49
+ };
50
+ export const Tex2SVGWithProvider = props => (React.createElement(MathJaxProvider, { src: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" },
51
+ React.createElement(Tex2SVG, { ...props })));
52
+ export const MathJaxProvider = ({ src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js', options = {}, children = null, }) => {
53
+ const [mathJax, setMathJax] = useState(typeof window === 'undefined' ? null : window.MathJax);
54
+ useEffect(() => {
55
+ const existingScript = document.getElementById('mathjax-script');
56
+ if (existingScript) {
57
+ const onLoad = existingScript.onload;
58
+ existingScript.onload = () => {
59
+ onLoad();
60
+ setMathJax(window.MathJax);
61
+ };
62
+ }
63
+ if (!existingScript && !window.MathJax) {
64
+ const script = document.createElement('script');
65
+ window.MathJax = {
66
+ tex: {
67
+ inlineMath: [],
68
+ displayMath: [],
69
+ },
70
+ options: {
71
+ enableMenu: false,
72
+ },
73
+ startup: {
74
+ elements: null,
75
+ typeset: false,
76
+ },
77
+ };
78
+ script.id = 'mathjax-script';
79
+ // "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";
80
+ // "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js";
81
+ // 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js'
82
+ script.src = src;
83
+ script.async = true;
84
+ script.onload = () => setMathJax(window.MathJax);
85
+ document.head.appendChild(script);
86
+ }
87
+ return () => { };
88
+ });
89
+ return React.createElement(MathJaxContext.Provider, { value: mathJax }, children);
90
+ };
91
+ export function useTexChtml({ latex = '', inline = false, onSuccess = (html) => { }, onError = (html) => { }, } = {}) {
92
+ const mathJax = useContext(MathJaxContext) || null;
93
+ const [html, setHtml] = useState(null);
94
+ const [isLoading, setIsLoading] = useState(false);
95
+ const error = !!html?.outerHTML.match(/data-mjx-error/);
96
+ useEffect(() => {
97
+ async function setMathJaxHTML() {
98
+ let cancelled = false;
99
+ const isReady = mathJax?.tex2chtml || (await mathJax?.loader?.ready?.());
100
+ if (isReady) {
101
+ try {
102
+ setIsLoading(true);
103
+ typeset(() => {
104
+ if (cancelled) {
105
+ return;
106
+ }
107
+ const mathJaxElement = mathJax.tex2chtml(latex, { display: !inline });
108
+ setHtml(mathJaxElement);
109
+ });
110
+ }
111
+ catch (e) {
112
+ console.error('[podlite/formula] Something went really wrong, if this problem persists then please open an issue', e);
113
+ }
114
+ finally {
115
+ setIsLoading(false);
116
+ }
117
+ }
118
+ }
119
+ setMathJaxHTML();
120
+ }, [mathJax, latex]);
121
+ useEffect(() => {
122
+ if (html && error)
123
+ onError(html);
124
+ if (html && !error)
125
+ onSuccess(html);
126
+ }, [html]);
127
+ return [html, { error, isLoading }];
128
+ }
129
+ export const Tex2Chtml = ({ latex = '', inline = false, className = inline ? 'f-code' : 'formula', onError = (html) => { }, onSuccess = (html) => { }, ...props }) => {
130
+ const ref = useRef(null);
131
+ const [html, { error }] = useTexChtml({ latex, onError, onSuccess, inline });
132
+ useEffect(() => {
133
+ if (html && !error) {
134
+ Object.keys(props).map(key => html.setAttribute(key, props[key]));
135
+ ref.current?.appendChild(html);
136
+ return () => {
137
+ ref.current?.removeChild(html);
138
+ };
139
+ }
140
+ return () => { };
141
+ }, [props, html]);
142
+ return React.createElement(inline ? 'span' : 'div', {
143
+ className,
144
+ ref: ref,
145
+ });
146
+ };
147
+ export const Tex2ChtmlWithProvider = props => (React.createElement(MathJaxProvider, { src: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" },
148
+ React.createElement(Tex2Chtml, { ...props })));
149
+ function typeset(code) {
150
+ window.MathJax.startup.promise = MathJax.startup.promise
151
+ .then(() => window.MathJax.typesetPromise(code()))
152
+ .catch(err => console.log(`[formula] typeset error: ${err.message}`));
153
+ return window.MathJax.startup.promise;
154
+ }
155
+ export default Tex2SVGWithProvider;
156
+ //# sourceMappingURL=MathJax.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MathJax.js","sourceRoot":"","sources":["../src/MathJax.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAarF,MAAM,cAAc,GAAG,aAAa,CAAC,EAAE,CAAC,CAAA;AAExC,MAAM,UAAU,SAAS,CAAC,EACxB,KAAK,GAAG,EAAE,EACV,SAAS,GAAG,CAAC,IAAiB,EAAE,EAAE,GAAE,CAAC,EACrC,OAAO,GAAG,CAAC,IAAiB,EAAE,EAAE,GAAE,CAAC,MACjC,EAAE;IACJ,MAAM,OAAO,GAA6B,UAAU,CAAC,cAAc,CAAC,IAAI,IAAI,CAAA;IAC5E,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAA;IAC1D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,UAAU,cAAc;YAC3B,MAAM,OAAO,GAAG,OAAO,EAAE,cAAc,IAAI,CAAC,MAAM,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;YAE7E,IAAI,OAAO,EAAE;gBACX,IAAI;oBACF,YAAY,CAAC,IAAI,CAAC,CAAA;oBAClB,MAAM,cAAc,GAA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ACnB,CAAA;AAUD,SAAS,OAAO,CAAC,IAAgC;IAC/C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO;SACrD,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC;SACjD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IACvE,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAA;AACvC,CAAC;AAED,eAAe,mBAAmB,CAAA"}
@@ -0,0 +1,3 @@
1
+ mjx-container[jax='CHTML'] {
2
+ font-size: 1.2em;
3
+ }
package/esm/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { Plugin, Plugins } from '@podlite/schema';
3
+ export { MathJaxProvider } from './MathJax';
4
+ declare const Formula: ({ formula, isInline, caption, id, }: {
5
+ formula: string;
6
+ caption?: string;
7
+ id?: string;
8
+ isInline: boolean;
9
+ }) => React.JSX.Element;
10
+ export declare const FormulaPlugin: Plugin;
11
+ export declare const PluginRegister: Plugins;
12
+ export default Formula;
package/esm/index.js ADDED
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { getNodeId, makeAttrs } from '@podlite/schema';
3
+ import { Tex2ChtmlWithProvider } from './MathJax';
4
+ export { MathJaxProvider } from './MathJax';
5
+ const Formula = ({ formula, isInline = false, caption, id, }) => {
6
+ const element = (React.createElement(React.Fragment, null,
7
+ React.createElement(Tex2ChtmlWithProvider, { className: `${isInline ? 'f-code' : 'formula'}`, latex: formula, inline: isInline }),
8
+ caption ? React.createElement("div", { className: "caption" }, caption) : null));
9
+ return isInline ? (element) : (React.createElement("div", { className: "formula", id: id }, element));
10
+ };
11
+ export const FormulaPlugin = {
12
+ toJSX: helper => () => (node, ctx, interator) => {
13
+ const conf = makeAttrs(node, ctx);
14
+ const caption = conf.exists('caption') ? conf.getFirstValue('caption') : null;
15
+ const id = getNodeId(node, ctx);
16
+ const isInlineContext = node.type === 'fcode';
17
+ return helper(({ children, key }) => {
18
+ return (React.createElement(Formula, { key: key, isInline: isInlineContext, id: id, caption: caption, formula: node.content[0]?.value }));
19
+ }, node, interator(node.content, { ...ctx }));
20
+ },
21
+ };
22
+ export const PluginRegister = {
23
+ formula: FormulaPlugin,
24
+ 'F<>': FormulaPlugin,
25
+ };
26
+ export default Formula;
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAmB,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,MAAM,OAAO,GAAG,CAAC,EACf,OAAO,EACP,QAAQ,GAAG,KAAK,EAChB,OAAO,EACP,EAAE,GAMH,EAAE,EAAE;IACH,MAAM,OAAO,GAAG,CACd;QACE,oBAAC,qBAAqB,IAAC,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAI;QAC3G,OAAO,CAAC,CAAC,CAAC,6BAAK,SAAS,EAAC,SAAS,IAAE,OAAO,CAAO,CAAC,CAAC,CAAC,IAAI,CACzD,CACJ,CAAA;IAED,OAAO,QAAQ,CAAC,CAAC,CAAC,CAChB,OAAO,CACR,CAAC,CAAC,CAAC,CACF,6BAAK,SAAS,EAAC,SAAS,EAAC,EAAE,EAAE,EAAE,IAC5B,OAAO,CACJ,CACP,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE;QAC9C,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAC7E,MAAM,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAC/B,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,KAAK,OAAO,CAAA;QAC7C,OAAO,MAAM,CACX,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAE;YACpB,OAAO,CACL,oBAAC,OAAO,IAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,GAAI,CAC5G,CAAA;QACH,CAAC,EACD,IAAI,EACJ,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,CACpC,CAAA;IACH,CAAC;CACF,CAAA;AACD,MAAM,CAAC,MAAM,cAAc,GAAY;IACrC,OAAO,EAAE,aAAa;IACtB,KAAK,EAAE,aAAa;CACrB,CAAA;AACD,eAAe,OAAO,CAAA"}
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ declare global {
3
+ interface Window {
4
+ MathJax: {
5
+ [key: string]: any;
6
+ };
7
+ }
8
+ }
9
+ export declare type ContextProps = {
10
+ options?: {};
11
+ src?: string;
12
+ };
13
+ export declare function useTexSVG({ latex, onSuccess, onError, }?: {
14
+ latex?: string;
15
+ onSuccess?: (html: HTMLElement) => void;
16
+ onError?: (html: HTMLElement) => void;
17
+ }): [HTMLElement | null, {
18
+ error: boolean;
19
+ isLoading: boolean;
20
+ }];
21
+ export declare type Tex2SVGProps = {
22
+ [key: string]: any;
23
+ } & {
24
+ latex: string;
25
+ onError?: (html: HTMLElement) => void;
26
+ onSuccess?: (html: HTMLElement) => void;
27
+ inline?: boolean;
28
+ };
29
+ export declare const Tex2SVG: React.FC<Tex2SVGProps>;
30
+ export declare const Tex2SVGWithProvider: React.FC<Tex2SVGProps>;
31
+ export declare const MathJaxProvider: React.FC<ContextProps>;
32
+ export declare function useTexChtml({ latex, inline, onSuccess, onError, }?: {
33
+ latex?: string;
34
+ inline?: boolean;
35
+ onSuccess?: (html: HTMLElement) => void;
36
+ onError?: (html: HTMLElement) => void;
37
+ }): [HTMLElement | null, {
38
+ error: boolean;
39
+ isLoading: boolean;
40
+ }];
41
+ export declare const Tex2Chtml: React.FC<Tex2SVGProps>;
42
+ export declare const Tex2ChtmlWithProvider: React.FC<Tex2SVGProps>;
43
+ export default Tex2SVGWithProvider;
package/lib/MathJax.js ADDED
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.Tex2ChtmlWithProvider = exports.Tex2Chtml = exports.useTexChtml = exports.MathJaxProvider = exports.Tex2SVGWithProvider = exports.Tex2SVG = exports.useTexSVG = void 0;
23
+ const react_1 = __importStar(require("react"));
24
+ const MathJaxContext = (0, react_1.createContext)({});
25
+ function useTexSVG({ latex = '', onSuccess = (html) => { }, onError = (html) => { }, } = {}) {
26
+ const mathJax = (0, react_1.useContext)(MathJaxContext) || null;
27
+ const [html, setHtml] = (0, react_1.useState)(null);
28
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
29
+ const error = !!html?.outerHTML.match(/data-mjx-error/);
30
+ (0, react_1.useEffect)(() => {
31
+ async function setMathJaxHTML() {
32
+ const isReady = mathJax?.tex2svgPromise || (await mathJax?.loader?.ready?.());
33
+ if (isReady) {
34
+ try {
35
+ setIsLoading(true);
36
+ const mathJaxElement = await mathJax.tex2svgPromise(latex);
37
+ setHtml(mathJaxElement);
38
+ }
39
+ catch (e) {
40
+ console.error('[podlite/formula] Something went really wrong, if this problem persists then please open an issue', e);
41
+ }
42
+ finally {
43
+ setIsLoading(false);
44
+ }
45
+ }
46
+ }
47
+ setMathJaxHTML();
48
+ }, [mathJax, latex]);
49
+ (0, react_1.useEffect)(() => {
50
+ if (html && error)
51
+ onError(html);
52
+ if (html && !error)
53
+ onSuccess(html);
54
+ }, [html]);
55
+ return [html, { error, isLoading }];
56
+ }
57
+ exports.useTexSVG = useTexSVG;
58
+ const Tex2SVG = ({ latex = '', onError = (html) => { }, onSuccess = (html) => { }, ...props }) => {
59
+ const ref = (0, react_1.useRef)(null);
60
+ const [html, { error }] = useTexSVG({ latex, onError, onSuccess });
61
+ (0, react_1.useEffect)(() => {
62
+ if (html && !error) {
63
+ Object.keys(props).map(key => html.setAttribute(key, props[key]));
64
+ ref.current?.appendChild(html);
65
+ return () => {
66
+ ref.current?.removeChild(html);
67
+ };
68
+ }
69
+ return () => { };
70
+ }, [props, html]);
71
+ return react_1.default.createElement("span", { ref: ref });
72
+ };
73
+ exports.Tex2SVG = Tex2SVG;
74
+ const Tex2SVGWithProvider = props => (react_1.default.createElement(exports.MathJaxProvider, { src: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" },
75
+ react_1.default.createElement(exports.Tex2SVG, { ...props })));
76
+ exports.Tex2SVGWithProvider = Tex2SVGWithProvider;
77
+ const MathJaxProvider = ({ src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js', options = {}, children = null, }) => {
78
+ const [mathJax, setMathJax] = (0, react_1.useState)(typeof window === 'undefined' ? null : window.MathJax);
79
+ (0, react_1.useEffect)(() => {
80
+ const existingScript = document.getElementById('mathjax-script');
81
+ if (existingScript) {
82
+ const onLoad = existingScript.onload;
83
+ existingScript.onload = () => {
84
+ onLoad();
85
+ setMathJax(window.MathJax);
86
+ };
87
+ }
88
+ if (!existingScript && !window.MathJax) {
89
+ const script = document.createElement('script');
90
+ window.MathJax = {
91
+ tex: {
92
+ inlineMath: [],
93
+ displayMath: [],
94
+ },
95
+ options: {
96
+ enableMenu: false,
97
+ },
98
+ startup: {
99
+ elements: null,
100
+ typeset: false,
101
+ },
102
+ };
103
+ script.id = 'mathjax-script';
104
+ // "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";
105
+ // "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js";
106
+ // 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js'
107
+ script.src = src;
108
+ script.async = true;
109
+ script.onload = () => setMathJax(window.MathJax);
110
+ document.head.appendChild(script);
111
+ }
112
+ return () => { };
113
+ });
114
+ return react_1.default.createElement(MathJaxContext.Provider, { value: mathJax }, children);
115
+ };
116
+ exports.MathJaxProvider = MathJaxProvider;
117
+ function useTexChtml({ latex = '', inline = false, onSuccess = (html) => { }, onError = (html) => { }, } = {}) {
118
+ const mathJax = (0, react_1.useContext)(MathJaxContext) || null;
119
+ const [html, setHtml] = (0, react_1.useState)(null);
120
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
121
+ const error = !!html?.outerHTML.match(/data-mjx-error/);
122
+ (0, react_1.useEffect)(() => {
123
+ async function setMathJaxHTML() {
124
+ let cancelled = false;
125
+ const isReady = mathJax?.tex2chtml || (await mathJax?.loader?.ready?.());
126
+ if (isReady) {
127
+ try {
128
+ setIsLoading(true);
129
+ typeset(() => {
130
+ if (cancelled) {
131
+ return;
132
+ }
133
+ const mathJaxElement = mathJax.tex2chtml(latex, { display: !inline });
134
+ setHtml(mathJaxElement);
135
+ });
136
+ }
137
+ catch (e) {
138
+ console.error('[podlite/formula] Something went really wrong, if this problem persists then please open an issue', e);
139
+ }
140
+ finally {
141
+ setIsLoading(false);
142
+ }
143
+ }
144
+ }
145
+ setMathJaxHTML();
146
+ }, [mathJax, latex]);
147
+ (0, react_1.useEffect)(() => {
148
+ if (html && error)
149
+ onError(html);
150
+ if (html && !error)
151
+ onSuccess(html);
152
+ }, [html]);
153
+ return [html, { error, isLoading }];
154
+ }
155
+ exports.useTexChtml = useTexChtml;
156
+ const Tex2Chtml = ({ latex = '', inline = false, className = inline ? 'f-code' : 'formula', onError = (html) => { }, onSuccess = (html) => { }, ...props }) => {
157
+ const ref = (0, react_1.useRef)(null);
158
+ const [html, { error }] = useTexChtml({ latex, onError, onSuccess, inline });
159
+ (0, react_1.useEffect)(() => {
160
+ if (html && !error) {
161
+ Object.keys(props).map(key => html.setAttribute(key, props[key]));
162
+ ref.current?.appendChild(html);
163
+ return () => {
164
+ ref.current?.removeChild(html);
165
+ };
166
+ }
167
+ return () => { };
168
+ }, [props, html]);
169
+ return react_1.default.createElement(inline ? 'span' : 'div', {
170
+ className,
171
+ ref: ref,
172
+ });
173
+ };
174
+ exports.Tex2Chtml = Tex2Chtml;
175
+ const Tex2ChtmlWithProvider = props => (react_1.default.createElement(exports.MathJaxProvider, { src: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" },
176
+ react_1.default.createElement(exports.Tex2Chtml, { ...props })));
177
+ exports.Tex2ChtmlWithProvider = Tex2ChtmlWithProvider;
178
+ function typeset(code) {
179
+ window.MathJax.startup.promise = MathJax.startup.promise
180
+ .then(() => window.MathJax.typesetPromise(code()))
181
+ .catch(err => console.log(`[formula] typeset error: ${err.message}`));
182
+ return window.MathJax.startup.promise;
183
+ }
184
+ exports.default = exports.Tex2SVGWithProvider;
185
+ //# sourceMappingURL=MathJax.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MathJax.js","sourceRoot":"","sources":["../src/MathJax.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqF;AAarF,MAAM,cAAc,GAAG,IAAA,qBAAa,EAAC,EAAE,CAAC,CAAA;AAExC,SAAgB,SAAS,CAAC,EACxB,KAAK,GAAG,EAAE,EACV,SAAS,GAAG,CAAC,IAAiB,EAAE,EAAE,GAAE,CAAC,EACrC,OAAO,GAAG,CAAC,IAAiB,EAAE,EAAE,GAAE,CAAC,MACjC,EAAE;IACJ,MAAM,OAAO,GAA6B,IAAA,kBAAU,EAAC,cAAc,CAAC,IAAI,IAAI,CAAA;IAC5E,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAqB,IAAI,CAAC,CAAA;IAC1D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAEvD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,KAAK,UAAU,cAAc;YAC3B,MAAM,OAAO,GAAG,OAAO,EAAE,cAAc,IAAI,CAAC,MAAM,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;YAE7E,IAAI,OAAO,EAAE;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E;QAClD,SAAS;QACT,GAAG,EAAE,GAAG;KACT,CAAC,CAAA;AACJ,CAAC,CAAA;AAzBY,QAAA,SAAS,aAyBrB;AAEM,MAAM,qBAAqB,GAA2B,KAAK,CAAC,EAAE,CAAC,CACpE,8BAAC,uBAAe,IAAC,GAAG,EAAC,8DAA8D;IACjF,8BAAC,iBAAS,OAAK,KAAK,GAAI,CACR,CACnB,CAAA;AAJY,QAAA,qBAAqB,yBAIjC;AAUD,SAAS,OAAO,CAAC,IAAgC;IAC/C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO;SACrD,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC;SACjD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IACvE,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAA;AACvC,CAAC;AAED,kBAAe,2BAAmB,CAAA"}
@@ -0,0 +1,3 @@
1
+ mjx-container[jax='CHTML'] {
2
+ font-size: 1.2em;
3
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { Plugin, Plugins } from '@podlite/schema';
3
+ export { MathJaxProvider } from './MathJax';
4
+ declare const Formula: ({ formula, isInline, caption, id, }: {
5
+ formula: string;
6
+ caption?: string;
7
+ id?: string;
8
+ isInline: boolean;
9
+ }) => React.JSX.Element;
10
+ export declare const FormulaPlugin: Plugin;
11
+ export declare const PluginRegister: Plugins;
12
+ export default Formula;
package/lib/index.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PluginRegister = exports.FormulaPlugin = exports.MathJaxProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const schema_1 = require("@podlite/schema");
9
+ const MathJax_1 = require("./MathJax");
10
+ var MathJax_2 = require("./MathJax");
11
+ Object.defineProperty(exports, "MathJaxProvider", { enumerable: true, get: function () { return MathJax_2.MathJaxProvider; } });
12
+ const Formula = ({ formula, isInline = false, caption, id, }) => {
13
+ const element = (react_1.default.createElement(react_1.default.Fragment, null,
14
+ react_1.default.createElement(MathJax_1.Tex2ChtmlWithProvider, { className: `${isInline ? 'f-code' : 'formula'}`, latex: formula, inline: isInline }),
15
+ caption ? react_1.default.createElement("div", { className: "caption" }, caption) : null));
16
+ return isInline ? (element) : (react_1.default.createElement("div", { className: "formula", id: id }, element));
17
+ };
18
+ exports.FormulaPlugin = {
19
+ toJSX: helper => () => (node, ctx, interator) => {
20
+ const conf = (0, schema_1.makeAttrs)(node, ctx);
21
+ const caption = conf.exists('caption') ? conf.getFirstValue('caption') : null;
22
+ const id = (0, schema_1.getNodeId)(node, ctx);
23
+ const isInlineContext = node.type === 'fcode';
24
+ return helper(({ children, key }) => {
25
+ return (react_1.default.createElement(Formula, { key: key, isInline: isInlineContext, id: id, caption: caption, formula: node.content[0]?.value }));
26
+ }, node, interator(node.content, { ...ctx }));
27
+ },
28
+ };
29
+ exports.PluginRegister = {
30
+ formula: exports.FormulaPlugin,
31
+ 'F<>': exports.FormulaPlugin,
32
+ };
33
+ exports.default = Formula;
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,4CAAuE;AACvE,uCAAiD;AACjD,qCAA2C;AAAlC,0GAAA,eAAe,OAAA;AACxB,MAAM,OAAO,GAAG,CAAC,EACf,OAAO,EACP,QAAQ,GAAG,KAAK,EAChB,OAAO,EACP,EAAE,GAMH,EAAE,EAAE;IACH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AI,CAC5G,CAAA;QACH,CAAC,EACD,IAAI,EACJ,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,CACpC,CAAA;IACH,CAAC;CACF,CAAA;AACY,QAAA,cAAc,GAAY;IACrC,OAAO,EAAE,qBAAa;IACtB,KAAK,EAAE,qBAAa;CACrB,CAAA;AACD,kBAAe,OAAO,CAAA"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@podlite/formula",
3
+ "version": "0.0.1",
4
+ "description": "=formula",
5
+ "main": "./lib/index.js",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "clean": "rm -rf esm lib *.tsbuildinfo",
9
+ "build": "yarn g:build && yarn g:copy_assets",
10
+ "test": "yarn g:jest --passWithNoTests"
11
+ },
12
+ "files": [
13
+ "lib",
14
+ "esm",
15
+ "README.md",
16
+ "CHANGELOG.md",
17
+ "LICENSE"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public",
21
+ "main": "./lib/index.js",
22
+ "types": "./lib/index.d.ts",
23
+ "module": "./esm/index.js"
24
+ },
25
+ "dependencies": {
26
+ "@podlite/schema": "0.0.19",
27
+ "react-is": "^17.0.2"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "^16.0.0 || ^17.0.0 ",
31
+ "react-dom": "^16.0.0 || ^17.0.0",
32
+ "react-is": "*"
33
+ },
34
+ "module": "./esm/index.js"
35
+ }