@geastack/engine 0.1.18 → 0.1.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "GeaStack rendering engine, intrinsic JSX primitives, and native engine backends.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -57,6 +57,6 @@
57
57
  },
58
58
  "sideEffects": false,
59
59
  "dependencies": {
60
- "@geastack/core": "^0.1.40"
60
+ "@geastack/core": "^0.1.46"
61
61
  }
62
62
  }
package/ui/node.cpp CHANGED
@@ -283,7 +283,8 @@ const char *NodeHandle::tagName() const
283
283
  // node, TEXT_NODE (3), COMMENT_NODE (8), or DOCUMENT_FRAGMENT_NODE (11).
284
284
  NodeHandle::NodeTypeProperty::operator int() const
285
285
  {
286
- if (!gea::framework::identity::current(id, owner)) return 0;
286
+ if (!gea::framework::identity::current(id_, token())) return 0;
287
+ const int id = id_;
287
288
  const auto &tree=Tree::instance();
288
289
  // The template renderer's list/conditional anchors are hidden nodes tagged
289
290
  // "#comment"; DOM queries must see them as the comments they stand for.
package/ui/node.h CHANGED
@@ -5,6 +5,7 @@
5
5
  #include "style.h"
6
6
 
7
7
  #include <cstddef>
8
+ #include <cstdint>
8
9
  #include <string>
9
10
  #include <utility>
10
11
  #include <vector>
@@ -48,13 +49,63 @@ public:
48
49
  // Structural comments/fragments report 8/11 and never become visual boxes.
49
50
  // A retired handle reports 0, distinct from a live empty fragment.
50
51
  // Resolved lazily on read (cheap, rare) rather than at every handle
51
- // construction (hot path); generation ownership is captured separately.
52
- struct NodeTypeProperty {
53
- int id;
54
- gea::framework::identity::Owner owner = gea::framework::identity::node(id);
52
+ // construction (hot path). Inside a handle the property borrows the
53
+ // handle's identity token instead of owning a second reference: handles
54
+ // are copied constantly, and each shared_ptr copy is an atomic
55
+ // read-modify-write (a critical section on targets without hardware
56
+ // atomics). The handle rebuilds it on copy and move. A property copied
57
+ // out of its handle takes its own owner, so it can outlive the handle.
58
+ class NodeTypeProperty {
59
+ public:
55
60
  operator int() const;
56
61
  bool operator==(int other) const { return static_cast<int>(*this) == other; }
57
62
  bool operator!=(int other) const { return static_cast<int>(*this) != other; }
63
+
64
+ // A standalone copy owns the node's current token when it is still
65
+ // the same allocation; a retired one stays retired (reports 0).
66
+ NodeTypeProperty(const NodeTypeProperty &other) : id_(other.id_), bits_(0) { adopt(other.token()); }
67
+ NodeTypeProperty &operator=(const NodeTypeProperty &other)
68
+ {
69
+ if (this != &other) {
70
+ const auto *token = other.token();
71
+ release();
72
+ id_ = other.id_;
73
+ adopt(token);
74
+ }
75
+ return *this;
76
+ }
77
+ ~NodeTypeProperty() { release(); }
78
+
79
+ private:
80
+ friend class NodeHandle;
81
+ using Token = gea::framework::identity::Token;
82
+ using Owner = gea::framework::identity::Owner;
83
+ NodeTypeProperty(int id, const Token *token) : id_(id), bits_(reinterpret_cast<std::uintptr_t>(token)) {}
84
+ const Token *token() const
85
+ {
86
+ if (bits_ & 1) return reinterpret_cast<const Owner *>(bits_ & ~std::uintptr_t{1})->get();
87
+ return reinterpret_cast<const Token *>(bits_);
88
+ }
89
+ void borrow(int id, const Token *token)
90
+ {
91
+ release();
92
+ id_ = id;
93
+ bits_ = reinterpret_cast<std::uintptr_t>(token);
94
+ }
95
+ void release()
96
+ {
97
+ if (bits_ & 1) delete reinterpret_cast<Owner *>(bits_ & ~std::uintptr_t{1});
98
+ bits_ = 0;
99
+ }
100
+ void adopt(const Token *token)
101
+ {
102
+ Owner owner = gea::framework::identity::node(id_);
103
+ bits_ = token && owner.get() == token ? reinterpret_cast<std::uintptr_t>(new Owner(std::move(owner))) | 1 : 0;
104
+ }
105
+ int id_;
106
+ // The handle's borrowed Token*, or (low bit set) a standalone copy's own
107
+ // heap Owner*: the handle stays as small as one pointer here.
108
+ std::uintptr_t bits_;
58
109
  };
59
110
 
60
111
  // A real default constructor (not a defaulted-arg explicit ctor): records
@@ -63,14 +114,44 @@ public:
63
114
  // constructor, so `explicit NodeHandle(int = -1)` alone breaks every
64
115
  // generated `__gea_type_X __gea_out{};`.
65
116
  NodeHandle() : NodeHandle(-1) {}
66
- explicit NodeHandle(int id) : id_(id), identity_(gea::framework::identity::node(id)), nodeType{id, identity_} {}
117
+ explicit NodeHandle(int id) : id_(id), identity_(gea::framework::identity::node(id)), nodeType{id, identity_.get()} {}
118
+ // A handle for an owner already in hand (a Style's, another handle's),
119
+ // without a registry lookup. Validity is still checked on use.
120
+ NodeHandle(int id, gea::framework::identity::Owner owner)
121
+ : id_(id), identity_(std::move(owner)), nodeType{id, identity_.get()} {}
122
+ // Copies and moves rebuild nodeType from this handle's own owner.
123
+ NodeHandle(const NodeHandle &other) : id_(other.id_), identity_(other.identity_), nodeType{other.id_, identity_.get()} {}
124
+ NodeHandle(NodeHandle &&other) noexcept
125
+ : id_(other.id_), identity_(std::move(other.identity_)), nodeType{other.id_, identity_.get()}
126
+ {
127
+ other.nodeType.borrow(other.id_, nullptr);
128
+ }
129
+ NodeHandle &operator=(const NodeHandle &other)
130
+ {
131
+ if (this != &other) {
132
+ id_ = other.id_;
133
+ identity_ = other.identity_;
134
+ nodeType.borrow(id_, identity_.get());
135
+ }
136
+ return *this;
137
+ }
138
+ NodeHandle &operator=(NodeHandle &&other) noexcept
139
+ {
140
+ if (this != &other) {
141
+ id_ = other.id_;
142
+ identity_ = std::move(other.identity_);
143
+ nodeType.borrow(id_, identity_.get());
144
+ other.nodeType.borrow(other.id_, nullptr);
145
+ }
146
+ return *this;
147
+ }
67
148
  const void *identity() const { return identity_.get(); }
68
149
  std::shared_ptr<const void> weakIdentityOwner() const { return identity_; }
69
150
  // Event targets and DOM elements are two views of the same tree identity.
70
151
  // Pointer/touch event targets declared as Element therefore project to a
71
152
  // full node handle without boxing or losing the source node id.
72
153
  NodeHandle(const gea::framework::events::EventTarget &target)
73
- : id_(target.id()), identity_(target.identityOwner()), nodeType{target.id(), identity_} {}
154
+ : id_(target.id()), identity_(target.identityOwner()), nodeType{target.id(), identity_.get()} {}
74
155
  // Implicit build from a boxed node value (record carrying "__gea_node_id"),
75
156
  // so the compiled-component emitters' `NodeHandle x = <gea_cpp_value>` copy-
76
157
  // inits and NodeHandle-typed args accept a boxed node. SFINAE'd on
@@ -118,11 +199,27 @@ public:
118
199
  NodeHandle querySelector(const std::string &s) const { return querySelector(selectorText(s)); }
119
200
  std::vector<NodeHandle> querySelectorAll(const std::string &s) const { return querySelectorAll(selectorText(s)); }
120
201
  explicit operator bool() const { return valid(); }
121
- Style style() const { return Style(id()); }
202
+ // Shares this handle's owner instead of looking the id up again; the
203
+ // Style validates it on every use, as it validated its own lookup.
204
+ Style style() const { return Style(id_, identity_); }
205
+ // `style().setNumberProperty(...)` without the Style: it would take a
206
+ // second owner of this handle's identity just to forward the write.
207
+ bool setStyleNumberProperty(const std::string &property, double value) const;
122
208
  ClassList classList() const { return ClassList(id()); }
123
209
 
124
210
  NodeTypeProperty nodeType;
125
211
 
212
+ private:
213
+ friend class Style;
214
+ struct Borrowed {};
215
+ // Shares `owner`'s token without a reference count, for a handle that
216
+ // lives only inside one call while the caller (a Style) holds `owner`.
217
+ // Copies of it do not keep the token alive, so it is never stored.
218
+ NodeHandle(int id, const gea::framework::identity::Owner &owner, Borrowed)
219
+ : id_(id), identity_(gea::framework::identity::Owner{}, owner.get()), nodeType{id, identity_.get()} {}
220
+
221
+ public:
222
+
126
223
  NodeHandle cloneNode(bool deep = true) const;
127
224
  // Named *Handle to avoid colliding with the DOM `firstChild` PROPERTY
128
225
  // lowering (gea_ir::domFirstChild), which geatsc resolves on Node-typed
@@ -8,6 +8,10 @@
8
8
  #ifndef GEA_UI_INPUT_NODES
9
9
  #define GEA_UI_INPUT_NODES 1
10
10
  #endif
11
+ // Without a <video> node the build omits the video host and its frame phase.
12
+ #ifndef GEA_UI_VIDEO_NODES
13
+ #define GEA_UI_VIDEO_NODES 1
14
+ #endif
11
15
 
12
16
  // Generated from the whole-source class-token bound. Unknown programs retain
13
17
  // four inline entries. Overflow support is independent of this capacity.
package/ui/style.cpp CHANGED
@@ -16,6 +16,7 @@
16
16
 
17
17
  #include <algorithm>
18
18
  #include <array>
19
+ #include <atomic>
19
20
  #include <cctype>
20
21
  #include <cmath>
21
22
  #include <cstdint>
@@ -1656,7 +1657,9 @@ enum class LengthAxis {
1656
1657
  bool propertyAffectsDescendantStyle(Property property);
1657
1658
  void recomputeDescendantClassStyles(int node);
1658
1659
  void recomputeSubtreeClassStyles(int node);
1659
- void setStyleValue(NodeHandle node, Property property, int value, StyleApplicationSource source);
1660
+ void setStyleValue(const NodeHandle &node, Property property, int value, StyleApplicationSource source);
1661
+ void setValidatedStyleValue(const NodeHandle &node, int id, Property property, int value, StyleApplicationSource source);
1662
+ void setInlineStyleValue(int nodeId, Property property, int value);
1660
1663
  struct ActiveRulePlan;
1661
1664
  #if GEA_CSS_ANIMATIONS
1662
1665
  void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan = nullptr);
@@ -8518,16 +8521,24 @@ bool setClassRuleValueFast(NodeHandle node, Property property, int value)
8518
8521
  return setClassRuleValueFastUnchecked(target, property, value);
8519
8522
  }
8520
8523
 
8521
- void setStyleValue(NodeHandle node, Property property, int value, StyleApplicationSource source)
8524
+ void setStyleValue(const NodeHandle &node, Property property, int value, StyleApplicationSource source)
8525
+ {
8526
+ // One validity check; a Style would copy the owner only to check it again.
8527
+ const int id = node.id();
8528
+ if (id < 0) return;
8529
+ setValidatedStyleValue(node, id, property, value, source);
8530
+ }
8531
+
8532
+ // setStyleValue for a caller that has already resolved `node`'s live `id`.
8533
+ void setValidatedStyleValue(const NodeHandle &node, int id, Property property, int value, StyleApplicationSource source)
8522
8534
  {
8523
- if (!node) return;
8524
8535
  if (source == StyleApplicationSource::ClassRule) {
8525
- if (node.id() == g_resolvedFontNode && isFontMetricProperty(property)) return;
8526
- if (node.id() == g_resolvedLineHeightNode && isLineHeightProperty(property)) return;
8536
+ if (id == g_resolvedFontNode && isFontMetricProperty(property)) return;
8537
+ if (id == g_resolvedLineHeightNode && isLineHeightProperty(property)) return;
8527
8538
  if (setClassRuleValueFast(node, property, value)) return;
8528
- Tree::instance().setStyleFromClass(node.id(), property, value);
8539
+ Tree::instance().setStyleFromClass(id, property, value);
8529
8540
  } else {
8530
- node.style().set(property, value);
8541
+ setInlineStyleValue(id, property, value);
8531
8542
  }
8532
8543
  }
8533
8544
 
@@ -9236,6 +9247,24 @@ bool applyAnimatedTransformStyleValueFast(int nodeId, Property property, int val
9236
9247
  return true;
9237
9248
  }
9238
9249
 
9250
+ // Style::set for a node id its caller has validated.
9251
+ void setInlineStyleValue(int nodeId, Property property, int value)
9252
+ {
9253
+ if (nodeId < 0) return;
9254
+ #if GEA_CSS_ANIMATIONS
9255
+ double before = 0;
9256
+ const bool transition = inlineTransitionBefore(nodeId, property, before);
9257
+ #endif
9258
+ Tree::instance().setStyle(nodeId, property, value);
9259
+ #if GEA_CSS_ANIMATIONS
9260
+ if (transition) applyInlineTransition(nodeId, property, before);
9261
+ #endif
9262
+ // This element's cascaded lengths can depend on its own font too. Updating
9263
+ // descendants alone leaves, for example, class padding in ch at old metrics.
9264
+ if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId);
9265
+ else if (propertyAffectsDescendantStyle(property)) recomputeDescendantClassStyles(nodeId);
9266
+ }
9267
+
9239
9268
  } // namespace
