bc-deeplib 3.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/deeplib.d.ts CHANGED
@@ -46,7 +46,6 @@ declare module 'bc-deeplib/base/base_module' {
46
46
  set settings(value: BaseSettingsModel | null);
47
47
  /**
48
48
  * Initializes the module.
49
- * Default implementation registers default settings immediately.
50
49
  * Subclasses can override to perform additional setup.
51
50
  */
52
51
  init(): void;
@@ -119,7 +118,7 @@ declare module 'bc-deeplib/base/base_subscreen' {
119
118
  * If not configured, the default is the main menu for all screens, but main menu itself.
120
119
  * For main menu, the default is the Extensions menu
121
120
  */
122
- returnScreen?: (() => ScreenSpecifier | BaseSubscreen) | ScreenSpecifier | BaseSubscreen;
121
+ returnScreen?: Thunk<ScreenSpecifier | BaseSubscreen>;
123
122
  /**
124
123
  * The background image for this subscreen.
125
124
  * Currently supports only images from the Club.
@@ -255,8 +254,9 @@ declare module 'bc-deeplib/base/base_subscreen' {
255
254
  }
256
255
  declare module 'bc-deeplib/base/elements_typings' {
257
256
  export type SettingElement = Button | Checkbox | Input | Label | Dropdown | Custom;
257
+ type ElementFlexDirection = 'row' | 'column' | 'rowReverse' | 'columnReverse';
258
258
  export type BaseElementModel = {
259
- id: string;
259
+ id: string | null;
260
260
  size?: Thunk<[width: number | null, height: number | null]>;
261
261
  position?: Thunk<[x: number, y: number, anchor?: ElementHelp.AnchorXY]>;
262
262
  disabled?: Thunk<boolean>;
@@ -271,65 +271,62 @@ declare module 'bc-deeplib/base/elements_typings' {
271
271
  export type Checkbox = Prettify<{
272
272
  type: 'checkbox';
273
273
  label?: string;
274
- description?: string;
274
+ description?: ElementButton.StaticNode;
275
275
  setElementValue?: () => boolean;
276
276
  setSettingValue?: (val: boolean) => void;
277
277
  htmlOptions?: Partial<Record<'container' | 'checkbox' | 'label', Omit<HTMLOptions<any>, 'tag'>>> | null | undefined;
278
+ options?: {
279
+ direction?: ElementFlexDirection;
280
+ };
278
281
  } & BaseElementModel>;
279
282
  export type Input = Prettify<{
280
283
  type: 'text' | 'number' | 'color';
281
284
  label?: string;
282
- description?: string;
285
+ description?: ElementButton.StaticNode;
283
286
  setElementValue?: () => string;
284
287
  setSettingValue?: (val: string) => void;
285
288
  htmlOptions?: Partial<Record<'container' | 'input' | 'label', Omit<HTMLOptions<any>, 'tag'>>> | null | undefined;
289
+ options?: {
290
+ direction?: ElementFlexDirection;
291
+ };
286
292
  } & BaseElementModel>;
287
293
  export type Dropdown = Prettify<{
288
- id: Parameters<typeof ElementCreateDropdown>[0];
294
+ id: Parameters<typeof ElementDropdown.CreateLabelled>[0];
289
295
  type: 'dropdown';
290
296
  label?: string;
291
- description?: string;
292
- optionsList: Parameters<typeof ElementCreateDropdown>[1];
297
+ optionsList: Parameters<typeof ElementDropdown.CreateLabelled>[1];
298
+ onChange?: Parameters<typeof ElementDropdown.CreateLabelled>[3];
299
+ description?: ElementButton.StaticNode;
293
300
  setElementValue?: () => string;
294
301
  setSettingValue?: (val: string) => void;
295
- options?: Parameters<typeof ElementCreateDropdown>[3];
296
- htmlOptions?: {
297
- container?: Partial<Omit<HTMLOptions<any>, 'tag'>>;
298
- select?: Parameters<typeof ElementCreateDropdown>[4];
299
- label?: Partial<Omit<HTMLOptions<'label'>, 'tag'>>;
302
+ options?: Parameters<typeof ElementDropdown.CreateLabelled>[4] & {
303
+ direction?: ElementFlexDirection;
300
304
  };
305
+ htmlOptions?: Partial<Record<'label' | 'container' | 'select', Omit<HTMLOptions<any>, 'tag'>>> | null | undefined;
301
306
  } & Omit<BaseElementModel, 'id' | 'disabled'>>;
302
307
  export type Label = Prettify<{
303
308
  type: 'label';
304
309
  label?: string;
305
- description?: string;
310
+ description?: ElementButton.StaticNode;
306
311
  htmlOptions?: Omit<HTMLOptions<any>, 'tag'>;
307
312
  } & BaseElementModel>;
308
313
  export type Custom = Prettify<{
309
314
  type: 'custom';
310
315
  htmlOptions: HTMLOptions<keyof HTMLElementTagNameMap>;
311
316
  } & BaseElementModel>;
317
+ export {};
312
318
 
313
319
  }
314
320
  declare module 'bc-deeplib/base/initialization' {
315
- import { BaseModule, ModSdkManager, ModStorage, MainMenuOptions, TranslationOptions, Logger } from 'bc-deeplib/deeplib';
321
+ import { ModSdkManager, ModStorage, MainMenuOptions, TranslationOptions, ModulesList } from 'bc-deeplib/deeplib';
322
+ import { ILogger } from 'js-logger';
316
323
  /** Configuration object for initializing a mod via `initMod`. */
317
324
  interface InitOptions {
318
- /**
319
- * Name of the mod.
320
- * Used to identify the mod in the Mod SDK and storage.
321
- */
322
- modName: string;
323
- /**
324
- * Repository URL for the mod.
325
- * Used to register the mod with the Mod SDK and display in the main menu.
326
- */
327
- modRepository?: string;
328
325
  /**
329
326
  * List of modules (`BaseModule` subclasses) to register with the mod system.
330
327
  * Modules are initialized, loaded, and run in order.
331
328
  */
332
- modules?: BaseModule[];
329
+ modules?: Partial<ModulesList>;
333
330
  /**
334
331
  * Configuration for customizing the main menu when the mod is active.
335
332
  * Does nothing if GUI module is not loaded.
@@ -362,8 +359,7 @@ declare module 'bc-deeplib/base/initialization' {
362
359
  * Mod specific logger instance.
363
360
  * Initialized by `initMod()`.
364
361
  */
365
- export let modLogger: Logger;
366
- export let MOD_NAME: string;
362
+ export let modLogger: ILogger;
367
363
  /**
368
364
  * Entry point for initializing a mod. Handles:
369
365
  * - Setting up the Mod SDK
@@ -371,7 +367,7 @@ declare module 'bc-deeplib/base/initialization' {
371
367
  * - Injecting required styles
372
368
  * - Delaying initialization until login (if necessary)
373
369
  */
374
- export function initMod(options: InitOptions): void;
370
+ export function initMod(options: InitOptions): Promise<void>;
375
371
  /**
376
372
  * Cleans up and removes the mod from memory.
377
373
  * Calls `unload()` on all modules and removes the global loaded flag.
@@ -381,7 +377,14 @@ declare module 'bc-deeplib/base/initialization' {
381
377
 
382
378
  }
383
379
  declare module 'bc-deeplib/base/modules' {
384
- import { BaseModule } from 'bc-deeplib/deeplib';
380
+ import { GUI, VersionModule } from 'bc-deeplib/deeplib';
381
+ import { DebugModule } from 'bc-deeplib/modules/debug';
382
+ export interface ModulesList {
383
+ VersionModule: VersionModule;
384
+ GUI: GUI;
385
+ DebugModule: DebugModule;
386
+ }
387
+ export type ModuleKey = Prettify<keyof ModulesList>;
385
388
  /**
386
389
  * Retrieves all registered module instances.
387
390
  *
@@ -398,7 +401,7 @@ declare module 'bc-deeplib/base/modules' {
398
401
  * }
399
402
  * ```
400
403
  */
401
- export function modules(): BaseModule[];
404
+ export function modules(): ModulesList[ModuleKey][];
402
405
  /**
403
406
  * Registers a module instance in the global registry.
404
407
  *
@@ -414,7 +417,7 @@ declare module 'bc-deeplib/base/modules' {
414
417
  * registerModule(new MyGlobalModule());
415
418
  * ```
416
419
  */
417
- export function registerModule<T extends BaseModule>(module: T): T;
420
+ export function registerModule<K extends ModuleKey>(key: K, module: ModulesList[K]): ModulesList[K];
418
421
  /**
419
422
  * Retrieves a registered module by its type name.
420
423
  *
@@ -430,7 +433,7 @@ declare module 'bc-deeplib/base/modules' {
430
433
  * themeModule?.reloadTheme();
431
434
  * ```
432
435
  */
433
- export function getModule<T extends BaseModule>(moduleType: string): T | undefined;
436
+ export function getModule<K extends ModuleKey>(key: K): ModulesList[K];
434
437
 
435
438
  }
436
439
  declare module 'bc-deeplib/deeplib' {
@@ -444,6 +447,7 @@ declare module 'bc-deeplib/deeplib' {
444
447
  export * from 'bc-deeplib/models/settings';
445
448
  export * from 'bc-deeplib/modules/gui';
446
449
  export * from 'bc-deeplib/modules/version';
450
+ export * from 'bc-deeplib/modules/debug';
447
451
  export * from 'bc-deeplib/screens/debug';
448
452
  export * from 'bc-deeplib/screens/main_menu';
449
453
  export * from 'bc-deeplib/screens/import_export';
@@ -502,12 +506,7 @@ declare module 'bc-deeplib/models/base' {
502
506
  * Represents the base settings structure for a mod.
503
507
  * Present for all mods.
504
508
  */
505
- export type BaseSettingsModel = {
506
- /** Whether the mod is currently active. */
507
- modEnabled: boolean;
508
- /** Whether to display a notification when a new version is detected. */
509
- doShowNewVersionMessage: boolean;
510
- };
509
+ export type BaseSettingsModel = Record<string, unknown>;
511
510
 
512
511
  }
513
512
  declare module 'bc-deeplib/models/settings' {
@@ -518,6 +517,29 @@ declare module 'bc-deeplib/models/settings' {
518
517
  Version: string;
519
518
  };
520
519
 
520
+ }
521
+ declare module 'bc-deeplib/modules/debug' {
522
+ import { BaseModule } from 'bc-deeplib/deeplib';
523
+ interface DebugSettings {
524
+ showRawTranslations: boolean;
525
+ showFileNames: boolean;
526
+ showIncomingServerTransactions: boolean;
527
+ incomingMessageFilterMode: 'include' | 'exclude';
528
+ incomingMessageTypes: string;
529
+ showOutcomingServerTransactions: boolean;
530
+ outcomingMessageFilterMode: 'include' | 'exclude';
531
+ outcomingMessageTypes: string;
532
+ showRawActivityNames: boolean;
533
+ showRawAssetNames: boolean;
534
+ }
535
+ export class DebugModule extends BaseModule {
536
+ debugSettings: DebugSettings;
537
+ load(): void;
538
+ unload(): void;
539
+ saveDebugSettings(): void;
540
+ }
541
+ export {};
542
+
521
543
  }
522
544
  declare module 'bc-deeplib/modules/gui' {
523
545
  import { BaseModule, BaseSubscreen, MainMenu } from 'bc-deeplib/deeplib';
@@ -563,7 +585,7 @@ declare module 'bc-deeplib/modules/gui' {
563
585
  /** Returns all registered subscreens. */
564
586
  get subscreens(): BaseSubscreen[];
565
587
  /** Returns the main menu subscreen instance. */
566
- get mainMenu(): MainMenu;
588
+ get mainMenu(): MainMenu | null;
567
589
  /**
568
590
  * Creates the GUI instance and initializes the main menu.
569
591
  *
@@ -663,9 +685,12 @@ declare module 'bc-deeplib/modules/version' {
663
685
  declare module 'bc-deeplib/screens/debug' {
664
686
  import { SettingElement } from 'bc-deeplib/base/elements_typings';
665
687
  import { BaseSubscreen, SubscreenOptions } from 'bc-deeplib/deeplib';
688
+ import { DebugModule } from 'bc-deeplib/modules/debug';
666
689
  export class GuiDebug extends BaseSubscreen {
667
690
  protected static subscreenOptions: SubscreenOptions;
691
+ readonly module: DebugModule;
668
692
  get pageStructure(): SettingElement[][];
693
+ exit(): void;
669
694
  }
670
695
 
671
696
  }
@@ -801,6 +826,17 @@ declare module 'bc-deeplib/utilities/common' {
801
826
  * Converts bytes to kilobytes.
802
827
  */
803
828
  export const byteToKB: (nByte: number) => number;
829
+ export type Ok<T> = {
830
+ ok: true;
831
+ value: T;
832
+ };
833
+ export type Err<E = unknown> = {
834
+ ok: false;
835
+ error: E;
836
+ };
837
+ export type Result<T, E = unknown> = Ok<T> | Err<E>;
838
+ export function tryCatch<T, E = unknown>(fn: () => T, mapError?: (e: unknown) => E): Result<T, E>;
839
+ export function tryCatchAsync<T, E = unknown>(fn: () => Promise<T>, mapError?: (e: unknown) => E): Promise<Result<T, E>>;
804
840
 
805
841
  }
806
842
  declare module 'bc-deeplib/utilities/data' {
@@ -861,9 +897,9 @@ declare module 'bc-deeplib/utilities/elements/elements' {
861
897
  function elementCreateDropdown(options: Omit<Dropdown, 'type'>): HTMLLabelElement;
862
898
  function elementCreateTooltip(): HTMLDivElement;
863
899
  function elementGetTooltip(): HTMLElement | undefined;
864
- function elementSetTooltip(text: string): boolean;
900
+ function elementSetTooltip(text: ElementButton.StaticNode, position?: 'top' | 'bottom'): boolean;
865
901
  interface PrevNext {
866
- id: string;
902
+ id: string | null;
867
903
  initialLabel?: string;
868
904
  back: (arg0: PrevNextCallbacks) => void;
869
905
  initialPrevTooltip?: string;
@@ -911,6 +947,11 @@ declare module 'bc-deeplib/utilities/elements/helpers' {
911
947
  * Returns null if the element is not found.
912
948
  */
913
949
  hasOverflow: typeof hasOverflow;
950
+ /**
951
+ * Checks if two rectangles overlap.
952
+ * Returns true if the rectangles overlap, false otherwise.
953
+ */
954
+ doRectsOverlap: typeof doRectsOverlap;
914
955
  };
915
956
  function autoSetPosition(_: ElementHelp.ElementOrId, position: SettingElement['position']): void;
916
957
  function autoSetSize(_: ElementHelp.ElementOrId, size: SettingElement['size']): void;
@@ -921,6 +962,7 @@ declare module 'bc-deeplib/utilities/elements/helpers' {
921
962
  vertical: boolean;
922
963
  horizontal: boolean;
923
964
  } | null;
965
+ function doRectsOverlap(rect1: DOMRect, rect2: DOMRect): boolean;
924
966
  export {};
925
967
 
926
968
  }
@@ -953,7 +995,7 @@ declare module 'bc-deeplib/utilities/elements/modal' {
953
995
  /** Button label text. */
954
996
  text: string;
955
997
  /** Action identifier returned when the button is clicked. */
956
- action: T;
998
+ action: T | (() => void);
957
999
  /** Whether the button is disabled. */
958
1000
  disabled?: boolean;
959
1001
  };
@@ -986,21 +1028,43 @@ declare module 'bc-deeplib/utilities/elements/modal' {
986
1028
  enterAction?: T;
987
1029
  /** Modal ID. */
988
1030
  modalId?: string;
1031
+ /** Modal class list. */
1032
+ modalClassList?: string[];
1033
+ /** Callback function to be called when the modal is shown. */
1034
+ onShow?: (this: HTMLDialogElement) => void;
989
1035
  };
990
- export interface AlertOptions {
1036
+ export interface AlertOptions<T extends string = string> {
991
1037
  /** Auto-close timeout in milliseconds. */
992
1038
  timeoutMs?: number;
993
1039
  /** Modal ID. */
994
1040
  modalId?: string;
1041
+ /** Modal class list. */
1042
+ modalClassList?: string[];
1043
+ /** Additional buttons to display in the modal. */
1044
+ buttons?: ModalButton<T>[];
1045
+ /** Callback function to be called when the modal is shown. */
1046
+ onShow?: (this: HTMLDialogElement) => void;
995
1047
  }
996
- export interface ConfirmOptions {
1048
+ export interface ConfirmOptions<T extends string = string> {
997
1049
  /** Modal ID. */
998
1050
  modalId?: string;
1051
+ /** Modal class list. */
1052
+ modalClassList?: string[];
1053
+ /** Additional buttons to display in the modal. */
1054
+ buttons?: ModalButton<T>[];
1055
+ /** Callback function to be called when the modal is shown. */
1056
+ onShow?: (this: HTMLDialogElement) => void;
999
1057
  }
1000
- export interface PromptOptions {
1058
+ export interface PromptOptions<T extends string = string> {
1001
1059
  defaultValue?: string;
1002
1060
  /** Modal ID. */
1003
1061
  modalId?: string;
1062
+ /** Modal class list. */
1063
+ modalClassList?: string[];
1064
+ /** Additional buttons to display in the modal. */
1065
+ buttons?: ModalButton<T>[];
1066
+ /** Callback function to be called when the modal is shown. */
1067
+ onShow?: (this: HTMLDialogElement) => void;
1004
1068
  }
1005
1069
  /**
1006
1070
  * Modal dialog implementation with queuing, buttons, optional input, and focus trapping.
@@ -1012,6 +1076,7 @@ declare module 'bc-deeplib/utilities/elements/modal' {
1012
1076
  private blocker;
1013
1077
  private inputEl?;
1014
1078
  private timeoutId?;
1079
+ private updateIntervalId?;
1015
1080
  /** Static modal queue. */
1016
1081
  private static queue;
1017
1082
  /** Flag to indicate if a modal is currently being shown. */
@@ -1096,25 +1161,7 @@ declare module 'bc-deeplib/utilities/event_channel' {
1096
1161
 
1097
1162
  }
1098
1163
  declare module 'bc-deeplib/utilities/logger' {
1099
- type LogLevel = 'info' | 'log' | 'warn' | 'error' | 'debug';
1100
- interface LogEntry {
1101
- readonly args: readonly any[];
1102
- readonly date: Date;
1103
- readonly logLevel: LogLevel;
1104
- }
1105
- export class Logger extends Array<LogEntry> {
1106
- private ModName;
1107
- constructor(modName?: string);
1108
- private _Log;
1109
- info(...args: any[]): void;
1110
- log(...args: any[]): void;
1111
- warn(...args: any[]): void;
1112
- error(...args: any[]): void;
1113
- debug(...args: any[]): void;
1114
- static colorizeLog(logLevel: LogLevel): string;
1115
- }
1116
- export const deepLibLogger: Logger;
1117
- export {};
1164
+ export const deepLibLogger: import("js-logger").ILogger;
1118
1165
 
1119
1166
  }
1120
1167
  declare module 'bc-deeplib/utilities/messages' {
@@ -1230,6 +1277,8 @@ declare module 'bc-deeplib/utilities/translation' {
1230
1277
  defaultLanguage?: string;
1231
1278
  /** If true, the localization will be fixed to the default language, ignoring user language settings. */
1232
1279
  fixedLanguage?: boolean;
1280
+ /** If true, the localization will fetch the translations from the folder. */
1281
+ fetchFolder?: boolean;
1233
1282
  }
1234
1283
  /**
1235
1284
  * Localization class handles loading and retrieving translation strings
@@ -1241,7 +1290,7 @@ declare module 'bc-deeplib/utilities/translation' {
1241
1290
  private static PathToModTranslation;
1242
1291
  private static PathToLibTranslation;
1243
1292
  private static DefaultLanguage;
1244
- /** Flag to prevent re-initialization */
1293
+ private static FetchFolder;
1245
1294
  private static initialized;
1246
1295
  /** Initialize the localization system by loading translation files. */
1247
1296
  static init(initOptions?: TranslationOptions): Promise<void>;
@@ -1249,16 +1298,25 @@ declare module 'bc-deeplib/utilities/translation' {
1249
1298
  static getTextMod(srcTag: string): string | undefined;
1250
1299
  /** Get a translated string from library translations by source tag. */
1251
1300
  static getTextLib(srcTag: string): string | undefined;
1301
+ private static fetchTranslation;
1252
1302
  /**
1253
- * Fetch and parse a language file from the given base URL and language code.
1254
- * Falls back to default language if the requested language file is unavailable.
1303
+ * Fetch and parse a single translation file for a given language.
1304
+ * Only requests `${baseUrl}${lang}.lang` and returns its parsed contents,
1305
+ * or an empty dictionary if the file cannot be fetched.
1255
1306
  */
1256
1307
  private static fetchLanguageFile;
1308
+ /**
1309
+ * Fetch and parse all translation files from a language folder.
1310
+ * First attempts to load a manifest file listing all translation files,
1311
+ * then falls back to trying common file names.
1312
+ * Returns empty dict if folder doesn't exist or has no valid files.
1313
+ */
1314
+ private static fetchLanguageFolder;
1257
1315
  /**
1258
1316
  * Parse the raw content of a language file into a TranslationDict.
1259
1317
  * Ignores empty lines and comments starting with '#'.
1260
1318
  */
1261
- private static parseLanguageFile;
1319
+ private static parseTranslation;
1262
1320
  }
1263
1321
  /**
1264
1322
  * Retrieve a localized string for the given source tag.
@@ -1266,7 +1324,7 @@ declare module 'bc-deeplib/utilities/translation' {
1266
1324
  * then falls back to the library translation,
1267
1325
  * and if neither exist, returns the source tag itself.
1268
1326
  */
1269
- export const getText: (srcTag: string) => string;
1327
+ export const getText: (srcTag: string, replacements?: Record<string, string | number | boolean>) => string;
1270
1328
 
1271
1329
  }
1272
1330
  declare module 'bc-deeplib' {