13 lines
72 KiB
JavaScript
13 lines
72 KiB
JavaScript
|
/**
|
|||
|
* MathQuill v0.10.1 http://mathquill.com
|
|||
|
* by Han, Jeanine, and Mary 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=kt.call(arguments,0,e),i=kt.call(arguments,e);return t.apply(this,n.concat([i]))}}function n(t){return e(function(e,n){"function"!=typeof e&&(e=jt(e));var i=function(t){return e.apply(t,[t].concat(n))};return t.call(this,i)})}function i(t){var e=kt.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===Tt||t===Ct)}function o(t,e,n){s("a parent is always present",t),s("leftward is properly set up",function(){return e?e[Ct]===n&&e.parent===t:t.ends[Tt]===n}()),s("rightward is properly set up",function(){return n?n[Tt]===e&&n.parent===t:t.ends[Ct]===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. 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')}function l(t){return a(),bt(t)}function c(e){function n(t){var e,n;return t&&t.nodeType?(e=Dt(t).children(".mq-root-block").attr(xt),n=e&&St.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=Ft[n],t[n]=r?r(i):i)}var s,r,o;if(!(e>=g&&b>=e))throw"Only interface versions between "+g+" and "+b+" supported. You specified: "+e;s={},n.L=Tt,n.R=Ct,n.config=function(t){return i(Bt.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";Nt[t]=e},r=s.AbstractMathQuill=Qt($t,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=Dt('<span class="mq-root-block"/>').attr(xt,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=Qt(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=Et[t],e&&(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[Tt];)t.selectLeft();return this},e.clearSelection=f
|
|||
|
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]||"")})}}),k=Qt(O,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 w.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}}),j=Qt(k,function(t,e){t.init=function(t,n){e.init.call(this,t,"<span>"+(n||t)+"</span>")}}),Q=Qt(k,function(t,e){t.init=function(t,n,i){e.init.call(this,t,'<span class="mq-binary-operator">'+n+"</span>",i)}}),T=Qt(y,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[Tt]===this.ends[Ct]&&0!==this.ends[Tt]?this.ends[Tt].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?Tt:Ct,t,n))},t.moveOutOf=function(t,e,n){var i=n&&this.parent[n+"Into"];!i&&this[t]?e.insAtDirEnd(-t,this[t]):e.insDirOf(t,this.parent)},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[Ct];if(!n||n.jQ.offset().left+n.jQ.outerWidth()<t)return e.insAtRightEnd(this);if(t<this.ends[Tt].jQ.offset().left)return e.insAtLeftEnd(this);for(;t<n.jQ.offset().left;)n=n[Tt];return n.seek(t,e)},t.chToCmd=function(t){var e;return t.match(/^[a-eg-zA-Z]$/)?I(t):/^\d$/.test(t)?A(t):(e=At[t]||Et[t])?e(t):j(t)},t.write=function(t,e){var n=this.chToCmd(e);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}}),Mt.StaticMath=function(t){return Qt(t.AbstractMathQuill,function(e,n){this.RootBlock=T,e.__mathquillify=function(){return 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}})},C=Qt(T,u),Mt.MathField=function(e){return Qt(e.EditableField,function(e,n){this.RootBlock=C,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}})},D=Qt(St,function(t,e){function n(t){var e,n;return t.jQ[0].normalize(),e=t.jQ[0].firstChild,s("only node in TextBlock span is Text node",3===e.nodeType),n=_(e.data),n.jQadd(e),t.children().disown(),n.adopt(t,0,0)}t.ctrlSeq="\\text",t.replaces=function(t){t instanceof Lt?this.replacedText=t.remove().jQ.text():"string"==typeof t&&(this.replacedText=t)},t.jQadd=function(t){e.jQadd.call(this,t),this.ends[Tt]&&
|
|||
|
t.htmlTemplate='<span class="mq-supsub mq-non-leaf"><span class="mq-sub">&0</span><span style="display:inline-block;width:0">​</span></span>',t.textTemplate=["_"],t.finalizeTree=function(){this.downInto=this.sub=this.ends[Tt],this.sub.upOutOf=f,e.finalizeTree.call(this)}}),Et.superscript=Et.supscript=Et["^"]=Qt(rt,function(t,e){t.supsub="sup",t.htmlTemplate='<span class="mq-supsub mq-non-leaf mq-sup-only"><span class="mq-sup">&0</span></span>',t.textTemplate=["^"],t.finalizeTree=function(){this.upInto=this.sup=this.ends[Ct],this.sup.downOutOf=f,e.finalizeTree.call(this)}}),ot=Qt(O,function(t,e){t.init=function(t,e){var n='<span class="mq-large-operator mq-non-leaf"><span class="mq-to"><span>&1</span></span><big>'+e+'</big><span class="mq-from"><span>&0</span></span></span>';k.prototype.init.call(this,t,n)},t.createLeftOf=function(t){e.createLeftOf.apply(this,arguments),t.options.sumStartsWithNEquals&&(I("n").createLeftOf(t),K().createLeftOf(t))},t.latex=function(){function t(t){return 1===t.length?t:"{"+(t||" ")+"}"}return this.ctrlSeq+"_"+t(this.ends[Tt].latex())+"^"+t(this.ends[Ct].latex())},t.parser=function(){var t,e=w.string,n=w.optWhitespace,i=w.succeed,s=x.block,r=this,o=r.blocks=[T(),T()];for(t=0;t<o.length;t+=1)o[t].adopt(r,r.ends[Ct],0);return n.then(e("_").or(e("^"))).then(function(t){var e=o["_"===t?0:1];return s.then(function(t){return t.children().adopt(e,e.ends[Ct],0),i(r)})}).many().result(r)},t.finalizeTree=function(){this.downInto=this.ends[Tt],this.upInto=this.ends[Ct],this.ends[Tt].upOutOf=this.ends[Ct],this.ends[Ct].downOutOf=this.ends[Tt]}}),Et["∑"]=Et.sum=Et.summation=i(ot,"\\sum ","∑"),Et["∏"]=Et.prod=Et.product=i(ot,"\\prod ","∏"),Et.coprod=Et.coproduct=i(ot,"\\coprod ","∐"),at=Et.frac=Et.dfrac=Et.cfrac=Et.fraction=Qt(O,function(t,e){t.ctrlSeq="\\frac",t.htmlTemplate='<span class="mq-fraction mq-non-leaf"><span class="mq-numerator">&0</span><span class="mq-denominator">&1</span><span style="display:inline-block;width:0">​</span></span>',t.textTemplate=["(",")/(",")"],t.finalizeTree=function(){this.upInto=this.ends[Ct].upOutOf=this.ends[Tt],this.downInto=this.ends[Tt].downOutOf=this.ends[Ct]}}),lt=Et.over=At["/"]=Qt(at,function(e,n){e.createLeftOf=function(e){if(!this.replacedFragment){for(var i=e[Tt];i&&!(i instanceof Q||i instanceof(Et.text||t)||i instanceof ot||"\\ "===i.ctrlSeq||/^[,;:]$/.test(i.ctrlSeq));)i=i[Tt];i instanceof ot&&i[Ct]instanceof rt&&(i=i[Ct],i[Ct]instanceof rt&&i[Ct].ctrlSeq!=i.ctrlSeq&&(i=i[Ct])),i!==e[Tt]&&(this.replaces(Lt(i[Ct]||e.parent.ends[Tt],e[Tt])),e[Tt]=i)}n.createLeftOf.call(this,e)}}),ct=Et.sqrt=Et["√"]=Qt(O,function(t,e){t.ctrlSeq="\\sqrt",t.htmlTemplate='<span class="mq-non-leaf"><span class="mq-scaled mq-sqrt-prefix">√</span><span class="mq-non-leaf mq-sqrt-stem">&0</span></span>',t.textTemplate=["sqrt(",")"],t.parser=function(){return x.optBlock.then(function(t){return x.block.map(function(e){var n=ht();return n.blocks=[t,e],t.adopt(n,0,0),e.adopt(n,t,0),n})}).or(e.parser.call(this))},t.reflow=function(){var t=this.ends[Ct].jQ;Y(t.prev(),1,t.innerHeight()/+t.css("fontSize").slice(0,-2)-.1)}}),ut=Et.vec=Qt(O,function(t,e){t.ctrlSeq="\\vec",t.htmlTemplate='<span class="mq-non-leaf"><span class="mq-vector-prefix">→</span><span class="mq-vector-stem">&0</span></span>',t.textTemplate=["vec(",")"]}),ht=Et.nthroot=Qt(ct,function(t,e){t.htmlTemplate='<sup class="mq-nthroot mq-non-leaf">&0</sup><span class="mq-scaled"><span class="mq-sqrt-prefix mq-scaled">√</span><span class="mq-sqrt-stem mq-non-leaf">&1</span></span>',t.textTemplate=["sqrt[","](",")"],t.latex=function(){return"\\sqrt["+this.ends[Tt].latex()+"]{"+this.ends[Ct].latex()+"}"}}),ft=Qt(Qt(O,p),function(e,n){e.init=function(t,e,i,s,r){n.init.call(this,"\\left"+s,m,[e,i]),this.side=t,this.sides={},this.sides[Tt]={ch:e,ctrlSeq:s},this.sides[Ct]={ch:i,ctrlSeq:r}},e.numBlocks=function(){return 1},e.html=function(){return this.htmlTemplate='<span class="mq-non-leaf"><span class="mq-scaled mq-paren'+(this.side===Ct?" mq-ghost":"")+'">'+this.sides[Tt].ch+'</span>
|