This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

69
node_modules/pixi.js/lib/utils/pool/Pool.d.ts generated vendored Normal file
View File

@@ -0,0 +1,69 @@
/**
* A generic class for managing a pool of items.
* @template T The type of items in the pool. Must implement {@link utils.PoolItem}.
* @memberof utils
*/
export declare class Pool<T extends PoolItem> {
readonly _classType: PoolItemConstructor<T>;
private readonly _pool;
private _count;
private _index;
/**
* Constructs a new Pool.
* @param ClassType - The constructor of the items in the pool.
* @param {number} [initialSize] - The initial size of the pool.
*/
constructor(ClassType: PoolItemConstructor<T>, initialSize?: number);
/**
* Prepopulates the pool with a given number of items.
* @param total - The number of items to add to the pool.
*/
prepopulate(total: number): void;
/**
* Gets an item from the pool. Calls the item's `init` method if it exists.
* If there are no items left in the pool, a new one will be created.
* @param {unknown} [data] - Optional data to pass to the item's constructor.
* @returns {T} The item from the pool.
*/
get(data?: unknown): T;
/**
* Returns an item to the pool. Calls the item's `reset` method if it exists.
* @param {T} item - The item to return to the pool.
*/
return(item: T): void;
/**
* Gets the number of items in the pool.
* @readonly
* @member {number}
*/
get totalSize(): number;
/**
* Gets the number of items in the pool that are free to use without needing to create more.
* @readonly
* @member {number}
*/
get totalFree(): number;
/**
* Gets the number of items in the pool that are currently in use.
* @readonly
* @member {number}
*/
get totalUsed(): number;
/** clears the pool - mainly used for debugging! */
clear(): void;
}
/**
* An object that can be stored in a {@link utils.Pool}.
* @memberof utils
*/
export type PoolItem = {
init?: (data?: any) => void;
reset?: () => void;
[key: string]: any;
};
/**
* The constructor of an object that can be stored in a {@link utils.Pool}.
* @typeParam K - The type of the object that can be stored in a {@link utils.Pool}.
* @memberof utils
*/
export type PoolItemConstructor<K extends PoolItem> = new () => K;

85
node_modules/pixi.js/lib/utils/pool/Pool.js generated vendored Normal file
View File

@@ -0,0 +1,85 @@
'use strict';
"use strict";
class Pool {
/**
* Constructs a new Pool.
* @param ClassType - The constructor of the items in the pool.
* @param {number} [initialSize] - The initial size of the pool.
*/
constructor(ClassType, initialSize) {
this._pool = [];
this._count = 0;
this._index = 0;
this._classType = ClassType;
if (initialSize) {
this.prepopulate(initialSize);
}
}
/**
* Prepopulates the pool with a given number of items.
* @param total - The number of items to add to the pool.
*/
prepopulate(total) {
for (let i = 0; i < total; i++) {
this._pool[this._index++] = new this._classType();
}
this._count += total;
}
/**
* Gets an item from the pool. Calls the item's `init` method if it exists.
* If there are no items left in the pool, a new one will be created.
* @param {unknown} [data] - Optional data to pass to the item's constructor.
* @returns {T} The item from the pool.
*/
get(data) {
let item;
if (this._index > 0) {
item = this._pool[--this._index];
} else {
item = new this._classType();
}
item.init?.(data);
return item;
}
/**
* Returns an item to the pool. Calls the item's `reset` method if it exists.
* @param {T} item - The item to return to the pool.
*/
return(item) {
item.reset?.();
this._pool[this._index++] = item;
}
/**
* Gets the number of items in the pool.
* @readonly
* @member {number}
*/
get totalSize() {
return this._count;
}
/**
* Gets the number of items in the pool that are free to use without needing to create more.
* @readonly
* @member {number}
*/
get totalFree() {
return this._index;
}
/**
* Gets the number of items in the pool that are currently in use.
* @readonly
* @member {number}
*/
get totalUsed() {
return this._count - this._index;
}
/** clears the pool - mainly used for debugging! */
clear() {
this._pool.length = 0;
this._index = 0;
}
}
exports.Pool = Pool;
//# sourceMappingURL=Pool.js.map

