@geastack/engine 0.1.5

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 (86) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +29 -0
  3. package/bitmap_font.cpp +165 -0
  4. package/canvas.cpp +4608 -0
  5. package/components/Button.d.ts +4 -0
  6. package/components/Button.tsx +32 -0
  7. package/components/Image.d.ts +3 -0
  8. package/components/Image.tsx +17 -0
  9. package/components/Text.d.ts +3 -0
  10. package/components/Text.tsx +9 -0
  11. package/components/View.d.ts +3 -0
  12. package/components/View.tsx +24 -0
  13. package/components/index.d.ts +8 -0
  14. package/components/index.ts +4 -0
  15. package/css/animation.h +252 -0
  16. package/css/declarative.h +131 -0
  17. package/css/easing.h +160 -0
  18. package/css/engine.h +223 -0
  19. package/css/interpolate.h +38 -0
  20. package/image_store.cpp +807 -0
  21. package/package.json +62 -0
  22. package/rasterized_font.cpp +570 -0
  23. package/touch_runtime.cpp +513 -0
  24. package/ui/absolute_leaf_refresh.cpp +279 -0
  25. package/ui/absolute_leaf_refresh.h +12 -0
  26. package/ui/canvas_element.cpp +2314 -0
  27. package/ui/canvas_element.h +353 -0
  28. package/ui/canvas_store.cpp +188 -0
  29. package/ui/canvas_store.h +59 -0
  30. package/ui/core.cpp +135 -0
  31. package/ui/css_atom.cpp +155 -0
  32. package/ui/css_atom.h +21 -0
  33. package/ui/dirty_regions.cpp +66 -0
  34. package/ui/dirty_regions.h +34 -0
  35. package/ui/display_invalidation.cpp +101 -0
  36. package/ui/display_invalidation.h +15 -0
  37. package/ui/document.cpp +356 -0
  38. package/ui/document.h +101 -0
  39. package/ui/image.h +16 -0
  40. package/ui/image_element.cpp +13 -0
  41. package/ui/image_node.cpp +165 -0
  42. package/ui/input.cpp +936 -0
  43. package/ui/input_render.cpp +213 -0
  44. package/ui/internal.h +567 -0
  45. package/ui/layout.cpp +2025 -0
  46. package/ui/layout_snapshot.cpp +82 -0
  47. package/ui/layout_snapshot.h +12 -0
  48. package/ui/mirror.h +25 -0
  49. package/ui/node.cpp +243 -0
  50. package/ui/node.h +154 -0
  51. package/ui/node_lifecycle.cpp +137 -0
  52. package/ui/node_lifecycle.h +13 -0
  53. package/ui/node_model.h +597 -0
  54. package/ui/refresh_perf.h +235 -0
  55. package/ui/refresh_trace.h +68 -0
  56. package/ui/render.cpp +12097 -0
  57. package/ui/root_scroll_refresh.cpp +859 -0
  58. package/ui/root_scroll_refresh.h +30 -0
  59. package/ui/state_init.h +21 -0
  60. package/ui/style.cpp +14994 -0
  61. package/ui/style.h +727 -0
  62. package/ui/style_values.h +31 -0
  63. package/ui/text.cpp +2010 -0
  64. package/ui/text.h +15 -0
  65. package/ui/text_element.cpp +15 -0
  66. package/ui/tree_events.cpp +621 -0
  67. package/ui/tree_events.h +69 -0
  68. package/ui/tree_internal.h +191 -0
  69. package/ui/tree_nodes.cpp +628 -0
  70. package/ui/tree_render.cpp +3138 -0
  71. package/ui/tree_scroll_mirror.cpp +101 -0
  72. package/ui/tree_state.cpp +574 -0
  73. package/ui/tree_state.h +235 -0
  74. package/ui/tree_style.cpp +698 -0
  75. package/ui/ui.h +9 -0
  76. package/ui/view.cpp +2232 -0
  77. package/ui/view.h +14 -0
  78. package/ui/view_element.cpp +13 -0
  79. package/ui/viewport_region.cpp +36 -0
  80. package/ui/viewport_region.h +12 -0
  81. package/ui/virtual_keyboard.cpp +908 -0
  82. package/ui/virtual_keyboard.h +59 -0
  83. package/vendor/AnimatedGIF/AnimatedGIF.c +982 -0
  84. package/vendor/AnimatedGIF/AnimatedGIF.h +216 -0
  85. package/vendor/stb/stb_image.h +7988 -0
  86. package/vendor/stb/stb_truetype.h +5079 -0
