@mlightcad/common 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.js +1478 -0
- package/dist/common.umd.cjs +1 -0
- package/lib/AcCmColor.d.ts +201 -0
- package/lib/AcCmColor.d.ts.map +1 -0
- package/lib/AcCmColor.js +641 -0
- package/lib/AcCmColor.js.map +1 -0
- package/lib/AcCmColorUtil.d.ts +41 -0
- package/lib/AcCmColorUtil.d.ts.map +1 -0
- package/lib/AcCmColorUtil.js +90 -0
- package/lib/AcCmColorUtil.js.map +1 -0
- package/lib/AcCmErrors.d.ts +56 -0
- package/lib/AcCmErrors.d.ts.map +1 -0
- package/lib/AcCmErrors.js +70 -0
- package/lib/AcCmErrors.js.map +1 -0
- package/lib/AcCmEventDispatcher.d.ts +101 -0
- package/lib/AcCmEventDispatcher.d.ts.map +1 -0
- package/lib/AcCmEventDispatcher.js +97 -0
- package/lib/AcCmEventDispatcher.js.map +1 -0
- package/lib/AcCmEventManager.d.ts +66 -0
- package/lib/AcCmEventManager.d.ts.map +1 -0
- package/lib/AcCmEventManager.js +133 -0
- package/lib/AcCmEventManager.js.map +1 -0
- package/lib/AcCmLodashUtils.d.ts +145 -0
- package/lib/AcCmLodashUtils.d.ts.map +1 -0
- package/lib/AcCmLodashUtils.js +293 -0
- package/lib/AcCmLodashUtils.js.map +1 -0
- package/lib/AcCmLogUtil.d.ts +80 -0
- package/lib/AcCmLogUtil.d.ts.map +1 -0
- package/lib/AcCmLogUtil.js +72 -0
- package/lib/AcCmLogUtil.js.map +1 -0
- package/lib/AcCmObject.d.ts +150 -0
- package/lib/AcCmObject.d.ts.map +1 -0
- package/lib/AcCmObject.js +204 -0
- package/lib/AcCmObject.js.map +1 -0
- package/lib/AcCmPerformanceCollector.d.ts +89 -0
- package/lib/AcCmPerformanceCollector.d.ts.map +1 -0
- package/lib/AcCmPerformanceCollector.js +119 -0
- package/lib/AcCmPerformanceCollector.js.map +1 -0
- package/lib/AcCmStringUtil.d.ts +44 -0
- package/lib/AcCmStringUtil.d.ts.map +1 -0
- package/lib/AcCmStringUtil.js +58 -0
- package/lib/AcCmStringUtil.js.map +1 -0
- package/lib/AcCmTaskScheduler.d.ts +188 -0
- package/lib/AcCmTaskScheduler.d.ts.map +1 -0
- package/lib/AcCmTaskScheduler.js +256 -0
- package/lib/AcCmTaskScheduler.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/lib/loader/AcCmFileLoader.d.ts +95 -0
- package/lib/loader/AcCmFileLoader.d.ts.map +1 -0
- package/lib/loader/AcCmFileLoader.js +275 -0
- package/lib/loader/AcCmFileLoader.js.map +1 -0
- package/lib/loader/AcCmLoader.d.ts +125 -0
- package/lib/loader/AcCmLoader.d.ts.map +1 -0
- package/lib/loader/AcCmLoader.js +116 -0
- package/lib/loader/AcCmLoader.js.map +1 -0
- package/lib/loader/AcCmLoadingManager.d.ts +166 -0
- package/lib/loader/AcCmLoadingManager.d.ts.map +1 -0
- package/lib/loader/AcCmLoadingManager.js +172 -0
- package/lib/loader/AcCmLoadingManager.js.map +1 -0
- package/lib/loader/index.d.ts +3 -0
- package/lib/loader/index.d.ts.map +1 -0
- package/lib/loader/index.js +3 -0
- package/lib/loader/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTTP-based file loader implementation for the AutoCAD Common library.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a concrete implementation of the loader interface using
|
|
5
|
+
* the Fetch API for loading files over HTTP. Supports various response types
|
|
6
|
+
* and provides comprehensive error handling.
|
|
7
|
+
*
|
|
8
|
+
* @module AcCmFileLoader
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
import { AcCmLoader, AcCmLoaderProgressCallback } from './AcCmLoader';
|
|
12
|
+
import { AcCmLoadingManager, AcCmOnErrorCallback, AcCmOnLoadCallback } from './AcCmLoadingManager';
|
|
13
|
+
/**
|
|
14
|
+
* The supported response types for file loading operations.
|
|
15
|
+
*
|
|
16
|
+
* - `''` or `'text'` - Returns the data as a string (default).
|
|
17
|
+
* - `'arraybuffer'` - Loads the data into an ArrayBuffer.
|
|
18
|
+
* - `'blob'` - Returns the data as a Blob.
|
|
19
|
+
* - `'document'` - Parses the file using the DOMParser.
|
|
20
|
+
* - `'json'` - Parses the file using JSON.parse.
|
|
21
|
+
*/
|
|
22
|
+
type AcCmResponseType = '' | 'text' | 'arraybuffer' | 'blob' | 'document' | 'json';
|
|
23
|
+
/**
|
|
24
|
+
* HTTP-based file loader using the Fetch API.
|
|
25
|
+
*
|
|
26
|
+
* A low-level class for loading resources over HTTP, used internally by most loaders.
|
|
27
|
+
* It can also be used directly to load any file type that does not have a specialized loader.
|
|
28
|
+
*
|
|
29
|
+
* Supports various response types, custom MIME types, and provides comprehensive error handling
|
|
30
|
+
* with automatic retry mechanisms for failed requests.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { AcCmFileLoader } from './AcCmFileLoader'
|
|
35
|
+
*
|
|
36
|
+
* const loader = new AcCmFileLoader()
|
|
37
|
+
*
|
|
38
|
+
* // Load a text file
|
|
39
|
+
* loader.load(
|
|
40
|
+
* 'data.txt',
|
|
41
|
+
* (data) => console.log('Loaded:', data),
|
|
42
|
+
* (progress) => console.log('Progress:', progress.loaded / progress.total),
|
|
43
|
+
* (error) => console.error('Error:', error)
|
|
44
|
+
* )
|
|
45
|
+
*
|
|
46
|
+
* // Load binary data
|
|
47
|
+
* loader.setResponseType('arraybuffer')
|
|
48
|
+
* loader.load('file.dwg', (arrayBuffer) => {
|
|
49
|
+
* // Process binary data
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class AcCmFileLoader extends AcCmLoader {
|
|
54
|
+
/**
|
|
55
|
+
* The expected mimeType. Default is undefined.
|
|
56
|
+
*/
|
|
57
|
+
mimeType?: DOMParserSupportedType;
|
|
58
|
+
/**
|
|
59
|
+
* The expected response type. Default is undefined.
|
|
60
|
+
*/
|
|
61
|
+
responseType?: AcCmResponseType;
|
|
62
|
+
/**
|
|
63
|
+
* Create a new AcCmFileLoader instance.
|
|
64
|
+
* @param manager The loadingManager for the loader to use. Default is DefaultLoadingManager.
|
|
65
|
+
*/
|
|
66
|
+
constructor(manager?: AcCmLoadingManager);
|
|
67
|
+
/**
|
|
68
|
+
* Load the URL and pass the response to the onLoad function.
|
|
69
|
+
* @param url The path or URL to the file. This can also be a Data URI.
|
|
70
|
+
* @param onLoad (optional) — Will be called when loading completes.
|
|
71
|
+
* @param onProgress (optional) — Will be called while load progresses.
|
|
72
|
+
* @param onError (optional) — Will be called if an error occurs.
|
|
73
|
+
*/
|
|
74
|
+
load(url: string, onLoad: AcCmOnLoadCallback, onProgress: AcCmLoaderProgressCallback, onError: AcCmOnErrorCallback): void;
|
|
75
|
+
/**
|
|
76
|
+
* Change the response type. Valid values are:
|
|
77
|
+
* - text or empty string (default) - returns the data as String.
|
|
78
|
+
* - arraybuffer - loads the data into a ArrayBuffer and returns that.
|
|
79
|
+
* - blob - returns the data as a Blob.
|
|
80
|
+
* - document - parses the file using the DOMParser.
|
|
81
|
+
* - json - parses the file using JSON.parse.
|
|
82
|
+
* @param value
|
|
83
|
+
* @returns Return this object
|
|
84
|
+
*/
|
|
85
|
+
setResponseType(value: AcCmResponseType): this;
|
|
86
|
+
/**
|
|
87
|
+
* Set the expected mimeType of the file being loaded. Note that in many cases this will be determined
|
|
88
|
+
* automatically, so by default it is undefined.
|
|
89
|
+
* @param value The expected mimeType of the file being loaded.
|
|
90
|
+
* @returns Return this object.
|
|
91
|
+
*/
|
|
92
|
+
setMimeType(value: DOMParserSupportedType): this;
|
|
93
|
+
}
|
|
94
|
+
export {};
|
|
95
|
+
//# sourceMappingURL=AcCmFileLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AcCmFileLoader.d.ts","sourceRoot":"","sources":["../../src/loader/AcCmFileLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACrE,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,sBAAsB,CAAA;AAmC7B;;;;;;;;GAQG;AACH,KAAK,gBAAgB,GACjB,EAAE,GACF,MAAM,GACN,aAAa,GACb,MAAM,GACN,UAAU,GACV,MAAM,CAAA;AAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C;;OAEG;IACH,QAAQ,CAAC,EAAE,sBAAsB,CAAA;IACjC;;OAEG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAA;IAE/B;;;OAGG;gBACS,OAAO,CAAC,EAAE,kBAAkB;IAIxC;;;;;;OAMG;IACH,IAAI,CACF,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,kBAAkB,EAC1B,UAAU,EAAE,0BAA0B,EACtC,OAAO,EAAE,mBAAmB;IAmL9B;;;;;;;;;OASG;IACH,eAAe,CAAC,KAAK,EAAE,gBAAgB;IAKvC;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,sBAAsB;CAI1C"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTTP-based file loader implementation for the AutoCAD Common library.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a concrete implementation of the loader interface using
|
|
5
|
+
* the Fetch API for loading files over HTTP. Supports various response types
|
|
6
|
+
* and provides comprehensive error handling.
|
|
7
|
+
*
|
|
8
|
+
* @module AcCmFileLoader
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
var __extends = (this && this.__extends) || (function () {
|
|
12
|
+
var extendStatics = function (d, b) {
|
|
13
|
+
extendStatics = Object.setPrototypeOf ||
|
|
14
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
15
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
16
|
+
return extendStatics(d, b);
|
|
17
|
+
};
|
|
18
|
+
return function (d, b) {
|
|
19
|
+
if (typeof b !== "function" && b !== null)
|
|
20
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
21
|
+
extendStatics(d, b);
|
|
22
|
+
function __() { this.constructor = d; }
|
|
23
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
import { AcCmLoader } from './AcCmLoader';
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
var loading = {};
|
|
31
|
+
/**
|
|
32
|
+
* Custom error class for HTTP-related failures.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
var HttpError = /** @class */ (function (_super) {
|
|
37
|
+
__extends(HttpError, _super);
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new HttpError.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} message - The error message.
|
|
42
|
+
* @param {Response} response - The HTTP response that caused the error.
|
|
43
|
+
*/
|
|
44
|
+
function HttpError(message, response) {
|
|
45
|
+
var _this = _super.call(this, message) || this;
|
|
46
|
+
_this.response = response;
|
|
47
|
+
return _this;
|
|
48
|
+
}
|
|
49
|
+
return HttpError;
|
|
50
|
+
}(Error));
|
|
51
|
+
/**
|
|
52
|
+
* HTTP-based file loader using the Fetch API.
|
|
53
|
+
*
|
|
54
|
+
* A low-level class for loading resources over HTTP, used internally by most loaders.
|
|
55
|
+
* It can also be used directly to load any file type that does not have a specialized loader.
|
|
56
|
+
*
|
|
57
|
+
* Supports various response types, custom MIME types, and provides comprehensive error handling
|
|
58
|
+
* with automatic retry mechanisms for failed requests.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { AcCmFileLoader } from './AcCmFileLoader'
|
|
63
|
+
*
|
|
64
|
+
* const loader = new AcCmFileLoader()
|
|
65
|
+
*
|
|
66
|
+
* // Load a text file
|
|
67
|
+
* loader.load(
|
|
68
|
+
* 'data.txt',
|
|
69
|
+
* (data) => console.log('Loaded:', data),
|
|
70
|
+
* (progress) => console.log('Progress:', progress.loaded / progress.total),
|
|
71
|
+
* (error) => console.error('Error:', error)
|
|
72
|
+
* )
|
|
73
|
+
*
|
|
74
|
+
* // Load binary data
|
|
75
|
+
* loader.setResponseType('arraybuffer')
|
|
76
|
+
* loader.load('file.dwg', (arrayBuffer) => {
|
|
77
|
+
* // Process binary data
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
var AcCmFileLoader = /** @class */ (function (_super) {
|
|
82
|
+
__extends(AcCmFileLoader, _super);
|
|
83
|
+
/**
|
|
84
|
+
* Create a new AcCmFileLoader instance.
|
|
85
|
+
* @param manager The loadingManager for the loader to use. Default is DefaultLoadingManager.
|
|
86
|
+
*/
|
|
87
|
+
function AcCmFileLoader(manager) {
|
|
88
|
+
return _super.call(this, manager) || this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Load the URL and pass the response to the onLoad function.
|
|
92
|
+
* @param url The path or URL to the file. This can also be a Data URI.
|
|
93
|
+
* @param onLoad (optional) — Will be called when loading completes.
|
|
94
|
+
* @param onProgress (optional) — Will be called while load progresses.
|
|
95
|
+
* @param onError (optional) — Will be called if an error occurs.
|
|
96
|
+
*/
|
|
97
|
+
AcCmFileLoader.prototype.load = function (url, onLoad, onProgress, onError) {
|
|
98
|
+
var _this = this;
|
|
99
|
+
if (url === undefined)
|
|
100
|
+
url = '';
|
|
101
|
+
if (this.path !== undefined)
|
|
102
|
+
url = this.path + url;
|
|
103
|
+
url = this.manager.resolveURL(url);
|
|
104
|
+
// Check if request is duplicate
|
|
105
|
+
if (loading[url] !== undefined) {
|
|
106
|
+
loading[url].push({
|
|
107
|
+
onLoad: onLoad,
|
|
108
|
+
onProgress: onProgress,
|
|
109
|
+
onError: onError
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// Initialise array for duplicate requests
|
|
114
|
+
loading[url] = [];
|
|
115
|
+
loading[url].push({
|
|
116
|
+
onLoad: onLoad,
|
|
117
|
+
onProgress: onProgress,
|
|
118
|
+
onError: onError
|
|
119
|
+
});
|
|
120
|
+
// create request
|
|
121
|
+
var req = new Request(url, {
|
|
122
|
+
headers: new Headers(this.requestHeader),
|
|
123
|
+
credentials: this.withCredentials ? 'include' : 'same-origin'
|
|
124
|
+
// An abort controller could be added within a future PR
|
|
125
|
+
});
|
|
126
|
+
// record states ( avoid data race )
|
|
127
|
+
var mimeType = this.mimeType;
|
|
128
|
+
var responseType = this.responseType;
|
|
129
|
+
// start the fetch
|
|
130
|
+
fetch(req)
|
|
131
|
+
.then(function (response) {
|
|
132
|
+
var _a;
|
|
133
|
+
if (response.status === 200 || response.status === 0) {
|
|
134
|
+
// Some browsers return HTTP Status 0 when using non-http protocol
|
|
135
|
+
// e.g. 'file://' or 'data://'. Handle as success.
|
|
136
|
+
if (response.status === 0) {
|
|
137
|
+
console.warn('HTTP Status 0 received.');
|
|
138
|
+
}
|
|
139
|
+
// Workaround: Checking if response.body === undefined for Alipay browser #23548
|
|
140
|
+
if (typeof ReadableStream === 'undefined' ||
|
|
141
|
+
response.body === undefined ||
|
|
142
|
+
((_a = response.body) === null || _a === void 0 ? void 0 : _a.getReader) === undefined) {
|
|
143
|
+
return response;
|
|
144
|
+
}
|
|
145
|
+
var callbacks_1 = loading[url];
|
|
146
|
+
var reader_1 = response.body.getReader();
|
|
147
|
+
// Nginx needs X-File-Size check
|
|
148
|
+
// https://serverfault.com/questions/482875/why-does-nginx-remove-content-length-header-for-chunked-content
|
|
149
|
+
var contentLength = response.headers.get('X-File-Size') ||
|
|
150
|
+
response.headers.get('Content-Length');
|
|
151
|
+
var total_1 = contentLength ? parseInt(contentLength) : 0;
|
|
152
|
+
var lengthComputable_1 = total_1 !== 0;
|
|
153
|
+
var loaded_1 = 0;
|
|
154
|
+
// periodically read data into the new stream tracking while download progress
|
|
155
|
+
var stream = new ReadableStream({
|
|
156
|
+
start: function (controller) {
|
|
157
|
+
readData();
|
|
158
|
+
function readData() {
|
|
159
|
+
reader_1.read().then(function (_a) {
|
|
160
|
+
var done = _a.done, value = _a.value;
|
|
161
|
+
if (done) {
|
|
162
|
+
controller.close();
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
loaded_1 += value.byteLength;
|
|
166
|
+
var event_1 = new ProgressEvent('progress', {
|
|
167
|
+
lengthComputable: lengthComputable_1,
|
|
168
|
+
loaded: loaded_1,
|
|
169
|
+
total: total_1
|
|
170
|
+
});
|
|
171
|
+
for (var i = 0, il = callbacks_1.length; i < il; i++) {
|
|
172
|
+
var callback = callbacks_1[i];
|
|
173
|
+
if (callback.onProgress)
|
|
174
|
+
callback.onProgress(event_1);
|
|
175
|
+
}
|
|
176
|
+
controller.enqueue(value);
|
|
177
|
+
readData();
|
|
178
|
+
}
|
|
179
|
+
}, function (e) {
|
|
180
|
+
controller.error(e);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return new Response(stream);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new HttpError("fetch for \"".concat(response.url, "\" responded with ").concat(response.status, ": ").concat(response.statusText), response);
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
.then(function (response) {
|
|
192
|
+
switch (responseType) {
|
|
193
|
+
case 'arraybuffer':
|
|
194
|
+
return response.arrayBuffer();
|
|
195
|
+
case 'blob':
|
|
196
|
+
return response.blob();
|
|
197
|
+
case 'document':
|
|
198
|
+
return response.text().then(function (text) {
|
|
199
|
+
var parser = new DOMParser();
|
|
200
|
+
return parser.parseFromString(text, mimeType);
|
|
201
|
+
});
|
|
202
|
+
case 'json':
|
|
203
|
+
return response.json();
|
|
204
|
+
default:
|
|
205
|
+
if (mimeType === undefined) {
|
|
206
|
+
return response.text();
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// sniff encoding
|
|
210
|
+
var re = /charset="?([^;"\s]*)"?/i;
|
|
211
|
+
var exec = re.exec(mimeType);
|
|
212
|
+
var label = exec && exec[1] ? exec[1].toLowerCase() : undefined;
|
|
213
|
+
var decoder_1 = new TextDecoder(label);
|
|
214
|
+
return response.arrayBuffer().then(function (ab) { return decoder_1.decode(ab); });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
.then(function (data) {
|
|
219
|
+
var callbacks = loading[url];
|
|
220
|
+
delete loading[url];
|
|
221
|
+
for (var i = 0, il = callbacks.length; i < il; i++) {
|
|
222
|
+
var callback = callbacks[i];
|
|
223
|
+
if (callback.onLoad)
|
|
224
|
+
callback.onLoad(data);
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
.catch(function (err) {
|
|
228
|
+
// Abort errors and other errors are handled the same
|
|
229
|
+
var callbacks = loading[url];
|
|
230
|
+
if (callbacks === undefined) {
|
|
231
|
+
// When onLoad was called and url was deleted in `loading`
|
|
232
|
+
_this.manager.itemError(url);
|
|
233
|
+
throw err;
|
|
234
|
+
}
|
|
235
|
+
delete loading[url];
|
|
236
|
+
for (var i = 0, il = callbacks.length; i < il; i++) {
|
|
237
|
+
var callback = callbacks[i];
|
|
238
|
+
if (callback.onError)
|
|
239
|
+
callback.onError(err);
|
|
240
|
+
}
|
|
241
|
+
_this.manager.itemError(url);
|
|
242
|
+
})
|
|
243
|
+
.finally(function () {
|
|
244
|
+
_this.manager.itemEnd(url);
|
|
245
|
+
});
|
|
246
|
+
this.manager.itemStart(url);
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Change the response type. Valid values are:
|
|
250
|
+
* - text or empty string (default) - returns the data as String.
|
|
251
|
+
* - arraybuffer - loads the data into a ArrayBuffer and returns that.
|
|
252
|
+
* - blob - returns the data as a Blob.
|
|
253
|
+
* - document - parses the file using the DOMParser.
|
|
254
|
+
* - json - parses the file using JSON.parse.
|
|
255
|
+
* @param value
|
|
256
|
+
* @returns Return this object
|
|
257
|
+
*/
|
|
258
|
+
AcCmFileLoader.prototype.setResponseType = function (value) {
|
|
259
|
+
this.responseType = value;
|
|
260
|
+
return this;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Set the expected mimeType of the file being loaded. Note that in many cases this will be determined
|
|
264
|
+
* automatically, so by default it is undefined.
|
|
265
|
+
* @param value The expected mimeType of the file being loaded.
|
|
266
|
+
* @returns Return this object.
|
|
267
|
+
*/
|
|
268
|
+
AcCmFileLoader.prototype.setMimeType = function (value) {
|
|
269
|
+
this.mimeType = value;
|
|
270
|
+
return this;
|
|
271
|
+
};
|
|
272
|
+
return AcCmFileLoader;
|
|
273
|
+
}(AcCmLoader));
|
|
274
|
+
export { AcCmFileLoader };
|
|
275
|
+
//# sourceMappingURL=AcCmFileLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AcCmFileLoader.js","sourceRoot":"","sources":["../../src/loader/AcCmFileLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,UAAU,EAA8B,MAAM,cAAc,CAAA;AAOrE;;GAEG;AACH,IAAM,OAAO,GAOT,EAAE,CAAA;AAEN;;;;GAIG;AACH;IAAwB,6BAAK;IAI3B;;;;;OAKG;IACH,mBAAY,OAAe,EAAE,QAAkB;QAC7C,YAAA,MAAK,YAAC,OAAO,CAAC,SAAA;QACd,KAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;;IAC1B,CAAC;IACH,gBAAC;AAAD,CAAC,AAdD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I,CAAC,QAAQ,GAAG,KAAK,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IACH,qBAAC;AAAD,CAAC,AAzOD,CAAoC,UAAU,GAyO7C"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Base loader implementation for the AutoCAD Common library.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the abstract base class for all loaders in the system,
|
|
5
|
+
* defining the common interface and shared functionality for loading various
|
|
6
|
+
* types of resources.
|
|
7
|
+
*
|
|
8
|
+
* @module AcCmLoader
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
import { AcCmLoadingManager, AcCmOnErrorCallback } from './AcCmLoadingManager';
|
|
12
|
+
/**
|
|
13
|
+
* Callback function for reporting loading progress.
|
|
14
|
+
*
|
|
15
|
+
* @param {ProgressEvent} progress - The progress event containing loading information.
|
|
16
|
+
*/
|
|
17
|
+
export type AcCmLoaderProgressCallback = (progress: ProgressEvent) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Abstract base class for implementing resource loaders.
|
|
20
|
+
*
|
|
21
|
+
* This class provides the common functionality and interface that all loaders
|
|
22
|
+
* must implement, including loading manager integration, path handling, and
|
|
23
|
+
* configuration options for cross-origin requests.
|
|
24
|
+
*
|
|
25
|
+
* @abstract
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* class MyCustomLoader extends AcCmLoader {
|
|
30
|
+
* load(url: string, onLoad: (data: MyDataType) => void, onProgress?: AcCmLoaderProgressCallback, onError?: AcCmOnErrorCallback): void {
|
|
31
|
+
* // Implementation specific loading logic
|
|
32
|
+
* const fullUrl = this.resolveURL(url)
|
|
33
|
+
* // ... fetch and process data
|
|
34
|
+
* onLoad(processedData)
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare abstract class AcCmLoader {
|
|
40
|
+
manager: AcCmLoadingManager;
|
|
41
|
+
/**
|
|
42
|
+
* The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
|
|
43
|
+
* Default is anonymous.
|
|
44
|
+
*/
|
|
45
|
+
crossOrigin: string;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the XMLHttpRequest uses credentials. Default is false.
|
|
48
|
+
*/
|
|
49
|
+
withCredentials: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The base path from which the asset will be loaded. Default is the empty string.
|
|
52
|
+
*/
|
|
53
|
+
path: string;
|
|
54
|
+
/**
|
|
55
|
+
* The base path from which additional resources like textures will be loaded.
|
|
56
|
+
* Default is the empty string.
|
|
57
|
+
*/
|
|
58
|
+
resourcePath: string;
|
|
59
|
+
/**
|
|
60
|
+
* The request header used in HTTP request.
|
|
61
|
+
*/
|
|
62
|
+
requestHeader: HeadersInit;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new AcCmLoader instance.
|
|
65
|
+
* @param manager The loadingManager for the loader to use. Default is DefaultLoadingManager.
|
|
66
|
+
*/
|
|
67
|
+
constructor(manager?: AcCmLoadingManager);
|
|
68
|
+
/**
|
|
69
|
+
* This method needs to be implement by all concrete loaders. It holds the logic for loading
|
|
70
|
+
* the asset from the backend.
|
|
71
|
+
* @param url The path or URL to the file. This can also be a Data URI.
|
|
72
|
+
* @param onLoad (optional) — Will be called when loading completes.
|
|
73
|
+
* @param onProgress (optional) — Will be called while load progresses.
|
|
74
|
+
* @param onError (optional) — Will be called if an error occurs.
|
|
75
|
+
*/
|
|
76
|
+
abstract load(url: string, onLoad?: (data: unknown) => void, onProgress?: AcCmLoaderProgressCallback, onError?: AcCmOnErrorCallback): void;
|
|
77
|
+
/**
|
|
78
|
+
* This method is equivalent to 'load', but returns a Promise.
|
|
79
|
+
* @param url A string containing the path/URL of the file to be loaded.
|
|
80
|
+
* @param onProgress (optional) — A function to be called while the loading is in progress.
|
|
81
|
+
* The argument will be the ProgressEvent instance, which contains .lengthComputable, .total
|
|
82
|
+
* and .loaded. If the server does not set the Content-Length header; .total will be 0.
|
|
83
|
+
* @returns Return a promise.
|
|
84
|
+
*/
|
|
85
|
+
loadAsync(url: string, onProgress: AcCmLoaderProgressCallback): Promise<unknown>;
|
|
86
|
+
/**
|
|
87
|
+
* This method needs to be implement by all concrete loaders. It holds the logic for parsing the asset.
|
|
88
|
+
*/
|
|
89
|
+
parse(_data: unknown): void;
|
|
90
|
+
/**
|
|
91
|
+
* Set the crossOrigin string to implement CORS for loading the url from a different domain that allows
|
|
92
|
+
* CORS.
|
|
93
|
+
* @param crossOrigin The crossOrigin string
|
|
94
|
+
* @returns Return this object
|
|
95
|
+
*/
|
|
96
|
+
setCrossOrigin(crossOrigin: string): this;
|
|
97
|
+
/**
|
|
98
|
+
* Set whether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS
|
|
99
|
+
* client certificates.
|
|
100
|
+
* Note that this has no effect if you are loading files locally or from the same domain.
|
|
101
|
+
* @param value The flag whether the XMLHttpRequest uses credentials.
|
|
102
|
+
* @returns Return this object
|
|
103
|
+
*/
|
|
104
|
+
setWithCredentials(value: boolean): this;
|
|
105
|
+
/**
|
|
106
|
+
* Set the base path for the asset.
|
|
107
|
+
* @param path The base path for the asset.
|
|
108
|
+
* @returns Return this object
|
|
109
|
+
*/
|
|
110
|
+
setPath(path: string): this;
|
|
111
|
+
/**
|
|
112
|
+
* Set the base path for dependent resources like textures.
|
|
113
|
+
* @param resourcePath The base path for dependent resources like textures.
|
|
114
|
+
* @returns Return this object
|
|
115
|
+
*/
|
|
116
|
+
setResourcePath(resourcePath: string): this;
|
|
117
|
+
/**
|
|
118
|
+
* Set the request header used in HTTP request.
|
|
119
|
+
* @param requestHeader key: The name of the header whose value is to be set. value: The value
|
|
120
|
+
* to set as the body of the header.
|
|
121
|
+
* @returns Return this object
|
|
122
|
+
*/
|
|
123
|
+
setRequestHeader(requestHeader: HeadersInit): this;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=AcCmLoader.d.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AAC,aAAa,EAAE,WAAW;CAI5C"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Base loader implementation for the AutoCAD Common library.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the abstract base class for all loaders in the system,
|
|
5
|
+
* defining the common interface and shared functionality for loading various
|
|
6
|
+
* types of resources.
|
|
7
|
+
*
|
|
8
|
+
* @module AcCmLoader
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
import { DefaultLoadingManager } from './AcCmLoadingManager';
|
|
12
|
+
/**
|
|
13
|
+
* Abstract base class for implementing resource loaders.
|
|
14
|
+
*
|
|
15
|
+
* This class provides the common functionality and interface that all loaders
|
|
16
|
+
* must implement, including loading manager integration, path handling, and
|
|
17
|
+
* configuration options for cross-origin requests.
|
|
18
|
+
*
|
|
19
|
+
* @abstract
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* class MyCustomLoader extends AcCmLoader {
|
|
24
|
+
* load(url: string, onLoad: (data: MyDataType) => void, onProgress?: AcCmLoaderProgressCallback, onError?: AcCmOnErrorCallback): void {
|
|
25
|
+
* // Implementation specific loading logic
|
|
26
|
+
* const fullUrl = this.resolveURL(url)
|
|
27
|
+
* // ... fetch and process data
|
|
28
|
+
* onLoad(processedData)
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
var AcCmLoader = /** @class */ (function () {
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new AcCmLoader instance.
|
|
36
|
+
* @param manager The loadingManager for the loader to use. Default is DefaultLoadingManager.
|
|
37
|
+
*/
|
|
38
|
+
function AcCmLoader(manager) {
|
|
39
|
+
this.manager = manager !== undefined ? manager : DefaultLoadingManager;
|
|
40
|
+
this.crossOrigin = 'anonymous';
|
|
41
|
+
this.withCredentials = false;
|
|
42
|
+
this.path = '';
|
|
43
|
+
this.resourcePath = '';
|
|
44
|
+
this.requestHeader = {};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This method is equivalent to 'load', but returns a Promise.
|
|
48
|
+
* @param url A string containing the path/URL of the file to be loaded.
|
|
49
|
+
* @param onProgress (optional) — A function to be called while the loading is in progress.
|
|
50
|
+
* The argument will be the ProgressEvent instance, which contains .lengthComputable, .total
|
|
51
|
+
* and .loaded. If the server does not set the Content-Length header; .total will be 0.
|
|
52
|
+
* @returns Return a promise.
|
|
53
|
+
*/
|
|
54
|
+
AcCmLoader.prototype.loadAsync = function (url, onProgress) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
return new Promise(function (resolve, reject) {
|
|
57
|
+
_this.load(url, resolve, onProgress, reject);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* This method needs to be implement by all concrete loaders. It holds the logic for parsing the asset.
|
|
62
|
+
*/
|
|
63
|
+
AcCmLoader.prototype.parse = function (_data) { };
|
|
64
|
+
/**
|
|
65
|
+
* Set the crossOrigin string to implement CORS for loading the url from a different domain that allows
|
|
66
|
+
* CORS.
|
|
67
|
+
* @param crossOrigin The crossOrigin string
|
|
68
|
+
* @returns Return this object
|
|
69
|
+
*/
|
|
70
|
+
AcCmLoader.prototype.setCrossOrigin = function (crossOrigin) {
|
|
71
|
+
this.crossOrigin = crossOrigin;
|
|
72
|
+
return this;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Set whether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS
|
|
76
|
+
* client certificates.
|
|
77
|
+
* Note that this has no effect if you are loading files locally or from the same domain.
|
|
78
|
+
* @param value The flag whether the XMLHttpRequest uses credentials.
|
|
79
|
+
* @returns Return this object
|
|
80
|
+
*/
|
|
81
|
+
AcCmLoader.prototype.setWithCredentials = function (value) {
|
|
82
|
+
this.withCredentials = value;
|
|
83
|
+
return this;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Set the base path for the asset.
|
|
87
|
+
* @param path The base path for the asset.
|
|
88
|
+
* @returns Return this object
|
|
89
|
+
*/
|
|
90
|
+
AcCmLoader.prototype.setPath = function (path) {
|
|
91
|
+
this.path = path;
|
|
92
|
+
return this;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Set the base path for dependent resources like textures.
|
|
96
|
+
* @param resourcePath The base path for dependent resources like textures.
|
|
97
|
+
* @returns Return this object
|
|
98
|
+
*/
|
|
99
|
+
AcCmLoader.prototype.setResourcePath = function (resourcePath) {
|
|
100
|
+
this.resourcePath = resourcePath;
|
|
101
|
+
return this;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Set the request header used in HTTP request.
|
|
105
|
+
* @param requestHeader key: The name of the header whose value is to be set. value: The value
|
|
106
|
+
* to set as the body of the header.
|
|
107
|
+
* @returns Return this object
|
|
108
|
+
*/
|
|
109
|
+
AcCmLoader.prototype.setRequestHeader = function (requestHeader) {
|
|
110
|
+
this.requestHeader = requestHeader;
|
|
111
|
+
return this;
|
|
112
|
+
};
|
|
113
|
+
return AcCmLoader;
|
|
114
|
+
}());
|
|
115
|
+
export { AcCmLoader };
|
|
116
|
+
//# sourceMappingURL=AcCmLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AcCmLoader.js","sourceRoot":"","sources":["../../src/loader/AcCmLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAGL,qBAAqB,EACtB,MAAM,sBAAsB,CAAA;AAS7B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH;IAyBE;;;OAGG;IACH,oBAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB,CAAA;QACtE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,eAAe,GAAG,KAAK,CAAA;QAC5B,IAAI,CAAC,I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