@onekeyfe/react-native-native-list 3.0.157-alpha.248 → 3.0.157-alpha.250

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 (130) hide show
  1. package/README.md +21 -5
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +711 -0
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActionRenderer.kt +169 -0
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +243 -0
  5. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +20 -6
  6. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +487 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +820 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListImageSlot.kt +147 -0
  9. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +453 -0
  10. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +997 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +234 -0
  12. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +232 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListMetricCardRenderer.kt +551 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +24 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +475 -0
  16. package/android/src/main/java/com/onekey/nativelist/NativeListRailRenderer.kt +143 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +42 -0
  18. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +415 -0
  19. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +163 -0
  20. package/android/src/main/java/com/onekey/nativelist/NativeListRowHost.kt +70 -0
  21. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +748 -0
  22. package/android/src/main/java/com/onekey/nativelist/NativeListSystemRenderer.kt +464 -0
  23. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +25 -0
  24. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +174 -104
  25. package/android/src/main/java/com/onekey/nativelist/NativeListWalletGroupRenderer.kt +407 -0
  26. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListSelectorBackgroundColorTest.kt +34 -0
  27. package/docs/DESIGN.md +518 -9
  28. package/docs/MIGRATION_BASELINE.md +117 -0
  29. package/docs/ROW_TEMPLATES.md +359 -0
  30. package/docs/SPEC.md +358 -0
  31. package/docs/STYLE_SPEC.md +978 -0
  32. package/docs/images/list-capabilities.svg +39 -0
  33. package/docs/images/row-action.svg +17 -0
  34. package/docs/images/row-activity.svg +24 -0
  35. package/docs/images/row-data.svg +24 -0
  36. package/docs/images/row-identity.svg +25 -0
  37. package/docs/images/row-market.svg +23 -0
  38. package/docs/images/row-media-tile.svg +26 -0
  39. package/docs/images/row-message.svg +20 -0
  40. package/docs/images/row-metric-card.svg +33 -0
  41. package/docs/images/row-rail.svg +18 -0
  42. package/docs/images/row-section-header.svg +19 -0
  43. package/docs/images/row-style-regions.svg +30 -0
  44. package/docs/images/row-system.svg +30 -0
  45. package/docs/images/row-wallet-group.svg +26 -0
  46. package/ios/NativeListAccessoryStack.swift +680 -0
  47. package/ios/NativeListActionRenderer.swift +108 -0
  48. package/ios/NativeListActivityRenderer.swift +179 -0
  49. package/ios/NativeListDataRowRenderer.swift +444 -0
  50. package/ios/NativeListIdentityRenderer.swift +685 -0
  51. package/ios/NativeListImageSlot.swift +140 -0
  52. package/ios/NativeListLeadingVisual.swift +372 -0
  53. package/ios/NativeListMarketRenderer.swift +698 -0
  54. package/ios/NativeListMediaTileRenderer.swift +184 -0
  55. package/ios/NativeListMessageRenderer.swift +168 -0
  56. package/ios/NativeListMetricCardRenderer.swift +420 -0
  57. package/ios/NativeListModels.swift +32 -0
  58. package/ios/NativeListRailRenderer.swift +152 -0
  59. package/ios/NativeListRendererCell.swift +311 -0
  60. package/ios/NativeListRendererRegistry.swift +50 -0
  61. package/ios/NativeListResolvedText.swift +122 -0
  62. package/ios/NativeListRowHost.swift +63 -0
  63. package/ios/NativeListSectionHeaderRenderer.swift +708 -0
  64. package/ios/NativeListSystemRenderer.swift +568 -0
  65. package/ios/NativeListTextLabel.swift +42 -0
  66. package/ios/NativeListTextStyles.swift +236 -0
  67. package/ios/NativeListWalletGroupRenderer.swift +255 -0
  68. package/ios/RNCNativeListView.swift +111 -180
  69. package/lib/module/models.js +54 -0
  70. package/lib/module/validation.js +324 -26
  71. package/lib/module/web/NativeListWebEngine.js +148 -936
  72. package/lib/module/web/templates/ActionRowRenderer.js +97 -0
  73. package/lib/module/web/templates/ActivityRowRenderer.js +95 -0
  74. package/lib/module/web/templates/DataRowRenderer.js +145 -0
  75. package/lib/module/web/templates/IdentityRowRenderer.js +289 -0
  76. package/lib/module/web/templates/MarketRowRenderer.js +310 -0
  77. package/lib/module/web/templates/MediaTileRowRenderer.js +132 -0
  78. package/lib/module/web/templates/MessageRowRenderer.js +165 -0
  79. package/lib/module/web/templates/MetricCardRowRenderer.js +172 -0
  80. package/lib/module/web/templates/RailRowRenderer.js +98 -0
  81. package/lib/module/web/templates/RowContainerStyle.js +100 -0
  82. package/lib/module/web/templates/RowElements.js +93 -0
  83. package/lib/module/web/templates/RowRendererRegistry.js +70 -0
  84. package/lib/module/web/templates/RowText.js +121 -0
  85. package/lib/module/web/templates/RowVisual.js +43 -0
  86. package/lib/module/web/templates/SectionHeaderRowRenderer.js +146 -0
  87. package/lib/module/web/templates/SystemRowRenderer.js +161 -0
  88. package/lib/module/web/templates/WalletGroupRowRenderer.js +96 -0
  89. package/lib/typescript/src/models.d.ts +166 -13
  90. package/lib/typescript/src/web/NativeListWebEngine.d.ts +18 -16
  91. package/lib/typescript/src/web/templates/ActionRowRenderer.d.ts +15 -0
  92. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +15 -0
  93. package/lib/typescript/src/web/templates/DataRowRenderer.d.ts +15 -0
  94. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +16 -0
  95. package/lib/typescript/src/web/templates/MarketRowRenderer.d.ts +30 -0
  96. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +15 -0
  97. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +44 -0
  98. package/lib/typescript/src/web/templates/MetricCardRowRenderer.d.ts +15 -0
  99. package/lib/typescript/src/web/templates/RailRowRenderer.d.ts +28 -0
  100. package/lib/typescript/src/web/templates/RowContainerStyle.d.ts +9 -0
  101. package/lib/typescript/src/web/templates/RowElements.d.ts +38 -0
  102. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +83 -0
  103. package/lib/typescript/src/web/templates/RowText.d.ts +9 -0
  104. package/lib/typescript/src/web/templates/RowVisual.d.ts +20 -0
  105. package/lib/typescript/src/web/templates/SectionHeaderRowRenderer.d.ts +15 -0
  106. package/lib/typescript/src/web/templates/SystemRowRenderer.d.ts +16 -0
  107. package/lib/typescript/src/web/templates/WalletGroupRowRenderer.d.ts +20 -0
  108. package/package.json +3 -3
  109. package/src/models.ts +281 -19
  110. package/src/validation.ts +501 -46
  111. package/src/web/NativeListWebEngine.ts +361 -1932
  112. package/src/web/templates/ActionRowRenderer.ts +123 -0
  113. package/src/web/templates/ActivityRowRenderer.ts +159 -0
  114. package/src/web/templates/DataRowRenderer.ts +212 -0
  115. package/src/web/templates/IdentityRowRenderer.ts +527 -0
  116. package/src/web/templates/MarketRowRenderer.ts +467 -0
  117. package/src/web/templates/MediaTileRowRenderer.ts +182 -0
  118. package/src/web/templates/MessageRowRenderer.ts +306 -0
  119. package/src/web/templates/MetricCardRowRenderer.ts +337 -0
  120. package/src/web/templates/RailRowRenderer.ts +136 -0
  121. package/src/web/templates/RowContainerStyle.ts +131 -0
  122. package/src/web/templates/RowElements.ts +160 -0
  123. package/src/web/templates/RowRendererRegistry.ts +111 -0
  124. package/src/web/templates/RowText.ts +181 -0
  125. package/src/web/templates/RowVisual.ts +115 -0
  126. package/src/web/templates/SectionHeaderRowRenderer.ts +243 -0
  127. package/src/web/templates/SystemRowRenderer.ts +282 -0
  128. package/src/web/templates/WalletGroupRowRenderer.ts +131 -0
  129. package/android/src/main/java/com/onekey/nativelist/NativeListRowView.kt +0 -4538
  130. package/ios/NativeListCell.swift +0 -4300
