@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
@@ -9,6 +9,7 @@ import type { ElementEventCoordinator } from "./element-event-coordinator";
9
9
  import type { Button, CommonScripts, Frame } from "./frames";
10
10
  import { hookButtonClick, hookScript } from "./native-hooks";
11
11
  import { api, isSecret, reveal } from "./native";
12
+ import { createPointerClickGate } from "./pointer-click";
12
13
  import { createProtectedLayoutUpdate } from "./protected-layout";
13
14
  import { protect } from "./protect";
14
15
  import { hitViewNode, type LogicalNode } from "./view-nodes";
@@ -27,7 +28,7 @@ export interface ElementStyleInput {
27
28
  set(this: void, state: StyleState, active: boolean): void;
28
29
  }
29
30
 
30
- type ElementInput = ElementEvents & { onShow?(this: void): void; onHide?(this: void): void };
31
+ type ElementInput = ElementEvents & { clickMaxDuration?: number; onShow?(this: void): void; onHide?(this: void): void };
31
32
  type HitRegion = Pick<Frame, "IsVisible" | "IsMouseOver" | "IsForbidden">;
32
33
  type HitCandidate = Partial<HitRegion> & { mouseHit?(this: object): boolean | undefined; value?: HitCandidate };
33
34
  type ScopeFactory = (this: void) => RuntimeScope;
