@overmvp/kumi 0.3.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.
- package/animation/index.ts +4 -0
- package/animation/motion-policy.ts +20 -0
- package/animation/slide.ts +61 -0
- package/animation/spring.ts +75 -0
- package/animation/staggered-reveal.ts +34 -0
- package/builder/css-gradients.mjs +74 -0
- package/builder/css-mask-assets.mjs +52 -0
- package/builder/css-mask-assets.test.mjs +31 -0
- package/builder/css-v1.mjs +73 -22
- package/builder/css-v1.test.mjs +42 -2
- package/builder/src/compiler.rs +25 -0
- package/builder/src/lua_upvalues.rs +641 -0
- package/builder/src/main.rs +1 -0
- package/builder/style-modules.mjs +21 -3
- package/builder/style-modules.test.mjs +24 -0
- package/builder/style-states.mjs +6 -4
- package/package.json +1 -1
- package/router/index.ts +1 -0
- package/router/link.tsx +32 -0
- package/scripts/addon-build.mjs +15 -2
- package/scripts/addon-project.mjs +22 -11
- package/src/bindings.ts +10 -4
- package/src/context.ts +31 -7
- package/src/css-tokens.ts +11 -2
- package/src/css-v1.ts +3 -0
- package/src/elements.ts +9 -0
- package/src/flex-layout.ts +26 -5
- package/src/frame-scheduler.ts +3 -1
- package/src/index.ts +2 -2
- package/src/keyed-list.ts +9 -6
- package/src/module-ui.ts +18 -2
- package/src/module.ts +12 -3
- package/src/reactivity.ts +14 -1
- package/src/style-classes.ts +22 -1
- package/src/style-states.ts +13 -6
- package/state/setup-store.ts +3 -3
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +1 -1
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +1 -1
- package/templates/addon/AGENTS.md +1 -1
- package/templates/addon/kumi.config.ts +17 -17
- package/templates/addon/src/app/layout/{AppWindow.module.scss → AppWindow.module.css} +10 -12
- package/templates/addon/src/modules/greeting/ui/{Greeting.module.scss → Greeting.module.css} +9 -11
- package/templates/addon/src/modules/playtime/ui/{Playtime.module.scss → Playtime.module.css} +3 -5
- package/templates/addon/src/shared/styles/tokens.css +13 -0
- package/templates/addon/src/shared/ui/{Controls.module.scss → Controls.module.css} +18 -20
- package/wow/action-button.ts +26 -1
- package/wow/addon-manifest.ts +2 -0
- package/wow/animation.ts +3 -14
- package/wow/app-ui.ts +19 -10
- package/wow/css-background-image.ts +75 -0
- package/wow/css-box.ts +7 -5
- package/wow/css-image-mask.ts +32 -0
- package/wow/css-surfaces.ts +78 -31
- package/wow/element-events.ts +33 -13
- package/wow/heal-prediction.ts +2 -4
- package/wow/index.ts +2 -1
- package/wow/layout-view.ts +18 -9
- package/wow/module-replacements.ts +103 -0
- package/wow/pointer-click.ts +35 -0
- package/wow/protected-view.ts +49 -13
- package/wow/rounded-texture.ts +9 -4
- package/wow/state-paint.ts +5 -14
- package/wow/texture-fill.ts +10 -0
- package/wow/unit-cast.ts +6 -4
- package/wow/view.ts +287 -175
- 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
|
|
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
|
+
});
|
package/builder/style-states.mjs
CHANGED
|
@@ -22,16 +22,18 @@ export function parseLocalStyleSelector(selector) {
|
|
|
22
22
|
return { name: match[1], when };
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function
|
|
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
|
+
"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" },
|
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;
|
package/router/link.tsx
ADDED
|
@@ -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
|
+
}
|
package/scripts/addon-build.mjs
CHANGED
|
@@ -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,11 @@ 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
|
+
for (const [path, data] of project.styleMaskAssets ?? []) {
|
|
355
|
+
const destination = join(main, path);
|
|
356
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
357
|
+
writeFileSync(destination, data);
|
|
358
|
+
}
|
|
346
359
|
|
|
347
360
|
// Replace whole folders so files from an older build cannot linger, then drop folders of removed plugins.
|
|
348
361
|
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 {
|
|
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
|
-
|
|
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() ||
|
|
38
|
+
if (!entry.isFile() || !/\.module\.(css|scss)$/u.test(entry.name)) continue;
|
|
33
39
|
const path = join(entry.parentPath, entry.name);
|
|
34
|
-
const
|
|
35
|
-
|
|
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
|
}
|
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
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
const key = {};
|
|
5
27
|
|
|
6
28
|
function run<Output>(value: Value, render: (this: void) => Output, protect: Protect) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
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
|
|
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" &&
|
|
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,6 +154,8 @@ 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>;
|
|
159
161
|
/** Lay out this keyed frame directly in its parent CSS container. */
|
|
@@ -183,6 +185,9 @@ interface NativeProps {
|
|
|
183
185
|
};
|
|
184
186
|
cooldown: NativeLayout & {
|
|
185
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;
|
|
186
191
|
};
|
|
187
192
|
scrollview: ElementLayout<"scrollview"> & {
|
|
188
193
|
contentHeight: Binding<number>;
|
|
@@ -220,7 +225,11 @@ interface NativeProps {
|
|
|
220
225
|
disabled?: Binding<boolean>;
|
|
221
226
|
checked?: Binding<boolean>;
|
|
222
227
|
ref?: ElementRef<"button">;
|
|
228
|
+
/** Maximum pointer hold in seconds for onClick. Pointer drags also suppress onClick. */
|
|
229
|
+
clickMaxDuration?: number;
|
|
223
230
|
secureAction?: Binding<ActionSlot | undefined>;
|
|
231
|
+
/** Macro text run by a hardware click. Use this in place of `secureAction`. */
|
|
232
|
+
secureMacro?: Binding<string | undefined>;
|
|
224
233
|
/** An anchored secure button keeps its identity and mounts paint and children on its first show. */
|
|
225
234
|
deferContentUntilShown?: true;
|
|
226
235
|
/** Lay out this keyed button directly in its parent CSS container. */
|
package/src/flex-layout.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
527
|
-
|
|
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;
|
package/src/frame-scheduler.ts
CHANGED
|
@@ -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
|
|
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";
|
package/src/keyed-list.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { captureContexts, withContexts } from "./context";
|
|
1
2
|
import type { Element, ElementKey, UIElement } from "./elements";
|
|
2
3
|
import type { OwnedArray, OwnedMap, OwnedReadonlyArray, OwnedRecord, OwnedSet } from "./owned-collections";
|
|
3
4
|
import { withReactiveScope } from "./reactive-scope";
|
|
@@ -226,7 +227,8 @@ interface MapRow<Item, View> {
|
|
|
226
227
|
|
|
227
228
|
function mountMapRow<Item, Key extends ElementKey, View>(key: Key, initial: MapInput<Item>,
|
|
228
229
|
render: (this: void, item: Item, index: number, key: Key) => UIElement,
|
|
229
|
-
parent: RuntimeScope, host: ListHost<View>, reorder: (this: void) => void
|
|
230
|
+
parent: RuntimeScope, host: ListHost<View>, reorder: (this: void) => void,
|
|
231
|
+
contexts: ReturnType<typeof captureContexts>): Result<MapRow<Item, View>> {
|
|
230
232
|
const scope = parent.fork();
|
|
231
233
|
const input = ref(initial);
|
|
232
234
|
let mounted: Row<View> | undefined;
|
|
@@ -235,10 +237,10 @@ function mountMapRow<Item, Key extends ElementKey, View>(key: Key, initial: MapI
|
|
|
235
237
|
const subscription = scope.watch(() => {
|
|
236
238
|
const { item, index } = input.value;
|
|
237
239
|
const candidate = scope.fork();
|
|
238
|
-
const result = withReactiveScope(candidate, () => {
|
|
240
|
+
const result = withContexts(contexts, () => withReactiveScope(candidate, () => {
|
|
239
241
|
const node = render(item, index, key);
|
|
240
242
|
return node.key === key ? node : { ...node as OwnedRecord<UIElement>, key };
|
|
241
|
-
});
|
|
243
|
+
}));
|
|
242
244
|
return { candidate, result };
|
|
243
245
|
}, ({ candidate, result }) => {
|
|
244
246
|
if (!result.ok) {
|
|
@@ -286,7 +288,7 @@ function mountMapRow<Item, Key extends ElementKey, View>(key: Key, initial: MapI
|
|
|
286
288
|
function mountMap<Item, Key extends ElementKey, View>(read: (this: void) => readonly Item[],
|
|
287
289
|
keyBy: (this: void, item: Item, index: number) => Key,
|
|
288
290
|
render: (this: void, item: Item, index: number, key: Key) => UIElement,
|
|
289
|
-
usesIndex: boolean, scope: RuntimeScope, host: ListHost<View>): Failure | undefined {
|
|
291
|
+
usesIndex: boolean, scope: RuntimeScope, host: ListHost<View>, contexts: ReturnType<typeof captureContexts>): Failure | undefined {
|
|
290
292
|
let rows = new Map<Key, MapRow<Item, View>>() as OwnedMap<Key, MapRow<Item, View>>;
|
|
291
293
|
let orderPending = false;
|
|
292
294
|
|
|
@@ -326,7 +328,7 @@ function mountMap<Item, Key extends ElementKey, View>(read: (this: void) => read
|
|
|
326
328
|
for (const [key, input] of inputs) {
|
|
327
329
|
let row = rows.get(key);
|
|
328
330
|
if (!row) {
|
|
329
|
-
const mounted = mountMapRow(key, input, render, scope, host, reorder);
|
|
331
|
+
const mounted = mountMapRow(key, input, render, scope, host, reorder, contexts);
|
|
330
332
|
if (!mounted.ok) {
|
|
331
333
|
for (const staged of created) staged.dispose();
|
|
332
334
|
return mounted;
|
|
@@ -362,5 +364,6 @@ function mountMap<Item, Key extends ElementKey, View>(read: (this: void) => read
|
|
|
362
364
|
export function jsxMap<Item, Key extends ElementKey>(this: void, read: (this: void) => readonly Item[],
|
|
363
365
|
keyBy: (this: void, item: Item, index: number) => Key,
|
|
364
366
|
render: (this: void, item: Item, index: number, key: Key) => UIElement, usesIndex = false): Element<"keyedList"> {
|
|
365
|
-
|
|
367
|
+
const contexts = captureContexts();
|
|
368
|
+
return { kind: "keyedList", props: { mount: (scope, host) => mountMap(read, keyBy, render, usesIndex, scope, host, contexts) }, children: [] };
|
|
366
369
|
}
|