@overmvp/kumi 0.1.0 → 0.3.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 (175) hide show
  1. package/README.md +59 -6
  2. package/builder/css-v1.mjs +54 -1
  3. package/builder/css-v1.test.mjs +40 -0
  4. package/builder/link-addon-package.mjs +47 -6
  5. package/builder/module-declarations.test.mjs +9 -18
  6. package/builder/native-kernels.mjs +1 -1
  7. package/builder/src/compiler.rs +180 -8
  8. package/builder/src/main.rs +19 -5
  9. package/builder/src/native_ir.rs +1 -1
  10. package/builder/src/native_signal.rs +46 -10
  11. package/builder/src/numbers.lua +14 -0
  12. package/builder/src/project-front.mjs +385 -34
  13. package/builder/src/routes.rs +11 -14
  14. package/builder/src/setup-store.lua +18 -0
  15. package/builder/src/signal-kernel.fingerprint +1 -1
  16. package/builder/src/ts-lower.mjs +2 -2
  17. package/builder/src/wow-reads.lua +22 -0
  18. package/builder/style-modules.mjs +93 -0
  19. package/config.ts +56 -14
  20. package/eslint.mjs +74 -0
  21. package/form/index.ts +15 -11
  22. package/package.json +11 -7
  23. package/router/index.ts +9 -2
  24. package/router/navigation.ts +22 -0
  25. package/router/router-view.ts +134 -0
  26. package/scripts/addon-build.mjs +364 -0
  27. package/scripts/addon-project.mjs +78 -0
  28. package/scripts/kumi-cli.mjs +52 -17
  29. package/scripts/link-addons.mjs +12 -2
  30. package/src/bindings.ts +2 -2
  31. package/src/css-tokens.ts +16 -11
  32. package/src/css-v1.ts +10 -0
  33. package/src/elements.ts +26 -0
  34. package/src/frame-scheduler.ts +3 -1
  35. package/src/index.ts +1 -0
  36. package/src/jsx-runtime.ts +8 -1
  37. package/src/keyed-list.ts +8 -5
  38. package/src/module-ui.ts +147 -0
  39. package/src/module.ts +42 -8
  40. package/src/owned-collections.ts +8 -0
  41. package/src/providers.ts +7 -1
  42. package/src/reactive-scope.ts +3 -3
  43. package/src/reactivity.ts +28 -7
  44. package/src/result.ts +6 -0
  45. package/src/signal-kernel.ts +35 -2
  46. package/state/index.ts +6 -0
  47. package/state/setup-store-persistence.ts +206 -0
  48. package/state/setup-store-view.ts +10 -0
  49. package/state/setup-store.ts +342 -0
  50. package/state/store.ts +2 -0
  51. package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
  52. package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
  53. package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
  54. package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
  55. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
  56. package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
  57. package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
  58. package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
  59. package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
  60. package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
  61. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
  62. package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
  63. package/templates/addon/AGENTS.md +34 -0
  64. package/templates/addon/Assets/Art/Corner10.tga +0 -0
  65. package/templates/addon/Assets/Art/Corner11.tga +0 -0
  66. package/templates/addon/Assets/Art/Corner12.tga +0 -0
  67. package/templates/addon/Assets/Art/Corner13.tga +0 -0
  68. package/templates/addon/Assets/Art/Corner14.tga +0 -0
  69. package/templates/addon/Assets/Art/Corner15.tga +0 -0
  70. package/templates/addon/Assets/Art/Corner16.tga +0 -0
  71. package/templates/addon/Assets/Art/Corner2.tga +0 -0
  72. package/templates/addon/Assets/Art/Corner3.tga +0 -0
  73. package/templates/addon/Assets/Art/Corner4.tga +0 -0
  74. package/templates/addon/Assets/Art/Corner5.tga +0 -0
  75. package/templates/addon/Assets/Art/Corner6.tga +0 -0
  76. package/templates/addon/Assets/Art/Corner7.tga +0 -0
  77. package/templates/addon/Assets/Art/Corner8.tga +0 -0
  78. package/templates/addon/Assets/Art/Corner9.tga +0 -0
  79. package/templates/addon/Assets/Art/Dot.tga +0 -0
  80. package/templates/addon/Assets/Art/Gear.tga +0 -0
  81. package/templates/addon/Assets/Art/Grip.tga +0 -0
  82. package/templates/addon/Assets/Art/Outline10.tga +0 -0
  83. package/templates/addon/Assets/Art/Outline12.tga +0 -0
  84. package/templates/addon/Assets/Art/Outline13.tga +0 -0
  85. package/templates/addon/Assets/Art/Outline14.tga +0 -0
  86. package/templates/addon/Assets/Art/Outline15.tga +0 -0
  87. package/templates/addon/Assets/Art/Outline2.tga +0 -0
  88. package/templates/addon/Assets/Art/Outline3.tga +0 -0
  89. package/templates/addon/Assets/Art/Outline5.tga +0 -0
  90. package/templates/addon/Assets/Art/Outline7.tga +0 -0
  91. package/templates/addon/Assets/Art/Outline9.tga +0 -0
  92. package/templates/addon/Assets/Art/Round11.tga +0 -0
  93. package/templates/addon/Assets/Art/Round11Border.tga +0 -0
  94. package/templates/addon/Assets/Art/Round4.tga +0 -0
  95. package/templates/addon/Assets/Art/Round4Border.tga +0 -0
  96. package/templates/addon/Assets/Art/Round6.tga +0 -0
  97. package/templates/addon/Assets/Art/Round6Border.tga +0 -0
  98. package/templates/addon/Assets/Art/Round8.tga +0 -0
  99. package/templates/addon/Assets/Art/Round8Border.tga +0 -0
  100. package/templates/addon/Assets/Art/Search.tga +0 -0
  101. package/templates/addon/CLAUDE.md +1 -0
  102. package/templates/addon/README.md +42 -7
  103. package/templates/addon/eslint.config.mjs +3 -9
  104. package/templates/addon/gitignore +1 -0
  105. package/templates/addon/kumi.config.ts +17 -0
  106. package/templates/addon/package.json +4 -5
  107. package/templates/addon/src/app/app.module.ts +18 -0
  108. package/templates/addon/src/app/commands.store.ts +11 -0
  109. package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
  110. package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
  111. package/templates/addon/src/app/main.ts +5 -0
  112. package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
  113. package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
  114. package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
  115. package/templates/addon/src/app/theme.ts +6 -0
  116. package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
  117. package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
  118. package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
  119. package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
  120. package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
  121. package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
  122. package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
  123. package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
  124. package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
  125. package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
  126. package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
  127. package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
  128. package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
  129. package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
  130. package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
  131. package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
  132. package/templates/addon/src/shared/api/native-art.ts +28 -0
  133. package/templates/addon/src/shared/assets/close.png +0 -0
  134. package/templates/addon/src/shared/lib/format.ts +20 -0
  135. package/templates/addon/src/shared/styles/_tokens.scss +12 -0
  136. package/templates/addon/src/shared/ui/Button.tsx +29 -0
  137. package/templates/addon/src/shared/ui/Choice.tsx +34 -0
  138. package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
  139. package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
  140. package/templates/addon/src/shared/ui/Slider.tsx +25 -0
  141. package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
  142. package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
  143. package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
  144. package/templates/addon/tsconfig.json +49 -10
  145. package/wow/action-bar-layout.ts +108 -0
  146. package/wow/action-button.ts +219 -0
  147. package/wow/action-catalog.ts +98 -0
  148. package/wow/addon-manifest.ts +36 -0
  149. package/wow/app-ui.ts +221 -0
  150. package/wow/cooldown-timing.ts +24 -0
  151. package/wow/css-box.ts +40 -6
  152. package/wow/css-surfaces.ts +229 -24
  153. package/wow/cursor.ts +45 -0
  154. package/wow/frame-access.ts +23 -1
  155. package/wow/frame-timing.ts +13 -0
  156. package/wow/hooks.ts +133 -0
  157. package/wow/index.ts +18 -4
  158. package/wow/layout-view.ts +26 -14
  159. package/wow/locale-font.ts +15 -0
  160. package/wow/native.ts +18 -0
  161. package/wow/panel-host.ts +97 -0
  162. package/wow/pixel.ts +35 -0
  163. package/wow/plugins.ts +246 -0
  164. package/wow/protect.ts +27 -3
  165. package/wow/protected-view.ts +103 -0
  166. package/wow/range-art.ts +7 -0
  167. package/wow/readable-api.ts +120 -0
  168. package/wow/rounded-texture.ts +33 -6
  169. package/wow/saved-variables.ts +67 -18
  170. package/wow/spell-cooldown.ts +36 -0
  171. package/wow/start-addon.ts +31 -8
  172. package/wow/view.ts +201 -83
  173. package/templates/addon/__ADDON_NAME__.toc +0 -4
  174. package/templates/addon/scripts/build.mjs +0 -25
  175. package/templates/addon/src/app/main.tsx +0 -13
