!function e(t,n,r){function i(s,u){if(!n[s]){if(!t[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var p=n[s]={exports:{}};t[s][0].call(p.exports,function(e){var n=t[s][1][e];return i(n?n:e)},p,p.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;sr;r++)t=e[r],n.push(this.parseOperation(t));for(i=0,u=n.length;u>i;i++)t=n[i],this.HB.addOperation(t);for(o=0,a=n.length;a>o;o++)t=n[o],t.execute()||this.unprocessed_ops.push(t);return this.tryUnprocessed()},e.prototype.applyOpsCheckDouble=function(e){var t,n,r,i;for(i=[],n=0,r=e.length;r>n;n++)t=e[n],i.push(null==this.HB.getOperation(t.uid)?this.applyOp(t):void 0);return i},e.prototype.applyOps=function(e){var t,n,r,i;for(i=[],n=0,r=e.length;r>n;n++)t=e[n],i.push(this.applyOp(t));return i},e.prototype.applyOp=function(e){var t;return t=this.parseOperation(e),this.HB.addToCounter(t),t.execute()?this.HB.addOperation(t):this.unprocessed_ops.push(t),this.tryUnprocessed()},e.prototype.tryUnprocessed=function(){var e,t,n,r,i,o,s;for(s=[];;){for(e=this.unprocessed_ops.length,n=[],o=this.unprocessed_ops,r=0,i=o.length;i>r;r++)t=o[r],t.execute()?this.HB.addOperation(t):n.push(t);if(this.unprocessed_ops=n,this.unprocessed_ops.length===e)break;s.push(void 0)}return s},e}(),t.exports=n},{}],2:[function(e,t){var n,r,i,o;o=e("../Types/JsonTypes"),r=e("../HistoryBuffer"),n=e("../Engine"),i=function(){function e(e,t){var i,s;this.HB=new r(e),s=o(this.HB),this.types=s.types,this.engine=new n(this.HB,s.parser),this.connector=new t(this.engine,this.HB,s.execution_listener,this),i=new this.types.JsonType(this.HB.getReservedUniqueIdentifier()),this.HB.addOperation(i).execute(),this.root_element=i}return e.prototype.getSharedObject=function(){return this.root_element},e.prototype.getEngine=function(){return this.engine},e.prototype.getConnector=function(){return this.connector},e.prototype.getHistoryBuffer=function(){return this.HB},e.prototype.setMutableDefault=function(e){return this.root_element.setMutableDefault(e)},e.prototype.getUserId=function(){return this.HB.getUserId()},e.prototype.toJson=function(){return this.root_element.toJson()},e.prototype.val=function(e,t,n){return this.root_element.val(e,t,n)},e.prototype.on=function(){var e;return(e=this.root_element).on.apply(e,arguments)},e.prototype.deleteListener=function(){var e;return(e=this.root_element).deleteListener.apply(e,arguments)},Object.defineProperty(e.prototype,"value",{get:function(){return this.root_element.value},set:function(e){var t,n,r;if(e.constructor==={}.constructor){r=[];for(t in e)n=e[t],r.push(this.val(t,n,"immutable"));return r}throw new Error("You must only set Object values!")}}),e}(),t.exports=i,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.JsonYatta=i)},{"../Engine":1,"../HistoryBuffer":3,"../Types/JsonTypes":5}],3:[function(e,t){var n;n=function(){function e(e){this.user_id=e,this.operation_counter={},this.buffer={},this.change_listeners=[]}return e.prototype.getUserId=function(){return this.user_id},e.prototype.getReservedUniqueIdentifier=function(){return{creator:"_",op_number:"_"}},e.prototype.getOperationCounter=function(){var e,t,n,r;t={},r=this.operation_counter;for(n in r)e=r[n],t[n]=e;return t},e.prototype._encode=function(e){var t,n,r,i,o,s,u,a,p,l;null==e&&(e={}),t=[],a=function(t,n){if(null==t||null==n)throw new Error("dah!");return null==e[t]||e[t]<=n},l=this.buffer;for(u in l){p=l[u];for(o in p)if(n=p[o],!isNaN(parseInt(o))&&a(u,o)){if(r=n._encode(),null!=n.next_cl){for(i=n.next_cl;null!=i.next_cl&&a(i.creator,i.op_number);)i=i.next_cl;r.next=i.getUid()}else if(null!=n.prev_cl){for(s=n.prev_cl;null!=s.prev_cl&&a(s.creator,s.op_number);)s=s.prev_cl;r.prev=s.getUid()}t.push(r)}}return t},e.prototype.getNextOperationIdentifier=function(e){var t;return null==e&&(e=this.user_id),null==this.operation_counter[e]&&(this.operation_counter[e]=0),t={creator:e,op_number:this.operation_counter[e]},this.operation_counter[e]++,t},e.prototype.getOperation=function(e){var t;if(e instanceof Object)return null!=(t=this.buffer[e.creator])?t[e.op_number]:void 0;if(null!=e)throw new Error("This type of uid is not defined!")},e.prototype.addOperation=function(e){if(null==this.buffer[e.creator]&&(this.buffer[e.creator]={}),null!=this.buffer[e.creator][e.op_number])throw new Error("You must not overwrite operations!");return this.buffer[e.creator][e.op_number]=e,e},e.prototype.addToCounter=function(e){var t;if(null==this.operation_counter[e.creator]&&(this.operation_counter[e.creator]=0),"number"==typeof e.op_number&&e.creator!==this.getUserId()&&e.op_number===this.operation_counter[e.creator]){for(this.operation_counter[e.creator]++,t=[];null!=this.getOperation({creator:e.creator,op_number:this.operation_counter[e.creator]});)t.push(this.operation_counter[e.creator]++);return t}},e}(),t.exports=n},{}],4:[function(e,t){var n=[].slice,r={}.hasOwnProperty,i=function(e,t){function n(){this.constructor=e}for(var i in t)r.call(t,i)&&(e[i]=t[i]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e};t.exports=function(e){var t,r,o,s,u,a,p;return p={},a=[],u=function(){function t(t){null==t&&(t=e.getNextOperationIdentifier()),this.creator=t.creator,this.op_number=t.op_number}return t.prototype.on=function(e,t){var n,r,i,o,s;for(null==this.event_listeners&&(this.event_listeners={}),e.constructor!==[].constructor&&(e=[e]),s=[],i=0,o=e.length;o>i;i++)n=e[i],null==(r=this.event_listeners)[n]&&(r[n]=[]),s.push(this.event_listeners[n].push(t));return s},t.prototype.deleteListener=function(e,t){var n,r,i,o,s;for(e.constructor!==[].constructor&&(e=[e]),s=[],r=0,i=e.length;i>r;r++)n=e[r],s.push(null!=(null!=(o=this.event_listeners)?o[n]:void 0)?this.event_listeners[n]=this.event_listeners[n].filter(function(e){return t!==e}):void 0);return s},t.prototype.callEvent=function(){return this.forwardEvent.apply(this,[this].concat(n.call(arguments)))},t.prototype.forwardEvent=function(){var e,t,r,i,o,s,u,a,p;if(i=arguments[0],t=arguments[1],e=3<=arguments.length?n.call(arguments,2):[],null!=(null!=(u=this.event_listeners)?u[t]:void 0)){for(a=this.event_listeners[t],p=[],o=0,s=a.length;s>o;o++)r=a[o],p.push(r.call.apply(r,[i,t].concat(n.call(e))));return p}},t.prototype.setParent=function(e){this.parent=e},t.prototype.getParent=function(){return this.parent},t.prototype.getUid=function(){return{creator:this.creator,op_number:this.op_number}},t.prototype.execute=function(){var e,t,n;for(this.is_executed=!0,t=0,n=a.length;n>t;t++)(e=a[t])(this._encode());return this},t.prototype.saveOperation=function(e,t){return null!=(null!=t?t.execute:void 0)?this[e]=t:null!=t?(null==this.unchecked&&(this.unchecked={}),this.unchecked[e]=t):void 0},t.prototype.validateSavedOperations=function(){var t,n,r,i,o,s;o={},i=this,s=this.unchecked;for(t in s)r=s[t],n=e.getOperation(r),n?this[t]=n:(o[t]=r,i=!1);return delete this.unchecked,i||(this.unchecked=o),i},t}(),t=function(e){function t(e,n){this.saveOperation("deletes",n),t.__super__.constructor.call(this,e)}return i(t,e),t.prototype._encode=function(){return{type:"Delete",uid:this.getUid(),deletes:this.deletes.getUid()}},t.prototype.execute=function(){return this.validateSavedOperations()?(this.deletes.applyDelete(this),t.__super__.execute.apply(this,arguments)):!1},t}(u),p.Delete=function(e){var n,r;return r=e.uid,n=e.deletes,new t(r,n)},s=function(e){function t(e,n,r,i){this.saveOperation("prev_cl",n),this.saveOperation("next_cl",r),null!=i?this.saveOperation("origin",i):this.saveOperation("origin",n),t.__super__.constructor.call(this,e)}return i(t,e),t.prototype.applyDelete=function(e){return null==this.deleted_by&&(this.deleted_by=[]),this.deleted_by.push(e),null!=this.parent&&1===this.deleted_by.length?this.parent.callEvent("delete",this):void 0},t.prototype.isDeleted=function(){var e;return(null!=(e=this.deleted_by)?e.length:void 0)>0},t.prototype.getDistanceToOrigin=function(){var e,t;for(e=0,t=this.prev_cl;;){if(this.origin===t)break;if(e++,this===this.prev_cl)throw new Error("this should not happen ;) ");t=t.prev_cl}return e},t.prototype.update_sl=function(){var e;return e=this.prev_cl,update("prev_cl","prev_sl"),update("next_cl","prev_sl")},t.prototype.execute=function(){var e,n,r,i,o,s,u;if(null!=this.is_executed)return this;if(this.validateSavedOperations()){if((null!=(o=this.prev_cl)?o.validateSavedOperations():void 0)&&(null!=(s=this.next_cl)?s.validateSavedOperations():void 0)&&this.prev_cl.next_cl!==this){for(e=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||t.isDeleted())&&!(t instanceof l.Delimiter)){for(;t.isDeleted()&&!(t instanceof l.Delimiter);)t=t.next_cl;for(;;){if(t instanceof l.Delimiter)break;if(0>=e&&!t.isDeleted())break;t=t.next_cl,t.isDeleted()||(e-=1)}}return t},n}(l.Insert),s=function(t){function n(e,t,r,i,o,s,u){n.__super__.constructor.call(this,t,r,i,o,s,u),null!=e&&this.replace(e)}return i(n,t),n.prototype.replace=function(t,n){var r,i;return r=this.getLastOperation(),i=new u(t,this,n,r,r.next_cl),e.addOperation(i).execute()},n.prototype.setParent=function(e,t){var r;return this.on("insert",function(e){return function(n,r){return r.next_cl instanceof l.Delimiter?e.parent.callEvent("change",t):void 0}}(this)),this.on("change",function(e){return function(){return e.parent.callEvent("change",t)}}(this)),r=function(e){return function(n,i){return i.next_cl instanceof l.Delimiter&&i.prev_cl instanceof l.Delimiter&&e.parent.callEvent("addProperty",t),e.deleteListener("addProperty",r)}}(this),this.on("insert",r),n.__super__.setParent.call(this,e)},n.prototype.val=function(){var e;return e=this.getLastOperation(),"function"==typeof e.val?e.val():void 0},n.prototype._encode=function(){var e;return e={type:"ReplaceManager",uid:this.getUid(),beginning:this.beginning.getUid(),end:this.end.getUid()},null!=this.prev_cl&&null!=this.next_cl&&(e.prev=this.prev_cl.getUid(),e.next=this.next_cl.getUid()),null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},n}(r),p.ReplaceManager=function(e){var t,n,r,i,o,u,a;return n=e.content,a=e.uid,u=e.prev,i=e.next,o=e.origin,t=e.beginning,r=e.end,new s(n,a,t,r,u,i,o)},u=function(e){function t(e,n,r,i,o,s){if(this.saveOperation("content",e),this.saveOperation("parent",n),null==i||null==o||null==e)throw new Error("You must define content, prev, and next for Replaceable-types!");t.__super__.constructor.call(this,r,i,o,s)}return i(t,e),t.prototype.val=function(){return this.content},t.prototype.replace=function(e){return this.parent.replace(e)},t.prototype.execute=function(){var e;return this.validateSavedOperations()?("function"==typeof(e=this.content).setReplaceManager&&e.setReplaceManager(this.parent),t.__super__.execute.apply(this,arguments)):!1},t.prototype._encode=function(){var e;return e={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&&(e.origin=this.origin.getUid()),e},t}(l.Insert),p.Replaceable=function(e){var t,n,r,i,o,s;return t=e.content,i=e.ReplaceManager,s=e.uid,o=e.prev,n=e.next,r=e.origin,new u(t,i,s,o,n,r)},l.ListManager=r,l.MapManager=o,l.ReplaceManager=s,l.Replaceable=u,a}},{"./BasicTypes":4}],7:[function(e,t){var n,r={}.hasOwnProperty,i=function(e,t){function n(){this.constructor=e}for(var i in t)r.call(t,i)&&(e[i]=t[i]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e};n=e("./StructuredTypes"),t.exports=function(e){var t,r,o,s,u,a;return u=n(e),a=u.types,s=u.parser,t=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return i(t,e),t}(a.Delete),s.TextDelete=s.Delete,r=function(e){function t(e,n,r,i,o){if(this.content=e,null==r||null==i)throw new Error("You must define prev, and next for TextInsert-types!");t.__super__.constructor.call(this,n,r,i,o)}return i(t,e),t.prototype.getLength=function(){return this.isDeleted()?0:this.content.length},t.prototype.val=function(){return this.isDeleted()?"":this.content},t.prototype._encode=function(){var e;return e={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&&(e.origin=this.origin.getUid()),e},t}(a.Insert),s.TextInsert=function(e){var t,n,i,o,s;return t=e.content,s=e.uid,o=e.prev,n=e.next,i=e.origin,new r(t,s,o,n,i)},o=function(n){function o(e,t,n,r,i,s){o.__super__.constructor.call(this,e,t,n,r,i,s)}return i(o,n),o.prototype.insertText=function(t,n){var i,o,s,u,a,p;for(o=this.getOperationByPosition(t),p=[],u=0,a=n.length;a>u;u++)i=n[u],s=new r(i,void 0,o.prev_cl,o),p.push(e.addOperation(s).execute());return p},o.prototype.deleteText=function(n,r){var i,o,s,u,p;for(u=this.getOperationByPosition(n),o=[],s=p=0;(r>=0?r>p:p>r)&&!(u instanceof a.Delimiter);s=r>=0?++p:--p){for(i=e.addOperation(new t(void 0,u)).execute(),u=u.next_cl;!(u instanceof a.Delimiter)&&u.isDeleted();)u=u.next_cl;o.push(i._encode())}return o},o.prototype.replaceText=function(t){var n;if(null!=this.replace_manager)return n=e.addOperation(new o(void 0)).execute(),n.insertText(0,t),this.replace_manager.replace(n);throw new Error("This type is currently not maintained by a ReplaceManager!")},o.prototype.val=function(){var e,t;return e=function(){var e,n,r,i;for(r=this.toArray(),i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(null!=t.val?t.val():"");return i}.call(this),e.join("")},o.prototype.setReplaceManager=function(e){return this.saveOperation("replace_manager",e),this.validateSavedOperations(),this.on(["insert","delete"],function(e){return function(){var t;return null!=(t=e.replace_manager)?t.callEvent("change"):void 0}}(this))},o.prototype.bind=function(e){var t;return t=this,e.value=this.val(),this.on("insert",function(n,r){var i,o,s,u;return s=r.getPosition(),i=function(e){return s>=e?e:e+=1},o=i(e.selectionStart),u=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,u)}),this.on("delete",function(n,r){var i,o,s,u;return s=r.getPosition(),i=function(e){return s>e?e:e-=1},o=i(e.selectionStart),u=i(e.selectionEnd),e.value=t.val(),e.setSelectionRange(o,u)}),e.onkeypress=function(n){var r,i,o,s;return r=null,r=null!=n.key?32===n.charCode?" ":13===n.keyCode?"\n":n.key:String.fromCharCode(n.keyCode),r.length>0?(s=Math.min(e.selectionStart,e.selectionEnd),i=Math.abs(e.selectionEnd-e.selectionStart),t.deleteText(s,i),t.insertText(s,r),o=s+r.length,e.setSelectionRange(o,o),n.preventDefault()):n.preventDefault()},e.onpaste=function(e){return e.preventDefault()},e.oncut=function(e){return e.preventDefault()},e.onkeydown=function(n){var r,i,o,s,u;if(s=Math.min(e.selectionStart,e.selectionEnd),i=Math.abs(e.selectionEnd-e.selectionStart),null!=n.keyCode&&8===n.keyCode){if(i>0)t.deleteText(s,i),e.setSelectionRange(s,s);else if(null!=n.ctrlKey&&n.ctrlKey){for(u=e.value,o=s,r=0,s>0&&(o--,r++);o>0&&" "!==u[o]&&"\n"!==u[o];)o--,r++;t.deleteText(o,s-o),e.setSelectionRange(o,o)}else t.deleteText(s-1,1);return n.preventDefault()}return null!=n.keyCode&&46===n.keyCode?(i>0?(t.deleteText(s,i),e.setSelectionRange(s,s)):(t.deleteText(s,1),e.setSelectionRange(s,s)),n.preventDefault()):void 0}},o.prototype._encode=function(){var e;return e={type:"Word",uid:this.getUid(),beginning:this.beginning.getUid(),end:this.end.getUid()},null!=this.prev_cl&&(e.prev=this.prev_cl.getUid()),null!=this.next_cl&&(e.next=this.next_cl.getUid()),null!=this.origin&&this.origin!==this.prev_cl&&(e.origin=this.origin.getUid()),e},o}(a.ListManager),s.Word=function(e){var t,n,r,i,s,u;return u=e.uid,t=e.beginning,n=e.end,s=e.prev,r=e.next,i=e.origin,new o(u,t,n,s,r,i)},a.TextInsert=r,a.TextDelete=t,a.Word=o,u}},{"./StructuredTypes":6}]},{},[2]);