zois-core 1.2.1 → 2.0.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.
Files changed (118) hide show
  1. package/README.md +23 -2
  2. package/dist/assets/icons/exit.svg +17 -0
  3. package/dist/changelogs.js +153 -0
  4. package/dist/core-subscreen/coreSubscreen.js +81 -0
  5. package/dist/core-subscreen/developmentSubscreen.js +22 -0
  6. package/dist/core-subscreen/generalSubscreen.js +23 -0
  7. package/dist/core-subscreen/mainSubscreen.js +58 -0
  8. package/dist/core-subscreen/shards/coreButtonShard.js +30 -0
  9. package/dist/core-subscreen/shards/coreCheckboxShard.js +33 -0
  10. package/dist/core-subscreen/shards/coreInputListShard.js +38 -0
  11. package/dist/core-subscreen/shards/coreSelectShard.js +17 -0
  12. package/dist/core-subscreen/shards/coreTextShard.js +9 -0
  13. package/dist/core-subscreen/shards/index.js +5 -0
  14. package/dist/core-subscreen/toastsSubscreen.js +112 -0
  15. package/dist/core.js +178 -0
  16. package/dist/dialogs.js +110 -0
  17. package/dist/index.js +201 -1
  18. package/dist/localization.js +71 -0
  19. package/dist/logging.js +31 -0
  20. package/dist/messaging.js +234 -1
  21. package/dist/modSdk.js +63 -0
  22. package/dist/shard-modules/attributesModule.js +16 -0
  23. package/dist/shard-modules/centerModule.js +12 -0
  24. package/dist/shard-modules/clickModule.js +14 -0
  25. package/dist/shard-modules/counterUpModule.js +37 -0
  26. package/dist/shard-modules/dynamicClassModule.js +15 -0
  27. package/dist/shard-modules/index.js +9 -0
  28. package/dist/shard-modules/multiClickModule.js +41 -0
  29. package/dist/shard-modules/shardModule.js +12 -0
  30. package/dist/shard-modules/styleModule.js +20 -0
  31. package/dist/shard-modules/typeModule.js +37 -0
  32. package/dist/shards/backNextButtonShard.js +99 -0
  33. package/dist/shards/buttonShard.js +150 -0
  34. package/dist/shards/cardShard.js +35 -0
  35. package/dist/shards/checkboxShard.js +139 -0
  36. package/dist/shards/containerShard.js +16 -0
  37. package/dist/shards/imageShard.js +98 -0
  38. package/dist/shards/index.js +13 -0
  39. package/dist/shards/inputListShard.js +162 -0
  40. package/dist/shards/inputShard.js +33 -0
  41. package/dist/shards/selectShard.js +126 -0
  42. package/dist/shards/shard.js +79 -0
  43. package/dist/shards/svgShard.js +29 -0
  44. package/dist/shards/tabsShard.js +59 -0
  45. package/dist/shards/textShard.js +27 -0
  46. package/dist/styles.css +209 -1
  47. package/dist/toasts.js +189 -0
  48. package/dist/types/changelogs.d.ts +1 -0
  49. package/dist/types/core-subscreen/coreSubscreen.d.ts +15 -0
  50. package/dist/types/core-subscreen/developmentSubscreen.d.ts +5 -0
  51. package/dist/types/core-subscreen/generalSubscreen.d.ts +5 -0
  52. package/dist/types/core-subscreen/mainSubscreen.d.ts +6 -0
  53. package/dist/types/core-subscreen/shards/coreButtonShard.d.ts +5 -0
  54. package/dist/types/core-subscreen/shards/coreCheckboxShard.d.ts +6 -0
  55. package/dist/types/core-subscreen/shards/coreInputListShard.d.ts +6 -0
  56. package/dist/types/core-subscreen/shards/coreSelectShard.d.ts +5 -0
  57. package/dist/types/core-subscreen/shards/coreTextShard.d.ts +4 -0
  58. package/dist/types/core-subscreen/shards/index.d.ts +5 -0
  59. package/dist/types/core-subscreen/toastsSubscreen.d.ts +5 -0
  60. package/dist/types/core.d.ts +18 -0
  61. package/dist/types/dialogs.d.ts +29 -0
  62. package/dist/types/globals.d.ts +6 -0
  63. package/dist/types/index.d.ts +62 -6
  64. package/dist/types/localization.d.ts +4 -0
  65. package/dist/types/logging.d.ts +16 -0
  66. package/dist/types/messaging.d.ts +5 -3
  67. package/dist/types/{modsApi.d.ts → modSdk.d.ts} +2 -2
  68. package/dist/types/shard-modules/attributesModule.d.ts +7 -0
  69. package/dist/types/shard-modules/centerModule.d.ts +5 -0
  70. package/dist/types/shard-modules/clickModule.d.ts +7 -0
  71. package/dist/types/shard-modules/counterUpModule.d.ts +13 -0
  72. package/dist/types/shard-modules/dynamicClassModule.d.ts +8 -0
  73. package/dist/types/{ui-modules → shard-modules}/index.d.ts +2 -0
  74. package/dist/types/shard-modules/multiClickModule.d.ts +12 -0
  75. package/dist/types/shard-modules/shardModule.d.ts +7 -0
  76. package/dist/types/shard-modules/styleModule.d.ts +8 -0
  77. package/dist/types/shard-modules/typeModule.d.ts +11 -0
  78. package/dist/types/shards/backNextButtonShard.d.ts +14 -0
  79. package/dist/types/shards/buttonShard.d.ts +21 -0
  80. package/dist/types/shards/cardShard.d.ts +10 -0
  81. package/dist/types/shards/checkboxShard.d.ts +19 -0
  82. package/dist/types/shards/containerShard.d.ts +7 -0
  83. package/dist/types/shards/imageShard.d.ts +11 -0
  84. package/dist/types/shards/index.d.ts +13 -0
  85. package/dist/types/shards/inputListShard.d.ts +16 -0
  86. package/dist/types/shards/inputShard.d.ts +14 -0
  87. package/dist/types/shards/selectShard.d.ts +17 -0
  88. package/dist/types/shards/shard.d.ts +21 -0
  89. package/dist/types/shards/svgShard.d.ts +12 -0
  90. package/dist/types/shards/tabsShard.d.ts +17 -0
  91. package/dist/types/shards/textShard.d.ts +13 -0
  92. package/dist/types/toasts.d.ts +21 -0
  93. package/dist/types/ui.d.ts +35 -148
  94. package/dist/ui.js +375 -11
  95. package/dist/validation.js +31 -1
  96. package/dist/wardrobe.js +167 -1
  97. package/package.json +47 -26
  98. package/scripts/zois-core.mjs +126 -0
  99. package/dist/modsApi.js +0 -1
  100. package/dist/modules.js +0 -1
  101. package/dist/popups.js +0 -1
  102. package/dist/types/modules.d.ts +0 -18
  103. package/dist/types/popups.d.ts +0 -63
  104. package/dist/types/ui-modules/attributesModule.d.ts +0 -6
  105. package/dist/types/ui-modules/centerModule.d.ts +0 -4
  106. package/dist/types/ui-modules/clickModule.d.ts +0 -6
  107. package/dist/types/ui-modules/counterUpModule.d.ts +0 -12
  108. package/dist/types/ui-modules/dynamicClassModule.d.ts +0 -7
  109. package/dist/types/ui-modules/styleModule.d.ts +0 -7
  110. package/dist/types/ui-modules/typeModule.d.ts +0 -10
  111. package/dist/ui-modules/attributesModule.js +0 -1
  112. package/dist/ui-modules/centerModule.js +0 -1
  113. package/dist/ui-modules/clickModule.js +0 -1
  114. package/dist/ui-modules/counterUpModule.js +0 -1
  115. package/dist/ui-modules/dynamicClassModule.js +0 -1
  116. package/dist/ui-modules/index.js +0 -1
  117. package/dist/ui-modules/styleModule.js +0 -1
  118. package/dist/ui-modules/typeModule.js +0 -1