@@ -0,0 +1,527 @@
1
+ import { applyTabularNumbers, hasExplicitRowHeight } from './RowElements';
2
+ import type {
3
+ IdentityRow,
4
+ NativeListTextStyle,
5
+ RowBoxStyle,
6
+ TrailingAccessory,
7
+ TextTone,
8
+ } from '../../models';
9
+ import {
10
+ createElement,
11
+ setData,
12
+ tagSlot,
13
+ markActionAnchorSource,
14
+ createTextColumn,
15
+ createBadge,
16
+ } from './RowElements';
17
+ import {
18
+ applyTextLayout,
19
+ applyTextStyleToSlot,
20
+ applyValueSegments,
21
+ } from './RowText';
22
+ import { RowVisualStyle, type RowPrimitives } from './RowVisual';
23
+ function toneColor(
24
+ tone: TextTone | undefined,
25
+ fallback: 'primary' | 'secondary'
26
+ ): string {
27
+ if (tone === 'positive') return 'var(--nl-positive)';
28
+ if (tone === 'negative') return 'var(--nl-negative)';
29
+ if (tone === 'secondary') return 'var(--nl-secondary)';
30
+ return fallback === 'secondary' ? 'var(--nl-secondary)' : 'var(--nl-primary)';
31
+ }
32
+ function appendAccessories(
33
+ parent: HTMLElement,
34
+ document: Document,
35
+ primitives: RowPrimitives,
36
+ row: IdentityRow,
37
+ accessories: readonly TrailingAccessory[] | undefined
38
+ ) {
39
+ if (!accessories?.length) return;
40
+ const container = createElement(
41
+ document,
42
+ 'span',
43
+ 'ok-native-list-accessories'
44
+ );
45
+
46
+ if (
47
+ row &&
48
+ hasExplicitRowHeight(row) &&
49
+ 'presentation' in row &&
50
+ row.presentation === 'networkSelector'
51
+ ) {
52
+ container.style.gap = accessories.some(
53
+ (accessory) => accessory.kind === 'checkbox'
54
+ )
55
+ ? '12px'
56
+ : '20px';
57
+ }
58
+ if (
59
+ row &&
60
+ hasExplicitRowHeight(row) &&
61
+ 'presentation' in row &&
62
+ row.presentation === 'accountSelector' &&
63
+ accessories.length === 1 &&
64
+ accessories[0]?.kind === 'icon' &&
65
+ accessories[0].name === 'PlusSmallOutline'
66
+ ) {
67
+ setData(container, 'nativeListAccountControl', 'createAddress');
68
+ }
69
+ let valueIndex = 0;
70
+ accessories.forEach((accessory, slot) => {
71
+ const element = primitives.accessory(row.key, accessory, slot);
72
+ if (accessory.kind === 'value' || accessory.kind === 'valuePair') {
73
+ tagSlot(element, valueIndex++ === 0 ? 'value' : 'valueSecondary');
74
+ }
75
+ container.appendChild(element);
76
+ });
77
+ parent.appendChild(container);
78
+ }
79
+ function createIdentityRow(
80
+ document: Document,
81
+ primitives: RowPrimitives,
82
+ row: IdentityRow
83
+ ): HTMLElement {
84
+ const presentation = row.presentation;
85
+ const body = createElement(
86
+ document,
87
+ 'div',
88
+ [
89
+ 'ok-native-list-row',
90
+ 'ok-native-list-standard',
91
+ !presentation ? 'ok-native-list-identity-row' : '',
92
+ presentation === 'networkSelector' ? 'ok-native-list-network-row' : '',
93
+ presentation === 'walletSidebar' ? 'ok-native-list-wallet-row' : '',
94
+ presentation === 'accountSelector' ? 'ok-native-list-account-row' : '',
95
+ ]
96
+ .filter(Boolean)
97
+ .join(' ')
98
+ );
99
+ setData(
100
+ body,
101
+ 'nativeListSelector',
102
+ hasExplicitRowHeight(row) ? presentation : undefined
103
+ );
104
+ if (row.titleActionKey && row.titleActionOnHover) {
105
+ setData(body, 'nativeListHoverAction', row.titleActionKey);
106
+ markActionAnchorSource(body, 'leadingAction');
107
+ }
108
+ if (row.leadingAction) {
109
+ const action = primitives.iconAction(
110
+ row.leadingAction.name,
111
+ row.leadingAction.actionKey,
112
+ row.leadingAction.disabled,
113
+ row.leadingAction.tintColor
114
+ );
115
+ markActionAnchorSource(action, 'leadingAction');
116
+ body.appendChild(action);
117
+ }
118
+ const visual = primitives.visual(
119
+ row.leading,
120
+ hasExplicitRowHeight(row) ? presentation : undefined
121
+ );
122
+ if (
123
+ visual &&
124
+ true &&
125
+ hasExplicitRowHeight(row) &&
126
+ row.presentation === 'walletSidebar' &&
127
+ 'fallbackIcon' in row.leading &&
128
+ row.leading.fallbackIcon?.name === 'LockSolid'
129
+ ) {
130
+ // OneKey patch: hidden-wallet locks use WalletAvatar's full 40-point icon.
131
+ const icon = visual.querySelector<SVGElement>(
132
+ '.ok-native-list-visual-fallback svg'
133
+ );
134
+ if (icon) {
135
+ icon.style.width = '40px';
136
+ icon.style.height = '40px';
137
+ }
138
+ const fallback = visual.querySelector<HTMLElement>(
139
+ '.ok-native-list-visual-fallback'
140
+ );
141
+ if (fallback) {
142
+ fallback.style.borderRadius = '0';
143
+ fallback.style.overflow = 'visible';
144
+ }
145
+ }
146
+ if (
147
+ visual &&
148
+ true &&
149
+ hasExplicitRowHeight(row) &&
150
+ row.presentation === 'walletSidebar' &&
151
+ 'borderStyle' in row.leading &&
152
+ row.leading.borderStyle === 'dashed'
153
+ )
154
+ visual.style.borderWidth = '1px';
155
+ if (visual) body.appendChild(visual);
156
+ const title = row.title;
157
+ const subtitle = row.subtitle;
158
+ const column = createTextColumn(
159
+ document,
160
+ title,
161
+ subtitle,
162
+ row.tertiary,
163
+ row.tertiaryTone,
164
+ presentation !== 'walletSidebar' ? row.badges : undefined,
165
+ {
166
+ title: 'title',
167
+ subtitle: 'subtitle',
168
+ tertiary: 'tertiary',
169
+ }
170
+ );
171
+ {
172
+ const titleElement = column.firstElementChild as HTMLElement;
173
+ if (row.titleMatch?.length) {
174
+ const textTarget =
175
+ titleElement.querySelector<HTMLElement>('[data-nl-slot="title"]') ??
176
+ titleElement;
177
+ const firstText = textTarget.firstChild;
178
+ if (firstText) firstText.remove();
179
+ const fragment = document.createDocumentFragment();
180
+ let offset = 0;
181
+ row.titleMatch.forEach(({ start, end }) => {
182
+ fragment.appendChild(
183
+ document.createTextNode(row.title.slice(offset, start))
184
+ );
185
+ const match = createElement(
186
+ document,
187
+ 'span',
188
+ 'ok-native-list-info',
189
+ row.title.slice(start, end)
190
+ );
191
+ fragment.appendChild(match);
192
+ offset = end;
193
+ });
194
+ fragment.appendChild(document.createTextNode(row.title.slice(offset)));
195
+ textTarget.prepend(fragment);
196
+ }
197
+ if (row.subtitleSegments?.length) {
198
+ column.querySelector('.ok-native-list-secondary')?.remove();
199
+ const segments = createElement(
200
+ document,
201
+ 'span',
202
+ 'ok-native-list-subtitle-segments'
203
+ );
204
+ row.subtitleSegments.forEach((segment) => {
205
+ if (segment.separatorBefore)
206
+ segments.appendChild(
207
+ createElement(document, 'span', 'ok-native-list-subtitle-dot')
208
+ );
209
+ const text = createElement(
210
+ document,
211
+ 'span',
212
+ 'ok-native-list-secondary',
213
+ segment.text
214
+ );
215
+ tagSlot(text, 'subtitle');
216
+ applyValueSegments(text, segment.textSegments, 14, 20, 400);
217
+ setData(text, 'tone', segment.tone);
218
+ text.style.color =
219
+ segment.tone === 'disabled'
220
+ ? 'var(--nl-disabled)'
221
+ : segment.tone === 'caution'
222
+ ? 'var(--nl-caution)'
223
+ : toneColor(segment.tone, 'secondary');
224
+ segments.appendChild(text);
225
+ });
226
+ column.insertBefore(segments, titleElement.nextSibling);
227
+ }
228
+ if (presentation === 'walletSidebar' && row.badges?.length) {
229
+ const badges = createElement(
230
+ document,
231
+ 'span',
232
+ 'ok-native-list-wallet-badges'
233
+ );
234
+ row.badges.forEach((badge) =>
235
+ badges.appendChild(createBadge(document, badge))
236
+ );
237
+ column.appendChild(badges);
238
+ }
239
+ for (const key of ['title', 'subtitle'] as const) {
240
+ const lines = row.style?.[key]?.lines ?? row[`${key}Lines`];
241
+ if (lines !== undefined)
242
+ column
243
+ .querySelectorAll<HTMLElement>(`[data-nl-slot="${key}"]`)
244
+ .forEach((text) => applyTextLayout(text, { lines }));
245
+ }
246
+ }
247
+ body.appendChild(column);
248
+ appendAccessories(body, document, primitives, row, row.trailing);
249
+ return body;
250
+ }
251
+ const ROW_BOX_STYLE_KEYS: ReadonlySet<string> = new Set([
252
+ 'container',
253
+ 'horizontalPadding',
254
+ 'verticalPadding',
255
+ 'leadingGap',
256
+ 'lineGap',
257
+ 'titleBadgeGap',
258
+ 'trailingGap',
259
+ 'image',
260
+ ]);
261
+ function applyIdentityStyle(body: HTMLElement, row: IdentityRow) {
262
+ const style = (row as { style?: Record<string, unknown> }).style;
263
+ if (!style) return;
264
+ const box = style as RowBoxStyle;
265
+ if (box.horizontalPadding !== undefined)
266
+ body.style.paddingInline = String(box.horizontalPadding) + 'px';
267
+ if (box.verticalPadding !== undefined)
268
+ body.style.paddingBlock = String(box.verticalPadding) + 'px';
269
+ const vertical =
270
+ row.type === 'identity' && row.presentation === 'walletSidebar';
271
+ const leading = body.querySelector<HTMLElement>(
272
+ ':scope > .ok-native-list-visual, :scope > .ok-native-list-stacked'
273
+ );
274
+ const defaultGap =
275
+ body.style.gap ||
276
+ (row.type === 'identity' && row.presentation === 'walletSidebar'
277
+ ? '4px'
278
+ : row.type === 'identity' && row.presentation === 'accountSelector'
279
+ ? '8px'
280
+ : '12px');
281
+ if (box.lineGap !== undefined) {
282
+ const targets = body.querySelectorAll<HTMLElement>(
283
+ ':scope > .ok-native-list-flex'
284
+ );
285
+ targets.forEach((column) => {
286
+ column.style.rowGap = String(box.lineGap) + 'px';
287
+ });
288
+ }
289
+ if (leading && box.leadingGap !== undefined) {
290
+ const gap = 'calc(' + String(box.leadingGap) + 'px - ' + defaultGap + ')';
291
+ if (vertical) leading.style.marginBottom = gap;
292
+ else leading.style.marginInlineEnd = gap;
293
+ }
294
+ if (box.titleBadgeGap !== undefined) {
295
+ const gap = String(box.titleBadgeGap) + 'px';
296
+ body
297
+ .querySelectorAll<HTMLElement>(
298
+ '.ok-native-list-badges, .ok-native-list-wallet-badges'
299
+ )
300
+ .forEach((badges) => {
301
+ if (badges.classList.contains('ok-native-list-wallet-badges'))
302
+ badges.style.marginTop =
303
+ box.lineGap === undefined
304
+ ? gap
305
+ : 'calc(' + gap + ' - ' + String(box.lineGap) + 'px)';
306
+ else badges.style.marginInlineStart = gap;
307
+ });
308
+ }
309
+ if (box.trailingGap !== undefined) {
310
+ const gap = String(box.trailingGap) + 'px';
311
+ body
312
+ .querySelectorAll<HTMLElement>(
313
+ '.ok-native-list-accessories, .ok-native-list-amounts'
314
+ )
315
+ .forEach((trailing) => {
316
+ trailing.style.gap = gap;
317
+ });
318
+ }
319
+ if (leading && box.image) {
320
+ const image = box.image;
321
+ if (image.width !== undefined) {
322
+ leading.style.width = String(image.width) + 'px';
323
+ if (!vertical) leading.style.flexBasis = String(image.width) + 'px';
324
+ }
325
+ if (image.height !== undefined)
326
+ leading.style.height = String(image.height) + 'px';
327
+ const radius =
328
+ image.cornerRadius !== undefined
329
+ ? String(image.cornerRadius) + 'px'
330
+ : image.shape === 'circle'
331
+ ? '50%'
332
+ : image.shape === 'square'
333
+ ? '0px'
334
+ : image.shape === 'rounded'
335
+ ? '10px'
336
+ : undefined;
337
+ if (radius !== undefined) {
338
+ leading.style.setProperty('border-radius', radius, 'important');
339
+ // Clip the bitmap itself; decorations may extend beyond the visual slot.
340
+ leading.style.overflow = leading.matches('img') ? 'hidden' : 'visible';
341
+ }
342
+ const images = leading.matches('img')
343
+ ? [leading]
344
+ : leading.querySelectorAll<HTMLElement>(
345
+ ':scope > img, :scope > .ok-native-list-visual-fallback'
346
+ );
347
+ images.forEach((bitmap) => {
348
+ if (bitmap !== leading) {
349
+ if (image.width !== undefined) bitmap.style.width = '100%';
350
+ if (image.height !== undefined) bitmap.style.height = '100%';
351
+ }
352
+ if (radius !== undefined) bitmap.style.borderRadius = radius;
353
+ if (image.contentFit !== undefined)
354
+ bitmap.style.objectFit =
355
+ image.contentFit === 'center' ? 'none' : image.contentFit;
356
+ });
357
+ }
358
+ Object.keys(style).forEach((key) => {
359
+ if (ROW_BOX_STYLE_KEYS.has(key)) return;
360
+ const slotStyle = style[key] as NativeListTextStyle | undefined;
361
+ if (!slotStyle) return;
362
+ body
363
+ .querySelectorAll<HTMLElement>('[data-nl-slot="' + key + '"]')
364
+ .forEach((element) => {
365
+ applyTextStyleToSlot(element, slotStyle);
366
+ });
367
+ });
368
+ }
369
+ type Views = {
370
+ visual?: {
371
+ key: string;
372
+ node: HTMLElement;
373
+ defaults: RowVisualStyle;
374
+ };
375
+ primitives: RowPrimitives;
376
+ };
377
+ const views = new WeakMap<HTMLElement, Views>();
378
+ function bind(body: HTMLElement, row: IdentityRow, primitives: RowPrimitives) {
379
+ const v = views.get(body)!;
380
+ v.primitives = primitives;
381
+ let used = false;
382
+ const next = createIdentityRow(
383
+ body.ownerDocument,
384
+ {
385
+ ...primitives,
386
+ visual: (source, presentation) => {
387
+ used = true;
388
+ const key = JSON.stringify([row.key, source, presentation]);
389
+ if (v.visual?.key !== key) {
390
+ if (v.visual) primitives.dispose(v.visual.node);
391
+ const node = primitives.visual(source, presentation);
392
+ if (!node) {
393
+ v.visual = undefined;
394
+ return;
395
+ }
396
+ v.visual = {
397
+ key,
398
+ node,
399
+ defaults: new RowVisualStyle(node),
400
+ };
401
+ }
402
+ v.visual.defaults.restore();
403
+ return v.visual.node;
404
+ },
405
+ },
406
+ row
407
+ );
408
+ if (!used && v.visual) {
409
+ primitives.dispose(v.visual.node);
410
+ v.visual = undefined;
411
+ }
412
+ body.replaceChildren(...Array.from(next.childNodes));
413
+ body.className = next.className;
414
+ body.style.cssText = next.style.cssText;
415
+ if (
416
+ row.presentation &&
417
+ ['accountSelector', 'networkSelector', 'walletSidebar'].includes(
418
+ row.presentation
419
+ )
420
+ )
421
+ applyTabularNumbers(body);
422
+ for (const name of body.getAttributeNames())
423
+ if (name.startsWith('data-') && name !== 'data-nl-renderer')
424
+ body.removeAttribute(name);
425
+ for (const name of next.getAttributeNames())
426
+ if (name.startsWith('data-'))
427
+ body.setAttribute(name, next.getAttribute(name)!);
428
+ if (row.type === 'identity' && hasExplicitRowHeight(row)) {
429
+ const title = body.querySelector<HTMLElement>('.ok-native-list-title');
430
+ if (row.presentation === 'accountSelector') {
431
+ body.style.gap = '12px';
432
+ body.style.borderRadius = '12px';
433
+ if ('shape' in row.leading && row.leading.shape === 'rounded') {
434
+ const visual = body.querySelector<HTMLElement>(
435
+ '.ok-native-list-visual'
436
+ );
437
+ if (visual) visual.style.borderRadius = '8px';
438
+ }
439
+ if (title) title.style.lineHeight = '24px';
440
+ }
441
+ if (row.presentation === 'networkSelector') {
442
+ body.style.borderRadius = '12px';
443
+ const visual = body.querySelector<HTMLElement>('.ok-native-list-visual');
444
+ if (visual) {
445
+ visual.style.width = '32px';
446
+ visual.style.height = '32px';
447
+ visual.style.flexBasis = '32px';
448
+ }
449
+ if (
450
+ row.leading.kind === 'network' &&
451
+ !row.leading.image &&
452
+ !row.leading.fallbackIcon &&
453
+ row.leading.fallbackText
454
+ ) {
455
+ const fallback = visual?.querySelector<HTMLElement>(
456
+ '.ok-native-list-visual-fallback'
457
+ );
458
+ if (fallback) {
459
+ fallback.style.fontSize = '19px';
460
+ fallback.style.lineHeight = '27px';
461
+ fallback.style.fontWeight = '600';
462
+ fallback.style.color = 'var(--nl-inverse-text)';
463
+ }
464
+ }
465
+ visual
466
+ ?.querySelectorAll<HTMLElement>('.ok-native-list-visual-main')
467
+ .forEach((image) => {
468
+ image.style.width = '32px';
469
+ image.style.height = '32px';
470
+ });
471
+ if (title) {
472
+ title.style.fontSize = '16px';
473
+ title.style.lineHeight = '24px';
474
+ title.style.fontWeight = '500';
475
+ }
476
+ body
477
+ .querySelectorAll<HTMLElement>('.ok-native-list-accessory')
478
+ .forEach((value) => {
479
+ value.style.fontSize = '16px';
480
+ value.style.lineHeight = '24px';
481
+ value.style.fontWeight = '500';
482
+ });
483
+ }
484
+ }
485
+
486
+ applyIdentityStyle(body, row);
487
+ }
488
+ function create(
489
+ document: Document,
490
+ row: IdentityRow,
491
+ primitives: RowPrimitives
492
+ ) {
493
+ const body = document.createElement('div');
494
+ body.dataset.nlRenderer = 'identity';
495
+ views.set(body, { primitives });
496
+ bind(body, row, primitives);
497
+ return body;
498
+ }
499
+ function recycle(body: HTMLElement) {
500
+ const v = views.get(body);
501
+ if (v?.visual) v.primitives.dispose(v.visual.node);
502
+ if (v) v.visual = undefined;
503
+ body.replaceChildren();
504
+ }
505
+ export const identityRowRenderer = {
506
+ key: 'identity' as const,
507
+ create,
508
+ bind,
509
+ recycle,
510
+ appliesSizePreset: (row: IdentityRow) => !row.presentation,
511
+ measure: (row: IdentityRow, _width: number) =>
512
+ row.presentation === 'walletSidebar'
513
+ ? 68 + (row.badges?.length ? 24 : 0)
514
+ : row.presentation === 'networkSelector'
515
+ ? 47
516
+ : row.presentation === 'accountSelector'
517
+ ? 58
518
+ : row.tertiary
519
+ ? 72
520
+ : row.subtitle
521
+ ? 60
522
+ : 56,
523
+ measureRendered: (
524
+ _body: HTMLElement,
525
+ _row: IdentityRow
526
+ ): number | undefined => undefined,
527
+ };