@@ -0,0 +1,4 @@
1
+ import type { ButtonProps } from '@geastack/core'
2
+
3
+ export type { ButtonProps } from '@geastack/core'
4
+ export function Button(props: ButtonProps): any
@@ -0,0 +1,32 @@
1
+ import type { ClassValue, PressHandler, Style } from '@geastack/core'
2
+
3
+ export function Button({
4
+ class: cls,
5
+ style,
6
+ pressId,
7
+ pressValue,
8
+ onPress,
9
+ onClick,
10
+ children
11
+ }: {
12
+ class?: ClassValue
13
+ style?: Style
14
+ pressId?: number
15
+ pressValue?: number
16
+ onPress?: PressHandler
17
+ onClick?: PressHandler
18
+ children?: any
19
+ }) {
20
+ return (
21
+ <button
22
+ class={cls}
23
+ style={style}
24
+ pressId={pressId}
25
+ pressValue={pressValue}
26
+ onPress={onPress}
27
+ onClick={onClick}
28
+ >
29
+ {children}
30
+ </button>
31
+ )
32
+ }
@@ -0,0 +1,3 @@
1
+ import type { ImageProps } from '@geastack/core'
2
+
3
+ export function Image(props: ImageProps): any
@@ -0,0 +1,17 @@
1
+ import type { ImageProps } from '@geastack/core'
2
+
3
+ export function Image({ class: className, src, style, fit, playing, loop, onLoad, onError, onFrame }: ImageProps) {
4
+ return (
5
+ <img
6
+ class={className}
7
+ src={src}
8
+ style={style}
9
+ fit={fit}
10
+ playing={playing}
11
+ loop={loop}
12
+ onLoad={onLoad}
13
+ onError={onError}
14
+ onFrame={onFrame}
15
+ />
16
+ )
17
+ }
@@ -0,0 +1,3 @@
1
+ import type { TextProps } from '@geastack/core'
2
+
3
+ export function Text(props: TextProps): any
@@ -0,0 +1,9 @@
1
+ import type { TextProps } from '@geastack/core'
2
+
3
+ export function Text({ class: cls, style, children }: TextProps) {
4
+ return (
5
+ <span class={cls} style={style}>
6
+ {children}
7
+ </span>
8
+ )
9
+ }
@@ -0,0 +1,3 @@
1
+ import type { ViewProps } from '@geastack/core'
2
+
3
+ export function View(props: ViewProps): any
@@ -0,0 +1,24 @@
1
+ import type { ViewProps } from '@geastack/core'
2
+
3
+ export function View({
4
+ class: cls,
5
+ style,
6
+ pressId,
7
+ pressValue,
8
+ onPress,
9
+ onClick,
10
+ children
11
+ }: ViewProps) {
12
+ return (
13
+ <div
14
+ class={cls}
15
+ style={style}
16
+ pressId={pressId}
17
+ pressValue={pressValue}
18
+ onPress={onPress}
19
+ onClick={onClick}
20
+ >
21
+ {children}
22
+ </div>
23
+ )
24
+ }
@@ -0,0 +1,8 @@
1
+ export { View } from './View'
2
+ export type { ViewProps } from '@geastack/core'
3
+ export { Text } from './Text'
4
+ export type { TextProps } from '@geastack/core'
5
+ export { Image } from './Image'
6
+ export type { ImageProps } from '@geastack/core'
7
+ export { Button } from './Button'
8
+ export type { ButtonProps } from '@geastack/core'
@@ -0,0 +1,4 @@
1
+ export { View } from './View'
2
+ export { Text } from './Text'
3
+ export { Image } from './Image'
4
+ export { Button } from './Button'
@@ -0,0 +1,252 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+ //
4
+ // gea::css — animation descriptors: a keyframe track on one node property, with
5
+ // CSS-animation timing (duration/delay/iterations/direction/fill) and an easing
6
+ // timing function. Maps a UI Property to how its value interpolates. Header-only
7
+ // (inline). Part of the gea CSS animation engine. See docs/geaos-grand-vision.md (M1).
8
+
9
+ #include <cmath>
10
+ #include <cstdint>
11
+ #include <initializer_list>
12
+ #include <vector>
13
+
14
+ #include "../ui/style.h"
15
+ #include "easing.h"
16
+ #include "interpolate.h"
17
+
18
+ namespace gea::css {
19
+
20
+ using gea::embedded::ui::Property;
21
+
22
+ // How a property's value interpolates.
23
+ enum class ValueKind : uint8_t { Scalar, Angle, Color };
24
+
25
+ inline ValueKind kindOf(Property p)
26
+ {
27
+ switch (p) {
28
+ case Property::BackgroundColor:
29
+ case Property::ActiveBackgroundColor:
30
+ case Property::Color:
31
+ case Property::BorderColor:
32
+ return ValueKind::Color;
33
+ case Property::TransformRotate:
34
+ case Property::TransformRotateX:
35
+ case Property::TransformRotateY:
36
+ return ValueKind::Angle;
37
+ default:
38
+ return ValueKind::Scalar;
39
+ }
40
+ }
41
+
42
+ enum class Direction : uint8_t { Normal, Reverse, Alternate, AlternateReverse };
43
+ enum class Fill : uint8_t { None, Forwards, Backwards, Both };
44
+
45
+ struct Keyframe {
46
+ double offset; // 0..1 along the animation
47
+ double value; // scalar/angle value; for Color, an RGB565 int stored as double
48
+ };
49
+
50
+ class KeyframeList {
51
+ public:
52
+ static constexpr std::size_t kInlineCapacity = 3;
53
+
54
+ KeyframeList() = default;
55
+
56
+ KeyframeList(std::initializer_list<Keyframe> values) { *this = values; }
57
+
58
+ KeyframeList &operator=(std::initializer_list<Keyframe> values)
59
+ {
60
+ clear();
61
+ for (const Keyframe &value : values) push_back(value);
62
+ return *this;
63
+ }
64
+
65
+ KeyframeList &operator=(const std::vector<Keyframe> &values)
66
+ {
67
+ clear();
68
+ if (values.size() <= kInlineCapacity) {
69
+ for (const Keyframe &value : values) inline_[count_++] = value;
70
+ } else {
71
+ spill_ = values;
72
+ spilled_ = true;
73
+ }
74
+ return *this;
75
+ }
76
+
77
+ bool empty() const { return size() == 0; }
78
+ std::size_t size() const { return spilled_ ? spill_.size() : count_; }
79
+
80
+ void clear()
81
+ {
82
+ count_ = 0;
83
+ if (spilled_) spill_.clear();
84
+ spilled_ = false;
85
+ }
86
+
87
+ void push_back(const Keyframe &value)
88
+ {
89
+ if (!spilled_ && count_ < kInlineCapacity) {
90
+ inline_[count_++] = value;
91
+ return;
92
+ }
93
+ if (!spilled_) {
94
+ spill_.assign(inline_, inline_ + count_);
95
+ spilled_ = true;
96
+ }
97
+ spill_.push_back(value);
98
+ }
99
+
100
+ const Keyframe &operator[](std::size_t index) const
101
+ {
102
+ return spilled_ ? spill_[index] : inline_[index];
103
+ }
104
+
105
+ Keyframe &operator[](std::size_t index)
106
+ {
107
+ return spilled_ ? spill_[index] : inline_[index];
108
+ }
109
+
110
+ const Keyframe &front() const { return (*this)[0]; }
111
+ const Keyframe &back() const { return (*this)[size() - 1]; }
112
+
113
+ private:
114
+ Keyframe inline_[kInlineCapacity]{};
115
+ std::vector<Keyframe> spill_;
116
+ std::uint8_t count_ = 0;
117
+ bool spilled_ = false;
118
+ };
119
+
120
+ // One animated property on one node. A 2-keyframe track is a CSS transition; an
121
+ // N-keyframe track is a @keyframes rule. Easing applies per segment (CSS default).
122
+ struct Animation {
123
+ int nodeId = -1;
124
+ Property property = Property::Opacity;
125
+ ValueKind kind = ValueKind::Scalar;
126
+ KeyframeList keyframes; // >= 2, sorted by offset
127
+ Easing easing = Easing::ease();
128
+ uint32_t durationMs = 300;
129
+ uint32_t delayMs = 0;
130
+ int iterations = 1; // < 0 == infinite
131
+ Direction direction = Direction::Normal;
132
+ Fill fill = Fill::None;
133
+
134
+ static Animation transition(int nodeId, Property property, double from, double to,
135
+ uint32_t durationMs, Easing easing = Easing::ease(),
136
+ uint32_t delayMs = 0)
137
+ {
138
+ Animation a;
139
+ a.nodeId = nodeId;
140
+ a.property = property;
141
+ a.kind = kindOf(property);
142
+ a.keyframes = {{0.0, from}, {1.0, to}};
143
+ a.easing = easing;
144
+ a.durationMs = durationMs;
145
+ a.delayMs = delayMs;
146
+ return a;
147
+ }
148
+ };
149
+
150
+ inline double sampleSegment(const Animation &a, const Keyframe &k0, const Keyframe &k1, double p)
151
+ {
152
+ const double span = k1.offset - k0.offset;
153
+ const double localT = span > 1e-9 ? (p - k0.offset) / span : 0.0;
154
+ const double eased = a.easing.kind() == EasingKind::Linear ? localT : a.easing(localT);
155
+
156
+ if (a.kind == ValueKind::Color) {
157
+ return static_cast<double>(
158
+ lerpColor565(static_cast<int>(std::llround(k0.value)), static_cast<int>(std::llround(k1.value)), eased));
159
+ }
160
+ return lerp(k0.value, k1.value, eased);
161
+ }
162
+
163
+ // Sample the property value at timeline progress p (0..1 within one iteration):
164
+ // find the bracketing keyframes, ease the in-segment progress, interpolate per
165
+ // kind. Returns the value to apply (degrees for Angle, RGB565 for Color).
166
+ inline double sampleTrack(const Animation &a, double p)
167
+ {
168
+ const auto &kf = a.keyframes;
169
+ const std::size_t count = kf.size();
170
+ if (count == 0) return 0.0;
171
+ if (count == 1) return kf[0].value;
172
+ if (count == 2) {
173
+ const Keyframe &k0 = kf[0];
174
+ const Keyframe &k1 = kf[1];
175
+ if (p <= k0.offset) return k0.value;
176
+ if (p >= k1.offset) return k1.value;
177
+ return sampleSegment(a, k0, k1, p);
178
+ }
179
+ if (p <= kf.front().offset) return kf.front().value;
180
+ if (p >= kf.back().offset) return kf.back().value;
181
+
182
+ std::size_t i = 0;
183
+ if (count == 3 && p >= kf[1].offset) {
184
+ i = 1;
185
+ } else if (count > 3) {
186
+ while (i + 1 < count && kf[i + 1].offset <= p) ++i;
187
+ }
188
+
189
+ const Keyframe &k0 = kf[i];
190
+ const Keyframe &k1 = kf[i + 1];
191
+ return sampleSegment(a, k0, k1, p);
192
+ }
193
+
194
+ // Timeline state of an animation at a given elapsed time (since it started).
195
+ struct Progress {
196
+ bool active; // should a value be applied this frame? (false before start w/o backwards fill)
197
+ bool done; // all iterations complete
198
+ double p; // iteration progress 0..1, already direction-adjusted
199
+ };
200
+
201
+ namespace detail {
202
+ // Apply direction to a raw in-iteration fraction (CSS animation-direction).
203
+ inline double directionAdjust(Direction dir, long iterationIndex, double frac)
204
+ {
205
+ bool reverse = false;
206
+ switch (dir) {
207
+ case Direction::Normal:
208
+ reverse = false;
209
+ break;
210
+ case Direction::Reverse:
211
+ reverse = true;
212
+ break;
213
+ case Direction::Alternate:
214
+ reverse = (iterationIndex % 2) == 1;
215
+ break;
216
+ case Direction::AlternateReverse:
217
+ reverse = (iterationIndex % 2) == 0;
218
+ break;
219
+ }
220
+ return reverse ? 1.0 - frac : frac;
221
+ }
222
+ } // namespace detail
223
+
224
+ // Compute the CSS-animation progress at `elapsedMs` since start: honors delay,
225
+ // duration, iteration count (negative == infinite), and direction
226
+ // (normal/reverse/alternate). `p` is the value to feed sampleTrack().
227
+ inline Progress computeProgress(const Animation &a, double elapsedMs)
228
+ {
229
+ const double dur = a.durationMs <= 0 ? 1.0 : static_cast<double>(a.durationMs);
230
+
231
+ // Before the start delay: only meaningful if filling backwards.
232
+ if (elapsedMs < static_cast<double>(a.delayMs)) {
233
+ const bool fillBack = a.fill == Fill::Backwards || a.fill == Fill::Both;
234
+ return {fillBack, false, detail::directionAdjust(a.direction, 0, 0.0)};
235
+ }
236
+
237
+ const double activeMs = elapsedMs - static_cast<double>(a.delayMs);
238
+ const double iterF = activeMs / dur;
239
+
240
+ // Finite and complete: hold the final value iff filling forwards.
241
+ if (a.iterations >= 0 && iterF >= static_cast<double>(a.iterations)) {
242
+ const bool fillFwd = a.fill == Fill::Forwards || a.fill == Fill::Both;
243
+ const long lastIter = a.iterations > 0 ? a.iterations - 1 : 0;
244
+ return {fillFwd, true, detail::directionAdjust(a.direction, lastIter, 1.0)};
245
+ }
246
+
247
+ const long idx = static_cast<long>(iterF);
248
+ const double frac = iterF - static_cast<double>(idx);
249
+ return {true, false, detail::directionAdjust(a.direction, idx, frac)};
250
+ }
251
+
252
+ } // namespace gea::css
@@ -0,0 +1,131 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+ //
4
+ // gea::css — declarative animations from DOM data-attributes.
5
+ //
6
+ // ESP32 applications are TSX→C++ (geatsc) and reach native code only via the
7
+ // gea::host::* binding layer. Rather than thread a gea.animate() host call through
8
+ // several geatsc lowering files, we lean on a capability geatsc already has: it
9
+ // forwards arbitrary *static* JSX attributes to NodeHandle::setAttribute (the
10
+ // renderer ignores unknown attributes, but getAttribute reads them back). So apps
11
+ // annotate elements declaratively:
12
+ //
13
+ // <div id="b" data-anim="rotate" data-anim-from="0" data-anim-to="360"
14
+ // data-anim-dur="1500" data-anim-ease="linear" data-anim-iter="-1" />
15
+ //
16
+ // and this scanner walks the mounted tree once after the app mounts, parses those
17
+ // attributes, and starts the corresponding gea::css animations (which the runtime
18
+ // already ticks every frame). Header-only so it links into runtime/launch-surface
19
+ // TUs without a build source-list change. Reusable by any app (watch face,
20
+ // settings, the showcase). See docs/geaos-grand-vision.md (§8c, M3).
21
+
22
+ #include <cstdint>
23
+ #include <cstdlib>
24
+ #include <cstring>
25
+
26
+ #include "engine.h"
27
+ #include "ui/tree_internal.h"
28
+
29
+ namespace gea::css {
30
+
31
+ class DeclarativeAnimations {
32
+ public:
33
+ // Walk the mounted tree for [data-anim] elements and start each one's animation.
34
+ // Call once after an app mounts; nowMs is the current frame clock.
35
+ static void scanAndStart(uint32_t nowMs)
36
+ {
37
+ gea::embedded::ui::Tree &tree = gea::embedded::ui::Tree::instance();
38
+ const int count = tree.nodeCount();
39
+ for (int id = 0; id < count; ++id) {
40
+ const char *kind = tree.getAttribute(id, "data-anim");
41
+ if (!kind || kind[0] == '\0') continue;
42
+ startForNode(tree, id, kind, nowMs);
43
+ }
44
+ }
45
+
46
+ private:
47
+ static int attrInt(gea::embedded::ui::Tree &tree, int id, const char *name, int def)
48
+ {
49
+ const char *v = tree.getAttribute(id, name);
50
+ if (!v || v[0] == '\0') return def;
51
+ if (v[0] == '#') return static_cast<int>(std::strtol(v + 1, nullptr, 16));
52
+ return static_cast<int>(std::strtol(v, nullptr, 0)); // base 0 → 0x.. auto-detected
53
+ }
54
+
55
+ static Easing easingFromAttr(const char *name)
56
+ {
57
+ if (!name || name[0] == '\0') return Easing::ease();
58
+ if (!std::strcmp(name, "linear")) return Easing::linear();
59
+ if (!std::strcmp(name, "ease")) return Easing::ease();
60
+ if (!std::strcmp(name, "ease-in")) return Easing::easeIn();
61
+ if (!std::strcmp(name, "ease-out")) return Easing::easeOut();
62
+ if (!std::strcmp(name, "ease-in-out")) return Easing::easeInOut();
63
+ if (!std::strncmp(name, "steps(", 6)) {
64
+ const int n = static_cast<int>(std::strtol(name + 6, nullptr, 10));
65
+ return Easing::steps(n > 0 ? n : 1);
66
+ }
67
+ if (!std::strncmp(name, "cubic-bezier(", 13)) {
68
+ const char *p = name + 13;
69
+ char *end = nullptr;
70
+ const double x1 = std::strtod(p, &end);
71
+ const double y1 = (end && *end == ',') ? std::strtod(end + 1, &end) : 0.0;
72
+ const double x2 = (end && *end == ',') ? std::strtod(end + 1, &end) : 1.0;
73
+ const double y2 = (end && *end == ',') ? std::strtod(end + 1, &end) : 1.0;
74
+ return Easing::cubicBezier(x1, y1, x2, y2);
75
+ }
76
+ return Easing::ease();
77
+ }
78
+
79
+ static Direction directionFromAttr(const char *dir)
80
+ {
81
+ if (!dir || dir[0] == '\0') return Direction::Normal;
82
+ if (!std::strcmp(dir, "alternate")) return Direction::Alternate;
83
+ if (!std::strcmp(dir, "alternate-reverse")) return Direction::AlternateReverse;
84
+ if (!std::strcmp(dir, "reverse")) return Direction::Reverse;
85
+ return Direction::Normal;
86
+ }
87
+
88
+ static void startForNode(gea::embedded::ui::Tree &tree, int id, const char *kind, uint32_t nowMs)
89
+ {
90
+ using Property = gea::embedded::ui::Property;
91
+
92
+ const int from = attrInt(tree, id, "data-anim-from", 0);
93
+ const int to = attrInt(tree, id, "data-anim-to", 0);
94
+ const int dur = attrInt(tree, id, "data-anim-dur", 1000);
95
+ const int iter = attrInt(tree, id, "data-anim-iter", -1);
96
+ const int delay = attrInt(tree, id, "data-anim-delay", 0);
97
+ const Easing ease = easingFromAttr(tree.getAttribute(id, "data-anim-ease"));
98
+ const Direction dir = directionFromAttr(tree.getAttribute(id, "data-anim-dir"));
99
+
100
+ auto startOne = [&](Property prop, int f, int t) {
101
+ Animation a = Animation::transition(id, prop, f, t, static_cast<uint32_t>(dur > 0 ? dur : 1),
102
+ ease, static_cast<uint32_t>(delay < 0 ? 0 : delay));
103
+ a.iterations = iter;
104
+ a.direction = dir;
105
+ AnimationEngine::instance().start(a, nowMs);
106
+ };
107
+
108
+ if (!std::strcmp(kind, "rotate"))
109
+ startOne(Property::TransformRotate, from, to);
110
+ else if (!std::strcmp(kind, "opacity"))
111
+ startOne(Property::Opacity, from, to);
112
+ else if (!std::strcmp(kind, "color"))
113
+ startOne(Property::Color, from, to);
114
+ else if (!std::strcmp(kind, "bg") || !std::strcmp(kind, "background"))
115
+ startOne(Property::BackgroundColor, from, to);
116
+ else if (!std::strcmp(kind, "width"))
117
+ startOne(Property::Width, from, to);
118
+ else if (!std::strcmp(kind, "height"))
119
+ startOne(Property::Height, from, to);
120
+ else if (!std::strcmp(kind, "left") || !std::strcmp(kind, "translateX"))
121
+ startOne(Property::Left, from, to);
122
+ else if (!std::strcmp(kind, "top") || !std::strcmp(kind, "translateY"))
123
+ startOne(Property::Top, from, to);
124
+ else if (!std::strcmp(kind, "scale")) { // no transform-scale property → drive width+height
125
+ startOne(Property::Width, from, to);
126
+ startOne(Property::Height, from, to);
127
+ }
128
+ }
129
+ };
130
+
131
+ } // namespace gea::css
package/css/easing.h ADDED
@@ -0,0 +1,160 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+ //
4
+ // gea::css — CSS-style timing functions (easing). Header-only (inline) so the
5
+ // engine links into any TU that uses it without a build-system source-list
6
+ // change. Part of the gea CSS transitions/keyframes/animation engine.
7
+ // See docs/geaos-grand-vision.md (M1).
8
+ //
9
+ // Maps linear progress t∈[0,1] to eased progress, matching the CSS
10
+ // <easing-function> grammar: the cubic-bezier() presets (linear/ease/ease-in/
11
+ // ease-out/ease-in-out), parametric cubic-bezier(x1,y1,x2,y2), steps(n,
12
+ // jumpterm), and a custom function escape hatch.
13
+
14
+ #include <cmath>
15
+ #include <cstdint>
16
+
17
+ namespace gea::css {
18
+
19
+ enum class EasingKind : uint8_t { Linear, CubicBezier, Steps, Custom };
20
+ enum class StepPosition : uint8_t { JumpStart, JumpEnd, JumpNone, JumpBoth };
21
+
22
+ using CustomEasingFn = double (*)(double t);
23
+
24
+ namespace detail {
25
+ inline double clamp01(double t) { return t < 0.0 ? 0.0 : (t > 1.0 ? 1.0 : t); }
26
+
27
+ // Cubic bezier with endpoints P0=0, P3=1 and one interior control value.
28
+ inline double bezierAxis(double c1, double c2, double t)
29
+ {
30
+ const double u = 1.0 - t;
31
+ return 3.0 * u * u * t * c1 + 3.0 * u * t * t * c2 + t * t * t;
32
+ }
33
+ inline double bezierAxisDeriv(double c1, double c2, double t)
34
+ {
35
+ const double u = 1.0 - t;
36
+ return 3.0 * u * u * c1 + 6.0 * u * t * (c2 - c1) + 3.0 * t * t * (1.0 - c2);
37
+ }
38
+ // Solve the cubic-bezier timing function for y given x (= input progress).
39
+ inline double solveCubicBezier(double x1, double y1, double x2, double y2, double x)
40
+ {
41
+ if (x <= 0.0) return 0.0;
42
+ if (x >= 1.0) return 1.0;
43
+ double s = x; // Newton-Raphson
44
+ for (int i = 0; i < 8; ++i) {
45
+ const double xs = bezierAxis(x1, x2, s) - x;
46
+ if (std::fabs(xs) < 1e-6) break;
47
+ const double d = bezierAxisDeriv(x1, x2, s);
48
+ if (std::fabs(d) < 1e-6) break;
49
+ s -= xs / d;
50
+ }
51
+ if (s < 0.0 || s > 1.0) { // bisection fallback
52
+ double lo = 0.0, hi = 1.0;
53
+ for (int i = 0; i < 24; ++i) {
54
+ s = 0.5 * (lo + hi);
55
+ const double xs = bezierAxis(x1, x2, s);
56
+ if (std::fabs(xs - x) < 1e-6) break;
57
+ if (xs < x)
58
+ lo = s;
59
+ else
60
+ hi = s;
61
+ }
62
+ }
63
+ return bezierAxis(y1, y2, s);
64
+ }
65
+ } // namespace detail
66
+
67
+ class Easing {
68
+ public:
69
+ constexpr Easing() = default;
70
+
71
+ static Easing linear()
72
+ {
73
+ Easing e;
74
+ e.kind_ = EasingKind::Linear;
75
+ return e;
76
+ }
77
+ static Easing cubicBezier(double x1, double y1, double x2, double y2)
78
+ {
79
+ Easing e;
80
+ e.kind_ = EasingKind::CubicBezier;
81
+ e.bx1_ = x1;
82
+ e.by1_ = y1;
83
+ e.bx2_ = x2;
84
+ e.by2_ = y2;
85
+ return e;
86
+ }
87
+ static Easing ease() { return cubicBezier(0.25, 0.1, 0.25, 1.0); }
88
+ static Easing easeIn() { return cubicBezier(0.42, 0.0, 1.0, 1.0); }
89
+ static Easing easeOut() { return cubicBezier(0.0, 0.0, 0.58, 1.0); }
90
+ static Easing easeInOut() { return cubicBezier(0.42, 0.0, 0.58, 1.0); }
91
+ static Easing steps(int count, StepPosition position = StepPosition::JumpEnd)
92
+ {
93
+ Easing e;
94
+ e.kind_ = EasingKind::Steps;
95
+ e.steps_ = count < 1 ? 1 : count;
96
+ e.stepPosition_ = position;
97
+ return e;
98
+ }
99
+ static Easing custom(CustomEasingFn fn)
100
+ {
101
+ Easing e;
102
+ e.kind_ = EasingKind::Custom;
103
+ e.custom_ = fn;
104
+ return e;
105
+ }
106
+
107
+ double operator()(double t) const { return eval(t); }
108
+ EasingKind kind() const { return kind_; }
109
+
110
+ double eval(double t) const
111
+ {
112
+ t = detail::clamp01(t);
113
+ switch (kind_) {
114
+ case EasingKind::Linear:
115
+ return t;
116
+ case EasingKind::CubicBezier: {
117
+ // One-entry memo: the per-property tracks of one CSS animation evaluate the
118
+ // IDENTICAL curve at the IDENTICAL t within a tick (a transform spin
119
+ // registers rotateX/rotateY/rotateZ as separate tracks), and the
120
+ // double-precision iterative solve is soft-float on the LX7 (~50us each).
121
+ // Animations tick only on the frame task, so a plain static is safe.
122
+ static double mT = -2.0, mX1 = 0, mY1 = 0, mX2 = 0, mY2 = 0, mOut = 0;
123
+ if (t == mT && bx1_ == mX1 && by1_ == mY1 && bx2_ == mX2 && by2_ == mY2) return mOut;
124
+ mT = t;
125
+ mX1 = bx1_;
126
+ mY1 = by1_;
127
+ mX2 = bx2_;
128
+ mY2 = by2_;
129
+ mOut = detail::solveCubicBezier(bx1_, by1_, bx2_, by2_, t);
130
+ return mOut;
131
+ }
132
+ case EasingKind::Steps: {
133
+ const double n = static_cast<double>(steps_);
134
+ switch (stepPosition_) {
135
+ case StepPosition::JumpStart:
136
+ return detail::clamp01(std::ceil(t * n) / n);
137
+ case StepPosition::JumpEnd:
138
+ return detail::clamp01(std::floor(t * n) / n);
139
+ case StepPosition::JumpNone:
140
+ return steps_ <= 1 ? 0.0 : detail::clamp01(std::floor(t * n) / (n - 1.0));
141
+ case StepPosition::JumpBoth:
142
+ return detail::clamp01((std::floor(t * n) + 1.0) / (n + 1.0));
143
+ }
144
+ return t;
145
+ }
146
+ case EasingKind::Custom:
147
+ return custom_ ? detail::clamp01(custom_(t)) : t;
148
+ }
149
+ return t;
150
+ }
151
+
152
+ private:
153
+ EasingKind kind_ = EasingKind::Linear;
154
+ double bx1_ = 0.0, by1_ = 0.0, bx2_ = 1.0, by2_ = 1.0;
155
+ int steps_ = 1;
156
+ StepPosition stepPosition_ = StepPosition::JumpEnd;
157
+ CustomEasingFn custom_ = nullptr;
158
+ };
159
+
160
+ } // namespace gea::css