@overmvp/kumi 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +14 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +334 -0
- package/builder/css-v1.test.mjs +321 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +86 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +444 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2164 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +367 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +47 -0
- package/builder/src/numbers.lua +62 -0
- package/builder/src/project-front.mjs +3331 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +127 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +17 -0
- package/form/index.ts +522 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +22 -4
- package/router/index.ts +43 -0
- package/router/package.json +12 -0
- package/router/routes.ts +64 -0
- package/scripts/kumi-cli.mjs +70 -0
- package/scripts/link-addons.mjs +51 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +234 -0
- package/src/css-v1.ts +58 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +479 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +334 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +28 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +22 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +363 -0
- package/src/media-query.ts +144 -0
- package/src/module.ts +277 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +44 -0
- package/src/providers.ts +235 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +254 -0
- package/src/result.ts +58 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +30 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +3 -0
- package/state/package.json +12 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +82 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/README.md +14 -0
- package/templates/addon/__ADDON_NAME__.toc +4 -0
- package/templates/addon/eslint.config.mjs +12 -0
- package/templates/addon/gitignore +8 -0
- package/templates/addon/package.json +21 -0
- package/templates/addon/scripts/build.mjs +25 -0
- package/templates/addon/src/app/main.tsx +13 -0
- package/templates/addon/tsconfig.json +24 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- package/wow/animation.ts +428 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/css-box.ts +110 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +398 -0
- package/wow/css-text.ts +399 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +31 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +97 -0
- package/wow/layout-view.ts +651 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +135 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/protect.ts +24 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/range-art.ts +74 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +156 -0
- package/wow/saved-variables.ts +60 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/start-addon.ts +99 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1746 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { currentScope } from "../src/reactive-scope";
|
|
2
|
+
import { fail, ok, type Result } from "../src/result";
|
|
3
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
4
|
+
import type { Job } from "../src/scheduler";
|
|
5
|
+
import { createFrame, type Frame, type FrameEventRegistration } from "./frames";
|
|
6
|
+
import { api, reveal } from "./native";
|
|
7
|
+
import { protectNative } from "./protect";
|
|
8
|
+
|
|
9
|
+
export interface ProtectedLayoutOptions {
|
|
10
|
+
scope?: RuntimeScope;
|
|
11
|
+
label?: string;
|
|
12
|
+
prewarm?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ProtectedLayoutUpdate {
|
|
16
|
+
request(this: void): Result<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type Enqueue = (this: void) => void;
|
|
20
|
+
type CombatEventFrame = FrameEventRegistration & {
|
|
21
|
+
SetScript(this: object, script: "OnEvent", handler: Enqueue): void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const waiting = new Set<Enqueue>();
|
|
25
|
+
const regenEvent = "PLAYER_REGEN_ENABLED";
|
|
26
|
+
let combatEvents: CombatEventFrame | undefined;
|
|
27
|
+
let listening = false;
|
|
28
|
+
|
|
29
|
+
function nativeFailure(problem: unknown, fallback: string) {
|
|
30
|
+
const reason = reveal(problem);
|
|
31
|
+
return fail(typeof reason === "string" ? reason : fallback);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function stopListening() {
|
|
35
|
+
const frame = combatEvents;
|
|
36
|
+
if (frame === undefined || !listening || waiting.size !== 0) return;
|
|
37
|
+
const [success, problem] = protectNative(() => frame.UnregisterEvent(regenEvent));
|
|
38
|
+
if (success) listening = false;
|
|
39
|
+
else {
|
|
40
|
+
const { reason } = nativeFailure(problem, "Could not stop listening for the end of combat");
|
|
41
|
+
protectNative(() => api.geterrorhandler()(reason));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function flushWaiting() {
|
|
46
|
+
const ready = [...waiting];
|
|
47
|
+
waiting.clear();
|
|
48
|
+
stopListening();
|
|
49
|
+
for (const enqueue of ready) enqueue();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function combatFrame() {
|
|
53
|
+
return combatEvents ??= createFrame("Frame") as Frame & CombatEventFrame;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function watchCombat(): Result<void> {
|
|
57
|
+
if (listening) return ok(undefined);
|
|
58
|
+
const [success, problem] = protectNative(() => {
|
|
59
|
+
const frame = combatFrame();
|
|
60
|
+
frame.SetScript("OnEvent", flushWaiting);
|
|
61
|
+
frame.RegisterEvent(regenEvent);
|
|
62
|
+
});
|
|
63
|
+
if (!success) return nativeFailure(problem, "Could not listen for the end of combat");
|
|
64
|
+
listening = true;
|
|
65
|
+
return ok(undefined);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Reconcile protected layout with current state on the owning runtime's frame budget. */
|
|
69
|
+
export function createProtectedLayoutUpdate(this: void, commit: Job,
|
|
70
|
+
{ scope = currentScope(), label = "Protected layout", prewarm = false }: ProtectedLayoutOptions = {}): Result<ProtectedLayoutUpdate> {
|
|
71
|
+
if (scope === undefined || !scope.isActive()) return fail("Protected layout requires an active scope");
|
|
72
|
+
if (prewarm && combatEvents === undefined) {
|
|
73
|
+
const [success, problem] = protectNative(combatFrame);
|
|
74
|
+
if (!success) return nativeFailure(problem, "Could not prepare the protected layout event frame");
|
|
75
|
+
}
|
|
76
|
+
const owner = scope;
|
|
77
|
+
const frames = owner.frameJobs;
|
|
78
|
+
const key = {};
|
|
79
|
+
const options = { lane: "normal", label } as const;
|
|
80
|
+
let waiter: Enqueue | undefined;
|
|
81
|
+
let committing = false;
|
|
82
|
+
|
|
83
|
+
function enqueue() {
|
|
84
|
+
if (owner.isActive()) frames.queue(key, run, options);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function cancel() {
|
|
88
|
+
const pending = waiter;
|
|
89
|
+
waiter = undefined;
|
|
90
|
+
if (pending !== undefined && waiting.delete(pending)) stopListening();
|
|
91
|
+
frames.cancel(key);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function waitForCombat() {
|
|
95
|
+
frames.cancel(key);
|
|
96
|
+
if (waiter !== undefined && waiting.has(waiter)) return ok(undefined);
|
|
97
|
+
const ready = watchCombat();
|
|
98
|
+
if (!ready.ok) return ready;
|
|
99
|
+
const next = () => {
|
|
100
|
+
if (waiter !== next) return;
|
|
101
|
+
waiter = undefined;
|
|
102
|
+
enqueue();
|
|
103
|
+
};
|
|
104
|
+
waiter = next;
|
|
105
|
+
waiting.add(next);
|
|
106
|
+
return ready;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function request(): Result<void> {
|
|
110
|
+
if (!owner.isActive()) return fail("The protected layout scope has been disposed");
|
|
111
|
+
const lockdown = reveal(api.InCombatLockdown());
|
|
112
|
+
if (typeof lockdown !== "boolean" || lockdown) return waitForCombat();
|
|
113
|
+
|
|
114
|
+
cancel();
|
|
115
|
+
if (committing) {
|
|
116
|
+
enqueue();
|
|
117
|
+
return ok(undefined);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
committing = true;
|
|
121
|
+
const [success, result] = protectNative(commit);
|
|
122
|
+
committing = false;
|
|
123
|
+
return success ? result ?? ok(undefined) : nativeFailure(result, "Protected layout update failed");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function run() {
|
|
127
|
+
const result = request();
|
|
128
|
+
if (!result.ok) return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const cleanup = owner.onDispose(cancel);
|
|
132
|
+
return cleanup.ok ? ok({ request }) : cleanup;
|
|
133
|
+
}
|
package/wow/range-art.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { fail, ok } from "../src/result";
|
|
2
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
3
|
+
import { createFrame, type FrameMap, type Texture } from "./frames";
|
|
4
|
+
import { isSecret, reveal } from "./native";
|
|
5
|
+
import { protect } from "./protect";
|
|
6
|
+
|
|
7
|
+
/** Place the skin's hosts on the same travel interval as the native slider thumb. */
|
|
8
|
+
export function mountRangeArt(this: void, slider: FrameMap["Slider"], size: number, scope: RuntimeScope) {
|
|
9
|
+
if (isSecret(size) || !Number.isFinite(size) || size <= 0) return fail("Invalid native slider thumb size");
|
|
10
|
+
|
|
11
|
+
const nativeThumb = slider.CreateTexture(undefined, "OVERLAY");
|
|
12
|
+
let previousThumb: { texture: Texture; shown: boolean } | undefined;
|
|
13
|
+
const cleanup = scope.onDispose(() => {
|
|
14
|
+
if (previousThumb === undefined) {
|
|
15
|
+
nativeThumb.Hide();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const { texture, shown } = previousThumb;
|
|
19
|
+
const current = protect(() => slider.GetThumbTexture());
|
|
20
|
+
if (current.ok && !isSecret(current.value)) {
|
|
21
|
+
if (current.value !== nativeThumb) {
|
|
22
|
+
nativeThumb.Hide();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
protect(() => slider.SetThumbTexture(texture));
|
|
26
|
+
const restored = protect(() => slider.GetThumbTexture());
|
|
27
|
+
if (restored.ok && !isSecret(restored.value) && restored.value === texture) {
|
|
28
|
+
nativeThumb.Hide();
|
|
29
|
+
texture.SetShown(shown);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Keep a visible native thumb when an existing one cannot be restored.
|
|
34
|
+
nativeThumb.SetAlpha(1);
|
|
35
|
+
nativeThumb.Show();
|
|
36
|
+
});
|
|
37
|
+
if (!cleanup.ok) return cleanup;
|
|
38
|
+
nativeThumb.SetTexture("Interface\\Buttons\\WHITE8X8");
|
|
39
|
+
nativeThumb.SetSize(size, size);
|
|
40
|
+
|
|
41
|
+
const track = createFrame("Frame", undefined, slider);
|
|
42
|
+
scope.onDispose(() => track.Hide());
|
|
43
|
+
const fill = createFrame("Frame", undefined, slider);
|
|
44
|
+
scope.onDispose(() => fill.Hide());
|
|
45
|
+
const thumb = createFrame("Frame", undefined, slider);
|
|
46
|
+
scope.onDispose(() => thumb.Hide());
|
|
47
|
+
|
|
48
|
+
track.SetHeight(size);
|
|
49
|
+
track.SetPoint("LEFT", slider, "LEFT", size / 2, 0);
|
|
50
|
+
track.SetPoint("RIGHT", slider, "RIGHT", -size / 2, 0);
|
|
51
|
+
fill.SetHeight(size);
|
|
52
|
+
fill.SetPoint("LEFT", track, "LEFT");
|
|
53
|
+
fill.SetPoint("RIGHT", nativeThumb, "CENTER");
|
|
54
|
+
thumb.SetPoint("TOPLEFT", nativeThumb, "TOPLEFT");
|
|
55
|
+
thumb.SetPoint("BOTTOMRIGHT", nativeThumb, "BOTTOMRIGHT");
|
|
56
|
+
|
|
57
|
+
function installThumb() {
|
|
58
|
+
if (!scope.isActive()) return fail("The reactive scope has been disposed");
|
|
59
|
+
const previous = slider.GetThumbTexture() as Texture | undefined;
|
|
60
|
+
if (isSecret(previous)) return fail("Native slider thumb is unreadable");
|
|
61
|
+
if (previous !== undefined) {
|
|
62
|
+
const shown = reveal(previous.IsShown());
|
|
63
|
+
if (shown === undefined) return fail("Native slider thumb visibility is unreadable");
|
|
64
|
+
previousThumb = { texture: previous, shown };
|
|
65
|
+
}
|
|
66
|
+
slider.SetThumbTexture(nativeThumb);
|
|
67
|
+
const installed = slider.GetThumbTexture();
|
|
68
|
+
if (isSecret(installed) || installed !== nativeThumb) return fail("Native slider thumb was not installed");
|
|
69
|
+
previous?.Hide();
|
|
70
|
+
nativeThumb.SetAlpha(0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return ok({ track, fill, thumb, installThumb });
|
|
74
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ownedArray, type OwnedArray, type OwnedReadonlyArray } from "../src/owned-collections";
|
|
2
|
+
import { fail, ok, type Result } from "../src/result";
|
|
3
|
+
import { canAccessRegion } from "./frame-access";
|
|
4
|
+
import type { Frame } from "./frames";
|
|
5
|
+
import { frameStrata as strata, maximumFrameLevel } from "./frame-layer";
|
|
6
|
+
import { api, isSecret, reveal } from "./native";
|
|
7
|
+
import { protect } from "./protect";
|
|
8
|
+
|
|
9
|
+
const maximumDepth = 13;
|
|
10
|
+
|
|
11
|
+
type LevelFrame = Pick<Frame, "GetChildren" | "GetFrameLevel" | "GetParent" | "IsForbidden" | "IsProtected" | "SetFrameLevel">;
|
|
12
|
+
type Descendant = { frame: LevelFrame; parent: LevelFrame; level: number };
|
|
13
|
+
|
|
14
|
+
function unprotected(frame: LevelFrame): boolean {
|
|
15
|
+
const [protectedState] = frame.IsProtected();
|
|
16
|
+
return reveal(protectedState) === false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readStrata(frame: Frame): number {
|
|
20
|
+
const value = reveal(frame.GetFrameStrata());
|
|
21
|
+
return typeof value === "string" ? (strata as readonly string[] as OwnedReadonlyArray<string>).indexOf(value) : -1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function collectLevels(parent: LevelFrame, levels: OwnedArray<Descendant>, depth: number): boolean {
|
|
25
|
+
if (depth === maximumDepth) return true;
|
|
26
|
+
const children = parent.GetChildren();
|
|
27
|
+
for (const child of children) {
|
|
28
|
+
if (!canAccessRegion(child) || !unprotected(child)) continue;
|
|
29
|
+
const level = reveal(child.GetFrameLevel());
|
|
30
|
+
if (level === undefined) return false;
|
|
31
|
+
levels.push({ frame: child, parent, level });
|
|
32
|
+
if (!collectLevels(child, levels, depth + 1)) return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function reparent(frame: Frame, parent: Frame): Result<void> {
|
|
38
|
+
if (!canAccessRegion(frame) || !canAccessRegion(parent)) return fail("Frame or parent is inaccessible");
|
|
39
|
+
const oldParent = frame.GetParent();
|
|
40
|
+
if (isSecret(oldParent)) return fail("Frame parent is unreadable");
|
|
41
|
+
if (oldParent === parent) return ok(undefined);
|
|
42
|
+
if (frame === parent) return fail("A frame cannot be its own parent");
|
|
43
|
+
|
|
44
|
+
const inCombat = api.InCombatLockdown();
|
|
45
|
+
if (isSecret(inCombat)) return fail("Combat lockdown is unreadable");
|
|
46
|
+
if (inCombat && (!unprotected(frame) || !unprotected(parent))) {
|
|
47
|
+
return fail("Cannot reparent a protected frame in combat");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const frameStrata = readStrata(frame);
|
|
51
|
+
const parentStrata = readStrata(parent);
|
|
52
|
+
const levelBefore = reveal(frame.GetFrameLevel());
|
|
53
|
+
const parentLevel = reveal(parent.GetFrameLevel());
|
|
54
|
+
if (frameStrata < 0 || parentStrata < 0 || levelBefore === undefined || parentLevel === undefined) {
|
|
55
|
+
return fail("Frame or parent layers are unreadable");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Record levels before native SetParent, which can shift descendants on its own.
|
|
59
|
+
const descendants = ownedArray<Descendant>();
|
|
60
|
+
if (!collectLevels(frame, descendants, 0)) return fail("A descendant frame level is unreadable");
|
|
61
|
+
|
|
62
|
+
frame.SetParent(parent);
|
|
63
|
+
if (reveal(frame.GetParent()) !== parent) return fail("The client did not confirm the new frame parent");
|
|
64
|
+
|
|
65
|
+
const targetStrata = Math.max(frameStrata, parentStrata);
|
|
66
|
+
if (readStrata(frame) !== targetStrata) {
|
|
67
|
+
frame.SetFrameStrata(strata[targetStrata]);
|
|
68
|
+
if (readStrata(frame) !== targetStrata) return fail("The client did not apply the new frame strata");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let levelAfter = reveal(frame.GetFrameLevel());
|
|
72
|
+
if (levelAfter !== undefined && levelAfter <= parentLevel) {
|
|
73
|
+
frame.SetFrameLevel(parentLevel + 1);
|
|
74
|
+
levelAfter = reveal(frame.GetFrameLevel());
|
|
75
|
+
}
|
|
76
|
+
if (levelAfter === undefined || levelAfter <= parentLevel) return fail("The client did not confirm the new frame level");
|
|
77
|
+
|
|
78
|
+
const delta = levelAfter - levelBefore;
|
|
79
|
+
for (const descendant of descendants) {
|
|
80
|
+
const child = descendant.frame;
|
|
81
|
+
if (!canAccessRegion(child) || !unprotected(child)) continue;
|
|
82
|
+
if (reveal(child.GetParent()) !== descendant.parent) return fail("A descendant frame changed parent during reparenting");
|
|
83
|
+
const level = reveal(child.GetFrameLevel());
|
|
84
|
+
if (level === undefined) return fail("A descendant frame level is unreadable");
|
|
85
|
+
const target = Math.max(0, Math.min(maximumFrameLevel, descendant.level + delta));
|
|
86
|
+
if (level !== target) {
|
|
87
|
+
child.SetFrameLevel(target);
|
|
88
|
+
if (reveal(child.GetFrameLevel()) !== target) return fail("The client did not apply a descendant frame level");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return ok(undefined);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Move a frame and preserve the relative levels of its accessible, unprotected descendants. */
|
|
96
|
+
export function reparentFrame(frame: Frame, parent: Frame): Result<void> {
|
|
97
|
+
const result = protect(() => reparent(frame, parent));
|
|
98
|
+
return result.ok ? result.value : result;
|
|
99
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { OwnedReadonlyArray } from "../src/owned-collections";
|
|
2
|
+
import type { Frame, StatusBar, Texture } from "./frames";
|
|
3
|
+
|
|
4
|
+
type Layer = Parameters<Frame["CreateTexture"]>[1];
|
|
5
|
+
type FillMask = ReturnType<StatusBar["CreateMaskTexture"]>;
|
|
6
|
+
type SliceTexture = Pick<FillMask, "SetTexture" | "SetTextureSliceMargins" | "SetTextureSliceMode">;
|
|
7
|
+
type TextureAsset = NonNullable<Parameters<SliceTexture["SetTexture"]>[0]>;
|
|
8
|
+
export type RoundedTextureSide = "left" | "right";
|
|
9
|
+
|
|
10
|
+
export interface RoundedTextureOptions {
|
|
11
|
+
directory(this: void): string;
|
|
12
|
+
readonly resolveArt?: never;
|
|
13
|
+
fallback(this: void): string;
|
|
14
|
+
readonly radii: readonly number[];
|
|
15
|
+
readonly stretched?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RoundedTextureResolverOptions extends Omit<RoundedTextureOptions, "directory" | "resolveArt"> {
|
|
19
|
+
readonly directory?: never;
|
|
20
|
+
/** Resolve an exact variant to a native path or FileID, or return undefined when absent. */
|
|
21
|
+
resolveArt(this: void, radius: number, outline: boolean, side?: RoundedTextureSide): TextureAsset | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface MaskedStatusBarFill {
|
|
25
|
+
setRadius(this: void, radius: number, side?: RoundedTextureSide): FillMask | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RoundedTextures {
|
|
29
|
+
create(this: void, parent: Frame, radius: number, outline?: boolean, layer?: Layer, sublevel?: number,
|
|
30
|
+
side?: RoundedTextureSide): Texture;
|
|
31
|
+
apply(this: void, texture: Texture, radius: number, outline?: boolean, side?: RoundedTextureSide): void;
|
|
32
|
+
/** Install an exact registered radius on a caller-owned mask. */
|
|
33
|
+
applyMask(this: void, mask: FillMask, radius: number): boolean;
|
|
34
|
+
bindStatusBarFill(this: void, bar: StatusBar, fill: Texture): MaskedStatusBarFill;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const maskWrap = "CLAMPTOBLACKADDITIVE";
|
|
38
|
+
|
|
39
|
+
/** Apply host-supplied Round textures with native nine-slice margins. */
|
|
40
|
+
export function createRoundedTextures(this: void, { directory, resolveArt, fallback, radii, stretched }:
|
|
41
|
+
RoundedTextureOptions | RoundedTextureResolverOptions): RoundedTextures {
|
|
42
|
+
const rounded = (radii as OwnedReadonlyArray<number>).filter(radius => radius > 0).sort((left, right) => right - left);
|
|
43
|
+
const square = [0];
|
|
44
|
+
const hasRadiusTwo = rounded.includes(2);
|
|
45
|
+
|
|
46
|
+
function readArt(prefix: string, radius: number, outline: boolean, side?: RoundedTextureSide): TextureAsset | undefined {
|
|
47
|
+
if (resolveArt !== undefined) return resolveArt(radius, outline, side);
|
|
48
|
+
const edge = side === "left" ? "L" : side === "right" ? "R" : "";
|
|
49
|
+
return prefix + radius + edge + (outline ? "Border" : "");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function setArt(texture: SliceTexture, asset: TextureAsset | undefined, margin: number, wrap?: string): boolean {
|
|
53
|
+
if (asset === undefined) return false;
|
|
54
|
+
const found = wrap === undefined ? texture.SetTexture(asset) : texture.SetTexture(asset, wrap, wrap);
|
|
55
|
+
if (found === false) return false;
|
|
56
|
+
if (stretched !== undefined && texture.SetTextureSliceMargins && texture.SetTextureSliceMode) {
|
|
57
|
+
texture.SetTextureSliceMargins(margin, margin, margin, margin);
|
|
58
|
+
texture.SetTextureSliceMode(stretched);
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function tryRound(texture: SliceTexture, radius: number, outline: boolean, side?: RoundedTextureSide, wrap?: string): boolean {
|
|
64
|
+
const candidates = radius <= 0 ? square : rounded;
|
|
65
|
+
let index = candidates.findIndex(candidate => candidate <= radius);
|
|
66
|
+
if (index < 0) index = Math.max(0, candidates.length - 1);
|
|
67
|
+
|
|
68
|
+
const prefix = directory === undefined ? "" : directory() + "Round";
|
|
69
|
+
const first = candidates[index];
|
|
70
|
+
if (first !== undefined && (side === "left" || side === "right")
|
|
71
|
+
&& setArt(texture, readArt(prefix, first, outline, side), first, wrap)) return true;
|
|
72
|
+
|
|
73
|
+
// Keep an outline's faint second pixel outside the stretched center.
|
|
74
|
+
const minimumMargin = outline ? 2 : 1;
|
|
75
|
+
while (index < candidates.length) {
|
|
76
|
+
const candidate = candidates[index];
|
|
77
|
+
if (setArt(texture, readArt(prefix, candidate, outline), Math.max(minimumMargin, candidate), wrap)) return true;
|
|
78
|
+
index++;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Retain the older radius-two fallback after the smallest candidate fails.
|
|
82
|
+
return candidates[candidates.length - 1] === 1 && hasRadiusTwo && setArt(texture, readArt(prefix, 2, outline), 2, wrap);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function setWhite(texture: SliceTexture, wrap?: string): void {
|
|
86
|
+
if (wrap === undefined) texture.SetTexture(fallback());
|
|
87
|
+
else texture.SetTexture(fallback(), wrap, wrap);
|
|
88
|
+
texture.SetTextureSliceMargins?.(0, 0, 0, 0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function apply(this: void, texture: Texture, radius: number, outline = false, side?: RoundedTextureSide): void {
|
|
92
|
+
texture.SetAlpha(1);
|
|
93
|
+
if (tryRound(texture, radius, outline, side)) return;
|
|
94
|
+
setWhite(texture);
|
|
95
|
+
if (outline) texture.SetAlpha(0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function create(this: void, parent: Frame, radius: number, outline?: boolean, layer: Layer = "BACKGROUND", sublevel?: number,
|
|
99
|
+
side?: RoundedTextureSide): Texture {
|
|
100
|
+
const texture = parent.CreateTexture(undefined, layer, undefined, sublevel);
|
|
101
|
+
apply(texture, radius, outline, side);
|
|
102
|
+
return texture;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function applyMask(this: void, mask: FillMask, radius: number): boolean {
|
|
106
|
+
if (stretched === undefined || !rounded.includes(radius) || typeof mask.SetTextureSliceMargins !== "function"
|
|
107
|
+
|| typeof mask.SetTextureSliceMode !== "function") return false;
|
|
108
|
+
const prefix = directory === undefined ? "" : directory() + "Round";
|
|
109
|
+
return setArt(mask, readArt(prefix, radius, false), radius, maskWrap);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Keep the mask anchored to the bar while the native fill changes size. */
|
|
113
|
+
function bindStatusBarFill(this: void, bar: StatusBar, fill: Texture): MaskedStatusBarFill {
|
|
114
|
+
let mask: FillMask | undefined;
|
|
115
|
+
let activeMask: FillMask | undefined;
|
|
116
|
+
let previousRadius: number | undefined;
|
|
117
|
+
let previousSide: RoundedTextureSide | undefined;
|
|
118
|
+
|
|
119
|
+
function setRadius(this: void, radius: number, side?: RoundedTextureSide): FillMask | undefined {
|
|
120
|
+
if (radius === previousRadius && side === previousSide) return activeMask;
|
|
121
|
+
previousRadius = radius;
|
|
122
|
+
previousSide = side;
|
|
123
|
+
|
|
124
|
+
if (radius > 0 && stretched !== undefined && typeof bar.CreateMaskTexture === "function"
|
|
125
|
+
&& typeof fill.AddMaskTexture === "function" && typeof fill.RemoveMaskTexture === "function") {
|
|
126
|
+
if (mask === undefined) {
|
|
127
|
+
mask = bar.CreateMaskTexture();
|
|
128
|
+
mask.SetAllPoints(bar);
|
|
129
|
+
}
|
|
130
|
+
if (typeof mask.SetTextureSliceMargins === "function" && typeof mask.SetTextureSliceMode === "function"
|
|
131
|
+
&& tryRound(mask, radius, false, side, maskWrap)) {
|
|
132
|
+
if (activeMask === undefined) {
|
|
133
|
+
setWhite(fill);
|
|
134
|
+
fill.AddMaskTexture(mask);
|
|
135
|
+
activeMask = mask;
|
|
136
|
+
}
|
|
137
|
+
return activeMask;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (activeMask !== undefined) {
|
|
142
|
+
// Overlays can retain the mask until their next refresh.
|
|
143
|
+
setWhite(activeMask, maskWrap);
|
|
144
|
+
fill.RemoveMaskTexture(activeMask);
|
|
145
|
+
activeMask = undefined;
|
|
146
|
+
}
|
|
147
|
+
if (radius > 0) apply(fill, radius, false, side);
|
|
148
|
+
else setWhite(fill);
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return { setRadius };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { create, apply, applyMask, bindStatusBarFill };
|
|
156
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { fail, ok } from "../src/result";
|
|
2
|
+
import type { StoreStorage } from "@kumi/state";
|
|
3
|
+
import { rawField, setRawField } from "./lua-table";
|
|
4
|
+
import { api, reveal } from "./native";
|
|
5
|
+
|
|
6
|
+
type SavedValue = string | number | boolean;
|
|
7
|
+
|
|
8
|
+
export interface SavedVariablesOptions<State extends Record<string, SavedValue>> {
|
|
9
|
+
global: string;
|
|
10
|
+
key: string;
|
|
11
|
+
defaults: State;
|
|
12
|
+
isReady(this: void): boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Opens one record in a .toc-declared SavedVariables table once the host has loaded it. */
|
|
16
|
+
export function savedVariablesStorage<State extends Record<string, SavedValue>>(
|
|
17
|
+
{ global, key, defaults, isReady }: SavedVariablesOptions<State>,
|
|
18
|
+
): StoreStorage<State> {
|
|
19
|
+
const keys = Object.keys(defaults) as (keyof State & string)[];
|
|
20
|
+
|
|
21
|
+
function root() {
|
|
22
|
+
if (!isReady()) return fail("SavedVariables are not ready: " + global);
|
|
23
|
+
const stored = reveal(rawField(api, global));
|
|
24
|
+
if (stored !== undefined && typeof stored !== "object") return fail("Invalid SavedVariables table: " + global);
|
|
25
|
+
return ok(stored);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function valid<K extends keyof State & string>(field: K, value: unknown): value is State[K] {
|
|
29
|
+
return typeof value === typeof defaults[field] && (typeof value !== "number" || Number.isFinite(value));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
read: () => {
|
|
34
|
+
const opened = root();
|
|
35
|
+
if (!opened.ok) return opened;
|
|
36
|
+
const stored = reveal(rawField(opened.value, key));
|
|
37
|
+
if (stored === undefined) return ok(undefined);
|
|
38
|
+
if (typeof stored !== "object") return fail("Invalid saved store: " + key);
|
|
39
|
+
const result: Partial<State> = {};
|
|
40
|
+
for (const field of keys) {
|
|
41
|
+
const value = reveal(rawField(stored, field));
|
|
42
|
+
if (valid(field, value)) result[field] = value;
|
|
43
|
+
}
|
|
44
|
+
return ok(result);
|
|
45
|
+
},
|
|
46
|
+
write: snapshot => {
|
|
47
|
+
const opened = root();
|
|
48
|
+
if (!opened.ok) return opened;
|
|
49
|
+
const record: Partial<State> = {};
|
|
50
|
+
for (const field of keys) {
|
|
51
|
+
const value = reveal(snapshot[field]);
|
|
52
|
+
if (!valid(field, value)) return fail("Invalid saved value: " + key + "." + field);
|
|
53
|
+
record[field] = value;
|
|
54
|
+
}
|
|
55
|
+
if (opened.value) setRawField(opened.value as object, key, record);
|
|
56
|
+
else setRawField(api, global, { [key]: record });
|
|
57
|
+
return ok(undefined);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { bindValue, type Element, type RuntimeScope } from "../src";
|
|
2
|
+
import type { OwnedRecord } from "../src/owned-collections";
|
|
3
|
+
import { createFrame, type Frame, type FrameMap } from "./frames";
|
|
4
|
+
import { reveal } from "./native";
|
|
5
|
+
|
|
6
|
+
export type ScrollArea = FrameMap["ScrollFrame"] & {
|
|
7
|
+
content: Frame;
|
|
8
|
+
SetContentHeight(this: object, height: number): void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type CreateScrollArea = (this: void, parent: Frame) => ScrollArea;
|
|
12
|
+
|
|
13
|
+
function createDefaultArea(parent: Frame) {
|
|
14
|
+
const viewport = createFrame("ScrollFrame", undefined, parent);
|
|
15
|
+
const content = createFrame("Frame", undefined, viewport);
|
|
16
|
+
content.SetSize(1, 1);
|
|
17
|
+
viewport.SetScrollChild(content);
|
|
18
|
+
viewport.SetScript("OnSizeChanged", (_, width) => {
|
|
19
|
+
const available = reveal(width);
|
|
20
|
+
if (available !== undefined) content.SetWidth(Math.max(1, available));
|
|
21
|
+
});
|
|
22
|
+
viewport.EnableMouseWheel(true);
|
|
23
|
+
viewport.SetScript("OnMouseWheel", (_, raw) => {
|
|
24
|
+
const delta = reveal(raw);
|
|
25
|
+
const current = reveal(viewport.GetVerticalScroll());
|
|
26
|
+
const maximum = reveal(viewport.GetVerticalScrollRange());
|
|
27
|
+
if (delta === undefined || current === undefined || maximum === undefined) return;
|
|
28
|
+
viewport.SetVerticalScroll(Math.max(0, Math.min(maximum, current - delta * 30)));
|
|
29
|
+
});
|
|
30
|
+
return Object.assign(viewport as OwnedRecord<typeof viewport>, {
|
|
31
|
+
content,
|
|
32
|
+
SetContentHeight(this: object, height: number) { content.SetHeight(height); },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function mountScrollView(parent: Frame, scope: RuntimeScope, props: Element<"scrollview">["props"], create?: CreateScrollArea) {
|
|
37
|
+
const frame = create?.(parent) ?? createDefaultArea(parent);
|
|
38
|
+
const failure = bindValue(scope, props.contentHeight, height => {
|
|
39
|
+
const visible = reveal(height);
|
|
40
|
+
if (visible !== undefined && Number.isFinite(visible)) frame.SetContentHeight(Math.max(1, visible));
|
|
41
|
+
});
|
|
42
|
+
if (props.onScroll) frame.HookScript("OnVerticalScroll", (_, raw) => {
|
|
43
|
+
const offset = reveal(raw);
|
|
44
|
+
if (offset !== undefined && scope.isActive()) props.onScroll?.(offset);
|
|
45
|
+
});
|
|
46
|
+
let visible = false;
|
|
47
|
+
const notifyHidden = () => {
|
|
48
|
+
if (!visible) return;
|
|
49
|
+
visible = false;
|
|
50
|
+
props.onHide?.();
|
|
51
|
+
};
|
|
52
|
+
const notifyVisible = () => {
|
|
53
|
+
if (visible || !scope.isActive() || reveal(frame.IsVisible()) !== true) return;
|
|
54
|
+
visible = true;
|
|
55
|
+
props.onShow?.();
|
|
56
|
+
};
|
|
57
|
+
if (props.onShow || props.onHide) {
|
|
58
|
+
frame.HookScript("OnShow", notifyVisible);
|
|
59
|
+
frame.HookScript("OnHide", notifyHidden);
|
|
60
|
+
scope.onDispose(notifyHidden);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return { frame, content: frame.content, failure, notifyVisible };
|
|
64
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ref, type Ref } from "../src/reactivity";
|
|
2
|
+
import { isSecret, type SecretValue } from "./native";
|
|
3
|
+
|
|
4
|
+
/** A secret operand always counts as changed. Compare readable operands normally. */
|
|
5
|
+
export function secretSafeEquals(this: void, previous: unknown, next: unknown): boolean {
|
|
6
|
+
return !isSecret(previous) && !isSecret(next) && previous === next;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const secretRefOptions = { equals: secretSafeEquals };
|
|
10
|
+
|
|
11
|
+
/** Store a client value that may be secret without comparing restricted values. */
|
|
12
|
+
export function nativeRef<T>(this: void, value: T | SecretValue<T>): Ref<T | SecretValue<T>> {
|
|
13
|
+
return ref<T | SecretValue<T>>(value, secretRefOptions);
|
|
14
|
+
}
|