poplar-annotation
Version:
web-based annotation tool for natural language processing (NLP) needs, inspired by brat rapid annotation tool.
1 lines • 77.6 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Poplar=t():e.Poplar=t()}(window,function(){return o={},r.m=n=[function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SVGNS="http://www.w3.org/2000/svg"},function(e,t,n){"use strict";var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],o=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0});var i,a,l,c=n(4),u=n(3);function h(){var e=null!==a&&a.apply(this,arguments)||this;return e.entities=new Map,e.nextId=0,e}i=t.Base||(t.Base={}),a=u.EventEmitter,r(h,a),Object.defineProperty(h.prototype,"json",{get:function(){var t,e,n=[];try{for(var o=s(this.values()),r=o.next();!r.done;r=o.next()){var i=r.value;"json"in i?n.push(i.json):n.push(JSON.parse(JSON.stringify(i)))}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}return n},enumerable:!0,configurable:!0}),Object.defineProperty(h.prototype,"length",{get:function(){return this.entities.size},enumerable:!0,configurable:!0}),h.prototype.get=function(e){return c.assert(this.has(e),"There's no Entity which id="+e+" in repo!"),this.entities.get(e)},h.prototype.has=function(e){return this.entities.has(e)},h.prototype.set=function(e,t){var n=this.has(e);return this.entities.set(e,t),n?this.emit("updated",t):(this.nextId<e+1&&(this.nextId=e+1),this.emit("created",t)),this},h.prototype.add=function(e){if("id"in e){var t=e.id;return c.assert(!this.has(t),"reAdd "+t+"!"),null===t?(e.id=this.nextId,this.add(e)):(this.set(t,e),t)}var n=this.nextId;return this.set(n,e),n},h.prototype[Symbol.iterator]=function(){return this.entities[Symbol.iterator]()},h.prototype.delete=function(e){if("number"==typeof e&&this.has(e)){var t=this.get(e);return this.entities.delete(e),this.emit("removed",t),!0}return"number"!=typeof e&&"id"in e&&this.delete(e.id)},h.prototype.values=function(){return this.entities.values()},l=h,i.Repository=l},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=(Object.defineProperty(r.prototype,"isSome",{get:function(){return null!==this.value},enumerable:!0,configurable:!0}),r.prototype.map=function(e){return null===this.value?new r(null):new r(e(this.value))},r.prototype.flatMap=function(e){return null===this.value?new r(null):s(e(this.value).toNullable())},r.prototype.orElse=function(e){return null===this.value?e:this.value},r.prototype.toNullable=function(){return this.value},r.prototype.match=function(e,t){return this.isSome?e:t},r);function r(e){this.value=e}function i(e){return new o(e)}function s(e){return null==e?t.none:i(e)}t.Option=o,t.none=new o(null),t.some=i,t.fromNullable=s,t.fromTry=function(e){try{return i(e())}catch(e){return t.none}}},function(e,t,n){"use strict";var o,r="object"==typeof Reflect?Reflect:null,u=r&&"function"==typeof r.apply?r.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};o=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function s(){s.init.call(this)}((e.exports=s).EventEmitter=s).prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var a=10;function l(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function c(e,t,n,o){var r,i,s;if("function"!=typeof n)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n);if(void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),s=i[t]),void 0===s)s=i[t]=n,++e._eventsCount;else if("function"==typeof s?s=i[t]=o?[n,s]:[s,n]:o?s.unshift(n):s.push(n),0<(r=l(e))&&s.length>r&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,function(e){console&&console.warn&&console.warn(e)}(a)}return e}function h(e,t,n){var o={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=function(){for(var e=[],t=0;t<arguments.length;t++)e.push(arguments[t]);this.fired||(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,u(this.listener,this.target,e))}.bind(o);return r.listener=n,o.wrapFn=r}function f(e,t,n){var o=e._events;if(void 0===o)return[];var r=o[t];return void 0===r?[]:"function"==typeof r?n?[r.listener||r]:[r]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(r):p(r,r.length)}function d(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function p(e,t){for(var n=new Array(t),o=0;o<t;++o)n[o]=e[o];return n}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return l(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var o="error"===e,r=this._events;if(void 0!==r)o=o&&void 0===r.error;else if(!o)return!1;if(o){var i;if(0<t.length&&(i=t[0]),i instanceof Error)throw i;var s=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw s.context=i,s}var a=r[e];if(void 0===a)return!1;if("function"==typeof a)u(a,this,t);else{var l=a.length,c=p(a,l);for(n=0;n<l;++n)u(c[n],this,t)}return!0},s.prototype.on=s.prototype.addListener=function(e,t){return c(this,e,t,!1)},s.prototype.prependListener=function(e,t){return c(this,e,t,!0)},s.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);return this.on(e,h(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);return this.prependListener(e,h(this,e,t)),this},s.prototype.off=s.prototype.removeListener=function(e,t){var n,o,r,i,s;if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);if(void 0===(o=this._events))return this;if(void 0===(n=o[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(r=-1,i=n.length-1;0<=i;i--)if(n[i]===t||n[i].listener===t){s=n[i].listener,r=i;break}if(r<0)return this;0===r?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,r),1===n.length&&(o[e]=n[0]),void 0!==o.removeListener&&this.emit("removeListener",e,s||t)}return this},s.prototype.removeAllListeners=function(e){var t,n,o;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var r,i=Object.keys(n);for(o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(o=t.length-1;0<=o;o--)this.removeListener(e,t[o]);return this},s.prototype.listeners=function(e){return f(this,e,!0)},s.prototype.rawListeners=function(e){return f(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},s.prototype.listenerCount=d,s.prototype.eventNames=function(){return 0<this._eventsCount?o(this._events):[]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.assert=function(e,t){0}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.shadeColor=function(e,t){var n=parseInt(e.slice(1),16),o=Math.min((n>>16)+(n>>16)*t/100,255),r=Math.min((n>>8&255)+(n>>8&255)*t/100,255);return"#"+(Math.min((255&n)+(255&n)*t/100,255)|r<<8|o<<16).toString(16)},t.addAlpha=function(e,t){var n=parseInt(e.slice(1),16);return"rgba("+(n>>16)+","+(n>>8&255)+","+(255&n)+","+t+"%)"}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});function o(){this.layer=0}t.TopContextUser=o,t.overLaps=function e(t,n){return t.layer===n.layer&&(t.left>n.left?e(n,t):!(t.left+t.width<n.left))}},function(e,t,n){"use strict";var o,a=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s},l=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(r(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0});var c=n(6),x=n(0),u=n(1),h=n(5);!function(e){var r,t=(r=c.TopContextUser,a(n,r),Object.defineProperty(n.prototype,"id",{get:function(){return this.store.id},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"lineIn",{get:function(){return this.contextIn.belongTo},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"view",{get:function(){return this.lineIn.view},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"highLightWidth",{get:function(){return this.view.contentWidth(this.store.startIndex,this.store.endIndex)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"highLightLeft",{get:function(){return this.view.contentWidth(this.lineIn.startIndex,this.store.startIndex)+this.lineIn.view.paddingLeft},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"middle",{get:function(){return this.highLightLeft+this.highLightWidth/2},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"labelLeft",{get:function(){return this.middle-this.labelWidth/2},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"labelRight",{get:function(){return this.middle+this.labelWidth/2},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"labelWidth",{get:function(){return this.view.labelFont.widthOf(this.store.category.text)+this.config.labelPadding+2},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"left",{get:function(){return"max"===this.config.labelWidthCalcMethod?this.labelWidth>this.highLightWidth?this.labelLeft:this.highLightLeft:this.labelLeft},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"width",{get:function(){return"max"===this.config.labelWidthCalcMethod?this.labelWidth>this.highLightWidth-1?this.labelWidth:this.highLightWidth-1:this.labelWidth},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"annotationY",{get:function(){return-this.view.topContextLayerHeight*(this.layer-1)-(this.view.labelFont.lineHeight+2+2*this.config.labelPadding+this.config.bracketWidth)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"globalY",{get:function(){return this.lineIn.y+this.annotationY},enumerable:!0,configurable:!0}),n.prototype.render=function(){var e;this.svgElement=document.createElementNS(x.SVGNS,"g"),(e=this.svgElement.classList).add.apply(e,l(this.config.labelClasses));var t=this.createHighLightElement(),n=this.createAnnotationElement(),o=this.view.topContextLayerHeight*(this.layer-1),r=this.createBracketElement(this.highLightWidth,-o,0,-o,this.config.bracketWidth);return this.svgElement.appendChild(t),this.svgElement.appendChild(n),this.svgElement.appendChild(r),this.svgElement},n.prototype.update=function(){this.svgElement.style.transform="translate("+this.highLightLeft+"px,"+this.lineIn.y+"px)"},n.prototype.remove=function(){this.svgElement.remove()},n.prototype.createHighLightElement=function(){var e=document.createElementNS(x.SVGNS,"rect"),t=this.store.category.color;return e.setAttribute("height",this.lineIn.view.contentFont.lineHeight.toString()),e.setAttribute("width",this.highLightWidth.toString()),e.setAttribute("fill",/^#/g.test(t)?h.addAlpha(t,70):t),e},n.prototype.createBracketElement=function(e,t,n,o,r,i){void 0===i&&(i=.6);var s=e-n,a=t-o,l=Math.sqrt(s*s+a*a),c=e+i*r*(a/=l),u=t-i*r*(s/=l),h=e-.25*l*s+(1-i)*r*a,f=t-.25*l*a-(1-i)*r*s,d=e-.5*l*s+r*a,p=t-.5*l*a-r*s,y=n+i*r*a,v=o-i*r*s,m=e-.75*l*s+(1-i)*r*a,b=t-.75*l*a-(1-i)*r*s,g=document.createElementNS(x.SVGNS,"path");return g.setAttribute("d","M"+e+","+t+"Q"+c+","+u+","+h+","+f+"T"+d+","+p+"M"+n+","+o+"Q"+y+","+v+","+m+","+b+"T"+d+","+p),g.setAttribute("fill","none"),g.setAttribute("stroke",this.store.category.borderColor),g},n.prototype.createAnnotationElement=function(){var t=this,e=this.view.labelCategoryElementFactoryRepository.get(this.store.category.id).create();return e.style.transform="translate("+(this.highLightWidth-this.labelWidth)/2+"px,"+this.annotationY+"px)",e.onclick=function(e){t.view.root.emit("labelClicked",t.id,e)},e.ondblclick=function(e){t.view.root.emit("labelDoubleClicked",t.id,e)},e.oncontextmenu=function(e){t.view.root.emit("labelRightClicked",t.id,e),e.preventDefault()},e.onmouseenter=function(){t.svgElement.classList.add("hover"),Array.from(t.store.connectionsFrom).map(function(e){return t.view.connectionViewRepository.get(e.id)}).map(function(e){return e.addHover("from")}),Array.from(t.store.connectionsTo).map(function(e){return t.view.connectionViewRepository.get(e.id)}).map(function(e){return e.addHover("to")})},e.onmouseleave=function(){t.svgElement.classList.remove("hover"),Array.from(t.store.connectionsFrom).map(function(e){return t.view.connectionViewRepository.get(e.id)}).map(function(e){return e.removeHover("from")}),Array.from(t.store.connectionsTo).map(function(e){return t.view.connectionViewRepository.get(e.id)}).map(function(e){return e.removeHover("to")})},e},n);function n(e,t,n){var o=r.call(this)||this;return o.store=e,o.contextIn=t,o.config=n,o.layer=0,o.svgElement=null,o}e.Entity=t;var o,i=(o=u.Base.Repository,a(s,o),s.prototype.get=function(e){return this.entities.get(e)},s);function s(){return null!==o&&o.apply(this,arguments)||this}e.Repository=i}(t.LabelView||(t.LabelView={}))},function(e,t,n){"use strict";var o,l=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),c=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],o=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0});var u=n(1);!function(e){var n=(Object.defineProperty(t.prototype,"startIndex",{get:function(){return this._startIndex},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"endIndex",{get:function(){return this._endIndex},enumerable:!0,configurable:!0}),t.prototype.move=function(e){this._startIndex+=e,this._endIndex+=e},Object.defineProperty(t.prototype,"category",{get:function(){return this.root.labelCategoryRepo.get(this.categoryId)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"json",{get:function(){return{id:this.id,categoryId:this.categoryId,startIndex:this.startIndex,endIndex:this.endIndex}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"sameLineConnections",{get:function(){var t,e,n=[];try{for(var o=c(this.root.connectionRepo.values()),r=o.next();!r.done;r=o.next()){var i=r.value;i.priorLabel===this&&n.push(i)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}return n},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"connectionsFrom",{get:function(){var t,e,n=new Set;try{for(var o=c(this.root.connectionRepo.values()),r=o.next();!r.done;r=o.next()){var i=r.value;i.from===this&&n.add(i)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}return n},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"connectionsTo",{get:function(){var t,e,n=new Set;try{for(var o=c(this.root.connectionRepo.values()),r=o.next();!r.done;r=o.next()){var i=r.value;i.to===this&&n.add(i)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}return n},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"allConnections",{get:function(){return new Set(Array.prototype.concat(Array.from(this.connectionsFrom),Array.from(this.connectionsTo)))},enumerable:!0,configurable:!0}),t);function t(e,t,n,o,r){this.id=e,this.categoryId=t,this._startIndex=n,this._endIndex=o,this.root=r}e.Entity=n;var o,r,i=(o=u.Base.Repository,l(s,o),s.prototype.set=function(e,t){return this.againstMultipleLabelWith(t)?console.warn("try set a label against the againstMultipleLabelWith rule!"):o.prototype.set.call(this,e,t),this},s.prototype.add=function(e){return this.againstMultipleLabelWith(e)?(console.warn("try add a label against the againstMultipleLabelWith rule!"),-1):o.prototype.add.call(this,e)},s.prototype.againstMultipleLabelWith=function(t){function n(e,t){return e.startIndex===t.startIndex&&e.endIndex===t.endIndex}var o="notAllowed"===this.config.allowMultipleLabel?n:function(e,t){return n(e,t)&&e.categoryId==t.categoryId};return Array.from(this.values()).some(function(e){return o(e,t)})},s.prototype.getEntitiesInRange=function(t,n){return Array.from(this.entities.values()).filter(function(e){return t<=e.startIndex&&e.endIndex<=n})},s.prototype.getEntitiesCross=function(t){return Array.from(this.entities.values()).filter(function(e){return e.startIndex<=t&&t<e.endIndex})},s);function s(e){var t=o.call(this)||this;return t.config=e,t}function a(e,t){return new n(e.id,e.categoryId,e.startIndex,e.endIndex,t)}e.Repository=i,(r=e.Factory||(e.Factory={})).create=a,r.createAll=function(e,t){return e.map(function(e){return a(e,t)})}}(t.Label||(t.Label={}))},function(e,t,n){"use strict";var o,l=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var c=n(1);!function(e){var n=(Object.defineProperty(t.prototype,"category",{get:function(){return this.root.connectionCategoryRepo.get(this.categoryId)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"from",{get:function(){return this.root.labelRepo.get(this.fromId)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"to",{get:function(){return this.root.labelRepo.get(this.toId)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"priorLabel",{get:function(){return this.from.startIndex<this.to.startIndex?this.from:this.to},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"posteriorLabel",{get:function(){return this.from.startIndex>=this.to.startIndex?this.from:this.to},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"json",{get:function(){return{id:this.id,categoryId:this.categoryId,fromId:this.fromId,toId:this.toId}},enumerable:!0,configurable:!0}),t);function t(e,t,n,o,r){this.id=e,this.categoryId=t,this.fromId=n,this.toId=o,this.root=r}e.Entity=n;var o,r,i=(o=c.Base.Repository,l(s,o),s.prototype.set=function(e,t){return this.againstMultipleConnectionRuleWith(t)?console.warn("try set a label against the checkMultipleLabel rule!"):o.prototype.set.call(this,e,t),this},s.prototype.add=function(e){return this.againstMultipleConnectionRuleWith(e)?(console.warn("try add a label against the checkMultipleLabel rule!"),-1):o.prototype.add.call(this,e)},s.prototype.againstMultipleConnectionRuleWith=function(t){function n(e,t){return e.from===t.from&&e.to===t.to}var o="notAllowed"===this.config.allowMultipleConnection?n:function(e,t){return n(e,t)&&e.categoryId==t.categoryId};return Array.from(this.values()).some(function(e){return o(e,t)})},s);function s(e){var t=o.call(this)||this;return t.config=e,t}function a(e,t){return new n(e.id,e.categoryId,e.fromId,e.toId,t)}e.Repository=i,(r=e.Factory||(e.Factory={})).create=a,r.createAll=function(e,t){return e.map(function(e){return a(e,t)})}}(t.Connection||(t.Connection={}))},function(e,t,n){"use strict";var o,a=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s},l=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(r(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0});var c=n(1),u=n(0),h=n(6);!function(e){var r,t=(r=h.TopContextUser,a(n,r),Object.defineProperty(n.prototype,"id",{get:function(){return this.store.id},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"lineIn",{get:function(){return this.contextIn.belongTo},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"view",{get:function(){return this.lineIn.view},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sameLineLabelView",{get:function(){return this.view.labelViewRepository.get(this.store.priorLabel.id)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"mayNotSameLineLabelView",{get:function(){return this.view.labelViewRepository.get(this.store.posteriorLabel.id)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"fromLabelView",{get:function(){return this.view.labelViewRepository.get(this.store.from.id)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"toLabelView",{get:function(){return this.view.labelViewRepository.get(this.store.to.id)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"leftLabelView",{get:function(){return this.fromLabelView.labelLeft<this.toLabelView.labelLeft?this.fromLabelView:this.toLabelView},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"rightLabelView",{get:function(){return this.fromLabelView.labelLeft>=this.toLabelView.labelLeft?this.fromLabelView:this.toLabelView},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"middle",{get:function(){return(this.leftLabelView.labelLeft+this.rightLabelView.labelRight)/2},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"textWidth",{get:function(){return this.view.connectionFont.widthOf(this.store.category.text)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"textLeft",{get:function(){return this.middle-this.textWidth/2},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"lineIncludedWidth",{get:function(){return this.fromLabelView.labelLeft<this.toLabelView.labelLeft?this.toLabelView.labelRight-this.fromLabelView.labelLeft:this.fromLabelView.labelRight-this.toLabelView.labelLeft},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"lineIncludedLeft",{get:function(){return this.fromLabelView.labelLeft<this.toLabelView.labelLeft?this.fromLabelView.labelLeft:this.toLabelView.labelLeft},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"width",{get:function(){return"text"===this.config.connectionWidthCalcMethod?this.textWidth:this.lineIncludedWidth},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"left",{get:function(){return"text"===this.config.connectionWidthCalcMethod?this.textLeft:this.lineIncludedLeft},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"globalY",{get:function(){return this.lineIn.y-this.layer*this.view.topContextLayerHeight},enumerable:!0,configurable:!0}),n.prototype.render=function(){var t=this;this.svgElement=document.createElementNS(u.SVGNS,"g");var e=this.view.connectionCategoryElementFactoryRepository.get(this.store.category.id).create();return this.svgElement.appendChild(e),this.svgElement.style.cursor="pointer",this.svgElement.onclick=function(e){t.view.root.emit("connectionClicked",t.id,e)},this.svgElement.ondblclick=function(e){t.view.root.emit("connectionDoubleClicked",t.id,e)},this.svgElement.oncontextmenu=function(e){t.view.root.emit("connectionRightClicked",t.id,e),e.preventDefault()},this.svgElement.onmouseenter=function(){t.svgElement.classList.add("hover"),t.lineElement.classList.add("hover")},this.svgElement.onmouseleave=function(){t.svgElement.classList.remove("hover"),t.lineElement.classList.remove("hover")},this.renderLine(),this.svgElement},n.prototype.update=function(){this.svgElement.style.transform="translate("+this.textLeft+"px,"+this.globalY+"px)",this.updateLine()},n.prototype.addHover=function(e){this.svgElement.classList.add("hover-"+e),this.lineElement.classList.add("hover-"+e)},n.prototype.removeHover=function(e){this.svgElement.classList.remove("hover-"+e),this.lineElement.classList.remove("hover-"+e)},n.prototype.remove=function(){this.svgElement.remove(),this.lineElement.remove()},n.prototype.updateLine=function(){var e=this.globalY+this.view.topContextLayerHeight/2-this.view.labelFont.fontSize+2;this.fromLabelView.labelLeft<this.toLabelView.labelLeft?this.lineElement.setAttribute("d","\n M "+(this.fromLabelView.labelLeft+1)+" "+(this.fromLabelView.globalY+1)+"\n C "+(this.fromLabelView.labelLeft-8)+" "+e+",\n "+(this.fromLabelView.labelLeft-8)+" "+e+",\n "+(this.fromLabelView.labelLeft+1)+" "+e+"\n L "+(this.toLabelView.labelLeft+this.toLabelView.labelWidth)+" "+e+"\n C "+(this.toLabelView.labelLeft+this.toLabelView.labelWidth+8)+" "+e+",\n "+(this.toLabelView.labelLeft+this.toLabelView.labelWidth+8)+" "+e+",\n "+(this.toLabelView.labelLeft+this.toLabelView.labelWidth)+" "+(this.toLabelView.globalY-1)+"\n "):this.lineElement.setAttribute("d","\n M "+(this.fromLabelView.labelRight-1)+" "+(this.fromLabelView.globalY+1)+"\n C "+(this.fromLabelView.labelRight+8)+" "+e+",\n "+(this.fromLabelView.labelRight+8)+" "+e+",\n "+(this.fromLabelView.labelRight-1)+" "+e+"\n L "+this.toLabelView.labelLeft+" "+e+"\n C "+(this.toLabelView.labelLeft-8)+" "+e+",\n "+(this.toLabelView.labelLeft-8)+" "+e+",\n "+this.toLabelView.labelLeft+" "+(this.toLabelView.globalY-1)+"\n ")},n.prototype.renderLine=function(){var e;this.lineElement=document.createElementNS(u.SVGNS,"path"),(e=this.lineElement.classList).add.apply(e,l(this.config.connectionClasses.map(function(e){return e+"-line"}))),this.lineElement.setAttribute("fill","none"),this.lineElement.style.markerEnd="url(#marker-arrow)",this.updateLine(),this.contextIn.backgroundElement.appendChild(this.lineElement)},n);function n(e,t,n){var o=r.call(this)||this;return o.store=e,o.contextIn=t,o.config=n,o.svgElement=null,o.lineElement=null,o}e.Entity=t;var o,i=(o=c.Base.Repository,a(s,o),s);function s(){return null!==o&&o.apply(this,arguments)||this}e.Repository=i}(t.ConnectionView||(t.ConnectionView={}))},function(e,t,n){"use strict";var o=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s},l=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0});var r,h,c=n(0);function i(e,t,n,o,r,i){this.fontFamily=e,this.fontSize=t,this.fontWeight=n,this.lineHeight=o,this.topToBaseLine=r,this.width=i}r=t.Font||(t.Font={}),i.prototype.widthOf=function(e){var t=this;return"string"==typeof e?this.widthOf(Array.from(e)):e.map(function(e){return t.width.get(e)}).reduce(function(e,t){return e+t},0)},h=i,r.ValueObject=h,function(e){function i(e,n,t){var o=new Map,r=new Set(e);r.delete("\n");var i=Array.from(r);n.textContent=i.join(""),n.parentNode.parentNode.insertBefore(t,n.parentNode),i.forEach(function(e,t){o.set(e,n.getExtentOfChar(t).width)});var s=t.getBoundingClientRect().top-n.getBoundingClientRect().top,a=parseFloat(window.getComputedStyle(n).fontSize),l=window.getComputedStyle(n).fontFamily,c=window.getComputedStyle(n).fontWeight,u=n.getBoundingClientRect().height;return new h(l,a,c,u,s,o)}e.create=i;var n=(t.prototype.thanCreate=function(e,t){var n,o;(n=this.measuringElement.classList).add.apply(n,l(e));var r=i(t,this.measuringElement,this.baseLineReferenceElement);return(o=this.measuringElement.classList).remove.apply(o,l(e)),this.result.push(r),this},t.prototype.endBatch=function(){return this.baseLineReferenceElement.remove(),this.measuringElement.remove(),this.result},t);function t(e,t){this.svgElement=e,this.textElement=t,this.baseLineReferenceElement=document.createElementNS(c.SVGNS,"rect"),this.baseLineReferenceElement.setAttribute("width","1px"),this.baseLineReferenceElement.setAttribute("height","1px"),this.svgElement.appendChild(this.baseLineReferenceElement),this.measuringElement=document.createElementNS(c.SVGNS,"tspan"),this.textElement.appendChild(this.measuringElement),this.result=[]}e.startBatch=function(e,t){return new n(e,t)}}(r.Factory||(r.Factory={})),(r.Service||(r.Service={})).measureMore=function(n,e,t,o){var r,i=new Set(e);i.delete("\n");var s=Array.from(i).filter(function(e){return!n.width.has(e)});if(0<s.length){var a=document.createElementNS(c.SVGNS,"tspan");(r=a.classList).add.apply(r,l(t)),a.textContent=s.join(""),o.appendChild(a),s.forEach(function(e,t){n.width.set(e,a.getExtentOfChar(t).width)}),a.remove()}return n}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(13);t.Annotator=o.Annotator;var r=n(27),i=n(28),s=n(29),a={Connection:r.Connection,Label:i.Label,Content:s.Content};t.Action=a},function(e,t,n){"use strict";var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var s,i=n(3),a=n(14),l=n(17),c=n(0),u=n(24),h=n(25),f=n(26),d=(s=i.EventEmitter,r(p,s),p.prototype.applyAction=function(e){e.apply(this.store)},p.prototype.export=function(){this.view.contentEditor.hide();var e=this.view.svgElement.outerHTML.replace(/ /," ");return this.view.contentEditor.show(),e},p.prototype.remove=function(){this.view.svgElement.remove(),this.store.config.contentEditable&&this.view.contentEditor.remove()},p);function p(e,t,n){var o=s.call(this)||this;o.containerElement=t,o.configInput=n;var r=u.parseInput(n||{});o.store=new a.Store(r),o.store.json="string"==typeof e?JSON.parse(e):e;var i=document.createElementNS(c.SVGNS,"svg");return i.setAttribute("xmlns",c.SVGNS),t.appendChild(i),o.view=new l.View(o,i,r),o.textSelectionHandler=new h.TextSelectionHandler(o,r),o.twoLabelsClickedHandler=new f.TwoLabelsClickedHandler(o,r),o}t.Annotator=d},function(e,t,n){"use strict";var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var i,s=n(15),a=n(8),l=n(16),c=n(9),u=n(3),h=(i=u.EventEmitter,r(f,i),Object.defineProperty(f.prototype,"content",{get:function(){return this._content},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"json",{get:function(){return{content:this._content,labelCategories:this.labelCategoryRepo.json,labels:this.labelRepo.json,connectionCategories:this.connectionCategoryRepo.json,connections:this.connectionRepo.json}},set:function(e){var t=this;this._content=e.content.endsWith("\n")?e.content:e.content+"\n",s.LabelCategory.Factory.createAll(e.labelCategories,this.config).map(function(e){return t.labelCategoryRepo.add(e)}),a.Label.Factory.createAll(e.labels,this).map(function(e){return t.labelRepo.add(e)}),e.connectionCategories.map(function(e){return t.connectionCategoryRepo.add(e)}),c.Connection.Factory.createAll(e.connections,this).map(function(e){return t.connectionRepo.add(e)})},enumerable:!0,configurable:!0}),f.prototype.contentSlice=function(e,t){return this.content.slice(e,t)},f.prototype.moveLabels=function(t,n){Array.from(this.labelRepo.values()).filter(function(e){return e.startIndex>=t}).map(function(e){return e.move(n)})},f.prototype.spliceContent=function(t,e){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];var r=t+e;if(0===e||void 0===Array.from(this.labelRepo.values()).find(function(e){return e.startIndex<=t&&t<e.endIndex||e.startIndex<r&&r<e.endIndex})){var i=this.content.slice(0,t),s=this.content.slice(t,t+e),a=n.join(""),l=this.content.slice(t+e);this._content=i+a+l,this.moveLabels(t+e,a.length-s.length),this.emit("contentSpliced",t,s,a)}},f);function f(e){var t=i.call(this)||this;return t._content="",t.config=e,t.labelCategoryRepo=new s.LabelCategory.Repository,t.labelRepo=new a.Label.Repository(e),t.connectionCategoryRepo=new l.ConnectionCategory.Repository,t.connectionRepo=new c.Connection.Repository(e),t}t.Store=h},function(e,t,n){"use strict";var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var i,s,a,l,c=n(1),u=n(5);function h(){return null!==s&&s.apply(this,arguments)||this}function f(e,t){var n=e.borderColor,o=e.color;return!e.borderColor&&e["border-color"]&&(n=e["border-color"]),e.color||(o=t),e.borderColor||(n=u.shadeColor(o,-30)),{id:e.id,text:e.text,color:o,borderColor:n}}i=t.LabelCategory||(t.LabelCategory={}),s=c.Base.Repository,r(h,s),l=h,i.Repository=l,(a=i.Factory||(i.Factory={})).create=f,a.createAll=function(e,t){return e.map(function(e){return f(e,t.defaultLabelColor)})}},function(e,t,n){"use strict";var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var i,s,a,l=n(1);function c(){return null!==s&&s.apply(this,arguments)||this}i=t.ConnectionCategory||(t.ConnectionCategory={}),s=l.Base.Repository,r(c,s),a=c,i.Repository=a},function(e,t,n){"use strict";var d=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s},_=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(d(arguments[t]));return e},I=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],o=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0});var p=n(0),S=n(18),y=n(11),v=n(21),m=n(7),b=n(10),g=n(22),x=n(23),O=n(2),o=(w.layoutTopContextsAfter=function(e){for(;e.next.isSome;)e.topContext.update(),e=e.next.toNullable();e.topContext.update()},w.prototype.constructLabelViewsForLine=function(t){var n=this,e=this.store.labelRepo.getEntitiesInRange(t.startIndex,t.endIndex).map(function(e){return new m.LabelView.Entity(e,t.topContext,n.config)});return e.map(function(e){return n.labelViewRepository.add(e)}),e.map(function(e){return t.topContext.addChild(e)}),e},w.prototype.constructConnectionsForLine=function(n){var o=this;return this.store.labelRepo.getEntitiesInRange(n.startIndex,n.endIndex).map(function(e){var t=e.sameLineConnections.filter(function(e){return!o.connectionViewRepository.has(e.id)}).map(function(e){return new b.ConnectionView.Entity(e,n.topContext,o.config)});return t.map(function(e){return o.connectionViewRepository.add(e)}),t.map(function(e){return n.topContext.addChild(e)}),t}).reduce(function(e,t){return e.concat(t)},[])},Object.defineProperty(w.prototype,"height",{get:function(){var n=this;return this.lines.reduce(function(e,t){return e+t.height+n.contentFont.fontSize*(n.config.lineHeight-1)},20)},enumerable:!0,configurable:!0}),w.createMarkerElement=function(){var e=document.createElementNS(p.SVGNS,"path");e.setAttribute("d","M0,4 L0,8 L6,6 L0,4 L0,8"),e.setAttribute("stroke","#000000"),e.setAttribute("fill","#000000");var t=document.createElementNS(p.SVGNS,"marker");return t.setAttribute("id","marker-arrow"),t.setAttribute("markerWidth","8"),t.setAttribute("markerHeight","10"),t.setAttribute("orient","auto"),t.setAttribute("refX","5"),t.setAttribute("refY","6"),t.appendChild(e),t},w.prototype.contentWidth=function(e,t){return this.contentFont.widthOf(this.store.contentSlice(e,t))},w.prototype.removeLine=function(e){var t=this;e.remove(),e.topContext.children.forEach(function(e){e instanceof m.LabelView.Entity?t.labelViewRepository.delete(e):e instanceof b.ConnectionView.Entity&&t.connectionViewRepository.delete(e)})},w.prototype.registerEventHandlers=function(){var n=this;this.textElement.onmouseup=function(e){"Range"===window.getSelection().type?n.root.textSelectionHandler.textSelected():n.config.contentEditable&&n.contentEditor.caretChanged(e.clientY)},this.store.labelRepo.on("created",this.onLabelCreated.bind(this)),this.store.labelRepo.on("removed",function(e){var t=n.labelViewRepository.get(e.id);t.lineIn.topContext.removeChild(t),t.remove(),n.labelViewRepository.delete(t),t.lineIn.topContext.update(),t.lineIn.update(),w.layoutTopContextsAfter(t.lineIn),n.config.contentEditable&&n.contentEditor.update()}),this.store.connectionRepo.on("created",this.onConnectionCreated.bind(this)),this.store.connectionRepo.on("removed",function(e){var t=n.connectionViewRepository.get(e.id);t.lineIn.topContext.removeChild(t),t.remove(),n.connectionViewRepository.delete(t),t.lineIn.topContext.update(),t.lineIn.update(),w.layoutTopContextsAfter(t.lineIn),n.config.contentEditable&&n.contentEditor.update()}),this.config.contentEditable&&this.store.on("contentSpliced",this.onContentSpliced.bind(this))},w.prototype.rerenderLines=function(e,t){for(var n,o,r,i,s,a,l,c=this.lines[0].svgElement.parentElement,u=e;u<=t;++u)this.removeLine(this.lines[u]);var h=this.lines[e],f=this.lines[t],d=S.Line.Service.divide(this,h.startIndex,f.endIndex);for(0!==d.length&&(d[0].last=h.last,h.last.map(function(e){return e.next=O.some(d[0])}),d[d.length-1].next=f.next,f.next.map(function(e){return e.last=O.some(d[d.length-1])}),(n=this.lines).splice.apply(n,_([e,t-e+1],d)),0===e?f.next.isSome?d[0].insertBefore(f.next):d[0].insertInto(c):d[0].insertAfter(h.last)),u=1;u<d.length;++u)d[u].insertAfter(O.some(d[u-1]));function p(t){y.constructLabelViewsForLine(t).map(function(e){return t.topContext.renderChild(e)})}var y=this;try{for(var v=I(d),m=v.next();!m.done;m=v.next())p(C=m.value)}catch(e){o={error:e}}finally{try{m&&!m.done&&(r=v.return)&&r.call(v)}finally{if(o)throw o.error}}function b(t){g.constructConnectionsForLine(t).map(function(e){return t.topContext.renderChild(e)})}var g=this;try{for(var x=I(d),w=x.next();!w.done;w=x.next())b(C=w.value)}catch(e){i={error:e}}finally{try{w&&!w.done&&(s=x.return)&&s.call(x)}finally{if(i)throw i.error}}try{for(var E=I(d),L=E.next();!L.done;L=E.next()){var C;(C=L.value).update(),C.topContext.update()}}catch(e){a={error:e}}finally{try{L&&!L.done&&(l=E.return)&&l.call(E)}finally{if(a)throw a.error}}},w.prototype.onLabelCreated=function(e){var t=d(this.findRangeInLines(e.startIndex,e.endIndex),2),n=t[0];if(t[1]===n+1){var o=this.lines[n],r=new m.LabelView.Entity(e,o.topContext,this.config);this.labelViewRepository.add(r),o.topContext.addChild(r),o.topContext.renderChild(r),o.topContext.update(),o.update()}else{var i=this.findHardLineEndsInIndex(n);this.rerenderLines(n,i)}w.layoutTopContextsAfter(this.lines[n]),this.config.contentEditable&&this.contentEditor.update(),this.svgElement.style.height=this.height.toString()+"px"},w.prototype.findRangeInLines=function(n,o){var r=0,i=0;return this.lines.forEach(function(e,t){e.startIndex<=n&&n<e.endIndex&&(r=t),e.startIndex<=o-1&&o-1<e.endIndex&&(i=t+1)}),[r,i]},w.prototype.onConnectionCreated=function(e){var t=this.labelViewRepository.get(e.priorLabel.id),n=t.lineIn.topContext,o=new b.ConnectionView.Entity(e,n,this.config);this.connectionViewRepository.add(o),n.addChild(o),n.renderChild(o),n.update(),t.lineIn.update(),w.layoutTopContextsAfter(t.lineIn),this.config.contentEditable&&this.contentEditor.update(),this.svgElement.style.height=this.height.toString()+"px"},w.prototype.onContentSpliced=function(e,t,n){""!==t&&this.onRemoved(e,t),""!==n&&this.onInserted(e,n)},w.prototype.onRemoved=function(e,t){var n=d(this.findRangeInLines(e,e+1),2),o=n[0];n[1],this.lines[o].startIndex===e-t.length?this.lines[o].move(-t.length):this.lines[o].inserted(-t.length);for(var r=o+1;r<this.lines.length;)this.lines[r].move(-t.length),++r;var i=this.findHardLineEndsInIndex(o);if("\n"===t&&this.lines[o].isBlank){var s=this.lines[o].last,a=this.lines[o].next;this.lines[o].remove(),this.lines.splice(o,1),s.map(function(e){return e.next=a}),a.map(function(e){return e.last=s})}else this.rerenderLines(o,i);w.layoutTopContextsAfter(this.lines[i-1]);var l=Array.from(t).filter(function(e){return"\n"===e}).length;0===l?(this.contentEditor.characterIndex-=t.length,this.contentEditor.avoidInLabel("forward")):0<=this.contentEditor.lineIndex-l&&(this.contentEditor.lineIndex-=l,this.contentEditor.characterIndex=this.contentEditor.line.content.length,this.contentEditor.avoidInLabel("forward")),this.contentEditor.update(),this.svgElement.style.height=this.height.toString()+"px"},w.prototype.onInserted=function(e,t){var n=d(this.findRangeInLines(e,e+1),2),o=n[0];n[1],this.lines[o].startIndex===e+t.length?this.lines[o].move(t.length):this.lines[o].inserted(t.length);for(var r=o+1;r<this.lines.length;)this.lines[r].move(t.length),++r;var i=this.findHardLineEndsInIndex(o);this.rerenderLines(o,i),w.layoutTopContextsAfter(this.lines[i]);var s=Array.from(t),a=s.filter(function(e){return"\n"===e}).length,l=s.lastIndexOf("\n"),c=t.length-l;0===a?this.contentEditor.characterIndex+=t.length:(this.contentEditor.lineIndex+=a,this.contentEditor.characterIndex=c-1),this.contentEditor.avoidInLabel("forward"),this.contentEditor.update(),this.svgElement.style.height=this.height.toString()+"px"},w.prototype.findHardLineEndsInIndex=function(e){var t;for(t=e;t<this.lines.length-1&&!this.lines[t].endWithHardLineBreak;++t);return t},w.prototype.collectStyle=function(){var e=document.createElementNS(p.SVGNS,"style"),t="\n "+this.config.contentClasses.map(function(e){return"."+e}).join(",")+" {\n font-family: "+this.contentFont.fontFamily+";\n font-weight: "+this.contentFont.fontWeight+";\n font-size: "+this.contentFont.fontSize+"px;\n line-height: "+this.contentFont.lineHeight+"px;\n }\n ",n="\n "+this.config.labelClasses.map(function(e){return"."+e}).join(",")+" {\n font-family: "+this.labelFont.fontFamily+";\n font-weight: "+this.labelFont.fontWeight+";\n font-size: "+this.labelFont.fontSize+"px;\n }\n ",o=this.config.connectionClasses.map(function(e){return"."+e}).join(","),r=this.config.connectionClasses.map(function(e){return"."+e+"-line"}).join(","),i="\n "+o+" {\n font-family: "+this.connectionFont.fontFamily+";\n font-weight: "+this.connectionFont.fontWeight+";\n font-size: "+this.connectionFont.fontSize+"px;\n }\n "+r+" {\n stroke: #000;\n }\n ";return e.innerHTML=t+n+i,e},Object.defineProperty(w.prototype,"paddingLeft",{get:function(){var t=this;return Math.max.apply(Math,_(Array.from(this.store.labelCategoryRepo.values()).map(function(e){return t.labelFont.widthOf(e.text)})))/2+1},enumerable:!0,configurable:!0}),w);function w(e,t,n){var o,r,i;this.root=e,this.svgElement=t,this.config=n,this.contentEditor=null,this.store=e.store,this.labelViewRepository=new m.LabelView.Repository,this.connectionViewRepository=new b.ConnectionView.Repository,this.markerElement=w.createMarkerElement(),this.svgElement.appendChild(this.markerElement),this.textElement=document.createElementNS(p.SVGNS,"text"),this.textElement.style.whiteSpace="pre",this.textElement.style.wordWrap="normal",this.svgElement.appendChild(this.textElement);var s=Array.from(this.store.labelCategoryRepo.values()).map(function(e){return e.text}).join(""),a=Array.from(this.store.connectionCategoryRepo.values()).map(function(e){return e.text}).join("");o=d(y.Font.Factory.startBatch(t,this.textElement).thanCreate(n.contentClasses,this.store.content).thanCreate(n.labelClasses,s).thanCreate(n.connectionClasses,a).endBatch(),3),this.contentFont=o[0],this.labelFont=o[1],this.connectionFont=o[2];var l=this.labelFont.lineHeight+2+2*n.labelPadding+n.bracketWidth;this.topContextLayerHeight=2*n.topContextMargin+Math.max(l,this.connectionFont.lineHeight),(r=this.textElement.classList).add.apply(r,_(n.contentClasses)),this.labelCategoryElementFactoryRepository=new v.LabelCategoryElement.FactoryRepository(this,n),this.connectionCategoryElementFactoryRepository=new g.ConnectionCategoryElement.FactoryRepository(this,n),this.lineMaxWidth=t.width.baseVal.value-2*this.paddingLeft,this.lines=S.Line.Service.divide(this,0,this.store.content.length),this.lines.map(this.constructLabelViewsForLine.bind(this)),this.lines.map(this.constructConnectionsForLine.bind(this));var c=this.lines.map(function(e){return e.render()});if((i=this.textElement).append.apply(i,_(c)),this.svgElement.style.height=this.height.toString()+"px",this.registerEventHandlers(),this.config.contentEditable){this.contentEditor=new x.ContentEditor(this);var u=d(this.contentEditor.render(),2),h=u[0],f=u[1];this.svgElement.appendChild(h),this.svgElement.parentNode.insertBefore(f,this.svgElement)}this.svgElement.appendChild(this.collectStyle())}t.View=o},function(e,t,n){"use strict";var i=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s},d=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],o=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){re