@onekeyfe/react-native-native-list 3.0.157 → 3.0.159

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.md +21 -5
  2. package/android/build.gradle +7 -0
  3. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +20 -0
  4. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +711 -0
  5. package/android/src/main/java/com/onekey/nativelist/NativeListActionRenderer.kt +169 -0
  6. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +179 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +264 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +20 -6
  9. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +53 -0
  10. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +487 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListEndAlignment.kt +5 -0
  12. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +820 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListImageSlot.kt +147 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +453 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +997 -0
  16. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +268 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +243 -0
  18. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +232 -0
  19. package/android/src/main/java/com/onekey/nativelist/NativeListMetricCardRenderer.kt +551 -0
  20. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +27 -1
  21. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +475 -0
  22. package/android/src/main/java/com/onekey/nativelist/NativeListRailRenderer.kt +143 -0
  23. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +42 -0
  24. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +415 -0
  25. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +163 -0
  26. package/android/src/main/java/com/onekey/nativelist/NativeListRowHost.kt +70 -0
  27. package/android/src/main/java/com/onekey/nativelist/NativeListScrollPositionTracker.kt +59 -0
  28. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +763 -0
  29. package/android/src/main/java/com/onekey/nativelist/NativeListSystemRenderer.kt +464 -0
  30. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +25 -0
  31. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +432 -124
  32. package/android/src/main/java/com/onekey/nativelist/NativeListWalletGroupRenderer.kt +407 -0
  33. package/android/src/main/res/values/native_scroll_coordinator_ids.xml +5 -0
  34. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListEndAlignmentTest.kt +34 -0
  35. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListScrollPositionTrackerTest.kt +44 -0
  36. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListSelectorBackgroundColorTest.kt +34 -0
  37. package/docs/DESIGN.md +520 -9
  38. package/docs/MIGRATION_BASELINE.md +117 -0
  39. package/docs/ROW_TEMPLATES.md +404 -0
  40. package/docs/SPEC.md +621 -0
  41. package/docs/STYLE_SPEC.md +988 -0
  42. package/docs/images/list-capabilities.svg +39 -0
  43. package/docs/images/row-action.svg +17 -0
  44. package/docs/images/row-activity.svg +24 -0
  45. package/docs/images/row-data.svg +24 -0
  46. package/docs/images/row-identity.svg +25 -0
  47. package/docs/images/row-market.svg +23 -0
  48. package/docs/images/row-media-tile.svg +26 -0
  49. package/docs/images/row-message.svg +20 -0
  50. package/docs/images/row-metric-card.svg +33 -0
  51. package/docs/images/row-rail.svg +18 -0
  52. package/docs/images/row-section-header.svg +19 -0
  53. package/docs/images/row-style-regions.svg +30 -0
  54. package/docs/images/row-system.svg +30 -0
  55. package/docs/images/row-wallet-group.svg +26 -0
  56. package/ios/HybridNativeList.swift +30 -0
  57. package/ios/NativeListAccessoryStack.swift +680 -0
  58. package/ios/NativeListActionRenderer.swift +108 -0
  59. package/ios/NativeListActivityDetailsView.swift +291 -0
  60. package/ios/NativeListActivityRenderer.swift +201 -0
  61. package/ios/NativeListDataRowRenderer.swift +444 -0
  62. package/ios/NativeListIdentityRenderer.swift +685 -0
  63. package/ios/NativeListImageSlot.swift +140 -0
  64. package/ios/NativeListLeadingVisual.swift +372 -0
  65. package/ios/NativeListMarketRenderer.swift +698 -0
  66. package/ios/NativeListMediaPreviewSlot.swift +259 -0
  67. package/ios/NativeListMediaTileRenderer.swift +190 -0
  68. package/ios/NativeListMessageRenderer.swift +168 -0
  69. package/ios/NativeListMetricCardRenderer.swift +420 -0
  70. package/ios/NativeListModels.swift +36 -1
  71. package/ios/NativeListRailRenderer.swift +152 -0
  72. package/ios/NativeListRendererCell.swift +311 -0
  73. package/ios/NativeListRendererRegistry.swift +50 -0
  74. package/ios/NativeListResolvedText.swift +130 -0
  75. package/ios/NativeListRowHost.swift +63 -0
  76. package/ios/NativeListScrollPositionTracker.swift +30 -0
  77. package/ios/NativeListSectionHeaderRenderer.swift +734 -0
  78. package/ios/NativeListSystemRenderer.swift +568 -0
  79. package/ios/NativeListTextLabel.swift +42 -0
  80. package/ios/NativeListTextStyles.swift +236 -0
  81. package/ios/NativeListWalletGroupRenderer.swift +255 -0
  82. package/ios/RNCNativeListView.swift +282 -184
  83. package/ios/tests/NativeListActivityPresentationTests.swift +97 -0
  84. package/ios/tests/NativeListLifecycleTests.swift +241 -0
  85. package/ios/tests/NativeListMediaVisibilityTests.swift +109 -0
  86. package/ios/tests/NativeListScrollPositionTrackerTests.swift +25 -0
  87. package/lib/module/NativeList.js +56 -3
  88. package/lib/module/NativeList.web.js +5 -0
  89. package/lib/module/models.js +54 -0
  90. package/lib/module/validation.js +386 -28
  91. package/lib/module/web/NativeListWebEngine.js +148 -936
  92. package/lib/module/web/templates/ActionRowRenderer.js +97 -0
  93. package/lib/module/web/templates/ActivityRowRenderer.js +95 -0
  94. package/lib/module/web/templates/DataRowRenderer.js +145 -0
  95. package/lib/module/web/templates/IdentityRowRenderer.js +289 -0
  96. package/lib/module/web/templates/MarketRowRenderer.js +310 -0
  97. package/lib/module/web/templates/MediaTileRowRenderer.js +132 -0
  98. package/lib/module/web/templates/MessageRowRenderer.js +165 -0
  99. package/lib/module/web/templates/MetricCardRowRenderer.js +172 -0
  100. package/lib/module/web/templates/RailRowRenderer.js +98 -0
  101. package/lib/module/web/templates/RowContainerStyle.js +100 -0
  102. package/lib/module/web/templates/RowElements.js +93 -0
  103. package/lib/module/web/templates/RowRendererRegistry.js +70 -0
  104. package/lib/module/web/templates/RowText.js +121 -0
  105. package/lib/module/web/templates/RowVisual.js +43 -0
  106. package/lib/module/web/templates/SectionHeaderRowRenderer.js +146 -0
  107. package/lib/module/web/templates/SystemRowRenderer.js +161 -0
  108. package/lib/module/web/templates/WalletGroupRowRenderer.js +96 -0
  109. package/lib/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  110. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
  111. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
  112. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
  113. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
  114. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
  115. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
  116. package/lib/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
  117. package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
  118. package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
  119. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
  120. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
  121. package/lib/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  122. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
  123. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
  124. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
  125. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
  126. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
  127. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
  128. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
  129. package/lib/typescript/src/NativeList.nitro.d.ts +3 -0
  130. package/lib/typescript/src/NativeList.types.d.ts +14 -1
  131. package/lib/typescript/src/models.d.ts +199 -18
  132. package/lib/typescript/src/web/NativeListWebEngine.d.ts +18 -16
  133. package/lib/typescript/src/web/templates/ActionRowRenderer.d.ts +15 -0
  134. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +15 -0
  135. package/lib/typescript/src/web/templates/DataRowRenderer.d.ts +15 -0
  136. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +16 -0
  137. package/lib/typescript/src/web/templates/MarketRowRenderer.d.ts +30 -0
  138. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +15 -0
  139. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +44 -0
  140. package/lib/typescript/src/web/templates/MetricCardRowRenderer.d.ts +15 -0
  141. package/lib/typescript/src/web/templates/RailRowRenderer.d.ts +28 -0
  142. package/lib/typescript/src/web/templates/RowContainerStyle.d.ts +9 -0
  143. package/lib/typescript/src/web/templates/RowElements.d.ts +38 -0
  144. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +83 -0
  145. package/lib/typescript/src/web/templates/RowText.d.ts +9 -0
  146. package/lib/typescript/src/web/templates/RowVisual.d.ts +20 -0
  147. package/lib/typescript/src/web/templates/SectionHeaderRowRenderer.d.ts +15 -0
  148. package/lib/typescript/src/web/templates/SystemRowRenderer.d.ts +16 -0
  149. package/lib/typescript/src/web/templates/WalletGroupRowRenderer.d.ts +20 -0
  150. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  151. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
  152. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
  153. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
  154. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
  155. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
  156. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
  157. package/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
  158. package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
  159. package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
  160. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
  161. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
  162. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  163. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
  164. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
  165. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
  166. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
  167. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
  168. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
  169. package/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
  170. package/package.json +7 -6
  171. package/react-native-native-list.podspec +6 -0
  172. package/scripts/enable-container-slots.mjs +58 -0
  173. package/scripts/enable-container-slots.test.mjs +58 -0
  174. package/src/NativeList.nitro.ts +3 -0
  175. package/src/NativeList.tsx +84 -2
  176. package/src/NativeList.types.ts +14 -1
  177. package/src/NativeList.web.tsx +5 -0
  178. package/src/models.ts +320 -20
  179. package/src/validation.ts +641 -49
  180. package/src/web/NativeListWebEngine.ts +361 -1932
  181. package/src/web/templates/ActionRowRenderer.ts +123 -0
  182. package/src/web/templates/ActivityRowRenderer.ts +159 -0
  183. package/src/web/templates/DataRowRenderer.ts +212 -0
  184. package/src/web/templates/IdentityRowRenderer.ts +527 -0
  185. package/src/web/templates/MarketRowRenderer.ts +467 -0
  186. package/src/web/templates/MediaTileRowRenderer.ts +182 -0
  187. package/src/web/templates/MessageRowRenderer.ts +306 -0
  188. package/src/web/templates/MetricCardRowRenderer.ts +337 -0
  189. package/src/web/templates/RailRowRenderer.ts +136 -0
  190. package/src/web/templates/RowContainerStyle.ts +131 -0
  191. package/src/web/templates/RowElements.ts +160 -0
  192. package/src/web/templates/RowRendererRegistry.ts +111 -0
  193. package/src/web/templates/RowText.ts +181 -0
  194. package/src/web/templates/RowVisual.ts +115 -0
  195. package/src/web/templates/SectionHeaderRowRenderer.ts +243 -0
  196. package/src/web/templates/SystemRowRenderer.ts +282 -0
  197. package/src/web/templates/WalletGroupRowRenderer.ts +131 -0
  198. package/android/src/main/java/com/onekey/nativelist/NativeListRowView.kt +0 -4538
  199. package/ios/NativeListCell.swift +0 -4300
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ import { ROW_BOX_STYLE_KEYS_BY_TYPE } from "./models.js";
3
4
  const MAX_KEY_LENGTH = 256;
