@overmvp/kumi 0.1.0 → 0.4.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.
Files changed (201) hide show
  1. package/README.md +59 -6
  2. package/animation/index.ts +4 -0
  3. package/animation/motion-policy.ts +20 -0
  4. package/animation/slide.ts +61 -0
  5. package/animation/spring.ts +75 -0
  6. package/animation/staggered-reveal.ts +34 -0
  7. package/builder/css-gradients.mjs +74 -0
  8. package/builder/css-mask-assets.mjs +52 -0
  9. package/builder/css-mask-assets.test.mjs +31 -0
  10. package/builder/css-v1.mjs +127 -23
  11. package/builder/css-v1.test.mjs +82 -2
  12. package/builder/link-addon-package.mjs +47 -6
  13. package/builder/module-declarations.test.mjs +9 -18
  14. package/builder/native-kernels.mjs +1 -1
  15. package/builder/src/compiler.rs +205 -8
  16. package/builder/src/lua_upvalues.rs +641 -0
  17. package/builder/src/main.rs +20 -5
  18. package/builder/src/native_ir.rs +1 -1
  19. package/builder/src/native_signal.rs +46 -10
  20. package/builder/src/numbers.lua +14 -0
  21. package/builder/src/project-front.mjs +385 -34
  22. package/builder/src/routes.rs +11 -14
  23. package/builder/src/setup-store.lua +18 -0
  24. package/builder/src/signal-kernel.fingerprint +1 -1
  25. package/builder/src/ts-lower.mjs +2 -2
  26. package/builder/src/wow-reads.lua +22 -0
  27. package/builder/style-modules.mjs +111 -0
  28. package/builder/style-modules.test.mjs +24 -0
  29. package/builder/style-states.mjs +6 -4
  30. package/config.ts +56 -14
  31. package/eslint.mjs +74 -0
  32. package/form/index.ts +15 -11
  33. package/package.json +11 -7
  34. package/router/index.ts +10 -2
  35. package/router/link.tsx +32 -0
  36. package/router/navigation.ts +22 -0
  37. package/router/router-view.ts +134 -0
  38. package/scripts/addon-build.mjs +377 -0
  39. package/scripts/addon-project.mjs +89 -0
  40. package/scripts/kumi-cli.mjs +52 -17
  41. package/scripts/link-addons.mjs +12 -2
  42. package/src/bindings.ts +12 -6
  43. package/src/context.ts +31 -7
  44. package/src/css-tokens.ts +27 -13
  45. package/src/css-v1.ts +13 -0
  46. package/src/elements.ts +35 -0
  47. package/src/flex-layout.ts +26 -5
  48. package/src/frame-scheduler.ts +6 -2
  49. package/src/index.ts +2 -1
  50. package/src/jsx-runtime.ts +8 -1
  51. package/src/keyed-list.ts +17 -11
  52. package/src/module-ui.ts +163 -0
  53. package/src/module.ts +51 -8
  54. package/src/owned-collections.ts +8 -0
  55. package/src/providers.ts +7 -1
  56. package/src/reactive-scope.ts +3 -3
  57. package/src/reactivity.ts +42 -8
  58. package/src/result.ts +6 -0
  59. package/src/signal-kernel.ts +35 -2
  60. package/src/style-classes.ts +22 -1
  61. package/src/style-states.ts +13 -6
  62. package/state/index.ts +6 -0
  63. package/state/setup-store-persistence.ts +206 -0
  64. package/state/setup-store-view.ts +10 -0
  65. package/state/setup-store.ts +342 -0
  66. package/state/store.ts +2 -0
  67. package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
  68. package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
  69. package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
  70. package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
  71. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
  72. package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
  73. package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
  74. package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
  75. package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
  76. package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
  77. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
  78. package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
  79. package/templates/addon/AGENTS.md +34 -0
  80. package/templates/addon/Assets/Art/Corner10.tga +0 -0
  81. package/templates/addon/Assets/Art/Corner11.tga +0 -0
  82. package/templates/addon/Assets/Art/Corner12.tga +0 -0
  83. package/templates/addon/Assets/Art/Corner13.tga +0 -0
  84. package/templates/addon/Assets/Art/Corner14.tga +0 -0
  85. package/templates/addon/Assets/Art/Corner15.tga +0 -0
  86. package/templates/addon/Assets/Art/Corner16.tga +0 -0
  87. package/templates/addon/Assets/Art/Corner2.tga +0 -0
  88. package/templates/addon/Assets/Art/Corner3.tga +0 -0
  89. package/templates/addon/Assets/Art/Corner4.tga +0 -0
  90. package/templates/addon/Assets/Art/Corner5.tga +0 -0
  91. package/templates/addon/Assets/Art/Corner6.tga +0 -0
  92. package/templates/addon/Assets/Art/Corner7.tga +0 -0
  93. package/templates/addon/Assets/Art/Corner8.tga +0 -0
  94. package/templates/addon/Assets/Art/Corner9.tga +0 -0
  95. package/templates/addon/Assets/Art/Dot.tga +0 -0
  96. package/templates/addon/Assets/Art/Gear.tga +0 -0
  97. package/templates/addon/Assets/Art/Grip.tga +0 -0
  98. package/templates/addon/Assets/Art/Outline10.tga +0 -0
  99. package/templates/addon/Assets/Art/Outline12.tga +0 -0
  100. package/templates/addon/Assets/Art/Outline13.tga +0 -0
  101. package/templates/addon/Assets/Art/Outline14.tga +0 -0
  102. package/templates/addon/Assets/Art/Outline15.tga +0 -0
  103. package/templates/addon/Assets/Art/Outline2.tga +0 -0
  104. package/templates/addon/Assets/Art/Outline3.tga +0 -0
  105. package/templates/addon/Assets/Art/Outline5.tga +0 -0
  106. package/templates/addon/Assets/Art/Outline7.tga +0 -0
  107. package/templates/addon/Assets/Art/Outline9.tga +0 -0
  108. package/templates/addon/Assets/Art/Round11.tga +0 -0
  109. package/templates/addon/Assets/Art/Round11Border.tga +0 -0
  110. package/templates/addon/Assets/Art/Round4.tga +0 -0
  111. package/templates/addon/Assets/Art/Round4Border.tga +0 -0
  112. package/templates/addon/Assets/Art/Round6.tga +0 -0
  113. package/templates/addon/Assets/Art/Round6Border.tga +0 -0
  114. package/templates/addon/Assets/Art/Round8.tga +0 -0
  115. package/templates/addon/Assets/Art/Round8Border.tga +0 -0
  116. package/templates/addon/Assets/Art/Search.tga +0 -0
  117. package/templates/addon/CLAUDE.md +1 -0
  118. package/templates/addon/README.md +42 -7
  119. package/templates/addon/eslint.config.mjs +3 -9
  120. package/templates/addon/gitignore +1 -0
  121. package/templates/addon/kumi.config.ts +17 -0
  122. package/templates/addon/package.json +4 -5
  123. package/templates/addon/src/app/app.module.ts +18 -0
  124. package/templates/addon/src/app/commands.store.ts +11 -0
  125. package/templates/addon/src/app/layout/AppWindow.module.css +90 -0
  126. package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
  127. package/templates/addon/src/app/main.ts +5 -0
  128. package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
  129. package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
  130. package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
  131. package/templates/addon/src/app/theme.ts +6 -0
  132. package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
  133. package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
  134. package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
  135. package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
  136. package/templates/addon/src/modules/greeting/ui/Greeting.module.css +103 -0
  137. package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
  138. package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
  139. package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
  140. package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
  141. package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
  142. package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
  143. package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
  144. package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
  145. package/templates/addon/src/modules/playtime/ui/Playtime.module.css +23 -0
  146. package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
  147. package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
  148. package/templates/addon/src/shared/api/native-art.ts +28 -0
  149. package/templates/addon/src/shared/assets/close.png +0 -0
  150. package/templates/addon/src/shared/lib/format.ts +20 -0
  151. package/templates/addon/src/shared/styles/tokens.css +13 -0
  152. package/templates/addon/src/shared/ui/Button.tsx +29 -0
  153. package/templates/addon/src/shared/ui/Choice.tsx +34 -0
  154. package/templates/addon/src/shared/ui/Controls.module.css +91 -0
  155. package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
  156. package/templates/addon/src/shared/ui/Slider.tsx +25 -0
  157. package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
  158. package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
  159. package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
  160. package/templates/addon/tsconfig.json +49 -10
  161. package/wow/action-bar-layout.ts +108 -0
  162. package/wow/action-button.ts +244 -0
  163. package/wow/action-catalog.ts +98 -0
  164. package/wow/addon-manifest.ts +38 -0
  165. package/wow/animation.ts +3 -14
  166. package/wow/app-ui.ts +230 -0
  167. package/wow/cooldown-timing.ts +24 -0
  168. package/wow/css-background-image.ts +75 -0
  169. package/wow/css-box.ts +46 -10
  170. package/wow/css-image-mask.ts +32 -0
  171. package/wow/css-surfaces.ts +295 -43
  172. package/wow/cursor.ts +45 -0
  173. package/wow/element-events.ts +33 -13
  174. package/wow/frame-access.ts +23 -1
  175. package/wow/frame-timing.ts +13 -0
  176. package/wow/heal-prediction.ts +2 -4
  177. package/wow/hooks.ts +133 -0
  178. package/wow/index.ts +19 -4
  179. package/wow/layout-view.ts +44 -23
  180. package/wow/locale-font.ts +15 -0
  181. package/wow/module-replacements.ts +103 -0
  182. package/wow/native.ts +18 -0
  183. package/wow/panel-host.ts +97 -0
  184. package/wow/pixel.ts +35 -0
  185. package/wow/plugins.ts +246 -0
  186. package/wow/pointer-click.ts +35 -0
  187. package/wow/protect.ts +27 -3
  188. package/wow/protected-view.ts +139 -0
  189. package/wow/range-art.ts +7 -0
  190. package/wow/readable-api.ts +120 -0
  191. package/wow/rounded-texture.ts +38 -6
  192. package/wow/saved-variables.ts +67 -18
  193. package/wow/spell-cooldown.ts +36 -0
  194. package/wow/start-addon.ts +31 -8
  195. package/wow/state-paint.ts +5 -14
  196. package/wow/texture-fill.ts +10 -0
  197. package/wow/unit-cast.ts +6 -4
  198. package/wow/view.ts +458 -228
  199. package/templates/addon/__ADDON_NAME__.toc +0 -4
  200. package/templates/addon/scripts/build.mjs +0 -25
  201. package/templates/addon/src/app/main.tsx +0 -13