1
node_modules/pixi.js/lib/utils/pool/Pool.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Pool.js","sources":["../../../src/utils/pool/Pool.ts"],"sourcesContent":["/**\n * A generic class for managing a pool of items.\n * @template T The type of items in the pool. Must implement {@link utils.PoolItem}.\n * @memberof utils\n */\nexport class Pool<T extends PoolItem>\n{\n public readonly _classType: PoolItemConstructor<T>;\n private readonly _pool: T[] = [];\n private _count = 0;\n private _index = 0;\n\n /**\n * Constructs a new Pool.\n * @param ClassType - The constructor of the items in the pool.\n * @param {number} [initialSize] - The initial size of the pool.\n */\n constructor(ClassType: PoolItemConstructor<T>, initialSize?: number)\n {\n this._classType = ClassType;\n\n if (initialSize)\n {\n this.prepopulate(initialSize);\n }\n }\n\n /**\n * Prepopulates the pool with a given number of items.\n * @param total - The number of items to add to the pool.\n */\n public prepopulate(total: number): void\n {\n for (let i = 0; i < total; i++)\n {\n this._pool[this._index++] = new this._classType();\n }\n\n this._count += total;\n }\n\n /**\n * Gets an item from the pool. Calls the item's `init` method if it exists.\n * If there are no items left in the pool, a new one will be created.\n * @param {unknown} [data] - Optional data to pass to the item's constructor.\n * @returns {T} The item from the pool.\n */\n public get(data?: unknown): T\n {\n let item;\n\n if (this._index > 0)\n {\n item = this._pool[--this._index];\n }\n else\n {\n item = new this._classType();\n }\n\n item.init?.(data);\n\n return item;\n }\n\n /**\n * Returns an item to the pool. Calls the item's `reset` method if it exists.\n * @param {T} item - The item to return to the pool.\n */\n public return(item: T): void\n {\n item.reset?.();\n\n this._pool[this._index++] = item;\n }\n\n /**\n * Gets the number of items in the pool.\n * @readonly\n * @member {number}\n */\n get totalSize(): number\n {\n return this._count;\n }\n\n /**\n * Gets the number of items in the pool that are free to use without needing to create more.\n * @readonly\n * @member {number}\n */\n get totalFree(): number\n {\n return this._index;\n }\n\n /**\n * Gets the number of items in the pool that are currently in use.\n * @readonly\n * @member {number}\n */\n get totalUsed(): number\n {\n return this._count - this._index;\n }\n\n /** clears the pool - mainly used for debugging! */\n public clear()\n {\n this._pool.length = 0;\n this._index = 0;\n }\n}\n\n/**\n * An object that can be stored in a {@link utils.Pool}.\n * @memberof utils\n */\nexport type PoolItem = {\n init?: (data?: any) => void;\n reset?: () => void;\n [key: string]: any;\n};\n\n/**\n * The constructor of an object that can be stored in a {@link utils.Pool}.\n * @typeParam K - The type of the object that can be stored in a {@link utils.Pool}.\n * @memberof utils\n */\nexport type PoolItemConstructor<K extends PoolItem> = new () => K;\n"],"names":[],"mappings":";;;AAKO,MAAM,IACb,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWI,WAA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;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,SACJ,GAAA;AACI,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,SACJ,GAAA;AACI,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,SACJ,GAAA;AACI,IAAO,OAAA,IAAA,CAAK,SAAS,IAAK,CAAA,MAAA,CAAA;AAAA,GAC9B;AAAA;AAAA,EAGO,KACP,GAAA;AACI,IAAA,IAAA,CAAK,MAAM,MAAS,GAAA,CAAA,CAAA;AACpB,IAAA,IAAA,CAAK,MAAS,GAAA,CAAA,CAAA;AAAA,GAClB;AACJ;;;;"}

83
node_modules/pixi.js/lib/utils/pool/Pool.mjs generated vendored Normal file
View File

@@ -0,0 +1,83 @@
"use strict";
class Pool {
/**
* Constructs a new Pool.
* @param ClassType - The constructor of the items in the pool.
* @param {number} [initialSize] - The initial size of the pool.
*/
constructor(ClassType, initialSize) {
this._pool = [];
this._count = 0;
this._index = 0;
this._classType = ClassType;
if (initialSize) {
this.prepopulate(initialSize);
}
}
/**
* Prepopulates the pool with a given number of items.
* @param total - The number of items to add to the pool.
*/
prepopulate(total) {
for (let i = 0; i < total; i++) {
this._pool[this._index++] = new this._classType();
}
this._count += total;
}
/**
* Gets an item from the pool. Calls the item's `init` method if it exists.
* If there are no items left in the pool, a new one will be created.
* @param {unknown} [data] - Optional data to pass to the item's constructor.
* @returns {T} The item from the pool.
*/
get(data) {
let item;
if (this._index > 0) {
item = this._pool[--this._index];
} else {
item = new this._classType();
}
item.init?.(data);
return item;
}
/**
* Returns an item to the pool. Calls the item's `reset` method if it exists.
* @param {T} item - The item to return to the pool.
*/
return(item) {
item.reset?.();
this._pool[this._index++] = item;
}
/**
* Gets the number of items in the pool.
* @readonly
* @member {number}
*/
get totalSize() {
return this._count;
}
/**
* Gets the number of items in the pool that are free to use without needing to create more.
* @readonly
* @member {number}
*/
get totalFree() {
return this._index;
}
/**
* Gets the number of items in the pool that are currently in use.
* @readonly
* @member {number}
*/
get totalUsed() {
return this._count - this._index;
}
/** clears the pool - mainly used for debugging! */
clear() {
this._pool.length = 0;
this._index = 0;
}
}
export { Pool };
//# sourceMappingURL=Pool.mjs.map

