define(["require","exports","tslib","react","classnames","comments2/components/annotation_rectangle_creation_layer/resize_handles","comments2/components/annotation_rectangle_creation_layer/utilities","comments2/components/raf_style"],(function(e,t,n,o,r,a,i,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),o=n.__importStar(o),r=n.__importDefault(r);var c=(function(e){function t(){var t=e.apply(this,arguments)||this;return t.state={clickThreshold:i.Threshold.NotExceeded,internalPlacement:null},t.ref=null,t.rectangleRef=null,t.onDeltaStart=function(e,o,r){if(void 0===r&&(r=!1),i.pertainsToLeftClick(e)){var a=e.clientX,s=e.clientY,c=t.rectangleRef,l={x:a,y:s},h=r?n.__assign({},l,{width:0,height:0}):c&&i.clientRectToRectangle(c.getBoundingClientRect());h&&(t.attachListeners(),t.props.onRectChangeStart(r),t.setState({resizeDragMeta:{originPoint:l,deltaMovement:o,originRect:h}}))}},t.onDeltaChange=function(e){var n=t.state,o=n.resizeDragMeta,r=n.clickThreshold;if(o&&t.rectCanChange(e)){var a=e.clientX,s=e.clientY,c=o.originPoint,l=o.deltaMovement,h=o.originRect,d=i.calculateDelta(c,{x:a,y:s});r===i.Threshold.NotExceeded?(t.setState({clickThreshold:i.Threshold.Exceeded}),t.props.onRectChange(i.applyDelta(h,d,l),l,!0)):t.props.onRectChange(i.applyDelta(h,d,l),l)}},t.onDeltaEnd=function(){t.state.clickThreshold===i.Threshold.NotExceeded&&t.props.clearPlacement(),t.removeListeners(),t.props.onRectChangeEnd(),t.setState({resizeDragMeta:void 0,clickThreshold:i.Threshold.Ignore})},t.onRectangleMouseDown=function(e){e.currentTarget===e.target&&t.onDeltaStart(e,a.DragInitiator)},t.buildResizer=function(e){return o.createElement("div",{style:a.resizeStyles[e],key:e,className:a.resizeClasses[e],onMouseDown:function(n){return t.onDeltaStart(n,e)}})},t.setRef=function(e){t.ref=e},t.setRectangleRef=function(e){t.rectangleRef=e},t.onLayerMouseDown=function(e){var n=e.target,o=i.isOnText(e)||i.isOnLink(e),r=t.rectangleRef&&t.rectangleRef.contains(n);o||r||(t.setState({clickThreshold:i.Threshold.NotExceeded}),t.onDeltaStart(e,a.Corner.BottomRight,!0))},t}return n.__extends(t,e),Object.defineProperty(t.prototype,"className",{get:function(){return r.default({"sc-annotation-rectangle-creation-layer":!0,"sc-annotation-rectangle-creation-layer__is-creating":!!this.state.resizeDragMeta})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"annotationClassName",{get:function(){return r.default("sc-annotation-rectangle-creation-draft")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"style",{get:function(){var e=this.props.placement;if(e)return{transform:"translate("+e.x+"px, "+e.y+"px)",width:e.width,height:e.height}},enumerable:!0,configurable:!0}),t.prototype.attachListeners=function(){document.addEventListener("mousemove",this.onDeltaChange,!0),document.addEventListener("mouseup",this.onDeltaEnd)},t.prototype.removeListeners=function(){document.removeEventListener("mousemove",this.onDeltaChange),document.removeEventListener("mouseup",this.onDeltaEnd)},t.prototype.rectCanChange=function(e){var t=this.state,n=t.resizeDragMeta;return t.clickThreshold!==i.Threshold.NotExceeded||n&&i.hasExceededThreshold(n.originPoint,e)},t.prototype.maybeRenderAnnotationDraft=function(){var e=this;if(this.props.placement)return o.createElement(s.RafStyle,{style:this.style},(function(t){return o.createElement("div",{ref:e.setRectangleRef,style:t,className:e.annotationClassName,onMouseDown:e.onRectangleMouseDown},[a.Edge.Top,a.Edge.Left,a.Edge.Right,a.Edge.Bottom,a.Corner.TopLeft,a.Corner.TopRight,a.Corner.BottomLeft,a.Corner.BottomRight].map(e.buildResizer))}))},t.prototype.render=function(){var e=this.className,t=this.setRef,n=this.onLayerMouseDown;return o.createElement("div",{ref:t,className:e,onMouseDown:n},this.props.children,this.maybeRenderAnnotationDraft())},t})(o.PureComponent);t.AnnotationRectangleCreationLayer=c})); //# sourceMappingURL=index.min.js-vflSM_kOB.map