@@ -0,0 +1,108 @@
1
+ import type { Anchor } from "../src/elements";
2
+ import type { ReadonlyRef } from "../src/reactivity";
3
+ import { computed, computedResult } from "../src/reactive-scope";
4
+ import { ok } from "../src/result";
5
+ import { snapPixel } from "./pixel";
6
+
7
+ export interface ActionBarPosition {
8
+ readonly x: number;
9
+ readonly y: number;
10
+ }
11
+
12
+ export interface ActionBarLayoutOptions {
13
+ readonly count: ReadonlyRef<number>;
14
+ readonly slotSize: ReadonlyRef<number>;
15
+ readonly vertical: ReadonlyRef<boolean>;
16
+ readonly pixel: ReadonlyRef<number>;
17
+ readonly x: ReadonlyRef<number>;
18
+ readonly y: ReadonlyRef<number>;
19
+ readonly preview: ReadonlyRef<ActionBarPosition | undefined>;
20
+ readonly gap: number;
21
+ readonly padding: number;
22
+ readonly controlSize: number;
23
+ readonly controlGap: number;
24
+ readonly iconInsetPixels: number;
25
+ }
26
+
27
+ function measure(size: number, pixel: number, options: ActionBarLayoutOptions) {
28
+ const cell = snapPixel(size, pixel);
29
+ const step = cell + snapPixel(options.gap, pixel);
30
+ const control = snapPixel(options.controlSize, pixel);
31
+ const padding = snapPixel(options.padding, pixel);
32
+ const trayInset = control + snapPixel(options.controlGap, pixel);
33
+ const first = trayInset + padding;
34
+ const across = Math.max(cell, control) + 2 * padding;
35
+ return {
36
+ cell, step, first, control, trayInset, across,
37
+ cellCenter: snapPixel((across - cell) / 2, pixel),
38
+ controlCenter: snapPixel((across - control) / 2, pixel),
39
+ };
40
+ }
41
+
42
+ /** Bind an explicitly anchored strip of secure slots, a tray and two end controls. */
43
+ export function useActionBarLayout(this: void, options: ActionBarLayoutOptions) {
44
+ const { count, slotSize, vertical, pixel, preview, x, y } = options;
45
+ const geometry = computed(() => measure(slotSize.value, pixel.value, options));
46
+
47
+ function select<Value>(read: (this: void, value: ReturnType<typeof measure>) => Value) {
48
+ return computedResult(() => {
49
+ const size = geometry.value;
50
+ return size.ok ? ok(read(size.value)) : size;
51
+ });
52
+ }
53
+
54
+ function length(value: ReturnType<typeof measure>) {
55
+ const slots = count.value;
56
+ return 2 * value.first + (slots > 0 ? value.cell + (slots - 1) * value.step : 0);
57
+ }
58
+
59
+ const anchor = computed<Anchor>(() => {
60
+ const current = preview.value;
61
+ return { point: "BOTTOM", x: snapPixel(current?.x ?? x.value, pixel.value), y: snapPixel(current?.y ?? y.value, pixel.value) };
62
+ });
63
+ const control = select(value => value.control);
64
+ const cell = select(value => value.cell);
65
+ const icon = select(value => value.cell - 2 * options.iconInsetPixels * pixel.value);
66
+
67
+ return {
68
+ bar: {
69
+ anchor,
70
+ width: select(value => vertical.value ? value.across : length(value)),
71
+ height: select(value => vertical.value ? length(value) : value.across),
72
+ },
73
+ start: {
74
+ width: control, height: control,
75
+ anchor: select((value): Anchor => vertical.value
76
+ ? { point: "TOPLEFT", x: value.controlCenter }
77
+ : { point: "TOPLEFT", y: -value.controlCenter }),
78
+ },
79
+ end: {
80
+ width: control, height: control,
81
+ anchor: select((value): Anchor => vertical.value
82
+ ? { point: "BOTTOMLEFT", x: value.controlCenter }
83
+ : { point: "TOPRIGHT", y: -value.controlCenter }),
84
+ },
85
+ tray: {
86
+ width: select(value => vertical.value ? value.across : length(value) - 2 * value.trayInset),
87
+ height: select(value => vertical.value ? length(value) - 2 * value.trayInset : value.across),
88
+ anchor: select((value): Anchor => vertical.value
89
+ ? { point: "TOPLEFT", y: -value.trayInset }
90
+ : { point: "TOPLEFT", x: value.trayInset }),
91
+ },
92
+ iconSize: icon,
93
+ cellSize: cell,
94
+ slot(this: void, index: number) {
95
+ return {
96
+ width: cell,
97
+ height: cell,
98
+ shown: computed(() => index < count.value),
99
+ anchor: select((value): Anchor => {
100
+ const offset = value.first + index * value.step;
101
+ return vertical.value
102
+ ? { point: "TOPLEFT", x: value.cellCenter, y: -offset }
103
+ : { point: "TOPLEFT", x: offset, y: -value.cellCenter };
104
+ }),
105
+ };
106
+ },
107
+ };
108
+ }
@@ -0,0 +1,244 @@
1
+ import { bindValue } from "../src/bindings";
2
+ import type { ActionSlot, Binding, Element } from "../src/elements";
3
+ import { withReactiveScope } from "../src/reactive-scope";
4
+ import { fail, formatFailure, type Failure, type Result } from "../src/result";
5
+ import type { RuntimeScope } from "../src/runtime";
6
+ import type { Cancel } from "../src/scheduler";
7
+ import { hasCursorAction } from "./cursor";
8
+ import { createEventDispatcher } from "./event-dispatcher";
9
+ import type { Button } from "./frames";
10
+ import { readLayoutValue } from "./layout-view";
11
+ import { api, isSecret, reveal } from "./native";
12
+ import { createProtectedLayoutUpdate } from "./protected-layout";
13
+ import { readableApi } from "./readable-api";
14
+
15
+ type Receive = (this: void) => Result<boolean> | void;
16
+ type DropButton = Button & {
17
+ SetScript(this: object, event: "OnReceiveDrag", receive?: (this: void) => void): void;
18
+ };
19
+ type SecureButton = DropButton & {
20
+ SetAttribute(this: object, key: string, value?: string | number | boolean): void;
21
+ };
22
+ const events = createEventDispatcher();
23
+
24
+ export function unlockedActionSlot(): boolean {
25
+ return reveal(api.InCombatLockdown()) === false;
26
+ }
27
+
28
+ function report(failure: Failure) {
29
+ api.geterrorhandler()(formatFailure(failure));
30
+ }
31
+
32
+ function showText(button: Button, text: string) {
33
+ const tooltip = api.GameTooltip;
34
+ if (tooltip === undefined) return;
35
+ tooltip.SetOwner(button, "ANCHOR_TOP");
36
+ tooltip.SetText(text);
37
+ tooltip.Show();
38
+ }
39
+
40
+ export function listenForDrop(button: Button, scope: RuntimeScope, receive?: Receive) {
41
+ if (receive === undefined) return;
42
+ const target = button as DropButton;
43
+ button.RegisterForDrag("LeftButton");
44
+ target.SetScript("OnReceiveDrag", () => {
45
+ if (!scope.isActive() || !unlockedActionSlot()) return;
46
+ const attempt = scope.protect(receive);
47
+ if (!attempt.ok) report(attempt);
48
+ else if (attempt.value?.ok === false) showText(button, attempt.value.reason);
49
+ });
50
+ const cleanup = scope.onDispose(() => { target.SetScript("OnReceiveDrag", undefined); });
51
+ return cleanup.ok ? undefined : cleanup;
52
+ }
53
+
54
+ function sameAction(previous: ActionSlot | undefined, next: ActionSlot | undefined) {
55
+ return previous?.kind === next?.kind && previous?.id === next?.id;
56
+ }
57
+
58
+ function prepareSecureButton(button: Button) {
59
+ const target = button as SecureButton;
60
+ target.SetAttribute("useOnKeyDown", false);
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);
87
+ let applied: ActionSlot | undefined;
88
+ let pending: ActionSlot | undefined;
89
+ const protectedWrite = createProtectedLayoutUpdate(() => {
90
+ const next = pending;
91
+ if (sameAction(applied, next)) return;
92
+ if (applied !== undefined && applied.kind !== next?.kind) target.SetAttribute(applied.kind, undefined);
93
+ if (next !== undefined) target.SetAttribute(next.kind, next.kind === "item" ? "item:" + String(next.id) : next.id);
94
+ if (applied?.kind !== next?.kind) target.SetAttribute("type", next?.kind);
95
+ applied = next;
96
+ }, { scope, label: "Secure action button" });
97
+ if (!protectedWrite.ok) return protectedWrite;
98
+ const write = protectedWrite.value.request;
99
+ const binding = bindValue(scope, source, value => {
100
+ if (isSecret(value) || isSecret(value?.kind) || isSecret(value?.id)) return;
101
+ if (value !== undefined && (value.kind !== "item" && value.kind !== "spell" && value.kind !== "toy"
102
+ || !(value.id > 0 && value.id <= 2147483647 && Math.floor(value.id) === value.id))) return;
103
+ pending = value;
104
+ const result = write();
105
+ if (!result.ok) report(result);
106
+ }, (previous, next) => !isSecret(previous) && !isSecret(next)
107
+ && !isSecret(previous?.kind) && !isSecret(next?.kind) && !isSecret(previous?.id) && !isSecret(next?.id)
108
+ && sameAction(previous, next));
109
+ if (binding !== undefined) return binding;
110
+
111
+ let unwatch: Cancel | undefined;
112
+ function tooltip() {
113
+ const gameTooltip = api.GameTooltip;
114
+ if (gameTooltip === undefined) return;
115
+ if (receive !== undefined && unlockedActionSlot() && hasCursorAction()) {
116
+ showText(button, "Drop to assign");
117
+ return;
118
+ }
119
+ const action = applied;
120
+ if (action === undefined) {
121
+ showText(button, "Empty slot. Drag an action here.");
122
+ return;
123
+ }
124
+ gameTooltip.SetOwner(button, "ANCHOR_TOP");
125
+ if (action.kind === "spell") gameTooltip.SetSpellByID(action.id);
126
+ else if (action.kind === "toy" && gameTooltip.SetToyByItemID !== undefined) gameTooltip.SetToyByItemID(action.id);
127
+ else gameTooltip.SetItemByID(action.id);
128
+ gameTooltip.Show();
129
+ }
130
+ function leave() {
131
+ if (unwatch === undefined) return;
132
+ unwatch();
133
+ unwatch = undefined;
134
+ api.GameTooltip?.Hide();
135
+ }
136
+ button.HookScript("OnEnter", () => {
137
+ if (!scope.isActive()) return;
138
+ tooltip();
139
+ if (unwatch !== undefined) return;
140
+ const watch = events.on(scope, "CURSOR_CHANGED", tooltip);
141
+ if (watch.ok) unwatch = watch.value;
142
+ else report(watch);
143
+ });
144
+ button.HookScript("OnLeave", leave);
145
+ const cleanup = scope.onDispose(leave);
146
+ if (!cleanup.ok) return cleanup;
147
+ return listenForDrop(button, scope, receive);
148
+ }
149
+
150
+ export function bindActionVisibility(button: Button, scope: RuntimeScope, source: Binding<boolean>,
151
+ mount: (this: void, owner: RuntimeScope) => Failure | undefined): Failure | undefined {
152
+ let desired = false;
153
+ let visible: boolean | undefined;
154
+ let mounted = false;
155
+ const update = createProtectedLayoutUpdate(() => {
156
+ const next = desired;
157
+ if (next === visible) return;
158
+ if (next && !mounted) {
159
+ const owner = scope.fork();
160
+ const created = withReactiveScope(owner, () => mount(owner));
161
+ const failure = created.ok ? created.value : created;
162
+ if (failure !== undefined) {
163
+ owner.dispose();
164
+ return failure;
165
+ }
166
+ if (!owner.isActive()) return fail("Action content disposed during mount");
167
+ mounted = true;
168
+ }
169
+ button.SetShown(next);
170
+ visible = next;
171
+ }, { scope, label: "Secure action visibility" });
172
+ if (!update.ok) return update;
173
+
174
+ // watch runs the change callback outside the source's observer. Mounting the body must not track into it.
175
+ const observed = scope.watch(() => readLayoutValue(source), next => {
176
+ if (!next.ok) return next;
177
+ if (typeof next.value !== "boolean") return fail("Secure action visibility requires a readable boolean");
178
+ desired = next.value;
179
+ const applied = update.value.request();
180
+ if (!applied.ok) return applied;
181
+ }, true);
182
+ return observed.ok ? undefined : observed;
183
+ }
184
+
185
+ interface DragStart {
186
+ readonly x: number;
187
+ readonly y: number;
188
+ readonly scale: number;
189
+ }
190
+
191
+ export function bindButtonMove(button: Button, scope: RuntimeScope,
192
+ { onMove, onMoveEnd, onMoveCancel }: Element<"button">["props"]) {
193
+ if (onMove === undefined && onMoveEnd === undefined) return;
194
+ let start: DragStart | undefined;
195
+
196
+ function stop() {
197
+ const previous = start;
198
+ if (previous === undefined) return undefined;
199
+ start = undefined;
200
+ button.SetScript("OnUpdate", undefined);
201
+ return previous;
202
+ }
203
+
204
+ function cancel() {
205
+ if (stop() !== undefined && scope.isActive()) onMoveCancel?.();
206
+ }
207
+
208
+ button.RegisterForDrag("LeftButton");
209
+ button.SetScript("OnDragStart", () => {
210
+ if (!scope.isActive() || !unlockedActionSlot() || reveal(button.IsEnabled()) !== true) return;
211
+ const [x, y] = readableApi.GetCursorPosition();
212
+ const scale = reveal(button.GetEffectiveScale());
213
+ if (x === undefined || y === undefined || scale === undefined || scale <= 0) return;
214
+ start = { x, y, scale };
215
+ if (onMove === undefined) return;
216
+ button.SetScript("OnUpdate", () => {
217
+ const origin = start;
218
+ if (origin === undefined || !unlockedActionSlot()) return;
219
+ const [nextX, nextY] = readableApi.GetCursorPosition();
220
+ if (nextX !== undefined && nextY !== undefined) onMove((nextX - origin.x) / origin.scale, (nextY - origin.y) / origin.scale);
221
+ });
222
+ });
223
+ button.SetScript("OnDragStop", () => {
224
+ const origin = stop();
225
+ if (origin === undefined) return;
226
+ if (scope.isActive() && unlockedActionSlot()) {
227
+ const [x, y] = readableApi.GetCursorPosition();
228
+ if (x !== undefined && y !== undefined) {
229
+ onMoveEnd?.((x - origin.x) / origin.scale, (y - origin.y) / origin.scale);
230
+ return;
231
+ }
232
+ }
233
+ onMoveCancel?.();
234
+ });
235
+ button.HookScript("OnHide", cancel);
236
+ const combat = events.on(scope, "PLAYER_REGEN_DISABLED", cancel);
237
+ if (!combat.ok) return combat;
238
+ const cleanup = scope.onDispose(() => {
239
+ cancel();
240
+ button.SetScript("OnDragStart", undefined);
241
+ button.SetScript("OnDragStop", undefined);
242
+ });
243
+ return cleanup.ok ? undefined : cleanup;
244
+ }
@@ -0,0 +1,98 @@
1
+ import { api, reveal, type SecretValue } from "./native";
2
+
3
+ type VisitAction = (this: void, id: number, label?: string) => boolean;
4
+
5
+ function validId(id: number | undefined): id is number {
6
+ return typeof id === "number" && id > 0 && id <= 2147483647 && Math.floor(id) === id;
7
+ }
8
+
9
+ function readCount(value: number | SecretValue<number> | undefined): number {
10
+ const count = reveal(value);
11
+ return typeof count === "number" && Number.isFinite(count) && count > 0 ? Math.floor(count) : 0;
12
+ }
13
+
14
+ function readTable<Table extends object>(input: Table | SecretValue<Table> | undefined): Table | undefined {
15
+ const table = reveal(input);
16
+ if (table === undefined || typeof table !== "object") return undefined;
17
+ const canAccess = api.canaccesstable;
18
+ if (canAccess !== undefined) return canAccess(table) ? table : undefined;
19
+ const isRestricted = api.issecrettable;
20
+ return isRestricted !== undefined && isRestricted(table) ? undefined : table;
21
+ }
22
+
23
+ /** Resolve an item without loading uncached item details. */
24
+ export function readItemId(this: void, item: string | number): number | undefined {
25
+ const id = reveal(api.C_Item.GetItemInfoInstant(item)[0]);
26
+ return validId(id) ? id : undefined;
27
+ }
28
+
29
+ /** Visit readable bag items in slot order. Return false from the visitor to stop. */
30
+ export function visitBagItems(this: void, visit: (this: void, id: number, link?: string) => boolean): void {
31
+ const containers = api.C_Container;
32
+ const bagLimit = reveal(api.NUM_TOTAL_EQUIPPED_BAG_SLOTS);
33
+ const lastBag = bagLimit !== undefined && Number.isFinite(bagLimit) ? bagLimit : 5;
34
+ for (let bag = 0; bag <= lastBag; bag += 1) {
35
+ const slots = readCount(containers.GetContainerNumSlots(bag));
36
+ for (let slot = 1; slot <= slots; slot += 1) {
37
+ const item = readTable(containers.GetContainerItemInfo(bag, slot));
38
+ if (item === undefined) continue;
39
+ const id = reveal(item.itemID);
40
+ if (validId(id) && !visit(id, reveal(item.hyperlink))) return;
41
+ }
42
+ }
43
+ }
44
+
45
+ /** Visit collected toys currently listed by the client's Toy Box filter. */
46
+ export function visitCollectedToys(this: void, visit: VisitAction): void {
47
+ const book = api.C_ToyBox;
48
+ if (book === undefined) return;
49
+ const count = readCount(book.GetNumFilteredToys());
50
+ for (let index = 1; index <= count; index += 1) {
51
+ const id = reveal(book.GetToyFromIndex(index));
52
+ if (!validId(id) || reveal(api.PlayerHasToy(id)) !== true) continue;
53
+ const [, name] = book.GetToyInfo(id);
54
+ if (!visit(id, reveal(name))) return;
55
+ }
56
+ }
57
+
58
+ function visitFlyout(id: number, visit: VisitAction): boolean {
59
+ const readInfo = api.GetFlyoutInfo;
60
+ const readSlot = api.GetFlyoutSlotInfo;
61
+ if (readInfo === undefined || readSlot === undefined) return true;
62
+ const [, , size, known] = readInfo(id);
63
+ if (reveal(known) !== true) return true;
64
+ const count = readCount(size);
65
+ for (let slot = 1; slot <= count; slot += 1) {
66
+ const [spell, override, learned, name] = readSlot(id, slot);
67
+ if (reveal(learned) !== true) continue;
68
+ const spellId = reveal(override) ?? reveal(spell);
69
+ if (validId(spellId) && !visit(spellId, reveal(name))) return false;
70
+ }
71
+ return true;
72
+ }
73
+
74
+ /** Visit visible, active player spellbook entries and learned flyout spells. */
75
+ export function visitPlayerSpells(this: void, visit: VisitAction): void {
76
+ const book = api.C_SpellBook;
77
+ const bank = api.Enum.SpellBookSpellBank.Player;
78
+ const types = api.Enum.SpellBookItemType;
79
+ const lines = readCount(book.GetNumSpellBookSkillLines());
80
+ for (let line = 1; line <= lines; line += 1) {
81
+ const info = readTable(book.GetSpellBookSkillLineInfo(line));
82
+ if (info === undefined || reveal(info.shouldHide) === true) continue;
83
+ const offset = reveal(info.itemIndexOffset) ?? 0;
84
+ const count = readCount(info.numSpellBookItems);
85
+ for (let index = 1; index <= count; index += 1) {
86
+ const entry = readTable(book.GetSpellBookItemInfo(offset + index, bank));
87
+ if (entry === undefined || reveal(entry.isOffSpec) === true || reveal(entry.isPassive) === true) continue;
88
+ const type = reveal(entry.itemType);
89
+ if (type === types.Spell) {
90
+ const spell = reveal(entry.spellID);
91
+ if (validId(spell) && !visit(spell, reveal(entry.name))) return;
92
+ } else if (type === types.Flyout) {
93
+ const flyout = reveal(entry.actionID);
94
+ if (validId(flyout) && !visitFlyout(flyout, visit)) return;
95
+ }
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,38 @@
1
+ import type { OwnedLuaArray } from "../src/owned-collections";
2
+ import type { StyleVariables } from "../src/style-variables";
3
+ import { rawField } from "./lua-table";
4
+
5
+ // The compiler binds this to the addon's private table: the second value WoW passes to each addon file.
6
+ declare const kumiAddonTable: object | undefined;
7
+
8
+ export interface PluginManifest {
9
+ readonly id: string;
10
+ /** The plugin's addon folder, `<addon>_<id>`. */
11
+ readonly addon: string;
12
+ readonly title: string;
13
+ readonly notes: string;
14
+ readonly load: "startup" | "demand";
15
+ }
16
+
17
+ /** @internal What kumi build wrote to KumiAddon.lua for this addon. */
18
+ export interface AddonManifest {
19
+ readonly name: string;
20
+ readonly savedVariables?: string;
21
+ readonly savedVariablesPerCharacter?: string;
22
+ readonly styleVariables?: StyleVariables;
23
+ readonly pluginState: "account" | "character";
24
+ /** A Lua list written by KumiAddon.lua. Read it with an index loop. */
25
+ readonly plugins: OwnedLuaArray<PluginManifest>;
26
+ /** Plugin modules registered by their generated entries, by plugin ID. */
27
+ readonly registered: Record<string, object | undefined>;
28
+ /** Errors raised while a plugin's file ran, by plugin ID. */
29
+ readonly failures: Record<string, string | undefined>;
30
+ started: boolean;
31
+ /** The demand plugin whose files WoW is loading right now. */
32
+ loading?: string;
33
+ }
34
+
35
+ /** @internal The manifest of the running addon, or undefined when the addon was not built by kumi build. */
36
+ export function addonManifest(this: void): AddonManifest | undefined {
37
+ return rawField<AddonManifest>(kumiAddonTable, "KumiAddon");
38
+ }
package/wow/animation.ts CHANGED
@@ -3,6 +3,7 @@ import type { RuntimeScope } from "../src/runtime";
3
3
  import { fail, ok, type Result } from "../src/result";
4
4
  import { currentScope } 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,13 +25,7 @@ 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
- /** "reduced" freezes loops on their first pose and finishes one-shots at once. */
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
  /**
@@ -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);
@@ -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 ?? defaults.motion)?.() === "reduced";
197
+ return isReducedMotion(options.motion);
209
198
  }
210
199
 
211
200
  function skipToEnd() {