"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[688],{9587:(t,e,i)=>{i.r(e),i.d(e,{LineToolCallout:()=>c});var n,s=i(48943),r=i(3156),o=i(43337),a=i(78176),l=i(18712),h=i(65045),d=i(63117);!function(t){t[t.PointsCount=2]="PointsCount",t.Name="Callout"}(n||(n={}));class c extends d.InplaceTextLineDataSource{constructor(t,e,n,s){super(t,e||c.createProperties(t.backgroundTheme().spawnOwnership()),n,s),this._barOffset=0,this._dragStartLeftEdgeIndex=NaN,this._timeScale=t.timeScale(),Promise.all([i.e(6290),i.e(986),i.e(6668),i.e(1583)]).then(i.bind(i,4787)).then((t=>{this._paneView=new t.CalloutPaneView(this,this._model,this._openTextEditor.bind(this),this._closeTextEditor.bind(this)),this._setPaneViews([this._paneView])}))}pointsCount(){return 2}name(){return"Callout"}getBarOffset(){return this._barOffset}editableTextProperties(){const t=this.properties().childs();return{text:t.text,textColor:t.color,wordWrap:t.wordWrap}}removeIfEditableTextIsEmpty(){return!0}activateEditingOnCreation(){return!0}shouldBeRemovedOnDeselect(){const t=this._properties.childs().text.value().trim();return this._points.length===this.pointsCount()&&""===t}addPoint(t){const e=super.addPoint(t);return e&&this._calculateBarOffset(),e}setLastPoint(t){const e=super.setLastPoint(t);return 2===this.points().length&&this._calculateBarOffset(),e}setPoint(t,e){switch(t){case 0:super.setPoint(t,e),this._calculateBarOffset();break;case 1:const i=this.properties().childs();if(!i.wordWrapWidth)return;const n=this._points,s=this._dragStartLeftEdgeIndex,r=Math.round((e.index-s)/2),o=this._model.mainSeries().interval();if(isFinite(s)&&isFinite(r)){n[1]={index:s+r,price:n[1].price,interval:o},this._calculateBarOffset(),this._normalizePoints();const t=this._timeScale.indexToCoordinate(s+2*r)-this._timeScale.indexToCoordinate(s)-8-2;if(!isFinite(t))return;i.wordWrapWidth.setValue(Math.max(100,t));break}n[1]={...e,interval:o},this._calculateBarOffset(),this._normalizePoints()}}setPoints(t){super.setPoints(t);const e=this.properties().childs();if(!e.wordWrapWidth)return;const i=this._dragStartLeftEdgeIndex,n=Math.round((t[1].index-i)/2);if(this._calculateBarOffset(),this._normalizePoints(),isFinite(i)&&isFinite(n)){const t=this._timeScale.indexToCoordinate(i+2*n)-this._timeScale.indexToCoordinate(i)-8-2;if(!isFinite(t))return;e.wordWrapWidth.setValue(Math.max(100,t))}}move(t,e,i){super.move(t,e,i),this._calculateBarOffset()}state(t){const e=super.state(t);return e.barOffset=this._barOffset,e}restoreData(t){t.barOffset?this._barOffset=t.barOffset:this._calculateBarOffset(),this.calculatePoint2()}setPriceScale(t){super.setPriceScale(t),t&&t.priceRange()&&this.calculatePoint2()}template(){const t=super.template();return t.text=this.properties().childs().text.value(),t}calculatePoint2(){if(this._model.lineBeingEdited()===this||this._model.sourcesBeingMoved().includes(this))return;if(this._points.length<2)return;const[t,e]=this.points();this._points[1]={price:e.price,index:t.index+this._barOffset,
interval:this._model.mainSeries().interval()}}static createProperties(t,e){const i=new a.DefaultProperty({defaultName:"linetoolcallout",state:e,theme:t});return this._configureProperties(i),i}_applyTemplateImpl(t){this.properties().childs().text.setValue(t.text),super._applyTemplateImpl(t)}_correctPoints(t,e){if(t.length<this.pointsCount()||null===this._currentMovingPoint||void 0===this._currentMovingPoint.logical||null===this._startMovingPoint||void 0===this._startMovingPoint.logical)return!1;const i=this._currentMovingPoint.logical.index-this._startMovingPoint.logical.index,n=this._currentMovingPoint.logical.price-this._startMovingPoint.logical.price,s=t[1];return s.index=s.index+i,s.price+=n,t[1]=s,!0}_onPointsetUpdated(t){super._onPointsetUpdated(t),0!==t.length&&(1===this._points.length&&this._points.push(this._points[0]),this._dragStartLeftEdgeIndex=this.points()[1].index)}_normalizePoint(t,e){return 0===e?super._normalizePointWithoutOffset(t)??super._normalizePoint(t,e):super._normalizePoint(t,e)}_createDataSourceBackgroundColorWV(){const t=(0,r.generateColorCached)(),{backgroundColor:e,transparency:i}=this.properties().childs();return(0,s.combine)(((e,i)=>t(e,i)),(0,l.convertPropertyToWatchedValue)(e).ownership(),(0,l.convertPropertyToWatchedValue)(i).ownership()).ownership()}async _getPropertyDefinitionsViewModelClass(){return(await Promise.all([i.e(3198),i.e(5410),i.e(2745),i.e(8823),i.e(8537)]).then(i.bind(i,1006))).CalloutDefinitionsViewModel}static _configureProperties(t){super._configureProperties(t),t.hasChild("text")||t.addChild("text",new o.Property("")),t.addExcludedKey("text",1),t.addChild("textsColors",new h.LineToolColorsProperty([t.childs().color]))}_calculateBarOffset(){this.points().length>1&&(this._barOffset=this.points()[1].index-this.points()[0].index)}}},63117:(t,e,i)=>{i.d(e,{InplaceTextLineDataSource:()=>w,InplaceTextUndoCommand:()=>C});var n=i(50279),s=i(50151),r=i(10555),o=i(58978),a=i(24377),l=i(11542),h=i(95804),d=i(48943),c=i(22613),u=i(72270),_=i(41414),p=i(40472),g=i(13896);const x={selectionColor:(0,o.getHexColorByName)("color-tv-blue-500"),cursorColor:(0,o.getHexColorByName)("color-black")},f={selectionColor:(0,o.getHexColorByName)("color-white"),cursorColor:(0,o.getHexColorByName)("color-white")};var m;!function(t){t[t.TextEditingJustFinishedTime=100]="TextEditingJustFinishedTime"}(m||(m={}));class C extends u.UndoCommand{constructor(t,e,n,s){super(new h.TranslatedString("change {title} text",l.t(null,void 0,i(57122))).format({title:new h.TranslatedString(e.name(),e.translatedType())}),!0,!g.lineToolsDoNotAffectChartInvalidation),this._sourceId=e.id(),this._model=t,this._oldValue=n,this._newValue=s}redo(){const t=this._source();this._textProperty(t).setValue(this._newValue)}undo(){const t=this._source();this._textProperty(t).setValue(this._oldValue)}_textProperty(t){return t.editableTextProperties().text}_source(){return(0,s.ensureNotNull)(this._model.dataSourceForId(this._sourceId))}}class w extends _.LineDataSource{constructor(t,e,n,s){super(t,e,n,s),this._container=null,
this._activeEditingOwnerSource=null,this._editableText=new c.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,d.combine)(((t,e)=>{if(null===e)return this._model.dark().value();const i=(0,a.blendRgba)((0,a.parseRgba)(t),(0,a.parseRgba)(e));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((e=>{this._cursorPaneView=new e.InplaceTextCursorPaneView(this,t),this._additionalCursorDataGetters&&(this._cursorPaneView.setAdditionalCursorData(...this._additionalCursorDataGetters),null!==this._cursorPosition&&(this._cursorPaneView.setCursorPosition(this._cursorPosition),t.updateSource(this)))}))}destroy(){this._isDarkBackground.destroy(),this._editableText.unsubscribe(),this._closeTextEditor(),super.destroy()}editableTextStyle(){return{...this._isDarkBackground.value()?f:x}}removeIfEditableTextIsEmpty(){return!1}activateEditingOnCreation(){return!1}topPaneViews(t){return this._activeEditingOwnerSource&&t.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(t,e){this._activateTextEditingEl=t,this._editingOnCreation=!!e,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(t,e){this._cursorPaneView?this._cursorPaneView.setAdditionalCursorData(t,e):this._additionalCursorDataGetters=[t,e]}_updateAllPaneViews(t){super._updateAllPaneViews(t),this._cursorPaneView?.update(t)}async _openTextEditor(t,e,n,o,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",e.appendChild(this._container);const{updateChartEditorText:l,closeChartEditorText:h}=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=t,this._closeChartEditorText=h;const{text:d,textColor:c,wordWrap:u}=this.editableTextProperties(),{forbidLineBreaks:_,maxLength:g}=this.editableTextStyle();this._editableText.setValue(d.value());const x=this.isFixed()?(0,s.ensureDefined)(this.fixedPoint(t)):(0,s.ensureNotNull)(this.pointToScreenPoint(this._points[0],t)),f={position:(0,r.point)(x.x,x.y),textInfo:n,placeholder:o,text:this._editableText,textColor:c,wordWrap:u,forbidLineBreaks:_,maxLength:g,onClose:a,onSelectionChange:this._onSelectionChange.bind(this),onContextMenu:this.onContextMenu?this.onContextMenu.bind(this):void 0};l(this._container,f),this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id()))}_closeTextEditor(t){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 t=this.editableTextProperties().text.value(),e=this._editableText.value();t!==e&&(this._editingOnCreation&&this.editableTextProperties().text.setValue(e),this._model.undoModel().undoHistory().pushUndoCommand(this._changeEditableTextUndoCommand(t,e)))}_changeEditableTextUndoCommand(t,e){return new C(this._model,this,t,e)}_createDataSourceBackgroundColorWV(){return new c.WatchedValue(null).readonly().ownership()}_onSelectionChange(t){if(null===this._container)return;const e={};if(void 0!==t){const{start:i,end:n}=t;i===n?e.cursorPosition=i:e.selectionRange=[Math.min(i,n),Math.max(i,n)]}(0,n.default)(e,this._selectionData)||(this._selectionData=e,this._paneViews.forEach((t=>{t.forEach((t=>{"setSelectionRange"in t&&t.setSelectionRange(e.selectionRange)}))})),this._cursorPaneView?this._cursorPaneView.setCursorPosition(e.cursorPosition):this._cursorPosition=e.cursorPosition??null,this.updateAllViewsAndRedraw((0,p.sourceChangeEvent)(this.id())))}}},3156:(t,e,i)=>{i.d(e,{generateColorCached:()=>o});var n=i(59332),s=i(52859),r=i(16659);function o(t=1e3){const e=n.default.Cache;n.default.Cache=r.CircularCacheBuffer.bind(r.CircularCacheBuffer,t);const i=(0,n.default)(s.generateColor,((t,e,i)=>`${t}_${e}_${i}`));return n.default.Cache=e,i}}}]);