"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[986,1277],{2268:(e,t,i)=>{i.d(t,{InplaceTextLineSourcePaneView:()=>_,inplaceEditHandlers:()=>u});var n=i(50151),o=i(11542),s=i(52859),r=i(62773),a=i(54707),l=i(2383),d=i(43838),c=i(39612);const h=o.t(null,void 0,i(6060));function u(e){const t=(t,i)=>{i.sourceWasSelected&&e(t)};return{areaName:l.AreaName.Text,executeDefaultAction:{doubleClickHandler:!0,doubleTapHandler:!0},clickHandler:t,tapHandler:t}}class _ extends a.LineSourcePaneView{constructor(e,t,i,n,o){super(e,t,o),this._textInfo=new r.WatchedObject({}),this._isTextEditModeActivated=!1,this._textWasEdited=!1,this._showTextEditor=i,this._hideTextEditor=n,this._editableTextSpawn=this._source.editableText().spawn(),this._editableTextSpawn.subscribe((()=>this._updateTextWasEditable()))}destroy(){this._editableTextSpawn.destroy()}setSelectionRange(e){this._selectionRange=e}closeTextEditor(){this._closeTextEditorImpl()}_closeTextEditorImpl(e){this._textWasEdited=!1,this._isTextEditModeActivated=!1,this._hideTextEditor?.(e)}_placeHolderMode(e){return!this._isTextEditMode()&&this._model.hoveredSource()===this._source&&0===this._model.hoveredSourceOrigin()&&(!e||this._model.lastHittestData()?.areaName!==l.AreaName.AnchorPoint)&&!(0,c.lastMouseOrTouchEventInfo)().isTouch&&!this._source.editableTextProperties().text.value()&&this._model.selection().isSelected(this._source)}_updateTextWasEditable(){this._textWasEdited=!0}_textCursorType(){return this._model.selection().isSelected(this._source)&&!this._model.sourcesBeingMoved().includes(this._source)?d.PaneCursorType.Text:void 0}_updateInplaceText(e){this._textInfo.setValue(e),this._model.selection().isSelected(this._source)||this.closeTextEditor();const t=this._source.textEditingEl();t&&this._activateEditMode(t)}_tryActivateEditMode(e,t){const i=(0,n.ensureNotNull)(t.target instanceof HTMLElement?t.target.closest(".chart-gui-wrapper"):null);this._activateEditMode(i)}_isTextEditMode(){return this._isTextEditModeActivated}_isTextBeingEdited(){return this._textWasEdited}_textData(){return this._text()||(this._textWasEdited?"​":h)}_textColor(){const e=this._source.editableTextProperties().textColor.value();return this._text()?e:(0,s.generateColor)(e,50,!0)}_inplaceTextHighlight(){const e=this._source.editableTextStyle();return this._selectionRange?{selectionHighlight:{start:this._selectionRange[0],end:this._selectionRange[1],color:(0,s.generateColor)(e.selectionColor,80,!0)}}:{}}_activateEditMode(e){this._showTextEditor?.((0,n.ensureNotNull)(this._getOwnerSource()),e,this._textInfo,h,this._closeTextEditorImpl.bind(this)),this._isTextEditModeActivated=!0}_text(){return this._isTextEditMode()?this._source.editableText().value():this._source.editableTextProperties().text.value()}}},63117:(e,t,i)=>{i.d(t,{InplaceTextLineDataSource:()=>S,InplaceTextUndoCommand:()=>m});var n=i(50279),o=i(50151),s=i(10555),r=i(58978),a=i(24377),l=i(11542),d=i(95804),c=i(48943),h=i(22613),u=i(72270),_=i(41414),p=i(40472),g=i(13896);const x={selectionColor:(0, r.getHexColorByName)("color-tv-blue-500"),cursorColor:(0,r.getHexColorByName)("color-black")},T={selectionColor:(0,r.getHexColorByName)("color-white"),cursorColor:(0,r.getHexColorByName)("color-white")};var P;!function(e){e[e.TextEditingJustFinishedTime=100]="TextEditingJustFinishedTime"}(P||(P={}));class m extends u.UndoCommand{constructor(e,t,n,o){super(new d.TranslatedString("change {title} text",l.t(null,void 0,i(57122))).format({title:new d.TranslatedString(t.name(),t.translatedType())}),!0,!g.lineToolsDoNotAffectChartInvalidation),this._sourceId=t.id(),this._model=e,this._oldValue=n,this._newValue=o}redo(){const e=this._source();this._textProperty(e).setValue(this._newValue)}undo(){const e=this._source();this._textProperty(e).setValue(this._oldValue)}_textProperty(e){return e.editableTextProperties().text}_source(){return(0,o.ensureNotNull)(this._model.dataSourceForId(this._sourceId))}}class S extends _.LineDataSource{constructor(e,t,n,o){super(e,t,n,o),this._container=null,this._activeEditingOwnerSource=null,this._editableText=new h.WatchedValue(""),this._activateTextEditingEl=null,this._paneView=null,this._selectionData={},this._cursorPaneView=null,this._cursorPosition=null,this._editingOnCreation=!1,this._editingActivationTime=null,this._editingDeactivationTime=0,this._editableText.subscribe((()=>{this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id()))})),this._isDarkBackground=(0,c.combine)(((e,t)=>{if(null===t)return this._model.dark().value();const i=(0,a.blendRgba)((0,a.parseRgba)(e),(0,a.parseRgba)(t));return"black"===(0,a.rgbToBlackWhiteString)([i[0],i[1],i[2]],150)}),this._model.backgroundColor().spawnOwnership(),this._createDataSourceBackgroundColorWV()),Promise.all([i.e(6290),i.e(986),i.e(6668),i.e(1583)]).then(i.bind(i,87866)).then((t=>{this._cursorPaneView=new t.InplaceTextCursorPaneView(this,e),this._additionalCursorDataGetters&&(this._cursorPaneView.setAdditionalCursorData(...this._additionalCursorDataGetters),null!==this._cursorPosition&&(this._cursorPaneView.setCursorPosition(this._cursorPosition),e.updateSource(this)))}))}destroy(){this._isDarkBackground.destroy(),this._editableText.unsubscribe(),this._closeTextEditor(),super.destroy()}editableTextStyle(){return{...this._isDarkBackground.value()?T:x}}removeIfEditableTextIsEmpty(){return!1}activateEditingOnCreation(){return!1}topPaneViews(e){return this._activeEditingOwnerSource&&e.hasDataSource(this._activeEditingOwnerSource)&&!window.TradingView.printing&&this._cursorPaneView?(this._cursorPaneView.update((0,p.sourceChangeEvent)(this.id())),[this._cursorPaneView]):null}dataAndViewsReady(){return super.dataAndViewsReady()&&null!==this._cursorPaneView}editableText(){return this._editableText}textEditingEl(){return this._activateTextEditingEl}activateTextEditingOn(e,t){this._activateTextEditingEl=e,this._editingOnCreation=!!t,this._editingActivationTime=performance.now(),this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id()))}deactivateTextEditing(){this._closeTextEditor()}textEditingActivationTime(){ return this._editingActivationTime}textEditingJustFinished(){return performance.now()-this._editingDeactivationTime<100}setAdditionalCursorData(e,t){this._cursorPaneView?this._cursorPaneView.setAdditionalCursorData(e,t):this._additionalCursorDataGetters=[e,t]}_updateAllPaneViews(e){super._updateAllPaneViews(e),this._cursorPaneView?.update(e)}async _openTextEditor(e,t,n,r,a){if(null!==this._container)return;null===this._editingActivationTime&&(this._editingActivationTime=performance.now()),this._activateTextEditingEl=null,this._cursorPosition=null,this._container=document.createElement("div"),this._container.style.position="absolute",this._container.style.top="0",this._container.style.bottom="0",this._container.style.left="0",this._container.style.right="0",this._container.style.overflow="hidden",this._container.style.pointerEvents="none",t.appendChild(this._container);const{updateChartEditorText:l,closeChartEditorText:d}=await Promise.all([i.e(3637),i.e(2227),i.e(5592)]).then(i.bind(i,44847));if(null===this._container||this._isDestroyed)return;this._activeEditingOwnerSource=e,this._closeChartEditorText=d;const{text:c,textColor:h,wordWrap:u}=this.editableTextProperties(),{forbidLineBreaks:_,maxLength:g}=this.editableTextStyle();this._editableText.setValue(c.value());const x=this.isFixed()?(0,o.ensureDefined)(this.fixedPoint(e)):(0,o.ensureNotNull)(this.pointToScreenPoint(this._points[0],e)),T={position:(0,s.point)(x.x,x.y),textInfo:n,placeholder:r,text:this._editableText,textColor:h,wordWrap:u,forbidLineBreaks:_,maxLength:g,onClose:a,onSelectionChange:this._onSelectionChange.bind(this),onContextMenu:this.onContextMenu?this.onContextMenu.bind(this):void 0};l(this._container,T),this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id()))}_closeTextEditor(e){null===this._container||this._isDestroyed||(this._editingActivationTime=null,this._editingDeactivationTime=performance.now(),this._saveEditedText(),this._editingOnCreation=!1,this._onSelectionChange(),this._closeChartEditorText?.(this._container),this._closeChartEditorText=void 0,this._container.remove(),this._container=null,this._activeEditingOwnerSource=null,this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id())))}_saveEditedText(){const e=this.editableTextProperties().text.value(),t=this._editableText.value();e!==t&&(this._editingOnCreation&&this.editableTextProperties().text.setValue(t),this._model.undoModel().undoHistory().pushUndoCommand(this._changeEditableTextUndoCommand(e,t)))}_changeEditableTextUndoCommand(e,t){return new m(this._model,this,e,t)}_createDataSourceBackgroundColorWV(){return new h.WatchedValue(null).readonly().ownership()}_onSelectionChange(e){if(null===this._container)return;const t={};if(void 0!==e){const{start:i,end:n}=e;i===n?t.cursorPosition=i:t.selectionRange=[Math.min(i,n),Math.max(i,n)]}(0,n.default)(t,this._selectionData)||(this._selectionData=t,this._paneViews.forEach((e=>{e.forEach((e=>{"setSelectionRange"in e&&e.setSelectionRange(t.selectionRange)}))})), this._cursorPaneView?this._cursorPaneView.setCursorPosition(t.cursorPosition):this._cursorPosition=t.cursorPosition??null,this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id())))}}},54707:(e,t,i)=>{i.d(t,{LineSourcePaneView:()=>x,anchorResizeCursorType:()=>p,createLineSourcePaneViewPoint:()=>g});var n=i(58978),o=i(50151),s=i(39612),r=i(2383),a=i(45801),l=i(73914),d=i(43838),c=i(4753);const h=n.colorsPalette["color-tv-blue-600"];var u,_;function p(e,t){const i=e.x-t.x,n=e.y-t.y;if(!Number.isFinite(i)||!Number.isFinite(n)||0===i&&0===n)return d.PaneCursorType.Default;let s=Math.atan2(n,i);return s<0&&(s+=2*Math.PI),s>=_.deg337_5||s<_.deg22_5||s>=_.deg157_5&&s<_.deg202_5?d.PaneCursorType.HorizontalResize:s>=_.deg22_5&&s<_.deg67_5||s>=_.deg202_5&&s<_.deg247_5?d.PaneCursorType.DiagonalNwSeResize:s>=_.deg67_5&&s<_.deg112_5||s>=_.deg247_5&&s<_.deg292_5?d.PaneCursorType.VerticalResize:s>=_.deg112_5&&s<_.deg157_5||s>=_.deg292_5&&s<_.deg337_5?d.PaneCursorType.DiagonalNeSwResize:void(0,o.assert)(!1,"unexpected angle")}function g(e,t){return e.pointIndex=t,e}!function(e){e[e.RegularAnchorRadius=6]="RegularAnchorRadius",e[e.TouchAnchorRadius=13]="TouchAnchorRadius",e[e.RegularStrokeWidth=1]="RegularStrokeWidth",e[e.TouchStrokeWidth=3]="TouchStrokeWidth",e[e.RegularSelectedStrokeWidth=3]="RegularSelectedStrokeWidth",e[e.TouchSelectedStrokeWidth=0]="TouchSelectedStrokeWidth"}(u||(u={})),function(e){e[e.deg22_5=Math.PI/8]="deg22_5",e[e.deg67_5=3*Math.PI/8]="deg67_5",e[e.deg112_5=5*Math.PI/8]="deg112_5",e[e.deg157_5=7*Math.PI/8]="deg157_5",e[e.deg202_5=9*Math.PI/8]="deg202_5",e[e.deg247_5=11*Math.PI/8]="deg247_5",e[e.deg292_5=13*Math.PI/8]="deg292_5",e[e.deg337_5=15*Math.PI/8]="deg337_5"}(_||(_={}));class x{constructor(e,t,i){this._invalidated=!0,this._points=[],this._middlePoint=null,this._selectionRenderers=[],this._lineAnchorRenderers=[],this._source=e,this._model=t,this._ownerSource=i??null}priceToCoordinate(e){const t=this._getOwnerSource(),i=t?.priceScale();if(null==i)return null;const n=null!==t?t.firstValue():null;return null===n?null:i.priceToCoordinate(e,n)}anchorColor(){return h}isHoveredSource(){return this._source===this._model.hoveredSource()}isSelectedSource(){return this._model.selection().isSelected(this._source)}isBeingEdited(){return this._model.lineBeingEdited()===this._source}isEditMode(){return!this._model.isSnapshot()}areAnchorsVisible(){return(this.isHoveredSource()&&!this.isLocked()||this.isSelectedSource())&&this.isEditMode()}update(){this._invalidated=!0}isLocked(){return Boolean(this._source.isLocked&&this._source.isLocked())}addAnchors(e,t={}){let i=this._getPoints();this._model.lineBeingCreated()===this._source&&(i=i.slice(0,-1));const n=this._source.points(),o=i.map(((e,t)=>{const i=n[t],o=(0,l.lineSourcePaneViewPointToLineAnchorPoint)(e);return i&&(o.snappingPrice=i.price,o.snappingIndex=i.index),o}));e.append(this.createLineAnchor({...t,points:o},0))}createLineAnchor(e,t){const i=e.points.map((e=>e.point)),n=this._getOwnerSource();if(this.isLocked()){const o=this._getSelectionRenderer(t) ;return o.setData({bgColors:this._lineAnchorColors(i),points:e.points,visible:this.areAnchorsVisible(),hittestResult:r.HitTarget.Regular,ownerSourceId:n?.id(),barSpacing:this._model.timeScale().barSpacing()}),o}const o=(0,s.lastMouseOrTouchEventInfo)().isTouch,a=this._getLineAnchorRenderer(t),l=this.isHoveredSource()?this._model.lastHittestData()?.pointIndex??null:null;return a.setData({...e,color:this.anchorColor(),backgroundColors:this._lineAnchorColors(i),hoveredPointIndex:l,linePointBeingEdited:this.isBeingEdited()?this._model.linePointBeingEdited():null,radius:this._anchorRadius(),strokeWidth:o?u.TouchStrokeWidth:u.RegularStrokeWidth,selected:this.isSelectedSource(),selectedStrokeWidth:o?u.TouchSelectedStrokeWidth:u.RegularSelectedStrokeWidth,visible:this.areAnchorsVisible(),clickHandler:e.clickHandler,ownerSourceId:n?.id()}),a}_getOwnerSource(){return this._ownerSource??this._source.ownerSource()}_anchorRadius(){return(0,s.lastMouseOrTouchEventInfo)().isTouch?u.TouchAnchorRadius:u.RegularAnchorRadius}_lineAnchorColors(e){const t=(0,o.ensureNotNull)(this._model.paneForSource(this._source)).height();return e.map((e=>this._model.backgroundColorAtYPercentFromTop(e.y/t)))}_updateImpl(e){this._points=[];this._model.timeScale().isEmpty()||this._validatePriceScale()&&(this._source.points().forEach(((e,t)=>{const i=this._source.pointToScreenPoint(e,this._ownerSource??void 0);i&&this._points.push(g(i,t))})),2===this._points.length&&(this._middlePoint=this._source.calcMiddlePoint(this._points[0],this._points[1])),this._invalidated=!1)}_validatePriceScale(){const e=this._getOwnerSource()?.priceScale();return null!=e&&!e.isEmpty()}_getSource(){return this._source}_getPoints(){return this._points}_getModel(){return this._model}_height(){const e=this._getOwnerSource()?.priceScale();return null!=e?e.height():0}_width(){return this._model.timeScale().width()}_needLabelExclusionPath(e,t){const i=this._source.properties().childs();return"middle"===(t??i.vertLabelsAlign.value())&&(0,c.needTextExclusionPath)(e)}_addAlertRenderer(e,t,i=this._source.properties().linecolor.value()){}_getAlertRenderer(e,t=this._source.properties().linecolor.value(),i){return null}_getSelectionRenderer(e){for(;this._selectionRenderers.length<=e;)this._selectionRenderers.push(new a.SelectionRenderer);return this._selectionRenderers[e]}_getLineAnchorRenderer(e){for(;this._lineAnchorRenderers.length<=e;)this._lineAnchorRenderers.push(new l.LineAnchorRenderer);return this._lineAnchorRenderers[e]}}},73914:(e,t,i)=>{i.d(t,{LineAnchorRenderer:()=>T,lineSourcePaneViewPointToLineAnchorPoint:()=>P,lineSourcePaneViewPointToLineAnchorPoint2:()=>m,mapLineSourcePaneViewPointToLineAnchorPoint:()=>S});var n=i(10555),o=i(6453),s=i(50151),r=i(58221),a=i(87465),l=i(2383),d=i(43838),c=i(4539),h=i(10307);function u(e,t,i,n){const{point:o}=t,s=i+n/2;(0,r.drawRoundRect)(e,o.x-s,o.y-s,2*s,2*s,(i+n)/2),e.closePath(),e.lineWidth=n}function _(e,t,i,n){e.globalAlpha=.2,u(e,t,i,n),e.stroke(),e.globalAlpha=1}function p(e,t,i,n){u(e,t,i-n,n),e.fill(),e.stroke()}function g(e,t,i,n){ const{point:o}=t;e.globalAlpha=.2,e.beginPath(),e.arc(o.x,o.y,i+n/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=n,e.stroke(),e.globalAlpha=1}function x(e,t,i,n){const{point:o}=t;e.beginPath(),e.arc(o.x,o.y,i-n/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=n,e.fill(),e.stroke()}class T extends h.BitmapCoordinatesPaneRenderer{constructor(e){super(),this._data=e??null}setData(e){this._data=e}hitTest(e){if(null===this._data||this._data.disableInteractions)return null;const{radius:t,points:i}=this._data,n=t+(0,c.interactionTolerance)().anchor;for(const t of i){if(t.point.subtract(e).length()<=n)return new l.HitTestResult(t.hitTarget??l.HitTarget.ChangePoint,{areaName:l.AreaName.AnchorPoint,pointIndex:t.pointIndex,cursorType:t.cursorType??d.PaneCursorType.Default,activeItem:t.activeItem,snappingPrice:t.snappingPrice,snappingIndex:t.snappingIndex,nonDiscreteIndex:t.nonDiscreteIndex,possibleMovingDirections:t.possibleMovingDirections,clickHandler:this._data.clickHandler,tapHandler:this._data.clickHandler,ownerSourceId:this._data.ownerSourceId})}return null}doesIntersectWithBox(e){return null!==this._data&&this._data.points.some((t=>(0,o.pointInBox)(t.point,e)))}_drawImpl(e){if(null===this._data||!this._data.visible)return;const t=[],i=[],n=[],o=[];for(let e=0;e