zois-core 2.0.0 → 2.0.2
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/exit.svg +17 -0
- package/dist/changelogs.js +30 -44
- package/dist/core.js +3 -3
- package/dist/dialogs.js +2 -2
- package/dist/index.js +4 -5
- package/dist/shards/buttonShard.js +45 -13
- package/dist/shards/checkboxShard.js +1 -1
- package/dist/shards/containerShard.js +122 -5
- package/dist/shards/shard.js +9 -6
- package/dist/shards/svgShard.js +1 -19
- package/dist/toasts.js +2 -1
- package/dist/types/changelogs.d.ts +1 -1
- package/dist/types/globals.d.ts +6 -0
- package/dist/types/index.d.ts +14 -8
- package/dist/types/shards/buttonShard.d.ts +2 -1
- package/dist/types/shards/containerShard.d.ts +5 -2
- package/dist/types/shards/shard.d.ts +1 -0
- package/dist/types/ui.d.ts +10 -1
- package/dist/ui.js +39 -7
- package/package.json +6 -3
- package/scripts/zois-core.mjs +126 -0
- package/scripts/generateChangelog.mjs +0 -80
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg"
|
|
2
|
+
width="86" height="86"
|
|
3
|
+
viewBox="0 0 86 86"
|
|
4
|
+
fill="none">
|
|
5
|
+
<g transform="translate(0.000000,86.000000) scale(0.100000,-0.100000)"
|
|
6
|
+
fill="currentColor" stroke="none">
|
|
7
|
+
<path d="M120 507 l0 -305 151 -81 c83 -45 160 -81 170 -81 18 0 19 12 19 281
|
|
8
|
+
0 163 -4 288 -10 299 -11 20 -44 40 -212 129 l-118 62 0 -304z"/>
|
|
9
|
+
<path d="M260 787 c31 -19 52 -23 180 -27 l145 -5 3 -72 3 -73 29 0 30 0 0 81
|
|
10
|
+
c0 126 14 119 -223 119 l-202 0 35 -23z"/>
|
|
11
|
+
<path d="M690 590 c0 -19 -7 -20 -90 -20 l-90 0 0 -60 0 -60 90 0 c83 0 90 -1
|
|
12
|
+
90 -20 0 -11 3 -20 7 -20 14 0 93 84 93 99 0 16 -78 101 -92 101 -4 0 -8 -9
|
|
13
|
+
-8 -20z"/>
|
|
14
|
+
<path d="M590 336 l0 -76 -40 0 c-38 0 -40 -2 -40 -30 0 -29 1 -30 50 -30 77 0
|
|
15
|
+
92 20 88 123 -3 81 -3 82 -30 85 l-28 3 0 -75z"/>
|
|
16
|
+
</g>
|
|
17
|
+
</svg>
|
package/dist/changelogs.js
CHANGED
|
@@ -1,37 +1,8 @@
|
|
|
1
1
|
import { MOD_DATA } from ".";
|
|
2
2
|
import { logger } from "./logging";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
class GitHubAPI {
|
|
6
|
-
static baseUrl = "https://api.github.com";
|
|
7
|
-
static getHeaders() {
|
|
8
|
-
const headers = {
|
|
9
|
-
"Accept": "application/vnd.github.v3+json",
|
|
10
|
-
"User-Agent": "GitHubAPI-Client"
|
|
11
|
-
};
|
|
12
|
-
return headers;
|
|
13
|
-
}
|
|
14
|
-
static async getCommit(sha) {
|
|
15
|
-
const effectiveOwner = MOD_DATA.changelog?.owner;
|
|
16
|
-
const effectiveRepo = MOD_DATA.changelog?.repo;
|
|
17
|
-
const url = `${GitHubAPI.baseUrl}/repos/${effectiveOwner}/${effectiveRepo}/commits/${sha}`;
|
|
18
|
-
const response = await fetch(url, {
|
|
19
|
-
method: "GET",
|
|
20
|
-
headers: this.getHeaders()
|
|
21
|
-
});
|
|
22
|
-
if (!response.ok) {
|
|
23
|
-
const error = await response.json().catch(() => ({}));
|
|
24
|
-
logger.error(`GitHub API error: ${response.status} ${error.message || response.statusText}`);
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
return await response.json();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function showChangelogModal() {
|
|
3
|
+
import { addDynamicClass } from "./ui";
|
|
4
|
+
function showChangelogModal() {
|
|
31
5
|
const changelog = MOD_DATA.changelog;
|
|
32
|
-
const id = toastsManager.spinner({
|
|
33
|
-
message: "Preparing changelog..."
|
|
34
|
-
});
|
|
35
6
|
const { data } = changelog;
|
|
36
7
|
const overlay = document.createElement("div");
|
|
37
8
|
overlay.style.cssText = `
|
|
@@ -93,8 +64,8 @@ async function showChangelogModal() {
|
|
|
93
64
|
commitsList.style.display = "flex";
|
|
94
65
|
commitsList.style.flexDirection = "column";
|
|
95
66
|
commitsList.style.gap = "16px";
|
|
96
|
-
for (const commitData of data) {
|
|
97
|
-
const commitElement =
|
|
67
|
+
for (const commitData of data.changes) {
|
|
68
|
+
const commitElement = createCommitElement(commitData);
|
|
98
69
|
if (commitElement) commitsList.appendChild(commitElement);
|
|
99
70
|
}
|
|
100
71
|
content.appendChild(commitsList);
|
|
@@ -112,14 +83,9 @@ async function showChangelogModal() {
|
|
|
112
83
|
document.removeEventListener("keydown", handler);
|
|
113
84
|
}
|
|
114
85
|
});
|
|
115
|
-
toastsManager.removeSpinner(id);
|
|
116
86
|
}
|
|
117
|
-
|
|
87
|
+
function createCommitElement(changelogCommit) {
|
|
118
88
|
try {
|
|
119
|
-
if (!avatarsCache.has(changelogCommit.author)) {
|
|
120
|
-
const githubCommit = await GitHubAPI.getCommit(changelogCommit.hash);
|
|
121
|
-
avatarsCache.set(changelogCommit.author, githubCommit?.author?.avatar_url || githubCommit?.committer?.avatar_url || "https://github.com/identicons/default.png");
|
|
122
|
-
}
|
|
123
89
|
const commitDiv = document.createElement("div");
|
|
124
90
|
commitDiv.style.cssText = `
|
|
125
91
|
display: flex;
|
|
@@ -133,7 +99,7 @@ async function createCommitElement(changelogCommit) {
|
|
|
133
99
|
commitDiv.onmouseover = () => commitDiv.style.borderColor = "#3b82f6";
|
|
134
100
|
commitDiv.onmouseout = () => commitDiv.style.borderColor = "#e5e7eb";
|
|
135
101
|
const avatar = document.createElement("img");
|
|
136
|
-
avatar.src =
|
|
102
|
+
avatar.src = changelogCommit.author.avatar_url;
|
|
137
103
|
avatar.style.cssText = `
|
|
138
104
|
width: 48px;
|
|
139
105
|
height: 48px;
|
|
@@ -142,23 +108,43 @@ async function createCommitElement(changelogCommit) {
|
|
|
142
108
|
`;
|
|
143
109
|
const info = document.createElement("div");
|
|
144
110
|
info.style.flex = "1";
|
|
111
|
+
info.style.position = "relative";
|
|
145
112
|
const author = document.createElement("div");
|
|
146
|
-
author.textContent = changelogCommit.author;
|
|
113
|
+
author.textContent = changelogCommit.author.name;
|
|
147
114
|
author.style.fontWeight = "600";
|
|
148
115
|
author.style.marginBottom = "4px";
|
|
149
116
|
const message = document.createElement("div");
|
|
150
117
|
message.textContent = changelogCommit.message;
|
|
151
118
|
message.style.cssText = "color: #374151; line-height: 1.4;";
|
|
152
|
-
|
|
119
|
+
const tags = document.createElement("div");
|
|
120
|
+
tags.style.cssText = "display: flex; gap: 4px; position: absolute; right: 2px; top: 2px;";
|
|
121
|
+
for (const tag of changelogCommit.tags) {
|
|
122
|
+
const tagEl = document.createElement("p");
|
|
123
|
+
tagEl.textContent = tag;
|
|
124
|
+
addDynamicClass(tagEl, {
|
|
125
|
+
base: {
|
|
126
|
+
fontSize: "0.85em",
|
|
127
|
+
padding: "2px 6px",
|
|
128
|
+
borderRadius: "6px",
|
|
129
|
+
background: tag === "fix" ? "#f9b4b4" : tag === "feature" ? "#cbffcbc7" : "#a1e0f4",
|
|
130
|
+
color: tag === "fix" ? "#771515" : tag === "feature" ? "#147914" : "#09093e",
|
|
131
|
+
borderWidth: "1px",
|
|
132
|
+
borderStyle: "solid",
|
|
133
|
+
borderColor: tag === "fix" ? "#ca6565" : tag === "feature" ? "#4eea4e" : "#66adec"
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
tags.append(tagEl);
|
|
137
|
+
}
|
|
138
|
+
info.append(author, message, tags);
|
|
153
139
|
commitDiv.style.cursor = "pointer";
|
|
154
140
|
commitDiv.onclick = () => {
|
|
155
|
-
window.open(
|
|
141
|
+
window.open(changelogCommit.commit_url, "_blank");
|
|
156
142
|
};
|
|
157
143
|
commitDiv.appendChild(avatar);
|
|
158
144
|
commitDiv.appendChild(info);
|
|
159
145
|
return commitDiv;
|
|
160
146
|
} catch (err) {
|
|
161
|
-
logger.error(`Failed to load commit ${changelogCommit.
|
|
147
|
+
logger.error(`Failed to load commit ${changelogCommit.sha}:`, err);
|
|
162
148
|
return null;
|
|
163
149
|
}
|
|
164
150
|
}
|
package/dist/core.js
CHANGED
|
@@ -39,6 +39,9 @@ function registerSubscreen() {
|
|
|
39
39
|
}
|
|
40
40
|
let loginScreenElements = [];
|
|
41
41
|
async function registerCore() {
|
|
42
|
+
const style = document.createElement("style");
|
|
43
|
+
style.innerHTML = styles;
|
|
44
|
+
document.head.append(style);
|
|
42
45
|
if (localStorage.getItem("autoConnectToDevServer") === "true") {
|
|
43
46
|
hookFunction("CommonGetServer", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
|
|
44
47
|
return "https://bondage-club-server-test.herokuapp.com/";
|
|
@@ -84,9 +87,6 @@ async function registerCore() {
|
|
|
84
87
|
coreSettings = JSON.parse(LZString.decompressFromBase64(Player.ExtensionSettings.ZOIS_CORE) ?? "{}");
|
|
85
88
|
}
|
|
86
89
|
if (coreSettings.devMode) registerSubscreen();
|
|
87
|
-
const style = document.createElement("style");
|
|
88
|
-
style.innerHTML = styles;
|
|
89
|
-
document.head.append(style);
|
|
90
90
|
window.ZOIS_CORE = Object.freeze({
|
|
91
91
|
version,
|
|
92
92
|
enableDevMode: () => {
|
package/dist/dialogs.js
CHANGED
|
@@ -4,7 +4,7 @@ function createDialog(dialog) {
|
|
|
4
4
|
const clear = () => {
|
|
5
5
|
_dialog.remove();
|
|
6
6
|
background.remove();
|
|
7
|
-
document.removeEventListener("keydown", handleKeyDown);
|
|
7
|
+
document.removeEventListener("keydown", handleKeyDown, { capture: true });
|
|
8
8
|
};
|
|
9
9
|
const submit = () => {
|
|
10
10
|
clear();
|
|
@@ -30,7 +30,7 @@ function createDialog(dialog) {
|
|
|
30
30
|
if (e.key === "Enter") submit();
|
|
31
31
|
if (e.key === "Escape") cancel();
|
|
32
32
|
};
|
|
33
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
33
|
+
document.addEventListener("keydown", handleKeyDown, { capture: true });
|
|
34
34
|
const background = document.createElement("div");
|
|
35
35
|
background.style.cssText = "position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; opacity: 0.5; background: black;";
|
|
36
36
|
const _dialog = document.createElement("div");
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,9 @@ function bootstrap(modData) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
);
|
|
48
|
+
ServerIsLoggedInAsync().then(() => {
|
|
49
|
+
if (modData.onReady) setTimeout(modData.onReady, getRandomNumber(3e3, 6e3));
|
|
50
|
+
});
|
|
48
51
|
}
|
|
49
52
|
function formatString(text) {
|
|
50
53
|
if (!text || typeof text !== "string") {
|
|
@@ -165,9 +168,6 @@ function injectStyles(stylesToInject) {
|
|
|
165
168
|
style.innerHTML = stylesToInject;
|
|
166
169
|
document.head.append(style);
|
|
167
170
|
}
|
|
168
|
-
function waitForStart(callback) {
|
|
169
|
-
waitFor(() => typeof window.Player?.MemberNumber === "number").then(() => setTimeout(callback, getRandomNumber(3e3, 6e3)));
|
|
170
|
-
}
|
|
171
171
|
function normalizeObject(obj) {
|
|
172
172
|
if (!CommonIsObject(obj)) return obj;
|
|
173
173
|
if (Array.isArray(obj)) {
|
|
@@ -197,6 +197,5 @@ export {
|
|
|
197
197
|
normalizeObject,
|
|
198
198
|
sleep,
|
|
199
199
|
version,
|
|
200
|
-
waitFor
|
|
201
|
-
waitForStart
|
|
200
|
+
waitFor
|
|
202
201
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createElement, ExternalLink } from "lucide";
|
|
1
2
|
import { MOD_DATA } from "../index";
|
|
2
3
|
import { addDynamicClass, autosetFontSize, setFontFamily, setFontSize } from "../ui";
|
|
3
4
|
import { Shard } from "./shard";
|
|
@@ -36,33 +37,52 @@ class ButtonShard extends Shard {
|
|
|
36
37
|
":hover .tooltip": {
|
|
37
38
|
visibility: "visible"
|
|
38
39
|
},
|
|
39
|
-
"[data-zc-
|
|
40
|
-
background: "rgb(124, 255, 124)",
|
|
41
|
-
borderColor: "rgb(82, 204, 82)",
|
|
42
|
-
color: "black"
|
|
43
|
-
},
|
|
44
|
-
"[data-zc-style=green]:hover": {
|
|
45
|
-
background: "rgb(94, 197, 94)",
|
|
46
|
-
color: "black"
|
|
47
|
-
},
|
|
48
|
-
"[data-zc-style=inverted]": {
|
|
40
|
+
"[data-zc-variant=filled]": {
|
|
49
41
|
background: "var(--tmd-accent, #111)",
|
|
50
42
|
border: "2px solid var(--tmd-accent, #111)",
|
|
51
43
|
color: "var(--tmd-text, white)"
|
|
52
44
|
},
|
|
53
|
-
"[data-zc-
|
|
45
|
+
"[data-zc-variant=filled]:hover": {
|
|
54
46
|
background: "var(--tmd-accent-hover, none)",
|
|
55
47
|
color: "var(--tmd-text, black)"
|
|
48
|
+
},
|
|
49
|
+
"> .external-link-icon": {
|
|
50
|
+
display: "flex",
|
|
51
|
+
columnGap: "0.25em",
|
|
52
|
+
position: "absolute",
|
|
53
|
+
right: "-0.25em",
|
|
54
|
+
top: "-0.25em",
|
|
55
|
+
width: "0.75em",
|
|
56
|
+
height: "0.75em",
|
|
57
|
+
background: "var(--tmd-accent, #5b5bff)",
|
|
58
|
+
color: "var(--tmd-text, white)",
|
|
59
|
+
padding: "0.1em",
|
|
60
|
+
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"
|
|
56
76
|
}
|
|
57
77
|
};
|
|
58
78
|
}
|
|
59
79
|
generateBody() {
|
|
60
|
-
const { text,
|
|
80
|
+
const { text, variant, icon, iconAbsolutePosition = true, tooltip, href, onClick, isDisabled } = this.context;
|
|
61
81
|
let iconElement;
|
|
62
82
|
let textElement;
|
|
63
83
|
const btn = document.createElement("button");
|
|
64
84
|
addDynamicClass(btn, this.dynamicClassButton);
|
|
65
|
-
btn.setAttribute("data-zc-
|
|
85
|
+
btn.setAttribute("data-zc-variant", variant);
|
|
66
86
|
btn.style.display = "flex";
|
|
67
87
|
btn.style.alignItems = "center";
|
|
68
88
|
btn.style.justifyContent = "center";
|
|
@@ -96,10 +116,22 @@ class ButtonShard extends Shard {
|
|
|
96
116
|
tooltipEl.textContent = tooltip.text;
|
|
97
117
|
btn.append(tooltipEl);
|
|
98
118
|
}
|
|
119
|
+
if (href) {
|
|
120
|
+
const externalLinkContainer = document.createElement("div");
|
|
121
|
+
externalLinkContainer.classList.add("external-link-icon");
|
|
122
|
+
const externalLinkIcon = createElement(ExternalLink);
|
|
123
|
+
externalLinkIcon.style.width = "auto";
|
|
124
|
+
externalLinkIcon.style.height = "100%";
|
|
125
|
+
const externalLinkLabel = document.createElement("span");
|
|
126
|
+
externalLinkLabel.textContent = href;
|
|
127
|
+
externalLinkContainer.append(externalLinkIcon, externalLinkLabel);
|
|
128
|
+
btn.append(externalLinkContainer);
|
|
129
|
+
}
|
|
99
130
|
if (typeof isDisabled === "function" && isDisabled()) btn.classList.add("zcDisabled");
|
|
100
131
|
btn.addEventListener("click", () => {
|
|
101
132
|
if (typeof isDisabled === "function" && isDisabled()) return btn.classList.add("zcDisabled");
|
|
102
133
|
if (typeof onClick === "function") onClick();
|
|
134
|
+
if (href) window.open(href, "_blank", "noopener,noreferrer");
|
|
103
135
|
});
|
|
104
136
|
return {
|
|
105
137
|
text: textElement,
|
|
@@ -15,7 +15,7 @@ class CheckboxShard extends Shard {
|
|
|
15
15
|
display: "flex",
|
|
16
16
|
alignItems: "center",
|
|
17
17
|
justifyContent: "center",
|
|
18
|
-
transition: "
|
|
18
|
+
transition: "background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
|
|
19
19
|
appearance: "none"
|
|
20
20
|
},
|
|
21
21
|
":checked": {
|
|
@@ -1,13 +1,130 @@
|
|
|
1
|
+
import { addDynamicClass } from "../ui";
|
|
1
2
|
import { Shard } from "./shard";
|
|
2
3
|
class ContainerShard extends Shard {
|
|
4
|
+
get dynamicClassContainer() {
|
|
5
|
+
return {
|
|
6
|
+
base: {},
|
|
7
|
+
"> div:first-child::-webkit-scrollbar": {
|
|
8
|
+
display: "none"
|
|
9
|
+
},
|
|
10
|
+
"> div:first-child": {
|
|
11
|
+
scrollbarWidth: "none"
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
get mountReturnValue() {
|
|
16
|
+
return this.body?.content ?? null;
|
|
17
|
+
}
|
|
3
18
|
generateBody() {
|
|
19
|
+
const scrollMode = this.context.scroll ?? "auto";
|
|
4
20
|
const container = document.createElement("div");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
21
|
+
container.style.position = "relative";
|
|
22
|
+
addDynamicClass(container, this.dynamicClassContainer);
|
|
23
|
+
const mayNeedVerticalScrollbar = scrollMode === "y" || scrollMode === "all" || scrollMode === "auto";
|
|
24
|
+
const containerContent = document.createElement("div");
|
|
25
|
+
containerContent.style.width = "100%";
|
|
26
|
+
containerContent.style.height = "100%";
|
|
27
|
+
containerContent.style.boxSizing = "border-box";
|
|
28
|
+
switch (scrollMode) {
|
|
29
|
+
case "all":
|
|
30
|
+
containerContent.style.overflow = "scroll";
|
|
31
|
+
break;
|
|
32
|
+
case "x":
|
|
33
|
+
containerContent.style.overflowX = "scroll";
|
|
34
|
+
containerContent.style.overflowY = "hidden";
|
|
35
|
+
break;
|
|
36
|
+
case "y":
|
|
37
|
+
containerContent.style.overflowY = "scroll";
|
|
38
|
+
containerContent.style.overflowX = "hidden";
|
|
39
|
+
break;
|
|
40
|
+
case "none":
|
|
41
|
+
containerContent.style.overflow = "unset";
|
|
42
|
+
break;
|
|
43
|
+
case "auto":
|
|
44
|
+
default:
|
|
45
|
+
containerContent.style.overflow = "auto";
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const scrollbar = document.createElement("div");
|
|
49
|
+
scrollbar.style.cssText = `
|
|
50
|
+
position: absolute;
|
|
51
|
+
right: 0;
|
|
52
|
+
top: 50%;
|
|
53
|
+
display: none;
|
|
54
|
+
flex-direction: column;
|
|
55
|
+
gap: calc(var(--size-unit) * 1.25px);
|
|
56
|
+
transform: translateY(-50%);
|
|
57
|
+
pointer-events: none;
|
|
58
|
+
z-index: 10;
|
|
59
|
+
width: calc(var(--size-unit) * 1.25px);
|
|
60
|
+
`;
|
|
61
|
+
const diamonds = [];
|
|
62
|
+
for (let i = 0; i < 6; i++) {
|
|
63
|
+
const diamond = document.createElement("div");
|
|
64
|
+
diamond.style.cssText = `
|
|
65
|
+
transform: rotate(45deg);
|
|
66
|
+
width: 100%;
|
|
67
|
+
aspect-ratio: 1/1;
|
|
68
|
+
background: var(--tmd-element, gray);
|
|
69
|
+
border: 1px solid var(--tmd-accent, black);
|
|
70
|
+
transition: background 0.15s ease, transform 0.15s ease;
|
|
71
|
+
`;
|
|
72
|
+
scrollbar.append(diamond);
|
|
73
|
+
diamonds.push(diamond);
|
|
74
|
+
}
|
|
75
|
+
const updateIndicators = () => {
|
|
76
|
+
const maxScroll = containerContent.scrollHeight - containerContent.clientHeight;
|
|
77
|
+
if (maxScroll <= 1) {
|
|
78
|
+
diamonds.forEach((d) => {
|
|
79
|
+
d.style.background = "var(--tmd-element, gray)";
|
|
80
|
+
d.style.transform = "rotate(45deg) scale(1)";
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const progress = Math.min(1, Math.max(0, containerContent.scrollTop / maxScroll));
|
|
85
|
+
const activeIndex = Math.round(progress * (diamonds.length - 1));
|
|
86
|
+
diamonds.forEach((diamond, i) => {
|
|
87
|
+
if (i === activeIndex) {
|
|
88
|
+
diamond.style.background = "var(--tmd-accent, #fff)";
|
|
89
|
+
diamond.style.transform = "rotate(45deg) scale(1.25)";
|
|
90
|
+
} else if (i < activeIndex) {
|
|
91
|
+
diamond.style.background = "var(--tmd-element, #aaa)";
|
|
92
|
+
diamond.style.transform = "rotate(45deg) scale(1)";
|
|
93
|
+
} else {
|
|
94
|
+
diamond.style.background = "var(--tmd-element-hover, gray)";
|
|
95
|
+
diamond.style.transform = "rotate(45deg) scale(1)";
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
containerContent.addEventListener("scroll", updateIndicators, { passive: true });
|
|
100
|
+
const needsVerticalScrollbar = scrollMode === "y" || scrollMode === "all";
|
|
101
|
+
const updateScrollbarVisibility = () => {
|
|
102
|
+
const isOverflowing = containerContent.scrollHeight - containerContent.clientHeight > 1;
|
|
103
|
+
const shouldShow = needsVerticalScrollbar || scrollMode === "auto" && isOverflowing;
|
|
104
|
+
containerContent.style.paddingRight = shouldShow ? "min(2vw, 2vh)" : "";
|
|
105
|
+
scrollbar.style.display = shouldShow ? "flex" : "none";
|
|
106
|
+
updateIndicators();
|
|
107
|
+
};
|
|
108
|
+
if (mayNeedVerticalScrollbar) {
|
|
109
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
110
|
+
requestAnimationFrame(updateScrollbarVisibility);
|
|
111
|
+
});
|
|
112
|
+
resizeObserver.observe(containerContent);
|
|
113
|
+
const mutationObserver = new MutationObserver(() => {
|
|
114
|
+
requestAnimationFrame(updateScrollbarVisibility);
|
|
115
|
+
});
|
|
116
|
+
mutationObserver.observe(containerContent, {
|
|
117
|
+
childList: true,
|
|
118
|
+
subtree: true,
|
|
119
|
+
characterData: true
|
|
120
|
+
});
|
|
121
|
+
requestAnimationFrame(updateScrollbarVisibility);
|
|
122
|
+
}
|
|
123
|
+
container.append(containerContent, scrollbar);
|
|
9
124
|
return {
|
|
10
|
-
base: container
|
|
125
|
+
base: container,
|
|
126
|
+
content: containerContent,
|
|
127
|
+
scrollbar
|
|
11
128
|
};
|
|
12
129
|
}
|
|
13
130
|
}
|
package/dist/shards/shard.js
CHANGED
|
@@ -11,6 +11,9 @@ class Shard {
|
|
|
11
11
|
}
|
|
12
12
|
context;
|
|
13
13
|
body = null;
|
|
14
|
+
get mountReturnValue() {
|
|
15
|
+
return this.body?.base ?? null;
|
|
16
|
+
}
|
|
14
17
|
mount(parentElement = this.context.parent ?? document.body) {
|
|
15
18
|
parentElement.append(this.body.base);
|
|
16
19
|
this.update();
|
|
@@ -22,7 +25,7 @@ class Shard {
|
|
|
22
25
|
window.removeEventListener("zois-core:subscreenunloaded", onUnload);
|
|
23
26
|
};
|
|
24
27
|
window.addEventListener("zois-core:subscreenunloaded", onUnload);
|
|
25
|
-
return this.
|
|
28
|
+
return this.mountReturnValue;
|
|
26
29
|
}
|
|
27
30
|
processModules(stage) {
|
|
28
31
|
const modules = this.context.modules ?? {};
|
|
@@ -33,7 +36,7 @@ class Shard {
|
|
|
33
36
|
try {
|
|
34
37
|
this.context = module.overrideContext(this.context, this.body[key]);
|
|
35
38
|
} catch (e) {
|
|
36
|
-
logger.error("OverrideContext call failed in", module);
|
|
39
|
+
logger.error("OverrideContext call failed in", module, e);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
}
|
|
@@ -45,8 +48,8 @@ class Shard {
|
|
|
45
48
|
if (module instanceof ShardModule) {
|
|
46
49
|
try {
|
|
47
50
|
module.layoutEffect(this.context, this.body[key]);
|
|
48
|
-
} catch {
|
|
49
|
-
logger.error("LayoutEffect call failed in", module);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
logger.error("LayoutEffect call failed in", module, e);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
}
|
|
@@ -58,8 +61,8 @@ class Shard {
|
|
|
58
61
|
if (module instanceof ShardModule) {
|
|
59
62
|
try {
|
|
60
63
|
module.effect(this.context, this.body[key]);
|
|
61
|
-
} catch {
|
|
62
|
-
logger.error("Effect call failed in", module);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
logger.error("Effect call failed in", module, e);
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
}
|
package/dist/shards/svgShard.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setSize } from "../ui";
|
|
1
|
+
import { recolorSVG, setSize } from "../ui";
|
|
2
2
|
import { Shard } from "./shard";
|
|
3
3
|
class SvgShard extends Shard {
|
|
4
4
|
generateBody() {
|
|
@@ -10,24 +10,6 @@ class SvgShard extends Shard {
|
|
|
10
10
|
div.innerHTML = svgString;
|
|
11
11
|
return div.firstElementChild;
|
|
12
12
|
}
|
|
13
|
-
function recolorSVG(svgElement, { fill: fill2, stroke: stroke2 }) {
|
|
14
|
-
const elements = svgElement.querySelectorAll("*");
|
|
15
|
-
elements.forEach((element) => {
|
|
16
|
-
if (element.getAttribute("fill") !== "none") {
|
|
17
|
-
element.setAttribute("fill", fill2);
|
|
18
|
-
}
|
|
19
|
-
if (element.getAttribute("stroke") !== "none") {
|
|
20
|
-
element.setAttribute("stroke", stroke2);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
if (svgElement.getAttribute("fill") !== "none") {
|
|
24
|
-
svgElement.setAttribute("fill", fill2);
|
|
25
|
-
}
|
|
26
|
-
if (svgElement.getAttribute("stroke") !== "none") {
|
|
27
|
-
svgElement.setAttribute("stroke", stroke2);
|
|
28
|
-
}
|
|
29
|
-
return svgElement;
|
|
30
|
-
}
|
|
31
13
|
const svg = dataURLToSVGElement(dataurl);
|
|
32
14
|
if (svg) {
|
|
33
15
|
recolorSVG(svg, { fill, stroke });
|
package/dist/toasts.js
CHANGED
|
@@ -105,9 +105,10 @@ function createToast({ title, message, type, duration, theme, id }) {
|
|
|
105
105
|
_message.textContent = message;
|
|
106
106
|
textContainer.append(_message);
|
|
107
107
|
toast.append(getToastIcon(type, theme), textContainer);
|
|
108
|
-
update();
|
|
109
108
|
window.addEventListener("resize", update);
|
|
110
109
|
toastContainer.append(toast);
|
|
110
|
+
update();
|
|
111
|
+
void toast.offsetHeight;
|
|
111
112
|
setTimeout(() => {
|
|
112
113
|
toast.style.animation = `${pos.includes("left") ? "zcSlideOutToLeft" : "zcSlideOutToRight"} 0.3s ease-out forwards`;
|
|
113
114
|
}, duration);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function showChangelogModal():
|
|
1
|
+
export declare function showChangelogModal(): void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,14 +26,21 @@ export interface ModData {
|
|
|
26
26
|
};
|
|
27
27
|
changelog?: {
|
|
28
28
|
data: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
generated_at: string;
|
|
30
|
+
changes: {
|
|
31
|
+
message: string;
|
|
32
|
+
sha: string;
|
|
33
|
+
author: {
|
|
34
|
+
name: string;
|
|
35
|
+
avatar_url: string;
|
|
36
|
+
};
|
|
37
|
+
date: string;
|
|
38
|
+
tags: ("feature" | "chore" | "fix")[];
|
|
39
|
+
commit_url: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
36
42
|
};
|
|
43
|
+
onReady?: () => void;
|
|
37
44
|
}
|
|
38
45
|
interface ThemedColorsModule {
|
|
39
46
|
base: {
|
|
@@ -103,6 +110,5 @@ export declare function getPlayer(value: string | number): Character | null;
|
|
|
103
110
|
export declare function getNickname(target: Character): string;
|
|
104
111
|
export declare function getThemedColorsModule(): ThemedColorsModule | null;
|
|
105
112
|
export declare function injectStyles(stylesToInject: string): void;
|
|
106
|
-
export declare function waitForStart(callback: () => void): void;
|
|
107
113
|
export declare function normalizeObject<T>(obj: T[]): T[];
|
|
108
114
|
export declare function normalizeObject<T extends object>(obj: T): T;
|
|
@@ -3,13 +3,14 @@ import { Shard, ShardContext } from "./shard";
|
|
|
3
3
|
export interface ButtonShardContext extends ShardContext<"icon" | "text"> {
|
|
4
4
|
text?: string;
|
|
5
5
|
fontSize?: number | "auto";
|
|
6
|
-
|
|
6
|
+
variant?: "outlined" | "filled";
|
|
7
7
|
icon?: string | SVGElement;
|
|
8
8
|
iconAbsolutePosition?: boolean;
|
|
9
9
|
tooltip?: {
|
|
10
10
|
text: string;
|
|
11
11
|
position: "left" | "right";
|
|
12
12
|
};
|
|
13
|
+
href?: string;
|
|
13
14
|
onClick?: () => void;
|
|
14
15
|
isDisabled?: () => boolean;
|
|
15
16
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { DynamicClassStyles } from "../ui";
|
|
1
2
|
import { Shard, ShardContext } from "./shard";
|
|
2
|
-
export interface ContainerShardContext extends ShardContext {
|
|
3
|
-
scroll?: "x" | "y" | "all" | "auto";
|
|
3
|
+
export interface ContainerShardContext extends ShardContext<"content" | "scrollbar"> {
|
|
4
|
+
scroll?: "x" | "y" | "all" | "none" | "auto";
|
|
4
5
|
}
|
|
5
6
|
export declare class ContainerShard extends Shard<ContainerShardContext> {
|
|
7
|
+
protected get dynamicClassContainer(): DynamicClassStyles;
|
|
8
|
+
protected get mountReturnValue(): HTMLElement | SVGElement | null;
|
|
6
9
|
generateBody(): Record<keyof NonNullable<ContainerShardContext["modules"]>, HTMLElement | SVGElement>;
|
|
7
10
|
}
|
|
@@ -13,6 +13,7 @@ export interface ShardContext<T extends string = never> {
|
|
|
13
13
|
export declare abstract class Shard<Context extends ShardContext = ShardContext> {
|
|
14
14
|
protected context: Context;
|
|
15
15
|
protected body: Record<keyof NonNullable<Context["modules"]>, HTMLElement | SVGElement> | null;
|
|
16
|
+
protected get mountReturnValue(): HTMLElement | SVGElement;
|
|
16
17
|
constructor(context: Context);
|
|
17
18
|
mount(parentElement?: HTMLElement): HTMLElement | SVGElement;
|
|
18
19
|
protected abstract generateBody(): Record<keyof NonNullable<Context["modules"]>, HTMLElement | SVGElement>;
|
package/dist/types/ui.d.ts
CHANGED
|
@@ -22,7 +22,14 @@ export interface DynamicClassStyles {
|
|
|
22
22
|
[key: string]: Partial<CSSStyleDeclaration> | undefined;
|
|
23
23
|
}
|
|
24
24
|
export declare function hexToRgb(hex: string): string;
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function recolorSVG(svgElement: SVGElement, { fill, stroke }: {
|
|
26
|
+
fill: string;
|
|
27
|
+
stroke: string;
|
|
28
|
+
}): SVGElement;
|
|
29
|
+
export declare function dataUrlSvgWithColor(dataUrl: string, newColor: {
|
|
30
|
+
fill?: string;
|
|
31
|
+
stroke?: string;
|
|
32
|
+
}): string;
|
|
26
33
|
export declare function dataUrlSvgReplaceVars(dataUrl: string, vars: Record<string, string>): string;
|
|
27
34
|
export declare function cssVar(name: string, fallback: string): string;
|
|
28
35
|
export declare function getRelativeHeight(height: number): number;
|
|
@@ -35,6 +42,7 @@ export declare function setFontSize(element: HTMLElement, targetFontSize: number
|
|
|
35
42
|
export declare function setFontFamily(element: HTMLElement, fontFamily?: string): void;
|
|
36
43
|
export declare function setPadding(element: HTMLElement, targetPadding: number): void;
|
|
37
44
|
export declare function autosetFontSize(element: HTMLElement): void;
|
|
45
|
+
export declare function setSizeUnitVariable(): void;
|
|
38
46
|
export declare function addDynamicClass(targetElement: HTMLElement | SVGElement, styles: DynamicClassStyles): void;
|
|
39
47
|
export declare function setPreviousSubscreen(): void;
|
|
40
48
|
export declare function setSubscreen(subscreen: BaseSubscreen | null): void;
|
|
@@ -51,6 +59,7 @@ export declare abstract class BaseSubscreen {
|
|
|
51
59
|
click(): void;
|
|
52
60
|
exit(): void;
|
|
53
61
|
update(): void;
|
|
62
|
+
resize(): void;
|
|
54
63
|
setPreviousSubscreen(): void;
|
|
55
64
|
create(shard: Shard): HTMLElement;
|
|
56
65
|
createButton(ctx: ButtonShardContext): HTMLButtonElement;
|
package/dist/ui.js
CHANGED
|
@@ -3,6 +3,7 @@ import { StyleModule } from "./shard-modules";
|
|
|
3
3
|
import { MOD_DATA } from "./index";
|
|
4
4
|
import { ButtonShard, TextShard, InputShard, CheckboxShard, InputListShard, ImageShard, SvgShard, BackNextButtonShard, TabsShard, CardShard, SelectShard, ContainerShard } from "./shards";
|
|
5
5
|
import { logger } from "./logging";
|
|
6
|
+
import exitIcon from "./assets/icons/exit.svg";
|
|
6
7
|
function hexToRgb(hex) {
|
|
7
8
|
hex = hex.replace("#", "");
|
|
8
9
|
const r = parseInt(hex.substring(0, 2), 16);
|
|
@@ -10,8 +11,30 @@ function hexToRgb(hex) {
|
|
|
10
11
|
const b = parseInt(hex.substring(4, 6), 16);
|
|
11
12
|
return `rgb(${r}, ${g}, ${b})`;
|
|
12
13
|
}
|
|
14
|
+
function recolorSVG(svgElement, { fill, stroke }) {
|
|
15
|
+
const elements = svgElement.querySelectorAll("*");
|
|
16
|
+
elements.forEach((element) => {
|
|
17
|
+
if (element.getAttribute("fill") !== "none") {
|
|
18
|
+
element.setAttribute("fill", fill);
|
|
19
|
+
}
|
|
20
|
+
if (element.getAttribute("stroke") !== "none") {
|
|
21
|
+
element.setAttribute("stroke", stroke);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (svgElement.getAttribute("fill") !== "none") {
|
|
25
|
+
svgElement.setAttribute("fill", fill);
|
|
26
|
+
}
|
|
27
|
+
if (svgElement.getAttribute("stroke") !== "none") {
|
|
28
|
+
svgElement.setAttribute("stroke", stroke);
|
|
29
|
+
}
|
|
30
|
+
return svgElement;
|
|
31
|
+
}
|
|
13
32
|
function dataUrlSvgWithColor(dataUrl, newColor) {
|
|
14
|
-
|
|
33
|
+
if (newColor.fill?.startsWith("#")) newColor.fill = hexToRgb(newColor.fill);
|
|
34
|
+
if (newColor.stroke?.startsWith("#")) newColor.stroke = hexToRgb(newColor.stroke);
|
|
35
|
+
if (newColor.fill) dataUrl = dataUrl.replace(/fill="[^"]*"/g, `fill="${newColor.fill}"`);
|
|
36
|
+
if (newColor.stroke) dataUrl = dataUrl.replace(/stroke="[^"]*"/g, `stroke="${newColor.stroke}"`);
|
|
37
|
+
return dataUrl;
|
|
15
38
|
}
|
|
16
39
|
function dataUrlSvgReplaceVars(dataUrl, vars) {
|
|
17
40
|
for (let [name, value] of Object.entries(vars)) {
|
|
@@ -84,6 +107,12 @@ function autosetFontSize(element) {
|
|
|
84
107
|
fontSize: Font + "px"
|
|
85
108
|
});
|
|
86
109
|
}
|
|
110
|
+
function setSizeUnitVariable() {
|
|
111
|
+
const canvasWidth = MainCanvas.canvas.clientWidth;
|
|
112
|
+
const canvasHeight = MainCanvas.canvas.clientHeight;
|
|
113
|
+
const scaleFactor = Math.min(canvasWidth, canvasHeight) / 100;
|
|
114
|
+
document.documentElement.style.setProperty("--size-unit", scaleFactor.toString());
|
|
115
|
+
}
|
|
87
116
|
const createdDynamicClasses = [];
|
|
88
117
|
function generateDynamicClassCacheKey(styles) {
|
|
89
118
|
const sortedStringify = (obj) => {
|
|
@@ -156,7 +185,7 @@ function setSubscreen(subscreen) {
|
|
|
156
185
|
try {
|
|
157
186
|
previousSubscreen.unload();
|
|
158
187
|
} catch (e) {
|
|
159
|
-
logger.error("Failed to unload subscreen", previousSubscreen);
|
|
188
|
+
logger.error("Failed to unload subscreen", previousSubscreen, e);
|
|
160
189
|
}
|
|
161
190
|
window.dispatchEvent(new SubscreenUnloadedEvent({ subscreen: previousSubscreen }));
|
|
162
191
|
}
|
|
@@ -164,7 +193,7 @@ function setSubscreen(subscreen) {
|
|
|
164
193
|
try {
|
|
165
194
|
subscreen.load();
|
|
166
195
|
} catch (e) {
|
|
167
|
-
logger.error("Failed to load subscreen", subscreen);
|
|
196
|
+
logger.error("Failed to load subscreen", subscreen, e);
|
|
168
197
|
}
|
|
169
198
|
window.dispatchEvent(new SubscreenLoadedEvent({ subscreen }));
|
|
170
199
|
}
|
|
@@ -186,12 +215,13 @@ class BaseSubscreen {
|
|
|
186
215
|
run() {
|
|
187
216
|
}
|
|
188
217
|
load() {
|
|
218
|
+
setSizeUnitVariable();
|
|
189
219
|
this.createButton({
|
|
190
220
|
x: 1815,
|
|
191
221
|
y: 75,
|
|
192
222
|
width: 90,
|
|
193
223
|
height: 90,
|
|
194
|
-
icon: "
|
|
224
|
+
icon: dataUrlSvgWithColor(exitIcon, { fill: cssVar("--tmd-text", "black") }),
|
|
195
225
|
tooltip: {
|
|
196
226
|
position: "left",
|
|
197
227
|
text: "Back"
|
|
@@ -212,9 +242,6 @@ class BaseSubscreen {
|
|
|
212
242
|
fontSize: 8
|
|
213
243
|
}).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
|
|
214
244
|
}
|
|
215
|
-
if (subscreenHooks[this.constructor.name]) {
|
|
216
|
-
subscreenHooks[this.name].forEach((hook) => hook(this));
|
|
217
|
-
}
|
|
218
245
|
}
|
|
219
246
|
unload() {
|
|
220
247
|
}
|
|
@@ -225,6 +252,9 @@ class BaseSubscreen {
|
|
|
225
252
|
}
|
|
226
253
|
update() {
|
|
227
254
|
}
|
|
255
|
+
resize() {
|
|
256
|
+
setSizeUnitVariable();
|
|
257
|
+
}
|
|
228
258
|
setPreviousSubscreen() {
|
|
229
259
|
setPreviousSubscreen();
|
|
230
260
|
}
|
|
@@ -341,11 +371,13 @@ export {
|
|
|
341
371
|
getRelativeY,
|
|
342
372
|
hexToRgb,
|
|
343
373
|
hookSubscreen,
|
|
374
|
+
recolorSVG,
|
|
344
375
|
setFontFamily,
|
|
345
376
|
setFontSize,
|
|
346
377
|
setPadding,
|
|
347
378
|
setPosition,
|
|
348
379
|
setPreviousSubscreen,
|
|
349
380
|
setSize,
|
|
381
|
+
setSizeUnitVariable,
|
|
350
382
|
setSubscreen
|
|
351
383
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zois-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
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"
|
|
7
7
|
},
|
|
8
8
|
"author": "Zoi",
|
|
9
9
|
"license": "MIT",
|
|
@@ -69,7 +69,9 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
+
"@octokit/rest": "^22.0.1",
|
|
72
73
|
"bondage-club-mod-sdk": "^1.2.0",
|
|
74
|
+
"chalk": "^5.6.2",
|
|
73
75
|
"class-transformer": "^0.5.1",
|
|
74
76
|
"class-validator": "^0.14.4",
|
|
75
77
|
"lucide": "^1.24.0",
|
|
@@ -78,8 +80,9 @@
|
|
|
78
80
|
"devDependencies": {
|
|
79
81
|
"bc-stubs": "130.0.0-Beta.1",
|
|
80
82
|
"esbuild": "^0.28.1",
|
|
83
|
+
"esbuild-plugin-copy": "^2.1.1",
|
|
84
|
+
"glob": "^13.0.6",
|
|
81
85
|
"nodemon": "^3.1.14",
|
|
82
|
-
"simple-git": "^3.36.0",
|
|
83
86
|
"typescript": "^5.9.3"
|
|
84
87
|
},
|
|
85
88
|
"scripts": {
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { Octokit } from "@octokit/rest";
|
|
5
|
+
|
|
6
|
+
const octokit = new Octokit();
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const command = args[0];
|
|
9
|
+
|
|
10
|
+
function getArg(name) {
|
|
11
|
+
const arg = args.find((a) => a.startsWith("--" + name));
|
|
12
|
+
if (arg) return arg.slice(name.length + 3);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
switch (command) {
|
|
17
|
+
case "generate-changelog": {
|
|
18
|
+
generateChangelog().catch((err) => {
|
|
19
|
+
console.log(chalk.red("Script failed:"), err.message);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
});
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
default: {
|
|
25
|
+
console.log(chalk.red("Unknown command"), `"${chalk.cyan(command)}"`);
|
|
26
|
+
console.log("Available commands:")
|
|
27
|
+
console.log(`• ${chalk.cyan("generate-changelog")} — Generate changelog bundle`)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function getCommitsSince(owner, repo, sinceSha, perPage = 50) {
|
|
32
|
+
const commits = [];
|
|
33
|
+
let page = 1;
|
|
34
|
+
let hasMore = true;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
while (hasMore) {
|
|
38
|
+
const { data } = await octokit.rest.repos.listCommits({
|
|
39
|
+
owner,
|
|
40
|
+
repo,
|
|
41
|
+
sha: "HEAD",
|
|
42
|
+
per_page: perPage,
|
|
43
|
+
page: page,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (data.length === 0) break;
|
|
47
|
+
|
|
48
|
+
const startIndex = data.findIndex((commit) => commit.sha === sinceSha);
|
|
49
|
+
|
|
50
|
+
if (startIndex !== -1) {
|
|
51
|
+
commits.push(...data.slice(0, startIndex + 1));
|
|
52
|
+
break;
|
|
53
|
+
} else {
|
|
54
|
+
commits.push(...data);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
page++;
|
|
58
|
+
hasMore = data.length === perPage;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return commits.map((commit) => ({
|
|
62
|
+
sha: commit.sha,
|
|
63
|
+
message: commit.commit.message,
|
|
64
|
+
date: commit.commit.author.date,
|
|
65
|
+
author: {
|
|
66
|
+
name: commit.author?.login || commit.commit.author.name,
|
|
67
|
+
avatar_url: commit.author?.avatar_url,
|
|
68
|
+
html_url: commit.author?.html_url,
|
|
69
|
+
},
|
|
70
|
+
committer: {
|
|
71
|
+
name: commit.committer?.login || commit.commit.committer.name,
|
|
72
|
+
avatar_url: commit.committer?.avatar_url,
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.log(chalk.red("Error getting commits:"), error.message);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function generateChangelog() {
|
|
83
|
+
const owner = getArg("owner");
|
|
84
|
+
if (!owner) {
|
|
85
|
+
console.log(chalk.red("--owner argument not specified"));
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
const repo = getArg("repo");
|
|
89
|
+
if (!repo) {
|
|
90
|
+
console.log(chalk.red("--repo argument not specified"));
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
const fromCommit = getArg("from");
|
|
94
|
+
if (!fromCommit) {
|
|
95
|
+
console.log(chalk.red("--from argument not specified"));
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
console.log(`Generating changelog from commit ${chalk.cyan(fromCommit)}...`);
|
|
99
|
+
|
|
100
|
+
const commits = await getCommitsSince(owner, repo, fromCommit);
|
|
101
|
+
|
|
102
|
+
const resultToWrite = {
|
|
103
|
+
generated_at: (new Date()).toISOString(),
|
|
104
|
+
changes: commits.map((c) => ({
|
|
105
|
+
message: c.message,
|
|
106
|
+
sha: c.sha,
|
|
107
|
+
author: {
|
|
108
|
+
name: c.author.name,
|
|
109
|
+
avatar_url: c.author.avatar_url ?? "https://avatars.githubusercontent.com/" + c.author.name,
|
|
110
|
+
},
|
|
111
|
+
date: c.date,
|
|
112
|
+
tags: [],
|
|
113
|
+
commit_url: `https://github.com/${owner}/${repo}/commit/${c.sha}`
|
|
114
|
+
}))
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const outputPath = path.join(process.cwd(), "changelog.json");
|
|
118
|
+
|
|
119
|
+
await fs.writeFile(
|
|
120
|
+
outputPath,
|
|
121
|
+
JSON.stringify(resultToWrite, null, 2),
|
|
122
|
+
"utf-8"
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
console.log(`Generated changelog.json. (${commits.length} commits)`);
|
|
126
|
+
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import simpleGit from "simple-git";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
const git = simpleGit({ baseDir: process.cwd() });
|
|
6
|
-
|
|
7
|
-
async function getUnpushedCommits() {
|
|
8
|
-
try {
|
|
9
|
-
const branchSummary = await git.branch();
|
|
10
|
-
const currentBranch = branchSummary.current;
|
|
11
|
-
|
|
12
|
-
const remoteBranch = `origin/${currentBranch}`;
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
const log = await git.log([`${remoteBranch}..HEAD`]);
|
|
16
|
-
return log.all;
|
|
17
|
-
} catch (err) {
|
|
18
|
-
console.warn("No remote tracking branch found, returning all commits.");
|
|
19
|
-
const log = await git.log();
|
|
20
|
-
return log.all;
|
|
21
|
-
}
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error("Error getting unpushed commits:", error.message);
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function getCommitsFromHash(hash) {
|
|
29
|
-
try {
|
|
30
|
-
const log = await git.log({
|
|
31
|
-
from: hash,
|
|
32
|
-
to: "HEAD"
|
|
33
|
-
});
|
|
34
|
-
return log.all;
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error(`Error getting commits from hash ${hash}:`, error.message);
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function generateChangelog() {
|
|
42
|
-
const args = process.argv.slice(2);
|
|
43
|
-
let commits = [];
|
|
44
|
-
|
|
45
|
-
if (args.length > 0 && args[0].startsWith("--from=")) {
|
|
46
|
-
const hash = args[0].split("=")[1];
|
|
47
|
-
if (hash) {
|
|
48
|
-
console.log(`Generating changelog from commit ${hash}...`);
|
|
49
|
-
commits = await getCommitsFromHash(hash);
|
|
50
|
-
} else {
|
|
51
|
-
console.error("Invalid --from= hash provided.");
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
console.log("Generating changelog for unpushed commits...");
|
|
56
|
-
commits = await getUnpushedCommits();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const changelog = commits.map((commit) => ({
|
|
60
|
-
hash: commit.hash,
|
|
61
|
-
author: commit.author_name || commit.author || "Unknown",
|
|
62
|
-
message: commit.message || commit.body || "",
|
|
63
|
-
date: commit.date
|
|
64
|
-
}));
|
|
65
|
-
|
|
66
|
-
const outputPath = path.join(process.cwd(), "changelog.json");
|
|
67
|
-
|
|
68
|
-
await fs.writeFile(
|
|
69
|
-
outputPath,
|
|
70
|
-
JSON.stringify(changelog, null, 2),
|
|
71
|
-
"utf-8"
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
console.log(`Generated changelog.json. (${changelog.length} commits)`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
generateChangelog().catch((err) => {
|
|
78
|
-
console.error("❌ Script failed:", err.message);
|
|
79
|
-
process.exit(1);
|
|
80
|
-
});
|