9240
9269
 
9241
9270
  StorageUsage styleDependencyStorageUsage()
@@ -9330,19 +9359,7 @@ bool resolveLayoutBoxLengths(int nodeId, int percentageBasis)
9330
9359
 
9331
9360
  void Style::set(Property property, int value) const
9332
9361
  {
9333
- if (nodeId() < 0) return;
9334
- #if GEA_CSS_ANIMATIONS
9335
- double before = 0;
9336
- const bool transition = inlineTransitionBefore(nodeId(), property, before);
9337
- #endif
9338
- Tree::instance().setStyle(nodeId(), property, value);
9339
- #if GEA_CSS_ANIMATIONS
9340
- if (transition) applyInlineTransition(nodeId(), property, before);
9341
- #endif
9342
- // This element's cascaded lengths can depend on its own font too. Updating
9343
- // descendants alone leaves, for example, class padding in ch at old metrics.
9344
- if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId());
9345
- else if (propertyAffectsDescendantStyle(property)) recomputeDescendantClassStyles(nodeId());
9362
+ setInlineStyleValue(nodeId(), property, value);
9346
9363
  }
9347
9364
 
9348
9365
  void Style::backgroundColor(int rgb565) const
@@ -9354,19 +9371,29 @@ void Style::backgroundColor(int rgb565) const
9354
9371
  void Style::setProperty(const std::string &property, const std::string &value) const
