@mlightcad/common
Version:
The common package provides shared utilities and base classes that are used across the RealDWG-Web ecosystem. This package contains fundamental components for color management, event handling, logging, performance monitoring, and file loading operations.
119 lines • 4.94 kB
TypeScript
import { AcCmLoader } from './AcCmLoader';
/**
* This function will be called when loading starts. The arguments are:
* - url: The url of the item just loaded.
* - itemsLoaded: the number of items already loaded so far.
* - itemsTotal: the total amount of items to be loaded.
*/
export type AcCmOnStartCallback = (url: string, itemsLoaded: number, itemsTotal: number) => void;
/**
* This function will be called when all loading is completed.
*/
export type AcCmOnLoadCallback = () => void;
/**
* This function will be called when an item is complete. The arguments are:
* - url: The url of the item just loaded.
* - itemsLoaded: the number of items already loaded so far.
* - itemsTotal: the total amount of items to be loaded.
*/
export type AcCmOnProgressCallback = (url: string, itemsLoaded: number, itemsTotal: number) => void;
/**
* This function will be called when any item errors, with the argument:
* - url: The url of the item that errored.
*/
export type AcCmOnErrorCallback = (url: string) => void;
/**
* The callback called before a request is sent. It may return the original URL, or a new URL to override
* loading behavior.
*/
export type AcCmUrlModifier = (url: string) => string;
/**
* Handles and keeps track of loaded and pending data. A default global instance of this class is
* created and used by loaders if not supplied manually. In general that should be sufficient,
* however there are times when it can be useful to have separate loaders - for example if you want
* to show separate loading bars for objects and textures.
*/
export declare class AcCmLoadingManager {
/**
* This function will be called when loading starts.
*/
onStart?: AcCmOnStartCallback;
/**
* This function will be called when all loading is completed. By default this is undefined, unless
* passed in the constructor.
*/
onLoad?: AcCmOnLoadCallback;
/**
* This function will be called when an item is complete.
*/
onProgress?: AcCmOnProgressCallback;
/**
* This function will be called when any item errors.
*/
onError?: AcCmOnErrorCallback;
private isLoading;
private itemsLoaded;
private itemsTotal;
private handlers;
private urlModifier?;
/**
* Create a new AcCmLoadingManager instance
* @param onLoad this function will be called when all loaders are done.
* @param onProgress this function will be called when an item is complete.
* @param onError this function will be called a loader encounters errors.
*/
constructor(onLoad?: AcCmOnLoadCallback, onProgress?: AcCmOnProgressCallback, onError?: AcCmOnErrorCallback);
/**
* This should be called by any loader using the manager when the loader starts loading an url.
* @param url The loaded url
*/
itemStart(url: string): void;
/**
* This should be called by any loader using the manager when the loader ended loading an url.
* @param url The loaded url
*/
itemEnd(url: string): void;
/**
* This should be called by any loader using the manager when the loader errors loading an url.
* @param url The loaded url
*/
itemError(url: string): void;
/**
* Given a URL, uses the URL modifier callback (if any) and returns a resolved URL. If no URL
* modifier is set, returns the original URL.
* @param url The url to load
* @returns Return resolved URL
*/
resolveURL(url: string): string;
/**
* If provided, the callback will be passed each resource URL before a request is sent. The callback
* may return the original URL, or a new URL to override loading behavior. This behavior can be used
* to load assets from .ZIP files, drag-and-drop APIs, and Data URIs.
* @param transform URL modifier callback. Called with url argument, and must return resolvedURL.
* @returns Return this object
*/
setURLModifier(transform: AcCmUrlModifier): this;
/**
* Register a loader with the given regular expression. Can be used to define what loader should
* be used in order to load specific files. A typical use case is to overwrite the default loader
* for textures.
* @param regex A regular expression.
* @param loader The loader.
* @returns Return this object
*/
addHandler(regex: RegExp, loader: AcCmLoader): this;
/**
* Remove the loader for the given regular expression.
* @param regex A regular expression.
* @returns Return this object
*/
removeHandler(regex: RegExp): this;
/**
* Retrieve the registered loader for the given file path.
* @param file The file path.
* @returns Return the registered loader for the given file path.
*/
getHandler(file: string): RegExp | AcCmLoader | null;
}
export declare const DefaultLoadingManager: AcCmLoadingManager;
//# sourceMappingURL=AcCmLoadingManager.d.ts.map