!function t(e,n,r){function i(u,s){if(!n[u]){if(!e[u]){var p="function"==typeof require&&require;if(!s&&p)return p(u,!0);if(o)return o(u,!0);throw new Error("Cannot find module '"+u+"'")}var a=n[u]={exports:{}};e[u][0].call(a.exports,function(t){var n=e[u][1][t];return i(n?n:t)},a,a.exports,t,e,n,r)}return n[u].exports}for(var o="function"==typeof require&&require,u=0;ur;r++)e=t[r],n.push(this.parseOperation(e));for(i=0,s=n.length;s>i;i++)e=n[i],this.HB.addOperation(e);for(o=0,p=n.length;p>o;o++)e=n[o],e.execute()||this.unprocessed_ops.push(e);return this.tryUnprocessed()},t.prototype.applyOpsCheckDouble=function(t){var e,n,r,i;for(i=[],n=0,r=t.length;r>n;n++)e=t[n],i.push(null!=this.HB.getOperation(e.uid)?this.applyOp(e):void 0);return i},t.prototype.applyOps=function(t){var e,n,r,i;for(i=[],n=0,r=t.length;r>n;n++)e=t[n],i.push(this.applyOp(e));return i},t.prototype.applyOp=function(t){var e;return e=this.parseOperation(t),this.HB.addToCounter(e),e.execute()?this.HB.addOperation(e):this.unprocessed_ops.push(e),this.tryUnprocessed()},t.prototype.tryUnprocessed=function(){var t,e,n,r,i,o,u;for(u=[];;){for(t=this.unprocessed_ops.length,n=[],o=this.unprocessed_ops,r=0,i=o.length;i>r;r++)e=o[r],e.execute()?this.HB.addOperation(e):n.push(e);if(this.unprocessed_ops=n,this.unprocessed_ops.length===t)break;u.push(void 0)}return u},t}(),e.exports=n},{}],2:[function(t,e){var n,r,i,o;o=t("../Types/JsonTypes"),r=t("../HistoryBuffer"),n=t("../Engine"),i=function(){function t(t,e){var i,u;this.HB=new r(t),u=o(this.HB),this.engine=new n(this.HB,u.parser),this.connector=new e(this.engine,this.HB,u.execution_listener,this),i=new u.types.JsonType(this.HB.getReservedUniqueIdentifier()),this.HB.addOperation(i).execute(),this.root_element=i}return t.prototype.getRootElement=function(){return this.root_element},t.prototype.getEngine=function(){return this.engine},t.prototype.getConnector=function(){return this.connector},t.prototype.getHistoryBuffer=function(){return this.HB},t.prototype.setMutableDefault=function(t){return this.root_element.setMutableDefault(t)},t.prototype.getUserId=function(){return this.HB.getUserId()},t.prototype.val=function(t,e,n){return this.root_element.val(t,e,n)},Object.defineProperty(t.prototype,"value",{get:function(){return this.root_element.value},set:function(t){var e,n,r;if(t.constructor==={}.constructor){r=[];for(e in t)n=t[e],r.push(this.val(e,n,"immutable"));return r}throw new Error("You must only set Object values!")}}),t}(),"undefined"!=typeof window&&null!==window&&(window.JsonYatta=i),e.exports=i},{"../Engine":1,"../HistoryBuffer":3,"../Types/JsonTypes":5}],3:[function(t,e){var n;n=function(){function t(t){this.user_id=t,this.operation_counter={},this.buffer={},this.change_listeners=[]}return t.prototype.getUserId=function(){return this.user_id},t.prototype.getReservedUniqueIdentifier=function(){return{creator:"_",op_number:"_"}},t.prototype.getOperationCounter=function(){var t,e,n,r;e={},r=this.operation_counter;for(n in r)t=r[n],e[n]=t;return e},t.prototype._encode=function(t){var e,n,r,i,o,u,s,p,a,c;null==t&&(t={}),e=[],p=function(e,n){if(null==e||null==n)throw new Error("dah!");return null==t[e]||t[e]<=n},c=this.buffer;for(s in c){a=c[s];for(o in a)if(n=a[o],!isNaN(parseInt(o))&&p(s,o)){if(r=n._encode(),null!=n.next_cl){for(i=n.next_cl;null!=i.next_cl&&p(i.creator,i.op_number);)i=i.next_cl;r.next=i.getUid()}else if(null!=n.prev_cl){for(u=n.prev_cl;null!=u.prev_cl&&p(i.creator,i.op_number);)u=u.prev_cl;r.prev=u.getUid()}e.push(r)}}return e},t.prototype.getNextOperationIdentifier=function(t){var e;return null==t&&(t=this.user_id),null==this.operation_counter[t]&&(this.operation_counter[t]=0),e={creator:t,op_number:this.operation_counter[t]},this.operation_counter[t]++,e},t.prototype.getOperation=function(t){var e;if(t instanceof Object)return null!=(e=this.buffer[t.creator])?e[t.op_number]:void 0;if(null!=t)throw new Error("This type of uid is not defined!")},t.prototype.addOperation=function(t){if(null==this.buffer[t.creator]&&(this.buffer[t.creator]={}),null!=this.buffer[t.creator][t.op_number])throw new Error("You must not overwrite operations!");return this.buffer[t.creator][t.op_number]=t,t},t.prototype.addToCounter=function(t){return null==this.operation_counter[t.creator]&&(this.operation_counter[t.creator]=0),"number"==typeof t.op_number&&t.creator!==this.getUserId()?this.operation_counter[t.creator]++:void 0},t}(),e.exports=n},{}],4:[function(t,e){var n={}.hasOwnProperty,r=function(t,e){function r(){this.constructor=t}for(var i in e)n.call(e,i)&&(t[i]=e[i]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};e.exports=function(t){var e,n,i,o,u,s,p;return p={},s=[],u=function(){function e(e){null==e&&(e=t.getNextOperationIdentifier()),this.creator=e.creator,this.op_number=e.op_number}return e.prototype.on=function(t,e){var n;return null==this.event_listeners&&(this.event_listeners={}),null==(n=this.event_listeners)[t]&&(n[t]=[]),this.event_listeners[t].push(e)},e.prototype.callEvent=function(t,e){var n,r,i,o,u;if(null!=this.event_listeners[t]){for(o=this.event_listeners[t],u=[],r=0,i=o.length;i>r;r++)n=o[r],u.push(n.call(this,t,e));return u}},e.prototype.setParent=function(t){return this.parent=t},e.prototype.getUid=function(){return{creator:this.creator,op_number:this.op_number}},e.prototype.execute=function(){var t,e,n;for(this.is_executed=!0,e=0,n=s.length;n>e;e++)(t=s[e])(this._encode());return this},e.prototype.saveOperation=function(t,e){return null!=(null!=e?e.execute:void 0)?this[t]=e:null!=e?(null==this.unchecked&&(this.unchecked={}),this.unchecked[t]=e):void 0},e.prototype.validateSavedOperations=function(){var e,n,r,i,o,u;o={},i=this,u=this.unchecked;for(e in u)r=u[e],n=t.getOperation(r),n?this[e]=n:(o[e]=r,i=!1);return delete this.unchecked,i||(this.unchecked=o),i},e}(),e=function(t){function e(t,n){this.saveOperation("deletes",n),e.__super__.constructor.call(this,t)}return r(e,t),e.prototype._encode=function(){return{type:"Delete",uid:this.getUid(),deletes:this.deletes.getUid()}},e.prototype.execute=function(){return this.validateSavedOperations()?(this.deletes.applyDelete(this),e.__super__.execute.apply(this,arguments),this):!1},e}(u),p.Delete=function(t){var n,r;return r=t.uid,n=t.deletes,new e(r,n)},o=function(t){function e(t,n,r,i){this.saveOperation("prev_cl",n),this.saveOperation("next_cl",r),null!=i?this.saveOperation("origin",i):this.saveOperation("origin",n),e.__super__.constructor.call(this,t)}return r(e,t),e.prototype.applyDelete=function(t){return null==this.deleted_by&&(this.deleted_by=[]),this.deleted_by.push(t)},e.prototype.isDeleted=function(){var t;return(null!=(t=this.deleted_by)?t.length:void 0)>0},e.prototype.getDistanceToOrigin=function(){var t,e;for(t=0,e=this.prev_cl;;){if(this.origin===e)break;if(t++,this===this.prev_cl)throw new Error("this should not happen ;) ");e=e.prev_cl}return t},e.prototype.update_sl=function(){var t;return t=this.prev_cl,update("prev_cl","prev_sl"),update("next_cl","prev_sl")},e.prototype.execute=function(){var t,n,r,i,o;if(null!=this.is_executed)return this;if(this.validateSavedOperations()){if((null!=(i=this.prev_cl)?i.validateSavedOperations():void 0)&&(null!=(o=this.next_cl)?o.validateSavedOperations():void 0)&&this.prev_cl.next_cl!==this){for(t=0,r=this.prev_cl.next_cl,n=0;;){if(null==r&&(console.log(JSON.stringify(this.prev_cl.getUid())),console.log(JSON.stringify(this.next_cl.getUid()))),r===this.next_cl)break;if(r.getDistanceToOrigin()===n)r.creator0)for(;;){if(e=e.next_cl,e.isDeleted()||(t-=1),0===t)break;if(e instanceof c.Delimiter)throw new Error("position parameter exceeded the length of the document!")}return e},n}(c.Insert),u=function(e){function n(t,e,r,i,o,u,s){n.__super__.constructor.call(this,e,r,i,o,u,s),null!=t&&this.replace(t)}return i(n,e),n.prototype.replace=function(e){var n,r;return n=this.getLastOperation(),r=new s(e,this,void 0,n,n.next_cl),t.addOperation(r).execute()},n.prototype.val=function(){var t;if(t=this.getLastOperation(),t instanceof c.Delimiter)throw new Error("dtrn");return t.val()},n.prototype._encode=function(){var t;return t={type:"ReplaceManager",uid:this.getUid(),beginning:this.beginning.getUid(),end:this.end.getUid()},null!=this.prev_cl&&null!=this.next_cl&&(t.prev=this.prev_cl.getUid(),t.next=this.next_cl.getUid()),null!=this.origin&&this.origin!==this.prev_cl&&(t.origin=this.origin.getUid()),t},n}(r),a.ReplaceManager=function(t){var e,n,r,i,o,s,p;return n=t.content,p=t.uid,s=t.prev,i=t.next,o=t.origin,e=t.beginning,r=t.end,new u(n,p,e,r,s,i,o)},s=function(t){function e(t,n,r,i,o,u){if(this.saveOperation("content",t),this.saveOperation("parent",n),null==i||null==o||null==t)throw new Error("You must define content, prev, and next for Replaceable-types!");e.__super__.constructor.call(this,r,i,o,u)}return i(e,t),e.prototype.val=function(){return this.content},e.prototype.replace=function(t){return this.parent.replace(t)},e.prototype.execute=function(){var t;return this.validateSavedOperations()?("function"==typeof(t=this.content).setReplaceManager&&t.setReplaceManager(this.parent),e.__super__.execute.apply(this,arguments),this):!1},e.prototype._encode=function(){var t;return t={type:"Replaceable",content:this.content.getUid(),ReplaceManager:this.parent.getUid(),prev:this.prev_cl.getUid(),next:this.next_cl.getUid(),uid:this.getUid()},null!=this.origin&&this.origin!==this.prev_cl&&(t.origin=this.origin.getUid()),t},e}(c.Insert),a.Replaceable=function(t){var e,n,r,i,o,u;return e=t.content,i=t.ReplaceManager,u=t.uid,o=t.prev,n=t.next,r=t.origin,new s(e,i,u,o,n,r)},c.ListManager=r,c.MapManager=o,c.ReplaceManager=u,c.Replaceable=s,p}},{"./BasicTypes":4}],7:[function(t,e){var n,r={}.hasOwnProperty,i=function(t,e){function n(){this.constructor=t}for(var i in e)r.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};n=t("./StructuredTypes"),e.exports=function(t){var e,r,o,u,s,p;return s=n(t),p=s.types,u=s.parser,e=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return i(e,t),e}(p.Delete),u.TextDelete=u.Delete,r=function(t){function e(t,n,r,i,o){if(this.content=t,null==r||null==i)throw new Error("You must define prev, and next for TextInsert-types!");e.__super__.constructor.call(this,n,r,i,o)}return i(e,t),e.prototype.getLength=function(){return this.isDeleted()?0:this.content.length},e.prototype.val=function(){return this.isDeleted()?"":this.content},e.prototype._encode=function(){var t;return t={type:"TextInsert",content:this.content,uid:this.getUid(),prev:this.prev_cl.getUid(),next:this.next_cl.getUid()},null!=this.origin&&this.origin!==this.prev_cl&&(t.origin=this.origin.getUid()),t},e}(p.Insert),u.TextInsert=function(t){var e,n,i,o,u;return e=t.content,u=t.uid,o=t.prev,n=t.next,i=t.origin,new r(e,u,o,n,i)},o=function(n){function o(t,e,n,r,i,u){o.__super__.constructor.call(this,t,e,n,r,i,u)}return i(o,n),o.prototype.insertText=function(e,n){var i,o,u,s,p,a;for(o=this.getOperationByPosition(e),a=[],s=0,p=n.length;p>s;s++)i=n[s],u=new r(i,void 0,o.prev_cl,o),a.push(t.addOperation(u).execute());return a},o.prototype.deleteText=function(n,r){var i,o,u,s,a;for(u=this.getOperationByPosition(n),a=[],o=s=0;r>=0?r>s:s>r;o=r>=0?++s:--s){for(i=t.addOperation(new e(void 0,u)).execute(),u=u.next_cl;u.isDeleted();){if(u instanceof p.Delimiter)throw new Error("You can't delete more than there is..");u=u.next_cl}a.push(i._encode())}return a},o.prototype.replaceText=function(e){var n;if(null!=this.replace_manager)return n=t.addOperation(new o(void 0)).execute(),n.insertText(0,e),this.replace_manager.replace(n);throw new Error("This type is currently not maintained by a ReplaceManager!")},o.prototype.val=function(){var t,e;return t=function(){var t,n,r,i;for(r=this.toArray(),i=[],t=0,n=r.length;n>t;t++)e=r[t],i.push(null!=e.val?e.val():"");return i}.call(this),t.join("")},o.prototype.setReplaceManager=function(t){return this.saveOperation("replace_manager",t),this.validateSavedOperations},o.prototype._encode=function(){var t;return t={type:"Word",uid:this.getUid(),beginning:this.beginning.getUid(),end:this.end.getUid()},null!=this.prev_cl&&(t.prev=this.prev_cl.getUid()),null!=this.next_cl&&(t.next=this.next_cl.getUid()),null!=this.origin&&this.origin!==this.prev_cl&&(t.origin=this.origin.getUid()),t},o}(p.ListManager),u.Word=function(t){var e,n,r,i,u,s;return s=t.uid,e=t.beginning,n=t.end,u=t.prev,r=t.next,i=t.origin,new o(s,e,n,u,r,i)},p.TextInsert=r,p.TextDelete=e,p.Word=o,s}},{"./StructuredTypes":6}]},{},[2]);