9355
9372
  {
9356
9373
  if (nodeId() < 0) return;
9357
- StyleSheet::instance().applyProperty(NodeHandle(nodeId()), property, value);
9374
+ StyleSheet::instance().applyProperty(NodeHandle(nodeId_, identity_), property, value);
9375
+ }
9376
+
9377
+ bool NodeHandle::setStyleNumberProperty(const std::string &property, double value) const
9378
+ {
9379
+ // applyNumberDeclarationWithSource validates this handle; no Style, so no
9380
+ // second identity owner for the write.
9381
+ return StyleSheet::instance().applyNumberProperty(*this, property.c_str(), value);
9358
9382
  }
9359
9383
 
9360
9384
  bool Style::setNumberProperty(const std::string &property, double value) const
9361
9385
  {
9362
9386
  if (nodeId() < 0) return false;
9363
- return StyleSheet::instance().applyNumberProperty(NodeHandle(nodeId()), property.c_str(), value);
9387
+ // This Style holds the validated owner for the whole call, and numeric
9388
+ // style application keeps node ids, not handles, so the handle borrows it.
9389
+ return StyleSheet::instance().applyNumberProperty(NodeHandle(nodeId_, identity_, NodeHandle::Borrowed{}),
9390
+ property.c_str(), value);
9364
9391
  }
