var ot;function hex2rgb(t){if(3==(t="#"==t[0]?t.substr(1):t).length){var e=t;t="";for(var e=/^([a-f0-9])([a-f0-9])([a-f0-9])$/i.exec(e).slice(1),n=0;n<3;n++)t+=e[n]+e[n]}var o=/^([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)}}(ot=void 0===ot?{}:ot).TextOperation=(()=>{function l(){if(!this||this.constructor!==l)return new l;this.ops=[],this.baseLength=0,this.targetLength=0}l.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(var e=0;et.length)throw new Error("Operation can't retain more characters than are left in the string.");e[n++]=t.slice(o,o+a),o+=a}else f(a)?e[n++]=a:o-=a}if(o!==t.length)throw new Error("The operation didn't operate on the whole string.");return e.join("")},l.prototype.invert=function(t){for(var e=0,n=new l,o=this.ops,i=0,r=o.length;i-a?(s=s.slice(-a),a=o[r++]):s.length===-a?(s=n[i++],a=o[r++]):(a+=s.length,s=n[i++]);else if(f(s)&&u(a))s.length>a?(e.insert(s.slice(0,a)),s=s.slice(a),a=o[r++]):s.length===a?(e.insert(s),s=n[i++],a=o[r++]):(e.insert(s),a-=s.length,s=n[i++]);else{if(!u(s)||!g(a))throw new Error("This shouldn't happen: op1: "+JSON.stringify(s)+", op2: "+JSON.stringify(a));-a{var s=t.ot?t.ot.TextOperation:require("./text-operation");function i(t,e){this.anchor=t,this.head=e}function r(t){this.ranges=t||[]}return i.fromJSON=function(t){return new i(t.anchor,t.head)},i.prototype.equals=function(t){return this.anchor===t.anchor&&this.head===t.head},i.prototype.isEmpty=function(){return this.anchor===this.head},i.prototype.transform=function(r){function t(t){for(var e=t,n=r.ops,o=0,i=r.ops.length;o{function o(t,e){this.wrapped=t,this.meta=e}function n(t,e){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])}function i(t,e){return t&&"object"==typeof t&&"function"==typeof t.transform?t.transform(e):t}return o.prototype.apply=function(){return this.wrapped.apply.apply(this.wrapped,arguments)},o.prototype.invert=function(){var t=this.meta;return new o(this.wrapped.invert.apply(this.wrapped,arguments),t&&"object"==typeof t&&"function"==typeof t.invert?t.invert.apply(t,arguments):t)},o.prototype.compose=function(t){return new o(this.wrapped.compose(t.wrapped),(e=this.meta,t=t.meta,e&&"object"==typeof e?"function"==typeof e.compose?e.compose(t):(n(e,e={}),n(t,e),e):t));var e},o.transform=function(t,e){var n=(0,t.wrapped.constructor.transform)(t.wrapped,e.wrapped);return[new o(n[0],i(t.meta,e.wrapped)),new o(n[1],i(e.meta,t.wrapped))]},o})(),"object"==typeof module&&(module.exports=ot.WrappedOperation),(ot=void 0===ot?{}:ot).UndoManager=(()=>{var e="normal",o="undoing",i="redoing";function t(t){this.maxItems=t||50,this.state=e,this.dontCompose=!1,this.undoStack=[],this.redoStack=[]}function n(t,e){for(var n=[],o=e.constructor,i=t.length-1;0<=i;i--){var r=o.transform(t[i],e);"function"==typeof r[0].isNoop&&r[0].isNoop()||n.push(r[0]),e=r[1]}return n.reverse()}return t.prototype.add=function(t,e){var n;this.state===o?(this.redoStack.push(t),this.dontCompose=!0):this.state===i?(this.undoStack.push(t),this.dontCompose=!0):(n=this.undoStack,!this.dontCompose&&e&&0this.maxItems&&n.shift()),this.dontCompose=!1,this.redoStack=[])},t.prototype.transform=function(t){this.undoStack=n(this.undoStack,t),this.redoStack=n(this.redoStack,t)},t.prototype.performUndo=function(t){if(this.state=o,0===this.undoStack.length)throw new Error("undo not possible");t(this.undoStack.pop()),this.state=e},t.prototype.performRedo=function(t){if(this.state=i,0===this.redoStack.length)throw new Error("redo not possible");t(this.redoStack.pop()),this.state=e},t.prototype.canUndo=function(){return 0!==this.undoStack.length},t.prototype.canRedo=function(){return 0!==this.redoStack.length},t.prototype.isUndoing=function(){return this.state===o},t.prototype.isRedoing=function(){return this.state===i},t})(),"object"==typeof module&&(module.exports=ot.UndoManager),(ot=void 0===ot?{}:ot).Client=(()=>{function t(t){this.revision=t,this.setState(p)}function e(){}t.prototype.setState=function(t){this.state=t},t.prototype.applyClient=function(t){this.setState(this.state.applyClient(this,t))},t.prototype.applyServer=function(t,e){this.setState(this.state.applyServer(this,t,e))},t.prototype.applyOperations=function(t,e){this.setState(this.state.applyOperations(this,t,e))},t.prototype.serverAck=function(t){this.setState(this.state.serverAck(this,t))},t.prototype.serverReconnect=function(){"function"==typeof this.state.resend&&this.state.resend(this)},t.prototype.transformSelection=function(t){return this.state.transformSelection(t)},t.prototype.sendOperation=function(t,e){throw new Error("sendOperation must be defined in child class")},t.prototype.applyOperation=function(t){throw new Error("applyOperation must be defined in child class")},(t.Synchronized=e).prototype.applyClient=function(t,e){return t.sendOperation(t.revision,e),new c(e)},e.prototype.applyServer=function(t,e,n){if(1{var f=ot.TextOperation,i=ot.Selection;function n(t){this.cm=t,this.ignoreNextChange=!1,this.changeInProgress=!1,this.selectionChanged=!1,a(this,"onChanges"),a(this,"onChange"),a(this,"onCursorActivity"),a(this,"onFocus"),a(this,"onBlur"),t.on("changes",this.onChanges),t.on("change",this.onChange),t.on("cursorActivity",this.onCursorActivity),t.on("focus",this.onFocus),t.on("blur",this.onBlur)}function o(t,e){return t.line{function t(t){this.socket=t;var i=this;t.on("client_left",function(t){i.trigger("client_left",t)}),t.on("set_name",function(t,e){i.trigger("set_name",t,e)}),t.on("set_color",function(t,e){i.trigger("set_color",t,e)}),t.on("ack",function(t){i.trigger("ack",t)}),t.on("operation",function(t,e,n,o){i.trigger("operation",e,n),i.trigger("selection",t,o)}),t.on("operations",function(t,e){i.trigger("operations",t,e)}),t.on("selection",function(t,e){i.trigger("selection",t,e)}),t.on("reconnect",function(){i.trigger("reconnect")})}return t.prototype.sendOperation=function(t,e,n){this.socket.emit("operation",t,e,n)},t.prototype.sendSelection=function(t){this.socket.emit("selection",t)},t.prototype.getOperations=function(t,e){this.socket.emit("get_operations",t,e)},t.prototype.registerCallbacks=function(t){this.callbacks=t},t.prototype.trigger=function(t){var e=Array.prototype.slice.call(arguments,1),t=this.callbacks&&this.callbacks[t];t&&t.apply(this,e)},t})(),ot.AjaxAdapter=(()=>{function t(t,e,n){"/"!==t[t.length-1]&&(t+="/"),this.path=t,this.ownUserName=e,this.majorRevision=n.major||0,this.minorRevision=n.minor||0,this.poll()}return t.prototype.renderRevisionPath=function(){return"revision/"+this.majorRevision+"-"+this.minorRevision},t.prototype.handleResponse=function(t){for(var e=t.operations,n=0;n{var t,r=ot.Client,s=ot.Selection,a=ot.UndoManager,p=ot.TextOperation,i=ot.WrappedOperation;function h(t,e){this.selectionBefore=t,this.selectionAfter=e}function e(t,e){this.clientId=t,this.selection=e}function n(t,e,n,o,i,r){this.id=t,this.listEl=e,this.editorAdapter=n,this.name=o,this.color=i,this.li=document.createElement("li"),o&&(this.li.textContent=o,this.listEl.appendChild(this.li)),i?this.setForceColor(i):this.setColor(o?f(o):Math.random()),r&&this.updateSelection(r)}function o(t,e,n,o){r.call(this,t),this.serverAdapter=n,this.editorAdapter=o,this.undoManager=new a,this.initializeClientList(),this.initializeClients(e);var i=this;this.editorAdapter.registerCallbacks({change:function(t,e){i.onChange(t,e)},selectionChange:function(){i.onSelectionChange()},blur:function(){i.onBlur()}}),this.editorAdapter.registerUndo(function(){i.undo()}),this.editorAdapter.registerRedo(function(){i.redo()}),this.serverAdapter.registerCallbacks({client_left:function(t){i.onClientLeft(t)},set_name:function(t,e){i.getClientObject(t).setName(e)},set_color:function(t,e){i.getClientObject(t).setForceColor(e)},ack:function(t){i.serverAck(t)},operation:function(t,e){i.applyServer(t,p.fromJSON(e))},operations:function(t,e){i.applyOperations(t,e)},selection:function(t,e){e?i.getClientObject(t).updateSelection(i.transformSelection(s.fromJSON(e))):i.getClientObject(t).removeSelection()},clients:function(t){var e,n;for(e in i.clients)i.clients.hasOwnProperty(e)&&!t.hasOwnProperty(e)&&i.onClientLeft(e);for(e in t)t.hasOwnProperty(e)&&(n=i.getClientObject(e),t[e].name&&n.setName(t[e].name),(n=t[e].selection)?i.clients[e].updateSelection(i.transformSelection(s.fromJSON(n))):i.clients[e].removeSelection())},reconnect:function(){i.serverReconnect()}})}function c(){}function l(t,e,n){function o(t){t=Math.round(255*t).toString(16);return 1===t.length?"0"+t:t}return"#"+o(t)+o(e)+o(n)}function u(t,e,n){var o,i;return 0===e?l(n,n,n):(i=2*n-(o=n<.5?n*(1+e):n+e-e*n),l((e=function(t){return t<0&&(t+=1),1