@onekeyfe/react-native-native-list 6.7.0-alpha.344 → 6.7.0-alpha.354

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 (113) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +7 -0
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +240 -7
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -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 +135 -1
  9. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +43 -14
  10. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +17 -2
  12. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +22 -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 +585 -21
  19. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +1 -0
  20. package/docs/ROW_TEMPLATES.md +60 -9
  21. package/docs/SPEC.md +361 -8
  22. package/docs/STYLE_SPEC.md +6 -0
  23. package/ios/HybridNativeList.swift +10 -0
  24. package/ios/NativeListAccessoryStack.swift +220 -37
  25. package/ios/NativeListActivityDetailsView.swift +18 -8
  26. package/ios/NativeListActivityRenderer.swift +8 -2
  27. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  28. package/ios/NativeListDataRowRenderer.swift +105 -8
  29. package/ios/NativeListDesignAssets.swift +3 -0
  30. package/ios/NativeListIdentityRenderer.swift +119 -4
  31. package/ios/NativeListLeadingVisual.swift +49 -14
  32. package/ios/NativeListMessageRenderer.swift +34 -1
  33. package/ios/NativeListModels.swift +16 -2
  34. package/ios/NativeListRendererRegistry.swift +1 -0
  35. package/ios/NativeListResolvedText.swift +2 -1
  36. package/ios/NativeListRowHost.swift +14 -0
  37. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  38. package/ios/RNCNativeListView.swift +331 -29
  39. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  40. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  41. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  42. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  43. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  44. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  45. package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
  46. package/ios/tests/NativeListLifecycleTests.swift +890 -3
  47. package/lib/module/NativeList.js +64 -27
  48. package/lib/module/NativeList.web.js +84 -17
  49. package/lib/module/models.js +1 -0
  50. package/lib/module/selection.js +1 -1
  51. package/lib/module/validation.js +532 -18
  52. package/lib/module/web/NativeListWebEngine.js +391 -24
  53. package/lib/module/web/templates/ActivityRowRenderer.js +8 -7
  54. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  55. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  56. package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
  57. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  58. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  59. package/lib/module/web/templates/RowRendererRegistry.js +3 -0
  60. package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
  61. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
  62. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
  63. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
  64. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
  65. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
  66. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
  67. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
  68. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
  69. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
  70. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
  71. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
  72. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
  73. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
  74. package/lib/typescript/src/NativeList.d.ts +2 -2
  75. package/lib/typescript/src/NativeList.nitro.d.ts +1 -0
  76. package/lib/typescript/src/NativeList.types.d.ts +8 -0
  77. package/lib/typescript/src/models.d.ts +101 -9
  78. package/lib/typescript/src/validation.d.ts +13 -0
  79. package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -0
  80. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  81. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  82. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
  83. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
  84. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
  85. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
  86. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
  87. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
  88. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
  89. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
  90. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
  91. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
  92. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
  93. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
  94. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
  95. package/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
  96. package/package.json +3 -3
  97. package/react-native-native-list.podspec +1 -0
  98. package/src/NativeList.nitro.ts +1 -0
  99. package/src/NativeList.tsx +155 -69
  100. package/src/NativeList.types.ts +9 -0
  101. package/src/NativeList.web.tsx +159 -49
  102. package/src/models.ts +113 -3
  103. package/src/selection.ts +1 -0
  104. package/src/validation.ts +1156 -18
  105. package/src/web/NativeListWebEngine.ts +594 -28
  106. package/src/web/templates/ActivityRowRenderer.ts +14 -6
  107. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  108. package/src/web/templates/DataRowRenderer.ts +93 -20
  109. package/src/web/templates/IdentityRowRenderer.ts +150 -5
  110. package/src/web/templates/MessageRowRenderer.ts +23 -7
  111. package/src/web/templates/RowContainerStyle.ts +2 -0
  112. package/src/web/templates/RowRendererRegistry.ts +11 -1
  113. package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
@@ -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
  }
