diff --git a/docs/content/dev/ot.md b/docs/content/dev/ot.md index a1d0bebe..65b7c02f 100644 --- a/docs/content/dev/ot.md +++ b/docs/content/dev/ot.md @@ -11,3 +11,10 @@ And even more in this 2010 article series: - - - + +## OT library + +HedgeDoc uses a vendored version of OT.js. The source code lives under `public/vendor/ot/`. +The HedgeDoc frontend uses a minified build `public/vendor/ot/ot.min.js`. + +This build is generated by `yarn run build:ot`. This needs to be done after changes to the OT code. diff --git a/docs/content/dev/release_checklist.md b/docs/content/dev/release_checklist.md index d9c52bda..f5567654 100644 --- a/docs/content/dev/release_checklist.md +++ b/docs/content/dev/release_checklist.md @@ -52,6 +52,7 @@ To copy this checklist please go to [this link](https://github.com/hedgedoc/hedg mkdir /tmp/hedgedoc && cd /tmp/hedgedoc git clone -b master https://github.com/hedgedoc/hedgedoc.git . yarn install +yarn build:ot yarn build cd .. tar cvzf hedgedoc-x.y.z.tar.gz --sort=name --exclude hedgedoc/node_modules --exclude hedgedoc/.git --exclude hedgedoc/.github --exclude hedgedoc/.yarn/cache hedgedoc diff --git a/package.json b/package.json index 884f39e0..7873d3c7 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "dev": "webpack --config webpack.dev.js --progress --watch", "heroku-prebuild": "bin/heroku", "build": "webpack --config webpack.prod.js --progress", + "build:ot": "bash -c \"cd public/vendor/ot && ./compress.sh\"", "start": "node app.js" }, "dependencies": { @@ -196,6 +197,7 @@ "spin.js": "4.1.2", "string-loader": "0.0.1", "turndown": "7.2.2", + "uglify-js": "3.19.3", "url-loader": "4.1.1", "velocity-animate": "1.5.2", "visibilityjs": "2.0.2", diff --git a/public/vendor/ot/compress.sh b/public/vendor/ot/compress.sh index b7cb423f..6deade9d 100644 --- a/public/vendor/ot/compress.sh +++ b/public/vendor/ot/compress.sh @@ -1,4 +1,4 @@ -uglifyjs --compress --mangle --output ot.min.js \ +yarn uglifyjs --compress --mangle --output ot.min.js \ ./text-operation.js \ ./selection.js \ ./wrapped-operation.js \ @@ -7,4 +7,4 @@ uglifyjs --compress --mangle --output ot.min.js \ ./codemirror-adapter.js \ ./socketio-adapter.js \ ./ajax-adapter.js \ -./editor-client.js \ No newline at end of file +./editor-client.js diff --git a/public/vendor/ot/ot.min.js b/public/vendor/ot/ot.min.js index d942cb5d..81192fc1 100644 --- a/public/vendor/ot/ot.min.js +++ b/public/vendor/ot/ot.min.js @@ -1 +1 @@ -function hex2rgb(t){if("#"==t[0]&&(t=t.substr(1)),3==t.length){var e=t;t="",e=/^([a-f0-9])([a-f0-9])([a-f0-9])$/i.exec(e).slice(1);for(var 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)}}if("undefined"==typeof ot)var ot={};if(ot.TextOperation=function(){"use strict";function t(){return this&&this.constructor===t?(this.ops=[],this.baseLength=0,void(this.targetLength=0)):new t}function e(e,n){var o=e.ops,r=t.isRetain;switch(o.length){case 1:return o[0];case 2:return r(o[0])?o[1]:r(o[1])?o[0]:null;case 3:if(r(o[0])&&r(o[2]))return o[1]}return null}function n(t){return o(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(var e=0;e0},r=t.isInsert=function(t){return"string"==typeof t},i=t.isDelete=function(t){return"number"==typeof t&&t<0};return t.prototype.retain=function(t){if("number"!=typeof t)throw new Error("retain expects an integer");return 0===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"!=typeof t)throw new Error("insert expects a string");if(""===t)return this;this.targetLength+=t.length;var e=this.ops;return r(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"==typeof t&&(t=t.length),"number"!=typeof t)throw new Error("delete expects an integer or a string");return 0===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(){return 0===this.ops.length||1===this.ops.length&&o(this.ops[0])},t.prototype.toString=function(){var t=Array.prototype.map||function(t){for(var e=this,n=[],o=0,r=e.length;ot.length)throw new Error("Operation can't retain more characters than are left in the string.");n[i++]=t.slice(s,s+c),s+=c}else r(c)?n[i++]=c:s-=c}if(s!==t.length)throw new Error("The operation didn't operate on the whole string.");return n.join("")},t.prototype.invert=function(e){for(var n=0,i=new t,s=this.ops,a=0,h=s.length;au?(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++]);else if(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++]);else if(r(l)&&o(u))l.length>u?(s.insert(l.slice(0,u)),l=l.slice(u),u=h[c++]):l.length===u?(s.insert(l),l=a[p++],u=h[c++]):(s.insert(l),u-=l.length,l=a[p++]);else{if(!o(l)||!i(u))throw new Error("This shouldn't happen: op1: "+JSON.stringify(l)+", op2: "+JSON.stringify(u));l>-u?(s["delete"](u),l+=u,u=h[c++]):l===-u?(s["delete"](u),l=a[p++],u=h[c++]):(s["delete"](l),u+=l,l=a[p++])}}}return s},t.prototype.shouldBeComposedWith=function(t){if(this.isNoop()||t.isNoop())return!0;var o=n(this),s=n(t),a=e(this),h=e(t);return!(!a||!h)&&(r(a)&&r(h)?o+a.length===s:!(!i(a)||!i(h))&&(s-h===o||o===s))},t.prototype.shouldBeComposedWithInverted=function(t){if(this.isNoop()||t.isNoop())return!0;var o=n(this),s=n(t),a=e(this),h=e(t);return!(!a||!h)&&(r(a)&&r(h)?o+a.length===s||o===s:!(!i(a)||!i(h))&&s-h===o)},t.transform=function(e,n){if(e.baseLength!==n.baseLength)throw new Error("Both operations have to have the same base length");for(var s=new t,a=new t,h=e.ops,p=n.ops,c=0,l=0,u=h[c++],f=p[l++];;){if("undefined"==typeof u&&"undefined"==typeof f)break;if(r(u))s.insert(u),a.retain(u.length),u=h[c++];else if(r(f))s.retain(f.length),a.insert(f),f=p[l++];else{if("undefined"==typeof u)throw new Error("Cannot compose operations: first operation is too short.");if("undefined"==typeof f)throw new Error("Cannot compose operations: first operation is too long.");var d;if(o(u)&&o(f))u>f?(d=f,u-=f,f=p[l++]):u===f?(d=f,u=h[c++],f=p[l++]):(d=u,f-=u,u=h[c++]),s.retain(d),a.retain(d);else if(i(u)&&i(f))-u>-f?(u-=f,f=p[l++]):u===f?(u=h[c++],f=p[l++]):(f-=u,u=h[c++]);else if(i(u)&&o(f))-u>f?(d=f,u+=f,f=p[l++]):-u===f?(d=f,u=h[c++],f=p[l++]):(d=-u,f+=u,u=h[c++]),s["delete"](d);else{if(!o(u)||!i(f))throw new Error("The two operations aren't compatible");u>-f?(d=-f,u+=f,f=p[l++]):u===-f?(d=u,u=h[c++],f=p[l++]):(d=u,f+=u,u=h[c++]),a["delete"](d)}}}return[s,a]},t}(),"object"==typeof module&&(module.exports=ot.TextOperation),"undefined"==typeof ot)var ot={};if(ot.Selection=function(t){"use strict";function e(t,e){this.anchor=t,this.head=e}function n(t){this.ranges=t||[]}var o=t.ot?t.ot.TextOperation:require("./text-operation");return e.fromJSON=function(t){return new e(t.anchor,t.head)},e.prototype.equals=function(t){return this.anchor===t.anchor&&this.head===t.head},e.prototype.isEmpty=function(){return this.anchor===this.head},e.prototype.transform=function(t){function n(e){for(var n=e,r=t.ops,i=0,s=t.ops.length;i=0;r--){var i=o.transform(t[r],e);"function"==typeof i[0].isNoop&&i[0].isNoop()||n.push(i[0]),e=i[1]}return n.reverse()}var n="normal",o="undoing",r="redoing";return t.prototype.add=function(t,e){if(this.state===o)this.redoStack.push(t),this.dontCompose=!0;else if(this.state===r)this.undoStack.push(t),this.dontCompose=!0;else{var n=this.undoStack;!this.dontCompose&&e&&n.length>0?n.push(t.compose(n.pop())):(n.push(t),n.length>this.maxItems&&n.shift()),this.dontCompose=!1,this.redoStack=[]}},t.prototype.transform=function(t){this.undoStack=e(this.undoStack,t),this.redoStack=e(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=n},t.prototype.performRedo=function(t){if(this.state=r,0===this.redoStack.length)throw new Error("redo not possible");t(this.redoStack.pop()),this.state=n},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===r},t}(),"object"==typeof module&&(module.exports=ot.UndoManager),"undefined"==typeof ot)var ot={};ot.Client=function(t){"use strict";function e(t){this.revision=t,this.setState(a)}function n(){}function o(t){this.outstanding=t}function r(t,e){this.outstanding=t,this.buffer=e}function i(t,e,n){this.acknowlaged=t,this.client=e,this.revision=n}function s(t,e,n,o){this.acknowlaged=t,this.buffer=e,this.client=n,this.revision=o}e.prototype.setState=function(t){this.state=t},e.prototype.applyClient=function(t){this.setState(this.state.applyClient(this,t))},e.prototype.applyServer=function(t,e){this.setState(this.state.applyServer(this,t,e))},e.prototype.applyOperations=function(t,e){this.setState(this.state.applyOperations(this,t,e))},e.prototype.serverAck=function(t){this.setState(this.state.serverAck(this,t))},e.prototype.serverReconnect=function(){"function"==typeof this.state.resend&&this.state.resend(this)},e.prototype.transformSelection=function(t){return this.state.transformSelection(t)},e.prototype.sendOperation=function(t,e){throw new Error("sendOperation must be defined in child class")},e.prototype.applyOperation=function(t){throw new Error("applyOperation must be defined in child class")},e.Synchronized=n,n.prototype.applyClient=function(t,e){return t.sendOperation(t.revision,e),new o(e)},n.prototype.applyServer=function(t,e,n){if(e-t.revision>1)throw new Error("Invalid revision.");return t.revision=e,t.applyOperation(n),this},n.prototype.serverAck=function(t,e){throw new Error("There is no pending operation.")},n.prototype.transformSelection=function(t){return t};var a=new n;return e.AwaitingConfirm=o,o.prototype.applyClient=function(t,e){return new r(this.outstanding,e)},o.prototype.applyServer=function(t,e,n){if(e-t.revision>1)throw new Error("Invalid revision.");t.revision=e;var r=n.constructor.transform(this.outstanding,n);return t.applyOperation(r[1]),new o(r[0])},o.prototype.serverAck=function(t,e){return e-t.revision>1?new i(this.outstanding,t,e).getOperations():(t.revision=e,a)},o.prototype.transformSelection=function(t){return t.transform(this.outstanding)},o.prototype.resend=function(t){t.sendOperation(t.revision,this.outstanding)},e.AwaitingWithBuffer=r,r.prototype.applyClient=function(t,e){var n=this.buffer.compose(e);return new r(this.outstanding,n)},r.prototype.applyServer=function(t,e,n){if(e-t.revision>1)throw new Error("Invalid revision.");t.revision=e;var o=n.constructor.transform,i=o(this.outstanding,n),s=o(this.buffer,i[1]);return t.applyOperation(s[1]),new r(i[0],s[0])},r.prototype.serverAck=function(t,e){return e-t.revision>1?new s(this.outstanding,this.buffer,t,e).getOperations():(t.revision=e,t.sendOperation(t.revision,this.buffer),new o(this.buffer))},r.prototype.transformSelection=function(t){return t.transform(this.outstanding).transform(this.buffer)},r.prototype.resend=function(t){t.sendOperation(t.revision,this.outstanding)},e.Stale=i,i.prototype.applyClient=function(t,e){return new s(this.acknowlaged,e,t,this.revision)},i.prototype.applyServer=function(t,e,n){throw new Error("Ignored server-side change.")},i.prototype.applyOperations=function(t,e,n){for(var o=this.acknowlaged.constructor.transform,r=0;re.line?1:t.che.ch?1:0}function o(t,e){return n(t,e)<=0}function r(t,e){return o(t,e)?t:e}function i(t,e){return o(t,e)?e:t}function s(t){return t.indexFromPos({line:t.lastLine(),ch:0})+t.getLine(t.lastLine()).length}function a(t,e){var n=t[e];t[e]=function(){n.apply(t,arguments)}}var h=ot.TextOperation,p=ot.Selection;e.prototype.detach=function(){this.cm.off("changes",this.onChanges),this.cm.off("change",this.onChange),this.cm.off("cursorActivity",this.onCursorActivity),this.cm.off("focus",this.onFocus),this.cm.off("blur",this.onBlur)},e.operationFromCodeMirrorChanges=function(t,e){function n(t){return t[t.length-1]}function r(t){if(0===t.length)return 0;for(var e=0,n=0;n=0;u--){var f=t[u];l=i(l,f);var d=l(f.from),g=a-d-r(f.text);p=(new h).retain(d)["delete"](r(f.removed)).insert(f.text.join("\n")).retain(g).compose(p),c=c.compose((new h).retain(d)["delete"](r(f.text)).insert(f.removed.join("\n")).retain(g)),a+=r(f.removed)-r(f.text)}return[p,c]},e.operationFromCodeMirrorChange=e.operationFromCodeMirrorChanges,e.applyOperationToCodeMirror=function(t,e){e.operation(function(){for(var n=t.ops,o=0,r=0,i=n.length;r0&&(this.majorRevision+=n.length,this.minorRevision=0);var o=t.events;if(o){for(e=0;e1&&(t-=1),6*t<1?i+6*(o-i)*t:2*t<1?o:3*t<2?i+6*(o-i)*(2/3-t):i};return r(s(t+1/3),s(t),s(t-1/3))}function s(t){for(var e=1,n=0;n0&&n.shouldBeComposedWithInverted(h(this.undoManager.undoStack).wrapped)),s=new t(this.selection,o);this.undoManager.add(new d(n,s),i),this.applyClient(e)},o.prototype.updateSelection=function(){this.selection=this.editorAdapter.getSelection()},o.prototype.onSelectionChange=function(){var t=this.selection;this.updateSelection(),t&&this.selection.equals(t)||this.sendSelection(this.selection)},o.prototype.onBlur=function(){this.selection=null,this.sendSelection(null)},o.prototype.sendSelection=function(t){this.state instanceof c.AwaitingWithBuffer||this.serverAdapter.sendSelection(t)},o.prototype.sendOperation=function(t,e){this.serverAdapter.sendOperation(t,e.toJSON(),this.selection)},o.prototype.getOperations=function(t,e){this.serverAdapter.getOperations(t,e)},o.prototype.applyOperation=function(t){this.editorAdapter.applyOperation(t),this.updateSelection(),this.undoManager.transform(new d(t,null))},o}(); \ No newline at end of file +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