1 | import { Loader } from "./Loader.js";
|
2 |
|
3 | export const DefaultLoadingManager: LoadingManager;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export class LoadingManager {
|
9 | constructor(
|
10 | onLoad?: () => void,
|
11 | onProgress?: (url: string, loaded: number, total: number) => void,
|
12 | onError?: (url: string) => void,
|
13 | );
|
14 |
|
15 | /**
|
16 | * Will be called when loading of an item starts.
|
17 | * @param url The url of the item that started loading.
|
18 | * @param loaded The number of items already loaded so far.
|
19 | * @param total The total amount of items to be loaded.
|
20 | */
|
21 | onStart?: ((url: string, loaded: number, total: number) => void) | undefined;
|
22 |
|
23 | /**
|
24 | * Will be called when all items finish loading.
|
25 | * The default is a function with empty body.
|
26 | */
|
27 | onLoad: () => void;
|
28 |
|
29 | /**
|
30 | * Will be called for each loaded item.
|
31 | * The default is a function with empty body.
|
32 | * @param url The url of the item just loaded.
|
33 | * @param loaded The number of items already loaded so far.
|
34 | * @param total The total amount of items to be loaded.
|
35 | */
|
36 | onProgress: (url: string, loaded: number, total: number) => void;
|
37 |
|
38 | /**
|
39 | * Will be called when item loading fails.
|
40 | * The default is a function with empty body.
|
41 | * @param url The url of the item that errored.
|
42 | */
|
43 | onError: (url: string) => void;
|
44 |
|
45 | /**
|
46 | * If provided, the callback will be passed each resource URL before a request is sent.
|
47 | * The callback may return the original URL, or a new URL to override loading behavior.
|
48 | * This behavior can be used to load assets from .ZIP files, drag-and-drop APIs, and Data URIs.
|
49 | * @param callback URL modifier callback. Called with url argument, and must return resolvedURL.
|
50 | */
|
51 | setURLModifier(callback?: (url: string) => string): this;
|
52 |
|
53 | /**
|
54 | * Given a URL, uses the URL modifier callback (if any) and returns a resolved URL.
|
55 | * If no URL modifier is set, returns the original URL.
|
56 | * @param url the url to load
|
57 | */
|
58 | resolveURL(url: string): string;
|
59 |
|
60 | itemStart(url: string): void;
|
61 | itemEnd(url: string): void;
|
62 | itemError(url: string): void;
|
63 |
|
64 | // handlers
|
65 |
|
66 | addHandler(regex: RegExp, loader: Loader): this;
|
67 | removeHandler(regex: RegExp): this;
|
68 | getHandler(file: string): Loader | null;
|
69 | }
|