zois-core 2.0.1 → 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/changelogs.js +1 -1
- package/dist/shards/checkboxShard.js +1 -1
- package/dist/shards/containerShard.js +122 -5
- package/dist/shards/shard.js +9 -6
- package/dist/types/shards/containerShard.d.ts +5 -2
- package/dist/types/shards/shard.d.ts +1 -0
- package/dist/types/ui.d.ts +2 -0
- package/dist/ui.js +11 -3
- package/package.json +1 -1
package/dist/changelogs.js
CHANGED
|
@@ -128,7 +128,7 @@ function createCommitElement(changelogCommit) {
|
|
|
128
128
|
borderRadius: "6px",
|
|
129
129
|
background: tag === "fix" ? "#f9b4b4" : tag === "feature" ? "#cbffcbc7" : "#a1e0f4",
|
|
130
130
|
color: tag === "fix" ? "#771515" : tag === "feature" ? "#147914" : "#09093e",
|
|
131
|
-
borderWidth: "
|
|
131
|
+
borderWidth: "1px",
|
|
132
132
|
borderStyle: "solid",
|
|
133
133
|
borderColor: tag === "fix" ? "#ca6565" : tag === "feature" ? "#4eea4e" : "#66adec"
|
|
134
134
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
@@ -42,6 +42,7 @@ export declare function setFontSize(element: HTMLElement, targetFontSize: number
|
|
|
42
42
|
export declare function setFontFamily(element: HTMLElement, fontFamily?: string): void;
|
|
43
43
|
export declare function setPadding(element: HTMLElement, targetPadding: number): void;
|
|
44
44
|
export declare function autosetFontSize(element: HTMLElement): void;
|
|
45
|
+
export declare function setSizeUnitVariable(): void;
|
|
45
46
|
export declare function addDynamicClass(targetElement: HTMLElement | SVGElement, styles: DynamicClassStyles): void;
|
|
46
47
|
export declare function setPreviousSubscreen(): void;
|
|
47
48
|
export declare function setSubscreen(subscreen: BaseSubscreen | null): void;
|
|
@@ -58,6 +59,7 @@ export declare abstract class BaseSubscreen {
|
|
|
58
59
|
click(): void;
|
|
59
60
|
exit(): void;
|
|
60
61
|
update(): void;
|
|
62
|
+
resize(): void;
|
|
61
63
|
setPreviousSubscreen(): void;
|
|
62
64
|
create(shard: Shard): HTMLElement;
|
|
63
65
|
createButton(ctx: ButtonShardContext): HTMLButtonElement;
|
package/dist/ui.js
CHANGED
|
@@ -107,6 +107,12 @@ function autosetFontSize(element) {
|
|
|
107
107
|
fontSize: Font + "px"
|
|
108
108
|
});
|
|
109
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
|
+
}
|
|
110
116
|
const createdDynamicClasses = [];
|
|
111
117
|
function generateDynamicClassCacheKey(styles) {
|
|
112
118
|
const sortedStringify = (obj) => {
|
|
@@ -209,6 +215,7 @@ class BaseSubscreen {
|
|
|
209
215
|
run() {
|
|
210
216
|
}
|
|
211
217
|
load() {
|
|
218
|
+
setSizeUnitVariable();
|
|
212
219
|
this.createButton({
|
|
213
220
|
x: 1815,
|
|
214
221
|
y: 75,
|
|
@@ -235,9 +242,6 @@ class BaseSubscreen {
|
|
|
235
242
|
fontSize: 8
|
|
236
243
|
}).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
|
|
237
244
|
}
|
|
238
|
-
if (subscreenHooks[this.constructor.name]) {
|
|
239
|
-
subscreenHooks[this.name].forEach((hook) => hook(this));
|
|
240
|
-
}
|
|
241
245
|
}
|
|
242
246
|
unload() {
|
|
243
247
|
}
|
|
@@ -248,6 +252,9 @@ class BaseSubscreen {
|
|
|
248
252
|
}
|
|
249
253
|
update() {
|
|
250
254
|
}
|
|
255
|
+
resize() {
|
|
256
|
+
setSizeUnitVariable();
|
|
257
|
+
}
|
|
251
258
|
setPreviousSubscreen() {
|
|
252
259
|
setPreviousSubscreen();
|
|
253
260
|
}
|
|
@@ -371,5 +378,6 @@ export {
|
|
|
371
378
|
setPosition,
|
|
372
379
|
setPreviousSubscreen,
|
|
373
380
|
setSize,
|
|
381
|
+
setSizeUnitVariable,
|
|
374
382
|
setSubscreen
|
|
375
383
|
};
|