@overmvp/kumi 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -2
  3. package/animation/color-transition.ts +196 -0
  4. package/animation/cycle.ts +151 -0
  5. package/animation/ease.ts +29 -0
  6. package/animation/index.ts +13 -0
  7. package/animation/package.json +12 -0
  8. package/animation/presets.ts +376 -0
  9. package/animation/spec.ts +197 -0
  10. package/builder/Cargo.lock +192 -0
  11. package/builder/Cargo.toml +7 -0
  12. package/builder/css-v1.mjs +334 -0
  13. package/builder/css-v1.test.mjs +321 -0
  14. package/builder/generated-output.mjs +61 -0
  15. package/builder/generated-output.test.mjs +132 -0
  16. package/builder/jsx-form.mjs +93 -0
  17. package/builder/jsx-form.test.mjs +48 -0
  18. package/builder/jsx-lists.mjs +209 -0
  19. package/builder/link-addon-package.mjs +86 -0
  20. package/builder/lua-assets.mjs +74 -0
  21. package/builder/lua-builtin-values.mjs +57 -0
  22. package/builder/lua-builtin-values.test.mjs +155 -0
  23. package/builder/lua-loop-closures.mjs +183 -0
  24. package/builder/lua-loop-closures.test.mjs +89 -0
  25. package/builder/lua-truthiness.mjs +61 -0
  26. package/builder/lua-truthiness.test.mjs +113 -0
  27. package/builder/module-declarations.mjs +594 -0
  28. package/builder/module-declarations.test.mjs +444 -0
  29. package/builder/native-kernels.mjs +60 -0
  30. package/builder/native-lua.d.ts +57 -0
  31. package/builder/native-routes.mjs +51 -0
  32. package/builder/no-static-ref-read.mjs +93 -0
  33. package/builder/no-static-ref-read.test.mjs +181 -0
  34. package/builder/secure-snippet.mjs +317 -0
  35. package/builder/secure-snippet.test.mjs +101 -0
  36. package/builder/shared-lua-runtime.mjs +150 -0
  37. package/builder/src/addon-link.lua +29 -0
  38. package/builder/src/arrays.lua +260 -0
  39. package/builder/src/assets.rs +177 -0
  40. package/builder/src/classes.lua +75 -0
  41. package/builder/src/collections.lua +190 -0
  42. package/builder/src/compiler.rs +2164 -0
  43. package/builder/src/config.rs +42 -0
  44. package/builder/src/entries.rs +166 -0
  45. package/builder/src/errors.lua +15 -0
  46. package/builder/src/lua_data.rs +231 -0
  47. package/builder/src/main.rs +367 -0
  48. package/builder/src/native_ir.rs +65 -0
  49. package/builder/src/native_signal.rs +47 -0
  50. package/builder/src/numbers.lua +62 -0
  51. package/builder/src/project-front.mjs +3331 -0
  52. package/builder/src/records.lua +75 -0
  53. package/builder/src/routes.rs +127 -0
  54. package/builder/src/signal-kernel.fingerprint +1 -0
  55. package/builder/src/strings.lua +103 -0
  56. package/builder/src/ts-lower.mjs +68 -0
  57. package/builder/src/wow_client.rs +253 -0
  58. package/builder/src/wow_types.rs +564 -0
  59. package/builder/style-states.mjs +100 -0
  60. package/builder/style-states.test.mjs +103 -0
  61. package/builder/vite-assets.mjs +53 -0
  62. package/builder/vite-project.mjs +10 -0
  63. package/config.ts +17 -0
  64. package/form/index.ts +522 -0
  65. package/form/package.json +13 -0
  66. package/motion/index.ts +2 -0
  67. package/motion/package.json +10 -0
  68. package/package.json +22 -4
  69. package/router/index.ts +43 -0
  70. package/router/package.json +12 -0
  71. package/router/routes.ts +64 -0
  72. package/scripts/kumi-cli.mjs +70 -0
  73. package/scripts/link-addons.mjs +51 -0
  74. package/src/bindings.ts +35 -0
  75. package/src/context.ts +15 -0
  76. package/src/css-tokens.ts +234 -0
  77. package/src/css-v1.ts +58 -0
  78. package/src/cvars.ts +91 -0
  79. package/src/element-node.ts +32 -0
  80. package/src/elements.ts +479 -0
  81. package/src/feature-scope.ts +82 -0
  82. package/src/flex-layout.ts +807 -0
  83. package/src/frame-scheduler.ts +334 -0
  84. package/src/grid-tracks.ts +165 -0
  85. package/src/image-imports.d.ts +24 -0
  86. package/src/images.ts +79 -0
  87. package/src/index.ts +28 -0
  88. package/src/jsx-dev-runtime.ts +2 -0
  89. package/src/jsx-runtime.ts +22 -0
  90. package/src/jsx.d.ts +12 -0
  91. package/src/keyed-list.ts +363 -0
  92. package/src/media-query.ts +144 -0
  93. package/src/module.ts +277 -0
  94. package/src/node-selectors.ts +114 -0
  95. package/src/owned-collections.ts +44 -0
  96. package/src/providers.ts +235 -0
  97. package/src/reactive-scope.ts +34 -0
  98. package/src/reactivity.ts +254 -0
  99. package/src/result.ts +58 -0
  100. package/src/runtime.ts +52 -0
  101. package/src/scheduler.ts +185 -0
  102. package/src/signal-kernel.ts +30 -0
  103. package/src/style-classes.ts +51 -0
  104. package/src/style-states.ts +134 -0
  105. package/src/style-variables.ts +53 -0
  106. package/src/text-children.ts +42 -0
  107. package/src/theme.ts +50 -0
  108. package/src/transition.ts +18 -0
  109. package/state/index.ts +3 -0
  110. package/state/package.json +12 -0
  111. package/state/store-bindings.ts +25 -0
  112. package/state/store.ts +82 -0
  113. package/styles/_layers.scss +14 -0
  114. package/templates/addon/README.md +14 -0
  115. package/templates/addon/__ADDON_NAME__.toc +4 -0
  116. package/templates/addon/eslint.config.mjs +12 -0
  117. package/templates/addon/gitignore +8 -0
  118. package/templates/addon/package.json +21 -0
  119. package/templates/addon/scripts/build.mjs +25 -0
  120. package/templates/addon/src/app/main.tsx +13 -0
  121. package/templates/addon/tsconfig.json +24 -0
  122. package/translate/index.ts +14 -0
  123. package/translate/package.json +9 -0
  124. package/utils/colors.ts +76 -0
  125. package/utils/format.ts +37 -0
  126. package/utils/index.ts +4 -0
  127. package/utils/number.ts +17 -0
  128. package/utils/package.json +7 -0
  129. package/utils/text.ts +6 -0
  130. package/validate/index.ts +119 -0
  131. package/validate/package.json +9 -0
  132. package/wow/absolute-position.ts +142 -0
  133. package/wow/animation.ts +428 -0
  134. package/wow/aura-button.ts +76 -0
  135. package/wow/aura-container.ts +591 -0
  136. package/wow/aura-countdown.ts +201 -0
  137. package/wow/aura-slot.ts +153 -0
  138. package/wow/bar-shade.ts +93 -0
  139. package/wow/borrowed-slot.ts +216 -0
  140. package/wow/button-drag.ts +48 -0
  141. package/wow/cast-clock.ts +153 -0
  142. package/wow/cast-text.ts +83 -0
  143. package/wow/class-colors.ts +126 -0
  144. package/wow/clock.ts +7 -0
  145. package/wow/color-picker.ts +128 -0
  146. package/wow/commands.ts +17 -0
  147. package/wow/contained-frame.ts +128 -0
  148. package/wow/contract.ts +42 -0
  149. package/wow/css-box.ts +110 -0
  150. package/wow/css-color.ts +12 -0
  151. package/wow/css-style.ts +109 -0
  152. package/wow/css-surfaces.ts +398 -0
  153. package/wow/css-text.ts +399 -0
  154. package/wow/cvar-schema.ts +32 -0
  155. package/wow/cvars.ts +98 -0
  156. package/wow/dropdown-art.ts +39 -0
  157. package/wow/element-click.ts +20 -0
  158. package/wow/element-event-coordinator.ts +219 -0
  159. package/wow/element-events.ts +317 -0
  160. package/wow/event-dispatcher.ts +151 -0
  161. package/wow/events.ts +50 -0
  162. package/wow/font-cache.ts +92 -0
  163. package/wow/frame-access.ts +31 -0
  164. package/wow/frame-layer.ts +5 -0
  165. package/wow/frames.ts +236 -0
  166. package/wow/heal-prediction.ts +305 -0
  167. package/wow/image-layers.ts +55 -0
  168. package/wow/index.ts +97 -0
  169. package/wow/layout-view.ts +651 -0
  170. package/wow/lua-string.ts +18 -0
  171. package/wow/lua-table.ts +18 -0
  172. package/wow/macro-book.ts +84 -0
  173. package/wow/map-position.ts +27 -0
  174. package/wow/media-query.ts +65 -0
  175. package/wow/module-events.ts +11 -0
  176. package/wow/native-hooks.ts +168 -0
  177. package/wow/native-placement.ts +88 -0
  178. package/wow/native.ts +135 -0
  179. package/wow/number-format.ts +8 -0
  180. package/wow/number-input.ts +10 -0
  181. package/wow/protect.ts +24 -0
  182. package/wow/protected-layout.ts +133 -0
  183. package/wow/range-art.ts +74 -0
  184. package/wow/reparent-frame.ts +99 -0
  185. package/wow/rounded-texture.ts +156 -0
  186. package/wow/saved-variables.ts +60 -0
  187. package/wow/scroll-view.ts +64 -0
  188. package/wow/secret-ref.ts +14 -0
  189. package/wow/secure-bindings.ts +89 -0
  190. package/wow/secure-clicks.ts +432 -0
  191. package/wow/secure-snippet.ts +235 -0
  192. package/wow/secure-state.ts +130 -0
  193. package/wow/secure-target-visibility.ts +89 -0
  194. package/wow/secure-transaction.ts +331 -0
  195. package/wow/special-window.ts +269 -0
  196. package/wow/start-addon.ts +99 -0
  197. package/wow/state-paint.ts +256 -0
  198. package/wow/transition.ts +86 -0
  199. package/wow/unit-button.ts +39 -0
  200. package/wow/unit-cast.ts +92 -0
  201. package/wow/unit-health-text.ts +47 -0
  202. package/wow/view-nodes.ts +304 -0
  203. package/wow/view.ts +1746 -0
  204. package/wow/visible-frame-job.ts +34 -0
  205. 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,15 @@
1
- # Temporary Holding Version
1
+ # Kumi
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Build World of Warcraft Retail addons with TypeScript and TSX. Kumi compiles to Lua 5.1 and includes a native UI renderer, reactive state, forms, validation, routing, and animations.
4
+
5
+ ```sh
6
+ npx @overmvp/kumi init MyAddon
7
+ cd MyAddon
8
+ npm install
9
+ npm run check
10
+ npm run build
11
+ ```
12
+
13
+ The starter includes ESLint and a reactive counter. Building requires Node.js 24 or newer, Rust with Cargo, and `KUMI_WOW_DOCS` pointing to an exported set of Blizzard UI documentation for your Retail client.
14
+
15
+ [Source and documentation](https://github.com/OverMVP/kumi) · [MIT license](https://opensource.org/license/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";
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@kumi/animation",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./index.ts"
8
+ },
9
+ "peerDependencies": {
10
+ "@kumi/core": "0.1.x"
11
+ }
12
+ }