9365
9392
 
9366
9393
  bool Style::removeProperty(const std::string &property) const
9367
9394
  {
9368
9395
  if (nodeId() < 0) return false;
9369
- return StyleSheet::instance().removeProperty(NodeHandle(nodeId()), property);
9396
+ return StyleSheet::instance().removeProperty(NodeHandle(nodeId_, identity_), property);
9370
9397
  }
9371
9398
 
9372
9399
  void applyAnimatedStyleValue(int nodeId, Property property, int value)
@@ -9434,145 +9461,147 @@ void applyInheritedStyleDefaults(int node)
9434
9461
  #endif
9435
9462
  }
9436
9463
 
9437
- bool applyNumberDeclarationWithSource(NodeHandle node,
9464
+ bool applyNumberDeclarationWithSource(const NodeHandle &node,
9438
9465
  CssDeclarationId declaration,
9439
9466
  double value,
9440
9467
  StyleApplicationSource source)
9441
9468
  {
9442
- if (!node) return false;
9469
+ // The node is validated once here; its writes below reuse the live id.
9470
+ const int id = node.id();
9471
+ if (id < 0) return false;
9443
9472
  const int length = numericLength(value);
9444
9473
  switch (declaration) {
9445
9474
  case CssDeclarationId::Order:
9446
9475
  if (std::isfinite(value) && std::trunc(value) == value)
9447
- setStyleValue(node, Property::Order, static_cast<int>(std::clamp(value, -2147483648.0, 2147483647.0)), source);
9476
+ setValidatedStyleValue(node, id, Property::Order, static_cast<int>(std::clamp(value, -2147483648.0, 2147483647.0)), source);
9448
9477
  return true;
9449
9478
  case CssDeclarationId::Gap:
9450
- setStyleValue(node, Property::Gap, length, source);
9479
+ setValidatedStyleValue(node, id, Property::Gap, length, source);
9451
9480
  return true;
9452
9481
  case CssDeclarationId::Width:
9453
- setStyleValue(node, Property::Width, length, source);
9482
+ setValidatedStyleValue(node, id, Property::Width, length, source);
9454
9483
  return true;
9455
9484
  case CssDeclarationId::Height:
9456
- setStyleValue(node, Property::Height, length, source);
9485
+ setValidatedStyleValue(node, id, Property::Height, length, source);
9457
9486
  return true;
9458
9487
  case CssDeclarationId::MinWidth:
9459
- setStyleValue(node, Property::MinWidth, length, source);
9488
+ setValidatedStyleValue(node, id, Property::MinWidth, length, source);
9460
9489
  return true;
9461
9490
  case CssDeclarationId::MinHeight:
9462
- setStyleValue(node, Property::MinHeight, length, source);
9491
+ setValidatedStyleValue(node, id, Property::MinHeight, length, source);
9463
9492
  return true;
9464
9493
  case CssDeclarationId::MaxWidth:
9465
- setStyleValue(node, Property::MaxWidth, length, source);
9494
+ setValidatedStyleValue(node, id, Property::MaxWidth, length, source);
9466
9495
  return true;
9467
9496
  case CssDeclarationId::MaxHeight:
9468
- setStyleValue(node, Property::MaxHeight, length, source);
9497
+ setValidatedStyleValue(node, id, Property::MaxHeight, length, source);
9469
9498
  return true;
9470
9499
  case CssDeclarationId::Flex:
9471
- setStyleValue(node, Property::Flex, rawNumber(value), source);
9472
- setStyleValue(node, Property::FlexShrink, rawNumber(1.0), source);
9473
- setStyleValue(node, Property::FlexBasis, kUnset, source); // numeric `flex: N` has no explicit basis
9500
+ setValidatedStyleValue(node, id, Property::Flex, rawNumber(value), source);
9501
+ setValidatedStyleValue(node, id, Property::FlexShrink, rawNumber(1.0), source);
9502
+ setValidatedStyleValue(node, id, Property::FlexBasis, kUnset, source); // numeric `flex: N` has no explicit basis
9474
9503
  return true;
9475
9504
  case CssDeclarationId::Padding:
9476
9505
  setAllPadding(node, length, source);
9477
9506
  return true;
9478
9507
  case CssDeclarationId::PaddingTop:
9479
- setStyleValue(node, Property::PaddingTop, length, source);
9508
+ setValidatedStyleValue(node, id, Property::PaddingTop, length, source);
9480
9509
  return true;
9481
9510
  case CssDeclarationId::PaddingRight:
9482
- setStyleValue(node, Property::PaddingRight, length, source);
9511
+ setValidatedStyleValue(node, id, Property::PaddingRight, length, source);
9483
9512
  return true;
9484
9513
  case CssDeclarationId::PaddingBottom:
9485
- setStyleValue(node, Property::PaddingBottom, length, source);
9514
+ setValidatedStyleValue(node, id, Property::PaddingBottom, length, source);
9486
9515
  return true;
9487
9516
  case CssDeclarationId::PaddingLeft:
9488
- setStyleValue(node, Property::PaddingLeft, length, source);
9517
+ setValidatedStyleValue(node, id, Property::PaddingLeft, length, source);
9489
9518
  return true;
9490
9519
  case CssDeclarationId::Margin:
9491
9520
  setAllMargin(node, length, source);
9492
9521
  return true;
9493
9522
  case CssDeclarationId::MarginTop:
9494
- setStyleValue(node, Property::MarginTop, length, source);
9523
+ setValidatedStyleValue(node, id, Property::MarginTop, length, source);
9495
9524
  return true;
9496
9525
  case CssDeclarationId::MarginRight:
9497
- setStyleValue(node, Property::MarginRight, length, source);
9526
+ setValidatedStyleValue(node, id, Property::MarginRight, length, source);
9498
9527
  return true;
9499
9528
  case CssDeclarationId::MarginBottom:
9500
- setStyleValue(node, Property::MarginBottom, length, source);
9529
+ setValidatedStyleValue(node, id, Property::MarginBottom, length, source);
9501
9530
  return true;
9502
9531
  case CssDeclarationId::MarginLeft:
9503
- setStyleValue(node, Property::MarginLeft, length, source);
9532
+ setValidatedStyleValue(node, id, Property::MarginLeft, length, source);
9504
9533
  return true;
9505
9534
  case CssDeclarationId::Top:
9506
- setStyleValue(node, Property::Top, length, source);
9535
+ setValidatedStyleValue(node, id, Property::Top, length, source);
9507
9536
  return true;
9508
9537
  case CssDeclarationId::Right:
9509
- setStyleValue(node, Property::Right, length, source);
9538
+ setValidatedStyleValue(node, id, Property::Right, length, source);
9510
9539
  return true;
9511
9540
  case CssDeclarationId::Bottom:
9512
- setStyleValue(node, Property::Bottom, length, source);
9541
+ setValidatedStyleValue(node, id, Property::Bottom, length, source);
9513
9542
  return true;
9514
9543
  case CssDeclarationId::Left:
9515
- setStyleValue(node, Property::Left, length, source);
9544
+ setValidatedStyleValue(node, id, Property::Left, length, source);
9516
9545
  return true;
9517
9546
  case CssDeclarationId::ZIndex:
9518
- setStyleValue(node, Property::ZIndex, rawNumber(value), source);
9547
+ setValidatedStyleValue(node, id, Property::ZIndex, rawNumber(value), source);
9519
9548
  return true;
9520
9549
  case CssDeclarationId::Opacity:
9521
- setStyleValue(node, Property::Opacity, numericOpacity(value), source);
9550
+ setValidatedStyleValue(node, id, Property::Opacity, numericOpacity(value), source);
9522
9551
  return true;
9523
9552
  case CssDeclarationId::BorderWidth:
9524
9553
  if (value >= 0.0 && std::isfinite(value)) setUniformBorderWidth(node, snapBorderWidth(value), source);
9525
9554
  return true;
9526
9555
  case CssDeclarationId::BorderTopWidth:
9527
- if (value >= 0.0 && std::isfinite(value)) setStyleValue(node, Property::BorderTopWidth, snapBorderWidth(value), source);
9556
+ if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderTopWidth, snapBorderWidth(value), source);
9528
9557
  return true;
9529
9558
  case CssDeclarationId::BorderRightWidth:
9530
- if (value >= 0.0 && std::isfinite(value)) setStyleValue(node, Property::BorderRightWidth, snapBorderWidth(value), source);
9559
+ if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderRightWidth, snapBorderWidth(value), source);
9531
9560
  return true;
9532
9561
  case CssDeclarationId::BorderBottomWidth:
9533
- if (value >= 0.0 && std::isfinite(value)) setStyleValue(node, Property::BorderBottomWidth, snapBorderWidth(value), source);
9562
+ if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderBottomWidth, snapBorderWidth(value), source);
9534
9563
  return true;
