@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eugene M.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Kumi
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Kumi lets you write World of Warcraft addons in TypeScript and TSX, the way you would write a web app with Vue or React. Kumi's own compiler turns your code into plain Lua 5.1 that the game runs. There is no runtime interpreter and no JavaScript engine in the game.
|
|
4
|
+
|
|
5
|
+
You get:
|
|
6
|
+
|
|
7
|
+
- **Components in TSX** that update themselves when data changes.
|
|
8
|
+
- **Stores** for state, with saving to SavedVariables built in.
|
|
9
|
+
- **Modules and services** with dependency injection, so a big addon stays organized.
|
|
10
|
+
- **A window with pages** from files in `src/app/routes`.
|
|
11
|
+
- **Plugins** that players turn on or off in the addon list, and parts that load only when needed.
|
|
12
|
+
- **Forms, animations, SCSS styles** and a typed WoW API.
|
|
13
|
+
- **Clear rules**: ESLint and the compiler tell you when code is in the wrong place.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
export const useCounter = defineStore("counter", () => {
|
|
17
|
+
const clicks = ref(0);
|
|
18
|
+
function click() { clicks.value += 1; }
|
|
19
|
+
return { clicks: readonly(clicks), click };
|
|
20
|
+
}, { persist: { pick: ["clicks"] } });
|
|
21
|
+
|
|
22
|
+
export function CounterButton() {
|
|
23
|
+
const counter = useCounter();
|
|
24
|
+
const { clicks } = storeToRefs(counter);
|
|
25
|
+
return <Button label={computed(() => "Clicked " + String(clicks.value) + " times")} onClick={counter.click} />;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Start a project
|
|
30
|
+
|
|
31
|
+
You need Node.js 24 or newer and Rust with Cargo. Kumi also needs Blizzard's UI documentation export to know the WoW API; point `KUMI_WOW_DOCS` at it.
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
npx --yes @overmvp/kumi init MyAddon
|
|
35
|
+
cd MyAddon
|
|
36
|
+
npm install
|
|
37
|
+
npm run check
|
|
38
|
+
npm run build -- --target forever
|
|
39
|
+
npm run link -- "D:/Games/World of Warcraft/_forever_/Interface/AddOns"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Log in, type `/myaddon`, and the addon's window opens. Change some code, run `npm run build` again and `/reload` in the game.
|
|
43
|
+
|
|
44
|
+
## Learn Kumi
|
|
45
|
+
|
|
46
|
+
Read the guides in order the first time:
|
|
47
|
+
|
|
48
|
+
1. [Getting started](docs/getting-started.md): create, build and run an addon.
|
|
49
|
+
2. [Project structure](docs/project-structure.md): where each kind of code goes.
|
|
50
|
+
3. [Modules and services](docs/modules-and-services.md)
|
|
51
|
+
4. [Stores](docs/stores.md): state, saving, sharing between modules.
|
|
52
|
+
5. [Components](docs/components.md)
|
|
53
|
+
6. [Reactivity and hooks](docs/reactivity-and-hooks.md)
|
|
54
|
+
7. [Styling](docs/styling.md)
|
|
55
|
+
8. [Forms](docs/forms.md)
|
|
56
|
+
9. [Animation](docs/animation.md)
|
|
57
|
+
10. [Windows and pages](docs/windows-and-pages.md)
|
|
58
|
+
11. [Plugins](docs/plugins.md)
|
|
59
|
+
12. [The WoW API](docs/wow-api.md): calling the game, secret values, secure buttons.
|
|
60
|
+
13. [Configuration and CLI](docs/configuration.md)
|
|
61
|
+
14. [Rules](docs/rules.md): what ESLint and the compiler enforce, and why.
|
|
62
|
+
15. [Advanced](docs/advanced.md): low-level views, secure builders, native hooks.
|
|
63
|
+
|
|
64
|
+
Working on Kumi itself? See [Contributing](CONTRIBUTING.md) and [the compiler notes](docs/compiler.md).
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
2
|
+
import { ownedMap } from "../src/owned-collections";
|
|
3
|
+
import { fail, type Failure } from "../src/result";
|
|
4
|
+
import { easeProgress } from "./ease";
|
|
5
|
+
import type { Ease } from "./spec";
|
|
6
|
+
|
|
7
|
+
type RGBA = [red: number, green: number, blue: number, alpha: number];
|
|
8
|
+
type Color = Readonly<RGBA>;
|
|
9
|
+
|
|
10
|
+
export interface ColorTransitionOptions<Key extends object> {
|
|
11
|
+
now(this: void): number;
|
|
12
|
+
maxStep: number;
|
|
13
|
+
paint(this: void, key: Key, value: Color): void | Failure;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ColorTransitions<Key extends object> {
|
|
17
|
+
start(this: void, key: Key, from: Color, to: Color, duration: number, ease: Ease): Failure | undefined;
|
|
18
|
+
retarget(this: void, key: Key, to: Color): Failure | undefined;
|
|
19
|
+
running(this: void, key: Key): boolean;
|
|
20
|
+
/** The source before the first step, then the last successfully painted value. */
|
|
21
|
+
current(this: void, key: Key): Color | undefined;
|
|
22
|
+
cancel(this: void, key: Key): void;
|
|
23
|
+
finish(this: void, key: Key): Failure | undefined;
|
|
24
|
+
flush(this: void): Failure | undefined;
|
|
25
|
+
count(this: void): number;
|
|
26
|
+
/** @internal Advances legacy deterministic frame probes using their supplied frame interval. */
|
|
27
|
+
advance(this: void, elapsed: number): Failure | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface Track<Key> {
|
|
31
|
+
readonly key: Key;
|
|
32
|
+
readonly from: RGBA;
|
|
33
|
+
readonly to: RGBA;
|
|
34
|
+
readonly drawn: RGBA;
|
|
35
|
+
readonly sample: RGBA;
|
|
36
|
+
duration: number;
|
|
37
|
+
ease: Ease;
|
|
38
|
+
elapsed: number;
|
|
39
|
+
lastFrame: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function copy(target: RGBA, source: Color) {
|
|
43
|
+
target[0] = source[0];
|
|
44
|
+
target[1] = source[1];
|
|
45
|
+
target[2] = source[2];
|
|
46
|
+
target[3] = source[3];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function same(left: Color, right: Color) {
|
|
50
|
+
return left[0] === right[0] && left[1] === right[1] && left[2] === right[2] && left[3] === right[3];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function finite(color: Color) {
|
|
54
|
+
return Number.isFinite(color[0]) && Number.isFinite(color[1])
|
|
55
|
+
&& Number.isFinite(color[2]) && Number.isFinite(color[3]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Interpolate ordinary RGBA channels on the scope's existing frame budget. */
|
|
59
|
+
export function createColorTransitions<Key extends object>(this: void, scope: RuntimeScope,
|
|
60
|
+
options: ColorTransitionOptions<Key>): ColorTransitions<Key> {
|
|
61
|
+
const { now, maxStep, paint } = options;
|
|
62
|
+
const { frameJobs } = scope;
|
|
63
|
+
const active = ownedMap<Key, Track<Key>>();
|
|
64
|
+
let painting: Track<Key> | undefined;
|
|
65
|
+
const job = { lane: "normal", label: "Color transition" } as const;
|
|
66
|
+
|
|
67
|
+
function retire(track: Track<Key>) {
|
|
68
|
+
if (active.get(track.key) === track) active.delete(track.key);
|
|
69
|
+
frameJobs.cancel(track);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function draw(key: Key, value: Color): Failure | undefined {
|
|
73
|
+
const written = scope.protect(() => paint(key, value));
|
|
74
|
+
return written.ok ? written.value ?? undefined : written;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function step(track: Track<Key>, elapsed: number): Failure | undefined {
|
|
78
|
+
if (elapsed === 0) return;
|
|
79
|
+
track.elapsed += Math.min(elapsed, maxStep);
|
|
80
|
+
const progress = Math.min(1, track.elapsed / track.duration);
|
|
81
|
+
if (progress === 1) {
|
|
82
|
+
retire(track);
|
|
83
|
+
return draw(track.key, track.to);
|
|
84
|
+
}
|
|
85
|
+
const eased = easeProgress(track.ease, progress);
|
|
86
|
+
for (let index = 0; index < 4; index++) {
|
|
87
|
+
track.sample[index] = track.from[index] * (1 - eased) + track.to[index] * eased;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const previous = painting;
|
|
91
|
+
painting = track;
|
|
92
|
+
const failure = draw(track.key, track.sample);
|
|
93
|
+
painting = previous;
|
|
94
|
+
if (failure !== undefined) retire(track);
|
|
95
|
+
else copy(track.drawn, track.sample);
|
|
96
|
+
return failure;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function start(key: Key, from: Color, to: Color, duration: number, ease: Ease) {
|
|
100
|
+
if (!scope.isActive()) return;
|
|
101
|
+
if (!Number.isFinite(maxStep) || maxStep <= 0) return fail("Color transition maximum step must be positive and finite");
|
|
102
|
+
if (!Number.isFinite(duration) || duration < 0) return fail("Color transition duration must be nonnegative and finite");
|
|
103
|
+
if (!finite(from) || !finite(to)) return fail("Color transition channels must be finite");
|
|
104
|
+
const current = active.get(key);
|
|
105
|
+
if (duration === 0) {
|
|
106
|
+
if (current !== undefined) retire(current);
|
|
107
|
+
return draw(key, to);
|
|
108
|
+
}
|
|
109
|
+
if (current !== undefined && same(current.to, to)) return;
|
|
110
|
+
const time = scope.protect(now);
|
|
111
|
+
if (!time.ok) return time;
|
|
112
|
+
if (!Number.isFinite(time.value)) return fail("Color transition clock must be finite");
|
|
113
|
+
if (current !== undefined && current !== painting) {
|
|
114
|
+
copy(current.from, current.drawn);
|
|
115
|
+
copy(current.to, to);
|
|
116
|
+
current.duration = duration;
|
|
117
|
+
current.ease = ease;
|
|
118
|
+
current.elapsed = 0;
|
|
119
|
+
current.lastFrame = time.value;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const source = current?.drawn ?? from;
|
|
124
|
+
if (current !== undefined) retire(current);
|
|
125
|
+
if (same(source, to)) return draw(key, to);
|
|
126
|
+
const track: Track<Key> = {
|
|
127
|
+
key, from: [...source], to: [...to], drawn: [...source], sample: [...source],
|
|
128
|
+
duration, ease, elapsed: 0, lastFrame: time.value,
|
|
129
|
+
};
|
|
130
|
+
active.set(key, track);
|
|
131
|
+
frameJobs.queue(track, () => {
|
|
132
|
+
const time = scope.protect(now);
|
|
133
|
+
if (!time.ok) {
|
|
134
|
+
retire(track);
|
|
135
|
+
return time;
|
|
136
|
+
}
|
|
137
|
+
const elapsed = time.value - track.lastFrame;
|
|
138
|
+
if (!Number.isFinite(elapsed) || elapsed < 0) {
|
|
139
|
+
retire(track);
|
|
140
|
+
return fail("Color transition clock must advance by a finite interval");
|
|
141
|
+
}
|
|
142
|
+
track.lastFrame = time.value;
|
|
143
|
+
return step(track, elapsed) ?? (active.get(key) === track);
|
|
144
|
+
}, job);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function finish(key: Key) {
|
|
148
|
+
const track = active.get(key);
|
|
149
|
+
if (track === undefined) return;
|
|
150
|
+
retire(track);
|
|
151
|
+
return draw(key, track.to);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
scope.onDispose(() => {
|
|
155
|
+
for (const [, track] of active) frameJobs.cancel(track);
|
|
156
|
+
active.clear();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
start,
|
|
161
|
+
retarget: (key, to) => {
|
|
162
|
+
const track = active.get(key);
|
|
163
|
+
if (track !== undefined) return start(key, track.drawn, to, track.duration, track.ease);
|
|
164
|
+
},
|
|
165
|
+
running: key => active.has(key),
|
|
166
|
+
current: key => active.get(key)?.drawn,
|
|
167
|
+
cancel: key => {
|
|
168
|
+
const track = active.get(key);
|
|
169
|
+
if (track !== undefined) retire(track);
|
|
170
|
+
},
|
|
171
|
+
finish,
|
|
172
|
+
flush: () => {
|
|
173
|
+
let failure: Failure | undefined;
|
|
174
|
+
for (const key of [...active.keys()]) {
|
|
175
|
+
const result = finish(key);
|
|
176
|
+
failure ??= result;
|
|
177
|
+
}
|
|
178
|
+
return failure;
|
|
179
|
+
},
|
|
180
|
+
count: () => active.size,
|
|
181
|
+
advance: elapsed => {
|
|
182
|
+
if (!Number.isFinite(elapsed) || elapsed < 0) return fail("Color transition interval must be nonnegative and finite");
|
|
183
|
+
let failure: Failure | undefined;
|
|
184
|
+
const time = scope.protect(now);
|
|
185
|
+
if (!time.ok) return time;
|
|
186
|
+
if (!Number.isFinite(time.value)) return fail("Color transition clock must be finite");
|
|
187
|
+
for (const track of [...active.values()]) {
|
|
188
|
+
if (active.get(track.key) !== track) continue;
|
|
189
|
+
track.lastFrame = time.value;
|
|
190
|
+
const result = step(track, elapsed);
|
|
191
|
+
failure ??= result;
|
|
192
|
+
}
|
|
193
|
+
return failure;
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { fail, ok, type Result } from "@kumi/core";
|
|
2
|
+
import { ownedArray, type OwnedArray, type OwnedReadonlyArray, type OwnedRecord } from "../src/owned-collections";
|
|
3
|
+
import type { AnchorPoint, AnimationSpec, AnimationStep, Ease, RegionAnimation, ScaleValue } from "./spec";
|
|
4
|
+
|
|
5
|
+
/** One keyframe of a looping cycle: time in seconds within the period and the value at that time. */
|
|
6
|
+
export interface CycleKey<Value = number> {
|
|
7
|
+
t: number;
|
|
8
|
+
v: Value;
|
|
9
|
+
/** Easing towards the next key. */
|
|
10
|
+
ease?: Ease;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A looping keyframe cycle. Positions are absolute offsets, scale is an absolute factor and
|
|
15
|
+
* turn is an absolute angle in degrees. `phase` starts the loop at that time of the period.
|
|
16
|
+
*/
|
|
17
|
+
export interface AnimationCycle {
|
|
18
|
+
period: number;
|
|
19
|
+
phase?: number;
|
|
20
|
+
x?: readonly CycleKey[];
|
|
21
|
+
y?: readonly CycleKey[];
|
|
22
|
+
alpha?: readonly CycleKey[];
|
|
23
|
+
scale?: readonly CycleKey<ScaleValue>[];
|
|
24
|
+
turn?: readonly CycleKey[];
|
|
25
|
+
origin?: AnchorPoint;
|
|
26
|
+
/** Skip segments whose value does not change. Alpha keeps every segment because it is absolute. */
|
|
27
|
+
lean?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type Interpolate<Value> = (this: void, from: Value, to: Value, share: number) => Value;
|
|
31
|
+
interface Segment<Value> { from: Value; to: Value; delay: number; duration: number; ease: Ease }
|
|
32
|
+
|
|
33
|
+
const phaseEpsilon = 1e-6;
|
|
34
|
+
|
|
35
|
+
export function scaleFactors(value: ScaleValue): readonly [number, number] {
|
|
36
|
+
return typeof value === "number" ? [value, value] : value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function lerpNumber(this: void, from: number, to: number, share: number): number {
|
|
40
|
+
return from + (to - from) * share;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function lerpScale(this: void, from: ScaleValue, to: ScaleValue, share: number): ScaleValue {
|
|
44
|
+
if (typeof from === "number" && typeof to === "number") return lerpNumber(from, to, share);
|
|
45
|
+
const [fromX, fromY] = scaleFactors(from);
|
|
46
|
+
const [toX, toY] = scaleFactors(to);
|
|
47
|
+
return [lerpNumber(fromX, toX, share), lerpNumber(fromY, toY, share)];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function unchanged(from: ScaleValue, to: ScaleValue) {
|
|
51
|
+
const [fromX, fromY] = scaleFactors(from);
|
|
52
|
+
const [toX, toY] = scaleFactors(to);
|
|
53
|
+
return Math.abs(fromX - toX) < 1e-9 && Math.abs(fromY - toY) < 1e-9;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Insert a key at the phase so the baked loop can start there. An in-out ease splits into in and out. */
|
|
57
|
+
function withPhase<Value>(source: readonly CycleKey<Value>[], phase: number, period: number, interpolate: Interpolate<Value>) {
|
|
58
|
+
const records = source as OwnedReadonlyArray<OwnedRecord<CycleKey<Value>>>;
|
|
59
|
+
const keys = records.map<CycleKey<Value>>(key => ({ ...key })) as OwnedArray<CycleKey<Value>>;
|
|
60
|
+
if (keys.some(key => Math.abs(key.t - phase) < phaseEpsilon)) return keys;
|
|
61
|
+
for (let index = 0; index < keys.length; index++) {
|
|
62
|
+
const from = keys[index];
|
|
63
|
+
const to = keys[(index + 1) % keys.length];
|
|
64
|
+
const end = index === keys.length - 1 ? period : to.t;
|
|
65
|
+
if (phase <= from.t || phase >= end) continue;
|
|
66
|
+
const value = from.v === to.v ? from.v : interpolate(from.v, to.v, (phase - from.t) / (end - from.t));
|
|
67
|
+
const ease = from.ease;
|
|
68
|
+
if (ease === "inOut") from.ease = "in";
|
|
69
|
+
keys.splice(index + 1, 0, { t: phase, v: value, ease: ease === "inOut" ? "out" : ease });
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
return keys;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function bakeChannel<Value>(cycle: AnimationCycle, source: readonly CycleKey<Value>[] | undefined, interpolate: Interpolate<Value>,
|
|
76
|
+
same: (this: void, from: Value, to: Value) => boolean, keepUnchanged: boolean): OwnedReadonlyArray<Segment<Value>> {
|
|
77
|
+
if (source === undefined || (source as OwnedReadonlyArray<CycleKey<Value>>).length === 0) return ownedArray<Segment<Value>>();
|
|
78
|
+
const phase = cycle.phase ?? 0;
|
|
79
|
+
const keys = withPhase(source, phase, cycle.period, interpolate);
|
|
80
|
+
let first = -1;
|
|
81
|
+
for (let index = 0; index < keys.length; index++) {
|
|
82
|
+
if (Math.abs(keys[index].t - phase) < phaseEpsilon) first = index;
|
|
83
|
+
}
|
|
84
|
+
if (first < 0) return ownedArray<Segment<Value>>();
|
|
85
|
+
const segments = ownedArray<Segment<Value>>();
|
|
86
|
+
let delay = 0;
|
|
87
|
+
for (let step = 0; step < keys.length; step++) {
|
|
88
|
+
const index = (first + step) % keys.length;
|
|
89
|
+
const from = keys[index];
|
|
90
|
+
const to = keys[(index + 1) % keys.length];
|
|
91
|
+
const duration = (index === keys.length - 1 ? cycle.period : to.t) - from.t;
|
|
92
|
+
// The final segment always stays so the native group keeps the loop's full period.
|
|
93
|
+
if (!cycle.lean || keepUnchanged || step === keys.length - 1 || !same(from.v, to.v)) {
|
|
94
|
+
segments.push({ from: from.v, to: to.v, delay, duration, ease: from.ease ?? "linear" });
|
|
95
|
+
}
|
|
96
|
+
delay += duration;
|
|
97
|
+
}
|
|
98
|
+
return segments;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function validKeys(keys: readonly CycleKey<unknown>[] | undefined, period: number) {
|
|
102
|
+
if (keys === undefined) return true;
|
|
103
|
+
let previous = -1;
|
|
104
|
+
for (const key of keys as OwnedReadonlyArray<CycleKey<unknown>>) {
|
|
105
|
+
if (!Number.isFinite(key.t) || key.t < 0 || key.t >= period || key.t <= previous) return false;
|
|
106
|
+
previous = key.t;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Bake a keyframe cycle into native animation steps on one looping group.
|
|
113
|
+
* A cycle without `turn` animates any region; with `turn` it needs a texture.
|
|
114
|
+
*/
|
|
115
|
+
export function cycleAnimation(cycle: AnimationCycle & { turn?: undefined }): Result<RegionAnimation>;
|
|
116
|
+
export function cycleAnimation(cycle: AnimationCycle): Result<AnimationSpec>;
|
|
117
|
+
export function cycleAnimation(cycle: AnimationCycle): Result<AnimationSpec> {
|
|
118
|
+
const { period } = cycle;
|
|
119
|
+
if (!Number.isFinite(period) || period <= 0) return fail("A cycle needs a positive period");
|
|
120
|
+
const phase = cycle.phase ?? 0;
|
|
121
|
+
if (!Number.isFinite(phase) || phase < 0 || phase >= period) return fail("A cycle phase must lie within its period");
|
|
122
|
+
if (!validKeys(cycle.x, period) || !validKeys(cycle.y, period) || !validKeys(cycle.alpha, period)
|
|
123
|
+
|| !validKeys(cycle.scale, period) || !validKeys(cycle.turn, period)) {
|
|
124
|
+
return fail("Cycle keys need increasing times within the period");
|
|
125
|
+
}
|
|
126
|
+
const origin = cycle.origin === undefined ? undefined : { point: cycle.origin };
|
|
127
|
+
const steps: AnimationStep[] = [];
|
|
128
|
+
const timing = (segment: Segment<unknown>) => ({ at: segment.delay, duration: segment.duration, ease: segment.ease });
|
|
129
|
+
const sameNumber = (from: number, to: number) => Math.abs(from - to) < 1e-9;
|
|
130
|
+
|
|
131
|
+
for (const segment of bakeChannel(cycle, cycle.x, lerpNumber, sameNumber, false)) {
|
|
132
|
+
steps.push({ ...timing(segment), move: [segment.to - segment.from, 0] });
|
|
133
|
+
}
|
|
134
|
+
for (const segment of bakeChannel(cycle, cycle.y, lerpNumber, sameNumber, false)) {
|
|
135
|
+
steps.push({ ...timing(segment), move: [0, segment.to - segment.from] });
|
|
136
|
+
}
|
|
137
|
+
for (const segment of bakeChannel(cycle, cycle.alpha, lerpNumber, sameNumber, true)) {
|
|
138
|
+
steps.push({ ...timing(segment), alpha: [segment.from, segment.to] });
|
|
139
|
+
}
|
|
140
|
+
for (const segment of bakeChannel(cycle, cycle.scale, lerpScale, unchanged, false)) {
|
|
141
|
+
// Native scale steps multiply, so each segment scales relative to where the previous one ended.
|
|
142
|
+
const [fromX, fromY] = scaleFactors(segment.from);
|
|
143
|
+
const [toX, toY] = scaleFactors(segment.to);
|
|
144
|
+
steps.push({ ...timing(segment), scale: [1, [toX / fromX, toY / fromY]], origin });
|
|
145
|
+
}
|
|
146
|
+
for (const segment of bakeChannel(cycle, cycle.turn, lerpNumber, sameNumber, false)) {
|
|
147
|
+
steps.push({ ...timing(segment), rotate: segment.to - segment.from, origin });
|
|
148
|
+
}
|
|
149
|
+
if (steps.length === 0) return fail("A cycle needs at least one channel with keys");
|
|
150
|
+
return ok({ steps, loop: "repeat" });
|
|
151
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Ease } from "./spec";
|
|
2
|
+
|
|
3
|
+
/** Native AnimationGroup smoothing names. */
|
|
4
|
+
export type NativeSmoothing = "NONE" | "IN" | "OUT" | "IN_OUT";
|
|
5
|
+
|
|
6
|
+
const smoothing: Readonly<Record<Ease, NativeSmoothing>> = { linear: "NONE", in: "IN", out: "OUT", inOut: "IN_OUT" };
|
|
7
|
+
const easeNames: Readonly<Record<NativeSmoothing, Ease>> = { NONE: "linear", IN: "in", OUT: "out", IN_OUT: "inOut" };
|
|
8
|
+
|
|
9
|
+
export function nativeSmoothing(ease: Ease): NativeSmoothing {
|
|
10
|
+
return smoothing[ease];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function easeFromSmoothing(value: NativeSmoothing): Ease {
|
|
14
|
+
return easeNames[value];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Cubic curves for frame-driven tweens. They match the Lua Motion engine and the motion spec,
|
|
19
|
+
* so a tween and a native animation with the same name feel alike.
|
|
20
|
+
*/
|
|
21
|
+
export function easeProgress(ease: Ease, progress: number): number {
|
|
22
|
+
const t = progress <= 0 ? 0 : progress >= 1 ? 1 : progress;
|
|
23
|
+
if (ease === "linear") return t;
|
|
24
|
+
if (ease === "in") return t * t * t;
|
|
25
|
+
if (ease === "out") return 1 - (1 - t) * (1 - t) * (1 - t);
|
|
26
|
+
if (t < 0.5) return 4 * t * t * t;
|
|
27
|
+
const rest = -2 * t + 2;
|
|
28
|
+
return 1 - rest * rest * rest / 2;
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { finalAlpha, planAnimation, stepKind } from "./spec";
|
|
2
|
+
export type { AlphaStep, AnchorPoint, AnimationPlan, AnimationSpec, AnimationStep, Ease, FlipBook, FlipBookStep, MoveStep, Origin, PlannedStep,
|
|
3
|
+
Range, RegionAnimation, RegionStep, RotateStep, ScaleStep, ScaleValue, StepKind, StepPosition, TextureStep } from "./spec";
|
|
4
|
+
export { cycleAnimation, scaleFactors } from "./cycle";
|
|
5
|
+
export type { AnimationCycle, CycleKey } from "./cycle";
|
|
6
|
+
export { easeFromSmoothing, easeProgress, nativeSmoothing } from "./ease";
|
|
7
|
+
export type { NativeSmoothing } from "./ease";
|
|
8
|
+
import * as presets from "./presets";
|
|
9
|
+
export { presets };
|
|
10
|
+
export type { AttentionOptions, BeaconOptions, BreatheOptions, BurstOptions, DriftOptions, EnterOptions, ExitOptions, FadeOptions, FlashOptions,
|
|
11
|
+
FloatOptions, GlimmerOptions, HeartbeatOptions, HopOptions, PopOptions, PulseOptions, RippleOptions, ShakeOptions, Side, SlideOptions,
|
|
12
|
+
SpinOptions } from "./presets";
|
|
13
|
+
export { createColorTransitions, type ColorTransitionOptions, type ColorTransitions } from "./color-transition";
|