@onekeyfe/react-native-native-list 6.7.0-2 → 6.7.0-20

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 (144) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +29 -3
  5. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  6. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +87 -7
  8. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +193 -10
  9. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
  10. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +145 -2
  12. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
  16. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
  18. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1920 -109
  19. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +29 -0
  20. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  21. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  22. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  23. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  24. package/docs/ROW_TEMPLATES.md +60 -9
  25. package/docs/SPEC.md +1004 -17
  26. package/docs/STYLE_SPEC.md +6 -0
  27. package/ios/HybridNativeList.swift +21 -2
  28. package/ios/NativeListAccessoryStack.swift +235 -39
  29. package/ios/NativeListActivityDetailsView.swift +18 -8
  30. package/ios/NativeListActivityRenderer.swift +8 -2
  31. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  32. package/ios/NativeListDataRowRenderer.swift +155 -27
  33. package/ios/NativeListDesignAssets.swift +9 -0
  34. package/ios/NativeListIdentityRenderer.swift +191 -30
  35. package/ios/NativeListLeadingVisual.swift +119 -22
  36. package/ios/NativeListMessageRenderer.swift +34 -1
  37. package/ios/NativeListModels.swift +42 -2
  38. package/ios/NativeListRendererRegistry.swift +1 -0
  39. package/ios/NativeListResolvedText.swift +2 -1
  40. package/ios/NativeListRowHost.swift +14 -0
  41. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  42. package/ios/RNCNativeListView.swift +1031 -55
  43. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  44. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  45. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
  46. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
  47. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
  48. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
  49. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  50. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  51. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
  52. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
  53. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  54. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  55. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
  56. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
  57. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
  58. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
  59. package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
  60. package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
  61. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  62. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  63. package/ios/tests/NativeListLifecycleTests.swift +2720 -3
  64. package/lib/module/NativeList.js +200 -32
  65. package/lib/module/NativeList.web.js +262 -32
  66. package/lib/module/index.js +1 -1
  67. package/lib/module/models.js +1 -0
  68. package/lib/module/selection.js +1 -1
  69. package/lib/module/validation.js +776 -52
  70. package/lib/module/web/NativeListWebEngine.js +919 -79
  71. package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
  72. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  73. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  74. package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
  75. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  76. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  77. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  78. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  79. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  80. package/lib/module/web/templates/RowRendererRegistry.js +8 -3
  81. package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
  82. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  83. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  84. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  85. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  86. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  87. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  88. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  89. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  90. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  91. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  92. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  93. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  94. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  95. package/lib/typescript/src/NativeList.d.ts +3 -3
  96. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  97. package/lib/typescript/src/NativeList.types.d.ts +29 -1
  98. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  99. package/lib/typescript/src/index.d.ts +2 -2
  100. package/lib/typescript/src/models.d.ts +176 -10
  101. package/lib/typescript/src/validation.d.ts +15 -0
  102. package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
  103. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  104. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  105. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  106. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  107. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  108. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
  109. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  110. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  111. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  112. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  114. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  115. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  116. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  117. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  118. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  119. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  120. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  121. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  122. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  123. package/package.json +3 -3
  124. package/react-native-native-list.podspec +1 -0
  125. package/src/NativeList.nitro.ts +2 -0
  126. package/src/NativeList.tsx +391 -82
  127. package/src/NativeList.types.ts +34 -1
  128. package/src/NativeList.web.tsx +420 -65
  129. package/src/index.ts +2 -0
  130. package/src/models.ts +210 -3
  131. package/src/selection.ts +1 -0
  132. package/src/validation.ts +1635 -76
  133. package/src/web/NativeListWebEngine.ts +1476 -112
  134. package/src/web/templates/ActivityRowRenderer.ts +732 -8
  135. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  136. package/src/web/templates/DataRowRenderer.ts +93 -20
  137. package/src/web/templates/IdentityRowRenderer.ts +150 -5
  138. package/src/web/templates/MarketRowRenderer.ts +19 -3
  139. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  140. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  141. package/src/web/templates/MessageRowRenderer.ts +23 -7
  142. package/src/web/templates/RowContainerStyle.ts +2 -0
  143. package/src/web/templates/RowRendererRegistry.ts +21 -6
  144. package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
@@ -12,8 +12,40 @@ const MAX_HEADER_LENGTH = 4096;
12
12
  const MAX_SPACER_HEIGHT = 512;
13
13
  const MAX_SECTION_INDEX_TITLE_LENGTH = 8;
14
14
  const MAX_MARKET_BADGES = 3;
15
+ function isDevelopment() {
16
+ return typeof __DEV__ !== 'undefined' && __DEV__;
17
+ }
18
+ class NativeListInputError extends Error {
19
+ constructor(path, reason) {
20
+ super(`NativeList ${path}: ${reason}`);
21
+ this.path = path;
22
+ this.reason = reason;
23
+ }
24
+ }
15
25
  function fail(path, message) {
16
- throw new Error(`NativeList ${path}: ${message}`);
26
+ throw new NativeListInputError(path, message);
27
+ }
28
+
29
+ /** Component boundaries report locations, never caller-controlled payload values. */
30
+ export function containNativeListInput(operation) {
31
+ try {
32
+ return operation();
33
+ } catch (error) {
34
+ const path = error instanceof NativeListInputError ? error.path : 'input';
35
+ const reason = isDevelopment() && error instanceof NativeListInputError ? `: ${error.reason.split('"')[0].trim()}` : '';
36
+ console.warn(`NativeList rejected invalid input at ${path}${reason}`);
37
+ return undefined;
38
+ }
39
+ }
40
+ export function emptyNativeListSnapshot() {
41
+ return {
42
+ schemaVersion: 1,
43
+ generation: 0,
44
+ layout: {
45
+ kind: 'linear'
46
+ },
47
+ rows: []
48
+ };
17
49
  }