@@ -541,15 +584,88 @@ function assertVisualShape(shape, path) {
541
584
  function assertTrailingAccessories(accessories, path) {
542
585
  accessories?.forEach((accessory, index) => {
543
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');
544
598
  if (accessory.kind === 'progress' && (accessory.value < 0 || accessory.value > 1)) {
545
599
  fail(`${accessoryPath}.value`, 'must be within 0...1');
546
600
  }
547
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`);
548
604
  assertTextTone(accessory.primaryTone, `${accessoryPath}.primaryTone`);
549
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
+ }
550
622
  }
551
623
  });
552
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
+ }
553
669
  function assertImage(image, path) {
554
670
  if (!image) return;
555
671
  if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
@@ -594,6 +710,9 @@ function assertLeadingVisual(visual, path) {
594
710
  assertText(visual.cornerIcon?.name, `${path}.cornerIcon.name`);
595
711
  // OneKey patch: validate optional selector overlays at the JSON boundary.
596
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');
597
716
  if ((visual.overlays?.length ?? 0) > 2) fail(`${path}.overlays`, 'supports at most two overlays');
598
717
  visual.overlays?.forEach((overlay, index) => {
599
718
  if (!['topLeft', 'bottomRight'].includes(overlay.position)) fail(`${path}.overlays[${index}].position`, 'must be topLeft or bottomRight');
@@ -610,7 +729,11 @@ function assertLeadingVisual(visual, path) {
610
729
  }
611
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');
612
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');
613
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');
614
737
  });
615
738
  if (visual.kind === 'token') {
616
739
  assertImage(visual.networkImage, `${path}.networkImage`);
@@ -624,6 +747,7 @@ function assertVisual(row, path) {
624
747
  });
625
748
  }
626
749
  function assertActivity(row, path) {
750
+ if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean') fail(`${path}.hideLeading`, 'must be boolean');
627
751
  assertText(row.title, `${path}.title`);
628
752
  assertText(row.description, `${path}.description`);
629
753
  if (row.presentation !== undefined && !['stacked', 'table'].includes(row.presentation)) fail(`${path}.presentation`, 'must be stacked or table');
@@ -720,10 +844,26 @@ function assertRow(row, index, path = `rows[${index}]`) {
720
844
  assertWalletGroup(row, path);
721
845
  break;
722
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
+ }
723
856
  if (row.presentation !== undefined && row.presentation !== 'walletSidebar' && row.presentation !== 'accountSelector' && row.presentation !== 'networkSelector') {
724
857
  fail(`${path}.presentation`, 'must be walletSidebar, accountSelector, or networkSelector when provided');
725
858
  }
726
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);
727
867
  assertText(row.subtitle, `${path}.subtitle`);
728
868
  // OneKey patch: selector text segments truncate independently.
729
869
  row.subtitleSegments?.forEach((segment, segmentIndex) => {
@@ -755,10 +895,13 @@ function assertRow(row, index, path = `rows[${index}]`) {
755
895
  assertActivity(row, path);
756
896
  break;
757
897
  case 'message':
898
+ if (row.presentation !== undefined && row.presentation !== 'inlineWarning') {
899
+ fail(`${path}.presentation`, 'must be inlineWarning');
900
+ }
758
901
  assertText(row.title, `${path}.title`);
759
902
  assertText(row.body, `${path}.body`);
760
- if (![1, 2, 3].includes(row.bodyLines ?? 3)) {
761
- 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');
762
905
  }
763
906
  assertImage(row.thumbnail, `${path}.thumbnail`);
764
907
  break;
@@ -769,6 +912,13 @@ function assertRow(row, index, path = `rows[${index}]`) {
769
912
  row.columns.forEach((column, columnIndex) => {
770
913
  assertKey(column.key, `${path}.columns[${columnIndex}].key`);
771
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
+ }
772
922
  assertText(column.secondaryLeadingText, `${path}.columns[${columnIndex}].secondaryLeadingText`);
773
923
  assertText(column.secondaryText, `${path}.columns[${columnIndex}].secondaryText`);
774
924
  assertTextTone(column.secondaryTone, `${path}.columns[${columnIndex}].secondaryTone`);
@@ -776,6 +926,10 @@ function assertRow(row, index, path = `rows[${index}]`) {
776
926
  if ((row.badges?.length ?? 0) > MAX_BADGES) {
777
927
  fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
778
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`);
779
933
  break;
780
934
  case 'market':
781
935
  assertMarketRow(row, path);
@@ -826,6 +980,11 @@ function assertRow(row, index, path = `rows[${index}]`) {
826
980
  assertText(row.title, `${path}.title`);
827
981
  assertText(row.subtitle, `${path}.subtitle`);
828
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`);
829
988
  if (row.valueActionKey !== undefined) {
830
989
  assertKey(row.valueActionKey, `${path}.valueActionKey`);
831
990
  }
@@ -846,6 +1005,9 @@ function assertRow(row, index, path = `rows[${index}]`) {
846
1005
  }
847
1006
  assertTrailingAccessories(row.trailing, `${path}.trailing`);
848
1007
  break;
1008
+ case 'buttonGroup':
1009
+ assertButtonGroup(row, path);
1010
+ break;
849
1011
  case 'system':
850
1012
  const presentation = 'presentation' in row ? row.presentation : undefined;
851
1013
  if (presentation !== undefined && presentation !== 'market') {
@@ -906,10 +1068,18 @@ function assertMediaPreview(value, path) {
906
1068
  fail(`${path}.probeOrder`, 'must contain one or two distinct image/video candidates');
907
1069
  }
908
1070
  }
909
- export function validateSnapshot(snapshot) {
1071
+ function assertSnapshotContract(snapshot) {
1072
+ if (snapshot.structuralTransition) {
1073
+ assertKey(snapshot.structuralTransition.id, 'snapshot.structuralTransition.id');
1074
+ if (snapshot.structuralTransition.anchorKey !== undefined) assertKey(snapshot.structuralTransition.anchorKey, 'snapshot.structuralTransition.anchorKey');
1075
+ const duration = snapshot.structuralTransition.durationMs;
1076
+ if (duration !== undefined && (!Number.isFinite(duration) || duration < 0 || duration > 2000)) fail('snapshot.structuralTransition.durationMs', 'must be finite within 0...2000');
1077
+ }
910
1078
  if (snapshot.capabilities?.refreshTriggerDistance !== undefined && (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) || snapshot.capabilities.refreshTriggerDistance <= 0)) fail('capabilities.refreshTriggerDistance', 'must be a positive finite number');
911
1079
  assertPlainSerializable(snapshot, 'snapshot', new Set());
912
1080
  assertText(snapshot.theme?.imageFallbackBackground, 'theme.imageFallbackBackground');
1081
+ 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');
1082
+ 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');
913
1083
  if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
914
1084
  if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
915
1085
  fail('snapshot.generation', 'must be a non-negative safe integer');
@@ -978,7 +1148,255 @@ export function validateSnapshot(snapshot) {
978
1148
  if (snapshot.selection?.mode === 'single' && selectedKeys.size > 1) {
979
1149
  fail('snapshot.selection.selectedKeys', 'supports at most one key in single mode');
980
1150
  }
981
- return normalizeSnapshotStyles(snapshot);
1151
+ return snapshot;
1152
+ }
1153
+ function protocolObject(value, path) {
1154
+ if (!value || typeof value !== 'object' || Array.isArray(value)) fail(path, 'must be an object');
1155
+ return value;
1156
+ }
1157
+ function protocolKey(value, path) {
1158
+ if (typeof value !== 'string' || value.trim().length === 0) fail(path, 'must be a non-blank string');
1159
+ }
1160
+ 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']);
1161
+ 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']);
1162
+
1163
+ /** Validate only shapes that renderers dereference, not display budgets. */
1164
+ function assertProtocolFields(value, path, parentField = '') {
1165
+ if (value === undefined || value === null || typeof value !== 'object') return;
1166
+ if (Array.isArray(value)) {
1167
+ for (const [index, item] of value.entries()) {
1168
+ const itemPath = `${path}[${index}]`;
1169
+ if (['selectedKeys', 'fallbackUris', 'probeOrder'].includes(parentField)) {
1170
+ if (typeof item !== 'string') fail(itemPath, 'must be a string');
1171
+ } else if (parentField === 'points') {
1172
+ if (typeof item !== 'number') fail(itemPath, 'must be a finite number');
1173
+ } else if (parentField === 'hoverImages' && item === null) continue;else protocolObject(item, itemPath);
1174
+ assertProtocolFields(item, itemPath, parentField);
1175
+ }
1176
+ return;
1177
+ }
1178
+ const object = value;
1179
+ if (parentField === 'fallbackIcon') {
1180
+ protocolKey(object.name, `${path}.name`);
1181
+ 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]');
1182
+ for (const field of ['tintColor', 'backgroundColor']) {
1183
+ const color = object[field];
1184
+ 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');
1185
+ }
1186
+ }
1187
+ if (parentField === 'overlays' && object.fallbackIcon !== undefined && !object.image) fail(`${path}.fallbackIcon`, 'requires image');
1188
+ if (!path.includes('.style.') && ['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(parentField) && typeof object.uri !== 'string') fail(`${path}.uri`, 'must be a string');
1189
+ Object.entries(value).forEach(([field, item]) => {
1190
+ if (item === undefined) return;
1191
+ const fieldPath = `${path}.${field}`;
1192
+ if (!path.endsWith('.style') && PROTOCOL_ARRAY_FIELDS.has(field) && !Array.isArray(item)) fail(fieldPath, 'must be an array');
1193
+ if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number') fail(fieldPath, 'must be a finite number');
1194
+ if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item === 'number' && item < 0 && !['offsetX', 'offsetY'].includes(field)) fail(fieldPath, 'must be non-negative');
1195
+ if (parentField === 'overlays' && field === 'fontWeight' && !['regular', 'medium', 'semibold', 'bold'].includes(item)) fail(fieldPath, 'must be regular, medium, semibold, or bold');
1196
+ if (field === 'buttonStyle' && item !== 'tertiary') fail(fieldPath, 'must be tertiary');
1197
+ if (field === 'hideLeading' && typeof item !== 'boolean') fail(fieldPath, 'must be boolean');
1198
+ if (field === 'key' || field === 'sectionKey' || field === 'actionKey' || field.endsWith('ActionKey')) protocolKey(item, fieldPath);
1199
+ if ((field === 'uri' || field === 'fallbackUri') && typeof item !== 'string') fail(fieldPath, 'must be a string');
1200
+ if (field === 'style' && !(item === 'subscript' && /[Ss]egments\[/.test(path)) || field === 'container') protocolObject(item, fieldPath);
1201
+ 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);
1202
+ assertProtocolFields(item, fieldPath, field);
1203
+ });
1204
+ }
1205
+ function assertRowProtocol(row, path) {
1206
+ protocolObject(row, path);
1207
+ assertRowType(row.type, path);
1208
+ protocolKey(row.key, `${path}.key`);
1209
+ assertProtocolFields(row, path);
1210
+ for (const field of ['leading', 'visual', 'secondaryLeading']) {
1211
+ const visual = row[field];
1212
+ if (visual !== undefined || field === 'leading' && (row.type === 'identity' || row.type === 'market')) {
1213
+ const object = protocolObject(visual, `${path}.${field}`);
1214
+ if (object.kind === 'stackedImages' && !Array.isArray(object.images)) fail(`${path}.${field}.images`, 'must be an array');
1215
+ }
1216
+ }
1217
+ for (const field of ['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'indexTitle']) {
1218
+ const value = row[field];
1219
+ if (value !== undefined && typeof value !== 'string') fail(`${path}.${field}`, 'must be a string');
1220
+ }
1221
+ if (row.height !== undefined && row.height < 0) fail(`${path}.height`, 'must be non-negative');
1222
+ if (row.type === 'identity') {
1223
+ assertIdentityExtras(row, path);
1224
+ if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes)) fail(`${path}.titleSuffixes`, 'must be an array');
1225
+ row.titleSuffixes?.forEach((suffix, index) => {
1226
+ protocolObject(suffix, `${path}.titleSuffixes[${index}]`);
1227
+ if (typeof suffix.text !== 'string' || !['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}]`, 'invalid title suffix');
1228
+ 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');
1229
+ });
1230
+ let end = 0;
1231
+ row.titleMatch?.forEach(match => {
1232
+ 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');
1233
+ end = match.end;
1234
+ });
1235
+ }
1236
+ if (row.type === 'buttonGroup') assertButtonGroup(row, path);
1237
+ if (row.type === 'sectionHeader') assertTextHelp(row.valueHelp, `${path}.valueHelp`);
1238
+ if (row.type === 'mediaTile' && row.media) {
1239
+ protocolObject(row.media.source, `${path}.media.source`);
1240
+ if (!Array.isArray(row.media.probeOrder)) fail(`${path}.media.probeOrder`, 'must be an array');
1241
+ }
1242
+ if (row.type === 'walletGroup') {
1243
+ protocolObject(row.parent, `${path}.parent`);
1244
+ if (!Array.isArray(row.children)) fail(`${path}.children`, 'must be an array');
1245
+ const members = [row.parent, ...row.children];
1246
+ const keys = new Set();
1247
+ if (row.parent.key !== row.key) fail(`${path}.parent.key`, 'must match its group');
1248
+ members.forEach((member, index) => {
1249
+ assertRowProtocol(member, `${path}.members[${index}]`);
1250
+ if (member.type !== 'identity' || keys.has(member.key)) fail(path, 'invalid wallet member identity');
1251
+ keys.add(member.key);
1252
+ });
1253
+ }
1254
+ if (row.type === 'dataRow') {
1255
+ if (!Array.isArray(row.columns)) fail(`${path}.columns`, 'must be an array');
1256
+ row.columns.forEach((column, index) => {
1257
+ const columnPath = `${path}.columns[${index}]`;
1258
+ protocolObject(column, columnPath);
1259
+ assertIdentityExtras(column, columnPath);
1260
+ });
1261
+ assertTrailingAccessories(row.trailing, `${path}.trailing`);
1262
+ }
1263
+ if (row.type === 'market') {
1264
+ protocolObject(row.change, `${path}.change`);
1265
+ if (row.webTable) {
1266
+ const {
1267
+ columns,
1268
+ cells
1269
+ } = row.webTable;
1270
+ if (!Array.isArray(columns) || !Array.isArray(cells) || columns.length !== cells.length) fail(`${path}.webTable`, 'columns and cells must match');
1271
+ const keys = new Set();
1272
+ columns.forEach((column, index) => {
1273
+ protocolKey(column.key, `${path}.webTable.columns[${index}].key`);
1274
+ if (keys.has(column.key) || cells[index]?.key !== column.key) fail(`${path}.webTable`, 'invalid column identity');
1275
+ keys.add(column.key);
1276
+ const cell = cells[index];
1277
+ if (!['favorite', 'asset', 'text', 'sparkline'].includes(cell.kind)) fail(`${path}.webTable.cells[${index}]`, 'unsupported cell kind');
1278
+ if (cell.kind === 'asset') protocolObject(cell.title, `${path}.webTable.cells[${index}].title`);
1279
+ if ((cell.kind === 'asset' || cell.kind === 'text') && cell.secondary !== undefined && !Array.isArray(cell.secondary)) fail(`${path}.webTable.cells[${index}].secondary`, 'must be an array');
1280
+ if (cell.kind === 'text' && !Array.isArray(cell.primary)) fail(`${path}.webTable.cells[${index}].primary`, 'must be an array');
1281
+ // The Web renderer spreads samples into Math.min/Math.max.
1282
+ 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');
1283
+ });
1284
+ }
1285
+ }
1286
+ }
1287
+ function assertSnapshotProtocol(snapshot) {
1288
+ protocolObject(snapshot, 'snapshot');
1289
+ if (snapshot.structuralTransition) {
1290
+ protocolObject(snapshot.structuralTransition, 'snapshot.structuralTransition');
1291
+ protocolKey(snapshot.structuralTransition.id, 'snapshot.structuralTransition.id');
1292
+ if (snapshot.structuralTransition.anchorKey !== undefined) protocolKey(snapshot.structuralTransition.anchorKey, 'snapshot.structuralTransition.anchorKey');
1293
+ const duration = snapshot.structuralTransition.durationMs;
1294
+ if (duration !== undefined && (!Number.isFinite(duration) || duration < 0 || duration > 2000)) fail('snapshot.structuralTransition.durationMs', 'must be finite within 0...2000');
1295
+ }
1296
+ 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');
1297
+ 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');
1298
+ if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
1299
+ if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) fail('snapshot.generation', 'must be a non-negative safe integer');
1300
+ protocolObject(snapshot.layout, 'snapshot.layout');
1301
+ assertProtocolFields(snapshot.layout, 'snapshot.layout');
1302
+ if (snapshot.layout.orientation !== undefined && !['vertical', 'horizontal'].includes(snapshot.layout.orientation)) fail('snapshot.layout.orientation', 'is not supported');
1303
+ if (!['linear', 'sectioned', 'grid', 'table'].includes(snapshot.layout.kind)) fail('snapshot.layout.kind', 'is not supported');
1304
+ if (!Array.isArray(snapshot.rows)) fail('snapshot.rows', 'must be an array');
1305
+ 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');
1306
+ const keys = new Set();
1307
+ for (const [index, row] of snapshot.rows.entries()) {
1308
+ assertRowProtocol(row, `rows[${index}]`);
1309
+ if (keys.has(row.key)) fail(`rows[${index}].key`, 'duplicate row identity');
1310
+ keys.add(row.key);
1311
+ }
1312
+ if (snapshot.emptyState) assertRowProtocol(snapshot.emptyState, 'emptyState');
1313
+ if (snapshot.fixedFooter) assertRowProtocol(snapshot.fixedFooter, 'fixedFooter');
1314
+ if (snapshot.selection) {
1315
+ if (!Array.isArray(snapshot.selection.selectedKeys)) fail('snapshot.selection.selectedKeys', 'must be an array');
1316
+ snapshot.selection.selectedKeys.forEach(key => {
1317
+ if (!keys.has(key)) fail('snapshot.selection.selectedKeys', 'unknown row identity');
1318
+ });
1319
+ }
1320
+ }
1321
+
1322
+ /** Empty optional image descriptors must take the same path as absent images. */
1323
+ function normalizeEmptyImages(value, field = '') {
1324
+ if (!value || typeof value !== 'object') return value;
1325
+ if (Array.isArray(value)) {
1326
+ const next = value.map(item => normalizeEmptyImages(item));
1327
+ const filtered = field === 'images' ? next.filter(item => item !== undefined) : next.map(item => item === undefined ? null : item);
1328
+ return filtered.length === value.length && filtered.every((item, index) => item === value[index]) ? value : filtered;
1329
+ }
1330
+ const object = value;
1331
+ if (typeof object.uri === 'string' && !object.uri.trim() && 'width' in object && 'height' in object) return undefined;
1332
+ let changed = false;
1333
+ const next = {
1334
+ ...object
1335
+ };
1336
+ Object.entries(object).forEach(([key, item]) => {
1337
+ const normalized = normalizeEmptyImages(item, key);
1338
+ if (normalized !== item) {
1339
+ // Omitted JSON patch fields must also be absent from the JS merge.
1340
+ if (field === 'changes' && normalized === undefined) delete next[key];else next[key] = normalized;
1341
+ changed = true;
1342
+ }
1343
+ });
1344
+ if (field === 'media' && next.source === undefined) return undefined;
1345
+ return changed ? next : value;
1346
+ }
1347
+ export function validateSnapshot(snapshot) {
1348
+ assertPlainSerializable(snapshot, 'snapshot', new Set());
1349
+ if (isDevelopment()) assertSnapshotContract(snapshot);
1350
+ const normalized = isDevelopment() ? snapshot : normalizeEmptyImages(snapshot);
1351
+ assertSnapshotProtocol(normalized);
1352
+ return normalizeSnapshotStyles(normalized);
1353
+ }
1354
+ const ownedNativeSnapshots = new WeakMap();
1355
+ function capturePlainData(value, seen = new Map()) {
1356
+ if (value === null || typeof value !== 'object') return value;
1357
+ const previous = seen.get(value);
1358
+ if (previous) return previous;
1359
+ const copy = Array.isArray(value) ? new Array(value.length) : Object.create(Object.getPrototypeOf(value));
1360
+ seen.set(value, copy);
1361
+ const captureKey = key => {
1362
+ Object.defineProperty(copy, key, {
1363
+ value: capturePlainData(value[key], seen),
1364
+ enumerable: true,
1365
+ writable: true,
1366
+ configurable: true
1367
+ });
1368
+ };
1369
+ if (Array.isArray(value)) {
1370
+ for (let index = 0; index < value.length; index += 1) {
1371
+ if (index in value) captureKey(String(index));
1372
+ }
1373
+ Object.keys(value).forEach(key => {
1374
+ const index = Number(key);
1375
+ if (Number.isInteger(index) && index >= 0 && index < value.length && String(index) === key) return;
1376
+ captureKey(key);
1377
+ });
1378
+ } else {
1379
+ Object.keys(value).forEach(captureKey);
1380
+ }
1381
+ return copy;
1382
+ }
1383
+ function deepFreeze(value, seen = new WeakSet()) {
1384
+ if (value === null || typeof value !== 'object' || seen.has(value)) return value;
1385
+ seen.add(value);
1386
+ Object.values(value).forEach(item => deepFreeze(item, seen));
1387
+ return Object.freeze(value);
1388
+ }
1389
+
1390
+ /** Capture caller data once before validation, including accessor values. */
1391
+ export function captureNativeListInput(value) {
1392
+ return capturePlainData(value);
1393
+ }
1394
+
1395
+ /** Private native-wrapper ownership; exported validators keep their public identity. */
1396
+ export function ownValidatedNativeSnapshot(snapshot) {
1397
+ const owned = deepFreeze(snapshot);
1398
+ ownedNativeSnapshots.set(owned, new Map(owned.rows.map((row, index) => [row.key, index])));
1399
+ return owned;
982
1400
  }
