better-react-mathjax 2.0.4-beta1 → 2.2.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/MathJaxContext/MathJaxContext.d.ts +1 -0
- package/MathJaxContext/MathJaxContext.js +1 -1
- package/README.md +13 -4
- package/esm/MathJaxContext/MathJaxContext.js +1 -1
- package/package.json +1 -1
- package/ServerMathjaxContext/ServerMathjaxContext.d.ts +0 -1
- package/ServerMathjaxContext/ServerMathjaxContext.js +0 -1
- package/ServerMathjaxContext/package.json +0 -5
- package/esm/ServerMathjaxContext/ServerMathjaxContext.js +0 -1
|
@@ -20,6 +20,7 @@ export type MathJaxSubscriberProps = ({
|
|
|
20
20
|
export declare const MathJaxBaseContext: React.Context<MathJaxSubscriberProps | undefined>;
|
|
21
21
|
interface MathJaxContextStaticProps extends MathJaxOverrideableProps {
|
|
22
22
|
src?: string;
|
|
23
|
+
asyncLoad?: boolean;
|
|
23
24
|
onLoad?: () => void;
|
|
24
25
|
onError?: (error: any) => void;
|
|
25
26
|
children?: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var v2Promise,v3Promise,__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,
|
|
1
|
+
"use strict";var v2Promise,v3Promise,__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&("get"in r?t.__esModule:!r.writable&&!r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){e[n=void 0===n?o:n]=t[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&__createBinding(t,e,o);return __setModuleDefault(t,e),t},react_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MathJaxBaseContext=void 0,__importStar(require("react"))),DEFAULT_V2_SRC=(exports.MathJaxBaseContext=(0,react_1.createContext)(void 0),"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-MML-AM_CHTML"),DEFAULT_V3_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js",MathJaxContext=function(e){var n=e.config,t=e.version,t=void 0===t?3:t,o=e.src,o=void 0===o?2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC:o,r=e.onStartup,i=e.onLoad,a=e.asyncLoad,s=void 0!==a&&a,c=e.onError,a=e.typesettingOptions,u=e.renderMode,u=void 0===u?"post":u,d=e.hideUntilTypeset,e=e.children,h=(0,react_1.useContext)(exports.MathJaxBaseContext);if(void 0!==(null==h?void 0:h.version)&&(null==h?void 0:h.version)!==t)throw Error("Cannot nest MathJaxContexts with different versions. MathJaxContexts should not be nested at all but if they are, they cannot have different versions. Stick with one version of MathJax in your app and avoid using more than one MathJaxContext.");if(2===t&&void 0!==v3Promise||3===t&&void 0!==v2Promise)throw Error("Cannot use MathJax versions 2 and 3 simultaneously in the same app due to how MathJax is set up in the browser; either you have multiple MathJaxContexts with different versions or you have mounted and unmounted MathJaxContexts with different versions. Please stick with one version of MathJax in your app. File an issue in the project Github page if you need this feature.");var l=(0,react_1.useRef)(h),h=(0,react_1.useRef)((null==h?void 0:h.version)||null);if(null===h.current)h.current=t;else if(h.current!==t)throw Error("Cannot change version of MathJax in a MathJaxContext after it has mounted. Reload the page with a new version when this must happen.");var v=o||(2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC);function f(t,o){n&&(window.MathJax=n);var e=document.createElement("script");e.type="text/javascript",e.src=v,e.async=s,e.addEventListener("load",function(){var e=window.MathJax;r&&r(e),t(e),i&&i()}),e.addEventListener("error",function(e){return o(e)}),document.getElementsByTagName("head")[0].appendChild(e)}return void 0===l.current&&(h={typesettingOptions:a,renderMode:u,hideUntilTypeset:d},2===t?void 0===v2Promise&&("undefined"!=typeof window?(v2Promise=new Promise(f)).catch(function(e){if(!c)throw Error("Failed to download MathJax version 2 from '".concat(v,"' due to: ").concat(JSON.stringify(e)));c(e)}):(v2Promise=Promise.reject()).catch(function(e){})):void 0===v3Promise&&("undefined"!=typeof window?(v3Promise=new Promise(f)).catch(function(e){if(!c)throw Error("Failed to download MathJax version 3 from '".concat(v,"' due to: ").concat(e));c(e)}):(v3Promise=Promise.reject()).catch(function(e){})),l.current=__assign(__assign({},h),2===t?{version:2,promise:v2Promise}:{version:3,promise:v3Promise})),react_1.default.createElement(exports.MathJaxBaseContext.Provider,{value:l.current},e)};exports.default=MathJaxContext;
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ well as dynamic updates. Simple to use but with many configuration options.
|
|
|
34
34
|
Add this library manually as a dependency to `package.json`...
|
|
35
35
|
```
|
|
36
36
|
dependencies: {
|
|
37
|
-
"better-react-mathjax": "^2.0
|
|
37
|
+
"better-react-mathjax": "^2.2.0"
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
... and then run `npm install` **or** let `npm` or `yarn` do it for you, depending on which package manager you have
|
|
@@ -95,6 +95,9 @@ Latex and MathML with the default [MathJax version 3](https://docs.mathjax.org/e
|
|
|
95
95
|
HTML output for both. If you need something else or want to host your own copy of MathJax, read more about the `src`
|
|
96
96
|
attribute of the `MathJaxContext` below.
|
|
97
97
|
|
|
98
|
+
Note that both `MathJax` and `MathJaxContext` components ship with `"use client"` directives and are thus client
|
|
99
|
+
components in contexts where this is taken into account.
|
|
100
|
+
|
|
98
101
|
## Examples
|
|
99
102
|
|
|
100
103
|
The first 3 are basic examples with zero configuration standard setup using MathJax version 3 with default MathJax config
|
|
@@ -277,14 +280,20 @@ to do any further configuration which cannot be done through the `config` object
|
|
|
277
280
|
|
|
278
281
|
**Default**: `undefined`
|
|
279
282
|
|
|
280
|
-
### `onLoad: () => void
|
|
283
|
+
### `onLoad: () => void | undefined` ###
|
|
281
284
|
|
|
282
285
|
Callback to be called when MathJax has loaded successfully and after the MathJax object has been made available to the
|
|
283
286
|
wrapped `MathJax` components.
|
|
284
287
|
|
|
285
288
|
**Default**: `undefined`
|
|
286
289
|
|
|
287
|
-
### `
|
|
290
|
+
### `asyncLoad: boolean | undefined` ###
|
|
291
|
+
|
|
292
|
+
Value to use for the `async` property of the MathJax `script` tag.
|
|
293
|
+
|
|
294
|
+
**Default**: `false`
|
|
295
|
+
|
|
296
|
+
### `onError: (error: any) => void | undefined` ###
|
|
288
297
|
|
|
289
298
|
Callback to handle errors in the startup phase when MathJax is loaded.
|
|
290
299
|
|
|
@@ -326,7 +335,7 @@ Requires `typesettingOptions` to be set and version to be `3`. If `renderMode` i
|
|
|
326
335
|
|
|
327
336
|
Indicates whether the content of the `MathJax` component may change after initial rendering.
|
|
328
337
|
|
|
329
|
-
**Default**: `false`
|
|
338
|
+
**Default**: `false` (**note**: is `true` by default in development environment for hot reload to work)
|
|
330
339
|
|
|
331
340
|
***
|
|
332
341
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var a in t=arguments[o])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};import React,{createContext,useContext,useRef}from"react";var v2Promise,v3Promise,MathJaxBaseContext=createContext(void 0),DEFAULT_V2_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-MML-AM_CHTML",DEFAULT_V3_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js",MathJaxContext=function(e){var n=e.config,t=e.version,t=void 0===t?3:t,o=e.src,o=void 0===o?2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC:o,a=e.onStartup,r=e.onLoad,i=e.
|
|
1
|
+
var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var a in t=arguments[o])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};import React,{createContext,useContext,useRef}from"react";var v2Promise,v3Promise,MathJaxBaseContext=createContext(void 0),DEFAULT_V2_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-MML-AM_CHTML",DEFAULT_V3_SRC="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js",MathJaxContext=function(e){var n=e.config,t=e.version,t=void 0===t?3:t,o=e.src,o=void 0===o?2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC:o,a=e.onStartup,r=e.onLoad,i=e.asyncLoad,s=void 0!==i&&i,h=e.onError,i=e.typesettingOptions,d=e.renderMode,d=void 0===d?"post":d,c=e.hideUntilTypeset,e=e.children,u=useContext(MathJaxBaseContext);if(void 0!==(null==u?void 0:u.version)&&(null==u?void 0:u.version)!==t)throw Error("Cannot nest MathJaxContexts with different versions. MathJaxContexts should not be nested at all but if they are, they cannot have different versions. Stick with one version of MathJax in your app and avoid using more than one MathJaxContext.");if(2===t&&void 0!==v3Promise||3===t&&void 0!==v2Promise)throw Error("Cannot use MathJax versions 2 and 3 simultaneously in the same app due to how MathJax is set up in the browser; either you have multiple MathJaxContexts with different versions or you have mounted and unmounted MathJaxContexts with different versions. Please stick with one version of MathJax in your app. File an issue in the project Github page if you need this feature.");var v=useRef(u),u=useRef((null==u?void 0:u.version)||null);if(null===u.current)u.current=t;else if(u.current!==t)throw Error("Cannot change version of MathJax in a MathJaxContext after it has mounted. Reload the page with a new version when this must happen.");var f=o||(2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC);function l(t,o){n&&(window.MathJax=n);var e=document.createElement("script");e.type="text/javascript",e.src=f,e.async=s,e.addEventListener("load",function(){var e=window.MathJax;a&&a(e),t(e),r&&r()}),e.addEventListener("error",function(e){return o(e)}),document.getElementsByTagName("head")[0].appendChild(e)}return void 0===v.current&&(u={typesettingOptions:i,renderMode:d,hideUntilTypeset:c},2===t?void 0===v2Promise&&("undefined"!=typeof window?(v2Promise=new Promise(l)).catch(function(e){if(!h)throw Error("Failed to download MathJax version 2 from '".concat(f,"' due to: ").concat(JSON.stringify(e)));h(e)}):(v2Promise=Promise.reject()).catch(function(e){})):void 0===v3Promise&&("undefined"!=typeof window?(v3Promise=new Promise(l)).catch(function(e){if(!h)throw Error("Failed to download MathJax version 3 from '".concat(f,"' due to: ").concat(e));h(e)}):(v3Promise=Promise.reject()).catch(function(e){})),v.current=__assign(__assign({},u),2===t?{version:2,promise:v2Promise}:{version:3,promise:v3Promise})),React.createElement(MathJaxBaseContext.Provider,{value:v.current},e)};export default MathJaxContext;export{MathJaxBaseContext};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-react-mathjax",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Up-to-date component for using MathJax in latest React (using functional components and hooks API). Focuses on being versatile and making the use of MathJax in React a pleasant experience without flashes of non-typeset content, both with respect to initial rendering as well as dynamic updates. Simple to use but with many configuration options.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "mathjax-full/es5/tex-chtml.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,a,n)}:function(e,t,r,a){e[a=void 0===a?r:a]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},react_1=(Object.defineProperty(exports,"__esModule",{value:!0}),__importStar(require("react"))),MathJaxContext_1=require("../MathJaxContext"),ServerMathJaxContext=(require("mathjax-full/es5/tex-chtml.js"),function(e){var e=e.children,t=(0,react_1.useContext)(MathJaxContext_1.MathJaxBaseContext),t=(0,react_1.useRef)(t);window.MathJax;return react_1.default.createElement(MathJaxContext_1.MathJaxBaseContext.Provider,{value:t.current},e)});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import React,{useContext,useRef}from"react";import{MathJaxBaseContext}from"../MathJaxContext";import"mathjax-full/es5/tex-chtml.js";var ServerMathJaxContext=function(t){var t=t.children,e=useContext(MathJaxBaseContext),e=useRef(e);window.MathJax;return React.createElement(MathJaxBaseContext.Provider,{value:e.current},t)};
|