@overmvp/kumi 0.3.0 → 0.5.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 (89) hide show
  1. package/animation/index.ts +4 -0
  2. package/animation/motion-policy.ts +20 -0
  3. package/animation/slide.ts +61 -0
  4. package/animation/spring.ts +75 -0
  5. package/animation/staggered-reveal.ts +34 -0
  6. package/builder/css-gradients.mjs +74 -0
  7. package/builder/css-mask-assets.mjs +52 -0
  8. package/builder/css-mask-assets.test.mjs +31 -0
  9. package/builder/css-v1.mjs +73 -22
  10. package/builder/css-v1.test.mjs +42 -2
  11. package/builder/module-declarations.mjs +2 -2
  12. package/builder/module-declarations.test.mjs +4 -2
  13. package/builder/src/compiler.rs +25 -0
  14. package/builder/src/lua_upvalues.rs +641 -0
  15. package/builder/src/main.rs +1 -0
  16. package/builder/style-modules.mjs +21 -3
  17. package/builder/style-modules.test.mjs +24 -0
  18. package/builder/style-states.mjs +6 -4
  19. package/package.json +1 -1
  20. package/router/index.ts +1 -0
  21. package/router/link.tsx +32 -0
  22. package/router/router-view.ts +5 -3
  23. package/scripts/addon-build.mjs +17 -2
  24. package/scripts/addon-project.mjs +22 -11
  25. package/scripts/kumi-cli.mjs +0 -0
  26. package/src/bindings.ts +10 -4
  27. package/src/context.ts +31 -7
  28. package/src/css-tokens.ts +11 -2
  29. package/src/css-v1.ts +3 -0
  30. package/src/elements.ts +20 -1
  31. package/src/flex-layout.ts +26 -5
  32. package/src/frame-scheduler.ts +3 -1
  33. package/src/index.ts +2 -2
  34. package/src/keyed-list.ts +9 -6
  35. package/src/module-ui.ts +22 -2
  36. package/src/module.ts +26 -7
  37. package/src/reactivity.ts +14 -1
  38. package/src/style-classes.ts +22 -1
  39. package/src/style-states.ts +13 -6
  40. package/state/setup-store.ts +3 -3
  41. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +1 -1
  42. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +1 -1
  43. package/templates/addon/AGENTS.md +1 -1
  44. package/templates/addon/kumi.config.ts +17 -17
  45. package/templates/addon/src/app/app.module.ts +3 -5
  46. package/templates/addon/src/app/layout/{AppWindow.module.scss → AppWindow.module.css} +10 -12
  47. package/templates/addon/src/modules/greeting/greeting.module.ts +2 -2
  48. package/templates/addon/src/modules/greeting/ui/{Greeting.module.scss → Greeting.module.css} +9 -11
  49. package/templates/addon/src/modules/playtime/playtime.module.ts +3 -5
  50. package/templates/addon/src/modules/playtime/ui/{Playtime.module.scss → Playtime.module.css} +3 -5
  51. package/templates/addon/src/shared/styles/tokens.css +13 -0
  52. package/templates/addon/src/shared/ui/{Controls.module.scss → Controls.module.css} +18 -20
  53. package/utils/format.ts +13 -0
  54. package/utils/index.ts +1 -1
  55. package/wow/action-button.ts +26 -1
  56. package/wow/addon-manifest.ts +2 -0
  57. package/wow/animation.ts +19 -18
  58. package/wow/app-ui.ts +150 -31
  59. package/wow/aura-container.ts +132 -38
  60. package/wow/aura-countdown.ts +19 -3
  61. package/wow/aura-follower.ts +32 -0
  62. package/wow/aura-view.ts +49 -0
  63. package/wow/css-background-image.ts +75 -0
  64. package/wow/css-box.ts +14 -9
  65. package/wow/css-image-mask.ts +32 -0
  66. package/wow/css-surfaces.ts +88 -35
  67. package/wow/element-events.ts +33 -13
  68. package/wow/frames.ts +2 -0
  69. package/wow/heal-prediction.ts +2 -4
  70. package/wow/hooks.ts +17 -0
  71. package/wow/hotkeys.ts +221 -0
  72. package/wow/index.ts +11 -6
  73. package/wow/initial-view.ts +99 -0
  74. package/wow/layout-view.ts +19 -10
  75. package/wow/module-replacements.ts +103 -0
  76. package/wow/native.ts +1 -0
  77. package/wow/pixel.ts +25 -0
  78. package/wow/pointer-click.ts +35 -0
  79. package/wow/protected-view.ts +49 -13
  80. package/wow/rounded-texture.ts +9 -4
  81. package/wow/scroll-view.ts +5 -4
  82. package/wow/state-paint.ts +5 -14
  83. package/wow/status-bar.ts +65 -0
  84. package/wow/texture-fill.ts +10 -0
  85. package/wow/unit-button.ts +25 -4
  86. package/wow/unit-cast.ts +6 -4
  87. package/wow/view-nodes.ts +11 -4
  88. package/wow/view.ts +387 -278
  89. package/templates/addon/src/shared/styles/_tokens.scss +0 -12
