ngx-mathquill
Version:
A thin typescript wrapper around mathquill
11 lines • 66.1 kB
JavaScript
/**
* MathQuill v0.10.1, by Han, Jeanine, and Mary
* http://mathquill.com | maintainers@mathquill.com
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL
* was not distributed with this file, You can obtain
* one at http://mozilla.org/MPL/2.0/.
*/
!function(){function t(){}function e(t){var e=t.length-1;return function(){var n=m.call(arguments,0,e),i=m.call(arguments,e);return t.apply(this,n.concat([i]))}}function n(t){return e(function(e,n){"function"!=typeof e&&(e=g(e));var i=function(t){return e.apply(t,[t].concat(n))};return t.call(this,i)})}function i(t){var e=m.call(arguments,1);return function(){return t.apply(this,e)}}function s(t,e){if(!e)throw new Error("prayer failed: "+t)}function r(t){s("a direction was passed",t===b||t===w)}function o(t,e,n){s("a parent is always present",t),s("leftward is properly set up",function(){return e?e[w]===n&&e.parent===t:t.ends[b]===n}()),s("rightward is properly set up",function(){return n?n[b]===e&&n.parent===t:t.ends[w]===e}())}function a(){window.console&&console.warn('You are using the MathQuill API without specifying an interface version, which will fail in v1.0.0. Easiest fix is to do the following before doing anything else:\n\n MathQuill = MathQuill.getInterface(1);\n // now MathQuill.MathField() works like it used to\n\nSee also the "`dev` branch (2014–2015) → v0.10.0 Migration Guide" at\n https://github.com/mathquill/mathquill/wiki/%60dev%60-branch-(2014%E2%80%932015)-%E2%86%92-v0.10.0-Migration-Guide')}function c(t){return a(),_t(t)}function l(e){function n(t){var e,n;return t&&t.nodeType?(e=q(t).children(".mq-root-block").attr(zt),n=e&&k.byId[e].controller,n?s[n.KIND_OF_MQ](n):null):null}function i(t,e){var n,i,r;e&&e.handlers&&(e.handlers={fns:e.handlers,APIClasses:s});for(n in e)e.hasOwnProperty(n)&&(i=e[n],r=_[n],t[n]=r?r(i):i)}var s,r,o;if(!(A<=e&&e<=z))throw"Only interface versions between "+A+" and "+z+" supported. You specified: "+e;s={},n.L=b,n.R=w,n.saneKeyboardEvents=M,n.config=function(t){return i(D.p,t),this},n.registerEmbed=function(t,e){if(!/^[a-z][a-z0-9]*$/i.test(t))throw"Embed name must start with letter and be only letters and digits";L[t]=e},r=s.AbstractMathQuill=v(E,function(t){t.init=function(t){this.__controller=t,this.__options=t.options,this.id=t.id,this.data=t.data},t.__mathquillify=function(t){var e,n=this.__controller,i=n.root,s=n.container;n.createTextarea(),e=s.addClass(t).contents().detach(),i.jQ=q('<span class="mq-root-block"/>').attr(zt,i.id).appendTo(s),this.latex(e.text()),this.revert=function(){return s.empty().unbind(".mathquill").removeClass("mq-editable-field mq-math-mode mq-text-mode").append(e)}},t.config=function(t){return i(this.__options,t),this},t.el=function(){return this.__controller.container[0]},t.text=function(){return this.__controller.exportText()},t.latex=function(t){return arguments.length>0?(this.__controller.renderLatexMath(t),this.__controller.blurred&&this.__controller.cursor.hide().parent.blur(),this):this.__controller.exportLatex()},t.html=function(){return this.__controller.root.jQ.html().replace(/ mathquill-(?:command|block)-id="?\d+"?/g,"").replace(/<span class="?mq-cursor( mq-blink)?"?>.?<\/span>/i,"").replace(/ mq-hasCursor|mq-hasCursor ?/,"").replace(/ class=(""|(?= |>))/g,"")},t.reflow=function(){return this.__controller.root.postOrder("reflow"),this}}),n.prototype=r.prototype,s.EditableField=v(r,function(e,n){e.__mathquillify=function(){return n.__mathquillify.apply(this,arguments),this.__controller.editable=!0,this.__controller.delegateMouseEvents(),this.__controller.editablesTextareaEvents(),this},e.focus=function(){return this.__controller.textarea.focus(),this},e.blur=function(){return this.__controller.textarea.blur(),this},e.write=function(t){return this.__controller.writeLatex(t),this.__controller.scrollHoriz(),this.__controller.blurred&&this.__controller.cursor.hide().parent.blur(),this},e.cmd=function(t){var e,n=this.__controller.notify(),i=n.cursor;return/^\\[a-z]+$/i.test(t)?(t=t.slice(1),(e=x[t]||St[t])&&(t=e(t),i.selection&&t.replaces(i.replaceSelection()),t.createLeftOf(i.show()),this.__controller.scrollHoriz())):i.parent.write(i,t),n.blurred&&i.hide().parent.blur(),this},e.select=function(){var t=this.__controller;for(t.notify("move").cursor.insAtRightEnd(t.root);t.cursor[b];)t.selectLeft();return this},e.clearSelection=function(){return this.__controller.cursor.clearSelection(),this},e.moveToDirEnd=function(t){return this.__controller.notify("move").cursor.insAtDirEnd(t,this.__controller.root),this},e.moveToLeftEnd=function(){return this.moveToDirEnd(b)},e.moveToRightEnd=function(){return this.moveToDirEnd(w)},e.keystroke=function(e){var n;for(e=e.replace(/^\s+|\s+$/g,"").split(/\s+/),n=0;n<e.length;n+=1)this.__controller.keystroke(e[n],{preventDefault:t});return this},e.typedText=function(t){for(var e=0;e<t.length;e+=1)this.__controller.typedText(t.charAt(e));return this},e.dropEmbedded=function(t,e,n){var i,s=t-q(window).scrollLeft(),r=e-q(window).scrollTop(),o=document.elementFromPoint(s,r);this.__controller.seek(q(o),t,e),i=Qt().setOptions(n),i.createLeftOf(this.__controller.cursor)},e.clickAt=function(t,e,n){n=n||document.elementFromPoint(t,e);var i=this.__controller,s=i.root;return Lt.contains(s.jQ[0],n)||(n=s.jQ[0]),i.seek(q(n),t+pageXOffset,e+pageYOffset),i.blurred&&this.focus(),this},e.ignoreNextMousedown=function(t){return this.__controller.cursor.options.ignoreNextMousedown=t,this}}),n.EditableField=function(){throw"wtf don't call me, I'm 'abstract'"},n.EditableField.prototype=s.EditableField.prototype;for(o in C)!function(t,i){var r=s[t]=i(s);n[t]=function(i,s){var o,a=n(i);return a instanceof r||!i||!i.nodeType?a:(o=T(r.RootBlock(),q(i),D()),o.KIND_OF_MQ=t,r(o).__mathquillify(s,e))},n[t].prototype=r.prototype}(o,C[o]);return n}function h(t){var e,n="moveOutOf deleteOutOf selectOutOf upOutOf downOutOf".split(" ");for(e=0;e<n.length;e+=1)!function(e){t[e]=function(t){this.controller.handle(e,t)}}(n[e]);t.reflow=function(){this.controller.handle("reflow"),this.controller.handle("edited"),this.controller.handle("edit")}}function u(t){var e=this.parent,n=t;do{if(n[w])return t.insLeftOf(e);n=n.parent.parent}while(n!==e);t.insRightOf(e)}function f(t,e){t.jQadd=function(){e.jQadd.apply(this,arguments),this.delimjQs=this.jQ.children(":first").add(this.jQ.children(":last")),this.contentjQ=this.jQ.children(":eq(1)")},t.reflow=function(){var t=this.contentjQ.outerHeight()/parseFloat(this.contentjQ.css("fontSize"));ct(this.delimjQs,It(1+.2*(t-1),1.2),1.2*t)}}function p(t,e){var e=e||t,n=xt[t],s=xt[e];j[t]=i(Ot,b,t,n,e,s),j[n]=i(Ot,w,t,n,e,s)}var d,m,g,v,b,w,q,y,k,O,x,j,Q,S,T,C,D,_,E,L,A,z,I,M,R,B,F,N,$,P,V,W,U,H,G,K,Y,X,Z,J,tt,et,nt,it,st,rt,ot,at,ct,lt,ht,ut,ft,pt,dt,mt,gt,vt,bt,wt,qt,yt,kt,Ot,xt,jt,Qt,St,Tt,Ct,Dt,_t,Et,Lt=window.jQuery,At="mathquill-command-id",zt="mathquill-block-id",It=Math.min,Mt=Math.max;if(!Lt)throw"MathQuill requires jQuery 1.5.2+ to be loaded first";m=[].slice,g=e(function(t,n){return e(function(e,i){if(t in e)return e[t].apply(e,n.concat(i))})}),v=function(t,e,n){function i(t){return"object"==typeof t}function s(t){return"function"==typeof t}function r(){}return function t(n,o){function a(){var t=new c;return s(t.init)&&t.init.apply(t,arguments),t}function c(){}var l,h,u;return void 0===o&&(o=n,n=Object),a.Bare=c,l=r.prototype=n.prototype,h=c.prototype=a.prototype=a.p=new r,h.constructor=a,a.extend=function(e){return t(a,e)},(a.open=function(t){if(u={},s(t)?u=t.call(a,h,l,a,n):i(t)&&(u=t),i(u))for(var r in u)e.call(u,r)&&(h[r]=u[r]);return s(h.init)||(h.init=n),a})(o)}}(0,{}.hasOwnProperty),b=-1,w=1,q=v(Lt,function(t){t.insDirOf=function(t,e){return t===b?this.insertBefore(e.first()):this.insertAfter(e.last())},t.insAtDirEnd=function(t,e){return t===b?this.prependTo(e):this.appendTo(e)}}),y=v(function(t){t.parent=0,t[b]=0,t[w]=0,t.init=function(t,e,n){this.parent=t,this[b]=e,this[w]=n},this.copy=function(t){return y(t.parent,t[b],t[w])}}),k=v(function(t){function e(){return i+=1}t[b]=0,t[w]=0,t.parent=0;var i=0;this.byId={},t.init=function(){this.id=e(),k.byId[this.id]=this,this.ends={},this.ends[b]=0,this.ends[w]=0},t.dispose=function(){delete k.byId[this.id]},t.toString=function(){return"{{ MathQuill Node #"+this.id+" }}"},t.jQ=q(),t.jQadd=function(t){return this.jQ=this.jQ.add(t)},t.jQize=function(t){function e(t){var n,i;for(t.getAttribute&&(n=t.getAttribute("mathquill-command-id"),i=t.getAttribute("mathquill-block-id"),n&&k.byId[n].jQadd(t),i&&k.byId[i].jQadd(t)),t=t.firstChild;t;t=t.nextSibling)e(t)}var n;for(t=q(t||this.html()),n=0;n<t.length;n+=1)e(t[n]);return t},t.createDir=function(t,e){r(t);var n=this;return n.jQize(),n.jQ.insDirOf(t,e.jQ),e[t]=n.adopt(e.parent,e[b],e[w]),n},t.createLeftOf=function(t){return this.createDir(b,t)},t.selectChildren=function(t,e){return S(t,e)},t.bubble=n(function(t){var e;for(e=this;e&&!1!==t(e);e=e.parent);return this}),t.postOrder=n(function(t){return function e(n){n.eachChild(e),t(n)}(this),this}),t.isEmpty=function(){return 0===this.ends[b]&&0===this.ends[w]},t.isStyleBlock=function(){return!1},t.children=function(){return O(this.ends[b],this.ends[w])},t.eachChild=function(){var t=this.children();return t.each.apply(t,arguments),this},t.foldChildren=function(t,e){return this.children().fold(t,e)},t.withDirAdopt=function(t,e,n,i){return O(this,this).withDirAdopt(t,e,n,i),this},t.adopt=function(t,e,n){return O(this,this).adopt(t,e,n),this},t.disown=function(){return O(this,this).disown(),this},t.remove=function(){return this.jQ.remove(),this.postOrder("dispose"),this.disown()}}),O=v(function(t){t.init=function(t,e,n){if(n===d&&(n=b),r(n),s("no half-empty fragments",!t==!e),this.ends={},t){s("withDir is passed to Fragment",t instanceof k),s("oppDir is passed to Fragment",e instanceof k),s("withDir and oppDir have the same parent",t.parent===e.parent),this.ends[n]=t,this.ends[-n]=e;var i=this.fold([],function(t,e){return t.push.apply(t,e.jQ.get()),t});this.jQ=this.jQ.add(i)}},t.jQ=q(),t.withDirAdopt=function(t,e,n,i){return t===b?this.adopt(e,n,i):this.adopt(e,i,n)},t.adopt=function(t,e,n){var i,s,r;return o(t,e,n),i=this,i.disowned=!1,(s=i.ends[b])?(r=i.ends[w],e||(t.ends[b]=s),n?n[b]=r:t.ends[w]=r,i.ends[w][w]=n,i.each(function(n){n[b]=e,n.parent=t,e&&(e[w]=n),e=n}),i):this},t.disown=function(){var t,e,n=this,i=n.ends[b];return!i||n.disowned?n:(n.disowned=!0,t=n.ends[w],e=i.parent,o(e,i[b],i),o(e,t,t[w]),i[b]?i[b][w]=t[w]:e.ends[b]=t[w],t[w]?t[w][b]=i[b]:e.ends[w]=i[b],n)},t.remove=function(){return this.jQ.remove(),this.each("postOrder","dispose"),this.disown()},t.each=n(function(t){var e=this,n=e.ends[b];if(!n)return e;for(;n!==e.ends[w][w]&&!1!==t(n);n=n[w]);return e}),t.fold=function(t,e){return this.each(function(n){t=e.call(this,t,n)}),t}}),x={},j={},Q=v(y,function(t){t.init=function(t,e){this.parent=t,this.options=e;var n=this.jQ=this._jQ=q('<span class="mq-cursor">​</span>');this.blink=function(){n.toggleClass("mq-blink")},this.upDownCache={}},t.show=function(){return this.jQ=this._jQ.removeClass("mq-blink"),"intervalId"in this?clearInterval(this.intervalId):(this[w]?this.selection&&this.selection.ends[b][b]===this[b]?this.jQ.insertBefore(this.selection.jQ):this.jQ.insertBefore(this[w].jQ.first()):this.jQ.appendTo(this.parent.jQ),this.parent.focus()),this.intervalId=setInterval(this.blink,500),this},t.hide=function(){return"intervalId"in this&&clearInterval(this.intervalId),delete this.intervalId,this.jQ.detach(),this.jQ=q(),this},t.withDirInsertAt=function(t,e,n,i){var s=this.parent;this.parent=e,this[t]=n,this[-t]=i,s!==e&&s.blur&&s.blur(this)},t.insDirOf=function(t,e){return r(t),this.jQ.insDirOf(t,e.jQ),this.withDirInsertAt(t,e.parent,e[t],e),this.parent.jQ.addClass("mq-hasCursor"),this},t.insLeftOf=function(t){return this.insDirOf(b,t)},t.insRightOf=function(t){return this.insDirOf(w,t)},t.insAtDirEnd=function(t,e){return r(t),this.jQ.insAtDirEnd(t,e.jQ),this.withDirInsertAt(t,e,0,e.ends[t]),e.focus(),this},t.insAtLeftEnd=function(t){return this.insAtDirEnd(b,t)},t.insAtRightEnd=function(t){return this.insAtDirEnd(w,t)},t.jumpUpDown=function(t,e){var n,i,s=this;s.upDownCache[t.id]=y.copy(s),n=s.upDownCache[e.id],n?n[w]?s.insLeftOf(n[w]):s.insAtRightEnd(n.parent):(i=s.offset().left,e.seek(i,s))},t.offset=function(){var t=this,e=t.jQ.removeClass("mq-cursor").offset();return t.jQ.addClass("mq-cursor"),e},t.unwrapGramp=function(){var t=this.parent.parent,e=t.parent,n=t[w],i=this,s=t[b];if(t.disown().eachChild(function(i){i.isEmpty()||(i.children().adopt(e,s,n).each(function(e){e.jQ.insertBefore(t.jQ.first())}),s=i.ends[w])}),!this[w])if(this[b])this[w]=this[b][w];else for(;!this[w];){if(this.parent=this.parent[w],!this.parent){this[w]=t[w],this.parent=e;break}this[w]=this.parent.ends[b]}this[w]?this.insLeftOf(this[w]):this.insAtRightEnd(e),t.jQ.remove(),t[b].siblingDeleted&&t[b].siblingDeleted(i.options,w),t[w].siblingDeleted&&t[w].siblingDeleted(i.options,b)},t.startSelection=function(){var t,e=this.anticursor=y.copy(this),n=e.ancestors={};for(t=e;t.parent;t=t.parent)n[t.parent.id]=t},t.endSelection=function(){delete this.anticursor},t.select=function(){var t,e,n,i,r,o,a,c=this.anticursor;if(this[b]===c[b]&&this.parent===c.parent)return!1;for(t=this;t.parent;t=t.parent)if(t.parent.id in c.ancestors){e=t.parent;break}if(s("cursor and anticursor in the same tree",e),n=c.ancestors[e.id],o=w,t[b]!==n)for(a=t;a;a=a[w])if(a[w]===n[w]){o=b,i=t,r=n;break}return o===w&&(i=n,r=t),i instanceof y&&(i=i[w]),r instanceof y&&(r=r[b]),this.hide().selection=e.selectChildren(i,r),this.insDirOf(o,this.selection.ends[o]),this.selectionChanged(),!0},t.clearSelection=function(){return this.selection&&(this.selection.clear(),delete this.selection,this.selectionChanged()),this},t.deleteSelection=function(){this.selection&&(this[b]=this.selection.ends[b][b],this[w]=this.selection.ends[w][w],this.selection.remove(),this.selectionChanged(),delete this.selection)},t.replaceSelection=function(){var t=this.selection;return t&&(this[b]=t.ends[b][b],this[w]=t.ends[w][w],delete this.selection),t}}),S=v(O,function(t,e){t.init=function(){e.init.apply(this,arguments),this.jQ=this.jQ.wrapAll('<span class="mq-selection"></span>').parent()},t.adopt=function(){return this.jQ.replaceWith(this.jQ=this.jQ.children()),e.adopt.apply(this,arguments)},t.clear=function(){return this.jQ.replaceWith(this.jQ[0].childNodes),this},t.join=function(t){return this.fold("",function(e,n){return e+n[t]()})}}),T=v(function(t){t.init=function(t,e,n){this.id=t.id,this.data={},this.root=t,this.container=e,this.options=n,t.controller=this,this.cursor=t.cursor=Q(t,n)},t.handle=function(t,e){var n,i=this.options.handlers;i&&i.fns[t]&&(n=i.APIClasses[this.KIND_OF_MQ](this),e===b||e===w?i.fns[t](e,n):i.fns[t](n))};var e=[];this.onNotify=function(t){e.push(t)},t.notify=function(){for(var t=0;t<e.length;t+=1)e[t].apply(this.cursor,arguments);return this}}),C={},D=v(),_={},E=v(),L={},c.prototype=E.p,c.VERSION="v0.10.1",c.interfaceVersion=function(t){if(1!==t)throw"Only interface version 1 supported. You specified: "+t;return a=function(){window.console&&console.warn('You called MathQuill.interfaceVersion(1); to specify the interface version, which will fail in v1.0.0. You can fix this easily by doing this before doing anything else:\n\n MathQuill = MathQuill.getInterface(1);\n // now MathQuill.MathField() works like it used to\n\nSee also the "`dev` branch (2014–2015) → v0.10.0 Migration Guide" at\n https://github.com/mathquill/mathquill/wiki/%60dev%60-branch-(2014%E2%80%932015)-%E2%86%92-v0.10.0-Migration-Guide')},a(),c},c.getInterface=l,A=l.MIN=1,z=l.MAX=2,c.noConflict=function(){return window.MathQuill=I,c},I=window.MathQuill,window.MathQuill=c,M=function(){function e(t){var e,i=t.which||t.keyCode,s=n[i],r=[];return t.ctrlKey&&r.push("Ctrl"),t.originalEvent&&t.originalEvent.metaKey&&r.push("Meta"),t.altKey&&r.push("Alt"),t.shiftKey&&r.push("Shift"),e=s||String.fromCharCode(i),r.length||s?(r.push(e),r.join("-")):e}var n={8:"Backspace",9:"Tab",10:"Enter",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Esc",32:"Spacebar",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",45:"Insert",46:"Del",144:"NumLock"};return function(n,i){function s(t){k=t,clearTimeout(g),g=setTimeout(t)}function r(e){s(function(n){k=t,clearTimeout(g),e(n)})}function o(e){k(),k=t,clearTimeout(g),q.val(e),e&&q[0].select&&q[0].select(),v=!!e}function a(){var t=q[0];return"selectionStart"in t&&t.selectionStart!==t.selectionEnd}function c(){i.keystroke(e(b),b)}function l(t){b=t,w=null,v&&r(function(t){t&&"focusout"===t.type||!q[0].select||q[0].select()}),c()}function h(t){b&&w&&c(),w=t,s(f)}function u(t){b&&!w&&s(f)}function f(){if(!a()){var t=q.val();1===t.length?(q.val(""),i.typedText(t)):t&&q[0].select&&q[0].select()}}function p(){b=w=null}function d(t){q.focus(),s(m)}function m(){var t=q.val();q.val(""),t&&i.paste(t)}var g,v,b=null,w=null,q=Lt(n),y=Lt(i.container||q),k=t;return y.bind("keydown keypress input keyup focusout paste",function(t){k(t)}),v=!1,y.bind({keydown:l,keypress:h,keyup:u,focusout:p,cut:function(){r(function(){i.cut()})},copy:function(){r(function(){i.copy()})},paste:d}),{select:o}}}(),R=v(function(t,e,n){function i(t,e){throw t=t?"'"+t+"'":"EOF","Parse Error: "+e+" at "+t}var r,o,a;t.init=function(t){this._=t},t.parse=function(t){function e(t,e){return e}return this.skip(a)._(""+t,e,i)},t.or=function(t){s("or is passed a parser",t instanceof n);var e=this;return n(function(n,i,s){function r(e){return t._(n,i,s)}return e._(n,i,r)})},t.then=function(t){var e=this;return n(function(i,r,o){function a(e,i){var a=t instanceof n?t:t(i);return s("a parser is returned",a instanceof n),a._(e,r,o)}return e._(i,a,o)})},t.many=function(){var t=this;return n(function(e,n,i){function s(t,n){return e=t,o.push(n),!0}function r(){return!1}for(var o=[];t._(e,s,r););return n(e,o)})},t.times=function(t,e){arguments.length<2&&(e=t);var i=this;return n(function(n,s,r){function o(t,e){return u.push(e),n=t,!0}function a(t,e){return l=e,n=t,!1}function c(t,e){return!1}var l,h,u=[],f=!0;for(h=0;h<t;h+=1)if(!(f=i._(n,o,a)))return r(n,l);for(;h<e&&f;h+=1)f=i._(n,o,c);return s(n,u)})},t.result=function(t){return this.then(o(t))},t.atMost=function(t){return this.times(0,t)},t.atLeast=function(t){var e=this;return e.times(t).then(function(t){return e.many().map(function(e){return t.concat(e)})})},t.map=function(t){return this.then(function(e){return o(t(e))})},t.skip=function(t){return this.then(function(e){return t.result(e)})},this.string=function(t){var e=t.length,i="expected '"+t+"'";return n(function(n,s,r){var o=n.slice(0,e);return o===t?s(n.slice(e),o):r(n,i)})},r=this.regex=function(t){s("regexp parser is anchored","^"===t.toString().charAt(1));var e="expected "+t;return n(function(n,i,s){var r,o=t.exec(n);return o?(r=o[0],i(n.slice(r.length),r)):s(n,e)})},o=n.succeed=function(t){return n(function(e,n){return n(e,t)})},n.fail=function(t){return n(function(e,n,i){return i(e,t)})},n.letter=r(/^[a-z]/i),n.letters=r(/^[a-z]*/i),n.digit=r(/^[0-9]/),n.digits=r(/^[0-9]*/),n.whitespace=r(/^\s+/),n.optWhitespace=r(/^\s*/),n.any=n(function(t,e,n){return t?e(t.slice(1),t.charAt(0)):n(t,"expected any character")}),n.all=n(function(t,e,n){return e("",t)}),a=n.eof=n(function(t,e,n){return t?n(t,"expected EOF"):e(t,t)})}),T.open(function(t){t.focusBlurEvents=function(){function t(){clearTimeout(n),r.selection&&r.selection.jQ.addClass("mq-blur"),e()}function e(){r.hide().parent.blur(),i.container.removeClass("mq-focused"),q(window).unbind("blur",t)}var n,i=this,s=i.root,r=i.cursor;i.textarea.focus(function(){i.blurred=!1,clearTimeout(n),i.container.addClass("mq-focused"),r.parent||r.insAtRightEnd(s),r.selection?(r.selection.jQ.removeClass("mq-blur"),i.selectionChanged()):r.show()}).blur(function(){i.blurred=!0,n=setTimeout(function(){s.postOrder("intentionalBlur"),r.clearSelection().endSelection(),e()}),q(window).bind("blur",t)}),i.blurred=!0,r.hide().parent.blur()}}),T.open(function(t,e){t.exportText=function(){return this.root.foldChildren("",function(t,e){return t+e.text()})}}),T.open(function(e){D.p.ignoreNextMousedown=t,e.delegateMouseEvents=function(){var e=this.root.jQ;this.container.bind("mousedown.mathquill",function(n){function i(t){o=q(t.target)}function s(t){h.anticursor||h.startSelection(),l.seek(o,t.pageX,t.pageY).cursor.select(),o=d}function r(t){h.blink=u,h.selection||(l.editable?h.show():f.detach()),a.unbind("mousemove",i),q(t.target.ownerDocument).unbind("mousemove",s).unbind("mouseup",r)}var o,a=q(n.target).closest(".mq-root-block"),c=k.byId[a.attr(zt)||e.attr(zt)],l=c.controller,h=l.cursor,u=h.blink,f=l.textareaSpan,p=l.textarea;n.preventDefault(),n.target.unselectable=!0,h.options.ignoreNextMousedown(n)||(h.options.ignoreNextMousedown=t,l.blurred&&(l.editable||a.prepend(f),p.focus()),h.blink=t,l.seek(q(n.target),n.pageX,n.pageY).cursor.startSelection(),a.mousemove(i),q(n.target.ownerDocument).mousemove(s).mouseup(r))})}}),T.open(function(t){t.seek=function(t,e,n){var i,r,o,a=this.notify("select").cursor;return t&&((i=t.attr(zt)||t.attr(At))||(r=t.parent(),i=r.attr(zt)||r.attr(At))),o=i?k.byId[i]:this.root,s("nodeId is the id of some Node that exists",o),a.clearSelection().show(),o.seek(e,a),this.scrollHoriz(),this}}),T.open(function(t){t.keystroke=function(t,e){this.cursor.parent.keystroke(t,e,this)}}),k.open(function(t){t.keystroke=function(t,e,n){var i=n.cursor;switch(t){case"Ctrl-Shift-Backspace":case"Ctrl-Backspace":n.ctrlDeleteDir(b);break;case"Shift-Backspace":case"Backspace":n.backspace();break;case"Esc":case"Tab":return void n.escapeDir(w,t,e);case"Shift-Tab":case"Shift-Esc":return void n.escapeDir(b,t,e);case"End":n.notify("move").cursor.insAtRightEnd(i.parent);break;case"Ctrl-End":n.notify("move").cursor.insAtRightEnd(n.root);break;case"Shift-End":for(;i[w];)n.selectRight();break;case"Ctrl-Shift-End":for(;i[w]||i.parent!==n.root;)n.selectRight();break;case"Home":n.notify("move").cursor.insAtLeftEnd(i.parent);break;case"Ctrl-Home":n.notify("move").cursor.insAtLeftEnd(n.root);break;case"Shift-Home":for(;i[b];)n.selectLeft();break;case"Ctrl-Shift-Home":for(;i[b]||i.parent!==n.root;)n.selectLeft();break;case"Left":n.moveLeft();break;case"Shift-Left":n.selectLeft();break;case"Ctrl-Left":break;case"Right":n.moveRight();break;case"Shift-Right":n.selectRight();break;case"Ctrl-Right":break;case"Up":n.moveUp();break;case"Down":n.moveDown();break;case"Shift-Up":if(i[b])for(;i[b];)n.selectLeft();else n.selectLeft();case"Shift-Down":if(i[w])for(;i[w];)n.selectRight();else n.selectRight();case"Ctrl-Up":case"Ctrl-Down":break;case"Ctrl-Shift-Del":case"Ctrl-Del":n.ctrlDeleteDir(w);break;case"Shift-Del":case"Del":n.deleteForward();break;case"Meta-A":case"Ctrl-A":for(n.notify("move").cursor.insAtRightEnd(n.root);i[b];)n.selectLeft();break;default:return}e.preventDefault(),n.scrollHoriz()},t.moveOutOf=t.moveTowards=t.deleteOutOf=t.deleteTowards=t.unselectInto=t.selectOutOf=t.selectTowards=function(){s("overridden or never called on this node")}}),T.open(function(t){function e(t,e){var n=t.notify("upDown").cursor,i=e+"Into",s=e+"OutOf";return n[w][i]?n.insAtLeftEnd(n[w][i]):n[b][i]?n.insAtRightEnd(n[b][i]):n.parent.bubble(function(t){var e=t[s];if(e&&("function"==typeof e&&(e=t[s](n)),e instanceof k&&n.jumpUpDown(t,e),!0!==e))return!1}),t}this.onNotify(function(t){"move"!==t&&"upDown"!==t||this.show().clearSelection()}),t.escapeDir=function(t,e,n){r(t);var i=this.cursor;if(i.parent!==this.root&&n.preventDefault(),i.parent!==this.root)return i.parent.moveOutOf(t,i),this.notify("move")},_.leftRightIntoCmdGoes=function(t){if(t&&"up"!==t&&"down"!==t)throw'"up" or "down" required for leftRightIntoCmdGoes option, got "'+t+'"';return t},t.moveDir=function(t){r(t);var e=this.cursor,n=e.options.leftRightIntoCmdGoes;return e.selection?e.insDirOf(t,e.selection.ends[t]):e[t]?e[t].moveTowards(t,e,n):e.parent.moveOutOf(t,e,n),this.notify("move")},t.moveLeft=function(){return this.moveDir(b)},t.moveRight=function(){return this.moveDir(w)},t.moveUp=function(){return e(this,"up")},t.moveDown=function(){return e(this,"down")},this.onNotify(function(t){"upDown"!==t&&(this.upDownCache={})}),this.onNotify(function(t){"edit"===t&&this.show().deleteSelection()}),t.deleteDir=function(t){var e,n;return r(t),e=this.cursor,n=e.selection,this.notify("edit"),n||(e[t]?e[t].deleteTowards(t,e):e.parent.deleteOutOf(t,e)),e[b].siblingDeleted&&e[b].siblingDeleted(e.options,w),e[w].siblingDeleted&&e[w].siblingDeleted(e.options,b),e.parent.bubble("reflow"),this},t.ctrlDeleteDir=function(t){r(t);var e=this.cursor;return!e[b]||e.selection?this.deleteDir():(this.notify("edit"),O(e.parent.ends[b],e[b]).remove(),e.insAtDirEnd(b,e.parent),e[b].siblingDeleted&&e[b].siblingDeleted(e.options,w),e[w].siblingDeleted&&e[w].siblingDeleted(e.options,b),e.parent.bubble("reflow"),this)},t.backspace=function(){return this.deleteDir(b)},t.deleteForward=function(){return this.deleteDir(w)},this.onNotify(function(t){"select"!==t&&this.endSelection()}),t.selectDir=function(t){var e,n=this.notify("select").cursor,i=n.selection;r(t),n.anticursor||n.startSelection(),e=n[t],e?i&&i.ends[t]===e&&n.anticursor[-t]!==e?e.unselectInto(t,n):e.selectTowards(t,n):n.parent.selectOutOf(t,n),n.clearSelection(),n.select()||n.show()},t.selectLeft=function(){return this.selectDir(b)},t.selectRight=function(){return this.selectDir(w)}}),T.open(function(t){D.p.substituteTextarea=function(){return q("<textarea autocapitalize=off autocomplete=off autocorrect=off spellcheck=false x-palm-disable-ste-all=true />")[0]},t.createTextarea=function(){var t,e=this.textareaSpan=q('<span class="mq-textarea"></span>'),n=this.options.substituteTextarea();if(!n.nodeType)throw"substituteTextarea() must return a DOM element, got "+n;n=this.textarea=q(n).appendTo(e),t=this,t.cursor.selectionChanged=function(){t.selectionChanged()}},t.selectionChanged=function(){var t=this;lt(t.container[0]),t.textareaSelectionTimeout===d&&(t.textareaSelectionTimeout=setTimeout(function(){t.setTextareaSelection()}))},t.setTextareaSelection=function(){this.textareaSelectionTimeout=d;var t="";this.cursor.selection&&(t=this.cursor.selection.join("latex"),this.options.statelessClipboard&&(t="$"+t+"$")),this.selectFn(t)},t.staticMathTextareaEvents=function(){function t(){s.detach(),e.blurred=!0}var e=this,n=(e.root,e.cursor),i=e.textarea,s=e.textareaSpan;this.container.prepend(Lt('<span class="mq-selectable">').text("$"+e.exportLatex()+"$")),e.blurred=!0,i.bind("cut paste",!1).bind("copy",function(){e.setTextareaSelection()}).focus(function(){e.blurred=!1}).blur(function(){n.selection&&n.selection.clear(),setTimeout(t)}),e.selectFn=function(t){i.val(t),t&&i.select()}},D.p.substituteKeyboardEvents=M,t.editablesTextareaEvents=function(){var t=this,e=t.textarea,n=t.textareaSpan,i=this.options.substituteKeyboardEvents(e,this);this.selectFn=function(t){i.select(t)},this.container.prepend(n),this.focusBlurEvents()},t.typedText=function(t){if("\n"===t)return this.handle("enter");var e=this.notify().cursor;e.parent.write(e,t),this.scrollHoriz()},t.cut=function(){var t=this,e=t.cursor;e.selection&&setTimeout(function(){t.notify("edit"),e.parent.bubble("reflow")})},t.copy=function(){this.setTextareaSelection()},t.paste=function(t){this.options.statelessClipboard&&(t="$"===t.slice(0,1)&&"$"===t.slice(-1)?t.slice(1,-1):"\\text{"+t+"}"),this.writeLatex(t).cursor.show()}}),B=function(){function t(t){var e=W();return t.adopt(e,0,0),e}function e(t){var e,n=t[0]||W();for(e=1;e<t.length;e+=1)t[e].children().adopt(n,n.ends[w],0);return n}var n=R.string,i=R.regex,s=R.letter,r=R.any,o=R.optWhitespace,a=R.succeed,c=R.fail,l=s.map(function(t){return K(t)}),h=i(/^[^${}\\_^]/).map(function(t){return P(t)}),u=i(/^[^\\a-eg-zA-Z]/).or(n("\\").then(i(/^[a-z]+/i).or(i(/^\s+/).result(" ")).or(r))).then(function(t){var e=x[t];return e?e(t).parser():c("unknown command: \\"+t)}),f=u.or(l).or(h),p=n("{").then(function(){return m}).skip(n("}")),d=o.then(p.or(f.map(t))),m=d.many().map(e).skip(o),g=n("[").then(d.then(function(t){return"]"!==t.join("latex")?a(t):c()}).many().map(e).skip(o)).skip(n("]")),v=m;return v.block=d,v.optBlock=g,v}(),T.open(function(t,e){t.exportLatex=function(){return this.root.latex().replace(/(\\[a-z]+) (?![a-z])/gi,"$1")},t.writeLatex=function(t){var e,n=this.notify("edit").cursor,i=R.all,s=R.eof,r=B.skip(s).or(i.result(!1)).parse(t);return r&&!r.isEmpty()&&(r.children().adopt(n.parent,n[b],n[w]),e=r.jQize(),e.insertBefore(n.jQ),n[b]=r.ends[w],r.finalizeInsert(n.options,n),r.ends[w][w].siblingCreated&&r.ends[w][w].siblingCreated(n.options,b),r.ends[b][b].siblingCreated&&r.ends[b][b].siblingCreated(n.options,w),n.parent.bubble("reflow")),this},t.renderLatexMath=function(t){var e,n,i=this.root,s=this.cursor,r=R.all,o=R.eof,a=B.skip(o).or(r.result(!1)).parse(t);i.eachChild("postOrder","dispose"),i.ends[b]=i.ends[w]=0,a&&a.children().adopt(i,0,0),e=i.jQ,a?(n=a.join("html"),e.html(n),i.jQize(e.children()),i.finalizeInsert(s.options)):e.empty(),delete s.selection,s.insAtRightEnd(i)},t.renderLatexText=function(t){var e,n,i,s,r,o,a,c,l,h,u=this.root,f=this.cursor;if(u.jQ.children().slice(1).remove(),u.eachChild("postOrder","dispose"),u.ends[b]=u.ends[w]=0,delete f.selection,f.show().insAtRightEnd(u),e=R.regex,n=R.string,i=R.eof,s=R.all,r=n("$").then(B).skip(n("$").or(i)).map(function(t){var e,n=RootMathCommand(f);return n.createBlocks(),e=n.ends[b],t.children().adopt(e,0,0),n}),o=n("\\$").result("$"),a=o.or(e(/^[^$]/)).map(P),c=r.or(a).many(),l=c.skip(i).or(s.result(!1)).parse(t)){for(h=0;h<l.length;h+=1)l[h].adopt(u,u.ends[w],0);u.jQize().appendTo(u.jQ),u.finalizeInsert(f.options)}}}),T.open(function(t){t.scrollHoriz=function(){var t,e,n,i,s,r=this.cursor,o=r.selection,a=this.root.jQ[0].getBoundingClientRect();if(o)if(n=o.jQ[0].getBoundingClientRect(),i=n.left-(a.left+20),s=n.right-(a.right-20),o.ends[b]===r[w])if(i<0)e=i;else{if(!(s>0))return;e=n.left-s<a.left+20?i:s}else if(s>0)e=s;else{if(!(i<0))return;e=n.right-i>a.right-20?s:i}else if((t=r.jQ[0].getBoundingClientRect().left)>a.right-20)e=t-(a.right-20);else{if(!(t<a.left+20))return;e=t-(a.left+20)}this.root.jQ.stop().animate({scrollLeft:"+="+e},100)}}),F=v(k,function(t,e){t.finalizeInsert=function(t,e){var n=this;n.postOrder("finalizeTree",t),n.postOrder("contactWeld",e),n.postOrder("blur"),n.postOrder("reflow"),n[w].siblingCreated&&n[w].siblingCreated(t,b),n[b].siblingCreated&&n[b].siblingCreated(t,w),n.bubble("reflow")}}),N=v(F,function(t,e){t.init=function(t,n,i){var s=this;e.init.call(s),s.ctrlSeq||(s.ctrlSeq=t),n&&(s.htmlTemplate=n),i&&(s.textTemplate=i)},t.replaces=function(t){t.disown(),this.replacedFragment=t},t.isEmpty=function(){return this.foldChildren(!0,function(t,e){return t&&e.isEmpty()})},t.parser=function(){var t=B.block,e=this;return t.times(e.numBlocks()).map(function(t){e.blocks=t;for(var n=0;n<t.length;n+=1)t[n].adopt(e,e.ends[w],0);return e})},t.createLeftOf=function(t){var n=this,i=n.replacedFragment;n.createBlocks(),e.createLeftOf.call(n,t),i&&(i.adopt(n.ends[b],0,0),i.jQ.appendTo(n.ends[b].jQ)),n.finalizeInsert(t.options),n.placeCursor(t)},t.createBlocks=function(){var t,e,n=this,i=n.numBlocks(),s=n.blocks=Array(i);for(t=0;t<i;t+=1)e=s[t]=W(),e.adopt(n,n.ends[w],0)},t.placeCursor=function(t){t.insAtRightEnd(this.foldChildren(this.ends[b],function(t,e){return t.isEmpty()?t:e}))},t.moveTowards=function(t,e,n){var i=n&&this[n+"Into"];e.insAtDirEnd(-t,i||this.ends[-t])},t.deleteTowards=function(t,e){this.isEmpty()?e[t]=this.remove()[t]:this.moveTowards(t,e,null)},t.selectTowards=function(t,e){e[-t]=this,e[t]=this[t]},t.selectChildren=function(){return S(this,this)},t.unselectInto=function(t,e){e.insAtDirEnd(-t,e.anticursor.ancestors[this.id])},t.seek=function(t,e){function n(t){var e={};return e[b]=t.jQ.offset().left,e[w]=e[b]+t.jQ.outerWidth(),e}var i,s=this,r=n(s);return t<r[b]?e.insLeftOf(s):t>r[w]?e.insRightOf(s):(i=r[b],void s.eachChild(function(o){var a=n(o);return t<a[b]?(t-i<a[b]-t?o[b]?e.insAtRightEnd(o[b]):e.insLeftOf(s):e.insAtLeftEnd(o),!1):t>a[w]?void(o[w]?i=a[w]:r[w]-t<t-a[w]?e.insRightOf(s):e.insAtRightEnd(o)):(o.seek(t,e),!1)}))},t.numBlocks=function(){var t=this.htmlTemplate.match(/&\d+/g)
;return t?t.length:0},t.html=function(){var t,e,n,i=this,r=i.blocks,o=" mathquill-command-id="+i.id,a=i.htmlTemplate.match(/<[^<>]+>|[^<>]+/g);for(s("no unmatched angle brackets",a.join("")===this.htmlTemplate),t=0,e=a[0];e;t+=1,e=a[t])if("/>"===e.slice(-2))a[t]=e.slice(0,-2)+o+"/>";else if("<"===e.charAt(0)){s("not an unmatched top-level close tag","/"!==e.charAt(1)),a[t]=e.slice(0,-1)+o+">",n=1;do{t+=1,e=a[t],s("no missing close tags",e),"</"===e.slice(0,2)?n-=1:"<"===e.charAt(0)&&"/>"!==e.slice(-2)&&(n+=1)}while(n>0)}return a.join("").replace(/>&(\d+)/g,function(t,e){return" mathquill-block-id="+r[e].id+">"+r[e].join("html")})},t.latex=function(){return this.foldChildren(this.ctrlSeq,function(t,e){return t+"{"+(e.latex()||" ")+"}"})},t.textTemplate=[""],t.text=function(){var t=this,e=0;return t.foldChildren(t.textTemplate[e],function(n,i){e+=1;var s=i.text();return n&&"("===t.textTemplate[e]&&"("===s[0]&&")"===s.slice(-1)?n+s.slice(1,-1)+t.textTemplate[e]:n+i.text()+(t.textTemplate[e]||"")})}}),$=v(N,function(e,n){e.init=function(t,e,i){i||(i=t&&t.length>1?t.slice(1):t),n.init.call(this,t,e,[i])},e.parser=function(){return R.succeed(this)},e.numBlocks=function(){return 0},e.replaces=function(t){t.remove()},e.createBlocks=t,e.moveTowards=function(t,e){e.jQ.insDirOf(t,this.jQ),e[-t]=this,e[t]=this[t]},e.deleteTowards=function(t,e){e[t]=this.remove()[t]},e.seek=function(t,e){t-this.jQ.offset().left<this.jQ.outerWidth()/2?e.insLeftOf(this):e.insRightOf(this)},e.latex=function(){return this.ctrlSeq},e.text=function(){return this.textTemplate},e.placeCursor=t,e.isEmpty=function(){return!0}}),P=v($,function(t,e){t.init=function(t,n){e.init.call(this,t,"<span>"+(n||t)+"</span>")}}),V=v($,function(t,e){t.init=function(t,n,i){e.init.call(this,t,'<span class="mq-binary-operator">'+n+"</span>",i)}}),W=v(F,function(t,e){t.join=function(t){return this.foldChildren("",function(e,n){return e+n[t]()})},t.html=function(){return this.join("html")},t.latex=function(){return this.join("latex")},t.text=function(){return this.ends[b]===this.ends[w]&&0!==this.ends[b]?this.ends[b].text():this.join("text")},t.keystroke=function(t,n,i){return!i.options.spaceBehavesLikeTab||"Spacebar"!==t&&"Shift-Spacebar"!==t?e.keystroke.apply(this,arguments):(n.preventDefault(),void i.escapeDir("Shift-Spacebar"===t?b:w,t,n))},t.moveOutOf=function(t,e,n){n&&this.parent[n+"Into"]||!this[t]?e.insDirOf(t,this.parent):e.insAtDirEnd(-t,this[t])},t.selectOutOf=function(t,e){e.insDirOf(t,this.parent)},t.deleteOutOf=function(t,e){e.unwrapGramp()},t.seek=function(t,e){var n=this.ends[w];if(!n||n.jQ.offset().left+n.jQ.outerWidth()<t)return e.insAtRightEnd(this);if(t<this.ends[b].jQ.offset().left)return e.insAtLeftEnd(this);for(;t<n.jQ.offset().left;)n=n[b];return n.seek(t,e)},t.chToCmd=function(t,e){var n;return t.match(/^[a-eg-zA-Z]$/)?K(t):/^\d$/.test(t)?H(t):e&&e.typingSlashWritesDivisionSymbol&&"/"===t?x["÷"](t):e&&e.typingAsteriskWritesTimesSymbol&&"*"===t?x["×"](t):(n=j[t]||x[t])?n(t):P(t)},t.write=function(t,e){var n=this.chToCmd(e,t.options);t.selection&&n.replaces(t.replaceSelection()),n.createLeftOf(t.show())},t.focus=function(){return this.jQ.addClass("mq-hasCursor"),this.jQ.removeClass("mq-empty"),this},t.blur=function(){return this.jQ.removeClass("mq-hasCursor"),this.isEmpty()&&this.jQ.addClass("mq-empty"),this}}),C.StaticMath=function(t){return v(t.AbstractMathQuill,function(e,n){this.RootBlock=W,e.__mathquillify=function(t,e){return this.config(t),n.__mathquillify.call(this,"mq-math-mode"),this.__controller.delegateMouseEvents(),this.__controller.staticMathTextareaEvents(),this},e.init=function(){n.init.apply(this,arguments),this.__controller.root.postOrder("registerInnerField",this.innerFields=[],t.MathField)},e.latex=function(){var e=n.latex.apply(this,arguments);return arguments.length>0&&this.__controller.root.postOrder("registerInnerField",this.innerFields=[],t.MathField),e}})},U=v(W,h),C.MathField=function(e){return v(e.EditableField,function(e,n){this.RootBlock=U,e.__mathquillify=function(e,i){return this.config(e),i>1&&(this.__controller.root.reflow=t),n.__mathquillify.call(this,"mq-editable-field mq-math-mode"),delete this.__controller.root.reflow,this}})},H=v(P,function(t,e){t.createLeftOf=function(t){t.options.autoSubscriptNumerals&&t.parent!==t.parent.parent.sub&&(t[b]instanceof G&&!1!==t[b].isItalic||t[b]instanceof gt&&t[b][b]instanceof G&&!1!==t[b][b].isItalic)?(x._().createLeftOf(t),e.createLeftOf.call(this,t),t.insRightOf(t.parent.parent)):e.createLeftOf.call(this,t)}}),G=v($,function(t,e){t.init=function(t,n){e.init.call(this,t,"<var>"+(n||t)+"</var>")},t.text=function(){var t=this.ctrlSeq;return this.isPartOfOperator?"\\"==t[0]?t=t.slice(1,t.length):" "==t[t.length-1]&&(t=t.slice(0,-1)):(!this[b]||this[b]instanceof G||this[b]instanceof V||"\\ "===this[b].ctrlSeq||(t="*"+t),!this[w]||this[w]instanceof V||this[w]instanceof gt||(t+="*")),t}}),D.p.autoCommands={_maxLength:0},_.autoCommands=function(t){var e,n,i,s,r;if(!/^[a-z]+(?: [a-z]+)*$/i.test(t))throw'"'+t+'" not a space-delimited list of only letters';for(e=t.split(" "),n={},i=0,s=0;s<e.length;s+=1){if(r=e[s],r.length<2)throw'autocommand "'+r+'" not minimum length of 2';if(x[r]===J)throw'"'+r+'" is a built-in operator name';n[r]=1,i=Mt(i,r.length)}return n._maxLength=i,n},K=v(G,function(t,e){function n(t){return!t||t instanceof V||t instanceof vt}t.init=function(t){return e.init.call(this,this.letter=t)},t.createLeftOf=function(t){var n,i,s,r,o;if(e.createLeftOf.apply(this,arguments),n=t.options.autoCommands,i=n._maxLength,i>0){for(s="",r=this,o=0;r instanceof K&&r.ctrlSeq===r.letter&&o<i;)s=r.letter+s,r=r[b],o+=1;for(;s.length;){if(n.hasOwnProperty(s)){for(o=1,r=this;o<s.length;o+=1,r=r[b]);return O(r,this).remove(),t[b]=r[b],x[s](s).createLeftOf(t)}s=s.slice(1)}}},t.italicize=function(t){return this.isItalic=t,this.isPartOfOperator=!t,this.jQ.toggleClass("mq-operator-name",!t),this},t.finalizeTree=t.siblingDeleted=t.siblingCreated=function(t,e){e!==b&&this[w]instanceof K||this.autoUnItalicize(t)},t.autoUnItalicize=function(t){var e,i,s,r,o,a,c,l,h,u,f,p,d=t.autoOperatorNames;if(0!==d._maxLength){for(e=this.letter,i=this[b];i instanceof K;i=i[b])e=i.letter+e;for(s=this[w];s instanceof K;s=s[w])e+=s.letter;O(i[w]||this.parent.ends[b],s[b]||this.parent.ends[w]).each(function(t){t.italicize(!0).jQ.removeClass("mq-first mq-last mq-followed-by-supsub"),t.ctrlSeq=t.letter});t:for(r=0,o=i[w]||this.parent.ends[b];r<e.length;r+=1,o=o[w])for(a=It(d._maxLength,e.length-r);a>0;a-=1)if(c=e.slice(r,r+a),d.hasOwnProperty(c)){for(l=0,h=o;l<a;l+=1,h=h[w])h.italicize(!1),u=h;f=Y.hasOwnProperty(c),o.ctrlSeq=(f?"\\":"\\operatorname{")+o.ctrlSeq,u.ctrlSeq+=f?" ":"}",Z.hasOwnProperty(c)&&u[b][b][b].jQ.addClass("mq-last"),n(o[b])||o.jQ.addClass("mq-first"),n(u[w])||(u[w]instanceof gt?(p=u[w],(p.siblingCreated=p.siblingDeleted=function(){p.jQ.toggleClass("mq-after-operator-name",!(p[w]instanceof Ot))})()):u.jQ.toggleClass("mq-last",!(u[w]instanceof Ot))),r+=a-1,o=u;continue t}}}}),Y={},X=D.p.autoOperatorNames={_maxLength:9},Z={limsup:1,liminf:1,projlim:1,injlim:1},function(){var t,e,n,i,s="arg deg det dim exp gcd hom inf ker lg lim ln log max min sup limsup liminf injlim projlim Pr".split(" ");for(t=0;t<s.length;t+=1)Y[s[t]]=X[s[t]]=1;for(e="sin cos tan arcsin arccos arctan sinh cosh tanh sec csc cot coth".split(" "),t=0;t<e.length;t+=1)Y[e[t]]=1;for(n="sin cos tan sec cosec csc cotan cot ctg".split(" "),t=0;t<n.length;t+=1)X[n[t]]=X["arc"+n[t]]=X[n[t]+"h"]=X["ar"+n[t]+"h"]=X["arc"+n[t]+"h"]=1;for(i="gcf hcf lcm proj span".split(" "),t=0;t<i.length;t+=1)X[i[t]]=1}(),_.autoOperatorNames=function(t){var e,n,i,s,r;if(!/^[a-z]+(?: [a-z]+)*$/i.test(t))throw'"'+t+'" not a space-delimited list of only letters';for(e=t.split(" "),n={},i=0,s=0;s<e.length;s+=1){if(r=e[s],r.length<2)throw'"'+r+'" not minimum length of 2';n[r]=1,i=Mt(i,r.length)}return n._maxLength=i,n},J=v($,function(t,e){t.init=function(t){this.ctrlSeq=t},t.createLeftOf=function(t){var e,n=this.ctrlSeq;for(e=0;e<n.length;e+=1)K(n.charAt(e)).createLeftOf(t)},t.parser=function(){var t,e=this.ctrlSeq,n=W();for(t=0;t<e.length;t+=1)K(e.charAt(t)).adopt(n,n.ends[w],0);return R.succeed(n.children())}});for(tt in X)X.hasOwnProperty(tt)&&(x[tt]=J);x.operatorname=v(N,function(e){e.createLeftOf=t,e.numBlocks=function(){return 1},e.parser=function(){return B.block.map(function(t){return t.children()})}}),x.f=v(K,function(t,e){t.init=function(){$.p.init.call(this,this.letter="f",'<var class="mq-f">f</var>')},t.italicize=function(t){return this.jQ.html("f").toggleClass("mq-f",t),e.italicize.apply(this,arguments)}}),x[" "]=x.space=i(P,"\\ "," "),x["'"]=x.prime=i(P,"'","′"),x["″"]=x.dprime=i(P,"″","″"),x.backslash=i(P,"\\backslash ","\\"),j["\\"]||(j["\\"]=x.backslash),x.$=i(P,"\\$","$"),et=v($,function(t,e){t.init=function(t,n){e.init.call(this,t,'<span class="mq-nonSymbola">'+(n||t)+"</span>")}}),x["@"]=et,x["&"]=i(et,"\\&","&"),x["%"]=i(et,"\\%","%"),x.alpha=x.beta=x.gamma=x.delta=x.zeta=x.eta=x.theta=x.iota=x.kappa=x.mu=x.nu=x.xi=x.rho=x.sigma=x.tau=x.chi=x.psi=x.omega=v(G,function(t,e){t.init=function(t){e.init.call(this,"\\"+t+" ","&"+t+";")}}),x.phi=i(G,"\\phi ","ϕ"),x.phiv=x.varphi=i(G,"\\varphi ","φ"),x.epsilon=i(G,"\\epsilon ","ϵ"),x.epsiv=x.varepsilon=i(G,"\\varepsilon ","ε"),x.piv=x.varpi=i(G,"\\varpi ","ϖ"),x.sigmaf=x.sigmav=x.varsigma=i(G,"\\varsigma ","ς"),x.thetav=x.vartheta=x.thetasym=i(G,"\\vartheta ","ϑ"),x.upsilon=x.upsi=i(G,"\\upsilon ","υ"),x.gammad=x.Gammad=x.digamma=i(G,"\\digamma ","ϝ"),x.kappav=x.varkappa=i(G,"\\varkappa ","ϰ"),x.rhov=x.varrho=i(G,"\\varrho ","ϱ"),x.pi=x["π"]=i(et,"\\pi ","π"),x.lambda=i(et,"\\lambda ","λ"),x.Upsilon=x.Upsi=x.upsih=x.Upsih=i($,"\\Upsilon ",'<var style="font-family: serif">ϒ</var>'),x.Gamma=x.Delta=x.Theta=x.Lambda=x.Xi=x.Pi=x.Sigma=x.Phi=x.Psi=x.Omega=x.forall=v(P,function(t,e){t.init=function(t){e.init.call(this,"\\"+t+" ","&"+t+";")}}),nt=v(N,function(t){t.init=function(t){this.latex=t},t.createLeftOf=function(t){var e=B.parse(this.latex);e.children().adopt(t.parent,t[b],t[w]),t[b]=e.ends[w],e.jQize().insertBefore(t.jQ),e.finalizeInsert(t.options,t),e.ends[w][w].siblingCreated&&e.ends[w][w].siblingCreated(t.options,b),e.ends[b][b].siblingCreated&&e.ends[b][b].siblingCreated(t.options,w),t.parent.bubble("reflow")},t.parser=function(){var t=B.parse(this.latex).children();return R.succeed(t)}}),x["¹"]=i(nt,"^1"),x["²"]=i(nt,"^2"),x["³"]=i(nt,"^3"),x["¼"]=i(nt,"\\frac14"),x["½"]=i(nt,"\\frac12"),x["¾"]=i(nt,"\\frac34"),it=v(V,function(t){t.init=P.prototype.init,t.contactWeld=t.siblingCreated=t.siblingDeleted=function(t,e){function n(t){return t[b]?t[b]instanceof V||/^[,;:\(\[]$/.test(t[b].ctrlSeq)?"":"mq-binary-operator":t.parent&&t.parent.parent&&t.parent.parent.isStyleBlock()?n(t.parent.parent):""}if(e!==w)return this.jQ[0].className=n(this),this}}),x["+"]=i(it,"+","+"),x["–"]=x["-"]=i(it,"-","−"),x["±"]=x.pm=x.plusmn=x.plusminus=i(it,"\\pm ","±"),x.mp=x.mnplus=x.minusplus=i(it,"\\mp ","∓"),j["*"]=x.sdot=x.cdot=i(V,"\\cdot ","·","*"),st=v(V,function(t,e){t.init=function(t,n){this.data=t,this.strict=n;var i=n?"Strict":"";e.init.call(this,t["ctrlSeq"+i],t["html"+i],t["text"+i])},t.swap=function(t){this.strict=t;var e=t?"Strict":"";this.ctrlSeq=this.data["ctrlSeq"+e],this.jQ.html(this.data["html"+e]),this.textTemplate=[this.data["text"+e]]},t.deleteTowards=function(t,n){if(t===b&&!this.strict)return this.swap(!0),void this.bubble("reflow");e.deleteTowards.apply(this,arguments)}}),rt={ctrlSeq:"\\le ",html:"≤",text:"≤",ctrlSeqStrict:"<",htmlStrict:"<",textStrict:"<"},ot={ctrlSeq:"\\ge ",html:"≥",text:"≥",ctrlSeqStrict:">",htmlStrict:">",textStrict:">"},x["<"]=x.lt=i(st,rt,!0),x[">"]=x.gt=i(st,ot,!0),x["≤"]=x.le=x.leq=i(st,rt,!1),x["≥"]=x.ge=x.geq=i(st,ot,!1),at=v(V,function(t,e){t.init=function(){e.init.call(this,"=","=")},t.createLeftOf=function(t){if(t[b]instanceof st&&t[b].strict)return t[b].swap(!1),void t[b].bubble("reflow");e.createLeftOf.apply(this,arguments)}}),x["="]=at,x["×"]=x.times=i(V,"\\times ","×","[x]"),x["÷"]=x.div=x.divide=x.divides=i(V,"\\div ","÷","[/]"),j["~"]=x.sim=i(V,"\\sim ","~","~"),lt=t,ht=document.createElement("div"),ut=ht.style,ft={transform:1,WebkitTransform:1,MozTransform:1,OTransform:1,msTransform:1};for(dt in ft)if(dt in ut){pt=dt;break}pt?ct=function(t,e,n){t.css(pt,"scale("+e+","+n+")")}:"filter"in ut?(lt=function(t){t.className=t.className},ct=function(t,e,n){function i(){t.css("marginRight",(s.width()-1)*(e-1)/e+"px")}var s,r;e/=1+(n-1)/2,t.css("fontSize",n+"em"),t.hasClass("mq-matrixed-container")||t.addClass("mq-matrixed-container").wrapInner('<span class="mq-matrixed"></span>'),s=t.children().css("filter","progid:DXImageTransform.Microsoft.Matrix(M11="+e+",SizingMethod='auto expand')"),i(),r=setInterval(i),q(window).load(function(){clearTimeout(r),i()})}):ct=function(t,e,n){t.css("fontSize",n+"em")},mt=v(N,function(t,e){t.init=function(t,n,i){e.init.call(this,t,"<"+n+" "+i+">&0</"+n+">")}}),x.mathrm=i(mt,"\\mathrm","span",'class="mq-roman mq-font"'),x.mathit=i(mt,"\\mathit","i",'class="mq-font"'),x.mathbf=i(mt,"\\mathbf","b",'class="mq-font"'),x.mathsf=i(mt,"\\mathsf","span",'class="mq-sans-serif mq-font"'),x.mathtt=i(mt,"\\mathtt","span",'class="mq-monospace mq-font"'),x.underline=i(mt,"\\underline","span",'class="mq-non-leaf mq-underline"'),x.overline=x.bar=i(mt,"\\overline","span",'class="mq-non-leaf mq-overline"'),x.overrightarrow=i(mt,"\\overrightarrow","span",'class="mq-non-leaf mq-overarrow mq-arrow-right"'),x.overleftarrow=i(mt,"\\overleftarrow","span",'class="mq-non-leaf mq-overarrow mq-arrow-left"'),x.dot=v(N,function(t,e){t.init=function(){e.init.call(this,"\\dot",'<span class="mq-non-leaf"><span class="mq-dot-recurring-inner"><span class="mq-dot-recurring">˙</span><span class="mq-empty-box">&0</span></span></span>')}}),x.textcolor=v(N,function(t,e){t.setColor=function(t){this.color=t,this.htmlTemplate='<span class="mq-textcolor" style="color:'+t+'">&0</span>'},t.latex=function(){return"\\textcolor{"+this.color+"}{"+this.blocks[0].latex()+"}"},t.parser=function(){var t=this,n=R.optWhitespace,i=R.string,s=R.regex;return n.then(i("{")).then(s(/^[#\w\s.,()%-]*/)).skip(i("}")).then(function(n){return t.setColor(n),e.parser.call(t)})},t.isStyleBlock=function(){return!0}}),x.class=v(N,function(t,e){t.parser=function(){var t=this,n=R.string,i=R.regex;return R.optWhitespace.then(n("{")).then(i(/^[-\w\s\\\xA0-\xFF]*/)).skip(n("}")).then(function(n){return t.cls=n||"",t.htmlTemplate='<span class="mq-class '+n+'">&0</span>',e.parser.call(t)})},t.latex=function(){return"\\class{"+this.cls+"}{"+this.blocks[0].latex()+"}"},t.isStyleBlock=function(){return!0}}),gt=v(N,function(t,e){t.ctrlSeq="_{...}^{...}",t.createLeftOf=function(t){if(this.replacedFragment||t[b]||!t.options.supSubsRequireOperand)return e.createLeftOf.apply(this,arguments)},t.contactWeld=function(t){var e,n,i,s,r,o;for(e=b;e;e=e===b&&w)if(this[e]instanceof gt){for(n="sub";n;n="sub"===n&&"sup")i=this[n],s=this[e][n],i&&(s?i.isEmpty()?o=y(s,0,s.ends[b]):(i.jQ.children().insAtDirEnd(-e,s.jQ),r=i.children().disown(),o=y(s,r.ends[w],s.ends[b]),e===b?r.adopt(s,s.ends[w],0):r.adopt(s,0,s.ends[b])):this[e].addBlock(i.disown()),this.placeCursor=function(t,n){return function(i){i.insAtDirEnd(-e,t||n)}}(s,i));this.remove(),t&&t[b]===this&&(e===w&&o?o[b]?t.insRightOf(o[b]):t.insAtLeftEnd(o.parent):t.insRightOf(this[e]));break}},D.p.charsThatBreakOutOfSupSub="",t.finalizeTree=function(){this.ends[b].write=function(t,e){if(t.options.autoSubscriptNumerals&&this===this.parent.sub){if("_"===e)return;var n=this.chToCmd(e,t.options);return n instanceof $?t.deleteSelection():t.clearSelection().insRightOf(this.parent),n.createLeftOf(t.show())}t[b]&&!t[w]&&!t.selection&&t.options.charsThatBreakOutOfSupSub.indexOf(e)>-1&&t.insRightOf(this.parent),W.p.write.apply(this,arguments)}},t.moveTowards=function(t,n,i){n.options.autoSubscriptNumerals&&!this.sup?n.insDirOf(t,this):e.moveTowards.apply(this,arguments)},t.deleteTowards=function(t,n){if(n.options.autoSubscriptNumerals&&this.sub){var i=this.sub.ends[-t];i instanceof $?i.remove():i&&i.deleteTowards(t,n.insAtDirEnd(-t,this.sub)),this.sub.isEmpty()&&(this.sub.deleteOutOf(b,n.insAtLeftEnd(this.sub)),this.sup&&n.insDirOf(-t,this))}else e.deleteTowards.apply(this,arguments)},t.latex=function(){function t(t,e){var n=e&&e.latex();return e?t+(1===n.length?n:"{"+(n||" ")+"}"):""}return t("_",this.sub)+t("^",this.sup)},t.addBlock=function(t){"sub"===this.supsub?(this.sup=this.upInto=this.sub.upOutOf=t,t.adopt(this,this.sub,0).downOutOf=this.sub,t.jQ=q('<span class="mq-sup"/>').append(t.jQ.children()).attr(zt,t.id).prependTo(this.jQ)):(this.sub=this.downInto=this.sup.downOutOf=t,t.adopt(this,0,this.sup).upOutOf=this.sup,t.jQ=q('<span class="mq-sub"></span>').append(t.jQ.children()).attr(zt,t.id).appendTo(this.jQ.removeClass("mq-sup-only")),this.jQ.append('<span style="display:inline-block;width:0">​</span>'));for(var e=0;e<2;e+=1)!function(t,e,n,i){t[e].deleteOutOf=function(s,r){if(r.insDirOf(this[s]?-s:s,this.parent),!this.isEmpty()){var o=this.ends[s];this.children().disown().withDirAdopt(s,r.parent,r[s],r[-s]).jQ.insDirOf(-s,r.jQ),r[-s]=o}t.supsub=n,delete t[e],delete t[i+"Into"],t[n][i+"OutOf"]=u,delete t[n].deleteOutOf,"sub"===e&&q(t.jQ.addClass("mq-sup-only")[0].lastChild).remove(),this.remove()}}(this,"sub sup".split(" ")[e],"sup sub".split(" ")[e],"down up".split(" ")[e])}}),x.subscript=x._=v(gt,function(t,e){t.supsub="sub",t.htmlTemplate='<spa