UNPKG

react-scitext

Version:

React component for rendering scientific text with Markdown, LaTeX, and SMILES support

32 lines (29 loc) 32.2 kB
(function(x,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("react"),require("react-markdown"),require("remark-gfm"),require("smiles-drawer"),require("react-katex")):typeof define=="function"&&define.amd?define(["exports","react","react-markdown","remark-gfm","smiles-drawer","react-katex"],M):(x=typeof globalThis<"u"?globalThis:x||self,M(x.ReactSciText={},x.React,x.ReactMarkdown,x.remarkGfm,x.SmilesDrawer,x.ReactKatex))})(this,function(x,M,$e,_e,ot,L){"use strict";function ct(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const c=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,c.get?c:{enumerable:!0,get:()=>t[n]})}}return r.default=t,Object.freeze(r)}const Ce=ct(ot);var ce={exports:{}},G={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var we;function ut(){if(we)return G;we=1;var t=M,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),c=Object.prototype.hasOwnProperty,d=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function m(o,h,s){var l,f={},j=null,R=null;s!==void 0&&(j=""+s),h.key!==void 0&&(j=""+h.key),h.ref!==void 0&&(R=h.ref);for(l in h)c.call(h,l)&&!p.hasOwnProperty(l)&&(f[l]=h[l]);if(o&&o.defaultProps)for(l in h=o.defaultProps,h)f[l]===void 0&&(f[l]=h[l]);return{$$typeof:r,type:o,key:j,ref:R,props:f,_owner:d.current}}return G.Fragment=n,G.jsx=m,G.jsxs=m,G}var K={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Re;function dt(){return Re||(Re=1,process.env.NODE_ENV!=="production"&&function(){var t=M,r=Symbol.for("react.element"),n=Symbol.for("react.portal"),c=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),p=Symbol.for("react.profiler"),m=Symbol.for("react.provider"),o=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),s=Symbol.for("react.suspense"),l=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),R=Symbol.for("react.offscreen"),I=Symbol.iterator,W="@@iterator";function A(e){if(e===null||typeof e!="object")return null;var i=I&&e[I]||e[W];return typeof i=="function"?i:null}var N=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function C(e){{for(var i=arguments.length,u=new Array(i>1?i-1:0),v=1;v<i;v++)u[v-1]=arguments[v];O("error",e,u)}}function O(e,i,u){{var v=N.ReactDebugCurrentFrame,y=v.getStackAddendum();y!==""&&(i+="%s",u=u.concat([y]));var E=u.map(function(b){return String(b)});E.unshift("Warning: "+i),Function.prototype.apply.call(console[e],console,E)}}var he=!1,pe=!1,Q=!1,w=!1,H=!1,S;S=Symbol.for("react.module.reference");function D(e){return!!(typeof e=="string"||typeof e=="function"||e===c||e===p||H||e===d||e===s||e===l||w||e===R||he||pe||Q||typeof e=="object"&&e!==null&&(e.$$typeof===j||e.$$typeof===f||e.$$typeof===m||e.$$typeof===o||e.$$typeof===h||e.$$typeof===S||e.getModuleId!==void 0))}function ee(e,i,u){var v=e.displayName;if(v)return v;var y=i.displayName||i.name||"";return y!==""?u+"("+y+")":u}function z(e){return e.displayName||"Context"}function Z(e){if(e==null)return null;if(typeof e.tag=="number"&&C("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case c:return"Fragment";case n:return"Portal";case p:return"Profiler";case d:return"StrictMode";case s:return"Suspense";case l:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case o:var i=e;return z(i)+".Consumer";case m:var u=e;return z(u._context)+".Provider";case h:return ee(e,e.render,"ForwardRef");case f:var v=e.displayName||null;return v!==null?v:Z(e.type)||"Memo";case j:{var y=e,E=y._payload,b=y._init;try{return Z(b(E))}catch{return null}}}return null}var U=Object.assign,te=0,De,Ve,Fe,ze,Ze,Ye,Be;function He(){}He.__reactDisabledLog=!0;function $t(){{if(te===0){De=console.log,Ve=console.info,Fe=console.warn,ze=console.error,Ze=console.group,Ye=console.groupCollapsed,Be=console.groupEnd;var e={configurable:!0,enumerable:!0,value:He,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}te++}}function _t(){{if(te--,te===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:U({},e,{value:De}),info:U({},e,{value:Ve}),warn:U({},e,{value:Fe}),error:U({},e,{value:ze}),group:U({},e,{value:Ze}),groupCollapsed:U({},e,{value:Ye}),groupEnd:U({},e,{value:Be})})}te<0&&C("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var me=N.ReactCurrentDispatcher,ve;function ie(e,i,u){{if(ve===void 0)try{throw Error()}catch(y){var v=y.stack.trim().match(/\n( *(at )?)/);ve=v&&v[1]||""}return` `+ve+e}}var ge=!1,ae;{var Ct=typeof WeakMap=="function"?WeakMap:Map;ae=new Ct}function Ue(e,i){if(!e||ge)return"";{var u=ae.get(e);if(u!==void 0)return u}var v;ge=!0;var y=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var E;E=me.current,me.current=null,$t();try{if(i){var b=function(){throw Error()};if(Object.defineProperty(b.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(b,[])}catch(T){v=T}Reflect.construct(e,[],b)}else{try{b.call()}catch(T){v=T}e.call(b.prototype)}}else{try{throw Error()}catch(T){v=T}e()}}catch(T){if(T&&v&&typeof T.stack=="string"){for(var g=T.stack.split(` `),k=v.stack.split(` `),$=g.length-1,_=k.length-1;$>=1&&_>=0&&g[$]!==k[_];)_--;for(;$>=1&&_>=0;$--,_--)if(g[$]!==k[_]){if($!==1||_!==1)do if($--,_--,_<0||g[$]!==k[_]){var P=` `+g[$].replace(" at new "," at ");return e.displayName&&P.includes("<anonymous>")&&(P=P.replace("<anonymous>",e.displayName)),typeof e=="function"&&ae.set(e,P),P}while($>=1&&_>=0);break}}}finally{ge=!1,me.current=E,_t(),Error.prepareStackTrace=y}var J=e?e.displayName||e.name:"",X=J?ie(J):"";return typeof e=="function"&&ae.set(e,X),X}function wt(e,i,u){return Ue(e,!1)}function Rt(e){var i=e.prototype;return!!(i&&i.isReactComponent)}function le(e,i,u){if(e==null)return"";if(typeof e=="function")return Ue(e,Rt(e));if(typeof e=="string")return ie(e);switch(e){case s:return ie("Suspense");case l:return ie("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return wt(e.render);case f:return le(e.type,i,u);case j:{var v=e,y=v._payload,E=v._init;try{return le(E(y),i,u)}catch{}}}return""}var re=Object.prototype.hasOwnProperty,Xe={},qe=N.ReactDebugCurrentFrame;function oe(e){if(e){var i=e._owner,u=le(e.type,e._source,i?i.type:null);qe.setExtraStackFrame(u)}else qe.setExtraStackFrame(null)}function St(e,i,u,v,y){{var E=Function.call.bind(re);for(var b in e)if(E(e,b)){var g=void 0;try{if(typeof e[b]!="function"){var k=Error((v||"React class")+": "+u+" type `"+b+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[b]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw k.name="Invariant Violation",k}g=e[b](i,b,v,u,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch($){g=$}g&&!(g instanceof Error)&&(oe(y),C("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",v||"React class",u,b,typeof g),oe(null)),g instanceof Error&&!(g.message in Xe)&&(Xe[g.message]=!0,oe(y),C("Failed %s type: %s",u,g.message),oe(null))}}}var kt=Array.isArray;function be(e){return kt(e)}function Tt(e){{var i=typeof Symbol=="function"&&Symbol.toStringTag,u=i&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u}}function Pt(e){try{return Je(e),!1}catch{return!0}}function Je(e){return""+e}function Ge(e){if(Pt(e))return C("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Tt(e)),Je(e)}var Ke=N.ReactCurrentOwner,Mt={key:!0,ref:!0,__self:!0,__source:!0},Qe,et;function Ot(e){if(re.call(e,"ref")){var i=Object.getOwnPropertyDescriptor(e,"ref").get;if(i&&i.isReactWarning)return!1}return e.ref!==void 0}function At(e){if(re.call(e,"key")){var i=Object.getOwnPropertyDescriptor(e,"key").get;if(i&&i.isReactWarning)return!1}return e.key!==void 0}function Nt(e,i){typeof e.ref=="string"&&Ke.current}function Lt(e,i){{var u=function(){Qe||(Qe=!0,C("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}}function It(e,i){{var u=function(){et||(et=!0,C("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};u.isReactWarning=!0,Object.defineProperty(e,"ref",{get:u,configurable:!0})}}var Wt=function(e,i,u,v,y,E,b){var g={$$typeof:r,type:e,key:i,ref:u,props:b,_owner:E};return g._store={},Object.defineProperty(g._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(g,"_self",{configurable:!1,enumerable:!1,writable:!1,value:v}),Object.defineProperty(g,"_source",{configurable:!1,enumerable:!1,writable:!1,value:y}),Object.freeze&&(Object.freeze(g.props),Object.freeze(g)),g};function Dt(e,i,u,v,y){{var E,b={},g=null,k=null;u!==void 0&&(Ge(u),g=""+u),At(i)&&(Ge(i.key),g=""+i.key),Ot(i)&&(k=i.ref,Nt(i,y));for(E in i)re.call(i,E)&&!Mt.hasOwnProperty(E)&&(b[E]=i[E]);if(e&&e.defaultProps){var $=e.defaultProps;for(E in $)b[E]===void 0&&(b[E]=$[E])}if(g||k){var _=typeof e=="function"?e.displayName||e.name||"Unknown":e;g&&Lt(b,_),k&&It(b,_)}return Wt(e,g,k,y,v,Ke.current,b)}}var xe=N.ReactCurrentOwner,tt=N.ReactDebugCurrentFrame;function q(e){if(e){var i=e._owner,u=le(e.type,e._source,i?i.type:null);tt.setExtraStackFrame(u)}else tt.setExtraStackFrame(null)}var ye;ye=!1;function Ee(e){return typeof e=="object"&&e!==null&&e.$$typeof===r}function rt(){{if(xe.current){var e=Z(xe.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function Vt(e){return""}var nt={};function Ft(e){{var i=rt();if(!i){var u=typeof e=="string"?e:e.displayName||e.name;u&&(i=` Check the top-level render call using <`+u+">.")}return i}}function st(e,i){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var u=Ft(i);if(nt[u])return;nt[u]=!0;var v="";e&&e._owner&&e._owner!==xe.current&&(v=" It was passed a child from "+Z(e._owner.type)+"."),q(e),C('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',u,v),q(null)}}function it(e,i){{if(typeof e!="object")return;if(be(e))for(var u=0;u<e.length;u++){var v=e[u];Ee(v)&&st(v,i)}else if(Ee(e))e._store&&(e._store.validated=!0);else if(e){var y=A(e);if(typeof y=="function"&&y!==e.entries)for(var E=y.call(e),b;!(b=E.next()).done;)Ee(b.value)&&st(b.value,i)}}}function zt(e){{var i=e.type;if(i==null||typeof i=="string")return;var u;if(typeof i=="function")u=i.propTypes;else if(typeof i=="object"&&(i.$$typeof===h||i.$$typeof===f))u=i.propTypes;else return;if(u){var v=Z(i);St(u,e.props,"prop",v,e)}else if(i.PropTypes!==void 0&&!ye){ye=!0;var y=Z(i);C("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",y||"Unknown")}typeof i.getDefaultProps=="function"&&!i.getDefaultProps.isReactClassApproved&&C("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Zt(e){{for(var i=Object.keys(e.props),u=0;u<i.length;u++){var v=i[u];if(v!=="children"&&v!=="key"){q(e),C("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",v),q(null);break}}e.ref!==null&&(q(e),C("Invalid attribute `ref` supplied to `React.Fragment`."),q(null))}}var at={};function lt(e,i,u,v,y,E){{var b=D(e);if(!b){var g="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(g+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var k=Vt();k?g+=k:g+=rt();var $;e===null?$="null":be(e)?$="array":e!==void 0&&e.$$typeof===r?($="<"+(Z(e.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):$=typeof e,C("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",$,g)}var _=Dt(e,i,u,y,E);if(_==null)return _;if(b){var P=i.children;if(P!==void 0)if(v)if(be(P)){for(var J=0;J<P.length;J++)it(P[J],e);Object.freeze&&Object.freeze(P)}else C("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else it(P,e)}if(re.call(i,"key")){var X=Z(e),T=Object.keys(i).filter(function(qt){return qt!=="key"}),je=T.length>0?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}";if(!at[X+je]){var Xt=T.length>0?"{"+T.join(": ..., ")+": ...}":"{}";C(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,je,X,Xt,X),at[X+je]=!0}}return e===c?Zt(_):zt(_),_}}function Yt(e,i,u){return lt(e,i,u,!0)}function Bt(e,i,u){return lt(e,i,u,!1)}var Ht=Bt,Ut=Yt;K.Fragment=c,K.jsx=Ht,K.jsxs=Ut}()),K}process.env.NODE_ENV==="production"?ce.exports=ut():ce.exports=dt();var a=ce.exports;function ne(t){const r=[],n=/\\(begin|end)\{([^}]+)\}/g;let c;const d=[];for(;(c=n.exec(t))!==null;)d.push({type:c[1],env:c[2],index:c.index,length:c[0].length});const p=[];for(const m of d)if(m.type==="begin")p.push(m);else if(m.type==="end"&&p.length>0&&p[p.length-1].env===m.env){const o=p.pop();if(p.length===0){const h=o.index,s=m.index+m.length;r.push({start:h,end:s,content:t.substring(h,s)})}}return r.sort((m,o)=>m.start-o.start)}function Se(t){return t.split(/(\\\(.+?\\\)|\$\$.*?\$\$|\$.*?\$|\\\[.*?\\\])/gs)}function ue(t){return t.match(/^\\\((.+?)\\\)$/s)}function V(t){const r=t.match(/^\\\(\s*([a-zA-Z_0-9]{1,3})\s*\\\)$/s);if(!r)return null;const n=r[1];return n.includes("\\")||n.includes("{")||n.includes("}")||n.includes("^")||n.includes("_")||n.includes("frac")?null:{match:r,content:n}}function F(t){const r=t.match(/^\$([a-zA-Z][a-zA-Z0-9_]{0,2})\$$/s);if(!r)return null;const n=r[1];return n.includes("\\")||n.includes("{")||n.includes("}")||n.includes("^")||n.includes("_")||n.includes("frac")||n.includes("+")||n.includes("-")||n.includes("*")||n.includes("/")||n.includes("=")||n.includes("(")||n.includes(")")||n.length>3?null:{match:r,content:n}}function de(t){return t.match(/^\\\[(.+?)\\\]$/s)||t.match(/^\$\$(.*?)\$\$$/s)}function Y(t){const r=t.match(/^\$(.+?)\$$/s);if(!r)return null;const n=r[1];return[/[+\-*/=<>≤≥≠±∞∑∏∫∪∩∈∉⊆⊇∅∀∃∴∝]/,/\\(frac|sqrt|int|sum|prod|lim|sin|cos|tan|log|ln|exp|times|cup|cap|subset|supset|in|notin|forall|exists|therefore|propto)/,/\([^)]*[+\-*/=,][^)]*\)/,/\{[^}]*[,=][^}]*\}/,/\{[^}]*\([^)]*,[^)]*\)[^}]*\}/,/[_^]/,/[A-Z][a-z]?_?\d+/,/\\[a-zA-Z]+/,/\d+\s*[a-zA-Z]/,/[a-zA-Z]\s*[=]\s*[^,}]/].some(d=>d.test(n))?r:null}function ke(t){return t.match(/^\\begin\{([^}]+)\}(.*?)\\end\{\1\}$/s)}function Te(t){return![/\\input\{/,/\\include\{/,/\\write/,/\\read/,/\\openin/,/\\openout/,/\\immediate/,/\\special/,/\\pdfliteral/].some(n=>n.test(t))}function ft(t){return t.replace(/\\input\{[^}]*\}/g,"").replace(/\\include\{[^}]*\}/g,"").replace(/\\write[^{]*\{[^}]*\}/g,"").replace(/\\read[^{]*\{[^}]*\}/g,"")}function B(t){return t.split(/(\$[a-zA-Z][a-zA-Z0-9_]{0,2}\$|\\\([a-zA-Z][a-zA-Z0-9]{0,2}\\\))/g).map((n,c)=>{const d=F(n);if(d)return a.jsx("span",{className:"font-bold",role:"text","aria-label":`Variable ${d.content}`,children:d.content},c);const p=V(n);return p?a.jsx("span",{className:"font-bold italic",role:"math","aria-label":`Mathematical variable ${p.content}`,children:p.content},c):a.jsx("span",{children:n},c)}).filter(n=>!(n.props.children===""))}function Pe(t,r){const n=`h${r}`,c={1:"text-3xl font-bold mb-4 mt-6",2:"text-2xl font-semibold mb-3 mt-5",3:"text-xl font-medium mb-2 mt-4",4:"text-lg font-medium mb-2 mt-3",5:"text-base font-medium mb-1 mt-2",6:"text-sm font-medium mb-1 mt-2"},d=t.toLowerCase().replace(/[^a-z0-9\s]/g,"").replace(/\s+/g,"-").substring(0,50),p=Me(t);return a.jsx(n,{id:d,className:c[r],tabIndex:-1,children:p})}function Me(t){const r=[],n=/(\\\[.*?\\\]|\$\$.*?\$\$|\\\(.*?\\\)|\$[^$\s][^$]*[^$\s]\$|\$[^$\s]+\$)/gs,c=[];let d;for(;(d=n.exec(t))!==null;)d[0].startsWith("$")&&!d[0].startsWith("$$")&&F(d[0])||d[0].startsWith("\\(")&&d[0].endsWith("\\)")&&V(d[0])||d[0].startsWith("$")&&!d[0].startsWith("$$")&&!Y(d[0])||c.push({start:d.index,end:d.index+d[0].length,content:d[0]});let p=0;if(c.forEach((m,o)=>{if(m.start>p){const h=t.slice(p,m.start);if(h){const s=B(h);r.push(...s)}}r.push(a.jsx("span",{className:"math-content",children:m.content},`math-${o}`)),p=m.end}),p<t.length){const m=t.slice(p);if(m){const o=B(m);r.push(...o)}}return c.length===0?B(t):r.filter(m=>{if(M.isValidElement(m)){const o=m.props;if(typeof o.children=="string")return o.children.trim()!==""}return!0})}function Oe(t){return!t||typeof t!="string"||t.length>1e5?!1:![/javascript:/gi,/data:text\/html/gi,/vbscript:/gi,/<script[^>]*>/gi,/<iframe[^>]*>/gi,/<object[^>]*>/gi,/<embed[^>]*>/gi,/<link[^>]*>/gi,/<meta[^>]*>/gi].some(n=>n.test(t))}function ht(t){return t.replace(/<script[^>]*>.*?<\/script>/gis,"").replace(/<iframe[^>]*>.*?<\/iframe>/gis,"").replace(/javascript:/gi,"").replace(/data:text\/html/gi,"").replace(/vbscript:/gi,"")}function pt(t){return t.split(/(<smiles>.*?<\/smiles>)/gs)}function Ae(t){return t.match(/<smiles>(.*?)<\/smiles>/s)}function Ne(t){return!t||typeof t!="string"||t.length>1e3?!1:/^[a-zA-Z0-9\[\]()=#@+\-\\\/:.%]+$/.test(t)}function Le(t){return t.replace(/<[^>]*>/g,"").replace(/javascript:/gi,"").replace(/data:/gi,"").trim()}function mt(t){const r=Ae(t);return r?r[1]:null}const se=({code:t,errorCallback:r})=>{const n=M.useRef(null),[c,d]=M.useState(!1),[p,m]=M.useState("");return M.useEffect(()=>{if(!t||!n.current)return;const o=Le(t);if(!Ne(o)){const h=new Error(`Invalid SMILES code: ${t}`);d(!0),m(`Error rendering chemical structure: ${t}`),r(h);return}d(!1),m("");try{const h=new Ce.SvgDrawer({width:300,height:200});Ce.parse(o,s=>{if(n.current){n.current.innerHTML="";const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("width","300"),l.setAttribute("height","200"),l.setAttribute("data-smiles",t),l.style.maxWidth="100%",l.style.height="auto",n.current.appendChild(l),h.draw(s,l,"light")}},s=>{d(!0),m(`Error rendering chemical structure: ${t}`),r&&r(s)})}catch(h){d(!0),m(`Error rendering chemical structure: ${t}`),r&&r(h)}},[t,r]),c?a.jsx("div",{className:"smiles-error bg-red-50 border border-red-200 rounded-md p-3 my-2",role:"alert","aria-live":"polite","aria-label":"Chemical structure rendering error",children:a.jsx("p",{className:"text-sm text-red-800",children:p})}):a.jsxs("div",{className:"smiles-container block",role:"img","aria-label":`Chemical structure: ${t}`,"aria-describedby":`smiles-description-${t.replace(/[^a-zA-Z0-9]/g,"")}`,children:[a.jsx("div",{ref:n,style:{maxWidth:"100%",height:"auto"}}),a.jsxs("span",{id:`smiles-description-${t.replace(/[^a-zA-Z0-9]/g,"")}`,style:{position:"absolute",width:"1px",height:"1px",padding:0,margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:["SMILES notation: ",t,". This represents a chemical structure rendered as a 2D diagram."]})]})};class vt{constructor(r){this.text=r}parseContent(){const r=[];return this.findSmilesMatches(r),this.findHeadingMatches(r),this.findMathMatches(r),this.findEnvironmentMatches(r),this.filterNestedMatches(r)}findSmilesMatches(r){const n=/<smiles>.*?<\/smiles>/gs;let c;for(;(c=n.exec(this.text))!==null;)r.push({start:c.index,end:c.index+c[0].length,content:c[0],type:"smiles"})}findHeadingMatches(r){const n=/^(#{1,6})\s+(.+)$/gm;let c;for(;(c=n.exec(this.text))!==null;)r.push({start:c.index,end:c.index+c[0].length,content:c[0],type:"heading"})}findMathMatches(r){const n=/(\$\$.*?\$\$|\\\[.*?\\\])/gs;let c;for(;(c=n.exec(this.text))!==null;)r.push({start:c.index,end:c.index+c[0].length,content:c[0],type:"math"});const d=/(\\\(.*?\\\)|\$[^$\s][^$]*[^$\s]\$|\$[^$\s]+\$)/gs;let p;for(;(p=d.exec(this.text))!==null;)r.some(o=>p.index<o.end&&p.index+p[0].length>o.start)||this.isInListContext(p.index)||this.shouldSkipMathFragment(p[0])||r.push({start:p.index,end:p.index+p[0].length,content:p[0],type:"math"})}findEnvironmentMatches(r){ne(this.text).forEach(c=>{r.push({...c,type:"env"})})}isInListContext(r){const n=this.text.lastIndexOf(` `,r-1),c=n===-1?0:n+1,d=this.text.slice(c,r);return/^\s*[-*+]\s*$/.test(d)}shouldSkipMathFragment(r){return!!(r.startsWith("$")&&!r.startsWith("$$")&&F(r)||r.startsWith("\\(")&&r.endsWith("\\)")&&V(r)||r.startsWith("$")&&!r.startsWith("$$")&&!Y(r))}filterNestedMatches(r){return r.sort((n,c)=>n.start-c.start),r.filter((n,c,d)=>!d.some((m,o)=>c===o?!1:n.start>=m.start&&n.end<=m.end))}}function gt(t,r){const n=t.replace(/^\\begin\{[^}]+\}/s,"").replace(/\\end\{[^}]+\}$/s,"").trim(),c=ne(n),d={};let p="",m=0;c.forEach((h,s)=>{const l=`__LATEX_ENV_PLACEHOLDER_${s}__`;d[l]=h.content,p+=n.substring(m,h.start),p+=l,m=h.end}),p+=n.substring(m);let o=p.split(/\\item/).filter(h=>h.trim());return o.length===0&&p.trim()&&(o=[p.trim()]),o.map((h,s)=>{const l=h.trim(),f=j=>{const R=/(__LATEX_ENV_PLACEHOLDER_\d+__)/g;return j.split(R).filter(Boolean).map((W,A)=>{if(d[W])return a.jsx("span",{children:d[W]},A);const N=new Map;let C=0,O=W;const he=/<smiles>(.*?)<\/smiles>/g;O=O.replace(he,(w,H)=>{const S=`SMILES_PLACEHOLDER_${C++}`;return N.set(S,a.jsx(se,{code:H,errorCallback:D=>console.error(D)},S)),S});const pe=/(\\\(.*?\\\)|\$[^$\s][^$]*[^$\s]\$|\$[^$\s]+\$)/gs;O=O.replace(pe,w=>{if(F(w)||w.startsWith("\\(")&&w.endsWith("\\)")&&V(w)||w.startsWith("$")&&!w.startsWith("$$")&&!Y(w))return w;const S=`MATH_PLACEHOLDER_${C++}`;return N.set(S,a.jsx(L.InlineMath,{math:w.startsWith("\\(")?w.slice(2,-2):w.slice(1,-1)},S)),S}),O=O.replace(/\$([a-zA-Z][a-zA-Z0-9_]{0,2})\$/g,"**$1**"),O=O.replace(/\\\(([a-zA-Z][a-zA-Z0-9]{0,2})\\\)/g,"***$1***");let Q=[O];return N.forEach((w,H)=>{Q=Q.flatMap(S=>{if(typeof S=="string"&&S.includes(H)){const D=S.split(H),ee=[];for(let z=0;z<D.length;z++)z>0&&ee.push(w),D[z]&&ee.push(D[z]);return ee}return[S]})}),a.jsx("span",{children:Q},A)})};if(r==="description"){const j=l.match(/^\[([^\]]+)\]\s*(.*)$/s);if(j){const[,R,I]=j;return a.jsxs("div",{className:"mb-2",children:[a.jsx("dt",{className:"font-semibold",children:R}),a.jsx("dd",{className:"ml-4",children:f(I)})]},s)}else return a.jsx("div",{className:"mb-2",children:a.jsx("dd",{className:"ml-0",children:f(l)})},s)}return a.jsx("li",{className:"mb-1",children:f(l)},s)}).filter(Boolean)}function bt(t,r){const n=gt(r,t);if(n.length===0)return a.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 p-3 rounded-md my-4",children:[a.jsxs("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mb-2",children:["Malformed LaTeX ",t," environment:"]}),a.jsx("pre",{className:"whitespace-pre-wrap text-sm text-gray-700 dark:text-gray-300",children:r})]});switch(t){case"enumerate":return a.jsx("ol",{className:"list-decimal list-outside space-y-1 my-4 pl-5",children:n});case"itemize":return a.jsx("ul",{className:"list-disc list-outside space-y-1 my-4 pl-5",children:n});case"description":return a.jsx("dl",{className:"space-y-2 my-4 pl-5",children:n});default:return a.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 p-4 rounded-md my-4",children:[a.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-2",children:["LaTeX ",t," environment:"]}),a.jsx("div",{className:"pl-4",children:n.length>0?a.jsx("ul",{className:"list-none space-y-1",children:n}):a.jsx("pre",{className:"whitespace-pre-wrap text-sm",children:r})})]})}}function Ie(t,r=!1){const n=ke(t);if(n){const[,o]=n;return bt(o,t)}const c=de(t),d=ue(t),p=Y(t);if(c&&!r){const o=c[1]||c[2];return a.jsx("div",{className:"my-2",children:a.jsx(L.BlockMath,{math:o})})}else{if(d)return a.jsx(L.InlineMath,{math:d[1]});if(p)return a.jsx(L.InlineMath,{math:p[1]});{const o=F(t);if(o)return a.jsx("span",{className:"font-bold",children:o.content});const h=V(t);if(h)return a.jsx("span",{className:"font-bold italic",children:h.content})}}const m=Se(t);return a.jsx(a.Fragment,{children:m.map((o,h)=>{const s=de(o);if(s&&!r){const l=s[1]||s[2];return a.jsx("div",{className:"my-2",children:a.jsx(L.BlockMath,{math:l})},h)}else if(s&&r){const l=s[1]||s[2];return a.jsx(L.InlineMath,{math:l},h)}else{const l=F(o);if(l)return a.jsx("span",{className:"font-bold",children:l.content},h);{const f=V(o);if(f)return a.jsx("span",{className:"font-bold italic",children:f.content},h);{const j=ue(o);if(j)return a.jsx(L.InlineMath,{math:j[1]},h);{const R=Y(o);return R?a.jsx(L.InlineMath,{math:R[1]},h):a.jsx("span",{className:"whitespace-pre-line",children:o},h)}}}}})})}function fe(t,r){const n=new Map;let c=0,d=t;const p=/<smiles>(.*?)<\/smiles>/g;d=d.replace(p,(s,l)=>{const f=`SMILES_PLACEHOLDER_${c++}`;return n.set(f,a.jsx(se,{code:l,errorCallback:j=>console.error(j)},f)),f});const m=/(\\\(.*?\\\)|\$[^$\s][^$]*[^$\s]\$|\$[^$\s]+\$)/gs;d=d.replace(m,s=>{if(F(s)||s.startsWith("\\(")&&s.endsWith("\\)")&&V(s)||s.startsWith("$")&&!s.startsWith("$$")&&!Y(s))return s;const f=`MATH_PLACEHOLDER_${c++}`;return n.set(f,a.jsx(L.InlineMath,{math:s.startsWith("\\(")?s.slice(2,-2):s.slice(1,-1)},f)),f}),d=d.replace(/\$([a-zA-Z][a-zA-Z0-9_]{0,2})\$/g,"**$1**"),d=d.replace(/\\\(([a-zA-Z][a-zA-Z0-9]{0,2})\\\)/g,"***$1***");const o=()=>s=>{if(typeof s=="string"){let l=[s];return n.forEach((f,j)=>{l=l.flatMap(R=>{if(typeof R=="string"&&R.includes(j)){const I=R.split(j),W=[];for(let A=0;A<I.length;A++)A>0&&W.push(f),I[A]&&W.push(I[A]);return W}return[R]})}),l}return Array.isArray(s)?s.map(o()):s},h={p:({children:s,...l})=>{const f=o();return a.jsx("p",{...l,children:f(s)})},h1:({children:s,...l})=>{const f=o();return a.jsx("h1",{className:"text-3xl font-bold mb-4 mt-6",...l,children:f(s)})},h2:({children:s,...l})=>{const f=o();return a.jsx("h2",{className:"text-2xl font-semibold mb-3 mt-5",...l,children:f(s)})},h3:({children:s,...l})=>{const f=o();return a.jsx("h3",{className:"text-xl font-medium mb-2 mt-4",...l,children:f(s)})},h4:({children:s,...l})=>{const f=o();return a.jsx("h4",{className:"text-lg font-medium mb-2 mt-3",...l,children:f(s)})},h5:({children:s,...l})=>{const f=o();return a.jsx("h5",{className:"text-base font-medium mb-1 mt-2",...l,children:f(s)})},h6:({children:s,...l})=>{const f=o();return a.jsx("h6",{className:"text-sm font-medium mb-1 mt-2",...l,children:f(s)})},strong:({children:s,...l})=>{const f=o();return a.jsx("strong",{...l,children:f(s)})},em:({children:s,...l})=>{const f=o();return a.jsx("em",{...l,children:f(s)})},code:({children:s,...l})=>{const f=o();return a.jsx("code",{...l,children:f(s)})},ul:({children:s,...l})=>{const f=o();return a.jsx("ul",{className:"list-disc list-outside space-y-1 my-4 pl-5",...l,children:f(s)})},ol:({children:s,...l})=>{const f=o();return a.jsx("ol",{className:"list-decimal list-outside space-y-1 my-4 pl-5",...l,children:f(s)})},li:({children:s,...l})=>{const f=o();return a.jsx("li",{className:"mb-1",...l,children:f(s)})},a:({children:s,...l})=>{const f=o();return a.jsx("a",{...l,children:f(s)})},blockquote:({children:s,...l})=>{const f=o();return a.jsx("blockquote",{...l,children:f(s)})},span:({children:s,...l})=>{const f=o();return a.jsx("span",{...l,children:f(s)})},div:({children:s,...l})=>{const f=o();return a.jsx("div",{...l,children:f(s)})}};return a.jsx($e,{remarkPlugins:[_e],components:h,children:d},`text-${r}`)}const xt=({content:t,renderAsMarkdown:r=!0,inline:n=!1})=>!t||typeof t!="string"?null:Oe(t)?(d=>ne(d).length>0||d.includes("\\[")||d.includes("$$"))(t)||!r?yt(t,{renderAsMarkdown:r,inline:n}):jt(t,{inline:n}):a.jsx("div",{className:"error-message bg-red-50 border border-red-200 rounded-md p-3",role:"alert","aria-live":"polite",children:a.jsx("p",{className:"text-red-800",children:"Invalid or potentially unsafe content"})});function yt(t,r){const{renderAsMarkdown:n,inline:c}=r,m=new vt(t).parseContent().filter(s=>s.type==="math"?s.content.match(/^(\$\$|\\\[)/):s.type==="smiles"||s.type==="heading"||s.type==="env"),o=[];let h=0;if(m.forEach((s,l)=>{if(s.start>h){const f=t.slice(h,s.start);if(f.trim())if(n){const j=fe(f,l);o.push(j)}else{const j=B(f);o.push(a.jsx("span",{className:"whitespace-pre-line",children:j},`text-${l}`))}}o.push(Et(s,l)),h=s.end}),h<t.length){const s=t.slice(h);if(s.trim())if(n){const l=fe(s,h);o.push(l)}else{const l=B(s);o.push(a.jsx("span",{className:"whitespace-pre-line",children:l},"text-final"))}}return c?a.jsx("span",{className:"prose-inline",role:"presentation","aria-label":"Scientific content with mixed formatting",children:o.length>0?o:We(t,n)}):a.jsx("div",{className:"prose dark:prose-invert max-w-none",role:"article","aria-label":"Scientific document content",children:o.length>0?o:We(t,n)})}function Et(t,r){var n;switch(t.type){case"smiles":const c=(n=t.content.match(/<smiles>(.*?)<\/smiles>/))==null?void 0:n[1];if(c)return a.jsx(se,{code:c,errorCallback:m=>console.error(m)},`smiles-${r}`);break;case"heading":const d=t.content.match(/^(#{1,6})\s+(.+)$/);if(d){const m=d[1].length,o=d[2];return a.jsx("div",{children:Pe(o,m)},`heading-${r}`)}break;case"math":case"env":return Te(t.content)?t.content.match(/^(\$\$|\\\[)/)?a.jsx("div",{role:"math","aria-label":`Mathematical expression: ${t.content.replace(/[\$\\\[\]]/g,"").trim()}`,children:Ie(t.content,!1)},`latex-${r}`):a.jsx("span",{role:"math","aria-label":`Inline math: ${t.content.replace(/[\$\\\(\)]/g,"").trim()}`,children:Ie(t.content,!0)},`latex-${r}`):a.jsx("div",{className:"bg-red-50 border border-red-200 rounded-md p-3",role:"alert","aria-live":"polite","aria-label":"LaTeX rendering error",children:a.jsx("p",{className:"text-red-800",children:"Invalid LaTeX content"})},`error-${r}`)}return a.jsx("span",{children:t.content},`fallback-${r}`)}function jt(t,r){const{inline:n}=r,c=fe(t,0);return n?a.jsx("span",{className:"prose-inline",role:"presentation","aria-label":"Scientific content with mixed formatting",children:c}):a.jsx("div",{className:"prose dark:prose-invert max-w-none",role:"article","aria-label":"Scientific document content",children:c})}function We(t,r){return r?a.jsx($e,{remarkPlugins:[_e],children:t.replace(/\$([a-zA-Z][a-zA-Z0-9_]{0,2})\$/g,"**$1**").replace(/\\\(\s*([a-zA-Z][a-zA-Z0-9]{0,2})\s*\\\)/g,"***$1***")}):a.jsx("span",{className:"whitespace-pre-line",children:B(t)})}x.RichText=xt,x.Smiles=se,x.extractSmilesCode=mt,x.findTopLevelEnvs=ne,x.isBlockLatexFragment=de,x.isInlineLatexFragment=ue,x.isLatexEnvironment=ke,x.isSelectiveInlineLatex=Y,x.isSimpleVariable=F,x.isSmallVariableLatex=V,x.isSmilesCode=Ae,x.processMixedContent=Me,x.processTextWithSmallVariables=B,x.renderHeading=Pe,x.sanitizeLatexContent=ft,x.sanitizeMarkdownContent=ht,x.sanitizeSmilesCode=Le,x.splitLatex=Se,x.splitSmiles=pt,x.validateLatexInput=Te,x.validateMarkdownContent=Oe,x.validateSmilesCode=Ne,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});