@@ -29,7 +29,25 @@ export function readStyleBreakpoints(root) {
29
29
  return widths;
30
30
  }
31
31
 
32
- export function compileLocalStyleModule(root, breakpoints) {
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) {
33
51
  const classes = Object.create(null);
34
52
  const rules = new Map();
35
53
  const states = new Map();
@@ -52,7 +70,7 @@ export function compileLocalStyleModule(root, breakpoints) {
52
70
  if (when.length !== 0) throw node.error("Media queries require a plain local class");
53
71
  assertMediaProperties(contents);
54
72
  if (!media.has(name)) media.set(name, []);
55
- media.get(name).push({ when: query, style: compileCssDeclarations(contents) });
73
+ media.get(name).push({ when: query, style: compileCssDeclarations(contents, { tokens }) });
56
74
  continue;
57
75
  }
58
76
 
@@ -80,7 +98,7 @@ export function compileLocalStyleModule(root, breakpoints) {
80
98
  }
81
99
 
82
100
  for (const { name, when, contents } of rules.values()) {
83
- const style = compileCssDeclarations([...contents.values()], { state: when.length !== 0 });
101
+ const style = compileCssDeclarations([...contents.values()], { tokens, state: when.length !== 0 });
84
102
  if (when.length === 0) Object.assign(classFor(name), style);
85
103
  else {
86
104
  if (!states.has(name)) states.set(name, []);
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overmvp/kumi",
3
- "version": "0.3.0",
3
+ "version": "0.5.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" },
package/router/index.ts CHANGED
@@ -5,6 +5,7 @@ import { collectRoutes, renderRoute, type RouteLayoutProps } from "./routes";
5
5
 
6
6
  export type { RouteContext, RouteLayoutProps } from "./routes";
7
7
  export { useNavigation, withNavigation, type Navigation } from "./navigation";
8
+ export { Link, type LinkProps } from "./link";
8
9
  export { RouterView, onActivated, onDeactivated, withRouterHost, type RoutePage, type RouterHost } from "./router-view";
9
10
 
10
11
  type PageFactory<Context> = (this: void, context: Context) => UIElement;
@@ -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
+ }
@@ -1,8 +1,8 @@
1
1
  import { createContext } from "../src/context";
2
- import { createElement, type UIElement } from "../src/elements";
2
+ import { createElement, type Element, type UIElement } from "../src/elements";
3
3
  import { jsxMap } from "../src/keyed-list";
4
4
  import type { ModulePage } from "../src/module-ui";
5
- import { ownedArray, type OwnedArray, type OwnedReadonlyArray } from "../src/owned-collections";
5
+ import { ownedArray, type OwnedArray, type OwnedReadonlyArray, type OwnedRecord } from "../src/owned-collections";
6
6
  import { computed, currentScope, withReactiveScope } from "../src/reactive-scope";
7
7
  import { ref, type ReadonlyRef } from "../src/reactivity";
8
8
  import { fail, formatFailure, ok, type Protect, type Result } from "../src/result";
@@ -127,8 +127,10 @@ export function RouterView(this: void, props: { readonly className?: ClassNames
127
127
  if (!watched.ok) throw new Error(watched.reason);
128
128
  owner.onDispose(() => { activity?.dispose(); });
129
129
 
130
- return jsxMap(() => visits.value, entry => entry.path, entry => createElement("div", {
130
+ const view = jsxMap(() => visits.value, entry => entry.path, entry => createElement("div", {
131
131
  className: props.className,
132
132
  shown: computed(() => host.navigation.path.value === entry.path),
133
133
  }, entry.content));
134
+ // A cold window has one initial visit. Its native subtree can stage with the hidden window.
135
+ return { ...view as OwnedRecord<Element<"keyedList">>, props: { mount: view.props.mount, stageFirstRow: true } };
134
136
  }
@@ -1,7 +1,7 @@
1
1
  // Build a Kumi addon and its plugins from kumi.config.ts.
2
- import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync } from "node:fs";
2
+ import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { createRequire } from "node:module";
4
- import { isAbsolute, join, relative, resolve } from "node:path";
4
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
6
6
  import { linkAddonPackage } from "../builder/link-addon-package.mjs";
7
7
  import { writeGeneratedText } from "../builder/generated-output.mjs";
@@ -15,6 +15,8 @@ const MANIFEST = "KumiAddon.lua";
15
15
  const SHARED = "KumiShared.lua";
16
16
  const LINK_STAMP = "kumi-cli-link";
17
17
  const quote = JSON.stringify;
18
+ const luaString = text => '"' + text.replace(/["\\\x00-\x1f\x7f]/gu, char =>
19
+ char === '"' || char === "\\" ? "\\" + char : "\\" + String(char.charCodeAt(0)).padStart(3, "0")) + '"';
18
20
 
19
21
  function inside(base, path) {
20
22
  const child = relative(base, path);
@@ -182,6 +184,11 @@ export function manifestLua(project) {
182
184
  const plugins = project.plugins.map(plugin => " { id = " + quote(plugin.id) + ", addon = " + quote(plugin.addon)
183
185
  + ", title = " + quote(plugin.title) + ", notes = " + quote(plugin.notes ?? "") + ", load = " + quote(plugin.load) + " },");
184
186
  const optional = (field, value) => value === undefined ? [] : [" " + field + " = " + quote(value) + ","];
187
+ const variables = project.styleVariables?.size ? [
188
+ " styleVariables = {",
189
+ ...Array.from(project.styleVariables, ([name, value]) => ` [${luaString(name)}] = ${luaString(value)},`),
190
+ " },",
191
+ ] : [];
185
192
  return [
186
193
  "-- Generated by kumi build.",
187
194
  "local name, owner = ...",
@@ -194,6 +201,7 @@ export function manifestLua(project) {
194
201
  " name = name,",
195
202
  ...optional("savedVariables", project.addon.savedVariables),
196
203
  ...optional("savedVariablesPerCharacter", project.addon.savedVariablesPerCharacter),
204
+ ...variables,
197
205
  " pluginState = " + quote(project.pluginState) + ",",
198
206
  " plugins = plugins,",
199
207
  " registered = {},",
@@ -343,6 +351,13 @@ export async function buildProject(workspace, project, interfaceVersion, pack) {
343
351
  }
344
352
  const assets = join(workspace, "Assets");
345
353
  if (existsSync(assets)) cpSync(assets, join(main, "Assets"), { recursive: true });
354
+ const bindings = join(workspace, "Bindings.xml");
355
+ if (existsSync(bindings)) cpSync(bindings, join(main, "Bindings.xml"));
356
+ for (const [path, data] of project.styleMaskAssets ?? []) {
357
+ const destination = join(main, path);
358
+ mkdirSync(dirname(destination), { recursive: true });
359
+ writeFileSync(destination, data);
360
+ }
346
361
 
347
362
  // Replace whole folders so files from an older build cannot linger, then drop folders of removed plugins.
348
363
  const folders = [project.name, ...project.plugins.map(plugin => plugin.addon)];
@@ -4,11 +4,13 @@ import { dirname, join, relative } from "node:path";
4
4
  import { parseArgs } from "node:util";
5
5
  import postcss from "postcss";
6
6
  import { compile } from "sass";
7
- import { compileLocalStyleModule, readStyleBreakpoints } from "../builder/style-modules.mjs";
7
+ import { prepareCssMaskImages } from "../builder/css-mask-assets.mjs";
8
+ import { compileLocalStyleModule, readStyleBreakpoints, readStyleTokens } from "../builder/style-modules.mjs";
8
9
  import { buildProject, interfaceFor, readProject, writePluginSources } from "./addon-build.mjs";
9
10
 
10
11
  function readCss(file) {
11
- return postcss.parse(compile(file).css, { from: file });
12
+ const css = file.endsWith(".scss") ? compile(file).css : readFileSync(file, "utf8");
13
+ return postcss.parse(css, { from: file });
12
14
  }
13
15
 
14
16
  function writeGenerated(file, text) {
@@ -17,9 +19,11 @@ function writeGenerated(file, text) {
17
19
  writeFileSync(file, text);
18
20
  }
19
21
 
20
- function prepareStyles(workspace) {
22
+ function prepareStyles(workspace, addonName) {
21
23
  const source = join(workspace, "src");
22
24
  const styles = join(workspace, "build", "styles");
25
+ const tokensSource = join(source, "shared", "styles", "tokens.css");
26
+ const tokens = existsSync(tokensSource) ? readStyleTokens(readCss(tokensSource)) : new Map();
23
27
  const breakpointsSource = join(source, "shared", "styles", "breakpoints.tokens.scss");
24
28
  const breakpoints = existsSync(breakpointsSource)
25
29
  ? readStyleBreakpoints(readCss(breakpointsSource))
@@ -28,21 +32,28 @@ function prepareStyles(workspace) {
28
32
  writeGenerated(join(styles, "shared", "styles", "breakpoints.ts"),
29
33
  "export default " + JSON.stringify(breakpointValues) + " as const;\n");
30
34
 
35
+ const styleOutputs = new Map();
36
+ const styleMaskAssets = new Map();
31
37
  for (const entry of readdirSync(source, { recursive: true, withFileTypes: true })) {
32
- if (!entry.isFile() || !entry.name.endsWith(".module.scss")) continue;
38
+ if (!entry.isFile() || !/\.module\.(css|scss)$/u.test(entry.name)) continue;
33
39
  const path = join(entry.parentPath, entry.name);
34
- const classes = compileLocalStyleModule(readCss(path), breakpoints);
35
- const output = relative(source, path).replace(/\.module\.scss$/u, ".ts");
40
+ const output = relative(source, path).replace(/\.module\.(css|scss)$/u, ".ts");
41
+ if (styleOutputs.has(output)) throw new Error(`Style modules ${styleOutputs.get(output)} and ${path} have the same import name`);
42
+ styleOutputs.set(output, path);
43
+ const classes = compileLocalStyleModule(readCss(path), breakpoints, tokens);
44
+ prepareCssMaskImages(classes, addonName, styleMaskAssets);
36
45
  writeGenerated(join(styles, output),
37
46
  'import type { StyleClass } from "@kumi/core";\n' +
38
47
  "export default " + JSON.stringify(classes, null, 2) + " satisfies Record<string, StyleClass>;\n");
39
48
  }
49
+ return { styleVariables: tokens, styleMaskAssets };
40
50
  }
41
51
 
42
- function prepareProject(workspace, pack) {
43
- prepareStyles(workspace);
52
+ function prepareProject(workspace, project, pack) {
53
+ const styles = prepareStyles(workspace, project.name);
44
54
  if (!existsSync(join(workspace, "build", "types", "wow-api.d.ts"))) pack(["wow-api"]);
45
55
  if (existsSync(join(workspace, "src", "app", "routes"))) pack(["routes"]);
56
+ return styles;
46
57
  }
47
58
 
48
59
  function projectTool(workspace, packageName, command) {
@@ -57,7 +68,7 @@ function projectTool(workspace, packageName, command) {
57
68
  export async function checkAddon(workspace, args, pack, run) {
58
69
  const { values } = parseArgs({ args, options: { "types-only": { type: "boolean" } } });
59
70
  const project = await readProject(workspace);
60
- prepareProject(workspace, pack);
71
+ prepareProject(workspace, project, pack);
61
72
  await writePluginSources(workspace, project);
62
73
  run(process.execPath, ["--v8-pool-size=1", projectTool(workspace, "typescript", "tsc"), "-p", "tsconfig.json"]);
63
74
  if (!values["types-only"]) {
@@ -73,6 +84,6 @@ export async function buildAddon(workspace, args, pack) {
73
84
  throw new Error("Expected a positive interface number after --toc");
74
85
  }
75
86
  const project = await readProject(workspace);
76
- prepareProject(workspace, pack);
77
- await buildProject(workspace, project, interfaceFor(project, target, values.toc), pack);
87
+ const styles = prepareProject(workspace, project, pack);
88
+ await buildProject(workspace, { ...project, ...styles }, interfaceFor(project, target, values.toc), pack);
78
89
  }
File without changes
package/src/bindings.ts CHANGED
@@ -1,19 +1,23 @@
1
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
8
  type BoundValue = string | boolean | number | ActionSlot | Anchor | CooldownValue | ImageVerticalGradient | undefined;
9
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
+ }
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;
@@ -162,7 +163,10 @@ function decode(raw: string, recipe: CssTokenRecipe): unknown {
162
163
  const columns = parseGridSpan(text);
163
164
  return columns === undefined ? undefined : `span ${columns}`;
164
165
  }
165
- 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
+ }
166
170
  const length = kind === "length" || kind === "signedLength" || kind === "positiveLength" || kind === "size" || kind === "radius";
167
171
  const number = kind === "fontWeight" && add === undefined && (text === "normal" || text === "bold")
168
172
  ? text === "normal" ? 400 : 700 : length ? pixels(text) : decimal(text);
@@ -206,6 +210,11 @@ export function resolveCssTokens<Style extends WithRecipes>(this: void, base: St
206
210
  token = authored.value ?? false;
207
211
  sourced[recipe.token] = token;
208
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
+ }
209
218
  if (token === false || token === recipe.source) continue;
210
219
  const parsed = decode(token, recipe);
211
220
  const path = recipe.path as OwnedReadonlyArray<Field>;
package/src/css-v1.ts CHANGED
@@ -35,6 +35,8 @@ export interface CssTokenRecipe {
35
35
  readonly fallback: unknown;
36
36
  /** @internal Exact compiler-validated token text whose decoded value is `fallback`. */
37
37
  readonly source?: string;
38
+ /** @internal Optional CSS fallback evaluated when the named variable is missing. */
39
+ readonly fallbackExpression?: string;
38
40
  readonly add?: number;
39
41
  readonly part?: string | number;
40
42
  readonly values?: readonly (string | number)[];
@@ -55,6 +57,7 @@ export interface CssV1Style {
55
57
  borderPaint?: CssBorderPaintPlan;
56
58
  borderRadius?: number;
57
59
  backgroundImage?: StatePaint["backgroundImage"];
60
+ maskImage?: Readonly<{ path: string }>;
58
61
  fontWeight?: CssFontWeight;
59
62
  textAlign?: CssTextAlign;
60
63
  textShadow?: CssTextShadow;
package/src/elements.ts CHANGED
@@ -154,8 +154,12 @@ type ElementLayout<Kind extends MountedElementKind> = NativeLayout & { nodeRef?:
154
154
  interface NativeProps {
155
155
  frame: ElementLayout<"frame"> & ElementEvents & {
156
156
  ref?: ElementRef<"frame">;
157
+ /** Allow the frame to run snippets installed with secureStateSnippet. */
158
+ secureStateHandler?: true;
157
159
  /** The native frame's own scale in parent coordinates. */
158
160
  nativeScale?: Binding<number>;
161
+ /** Let a render-only frame anchor to a native aura container without observing its geometry. */
162
+ nativeAuraFollower?: true;
159
163
  /** Lay out this keyed frame directly in its parent CSS container. */
160
164
  directKeyedLayout?: true;
161
165
  /** Decorative artwork for WoW, reconciled as a single layer without child frames. */
@@ -183,6 +187,9 @@ interface NativeProps {
183
187
  };
184
188
  cooldown: NativeLayout & {
185
189
  value: Binding<CooldownValue | undefined>;
190
+ /** Custom texture for the swipe. With this option the swipe is the sole timer visual. */
191
+ swipeTexture?: string;
192
+ reverse?: boolean;
186
193
  };
187
194
  scrollview: ElementLayout<"scrollview"> & {
188
195
  contentHeight: Binding<number>;
@@ -209,6 +216,8 @@ interface NativeProps {
209
216
  max: Binding<StatusBarValue>;
210
217
  value: Binding<StatusBarValue>;
211
218
  smooth?: boolean;
219
+ /** Change the key when a new source owns the bar or an opaque range changes. */
220
+ resetKey?: Binding<number>;
212
221
  ref?: ElementRef<"statusbar">;
213
222
  };
214
223
  button: ElementLayout<"button"> & ElementEvents & {
@@ -220,7 +229,15 @@ interface NativeProps {
220
229
  disabled?: Binding<boolean>;
221
230
  checked?: Binding<boolean>;
222
231
  ref?: ElementRef<"button">;
232
+ /** Maximum pointer hold in seconds for onClick. Pointer drags also suppress onClick. */
233
+ clickMaxDuration?: number;
223
234
  secureAction?: Binding<ActionSlot | undefined>;
235
+ /** Macro text run by a hardware click. Use this in place of `secureAction`. */
236
+ secureMacro?: Binding<string | undefined>;
237
+ /** Select this unit on a left click. The client tracks unit visibility through combat. */
238
+ secureUnit?: string;
239
+ /** Open the client's unit menu from a secure right click. Requires secureUnit. */
240
+ secureUnitMenu?: true;
224
241
  /** An anchored secure button keeps its identity and mounts paint and children on its first show. */
225
242
  deferContentUntilShown?: true;
226
243
  /** Lay out this keyed button directly in its parent CSS container. */
@@ -269,6 +286,8 @@ interface NativeProps {
269
286
  onChange?(this: void, value: number): void;
270
287
  /** Runs after a pointer adjustment that changed the value. */
271
288
  onCommit?(this: void): void;
289
+ /** Discard an unfinished adjustment when the range control hides or becomes disabled. */
290
+ onCancel?(this: void): void;
272
291
  };
273
292
  listbox: ElementLayout<"listbox"> & {
274
293
  value: Binding<string>;
@@ -319,7 +338,7 @@ export interface CustomElements {}
319
338
 
320
339
  interface BuiltInProps extends NativeProps {
321
340
  fragment: Record<never, never>;
322
- keyedList: { mount: MountKeyedList };
341
+ keyedList: { mount: MountKeyedList; stageFirstRow?: true };
323
342
  transition: TransitionOptions;
324
343
  portal: { target?: KumiNode<"frame"> };
325
344
  selectItem: { value: string; label: 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;
@@ -332,5 +334,5 @@ export function createFrameScheduler(
332
334
  wake();
333
335
  }
334
336
 
335
- 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 };
336
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,7 +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
+ export { Extensions, modulePages, type ExtensionComponent, type ModulePage, type ModuleReplacement, type ModuleUi, type ModuleView, type ModuleWindow, type ViewComponent } from "./module-ui";
15
15
  export { provide, serviceToken, type ResolveProviderInput, type ServiceProvider, type ServiceToken } from "./providers";
16
16
  export * from "./images";
17
17
  export * from "./keyed-list";