@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
package/wow/app-ui.ts ADDED
@@ -0,0 +1,230 @@
1
+ import { createContext } from "../src/context";
2
+ import { createElement } from "../src/elements";
3
+ import { installModuleUi, modulePages, type ModulePage, type ModuleReplacement, type ModuleUi, type ModuleView, type ModuleWindow, type ViewComponent } from "../src/module-ui";
4
+ import type { OwnedReadonlyArray, OwnedRecord } from "../src/owned-collections";
5
+ import { computed } from "../src/reactive-scope";
6
+ import { ref, type ReadonlyRef } from "../src/reactivity";
7
+ import { fail, formatFailure, ok, type Result } from "../src/result";
8
+ import type { Runtime, RuntimeScope } from "../src/runtime";
9
+ import { withRouterHost, type RoutePage, type RouterHost } from "../router/router-view";
10
+ import { defineStore, readonly } from "../state/setup-store";
11
+ import type { EventApi } from "./contract";
12
+ import type { FrameStrata } from "./frame-layer";
13
+ import { mountModuleReplacements } from "./module-replacements";
14
+ import { createNativePanel } from "./panel-host";
15
+ import { mountProtectedView } from "./protected-view";
16
+ import type { NativeViewOptions } from "./view";
17
+
18
+ /** App-wide options for every view Kumi mounts: textures, fonts, control skins and media queries. */
19
+ export type AppTheme = Omit<NativeViewOptions, "rootLayer" | "bindings" | "manualTextBindings" | "layoutDiagnostics" | "regionsOnly"
20
+ | "rootBackdrop" | "rootScale" | "unanchoredRoot" | "portalRoot" | "unprotectedOnly">;
21
+
22
+ interface FileRouter {
23
+ readonly pages: OwnedReadonlyArray<{ readonly path: string; readonly title?: string; readonly order?: number }>;
24
+ has(this: void, path: string): boolean;
25
+ render(this: void, path: string, context: object): ReturnType<ViewComponent> | undefined;
26
+ }
27
+
28
+ interface AppContext {
29
+ readonly runtime: Runtime;
30
+ readonly scope: RuntimeScope;
31
+ readonly events: EventApi;
32
+ readonly theme: AppTheme;
33
+ }
34
+
35
+ interface ViewHost {
36
+ /** Apply pending changes to the view now instead of on the next frame. */
37
+ refresh(this: void): Result<void>;
38
+ /** The size of one physical pixel in the view's units. */
39
+ readonly pixel: ReadonlyRef<number>;
40
+ }
41
+
42
+ interface WindowState {
43
+ readonly config: ModuleWindow;
44
+ readonly router: FileRouter;
45
+ readonly owner: RuntimeScope;
46
+ show?: (this: void) => void;
47
+ hide?: (this: void) => void;
48
+ }
49
+
50
+ let app: AppContext | undefined;
51
+ const windowState = ref<WindowState | undefined>(undefined);
52
+ const windowOpen = ref(false);
53
+ const windowPath = ref<string | undefined>(undefined);
54
+ const viewContext = createContext<ViewHost>();
55
+
56
+ /** @internal The running addon, for hooks such as useEvent. */
57
+ export function appContext(this: void): AppContext | undefined {
58
+ return app;
59
+ }
60
+
61
+ function routeExists(path: string) {
62
+ const state = windowState.value;
63
+ if (state === undefined) return false;
64
+ if (state.router.has(path)) return true;
65
+ for (const page of modulePages().value as OwnedReadonlyArray<ModulePage>) if (page.path === path) return true;
66
+ return false;
67
+ }
68
+
69
+ function firstPath(state: WindowState) {
70
+ if (state.config.start !== undefined) return state.config.start;
71
+ for (const page of state.router.pages) return page.path;
72
+ for (const page of modulePages().value as OwnedReadonlyArray<ModulePage>) return page.path;
73
+ return undefined;
74
+ }
75
+
76
+ function mountWindow(state: WindowState): Result<void> {
77
+ const context = app;
78
+ if (context === undefined) return fail("The addon window needs a running addon");
79
+ const { config } = state;
80
+ const panel = createNativePanel(state.owner, context.events, config.width, config.height,
81
+ (config.strata ?? "DIALOG") as FrameStrata, 0);
82
+ if (!panel.ok) return panel;
83
+ const host: RouterHost = {
84
+ navigation: { path: windowPath as ReadonlyRef<string | undefined>, navigate: path => { navigateWindow(path); } },
85
+ render: path => state.router.has(path) ? state.router.render(path, {}) : undefined,
86
+ modulePages: modulePages(),
87
+ };
88
+ const mounted = panel.value.mount(context.runtime, owner => {
89
+ const layout = withRouterHost(host, () => createElement(config.layout, {}), owner.protect);
90
+ if (!layout.ok) throw new Error(layout.reason);
91
+ return layout.value;
92
+ }, {
93
+ cssFlow: true, initialLayout: "sync", ...context.theme as OwnedRecord<NativeViewOptions>,
94
+ });
95
+ if (!mounted.ok) return mounted;
96
+ state.owner.onDispose(mounted.value.dispose);
97
+ state.show = panel.value.show;
98
+ state.hide = panel.value.hide;
99
+ return ok(undefined);
100
+ }
101
+
102
+ function navigateWindow(path: string): Result<void> {
103
+ if (!routeExists(path)) return fail("The window has no page at " + path);
104
+ windowPath.value = path;
105
+ return ok(undefined);
106
+ }
107
+
108
+ function openWindow(path?: string): Result<void> {
109
+ const state = windowState.value;
110
+ if (state === undefined) return fail("The addon has no window. Declare window in the app module.");
111
+ if (!state.owner.isActive()) return fail("The addon window has closed");
112
+ const target = path ?? windowPath.value ?? firstPath(state);
113
+ if (target === undefined) return fail("The addon window has no pages");
114
+ const navigated = navigateWindow(target);
115
+ if (!navigated.ok) return navigated;
116
+ if (state.show === undefined) {
117
+ const mounted = mountWindow(state);
118
+ if (!mounted.ok) return mounted;
119
+ }
120
+ state.show?.();
121
+ windowOpen.value = true;
122
+ return ok(undefined);
123
+ }
124
+
125
+ function closeWindow() {
126
+ windowState.value?.hide?.();
127
+ windowOpen.value = false;
128
+ }
129
+
130
+ /**
131
+ * The addon window declared by the app module. Open it from a button, a slash command or a store.
132
+ *
133
+ * ```ts
134
+ * const window = useWindow();
135
+ * window.toggle("/settings");
136
+ * ```
137
+ */
138
+ export const useWindow = defineStore("kumi/window", () => {
139
+ const pages = computed(() => {
140
+ const rows: RoutePage[] = [];
141
+ const state = windowState.value;
142
+ if (state === undefined) return rows;
143
+ for (const page of state.router.pages) rows.push({ path: page.path, title: page.title ?? page.path, order: page.order ?? 0 });
144
+ for (const page of modulePages().value as OwnedReadonlyArray<ModulePage>) rows.push({ path: page.path, title: page.title, order: page.order ?? 0 });
145
+ return rows.sort((left, right) => left.order - right.order);
146
+ });
147
+
148
+ function open(this: void, path?: string): Result<void> {
149
+ return openWindow(path);
150
+ }
151
+
152
+ function close(this: void): void {
153
+ closeWindow();
154
+ }
155
+
156
+ function toggle(this: void, path?: string): Result<void> {
157
+ if (windowOpen.value && (path === undefined || path === windowPath.value)) {
158
+ closeWindow();
159
+ return ok(undefined);
160
+ }
161
+ return openWindow(path);
162
+ }
163
+
164
+ function navigate(this: void, path: string): Result<void> {
165
+ return navigateWindow(path);
166
+ }
167
+
168
+ return { isOpen: readonly(windowOpen), path: readonly(windowPath), pages, open, close, toggle, navigate };
169
+ });
170
+
171
+ /** Inside a HUD view: refresh it now, or read the size of one physical pixel. */
172
+ export function useViewHost(this: void): ViewHost {
173
+ const host = viewContext.use();
174
+ if (host === undefined) throw new Error("useViewHost works during the setup of a module view");
175
+ return host;
176
+ }
177
+
178
+ function mountView(context: AppContext, { component, strata = "MEDIUM", combatUpdates }: ModuleView, scope: RuntimeScope): Result<void> {
179
+ const mounted = mountProtectedView(context.runtime, scope, (_view, refresh, pixel) => {
180
+ const rendered = viewContext.run({ refresh, pixel }, () => createElement(component, {}), scope.protect);
181
+ if (!rendered.ok) throw new Error(formatFailure(rendered));
182
+ return rendered.value;
183
+ }, { ...context.theme as OwnedRecord<NativeViewOptions>, rootLayer: { strata: strata as FrameStrata }, combatUpdates });
184
+ return mounted.ok ? ok(undefined) : mounted;
185
+ }
186
+
187
+ function mountViews(context: AppContext, id: string, views: OwnedReadonlyArray<ViewComponent | ModuleView>, scope: RuntimeScope): Result<void> {
188
+ for (const view of views) {
189
+ const mounted = mountView(context, typeof view === "function" ? { component: view } : view, scope);
190
+ if (!mounted.ok) return fail("Module " + id + ": " + mounted.reason);
191
+ }
192
+ return ok(undefined);
193
+ }
194
+
195
+ function mountUi(id: string, ui: ModuleUi, scope: RuntimeScope): Result<void> {
196
+ const context = app;
197
+ if (context === undefined) return fail("Module " + id + " declares UI but the addon is not running");
198
+ if (ui.window !== undefined) {
199
+ if (windowState.value !== undefined) return fail("Module " + id + ": the addon already has a window");
200
+ const router = ui.window.routes as Result<FileRouter>;
201
+ if (router === undefined || typeof router !== "object" || !("ok" in router)) {
202
+ return fail("Module " + id + ": window.routes must be the router from @kumi/routes");
203
+ }
204
+ if (!router.ok) return fail("Module " + id + ": " + router.reason);
205
+ windowState.value = { config: ui.window, router: router.value, owner: scope };
206
+ const released = scope.onDispose(() => {
207
+ closeWindow();
208
+ windowState.value = undefined;
209
+ });
210
+ if (!released.ok) return released;
211
+ }
212
+ const views = (ui.views ?? []) as OwnedReadonlyArray<ViewComponent | ModuleView>;
213
+ const replacements = ui.replaces as OwnedReadonlyArray<ModuleReplacement> | undefined;
214
+ if (replacements !== undefined && replacements.length > 0) {
215
+ return mountModuleReplacements(context.runtime, scope, id, replacements,
216
+ viewScope => mountViews(context, id, views, viewScope));
217
+ }
218
+ return mountViews(context, id, views, scope);
219
+ }
220
+
221
+ /** @internal Called by startAddon before the root module activates. */
222
+ export function installAppUi(this: void, runtime: Runtime, scope: RuntimeScope, events: EventApi, theme: AppTheme): void {
223
+ app = { runtime, scope, events, theme };
224
+ installModuleUi(mountUi);
225
+ scope.onDispose(() => {
226
+ if (app?.scope === scope) app = undefined;
227
+ installModuleUi(undefined);
228
+ });
229
+ }
230
+
@@ -0,0 +1,24 @@
1
+ import { api, reveal } from "./native";
2
+
3
+ export interface CooldownTiming {
4
+ readonly start: number;
5
+ readonly duration: number;
6
+ readonly rate: number;
7
+ }
8
+
9
+ /** Read the active cooldown as ordinary numbers when the client allows it. */
10
+ export function readCooldownTiming(this: void, kind: "spell" | "item" | "toy", id: number): CooldownTiming | undefined {
11
+ if (kind === "spell") {
12
+ const info = reveal(api.C_Spell.GetSpellCooldown(id));
13
+ if (info === undefined) return undefined;
14
+ const start = reveal(info.startTime);
15
+ const duration = reveal(info.duration);
16
+ return start !== undefined && duration !== undefined && duration > 0
17
+ ? { start, duration, rate: reveal(info.modRate) ?? 1 } : undefined;
18
+ }
19
+ const [rawStart, rawDuration, active] = api.C_Container.GetItemCooldown(id);
20
+ const start = reveal(rawStart);
21
+ const duration = reveal(rawDuration);
22
+ return reveal(active) === 1 && start !== undefined && duration !== undefined && duration > 0
23
+ ? { start, duration, rate: 1 } : undefined;
24
+ }
@@ -0,0 +1,75 @@
1
+ import { fail, ok, type Result } from "../src/result";
2
+ import { sameBackgroundImage, type StatePaint } from "../src/style-states";
3
+ import { resolveStyleValue, type StyleEnvironment } from "../src/style-variables";
4
+ import type { RGBA } from "../utils/colors";
5
+ import { readCssColor } from "./css-color";
6
+ import type { Texture } from "./frames";
7
+ import { api, reveal } from "./native";
8
+
9
+ type BackgroundImage = StatePaint["backgroundImage"];
10
+
11
+ export function cssTexturePath(path: string): string {
12
+ const local = path.startsWith("./") ? path.slice(2) : path;
13
+ return local.split("/").join("\\");
14
+ }
15
+
16
+ function gradientStop(input: string, environment: StyleEnvironment | undefined): Result<RGBA> {
17
+ const resolved = resolveStyleValue(input, environment);
18
+ if (!resolved.ok) return resolved;
19
+ const literal = reveal(resolved.value);
20
+ const color = literal === "transparent" ? [0, 0, 0, 0] as RGBA
21
+ : literal === "black" ? [0, 0, 0, 1] as RGBA
22
+ : literal === "white" ? [1, 1, 1, 1] as RGBA
23
+ : literal === undefined ? undefined : readCssColor(literal);
24
+ return color === undefined ? fail(`Invalid CSS gradient color ${input}`) : ok(color);
25
+ }
26
+
27
+ function sameColor(previous: RGBA | undefined, next: RGBA) {
28
+ return previous !== undefined && previous[0] === next[0] && previous[1] === next[1]
29
+ && previous[2] === next[2] && previous[3] === next[3];
30
+ }
31
+
32
+ export function createBackgroundPainter(texture: Texture, show: (this: void, visible: boolean) => void, environment?: StyleEnvironment) {
33
+ let previous: BackgroundImage;
34
+ let minColor: RGBA | undefined;
35
+ let maxColor: RGBA | undefined;
36
+
37
+ return function paint(this: void, image?: BackgroundImage): Result<void> {
38
+ if (image !== undefined && "gradient" in image) {
39
+ const { axis, min, max } = image.gradient;
40
+ const low = gradientStop(min, environment);
41
+ if (!low.ok) return low;
42
+ const high = gradientStop(max, environment);
43
+ if (!high.ok) return high;
44
+ const a = low.value, b = high.value;
45
+ if (sameBackgroundImage(previous, image) && sameColor(minColor, a) && sameColor(maxColor, b)) return ok(undefined);
46
+
47
+ const createColor = api.CreateColor;
48
+ if (typeof createColor !== "function" || typeof texture.SetGradient !== "function") {
49
+ return fail("CSS linear gradients require native texture gradients");
50
+ }
51
+ if (previous !== undefined && "atlas" in previous) texture.SetTexCoord(0, 1, 0, 1);
52
+ texture.SetColorTexture(1, 1, 1, 1);
53
+ // A fully transparent CSS stop takes the hue of its neighbor.
54
+ const start = a[3] === 0 ? createColor(b[0], b[1], b[2], 0) : createColor(...a);
55
+ const end = b[3] === 0 ? createColor(a[0], a[1], a[2], 0) : createColor(...b);
56
+ texture.SetGradient(axis, start, end);
57
+ minColor = a;
58
+ maxColor = b;
59
+ show(true);
60
+ } else {
61
+ if (sameBackgroundImage(previous, image)) return ok(undefined);
62
+ if (previous !== undefined && "gradient" in previous) texture.SetVertexColor(1, 1, 1, 1);
63
+ if (image === undefined) show(false);
64
+ else if ("path" in image) {
65
+ if (previous !== undefined && "atlas" in previous) texture.SetTexCoord(0, 1, 0, 1);
66
+ show(texture.SetTexture(cssTexturePath(image.path)) !== false);
67
+ } else {
68
+ texture.SetAtlas(image.atlas, false);
69
+ show(true);
70
+ }
71
+ }
72
+ previous = image;
73
+ return ok(undefined);
74
+ };
75
+ }
package/wow/css-box.ts CHANGED
@@ -7,8 +7,10 @@ import { createFrame, type Frame, type FrameParent } from "./frames";
7
7
  import { borderInsets, createCssSurface, type CssSurface, type CssSurfaceOptions } from "./css-surfaces";
