@overmvp/kumi 0.4.0 → 0.5.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/builder/module-declarations.mjs +2 -2
- package/builder/module-declarations.test.mjs +4 -2
- package/package.json +1 -1
- package/router/router-view.ts +5 -3
- package/scripts/addon-build.mjs +2 -0
- package/scripts/kumi-cli.mjs +0 -0
- package/src/elements.ts +11 -1
- package/src/module-ui.ts +4 -0
- package/src/module.ts +14 -4
- package/templates/addon/src/app/app.module.ts +3 -5
- package/templates/addon/src/modules/greeting/greeting.module.ts +2 -2
- package/templates/addon/src/modules/playtime/playtime.module.ts +3 -5
- package/utils/format.ts +13 -0
- package/utils/index.ts +1 -1
- package/wow/animation.ts +16 -4
- package/wow/app-ui.ts +132 -22
- package/wow/aura-container.ts +132 -38
- package/wow/aura-countdown.ts +19 -3
- package/wow/aura-follower.ts +32 -0
- package/wow/aura-view.ts +49 -0
- package/wow/css-box.ts +7 -4
- package/wow/css-surfaces.ts +10 -4
- package/wow/frames.ts +2 -0
- package/wow/hooks.ts +17 -0
- package/wow/hotkeys.ts +221 -0
- package/wow/index.ts +9 -5
- package/wow/initial-view.ts +99 -0
- package/wow/layout-view.ts +1 -1
- package/wow/native.ts +1 -0
- package/wow/pixel.ts +25 -0
- package/wow/scroll-view.ts +5 -4
- package/wow/status-bar.ts +65 -0
- package/wow/unit-button.ts +25 -4
- package/wow/view-nodes.ts +11 -4
- package/wow/view.ts +113 -116
package/wow/hotkeys.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { ownedArray, ownedSet, type OwnedRecord } from "../src/owned-collections";
|
|
2
|
+
import { currentScope } from "../src/reactive-scope";
|
|
3
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
4
|
+
import { canAccessRegion } from "./frame-access";
|
|
5
|
+
import { frameStrata, type FrameStrata } from "./frame-layer";
|
|
6
|
+
import { createFrame, type Frame } from "./frames";
|
|
7
|
+
import { luaString } from "./lua-string";
|
|
8
|
+
import { rawField, setRawField } from "./lua-table";
|
|
9
|
+
import { hookScript } from "./native-hooks";
|
|
10
|
+
import { api, isSecret, reveal } from "./native";
|
|
11
|
+
import { createProtectedLayoutUpdate } from "./protected-layout";
|
|
12
|
+
|
|
13
|
+
type Action = (this: void) => void;
|
|
14
|
+
type FrameHotkeyRef = (this: void, frame?: Frame) => void;
|
|
15
|
+
export type HotkeyActions = Readonly<Record<string, Action>>;
|
|
16
|
+
type HotkeyLookup = OwnedRecord<Record<string, Action | undefined>>;
|
|
17
|
+
|
|
18
|
+
interface HotkeyCondition {
|
|
19
|
+
/** Decide whether this scope accepts input. Read current state here. */
|
|
20
|
+
enabled?(this: void): boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface FrameHotkeyOptions extends HotkeyCondition {
|
|
24
|
+
readonly scope: "frame";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface GlobalHotkeyOptions extends HotkeyCondition {
|
|
28
|
+
readonly scope: "global";
|
|
29
|
+
/** Addon-unique Lua function name that Bindings.xml calls with a command ID. */
|
|
30
|
+
readonly dispatcher: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface FrameHotkeys {
|
|
34
|
+
readonly actions: HotkeyLookup;
|
|
35
|
+
readonly options: FrameHotkeyOptions;
|
|
36
|
+
target?: Frame;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const frames = ownedArray<FrameHotkeys>();
|
|
40
|
+
const held = ownedSet<string>();
|
|
41
|
+
let listener: Frame | undefined;
|
|
42
|
+
|
|
43
|
+
function chord(key: string, alt: boolean, ctrl: boolean, shift: boolean, meta: boolean): string {
|
|
44
|
+
return (alt ? "ALT-" : "") + (ctrl ? "CTRL-" : "") + (shift ? "SHIFT-" : "") + (meta ? "META-" : "") + key;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function normalizeChord(input: string): string | undefined {
|
|
48
|
+
const parts = input.toUpperCase().split("-");
|
|
49
|
+
const key = parts.pop();
|
|
50
|
+
if (key === undefined || luaString.match(key, "^[A-Z0-9_]+$") === undefined) return;
|
|
51
|
+
const modifiers = ownedSet<string>();
|
|
52
|
+
for (const part of parts) {
|
|
53
|
+
if (part !== "ALT" && part !== "CTRL" && part !== "SHIFT" && part !== "META" || modifiers.has(part)) return;
|
|
54
|
+
modifiers.add(part);
|
|
55
|
+
}
|
|
56
|
+
return chord(key, modifiers.has("ALT"), modifiers.has("CTRL"), modifiers.has("SHIFT"), modifiers.has("META"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function collect(actions: HotkeyActions, local: boolean) {
|
|
60
|
+
const lookup = {} as HotkeyLookup;
|
|
61
|
+
for (const [name, action] of Object.entries(actions as OwnedRecord<HotkeyActions>)) {
|
|
62
|
+
const key = local ? normalizeChord(name) : luaString.match(name, "^[A-Za-z0-9_]+$");
|
|
63
|
+
if (key === undefined || lookup[key] !== undefined || typeof action !== "function") throw new Error("Invalid or repeated hotkey: " + name);
|
|
64
|
+
lookup[key] = action;
|
|
65
|
+
}
|
|
66
|
+
return lookup;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function visible(target: Frame | undefined): target is Frame {
|
|
70
|
+
return canAccessRegion(target) && reveal(target.IsVisible()) === true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function foreground(): FrameHotkeys | undefined {
|
|
74
|
+
let highest: FrameHotkeys | undefined;
|
|
75
|
+
let highestStrata = -1;
|
|
76
|
+
let highestLevel = -1;
|
|
77
|
+
for (const entry of frames) {
|
|
78
|
+
const target = entry.target;
|
|
79
|
+
if (!visible(target) || entry.options.enabled?.() === false) continue;
|
|
80
|
+
const strata = frameStrata.indexOf(reveal(target.GetFrameStrata()) as FrameStrata);
|
|
81
|
+
const level = reveal(target.GetFrameLevel());
|
|
82
|
+
if (strata < 0 || level === undefined || strata < highestStrata || strata === highestStrata && level < highestLevel) continue;
|
|
83
|
+
highest = entry;
|
|
84
|
+
highestStrata = strata;
|
|
85
|
+
highestLevel = level;
|
|
86
|
+
}
|
|
87
|
+
return highest;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function refreshListener() {
|
|
91
|
+
const shown = frames.some(entry => visible(entry.target));
|
|
92
|
+
if (!shown) clearHeld();
|
|
93
|
+
listener?.SetShown(shown);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function inputAvailable() {
|
|
97
|
+
if (reveal(api.InCombatLockdown()) !== false) return false;
|
|
98
|
+
const focus = rawField<(this: void) => unknown>(api, "GetCurrentKeyBoardFocus");
|
|
99
|
+
if (focus === undefined) return false;
|
|
100
|
+
const target = focus();
|
|
101
|
+
return !isSecret(target) && target === undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function clearHeld() {
|
|
105
|
+
held.clear();
|
|
106
|
+
listener?.SetScript("OnUpdate");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function releaseKey(this: void, _: Frame, input: string) {
|
|
110
|
+
const key = reveal(input);
|
|
111
|
+
if (key !== undefined) held.delete(key);
|
|
112
|
+
if (held.size === 0) listener?.SetScript("OnUpdate");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function refreshHeld(this: void) {
|
|
116
|
+
// The edit box can consume KeyUp after a shortcut moves focus into it.
|
|
117
|
+
for (const key of held) if (reveal(api.IsKeyDown(key, true)) === false) held.delete(key);
|
|
118
|
+
if (held.size === 0) listener?.SetScript("OnUpdate");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function onKeyDown(this: void, frame: Frame, input: string) {
|
|
122
|
+
const key = reveal(input);
|
|
123
|
+
if (typeof key !== "string" || !inputAvailable() || held.has(key)) return;
|
|
124
|
+
const alt = reveal(api.IsAltKeyDown()), ctrl = reveal(api.IsControlKeyDown());
|
|
125
|
+
const shift = reveal(api.IsShiftKeyDown()), meta = reveal(api.IsMetaKeyDown());
|
|
126
|
+
if (typeof alt !== "boolean" || typeof ctrl !== "boolean" || typeof shift !== "boolean" || typeof meta !== "boolean") return;
|
|
127
|
+
const action = foreground()?.actions[chord(key, alt, ctrl, shift, meta)];
|
|
128
|
+
if (action === undefined) return;
|
|
129
|
+
held.add(key);
|
|
130
|
+
frame.SetScript("OnUpdate", refreshHeld);
|
|
131
|
+
action();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function prepareListener() {
|
|
135
|
+
if (listener === undefined && frames.some(entry => visible(entry.target))) {
|
|
136
|
+
const frame = createFrame("Frame", undefined, api.UIParent);
|
|
137
|
+
frame.Hide();
|
|
138
|
+
frame.EnableMouse(false);
|
|
139
|
+
frame.EnableKeyboard(true);
|
|
140
|
+
frame.SetPropagateKeyboardInput(true);
|
|
141
|
+
if (reveal(frame.GetPropagateKeyboardInput()) !== true) {
|
|
142
|
+
frame.EnableKeyboard(false);
|
|
143
|
+
throw new Error("Could not set keyboard propagation");
|
|
144
|
+
}
|
|
145
|
+
frame.SetScript("OnKeyDown", onKeyDown);
|
|
146
|
+
frame.SetScript("OnKeyUp", releaseKey);
|
|
147
|
+
listener = frame;
|
|
148
|
+
}
|
|
149
|
+
refreshListener();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function requireSuccess(result: { ok: true } | { ok: false; reason: string }) {
|
|
153
|
+
if (!result.ok) throw new Error(result.reason);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function scopedHotkeys(scope: RuntimeScope, actions: FrameHotkeys["actions"], options: FrameHotkeyOptions): FrameHotkeyRef {
|
|
157
|
+
const entry: FrameHotkeys = { actions, options };
|
|
158
|
+
const update = createProtectedLayoutUpdate(prepareListener, { scope, label: "Hotkey listener" });
|
|
159
|
+
if (!update.ok) throw new Error(update.reason);
|
|
160
|
+
const { request } = update.value;
|
|
161
|
+
let attachment: RuntimeScope | undefined;
|
|
162
|
+
function refresh() {
|
|
163
|
+
if (listener === undefined) requireSuccess(request());
|
|
164
|
+
else refreshListener();
|
|
165
|
+
}
|
|
166
|
+
requireSuccess(scope.onDispose(() => {
|
|
167
|
+
const index = frames.indexOf(entry);
|
|
168
|
+
if (index >= 0) frames.splice(index, 1);
|
|
169
|
+
entry.target = undefined;
|
|
170
|
+
refreshListener();
|
|
171
|
+
}));
|
|
172
|
+
frames.push(entry);
|
|
173
|
+
return frame => {
|
|
174
|
+
if (!scope.isActive() || frame === entry.target) return;
|
|
175
|
+
if (attachment !== undefined) requireSuccess(attachment.dispose());
|
|
176
|
+
attachment = undefined;
|
|
177
|
+
const target = frame !== undefined && canAccessRegion(frame) ? frame : undefined;
|
|
178
|
+
entry.target = undefined;
|
|
179
|
+
if (target !== undefined) {
|
|
180
|
+
const own = scope.fork();
|
|
181
|
+
const shown = hookScript(target, "OnShow", refresh, own);
|
|
182
|
+
const hidden = shown.ok ? hookScript(target, "OnHide", refresh, own) : shown;
|
|
183
|
+
if (!hidden.ok) {
|
|
184
|
+
own.dispose();
|
|
185
|
+
refresh();
|
|
186
|
+
throw new Error(hidden.reason);
|
|
187
|
+
}
|
|
188
|
+
attachment = own;
|
|
189
|
+
entry.target = target;
|
|
190
|
+
}
|
|
191
|
+
refresh();
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function globalHotkeys(scope: RuntimeScope, actions: FrameHotkeys["actions"], options: GlobalHotkeyOptions): void {
|
|
196
|
+
const name = options.dispatcher;
|
|
197
|
+
if (luaString.match(name, "^[A-Za-z_][A-Za-z0-9_]*$") === undefined) throw new Error("Invalid hotkey dispatcher name");
|
|
198
|
+
const existing = rawField(api, name);
|
|
199
|
+
if (isSecret(existing) || existing !== undefined) throw new Error("Hotkey dispatcher name is already in use: " + name);
|
|
200
|
+
|
|
201
|
+
function dispatch(this: void, id: unknown) {
|
|
202
|
+
if (isSecret(id) || typeof id !== "string" || !scope.isActive() || options.enabled?.() === false) return;
|
|
203
|
+
const action = actions[id];
|
|
204
|
+
action?.();
|
|
205
|
+
}
|
|
206
|
+
requireSuccess(scope.onDispose(() => {
|
|
207
|
+
if (reveal(rawField(api, name)) === dispatch) setRawField(api, name, undefined);
|
|
208
|
+
}));
|
|
209
|
+
setRawField(api, name, dispatch);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Observe chords on the foremost bound frame, or dispatch player-assigned WoW bindings. */
|
|
213
|
+
export function useHotkeys(this: void, actions: HotkeyActions, options: FrameHotkeyOptions): FrameHotkeyRef;
|
|
214
|
+
export function useHotkeys(this: void, actions: HotkeyActions, options: GlobalHotkeyOptions): void;
|
|
215
|
+
export function useHotkeys(this: void, actions: HotkeyActions, options: FrameHotkeyOptions | GlobalHotkeyOptions): FrameHotkeyRef | void {
|
|
216
|
+
const scope = currentScope();
|
|
217
|
+
if (scope === undefined || !scope.isActive()) throw new Error("useHotkeys requires an active scope");
|
|
218
|
+
const lookup = collect(actions, options.scope === "frame");
|
|
219
|
+
if (options.scope === "frame") return scopedHotkeys(scope, lookup, options);
|
|
220
|
+
globalHotkeys(scope, lookup, options);
|
|
221
|
+
}
|
package/wow/index.ts
CHANGED
|
@@ -57,28 +57,31 @@ export { createClassColorLookup, readClassColor, type ClassColorLookup } from ".
|
|
|
57
57
|
export { bindAuraDispelTexture, configureAuraMouse } from "./aura-button";
|
|
58
58
|
export type { AuraDispelColorMap, AuraDispelTextureOptions, AuraTooltipMode } from "./aura-button";
|
|
59
59
|
export { createAuraContainer } from "./aura-container";
|
|
60
|
+
export { mountAuraButton, type AuraButtonRegions } from "./aura-view";
|
|
60
61
|
export { bindAuraDurationText, bindAuraStackText, setAuraCountdownFormat, type AuraDurationTextOptions, type AuraStackTextOptions } from "./aura-countdown";
|
|
61
62
|
export { createAuraSlot, type AuraSlot, type AuraSlotOptions } from "./aura-slot";
|
|
62
63
|
export { createHealPrediction, type HealPrediction, type HealPredictionLook, type HealPredictionOptions, type HealPredictionStyle } from "./heal-prediction";
|
|
63
64
|
export { openColorPicker, type ColorPickerOptions } from "./color-picker";
|
|
64
|
-
export type { AuraButton, AuraCandidateFilters, AuraContainer, AuraContainerGroup, AuraContainerOptions, AuraContainerSlot, AuraGroupFilter } from "./aura-container";
|
|
65
|
+
export type { AuraButton, AuraCandidateFilters, AuraContainer, AuraContainerGroup, AuraContainerOptions, AuraContainerSlot, AuraFlowLayout, AuraGroupFilter } from "./aura-container";
|
|
66
|
+
export { anchorAuraFollower } from "./aura-follower";
|
|
65
67
|
export { findSlashCommand } from "./commands";
|
|
66
68
|
export { macroBook } from "./macro-book";
|
|
67
69
|
export { createWoWCVars, cvars, rawCVars } from "./cvars";
|
|
68
70
|
export type { WoWCVarEntry, WoWCVarInfo, WoWRawCVars } from "./cvars";
|
|
69
71
|
export { wowCVarSchema } from "./cvar-schema";
|
|
70
72
|
export type { WoWCVarName, WoWCVarSchema, WoWCVarValue } from "./cvar-schema";
|
|
71
|
-
export { configureAnimations, createAnimation, createTicker, playWhileVisible, useAnimation } from "./animation";
|
|
73
|
+
export { configureAnimations, createAnimation, createTicker, playWhileVisible, useAnimation, useAnimationWhile } from "./animation";
|
|
72
74
|
export type { AnimationControl, AnimationDefaults, AnimationPlayback, AnimationRef, AnimationRefOptions, AnimationTarget, MotionMode,
|
|
73
75
|
NativeAnimationOptions, PlayOptions, StepPatch, TargetOf, Ticker } from "./animation";
|
|
74
|
-
export {
|
|
76
|
+
export { statusBarValue } from "./status-bar";
|
|
77
|
+
export { applyFrameScale, mountNative, mountNativeRangeArt } from "./view";
|
|
75
78
|
export type { NativeRootLayer, NativeViewOptions } from "./view";
|
|
76
79
|
export type { NativeLayoutDiagnostics } from "./layout-view";
|
|
77
80
|
export type { FrameStrata } from "./frame-layer";
|
|
78
81
|
export type { CreateScrollArea, ScrollArea } from "./scroll-view";
|
|
79
82
|
export { protect } from "./protect";
|
|
80
83
|
export { luaString } from "./lua-string";
|
|
81
|
-
export { physicalPixel, snapPixel, watchDisplayMetrics } from "./pixel";
|
|
84
|
+
export { physicalPixel, snapPixel, useFramePixel, watchDisplayMetrics } from "./pixel";
|
|
82
85
|
export { formatWoWNumber } from "./number-format";
|
|
83
86
|
export { clampWoWNumber } from "./number-input";
|
|
84
87
|
export { formatMapCoordinates, readPlayerMapPosition } from "./map-position";
|
|
@@ -86,7 +89,8 @@ export { rawField, setRawField, weakKeys } from "./lua-table";
|
|
|
86
89
|
export { savedVariablesStorage, type SavedRecord, type SavedValue, type SavedVariablesOptions } from "./saved-variables";
|
|
87
90
|
export { usePlugins, type KumiPlugins, type PluginId, type PluginInfo, type PluginServices, type PluginStatus } from "./plugins";
|
|
88
91
|
export { useViewHost, useWindow, type AppTheme } from "./app-ui";
|
|
89
|
-
export { onCleanup, useCombat, useEvent, useNow, useSlashCommand } from "./hooks";
|
|
92
|
+
export { onCleanup, useCombat, useEvent, useNow, useScreenSize, useSlashCommand } from "./hooks";
|
|
93
|
+
export { useHotkeys, type FrameHotkeyOptions, type GlobalHotkeyOptions, type HotkeyActions } from "./hotkeys";
|
|
90
94
|
export type { EventApi, EventOptions, EventScope, WoWEvent, WoWEventMap } from "./contract";
|
|
91
95
|
|
|
92
96
|
declare const DoReadyCheck: ((this: void) => void) | undefined;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ownedArray, ownedSet, type OwnedReadonlyArray } from "../src/owned-collections";
|
|
2
|
+
import { withReactiveScope } from "../src/reactive-scope";
|
|
3
|
+
import { fail, type Failure } from "../src/result";
|
|
4
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
5
|
+
import type { Job } from "../src/scheduler";
|
|
6
|
+
|
|
7
|
+
/** Hold the first layout until the whole initial tree is available. */
|
|
8
|
+
export function initialLayoutQueue() {
|
|
9
|
+
const jobs = ownedSet<Job>();
|
|
10
|
+
let pending: OwnedReadonlyArray<Job> | undefined;
|
|
11
|
+
let index = 0;
|
|
12
|
+
let pass = 0;
|
|
13
|
+
let collecting = true;
|
|
14
|
+
|
|
15
|
+
function stop() {
|
|
16
|
+
collecting = false;
|
|
17
|
+
pending = undefined;
|
|
18
|
+
jobs.clear();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function step(): true | Failure | undefined {
|
|
22
|
+
if (pending !== undefined && index < pending.length) {
|
|
23
|
+
const job = pending[index++];
|
|
24
|
+
jobs.delete(job);
|
|
25
|
+
return job() ?? true;
|
|
26
|
+
}
|
|
27
|
+
if (jobs.size === 0) { stop(); return; }
|
|
28
|
+
if (++pass > 16) { stop(); return fail("Initial native layout did not settle"); }
|
|
29
|
+
const snapshot = ownedArray<Job>();
|
|
30
|
+
for (const job of jobs) snapshot.push(job);
|
|
31
|
+
pending = snapshot;
|
|
32
|
+
index = 0;
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
stage: (job: Job) => {
|
|
38
|
+
if (collecting) jobs.add(job);
|
|
39
|
+
return collecting;
|
|
40
|
+
},
|
|
41
|
+
step,
|
|
42
|
+
stop,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface InitialViewStages {
|
|
47
|
+
accepts(this: void): boolean;
|
|
48
|
+
push(this: void, owner: RuntimeScope, job: Job): void;
|
|
49
|
+
start(this: void): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Drain the native children in mount order. First layout runs only after the last child. */
|
|
53
|
+
export function stageInitialView(this: void, scope: RuntimeScope, layout: ReturnType<typeof initialLayoutQueue>,
|
|
54
|
+
complete: (this: void, failure?: Failure) => void | Failure): InitialViewStages {
|
|
55
|
+
const jobs = ownedArray<{ readonly owner: RuntimeScope; readonly run: Job }>();
|
|
56
|
+
const key = {};
|
|
57
|
+
let mounting = true;
|
|
58
|
+
|
|
59
|
+
function finish(failure?: Failure) {
|
|
60
|
+
mounting = false;
|
|
61
|
+
if (failure !== undefined) scope.dispose();
|
|
62
|
+
return complete(failure);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function advance() {
|
|
66
|
+
for (let count = 0; count < 32 && (count === 0 || scope.frameJobs.remainingMs() > 0); count++) {
|
|
67
|
+
if (!scope.isActive()) return;
|
|
68
|
+
if (mounting) {
|
|
69
|
+
const item = jobs.pop();
|
|
70
|
+
if (item === undefined) {
|
|
71
|
+
mounting = false;
|
|
72
|
+
return true; // Give layout its own frame budget.
|
|
73
|
+
}
|
|
74
|
+
if (!item.owner.isActive()) continue;
|
|
75
|
+
const result = withReactiveScope(item.owner, item.run);
|
|
76
|
+
const failure = result.ok ? result.value : result;
|
|
77
|
+
if (failure !== undefined) return finish(failure);
|
|
78
|
+
} else {
|
|
79
|
+
const result = scope.protect(layout.step);
|
|
80
|
+
const step = result.ok ? result.value : result;
|
|
81
|
+
if (step === true) continue;
|
|
82
|
+
return finish(step);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
scope.onDispose(() => {
|
|
89
|
+
mounting = false;
|
|
90
|
+
jobs.length = 0;
|
|
91
|
+
layout.stop();
|
|
92
|
+
scope.frameJobs.cancel(key);
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
accepts: () => mounting,
|
|
96
|
+
push: (owner, run) => { jobs.push({ owner, run }); },
|
|
97
|
+
start: () => { scope.frameJobs.queue(key, advance, { lane: "user", label: "Initial window view" }); },
|
|
98
|
+
};
|
|
99
|
+
}
|
package/wow/layout-view.ts
CHANGED
|
@@ -549,7 +549,7 @@ export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, p
|
|
|
549
549
|
let lastFailure: string | undefined;
|
|
550
550
|
let root: NativeLayoutItem;
|
|
551
551
|
const visibility = new Set<NativeLayoutItem>() as OwnedSet<NativeLayoutItem>;
|
|
552
|
-
const initial = stageInitial === undefined ? undefined : () => layout(true);
|
|
552
|
+
const initial = stageInitial === undefined ? undefined : () => scope.isActive() ? layout(true) : undefined;
|
|
553
553
|
const enqueue = () => {
|
|
554
554
|
if (!scope.isActive() || waiting) return;
|
|
555
555
|
if (initial !== undefined && stageInitial?.(initial) === true) return;
|
package/wow/native.ts
CHANGED
|
@@ -63,6 +63,7 @@ interface LegacyGlobals {
|
|
|
63
63
|
]>;
|
|
64
64
|
GetInventoryItemTexture?(this: void, unit: string, slot: number): number | string | SecretValue<number | string> | undefined;
|
|
65
65
|
IsInRaid(this: void, category?: number): boolean;
|
|
66
|
+
UnitHasIncomingResurrection?(this: void, unit: string): boolean | SecretValue<boolean>;
|
|
66
67
|
readonly RAID_CLASS_COLORS?: Readonly<Partial<Record<string, { readonly r: number; readonly g: number; readonly b: number }>>>;
|
|
67
68
|
readonly SlashCmdList?: Record<string, (this: void, input: string) => void>;
|
|
68
69
|
readonly TooltipDataProcessor?: {
|
package/wow/pixel.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { currentScope } from "../src/reactive-scope";
|
|
2
|
+
import { ref } from "../src/reactivity";
|
|
1
3
|
import { ok } from "../src/result";
|
|
2
4
|
import type { RuntimeScope } from "../src/runtime";
|
|
3
5
|
import { createEventDispatcher } from "./event-dispatcher";
|
|
@@ -33,3 +35,26 @@ export function watchDisplayMetrics(this: void, scope: RuntimeScope, refresh: (t
|
|
|
33
35
|
if (!size.ok) { scale.value(); return size; }
|
|
34
36
|
return ok(undefined);
|
|
35
37
|
}
|
|
38
|
+
|
|
39
|
+
/** Follow the display pixel in an owned frame's local units. Read the frame's authored scale in readScale. */
|
|
40
|
+
export function useFramePixel(this: void, readScale: (this: void) => number) {
|
|
41
|
+
const scope = currentScope();
|
|
42
|
+
if (scope === undefined) throw new Error("useFramePixel needs an active scope");
|
|
43
|
+
const pixel = ref(1);
|
|
44
|
+
let frame: Pick<Frame, "GetEffectiveScale"> | undefined;
|
|
45
|
+
|
|
46
|
+
function refresh(this: void): void {
|
|
47
|
+
if (frame !== undefined) pixel.value = physicalPixel(frame);
|
|
48
|
+
}
|
|
49
|
+
function schedule(this: void): void { scope?.nextTick(refresh); }
|
|
50
|
+
function bind(this: void, value?: Pick<Frame, "GetEffectiveScale">): void {
|
|
51
|
+
frame = value;
|
|
52
|
+
refresh();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const subscription = watchDisplayMetrics(scope, schedule);
|
|
56
|
+
if (!subscription.ok) throw new Error(subscription.reason);
|
|
57
|
+
const scaled = scope.watch(readScale, schedule);
|
|
58
|
+
if (!scaled.ok) throw new Error(scaled.reason);
|
|
59
|
+
return { pixel, refresh, bind };
|
|
60
|
+
}
|
package/wow/scroll-view.ts
CHANGED
|
@@ -10,12 +10,12 @@ export type ScrollArea = FrameMap["ScrollFrame"] & {
|
|
|
10
10
|
|
|
11
11
|
export type CreateScrollArea = (this: void, parent: Frame) => ScrollArea;
|
|
12
12
|
|
|
13
|
-
function createDefaultArea(parent: Frame) {
|
|
13
|
+
function createDefaultArea(parent: Frame, layoutOwnsWidth: boolean) {
|
|
14
14
|
const viewport = createFrame("ScrollFrame", undefined, parent);
|
|
15
15
|
const content = createFrame("Frame", undefined, viewport);
|
|
16
16
|
content.SetSize(1, 1);
|
|
17
17
|
viewport.SetScrollChild(content);
|
|
18
|
-
viewport.SetScript("OnSizeChanged", (_, width) => {
|
|
18
|
+
if (!layoutOwnsWidth) viewport.SetScript("OnSizeChanged", (_, width) => {
|
|
19
19
|
const available = reveal(width);
|
|
20
20
|
if (available !== undefined) content.SetWidth(Math.max(1, available));
|
|
21
21
|
});
|
|
@@ -33,8 +33,9 @@ function createDefaultArea(parent: Frame) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function mountScrollView(parent: Frame, scope: RuntimeScope, props: Element<"scrollview">["props"], create?: CreateScrollArea
|
|
37
|
-
|
|
36
|
+
export function mountScrollView(parent: Frame, scope: RuntimeScope, props: Element<"scrollview">["props"], create?: CreateScrollArea,
|
|
37
|
+
layoutOwnsWidth = false) {
|
|
38
|
+
const frame = create?.(parent) ?? createDefaultArea(parent, layoutOwnsWidth);
|
|
38
39
|
const failure = bindValue(scope, props.contentHeight, height => {
|
|
39
40
|
const visible = reveal(height);
|
|
40
41
|
if (visible !== undefined && Number.isFinite(visible)) frame.SetContentHeight(Math.max(1, visible));
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Binding, Element, RuntimeScope, StatusBarValue } from "../src";
|
|
2
|
+
import { ok, type Failure, type Result } from "../src/result";
|
|
3
|
+
import type { StatusBar } from "./frames";
|
|
4
|
+
import { api } from "./native";
|
|
5
|
+
|
|
6
|
+
type StatusBarProps = Element<"statusbar">["props"];
|
|
7
|
+
type NativeValue = Parameters<StatusBar["SetValue"]>[0];
|
|
8
|
+
|
|
9
|
+
/** Box a WoW number so application refs can publish it without comparing the number. */
|
|
10
|
+
export function statusBarValue(this: void, value: NativeValue): StatusBarValue {
|
|
11
|
+
return { nativeValue: value } as StatusBarValue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function readBinding(binding: Binding<number>): Result<number>;
|
|
15
|
+
function readBinding(binding: Binding<StatusBarValue>): Result<StatusBarValue>;
|
|
16
|
+
function readBinding(binding: Binding<StatusBarValue>): Result<StatusBarValue> {
|
|
17
|
+
if (typeof binding === "number" || "nativeValue" in binding) return ok(binding);
|
|
18
|
+
const value = binding.value;
|
|
19
|
+
return typeof value === "object" && "ok" in value ? value : ok(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function unwrap(value: StatusBarValue): NativeValue {
|
|
23
|
+
return typeof value === "number" ? value : value.nativeValue as NativeValue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function bindStatusBar(this: void, scope: RuntimeScope, bar: StatusBar,
|
|
27
|
+
{ min, max, value, smooth, resetKey = 0 }: StatusBarProps, reduceMotion?: (this: void) => boolean): Failure | undefined {
|
|
28
|
+
const nativeInterpolation = smooth === true ? api.Enum?.StatusBarInterpolation?.ExponentialEaseOut : undefined;
|
|
29
|
+
let previousMin: StatusBarValue | undefined;
|
|
30
|
+
let previousMax: StatusBarValue | undefined;
|
|
31
|
+
let previousValue: StatusBarValue | undefined;
|
|
32
|
+
let previousKey: number | undefined;
|
|
33
|
+
let wasSmoothing = false;
|
|
34
|
+
const subscription = scope.watchEffect(() => {
|
|
35
|
+
const nextMin = readBinding(min);
|
|
36
|
+
const nextMax = readBinding(max);
|
|
37
|
+
const nextValue = readBinding(value);
|
|
38
|
+
const nextKey = readBinding(resetKey);
|
|
39
|
+
if (!nextMin.ok) return nextMin;
|
|
40
|
+
if (!nextMax.ok) return nextMax;
|
|
41
|
+
if (!nextValue.ok) return nextValue;
|
|
42
|
+
if (!nextKey.ok) return nextKey;
|
|
43
|
+
|
|
44
|
+
// Compare only readable bounds and wrapper identities. Native setters consume the payloads.
|
|
45
|
+
const boundsChanged = previousMin !== nextMin.value || previousMax !== nextMax.value;
|
|
46
|
+
const canSmooth = nativeInterpolation !== undefined && reduceMotion?.() !== true;
|
|
47
|
+
const reset = boundsChanged || previousKey !== nextKey.value;
|
|
48
|
+
if (boundsChanged) bar.SetMinMaxValues(unwrap(nextMin.value), unwrap(nextMax.value));
|
|
49
|
+
if (reset || previousValue !== nextValue.value || (wasSmoothing && !canSmooth)) {
|
|
50
|
+
const interpolate = canSmooth && !reset;
|
|
51
|
+
if (interpolate) {
|
|
52
|
+
bar.SetValue(unwrap(nextValue.value), nativeInterpolation);
|
|
53
|
+
} else {
|
|
54
|
+
bar.SetValue(unwrap(nextValue.value));
|
|
55
|
+
if (wasSmoothing) bar.SetToTargetValue?.();
|
|
56
|
+
}
|
|
57
|
+
wasSmoothing = interpolate;
|
|
58
|
+
}
|
|
59
|
+
previousMin = nextMin.value;
|
|
60
|
+
previousMax = nextMax.value;
|
|
61
|
+
previousValue = nextValue.value;
|
|
62
|
+
previousKey = nextKey.value;
|
|
63
|
+
});
|
|
64
|
+
return subscription.ok ? undefined : subscription;
|
|
65
|
+
}
|
package/wow/unit-button.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { fail, type Result } from "../src/result";
|
|
1
|
+
import { fail, type Failure, type Result } from "../src/result";
|
|
2
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
2
3
|
import { createFrame, type Button, type FrameParent } from "./frames";
|
|
4
|
+
import { luaString } from "./lua-string";
|
|
3
5
|
import { api, isSecret } from "./native";
|
|
4
6
|
import { protect } from "./protect";
|
|
7
|
+
import { stateDriver } from "./secure-state";
|
|
5
8
|
|
|
6
9
|
export interface SecureUnitButtonOptions {
|
|
7
10
|
unit: string;
|
|
@@ -13,6 +16,26 @@ const secureTemplate = "SecureUnitButtonTemplate";
|
|
|
13
16
|
const pingTemplate = "PingableUnitFrameTemplate";
|
|
14
17
|
let unitTemplate: string | undefined;
|
|
15
18
|
|
|
19
|
+
function configureUnit(button: Button, unit: string, menu: boolean) {
|
|
20
|
+
button.SetAttribute("unit", unit);
|
|
21
|
+
button.SetAttribute("*type1", "target");
|
|
22
|
+
if (menu) button.SetAttribute("*type2", "togglemenu");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Configure the secure button allocated by the JSX renderer. */
|
|
26
|
+
export function bindSecureUnit(button: Button, scope: RuntimeScope, unit: string, menu = false): Failure | undefined {
|
|
27
|
+
if (isSecret(unit) || typeof unit !== "string" || luaString.match(unit, "^[a-z][a-z0-9]*$") === undefined) {
|
|
28
|
+
return fail("A secure unit button needs a readable unit token");
|
|
29
|
+
}
|
|
30
|
+
configureUnit(button, unit, menu);
|
|
31
|
+
const clicks = button as Button & { SetAttribute(this: object, key: string, value: boolean): void };
|
|
32
|
+
clicks.SetAttribute("useOnKeyDown", false);
|
|
33
|
+
button.RegisterForClicks("LeftButtonUp", "RightButtonUp");
|
|
34
|
+
button.Hide();
|
|
35
|
+
const visibility = stateDriver(button, "visibility", "[@" + unit + ",exists] show; hide", { scope });
|
|
36
|
+
return visibility.ok ? undefined : visibility;
|
|
37
|
+
}
|
|
38
|
+
|
|
16
39
|
function templateFor(pingable: boolean) {
|
|
17
40
|
if (!pingable) return secureTemplate;
|
|
18
41
|
if (unitTemplate === undefined) {
|
|
@@ -30,9 +53,7 @@ export function createSecureUnitButton(this: void, parent: FrameParent, { unit,
|
|
|
30
53
|
return protect(() => {
|
|
31
54
|
const button = createFrame("Button", name, parent, templateFor(pingable));
|
|
32
55
|
// The ping mixin must resolve the token from the secure attribute.
|
|
33
|
-
button
|
|
34
|
-
button.SetAttribute("*type1", "target");
|
|
35
|
-
button.SetAttribute("*type2", "togglemenu");
|
|
56
|
+
configureUnit(button, unit, true);
|
|
36
57
|
button.RegisterForClicks("AnyUp");
|
|
37
58
|
return button;
|
|
38
59
|
});
|
package/wow/view-nodes.ts
CHANGED
|
@@ -295,10 +295,17 @@ export function mountViewNode<Kind extends MountedElementKind>(this: void, scope
|
|
|
295
295
|
return node;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
|
|
299
|
-
|
|
298
|
+
/** Clear an attached ref even if its callback disposes the view synchronously. */
|
|
299
|
+
export function attachViewRef<Value>(this: void, scope: RuntimeScope, ref: ((this: void, value?: Value) => void) | undefined,
|
|
300
|
+
value: (this: void) => Value): Failure | undefined {
|
|
300
301
|
if (ref === undefined) return;
|
|
301
|
-
const
|
|
302
|
+
const cleanup = scope.onDispose(() => ref(undefined));
|
|
303
|
+
if (!cleanup.ok) return cleanup;
|
|
304
|
+
const exposed = scope.protect(() => ref(value()));
|
|
302
305
|
if (!exposed.ok) return exposed;
|
|
303
|
-
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function finishViewNode<Kind extends MountedElementKind>(this: void, scope: RuntimeScope, node: LogicalNode<Kind>,
|
|
309
|
+
ref?: (this: void, value?: KumiNode<Kind>) => void): Failure | undefined {
|
|
310
|
+
if (ref !== undefined) return attachViewRef(scope, ref, () => expose(node));
|
|
304
311
|
}
|