File tree Expand file tree Collapse file tree 5 files changed +22
-7
lines changed
Expand file tree Collapse file tree 5 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ export type TGraphConstants = {
129129export const initGraphConstants : TGraphConstants = {
130130 system : {
131131 GRID_SIZE : 16 ,
132- PIXEL_RATIO : window . devicePixelRatio || 1 ,
132+ PIXEL_RATIO : typeof window !== "undefined" ? window . devicePixelRatio || 1 : 1 ,
133133 USABLE_RECT_GAP : 400 ,
134134 CAMERA_VIEWPORT_TRESHOLD : 0.5 ,
135135 } ,
Original file line number Diff line number Diff line change @@ -30,7 +30,11 @@ class FpsManager {
3030
3131 this . averageFPS = Math . floor ( sum / 10 ) ;
3232
33- window . requestAnimationFrame ( refreshLoop ) ;
33+ if ( typeof window === "undefined" ) {
34+ global . setTimeout ( refreshLoop , 16 ) ;
35+ } else {
36+ window . requestAnimationFrame ( refreshLoop ) ;
37+ }
3438 } ;
3539
3640 refreshLoop ( ) ;
Original file line number Diff line number Diff line change 22
33import { scheduler } from "../../lib/Scheduler" ;
44
5- const getNowTime = window . performance . now . bind ( performance ) ;
5+ const getNowTime = ( ) => performance . now ( ) ;
66
77type Options = {
88 delay ?: number ;
Original file line number Diff line number Diff line change 11import { noop } from "./functions" ;
22
33const TIME_PER_FRAME_FOR_GC = 5 ; // 5 mc
4- const rIC = window . requestIdleCallback || window . setTimeout ;
4+ const globalObject = typeof window === "undefined" ? global : window ;
5+ const rIC = globalObject . requestIdleCallback || globalObject . setTimeout ;
56
6- const getTime = ( ) => window . performance . now ( ) ;
7+ const getTime = ( ) => performance . now ( ) ;
78type EmitterEventsDefinition = Record < string , ( ...args : unknown [ ] ) => void > ;
89export class Emitter < T extends EmitterEventsDefinition = EmitterEventsDefinition > {
910 private destroyed : boolean ;
Original file line number Diff line number Diff line change 11/* eslint-disable no-unmodified-loop-condition */
2+ import memoize from "lodash/memoize" ;
3+
24export function getFontSize ( fontSize , scale ) {
35 return ( fontSize / scale ) | 0 ;
46}
57
6- const canvas : HTMLCanvasElement = document . createElement ( "canvas" ) ;
7- const context : CanvasRenderingContext2D = canvas . getContext ( "2d" ) ;
8+ function canvasContextGetter ( ) {
9+ const canvas : HTMLCanvasElement = document . createElement ( "canvas" ) ;
10+
11+ return canvas . getContext ( "2d" ) ;
12+ }
13+
14+ const getCanvasContext = memoize ( canvasContextGetter , ( ) => "canvasContext" ) ;
15+
816const mapTextToMeasures : Map < string , number > = new Map ( ) ;
917
1018export function measureText ( text , font , approximate = true ) : number {
19+ const context = getCanvasContext ( ) ;
20+
1121 context . font = font ;
1222
1323 if ( ! approximate ) {
You can’t perform that action at this time.
0 commit comments