@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,7 +1,9 @@
1
1
  use std::collections::BTreeMap;
2
2
  use std::fs;
3
3
  use std::io;
4
- use std::path::{Component, Path, PathBuf};
4
+ use std::path::{Path, PathBuf};
5
+
6
+ pub const SOURCE_DIRECTORY: &str = "src/app/routes";
5
7
 
6
8
  fn files(root: &Path, dir: &Path, found: &mut Vec<PathBuf>) -> io::Result<()> {
7
9
  for entry in fs::read_dir(dir)? {
@@ -39,23 +41,18 @@ fn slash(path: &Path) -> Result<String, Box<dyn std::error::Error>> {
39
41
 
40
42
  pub fn generate(
41
43
  workspace: &Path,
42
- root: &Path,
43
44
  output: &Path,
44
45
  check: bool,
45
46
  ) -> Result<(), Box<dyn std::error::Error>> {
46
- let base = root
47
- .strip_prefix(workspace)
48
- .map_err(|_| "The route directory must be inside the workspace")?;
49
- if base
50
- .components()
51
- .any(|part| !matches!(part, Component::Normal(_)))
52
- {
53
- return Err(
54
- "The route directory must use a workspace-relative path without parent segments".into(),
55
- );
56
- }
47
+ let base = Path::new(SOURCE_DIRECTORY);
48
+ let root = workspace.join(base);
57
49
  let mut found = Vec::new();
58
- files(root, root, &mut found)?;
50
+ files(&root, &root, &mut found).map_err(|error| {
51
+ io::Error::new(
52
+ error.kind(),
53
+ format!("Cannot discover routes in {}: {error}", root.display()),
54
+ )
55
+ })?;
59
56
  found.sort();
60
57
  let mut routes = BTreeMap::new();
61
58
  let mut pages = Vec::new();
@@ -0,0 +1,18 @@
1
+ local function setupStoreView(fields, accessors)
2
+ return setmetatable(fields, {
3
+ __index = function(_, key)
4
+ local accessor = accessors[key]
5
+ if accessor ~= nil then return (accessor.get()) end
6
+ end,
7
+ __newindex = function(store, key, value)
8
+ local accessor = accessors[key]
9
+ if accessor == nil then
10
+ rawset(store, key, value)
11
+ return
12
+ end
13
+ local write = accessor.set
14
+ if write == nil then error("Cannot assign readonly store field " .. tostring(key), 2) end
15
+ write(value)
16
+ end,
17
+ })
18
+ end
@@ -1 +1 @@
1
- 5fed281d0180bafbf91a39de73c1550647af86bf8346e416fc74c85df61b1761
1
+ faac38b892cdbd3155b8fb05608b1e76e561bb056076bfad110ee59f477c30ca
@@ -5,7 +5,7 @@ import { resolve } from "node:path";
5
5
  export const signalIntrinsic = {
6
6
  file: "src/signal-kernel.ts",
7
7
  module: "src/signal-kernel",
8
- operation: "SignalFactoryV1",
8
+ operation: "SignalFactoryV3",
9
9
  abi: "createSignalFactory\tno-self\t3\tscalar",
10
10
  fingerprint: readFileSync(new URL("./signal-kernel.fingerprint", import.meta.url), "utf8").trim(),
11
11
  };
@@ -46,7 +46,7 @@ export function lowerSignalFactory(ts, program, sdkRoot, input = resolve(sdkRoot
46
46
  const printer = ts.createPrinter({ removeComments: true, newLine: ts.NewLineKind.LineFeed });
47
47
  const fingerprint = sha256(printer.printFile(file));
48
48
  if (fingerprint !== signalIntrinsic.fingerprint) {
49
- invalid(declaration, `SignalFactoryV1 source changed (${fingerprint}); review the native lowering`);
49
+ invalid(declaration, `SignalFactoryV3 source changed (${fingerprint}); review the native lowering`);
50
50
  }
51
51
  const source = sha256(file.text);
52
52
  const start = file.getLineAndCharacterOfPosition(declaration.getStart(file));
@@ -0,0 +1,22 @@
1
+ local function wowReadable(value)
2
+ local secret = issecretvalue
3
+ if secret ~= nil and secret(value) == true then return nil end
4
+ return value
5
+ end
6
+
7
+ local function wowReadableSecond(_, value)
8
+ local secret = issecretvalue
9
+ if secret ~= nil and secret(value) == true then return nil end
10
+ return value
11
+ end
12
+
13
+ local function wowReadableThird(_, _, value)
14
+ local secret = issecretvalue
15
+ if secret ~= nil and secret(value) == true then return nil end
16
+ return value
17
+ end
18
+
19
+ local function wowOptionalReadable(read, ...)
20
+ if read == nil then return nil end
21
+ return wowReadable((read(...)))
22
+ end
@@ -0,0 +1,111 @@
1
+ import { compileCssDeclarations } from "./css-v1.mjs";
2
+ import { assertMediaProperties, compareStyleStates, parseLocalStyleSelector, parseMediaQuery } from "./style-states.mjs";
3
+
4
+ function declarations(rule) {
5
+ return rule.nodes.filter(node => {
6
+ if (node.type === "decl") return true;
7
+ if (node.type === "comment") return false;
8
+ throw node.error("Expected a style declaration");
9
+ });
10
+ }
11
+
12
+ export function readStyleBreakpoints(root) {
13
+ const rules = root.nodes.filter(node => node.type !== "comment");
14
+ if (rules.length !== 1 || rules[0].type !== "rule" || rules[0].selector !== ":export") {
15
+ throw root.error("Expected one :export rule for style breakpoints");
16
+ }
17
+ const names = new Set();
18
+ const widths = new Map();
19
+ for (const { prop, value } of declarations(rules[0])) {
20
+ const width = Number(value);
21
+ if (!/^[a-z][a-zA-Z0-9]*$/u.test(prop) || !/^\d+$/u.test(value) || !Number.isSafeInteger(width)) {
22
+ throw rules[0].error("Expected a named breakpoint with a nonnegative integer width", { word: prop });
23
+ }
24
+ if (widths.has(width) || names.has(prop)) throw rules[0].error(`Duplicate breakpoint ${prop}`, { word: prop });
25
+ names.add(prop);
26
+ widths.set(width, prop);
27
+ }
28
+ if (widths.get(0) !== "base") throw rules[0].error("The base breakpoint must be 0");
29
+ return widths;
30
+ }
31
+
32
+ export function readStyleTokens(root) {
33
+ const tokens = new Map();
34
+ for (const rule of root.nodes) {
35
+ if (rule.type === "comment") continue;
36
+ if (rule.type !== "rule" || rule.selector !== ":root") {
37
+ throw rule.error("Expected a :root rule for CSS tokens");
38
+ }
39
+ for (const declaration of declarations(rule)) {
40
+ const { prop, value, important } = declaration;
41
+ if (!/^--[\w-]+$/u.test(prop) || !value.trim() || important) {
42
+ throw declaration.error("Expected a CSS custom property with a value");
43
+ }
44
+ tokens.set(prop, value.trim());
45
+ }
46
+ }
47
+ return tokens;
48
+ }
49
+
50
+ export function compileLocalStyleModule(root, breakpoints, tokens) {
51
+ const classes = Object.create(null);
52
+ const rules = new Map();
53
+ const states = new Map();
54
+ const media = new Map();
55
+
56
+ function classFor(name) {
57
+ return classes[name] ??= { className: name };
58
+ }
59
+
60
+ function compileRule(node, query) {
61
+ if (node.type === "comment") return;
62
+ if (node.type !== "rule") throw node.error("Expected a local style rule");
63
+ const contents = declarations(node);
64
+ for (const selector of node.selectors) {
65
+ let selected;
66
+ try { selected = parseLocalStyleSelector(selector); }
67
+ catch (error) { throw node.error(error.message, { word: selector }); }
68
+ const { name, when } = selected;
69
+ if (query !== undefined) {
70
+ if (when.length !== 0) throw node.error("Media queries require a plain local class");
71
+ assertMediaProperties(contents);
72
+ if (!media.has(name)) media.set(name, []);
73
+ media.get(name).push({ when: query, style: compileCssDeclarations(contents, { tokens }) });
74
+ continue;
75
+ }
76
+
77
+ const key = name + ":" + when.join(":");
78
+ if (!rules.has(key)) rules.set(key, { name, when, contents: new Map() });
79
+ const merged = rules.get(key).contents;
80
+ for (const declaration of contents) {
81
+ // Preserve the last declaration's position relative to shorthands.
82
+ merged.delete(declaration.prop);
83
+ merged.set(declaration.prop, declaration);
84
+ }
85
+ }
86
+ }
87
+
88
+ for (const node of root.nodes) {
89
+ if (node.type !== "atrule") {
90
+ compileRule(node);
91
+ continue;
92
+ }
93
+ if (node.name !== "media" || node.nodes === undefined) throw node.error("Expected a local style rule or media block");
94
+ let query;
95
+ try { query = parseMediaQuery(node.params, breakpoints); }
96
+ catch (error) { throw node.error(error.message); }
97
+ for (const child of node.nodes) compileRule(child, query);
98
+ }
99
+
100
+ for (const { name, when, contents } of rules.values()) {
101
+ const style = compileCssDeclarations([...contents.values()], { tokens, state: when.length !== 0 });
102
+ if (when.length === 0) Object.assign(classFor(name), style);
103
+ else {
104
+ if (!states.has(name)) states.set(name, []);
105
+ states.get(name).push({ when, paint: style });
106
+ }
107
+ }
108
+ for (const [name, variants] of states) classFor(name).stateStyles = variants.sort(compareStyleStates);
109
+ for (const [name, variants] of media) classFor(name).mediaStyles = variants;
110
+ return classes;
111
+ }
@@ -0,0 +1,24 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import postcss from "postcss";
4
+ import { compileLocalStyleModule, readStyleTokens } from "./style-modules.mjs";
5
+
6
+ test("loads standard CSS defaults in base, state and media declarations", () => {
7
+ const tokens = readStyleTokens(postcss.parse(`
8
+ :root { --Accent: #224466; --accent: var(--Accent); --panel-width: 280px; }
9
+ :root { --panel-width: 300px; }
10
+ `));
11
+ const styles = compileLocalStyleModule(postcss.parse(`
12
+ .panel { width: var(--panel-width); background-color: var(--accent); }
13
+ .panel:hover { border-color: var(--optional, var(--accent)); }
14
+ @media (max-width: 480px) { .panel { width: var(--compact, 200px); } }
15
+ `), new Map([[480, "compact"]]), tokens);
16
+ const { panel } = styles;
17
+ assert.equal(panel.width, 300);
18
+ assert.equal(panel.backgroundColor, "var(--accent, #224466)");
19
+ assert.equal(panel.stateStyles[0].paint.borderColor, "#224466");
20
+ assert.equal(panel.stateStyles[0].paint.styleTokens[0].fallbackExpression, "var(--accent)");
21
+ assert.equal(panel.mediaStyles[0].style.width, 200);
22
+ assert.throws(() => compileLocalStyleModule(postcss.parse(".panel { width: var(--undeclared); }"),
23
+ new Map(), tokens), /Unknown token --undeclared/u);
24
+ });
@@ -22,16 +22,18 @@ export function parseLocalStyleSelector(selector) {
22
22
  return { name: match[1], when };
23
23
  }
24
24
 
25
- function parseBackgroundImage(value) {
26
- const atlas = textureAtlas.exec(value);
27
- if (atlas) return { atlas: atlas[1] ?? atlas[3] };
28
-
25
+ export function parseTexturePath(value) {
29
26
  const path = textureUrl.exec(value)?.[2];
30
27
  if (path === undefined) return;
31
28
  const relative = path.startsWith("./") ? path.slice(2) : path;
32
29
  if (relative.split("/").every(segment => pathSegment.test(segment))) return { path };
33
30
  }
34
31
 
32
+ function parseBackgroundImage(value) {
33
+ const atlas = textureAtlas.exec(value);
34
+ return atlas ? { atlas: atlas[1] ?? atlas[3] } : parseTexturePath(value);
35
+ }
36
+
35
37
  export function parseStyleColor(value) {
36
38
  if (hexColor.test(value)) return value;
37
39
  const rgba = rgbaColor.exec(value);
package/config.ts CHANGED
@@ -1,17 +1,59 @@
1
- export interface BundleImport<Bundle extends string = string> {
2
- bundle: Bundle;
3
- mode: "embedded" | "plugin";
4
- /** Generate the Lua build entry from the feature module's activate export. */
5
- entry?: "module";
1
+ /**
2
+ * Types for `kumi.config.ts`. Write the config as a plain object:
3
+ *
4
+ * ```ts
5
+ * import type { KumiConfig } from "@overmvp/kumi/config";
6
+ *
7
+ * export default {
8
+ * addon: { name: "MyAddon", title: "My Addon", savedVariables: "MyAddonDB" },
9
+ * } satisfies KumiConfig;
10
+ * ```
11
+ */
12
+ export interface KumiConfig {
13
+ /** The main addon. Kumi writes its TOC from these fields. */
14
+ readonly addon: AddonConfig;
15
+ /**
16
+ * Optional parts that players turn on or off in the addon list, keyed by plugin ID
17
+ * (lowercase letters, digits and dashes). Each plugin is built as its own addon folder, `<name>_<id>`.
18
+ */
19
+ readonly plugins?: Readonly<Record<string, PluginConfig>>;
20
+ /** Whether turning a plugin on or off applies to the current character or to every character. Defaults to `"account"`. */
21
+ readonly pluginState?: "account" | "character";
6
22
  }
7
23
 
8
- export interface KumiConfig<Bundle extends string = string> {
9
- build?: {
10
- /** AddOns directory. Relative paths start at the project workspace. */
11
- addonsDir?: string;
12
- imports?: readonly BundleImport<Bundle>[];
13
- };
14
- dev?: {
15
- port?: number;
16
- };
24
+ export interface AddonConfig {
25
+ /** Folder and TOC name: a letter followed by letters, digits, `_` or `-`. */
26
+ readonly name: string;
27
+ /** The title shown in the addon list. */
28
+ readonly title: string;
29
+ readonly notes?: string;
30
+ readonly author?: string;
31
+ readonly version?: string;
32
+ /** A texture inside the addon folder, such as `Assets/Art/Icon.tga`. Plugins reuse it. */
33
+ readonly icon?: string;
34
+ /** Interface numbers per client. `kumi build --target` picks one. Kumi has defaults for both clients. */
35
+ readonly interface?: { readonly retail?: number | readonly number[]; readonly forever?: number | readonly number[] };
36
+ /** Account-wide SavedVariables global. Persisted stores save under their ID here unless they pass a storage. */
37
+ readonly savedVariables?: string;
38
+ /** Per-character SavedVariables global. */
39
+ readonly savedVariablesPerCharacter?: string;
40
+ /** Addons that load before this one when they are installed. */
41
+ readonly optionalDependencies?: readonly string[];
42
+ }
43
+
44
+ export interface PluginConfig {
45
+ /** The plugin's module file under `src`, for example `src/modules/history/history.module.ts`. */
46
+ readonly module: string;
47
+ /** The name of the exported `@Module` class. Needed only when the file exports more than one module. */
48
+ readonly export?: string;
49
+ /** The plugin's name in the addon list and in `usePlugins()`. */
50
+ readonly title: string;
51
+ readonly notes?: string;
52
+ /**
53
+ * `"startup"` (default): WoW loads the plugin with the addon while it is enabled.
54
+ * `"demand"`: the plugin loads the first time the addon calls `load()` for it.
55
+ */
56
+ readonly load?: "startup" | "demand";
57
+ /** Whether the plugin starts enabled on a fresh install. Defaults to `true`. */
58
+ readonly enabled?: boolean;
17
59
  }
package/eslint.mjs ADDED
@@ -0,0 +1,74 @@
1
+ // Kumi's project rules: the layer order inside a feature, public module APIs and the WoW boundary.
2
+ //
3
+ // import ts from "@typescript-eslint/eslint-plugin";
4
+ // import parser from "@typescript-eslint/parser";
5
+ // import { kumiRules } from "<kumi package>/eslint.mjs";
6
+ // export default kumiRules({ parser, plugin: ts });
7
+ import { readFileSync } from "node:fs";
8
+
9
+ const sdkPackage = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).name;
10
+
11
+ const NATIVE_NAMES = ["api", "readableApi", "rawField", "setRawField", "createFrame", "reveal", "isSecret", "savedVariablesStorage"];
12
+ const GAME_GLOBALS = ["_G", "CreateFrame", "UIParent", "GameTooltip", "InCombatLockdown", "GetTime", "GetMoney", "GetCursorInfo",
13
+ "ClearCursor", "C_Container", "C_Item", "C_Spell", "C_SpellBook", "C_ToyBox", "C_AddOns", "C_Timer", "SlashCmdList", "geterrorhandler"];
14
+
15
+ const messages = {
16
+ deep: "Import Kumi through its @kumi/* paths. Deep package imports skip the project's rules.",
17
+ native: "Call WoW in the feature's api/ layer. Other layers use the api functions, services or hooks.",
18
+ module: "Use another feature through its <feature>.module.ts file, its public API.",
19
+ decorators: "Declare modules with @Module and services with @Injectable.",
20
+ shared: "Shared code is reusable: it does not import app or feature code.",
21
+ api: "api/ wraps WoW calls. It takes plain values and returns plain values; it does not import services, stores or UI.",
22
+ services: "services/ hold logic. They use the feature's api/ and never stores or UI.",
23
+ model: "Stores call services, never api/ directly, and do not import UI.",
24
+ ui: "Components read stores and render. Call services and WoW through stores.",
25
+ };
26
+
27
+ const deepImports = { group: [sdkPackage + "/*", "**/node_modules/**"], message: messages.deep };
28
+ const nativeImport = { name: "@kumi/wow", importNames: NATIVE_NAMES, message: messages.native };
29
+ const generated = { name: "@kumi/wow-generated", message: messages.native };
30
+ const legacyModule = { name: "@kumi/core", importNames: ["defineModule"], message: messages.decorators };
31
+ // `../other/model/x` from a module file or `../../other/ui/x` from a layer. `shared/` and the own layers stay allowed.
32
+ const otherFeatureDeep = { regex: "^(?:\\.\\./)+(?!shared/|app/)[^/.][^/]*/(?:api|services|model|ui|widgets)(?:/|$)", message: messages.module };
33
+
34
+ function restrict(patterns, native) {
35
+ const paths = [legacyModule];
36
+ if (!native) paths.push(nativeImport, generated);
37
+ return ["error", { paths, patterns: [deepImports, ...patterns] }];
38
+ }
39
+
40
+ /** Flat ESLint config for a Kumi project. Pass the project's TypeScript ESLint parser and plugin. */
41
+ export function kumiRules({ parser, plugin, files = ["src/**/*.{ts,tsx}"] }) {
42
+ const layer = (folder, patterns, native = false) => ({
43
+ files: ["src/modules/*/" + folder + "/**/*.{ts,tsx}"],
44
+ rules: { "no-restricted-imports": restrict(patterns, native) },
45
+ });
46
+ return [{
47
+ files,
48
+ languageOptions: { parser },
49
+ plugins: { "@typescript-eslint": plugin },
50
+ rules: {
51
+ "no-debugger": "error",
52
+ "no-restricted-globals": ["error", ...GAME_GLOBALS.map(name => ({ name, message: messages.native }))],
53
+ "no-restricted-imports": restrict([otherFeatureDeep], false),
54
+ "no-restricted-syntax": ["error", {
55
+ selector: "CallExpression[callee.type='MemberExpression'][callee.property.name=/^(CreateFrame|CreateTexture|SetTexture|SetAttribute|SetVertexColor|SetPoint|SetScript)$/]",
56
+ message: "Declare frames, textures and scripts in JSX, or use a typed SDK helper.",
57
+ }],
58
+ "@typescript-eslint/consistent-type-imports": "error",
59
+ },
60
+ },
61
+ layer("api", [{ regex: "^(?:\\.\\./)+(?:services|model|ui|widgets)(?:/|$)", message: messages.api }, otherFeatureDeep], true),
62
+ layer("services", [{ regex: "^(?:\\.\\./)+(?:model|ui|widgets)(?:/|$)", message: messages.services }, otherFeatureDeep]),
63
+ layer("model", [{ regex: "^(?:\\.\\./)+(?:api|ui|widgets)(?:/|$)", message: messages.model }, otherFeatureDeep]),
64
+ layer("ui", [{ regex: "^(?:\\.\\./)+(?:api|services|widgets)(?:/|$)", message: messages.ui }, otherFeatureDeep]),
65
+ layer("widgets", [{ regex: "^(?:\\.\\./)+(?:api|services)(?:/|$)", message: messages.ui }, otherFeatureDeep]),
66
+ {
67
+ files: ["src/shared/**/*.{ts,tsx}"],
68
+ rules: { "no-restricted-imports": restrict([{ regex: "^(?:\\.\\./)+(?:app|modules)(?:/|$)", message: messages.shared }], false) },
69
+ },
70
+ {
71
+ files: ["src/shared/api/**/*.{ts,tsx}"],
72
+ rules: { "no-restricted-imports": restrict([{ regex: "^(?:\\.\\./)+(?:app|modules)(?:/|$)", message: messages.shared }], true) },
73
+ }];
74
+ }
package/form/index.ts CHANGED
@@ -41,11 +41,13 @@ export type FormValueFields<State extends object> = {
41
41
  };
42
42
 
43
43
  export type FormValueStore<State extends object> = Pick<StateStore<State>, "field" | "patch">;
44
+ export type FormValueCommit<State extends object> = (this: void, patch: Partial<State>) => Result<void>;
44
45
  export type FormValidationMode = "onChange" | "onBlur" | "onSubmit";
45
46
 
46
47
  export type FormValueOptions<State extends object> =
47
- | { values?: FormValuesSource<State> | FormValueStore<State>; fields?: never }
48
- | { fields: FormValueFields<State>; values?: never };
48
+ | { values?: FormValuesSource<State> | FormValueStore<State>; fields?: never; commit?: never }
49
+ | { values: Readonly<State>; commit: FormValueCommit<State>; fields?: never }
50
+ | { fields: FormValueFields<State>; values?: never; commit?: never };
49
51
 
50
52
  export interface FormBinding<Value, Name extends string = string> {
51
53
  readonly name: Name;
@@ -78,7 +80,7 @@ export function createForm<State extends object>(defaults: State, validate?: For
78
80
  }
79
81
 
80
82
  export function useForm<State extends object>({ defaultValues, validator, validate, protect = direct, mode = "onBlur",
81
- values: source, fields: bindings }: FormOptions<State>) {
83
+ values: source, fields: bindings, commit }: FormOptions<State>) {
82
84
  const initial = Object.fromEntries(Object.entries(defaultValues).filter(([, value]) => value != null)) as State;
83
85
  const issues = ref<readonly FormIssue[]>([]);
84
86
  let validationIssues: readonly FormIssue[] = [];
@@ -101,11 +103,13 @@ export function useForm<State extends object>({ defaultValues, validator, valida
101
103
 
102
104
  const keys = Object.keys(initial) as Key<State>[];
103
105
  const writable = new Set(keys);
104
- const store = source && "patch" in source ? source : undefined;
105
- const adapter = source && "get" in source ? source : undefined;
106
+ const store = commit === undefined && source && "patch" in source ? source : undefined;
107
+ const adapter = commit === undefined && source && "get" in source ? source : undefined;
108
+ const save = commit ?? store?.patch;
106
109
  const linked = source !== undefined || bindings !== undefined;
107
110
 
108
111
  function read<K extends Key<State>>(key: K): State[K] | undefined {
112
+ if (commit !== undefined) return source[key];
109
113
  if (store) return store.field(key).value;
110
114
  return bindings ? bindings[key].get() : adapter?.get(key);
111
115
  }
@@ -226,7 +230,7 @@ export function useForm<State extends object>({ defaultValues, validator, valida
226
230
  return next.length === 0;
227
231
  }
228
232
 
229
- function applyStore(store: FormValueStore<State>, patch: Partial<State>, changed: readonly Key<State>[]) {
233
+ function applyStore(commitValues: FormValueCommit<State>, patch: Partial<State>, changed: readonly Key<State>[]) {
230
234
  if (validateSnapshot) {
231
235
  // Validate the proposed saved values. An unrelated invalid draft stays local.
232
236
  const candidate = { ...initial, ...patch };
@@ -245,7 +249,7 @@ export function useForm<State extends object>({ defaultValues, validator, valida
245
249
  return fail(errors[0].message);
246
250
  }
247
251
  }
248
- const saved = store.patch(patch);
252
+ const saved = commitValues(patch);
249
253
  if (!saved.ok) {
250
254
  for (const key of changed) {
251
255
  field(key);
@@ -270,7 +274,7 @@ export function useForm<State extends object>({ defaultValues, validator, valida
270
274
  if (existing) return existing.field as FormField<State[K]>;
271
275
  const current = () => readCurrent(key);
272
276
  const cached = ref<State[K]>(current());
273
- const draft = store ? ref<State[K] | undefined>(undefined) : undefined;
277
+ const draft = save ? ref<State[K] | undefined>(undefined) : undefined;
274
278
  const value = linked ? new LinkedField(cached, () => {
275
279
  const edited = draft?.value;
276
280
  if (edited != null) return edited;
@@ -349,7 +353,7 @@ export function useForm<State extends object>({ defaultValues, validator, valida
349
353
  }
350
354
 
351
355
  function applyValues(patch: Partial<State>, changed: readonly Key<State>[]): Result<void> {
352
- if (store) return applyStore(store, patch, changed);
356
+ if (save) return applyStore(save, patch, changed);
353
357
  if (linked && changed.length > 1) return fail("Atomic edits require a reactive form store");
354
358
  for (const key of changed) {
355
359
  field(key);
@@ -414,8 +418,8 @@ export function useForm<State extends object>({ defaultValues, validator, valida
414
418
  }
415
419
 
416
420
  function reset(): Result<void> {
417
- if (store) {
418
- const saved = applyStore(store, initial, keys);
421
+ if (save) {
422
+ const saved = applyStore(save, initial, keys);
419
423
  if (!saved.ok) return saved;
420
424
  for (const state of fields.values()) state.clear();
421
425
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overmvp/kumi",
3
- "version": "0.1.0",
3
+ "version": "0.4.0",
4
4
  "description": "TypeScript and TSX framework with a native Lua 5.1 compiler for World of Warcraft Retail addons",
5
5
  "license": "MIT",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/OverMVP/kumi.git" },
@@ -8,17 +8,21 @@
8
8
  "engines": { "node": ">=24" },
9
9
  "bin": { "kumi": "scripts/kumi-cli.mjs" },
10
10
  "files": [
11
- "animation", "builder", "config.ts", "form", "motion", "router", "src", "state", "styles", "translate", "utils", "validate", "wow",
12
- "scripts/kumi-cli.mjs", "scripts/link-addons.mjs", "templates/addon"
11
+ "animation", "builder", "config.ts", "eslint.mjs", "form", "motion", "router", "src", "state", "styles", "translate", "utils", "validate", "wow",
12
+ "scripts/kumi-cli.mjs", "scripts/addon-project.mjs", "scripts/addon-build.mjs", "scripts/link-addons.mjs", "templates/addon"
13
13
  ],
14
14
  "publishConfig": { "access": "public" },
15
15
  "scripts": {
16
- "check": "tsc -p tsconfig.json && node scripts/check-parity.mjs",
16
+ "check": "tsc -p tsconfig.json",
17
17
  "check:starter": "node scripts/check-starter.mjs",
18
- "test:lua": "node scripts/lua-tests.mjs"
18
+ "test:lua": "node scripts/lua-tests.mjs",
19
+ "test:unit": "node --import ./tests/support/ts-resolve.mjs --test builder/*.test.mjs tests/*.test.mjs scripts/*.test.mjs"
20
+ },
21
+ "dependencies": {
22
+ "postcss": "8.5.6",
23
+ "sass": "1.108.2"
19
24
  },
20
25
  "devDependencies": {
21
- "typescript": "6.0.2",
22
- "typescript-to-lua": "1.37.1"
26
+ "typescript": "6.0.2"
23
27
  }
24
28
  }
package/router/index.ts CHANGED
@@ -1,12 +1,16 @@
1
1
  import type { UIElement } from "../src/elements";
2
2
  import { fail, ok } from "@kumi/core";
3
- import { ownedMap } from "../src/owned-collections";
3
+ import { ownedArray, ownedMap } from "../src/owned-collections";
4
4
  import { collectRoutes, renderRoute, type RouteLayoutProps } from "./routes";
5
5
 
6
6
  export type { RouteContext, RouteLayoutProps } from "./routes";
7
+ export { useNavigation, withNavigation, type Navigation } from "./navigation";
8
+ export { Link, type LinkProps } from "./link";
9
+ export { RouterView, onActivated, onDeactivated, withRouterHost, type RoutePage, type RouterHost } from "./router-view";
7
10
 
8
11
  type PageFactory<Context> = (this: void, context: Context) => UIElement;
9
- type PageModule = { default: PageFactory<never> | { render: PageFactory<never> } };
12
+ /** A page file: its default export renders the page. `title` and `order` describe its tab. */
13
+ type PageModule = { default: PageFactory<never> | { render: PageFactory<never> }; title?: string; order?: number };
10
14
  type ContextReader<Definition> = Definition extends PageFactory<infer Context> ? PageFactory<Context>
11
15
  : Definition extends { render: PageFactory<infer Context> } ? PageFactory<Context> : never;
12
16
  type PageContext<Page extends PageModule> = ContextReader<Page["default"]> extends PageFactory<infer Context> ? Context : never;
@@ -20,16 +24,20 @@ export function createRouter<Page extends PageModule, Path extends string = stri
20
24
  const registry = collectRoutes(files);
21
25
  if (!registry.ok) return registry;
22
26
  const routes = ownedMap<Path, NonNullable<ReturnType<typeof registry.value.get>>>();
27
+ const pages = ownedArray<{ readonly path: Path; readonly title?: string; readonly order?: number }>();
23
28
  const paths = files.paths ?? Array.from(registry.value.keys()) as Path[];
24
29
  for (const path of paths) {
25
30
  const route = registry.value.get(path);
26
31
  if (!route || routes.has(path)) return fail(`Invalid generated route: ${path}`);
27
32
  routes.set(path, route);
33
+ pages.push({ path, title: route.page.title, order: route.page.order });
28
34
  }
29
35
  if (routes.size !== registry.value.size) return fail("Generated routes are missing paths");
30
36
 
31
37
  return ok({
32
38
  entries: () => routes.entries(),
39
+ /** The file routes with the `title` and `order` their page files export. */
40
+ pages,
33
41
  match: (path: string) => routes.get(path as Path),
34
42
  has: (path: string): path is Path => routes.has(path as Path),
35
43
  render(this: void, path: Path, context: PageContext<Page>) {
@@ -0,0 +1,32 @@
1
+ import { createElement, type Binding, type UIElement, type UINode } from "../src/elements";
2
+ import { jsxMap } from "../src/keyed-list";
3
+ import { computed } from "../src/reactive-scope";
4
+ import type { ClassNames } from "../src/style-classes";
5
+ import { useNavigation } from "./navigation";
6
+
7
+ export interface LinkProps {
8
+ readonly to: string;
9
+ readonly className?: ClassNames | ((this: void, isActive: boolean) => ClassNames | undefined);
10
+ readonly ariaLabel?: string;
11
+ readonly disabled?: Binding<boolean>;
12
+ readonly children?: UINode;
13
+ }
14
+
15
+ /** A route button whose checked state follows the window's active page. */
16
+ export function Link(this: void, { to, className, ariaLabel, disabled, children }: LinkProps): UIElement {
17
+ const context = useNavigation();
18
+ if (!context.ok) throw new Error("<Link> requires a router context");
19
+ const { path, navigate } = context.value;
20
+ const active = () => path.value === to;
21
+ const checked = computed(active);
22
+ const open = () => navigate(to);
23
+
24
+ function render(style?: ClassNames) {
25
+ return <button unstyled directKeyedLayout ariaLabel={ariaLabel} className={style}
26
+ checked={checked} disabled={disabled} onClick={open}>{children}</button>;
27
+ }
28
+
29
+ if (typeof className !== "function") return render(className);
30
+ const selectClass = className;
31
+ return jsxMap(() => [active()], () => 0, isActive => render(selectClass(isActive)));
32
+ }
@@ -0,0 +1,22 @@
1
+ import { createContext } from "../src/context";
2
+ import type { ReadonlyRef } from "../src/reactivity";
3
+ import { fail, ok, type Protect, type Result } from "../src/result";
4
+
5
+ export interface Navigation<Path extends string = string> {
6
+ readonly path: ReadonlyRef<Path | undefined>;
7
+ navigate(this: void, path: Path): void;
8
+ }
9
+
10
+ const context = createContext<unknown>();
11
+ const missingNavigation = fail("Navigation requires a router context");
12
+
13
+ /** Run view setup with the navigation state of its host. */
14
+ export function withNavigation<Path extends string, View>(this: void, navigation: Navigation<Path>,
15
+ render: (this: void) => View, protect: Protect): Result<View> {
16
+ return context.run(navigation, render, protect);
17
+ }
18
+
19
+ export function useNavigation<Path extends string = string>(this: void): Result<Navigation<Path>> {
20
+ const navigation = context.use();
21
+ return navigation === undefined ? missingNavigation : ok(navigation as Navigation<Path>);
22
+ }