zois-core 2.2.1 → 3.0.0
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/toast-themes/abdl/bottle.svg +10 -0
- package/dist/assets/icons/toast-themes/abdl/diaper.svg +11 -0
- package/dist/assets/icons/toast-themes/abdl/heart.svg +7 -0
- package/dist/assets/icons/toast-themes/abdl/sparkle.svg +5 -0
- package/dist/assets/icons/toast-themes/abdl/star.svg +5 -0
- package/dist/assets/icons/toast-themes/abdl/teddy.svg +18 -0
- package/dist/assets/icons/toast-themes/anime/error.svg +20 -0
- package/dist/assets/icons/toast-themes/anime/info.svg +20 -0
- package/dist/assets/icons/toast-themes/anime/success.svg +16 -0
- package/dist/assets/icons/toast-themes/anime/warning.svg +19 -0
- package/dist/changelogs.js +628 -295
- package/dist/cssVars.js +46 -0
- package/dist/dialogs.js +523 -83
- package/dist/events.js +28 -6
- package/dist/index.js +27 -70
- package/dist/localization.js +250 -40
- package/dist/messaging.js +1 -1
- package/dist/migration.js +37 -0
- package/dist/modules/baseModule.js +110 -0
- package/dist/modules/index.js +4 -0
- package/dist/modules/loadingStrategy.js +20 -0
- package/dist/modules/moduleContext.js +56 -0
- package/dist/modules/modulesManager.js +175 -0
- package/dist/{modSdk.js → patching.js} +33 -9
- package/dist/rpc.js +139 -0
- package/dist/scripts/zois-core.js +14 -14
- package/dist/settings.js +90 -0
- package/dist/settingsDialog.js +1361 -0
- package/dist/shard-modules/{attributesModule.js → attributes.js} +2 -2
- package/dist/shard-modules/{shardModule.js → base.js} +2 -2
- package/dist/shard-modules/{centerModule.js → center.js} +4 -2
- package/dist/shard-modules/{clickModule.js → click.js} +2 -2
- package/dist/shard-modules/{counterUpModule.js → counterUp.js} +2 -2
- package/dist/shard-modules/{dynamicClassModule.js → dynamicClass.js} +2 -2
- package/dist/shard-modules/index.js +9 -9
- package/dist/shard-modules/{multiClickModule.js → multiClick.js} +2 -2
- package/dist/shard-modules/{styleModule.js → style.js} +2 -2
- package/dist/shard-modules/{typeModule.js → type.js} +2 -2
- package/dist/shards/backNextButton.js +173 -0
- package/dist/shards/{shard.js → base.js} +15 -15
- package/dist/shards/{buttonShard.js → button.js} +30 -52
- package/dist/shards/{cardShard.js → card.js} +4 -4
- package/dist/shards/{checkboxShard.js → checkbox.js} +6 -13
- package/dist/shards/{containerShard.js → container.js} +2 -2
- package/dist/shards/extensionsStorageBar.js +377 -0
- package/dist/shards/fileInput.js +180 -0
- package/dist/shards/flexContainer.js +30 -0
- package/dist/shards/gridContainer.js +34 -0
- package/dist/shards/{imageShard.js → image.js} +8 -6
- package/dist/shards/index.js +17 -13
- package/dist/shards/{inputShard.js → input.js} +4 -4
- package/dist/shards/{inputListShard.js → inputList.js} +22 -4
- package/dist/shards/select.js +201 -0
- package/dist/shards/svg.js +28 -0
- package/dist/shards/{tabsShard.js → tabs.js} +18 -19
- package/dist/shards/{textShard.js → text.js} +4 -4
- package/dist/shared.js +215 -0
- package/dist/styles.css +0 -51
- package/dist/subscreens/customTranslations.js +239 -0
- package/dist/subscreens/languageDetails.js +194 -0
- package/dist/subscreens/localization.js +115 -0
- package/dist/toast-themes/abdl.js +419 -0
- package/dist/toast-themes/anime.js +483 -0
- package/dist/toast-themes/base.js +40 -0
- package/dist/toast-themes/cyber.js +538 -0
- package/dist/toast-themes/default.js +282 -0
- package/dist/toastThemesDialog.js +274 -0
- package/dist/toasts.js +195 -174
- package/dist/types/cssVars.d.ts +1 -0
- package/dist/types/dialogs.d.ts +46 -18
- package/dist/types/events.d.ts +11 -2
- package/dist/types/global.d.ts +4 -3
- package/dist/types/index.d.ts +12 -19
- package/dist/types/localization.d.ts +25 -3
- package/dist/types/migration.d.ts +6 -0
- package/dist/types/modules/baseModule.d.ts +108 -0
- package/dist/types/modules/index.d.ts +4 -0
- package/dist/types/modules/loadingStrategy.d.ts +7 -0
- package/dist/types/modules/moduleContext.d.ts +9 -0
- package/dist/types/modules/modulesManager.d.ts +23 -0
- package/dist/types/{modSdk.d.ts → patching.d.ts} +2 -3
- package/dist/types/rpc.d.ts +72 -0
- package/dist/types/settings.d.ts +19 -0
- package/dist/types/settingsDialog.d.ts +4 -0
- package/dist/types/shard-modules/{attributesModule.d.ts → attributes.d.ts} +2 -2
- package/dist/types/shard-modules/{shardModule.d.ts → base.d.ts} +2 -2
- package/dist/types/shard-modules/{centerModule.d.ts → center.d.ts} +2 -1
- package/dist/types/shard-modules/{clickModule.d.ts → click.d.ts} +2 -2
- package/dist/types/shard-modules/{counterUpModule.d.ts → counterUp.d.ts} +2 -2
- package/dist/types/shard-modules/{dynamicClassModule.d.ts → dynamicClass.d.ts} +2 -2
- package/dist/types/shard-modules/index.d.ts +9 -9
- package/dist/types/shard-modules/{multiClickModule.d.ts → multiClick.d.ts} +2 -2
- package/dist/types/shard-modules/{styleModule.d.ts → style.d.ts} +2 -2
- package/dist/types/shard-modules/{typeModule.d.ts → type.d.ts} +2 -2
- package/dist/types/shards/{backNextButtonShard.d.ts → backNextButton.d.ts} +4 -3
- package/dist/types/shards/{shard.d.ts → base.d.ts} +3 -2
- package/dist/types/shards/{buttonShard.d.ts → button.d.ts} +6 -6
- package/dist/types/shards/{cardShard.d.ts → card.d.ts} +3 -3
- package/dist/types/shards/{checkboxShard.d.ts → checkbox.d.ts} +5 -5
- package/dist/types/shards/{containerShard.d.ts → container.d.ts} +2 -2
- package/dist/types/shards/extensionsStorageBar.d.ts +28 -0
- package/dist/types/shards/fileInput.d.ts +10 -0
- package/dist/types/shards/flexContainer.d.ts +14 -0
- package/dist/types/shards/gridContainer.d.ts +18 -0
- package/dist/types/shards/{imageShard.d.ts → image.d.ts} +2 -2
- package/dist/types/shards/index.d.ts +17 -13
- package/dist/types/shards/{inputShard.d.ts → input.d.ts} +3 -3
- package/dist/types/shards/{inputListShard.d.ts → inputList.d.ts} +3 -2
- package/dist/types/shards/{selectShard.d.ts → select.d.ts} +6 -4
- package/dist/types/shards/svg.d.ts +11 -0
- package/dist/types/shards/{tabsShard.d.ts → tabs.d.ts} +3 -6
- package/dist/types/shards/{textShard.d.ts → text.d.ts} +3 -3
- package/dist/types/shared.d.ts +7 -0
- package/dist/types/subscreens/customTranslations.d.ts +10 -0
- package/dist/types/subscreens/languageDetails.d.ts +14 -0
- package/dist/types/subscreens/localization.d.ts +5 -0
- package/dist/types/toast-themes/abdl.d.ts +9 -0
- package/dist/types/toast-themes/anime.d.ts +9 -0
- package/dist/types/toast-themes/base.d.ts +39 -0
- package/dist/types/toast-themes/cyber.d.ts +10 -0
- package/dist/types/toast-themes/default.d.ts +9 -0
- package/dist/types/toastThemesDialog.d.ts +1 -0
- package/dist/types/toasts.d.ts +48 -36
- package/dist/types/ui.d.ts +128 -49
- package/dist/types/validation.d.ts +5 -0
- package/dist/ui.js +414 -79
- package/dist/validation.js +79 -1
- package/dist/wardrobe.js +2 -2
- package/package.json +36 -14
- package/dist/core-subscreen/coreSubscreen.js +0 -81
- package/dist/core-subscreen/developmentSubscreen.js +0 -22
- package/dist/core-subscreen/generalSubscreen.js +0 -23
- package/dist/core-subscreen/mainSubscreen.js +0 -58
- package/dist/core-subscreen/shards/coreButtonShard.js +0 -30
- package/dist/core-subscreen/shards/coreCheckboxShard.js +0 -33
- package/dist/core-subscreen/shards/coreInputListShard.js +0 -38
- package/dist/core-subscreen/shards/coreSelectShard.js +0 -17
- package/dist/core-subscreen/shards/coreTextShard.js +0 -9
- package/dist/core-subscreen/shards/index.js +0 -5
- package/dist/core-subscreen/toastsSubscreen.js +0 -111
- package/dist/core.js +0 -192
- package/dist/shards/backNextButtonShard.js +0 -99
- package/dist/shards/selectShard.js +0 -131
- package/dist/shards/svgShard.js +0 -29
- package/dist/types/core-subscreen/coreSubscreen.d.ts +0 -15
- package/dist/types/core-subscreen/developmentSubscreen.d.ts +0 -5
- package/dist/types/core-subscreen/generalSubscreen.d.ts +0 -5
- package/dist/types/core-subscreen/mainSubscreen.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreButtonShard.d.ts +0 -5
- package/dist/types/core-subscreen/shards/coreCheckboxShard.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreInputListShard.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreSelectShard.d.ts +0 -5
- package/dist/types/core-subscreen/shards/coreTextShard.d.ts +0 -4
- package/dist/types/core-subscreen/shards/index.d.ts +0 -5
- package/dist/types/core-subscreen/toastsSubscreen.d.ts +0 -5
- package/dist/types/core.d.ts +0 -18
- package/dist/types/shards/svgShard.d.ts +0 -12
package/dist/ui.js
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { StyleModule } from "./shard-modules";
|
|
2
2
|
import { MOD_DATA } from "./index";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ButtonShard,
|
|
5
|
+
TextShard,
|
|
6
|
+
InputShard,
|
|
7
|
+
CheckboxShard,
|
|
8
|
+
InputListShard,
|
|
9
|
+
ImageShard,
|
|
10
|
+
SvgShard,
|
|
11
|
+
BackNextButtonShard,
|
|
12
|
+
TabsShard,
|
|
13
|
+
CardShard,
|
|
14
|
+
SelectShard,
|
|
15
|
+
ContainerShard,
|
|
16
|
+
ExtensionsStorageBarShard,
|
|
17
|
+
FileInputShard,
|
|
18
|
+
GridContainerShard,
|
|
19
|
+
FlexContainerShard
|
|
20
|
+
} from "./shards";
|
|
4
21
|
import { logger } from "./logging";
|
|
5
22
|
import exitIcon from "./assets/icons/exit.svg";
|
|
6
23
|
import { eventBus } from "./events";
|
|
24
|
+
import { dialogsManager } from "./dialogs";
|
|
25
|
+
import { jsx } from "tsx-dom/jsx-runtime";
|
|
7
26
|
function hexToRgb(hex) {
|
|
8
27
|
hex = hex.replace("#", "");
|
|
9
28
|
const r = parseInt(hex.substring(0, 2), 16);
|
|
@@ -45,73 +64,60 @@ function dataUrlSvgReplaceVars(dataUrl, vars) {
|
|
|
45
64
|
}
|
|
46
65
|
return dataUrl;
|
|
47
66
|
}
|
|
67
|
+
function svgFromString(svg) {
|
|
68
|
+
const template = document.createElement("template");
|
|
69
|
+
template.innerHTML = svg.trim();
|
|
70
|
+
const el = template.content.firstElementChild;
|
|
71
|
+
if (!el || el.tagName.toLowerCase() !== "svg") {
|
|
72
|
+
throw new Error("Invalid SVG flag");
|
|
73
|
+
}
|
|
74
|
+
return el;
|
|
75
|
+
}
|
|
48
76
|
function cssVar(name, fallback) {
|
|
49
77
|
const value = getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
50
78
|
return value || fallback;
|
|
51
79
|
}
|
|
52
80
|
function getRelativeHeight(height) {
|
|
53
|
-
return height * (
|
|
81
|
+
return `calc(${height} * var(--height-unit) * 1px)`;
|
|
54
82
|
}
|
|
55
83
|
function getRelativeWidth(width) {
|
|
56
|
-
return width * (
|
|
84
|
+
return `calc(${width} * var(--width-unit) * 1px)`;
|
|
57
85
|
}
|
|
58
|
-
function getRelativeY(yPos,
|
|
59
|
-
|
|
60
|
-
return anchorPosition === "top" ? MainCanvas.canvas.offsetTop + yPos * scaleY : window.innerHeight - (MainCanvas.canvas.offsetTop + MainCanvas.canvas.clientHeight) + yPos * scaleY;
|
|
86
|
+
function getRelativeY(yPos, anchor = "top") {
|
|
87
|
+
return `calc(var(--canvas-${anchor}) + ${yPos} * var(--height-unit) * 1px)`;
|
|
61
88
|
}
|
|
62
|
-
function getRelativeX(xPos,
|
|
63
|
-
|
|
64
|
-
return anchorPosition === "left" ? MainCanvas.canvas.offsetLeft + xPos * scaleX : window.innerWidth - (MainCanvas.canvas.offsetLeft + MainCanvas.canvas.clientWidth) + xPos * scaleX;
|
|
89
|
+
function getRelativeX(xPos, anchor = "left") {
|
|
90
|
+
return `calc(var(--canvas-${anchor}) + ${xPos} * var(--width-unit) * 1px)`;
|
|
65
91
|
}
|
|
66
92
|
function setPosition(element, xPos, yPos, anchor = "top-left") {
|
|
67
93
|
const yAnchor = anchor === "top-left" || anchor === "top-right" ? "top" : "bottom";
|
|
68
94
|
const xAnchor = anchor === "top-left" || anchor === "bottom-left" ? "left" : "right";
|
|
69
|
-
const y = getRelativeY(yPos, yAnchor);
|
|
70
|
-
const x = getRelativeX(xPos, xAnchor);
|
|
71
95
|
Object.assign(element.style, {
|
|
72
96
|
position: "fixed",
|
|
73
|
-
[xAnchor]:
|
|
74
|
-
[yAnchor]:
|
|
97
|
+
[xAnchor]: getRelativeX(xPos, xAnchor),
|
|
98
|
+
[yAnchor]: getRelativeY(yPos, yAnchor)
|
|
75
99
|
});
|
|
76
100
|
}
|
|
77
101
|
function setSize(element, width, height) {
|
|
78
102
|
Object.assign(element.style, {
|
|
79
|
-
width: getRelativeWidth(width)
|
|
80
|
-
height: getRelativeHeight(height)
|
|
103
|
+
width: getRelativeWidth(width),
|
|
104
|
+
height: getRelativeHeight(height)
|
|
81
105
|
});
|
|
82
106
|
}
|
|
83
107
|
function setFontSize(element, targetFontSize) {
|
|
84
|
-
|
|
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
|
-
});
|
|
108
|
+
element.style.fontSize = `calc(${targetFontSize} * var(--size-unit) * 1px)`;
|
|
91
109
|
}
|
|
92
110
|
function setFontFamily(element, fontFamily) {
|
|
93
111
|
element.style.fontFamily = fontFamily ?? "sans-serif";
|
|
94
112
|
}
|
|
95
113
|
function setPadding(element, targetPadding) {
|
|
96
|
-
|
|
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
|
-
});
|
|
114
|
+
element.style.padding = `calc(${targetPadding} * var(--size-unit) * 1px)`;
|
|
103
115
|
}
|
|
104
116
|
function autosetFontSize(element) {
|
|
105
|
-
|
|
106
|
-
Object.assign(element.style, {
|
|
107
|
-
fontSize: Font + "px"
|
|
108
|
-
});
|
|
117
|
+
element.style.fontSize = "calc(min(var(--width-unit), var(--height-unit)) * 40 * 1px)";
|
|
109
118
|
}
|
|
110
|
-
function
|
|
111
|
-
|
|
112
|
-
const canvasHeight = MainCanvas.canvas.clientHeight;
|
|
113
|
-
const scaleFactor = Math.min(canvasWidth, canvasHeight) / 100;
|
|
114
|
-
document.documentElement.style.setProperty("--size-unit", scaleFactor.toString());
|
|
119
|
+
function u(value) {
|
|
120
|
+
return `calc(${value} * var(--size-unit) * 1px)`;
|
|
115
121
|
}
|
|
116
122
|
const createdDynamicClasses = [];
|
|
117
123
|
function generateDynamicClassCacheKey(styles) {
|
|
@@ -132,9 +138,13 @@ function generateDynamicClassCacheKey(styles) {
|
|
|
132
138
|
return cacheKey;
|
|
133
139
|
}
|
|
134
140
|
function addDynamicClass(targetElement, styles) {
|
|
141
|
+
const className = getDynamicClass(styles);
|
|
142
|
+
targetElement.classList.add(className);
|
|
143
|
+
}
|
|
144
|
+
function getDynamicClass(styles) {
|
|
135
145
|
const cacheKey = generateDynamicClassCacheKey(styles);
|
|
136
146
|
const _class = createdDynamicClasses.find((g) => g.key === cacheKey);
|
|
137
|
-
if (_class) return
|
|
147
|
+
if (_class) return _class.className;
|
|
138
148
|
let className;
|
|
139
149
|
do {
|
|
140
150
|
className = "dynamic-" + Math.random().toString(36).substring(2, 10);
|
|
@@ -162,49 +172,271 @@ function addDynamicClass(targetElement, styles) {
|
|
|
162
172
|
cssRules += buildCssBlock(`.${className}${key}`, value);
|
|
163
173
|
}
|
|
164
174
|
}
|
|
165
|
-
let styleElement = document.getElementById(`${MOD_DATA
|
|
175
|
+
let styleElement = document.getElementById(`${MOD_DATA?.key ?? ""}-dynamic-classes`);
|
|
166
176
|
if (styleElement) {
|
|
167
177
|
styleElement.textContent += cssRules;
|
|
168
178
|
} else {
|
|
169
179
|
styleElement = document.createElement("style");
|
|
170
|
-
styleElement.id = `${MOD_DATA
|
|
180
|
+
styleElement.id = `${MOD_DATA?.key ?? ""}-dynamic-classes`;
|
|
171
181
|
styleElement.textContent = cssRules;
|
|
172
182
|
document.head.appendChild(styleElement);
|
|
173
183
|
}
|
|
174
|
-
|
|
184
|
+
return className;
|
|
175
185
|
}
|
|
176
|
-
|
|
177
|
-
|
|
186
|
+
const injectedKeyframes = /* @__PURE__ */ new Map();
|
|
187
|
+
function getDynamicKeyframes(name, frames) {
|
|
188
|
+
const sortedStringify = (obj) => JSON.stringify(
|
|
189
|
+
Object.keys(obj).sort().reduce((acc, key) => {
|
|
190
|
+
acc[key] = obj[key];
|
|
191
|
+
return acc;
|
|
192
|
+
}, {})
|
|
193
|
+
);
|
|
194
|
+
let cacheKey = `${name}|`;
|
|
195
|
+
for (const [pct, styles] of Object.entries(frames)) {
|
|
196
|
+
cacheKey += `${pct}:=${sortedStringify(styles)}|`;
|
|
197
|
+
}
|
|
198
|
+
const existing = injectedKeyframes.get(cacheKey);
|
|
199
|
+
if (existing) return existing;
|
|
200
|
+
let animName;
|
|
201
|
+
do {
|
|
202
|
+
animName = `zc-kf-${name}-${Math.random().toString(36).substring(2, 8)}`;
|
|
203
|
+
} while ([...injectedKeyframes.values()].includes(animName));
|
|
204
|
+
injectedKeyframes.set(cacheKey, animName);
|
|
205
|
+
const toKebab = (prop) => prop.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
206
|
+
let css = `@keyframes ${animName} {`;
|
|
207
|
+
for (const [pct, styles] of Object.entries(frames)) {
|
|
208
|
+
css += `${pct} {`;
|
|
209
|
+
for (const [property, value] of Object.entries(styles)) {
|
|
210
|
+
css += `${toKebab(property)}: ${value};`;
|
|
211
|
+
}
|
|
212
|
+
css += "}";
|
|
213
|
+
}
|
|
214
|
+
css += "}";
|
|
215
|
+
let styleEl = document.getElementById("zc-dynamic-keyframes");
|
|
216
|
+
if (!styleEl) {
|
|
217
|
+
styleEl = document.createElement("style");
|
|
218
|
+
styleEl.id = "zc-dynamic-keyframes";
|
|
219
|
+
document.head.appendChild(styleEl);
|
|
220
|
+
}
|
|
221
|
+
styleEl.textContent += css;
|
|
222
|
+
return animName;
|
|
178
223
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
currentSubscreen = subscreen;
|
|
184
|
-
if (previousSubscreen) {
|
|
185
|
-
try {
|
|
186
|
-
previousSubscreen.unload();
|
|
187
|
-
} catch (e) {
|
|
188
|
-
logger.error("Failed to unload subscreen", previousSubscreen, e);
|
|
224
|
+
function onClickOutside(element, callback) {
|
|
225
|
+
const handler = (event) => {
|
|
226
|
+
if (element.contains(event.target)) {
|
|
227
|
+
return;
|
|
189
228
|
}
|
|
229
|
+
callback(event);
|
|
230
|
+
};
|
|
231
|
+
document.addEventListener("click", handler, true);
|
|
232
|
+
return () => {
|
|
233
|
+
document.removeEventListener("click", handler, true);
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
class KeydownManager {
|
|
237
|
+
handlers = [];
|
|
238
|
+
register(key, handler, options = {}) {
|
|
239
|
+
const entry = {
|
|
240
|
+
key,
|
|
241
|
+
handler,
|
|
242
|
+
once: options.once ?? false
|
|
243
|
+
};
|
|
244
|
+
this.handlers.push(entry);
|
|
245
|
+
return () => this.unregister(entry);
|
|
246
|
+
}
|
|
247
|
+
handleKeydown(key) {
|
|
248
|
+
const entry = this.handlers.findLast((entry2) => entry2.key === key);
|
|
249
|
+
if (!entry) return false;
|
|
250
|
+
if (entry.once) {
|
|
251
|
+
this.unregister(entry);
|
|
252
|
+
}
|
|
253
|
+
entry.handler();
|
|
254
|
+
return true;
|
|
190
255
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
256
|
+
unregister(entry) {
|
|
257
|
+
const index = this.handlers.indexOf(entry);
|
|
258
|
+
if (index !== -1) {
|
|
259
|
+
this.handlers.splice(index, 1);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const keydownManager = new KeydownManager();
|
|
264
|
+
function createTooltip(element, items) {
|
|
265
|
+
let tooltip = null;
|
|
266
|
+
let observer = null;
|
|
267
|
+
const updatePosition = () => {
|
|
268
|
+
if (!tooltip || !element.isConnected) return;
|
|
269
|
+
const rect = element.getBoundingClientRect();
|
|
270
|
+
const tooltipRect = tooltip.getBoundingClientRect();
|
|
271
|
+
const gap = 8;
|
|
272
|
+
const rightSpace = window.innerWidth - rect.right;
|
|
273
|
+
const leftSpace = rect.left;
|
|
274
|
+
const showRight = rightSpace >= tooltipRect.width + gap || rightSpace >= leftSpace;
|
|
275
|
+
const left = showRight ? rect.right + gap : rect.left - tooltipRect.width - gap;
|
|
276
|
+
const top = Math.max(
|
|
277
|
+
4,
|
|
278
|
+
Math.min(
|
|
279
|
+
rect.top + rect.height / 2 - tooltipRect.height / 2,
|
|
280
|
+
window.innerHeight - tooltipRect.height - 4
|
|
281
|
+
)
|
|
282
|
+
);
|
|
283
|
+
tooltip.style.left = `${Math.max(
|
|
284
|
+
4,
|
|
285
|
+
Math.min(left, window.innerWidth - tooltipRect.width - 4)
|
|
286
|
+
)}px`;
|
|
287
|
+
tooltip.style.top = `${top}px`;
|
|
288
|
+
};
|
|
289
|
+
const hide = () => {
|
|
290
|
+
if (tooltip) {
|
|
291
|
+
tooltip.remove();
|
|
292
|
+
tooltip = null;
|
|
196
293
|
}
|
|
294
|
+
observer?.disconnect();
|
|
295
|
+
observer = null;
|
|
296
|
+
window.removeEventListener("resize", updatePosition);
|
|
297
|
+
window.removeEventListener("scroll", updatePosition, true);
|
|
298
|
+
};
|
|
299
|
+
const show = () => {
|
|
300
|
+
if (tooltip || !element.isConnected) return;
|
|
301
|
+
tooltip = document.createElement("div");
|
|
302
|
+
tooltip.style.cssText = `
|
|
303
|
+
position: fixed;
|
|
304
|
+
z-index: 100;
|
|
305
|
+
width: max-content;
|
|
306
|
+
max-width: ${u(450)};
|
|
307
|
+
height: fit-content;
|
|
308
|
+
font-size: ${u(3.5)};
|
|
309
|
+
color: var(--tmd-text, black);
|
|
310
|
+
background: var(--tmd-element-hint, #f8f8f8);
|
|
311
|
+
border-radius: 4px;
|
|
312
|
+
border: 1px solid var(--tmd-accent, #9f9f9f);
|
|
313
|
+
pointer-events: none;
|
|
314
|
+
overflow-wrap: anywhere;
|
|
315
|
+
`;
|
|
316
|
+
const _items = typeof items === "function" ? items() : items;
|
|
317
|
+
_items.forEach((item, index) => {
|
|
318
|
+
const row = document.createElement("div");
|
|
319
|
+
row.style.cssText = `
|
|
320
|
+
display: flex;
|
|
321
|
+
align-items: center;
|
|
322
|
+
gap: ${u(1)};
|
|
323
|
+
padding: ${u(1)};
|
|
324
|
+
${index < items.length - 1 ? `
|
|
325
|
+
border-bottom: 1px solid var(--tmd-accent, #9f9f9f);
|
|
326
|
+
` : ""}
|
|
327
|
+
`;
|
|
328
|
+
if (item.icon) {
|
|
329
|
+
const icon = item.icon;
|
|
330
|
+
icon.style.cssText += `
|
|
331
|
+
flex-shrink: 0;
|
|
332
|
+
width: ${u(4)};
|
|
333
|
+
height: ${u(4)};
|
|
334
|
+
object-fit: contain;
|
|
335
|
+
`;
|
|
336
|
+
row.append(icon);
|
|
337
|
+
}
|
|
338
|
+
const text = document.createElement("span");
|
|
339
|
+
text.textContent = item.text;
|
|
340
|
+
text.style.cssText = `
|
|
341
|
+
min-width: 0;
|
|
342
|
+
flex: 1;
|
|
343
|
+
`;
|
|
344
|
+
row.append(text);
|
|
345
|
+
tooltip.append(row);
|
|
346
|
+
});
|
|
347
|
+
setFontFamily(tooltip, CommonGetFontName());
|
|
348
|
+
document.body.append(tooltip);
|
|
349
|
+
updatePosition();
|
|
350
|
+
window.addEventListener("resize", updatePosition);
|
|
351
|
+
window.addEventListener("scroll", updatePosition, true);
|
|
352
|
+
observer = new MutationObserver(() => {
|
|
353
|
+
if (!element.isConnected) {
|
|
354
|
+
hide();
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
observer.observe(document.body, {
|
|
358
|
+
childList: true,
|
|
359
|
+
subtree: true
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
element.addEventListener("mouseenter", show);
|
|
363
|
+
element.addEventListener("mouseleave", hide);
|
|
364
|
+
if (typeof items === "function") {
|
|
365
|
+
element.addEventListener("click", () => {
|
|
366
|
+
setTimeout(() => {
|
|
367
|
+
if (!element.matches(":hover") || element.matches(":disabled")) return;
|
|
368
|
+
hide();
|
|
369
|
+
show();
|
|
370
|
+
}, 0);
|
|
371
|
+
});
|
|
197
372
|
}
|
|
198
373
|
}
|
|
374
|
+
const subscreenStack = [];
|
|
199
375
|
function getCurrentSubscreen() {
|
|
200
|
-
return
|
|
376
|
+
return subscreenStack[subscreenStack.length - 1] ?? null;
|
|
201
377
|
}
|
|
202
378
|
function getPreviousSubscreen() {
|
|
203
|
-
return
|
|
379
|
+
return subscreenStack.length >= 2 ? subscreenStack[subscreenStack.length - 2] : null;
|
|
380
|
+
}
|
|
381
|
+
function getSubscreenStack() {
|
|
382
|
+
return subscreenStack;
|
|
383
|
+
}
|
|
384
|
+
function setSubscreen(nextSubscreen) {
|
|
385
|
+
const currentSubscreen = getCurrentSubscreen();
|
|
386
|
+
if (currentSubscreen) {
|
|
387
|
+
try {
|
|
388
|
+
currentSubscreen.unload();
|
|
389
|
+
} catch (e) {
|
|
390
|
+
logger.error("Failed to unload subscreen", currentSubscreen, e);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (nextSubscreen === null) {
|
|
394
|
+
while (subscreenStack.length > 0) {
|
|
395
|
+
const screen = subscreenStack.pop();
|
|
396
|
+
if (screen === currentSubscreen) continue;
|
|
397
|
+
try {
|
|
398
|
+
screen.unload();
|
|
399
|
+
} catch (e) {
|
|
400
|
+
logger.error("Failed to unload subscreen", screen, e);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const existingIndex = subscreenStack.indexOf(nextSubscreen);
|
|
406
|
+
if (existingIndex !== -1) {
|
|
407
|
+
subscreenStack.length = existingIndex + 1;
|
|
408
|
+
} else {
|
|
409
|
+
subscreenStack.push(nextSubscreen);
|
|
410
|
+
}
|
|
411
|
+
try {
|
|
412
|
+
nextSubscreen.load();
|
|
413
|
+
} catch (e) {
|
|
414
|
+
logger.error("Failed to load subscreen", nextSubscreen, e);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function setPreviousSubscreen() {
|
|
418
|
+
const currentSubscreen = getCurrentSubscreen();
|
|
419
|
+
if (!currentSubscreen) return;
|
|
420
|
+
try {
|
|
421
|
+
currentSubscreen.unload();
|
|
422
|
+
} catch (e) {
|
|
423
|
+
logger.error("Failed to unload subscreen", currentSubscreen, e);
|
|
424
|
+
}
|
|
425
|
+
subscreenStack.pop();
|
|
426
|
+
const previousSubscreen = getCurrentSubscreen();
|
|
427
|
+
if (previousSubscreen) {
|
|
428
|
+
try {
|
|
429
|
+
previousSubscreen.load();
|
|
430
|
+
} catch (e) {
|
|
431
|
+
logger.error("Failed to load subscreen", previousSubscreen, e);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
204
434
|
}
|
|
205
435
|
class BaseSubscreen {
|
|
206
436
|
setSubscreen = setSubscreen;
|
|
207
437
|
setPreviousSubscreen = setPreviousSubscreen;
|
|
438
|
+
unregisterEscape = null;
|
|
439
|
+
exitConfirmationMessage = null;
|
|
208
440
|
get currentSubscreen() {
|
|
209
441
|
return getCurrentSubscreen();
|
|
210
442
|
}
|
|
@@ -225,12 +457,12 @@ class BaseSubscreen {
|
|
|
225
457
|
*
|
|
226
458
|
* You probably want to override {@link onLoad}, **do not** override `load` if you don't understand what you're doing.
|
|
227
459
|
*
|
|
228
|
-
* Override {@link onLoad}
|
|
460
|
+
* Override {@link onLoad} to define html elements.
|
|
229
461
|
*/
|
|
230
462
|
load() {
|
|
231
|
-
|
|
463
|
+
this.createSubscreenStackBar();
|
|
232
464
|
this.createExitButton();
|
|
233
|
-
|
|
465
|
+
this.unregisterEscape = keydownManager.register("Escape", () => this.exit());
|
|
234
466
|
this.onLoad?.();
|
|
235
467
|
eventBus?.emit("subscreenLoaded", {
|
|
236
468
|
subscreen: this
|
|
@@ -242,6 +474,7 @@ class BaseSubscreen {
|
|
|
242
474
|
* You probably want to override {@link onUnload}, **do not** override `unload` if you don't understand what you're doing.
|
|
243
475
|
*/
|
|
244
476
|
unload() {
|
|
477
|
+
this.unregisterEscape?.();
|
|
245
478
|
this.onUnload?.();
|
|
246
479
|
eventBus?.emit("subscreenUnloaded", {
|
|
247
480
|
subscreen: this
|
|
@@ -263,8 +496,17 @@ class BaseSubscreen {
|
|
|
263
496
|
* You probably want to override {@link onExit}, **do not** override `exit` if you don't understand what you're doing.
|
|
264
497
|
*/
|
|
265
498
|
exit() {
|
|
266
|
-
this.
|
|
267
|
-
|
|
499
|
+
if (this.exitConfirmationMessage === null) {
|
|
500
|
+
this.onExit?.();
|
|
501
|
+
setPreviousSubscreen();
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
dialogsManager.confirm({ message: this.exitConfirmationMessage }).then((result) => {
|
|
505
|
+
if (result) {
|
|
506
|
+
this.onExit?.();
|
|
507
|
+
setPreviousSubscreen();
|
|
508
|
+
}
|
|
509
|
+
});
|
|
268
510
|
}
|
|
269
511
|
update() {
|
|
270
512
|
}
|
|
@@ -274,7 +516,6 @@ class BaseSubscreen {
|
|
|
274
516
|
* You probably want to override {@link onResize}, **do not** override `resize` if you don't understand what you're doing.
|
|
275
517
|
*/
|
|
276
518
|
resize() {
|
|
277
|
-
setSizeUnitVariable();
|
|
278
519
|
this.onResize?.();
|
|
279
520
|
}
|
|
280
521
|
createExitButton() {
|
|
@@ -284,10 +525,9 @@ class BaseSubscreen {
|
|
|
284
525
|
width: 90,
|
|
285
526
|
height: 90,
|
|
286
527
|
icon: dataUrlSvgWithColor(exitIcon, { fill: cssVar("--tmd-text", "black") }),
|
|
287
|
-
tooltip: {
|
|
288
|
-
position: "left",
|
|
528
|
+
tooltip: [{
|
|
289
529
|
text: "Back"
|
|
290
|
-
},
|
|
530
|
+
}],
|
|
291
531
|
modules: {
|
|
292
532
|
base: [
|
|
293
533
|
new StyleModule({
|
|
@@ -298,18 +538,85 @@ class BaseSubscreen {
|
|
|
298
538
|
onClick: () => this.exit()
|
|
299
539
|
});
|
|
300
540
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
541
|
+
createSubscreenStackBar() {
|
|
542
|
+
const stack = [...subscreenStack];
|
|
543
|
+
if (stack.length === 0) return;
|
|
544
|
+
const barClassName = getDynamicClass({
|
|
545
|
+
base: {
|
|
546
|
+
display: "flex",
|
|
547
|
+
alignItems: "center",
|
|
548
|
+
gap: "0.45em",
|
|
549
|
+
background: "var(--tmd-element, rgb(244, 244, 244))",
|
|
550
|
+
border: "1px solid var(--tmd-element-hover, rgb(194, 194, 194))",
|
|
551
|
+
color: "var(--tmd-text, black)",
|
|
552
|
+
fontSize: u(4),
|
|
553
|
+
borderRadius: "0.25em",
|
|
554
|
+
boxSizing: "border-box"
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
const bar = /* @__PURE__ */ jsx("div", { class: barClassName });
|
|
558
|
+
stack.forEach((s, i) => {
|
|
559
|
+
if (i !== 0) {
|
|
560
|
+
const separator = /* @__PURE__ */ jsx("span", { style: { opacity: "0.5" }, children: "/" });
|
|
561
|
+
bar.append(separator);
|
|
562
|
+
}
|
|
563
|
+
const isCurrent = i === stack.length - 1;
|
|
564
|
+
const itemClassName = getDynamicClass({
|
|
565
|
+
base: {
|
|
566
|
+
cursor: isCurrent ? "default" : "pointer",
|
|
567
|
+
border: "none",
|
|
568
|
+
background: "none",
|
|
569
|
+
color: "inherit",
|
|
570
|
+
borderRadius: "0.25em",
|
|
571
|
+
paddingInline: "0.25em",
|
|
572
|
+
height: "100%",
|
|
573
|
+
whiteSpace: "nowrap",
|
|
574
|
+
overflow: isCurrent ? "unset" : "hidden",
|
|
575
|
+
textOverflow: isCurrent ? "unset" : "ellipsis",
|
|
576
|
+
fontWeight: isCurrent ? "bold" : "unset"
|
|
577
|
+
},
|
|
578
|
+
hover: {
|
|
579
|
+
background: isCurrent ? "none" : "var(--tmd-element-hover, rgb(223, 223, 223))"
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
const item = /* @__PURE__ */ jsx(
|
|
583
|
+
"button",
|
|
584
|
+
{
|
|
585
|
+
class: itemClassName,
|
|
586
|
+
onClick: () => {
|
|
587
|
+
if (isCurrent) return;
|
|
588
|
+
const targetIndex = subscreenStack.indexOf(s);
|
|
589
|
+
if (targetIndex === -1) return;
|
|
590
|
+
while (subscreenStack.length - 1 > targetIndex) {
|
|
591
|
+
setPreviousSubscreen();
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
children: s.name
|
|
595
|
+
}
|
|
596
|
+
);
|
|
597
|
+
bar.append(item);
|
|
598
|
+
});
|
|
599
|
+
return this.create(bar, {
|
|
304
600
|
x: 100,
|
|
305
|
-
y:
|
|
306
|
-
|
|
307
|
-
|
|
601
|
+
y: 70,
|
|
602
|
+
width: 1700,
|
|
603
|
+
height: 65
|
|
604
|
+
});
|
|
308
605
|
}
|
|
309
|
-
|
|
606
|
+
createFromShard(shard) {
|
|
310
607
|
const htmlElement = shard.mount();
|
|
311
608
|
return htmlElement;
|
|
312
609
|
}
|
|
610
|
+
create(element, properties) {
|
|
611
|
+
setFontFamily(element, MOD_DATA.fontFamily);
|
|
612
|
+
if (properties.width !== void 0) element.style.width = getRelativeWidth(properties.width);
|
|
613
|
+
if (properties.height !== void 0) element.style.height = getRelativeHeight(properties.height);
|
|
614
|
+
if (properties.x !== void 0 && properties.y !== void 0) setPosition(element, properties.x, properties.y, properties.anchor);
|
|
615
|
+
properties.parent ??= document.body;
|
|
616
|
+
properties.parent.append(element);
|
|
617
|
+
eventBus?.on("subscreenUnloaded", () => element.remove());
|
|
618
|
+
return element;
|
|
619
|
+
}
|
|
313
620
|
createButton(ctx) {
|
|
314
621
|
const shard = new ButtonShard(ctx);
|
|
315
622
|
const htmlElement = shard.mount();
|
|
@@ -398,21 +705,48 @@ class BaseSubscreen {
|
|
|
398
705
|
const htmlElement = shard.mount();
|
|
399
706
|
return htmlElement;
|
|
400
707
|
}
|
|
708
|
+
createFlexContainer(ctx) {
|
|
709
|
+
const shard = new FlexContainerShard(ctx);
|
|
710
|
+
const htmlElement = shard.mount();
|
|
711
|
+
return htmlElement;
|
|
712
|
+
}
|
|
713
|
+
createGridContainer(ctx) {
|
|
714
|
+
const shard = new GridContainerShard(ctx);
|
|
715
|
+
const htmlElement = shard.mount();
|
|
716
|
+
return htmlElement;
|
|
717
|
+
}
|
|
718
|
+
createExtensionsStorageBar(ctx) {
|
|
719
|
+
const shard = new ExtensionsStorageBarShard(ctx);
|
|
720
|
+
const htmlElement = shard.mount();
|
|
721
|
+
return htmlElement;
|
|
722
|
+
}
|
|
723
|
+
createFileInput(ctx) {
|
|
724
|
+
const shard = new FileInputShard(ctx);
|
|
725
|
+
const htmlElement = shard.mount();
|
|
726
|
+
return htmlElement;
|
|
727
|
+
}
|
|
401
728
|
}
|
|
402
729
|
export {
|
|
403
730
|
BaseSubscreen,
|
|
731
|
+
KeydownManager,
|
|
404
732
|
addDynamicClass,
|
|
405
733
|
autosetFontSize,
|
|
734
|
+
createTooltip,
|
|
406
735
|
cssVar,
|
|
407
736
|
dataUrlSvgReplaceVars,
|
|
408
737
|
dataUrlSvgWithColor,
|
|
409
738
|
getCurrentSubscreen,
|
|
739
|
+
getDynamicClass,
|
|
740
|
+
getDynamicKeyframes,
|
|
410
741
|
getPreviousSubscreen,
|
|
411
742
|
getRelativeHeight,
|
|
412
743
|
getRelativeWidth,
|
|
413
744
|
getRelativeX,
|
|
414
745
|
getRelativeY,
|
|
746
|
+
getSubscreenStack,
|
|
415
747
|
hexToRgb,
|
|
748
|
+
keydownManager,
|
|
749
|
+
onClickOutside,
|
|
416
750
|
recolorSVG,
|
|
417
751
|
setFontFamily,
|
|
418
752
|
setFontSize,
|
|
@@ -420,6 +754,7 @@ export {
|
|
|
420
754
|
setPosition,
|
|
421
755
|
setPreviousSubscreen,
|
|
422
756
|
setSize,
|
|
423
|
-
|
|
424
|
-
|
|
757
|
+
setSubscreen,
|
|
758
|
+
svgFromString,
|
|
759
|
+
u
|
|
425
760
|
};
|