UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 7.5 kB
import*as Common from"../../core/common/common.js";import*as Host from"../../core/host/host.js";import*as PerfUI from"../../ui/legacy/components/perf_ui/perf_ui.js";import*as UI from"../../ui/legacy/legacy.js";import*as ThemeSupport from"../../ui/legacy/theme_support/theme_support.js";import{Bounds,formatMillisecondsToSeconds}from"./TickingFlameChartHelpers.js";const defaultFont="11px "+Host.Platform.fontFamily();function getGroupDefaultTextColor(){return ThemeSupport.ThemeSupport.instance().getComputedValue("--color-text-primary")}const DefaultStyle=()=>({height:20,padding:2,collapsible:!1,font:defaultFont,color:getGroupDefaultTextColor(),backgroundColor:"rgba(100 0 0 / 10%)",nestingLevel:0,itemsHeight:20,shareHeaderLine:!1,useFirstLineForOverview:!1,useDecoratorsForOverview:!1});export const HotColorScheme=["#ffba08","#faa307","#f48c06","#e85d04","#dc2f02","#d00000","#9d0208"];export const ColdColorScheme=["#7400b8","#6930c3","#5e60ce","#5390d9","#4ea8de","#48bfe3","#56cfe1","#64dfdf"];function calculateFontColor(t){const e=Common.Color.parse(t)?.as("hsl");return e&&e.l<.5?"#eee":"#444"}export class Event{timelineData;setLive;setComplete;updateMaxTime;selfIndex;liveInternal;title;colorInternal;fontColorInternal;hoverData;constructor(t,e,i={color:void 0,duration:void 0,hoverData:{},level:0,name:"",startTime:0}){this.timelineData=t,this.setLive=e.setLive,this.setComplete=e.setComplete,this.updateMaxTime=e.updateMaxTime,this.selfIndex=this.timelineData.entryLevels.length,this.liveInternal=!1;const n=void 0===i.duration?0:i.duration;this.timelineData.entryLevels.push(i.level||0),this.timelineData.entryStartTimes.push(i.startTime||0),this.timelineData.entryTotalTimes.push(n),-1===n&&(this.endTime=-1),this.title=i.name||"",this.colorInternal=i.color||HotColorScheme[0],this.fontColorInternal=calculateFontColor(this.colorInternal),this.hoverData=i.hoverData||{}}decorate(t){t.createChild("span").textContent=`Name: ${this.title}`,t.createChild("br");const e=formatMillisecondsToSeconds(this.startTime,2);if(this.liveInternal)t.createChild("span").textContent=`Duration: ${e} - LIVE!`;else if(isNaN(this.duration))t.createChild("span").textContent=`Time: ${e}`;else{const i=formatMillisecondsToSeconds(this.duration+this.startTime,2);t.createChild("span").textContent=`Duration: ${e} - ${i}`}}set endTime(t){if(-1===t)this.timelineData.entryTotalTimes[this.selfIndex]=this.setLive(this.selfIndex),this.liveInternal=!0;else{this.liveInternal=!1;const e=t-this.timelineData.entryStartTimes[this.selfIndex];this.timelineData.entryTotalTimes[this.selfIndex]=e,this.setComplete(this.selfIndex),this.updateMaxTime(t)}}get id(){return this.selfIndex}set level(t){this.timelineData.entryLevels[this.selfIndex]=t}set color(t){this.colorInternal=t,this.fontColorInternal=calculateFontColor(this.colorInternal)}get color(){return this.colorInternal}get fontColor(){return this.fontColorInternal}get startTime(){return this.timelineData.entryStartTimes[this.selfIndex]}get duration(){return this.timelineData.entryTotalTimes[this.selfIndex]}get live(){return this.liveInternal}}export class TickingFlameChart extends UI.Widget.VBox{intervalTimer;lastTimestamp;canTickInternal;ticking;isShown;bounds;dataProvider;delegate;chartGroupExpansionSetting;chart;stoppedPermanently;constructor(){super(),this.intervalTimer=0,this.lastTimestamp=0,this.canTickInternal=!0,this.ticking=!1,this.isShown=!1,this.bounds=new Bounds(0,1e3,3e4,1e3),this.dataProvider=new TickingFlameChartDataProvider(this.bounds,this.updateMaxTime.bind(this)),this.delegate=new TickingFlameChartDelegate,this.chartGroupExpansionSetting=Common.Settings.Settings.instance().createSetting("mediaFlameChartGroupExpansion",{}),this.chart=new PerfUI.FlameChart.FlameChart(this.dataProvider,this.delegate,this.chartGroupExpansionSetting),this.chart.disableRangeSelection(),this.chart.bindCanvasEvent("wheel",(t=>{this.onScroll(t)})),this.chart.show(this.contentElement)}addMarker(t){t.duration=NaN,this.startEvent(t)}startEvent(t){void 0===t.duration&&(t.duration=-1);const e=t.startTime||0,i=this.dataProvider.startEvent(t);return this.updateMaxTime(e),i}addGroup(t,e){this.dataProvider.addGroup(t,e)}updateMaxTime(t){this.bounds.pushMaxAtLeastTo(t)&&this.updateRender()}onScroll(t){const e=Math.round(t.deltaY/50),i=t.offsetX/t.srcElement.clientWidth;e>0?this.bounds.zoomOut(e,i):this.bounds.zoomIn(-e,i),this.updateRender()}willHide(){this.isShown=!1,this.ticking&&this.stop()}wasShown(){this.isShown=!0,this.canTickInternal&&!this.ticking&&this.start()}set canTick(t){this.canTickInternal=t,this.ticking&&!t&&this.stop(),!this.ticking&&this.isShown&&t&&this.start()}start(){0===this.lastTimestamp&&(this.lastTimestamp=Date.now()),0!==this.intervalTimer||this.stoppedPermanently||(this.intervalTimer=window.setInterval(this.updateRender.bind(this),16),this.ticking=!0)}stop(t=!1){window.clearInterval(this.intervalTimer),this.intervalTimer=0,t&&(this.stoppedPermanently=!0),this.ticking=!1}updateRender(){if(this.ticking){const t=Date.now(),e=t-this.lastTimestamp;this.lastTimestamp=t,this.bounds.addMax(e)}this.dataProvider.updateMaxTime(this.bounds),this.chart.setWindowTimes(this.bounds.low,this.bounds.high,!0),this.chart.scheduleUpdate()}}class TickingFlameChartDelegate{constructor(){}windowChanged(t,e,i){}updateRangeSelection(t,e){}updateSelectedGroup(t,e){}}class TickingFlameChartDataProvider{updateMaxTimeHandle;bounds;liveEvents;eventMap;timelineDataInternal;maxLevel;constructor(t,e){this.updateMaxTimeHandle=e,this.bounds=t,this.liveEvents=new Set,this.eventMap=new Map,this.timelineDataInternal=PerfUI.FlameChart.FlameChartTimelineData.createEmpty(),this.maxLevel=0}addGroup(t,e){if(this.timelineDataInternal.groups){const e={name:t,startLevel:this.maxLevel,expanded:!0,selectable:!1,style:{height:20,padding:2,collapsible:!1,font:defaultFont,color:getGroupDefaultTextColor(),backgroundColor:"rgba(100 0 0 / 10%)",nestingLevel:0,itemsHeight:20,shareHeaderLine:!1,useFirstLineForOverview:!1,useDecoratorsForOverview:!1},track:null};this.timelineDataInternal.groups.push(e),ThemeSupport.ThemeSupport.instance().addEventListener(ThemeSupport.ThemeChangeEvent.eventName,(()=>{e.style.color=getGroupDefaultTextColor()}))}this.maxLevel+=e}startEvent(t){if(t.level=t.level||0,t.level>this.maxLevel)throw`level ${t.level} is above the maximum allowed of ${this.maxLevel}`;const e=new Event(this.timelineDataInternal,{setLive:this.setLive.bind(this),setComplete:this.setComplete.bind(this),updateMaxTime:this.updateMaxTimeHandle},t);return this.eventMap.set(e.id,e),e}setLive(t){return this.liveEvents.add(t),this.bounds.max}setComplete(t){this.liveEvents.delete(t)}updateMaxTime(t){this.bounds=t;for(const t of this.liveEvents.entries())this.eventMap.get(t[0]).endTime=-1}maxStackDepth(){return this.maxLevel+1}timelineData(){return this.timelineDataInternal}minimumBoundary(){return this.bounds.low}totalTime(){return this.bounds.high}entryColor(t){return this.eventMap.get(t).color}textColor(t){return this.eventMap.get(t).fontColor}entryTitle(t){return this.eventMap.get(t).title}entryFont(t){return defaultFont}decorateEntry(t,e,i,n,s,a,r,o,l){return!1}forceDecoration(t){return!1}prepareHighlightedEntryInfo(t){const e=document.createElement("div");return this.eventMap.get(t).decorate(e),e}formatValue(t,e){return t+=Math.round(this.bounds.low),this.bounds.range<2800?formatMillisecondsToSeconds(t,2):this.bounds.range<3e4?formatMillisecondsToSeconds(t,1):formatMillisecondsToSeconds(t,0)}canJumpToEntry(t){return!1}}