1
node_modules/pixi.js/lib/utils/pool/Pool.mjs.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Pool.mjs","sources":["../../../src/utils/pool/Pool.ts"],"sourcesContent":["/**\n * A generic class for managing a pool of items.\n * @template T The type of items in the pool. Must implement {@link utils.PoolItem}.\n * @memberof utils\n */\nexport class Pool<T extends PoolItem>\n{\n public readonly _classType: PoolItemConstructor<T>;\n private readonly _pool: T[] = [];\n private _count = 0;\n private _index = 0;\n\n /**\n * Constructs a new Pool.\n * @param ClassType - The constructor of the items in the pool.\n * @param {number} [initialSize] - The initial size of the pool.\n */\n constructor(ClassType: PoolItemConstructor<T>, initialSize?: number)\n {\n this._classType = ClassType;\n\n if (initialSize)\n {\n this.prepopulate(initialSize);\n }\n }\n\n /**\n * Prepopulates the pool with a given number of items.\n * @param total - The number of items to add to the pool.\n */\n public prepopulate(total: number): void\n {\n for (let i = 0; i < total; i++)\n {\n this._pool[this._index++] = new this._classType();\n }\n\n this._count += total;\n }\n\n /**\n * Gets an item from the pool. Calls the item's `init` method if it exists.\n * If there are no items left in the pool, a new one will be created.\n * @param {unknown} [data] - Optional data to pass to the item's constructor.\n * @returns {T} The item from the pool.\n */\n public get(data?: unknown): T\n {\n let item;\n\n if (this._index > 0)\n {\n item = this._pool[--this._index];\n }\n else\n {\n item = new this._classType();\n }\n\n item.init?.(data);\n\n return item;\n }\n\n /**\n * Returns an item to the pool. Calls the item's `reset` method if it exists.\n * @param {T} item - The item to return to the pool.\n */\n public return(item: T): void\n {\n item.reset?.();\n\n this._pool[this._index++] = item;\n }\n\n /**\n * Gets the number of items in the pool.\n * @readonly\n * @member {number}\n */\n get totalSize(): number\n {\n return this._count;\n }\n\n /**\n * Gets the number of items in the pool that are free to use without needing to create more.\n * @readonly\n * @member {number}\n */\n get totalFree(): number\n {\n return this._index;\n }\n\n /**\n * Gets the number of items in the pool that are currently in use.\n * @readonly\n * @member {number}\n */\n get totalUsed(): number\n {\n return this._count - this._index;\n }\n\n /** clears the pool - mainly used for debugging! */\n public clear()\n {\n this._pool.length = 0;\n this._index = 0;\n }\n}\n\n/**\n * An object that can be stored in a {@link utils.Pool}.\n * @memberof utils\n */\nexport type PoolItem = {\n init?: (data?: any) => void;\n reset?: () => void;\n [key: string]: any;\n};\n\n/**\n * The constructor of an object that can be stored in a {@link utils.Pool}.\n * @typeParam K - The type of the object that can be stored in a {@link utils.Pool}.\n * @memberof utils\n */\nexport type PoolItemConstructor<K extends PoolItem> = new () => K;\n"],"names":[],"mappings":";AAKO,MAAM,IACb,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWI,WAAA,CAAY,WAAmC,WAC/C,EAAA;AAVA,IAAA,IAAA,CAAiB,QAAa,EAAC,CAAA;AAC/B,IAAA,IAAA,CAAQ,MAAS,GAAA,CAAA,CAAA;AACjB,IAAA,IAAA,CAAQ,MAAS,GAAA,CAAA,CAAA;AASb,IAAA,IAAA,CAAK,UAAa,GAAA,SAAA,CAAA;AAElB,IAAA,IAAI,WACJ,EAAA;AACI,MAAA,IAAA,CAAK,YAAY,WAAW,CAAA,CAAA;AAAA,KAChC;AAAA,GACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,YAAY,KACnB,EAAA;AACI,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,KAAA,EAAO,CAC3B,EAAA,EAAA;AACI,MAAA,IAAA,CAAK,MAAM,IAAK,CAAA,MAAA,EAAQ,CAAI,GAAA,IAAI,KAAK,UAAW,EAAA,CAAA;AAAA,KACpD;AAEA,IAAA,IAAA,CAAK,MAAU,IAAA,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, PoolItemConstructor } from './Pool';
/**
* A type alias for a constructor of a Pool.
* @template T The type of items in the pool. Must extend PoolItem.
* @memberof utils
*/
export type PoolConstructor<T extends PoolItem> = new () => Pool<T>;
/**
* A group of pools that can be used to store objects of different types.
* @memberof utils
*/
export declare class PoolGroupClass {
/**
* A map to store the pools by their class type.
* @private
*/
private readonly _poolsByClass;
/**
* Prepopulates a specific pool with a given number of items.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.
* @param {number} total - The number of items to add to the pool.
*/
prepopulate<T extends PoolItem>(Class: PoolItemConstructor<T>, total: number): void;
/**
* Gets an item from a specific pool.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.
* @param {unknown} [data] - Optional data to pass to the item's constructor.
* @returns {T} The item from the pool.
*/
get<T extends PoolItem>(Class: PoolItemConstructor<T>, data?: unknown): T;
/**
* Returns an item to its respective pool.
* @param {PoolItem} item - The item to return to the pool.
*/
return(item: PoolItem): void;
/**
* Gets a specific pool based on the class type.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} ClassType - The constructor of the items in the pool.
* @returns {Pool<T>} The pool of the given class type.
*/
getPool<T extends PoolItem>(ClassType: PoolItemConstructor<T>): Pool<T>;
/** gets the usage stats of each pool in the system */
stats(): Record<string, {
free: number;
used: number;
size: number;
}>;
}
export declare const BigPool: PoolGroupClass;