4
5
  const MAX_TEXT_LENGTH = 4096;
5
6
  const MAX_BADGES = 2;
@@ -68,8 +69,90 @@ function assertBoundedStyleNumber(value, path, min, max) {
68
69
  fail(path, `must be within ${min}...${max}`);
69
70
  }
70
71
  }
71
- function assertMarketTextStyle(style, path) {
72
- if (!style) return;
72
+
73
+ /**
74
+ * The named typography scale from docs/STYLE_SPEC.md §3.2. Tokens are resolved
75
+ * to numbers here, before serialization, so the iOS, Android, and Web renderers
76
+ * never learn the vocabulary and cannot drift from it.
77
+ */
78
+ const TYPOGRAPHY_TOKENS = {
79
+ $headingXl: {
80
+ fontSize: 24,
81
+ lineHeight: 32,
82
+ fontWeight: 'semibold'
83
+ },
84
+ $headingLg: {
85
+ fontSize: 20,
86
+ lineHeight: 28,
87
+ fontWeight: 'semibold'
88
+ },
89
+ $headingMd: {
90
+ fontSize: 18,
91
+ lineHeight: 24,
92
+ fontWeight: 'semibold'
93
+ },
94
+ $headingSm: {
95
+ fontSize: 16,
96
+ lineHeight: 24,
97
+ fontWeight: 'medium'
98
+ },
99
+ $headingXs: {
100
+ fontSize: 14,
101
+ lineHeight: 20,
102
+ fontWeight: 'semibold'
103
+ },
104
+ $bodyLg: {
105
+ fontSize: 16,
106
+ lineHeight: 24,
107
+ fontWeight: 'regular'
108
+ },
109
+ $bodyMd: {
110
+ fontSize: 14,
111
+ lineHeight: 20,
112
+ fontWeight: 'regular'
113
+ },
114
+ $bodySm: {
115
+ fontSize: 12,
116
+ lineHeight: 16,
117
+ fontWeight: 'regular'
118
+ },
119
+ $bodyXs: {
120
+ fontSize: 11,
121
+ lineHeight: 16,
122
+ fontWeight: 'regular'
123
+ }
124
+ };
125
+
126
+ /** Style keys name model fields, never views. See docs/STYLE_SPEC.md §4. */
127
+ const TEXT_STYLE_KEYS_BY_ROW_TYPE = {
128
+ identity: ['title', 'subtitle', 'tertiary', 'badge', 'value', 'valueSecondary'],
129
+ walletGroup: [],
130
+ rail: ['title', 'badge', 'status'],
131
+ activity: ['title', 'description', 'status', 'primaryAmount', 'secondaryAmount'],
132
+ message: ['title', 'body', 'time'],
133
+ dataRow: ['columns', 'columnSecondary', 'index'],
134
+ market: ['title', 'subtitle', 'price', 'change'],
135
+ mediaTile: ['title', 'subtitle', 'badge'],
136
+ metricCard: ['title', 'value', 'subtitle', 'trend'],
137
+ sectionHeader: ['title', 'subtitle', 'value'],
138
+ action: ['title', 'value'],
139
+ system: ['title', 'message', 'actionText']
140
+ };
141
+ const EXTRA_STYLE_KEYS_BY_ROW_TYPE = {
142
+ market: ['titleBadgeLayout', 'contentTrailingGap', 'subtitleTrailingPadding', 'changeWidth', 'changeHeight', 'changeCornerRadius']
143
+ };
144
+ function assertTextStyle(style, path, additionalKeys = []) {
145
+ if (style === undefined) return;
146
+ if (typeof style !== 'object' || style === null || Array.isArray(style)) {
147
+ fail(path, 'must be an object');
148
+ }
149
+ assertUnknownKeys(style, ['token', 'fontSize', 'fontWeight', 'color', 'lineHeight', 'lines', 'truncate', 'alignment', 'verticalAlignment', 'offsetY', ...additionalKeys], path, 'text style key');
150
+ if (style.color !== undefined && (typeof style.color !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(style.color))) {
151
+ fail(`${path}.color`, 'must be #RRGGBB or #RRGGBBAA');
152
+ }
153
+ if (style.token !== undefined && !Object.prototype.hasOwnProperty.call(TYPOGRAPHY_TOKENS, style.token)) {
154
+ fail(`${path}.token`, `must be one of ${Object.keys(TYPOGRAPHY_TOKENS).join(', ')}`);
155
+ }
73
156
  assertBoundedStyleNumber(style.fontSize, `${path}.fontSize`, 8, 48);
74
157
  assertBoundedStyleNumber(style.lineHeight, `${path}.lineHeight`, 8, 64);
75
158
  if (style.fontWeight !== undefined && !['regular', 'medium', 'semibold', 'bold'].includes(style.fontWeight)) {
@@ -78,36 +161,191 @@ function assertMarketTextStyle(style, path) {
78
161
  if (style.alignment !== undefined && !['start', 'center', 'end'].includes(style.alignment)) {
79
162
  fail(`${path}.alignment`, 'must be start, center, or end');
80
163
  }
81
- if (style.lines !== undefined && ![1, 2].includes(style.lines)) {
82
- fail(`${path}.lines`, 'must be 1 or 2');
164
+ if (style.lines !== undefined && ![1, 2, 3].includes(style.lines)) {
165
+ fail(`${path}.lines`, 'must be 1, 2, or 3');
166
+ }
167
+ if (style.truncate !== undefined && !['tail', 'clip'].includes(style.truncate)) {
168
+ fail(`${path}.truncate`, 'must be tail or clip');
169
+ }
170
+ if (style.verticalAlignment !== undefined && !['top', 'center', 'bottom'].includes(style.verticalAlignment)) {
171
+ fail(`${path}.verticalAlignment`, 'must be top, center, or bottom');
172
+ }
173
+ assertBoundedStyleNumber(style.offsetY, `${path}.offsetY`, -8, 8);
174
+ }
175
+ function assertBoxStyle(style, path) {
176
+ const container = style.container;
177
+ if (container !== undefined) {
178
+ const containerPath = `${path}.container`;
179
+ if (typeof container !== 'object' || container === null || Array.isArray(container)) {
180
+ fail(containerPath, 'must be an object');
181
+ }
182
+ assertUnknownKeys(container, ['height', 'backgroundColor', 'opacity', 'cornerRadius', 'borderWidth', 'borderColor', 'contentVerticalAlignment'], containerPath, 'row container style key');
183
+ for (const key of ['backgroundColor', 'borderColor']) {
184
+ const value = container[key];
185
+ if (value !== undefined && (typeof value !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value))) {
186
+ fail(`${containerPath}.${key}`, 'must be #RRGGBB or #RRGGBBAA');
187
+ }
188
+ }
189
+ assertBoundedStyleNumber(container.height, `${containerPath}.height`, 0, 4096);
190
+ assertBoundedStyleNumber(container.opacity, `${containerPath}.opacity`, 0, 1);
191
+ assertBoundedStyleNumber(container.cornerRadius, `${containerPath}.cornerRadius`, 0, 80);
192
+ assertBoundedStyleNumber(container.borderWidth, `${containerPath}.borderWidth`, 0, 8);
193
+ if (container.contentVerticalAlignment !== undefined && !['top', 'center', 'bottom'].includes(container.contentVerticalAlignment)) {
194
+ fail(`${containerPath}.contentVerticalAlignment`, 'must be top, center, or bottom');
195
+ }
196
+ }
197
+ for (const field of ['horizontalPadding', 'verticalPadding', 'leadingGap', 'titleBadgeGap', 'trailingGap']) {
198
+ assertBoundedStyleNumber(style[field], `${path}.${field}`, 0, 64);
199
+ }
200
+ assertBoundedStyleNumber(style.lineGap, `${path}.lineGap`, 0, 16);
201
+ if (style.image !== undefined) {
202
+ if (typeof style.image !== 'object' || style.image === null || Array.isArray(style.image)) {
203
+ fail(`${path}.image`, 'must be an object');
204
+ }
205
+ assertUnknownKeys(style.image, ['width', 'height', 'shape', 'cornerRadius', 'contentFit'], `${path}.image`, 'image style key');
206
+ assertBoundedStyleNumber(style.image.width, `${path}.image.width`, 1, 160);
207
+ assertBoundedStyleNumber(style.image.height, `${path}.image.height`, 1, 160);
208
+ assertBoundedStyleNumber(style.image.cornerRadius, `${path}.image.cornerRadius`, 0, 80);
209
+ assertVisualShape(style.image.shape, `${path}.image.shape`);
210
+ if (style.image.contentFit !== undefined && !['cover', 'contain', 'fill', 'center'].includes(style.image.contentFit)) {
211
+ fail(`${path}.image.contentFit`, 'must be cover, contain, fill, or center');
212
+ }
83
213
  }
84
214
  }
85
215
  function assertMarketStyle(style, path) {
86
216
  if (!style) return;
87
- for (const field of ['horizontalPadding', 'verticalPadding', 'leadingGap', 'titleBadgeGap', 'trailingGap', 'contentTrailingGap', 'subtitleTrailingPadding']) {
217
+ assertBoxStyle(style, path);
218
+ for (const field of ['contentTrailingGap', 'subtitleTrailingPadding']) {
88
219
  assertBoundedStyleNumber(style[field], `${path}.${field}`, 0, 64);
89
220
  }
90
221
  // OneKey patch: validate the opt-in Market badge layout.
91
222
  if (style.titleBadgeLayout !== undefined && style.titleBadgeLayout !== 'inline') {
92
223
  fail(`${path}.titleBadgeLayout`, 'must be inline when provided');
93
224
  }
94
- assertBoundedStyleNumber(style.lineGap, `${path}.lineGap`, 0, 16);
95
225
  assertBoundedStyleNumber(style.changeWidth, `${path}.changeWidth`, 1, 160);
96
226
  assertBoundedStyleNumber(style.changeHeight, `${path}.changeHeight`, 1, 160);
97
227
  assertBoundedStyleNumber(style.changeCornerRadius, `${path}.changeCornerRadius`, 0, 80);
98
- if (style.image) {
99
- assertBoundedStyleNumber(style.image.width, `${path}.image.width`, 1, 160);
100
- assertBoundedStyleNumber(style.image.height, `${path}.image.height`, 1, 160);
101
- assertBoundedStyleNumber(style.image.cornerRadius, `${path}.image.cornerRadius`, 0, 80);
102
- assertVisualShape(style.image.shape, `${path}.image.shape`);
103
- if (style.image.contentFit !== undefined && !['cover', 'contain', 'fill', 'center'].includes(style.image.contentFit)) {
104
- fail(`${path}.image.contentFit`, 'must be cover, contain, fill, or center');
228
+ assertTextStyle(style.title, `${path}.title`);
229
+ assertTextStyle(style.subtitle, `${path}.subtitle`);
230
+ assertTextStyle(style.price, `${path}.price`);
231
+ assertTextStyle(style.change, `${path}.change`);
232
+ }
233
+
234
+ /**
235
+ * Rejects keys the template does not declare, so a style written for one
236
+ * template cannot reach a shared view through another. See docs/STYLE_SPEC.md
237
+ * §7 rule 1.
238
+ */
239
+ function assertRowStyle(row, path) {
240
+ const style = row.style;
241
+ if (style === undefined) return;
242
+ if (typeof style !== 'object' || style === null || Array.isArray(style)) {
243
+ fail(`${path}.style`, 'must be an object');
244
+ }
245
+ const textKeys = TEXT_STYLE_KEYS_BY_ROW_TYPE[row.type] ?? [];
246
+ const allowed = new Set(['container', ...ROW_BOX_STYLE_KEYS_BY_TYPE[row.type], ...textKeys, ...(EXTRA_STYLE_KEYS_BY_ROW_TYPE[row.type] ?? [])]);
247
+ Object.keys(style).forEach(key => {
248
+ if (!allowed.has(key)) {
249
+ fail(`${path}.style.${key}`, `is not a style key of the "${row.type}" template`);
105
250
  }
251
+ });
252
+ // Market keeps its own richer assertions, driven from assertMarketRow.
253
+ if (row.type === 'market') return;
254
+ assertBoxStyle(style, `${path}.style`);
255
+ const slots = style;
256
+ textKeys.forEach(key => assertTextStyle(slots[key], `${path}.style.${key}`));
257
+ }
258
+ const LIST_STYLE_KEYS = ['separator', 'groupCornerRadius'];
259
+ const SEPARATOR_STYLE_KEYS = ['inset', 'color'];
260
+ function assertUnknownKeys(value, allowed, path, subject) {
261
+ Object.keys(value).forEach(key => {
262
+ if (!allowed.includes(key)) fail(`${path}.${key}`, `is not a ${subject}`);
263
+ });
264
+ }
265
+ function assertListStyle(listStyle, path) {
266
+ if (listStyle === undefined) return;
267
+ if (typeof listStyle !== 'object' || listStyle === null || Array.isArray(listStyle)) {
268
+ fail(path, 'must be an object');
269
+ }
270
+ assertUnknownKeys(listStyle, LIST_STYLE_KEYS, path, 'list style key');
271
+ assertBoundedStyleNumber(listStyle.groupCornerRadius, `${path}.groupCornerRadius`, 0, 40);
272
+ const separator = listStyle.separator;
273
+ if (separator === undefined) return;
274
+ if (typeof separator !== 'object' || separator === null || Array.isArray(separator)) {
275
+ fail(`${path}.separator`, 'must be an object');
276
+ }
277
+ assertUnknownKeys(separator, SEPARATOR_STYLE_KEYS, `${path}.separator`, 'separator style key');
278
+ assertBoundedStyleNumber(separator.inset, `${path}.separator.inset`, 0, 64);
279
+ // Same format as every row style color; renderers parse it directly.
280
+ if (separator.color !== undefined && (typeof separator.color !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(separator.color))) {
281
+ fail(`${path}.separator.color`, 'must be #RRGGBB or #RRGGBBAA');
106
282
  }
107
- assertMarketTextStyle(style.title, `${path}.title`);
108
- assertMarketTextStyle(style.subtitle, `${path}.subtitle`);
109
- assertMarketTextStyle(style.price, `${path}.price`);
110
- assertMarketTextStyle(style.change, `${path}.change`);
283
+ }
284
+
285
+ /** Token resolution is idempotent: a resolved style carries no token. */
286
+ function resolveTextStyle(style) {
287
+ if (!style?.token) return style;
288
+ const {
289
+ token,
290
+ ...overrides
291
+ } = style;
292
+ return {
293
+ ...TYPOGRAPHY_TOKENS[token],
294
+ ...overrides
295
+ };
296
+ }
297
+ function resolveStyleTokens(style, rowType) {
298
+ const textKeys = TEXT_STYLE_KEYS_BY_ROW_TYPE[rowType] ?? [];
299
+ let changed = false;
300
+ const next = {
301
+ ...style
302
+ };
303
+ textKeys.forEach(key => {
304
+ const slot = style[key];
305
+ const resolved = resolveTextStyle(slot);
306
+ if (resolved !== slot) {
307
+ next[key] = resolved;
308
+ changed = true;
309
+ }
310
+ });
311
+ return changed ? next : style;
312
+ }
313
+ function normalizeRowStyles(row) {
314
+ // Narrowing a generic does not reach the walletGroup members; go through the
315
+ // union type instead.
316
+ const model = row;
317
+ const style = row.style;
318
+ const nextStyle = style ? resolveStyleTokens(style, row.type) : style;
319
+ const prefix = model.type === 'market' ? model.subtitlePrefix : undefined;
320
+ const nextPrefixStyle = resolveTextStyle(prefix?.style);
321
+ let nextParent;
322
+ let nextChildren;
323
+ if (model.type === 'walletGroup') {
324
+ const parent = normalizeRowStyles(model.parent);
325
+ const children = model.children.map(normalizeRowStyles);
326
+ if (parent !== model.parent || children.some((child, index) => child !== model.children[index])) {
327
+ nextParent = parent;
328
+ nextChildren = children;
329
+ }
330
+ }
331
+ if (nextStyle === style && nextPrefixStyle === prefix?.style && nextParent === undefined) {
332
+ return row;
333
+ }
334
+ const next = {
335
+ ...row
336
+ };
337
+ if (nextStyle !== style) next.style = nextStyle;
338
+ if (prefix && nextPrefixStyle !== prefix.style) {
339
+ next.subtitlePrefix = {
340
+ ...prefix,
341
+ style: nextPrefixStyle
342
+ };
343
+ }
344
+ if (nextParent !== undefined) {
345
+ next.parent = nextParent;
346
+ next.children = nextChildren;
347
+ }
348
+ return next;
111
349
  }
112
350
  function assertMarketRow(row, path) {
113
351
  if (!['token', 'stock', 'perp'].includes(row.variant)) {
@@ -120,7 +358,7 @@ function assertMarketRow(row, path) {
120
358
  assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
121
359
  assertBoundedStyleNumber(row.subtitlePrefix.gap, `${path}.subtitlePrefix.gap`, 0, 64);
122
360
  assertBoundedStyleNumber(row.subtitlePrefix.maxWidth, `${path}.subtitlePrefix.maxWidth`, 1, 320);
123
- assertMarketTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
361
+ assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
124
362
  }
125
363
  assertText(row.price, `${path}.price`);
126
364
  assertText(row.change.text, `${path}.change.text`);
@@ -159,7 +397,8 @@ function assertMarketRow(row, path) {
159
397
  badgeKeys.add(badge.key);
160
398
  assertText(badge.text, `${badgePath}.text`);
161
399
  // OneKey patch: share typography bounds with Market text styles.
162
- assertMarketTextStyle(badge.style, `${badgePath}.style`);
400
+ assertTextStyle(badge.style, `${badgePath}.style`, ['height', 'horizontalPadding']);
401
+ if (badge.style) assertUnknownKeys(badge.style, ['fontSize', 'fontWeight', 'lineHeight', 'height', 'horizontalPadding'], `${badgePath}.style`, 'Market badge style key');
163
402
  assertBoundedStyleNumber(badge.style?.height, `${badgePath}.style.height`, 1, 64);
164
403
  assertBoundedStyleNumber(badge.style?.horizontalPadding, `${badgePath}.style.horizontalPadding`, 0, 32);
165
404
  if (badge.iconName !== undefined && badge.iconName !== 'verified') {
@@ -278,6 +517,46 @@ function assertVisual(row, path) {
278
517
  });
279
518
  }
280
519
  function assertActivity(row, path) {
520
+ assertText(row.title, `${path}.title`);
521
+ assertText(row.description, `${path}.description`);
522
+ if (row.presentation !== undefined && !['stacked', 'table'].includes(row.presentation)) fail(`${path}.presentation`, 'must be stacked or table');
523
+ if (row.descriptionActionKey !== undefined) assertKey(row.descriptionActionKey, `${path}.descriptionActionKey`);
524
+ if ((row.amounts?.length ?? 0) > 32) fail(`${path}.amounts`, 'supports at most 32 amount lines');
525
+ const amountKeys = new Set();
526
+ row.amounts?.forEach((amount, index) => {
527
+ const amountPath = `${path}.amounts[${index}]`;
528
+ assertKey(amount.key, `${amountPath}.key`);
529
+ if (amountKeys.has(amount.key)) fail(amountPath, 'duplicate amount key');
530
+ amountKeys.add(amount.key);
531
+ assertText(amount.text, `${amountPath}.text`);
532
+ assertLeadingVisual(amount.leading, `${amountPath}.leading`);
533
+ assertText(amount.secondaryText, `${amountPath}.secondaryText`);
534
+ if (amount.tone !== undefined && !['primary', 'secondary', 'positive', 'negative'].includes(amount.tone)) fail(`${amountPath}.tone`, 'invalid text tone');
535
+ amount.textSegments?.forEach((segment, segmentIndex) => {
536
+ assertText(segment.text, `${amountPath}.textSegments[${segmentIndex}].text`);
537
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(amountPath, 'invalid text segment style');
538
+ });
539
+ });
540
+ const assertActivitySegments = (segments, segmentPath) => segments?.forEach((segment, index) => {
541
+ assertText(segment.text, `${segmentPath}[${index}].text`);
542
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(segmentPath, 'invalid text segment style');
543
+ });
544
+ row.amounts?.forEach((amount, index) => assertActivitySegments(amount.secondaryTextSegments, `${path}.amounts[${index}].secondaryTextSegments`));
545
+ assertActivitySegments(row.fee?.primaryTextSegments, `${path}.fee.primaryTextSegments`);
546
+ assertActivitySegments(row.fee?.secondaryTextSegments, `${path}.fee.secondaryTextSegments`);
547
+ assertText(row.fee?.label, `${path}.fee.label`);
548
+ assertText(row.fee?.primary, `${path}.fee.primary`);
549
+ assertText(row.fee?.secondary, `${path}.fee.secondary`);
550
+ if ((row.badges?.length ?? 0) > 4) fail(`${path}.badges`, 'supports at most 4 activity badges');
551
+ const badgeKeys = new Set();
552
+ row.badges?.forEach((badge, index) => {
553
+ assertKey(badge.key, `${path}.badges[${index}].key`);
554
+ if (badgeKeys.has(badge.key)) fail(`${path}.badges`, 'duplicate badge key');
555
+ badgeKeys.add(badge.key);
556
+ assertText(badge.text, `${path}.badges[${index}].text`);
557
+ if (badge.tone !== undefined && !['neutral', 'info', 'success', 'warning', 'danger'].includes(badge.tone)) fail(`${path}.badges`, 'invalid badge tone');
558
+ });
559
+ if (row.fee?.hidden !== undefined && typeof row.fee.hidden !== 'boolean') fail(`${path}.fee.hidden`, 'must be boolean');
281
560
  if ((row.footerActions?.length ?? 0) > MAX_FOOTER_ACTIONS) {
282
561
  fail(`${path}.footerActions`, `supports at most ${MAX_FOOTER_ACTIONS} actions`);
283
562
  }
@@ -309,11 +588,17 @@ function assertWalletGroup(row, path) {
309
588
  keys.add(member.key);
310
589
  });
311
590
  }
591
+ function assertRowType(type, path) {
592
+ if (typeof type !== 'string' || !Object.prototype.hasOwnProperty.call(ROW_BOX_STYLE_KEYS_BY_TYPE, type)) {
593
+ fail(`${path}.type`, 'is not supported');
594
+ }
595
+ }
312
596
  function assertRow(row, index, path = `rows[${index}]`) {
597
+ assertRowType(row.type, path);
313
598
  assertKey(row.key, `${path}.key`);
314
599
  // OneKey patch: explicit dimensions and opacity cannot corrupt list layout.
315
600
  if (row.height !== undefined && (row.height < 0 || row.height > 4096)) fail(`${path}.height`, 'must be within 0...4096');
316
- if (row.heightRounding !== undefined && (row.height === undefined || !['floor', 'nearest'].includes(row.heightRounding))) fail(`${path}.heightRounding`, 'requires an explicit height and must be floor or nearest');
601
+ if (row.heightRounding !== undefined && (row.height === undefined && row.style?.container?.height === undefined || !['floor', 'nearest'].includes(row.heightRounding))) fail(`${path}.heightRounding`, 'requires an explicit height and must be floor or nearest');
317
602
  if (row.opacity !== undefined && (row.opacity < 0 || row.opacity > 1)) fail(`${path}.opacity`, 'must be within 0...1');
318
603
  if (row.groupId && !row.groupPosition) {
319
604
  fail(`${path}.groupPosition`, 'is required when groupId is present');
@@ -321,6 +606,7 @@ function assertRow(row, index, path = `rows[${index}]`) {
321
606
  if (!row.groupId && row.groupPosition) {
322
607
  fail(`${path}.groupId`, 'is required when groupPosition is present');
323
608
  }
609
+ assertRowStyle(row, path);
324
610
  assertVisual(row, path);
325
611
  switch (row.type) {
326
612
  case 'walletGroup':
@@ -364,8 +650,8 @@ function assertRow(row, index, path = `rows[${index}]`) {
364
650
  case 'message':
365
651
  assertText(row.title, `${path}.title`);
366
652
  assertText(row.body, `${path}.body`);
367
- if ((row.bodyLines ?? 3) < 1 || (row.bodyLines ?? 3) > 3) {
368
- fail(`${path}.bodyLines`, 'must be within 1...3');
653
+ if (![1, 2, 3].includes(row.bodyLines ?? 3)) {
654
+ fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
369
655
  }
370
656
  assertImage(row.thumbnail, `${path}.thumbnail`);
371
657
  break;
@@ -388,12 +674,13 @@ function assertRow(row, index, path = `rows[${index}]`) {
388
674
  assertMarketRow(row, path);
389
675
  break;
390
676
  case 'mediaTile':
677
+ assertMediaPreview(row.media, `${path}.media`);
391
678
  assertImage(row.image, `${path}.image`);
392
679
  if (row.imageState !== undefined && !['empty', 'error'].includes(row.imageState)) {
393
680
  fail(`${path}.imageState`, 'must be empty or error when provided');
394
681
  }
395
- if (row.imageState === undefined && row.image === undefined) {
396
- fail(`${path}.image`, 'is required unless imageState is empty or error');
682
+ if (row.imageState === undefined && row.image === undefined && row.media === undefined) {
683
+ fail(`${path}.image`, 'is required unless media is provided or imageState is empty or error');
397
684
  }
398
685
  assertImage(row.networkImage, `${path}.networkImage`);
399
686
  assertText(row.title, `${path}.title`);
@@ -422,6 +709,7 @@ function assertRow(row, index, path = `rows[${index}]`) {
422
709
  }
423
710
  break;
424
711
  case 'sectionHeader':
712
+ if (row.titleLoading !== undefined && typeof row.titleLoading !== 'boolean') fail(`${path}.titleLoading`, 'must be boolean');
425
713
  assertKey(row.sectionKey, `${path}.sectionKey`);
426
714
  if (row.presentation !== undefined && row.presentation !== 'networkSelector') {
427
715
  fail(`${path}.presentation`, 'must be networkSelector when provided');
@@ -500,12 +788,27 @@ function assertGroups(rows) {
500
788
  }
501
789
  }
502
790
  }
791
+ function assertMediaPreview(value, path) {
792
+ if (value === undefined) return;
793
+ if (!value || typeof value !== 'object' || Array.isArray(value)) fail(path, 'must be a media descriptor');
794
+ const media = value;
795
+ assertImage(media.source, `${path}.source`);
796
+ if (!media.source) fail(`${path}.source`, 'is required');
797
+ const order = media.probeOrder;
798
+ if (!Array.isArray(order) || order.length < 1 || order.length > 2 || order.some(kind => kind !== 'image' && kind !== 'video') || new Set(order).size !== order.length) {
799
+ fail(`${path}.probeOrder`, 'must contain one or two distinct image/video candidates');
800
+ }
801
+ }
503
802
  export function validateSnapshot(snapshot) {
803
+ if (snapshot.capabilities?.refreshTriggerDistance !== undefined && (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) || snapshot.capabilities.refreshTriggerDistance <= 0)) fail('capabilities.refreshTriggerDistance', 'must be a positive finite number');
504
804
  assertPlainSerializable(snapshot, 'snapshot', new Set());
505
805
  if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
506
806
  if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
507
807
  fail('snapshot.generation', 'must be a non-negative safe integer');
508
808
  }
809
+ if (snapshot.layout.gridColumns !== undefined && (!Number.isInteger(snapshot.layout.gridColumns) || snapshot.layout.gridColumns < 2 || snapshot.layout.gridColumns > 7)) {
810
+ fail('snapshot.layout.gridColumns', 'must be an integer from 2 to 7');
811
+ }
509
812
  if (snapshot.layout.kind === 'grid' && !snapshot.layout.gridColumns) {
510
813
  fail('snapshot.layout.gridColumns', 'is required for grid layout');
511
814
  }
@@ -532,6 +835,7 @@ export function validateSnapshot(snapshot) {
532
835
  fail('snapshot.capabilities.sectionIndex', 'requires a vertical sectioned layout');
533
836
  }
534
837
  }
838
+ assertListStyle(snapshot.listStyle, 'snapshot.listStyle');
535
839
  const rowKeys = new Set();
536
840
  const sectionIndexTitles = new Set();
537
841
  snapshot.rows.forEach((row, index) => {
@@ -566,10 +870,41 @@ export function validateSnapshot(snapshot) {
566
870
  if (snapshot.selection?.mode === 'single' && selectedKeys.size > 1) {
567
871
  fail('snapshot.selection.selectedKeys', 'supports at most one key in single mode');
568
872
  }
569
- return snapshot;
873
+ return normalizeSnapshotStyles(snapshot);
874
+ }
875
+
876
+ /**
877
+ * Resolves typography tokens to numbers. Returns the original snapshot when
878
+ * nothing needs resolving, so the common no-style path keeps object identity.
879
+ */
880
+ function normalizeSnapshotStyles(snapshot) {
881
+ let changed = false;
882
+ const rows = snapshot.rows.map(row => {
883
+ const next = normalizeRowStyles(row);
884
+ if (next !== row) changed = true;
885
+ return next;
886
+ });
887
+ const emptyState = snapshot.emptyState ? normalizeRowStyles(snapshot.emptyState) : snapshot.emptyState;
888
+ const fixedFooter = snapshot.fixedFooter ? normalizeRowStyles(snapshot.fixedFooter) : snapshot.fixedFooter;
889
+ if (!changed && emptyState === snapshot.emptyState && fixedFooter === snapshot.fixedFooter) {
890
+ return snapshot;
891
+ }
892
+ return {
893
+ ...snapshot,
894
+ rows,
895
+ emptyState,
896
+ fixedFooter
897
+ };
570
898
  }
571
899
  function assertPatchChanges(patch, index) {
572
900
  const path = `patches[${index}].changes`;
901
+ const patchedStyle = patch.changes.style;
902
+ if (patchedStyle !== undefined) {
903
+ assertRowStyle({
904
+ type: patch.type,
905
+ style: patchedStyle
906
+ }, path);
907
+ }
573
908
  // OneKey patch: partial balance updates retain a valid, current accessibility label.
574
909
  if ('accessibilityLabel' in patch.changes) {
575
910
  assertText(patch.changes.accessibilityLabel, `${path}.accessibilityLabel`);
@@ -602,6 +937,7 @@ function assertPatchChanges(patch, index) {
602
937
  assertLeadingVisual(patch.changes.visual, `${path}.visual`);
603
938
  break;
604
939
  case 'activity':
940
+ assertActivity(patch.changes, path);
605
941
  assertText(patch.changes.title, `${path}.title`);
606
942
  assertText(patch.changes.description, `${path}.description`);
607
943
  assertText(patch.changes.status, `${path}.status`);
@@ -617,8 +953,8 @@ function assertPatchChanges(patch, index) {
617
953
  assertText(patch.changes.title, `${path}.title`);
618
954
  assertText(patch.changes.body, `${path}.body`);
619
955
  assertText(patch.changes.time, `${path}.time`);
620
- if (patch.changes.bodyLines !== undefined && (patch.changes.bodyLines < 1 || patch.changes.bodyLines > 3)) {
621
- fail(`${path}.bodyLines`, 'must be within 1...3');
956
+ if (patch.changes.bodyLines !== undefined && ![1, 2, 3].includes(patch.changes.bodyLines)) {
957
+ fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
622
958
  }
623
959
  assertImage(patch.changes.thumbnail, `${path}.thumbnail`);
624
960
  break;
@@ -655,6 +991,7 @@ function assertPatchChanges(patch, index) {
655
991
  }, path);
656
992
  break;
657
993
  case 'mediaTile':
994
+ assertMediaPreview(patch.changes.media, `${path}.media`);
658
995
  assertImage(patch.changes.image, `${path}.image`);
659
996
  if (patch.changes.imageState !== undefined && !['empty', 'error'].includes(patch.changes.imageState)) {
660
997
  fail(`${path}.imageState`, 'must be empty or error when provided');
@@ -687,6 +1024,7 @@ function assertPatchChanges(patch, index) {
687
1024
  }
688
1025
  break;
689
1026
  case 'sectionHeader':
1027
+ if (patch.changes.titleLoading !== undefined && typeof patch.changes.titleLoading !== 'boolean') fail(`${path}.titleLoading`, 'must be boolean');
690
1028
  assertSectionHeaderVariant(patch.changes.variant, `${path}.variant`);
691
1029
  assertText(patch.changes.title, `${path}.title`);
692
1030
  assertText(patch.changes.subtitle, `${path}.subtitle`);
@@ -723,7 +1061,27 @@ export function validatePatches(patches) {
723
1061
  }
724
1062
  assertPatchChanges(patch, index);
725
1063
  });
726
- return patches;
1064
+ return normalizePatchStyles(patches);
1065
+ }
1066
+
1067
+ /** Patches reach the native side without passing through a snapshot. */
1068
+ function normalizePatchStyles(patches) {
1069
+ let changed = false;
1070
+ const next = patches.map(patch => {
1071
+ const style = patch.changes.style;
1072
+ if (!style) return patch;
1073
+ const resolved = resolveStyleTokens(style, patch.type);
1074
+ if (resolved === style) return patch;
1075
+ changed = true;
1076
+ return {
1077
+ ...patch,
1078
+ changes: {
1079
+ ...patch.changes,
1080
+ style: resolved
1081
+ }
1082
+ };
1083
+ });
1084
+ return changed ? next : patches;
727
1085
  }
728
1086
  export function applyRowPatches(snapshot, patches) {
729
1087
  validatePatches(patches);