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.
- package/README.md +23 -2
- package/dist/assets/icons/exit.svg +17 -0
- package/dist/changelogs.js +153 -0
- package/dist/core-subscreen/coreSubscreen.js +81 -0
- package/dist/core-subscreen/developmentSubscreen.js +22 -0
- package/dist/core-subscreen/generalSubscreen.js +23 -0
- package/dist/core-subscreen/mainSubscreen.js +58 -0
- package/dist/core-subscreen/shards/coreButtonShard.js +30 -0
- package/dist/core-subscreen/shards/coreCheckboxShard.js +33 -0
- package/dist/core-subscreen/shards/coreInputListShard.js +38 -0
- package/dist/core-subscreen/shards/coreSelectShard.js +17 -0
- package/dist/core-subscreen/shards/coreTextShard.js +9 -0
- package/dist/core-subscreen/shards/index.js +5 -0
- package/dist/core-subscreen/toastsSubscreen.js +112 -0
- package/dist/core.js +178 -0
- package/dist/dialogs.js +110 -0
- package/dist/index.js +201 -1
- package/dist/localization.js +71 -0
- package/dist/logging.js +31 -0
- package/dist/messaging.js +234 -1
- package/dist/modSdk.js +63 -0
- package/dist/shard-modules/attributesModule.js +16 -0
- package/dist/shard-modules/centerModule.js +12 -0
- package/dist/shard-modules/clickModule.js +14 -0
- package/dist/shard-modules/counterUpModule.js +37 -0
- package/dist/shard-modules/dynamicClassModule.js +15 -0
- package/dist/shard-modules/index.js +9 -0
- package/dist/shard-modules/multiClickModule.js +41 -0
- package/dist/shard-modules/shardModule.js +12 -0
- package/dist/shard-modules/styleModule.js +20 -0
- package/dist/shard-modules/typeModule.js +37 -0
- package/dist/shards/backNextButtonShard.js +99 -0
- package/dist/shards/buttonShard.js +150 -0
- package/dist/shards/cardShard.js +35 -0
- package/dist/shards/checkboxShard.js +139 -0
- package/dist/shards/containerShard.js +16 -0
- package/dist/shards/imageShard.js +98 -0
- package/dist/shards/index.js +13 -0
- package/dist/shards/inputListShard.js +162 -0
- package/dist/shards/inputShard.js +33 -0
- package/dist/shards/selectShard.js +126 -0
- package/dist/shards/shard.js +79 -0
- package/dist/shards/svgShard.js +29 -0
- package/dist/shards/tabsShard.js +59 -0
- package/dist/shards/textShard.js +27 -0
- package/dist/styles.css +209 -1
- package/dist/toasts.js +189 -0
- package/dist/types/changelogs.d.ts +1 -0
- package/dist/types/core-subscreen/coreSubscreen.d.ts +15 -0
- package/dist/types/core-subscreen/developmentSubscreen.d.ts +5 -0
- package/dist/types/core-subscreen/generalSubscreen.d.ts +5 -0
- package/dist/types/core-subscreen/mainSubscreen.d.ts +6 -0
- package/dist/types/core-subscreen/shards/coreButtonShard.d.ts +5 -0
- package/dist/types/core-subscreen/shards/coreCheckboxShard.d.ts +6 -0
- package/dist/types/core-subscreen/shards/coreInputListShard.d.ts +6 -0
- package/dist/types/core-subscreen/shards/coreSelectShard.d.ts +5 -0
- package/dist/types/core-subscreen/shards/coreTextShard.d.ts +4 -0
- package/dist/types/core-subscreen/shards/index.d.ts +5 -0
- package/dist/types/core-subscreen/toastsSubscreen.d.ts +5 -0
- package/dist/types/core.d.ts +18 -0
- package/dist/types/dialogs.d.ts +29 -0
- package/dist/types/globals.d.ts +6 -0
- package/dist/types/index.d.ts +62 -6
- package/dist/types/localization.d.ts +4 -0
- package/dist/types/logging.d.ts +16 -0
- package/dist/types/messaging.d.ts +5 -3
- package/dist/types/{modsApi.d.ts → modSdk.d.ts} +2 -2
- package/dist/types/shard-modules/attributesModule.d.ts +7 -0
- package/dist/types/shard-modules/centerModule.d.ts +5 -0
- package/dist/types/shard-modules/clickModule.d.ts +7 -0
- package/dist/types/shard-modules/counterUpModule.d.ts +13 -0
- package/dist/types/shard-modules/dynamicClassModule.d.ts +8 -0
- package/dist/types/{ui-modules → shard-modules}/index.d.ts +2 -0
- package/dist/types/shard-modules/multiClickModule.d.ts +12 -0
- package/dist/types/shard-modules/shardModule.d.ts +7 -0
- package/dist/types/shard-modules/styleModule.d.ts +8 -0
- package/dist/types/shard-modules/typeModule.d.ts +11 -0
- package/dist/types/shards/backNextButtonShard.d.ts +14 -0
- package/dist/types/shards/buttonShard.d.ts +21 -0
- package/dist/types/shards/cardShard.d.ts +10 -0
- package/dist/types/shards/checkboxShard.d.ts +19 -0
- package/dist/types/shards/containerShard.d.ts +7 -0
- package/dist/types/shards/imageShard.d.ts +11 -0
- package/dist/types/shards/index.d.ts +13 -0
- package/dist/types/shards/inputListShard.d.ts +16 -0
- package/dist/types/shards/inputShard.d.ts +14 -0
- package/dist/types/shards/selectShard.d.ts +17 -0
- package/dist/types/shards/shard.d.ts +21 -0
- package/dist/types/shards/svgShard.d.ts +12 -0
- package/dist/types/shards/tabsShard.d.ts +17 -0
- package/dist/types/shards/textShard.d.ts +13 -0
- package/dist/types/toasts.d.ts +21 -0
- package/dist/types/ui.d.ts +35 -148
- package/dist/ui.js +375 -11
- package/dist/validation.js +31 -1
- package/dist/wardrobe.js +167 -1
- package/package.json +47 -26
- package/scripts/zois-core.mjs +126 -0
- package/dist/modsApi.js +0 -1
- package/dist/modules.js +0 -1
- package/dist/popups.js +0 -1
- package/dist/types/modules.d.ts +0 -18
- package/dist/types/popups.d.ts +0 -63
- package/dist/types/ui-modules/attributesModule.d.ts +0 -6
- package/dist/types/ui-modules/centerModule.d.ts +0 -4
- package/dist/types/ui-modules/clickModule.d.ts +0 -6
- package/dist/types/ui-modules/counterUpModule.d.ts +0 -12
- package/dist/types/ui-modules/dynamicClassModule.d.ts +0 -7
- package/dist/types/ui-modules/styleModule.d.ts +0 -7
- package/dist/types/ui-modules/typeModule.d.ts +0 -10
- package/dist/ui-modules/attributesModule.js +0 -1
- package/dist/ui-modules/centerModule.js +0 -1
- package/dist/ui-modules/clickModule.js +0 -1
- package/dist/ui-modules/counterUpModule.js +0 -1
- package/dist/ui-modules/dynamicClassModule.js +0 -1
- package/dist/ui-modules/index.js +0 -1
- package/dist/ui-modules/styleModule.js +0 -1
- package/dist/ui-modules/typeModule.js +0 -1
package/dist/ui.js
CHANGED
|
@@ -1,11 +1,375 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { getThemedColorsModule, SubscreenLoadedEvent, SubscreenUnloadedEvent } from "./index";
|
|
2
|
+
import { StyleModule } from "./shard-modules";
|
|
3
|
+
import { MOD_DATA } from "./index";
|
|
4
|
+
import { ButtonShard, TextShard, InputShard, CheckboxShard, InputListShard, ImageShard, SvgShard, BackNextButtonShard, TabsShard, CardShard, SelectShard, ContainerShard } from "./shards";
|
|
5
|
+
import { logger } from "./logging";
|
|
6
|
+
import exitIcon from "./assets/icons/exit.svg";
|
|
7
|
+
function hexToRgb(hex) {
|
|
8
|
+
hex = hex.replace("#", "");
|
|
9
|
+
const r = parseInt(hex.substring(0, 2), 16);
|
|
10
|
+
const g = parseInt(hex.substring(2, 4), 16);
|
|
11
|
+
const b = parseInt(hex.substring(4, 6), 16);
|
|
12
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
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
|
+
}
|
|
32
|
+
function dataUrlSvgWithColor(dataUrl, newColor) {
|
|
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;
|
|
38
|
+
}
|
|
39
|
+
function dataUrlSvgReplaceVars(dataUrl, vars) {
|
|
40
|
+
for (let [name, value] of Object.entries(vars)) {
|
|
41
|
+
if (value.startsWith("#")) {
|
|
42
|
+
value = hexToRgb(value);
|
|
43
|
+
}
|
|
44
|
+
dataUrl = dataUrl.replaceAll(`$${name}`, value);
|
|
45
|
+
}
|
|
46
|
+
return dataUrl;
|
|
47
|
+
}
|
|
48
|
+
function cssVar(name, fallback) {
|
|
49
|
+
const value = getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
50
|
+
return value || fallback;
|
|
51
|
+
}
|
|
52
|
+
function getRelativeHeight(height) {
|
|
53
|
+
return height * (MainCanvas.canvas.clientHeight / 1e3);
|
|
54
|
+
}
|
|
55
|
+
function getRelativeWidth(width) {
|
|
56
|
+
return width * (MainCanvas.canvas.clientWidth / 2e3);
|
|
57
|
+
}
|
|
58
|
+
function getRelativeY(yPos, anchorPosition = "top") {
|
|
59
|
+
const scaleY = MainCanvas.canvas.clientHeight / 1e3;
|
|
60
|
+
return anchorPosition === "top" ? MainCanvas.canvas.offsetTop + yPos * scaleY : window.innerHeight - (MainCanvas.canvas.offsetTop + MainCanvas.canvas.clientHeight) + yPos * scaleY;
|
|
61
|
+
}
|
|
62
|
+
function getRelativeX(xPos, anchorPosition = "left") {
|
|
63
|
+
const scaleX = MainCanvas.canvas.clientWidth / 2e3;
|
|
64
|
+
return anchorPosition === "left" ? MainCanvas.canvas.offsetLeft + xPos * scaleX : window.innerWidth - (MainCanvas.canvas.offsetLeft + MainCanvas.canvas.clientWidth) + xPos * scaleX;
|
|
65
|
+
}
|
|
66
|
+
function setPosition(element, xPos, yPos, anchor = "top-left") {
|
|
67
|
+
const yAnchor = anchor === "top-left" || anchor === "top-right" ? "top" : "bottom";
|
|
68
|
+
const xAnchor = anchor === "top-left" || anchor === "bottom-left" ? "left" : "right";
|
|
69
|
+
const y = getRelativeY(yPos, yAnchor);
|
|
70
|
+
const x = getRelativeX(xPos, xAnchor);
|
|
71
|
+
Object.assign(element.style, {
|
|
72
|
+
position: "fixed",
|
|
73
|
+
[xAnchor]: x + "px",
|
|
74
|
+
[yAnchor]: y + "px"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function setSize(element, width, height) {
|
|
78
|
+
Object.assign(element.style, {
|
|
79
|
+
width: getRelativeWidth(width) + "px",
|
|
80
|
+
height: getRelativeHeight(height) + "px"
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function setFontSize(element, targetFontSize) {
|
|
84
|
+
const canvasWidth = MainCanvas.canvas.clientWidth;
|
|
85
|
+
const canvasHeight = MainCanvas.canvas.clientHeight;
|
|
86
|
+
const scaleFactor = Math.min(canvasWidth, canvasHeight) / 100;
|
|
87
|
+
const fontSize = targetFontSize * scaleFactor;
|
|
88
|
+
Object.assign(element.style, {
|
|
89
|
+
fontSize: fontSize + "px"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function setFontFamily(element, fontFamily) {
|
|
93
|
+
element.style.fontFamily = fontFamily ?? "sans-serif";
|
|
94
|
+
}
|
|
95
|
+
function setPadding(element, targetPadding) {
|
|
96
|
+
const canvasWidth = MainCanvas.canvas.clientWidth;
|
|
97
|
+
const canvasHeight = MainCanvas.canvas.clientHeight;
|
|
98
|
+
const scaleFactor = Math.min(canvasWidth, canvasHeight) / 100;
|
|
99
|
+
const paddingValue = targetPadding * scaleFactor;
|
|
100
|
+
Object.assign(element.style, {
|
|
101
|
+
padding: paddingValue + "px"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function autosetFontSize(element) {
|
|
105
|
+
const Font = MainCanvas.canvas.clientWidth <= MainCanvas.canvas.clientHeight * 2 ? MainCanvas.canvas.clientWidth / 50 : MainCanvas.canvas.clientHeight / 25;
|
|
106
|
+
Object.assign(element.style, {
|
|
107
|
+
fontSize: Font + "px"
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const createdDynamicClasses = [];
|
|
111
|
+
function generateDynamicClassCacheKey(styles) {
|
|
112
|
+
const sortedStringify = (obj) => {
|
|
113
|
+
if (!obj) return "null";
|
|
114
|
+
return JSON.stringify(
|
|
115
|
+
Object.keys(obj).sort().reduce((acc, key) => {
|
|
116
|
+
acc[key] = obj[key];
|
|
117
|
+
return acc;
|
|
118
|
+
}, {})
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
let cacheKey = "";
|
|
122
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
123
|
+
if (value === void 0) continue;
|
|
124
|
+
cacheKey += `${key}:=${sortedStringify(value)}|`;
|
|
125
|
+
}
|
|
126
|
+
return cacheKey;
|
|
127
|
+
}
|
|
128
|
+
function addDynamicClass(targetElement, styles) {
|
|
129
|
+
const cacheKey = generateDynamicClassCacheKey(styles);
|
|
130
|
+
const _class = createdDynamicClasses.find((g) => g.key === cacheKey);
|
|
131
|
+
if (_class) return targetElement.classList.add(_class.className);
|
|
132
|
+
let className;
|
|
133
|
+
do {
|
|
134
|
+
className = "dynamic-" + Math.random().toString(36).substring(2, 10);
|
|
135
|
+
} while (createdDynamicClasses.find((g) => g.className === className));
|
|
136
|
+
createdDynamicClasses.push({
|
|
137
|
+
key: cacheKey,
|
|
138
|
+
className
|
|
139
|
+
});
|
|
140
|
+
const buildCssBlock = (selector, styleRules) => {
|
|
141
|
+
let css = `${selector} {`;
|
|
142
|
+
for (const [property, value] of Object.entries(styleRules)) {
|
|
143
|
+
css += `${property.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase()}: ${value};`;
|
|
144
|
+
}
|
|
145
|
+
css += "}";
|
|
146
|
+
return css;
|
|
147
|
+
};
|
|
148
|
+
let cssRules = "";
|
|
149
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
150
|
+
if (value === void 0) continue;
|
|
151
|
+
if (key === "base") {
|
|
152
|
+
cssRules += buildCssBlock(`.${className}`, value);
|
|
153
|
+
} else if (["hover", "active", "focus", "disabled", "before", "after"].includes(key)) {
|
|
154
|
+
cssRules += buildCssBlock(`.${className}:${key}`, value);
|
|
155
|
+
} else {
|
|
156
|
+
cssRules += buildCssBlock(`.${className}${key}`, value);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
let styleElement = document.getElementById(`${MOD_DATA.key ?? ""}-dynamic-classes`);
|
|
160
|
+
if (styleElement) {
|
|
161
|
+
styleElement.textContent += cssRules;
|
|
162
|
+
} else {
|
|
163
|
+
styleElement = document.createElement("style");
|
|
164
|
+
styleElement.id = `${MOD_DATA.key ?? ""}-dynamic-classes`;
|
|
165
|
+
styleElement.textContent = cssRules;
|
|
166
|
+
document.head.appendChild(styleElement);
|
|
167
|
+
}
|
|
168
|
+
targetElement.classList.add(className);
|
|
169
|
+
}
|
|
170
|
+
function setPreviousSubscreen() {
|
|
171
|
+
setSubscreen(previousSubscreen);
|
|
172
|
+
}
|
|
173
|
+
let previousSubscreen = null;
|
|
174
|
+
let currentSubscreen = null;
|
|
175
|
+
function setSubscreen(subscreen) {
|
|
176
|
+
previousSubscreen = currentSubscreen;
|
|
177
|
+
currentSubscreen = subscreen;
|
|
178
|
+
if (previousSubscreen) {
|
|
179
|
+
try {
|
|
180
|
+
previousSubscreen.unload();
|
|
181
|
+
} catch (e) {
|
|
182
|
+
logger.error("Failed to unload subscreen", previousSubscreen, e);
|
|
183
|
+
}
|
|
184
|
+
window.dispatchEvent(new SubscreenUnloadedEvent({ subscreen: previousSubscreen }));
|
|
185
|
+
}
|
|
186
|
+
if (subscreen) {
|
|
187
|
+
try {
|
|
188
|
+
subscreen.load();
|
|
189
|
+
} catch (e) {
|
|
190
|
+
logger.error("Failed to load subscreen", subscreen, e);
|
|
191
|
+
}
|
|
192
|
+
window.dispatchEvent(new SubscreenLoadedEvent({ subscreen }));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function getCurrentSubscreen() {
|
|
196
|
+
return currentSubscreen;
|
|
197
|
+
}
|
|
198
|
+
function getPreviousSubscreen() {
|
|
199
|
+
return previousSubscreen;
|
|
200
|
+
}
|
|
201
|
+
class BaseSubscreen {
|
|
202
|
+
setSubscreen = setSubscreen;
|
|
203
|
+
get currentSubscreen() {
|
|
204
|
+
return getCurrentSubscreen();
|
|
205
|
+
}
|
|
206
|
+
get previousSubscreen() {
|
|
207
|
+
return getPreviousSubscreen();
|
|
208
|
+
}
|
|
209
|
+
run() {
|
|
210
|
+
}
|
|
211
|
+
load() {
|
|
212
|
+
this.createButton({
|
|
213
|
+
x: 1815,
|
|
214
|
+
y: 75,
|
|
215
|
+
width: 90,
|
|
216
|
+
height: 90,
|
|
217
|
+
icon: dataUrlSvgWithColor(exitIcon, { fill: cssVar("--tmd-text", "black") }),
|
|
218
|
+
tooltip: {
|
|
219
|
+
position: "left",
|
|
220
|
+
text: "Back"
|
|
221
|
+
},
|
|
222
|
+
modules: {
|
|
223
|
+
base: [
|
|
224
|
+
new StyleModule({
|
|
225
|
+
zIndex: "10"
|
|
226
|
+
})
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
}).addEventListener("click", () => this.exit());
|
|
230
|
+
if (this.name) {
|
|
231
|
+
this.createText({
|
|
232
|
+
text: this.name,
|
|
233
|
+
x: 100,
|
|
234
|
+
y: 60,
|
|
235
|
+
fontSize: 8
|
|
236
|
+
}).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
|
|
237
|
+
}
|
|
238
|
+
if (subscreenHooks[this.constructor.name]) {
|
|
239
|
+
subscreenHooks[this.name].forEach((hook) => hook(this));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
unload() {
|
|
243
|
+
}
|
|
244
|
+
click() {
|
|
245
|
+
}
|
|
246
|
+
exit() {
|
|
247
|
+
setPreviousSubscreen();
|
|
248
|
+
}
|
|
249
|
+
update() {
|
|
250
|
+
}
|
|
251
|
+
setPreviousSubscreen() {
|
|
252
|
+
setPreviousSubscreen();
|
|
253
|
+
}
|
|
254
|
+
create(shard) {
|
|
255
|
+
const htmlElement = shard.mount();
|
|
256
|
+
return htmlElement;
|
|
257
|
+
}
|
|
258
|
+
createButton(ctx) {
|
|
259
|
+
const shard = new ButtonShard(ctx);
|
|
260
|
+
const htmlElement = shard.mount();
|
|
261
|
+
return htmlElement;
|
|
262
|
+
}
|
|
263
|
+
createText(ctx) {
|
|
264
|
+
const shard = new TextShard(ctx);
|
|
265
|
+
const htmlElement = shard.mount();
|
|
266
|
+
return htmlElement;
|
|
267
|
+
}
|
|
268
|
+
createInput(ctx) {
|
|
269
|
+
const shard = new InputShard(ctx);
|
|
270
|
+
const htmlElement = shard.mount();
|
|
271
|
+
return htmlElement;
|
|
272
|
+
}
|
|
273
|
+
createCheckbox(ctx) {
|
|
274
|
+
const shard = new CheckboxShard(ctx);
|
|
275
|
+
const htmlElement = shard.mount();
|
|
276
|
+
return htmlElement;
|
|
277
|
+
}
|
|
278
|
+
createInputList(ctx) {
|
|
279
|
+
const shard = new InputListShard(ctx);
|
|
280
|
+
const htmlElement = shard.mount();
|
|
281
|
+
return htmlElement;
|
|
282
|
+
}
|
|
283
|
+
createImage(ctx) {
|
|
284
|
+
const shard = new ImageShard(ctx);
|
|
285
|
+
const htmlElement = shard.mount();
|
|
286
|
+
return htmlElement;
|
|
287
|
+
}
|
|
288
|
+
createSvg(ctx) {
|
|
289
|
+
const shard = new SvgShard(ctx);
|
|
290
|
+
const htmlElement = shard.mount();
|
|
291
|
+
return htmlElement;
|
|
292
|
+
}
|
|
293
|
+
createBackNextButton(ctx) {
|
|
294
|
+
const shard = new BackNextButtonShard(ctx);
|
|
295
|
+
const htmlElement = shard.mount();
|
|
296
|
+
return htmlElement;
|
|
297
|
+
}
|
|
298
|
+
createTabs(ctx) {
|
|
299
|
+
const shard = new TabsShard(ctx);
|
|
300
|
+
const htmlElement = shard.mount();
|
|
301
|
+
return htmlElement;
|
|
302
|
+
}
|
|
303
|
+
drawPolylineArrow({
|
|
304
|
+
points,
|
|
305
|
+
strokeColor = getThemedColorsModule()?.base?.text ?? "black",
|
|
306
|
+
lineWidth = 2,
|
|
307
|
+
circleRadius = 5,
|
|
308
|
+
circleColor = getThemedColorsModule()?.base?.text ?? "black"
|
|
309
|
+
}) {
|
|
310
|
+
if (points.length < 2) return;
|
|
311
|
+
const ctx = MainCanvas.canvas.getContext("2d");
|
|
312
|
+
if (!ctx) return;
|
|
313
|
+
ctx.save();
|
|
314
|
+
ctx.strokeStyle = strokeColor;
|
|
315
|
+
ctx.lineWidth = lineWidth;
|
|
316
|
+
ctx.fillStyle = circleColor;
|
|
317
|
+
ctx.beginPath();
|
|
318
|
+
ctx.moveTo(points[0].x, points[0].y);
|
|
319
|
+
for (let i = 1; i < points.length; i++) {
|
|
320
|
+
ctx.lineTo(points[i].x, points[i].y);
|
|
321
|
+
}
|
|
322
|
+
ctx.stroke();
|
|
323
|
+
ctx.beginPath();
|
|
324
|
+
ctx.arc(points[0].x, points[0].y, circleRadius, 0, Math.PI * 2);
|
|
325
|
+
ctx.fill();
|
|
326
|
+
ctx.beginPath();
|
|
327
|
+
ctx.arc(points[points.length - 1].x, points[points.length - 1].y, circleRadius, 0, Math.PI * 2);
|
|
328
|
+
ctx.fill();
|
|
329
|
+
ctx.restore();
|
|
330
|
+
}
|
|
331
|
+
createCard(ctx) {
|
|
332
|
+
const shard = new CardShard(ctx);
|
|
333
|
+
const htmlElement = shard.mount();
|
|
334
|
+
return htmlElement;
|
|
335
|
+
}
|
|
336
|
+
createSelect(ctx) {
|
|
337
|
+
const shard = new SelectShard(ctx);
|
|
338
|
+
const htmlElement = shard.mount();
|
|
339
|
+
return htmlElement;
|
|
340
|
+
}
|
|
341
|
+
createContainer(ctx) {
|
|
342
|
+
const shard = new ContainerShard(ctx);
|
|
343
|
+
const htmlElement = shard.mount();
|
|
344
|
+
return htmlElement;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const subscreenHooks = {};
|
|
348
|
+
function hookSubscreen(subscreenName, hook) {
|
|
349
|
+
if (!subscreenHooks[subscreenName]) subscreenHooks[subscreenName] = [];
|
|
350
|
+
subscreenHooks[subscreenName].push(hook);
|
|
351
|
+
}
|
|
352
|
+
export {
|
|
353
|
+
BaseSubscreen,
|
|
354
|
+
addDynamicClass,
|
|
355
|
+
autosetFontSize,
|
|
356
|
+
cssVar,
|
|
357
|
+
dataUrlSvgReplaceVars,
|
|
358
|
+
dataUrlSvgWithColor,
|
|
359
|
+
getCurrentSubscreen,
|
|
360
|
+
getPreviousSubscreen,
|
|
361
|
+
getRelativeHeight,
|
|
362
|
+
getRelativeWidth,
|
|
363
|
+
getRelativeX,
|
|
364
|
+
getRelativeY,
|
|
365
|
+
hexToRgb,
|
|
366
|
+
hookSubscreen,
|
|
367
|
+
recolorSVG,
|
|
368
|
+
setFontFamily,
|
|
369
|
+
setFontSize,
|
|
370
|
+
setPadding,
|
|
371
|
+
setPosition,
|
|
372
|
+
setPreviousSubscreen,
|
|
373
|
+
setSize,
|
|
374
|
+
setSubscreen
|
|
375
|
+
};
|
package/dist/validation.js
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
|
-
import{plainToInstance
|
|
1
|
+
import { plainToInstance } from "class-transformer";
|
|
2
|
+
import { validate } from "class-validator";
|
|
3
|
+
export * from "class-validator";
|
|
4
|
+
export * from "class-transformer";
|
|
5
|
+
async function validateData(data, dtoClass) {
|
|
6
|
+
try {
|
|
7
|
+
const dtoInstance = plainToInstance(dtoClass, data);
|
|
8
|
+
const errors = await validate(dtoInstance);
|
|
9
|
+
if (errors.length > 0) {
|
|
10
|
+
const errorMessages = errors.flatMap(
|
|
11
|
+
(error) => Object.values(error.constraints || {})
|
|
12
|
+
);
|
|
13
|
+
return {
|
|
14
|
+
isValid: false,
|
|
15
|
+
errors: errorMessages
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
isValid: true,
|
|
20
|
+
validatedData: dtoInstance
|
|
21
|
+
};
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return {
|
|
24
|
+
isValid: false,
|
|
25
|
+
errors: ["Validation error: " + error.message]
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
validateData
|
|
31
|
+
};
|
package/dist/wardrobe.js
CHANGED
|
@@ -1 +1,167 @@
|
|
|
1
|
-
import{normalizeObject
|
|
1
|
+
import { normalizeObject } from "./index";
|
|
2
|
+
class AppearanceComparer {
|
|
3
|
+
seedsCache = /* @__PURE__ */ new Map();
|
|
4
|
+
getSeed(arr) {
|
|
5
|
+
const normalized = normalizeObject(ServerAppearanceBundle(arr));
|
|
6
|
+
const key = JSON.stringify(normalized);
|
|
7
|
+
if (!this.seedsCache.has(key)) {
|
|
8
|
+
this.seedsCache.set(key, this.generateSeed(key));
|
|
9
|
+
}
|
|
10
|
+
return this.seedsCache.get(key);
|
|
11
|
+
}
|
|
12
|
+
generateSeed(str) {
|
|
13
|
+
let seed = 0;
|
|
14
|
+
for (let i = 0; i < str.length; i++) {
|
|
15
|
+
const char = str.charCodeAt(i);
|
|
16
|
+
seed = (seed << 5) - seed + char;
|
|
17
|
+
seed = seed & seed;
|
|
18
|
+
}
|
|
19
|
+
return seed;
|
|
20
|
+
}
|
|
21
|
+
compare(arr1, arr2) {
|
|
22
|
+
return this.getSeed(arr1) === this.getSeed(arr2);
|
|
23
|
+
}
|
|
24
|
+
getDifference(arr1, arr2) {
|
|
25
|
+
const diff = {
|
|
26
|
+
added: [],
|
|
27
|
+
modified: [],
|
|
28
|
+
removed: []
|
|
29
|
+
};
|
|
30
|
+
if (this.compare(arr1, arr2)) return diff;
|
|
31
|
+
const diffMap = ServerBuildAppearanceDiff("Female3DCG", arr1, ServerAppearanceBundle(arr2));
|
|
32
|
+
for (const [group, diffResult] of Object.entries(diffMap)) {
|
|
33
|
+
if (diffResult[0] === null && diffResult[1] !== null) {
|
|
34
|
+
diff.added.push(diffResult[1].Asset.Description);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (diffResult[0] !== null && diffResult[1] === null) {
|
|
38
|
+
diff.removed.push(diffResult[0].Asset.Description);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (diffResult[0].Asset.Name !== diffResult[1].Asset.Name) {
|
|
42
|
+
diff.removed.push(diffResult[0].Asset.Description);
|
|
43
|
+
diff.added.push(diffResult[1].Asset.Description);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (!this.compare([diffResult[0]], [diffResult[1]])) diff.modified.push(diffResult[0].Asset.Description);
|
|
47
|
+
}
|
|
48
|
+
return diff;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const appearanceComparer = new AppearanceComparer();
|
|
52
|
+
function smartGetAsset(item) {
|
|
53
|
+
const asset = Asset.includes(item) ? item : item.Asset;
|
|
54
|
+
if (!Asset.includes(asset)) {
|
|
55
|
+
throw new Error("Failed to convert item to asset");
|
|
56
|
+
}
|
|
57
|
+
return asset;
|
|
58
|
+
}
|
|
59
|
+
function smartGetAssetGroup(item) {
|
|
60
|
+
const group = AssetGroup.includes(item) ? item : Asset.includes(item) ? item.Group : item.Asset.Group;
|
|
61
|
+
if (!AssetGroup.includes(group)) {
|
|
62
|
+
throw new Error("Failed to convert item to group");
|
|
63
|
+
}
|
|
64
|
+
return group;
|
|
65
|
+
}
|
|
66
|
+
function smartGetItemName(item) {
|
|
67
|
+
if (item?.Craft?.Name) return item.Craft.Name;
|
|
68
|
+
return item?.Asset?.Description;
|
|
69
|
+
}
|
|
70
|
+
function isAssetGroupName(name) {
|
|
71
|
+
return AssetGroup.some((group) => group.Name === name);
|
|
72
|
+
}
|
|
73
|
+
function isCloth(item, allowCosplay = false) {
|
|
74
|
+
const group = smartGetAssetGroup(item);
|
|
75
|
+
return group.Category === "Appearance" && group.AllowNone && group.Clothing && (allowCosplay || !group.BodyCosplay);
|
|
76
|
+
}
|
|
77
|
+
function isCosplay(item) {
|
|
78
|
+
const group = smartGetAssetGroup(item);
|
|
79
|
+
return group.Category === "Appearance" && group.AllowNone && group.Clothing && group.BodyCosplay;
|
|
80
|
+
}
|
|
81
|
+
function isBody(item) {
|
|
82
|
+
const group = smartGetAssetGroup(item);
|
|
83
|
+
return group.Category === "Appearance" && !group.Clothing;
|
|
84
|
+
}
|
|
85
|
+
function isBind(item, excludeSlots = ["ItemNeck", "ItemNeckAccessories", "ItemNeckRestraints"]) {
|
|
86
|
+
const group = smartGetAssetGroup(item);
|
|
87
|
+
if (group.Category !== "Item" || group.BodyCosplay) return false;
|
|
88
|
+
return !excludeSlots.includes(group.Name);
|
|
89
|
+
}
|
|
90
|
+
function importAppearance(C, bundleToAttach, include = ["Cosplay", "Binds", "Collar", "Locks"], characterValidate = C, ignoreAccessValidation = false) {
|
|
91
|
+
bundleToAttach = bundleToAttach.filter((i) => !!i && !isBody(i));
|
|
92
|
+
if (!include.includes("Cosplay")) bundleToAttach = bundleToAttach.filter((i) => !isCosplay(i));
|
|
93
|
+
if (!include.includes("Binds")) bundleToAttach = bundleToAttach.filter((i) => !isBind(i));
|
|
94
|
+
if (!include.includes("Collar")) bundleToAttach = bundleToAttach.filter((i) => i.Asset.Group.Name !== "ItemNeck");
|
|
95
|
+
if (!include.includes("Locks")) bundleToAttach = bundleToAttach.map((i) => {
|
|
96
|
+
if (i.Property?.LockedBy) delete i.Property.LockedBy;
|
|
97
|
+
return i;
|
|
98
|
+
});
|
|
99
|
+
const blockedGroups = [];
|
|
100
|
+
if (ignoreAccessValidation) {
|
|
101
|
+
C.Appearance = C.Appearance.filter((a) => isBody(a));
|
|
102
|
+
} else {
|
|
103
|
+
const validationParams = ValidationCreateDiffParams(characterValidate, Player.MemberNumber);
|
|
104
|
+
C.Appearance = C.Appearance.filter((a) => {
|
|
105
|
+
if (isBody(a)) {
|
|
106
|
+
blockedGroups.push(a.Asset.Group.Name);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
if (!ValidationCanRemoveItem(
|
|
110
|
+
a,
|
|
111
|
+
validationParams,
|
|
112
|
+
!!bundleToAttach.find((b) => b?.Asset?.Group?.Name === a?.Asset?.Group?.Name)
|
|
113
|
+
) || a.Property?.LockedBy && !DialogCanUnlock(characterValidate, a) || a.Asset.Name === "SlaveCollar" && characterValidate.IsPlayer()) {
|
|
114
|
+
blockedGroups.push(a.Asset.Group.Name);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (const item of bundleToAttach) {
|
|
121
|
+
if (!ignoreAccessValidation) {
|
|
122
|
+
if (!validationCanAccessCheck(characterValidate, item.Asset.Group.Name, item.Asset)) continue;
|
|
123
|
+
if (blockedGroups.includes(item.Asset.Group.Name)) continue;
|
|
124
|
+
}
|
|
125
|
+
const _item = CharacterAppearanceSetItem(C, item.Asset.Group.Name, item.Asset, item.Color);
|
|
126
|
+
if (!_item) continue;
|
|
127
|
+
if (item.Craft && CraftingValidate(item.Craft, item.Asset) !== CraftingStatusType.CRITICAL_ERROR) _item.Craft = item.Craft;
|
|
128
|
+
if (item.Property) {
|
|
129
|
+
ValidationSanitizeProperties(C, item);
|
|
130
|
+
_item.Property = item.Property;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
CharacterRefresh(C);
|
|
134
|
+
if (!C.IsNpc()) ChatRoomCharacterUpdate(C);
|
|
135
|
+
}
|
|
136
|
+
function validationCanAccessCheck(C, group, asset) {
|
|
137
|
+
return !ValidationIsItemBlockedOrLimited(C, Player.MemberNumber, group, asset.Name) && ServerChatRoomGetAllowItem(Player, C);
|
|
138
|
+
}
|
|
139
|
+
function serverAppearanceBundleToAppearance(assetFamily, serverAppearanceBundle) {
|
|
140
|
+
return serverAppearanceBundle.map((t) => {
|
|
141
|
+
return ServerBundledItemToAppearanceItem(assetFamily, t);
|
|
142
|
+
}).filter((i) => !!i);
|
|
143
|
+
}
|
|
144
|
+
function addRequiredAppearanceItems(appearanceBundle) {
|
|
145
|
+
AssetGroup.forEach((group) => {
|
|
146
|
+
if (group.Category !== "Appearance" || group.AllowNone) return;
|
|
147
|
+
if (appearanceBundle.find((i) => i.Asset.Group.Name === group.Name)) return;
|
|
148
|
+
const asset = AssetGet("Female3DCG", group.Name, group.Asset[0]?.Name);
|
|
149
|
+
if (!asset) return;
|
|
150
|
+
appearanceBundle.push({ Asset: asset, Color: group.DefaultColor });
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
addRequiredAppearanceItems,
|
|
155
|
+
appearanceComparer,
|
|
156
|
+
importAppearance,
|
|
157
|
+
isAssetGroupName,
|
|
158
|
+
isBind,
|
|
159
|
+
isBody,
|
|
160
|
+
isCloth,
|
|
161
|
+
isCosplay,
|
|
162
|
+
serverAppearanceBundleToAppearance,
|
|
163
|
+
smartGetAsset,
|
|
164
|
+
smartGetAssetGroup,
|
|
165
|
+
smartGetItemName,
|
|
166
|
+
validationCanAccessCheck
|
|
167
|
+
};
|