text: import*as Common from"../common/common.js";import*as PerfUI from"../perf_ui/perf_ui.js";import*as SDK from"../sdk/sdk.js";export class NetworkTimeBoundary{constructor(r,t){this.minimum=r,this.maximum=t}equals(r){return this.minimum===r.minimum&&this.maximum===r.maximum}}export class NetworkTimeCalculator extends Common.ObjectWrapper.ObjectWrapper{constructor(r){super(),this.startAtZero=r,this._minimumBoundary=-1,this._maximumBoundary=-1,this._boundryChangedEventThrottler=new Common.Throttler.Throttler(0),this._window=null}setWindow(r){this._window=r,this._boundaryChanged()}setInitialUserFriendlyBoundaries(){this._minimumBoundary=0,this._maximumBoundary=1}computePosition(r){return(r-this.minimumBoundary())/this.boundarySpan()*this._workingArea}formatValue(r,t){return Number.secondsToString(r,!!t)}minimumBoundary(){return this._window?this._window.minimum:this._minimumBoundary}zeroTime(){return this._minimumBoundary}maximumBoundary(){return this._window?this._window.maximum:this._maximumBoundary}boundary(){return new NetworkTimeBoundary(this.minimumBoundary(),this.maximumBoundary())}boundarySpan(){return this.maximumBoundary()-this.minimumBoundary()}reset(){this._minimumBoundary=-1,this._maximumBoundary=-1,this._boundaryChanged()}_value(r){return 0}setDisplayWidth(r){this._workingArea=r}computeBarGraphPercentages(r){let t,e,n;return t=-1!==r.startTime?(r.startTime-this.minimumBoundary())/this.boundarySpan()*100:0,e=-1!==r.responseReceivedTime?(r.responseReceivedTime-this.minimumBoundary())/this.boundarySpan()*100:this.startAtZero?t:100,n=-1!==r.endTime?(r.endTime-this.minimumBoundary())/this.boundarySpan()*100:this.startAtZero?e:100,this.startAtZero&&(n-=t,e-=t,t=0),{start:t,middle:e,end:n}}computePercentageFromEventTime(r){return-1===r||this.startAtZero?0:(r-this.minimumBoundary())/this.boundarySpan()*100}percentageToTime(r){return r*this.boundarySpan()/100+this.minimumBoundary()}_boundaryChanged(){this._boundryChangedEventThrottler.schedule(function(){return this.dispatchEventToListeners(Events.BoundariesChanged),Promise.resolve()}.bind(this))}updateBoundariesForEventTime(r){-1===r||this.startAtZero||(void 0===this._maximumBoundary||r>this._maximumBoundary)&&(this._maximumBoundary=r,this._boundaryChanged())}computeBarGraphLabels(r){let t="";-1!==r.responseReceivedTime&&-1!==r.endTime&&(t=Number.secondsToString(r.endTime-r.responseReceivedTime));const e=r.latency>0,n=e?Number.secondsToString(r.latency):t;if(r.timing)return{left:n,right:t};let o;if(e&&t){const e=Number.secondsToString(r.duration);o=_latencyDownloadTotalFormat.format(n,t,e)}else e?o=_latencyFormat.format(n):t&&(o=_downloadFormat.format(t));return r.fetchedViaServiceWorker?o=_fromServiceWorkerFormat.format(o):r.cached()&&(o=_fromCacheFormat.format(o)),{left:n,right:t,tooltip:o}}updateBoundaries(r){const t=this._lowerBound(r),e=this._upperBound(r);let n=!1;(-1!==t||this.startAtZero)&&(n=this._extendBoundariesToIncludeTimestamp(this.startAtZero?0:t)),-1!==e&&(n=this._extendBoundariesToIncludeTimestamp(e)||n),n&&this._boundaryChanged()}_extendBoundariesToIncludeTimestamp(r){const t=this._minimumBoundary,e=this._maximumBoundary,n=_minimumSpread;return-1===this._minimumBoundary||-1===this._maximumBoundary?(this._minimumBoundary=r,this._maximumBoundary=r+n):(this._minimumBoundary=Math.min(r,this._minimumBoundary),this._maximumBoundary=Math.max(r,this._minimumBoundary+n,this._maximumBoundary)),t!==this._minimumBoundary||e!==this._maximumBoundary}_lowerBound(r){return 0}_upperBound(r){return 0}}export const _minimumSpread=.1;export const Events={BoundariesChanged:Symbol("BoundariesChanged")};export const _latencyDownloadTotalFormat=new Common.UIString.UIStringFormat("%s latency, %s download (%s total)");export const _latencyFormat=new Common.UIString.UIStringFormat("%s latency");export const _downloadFormat=new Common.UIString.UIStringFormat("%s download");export const _fromServiceWorkerFormat=new Common.UIString.UIStringFormat("%s (from ServiceWorker)");export const _fromCacheFormat=new Common.UIString.UIStringFormat("%s (from cache)");export class NetworkTransferTimeCalculator extends NetworkTimeCalculator{constructor(){super(!1)}formatValue(r,t){return Number.secondsToString(r-this.zeroTime(),!!t)}_lowerBound(r){return r.issueTime()}_upperBound(r){return r.endTime}}export class NetworkTransferDurationCalculator extends NetworkTimeCalculator{constructor(){super(!0)}formatValue(r,t){return Number.secondsToString(r,!!t)}_upperBound(r){return r.duration}}