8
8
  import type { ReadCssStyle } from "./css-style";
9
9
  import { hookScript } from "./native-hooks";
10
- import { reveal } from "./native";
10
+ import { api, reveal } from "./native";
11
11
  import { mountLayoutRoot, readLayoutValue, type NativeLayoutGroup, type StageInitialLayout } from "./layout-view";
12
+ import { physicalPixel, watchDisplayMetrics } from "./pixel";
13
+ import { createProtectedLayoutUpdate } from "./protected-layout";
12
14
  import { mountScrollView, type CreateScrollArea } from "./scroll-view";
13
15
  import type { NativePaintState } from "./state-paint";
14
16
 
@@ -17,24 +19,57 @@ type Inset = readonly [top: number, right: number, bottom: number, left: number]
17
19
  type Content = { readonly frame: Frame; readonly layout?: NativeLayoutGroup };
18
20
 
19
21
  export function hasCssSurface(this: void, style: NativeStyle, paint?: NativePaintState): boolean {
20
- return style.border !== undefined || style.backgroundImage !== undefined || (style.borderRadius !== undefined
21
- && (style.backgroundColor !== undefined || paint?.usesBackgroundColor === true || paint?.usesBackgroundImage === true));
22
+ return style.border !== undefined || style.backgroundImage !== undefined || paint?.usesBackgroundImage === true
23
+ || (style.borderRadius !== undefined && (style.backgroundColor !== undefined || paint?.usesBackgroundColor === true));
22
24
  }
