@typecad/ui 1.0.0-alpha.13 → 1.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1457 -1469
- package/dist/cli.js +22 -19
- package/dist/preview/host-ui-runtime.js +0 -1
- package/dist/ui-engine/model.js +7 -1
- package/dist/ui-engine/runtime-header/canvas-scrollbar.js +115 -115
- package/dist/ui-engine/runtime-header/dirty-scroll-mutators.js +182 -182
- package/dist/ui-engine/runtime-header/forward-decls.js +227 -216
- package/dist/ui-engine/runtime-header/init-press-input.js +138 -138
- package/dist/ui-engine/runtime-header/keyboard.js +676 -676
- package/dist/ui-engine/runtime-header/node-draw-body.js +1658 -1656
- package/dist/ui-engine/runtime-header/paint-order-coords.js +259 -259
- package/dist/ui-engine/runtime-header/paint-rects-repair.js +736 -736
- package/dist/ui-engine/runtime-header/scroll-physics.js +4 -4
- package/dist/ui-engine/runtime-header/structs.js +228 -228
- package/dist/ui-engine/runtime-header/text-rendering.js +888 -888
- package/dist/ui-engine/runtime-header/tick/bindings-phase.js +118 -118
- package/dist/ui-engine/runtime-header/tick/dirty-draw-phase.js +896 -896
- package/dist/ui-engine/runtime-header/tick/scroll-canvas-phase.js +24 -24
- package/dist/ui-engine/runtime-header/touch-keyboard-fwd.js +11 -11
- package/dist/ui-engine/runtime-header/types-defines.js +110 -110
- package/dist/ui-engine/shadcn-kit.d.ts +1 -1
- package/dist/ui-engine/shadcn-kit.js +4 -0
- package/dist/ui-engine/ui-lowering.d.ts +1 -1
- package/dist/ui-engine/ui-lowering.js +14 -5
- package/dist/ui-engine/ui-registry.js +9 -1
- package/dist/wizard/display-catalog.d.ts +0 -3
- package/dist/wizard/display-catalog.js +3 -12
- package/dist/wizard/index.d.ts +2 -0
- package/dist/wizard/index.js +1 -0
- package/dist/wizard/integration-wizard.d.ts +3 -0
- package/dist/wizard/integration-wizard.js +69 -20
- package/dist/wizard/package-writer.d.ts +20 -0
- package/dist/wizard/package-writer.js +79 -0
- package/package.json +4 -4
- package/src/cli.ts +90 -87
- package/src/preview/host-ui-runtime.ts +0 -1
- package/src/ui-engine/model.ts +6 -1
- package/src/ui-engine/runtime-header/canvas-scrollbar.ts +121 -121
- package/src/ui-engine/runtime-header/dirty-scroll-mutators.ts +188 -188
- package/src/ui-engine/runtime-header/forward-decls.ts +238 -227
- package/src/ui-engine/runtime-header/init-press-input.ts +144 -144
- package/src/ui-engine/runtime-header/keyboard.ts +689 -689
- package/src/ui-engine/runtime-header/node-draw-body.ts +1683 -1681
- package/src/ui-engine/runtime-header/paint-order-coords.ts +265 -265
- package/src/ui-engine/runtime-header/paint-rects-repair.ts +742 -742
- package/src/ui-engine/runtime-header/scroll-physics.ts +4 -4
- package/src/ui-engine/runtime-header/structs.ts +234 -234
- package/src/ui-engine/runtime-header/text-rendering.ts +894 -894
- package/src/ui-engine/runtime-header/tick/bindings-phase.ts +124 -124
- package/src/ui-engine/runtime-header/tick/dirty-draw-phase.ts +902 -902
- package/src/ui-engine/runtime-header/tick/scroll-canvas-phase.ts +30 -30
- package/src/ui-engine/runtime-header/touch-keyboard-fwd.ts +11 -11
- package/src/ui-engine/runtime-header/types-defines.ts +116 -116
- package/src/ui-engine/shadcn-kit.ts +4 -0
- package/src/ui-engine/ui-lowering.ts +12 -4
- package/src/ui-engine/ui-registry.ts +9 -1
- package/src/wizard/display-catalog.ts +261 -273
- package/src/wizard/index.ts +46 -38
- package/src/wizard/integration-wizard.ts +679 -619
- package/src/wizard/package-writer.ts +98 -0
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
// Slice of the C++ runtime header (original source lines 5279-5287).
|
|
2
|
-
// scrollbar + buffered scroll canvas push.
|
|
3
|
-
// See docs/superpowers/specs/2026-07-12-split-runtime-header-design.md.
|
|
4
|
-
export function emitTickScrollCanvasPhase(): string {
|
|
5
|
-
return `
|
|
6
|
-
// ②b Draw scrollbar + push canvas for the buffered scroll container.
|
|
7
|
-
if (bufferedScrollNode >= 0 && bufferedScrollCanvas) {
|
|
8
|
-
ui_push_buffered_scroll_canvas(bufferedScrollCanvas, bufferedScrollRepaintCanvas,
|
|
9
|
-
bufferedScrollNode, bufferedScrollVX, bufferedScrollVY,
|
|
10
|
-
bufferedScrollRepaintY, bufferedScrollRepaintH, __ui_draw_target);
|
|
11
|
-
} else if (bufferedScrollNode >= 0 && bufferedScrollBands) {
|
|
12
|
-
// Band render fallback: the main loop didn't trigger it at the owner's
|
|
13
|
-
// z-slot (e.g. the owner was filtered out after dispatch). Render now so
|
|
14
|
-
// the subtree is never left unpainted. ui_render_scroll_bands sets
|
|
15
|
-
// lastPaintedScrollY itself on success; only the failure fallback (band
|
|
16
|
-
// canvas wouldn't allocate) needs to record the scrollY here so the next
|
|
17
|
-
// frame's delta is correct.
|
|
18
|
-
if (!ui_render_scroll_bands(static_cast<uint16_t>(bufferedScrollNode))) {
|
|
19
|
-
// No band canvas means there is no coherent frame to submit. Retain the
|
|
20
|
-
// previous viewport rather than drawing the scrollbar/direct subtree to
|
|
21
|
-
// the live SPI target, which would reintroduce tearing.
|
|
22
|
-
if (__ui_scroll_render_locked) __ui_scroll_render_locked[static_cast<uint16_t>(bufferedScrollNode)] = 1;
|
|
23
|
-
__ui_nodes[bufferedScrollNode].dirty = 0;
|
|
24
|
-
}
|
|
25
|
-
} else if (bufferedScrollNode >= 0 && bufferedScrollDirectFull) {
|
|
26
|
-
// The direct-full path is intentionally disabled for tear-sensitive scroll
|
|
27
|
-
// rendering. Keep the retained pixels when no compositor is available.
|
|
28
|
-
if (__ui_scroll_render_locked) __ui_scroll_render_locked[static_cast<uint16_t>(bufferedScrollNode)] = 1;
|
|
29
|
-
__ui_nodes[bufferedScrollNode].dirty = 0;`;
|
|
30
|
-
}
|
|
1
|
+
// Slice of the C++ runtime header (original source lines 5279-5287).
|
|
2
|
+
// scrollbar + buffered scroll canvas push.
|
|
3
|
+
// See docs/superpowers/specs/2026-07-12-split-runtime-header-design.md.
|
|
4
|
+
export function emitTickScrollCanvasPhase(): string {
|
|
5
|
+
return `
|
|
6
|
+
// ②b Draw scrollbar + push canvas for the buffered scroll container.
|
|
7
|
+
if (bufferedScrollNode >= 0 && bufferedScrollCanvas) {
|
|
8
|
+
ui_push_buffered_scroll_canvas(bufferedScrollCanvas, bufferedScrollRepaintCanvas,
|
|
9
|
+
bufferedScrollNode, bufferedScrollVX, bufferedScrollVY,
|
|
10
|
+
bufferedScrollRepaintY, bufferedScrollRepaintH, __ui_draw_target);
|
|
11
|
+
} else if (bufferedScrollNode >= 0 && bufferedScrollBands) {
|
|
12
|
+
// Band render fallback: the main loop didn't trigger it at the owner's
|
|
13
|
+
// z-slot (e.g. the owner was filtered out after dispatch). Render now so
|
|
14
|
+
// the subtree is never left unpainted. ui_render_scroll_bands sets
|
|
15
|
+
// lastPaintedScrollY itself on success; only the failure fallback (band
|
|
16
|
+
// canvas wouldn't allocate) needs to record the scrollY here so the next
|
|
17
|
+
// frame's delta is correct.
|
|
18
|
+
if (!ui_render_scroll_bands(static_cast<uint16_t>(bufferedScrollNode))) {
|
|
19
|
+
// No band canvas means there is no coherent frame to submit. Retain the
|
|
20
|
+
// previous viewport rather than drawing the scrollbar/direct subtree to
|
|
21
|
+
// the live SPI target, which would reintroduce tearing.
|
|
22
|
+
if (__ui_scroll_render_locked) __ui_scroll_render_locked[static_cast<uint16_t>(bufferedScrollNode)] = 1;
|
|
23
|
+
__ui_nodes[bufferedScrollNode].dirty = 0;
|
|
24
|
+
}
|
|
25
|
+
} else if (bufferedScrollNode >= 0 && bufferedScrollDirectFull) {
|
|
26
|
+
// The direct-full path is intentionally disabled for tear-sensitive scroll
|
|
27
|
+
// rendering. Keep the retained pixels when no compositor is available.
|
|
28
|
+
if (__ui_scroll_render_locked) __ui_scroll_render_locked[static_cast<uint16_t>(bufferedScrollNode)] = 1;
|
|
29
|
+
__ui_nodes[bufferedScrollNode].dirty = 0;`;
|
|
30
|
+
}
|
|
@@ -26,7 +26,7 @@ extern const uint16_t __ui_rangechange_handler_count;
|
|
|
26
26
|
|
|
27
27
|
// Touch state machine: tracks down → hold → up → click lifecycle
|
|
28
28
|
// Touch node/scroll node state is defined near navigation because ui_navigate resets it.
|
|
29
|
-
static uint32_t __ui_touch_down_time = 0; //
|
|
29
|
+
static uint32_t __ui_touch_down_time = 0; // __tc_now_ms() when touch started
|
|
30
30
|
static int16_t __ui_touch_down_y_pos = 0; // Y position when touch started (for tap vs drag detection)
|
|
31
31
|
static uint32_t __ui_last_touch_time = 0; // for debounce (updated on touch down only)
|
|
32
32
|
static uint32_t __ui_last_release_time = 0; // for release debounce
|
|
@@ -174,13 +174,13 @@ static void ui_touch_down(int16_t tx, int16_t ty) {
|
|
|
174
174
|
// option rows. No hit-test/press/scroll while the overlay is open.
|
|
175
175
|
if (__ui_select_menu >= 0) {
|
|
176
176
|
__ui_touch_state = 1;
|
|
177
|
-
__ui_touch_down_time =
|
|
177
|
+
__ui_touch_down_time = __tc_now_ms();
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
180
|
int16_t node = ui_hit_test(tx, ty);
|
|
181
181
|
__ui_touch_node = node;
|
|
182
182
|
__ui_touch_state = 1;
|
|
183
|
-
__ui_touch_down_time =
|
|
183
|
+
__ui_touch_down_time = __tc_now_ms();
|
|
184
184
|
__ui_touch_down_y_pos = ty;
|
|
185
185
|
__ui_drag_start_x = tx;
|
|
186
186
|
__ui_drag_start_y = ty;
|
|
@@ -215,7 +215,7 @@ static void ui_touch_down(int16_t tx, int16_t ty) {
|
|
|
215
215
|
int16_t usable = __ui_nodes[node].box.w - 8;
|
|
216
216
|
if (usable <= 0) usable = 1;
|
|
217
217
|
int16_t nextVal = rMin + (static_cast<int32_t>(relX) * range) / usable;
|
|
218
|
-
nextVal =
|
|
218
|
+
nextVal = __ui_constrain(nextVal, rMin, rMax);
|
|
219
219
|
if (nextVal != __ui_nodes[node].value) {
|
|
220
220
|
__ui_nodes[node].value = nextVal;
|
|
221
221
|
ui_mark_dirty(node);
|
|
@@ -261,7 +261,7 @@ static void ui_touch_up() {
|
|
|
261
261
|
if (__ui_select_menu >= 0) {
|
|
262
262
|
ui_select_menu_tap(__ui_last_touch_x, __ui_last_touch_y);
|
|
263
263
|
__ui_touch_state = 0;
|
|
264
|
-
__ui_last_touch_time =
|
|
264
|
+
__ui_last_touch_time = __tc_now_ms();
|
|
265
265
|
return;
|
|
266
266
|
}
|
|
267
267
|
#if !defined(UI_HIDE_OSK)
|
|
@@ -269,11 +269,11 @@ static void ui_touch_up() {
|
|
|
269
269
|
ui_kb_handle_tap(__ui_last_touch_x, __ui_last_touch_y);
|
|
270
270
|
__ui_kb_bs_held = 0;
|
|
271
271
|
__ui_touch_state = 0;
|
|
272
|
-
__ui_last_touch_time =
|
|
272
|
+
__ui_last_touch_time = __tc_now_ms();
|
|
273
273
|
return;
|
|
274
274
|
}
|
|
275
275
|
#endif
|
|
276
|
-
uint32_t elapsed =
|
|
276
|
+
uint32_t elapsed = __tc_now_ms() - __ui_touch_down_time;
|
|
277
277
|
// Release the scroll owner: arm a bounded settle (bounce-back / edge-snap).
|
|
278
278
|
// No fling — motion ends with the finger (the settle animation is the only
|
|
279
279
|
// post-lift motion, terminating within UI_SCROLL_SETTLE_MS).
|
|
@@ -353,7 +353,7 @@ static void ui_touch_up() {
|
|
|
353
353
|
// Called each frame from ui_poll_touch when touch is detected.
|
|
354
354
|
// Implements debounce + the down/hold/up/click state machine.
|
|
355
355
|
static inline void ui_handle_touch(int16_t tx, int16_t ty) {
|
|
356
|
-
uint32_t now =
|
|
356
|
+
uint32_t now = __tc_now_ms();
|
|
357
357
|
// Track last touch coords for tap-up routing.
|
|
358
358
|
__ui_last_touch_x = tx;
|
|
359
359
|
__ui_last_touch_y = ty;
|
|
@@ -404,7 +404,7 @@ static inline void ui_handle_touch(int16_t tx, int16_t ty) {
|
|
|
404
404
|
int16_t usable = __ui_nodes[__ui_range_node].box.w - 8;
|
|
405
405
|
if (usable <= 0) usable = 1;
|
|
406
406
|
int16_t newVal = rMin + (static_cast<int32_t>(relX) * range) / usable;
|
|
407
|
-
newVal =
|
|
407
|
+
newVal = __ui_constrain(newVal, rMin, rMax);
|
|
408
408
|
if (newVal != __ui_nodes[__ui_range_node].value) {
|
|
409
409
|
__ui_nodes[__ui_range_node].value = newVal;
|
|
410
410
|
ui_mark_dirty(__ui_range_node);
|
|
@@ -457,9 +457,9 @@ static inline void ui_handle_no_touch() {
|
|
|
457
457
|
if (__ui_touch_state != 0) {
|
|
458
458
|
// Debounce: require a gap since the last release before processing another.
|
|
459
459
|
// This prevents crash from rapid touch/no-touch flicker on resistive screens.
|
|
460
|
-
if (
|
|
460
|
+
if (__tc_now_ms() - __ui_last_release_time < UI_TOUCH_DEBOUNCE_MS) return;
|
|
461
461
|
ui_touch_up();
|
|
462
|
-
__ui_last_release_time =
|
|
462
|
+
__ui_last_release_time = __tc_now_ms();
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
|
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
// Slice of the C++ runtime header (original source lines 17-89).
|
|
2
|
-
// Guard open, includes, and #define knobs.
|
|
3
|
-
// See docs/superpowers/specs/2026-07-12-split-runtime-header-design.md.
|
|
4
|
-
export function emitTypesDefines(): string {
|
|
5
|
-
return `
|
|
6
|
-
// ── Cuttlefish UI runtime (emit once per TU) ──────────────────────────────
|
|
7
|
-
#ifndef __TC_UI_RUNTIME
|
|
8
|
-
#define __TC_UI_RUNTIME
|
|
9
|
-
#include <stdint.h>
|
|
10
|
-
#include <cstring>
|
|
11
|
-
#include <new>
|
|
12
|
-
#define UI_TEXT_BUF 32 // max stored UI text chars, excluding the trailing NUL
|
|
13
|
-
#define UI_TEXT_LINE_BUF 96
|
|
14
|
-
#define UI_WS_NORMAL 0
|
|
15
|
-
#define UI_WS_NOWRAP 1
|
|
16
|
-
#define UI_WS_PRE 2
|
|
17
|
-
#define UI_WS_PRE_LINE 3
|
|
18
|
-
#ifndef UI_MAX_BUFFERED_PAINT_PIXELS
|
|
19
|
-
#define UI_MAX_BUFFERED_PAINT_PIXELS 20000
|
|
20
|
-
#endif
|
|
21
|
-
// Above this many pixels, prefer the band renderer (small ~10KB SRAM canvas,
|
|
22
|
-
// strip-at-a-time) over the repair canvas even when the repair canvas could
|
|
23
|
-
// allocate (e.g. in PSRAM). A large repair canvas (a full-width button is
|
|
24
|
-
// ~15-30KB) has higher alloc/seed/push latency than banding — the per-band
|
|
25
|
-
// push is smaller and the band canvas lives in fast internal SRAM. Set below
|
|
26
|
-
// UI_MAX_BUFFERED_PAINT_PIXELS so large rects band while small repaints keep
|
|
27
|
-
// the fast single-canvas composite. Tune per target; 0 = always prefer the
|
|
28
|
-
// repair canvas when it allocates (the pre-PSRAM behavior).
|
|
29
|
-
#ifndef UI_BAND_PREFER_PIXELS
|
|
30
|
-
#define UI_BAND_PREFER_PIXELS 8000
|
|
31
|
-
#endif
|
|
32
|
-
#ifndef UI_USE_FULL_FRAMEBUFFER
|
|
33
|
-
#define UI_USE_FULL_FRAMEBUFFER 0
|
|
34
|
-
#endif
|
|
35
|
-
#ifndef UI_TRANSITION_SNAP_MS
|
|
36
|
-
#define UI_TRANSITION_SNAP_MS 100
|
|
37
|
-
#endif
|
|
38
|
-
// Scroll physics + capability defaults. The per-TU #define overrides emitted
|
|
39
|
-
// by the UI emitter (from resolveScrollConfig) hit BEFORE this header, so these
|
|
40
|
-
// #ifndef guards adopt the configured values. Spec: 2026-06-28-scroll-engine-rewrite-design.md
|
|
41
|
-
#ifndef UI_SCROLL_MAX_OVERSCROLL
|
|
42
|
-
#define UI_SCROLL_MAX_OVERSCROLL 40
|
|
43
|
-
#endif
|
|
44
|
-
#ifndef UI_SCROLL_STIFFNESS_X10
|
|
45
|
-
#define UI_SCROLL_STIFFNESS_X10 5
|
|
46
|
-
#endif
|
|
47
|
-
#ifndef UI_SCROLL_EDGE_SNAP_PX
|
|
48
|
-
#define UI_SCROLL_EDGE_SNAP_PX 12
|
|
49
|
-
#endif
|
|
50
|
-
#ifndef UI_SCROLL_DRAG_SCALE_X10
|
|
51
|
-
#define UI_SCROLL_DRAG_SCALE_X10 10
|
|
52
|
-
#endif
|
|
53
|
-
#ifndef UI_SCROLL_SETTLE_MS
|
|
54
|
-
#define UI_SCROLL_SETTLE_MS 180
|
|
55
|
-
#endif
|
|
56
|
-
#ifndef UI_SCROLL_DEADBAND_PX
|
|
57
|
-
#define UI_SCROLL_DEADBAND_PX 2
|
|
58
|
-
#endif
|
|
59
|
-
// Capability tier flags (emitted per-TU before this header; defaults = full).
|
|
60
|
-
// The default-on check must run BEFORE the per-flag #ifndef defaults below —
|
|
61
|
-
// after them, all three flags are defined 0 and the fallback would redefine
|
|
62
|
-
// UI_SCROLL_INPUT_TIER_RESISTIVE with a different value (ill-formed).
|
|
63
|
-
#if !defined(UI_SCROLL_INPUT_TIER_CAPACITIVE) && !defined(UI_SCROLL_INPUT_TIER_RESISTIVE) && !defined(UI_SCROLL_INPUT_TIER_NONE)
|
|
64
|
-
#define UI_SCROLL_INPUT_TIER_RESISTIVE 1
|
|
65
|
-
#endif
|
|
66
|
-
#ifndef UI_SCROLL_INPUT_TIER_CAPACITIVE
|
|
67
|
-
#define UI_SCROLL_INPUT_TIER_CAPACITIVE 0
|
|
68
|
-
#endif
|
|
69
|
-
#ifndef UI_SCROLL_INPUT_TIER_RESISTIVE
|
|
70
|
-
#define UI_SCROLL_INPUT_TIER_RESISTIVE 0
|
|
71
|
-
#endif
|
|
72
|
-
#ifndef UI_SCROLL_INPUT_TIER_NONE
|
|
73
|
-
#define UI_SCROLL_INPUT_TIER_NONE 0
|
|
74
|
-
#endif
|
|
75
|
-
#ifndef UI_SCROLL_RENDER_TIER_FULL
|
|
76
|
-
#define UI_SCROLL_RENDER_TIER_FULL 1
|
|
77
|
-
#endif
|
|
78
|
-
#ifndef UI_SCROLL_RENDER_TIER_CONSTRAINED
|
|
79
|
-
#define UI_SCROLL_RENDER_TIER_CONSTRAINED 0
|
|
80
|
-
#endif
|
|
81
|
-
#define UI_SCROLL_HAS_TOUCH (UI_SCROLL_INPUT_TIER_CAPACITIVE || UI_SCROLL_INPUT_TIER_RESISTIVE)
|
|
82
|
-
#define UI_SCROLL_ELASTIC (UI_SCROLL_RENDER_TIER_FULL)
|
|
83
|
-
// Telemetry: emits per-frame scrollY/overscrollPx/dy over Serial when defined.
|
|
84
|
-
#ifndef UI_SCROLL_DEBUG
|
|
85
|
-
#define UI_SCROLL_DEBUG 0
|
|
86
|
-
#endif
|
|
87
|
-
// Band renderer: height (px) of the horizontal band canvas used to composite
|
|
88
|
-
// scroll subtrees tear-free when no viewport canvas fits (no PSRAM / over
|
|
89
|
-
// budget). Each band is vw × UI_STRIP_BAND_HEIGHT. Must be tall enough that a
|
|
90
|
-
// single line of AA text (glyph height ~lineHeight, typically 16-22px at ts=2)
|
|
91
|
-
// fits within one band — if a glyph straddles a band boundary, its anti-
|
|
92
|
-
// aliased edge pixels blend toward the wrong bg in the adjacent band, visible
|
|
93
|
-
// as a clipped/faded text bottom. 32 ensures most fonts fit; at 480px wide
|
|
94
|
-
// that's ~30KB (fits SRAM on most ESP32 targets).
|
|
95
|
-
// Dirty-rect merging (LVGL refresh-cycle technique): several same-frame
|
|
96
|
-
// dirty nodes whose paint rects are near each other composite as one banded
|
|
97
|
-
// region instead of per-node transactions. Regions cap at the band-
|
|
98
|
-
// compositable pixel budget; singleton rects keep the per-node ladder.
|
|
99
|
-
#ifndef UI_MERGE_INFLATE
|
|
100
|
-
#define UI_MERGE_INFLATE 8
|
|
101
|
-
#endif
|
|
102
|
-
#ifndef UI_MERGE_MAX_REGIONS
|
|
103
|
-
#define UI_MERGE_MAX_REGIONS 6
|
|
104
|
-
#endif
|
|
105
|
-
#ifndef UI_MERGE_MAX_NODES
|
|
106
|
-
#define UI_MERGE_MAX_NODES 12
|
|
107
|
-
#endif
|
|
108
|
-
|
|
109
|
-
#ifndef UI_STRIP_BAND_HEIGHT
|
|
110
|
-
#define UI_STRIP_BAND_HEIGHT 32
|
|
111
|
-
#endif
|
|
112
|
-
#if defined(ESP32) || defined(ESP8266)
|
|
113
|
-
#include <Esp.h>
|
|
114
|
-
#endif
|
|
115
|
-
`;
|
|
116
|
-
}
|
|
1
|
+
// Slice of the C++ runtime header (original source lines 17-89).
|
|
2
|
+
// Guard open, includes, and #define knobs.
|
|
3
|
+
// See docs/superpowers/specs/2026-07-12-split-runtime-header-design.md.
|
|
4
|
+
export function emitTypesDefines(): string {
|
|
5
|
+
return `
|
|
6
|
+
// ── Cuttlefish UI runtime (emit once per TU) ──────────────────────────────
|
|
7
|
+
#ifndef __TC_UI_RUNTIME
|
|
8
|
+
#define __TC_UI_RUNTIME
|
|
9
|
+
#include <stdint.h>
|
|
10
|
+
#include <cstring>
|
|
11
|
+
#include <new>
|
|
12
|
+
#define UI_TEXT_BUF 32 // max stored UI text chars, excluding the trailing NUL
|
|
13
|
+
#define UI_TEXT_LINE_BUF 96
|
|
14
|
+
#define UI_WS_NORMAL 0
|
|
15
|
+
#define UI_WS_NOWRAP 1
|
|
16
|
+
#define UI_WS_PRE 2
|
|
17
|
+
#define UI_WS_PRE_LINE 3
|
|
18
|
+
#ifndef UI_MAX_BUFFERED_PAINT_PIXELS
|
|
19
|
+
#define UI_MAX_BUFFERED_PAINT_PIXELS 20000
|
|
20
|
+
#endif
|
|
21
|
+
// Above this many pixels, prefer the band renderer (small ~10KB SRAM canvas,
|
|
22
|
+
// strip-at-a-time) over the repair canvas even when the repair canvas could
|
|
23
|
+
// allocate (e.g. in PSRAM). A large repair canvas (a full-width button is
|
|
24
|
+
// ~15-30KB) has higher alloc/seed/push latency than banding — the per-band
|
|
25
|
+
// push is smaller and the band canvas lives in fast internal SRAM. Set below
|
|
26
|
+
// UI_MAX_BUFFERED_PAINT_PIXELS so large rects band while small repaints keep
|
|
27
|
+
// the fast single-canvas composite. Tune per target; 0 = always prefer the
|
|
28
|
+
// repair canvas when it allocates (the pre-PSRAM behavior).
|
|
29
|
+
#ifndef UI_BAND_PREFER_PIXELS
|
|
30
|
+
#define UI_BAND_PREFER_PIXELS 8000
|
|
31
|
+
#endif
|
|
32
|
+
#ifndef UI_USE_FULL_FRAMEBUFFER
|
|
33
|
+
#define UI_USE_FULL_FRAMEBUFFER 0
|
|
34
|
+
#endif
|
|
35
|
+
#ifndef UI_TRANSITION_SNAP_MS
|
|
36
|
+
#define UI_TRANSITION_SNAP_MS 100
|
|
37
|
+
#endif
|
|
38
|
+
// Scroll physics + capability defaults. The per-TU #define overrides emitted
|
|
39
|
+
// by the UI emitter (from resolveScrollConfig) hit BEFORE this header, so these
|
|
40
|
+
// #ifndef guards adopt the configured values. Spec: 2026-06-28-scroll-engine-rewrite-design.md
|
|
41
|
+
#ifndef UI_SCROLL_MAX_OVERSCROLL
|
|
42
|
+
#define UI_SCROLL_MAX_OVERSCROLL 40
|
|
43
|
+
#endif
|
|
44
|
+
#ifndef UI_SCROLL_STIFFNESS_X10
|
|
45
|
+
#define UI_SCROLL_STIFFNESS_X10 5
|
|
46
|
+
#endif
|
|
47
|
+
#ifndef UI_SCROLL_EDGE_SNAP_PX
|
|
48
|
+
#define UI_SCROLL_EDGE_SNAP_PX 12
|
|
49
|
+
#endif
|
|
50
|
+
#ifndef UI_SCROLL_DRAG_SCALE_X10
|
|
51
|
+
#define UI_SCROLL_DRAG_SCALE_X10 10
|
|
52
|
+
#endif
|
|
53
|
+
#ifndef UI_SCROLL_SETTLE_MS
|
|
54
|
+
#define UI_SCROLL_SETTLE_MS 180
|
|
55
|
+
#endif
|
|
56
|
+
#ifndef UI_SCROLL_DEADBAND_PX
|
|
57
|
+
#define UI_SCROLL_DEADBAND_PX 2
|
|
58
|
+
#endif
|
|
59
|
+
// Capability tier flags (emitted per-TU before this header; defaults = full).
|
|
60
|
+
// The default-on check must run BEFORE the per-flag #ifndef defaults below —
|
|
61
|
+
// after them, all three flags are defined 0 and the fallback would redefine
|
|
62
|
+
// UI_SCROLL_INPUT_TIER_RESISTIVE with a different value (ill-formed).
|
|
63
|
+
#if !defined(UI_SCROLL_INPUT_TIER_CAPACITIVE) && !defined(UI_SCROLL_INPUT_TIER_RESISTIVE) && !defined(UI_SCROLL_INPUT_TIER_NONE)
|
|
64
|
+
#define UI_SCROLL_INPUT_TIER_RESISTIVE 1
|
|
65
|
+
#endif
|
|
66
|
+
#ifndef UI_SCROLL_INPUT_TIER_CAPACITIVE
|
|
67
|
+
#define UI_SCROLL_INPUT_TIER_CAPACITIVE 0
|
|
68
|
+
#endif
|
|
69
|
+
#ifndef UI_SCROLL_INPUT_TIER_RESISTIVE
|
|
70
|
+
#define UI_SCROLL_INPUT_TIER_RESISTIVE 0
|
|
71
|
+
#endif
|
|
72
|
+
#ifndef UI_SCROLL_INPUT_TIER_NONE
|
|
73
|
+
#define UI_SCROLL_INPUT_TIER_NONE 0
|
|
74
|
+
#endif
|
|
75
|
+
#ifndef UI_SCROLL_RENDER_TIER_FULL
|
|
76
|
+
#define UI_SCROLL_RENDER_TIER_FULL 1
|
|
77
|
+
#endif
|
|
78
|
+
#ifndef UI_SCROLL_RENDER_TIER_CONSTRAINED
|
|
79
|
+
#define UI_SCROLL_RENDER_TIER_CONSTRAINED 0
|
|
80
|
+
#endif
|
|
81
|
+
#define UI_SCROLL_HAS_TOUCH (UI_SCROLL_INPUT_TIER_CAPACITIVE || UI_SCROLL_INPUT_TIER_RESISTIVE)
|
|
82
|
+
#define UI_SCROLL_ELASTIC (UI_SCROLL_RENDER_TIER_FULL)
|
|
83
|
+
// Telemetry: emits per-frame scrollY/overscrollPx/dy over Serial when defined.
|
|
84
|
+
#ifndef UI_SCROLL_DEBUG
|
|
85
|
+
#define UI_SCROLL_DEBUG 0
|
|
86
|
+
#endif
|
|
87
|
+
// Band renderer: height (px) of the horizontal band canvas used to composite
|
|
88
|
+
// scroll subtrees tear-free when no viewport canvas fits (no PSRAM / over
|
|
89
|
+
// budget). Each band is vw × UI_STRIP_BAND_HEIGHT. Must be tall enough that a
|
|
90
|
+
// single line of AA text (glyph height ~lineHeight, typically 16-22px at ts=2)
|
|
91
|
+
// fits within one band — if a glyph straddles a band boundary, its anti-
|
|
92
|
+
// aliased edge pixels blend toward the wrong bg in the adjacent band, visible
|
|
93
|
+
// as a clipped/faded text bottom. 32 ensures most fonts fit; at 480px wide
|
|
94
|
+
// that's ~30KB (fits SRAM on most ESP32 targets).
|
|
95
|
+
// Dirty-rect merging (LVGL refresh-cycle technique): several same-frame
|
|
96
|
+
// dirty nodes whose paint rects are near each other composite as one banded
|
|
97
|
+
// region instead of per-node transactions. Regions cap at the band-
|
|
98
|
+
// compositable pixel budget; singleton rects keep the per-node ladder.
|
|
99
|
+
#ifndef UI_MERGE_INFLATE
|
|
100
|
+
#define UI_MERGE_INFLATE 8
|
|
101
|
+
#endif
|
|
102
|
+
#ifndef UI_MERGE_MAX_REGIONS
|
|
103
|
+
#define UI_MERGE_MAX_REGIONS 6
|
|
104
|
+
#endif
|
|
105
|
+
#ifndef UI_MERGE_MAX_NODES
|
|
106
|
+
#define UI_MERGE_MAX_NODES 12
|
|
107
|
+
#endif
|
|
108
|
+
|
|
109
|
+
#ifndef UI_STRIP_BAND_HEIGHT
|
|
110
|
+
#define UI_STRIP_BAND_HEIGHT 32
|
|
111
|
+
#endif
|
|
112
|
+
#if defined(ESP32) || defined(ESP8266)
|
|
113
|
+
#include <Esp.h>
|
|
114
|
+
#endif
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
@@ -136,6 +136,10 @@ export const SHADCN_KIT_CSS = `/* ----------------------------------------------
|
|
|
136
136
|
padding: 10px 16px;
|
|
137
137
|
font-weight: bold;
|
|
138
138
|
transition: background 80ms;
|
|
139
|
+
/* Reset the UA's browser-default button border (shadcn's button reset):
|
|
140
|
+
ghost must be truly borderless — variants that want one (outline)
|
|
141
|
+
re-declare it themselves. */
|
|
142
|
+
border: none;
|
|
139
143
|
}
|
|
140
144
|
.btn:pressed { transform: translateY(1px); }
|
|
141
145
|
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
|
|
@@ -60,6 +60,7 @@ export function lowerUIToCpp(
|
|
|
60
60
|
allScreens: StyledNode[] = [],
|
|
61
61
|
imageAssetIds: Map<string, number> = new Map(),
|
|
62
62
|
keyframeSets: KeyframeSetModel[] = [],
|
|
63
|
+
keyframeNs: string = "",
|
|
63
64
|
): LoweredUI {
|
|
64
65
|
void storage;
|
|
65
66
|
const model = lowerUIToModel(root, boxes, colorFormat, display, fontAssets, allScreens, imageAssetIds, keyframeSets);
|
|
@@ -114,7 +115,7 @@ export function lowerUIToCpp(
|
|
|
114
115
|
|
|
115
116
|
const screenCount = model.nodes.length > 0 ? Math.max(...model.nodes.map(n => n.screenId)) + 1 : 1;
|
|
116
117
|
const imageTables = "const UIImage __ui_images[] = {};\nconst uint16_t __ui_image_count = 0;";
|
|
117
|
-
const keyframeTables = emitKeyframeTables(model);
|
|
118
|
+
const keyframeTables = emitKeyframeTables(model, keyframeNs);
|
|
118
119
|
return { fontTables, nodeTable, transitionTable, typeDecl, keyboardLoaders, keyboardDispatch, screenCount, imageTables, keyframeTables, diagnostics: [] };
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -424,7 +425,7 @@ function emitTransitionTable(model: UIProgram): string {
|
|
|
424
425
|
}
|
|
425
426
|
|
|
426
427
|
/** Emit keyframe stop arrays + keyframe set index + animation table. */
|
|
427
|
-
function emitKeyframeTables(model: UIProgram): string {
|
|
428
|
+
function emitKeyframeTables(model: UIProgram, keyframeNs: string = ""): string {
|
|
428
429
|
if (model.keyframeSets.length === 0 && model.animations.length === 0) {
|
|
429
430
|
return [
|
|
430
431
|
`const UIKeyframeSet __ui_keyframe_sets[] = {};`,
|
|
@@ -435,8 +436,14 @@ function emitKeyframeTables(model: UIProgram): string {
|
|
|
435
436
|
}
|
|
436
437
|
const lines: string[] = [];
|
|
437
438
|
// Emit one stop array per keyframe set.
|
|
439
|
+
// `keyframeNs` namespaces symbols per UI module, and shared stylesheets can
|
|
440
|
+
// register the same animation name into multiple mounted modules — dedupe
|
|
441
|
+
// by name so identical sets emit once (duplicate static arrays fail to link).
|
|
442
|
+
const seenKfNames = new Set<string>();
|
|
438
443
|
for (const ks of model.keyframeSets) {
|
|
439
|
-
|
|
444
|
+
if (seenKfNames.has(ks.name)) continue;
|
|
445
|
+
seenKfNames.add(ks.name);
|
|
446
|
+
const safeName = (keyframeNs ? keyframeNs + "_" : "") + ks.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
440
447
|
lines.push(`static const UIKeyframeStop __ui_kf_${safeName}_stops[] = {`);
|
|
441
448
|
for (const s of ks.stops) {
|
|
442
449
|
lines.push(` { .percent=${s.percent}, .props=${s.props}, .bg=${hex(s.bg)}, .fg=${hex(s.fg)}, .opacity=${s.opacity}, .transformOffsetX=${s.transformOffsetX}, .transformOffsetY=${s.transformOffsetY}, .translatePctX=${s.translatePctX}, .translatePctY=${s.translatePctY}, .scaleX=${s.scaleX}, .scaleY=${s.scaleY}, .rotateDeg=${s.rotateDeg}, .width=${s.width}, .height=${s.height} },`);
|
|
@@ -446,7 +453,8 @@ function emitKeyframeTables(model: UIProgram): string {
|
|
|
446
453
|
// Emit keyframe set index table.
|
|
447
454
|
lines.push(`const UIKeyframeSet __ui_keyframe_sets[] = {`);
|
|
448
455
|
model.keyframeSets.forEach((ks) => {
|
|
449
|
-
|
|
456
|
+
if (!seenKfNames.has(ks.name)) return;
|
|
457
|
+
const safeName = (keyframeNs ? keyframeNs + "_" : "") + ks.name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
450
458
|
lines.push(` { .stopCount=${ks.stops.length}, .stops=__ui_kf_${safeName}_stops },`);
|
|
451
459
|
});
|
|
452
460
|
lines.push(`};`);
|
|
@@ -237,7 +237,8 @@ export function lowerOnMount(htmlPath: string, opts: LowerOptions): LoweredUI {
|
|
|
237
237
|
|
|
238
238
|
const imageAssets = loadImageAssets(allStyled.length > 0 ? allStyled : [mod.styled], path.dirname(abs));
|
|
239
239
|
|
|
240
|
-
const
|
|
240
|
+
const kfNs = hashlibLike(abs);
|
|
241
|
+
const result = lowerUIToCpp(mod.styled, allBoxes, opts.colorFormat, opts.storage, mod.keyboards, mod.rules, getDisplayProfile(), mod.fontAssets, allStyled, imageAssets.nodeIdToAssetIndex, keyframeSets, kfNs);
|
|
241
242
|
|
|
242
243
|
// Layout diagnostics: viewport-overflow (node bottom past the viewport) and
|
|
243
244
|
// text-overflow (node right edge past its parent). Both reference the node by
|
|
@@ -332,6 +333,13 @@ export function hasUIModule(htmlPath: string): boolean {
|
|
|
332
333
|
return modules.has(path.resolve(htmlPath));
|
|
333
334
|
}
|
|
334
335
|
|
|
336
|
+
/** Stable short per-module namespace for generated symbols (link-level dedup). */
|
|
337
|
+
function hashlibLike(absPath: string): string {
|
|
338
|
+
let h = 5381;
|
|
339
|
+
for (let i = 0; i < absPath.length; i++) h = ((h * 33) ^ absPath.charCodeAt(i)) >>> 0;
|
|
340
|
+
return "m" + h.toString(36);
|
|
341
|
+
}
|
|
342
|
+
|
|
335
343
|
/** All loaded UI modules (used by the emitter to inject every mounted tree). */
|
|
336
344
|
export function allUIModules(): UIModule[] {
|
|
337
345
|
return [...modules.values()];
|