@overmvp/kumi 0.3.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/animation/index.ts +4 -0
- package/animation/motion-policy.ts +20 -0
- package/animation/slide.ts +61 -0
- package/animation/spring.ts +75 -0
- package/animation/staggered-reveal.ts +34 -0
- package/builder/css-gradients.mjs +74 -0
- package/builder/css-mask-assets.mjs +52 -0
- package/builder/css-mask-assets.test.mjs +31 -0
- package/builder/css-v1.mjs +73 -22
- package/builder/css-v1.test.mjs +42 -2
- package/builder/module-declarations.mjs +2 -2
- package/builder/module-declarations.test.mjs +4 -2
- package/builder/src/compiler.rs +25 -0
- package/builder/src/lua_upvalues.rs +641 -0
- package/builder/src/main.rs +1 -0
- package/builder/style-modules.mjs +21 -3
- package/builder/style-modules.test.mjs +24 -0
- package/builder/style-states.mjs +6 -4
- package/package.json +1 -1
- package/router/index.ts +1 -0
- package/router/link.tsx +32 -0
- package/router/router-view.ts +5 -3
- package/scripts/addon-build.mjs +17 -2
- package/scripts/addon-project.mjs +22 -11
- package/scripts/kumi-cli.mjs +0 -0
- package/src/bindings.ts +10 -4
- package/src/context.ts +31 -7
- package/src/css-tokens.ts +11 -2
- package/src/css-v1.ts +3 -0
- package/src/elements.ts +20 -1
- package/src/flex-layout.ts +26 -5
- package/src/frame-scheduler.ts +3 -1
- package/src/index.ts +2 -2
- package/src/keyed-list.ts +9 -6
- package/src/module-ui.ts +22 -2
- package/src/module.ts +26 -7
- package/src/reactivity.ts +14 -1
- package/src/style-classes.ts +22 -1
- package/src/style-states.ts +13 -6
- package/state/setup-store.ts +3 -3
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +1 -1
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +1 -1
- package/templates/addon/AGENTS.md +1 -1
- package/templates/addon/kumi.config.ts +17 -17
- package/templates/addon/src/app/app.module.ts +3 -5
- package/templates/addon/src/app/layout/{AppWindow.module.scss → AppWindow.module.css} +10 -12
- package/templates/addon/src/modules/greeting/greeting.module.ts +2 -2
- package/templates/addon/src/modules/greeting/ui/{Greeting.module.scss → Greeting.module.css} +9 -11
- package/templates/addon/src/modules/playtime/playtime.module.ts +3 -5
- package/templates/addon/src/modules/playtime/ui/{Playtime.module.scss → Playtime.module.css} +3 -5
- package/templates/addon/src/shared/styles/tokens.css +13 -0
- package/templates/addon/src/shared/ui/{Controls.module.scss → Controls.module.css} +18 -20
- package/utils/format.ts +13 -0
- package/utils/index.ts +1 -1
- package/wow/action-button.ts +26 -1
- package/wow/addon-manifest.ts +2 -0
- package/wow/animation.ts +19 -18
- package/wow/app-ui.ts +150 -31
- 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-background-image.ts +75 -0
- package/wow/css-box.ts +14 -9
- package/wow/css-image-mask.ts +32 -0
- package/wow/css-surfaces.ts +88 -35
- package/wow/element-events.ts +33 -13
- package/wow/frames.ts +2 -0
- package/wow/heal-prediction.ts +2 -4
- package/wow/hooks.ts +17 -0
- package/wow/hotkeys.ts +221 -0
- package/wow/index.ts +11 -6
- package/wow/initial-view.ts +99 -0
- package/wow/layout-view.ts +19 -10
- package/wow/module-replacements.ts +103 -0
- package/wow/native.ts +1 -0
- package/wow/pixel.ts +25 -0
- package/wow/pointer-click.ts +35 -0
- package/wow/protected-view.ts +49 -13
- package/wow/rounded-texture.ts +9 -4
- package/wow/scroll-view.ts +5 -4
- package/wow/state-paint.ts +5 -14
- package/wow/status-bar.ts +65 -0
- package/wow/texture-fill.ts +10 -0
- package/wow/unit-button.ts +25 -4
- package/wow/unit-cast.ts +6 -4
- package/wow/view-nodes.ts +11 -4
- package/wow/view.ts +387 -278
- package/templates/addon/src/shared/styles/_tokens.scss +0 -12
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
@use "../styles/tokens" as *;
|
|
2
|
-
|
|
3
1
|
.button {
|
|
4
2
|
height: 28px;
|
|
5
3
|
min-width: 72px;
|
|
6
|
-
border: 1px solid
|
|
4
|
+
border: 1px solid var(--color-line);
|
|
7
5
|
border-radius: 4px;
|
|
8
|
-
background-color:
|
|
6
|
+
background-color: var(--color-control);
|
|
9
7
|
font-size: 14px;
|
|
10
|
-
color:
|
|
8
|
+
color: var(--color-text);
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
.button:hover { background-color:
|
|
14
|
-
.button:checked { background-color:
|
|
11
|
+
.button:hover { background-color: var(--color-raised); }
|
|
12
|
+
.button:checked { background-color: var(--color-selected); border-color: var(--color-gold); }
|
|
15
13
|
.button:disabled { opacity: 0.55; }
|
|
16
14
|
|
|
17
15
|
.primary {
|
|
18
16
|
height: 28px;
|
|
19
17
|
min-width: 96px;
|
|
20
|
-
border: 1px solid
|
|
18
|
+
border: 1px solid var(--color-gold);
|
|
21
19
|
border-radius: 4px;
|
|
22
|
-
background-color:
|
|
20
|
+
background-color: var(--color-gold-dark);
|
|
23
21
|
font-size: 14px;
|
|
24
|
-
color:
|
|
22
|
+
color: var(--color-text);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
.primary:hover { background-color: #ad7528; }
|
|
@@ -36,18 +34,18 @@
|
|
|
36
34
|
.glyph {
|
|
37
35
|
width: 16px;
|
|
38
36
|
height: 16px;
|
|
39
|
-
color:
|
|
37
|
+
color: var(--color-muted);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
.switch {
|
|
43
41
|
width: 46px;
|
|
44
42
|
height: 22px;
|
|
45
|
-
border: 1px solid
|
|
43
|
+
border: 1px solid var(--color-edge);
|
|
46
44
|
border-radius: 11px;
|
|
47
|
-
background-color:
|
|
45
|
+
background-color: var(--color-control);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
.switch:checked { border-color:
|
|
48
|
+
.switch:checked { border-color: var(--color-gold); background-color: var(--color-selected); }
|
|
51
49
|
.switch:disabled { opacity: 0.55; }
|
|
52
50
|
|
|
53
51
|
.knobOff, .knobOn {
|
|
@@ -57,8 +55,8 @@
|
|
|
57
55
|
height: 16px;
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
.knobOff { left: 3px; color:
|
|
61
|
-
.knobOn { right: 3px; color:
|
|
58
|
+
.knobOff { left: 3px; color: var(--color-muted); }
|
|
59
|
+
.knobOn { right: 3px; color: var(--color-gold); }
|
|
62
60
|
|
|
63
61
|
.choice {
|
|
64
62
|
display: flex;
|
|
@@ -72,22 +70,22 @@
|
|
|
72
70
|
|
|
73
71
|
.track {
|
|
74
72
|
height: 6px;
|
|
75
|
-
background-color:
|
|
73
|
+
background-color: var(--color-line);
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
.fill {
|
|
79
77
|
height: 6px;
|
|
80
|
-
background-color:
|
|
78
|
+
background-color: var(--color-gold);
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
.thumb {
|
|
84
82
|
width: 16px;
|
|
85
83
|
height: 16px;
|
|
86
|
-
color:
|
|
84
|
+
color: var(--color-gold);
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
.sliderCaption {
|
|
90
88
|
text-align: left;
|
|
91
89
|
font-size: 13px;
|
|
92
|
-
color:
|
|
90
|
+
color: var(--color-muted);
|
|
93
91
|
}
|
package/utils/format.ts
CHANGED
|
@@ -23,6 +23,19 @@ export function formatDuration(this: void, seconds: number, rounding: DurationRo
|
|
|
23
23
|
return `${Math.floor(whole / 60)}:${remainder < 10 ? "0" : ""}${remainder}`;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function twoDigits(this: void, value: number): string {
|
|
27
|
+
return (value < 10 ? "0" : "") + String(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Format elapsed time as MM:SS, adding hours when needed. */
|
|
31
|
+
export function formatClock(this: void, seconds: number): string {
|
|
32
|
+
const elapsed = Number.isFinite(seconds) ? Math.max(0, Math.floor(seconds)) : 0;
|
|
33
|
+
const hours = Math.floor(elapsed / 3600);
|
|
34
|
+
const minutes = Math.floor(elapsed / 60) % 60;
|
|
35
|
+
const clock = twoDigits(minutes) + ":" + twoDigits(elapsed % 60);
|
|
36
|
+
return hours > 0 ? String(hours) + ":" + clock : clock;
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
export function formatInteger(this: void, value: number, separator = ","): string {
|
|
27
40
|
let remaining = Math.abs(value);
|
|
28
41
|
if (remaining > 9_007_199_254_740_991 || !Number.isInteger(remaining)) return String(value);
|
package/utils/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { colorContrast, contrastRatio, copyRGB, hexToRGB, isRGB, mixRGB, rgbaToHex, rgbToHex, type RGB, type RGBA } from "./colors";
|
|
2
|
-
export { formatCompactAmount, formatDuration, formatInteger, formatPercent, type DurationRounding } from "./format";
|
|
2
|
+
export { formatClock, formatCompactAmount, formatDuration, formatInteger, formatPercent, type DurationRounding } from "./format";
|
|
3
3
|
export { clamp, fromPercent, isFiniteNumber, toPercent } from "./number";
|
|
4
4
|
export { replaceFirst } from "./text";
|
package/wow/action-button.ts
CHANGED
|
@@ -55,10 +55,35 @@ function sameAction(previous: ActionSlot | undefined, next: ActionSlot | undefin
|
|
|
55
55
|
return previous?.kind === next?.kind && previous?.id === next?.id;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
function prepareSecureButton(button: Button) {
|
|
59
59
|
const target = button as SecureButton;
|
|
60
60
|
target.SetAttribute("useOnKeyDown", false);
|
|
61
61
|
button.RegisterForClicks("LeftButtonUp");
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function bindSecureMacro(button: Button, scope: RuntimeScope, source: Binding<string | undefined>) {
|
|
66
|
+
const target = prepareSecureButton(button);
|
|
67
|
+
let applied: string | undefined;
|
|
68
|
+
let pending: string | undefined;
|
|
69
|
+
const write = createProtectedLayoutUpdate(() => {
|
|
70
|
+
if (applied === pending) return;
|
|
71
|
+
if (pending === undefined) target.SetAttribute("type", undefined);
|
|
72
|
+
target.SetAttribute("macrotext", pending);
|
|
73
|
+
if (applied === undefined && pending !== undefined) target.SetAttribute("type", "macro");
|
|
74
|
+
applied = pending;
|
|
75
|
+
}, { scope, label: "Secure macro button" });
|
|
76
|
+
if (!write.ok) return write;
|
|
77
|
+
return bindValue(scope, source, text => {
|
|
78
|
+
if (isSecret(text)) return;
|
|
79
|
+
pending = typeof text === "string" && text.trim() !== "" ? text : undefined;
|
|
80
|
+
const result = write.value.request();
|
|
81
|
+
if (!result.ok) report(result);
|
|
82
|
+
}, (previous, next) => !isSecret(previous) && !isSecret(next) && previous === next);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function bindSecureAction(button: Button, scope: RuntimeScope, source: Binding<ActionSlot | undefined>, receive?: Receive) {
|
|
86
|
+
const target = prepareSecureButton(button);
|
|
62
87
|
let applied: ActionSlot | undefined;
|
|
63
88
|
let pending: ActionSlot | undefined;
|
|
64
89
|
const protectedWrite = createProtectedLayoutUpdate(() => {
|
package/wow/addon-manifest.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OwnedLuaArray } from "../src/owned-collections";
|
|
2
|
+
import type { StyleVariables } from "../src/style-variables";
|
|
2
3
|
import { rawField } from "./lua-table";
|
|
3
4
|
|
|
4
5
|
// The compiler binds this to the addon's private table: the second value WoW passes to each addon file.
|
|
@@ -18,6 +19,7 @@ export interface AddonManifest {
|
|
|
18
19
|
readonly name: string;
|
|
19
20
|
readonly savedVariables?: string;
|
|
20
21
|
readonly savedVariablesPerCharacter?: string;
|
|
22
|
+
readonly styleVariables?: StyleVariables;
|
|
21
23
|
readonly pluginState: "account" | "character";
|
|
22
24
|
/** A Lua list written by KumiAddon.lua. Read it with an index loop. */
|
|
23
25
|
readonly plugins: OwnedLuaArray<PluginManifest>;
|
package/wow/animation.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ownedArray, type OwnedArray, type OwnedReadonlyArray, type OwnedRecord } from "../src/owned-collections";
|
|
2
2
|
import type { RuntimeScope } from "../src/runtime";
|
|
3
3
|
import { fail, ok, type Result } from "../src/result";
|
|
4
|
-
import { currentScope } from "../src/reactive-scope";
|
|
4
|
+
import { computed, currentScope, watch } from "../src/reactive-scope";
|
|
5
5
|
import { nativeSmoothing } from "../animation/ease";
|
|
6
|
+
import { isReducedMotion, type MotionMode } from "../animation/motion-policy";
|
|
6
7
|
import { finalAlpha, planAnimation, type AlphaStep, type AnimationPlan, type AnimationSpec, type AnimationStep, type FlipBookStep,
|
|
7
8
|
type MoveStep, type PlannedStep, type RegionAnimation, type RegionStep, type RotateStep, type ScaleStep } from "../animation/spec";
|
|
8
9
|
import { scaleFactors } from "../animation/cycle";
|
|
@@ -24,20 +25,14 @@ export interface AnimationTarget {
|
|
|
24
25
|
/** The region type a spec needs: rotation and flipbooks work on textures only. */
|
|
25
26
|
export type TargetOf<Step extends AnimationStep> = [Exclude<Step, RegionStep>] extends [never] ? AnimationTarget : Texture;
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
export type MotionMode = "full" | "reduced";
|
|
29
|
-
|
|
30
|
-
export interface AnimationDefaults {
|
|
31
|
-
/** Read on every play of an animation that has no `motion` option of its own. */
|
|
32
|
-
motion?: (this: void) => MotionMode;
|
|
33
|
-
}
|
|
28
|
+
export { configureAnimations, type AnimationDefaults, type MotionMode } from "../animation/motion-policy";
|
|
34
29
|
|
|
35
30
|
export interface NativeAnimationOptions {
|
|
36
31
|
/**
|
|
37
32
|
* Stops the group and clears its script when the scope is disposed. Inside a component's setup the
|
|
38
|
-
* component's scope is used when this is left out.
|
|
33
|
+
* component's scope is used when this is left out. Pass false when an integration owns cleanup.
|
|
39
34
|
*/
|
|
40
|
-
scope?: RuntimeScope;
|
|
35
|
+
scope?: RuntimeScope | false;
|
|
41
36
|
/** Multiplies every move offset, for views that scale their art. */
|
|
42
37
|
distance?: number;
|
|
43
38
|
/** Native speed multiplier. */
|
|
@@ -89,12 +84,6 @@ export interface AnimationControl extends AnimationPlayback {
|
|
|
89
84
|
}
|
|
90
85
|
|
|
91
86
|
const looping = { repeat: "REPEAT", bounce: "BOUNCE" } as const;
|
|
92
|
-
let defaults: AnimationDefaults = {};
|
|
93
|
-
|
|
94
|
-
/** Set application-wide defaults, such as the reduced motion setting of the player's profile. */
|
|
95
|
-
export function configureAnimations(this: void, options: AnimationDefaults): void {
|
|
96
|
-
defaults = { ...options as OwnedRecord<AnimationDefaults> };
|
|
97
|
-
}
|
|
98
87
|
|
|
99
88
|
function applyTiming(animation: NativeAnimation, step: PlannedStep) {
|
|
100
89
|
animation.SetOrder(1);
|
|
@@ -169,7 +158,7 @@ export function createAnimation(this: void, target: AnimationTarget, spec: Regio
|
|
|
169
158
|
export function createAnimation(this: void, target: Texture, spec: AnimationSpec, options?: NativeAnimationOptions): Result<AnimationControl>;
|
|
170
159
|
export function createAnimation(this: void, target: AnimationTarget, spec: AnimationSpec,
|
|
171
160
|
options: NativeAnimationOptions = {}): Result<AnimationControl> {
|
|
172
|
-
return build(target, spec, options, options.scope ?? currentScope());
|
|
161
|
+
return build(target, spec, options, options.scope === false ? undefined : options.scope ?? currentScope());
|
|
173
162
|
}
|
|
174
163
|
|
|
175
164
|
function build(target: AnimationTarget, spec: AnimationSpec, options: Omit<NativeAnimationOptions, "scope">,
|
|
@@ -205,7 +194,7 @@ function build(target: AnimationTarget, spec: AnimationSpec, options: Omit<Nativ
|
|
|
205
194
|
if (options.speed !== undefined) group.SetAnimationSpeedMultiplier(options.speed);
|
|
206
195
|
|
|
207
196
|
function reduced() {
|
|
208
|
-
return (options.motion
|
|
197
|
+
return isReducedMotion(options.motion);
|
|
209
198
|
}
|
|
210
199
|
|
|
211
200
|
function skipToEnd() {
|
|
@@ -367,6 +356,18 @@ export function useAnimation<const Step extends AnimationStep>(this: void, spec:
|
|
|
367
356
|
};
|
|
368
357
|
}
|
|
369
358
|
|
|
359
|
+
/** Play a decorative animation while active, and hide its element when motion is reduced. */
|
|
360
|
+
export function useAnimationWhile<const Step extends AnimationStep>(this: void, spec: AnimationSpec<Step>,
|
|
361
|
+
active: (this: void) => boolean, offset?: number) {
|
|
362
|
+
const animation = useAnimation(spec);
|
|
363
|
+
const visible = () => active() && !isReducedMotion();
|
|
364
|
+
watch(visible, playing => {
|
|
365
|
+
if (playing) animation.play(offset === undefined ? undefined : { offset });
|
|
366
|
+
else animation.stop();
|
|
367
|
+
}, { immediate: true });
|
|
368
|
+
return { ref: animation.ref, shown: computed(visible) };
|
|
369
|
+
}
|
|
370
|
+
|
|
370
371
|
function lengthOf(spec: AnimationSpec) {
|
|
371
372
|
const plan = planAnimation(spec);
|
|
372
373
|
return plan.ok ? plan.value.length : 0;
|
package/wow/app-ui.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { createContext } from "../src/context";
|
|
2
2
|
import { createElement } from "../src/elements";
|
|
3
|
-
import { installModuleUi, modulePages, type ModulePage, type ModuleUi, type ModuleView, type ModuleWindow, type ViewComponent } from "../src/module-ui";
|
|
3
|
+
import { installModuleUi, modulePages, type ModulePage, type ModuleReplacement, type ModuleUi, type ModuleView, type ModuleWindow, type ViewComponent } from "../src/module-ui";
|
|
4
4
|
import type { OwnedReadonlyArray, OwnedRecord } from "../src/owned-collections";
|
|
5
5
|
import { computed } from "../src/reactive-scope";
|
|
6
6
|
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
7
|
-
import { fail, formatFailure, ok, type Result } from "../src/result";
|
|
7
|
+
import { fail, formatFailure, ok, type Failure, type Result } from "../src/result";
|
|
8
8
|
import type { Runtime, RuntimeScope } from "../src/runtime";
|
|
9
9
|
import { withRouterHost, type RoutePage, type RouterHost } from "../router/router-view";
|
|
10
10
|
import { defineStore, readonly } from "../state/setup-store";
|
|
11
|
+
import { unlockedActionSlot } from "./action-button";
|
|
11
12
|
import type { EventApi } from "./contract";
|
|
12
13
|
import type { FrameStrata } from "./frame-layer";
|
|
14
|
+
import { mountModuleReplacements } from "./module-replacements";
|
|
13
15
|
import { createNativePanel } from "./panel-host";
|
|
14
16
|
import { mountProtectedView } from "./protected-view";
|
|
15
17
|
import type { NativeViewOptions } from "./view";
|
|
16
18
|
|
|
17
19
|
/** App-wide options for every view Kumi mounts: textures, fonts, control skins and media queries. */
|
|
18
20
|
export type AppTheme = Omit<NativeViewOptions, "rootLayer" | "bindings" | "manualTextBindings" | "layoutDiagnostics" | "regionsOnly"
|
|
19
|
-
| "rootBackdrop" | "rootScale" | "unanchoredRoot" | "portalRoot">;
|
|
21
|
+
| "rootBackdrop" | "rootScale" | "unanchoredRoot" | "portalRoot" | "unprotectedOnly" | "completeStagedMount">;
|
|
20
22
|
|
|
21
23
|
interface FileRouter {
|
|
22
24
|
readonly pages: OwnedReadonlyArray<{ readonly path: string; readonly title?: string; readonly order?: number }>;
|
|
@@ -42,13 +44,18 @@ interface WindowState {
|
|
|
42
44
|
readonly config: ModuleWindow;
|
|
43
45
|
readonly router: FileRouter;
|
|
44
46
|
readonly owner: RuntimeScope;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
panel?: WindowPanel;
|
|
48
|
+
opening?: RuntimeScope;
|
|
49
|
+
inCombat?: boolean;
|
|
50
|
+
resumePath?: string;
|
|
47
51
|
}
|
|
48
52
|
|
|
53
|
+
type WindowPanel = Extract<ReturnType<typeof createNativePanel>, { ok: true }>["value"];
|
|
54
|
+
|
|
49
55
|
let app: AppContext | undefined;
|
|
50
56
|
const windowState = ref<WindowState | undefined>(undefined);
|
|
51
57
|
const windowOpen = ref(false);
|
|
58
|
+
const windowOpening = ref(false);
|
|
52
59
|
const windowPath = ref<string | undefined>(undefined);
|
|
53
60
|
const viewContext = createContext<ViewHost>();
|
|
54
61
|
|
|
@@ -72,15 +79,16 @@ function firstPath(state: WindowState) {
|
|
|
72
79
|
return undefined;
|
|
73
80
|
}
|
|
74
81
|
|
|
75
|
-
function mountWindow(state: WindowState
|
|
82
|
+
function mountWindow(state: WindowState, owner: RuntimeScope,
|
|
83
|
+
complete?: NativeViewOptions["completeStagedMount"]): Result<WindowPanel> {
|
|
76
84
|
const context = app;
|
|
77
85
|
if (context === undefined) return fail("The addon window needs a running addon");
|
|
78
86
|
const { config } = state;
|
|
79
|
-
const panel = createNativePanel(
|
|
87
|
+
const panel = createNativePanel(owner, context.events, config.width, config.height,
|
|
80
88
|
(config.strata ?? "DIALOG") as FrameStrata, 0);
|
|
81
89
|
if (!panel.ok) return panel;
|
|
82
90
|
const host: RouterHost = {
|
|
83
|
-
navigation: { path: windowPath as ReadonlyRef<string | undefined>, navigate: path => {
|
|
91
|
+
navigation: { path: windowPath as ReadonlyRef<string | undefined>, navigate: path => { navigateSettings(path); } },
|
|
84
92
|
render: path => state.router.has(path) ? state.router.render(path, {}) : undefined,
|
|
85
93
|
modulePages: modulePages(),
|
|
86
94
|
};
|
|
@@ -90,12 +98,93 @@ function mountWindow(state: WindowState): Result<void> {
|
|
|
90
98
|
return layout.value;
|
|
91
99
|
}, {
|
|
92
100
|
cssFlow: true, initialLayout: "sync", ...context.theme as OwnedRecord<NativeViewOptions>,
|
|
101
|
+
completeStagedMount: complete, unprotectedOnly: complete === undefined ? undefined : true,
|
|
93
102
|
});
|
|
94
103
|
if (!mounted.ok) return mounted;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
104
|
+
const cleanup = owner.onDispose(mounted.value.dispose);
|
|
105
|
+
if (cleanup.ok) return panel;
|
|
106
|
+
mounted.value.dispose();
|
|
107
|
+
return cleanup;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function cancelOpening(state: WindowState) {
|
|
111
|
+
const opening = state.opening;
|
|
112
|
+
state.opening = undefined;
|
|
113
|
+
windowOpening.value = false;
|
|
114
|
+
opening?.dispose();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function showWindow(panel: WindowPanel) {
|
|
118
|
+
panel.show();
|
|
119
|
+
windowOpen.value = panel.isShown();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function windowBlocked(state: WindowState): boolean {
|
|
123
|
+
return state.config.suspendInCombat === true && (state.inCombat === true || !unlockedActionSlot());
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function hideWindow(state: WindowState) {
|
|
127
|
+
cancelOpening(state);
|
|
128
|
+
state.panel?.hide();
|
|
129
|
+
windowOpen.value = false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function suspendWindow(state: WindowState) {
|
|
133
|
+
if (!windowOpen.value && !windowOpening.value) return;
|
|
134
|
+
state.resumePath = windowPath.value;
|
|
135
|
+
hideWindow(state);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function installWindowCombat(state: WindowState, events: EventApi): Result<void> {
|
|
139
|
+
if (state.config.suspendInCombat !== true) return ok(undefined);
|
|
140
|
+
const entering = events.on(state.owner, "PLAYER_REGEN_DISABLED", () => {
|
|
141
|
+
state.inCombat = true;
|
|
142
|
+
suspendWindow(state);
|
|
143
|
+
});
|
|
144
|
+
if (!entering.ok) return entering;
|
|
145
|
+
const leaving = events.on(state.owner, "PLAYER_REGEN_ENABLED", () => {
|
|
146
|
+
state.inCombat = false;
|
|
147
|
+
state.owner.nextTick(() => {
|
|
148
|
+
const path = state.resumePath;
|
|
149
|
+
if (path === undefined || windowBlocked(state)) return;
|
|
150
|
+
state.resumePath = undefined;
|
|
151
|
+
const target = routeExists(path) ? path : firstPath(state);
|
|
152
|
+
if (target === undefined) return;
|
|
153
|
+
const opened = openWindow(target);
|
|
154
|
+
if (!opened.ok) return opened;
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
return leaving.ok ? ok(undefined) : leaving;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function stageWindow(state: WindowState) {
|
|
161
|
+
const attempt = state.owner.fork();
|
|
162
|
+
const key = {};
|
|
163
|
+
let panel: WindowPanel | undefined;
|
|
164
|
+
state.opening = attempt;
|
|
165
|
+
windowOpening.value = true;
|
|
166
|
+
attempt.onDispose(() => { attempt.frameJobs.cancel(key); });
|
|
167
|
+
|
|
168
|
+
function finish(failure?: Failure) {
|
|
169
|
+
if (state.opening !== attempt) return;
|
|
170
|
+
if (windowBlocked(state)) { suspendWindow(state); return; }
|
|
171
|
+
if (failure !== undefined || panel === undefined) {
|
|
172
|
+
cancelOpening(state);
|
|
173
|
+
return failure ?? fail("The initial window mount did not create a panel");
|
|
174
|
+
}
|
|
175
|
+
state.panel = panel;
|
|
176
|
+
state.opening = undefined;
|
|
177
|
+
windowOpening.value = false;
|
|
178
|
+
showWindow(panel);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
attempt.frameJobs.queue(key, () => {
|
|
182
|
+
if (!attempt.isActive()) return;
|
|
183
|
+
const mounted = attempt.protect(() => mountWindow(state, attempt, finish));
|
|
184
|
+
const result = mounted.ok ? mounted.value : mounted;
|
|
185
|
+
if (!result.ok) return finish(result);
|
|
186
|
+
panel = result.value;
|
|
187
|
+
}, { lane: "user", label: "Prepare window JSX" });
|
|
99
188
|
}
|
|
100
189
|
|
|
101
190
|
function navigateWindow(path: string): Result<void> {
|
|
@@ -104,26 +193,45 @@ function navigateWindow(path: string): Result<void> {
|
|
|
104
193
|
return ok(undefined);
|
|
105
194
|
}
|
|
106
195
|
|
|
196
|
+
function navigateSettings(path: string): Result<void> {
|
|
197
|
+
const state = windowState.value;
|
|
198
|
+
if (state !== undefined && windowBlocked(state)) return ok(undefined);
|
|
199
|
+
return windowOpening.value ? openWindow(path) : navigateWindow(path);
|
|
200
|
+
}
|
|
201
|
+
|
|
107
202
|
function openWindow(path?: string): Result<void> {
|
|
108
203
|
const state = windowState.value;
|
|
109
204
|
if (state === undefined) return fail("The addon has no window. Declare window in the app module.");
|
|
110
205
|
if (!state.owner.isActive()) return fail("The addon window has closed");
|
|
206
|
+
if (windowBlocked(state)) return ok(undefined);
|
|
111
207
|
const target = path ?? windowPath.value ?? firstPath(state);
|
|
112
208
|
if (target === undefined) return fail("The addon window has no pages");
|
|
209
|
+
const previous = windowPath.value;
|
|
113
210
|
const navigated = navigateWindow(target);
|
|
114
211
|
if (!navigated.ok) return navigated;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
212
|
+
state.resumePath = undefined;
|
|
213
|
+
if (state.panel !== undefined) {
|
|
214
|
+
showWindow(state.panel);
|
|
215
|
+
return ok(undefined);
|
|
216
|
+
}
|
|
217
|
+
if (state.config.mount === "staged") {
|
|
218
|
+
if (state.opening !== undefined && target !== previous) cancelOpening(state);
|
|
219
|
+
if (state.opening === undefined) stageWindow(state);
|
|
220
|
+
return ok(undefined);
|
|
118
221
|
}
|
|
119
|
-
state.
|
|
120
|
-
|
|
222
|
+
const mounted = mountWindow(state, state.owner);
|
|
223
|
+
if (!mounted.ok) return mounted;
|
|
224
|
+
state.panel = mounted.value;
|
|
225
|
+
showWindow(mounted.value);
|
|
121
226
|
return ok(undefined);
|
|
122
227
|
}
|
|
123
228
|
|
|
124
229
|
function closeWindow() {
|
|
125
|
-
windowState.value
|
|
126
|
-
|
|
230
|
+
const state = windowState.value;
|
|
231
|
+
if (state !== undefined) {
|
|
232
|
+
state.resumePath = undefined;
|
|
233
|
+
hideWindow(state);
|
|
234
|
+
}
|
|
127
235
|
}
|
|
128
236
|
|
|
129
237
|
/**
|
|
@@ -153,7 +261,7 @@ export const useWindow = defineStore("kumi/window", () => {
|
|
|
153
261
|
}
|
|
154
262
|
|
|
155
263
|
function toggle(this: void, path?: string): Result<void> {
|
|
156
|
-
if (windowOpen.value && (path === undefined || path === windowPath.value)) {
|
|
264
|
+
if ((windowOpen.value || windowOpening.value) && (path === undefined || path === windowPath.value)) {
|
|
157
265
|
closeWindow();
|
|
158
266
|
return ok(undefined);
|
|
159
267
|
}
|
|
@@ -161,10 +269,10 @@ export const useWindow = defineStore("kumi/window", () => {
|
|
|
161
269
|
}
|
|
162
270
|
|
|
163
271
|
function navigate(this: void, path: string): Result<void> {
|
|
164
|
-
return
|
|
272
|
+
return navigateSettings(path);
|
|
165
273
|
}
|
|
166
274
|
|
|
167
|
-
return { isOpen: readonly(windowOpen), path: readonly(windowPath), pages, open, close, toggle, navigate };
|
|
275
|
+
return { isOpen: readonly(windowOpen), isOpening: readonly(windowOpening), path: readonly(windowPath), pages, open, close, toggle, navigate };
|
|
168
276
|
});
|
|
169
277
|
|
|
170
278
|
/** Inside a HUD view: refresh it now, or read the size of one physical pixel. */
|
|
@@ -174,15 +282,23 @@ export function useViewHost(this: void): ViewHost {
|
|
|
174
282
|
return host;
|
|
175
283
|
}
|
|
176
284
|
|
|
177
|
-
function mountView(context: AppContext, component
|
|
285
|
+
function mountView(context: AppContext, { component, strata = "MEDIUM", combatUpdates }: ModuleView, scope: RuntimeScope): Result<void> {
|
|
178
286
|
const mounted = mountProtectedView(context.runtime, scope, (_view, refresh, pixel) => {
|
|
179
287
|
const rendered = viewContext.run({ refresh, pixel }, () => createElement(component, {}), scope.protect);
|
|
180
288
|
if (!rendered.ok) throw new Error(formatFailure(rendered));
|
|
181
289
|
return rendered.value;
|
|
182
|
-
}, { ...context.theme as OwnedRecord<NativeViewOptions>, rootLayer: { strata: strata as FrameStrata } });
|
|
290
|
+
}, { ...context.theme as OwnedRecord<NativeViewOptions>, rootLayer: { strata: strata as FrameStrata }, combatUpdates });
|
|
183
291
|
return mounted.ok ? ok(undefined) : mounted;
|
|
184
292
|
}
|
|
185
293
|
|
|
294
|
+
function mountViews(context: AppContext, id: string, views: OwnedReadonlyArray<ViewComponent | ModuleView>, scope: RuntimeScope): Result<void> {
|
|
295
|
+
for (const view of views) {
|
|
296
|
+
const mounted = mountView(context, typeof view === "function" ? { component: view } : view, scope);
|
|
297
|
+
if (!mounted.ok) return fail("Module " + id + ": " + mounted.reason);
|
|
298
|
+
}
|
|
299
|
+
return ok(undefined);
|
|
300
|
+
}
|
|
301
|
+
|
|
186
302
|
function mountUi(id: string, ui: ModuleUi, scope: RuntimeScope): Result<void> {
|
|
187
303
|
const context = app;
|
|
188
304
|
if (context === undefined) return fail("Module " + id + " declares UI but the addon is not running");
|
|
@@ -193,20 +309,23 @@ function mountUi(id: string, ui: ModuleUi, scope: RuntimeScope): Result<void> {
|
|
|
193
309
|
return fail("Module " + id + ": window.routes must be the router from @kumi/routes");
|
|
194
310
|
}
|
|
195
311
|
if (!router.ok) return fail("Module " + id + ": " + router.reason);
|
|
196
|
-
|
|
312
|
+
const state: WindowState = { config: ui.window, router: router.value, owner: scope };
|
|
313
|
+
const combat = installWindowCombat(state, context.events);
|
|
314
|
+
if (!combat.ok) return combat;
|
|
315
|
+
windowState.value = state;
|
|
197
316
|
const released = scope.onDispose(() => {
|
|
198
317
|
closeWindow();
|
|
199
318
|
windowState.value = undefined;
|
|
200
319
|
});
|
|
201
320
|
if (!released.ok) return released;
|
|
202
321
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
322
|
+
const views = (ui.views ?? []) as OwnedReadonlyArray<ViewComponent | ModuleView>;
|
|
323
|
+
const replacements = ui.replaces as OwnedReadonlyArray<ModuleReplacement> | undefined;
|
|
324
|
+
if (replacements !== undefined && replacements.length > 0) {
|
|
325
|
+
return mountModuleReplacements(context.runtime, scope, id, replacements,
|
|
326
|
+
viewScope => mountViews(context, id, views, viewScope));
|
|
208
327
|
}
|
|
209
|
-
return
|
|
328
|
+
return mountViews(context, id, views, scope);
|
|
210
329
|
}
|
|
211
330
|
|
|
212
331
|
/** @internal Called by startAddon before the root module activates. */
|