@mlightcad/common 1.2.1 → 1.2.3

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/package.json +2 -2
  2. package/dist/common.js +0 -1479
  3. package/dist/common.umd.cjs +0 -1
  4. package/lib/AcCmColor.d.ts +0 -201
  5. package/lib/AcCmColor.d.ts.map +0 -1
  6. package/lib/AcCmColor.js +0 -641
  7. package/lib/AcCmColor.js.map +0 -1
  8. package/lib/AcCmColorUtil.d.ts +0 -41
  9. package/lib/AcCmColorUtil.d.ts.map +0 -1
  10. package/lib/AcCmColorUtil.js +0 -90
  11. package/lib/AcCmColorUtil.js.map +0 -1
  12. package/lib/AcCmErrors.d.ts +0 -56
  13. package/lib/AcCmErrors.d.ts.map +0 -1
  14. package/lib/AcCmErrors.js +0 -70
  15. package/lib/AcCmErrors.js.map +0 -1
  16. package/lib/AcCmEventDispatcher.d.ts +0 -101
  17. package/lib/AcCmEventDispatcher.d.ts.map +0 -1
  18. package/lib/AcCmEventDispatcher.js +0 -97
  19. package/lib/AcCmEventDispatcher.js.map +0 -1
  20. package/lib/AcCmEventManager.d.ts +0 -66
  21. package/lib/AcCmEventManager.d.ts.map +0 -1
  22. package/lib/AcCmEventManager.js +0 -133
  23. package/lib/AcCmEventManager.js.map +0 -1
  24. package/lib/AcCmLodashUtils.d.ts +0 -145
  25. package/lib/AcCmLodashUtils.d.ts.map +0 -1
  26. package/lib/AcCmLodashUtils.js +0 -293
  27. package/lib/AcCmLodashUtils.js.map +0 -1
  28. package/lib/AcCmLogUtil.d.ts +0 -80
  29. package/lib/AcCmLogUtil.d.ts.map +0 -1
  30. package/lib/AcCmLogUtil.js +0 -72
  31. package/lib/AcCmLogUtil.js.map +0 -1
  32. package/lib/AcCmObject.d.ts +0 -150
  33. package/lib/AcCmObject.d.ts.map +0 -1
  34. package/lib/AcCmObject.js +0 -204
  35. package/lib/AcCmObject.js.map +0 -1
  36. package/lib/AcCmPerformanceCollector.d.ts +0 -89
  37. package/lib/AcCmPerformanceCollector.d.ts.map +0 -1
  38. package/lib/AcCmPerformanceCollector.js +0 -119
  39. package/lib/AcCmPerformanceCollector.js.map +0 -1
  40. package/lib/AcCmStringUtil.d.ts +0 -44
  41. package/lib/AcCmStringUtil.d.ts.map +0 -1
  42. package/lib/AcCmStringUtil.js +0 -58
  43. package/lib/AcCmStringUtil.js.map +0 -1
  44. package/lib/AcCmTaskScheduler.d.ts +0 -186
  45. package/lib/AcCmTaskScheduler.d.ts.map +0 -1
  46. package/lib/AcCmTaskScheduler.js +0 -253
  47. package/lib/AcCmTaskScheduler.js.map +0 -1
  48. package/lib/index.d.ts +0 -12
  49. package/lib/index.d.ts.map +0 -1
  50. package/lib/index.js +0 -12
  51. package/lib/index.js.map +0 -1
  52. package/lib/loader/AcCmFileLoader.d.ts +0 -95
  53. package/lib/loader/AcCmFileLoader.d.ts.map +0 -1
  54. package/lib/loader/AcCmFileLoader.js +0 -275
  55. package/lib/loader/AcCmFileLoader.js.map +0 -1
  56. package/lib/loader/AcCmLoader.d.ts +0 -125
  57. package/lib/loader/AcCmLoader.d.ts.map +0 -1
  58. package/lib/loader/AcCmLoader.js +0 -116
  59. package/lib/loader/AcCmLoader.js.map +0 -1
  60. package/lib/loader/AcCmLoadingManager.d.ts +0 -166
  61. package/lib/loader/AcCmLoadingManager.d.ts.map +0 -1
  62. package/lib/loader/AcCmLoadingManager.js +0 -172
  63. package/lib/loader/AcCmLoadingManager.js.map +0 -1
  64. package/lib/loader/index.d.ts +0 -3
  65. package/lib/loader/index.d.ts.map +0 -1
  66. package/lib/loader/index.js +0 -3
  67. package/lib/loader/index.js.map +0 -1