73
node_modules/pixi.js/lib/utils/pool/PoolGroup.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
'use strict';
var Pool = require('./Pool.js');
"use strict";
class PoolGroupClass {
constructor() {
/**
* A map to store the pools by their class type.
* @private
*/
this._poolsByClass = /* @__PURE__ */ new Map();
}
/**
* Prepopulates a specific pool with a given number of items.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.
* @param {number} total - The number of items to add to the pool.
*/
prepopulate(Class, total) {
const classPool = this.getPool(Class);
classPool.prepopulate(total);
}
/**
* Gets an item from a specific pool.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.
* @param {unknown} [data] - Optional data to pass to the item's constructor.
* @returns {T} The item from the pool.
*/
get(Class, data) {
const pool = this.getPool(Class);
return pool.get(data);
}
/**
* Returns an item to its respective pool.
* @param {PoolItem} item - The item to return to the pool.
*/
return(item) {
const pool = this.getPool(item.constructor);
pool.return(item);
}
/**
* Gets a specific pool based on the class type.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} ClassType - The constructor of the items in the pool.
* @returns {Pool<T>} The pool of the given class type.
*/
getPool(ClassType) {
if (!this._poolsByClass.has(ClassType)) {
this._poolsByClass.set(ClassType, new Pool.Pool(ClassType));
}
return this._poolsByClass.get(ClassType);
}
/** gets the usage stats of each pool in the system */
stats() {
const stats = {};
this._poolsByClass.forEach((pool) => {
const name = stats[pool._classType.name] ? pool._classType.name + pool._classType.ID : pool._classType.name;
stats[name] = {
free: pool.totalFree,
used: pool.totalUsed,
size: pool.totalSize
};
});
return stats;
}
}
const BigPool = new PoolGroupClass();
exports.BigPool = BigPool;
exports.PoolGroupClass = PoolGroupClass;
//# sourceMappingURL=PoolGroup.js.map

1
node_modules/pixi.js/lib/utils/pool/PoolGroup.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

70
node_modules/pixi.js/lib/utils/pool/PoolGroup.mjs generated vendored Normal file
View File