18
50
  function assertPlainSerializable(value, path, seen) {
19
51
  if (value === null || value === undefined) return;
@@ -39,10 +71,9 @@ function assertPlainSerializable(value, path, seen) {
39
71
  seen.delete(objectValue);
40
72
  }
41
73
  function assertKey(key, path) {
42
- if (typeof key !== 'string' || key.length === 0 || key.length > MAX_KEY_LENGTH) {
43
- fail(path, `must be a non-empty string no longer than ${MAX_KEY_LENGTH} characters`);
74
+ if (typeof key !== 'string' || key.trim().length === 0 || key.length > MAX_KEY_LENGTH) {
75
+ fail(path, `must be a non-blank string no longer than ${MAX_KEY_LENGTH} characters`);
44
76
  }
45
- if (key.trim() !== key) fail(path, 'must not have leading or trailing whitespace');
46
77
  }
47
78
  function assertText(text, path) {
48
79
  if (text === undefined) return;
@@ -136,10 +167,13 @@ const TEXT_STYLE_KEYS_BY_ROW_TYPE = {
136
167
  metricCard: ['title', 'value', 'subtitle', 'trend'],
137
168
  sectionHeader: ['title', 'subtitle', 'value'],
138
169
  action: ['title', 'value'],
170
+ buttonGroup: [],
139
171
  system: ['title', 'message', 'actionText']
140
172
  };
141
173
  const EXTRA_STYLE_KEYS_BY_ROW_TYPE = {
142
- market: ['titleBadgeLayout', 'contentTrailingGap', 'subtitleTrailingPadding', 'changeWidth', 'changeHeight', 'changeCornerRadius']
174
+ identity: ['leadingContentMaxWidthRatio'],
175
+ market: ['titleBadgeLayout', 'contentTrailingGap', 'subtitleTrailingPadding', 'changeWidth', 'changeHeight', 'changeCornerRadius'],
176
+ sectionHeader: ['valuePlacement', 'titleDecoration']
143
177
  };
144
178
  function assertTextStyle(style, path, additionalKeys = []) {
145
179
  if (style === undefined) return;
@@ -252,6 +286,15 @@ function assertRowStyle(row, path) {
252
286
  // Market keeps its own richer assertions, driven from assertMarketRow.
253
287
  if (row.type === 'market') return;
254
288
  assertBoxStyle(style, `${path}.style`);
289
+ if (row.type === 'identity') {
290
+ const ratio = style?.leadingContentMaxWidthRatio;
291
+ if (ratio !== undefined && (!Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) fail(`${path}.style.leadingContentMaxWidthRatio`, 'must be within (0, 1]');
292
+ }
293
+ if (row.type === 'sectionHeader') {
294
+ const sectionStyle = style;
295
+ if (sectionStyle?.valuePlacement !== undefined && sectionStyle.valuePlacement !== 'afterTitle') fail(`${path}.style.valuePlacement`, 'must be afterTitle');
296
+ if (sectionStyle?.titleDecoration !== undefined && !['none', 'dashed'].includes(sectionStyle.titleDecoration)) fail(`${path}.style.titleDecoration`, 'must be none or dashed');
297
+ }
255
298
  const slots = style;
256
299
  textKeys.forEach(key => assertTextStyle(slots[key], `${path}.style.${key}`));
257
300
  }
@@ -347,7 +390,139 @@ function normalizeRowStyles(row) {
347
390
  }
348
391
  return next;
349
392
  }
393
+ function assertMarketBadges(badges, path) {
394
+ if ((badges?.length ?? 0) > MAX_MARKET_BADGES) {
395
+ fail(`${path}.badges`, `supports at most ${MAX_MARKET_BADGES} badges`);
396
+ }
397
+ const badgeKeys = new Set();
398
+ badges?.forEach((badge, index) => {
399
+ const badgePath = `${path}.badges[${index}]`;
400
+ assertKey(badge.key, `${badgePath}.key`);
401
+ if (badgeKeys.has(badge.key)) {
402
+ fail(`${path}.badges`, `duplicate badge key "${badge.key}"`);
403
+ }
404
+ badgeKeys.add(badge.key);
405
+ assertText(badge.text, `${badgePath}.text`);
406
+ // OneKey patch: share typography bounds with Market text styles.
407
+ assertTextStyle(badge.style, `${badgePath}.style`, ['height', 'horizontalPadding']);
408
+ if (badge.style) assertUnknownKeys(badge.style, ['fontSize', 'fontWeight', 'lineHeight', 'height', 'horizontalPadding'], `${badgePath}.style`, 'Market badge style key');
409
+ assertBoundedStyleNumber(badge.style?.height, `${badgePath}.style.height`, 1, 64);
410
+ assertBoundedStyleNumber(badge.style?.horizontalPadding, `${badgePath}.style.horizontalPadding`, 0, 32);
411
+ if (badge.iconName !== undefined && badge.iconName !== 'verified') {
412
+ fail(`${badgePath}.iconName`, 'must be verified when provided');
413
+ }
414
+ if (badge.iconName !== undefined && badge.icon !== undefined) {
415
+ fail(`${badgePath}.icon`, 'cannot be combined with iconName');
416
+ }
417
+ assertImage(badge.icon, `${badgePath}.icon`);
418
+ if (badge.tone !== undefined && !['neutral', 'info', 'success', 'warning', 'danger'].includes(badge.tone)) {
419
+ fail(`${badgePath}.tone`, 'must be neutral, info, success, warning, or danger');
420
+ }
421
+ if (!badge.text && !badge.icon && !badge.iconName) {
422
+ fail(badgePath, 'requires text, icon, or iconName');
423
+ }
424
+ if (badge.actionKey !== undefined) {
425
+ assertKey(badge.actionKey, `${badgePath}.actionKey`);
426
+ }
427
+ });
428
+ }
429
+ function assertWebMarketTable(table, path) {
430
+ if (!table) return;
431
+ assertUnknownKeys(table, ['columns', 'cells', 'testID', 'draggable', 'contextMenuActionKey'], path, 'Web table key');
432
+ if (table.draggable !== undefined && typeof table.draggable !== 'boolean') fail(`${path}.draggable`, 'must be boolean');
433
+ if (table.contextMenuActionKey !== undefined) assertKey(table.contextMenuActionKey, `${path}.contextMenuActionKey`);
434
+ assertText(table.testID, `${path}.testID`);
435
+ if (!Array.isArray(table.columns) || table.columns.length < 1 || table.columns.length > 12) fail(`${path}.columns`, 'must contain 1...12 columns');
436
+ if (!Array.isArray(table.cells) || table.cells.length !== table.columns.length) fail(`${path}.cells`, 'must match the column count');
437
+ const keys = new Set();
438
+ table.columns.forEach((column, index) => {
439
+ const field = `${path}.columns[${index}]`;
440
+ assertUnknownKeys(column, ['key', 'width', 'minWidth', 'flex', 'alignment', 'paddingStart', 'paddingEnd'], field, 'Web column key');
441
+ assertKey(column.key, `${field}.key`);
442
+ if (keys.has(column.key)) fail(field, 'column keys must be unique');
443
+ keys.add(column.key);
444
+ assertBoundedStyleNumber(column.width, `${field}.width`, 0, 4096);
445
+ assertBoundedStyleNumber(column.minWidth, `${field}.minWidth`, 0, 4096);
446
+ assertBoundedStyleNumber(column.flex, `${field}.flex`, 0, 16);
447
+ assertBoundedStyleNumber(column.paddingStart, `${field}.paddingStart`, 0, 64);
448
+ assertBoundedStyleNumber(column.paddingEnd, `${field}.paddingEnd`, 0, 64);
449
+ if (column.alignment !== undefined && !['start', 'center', 'end'].includes(column.alignment)) fail(`${field}.alignment`, 'must be start, center, or end');
450
+ });
451
+ const text = (value, field) => {
452
+ assertUnknownKeys(value, ['text', 'segments', 'tone', 'style'], field, 'Web text key');
453
+ assertText(value.text, `${field}.text`);
454
+ assertTextTone(value.tone, `${field}.tone`);
455
+ assertTextStyle(value.style, `${field}.style`);
456
+ if (value.style) assertUnknownKeys(value.style, ['fontSize', 'fontWeight', 'lineHeight', 'color'], `${field}.style`, 'Web table text style');
457
+ if ((value.segments?.length ?? 0) > 64) fail(`${field}.segments`, 'supports at most 64 segments');
458
+ value.segments?.forEach((segment, index) => {
459
+ assertUnknownKeys(segment, ['text', 'style'], `${field}.segments[${index}]`, 'Web text segment');
460
+ assertText(segment.text, `${field}.segments[${index}].text`);
461
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(field, 'segment style must be subscript');
462
+ });
463
+ };
464
+ const line = (parts, field) => {
465
+ if (!parts) return;
466
+ if (!Array.isArray(parts) || parts.length > 8) fail(field, 'supports at most 8 text parts');
467
+ parts.forEach((value, index) => text(value, `${field}[${index}]`));
468
+ };
469
+ table.cells.forEach((cell, index) => {
470
+ const field = `${path}.cells[${index}]`;
471
+ assertKey(cell.key, `${field}.key`);
472
+ if (cell.key !== table.columns[index].key) fail(field, 'cell key/order must match its column');
473
+ switch (cell.kind) {
474
+ case 'favorite':
475
+ assertUnknownKeys(cell, ['key', 'kind', 'active', 'disabled', 'testID', 'hoverActionKey', 'actionKey', 'accessibilityLabel'], field, 'Web favorite key');
476
+ if (typeof cell.active !== 'boolean') fail(field, 'active must be boolean');
477
+ if (cell.disabled !== undefined && typeof cell.disabled !== 'boolean') fail(field, 'disabled must be boolean');
478
+ if (cell.hoverActionKey !== undefined) assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
479
+ assertText(cell.testID, `${field}.testID`);
480
+ assertKey(cell.actionKey, `${field}.actionKey`);
481
+ assertText(cell.accessibilityLabel, `${field}.accessibilityLabel`);
482
+ break;
483
+ case 'asset':
484
+ assertUnknownKeys(cell, ['key', 'kind', 'leading', 'title', 'secondary', 'hoverSecondary', 'hoverActionKey', 'hoverActionLabel', 'badges', 'lineGap', 'secondaryBadges', 'hoverImages'], field, 'Web asset key');
485
+ assertBoundedStyleNumber(cell.lineGap, `${field}.lineGap`, 0, 8);
486
+ assertMarketBadges(cell.secondaryBadges, `${field}.secondary`);
487
+ cell.secondaryBadges?.forEach((badge, i) => {
488
+ assertUnknownKeys(badge, ['key', 'text', 'style'], `${field}.secondaryBadges[${i}]`, 'Web secondary badge key');
489
+ if (!badge.text) fail(field, 'secondary badges require text');
490
+ });
491
+ if (cell.hoverImages !== undefined && (!Array.isArray(cell.hoverImages) || cell.hoverImages.length > 4)) fail(field, 'supports at most 4 hover images');
492
+ cell.hoverImages?.forEach((image, i) => {
493
+ if (image !== null) assertImage(image, `${field}.hoverImages[${i}]`);
494
+ });
495
+ assertLeadingVisual(cell.leading, `${field}.leading`);
496
+ text(cell.title, `${field}.title`);
497
+ line(cell.secondary, `${field}.secondary`);
498
+ line(cell.hoverSecondary, `${field}.hoverSecondary`);
499
+ assertText(cell.hoverActionLabel, `${field}.hoverActionLabel`);
500
+ if (cell.hoverActionKey !== undefined) assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
501
+ assertMarketBadges(cell.badges, field);
502
+ cell.badges?.forEach((badge, i) => assertUnknownKeys(badge, ['key', 'text', 'iconName', 'icon', 'textColor', 'backgroundColor', 'actionKey', 'accessibilityLabel', 'style'], `${field}.badges[${i}]`, 'Web title badge key'));
503
+ break;
504
+ case 'text':
505
+ assertUnknownKeys(cell, ['key', 'kind', 'primary', 'secondary', 'partGap'], field, 'Web text cell key');
506
+ assertBoundedStyleNumber(cell.partGap, `${field}.partGap`, 0, 8);
507
+ if (!Array.isArray(cell.primary) || !cell.primary.length) fail(field, 'requires primary text');
508
+ line(cell.primary, `${field}.primary`);
509
+ line(cell.secondary, `${field}.secondary`);
510
+ break;
511
+ case 'sparkline':
512
+ assertUnknownKeys(cell, ['key', 'kind', 'points', 'width', 'height', 'strokeColor', 'fillColor'], field, 'Web sparkline key');
513
+ if (!Array.isArray(cell.points) || cell.points.length > 256 || cell.points.some(value => !Number.isFinite(value))) fail(field, 'supports at most 256 finite samples');
514
+ if (typeof cell.width !== 'number' || typeof cell.height !== 'number') fail(field, 'sparkline dimensions are required');
515
+ assertBoundedStyleNumber(cell.width, `${field}.width`, 1, 512);
516
+ assertBoundedStyleNumber(cell.height, `${field}.height`, 1, 512);
517
+ for (const color of [cell.strokeColor, cell.fillColor]) if (typeof color !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color)) fail(field, 'colors must be #RRGGBB or #RRGGBBAA');
518
+ break;
519
+ default:
520
+ fail(field, 'unsupported Web table cell kind');
521
+ }
522
+ });
523
+ }
350
524
  function assertMarketRow(row, path) {
525
+ assertWebMarketTable(row.webTable, `${path}.webTable`);
351
526
  if (!['token', 'stock', 'perp'].includes(row.variant)) {
352
527
  fail(`${path}.variant`, 'must be token, stock, or perp');
353
528
  }
@@ -356,6 +531,7 @@ function assertMarketRow(row, path) {
356
531
  // OneKey patch: validate the independently laid out Market name.
357
532
  if (row.subtitlePrefix) {
358
533
  assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
534
+ assertText(row.subtitlePrefix.hoverActionKey, `${path}.subtitlePrefix.hoverActionKey`);
359
535
  assertBoundedStyleNumber(row.subtitlePrefix.gap, `${path}.subtitlePrefix.gap`, 0, 64);
360
536
  assertBoundedStyleNumber(row.subtitlePrefix.maxWidth, `${path}.subtitlePrefix.maxWidth`, 1, 320);
361
537
  assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
@@ -384,40 +560,7 @@ function assertMarketRow(row, path) {
384
560
  if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
385
561
  fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
386
562
  }
387
- if ((row.badges?.length ?? 0) > MAX_MARKET_BADGES) {
388
- fail(`${path}.badges`, `supports at most ${MAX_MARKET_BADGES} badges`);
389
- }
390
- const badgeKeys = new Set();
391
- row.badges?.forEach((badge, index) => {
392
- const badgePath = `${path}.badges[${index}]`;
393
- assertKey(badge.key, `${badgePath}.key`);
394
- if (badgeKeys.has(badge.key)) {
395
- fail(`${path}.badges`, `duplicate badge key "${badge.key}"`);
396
- }
397
- badgeKeys.add(badge.key);
398
- assertText(badge.text, `${badgePath}.text`);
399
- // OneKey patch: share typography bounds with Market text styles.
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');
402
- assertBoundedStyleNumber(badge.style?.height, `${badgePath}.style.height`, 1, 64);
403
- assertBoundedStyleNumber(badge.style?.horizontalPadding, `${badgePath}.style.horizontalPadding`, 0, 32);
404
- if (badge.iconName !== undefined && badge.iconName !== 'verified') {
405
- fail(`${badgePath}.iconName`, 'must be verified when provided');
406
- }
407
- if (badge.iconName !== undefined && badge.icon !== undefined) {
408
- fail(`${badgePath}.icon`, 'cannot be combined with iconName');
409
- }
410
- assertImage(badge.icon, `${badgePath}.icon`);
411
- if (badge.tone !== undefined && !['neutral', 'info', 'success', 'warning', 'danger'].includes(badge.tone)) {
412
- fail(`${badgePath}.tone`, 'must be neutral, info, success, warning, or danger');
413
- }
414
- if (!badge.text && !badge.icon && !badge.iconName) {
415
- fail(badgePath, 'requires text, icon, or iconName');
416
- }
417
- if (badge.actionKey !== undefined) {
418
- assertKey(badge.actionKey, `${badgePath}.actionKey`);
419
- }
420
- });
563
+ assertMarketBadges(row.badges, path);
421
564
  for (const [key, value] of [['pressActionKey', row.pressActionKey], ['pressInActionKey', row.pressInActionKey], ['longPressActionKey', row.longPressActionKey], ['diagnostics.imageBindActionKey', row.diagnostics?.imageBindActionKey]]) {
422
565
  if (value !== undefined) assertKey(value, `${path}.${key}`);
423
566
  }
@@ -441,18 +584,98 @@ function assertVisualShape(shape, path) {
441
584
  function assertTrailingAccessories(accessories, path) {
442
585
  accessories?.forEach((accessory, index) => {
443
586
  const accessoryPath = `${path}[${index}]`;
587
+ if (accessory.kind === 'button') {
588
+ assertUnknownKeys(accessory, ['kind', 'label', 'actionKey', 'disabled', 'testID', 'accessibilityLabel', 'textColor', 'backgroundColor', 'pressedBackgroundColor', 'hoverBackgroundColor', 'focusRingColor'], accessoryPath, 'button key');
589
+ if (typeof accessory.label !== 'string' || !accessory.label.trim()) fail(`${accessoryPath}.label`, 'must be non-blank');
590
+ assertKey(accessory.actionKey, `${accessoryPath}.actionKey`);
591
+ if (accessory.disabled !== undefined && typeof accessory.disabled !== 'boolean') fail(`${accessoryPath}.disabled`, 'must be boolean');
592
+ for (const field of ['textColor', 'backgroundColor', 'pressedBackgroundColor', 'hoverBackgroundColor', 'focusRingColor']) {
593
+ const value = accessory[field];
594
+ if (value !== undefined && (typeof value !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value))) fail(`${accessoryPath}.${field}`, 'must be #RRGGBB or #RRGGBBAA');
595
+ }
596
+ }
597
+ if (accessory.kind === 'icon' && accessory.buttonStyle !== undefined && accessory.buttonStyle !== 'tertiary') fail(`${accessoryPath}.buttonStyle`, 'must be tertiary');
444
598
  if (accessory.kind === 'progress' && (accessory.value < 0 || accessory.value > 1)) {
445
599
  fail(`${accessoryPath}.value`, 'must be within 0...1');
446
600
  }
447
601
  if (accessory.kind === 'valuePair') {
602
+ if (accessory.primaryFontWeight !== undefined && accessory.primaryFontWeight !== 'medium') fail(`${accessoryPath}.primaryFontWeight`, 'must be medium when provided');
603
+ assertTextHelp(accessory.primaryHelp, `${accessoryPath}.primaryHelp`);
448
604
  assertTextTone(accessory.primaryTone, `${accessoryPath}.primaryTone`);
449
605
  assertTextTone(accessory.secondaryTone, `${accessoryPath}.secondaryTone`);
606
+ for (const field of ['primaryTextSegments', 'secondaryTextSegments']) {
607
+ const segments = accessory[field];
608
+ if (segments === undefined) continue;
609
+ const segmentPath = `${accessoryPath}.${field}`;
610
+ if (!Array.isArray(segments) || segments.length > 64) fail(segmentPath, 'must be an array of at most 64 segments');
611
+ let textLength = 0;
612
+ segments.forEach((segment, segmentIndex) => {
613
+ const path = `${segmentPath}[${segmentIndex}]`;
614
+ const entry = protocolObject(segment, path);
615
+ assertUnknownKeys(entry, ['text', 'style'], path, 'segment key');
616
+ if (typeof entry.text !== 'string' || entry.text.length > MAX_TEXT_LENGTH) fail(`${path}.text`, `must be a string no longer than ${MAX_TEXT_LENGTH} characters`);
617
+ if (entry.style !== undefined && entry.style !== 'subscript') fail(`${path}.style`, 'must be subscript when provided');
618
+ textLength += entry.text.length;
619
+ });
620
+ if (textLength > MAX_TEXT_LENGTH) fail(segmentPath, `total text must be at most ${MAX_TEXT_LENGTH} characters`);
621
+ }
450
622
  }
451
623
  });
452
624
  }
625
+ function assertTextHelp(help, path) {
626
+ if (help === undefined) return;
627
+ const object = protocolObject(help, path);
628
+ assertUnknownKeys(object, ['actionKey', 'presentation', 'underline'], path, 'help key');
629
+ assertKey(help.actionKey, `${path}.actionKey`);
630
+ if (!['tooltip', 'popover'].includes(help.presentation)) fail(`${path}.presentation`, 'must be tooltip or popover');
631
+ if (help.underline !== undefined && help.underline !== 'dashed') fail(`${path}.underline`, 'must be dashed');
632
+ }
633
+ function assertButtonGroup(row, path) {
634
+ if (!Array.isArray(row.buttons) || row.buttons.length === 0) fail(`${path}.buttons`, 'must contain at least one button');
635
+ const keys = new Set();
636
+ row.buttons.forEach((button, index) => {
637
+ const itemPath = `${path}.buttons[${index}]`;
638
+ const object = protocolObject(button, itemPath);
639
+ assertUnknownKeys(object, ['key', 'label', 'actionKey', 'disabled', 'loading', 'testID', 'accessibilityLabel'], itemPath, 'button key');
640
+ assertKey(button.key, `${itemPath}.key`);
641
+ if (keys.has(button.key)) fail(`${itemPath}.key`, 'duplicate button key');
642
+ keys.add(button.key);
643
+ if (typeof button.label !== 'string' || !button.label.trim() || button.label.length > MAX_TEXT_LENGTH) fail(`${itemPath}.label`, 'must be non-blank bounded text');
644
+ assertKey(button.actionKey, `${itemPath}.actionKey`);
645
+ for (const field of ['disabled', 'loading']) {
646
+ if (button[field] !== undefined && typeof button[field] !== 'boolean') fail(`${itemPath}.${field}`, 'must be boolean');
647
+ }
648
+ for (const field of ['testID', 'accessibilityLabel']) {
649
+ if (button[field] !== undefined && typeof button[field] !== 'string') fail(`${itemPath}.${field}`, 'must be a string');
650
+ }
651
+ });
652
+ }
653
+ function assertIdentityExtras(row, path) {
654
+ for (const field of ['titleIcon', 'secondaryTitleIcon']) {
655
+ const titleIcon = row[field];
656
+ if (titleIcon === undefined) continue;
657
+ const iconPath = `${path}.${field}`;
658
+ const icon = protocolObject(titleIcon, iconPath);
659
+ assertUnknownKeys(icon, ['name', 'tintColor', 'accessibilityLabel', 'hoverActionKey'], iconPath, 'title icon key');
660
+ if (typeof titleIcon.name !== 'string' || !titleIcon.name.trim()) fail(`${iconPath}.name`, 'must be non-blank');
661
+ if (titleIcon.tintColor !== undefined && (typeof titleIcon.tintColor !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(titleIcon.tintColor))) fail(`${iconPath}.tintColor`, 'must be #RRGGBB or #RRGGBBAA');
662
+ if (titleIcon.accessibilityLabel !== undefined && typeof titleIcon.accessibilityLabel !== 'string') fail(`${iconPath}.accessibilityLabel`, 'must be a string');
663
+ if (titleIcon.hoverActionKey !== undefined) assertKey(titleIcon.hoverActionKey, `${iconPath}.hoverActionKey`);
664
+ }
665
+ const ratio = row.style?.leadingContentMaxWidthRatio;
666
+ if (ratio !== undefined && (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) fail(`${path}.style.leadingContentMaxWidthRatio`, 'must be within (0, 1]');
667
+ assertTrailingAccessories(row.trailing, `${path}.trailing`);
668
+ }
453
669
  function assertImage(image, path) {
454
670
  if (!image) return;
455
671
  if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
672
+ if (image.fallbackUris !== undefined) {
673
+ if (!Array.isArray(image.fallbackUris)) fail(`${path}.fallbackUris`, 'must be an array');
674
+ image.fallbackUris.forEach((uri, index) => {
675
+ if (typeof uri !== 'string') fail(`${path}.fallbackUris[${index}]`, 'must be a string');
676
+ assertText(uri, `${path}.fallbackUris[${index}]`);
677
+ });
678
+ }
456
679
  if (!Number.isFinite(image.width) || !Number.isFinite(image.height) || image.width <= 0 || image.height <= 0 || image.width > MAX_IMAGE_EDGE || image.height > MAX_IMAGE_EDGE) {
457
680
  fail(path, `width and height must be within 1...${MAX_IMAGE_EDGE}`);
458
681
  }
@@ -487,6 +710,9 @@ function assertLeadingVisual(visual, path) {
487
710
  assertText(visual.cornerIcon?.name, `${path}.cornerIcon.name`);
488
711
  // OneKey patch: validate optional selector overlays at the JSON boundary.
489
712
  assertText(visual.fallbackIcon?.name, `${path}.fallbackIcon.name`);
713
+ if (visual.fallbackTextColor !== undefined && (typeof visual.fallbackTextColor !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackTextColor))) fail(`${path}.fallbackTextColor`, 'must be a hex color');
714
+ if (visual.fallbackIcon?.size !== undefined && (!Number.isFinite(visual.fallbackIcon.size) || visual.fallbackIcon.size <= 0 || visual.fallbackIcon.size > 40)) fail(`${path}.fallbackIcon.size`, 'must be within (0, 40]');
715
+ if (visual.fallbackIcon?.backgroundColor !== undefined && !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackIcon.backgroundColor)) fail(`${path}.fallbackIcon.backgroundColor`, 'must be a hex color');
490
716
  if ((visual.overlays?.length ?? 0) > 2) fail(`${path}.overlays`, 'supports at most two overlays');
491
717
  visual.overlays?.forEach((overlay, index) => {
492
718
  if (!['topLeft', 'bottomRight'].includes(overlay.position)) fail(`${path}.overlays[${index}].position`, 'must be topLeft or bottomRight');
@@ -503,7 +729,11 @@ function assertLeadingVisual(visual, path) {
503
729
  }
504
730
  if (overlay.padding !== undefined && overlay.padding * 2 >= Math.min(overlay.width ?? overlay.size ?? 20, overlay.height ?? overlay.size ?? 20)) fail(`${path}.overlays[${index}].padding`, 'must fit inside the overlay');
505
731
  assertImage(overlay.image, `${path}.overlays[${index}].image`);
732
+ if (overlay.fallbackIcon !== undefined && !overlay.image) fail(`${path}.overlays[${index}].fallbackIcon`, 'requires image');
733
+ if (overlay.fallbackIcon !== undefined && (typeof overlay.fallbackIcon.name !== 'string' || !overlay.fallbackIcon.name.trim())) fail(`${path}.overlays[${index}].fallbackIcon.name`, 'must be non-blank');
734
+ if (overlay.fallbackIcon?.tintColor !== undefined && !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(overlay.fallbackIcon.tintColor)) fail(`${path}.overlays[${index}].fallbackIcon.tintColor`, 'must be a hex color');
506
735
  assertText(overlay.text, `${path}.overlays[${index}].text`);
736
+ if (overlay.fontWeight !== undefined && !['regular', 'medium', 'semibold', 'bold'].includes(overlay.fontWeight)) fail(`${path}.overlays[${index}].fontWeight`, 'must be regular, medium, semibold, or bold');
507
737
  });
508
738
  if (visual.kind === 'token') {
509
739
  assertImage(visual.networkImage, `${path}.networkImage`);
@@ -517,6 +747,7 @@ function assertVisual(row, path) {
517
747
  });
518
748
  }
519
749
  function assertActivity(row, path) {
750
+ if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean') fail(`${path}.hideLeading`, 'must be boolean');
520
751
  assertText(row.title, `${path}.title`);
521
752
  assertText(row.description, `${path}.description`);
522
753
  if (row.presentation !== undefined && !['stacked', 'table'].includes(row.presentation)) fail(`${path}.presentation`, 'must be stacked or table');
@@ -613,10 +844,26 @@ function assertRow(row, index, path = `rows[${index}]`) {
613
844
  assertWalletGroup(row, path);
614
845
  break;
615
846
  case 'identity':
847
+ if (row.contentHeight !== undefined && row.contentHeight !== 'auto') {
848
+ fail(`${path}.contentHeight`, 'must be auto');
849
+ }
850
+ if (row.subtitleLines !== undefined && ![0, 1, 2].includes(row.subtitleLines)) {
851
+ fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
852
+ }
853
+ if (row.longPressActionKey !== undefined) {
854
+ assertKey(row.longPressActionKey, `${path}.longPressActionKey`);
855
+ }
616
856
  if (row.presentation !== undefined && row.presentation !== 'walletSidebar' && row.presentation !== 'accountSelector' && row.presentation !== 'networkSelector') {
617
857
  fail(`${path}.presentation`, 'must be walletSidebar, accountSelector, or networkSelector when provided');
618
858
  }
619
859
  assertText(row.title, `${path}.title`);
860
+ if ((row.titleSuffixes?.length ?? 0) > 3) fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
861
+ row.titleSuffixes?.forEach((suffix, index) => {
862
+ assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
863
+ if (!['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}].tone`, 'must be secondary or disabled');
864
+ if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
865
+ });
866
+ assertIdentityExtras(row, path);
620
867
  assertText(row.subtitle, `${path}.subtitle`);
621
868
  // OneKey patch: selector text segments truncate independently.
622
869
  row.subtitleSegments?.forEach((segment, segmentIndex) => {
@@ -648,10 +895,13 @@ function assertRow(row, index, path = `rows[${index}]`) {
648
895
  assertActivity(row, path);
649
896
  break;
650
897
  case 'message':
898
+ if (row.presentation !== undefined && row.presentation !== 'inlineWarning') {
899
+ fail(`${path}.presentation`, 'must be inlineWarning');
900
+ }
651
901
  assertText(row.title, `${path}.title`);
652
902
  assertText(row.body, `${path}.body`);
653
- if (![1, 2, 3].includes(row.bodyLines ?? 3)) {
654
- fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
903
+ if (![0, 1, 2, 3].includes(row.bodyLines ?? 3)) {
904
+ fail(`${path}.bodyLines`, 'must be 0, 1, 2, or 3');
655
905
  }
656
906
  assertImage(row.thumbnail, `${path}.thumbnail`);
657
907
  break;
@@ -662,6 +912,13 @@ function assertRow(row, index, path = `rows[${index}]`) {
662
912
  row.columns.forEach((column, columnIndex) => {
663
913
  assertKey(column.key, `${path}.columns[${columnIndex}].key`);
664
914
  assertText(column.text, `${path}.columns[${columnIndex}].text`);
915
+ assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
916
+ for (const field of ['textSegments', 'secondaryTextSegments']) {
917
+ column[field]?.forEach((segment, segmentIndex) => {
918
+ assertText(segment.text, `${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`);
919
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`, 'must be subscript');
920
+ });
921
+ }
665
922
  assertText(column.secondaryLeadingText, `${path}.columns[${columnIndex}].secondaryLeadingText`);
666
923
  assertText(column.secondaryText, `${path}.columns[${columnIndex}].secondaryText`);
667
924
  assertTextTone(column.secondaryTone, `${path}.columns[${columnIndex}].secondaryTone`);
@@ -669,6 +926,10 @@ function assertRow(row, index, path = `rows[${index}]`) {
669
926
  if ((row.badges?.length ?? 0) > MAX_BADGES) {
670
927
  fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
671
928
  }
929
+ if ((row.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
930
+ fail(`${path}.trailing`, `supports at most ${MAX_TRAILING_ACCESSORIES} accessories`);
931
+ }
932
+ assertTrailingAccessories(row.trailing, `${path}.trailing`);
672
933
  break;
673
934
  case 'market':
674
935
  assertMarketRow(row, path);
@@ -719,6 +980,11 @@ function assertRow(row, index, path = `rows[${index}]`) {
719
980
  assertText(row.title, `${path}.title`);
720
981
  assertText(row.subtitle, `${path}.subtitle`);
721
982
  assertText(row.value, `${path}.value`);
983
+ if (row.leadingBadge) {
984
+ assertKey(row.leadingBadge.key, `${path}.leadingBadge.key`);
985
+ assertText(row.leadingBadge.text, `${path}.leadingBadge.text`);
986
+ }
987
+ assertTextHelp(row.valueHelp, `${path}.valueHelp`);
722
988
  if (row.valueActionKey !== undefined) {
723
989
  assertKey(row.valueActionKey, `${path}.valueActionKey`);
724
990
  }
@@ -739,6 +1005,9 @@ function assertRow(row, index, path = `rows[${index}]`) {
739
1005
  }
740
1006
  assertTrailingAccessories(row.trailing, `${path}.trailing`);
741
1007
  break;
1008
+ case 'buttonGroup':
1009
+ assertButtonGroup(row, path);
1010
+ break;
742
1011
  case 'system':
743
1012
  const presentation = 'presentation' in row ? row.presentation : undefined;
744
1013
  if (presentation !== undefined && presentation !== 'market') {
@@ -799,9 +1068,23 @@ function assertMediaPreview(value, path) {
799
1068
  fail(`${path}.probeOrder`, 'must contain one or two distinct image/video candidates');
800
1069
  }
801
1070
  }
802
- export function validateSnapshot(snapshot) {
1071
+ function assertSnapshotContract(snapshot) {
1072
+ if (snapshot.disclosure !== undefined) {
1073
+ if (typeof snapshot.disclosure.expanded !== 'boolean') fail('snapshot.disclosure.expanded', 'must be a boolean');
1074
+ const inset = snapshot.disclosure.expandedTrailingInset;
1075
+ if (inset !== undefined && (!Number.isFinite(inset) || inset < 0)) fail('snapshot.disclosure.expandedTrailingInset', 'must be finite and nonnegative');
1076
+ }
1077
+ if (snapshot.structuralTransition) {
1078
+ assertKey(snapshot.structuralTransition.id, 'snapshot.structuralTransition.id');
1079
+ if (snapshot.structuralTransition.anchorKey !== undefined) assertKey(snapshot.structuralTransition.anchorKey, 'snapshot.structuralTransition.anchorKey');
1080
+ const duration = snapshot.structuralTransition.durationMs;
1081
+ if (duration !== undefined && (!Number.isFinite(duration) || duration < 0 || duration > 2000)) fail('snapshot.structuralTransition.durationMs', 'must be finite within 0...2000');
1082
+ }
803
1083
  if (snapshot.capabilities?.refreshTriggerDistance !== undefined && (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) || snapshot.capabilities.refreshTriggerDistance <= 0)) fail('capabilities.refreshTriggerDistance', 'must be a positive finite number');
804
1084
  assertPlainSerializable(snapshot, 'snapshot', new Set());
1085
+ assertText(snapshot.theme?.imageFallbackBackground, 'theme.imageFallbackBackground');
1086
+ if (snapshot.theme?.successBackground !== undefined && (typeof snapshot.theme.successBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))) fail('theme.successBackground', 'must be a hex color');
1087
+ if (snapshot.theme?.rowHoverBackground !== undefined && (typeof snapshot.theme.rowHoverBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))) fail('theme.rowHoverBackground', 'must be a hex color');
805
1088
  if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
806
1089
  if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
807
1090
  fail('snapshot.generation', 'must be a non-negative safe integer');
@@ -870,7 +1153,261 @@ export function validateSnapshot(snapshot) {
870
1153
  if (snapshot.selection?.mode === 'single' && selectedKeys.size > 1) {
871
1154
  fail('snapshot.selection.selectedKeys', 'supports at most one key in single mode');
872
1155
  }
873
- return normalizeSnapshotStyles(snapshot);
1156
+ return snapshot;
1157
+ }
1158
+ function protocolObject(value, path) {
1159
+ if (!value || typeof value !== 'object' || Array.isArray(value)) fail(path, 'must be an object');
1160
+ return value;
1161
+ }
1162
+ function protocolKey(value, path) {
1163
+ if (typeof value !== 'string' || value.trim().length === 0) fail(path, 'must be a non-blank string');
1164
+ }
1165
+ const PROTOCOL_ARRAY_FIELDS = new Set(['columns', 'titleSuffixes', 'cells', 'points', 'images', 'overlays', 'badges', 'trailing', 'footerActions', 'buttons', 'amounts', 'metrics', 'children', 'subtitleSegments', 'titleMatch', 'selectedKeys', 'segments', 'hoverSecondary', 'hoverImages', 'secondaryBadges', 'fallbackUris', 'probeOrder', 'priceSegments', 'textSegments', 'secondaryTextSegments', 'primaryTextSegments']);
1166
+ const PROTOCOL_NUMBER_FIELDS = new Set(['leadingContentMaxWidthRatio', 'height', 'width', 'fontSize', 'lineHeight', 'opacity', 'offsetY', 'offsetX', 'cornerRadius', 'borderWidth', 'horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'titleBadgeGap', 'trailingGap', 'start', 'end', 'padding', 'offset', 'overscan', 'minWidth', 'flex', 'paddingStart', 'paddingEnd', 'changeWidth', 'changeHeight', 'changeCornerRadius', 'contentTrailingGap', 'subtitleTrailingPadding', 'partGap', 'contentPadding', 'contentPaddingHorizontal', 'contentPaddingTop', 'contentPaddingBottom', 'itemSpacing', 'gridColumns']);
1167
+
1168
+ /** Validate only shapes that renderers dereference, not display budgets. */
1169
+ function assertProtocolFields(value, path, parentField = '') {
1170
+ if (value === undefined || value === null || typeof value !== 'object') return;
1171
+ if (Array.isArray(value)) {
1172
+ for (const [index, item] of value.entries()) {
1173
+ const itemPath = `${path}[${index}]`;
1174
+ if (['selectedKeys', 'fallbackUris', 'probeOrder'].includes(parentField)) {
1175
+ if (typeof item !== 'string') fail(itemPath, 'must be a string');
1176
+ } else if (parentField === 'points') {
1177
+ if (typeof item !== 'number') fail(itemPath, 'must be a finite number');
1178
+ } else if (parentField === 'hoverImages' && item === null) continue;else protocolObject(item, itemPath);
1179
+ assertProtocolFields(item, itemPath, parentField);
1180
+ }
1181
+ return;
1182
+ }
1183
+ const object = value;
1184
+ if (parentField === 'fallbackIcon') {
1185
+ protocolKey(object.name, `${path}.name`);
1186
+ if (object.size !== undefined && (typeof object.size !== 'number' || !Number.isFinite(object.size) || object.size <= 0 || object.size > 40)) fail(`${path}.size`, 'must be within (0, 40]');
1187
+ for (const field of ['tintColor', 'backgroundColor']) {
1188
+ const color = object[field];
1189
+ if (color !== undefined && (typeof color !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color))) fail(`${path}.${field}`, 'must be a hex color');
1190
+ }
1191
+ }
1192
+ if (parentField === 'overlays' && object.fallbackIcon !== undefined && !object.image) fail(`${path}.fallbackIcon`, 'requires image');
1193
+ if (!path.includes('.style.') && ['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(parentField) && typeof object.uri !== 'string') fail(`${path}.uri`, 'must be a string');
1194
+ Object.entries(value).forEach(([field, item]) => {
1195
+ if (item === undefined) return;
1196
+ const fieldPath = `${path}.${field}`;
1197
+ if (!path.endsWith('.style') && PROTOCOL_ARRAY_FIELDS.has(field) && !Array.isArray(item)) fail(fieldPath, 'must be an array');
1198
+ if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number') fail(fieldPath, 'must be a finite number');
1199
+ if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item === 'number' && item < 0 && !['offsetX', 'offsetY'].includes(field)) fail(fieldPath, 'must be non-negative');
1200
+ if (parentField === 'overlays' && field === 'fontWeight' && !['regular', 'medium', 'semibold', 'bold'].includes(item)) fail(fieldPath, 'must be regular, medium, semibold, or bold');
1201
+ if (field === 'buttonStyle' && item !== 'tertiary') fail(fieldPath, 'must be tertiary');
1202
+ if (field === 'hideLeading' && typeof item !== 'boolean') fail(fieldPath, 'must be boolean');
1203
+ if (field === 'key' || field === 'sectionKey' || field === 'actionKey' || field.endsWith('ActionKey')) protocolKey(item, fieldPath);
1204
+ if ((field === 'uri' || field === 'fallbackUri') && typeof item !== 'string') fail(fieldPath, 'must be a string');
1205
+ if (field === 'style' && !(item === 'subscript' && /[Ss]egments\[/.test(path)) || field === 'container') protocolObject(item, fieldPath);
1206
+ if (path.endsWith('.style') && ['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'change', 'columns', 'columnSecondary', 'value', 'valueSecondary', 'badge', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'trend', 'message', 'actionText'].includes(field)) protocolObject(item, fieldPath);
1207
+ assertProtocolFields(item, fieldPath, field);
1208
+ });
1209
+ }
1210
+ function assertRowProtocol(row, path) {
1211
+ protocolObject(row, path);
1212
+ assertRowType(row.type, path);
1213
+ protocolKey(row.key, `${path}.key`);
1214
+ assertProtocolFields(row, path);
1215
+ for (const field of ['leading', 'visual', 'secondaryLeading']) {
1216
+ const visual = row[field];
1217
+ if (visual !== undefined || field === 'leading' && (row.type === 'identity' || row.type === 'market')) {
1218
+ const object = protocolObject(visual, `${path}.${field}`);
1219
+ if (object.kind === 'stackedImages' && !Array.isArray(object.images)) fail(`${path}.${field}.images`, 'must be an array');
1220
+ }
1221
+ }
1222
+ for (const field of ['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'indexTitle']) {
1223
+ const value = row[field];
1224
+ if (value !== undefined && typeof value !== 'string') fail(`${path}.${field}`, 'must be a string');
1225
+ }
1226
+ if (row.height !== undefined && row.height < 0) fail(`${path}.height`, 'must be non-negative');
1227
+ if (row.type === 'identity') {
1228
+ assertIdentityExtras(row, path);
1229
+ if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes)) fail(`${path}.titleSuffixes`, 'must be an array');
1230
+ row.titleSuffixes?.forEach((suffix, index) => {
1231
+ protocolObject(suffix, `${path}.titleSuffixes[${index}]`);
1232
+ if (typeof suffix.text !== 'string' || !['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}]`, 'invalid title suffix');
1233
+ if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
1234
+ });
1235
+ let end = 0;
1236
+ row.titleMatch?.forEach(match => {
1237
+ if (!Number.isInteger(match.start) || !Number.isInteger(match.end) || match.start < end || match.end <= match.start || match.end > row.title.length) fail(`${path}.titleMatch`, 'invalid text range');
1238
+ end = match.end;
1239
+ });
1240
+ }
1241
+ if (row.type === 'buttonGroup') assertButtonGroup(row, path);
1242
+ if (row.type === 'sectionHeader') assertTextHelp(row.valueHelp, `${path}.valueHelp`);
1243
+ if (row.type === 'mediaTile' && row.media) {
1244
+ protocolObject(row.media.source, `${path}.media.source`);
1245
+ if (!Array.isArray(row.media.probeOrder)) fail(`${path}.media.probeOrder`, 'must be an array');
1246
+ }
1247
+ if (row.type === 'walletGroup') {
1248
+ protocolObject(row.parent, `${path}.parent`);
1249
+ if (!Array.isArray(row.children)) fail(`${path}.children`, 'must be an array');
1250
+ const members = [row.parent, ...row.children];
1251
+ const keys = new Set();
1252
+ if (row.parent.key !== row.key) fail(`${path}.parent.key`, 'must match its group');
1253
+ members.forEach((member, index) => {
1254
+ assertRowProtocol(member, `${path}.members[${index}]`);
1255
+ if (member.type !== 'identity' || keys.has(member.key)) fail(path, 'invalid wallet member identity');
1256
+ keys.add(member.key);
1257
+ });
1258
+ }
1259
+ if (row.type === 'dataRow') {
1260
+ if (!Array.isArray(row.columns)) fail(`${path}.columns`, 'must be an array');
1261
+ row.columns.forEach((column, index) => {
1262
+ const columnPath = `${path}.columns[${index}]`;
1263
+ protocolObject(column, columnPath);
1264
+ assertIdentityExtras(column, columnPath);
1265
+ });
1266
+ assertTrailingAccessories(row.trailing, `${path}.trailing`);
1267
+ }
1268
+ if (row.type === 'market') {
1269
+ protocolObject(row.change, `${path}.change`);
1270
+ if (row.webTable) {
1271
+ const {
1272
+ columns,
1273
+ cells
1274
+ } = row.webTable;
1275
+ if (!Array.isArray(columns) || !Array.isArray(cells) || columns.length !== cells.length) fail(`${path}.webTable`, 'columns and cells must match');
1276
+ const keys = new Set();
1277
+ columns.forEach((column, index) => {
1278
+ protocolKey(column.key, `${path}.webTable.columns[${index}].key`);
1279
+ if (keys.has(column.key) || cells[index]?.key !== column.key) fail(`${path}.webTable`, 'invalid column identity');
1280
+ keys.add(column.key);
1281
+ const cell = cells[index];
1282
+ if (!['favorite', 'asset', 'text', 'sparkline'].includes(cell.kind)) fail(`${path}.webTable.cells[${index}]`, 'unsupported cell kind');
1283
+ if (cell.kind === 'asset') protocolObject(cell.title, `${path}.webTable.cells[${index}].title`);
1284
+ if ((cell.kind === 'asset' || cell.kind === 'text') && cell.secondary !== undefined && !Array.isArray(cell.secondary)) fail(`${path}.webTable.cells[${index}].secondary`, 'must be an array');
1285
+ if (cell.kind === 'text' && !Array.isArray(cell.primary)) fail(`${path}.webTable.cells[${index}].primary`, 'must be an array');
1286
+ // The Web renderer spreads samples into Math.min/Math.max.
1287
+ if (cell.kind === 'sparkline' && (!Array.isArray(cell.points) || cell.points.length > 256)) fail(`${path}.webTable.cells[${index}].points`, 'must be an array of at most 256 samples');
1288
+ });
1289
+ }
1290
+ }
1291
+ }
1292
+ function assertSnapshotProtocol(snapshot) {
1293
+ protocolObject(snapshot, 'snapshot');
1294
+ if (snapshot.disclosure !== undefined) {
1295
+ protocolObject(snapshot.disclosure, 'snapshot.disclosure');
1296
+ if (typeof snapshot.disclosure.expanded !== 'boolean') fail('snapshot.disclosure.expanded', 'must be a boolean');
1297
+ const inset = snapshot.disclosure.expandedTrailingInset;
1298
+ if (inset !== undefined && (!Number.isFinite(inset) || inset < 0)) fail('snapshot.disclosure.expandedTrailingInset', 'must be finite and nonnegative');
1299
+ }
1300
+ if (snapshot.structuralTransition) {
1301
+ protocolObject(snapshot.structuralTransition, 'snapshot.structuralTransition');
1302
+ protocolKey(snapshot.structuralTransition.id, 'snapshot.structuralTransition.id');
1303
+ if (snapshot.structuralTransition.anchorKey !== undefined) protocolKey(snapshot.structuralTransition.anchorKey, 'snapshot.structuralTransition.anchorKey');
1304
+ const duration = snapshot.structuralTransition.durationMs;
1305
+ if (duration !== undefined && (!Number.isFinite(duration) || duration < 0 || duration > 2000)) fail('snapshot.structuralTransition.durationMs', 'must be finite within 0...2000');
1306
+ }
1307
+ if (snapshot.theme?.successBackground !== undefined && (typeof snapshot.theme.successBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))) fail('theme.successBackground', 'must be a hex color');
1308
+ if (snapshot.theme?.rowHoverBackground !== undefined && (typeof snapshot.theme.rowHoverBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))) fail('theme.rowHoverBackground', 'must be a hex color');
1309
+ if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
1310
+ if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) fail('snapshot.generation', 'must be a non-negative safe integer');
1311
+ protocolObject(snapshot.layout, 'snapshot.layout');
1312
+ assertProtocolFields(snapshot.layout, 'snapshot.layout');
1313
+ if (snapshot.layout.orientation !== undefined && !['vertical', 'horizontal'].includes(snapshot.layout.orientation)) fail('snapshot.layout.orientation', 'is not supported');
1314
+ if (!['linear', 'sectioned', 'grid', 'table'].includes(snapshot.layout.kind)) fail('snapshot.layout.kind', 'is not supported');
1315
+ if (!Array.isArray(snapshot.rows)) fail('snapshot.rows', 'must be an array');
1316
+ if (snapshot.layout.kind === 'grid' && (!Number.isInteger(snapshot.layout.gridColumns) || (snapshot.layout.gridColumns ?? 0) < 1 || (snapshot.layout.gridColumns ?? 0) > 7)) fail('snapshot.layout.gridColumns', 'must be an integer from 1 to 7');
1317
+ const keys = new Set();
1318
+ for (const [index, row] of snapshot.rows.entries()) {
1319
+ assertRowProtocol(row, `rows[${index}]`);
1320
+ if (keys.has(row.key)) fail(`rows[${index}].key`, 'duplicate row identity');
1321
+ keys.add(row.key);
1322
+ }
1323
+ if (snapshot.emptyState) assertRowProtocol(snapshot.emptyState, 'emptyState');
1324
+ if (snapshot.fixedFooter) assertRowProtocol(snapshot.fixedFooter, 'fixedFooter');
1325
+ if (snapshot.selection) {
1326
+ if (!Array.isArray(snapshot.selection.selectedKeys)) fail('snapshot.selection.selectedKeys', 'must be an array');
1327
+ snapshot.selection.selectedKeys.forEach(key => {
1328
+ if (!keys.has(key)) fail('snapshot.selection.selectedKeys', 'unknown row identity');
1329
+ });
1330
+ }
1331
+ }
1332
+
1333
+ /** Empty optional image descriptors must take the same path as absent images. */
1334
+ function normalizeEmptyImages(value, field = '') {
1335
+ if (!value || typeof value !== 'object') return value;
1336
+ if (Array.isArray(value)) {
1337
+ const next = value.map(item => normalizeEmptyImages(item));
1338
+ const filtered = field === 'images' ? next.filter(item => item !== undefined) : next.map(item => item === undefined ? null : item);
1339
+ return filtered.length === value.length && filtered.every((item, index) => item === value[index]) ? value : filtered;
1340
+ }
1341
+ const object = value;
1342
+ if (typeof object.uri === 'string' && !object.uri.trim() && 'width' in object && 'height' in object) return undefined;
1343
+ let changed = false;
1344
+ const next = {
1345
+ ...object
1346
+ };
1347
+ Object.entries(object).forEach(([key, item]) => {
1348
+ const normalized = normalizeEmptyImages(item, key);
1349
+ if (normalized !== item) {
1350
+ // Omitted JSON patch fields must also be absent from the JS merge.
1351
+ if (field === 'changes' && normalized === undefined) delete next[key];else next[key] = normalized;
1352
+ changed = true;
1353
+ }
1354
+ });
1355
+ if (field === 'media' && next.source === undefined) return undefined;
1356
+ return changed ? next : value;
1357
+ }
1358
+ export function validateSnapshot(snapshot) {
1359
+ assertPlainSerializable(snapshot, 'snapshot', new Set());
1360
+ if (isDevelopment()) assertSnapshotContract(snapshot);
1361
+ const normalized = isDevelopment() ? snapshot : normalizeEmptyImages(snapshot);
1362
+ assertSnapshotProtocol(normalized);
1363
+ return normalizeSnapshotStyles(normalized);
1364
+ }
1365
+ const ownedNativeSnapshots = new WeakMap();
1366
+ function capturePlainData(value, seen = new Map()) {
1367
+ if (value === null || typeof value !== 'object') return value;
1368
+ const previous = seen.get(value);
1369
+ if (previous) return previous;
1370
+ const copy = Array.isArray(value) ? new Array(value.length) : Object.create(Object.getPrototypeOf(value));
1371
+ seen.set(value, copy);
1372
+ const captureKey = key => {
1373
+ Object.defineProperty(copy, key, {
1374
+ value: capturePlainData(value[key], seen),
1375
+ enumerable: true,
1376
+ writable: true,
1377
+ configurable: true
1378
+ });
1379
+ };
1380
+ if (Array.isArray(value)) {
1381
+ for (let index = 0; index < value.length; index += 1) {
1382
+ if (index in value) captureKey(String(index));
1383
+ }
1384
+ Object.keys(value).forEach(key => {
1385
+ const index = Number(key);
1386
+ if (Number.isInteger(index) && index >= 0 && index < value.length && String(index) === key) return;
1387
+ captureKey(key);
1388
+ });
1389
+ } else {
1390
+ Object.keys(value).forEach(captureKey);
1391
+ }
1392
+ return copy;
1393
+ }
1394
+ function deepFreeze(value, seen = new WeakSet()) {
1395
+ if (value === null || typeof value !== 'object' || seen.has(value)) return value;
1396
+ seen.add(value);
1397
+ Object.values(value).forEach(item => deepFreeze(item, seen));
1398
+ return Object.freeze(value);
1399
+ }
1400
+
1401
+ /** Capture caller data once before validation, including accessor values. */
1402
+ export function captureNativeListInput(value) {
1403
+ return capturePlainData(value);
1404
+ }
1405
+
1406
+ /** Private native-wrapper ownership; exported validators keep their public identity. */
1407
+ export function ownValidatedNativeSnapshot(snapshot) {
1408
+ const owned = deepFreeze(snapshot);
1409
+ ownedNativeSnapshots.set(owned, new Map(owned.rows.map((row, index) => [row.key, index])));
1410
+ return owned;
874
1411
  }
875
1412
 
876
1413
  /**
@@ -916,7 +1453,23 @@ function assertPatchChanges(patch, index) {
916
1453
  }
917
1454
  switch (patch.type) {
918
1455
  case 'identity':
1456
+ if (patch.changes.contentHeight !== undefined && patch.changes.contentHeight !== 'auto') {
1457
+ fail(`${path}.contentHeight`, 'must be auto');
1458
+ }
1459
+ if (patch.changes.subtitleLines !== undefined && ![0, 1, 2].includes(patch.changes.subtitleLines)) {
1460
+ fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
1461
+ }
1462
+ if (patch.changes.longPressActionKey !== undefined) {
1463
+ assertKey(patch.changes.longPressActionKey, `${path}.longPressActionKey`);
1464
+ }
919
1465
  assertText(patch.changes.title, `${path}.title`);
1466
+ if ((patch.changes.titleSuffixes?.length ?? 0) > 3) fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
1467
+ patch.changes.titleSuffixes?.forEach((suffix, index) => {
1468
+ assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
1469
+ if (!['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}].tone`, 'must be secondary or disabled');
1470
+ if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
1471
+ });
1472
+ assertIdentityExtras(patch.changes, path);
920
1473
  assertText(patch.changes.subtitle, `${path}.subtitle`);
921
1474
  assertText(patch.changes.tertiary, `${path}.tertiary`);
922
1475
  if (patch.changes.tertiaryTone !== undefined && !['secondary', 'info'].includes(patch.changes.tertiaryTone)) {
@@ -950,11 +1503,14 @@ function assertPatchChanges(patch, index) {
950
1503
  }
951
1504
  break;
952
1505
  case 'message':
1506
+ if (patch.changes.presentation !== undefined && patch.changes.presentation !== 'inlineWarning') {
1507
+ fail(`${path}.presentation`, 'must be inlineWarning');
1508
+ }
953
1509
  assertText(patch.changes.title, `${path}.title`);
954
1510
  assertText(patch.changes.body, `${path}.body`);
955
1511
  assertText(patch.changes.time, `${path}.time`);
956
- if (patch.changes.bodyLines !== undefined && ![1, 2, 3].includes(patch.changes.bodyLines)) {
957
- fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
1512
+ if (patch.changes.bodyLines !== undefined && ![0, 1, 2, 3].includes(patch.changes.bodyLines)) {
1513
+ fail(`${path}.bodyLines`, 'must be 0, 1, 2, or 3');
958
1514
  }
959
1515
  assertImage(patch.changes.thumbnail, `${path}.thumbnail`);
960
1516
  break;
@@ -965,12 +1521,23 @@ function assertPatchChanges(patch, index) {
965
1521
  patch.changes.columns?.forEach((column, columnIndex) => {
966
1522
  assertKey(column.key, `${path}.columns[${columnIndex}].key`);
967
1523
  assertText(column.text, `${path}.columns[${columnIndex}].text`);
1524
+ assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
1525
+ for (const field of ['textSegments', 'secondaryTextSegments']) {
1526
+ column[field]?.forEach((segment, segmentIndex) => {
1527
+ assertText(segment.text, `${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`);
1528
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`, 'must be subscript');
1529
+ });
1530
+ }
968
1531
  assertText(column.secondaryText, `${path}.columns[${columnIndex}].secondaryText`);
969
1532
  assertTextTone(column.secondaryTone, `${path}.columns[${columnIndex}].secondaryTone`);
970
1533
  });
971
1534
  if ((patch.changes.badges?.length ?? 0) > MAX_BADGES) {
972
1535
  fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
973
1536
  }
1537
+ if ((patch.changes.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
1538
+ fail(`${path}.trailing`, `supports at most ${MAX_TRAILING_ACCESSORIES} accessories`);
1539
+ }
1540
+ assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
974
1541
  break;
975
1542
  case 'market':
976
1543
  assertMarketRow({
@@ -1029,6 +1596,11 @@ function assertPatchChanges(patch, index) {
1029
1596
  assertText(patch.changes.title, `${path}.title`);
1030
1597
  assertText(patch.changes.subtitle, `${path}.subtitle`);
1031
1598
  assertText(patch.changes.value, `${path}.value`);
1599
+ if (patch.changes.leadingBadge) {
1600
+ assertKey(patch.changes.leadingBadge.key, `${path}.leadingBadge.key`);
1601
+ assertText(patch.changes.leadingBadge.text, `${path}.leadingBadge.text`);
1602
+ }
1603
+ assertTextHelp(patch.changes.valueHelp, `${path}.valueHelp`);
1032
1604
  if (patch.changes.valueActionKey !== undefined) {
1033
1605
  assertKey(patch.changes.valueActionKey, `${path}.valueActionKey`);
1034
1606
  }
@@ -1042,6 +1614,11 @@ function assertPatchChanges(patch, index) {
1042
1614
  }
1043
1615
  assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
1044
1616
  break;
1617
+ case 'buttonGroup':
1618
+ if (patch.changes.buttons !== undefined) assertButtonGroup({
1619
+ buttons: patch.changes.buttons
1620
+ }, path);
1621
+ break;
1045
1622
  case 'system':
1046
1623
  assertText(patch.changes.message, `${path}.message`);
1047
1624
  break;
@@ -1051,17 +1628,26 @@ function assertPatchChanges(patch, index) {
1051
1628
  }
1052
1629
  export function validatePatches(patches) {
1053
1630
  assertPlainSerializable(patches, 'patches', new Set());
1631
+ if (!Array.isArray(patches)) fail('patches', 'must be an array');
1054
1632
  const keys = new Set();
1055
- patches.forEach((patch, index) => {
1056
- assertKey(patch.key, `patches[${index}].key`);
1633
+ for (const [index, patch] of patches.entries()) {
1634
+ protocolObject(patch, `patches[${index}]`);
1635
+ protocolKey(patch.key, `patches[${index}].key`);
1057
1636
  if (keys.has(patch.key)) fail(`patches[${index}].key`, `duplicate key "${patch.key}"`);
1058
1637
  keys.add(patch.key);
1638
+ protocolObject(patch.changes, `patches[${index}].changes`);
1639
+ assertRowType(patch.type, `patches[${index}]`);
1640
+ assertProtocolFields(patch.changes, `patches[${index}].changes`);
1641
+ if (patch.type === 'identity') assertIdentityExtras(patch.changes, `patches[${index}].changes`);
1642
+ if (!isDevelopment()) continue;
1643
+ assertKey(patch.key, `patches[${index}].key`);
1059
1644
  if (Object.keys(patch.changes).length === 0) {
1060
1645
  fail(`patches[${index}].changes`, 'must contain at least one field');
1061
1646
  }
1062
1647
  assertPatchChanges(patch, index);
1063
- });
1064
- return normalizePatchStyles(patches);
1648
+ }
1649
+ const normalized = isDevelopment() ? patches : normalizeEmptyImages(patches);
1650
+ return normalizePatchStyles(normalized.filter(patch => Object.keys(patch.changes).length > 0));
1065
1651
  }
1066
1652
 
1067
1653
  /** Patches reach the native side without passing through a snapshot. */
@@ -1083,11 +1669,101 @@ function normalizePatchStyles(patches) {
1083
1669
  });
1084
1670
  return changed ? next : patches;
1085
1671
  }
1672
+ const EMPTY_ROW_PATCHES = Object.freeze([]);
1673
+ function sameJsonValue(left, right) {
1674
+ if (left === right) return true;
1675
+ if (left === null || right === null) return false;
1676
+ if (typeof left !== 'object' || typeof right !== 'object') return false;
1677
+ if (Array.isArray(left) || Array.isArray(right)) {
1678
+ return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => sameJsonValue(value, right[index]));
1679
+ }
1680
+ const leftObject = left;
1681
+ const rightObject = right;
1682
+ const leftKeys = Object.keys(leftObject).filter(key => leftObject[key] !== undefined);
1683
+ const rightKeys = Object.keys(rightObject).filter(key => rightObject[key] !== undefined);
1684
+ return leftKeys.length === rightKeys.length && leftKeys.every(key => sameJsonValue(leftObject[key], rightObject[key]));
1685
+ }
1686
+ function sameOptionalPresence(left, right) {
1687
+ return left === undefined === (right === undefined);
1688
+ }
1689
+
1690
+ /** Plan value-only patches; callers own valid immutable snapshots and commit state. */
1691
+ export function planNativeListPatches(previous, next) {
1692
+ if (previous === next) return EMPTY_ROW_PATCHES;
1693
+ const {
1694
+ rows: previousRows,
1695
+ ...previousMetadata
1696
+ } = previous;
1697
+ const {
1698
+ rows: nextRows,
1699
+ ...nextMetadata
1700
+ } = next;
1701
+ if (previousRows.length !== nextRows.length || !sameJsonValue(previousMetadata, nextMetadata)) return undefined;
1702
+ if (previousRows === nextRows) return EMPTY_ROW_PATCHES;
1703
+ const patches = [];
1704
+ for (let index = 0; index < nextRows.length; index += 1) {
1705
+ const oldRow = previousRows[index];
1706
+ const row = nextRows[index];
1707
+ if (oldRow.key !== row.key || oldRow.type !== row.type) return undefined;
1708
+ if (oldRow === row) continue;
1709
+ if (oldRow.type === 'identity' && row.type === 'identity') {
1710
+ const {
1711
+ subtitle: oldSubtitle,
1712
+ subtitleSegments: oldSubtitleSegments,
1713
+ trailing: oldTrailing,
1714
+ ...oldMetadata
1715
+ } = oldRow;
1716
+ const {
1717
+ subtitle,
1718
+ subtitleSegments,
1719
+ trailing,
1720
+ ...metadata
1721
+ } = row;
1722
+ if (!sameOptionalPresence(oldSubtitle, subtitle) || !sameOptionalPresence(oldSubtitleSegments, subtitleSegments) || !sameOptionalPresence(oldTrailing, trailing) || !sameJsonValue(oldMetadata, metadata)) return undefined;
1723
+ if (!sameJsonValue(oldSubtitle, subtitle) || !sameJsonValue(oldSubtitleSegments, subtitleSegments) || !sameJsonValue(oldTrailing, trailing)) {
1724
+ patches.push({
1725
+ type: 'identity',
1726
+ key: row.key,
1727
+ changes: {
1728
+ subtitle,
1729
+ subtitleSegments,
1730
+ trailing
1731
+ }
1732
+ });
1733
+ }
1734
+ } else if (oldRow.type === 'dataRow' && row.type === 'dataRow') {
1735
+ const {
1736
+ columns: oldColumns,
1737
+ trailing: oldTrailing,
1738
+ ...oldMetadata
1739
+ } = oldRow;
1740
+ const {
1741
+ columns,
1742
+ trailing,
1743
+ ...metadata
1744
+ } = row;
1745
+ if (!sameOptionalPresence(oldTrailing, trailing) || !sameJsonValue(oldMetadata, metadata) || !sameJsonValue(oldColumns[0], columns[0])) return undefined;
1746
+ if (!sameJsonValue(oldColumns.slice(1), columns.slice(1)) || !sameJsonValue(oldTrailing, trailing)) {
1747
+ patches.push({
1748
+ type: 'dataRow',
1749
+ key: row.key,
1750
+ changes: {
1751
+ columns,
1752
+ trailing
1753
+ }
1754
+ });
1755
+ }
1756
+ } else if (!sameJsonValue(oldRow, row)) {
1757
+ return undefined;
1758
+ }
1759
+ }
1760
+ return patches.length === 0 ? EMPTY_ROW_PATCHES : patches;
1761
+ }
1086
1762
  export function applyRowPatches(snapshot, patches) {
1087
- validatePatches(patches);
1088
- const patchByKey = new Map(patches.map(patch => [patch.key, patch]));
1763
+ const normalizedPatches = validatePatches(patches);
1764
+ const patchByKey = new Map(normalizedPatches.map(patch => [patch.key, patch]));
1089
1765
  const knownKeys = new Set(snapshot.rows.map(row => row.key));
1090
- patches.forEach(patch => {
1766
+ normalizedPatches.forEach(patch => {
1091
1767
  if (!knownKeys.has(patch.key)) fail('patches', `unknown row key "${patch.key}"`);
1092
1768
  });
1093
1769
  const rows = snapshot.rows.map(row => {
@@ -1096,6 +1772,7 @@ export function applyRowPatches(snapshot, patches) {
1096
1772
  if (patch.type !== row.type) {
1097
1773
  fail('patches', `row "${row.key}" is ${row.type}, not ${patch.type}`);
1098
1774
  }
1775
+ if (row.type === 'market' && row.webTable && patch.type === 'market' && (patch.changes.price !== undefined || patch.changes.priceSegments !== undefined || patch.changes.change !== undefined) && patch.changes.webTable === undefined) fail('patches', 'table quote changes must include the visible table cells');
1099
1776
  return {
1100
1777
  ...row,
1101
1778
  ...patch.changes,
@@ -1108,6 +1785,53 @@ export function applyRowPatches(snapshot, patches) {
1108
1785
  rows
1109
1786
  });
1110
1787
  }
1788
+
1789
+ /** Native wrapper only: preserve full public validation for unsupported patches. */
1790
+ export function applyOwnedNativePatches(snapshot, patches) {
1791
+ const acceptedPatches = deepFreeze(validatePatches(capturePlainData(patches)));
1792
+ const rowIndexes = ownedNativeSnapshots.get(snapshot);
1793
+ const canPatchRows = rowIndexes !== undefined && acceptedPatches.every(patch => {
1794
+ const index = rowIndexes.get(patch.key);
1795
+ if (index === undefined || snapshot.rows[index].type !== patch.type) return false;
1796
+ const allowed = patch.type === 'identity' ? ['subtitle', 'subtitleSegments', 'trailing'] : patch.type === 'dataRow' ? ['columns', 'trailing'] : undefined;
1797
+ return allowed !== undefined && Object.entries(patch.changes).every(([key, value]) => allowed.includes(key) && (value !== undefined || snapshot.rows[index][key] === undefined));
1798
+ });
1799
+ if (!canPatchRows) {
1800
+ const baseline = rowIndexes ? snapshot : capturePlainData(snapshot);
1801
+ return {
1802
+ patches: acceptedPatches,
1803
+ snapshot: ownValidatedNativeSnapshot(applyRowPatches(baseline, acceptedPatches)),
1804
+ json: JSON.stringify(acceptedPatches)
1805
+ };
1806
+ }
1807
+ const nextRows = snapshot.rows.slice();
1808
+ for (const patch of acceptedPatches) {
1809
+ const index = rowIndexes.get(patch.key);
1810
+ const previous = nextRows[index];
1811
+ const merged = {
1812
+ ...previous,
1813
+ ...patch.changes,
1814
+ key: previous.key,
1815
+ type: previous.type
1816
+ };
1817
+ const path = `rows[${index}]`;
1818
+ assertPlainSerializable(merged, path, new Set());
1819
+ if (isDevelopment()) assertRow(merged, index);
1820
+ const normalized = isDevelopment() ? merged : normalizeEmptyImages(merged);
1821
+ assertRowProtocol(normalized, path);
1822
+ nextRows[index] = deepFreeze(normalizeRowStyles(normalized));
1823
+ }
1824
+ const nextSnapshot = Object.freeze({
1825
+ ...snapshot,
1826
+ rows: Object.freeze(nextRows)
1827
+ });
1828
+ ownedNativeSnapshots.set(nextSnapshot, rowIndexes);
1829
+ return {
1830
+ patches: acceptedPatches,
1831
+ snapshot: nextSnapshot,
1832
+ json: JSON.stringify(acceptedPatches)
1833
+ };
1834
+ }
1111
1835
  export function serializeSnapshot(snapshot) {
1112
1836
  return JSON.stringify(validateSnapshot(snapshot));
1113
1837
  }