23
25
 
24
26
  export function mountCssSurface(this: void, scope: RuntimeScope, frame: Frame, style: NativeStyle, paint: NativePaintState | undefined,
25
27
  rounded: CssSurfaceOptions["rounded"], environment?: StyleEnvironment, live?: ReadCssStyle, nativeRoundedArt?: true): Result<CssSurface> {
28
+ const image = style.backgroundImage !== undefined || paint?.usesBackgroundImage === true;
29
+ const radius = nativeRoundedArt !== true && live === undefined && !image ? reveal(style.borderRadius) : undefined;
30
+ const fixedRadius = typeof radius === "number" && Number.isFinite(radius) && radius > 0 ? radius : undefined;
31
+ const fixedFillRadius = rounded?.applyExactFill !== undefined && style.border === undefined ? fixedRadius : undefined;
32
+ const fixedBorderRadius = rounded?.borderOutline !== undefined && style.border !== undefined ? fixedRadius : undefined;
26
33
  const created = createCssSurface(scope, frame, {
27
34
  rounded, environment, nativeRoundedArt, color: style.backgroundColor !== undefined || paint?.usesBackgroundColor === true,
28
- image: style.backgroundImage !== undefined || paint?.usesBackgroundImage === true,
35
+ image, maskImage: style.maskImage, fixedFillRadius, fixedBorderRadius,
36
+ liveOutline: live !== undefined && style.border !== undefined && style.borderRadius !== undefined,
29
37
  borderState: style.border !== undefined && paint?.usesBorderColor === true,
38
+ fixedBorder: live === undefined ? style.border : undefined,
39
+ borderPaint: style.borderPaint,
40
+ pixelSize: style.border !== undefined && nativeRoundedArt !== true ? () => physicalPixel(frame) : undefined,
30
41
  });
31
42
  if (!created.ok) return created;
32
- const installed = scope.watchEffect(() => {
43
+ const surface = created.value;
44
+ function refresh() {
33
45
  const current = live?.() ?? style;
34
- const result = created.value.setBorder(current.border, current.borderRadius);
46
+ const result = surface.setBorder(current.border, current.borderRadius);
35
47
  if (!result.ok) return result;
36
- });
37
- return installed.ok ? created : installed;
48
+ }
49
+ const installed = scope.watchEffect(refresh);
50
+ if (!installed.ok) return installed;
51
+ if (style.border !== undefined && nativeRoundedArt !== true) {
52
+ const redraw = createProtectedLayoutUpdate(refresh, { scope, label: "CSS border pixels" });
53
+ if (!redraw.ok) return redraw;
54
+ const refreshPixels = () => {
55
+ const refreshed = redraw.value.request();
56
+ if (!refreshed.ok) api.geterrorhandler()(refreshed.reason);
57
+ };
58
+ const watched = watchDisplayMetrics(scope, refreshPixels);
59
+ if (!watched.ok) return watched;
60
+ const border = surface.responsiveBorder;
61
+ if (border !== undefined) {
62
+ const size = hookScript(frame, "OnSizeChanged", (_, width, height) => {
63
+ if (border.resize(width, height)) refreshPixels();
64
+ }, scope);
65
+ if (!size.ok) {
66
+ border.useFallback();
67
+ const restored = refresh();
68
+ if (restored !== undefined) return restored;
69
+ }
70
+ }
71
+ }
72
+ return created;
38
73
  }
