UNPKG

@mlightcad/common

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://img.shields.io/npm/v/@mlightcad/common.svg)](https://www.npmjs.com/package/@mlightcad/common)

116 lines 4.33 kB
/** * @fileoverview Base loader implementation for the AutoCAD Common library. * * This module provides the abstract base class for all loaders in the system, * defining the common interface and shared functionality for loading various * types of resources. * * @module AcCmLoader * @version 1.0.0 */ import { DefaultLoadingManager } from './AcCmLoadingManager'; /** * Abstract base class for implementing resource loaders. * * This class provides the common functionality and interface that all loaders * must implement, including loading manager integration, path handling, and * configuration options for cross-origin requests. * * @abstract * * @example * ```typescript * class MyCustomLoader extends AcCmLoader { * load(url: string, onLoad: (data: MyDataType) => void, onProgress?: AcCmLoaderProgressCallback, onError?: AcCmOnErrorCallback): void { * // Implementation specific loading logic * const fullUrl = this.resolveURL(url) * // ... fetch and process data * onLoad(processedData) * } * } * ``` */ 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