@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.
Files changed (67) hide show
  1. package/dist/common.js +1478 -0
  2. package/dist/common.umd.cjs +1 -0
  3. package/lib/AcCmColor.d.ts +201 -0
  4. package/lib/AcCmColor.d.ts.map +1 -0
  5. package/lib/AcCmColor.js +641 -0
  6. package/lib/AcCmColor.js.map +1 -0
  7. package/lib/AcCmColorUtil.d.ts +41 -0
  8. package/lib/AcCmColorUtil.d.ts.map +1 -0
  9. package/lib/AcCmColorUtil.js +90 -0
  10. package/lib/AcCmColorUtil.js.map +1 -0
  11. package/lib/AcCmErrors.d.ts +56 -0
  12. package/lib/AcCmErrors.d.ts.map +1 -0
  13. package/lib/AcCmErrors.js +70 -0
  14. package/lib/AcCmErrors.js.map +1 -0
  15. package/lib/AcCmEventDispatcher.d.ts +101 -0
  16. package/lib/AcCmEventDispatcher.d.ts.map +1 -0
  17. package/lib/AcCmEventDispatcher.js +97 -0
  18. package/lib/AcCmEventDispatcher.js.map +1 -0
  19. package/lib/AcCmEventManager.d.ts +66 -0
  20. package/lib/AcCmEventManager.d.ts.map +1 -0
  21. package/lib/AcCmEventManager.js +133 -0
  22. package/lib/AcCmEventManager.js.map +1 -0
  23. package/lib/AcCmLodashUtils.d.ts +145 -0
  24. package/lib/AcCmLodashUtils.d.ts.map +1 -0
  25. package/lib/AcCmLodashUtils.js +293 -0
  26. package/lib/AcCmLodashUtils.js.map +1 -0
  27. package/lib/AcCmLogUtil.d.ts +80 -0
  28. package/lib/AcCmLogUtil.d.ts.map +1 -0
  29. package/lib/AcCmLogUtil.js +72 -0
  30. package/lib/AcCmLogUtil.js.map +1 -0
  31. package/lib/AcCmObject.d.ts +150 -0
  32. package/lib/AcCmObject.d.ts.map +1 -0
  33. package/lib/AcCmObject.js +204 -0
  34. package/lib/AcCmObject.js.map +1 -0
  35. package/lib/AcCmPerformanceCollector.d.ts +89 -0
  36. package/lib/AcCmPerformanceCollector.d.ts.map +1 -0
  37. package/lib/AcCmPerformanceCollector.js +119 -0
  38. package/lib/AcCmPerformanceCollector.js.map +1 -0
  39. package/lib/AcCmStringUtil.d.ts +44 -0
  40. package/lib/AcCmStringUtil.d.ts.map +1 -0
  41. package/lib/AcCmStringUtil.js +58 -0
  42. package/lib/AcCmStringUtil.js.map +1 -0
  43. package/lib/AcCmTaskScheduler.d.ts +188 -0
  44. package/lib/AcCmTaskScheduler.d.ts.map +1 -0
  45. package/lib/AcCmTaskScheduler.js +256 -0
  46. package/lib/AcCmTaskScheduler.js.map +1 -0
  47. package/lib/index.d.ts +12 -0
  48. package/lib/index.d.ts.map +1 -0
  49. package/lib/index.js +12 -0
  50. package/lib/index.js.map +1 -0
  51. package/lib/loader/AcCmFileLoader.d.ts +95 -0
  52. package/lib/loader/AcCmFileLoader.d.ts.map +1 -0
  53. package/lib/loader/AcCmFileLoader.js +275 -0
  54. package/lib/loader/AcCmFileLoader.js.map +1 -0
  55. package/lib/loader/AcCmLoader.d.ts +125 -0
  56. package/lib/loader/AcCmLoader.d.ts.map +1 -0
  57. package/lib/loader/AcCmLoader.js +116 -0
  58. package/lib/loader/AcCmLoader.js.map +1 -0
  59. package/lib/loader/AcCmLoadingManager.d.ts +166 -0
  60. package/lib/loader/AcCmLoadingManager.d.ts.map +1 -0
  61. package/lib/loader/AcCmLoadingManager.js +172 -0
  62. package/lib/loader/AcCmLoadingManager.js.map +1 -0
  63. package/lib/loader/index.d.ts +3 -0
  64. package/lib/loader/index.d.ts.map +1 -0
  65. package/lib/loader/index.js +3 -0
  66. package/lib/loader/index.js.map +1 -0
  67. package/package.json +1 -1
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @fileoverview String manipulation utilities for the AutoCAD Common library.
3
+ *
4
+ * This module provides utility functions for common string operations,
5
+ * including formatting and conversion utilities.
6
+ *
7
+ * @module AcCmStringUtil
8
+ * @version 1.0.0
9
+ */
10
+ /**
11
+ * Utility class providing static methods for string operations and formatting.
12
+ *
13
+ * Contains helper functions for data formatting, size conversions, and other
14
+ * string manipulation tasks commonly needed in AutoCAD file processing.
15
+ *
16
+ * @class AcTrStringUtil
17
+ * @version 1.0.0
18
+ */
19
+ export declare class AcTrStringUtil {
20
+ /**
21
+ * Converts a byte count to a human-readable string using appropriate size units.
22
+ *
23
+ * Automatically selects the most appropriate unit (B, KB, MB, GB, TB) based on the size
24
+ * and formats the result with the specified number of decimal places.
25
+ *
26
+ * @param {number} bytes - The number of bytes to format.
27
+ * @param {number} [decimals=2] - Number of decimal places to include in the result.
28
+ * @returns {string} A formatted string with the appropriate unit.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { AcTrStringUtil } from './AcCmStringUtil'
33
+ *
34
+ * // Format different byte sizes
35
+ * AcTrStringUtil.formatBytes(0) // "0 B"
36
+ * AcTrStringUtil.formatBytes(1024) // "1 KB"
37
+ * AcTrStringUtil.formatBytes(1024 * 1024) // "1 MB"
38
+ * AcTrStringUtil.formatBytes(1536, 1) // "1.5 KB"
39
+ * AcTrStringUtil.formatBytes(2048000, 0) // "2 MB"
40
+ * ```
41
+ */
42
+ static formatBytes(bytes: number, decimals?: number): string;
43
+ }
44
+ //# sourceMappingURL=AcCmStringUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcCmStringUtil.d.ts","sourceRoot":"","sources":["../src/AcCmStringUtil.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH,qBAAa,cAAc;IACzB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAI,GAAG,MAAM;CAYxD"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @fileoverview String manipulation utilities for the AutoCAD Common library.
3
+ *
4
+ * This module provides utility functions for common string operations,
5
+ * including formatting and conversion utilities.
6
+ *
7
+ * @module AcCmStringUtil
8
+ * @version 1.0.0
9
+ */
10
+ /**
11
+ * Utility class providing static methods for string operations and formatting.
12
+ *
13
+ * Contains helper functions for data formatting, size conversions, and other
14
+ * string manipulation tasks commonly needed in AutoCAD file processing.
15
+ *
16
+ * @class AcTrStringUtil
17
+ * @version 1.0.0
18
+ */
19
+ var AcTrStringUtil = /** @class */ (function () {
20
+ function AcTrStringUtil() {
21
+ }
22
+ /**
23
+ * Converts a byte count to a human-readable string using appropriate size units.
24
+ *
25
+ * Automatically selects the most appropriate unit (B, KB, MB, GB, TB) based on the size
26
+ * and formats the result with the specified number of decimal places.
27
+ *
28
+ * @param {number} bytes - The number of bytes to format.
29
+ * @param {number} [decimals=2] - Number of decimal places to include in the result.
30
+ * @returns {string} A formatted string with the appropriate unit.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import { AcTrStringUtil } from './AcCmStringUtil'
35
+ *
36
+ * // Format different byte sizes
37
+ * AcTrStringUtil.formatBytes(0) // "0 B"
38
+ * AcTrStringUtil.formatBytes(1024) // "1 KB"
39
+ * AcTrStringUtil.formatBytes(1024 * 1024) // "1 MB"
40
+ * AcTrStringUtil.formatBytes(1536, 1) // "1.5 KB"
41
+ * AcTrStringUtil.formatBytes(2048000, 0) // "2 MB"
42
+ * ```
43
+ */
44
+ AcTrStringUtil.formatBytes = function (bytes, decimals) {
45
+ if (decimals === void 0) { decimals = 2; }
46
+ if (bytes === 0)
47
+ return '0 B';
48
+ var k = 1024;
49
+ var dm = Math.max(0, decimals);
50
+ var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
51
+ var i = Math.floor(Math.log(bytes) / Math.log(k));
52
+ var value = bytes / Math.pow(k, i);
53
+ return "".concat(parseFloat(value.toFixed(dm)), " ").concat(sizes[i]);
54
+ };
55
+ return AcTrStringUtil;
56
+ }());
57
+ export { AcTrStringUtil };
58
+ //# sourceMappingURL=AcCmStringUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcCmStringUtil.js","sourceRoot":"","sources":["../src/AcCmStringUtil.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AACH;IAAA;IAmCA,CAAC;IAlCC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,0BAAW,GAAlB,UAAmB,KAAa,EAAE,QAAY;QAAZ,yBAAA,EAAA,YAAY;QAC5C,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QAE7B,IAAM,CAAC,GAAG,IAAI,CAAA;QACd,IAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;QAChC,IAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QAE3C,IAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACnD,IAAM,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAEpC,OAAO,UAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,cAAI,KAAK,CAAC,CAAC,CAAC,CAAE,CAAA;IACvD,CAAC;IACH,qBAAC;AAAD,CAAC,AAnCD,IAmCC"}
@@ -0,0 +1,188 @@
1
+ /**
2
+ * @fileoverview Task scheduling and execution system for the AutoCAD Common library.
3
+ *
4
+ * This module provides a type-safe task scheduler that can execute a chain of named tasks
5
+ * in sequence, with progress reporting, error handling, and data flow between tasks.
6
+ *
7
+ * @module AcCmTaskScheduler
8
+ * @version 1.0.0
9
+ */
10
+ /**
11
+ * Represents an error that occurred during task execution in the scheduler.
12
+ *
13
+ * This interface provides detailed information about task failures, including
14
+ * the original error, the position of the failed task in the execution queue,
15
+ * and a reference to the task that caused the failure.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const errorHandler = (taskError: AcCmTaskError) => {
20
+ * console.error(`Task "${taskError.task.name}" failed at position ${taskError.taskIndex}:`, taskError.error)
21
+ * }
22
+ * ```
23
+ */
24
+ export interface AcCmTaskError {
25
+ /**
26
+ * The error that was thrown during task execution.
27
+ *
28
+ * This can be any type of error (Error, string, object, etc.) that was
29
+ * thrown by the task's run() method or during task execution.
30
+ */
31
+ error: unknown;
32
+ /**
33
+ * The zero-based index of the failed task in the task execution queue.
34
+ *
35
+ * This indicates the position of the failed task relative to the start
36
+ * of the task chain, useful for debugging and error reporting.
37
+ */
38
+ taskIndex: number;
39
+ /**
40
+ * The task instance that failed during execution.
41
+ *
42
+ * Provides access to the task's name and other properties for
43
+ * detailed error reporting and debugging.
44
+ */
45
+ task: AcCmTask<unknown, unknown>;
46
+ }
47
+ /**
48
+ * Represents a named unit of work with an asynchronous or synchronous execution function.
49
+ *
50
+ * Tasks can be chained together in a scheduler to create complex workflows with
51
+ * proper data flow and error handling.
52
+ *
53
+ * @template TIn - Input type for the task.
54
+ * @template TOut - Output type for the task.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * class LoadFileTask extends AcCmTask<string, ArrayBuffer> {
59
+ * constructor() {
60
+ * super('LoadFile')
61
+ * }
62
+ *
63
+ * async run(url: string): Promise<ArrayBuffer> {
64
+ * const response = await fetch(url)
65
+ * return response.arrayBuffer()
66
+ * }
67
+ * }
68
+ * ```
69
+ */
70
+ export declare class AcCmTask<TIn, TOut> {
71
+ /**
72
+ * Name of the task (for logging/debugging purposes)
73
+ */
74
+ readonly name: string;
75
+ /**
76
+ * Creates a new task with the specified name.
77
+ *
78
+ * @param {string} name - The name identifier for this task.
79
+ */
80
+ constructor(name: string);
81
+ /**
82
+ * Executes the task with the given input.
83
+ *
84
+ * This method must be implemented by subclasses to define the actual work
85
+ * performed by the task. Can return either a synchronous result or a Promise.
86
+ *
87
+ * @param {TIn} _input - The input data for the task.
88
+ * @returns {TOut | Promise<TOut>} The task result, either synchronous or asynchronous.
89
+ * @throws {Error} When the method is not implemented by a subclass.
90
+ */
91
+ run(_input: TIn): TOut | Promise<TOut>;
92
+ }
93
+ /**
94
+ * Callback function that reports progress after a task completes.
95
+ *
96
+ * @param {number} progress - A number between 0 and 1 indicating task completion.
97
+ * @param {AcCmTask<unknown, unknown>} task - The task that was just completed.
98
+ */
99
+ type AcCmProgressCallback = (progress: number, task: AcCmTask<unknown, unknown>) => void;
100
+ /**
101
+ * Callback function to handle the final output after all tasks complete successfully.
102
+ *
103
+ * @template T - The type of the final result.
104
+ * @param {T} finalResult - The final result from the task chain.
105
+ */
106
+ export type AcCmCompleteCallback<T> = (finalResult: T) => void;
107
+ /**
108
+ * Callback function that handles errors during task execution.
109
+ *
110
+ * Returning `true` will interrupt the entire workflow.
111
+ * Returning `false` will allow the scheduler to continue executing remaining tasks.
112
+ *
113
+ * @param {AcCmTaskError} error - Detailed information about the task error.
114
+ * @returns {boolean} Whether to interrupt the task execution flow.
115
+ */
116
+ type AcCmErrorCallback = (error: AcCmTaskError) => boolean;
117
+ /**
118
+ * Type-safe task scheduler that executes a chain of named tasks in order.
119
+ *
120
+ * The scheduler passes results between tasks, reports progress, and stops
121
+ * execution on the first failure. Supports both synchronous and asynchronous tasks.
122
+ *
123
+ * @template TInitial - Initial input type for the first task.
124
+ * @template TFinal - Final output type from the last task.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Create scheduler with string input and object output
129
+ * const scheduler = new AcCmTaskScheduler<string, ParsedData>()
130
+ *
131
+ * // Add tasks
132
+ * scheduler.addTask(new LoadFileTask())
133
+ * scheduler.addTask(new ParseDataTask())
134
+ * scheduler.addTask(new ValidateDataTask())
135
+ *
136
+ * // Set callbacks
137
+ * scheduler.setProgressCallback((progress, task) => {
138
+ * console.log(`${task.name}: ${(progress * 100).toFixed(1)}%`)
139
+ * })
140
+ *
141
+ * scheduler.setCompleteCallback((result) => {
142
+ * console.log('All tasks completed:', result)
143
+ * })
144
+ *
145
+ * // Execute
146
+ * await scheduler.execute('file.dwg')
147
+ * ```
148
+ */
149
+ export declare class AcCmTaskScheduler<TInitial, TFinal = TInitial> {
150
+ private tasks;
151
+ private onProgress;
152
+ private onComplete;
153
+ private onError;
154
+ /**
155
+ * Schedules a task to be executed asynchronously.
156
+ *
157
+ * This method uses requestAnimationFrame in browser environments or setTimeout
158
+ * in Node.js environments to schedule the task.
159
+ *
160
+ * @param callback - The callback function to schedule
161
+ * @returns Promise that resolves with the result of the callback
162
+ */
163
+ private scheduleTask;
164
+ /**
165
+ * Adds a task to the execution queue.
166
+ *
167
+ * @param task Task instance with name and run function
168
+ */
169
+ addTask<TIn, TOut>(task: AcCmTask<TIn, TOut>): void;
170
+ /**
171
+ * Sets a callback to receive progress updates.
172
+ */
173
+ setProgressCallback(callback: AcCmProgressCallback): void;
174
+ /**
175
+ * Sets a callback to be called after successful completion of all tasks.
176
+ */
177
+ setCompleteCallback(callback: AcCmCompleteCallback<TFinal>): void;
178
+ /**
179
+ * Sets a callback to be called if any task throws an error.
180
+ */
181
+ setErrorCallback(callback: AcCmErrorCallback): void;
182
+ /**
183
+ * Starts execution of the task queue with the given initial input.
184
+ */
185
+ run(initialData: TInitial): Promise<void>;
186
+ }
187
+ export {};
188
+ //# sourceMappingURL=AcCmTaskScheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcCmTaskScheduler.d.ts","sourceRoot":"","sources":["../src/AcCmTaskScheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAA;IAEd;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;;;OAKG;IACH,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,QAAQ,CAAC,GAAG,EAAE,IAA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AC;CAwBhD"}
@@ -0,0 +1,256 @@
1
+ /**
2
+ * @fileoverview Task scheduling and execution system for the AutoCAD Common library.
3
+ *
4
+ * This module provides a type-safe task scheduler that can execute a chain of named tasks
5
+ * in sequence, with progress reporting, error handling, and data flow between tasks.
6
+ *
7
+ * @module AcCmTaskScheduler
8
+ * @version 1.0.0
9
+ */
10
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
11
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
12
+ return new (P || (P = Promise))(function (resolve, reject) {
13
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
17
+ });
18
+ };
19
+ var __generator = (this && this.__generator) || function (thisArg, body) {
20
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
21
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
22
+ function verb(n) { return function (v) { return step([n, v]); }; }
23
+ function step(op) {
24
+ if (f) throw new TypeError("Generator is already executing.");
25
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
26
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
27
+ if (y = 0, t) op = [op[0] & 2, t.value];
28
+ switch (op[0]) {
29
+ case 0: case 1: t = op; break;
30
+ case 4: _.label++; return { value: op[1], done: false };
31
+ case 5: _.label++; y = op[1]; op = [0]; continue;
32
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
33
+ default:
34
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
35
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
36
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
37
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
38
+ if (t[2]) _.ops.pop();
39
+ _.trys.pop(); continue;
40
+ }
41
+ op = body.call(thisArg, _);
42
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
43
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
44
+ }
45
+ };
46
+ /**
47
+ * Represents a named unit of work with an asynchronous or synchronous execution function.
48
+ *
49
+ * Tasks can be chained together in a scheduler to create complex workflows with
50
+ * proper data flow and error handling.
51
+ *
52
+ * @template TIn - Input type for the task.
53
+ * @template TOut - Output type for the task.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * class LoadFileTask extends AcCmTask<string, ArrayBuffer> {
58
+ * constructor() {
59
+ * super('LoadFile')
60
+ * }
61
+ *
62
+ * async run(url: string): Promise<ArrayBuffer> {
63
+ * const response = await fetch(url)
64
+ * return response.arrayBuffer()
65
+ * }
66
+ * }
67
+ * ```
68
+ */
69
+ var AcCmTask = /** @class */ (function () {
70
+ /**
71
+ * Creates a new task with the specified name.
72
+ *
73
+ * @param {string} name - The name identifier for this task.
74
+ */
75
+ function AcCmTask(name) {
76
+ this.name = name;
77
+ }
78
+ /**
79
+ * Executes the task with the given input.
80
+ *
81
+ * This method must be implemented by subclasses to define the actual work
82
+ * performed by the task. Can return either a synchronous result or a Promise.
83
+ *
84
+ * @param {TIn} _input - The input data for the task.
85
+ * @returns {TOut | Promise<TOut>} The task result, either synchronous or asynchronous.
86
+ * @throws {Error} When the method is not implemented by a subclass.
87
+ */
88
+ AcCmTask.prototype.run = function (_input) {
89
+ throw new Error('run() must be implemented by subclass');
90
+ };
91
+ return AcCmTask;
92
+ }());
93
+ export { AcCmTask };
94
+ /**
95
+ * Type-safe task scheduler that executes a chain of named tasks in order.
96
+ *
97
+ * The scheduler passes results between tasks, reports progress, and stops
98
+ * execution on the first failure. Supports both synchronous and asynchronous tasks.
99
+ *
100
+ * @template TInitial - Initial input type for the first task.
101
+ * @template TFinal - Final output type from the last task.
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // Create scheduler with string input and object output
106
+ * const scheduler = new AcCmTaskScheduler<string, ParsedData>()
107
+ *
108
+ * // Add tasks
109
+ * scheduler.addTask(new LoadFileTask())
110
+ * scheduler.addTask(new ParseDataTask())
111
+ * scheduler.addTask(new ValidateDataTask())
112
+ *
113
+ * // Set callbacks
114
+ * scheduler.setProgressCallback((progress, task) => {
115
+ * console.log(`${task.name}: ${(progress * 100).toFixed(1)}%`)
116
+ * })
117
+ *
118
+ * scheduler.setCompleteCallback((result) => {
119
+ * console.log('All tasks completed:', result)
120
+ * })
121
+ *
122
+ * // Execute
123
+ * await scheduler.execute('file.dwg')
124
+ * ```
125
+ */
126
+ var AcCmTaskScheduler = /** @class */ (function () {
127
+ function AcCmTaskScheduler() {
128
+ this.tasks = [];
129
+ this.onProgress = function () { };
130
+ this.onComplete = function () { };
131
+ this.onError = function () { return false; };
132
+ }
133
+ /**
134
+ * Schedules a task to be executed asynchronously.
135
+ *
136
+ * This method uses requestAnimationFrame in browser environments or setTimeout
137
+ * in Node.js environments to schedule the task.
138
+ *
139
+ * @param callback - The callback function to schedule
140
+ * @returns Promise that resolves with the result of the callback
141
+ */
142
+ AcCmTaskScheduler.prototype.scheduleTask = function (callback) {
143
+ return new Promise(function (resolve, reject) {
144
+ var executeCallback = function () {
145
+ // Execute the callback and handle the result
146
+ Promise.resolve(callback()).then(resolve).catch(reject);
147
+ };
148
+ if (typeof window !== 'undefined' &&
149
+ typeof window.requestAnimationFrame === 'function') {
150
+ // Browser environment with requestAnimationFrame
151
+ window.requestAnimationFrame(executeCallback);
152
+ }
153
+ else {
154
+ // Node.js or fallback to setTimeout
155
+ setTimeout(executeCallback, 0);
156
+ }
157
+ });
158
+ };
159
+ /**
160
+ * Adds a task to the execution queue.
161
+ *
162
+ * @param task Task instance with name and run function
163
+ */
164
+ AcCmTaskScheduler.prototype.addTask = function (task) {
165
+ this.tasks.push(task);
166
+ };
167
+ /**
168
+ * Sets a callback to receive progress updates.
169
+ */
170
+ AcCmTaskScheduler.prototype.setProgressCallback = function (callback) {
171
+ this.onProgress = callback;
172
+ };
173
+ /**
174
+ * Sets a callback to be called after successful completion of all tasks.
175
+ */
176
+ AcCmTaskScheduler.prototype.setCompleteCallback = function (callback) {
177
+ this.onComplete = callback;
178
+ };
179
+ /**
180
+ * Sets a callback to be called if any task throws an error.
181
+ */
182
+ AcCmTaskScheduler.prototype.setErrorCallback = function (callback) {
183
+ this.onError = callback;
184
+ };
185
+ /**
186
+ * Starts execution of the task queue with the given initial input.
187
+ */
188
+ AcCmTaskScheduler.prototype.run = function (initialData) {
189
+ return __awaiter(this, void 0, void 0, function () {
190
+ var total, result, _loop_1, this_1, i, state_1;
191
+ var _this = this;
192
+ return __generator(this, function (_a) {
193
+ switch (_a.label) {
194
+ case 0:
195
+ total = this.tasks.length;
196
+ result = initialData;
197
+ _loop_1 = function (i) {
198
+ var task, error_1, shouldInterrupt;
199
+ return __generator(this, function (_b) {
200
+ switch (_b.label) {
201
+ case 0:
202
+ task = this_1.tasks[i];
203
+ _b.label = 1;
204
+ case 1:
205
+ _b.trys.push([1, 3, , 4]);
206
+ return [4 /*yield*/, this_1.scheduleTask(function () { return __awaiter(_this, void 0, void 0, function () {
207
+ var output;
208
+ return __generator(this, function (_a) {
209
+ switch (_a.label) {
210
+ case 0: return [4 /*yield*/, task.run(result)];
211
+ case 1:
212
+ output = _a.sent();
213
+ this.onProgress((i + 1) / total, task);
214
+ return [2 /*return*/, output];
215
+ }
216
+ });
217
+ }); })];
218
+ case 2:
219
+ result = _b.sent();
220
+ return [3 /*break*/, 4];
221
+ case 3:
222
+ error_1 = _b.sent();
223
+ shouldInterrupt = this_1.onError({ error: error_1, taskIndex: i, task: task });
224
+ if (shouldInterrupt) {
225
+ return [2 /*return*/, "break"];
226
+ }
227
+ return [3 /*break*/, 4];
228
+ case 4: return [2 /*return*/];
229
+ }
230
+ });
231
+ };
232
+ this_1 = this;
233
+ i = 0;
234
+ _a.label = 1;
235
+ case 1:
236
+ if (!(i < total)) return [3 /*break*/, 4];
237
+ return [5 /*yield**/, _loop_1(i)];
238
+ case 2:
239
+ state_1 = _a.sent();
240
+ if (state_1 === "break")
241
+ return [3 /*break*/, 4];
242
+ _a.label = 3;
243
+ case 3:
244
+ i++;
245
+ return [3 /*break*/, 1];
246
+ case 4:
247
+ this.onComplete(result);
248
+ return [2 /*return*/];
249
+ }
250
+ });
251
+ });
252
+ };
253
+ return AcCmTaskScheduler;
254
+ }());
255
+ export { AcCmTaskScheduler };
256
+ //# sourceMappingURL=AcCmTaskScheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcCmTaskScheduler.js","sourceRoot":"","sources":["../src/AcCmTaskScheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IAME;;;;OAIG;IACH,kBAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED;;;;;;;;;OASG;IACH,sBAAG,GAAH,UAAI,MAAW;QACb,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;IAC1D,CAAC;IACH,eAAC;AAAD,CAAC,AA5BD,IA4BC;;AAgCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH;IAAA;QACU,UAAK,GAAiC,EAAE,CAAA;QACxC,eAAU,GAAyB,cAAO,CAAC,CAAA;QAC3C,eAAU,GAAiC,cAAO,CAAC,CAAA;QACnD,YAAO,GAAsB,cAAM,OAAA,KAAK,EAAL,CAAK,CAAA;IAwFlD,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wCAGf,qBAAM,OAAK,YAAY,CAAC;;;;gEAChB,qBAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAA;;4DAA/B,MAAM,GAAG,SAAsB;4DACrC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,CAAA;4DACtC,sBAAO,MAAM,EAAA;;;iDACd,CAAC,EAAA;;wCAJF,MAAM,GAAG,SAIP,CAAA;;;;wCAEI,eAAe,GAAG,OAAK,OAAO,CAAC,EAAE,KAAK,SAAA,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,MAAA,EAAE,CAAC,CAAA;wCACnE,IAAI,eAAe,EAAE,CAAC;;wCAGtB,CAAC;;;;;;;wBAdI,CAAC,GAAG,CAAC;;;6BAAE,CAAA,CAAC,GAAG,KAAK,CAAA;sDAAhB,CAAC;;;;;;;wBAAiB,CAAC,EAAE,CAAA;;;wBAkB9B,IAAI,CAAC,UAAU,CAAC,MAAgB,CAAC,CAAA;;;;;KAClC;IACH,wBAAC;AAAD,CAAC,AA5FD,IA4FC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export * from './AcCmColor';
2
+ export * from './AcCmErrors';
3
+ export * from './AcCmEventDispatcher';
4
+ export * from './AcCmEventManager';
5
+ export * from './AcCmLogUtil';
6
+ export * from './AcCmObject';
7
+ export * from './AcCmPerformanceCollector';
8
+ export * from './AcCmStringUtil';
9
+ export * from './AcCmTaskScheduler';
10
+ export * from './AcCmLodashUtils';
11
+ export * from './loader';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,UAAU,CAAA"}
package/lib/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export * from './AcCmColor';
2
+ export * from './AcCmErrors';
3
+ export * from './AcCmEventDispatcher';
4
+ export * from './AcCmEventManager';
5
+ export * from './AcCmLogUtil';
6
+ export * from './AcCmObject';
7
+ export * from './AcCmPerformanceCollector';
8
+ export * from './AcCmStringUtil';
9
+ export * from './AcCmTaskScheduler';
10
+ export * from './AcCmLodashUtils';
11
+ export * from './loader';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,UAAU,CAAA"}