123456789 |
- /*!
- * ====================================================
- * kityformula-editor - v1.0.0 - 2014-04-03
- * https://github.com/HanCong03/kityformula-editor
- * GitHub: https://github.com/kitygraph/kityformula-editor.git
- * Copyright (c) 2014 Baidu Kity Group; Licensed MIT
- * ====================================================
- */
- !function(){function a(a,b,c){if(d[a]={exports:{},value:null,factory:null},2===arguments.length&&(c=b),"[object Object]"===d.toString.call(c))d[a].value=c;else{if("function"!=typeof c)throw new Error("define函数未定义的行为");d[a].factory=c}}function b(a){var c=d[a],e=null;return c?c.value?c.value:(e=c.factory.call(null,b,c.exports,c),e&&(c.exports=e),c.value=c.exports,c.value):null}function c(a){return b(a)}var d={};a("assembly",[],function(){function a(a,b){this.formula=new kf.Formula(a,b)}function b(a,b,e,f,g){var i,j=null,k=null,l=[],m=b.operand||[],n=null;if(e.operand=[],-1===b.name.indexOf("text")){for(var o=0,p=m.length;p>o;o++)j=m[o],j!==h?j?"string"==typeof j?(m[o]="brackets"===b.name&&2>o?j:c("text",j),e.operand.push(m[o])):(e.operand.push({}),m[o]=arguments.callee(a.operand[o],j,e.operand[e.operand.length-1],f,g)):(m[o]=c("empty"),e.operand.push(m[o])):(l.push(o),g.hasOwnProperty("startOffset")||(g.startOffset=o),g.endOffset=o,b.attr&&b.attr.id&&(g.groupId=b.attr.id));for(;o=l.length;)o=l[o-1],m.splice(o,1),l.length--,a.operand.splice(o,1)}if(n=d(b.name),!n)throw new Error("operator type error: not found "+b.operator);i=function(){},i.prototype=n.prototype,k=new i,n.apply(k,m),e.func=k;for(var q in b.callFn)b.callFn.hasOwnProperty(q)&&k[q]&&k[q].apply(k,b.callFn[q]);return b.attr&&(b.attr.id&&(f[b.attr.id]={objGroup:k,strGroup:a}),k.setAttr(b.attr)),k}function c(a,b){switch(a){case"empty":return new kf.EmptyExpression;case"text":return new kf.TextExpression(b)}}function d(a){return g[a]||kf[a.replace(/^[a-z]/i,function(a){return a.toUpperCase()}).replace(/-([a-z])/gi,function(a,b){return b.toUpperCase()})+"Expression"]}function e(a){var b={};if("[object Array]"==={}.toString.call(a)){b=[];for(var c=0,d=a.length;d>c;c++)b[c]=f(a[c])}else for(var e in a)a.hasOwnProperty(e)&&(b[e]=f(a[e]));return b}function f(a){return a?"object"!=typeof a?a:e(a):a}var g={},h="";return a.prototype.generateBy=function(a){var c=a.tree,d={},f={},g={};return"string"!=typeof c?(this.formula.appendExpression(b(c,e(c),d,g,f)),{select:f,parsedTree:c,tree:d,mapping:g}):(d=new kf.TextExpression(c),void this.formula.appendExpression(d))},a.prototype.regenerateBy=function(a){return this.formula.clearExpressions(),this.generateBy(a)},{use:function(b,c){return new a(b,c)}}}),a("impl/latex/base/latex-utils",["impl/latex/base/rpn","impl/latex/base/utils","impl/latex/define/type","impl/latex/base/tree","impl/latex/handler/combination"],function(a){return{toRPNExpression:a("impl/latex/base/rpn"),generateTree:a("impl/latex/base/tree")}}),a("impl/latex/base/rpn",["impl/latex/base/utils","impl/latex/define/operator","impl/latex/define/func","impl/latex/handler/func","impl/latex/define/type"],function(a){function b(a){for(var b=[],c=null;void 0!==(c=a.pop());)if(c&&"object"==typeof c&&c.sign===!1){var d=c.handler(c,[],b.reverse());b.unshift(d),b.reverse()}else b.push(c);return b.reverse()}var c=a("impl/latex/base/utils");return function(d){var e=[],f=(a("impl/latex/define/type"),null);for(d=b(d);f=d.shift();)"combination"===f.name&&1===f.operand.length&&"brackets"===f.operand[0].name&&(f=f.operand[0]),e.push(c.isArray(f)?arguments.callee(f):f);return e}}),a("impl/latex/base/tree",["impl/latex/define/type","impl/latex/handler/combination","impl/latex/base/utils","impl/latex/define/operator","impl/latex/define/func","impl/latex/handler/func"],function(a){var b=(a("impl/latex/define/type"),a("impl/latex/handler/combination")),c=a("impl/latex/base/utils");return function(a){for(var d=null,e=[],f=0,g=a.length;g>f;f++)c.isArray(a[f])&&(a[f]=arguments.callee(a[f]));for(;d=a.shift();)e.push("object"==typeof d&&d.handler?d.handler(d,e,a):d);return b(e)}}),a("impl/latex/base/utils",["impl/latex/define/operator","impl/latex/handler/script","impl/latex/handler/func","impl/latex/define/type","impl/latex/handler/fraction","impl/latex/handler/sqrt","impl/latex/handler/summation","impl/latex/handler/integration","impl/latex/handler/brackets","impl/latex/define/func","impl/latex/handler/lib/int-extract"],function(a){var b=a("impl/latex/define/operator"),c=a("impl/latex/define/func"),d=a("impl/latex/handler/func"),e={getLatexType:function(a){return a=a.replace(/^\\/,""),b[a]?"operator":c[a]?"function":"text"},isArray:function(a){return a&&"[object Array]"===Object.prototype.toString.call(a)},getDefine:function(a){return e.extend({},b[a.replace("\\","")])},getFuncDefine:function(a){return{name:"function",params:a.replace(/^\\/,""),handler:d}},getBracketsDefine:function(a,c){return e.extend({params:[a,c]},b.brackets)},extend:function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}};return e}),a("impl/latex/define/brackets",[],function(){var a=!0;return{".":a,"{":a,"}":a,"[":a,"]":a,"(":a,")":a,"|":a}}),a("impl/latex/define/func",[],function(){return{sin:1,cos:1,arccos:1,cosh:1,det:1,inf:1,limsup:1,Pr:1,tan:1,arcsin:1,cot:1,dim:1,ker:1,ln:1,sec:1,tanh:1,arctan:1,coth:1,exp:1,lg:1,log:1,arg:1,csc:1,gcd:1,lim:1,max:1,sinh:1,cos:1,deg:1,hom:1,liminf:1,min:1,sup:1}}),a("impl/latex/define/operator",["impl/latex/handler/script","impl/latex/handler/func","impl/latex/handler/lib/int-extract","impl/latex/define/type","impl/latex/handler/fraction","impl/latex/handler/sqrt","impl/latex/handler/summation","impl/latex/handler/integration","impl/latex/handler/brackets","impl/latex/define/brackets"],function(a){var b=a("impl/latex/handler/script"),c=(a("impl/latex/handler/func"),a("impl/latex/define/type"));return{"^":{name:"superscript",type:c.OP,handler:b},_:{name:"subscript",type:c.OP,handler:b},frac:{name:"fraction",type:c.FN,sign:!1,handler:a("impl/latex/handler/fraction")},sqrt:{name:"radical",type:c.FN,sign:!1,handler:a("impl/latex/handler/sqrt")},sum:{name:"summation",type:c.FN,traversal:"rtl",handler:a("impl/latex/handler/summation")},"int":{name:"integration",type:c.FN,traversal:"rtl",handler:a("impl/latex/handler/integration")},brackets:{name:"brackets",type:"TYPE.FN",handler:a("impl/latex/handler/brackets")}}}),a("impl/latex/define/pre",["impl/latex/pre/sqrt","impl/latex/pre/int"],function(a){return{sqrt:a("impl/latex/pre/sqrt"),"int":a("impl/latex/pre/int")}}),a("impl/latex/define/reverse",["impl/latex/reverse/combination","impl/latex/reverse/fraction","impl/latex/reverse/func","impl/latex/reverse/integration","impl/latex/reverse/subscript","impl/latex/reverse/superscript","impl/latex/reverse/script","impl/latex/reverse/sqrt","impl/latex/reverse/summation","impl/latex/reverse/brackets"],function(a){return{combination:a("impl/latex/reverse/combination"),fraction:a("impl/latex/reverse/fraction"),"function":a("impl/latex/reverse/func"),integration:a("impl/latex/reverse/integration"),subscript:a("impl/latex/reverse/subscript"),superscript:a("impl/latex/reverse/superscript"),script:a("impl/latex/reverse/script"),radical:a("impl/latex/reverse/sqrt"),summation:a("impl/latex/reverse/summation"),brackets:a("impl/latex/reverse/brackets")}}),a("impl/latex/define/type",[],function(){return{OP:1,FN:2}}),a("impl/latex/handler/brackets",["impl/latex/define/brackets"],function(a){var b=a("impl/latex/define/brackets");return function(a,c,d){for(var e=0,f=a.params.length;f>e;e++)if(!(a.params[e]in b))throw new Error("Brackets: invalid params");return a.operand=a.params,a.params[2]=d.shift(),delete a.handler,delete a.params,a}}),a("impl/latex/handler/combination",[],function(){return function(){return 0===arguments[0].length?null:{name:"combination",operand:arguments[0]}}}),a("impl/latex/handler/fraction",[],function(){return function(a,b,c){var d=c.shift(),e=c.shift();if(void 0===d||void 0===e)throw new Error("Frac: Syntax Error");return a.operand=[d,e],delete a.handler,a}}),a("impl/latex/handler/func",["impl/latex/handler/lib/int-extract"],function(a){var b=a("impl/latex/handler/lib/int-extract");return function(a,c,d){var e=b(d);return a.operand=[a.params,e.exp,e.sup,e.sub],delete a.params,delete a.handler,a}}),a("impl/latex/handler/integration",["impl/latex/handler/lib/int-extract"],function(a){var b=a("impl/latex/handler/lib/int-extract");return function(a,c,d){var e=d.shift(),f=b(d);return a.operand=[f.exp,f.sup,f.sub],a.callFn={setType:[0|e]},delete a.handler,a}}),a("impl/latex/handler/lib/int-extract",[],function(){return function(a){var b=a.shift()||null,c=null,d=null;return null!==b&&("string"==typeof b?(d=b,b=null):"superscript"===b.name?(b=a.shift()||null,b&&(c=a.shift()||null,c&&("subscript"===c.name?(c=a.shift()||null,d=a.shift()||null):(d=c,c=null)))):"subscript"===b.name?(c=a.shift()||null,c&&(b=a.shift()||null,b&&("superscript"===b.name?(b=a.shift()||null,d=a.shift()||null):(d=b,b=null)))):(d=b,b=null)),{sub:c,sup:b,exp:d}}}),a("impl/latex/handler/script",[],function(){return function(a,b,c){var d=b.pop(),e=c.shift()||null;if(!e)throw new Error("Missing script");if(d=d||"",d.name===a.name||"script"===d.name)throw new Error("script error");return"subscript"===d.name?(d.name="script",d.operand[2]=d.operand[1],d.operand[1]=e,d):"superscript"===d.name?(d.name="script",d.operand[2]=e,d):(a.operand=[d,e],delete a.handler,a)}}),a("impl/latex/handler/sqrt",[],function(){return function(a,b,c){var d=c.shift(),e=c.shift();return a.operand=[e,d],delete a.handler,a}}),a("impl/latex/handler/summation",["impl/latex/handler/lib/int-extract"],function(a){var b=a("impl/latex/handler/lib/int-extract");return function(a,c,d){var e=b(d);return a.operand=[e.exp,e.sup,e.sub],delete a.handler,a}}),a("impl/latex/latex",["parser","impl/latex/base/latex-utils","impl/latex/base/rpn","impl/latex/base/tree","impl/latex/define/pre","impl/latex/pre/sqrt","impl/latex/pre/int","impl/latex/serialization","impl/latex/define/reverse","impl/latex/define/operator","impl/latex/handler/script","impl/latex/handler/func","impl/latex/define/type","impl/latex/handler/fraction","impl/latex/handler/sqrt","impl/latex/handler/summation","impl/latex/handler/integration","impl/latex/handler/brackets","impl/latex/reverse/combination","impl/latex/reverse/fraction","impl/latex/reverse/func","impl/latex/reverse/integration","impl/latex/reverse/subscript","impl/latex/reverse/superscript","impl/latex/reverse/script","impl/latex/reverse/sqrt","impl/latex/reverse/summation","impl/latex/reverse/brackets","impl/latex/base/utils","impl/latex/define/func"],function(a){function b(a){var b=k.getLatexType(a);switch(b){case"operator":return k.getDefine(a);case"function":return k.getFuncDefine(a);default:return c(a)}}function c(a){return 0===a.indexOf("\\")?a+"\\":a}function d(a){return a.replace(/\\\s+/,"").replace(/\s*([^a-z0-9\s])\s*/gi,function(a,b){return b})}var e=a("parser").Parser,f=a("impl/latex/base/latex-utils"),g=a("impl/latex/define/pre"),h=a("impl/latex/serialization"),i=a("impl/latex/define/operator"),j=a("impl/latex/define/reverse"),k=a("impl/latex/base/utils"),l="",m="",n=new RegExp(l+"|"+m,"g"),o=new RegExp(l,"g"),p=new RegExp(m,"g");e.register("latex",e.implement({parse:function(a){var b=this.split(this.format(a));return b=this.parseToGroup(b),b=this.parseToStruct(b),this.generateTree(b)},serialization:function(a,b){return h(a,b)},expand:function(a){var b=a.parse,c=null,d=a.pre,e=a.reverse;for(var f in b)b.hasOwnProperty(f)&&(c=f.replace(/\\/g,""),i[c]=b[f]);for(var f in e)e.hasOwnProperty(f)&&(j[f.replace(/\\/g,"")]=e[f]);if(d)for(var f in d)d.hasOwnProperty(f)&&(g[f.replace(/\\/g,"")]=d[f])},format:function(a){a=d(a),a=a.replace(n,"").replace(/\\{/gi,l).replace(/\\}/gi,m);for(var b in g)g.hasOwnProperty(b)&&(a=g[b](a));return a},split:function(a){var b=[],c=/(?:\\[a-z]+\s*)|(?:[{}]\s*)|(?:[^\\{}]\s*)/gi,d=/^\s+|\s+$/g,e=null;for(a=a.replace(d,"");e=c.exec(a);)e=e[0].replace(d,""),e&&b.push(e);return b},generateTree:function(a){for(var b=[],c=null;c=a.shift();)b.push(k.isArray(c)?this.generateTree(c):c);return b=f.toRPNExpression(b),f.generateTree(b)},parseToGroup:function(a){for(var b=[],c=[b],d=0,e=0,f=0,g=a.length;g>f;f++)switch(a[f]){case"{":d++,c.push(b),b.push([]),b=b[b.length-1];break;case"}":d--,b=c.pop();break;case"\\left":e++,c.push(b),b.push([[]]),b=b[b.length-1][0],b.type="brackets",f++,b.leftBrackets=a[f].replace(o,"{").replace(p,"}");break;case"\\right":e--,f++,b.rightBrackets=a[f].replace(o,"{").replace(p,"}"),b=c.pop();break;default:b.push(a[f].replace(o,"{").replace(p,"}"))}if(0!==d)throw new Error("Group Error!");if(0!==e)throw new Error("Brackets Error!");return c[0]},parseToStruct:function(a){for(var c=[],d=0,e=a.length;e>d;d++)k.isArray(a[d])?"brackets"===a[d].type?(c.push(k.getBracketsDefine(a[d].leftBrackets,a[d].rightBrackets)),c.push(this.parseToStruct(a[d]))):c.push(this.parseToStruct(a[d])):c.push(b(a[d]));return c}}))}),a("impl/latex/pre/int",[],function(){return function(a){return a.replace(/\\(i+)nt(\b|[^a-zA-Z])/g,function(a,b,c){return"\\int "+b.length+c})}}),a("impl/latex/pre/sqrt",[],function(){return function(a){return a.replace(/\\sqrt\s*((?:\[[^\]]*\])?)/g,function(a,b){return"\\sqrt{"+b.replace(/^\[|\]$/g,"")+"}"})}}),a("impl/latex/reverse/brackets",[],function(){return function(a){return["\\left",a[0],a[2],"\\right",a[1]].join(" ")}}),a("impl/latex/reverse/combination",[],function(){new RegExp("","g");return function(a){return this.attr["data-root"]||this.attr["data-placeholder"]?a.join(""):"{"+a.join("")+"}"}}),a("impl/latex/reverse/fraction",[],function(){return function(a){return"\\frac "+a[0]+" "+a[1]}}),a("impl/latex/reverse/func",[],function(){return function(a){var b=["\\"+a[0]];return a[2]&&b.push("^"+a[2]),a[3]&&b.push("_"+a[3]),b.push(" "+a[1]),b.join("")}}),a("impl/latex/reverse/integration",[],function(){return function(a){var b=["\\int"];return a[1]&&b.push("^"+a[1]),a[2]&&b.push("_"+a[2]),b.push(" "+a[0]),a.join("")}}),a("impl/latex/reverse/script",[],function(){return function(a){return a[0]+"^"+a[1]+"_"+a[2]}}),a("impl/latex/reverse/sqrt",[],function(){return function(a){var b=["\\sqrt"];return a[1]&&b.push("["+a[1]+"]"),b.push(" "+a[0]),b.join("")}}),a("impl/latex/reverse/subscript",[],function(){return function(a){return a[0]+"_"+a[1]}}),a("impl/latex/reverse/summation",[],function(){return function(a){var b=["\\sum"];return a[1]&&b.push("^"+a[1]),a[2]&&b.push("_"+a[2]),b.push(" "+a[0]),b.join("")}}),a("impl/latex/reverse/superscript",[],function(){return function(a){return a[0]+"^"+a[1]}}),a("impl/latex/serialization",["impl/latex/define/reverse","impl/latex/reverse/combination","impl/latex/reverse/fraction","impl/latex/reverse/func","impl/latex/reverse/integration","impl/latex/reverse/subscript","impl/latex/reverse/superscript","impl/latex/reverse/script","impl/latex/reverse/sqrt","impl/latex/reverse/summation","impl/latex/reverse/brackets"],function(a){function b(a,e){var f=[],g=null;if("object"!=typeof a)return a.replace(d,function(a,b){return b+" "});"combination"===a.name&&1===a.operand.length&&"combination"===a.operand[0].name&&(a=a.operand[0]),g=a.operand;for(var h=0,i=g.length;i>h;h++)f.push(g[h]?b(g[h]):g[h]);return c[a.name].call(a,f,e)}var c=a("impl/latex/define/reverse"),d=/(\\[\w]+)\\/g;return function(a,c){return b(a,c)}}),a("parser",[],function(a,b,c){function d(a){this.impl=new a,this.conf={}}function e(){this.conf={}}var f={},g={},h={extend:function(a,b){var c=null;b=[].slice.call(arguments,1);for(var d=0,e=b.length;e>d;d++){c=b[d];for(var f in c)c.hasOwnProperty(f)&&(a[f]=c[f])}},setData:function(a,b,c){if("string"==typeof b)a[b]=c;else{if("object"!=typeof b)throw new Error("invalid option");for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c])}}},i={use:function(a){if(!g[a])throw new Error("unknown parser type");return this.proxy(g[a])},config:function(a,b){return h.setData(f,a,b),this},register:function(a,b){return g[a.toLowerCase()]=b,this},implement:function(a){var b=function(){},c=a.constructor||function(){},d=function(){e.call(this),c.call(this)};b.prototype=e.prototype,d.prototype=new b,delete a.constructor;for(var f in a)"constructor"!==f&&a.hasOwnProperty(f)&&(d.prototype[f]=a[f]);return d},proxy:function(a){return new d(a)}};h.extend(d.prototype,{config:function(a,b){h.setData(this.conf,a,b)},set:function(a,b){this.impl.set(a,b)},parse:function(a){var b={config:{},tree:this.impl.parse(a)};return h.extend(b.config,f,this.conf),b},serialization:function(a,b){return this.impl.serialization(a,b)},expand:function(a){this.impl.expand(a)}}),h.extend(e.prototype,{set:function(a,b){h.extend(this.conf,a,b)},parse:function(){throw new Error("Abstract function")}}),c.exports={Parser:i,ParserInterface:e}}),function(b){a("kf.start",function(a){var c=a("parser").Parser;a("impl/latex/latex"),b.kf.Parser=c,b.kf.Assembly=a("assembly")});try{c("kf.start")}catch(d){}}(this)}();
|