bc-deeplib 1.1.1 → 1.1.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.
package/dist/deeplib.d.ts CHANGED
@@ -1,15 +1,82 @@
1
1
  declare module 'bc-deeplib/base/base_module' {
2
2
  import { BaseSettingsModel, Subscreen } from 'bc-deeplib/deeplib';
3
+ /**
4
+ * An abstract foundation for modular systems that require:
5
+ * - Optional settings screens
6
+ * - Persistent settings storage per module
7
+ * - Default settings registration
8
+ * - Lifecycle hooks for loading, running, and unloading
9
+ *
10
+ * ### Responsibilities
11
+ * This class defines the base contract for all modules in the system:
12
+ * - Provides a standardized interface for retrieving and storing settings
13
+ * - Ensures default settings are registered if missing
14
+ * - Integrates with the module storage system (`modStorage`)
15
+ * - Offers overridable lifecycle methods (`init`, `load`, `run`, `unload`)
16
+ *
17
+ * **Subclass Requirements:**
18
+ * - Must extend `BaseModule`
19
+ * - Should override `defaultSettings` to define defaults for its settings, if any
20
+ * - May override `settingsScreen` to provide a UI component
21
+ * - May override lifecycle methods as needed
22
+ */
3
23
  export abstract class BaseModule {
24
+ /**
25
+ * An optional UI screen for configuring this module's settings.
26
+ * Subclasses can override this getter to provide a `Subscreen` instance.
27
+ * Modules with screens are automatically registered to the main menu.
28
+ */
4
29
  get settingsScreen(): Subscreen | null;
30
+ /**
31
+ * The storage key under which this module's settings will be saved.
32
+ * Defaults to the class name.
33
+ *
34
+ * Subclasses can override this if they require a custom storage key.
35
+ */
5
36
  get settingsStorage(): string | null;
37
+ /**
38
+ * Retrieves the current settings for this module.
39
+ * If no settings exist yet, registers default settings first.
40
+ */
6
41
  get settings(): BaseSettingsModel;
42
+ /**
43
+ * Persists new settings for this module.
44
+ * Automatically initializes storage and defaults if they don't exist.
45
+ */
7
46
  set settings(value: BaseSettingsModel);
47
+ /**
48
+ * Initializes the module.
49
+ * Default implementation registers default settings immediately.
50
+ * Subclasses can override to perform additional setup.
51
+ */
8
52
  init(): void;
53
+ /**
54
+ * Registers default settings for this module in persistent storage.
55
+ * Only runs if a storage key and default settings are defined.
56
+ *
57
+ * If some settings already exist, they will be merged with defaults.
58
+ * Existing values will NOT be overwritten.
59
+ */
9
60
  registerDefaultSettings(): void;
61
+ /**
62
+ * Provides default settings for this module.
63
+ * Subclasses should override this getter to return their defaults.
64
+ */
10
65
  get defaultSettings(): BaseSettingsModel | null;
66
+ /**
67
+ * Called when the module is loaded into the system.
68
+ * Subclasses should override to perform data loading or initialization.
69
+ */
11
70
  load(): void;
71
+ /**
72
+ * By default doesn't get called each frame, only once when the module is loaded.
73
+ * Subclasses can override to implement runtime logic.
74
+ */
12
75
  run(): void;
76
+ /**
77
+ * Called when the module is being removed.
78
+ * Subclasses can override to perform cleanup or save final state.
79
+ */
13
80
  unload(): void;
14
81
  }
15
82
 
@@ -17,33 +84,123 @@ declare module 'bc-deeplib/base/base_module' {
17
84
  declare module 'bc-deeplib/base/base_subscreen' {
18
85
  import { BaseModule, BaseSettingsModel } from 'bc-deeplib/deeplib';
19
86
  import { SettingElement } from 'bc-deeplib/base/elements_typings';
87
+ /** Optional configuration flags for a `BaseSubscreen` instance. */
20
88
  type SubscreenOptions = {
89
+ /**
90
+ * If `true`, the subscreen will draw the player's character model
91
+ * in the UI when `run()` is called.
92
+ * Also shift the UI to the right to make room for the character.
93
+ */
21
94
  drawCharacter?: boolean;
22
95
  };
96
+ /**
97
+ * Represents a constructor type for a subscreen.
98
+ * Allows dynamic instantiation of subscreen classes with optional
99
+ * configuration options and a parent module reference.
100
+ */
23
101
  export type Subscreen = new (subscreenOptions?: SubscreenOptions, module?: BaseModule) => BaseSubscreen;
24
- export function getCurrentSubscreen(): BaseSubscreen | null;
102
+ /** Switches the active subscreen in the global `GUI` instance. */
25
103
  export function setSubscreen(subscreen: BaseSubscreen | string | null): BaseSubscreen | null;
104
+ /**
105
+ * Abstract base class for creating settings/configuration subscreens in a module.
106
+ *
107
+ * ### Responsibilities
108
+ * This class defines the base contract for all modules in the system:
109
+ * - Provides a standardized interface for retrieving and storing settings
110
+ * - Ensures default settings are registered if missing
111
+ * - Integrates with the module storage system (`modStorage`)
112
+ * - Offers overridable lifecycle methods (`init`, `load`, `run`, `unload`)
113
+ *
114
+ * **Subclass Requirements:**
115
+ * - Must extend `BaseSubscreen`
116
+ * - Should override `name`, `icon` to define subscreen metadata
117
+ * - May override `pageStructure` to define UI layout and controls
118
+ * - May override lifecycle methods as needed
119
+ */
26
120
  export abstract class BaseSubscreen {
121
+ /** Global registry of currently rendered elements and their definitions. */
27
122
  static currentElements: [HTMLElement, SettingElement][];
123
+ /** Tracks the currently visible page number (1-based index). */
28
124
  static currentPage: number;
125
+ /** Runtime options for this subscreen. */
29
126
  readonly options: SubscreenOptions;
127
+ /** Reference to the module this subscreen belongs to. */
30
128
  readonly module: BaseModule;
31
129
  constructor(subscreenOptions?: SubscreenOptions, module?: BaseModule);
130
+ /**
131
+ * Logical name of this subscreen.
132
+ * Used for localization key resolution in `load()`.
133
+ * Subclasses should override this with a meaningful identifier.
134
+ */
32
135
  get name(): string;
136
+ /**
137
+ * Path to or Base64 data for an icon representing this subscreen.
138
+ * Defaults to empty string (no icon).
139
+ */
33
140
  get icon(): string;
34
- get subscreenName(): string;
141
+ /** Changes the currently active subscreen. */
35
142
  setSubscreen(screen: BaseSubscreen | string | null): BaseSubscreen | null;
143
+ /** Gets this subscreen's settings object from its parent module. */
36
144
  get settings(): BaseSettingsModel;
145
+ /** Updates this subscreen's settings in its parent module. */
37
146
  set settings(value: BaseSettingsModel);
147
+ /**
148
+ * Defines the paginated layout of the subscreen's settings UI.
149
+ * Each element in the outer array is a page; each page contains `SettingElement`s.
150
+ *
151
+ * Subclasses should override to define their actual UI structure.
152
+ */
38
153
  get pageStructure(): SettingElement[][];
154
+ /** Gets the currently visible page's settings elements. */
39
155
  get currentPage(): SettingElement[];
156
+ /**
157
+ * Changes the visible page in a multi-page subscreen.
158
+ * Automatically wraps around when going past the first or last page.
159
+ */
40
160
  changePage(page: number, setLabel: (label: string) => void): void;
161
+ /**
162
+ * Updates the DOM to show only elements belonging to the current page.
163
+ * All elements on other pages are hidden.
164
+ */
41
165
  managePageElementsVisibility(): void;
166
+ /**
167
+ * Called when this subscreen is first displayed.
168
+ * Builds the layout, initializes navigation, and renders all settings elements.
169
+ *
170
+ * Handles:
171
+ * - Ensuring each module with a settings screen has its defaults loaded
172
+ * - Creating navigation menus and back/next page controls
173
+ * - Building and appending UI elements based on `pageStructure`
174
+ * - Setting up exit button and tooltip
175
+ * - Resetting to page 1
176
+ */
42
177
  load(): void;
178
+ /**
179
+ * Called each frame while this subscreen is active.
180
+ * Default behavior draws the player's character if `drawCharacter` is enabled.
181
+ */
43
182
  run(): void;
183
+ /**
184
+ * Handles mouse clicks *on canvas* while the subscreen is active.
185
+ * Default implementation is empty — subclasses may override.
186
+ */
44
187
  click(): void;
188
+ /**
189
+ * Exits this subscreen, returning to the main menu.
190
+ * Also saves persistent storage changes.
191
+ * Called after the `unload`.
192
+ */
45
193
  exit(): void;
194
+ /**
195
+ * Called when the window is resized.
196
+ * Also checks for overflow in the settings div and applies styling accordingly.
197
+ */
46
198
  resize(onLoad?: boolean): void;
199
+ /**
200
+ * Called when this subscreen is being removed.
201
+ * Resets the static element registry and removes the subscreen from the layout.
202
+ * Called before `exit`.
203
+ */
47
204
  unload(): void;
48
205
  }
49
206
  export {};
@@ -101,33 +258,137 @@ declare module 'bc-deeplib/base/elements_typings' {
101
258
 
102
259
  }
103
260
  declare module 'bc-deeplib/base/initialization' {
104
- import { BaseModule, ModSdkManager, BaseMigrator, ModStorage, MainMenuOptions } from 'bc-deeplib/deeplib';
261
+ import { BaseModule, ModSdkManager, BaseMigrator, ModStorage, MainMenuOptions, TranslationOptions } from 'bc-deeplib/deeplib';
262
+ /** Configuration object for initializing a mod via `initMod`. */
105
263
  interface InitOptions {
264
+ /**
265
+ * Information about the mod being initialized.
266
+ * - `info` — Required metadata describing the mod.
267
+ * - `options` — Optional runtime configuration for the Mod SDK.
268
+ */
106
269
  modInfo: {
107
270
  info: ModSDKModInfo;
108
271
  options?: ModSDKModOptions;
109
272
  };
273
+ /**
274
+ * List of modules (`BaseModule` subclasses) to register with the mod system.
275
+ * Modules are initialized, loaded, and run in order.
276
+ */
110
277
  modules?: BaseModule[];
278
+ /**
279
+ * List of data migration handlers to register with the `VersionModule`.
280
+ * Each `BaseMigrator` handles upgrading data from one version to another.
281
+ */
111
282
  migrators?: BaseMigrator[];
283
+ /** Configuration for customizing the main menu when the mod is active. */
112
284
  mainMenuOptions?: MainMenuOptions;
285
+ /**
286
+ * Optional hook executed *before* login when the player is not yet authenticated.
287
+ * Useful for pre-login setup or display changes.
288
+ */
113
289
  beforeLogin?: () => (void);
290
+ /**
291
+ * Optional async/sync function run after modules and translations are initialized.
292
+ * Can be used to perform additional setup tasks.
293
+ */
114
294
  initFunction?: () => (void | Promise<void>);
115
- pathToTranslationsFolder?: string;
295
+ /** Options for initializing the localization/translation system. */
296
+ translationOptions?: TranslationOptions;
116
297
  }
298
+ /**
299
+ * Global storage handler for mod.
300
+ * Initialized by `initMod()` and mod data loaded by `init()`.
301
+ */
117
302
  export let modStorage: ModStorage;
303
+ /**
304
+ * Entry point for initializing a mod. Handles:
305
+ * - Setting up the Mod SDK
306
+ * - Preparing persistent storage
307
+ * - Injecting required styles
308
+ * - Delaying initialization until login (if necessary)
309
+ */
118
310
  export function initMod(options: InitOptions): {
119
311
  sdk: ModSdkManager;
120
312
  };
313
+ /**
314
+ * Fully initializes the mod after login.
315
+ * Handles:
316
+ * - Preventing double-load
317
+ * - Loading mod data
318
+ * - Initializing localization
319
+ * - Registering modules and migrators
320
+ * - Running optional init functions
321
+ * - Applying main menu changes
322
+ * - Merging default settings into module settings
323
+ *
324
+ * @param options {InitOptions} Configuration for mod initialization.
325
+ */
121
326
  export function init(options: InitOptions): Promise<void>;
327
+ /**
328
+ * Cleans up and removes the mod from memory.
329
+ * Calls `unload()` on all modules and removes the global loaded flag.
330
+ */
122
331
  export function unloadMod(): true;
123
332
  export {};
124
333
 
125
334
  }
126
335
  declare module 'bc-deeplib/base/modules' {
127
336
  import { BaseModule } from 'bc-deeplib/deeplib';
337
+ /**
338
+ * Global registry of all loaded modules, keyed by their class name.
339
+ *
340
+ * The map is populated via {@link registerModule} and accessed via {@link modules} or {@link getModule}.
341
+ * This is the central storage for active `BaseModule` instances during the mod lifecycle.
342
+ */
128
343
  export const modulesMap: Map<string, BaseModule>;
344
+ /**
345
+ * Retrieves all registered module instances.
346
+ *
347
+ * @returns An array containing every module currently stored in {@link modulesMap}.
348
+ *
349
+ * @remarks
350
+ * The returned array is a **shallow copy** of the `Map` values, meaning that
351
+ * changes to the array do not affect the registry itself.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * for (const mod of modules()) {
356
+ * mod.run();
357
+ * }
358
+ * ```
359
+ */
129
360
  export function modules(): BaseModule[];
361
+ /**
362
+ * Registers a module instance in the global registry.
363
+ *
364
+ * @returns The same module instance passed in, for chaining or immediate use.
365
+ *
366
+ * @remarks
367
+ * - If a module with the same constructor name already exists, it will be **overwritten**.
368
+ * - Keys are based on the class name (`module.constructor.name`), so name collisions are possible
369
+ * if two different classes share the same name.
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * registerModule(new MyGlobalModule());
374
+ * ```
375
+ */
130
376
  export function registerModule<T extends BaseModule>(module: T): T;
377
+ /**
378
+ * Retrieves a registered module by its type name.
379
+ *
380
+ * @returns The matching module instance cast to type `T`, or `undefined` if not found.
381
+ *
382
+ * @remarks
383
+ * This function does not perform runtime type checks. If the type parameter `T`
384
+ * does not match the actual module type, you may get runtime errors when using the result.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * const themeModule = getModule<ThemeModule>('ThemeModule');
389
+ * themeModule?.reloadTheme();
390
+ * ```
391
+ */
131
392
  export function getModule<T extends BaseModule>(moduleType: string): T;
132
393
 
133
394
  }
@@ -145,9 +406,9 @@ declare module 'bc-deeplib/deeplib' {
145
406
  export * from 'bc-deeplib/screens/main_menu';
146
407
  export * from 'bc-deeplib/screens/import_export';
147
408
  export * from 'bc-deeplib/utilities/data';
148
- export * from 'bc-deeplib/utilities/elements/advanced_elements';
149
- export * from 'bc-deeplib/utilities/elements/element_helpers';
150
- export * from 'bc-deeplib/utilities/elements/layout_elements';
409
+ export * from 'bc-deeplib/utilities/elements/elements';
410
+ export * from 'bc-deeplib/utilities/elements/helpers';
411
+ export * from 'bc-deeplib/utilities/elements/layout';
151
412
  export * from 'bc-deeplib/utilities/common';
152
413
  export * from 'bc-deeplib/utilities/logger';
153
414
  export * from 'bc-deeplib/utilities/messages';
@@ -157,15 +418,50 @@ declare module 'bc-deeplib/deeplib' {
157
418
 
158
419
  }
159
420
  declare module 'bc-deeplib/migrators/base_migrator' {
421
+ /**
422
+ * Abstract base class for versioned migration handlers.
423
+ *
424
+ * A migrator is responsible for upgrading or transforming stored data
425
+ * when the mod version changes. Each migrator targets a specific version
426
+ * and executes its {@link Migrate} method once when needed.
427
+ *
428
+ * @remarks
429
+ * To create a new migrator:
430
+ * 1. Extend `BaseMigrator`.
431
+ * 2. Implement the {@link MigrationVersion} getter to return the target version string.
432
+ * 3. Implement {@link Migrate} with the migration logic (e.g., data structure changes).
433
+ */
160
434
  export abstract class BaseMigrator {
435
+ /**
436
+ * Gets the target version string for this migration.
437
+ *
438
+ * @remarks
439
+ * - This should exactly match the version format used by the mod
440
+ * - Used by the migration system to determine if this migration should be executed.
441
+ */
161
442
  abstract get MigrationVersion(): string;
162
- abstract Migrate(): boolean;
443
+ /**
444
+ * Executes the migration logic for this version.
445
+ *
446
+ * @remarks
447
+ * - Called once when upgrading from a version earlier than {@link MigrationVersion}.
448
+ * - Should handle any necessary data transformations, cleanup, or initialization
449
+ * to bring the mod's state up to date with the new version.
450
+ * - Must be idempotent — running it multiple times should not cause data corruption.
451
+ */
452
+ abstract Migrate(): void;
163
453
  }
164
454
 
165
455
  }
166
456
  declare module 'bc-deeplib/models/base' {
457
+ /**
458
+ * Represents the base settings structure for a mod.
459
+ * Present for all mods.
460
+ */
167
461
  export type BaseSettingsModel = {
462
+ /** Whether the mod is currently active. */
168
463
  modEnabled: boolean;
464
+ /** Whether to display a notification when a new version is detected. */
169
465
  doShowNewVersionMessage: boolean;
170
466
  };
171
467
 
@@ -181,28 +477,69 @@ declare module 'bc-deeplib/models/settings' {
181
477
  }
182
478
  declare module 'bc-deeplib/modules/gui' {
183
479
  import { BaseModule, BaseSubscreen, MainMenu } from 'bc-deeplib/deeplib';
480
+ /** Options for configuring a mod's main button in the extensions menu. */
184
481
  type ModButtonOptions = {
482
+ /**
483
+ * Unique identifier for the mod's settings button.
484
+ * Used internally by the preference system to track the button.
485
+ */
185
486
  Identifier: string;
487
+ /**
488
+ * The label displayed on the settings button.
489
+ * Can be a string or a function that returns a string dynamically.
490
+ */
186
491
  ButtonText: string | (() => string);
492
+ /**
493
+ * The path to or Base64 data of the icon for the settings button.
494
+ * Can be a string or a function that returns a string dynamically.
495
+ */
187
496
  Image: string | (() => string);
188
- load?: () => void;
189
- click?: () => void;
190
- run?: () => void;
191
- unload?: () => void;
192
- exit?: () => boolean | void;
193
497
  };
498
+ /**
499
+ * Central mod GUI controller that manages all subscreens.
500
+ *
501
+ * This module is responsible for:
502
+ * - Registering the mod's settings button in the game's preferences.
503
+ * - Managing subscreens (including settings screens for all registered modules).
504
+ * - Routing lifecycle events (load, run, click, exit, unload) to the active subscreen.
505
+ */
194
506
  export class GUI extends BaseModule {
507
+ /** The singleton instance of the GUI controller. */
195
508
  static instance: GUI | null;
509
+ /** All subscreens managed by this GUI, including the main menu and module settings screens. */
196
510
  private _subscreens;
511
+ /** The mod's main menu screen. */
197
512
  private _mainMenu;
513
+ /** The currently active subscreen, or `null` if none is active. */
198
514
  private _currentSubscreen;
515
+ /** Options defining how the mod's settings button is displayed and behaves. */
199
516
  private _modButtonOptions;
517
+ /** Returns all registered subscreens. */
200
518
  get subscreens(): BaseSubscreen[];
519
+ /** Returns the main menu subscreen instance. */
201
520
  get mainMenu(): MainMenu;
521
+ /** Returns the currently active subscreen. */
202
522
  get currentSubscreen(): BaseSubscreen | null;
523
+ /**
524
+ * Sets the current subscreen.
525
+ * Accepts either a `BaseSubscreen` instance or the `name` of a subscreen.
526
+ *
527
+ * @throws If a string is provided but no subscreen with that name exists.
528
+ */
203
529
  set currentSubscreen(subscreen: BaseSubscreen | string | null);
530
+ /**
531
+ * Creates the GUI instance and initializes the main menu.
532
+ *
533
+ * @throws If another `GUI` instance already exists.
534
+ */
204
535
  constructor(modButtonOptions: ModButtonOptions);
205
- get defaultSettings(): null;
536
+ /**
537
+ * Loads the GUI and registers the mod's settings button in the extensions menu.
538
+ *
539
+ * - Creates subscreens for each module's settings screen.
540
+ * - Registers lifecycle callbacks for subscreens events.
541
+ * - Sets up the main menu and its subscreens.
542
+ */
206
543
  load(): void;
207
544
  }
208
545
  export {};
@@ -210,19 +547,64 @@ declare module 'bc-deeplib/modules/gui' {
210
547
  }
211
548
  declare module 'bc-deeplib/modules/version' {
212
549
  import { BaseMigrator, BaseModule } from 'bc-deeplib/deeplib';
550
+ /**
551
+ * Handles version tracking, new version detection, and version-based migrations
552
+ * for the mod. Also manages displaying a "new version" message to players and
553
+ * executing registered migration routines when an update occurs.
554
+ *
555
+ * **Key Responsibilities:**
556
+ * - Track and store the current mod version in persistent player storage.
557
+ * - Detect if the mod has been updated since the last session.
558
+ * - Run version-specific migrations via registered `BaseMigrator` instances.
559
+ * - Optionally display a message to the user upon detecting a new version.
560
+ */
213
561
  export class VersionModule extends BaseModule {
562
+ /** Whether the current session is running a new version compared to stored data */
214
563
  private static isItNewVersion;
564
+ /** The current mod version (retrieved from `ModSdkManager.ModInfo.version`) */
215
565
  static Version: string;
566
+ /** Message to display when a new version is detected */
216
567
  static NewVersionMessage: string;
568
+ /** List of registered migration handlers, sorted by version */
217
569
  private static Migrators;
570
+ /**
571
+ * Initializes the module on load:
572
+ * - Stores the current mod version.
573
+ * - Hooks into `ChatRoomSync` to show a "new version" message when applicable.
574
+ */
218
575
  load(): void;
576
+ /**
577
+ * Checks if the stored version differs from the current version.
578
+ * If a new version is detected:
579
+ * - Flags the session as updated.
580
+ * - Runs applicable migrations.
581
+ * - Updates stored version in player data.
582
+ * - Saves `modStorage`.
583
+ */
219
584
  static checkVersionUpdate(): void;
585
+ /**
586
+ * Executes migrations for all registered migrators whose `MigrationVersion`
587
+ * is newer than the previously stored version.
588
+ */
220
589
  private static checkVersionMigration;
590
+ /**
591
+ * Registers a new migrator for handling version-specific changes.
592
+ * Migrators are sorted by their `MigrationVersion` in ascending order.
593
+ */
221
594
  static registerMigrator(migrator: BaseMigrator): void;
595
+ /** Sets the message that will be displayed when a new version is detected. */
222
596
  static setNewVersionMessage(newVersionMessage: string): void;
597
+ /** Sends the currently configured "new version" message to the local player. */
223
598
  static sendNewVersionMessage(): void;
599
+ /**
600
+ * Determines if a given `candidate` version is newer than the `current` version.
601
+ *
602
+ * Version strings are expected in `MAJOR.MINOR.PATCH` format.
603
+ */
224
604
  private static isNewVersion;
605
+ /** Saves the current mod version into persistent player storage. */
225
606
  private static saveVersion;
607
+ /** Loads the stored mod version from persistent player storage. */
226
608
  private static loadVersion;
227
609
  }
228
610
 
@@ -238,23 +620,47 @@ declare module 'bc-deeplib/screens/debug' {
238
620
  }
239
621
  declare module 'bc-deeplib/screens/import_export' {
240
622
  import { BaseSubscreen } from 'bc-deeplib/deeplib';
623
+ /**
624
+ * Configuration options for the {@link GuiImportExport} class.
625
+ */
241
626
  export type ImportExportOptions = {
627
+ /**
628
+ * A custom save file extension (e.g., ".mydata").
629
+ * If it doesn't start with a dot, it will be automatically prefixed.
630
+ */
242
631
  customFileExtension: string;
632
+ /** Optional callback invoked after data has been successfully imported. */
243
633
  onImport?: () => void;
634
+ /** Optional callback invoked after data has been successfully exported. */
244
635
  onExport?: () => void;
245
636
  };
637
+ /**
638
+ * Possible data transfer methods for import/export operations.
639
+ * - `clipboard`: Uses the system clipboard.
640
+ * - `file`: Uses file save/load dialogs.
641
+ */
246
642
  type DataTransferMethod = 'clipboard' | 'file';
643
+ /**
644
+ * GUI screen for importing and exporting mod data.
645
+ * Provides buttons to import/export data either via file or clipboard.
646
+ */
247
647
  export class GuiImportExport extends BaseSubscreen {
248
648
  private importExportOptions;
249
649
  get name(): string;
250
650
  constructor(importExportOptions: ImportExportOptions);
251
651
  load(): void;
252
652
  resize(): void;
653
+ /** Exports the mod data using the specified method. */
253
654
  dataExport(transferMethod: DataTransferMethod): Promise<void>;
655
+ /** Imports mod data using the specified method. */
254
656
  dataImport(transferMethod: DataTransferMethod): Promise<void>;
657
+ /** Saves data to a file using the browser's save dialog. */
255
658
  exportToFile(data: string, defaultFileName: string): Promise<void>;
659
+ /** Opens a file picker and reads the selected file's contents, importing the data. */
256
660
  importFromFile(): Promise<string | null>;
661
+ /** Copies the given data to the clipboard. */
257
662
  exportToClipboard(data: string): Promise<void>;
663
+ /** Prompts the user to enter data and returns it. */
258
664
  importFromClipboard(): Promise<string | null>;
259
665
  }
260
666
  export {};
@@ -263,10 +669,30 @@ declare module 'bc-deeplib/screens/import_export' {
263
669
  declare module 'bc-deeplib/screens/main_menu' {
264
670
  import { BaseSubscreen, GUI } from 'bc-deeplib/deeplib';
265
671
  import { GuiImportExport } from 'bc-deeplib/screens/import_export';
672
+ /**
673
+ * Configuration options for the main menu.
674
+ *
675
+ * If these are defined, new button for each option will be added to the main menu.
676
+ */
266
677
  export type MainMenuOptions = {
678
+ /**
679
+ * Optional URL to the project's repository.
680
+ * Example: "https://github.com/user/project"
681
+ */
267
682
  repoLink?: string;
683
+ /**
684
+ * Optional URL to the project's wiki or documentation.
685
+ * Example: "https://github.com/user/project/wiki"
686
+ */
268
687
  wikiLink?: string;
688
+ /**
689
+ * Optional subscreen to use for the "reset" action.
690
+ */
269
691
  resetSubscreen?: BaseSubscreen;
692
+ /**
693
+ * Optional subscreen for import/export functionality.
694
+ * Provides tools to import or export data to or from the mod.
695
+ */
270
696
  importExportSubscreen?: GuiImportExport;
271
697
  };
272
698
  export class MainMenu extends BaseSubscreen {
@@ -284,18 +710,52 @@ declare module 'bc-deeplib/screens/main_menu' {
284
710
 
285
711
  }
286
712
  declare module 'bc-deeplib/utilities/common' {
713
+ /**
714
+ * Deeply merges properties from `source` into `target`.
715
+ * - If both target and source properties are arrays, concatenates them.
716
+ * - If both are objects, recursively merges them.
717
+ * - Otherwise, source overwrites target.
718
+ */
287
719
  export function deepMerge(target: any, source: any): any;
720
+ /**
721
+ * Returns a new array with elements of the input array shuffled.
722
+ * Uses something-something shuffle algorithm by splicing from a cloned array.
723
+ */
288
724
  export function shuffleArray(array: string[]): string[];
725
+ /**
726
+ * Exports a value to the global object under a nested namespace path.
727
+ * Creates intermediate objects if they do not exist.
728
+ *
729
+ * Example: `exportToGlobal('MyMod.Utils', value)` creates `globalThis.MyMod.Utils = value`.
730
+ */
289
731
  export function exportToGlobal(name: string, value: any): void;
732
+ /**
733
+ * Deeply merges only matching properties from `mergeFrom` into `mergeTo`.
734
+ * Properties not present in `mergeTo` are ignored.
735
+ * Objects are recursively merged, primitive properties overwritten.
736
+ */
290
737
  export function deepMergeMatchingProperties<T extends object>(mergeTo: T, mergeFrom: T): T;
738
+ /** Checks if the given property has a getter defined on the object or its prototype chain. */
291
739
  export function hasGetter<T extends object>(obj: T, prop: keyof T | string): boolean;
740
+ /** Checks if the given property has a setter defined on the object or its prototype chain. */
292
741
  export function hasSetter<T extends object>(obj: T, prop: keyof T | string): boolean;
293
742
 
294
743
  }
295
744
  declare module 'bc-deeplib/utilities/data' {
296
745
  import { SettingsModel } from 'bc-deeplib/deeplib';
746
+ /**
747
+ * ModStorage is a singleton class responsible for managing
748
+ * mod-specific persistent storage both in player settings
749
+ * and in browser localStorage.
750
+ *
751
+ * It provides methods to load and save mod data compressed
752
+ * as base64 strings, and exposes typed accessors for
753
+ * playerStorage and extensionStorage.
754
+ */
297
755
  export class ModStorage<T extends SettingsModel = SettingsModel> {
756
+ /** Singleton instance of ModStorage */
298
757
  private static _instance;
758
+ /** The unique mod identifier used as key prefix in storage */
299
759
  private modName;
300
760
  constructor(modName: string);
301
761
  get playerStorage(): T;
@@ -311,9 +771,13 @@ declare module 'bc-deeplib/utilities/data' {
311
771
  }
312
772
 
313
773
  }
314
- declare module 'bc-deeplib/utilities/elements/advanced_elements' {
774
+ declare module 'bc-deeplib/utilities/elements/elements' {
315
775
  import { Button, Checkbox, Custom, Input, Label } from 'bc-deeplib/base/elements_typings';
316
- export const advancedElement: {
776
+ /**
777
+ * Collection of element creation utilities.
778
+ * Provides convenience wrappers for generating commonly used UI elements.
779
+ */
780
+ export const advElement: {
317
781
  createButton: typeof elementCreateButton;
318
782
  createCheckbox: typeof elementCreateCheckbox;
319
783
  createInput: typeof elementCreateInput;
@@ -347,57 +811,123 @@ declare module 'bc-deeplib/utilities/elements/advanced_elements' {
347
811
  }
348
812
  function elementPrevNext(options: PrevNext): HTMLElement;
349
813
  export type ModalButton<T extends string = string> = {
814
+ /** Button label text. */
350
815
  text: string;
816
+ /** Action identifier returned when the button is clicked. */
351
817
  action: T;
818
+ /** Whether the button is disabled. */
352
819
  disabled?: boolean;
353
820
  };
354
821
  export type ModalInputOptions = {
822
+ /** Default input value. */
355
823
  defaultValue?: string;
824
+ /** Makes the input read-only if true. */
356
825
  readOnly?: boolean;
826
+ /** Placeholder text. */
357
827
  placeholder?: string;
828
+ /** Input type. */
358
829
  type: 'input' | 'textarea';
830
+ /** Validation callback to check if the input value is valid. */
359
831
  validate?: (value: string) => string | null;
360
832
  };
361
833
  export type ModalOptions<T extends string = string> = {
834
+ /** Content or DOM node displayed in the modal header. */
362
835
  prompt: string | Node;
836
+ /** Optional input configuration. */
363
837
  input?: ModalInputOptions;
838
+ /** Buttons to display in the modal. */
364
839
  buttons?: ModalButton<T>[];
365
- custom?: readonly (string | Node | HTMLOptions<keyof HTMLElementTagNameMap> | null | undefined)[] | undefined;
840
+ /** Whether clicking backdrop closes the modal (default: true). */
366
841
  closeOnBackdrop?: boolean;
842
+ /** Auto-close timeout in milliseconds. */
367
843
  timeoutMs?: number;
368
844
  };
845
+ /**
846
+ * Modal dialog implementation with queuing, buttons, optional input, and focus trapping.
847
+ * Multiple modals are queued to ensure only one is visible at a time.
848
+ */
369
849
  export class Modal<T extends string = string> {
370
850
  private opts;
371
851
  private dialog;
372
852
  private blocker;
373
853
  private inputEl?;
374
854
  private timeoutId?;
855
+ /** Static modal queue. */
375
856
  private static queue;
857
+ /** Flag to indicate if a modal is currently being shown. */
376
858
  private static processing;
377
859
  constructor(opts: ModalOptions<T>);
860
+ /**
861
+ * Displays the modal and resolves with the chosen action and input value.
862
+ */
378
863
  show(): Promise<[T, string | null]>;
864
+ /**
865
+ * Shows a simple alert modal with a single "OK" button.
866
+ */
379
867
  static alert(msg: string, timeoutMs?: number): Promise<void>;
868
+ /**
869
+ * Shows a confirmation modal with "Cancel" and "OK" buttons.
870
+ * Returns true if "OK" is clicked.
871
+ */
380
872
  static confirm(msg: string): Promise<boolean>;
873
+ /**
874
+ * Shows a prompt modal with an input field and "Submit"/"Cancel" buttons.
875
+ * Returns the input value if submitted, otherwise null.
876
+ */
381
877
  static prompt(msg: string, defaultValue?: string): Promise<string | null>;
878
+ /** Creates the input element for the modal, applying configuration and validation. */
382
879
  private renderInput;
880
+ /** Creates modal action buttons from configuration. */
383
881
  private renderButtons;
882
+ /** Creates the modal backdrop blocker with optional click-to-close behavior. */
384
883
  private createBlocker;
884
+ /** Implements a focus trap to keep keyboard navigation inside the modal. */
385
885
  private setupFocusTrap;
886
+ /** Closes the modal, cleans up DOM, resolves promise, and shows next queued modal. */
386
887
  private close;
888
+ /**
889
+ * An internal function where we will save promise function.
890
+ */
387
891
  private resolve;
892
+ /** A function that adds a modal to the queue and returns a promise */
388
893
  private static enqueue;
894
+ /** A function that processes the queue, removing the first modal */
389
895
  private static dequeue;
390
896
  }
391
897
  export {};
392
898
 
393
899
  }
394
- declare module 'bc-deeplib/utilities/elements/element_helpers' {
900
+ declare module 'bc-deeplib/utilities/elements/helpers' {
395
901
  import { SettingElement } from 'bc-deeplib/base/elements_typings';
396
902
  export const domUtil: {
903
+ /**
904
+ * Automatically sets the position of the element based on the given position.
905
+ * The position can be either a [x, y] tuple or a function returning such a tuple.
906
+ * If both x and y are defined, the element's position is updated accordingly.
907
+ */
397
908
  autoSetPosition: typeof autoSetPosition;
909
+ /**
910
+ * Automatically sets the size of the element based on the given size.
911
+ * The size can be either a [width, height] tuple or a function returning such a tuple.
912
+ * If both width and height are defined, the element's size is updated accordingly.
913
+ */
398
914
  autoSetSize: typeof autoSetSize;
915
+ /**
916
+ * Hides the element by setting its CSS display property to 'none'.
917
+ * If the element cannot be found, the function does nothing.
918
+ */
399
919
  hide: typeof hide;
920
+ /**
921
+ * Unhides the element by clearing its CSS display property (sets it to '').
922
+ * If the element cannot be found, the function does nothing.
923
+ */
400
924
  unhide: typeof unhide;
925
+ /**
926
+ * Checks if the element has overflow content.
927
+ * Returns an object indicating if there is any overflow,
928
+ * and specifically if there is vertical or horizontal overflow.
929
+ * Returns null if the element is not found.
930
+ */
401
931
  hasOverflow: typeof hasOverflow;
402
932
  };
403
933
  function autoSetPosition(_: ElementHelp.ElementOrId, position: SettingElement['position']): void;
@@ -412,12 +942,12 @@ declare module 'bc-deeplib/utilities/elements/element_helpers' {
412
942
  export {};
413
943
 
414
944
  }
415
- declare module 'bc-deeplib/utilities/elements/layout_elements' {
416
- export const layoutElement: {
417
- createSubscreenDiv: typeof elementCreateSubscreenDiv;
418
- getSubscreenDiv: typeof elementGetSubscreenDiv;
419
- appendToSubscreenDiv: typeof elementAppendToSubscreenDiv;
420
- removeSubscreenDiv: typeof elementRemoveSubscreenDiv;
945
+ declare module 'bc-deeplib/utilities/elements/layout' {
946
+ export const layout: {
947
+ createSubscreen: typeof elementCreateSubscreenDiv;
948
+ getSubscreen: typeof elementGetSubscreenDiv;
949
+ appendToSubscreen: typeof elementAppendToSubscreenDiv;
950
+ removeSubscreen: typeof elementRemoveSubscreenDiv;
421
951
  createSettingsDiv: typeof elementCreateSettingsDiv;
422
952
  getSettingsDiv: typeof elementGetSettingsDiv;
423
953
  appendToSettingsDiv: typeof elementAppendToSettingsDiv;
@@ -470,6 +1000,10 @@ declare module 'bc-deeplib/utilities/messages' {
470
1000
 
471
1001
  }
472
1002
  declare module 'bc-deeplib/utilities/sdk' {
1003
+ /**
1004
+ * Defines priority levels for hooking functions.
1005
+ * Hooks with higher priority are called first in hook chain.
1006
+ */
473
1007
  export const HookPriority: {
474
1008
  Observe: number;
475
1009
  AddBehavior: number;
@@ -477,7 +1011,12 @@ declare module 'bc-deeplib/utilities/sdk' {
477
1011
  OverrideBehavior: number;
478
1012
  Top: number;
479
1013
  };
1014
+ /** Type alias representing module of hook? */
480
1015
  export type ModuleCategory = number | string;
1016
+ /**
1017
+ * Interface representing data about a patched function,
1018
+ * including the function name and all hooks applied to it.
1019
+ */
481
1020
  interface IPatchedFunctionData {
482
1021
  name: string;
483
1022
  hooks: {
@@ -487,16 +1026,41 @@ declare module 'bc-deeplib/utilities/sdk' {
487
1026
  removeCallback: () => void;
488
1027
  }[];
489
1028
  }
1029
+ /**
1030
+ * Manager class for mod SDK integration,
1031
+ * provides methods to register mods, hook functions, and manage patches.
1032
+ */
490
1033
  export class ModSdkManager {
491
1034
  private static SDK;
492
1035
  private static patchedFunctions;
493
1036
  static ModInfo: ModSDKModInfo;
1037
+ /** Registers a mod with the SDK and stores mod information. */
494
1038
  constructor(info: ModSDKModInfo, options?: ModSDKModOptions);
1039
+ /** Retrieves or initializes patch data for a given target function. */
495
1040
  initPatchableFunction(target: string): IPatchedFunctionData;
1041
+ /**
1042
+ * Hooks a function with a callback at a given priority.
1043
+ *
1044
+ * Prevents duplicate hooks.
1045
+ */
496
1046
  hookFunction<TargetName extends string>(target: TargetName, priority: number, hook: PatchHook<GetDotedPathType<typeof globalThis, TargetName>>, module?: ModuleCategory | null): () => void;
1047
+ /**
1048
+ * Applies patches to a target function.
1049
+ *
1050
+ * **This method is DANGEROUS** to use and has high potential to conflict with other mods.
1051
+ */
497
1052
  patchFunction(target: string, patches: Record<string, string>): void;
1053
+ /**
1054
+ * Removes all patches from a target function.
1055
+ */
498
1056
  unpatchFunction(target: string): void;
1057
+ /**
1058
+ * Removes all hooks associated with a specific module from a target function.
1059
+ */
499
1060
  removeHookByModule(target: string, module: ModuleCategory): boolean;
1061
+ /**
1062
+ * Removes all hooks associated with a specific module across all patched functions.
1063
+ */
500
1064
  removeAllHooksByModule(module: ModuleCategory): boolean;
501
1065
  }
502
1066
  export {};
@@ -504,32 +1068,79 @@ declare module 'bc-deeplib/utilities/sdk' {
504
1068
  }
505
1069
  declare module 'bc-deeplib/utilities/style' {
506
1070
  export const Style: {
1071
+ /**
1072
+ * Injects a CSS style block directly into the document head using a <style> tag.
1073
+ * If a style element with the same `styleId` already exists, it won't inject again.
1074
+ */
507
1075
  injectInline(styleId: string, styleSource: string): void;
1076
+ /**
1077
+ * Injects a CSS stylesheet link into the document head using a <link> tag.
1078
+ * If a link element with the same `styleId` already exists, it won't inject again.
1079
+ */
508
1080
  injectEmbed(styleId: string, styleLink: string): void;
1081
+ /**
1082
+ * Removes a style element from the document head by its ID.
1083
+ * Does nothing if the element is not found.
1084
+ */
509
1085
  eject(id: string): void;
1086
+ /**
1087
+ * Reloads an inline style by removing the existing style element (if any)
1088
+ * and injecting the new styles inline again.
1089
+ */
510
1090
  reload(styleId: string, styleSource: string): void;
1091
+ /** Fetches the text content of a stylesheet or any resource at the given link. */
511
1092
  fetch(link: string): Promise<string>;
512
1093
  };
513
1094
 
514
1095
  }
515
1096
  declare module 'bc-deeplib/utilities/translation' {
516
- interface InitOptions {
517
- pathToTranslationsFolder: string;
1097
+ /**
1098
+ * Options for initializing the Localization system.
1099
+ */
1100
+ export interface TranslationOptions {
1101
+ /** The path to the folder where the translations are stored. */
1102
+ pathToTranslationsFolder?: string;
1103
+ /** The default language to use. */
1104
+ defaultLanguage?: string;
1105
+ /** If true, the localization will be fixed to the default language, ignoring user language settings. */
1106
+ fixedLanguage?: boolean;
518
1107
  }
1108
+ /**
1109
+ * Localization class handles loading and retrieving translation strings
1110
+ * from library and mod-specific language files.
1111
+ */
519
1112
  export class Localization {
520
1113
  private static LibTranslation;
521
1114
  private static ModTranslation;
522
1115
  private static PathToModTranslation;
523
1116
  private static PathToLibTranslation;
1117
+ private static DefaultLanguage;
1118
+ /** Flag to prevent re-initialization */
524
1119
  private static initialized;
525
- static init(initOptions: InitOptions): Promise<void>;
1120
+ /** Initialize the localization system by loading translation files. */
1121
+ static init(initOptions?: TranslationOptions): Promise<void>;
1122
+ /** Get a translated string from mod translations by source tag. */
526
1123
  static getTextMod(srcTag: string): string | undefined;
1124
+ /** Get a translated string from library translations by source tag. */
527
1125
  static getTextLib(srcTag: string): string | undefined;
1126
+ /**
1127
+ * Fetch and parse a language file from the given base URL and language code.
1128
+ * Falls back to default language if the requested language file is unavailable.
1129
+ */
528
1130
  private static fetchLanguageFile;
1131
+ /**
1132
+ * Parse the raw content of a language file into a TranslationDict.
1133
+ * Ignores empty lines and comments starting with '#'.
1134
+ */
529
1135
  private static parseLanguageFile;
530
1136
  }
1137
+ /**
1138
+ * Retrieve a localized string for the given source tag.
1139
+ * First attempts to get the mod-specific translation,
1140
+ * then falls back to the library translation,
1141
+ * and if neither exist, returns the source tag itself.
1142
+ */
531
1143
  export const getText: (srcTag: string) => string;
532
- export {};
533
1144
 
534
1145
  }
535
1146
  declare module 'bc-deeplib' {