@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 1.41 kB
JavaScript
import*as Platform from"../../../core/platform/platform.js";import*as Types from"../types/types.js";const animations=[],animationsSyntheticEvents=[];let handlerState=1;export function reset(){animations.length=0,animationsSyntheticEvents.length=0}export function handleEvent(n){Types.TraceEvents.isTraceEventAnimation(n)&&animations.push(n)}export async function finalize(){createSortedAnimationsSyntheticEvents(matchBeginningAndEndEvents()),handlerState=3}function matchBeginningAndEndEvents(){const n=new Map;for(const t of animations){const e=t.id2;if(void 0===e)continue;const i=`${t.cat}:${e.local}:${t.name}`,a=Platform.MapUtilities.getWithDefault(n,i,(()=>({begin:null,end:null}))),o="b"===t.ph,s="e"===t.ph;o?a.begin={...t,ph:"b",id2:{local:t.id2?.local},id:t.args?.id}:s&&(a.end={...t,ph:"e",id2:{local:t.id2?.local},id:t.args?.id})}return n}function createSortedAnimationsSyntheticEvents(n){for(const[t,e]of n.entries()){if(!e.begin||!e.end)continue;const n={cat:e.end.cat,ph:e.end.ph,pid:e.end.pid,tid:e.end.tid,id:t,name:e.begin.name,dur:Types.Timing.MicroSeconds(e.end.ts-e.begin.ts),ts:e.begin.ts,args:{data:{beginEvent:e.begin,endEvent:e.end}}};n.dur<0||animationsSyntheticEvents.push(n)}animationsSyntheticEvents.sort(((n,t)=>n.ts-t.ts))}export function data(){if(3!==handlerState)throw new Error("Animation handler is not finalized");return{animations:Array.from(animationsSyntheticEvents)}}