You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a typescript rewrite to the main file if any one interested
/** * NProgress is a lightweight progress bar for JS applications. * It provides a simple way to visualize loading states with a slim progress bar at the top of the page. * * This is implemented as a singleton, so you should access it via NProgress.getInstance() or use the default export. * * @example * // Start the progress bar * NProgress.start(); * * // Set progress to 50% * NProgress.set(0.5); * * // Increment the progress bar * NProgress.inc(); * * // Complete the progress * NProgress.done(); * * // Configure options * NProgress.configure({ showSpinner: false }); */typeNProgressSettings={minimum: number;easing?: string;positionUsing?: string;speed?: number;trickle?: boolean;trickleSpeed?: number;showSpinner?: boolean;barSelector: string;spinnerSelector?: string;parent: string;template: string;};exportclassNProgress{privatestaticinstance: NProgress;privatestatus: number|null=null;// Default settingsprivatesettings: NProgressSettings={minimum: 0.08,easing: "linear",positionUsing: "",speed: 200,trickle: true,trickleSpeed: 200,showSpinner: true,barSelector: '[role="bar"]',spinnerSelector: '[role="spinner"]',parent: "body",template:
'<div class="bar" role="bar"><div class="peg"></div></div>'+'<div class="spinner" role="spinner"><div class="spinner-icon"></div></div>',};privateconstructor(){}publicstaticgetInstance(){if(!NProgress.instance){NProgress.instance=newNProgress();}returnNProgress.instance;}publicconfigure(options: Partial<NProgressSettings>){Object.assign(this.settings,options);returnthis;}publicstart(): NProgress{if(!this.status)this.set(0);constwork=()=>{setTimeout(()=>{if(!this.status)return;this.trickle();work();},this.settings.trickleSpeed);};if(this.settings.trickle)work();returnthis;}publicset(n: number): NProgress{conststarted=this.isStarted();n=this.clamp(n,this.settings.minimum||0.08,1);this.status=n===1 ? null : n;constprogress=this.render(!started);constbar=progress.querySelector<HTMLElement>(this.settings.barSelector);constspeed=this.settings.speed||200;constease=this.settings.easing||"linear";if(bar){this.applyCss(bar,this.barPositionCSS(n,speed,ease));}if(n===1){setTimeout(()=>{this.remove();},speed);}returnthis;}publicdone(force=false): NProgress{if(!force&&!this.status)returnthis;returnthis.inc(0.3+0.5*Math.random()).set(1);}publicinc(amount?: number): NProgress{letn=this.status??0;if(n>=1)returnthis;amount=amount??(n<0.2 ? 0.1 : n<0.5 ? 0.04 : n<0.8 ? 0.02 : 0.005);returnthis.set(this.clamp(n+amount,0,0.994));}publictrickle(): NProgress{returnthis.inc();}privateisStarted(): boolean{returntypeofthis.status==="number";}privaterender(fromStart=false): HTMLElement{if(this.isRendered())returndocument.getElementById("nprogress")!;constprogress=document.createElement("div");progress.id="nprogress";progress.innerHTML=this.settings.template;document.querySelector(this.settings.parent)!.appendChild(progress);returnprogress;}privateremove(): void{constprogress=document.getElementById("nprogress");progress?.parentNode?.removeChild(progress);}privateisRendered(): boolean{return!!document.getElementById("nprogress");}privateclamp(n: number,min: number,max: number): number{returnMath.min(Math.max(n,min),max);}privatebarPositionCSS(n: number,speed: number,ease: string): Record<string,string>{return{transform: `translate3d(${(-1+n)*100}%,0,0)`,transition: `all ${speed}ms ${ease}`,};}privateapplyCss(element: HTMLElement,styles: Record<string,string>): void{Object.assign(element.style,styles);}}exportdefaultNProgress.getInstance();
The text was updated successfully, but these errors were encountered:
Hello,
I wrote a typescript rewrite to the main file if any one interested
The text was updated successfully, but these errors were encountered: