define(["require","exports","tslib","react","classnames","comments2/components/annotation_highlight_draft","comments2/components/annotation_highlight_creation_layer/utilities","comments2/components/add_annotation_highlight_button"],(function(e,t,n,o,i,s,r,a){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),o=n.__importStar(o),i=n.__importDefault(i);var c={x:-100,y:-100},l=(function(e){function t(){var t=e.apply(this,arguments)||this;return t.ref=null,t.isMouseDown=!1,t.hasSelectionChanged=!1,t.state={selectionRects:null},t.handleMouseDown=function(){t.isMouseDown=!0,t.hasSelectionChanged=!1},t.handleMouseUp=function(){t.isMouseDown&&t.hasSelectionChanged&&t.refreshSelection(),t.isMouseDown=!1},t.handleSelectionChange=function(){var e=t.props.onCursorHighlightChange;t.isMouseDown?t.hasSelectionChanged||(e(null),t.hasSelectionChanged=!0):t.refreshSelection()},t.refreshSelection=function(){var e=t.props.onCursorHighlightChange;if(t.textIsSelected){var n=r.getTextSelectionRange(),o=r.getClientRects(n),i=n.getBoundingClientRect();t.setState({selectionRects:o}),e({rangeRects:o,boundingRect:i,isInContainer:t.selectionIsInContainer,size:a.BUTTON_SIZE,margin:a.BUTTON_MARGIN})}else e(null)},t.addAnnotationHighlight=function(){var e=t.state.selectionRects;e&&t.props.onTextHighlightChange(e)},t.setRef=function(e){t.ref=e},t}return n.__extends(t,e),Object.defineProperty(t.prototype,"className",{get:function(){return i.default("sc-annotation-highlight-creation-layer")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonPosition",{get:function(){return this.props.placement.button||c},enumerable:!0,configurable:!0}),t.prototype.textClientRectHasSize=function(e){if(e.isCollapsed)return!1;var t=e.getRangeAt(0).getBoundingClientRect();return 0!==t.width&&0!==t.height},Object.defineProperty(t.prototype,"selectionIsInContainer",{get:function(){var e=window.getSelection();if(null==e)return!1;var t=e.focusNode,n=e.anchorNode,o=this.ref;return Boolean(o&&t&&r.containsNode(o,t)&&n&&r.containsNode(o,n))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"textIsSelected",{get:function(){var e=window.getSelection();if(!e)return!1;var t=e.toString();return!(""===t||"\n"===t||!this.textClientRectHasSize(e))},enumerable:!0,configurable:!0}),t.prototype.componentDidMount=function(){document.addEventListener("selectionchange",this.handleSelectionChange),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)},t.prototype.componentWillUnmount=function(){document.removeEventListener("selectionchange",this.handleSelectionChange),document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp)},t.prototype.onButtonMouseDown=function(e){e.stopPropagation()},t.prototype.render=function(){var e=this.buttonPosition,t=this.className,n=this.props.placement.highlight;return o.createElement("div",{ref:this.setRef,className:t},this.props.children,n&&s.renderAnnotationHighlightDraft(n),o.createElement(a.AddAnnotationHighlightButton,{position:e,isVisible:!!this.props.buttonPosition,onClick:this.addAnnotationHighlight,onMouseDown:this.onButtonMouseDown}))},t})(o.PureComponent);t.AnnotationHighlightCreationLayer=l})); //# sourceMappingURL=index.min.js-vflVA1E_q.map