@@ -1,14 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawnSync } from "node:child_process";
3
- import { mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
4
- import { basename, join, resolve } from "node:path";
3
+ import { constants, copyFileSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
4
+ import { basename, extname, join, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
+ import { parseArgs } from "node:util";
6
7
  import { linkAddons } from "./link-addons.mjs";
7
8
 
8
9
  const sdk = fileURLToPath(new URL("../", import.meta.url));
9
10
  const { name, version } = JSON.parse(readFileSync(join(sdk, "package.json"), "utf8"));
10
11
  const template = join(sdk, "templates", "addon");
11
- const usage = "Usage: kumi init <AddonName> | kumi pack <kumi-pack arguments> | kumi link <build-dir> <AddOns-dir> [--dry-run] | kumi --version";
12
+ const usage = `Usage:
13
+ kumi init <AddonName>
14
+ kumi check [--types-only]
15
+ kumi build [--target retail|forever] [--toc number]
16
+ kumi link <AddOns-dir> [--dry-run]
17
+ kumi --version`;
18
+
19
+ const TEMPLATE_TEXT_EXTENSIONS = new Set([".css", ".json", ".md", ".mjs", ".scss", ".toc", ".ts", ".tsx"]);
12
20
 
13
21
  function init(destination) {
14
22
  const target = resolve(destination);
@@ -16,11 +24,13 @@ function init(destination) {
16
24
  if (!/^[A-Za-z][A-Za-z0-9_-]{0,62}$/u.test(addon)) throw new Error("Use a folder name such as MyAddon");
17
25
  const replacements = {
18
26
  __ADDON_NAME__: addon,
27
+ __ADDON_DB__: addon.replace(/[^A-Za-z0-9_]/g, "_") + "DB",
19
28
  __PROJECT_NAME__: addon.toLowerCase(),
20
29
  __KUMI_PACKAGE__: name,
21
30
  __KUMI_VERSION__: version,
31
+ __ADDON_SLASH__: addon.toLowerCase().replace(/[^a-z0-9]/gu, ""),
22
32
  };
23
- const fill = text => text.replace(/__(ADDON_NAME|PROJECT_NAME|KUMI_PACKAGE|KUMI_VERSION)__/gu, key => replacements[key]);
33
+ const fill = text => text.replace(/__(ADDON_NAME|ADDON_DB|ADDON_SLASH|PROJECT_NAME|KUMI_PACKAGE|KUMI_VERSION)__/gu, key => replacements[key]);
24
34
  function copy(from, to) {
25
35
  for (const entry of readdirSync(from, { withFileTypes: true })) {
26
36
  const source = join(from, entry.name);
@@ -28,7 +38,13 @@ function init(destination) {
28
38
  if (entry.isDirectory()) {
29
39
  mkdirSync(output);
30
40
  copy(source, output);
31
- } else if (entry.isFile()) writeFileSync(output, fill(readFileSync(source, "utf8")), { flag: "wx" });
41
+ } else if (entry.isFile()) {
42
+ if (entry.name === "gitignore" || TEMPLATE_TEXT_EXTENSIONS.has(extname(entry.name))) {
43
+ writeFileSync(output, fill(readFileSync(source, "utf8")), { flag: "wx" });
44
+ } else {
45
+ copyFileSync(source, output, constants.COPYFILE_EXCL);
46
+ }
47
+ }
32
48
  }
33
49
  }
34
50
  mkdirSync(target);
@@ -42,16 +58,29 @@ function run(command, args, env) {
42
58
  if (command === "cargo" && result.error.code === "ENOENT") throw new Error("Install Rust with Cargo on PATH to build Lua");
43
59
  throw result.error;
44
60
  }
45
- if (result.status !== 0) process.exit(result.status ?? 1);
61
+ if (result.status !== 0) throw Object.assign(new Error("Kumi subprocess failed"), { exitStatus: result.status ?? 1 });
46
62
  }
47
63
 
48
- function pack(args) {
49
- const target = resolve("build", "toolchain");
64
+ function createPackRunner(workspace) {
65
+ const target = join(workspace, "build", "toolchain");
50
66
  const env = { ...process.env, CARGO_TARGET_DIR: target, CARGO_BUILD_JOBS: "1", UV_THREADPOOL_SIZE: "1" };
51
- run("cargo", ["build", "--locked", "--jobs", "1", "--manifest-path", join(sdk, "builder", "Cargo.toml")], env);
52
67
  const packer = join(target, "debug", process.platform === "win32" ? "kumi-pack.exe" : "kumi-pack");
53
- run(packer, [ ...(args.includes("--workspace") ? [] : ["--workspace", process.cwd()]),
54
- ...(args.includes("compile") && !args.includes("--sdk-root") ? ["--sdk-root", sdk] : []), ...args], env);
68
+ let ready = false;
69
+ return args => {
70
+ if (!ready) {
71
+ run("cargo", ["build", "--locked", "--jobs", "1", "--manifest-path", join(sdk, "builder", "Cargo.toml")], env);
72
+ ready = true;
73
+ }
74
+ run(packer, [ ...(args.includes("--workspace") ? [] : ["--workspace", workspace]),
75
+ ...(args.includes("compile") && !args.includes("--sdk-root") ? ["--sdk-root", sdk] : []), ...args], env);
76
+ };
77
+ }
78
+
79
+ function link(args) {
80
+ const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { "dry-run": { type: "boolean" } } });
81
+ if (positionals.length === 1) linkAddons(join("build", "addons"), positionals[0], values["dry-run"]);
82
+ else if (positionals.length === 2) linkAddons(positionals[0], positionals[1], values["dry-run"]);
83
+ else throw new Error(usage);
55
84
  }
56
85
 
57
86
  const [command, ...args] = process.argv.slice(2);
@@ -59,12 +88,18 @@ try {
59
88
  if (command === "--version") console.log(version);
60
89
  else if (command === undefined || command === "--help" || command === "-h") console.log(usage);
61
90
  else if (command === "init" && args.length === 1 && !args[0].startsWith("-")) init(args[0]);
62
- else if (command === "pack" && args.length > 0) pack(args);
63
- else if (command === "link" && (args.length === 2 || args.length === 3 && args[2] === "--dry-run")) {
64
- linkAddons(args[0], args[1], args[2] === "--dry-run");
65
- }
91
+ else if (command === "check" || command === "build") {
92
+ const { checkAddon, buildAddon } = await import("./addon-project.mjs");
93
+ const workspace = process.cwd();
94
+ const pack = createPackRunner(workspace);
95
+ if (command === "check") await checkAddon(workspace, args, pack, run);
96
+ else await buildAddon(workspace, args, pack);
97
+ } else if (command === "pack" && args.length > 0) createPackRunner(process.cwd())(args);
98
+ else if (command === "link") link(args);
66
99
  else throw new Error(usage);
67
100
  } catch (error) {
68
- console.error(`kumi: ${error.code === "EEXIST" ? "The destination already exists. Choose a new directory." : error.message}`);
69
- process.exitCode = 1;
101
+ if (error.exitStatus === undefined) {
102
+ console.error(`kumi: ${error.code === "EEXIST" ? "The destination already exists. Choose a new directory." : error.message}`);
103
+ }
104
+ process.exitCode = error.exitStatus ?? 1;
70
105
  }
@@ -1,5 +1,5 @@
1
- import { lstatSync, realpathSync, readdirSync, statSync, symlinkSync, unlinkSync } from "node:fs";
2
- import { basename, join } from "node:path";
1
+ import { lstatSync, readlinkSync, realpathSync, readdirSync, statSync, symlinkSync, unlinkSync } from "node:fs";
2
+ import { basename, join, resolve, sep } from "node:path";
3
3
 
4
4
  function inspect(path) {
5
5
  return lstatSync(path, { throwIfNoEntry: false });
@@ -11,6 +11,16 @@ export function linkAddons(buildDirectory, addonsDirectory, dryRun) {
11
11
  if (!statSync(build).isDirectory() || !statSync(addons).isDirectory() || build === addons) {
12
12
  throw new Error("Specify a build folder and a different existing AddOns folder");
13
13
  }
14
+ // Remove links into this build whose folder no longer exists, such as a plugin removed from kumi.config.ts.
15
+ for (const entry of readdirSync(addons, { withFileTypes: true })) {
16
+ const destination = join(addons, entry.name);
17
+ const link = inspect(destination);
18
+ if (!link?.isSymbolicLink() || statSync(destination, { throwIfNoEntry: false }) !== undefined) continue;
19
+ const target = resolve(addons, readlinkSync(destination));
20
+ if (!target.toLowerCase().startsWith(build.toLowerCase() + sep)) continue;
21
+ if (!dryRun) unlinkSync(destination);
22
+ console.log(`Removed stale link ${destination}`);
23
+ }
14
24
  const plan = [];
15
25
  let found = 0;
16
26
  for (const entry of readdirSync(build, { withFileTypes: true })) {
package/src/bindings.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { Anchor, Binding } from "./elements";
1
+ import type { ActionSlot, Anchor, Binding, CooldownValue } from "./elements";
2
2
  import type { ImageVerticalGradient } from "./images";
3
3
  import type { ReadonlyRef } from "./reactivity";
4
4
  import type { RuntimeScope } from "./runtime";
5
5
  import type { Failure, Result } from "./result";
6
6
  import { TextBinding } from "./text-children";
7
7
 
8
- type BoundValue = string | boolean | number | Anchor | ImageVerticalGradient;
8
+ type BoundValue = string | boolean | number | ActionSlot | Anchor | CooldownValue | ImageVerticalGradient | undefined;
9
9
 
10
10
  /** Apply a static property once or subscribe to one reactive property for the mount's lifetime. */
11
11
  export function bindValue<T extends BoundValue>(scope: RuntimeScope, value: Binding<T>,
package/src/css-tokens.ts CHANGED
@@ -11,25 +11,30 @@ type Bag = Record<Field, unknown>;
11
11
  function digit(code: number) { return code >= 48 && code <= 57; }
12
12
 
13
13
  function decimal(text: string): number | undefined {
14
+ const length = text.length;
14
15
  const start = text.startsWith("-") || text.startsWith("+") ? 1 : 0;
15
16
  let index = start;
16
- while (digit(text.charCodeAt(index))) index++;
17
+ while (index < length && digit(text.charCodeAt(index))) index += 1;
17
18
  const hasWhole = index > start;
18
- if (text.charCodeAt(index) === 46) {
19
- const fraction = ++index;
20
- while (digit(text.charCodeAt(index))) index++;
19
+ if (index < length && text.charCodeAt(index) === 46) {
20
+ index += 1;
21
+ const fraction = index;
22
+ while (index < length && digit(text.charCodeAt(index))) index += 1;
21
23
  if (fraction === index) return;
22
24
  } else if (!hasWhole) return;
23
- const separator = text.charCodeAt(index);
24
- if (separator === 69 || separator === 101) {
25
- index++;
26
- const sign = text.charCodeAt(index);
27
- if (sign === 43 || sign === 45) index++;
25
+ if (index < length) {
26
+ const separator = text.charCodeAt(index);
27
+ if (separator !== 69 && separator !== 101) return;
28
+ index += 1;
29
+ if (index < length) {
30
+ const sign = text.charCodeAt(index);
31
+ if (sign === 43 || sign === 45) index += 1;
32
+ }
28
33
  const exponent = index;
29
- while (digit(text.charCodeAt(index))) index++;
34
+ while (index < length && digit(text.charCodeAt(index))) index += 1;
30
35
  if (exponent === index) return;
31
36
  }
32
- if (index !== text.length) return;
37
+ if (index !== length) return;
33
38
  const number = Number(text);
34
39
  return Number.isFinite(number) ? number : undefined;
35
40
  }
package/src/css-v1.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { RGBA } from "../utils/colors";
1
2
  import type { Binding } from "./elements";
2
3
  import type { StatePaint } from "./style-states";
3
4
  import type { LayoutDisplay, LayoutPosition } from "./flex-layout";
@@ -14,6 +15,13 @@ export interface CssBorderEdge {
14
15
 
15
16
  export type CssBorder = Readonly<Partial<Record<CssSide, CssBorderEdge>>>;
16
17
 
18
+ /** @internal Normalized paint for a compiled fixed uniform border. */
19
+ export interface CssBorderPaintPlan {
20
+ readonly width: number;
21
+ readonly literal: string;
22
+ readonly rgba: RGBA;
23
+ }
24
+
17
25
  export interface CssTextShadow {
18
26
  readonly x: number;
19
27
  readonly y: number;
@@ -43,6 +51,8 @@ export interface CssV1Style {
43
51
  * between them, its own size or its content's (as `width: fit-content`). */
44
52
  autoMargin?: Binding<readonly [boolean, boolean, boolean, boolean]>;
45
53
  border?: CssBorder;
54
+ /** @internal A hint for the final border after class and inline styles are combined. */
55
+ borderPaint?: CssBorderPaintPlan;
46
56
  borderRadius?: number;
47
57
  backgroundImage?: StatePaint["backgroundImage"];
48
58
  fontWeight?: CssFontWeight;
package/src/elements.ts CHANGED
@@ -34,6 +34,10 @@ export interface Anchor {
34
34
  }
35
35
 
36
36
  export type Binding<T> = T | ReadonlyRef<T> | ReadonlyRef<Result<T>>;
37
+ export type TextureSource = string | number | undefined;
38
+ export type TextureCoordinates = readonly [left: number, right: number, bottom: number, top: number];
39
+ export type ActionSlot = Readonly<{ kind: "item" | "spell" | "toy"; id: number }>;
40
+ export type CooldownValue = Readonly<{ start: number; duration: number; rate: number }>;
37
41
 
38
42
  declare const nativeStatusBarValue: unique symbol;
39
43
 
@@ -152,6 +156,8 @@ interface NativeProps {
152
156
  ref?: ElementRef<"frame">;
153
157
  /** The native frame's own scale in parent coordinates. */
154
158
  nativeScale?: Binding<number>;
159
+ /** Lay out this keyed frame directly in its parent CSS container. */
160
+ directKeyedLayout?: true;
155
161
  /** Decorative artwork for WoW, reconciled as a single layer without child frames. */
156
162
  nativeImageLayers?: Binding<readonly NativeImageLayer[]>;
157
163
  /** Use the host's two native nine-slice textures for a rounded fill and decorative 1px border. */
@@ -170,6 +176,14 @@ interface NativeProps {
170
176
  nativeDesaturated?: Binding<boolean>;
171
177
  ref?: ElementRef<"image">;
172
178
  };
179
+ texture: Omit<NativeProps["image"], "src"> & {
180
+ src: Binding<TextureSource>;
181
+ texCoords?: TextureCoordinates;
182
+ onSourceChange?(this: void, source: TextureSource): void;
183
+ };
184
+ cooldown: NativeLayout & {
185
+ value: Binding<CooldownValue | undefined>;
186
+ };
173
187
  scrollview: ElementLayout<"scrollview"> & {
174
188
  contentHeight: Binding<number>;
175
189
  ref?: ElementRef<"scrollview">;
@@ -206,6 +220,15 @@ interface NativeProps {
206
220
  disabled?: Binding<boolean>;
207
221
  checked?: Binding<boolean>;
208
222
  ref?: ElementRef<"button">;
223
+ secureAction?: Binding<ActionSlot | undefined>;
224
+ /** An anchored secure button keeps its identity and mounts paint and children on its first show. */
225
+ deferContentUntilShown?: true;
226
+ /** Lay out this keyed button directly in its parent CSS container. */
227
+ directKeyedLayout?: true;
228
+ onReceiveDrag?(this: void): Result<boolean> | void;
229
+ onMove?(this: void, x: number, y: number): void;
230
+ onMoveEnd?(this: void, x: number, y: number): void;
231
+ onMoveCancel?(this: void): void;
209
232
  onDrag?(this: void, offsetY: number): void;
210
233
  onDragEnd?(this: void, offsetY: number): void;
211
234
  onDragCancel?(this: void): void;
@@ -216,6 +239,7 @@ interface NativeProps {
216
239
  label?: string;
217
240
  placeholder?: string;
218
241
  unstyled?: boolean;
242
+ nativeImageLayers?: Binding<readonly NativeImageLayer[]>;
219
243
  nativeRoundedArt?: true;
220
244
  disabled?: Binding<boolean>;
221
245
  maxLetters?: number;
@@ -243,6 +267,8 @@ interface NativeProps {
243
267
  max: number;
244
268
  step?: number;
245
269
  onChange?(this: void, value: number): void;
270
+ /** Runs after a pointer adjustment that changed the value. */
271
+ onCommit?(this: void): void;
246
272
  };
247
273
  listbox: ElementLayout<"listbox"> & {
248
274
  value: Binding<string>;
@@ -202,7 +202,9 @@ export function createFrameScheduler(
202
202
 
203
203
  function remainingMs() {
204
204
  const own = deadline === undefined ? budget() : deadline - now();
205
- return Math.max(0, Math.min(own, driver.remainingMs?.() ?? own));
205
+ const parent = driver.remainingMs?.();
206
+ const available = parent !== undefined && (parent < own || Number.isNaN(parent)) ? parent : own;
207
+ return available <= 0 ? 0 : available;
206
208
  }
207
209
 
208
210
  function roll(time: number) {
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export * from "./cvars";
11
11
  export * from "./frame-scheduler";
12
12
  export { solveLayout, type LayoutRect, type LayoutSize, type LayoutStyle } from "./flex-layout";
13
13
  export * from "./module";
14
+ export { Extensions, modulePages, type ExtensionComponent, type ModulePage, type ModuleUi, type ModuleView, type ModuleWindow, type ViewComponent } from "./module-ui";
14
15
  export { provide, serviceToken, type ResolveProviderInput, type ServiceProvider, type ServiceToken } from "./providers";
15
16
  export * from "./images";
16
17
  export * from "./keyed-list";
@@ -14,7 +14,14 @@ export function jsx<Props, Node extends UIElement>(this: void, component: (this:
14
14
  props: Props, key?: ElementKey): Node;
15
15
  export function jsx<Props>(this: void, component: IntrinsicTag | ((this: void, props: Props) => UIElement),
16
16
  props: Props, key?: ElementKey) {
17
- const inputs = key === undefined ? props : { ...props, key };
17
+ let inputs = props;
18
+ if (key !== undefined) {
19
+ const keyed: Record<string, unknown> = {};
20
+ const source = props as Record<string, unknown>;
21
+ for (const name of Object.keys(source)) keyed[name] = source[name];
22
+ keyed.key = key;
23
+ inputs = keyed as Props;
24
+ }
18
25
  if (typeof component === "string") return createElement(component, inputs as KumiIntrinsicElements[IntrinsicTag]);
19
26
  return createElement(component, inputs);
20
27
  }
package/src/keyed-list.ts CHANGED
@@ -26,17 +26,20 @@ const layoutProps = new Set(["anchor", "width", "height", "opacity", "shown"]);
26
26
  const bindingProps: Partial<Record<UIElement["kind"], ReadonlySet<string>>> = {
27
27
  frame: new Set(["nativeScale", "nativeImageLayers"]),
28
28
  image: new Set(["nativeDesaturated", "verticalGradient"]),
29
+ texture: new Set(["src", "nativeDesaturated", "verticalGradient"]),
29
30
  text: new Set(["value", "color", "fontSize"]),
30
- button: new Set(["value", "disabled", "checked"]),
31
- editbox: new Set(["value"]),
31
+ button: new Set(["value", "disabled", "checked", "secureAction"]),
32
+ cooldown: new Set(["value"]),
33
+ editbox: new Set(["value", "nativeImageLayers"]),
32
34
  checkbox: new Set(["checked", "disabled"]),
33
35
  range: new Set(["value", "disabled"]),
34
36
  listbox: new Set(["value", "disabled"]),
35
37
  };
36
38
  // `ref` is not proxied: a ref owns the handle it received, so a row with a different ref is mounted again.
37
- const callbackProps = new Set(["onClick", "onChange", "onFocus", "onBlur", "onEnter", "onEscape", "onPointerEnter", "onPointerLeave",
38
- "onDrag", "onDragEnd", "onDragCancel", "onShow", "onHide", "onClickOutside", "onDismiss"]);
39
- const descriptorProps = new Set(["style", "src", "items", "data"]);
39
+ const callbackProps = new Set(["onClick", "onChange", "onCommit", "onFocus", "onBlur", "onEnter", "onEscape", "onPointerEnter", "onPointerLeave",
40
+ "onDrag", "onDragEnd", "onDragCancel", "onReceiveDrag", "onMove", "onMoveEnd", "onMoveCancel",
41
+ "onShow", "onHide", "onClickOutside", "onDismiss", "onSourceChange"]);
42
+ const descriptorProps = new Set(["style", "src", "texCoords", "items", "data"]);
40
43
 
41
44
  function propertyNames(props: Props) {
42
45
  return Object.keys(props).filter(name => name !== "children" && name !== "key" && props[name] !== undefined) as OwnedArray<string>;
@@ -0,0 +1,147 @@
1
+ import { createElement, type UIElement } from "./elements";
2
+ import { jsxMap } from "./keyed-list";
3
+ import { ownedArray, ownedMap, type OwnedReadonlyArray } from "./owned-collections";
4
+ import { ref, type ReadonlyRef, type SignalRef } from "./reactivity";
5
+ import { fail, ok, type Result } from "./result";
6
+ import type { RuntimeScope } from "./runtime";
7
+
8
+ /** A component that takes no props, such as a HUD view or a page. It reads its data from stores. */
9
+ export type ViewComponent = (this: void, props: Record<string, never>) => UIElement;
10
+ /** A component another module renders through `<Extensions name>`. */
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ export type ExtensionComponent = (this: void, props: any) => UIElement;
13
+
14
+ /** A view a module shows on screen while it is active. */
15
+ export interface ModuleView {
16
+ readonly component: ViewComponent;
17
+ /** The frame strata of the view's root, `"MEDIUM"` by default. */
18
+ readonly strata?: string;
19
+ }
20
+
21
+ /** A page a module adds to the addon window while it is active. */
22
+ export interface ModulePage {
23
+ /** The page's path in the window, such as `"/history"`. */
24
+ readonly path: string;
25
+ readonly title: string;
26
+ readonly component: ViewComponent;
27
+ /** Position among the window's pages. Lower values come first. */
28
+ readonly order?: number;
29
+ }
30
+
31
+ /** The addon's main window, declared once by the app module. */
32
+ export interface ModuleWindow {
33
+ /** The generated router: `import { router } from "@kumi/routes"`. */
34
+ readonly routes: unknown;
35
+ /** The window's frame. Render `<RouterView />` where the active page goes. */
36
+ readonly layout: ViewComponent;
37
+ readonly width: number;
38
+ readonly height: number;
39
+ /** The page to open first. Defaults to the first file route. */
40
+ readonly start?: string;
41
+ /** `"DIALOG"` by default. */
42
+ readonly strata?: string;
43
+ }
44
+
45
+ /** UI a module contributes. Kumi mounts and removes it with the module. */
46
+ export interface ModuleUi {
47
+ readonly views?: readonly (ViewComponent | ModuleView)[];
48
+ readonly extensions?: Readonly<Record<string, ExtensionComponent | readonly ExtensionComponent[]>>;
49
+ readonly pages?: readonly ModulePage[];
50
+ readonly window?: ModuleWindow;
51
+ }
52
+
53
+ type PlatformUi = (this: void, id: string, ui: ModuleUi, scope: RuntimeScope) => Result<void>;
54
+
55
+ interface Extension {
56
+ readonly id: number;
57
+ readonly component: ExtensionComponent;
58
+ }
59
+
60
+ let platform: PlatformUi | undefined;
61
+ let lastExtension = 0;
62
+ const points = ownedMap<string, SignalRef<readonly Extension[]>>();
63
+ const pages = ref<readonly ModulePage[]>([]);
64
+
65
+ // Copy into SDK-owned arrays: the native compiler needs proven sequences for loops and spreads.
66
+ function joined<Item extends object>(first: readonly Item[], second: readonly Item[]): readonly Item[] {
67
+ const list = ownedArray<Item>();
68
+ for (const item of first as OwnedReadonlyArray<Item>) list.push(item);
69
+ for (const item of second as OwnedReadonlyArray<Item>) list.push(item);
70
+ return list;
71
+ }
72
+
73
+ function without<Item extends object>(list: readonly Item[], removed: readonly Item[]): readonly Item[] {
74
+ const kept = ownedArray<Item>();
75
+ for (const item of list as OwnedReadonlyArray<Item>) if (!(removed as OwnedReadonlyArray<Item>).includes(item)) kept.push(item);
76
+ return kept;
77
+ }
78
+
79
+ function point(name: string) {
80
+ let entries = points.get(name);
81
+ if (entries === undefined) {
82
+ entries = ref<readonly Extension[]>([]);
83
+ points.set(name, entries);
84
+ }
85
+ return entries;
86
+ }
87
+
88
+ /** @internal The platform mounts views and the window. */
89
+ export function installModuleUi(this: void, host: PlatformUi | undefined): void {
90
+ platform = host;
91
+ }
92
+
93
+ /** The pages modules added to the window, in order. */
94
+ export function modulePages(this: void): ReadonlyRef<readonly ModulePage[]> {
95
+ return pages;
96
+ }
97
+
98
+ /** @internal Register a module's extensions and pages, then let the platform mount its views and window. */
99
+ export function mountModuleUi(this: void, id: string, ui: ModuleUi, scope: RuntimeScope): Result<void> {
100
+ const extensions = ui.extensions;
101
+ if (extensions !== undefined) {
102
+ for (const name of Object.keys(extensions)) {
103
+ const value = extensions[name];
104
+ const components = (typeof value === "function" ? [value] : value) as OwnedReadonlyArray<ExtensionComponent>;
105
+ const entries = point(name);
106
+ const added = ownedArray<Extension>();
107
+ for (const component of components) added.push({ id: ++lastExtension, component });
108
+ entries.value = joined(entries.value, added);
109
+ const removed = scope.onDispose(() => {
110
+ entries.value = without(entries.value, added);
111
+ });
112
+ if (!removed.ok) return removed;
113
+ }
114
+ }
115
+ const added = ui.pages as OwnedReadonlyArray<ModulePage> | undefined;
116
+ if (added !== undefined && added.length > 0) {
117
+ for (const page of added) {
118
+ if (!page.path.startsWith("/")) return fail("Module " + id + ": page path " + page.path + " must start with /");
119
+ }
120
+ const sorted = ownedArray<ModulePage>();
121
+ for (const page of joined(pages.value, added) as OwnedReadonlyArray<ModulePage>) sorted.push(page);
122
+ sorted.sort((left, right) => (left.order ?? 0) - (right.order ?? 0));
123
+ pages.value = sorted;
124
+ const removed = scope.onDispose(() => {
125
+ pages.value = without(pages.value, added);
126
+ });
127
+ if (!removed.ok) return removed;
128
+ }
129
+ const views = ui.views as OwnedReadonlyArray<ViewComponent | ModuleView> | undefined;
130
+ if ((views === undefined || views.length === 0) && ui.window === undefined) return ok(undefined);
131
+ if (platform === undefined) return fail("Module " + id + " declares views or a window. Start the addon with startAddon.");
132
+ return platform(id, ui, scope);
133
+ }
134
+
135
+ /**
136
+ * Render the components that active modules add to an extension point.
137
+ * A plugin's extensions appear when it starts and disappear when it stops.
138
+ *
139
+ * ```tsx
140
+ * <Extensions name="hud.sections" />
141
+ * ```
142
+ */
143
+ export function Extensions(this: void, props: { readonly name: string; readonly props?: object }): UIElement {
144
+ const entries = point(props.name);
145
+ const inputs = props.props ?? {};
146
+ return jsxMap(() => entries.value, entry => entry.id, entry => createElement(entry.component, inputs));
147
+ }
package/src/module.ts CHANGED
@@ -4,6 +4,8 @@ import { createServiceProvider, resolveProviders, serviceToken, type CheckedProv
4
4
  import type { RuntimeScope } from "./runtime";
5
5
  import { createFeatureLifecycle, type FeatureLifecycle } from "./feature-scope";
6
6
  import type { OwnedReadonlyArray } from "./owned-collections";
7
+ import { createStoreHost, openModuleStores, type AnyStoreFactory, type StoreHost } from "../state/setup-store";
8
+ import { mountModuleUi, type ModuleUi } from "./module-ui";
7
9
 
8
10
  export interface ModuleContext<Services extends object> {
9
11
  readonly services: Readonly<Services>;
@@ -20,7 +22,7 @@ export interface ModuleDeclaration<Exports extends object> {
20
22
  readonly serviceExports?: ServiceExports;
21
23
  readonly feature?: boolean;
22
24
  readonly initialize: (this: void, resolve: ResolveModule, scope?: ResolveModuleScope,
23
- attachFeature?: (this: void, controller: FeatureLifecycle) => void) => Result<Readonly<Exports>>;
25
+ attachFeature?: (this: void, controller: FeatureLifecycle) => void, stores?: StoreHost) => Result<Readonly<Exports>>;
24
26
  }
25
27
 
26
28
  declare const moduleExports: unique symbol;
@@ -73,11 +75,13 @@ export interface Module<Exports extends object> {
73
75
  }
74
76
 
75
77
  interface DeclarativeModuleOptions<Providers extends readonly ProviderDeclaration[], Exports extends ServiceExports,
76
- InferConstructor extends boolean = false> {
78
+ InferConstructor extends boolean = false> extends ModuleUi {
77
79
  readonly id: string;
78
80
  readonly imports?: readonly ModuleDependency<object>[];
79
81
  readonly feature?: boolean;
80
82
  readonly providers: Providers & NoInfer<CheckedProviders<Providers, InferConstructor>>;
83
+ /** Stores this module owns. They open when the module activates, and their setup can inject the module's services. */
84
+ readonly stores?: readonly AnyStoreFactory[];
81
85
  readonly exports: Exports;
82
86
  }
83
87
 
@@ -118,7 +122,7 @@ export function defineModule<
118
122
  if (!("providers" in definition)) return { exports: definition.exports({ services: definition.imports }) };
119
123
  if (typeof definition.providers !== "function") {
120
124
  const module = definition as DeclarativeModuleOptions<readonly ProviderDeclaration[], ServiceTokens>;
121
- return createServiceModule(module.id, module.imports ?? [], module.providers, module.exports, module.feature);
125
+ return createServiceModule(module.id, module.imports ?? [], module.providers, module.exports, module.feature, module.stores, module);
122
126
  }
123
127
  const legacy = definition as ModuleOptions<Dependencies, Providers, Exports> | ServiceModuleOptions<Dependencies, ServiceTokens>;
124
128
  return {
@@ -154,13 +158,14 @@ function hostInputs(resolve: ResolveModule, scope?: ResolveModuleScope) {
154
158
  }
155
159
 
156
160
  function createServiceModule<Exports extends ServiceExports>(id: string, imports: readonly ModuleDependency<object>[],
157
- providers: readonly ProviderDeclaration[], exports: Exports, feature?: boolean): ModuleDeclaration<PublicServices<Exports>> {
161
+ providers: readonly ProviderDeclaration[], exports: Exports, feature?: boolean,
162
+ stores?: readonly AnyStoreFactory[], ui?: ModuleUi): ModuleDeclaration<PublicServices<Exports>> {
158
163
  return {
159
164
  kind: "module",
160
165
  id,
161
166
  serviceExports: exports,
162
167
  feature,
163
- initialize(this: void, resolve, scope, attachFeature) {
168
+ initialize(this: void, resolve, scope, attachFeature, storeHost) {
164
169
  const imported = new Map<ServiceToken<object>, object>();
165
170
  const seen = new Set<string>();
166
171
  for (const reference of imports as OwnedReadonlyArray<ModuleDependency<object>>) {
@@ -189,8 +194,22 @@ function createServiceModule<Exports extends ServiceExports>(id: string, imports
189
194
  lifecycle = created.value;
190
195
  }
191
196
  const declarations = providers as OwnedReadonlyArray<ProviderDeclaration>;
197
+ const owned = stores as OwnedReadonlyArray<AnyStoreFactory> | undefined;
198
+ const hasStores = owned !== undefined && owned.length > 0;
199
+ const hasUi = ui !== undefined && (ui.views !== undefined || ui.extensions !== undefined || ui.pages !== undefined || ui.window !== undefined);
200
+ // Stores open after the providers, and UI mounts after the stores it reads.
201
+ const ready = !hasStores && !hasUi ? undefined : (inject: (this: void, token: ServiceToken<object>) => Result<object>) => {
202
+ if (scope === undefined || hasStores && storeHost === undefined) return fail("Module " + id + " needs a module container");
203
+ const owning = scope();
204
+ if (!owning.ok) return owning;
205
+ if (hasStores && storeHost !== undefined) {
206
+ const opened = openModuleStores(storeHost, id, owned, owning.value, inject);
207
+ if (!opened.ok) return opened;
208
+ }
209
+ return ui === undefined ? ok(undefined) : mountModuleUi(id, ui, owning.value);
210
+ };
192
211
  const services = resolveProviders(id, declarations.map(provider => createServiceProvider(provider)), exports, imported,
193
- hostInputs(resolve, scope), scope, lifecycle);
212
+ hostInputs(resolve, scope), scope, lifecycle, ready);
194
213
  if (services.ok && lifecycle !== undefined) attachFeature?.(lifecycle);
195
214
  return services;
196
215
  },
@@ -198,6 +217,8 @@ function createServiceModule<Exports extends ServiceExports>(id: string, imports
198
217
  }
199
218
 
200
219
  export interface ModuleContainer {
220
+ /** @internal The addon's stores. One instance per store ID across every module of the container. */
221
+ readonly stores: StoreHost;
201
222
  readonly bind: <Value extends object>(this: void, input: ModuleInput<Value>, value: NoInfer<Value>) => void;
202
223
  readonly resolve: ResolveModule;
203
224
  readonly setFeatureEnabled: <Value extends object>(this: void, module: ModuleDependency<Value>, enabled: boolean) => Result<void>;
@@ -211,6 +232,12 @@ export interface ModuleContainerOptions {
211
232
  export function createModuleContainer(protect: Protect = direct, options?: ModuleContainerOptions): ModuleContainer {
212
233
  const bindings = new Map<string, object>();
213
234
  const instances = new Map<string, object>();
235
+ const declared = new Map<string, object>();
236
+ let storeRoot: RuntimeScope | undefined;
237
+ const stores = createStoreHost(() => {
238
+ if (storeRoot === undefined || !storeRoot.isActive()) storeRoot = options?.forkScope();
239
+ return storeRoot;
240
+ });
214
241
  const features = new Map<string, FeatureLifecycle>();
215
242
  const path: string[] = [];
216
243
 
@@ -223,6 +250,8 @@ export function createModuleContainer(protect: Protect = direct, options?: Modul
223
250
  ? fail(`Missing module input: ${[...path, id].join(" -> ")}`)
224
251
  : ok(value as Readonly<Value>);
225
252
  }
253
+ const known = declared.get(id);
254
+ if (known !== undefined && known !== reference) return fail(`Duplicate module ID: ${id}. Each module needs its own ID.`);
226
255
  const existing = instances.get(id);
227
256
  if (existing !== undefined) return ok(existing as Readonly<Value>);
228
257
  const cycle = path.indexOf(id);
@@ -239,8 +268,9 @@ export function createModuleContainer(protect: Protect = direct, options?: Modul
239
268
  }
240
269
 
241
270
  path.push(id);
271
+ declared.set(id, reference);
242
272
  const initialized = protect(() => reference.initialize(resolve, getScope,
243
- reference.feature === true ? feature => { features.set(id, feature); } : undefined));
273
+ reference.feature === true ? feature => { features.set(id, feature); } : undefined, stores));
244
274
  let result = initialized.ok ? initialized.value : fail(`Module ${id}: ${initialized.reason}`);
245
275
  if (result.ok && reference.feature === true && scope !== undefined) {
246
276
  const cleanup = scope.onDispose(() => { features.delete(id); });
@@ -248,7 +278,10 @@ export function createModuleContainer(protect: Protect = direct, options?: Modul
248
278
  }
249
279
  if (result.ok) {
250
280
  instances.set(id, result.value);
251
- } else if (scope !== undefined) {
281
+ } else {
282
+ declared.delete(id);
283
+ }
284
+ if (!result.ok && scope !== undefined) {
252
285
  if (reference.feature === true) features.delete(id);
253
286
  const stopped = protect(scope.dispose);
254
287
  const cleanup = stopped.ok ? stopped.value : stopped;
@@ -259,6 +292,7 @@ export function createModuleContainer(protect: Protect = direct, options?: Modul
259
292
  };
260
293
 
261
294
  return {
295
+ stores,
262
296
  bind: (input, value) => { bindings.set(input.id, value); },
263
297
  resolve,
264
298
  setFeatureEnabled: (module, enabled) => {