9535
9564
  case CssDeclarationId::BorderLeftWidth:
9536
- if (value >= 0.0 && std::isfinite(value)) setStyleValue(node, Property::BorderLeftWidth, snapBorderWidth(value), source);
9565
+ if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderLeftWidth, snapBorderWidth(value), source);
9537
9566
  return true;
9538
9567
  case CssDeclarationId::BorderRadius:
9539
9568
  setAllBorderRadius(node, length, source);
9540
9569
  return true;
9541
9570
  case CssDeclarationId::BorderTopLeftRadius:
9542
- setStyleValue(node, Property::BorderRadiusTopLeft, length, source);
9571
+ setValidatedStyleValue(node, id, Property::BorderRadiusTopLeft, length, source);
9543
9572
  return true;
9544
9573
  case CssDeclarationId::BorderTopRightRadius:
9545
- setStyleValue(node, Property::BorderRadiusTopRight, length, source);
9574
+ setValidatedStyleValue(node, id, Property::BorderRadiusTopRight, length, source);
9546
9575
  return true;
9547
9576
  case CssDeclarationId::BorderBottomRightRadius:
9548
- setStyleValue(node, Property::BorderRadiusBottomRight, length, source);
9577
+ setValidatedStyleValue(node, id, Property::BorderRadiusBottomRight, length, source);
9549
9578
  return true;