983
1401
 
984
1402
  /**
@@ -1024,7 +1442,23 @@ function assertPatchChanges(patch, index) {
1024
1442
  }
1025
1443
  switch (patch.type) {
1026
1444
  case 'identity':
1445
+ if (patch.changes.contentHeight !== undefined && patch.changes.contentHeight !== 'auto') {
1446
+ fail(`${path}.contentHeight`, 'must be auto');
1447
+ }
1448
+ if (patch.changes.subtitleLines !== undefined && ![0, 1, 2].includes(patch.changes.subtitleLines)) {
1449
+ fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
1450
+ }
1451
+ if (patch.changes.longPressActionKey !== undefined) {
1452
+ assertKey(patch.changes.longPressActionKey, `${path}.longPressActionKey`);
1453
+ }
1027
1454
  assertText(patch.changes.title, `${path}.title`);
1455
+ if ((patch.changes.titleSuffixes?.length ?? 0) > 3) fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
1456
+ patch.changes.titleSuffixes?.forEach((suffix, index) => {
1457
+ assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
1458
+ if (!['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}].tone`, 'must be secondary or disabled');
1459
+ 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');
1460
+ });
1461
+ assertIdentityExtras(patch.changes, path);
1028
1462
  assertText(patch.changes.subtitle, `${path}.subtitle`);
1029
1463
  assertText(patch.changes.tertiary, `${path}.tertiary`);
1030
1464
  if (patch.changes.tertiaryTone !== undefined && !['secondary', 'info'].includes(patch.changes.tertiaryTone)) {
@@ -1058,11 +1492,14 @@ function assertPatchChanges(patch, index) {
1058
1492
  }
1059
1493
  break;
1060
1494
  case 'message':
1495
+ if (patch.changes.presentation !== undefined && patch.changes.presentation !== 'inlineWarning') {
1496
+ fail(`${path}.presentation`, 'must be inlineWarning');
1497
+ }
1061
1498
  assertText(patch.changes.title, `${path}.title`);
1062
1499
  assertText(patch.changes.body, `${path}.body`);
1063
1500
  assertText(patch.changes.time, `${path}.time`);
1064
- if (patch.changes.bodyLines !== undefined && ![1, 2, 3].includes(patch.changes.bodyLines)) {
1065
- fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
1501
+ if (patch.changes.bodyLines !== undefined && ![0, 1, 2, 3].includes(patch.changes.bodyLines)) {
1502
+ fail(`${path}.bodyLines`, 'must be 0, 1, 2, or 3');
1066
1503
  }
1067
1504
  assertImage(patch.changes.thumbnail, `${path}.thumbnail`);
1068
1505
  break;
@@ -1073,12 +1510,23 @@ function assertPatchChanges(patch, index) {
1073
1510
  patch.changes.columns?.forEach((column, columnIndex) => {
1074
1511
  assertKey(column.key, `${path}.columns[${columnIndex}].key`);
1075
1512
  assertText(column.text, `${path}.columns[${columnIndex}].text`);
1513
+ assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
1514
+ for (const field of ['textSegments', 'secondaryTextSegments']) {
1515
+ column[field]?.forEach((segment, segmentIndex) => {
1516
+ assertText(segment.text, `${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`);
1517
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`, 'must be subscript');
1518
+ });
1519
+ }
1076
1520
  assertText(column.secondaryText, `${path}.columns[${columnIndex}].secondaryText`);
1077
1521
  assertTextTone(column.secondaryTone, `${path}.columns[${columnIndex}].secondaryTone`);
1078
1522
  });
1079
1523
  if ((patch.changes.badges?.length ?? 0) > MAX_BADGES) {
1080
1524
  fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
1081
1525
  }
1526
+ if ((patch.changes.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
1527
+ fail(`${path}.trailing`, `supports at most ${MAX_TRAILING_ACCESSORIES} accessories`);
1528
+ }
1529
+ assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
1082
1530
  break;
1083
1531
  case 'market':
1084
1532
  assertMarketRow({
@@ -1137,6 +1585,11 @@ function assertPatchChanges(patch, index) {
1137
1585
  assertText(patch.changes.title, `${path}.title`);
1138
1586
  assertText(patch.changes.subtitle, `${path}.subtitle`);
1139
1587
  assertText(patch.changes.value, `${path}.value`);
1588
+ if (patch.changes.leadingBadge) {
1589
+ assertKey(patch.changes.leadingBadge.key, `${path}.leadingBadge.key`);
1590
+ assertText(patch.changes.leadingBadge.text, `${path}.leadingBadge.text`);
1591
+ }
1592
+ assertTextHelp(patch.changes.valueHelp, `${path}.valueHelp`);
1140
1593
  if (patch.changes.valueActionKey !== undefined) {
1141
1594
  assertKey(patch.changes.valueActionKey, `${path}.valueActionKey`);
1142
1595
  }
@@ -1150,6 +1603,11 @@ function assertPatchChanges(patch, index) {
1150
1603
  }
1151
1604
  assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
1152
1605
  break;
1606
+ case 'buttonGroup':
1607
+ if (patch.changes.buttons !== undefined) assertButtonGroup({
1608
+ buttons: patch.changes.buttons
1609
+ }, path);
1610
+ break;
1153
1611
  case 'system':
1154
1612
  assertText(patch.changes.message, `${path}.message`);
1155
1613
  break;
@@ -1159,17 +1617,26 @@ function assertPatchChanges(patch, index) {
1159
1617
  }
1160
1618
  export function validatePatches(patches) {
1161
1619
  assertPlainSerializable(patches, 'patches', new Set());
1620
+ if (!Array.isArray(patches)) fail('patches', 'must be an array');
1162
1621
  const keys = new Set();
1163
- patches.forEach((patch, index) => {
1164
- assertKey(patch.key, `patches[${index}].key`);
1622
+ for (const [index, patch] of patches.entries()) {
1623
+ protocolObject(patch, `patches[${index}]`);
1624
+ protocolKey(patch.key, `patches[${index}].key`);
1165
1625
  if (keys.has(patch.key)) fail(`patches[${index}].key`, `duplicate key "${patch.key}"`);
1166
1626
  keys.add(patch.key);
1627
+ protocolObject(patch.changes, `patches[${index}].changes`);
1628
+ assertRowType(patch.type, `patches[${index}]`);
1629
+ assertProtocolFields(patch.changes, `patches[${index}].changes`);
1630
+ if (patch.type === 'identity') assertIdentityExtras(patch.changes, `patches[${index}].changes`);
1631
+ if (!isDevelopment()) continue;
1632
+ assertKey(patch.key, `patches[${index}].key`);
1167
1633
  if (Object.keys(patch.changes).length === 0) {
1168
1634
  fail(`patches[${index}].changes`, 'must contain at least one field');
1169
1635
  }
1170
1636
  assertPatchChanges(patch, index);
1171
- });
1172
- return normalizePatchStyles(patches);
1637
+ }
1638
+ const normalized = isDevelopment() ? patches : normalizeEmptyImages(patches);
1639
+ return normalizePatchStyles(normalized.filter(patch => Object.keys(patch.changes).length > 0));
1173
1640
  }
1174
1641
 
1175
1642
  /** Patches reach the native side without passing through a snapshot. */
