yjs/y.js

3 lines
42 KiB
JavaScript

"use strict";function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function compareIds(e,t){return null==e||null==t?null==e&&null==t?!0:!1:e[0]===t[0]&&e[1]===t[1]?!0:!1}function _flushOne(){var e=[];for(var t in globalRoom.buffers)globalRoom.buffers[t].length>0&&e.push(t);if(e.length>0){var r=getRandom(e),n=globalRoom.buffers[r].shift(),a=globalRoom.users[r];return a.receiveMessage(n[0],n[1]),!0}return!1}function copyObject(e){var t={};for(var r in e)t[r]=e[r];return t}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();!function(e){function t(e,t,r,a){var i=Object.create((t||n).prototype);return i._invoke=c(e,r||null,new f(a||[])),i}function r(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(n){return{type:"throw",arg:n}}}function n(){}function a(){}function i(){}function s(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function o(e){this.arg=e}function u(e){function t(t,r){var n=e[t](r),s=n.value;return s instanceof o?Promise.resolve(s.arg).then(a,i):Promise.resolve(s).then(function(e){return n.value=e,n},i)}function r(e,r){var a=n?n.then(function(){return t(e,r)}):new Promise(function(n){n(t(e,r))});return n=a["catch"](s),a}"object"==typeof process&&process.domain&&(t=process.domain.bind(t));var n,a=t.bind(e,"next"),i=t.bind(e,"throw"),s=t.bind(e,"return");this._invoke=r}function c(e,t,n){var a=x;return function(i,s){if(a===w)throw new Error("Generator is already running");if(a===R)return d();for(;;){var o=n.delegate;if(o){if("return"===i||"throw"===i&&o.iterator[i]===g){n.delegate=null;var u=o.iterator["return"];if(u){var c=r(u,o.iterator,s);if("throw"===c.type){i="throw",s=c.arg;continue}}if("return"===i)continue}var c=r(o.iterator[i],o.iterator,s);if("throw"===c.type){n.delegate=null,i="throw",s=c.arg;continue}i="next",s=g;var l=c.arg;if(!l.done)return a=k,l;n[o.resultName]=l.value,n.next=o.nextLoc,n.delegate=null}if("next"===i)a===k?n.sent=s:delete n.sent;else if("throw"===i){if(a===x)throw a=R,s;n.dispatchException(s)&&(i="next",s=g)}else"return"===i&&n.abrupt("return",s);a=w;var c=r(e,t,n);if("normal"===c.type){a=n.done?R:k;var l={value:c.arg,done:n.done};if(c.arg!==S)return l;n.delegate&&"next"===i&&(s=g)}else"throw"===c.type&&(a=R,i="throw",s=c.arg)}}}function l(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function p(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function f(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(l,this),this.reset()}function h(e){if(e){var t=e[y];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function a(){for(;++r<e.length;)if(b.call(e,r))return a.value=e[r],a.done=!1,a;return a.value=g,a.done=!0,a};return n.next=n}}return{next:d}}function d(){return{value:g,done:!0}}var g,b=Object.prototype.hasOwnProperty,y="function"==typeof Symbol&&Symbol.iterator||"@@iterator",v="object"==typeof module,m=e.regeneratorRuntime;if(m)return void(v&&(module.exports=m));m=e.regeneratorRuntime=v?module.exports:{},m.wrap=t;var x="suspendedStart",k="suspendedYield",w="executing",R="completed",S={},O=i.prototype=n.prototype;a.prototype=O.constructor=i,i.constructor=a,a.displayName="GeneratorFunction",m.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return t?t===a||"GeneratorFunction"===(t.displayName||t.name):!1},m.mark=function(e){return e.__proto__=i,e.prototype=Object.create(O),e},m.awrap=function(e){return new o(e)},s(u.prototype),m.async=function(e,r,n,a){var i=new u(t(e,r,n,a));return m.isGeneratorFunction(r)?i:i.next().then(function(e){return e.done?e.value:i.next()})},s(O),O[y]=function(){return this},O.toString=function(){return"[object Generator]"},m.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},m.values=h,f.prototype={constructor:f,reset:function(){this.prev=0,this.next=0,this.sent=g,this.done=!1,this.delegate=null,this.tryEntries.forEach(p);for(var e,t=0;b.call(this,e="t"+t)||20>t;++t)this[e]=null},stop:function(){this.done=!0;var e=this.tryEntries[0],t=e.completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){function t(t,n){return i.type="throw",i.arg=e,r.next=t,!!n}if(this.done)throw e;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n],i=a.completion;if("root"===a.tryLoc)return t("end");if(a.tryLoc<=this.prev){var s=b.call(a,"catchLoc"),o=b.call(a,"finallyLoc");if(s&&o){if(this.prev<a.catchLoc)return t(a.catchLoc,!0);if(this.prev<a.finallyLoc)return t(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return t(a.catchLoc,!0)}else{if(!o)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return t(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&b.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?this.next=a.finallyLoc:this.complete(i),S},complete:function(e,t){if("throw"===e.type)throw e.arg;"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=e.arg,this.next="end"):"normal"===e.type&&t&&(this.next=t)},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),p(r),S}},"catch":function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;p(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:h(e),resultName:t,nextLoc:r},S}}}("object"==typeof global?global:"object"==typeof window?window:"object"==typeof self?self:void 0);var GeneratorFunction=regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}},e,this)}).constructor,Y=function(){function e(t){_classCallCheck(this,e),this.db=new e[t.db.name](this,t.db),this.connector=new e[t.connector.name](this,t.connector),this.db.requestTransaction(regeneratorRuntime.mark(function r(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.addOperation({id:["_",0],struct:"Map",map:{}}),"t0",1);case 1:case"end":return e.stop()}},r,this)}))}return e.prototype.transact=function(e){if(e.constructor!==GeneratorFunction)throw new Error("y.transact requires a Generator function! E.g. function*(){/*..*/}");this.db.requestTransaction(e)},e.prototype.destroy=function(){this.connector.disconnect(),this.db.removeDatabase(),this.connector=null,this.db=null,this.transact=function(){throw new Error("Remember?, you destroyed this type ;)")}},e}(),AbstractConnector=function(){function e(t,r){if(_classCallCheck(this,e),this.y=t,null==r&&(r={}),null==r.role||"master"===r.role)this.role="master";else{if("slave"!==r.role)throw new Error("Role must be either 'master' or 'slave'!");this.role="slave"}this.role=r.role,this.connections={},this.userEventListeners=[],this.whenSyncedListeners=[],this.currentSyncTarget=null,this.syncingClients=[],this.forwardToSyncingClients=r.forwardToSyncingClients===!1?!1:!0,this.debug=r.debug?!0:!1}return e.prototype.setUserId=function(e){this.userId=e,this.y.db.setUserId(e)},e.prototype.onUserEvent=function(e){this.userEventListeners.push(e)},e.prototype.userLeft=function(e){delete this.connections[e],e===this.currentSyncTarget&&(this.currentSyncTarget=null,this.findNextSyncTarget());for(var t=this.userEventListeners,r=Array.isArray(t),n=0,t=r?t:t[Symbol.iterator]();;){var a;if(r){if(n>=t.length)break;a=t[n++]}else{if(n=t.next(),n.done)break;a=n.value}var i=a;i({action:"userLeft",user:e})}},e.prototype.userJoined=function(e,t){if(null==t)throw new Error("You must specify the role of the joined user!");if(null!=this.connections[e])throw new Error("This user already joined!");this.connections[e]={isSynced:!1,role:t};for(var r=this.userEventListeners,n=Array.isArray(r),a=0,r=n?r:r[Symbol.iterator]();;){var i;if(n){if(a>=r.length)break;i=r[a++]}else{if(a=r.next(),a.done)break;i=a.value}var s=i;s({action:"userJoined",user:e,role:t})}null==this.currentSyncTarget&&this.findNextSyncTarget()},e.prototype.whenSynced=function(e){this.isSynced===!0?e():this.whenSyncedListeners.push(e)},e.prototype.findNextSyncTarget=function(){if(null!=this.currentSyncTarget&&this.connections[this.currentSyncTarget].isSynced===!1)throw new Error("The current sync has not finished!");var e=null;for(var t in this.connections)if(e=this.connections[t],!e.isSynced)break;if(null!=e){var r=this;this.y.db.requestTransaction(regeneratorRuntime.mark(function u(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r.currentSyncTarget=t,e.t0=r,e.t1=t,e.delegateYield(this.getStateVector(),"t2",4);case 4:e.t3=e.t2,e.t4={type:"sync step 1",stateVector:e.t3},e.t0.send.call(e.t0,e.t1,e.t4);case 7:case"end":return e.stop()}},u,this)}))}if(!this.isSynced){this.isSynced=!0;for(var n=this.whenSyncedListeners,a=Array.isArray(n),i=0,n=a?n:n[Symbol.iterator]();;){var s;if(a){if(i>=n.length)break;s=n[i++]}else{if(i=n.next(),i.done)break;s=i.value}var o=s;o()}this.whenSyncedListeners=null}return!1},e.prototype.receiveMessage=function(e,t){var r=this;if(this.debug&&console.log(e+" -> "+this.userId+": "+JSON.stringify(t)),"sync step 1"===t.type)!function(){var n=r;r.y.db.requestTransaction(regeneratorRuntime.mark(function a(){var r,i;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.delegateYield(this.getOperations(t.stateVector),"t0",1);case 1:return r=a.t0,a.delegateYield(this.getStateVector(),"t1",3);case 3:i=a.t1,n.send(e,{type:"sync step 2",os:r,stateVector:i}),this.forwardToSyncingClients&&(n.syncingClients.push(e),setTimeout(function(){n.syncingClients=n.syncingClients.filter(function(t){return t!==e}),n.send(e,{type:"sync done"})},n.syncingClientDuration));case 6:case"end":return a.stop()}},a,this)}))}();else if("sync step 2"===t.type)!function(){r.y.db.apply(t.os);var e=r;r.y.db.requestTransaction(regeneratorRuntime.mark(function n(){var r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.delegateYield(this.getOperations(t.stateVector),"t0",1);case 1:r=n.t0,r.length>0&&e.broadcast({type:"update",ops:r});case 3:case"end":return n.stop()}},n,this)}))}();else if("sync done"===t.type)this.connections[e].isSynced=!0,this.findNextSyncTarget();else if("update"===t.type){if(this.forwardToSyncingClients)for(var n=this.syncingClients,a=Array.isArray(n),i=0,n=a?n:n[Symbol.iterator]();;){var s;if(a){if(i>=n.length)break;s=n[i++]}else{if(i=n.next(),i.done)break;s=i.value}var o=s;this.send(o,t)}this.y.db.apply(t.ops)}},e.prototype.parseMessageFromXml=function(e){function t(e){var t=!0;e:for(;t;){var n=e;a=i=s=a=o=u=void 0,t=!1;for(var a=n.children,i=Array.isArray(a),s=0,a=i?a:a[Symbol.iterator]();;){var o;if(i){if(s>=a.length)break;o=a[s++]}else{if(s=a.next(),s.done)break;o=s.value}var u=o;if("true"===u.getAttribute("isArray")){e=u,t=!0;continue e}return r(u)}}}function r(e){var n={};for(var a in e.attrs){var i=e.attrs[a],s=parseInt(i);n[a]=isNaN(s)||""+s!==i?i:s}for(var o in e.children){var u=o.name;n[u]="true"===o.getAttribute("isArray")?t(o):r(o)}return n}r(e)},e.prototype.encodeMessageToXml=function(e,t){function r(e,t){for(var a in t){var i=t[a];null==a||(i.constructor===Object?r(e.c(a),i):i.constructor===Array?n(e.c(a),i):e.setAttribute(a,i))}}function n(e,t){e.setAttribute("isArray","true");for(var a=t,i=Array.isArray(a),s=0,a=i?a:a[Symbol.iterator]();;){var o;if(i){if(s>=a.length)break;o=a[s++]}else{if(s=a.next(),s.done)break;o=s.value}var u=o;u.constructor===Object?r(e.c("array-element"),u):n(e.c("array-element"),u)}}if(t.constructor===Object)r(e.c("y",{xmlns:"http://y.ninja/connector-stanza"}),t);else{if(t.constructor!==Array)throw new Error("I can't encode this json!");n(e.c("y",{xmlns:"http://y.ninja/connector-stanza"}),t)}},e}(),AbstractTransaction=function(){function e(t){_classCallCheck(this,e),this.store=t}return e.prototype.getType=regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.getOperation(e),"t0",1);case 1:return r=t.t0,t.abrupt("return",new Y[r.type].Create(r));case 3:case"end":return t.stop()}},t,this)}),e.prototype.addOperation=regeneratorRuntime.mark(function r(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(this.getState(e.id[0]),"t0",1);case 1:if(t=r.t0,e.id[1]!==t.clock){r.next=10;break}return t.clock++,r.delegateYield(this.setState(t),"t1",5);case 5:return r.delegateYield(this.setOperation(e),"t2",6);case 6:return this.store.operationAdded(e),r.abrupt("return",!0);case 10:if(!(e.id[1]<t.clock)){r.next=14;break}return r.abrupt("return",!1);case 14:throw new Error("Operations must arrive in order!");case 15:case"end":return r.stop()}},r,this)}),e}();Y.AbstractTransaction=AbstractTransaction;var AbstractOperationStore=function(){function e(t){_classCallCheck(this,e),this.y=t,this.parentListeners={},this.parentListenersRequestPending=!1,this.parentListenersActivated={},this.listenersById={},this.listenersByIdExecuteNow=[],this.listenersByIdRequestPending=!1}return e.prototype.setUserId=function(e){this.userId=e},e.prototype.apply=function(e){for(var t in e){var r=e[t],n=Y.Struct[r.struct].requiredOps(r);this.whenOperationsExist(n,r)}},e.prototype.whenOperationsExist=function(e,t){if(e.length>0){var r={op:t,missing:e.length};for(var n in e){var a=e[n],i=JSON.stringify(a),s=this.listenersById[i];null==s&&(s=[],this.listenersById[i]=s),s.push(r)}}else this.listenersByIdExecuteNow.push({op:t});if(!this.listenersByIdRequestPending){this.listenersByIdRequestPending=!0;var o=this;this.requestTransaction(regeneratorRuntime.mark(function u(){var e,t,r,n,a,i,s,c;return regeneratorRuntime.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:e=o.listenersByIdExecuteNow,o.listenersByIdExecuteNow=[],t=o.listenersById,o.listenersById={},o.listenersByIdRequestPending=!1,u.t0=regeneratorRuntime.keys(e);case 6:if((u.t1=u.t0()).done){u.next=12;break}return r=u.t1.value,n=e[r].op,u.delegateYield(Struct[n.struct].execute.call(this,n),"t2",10);case 10:u.next=6;break;case 12:u.t3=regeneratorRuntime.keys(t);case 13:if((u.t4=u.t3()).done){u.next=34;break}return a=u.t4.value,i=t[a],s=JSON.parse(a),u.delegateYield(this.getOperation(s),"t5",18);case 18:if(u.t6=u.t5,null!=u.t6){u.next=23;break}o.listenersById[a]=i,u.next=32;break;case 23:u.t7=regeneratorRuntime.keys(i);case 24:if((u.t8=u.t7()).done){u.next=32;break}if(r=u.t8.value,c=i[r],n=c.op,0!==--c.missing){u.next=30;break}return u.delegateYield(Struct[n.struct].execute.call(this,n),"t9",30);case 30:u.next=24;break;case 32:u.next=13;break;case 34:case"end":return u.stop()}},u,this)}))}},e.prototype.operationAdded=function(e){var t=JSON.stringify(e.id),r=this.listenersById[t];if(delete this.listenersById[t],null!=r)for(var n in r){var a=r[n];0===--a.missing&&this.whenOperationsExist([],a.op)}var i=this.parentListeners[e.parent];if(!this.parentListenersRequestPending&&null!=i&&0!==i.length){var s=this.parentListenersActivated[JSON.stringify(e.parent)];null==s&&(s=[],this.parentListenersActivated[JSON.stringify(e.parent)]=s),s.push(e),this.parentListenersRequestPending=!0;var o=this;this.requestTransaction(regeneratorRuntime.mark(function u(){var e,t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:o.parentListenersRequestPending=!1,e=o.parentListenersActivated,o.parentListenersActivated={},n.t0=regeneratorRuntime.keys(e);case 4:if((n.t1=n.t0()).done){n.next=11;break}return t=n.t1.value,n.delegateYield(this.getOperation(t),"t2",7);case 7:r=n.t2,Struct[r.struct].notifyObservers(e[t]),n.next=4;break;case 11:case"end":return n.stop()}},u,this)}))}},e.prototype.removeParentListener=function(e,t){var r=this.parentListeners[e];null!=r&&(this.parentListeners[e]=r.filter(function(e){return t!==e}))},e.prototype.addParentListener=function(e,t){var r=this.parentListeners[JSON.stringify(e)];null==r&&(r=[],this.parentListeners[JSON.stringify(e)]=r),r.push(t)},e}();Y.AbstractOperationStore=AbstractOperationStore;var Struct={Operation:{create:regeneratorRuntime.mark(function t(e){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.store.y.connector.userId,t.delegateYield(this.getState(r),"t0",2);case 2:return n=t.t0,e.id=[r,n.clock],t.delegateYield(this.addOperation(e),"t1",5);case 5:if(t.t2=t.t1,t.t2!==!1){t.next=8;break}throw new Error("This is highly unexpected :(");case 8:return this.store.y.connector.broadcast({type:"update",ops:[Struct[e.struct].encode(e)]}),t.abrupt("return",e);case 10:case"end":return t.stop()}},t,this)})},Insert:{create:regeneratorRuntime.mark(function r(e){var t,n,a,i,s;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0!==e.left&&void 0!==e.right&&void 0!==e.parent){r.next=2;break}throw new Error("You must define left, right, and parent!");case 2:return e.origin=e.left,e.struct="Insert",r.delegateYield(Struct.Operation.create.call(this,e),"t0",5);case 5:if(null==e.left){r.next=10;break}return r.delegateYield(this.getOperation(e.left),"t1",7);case 7:return t=r.t1,t.right=e.id,r.delegateYield(this.setOperation(t),"t2",10);case 10:if(null==e.right){r.next=15;break}return r.delegateYield(this.getOperation(e.right),"t3",12);case 12:return n=r.t3,n.left=e.id,r.delegateYield(this.setOperation(n),"t4",15);case 15:return r.delegateYield(this.getOperation(e.parent),"t5",16);case 16:if(a=r.t5,null==e.parentSub){r.next=23;break}if(!compareIds(a.map[e.parentSub],e.right)){r.next=21;break}return a.map[e.parentSub]=e.id,r.delegateYield(this.setOperation(a),"t6",21);case 21:r.next=29;break;case 23:if(i=compareIds(a.start,e.right),s=compareIds(a.end,e.left),!i&&!s){r.next=29;break}return i&&(a.start=e.id),s&&(a.end=e.id),r.delegateYield(this.setOperation(a),"t7",29);case 29:return r.abrupt("return",e);case 30:case"end":return r.stop()}},r,this)}),encode:function(e){return e},requiredOps:function(e){var t=[];return null!=e.left&&t.push(e.left),null!=e.right&&t.push(e.right),null==e.right&&null==e.left&&t.push(e.parent),null!=e.opContent&&t.push(e.opContent),t},getDistanceToOrigin:regeneratorRuntime.mark(function n(e){var t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(null!=e.left){n.next=4;break}return n.abrupt("return",0);case 4:return t=0,n.delegateYield(this.getOperation(e.left),"t0",6);case 6:r=n.t0;case 7:if(compareIds(e.origin,r?r.id:null)){n.next=17;break}if(t++,null!=r.left){n.next=13;break}return n.abrupt("break",17);case 13:return n.delegateYield(this.getOperation(r.left),"t1",14);case 14:r=n.t1;case 15:n.next=7;break;case 17:return n.abrupt("return",t);case 18:case"end":return n.stop()}},n,this)}),execute:regeneratorRuntime.mark(function a(e){var t,r,n,i,s,o,u,c,l;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.delegateYield(Struct.Insert.getDistanceToOrigin.call(this,e),"t0",1);case 1:if(r=t=a.t0,null==e.left){a.next=14;break}return a.delegateYield(this.getOperation(e.left),"t1",4);case 4:if(n=a.t1,null!=n.right){a.next=9;break}a.t2=null,a.next=11;break;case 9:return a.delegateYield(this.getOperation(n.right),"t3",10);case 10:a.t2=a.t3;case 11:n=a.t2,a.next=25;break;case 14:return a.delegateYield(this.getOperation(e.parent),"t4",15);case 15:if(i=a.t4,o=e.parentSub?i.map[e.parentSub]:i.start,null!=o){a.next=21;break}a.t5=null,a.next=23;break;case 21:return a.delegateYield(this.getOperation(o),"t6",22);case 22:a.t5=a.t6;case 23:s=a.t5,n=s;case 25:if(null==n||compareIds(n.id,e.right)){a.next=48;break}return a.delegateYield(Struct.Insert.getDistanceToOrigin.call(this,n),"t7",28);case 28:if(u=a.t7,u!==t){a.next=33;break}n.id[0]<e.id[0]&&(e.left=n.id,r=t+1),a.next=38;break;case 33:if(!(t>u)){a.next=37;break}u>=t-r&&(e.left=n.id,r=t+1),a.next=38;break;case 37:return a.abrupt("break",51);case 38:if(t++,!n.right){a.next=44;break}return a.delegateYield(this.getOperation(n.right),"t9",41);case 41:a.t8=a.t9,a.next=45;break;case 44:a.t8=null;case 45:n=a.t8,a.next=49;break;case 48:return a.abrupt("break",51);case 49:a.next=25;break;case 51:if(c=null,l=null,a.t10=i,a.t10){a.next=57;break}return a.delegateYield(this.getOperation(e.parent),"t11",56);case 56:a.t10=a.t11;case 57:if(i=a.t10,null==e.left){a.next=70;break}return a.delegateYield(this.getOperation(e.left),"t12",60);case 60:return c=a.t12,e.right=c.right,a.delegateYield(this.addOperation(e),"t13",63);case 63:if(a.t14=a.t13,a.t14!==!1){a.next=66;break}return a.abrupt("return");case 66:return c.right=e.id,a.delegateYield(this.setOperation(c),"t15",68);case 68:a.next=75;break;case 70:return e.right=e.parentSub?i.map[e.parentSub]||null:i.start,a.delegateYield(this.addOperation(e),"t16",72);case 72:if(a.t17=a.t16,a.t17!==!1){a.next=75;break}return a.abrupt("return");case 75:if(null==e.right){a.next=80;break}return a.delegateYield(this.getOperation(e.right),"t18",77);case 77:return l=a.t18,l.left=e.id,a.delegateYield(this.setOperation(l),"t19",80);case 80:if(null==e.parentSub){a.next=86;break}if(null!=c){a.next=84;break}return i.map[e.parentSub]=e.id,a.delegateYield(this.setOperation(i),"t20",84);case 84:a.next=90;break;case 86:if(null!=l&&null!=c){a.next=90;break}return null==l&&(i.end=e.id),null==c&&(i.start=e.id),a.delegateYield(this.setOperation(i),"t21",90);case 90:case"end":return a.stop()}},a,this)})},List:{create:regeneratorRuntime.mark(function i(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e.start=null,e.end=null,e.struct="List",t.delegateYield(Struct.Operation.create.call(this,e),"t0",4);case 4:return t.abrupt("return",t.t0);case 5:case"end":return t.stop()}},i,this)}),encode:function(e){return{struct:"List",id:e.id,type:e.type}},requiredOps:function(){return[]},execute:regeneratorRuntime.mark(function s(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e.start=null,e.end=null,t.delegateYield(this.addOperation(e),"t0",3);case 3:if(t.t1=t.t0,t.t1!==!1){t.next=6;break}return t.abrupt("return");case 6:case"end":return t.stop()}},s,this)}),ref:regeneratorRuntime.mark(function o(e,t){var r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(null!=e.start){n.next=2;break}return n.abrupt("return",null);case 2:return n.delegateYield(this.getOperation(e.start),"t0",3);case 3:r=n.t0;case 4:if(0===t||null==r.right){n.next=10;break}return n.delegateYield(this.getOperation(r.right),"t1",6);case 6:r=n.t1,t--,n.next=4;break;case 10:return n.abrupt("return",r);case 11:case"end":return n.stop()}},o,this)}),map:regeneratorRuntime.mark(function u(e,t){var r,n;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:e=e.start,r=[];case 2:if(null==e){a.next=9;break}return a.delegateYield(this.getOperation(e),"t0",4);case 4:n=a.t0,r.push(t(n.content)),e=n.right,a.next=2;break;case 9:return a.abrupt("return",r);case 10:case"end":return a.stop()}},u,this)}),insert:regeneratorRuntime.mark(function c(e,t,r){var n,a,i,s,c;return regeneratorRuntime.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.delegateYield(Struct.List.ref.call(this,e,t),"t0",1);case 1:n=o.t0,a=null!=n?n.id:null,i=null!=n?n.left:null,o.t1=regeneratorRuntime.keys(r);case 5:if((o.t2=o.t1()).done){o.next=12;break}return s=o.t2.value,c={left:i,right:a,content:r[s],parent:e.id},o.delegateYield(Struct.Insert.create.call(this,c),"t3",9);case 9:i=o.t3.id,o.next=5;break;case 12:case"end":return o.stop()}},c,this)})},Map:{create:regeneratorRuntime.mark(function l(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e.map={},e.struct="Map",t.delegateYield(Struct.Operation.create.call(this,e),"t0",3);case 3:return t.abrupt("return",t.t0);case 4:case"end":return t.stop()}},l,this)}),encode:function(e){return{struct:"Map",type:e.type,id:e.id}},requiredOps:function(){return[]},execute:regeneratorRuntime.mark(function p(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.addOperation(e),"t0",1);case 1:if(t.t1=t.t0,t.t1!==!1){t.next=4;break}return t.abrupt("return");case 4:case"end":return t.stop()}},p,this)}),get:regeneratorRuntime.mark(function f(e,t){var r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.delegateYield(this.getOperation(e.map[t]),"t0",1);case 1:if(r=n.t0,null!=r){n.next=6;break}n.t1=void 0,n.next=13;break;case 6:if(null!=r.opContent){n.next=10;break}n.t2=r.content,n.next=12;break;case 10:return n.delegateYield(this.getType(r.opContent),"t3",11);case 11:n.t2=n.t3;case 12:n.t1=n.t2;case 13:return n.abrupt("return",n.t1);case 14:case"end":return n.stop()}},f,this)}),set:regeneratorRuntime.mark(function h(e,t,r){var n,a;return regeneratorRuntime.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return n={left:null,right:e.map[t]||null,parent:e.id,parentSub:t},null!=r&&null!=r._model&&null!=(a=r._model.id)&&2===a.length?n.opContent=a:n.content=r,i.delegateYield(Struct.Insert.create.call(this,n),"t0",3);case 3:case"end":return i.stop()}},h,this)})}};Y.Struct=Struct;var globalRoom={users:{},buffers:{},removeUser:function(e){for(var t in this.users)this.users[t].userLeft(e);delete this.users[e],delete this.buffers[e]},addUser:function(e){this.users[e.userId]=e,this.buffers[e.userId]=[];for(var t in this.users)if(t!==e.userId){var r=this.users[t];r.userJoined(e.userId,"master"),e.userJoined(r.userId,"master")}}},userIdCounter=0,Test=function(e){function t(r,n){if(_classCallCheck(this,t),void 0===n)throw new Error("Options must not be undefined!");n.role="master",n.forwardToSyncingClients=!1,e.call(this,r,n),this.setUserId(userIdCounter++ +""),globalRoom.addUser(this),this.globalRoom=globalRoom}return _inherits(t,e),t.prototype.send=function(e,t){globalRoom.buffers[e].push(JSON.parse(JSON.stringify([this.userId,t])))},t.prototype.broadcast=function(e){for(var t in globalRoom.buffers)globalRoom.buffers[t].push(JSON.parse(JSON.stringify([this.userId,e])))},t.prototype.disconnect=function(){globalRoom.removeUser(this.userId)},t.prototype.flushAll=function(){for(var e=!0;e;)e=_flushOne()},t.prototype.flushOne=function(){_flushOne()},t}(AbstractConnector);Y.Test=Test;var WebRTC=function(e){function t(r){if(_classCallCheck(this,t),void 0===r)throw new Error("Options must not be undefined!");e.call(this,{role:"slave"});var n=r.room;null==r.url&&(r.url="https://yatta.ninja:8888");var a=new SimpleWebRTC(r);this.swr=a;var i=this;a.once("connectionReady",function(e){a.joinRoom(n),a.once("joinedRoom",function(){i.setUserId(e);var t;for(t in i.swr.webrtc.peers)i.userJoined(i.swr.webrtc.peers[t].id,"master");a.on("channelMessage",function(e,t,r){null!=r.type&&i.receiveMessage(e.id,r.payload)})}),a.on("createdPeer",function(e){i.userJoined(e.id,"master")}),a.on("peerStreamRemoved",function(e){i.userLeft(e.id)})})}return _inherits(t,e),t.prototype.send=function r(e,t){var n=this,r=function a(){var r,i=n.swr.webrtc.getPeers(e)[0];i&&(r=i.sendDirectly("simplewebrtc","yjs",t)),r||setTimeout(a,500)};r()},t.prototype.broadcast=function(e){this.swr.sendDirectlyToAll("simplewebrtc","yjs",e)},t}(AbstractConnector);Y.WebRTC=WebRTC,Y.IndexedDB=function(){var e=function(e){function t(r){_classCallCheck(this,t),e.call(this,r),this.transaction=r.db.transaction(["OperationStore","StateVector"],"readwrite"),this.sv=this.transaction.objectStore("StateVector"),this.os=this.transaction.objectStore("OperationStore"),this.buffer={}}return _inherits(t,e),t.prototype.setOperation=regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.os.put(e);case 2:return this.buffer[JSON.stringify(e.id)]=e,t.abrupt("return",e);case 4:case"end":return t.stop()}},r,this)}),t.prototype.getOperation=regeneratorRuntime.mark(function n(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(t=this.buffer[JSON.stringify(e)],null!=t){r.next=6;break}return r.next=4,this.os.get(e);case 4:t=r.sent,this.buffer[JSON.stringify(e)]=t;case 6:return r.abrupt("return",t);case 7:case"end":return r.stop()}},n,this)}),t.prototype.removeOperation=regeneratorRuntime.mark(function a(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.buffer[JSON.stringify(e)]=null,t.next=3,this.os["delete"](e);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},a,this)}),t.prototype.setState=regeneratorRuntime.mark(function i(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sv.put(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},i,this)}),t.prototype.getState=regeneratorRuntime.mark(function s(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.sv.get(e);case 2:if(r.t0=t=r.sent,null==r.t0){r.next=7;break}return r.abrupt("return",t);case 7:return r.abrupt("return",{user:e,clock:0});case 8:case"end":return r.stop()}},s,this)}),t.prototype.getStateVector=regeneratorRuntime.mark(function o(){var e,t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:e=[],t=this.sv.openCursor();case 2:return n.next=4,t;case 4:if(n.t0=r=n.sent,null==n.t0){n.next=10;break}e.push(r.value),r["continue"](),n.next=2;break;case 10:return n.abrupt("return",e);case 11:case"end":return n.stop()}},o,this)}),t.prototype.getStateSet=regeneratorRuntime.mark(function u(){var e,t,r,n,a,i,s;return regeneratorRuntime.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.delegateYield(this.getStateVector(),"t0",1);case 1:e=o.t0,t={},r=e,n=Array.isArray(r),a=0,r=n?r:r[Symbol.iterator]();case 4:if(!n){o.next=10;break}if(!(a>=r.length)){o.next=7;break}return o.abrupt("break",18);case 7:i=r[a++],o.next=14;break;case 10:if(a=r.next(),!a.done){o.next=13;break}return o.abrupt("break",18);case 13:i=a.value;case 14:s=i,t[s.user]=s.clock;case 16:o.next=4;break;case 18:return o.abrupt("return",t);case 19:case"end":return o.stop()}},u,this)}),t.prototype.getOperations=regeneratorRuntime.mark(function c(e){var t,r,n,a,i,s,o,u,l,p,f,h,d;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return null==e&&(e={}),t=[],c.delegateYield(this.getStateVector(),"t0",3);case 3:r=c.t0,n=r,a=Array.isArray(n),i=0,n=a?n:n[Symbol.iterator]();case 5:if(!a){c.next=11;break}if(!(i>=n.length)){c.next=8;break}return c.abrupt("break",31);case 8:s=n[i++],c.next=15;break;case 11:if(i=n.next(),!i.done){c.next=14;break}return c.abrupt("break",31);case 14:s=i.value;case 15:o=s,u=o.user,l=e[u]||0,p=o.clock,f=IDBKeyRange.bound([u,l],[u,p]),h=this.os.openCursor(f);case 21:return c.next=23,h;case 23:if(c.t1=d=c.sent,null==c.t1){c.next=29;break}t.push(d.value),d["continue"](),c.next=21;break;case 29:c.next=5;break;case 31:return c.abrupt("return",t);case 32:case"end":return c.stop()}},c,this)}),t}(AbstractTransaction),t=function(t){
function r(n,a){function i(e){var t=e.value;e.done||(t.constructor===IDBRequest||t.constructor===IDBCursor?(t.onsuccess=function(){i(o.next(t.result))},t.onerror=function(e){o["throw"](e)}):t===s.transactionQueue?t.queue.length>0?i(o.next(t.queue.shift())):t.onRequest=function(){t.onRequest=null,i(o.next(t.queue.shift()))}:t.constructor===IDBOpenDBRequest?(t.onsuccess=function(e){var t=e.target.result;i(o.next(t))},t.onerror=function(){o["throw"]("Couldn't open IndexedDB database!")},t.onupgradeneeded=function(e){var t=e.target.result;try{t.createObjectStore("OperationStore",{keyPath:"id"}),t.createObjectStore("StateVector",{keyPath:"user"})}catch(r){}}):o["throw"]("You can not yield this type!"))}if(_classCallCheck(this,r),t.call(this,n),null==a&&(a={}),null==a.namespace||"string"!=typeof a.namespace)throw new Error("IndexedDB: expect a string (opts.namespace)!");this.namespace=a.namespace,this.idbVersion=null!=a.idbVersion?a.idbVersion:5,this.transactionQueue={queue:[],onRequest:null};var s=this,o=regeneratorRuntime.mark(function u(){var t,r,n,i;return regeneratorRuntime.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,indexedDB.open(a.namespace,s.idbVersion);case 2:s.db=o.sent,t=s.transactionQueue,r=null,n=!0;case 6:if(!n){o.next=14;break}return o.next=9,t;case 9:return i=o.sent,r=new e(s),o.delegateYield(i.call(r,i),"t0",12);case 12:o.next=6;break;case 14:case"end":return o.stop()}},u,this)})();i(o.next())}return _inherits(r,t),r.prototype.requestTransaction=function(e){this.transactionQueue.queue.push(e),null!=this.transactionQueue.onRequest&&this.transactionQueue.onRequest()},r.prototype.removeDatabase=regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.db.close(),e.next=3,indexedDB.deleteDatabase(this.namespace);case 3:case"end":return e.stop()}},n,this)}),r}(AbstractOperationStore);return t}(),Y.Memory=function(){var e=function(e){function t(r){_classCallCheck(this,t),e.call(this,r),this.ss=r.ss,this.os=r.os}return _inherits(t,e),t.prototype.setOperation=regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("Insert"!==e.struct||void 0!==e.right){t.next=2;break}throw new Error("here!");case 2:return this.os[JSON.stringify(e.id)]=e,t.abrupt("return",e);case 4:case"end":return t.stop()}},r,this)}),t.prototype.getOperation=regeneratorRuntime.mark(function n(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(t=this.os[JSON.stringify(e)],null!=t){r.next=5;break}throw new Error("Op does not exist..");case 5:return r.abrupt("return",t);case 6:case"end":return r.stop()}},n,this)}),t.prototype.removeOperation=regeneratorRuntime.mark(function a(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:delete this.os[JSON.stringify(e)];case 1:case"end":return t.stop()}},a,this)}),t.prototype.setState=regeneratorRuntime.mark(function i(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.ss[e.user]=e.clock;case 1:case"end":return t.stop()}},i,this)}),t.prototype.getState=regeneratorRuntime.mark(function s(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=this.ss[e],null==t&&(t=0),r.abrupt("return",{user:e,clock:t});case 3:case"end":return r.stop()}},s,this)}),t.prototype.getStateVector=regeneratorRuntime.mark(function o(){var e,t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:e=[];for(t in this.ss)r=this.ss[t],e.push({user:t,clock:r});return n.abrupt("return",e);case 3:case"end":return n.stop()}},o,this)}),t.prototype.getStateSet=regeneratorRuntime.mark(function u(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.ss);case 1:case"end":return e.stop()}},u,this)}),t.prototype.getOperations=regeneratorRuntime.mark(function c(e){var t,r,n,a,i,s,o,u,l,p,f,h;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return null==e&&(e={}),t=[],c.delegateYield(this.getStateVector(),"t0",3);case 3:r=c.t0,n=r,a=Array.isArray(n),i=0,n=a?n:n[Symbol.iterator]();case 5:if(!a){c.next=11;break}if(!(i>=n.length)){c.next=8;break}return c.abrupt("break",35);case 8:s=n[i++],c.next=15;break;case 11:if(i=n.next(),!i.done){c.next=14;break}return c.abrupt("break",35);case 14:s=i.value;case 15:if(o=s,u=o.user,"_"!==u){c.next=19;break}return c.abrupt("continue",33);case 19:l=e[u]||0,p=o.clock,f=l;case 22:if(!(p>=f)){c.next=33;break}if(h=this.os[JSON.stringify([u,f])],null==h){c.next=30;break}return h=Struct[h.struct].encode(h),c.t1=t,c.delegateYield(this.makeOperationReady.call(this,e,h),"t2",28);case 28:c.t3=c.t2,c.t1.push.call(c.t1,c.t3);case 30:f++,c.next=22;break;case 33:c.next=5;break;case 35:return c.abrupt("return",t);case 36:case"end":return c.stop()}},c,this)}),t.prototype.makeOperationReady=regeneratorRuntime.mark(function l(e,t){var r,n;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:n=t;case 1:if(null==n.right){a.next=9;break}return a.delegateYield(this.getOperation(n.right),"t0",3);case 3:if(n=a.t0,r=e[n.id[0]],!(null!=r&&n.id[1]<r)){a.next=7;break}return a.abrupt("break",9);case 7:a.next=1;break;case 9:return t=copyObject(t),t.right=null==n?null:n.id,a.abrupt("return",t);case 12:case"end":return a.stop()}},l,this)}),t}(AbstractTransaction),t=function(t){function r(e){_classCallCheck(this,r),t.call(this,e),this.os={},this.ss={}}return _inherits(r,t),r.prototype.requestTransaction=function(t){for(var r=new e(this),n=t.call(r,new Y.Map.Create(["_",0])),a=n.next();!a.done;){if("transaction"!==a.value)throw new Error("You may not yield this type. (Maybe you meant to use 'yield*'?)");a=n.next(r)}},r.prototype.removeDatabase=regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:delete this.os;case 1:case"end":return e.stop()}},n,this)}),r}(AbstractOperationStore);return t}();var N=function(){function e(t){if(_classCallCheck(this,e),this.val=t,this.color=!0,this._left=null,this._right=null,this._parent=null,null==t.id)throw new Error("You must define id!")}return e.prototype.isRed=function(){return this.color},e.prototype.isBlack=function(){return!this.color},e.prototype.redden=function(){return this.color=!0,this},e.prototype.blacken=function(){return this.color=!1,this},e.prototype.rotateLeft=function(e){var t=this.parent,r=this.right,n=this.right.left;if(r.left=this,this.right=n,null==t)e.root=r;else if(t.left===this)t.left=r;else{if(t.right!==this)throw new Error("The elements are wrongly connected!");t.right=r}},e.prototype.rotateRight=function(e){var t=this.parent,r=this.left,n=this.left.right;if(r.right=this,this.left=n,null==t)e.root=r;else if(t.left===this)t.left=r;else{if(t.right!==this)throw new Error("The elements are wrongly connected!");t.right=r}},e.prototype.getUncle=function(){return this.parent===this.parent.parent.left?this.parent.parent.right:this.parent.parent.left},_createClass(e,[{key:"grandparent",get:function(){return this.parent.parent}},{key:"parent",get:function(){return this._parent}},{key:"left",get:function(){return this._left},set:function(e){null!=e&&(e._parent=this),this._left=e}},{key:"right",get:function(){return this._right},set:function(e){null!=e&&(e._parent=this),this._right=e}}]),e}(),RBTree=function(){function e(){_classCallCheck(this,e),this.root=null}return e.prototype.find=function(e){var t=this.root;if(null==t)return!1;for(;;){if(null==t)return!1;if(e<t.val.id)t=t.left;else{if(!(t.val.id<e))return t.val;t=t.right}}},e.prototype.add=function(e){var t=new N(e);if(null!=this.root){for(var r=this.root;;)if(t.val.id<r.val.id){if(null==r.left){r.left=t;break}r=r.left}else{if(!(r.val.id<t.val.id))return!1;if(null==r.right){r.right=t;break}r=r.right}this.fixInsert(t)}else this.root=t;this.root.blacken()},e.prototype.fixInsert=function(e){if(null==e.parent)return void e.blacken();if(!e.parent.isBlack()){var t=e.getUncle();null!=t&&t.isRed()?(e.parent.blacken(),t.blacken(),e.grandparent.redden(),this.fixInsert(e.grandparent)):(e===e.parent.right&&e.parent===e.grandparent.left?(e.parent.rotateLeft(this),e=e.left):e===e.parent.left&&e.parent===e.grandparent.right&&(e.parent.rotateRight(this),e=e.right),e.parent.blacken(),e.grandparent.redden(),e===e.parent.left?e.grandparent.rotateRight(this):e.grandparent.rotateLeft(this))}},e}();!function(){var e=function(){function e(t){_classCallCheck(this,e),this._model=t}return e.prototype.val=regeneratorRuntime.mark(function t(e){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,"transaction";case 2:if(r=t.sent,null==e){t.next=9;break}return t.delegateYield(Y.Struct.List.ref.call(r,this._model,e),"t0",5);case 5:return n=t.t0,t.abrupt("return",n?n.content:null);case 9:return t.delegateYield(Y.Struct.List.map.call(r,this._model,function(e){return e}),"t1",10);case 10:return t.abrupt("return",t.t1);case 11:case"end":return t.stop()}},t,this)}),e.prototype.insert=regeneratorRuntime.mark(function r(e,t){var n;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,"transaction";case 2:return n=r.sent,r.delegateYield(Y.Struct.List.insert.call(n,this._model,e,t),"t0",4);case 4:case"end":return r.stop()}},r,this)}),e}();Y.List=regeneratorRuntime.mark(function t(){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,"transaction";case 2:return r=t.sent,t.delegateYield(Y.Struct.List.create.call(r,{type:"List"}),"t0",4);case 4:return n=t.t0,t.abrupt("return",new e(n));case 6:case"end":return t.stop()}},t,this)}),Y.List.Create=e}(),function(){var e=function(){function e(t){_classCallCheck(this,e),this._model=t}return e.prototype.val=regeneratorRuntime.mark(function t(){var e,r,n=arguments;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,"transaction";case 2:return e=t.sent,t.delegateYield(e.getOperation(this._model),"t0",4);case 4:if(r=t.t0,1!==n.length){t.next=10;break}return t.delegateYield(Y.Struct.Map.get.call(e,r,n[0]),"t1",7);case 7:return t.abrupt("return",t.t1);case 10:if(2!==n.length){t.next=15;break}return t.delegateYield(Y.Struct.Map.set.call(e,r,n[0],n[1]),"t2",12);case 12:return t.abrupt("return",t.t2);case 15:throw new Error("Implement this case!");case 16:case"end":return t.stop()}},t,this)}),e}();Y.Map=regeneratorRuntime.mark(function t(){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,"transaction";case 2:if(r=t.sent,!(this instanceof Y.AbstractOperationStore)){t.next=9;break}return t.delegateYield(Y.Struct.map.create.call(r,{type:"Map"}),"t0",5);case 5:return n=t.t0,t.abrupt("return",new e(n));case 9:throw new Error("Don't use `new` to create this type!");case 10:case"end":return t.stop()}},t,this)}),Y.Map.Create=e}();
//# sourceMappingURL=y.js.map