zois-core 2.1.1 → 2.2.1
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/scripts/zois-core.js +18 -0
- package/dist/shards/inputListShard.js +3 -3
- 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 +3 -2
- package/scripts/zois-core.mjs +0 -126
|
@@ -118,7 +118,7 @@ class InputListShard extends Shard {
|
|
|
118
118
|
items.splice(0, items.length);
|
|
119
119
|
itemsElement.append(input);
|
|
120
120
|
value?.forEach((v) => addItem(String(v)));
|
|
121
|
-
if (typeof onChange === "function") onChange(numbersOnly ? items.map((i) => parseInt(i)) : items);
|
|
121
|
+
if (typeof onChange === "function") onChange(numbersOnly ? items.map((i) => parseInt(i, 10)) : items);
|
|
122
122
|
});
|
|
123
123
|
addButton(createElement(Trash2), () => {
|
|
124
124
|
if (typeof isDisabled === "function" && isDisabled()) return div.classList.add("zcDisabled");
|
|
@@ -128,7 +128,7 @@ class InputListShard extends Shard {
|
|
|
128
128
|
c.remove();
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
if (typeof onChange === "function") onChange(numbersOnly ? items.map((i) => parseInt(i)) : items);
|
|
131
|
+
if (typeof onChange === "function") onChange(numbersOnly ? items.map((i) => parseInt(i, 10)) : items);
|
|
132
132
|
});
|
|
133
133
|
if (typeof isDisabled === "function" && isDisabled()) div.classList.add("zcDisabled");
|
|
134
134
|
input.addEventListener("keypress", (e) => {
|
|
@@ -140,7 +140,7 @@ class InputListShard extends Shard {
|
|
|
140
140
|
if (typeof isDisabled === "function" && isDisabled()) return div.classList.add("zcDisabled");
|
|
141
141
|
addItem(input.value);
|
|
142
142
|
input.value = "";
|
|
143
|
-
if (typeof onChange === "function") onChange(numbersOnly ? items.map((i) => parseInt(i)) : items);
|
|
143
|
+
if (typeof onChange === "function") onChange(numbersOnly ? items.map((i) => parseInt(i, 10)) : items);
|
|
144
144
|
break;
|
|
145
145
|
}
|
|
146
146
|
}
|
package/dist/styles.css
CHANGED
|
@@ -199,6 +199,27 @@
|
|
|
199
199
|
border-right-color: rgb(42, 42, 42);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
+
@keyframes zcStrokeUD {
|
|
203
|
+
0%, 100% {
|
|
204
|
+
transform: translateY(0) rotate(-25deg);
|
|
205
|
+
}
|
|
206
|
+
50% {
|
|
207
|
+
transform: translateY(15px) rotate(-45deg);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
@keyframes zcFloatHeart {
|
|
211
|
+
0% {
|
|
212
|
+
transform: translateY(0) scale(0.5);
|
|
213
|
+
opacity: 0;
|
|
214
|
+
}
|
|
215
|
+
15% {
|
|
216
|
+
opacity: 1;
|
|
217
|
+
}
|
|
218
|
+
100% {
|
|
219
|
+
transform: translateY(-70px) scale(1.1);
|
|
220
|
+
opacity: 0;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
202
223
|
.zcCursor {
|
|
203
224
|
border-right: 2px solid var(--tmd-text, rgb(42, 42, 42));
|
|
204
225
|
width: fit-content;
|
package/dist/toasts.js
CHANGED
|
@@ -149,32 +149,58 @@ class ToastsManager {
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Displays informational toast.
|
|
154
|
+
* @param options - Title, message and duration of toast.
|
|
155
|
+
*/
|
|
152
156
|
info({ title, message, duration }) {
|
|
153
157
|
const id = this.generateToastId();
|
|
154
158
|
const theme = MOD_DATA.singleToastsTheme;
|
|
155
159
|
this.process({ title, message, duration, type: "info", id, theme });
|
|
156
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Displays success toast.
|
|
163
|
+
* @param options - Title, message and duration of toast.
|
|
164
|
+
*/
|
|
157
165
|
success({ title, message, duration }) {
|
|
158
166
|
const id = this.generateToastId();
|
|
159
167
|
const theme = MOD_DATA.singleToastsTheme;
|
|
160
168
|
this.process({ title, message, duration, type: "success", id, theme });
|
|
161
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Displays warning toast.
|
|
172
|
+
* @param options - Title, message and duration of toast.
|
|
173
|
+
*/
|
|
162
174
|
warn({ title, message, duration }) {
|
|
163
175
|
const id = this.generateToastId();
|
|
164
176
|
const theme = MOD_DATA.singleToastsTheme;
|
|
165
177
|
this.process({ title, message, duration, type: "warning", id, theme });
|
|
166
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Displays error toast.
|
|
181
|
+
* @param options - Title, message and duration of toast.
|
|
182
|
+
*/
|
|
167
183
|
error({ title, message, duration }) {
|
|
168
184
|
const id = this.generateToastId();
|
|
169
185
|
const theme = MOD_DATA.singleToastsTheme;
|
|
170
186
|
this.process({ title, message, duration, type: "error", id, theme });
|
|
171
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Displays a long-running spinner toast and returns its ID.
|
|
190
|
+
* Toast can be deleted manually with `toastsManager.removeSpinner(ID)` or by the user by clicking.
|
|
191
|
+
* @param options - Title and message of toast.
|
|
192
|
+
* @returns The unique ID of the created spinner toast.
|
|
193
|
+
*/
|
|
172
194
|
spinner({ title, message }) {
|
|
173
195
|
const id = this.generateToastId();
|
|
174
196
|
const theme = MOD_DATA.singleToastsTheme;
|
|
175
197
|
this.process({ title, message, duration: 1e6, type: "spinner", id, theme });
|
|
176
198
|
return id;
|
|
177
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Removes a spinner toast by its ID.
|
|
202
|
+
* @param id - Unique ID of the spinner toast to remove.
|
|
203
|
+
*/
|
|
178
204
|
removeSpinner(id) {
|
|
179
205
|
const toast = document.querySelector(`div[data-zc-toast-id="${id}"]`);
|
|
180
206
|
if (!toast) return;
|
|
@@ -9,7 +9,7 @@ export declare abstract class CoreSubscreen extends BaseSubscreen {
|
|
|
9
9
|
createText(ctx: TextShardContext): HTMLParagraphElement;
|
|
10
10
|
createButton(ctx: ButtonShardContext): HTMLButtonElement;
|
|
11
11
|
createCheckbox(ctx: CheckboxShardContext): HTMLDivElement;
|
|
12
|
-
createInputList(ctx: InputListShardContext): HTMLDivElement;
|
|
12
|
+
createInputList<NumbersOnly extends boolean>(ctx: InputListShardContext<NumbersOnly>): HTMLDivElement;
|
|
13
13
|
createSelect(ctx: SelectShardContext): HTMLDivElement;
|
|
14
14
|
unload(): void;
|
|
15
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InputListShard } from "../../shards";
|
|
2
2
|
import { DynamicClassStyles } from "../../ui";
|
|
3
|
-
export declare class CoreInputListShard extends InputListShard {
|
|
3
|
+
export declare class CoreInputListShard<NumbersOnly extends boolean> extends InputListShard<NumbersOnly> {
|
|
4
4
|
get dynamicClassContainer(): DynamicClassStyles;
|
|
5
5
|
get dynamicClassToolsButton(): DynamicClassStyles;
|
|
6
6
|
}
|
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 {};
|