@@ -1192,10 +1659,10 @@ function normalizePatchStyles(patches) {
1192
1659
  return changed ? next : patches;
1193
1660
  }
1194
1661
  export function applyRowPatches(snapshot, patches) {
1195
- validatePatches(patches);
1196
- const patchByKey = new Map(patches.map(patch => [patch.key, patch]));
1662
+ const normalizedPatches = validatePatches(patches);
1663
+ const patchByKey = new Map(normalizedPatches.map(patch => [patch.key, patch]));
1197
1664
  const knownKeys = new Set(snapshot.rows.map(row => row.key));
1198
- patches.forEach(patch => {
1665
+ normalizedPatches.forEach(patch => {
1199
1666
  if (!knownKeys.has(patch.key)) fail('patches', `unknown row key "${patch.key}"`);
1200
1667
  });
1201
1668
  const rows = snapshot.rows.map(row => {
@@ -1217,6 +1684,53 @@ export function applyRowPatches(snapshot, patches) {
1217
1684
  rows
1218
1685
  });
1219
1686
  }
1687
+
1688
+ /** Native wrapper only: preserve full public validation for unsupported patches. */
1689
+ export function applyOwnedNativePatches(snapshot, patches) {
1690
+ const acceptedPatches = deepFreeze(validatePatches(capturePlainData(patches)));
1691
+ const rowIndexes = ownedNativeSnapshots.get(snapshot);
1692
+ const canPatchRows = rowIndexes !== undefined && acceptedPatches.every(patch => {
1693
+ const index = rowIndexes.get(patch.key);
1694
+ if (index === undefined || snapshot.rows[index].type !== patch.type) return false;
1695
+ const allowed = patch.type === 'identity' ? ['subtitle', 'subtitleSegments', 'trailing'] : patch.type === 'dataRow' ? ['columns', 'trailing'] : undefined;
1696
+ return allowed !== undefined && Object.entries(patch.changes).every(([key, value]) => allowed.includes(key) && (value !== undefined || snapshot.rows[index][key] === undefined));
1697
+ });
1698
+ if (!canPatchRows) {
1699
+ const baseline = rowIndexes ? snapshot : capturePlainData(snapshot);
1700
+ return {
1701
+ patches: acceptedPatches,
1702
+ snapshot: ownValidatedNativeSnapshot(applyRowPatches(baseline, acceptedPatches)),
1703
+ json: JSON.stringify(acceptedPatches)
1704
+ };
1705
+ }
1706
+ const nextRows = snapshot.rows.slice();
1707
+ for (const patch of acceptedPatches) {
1708
+ const index = rowIndexes.get(patch.key);
1709
+ const previous = nextRows[index];
1710
+ const merged = {
1711
+ ...previous,
1712
+ ...patch.changes,
1713
+ key: previous.key,
1714
+ type: previous.type
1715
+ };
1716
+ const path = `rows[${index}]`;
1717
+ assertPlainSerializable(merged, path, new Set());
1718
+ if (isDevelopment()) assertRow(merged, index);
1719
+ const normalized = isDevelopment() ? merged : normalizeEmptyImages(merged);
1720
+ assertRowProtocol(normalized, path);
1721
+ nextRows[index] = deepFreeze(normalizeRowStyles(normalized));
1722
+ }
1723
+ const nextSnapshot = Object.freeze({
1724
+ ...snapshot,
1725
+ rows: Object.freeze(nextRows)
1726
+ });
1727
+ ownedNativeSnapshots.set(nextSnapshot, rowIndexes);
1728
+ return {
1729
+ patches: acceptedPatches,
1730
+ snapshot: nextSnapshot,
1731
+ json: JSON.stringify(acceptedPatches)
1732
+ };
1733
+ }
1220
1734
  export function serializeSnapshot(snapshot) {
1221
1735
  return JSON.stringify(validateSnapshot(snapshot));
1222
1736
  }