数式をpreviewするUserScript
code:script.js
var d,Le,T,J,Y,De,B={},O=[],$e=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|inech|zoo|^ord|itera/i;function w(t,e){for(var n in e)tn=en;return t}function Q(t){var e=t.parentNode;e&&e.removeChild(t)}function U(t,e,n){var o,s,r,u=arguments,c={};for(r in e)r=="key"?o=er:r=="ref"?s=er:cr=er;if(arguments.length>3)for(n=n,r=3;r<arguments.length;r++)n.push(ur);if(n!=null&&(c.children=n),typeof t=="function"&&t.defaultProps!=null)for(r in t.defaultProps)cr===void 0&&(cr=t.defaultPropsr);return N(t,c,o,s,null)}function N(t,e,n,o,s){var r={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:s??++d.__v};return d.vnode!=null&&d.vnode(r),r}function A(t){return t.children}function L(t,e){this.props=t,this.context=e}function j(t,e){if(e==null)return t.__?j(t.__,t.__.__k.indexOf(t)+1):null;for(var n;e<t.__k.length;e++)if((n=t.__ke)!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?j(t):null}function Z(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__ke)!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return Z(t)}}function ee(t){(!t.__d&&(t.__d=!0)&&T.push(t)&&!D.__r++||Y!==d.debounceRendering)&&((Y=d.debounceRendering)||J)(D)}function D(){for(var t;D.__r=T.length;)t=T.sort(function(e,n){return e.__v.__b-n.__v.__b}),T=[],t.some(function(e){var n,o,s,r,u,c;e.__d&&(u=(r=(n=e).__v).__e,(c=n.__P)&&(o=[],(s=w({},r)).__v=r.__v+1,X(c,r,s,n.__n,c.ownerSVGElement!==void 0,r.__h!=null?u:null,o,u??j(r),r.__h),ue(o,r),r.__e!=u&&Z(r)))})}function te(t,e,n,o,s,r,u,c,a,p){var i,f,_,l,h,m,v,g=o&&o.__k||O,b=g.length;for(n.__k=[],i=0;i<e.length;i++)if((l=n.__ki=(l=ei)==null||typeof l=="boolean"?null:typeof l=="string"||typeof l=="number"||typeof l=="bigint"?N(null,l,null,null,l):Array.isArray(l)?N(A,{children:l},null,null,null):l.__b>0?N(l.type,l.props,l.key,null,l.__v):l)!=null){if(l.__=n,l.__b=n.__b+1,(_=gi)===null||_&&l.key==_.key&&l.type===_.type)gi=void 0;else for(f=0;f<b;f++){if((_=gf)&&l.key==_.key&&l.type===_.type){gf=void 0;break}_=null}X(t,l,_=_||B,s,r,u,c,a,p),h=l.__e,(f=l.ref)&&_.ref!=f&&(v||(v=[]),_.ref&&v.push(_.ref,null,l),v.push(f,l.__c||h,l)),h!=null?(m==null&&(m=h),typeof l.type=="function"&&l.__k!=null&&l.__k===_.__k?l.__d=a=ne(l,a,t):a=re(t,l,_,g,h,a),p||n.type!=="option"?typeof n.type=="function"&&(n.__d=a):t.value=""):a&&_.__e==a&&a.parentNode!=t&&(a=j(_))}for(n.__e=m,i=b;i--;)gi!=null&&(typeof n.type=="function"&&gi.__e!=null&&gi.__e==n.__d&&(n.__d=j(o,i+1)),ce(gi,gi));if(v)for(i=0;i<v.length;i++)ae(vi,v++i,v++i)}function ne(t,e,n){var o,s;for(o=0;o<t.__k.length;o++)(s=t.__ko)&&(s.__=t,e=typeof s.type=="function"?ne(s,e,n):re(n,s,s,t.__k,s.__e,e));return e}function W(t,e){return e=e||[],t==null||typeof t=="boolean"||(Array.isArray(t)?t.some(function(n){W(n,e)}):e.push(t)),e}function re(t,e,n,o,s,r){var u,c,a;if(e.__d!==void 0)u=e.__d,e.__d=void 0;else if(n==null||s!=r||s.parentNode==null)e:if(r==null||r.parentNode!==t)t.appendChild(s),u=null;else{for(c=r,a=0;(c=c.nextSibling)&&a<o.length;a+=2)if(c==s)break e;t.insertBefore(s,r),u=r}return u!==void 0?u:s.nextSibling}function Fe(t,e,n,o,s){var r;for(r in n)r==="children"||r==="key"||r in e||$(t,r,null,nr,o);for(r in e)s&&typeof er!="function"||r==="children"||r==="key"||r==="value"||r==="checked"||nr===er||$(t,r,er,nr,o)}function oe(t,e,n){e0==="-"?t.setProperty(e,n):te=n==null?"":typeof n!="number"||$e.test(e)?n:n+"px"}function $(t,e,n,o,s){var r;e:if(e==="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||oe(t.style,e,"");if(n)for(e in n)o&&ne===oe||oe(t.style,e,ne)}else if(e0==="o"&&e1==="n")r=e!==(e=e.replace(/Capture$/,"")),e=e.toLowerCase()in t?e.toLowerCase().slice(2):e.slice(2),t.l||(t.l={}),t.le+r=n,n?o||t.addEventListener(e,r?se:ie,r):t.removeEventListener(e,r?se:ie,r);else if(e!=="dangerouslySetInnerHTML"){if(s)e=e.replace(/xlinkH:h/,"h").replace(/sName$/,"s");else if(e!=="href"&&e!=="list"&&e!=="form"&&e!=="tabIndex"&&e!=="download"&&e in t)try{te=n??"";break e}catch(u){}typeof n=="function"||(n!=null&&(n!==!1||e0==="a"&&e1==="r")?t.setAttribute(e,n):t.removeAttribute(e))}}function ie(t){this.lt.type+!1(d.event?d.event(t):t)}function se(t){this.lt.type+!0(d.event?d.event(t):t)}function X(t,e,n,o,s,r,u,c,a){var p,i,f,_,l,h,m,v,g,b,P,k=e.type;if(e.constructor!==void 0)return null;n.__h!=null&&(a=n.__h,c=e.__e=n.__e,e.__h=null,r=c),(p=d.__b)&&p(e);try{e:if(typeof k=="function"){if(v=e.props,g=(p=k.contextType)&&op.__c,b=p?g?g.props.value:p.__:o,n.__c?m=(i=e.__c=n.__c).__=i.__E:("prototype"in k&&k.prototype.render?e.__c=i=new k(v,b):(e.__c=i=new L(v,b),i.constructor=k,i.render=ze),g&&g.sub(i),i.props=v,i.state||(i.state={}),i.context=b,i.__n=o,f=i.__d=!0,i.__h=[]),i.__s==null&&(i.__s=i.state),k.getDerivedStateFromProps!=null&&(i.__s==i.state&&(i.__s=w({},i.__s)),w(i.__s,k.getDerivedStateFromProps(v,i.__s))),_=i.props,l=i.state,f)k.getDerivedStateFromProps==null&&i.componentWillMount!=null&&i.componentWillMount(),i.componentDidMount!=null&&i.__h.push(i.componentDidMount);else{if(k.getDerivedStateFromProps==null&&v!==_&&i.componentWillReceiveProps!=null&&i.componentWillReceiveProps(v,b),!i.__e&&i.shouldComponentUpdate!=null&&i.shouldComponentUpdate(v,i.__s,b)===!1||e.__v===n.__v){i.props=v,i.state=i.__s,e.__v!==n.__v&&(i.__d=!1),i.__v=e,e.__e=n.__e,e.__k=n.__k,e.__k.forEach(function(R){R&&(R.__=e)}),i.__h.length&&u.push(i);break e}i.componentWillUpdate!=null&&i.componentWillUpdate(v,i.__s,b),i.componentDidUpdate!=null&&i.__h.push(function(){i.componentDidUpdate(_,l,h)})}i.context=b,i.props=v,i.state=i.__s,(p=d.__r)&&p(e),i.__d=!1,i.__v=e,i.__P=t,p=i.render(i.props,i.state,i.context),i.state=i.__s,i.getChildContext!=null&&(o=w(w({},o),i.getChildContext())),f||i.getSnapshotBeforeUpdate==null||(h=i.getSnapshotBeforeUpdate(_,l)),P=p!=null&&p.type===A&&p.key==null?p.props.children:p,te(t,Array.isArray(P)?P:P,e,n,o,s,r,u,c,a),i.base=e.__e,e.__h=null,i.__h.length&&u.push(i),m&&(i.__E=i.__=null),i.__e=!1}else r==null&&e.__v===n.__v?(e.__k=n.__k,e.__e=n.__e):e.__e=Ie(n.__e,e,n,o,s,r,u,a);(p=d.diffed)&&p(e)}catch(R){e.__v=null,(a||r!=null)&&(e.__e=c,e.__h=!!a,rr.indexOf(c)=null),d.__e(R,e,n)}}function ue(t,e){d.__c&&d.__c(e,t),t.some(function(n){try{t=n.__h,n.__h=[],t.some(function(o){o.call(n)})}catch(o){d.__e(o,n.__v)}})}function Ie(t,e,n,o,s,r,u,c){var a,p,i,f,_=n.props,l=e.props,h=e.type,m=0;if(h==="svg"&&(s=!0),r!=null){for(;m<r.length;m++)if((a=rm)&&(a===t||(h?a.localName==h:a.nodeType==3))){t=a,rm=null;break}}if(t==null){if(h===null)return document.createTextNode(l);t=s?document.createElementNS("http://www.w3.org/2000/svg",h):document.createElement(h,l.is&&l),r=null,c=!1}if(h===null)_===l||c&&t.data===l||(t.data=l);else{if(r=r&&O.slice.call(t.childNodes),p=(_=n.props||B).dangerouslySetInnerHTML,i=l.dangerouslySetInnerHTML,!c){if(r!=null)for(_={},f=0;f<t.attributes.length;f++)_[t.attributes[f].name]=t.attributes[f].value;(i||p)&&(i&&(p&&i.__html==p.__html||i.__html===t.innerHTML)||(t.innerHTML=i&&i.__html||""))}if(Fe(t,l,_,s,c),i)e.__k=[];else if(m=e.props.children,te(t,Array.isArray(m)?m:m,e,n,o,s&&h!=="foreignObject",r,u,t.firstChild,c),r!=null)for(m=r.length;m--;)rm!=null&&Q(rm);c||("value"in l&&(m=l.value)!==void 0&&(m!==t.value||h==="progress"&&!m)&&$(t,"value",m,_.value,!1),"checked"in l&&(m=l.checked)!==void 0&&m!==t.checked&&$(t,"checked",m,_.checked,!1))}return t}function ae(t,e,n){try{typeof t=="function"?t(e):t.current=e}catch(o){d.__e(o,n)}}function ce(t,e,n){var o,s,r;if(d.unmount&&d.unmount(t),(o=t.ref)&&(o.current&&o.current!==t.__e||ae(o,null,e)),n||typeof t.type=="function"||(n=(s=t.__e)!=null),t.__e=t.__d=void 0,(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(u){d.__e(u,e)}o.base=o.__P=null}if(o=t.__k)for(r=0;r<o.length;r++)or&&ce(or,e,n);s!=null&&Q(s)}function ze(t,e,n){return this.constructor(t,n)}function le(t,e,n){var o,s,r;d.__&&d.__(t,e),s=(o=typeof n=="function")?null:n&&n.__k||e.__k,r=[],X(e,t=(!o&&n||e).__k=U(A,null,t),s||B,B,e.ownerSVGElement!==void 0,!o&&n?n:s?null:e.firstChild?O.slice.call(e.childNodes):null,r,!o&&n?n:s?s.__e:e.firstChild,o),ue(r,t)}d={__e:function(t,e){for(var n,o,s;e=e.__;)if((n=e.__c)&&!n.__)try{if((o=n.constructor)&&o.getDerivedStateFromError!=null&&(n.setState(o.getDerivedStateFromError(t)),s=n.__d),n.componentDidCatch!=null&&(n.componentDidCatch(t),s=n.__d),s)return n.__E=n}catch(r){t=r}throw t},__v:0},Le=function(t){return t!=null&&t.constructor===void 0},L.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!==this.state?this.__s:this.__s=w({},this.state),typeof t=="function"&&(t=t(w({},n),this.props)),t&&w(n,t),t!=null&&this.__v&&(e&&this.__h.push(e),ee(this))},L.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),ee(this))},L.prototype.render=A,T=[],J=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,D.__r=0,De=0;var _e=function(t,e,n,o){var s;e0=0;for(var r=1;r<e.length;r++){var u=er++,c=er?(e0|=u?1:2,n[er++]):e++r;u===3?o0=c:u===4?o1=Object.assign(o1||{},c):u===5?(o1=o1||{})[e++r]=c:u===6?o1[e++r]+=c+"":u?(s=t.apply(c,_e(t,c,n,"",null)),o.push(s),c0?e0|=2:(er-2=0,er=s)):o.push(c)}return o},pe=new Map;function fe(t){var e=pe.get(this);return e||(e=new Map,pe.set(this,e)),(e=_e(this,e.get(t)||(e.set(t,e=function(n){for(var o,s,r=1,u="",c="",a=0,p=function(_){r===1&&(_||(u=u.replace(/^\s*\n\s*|\s*\n\s*$/g,"")))?a.push(0,_,u):r===3&&(_||u)?(a.push(3,_,u),r=2):r===2&&u==="..."&&_?a.push(4,_,0):r===2&&u&&!_?a.push(5,0,!0,u):r>=5&&((u||!_&&r===5)&&(a.push(r,0,u,s),r=6),_&&(a.push(r,_,0,s),r=6)),u=""},i=0;i<n.length;i++){i&&(r===1&&p(),p(i));for(var f=0;f<ni.length;f++)o=nif,r===1?o==="<"?(p(),a=a,r=3):u+=o:r===4?u==="--"&&o===">"?(r=1,u=""):u=o+u0:c?o===c?c="":u+=o:o==='"'||o==="'"?c=o:o===">"?(p(),r=1):r&&(o==="="?(r=5,s=u,u=""):o==="/"&&(r<5||nif+1===">")?(p(),r===3&&(a=a0),r=a,(a=a0).push(2,0,r),r=0):o===" "||o===" "||o===` ||o==="\r"?(p(),r=2):u+=o),r===3&&u==="!--"&&(r=4,a=a[0])}return p(),a}(t)),e),arguments,[])).length>1?e:e[0]}var S=fe.bind(U);var de="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.3/katex.min.js",me=!1,he=()=>new Promise(async(t,e)=>{if(document.querySelector(scriptsrc="${de}")){me||await ve(),t();return}let n=document.createElement("script");n.addEventListener("load",async()=>{await ve(),me=!0,t()}),n.addEventListener("error",o=>e(o)),n.src=de,document.head.appendChild(n)}),ve=()=>new Promise(t=>{let e=setInterval(()=>{!window.katex||(clearInterval(e),t())},500)});var F,y,ge,H=0,q=[],ye=d.__b,be=d.__r,xe=d.diffed,ke=d.__c,we=d.unmount;function K(t,e){d.__h&&d.__h(y,t,H||e),H=0;var n=y.__H||(y.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function C(t){return H=1,Oe(Me,t)}function Oe(t,e,n){var o=K(F++,2);return o.t=t,o.__c||(o.__=[n?n(e):Me(void 0,e),function(s){var r=o.t(o.__[0],s);o.__[0]!==r&&(o.__=[r,o.__[1]],o.__c.setState({}))}],o.__c=y),o.__}function M(t,e){var n=K(F++,3);!d.__s&&Se(n.__H,e)&&(n.__=t,n.__H=e,y.__H.__h.push(n))}function x(t){return H=5,E(function(){return{current:t}},[])}function E(t,e){var n=K(F++,7);return Se(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function Ce(t,e){return H=8,E(function(){return t},e)}function Ue(){q.forEach(function(t){if(t.__P)try{t.__H.__h.forEach(I),t.__H.__h.forEach(V),t.__H.__h=[]}catch(e){t.__H.__h=[],d.__e(e,t.__v)}}),q=[]}d.__b=function(t){y=null,ye&&ye(t)},d.__r=function(t){be&&be(t),F=0;var e=(y=t.__c).__H;e&&(e.__h.forEach(I),e.__h.forEach(V),e.__h=[])},d.diffed=function(t){xe&&xe(t);var e=t.__c;e&&e.__H&&e.__H.__h.length&&(q.push(e)!==1&&ge===d.requestAnimationFrame||((ge=d.requestAnimationFrame)||function(n){var o,s=function(){clearTimeout(r),Ee&&cancelAnimationFrame(o),setTimeout(n)},r=setTimeout(s,100);Ee&&(o=requestAnimationFrame(s))})(Ue)),y=void 0},d.__c=function(t,e){e.some(function(n){try{n.__h.forEach(I),n.__h=n.__h.filter(function(o){return!o.__||V(o)})}catch(o){e.some(function(s){s.__h&&(s.__h=[])}),e=[],d.__e(o,n.__v)}}),ke&&ke(t,e)},d.unmount=function(t){we&&we(t);var e=t.__c;if(e&&e.__H)try{e.__H.__.forEach(I)}catch(n){d.__e(n,e.__v)}};var Ee=typeof requestAnimationFrame=="function";function I(t){var e=y;typeof t.__c=="function"&&t.__c(),y=e}function V(t){var e=y;t.__c=t.__(),y=e}function Se(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Me(t,e){return typeof e=="function"?e(t):e}var Te=t=>{let e=x(null),[n,o]=C(t),[s,r]=C(void 0);return M(()=>{(async()=>{await he();try{katex.render(n,e.current),r(void 0)}catch(u){u instanceof katex.ParseError&&r(u.message)}})()},[n,e]),{ref:e,formula:n,error:s,setFormula:o}};function We(t,e){var n,o=null,s=x(null),r=x(null),u=Ce(function(i){r.current=i,p()},[]),c=x(null),a=x(),p=function(){var f=null;r.current?f=r.current:s.current?f=s.current:e instanceof HTMLElement&&(f=e),c.current!==f&&(a.current&&(a.current(),a.current=null),c.current=f,f&&(a.current=t(f)))};return e&&!(e instanceof HTMLElement)&&(o=e),M(function(){o&&(s.current=o.current),p()},[o,(n=o)==null?void 0:n.current,e]),u}function Xe(t){t===void 0&&(t={});var e=t.onResize,n=x(void 0);n.current=e;var o=x(),s=C({width:void 0,height:void 0}),r=s[0],u=s[1],c=x(!1);M(function(){return function(){c.current=!0}},[]);var a=x({width:void 0,height:void 0}),p=We(function(i){return o.current||(o.current=new ResizeObserver(function(f){if(!!Array.isArray(f)&&!!f.length){var _=f[0],l=Math.round(_.contentRect.width),h=Math.round(_.contentRect.height);if(a.current.width!==l||a.current.height!==h){var m={width:l,height:h};n.current?n.current(m):(a.current.width=l,a.current.height=h,c.current||u(m))}}})),o.current.observe(i),function(){o.current&&o.current.unobserve(i)}},t.ref);return E(function(){return{ref:p,width:r.width,height:r.height}},[p,r?r.width:null,r?r.height:null])}var G=Xe;var je=class{get editor(){return document.getElementById("editor")}get lines(){return document.getElementsByClassName("lines")?.[0]}get computeLine(){return document.getElementById("compute-line")}get grid(){return document.getElementsByClassName("related-page-list clearfix")?.[0]?.getElementsByClassName("grid")?.[0]}get cursorLine(){return document.getElementsByClassName("cursor-line")?.[0]}get textInput(){return document.getElementById("text-input")}get cursor(){return document.getElementsByClassName("cursor")?.[0]}get selections(){return document.getElementsByClassName("selections")?.[0]}get popupMenu(){return document.getElementsByClassName("popup-menu")?.[0]}get pageMenus(){return document.getElementsByClassName("page-menu")?.[0]}get pageInfoMenu(){return document.getElementById("page-info-menu")}get pageEditMenu(){return document.getElementById("page-edit-menu")}get pageEditButtons(){return this.pageEditMenu.nextElementSibling.getElementsByTagName("a")}get randomJumpButton(){return document.getElementsByClassName("random-jump-button")?.[0]}get pageCustomButtons(){return document.getElementsByClassName("page-menu-extension")}},He=new je;function Pe({open:t,cursorPosition:e,children:n}){let{ref:o,width:s=0}=G(),{width:r=0}=G({ref:He.editor}),u=E(()=>W(n).length===0,[n]),c=qe(e),a=Ke(e,u),p=Ve(r,s,e,u);return S <div class="popup-menu" style="${c}" hidden="${!t}">
<div ref="${o}" class="button-container" style="${p}">
${n}
</div>
<div class="triangle" style="${a}" />
</div>}var qe=t=>({top:t.styleTop}),Ke=(t,e)=>({left:t.styleLeft,...e?{borderTopColor:"#555"}:{}});function Ve(t,e,n,o){let s=n.styleLeft/t*100,r=20/e*100,u=100-r;return{left:n.styleLeft,transform:translateX(-${Math.max(r,Math.min(s,u))}%),...o?{color:"#eee",fontSize:"11px",display:"inline-block",padding:"0 5px",cursor:"not-allowed",backgroundColor:"#555"}:{}}}var Re=()=>S<style>
.popup-menu {
position:absolute;
left:0;
width:100%;
z-index:300;
transform:translateY(calc(-100% - 14px));
-webkit-user-select:none;
user-select:none;
font-family:"Open Sans",Helvetica,Arial,"Hiragino Sans",sans-serif;
pointer-events:none
}
.popup-menu .button-container {
position:relative;
display:inline-block;
max-width:70vw;
min-width:80px;
text-align:center;
background-color:#111;
padding:0 1px;
border-radius:4px;
pointer-events:auto
}
max-width:90vw
}
max-width:90vw
}
.popup-menu .triangle {
position:absolute;
transform:translateX(-50%);
width:0;
height:0;
border-top:6px solid #111; border-left:8px solid transparent;
border-right:8px solid transparent
}
max-width:80vw;
text-align:left
}
.button {
font-size:11px;
color:#eee;
cursor:pointer;
display:inline-block;
padding:0 5px
}
.button:not(:first-of-type) {
border:0;
border-left:1px solid #eee }
.button.selected {
background-color:#222;
text-decoration:underline
}
font-size:13px;
padding:6px;
min-width:12vw
}
font-size:13px;
padding:6px;
min-width:12vw
}
.button div.icon {
height:2em;
max-width:10em;
display:inline-block;
overflow:hidden;
margin-left:1px;
vertical-align:top
}
.button div.icon img {
max-height:100%;
vertical-align:unset
}
font-size:11px;
display:block;
line-height:1.2em;
padding:12px 10px;
min-width:40px;
border-left:0
}
border:0;
border-bottom:1px solid #eee }
max-width:80vw;
text-align:left
}
font-size:11px;
display:block;
line-height:1.2em;
padding:12px 10px;
min-width:40px;
border-left:0
}
htmldata-os*='ios' .popup-menu.vertical .button-container .button:not(:last-of-type), .popup-menudata-os*='ios'.vertical .button-container .button:not(:last-of-type) { border:0;
border-bottom:1px solid #eee }
</style>;var Be=(t,e,n)=>M(()=>{let o=new MutationObserver(s=>{o.disconnect(),e(s);for(let r of t)r.current&&o.observe(r.current,n)});for(let s of t)s.current&&o.observe(s.current,n);return()=>o.disconnect()},[]);function Ne(t,e=0,{immediate:n=!0}={}){if(typeof t!="function")throw new Error("argument is not function.");let o,s=!1,r=e>0?()=>new Promise(c=>setTimeout(()=>c(),e)):()=>{},u=async()=>{if(await r(),!o){s=!1;return}let{parameters:c,resolve:a}=o;o=void 0,a({result:await t(...c),executed:!0}),await u()};return(...c)=>new Promise(async a=>{if(s){o?.resolve?.({executed:!1}),o={parameters:c,resolve:a};return}s=!0,n?a({result:await t(...c),executed:!0}):(o?.resolve?.({executed:!1}),o={parameters:c,resolve:a}),await u()})}function Ae(t,{delay:e=100,immediate:n=!0}={},o=[]){let s=E(()=>Ne(async r=>{let u=r.target,c=parseInt(u.style.top),a=parseInt(u.style.left),p=parseInt(u.style.height),i=u.parentElement.getBoundingClientRect(),f={top:c+i.top,left:a+i.left,right:a+1+i.left,bottom:c+p+i.top,height:p,width:1},_=document.elementsFromPoint(f.left+f.width/2,f.top+f.height/2);await t({cursorRect:f,parentRect:i,elements:_})},e,{immediate:n}),o);Be([{current:document.getElementsByClassName("cursor")?.[0]}],([r])=>s(r),{attributes:!0,attributeFilter:["style"]})}var Ge=()=>{let{ref:t,error:e,setFormula:n}=Te(""),[o,s]=C(!1),[r,u]=C({styleTop:0,styleLeft:0});return Ae(({cursorRect:{left:c},parentRect:{top:a,left:p},elements:i})=>{let f=i.find(l=>l.classList.contains("formula"));if(!f){s(!1);return}s(!0),n(f.textContent.slice(3,-1));let{top:_}=f.getBoundingClientRect();u({styleTop:_-a,styleLeft:c-p})}),S
<${Re} />
<style>
.error {color:#fd7373; }
.katex-display {
display: inline-block !important;
margin: 0 !important;
text-align: inherit !important;
}
</style>
<${Pe} cursorPosition="${r}" open="${o}">
${e&&S<span class="error">${e}</span>}
<span class="katex-display" ref="${t}" />
<//>
},z=document.createElement("div");z.dataset.userscriptName="katex-previewer";document.getElementById("editor").append(z);z.attachShadow({mode:"open"});le(S<${Ge} />`,z.shadowRoot);