@overmvp/kumi 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -6
- package/animation/index.ts +4 -0
- package/animation/motion-policy.ts +20 -0
- package/animation/slide.ts +61 -0
- package/animation/spring.ts +75 -0
- package/animation/staggered-reveal.ts +34 -0
- package/builder/css-gradients.mjs +74 -0
- package/builder/css-mask-assets.mjs +52 -0
- package/builder/css-mask-assets.test.mjs +31 -0
- package/builder/css-v1.mjs +127 -23
- package/builder/css-v1.test.mjs +82 -2
- package/builder/link-addon-package.mjs +47 -6
- package/builder/module-declarations.test.mjs +9 -18
- package/builder/native-kernels.mjs +1 -1
- package/builder/src/compiler.rs +205 -8
- package/builder/src/lua_upvalues.rs +641 -0
- package/builder/src/main.rs +20 -5
- package/builder/src/native_ir.rs +1 -1
- package/builder/src/native_signal.rs +46 -10
- package/builder/src/numbers.lua +14 -0
- package/builder/src/project-front.mjs +385 -34
- package/builder/src/routes.rs +11 -14
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -1
- package/builder/src/ts-lower.mjs +2 -2
- package/builder/src/wow-reads.lua +22 -0
- package/builder/style-modules.mjs +111 -0
- package/builder/style-modules.test.mjs +24 -0
- package/builder/style-states.mjs +6 -4
- package/config.ts +56 -14
- package/eslint.mjs +74 -0
- package/form/index.ts +15 -11
- package/package.json +11 -7
- package/router/index.ts +10 -2
- package/router/link.tsx +32 -0
- package/router/navigation.ts +22 -0
- package/router/router-view.ts +134 -0
- package/scripts/addon-build.mjs +377 -0
- package/scripts/addon-project.mjs +89 -0
- package/scripts/kumi-cli.mjs +52 -17
- package/scripts/link-addons.mjs +12 -2
- package/src/bindings.ts +12 -6
- package/src/context.ts +31 -7
- package/src/css-tokens.ts +27 -13
- package/src/css-v1.ts +13 -0
- package/src/elements.ts +35 -0
- package/src/flex-layout.ts +26 -5
- package/src/frame-scheduler.ts +6 -2
- package/src/index.ts +2 -1
- package/src/jsx-runtime.ts +8 -1
- package/src/keyed-list.ts +17 -11
- package/src/module-ui.ts +163 -0
- package/src/module.ts +51 -8
- package/src/owned-collections.ts +8 -0
- package/src/providers.ts +7 -1
- package/src/reactive-scope.ts +3 -3
- package/src/reactivity.ts +42 -8
- package/src/result.ts +6 -0
- package/src/signal-kernel.ts +35 -2
- package/src/style-classes.ts +22 -1
- package/src/style-states.ts +13 -6
- package/state/index.ts +6 -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.ts +2 -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 +42 -7
- package/templates/addon/eslint.config.mjs +3 -9
- package/templates/addon/gitignore +1 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +4 -5
- 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.css +90 -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.css +103 -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.css +23 -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.css +13 -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.css +91 -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 +49 -10
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +244 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +38 -0
- package/wow/animation.ts +3 -14
- package/wow/app-ui.ts +230 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-background-image.ts +75 -0
- package/wow/css-box.ts +46 -10
- package/wow/css-image-mask.ts +32 -0
- package/wow/css-surfaces.ts +295 -43
- package/wow/cursor.ts +45 -0
- package/wow/element-events.ts +33 -13
- package/wow/frame-access.ts +23 -1
- package/wow/frame-timing.ts +13 -0
- package/wow/heal-prediction.ts +2 -4
- package/wow/hooks.ts +133 -0
- package/wow/index.ts +19 -4
- package/wow/layout-view.ts +44 -23
- package/wow/locale-font.ts +15 -0
- package/wow/module-replacements.ts +103 -0
- package/wow/native.ts +18 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/pointer-click.ts +35 -0
- package/wow/protect.ts +27 -3
- package/wow/protected-view.ts +139 -0
- package/wow/range-art.ts +7 -0
- package/wow/readable-api.ts +120 -0
- package/wow/rounded-texture.ts +38 -6
- package/wow/saved-variables.ts +67 -18
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +31 -8
- package/wow/state-paint.ts +5 -14
- package/wow/texture-fill.ts +10 -0
- package/wow/unit-cast.ts +6 -4
- package/wow/view.ts +458 -228
- package/templates/addon/__ADDON_NAME__.toc +0 -4
- package/templates/addon/scripts/build.mjs +0 -25
- package/templates/addon/src/app/main.tsx +0 -13
package/README.md
CHANGED
|
@@ -1,15 +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
4
|
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
7
35
|
cd MyAddon
|
|
8
36
|
npm install
|
|
9
37
|
npm run check
|
|
10
|
-
npm run build
|
|
38
|
+
npm run build -- --target forever
|
|
39
|
+
npm run link -- "D:/Games/World of Warcraft/_forever_/Interface/AddOns"
|
|
11
40
|
```
|
|
12
41
|
|
|
13
|
-
|
|
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
|
|
14
67
|
|
|
15
|
-
|
|
68
|
+
MIT
|
package/animation/index.ts
CHANGED
|
@@ -11,3 +11,7 @@ export type { AttentionOptions, BeaconOptions, BreatheOptions, BurstOptions, Dri
|
|
|
11
11
|
FloatOptions, GlimmerOptions, HeartbeatOptions, HopOptions, PopOptions, PulseOptions, RippleOptions, ShakeOptions, Side, SlideOptions,
|
|
12
12
|
SpinOptions } from "./presets";
|
|
13
13
|
export { createColorTransitions, type ColorTransitionOptions, type ColorTransitions } from "./color-transition";
|
|
14
|
+
export { configureAnimations, isReducedMotion, type AnimationDefaults, type MotionMode } from "./motion-policy";
|
|
15
|
+
export { useSlide, type SlideValueOptions } from "./slide";
|
|
16
|
+
export { useStaggeredReveal, type StaggeredReveal, type StaggeredRevealOptions } from "./staggered-reveal";
|
|
17
|
+
export { useSpring, type SpringOptions } from "./spring";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ref } from "../src/reactivity";
|
|
2
|
+
|
|
3
|
+
/** Reduced motion skips one-shot motion and freezes looping native animations. */
|
|
4
|
+
export type MotionMode = "full" | "reduced";
|
|
5
|
+
|
|
6
|
+
export interface AnimationDefaults {
|
|
7
|
+
/** Read when an animation has no `motion` option of its own. */
|
|
8
|
+
motion?: (this: void) => MotionMode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const defaultMotion = ref<AnimationDefaults["motion"]>(undefined);
|
|
12
|
+
|
|
13
|
+
/** Set application-wide defaults for native animations and reactive slides. */
|
|
14
|
+
export function configureAnimations(this: void, options: AnimationDefaults): void {
|
|
15
|
+
defaultMotion.value = options.motion;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isReducedMotion(this: void, motion?: AnimationDefaults["motion"]): boolean {
|
|
19
|
+
return (motion ?? defaultMotion.value)?.() === "reduced";
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { currentScope } from "../src/reactive-scope";
|
|
2
|
+
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
3
|
+
import { fail } from "../src/result";
|
|
4
|
+
import { easeProgress } from "./ease";
|
|
5
|
+
import { isReducedMotion, type AnimationDefaults } from "./motion-policy";
|
|
6
|
+
import type { Ease } from "./spec";
|
|
7
|
+
|
|
8
|
+
export interface SlideValueOptions {
|
|
9
|
+
/** Seconds to reach a new target. Defaults to 0.14. */
|
|
10
|
+
readonly duration?: number;
|
|
11
|
+
readonly ease?: Ease;
|
|
12
|
+
/** Overrides the application-wide motion preference for this slide. */
|
|
13
|
+
readonly motion?: AnimationDefaults["motion"];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Follow a reactive coordinate, continuing from the current position when the target changes. */
|
|
17
|
+
export function useSlide(this: void, read: (this: void) => number,
|
|
18
|
+
{ duration = 0.14, ease = "out", motion }: SlideValueOptions = {}): ReadonlyRef<number> {
|
|
19
|
+
const scope = currentScope();
|
|
20
|
+
if (scope === undefined || !scope.isActive()) throw new Error("useSlide requires an active scope");
|
|
21
|
+
const intervalMs = duration * 1000;
|
|
22
|
+
if (!Number.isFinite(intervalMs) || intervalMs < 0) throw new Error("Slide duration must be nonnegative and finite");
|
|
23
|
+
|
|
24
|
+
const initial = read();
|
|
25
|
+
if (!Number.isFinite(initial)) throw new Error("Slide target must be finite");
|
|
26
|
+
const value = ref(initial);
|
|
27
|
+
const frames = scope.frameJobs;
|
|
28
|
+
const nowMs = frames.nowMs;
|
|
29
|
+
const job = {};
|
|
30
|
+
let target = initial;
|
|
31
|
+
let from = initial;
|
|
32
|
+
let started = 0;
|
|
33
|
+
|
|
34
|
+
function step(this: void) {
|
|
35
|
+
const now = nowMs?.();
|
|
36
|
+
if (now === undefined || !Number.isFinite(now) || isReducedMotion(motion) || now - started >= intervalMs) {
|
|
37
|
+
value.value = target;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
value.value = from + (target - from) * easeProgress(ease, (now - started) / intervalMs);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const watched = scope.watch(() => ({ next: read(), reduced: isReducedMotion(motion) }), ({ next, reduced }) => {
|
|
45
|
+
if (!Number.isFinite(next)) return fail("Slide target must be finite");
|
|
46
|
+
if (next === target && !reduced) return;
|
|
47
|
+
frames.cancel(job);
|
|
48
|
+
target = next;
|
|
49
|
+
from = value.value;
|
|
50
|
+
const now = nowMs?.();
|
|
51
|
+
if (reduced || intervalMs === 0 || from === target || now === undefined || !Number.isFinite(now)) {
|
|
52
|
+
value.value = target;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
started = now;
|
|
56
|
+
frames.queue(job, step, { label: "Slide" });
|
|
57
|
+
});
|
|
58
|
+
if (!watched.ok) throw new Error(watched.reason);
|
|
59
|
+
scope.onDispose(() => { frames.cancel(job); });
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { currentScope } from "../src/reactive-scope";
|
|
2
|
+
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
3
|
+
import { fail } from "../src/result";
|
|
4
|
+
import { isReducedMotion, type AnimationDefaults } from "./motion-policy";
|
|
5
|
+
|
|
6
|
+
export interface SpringOptions {
|
|
7
|
+
/** Natural frequency in hertz. Defaults to 4. */
|
|
8
|
+
readonly frequency?: number;
|
|
9
|
+
/** Distance below which a nearly stationary spring settles. Defaults to 0.01. */
|
|
10
|
+
readonly precision?: number;
|
|
11
|
+
readonly motion?: AnimationDefaults["motion"];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Follow a reactive target with a critically damped spring. Retargeting preserves velocity. */
|
|
15
|
+
export function useSpring(this: void, read: (this: void) => number,
|
|
16
|
+
{ frequency = 4, precision = 0.01, motion }: SpringOptions = {}): ReadonlyRef<number> {
|
|
17
|
+
const scope = currentScope();
|
|
18
|
+
if (scope === undefined || !scope.isActive()) throw new Error("useSpring requires an active scope");
|
|
19
|
+
const rate = 2 * Math.PI * frequency;
|
|
20
|
+
if (!Number.isFinite(rate) || rate <= 0) throw new Error("Spring frequency must be positive and finite");
|
|
21
|
+
if (!Number.isFinite(precision) || precision <= 0) throw new Error("Spring precision must be positive and finite");
|
|
22
|
+
let target = read();
|
|
23
|
+
if (!Number.isFinite(target)) throw new Error("Spring target must be finite");
|
|
24
|
+
|
|
25
|
+
const value = ref(target);
|
|
26
|
+
const frames = scope.frameJobs;
|
|
27
|
+
const nowMs = frames.nowMs;
|
|
28
|
+
const job = {};
|
|
29
|
+
let velocity = 0;
|
|
30
|
+
let previous = 0;
|
|
31
|
+
|
|
32
|
+
function settle() {
|
|
33
|
+
velocity = 0;
|
|
34
|
+
value.value = target;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function step(this: void) {
|
|
38
|
+
const now = nowMs?.();
|
|
39
|
+
if (now === undefined || !Number.isFinite(now) || isReducedMotion(motion)) return settle();
|
|
40
|
+
const elapsed = Math.max(0, (now - previous) / 1000);
|
|
41
|
+
previous = now;
|
|
42
|
+
if (elapsed === 0) return true;
|
|
43
|
+
|
|
44
|
+
// Closed-form critical damping preserves the same trajectory across different frame intervals.
|
|
45
|
+
const distance = value.value - target;
|
|
46
|
+
const tangent = (velocity + rate * distance) * elapsed;
|
|
47
|
+
const decay = Math.exp(-rate * elapsed);
|
|
48
|
+
const displacement = (distance + tangent) * decay;
|
|
49
|
+
const nextVelocity = (velocity - rate * tangent) * decay;
|
|
50
|
+
if (!Number.isFinite(displacement) || !Number.isFinite(nextVelocity)
|
|
51
|
+
|| Math.abs(displacement) <= precision && Math.abs(nextVelocity) / rate <= precision) return settle();
|
|
52
|
+
|
|
53
|
+
velocity = nextVelocity;
|
|
54
|
+
value.value = target + displacement;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const watched = scope.watch(() => ({ next: read(), reduced: isReducedMotion(motion) }), ({ next, reduced }) => {
|
|
59
|
+
if (!Number.isFinite(next)) return fail("Spring target must be finite");
|
|
60
|
+
if (next === target && !reduced) return;
|
|
61
|
+
target = next;
|
|
62
|
+
const now = nowMs?.();
|
|
63
|
+
if (reduced || now === undefined || !Number.isFinite(now) || value.value === target && velocity === 0) {
|
|
64
|
+
frames.cancel(job);
|
|
65
|
+
settle();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
previous = now;
|
|
70
|
+
if (frames.queued(job) === undefined) frames.queue(job, step, { label: "Spring" });
|
|
71
|
+
});
|
|
72
|
+
if (!watched.ok) throw new Error(watched.reason);
|
|
73
|
+
scope.onDispose(() => { frames.cancel(job); });
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { easeProgress } from "./ease";
|
|
2
|
+
import { useSlide, type SlideValueOptions } from "./slide";
|
|
3
|
+
|
|
4
|
+
export interface StaggeredRevealOptions extends SlideValueOptions {
|
|
5
|
+
/** Seconds between the start of adjacent items. Defaults to 0.024. */
|
|
6
|
+
readonly stagger?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface StaggeredReveal {
|
|
10
|
+
/** Eased progress from 0 to 1 for one item, using a zero-based index. */
|
|
11
|
+
progress(this: void, index: number): number;
|
|
12
|
+
/** Keep the container visible through the exit. */
|
|
13
|
+
visible(this: void): boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Reveal a fixed group in order, then close in reverse using the same timeline. */
|
|
17
|
+
export function useStaggeredReveal(this: void, open: (this: void) => boolean, count: number,
|
|
18
|
+
{ duration = 0.2, stagger = 0.024, ease = "out", motion }: StaggeredRevealOptions = {}): StaggeredReveal {
|
|
19
|
+
if (!Number.isInteger(count) || count < 1) throw new Error("Staggered reveal requires a positive item count");
|
|
20
|
+
if (!Number.isFinite(duration) || duration < 0 || !Number.isFinite(stagger) || stagger < 0) {
|
|
21
|
+
throw new Error("Staggered reveal timings must be nonnegative and finite");
|
|
22
|
+
}
|
|
23
|
+
const total = duration === 0 ? 0 : duration + (count - 1) * stagger;
|
|
24
|
+
const timeline = useSlide(() => open() ? 1 : 0, { duration: total, ease: "linear", motion });
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
progress(index) {
|
|
28
|
+
const position = timeline.value;
|
|
29
|
+
if (position === 0 || position === 1 || duration === 0) return position;
|
|
30
|
+
return easeProgress(ease, (position * total - index * stagger) / duration);
|
|
31
|
+
},
|
|
32
|
+
visible: () => open() || timeline.value > 0,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const directions = new Map([
|
|
2
|
+
["to right", ["HORIZONTAL", false]], ["90deg", ["HORIZONTAL", false]],
|
|
3
|
+
["to left", ["HORIZONTAL", true]], ["270deg", ["HORIZONTAL", true]],
|
|
4
|
+
["to top", ["VERTICAL", false]], ["0deg", ["VERTICAL", false]],
|
|
5
|
+
["to bottom", ["VERTICAL", true]], ["180deg", ["VERTICAL", true]],
|
|
6
|
+
]);
|
|
7
|
+
|
|
8
|
+
function argumentsOf(value) {
|
|
9
|
+
if (!value.startsWith("linear-gradient(") || !value.endsWith(")")) return;
|
|
10
|
+
const body = value.slice(16, -1);
|
|
11
|
+
const result = [];
|
|
12
|
+
let depth = 0;
|
|
13
|
+
let start = 0;
|
|
14
|
+
for (let index = 0; index < body.length; index++) {
|
|
15
|
+
const char = body[index];
|
|
16
|
+
if (char === "(") depth++;
|
|
17
|
+
if (char === ")") {
|
|
18
|
+
depth--;
|
|
19
|
+
if (depth < 0) return;
|
|
20
|
+
}
|
|
21
|
+
if (char === "," && depth === 0) {
|
|
22
|
+
result.push(body.slice(start, index).trim());
|
|
23
|
+
start = index + 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (depth !== 0) return;
|
|
27
|
+
result.push(body.slice(start).trim());
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function gradient(value) {
|
|
32
|
+
const args = argumentsOf(value);
|
|
33
|
+
if (args === undefined) return;
|
|
34
|
+
const direction = directions.get(args[0]?.replace(/\s+/gu, " "));
|
|
35
|
+
if (direction !== undefined) args.shift();
|
|
36
|
+
const [axis, reverse] = direction ?? directions.get("to bottom");
|
|
37
|
+
return { axis, reverse, stops: args };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function parseLinearGradient(value, readColor) {
|
|
41
|
+
const input = gradient(value);
|
|
42
|
+
if (input?.stops.length !== 2) return;
|
|
43
|
+
const [first, last] = input.stops.map(readColor);
|
|
44
|
+
if (first === undefined || last === undefined) return;
|
|
45
|
+
const { axis, reverse } = input;
|
|
46
|
+
return { gradient: { axis, min: reverse ? last : first, max: reverse ? first : last } };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function parseMaskGradient(value, readColor) {
|
|
50
|
+
const input = gradient(value);
|
|
51
|
+
if (input === undefined || input.stops.length < 2) return;
|
|
52
|
+
const stops = [];
|
|
53
|
+
for (const stop of input.stops) {
|
|
54
|
+
const [, color, percentage] = /^([\s\S]*?)(?:\s+((?:\d+(?:\.\d+)?|\.\d+))%)?$/u.exec(stop);
|
|
55
|
+
const literal = readColor(color);
|
|
56
|
+
const position = percentage === undefined ? undefined : Number(percentage) / 100;
|
|
57
|
+
if (literal === undefined || (position !== undefined && position > 1)) return;
|
|
58
|
+
stops.push({ position, alpha: literal.length === 9 ? Number.parseInt(literal.slice(7), 16) : 255 });
|
|
59
|
+
}
|
|
60
|
+
stops[0].position ??= 0;
|
|
61
|
+
stops.at(-1).position ??= 1;
|
|
62
|
+
let previous = 0;
|
|
63
|
+
for (let index = 1; index < stops.length; index++) {
|
|
64
|
+
const stop = stops[index];
|
|
65
|
+
if (stop.position === undefined) continue;
|
|
66
|
+
stop.position = Math.max(stop.position, stops[previous].position);
|
|
67
|
+
for (let gap = previous + 1; gap < index; gap++) {
|
|
68
|
+
const start = stops[previous].position;
|
|
69
|
+
stops[gap].position = start + (stop.position - start) * (gap - previous) / (index - previous);
|
|
70
|
+
}
|
|
71
|
+
previous = index;
|
|
72
|
+
}
|
|
73
|
+
return { gradient: { axis: input.axis, reverse: input.reverse, stops } };
|
|
74
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const samples = 256;
|
|
4
|
+
const thickness = 4;
|
|
5
|
+
|
|
6
|
+
function alphaAt(stops, position) {
|
|
7
|
+
if (position < stops[0].position) return stops[0].alpha;
|
|
8
|
+
const next = stops.findIndex(stop => stop.position > position);
|
|
9
|
+
if (next === -1) return stops.at(-1).alpha;
|
|
10
|
+
const before = stops[next - 1], after = stops[next];
|
|
11
|
+
const amount = (position - before.position) / (after.position - before.position);
|
|
12
|
+
return Math.round(before.alpha + (after.alpha - before.alpha) * amount);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function encodeMask({ axis, reverse, stops }) {
|
|
16
|
+
const horizontal = axis === "HORIZONTAL";
|
|
17
|
+
const width = horizontal ? samples : thickness;
|
|
18
|
+
const height = horizontal ? thickness : samples;
|
|
19
|
+
const data = Buffer.alloc(18 + width * height * 4, 255);
|
|
20
|
+
data.fill(0, 0, 18);
|
|
21
|
+
data[2] = 2; // Uncompressed truecolor.
|
|
22
|
+
data.writeUInt16LE(width, 12);
|
|
23
|
+
data.writeUInt16LE(height, 14);
|
|
24
|
+
data[16] = 32;
|
|
25
|
+
data[17] = 0x28; // Eight bits of alpha, origin at the top left.
|
|
26
|
+
for (let y = 0; y < height; y++) {
|
|
27
|
+
for (let x = 0; x < width; x++) {
|
|
28
|
+
const sample = horizontal ? x : height - 1 - y;
|
|
29
|
+
const position = (reverse ? samples - 1 - sample : sample) / (samples - 1);
|
|
30
|
+
data[18 + (y * width + x) * 4 + 3] = alphaAt(stops, position);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function prepareCssMaskImages(classes, addonName, assets) {
|
|
37
|
+
const root = `Interface/AddOns/${addonName}/`;
|
|
38
|
+
for (const style of Object.values(classes)) {
|
|
39
|
+
const mask = style.maskImage;
|
|
40
|
+
if (mask === undefined) continue;
|
|
41
|
+
if ("gradient" in mask) {
|
|
42
|
+
const data = encodeMask(mask.gradient);
|
|
43
|
+
const hash = createHash("sha256").update(data).digest("hex");
|
|
44
|
+
const output = `KumiGenerated/Masks/${hash}.tga`;
|
|
45
|
+
if (!assets.has(output)) assets.set(output, data);
|
|
46
|
+
style.maskImage = { path: root + output };
|
|
47
|
+
} else {
|
|
48
|
+
const path = mask.path.replace(/^\.\//u, "");
|
|
49
|
+
if (path.startsWith("Assets/")) style.maskImage = { path: root + path };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { prepareCssMaskImages } from "./css-mask-assets.mjs";
|
|
4
|
+
import { compileCssDeclarations } from "./css-v1.mjs";
|
|
5
|
+
|
|
6
|
+
function mask(value) {
|
|
7
|
+
return compileCssDeclarations([{ prop: "mask-image", value }]);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
test("packages one TGA for identical gradient masks and preserves their orientation and alpha", () => {
|
|
11
|
+
const styles = {
|
|
12
|
+
right: mask("linear-gradient(to right, transparent, black 43%)"),
|
|
13
|
+
same: mask("linear-gradient(90deg, transparent, black 43%)"),
|
|
14
|
+
bottom: mask("linear-gradient(transparent, black)"),
|
|
15
|
+
file: mask('url("./Assets/Fade.tga")'),
|
|
16
|
+
};
|
|
17
|
+
const assets = new Map();
|
|
18
|
+
prepareCssMaskImages(styles, "Sample", assets);
|
|
19
|
+
const root = "Interface/AddOns/Sample/";
|
|
20
|
+
assert.deepEqual(styles.right, styles.same);
|
|
21
|
+
assert.equal(styles.file.maskImage.path, root + "Assets/Fade.tga");
|
|
22
|
+
assert.equal(assets.size, 2);
|
|
23
|
+
const right = assets.get(styles.right.maskImage.path.slice(root.length));
|
|
24
|
+
const bottom = assets.get(styles.bottom.maskImage.path.slice(root.length));
|
|
25
|
+
assert.equal(right.readUInt16LE(12), 256);
|
|
26
|
+
assert.equal(bottom.readUInt16LE(14), 256);
|
|
27
|
+
assert.equal(right[21], 0);
|
|
28
|
+
assert.equal(right[21 + 128 * 4], 255);
|
|
29
|
+
assert.equal(bottom[21], 0);
|
|
30
|
+
assert.equal(bottom[21 + 255 * 16], 255);
|
|
31
|
+
});
|