@mlightcad/common 1.0.0

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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/dist/common.js +1226 -0
  3. package/dist/common.umd.cjs +1 -0
  4. package/lib/AcCmColor.d.ts +42 -0
  5. package/lib/AcCmColor.d.ts.map +1 -0
  6. package/lib/AcCmColor.js +456 -0
  7. package/lib/AcCmColor.js.map +1 -0
  8. package/lib/AcCmColorUtil.d.ts +9 -0
  9. package/lib/AcCmColorUtil.d.ts.map +1 -0
  10. package/lib/AcCmColorUtil.js +54 -0
  11. package/lib/AcCmColorUtil.js.map +1 -0
  12. package/lib/AcCmErrors.d.ts +23 -0
  13. package/lib/AcCmErrors.d.ts.map +1 -0
  14. package/lib/AcCmErrors.js +37 -0
  15. package/lib/AcCmErrors.js.map +1 -0
  16. package/lib/AcCmEventDispatcher.d.ts +48 -0
  17. package/lib/AcCmEventDispatcher.d.ts.map +1 -0
  18. package/lib/AcCmEventDispatcher.js +60 -0
  19. package/lib/AcCmEventDispatcher.js.map +1 -0
  20. package/lib/AcCmEventManager.d.ts +27 -0
  21. package/lib/AcCmEventManager.d.ts.map +1 -0
  22. package/lib/AcCmEventManager.js +94 -0
  23. package/lib/AcCmEventManager.js.map +1 -0
  24. package/lib/AcCmLogUtil.d.ts +31 -0
  25. package/lib/AcCmLogUtil.d.ts.map +1 -0
  26. package/lib/AcCmLogUtil.js +23 -0
  27. package/lib/AcCmLogUtil.js.map +1 -0
  28. package/lib/AcCmObject.d.ts +96 -0
  29. package/lib/AcCmObject.d.ts.map +1 -0
  30. package/lib/AcCmObject.js +175 -0
  31. package/lib/AcCmObject.js.map +1 -0
  32. package/lib/AcCmPerformanceCollector.d.ts +68 -0
  33. package/lib/AcCmPerformanceCollector.d.ts.map +1 -0
  34. package/lib/AcCmPerformanceCollector.js +110 -0
  35. package/lib/AcCmPerformanceCollector.js.map +1 -0
  36. package/lib/AcCmStringUtil.d.ts +11 -0
  37. package/lib/AcCmStringUtil.d.ts.map +1 -0
  38. package/lib/AcCmStringUtil.js +25 -0
  39. package/lib/AcCmStringUtil.js.map +1 -0
  40. package/lib/AcCmTaskScheduler.d.ts +70 -0
  41. package/lib/AcCmTaskScheduler.d.ts.map +1 -0
  42. package/lib/AcCmTaskScheduler.js +173 -0
  43. package/lib/AcCmTaskScheduler.js.map +1 -0
  44. package/lib/index.d.ts +11 -0
  45. package/lib/index.d.ts.map +1 -0
  46. package/lib/index.js +11 -0
  47. package/lib/index.js.map +1 -0
  48. package/lib/loader/AcCmFileLoader.d.ts +58 -0
  49. package/lib/loader/AcCmFileLoader.d.ts.map +1 -0
  50. package/lib/loader/AcCmFileLoader.js +225 -0
  51. package/lib/loader/AcCmFileLoader.js.map +1 -0
  52. package/lib/loader/AcCmLoader.d.ts +92 -0
  53. package/lib/loader/AcCmLoader.d.ts.map +1 -0
  54. package/lib/loader/AcCmLoader.js +88 -0
  55. package/lib/loader/AcCmLoader.js.map +1 -0
  56. package/lib/loader/AcCmLoadingManager.d.ts +119 -0
  57. package/lib/loader/AcCmLoadingManager.d.ts.map +1 -0
  58. package/lib/loader/AcCmLoadingManager.js +133 -0
  59. package/lib/loader/AcCmLoadingManager.js.map +1 -0
  60. package/lib/loader/index.d.ts +3 -0
  61. package/lib/loader/index.d.ts.map +1 -0
  62. package/lib/loader/index.js +3 -0
  63. package/lib/loader/index.js.map +1 -0
  64. package/package.json +44 -0
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Handles and keeps track of loaded and pending data. A default global instance of this class is
3
+ * created and used by loaders if not supplied manually. In general that should be sufficient,
4
+ * however there are times when it can be useful to have separate loaders - for example if you want
5
+ * to show separate loading bars for objects and textures.
6
+ */
7
+ var AcCmLoadingManager = /** @class */ (function () {
8
+ /**
9
+ * Create a new AcCmLoadingManager instance
10
+ * @param onLoad this function will be called when all loaders are done.
11
+ * @param onProgress this function will be called when an item is complete.
12
+ * @param onError this function will be called a loader encounters errors.
13
+ */
14
+ function AcCmLoadingManager(onLoad, onProgress, onError) {
15
+ this.isLoading = false;
16
+ this.itemsLoaded = 0;
17
+ this.itemsTotal = 0;
18
+ this.urlModifier = undefined;
19
+ this.handlers = [];
20
+ // Refer to #5689 for the reason why we don't set .onStart
21
+ // in the constructor
22
+ this.onStart = undefined;
23
+ this.onLoad = onLoad;
24
+ this.onProgress = onProgress;
25
+ this.onError = onError;
26
+ }
27
+ /**
28
+ * This should be called by any loader using the manager when the loader starts loading an url.
29
+ * @param url The loaded url
30
+ */
31
+ AcCmLoadingManager.prototype.itemStart = function (url) {
32
+ this.itemsTotal++;
33
+ if (this.isLoading === false) {
34
+ if (this.onStart !== undefined) {
35
+ this.onStart(url, this.itemsLoaded, this.itemsTotal);
36
+ }
37
+ }
38
+ this.isLoading = true;
39
+ };
40
+ /**
41
+ * This should be called by any loader using the manager when the loader ended loading an url.
42
+ * @param url The loaded url
43
+ */
44
+ AcCmLoadingManager.prototype.itemEnd = function (url) {
45
+ this.itemsLoaded++;
46
+ if (this.onProgress !== undefined) {
47
+ this.onProgress(url, this.itemsLoaded, this.itemsTotal);
48
+ }
49
+ if (this.itemsLoaded === this.itemsTotal) {
50
+ this.isLoading = false;
51
+ if (this.onLoad !== undefined) {
52
+ this.onLoad();
53
+ }
54
+ }
55
+ };
56
+ /**
57
+ * This should be called by any loader using the manager when the loader errors loading an url.
58
+ * @param url The loaded url
59
+ */
60
+ AcCmLoadingManager.prototype.itemError = function (url) {
61
+ if (this.onError !== undefined) {
62
+ this.onError(url);
63
+ }
64
+ };
65
+ /**
66
+ * Given a URL, uses the URL modifier callback (if any) and returns a resolved URL. If no URL
67
+ * modifier is set, returns the original URL.
68
+ * @param url The url to load
69
+ * @returns Return resolved URL
70
+ */
71
+ AcCmLoadingManager.prototype.resolveURL = function (url) {
72
+ if (this.urlModifier) {
73
+ return this.urlModifier(url);
74
+ }
75
+ return url;
76
+ };
77
+ /**
78
+ * If provided, the callback will be passed each resource URL before a request is sent. The callback
79
+ * may return the original URL, or a new URL to override loading behavior. This behavior can be used
80
+ * to load assets from .ZIP files, drag-and-drop APIs, and Data URIs.
81
+ * @param transform URL modifier callback. Called with url argument, and must return resolvedURL.
82
+ * @returns Return this object
83
+ */
84
+ AcCmLoadingManager.prototype.setURLModifier = function (transform) {
85
+ this.urlModifier = transform;
86
+ return this;
87
+ };
88
+ /**
89
+ * Register a loader with the given regular expression. Can be used to define what loader should
90
+ * be used in order to load specific files. A typical use case is to overwrite the default loader
91
+ * for textures.
92
+ * @param regex A regular expression.
93
+ * @param loader The loader.
94
+ * @returns Return this object
95
+ */
96
+ AcCmLoadingManager.prototype.addHandler = function (regex, loader) {
97
+ this.handlers.push(regex, loader);
98
+ return this;
99
+ };
100
+ /**
101
+ * Remove the loader for the given regular expression.
102
+ * @param regex A regular expression.
103
+ * @returns Return this object
104
+ */
105
+ AcCmLoadingManager.prototype.removeHandler = function (regex) {
106
+ var index = this.handlers.indexOf(regex);
107
+ if (index !== -1) {
108
+ this.handlers.splice(index, 2);
109
+ }
110
+ return this;
111
+ };
112
+ /**
113
+ * Retrieve the registered loader for the given file path.
114
+ * @param file The file path.
115
+ * @returns Return the registered loader for the given file path.
116
+ */
117
+ AcCmLoadingManager.prototype.getHandler = function (file) {
118
+ for (var i = 0, l = this.handlers.length; i < l; i += 2) {
119
+ var regex = this.handlers[i];
120
+ var loader = this.handlers[i + 1];
121
+ if (regex.global)
122
+ regex.lastIndex = 0; // see #17920
123
+ if (regex.test(file)) {
124
+ return loader;
125
+ }
126
+ }
127
+ return null;
128
+ };
129
+ return AcCmLoadingManager;
130
+ }());
131
+ export { AcCmLoadingManager };
132
+ export var DefaultLoadingManager = /*@__PURE__*/ new AcCmLoadingManager();
133
+ //# sourceMappingURL=AcCmLoadingManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AcCmLoadingManager.js","sourceRoot":"","sources":["../../src/loader/AcCmLoadingManager.ts"],"names":[],"mappings":"AA2CA;;;;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CAAC,EAAE,CAAC;YACxD,IAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAW,CAAA;YACxC,IAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;YAEnC,IAAI,KAAK,CAAC,MAAM;gBAAE,KAAK,CAAC,SAAS,GAAG,CAAC,CAAA,CAAC,aAAa;YAEnD,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,OAAO,MAAM,CAAA;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IACH,yBAAC;AAAD,CAAC,AA1KD,IA0KC;;AAED,MAAM,CAAC,IAAM,qBAAqB,GAAG,aAAa,CAAC,IAAI,kBAAkB,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './AcCmLoadingManager';
2
+ export * from './AcCmLoader';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loader/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,cAAc,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './AcCmLoadingManager';
2
+ export * from './AcCmLoader';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/loader/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,cAAc,CAAA"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@mlightcad/common",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "keywords": [
6
+ "autocad",
7
+ "cad",
8
+ "dwg",
9
+ "dxf",
10
+ "mlight",
11
+ "mlightcad",
12
+ "objecarx",
13
+ "realdwg"
14
+ ],
15
+ "files": [
16
+ "dist",
17
+ "lib",
18
+ "README.md",
19
+ "package.json"
20
+ ],
21
+ "main": "./dist/common.umd.cjs",
22
+ "module": "./dist/common.js",
23
+ "types": "./lib/index.d.ts",
24
+ "exports": {
25
+ "types": "./lib/index.d.ts",
26
+ "import": "./dist/common.js",
27
+ "require": "./dist/common.umd.cjs"
28
+ },
29
+ "devDependencies": {
30
+ "@types/lodash-es": "^4.17.12"
31
+ },
32
+ "dependencies": {
33
+ "loglevel": "^1.9.1"
34
+ },
35
+ "peerDependencies": {
36
+ "lodash-es": "*"
37
+ },
38
+ "scripts": {
39
+ "clean": "rimraf dist lib tsconfig.tsbuildinfo",
40
+ "build": "tsc && vite build",
41
+ "lint": "eslint src/",
42
+ "lint:fix": "eslint --fix --quiet src/"
43
+ }
44
+ }