package/dist/core.js ADDED
@@ -0,0 +1,178 @@
1
+ import styles from "./styles.css";
2
+ import { formatString, version, CoreSettingsChangedEvent, waitFor, SetSubscreenEvent } from "./index";
3
+ import { hookFunction, HookPriority } from "./modSdk";
4
+ import { getCurrentSubscreen, setSubscreen } from "./ui";
5
+ import { MainSubscreen } from "./core-subscreen/mainSubscreen";
6
+ import { createElement, Terminal } from "lucide";
7
+ import { ButtonShard, ContainerShard } from "./shards";
8
+ import { StyleModule } from "./shard-modules";
9
+ import { dialogsManager } from "./dialogs";
10
+ let coreSettings = {};
11
+ function syncSettings() {
12
+ if (typeof coreSettings !== "object") return;
13
+ Player.ExtensionSettings.ZOIS_CORE = LZString.compressToBase64(JSON.stringify(coreSettings));
14
+ ServerPlayerExtensionSettingsSync("ZOIS_CORE");
15
+ document.dispatchEvent(new CoreSettingsChangedEvent());
16
+ }
17
+ function registerSubscreen() {
18
+ PreferenceRegisterExtensionSetting({
19
+ Identifier: "ZOIS_CORE",
20
+ Image: () => {
21
+ const serializer = new XMLSerializer();
22
+ const svgString = serializer.serializeToString(createElement(Terminal));
23
+ return "data:image/svg+xml," + svgString;
24
+ },
25
+ ButtonText: () => "Zoi's Modding Core",
26
+ load: () => {
27
+ setSubscreen(new MainSubscreen());
28
+ },
29
+ run: () => {
30
+ getCurrentSubscreen()?.run();
31
+ },
32
+ click: () => {
33
+ getCurrentSubscreen()?.click();
34
+ },
35
+ exit: () => {
36
+ getCurrentSubscreen()?.exit();
37
+ }
38
+ });
39
+ }
40
+ let loginScreenElements = [];
41
+ async function registerCore() {
42
+ const style = document.createElement("style");
43
+ style.innerHTML = styles;
44
+ document.head.append(style);
45
+ if (localStorage.getItem("autoConnectToDevServer") === "true") {
46
+ hookFunction("CommonGetServer", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
47
+ return "https://bondage-club-server-test.herokuapp.com/";
48
+ });
49
+ const containerShard = new ContainerShard({
50
+ x: 1250,
51
+ y: 900,
52
+ modules: {
53
+ base: [
54
+ new StyleModule({
55
+ display: "flex"
56
+ })
57
+ ]
58
+ }
59
+ });
60
+ const container = containerShard.mount();
61
+ new ButtonShard({
62
+ padding: 1,
63
+ parent: container,
64
+ text: "You connected to dev server"
65
+ }).mount();
66
+ new ButtonShard({
67
+ width: 90,
68
+ height: 90,
69
+ padding: 1,
70
+ icon: "Icons/Cancel.png",
71
+ parent: container,
72
+ onClick: () => {
73
+ localStorage.removeItem("autoConnectToDevServer");
74
+ location.reload();
75
+ }
76
+ }).mount();
77
+ loginScreenElements.push(container);
78
+ hookFunction("LoginUnload", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
79
+ loginScreenElements.forEach((e) => e.remove());
80
+ return next(args);
81
+ });
82
+ ServerURL = CommonGetServer();
83
+ ServerInit();
84
+ }
85
+ await waitFor(() => typeof Player?.MemberNumber === "number");
86
+ if (typeof Player.ExtensionSettings.ZOIS_CORE === "string") {
87
+ coreSettings = JSON.parse(LZString.decompressFromBase64(Player.ExtensionSettings.ZOIS_CORE) ?? "{}");
88
+ }
89
+ if (coreSettings.devMode) registerSubscreen();
90
+ window.ZOIS_CORE = Object.freeze({
91
+ version,
92
+ enableDevMode: () => {
93
+ coreSettings.devMode = true;
94
+ syncSettings();
95
+ registerSubscreen();
96
+ },
97
+ getSettings: () => {
98
+ return JSON.parse(JSON.stringify(coreSettings));
99
+ }
100
+ });
101
+ hookFunction("ChatRoomMessageCreateReplyMessageElement", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
102
+ const [msgId, displayMessage, data] = args;
103
+ const r = formatString(displayMessage);
104
+ if (!r.isBeatifulString) return next(args);
105
+ if (!msgId) {
106
+ return [displayMessage];
107
+ }
108
+ const metadata = ChatRoomGetMetadataElem(data.time, data.sender);
109
+ metadata.setAttribute("aria-hidden", "true");
110
+ return [
111
+ ElementCreate({
112
+ tag: "span",
113
+ classList: ["chat-room-message-content"],
114
+ attributes: { "msgid": msgId },
115
+ innerHTML: r.html
116
+ }),
117
+ ElementMenu.Create(
118
+ ElementGenerateID(),
119
+ [
120
+ metadata,
121
+ ElementButton.Create(
122
+ null,
123
+ () => ChatRoomMessageSetReply(msgId),
124
+ { noStyling: true, tooltip: "Reply" },
125
+ { button: { attributes: { name: "reply" } } }
126
+ )
127
+ ],
128
+ { direction: "rtl", role: "menu" },
129
+ { menu: { classList: ["chat-room-message-popup"], attributes: { "aria-direction": "horizontal" } } }
130
+ )
131
+ ];
132
+ });
133
+ document.addEventListener("click", async (event) => {
134
+ const link = event.target.closest("a");
135
+ if (link && link.href) {
136
+ try {
137
+ const url = new URL(link.href);
138
+ if (url.protocol === "zc:") {
139
+ event.preventDefault();
140
+ if (link.href.startsWith("zc://open")) {
141
+ const target = url.pathname.split("/").filter(Boolean)[1];
142
+ if (target === void 0) return;
143
+ switch (target) {
144
+ case "Admin": {
145
+ if (await dialogsManager.confirm({ message: "This deep link wants to redirect you to Admin subscreen. Confirm the redirecting." })) {
146
+ ChatRoomOpenAdminScreen();
147
+ }
148
+ break;
149
+ }
150
+ case "Wardrobe": {
151
+ if (await dialogsManager.confirm({ message: "This deep link wants to redirect you to Wardrobe subscreen. Confirm the redirecting." })) {
152
+ ChatRoomOpenWardrobeScreen();
153
+ }
154
+ break;
155
+ }
156
+ case "Information": {
157
+ if (await dialogsManager.confirm({ message: "This deep link wants to redirect you to Information subscreen. Confirm the redirecting." })) {
158
+ ChatRoomOpenInformationScreen();
159
+ }
160
+ break;
161
+ }
162
+ default: {
163
+ window.dispatchEvent(new SetSubscreenEvent({ target, isTrusted: false }));
164
+ }
165
+ }
166
+ }
167
+ }
168
+ } catch (e) {
169
+ }
170
+ }
171
+ }, true);
172
+ }
173
+ export {
174
+ coreSettings,
175
+ registerCore,
176
+ registerSubscreen,
177
+ syncSettings
178
+ };
@@ -0,0 +1,110 @@
1
+ function createDialog(dialog) {
2
+ return new Promise((resolve, reject) => {
3
+ let inputOrSelectElement = null;
4
+ const clear = () => {
5
+ _dialog.remove();
6
+ background.remove();
7
+ document.removeEventListener("keydown", handleKeyDown, { capture: true });
8
+ };
9
+ const submit = () => {
10
+ clear();
11
+ if (dialog.type === "prompt") {
12
+ resolve(inputOrSelectElement.value);
13
+ }
14
+ if (dialog.type === "confirm") {
15
+ resolve(true);
16
+ }
17
+ if (dialog.type === "pick") {
18
+ resolve(inputOrSelectElement.value);
19
+ }
20
+ };
21
+ const cancel = () => {
22
+ clear();
23
+ resolve(false);
24
+ };
25
+ const handleKeyDown = (e) => {
26
+ if (e.key === "Enter" || e.key === "Escape") {
27
+ e.preventDefault();
28
+ e.stopPropagation();
29
+ }
30
+ if (e.key === "Enter") submit();
31
+ if (e.key === "Escape") cancel();
32
+ };
33
+ document.addEventListener("keydown", handleKeyDown, { capture: true });
34
+ const background = document.createElement("div");
35
+ background.style.cssText = "position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; opacity: 0.5; background: black;";
36
+ const _dialog = document.createElement("div");
37
+ _dialog.classList.add("zcDialog");
38
+ _dialog.setAttribute("data-zc-dialog-type", dialog.type);
39
+ _dialog.style.fontFamily = CommonGetFontName();
40
+ const message = document.createElement("p");
41
+ message.textContent = dialog.message;
42
+ _dialog.append(message);
43
+ switch (dialog.type) {
44
+ case "confirm": {
45
+ break;
46
+ }
47
+ case "prompt": {
48
+ const input = document.createElement("input");
49
+ input.style.cssText = "color: white; margin-top: 1px; width: 90%; background: rgb(82, 89, 104); border: none; border-radius: 4px; padding: 0.45em;";
50
+ inputOrSelectElement = input;
51
+ _dialog.append(input);
52
+ break;
53
+ }
54
+ case "pick": {
55
+ const select = document.createElement("select");
56
+ select.style.cssText = "cursor: pointer; width: 90%; background: rgb(82, 89, 104); border: none; padding: 0.4em; color: white; border-radius: 4px;";
57
+ dialog.options.forEach((o) => {
58
+ const option = document.createElement("option");
59
+ option.setAttribute("key", o.name);
60
+ option.text = o.name;
61
+ select.append(option);
62
+ });
63
+ inputOrSelectElement = select;
64
+ _dialog.append(select);
65
+ break;
66
+ }
67
+ }
68
+ const buttons = document.createElement("div");
69
+ buttons.style.cssText = "display: flex; justify-content: end; column-gap: 0.75em; width: 90%; padding: 0.9em 0;";
70
+ const cancelBtn = document.createElement("button");
71
+ cancelBtn.textContent = "Cancel";
72
+ cancelBtn.addEventListener("click", cancel);
73
+ const submitBtn = document.createElement("button");
74
+ submitBtn.textContent = "Ok";
75
+ submitBtn.addEventListener("click", submit);
76
+ buttons.append(cancelBtn, submitBtn);
77
+ _dialog.append(buttons);
78
+ document.body.append(_dialog, background);
79
+ if (inputOrSelectElement) inputOrSelectElement.focus();
80
+ });
81
+ }
82
+ class DialogsManager {
83
+ process(dialogProps) {
84
+ return createDialog(dialogProps);
85
+ }
86
+ prompt({ message }) {
87
+ return this.process({
88
+ type: "prompt",
89
+ message
90
+ });
91
+ }
92
+ confirm({ message }) {
93
+ return this.process({
94
+ type: "confirm",
95
+ message
96
+ });
97
+ }
98
+ pick({ message, options }) {
99
+ return this.process({
100
+ type: "pick",
101
+ message,
102
+ options
103
+ });
104
+ }
105
+ }
106
+ const dialogsManager = new DialogsManager();
107
+ export {
108
+ DialogsManager,
109
+ dialogsManager
110
+ };
package/dist/index.js CHANGED
@@ -1 +1,201 @@
1
- import l from"./styles.css";import{findModByName as u,registerMod as g}from"./modsApi";import{initVirtualDOM as m,useToastsStore as d,useDialogStore as f}from"./popups";import{version as c}from"../package.json";import{version as B}from"../package.json";let p;function D(e){if(!window.ZOISCORE){const t=document.createElement("style");t.innerHTML=l,document.head.append(t),window.ZOISCORE=Object.freeze({loaded:!0,useToastsStore:d,useDialogStore:f,version:c}),document.addEventListener("click",r=>{const o=r.target.closest("a");if(o&&o.href)try{const n=new URL(o.href);if(n.protocol==="zc:"&&(r.preventDefault(),o.href.startsWith("zc://open"))){const i={subscreen:n.searchParams.get("subscreen")};n.searchParams.get("mod")&&(i.mod=n.searchParams.get("mod")),window.dispatchEvent(new CustomEvent("zoiscore:open",{detail:i}))}}catch{}},!0),m()}p={...e},g()}function h(e){return new Promise(t=>setTimeout(t,e))}async function y(e,t=()=>!1){for(;!e();){if(t())return!1;await h(10)}return!0}function b(e,t){return e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e}function S(e,t){const r=e.split("."),o=t.split(".");for(let n=0;n<Math.max(r.length,o.length);n++){const i=parseInt(r[n]||"0",10),s=parseInt(o[n]||"0",10);if(i>s)return!0;if(i<s)return!1}return!1}function T(e,t){return!e&&!t||!e&&t==="Default"||!t&&e==="Default"||e==="Default"&&Array.isArray(t)&&t.filter(r=>r==="Default").length===t.length||t==="Default"&&Array.isArray(e)&&e.filter(r=>r==="Default").length===e.length?!0:JSON.stringify(e)===JSON.stringify(t)}function N(e){return typeof e=="string"?Math.round(new TextEncoder().encode(e).byteLength/100)/10:Math.round(new TextEncoder().encode(JSON.stringify(e)).byteLength/100)/10}function O(e){if(e)return ChatRoomCharacter.find(t=>t.MemberNumber==e||t.Name.toLowerCase()===e||t.Nickname?.toLowerCase()===e)}function k(e){return CharacterNickname(e)}function E(){if(!u("Themed"))return null;const e=JSON.parse(LZString.decompressFromBase64(Player.ExtensionSettings.Themed??""));return!e?.GlobalModule?.themedEnabled||!e?.GlobalModule?.doVanillaGuiOverhaul?null:e.ColorsModule}function P(e){const t=document.createElement("style");t.innerHTML=e,document.head.append(t)}function v(e){y(()=>typeof window.Player?.MemberNumber=="number").then(()=>setTimeout(e,b(3e3,6e3)))}function a(e){return typeof e!="object"||e===null?e:Array.isArray(e)?e.map(a).sort():Object.keys(e).sort().reduce((t,r)=>(t[r]=a(e[r]),t),{})}export{p as MOD_DATA,T as colorsEqual,k as getNickname,O as getPlayer,b as getRandomNumber,N as getSizeInKbytes,E as getThemedColorsModule,P as injectStyles,S as isVersionNewer,a as normalizeObject,D as registerCore,h as sleep,B as version,y as waitFor,v as waitForStart};
1
+ import { registerCore } from "./core";
2
+ import { dialogsManager } from "./dialogs";
3
+ import { loadLocalization } from "./localization";
4
+ import { createModSdk, findModByName, hookFunction, HookPriority } from "./modSdk";
5
+ import { getCurrentSubscreen, setSubscreen } from "./ui";
6
+ import { version } from "../package.json";
7
+ let MOD_DATA;
8
+ function bootstrap(modData) {
9
+ if (!window.ZOIS_CORE) registerCore();
10
+ MOD_DATA = modData;
11
+ createModSdk();
12
+ loadLocalization();
13
+ hookFunction("GameKeyDown", HookPriority.ADD_BEHAVIOR, (args, next) => {
14
+ const currentSubscreen = getCurrentSubscreen();
15
+ if (CommonKey.IsPressed(args[0], "Escape") && !!currentSubscreen) {
16
+ currentSubscreen.exit();
17
+ return false;
18
+ }
19
+ const zcDialog = document.querySelector(".zcDialog");
20
+ if (zcDialog instanceof HTMLDivElement) {
21
+ zcDialog.focus();
22
+ return false;
23
+ }
24
+ return next(args);
25
+ });
26
+ window.addEventListener(
27
+ "zois-core:setsubscreen",
28
+ async (_event) => {
29
+ const event = _event;
30
+ const target = event.detail.target;
31
+ const isTrusted = event.detail.isTrusted;
32
+ if (target === void 0) return;
33
+ if (target.startsWith(MOD_DATA.key + ":")) {
34
+ const currentSubscreen = getCurrentSubscreen();
35
+ const mod = target.substring(0, MOD_DATA.key.length);
36
+ const subscreen = target.substring(MOD_DATA.key.length + 1);
37
+ if (currentSubscreen?.constructor?.name === subscreen) return;
38
+ const s = MOD_DATA.subscreens?.[subscreen];
39
+ if (s === void 0) return;
40
+ if (isTrusted || await dialogsManager.confirm({ message: `Confirm the redirecting to modded subscreen ${target}` })) {
41
+ await PreferenceOpenSubscreen("Extensions");
42
+ await PreferenceSubscreenExtensionsOpen(mod, ["Online", "ChatRoom"]);
43
+ setSubscreen(new s());
44
+ }
45
+ }
46
+ }
47
+ );
48
+ ServerIsLoggedInAsync().then(() => {
49
+ if (modData.onReady) setTimeout(modData.onReady, getRandomNumber(3e3, 6e3));
50
+ });
51
+ }
52
+ function formatString(text) {
53
+ if (!text || typeof text !== "string") {
54
+ return { isBeatifulString: false };
55
+ }
56
+ let result = text;
57
+ let hasChanges = false;
58
+ const markdownRegex = /\[([^\]]+?)\]\(([^)]+?)\)/g;
59
+ const newResult = result.replace(markdownRegex, (match, linkText, url) => {
60
+ hasChanges = true;
61
+ const escapedText = linkText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
62
+ return `<a href="${url}" target="_blank" rel="noopener noreferrer">${escapedText}</a>`;
63
+ });
64
+ if (newResult !== result) {
65
+ result = newResult;
66
+ }
67
+ const zcRegex = /(?<!\S)zc:\/\/open[^\s<>"']*(?!\S)/gi;
68
+ result = result.replace(zcRegex, (match) => {
69
+ hasChanges = true;
70
+ return `<a href="${match}" target="_blank" rel="noopener noreferrer">${match}</a>`;
71
+ });
72
+ if (hasChanges) {
73
+ return {
74
+ html: result,
75
+ isBeatifulString: true
76
+ };
77
+ }
78
+ return { isBeatifulString: false };
79
+ }
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
+ function sleep(ms) {
101
+ return new Promise((resolve) => setTimeout(resolve, ms));
102
+ }
103
+ async function waitFor(func, cancelFunc = () => false) {
104
+ while (!func()) {
105
+ if (cancelFunc()) {
106
+ return false;
107
+ }
108
+ await sleep(10);
109
+ }
110
+ return true;
111
+ }
112
+ function getRandomNumber(min, max) {
113
+ min = Math.ceil(min);
114
+ max = Math.floor(max);
115
+ return Math.floor(Math.random() * (max - min + 1)) + min;
116
+ }
117
+ function isVersionNewer(version1, version2) {
118
+ const v1Parts = version1.split(".");
119
+ const v2Parts = version2.split(".");
120
+ for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
121
+ const v1Part = parseInt(v1Parts[i] || "0", 10);
122
+ const v2Part = parseInt(v2Parts[i] || "0", 10);
123
+ if (v1Part > v2Part) {
124
+ return true;
125
+ } else if (v1Part < v2Part) {
126
+ return false;
127
+ }
128
+ }
129
+ return false;
130
+ }
131
+ function colorsEqual(c1, c2) {
132
+ if (!c1 && !c2) return true;
133
+ if (!c1 && c2 === "Default" || !c2 && c1 === "Default") return true;
134
+ if (c1 === "Default" && Array.isArray(c2) && c2.filter((d) => d === "Default").length === c2.length) return true;
135
+ if (c2 === "Default" && Array.isArray(c1) && c1.filter((d) => d === "Default").length === c1.length) return true;
136
+ return JSON.stringify(c1) === JSON.stringify(c2);
137
+ }
138
+ function getSizeInKbytes(b) {
139
+ if (typeof b === "string") {
140
+ return Math.round(new TextEncoder().encode(b).byteLength / 100) / 10;
141
+ } else {
142
+ return Math.round(new TextEncoder().encode(JSON.stringify(b)).byteLength / 100) / 10;
143
+ }
144
+ }
145
+ function getPlayer(value) {
146
+ if (!value) return null;
147
+ return ChatRoomCharacter.find((Character) => {
148
+ return Character.MemberNumber == value || Character.Name.toLowerCase() === value || Character.Nickname?.toLowerCase() === value;
149
+ }) ?? null;
150
+ }
151
+ function getNickname(target) {
152
+ return CharacterNickname(target);
153
+ }
154
+ function getThemedColorsModule() {
155
+ if (!findModByName("Themed")) return null;
156
+ const data = LZString.decompressFromBase64(Player.ExtensionSettings.Themed ?? "") ?? "{}";
157
+ let themedData;
158
+ try {
159
+ themedData = JSON.parse(data);
160
+ } catch {
161
+ }
162
+ ;
163
+ if (!themedData?.GlobalModule?.themedEnabled || !themedData?.GlobalModule?.doVanillaGuiOverhaul) return null;
164
+ return themedData.ColorsModule;
165
+ }
166
+ function injectStyles(stylesToInject) {
167
+ const style = document.createElement("style");
168
+ style.innerHTML = stylesToInject;
169
+ document.head.append(style);
170
+ }
171
+ function normalizeObject(obj) {
172
+ if (!CommonIsObject(obj)) return obj;
173
+ if (Array.isArray(obj)) {
174
+ return obj.map(normalizeObject).sort();
175
+ }
176
+ return Object.keys(obj).sort().reduce((acc, key) => {
177
+ acc[key] = normalizeObject(obj[key]);
178
+ return acc;
179
+ }, {});
180
+ }
181
+ export {
182
+ CoreSettingsChangedEvent,
183
+ MOD_DATA,
184
+ SetSubscreenEvent,
185
+ SubscreenLoadedEvent,
186
+ SubscreenUnloadedEvent,
187
+ bootstrap,
188
+ colorsEqual,
189
+ formatString,
190
+ getNickname,
191
+ getPlayer,
192
+ getRandomNumber,
193
+ getSizeInKbytes,
194
+ getThemedColorsModule,
195
+ injectStyles,
196
+ isVersionNewer,
197
+ normalizeObject,
198
+ sleep,
199
+ version,
200
+ waitFor
201
+ };
@@ -0,0 +1,71 @@
1
+ import { MOD_DATA } from "./index";
2
+ import { logger } from "./logging";
3
+ import { hookFunction, HookPriority } from "./modSdk";
4
+ let translations = {};
5
+ function getText(tag, replacements) {
6
+ if (MOD_DATA.localization === void 0) {
7
+ logger.warn("Attempt to call getText() without configuring localization");
8
+ return tag;
9
+ }
10
+ const defaultLocale = MOD_DATA.localization.locales.default;
11
+ const preferredLocale = TranslationLanguage;
12
+ const value = getNestedValue(translations[preferredLocale], tag) ?? getNestedValue(translations[defaultLocale], tag);
13
+ if (!value) {
14
+ logger.warn("Unknown translation tag:", tag);
15
+ return tag;
16
+ }
17
+ ;
18
+ return replacements ? processReplacements(value, replacements) : value;
19
+ }
20
+ function getNestedValue(obj, path) {
21
+ if (!obj || !path) return void 0;
22
+ return path.split(".").reduce((current, key) => {
23
+ if (current && typeof current === "object" && key in current) {
24
+ return current[key];
25
+ }
26
+ return void 0;
27
+ }, obj);
28
+ }
29
+ function processReplacements(text, replacements) {
30
+ for (const [key, value] of Object.entries(replacements)) {
31
+ text = text.replaceAll("$" + key, value.toString());
32
+ }
33
+ return text;
34
+ }
35
+ async function loadLocalization() {
36
+ if (MOD_DATA.localization === void 0) {
37
+ logger.log("Skip localization procedure because its not configured");
38
+ return;
39
+ }
40
+ const supportedLocales = MOD_DATA.localization.locales.supported;
41
+ const defaultLocale = MOD_DATA.localization.locales.default;
42
+ const preferredLocale = TranslationLanguage;
43
+ if (!supportedLocales.includes(defaultLocale)) {
44
+ logger.warn(`Default locale ${defaultLocale} isn't supported, fix configuration`);
45
+ return;
46
+ }
47
+ hookFunction("TranslationSwitchLanguage", HookPriority.OBSERVE, (args, next) => {
48
+ const value = next(args);
49
+ if (supportedLocales.includes(TranslationLanguage) && !(TranslationLanguage in translations)) {
50
+ fetchTranslationsForLocale(TranslationLanguage);
51
+ }
52
+ return value;
53
+ });
54
+ await fetchTranslationsForLocale(defaultLocale);
55
+ if (preferredLocale !== defaultLocale && supportedLocales.includes(preferredLocale)) {
56
+ await fetchTranslationsForLocale(preferredLocale);
57
+ }
58
+ }
59
+ async function fetchTranslationsForLocale(locale) {
60
+ const response = await fetch(MOD_DATA.localization.translationsFolderPath + "/" + locale + ".json?=" + Date.now());
61
+ if (!response.ok) return logger.error(`Failed to fetch ${locale} translations at ${response.url}` + locale);
62
+ const data = await response.json();
63
+ logger.log(`Fetched translations for locale: ${locale}`, data);
64
+ translations[locale] = data;
65
+ }
66
+ export {
67
+ fetchTranslationsForLocale,
68
+ getText,
69
+ loadLocalization,
70
+ processReplacements
71
+ };
@@ -0,0 +1,31 @@
1
+ import { MOD_DATA } from "./index";
2
+ const logs = [];
3
+ class Logger {
4
+ get logs() {
5
+ return logs;
6
+ }
7
+ pushLog(level, message) {
8
+ this.logs.push({
9
+ level,
10
+ message,
11
+ timestamp: Date.now()
12
+ });
13
+ console[level](`%c${MOD_DATA.key}:`, "color: #00ffe7;", ...message);
14
+ }
15
+ debug(...message) {
16
+ this.pushLog("debug", message);
17
+ }
18
+ log(...message) {
19
+ this.pushLog("log", message);
20
+ }
21
+ warn(...message) {
22
+ this.pushLog("warn", message);
23
+ }
24
+ error(...message) {
25
+ this.pushLog("error", message);
26
+ }
27
+ }
28
+ const logger = new Logger();
29
+ export {
30
+ logger
31
+ };