@@ -104,6 +105,12 @@ export function bindElementEvents(this: void, frame: Frame, input: ElementInput,
104
105
  if (!hasElementInput(input) && !hover && !activeStyle && disabledStyle === undefined) return;
105
106
  if (!canChange(frame)) return fail("Element input target is inaccessible or restricted");
106
107
  if (input.tooltip !== undefined && host?.tooltip === undefined) return fail("Element tooltip requires the host tooltip port");
108
+ const clickMaxDuration = input.clickMaxDuration;
109
+ if (clickMaxDuration !== undefined && (!Number.isFinite(clickMaxDuration) || clickMaxDuration <= 0)) {
110
+ return fail("Button clickMaxDuration must be a positive number of seconds");
111
+ }
112
+ const gate = button !== undefined && input.onClick !== undefined && clickMaxDuration !== undefined
113
+ ? createPointerClickGate(clickMaxDuration) : undefined;
107
114
  const outside = input.onClickOutside !== undefined || input.onDismiss !== undefined || input.ignoreOutside === true;
108
115
  const coordinator = host?.coordinator;
109
116
  if (outside && coordinator === undefined) return fail("Outside dismissal requires the shared element event coordinator");
@@ -121,14 +128,14 @@ export function bindElementEvents(this: void, frame: Frame, input: ElementInput,
121
128
 
122
129
  const restorers = ownedArray<Cancel>();
123
130
  const motion = hover || activeStyle || input.onPointerEnter !== undefined || input.onPointerLeave !== undefined || input.tooltip !== undefined;
124
- const pressed = activeStyle || (button === undefined && input.onClick !== undefined) ? ownedSet<MouseButton>() : undefined;
131
+ const pressed = activeStyle || gate !== undefined || (button === undefined && input.onClick !== undefined) ? ownedSet<MouseButton>() : undefined;
125
132
  const observesVisibility = pressed !== undefined || outside || input.onShow !== undefined || input.onHide !== undefined
126
133
  || input.tooltip !== undefined || hover;
127
134
  let hoveredTip: Cancel | undefined;
128
135
  let visible = false;
129
136
  let active = true;
130
137
  let ownCleanup: RuntimeScope | undefined;
131
- let request: ((this: void) => Result<void>) | undefined;
138
+ let deferred: { readonly scope: RuntimeScope; readonly request: (this: void) => Result<void> } | undefined;
132
139
 
133
140
  function live() { return active && owner.isActive(); }
134
141
 
@@ -147,6 +154,7 @@ export function bindElementEvents(this: void, frame: Frame, input: ElementInput,
147
154
  const visibleValue = typeof frame.IsVisible === "function" ? reveal(frame.IsVisible()) : reveal(frame.IsShown());
148
155
  const shown = visibleValue === true;
149
156
  if (!shown) {
157
+ gate?.clear();
150
158
  if (pressed !== undefined) pressed.clear();
151
159
  if (activeStyle) style?.set("active", false);
152
160
  if (hover) style?.set("hover", false);
@@ -185,7 +193,7 @@ export function bindElementEvents(this: void, frame: Frame, input: ElementInput,
185
193
  restorers.length = 0;
186
194
  const temporary = ownCleanup;
187
195
  ownCleanup = undefined;
188
- request = undefined;
196
+ deferred = undefined;
189
197
  temporary?.dispose();
190
198
  return failure;
191
199
  }
@@ -215,7 +223,7 @@ export function bindElementEvents(this: void, frame: Frame, input: ElementInput,
215
223
  handler => hookButtonClick(button, handler, owner), (_self, raw) => {
216
224
  if (!live() || isSecret(raw)) return;
217
225
  const event = readClickEvent(raw === undefined ? "LeftButton" : raw);
218
- if (event !== undefined) click(event);
226
+ if (event !== undefined && (gate === undefined || gate.accept(event.button))) click(event);
219
227
  }, hookOnly, restorers);
220
228
  if (failure !== undefined) return failure;
221
229
  }
@@ -224,16 +232,20 @@ export function bindElementEvents(this: void, frame: Frame, input: ElementInput,
224
232
  if (!live() || reveal(frame.IsMouseOver()) !== true) return;
225
233
  const key = readMouseButton(raw);
226
234
  if (key === undefined) return;
235
+ gate?.press(key);
227
236
  pressed.add(key);
228
237
  if (activeStyle) style?.set("active", true);
229
238
  }) ?? listen("OnDragStart", () => {
230
239
  if (!live()) return;
240
+ gate?.drag();
231
241
  pressed.clear();
232
242
  if (activeStyle) style?.set("active", false);
233
243
  }) ?? listen("OnMouseUp", (_self, raw) => {
234
244
  if (!live()) return;
235
245
  const key = readMouseButton(raw);
236
- if (key === undefined || !pressed.delete(key)) return;
246
+ if (key === undefined) return;
247
+ gate?.release(key);
248
+ if (!pressed.delete(key)) return;
237
249
  const over = reveal(frame.IsMouseOver()) === true;
238
250
  if (activeStyle) style?.set("active", over && pressed.size > 0);
239
251
  if (button !== undefined || input.onClick === undefined || !over || reveal(frame.IsDragging?.()) === true) return;
@@ -292,13 +304,18 @@ export function bindElementEvents(this: void, frame: Frame, input: ElementInput,
292
304
 
293
305
  function reconcile(): Result<void> {
294
306
  if (protectedFrame(frame)) {
295
- if (request === undefined) {
296
- const lifetime = coordinator?.scope ?? (ownCleanup = newScope());
307
+ if (deferred === undefined || !deferred.scope.isActive()) {
308
+ const hostScope = coordinator?.scope;
309
+ const lifetime = hostScope?.isActive() === true ? hostScope : (ownCleanup = newScope());
297
310
  const queue = createProtectedLayoutUpdate(update, { scope: lifetime, label: "Element input scripts" });
298
- if (!queue.ok) { ownCleanup?.dispose(); return queue; }
299
- request = queue.value.request;
311
+ if (!queue.ok) {
312
+ ownCleanup?.dispose();
313
+ ownCleanup = undefined;
314
+ return queue;
315
+ }
316
+ deferred = { scope: lifetime, request: queue.value.request };
300
317
  }
301
- return request();
318
+ return deferred.request();
302
319
  }
303
320
  const configured = protect(update);
304
321
  return configured.ok ? configured.value ?? ok(undefined) : configured;
@@ -308,8 +325,11 @@ export function bindElementEvents(this: void, frame: Frame, input: ElementInput,
308
325
  active = false;
309
326
  closeTip();
310
327
  lease?.cancel();
311
- if (restorers.length === 0 && request === undefined) return;
312
- report(request?.() ?? reconcile());
328
+ if (restorers.length === 0) {
329
+ report(restore());
330
+ return;
331
+ }
332
+ report(deferred?.scope.isActive() === true ? deferred.request() : reconcile());
313
333
  });
314
334
  if (!cleanup.ok) return cleanup;
315
335
  const result = reconcile();
@@ -1,5 +1,5 @@
1
1
  import { fail, ok, type Result } from "../src/result";
2
- import type { Frame, FrameEventRegistration, Region, Texture } from "./frames";
2
+ import type { FontString, Frame, FrameEventRegistration, FrameMap, Region, Texture } from "./frames";
3
3
  import { reveal, type SecretValue } from "./native";
4
4
  import { protect } from "./protect";
5
5
 
@@ -10,6 +10,28 @@ export function canAccessRegion<T extends NativeRegion>(region: T | SecretValue<
10
10
  return readable !== undefined && reveal(readable.IsForbidden()) === false;
11
11
  }
12
12
 
13
+ export function readFrameWidth(this: void, region: Pick<Frame, "GetWidth">): number | undefined {
14
+ return reveal(region.GetWidth());
15
+ }
16
+
17
+ export function readFrameHeight(this: void, region: Pick<Frame, "GetHeight">): number | undefined {
18
+ return reveal(region.GetHeight());
19
+ }
20
+
21
+ export function readFrameScale(this: void, region: Pick<Frame, "GetEffectiveScale">): number | undefined {
22
+ return reveal(region.GetEffectiveScale());
23
+ }
24
+
25
+ export function readFrameShown(this: void, region: Pick<Frame, "IsShown">): boolean | undefined {
26
+ return reveal(region.IsShown());
27
+ }
28
+
29
+ export function readFontPath(this: void, region: FontString | FrameMap["EditBox"]): string | undefined {
30
+ const [raw] = region.GetFont();
31
+ const path = reveal(raw);
32
+ return typeof path === "string" ? path : undefined;
33
+ }
34
+
13
35
  /** Read a texture from a heterogeneous native region list. */
14
36
  export function asTexture(region: Region | SecretValue<Region> | undefined): Texture | undefined {
15
37
  if (canAccessRegion(region) && reveal(region.IsObjectType("Texture")) === true) {
@@ -0,0 +1,13 @@
1
+ import { createFrameDriver } from "../src/frame-scheduler";
2
+ import { clock } from "./clock";
3
+ import { rawField } from "./lua-table";
4
+ import { api } from "./native";
5
+
6
+ const profileClock = rawField<(this: void) => number>(api, "debugprofilestop");
7
+
8
+ /** The addon's frame clock and combat state for the scheduler. */
9
+ export const frameTiming = {
10
+ nowMs: () => profileClock?.() ?? api.GetTime() * 1000,
11
+ inCombat: () => api.InCombatLockdown() === true,
12
+ };
13
+ export const frameDriver = createFrameDriver(clock, frameTiming);
@@ -3,6 +3,7 @@ import { fail, ok, type Result } from "../src/result";
3
3
  import { createFrame, type Frame, type FrameParent, type StatusBar, type Texture } from "./frames";
4
4
  import { api, isSecret, reveal, type SecretValue } from "./native";
5
5
  import { protectNative } from "./protect";
6
+ import { setTextureFill } from "./texture-fill";
6
7
 
7
8
  type Amount = number | SecretValue<number>;
8
9
  type Mask = Parameters<Texture["AddMaskTexture"]>[0];
@@ -63,10 +64,7 @@ function paint(overlay: Overlay, fallback: Color, style?: HealPredictionStyle):
63
64
  const assetChanged = color === undefined || overlay.asset !== asset;
64
65
  if (assetChanged) {
65
66
  const tiled = asset !== undefined;
66
- if (tiled) overlay.fill.SetTexture(asset, "REPEAT", "REPEAT");
67
- else overlay.fill.SetTexture(white);
68
- overlay.fill.SetHorizTile(tiled);
69
- overlay.fill.SetVertTile(tiled);
67
+ setTextureFill(overlay.fill, asset ?? white, tiled, tiled);
70
68
  overlay.asset = asset;
71
69
  }
72
70
  if (assetChanged || color === undefined || color[0] !== r || color[1] !== g || color[2] !== b || color[3] !== a) {
package/wow/hooks.ts ADDED
@@ -0,0 +1,133 @@
1
+ import { currentScope } from "../src/reactive-scope";
2
+ import { ref, type ReadonlyRef, type SignalRef } from "../src/reactivity";
3
+ import type { OwnedReadonlyArray } from "../src/owned-collections";
4
+ import type { RuntimeScope } from "../src/runtime";
5
+ import { appContext } from "./app-ui";
6
+ import type { EventOptions, WoWEvent, WoWEventMap } from "./contract";
7
+ import { setRawField } from "./lua-table";
8
+ import { api, reveal } from "./native";
9
+
10
+ function owner(name: string): RuntimeScope {
11
+ const scope = currentScope();
12
+ if (scope === undefined) throw new Error(name + " works during the setup of a component or store");
13
+ return scope;
14
+ }
15
+
16
+ /**
17
+ * Run `handler` for a WoW event while the calling component or store is alive.
18
+ *
19
+ * ```ts
20
+ * useEvent("PLAYER_MONEY", () => { money.value = readMoney(); });
21
+ * ```
22
+ */
23
+ export function useEvent<Event extends WoWEvent>(this: void, event: Event,
24
+ handler: (this: void, ...payload: WoWEventMap[Event]) => void, options?: EventOptions): void {
25
+ const scope = owner("useEvent");
26
+ const context = appContext();
27
+ if (context === undefined) throw new Error("useEvent needs a running addon");
28
+ const subscribed = context.events.on(scope, event, handler, options);
29
+ if (!subscribed.ok) throw new Error(subscribed.reason);
30
+ }
31
+
32
+ /** Run `cleanup` when the calling component or store goes away. */
33
+ export function onCleanup(this: void, cleanup: (this: void) => void): void {
34
+ const registered = owner("onCleanup").onDispose(cleanup);
35
+ if (!registered.ok) throw new Error(registered.reason);
36
+ }
37
+
38
+ interface Clock {
39
+ readonly time: SignalRef<number>;
40
+ users: number;
41
+ cancel?: (this: void) => void;
42
+ }
43
+
44
+ const clocks: Record<number, Clock | undefined> = {};
45
+
46
+ function gameTime() {
47
+ const time = reveal(api.GetTime());
48
+ return typeof time === "number" ? time : 0;
49
+ }
50
+
51
+ /**
52
+ * The game time in seconds, updated every `interval` seconds while the caller is alive.
53
+ * Components that use the same interval share one timer.
54
+ */
55
+ export function useNow(this: void, interval = 1): ReadonlyRef<number> {
56
+ const scope = owner("useNow");
57
+ if (!(interval > 0)) throw new Error("useNow needs a positive interval");
58
+ let clock = clocks[interval];
59
+ if (clock === undefined) {
60
+ clock = { time: ref(gameTime()), users: 0 };
61
+ clocks[interval] = clock;
62
+ }
63
+ const shared = clock;
64
+ if (shared.users === 0) {
65
+ shared.time.value = gameTime();
66
+ const ticker = api.C_Timer.NewTicker(interval, () => { shared.time.value = gameTime(); });
67
+ shared.cancel = () => { (ticker as unknown as { Cancel(this: object): void }).Cancel(); };
68
+ }
69
+ shared.users++;
70
+ scope.onDispose(() => {
71
+ shared.users--;
72
+ if (shared.users > 0) return;
73
+ shared.cancel?.();
74
+ shared.cancel = undefined;
75
+ });
76
+ return shared.time;
77
+ }
78
+
79
+ let combat: SignalRef<boolean> | undefined;
80
+ let combatUsers = 0;
81
+
82
+ /** Whether the player is in combat. Protected changes, such as secure buttons or loading plugins, wait for false. */
83
+ export function useCombat(this: void): ReadonlyRef<boolean> {
84
+ const scope = owner("useCombat");
85
+ const context = appContext();
86
+ if (context === undefined) throw new Error("useCombat needs a running addon");
87
+ const state = combat ??= ref(reveal(api.InCombatLockdown()) === true);
88
+ if (combatUsers === 0) state.value = reveal(api.InCombatLockdown()) === true;
89
+ combatUsers++;
90
+ const started = context.events.on(scope, "PLAYER_REGEN_DISABLED", () => { state.value = true; });
91
+ if (!started.ok) throw new Error(started.reason);
92
+ const ended = context.events.on(scope, "PLAYER_REGEN_ENABLED", () => { state.value = false; });
93
+ if (!ended.ok) throw new Error(ended.reason);
94
+ scope.onDispose(() => { combatUsers--; });
95
+ return state;
96
+ }
97
+
98
+ function commandName(name: string): boolean {
99
+ if (name.length < 2 || name.charCodeAt(0) !== 47) return false;
100
+ for (let index = 1; index < name.length; index++) {
101
+ const code = name.charCodeAt(index);
102
+ const letter = code >= 65 && code <= 90 || code >= 97 && code <= 122;
103
+ const digit = code >= 48 && code <= 57;
104
+ if (!letter && !digit && code !== 95 && code !== 45) return false;
105
+ }
106
+ return true;
107
+ }
108
+
109
+ /**
110
+ * Register a slash command while the caller is alive. The first name is the command's ID.
111
+ *
112
+ * ```ts
113
+ * useSlashCommand(["/sessions", "/st"], input => { useWindow().toggle(); });
114
+ * ```
115
+ */
116
+ export function useSlashCommand(this: void, commands: readonly string[], handler: (this: void, input: string) => void): void {
117
+ const scope = owner("useSlashCommand");
118
+ const names = commands as OwnedReadonlyArray<string>;
119
+ if (names.length === 0 || names.some(name => !commandName(name))) {
120
+ throw new Error("useSlashCommand needs names such as /myaddon: a slash, then letters, digits, _ or -");
121
+ }
122
+ const key = "KUMI_" + names[0].slice(1).toUpperCase().split("-").join("_");
123
+ const globals = api as unknown as object;
124
+ const list = api.SlashCmdList;
125
+ if (list === undefined) throw new Error("This client has no slash commands");
126
+ if (list[key] !== undefined) throw new Error("Slash command " + names[0] + " is already registered");
127
+ for (let index = 0; index < names.length; index++) setRawField(globals, "SLASH_" + key + String(index + 1), names[index]);
128
+ list[key] = input => { handler(input.trim()); };
129
+ scope.onDispose(() => {
130
+ list[key] = undefined as never;
131
+ for (let index = 0; index < names.length; index++) setRawField(globals, "SLASH_" + key + String(index + 1), undefined);
132
+ });
133
+ }
package/wow/index.ts CHANGED
@@ -1,14 +1,19 @@
1
1
  import type { WoWApi } from "./contract";
2
2
  import { api, isSecret, reveal } from "./native";
3
3
  import { cvars } from "./cvars";
4
- import { frameTiming } from "./start-addon";
4
+ import { frameTiming } from "./frame-timing";
5
5
  export { api, isSecret, reveal } from "./native";
6
+ export { readableApi } from "./readable-api";
7
+ export { hasCursorAction, readCursorAction, readCursorKind, type CursorAction } from "./cursor";
8
+ export type { ReadableSpellCooldown } from "./spell-cooldown";
6
9
  export { nativeRef, secretSafeEquals } from "./secret-ref";
7
10
  export type { LuaMultiReturn, SecretValue, UnitToken, WoWGlobals } from "./native";
8
11
  export { createFrame, smoothStatusBarValue } from "./frames";
9
12
  export { createFontCache, type FontCache, type FontCacheOptions, type FontObject, type FontOutline } from "./font-cache";
10
- export { createRoundedTextures, type MaskedStatusBarFill, type RoundedTextureOptions, type RoundedTextureResolverOptions, type RoundedTextures, type RoundedTextureSide } from "./rounded-texture";
13
+ export { createLocaleFont } from "./locale-font";
14
+ export { createRoundedTextures, type MaskedStatusBarFill, type RoundedBorderCorner, type RoundedTextureOptions, type RoundedTextureResolverOptions, type RoundedTextures, type RoundedTextureSide } from "./rounded-texture";
11
15
  export { createBarShade, type BarShade, type BarShadeOptions, type BarShadeStyle } from "./bar-shade";
16
+ export { setTextureFill } from "./texture-fill";
12
17
  export { reparentFrame } from "./reparent-frame";
13
18
  export { bindContainedFrame, createContainedFrame } from "./contained-frame";
14
19
  export { bindAbsolutePosition } from "./absolute-position";
@@ -25,15 +30,21 @@ export { secureChildUpdateSnippet, secureSnippet, secureStateSnippet, wrapSecure
25
30
  export type { SecureFrameHandle, SecureSnippet, SecureSnippetEvent, SecureSnippetOptions, SecureSnippetValue, WrapSecureSnippetOptions } from "./secure-snippet";
26
31
  export type { SecureButton, SecureFrame, SecureInstallation, SecureOptions } from "./secure-transaction";
27
32
  export { createProtectedLayoutUpdate, type ProtectedLayoutOptions, type ProtectedLayoutUpdate } from "./protected-layout";
33
+ export { mountProtectedView, type ProtectedViewOptions } from "./protected-view";
34
+ export { useActionBarLayout, type ActionBarLayoutOptions, type ActionBarPosition } from "./action-bar-layout";
35
+ export { createNativePanel } from "./panel-host";
28
36
  export { scheduleVisibleFrameUpdate } from "./visible-frame-job";
29
37
  export { castInterrupter, castNotInterruptible, getUnitCastDuration, readUnitCast } from "./unit-cast";
30
38
  export type { UnitCast, UnitCastDuration, UnitCastEvent, UnitCastInterrupter } from "./unit-cast";
31
39
  export { createCastClock, type CastClockOptions } from "./cast-clock";
40
+ export { readCooldownTiming, type CooldownTiming } from "./cooldown-timing";
32
41
  export { paintCastInterruption, paintCastSpell, type CastSpellDisplay } from "./cast-text";
33
42
  export { renderUnitHealthText, type UnitHealthTextMode, type UnitHealthTextOptions } from "./unit-health-text";
34
43
  export type { AnimationGroup, NativeAnimationKind, NativeAnimationOf, BackdropFrame, BackdropInfo, Button, FontString, Frame, FrameEventRegistration, FrameMap, MaskTexture, FrameType, FrameParent, MinimapFrame,
35
44
  Region, StatusBar, Texture } from "./frames";
36
- export { asTexture, canAccessRegion, setFrameEventListening } from "./frame-access";
45
+ export { asTexture, canAccessRegion, readFontPath, readFrameHeight, readFrameScale, readFrameShown, readFrameWidth,
46
+ setFrameEventListening } from "./frame-access";
47
+ export { readItemId, visitBagItems, visitCollectedToys, visitPlayerSpells } from "./action-catalog";
37
48
  export { createEvents } from "./events";
38
49
  export { createEventDispatcher, type EventDispatcherFrame } from "./event-dispatcher";
39
50
  export { addonRuntime, frameDriver, frameTiming, startAddon, type AddonContext, type AddonStart, type AddonStartOptions } from "./start-addon";
@@ -67,11 +78,15 @@ export type { FrameStrata } from "./frame-layer";
67
78
  export type { CreateScrollArea, ScrollArea } from "./scroll-view";
68
79
  export { protect } from "./protect";
69
80
  export { luaString } from "./lua-string";
81
+ export { physicalPixel, snapPixel, watchDisplayMetrics } from "./pixel";
70
82
  export { formatWoWNumber } from "./number-format";
71
83
  export { clampWoWNumber } from "./number-input";
72
84
  export { formatMapCoordinates, readPlayerMapPosition } from "./map-position";
73
85
  export { rawField, setRawField, weakKeys } from "./lua-table";
74
- export { savedVariablesStorage, type SavedVariablesOptions } from "./saved-variables";
86
+ export { savedVariablesStorage, type SavedRecord, type SavedValue, type SavedVariablesOptions } from "./saved-variables";
87
+ export { usePlugins, type KumiPlugins, type PluginId, type PluginInfo, type PluginServices, type PluginStatus } from "./plugins";
88
+ export { useViewHost, useWindow, type AppTheme } from "./app-ui";
89
+ export { onCleanup, useCombat, useEvent, useNow, useSlashCommand } from "./hooks";
75
90
  export type { EventApi, EventOptions, EventScope, WoWEvent, WoWEventMap } from "./contract";
76
91
 
77
92
  declare const DoReadyCheck: ((this: void) => void) | undefined;
@@ -1,5 +1,6 @@
1
1
  import type { Binding, Element, RuntimeScope } from "../src";
2
- import { layoutPercent, solveLayout, type FlexLayout, type FlexNode, type LayoutStyle, type LayoutRect, type LayoutSize } from "../src/flex-layout";
2
+ import { isBindingRef } from "../src/bindings";
3
+ import { isIntrinsicWidth, layoutPercent, solveLayout, type FlexLayout, type FlexNode, type LayoutStyle, type LayoutRect, type LayoutSize } from "../src/flex-layout";
3
4
  import { parseGridSpan, parseGridTracks } from "../src/grid-tracks";
4
5
  import type { OwnedArray, OwnedLuaArray, OwnedReadonlyArray, OwnedRecord, OwnedSet } from "../src/owned-collections";
5
6
  import { fail, ok, type Failure, type Result } from "../src/result";
@@ -8,6 +9,7 @@ import { canAccessRegion } from "./frame-access";
8
9
  import type { FontString, Frame, FrameParent } from "./frames";
9
10
  import { api, isSecret, reveal } from "./native";
10
11
  import { hookScript } from "./native-hooks";
12
+ import { physicalPixel, watchDisplayMetrics } from "./pixel";
11
13
  import { protect } from "./protect";
12
14
  import { createProtectedLayoutUpdate, type ProtectedLayoutUpdate } from "./protected-layout";
13
15
 
@@ -54,7 +56,7 @@ export function readLayoutValue<T>(this: void, binding: Binding<T> | undefined):
54
56
  if (isSecret(binding)) return fail("Layout properties require readable values");
55
57
  if (binding === undefined) return missingLayoutValue;
56
58
  if (binding === null) return fail("Invalid layout binding");
57
- if (typeof binding !== "object" || !("value" in binding)) return ok(binding as T);
59
+ if (!isBindingRef(binding)) return ok(binding as T);
58
60
  const value = binding.value;
59
61
  if (isSecret(value)) return fail("Layout properties require readable values");
60
62
  if (typeof value === "object" && value !== null && "ok" in value) {
@@ -101,10 +103,12 @@ function resolveLayout(props: Layout): Result<LayoutStyle> {
101
103
  const size = readLayoutValue(key === "flexBasis" ? style?.flexBasis : props[key] ?? style?.[key]);
102
104
  if (!size.ok) return size;
103
105
  if (size.value === undefined) continue;
104
- if (size.value !== "auto" && !validNumber(size.value) && (key === "flexBasis" || layoutPercent(size.value) === undefined)) {
106
+ if (size.value !== "auto" && !validNumber(size.value)
107
+ && !(key === "width" && isIntrinsicWidth(size.value)) && (key === "flexBasis" || layoutPercent(size.value) === undefined)) {
105
108
  return fail("Invalid layout " + key);
106
109
  }
107
- result[key] = size.value;
110
+ if (key === "width") result.width = size.value;
111
+ else if (!isIntrinsicWidth(size.value)) result[key] = size.value;
108
112
  }
109
113
  for (const key of insetKeys) {
110
114
  const inset = readLayoutValue(style?.[key]);
@@ -265,12 +269,13 @@ export class NativeLayoutItem {
265
269
  const shown = props.style?.display === "none" ? ok(false) : readLayoutValue(props.shown);
266
270
  if (!shown.ok) return shown;
267
271
  const visible = shown.value !== false;
268
- if (visible === this.shown && this.style !== undefined && sameLayoutValue(this.style, next.value)) return;
269
- const hide = !visible && this.shown;
272
+ const changed = this.style === undefined || !sameLayoutValue(this.style, next.value);
273
+ if (visible === this.shown && !changed) return;
274
+ const visibilityChanged = visible !== this.shown;
270
275
  this.style = next.value;
271
276
  this.shown = visible;
272
- if (hide) this.updateVisibility();
273
- this.group.enqueue();
277
+ if (visibilityChanged && (!visible || !this.inFlow && !changed)) this.updateVisibility();
278
+ if (changed || this.inFlow) this.group.enqueue();
274
279
  });
275
280
  if (!sub.ok) return sub;
276
281
  this.region.SetShown(false);
@@ -282,6 +287,13 @@ export class NativeLayoutItem {
282
287
  this.updateVisibility();
283
288
  }
284
289
 
290
+ retire(): void {
291
+ // A keyed list can still reference the row until it publishes its new order.
292
+ this.shown = false;
293
+ this.group.visibility.delete(this);
294
+ if (acceptRegion(this.region).ok) this.region.SetShown(false);
295
+ }
296
+
285
297
  private updateVisibility() {
286
298
  if (this.lastRect === undefined) return;
287
299
  if (acceptRegion(this.region).ok) this.commitVisibility();
@@ -509,22 +521,27 @@ function createTextMeasurer(root: Frame, retry: (this: void) => void, pixel: (th
509
521
  };
510
522
  }
511
523
 
512
- function localPixel(frame: Frame): number {
513
- const [, screenHeight] = api.GetPhysicalScreenSize();
514
- const scale = frame.GetEffectiveScale();
515
- return validNumber(scale) && scale > 0 && validNumber(screenHeight) && screenHeight > 0 ? 768 / screenHeight / scale : 1;
524
+ export function isAbsoluteFill(this: void, props: Layout): boolean {
525
+ const { style } = props;
526
+ return props.anchor === undefined && style?.position === "absolute"
527
+ && style.top === 0 && style.right === 0 && style.bottom === 0 && style.left === 0 && style.autoMargin === undefined
528
+ && props.width === undefined && style.width === undefined && props.height === undefined && style.height === undefined;
516
529
  }
517
530
 
518
531
  export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, props: Layout, scope: RuntimeScope,
519
- diagnostics?: NativeLayoutDiagnostics, stageInitial?: StageInitialLayout): Result<NativeLayoutItem> {
520
- // The root keeps its own anchors: layout only reads the parent's width, so the parent is not an anchor target.
532
+ diagnostics?: NativeLayoutDiagnostics, stageInitial?: StageInitialLayout, measure?: Measure): Result<NativeLayoutItem> {
533
+ // The root keeps its own anchors. A zero-inset absolute root gets both axes from its containing block.
521
534
  const supported = acceptParent(parent, "ancestor");
522
535
  if (!supported.ok) return supported;
523
536
  const safe = acceptRegion(frame);
524
537
  if (!safe.ok) return safe;
525
538
  const owner = supported.value;
526
539
  const key = {};
527
- let availableWidth = props.fullWidth ? readSize(owner).width : undefined;
540
+ const fillsParent = isAbsoluteFill(props);
541
+ const readWidth = fillsParent || props.fullWidth === true;
542
+ const measured = readWidth ? readSize(owner) : empty;
543
+ let availableWidth = readWidth ? measured.width : undefined;
544
+ let availableHeight = fillsParent ? measured.height : undefined;
528
545
  let scale = reveal(frame.GetEffectiveScale());
529
546
  let committing = false;
530
547
  let waiting = false;
@@ -567,8 +584,8 @@ export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, p
567
584
  const safe = acceptRegion(item.region);
568
585
  if (!safe.ok) return safe;
569
586
  }
570
- pixel = localPixel(frame);
571
- const result = solveLayout(tree.node, { width: availableWidth });
587
+ pixel = physicalPixel(frame);
588
+ const result = solveLayout(tree.node, { width: availableWidth, height: availableHeight });
572
589
  if (!finiteLayout(result)) return fail("Layout resolved nonfinite geometry");
573
590
  committing = true;
574
591
  const moved = [] as NativeLayoutItem[] as OwnedArray<NativeLayoutItem>;
@@ -608,8 +625,8 @@ export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, p
608
625
  }
609
626
  }
610
627
 
611
- root = new NativeLayoutItem(frame, parent, false, props.fullWidth === true, true,
612
- { enqueue, children: [] as Flow[] as OwnedArray<Flow>, visibility, textMeasure });
628
+ root = new NativeLayoutItem(frame, parent, false, props.fullWidth === true, measure === undefined,
629
+ { enqueue, children: [] as Flow[] as OwnedArray<Flow>, visibility, textMeasure }, measure);
613
630
  const cleanup = scope.onDispose(() => {
614
631
  scope.frameJobs.cancel(key);
615
632
  scope.frameJobs.cancel(repairKey);
@@ -618,14 +635,19 @@ export function mountLayoutRoot(this: void, frame: Frame, parent: FrameParent, p
618
635
  if (!cleanup.ok) return cleanup;
619
636
  const resize = hookScript(owner, "OnSizeChanged", () => {
620
637
  if (committing) return;
621
- const width = props.fullWidth ? readSize(owner).width : undefined;
638
+ const size = readWidth ? readSize(owner) : empty;
639
+ const width = readWidth ? size.width : undefined;
640
+ const height = fillsParent ? size.height : undefined;
622
641
  const currentScale = reveal(frame.GetEffectiveScale());
623
- if (width === availableWidth && currentScale === scale) return;
642
+ if (width === availableWidth && height === availableHeight && currentScale === scale) return;
624
643
  availableWidth = width;
644
+ availableHeight = height;
625
645
  scale = currentScale;
626
646
  enqueue();
627
647
  }, scope);
628
648
  if (!resize.ok) return resize;
649
+ const metrics = watchDisplayMetrics(scope, enqueue);
650
+ if (!metrics.ok) return metrics;
629
651
  const installed = root.bind(props, scope);
630
652
  return installed.ok ? ok(root) : installed;
631
653
  }
@@ -639,8 +661,7 @@ export function attachLayoutItem(this: void, group: NativeLayoutGroup, region: G
639
661
  const remove = scope.onDispose(() => {
640
662
  const index = group.children.indexOf(item);
641
663
  if (index >= 0) group.children.splice(index, 1);
642
- group.visibility.delete(item);
643
- if (acceptRegion(region).ok) region.SetShown(false);
664
+ item.retire();
644
665
  group.enqueue();
645
666
  });
646
667
  if (!remove.ok) return remove;
@@ -0,0 +1,15 @@
1
+ import { readFontPath } from "./frame-access";
2
+ import type { FontString, FrameMap } from "./frames";
3
+ import { api } from "./native";
4
+
5
+ /** Apply a UI family while keeping Blizzard's existing glyph coverage in localized clients. */
6
+ export function createLocaleFont(this: void, family: string) {
7
+ return (target: FontString | FrameMap["EditBox"], size: number) => {
8
+ const previous = readFontPath(target);
9
+ const locale = api.GetLocale();
10
+ const path = locale === "ruRU" || locale === "koKR" || locale === "zhCN" || locale === "zhTW"
11
+ ? previous ?? family : family;
12
+ if (!target.SetFont(path, size, "") && previous !== undefined && path !== previous) target.SetFont(previous, size, "");
13
+ target.SetShadowOffset(0, 0);
14
+ };
15
+ }