@@ -0,0 +1,70 @@
import { Pool } from './Pool.mjs';
"use strict";
class PoolGroupClass {
constructor() {
/**
* A map to store the pools by their class type.
* @private
*/
this._poolsByClass = /* @__PURE__ */ new Map();
}
/**
* Prepopulates a specific pool with a given number of items.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.
* @param {number} total - The number of items to add to the pool.
*/
prepopulate(Class, total) {
const classPool = this.getPool(Class);
classPool.prepopulate(total);
}
/**
* Gets an item from a specific pool.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.
* @param {unknown} [data] - Optional data to pass to the item's constructor.
* @returns {T} The item from the pool.
*/
get(Class, data) {
const pool = this.getPool(Class);
return pool.get(data);
}
/**
* Returns an item to its respective pool.
* @param {PoolItem} item - The item to return to the pool.
*/
return(item) {
const pool = this.getPool(item.constructor);
pool.return(item);
}
/**
* Gets a specific pool based on the class type.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} ClassType - The constructor of the items in the pool.
* @returns {Pool<T>} The pool of the given class type.
*/
getPool(ClassType) {
if (!this._poolsByClass.has(ClassType)) {
this._poolsByClass.set(ClassType, new Pool(ClassType));
}
return this._poolsByClass.get(ClassType);
}
/** gets the usage stats of each pool in the system */
stats() {
const stats = {};
this._poolsByClass.forEach((pool) => {
const name = stats[pool._classType.name] ? pool._classType.name + pool._classType.ID : pool._classType.name;
stats[name] = {
free: pool.totalFree,
used: pool.totalUsed,
size: pool.totalSize
};
});
return stats;
}
}
const BigPool = new PoolGroupClass();
export { BigPool, PoolGroupClass };
//# sourceMappingURL=PoolGroup.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"PoolGroup.mjs","sources":["../../../src/utils/pool/PoolGroup.ts"],"sourcesContent":["import { Pool } from './Pool';\n\nimport type { PoolItem, PoolItemConstructor } from './Pool';\n\n/**\n * A type alias for a constructor of a Pool.\n * @template T The type of items in the pool. Must extend PoolItem.\n * @memberof utils\n */\nexport type PoolConstructor<T extends PoolItem> = new () => Pool<T>;\n\n/**\n * A group of pools that can be used to store objects of different types.\n * @memberof utils\n */\nexport class PoolGroupClass\n{\n /**\n * A map to store the pools by their class type.\n * @private\n */\n private readonly _poolsByClass: Map<PoolItemConstructor<PoolItem>, Pool<PoolItem>> = new Map();\n\n /**\n * Prepopulates a specific pool with a given number of items.\n * @template T The type of items in the pool. Must extend PoolItem.\n * @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.\n * @param {number} total - The number of items to add to the pool.\n */\n public prepopulate<T extends PoolItem>(Class: PoolItemConstructor<T>, total: number): void\n {\n const classPool = this.getPool(Class);\n\n classPool.prepopulate(total);\n }\n\n /**\n * Gets an item from a specific pool.\n * @template T The type of items in the pool. Must extend PoolItem.\n * @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.\n * @param {unknown} [data] - Optional data to pass to the item's constructor.\n * @returns {T} The item from the pool.\n */\n public get<T extends PoolItem>(Class: PoolItemConstructor<T>, data?: unknown): T\n {\n const pool = this.getPool(Class);\n\n return pool.get(data) as T;\n }\n\n /**\n * Returns an item to its respective pool.\n * @param {PoolItem} item - The item to return to the pool.\n */\n public return(item: PoolItem): void\n {\n const pool = this.getPool(item.constructor as PoolItemConstructor<PoolItem>);\n\n pool.return(item);\n }\n\n /**\n * Gets a specific pool based on the class type.\n * @template T The type of items in the pool. Must extend PoolItem.\n * @param {PoolItemConstructor<T>} ClassType - The constructor of the items in the pool.\n * @returns {Pool<T>} The pool of the given class type.\n */\n public getPool<T extends PoolItem>(ClassType: PoolItemConstructor<T>): Pool<T>\n {\n if (!this._poolsByClass.has(ClassType))\n {\n this._poolsByClass.set(ClassType, new Pool(ClassType));\n }\n\n return this._poolsByClass.get(ClassType) as Pool<T>;\n }\n\n /** gets the usage stats of each pool in the system */\n public stats(): Record<string, {free: number; used: number; size: number}>\n {\n const stats = {} as Record<string, {free: number; used: number; size: number}>;\n\n this._poolsByClass.forEach((pool) =>\n {\n // TODO: maybe we should allow the name to be set when `createEntity` is called\n const name = stats[pool._classType.name]\n ? pool._classType.name + (pool._classType as any).ID : pool._classType.name;\n\n stats[name] = {\n free: pool.totalFree,\n used: pool.totalUsed,\n size: pool.totalSize,\n };\n });\n\n return stats;\n }\n}\n\nexport const BigPool = new PoolGroupClass();\n"],"names":[],"mappings":";;;AAeO,MAAM,cACb,CAAA;AAAA,EADO,WAAA,GAAA;AAMH;AAAA;AAAA;AAAA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