"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[5231],{62414:(e,t,i)=>{i.r(t),i.d(t,{LineToolImage:()=>M,OriginPoints:()=>T,buildAbsoluteUserImageUrl:()=>x});var n=i(50151),r=i(10555),s=i(9343),o=i(22613),a=i(78176),l=i(43337),u=i(41414),h=i(40472),c=i(1765),d=i(51768),g=i(97995),p=i(70347),m=i(11542),_=i(49483),f=i(68335),b=i(37103);const P=m.t(null,void 0,i(15402));var v=i(60709),w=i(78861);async function C(e,t){return async function(e){const[t]=await Promise.all([Promise.all([i.e(1874),i.e(8185),i.e(5371),i.e(2202),i.e(5563),i.e(2647),i.e(2537),i.e(7833),i.e(9487),i.e(8220),i.e(6043),i.e(4765),i.e(2227),i.e(2164),i.e(9418),i.e(7038)]).then(i.bind(i,47942))]);return t.renderImageDialog(e)}({onConfirm:e,onClose:t})}let S=null;function I(e){if("LineToolImage"!==e)return S?.then((e=>e())),void(S=null);(0,p.runOrSigninWithFeature)((()=>{const e="LineToolImage";w.tool.setValue(e),(0,g.trackDrawingToolSelected)(e,"Left panel"),S=C(U,(()=>{S?.then((e=>e())),S=null,w.tool.value()===e&&(0,w.resetToCursor)(!0)})),(0,d.trackEvent)("Image","Open image dialog")}),{feature:"drawings",source:"Change drawing tool state"})}function U(e){const t=(0,v.chartWidgetCollectionService)();if(null===t)return;const r=!Boolean(c.getBool("hint.pasteImage")),s=t.activeChartWidget.value();var o,a;s.model().pasteImageAsLineTool(e.url,e.blobUrl,(0,n.ensureNotNull)(s.model().model().paneForSource(s.model().mainSeries())),e.transparency),r&&(o=t.getContainer(),a="hint.pasteImage",b.enabled("popup_hints")&&!_.CheckMobile.any()&&Promise.all([i.e(6195),i.e(628),i.e(2227),i.e(6166)]).then(i.bind(i,91759)).then((e=>{const t=new e.ChartEventHintRenderer(o),i=P.format({shortcut:(0,f.humanReadableHash)(f.Modifiers.Mod+86)});let n=null;t.show(i,(()=>{null!==n&&(clearTimeout(n),n=null,c.setValue(a,!0,{forceFlush:!0}))})),n=setTimeout((()=>{n=null,t.hide()}),5e3)})))}const y=(0,s.getLogger)("Chart.LineToolImage");var T;function L(e){return e.toLowerCase().startsWith("blob:")}function N(e){return e.toLowerCase().startsWith("data:")}!function(e){e[e.LeftTopAnchor=0]="LeftTopAnchor",e[e.RightTopAnchor=1]="RightTopAnchor",e[e.LeftBottomAnchor=2]="LeftBottomAnchor",e[e.RightBottomAnchor=3]="RightBottomAnchor",e[e.Center=4]="Center"}(T||(T={}));window.AWS_BBS3_DOMAIN;function x(e){return L(e)||N(e)?e:null}function O(e){return N(e)?e:new URL(e).pathname}class M extends u.LineDataSource{constructor(e,t,n,r){super(e,t||M.createProperties(e.backgroundTheme().spawnOwnership()),n,r),this._hasEditableCoordinates=new o.WatchedValue(!1),this._image=null,this._originPoint=4;const s=this.properties().childs().url;this._absoluteUserImageUrl=new l.Property(x(this.properties().childs().url.value())??""),this._absoluteUserImageUrl.subscribe(this,(e=>{const t=e.value();if(L(t))return;const i=x(t);null!==i&&s.setValue(O(i))})),s.subscribe(this,(()=>{const e=x(s.value());null!==e&&this._absoluteUserImageUrl.setValue(e)})),this._loadImage(),Promise.all([i.e(6290),i.e(986),i.e(6668),i.e(1583)]).then(i.bind(i,69699)).then((({ImagePaneView:t})=>{
this._setPaneViews([new t(this,e)])})),this.properties().childs().url.subscribe(this,(()=>{this._loadImage()}))}absoluteUserImageUrl(){return this._absoluteUserImageUrl}cssWidth(){return this.properties().childs().cssWidth.value()}cssHeight(){return this.properties().childs().cssHeight.value()}angle(){return this.properties().childs().angle.value()}originPoint(){return this._originPoint}dOffsetX(){return this._dOffsetX||0}pointsCount(){return 1}name(){return"Image"}image(){return this._image}setBlobImageUrl(e){this._image}getChangePointForSync(e){return null}pointToScreenPoint({index:e,price:t},i,s){const o=this._model.timeScale(),a=(0,n.ensureNotNull)(i?i.priceScale():this.priceScale()),l=(0,n.ensure)((i??this.ownerSource())?.firstValue()),u=o.indexToCoordinate(e)+(s??0),h=a.priceToCoordinate(t,l);return new r.Point(u,h)}setPoint(e,t,i){if(null===this._image)return;const{width:r,height:s}=this._image,o=(0,n.ensureNotNull)(this.pointToScreenPoint(t)),a=(0,n.ensureNotNull)(this.pointToScreenPoint(this._points[0],void 0,this.dOffsetX())),l=Math.max(Math.abs(a.x-o.x)/r,Math.abs(a.y-o.y)/s),u=Math.round(r*l),h=Math.round(s*l),c=this.properties().childs();c.cssWidth.setValue(u),c.cssHeight.setValue(h),this.propertiesChanged()}startChanging(e,t){super.startChanging(e,t),this._changeOriginPoint(M._oppositePoints[e])}endChanging(e,t){return this._changeOriginPoint(4),super.endChanging(e,t)}getPoint(){return null}syncLineStyleState(){const e=super.syncLineStyleState();return!e.url&&this._blobUrl&&(e.blobUrl=this._blobUrl),e}restoreExternalState(e){const{blobUrl:t,...i}=e;t&&this.setBlobImageUrl(t),super.restoreExternalState(i)}isSavedInChart(){return super.isSavedInChart()&&""!==this.absoluteUserImageUrl().value()}static createProperties(e,t){const i=new a.DefaultProperty({defaultName:"linetoolimage",state:t,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,11375))).ImageDefinitionsViewModel}static _configureProperties(e){super._configureProperties(e),e.hasChild("url")||e.addChild("url",new l.Property("")),e.addExcludedKey("url",1),e.addExcludedKey("cssWidth",1),e.addExcludedKey("cssHeight",1),e.addExcludedKey("angle",1)}_loadImage(){const e=this.properties(),t=(0,n.ensureDefined)(e.child("url")).value();t&&this._createImage(t)}_changeOriginPoint(e){const t=this.originPoint(),i=4===t?M._correctOriginDirections[e]:M._correctOriginDirections[M._oppositePoints[t]],s=this.properties().childs().cssWidth.value()/2,o=this.properties().childs().cssHeight.value()/2,[a]=this._points,l=(0,n.ensureNotNull)(this.pointToScreenPoint(a)),u=new r.Point(l.x+s*i[0],l.y+o*i[1]),h=(0,n.ensureNotNull)(this.screenPointToPoint(u));this._dOffsetX=4===t?u.x-(0,n.ensureNotNull)(this.pointToScreenPoint(h)).x:void 0,a.index=h.index,a.price=h.price,this._originPoint=e}_createImage(e){const t=L(e),i=x(e);if(null===i)return void y.logWarn(`Invalid image URL: ${e}`);if(i===this._image?.src)return
;const r=document.createElement("img");r.crossOrigin="anonymous",r.src=i,r.addEventListener("load",(()=>{this._image=r;const e=this._model,s=this.properties().childs();if(!t){const e=O(i);s.url.setValue(e),this._blobUrl=void 0}if(s.cssWidth.value()&&s.cssHeight.value())return void this._model.updateSource(this);const o=e.timeScale().width()/4,a=(0,n.ensureNotNull)(this.priceScale()).height()/4,l=r.naturalWidth,u=r.naturalHeight,c=Math.min(1,o/l),d=Math.min(1,a/u),g=Math.min(c,d),p=Math.round(g*l),m=Math.round(g*u);s.cssWidth.setValue(p),s.cssHeight.setValue(m),this.updateAllViews((0,h.sourceChangeEvent)(this.id())),this._model.updateSource(this)})),r.addEventListener("error",(()=>{this.model().removeSource(this)}))}}M._correctOriginDirections=[[-1,-1],[1,-1],[-1,1],[1,1],[0,0]],M._oppositePoints=[3,2,1,0,4],(0,w.runOnDrawingStateReady)((()=>{w.tool.subscribe(I)}))}}]);