@@ -1,44 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,58 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,186 +0,0 @@
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
- * @param {unknown} error - The error that was thrown.
111
- * @param {number} taskIndex - Index of the failed task in the task queue.
112
- * @param {AcCmTask<unknown, unknown>} task - The task that failed.
113
- */
114
- type AcCmErrorCallback = (error: AcCmTaskError) => void;
115
- /**
116
- * Type-safe task scheduler that executes a chain of named tasks in order.
117
- *
118
- * The scheduler passes results between tasks, reports progress, and stops
119
- * execution on the first failure. Supports both synchronous and asynchronous tasks.
120
- *
121
- * @template TInitial - Initial input type for the first task.
122
- * @template TFinal - Final output type from the last task.
123
- *
124
- * @example
125
- * ```typescript
126
- * // Create scheduler with string input and object output
127
- * const scheduler = new AcCmTaskScheduler<string, ParsedData>()
128
- *
129
- * // Add tasks
130
- * scheduler.addTask(new LoadFileTask())
131
- * scheduler.addTask(new ParseDataTask())
132
- * scheduler.addTask(new ValidateDataTask())
133
- *
134
- * // Set callbacks
135
- * scheduler.setProgressCallback((progress, task) => {
136
- * console.log(`${task.name}: ${(progress * 100).toFixed(1)}%`)
137
- * })
138
- *
139
- * scheduler.setCompleteCallback((result) => {
140
- * console.log('All tasks completed:', result)
141
- * })
142
- *
143
- * // Execute
144
- * await scheduler.execute('file.dwg')
145
- * ```
146
- */
147
- export declare class AcCmTaskScheduler<TInitial, TFinal = TInitial> {
148
- private tasks;
149
- private onProgress;
150
- private onComplete;
151
- private onError;
152
- /**
153
- * Schedules a task to be executed asynchronously.
154
- *
155
- * This method uses requestAnimationFrame in browser environments or setTimeout
156
- * in Node.js environments to schedule the task.
157
- *
158
- * @param callback - The callback function to schedule
159
- * @returns Promise that resolves with the result of the callback
160
- */
161
- private scheduleTask;
162
- /**
163
- * Adds a task to the execution queue.
164
- *
165
- * @param task Task instance with name and run function
166
- */
167
- addTask<TIn, TOut>(task: AcCmTask<TIn, TOut>): void;
168
- /**
169
- * Sets a callback to receive progress updates.
170
- */
171
- setProgressCallback(callback: AcCmProgressCallback): void;
172
- /**
173
- * Sets a callback to be called after successful completion of all tasks.
174
- */
175
- setCompleteCallback(callback: AcCmCompleteCallback<TFinal>): void;
176
- /**
177
- * Sets a callback to be called if any task throws an error.
178
- */
179
- setErrorCallback(callback: AcCmErrorCallback): void;
180
- /**
181
- * Starts execution of the task queue with the given initial input.
182
- */
183
- run(initialData: TInitial): Promise<void>;
184
- }
185
- export {};
186
- //# sourceMappingURL=AcCmTaskScheduler.d.ts.map
@@ -1 +0,0 @@
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,IAAI;IAC7B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;OAIG;gBACS,IAAI,EAAE,MAAM;IAIxB;;;;;;;;;OASG;IACH,GAAG,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAGvC;AAED;;;;;GAKG;AACH,KAAK,oBAAoB,GAAG,CAC1B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,KAC7B,IAAI,CAAA;AAET;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,IAAI,CAAA;AAE9D;;;;;;GAMG;AACH,KAAK,iBAAiB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ;IACxD,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,UAAU,CAAyC;IAC3D,OAAO,CAAC,OAAO,CAA8B;IAE7C;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;IAoBpB;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI;IAInD;;OAEG;IACH,mBAAmB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI;IAIzD;;OAEG;IACH,mBAAmB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG,IAAI;IAIjE;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAInD;;OAEG;IACG,GAAG,CAAC,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBhD"}
@@ -1,253 +0,0 @@
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 () { };
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;
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
- this_1.onError({ error: error_1, taskIndex: i, task: task });
224
- return [2 /*return*/, { value: void 0 }];
225
- case 4: return [2 /*return*/];
226
- }
227
- });
228
- };
229
- this_1 = this;
230
- i = 0;
231
- _a.label = 1;
232
- case 1:
233
- if (!(i < total)) return [3 /*break*/, 4];
234
- return [5 /*yield**/, _loop_1(i)];
235
- case 2:
236
- state_1 = _a.sent();
237
- if (typeof state_1 === "object")
238
- return [2 /*return*/, state_1.value];
239
- _a.label = 3;
240
- case 3:
241
- i++;
242
- return [3 /*break*/, 1];
243
- case 4:
244
- this.onComplete(result);
245
- return [2 /*return*/];
246
- }
247
- });
248
- });
249
- };
250
- return AcCmTaskScheduler;
251
- }());
252
- export { AcCmTaskScheduler };
253
- //# sourceMappingURL=AcCmTaskScheduler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AcCmTaskScheduler.js","sourceRoot":"","sources":["../src/AcCmTaskScheduler.ts"],"names":[],"mappings":"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"}
package/lib/index.d.ts DELETED
@@ -1,12 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,12 +0,0 @@
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
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
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"}