@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,376 @@
|
|
|
1
|
+
import type { AlphaStep, AnimationSpec, Ease, FlipBook, FlipBookStep, MoveStep, Origin, RegionAnimation, RegionStep, RotateStep,
|
|
2
|
+
ScaleStep } from "./spec";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ready-made animations. Region presets work on any frame, texture or text; on a frame they move,
|
|
6
|
+
* scale and fade everything inside it. Texture presets rotate or flip art and need a texture.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type Side = "left" | "right" | "top" | "bottom";
|
|
10
|
+
|
|
11
|
+
const center: Origin = { point: "CENTER" };
|
|
12
|
+
/** The shortest native step, used to jump to a start offset on the first frame. */
|
|
13
|
+
const instant = 0.001;
|
|
14
|
+
|
|
15
|
+
function sideOffset(side: Side, distance: number): readonly [number, number] {
|
|
16
|
+
if (side === "left") return [-distance, 0];
|
|
17
|
+
if (side === "right") return [distance, 0];
|
|
18
|
+
if (side === "top") return [0, distance];
|
|
19
|
+
return [0, -distance];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface FadeOptions {
|
|
23
|
+
duration?: number;
|
|
24
|
+
delay?: number;
|
|
25
|
+
ease?: Ease;
|
|
26
|
+
/** Opacity at the start. */
|
|
27
|
+
from?: number;
|
|
28
|
+
/** Opacity at the end. */
|
|
29
|
+
to?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Fade in and keep the final opacity. */
|
|
33
|
+
export function fadeIn({ duration = 0.16, delay, ease = "out", from = 0, to = 1 }: FadeOptions = {}): RegionAnimation {
|
|
34
|
+
return { keepFinalAlpha: true, steps: [{ alpha: [from, to], duration, delay, ease }] };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Fade out and keep the final opacity. */
|
|
38
|
+
export function fadeOut({ duration = 0.12, delay, ease = "in", from = 1, to = 0 }: FadeOptions = {}): RegionAnimation {
|
|
39
|
+
return { keepFinalAlpha: true, steps: [{ alpha: [from, to], duration, delay, ease }] };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface PulseOptions {
|
|
43
|
+
duration?: number;
|
|
44
|
+
/** Opacity at the bright end. */
|
|
45
|
+
high?: number;
|
|
46
|
+
/** Opacity at the dim end. */
|
|
47
|
+
low?: number;
|
|
48
|
+
ease?: Ease;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Endless soft fade between two opacities. Safe on restricted aura textures: it adds no scripts. */
|
|
52
|
+
export function pulse({ duration = 0.8, high = 0.9, low = 0.15, ease = "inOut" }: PulseOptions = {}): RegionAnimation {
|
|
53
|
+
return { loop: "bounce", steps: [{ alpha: [high, low], duration, ease }] };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Endless quick blink. */
|
|
57
|
+
export function blink({ duration = 0.25, low = 0 }: Pick<PulseOptions, "duration" | "low"> = {}): RegionAnimation {
|
|
58
|
+
return { loop: "bounce", steps: [{ alpha: [1, low], duration, ease: "linear" }] };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface BreatheOptions {
|
|
62
|
+
duration?: number;
|
|
63
|
+
/** Largest scale. */
|
|
64
|
+
scale?: number;
|
|
65
|
+
origin?: Origin;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Endless slow grow and shrink. */
|
|
69
|
+
export function breathe({ duration = 1.6, scale = 1.04, origin = center }: BreatheOptions = {}): RegionAnimation {
|
|
70
|
+
return { loop: "bounce", steps: [{ scale: [1, scale], duration, ease: "inOut", origin }] };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface HeartbeatOptions {
|
|
74
|
+
/** First beat's scale. */
|
|
75
|
+
first?: number;
|
|
76
|
+
/** Second beat's scale. */
|
|
77
|
+
second?: number;
|
|
78
|
+
/** Rest after the double beat, in seconds. */
|
|
79
|
+
rest?: number;
|
|
80
|
+
/** Multiplies all beat durations. */
|
|
81
|
+
tempo?: number;
|
|
82
|
+
origin?: Origin;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Endless double beat with a rest. */
|
|
86
|
+
export function heartbeat({ first = 1.12, second = 1.07, rest = 0.65, tempo = 1, origin = center }: HeartbeatOptions = {}): RegionAnimation {
|
|
87
|
+
const steps: ScaleStep[] = [
|
|
88
|
+
{ scale: [1, first], duration: 0.1 * tempo, ease: "out", origin },
|
|
89
|
+
{ scale: [1, 1 / first], duration: 0.16 * tempo, ease: "inOut", origin },
|
|
90
|
+
{ scale: [1, second], duration: 0.09 * tempo, ease: "out", origin },
|
|
91
|
+
{ scale: [1, 1 / second], duration: 0.25 * tempo, ease: "inOut", origin, endDelay: rest },
|
|
92
|
+
];
|
|
93
|
+
return { loop: "repeat", steps };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface FloatOptions {
|
|
97
|
+
duration?: number;
|
|
98
|
+
/** Pixels up at the top of the float. */
|
|
99
|
+
distance?: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Endless gentle rise and fall. */
|
|
103
|
+
export function float({ duration = 1.8, distance = 4 }: FloatOptions = {}): RegionAnimation {
|
|
104
|
+
return { loop: "bounce", steps: [{ move: [0, distance], duration, ease: "inOut" }] };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface PopOptions {
|
|
108
|
+
duration?: number;
|
|
109
|
+
/** Scale the pop starts from (in) or ends at (out). */
|
|
110
|
+
scale?: number;
|
|
111
|
+
origin?: Origin;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Appear with a fade and a scale that settles to 1. */
|
|
115
|
+
export function popIn({ duration = 0.18, scale = 1.3, origin = center }: PopOptions = {}): RegionAnimation {
|
|
116
|
+
return {
|
|
117
|
+
keepFinalAlpha: true,
|
|
118
|
+
steps: [
|
|
119
|
+
{ alpha: [0, 1], duration: Math.min(duration, 0.12) },
|
|
120
|
+
{ at: "<", scale: [scale, 1], duration, ease: "out", origin },
|
|
121
|
+
],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Disappear with a fade and a shrink. */
|
|
126
|
+
export function popOut({ duration = 0.14, scale = 0.85, origin = center }: PopOptions = {}): RegionAnimation {
|
|
127
|
+
return {
|
|
128
|
+
keepFinalAlpha: true,
|
|
129
|
+
steps: [
|
|
130
|
+
{ alpha: [1, 0], duration, ease: "in" },
|
|
131
|
+
{ at: "<", scale: [1, scale], duration, ease: "in", origin },
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface SlideOptions {
|
|
137
|
+
duration?: number;
|
|
138
|
+
/** Pixels travelled. */
|
|
139
|
+
distance?: number;
|
|
140
|
+
/** Fade together with the slide. */
|
|
141
|
+
fade?: boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Slide in from a side to the region's anchor. */
|
|
145
|
+
export function slideIn(from: Side = "bottom", { duration = 0.16, distance = 8, fade = true }: SlideOptions = {}): RegionAnimation {
|
|
146
|
+
const [x, y] = sideOffset(from, distance);
|
|
147
|
+
const steps: RegionStep[] = [];
|
|
148
|
+
if (fade) steps.push({ alpha: [0, 1], duration, ease: "out" });
|
|
149
|
+
// Jump to the start offset on the first frame, then travel back to the anchor.
|
|
150
|
+
steps.push({ at: 0, move: [x, y], duration: instant }, { move: [-x, -y], duration, ease: "out" });
|
|
151
|
+
return { keepFinalAlpha: fade, steps };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Slide away from the anchor towards a side. */
|
|
155
|
+
export function slideOut(to: Side = "bottom", { duration = 0.12, distance = 8, fade = true }: SlideOptions = {}): RegionAnimation {
|
|
156
|
+
const [x, y] = sideOffset(to, distance);
|
|
157
|
+
const steps: RegionStep[] = [{ move: [x, y], duration, ease: "in" }];
|
|
158
|
+
if (fade) steps.push({ at: "<", alpha: [1, 0], duration, ease: "in" });
|
|
159
|
+
return { keepFinalAlpha: fade, steps };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface ShakeOptions {
|
|
163
|
+
duration?: number;
|
|
164
|
+
/** Pixels to each side. */
|
|
165
|
+
distance?: number;
|
|
166
|
+
/** Full left-right swings. */
|
|
167
|
+
times?: number;
|
|
168
|
+
axis?: "x" | "y";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Shake around the anchor and stop where it started. */
|
|
172
|
+
export function shake({ duration = 0.3, distance = 4, times = 3, axis = "x" }: ShakeOptions = {}): RegionAnimation {
|
|
173
|
+
const swings = Math.min(16, Math.max(1, Math.floor(times)));
|
|
174
|
+
const leg = duration / (swings * 2);
|
|
175
|
+
const offset = (value: number): MoveStep["move"] => axis === "x" ? [value, 0] : [0, value];
|
|
176
|
+
const steps: MoveStep[] = [{ move: offset(distance), duration: leg / 2, ease: "out" }];
|
|
177
|
+
for (let swing = 1; swing < swings * 2; swing++) {
|
|
178
|
+
steps.push({ move: offset(swing % 2 === 1 ? -2 * distance : 2 * distance), duration: leg, ease: "inOut" });
|
|
179
|
+
}
|
|
180
|
+
steps.push({ move: offset(distance), duration: leg / 2, ease: "in" });
|
|
181
|
+
return { steps };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface HopOptions {
|
|
185
|
+
duration?: number;
|
|
186
|
+
/** Pixels up at the top of the hop. */
|
|
187
|
+
height?: number;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** One hop up and back down. */
|
|
191
|
+
export function hop({ duration = 0.35, height = 6 }: HopOptions = {}): RegionAnimation {
|
|
192
|
+
return {
|
|
193
|
+
steps: [
|
|
194
|
+
{ move: [0, height], duration: duration / 2, ease: "out" },
|
|
195
|
+
{ move: [0, -height], duration: duration / 2, ease: "in" },
|
|
196
|
+
],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface FlashOptions {
|
|
201
|
+
duration?: number;
|
|
202
|
+
/** Opacity at the flash's peak. */
|
|
203
|
+
peak?: number;
|
|
204
|
+
/** Opacity before and after. */
|
|
205
|
+
base?: number;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** One flash up to the peak and back. */
|
|
209
|
+
export function flash({ duration = 0.3, peak = 1, base = 0 }: FlashOptions = {}): RegionAnimation {
|
|
210
|
+
const steps: AlphaStep[] = [
|
|
211
|
+
{ alpha: [base, peak], duration: duration * 0.35, ease: "out" },
|
|
212
|
+
{ alpha: [peak, base], duration: duration * 0.65, ease: "in" },
|
|
213
|
+
];
|
|
214
|
+
return { keepFinalAlpha: true, steps };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface BurstOptions {
|
|
218
|
+
duration?: number;
|
|
219
|
+
/** Scale at the end. */
|
|
220
|
+
scale?: number;
|
|
221
|
+
/** Opacity at the start. */
|
|
222
|
+
peak?: number;
|
|
223
|
+
origin?: Origin;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function growAndFade(duration: number, scale: number, peak: number, origin: Origin, fadeEase: Ease, rest?: number): RegionStep[] {
|
|
227
|
+
return [
|
|
228
|
+
{ scale: [1, scale], duration, ease: "out", origin, endDelay: rest },
|
|
229
|
+
{ at: "<", alpha: [peak, 0], duration, ease: fadeEase },
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Grow and fade out for a one-shot proc or impact. */
|
|
234
|
+
export function burst({ duration = 0.45, scale = 1.35, peak = 0.9, origin = center }: BurstOptions = {}): RegionAnimation {
|
|
235
|
+
return { keepFinalAlpha: true, steps: growAndFade(duration, scale, peak, origin, "out") };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface RippleOptions extends BurstOptions {
|
|
239
|
+
/** Repeat with this rest in seconds. A one-shot ripple when left out. */
|
|
240
|
+
rest?: number;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Grow and fade away, like a ping. */
|
|
244
|
+
export function ripple({ duration = 0.6, scale = 1.5, peak = 0.6, rest, origin = center }: RippleOptions = {}): RegionAnimation {
|
|
245
|
+
return { loop: rest === undefined ? undefined : "repeat", steps: growAndFade(duration, scale, peak, origin, "in", rest) };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface GlimmerOptions {
|
|
249
|
+
/** Seconds for the fade in and out, before the rest. */
|
|
250
|
+
duration?: number;
|
|
251
|
+
peak?: number;
|
|
252
|
+
rest?: number;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Fade up from transparent, fade back out and hold before repeating. */
|
|
256
|
+
export function glimmer({ duration = 2, peak = 0.7, rest = 1.2 }: GlimmerOptions = {}): RegionAnimation {
|
|
257
|
+
const rise = duration * 0.45;
|
|
258
|
+
return {
|
|
259
|
+
loop: "repeat",
|
|
260
|
+
steps: [
|
|
261
|
+
{ alpha: [0, peak], duration: rise, ease: "inOut" },
|
|
262
|
+
{ alpha: [peak, 0], duration: duration - rise, ease: "inOut", endDelay: rest },
|
|
263
|
+
],
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface AttentionOptions {
|
|
268
|
+
/** Seconds for all pops. */
|
|
269
|
+
duration?: number;
|
|
270
|
+
scale?: number;
|
|
271
|
+
/** Number of pops in this one-shot, rounded down and bounded to 1–16. */
|
|
272
|
+
times?: number;
|
|
273
|
+
origin?: Origin;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Pop up and settle back to the region's original scale. */
|
|
277
|
+
export function attention({ duration = 0.22, scale = 1.15, times = 1, origin = center }: AttentionOptions = {}): RegionAnimation {
|
|
278
|
+
const pops = Number.isFinite(times) ? Math.min(16, Math.max(1, Math.floor(times))) : 1;
|
|
279
|
+
const leg = duration / (2 * pops);
|
|
280
|
+
const steps: ScaleStep[] = [];
|
|
281
|
+
for (let pop = 0; pop < pops; pop++) {
|
|
282
|
+
steps.push(
|
|
283
|
+
{ scale: [1, scale], duration: leg, ease: "out", origin },
|
|
284
|
+
{ scale: [1, 1 / scale], duration: leg, ease: "inOut", origin },
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
return { steps };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface DriftOptions {
|
|
291
|
+
/** Seconds per loop, including the hidden reset. */
|
|
292
|
+
duration?: number;
|
|
293
|
+
distance?: number;
|
|
294
|
+
peak?: number;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Rise while fading in and out. Return to the anchor while transparent. */
|
|
298
|
+
export function drift({ duration = 4, distance = 8, peak = 1 }: DriftOptions = {}): RegionAnimation {
|
|
299
|
+
const reset = Math.min(instant, duration * 0.01);
|
|
300
|
+
const travel = duration - reset;
|
|
301
|
+
const fadeOutAt = travel * 0.55;
|
|
302
|
+
return {
|
|
303
|
+
loop: "repeat",
|
|
304
|
+
steps: [
|
|
305
|
+
{ move: [0, distance], duration: travel },
|
|
306
|
+
{ at: 0, alpha: [0, peak], duration: travel * 0.3, ease: "out" },
|
|
307
|
+
{ at: fadeOutAt, alpha: [peak, 0], duration: travel - fadeOutAt, ease: "in" },
|
|
308
|
+
{ at: travel, move: [0, -distance], duration: reset },
|
|
309
|
+
],
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface BeaconOptions extends PulseOptions {
|
|
314
|
+
/** Scale at the bright end. */
|
|
315
|
+
scale?: number;
|
|
316
|
+
origin?: Origin;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** Pulse between bright, enlarged and dim, resting poses. */
|
|
320
|
+
export function beacon({ duration = 0.45, high = 1, low = 0.3, ease = "inOut", scale = 1.04, origin = center }: BeaconOptions = {}): RegionAnimation {
|
|
321
|
+
const light = pulse({ duration, high, low, ease });
|
|
322
|
+
return { ...light, steps: [...light.steps, { at: "<", scale: [scale, 1], duration, ease, origin }] };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface EnterOptions extends PopOptions {
|
|
326
|
+
/** Side to enter from. */
|
|
327
|
+
slide?: Side;
|
|
328
|
+
distance?: number;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** Fade and scale into place, optionally sliding in from a side. */
|
|
332
|
+
export function enter({ duration = 0.18, scale, origin, slide, distance }: EnterOptions = {}): RegionAnimation {
|
|
333
|
+
const pop = popIn({ duration, scale, origin });
|
|
334
|
+
if (slide === undefined) return pop;
|
|
335
|
+
const movement = slideIn(slide, { duration, distance, fade: false });
|
|
336
|
+
return { ...pop, steps: [...pop.steps, ...movement.steps] };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export interface ExitOptions extends Pick<SlideOptions, "duration" | "distance"> {
|
|
340
|
+
/** Side to leave towards. */
|
|
341
|
+
slide?: Side;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** Fade out, optionally sliding away from the anchor. */
|
|
345
|
+
export function exit({ duration = 0.12, slide, distance }: ExitOptions = {}): RegionAnimation {
|
|
346
|
+
return slide === undefined ? fadeOut({ duration }) : slideOut(slide, { duration, distance });
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export interface SpinOptions {
|
|
350
|
+
/** Seconds per turn. */
|
|
351
|
+
duration?: number;
|
|
352
|
+
/** Degrees per loop; negative turns clockwise. */
|
|
353
|
+
degrees?: number;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Endless rotation. Textures only. */
|
|
357
|
+
export function spin({ duration = 8, degrees = -360 }: SpinOptions = {}): AnimationSpec<RotateStep> {
|
|
358
|
+
return { loop: "repeat", steps: [{ rotate: degrees, duration, ease: "linear", origin: center }] };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** Endless swing around the center. Textures only. */
|
|
362
|
+
export function sway({ duration = 1.8, degrees = 6 }: SpinOptions = {}): AnimationSpec<RotateStep> {
|
|
363
|
+
return {
|
|
364
|
+
loop: "repeat",
|
|
365
|
+
steps: [
|
|
366
|
+
{ rotate: -degrees, duration: duration / 4, ease: "out", origin: center },
|
|
367
|
+
{ rotate: degrees * 2, duration: duration / 2, ease: "inOut", origin: center },
|
|
368
|
+
{ rotate: -degrees, duration: duration / 4, ease: "in", origin: center },
|
|
369
|
+
],
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** Endless sprite sheet playback. Textures only. */
|
|
374
|
+
export function flipbook(sheet: FlipBook, duration: number): AnimationSpec<FlipBookStep> {
|
|
375
|
+
return { loop: "repeat", steps: [{ flipbook: sheet, duration, ease: "linear" }] };
|
|
376
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { fail, ok, type Result } from "@kumi/core";
|
|
2
|
+
import type { OwnedReadonlyArray } from "../src/owned-collections";
|
|
3
|
+
|
|
4
|
+
/** Easing names shared by native animations and frame tweens. */
|
|
5
|
+
export type Ease = "linear" | "in" | "out" | "inOut";
|
|
6
|
+
export type AnchorPoint = "TOP" | "BOTTOM" | "LEFT" | "RIGHT" | "CENTER" | "TOPLEFT" | "TOPRIGHT" | "BOTTOMLEFT" | "BOTTOMRIGHT";
|
|
7
|
+
export type ScaleValue = number | readonly [x: number, y: number];
|
|
8
|
+
export type Range<Value> = readonly [from: Value, to: Value];
|
|
9
|
+
|
|
10
|
+
export interface Origin {
|
|
11
|
+
point: AnchorPoint;
|
|
12
|
+
x?: number;
|
|
13
|
+
y?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Absolute start in seconds, or "<" to start with the previous step. The default follows the previous step. */
|
|
17
|
+
export type StepPosition = number | "<";
|
|
18
|
+
|
|
19
|
+
interface Timing {
|
|
20
|
+
/** Seconds. */
|
|
21
|
+
duration: number;
|
|
22
|
+
/** Seconds added to the step's start. */
|
|
23
|
+
delay?: number;
|
|
24
|
+
/** Seconds the step holds its end before the group may finish. */
|
|
25
|
+
endDelay?: number;
|
|
26
|
+
ease?: Ease;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface StepBase extends Timing {
|
|
30
|
+
/** Name for `AnimationControl.set`. */
|
|
31
|
+
id?: string;
|
|
32
|
+
at?: StepPosition;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type Only<Key extends string> = { [Other in Exclude<"alpha" | "scale" | "rotate" | "move" | "flipbook", Key>]?: never };
|
|
36
|
+
|
|
37
|
+
export type AlphaStep = StepBase & Only<"alpha"> & {
|
|
38
|
+
/** Absolute opacity from and to, 0 to 1. */
|
|
39
|
+
alpha: Range<number>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type ScaleStep = StepBase & Only<"scale"> & {
|
|
43
|
+
/** Relative to the region's own scale. Consecutive scale steps multiply. */
|
|
44
|
+
scale: Range<ScaleValue>;
|
|
45
|
+
origin?: Origin;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type RotateStep = StepBase & Only<"rotate"> & {
|
|
49
|
+
/** Degrees, counterclockwise, relative to the current rotation. */
|
|
50
|
+
rotate: number;
|
|
51
|
+
origin?: Origin;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type MoveStep = StepBase & Only<"move"> & {
|
|
55
|
+
/** Offset in pixels, relative to the region's anchor. Multiplied by the native `distance` option. */
|
|
56
|
+
move: readonly [x: number, y: number];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export interface FlipBook {
|
|
60
|
+
rows: number;
|
|
61
|
+
columns: number;
|
|
62
|
+
frames: number;
|
|
63
|
+
frameWidth?: number;
|
|
64
|
+
frameHeight?: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type FlipBookStep = StepBase & Only<"flipbook"> & { flipbook: FlipBook };
|
|
68
|
+
|
|
69
|
+
export type AnimationStep = AlphaStep | ScaleStep | RotateStep | MoveStep | FlipBookStep;
|
|
70
|
+
/** Steps every region accepts. On a frame they also move, scale and fade everything inside it. */
|
|
71
|
+
export type RegionStep = AlphaStep | ScaleStep | MoveStep;
|
|
72
|
+
/** Steps the client applies to textures only. */
|
|
73
|
+
export type TextureStep = RotateStep | FlipBookStep;
|
|
74
|
+
export type StepKind = "alpha" | "scale" | "rotate" | "move" | "flipbook";
|
|
75
|
+
|
|
76
|
+
export interface AnimationSpec<Step extends AnimationStep = AnimationStep> {
|
|
77
|
+
steps: readonly Step[];
|
|
78
|
+
loop?: "repeat" | "bounce";
|
|
79
|
+
/** Keep the last alpha after a one-shot animation finishes. */
|
|
80
|
+
keepFinalAlpha?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface PlannedStep {
|
|
84
|
+
readonly index: number;
|
|
85
|
+
readonly id?: string;
|
|
86
|
+
readonly kind: StepKind;
|
|
87
|
+
/** Seconds from the start of the group, including the step's delay. */
|
|
88
|
+
readonly start: number;
|
|
89
|
+
readonly duration: number;
|
|
90
|
+
readonly endDelay: number;
|
|
91
|
+
readonly ease: Ease;
|
|
92
|
+
readonly step: AnimationStep;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** A spec that any region accepts, frames included. */
|
|
96
|
+
export type RegionAnimation = AnimationSpec<RegionStep>;
|
|
97
|
+
|
|
98
|
+
export interface AnimationPlan {
|
|
99
|
+
readonly steps: readonly PlannedStep[];
|
|
100
|
+
/** Seconds until the last step ends, including end delays. */
|
|
101
|
+
readonly length: number;
|
|
102
|
+
readonly loop?: "repeat" | "bounce";
|
|
103
|
+
readonly keepFinalAlpha: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function finite(value: number) {
|
|
107
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function orDefault(value: number | undefined, fallback: number) {
|
|
111
|
+
return value === undefined ? fallback : value;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function stepKind(step: AnimationStep): StepKind {
|
|
115
|
+
if (step.alpha !== undefined) return "alpha";
|
|
116
|
+
if (step.scale !== undefined) return "scale";
|
|
117
|
+
if (step.rotate !== undefined) return "rotate";
|
|
118
|
+
if (step.move !== undefined) return "move";
|
|
119
|
+
return "flipbook";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function scaleValid(value: ScaleValue) {
|
|
123
|
+
return typeof value === "number" ? finite(value) && value > 0
|
|
124
|
+
: finite(value[0]) && finite(value[1]) && value[0] > 0 && value[1] > 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function validateStep(step: AnimationStep, kind: StepKind, label: string): Result<void> {
|
|
128
|
+
if (!finite(step.duration) || step.duration <= 0) return fail(label + ": duration must be a positive number of seconds");
|
|
129
|
+
if (step.delay !== undefined && (!finite(step.delay) || step.delay < 0)) return fail(label + ": delay must not be negative");
|
|
130
|
+
if (step.endDelay !== undefined && (!finite(step.endDelay) || step.endDelay < 0)) return fail(label + ": endDelay must not be negative");
|
|
131
|
+
if (typeof step.at === "number" && (!finite(step.at) || step.at < 0)) return fail(label + ": at must not be negative");
|
|
132
|
+
switch (kind) {
|
|
133
|
+
case "alpha": {
|
|
134
|
+
const [from, to] = (step as AlphaStep).alpha;
|
|
135
|
+
if (!finite(from) || !finite(to) || from < 0 || from > 1 || to < 0 || to > 1) return fail(label + ": alpha must stay between 0 and 1");
|
|
136
|
+
return ok(undefined);
|
|
137
|
+
}
|
|
138
|
+
case "scale": {
|
|
139
|
+
const [from, to] = (step as ScaleStep).scale;
|
|
140
|
+
return scaleValid(from) && scaleValid(to) ? ok(undefined) : fail(label + ": scale must be positive");
|
|
141
|
+
}
|
|
142
|
+
case "rotate":
|
|
143
|
+
return finite((step as RotateStep).rotate) ? ok(undefined) : fail(label + ": rotate must be a number of degrees");
|
|
144
|
+
case "move": {
|
|
145
|
+
const [x, y] = (step as MoveStep).move;
|
|
146
|
+
return finite(x) && finite(y) ? ok(undefined) : fail(label + ": move must be two numbers");
|
|
147
|
+
}
|
|
148
|
+
case "flipbook": {
|
|
149
|
+
const { rows, columns, frames } = (step as FlipBookStep).flipbook;
|
|
150
|
+
const whole = (value: number) => finite(value) && value >= 1 && Math.floor(value) === value;
|
|
151
|
+
if (!whole(rows) || !whole(columns) || !whole(frames) || frames > rows * columns) {
|
|
152
|
+
return fail(label + ": flipbook needs whole rows, columns and frames that fit the sheet");
|
|
153
|
+
}
|
|
154
|
+
return ok(undefined);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Resolve step positions to absolute start times and validate the values before any native call. */
|
|
160
|
+
export function planAnimation(spec: AnimationSpec): Result<AnimationPlan> {
|
|
161
|
+
const steps = spec.steps as OwnedReadonlyArray<AnimationStep>;
|
|
162
|
+
if (steps.length === 0) return fail("An animation needs at least one step");
|
|
163
|
+
const planned: PlannedStep[] = [];
|
|
164
|
+
const ids = new Set<string>();
|
|
165
|
+
let previousStart = 0;
|
|
166
|
+
let previousEnd = 0;
|
|
167
|
+
let length = 0;
|
|
168
|
+
for (let index = 0; index < steps.length; index++) {
|
|
169
|
+
const step = steps[index];
|
|
170
|
+
const kind = stepKind(step);
|
|
171
|
+
const label = "Animation step " + (step.id ?? String(index + 1));
|
|
172
|
+
const valid = validateStep(step, kind, label);
|
|
173
|
+
if (!valid.ok) return valid;
|
|
174
|
+
if (step.id !== undefined) {
|
|
175
|
+
if (ids.has(step.id)) return fail("Duplicate animation step id " + step.id);
|
|
176
|
+
ids.add(step.id);
|
|
177
|
+
}
|
|
178
|
+
const base = step.at === "<" ? previousStart : step.at ?? previousEnd;
|
|
179
|
+
const start = base + orDefault(step.delay, 0);
|
|
180
|
+
const endDelay = orDefault(step.endDelay, 0);
|
|
181
|
+
planned.push({ index, id: step.id, kind, start, duration: step.duration, endDelay, ease: step.ease ?? "linear", step });
|
|
182
|
+
previousStart = base;
|
|
183
|
+
previousEnd = start + step.duration;
|
|
184
|
+
length = Math.max(length, start + step.duration + endDelay);
|
|
185
|
+
}
|
|
186
|
+
return ok({ steps: planned, length, loop: spec.loop, keepFinalAlpha: spec.keepFinalAlpha === true });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The alpha a one-shot animation leaves when it keeps its final alpha. */
|
|
190
|
+
export function finalAlpha(plan: AnimationPlan): number | undefined {
|
|
191
|
+
let latest: PlannedStep | undefined;
|
|
192
|
+
for (const step of plan.steps as OwnedReadonlyArray<PlannedStep>) {
|
|
193
|
+
if (step.kind !== "alpha") continue;
|
|
194
|
+
if (!latest || step.start + step.duration >= latest.start + latest.duration) latest = step;
|
|
195
|
+
}
|
|
196
|
+
return latest ? (latest.step as AlphaStep).alpha[1] : undefined;
|
|
197
|
+
}
|