zois-core 2.0.6 → 2.1.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/changelogs.js +1 -0
- package/dist/core-subscreen/toastsSubscreen.js +2 -3
- package/dist/core.js +16 -4
- package/dist/events.js +116 -0
- package/dist/index.js +18 -44
- package/dist/shards/buttonShard.js +19 -18
- package/dist/shards/checkboxShard.js +1 -0
- package/dist/shards/imageShard.js +1 -1
- package/dist/shards/inputListShard.js +1 -0
- package/dist/shards/selectShard.js +5 -0
- package/dist/shards/shard.js +9 -6
- package/dist/shards/tabsShard.js +2 -1
- package/dist/shards/textShard.js +3 -1
- package/dist/styles.css +6 -6
- package/dist/toasts.js +2 -1
- package/dist/types/events.d.ts +50 -0
- package/dist/types/{globals.d.ts → global.d.ts} +2 -0
- package/dist/types/index.d.ts +1 -27
- package/dist/types/shards/backNextButtonShard.d.ts +2 -2
- package/dist/types/shards/buttonShard.d.ts +2 -2
- package/dist/types/shards/cardShard.d.ts +2 -2
- package/dist/types/shards/checkboxShard.d.ts +2 -2
- package/dist/types/shards/containerShard.d.ts +1 -1
- package/dist/types/shards/imageShard.d.ts +1 -1
- package/dist/types/shards/inputListShard.d.ts +1 -1
- package/dist/types/shards/inputShard.d.ts +2 -2
- package/dist/types/shards/selectShard.d.ts +2 -2
- package/dist/types/shards/shard.d.ts +1 -1
- package/dist/types/shards/svgShard.d.ts +2 -2
- package/dist/types/shards/tabsShard.d.ts +2 -2
- package/dist/types/shards/textShard.d.ts +2 -2
- package/dist/ui.js +7 -3
- package/package.json +5 -1
package/dist/changelogs.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { coreSettings } from "../core";
|
|
1
|
+
import { coreSettings, syncSettings } from "../core";
|
|
3
2
|
import { CoreSubscreen } from "./coreSubscreen";
|
|
4
3
|
import { toastsManager } from "../toasts";
|
|
5
4
|
class ToastsSubscreen extends CoreSubscreen {
|
|
@@ -82,7 +81,7 @@ class ToastsSubscreen extends CoreSubscreen {
|
|
|
82
81
|
padding: 1,
|
|
83
82
|
width: 400,
|
|
84
83
|
onClick: () => {
|
|
85
|
-
|
|
84
|
+
syncSettings();
|
|
86
85
|
toastsManager.success({
|
|
87
86
|
title: "Something was completed successfully",
|
|
88
87
|
message: "Message details",
|
package/dist/core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import styles from "./styles.css";
|
|
2
|
-
import { formatString, version,
|
|
2
|
+
import { formatString, version, waitFor } from "./index";
|
|
3
3
|
import { hookFunction, HookPriority } from "./modSdk";
|
|
4
4
|
import { getCurrentSubscreen, setSubscreen } from "./ui";
|
|
5
5
|
import { MainSubscreen } from "./core-subscreen/mainSubscreen";
|
|
@@ -7,12 +7,16 @@ import { createElement, Terminal } from "lucide";
|
|
|
7
7
|
import { ButtonShard, ContainerShard } from "./shards";
|
|
8
8
|
import { StyleModule } from "./shard-modules";
|
|
9
9
|
import { dialogsManager } from "./dialogs";
|
|
10
|
+
import { getEventBus } from "./events";
|
|
10
11
|
let coreSettings = {};
|
|
12
|
+
let coreEventBus = null;
|
|
11
13
|
function syncSettings() {
|
|
12
14
|
if (typeof coreSettings !== "object") return;
|
|
13
15
|
Player.ExtensionSettings.ZOIS_CORE = LZString.compressToBase64(JSON.stringify(coreSettings));
|
|
14
16
|
ServerPlayerExtensionSettingsSync("ZOIS_CORE");
|
|
15
|
-
|
|
17
|
+
coreEventBus?.emit("coreSettingsChanged", {
|
|
18
|
+
settings: structuredClone(coreSettings)
|
|
19
|
+
});
|
|
16
20
|
}
|
|
17
21
|
function registerSubscreen() {
|
|
18
22
|
PreferenceRegisterExtensionSetting({
|
|
@@ -29,6 +33,9 @@ function registerSubscreen() {
|
|
|
29
33
|
run: () => {
|
|
30
34
|
getCurrentSubscreen()?.run();
|
|
31
35
|
},
|
|
36
|
+
resize: () => {
|
|
37
|
+
getCurrentSubscreen()?.resize();
|
|
38
|
+
},
|
|
32
39
|
click: () => {
|
|
33
40
|
getCurrentSubscreen()?.click();
|
|
34
41
|
},
|
|
@@ -42,6 +49,7 @@ function registerCore() {
|
|
|
42
49
|
const style = document.createElement("style");
|
|
43
50
|
style.innerHTML = styles;
|
|
44
51
|
document.head.append(style);
|
|
52
|
+
coreEventBus = getEventBus("zois-core");
|
|
45
53
|
window.ZOIS_CORE = Object.freeze({
|
|
46
54
|
version,
|
|
47
55
|
enableDevMode: () => {
|
|
@@ -52,7 +60,8 @@ function registerCore() {
|
|
|
52
60
|
},
|
|
53
61
|
getSettings: () => {
|
|
54
62
|
return JSON.parse(JSON.stringify(coreSettings));
|
|
55
|
-
}
|
|
63
|
+
},
|
|
64
|
+
getEventBus
|
|
56
65
|
});
|
|
57
66
|
if (localStorage.getItem("autoConnectToDevServer") === "true") {
|
|
58
67
|
hookFunction("CommonGetServer", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
|
|
@@ -156,7 +165,10 @@ function registerCore() {
|
|
|
156
165
|
break;
|
|
157
166
|
}
|
|
158
167
|
default: {
|
|
159
|
-
|
|
168
|
+
coreEventBus?.emit("setSubscreen", {
|
|
169
|
+
target,
|
|
170
|
+
isTrusted: false
|
|
171
|
+
});
|
|
160
172
|
}
|
|
161
173
|
}
|
|
162
174
|
}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { MOD_DATA } from ".";
|
|
2
|
+
import { logger } from "./logging";
|
|
3
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
4
|
+
const onceListeners = /* @__PURE__ */ new Map();
|
|
5
|
+
function parseEventSpec(spec) {
|
|
6
|
+
const idx = spec.indexOf(":");
|
|
7
|
+
if (idx === -1) {
|
|
8
|
+
return { event: spec, senderFilter: null };
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
senderFilter: spec.slice(0, idx),
|
|
12
|
+
event: spec.slice(idx + 1)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
class EventBus {
|
|
16
|
+
#id;
|
|
17
|
+
get id() {
|
|
18
|
+
return this.#id;
|
|
19
|
+
}
|
|
20
|
+
constructor(id) {
|
|
21
|
+
this.#id = id;
|
|
22
|
+
}
|
|
23
|
+
emit(event, data) {
|
|
24
|
+
const fullData = { ...data, sender: this.id };
|
|
25
|
+
const commonEventListeners = listeners.get(event);
|
|
26
|
+
if (commonEventListeners) {
|
|
27
|
+
for (const listener of commonEventListeners) {
|
|
28
|
+
try {
|
|
29
|
+
if (listener.senderFilter) {
|
|
30
|
+
if (listener.senderFilter === this.id) listener.callback(fullData);
|
|
31
|
+
} else {
|
|
32
|
+
listener.callback(fullData);
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const onceEventListeners = onceListeners.get(event);
|
|
39
|
+
if (onceEventListeners) {
|
|
40
|
+
for (const listener of onceEventListeners) {
|
|
41
|
+
try {
|
|
42
|
+
if (listener.senderFilter) {
|
|
43
|
+
if (listener.senderFilter === this.id) {
|
|
44
|
+
listener.callback(fullData);
|
|
45
|
+
onceEventListeners.delete(listener);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
listener.callback(fullData);
|
|
49
|
+
onceEventListeners.delete(listener);
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
on(eventSpec, callback) {
|
|
57
|
+
const { event, senderFilter } = parseEventSpec(eventSpec);
|
|
58
|
+
let eventListeners = listeners.get(event);
|
|
59
|
+
if (!eventListeners) {
|
|
60
|
+
eventListeners = /* @__PURE__ */ new Set();
|
|
61
|
+
listeners.set(event, eventListeners);
|
|
62
|
+
}
|
|
63
|
+
const listener = {
|
|
64
|
+
callback,
|
|
65
|
+
senderFilter
|
|
66
|
+
};
|
|
67
|
+
eventListeners.add(listener);
|
|
68
|
+
return () => {
|
|
69
|
+
eventListeners.delete(listener);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
once(eventSpec, callback) {
|
|
73
|
+
const { event, senderFilter } = parseEventSpec(eventSpec);
|
|
74
|
+
let eventListeners = onceListeners.get(event);
|
|
75
|
+
if (!eventListeners) {
|
|
76
|
+
eventListeners = /* @__PURE__ */ new Set();
|
|
77
|
+
onceListeners.set(event, eventListeners);
|
|
78
|
+
}
|
|
79
|
+
const listener = {
|
|
80
|
+
callback,
|
|
81
|
+
senderFilter
|
|
82
|
+
};
|
|
83
|
+
eventListeners.add(listener);
|
|
84
|
+
return () => {
|
|
85
|
+
eventListeners.delete(listener);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const createdBuses = /* @__PURE__ */ new Map();
|
|
90
|
+
function getEventBus(id) {
|
|
91
|
+
if (typeof id !== "string" || id.trim() === "") {
|
|
92
|
+
throw new Error("id must be a non-empty string");
|
|
93
|
+
}
|
|
94
|
+
if (createdBuses.has(id)) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`EventBus with id "${id}" already exists`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const bus = new EventBus(id);
|
|
100
|
+
createdBuses.set(id, bus);
|
|
101
|
+
return bus;
|
|
102
|
+
}
|
|
103
|
+
let eventBus = null;
|
|
104
|
+
function createEventBus() {
|
|
105
|
+
try {
|
|
106
|
+
eventBus = window.ZOIS_CORE.getEventBus(MOD_DATA.name);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
logger.error("Failed to create EventBus:", e);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export {
|
|
112
|
+
EventBus,
|
|
113
|
+
createEventBus,
|
|
114
|
+
eventBus,
|
|
115
|
+
getEventBus
|
|
116
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { registerCore } from "./core";
|
|
2
2
|
import { dialogsManager } from "./dialogs";
|
|
3
|
+
import { createEventBus, eventBus } from "./events";
|
|
3
4
|
import { loadLocalization } from "./localization";
|
|
4
5
|
import { createModSdk, hookFunction, HookPriority } from "./modSdk";
|
|
5
6
|
import { getCurrentSubscreen, setSubscreen } from "./ui";
|
|
@@ -9,6 +10,7 @@ function bootstrap(modData) {
|
|
|
9
10
|
MOD_DATA = modData;
|
|
10
11
|
createModSdk();
|
|
11
12
|
if (!window.ZOIS_CORE) registerCore();
|
|
13
|
+
createEventBus();
|
|
12
14
|
loadLocalization();
|
|
13
15
|
hookFunction("GameKeyDown", HookPriority.ADD_BEHAVIOR, (args, next) => {
|
|
14
16
|
const currentSubscreen = getCurrentSubscreen();
|
|
@@ -23,28 +25,24 @@ function bootstrap(modData) {
|
|
|
23
25
|
}
|
|
24
26
|
return next(args);
|
|
25
27
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
await PreferenceOpenSubscreen("Extensions");
|
|
42
|
-
await PreferenceSubscreenExtensionsOpen(mod, ["Online", "ChatRoom"]);
|
|
43
|
-
setSubscreen(new s());
|
|
44
|
-
}
|
|
28
|
+
eventBus?.on("setSubscreen", async (data) => {
|
|
29
|
+
const target = data.target;
|
|
30
|
+
const isTrusted = data.isTrusted;
|
|
31
|
+
if (target === void 0) return;
|
|
32
|
+
if (target.startsWith(MOD_DATA.key + ":")) {
|
|
33
|
+
const currentSubscreen = getCurrentSubscreen();
|
|
34
|
+
const mod = target.substring(0, MOD_DATA.key.length);
|
|
35
|
+
const subscreen = target.substring(MOD_DATA.key.length + 1);
|
|
36
|
+
if (currentSubscreen?.constructor?.name === subscreen) return;
|
|
37
|
+
const s = MOD_DATA.subscreens?.[subscreen];
|
|
38
|
+
if (s === void 0) return;
|
|
39
|
+
if (isTrusted || await dialogsManager.confirm({ message: `Confirm the redirecting to modded subscreen ${target}` })) {
|
|
40
|
+
await PreferenceOpenSubscreen("Extensions");
|
|
41
|
+
await PreferenceSubscreenExtensionsOpen(mod, ["Online", "ChatRoom"]);
|
|
42
|
+
setSubscreen(new s());
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
|
-
);
|
|
45
|
+
});
|
|
48
46
|
ServerIsLoggedInAsync().then(() => {
|
|
49
47
|
if (modData.onReady) setTimeout(modData.onReady, getRandomNumber(3e3, 6e3));
|
|
50
48
|
});
|
|
@@ -77,26 +75,6 @@ function formatString(text) {
|
|
|
77
75
|
}
|
|
78
76
|
return { isBeatifulString: false };
|
|
79
77
|
}
|
|
80
|
-
class SetSubscreenEvent extends CustomEvent {
|
|
81
|
-
constructor(detail) {
|
|
82
|
-
super(`zois-core:setsubscreen`, { detail });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
class SubscreenLoadedEvent extends CustomEvent {
|
|
86
|
-
constructor(detail) {
|
|
87
|
-
super(`zois-core:subscreenloaded`, { detail });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
class SubscreenUnloadedEvent extends CustomEvent {
|
|
91
|
-
constructor(detail) {
|
|
92
|
-
super(`zois-core:subscreenunloaded`, { detail });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
class CoreSettingsChangedEvent extends CustomEvent {
|
|
96
|
-
constructor() {
|
|
97
|
-
super(`zois-core:coresettingschanged`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
78
|
function sleep(ms) {
|
|
101
79
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
102
80
|
}
|
|
@@ -167,11 +145,7 @@ function normalizeObject(obj) {
|
|
|
167
145
|
}, {});
|
|
168
146
|
}
|
|
169
147
|
export {
|
|
170
|
-
CoreSettingsChangedEvent,
|
|
171
148
|
MOD_DATA,
|
|
172
|
-
SetSubscreenEvent,
|
|
173
|
-
SubscreenLoadedEvent,
|
|
174
|
-
SubscreenUnloadedEvent,
|
|
175
149
|
bootstrap,
|
|
176
150
|
colorsEqual,
|
|
177
151
|
formatString,
|
|
@@ -57,22 +57,8 @@ class ButtonShard extends Shard {
|
|
|
57
57
|
background: "var(--tmd-accent, #5b5bff)",
|
|
58
58
|
color: "var(--tmd-text, white)",
|
|
59
59
|
padding: "0.1em",
|
|
60
|
+
boxSizing: "border-box",
|
|
60
61
|
borderRadius: "50%"
|
|
61
|
-
},
|
|
62
|
-
":hover > .external-link-icon": {
|
|
63
|
-
minWidth: "fit-content",
|
|
64
|
-
padding: "0.1em 0.25em",
|
|
65
|
-
borderRadius: "0.5em",
|
|
66
|
-
bottom: "calc(100% + 0.25em)",
|
|
67
|
-
top: "unset"
|
|
68
|
-
},
|
|
69
|
-
"> .external-link-icon > span": {
|
|
70
|
-
display: "none",
|
|
71
|
-
fontSize: "0.5em",
|
|
72
|
-
whiteSpace: "nowrap"
|
|
73
|
-
},
|
|
74
|
-
":hover > .external-link-icon > span": {
|
|
75
|
-
display: "inline"
|
|
76
62
|
}
|
|
77
63
|
};
|
|
78
64
|
}
|
|
@@ -128,10 +114,25 @@ class ButtonShard extends Shard {
|
|
|
128
114
|
const externalLinkIcon = createElement(ExternalLink);
|
|
129
115
|
externalLinkIcon.style.width = "auto";
|
|
130
116
|
externalLinkIcon.style.height = "100%";
|
|
131
|
-
|
|
132
|
-
externalLinkLabel.textContent = href;
|
|
133
|
-
externalLinkContainer.append(externalLinkIcon, externalLinkLabel);
|
|
117
|
+
externalLinkContainer.append(externalLinkIcon);
|
|
134
118
|
btn.append(externalLinkContainer);
|
|
119
|
+
let hrefTooltip = null;
|
|
120
|
+
btn.addEventListener("mouseenter", () => {
|
|
121
|
+
if (hrefTooltip) return;
|
|
122
|
+
hrefTooltip = document.createElement("div");
|
|
123
|
+
hrefTooltip.style.cssText = `position: fixed; top: 0; left: 0; right: 0; bottom: 0; margin: auto;
|
|
124
|
+
width: fit-content; height: fit-content; font-size: calc(3.5px * var(--size-unit));
|
|
125
|
+
z-index: 100; color: var(--tmd-text, black); background: var(--tmd-element, #f8f8f8); padding: 0.2em;
|
|
126
|
+
border-radius: 4px; border: 1px solid var(--tmd-element-hover, #9f9f9f);`;
|
|
127
|
+
setFontFamily(hrefTooltip, CommonGetFontName());
|
|
128
|
+
hrefTooltip.textContent = href;
|
|
129
|
+
document.body.append(hrefTooltip);
|
|
130
|
+
});
|
|
131
|
+
btn.addEventListener("mouseleave", () => {
|
|
132
|
+
if (!hrefTooltip) return;
|
|
133
|
+
hrefTooltip.remove();
|
|
134
|
+
hrefTooltip = null;
|
|
135
|
+
});
|
|
135
136
|
}
|
|
136
137
|
if (typeof isDisabled === "function" && isDisabled()) btn.classList.add("zcDisabled");
|
|
137
138
|
btn.addEventListener("click", () => {
|
|
@@ -127,6 +127,7 @@ class CheckboxShard extends Shard {
|
|
|
127
127
|
const label = document.createElement("p");
|
|
128
128
|
label.textContent = text;
|
|
129
129
|
label.style.color = this.textColor;
|
|
130
|
+
label.style.margin = "0";
|
|
130
131
|
if (typeof isDisabled === "function" && isDisabled()) {
|
|
131
132
|
input.disabled = true;
|
|
132
133
|
wrapper.classList.add("zcDisabled");
|
|
@@ -2,7 +2,7 @@ import { Shard } from "./shard";
|
|
|
2
2
|
class ImageShard extends Shard {
|
|
3
3
|
modal = null;
|
|
4
4
|
generateBody() {
|
|
5
|
-
const { src, alt = ""
|
|
5
|
+
const { src, alt = "" } = this.context;
|
|
6
6
|
const img = document.createElement("img");
|
|
7
7
|
img.src = src;
|
|
8
8
|
img.alt = alt;
|
|
@@ -12,6 +12,7 @@ class SelectShard extends Shard {
|
|
|
12
12
|
border: "2px solid var(--tmd-accent, rgb(195, 195, 195))",
|
|
13
13
|
borderRadius: "0.4em",
|
|
14
14
|
padding: "0.25em",
|
|
15
|
+
boxSizing: "border-box",
|
|
15
16
|
zIndex: "10"
|
|
16
17
|
},
|
|
17
18
|
"[opened=true]": {
|
|
@@ -20,6 +21,9 @@ class SelectShard extends Shard {
|
|
|
20
21
|
"[opened=false]:hover": {
|
|
21
22
|
borderColor: "var(--tmd-accent-hover, rgb(170, 170, 170))"
|
|
22
23
|
},
|
|
24
|
+
"> p": {
|
|
25
|
+
margin: "0"
|
|
26
|
+
},
|
|
23
27
|
">svg": {
|
|
24
28
|
position: "absolute",
|
|
25
29
|
right: "0.45em",
|
|
@@ -51,6 +55,7 @@ class SelectShard extends Shard {
|
|
|
51
55
|
color: "var(--tmd-text, black)",
|
|
52
56
|
width: "100%",
|
|
53
57
|
padding: "0.25em",
|
|
58
|
+
boxSizing: "border-box",
|
|
54
59
|
borderRadius: "0.25em"
|
|
55
60
|
},
|
|
56
61
|
">div>div>svg": {
|
package/dist/shards/shard.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { eventBus } from "../events";
|
|
2
2
|
import { logger } from "../logging";
|
|
3
3
|
import { ShardModule } from "../shard-modules";
|
|
4
4
|
import { setPosition, setPadding, getRelativeWidth, getRelativeHeight } from "../ui";
|
|
@@ -18,13 +18,16 @@ class Shard {
|
|
|
18
18
|
parentElement.append(this.body.base);
|
|
19
19
|
this.update();
|
|
20
20
|
this.processModules("effect");
|
|
21
|
+
eventBus?.emit("shardMounted", {
|
|
22
|
+
shard: this
|
|
23
|
+
});
|
|
21
24
|
window.addEventListener("resize", () => this.update());
|
|
22
|
-
|
|
23
|
-
if (!(event instanceof SubscreenUnloadedEvent)) return;
|
|
25
|
+
eventBus?.once("subscreenUnloaded", () => {
|
|
24
26
|
this.body.base.remove();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
eventBus?.emit("shardUnmounted", {
|
|
28
|
+
shard: this
|
|
29
|
+
});
|
|
30
|
+
});
|
|
28
31
|
return this.mountReturnValue;
|
|
29
32
|
}
|
|
30
33
|
processModules(stage) {
|
package/dist/shards/tabsShard.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { eventBus } from "../events";
|
|
1
2
|
import { MOD_DATA } from "../index";
|
|
2
3
|
import { hookFunction, HookPriority } from "../modSdk";
|
|
3
4
|
import { autosetFontSize, setFontFamily } from "../ui";
|
|
@@ -56,7 +57,7 @@ class TabsShard extends Shard {
|
|
|
56
57
|
tabEl.addEventListener("click", switchTab);
|
|
57
58
|
tabsEl.append(tabEl);
|
|
58
59
|
});
|
|
59
|
-
|
|
60
|
+
eventBus?.once("subscreenUnloaded", () => this.clearDrawProcessHook?.());
|
|
60
61
|
return {
|
|
61
62
|
base: tabsEl
|
|
62
63
|
};
|
package/dist/shards/textShard.js
CHANGED
|
@@ -9,7 +9,9 @@ class TextShard extends Shard {
|
|
|
9
9
|
const p = document.createElement("p");
|
|
10
10
|
p.innerHTML = this.context.text ?? "";
|
|
11
11
|
p.style.color = this.context.color ?? this.defaultColor;
|
|
12
|
-
p.style.
|
|
12
|
+
p.style.margin = "0";
|
|
13
|
+
p.style.boxSizing = "border-box";
|
|
14
|
+
if (this.context.height) p.style.overflow = "auto";
|
|
13
15
|
if (this.context.withBackground) p.style.background = "var(--tmd-element,rgb(239, 239, 239))";
|
|
14
16
|
if (this.context.withBorder) p.style.border = "2px solid var(--tmd-accent, rgb(236, 236, 236))";
|
|
15
17
|
setFontFamily(p, MOD_DATA.fontFamily);
|
package/dist/styles.css
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
* {
|
|
2
|
-
margin: 0;
|
|
3
|
-
padding: 0;
|
|
4
|
-
box-sizing: border-box;
|
|
5
|
-
}
|
|
6
1
|
.zcInput {
|
|
7
2
|
background: var(--tmd-element, white);
|
|
8
3
|
color: var(--tmd-text, black);
|
|
@@ -39,6 +34,7 @@
|
|
|
39
34
|
background: var(--tmd-element, white);
|
|
40
35
|
color: var(--tmd-text, black);
|
|
41
36
|
padding: 0.4em 2.5em 0.4em 0.4em;
|
|
37
|
+
box-sizing: border-box;
|
|
42
38
|
}
|
|
43
39
|
.zcCard:hover {
|
|
44
40
|
border: 2px solid var(--tmd-accent-hover, rgb(170, 170, 170));
|
|
@@ -46,9 +42,11 @@
|
|
|
46
42
|
.zcCard_name {
|
|
47
43
|
font-size: 0.5em;
|
|
48
44
|
color: var(--tmd-text, rgb(100, 100, 100));
|
|
45
|
+
margin: 0;
|
|
49
46
|
}
|
|
50
47
|
.zcCard_value {
|
|
51
48
|
color: var(--tmd-text, black);
|
|
49
|
+
margin: 0;
|
|
52
50
|
margin-top: 0.4em;
|
|
53
51
|
font-weight: bold;
|
|
54
52
|
}
|
|
@@ -129,6 +127,7 @@
|
|
|
129
127
|
}
|
|
130
128
|
.zcToast p {
|
|
131
129
|
color: white;
|
|
130
|
+
margin: 0;
|
|
132
131
|
}
|
|
133
132
|
.zcToast > svg {
|
|
134
133
|
flex-shrink: 0;
|
|
@@ -155,7 +154,8 @@
|
|
|
155
154
|
box-shadow: 0px 0px 6px 1px #0000006e;
|
|
156
155
|
}
|
|
157
156
|
.zcDialog > p {
|
|
158
|
-
padding: 0.
|
|
157
|
+
padding: 0.85em 0px;
|
|
158
|
+
margin: 0;
|
|
159
159
|
user-select: none;
|
|
160
160
|
width: 90%;
|
|
161
161
|
color: white;
|
package/dist/toasts.js
CHANGED
|
@@ -2,6 +2,7 @@ import { CircleAlert, CircleCheck, CircleX, createElement, Info } from "lucide";
|
|
|
2
2
|
import { MOD_DATA } from "./index";
|
|
3
3
|
import { setPosition } from "./ui";
|
|
4
4
|
import { logger } from "./logging";
|
|
5
|
+
import { eventBus } from "./events";
|
|
5
6
|
function createToastsContainer() {
|
|
6
7
|
const container = document.createElement("div");
|
|
7
8
|
container.classList.add("zcToastsContainer");
|
|
@@ -21,7 +22,7 @@ function createToastsContainer() {
|
|
|
21
22
|
window.addEventListener("resize", update);
|
|
22
23
|
document.body.append(container);
|
|
23
24
|
update();
|
|
24
|
-
|
|
25
|
+
eventBus?.on("zois-core:coreSettingsChanged", update);
|
|
25
26
|
return container;
|
|
26
27
|
}
|
|
27
28
|
function getToastIcon(type, theme) {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { CoreSettings } from "./core";
|
|
2
|
+
import { Shard } from "./shards";
|
|
3
|
+
import { BaseSubscreen } from "./ui";
|
|
4
|
+
export type EventCallback<T = any> = (data: T) => void;
|
|
5
|
+
export type KnownEventMap = {
|
|
6
|
+
subscreenLoaded: {
|
|
7
|
+
subscreen: BaseSubscreen;
|
|
8
|
+
sender: string;
|
|
9
|
+
};
|
|
10
|
+
subscreenUnloaded: {
|
|
11
|
+
subscreen: BaseSubscreen;
|
|
12
|
+
sender: string;
|
|
13
|
+
};
|
|
14
|
+
setSubscreen: {
|
|
15
|
+
target: string;
|
|
16
|
+
isTrusted: boolean;
|
|
17
|
+
sender: string;
|
|
18
|
+
};
|
|
19
|
+
coreSettingsChanged: {
|
|
20
|
+
settings: CoreSettings;
|
|
21
|
+
sender: string;
|
|
22
|
+
};
|
|
23
|
+
shardMounted: {
|
|
24
|
+
shard: Shard;
|
|
25
|
+
sender: string;
|
|
26
|
+
};
|
|
27
|
+
shardUnmounted: {
|
|
28
|
+
shard: Shard;
|
|
29
|
+
sender: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type UnknownEventData = {
|
|
33
|
+
sender: string;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
export type EventMap = KnownEventMap & {
|
|
37
|
+
[event: string]: UnknownEventData;
|
|
38
|
+
};
|
|
39
|
+
export declare class EventBus {
|
|
40
|
+
#private;
|
|
41
|
+
get id(): string;
|
|
42
|
+
constructor(id: string);
|
|
43
|
+
emit<T extends string>(event: T, data: T extends keyof KnownEventMap ? Omit<KnownEventMap[T], "sender"> : Record<string, unknown>): void;
|
|
44
|
+
on<T extends string>(eventSpec: T, callback: EventCallback<T extends `${string}:${infer E}` ? E extends keyof KnownEventMap ? KnownEventMap[E] : UnknownEventData : T extends keyof KnownEventMap ? KnownEventMap[T] : UnknownEventData>): () => void;
|
|
45
|
+
once<T extends string>(eventSpec: T, callback: EventCallback<T extends `${string}:${infer E}` ? E extends keyof KnownEventMap ? KnownEventMap[E] : UnknownEventData : T extends keyof KnownEventMap ? KnownEventMap[T] : UnknownEventData>): () => void;
|
|
46
|
+
}
|
|
47
|
+
export declare function getEventBus(id: string): EventBus;
|
|
48
|
+
export declare let eventBus: EventBus | null;
|
|
49
|
+
export declare function createEventBus(): void;
|
|
50
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChangelogEntryTag } from "./changelogs";
|
|
2
|
-
import {
|
|
2
|
+
import { SubscreenConstructor } from "./ui";
|
|
3
3
|
export interface ModData {
|
|
4
4
|
name: string;
|
|
5
5
|
fullName: string;
|
|
@@ -53,32 +53,6 @@ export declare function formatString(text: string): ({
|
|
|
53
53
|
} | {
|
|
54
54
|
isBeatifulString: false;
|
|
55
55
|
});
|
|
56
|
-
export declare class SetSubscreenEvent extends CustomEvent<{
|
|
57
|
-
target: string;
|
|
58
|
-
isTrusted: boolean;
|
|
59
|
-
}> {
|
|
60
|
-
constructor(detail: {
|
|
61
|
-
target: string;
|
|
62
|
-
isTrusted: boolean;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
export declare class SubscreenLoadedEvent extends CustomEvent<{
|
|
66
|
-
subscreen: BaseSubscreen;
|
|
67
|
-
}> {
|
|
68
|
-
constructor(detail: {
|
|
69
|
-
subscreen: BaseSubscreen;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
export declare class SubscreenUnloadedEvent extends CustomEvent<{
|
|
73
|
-
subscreen: BaseSubscreen;
|
|
74
|
-
}> {
|
|
75
|
-
constructor(detail: {
|
|
76
|
-
subscreen: BaseSubscreen;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
export declare class CoreSettingsChangedEvent extends CustomEvent<never> {
|
|
80
|
-
constructor();
|
|
81
|
-
}
|
|
82
56
|
export declare function sleep(ms: number): Promise<() => {}>;
|
|
83
57
|
export declare function waitFor(func: () => boolean, cancelFunc?: () => boolean): Promise<boolean>;
|
|
84
58
|
export declare function getRandomNumber(min: number, max: number): number;
|
|
@@ -9,6 +9,6 @@ export interface BackNextButtonShardContext extends ShardContext<"backButton" |
|
|
|
9
9
|
export declare class BackNextButtonShard extends Shard<BackNextButtonShardContext> {
|
|
10
10
|
protected get dynamicClassContainer(): DynamicClassStyles;
|
|
11
11
|
protected get dynamicClassButton(): DynamicClassStyles;
|
|
12
|
-
generateBody(): Record<keyof NonNullable<BackNextButtonShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
13
|
-
update(): void;
|
|
12
|
+
protected generateBody(): Record<keyof NonNullable<BackNextButtonShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
13
|
+
protected update(): void;
|
|
14
14
|
}
|
|
@@ -16,6 +16,6 @@ export interface ButtonShardContext extends ShardContext<"icon" | "text"> {
|
|
|
16
16
|
}
|
|
17
17
|
export declare class ButtonShard extends Shard<ButtonShardContext> {
|
|
18
18
|
protected get dynamicClassButton(): DynamicClassStyles;
|
|
19
|
-
generateBody(): Record<keyof NonNullable<ButtonShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
20
|
-
update(): void;
|
|
19
|
+
protected generateBody(): Record<keyof NonNullable<ButtonShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
20
|
+
protected update(): void;
|
|
21
21
|
}
|
|
@@ -5,6 +5,6 @@ export interface CardShardContext extends ShardContext<"base" | "name" | "value"
|
|
|
5
5
|
icon?: SVGElement;
|
|
6
6
|
}
|
|
7
7
|
export declare class CardShard extends Shard<CardShardContext> {
|
|
8
|
-
generateBody(): Record<keyof NonNullable<CardShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
9
|
-
update(): void;
|
|
8
|
+
protected generateBody(): Record<keyof NonNullable<CardShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
9
|
+
protected update(): void;
|
|
10
10
|
}
|
|
@@ -16,6 +16,6 @@ export declare class CheckboxShard extends Shard<CheckboxShardContext> {
|
|
|
16
16
|
protected get dynamicClassTooltip(): DynamicClassStyles;
|
|
17
17
|
protected get dynamicClassBox(): DynamicClassStyles;
|
|
18
18
|
protected get textColor(): string;
|
|
19
|
-
generateBody(): Record<keyof NonNullable<CheckboxShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
20
|
-
update(): void;
|
|
19
|
+
protected generateBody(): Record<keyof NonNullable<CheckboxShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
20
|
+
protected update(): void;
|
|
21
21
|
}
|
|
@@ -6,5 +6,5 @@ export interface ContainerShardContext extends ShardContext<"content" | "scrollb
|
|
|
6
6
|
export declare class ContainerShard extends Shard<ContainerShardContext> {
|
|
7
7
|
protected get dynamicClassContainer(): DynamicClassStyles;
|
|
8
8
|
protected get mountReturnValue(): HTMLElement | SVGElement | null;
|
|
9
|
-
generateBody(): Record<keyof NonNullable<ContainerShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
9
|
+
protected generateBody(): Record<keyof NonNullable<ContainerShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
10
10
|
}
|
|
@@ -5,7 +5,7 @@ export interface ImageShardContext extends ShardContext {
|
|
|
5
5
|
}
|
|
6
6
|
export declare class ImageShard extends Shard<ImageShardContext> {
|
|
7
7
|
private modal;
|
|
8
|
-
generateBody(): Record<keyof NonNullable<ImageShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
8
|
+
protected generateBody(): Record<keyof NonNullable<ImageShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
9
9
|
private openModal;
|
|
10
10
|
private closeModal;
|
|
11
11
|
}
|
|
@@ -12,5 +12,5 @@ export declare class InputListShard extends Shard<InputListShardContext> {
|
|
|
12
12
|
protected get dynamicClassContainer(): DynamicClassStyles;
|
|
13
13
|
protected get dynamicClassInput(): DynamicClassStyles;
|
|
14
14
|
protected get dynamicClassToolsButton(): DynamicClassStyles;
|
|
15
|
-
generateBody(): Record<keyof NonNullable<InputListShardContext<number | string>["modules"]>, HTMLElement | SVGElement>;
|
|
15
|
+
protected generateBody(): Record<keyof NonNullable<InputListShardContext<number | string>["modules"]>, HTMLElement | SVGElement>;
|
|
16
16
|
}
|
|
@@ -9,6 +9,6 @@ export interface InputShardContext extends ShardContext {
|
|
|
9
9
|
isDisabled?: () => boolean;
|
|
10
10
|
}
|
|
11
11
|
export declare class InputShard extends Shard<InputShardContext> {
|
|
12
|
-
generateBody(): Record<keyof NonNullable<InputShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
13
|
-
update(): void;
|
|
12
|
+
protected generateBody(): Record<keyof NonNullable<InputShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
13
|
+
protected update(): void;
|
|
14
14
|
}
|
|
@@ -12,6 +12,6 @@ export interface SelectShardContext extends Omit<ShardContext, "height"> {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class SelectShard extends Shard<SelectShardContext> {
|
|
14
14
|
protected get dynamicClassContainer(): DynamicClassStyles;
|
|
15
|
-
generateBody(): Record<keyof NonNullable<SelectShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
16
|
-
update(): void;
|
|
15
|
+
protected generateBody(): Record<keyof NonNullable<SelectShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
16
|
+
protected update(): void;
|
|
17
17
|
}
|
|
@@ -12,7 +12,7 @@ export interface ShardContext<T extends string = never> {
|
|
|
12
12
|
}
|
|
13
13
|
export declare abstract class Shard<Context extends ShardContext = ShardContext> {
|
|
14
14
|
protected context: Context;
|
|
15
|
-
|
|
15
|
+
body: Record<keyof NonNullable<Context["modules"]>, HTMLElement | SVGElement> | null;
|
|
16
16
|
protected get mountReturnValue(): HTMLElement | SVGElement;
|
|
17
17
|
constructor(context: Context);
|
|
18
18
|
mount(parentElement?: HTMLElement): HTMLElement | SVGElement;
|
|
@@ -7,6 +7,6 @@ export interface SvgShardContext extends ShardContext {
|
|
|
7
7
|
strokeWidth?: string;
|
|
8
8
|
}
|
|
9
9
|
export declare class SvgShard extends Shard<SvgShardContext> {
|
|
10
|
-
generateBody(): Record<keyof NonNullable<SvgShardContext["modules"]>, SVGElement>;
|
|
11
|
-
update(): void;
|
|
10
|
+
protected generateBody(): Record<keyof NonNullable<SvgShardContext["modules"]>, SVGElement>;
|
|
11
|
+
protected update(): void;
|
|
12
12
|
}
|
|
@@ -13,6 +13,6 @@ export declare class TabsShard extends Shard<TabsShardContext> {
|
|
|
13
13
|
private tabHandlers;
|
|
14
14
|
private clearDrawProcessHook;
|
|
15
15
|
constructor(context: TabsShardContext);
|
|
16
|
-
generateBody(): Record<keyof NonNullable<TabsShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
17
|
-
update(): void;
|
|
16
|
+
protected generateBody(): Record<keyof NonNullable<TabsShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
17
|
+
protected update(): void;
|
|
18
18
|
}
|
|
@@ -8,6 +8,6 @@ export interface TextShardContext extends ShardContext {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class TextShard extends Shard<TextShardContext> {
|
|
10
10
|
protected get defaultColor(): string;
|
|
11
|
-
generateBody(): Record<keyof NonNullable<TextShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
12
|
-
update(): void;
|
|
11
|
+
protected generateBody(): Record<keyof NonNullable<TextShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
12
|
+
protected update(): void;
|
|
13
13
|
}
|
package/dist/ui.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SubscreenLoadedEvent, SubscreenUnloadedEvent } from "./index";
|
|
2
1
|
import { StyleModule } from "./shard-modules";
|
|
3
2
|
import { MOD_DATA } from "./index";
|
|
4
3
|
import { ButtonShard, TextShard, InputShard, CheckboxShard, InputListShard, ImageShard, SvgShard, BackNextButtonShard, TabsShard, CardShard, SelectShard, ContainerShard } from "./shards";
|
|
5
4
|
import { logger } from "./logging";
|
|
6
5
|
import exitIcon from "./assets/icons/exit.svg";
|
|
6
|
+
import { eventBus } from "./events";
|
|
7
7
|
function hexToRgb(hex) {
|
|
8
8
|
hex = hex.replace("#", "");
|
|
9
9
|
const r = parseInt(hex.substring(0, 2), 16);
|
|
@@ -187,7 +187,6 @@ function setSubscreen(subscreen) {
|
|
|
187
187
|
} catch (e) {
|
|
188
188
|
logger.error("Failed to unload subscreen", previousSubscreen, e);
|
|
189
189
|
}
|
|
190
|
-
window.dispatchEvent(new SubscreenUnloadedEvent({ subscreen: previousSubscreen }));
|
|
191
190
|
}
|
|
192
191
|
if (subscreen) {
|
|
193
192
|
try {
|
|
@@ -195,7 +194,6 @@ function setSubscreen(subscreen) {
|
|
|
195
194
|
} catch (e) {
|
|
196
195
|
logger.error("Failed to load subscreen", subscreen, e);
|
|
197
196
|
}
|
|
198
|
-
window.dispatchEvent(new SubscreenLoadedEvent({ subscreen }));
|
|
199
197
|
}
|
|
200
198
|
}
|
|
201
199
|
function getCurrentSubscreen() {
|
|
@@ -242,8 +240,14 @@ class BaseSubscreen {
|
|
|
242
240
|
fontSize: 8
|
|
243
241
|
}).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
|
|
244
242
|
}
|
|
243
|
+
eventBus?.emit("subscreenLoaded", {
|
|
244
|
+
subscreen: this
|
|
245
|
+
});
|
|
245
246
|
}
|
|
246
247
|
unload() {
|
|
248
|
+
eventBus?.emit("subscreenUnloaded", {
|
|
249
|
+
subscreen: this
|
|
250
|
+
});
|
|
247
251
|
}
|
|
248
252
|
click() {
|
|
249
253
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zois-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
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"
|
|
@@ -66,6 +66,10 @@
|
|
|
66
66
|
"./changelogs": {
|
|
67
67
|
"import": "./dist/changelogs.js",
|
|
68
68
|
"types": "./dist/types/changelogs.d.ts"
|
|
69
|
+
},
|
|
70
|
+
"./events": {
|
|
71
|
+
"import": "./dist/events.js",
|
|
72
|
+
"types": "./dist/types/events.d.ts"
|
|
69
73
|
}
|
|
70
74
|
},
|
|
71
75
|
"dependencies": {
|