UNPKG

2.81 kBTypeScriptView Raw
1import { RenderingContext2D, Fetch } from './types';
2import { ViewPort } from './ViewPort';
3import { Mouse } from './Mouse';
4import { Document, Element, AnimateElement } from './Document';
5export interface IScreenOptions {
6 /**
7 * Window object.
8 */
9 window?: Window | null;
10 /**
11 * WHATWG-compatible `fetch` function.
12 */
13 fetch?: Fetch;
14}
15export interface IScreenStartOptions {
16 /**
17 * Whether enable the redraw.
18 */
19 enableRedraw?: boolean;
20 /**
21 * Ignore mouse events.
22 */
23 ignoreMouse?: boolean;
24 /**
25 * Ignore animations.
26 */
27 ignoreAnimation?: boolean;
28 /**
29 * Does not try to resize canvas.
30 */
31 ignoreDimensions?: boolean;
32 /**
33 * Does not clear canvas.
34 */
35 ignoreClear?: boolean;
36 /**
37 * Scales horizontally to width.
38 */
39 scaleWidth?: number;
40 /**
41 * Scales vertically to height.
42 */
43 scaleHeight?: number;
44 /**
45 * Draws at a x offset.
46 */
47 offsetX?: number;
48 /**
49 * Draws at a y offset.
50 */
51 offsetY?: number;
52 /**
53 * Will call the function on every frame, if it returns true, will redraw.
54 */
55 forceRedraw?(): boolean;
56}
57export interface IScreenViewBoxConfig {
58 document: Document;
59 ctx: RenderingContext2D;
60 aspectRatio: string;
61 width: number;
62 desiredWidth: number;
63 height: number;
64 desiredHeight: number;
65 minX?: number;
66 minY?: number;
67 refX?: number;
68 refY?: number;
69 clip?: boolean;
70 clipX?: number;
71 clipY?: number;
72}
73export declare class Screen {
74 readonly ctx: RenderingContext2D;
75 static readonly defaultWindow: Window & typeof globalThis;
76 static readonly defaultFetch: typeof fetch;
77 static FRAMERATE: number;
78 static MAX_VIRTUAL_PIXELS: number;
79 readonly window: Window | null;
80 readonly fetch: Fetch;
81 readonly viewPort: ViewPort;
82 readonly mouse: Mouse;
83 readonly animations: AnimateElement[];
84 private readyPromise;
85 private resolveReady;
86 private waits;
87 private frameDuration;
88 private isReadyLock;
89 private isFirstRender;
90 private intervalId;
91 constructor(ctx: RenderingContext2D, { fetch, window }?: IScreenOptions);
92 wait(checker: () => boolean): void;
93 ready(): Promise<void>;
94 isReady(): boolean;
95 setDefaults(ctx: RenderingContext2D): void;
96 setViewBox({ document, ctx, aspectRatio, width, desiredWidth, height, desiredHeight, minX, minY, refX, refY, clip, clipX, clipY }: IScreenViewBoxConfig): void;
97 start(element: Element, { enableRedraw, ignoreMouse, ignoreAnimation, ignoreDimensions, ignoreClear, forceRedraw, scaleWidth, scaleHeight, offsetX, offsetY }?: IScreenStartOptions): void;
98 stop(): void;
99 private shouldUpdate;
100 private render;
101}
102//# sourceMappingURL=Screen.d.ts.map
\No newline at end of file