functionhex2rgb(t){if("#"==t[0]&&(t=t.substr(1)),3==t.length){vare=t;t="",e=/^([a-f0-9])([a-f0-9])([a-f0-9])$/i.exec(e).slice(1);for(varn=0;n<3;n++)t+=e[n]+e[n]}varo=/^([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i.exec(t).slice(1);return{red:parseInt(o[0],16),green:parseInt(o[1],16),blue:parseInt(o[2],16)}}if("undefined"==typeofot)varot={};if(ot.TextOperation=function(){"use strict";functiont(){returnthis&&this.constructor===t?(this.ops=[],this.baseLength=0,void(this.targetLength=0)):newt}functione(e,n){varo=e.ops,r=t.isRetain;switch(o.length){case1:returno[0];case2:returnr(o[0])?o[1]:r(o[1])?o[0]:null;case3:if(r(o[0])&&r(o[2]))returno[1]}returnnull}functionn(t){returno(t.ops[0])?t.ops[0]:0}t.prototype.equals=function(t){if(this.baseLength!==t.baseLength)return!1;if(this.targetLength!==t.targetLength)return!1;if(this.ops.length!==t.ops.length)return!1;for(vare=0;e<this.ops.length;e++)if(this.ops[e]!==t.ops[e])return!1;return!0};varo=t.isRetain=function(t){return"number"==typeoft&&t>0},r=t.isInsert=function(t){return"string"==typeoft},i=t.isDelete=function(t){return"number"==typeoft&&t<0};returnt.prototype.retain=function(t){if("number"!=typeoft)thrownewError("retain expects an integer");return0===t?this:(this.baseLength+=t,this.targetLength+=t,o(this.ops[this.ops.length-1])?this.ops[this.ops.length-1]+=t:this.ops.push(t),this)},t.prototype.insert=function(t){if("string"!=typeoft)thrownewError("insert expects a string");if(""===t)returnthis;this.targetLength+=t.length;vare=this.ops;returnr(e[e.length-1])?e[e.length-1]+=t:i(e[e.length-1])?r(e[e.length-2])?e[e.length-2]+=t:(e[e.length]=e[e.length-1],e[e.length-2]=t):e.push(t),this},t.prototype["delete"]=function(t){if("string"==typeoft&&(t=t.length),"number"!=typeoft)thrownewError("delete expects an integer or a string");return0===t?this:(t>0&&(t=-t),this.baseLength-=t,i(this.ops[this.ops.length-1])?this.ops[this.ops.length-1]+=t:this.ops.push(t),this)},t.prototype.isNoop=function(){return0===this.ops.length||1===this.ops.length&&o(this.ops[0])},t.prototype.toString=function(){vart=Array.prototype.map||function(t){for(vare=this,n=[],o=0,r=e.length;o<r;o++)n[o]=t(e[o]);returnn};returnt.call(this.ops,function(t){returno(t)?"retain "+t:r(t)?"insert '"+t+"'":"delete "+-t}).join(", ")},t.prototype.toJSON=function(){returnthis.ops},t.fromJSON=function(e){for(varn=newt,s=0,a=e.length;s<a;s++){varh=e[s];if(o(h))n.retain(h);elseif(r(h))n.insert(h);else{if(!i(h))thrownewError("unknown operation: "+JSON.stringify(h));n["delete"](h)}}returnn},t.prototype.apply=function(t){vare=this;if(t.length!==e.baseLength)thrownewError("The operation's base length must be equal to the string's length.");for(varn=[],i=0,s=0,a=this.ops,h=0,p=a.length;h<p;h++){varc=a[h];if(o(c)){if(s+c>t.length)thrownewError("Operation can't retain more characters than are left in the string.");n[i++]=t.slice(s,s+c),s+=c}elser(c)?n[i++]=c:s-=c}if(s!==t.length)thrownewError("The operation didn't operate on the whole string.");returnn.join("")},t.prototype.invert=function(e){for(varn=0,i=newt,s=this.ops,a=0,h=s.length;a<h;a++){varp=s[a];o(p)?(i.retain(p),n+=p):r(p)?i["delete"](p.length):(i.insert(e.slice(n,n-p)),n-=p)}returni},t.prototype.compose=function(e){varn=this;if(n.targetLength!==e.baseLength)thrownewError("The base length of the second operation has to be the target length of the first operation");for(vars=newt,a=n.ops,h=e.ops,p=0,c=0,l=a[p++],u=h[c++];;){if("undefined"==typeofl&&"undefined"==typeofu)break;if(i(l))s["delete"](l),l=a[p++];elseif(r(u))s.insert(u),u=h[c++];else{if("undefined"==typeofl)thrownewError("Cannot compose operations: first operation is too short.");if("undefined"==typeofu)thrownewError("Cannot compose operations: first operation is too long.");if(o(l)&&o(u))l>u?(s.retain(u),l-=u,u=h[c++]):l===u?(s.retain(l),l=a[p++],u=h[c++]):(s.retain(l),u-=l,l=a[p++]);elseif(r(l)&&i(u))l.length>-u?(l=l.slice(-u),u=h[c++]):l.length===-u?(l=a[p++],u=h[c++]):(u+=l.length,l=a[p++]);elseif(r(l)&&o(u))l.length>u?(s.insert(l.sli