@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.
88 lines • 3.38 kB
JavaScript
import { DefaultLoadingManager } from './AcCmLoadingManager';
/**
* Base class for implementing loaders.
*/
var AcCmLoader = /** @class */ (function () {
/**
* Creates a new AcCmLoader instance.
* @param manager The loadingManager for the loader to use. Default is DefaultLoadingManager.
*/
function AcCmLoader(manager) {
this.manager = manager !== undefined ? manager : DefaultLoadingManager;
this.crossOrigin = 'anonymous';
this.withCredentials = false;
this.path = '';
this.resourcePath = '';
this.requestHeader = {};
}
/**
* This method is equivalent to 'load', but returns a Promise.
* @param url A string containing the path/URL of the file to be loaded.
* @param onProgress (optional) — A function to be called while the loading is in progress.
* The argument will be the ProgressEvent instance, which contains .lengthComputable, .total
* and .loaded. If the server does not set the Content-Length header; .total will be 0.
* @returns Return a promise.
*/
AcCmLoader.prototype.loadAsync = function (url, onProgress) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.load(url, resolve, onProgress, reject);
});
};
/**
* This method needs to be implement by all concrete loaders. It holds the logic for parsing the asset.
*/
AcCmLoader.prototype.parse = function (_data) { };
/**
* Set the crossOrigin string to implement CORS for loading the url from a different domain that allows
* CORS.
* @param crossOrigin The crossOrigin string
* @returns Return this object
*/
AcCmLoader.prototype.setCrossOrigin = function (crossOrigin) {
this.crossOrigin = crossOrigin;
return this;
};
/**
* Set whether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS
* client certificates.
* Note that this has no effect if you are loading files locally or from the same domain.
* @param value The flag whether the XMLHttpRequest uses credentials.
* @returns Return this object
*/
AcCmLoader.prototype.setWithCredentials = function (value) {
this.withCredentials = value;
return this;
};
/**
* Set the base path for the asset.
* @param path The base path for the asset.
* @returns Return this object
*/
AcCmLoader.prototype.setPath = function (path) {
this.path = path;
return this;
};
/**
* Set the base path for dependent resources like textures.
* @param resourcePath The base path for dependent resources like textures.
* @returns Return this object
*/
AcCmLoader.prototype.setResourcePath = function (resourcePath) {
this.resourcePath = resourcePath;
return this;
};
/**
* Set the request header used in HTTP request.
* @param requestHeader key: The name of the header whose value is to be set. value: The value
* to set as the body of the header.
* @returns Return this object
*/
AcCmLoader.prototype.setRequestHeader = function (requestHeader) {
this.requestHeader = requestHeader;
return this;
};
return AcCmLoader;
}());
export { AcCmLoader };
//# sourceMappingURL=AcCmLoader.js.map