9550
9579
  case CssDeclarationId::BorderBottomLeftRadius:
9551
- setStyleValue(node, Property::BorderRadiusBottomLeft, length, source);
9580
+ setValidatedStyleValue(node, id, Property::BorderRadiusBottomLeft, length, source);
9552
9581
  return true;
9553
9582
  case CssDeclarationId::FontSize:
9554
- setStyleValue(node, Property::FontSize, length, source);
9583
+ setValidatedStyleValue(node, id, Property::FontSize, length, source);
9555
9584
  return true;
9556
9585
  #if GEA_CSS_FONT_STRETCH
9557
9586
  case CssDeclarationId::FontStretch:
9558
9587
  if (!std::isfinite(value) || value <= 0) return false;
9559
- setStyleValue(node, Property::FontStretch, std::clamp(roundToInt(std::clamp(value, 0.1, 3276.7) * 10), 1, 32767), source);
9588
+ setValidatedStyleValue(node, id, Property::FontStretch, std::clamp(roundToInt(std::clamp(value, 0.1, 3276.7) * 10), 1, 32767), source);
9560
9589
  return true;
9561
9590
  #endif
9562
9591
  case CssDeclarationId::FontWeight:
9563
- setStyleValue(node, Property::FontWeight, std::clamp(roundToInt(value), 1, 1000), source);
9592
+ setValidatedStyleValue(node, id, Property::FontWeight, std::clamp(roundToInt(value), 1, 1000), source);
9564
9593
  return true;
