@geastack/engine 0.1.6 → 0.1.7

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/ui/node_model.h CHANGED
@@ -2,12 +2,17 @@
2
2
  #pragma once
3
3
 
4
4
  #include "pixel.h"
5
+ #include "css_features.h"
6
+ #include "renderer_features.h"
7
+ #include "node_text.h"
8
+ #include "node_features.h"
5
9
 
6
10
  #include <algorithm>
7
11
  #include <cstdint>
8
12
  #include <cstddef>
9
13
  #include <deque>
10
14
  #include <string>
15
+ #include <type_traits>
11
16
 
12
17
  namespace gea::embedded::ui {
13
18
 
@@ -108,7 +113,7 @@ inline int usedAlignment(int alignment, int freeSpace, bool reversed = false)
108
113
  return keyword;
109
114
  }
110
115
 
111
- enum class NodeType : int8_t {
116
+ enum class NodeType : uint8_t {
112
117
  View = 0,
113
118
  Text = 1,
114
119
  Image = 2,
@@ -134,26 +139,71 @@ inline bool isNativeButtonNodeType(NodeType type)
134
139
  // BEFORE ComputedStyle so it can be a by-value member).
135
140
  struct RareStyle {
136
141
  // Logical edges: block-start/end, inline-start/end.
142
+ #if GEA_CSS_MARGIN_TRIM
137
143
  uint8_t margin_trim = 0;
144
+ #else
145
+ static constexpr uint8_t margin_trim = 0;
146
+ #endif
138
147
  // IEEE float bits travel through the existing integer style-value transport.
139
148
  // Negative ratios mean `auto <ratio>` (prefer a replaced element's natural ratio).
149
+ #if GEA_CSS_ASPECT_RATIO
140
150
  int32_t aspect_ratio = 0;
151
+ #else
152
+ static constexpr int32_t aspect_ratio = 0;
153
+ #endif
154
+ #if GEA_CSS_FLEX_LINE_COUNT
141
155
  int32_t flex_line_count = 1;
156
+ #else
157
+ static constexpr int32_t flex_line_count = 1;
158
+ #endif
159
+ #if GEA_CSS_FLEX_BASIS_EXPRESSIONS
142
160
  int32_t flex_basis_expression = -1;
161
+ #else
162
+ static constexpr int32_t flex_basis_expression = -1;
163
+ #endif
164
+ #if GEA_CSS_LINE_HEIGHT_EXPRESSIONS
143
165
  int32_t line_height_expression = -1;
166
+ #else
167
+ static constexpr int32_t line_height_expression = -1;
168
+ #endif
144
169
  // Individual grid item alignment; auto defers to the parent's justify-items.
170
+ #if GEA_CSS_JUSTIFY_SELF
145
171
  int8_t justify_self = -1;
172
+ #else
173
+ static constexpr int8_t justify_self = -1;
174
+ #endif
146
175
  // Computed contain flags: size, inline-size, layout, style, paint.
147
176
  // Currently consumed by document background propagation.
177
+ #if GEA_CSS_CONTAINMENT
148
178
  uint8_t containment = 0;
179
+ #else
180
+ static constexpr uint8_t containment = 0;
181
+ #endif
182
+ #if GEA_CSS_BACKGROUND_LAYERS
149
183
  uint16_t bg_clip = 0; // Interned clip list; zero is border-box.
184
+ #else
185
+ static constexpr uint16_t bg_clip = 0; // Interned clip list; zero is border-box.
186
+ #endif
150
187
  // row-start, column-start, row-end, column-end; zero is auto. Positive
151
188
  // spans carry kGridLineSpan, while signed integers retain explicit lines.
189
+ #if GEA_CSS_GRID
152
190
  int32_t grid_line[4] = {};
191
+ #else
192
+ static constexpr int32_t grid_line[4] = {};
193
+ #endif
153
194
  // Deferred box edges; absent expressions do not allocate a rare-style record.
195
+ #if GEA_CSS_BOX_EXPRESSIONS
154
196
  int32_t margin_expression[4] = {-1, -1, -1, -1};
197
+ #else
198
+ static constexpr int32_t margin_expression[4] = {-1, -1, -1, -1};
199
+ #endif
200
+ #if GEA_CSS_BOX_EXPRESSIONS
155
201
  int32_t padding_expression[4] = {-1, -1, -1, -1};
202
+ #else
203
+ static constexpr int32_t padding_expression[4] = {-1, -1, -1, -1};
204
+ #endif
156
205
  // --- grid (display:grid track templates) ---
206
+ #if GEA_CSS_GRID
157
207
  int8_t grid_column_count = 0;
158
208
  int8_t grid_row_count = 0;
159
209
  int8_t grid_column_type[kMaxGridTracks] = {};
@@ -161,9 +211,20 @@ struct RareStyle {
161
211
  int16_t grid_column_value[kMaxGridTracks] = {};
162
212
  int16_t grid_row_value[kMaxGridTracks] = {};
163
213
 
214
+ #else
215
+ static constexpr int8_t grid_column_count = 0;
216
+ static constexpr int8_t grid_row_count = 0;
217
+ static constexpr int8_t grid_column_type[kMaxGridTracks] = {};
218
+ static constexpr int8_t grid_row_type[kMaxGridTracks] = {};
219
+ static constexpr int16_t grid_column_value[kMaxGridTracks] = {};
220
+ static constexpr int16_t grid_row_value[kMaxGridTracks] = {};
221
+
222
+ #endif
223
+
164
224
  // --- transform / perspective (defaults must match NodeLifecycle::init:
165
225
  // scale 1000 = 1.0x, origins 500 = 50% center; the rest 0) ---
166
226
  // Authored identity effects still establish positioning containing blocks.
227
+ #if GEA_CSS_TRANSFORMS
167
228
  uint8_t transform_present = 0;
168
229
  uint8_t transform_preserve_3d = 0;
169
230
  uint8_t rotate_present = 0;
@@ -175,7 +236,6 @@ struct RareStyle {
175
236
  uint8_t transform_translate_outer_axes = 0;
176
237
  int16_t translate_x = 0, translate_y = 0, translate_z = 0;
177
238
  int16_t translate_x_percent = 0, translate_y_percent = 0;
178
- uint8_t filter_present = 0;
179
239
  int16_t transform_rotate = 0;
180
240
  int16_t transform_rotate_x = 0;
181
241
  int16_t transform_rotate_y = 0;
@@ -193,24 +253,97 @@ struct RareStyle {
193
253
  int16_t perspective_origin_x = 500;
194
254
  int16_t perspective_origin_y = 500;
195
255
 
256
+ #else
257
+ static constexpr uint8_t transform_present = 0;
258
+ static constexpr uint8_t transform_preserve_3d = 0;
259
+ static constexpr uint8_t rotate_present = 0;
260
+ static constexpr int16_t rotate_angle = 0;
261
+ static constexpr int32_t rotate_axis_x = 0, rotate_axis_y = 0, rotate_axis_z = 1000000;
262
+ static constexpr int16_t scale_x = 1000, scale_y = 1000, scale_z = 1000;
263
+ static constexpr uint8_t scale_present = 0;
264
+ static constexpr uint8_t translate_present = 0;
265
+ static constexpr uint8_t transform_translate_outer_axes = 0;
266
+ static constexpr int16_t translate_x = 0, translate_y = 0, translate_z = 0;
267
+ static constexpr int16_t translate_x_percent = 0, translate_y_percent = 0;
268
+ static constexpr int16_t transform_rotate = 0;
269
+ static constexpr int16_t transform_rotate_x = 0;
270
+ static constexpr int16_t transform_rotate_y = 0;
271
+ static constexpr int16_t transform_translate_x = 0;
272
+ static constexpr int16_t transform_translate_y = 0;
273
+ static constexpr int16_t transform_translate_z = 0;
274
+ static constexpr int16_t transform_translate_x_percent = 0;
275
+ static constexpr int16_t transform_translate_y_percent = 0;
276
+ static constexpr int16_t transform_scale_x = 1000;
277
+ static constexpr int16_t transform_scale_y = 1000;
278
+ static constexpr int16_t transform_scale_z = 1000;
279
+ static constexpr int16_t transform_origin_x = 500;
280
+ static constexpr int16_t transform_origin_y = 500;
281
+ static constexpr int16_t perspective = 0;
282
+ static constexpr int16_t perspective_origin_x = 500;
283
+ static constexpr int16_t perspective_origin_y = 500;
284
+ #endif
285
+ #if GEA_CSS_FILTERS
286
+ uint8_t filter_present = 0;
287
+ #else
288
+ static constexpr uint8_t filter_present = 0;
289
+ #endif
290
+
196
291
  // --- filter / box-shadow (all default 0 = no effect) ---
292
+ #if GEA_CSS_FILTERS
197
293
  int16_t filter_blur_radius = 0;
294
+ #else
295
+ static constexpr int16_t filter_blur_radius = 0;
296
+ #endif
297
+ #if GEA_CSS_BOX_SHADOW
198
298
  uint8_t box_shadow_inset = 0;
299
+ #else
300
+ static constexpr uint8_t box_shadow_inset = 0;
301
+ #endif
302
+ #if GEA_CSS_BOX_SHADOW
199
303
  int16_t box_shadow_offset_x = 0;
304
+ #else
305
+ static constexpr int16_t box_shadow_offset_x = 0;
306
+ #endif
307
+ #if GEA_CSS_BOX_SHADOW
200
308
  int16_t box_shadow_offset_y = 0;
309
+ #else
310
+ static constexpr int16_t box_shadow_offset_y = 0;
311
+ #endif
312
+ #if GEA_CSS_BOX_SHADOW
201
313
  int16_t box_shadow_blur_radius = 0;
314
+ #else
315
+ static constexpr int16_t box_shadow_blur_radius = 0;
316
+ #endif
317
+ #if GEA_CSS_BOX_SHADOW
202
318
  int16_t box_shadow_spread = 0;
319
+ #else
320
+ static constexpr int16_t box_shadow_spread = 0;
321
+ #endif
322
+ #if GEA_CSS_BOX_SHADOW
203
323
  style_color_t box_shadow_color = 0;
324
+ #else
325
+ static constexpr style_color_t box_shadow_color = 0;
326
+ #endif
327
+ #if GEA_CSS_BOX_SHADOW
204
328
  uint8_t box_shadow_alpha = 0;
329
+ #else
330
+ static constexpr uint8_t box_shadow_alpha = 0;
331
+ #endif
205
332
 
206
333
  // --- per-side borders (default white/opaque, matching NodeLifecycle::init;
207
334
  // only relevant when a side width > 0, which is rare) ---
335
+ #if GEA_CSS_SIDE_BORDERS
208
336
  int16_t border_side_width[4] = {};
337
+ #else
338
+ static constexpr int16_t border_side_width[4] = {};
339
+ #endif
209
340
  // 0: flat; 1: groove; 2: ridge; 3: inset; 4: outset.
341
+ #if GEA_CSS_BORDER_RELIEF
210
342
  uint8_t border_relief[4] = {};
211
- // Bits 0..3: explicit side colors; bit 4: literal common color;
212
- // bits 5..8: explicit side currentColor. Unspecified colors use currentColor.
213
- uint16_t border_color_flags = 0;
343
+ #else
344
+ static constexpr uint8_t border_relief[4] = {};
345
+ #endif
346
+ #if GEA_CSS_SIDE_BORDERS
214
347
  style_color_t border_side_color[4] = {
215
348
  gea::framework::graphics::pixel::nativeColor(255, 255, 255),
216
349
  gea::framework::graphics::pixel::nativeColor(255, 255, 255),
@@ -218,14 +351,31 @@ struct RareStyle {
218
351
  gea::framework::graphics::pixel::nativeColor(255, 255, 255),
219
352
  };
220
353
 
221
- uint8_t border_side_alpha[4] = {255, 255, 255, 255};
354
+ uint8_t border_side_alpha[4] = {255, 255, 255, 255};
355
+ #else
356
+ static constexpr style_color_t border_side_color[4] = {
357
+ gea::framework::graphics::pixel::nativeColor(255, 255, 255),
358
+ gea::framework::graphics::pixel::nativeColor(255, 255, 255),
359
+ gea::framework::graphics::pixel::nativeColor(255, 255, 255),
360
+ gea::framework::graphics::pixel::nativeColor(255, 255, 255),
361
+ };
362
+
363
+ static constexpr uint8_t border_side_alpha[4] = {255, 255, 255, 255};
364
+ #endif
222
365
 
223
366
  // --- linear / overlay / radial gradients + background grid (defaults match
224
367
  // NodeLifecycle::init: alphas 255, stops 500/1000, angle 1800, radial
225
368
  // center/extent 500/1000) ---
369
+ #if GEA_CSS_BACKGROUND_LAYERS
226
370
  uint16_t bg_image_layer_count = 1; // Includes none layers.
227
371
  int32_t bg_size_list = -1, bg_position_list = -1, bg_repeat_list = -1;
228
372
  int32_t bg_attachment_list = -1, bg_origin_list = -1;
373
+ #else
374
+ static constexpr uint16_t bg_image_layer_count = 1; // Includes none layers.
375
+ static constexpr int32_t bg_size_list = -1, bg_position_list = -1, bg_repeat_list = -1;
376
+ static constexpr int32_t bg_attachment_list = -1, bg_origin_list = -1;
377
+ #endif
378
+ #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS
229
379
  uint16_t bg_gradient_layer = 0, bg_overlay_gradient_layer = 0, bg_radial_gradient_layer = 0;
230
380
  style_color_t bg_gradient_from_color = 0;
231
381
  style_color_t bg_gradient_mid_color = 0;
@@ -265,6 +415,47 @@ struct RareStyle {
265
415
  uint16_t bg_grid_step_y = 0;
266
416
  uint8_t bg_grid_line_x = 0;
267
417
  uint8_t bg_grid_line_y = 0;
418
+ #else
419
+ static constexpr uint16_t bg_gradient_layer = 0, bg_overlay_gradient_layer = 0, bg_radial_gradient_layer = 0;
420
+ static constexpr style_color_t bg_gradient_from_color = 0;
421
+ static constexpr style_color_t bg_gradient_mid_color = 0;
422
+ static constexpr style_color_t bg_gradient_to_color = 0;
423
+ static constexpr uint8_t bg_gradient_from_alpha = 255;
424
+ static constexpr uint8_t bg_gradient_mid_alpha = 255;
425
+ static constexpr uint8_t bg_gradient_to_alpha = 255;
426
+ static constexpr uint16_t bg_gradient_mid_stop = 500;
427
+ static constexpr uint16_t bg_gradient_to_stop = 1000;
428
+ static constexpr uint8_t bg_gradient_has_mid = 0;
429
+ static constexpr int16_t bg_gradient_angle = 1800;
430
+ static constexpr uint8_t bg_overlay_gradient = 0;
431
+ static constexpr style_color_t bg_overlay_gradient_from_color = 0;
432
+ static constexpr style_color_t bg_overlay_gradient_mid_color = 0;
433
+ static constexpr style_color_t bg_overlay_gradient_to_color = 0;
434
+ static constexpr uint8_t bg_overlay_gradient_from_alpha = 255;
435
+ static constexpr uint8_t bg_overlay_gradient_mid_alpha = 255;
436
+ static constexpr uint8_t bg_overlay_gradient_to_alpha = 255;
437
+ static constexpr uint16_t bg_overlay_gradient_mid_stop = 500;
438
+ static constexpr uint16_t bg_overlay_gradient_to_stop = 1000;
439
+ static constexpr uint8_t bg_overlay_gradient_has_mid = 0;
440
+ static constexpr int16_t bg_overlay_gradient_angle = 1800;
441
+ static constexpr uint8_t bg_radial_gradient = 0;
442
+ static constexpr style_color_t bg_radial_gradient_from_color = 0;
443
+ static constexpr style_color_t bg_radial_gradient_to_color = 0;
444
+ static constexpr uint8_t bg_radial_gradient_from_alpha = 255;
445
+ static constexpr uint8_t bg_radial_gradient_to_alpha = 255;
446
+ static constexpr uint16_t bg_radial_gradient_stop = 1000;
447
+ static constexpr int16_t bg_radial_gradient_cx = 500;
448
+ static constexpr int16_t bg_radial_gradient_cy = 500;
449
+ static constexpr int16_t bg_radial_gradient_rx = 1000;
450
+ static constexpr int16_t bg_radial_gradient_ry = 1000;
451
+ static constexpr uint8_t bg_grid_axes = 0;
452
+ static constexpr style_color_t bg_grid_color = 0;
453
+ static constexpr uint8_t bg_grid_alpha = 255;
454
+ static constexpr uint16_t bg_grid_step_x = 0;
455
+ static constexpr uint16_t bg_grid_step_y = 0;
456
+ static constexpr uint8_t bg_grid_line_x = 0;
457
+ static constexpr uint8_t bg_grid_line_y = 0;
458
+ #endif
268
459
  };
269
460
 
270
461
  // Individual translation is applied outside the transform list. Its translation
@@ -280,6 +471,9 @@ inline int composedTranslateZ(const RareStyle &s) { return int(s.transform_trans
280
471
  inline int composedTranslateXPercent(const RareStyle &s) { return int(s.transform_translate_x_percent) + s.translate_x_percent; }
281
472
  inline int composedTranslateYPercent(const RareStyle &s) { return int(s.transform_translate_y_percent) + s.translate_y_percent; }
282
473
 
474
+ #define GEA_CSS_RARE_STYLE (GEA_CSS_ASPECT_RATIO || GEA_CSS_BACKGROUND_LAYERS || GEA_CSS_BORDER_RELIEF || GEA_CSS_BOX_EXPRESSIONS || GEA_CSS_BOX_SHADOW || GEA_CSS_CONTAINMENT || GEA_CSS_FILTERS || GEA_CSS_FLEX_BASIS_EXPRESSIONS || GEA_CSS_FLEX_LINE_COUNT || GEA_CSS_GRID || GEA_CSS_JUSTIFY_SELF || GEA_CSS_LINE_HEIGHT_EXPRESSIONS || GEA_CSS_MARGIN_TRIM || GEA_CSS_SIDE_BORDERS || GEA_CSS_TRANSFORMS || GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS)
475
+ static_assert(GEA_CSS_RARE_STYLE || std::is_empty<RareStyle>::value, "An unguarded rare field requires a reachability family");
476
+
283
477
  struct ComputedStyle {
284
478
  int8_t display;
285
479
  // True iff the `display` property was explicitly authored (a CSS rule or
@@ -291,95 +485,294 @@ struct ComputedStyle {
291
485
  int8_t display_explicit;
292
486
  int8_t flex_direction;
293
487
  int8_t flex_direction_explicit;
294
- int8_t flex_wrap; // low bits: 0 nowrap, 1 wrap, 2 wrap-reverse; bit 2: balance
488
+ #if GEA_CSS_FLEX_WRAP
489
+ int8_t flex_wrap;
490
+ #else
491
+ static constexpr int8_t flex_wrap = 0;
492
+ #endif // low bits: 0 nowrap, 1 wrap, 2 wrap-reverse; bit 2: balance
295
493
  int8_t justify_content;
296
494
  int8_t align_items;
495
+ #if GEA_CSS_JUSTIFY_ITEMS
297
496
  int8_t justify_items;
497
+ #else
498
+ static constexpr int8_t justify_items = 0;
499
+ #endif
500
+ #if GEA_CSS_ALIGN_CONTENT
298
501
  int8_t align_content;
502
+ #else
503
+ static constexpr int8_t align_content = 0;
504
+ #endif
505
+ #if GEA_CSS_ALIGN_SELF
299
506
  int8_t align_self;
507
+ #else
508
+ static constexpr int8_t align_self = -1;
509
+ #endif
510
+ #if !GEA_CSS_U8_GAP
300
511
  int16_t gap;
512
+ #endif
301
513
  int8_t box_sizing; // 0: content-box (CSS initial), 1: border-box
302
- int8_t float_side; // 0: none, 1: left, 2: right
303
- int8_t clear_side; // 0: none, 1: left, 2: right, 3: both
304
- int8_t writing_mode; // -1: inherit, 0: horizontal-tb, 1: vertical-lr, 2: vertical-rl, 3: sideways-rl, 4: sideways-lr
305
- int8_t direction; // -1: inherit, 0: ltr, 1: rtl
514
+ #if GEA_CSS_FLOATS
515
+ int8_t float_side;
516
+ #else
517
+ static constexpr int8_t float_side = 0;
518
+ #endif // 0: none, 1: left, 2: right
519
+ #if GEA_CSS_FLOATS
520
+ int8_t clear_side;
521
+ #else
522
+ static constexpr int8_t clear_side = 0;
523
+ #endif // 0: none, 1: left, 2: right, 3: both
524
+ #if GEA_CSS_WRITING_MODE
525
+ int8_t writing_mode;
526
+ #else
527
+ static constexpr int8_t writing_mode = 0;
528
+ #endif // -1: inherit, 0: horizontal-tb, 1: vertical-lr, 2: vertical-rl, 3: sideways-rl, 4: sideways-lr
529
+ #if GEA_CSS_WRITING_MODE
530
+ int8_t direction;
531
+ #else
532
+ static constexpr int8_t direction = 0;
533
+ #endif // -1: inherit, 0: ltr, 1: rtl
306
534
  uint8_t margin_auto; // TRBL bit mask; numeric margins remain zero for auto
535
+ #if GEA_CSS_AXIS_GAP
307
536
  int16_t row_gap, column_gap; // kUnset falls back to native gap
537
+ #else
538
+ static constexpr int16_t row_gap = kUnset, column_gap = kUnset;
539
+ #endif
540
+ #if GEA_CSS_PERCENT_GAP
308
541
  int16_t row_gap_percent, column_gap_percent;
542
+ #else
543
+ static constexpr int16_t row_gap_percent = kUnset, column_gap_percent = kUnset;
544
+ #endif
545
+ // Fits the alignment gap before the 32-bit fields. A literal common border
546
+ // color must not allocate a rare-style record merely for its binding flags.
547
+ // Bits 0..3: explicit side colors; bit 4: literal common color;
548
+ // bits 5..8: explicit side currentColor. Unspecified colors use currentColor.
549
+ #if !GEA_CSS_U8_BORDER_FLAGS
550
+ uint16_t border_color_flags = 0;
551
+ #endif
552
+ #if GEA_CSS_ORDER
309
553
  int32_t order; // Stable ordering of flex/grid items; never changes tree order.
554
+ #else
555
+ static constexpr int32_t order = 0;
556
+ #endif
310
557
  // Inherited unitless line-height number as IEEE float bits; -1 means length/normal.
311
558
  // Keep this common inherited value out of the much larger rare-style allocation.
312
559
  int32_t line_height_multiplier;
313
560
 
314
- int32_t width_expression, height_expression;
561
+ int32_t width_expression;
562
+ #if GEA_CSS_HEIGHT_EXPRESSIONS
563
+ int32_t height_expression;
564
+ #else
565
+ static constexpr int32_t height_expression = -1;
566
+ #endif
315
567
  int16_t width, height;
316
568
  int16_t width_percent, height_percent;
317
- int16_t min_width, min_height;
318
- int16_t max_width, max_height;
569
+ #if GEA_CSS_MIN_WIDTH
570
+ int16_t min_width;
571
+ #else
572
+ static constexpr int16_t min_width = kUnset;
573
+ #endif
574
+ int16_t min_height;
575
+ int16_t max_width;
576
+ #if GEA_CSS_MAX_HEIGHT
577
+ int16_t max_height;
578
+ #else
579
+ static constexpr int16_t max_height = kUnset;
580
+ #endif
581
+ #if !GEA_CSS_U8_FLEX
319
582
  int16_t flex;
320
583
  int16_t flex_shrink;
584
+ #endif
321
585
  // CSS `flex-basis` as a definite main-axis length in px, or kUnset for `auto`
322
586
  // (the default — main size comes from content / flex-grow). When definite, the
323
587
  // flex item's main-axis size is set to this basis before grow/shrink, so
324
588
  // `flex: 0 0 26px` yields a 26px item instead of stretching to fill or sizing
325
589
  // to content. Percentage and `auto` bases resolve to kUnset (content-sized).
590
+ #if GEA_CSS_FLEX_BASIS
326
591
  int16_t flex_basis;
592
+ #else
593
+ static constexpr int16_t flex_basis = kUnset;
594
+ #endif
327
595
 
596
+ #if !GEA_CSS_U8_PADDING
328
597
  int16_t padding[4];
598
+ #endif
329
599
  int16_t margin[4];
330
600
 
601
+ #if GEA_CSS_Z_INDEX
331
602
  int8_t position;
332
603
  int8_t z_index_auto;
604
+ #else
605
+ static constexpr int8_t z_index_auto = 1;
606
+ #endif
607
+ #if GEA_CSS_POSITION_PX_ALL
333
608
  int16_t pos_offsets[4];
609
+ #else
610
+ #if GEA_CSS_POSITION_TOP
611
+ int16_t pos_top;
612
+ #else
613
+ static constexpr int16_t pos_top = kUnset;
614
+ #endif
615
+ #if GEA_CSS_POSITION_RIGHT
616
+ int16_t pos_right;
617
+ #else
618
+ static constexpr int16_t pos_right = kUnset;
619
+ #endif
620
+ #if GEA_CSS_POSITION_BOTTOM
621
+ int16_t pos_bottom;
622
+ #else
623
+ static constexpr int16_t pos_bottom = kUnset;
624
+ #endif
625
+ #if GEA_CSS_POSITION_LEFT
626
+ int16_t pos_left;
627
+ #else
628
+ static constexpr int16_t pos_left = kUnset;
629
+ #endif
630
+ #endif
631
+ #if GEA_CSS_POSITION_PERCENT_ALL
334
632
  int16_t pos_offset_percent[4];
633
+ #else
634
+ #if GEA_CSS_POSITION_TOP_PERCENT
635
+ int16_t pos_percent_top;
636
+ #else
637
+ static constexpr int16_t pos_percent_top = kUnset;
638
+ #endif
639
+ #if GEA_CSS_POSITION_RIGHT_PERCENT
640
+ int16_t pos_percent_right;
641
+ #else
642
+ static constexpr int16_t pos_percent_right = kUnset;
643
+ #endif
644
+ #if GEA_CSS_POSITION_BOTTOM_PERCENT
645
+ int16_t pos_percent_bottom;
646
+ #else
647
+ static constexpr int16_t pos_percent_bottom = kUnset;
648
+ #endif
649
+ #if GEA_CSS_POSITION_LEFT_PERCENT
650
+ int16_t pos_percent_left;
651
+ #else
652
+ static constexpr int16_t pos_percent_left = kUnset;
653
+ #endif
654
+ #endif
655
+ #if GEA_CSS_Z_INDEX
335
656
  int16_t z_index;
657
+ #else
658
+ static constexpr int16_t z_index = 0;
659
+ #endif
336
660
 
337
- style_color_t bg_color;
661
+ // Group byte-sized paint flags before native colours. Keep natural alignment
662
+ // without paying padding between each RGB565 colour and its flags.
338
663
  int8_t has_bg;
339
664
  uint8_t bg_alpha;
665
+ #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS
340
666
  int8_t bg_fill;
667
+ #else
668
+ static constexpr int8_t bg_fill = 0;
669
+ #endif
670
+ int8_t has_active_bg;
671
+ #if GEA_CSS_TEXT_ALPHA
672
+ uint8_t text_alpha;
673
+ #else
674
+ static constexpr uint8_t text_alpha = 255;
675
+ #endif
676
+ #if GEA_CSS_BORDER_ALPHA
677
+ uint8_t border_alpha;
678
+ #else
679
+ static constexpr uint8_t border_alpha = 255;
680
+ #endif
681
+ #if !GEA_CSS_Z_INDEX
682
+ // Without the paired stacking flag, position fills the paint-byte group
683
+ // instead of leaving a hole before the 16-bit offset array.
684
+ int8_t position;
685
+ #endif
686
+ style_color_t bg_color;
341
687
  // linear/overlay/radial gradients + background-grid moved to RareStyle (rare).
342
688
  style_color_t active_bg_color;
343
- int8_t has_active_bg;
344
689
  style_color_t text_color;
345
- uint8_t text_alpha;
690
+ #if GEA_CSS_OPACITY
346
691
  uint8_t opacity;
692
+ #else
693
+ static constexpr uint8_t opacity = 255;
694
+ #endif
695
+ #if GEA_CSS_BLINK
347
696
  int16_t blink_interval_ms;
348
697
  int32_t blink_started_ms;
349
698
  uint8_t blink_visible;
699
+ #else
700
+ static constexpr int16_t blink_interval_ms = 0;
701
+ static constexpr int32_t blink_started_ms = 0;
702
+ static constexpr uint8_t blink_visible = 1;
703
+ #endif
350
704
 
705
+ #if !GEA_CSS_U8_BORDER
351
706
  int16_t border_width;
707
+ #endif
352
708
  style_color_t border_color;
353
- uint8_t border_alpha;
354
709
  // per-side border width/color/alpha moved to RareStyle (rare); border_radius
355
710
  // stays here (rounded rects are common).
356
- int16_t border_radius[4];
357
- int16_t border_radius_percent[4];
711
+ #if !GEA_CSS_U8_RADIUS
712
+ int16_t border_radius[GEA_CSS_RADIUS_COUNT];
713
+ #endif
714
+ #if GEA_CSS_PERCENT_RADIUS
715
+ int16_t border_radius_percent[GEA_CSS_RADIUS_COUNT];
716
+ #else
717
+ static constexpr int16_t border_radius_percent[4] = {kUnset, kUnset, kUnset, kUnset};
718
+ #endif
358
719
 
359
720
  // transform / perspective / filter / box-shadow moved to RareStyle (rare).
360
721
 
361
722
  int16_t font_id;
723
+ #if !GEA_CSS_U8_FONT
362
724
  int16_t font_size;
725
+ #endif
363
726
  int16_t font_weight;
727
+ #if !GEA_CSS_U8_LINE_HEIGHT
364
728
  int16_t line_height;
729
+ #endif
365
730
  int8_t text_align;
366
731
  int8_t overflow;
732
+ #if GEA_CSS_OVERFLOW_AXES
367
733
  int8_t overflow_x;
368
734
  int8_t overflow_y;
735
+ #else
736
+ static constexpr int8_t overflow_x = 0, overflow_y = 0;
737
+ #endif
738
+ #if GEA_CSS_MASK
369
739
  int16_t mask_right_fade_width;
740
+ #else
741
+ static constexpr int16_t mask_right_fade_width = 0;
742
+ #endif
743
+ #if GEA_CSS_IMAGE_FIT
370
744
  int8_t image_fit;
745
+ #else
746
+ static constexpr int8_t image_fit = 0;
747
+ #endif
371
748
  // CSS `backface-visibility`: 0 = visible (default), 1 = hidden. When hidden, a
372
749
  // flat element's entire painted subtree is culled when its back faces the viewer.
373
750
  // A preserve-3d element keeps its descendants' individual visibility.
751
+ #if GEA_CSS_TRANSFORMS
374
752
  int8_t backface_hidden;
375
- int8_t visibility; // 0 visible, 1 hidden, 2 collapse (inherited)
753
+ #else
754
+ static constexpr int8_t backface_hidden = 0;
755
+ #endif
756
+ #if GEA_CSS_VISIBILITY
757
+ int8_t visibility;
758
+ #else
759
+ static constexpr int8_t visibility = 0;
760
+ #endif // 0 visible, 1 hidden, 2 collapse (inherited)
376
761
  // CSS `text-decoration` — 0 = none (default), 1 = underline, 2 =
377
762
  // line-through. The text renderer paints a font-size-relative line at
378
763
  // the appropriate y-offset for each decorated run.
764
+ #if GEA_CSS_TEXT_DECORATION
379
765
  int8_t text_decoration;
766
+ #else
767
+ static constexpr int8_t text_decoration = 0;
768
+ #endif
380
769
  // CSS `text-transform` — 0 = none, 1 = uppercase, 2 = lowercase,
381
770
  // 3 = capitalize. Rendering applies this without mutating Node::text.
771
+ #if GEA_CSS_TEXT_TRANSFORM
382
772
  int8_t text_transform;
773
+ #else
774
+ static constexpr int8_t text_transform = 0;
775
+ #endif
383
776
  // CSS `white-space`: 0 normal, 1 nowrap, 2 pre, 3 pre-wrap, 4 pre-line,
384
777
  // 5 break-spaces. Inherited; space preservation and soft wrapping differ.
385
778
  int8_t white_space;
@@ -388,18 +781,51 @@ struct ComputedStyle {
388
781
  // line is truncated at a glyph boundary and an ASCII "..." is appended so
389
782
  // the visible run fits within the content width. Not inherited.
390
783
  int8_t text_overflow;
784
+ // Compiler-proven unsigned ranges need one byte load, with no unpacking.
785
+ // Group these bytes so narrowing does not merely create alignment holes.
786
+ #if GEA_CSS_U8_BORDER_FLAGS
787
+ uint8_t border_color_flags = 0;
788
+ #endif
789
+ #if GEA_CSS_U8_GAP
790
+ uint8_t gap;
791
+ #endif
792
+ #if GEA_CSS_U8_FLEX
793
+ uint8_t flex, flex_shrink;
794
+ #endif
795
+ #if GEA_CSS_U8_PADDING
796
+ uint8_t padding[4];
797
+ #endif
798
+ #if GEA_CSS_U8_BORDER
799
+ uint8_t border_width;
800
+ #endif
801
+ #if GEA_CSS_U8_RADIUS
802
+ uint8_t border_radius[GEA_CSS_RADIUS_COUNT];
803
+ #endif
804
+ #if GEA_CSS_U8_FONT
805
+ uint8_t font_size;
806
+ #endif
807
+ #if GEA_CSS_U8_LINE_HEIGHT
808
+ uint8_t line_height;
809
+ #endif
810
+
391
811
  // CSS `pointer-events` — 0 = auto (default), 1 = none. A `none` node is never
392
812
  // the target of a pointer event and its subtree is skipped in hit-testing, so
393
813
  // clicks pass through to whatever is painted behind it (e.g. a decorative
394
814
  // overlay image over interactive controls). Default 0 via zero-init.
815
+ #if GEA_CSS_POINTER_EVENTS
395
816
  int8_t pointer_events;
817
+ #else
818
+ static constexpr int8_t pointer_events = 0;
819
+ #endif
396
820
 
397
821
  // Handle into the shared RareStyle pool for cold/rarely-used style fields
398
822
  // (grid tracks, gradients, transforms, shadows, …) that most nodes never set.
399
823
  // -1 = none, so a plain styled node pays 2 bytes instead of inlining ~200 B.
400
824
  // Read via rstyle(style), write via rstyleMut(style). Aggregate-friendly: this
401
825
  // is the only member with a default initializer; the rest stay zero-init.
402
- #if GEA_EMBEDDED_RARE_STYLE_INLINE
826
+ #if !GEA_CSS_RARE_STYLE
827
+ static constexpr int16_t rare_style = -1;
828
+ #elif GEA_EMBEDDED_RARE_STYLE_INLINE
403
829
  // Compiler-driven hot placement: the rare fields live inline (direct load, same cache
404
830
  // line — spine's access pattern), no rstyle() pool indirection per node. rare_style is
405
831
  // kept but vestigial (always -1) so pool-handle call sites compile as harmless no-ops;
@@ -483,7 +909,10 @@ struct ComputedStyle {
483
909
  // RareStyle split moved transform/gradient fields off the hot ComputedStyle struct, so
484
910
  // every `style.transform_*` read became a function call. The static local is one shared
485
911
  // instance across TUs (inline-function rule); rstyleMut/release/reset (style.cpp) use it.
486
- #if GEA_EMBEDDED_RARE_STYLE_INLINE
912
+ #if !GEA_CSS_RARE_STYLE
913
+ inline constexpr RareStyle kRareStyleZero{};
914
+ inline const RareStyle &rstyle(const ComputedStyle &style) { (void)style; return kRareStyleZero; }
915
+ #elif GEA_EMBEDDED_RARE_STYLE_INLINE
487
916
  // Inline-embedded rare fields: rstyle() is a direct member access — no pool, no branch, no
488
917
  // separate cache line (spine's access pattern). rstyleMut/release/reset are still defined
489
918
  // out-of-line in style.cpp (their bodies #if'd) because rstyleMut also invalidates the
@@ -519,12 +948,18 @@ inline bool styleHasBackgroundImage(const ComputedStyle &style)
519
948
  inline constexpr int kInheritedBorderWidth = -1;
520
949
  inline int computedBorderWidth(const ComputedStyle &style, int side)
521
950
  {
951
+ #if GEA_CSS_SIDE_BORDERS
522
952
  const int specific = rstyle(style).border_side_width[side];
523
953
  return specific > style.border_width ? specific : style.border_width;
954
+ #else
955
+ (void)side;
956
+ return style.border_width;
957
+ #endif
524
958
  }
525
959
 
526
960
  inline bool setComputedBorderWidth(ComputedStyle &style, int side, int value, const ComputedStyle *parent)
527
961
  {
962
+ #if GEA_CSS_SIDE_BORDERS
528
963
  int widths[4];
529
964
  for (int i = 0; i < 4; ++i) {
530
965
  widths[i] = computedBorderWidth(style, i);
@@ -550,11 +985,19 @@ inline bool setComputedBorderWidth(ComputedStyle &style, int side, int value, co
550
985
  for (int i = 0; i < 4; ++i) rare.border_side_width[i] = stored[i];
551
986
  }
552
987
  return true;
988
+ #else
989
+ if (side >= 0) return false;
990
+ const int width = value == kInheritedBorderWidth ? (parent ? parent->border_width : 0) : value;
991
+ if (width == style.border_width) return false;
992
+ style.border_width = width;
993
+ return true;
994
+ #endif
553
995
  }
554
996
 
555
997
  inline bool setBorderColorBinding(ComputedStyle &style, int side, bool current)
556
998
  {
557
- const unsigned previous = rstyle(style).border_color_flags;
999
+ #if GEA_CSS_SIDE_BORDERS
1000
+ const unsigned previous = style.border_color_flags;
558
1001
  unsigned next;
559
1002
  if (side < 0) next = current ? 0u : 16u; // shorthand resets every side
560
1003
  else {
@@ -563,52 +1006,85 @@ inline bool setBorderColorBinding(ComputedStyle &style, int side, bool current)
563
1006
  else next &= ~(1u << (side + 5));
564
1007
  }
565
1008
  if (next == previous) return false;
566
- rstyleMut(style).border_color_flags = static_cast<uint16_t>(next);
1009
+ style.border_color_flags = static_cast<uint16_t>(next);
567
1010
  return true;
1011
+ #else
1012
+ if (side >= 0) return false;
1013
+ const unsigned next = current ? 0u : 16u;
1014
+ if (next == style.border_color_flags) return false;
1015
+ style.border_color_flags = static_cast<uint16_t>(next);
1016
+ return true;
1017
+ #endif
568
1018
  }
569
1019
 
570
1020
  inline bool borderColorIsCurrent(const ComputedStyle &style, int side = -1)
571
1021
  {
572
- const unsigned flags = rstyle(style).border_color_flags;
1022
+ #if GEA_CSS_SIDE_BORDERS
1023
+ const unsigned flags = style.border_color_flags;
573
1024
  if (side >= 0 && (flags & (1u << side))) return flags & (1u << (side + 5));
574
1025
  return !(flags & 16u);
1026
+ #else
1027
+ (void)side;
1028
+ return !(style.border_color_flags & 16u);
1029
+ #endif
575
1030
  }
576
1031
 
577
1032
  inline style_color_t borderPaintColor(const ComputedStyle &style, int side = -1)
578
1033
  {
1034
+ #if GEA_CSS_SIDE_BORDERS
579
1035
  if (borderColorIsCurrent(style, side)) return style.text_color;
580
- return side >= 0 && (rstyle(style).border_color_flags & (1u << side))
1036
+ return side >= 0 && (style.border_color_flags & (1u << side))
581
1037
  ? rstyle(style).border_side_color[side] : style.border_color;
1038
+ #else
1039
+ return borderColorIsCurrent(style, side) ? style.text_color : style.border_color;
1040
+ #endif
582
1041
  }
583
1042
 
584
1043
  inline uint8_t borderPaintAlpha(const ComputedStyle &style, int side = -1)
585
1044
  {
1045
+ #if GEA_CSS_SIDE_BORDERS
586
1046
  if (borderColorIsCurrent(style, side)) return style.text_alpha;
587
- return side >= 0 && (rstyle(style).border_color_flags & (1u << side))
1047
+ return side >= 0 && (style.border_color_flags & (1u << side))
588
1048
  ? rstyle(style).border_side_alpha[side] : style.border_alpha;
1049
+ #else
1050
+ return borderColorIsCurrent(style, side) ? style.text_alpha : style.border_alpha;
1051
+ #endif
589
1052
  }
590
1053
 
591
1054
  inline bool borderColorsDiffer(const ComputedStyle &style)
592
1055
  {
1056
+ #if GEA_CSS_SIDE_BORDERS
593
1057
  for (int side = 1; side < 4; ++side)
594
1058
  if (borderPaintColor(style, side) != borderPaintColor(style, 0) ||
595
1059
  borderPaintAlpha(style, side) != borderPaintAlpha(style, 0)) return true;
596
1060
  return false;
1061
+ #else
1062
+ (void)style;
1063
+ return false;
1064
+ #endif
597
1065
  }
598
1066
 
599
1067
  inline bool borderUsesCurrentColor(const ComputedStyle &style)
600
1068
  {
1069
+ #if GEA_CSS_SIDE_BORDERS
601
1070
  for (int side = 0; side < 4; ++side)
602
1071
  if ((style.border_width > 0 || rstyle(style).border_side_width[side] > 0) && borderColorIsCurrent(style, side)) return true;
603
1072
  return false;
1073
+ #else
1074
+ return style.border_width > 0 && borderColorIsCurrent(style);
1075
+ #endif
604
1076
  }
605
1077
 
606
1078
  // Layout boxes include padding and borders. CSS width/height can select either
607
1079
  // the content box or border box, but child origins always use these insets.
608
1080
  inline int boxInset(const ComputedStyle &style, int side)
609
1081
  {
1082
+ #if GEA_CSS_SIDE_BORDERS
610
1083
  const int sideWidth = rstyle(style).border_side_width[side];
611
1084
  return style.padding[side] + (sideWidth > style.border_width ? sideWidth : style.border_width);
1085
+ #else
1086
+ return style.padding[side] + style.border_width;
1087
+ #endif
612
1088
  }
613
1089
  inline int boxInsets(const ComputedStyle &style, bool horizontal)
614
1090
  {
@@ -640,7 +1116,7 @@ inline bool isDisplayNone(const ComputedStyle &style)
640
1116
 
641
1117
  inline bool isDisplayGrid(const ComputedStyle &style)
642
1118
  {
643
- return style.display == kDisplayGrid;
1119
+ return GEA_CSS_GRID && style.display == kDisplayGrid;
644
1120
  }
645
1121
 
646
1122
  inline bool usesRowLayout(const ComputedStyle &style)
@@ -670,8 +1146,15 @@ inline int usedOverflow(int axis, int other)
670
1146
  {
671
1147
  return isScrollableOverflow(other) ? (axis == 0 ? 2 : axis == 3 ? 1 : axis) : axis;
672
1148
  }
1149
+ #if GEA_CSS_OVERFLOW_AXES
673
1150
  inline int overflowX(const ComputedStyle &style) { return usedOverflow(style.overflow_x, style.overflow_y); }
674
1151
  inline int overflowY(const ComputedStyle &style) { return usedOverflow(style.overflow_y, style.overflow_x); }
1152
+ #else
1153
+ // A single-axis shorthand gives both axes exactly this value. The existing
1154
+ // helpers become one direct field read, with no axis-coupling computation.
1155
+ inline int overflowX(const ComputedStyle &style) { return style.overflow; }
1156
+ inline int overflowY(const ComputedStyle &style) { return style.overflow; }
1157
+ #endif
675
1158
  inline int8_t aggregateOverflow(int8_t overflowX, int8_t overflowY)
676
1159
  {
677
1160
  const int x = usedOverflow(overflowX, overflowY), y = usedOverflow(overflowY, overflowX);
@@ -686,23 +1169,49 @@ inline bool overflowEstablishesContext(const ComputedStyle &style)
686
1169
  // Grouping effects force the used transform-style to flat.
687
1170
  inline bool preserves3D(const ComputedStyle &style)
688
1171
  {
1172
+ #if GEA_CSS_TRANSFORMS
689
1173
  const auto &rare = rstyle(style);
690
1174
  return rare.transform_preserve_3d && style.opacity == 255 &&
691
1175
  !isScrollableOverflow(overflowX(style)) && !isScrollableOverflow(overflowY(style)) &&
692
1176
  !rare.filter_present && !rare.filter_blur_radius && !(rare.containment & 16) &&
693
1177
  !style.mask_right_fade_width;
1178
+ #else
1179
+ (void)style;
1180
+ return false;
1181
+ #endif
1182
+ }
1183
+ inline bool scrollsOverflowX(const ComputedStyle &style)
1184
+ {
1185
+ #if GEA_CSS_SCROLLING
1186
+ return overflowX(style) == 2;
1187
+ #else
1188
+ (void)style;
1189
+ return false;
1190
+ #endif
1191
+ }
1192
+ inline bool scrollsOverflowY(const ComputedStyle &style)
1193
+ {
1194
+ #if GEA_CSS_SCROLLING
1195
+ return overflowY(style) == 2;
1196
+ #else
1197
+ (void)style;
1198
+ return false;
1199
+ #endif
694
1200
  }
695
- inline bool scrollsOverflowX(const ComputedStyle &style) { return overflowX(style) == 2; }
696
- inline bool scrollsOverflowY(const ComputedStyle &style) { return overflowY(style) == 2; }
697
1201
 
698
1202
  inline bool hasSideBorder(const ComputedStyle &style)
699
1203
  {
1204
+ #if GEA_CSS_SIDE_BORDERS
700
1205
  if (style.rare_style < 0) return false; // no RareStyle => no per-side borders
701
1206
  const RareStyle &r = rstyle(style);
702
1207
  return r.border_side_width[0] > 0 ||
703
1208
  r.border_side_width[1] > 0 ||
704
1209
  r.border_side_width[2] > 0 ||
705
1210
  r.border_side_width[3] > 0;
1211
+ #else
1212
+ (void)style;
1213
+ return false;
1214
+ #endif
706
1215
  }
707
1216
 
708
1217
  inline bool hasAnyBorder(const ComputedStyle &style)
@@ -718,7 +1227,6 @@ inline bool hasBorderRelief(const ComputedStyle &style)
718
1227
 
719
1228
  struct LayoutBox {
720
1229
  int16_t x, y;
721
- int32_t width_expression, height_expression;
722
1230
  int16_t width, height;
723
1231
 
724
1232
  // Inline formatting: x offset, inside this box's content area, at which the
@@ -733,7 +1241,6 @@ struct LayoutBox {
733
1241
  // relative to its static-position parent. Capture before relative offsets
734
1242
  // and absolute-coordinate conversion; retained refresh reuses this anchor.
735
1243
  int16_t static_block_start = 0;
736
- uint8_t static_block_axis = 0; // 0: unavailable, 1: y, 2: x
737
1244
 
738
1245
  int16_t previous_x, previous_y;
739
1246
  int16_t previous_width, previous_height;
@@ -742,12 +1249,21 @@ struct LayoutBox {
742
1249
  // content height of itemCount * rowHeight (e.g. 5000 * 259 ≈ 1.29M px),
743
1250
  // which overflows int16_t. Truncation made scroll_content_height wrap
744
1251
  // negative, so scrollMaxY clamped to 0 and the list refused to scroll.
1252
+ #if GEA_CSS_SCROLLING
745
1253
  int32_t scroll_x;
746
1254
  int32_t scroll_y;
747
1255
  int32_t scroll_content_width;
748
1256
  int32_t scroll_content_height;
749
1257
  int32_t previous_scroll_x;
750
1258
  int32_t previous_scroll_y;
1259
+ #else
1260
+ static constexpr int32_t scroll_x = 0;
1261
+ static constexpr int32_t scroll_y = 0;
1262
+ static constexpr int32_t scroll_content_width = 0;
1263
+ static constexpr int32_t scroll_content_height = 0;
1264
+ static constexpr int32_t previous_scroll_x = 0;
1265
+ static constexpr int32_t previous_scroll_y = 0;
1266
+ #endif
751
1267
 
752
1268
  // Intra-pass layout memo: the flex engine re-measures whole subtrees after
753
1269
  // every parent resize (repositionChildren -> measureChildren -> layoutNode),
@@ -758,24 +1274,25 @@ struct LayoutBox {
758
1274
  // that pattern. Scoped to a single pass (serial bumped by beginLayoutPass),
759
1275
  // so no cross-frame invalidation is needed and the final
760
1276
  // absolute-coordinate resolve is unaffected.
761
- // result_w/h: the node dims each slot's layout produced. The MRU slot's
762
- // result is the node's live state, so its hit is unconditional; the older
763
- // slot's layout has been overwritten in the tree, so its hit is only sound
764
- // when it produced exactly the current dims (the subtree is then
765
- // byte-identical — child avails derive from the node's own box).
1277
+ // 16-bit pass tags are direct loads, not packed fields. beginLayoutPass()
1278
+ // clears every tag before reusing serial 1 after 65,535 passes.
1279
+ // Both slots share result_w/h. An older entry can hit only when its result
1280
+ // equals the current dimensions, so discard it on a dimension change instead
1281
+ // of storing a second result that can never hit. External flex resizing still
1282
+ // compares the shared result against live dimensions before either lookup.
766
1283
  int16_t memo_avail_w;
767
1284
  int16_t memo_avail_h;
768
1285
  int16_t memo_result_w;
769
1286
  int16_t memo_result_h;
770
- uint32_t memo_pass;
1287
+ uint16_t memo_pass;
771
1288
  int16_t memo2_avail_w;
772
1289
  int16_t memo2_avail_h;
773
- int16_t memo2_result_w;
774
- int16_t memo2_result_h;
775
- uint32_t memo2_pass;
1290
+ uint16_t memo2_pass;
1291
+ uint8_t static_block_axis = 0; // 0: unavailable, 1: y, 2: x
776
1292
  };
777
1293
 
778
1294
  struct RenderState {
1295
+ #if GEA_CSS_TRANSFORMS
779
1296
  int16_t previous_rotate_angle;
780
1297
  int32_t previous_rotate_axis_x, previous_rotate_axis_y, previous_rotate_axis_z;
781
1298
  int16_t previous_scale_x, previous_scale_y, previous_scale_z;
@@ -799,11 +1316,55 @@ struct RenderState {
799
1316
  int16_t previous_perspective_origin_x;
800
1317
  int16_t previous_perspective_origin_y;
801
1318
  uint8_t previous_transformable_box;
1319
+ #else
1320
+ static constexpr int16_t previous_rotate_angle = 0;
1321
+ static constexpr int32_t previous_rotate_axis_x = 0;
1322
+ static constexpr int32_t previous_rotate_axis_y = 0;
1323
+ static constexpr int32_t previous_rotate_axis_z = 1000000;
1324
+ static constexpr int16_t previous_scale_x = 1000;
1325
+ static constexpr int16_t previous_scale_y = 1000;
1326
+ static constexpr int16_t previous_scale_z = 1000;
1327
+ static constexpr int16_t previous_transform_rotate = 0;
1328
+ static constexpr int16_t previous_transform_rotate_x = 0;
1329
+ static constexpr int16_t previous_transform_rotate_y = 0;
1330
+ static constexpr int16_t previous_translate_x = 0;
1331
+ static constexpr int16_t previous_translate_y = 0;
1332
+ static constexpr int16_t previous_translate_z = 0;
1333
+ static constexpr int16_t previous_translate_x_percent = 0;
1334
+ static constexpr int16_t previous_translate_y_percent = 0;
1335
+ static constexpr uint8_t previous_transform_translate_outer_axes = 0;
1336
+ static constexpr int32_t previous_transform_translate_x = 0;
1337
+ static constexpr int32_t previous_transform_translate_y = 0;
1338
+ static constexpr int32_t previous_transform_translate_z = 0;
1339
+ static constexpr int32_t previous_transform_translate_x_percent = 0;
1340
+ static constexpr int32_t previous_transform_translate_y_percent = 0;
1341
+ static constexpr int16_t previous_transform_scale_x = 1000;
1342
+ static constexpr int16_t previous_transform_scale_y = 1000;
1343
+ static constexpr int16_t previous_transform_scale_z = 1000;
1344
+ static constexpr int16_t previous_transform_origin_x = 500;
1345
+ static constexpr int16_t previous_transform_origin_y = 500;
1346
+ static constexpr int16_t previous_perspective = 0;
1347
+ static constexpr int16_t previous_perspective_origin_x = 500;
1348
+ static constexpr int16_t previous_perspective_origin_y = 500;
1349
+ static constexpr uint8_t previous_transformable_box = 0;
1350
+ #endif
1351
+ #if GEA_CSS_FILTERS
802
1352
  int16_t previous_filter_blur_radius;
1353
+ #else
1354
+ static constexpr int16_t previous_filter_blur_radius = 0;
1355
+ #endif
803
1356
 
804
1357
  uint8_t dirty;
1358
+ #if GEA_CSS_SCROLLING
805
1359
  uint8_t scroll_dirty;
1360
+ #else
1361
+ static constexpr uint8_t scroll_dirty = 0;
1362
+ #endif
1363
+ #if GEA_CSS_SCROLLING
806
1364
  uint8_t non_scroll_dirty;
1365
+ #else
1366
+ static constexpr uint8_t non_scroll_dirty = 0;
1367
+ #endif
807
1368
  // Set alongside `dirty` when the change can affect GEOMETRY (layout
808
1369
  // property, box-changing text, structural mutation). Paint-only dirt (a
809
1370
  // background/color class toggle, stable-box text) leaves it clear, letting
@@ -811,10 +1372,12 @@ struct RenderState {
811
1372
  // relayout compute its LCA over geometry-relevant nodes only. Cleared with
812
1373
  // `dirty`.
813
1374
  uint8_t layout_dirty;
1375
+ #if GEA_CSS_TRANSFORMS
814
1376
  uint8_t transform_dirty;
1377
+ #else
1378
+ static constexpr uint8_t transform_dirty = 0;
1379
+ #endif
815
1380
  uint8_t bg_recolor_pending;
816
- style_color_t bg_recolor_from;
817
- style_color_t bg_recolor_to;
818
1381
  // Tree::setText pre-measures incoming text and sets this flag when the
819
1382
  // update is safe for the retained/direct-replay path: absolute text may
820
1383
  // update its measured bbox out of flow, while in-flow text must keep the
@@ -825,13 +1388,11 @@ struct RenderState {
825
1388
  // Glyph-incremental text dirty (set by Tree::setText): when a content-only text
826
1389
  // change keeps the same layout box and only a middle run of glyphs differs
827
1390
  // (e.g. a ticking counter "58"->"57", a clock), the dirty collector flushes only
828
- // [text_dirty_x0, text_dirty_x1] across the node's height instead of the whole
1391
+ // [text_dirty.x0, text_dirty.x1] across the node's height instead of the whole
829
1392
  // box. A 26vmin badge re-render then copies just the changed digits (~one glyph)
830
1393
  // rather than ~the whole panel width, so it fits a TE-locked frame's slack.
831
1394
  // Cleared with text_layout_stable each frame (LayoutSnapshot::capture).
832
1395
  uint8_t text_partial_dirty;
833
- int16_t text_dirty_x0;
834
- int16_t text_dirty_x1;
835
1396
  // This box SHARES a line box with other inline content, so it was placed on
836
1397
  // that line's baseline (FlexLayoutPass::placeLineItems). TextRenderer::record
837
1398
  // then draws the run at its baseline instead of centring the string's ink in
@@ -839,6 +1400,12 @@ struct RenderState {
839
1400
  // glyphs reach, so runs of different words — or different fonts — on one line
840
1401
  // end up at different heights. A run that owns its line keeps the centring.
841
1402
  uint8_t inline_baseline;
1403
+ // Only one paint shortcut may own this scratch space. Mixed changes use
1404
+ // the ordinary dirty-region replay. The recolor destination is bg_color.
1405
+ union {
1406
+ style_color_t bg_recolor_from;
1407
+ struct { int16_t x0, x1; } text_dirty;
1408
+ };
842
1409
  };
843
1410
 
844
1411
  inline bool hadIndividualLinearTransform(const RenderState &s)
@@ -848,37 +1415,30 @@ inline bool hadIndividualLinearTransform(const RenderState &s)
848
1415
  }
849
1416
 
850
1417
  struct Node {
851
- NodeType type;
852
- ComputedStyle style;
1418
+ // Keep the hot style at offset zero. Reuse only record tail padding;
1419
+ // ordinary field reads remain naturally aligned direct loads.
1420
+ [[no_unique_address]] ComputedStyle style;
1421
+ // Interned tag id; zero is the empty tag. Fits in style's tail padding
1422
+ // when the source proof removes the unused alpha fields.
1423
+ int16_t tag_id = 0;
853
1424
 
854
1425
  int16_t parent;
855
1426
  int16_t first_child, last_child;
856
1427
  int16_t next_sibling, prev_sibling;
857
1428
 
858
- // Text content. std::string gives us dynamic sizing without the silent
859
- // truncation a fixed buffer caused, and on every modern libstdc++ /
860
- // libc++ build it has small-string optimization — strings up to ~22
861
- // chars stay inline in the std::string header with no heap allocation,
862
- // so the common short-label case (button text, counter values) doesn't
863
- // pay an allocation cost. Apps that put paragraph copy in a single
864
- // text node (e.g. typography sampler, ~160 chars) get the heap
865
- // allocation they actually need rather than being chopped to 63 chars.
866
- std::string text;
1429
+ // Index into the shared pool for optional listeners/attributes/styles.
1430
+ // -1 means absent and is restored by Node{} / node reuse.
1431
+ int16_t rare_data = -1;
1432
+ // Empty structural nodes retain only the four-byte text ownership handle.
1433
+ NodeText text;
1434
+ #if GEA_UI_IMAGE_NODES
867
1435
  int16_t image_id;
868
- // Interned tag id (index into the global tag table) rather than a 16-byte
869
- // inline string — the tag vocabulary is ~15 distinct strings, so this saves
870
- // 14 B/node. 0 = the empty tag. Use Tree::tagName(node) / tagFromId(tag_id)
871
- // to read the string, internTag(...) to write.
872
- int16_t tag_id = 0;
873
-
874
- LayoutBox layout;
1436
+ #else
1437
+ static constexpr int16_t image_id = -1;
1438
+ #endif
1439
+ [[no_unique_address]] LayoutBox layout;
1440
+ NodeType type;
875
1441
  RenderState render;
876
-
877
- // Blink-style "rare data" handle: index into the shared NodeRareData pool for
878
- // the cold/optional per-node state most nodes never have (event listeners, and
879
- // later attributes/custom-properties/etc.). -1 = none, so the common node pays
880
- // 2 bytes instead of inlining those tables. Reset to -1 by Node{} / node reuse.
881
- int16_t rare_data = -1;
882
1442
  };
883
1443
 
884
1444
  // Overflow clips the padding edge on each non-visible axis. Open axes span