zois-core 2.1.0 → 2.2.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/assets/icons/hand.svg +1 -0
- package/dist/changelogs.js +154 -30
- package/dist/logging.js +19 -0
- package/dist/messaging.js +78 -9
- package/dist/modSdk.js +12 -2
- package/dist/shards/inputListShard.js +3 -3
- package/dist/shards/tabsShard.js +2 -1
- package/dist/styles.css +21 -0
- package/dist/toasts.js +26 -0
- package/dist/types/core-subscreen/coreSubscreen.d.ts +1 -1
- package/dist/types/core-subscreen/shards/coreInputListShard.d.ts +1 -1
- package/dist/types/index.d.ts +33 -4
- package/dist/types/logging.d.ts +25 -0
- package/dist/types/messaging.d.ts +62 -1
- package/dist/types/modSdk.d.ts +49 -1
- package/dist/types/shards/inputListShard.d.ts +6 -6
- package/dist/types/toasts.d.ts +29 -0
- package/dist/types/ui.d.ts +135 -5
- package/dist/ui.js +74 -36
- package/package.json +2 -1
- package/scripts/zois-core.mjs +84 -26
package/dist/types/index.d.ts
CHANGED
|
@@ -28,14 +28,16 @@ export interface ModData {
|
|
|
28
28
|
changelog?: {
|
|
29
29
|
data: {
|
|
30
30
|
generated_at: string;
|
|
31
|
+
contributors: {
|
|
32
|
+
name: string;
|
|
33
|
+
avatar_url: string;
|
|
34
|
+
is_owner: boolean;
|
|
35
|
+
}[];
|
|
31
36
|
changes: {
|
|
32
37
|
message: string;
|
|
33
38
|
note?: string;
|
|
34
39
|
sha: string;
|
|
35
|
-
author:
|
|
36
|
-
name: string;
|
|
37
|
-
avatar_url: string;
|
|
38
|
-
};
|
|
40
|
+
author: string;
|
|
39
41
|
date: string;
|
|
40
42
|
tags: ChangelogEntryTag[];
|
|
41
43
|
commit_url: string;
|
|
@@ -46,6 +48,10 @@ export interface ModData {
|
|
|
46
48
|
}
|
|
47
49
|
export { version } from "../package.json";
|
|
48
50
|
export declare let MOD_DATA: ModData;
|
|
51
|
+
/**
|
|
52
|
+
* Bootstraps the mod by initializing core systems and setting up essential hooks and event listeners.
|
|
53
|
+
* @param modData - The mod configuration.
|
|
54
|
+
*/
|
|
49
55
|
export declare function bootstrap(modData: ModData): void;
|
|
50
56
|
export declare function formatString(text: string): ({
|
|
51
57
|
html: string;
|
|
@@ -54,11 +60,34 @@ export declare function formatString(text: string): ({
|
|
|
54
60
|
isBeatifulString: false;
|
|
55
61
|
});
|
|
56
62
|
export declare function sleep(ms: number): Promise<() => {}>;
|
|
63
|
+
/**
|
|
64
|
+
* Waits until the provided condition function returns `true`.
|
|
65
|
+
* Optionally supports a cancel condition that aborts the wait early.
|
|
66
|
+
* Checks the conditions every 10 milliseconds.
|
|
67
|
+
* @param func - The condition function that must return `true` to resolve.
|
|
68
|
+
* @param cancelFunc - Optional function that returns `true` to cancel the wait. Defaults to `() => false`.
|
|
69
|
+
* @returns A promise that resolves to `true` if the condition was met, or `false` if cancelled.
|
|
70
|
+
*/
|
|
57
71
|
export declare function waitFor(func: () => boolean, cancelFunc?: () => boolean): Promise<boolean>;
|
|
58
72
|
export declare function getRandomNumber(min: number, max: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Compares two version strings and determines whether the first version is newer than the second.
|
|
75
|
+
* Versions are split by dots and compared numerically part by part.
|
|
76
|
+
* Missing parts are treated as zero.
|
|
77
|
+
* @param version1 - The first version string to compare.
|
|
78
|
+
* @param version2 - The second version string to compare against.
|
|
79
|
+
* @returns `true` if `version1` is newer than `version2`, otherwise `false`.
|
|
80
|
+
*/
|
|
59
81
|
export declare function isVersionNewer(version1: string, version2: string): boolean;
|
|
60
82
|
export declare function colorsEqual(c1: string[] | string | null | undefined, c2: string[] | string | null | undefined): boolean;
|
|
61
83
|
export declare function getSizeInKbytes(b: any): number;
|
|
84
|
+
/**
|
|
85
|
+
* Finds a character in the current chat room by member number, name, or nickname.
|
|
86
|
+
*
|
|
87
|
+
* The search is **case-insensitive**.
|
|
88
|
+
* @param value - The member number, name, or nickname to search for.
|
|
89
|
+
* @returns The matching `Character` object, or `null` if not found.
|
|
90
|
+
*/
|
|
62
91
|
export declare function getPlayer(value: string | number): Character | null;
|
|
63
92
|
export declare function getNickname(target: Character): string;
|
|
64
93
|
export declare function injectStyles(stylesToInject: string): void;
|
package/dist/types/logging.d.ts
CHANGED
|
@@ -5,12 +5,37 @@ interface LogEntry {
|
|
|
5
5
|
timestamp: number;
|
|
6
6
|
}
|
|
7
7
|
declare class Logger {
|
|
8
|
+
/**
|
|
9
|
+
* Returns the list of all recorded log entries.
|
|
10
|
+
*/
|
|
8
11
|
get logs(): LogEntry[];
|
|
9
12
|
private pushLog;
|
|
13
|
+
/**
|
|
14
|
+
* Logs a debug-level message.
|
|
15
|
+
* @param message - The message arguments to log.
|
|
16
|
+
*/
|
|
10
17
|
debug(...message: unknown[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* Logs a standard-level message.
|
|
20
|
+
* @param message - The message arguments to log.
|
|
21
|
+
*/
|
|
11
22
|
log(...message: unknown[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Logs a warning-level message.
|
|
25
|
+
* @param message - The message arguments to log.
|
|
26
|
+
*/
|
|
12
27
|
warn(...message: unknown[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Logs an error-level message.
|
|
30
|
+
* @param message - The message arguments to log.
|
|
31
|
+
*/
|
|
13
32
|
error(...message: unknown[]): void;
|
|
14
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Logger for collecting and outputting log messages with different severity levels.
|
|
36
|
+
* Logs are stored internally and also printed to the console with a colored prefix.
|
|
37
|
+
*
|
|
38
|
+
* **USE ONLY IN BROWSER ENVIRONMENT**
|
|
39
|
+
*/
|
|
15
40
|
export declare const logger: Logger;
|
|
16
41
|
export {};
|
|
@@ -6,21 +6,82 @@ type RequestResponse<T> = {
|
|
|
6
6
|
isError: true;
|
|
7
7
|
};
|
|
8
8
|
declare class MessagesManager {
|
|
9
|
+
/**
|
|
10
|
+
* Sends beep message to a specific player.
|
|
11
|
+
* @param data - The data to send in the beep.
|
|
12
|
+
* @param targetId - The member number of the target player.
|
|
13
|
+
*/
|
|
9
14
|
sendBeep<T>(data: T, targetId: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* Sends hidden packet message to the chat room or a specific player.
|
|
17
|
+
* @param msg - The message identifier.
|
|
18
|
+
* @param _data - Optional data payload to include.
|
|
19
|
+
* @param targetNumber - Optional target player member number.
|
|
20
|
+
*/
|
|
10
21
|
sendPacket<T>(msg: string, _data?: T, targetNumber?: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Sends a custom action message to the chat room with automatic pronoun replacement.
|
|
24
|
+
*
|
|
25
|
+
* Replaces placeholders such as `<Possessive>`, `<Intensive>`, `<SelfIntensive>`, and `<Pronoun>`.
|
|
26
|
+
* @param msg - The action message text.
|
|
27
|
+
* @param target - Optional target player member number.
|
|
28
|
+
* @param dictionary - Optional additional dictionary entries.
|
|
29
|
+
*/
|
|
11
30
|
sendAction(msg: string, target?: undefined | number, dictionary?: ChatMessageDictionaryEntry[]): void;
|
|
12
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Sends a request to a target player and waits for a response.
|
|
33
|
+
*
|
|
34
|
+
* Supports both packet and beep transport. Automatically times out after 6 seconds.
|
|
35
|
+
* @param options - Request configuration.
|
|
36
|
+
* @param options.message - The request message identifier.
|
|
37
|
+
* @param options.data - Optional data to send with the request.
|
|
38
|
+
* @param options.target - Target player member number.
|
|
39
|
+
* @param options.type - Transport type: `"packet"` or `"beep"`.
|
|
40
|
+
* @returns A promise that resolves with the response data or an error flag.
|
|
41
|
+
*/
|
|
42
|
+
sendRequest<T>({ message, data, target, type, responseDto }: {
|
|
13
43
|
message: string;
|
|
14
44
|
data?: unknown;
|
|
15
45
|
target: number;
|
|
16
46
|
type: "packet" | "beep";
|
|
47
|
+
responseDto?: ClassConstructor<unknown>;
|
|
17
48
|
}): Promise<RequestResponse<T>>;
|
|
49
|
+
/**
|
|
50
|
+
* Displays a local message in the chat log (visible only to the current player).
|
|
51
|
+
* @param message - The message content as a string or DOM node.
|
|
52
|
+
*/
|
|
18
53
|
sendLocal(message: string | Node): void;
|
|
54
|
+
/**
|
|
55
|
+
* Sends a regular chat message to the chat room.
|
|
56
|
+
* @param message - The chat message content.
|
|
57
|
+
*/
|
|
19
58
|
sendChat(message: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Registers a listener for incoming requests of a specific message type.
|
|
61
|
+
* Supports optional DTO validation. Works with both packet and beep transports.
|
|
62
|
+
* @param message - The request message identifier to listen for.
|
|
63
|
+
* @param dtoOrListener - Optional DTO class constructor or the listener function.
|
|
64
|
+
* @param listener - The listener function.
|
|
65
|
+
* @returns A cleanup function that removes the registered listeners.
|
|
66
|
+
*/
|
|
20
67
|
onRequest(message: string, listener: (data: any, sender: Character | number, senderName?: string) => unknown): () => void;
|
|
21
68
|
onRequest(message: string, dto: ClassConstructor<unknown>, listener: (data: any, sender: Character | number, senderName?: string) => unknown): () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Registers a listener for incoming packet messages of a specific type.
|
|
71
|
+
* Supports optional DTO validation.
|
|
72
|
+
* @param message - The packet message identifier to listen for.
|
|
73
|
+
* @param dtoOrListener - Optional DTO class constructor or the listener function.
|
|
74
|
+
* @param listener - The listener function.
|
|
75
|
+
* @returns A cleanup function that removes the registered listener.
|
|
76
|
+
*/
|
|
22
77
|
onPacket(message: string, listener: (data: any, sender: Character) => void): () => void;
|
|
23
78
|
onPacket(message: string, dto: ClassConstructor<unknown>, listener: (data: any, sender: Character) => void): () => void;
|
|
24
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Manager for sending and receiving messages, packets, beeps, actions, and requests
|
|
82
|
+
* between players in the chat room.
|
|
83
|
+
* Supports both packet-based and beep-based communication, request-response patterns,
|
|
84
|
+
* local messages, and custom actions with pronoun replacement.
|
|
85
|
+
*/
|
|
25
86
|
export declare const messagesManager: MessagesManager;
|
|
26
87
|
export {};
|
package/dist/types/modSdk.d.ts
CHANGED
|
@@ -8,8 +8,56 @@ export declare enum HookPriority {
|
|
|
8
8
|
}
|
|
9
9
|
export declare let modSdk: ModSDKModAPI;
|
|
10
10
|
export declare function createModSdk(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Hook a BC function.
|
|
13
|
+
* @template TFunctionName - The name of the hooked function, _e.g._ `"Player.CanChange"`
|
|
14
|
+
* @param functionName - Name of function to hook. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
|
|
15
|
+
* @param priority - Number used to determinate order hooks will be called in. Higher number is called first
|
|
16
|
+
* @param hook - The hook itself to use, @see PatchHook
|
|
17
|
+
* @returns Function that can be called to remove this hook
|
|
18
|
+
*/
|
|
11
19
|
export declare function hookFunction<TFunctionName extends string>(functionName: TFunctionName, priority: HookPriority, hook: PatchHook<GetDotedPathType<typeof globalThis, TFunctionName>>): () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Patch a BC function
|
|
22
|
+
*
|
|
23
|
+
* **This method is DANGEROUS** to use and has high potential to conflict with other mods.
|
|
24
|
+
*
|
|
25
|
+
* Only use it if what you are trying to accomplish can't be done easily with `hookFunction`.
|
|
26
|
+
*
|
|
27
|
+
* This function tranforms BC function to string, replaces patches as pure text and then `eval`uates it.
|
|
28
|
+
* If you don't know what this means, please avoid this function.
|
|
29
|
+
* @template TFunctionName - The name of the patched function, _e.g._ `"Player.CanChange"`
|
|
30
|
+
* @param functionName - Name of function to patch. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
|
|
31
|
+
* @param patches - Object in key: value format, where keys are chunks to replace and values are result.
|
|
32
|
+
*
|
|
33
|
+
* Patches from multiple calls are merged; where key matches the older one is replaced.
|
|
34
|
+
* Specifying value of `null` removes patch with this key.
|
|
35
|
+
*/
|
|
12
36
|
export declare function patchFunction(functionName: string, patches: Record<string, string | null>): void;
|
|
13
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Call original function, bypassing any hooks and ignoring any patches applied by ALL mods.
|
|
39
|
+
* @template TFunctionName - The name of the called function, _e.g._ `"Player.CanChange"`
|
|
40
|
+
* @param functionName - Name of function to call. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
|
|
41
|
+
* @param args - Arguments to use for the call
|
|
42
|
+
*/
|
|
43
|
+
export declare function callOriginal<TFunctionName extends string>(target: TFunctionName, args: [...Parameters<GetDotedPathType<typeof globalThis, TFunctionName>>]): ReturnType<GetDotedPathType<typeof globalThis, TFunctionName>> | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Returns info about all registered mods.
|
|
46
|
+
*/
|
|
14
47
|
export declare function getLoadedMods(): ModSDKModInfo[];
|
|
48
|
+
/**
|
|
49
|
+
* Determines whether a mod with the specified name is registered.
|
|
50
|
+
*/
|
|
15
51
|
export declare function findModByName(name: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get hash of original function in CRC32.
|
|
54
|
+
*
|
|
55
|
+
* The hash is computed from source obtained using `toString` with line endings normalized to LF
|
|
56
|
+
* @param functionName - Name of function. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
|
|
57
|
+
*/
|
|
58
|
+
export declare function getOriginalHash(functionName: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Remove all patches by `patchFunction` from specified function.
|
|
61
|
+
* @param functionName - Name of function to patch. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
|
|
62
|
+
*/
|
|
63
|
+
export declare function removePatches(functionName: string): void;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { DynamicClassStyles } from "../ui";
|
|
2
2
|
import { Shard, ShardContext } from "./shard";
|
|
3
|
-
export interface InputListShardContext<
|
|
4
|
-
value?:
|
|
3
|
+
export interface InputListShardContext<NumbersOnly extends boolean> extends ShardContext<"input"> {
|
|
4
|
+
value?: NumbersOnly extends true ? number[] : (string | number)[];
|
|
5
5
|
title?: string;
|
|
6
6
|
fontSize?: number | "auto";
|
|
7
|
-
numbersOnly?:
|
|
8
|
-
onChange?: (value:
|
|
7
|
+
numbersOnly?: NumbersOnly;
|
|
8
|
+
onChange?: (value: NumbersOnly extends true ? number[] : (string | number)[]) => void;
|
|
9
9
|
isDisabled?: () => boolean;
|
|
10
10
|
}
|
|
11
|
-
export declare class InputListShard extends Shard<InputListShardContext
|
|
11
|
+
export declare class InputListShard<NumbersOnly extends boolean> extends Shard<InputListShardContext<NumbersOnly>> {
|
|
12
12
|
protected get dynamicClassContainer(): DynamicClassStyles;
|
|
13
13
|
protected get dynamicClassInput(): DynamicClassStyles;
|
|
14
14
|
protected get dynamicClassToolsButton(): DynamicClassStyles;
|
|
15
|
-
protected generateBody(): Record<keyof NonNullable<InputListShardContext<
|
|
15
|
+
protected generateBody(): Record<keyof NonNullable<InputListShardContext<NumbersOnly>["modules"]>, HTMLElement | SVGElement>;
|
|
16
16
|
}
|
package/dist/types/toasts.d.ts
CHANGED
|
@@ -10,12 +10,41 @@ interface Toast {
|
|
|
10
10
|
export declare class ToastsManager {
|
|
11
11
|
private generateToastId;
|
|
12
12
|
private process;
|
|
13
|
+
/**
|
|
14
|
+
* Displays informational toast.
|
|
15
|
+
* @param options - Title, message and duration of toast.
|
|
16
|
+
*/
|
|
13
17
|
info({ title, message, duration }: Omit<Toast, "type" | "id" | "theme">): void;
|
|
18
|
+
/**
|
|
19
|
+
* Displays success toast.
|
|
20
|
+
* @param options - Title, message and duration of toast.
|
|
21
|
+
*/
|
|
14
22
|
success({ title, message, duration }: Omit<Toast, "type" | "id" | "theme">): void;
|
|
23
|
+
/**
|
|
24
|
+
* Displays warning toast.
|
|
25
|
+
* @param options - Title, message and duration of toast.
|
|
26
|
+
*/
|
|
15
27
|
warn({ title, message, duration }: Omit<Toast, "type" | "id" | "theme">): void;
|
|
28
|
+
/**
|
|
29
|
+
* Displays error toast.
|
|
30
|
+
* @param options - Title, message and duration of toast.
|
|
31
|
+
*/
|
|
16
32
|
error({ title, message, duration }: Omit<Toast, "type" | "id" | "theme">): void;
|
|
33
|
+
/**
|
|
34
|
+
* Displays a long-running spinner toast and returns its ID.
|
|
35
|
+
* Toast can be deleted manually with `toastsManager.removeSpinner(ID)` or by the user by clicking.
|
|
36
|
+
* @param options - Title and message of toast.
|
|
37
|
+
* @returns The unique ID of the created spinner toast.
|
|
38
|
+
*/
|
|
17
39
|
spinner({ title, message }: Omit<Toast, "type" | "id" | "duration" | "theme">): string;
|
|
40
|
+
/**
|
|
41
|
+
* Removes a spinner toast by its ID.
|
|
42
|
+
* @param id - Unique ID of the spinner toast to remove.
|
|
43
|
+
*/
|
|
18
44
|
removeSpinner(id: string): void;
|
|
19
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Toast notifications controller, alternative to BC's native `ToastManager`.
|
|
48
|
+
*/
|
|
20
49
|
export declare const toastsManager: ToastsManager;
|
|
21
50
|
export {};
|
package/dist/types/ui.d.ts
CHANGED
|
@@ -31,42 +31,173 @@ export declare function dataUrlSvgWithColor(dataUrl: string, newColor: {
|
|
|
31
31
|
stroke?: string;
|
|
32
32
|
}): string;
|
|
33
33
|
export declare function dataUrlSvgReplaceVars(dataUrl: string, vars: Record<string, string>): string;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the value of a CSS variable if it exists, otherwise returns the provided fallback.
|
|
36
|
+
* @param name - The name of the CSS variable (e.g. `"--button-color"`).
|
|
37
|
+
* @param fallback - The fallback value to return if the CSS variable is not set or empty.
|
|
38
|
+
* @returns The resolved CSS variable value or the fallback.
|
|
39
|
+
*/
|
|
34
40
|
export declare function cssVar(name: string, fallback: string): string;
|
|
35
41
|
export declare function getRelativeHeight(height: number): number;
|
|
36
42
|
export declare function getRelativeWidth(width: number): number;
|
|
37
43
|
export declare function getRelativeY(yPos: number, anchorPosition?: 'top' | 'bottom'): number;
|
|
38
44
|
export declare function getRelativeX(xPos: number, anchorPosition?: 'left' | 'right'): number;
|
|
45
|
+
/**
|
|
46
|
+
* Sets the position of the given HTML element relative to the specified anchor point.
|
|
47
|
+
* Position scaled relative to the current size of the main canvas.
|
|
48
|
+
* @param element - The HTML element to position.
|
|
49
|
+
* @param xPos - The base horizontal position value.
|
|
50
|
+
* @param yPos - The base vertical position value.
|
|
51
|
+
* @param anchor - The anchor point used for positioning. Defaults to `"top-left"`.
|
|
52
|
+
* @returns void
|
|
53
|
+
*/
|
|
39
54
|
export declare function setPosition(element: HTMLElement, xPos: number, yPos: number, anchor?: Anchor): void;
|
|
55
|
+
/**
|
|
56
|
+
* Sets the width and height of the given element,
|
|
57
|
+
* scaled relative to the current size of the main canvas.
|
|
58
|
+
* @param element - The element whose size should be updated.
|
|
59
|
+
* @param width - The base width value.
|
|
60
|
+
* @param height - The base height value.
|
|
61
|
+
* @returns void
|
|
62
|
+
*/
|
|
40
63
|
export declare function setSize(element: HTMLElement | SVGElement, width: number, height: number): void;
|
|
64
|
+
/**
|
|
65
|
+
* Sets the font size of the given HTML element based on a target font size value,
|
|
66
|
+
* scaled relative to the current size of the main canvas.
|
|
67
|
+
* @param element - The HTML element whose font size should be updated.
|
|
68
|
+
* @param targetFontSize - The base font size value to be scaled.
|
|
69
|
+
* @returns void
|
|
70
|
+
*/
|
|
41
71
|
export declare function setFontSize(element: HTMLElement, targetFontSize: number): void;
|
|
72
|
+
/**
|
|
73
|
+
* Sets the font family of the given HTML element.
|
|
74
|
+
* @param element - The HTML element whose font family should be updated.
|
|
75
|
+
* @param fontFamily - Optional font family name. Defaults to `"sans-serif"`.
|
|
76
|
+
* @returns void
|
|
77
|
+
*/
|
|
42
78
|
export declare function setFontFamily(element: HTMLElement, fontFamily?: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* Sets the padding of the given HTML element based on a target padding value,
|
|
81
|
+
* scaled relative to the current size of the main canvas.
|
|
82
|
+
* @param element - The HTML element whose padding should be updated.
|
|
83
|
+
* @param targetPadding - The base padding value to be scaled.
|
|
84
|
+
* @returns void
|
|
85
|
+
*/
|
|
43
86
|
export declare function setPadding(element: HTMLElement, targetPadding: number): void;
|
|
87
|
+
/**
|
|
88
|
+
* Automatically sets the font size of the given HTML element based on the current size of the main canvas.
|
|
89
|
+
* @param element - The HTML element whose font size should be updated.
|
|
90
|
+
* @returns void
|
|
91
|
+
*/
|
|
44
92
|
export declare function autosetFontSize(element: HTMLElement): void;
|
|
45
93
|
export declare function setSizeUnitVariable(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Adds a dynamically generated CSS class to the specified element.
|
|
96
|
+
*
|
|
97
|
+
* The function checks a cache of previously created classes using a key generated from the provided styles.
|
|
98
|
+
* If a class with the same styles already exists, it simply adds that class name to the element.
|
|
99
|
+
* Otherwise, it generates a unique class name (`dynamic-...`) with the corresponding CSS rules
|
|
100
|
+
* (including pseudo-classes `:hover`, `:active`, `:focus`, `:disabled` and pseudo-elements `::before`, `::after`),
|
|
101
|
+
*
|
|
102
|
+
* @param targetElement - The element to which the dynamic class should be applied.
|
|
103
|
+
* @param styles - An object of type `DynamicClassStyles`. Can contain:
|
|
104
|
+
* - `base` — base styles;
|
|
105
|
+
* - keys `hover`, `active`, `focus`, `disabled`, `before`, `after` — styles for the corresponding pseudo-classes/pseudo-elements;
|
|
106
|
+
* - any other keys — additional selectors in the form `.className{key}`.
|
|
107
|
+
* @returns `void`
|
|
108
|
+
*/
|
|
46
109
|
export declare function addDynamicClass(targetElement: HTMLElement | SVGElement, styles: DynamicClassStyles): void;
|
|
47
110
|
export declare function setPreviousSubscreen(): void;
|
|
48
111
|
export declare function setSubscreen(subscreen: BaseSubscreen | null): void;
|
|
49
112
|
export declare function getCurrentSubscreen(): BaseSubscreen | null;
|
|
50
113
|
export declare function getPreviousSubscreen(): BaseSubscreen | null;
|
|
114
|
+
/**
|
|
115
|
+
* Abstract class to define subscreens with lifecycle management, UI element creation and navigation functionality.
|
|
116
|
+
*/
|
|
51
117
|
export declare abstract class BaseSubscreen {
|
|
52
118
|
protected readonly setSubscreen: typeof setSubscreen;
|
|
53
|
-
|
|
54
|
-
get
|
|
119
|
+
protected readonly setPreviousSubscreen: typeof setPreviousSubscreen;
|
|
120
|
+
protected get currentSubscreen(): BaseSubscreen | null;
|
|
121
|
+
protected get previousSubscreen(): BaseSubscreen | null;
|
|
55
122
|
abstract get name(): string;
|
|
123
|
+
/**
|
|
124
|
+
* Called each frame.
|
|
125
|
+
*
|
|
126
|
+
* You probably want to override {@link onRun}, **do not** override `run` if you don't understand what you're doing.
|
|
127
|
+
*/
|
|
56
128
|
run(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Called each frame.
|
|
131
|
+
*/
|
|
132
|
+
protected onRun?(): void;
|
|
133
|
+
/**
|
|
134
|
+
* Called once after `setSubscreen()`.
|
|
135
|
+
* Responsible for how the subscreen will load.
|
|
136
|
+
*
|
|
137
|
+
* You probably want to override {@link onLoad}, **do not** override `load` if you don't understand what you're doing.
|
|
138
|
+
*
|
|
139
|
+
* Override {@link onLoad} for creating UI elements.
|
|
140
|
+
*/
|
|
57
141
|
load(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Called once after `setSubscreen()`.
|
|
144
|
+
*
|
|
145
|
+
* Create UI elements here.
|
|
146
|
+
*/
|
|
147
|
+
protected onLoad?(): void;
|
|
148
|
+
/**
|
|
149
|
+
* Called once when subscreen is being unloaded.
|
|
150
|
+
*
|
|
151
|
+
* You probably want to override {@link onUnload}, **do not** override `unload` if you don't understand what you're doing.
|
|
152
|
+
*/
|
|
58
153
|
unload(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Called once when subscreen is being unloaded.
|
|
156
|
+
*/
|
|
157
|
+
protected onUnload?(): void;
|
|
158
|
+
/**
|
|
159
|
+
* Called after user clicks.
|
|
160
|
+
*
|
|
161
|
+
* You probably want to override {@link onClick}, **do not** override `click` if you don't understand what you're doing.
|
|
162
|
+
*/
|
|
59
163
|
click(): void;
|
|
164
|
+
/**
|
|
165
|
+
* Called after user clicks.
|
|
166
|
+
*/
|
|
167
|
+
protected onClick?(): void;
|
|
168
|
+
/**
|
|
169
|
+
* Called after user presses `Esc` or clicks on exit button.
|
|
170
|
+
*
|
|
171
|
+
* Not called after subscreen unloading with `setSubscreen()`
|
|
172
|
+
*
|
|
173
|
+
* You probably want to override {@link onExit}, **do not** override `exit` if you don't understand what you're doing.
|
|
174
|
+
*/
|
|
60
175
|
exit(): void;
|
|
176
|
+
/**
|
|
177
|
+
* Called after user presses `Esc` or clicks on exit button.
|
|
178
|
+
*
|
|
179
|
+
* Not called after subscreen unloading with `setSubscreen()`
|
|
180
|
+
*/
|
|
181
|
+
protected onExit?(): void;
|
|
61
182
|
update(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Called after screen size change.
|
|
185
|
+
*
|
|
186
|
+
* You probably want to override {@link onResize}, **do not** override `resize` if you don't understand what you're doing.
|
|
187
|
+
*/
|
|
62
188
|
resize(): void;
|
|
63
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Called after screen size change.
|
|
191
|
+
*/
|
|
192
|
+
protected onResize?(): void;
|
|
193
|
+
createExitButton(): void;
|
|
194
|
+
createSubscreenTitle(): void;
|
|
64
195
|
create(shard: Shard): HTMLElement;
|
|
65
196
|
createButton(ctx: ButtonShardContext): HTMLButtonElement;
|
|
66
197
|
createText(ctx: TextShardContext): HTMLParagraphElement;
|
|
67
198
|
createInput(ctx: InputShardContext): HTMLInputElement | HTMLTextAreaElement;
|
|
68
199
|
createCheckbox(ctx: CheckboxShardContext): HTMLDivElement;
|
|
69
|
-
createInputList(ctx: InputListShardContext): HTMLDivElement;
|
|
200
|
+
createInputList<NumbersOnly extends boolean>(ctx: InputListShardContext<NumbersOnly>): HTMLDivElement;
|
|
70
201
|
createImage(ctx: ImageShardContext): HTMLImageElement;
|
|
71
202
|
createSvg(ctx: SvgShardContext): SVGElement;
|
|
72
203
|
createBackNextButton(ctx: BackNextButtonShardContext): HTMLDivElement;
|
|
@@ -76,5 +207,4 @@ export declare abstract class BaseSubscreen {
|
|
|
76
207
|
createSelect(ctx: SelectShardContext): HTMLDivElement;
|
|
77
208
|
createContainer(ctx: ContainerShardContext): HTMLDivElement;
|
|
78
209
|
}
|
|
79
|
-
export declare function hookSubscreen(subscreenName: string, hook: (subscreen: BaseSubscreen) => void): void;
|
|
80
210
|
export {};
|
package/dist/ui.js
CHANGED
|
@@ -204,63 +204,107 @@ function getPreviousSubscreen() {
|
|
|
204
204
|
}
|
|
205
205
|
class BaseSubscreen {
|
|
206
206
|
setSubscreen = setSubscreen;
|
|
207
|
+
setPreviousSubscreen = setPreviousSubscreen;
|
|
207
208
|
get currentSubscreen() {
|
|
208
209
|
return getCurrentSubscreen();
|
|
209
210
|
}
|
|
210
211
|
get previousSubscreen() {
|
|
211
212
|
return getPreviousSubscreen();
|
|
212
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Called each frame.
|
|
216
|
+
*
|
|
217
|
+
* You probably want to override {@link onRun}, **do not** override `run` if you don't understand what you're doing.
|
|
218
|
+
*/
|
|
213
219
|
run() {
|
|
214
|
-
|
|
220
|
+
this.onRun?.();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Called once after `setSubscreen()`.
|
|
224
|
+
* Responsible for how the subscreen will load.
|
|
225
|
+
*
|
|
226
|
+
* You probably want to override {@link onLoad}, **do not** override `load` if you don't understand what you're doing.
|
|
227
|
+
*
|
|
228
|
+
* Override {@link onLoad} for creating UI elements.
|
|
229
|
+
*/
|
|
215
230
|
load() {
|
|
216
231
|
setSizeUnitVariable();
|
|
217
|
-
this.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
width: 90,
|
|
221
|
-
height: 90,
|
|
222
|
-
icon: dataUrlSvgWithColor(exitIcon, { fill: cssVar("--tmd-text", "black") }),
|
|
223
|
-
tooltip: {
|
|
224
|
-
position: "left",
|
|
225
|
-
text: "Back"
|
|
226
|
-
},
|
|
227
|
-
modules: {
|
|
228
|
-
base: [
|
|
229
|
-
new StyleModule({
|
|
230
|
-
zIndex: "10"
|
|
231
|
-
})
|
|
232
|
-
]
|
|
233
|
-
}
|
|
234
|
-
}).addEventListener("click", () => this.exit());
|
|
235
|
-
if (this.name) {
|
|
236
|
-
this.createText({
|
|
237
|
-
text: this.name,
|
|
238
|
-
x: 100,
|
|
239
|
-
y: 60,
|
|
240
|
-
fontSize: 8
|
|
241
|
-
}).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
|
|
242
|
-
}
|
|
232
|
+
this.createExitButton();
|
|
233
|
+
if (this.name) this.createSubscreenTitle();
|
|
234
|
+
this.onLoad?.();
|
|
243
235
|
eventBus?.emit("subscreenLoaded", {
|
|
244
236
|
subscreen: this
|
|
245
237
|
});
|
|
246
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Called once when subscreen is being unloaded.
|
|
241
|
+
*
|
|
242
|
+
* You probably want to override {@link onUnload}, **do not** override `unload` if you don't understand what you're doing.
|
|
243
|
+
*/
|
|
247
244
|
unload() {
|
|
245
|
+
this.onUnload?.();
|
|
248
246
|
eventBus?.emit("subscreenUnloaded", {
|
|
249
247
|
subscreen: this
|
|
250
248
|
});
|
|
251
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Called after user clicks.
|
|
252
|
+
*
|
|
253
|
+
* You probably want to override {@link onClick}, **do not** override `click` if you don't understand what you're doing.
|
|
254
|
+
*/
|
|
252
255
|
click() {
|
|
253
|
-
|
|
256
|
+
this.onClick?.();
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Called after user presses `Esc` or clicks on exit button.
|
|
260
|
+
*
|
|
261
|
+
* Not called after subscreen unloading with `setSubscreen()`
|
|
262
|
+
*
|
|
263
|
+
* You probably want to override {@link onExit}, **do not** override `exit` if you don't understand what you're doing.
|
|
264
|
+
*/
|
|
254
265
|
exit() {
|
|
266
|
+
this.onExit?.();
|
|
255
267
|
setPreviousSubscreen();
|
|
256
268
|
}
|
|
257
269
|
update() {
|
|
258
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Called after screen size change.
|
|
273
|
+
*
|
|
274
|
+
* You probably want to override {@link onResize}, **do not** override `resize` if you don't understand what you're doing.
|
|
275
|
+
*/
|
|
259
276
|
resize() {
|
|
260
277
|
setSizeUnitVariable();
|
|
278
|
+
this.onResize?.();
|
|
261
279
|
}
|
|
262
|
-
|
|
263
|
-
|
|
280
|
+
createExitButton() {
|
|
281
|
+
this.createButton({
|
|
282
|
+
x: 1815,
|
|
283
|
+
y: 75,
|
|
284
|
+
width: 90,
|
|
285
|
+
height: 90,
|
|
286
|
+
icon: dataUrlSvgWithColor(exitIcon, { fill: cssVar("--tmd-text", "black") }),
|
|
287
|
+
tooltip: {
|
|
288
|
+
position: "left",
|
|
289
|
+
text: "Back"
|
|
290
|
+
},
|
|
291
|
+
modules: {
|
|
292
|
+
base: [
|
|
293
|
+
new StyleModule({
|
|
294
|
+
zIndex: "10"
|
|
295
|
+
})
|
|
296
|
+
]
|
|
297
|
+
},
|
|
298
|
+
onClick: () => this.exit()
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
createSubscreenTitle() {
|
|
302
|
+
this.createText({
|
|
303
|
+
text: this.name,
|
|
304
|
+
x: 100,
|
|
305
|
+
y: 60,
|
|
306
|
+
fontSize: 8
|
|
307
|
+
}).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
|
|
264
308
|
}
|
|
265
309
|
create(shard) {
|
|
266
310
|
const htmlElement = shard.mount();
|
|
@@ -355,11 +399,6 @@ class BaseSubscreen {
|
|
|
355
399
|
return htmlElement;
|
|
356
400
|
}
|
|
357
401
|
}
|
|
358
|
-
const subscreenHooks = {};
|
|
359
|
-
function hookSubscreen(subscreenName, hook) {
|
|
360
|
-
if (!subscreenHooks[subscreenName]) subscreenHooks[subscreenName] = [];
|
|
361
|
-
subscreenHooks[subscreenName].push(hook);
|
|
362
|
-
}
|
|
363
402
|
export {
|
|
364
403
|
BaseSubscreen,
|
|
365
404
|
addDynamicClass,
|
|
@@ -374,7 +413,6 @@ export {
|
|
|
374
413
|
getRelativeX,
|
|
375
414
|
getRelativeY,
|
|
376
415
|
hexToRgb,
|
|
377
|
-
hookSubscreen,
|
|
378
416
|
recolorSVG,
|
|
379
417
|
setFontFamily,
|
|
380
418
|
setFontSize,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zois-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "The core for the my mods, which contains a shared code reused in all my mods",
|
|
5
5
|
"bin": {
|
|
6
6
|
"zois-core": "scripts/zois-core.mjs"
|
|
@@ -87,6 +87,7 @@
|
|
|
87
87
|
"esbuild-plugin-copy": "^2.1.1",
|
|
88
88
|
"glob": "^13.0.6",
|
|
89
89
|
"nodemon": "^3.1.14",
|
|
90
|
+
"simple-git": "^3.36.0",
|
|
90
91
|
"typescript": "^5.9.3"
|
|
91
92
|
},
|
|
92
93
|
"scripts": {
|