better-react-mathjax 2.1.0 → 2.3.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.
@@ -1 +1 @@
1
- "use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),__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 n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&__createBinding(t,e,n);return __setModuleDefault(t,e),t},__rest=this&&this.__rest||function(e,t){var n={};for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]]);return n},react_1=(Object.defineProperty(exports,"__esModule",{value:!0}),__importStar(require("react"))),MathJaxContext_1=require("../MathJaxContext"),typesettingFailed=function(e){return"Typesetting failed: ".concat(void 0!==e.message?e.message:JSON.stringify(e))},MathJax=function(e){function r(){var e;"every"===h&&g&&"post"===_&&null!==f.current&&(f.current.style.visibility=null!=(e=null==(e=p.style)?void 0:e.visibility)?e:"visible"),b.current||("first"===h&&null!==f.current&&(f.current.style.visibility="visible"),n&&n(),b.current=!0),o&&o(),m.current=!1}var t=e.inline,i=void 0!==t&&t,t=e.hideUntilTypeset,n=e.onInitTypeset,o=e.onTypeset,s=e.text,u=e.dynamic,a=e.typesettingOptions,l=e.renderMode,c=e.children,p=__rest(e,["inline","hideUntilTypeset","onInitTypeset","onTypeset","text","dynamic","typesettingOptions","renderMode","children"]),d=(0,react_1.useRef)(""),f=(0,react_1.useRef)(null),y=(0,react_1.useContext)(MathJaxContext_1.MathJaxBaseContext),h=null!=t?t:null==y?void 0:y.hideUntilTypeset,_=null!=l?l:null==y?void 0:y.renderMode,v=null!=a?a:null==y?void 0:y.typesettingOptions,g=!1!==u&&(u||"production"!==process.env.NODE_ENV),b=(0,react_1.useRef)(!1),m=(0,react_1.useRef)(!1);return!m.current&&null!==f.current&&g&&"every"===h&&"post"===_&&(f.current.style.visibility="hidden"),("undefined"!=typeof window?react_1.useLayoutEffect:react_1.useEffect)(function(){if((g||!b.current)&&null!==f.current){if(!y)throw Error("MathJax was not loaded, did you use the MathJax component outside of a MathJaxContext?");if("pre"===_){if(!("string"==typeof(e=s)&&0<e.length))throw Error("Render mode 'pre' requires text prop to be set and non-empty, which was currently \"".concat(s,'"'));if(!a||!a.fn)throw Error("Render mode 'pre' requires 'typesettingOptions' prop with 'fn' property to be set on MathJax element or in the MathJaxContext");if(2===y.version)throw Error("Render mode 'pre' only available with MathJax 3, and version 2 is currently in use")}"post"!==_&&s===d.current||m.current||(m.current=!0,3===y.version?y.promise.then(function(t){var n;"pre"===_?(n=function(e){d.current=s,t.startup.document.clear(),t.startup.document.updateDocument(),null!==f.current&&(f.current.innerHTML=e.outerHTML),r()},a.fn.endsWith("Promise")?t.startup.promise.then(function(){return t[v.fn](s,__assign(__assign({},(null==v?void 0:v.options)||{}),{display:!i}))}).then(n).catch(function(e){throw r(),Error(typesettingFailed(e))}):t.startup.promise.then(function(){var e=t[v.fn](s,__assign(__assign({},(null==v?void 0:v.options)||{}),{display:!i}));n(e)}).catch(function(e){throw r(),Error(typesettingFailed(e))})):t.startup.promise.then(function(){return t.typesetClear([f.current]),t.typesetPromise([f.current])}).then(r).catch(function(e){throw r(),Error(typesettingFailed(e))})}).catch(function(e){throw r(),Error(typesettingFailed(e))}):y.promise.then(function(e){e.Hub.Queue(["Typeset",e.Hub,f.current]),e.Hub.Queue(r)}).catch(function(e){throw r(),Error(typesettingFailed(e))}))}var e}),react_1.default.createElement("span",__assign({},p,{style:__assign(__assign({display:i?"inline":"block"},p.style),{visibility:h?"hidden":null==(e=p.style)?void 0:e.visibility}),ref:f}),c)};exports.default=MathJax;
1
+ "use strict";"use client";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),__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||(()=>{var i=function(e){return(i=Object.getOwnPropertyNames||function(e){var t,n=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[n.length]=t);return n})(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=i(e),r=0;r<n.length;r++)"default"!==n[r]&&__createBinding(t,e,n[r]);return __setModuleDefault(t,e),t}})(),__rest=this&&this.__rest||function(e,t){var n={};for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]]);return n},react_1=(Object.defineProperty(exports,"__esModule",{value:!0}),__importStar(require("react"))),MathJaxContext_1=require("../MathJaxContext"),typesettingFailed=function(e){return"Typesetting failed: ".concat(void 0!==e.message?e.message:JSON.stringify(e))},MathJax=function(e){function r(){var e;"every"===h&&g&&"post"===_&&null!==f.current&&(f.current.style.visibility=null!=(e=null==(e=p.style)?void 0:e.visibility)?e:"visible"),b.current||("first"===h&&null!==f.current&&(f.current.style.visibility="visible"),n&&n(),b.current=!0),o&&o(),m.current=!1}var t=e.inline,i=void 0!==t&&t,t=e.hideUntilTypeset,n=e.onInitTypeset,o=e.onTypeset,s=e.text,u=e.dynamic,a=e.typesettingOptions,l=e.renderMode,c=e.children,p=__rest(e,["inline","hideUntilTypeset","onInitTypeset","onTypeset","text","dynamic","typesettingOptions","renderMode","children"]),d=(0,react_1.useRef)(""),f=(0,react_1.useRef)(null),y=(0,react_1.useContext)(MathJaxContext_1.MathJaxBaseContext),h=null!=t?t:null==y?void 0:y.hideUntilTypeset,_=null!=l?l:null==y?void 0:y.renderMode,v=null!=a?a:null==y?void 0:y.typesettingOptions,g=!1!==u&&(u||"production"!==process.env.NODE_ENV),b=(0,react_1.useRef)(!1),m=(0,react_1.useRef)(!1);return!m.current&&null!==f.current&&g&&"every"===h&&"post"===_&&(f.current.style.visibility="hidden"),("undefined"!=typeof window?react_1.useLayoutEffect:react_1.useEffect)(function(){if((g||!b.current)&&null!==f.current){if(!y)throw Error("MathJax was not loaded, did you use the MathJax component outside of a MathJaxContext?");if("pre"===_){if(!("string"==typeof(e=s)&&0<e.length))throw Error("Render mode 'pre' requires text prop to be set and non-empty, which was currently \"".concat(s,'"'));if(!a||!a.fn)throw Error("Render mode 'pre' requires 'typesettingOptions' prop with 'fn' property to be set on MathJax element or in the MathJaxContext");if(2===y.version)throw Error("Render mode 'pre' only available with MathJax 3, and version 2 is currently in use")}"post"!==_&&s===d.current||m.current||(m.current=!0,3===y.version?y.promise.then(function(t){var n;"pre"===_?(n=function(e){d.current=s,t.startup.document.clear(),t.startup.document.updateDocument(),null!==f.current&&(f.current.innerHTML=e.outerHTML),r()},a.fn.endsWith("Promise")?t.startup.promise.then(function(){return t[v.fn](s,__assign(__assign({},(null==v?void 0:v.options)||{}),{display:!i}))}).then(n).catch(function(e){throw r(),Error(typesettingFailed(e))}):t.startup.promise.then(function(){var e=t[v.fn](s,__assign(__assign({},(null==v?void 0:v.options)||{}),{display:!i}));n(e)}).catch(function(e){throw r(),Error(typesettingFailed(e))})):t.startup.promise.then(function(){return t.typesetClear([f.current]),t.typesetPromise([f.current])}).then(r).catch(function(e){throw r(),Error(typesettingFailed(e))})}).catch(function(e){throw r(),Error(typesettingFailed(e))}):y.promise.then(function(e){e.Hub.Queue(["Typeset",e.Hub,f.current]),e.Hub.Queue(r)}).catch(function(e){throw r(),Error(typesettingFailed(e))}))}var e}),react_1.default.createElement("span",__assign({},p,{style:__assign(__assign({display:i?"inline":"block"},p.style),{visibility:h?"hidden":null==(e=p.style)?void 0:e.visibility}),ref:f}),c)};exports.default=MathJax;
@@ -1 +1 @@
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;
1
+ "use strict";"use client";var v2Promise,v3Promise,__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},__createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&("get"in o?t.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),__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||(()=>{var o=function(e){return(o=Object.getOwnPropertyNames||function(e){var t,n=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[n.length]=t);return n})(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=o(e),r=0;r<n.length;r++)"default"!==n[r]&&__createBinding(t,e,n[r]);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 r=e.config,t=e.version,t=void 0===t?3:t,n=e.src,n=void 0===n?2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC:n,o=e.onStartup,i=e.onLoad,a=e.asyncLoad,s=void 0!==a&&a,u=e.onError,a=e.typesettingOptions,c=e.renderMode,c=void 0===c?"post":c,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 f=n||(2===t?DEFAULT_V2_SRC:DEFAULT_V3_SRC);function v(t,n){r&&(window.MathJax=r);var e=document.createElement("script");e.type="text/javascript",e.src=f,e.async=s,e.addEventListener("load",function(){var e=window.MathJax;o&&o(e),t(e),i&&i()}),e.addEventListener("error",function(e){return n(e)}),document.getElementsByTagName("head")[0].appendChild(e)}return void 0===l.current&&(h={typesettingOptions:a,renderMode:c,hideUntilTypeset:d},2===t?void 0===v2Promise&&("undefined"!=typeof window?(v2Promise=new Promise(v)).catch(function(e){if(!u)throw Error("Failed to download MathJax version 2 from '".concat(f,"' due to: ").concat(JSON.stringify(e)));u(e)}):(v2Promise=Promise.reject()).catch(function(e){})):void 0===v3Promise&&("undefined"!=typeof window?(v3Promise=new Promise(v)).catch(function(e){if(!u)throw Error("Failed to download MathJax version 3 from '".concat(f,"' due to: ").concat(e));u(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.3"
37
+ "better-react-mathjax": "^2.3.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
@@ -332,7 +335,7 @@ Requires `typesettingOptions` to be set and version to be `3`. If `renderMode` i
332
335
 
333
336
  Indicates whether the content of the `MathJax` component may change after initial rendering.
334
337
 
335
- **Default**: `false`
338
+ **Default**: `false` (**note**: is `true` by default in development environment for hot reload to work)
336
339
 
337
340
  ***
338
341
 
@@ -1 +1 @@
1
- var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},__rest=this&&this.__rest||function(t,e){var n={};for(i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]]);return n};import React,{useContext,useEffect,useLayoutEffect,useRef}from"react";import{MathJaxBaseContext}from"../MathJaxContext";var typesettingFailed=function(t){return"Typesetting failed: ".concat(void 0!==t.message?t.message:JSON.stringify(t))},MathJax=function(t){function r(){var t;"every"===h&&m&&"post"===v&&null!==f.current&&(f.current.style.visibility=null!=(t=null==(t=p.style)?void 0:t.visibility)?t:"visible"),_.current||("first"===h&&null!==f.current&&(f.current.style.visibility="visible"),n&&n(),_.current=!0),o&&o(),b.current=!1}var e=t.inline,i=void 0!==e&&e,e=t.hideUntilTypeset,n=t.onInitTypeset,o=t.onTypeset,s=t.text,u=t.dynamic,a=t.typesettingOptions,l=t.renderMode,c=t.children,p=__rest(t,["inline","hideUntilTypeset","onInitTypeset","onTypeset","text","dynamic","typesettingOptions","renderMode","children"]),y=useRef(""),f=useRef(null),d=useContext(MathJaxBaseContext),h=null!=e?e:null==d?void 0:d.hideUntilTypeset,v=null!=l?l:null==d?void 0:d.renderMode,g=null!=a?a:null==d?void 0:d.typesettingOptions,m=!1!==u&&(u||"production"!==process.env.NODE_ENV),_=useRef(!1),b=useRef(!1);return!b.current&&null!==f.current&&m&&"every"===h&&"post"===v&&(f.current.style.visibility="hidden"),("undefined"!=typeof window?useLayoutEffect:useEffect)(function(){if((m||!_.current)&&null!==f.current){if(!d)throw Error("MathJax was not loaded, did you use the MathJax component outside of a MathJaxContext?");if("pre"===v){if(!("string"==typeof(t=s)&&0<t.length))throw Error("Render mode 'pre' requires text prop to be set and non-empty, which was currently \"".concat(s,'"'));if(!a||!a.fn)throw Error("Render mode 'pre' requires 'typesettingOptions' prop with 'fn' property to be set on MathJax element or in the MathJaxContext");if(2===d.version)throw Error("Render mode 'pre' only available with MathJax 3, and version 2 is currently in use")}"post"!==v&&s===y.current||b.current||(b.current=!0,3===d.version?d.promise.then(function(e){var n;"pre"===v?(n=function(t){y.current=s,e.startup.document.clear(),e.startup.document.updateDocument(),null!==f.current&&(f.current.innerHTML=t.outerHTML),r()},a.fn.endsWith("Promise")?e.startup.promise.then(function(){return e[g.fn](s,__assign(__assign({},(null==g?void 0:g.options)||{}),{display:!i}))}).then(n).catch(function(t){throw r(),Error(typesettingFailed(t))}):e.startup.promise.then(function(){var t=e[g.fn](s,__assign(__assign({},(null==g?void 0:g.options)||{}),{display:!i}));n(t)}).catch(function(t){throw r(),Error(typesettingFailed(t))})):e.startup.promise.then(function(){return e.typesetClear([f.current]),e.typesetPromise([f.current])}).then(r).catch(function(t){throw r(),Error(typesettingFailed(t))})}).catch(function(t){throw r(),Error(typesettingFailed(t))}):d.promise.then(function(t){t.Hub.Queue(["Typeset",t.Hub,f.current]),t.Hub.Queue(r)}).catch(function(t){throw r(),Error(typesettingFailed(t))}))}var t}),React.createElement("span",__assign({},p,{style:__assign(__assign({display:i?"inline":"block"},p.style),{visibility:h?"hidden":null==(t=p.style)?void 0:t.visibility}),ref:f}),c)};export default MathJax;
1
+ "use client";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},__rest=this&&this.__rest||function(e,t){var n={};for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]]);return n};import React,{useContext,useEffect,useLayoutEffect,useRef}from"react";import{MathJaxBaseContext}from"../MathJaxContext";var typesettingFailed=function(e){return"Typesetting failed: ".concat(void 0!==e.message?e.message:JSON.stringify(e))},MathJax=function(e){function r(){var e;"every"===h&&m&&"post"===v&&null!==f.current&&(f.current.style.visibility=null!=(e=null==(e=p.style)?void 0:e.visibility)?e:"visible"),_.current||("first"===h&&null!==f.current&&(f.current.style.visibility="visible"),n&&n(),_.current=!0),o&&o(),b.current=!1}var t=e.inline,i=void 0!==t&&t,t=e.hideUntilTypeset,n=e.onInitTypeset,o=e.onTypeset,s=e.text,u=e.dynamic,a=e.typesettingOptions,l=e.renderMode,c=e.children,p=__rest(e,["inline","hideUntilTypeset","onInitTypeset","onTypeset","text","dynamic","typesettingOptions","renderMode","children"]),y=useRef(""),f=useRef(null),d=useContext(MathJaxBaseContext),h=null!=t?t:null==d?void 0:d.hideUntilTypeset,v=null!=l?l:null==d?void 0:d.renderMode,g=null!=a?a:null==d?void 0:d.typesettingOptions,m=!1!==u&&(u||"production"!==process.env.NODE_ENV),_=useRef(!1),b=useRef(!1);return!b.current&&null!==f.current&&m&&"every"===h&&"post"===v&&(f.current.style.visibility="hidden"),("undefined"!=typeof window?useLayoutEffect:useEffect)(function(){if((m||!_.current)&&null!==f.current){if(!d)throw Error("MathJax was not loaded, did you use the MathJax component outside of a MathJaxContext?");if("pre"===v){if(!("string"==typeof(e=s)&&0<e.length))throw Error("Render mode 'pre' requires text prop to be set and non-empty, which was currently \"".concat(s,'"'));if(!a||!a.fn)throw Error("Render mode 'pre' requires 'typesettingOptions' prop with 'fn' property to be set on MathJax element or in the MathJaxContext");if(2===d.version)throw Error("Render mode 'pre' only available with MathJax 3, and version 2 is currently in use")}"post"!==v&&s===y.current||b.current||(b.current=!0,3===d.version?d.promise.then(function(t){var n;"pre"===v?(n=function(e){y.current=s,t.startup.document.clear(),t.startup.document.updateDocument(),null!==f.current&&(f.current.innerHTML=e.outerHTML),r()},a.fn.endsWith("Promise")?t.startup.promise.then(function(){return t[g.fn](s,__assign(__assign({},(null==g?void 0:g.options)||{}),{display:!i}))}).then(n).catch(function(e){throw r(),Error(typesettingFailed(e))}):t.startup.promise.then(function(){var e=t[g.fn](s,__assign(__assign({},(null==g?void 0:g.options)||{}),{display:!i}));n(e)}).catch(function(e){throw r(),Error(typesettingFailed(e))})):t.startup.promise.then(function(){return t.typesetClear([f.current]),t.typesetPromise([f.current])}).then(r).catch(function(e){throw r(),Error(typesettingFailed(e))})}).catch(function(e){throw r(),Error(typesettingFailed(e))}):d.promise.then(function(e){e.Hub.Queue(["Typeset",e.Hub,f.current]),e.Hub.Queue(r)}).catch(function(e){throw r(),Error(typesettingFailed(e))}))}var e}),React.createElement("span",__assign({},p,{style:__assign(__assign({display:i?"inline":"block"},p.style),{visibility:h?"hidden":null==(e=p.style)?void 0:e.visibility}),ref:f}),c)};export default MathJax;
@@ -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.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};
1
+ "use client";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.1.0",
3
+ "version": "2.3.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",