better-react-mathjax 2.0.0 → 2.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC } from "react";
|
|
1
|
+
import React, { FC, ReactNode } from "react";
|
|
2
2
|
import type { MathJax2Config, MathJax2Object } from "../MathJax2";
|
|
3
3
|
import type { MathJax3Config, MathJax3Object, OptionList } from "../MathJax3";
|
|
4
4
|
export declare type TypesettingFunction = "tex2chtml" | "tex2chtmlPromise" | "tex2svg" | "tex2svgPromise" | "tex2mml" | "tex2mmlPromise" | "mathml2chtml" | "mathml2chtmlPromise" | "mathml2svg" | "mathml2svgPromise" | "mathml2mml" | "mathml2mmlPromise" | "asciimath2chtml" | "asciimath2chtmlPromise" | "asciimath2svg" | "asciimath2svgPromise" | "asciimath2mml" | "asciimath2mmlPromise";
|
|
@@ -6,7 +6,7 @@ export interface MathJaxOverrideableProps {
|
|
|
6
6
|
hideUntilTypeset?: "first" | "every";
|
|
7
7
|
typesettingOptions?: {
|
|
8
8
|
fn: TypesettingFunction;
|
|
9
|
-
options?: OptionList
|
|
9
|
+
options?: Omit<OptionList, "display">;
|
|
10
10
|
};
|
|
11
11
|
renderMode?: "pre" | "post";
|
|
12
12
|
}
|
|
@@ -22,6 +22,7 @@ interface MathJaxContextStaticProps extends MathJaxOverrideableProps {
|
|
|
22
22
|
src?: string;
|
|
23
23
|
onLoad?: () => void;
|
|
24
24
|
onError?: (error: any) => void;
|
|
25
|
+
children?: ReactNode;
|
|
25
26
|
}
|
|
26
27
|
export declare type MathJaxContextProps = ({
|
|
27
28
|
config?: MathJax2Config;
|
|
@@ -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.0/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,a=e.onLoad,i=e.onError,s=e.typesettingOptions,c=e.renderMode,c=void 0===c?"post":c,u=e.hideUntilTypeset,e=e.children,d=(0,react_1.useContext)(exports.MathJaxBaseContext);if(void 0!==(null==d?void 0:d.version)&&(null==d?void 0:d.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 h=(0,react_1.useRef)(d),d=(0,react_1.useRef)((null==d?void 0:d.version)||null);if(null===d.current)d.current=t;else if(d.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 l=o||(2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC);function v(t,o){n&&(window.MathJax=n);var e=document.createElement("script");e.type="text/javascript",e.src=l,e.async=!1,e.addEventListener("load",function(){var e=window.MathJax;r&&r(e),t(e),a&&a()}),e.addEventListener("error",function(e){return o(e)}),document.getElementsByTagName("head")[0].appendChild(e)}return void 0===h.current&&(d={typesettingOptions:s,renderMode:c,hideUntilTypeset:u},2===t?void 0===v2Promise&&("undefined"!=typeof window?(v2Promise=new Promise(v)).catch(function(e){if(!i)throw Error("Failed to download MathJax version 2 from '".concat(l,"' due to: ").concat(e));i(e)}):(v2Promise=Promise.reject()).catch(function(e){})):void 0===v3Promise&&("undefined"!=typeof window?(v3Promise=new Promise(v)).catch(function(e){if(!i)throw Error("Failed to download MathJax version 3 from '".concat(l,"' due to: ").concat(e));i(e)}):(v3Promise=Promise.reject()).catch(function(e){})),h.current=__assign(__assign({},d),2===t?{version:2,promise:v2Promise}:{version:3,promise:v3Promise})),react_1.default.createElement(exports.MathJaxBaseContext.Provider,{value:h.current},e)};exports.default=MathJaxContext;
|
package/README.md
CHANGED
|
@@ -258,15 +258,7 @@ Local or remote url to fetch MathJax from. More information about hosting your o
|
|
|
258
258
|
|
|
259
259
|
A source url may contain both some specific file and some query parameters corresponding to a configuration which, in turn, governs
|
|
260
260
|
which additional assets MathJax fetches. The default sources used when this property is omitted are the same as those
|
|
261
|
-
listed in the [MathJax instruction](https://www.mathjax.org/#gettingstarted) (however from a different CDN).
|
|
262
|
-
that for version 2, the fetched resource (`MathJax.js?config=TeX-MML-AM_CHTML`) includes support for Latex, MML
|
|
263
|
-
and AsciiMath with HTML output by default, and for version 3, the fetched resource (`tex-mml-chtml.js`) supports
|
|
264
|
-
MML and Latex with HTML output. These correspond to some typical and broad use of MathJax in the browser. If you have a
|
|
265
|
-
use case where you, using standalone MathJax, would have to use a different source url, then you have to manually supply
|
|
266
|
-
such a url (local or remote) here. This, in analogy to how you would modify the script import to adjust to your needs in
|
|
267
|
-
a plain HTML environment with direct use of MathJax. Read more about different configurations
|
|
268
|
-
[here](https://docs.mathjax.org/en/latest/web/components/combined.html) (for MathJax 3) and
|
|
269
|
-
[here](https://docs.mathjax.org/en/v2.7-latest/config-files.html#common-configurations) (for MathJax 2).
|
|
261
|
+
listed in the [MathJax instruction](https://www.mathjax.org/#gettingstarted) (however from a different CDN).
|
|
270
262
|
|
|
271
263
|
### `version: 2 | 3 | undefined` ###
|
|
272
264
|
|
|
@@ -339,8 +331,8 @@ Indicates whether the content of the `MathJax` component may change after initia
|
|
|
339
331
|
***
|
|
340
332
|
|
|
341
333
|
***Any additional props will be spread to the root element of the `MathJax` component which is a `span` with `display`
|
|
342
|
-
set to `inline` when the `inline` property is set to `true`, otherwise `block`. The `display` can be
|
|
343
|
-
`style`
|
|
334
|
+
set to `inline` when the `inline` property is set to `true`, otherwise `block`. The `display` can be overridden via
|
|
335
|
+
`style` prop if needed (then the `inline` property does not affect the wrapper). A ref is not possible to set
|
|
344
336
|
as this functionality is used by the `MathJax` component itself.***
|
|
345
337
|
|
|
346
338
|
## Custom use of MathJax directly ##
|
|
@@ -366,53 +358,6 @@ Sandbox example: https://codesandbox.io/s/better-react-mathjax-custom-example-la
|
|
|
366
358
|
|
|
367
359
|
Read full documentation, file problems or contribute on Github: https://github.com/fast-reflexes/better-react-mathjax
|
|
368
360
|
|
|
369
|
-
## Changelog ##
|
|
370
|
-
* v. 1.0.0
|
|
371
|
-
* Initial Release
|
|
372
|
-
* v. 1.0.1
|
|
373
|
-
* Removed types imported from `@types/mathjax` and `mathjax-full` due to several reasons. Custom type declarations will be supplied instead.
|
|
374
|
-
* v. 1.0.2
|
|
375
|
-
* Readded types with custom types for MathJax2 based on `@types/mathjax` and types from `mathjax-full` for MathJax3.
|
|
376
|
-
* v. 1.0.3
|
|
377
|
-
* Fixed missing license.
|
|
378
|
-
* Corrected function signature on `MathJax` component.
|
|
379
|
-
* Updated default MathJax 3 version provided by CDN to using v. 3.2.0.
|
|
380
|
-
* Updated MathJax 3 types used to v. 3.2.0.
|
|
381
|
-
* Added content to API documentation on property `src`.
|
|
382
|
-
* Added installation instructions.
|
|
383
|
-
* Added information about AsciiMath display mode.
|
|
384
|
-
* Corrected typo in API documentation on `version` property.
|
|
385
|
-
* v. 2.0.0
|
|
386
|
-
* **Breaking change**: can no longer use MathJax versions 2 and 3 side by side in different
|
|
387
|
-
`MathJaxContext`s. This did typically not work as intended before either and even though this change is
|
|
388
|
-
breaking, it should not affect many users, if any. Docs have been updated and `MathJaxContext` now throws an error
|
|
389
|
-
if it has been initialized with one version and another `MathJaxContext` (later or simultaneous) has a different
|
|
390
|
-
value on the `version` prop.
|
|
391
|
-
* Added support for hot reload by always setting `dynamic` to `true` when `dynamic` is not explicitly set to `false`
|
|
392
|
-
and `process.env.NODE_ENV` is not `production`.
|
|
393
|
-
* Honoring possible style settings of `style.visibility` in `MathJax` component when visibility is not controlled
|
|
394
|
-
by the component itself.
|
|
395
|
-
* Corrected sandbox example with AsciiMath where Latex default delimiter was used instead of AsciiMath delimiter
|
|
396
|
-
(still worked because Latex is loaded by default as well).
|
|
397
|
-
* Improved documentation with clarifications:
|
|
398
|
-
* The entire app should be wrapped in the only `MathJaxContext` that should exist in a project.
|
|
399
|
-
* How to deal with the situation when you have a lot of math on your page.
|
|
400
|
-
* The features available with the default imports from CDN.
|
|
401
|
-
* Difference between inline and display math.
|
|
402
|
-
* Added Q & A section to documentation.
|
|
403
|
-
* Changed all checks for undefined to use `typeof X === "undefined"` instead of `X === undefined`.
|
|
404
|
-
* Added support for esm modules as well as the previous cjs modules.
|
|
405
|
-
* Added language tags on code samples
|
|
406
|
-
|
|
407
|
-
## Migration guides
|
|
408
|
-
|
|
409
|
-
* v1 to v2:
|
|
410
|
-
* Remove all simultaneous use of MathJax version 2 and 3 in the same app and use only one version of MathJax
|
|
411
|
-
per loaded page. This means that even if you unmount the `MathJaxContext` and then remount it, it must have the
|
|
412
|
-
same version both times. If you load a new page context (e.g. not just change page in a SPA (single-page application))
|
|
413
|
-
the version can be determined anew. If you need to use both versions side by side, file an issue on the project
|
|
414
|
-
Github page.
|
|
415
|
-
|
|
416
361
|
## License
|
|
417
362
|
|
|
418
363
|
This project is licensed under the terms of the
|
|
@@ -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.0/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.onError,s=e.typesettingOptions,h=e.renderMode,h=void 0===h?"post":h,d=e.hideUntilTypeset,e=e.children,c=useContext(MathJaxBaseContext);if(void 0!==(null==c?void 0:c.version)&&(null==c?void 0:c.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 u=useRef(c),c=useRef((null==c?void 0:c.version)||null);if(null===c.current)c.current=t;else if(c.current!==t)throw Error("Cannot change version of MathJax in a MathJaxContext after
|
|
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.0/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.onError,s=e.typesettingOptions,h=e.renderMode,h=void 0===h?"post":h,d=e.hideUntilTypeset,e=e.children,c=useContext(MathJaxBaseContext);if(void 0!==(null==c?void 0:c.version)&&(null==c?void 0:c.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 u=useRef(c),c=useRef((null==c?void 0:c.version)||null);if(null===c.current)c.current=t;else if(c.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=!1,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===u.current&&(c={typesettingOptions:s,renderMode:h,hideUntilTypeset:d},2===t?void 0===v2Promise&&("undefined"!=typeof window?(v2Promise=new Promise(f)).catch(function(e){if(!i)throw Error("Failed to download MathJax version 2 from '".concat(v,"' due to: ").concat(e));i(e)}):(v2Promise=Promise.reject()).catch(function(e){})):void 0===v3Promise&&("undefined"!=typeof window?(v3Promise=new Promise(f)).catch(function(e){if(!i)throw Error("Failed to download MathJax version 3 from '".concat(v,"' due to: ").concat(e));i(e)}):(v3Promise=Promise.reject()).catch(function(e){})),u.current=__assign(__assign({},c),2===t?{version:2,promise:v2Promise}:{version:3,promise:v3Promise})),React.createElement(MathJaxBaseContext.Provider,{value:u.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.0.1",
|
|
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",
|