"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[3723],{40226:(e,t,i)=>{i.d(t,{LevelsProperty:()=>x});var s=i(90054),n=i(16738),r=i(87465),o=i(78176),a=i(60973);const l={prefixes:[""],range:[0,0],names:["coeff","color","visible","linestyle","linewidth"],typecheck:{pack:()=>Object(),unpack:()=>[]}};function d(e,t,i,s){return s.push(i[t]),s}function c(e,t,i,s){return s[t]=i[e],s}function u(){return[]}function h(){return{}}function p(e,t,i){return i.prefixes.forEach((s=>{const n=s+"level";for(let s=i.range[0];s<=i.range[1];s++)if(e[n+s]&&(0,r.isSameType)(e[n+s],t.typecheck())){let r=t.tpl();i.names.forEach(((i,o)=>{r=t.fill(""+o,i,e[n+s],r)})),e[n+s]=r}})),e}function _(e,t,i){return i(e,{tpl:h,fill:c,typecheck:t.typecheck.unpack},t)}class x extends o.DefaultProperty{constructor(e){const{levelsIterator:t=p,map:i={},...s}=e,n={...l,...i};s.state&&(s.state=_(s.state,n,t)),super(s),this._map=n,this._levelsIterator=t}state(e,t,i){const s=super.state(e,t);return i?s:(n=s,r=this._map,(0,this._levelsIterator)(n,{tpl:u,fill:d,typecheck:r.typecheck.pack},r));var n,r}preferences(){return(0,o.extractState)(this.state(this._excludedDefaultsKeys,void 0,!0),this._allDefaultsKeys)}applyTemplate(e,t){this.mergeAndFire((0,o.extractState)((0,n.default)((0,s.default)(t),_(e,this._map,this._levelsIterator)),this._allStateKeys,this._excludedTemplateKeys))}saveDefaults(){this._useUserPreferences&&(0,a.saveDefaults)(this._defaultName,this.preferences())}clone(){return new x(this._options())}merge(e,t){return super.merge(this._map?_(e,this._map,this._levelsIterator):e,t)}_options(){return{...super._options(),map:{...this._map},levelsIterator:this._levelsIterator}}}},90990:(e,t,i)=>{i.d(t,{LineToolFibWithInplaceTextBase:()=>d,getLevelProps:()=>a});var s=i(50151),n=i(43337),r=i(63117);const o=new n.Property(!1);function a(e,t){return(0,s.ensureDefined)(e.child(`level${t}`))}class l extends r.InplaceTextUndoCommand{constructor(e,t,i,s,n){super(e,t,i,s),this._levelIndex=n}_textProperty(e){return a(e.properties(),this._levelIndex).childs().text}}class d extends r.InplaceTextLineDataSource{constructor(){super(...arguments),this._inplaceEditLevelIndex=1}editableTextStyle(){return{...super.editableTextStyle(),forbidLineBreaks:!0,maxLength:50}}editableTextProperties(){const e=this.properties().childs();return{text:e.editableText,textColor:e.editableTextColor,wordWrap:o}}setInplaceEditLevelIndex(e){this._destroyEditableTextSubscriptions?.();const t=this.properties(),i=t.childs().editableText,n=t.childs().editableTextColor,r=a(t,e),o=(0,s.ensureDefined)(r).childs().text,l=(0,s.ensureDefined)(r).childs().color,d={};i.setValue(o.value()),n.setValue(l.value()),i.subscribe(d,(()=>o.setValue(i.value()))),o.subscribe(d,(()=>i.setValue(o.value()))),n.subscribe(d,(()=>l.setValue(n.value()))),l.subscribe(d,(()=>n.setValue(l.value()))),this._destroyEditableTextSubscriptions=()=>{i.unsubscribeAll(d),o.unsubscribeAll(d),n.unsubscribeAll(d),l.unsubscribeAll(d)},this._inplaceEditLevelIndex=e,this._editableText.setValue(i.value())}
_changeEditableTextUndoCommand(e,t){return new l(this._model,this,e,t,this._inplaceEditLevelIndex)}static _configureProperties(e){super._configureProperties(e),e.addChild("editableText",new n.Property("")),e.addChild("editableTextColor",new n.Property("")),e.addExcludedKey("editableText",3),e.addExcludedKey("editableTextColor",3)}}},91308:(e,t,i)=>{i.r(t),i.d(t,{LineToolFibRetracement:()=>h});var s,n,r=i(11542),o=i(95804),a=i(40226),l=i(13896),d=i(65045),c=i(90990);!function(e){e[e.FibRetracement=1]="FibRetracement",e[e.FibRetracementV2=2]="FibRetracementV2",e[e.Latest=2]="Latest"}(s||(s={})),function(e){e[e.LevelsCount=24]="LevelsCount",e[e.PointsCount=2]="PointsCount",e.Name="Fib Retracement"}(n||(n={}));const u=new o.TranslatedString("erase level line",r.t(null,void 0,i(77114)));class h extends c.LineToolFibWithInplaceTextBase{constructor(e,t,s,n){super(e,t??h.createProperties(e.backgroundTheme().spawnOwnership()),s,n),this.version=2,Promise.all([i.e(6290),i.e(986),i.e(6668),i.e(1583)]).then(i.bind(i,26506)).then((e=>{this._paneView=new e.FibRetracementPaneView(this,this._model,this._openTextEditor.bind(this),this._closeTextEditor.bind(this)),this._setPaneViews([this._paneView])}))}levelsCount(){return 24}pointsCount(){return 2}name(){return"Fib Retracement"}migrateVersion(e){1===e&&this.properties().childs().extendLines.setValue(!0)}processErase(e,t){const i="level"+t,{visible:s}=this.properties().childs()[i].childs();e.setProperty(s,!1,u,l.lineToolsDoNotAffectChartInvalidation)}fibLevelsBasedOnLogScale(){return this.properties().childs().fibLevelsBasedOnLogScale.value()&&!!this.priceScale()?.isLog()}template(){const e=super.template();for(let t=1;t<=24;t++){const i=(0,c.getLevelProps)(this._properties,t);e[`level${t}`].text=i.childs().text.value()}return e}static createProperties(e,t){const i=new a.LevelsProperty({defaultName:"linetoolfibretracement",state:t,map:{range:[1,24],names:["coeff","color","visible","text"]},theme:e});return this._configureProperties(i),i}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,55200))).FibDrawingsWith24LevelsDefinitionsViewModel}_applyTemplateImpl(e){for(let t=1;t<=24;t++){const i=(0,c.getLevelProps)(this._properties,t),s=e[`level${t}`];i.childs().text.setValue(s.text??s[3]??"")}super._applyTemplateImpl(e)}static _configureProperties(e){super._configureProperties(e);const t=[e.childs().trendline.childs().linewidth,e.childs().levelsStyle.childs().linewidth],i=[e.childs().trendline.childs().color];for(let t=1;t<=24;t++){const s=(0,c.getLevelProps)(e,t);i.push(s.childs().color),e.addExcludedKey(`level${t}.text`,1)}e.addChild("linesColors",new d.LineToolColorsProperty(i)),e.addChild("linesWidths",new d.LineToolWidthsProperty(t))}}},63117:(e,t,i)=>{i.d(t,{InplaceTextLineDataSource:()=>T,InplaceTextUndoCommand:()=>g});var s=i(50279),n=i(50151),r=i(10555),o=i(58978),a=i(24377),l=i(11542),d=i(95804),c=i(48943),u=i(22613),h=i(72270),p=i(41414),_=i(40472),x=i(13896);const v={selectionColor:(0,
o.getHexColorByName)("color-tv-blue-500"),cursorColor:(0,o.getHexColorByName)("color-black")},m={selectionColor:(0,o.getHexColorByName)("color-white"),cursorColor:(0,o.getHexColorByName)("color-white")};var b;!function(e){e[e.TextEditingJustFinishedTime=100]="TextEditingJustFinishedTime"}(b||(b={}));class g extends h.UndoCommand{constructor(e,t,s,n){super(new d.TranslatedString("change {title} text",l.t(null,void 0,i(57122))).format({title:new d.TranslatedString(t.name(),t.translatedType())}),!0,!x.lineToolsDoNotAffectChartInvalidation),this._sourceId=t.id(),this._model=e,this._oldValue=s,this._newValue=n}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,n.ensureNotNull)(this._model.dataSourceForId(this._sourceId))}}class T extends p.LineDataSource{constructor(e,t,s,n){super(e,t,s,n),this._container=null,this._activeEditingOwnerSource=null,this._editableText=new u.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,_.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()?m:v}}removeIfEditableTextIsEmpty(){return!1}activateEditingOnCreation(){return!1}topPaneViews(e){return this._activeEditingOwnerSource&&e.hasDataSource(this._activeEditingOwnerSource)&&!window.TradingView.printing&&this._cursorPaneView?(this._cursorPaneView.update((0,_.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,_.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,s,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",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:u,wordWrap:h}=this.editableTextProperties(),{forbidLineBreaks:p,maxLength:x}=this.editableTextStyle();this._editableText.setValue(c.value());const v=this.isFixed()?(0,n.ensureDefined)(this.fixedPoint(e)):(0,n.ensureNotNull)(this.pointToScreenPoint(this._points[0],e)),m={position:(0,r.point)(v.x,v.y),textInfo:s,placeholder:o,text:this._editableText,textColor:u,wordWrap:h,forbidLineBreaks:p,maxLength:x,onClose:a,onSelectionChange:this._onSelectionChange.bind(this),onContextMenu:this.onContextMenu?this.onContextMenu.bind(this):void 0};l(this._container,m),this.updateAllViewsAndRedraw((0,_.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,_.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 g(this._model,this,e,t)}_createDataSourceBackgroundColorWV(){return new u.WatchedValue(null).readonly().ownership()}_onSelectionChange(e){if(null===this._container)return;const t={};if(void 0!==e){const{start:i,end:s}=e;i===s?t.cursorPosition=i:t.selectionRange=[Math.min(i,s),Math.max(i,s)]}(0,s.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,_.sourceChangeEvent)(this.id())))}}}}]);