39
74
 
40
75
  function padding(style: NativeStyle | undefined, live?: ReadCssStyle, decorativeBorder = false): Result<Inset> {
@@ -47,11 +82,12 @@ function padding(style: NativeStyle | undefined, live?: ReadCssStyle, decorative
47
82
  return ok([top + bt, (right ?? top) + br, (bottom ?? top) + bb, (left ?? right ?? top) + bl]);
48
83
  }
49
84
 
50
- export function includeCssBorderPadding(this: void, scope: RuntimeScope, props: FrameProps, live?: ReadCssStyle, decorativeBorder = false): FrameProps {
85
+ export function includeCssBorderPadding<Props extends Pick<FrameProps, "style">>(this: void, scope: RuntimeScope, props: Props,
86
+ live?: ReadCssStyle, decorativeBorder = false): Props {
51
87
  const style = props.style;
52
88
  if (decorativeBorder || style?.border === undefined) return props;
53
89
  const adjusted = scope.computedResult(() => padding(style, live), "CSS border padding");
54
- return { ...props as OwnedRecord<FrameProps>, style: { ...style as OwnedRecord<NativeStyle>, padding: adjusted } };
90
+ return { ...props as OwnedRecord<Props>, style: { ...style as OwnedRecord<NativeStyle>, padding: adjusted } };
55
91
  }
56
92
 
57
93
  function insetContent(scope: RuntimeScope, frame: Frame, style: NativeStyle, live?: ReadCssStyle, decorativeBorder = false): Result<Frame> {
@@ -0,0 +1,32 @@
1
+ import type { CssV1Style } from "../src/css-v1";
2
+ import { fail, ok, type Result } from "../src/result";
3
+ import type { RuntimeScope } from "../src/runtime";
4
+ import { cssTexturePath } from "./css-background-image";
5
+ import type { Frame, MaskTexture, Texture } from "./frames";
6
+
7
+ export function mountImageMask(scope: RuntimeScope, parent: Frame, texture: Texture, source: NonNullable<CssV1Style["maskImage"]>): Result<void> {
8
+ if (typeof parent.CreateMaskTexture !== "function" || typeof texture.AddMaskTexture !== "function"
9
+ || typeof texture.RemoveMaskTexture !== "function") return fail("CSS mask-image requires native texture masks");
10
+
11
+ let mask: MaskTexture | undefined;
12
+ let attached = false;
13
+ const cleanup = scope.onDispose(() => {
14
+ if (mask === undefined) return;
15
+ if (attached) texture.RemoveMaskTexture(mask);
16
+ mask.Hide();
17
+ });
18
+ if (!cleanup.ok) return cleanup;
19
+ const applied = scope.protect(() => {
20
+ const target = parent.CreateMaskTexture();
21
+ mask = target;
22
+ const path = cssTexturePath(source.path);
23
+ if (target.SetTexture(path, "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE") === false) {
24
+ return fail(`Could not load CSS mask image ${source.path}`);
25
+ }
26
+ target.SetAllPoints(texture);
27
+ texture.AddMaskTexture(target);
28
+ attached = true;
29
+ return ok(undefined);
30
+ });
31
+ return applied.ok ? applied.value : applied;
32
+ }