9565
9594
  case CssDeclarationId::LineHeight: {
9566
9595
  const float multiplier = static_cast<float>(value);
9567
9596
  if (!std::isfinite(multiplier) || multiplier < 0) return false;
9568
9597
  int bits = 0; if (multiplier != 0) std::memcpy(&bits, &multiplier, sizeof(bits));
9569
- setStyleValue(node, Property::LineHeightMultiplier, bits, source);
9598
+ setValidatedStyleValue(node, id, Property::LineHeightMultiplier, bits, source);
9570
9599
  return true;
9571
9600
  }
9572
9601
  #if GEA_CSS_TRANSFORMS
9573
9602
  case CssDeclarationId::Transform:
9574
- setStyleValue(node, Property::TransformPresent, 1, source);
9575
- setStyleValue(node, Property::TransformRotate, numericRotateTenths(value), source);
9603
+ setValidatedStyleValue(node, id, Property::TransformPresent, 1, source);
9604
+ setValidatedStyleValue(node, id, Property::TransformRotate, numericRotateTenths(value), source);
9576
9605
  return true;
9577
9606
  case CssDeclarationId::Rotate: {
9578
9607
  IndividualRotation rotation; rotation.angle = numericRotateTenths(value);
@@ -9589,9 +9618,10 @@ bool applyNumberDeclarationWithSource(NodeHandle node,
9589
9618
  }
9590
9619
  }
