@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
@@ -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,19 +1,23 @@
1
- import type { Anchor, Binding } from "./elements";
1
+ import type { ActionSlot, Anchor, Binding, CooldownValue } from "./elements";
2
2
  import type { ImageVerticalGradient } from "./images";
3
- import type { ReadonlyRef } from "./reactivity";
3
+ import { isReactiveRef, 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
+
10
+ /** @internal Recognize reactive values before falling back to structural refs. */
11
+ export function isBindingRef(value: unknown): value is ReadonlyRef<unknown> {
12
+ return value !== null && typeof value === "object" && (isReactiveRef(value) || value instanceof TextBinding || "value" in value);
13
+ }
9
14
 
10
15
  /** Apply a static property once or subscribe to one reactive property for the mount's lifetime. */
11
16
  export function bindValue<T extends BoundValue>(scope: RuntimeScope, value: Binding<T>,
12
17
  apply: (this: void, value: T) => void,
13
18
  equals: (this: void, previous: T | undefined, current: T) => boolean = (previous, current) => previous === current,
14
19
  validate?: (this: void, value: T) => Failure | undefined): Failure | undefined {
15
- // Lua can invoke an accessor when checking for a property. A text binding reads its fragments in the effect.
16
- if (typeof value !== "object" || !((value as object) instanceof TextBinding || "value" in value)) {
20
+ if (!isBindingRef(value)) {
17
21
  const failure = validate?.(value as T);
18
22
  if (failure !== undefined) return failure;
19
23
  apply(value as T);
@@ -21,15 +25,17 @@ export function bindValue<T extends BoundValue>(scope: RuntimeScope, value: Bind
21
25
  }
22
26
  const ref = value as ReadonlyRef<T | Result<T>>;
23
27
  let previous: T | undefined;
28
+ let initialized = false;
24
29
  const subscription = scope.watchEffect(() => {
25
30
  const next = ref.value;
26
31
  if (typeof next === "object" && "ok" in next && !next.ok) return next;
27
32
  const current = typeof next === "object" && "ok" in next ? next.value : next;
28
33
  const failure = validate?.(current);
29
34
  if (failure !== undefined) return failure;
30
- if (equals(previous, current)) return;
35
+ if (initialized && equals(previous, current)) return;
31
36
  apply(current);
32
37
  previous = current;
38
+ initialized = true;
33
39
  });
34
40
  return subscription.ok ? undefined : subscription;
35
41
  }
package/src/context.ts CHANGED
@@ -1,15 +1,39 @@
1
1
  import type { Protect } from "./result";
2
2
 
3
+ interface ContextFrame {
4
+ readonly key: object;
5
+ readonly value: unknown;
6
+ readonly previous?: ContextFrame;
7
+ }
8
+
9
+ let current: ContextFrame | undefined;
10
+
11
+ /** @internal Save the context of a render callback that will run later. */
12
+ export function captureContexts() {
13
+ return current;
14
+ }
15
+
16
+ /** @internal Run a protected callback with the context it was created in. */
17
+ export function withContexts<Output>(captured: ContextFrame | undefined, render: (this: void) => Output): Output {
18
+ const previous = current;
19
+ current = captured;
20
+ const result = render();
21
+ current = previous;
22
+ return result;
23
+ }
24
+
3
25
  export function createContext<Value>() {
4
- let current: Value | undefined;
26
+ const key = {};
5
27
 
6
28
  function run<Output>(value: Value, render: (this: void) => Output, protect: Protect) {
7
- const previous = current;
8
- current = value;
9
- const result = protect(render);
10
- current = previous;
11
- return result;
29
+ return withContexts({ key, value, previous: current }, () => protect(render));
30
+ }
31
+
32
+ function use(): Value | undefined {
33
+ for (let frame = current; frame !== undefined; frame = frame.previous) {
34
+ if (frame.key === key) return frame.value as Value;
35
+ }
12
36
  }
13
37
 
14
- return { run, use: () => current };
38
+ return { run, use };
15
39
  }
package/src/css-tokens.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { CssTokenRecipe } from "./css-v1";
2
+ import { isIntrinsicWidth } from "./flex-layout";
2
3
  import { parseGridSpan, parseGridTracks } from "./grid-tracks";
3
4
  import { ownedArray, type OwnedArray, type OwnedLuaArray, type OwnedReadonlyArray, type OwnedRecord } from "./owned-collections";
4
5
  import { fail, ok, type Result } from "./result";
5
- import type { StyleEnvironment } from "./style-variables";
6
+ import { resolveStyleValue, type StyleEnvironment } from "./style-variables";
6
7
 
7
8
  type WithRecipes = { readonly styleTokens?: readonly CssTokenRecipe[] };
8
9
  type Field = string | number;
@@ -11,25 +12,30 @@ type Bag = Record<Field, unknown>;
11
12
  function digit(code: number) { return code >= 48 && code <= 57; }
12
13
 
13
14
  function decimal(text: string): number | undefined {
15
+ const length = text.length;
14
16
  const start = text.startsWith("-") || text.startsWith("+") ? 1 : 0;
15
17
  let index = start;
16
- while (digit(text.charCodeAt(index))) index++;
18
+ while (index < length && digit(text.charCodeAt(index))) index += 1;
17
19
  const hasWhole = index > start;
18
- if (text.charCodeAt(index) === 46) {
19
- const fraction = ++index;
20
- while (digit(text.charCodeAt(index))) index++;
20
+ if (index < length && text.charCodeAt(index) === 46) {
21
+ index += 1;
22
+ const fraction = index;
23
+ while (index < length && digit(text.charCodeAt(index))) index += 1;
21
24
  if (fraction === index) return;
22
25
  } 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++;
26
+ if (index < length) {
27
+ const separator = text.charCodeAt(index);
28
+ if (separator !== 69 && separator !== 101) return;
29
+ index += 1;
30
+ if (index < length) {
31
+ const sign = text.charCodeAt(index);
32
+ if (sign === 43 || sign === 45) index += 1;
33
+ }
28
34
  const exponent = index;
29
- while (digit(text.charCodeAt(index))) index++;
35
+ while (index < length && digit(text.charCodeAt(index))) index += 1;
30
36
  if (exponent === index) return;
31
37
  }
32
- if (index !== text.length) return;
38
+ if (index !== length) return;
33
39
  const number = Number(text);
34
40
  return Number.isFinite(number) ? number : undefined;
35
41
  }
@@ -157,7 +163,10 @@ function decode(raw: string, recipe: CssTokenRecipe): unknown {
157
163
  const columns = parseGridSpan(text);
158
164
  return columns === undefined ? undefined : `span ${columns}`;
159
165
  }
160
- if (kind === "size" && text === "auto" && add === undefined) return text;
166
+ if (kind === "size" && add === undefined) {
167
+ if (text === "auto" || (recipe.path as OwnedReadonlyArray<Field>)[0] === "width" && isIntrinsicWidth(text)) return text;
168
+ if (text.endsWith("%") && (decimal(text.slice(0, -1)) ?? -1) >= 0) return text;
169
+ }
161
170
  const length = kind === "length" || kind === "signedLength" || kind === "positiveLength" || kind === "size" || kind === "radius";
162
171
  const number = kind === "fontWeight" && add === undefined && (text === "normal" || text === "bold")
163
172
  ? text === "normal" ? 400 : 700 : length ? pixels(text) : decimal(text);
@@ -201,6 +210,11 @@ export function resolveCssTokens<Style extends WithRecipes>(this: void, base: St
201
210
  token = authored.value ?? false;
202
211
  sourced[recipe.token] = token;
203
212
  }
213
+ if (token === false && recipe.fallbackExpression !== undefined) {
214
+ const fallback = resolveStyleValue(recipe.fallbackExpression, environment);
215
+ if (!fallback.ok) return fallback;
216
+ token = fallback.value ?? false;
217
+ }
204
218
  if (token === false || token === recipe.source) continue;
205
219
  const parsed = decode(token, recipe);
206
220
  const path = recipe.path as OwnedReadonlyArray<Field>;
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;
@@ -27,6 +35,8 @@ export interface CssTokenRecipe {
27
35
  readonly fallback: unknown;
28
36
  /** @internal Exact compiler-validated token text whose decoded value is `fallback`. */
29
37
  readonly source?: string;
38
+ /** @internal Optional CSS fallback evaluated when the named variable is missing. */
39
+ readonly fallbackExpression?: string;
30
40
  readonly add?: number;
31
41
  readonly part?: string | number;
32
42
  readonly values?: readonly (string | number)[];
@@ -43,8 +53,11 @@ export interface CssV1Style {
43
53
  * between them, its own size or its content's (as `width: fit-content`). */
44
54
  autoMargin?: Binding<readonly [boolean, boolean, boolean, boolean]>;
45
55
  border?: CssBorder;
56
+ /** @internal A hint for the final border after class and inline styles are combined. */
57
+ borderPaint?: CssBorderPaintPlan;
46
58
  borderRadius?: number;
47
59
  backgroundImage?: StatePaint["backgroundImage"];
60
+ maskImage?: Readonly<{ path: string }>;
48
61
  fontWeight?: CssFontWeight;
49
62
  textAlign?: CssTextAlign;
50
63
  textShadow?: CssTextShadow;
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
 
@@ -150,8 +154,12 @@ type ElementLayout<Kind extends MountedElementKind> = NativeLayout & { nodeRef?:
150
154
  interface NativeProps {
151
155
  frame: ElementLayout<"frame"> & ElementEvents & {
152
156
  ref?: ElementRef<"frame">;
157
+ /** Allow the frame to run snippets installed with secureStateSnippet. */
158
+ secureStateHandler?: true;
153
159
  /** The native frame's own scale in parent coordinates. */
154
160
  nativeScale?: Binding<number>;
161
+ /** Lay out this keyed frame directly in its parent CSS container. */
162
+ directKeyedLayout?: true;
155
163
  /** Decorative artwork for WoW, reconciled as a single layer without child frames. */
156
164
  nativeImageLayers?: Binding<readonly NativeImageLayer[]>;
157
165
  /** Use the host's two native nine-slice textures for a rounded fill and decorative 1px border. */
@@ -170,6 +178,17 @@ interface NativeProps {
170
178
  nativeDesaturated?: Binding<boolean>;
171
179
  ref?: ElementRef<"image">;
172
180
  };
181
+ texture: Omit<NativeProps["image"], "src"> & {
182
+ src: Binding<TextureSource>;
183
+ texCoords?: TextureCoordinates;
184
+ onSourceChange?(this: void, source: TextureSource): void;
185
+ };
186
+ cooldown: NativeLayout & {
187
+ value: Binding<CooldownValue | undefined>;
188
+ /** Custom texture for the swipe. With this option the swipe is the sole timer visual. */
189
+ swipeTexture?: string;
190
+ reverse?: boolean;
191
+ };
173
192
  scrollview: ElementLayout<"scrollview"> & {
174
193
  contentHeight: Binding<number>;
175
194
  ref?: ElementRef<"scrollview">;
@@ -206,6 +225,19 @@ interface NativeProps {
206
225
  disabled?: Binding<boolean>;
207
226
  checked?: Binding<boolean>;
208
227
  ref?: ElementRef<"button">;
228
+ /** Maximum pointer hold in seconds for onClick. Pointer drags also suppress onClick. */
229
+ clickMaxDuration?: number;
230
+ secureAction?: Binding<ActionSlot | undefined>;
231
+ /** Macro text run by a hardware click. Use this in place of `secureAction`. */
232
+ secureMacro?: Binding<string | undefined>;
233
+ /** An anchored secure button keeps its identity and mounts paint and children on its first show. */
234
+ deferContentUntilShown?: true;
235
+ /** Lay out this keyed button directly in its parent CSS container. */
236
+ directKeyedLayout?: true;
237
+ onReceiveDrag?(this: void): Result<boolean> | void;
238
+ onMove?(this: void, x: number, y: number): void;
239
+ onMoveEnd?(this: void, x: number, y: number): void;
240
+ onMoveCancel?(this: void): void;
209
241
  onDrag?(this: void, offsetY: number): void;
210
242
  onDragEnd?(this: void, offsetY: number): void;
211
243
  onDragCancel?(this: void): void;
@@ -216,6 +248,7 @@ interface NativeProps {
216
248
  label?: string;
217
249
  placeholder?: string;
218
250
  unstyled?: boolean;
251
+ nativeImageLayers?: Binding<readonly NativeImageLayer[]>;
219
252
  nativeRoundedArt?: true;
220
253
  disabled?: Binding<boolean>;
221
254
  maxLetters?: number;
@@ -243,6 +276,8 @@ interface NativeProps {
243
276
  max: number;
244
277
  step?: number;
245
278
  onChange?(this: void, value: number): void;
279
+ /** Runs after a pointer adjustment that changed the value. */
280
+ onCommit?(this: void): void;
246
281
  };
247
282
  listbox: ElementLayout<"listbox"> & {
248
283
  value: Binding<string>;
@@ -7,9 +7,10 @@ type Insets = number | readonly [number, number] | readonly [number, number, num
7
7
  /** A border-box length; a percentage resolves against the parent's content box when that is known. */
8
8
  export type LayoutLength = number | `${number}%`;
9
9
  type Size = LayoutLength | "auto";
10
+ type IntrinsicWidth = "fit-content" | "min-content" | "max-content";
10
11
 
11
12
  export interface FlexStyle {
12
- width?: Size;
13
+ width?: Size | IntrinsicWidth;
13
14
  height?: Size;
14
15
  minWidth?: number;
15
16
  minHeight?: number;
@@ -87,6 +88,7 @@ interface Axis {
87
88
  minimum: number;
88
89
  maximum: number;
89
90
  specified?: number;
91
+ intrinsic?: IntrinsicWidth;
90
92
  /** A percentage size, resolved against the parent's content box during placement. */
91
93
  percent?: number;
92
94
  preferred: number;
@@ -124,7 +126,11 @@ export function layoutPercent(this: void, size: unknown): number | undefined {
124
126
  return Number.isFinite(value) && value >= 0 ? value : undefined;
125
127
  }
126
128
 
127
- function axis(size: Size | undefined, minimum: number | undefined, maximum: number | undefined,
129
+ export function isIntrinsicWidth(this: void, value: unknown): value is IntrinsicWidth {
130
+ return value === "fit-content" || value === "min-content" || value === "max-content";
131
+ }
132
+
133
+ function axis(size: Size | IntrinsicWidth | undefined, minimum: number | undefined, maximum: number | undefined,
128
134
  paddingStart: number, paddingEnd: number, marginStart: number, marginEnd: number): Axis {
129
135
  const floor = Math.max(paddingStart + paddingEnd, minimum ?? 0);
130
136
  return {
@@ -132,6 +138,7 @@ function axis(size: Size | undefined, minimum: number | undefined, maximum: numb
132
138
  minimum: floor,
133
139
  maximum: Math.max(floor, maximum ?? Infinity),
134
140
  specified: typeof size === "number" ? size : undefined,
141
+ intrinsic: isIntrinsicWidth(size) ? size : undefined,
135
142
  percent: layoutPercent(size),
136
143
  preferred: 0,
137
144
  };
@@ -238,6 +245,11 @@ function measureLeaf(item: Item, dimension: Dimension) {
238
245
  }
239
246
 
240
247
  function measureAxis(item: Item, dimension: Dimension) {
248
+ measurePreferred(item, dimension);
249
+ if (item[dimension].intrinsic === "min-content") item.width.preferred = minContentBox(item);
250
+ }
251
+
252
+ function measurePreferred(item: Item, dimension: Dimension) {
241
253
  const { children } = item;
242
254
  const target = item[dimension];
243
255
  if (children === undefined) {
@@ -304,6 +316,7 @@ function preferredSize(item: Item, dimension: Dimension, available: number) {
304
316
  const box = item[dimension];
305
317
  if (dimension === "width" && item.source.fullWidth === true) return Math.max(0, available - margins(box));
306
318
  if (box.percent !== undefined) return available * box.percent / 100;
319
+ if (box.intrinsic === "fit-content") return Math.min(box.preferred, Math.max(minContentBox(item), available - margins(box)));
307
320
  return box.preferred;
308
321
  }
309
322
 
@@ -483,7 +496,7 @@ function positionAligned(child: Item, dimension: Dimension, start: number, inner
483
496
  alignment: GridAlignment | FlexAlignment) {
484
497
  const box = child[dimension];
485
498
  const available = inner - margins(box);
486
- const preferred = alignment === "stretch" && box.specified === undefined && box.percent === undefined ? Math.max(0, available)
499
+ const preferred = alignment === "stretch" && box.specified === undefined && box.percent === undefined && box.intrinsic === undefined ? Math.max(0, available)
487
500
  : preferredSize(child, dimension, inner);
488
501
  const target = clamp(preferred, box);
489
502
  const offset = alignedOffset(alignment, available - target);
@@ -523,8 +536,10 @@ function positionAbsolutes(item: Item, dimension: Dimension, size: number) {
523
536
  const style = child.source.style;
524
537
  const start = dimension === "width" ? style.left : style.top;
525
538
  const end = dimension === "width" ? style.right : style.bottom;
526
- let target = box.specified ?? (box.percent !== undefined ? size * box.percent / 100
527
- : start !== undefined && end !== undefined ? size - start - end - margins(box) : box.preferred);
539
+ const available = size - (start ?? 0) - (end ?? 0);
540
+ let target = box.intrinsic !== undefined ? preferredSize(child, dimension, available)
541
+ : box.specified ?? (box.percent !== undefined ? size * box.percent / 100
542
+ : start !== undefined && end !== undefined ? available - margins(box) : box.preferred);
528
543
  target = clamp(target, box);
529
544
  const at = start !== undefined ? start + box.marginStart
530
545
  : end !== undefined ? size - end - box.marginEnd - target : item[dimension].paddingStart + box.marginStart;
@@ -643,6 +658,12 @@ function minContent(item: Item): number {
643
658
  return widest + padding;
644
659
  }
645
660
 
661
+ function minContentBox(item: Item): number {
662
+ if (item.children !== undefined) return minContent(item);
663
+ const own = item.source.minContentWidth?.();
664
+ return own === undefined ? item.width.preferred : own + item.width.paddingStart + item.width.paddingEnd;
665
+ }
666
+
646
667
  function minimumContribution(item: Item, dimension: Dimension) {
647
668
  const box = item[dimension];
648
669
  const explicitMinimum = dimension === "width" ? item.source.style.minWidth : item.source.style.minHeight;
@@ -31,6 +31,8 @@ export interface FrameLimits {
31
31
  }
32
32
 
33
33
  export interface FrameScheduler {
34
+ /** @internal Frame clock for animations, when supplied by the driver. */
35
+ readonly nowMs?: FrameTiming["nowMs"];
34
36
  queue(this: void, key: FrameKey, run: FrameJob, options?: FrameJobOptions): void;
35
37
  cancel(this: void, key: FrameKey): void;
36
38
  queued(this: void, key: FrameKey): FrameLane | undefined;
@@ -202,7 +204,9 @@ export function createFrameScheduler(
202
204
 
203
205
  function remainingMs() {
204
206
  const own = deadline === undefined ? budget() : deadline - now();
205
- return Math.max(0, Math.min(own, driver.remainingMs?.() ?? own));
207
+ const parent = driver.remainingMs?.();
208
+ const available = parent !== undefined && (parent < own || Number.isNaN(parent)) ? parent : own;
209
+ return available <= 0 ? 0 : available;
206
210
  }
207
211
 
208
212
  function roll(time: number) {
@@ -330,5 +334,5 @@ export function createFrameScheduler(
330
334
  wake();
331
335
  }
332
336
 
333
- return { queue, cancel, remainingMs, queued: key => byKey.get(key)?.lane, combatChanged: wake, step, inspect };
337
+ return { nowMs: driver.nowMs, queue, cancel, remainingMs, queued: key => byKey.get(key)?.lane, combatChanged: wake, step, inspect };
334
338
  }
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  /// <reference path="./jsx.d.ts" />
3
3
  export * from "./elements";
4
4
  export type { StatePaint, StateStyleVariant, StyleState } from "./style-states";
5
- export type { ClassNames, StyleClass } from "./style-classes";
5
+ export { clsx, type ClassNames, type ClassValue, type StyleClass } from "./style-classes";
6
6
  export type { KumiNode, MountedElementKind, NodeRect, NodeRef } from "./element-node";
7
7
  export type { NodeQuery, SelectorError } from "./node-selectors";
8
8
  export * from "./bindings";
@@ -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 ModuleReplacement, 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
  }