@overmvp/kumi 0.0.0-stage → 0.3.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 +67 -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 +387 -0
- package/builder/css-v1.test.mjs +361 -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 +127 -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 +435 -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 +2336 -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 +381 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +83 -0
- package/builder/src/numbers.lua +76 -0
- package/builder/src/project-front.mjs +3682 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +124 -0
- package/builder/src/setup-store.lua +18 -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-reads.lua +22 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-modules.mjs +93 -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 +59 -0
- package/eslint.mjs +74 -0
- package/form/index.ts +526 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +26 -4
- package/router/index.ts +50 -0
- package/router/navigation.ts +22 -0
- package/router/package.json +12 -0
- package/router/router-view.ts +134 -0
- package/router/routes.ts +64 -0
- package/scripts/addon-build.mjs +364 -0
- package/scripts/addon-project.mjs +78 -0
- package/scripts/kumi-cli.mjs +105 -0
- package/scripts/link-addons.mjs +61 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +239 -0
- package/src/css-v1.ts +68 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +505 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +336 -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 +29 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +29 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +366 -0
- package/src/media-query.ts +144 -0
- package/src/module-ui.ts +147 -0
- package/src/module.ts +311 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +52 -0
- package/src/providers.ts +241 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +275 -0
- package/src/result.ts +64 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +63 -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 +9 -0
- package/state/package.json +12 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +84 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +49 -0
- package/templates/addon/eslint.config.mjs +6 -0
- package/templates/addon/gitignore +9 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +20 -0
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/_tokens.scss +12 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +63 -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/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +219 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +36 -0
- package/wow/animation.ts +428 -0
- package/wow/app-ui.ts +221 -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/cooldown-timing.ts +24 -0
- package/wow/css-box.ts +144 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +603 -0
- package/wow/css-text.ts +399 -0
- package/wow/cursor.ts +45 -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 +53 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frame-timing.ts +13 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/hooks.ts +133 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +111 -0
- package/wow/layout-view.ts +663 -0
- package/wow/locale-font.ts +15 -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 +153 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/protect.ts +48 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/protected-view.ts +103 -0
- package/wow/range-art.ts +81 -0
- package/wow/readable-api.ts +120 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +183 -0
- package/wow/saved-variables.ts +109 -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/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +122 -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 +1864 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { constants, copyFileSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, extname, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { linkAddons } from "./link-addons.mjs";
|
|
8
|
+
|
|
9
|
+
const sdk = fileURLToPath(new URL("../", import.meta.url));
|
|
10
|
+
const { name, version } = JSON.parse(readFileSync(join(sdk, "package.json"), "utf8"));
|
|
11
|
+
const template = join(sdk, "templates", "addon");
|
|
12
|
+
const usage = `Usage:
|
|
13
|
+
kumi init <AddonName>
|
|
14
|
+
kumi check [--types-only]
|
|
15
|
+
kumi build [--target retail|forever] [--toc number]
|
|
16
|
+
kumi link <AddOns-dir> [--dry-run]
|
|
17
|
+
kumi --version`;
|
|
18
|
+
|
|
19
|
+
const TEMPLATE_TEXT_EXTENSIONS = new Set([".css", ".json", ".md", ".mjs", ".scss", ".toc", ".ts", ".tsx"]);
|
|
20
|
+
|
|
21
|
+
function init(destination) {
|
|
22
|
+
const target = resolve(destination);
|
|
23
|
+
const addon = basename(target);
|
|
24
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]{0,62}$/u.test(addon)) throw new Error("Use a folder name such as MyAddon");
|
|
25
|
+
const replacements = {
|
|
26
|
+
__ADDON_NAME__: addon,
|
|
27
|
+
__ADDON_DB__: addon.replace(/[^A-Za-z0-9_]/g, "_") + "DB",
|
|
28
|
+
__PROJECT_NAME__: addon.toLowerCase(),
|
|
29
|
+
__KUMI_PACKAGE__: name,
|
|
30
|
+
__KUMI_VERSION__: version,
|
|
31
|
+
__ADDON_SLASH__: addon.toLowerCase().replace(/[^a-z0-9]/gu, ""),
|
|
32
|
+
};
|
|
33
|
+
const fill = text => text.replace(/__(ADDON_NAME|ADDON_DB|ADDON_SLASH|PROJECT_NAME|KUMI_PACKAGE|KUMI_VERSION)__/gu, key => replacements[key]);
|
|
34
|
+
function copy(from, to) {
|
|
35
|
+
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
36
|
+
const source = join(from, entry.name);
|
|
37
|
+
const output = join(to, entry.name === "gitignore" ? ".gitignore" : fill(entry.name));
|
|
38
|
+
if (entry.isDirectory()) {
|
|
39
|
+
mkdirSync(output);
|
|
40
|
+
copy(source, output);
|
|
41
|
+
} else if (entry.isFile()) {
|
|
42
|
+
if (entry.name === "gitignore" || TEMPLATE_TEXT_EXTENSIONS.has(extname(entry.name))) {
|
|
43
|
+
writeFileSync(output, fill(readFileSync(source, "utf8")), { flag: "wx" });
|
|
44
|
+
} else {
|
|
45
|
+
copyFileSync(source, output, constants.COPYFILE_EXCL);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
mkdirSync(target);
|
|
51
|
+
copy(template, target);
|
|
52
|
+
console.log(`Created ${addon}. Run npm install, then npm run check and npm run build from its directory.`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function run(command, args, env) {
|
|
56
|
+
const result = spawnSync(command, args, { stdio: "inherit", env, windowsHide: true });
|
|
57
|
+
if (result.error) {
|
|
58
|
+
if (command === "cargo" && result.error.code === "ENOENT") throw new Error("Install Rust with Cargo on PATH to build Lua");
|
|
59
|
+
throw result.error;
|
|
60
|
+
}
|
|
61
|
+
if (result.status !== 0) throw Object.assign(new Error("Kumi subprocess failed"), { exitStatus: result.status ?? 1 });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createPackRunner(workspace) {
|
|
65
|
+
const target = join(workspace, "build", "toolchain");
|
|
66
|
+
const env = { ...process.env, CARGO_TARGET_DIR: target, CARGO_BUILD_JOBS: "1", UV_THREADPOOL_SIZE: "1" };
|
|
67
|
+
const packer = join(target, "debug", process.platform === "win32" ? "kumi-pack.exe" : "kumi-pack");
|
|
68
|
+
let ready = false;
|
|
69
|
+
return args => {
|
|
70
|
+
if (!ready) {
|
|
71
|
+
run("cargo", ["build", "--locked", "--jobs", "1", "--manifest-path", join(sdk, "builder", "Cargo.toml")], env);
|
|
72
|
+
ready = true;
|
|
73
|
+
}
|
|
74
|
+
run(packer, [ ...(args.includes("--workspace") ? [] : ["--workspace", workspace]),
|
|
75
|
+
...(args.includes("compile") && !args.includes("--sdk-root") ? ["--sdk-root", sdk] : []), ...args], env);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function link(args) {
|
|
80
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { "dry-run": { type: "boolean" } } });
|
|
81
|
+
if (positionals.length === 1) linkAddons(join("build", "addons"), positionals[0], values["dry-run"]);
|
|
82
|
+
else if (positionals.length === 2) linkAddons(positionals[0], positionals[1], values["dry-run"]);
|
|
83
|
+
else throw new Error(usage);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const [command, ...args] = process.argv.slice(2);
|
|
87
|
+
try {
|
|
88
|
+
if (command === "--version") console.log(version);
|
|
89
|
+
else if (command === undefined || command === "--help" || command === "-h") console.log(usage);
|
|
90
|
+
else if (command === "init" && args.length === 1 && !args[0].startsWith("-")) init(args[0]);
|
|
91
|
+
else if (command === "check" || command === "build") {
|
|
92
|
+
const { checkAddon, buildAddon } = await import("./addon-project.mjs");
|
|
93
|
+
const workspace = process.cwd();
|
|
94
|
+
const pack = createPackRunner(workspace);
|
|
95
|
+
if (command === "check") await checkAddon(workspace, args, pack, run);
|
|
96
|
+
else await buildAddon(workspace, args, pack);
|
|
97
|
+
} else if (command === "pack" && args.length > 0) createPackRunner(process.cwd())(args);
|
|
98
|
+
else if (command === "link") link(args);
|
|
99
|
+
else throw new Error(usage);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error.exitStatus === undefined) {
|
|
102
|
+
console.error(`kumi: ${error.code === "EEXIST" ? "The destination already exists. Choose a new directory." : error.message}`);
|
|
103
|
+
}
|
|
104
|
+
process.exitCode = error.exitStatus ?? 1;
|
|
105
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { lstatSync, readlinkSync, realpathSync, readdirSync, statSync, symlinkSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { basename, join, resolve, sep } 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
|
+
// Remove links into this build whose folder no longer exists, such as a plugin removed from kumi.config.ts.
|
|
15
|
+
for (const entry of readdirSync(addons, { withFileTypes: true })) {
|
|
16
|
+
const destination = join(addons, entry.name);
|
|
17
|
+
const link = inspect(destination);
|
|
18
|
+
if (!link?.isSymbolicLink() || statSync(destination, { throwIfNoEntry: false }) !== undefined) continue;
|
|
19
|
+
const target = resolve(addons, readlinkSync(destination));
|
|
20
|
+
if (!target.toLowerCase().startsWith(build.toLowerCase() + sep)) continue;
|
|
21
|
+
if (!dryRun) unlinkSync(destination);
|
|
22
|
+
console.log(`Removed stale link ${destination}`);
|
|
23
|
+
}
|
|
24
|
+
const plan = [];
|
|
25
|
+
let found = 0;
|
|
26
|
+
for (const entry of readdirSync(build, { withFileTypes: true })) {
|
|
27
|
+
if (!entry.isDirectory() || !/^[A-Za-z][A-Za-z0-9_-]*$/u.test(entry.name)) continue;
|
|
28
|
+
const source = join(build, entry.name);
|
|
29
|
+
if (!statSync(join(source, entry.name + ".toc"), { throwIfNoEntry: false })?.isFile()) continue;
|
|
30
|
+
found++;
|
|
31
|
+
const destination = join(addons, entry.name);
|
|
32
|
+
const installed = inspect(destination);
|
|
33
|
+
if (installed) {
|
|
34
|
+
if (!installed.isSymbolicLink() || realpathSync(destination) !== source) {
|
|
35
|
+
throw new Error(`Existing addon ${basename(destination)} at ${addons}. Choose another AddOns directory or move it first.`);
|
|
36
|
+
}
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
plan.push({ source, destination });
|
|
40
|
+
}
|
|
41
|
+
if (plan.length === 0) {
|
|
42
|
+
if (found === 0) throw new Error("No built addon folders with matching TOC files");
|
|
43
|
+
console.log("The addon links already point to this build.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const created = [];
|
|
47
|
+
try {
|
|
48
|
+
for (const entry of plan) {
|
|
49
|
+
if (!dryRun) {
|
|
50
|
+
symlinkSync(entry.source, entry.destination, process.platform === "win32" ? "junction" : "dir");
|
|
51
|
+
created.push(entry);
|
|
52
|
+
}
|
|
53
|
+
console.log(`${entry.destination} -> ${entry.source}`);
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
for (const { source, destination } of created.reverse()) {
|
|
57
|
+
if (inspect(destination)?.isSymbolicLink() && realpathSync(destination) === source) unlinkSync(destination);
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/bindings.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ActionSlot, Anchor, Binding, CooldownValue } 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 | ActionSlot | Anchor | CooldownValue | ImageVerticalGradient | undefined;
|
|
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,239 @@
|
|
|
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 length = text.length;
|
|
15
|
+
const start = text.startsWith("-") || text.startsWith("+") ? 1 : 0;
|
|
16
|
+
let index = start;
|
|
17
|
+
while (index < length && digit(text.charCodeAt(index))) index += 1;
|
|
18
|
+
const hasWhole = index > start;
|
|
19
|
+
if (index < length && text.charCodeAt(index) === 46) {
|
|
20
|
+
index += 1;
|
|
21
|
+
const fraction = index;
|
|
22
|
+
while (index < length && digit(text.charCodeAt(index))) index += 1;
|
|
23
|
+
if (fraction === index) return;
|
|
24
|
+
} else if (!hasWhole) return;
|
|
25
|
+
if (index < length) {
|
|
26
|
+
const separator = text.charCodeAt(index);
|
|
27
|
+
if (separator !== 69 && separator !== 101) return;
|
|
28
|
+
index += 1;
|
|
29
|
+
if (index < length) {
|
|
30
|
+
const sign = text.charCodeAt(index);
|
|
31
|
+
if (sign === 43 || sign === 45) index += 1;
|
|
32
|
+
}
|
|
33
|
+
const exponent = index;
|
|
34
|
+
while (index < length && digit(text.charCodeAt(index))) index += 1;
|
|
35
|
+
if (exponent === index) return;
|
|
36
|
+
}
|
|
37
|
+
if (index !== length) return;
|
|
38
|
+
const number = Number(text);
|
|
39
|
+
return Number.isFinite(number) ? number : undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function pixels(text: string): number | undefined {
|
|
43
|
+
const unit = text.endsWith("px");
|
|
44
|
+
const parsed = decimal(unit ? text.slice(0, -2) : text);
|
|
45
|
+
return unit || parsed === 0 ? parsed : undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function whitespace(code: number) { return code === 32 || (code >= 9 && code <= 13); }
|
|
49
|
+
|
|
50
|
+
function words(text: string): OwnedArray<string> {
|
|
51
|
+
const result = ownedArray<string>();
|
|
52
|
+
let start = 0;
|
|
53
|
+
while (start < text.length) {
|
|
54
|
+
if (whitespace(text.charCodeAt(start))) { start++; continue; }
|
|
55
|
+
let end = start + 1;
|
|
56
|
+
while (end < text.length && !whitespace(text.charCodeAt(end))) end++;
|
|
57
|
+
result.push(text.slice(start, end));
|
|
58
|
+
start = end;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function color(text: string): string | undefined {
|
|
64
|
+
if ((text.length !== 7 && text.length !== 9) || !text.startsWith("#")) return;
|
|
65
|
+
const lower = text.toLowerCase();
|
|
66
|
+
for (let i = 1; i < lower.length; i++) {
|
|
67
|
+
const code = lower.charCodeAt(i);
|
|
68
|
+
if (!digit(code) && (code < 97 || code > 102)) return;
|
|
69
|
+
}
|
|
70
|
+
return text;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function edges(text: string, signed: boolean, side: unknown) {
|
|
74
|
+
const tokens = words(text);
|
|
75
|
+
if (tokens.length === 0 || tokens.length > 4) return;
|
|
76
|
+
const sizes: number[] = [];
|
|
77
|
+
for (const token of tokens) {
|
|
78
|
+
const size = pixels(token);
|
|
79
|
+
if (size === undefined || (!signed && size < 0)) return;
|
|
80
|
+
sizes.push(size);
|
|
81
|
+
}
|
|
82
|
+
if (side === undefined && !signed) return sizes.length === 1 ? sizes[0] : sizes;
|
|
83
|
+
if (typeof side !== "number" || side < 0 || side > 3) return;
|
|
84
|
+
if (side === 0) return sizes[0];
|
|
85
|
+
if (side === 1) return sizes[1] ?? sizes[0];
|
|
86
|
+
if (side === 2) return sizes[2] ?? sizes[0];
|
|
87
|
+
return sizes[3] ?? sizes[1] ?? sizes[0];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function edge(text: string, part: unknown): string | number | undefined {
|
|
91
|
+
let width: number | undefined;
|
|
92
|
+
let paint: string | undefined;
|
|
93
|
+
let solid = false;
|
|
94
|
+
for (const token of words(text)) {
|
|
95
|
+
const size = pixels(token);
|
|
96
|
+
const ink = color(token);
|
|
97
|
+
if (size !== undefined && size >= 0 && width === undefined) width = size;
|
|
98
|
+
else if (ink !== undefined && paint === undefined) paint = ink;
|
|
99
|
+
else if (token === "solid" && !solid) solid = true;
|
|
100
|
+
else return;
|
|
101
|
+
}
|
|
102
|
+
if (width === undefined || paint === undefined) return;
|
|
103
|
+
if (part === "width") return width;
|
|
104
|
+
if (part === "color") return paint;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function shadow(text: string, part: unknown): string | number | undefined {
|
|
108
|
+
const tokens = words(text);
|
|
109
|
+
if (tokens.length !== 3) return;
|
|
110
|
+
const first = color(tokens[0]);
|
|
111
|
+
const x = pixels(tokens[first === undefined ? 0 : 1]);
|
|
112
|
+
const y = pixels(tokens[first === undefined ? 1 : 2]);
|
|
113
|
+
const ink = first ?? color(tokens[2]);
|
|
114
|
+
if (x === undefined || y === undefined || ink === undefined) return;
|
|
115
|
+
if (part === "x") return x;
|
|
116
|
+
if (part === "y") return y;
|
|
117
|
+
if (part === "color") return ink;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function nameChar(code: number) {
|
|
121
|
+
return digit(code) || (code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code === 45 || code === 95;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function image(text: string): { path: string } | { atlas: string } | undefined {
|
|
125
|
+
if (!text.endsWith(")")) return;
|
|
126
|
+
if (text.startsWith("atlas(")) {
|
|
127
|
+
let atlas = text.slice(6, -1).trim();
|
|
128
|
+
const quote = atlas.charAt(0);
|
|
129
|
+
if ((quote === '"' || quote === "'") && atlas.endsWith(quote)) atlas = atlas.slice(1, -1);
|
|
130
|
+
if (atlas === "") return;
|
|
131
|
+
for (let i = 0; i < atlas.length; i++) if (!nameChar(atlas.charCodeAt(i))) return;
|
|
132
|
+
return { atlas };
|
|
133
|
+
}
|
|
134
|
+
if (!text.startsWith("url(")) return;
|
|
135
|
+
const reference = text.slice(4, -1).trim();
|
|
136
|
+
const quote = reference.charAt(0);
|
|
137
|
+
if ((quote !== '"' && quote !== "'") || !reference.endsWith(quote)) return;
|
|
138
|
+
const path = reference.slice(1, -1);
|
|
139
|
+
const relative = path.startsWith("./") ? path.slice(2) : path;
|
|
140
|
+
for (const segment of relative.split("/")) {
|
|
141
|
+
if (segment === "" || !nameChar(segment.charCodeAt(0)) || !nameChar(segment.charCodeAt(segment.length - 1))) return;
|
|
142
|
+
for (let i = 1; i < segment.length - 1; i++) {
|
|
143
|
+
const code = segment.charCodeAt(i);
|
|
144
|
+
if (!nameChar(code) && code !== 32 && code !== 46) return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return { path };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function decode(raw: string, recipe: CssTokenRecipe): unknown {
|
|
151
|
+
const text = raw.trim();
|
|
152
|
+
const { kind, add, part, values } = recipe;
|
|
153
|
+
const choices = values as OwnedReadonlyArray<Field> | undefined;
|
|
154
|
+
if (kind === "color") return color(text);
|
|
155
|
+
if (kind === "enum") return choices !== undefined && choices.includes(text) ? text : undefined;
|
|
156
|
+
if (kind === "backgroundImage") return image(text);
|
|
157
|
+
if (kind === "margin" || kind === "padding") return edges(text, kind === "margin", part);
|
|
158
|
+
if (kind === "border") return edge(text, part);
|
|
159
|
+
if (kind === "textShadow") return shadow(text, part);
|
|
160
|
+
if (kind === "gridTracks") return parseGridTracks(text) === undefined ? undefined : text;
|
|
161
|
+
if (kind === "gridColumn") {
|
|
162
|
+
const columns = parseGridSpan(text);
|
|
163
|
+
return columns === undefined ? undefined : `span ${columns}`;
|
|
164
|
+
}
|
|
165
|
+
if (kind === "size" && text === "auto" && add === undefined) return text;
|
|
166
|
+
const length = kind === "length" || kind === "signedLength" || kind === "positiveLength" || kind === "size" || kind === "radius";
|
|
167
|
+
const number = kind === "fontWeight" && add === undefined && (text === "normal" || text === "bold")
|
|
168
|
+
? text === "normal" ? 400 : 700 : length ? pixels(text) : decimal(text);
|
|
169
|
+
if (number === undefined) return;
|
|
170
|
+
const value = number + (add ?? 0);
|
|
171
|
+
if (!Number.isFinite(value)) return;
|
|
172
|
+
if (kind === "integer" && !Number.isInteger(value)) return;
|
|
173
|
+
if (kind === "positiveLength" && value <= 0) return;
|
|
174
|
+
if (kind === "opacity" && value > 1) return;
|
|
175
|
+
if (kind !== "signedLength" && kind !== "integer" && value < 0) return;
|
|
176
|
+
if (choices !== undefined && !choices.includes(value)) return;
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function replace(target: Bag | unknown[], path: OwnedReadonlyArray<Field>, at: number, value: unknown): void {
|
|
181
|
+
const key = path[at];
|
|
182
|
+
const sequence = Array.isArray(target) && typeof key === "number" ? target as OwnedLuaArray<unknown> : undefined;
|
|
183
|
+
let next = value;
|
|
184
|
+
if (at < path.length - 1) {
|
|
185
|
+
const previous = sequence === undefined ? (target as Bag)[key] : sequence[key as number];
|
|
186
|
+
const copy = Array.isArray(previous) ? [...(previous as OwnedLuaArray<unknown>)]
|
|
187
|
+
: previous === undefined ? {} : { ...(previous as OwnedRecord<Bag>) };
|
|
188
|
+
replace(copy, path, at + 1, value);
|
|
189
|
+
next = copy;
|
|
190
|
+
}
|
|
191
|
+
if (sequence === undefined) (target as Bag)[key] = next;
|
|
192
|
+
else sequence[key as number] = next;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function resolveCssTokens<Style extends WithRecipes>(this: void, base: Style, environment?: StyleEnvironment): Result<Style> {
|
|
196
|
+
const recipes = base.styleTokens as OwnedReadonlyArray<CssTokenRecipe> | undefined;
|
|
197
|
+
if (recipes === undefined || environment === undefined) return ok(base);
|
|
198
|
+
let values: Bag | undefined;
|
|
199
|
+
// Token names start with "--". A plain table avoids Lua Map descriptors; false records a missing value.
|
|
200
|
+
const sourced: Record<string, string | false | undefined> = {};
|
|
201
|
+
for (const recipe of recipes) {
|
|
202
|
+
let token = sourced[recipe.token];
|
|
203
|
+
if (token === undefined) {
|
|
204
|
+
const authored = environment(recipe.token);
|
|
205
|
+
if (!authored.ok) return authored;
|
|
206
|
+
token = authored.value ?? false;
|
|
207
|
+
sourced[recipe.token] = token;
|
|
208
|
+
}
|
|
209
|
+
if (token === false || token === recipe.source) continue;
|
|
210
|
+
const parsed = decode(token, recipe);
|
|
211
|
+
const path = recipe.path as OwnedReadonlyArray<Field>;
|
|
212
|
+
if (parsed === undefined) return fail(`Invalid CSS token ${recipe.token} for ${path.join(".")}: ${token.slice(0, 80)}`);
|
|
213
|
+
if (parsed === recipe.fallback) continue;
|
|
214
|
+
values ??= { ...(base as OwnedRecord<Style>) };
|
|
215
|
+
replace(values, path, 0, parsed);
|
|
216
|
+
}
|
|
217
|
+
if (values === undefined) return ok(base);
|
|
218
|
+
const { minWidth, maxWidth, minHeight, maxHeight } = values;
|
|
219
|
+
if (typeof minWidth === "number" && typeof maxWidth === "number" && minWidth > maxWidth) return fail("CSS min-width exceeds max-width");
|
|
220
|
+
if (typeof minHeight === "number" && typeof maxHeight === "number" && minHeight > maxHeight) return fail("CSS min-height exceeds max-height");
|
|
221
|
+
return ok(values as Style);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function mergeCssTokens(this: void, previous: readonly CssTokenRecipe[] | undefined,
|
|
225
|
+
next: WithRecipes): readonly CssTokenRecipe[] | undefined {
|
|
226
|
+
if (previous === undefined) return next.styleTokens;
|
|
227
|
+
const fields = next as Bag;
|
|
228
|
+
const retained = ownedArray<CssTokenRecipe>();
|
|
229
|
+
for (const recipe of previous as OwnedReadonlyArray<CssTokenRecipe>) {
|
|
230
|
+
const path = recipe.path as OwnedReadonlyArray<Field>;
|
|
231
|
+
if (fields[path[0]] === undefined) retained.push(recipe);
|
|
232
|
+
}
|
|
233
|
+
const added = next.styleTokens as OwnedReadonlyArray<CssTokenRecipe> | undefined;
|
|
234
|
+
if (added !== undefined) {
|
|
235
|
+
for (const recipe of added) retained.push(recipe);
|
|
236
|
+
return retained;
|
|
237
|
+
}
|
|
238
|
+
return retained.length > 0 ? retained : undefined;
|
|
239
|
+
}
|
package/src/css-v1.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { RGBA } from "../utils/colors";
|
|
2
|
+
import type { Binding } from "./elements";
|
|
3
|
+
import type { StatePaint } from "./style-states";
|
|
4
|
+
import type { LayoutDisplay, LayoutPosition } from "./flex-layout";
|
|
5
|
+
|
|
6
|
+
export type CssSide = "top" | "right" | "bottom" | "left";
|
|
7
|
+
export type CssOverflow = "hidden" | "scroll";
|
|
8
|
+
export type CssFontWeight = number;
|
|
9
|
+
export type CssTextAlign = "left" | "center" | "right";
|
|
10
|
+
|
|
11
|
+
export interface CssBorderEdge {
|
|
12
|
+
readonly width: number;
|
|
13
|
+
readonly color: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type CssBorder = Readonly<Partial<Record<CssSide, CssBorderEdge>>>;
|
|
17
|
+
|
|
18
|
+
/** @internal Normalized paint for a compiled fixed uniform border. */
|
|
19
|
+
export interface CssBorderPaintPlan {
|
|
20
|
+
readonly width: number;
|
|
21
|
+
readonly literal: string;
|
|
22
|
+
readonly rgba: RGBA;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CssTextShadow {
|
|
26
|
+
readonly x: number;
|
|
27
|
+
readonly y: number;
|
|
28
|
+
readonly color: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface CssTokenRecipe {
|
|
32
|
+
readonly path: readonly (string | number)[];
|
|
33
|
+
readonly token: `--${string}`;
|
|
34
|
+
readonly kind: string;
|
|
35
|
+
readonly fallback: unknown;
|
|
36
|
+
/** @internal Exact compiler-validated token text whose decoded value is `fallback`. */
|
|
37
|
+
readonly source?: string;
|
|
38
|
+
readonly add?: number;
|
|
39
|
+
readonly part?: string | number;
|
|
40
|
+
readonly values?: readonly (string | number)[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CssV1Style {
|
|
44
|
+
/** `static` (default), `relative` (shifted after layout) or `absolute` (out of flow, in the containing block). */
|
|
45
|
+
position?: LayoutPosition;
|
|
46
|
+
top?: Binding<number>;
|
|
47
|
+
right?: Binding<number>;
|
|
48
|
+
bottom?: Binding<number>;
|
|
49
|
+
left?: Binding<number>;
|
|
50
|
+
/** Sides whose margin is `auto` (top, right, bottom, left): an absolute box with both insets on an axis is centered
|
|
51
|
+
* between them, its own size or its content's (as `width: fit-content`). */
|
|
52
|
+
autoMargin?: Binding<readonly [boolean, boolean, boolean, boolean]>;
|
|
53
|
+
border?: CssBorder;
|
|
54
|
+
/** @internal A hint for the final border after class and inline styles are combined. */
|
|
55
|
+
borderPaint?: CssBorderPaintPlan;
|
|
56
|
+
borderRadius?: number;
|
|
57
|
+
backgroundImage?: StatePaint["backgroundImage"];
|
|
58
|
+
fontWeight?: CssFontWeight;
|
|
59
|
+
textAlign?: CssTextAlign;
|
|
60
|
+
textShadow?: CssTextShadow;
|
|
61
|
+
textTransform?: "uppercase" | "lowercase" | "capitalize" | "none";
|
|
62
|
+
textOverflow?: "ellipsis";
|
|
63
|
+
whiteSpace?: "nowrap";
|
|
64
|
+
overflow?: CssOverflow;
|
|
65
|
+
styleTokens?: readonly CssTokenRecipe[];
|
|
66
|
+
/** @internal The flow mode of a live CSS display binding. */
|
|
67
|
+
layoutDisplay?: Binding<LayoutDisplay>;
|
|
68
|
+
}
|
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;
|