Files
ai/web/public/charting_library/bundles/line-tool-rectangle.216a3e91b03758570d50.js

6 lines
16 KiB
JavaScript

"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[8422],{31558:(e,t,i)=>{i.d(t,{commonLineToolPropertiesStateKeys:()=>n});const n=["symbolStateVersion","zOrderVersion","frozen","title","interval","symbol","currencyId","unitId","visible","intervalsVisibilities.ticks","intervalsVisibilities.seconds","intervalsVisibilities.secondsFrom","intervalsVisibilities.secondsTo","intervalsVisibilities.minutes","intervalsVisibilities.minutesFrom","intervalsVisibilities.minutesTo","intervalsVisibilities.hours","intervalsVisibilities.hoursFrom","intervalsVisibilities.hoursTo","intervalsVisibilities.days","intervalsVisibilities.daysFrom","intervalsVisibilities.daysTo","intervalsVisibilities.weeks","intervalsVisibilities.weeksFrom","intervalsVisibilities.weeksTo","intervalsVisibilities.months","intervalsVisibilities.monthsFrom","intervalsVisibilities.monthsTo","intervalsVisibilities.ranges"];var s,o,r;!function(e){e[e.NotShared=0]="NotShared",e[e.SharedInLayout=1]="SharedInLayout",e[e.GloballyShared=2]="GloballyShared"}(s||(s={})),function(e){e.BeforeAllAction="BeforeAll",e.CustomAction="CustomAction"}(o||(o={})),function(e){e.FloatingToolbarButton="FloatingToolbarButton",e.Default="Default"}(r||(r={}))},63117:(e,t,i)=>{i.d(t,{InplaceTextLineDataSource:()=>b,InplaceTextUndoCommand:()=>P});var n=i(50279),s=i(50151),o=i(10555),r=i(58978),a=i(24377),l=i(11542),c=i(95804),d=i(48943),h=i(22613),u=i(72270),p=i(41414),_=i(40472),x=i(13896);const T={selectionColor:(0,r.getHexColorByName)("color-tv-blue-500"),cursorColor:(0,r.getHexColorByName)("color-black")},g={selectionColor:(0,r.getHexColorByName)("color-white"),cursorColor:(0,r.getHexColorByName)("color-white")};var m;!function(e){e[e.TextEditingJustFinishedTime=100]="TextEditingJustFinishedTime"}(m||(m={}));class P extends u.UndoCommand{constructor(e,t,n,s){super(new c.TranslatedString("change {title} text",l.t(null,void 0,i(57122))).format({title:new c.TranslatedString(t.name(),t.translatedType())}),!0,!x.lineToolsDoNotAffectChartInvalidation),this._sourceId=t.id(),this._model=e,this._oldValue=n,this._newValue=s}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,s.ensureNotNull)(this._model.dataSourceForId(this._sourceId))}}class b extends p.LineDataSource{constructor(e,t,n,s){super(e,t,n,s),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,_.sourceChangeEvent)(this.id()))})),this._isDarkBackground=(0,d.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()?g:T}}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,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:c}=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=c;const{text:d,textColor:h,wordWrap:u}=this.editableTextProperties(),{forbidLineBreaks:p,maxLength:x}=this.editableTextStyle();this._editableText.setValue(d.value());const T=this.isFixed()?(0,s.ensureDefined)(this.fixedPoint(e)):(0,s.ensureNotNull)(this.pointToScreenPoint(this._points[0],e)),g={position:(0,o.point)(T.x,T.y),textInfo:n,placeholder:r,text:this._editableText,textColor:h,wordWrap:u,forbidLineBreaks:p,maxLength:x,onClose:a,
onSelectionChange:this._onSelectionChange.bind(this),onContextMenu:this.onContextMenu?this.onContextMenu.bind(this):void 0};l(this._container,g),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 P(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,_.sourceChangeEvent)(this.id())))}}},88636:(e,t,i)=>{i.d(t,{LineDataSourceProperty:()=>a});var n=i(90054),s=i(16738),o=i(50151),r=i(78176);class a extends r.DefaultProperty{constructor({templateKeys:e,...t}){super({ignoreAllowSavingDefaults:!0,saveNonDefaultUserPreferencesOnly:!0,...t}),this._templateKeys=(0,o.ensureDefined)(e||this._allDefaultsKeys)}template(){return(0,r.extractState)(this.state(),this._templateKeys,[])}applyTemplate(e){this.mergeAndFire((0,r.extractState)((0,s.default)((0,n.default)(this._factoryDefaultsSupplier()),e),this._templateKeys))}}},22132:(e,t,i)=>{i.r(t),i.d(t,{Constants:()=>A,LineToolRectangle:()=>D});var n=i(50151),s=i(10555),o=i(48943),r=i(18712),a=i(43337),l=i(63117),c=i(65045),d=i(24633),h=i(49156),u=i(78176),p=i(70031),_=i(37293),x=i(18330),T=i(50605),g=i(31558),m=i(88636),P=i(59883);const b={intervalsVisibilities:{..._.intervalsVisibilitiesDefaults},color:h.colors.colorGrapesPurple500,fillBackground:!0,backgroundColor:h.colors.colorGrapesPurple500Alpha20,linewidth:P.DEFAULT_LINE_TOOL_LINE_WIDTH,transparency:50,horzLabelsAlign:T.HorizontalAlign.Center,vertLabelsAlign:T.VerticalAlign.Middle,textColor:h.colors.colorGrapesPurple500,fontSize:14,bold:!1,italic:!1,extendLeft:!1,extendRight:!1,middleLine:{showLine:!1,lineWidth:1,lineColor:h.colors.colorGrapesPurple500,lineStyle:x.LineStyle.Dashed},linestyle:x.LineStyle.Solid},w=new Map([[d.StdTheme.Light,{}],[d.StdTheme.Dark,{}]]),f=(0,u.extractThemedColors)((0,
n.ensureDefined)(w.get(d.StdTheme.Light)),(0,n.ensureDefined)(w.get(d.StdTheme.Dark))),y=(0,u.extractAllPropertiesKeys)((0,n.ensureDefined)(w.get(d.StdTheme.Light))),v=(0,u.extractAllPropertiesKeys)(b),C=[...new Set([...y,...v,...g.commonLineToolPropertiesStateKeys,"text"])],S=[...new Set([...y,...v,"text"])];class V extends m.LineDataSourceProperty{constructor(e){super(e),this.hasChild("text")||this.addProperty("text","")}static create(e,t,i){return new this({defaultName:"linetoolrectangle",factoryDefaultsSupplier:()=>(0,p.factoryDefaultsForCurrentTheme)(b,w),nonThemedDefaultsKeys:v,themedDefaultsKeys:y,allStateKeys:C,themedColors:f,templateKeys:S,replaceThemedColorsOnThemeChange:!0,state:t,theme:e,useUserPreferences:i})}}var A;!function(e){e[e.LeftTopAnchor=0]="LeftTopAnchor",e[e.TopMiddleAnchor=6]="TopMiddleAnchor",e[e.RightTopAnchor=3]="RightTopAnchor",e[e.RightMiddleAnchor=5]="RightMiddleAnchor",e[e.RightBottomAnchor=1]="RightBottomAnchor",e[e.BottomMiddleAnchor=7]="BottomMiddleAnchor",e[e.LeftBottomAnchor=2]="LeftBottomAnchor",e[e.LeftMiddleAnchor=4]="LeftMiddleAnchor"}(A||(A={}));class D extends l.InplaceTextLineDataSource{constructor(e,t,n,s){super(e,t??D.createProperties(e.backgroundTheme().spawnOwnership()),n,s),Promise.all([i.e(6290),i.e(986),i.e(6668),i.e(1583)]).then(i.bind(i,63556)).then((({RectanglePaneView:t})=>{const i=[new t(this,e,this._openTextEditor.bind(this),this._closeTextEditor.bind(this))];this._setPaneViews(i)}))}pointsCount(){return 2}name(){return"Rectangle"}setPoint(e,t,i){if(e<2)return void super.setPoint(e,t,i);if(this._snapTo45DegreesApplicable(i)){const i=this._getSnapTo45DegreesAnchorPoint(e);if(e>=4)return this._correctMiddlePoints(e,t,i),void this._normalizePoints();this.snapPoint45Degree(t,i)}const n=this._model.mainSeries().interval();switch(e){case 2:this._points[1].price=t.price,this._points[0].index=t.index,this._points[0].interval=n;break;case 3:this._points[0].price=t.price,this._points[1].index=t.index,this._points[1].interval=n;break;case 4:this._points[0].index=t.index,this._points[0].interval=n;break;case 5:this._points[1].index=t.index,this._points[1].interval=n;break;case 6:this._points[0].price=t.price;break;case 7:this._points[1].price=t.price}this._normalizePoints()}getPoint(e){return e<2?super.getPoint(e):this._getAnchorPointForIndex(e)}template(){return this._properties.template()}snapTo45DegreesAvailable(){return!0}snapPoint45Degree(e,t,i){const s=this._priceScale,o=this.ownerSource();if(null===s||null===o)return;const r=o.firstValue();if(null===r)return;const a=this._model.timeScale(),l=(0,n.ensureNotNull)(this.pointToScreenPoint(e)),c=(0,n.ensureNotNull)(this.pointToScreenPoint(t)),d=l.x-c.x,h=l.y-c.y,u=d<0?-1:1,p=h<0?-1:1,_=Math.max(Math.abs(d),Math.abs(h)),x=Math.round(a.coordinateToIndex(c.x+_*u)),T=Math.abs(a.indexToCoordinate(x)-c.x),g=s.coordinateToPrice(c.y+T*p,r);e.index=x,e.price=g}editableTextProperties(){const e=this.properties().childs();return{text:e.text,textColor:e.textColor}}static createProperties(e,t,i){const n=V.create(e,t,i)
;return this._configureProperties(n),n}_getPropertyDefinitionsViewModelClass(){return Promise.all([i.e(3198),i.e(5410),i.e(2745),i.e(8823),i.e(8537)]).then(i.bind(i,9833)).then((e=>e.RectangleDefinitionsViewModel))}_applyTemplateImpl(e){super._applyTemplateImpl(e),this.properties().childs().text.setValue(e.text)}_createDataSourceBackgroundColorWV(){const{fillBackground:e,backgroundColor:t}=this.properties().childs();return(0,o.combine)(((e,t)=>e?t:null),(0,r.convertPropertyToWatchedValue)(e).ownership(),(0,r.convertPropertyToWatchedValue)(t).ownership()).ownership()}_correctMiddlePoints(e,t,i){e<6?this._correctRightLeftMiddlePoint(e,t,i):this._correctTopBottomMiddlePoint(e,t,i)}_correctRightLeftMiddlePoint(e,t,i){const o=(0,n.ensureNotNull)(this.pointToScreenPoint(t)),r=(0,n.ensureNotNull)(this.pointToScreenPoint(i)),a=(0,n.ensureNotNull)(this.pointToScreenPoint(this._points[0])),l=(0,n.ensureNotNull)(this.pointToScreenPoint(this._points[1]));let c=o.x-r.x;if(0===c)return;const d=a.x<l.x?1:-1,h=a.y<l.y?1:-1;switch(c*=d,e){case 4:{const e=l.y-h*c/2,t=(0,n.ensureNotNull)(this.screenPointToPoint(new s.Point(l.x,e)));this._points[1].price=t.price;const i=(0,n.ensureNotNull)(this.screenPointToPoint(new s.Point(a.x+d*c,a.y+h*c/2)));this._points[0].price=i.price,this._points[0].index=i.index;break}case 5:{const e=a.y-h*c/2,t=(0,n.ensureNotNull)(this.screenPointToPoint(new s.Point(a.x,e)));this._points[0].price=t.price;const i=(0,n.ensureNotNull)(this.screenPointToPoint(new s.Point(l.x+d*c,l.y+h*c/2)));this._points[1].price=i.price,this._points[1].index=i.index;break}}}_correctTopBottomMiddlePoint(e,t,i){const o=this._priceScale,r=this.ownerSource();if(null===o||null===r)return;const a=this._model.timeScale(),l=r.firstValue();if(null===l)return;const c=(0,n.ensureNotNull)(this.pointToScreenPoint(t)),d=(0,n.ensureNotNull)(this.pointToScreenPoint(i)),h=(0,n.ensureNotNull)(this.pointToScreenPoint(this._points[0])),u=(0,n.ensureNotNull)(this.pointToScreenPoint(this._points[1])),p=c.y-d.y,_=p<0?-1:1,x=h.x<u.x?1:-1,T=h.y<u.y?1:-1;switch(e){case 6:{const e=Math.floor(u.x-x*p/2),t=(0,n.ensureNotNull)(this.screenPointToPoint(new s.Point(e,u.y))),i=Math.abs(this._points[1].index-t.index),r=x*T*_*Math.ceil(i/2);if(0===r)return;this._points[1].index=this._points[1].index-r;const c=_*Math.abs(a.indexToCoordinate(this._points[1].index)-u.x);this._points[0].price=o.coordinateToPrice(h.y+c,l),this._points[0].index=this._points[0].index+r;break}case 7:{const e=Math.floor(h.x-x*p/2),t=(0,n.ensureNotNull)(this.screenPointToPoint(new s.Point(e,h.y))),i=Math.abs(this._points[0].index-t.index),r=x*T*_*Math.ceil(i/2);if(0===r)return;this._points[0].index=this._points[0].index-r;const c=_*Math.abs(a.indexToCoordinate(this._points[0].index)-h.x);this._points[1].price=o.coordinateToPrice(u.y+c,l),this._points[1].index=this._points[1].index+r;break}}}static _configureProperties(e){super._configureProperties(e),e.hasChild("text")||e.addChild("text",new a.Property("")),e.addChild("linesColors",new c.LineToolColorsProperty([e.childs().color])),
e.addChild("textsColors",new c.LineToolColorsProperty([e.childs().textColor])),e.addExcludedKey("text",1),e.addExcludedKey("linesColors",1),e.addExcludedKey("textsColors",1)}_getAnchorPointForIndex(e){const t=this.points(),i=t[0],n=t[1];let s=0,o=0;switch(e){case 0:s=i.price,o=i.index;break;case 1:s=n.price,o=n.index;break;case 2:s=n.price,o=i.index;break;case 3:s=i.price,o=n.index;break;case 4:s=(n.price+i.price)/2,o=i.index;break;case 5:s=(n.price+i.price)/2,o=n.index;break;case 6:s=i.price,o=(n.index+i.index)/2;break;case 7:s=n.price,o=(n.index+i.index)/2}return{index:o,price:s}}_getSnapTo45DegreesAnchorPoint(e){if(e>=4)return this._getAnchorPointForIndex(e);const t=this.points(),i=t[0],n=t[1];let s=0,o=0;switch(e){case 0:s=n.price,o=n.index;break;case 1:s=i.price,o=i.index;break;case 2:s=i.price,o=n.index;break;case 3:s=n.price,o=i.index}return{index:o,price:s}}}},70031:(e,t,i)=>{i.d(t,{factoryDefaultsForCurrentTheme:()=>l});var n=i(16738),s=i(90054),o=i(50151),r=i(45345),a=i(24633);function l(e,t){const i=r.watchedTheme.value()??a.StdTheme.Light,l=(0,s.default)(e);return(0,n.default)(l,(0,o.ensureDefined)(t.get(i))),l}}}]);