9591
9620
 
9592
- bool applyNumberPropertyWithSource(NodeHandle node, const char *property, double value, StyleApplicationSource source)
9621
+ bool applyNumberPropertyWithSource(const NodeHandle &node, const char *property, double value, StyleApplicationSource source)
9593
9622
  {
9594
- if (!node || !property) return false;
9623
+ // applyNumberDeclarationWithSource validates the node first.
9624
+ if (!property) return false;
9595
9625
  return applyNumberDeclarationWithSource(node, classifyDeclaration(property), value, source);
9596
9626
  }
9597
9627
 
@@ -18545,12 +18575,12 @@ bool StyleSheet::applyPixelLengthProperty(NodeHandle node, StyleDeclaration decl
18545
18575
  return false;
18546
18576
  }
18547
18577
 
18548
- bool StyleSheet::applyNumberProperty(NodeHandle node, const char *property, double value) const
18578
+ bool StyleSheet::applyNumberProperty(const NodeHandle &node, const char *property, double value) const
18549
18579
  {
18550
18580
  return applyNumberPropertyWithSource(node, property, value, StyleApplicationSource::Inline);
18551
18581
  }
18552
18582
 
18553
- bool StyleSheet::applyNumberProperty(NodeHandle node, StyleDeclaration declaration, double value) const
18583
+ bool StyleSheet::applyNumberProperty(const NodeHandle &node, StyleDeclaration declaration, double value) const
18554
18584
  {
18555
18585
  return applyNumberDeclarationWithSource(node, declaration, value, StyleApplicationSource::Inline);
18556
18586
  }
@@ -18625,9 +18655,15 @@ void Tree::setClassName(int node, const char *className)
18625
18655
  // growth, so tagFromId can hand out c_str() pointers that stay valid. Index 0
18626
18656
  // is the empty tag, matching Node::tag_id's zero default.
18627
18657
  namespace {
18658
+ // tagFromId runs for every node on every frame. Without hardware atomics
18659
+ // (ESP32-S3) a guarded function-local static takes an RTOS mutex on each
18660
+ // access, so later calls read the table through an acquire-loaded pointer.
18628
18661
  std::deque<std::string> &tagTable()
18629
18662
  {
18663
+ static std::atomic<std::deque<std::string> *> ready{nullptr};
18664
+ if (auto *table = ready.load(std::memory_order_acquire)) return *table;
18630
18665
  static std::deque<std::string> table = {std::string()};
18666
+ ready.store(&table, std::memory_order_release);
18631
18667
  return table;
18632
18668
  }
18633
18669
  } // namespace
package/ui/style.h CHANGED
@@ -356,6 +356,7 @@ class Style {
356
356
  public:
357
357
  explicit Style(int nodeId = -1)
358
358
  : nodeId_(nodeId), identity_(gea::framework::identity::node(nodeId)) {}
359
+ Style(int nodeId, gea::framework::identity::Owner owner) : nodeId_(nodeId), identity_(std::move(owner)) {}
359
360
 
360
361
  int nodeId() const { return gea::framework::identity::current(nodeId_, identity_) ? nodeId_ : -1; }
361
362
  void set(Property property, int value) const;
@@ -864,8 +865,8 @@ public:
864
865
  void applyProperty(NodeHandle node, const std::string &property, const std::string &value) const;
865
866
  // Preserve CSS px units through device scaling before property-specific rounding.
866
867
  bool applyPixelLengthProperty(NodeHandle node, StyleDeclaration declaration, double value) const;
867
- bool applyNumberProperty(NodeHandle node, StyleDeclaration declaration, double value) const;
868
- bool applyNumberProperty(NodeHandle node, const char *property, double value) const;
868
+ bool applyNumberProperty(const NodeHandle &node, StyleDeclaration declaration, double value) const;
869
+ bool applyNumberProperty(const NodeHandle &node, const char *property, double value) const;
869
870
  bool removeProperty(NodeHandle node, const std::string &property) const;
870
871
  void recomputeSubtree(int nodeId) const;
871
872
  void hoverChanged() const;