@overmvp/kumi 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +14 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +334 -0
- package/builder/css-v1.test.mjs +321 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +86 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +444 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2164 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +367 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +47 -0
- package/builder/src/numbers.lua +62 -0
- package/builder/src/project-front.mjs +3331 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +127 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +17 -0
- package/form/index.ts +522 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +22 -4
- package/router/index.ts +43 -0
- package/router/package.json +12 -0
- package/router/routes.ts +64 -0
- package/scripts/kumi-cli.mjs +70 -0
- package/scripts/link-addons.mjs +51 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +234 -0
- package/src/css-v1.ts +58 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +479 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +334 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +28 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +22 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +363 -0
- package/src/media-query.ts +144 -0
- package/src/module.ts +277 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +44 -0
- package/src/providers.ts +235 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +254 -0
- package/src/result.ts +58 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +30 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +3 -0
- package/state/package.json +12 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +82 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/README.md +14 -0
- package/templates/addon/__ADDON_NAME__.toc +4 -0
- package/templates/addon/eslint.config.mjs +12 -0
- package/templates/addon/gitignore +8 -0
- package/templates/addon/package.json +21 -0
- package/templates/addon/scripts/build.mjs +25 -0
- package/templates/addon/src/app/main.tsx +13 -0
- package/templates/addon/tsconfig.json +24 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- package/wow/animation.ts +428 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/css-box.ts +110 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +398 -0
- package/wow/css-text.ts +399 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +31 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +97 -0
- package/wow/layout-view.ts +651 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +135 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/protect.ts +24 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/range-art.ts +74 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +156 -0
- package/wow/saved-variables.ts +60 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/start-addon.ts +99 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1746 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
package/router/routes.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
2
|
+
import type { UIElement } from "../src/elements";
|
|
3
|
+
import type { ModuleContext } from "../src/module";
|
|
4
|
+
import { ownedMap, type OwnedMap } from "../src/owned-collections";
|
|
5
|
+
import { fail, ok, type Result } from "@kumi/core";
|
|
6
|
+
|
|
7
|
+
export interface RouteContext<Services extends object, Path extends string = string> extends ModuleContext<Services> {
|
|
8
|
+
path: Path;
|
|
9
|
+
scope: RuntimeScope;
|
|
10
|
+
navigate: (this: void, path: Path) => void;
|
|
11
|
+
t: (this: void, key: string) => string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Files<Page, Layout> = {
|
|
15
|
+
pages: Record<string, Page>;
|
|
16
|
+
layouts: Record<string, Layout>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export interface RouteLayoutProps<Context> {
|
|
20
|
+
context: Context;
|
|
21
|
+
children: UIElement;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type PageFactory<Context> = (this: void, context: Context) => UIElement;
|
|
25
|
+
type LayoutFactory<Context> = (this: void, props: RouteLayoutProps<Context>) => UIElement;
|
|
26
|
+
|
|
27
|
+
export function renderRoute<Context>(page: PageFactory<Context>, layouts: readonly LayoutFactory<Context>[], context: Context) {
|
|
28
|
+
let children = page(context);
|
|
29
|
+
for (let index = layouts.length - 1; index >= 0; index--) {
|
|
30
|
+
children = layouts[index]({ context, children });
|
|
31
|
+
}
|
|
32
|
+
return children;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type Routes<Page, Layout> = OwnedMap<string, { page: Page; layouts: Layout[] }>;
|
|
36
|
+
|
|
37
|
+
export function collectRoutes<Page, Layout>(files: Files<Page, Layout>): Result<Routes<Page, Layout>> {
|
|
38
|
+
const routes: Routes<Page, Layout> = ownedMap();
|
|
39
|
+
for (const [file, page] of Object.entries(files.pages)) {
|
|
40
|
+
const dirs = (file.startsWith("./") ? file.slice(2) : file).split("/");
|
|
41
|
+
dirs.pop();
|
|
42
|
+
const layouts: Layout[] = [];
|
|
43
|
+
const segments: string[] = [];
|
|
44
|
+
let folder = ".";
|
|
45
|
+
function addLayout() {
|
|
46
|
+
const layout = files.layouts[`${folder}/layout.tsx`];
|
|
47
|
+
if (layout !== undefined) layouts.push(layout);
|
|
48
|
+
}
|
|
49
|
+
addLayout();
|
|
50
|
+
for (const dir of dirs) {
|
|
51
|
+
folder += `/${dir}`;
|
|
52
|
+
if (dir.startsWith("(") && dir.endsWith(")")) {
|
|
53
|
+
addLayout();
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
segments.push(dir);
|
|
57
|
+
addLayout();
|
|
58
|
+
}
|
|
59
|
+
const path = `/${segments.join("/")}`;
|
|
60
|
+
if (routes.has(path)) return fail(`Duplicate route ${path} from ${file}`);
|
|
61
|
+
routes.set(path, { page, layouts });
|
|
62
|
+
}
|
|
63
|
+
return ok(routes);
|
|
64
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { linkAddons } from "./link-addons.mjs";
|
|
7
|
+
|
|
8
|
+
const sdk = fileURLToPath(new URL("../", import.meta.url));
|
|
9
|
+
const { name, version } = JSON.parse(readFileSync(join(sdk, "package.json"), "utf8"));
|
|
10
|
+
const template = join(sdk, "templates", "addon");
|
|
11
|
+
const usage = "Usage: kumi init <AddonName> | kumi pack <kumi-pack arguments> | kumi link <build-dir> <AddOns-dir> [--dry-run] | kumi --version";
|
|
12
|
+
|
|
13
|
+
function init(destination) {
|
|
14
|
+
const target = resolve(destination);
|
|
15
|
+
const addon = basename(target);
|
|
16
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]{0,62}$/u.test(addon)) throw new Error("Use a folder name such as MyAddon");
|
|
17
|
+
const replacements = {
|
|
18
|
+
__ADDON_NAME__: addon,
|
|
19
|
+
__PROJECT_NAME__: addon.toLowerCase(),
|
|
20
|
+
__KUMI_PACKAGE__: name,
|
|
21
|
+
__KUMI_VERSION__: version,
|
|
22
|
+
};
|
|
23
|
+
const fill = text => text.replace(/__(ADDON_NAME|PROJECT_NAME|KUMI_PACKAGE|KUMI_VERSION)__/gu, key => replacements[key]);
|
|
24
|
+
function copy(from, to) {
|
|
25
|
+
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
26
|
+
const source = join(from, entry.name);
|
|
27
|
+
const output = join(to, entry.name === "gitignore" ? ".gitignore" : fill(entry.name));
|
|
28
|
+
if (entry.isDirectory()) {
|
|
29
|
+
mkdirSync(output);
|
|
30
|
+
copy(source, output);
|
|
31
|
+
} else if (entry.isFile()) writeFileSync(output, fill(readFileSync(source, "utf8")), { flag: "wx" });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
mkdirSync(target);
|
|
35
|
+
copy(template, target);
|
|
36
|
+
console.log(`Created ${addon}. Run npm install, then npm run check and npm run build from its directory.`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function run(command, args, env) {
|
|
40
|
+
const result = spawnSync(command, args, { stdio: "inherit", env, windowsHide: true });
|
|
41
|
+
if (result.error) {
|
|
42
|
+
if (command === "cargo" && result.error.code === "ENOENT") throw new Error("Install Rust with Cargo on PATH to build Lua");
|
|
43
|
+
throw result.error;
|
|
44
|
+
}
|
|
45
|
+
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function pack(args) {
|
|
49
|
+
const target = resolve("build", "toolchain");
|
|
50
|
+
const env = { ...process.env, CARGO_TARGET_DIR: target, CARGO_BUILD_JOBS: "1", UV_THREADPOOL_SIZE: "1" };
|
|
51
|
+
run("cargo", ["build", "--locked", "--jobs", "1", "--manifest-path", join(sdk, "builder", "Cargo.toml")], env);
|
|
52
|
+
const packer = join(target, "debug", process.platform === "win32" ? "kumi-pack.exe" : "kumi-pack");
|
|
53
|
+
run(packer, [ ...(args.includes("--workspace") ? [] : ["--workspace", process.cwd()]),
|
|
54
|
+
...(args.includes("compile") && !args.includes("--sdk-root") ? ["--sdk-root", sdk] : []), ...args], env);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const [command, ...args] = process.argv.slice(2);
|
|
58
|
+
try {
|
|
59
|
+
if (command === "--version") console.log(version);
|
|
60
|
+
else if (command === undefined || command === "--help" || command === "-h") console.log(usage);
|
|
61
|
+
else if (command === "init" && args.length === 1 && !args[0].startsWith("-")) init(args[0]);
|
|
62
|
+
else if (command === "pack" && args.length > 0) pack(args);
|
|
63
|
+
else if (command === "link" && (args.length === 2 || args.length === 3 && args[2] === "--dry-run")) {
|
|
64
|
+
linkAddons(args[0], args[1], args[2] === "--dry-run");
|
|
65
|
+
}
|
|
66
|
+
else throw new Error(usage);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(`kumi: ${error.code === "EEXIST" ? "The destination already exists. Choose a new directory." : error.message}`);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { lstatSync, realpathSync, readdirSync, statSync, symlinkSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
function inspect(path) {
|
|
5
|
+
return lstatSync(path, { throwIfNoEntry: false });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function linkAddons(buildDirectory, addonsDirectory, dryRun) {
|
|
9
|
+
const build = realpathSync(buildDirectory);
|
|
10
|
+
const addons = realpathSync(addonsDirectory);
|
|
11
|
+
if (!statSync(build).isDirectory() || !statSync(addons).isDirectory() || build === addons) {
|
|
12
|
+
throw new Error("Specify a build folder and a different existing AddOns folder");
|
|
13
|
+
}
|
|
14
|
+
const plan = [];
|
|
15
|
+
let found = 0;
|
|
16
|
+
for (const entry of readdirSync(build, { withFileTypes: true })) {
|
|
17
|
+
if (!entry.isDirectory() || !/^[A-Za-z][A-Za-z0-9_-]*$/u.test(entry.name)) continue;
|
|
18
|
+
const source = join(build, entry.name);
|
|
19
|
+
if (!statSync(join(source, entry.name + ".toc"), { throwIfNoEntry: false })?.isFile()) continue;
|
|
20
|
+
found++;
|
|
21
|
+
const destination = join(addons, entry.name);
|
|
22
|
+
const installed = inspect(destination);
|
|
23
|
+
if (installed) {
|
|
24
|
+
if (!installed.isSymbolicLink() || realpathSync(destination) !== source) {
|
|
25
|
+
throw new Error(`Existing addon ${basename(destination)} at ${addons}. Choose another AddOns directory or move it first.`);
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
plan.push({ source, destination });
|
|
30
|
+
}
|
|
31
|
+
if (plan.length === 0) {
|
|
32
|
+
if (found === 0) throw new Error("No built addon folders with matching TOC files");
|
|
33
|
+
console.log("The addon links already point to this build.");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const created = [];
|
|
37
|
+
try {
|
|
38
|
+
for (const entry of plan) {
|
|
39
|
+
if (!dryRun) {
|
|
40
|
+
symlinkSync(entry.source, entry.destination, process.platform === "win32" ? "junction" : "dir");
|
|
41
|
+
created.push(entry);
|
|
42
|
+
}
|
|
43
|
+
console.log(`${entry.destination} -> ${entry.source}`);
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
for (const { source, destination } of created.reverse()) {
|
|
47
|
+
if (inspect(destination)?.isSymbolicLink() && realpathSync(destination) === source) unlinkSync(destination);
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/bindings.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Anchor, Binding } from "./elements";
|
|
2
|
+
import type { ImageVerticalGradient } from "./images";
|
|
3
|
+
import type { ReadonlyRef } from "./reactivity";
|
|
4
|
+
import type { RuntimeScope } from "./runtime";
|
|
5
|
+
import type { Failure, Result } from "./result";
|
|
6
|
+
import { TextBinding } from "./text-children";
|
|
7
|
+
|
|
8
|
+
type BoundValue = string | boolean | number | Anchor | ImageVerticalGradient;
|
|
9
|
+
|
|
10
|
+
/** Apply a static property once or subscribe to one reactive property for the mount's lifetime. */
|
|
11
|
+
export function bindValue<T extends BoundValue>(scope: RuntimeScope, value: Binding<T>,
|
|
12
|
+
apply: (this: void, value: T) => void,
|
|
13
|
+
equals: (this: void, previous: T | undefined, current: T) => boolean = (previous, current) => previous === current,
|
|
14
|
+
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)) {
|
|
17
|
+
const failure = validate?.(value as T);
|
|
18
|
+
if (failure !== undefined) return failure;
|
|
19
|
+
apply(value as T);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const ref = value as ReadonlyRef<T | Result<T>>;
|
|
23
|
+
let previous: T | undefined;
|
|
24
|
+
const subscription = scope.watchEffect(() => {
|
|
25
|
+
const next = ref.value;
|
|
26
|
+
if (typeof next === "object" && "ok" in next && !next.ok) return next;
|
|
27
|
+
const current = typeof next === "object" && "ok" in next ? next.value : next;
|
|
28
|
+
const failure = validate?.(current);
|
|
29
|
+
if (failure !== undefined) return failure;
|
|
30
|
+
if (equals(previous, current)) return;
|
|
31
|
+
apply(current);
|
|
32
|
+
previous = current;
|
|
33
|
+
});
|
|
34
|
+
return subscription.ok ? undefined : subscription;
|
|
35
|
+
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Protect } from "./result";
|
|
2
|
+
|
|
3
|
+
export function createContext<Value>() {
|
|
4
|
+
let current: Value | undefined;
|
|
5
|
+
|
|
6
|
+
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;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return { run, use: () => current };
|
|
15
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { CssTokenRecipe } from "./css-v1";
|
|
2
|
+
import { parseGridSpan, parseGridTracks } from "./grid-tracks";
|
|
3
|
+
import { ownedArray, type OwnedArray, type OwnedLuaArray, type OwnedReadonlyArray, type OwnedRecord } from "./owned-collections";
|
|
4
|
+
import { fail, ok, type Result } from "./result";
|
|
5
|
+
import type { StyleEnvironment } from "./style-variables";
|
|
6
|
+
|
|
7
|
+
type WithRecipes = { readonly styleTokens?: readonly CssTokenRecipe[] };
|
|
8
|
+
type Field = string | number;
|
|
9
|
+
type Bag = Record<Field, unknown>;
|
|
10
|
+
|
|
11
|
+
function digit(code: number) { return code >= 48 && code <= 57; }
|
|
12
|
+
|
|
13
|
+
function decimal(text: string): number | undefined {
|
|
14
|
+
const start = text.startsWith("-") || text.startsWith("+") ? 1 : 0;
|
|
15
|
+
let index = start;
|
|
16
|
+
while (digit(text.charCodeAt(index))) index++;
|
|
17
|
+
const hasWhole = index > start;
|
|
18
|
+
if (text.charCodeAt(index) === 46) {
|
|
19
|
+
const fraction = ++index;
|
|
20
|
+
while (digit(text.charCodeAt(index))) index++;
|
|
21
|
+
if (fraction === index) return;
|
|
22
|
+
} else if (!hasWhole) return;
|
|
23
|
+
const separator = text.charCodeAt(index);
|
|
24
|
+
if (separator === 69 || separator === 101) {
|
|
25
|
+
index++;
|
|
26
|
+
const sign = text.charCodeAt(index);
|
|
27
|
+
if (sign === 43 || sign === 45) index++;
|
|
28
|
+
const exponent = index;
|
|
29
|
+
while (digit(text.charCodeAt(index))) index++;
|
|
30
|
+
if (exponent === index) return;
|
|
31
|
+
}
|
|
32
|
+
if (index !== text.length) return;
|
|
33
|
+
const number = Number(text);
|
|
34
|
+
return Number.isFinite(number) ? number : undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function pixels(text: string): number | undefined {
|
|
38
|
+
const unit = text.endsWith("px");
|
|
39
|
+
const parsed = decimal(unit ? text.slice(0, -2) : text);
|
|
40
|
+
return unit || parsed === 0 ? parsed : undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function whitespace(code: number) { return code === 32 || (code >= 9 && code <= 13); }
|
|
44
|
+
|
|
45
|
+
function words(text: string): OwnedArray<string> {
|
|
46
|
+
const result = ownedArray<string>();
|
|
47
|
+
let start = 0;
|
|
48
|
+
while (start < text.length) {
|
|
49
|
+
if (whitespace(text.charCodeAt(start))) { start++; continue; }
|
|
50
|
+
let end = start + 1;
|
|
51
|
+
while (end < text.length && !whitespace(text.charCodeAt(end))) end++;
|
|
52
|
+
result.push(text.slice(start, end));
|
|
53
|
+
start = end;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function color(text: string): string | undefined {
|
|
59
|
+
if ((text.length !== 7 && text.length !== 9) || !text.startsWith("#")) return;
|
|
60
|
+
const lower = text.toLowerCase();
|
|
61
|
+
for (let i = 1; i < lower.length; i++) {
|
|
62
|
+
const code = lower.charCodeAt(i);
|
|
63
|
+
if (!digit(code) && (code < 97 || code > 102)) return;
|
|
64
|
+
}
|
|
65
|
+
return text;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function edges(text: string, signed: boolean, side: unknown) {
|
|
69
|
+
const tokens = words(text);
|
|
70
|
+
if (tokens.length === 0 || tokens.length > 4) return;
|
|
71
|
+
const sizes: number[] = [];
|
|
72
|
+
for (const token of tokens) {
|
|
73
|
+
const size = pixels(token);
|
|
74
|
+
if (size === undefined || (!signed && size < 0)) return;
|
|
75
|
+
sizes.push(size);
|
|
76
|
+
}
|
|
77
|
+
if (side === undefined && !signed) return sizes.length === 1 ? sizes[0] : sizes;
|
|
78
|
+
if (typeof side !== "number" || side < 0 || side > 3) return;
|
|
79
|
+
if (side === 0) return sizes[0];
|
|
80
|
+
if (side === 1) return sizes[1] ?? sizes[0];
|
|
81
|
+
if (side === 2) return sizes[2] ?? sizes[0];
|
|
82
|
+
return sizes[3] ?? sizes[1] ?? sizes[0];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function edge(text: string, part: unknown): string | number | undefined {
|
|
86
|
+
let width: number | undefined;
|
|
87
|
+
let paint: string | undefined;
|
|
88
|
+
let solid = false;
|
|
89
|
+
for (const token of words(text)) {
|
|
90
|
+
const size = pixels(token);
|
|
91
|
+
const ink = color(token);
|
|
92
|
+
if (size !== undefined && size >= 0 && width === undefined) width = size;
|
|
93
|
+
else if (ink !== undefined && paint === undefined) paint = ink;
|
|
94
|
+
else if (token === "solid" && !solid) solid = true;
|
|
95
|
+
else return;
|
|
96
|
+
}
|
|
97
|
+
if (width === undefined || paint === undefined) return;
|
|
98
|
+
if (part === "width") return width;
|
|
99
|
+
if (part === "color") return paint;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function shadow(text: string, part: unknown): string | number | undefined {
|
|
103
|
+
const tokens = words(text);
|
|
104
|
+
if (tokens.length !== 3) return;
|
|
105
|
+
const first = color(tokens[0]);
|
|
106
|
+
const x = pixels(tokens[first === undefined ? 0 : 1]);
|
|
107
|
+
const y = pixels(tokens[first === undefined ? 1 : 2]);
|
|
108
|
+
const ink = first ?? color(tokens[2]);
|
|
109
|
+
if (x === undefined || y === undefined || ink === undefined) return;
|
|
110
|
+
if (part === "x") return x;
|
|
111
|
+
if (part === "y") return y;
|
|
112
|
+
if (part === "color") return ink;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function nameChar(code: number) {
|
|
116
|
+
return digit(code) || (code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code === 45 || code === 95;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function image(text: string): { path: string } | { atlas: string } | undefined {
|
|
120
|
+
if (!text.endsWith(")")) return;
|
|
121
|
+
if (text.startsWith("atlas(")) {
|
|
122
|
+
let atlas = text.slice(6, -1).trim();
|
|
123
|
+
const quote = atlas.charAt(0);
|
|
124
|
+
if ((quote === '"' || quote === "'") && atlas.endsWith(quote)) atlas = atlas.slice(1, -1);
|
|
125
|
+
if (atlas === "") return;
|
|
126
|
+
for (let i = 0; i < atlas.length; i++) if (!nameChar(atlas.charCodeAt(i))) return;
|
|
127
|
+
return { atlas };
|
|
128
|
+
}
|
|
129
|
+
if (!text.startsWith("url(")) return;
|
|
130
|
+
const reference = text.slice(4, -1).trim();
|
|
131
|
+
const quote = reference.charAt(0);
|
|
132
|
+
if ((quote !== '"' && quote !== "'") || !reference.endsWith(quote)) return;
|
|
133
|
+
const path = reference.slice(1, -1);
|
|
134
|
+
const relative = path.startsWith("./") ? path.slice(2) : path;
|
|
135
|
+
for (const segment of relative.split("/")) {
|
|
136
|
+
if (segment === "" || !nameChar(segment.charCodeAt(0)) || !nameChar(segment.charCodeAt(segment.length - 1))) return;
|
|
137
|
+
for (let i = 1; i < segment.length - 1; i++) {
|
|
138
|
+
const code = segment.charCodeAt(i);
|
|
139
|
+
if (!nameChar(code) && code !== 32 && code !== 46) return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { path };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function decode(raw: string, recipe: CssTokenRecipe): unknown {
|
|
146
|
+
const text = raw.trim();
|
|
147
|
+
const { kind, add, part, values } = recipe;
|
|
148
|
+
const choices = values as OwnedReadonlyArray<Field> | undefined;
|
|
149
|
+
if (kind === "color") return color(text);
|
|
150
|
+
if (kind === "enum") return choices !== undefined && choices.includes(text) ? text : undefined;
|
|
151
|
+
if (kind === "backgroundImage") return image(text);
|
|
152
|
+
if (kind === "margin" || kind === "padding") return edges(text, kind === "margin", part);
|
|
153
|
+
if (kind === "border") return edge(text, part);
|
|
154
|
+
if (kind === "textShadow") return shadow(text, part);
|
|
155
|
+
if (kind === "gridTracks") return parseGridTracks(text) === undefined ? undefined : text;
|
|
156
|
+
if (kind === "gridColumn") {
|
|
157
|
+
const columns = parseGridSpan(text);
|
|
158
|
+
return columns === undefined ? undefined : `span ${columns}`;
|
|
159
|
+
}
|
|
160
|
+
if (kind === "size" && text === "auto" && add === undefined) return text;
|
|
161
|
+
const length = kind === "length" || kind === "signedLength" || kind === "positiveLength" || kind === "size" || kind === "radius";
|
|
162
|
+
const number = kind === "fontWeight" && add === undefined && (text === "normal" || text === "bold")
|
|
163
|
+
? text === "normal" ? 400 : 700 : length ? pixels(text) : decimal(text);
|
|
164
|
+
if (number === undefined) return;
|
|
165
|
+
const value = number + (add ?? 0);
|
|
166
|
+
if (!Number.isFinite(value)) return;
|
|
167
|
+
if (kind === "integer" && !Number.isInteger(value)) return;
|
|
168
|
+
if (kind === "positiveLength" && value <= 0) return;
|
|
169
|
+
if (kind === "opacity" && value > 1) return;
|
|
170
|
+
if (kind !== "signedLength" && kind !== "integer" && value < 0) return;
|
|
171
|
+
if (choices !== undefined && !choices.includes(value)) return;
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function replace(target: Bag | unknown[], path: OwnedReadonlyArray<Field>, at: number, value: unknown): void {
|
|
176
|
+
const key = path[at];
|
|
177
|
+
const sequence = Array.isArray(target) && typeof key === "number" ? target as OwnedLuaArray<unknown> : undefined;
|
|
178
|
+
let next = value;
|
|
179
|
+
if (at < path.length - 1) {
|
|
180
|
+
const previous = sequence === undefined ? (target as Bag)[key] : sequence[key as number];
|
|
181
|
+
const copy = Array.isArray(previous) ? [...(previous as OwnedLuaArray<unknown>)]
|
|
182
|
+
: previous === undefined ? {} : { ...(previous as OwnedRecord<Bag>) };
|
|
183
|
+
replace(copy, path, at + 1, value);
|
|
184
|
+
next = copy;
|
|
185
|
+
}
|
|
186
|
+
if (sequence === undefined) (target as Bag)[key] = next;
|
|
187
|
+
else sequence[key as number] = next;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function resolveCssTokens<Style extends WithRecipes>(this: void, base: Style, environment?: StyleEnvironment): Result<Style> {
|
|
191
|
+
const recipes = base.styleTokens as OwnedReadonlyArray<CssTokenRecipe> | undefined;
|
|
192
|
+
if (recipes === undefined || environment === undefined) return ok(base);
|
|
193
|
+
let values: Bag | undefined;
|
|
194
|
+
// Token names start with "--". A plain table avoids Lua Map descriptors; false records a missing value.
|
|
195
|
+
const sourced: Record<string, string | false | undefined> = {};
|
|
196
|
+
for (const recipe of recipes) {
|
|
197
|
+
let token = sourced[recipe.token];
|
|
198
|
+
if (token === undefined) {
|
|
199
|
+
const authored = environment(recipe.token);
|
|
200
|
+
if (!authored.ok) return authored;
|
|
201
|
+
token = authored.value ?? false;
|
|
202
|
+
sourced[recipe.token] = token;
|
|
203
|
+
}
|
|
204
|
+
if (token === false || token === recipe.source) continue;
|
|
205
|
+
const parsed = decode(token, recipe);
|
|
206
|
+
const path = recipe.path as OwnedReadonlyArray<Field>;
|
|
207
|
+
if (parsed === undefined) return fail(`Invalid CSS token ${recipe.token} for ${path.join(".")}: ${token.slice(0, 80)}`);
|
|
208
|
+
if (parsed === recipe.fallback) continue;
|
|
209
|
+
values ??= { ...(base as OwnedRecord<Style>) };
|
|
210
|
+
replace(values, path, 0, parsed);
|
|
211
|
+
}
|
|
212
|
+
if (values === undefined) return ok(base);
|
|
213
|
+
const { minWidth, maxWidth, minHeight, maxHeight } = values;
|
|
214
|
+
if (typeof minWidth === "number" && typeof maxWidth === "number" && minWidth > maxWidth) return fail("CSS min-width exceeds max-width");
|
|
215
|
+
if (typeof minHeight === "number" && typeof maxHeight === "number" && minHeight > maxHeight) return fail("CSS min-height exceeds max-height");
|
|
216
|
+
return ok(values as Style);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function mergeCssTokens(this: void, previous: readonly CssTokenRecipe[] | undefined,
|
|
220
|
+
next: WithRecipes): readonly CssTokenRecipe[] | undefined {
|
|
221
|
+
if (previous === undefined) return next.styleTokens;
|
|
222
|
+
const fields = next as Bag;
|
|
223
|
+
const retained = ownedArray<CssTokenRecipe>();
|
|
224
|
+
for (const recipe of previous as OwnedReadonlyArray<CssTokenRecipe>) {
|
|
225
|
+
const path = recipe.path as OwnedReadonlyArray<Field>;
|
|
226
|
+
if (fields[path[0]] === undefined) retained.push(recipe);
|
|
227
|
+
}
|
|
228
|
+
const added = next.styleTokens as OwnedReadonlyArray<CssTokenRecipe> | undefined;
|
|
229
|
+
if (added !== undefined) {
|
|
230
|
+
for (const recipe of added) retained.push(recipe);
|
|
231
|
+
return retained;
|
|
232
|
+
}
|
|
233
|
+
return retained.length > 0 ? retained : undefined;
|
|
234
|
+
}
|
package/src/css-v1.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Binding } from "./elements";
|
|
2
|
+
import type { StatePaint } from "./style-states";
|
|
3
|
+
import type { LayoutDisplay, LayoutPosition } from "./flex-layout";
|
|
4
|
+
|
|
5
|
+
export type CssSide = "top" | "right" | "bottom" | "left";
|
|
6
|
+
export type CssOverflow = "hidden" | "scroll";
|
|
7
|
+
export type CssFontWeight = number;
|
|
8
|
+
export type CssTextAlign = "left" | "center" | "right";
|
|
9
|
+
|
|
10
|
+
export interface CssBorderEdge {
|
|
11
|
+
readonly width: number;
|
|
12
|
+
readonly color: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type CssBorder = Readonly<Partial<Record<CssSide, CssBorderEdge>>>;
|
|
16
|
+
|
|
17
|
+
export interface CssTextShadow {
|
|
18
|
+
readonly x: number;
|
|
19
|
+
readonly y: number;
|
|
20
|
+
readonly color: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CssTokenRecipe {
|
|
24
|
+
readonly path: readonly (string | number)[];
|
|
25
|
+
readonly token: `--${string}`;
|
|
26
|
+
readonly kind: string;
|
|
27
|
+
readonly fallback: unknown;
|
|
28
|
+
/** @internal Exact compiler-validated token text whose decoded value is `fallback`. */
|
|
29
|
+
readonly source?: string;
|
|
30
|
+
readonly add?: number;
|
|
31
|
+
readonly part?: string | number;
|
|
32
|
+
readonly values?: readonly (string | number)[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface CssV1Style {
|
|
36
|
+
/** `static` (default), `relative` (shifted after layout) or `absolute` (out of flow, in the containing block). */
|
|
37
|
+
position?: LayoutPosition;
|
|
38
|
+
top?: Binding<number>;
|
|
39
|
+
right?: Binding<number>;
|
|
40
|
+
bottom?: Binding<number>;
|
|
41
|
+
left?: Binding<number>;
|
|
42
|
+
/** Sides whose margin is `auto` (top, right, bottom, left): an absolute box with both insets on an axis is centered
|
|
43
|
+
* between them, its own size or its content's (as `width: fit-content`). */
|
|
44
|
+
autoMargin?: Binding<readonly [boolean, boolean, boolean, boolean]>;
|
|
45
|
+
border?: CssBorder;
|
|
46
|
+
borderRadius?: number;
|
|
47
|
+
backgroundImage?: StatePaint["backgroundImage"];
|
|
48
|
+
fontWeight?: CssFontWeight;
|
|
49
|
+
textAlign?: CssTextAlign;
|
|
50
|
+
textShadow?: CssTextShadow;
|
|
51
|
+
textTransform?: "uppercase" | "lowercase" | "capitalize" | "none";
|
|
52
|
+
textOverflow?: "ellipsis";
|
|
53
|
+
whiteSpace?: "nowrap";
|
|
54
|
+
overflow?: CssOverflow;
|
|
55
|
+
styleTokens?: readonly CssTokenRecipe[];
|
|
56
|
+
/** @internal The flow mode of a live CSS display binding. */
|
|
57
|
+
layoutDisplay?: Binding<LayoutDisplay>;
|
|
58
|
+
}
|
package/src/cvars.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { fail, type Result } from "./result";
|
|
2
|
+
|
|
3
|
+
export type CVarValue = string | number | boolean;
|
|
4
|
+
export interface CVarCodec<Value extends CVarValue> {
|
|
5
|
+
decode(this: void, value: string): Value | undefined;
|
|
6
|
+
encode(this: void, value: unknown): string | undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type CVarSchema = Readonly<Record<string, CVarCodec<CVarValue>>>;
|
|
10
|
+
export type CVarName<Schema extends CVarSchema> = keyof Schema & string;
|
|
11
|
+
export type CVarValueFor<Schema extends CVarSchema, Name extends CVarName<Schema>> =
|
|
12
|
+
Exclude<ReturnType<Schema[Name]["decode"]>, undefined>;
|
|
13
|
+
|
|
14
|
+
export interface RawCVars {
|
|
15
|
+
read(this: void, name: string): string | undefined;
|
|
16
|
+
readDefault(this: void, name: string): string | undefined;
|
|
17
|
+
write(this: void, name: string, value: string): Result<void>;
|
|
18
|
+
register?(this: void, name: string, defaultValue: string): Result<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CVars<Schema extends CVarSchema> {
|
|
22
|
+
readonly raw: RawCVars;
|
|
23
|
+
read<Name extends CVarName<Schema>>(this: void, name: Name): CVarValueFor<Schema, Name> | undefined;
|
|
24
|
+
readDefault<Name extends CVarName<Schema>>(this: void, name: Name): CVarValueFor<Schema, Name> | undefined;
|
|
25
|
+
write<Name extends CVarName<Schema>>(this: void, name: Name, value: NoInfer<CVarValueFor<Schema, Name>>): Result<void>;
|
|
26
|
+
register<Name extends CVarName<Schema>>(this: void, name: Name, value: NoInfer<CVarValueFor<Schema, Name>>): Result<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function numeric(value: unknown): value is number {
|
|
30
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parseNumber(value: string) {
|
|
34
|
+
if (value.trim() === "") return undefined;
|
|
35
|
+
const number = Number(value);
|
|
36
|
+
return numeric(number) ? number : undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const boolean: CVarCodec<boolean> = {
|
|
40
|
+
decode: value => value === "1" ? true : value === "0" ? false : undefined,
|
|
41
|
+
encode: value => typeof value === "boolean" ? (value ? "1" : "0") : undefined,
|
|
42
|
+
};
|
|
43
|
+
const string: CVarCodec<string> = { decode: value => value, encode: value => typeof value === "string" ? value : undefined };
|
|
44
|
+
const number: CVarCodec<number> = { decode: parseNumber, encode: value => numeric(value) ? String(value) : undefined };
|
|
45
|
+
|
|
46
|
+
function integer(min = -Infinity, max = Infinity): CVarCodec<number> {
|
|
47
|
+
const valid = (value: unknown): value is number => numeric(value) && Math.floor(value) === value && value >= min && value <= max;
|
|
48
|
+
return {
|
|
49
|
+
decode(value) { const parsed = parseNumber(value); return valid(parsed) ? parsed : undefined; },
|
|
50
|
+
encode: value => valid(value) ? String(value) : undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function oneOf<const Values extends readonly [string, ...string[]] | readonly [number, ...number[]]>(
|
|
55
|
+
...values: Values
|
|
56
|
+
): CVarCodec<Values[number]> {
|
|
57
|
+
const numericChoices = typeof values[0] === "number";
|
|
58
|
+
return {
|
|
59
|
+
decode(value) {
|
|
60
|
+
const candidate = numericChoices ? parseNumber(value) : value;
|
|
61
|
+
for (const choice of values) if (choice === candidate) return choice;
|
|
62
|
+
},
|
|
63
|
+
encode(value) {
|
|
64
|
+
for (const choice of values) if (choice === value) return String(choice);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const cvar = { boolean, string, number, integer, oneOf };
|
|
70
|
+
|
|
71
|
+
export function defineCVars<const Schema extends CVarSchema>(schema: Schema): Schema { return schema; }
|
|
72
|
+
|
|
73
|
+
export function createCVars<Schema extends CVarSchema>(schema: Schema, raw: RawCVars): CVars<Schema> {
|
|
74
|
+
function decode<Name extends CVarName<Schema>>(name: Name, value: string | undefined) {
|
|
75
|
+
return value === undefined ? undefined : schema[name]?.decode(value) as CVarValueFor<Schema, Name> | undefined;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
raw,
|
|
79
|
+
read: name => decode(name, raw.read(name)),
|
|
80
|
+
readDefault: name => decode(name, raw.readDefault(name)),
|
|
81
|
+
write(name, value) {
|
|
82
|
+
const encoded = schema[name]?.encode(value);
|
|
83
|
+
return encoded === undefined ? fail("Invalid CVar value for " + name) : raw.write(name, encoded);
|
|
84
|
+
},
|
|
85
|
+
register(name, value) {
|
|
86
|
+
const encoded = schema[name]?.encode(value);
|
|
87
|
+
if (encoded === undefined) return fail("Invalid CVar default for " + name);
|
|
88
|
+
return raw.register?.(name, encoded) ?? fail("The host does not support CVar registration");
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { NativeHandle } from "./elements";
|
|
2
|
+
import type { NodeQuery, SelectorNode } from "./node-selectors";
|
|
3
|
+
|
|
4
|
+
export type MountedElementKind = "frame" | "image" | "text" | "statusbar" | "button" | "scrollview" | "slot"
|
|
5
|
+
| "editbox" | "checkbox" | "range" | "listbox";
|
|
6
|
+
|
|
7
|
+
export interface NodeRect {
|
|
8
|
+
readonly left: number;
|
|
9
|
+
readonly bottom: number;
|
|
10
|
+
readonly width: number;
|
|
11
|
+
readonly height: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface KumiNode<Kind extends MountedElementKind = MountedElementKind> extends SelectorNode {
|
|
15
|
+
readonly kind?: Kind;
|
|
16
|
+
readonly parent?: KumiNode;
|
|
17
|
+
readonly children?: readonly KumiNode[];
|
|
18
|
+
readonly firstChild?: KumiNode;
|
|
19
|
+
readonly lastChild?: KumiNode;
|
|
20
|
+
readonly previousSibling?: KumiNode;
|
|
21
|
+
readonly nextSibling?: KumiNode;
|
|
22
|
+
readonly native?: NativeHandle<Kind>;
|
|
23
|
+
closest(selector: string): NodeQuery<KumiNode | undefined> | undefined;
|
|
24
|
+
querySelector(selector: string): NodeQuery<KumiNode | undefined> | undefined;
|
|
25
|
+
querySelectorAll(selector: string): NodeQuery<readonly KumiNode[]> | undefined;
|
|
26
|
+
contains(node: KumiNode): boolean | undefined;
|
|
27
|
+
rect(): NodeRect | undefined;
|
|
28
|
+
isShown(): boolean | undefined;
|
|
29
|
+
focus(): boolean | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type NodeRef<Kind extends MountedElementKind> = (this: void, node?: KumiNode<Kind>) => void;
|