UNPKG

@mlightcad/common

Version:

The common package provides shared utilities and base classes that are used across the RealDWG-Web ecosystem. This package contains fundamental components for color management, event handling, logging, performance monitoring, and file loading operations.

1,280 lines (1,279 loc) 32.9 kB
function H(n, e) { for (var t = 0; t < e.length; t++) { const r = e[t]; if (typeof r != "string" && !Array.isArray(r)) { for (const o in r) if (o !== "default" && !(o in n)) { const i = Object.getOwnPropertyDescriptor(r, o); i && Object.defineProperty(n, o, i.get ? i : { enumerable: !0, get: () => r[o] }); } } } return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" })); } const I = { aliceblue: 15792383, antiquewhite: 16444375, aqua: 65535, aquamarine: 8388564, azure: 15794175, beige: 16119260, bisque: 16770244, black: 0, blanchedalmond: 16772045, blue: 255, blueviolet: 9055202, brown: 10824234, burlywood: 14596231, cadetblue: 6266528, chartreuse: 8388352, chocolate: 13789470, coral: 16744272, cornflowerblue: 6591981, cornsilk: 16775388, crimson: 14423100, cyan: 65535, darkblue: 139, darkcyan: 35723, darkgoldenrod: 12092939, darkgray: 11119017, darkgreen: 25600, darkkhaki: 12433259, darkmagenta: 9109643, darkolivegreen: 5597999, darkorange: 16747520, darkorchid: 10040012, darkred: 9109504, darksalmon: 15308410, darkseagreen: 9419919, darkslateblue: 4734347, darkslategray: 3100495, darkturquoise: 52945, darkviolet: 9699539, deeppink: 16716947, deepskyblue: 49151, dimgrey: 6908265, dodgerblue: 2003199, firebrick: 11674146, floralwhite: 16775920, forestgreen: 2263842, fuchsia: 16711935, gainsboro: 14474460, ghostwhite: 16316671, gold: 16766720, goldenrod: 14329120, gray: 8421504, green: 32768, greenyellow: 11403055, grey: 8421504, honeydew: 15794160, hotpink: 16738740, indianred: 13458524, indigo: 4915330, ivory: 16777200, khaki: 15787660, lavender: 15132410, lavenderblush: 16773365, lawngreen: 8190976, lemonchiffon: 16775885, lightblue: 11393254, lightcoral: 15761536, lightcyan: 14745599, lightgoldenrodyellow: 16448210, lightgray: 13882323, lightgreen: 9498256, lightgrey: 13882323, lightpink: 16758465, lightsalmon: 16752762, lightseagreen: 2142890, lightskyblue: 8900346, lightslategray: 7833753, lightslategrey: 7833753, lightsteelblue: 11584734, lightyellow: 16777184, lime: 65280, limegreen: 3329330, linen: 16445670, magenta: 16711935, maroon: 8388608, mediumaquamarine: 6737322, mediumblue: 205, mediumorchid: 12211667, mediumpurple: 9662683, mediumseagreen: 3978097, mediumslateblue: 8087790, mediumspringgreen: 64154, mediumturquoise: 4772300, mediumvioletred: 13047173, midnightblue: 1644912, mintcream: 16121850, mistyrose: 16770273, moccasin: 16770229, navajowhite: 16768685, navy: 128, oldlace: 16643558, olive: 8421376, olivedrab: 7048739, orange: 16753920, orangered: 16729344, orchid: 14315734, palegoldenrod: 15657130, palegreen: 10025880, paleturquoise: 11529966, palevioletred: 14381203, papayawhip: 16773077, peachpuff: 16767673, peru: 13468991, pink: 16761035, plum: 14524637, powderblue: 11591910, purple: 8388736, rebeccapurple: 6697881, red: 16711680, rosybrown: 12357519, royalblue: 4286945, saddlebrown: 9127187, salmon: 16416882, sandybrown: 16032864, seagreen: 3050327, seashell: 16774638, sienna: 10506797, silver: 12632256, skyblue: 8900331, slateblue: 6970061, slategrey: 7372944, snow: 16775930, springgreen: 65407, steelblue: 4620980, tan: 13808780, teal: 32896, thistle: 14204888, tomato: 16737095, turquoise: 4251856, violet: 15631086, wheat: 16113331, white: 16777215, whitesmoke: 16119285, yellow: 16776960, yellowgreen: 10145074 }, T = [ 0, 16711680, 16776960, 65280, 65535, 255, 16711935, 16777215, 8421504, 12632256, 16711680, 16744319, 13369344, 13395558, 10027008, 10046540, 8323072, 8339263, 4980736, 4990502, 16727808, 16752511, 13382400, 13401958, 10036736, 10051404, 8331008, 8343359, 4985600, 4992806, 16744192, 16760703, 13395456, 13408614, 10046464, 10056268, 8339200, 8347455, 4990464, 4995366, 16760576, 16768895, 13408512, 13415014, 10056192, 10061132, 8347392, 8351551, 4995328, 4997670, 16776960, 16777087, 13421568, 13421670, 10000384, 10000460, 8355584, 8355647, 5000192, 5000230, 12582656, 14679935, 10079232, 11717734, 7510016, 8755276, 6258432, 7307071, 3755008, 4344870, 8388352, 12582783, 6736896, 10079334, 5019648, 7510092, 4161280, 6258495, 2509824, 3755046, 4194048, 10485631, 3394560, 8375398, 2529280, 6264908, 2064128, 5209919, 1264640, 3099686, 65280, 8388479, 52224, 6736998, 38912, 5019724, 32512, 4161343, 19456, 2509862, 65343, 8388511, 52275, 6737023, 38950, 5019743, 32543, 4161359, 19475, 2509871, 65407, 8388543, 52326, 6737049, 38988, 5019762, 32575, 4161375, 19494, 2509881, 65471, 8388575, 52377, 6737074, 39026, 5019781, 32607, 4161391, 19513, 2509890, 65535, 8388607, 52428, 6737100, 39064, 5019800, 32639, 4161407, 19532, 2509900, 49151, 8380415, 39372, 6730444, 29336, 5014936, 24447, 4157311, 14668, 2507340, 32767, 8372223, 26316, 6724044, 19608, 5010072, 16255, 4153215, 9804, 2505036, 16383, 8364031, 13260, 6717388, 9880, 5005208, 8063, 4149119, 4940, 2502476, 255, 8355839, 204, 6710988, 152, 5000344, 127, 4145023, 76, 2500172, 4129023, 10452991, 3342540, 8349388, 2490520, 6245528, 2031743, 5193599, 1245260, 3089996, 8323327, 12550143, 6684876, 10053324, 4980888, 7490712, 4128895, 6242175, 2490444, 3745356, 12517631, 14647295, 10027212, 11691724, 7471256, 8735896, 6226047, 7290751, 3735628, 4335180, 16711935, 16744447, 13369548, 13395660, 9961624, 9981080, 8323199, 8339327, 4980812, 4990540, 16711871, 16744415, 13369497, 13395634, 9961586, 9981061, 8323167, 8339311, 4980793, 4990530, 16711807, 16744383, 13369446, 13395609, 9961548, 9981042, 8323135, 8339295, 4980774, 4990521, 16711743, 16744351, 13369395, 13395583, 9961510, 9981023, 8323103, 8339279, 4980755, 4990511, 3355443, 5987163, 8684676, 11382189, 14079702, 16777215, 0 ]; function b(n, e, t) { return Math.max(e, Math.min(t, n)); } const O = class O { constructor() { this._colorIndex = 256, this._color = null, this._colorName = null; } get color() { return this._color; } set color(e) { e == null ? this._color = null : (this._color = Math.round(b(e, 0, 256 * 256 * 256 - 1)), this._colorIndex = this.getColorIndexByValue(this._color), this._colorName = this.getColorNameByValue(this._color)); } get hexColor() { if (this._color && this._color > 0 && this._color <= 16777215) { let e = this._color.toString(16).toUpperCase(); for (; e.length < 6; ) e = "0" + e; return `0x${e}`; } return ""; } get cssColor() { return `rgb(${this.red},${this.green},${this.blue})`; } get red() { return this.color ? this.color >> 16 & 255 : null; } get green() { return this.color ? this.color >> 8 & 255 : null; } get blue() { return this.color ? this.color & 255 : null; } /** * AutoCAD color index value. The index value will be in the range 0 to 256. 0 and 256 are special values. * If value less than 0 is set, 0 will be used. If value greater than 256 is set, 256 will be used. * - 0 indicates that the entity uses the color of the BlockReference that's displaying it. If the entity * is not displayed through a block reference (for example, it is directly owned by the model space * block table record) and its color is 0, then it will display as though its color were 7. * - 256 indicates that the entity uses the color specified in the layer table record it references. */ get colorIndex() { return this._colorIndex; } set colorIndex(e) { e == null ? this._colorIndex = null : (this._colorIndex = b(e, 0, 256), this._color = T[e], this._colorName = this.getColorNameByValue(this._color)); } get colorName() { return this._colorName; } set colorName(e) { if (e) { const t = I[e.toLowerCase()]; t !== void 0 ? (this._colorName = e, this._color = t, this._colorIndex = this.getColorIndexByValue(this._color)) : console.warn("Unknown color: " + e); } else this._colorName = null; } get hasColorName() { return this._colorName == null; } get hasColorIndex() { return this._colorIndex == null; } get isByLayer() { return this.colorIndex == 256; } setByLayer() { return this.colorIndex = 256, this; } get isByBlock() { return this.colorIndex == 0; } setByBlock() { return this.colorIndex = 0, this; } setScalar(e) { return this.setRGB(e, e, e), this; } setRGB(e, t, r) { const o = Math.round(b(e, 0, 255)), i = Math.round(b(t, 0, 255)), l = Math.round(b(r, 0, 255)); return this.color = (o << 16) + (i << 8) + l, this; } setColorName(e) { const t = I[e.toLowerCase()]; return t !== void 0 ? this.color = t : console.warn("Unknown color " + e), this; } clone() { const e = new O(); return e.colorIndex = this.colorIndex, e.color = this.color, e._colorName = this._colorName, this; } copy(e) { return this.colorIndex = e.colorIndex, this.color = e.color, this._colorName = e._colorName, this; } equals(e) { return e.color == this.color && e.colorIndex == this.colorIndex && e._colorName == this._colorName; } toString() { return this.isByLayer ? "ByLayer" : this.isByBlock ? "ByBlock" : this.colorName ? this.colorName : this.hexColor; } getColorNameByValue(e) { for (const [t, r] of Object.entries(I)) if (r === e) return t; return null; } getColorIndexByValue(e) { const t = T.length - 1; for (let r = 1; r < t; ++r) if (T[r] === e) return r; return null; } }; O.NAMES = I; let R = O; const te = { /** * Throw error ILLEGAL_PARAMETERS when cannot instantiate from given parameter */ get ILLEGAL_PARAMETERS() { return new ReferenceError("Illegal Parameters"); }, /** * Throw error ZERO_DIVISION to catch situation of zero division */ get ZERO_DIVISION() { return new Error("Zero division"); }, /** * Error to throw from BooleanOperations module in case when fixBoundaryConflicts not capable to fix it */ get UNRESOLVED_BOUNDARY_CONFLICT() { return new Error("Unresolved boundary conflict in boolean operation"); }, /** * Error to throw from LinkedList:testInfiniteLoop static method * in case when circular loop detected in linked list */ get INFINITE_LOOP() { return new Error("Infinite loop"); }, get CANNOT_INVOKE_ABSTRACT_METHOD() { return new Error("Abstract method cannot be invoked"); }, get OPERATION_IS_NOT_SUPPORTED() { return new Error("Operation is not supported"); }, get NOT_IMPLEMENTED() { return new Error("Not implemented yet"); } }; class re { /** * Creates {@link AcCmEventDispatcher} object. */ constructor() { this._listeners = {}; } addEventListener(e, t) { this._listeners === void 0 && (this._listeners = {}); const r = this._listeners; r[e] === void 0 && (r[e] = []), r[e].indexOf(t) === -1 && r[e].push(t); } hasEventListener(e, t) { if (this._listeners === void 0) return !1; const r = this._listeners; return r[e] !== void 0 && r[e].indexOf(t) !== -1; } removeEventListener(e, t) { if (this._listeners === void 0) return; const o = this._listeners[e]; if (o !== void 0) { const i = o.indexOf(t); i !== -1 && o.splice(i, 1); } } /** * Fire an event type. * @param event The event that gets fired. */ dispatchEvent(e) { if (this._listeners === void 0) return; const r = this._listeners[e.type]; if (r !== void 0) { e.target = this; const o = r.slice(0); for (let i = 0, l = o.length; i < l; i++) o[i].call(this, e); } } } class U { constructor() { this.listeners = []; } /** * Add the event listener * @param listener Input listener to be added */ addEventListener(e) { this.listeners.push(e); } /** * Remove the listener * @param listener Input listener to be removed */ removeEventListener(e) { this.listeners = this.listeners.filter((t) => t !== e); } /** * Remove all listeners bound to the target and add one new listener * @param listener Input listener to be added */ replaceEventListener(e) { this.removeEventListener(e), this.addEventListener(e); } /** * Notify all listeners * @param payload Input payload passed to listener */ dispatch(e, ...t) { for (const r of this.listeners) r.call(null, e, ...t); } } var K = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function z(n) { return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n; } var D = { exports: {} }; (function(n) { (function(e, t) { n.exports ? n.exports = t() : e.log = t(); })(K, function() { var e = function() { }, t = "undefined", r = typeof window !== t && typeof window.navigator !== t && /Trident\/|MSIE /.test(window.navigator.userAgent), o = [ "trace", "debug", "info", "warn", "error" ], i = {}, l = null; function g(a, h) { var s = a[h]; if (typeof s.bind == "function") return s.bind(a); try { return Function.prototype.bind.call(s, a); } catch { return function() { return Function.prototype.apply.apply(s, [a, arguments]); }; } } function p() { console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace(); } function m(a) { return a === "debug" && (a = "log"), typeof console === t ? !1 : a === "trace" && r ? p : console[a] !== void 0 ? g(console, a) : console.log !== void 0 ? g(console, "log") : e; } function y() { for (var a = this.getLevel(), h = 0; h < o.length; h++) { var s = o[h]; this[s] = h < a ? e : this.methodFactory(s, a, this.name); } if (this.log = this.debug, typeof console === t && a < this.levels.SILENT) return "No console available for logging"; } function x(a) { return function() { typeof console !== t && (y.call(this), this[a].apply(this, arguments)); }; } function d(a, h, s) { return m(a) || x.apply(this, arguments); } function M(a, h) { var s = this, E, N, v, f = "loglevel"; typeof a == "string" ? f += ":" + a : typeof a == "symbol" && (f = void 0); function V(c) { var u = (o[c] || "silent").toUpperCase(); if (!(typeof window === t || !f)) { try { window.localStorage[f] = u; return; } catch { } try { window.document.cookie = encodeURIComponent(f) + "=" + u + ";"; } catch { } } } function B() { var c; if (!(typeof window === t || !f)) { try { c = window.localStorage[f]; } catch { } if (typeof c === t) try { var u = window.document.cookie, k = encodeURIComponent(f), P = u.indexOf(k + "="); P !== -1 && (c = /^([^;]+)/.exec( u.slice(P + k.length + 1) )[1]); } catch { } return s.levels[c] === void 0 && (c = void 0), c; } } function $() { if (!(typeof window === t || !f)) { try { window.localStorage.removeItem(f); } catch { } try { window.document.cookie = encodeURIComponent(f) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; } catch { } } } function w(c) { var u = c; if (typeof u == "string" && s.levels[u.toUpperCase()] !== void 0 && (u = s.levels[u.toUpperCase()]), typeof u == "number" && u >= 0 && u <= s.levels.SILENT) return u; throw new TypeError("log.setLevel() called with invalid level: " + c); } s.name = a, s.levels = { TRACE: 0, DEBUG: 1, INFO: 2, WARN: 3, ERROR: 4, SILENT: 5 }, s.methodFactory = h || d, s.getLevel = function() { return v ?? N ?? E; }, s.setLevel = function(c, u) { return v = w(c), u !== !1 && V(v), y.call(s); }, s.setDefaultLevel = function(c) { N = w(c), B() || s.setLevel(c, !1); }, s.resetLevel = function() { v = null, $(), y.call(s); }, s.enableAll = function(c) { s.setLevel(s.levels.TRACE, c); }, s.disableAll = function(c) { s.setLevel(s.levels.SILENT, c); }, s.rebuild = function() { if (l !== s && (E = w(l.getLevel())), y.call(s), l === s) for (var c in i) i[c].rebuild(); }, E = w( l ? l.getLevel() : "WARN" ); var S = B(); S != null && (v = w(S)), y.call(s); } l = new M(), l.getLogger = function(h) { if (typeof h != "symbol" && typeof h != "string" || h === "") throw new TypeError("You must supply a name when creating a logger."); var s = i[h]; return s || (s = i[h] = new M( h, l.methodFactory )), s; }; var j = typeof window !== t ? window.log : void 0; return l.noConflict = function() { return typeof window !== t && window.log === l && (window.log = j), l; }, l.getLoggers = function() { return i; }, l.default = l, l; }); })(D); var q = D.exports; const W = /* @__PURE__ */ z(q), Y = /* @__PURE__ */ H({ __proto__: null, default: W }, [q]), ne = !0, C = Y; C.setLevel("debug"); const oe = (n) => { try { C.setLevel(n); } catch (e) { C.setLevel("error"), C.error(e); } }; function A(n) { return n === null || typeof n != "object" ? n : Array.isArray(n) ? [...n] : { ...n }; } function Z(n, ...e) { for (const t of e) if (t) for (const r in t) Object.prototype.hasOwnProperty.call(t, r) && n[r] === void 0 && (n[r] = t[r]); return n; } function J(n, e) { return n != null && Object.prototype.hasOwnProperty.call(n, e); } function X(n) { return n == null ? !0 : Array.isArray(n) || typeof n == "string" ? n.length === 0 : n instanceof Map || n instanceof Set ? n.size === 0 : typeof n == "object" ? Object.keys(n).length === 0 : !1; } function L(n, e) { if (n === e) return !0; if (n == null || e == null) return n === e; if (typeof n != typeof e) return !1; if (typeof n != "object") return n === e; if (Array.isArray(n) !== Array.isArray(e)) return !1; if (Array.isArray(n)) { if (n.length !== e.length) return !1; for (let o = 0; o < n.length; o++) if (!L(n[o], e[o])) return !1; return !0; } const t = Object.keys(n), r = Object.keys(e); if (t.length !== r.length) return !1; for (const o of t) if (!Object.prototype.hasOwnProperty.call( e, o ) || !L( n[o], e[o] )) return !1; return !0; } class F { /** * Create one object to store attributes. For performance reason, values of attributes passed to constructor * will not be cloned to `attributes` property. So it means that value of `attributes` property in this object * is just a reference to arguments `attributes` passed to constructor. * @param attributes Input attributes to store in this object */ constructor(e, t) { this.events = { attrChanged: new U(), modelChanged: new U() }, this._changing = !1, this._previousAttributes = {}, this._pending = !1; const r = e || {}; t && Z(r, t), this.attributes = r, this.changed = {}; } /** * For strongly-typed access to attributes, use the `get` method only privately in public getter properties. * @example * get name(): string { * return super.get("name") * } */ get(e) { return this.attributes[e]; } set(e, t, r) { if (e == null) return this; let o; typeof e == "object" ? (o = e, r = t) : (o = {}, o[e] = t), r || (r = {}); const i = r.unset, l = r.silent, g = [], p = this._changing; this._changing = !0, p || (this._previousAttributes = A(this.attributes), this.changed = {}); const m = this.attributes, y = this.changed, x = this._previousAttributes; for (const d in o) t = o[d], L(m[d], t) || g.push(d), L(x[d], t) ? delete y[d] : y[d] = t, i ? delete m[d] : m[d] = t; if (!l) { g.length && (this._pending = r); for (let d = 0; d < g.length; d++) this.events.attrChanged.dispatch({ object: this, attrName: g[d], attrValue: m[g[d]], options: r }); } if (p) return this; if (!l) for (; this._pending; ) r = this._pending, this._pending = !1, this.events.modelChanged.dispatch({ object: this, options: r }); return this._pending = !1, this._changing = !1, this; } has(e) { return this.get(e) != null; } /** * Determine if the model has changed since the last `"change"` event. * If you specify an attribute name, determine if that attribute has changed. */ hasChanged(e) { return e == null ? !X(this.changed) : J(this.changed, e); } /** * Return an object containing all the attributes that have changed. Useful for determining what parts * of a view need to be updated and/or what attributes need to be persisted to the server. * * Unset attributes will be set to undefined. You can also pass an attributes object to diff against * the model, determining if there *would be* a change. */ changedAttributes(e) { if (!e) return this.hasChanged() ? A(this.changed) : {}; const t = this._changing ? this._previousAttributes : this.attributes, r = {}; for (const o in e) { const i = e[o]; L(t[o], i) || (r[o] = i); } return r; } /** * Get the previous value of an attribute, recorded at the time the last `"change"` event was fired. */ previous(e) { return e == null || !this._previousAttributes ? null : this._previousAttributes[e]; } /** * Get all of the attributes of the model at the time of the previous `"change"` event. */ previousAttributes() { return A(this._previousAttributes); } /** * Create a new model with identical attributes to this one. */ clone() { const e = A(this.attributes); return new F(e); } } class _ { /** * Private constructor to enforce singleton pattern. */ constructor() { this.entries = /* @__PURE__ */ new Map(); } /** * Retrieves the singleton instance of the AcCmPerformanceCollector. * @returns The shared AcCmPerformanceCollector instance. */ static getInstance() { return _.instance || (_.instance = new _()), _.instance; } /** * Adds or replaces a performance entry by name. * @template T The type of the performance data. * @param entry A performance entry object with name, data, and format method. */ collect(e) { this.entries.set(e.name, e); } /** * Logs all performance entries to the console using their format method. */ printAll() { for (const [e, t] of this.entries) console.log(`${e}:`), console.log(t.format()); } /** * Clears all collected performance entries. */ clear() { this.entries.clear(); } /** * Retrieves all entries as an array. * @returns A copy of all performance entries. */ getAll() { return Array.from(this.entries.values()); } /** * Gets a single entry by name. * @param name The unique name of the entry. * @returns The matching entry or undefined. */ getEntry(e) { return this.entries.get(e); } /** * Removes an entry by name. * @param name The name of the entry to remove. * @returns True if the entry was removed; false if not found. */ remove(e) { return this.entries.delete(e); } } class se { /** * Converts a byte count to a human-readable string using KB, MB, or GB. * * @param bytes - The number of bytes. * @param decimals - Number of decimal places to include (default is 2). * @returns A formatted string with the appropriate unit. */ static formatBytes(e, t = 2) { if (e === 0) return "0 B"; const r = 1024, o = Math.max(0, t), i = ["B", "KB", "MB", "GB", "TB"], l = Math.floor(Math.log(e) / Math.log(r)), g = e / Math.pow(r, l); return `${parseFloat(g.toFixed(o))} ${i[l]}`; } } class ie { constructor(e) { this.name = e; } /** * Executes the task. */ run(e) { throw new Error("run() must be implemented by subclass"); } } class le { constructor() { this.tasks = [], this.onProgress = () => { }, this.onComplete = () => { }, this.onError = () => { }; } /** * Adds a task to the execution queue. * * @param task Task instance with name and run function */ addTask(e) { this.tasks.push(e); } /** * Sets a callback to receive progress updates. */ setProgressCallback(e) { this.onProgress = e; } /** * Sets a callback to be called after successful completion of all tasks. */ setCompleteCallback(e) { this.onComplete = e; } /** * Sets a callback to be called if any task throws an error. */ setErrorCallback(e) { this.onError = e; } /** * Starts execution of the task queue with the given initial input. */ async run(e) { const t = this.tasks.length; let r = e; for (let o = 0; o < t; o++) { const i = this.tasks[o]; try { r = await new Promise((l, g) => { setTimeout(async () => { try { const p = await i.run(r); this.onProgress((o + 1) / t, i), l(p); } catch (p) { g(p); } }, 0); }); } catch (l) { this.onError(l, o, i); return; } } this.onComplete(r); } } class Q { /** * Create a new AcCmLoadingManager instance * @param onLoad this function will be called when all loaders are done. * @param onProgress this function will be called when an item is complete. * @param onError this function will be called a loader encounters errors. */ constructor(e, t, r) { this.isLoading = !1, this.itemsLoaded = 0, this.itemsTotal = 0, this.urlModifier = void 0, this.handlers = [], this.onStart = void 0, this.onLoad = e, this.onProgress = t, this.onError = r; } /** * This should be called by any loader using the manager when the loader starts loading an url. * @param url The loaded url */ itemStart(e) { this.itemsTotal++, this.isLoading === !1 && this.onStart !== void 0 && this.onStart(e, this.itemsLoaded, this.itemsTotal), this.isLoading = !0; } /** * This should be called by any loader using the manager when the loader ended loading an url. * @param url The loaded url */ itemEnd(e) { this.itemsLoaded++, this.onProgress !== void 0 && this.onProgress(e, this.itemsLoaded, this.itemsTotal), this.itemsLoaded === this.itemsTotal && (this.isLoading = !1, this.onLoad !== void 0 && this.onLoad()); } /** * This should be called by any loader using the manager when the loader errors loading an url. * @param url The loaded url */ itemError(e) { this.onError !== void 0 && this.onError(e); } /** * Given a URL, uses the URL modifier callback (if any) and returns a resolved URL. If no URL * modifier is set, returns the original URL. * @param url The url to load * @returns Return resolved URL */ resolveURL(e) { return this.urlModifier ? this.urlModifier(e) : e; } /** * If provided, the callback will be passed each resource URL before a request is sent. The callback * may return the original URL, or a new URL to override loading behavior. This behavior can be used * to load assets from .ZIP files, drag-and-drop APIs, and Data URIs. * @param transform URL modifier callback. Called with url argument, and must return resolvedURL. * @returns Return this object */ setURLModifier(e) { return this.urlModifier = e, this; } /** * Register a loader with the given regular expression. Can be used to define what loader should * be used in order to load specific files. A typical use case is to overwrite the default loader * for textures. * @param regex A regular expression. * @param loader The loader. * @returns Return this object */ addHandler(e, t) { return this.handlers.push(e, t), this; } /** * Remove the loader for the given regular expression. * @param regex A regular expression. * @returns Return this object */ removeHandler(e) { const t = this.handlers.indexOf(e); return t !== -1 && this.handlers.splice(t, 2), this; } /** * Retrieve the registered loader for the given file path. * @param file The file path. * @returns Return the registered loader for the given file path. */ getHandler(e) { for (let t = 0, r = this.handlers.length; t < r; t += 2) { const o = this.handlers[t], i = this.handlers[t + 1]; if (o.global && (o.lastIndex = 0), o.test(e)) return i; } return null; } } const ee = /* @__PURE__ */ new Q(); class ae { /** * Creates a new AcCmLoader instance. * @param manager The loadingManager for the loader to use. Default is DefaultLoadingManager. */ constructor(e) { this.manager = e !== void 0 ? e : ee, this.crossOrigin = "anonymous", this.withCredentials = !1, this.path = "", this.resourcePath = "", this.requestHeader = {}; } /** * This method is equivalent to 'load', but returns a Promise. * @param url A string containing the path/URL of the file to be loaded. * @param onProgress (optional) — A function to be called while the loading is in progress. * The argument will be the ProgressEvent instance, which contains .lengthComputable, .total * and .loaded. If the server does not set the Content-Length header; .total will be 0. * @returns Return a promise. */ loadAsync(e, t) { return new Promise((r, o) => { this.load(e, r, t, o); }); } /** * This method needs to be implement by all concrete loaders. It holds the logic for parsing the asset. */ parse(e) { } /** * Set the crossOrigin string to implement CORS for loading the url from a different domain that allows * CORS. * @param crossOrigin The crossOrigin string * @returns Return this object */ setCrossOrigin(e) { return this.crossOrigin = e, this; } /** * Set whether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS * client certificates. * Note that this has no effect if you are loading files locally or from the same domain. * @param value The flag whether the XMLHttpRequest uses credentials. * @returns Return this object */ setWithCredentials(e) { return this.withCredentials = e, this; } /** * Set the base path for the asset. * @param path The base path for the asset. * @returns Return this object */ setPath(e) { return this.path = e, this; } /** * Set the base path for dependent resources like textures. * @param resourcePath The base path for dependent resources like textures. * @returns Return this object */ setResourcePath(e) { return this.resourcePath = e, this; } /** * Set the request header used in HTTP request. * @param requestHeader key: The name of the header whose value is to be set. value: The value * to set as the body of the header. * @returns Return this object */ setRequestHeader(e) { return this.requestHeader = e, this; } } export { R as AcCmColor, te as AcCmErrors, re as AcCmEventDispatcher, U as AcCmEventManager, ae as AcCmLoader, Q as AcCmLoadingManager, F as AcCmObject, _ as AcCmPerformanceCollector, ie as AcCmTask, le as AcCmTaskScheduler, se as AcTrStringUtil, ne as DEBUG_MODE, ee as DefaultLoadingManager, A as clone, Z as defaults, J as has, X as isEmpty, L as isEqual, C as log, oe as setLogLevel };