@onekeyfe/react-native-native-list 3.0.157-alpha.249 → 3.0.157-alpha.251

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,310 @@
1
+ "use strict";
2
+
3
+ import { createElement, setData, markActionAnchorSource } from "./RowElements.js";
4
+ import { applyTextStyleToSlot, applyValueSegments, fontWeight } from "./RowText.js";
5
+ import { RowVisualStyle } from "./RowVisual.js";
6
+ export function resolveWebMarketLayoutStyle(row) {
7
+ const style = row.style;
8
+ const imageWidth = style?.image?.width ?? (row.variant === 'stock' ? 40 : 32);
9
+ const imageHeight = style?.image?.height ?? (row.variant === 'stock' ? 40 : 32);
10
+ return {
11
+ horizontalPadding: style?.horizontalPadding ?? (row.variant === 'perp' ? 16 : 20),
12
+ verticalPadding: style?.verticalPadding ?? 12,
13
+ leadingGap: style?.leadingGap ?? (row.variant === 'perp' ? 8 : 14),
14
+ titleBadgeGap: style?.titleBadgeGap ?? 4,
15
+ trailingGap: style?.trailingGap ?? 8,
16
+ imageWidth,
17
+ imageHeight,
18
+ imageCornerRadius: style?.image?.cornerRadius ?? (style?.image?.shape === 'square' ? 0 : style?.image?.shape === 'rounded' ? 8 : Math.min(imageWidth, imageHeight) / 2),
19
+ changeWidth: style?.changeWidth ?? 80,
20
+ changeHeight: style?.changeHeight ?? 32,
21
+ changeCornerRadius: style?.changeCornerRadius ?? 8
22
+ };
23
+ }
24
+ function applyMarketTextStyle(element, style, defaults) {
25
+ element.style.fontSize = String(style?.fontSize ?? defaults.fontSize) + 'px';
26
+ element.style.lineHeight = String(style?.lineHeight ?? defaults.lineHeight) + 'px';
27
+ element.style.fontWeight = String(fontWeight(style?.fontWeight, defaults.weight));
28
+ element.style.color = style?.color ?? '';
29
+ element.style.textAlign = style?.alignment ?? defaults.alignment;
30
+ element.style.whiteSpace = (style?.lines ?? 1) > 1 ? 'normal' : 'nowrap';
31
+ element.style.display = '';
32
+ element.style.removeProperty('-webkit-line-clamp');
33
+ element.style.removeProperty('-webkit-box-orient');
34
+ if ((style?.lines ?? 1) > 1) {
35
+ element.style.display = '-webkit-box';
36
+ element.style.setProperty('-webkit-line-clamp', String(style?.lines ?? 2));
37
+ element.style.setProperty('-webkit-box-orient', 'vertical');
38
+ }
39
+ }
40
+ export function setMarketQuoteContent(element, row) {
41
+ const style = row.style;
42
+ const layoutStyle = resolveWebMarketLayoutStyle(row);
43
+ const price = element.querySelector('.ok-native-list-market-price');
44
+ if (price) {
45
+ price.textContent = row.price;
46
+ applyMarketTextStyle(price, style?.price, {
47
+ fontSize: 16,
48
+ lineHeight: 24,
49
+ weight: 500,
50
+ alignment: 'end'
51
+ });
52
+ applyValueSegments(price, row.priceSegments, style?.price?.fontSize ?? 16, style?.price?.lineHeight ?? 24, fontWeight(style?.price?.fontWeight, 500));
53
+ }
54
+ const change = element.querySelector('.ok-native-list-market-change');
55
+ if (change) {
56
+ change.textContent = row.change.text;
57
+ setData(change, 'tone', row.change.tone);
58
+ applyMarketTextStyle(change, style?.change, {
59
+ fontSize: 14,
60
+ lineHeight: 20,
61
+ weight: 500,
62
+ alignment: 'center'
63
+ });
64
+ applyValueSegments(change, row.change.textSegments, style?.change?.fontSize ?? 14, style?.change?.lineHeight ?? 20, fontWeight(style?.change?.fontWeight, 500));
65
+ change.style.width = String(layoutStyle.changeWidth) + 'px';
66
+ change.style.height = String(layoutStyle.changeHeight) + 'px';
67
+ change.style.borderRadius = String(layoutStyle.changeCornerRadius) + 'px';
68
+ change.style.color = style?.change?.color ?? row.change.textColor ?? '';
69
+ change.style.background = row.change.backgroundColor ?? '';
70
+ }
71
+ if (price) applyTextStyleToSlot(price, style?.price ?? {}, 1);
72
+ if (change) applyTextStyleToSlot(change, style?.change ?? {}, 1);
73
+ element.setAttribute('aria-label', row.accessibilityLabel ?? [row.title, row.subtitle, row.price, row.change.text].filter(Boolean).join(', '));
74
+ }
75
+ function createMarketRow(document, primitives, row) {
76
+ const body = createElement(document, 'div', 'ok-native-list-row ok-native-list-market');
77
+ setData(body, 'variant', row.variant);
78
+ const style = row.style;
79
+ const layoutStyle = resolveWebMarketLayoutStyle(row);
80
+ body.style.padding = String(layoutStyle.verticalPadding) + 'px ' + String(layoutStyle.horizontalPadding) + 'px';
81
+ body.style.gap = '0px';
82
+ if (row.leadingAction) {
83
+ const action = primitives.iconAction(row.leadingAction.name, row.leadingAction.actionKey, row.leadingAction.disabled, row.leadingAction.tintColor);
84
+ action.style.flex = '0 0 36px';
85
+ action.style.width = '36px';
86
+ action.style.height = '36px';
87
+ action.style.marginRight = '5px';
88
+ setData(action, 'testid', row.leadingAction.testID);
89
+ if (row.leadingAction.accessibilityLabel) action.setAttribute('aria-label', row.leadingAction.accessibilityLabel);
90
+ markActionAnchorSource(action, 'leadingAction');
91
+ body.appendChild(action);
92
+ }
93
+ const visual = primitives.visual(row.leading);
94
+ if (visual) {
95
+ const width = layoutStyle.imageWidth;
96
+ const height = layoutStyle.imageHeight;
97
+ visual.style.width = String(width) + 'px';
98
+ visual.style.height = String(height) + 'px';
99
+ visual.style.flexBasis = String(width) + 'px';
100
+ visual.style.borderRadius = String(layoutStyle.imageCornerRadius) + 'px';
101
+ const borderColor = 'borderColor' in row.leading ? row.leading.borderColor : undefined;
102
+ if (borderColor) {
103
+ visual.style.border = '1px solid ' + borderColor;
104
+ visual.style.boxSizing = 'border-box';
105
+ }
106
+ visual.querySelectorAll('img').forEach(image => {
107
+ if (!image.classList.contains('ok-native-list-visual-corner')) {
108
+ image.style.width = '100%';
109
+ image.style.height = '100%';
110
+ if (borderColor) {
111
+ image.style.borderRadius = '0';
112
+ image.style.clipPath = 'inset(-1px round ' + String(layoutStyle.imageCornerRadius) + 'px)';
113
+ }
114
+ image.style.objectFit = style?.image?.contentFit === 'center' ? 'none' : style?.image?.contentFit ?? image.style.objectFit;
115
+ } else {
116
+ image.style.width = '20px';
117
+ image.style.height = '20px';
118
+ if (borderColor) {
119
+ image.style.right = '-5px';
120
+ image.style.bottom = '-5px';
121
+ }
122
+ }
123
+ });
124
+ visual.style.marginInlineEnd = String(layoutStyle.leadingGap) + 'px';
125
+ body.appendChild(visual);
126
+ }
127
+ const main = createElement(document, 'span', 'ok-native-list-market-main');
128
+ main.style.gap = String(style?.lineGap ?? 0) + 'px';
129
+ const titleLine = createElement(document, 'span', 'ok-native-list-market-title-line');
130
+ titleLine.style.gap = String(layoutStyle.titleBadgeGap) + 'px';
131
+ const title = createElement(document, 'span', 'ok-native-list-market-title', row.title);
132
+ applyMarketTextStyle(title, style?.title, {
133
+ fontSize: 16,
134
+ lineHeight: 24,
135
+ weight: 500,
136
+ alignment: 'start'
137
+ });
138
+ titleLine.appendChild(title);
139
+ row.badges?.forEach((badge, slot) => {
140
+ const element = createElement(document, badge.actionKey ? 'button' : 'span', 'ok-native-list-market-badge', badge.text);
141
+ if (badge.actionKey) {
142
+ element.setAttribute('type', 'button');
143
+ setData(element, 'nativeListAction', badge.actionKey);
144
+ markActionAnchorSource(element, 'marketBadge', slot);
145
+ }
146
+ setData(element, 'tone', badge.tone);
147
+ element.style.color = badge.textColor ?? (badge.tone === 'success' ? 'var(--nl-positive)' : badge.tone === 'danger' ? 'var(--nl-negative)' : badge.tone === 'info' ? 'var(--nl-info)' : badge.tone === 'warning' ? 'var(--nl-primary)' : '');
148
+ element.style.background = badge.backgroundColor ?? ((badge.icon || badge.iconName) && !badge.text ? 'transparent' : '');
149
+ if ((badge.icon || badge.iconName) && !badge.text) {
150
+ element.style.padding = '0';
151
+ }
152
+ if (badge.style) {
153
+ applyTextStyleToSlot(element, badge.style);
154
+ if (badge.style.height !== undefined) element.style.height = `${badge.style.height}px`;
155
+ if (badge.style.horizontalPadding !== undefined && badge.text) element.style.paddingInline = `${badge.style.horizontalPadding}px`;
156
+ }
157
+ if (badge.accessibilityLabel) element.setAttribute('aria-label', badge.accessibilityLabel);
158
+ if (badge.icon) {
159
+ const icon = primitives.thumbnail(badge.icon);
160
+ if (icon) {
161
+ icon.className = '';
162
+ icon.style.borderRadius = '50%';
163
+ element.prepend(icon);
164
+ }
165
+ }
166
+ if (badge.iconName === 'verified') {
167
+ const icon = createElement(document, 'span', 'ok-native-list-market-badge-icon');
168
+ primitives.icon(icon, 'BadgeVerifiedSolid');
169
+ element.prepend(icon);
170
+ }
171
+ titleLine.appendChild(element);
172
+ });
173
+ main.appendChild(titleLine);
174
+ if (row.subtitlePrefix || row.subtitle || row.subtitleSegments?.length) {
175
+ const subtitleLine = createElement(document, 'span', 'ok-native-list-market-subtitle-line');
176
+ subtitleLine.style.display = 'flex';
177
+ subtitleLine.style.alignItems = 'center';
178
+ subtitleLine.style.minWidth = '0';
179
+ subtitleLine.style.overflow = 'hidden';
180
+ subtitleLine.style.gap = String(row.subtitlePrefix ? row.subtitlePrefix.gap ?? 4 : 0) + 'px';
181
+ if (row.subtitlePrefix) {
182
+ const prefix = createElement(document, 'span', 'ok-native-list-market-subtitle-prefix', row.subtitlePrefix.text);
183
+ applyMarketTextStyle(prefix, row.subtitlePrefix.style, {
184
+ fontSize: 12,
185
+ lineHeight: 16,
186
+ weight: 400,
187
+ alignment: 'start'
188
+ });
189
+ prefix.style.display = 'block';
190
+ prefix.style.flex = '1 1 auto';
191
+ prefix.style.minWidth = '0';
192
+ prefix.style.overflow = 'hidden';
193
+ prefix.style.textOverflow = 'ellipsis';
194
+ prefix.style.color = row.subtitlePrefix.style?.color ?? 'var(--nl-secondary)';
195
+ if (row.subtitlePrefix.maxWidth !== undefined) {
196
+ prefix.style.maxWidth = String(row.subtitlePrefix.maxWidth) + 'px';
197
+ }
198
+ subtitleLine.appendChild(prefix);
199
+ }
200
+ if (row.subtitle || row.subtitleSegments?.length) {
201
+ const subtitle = createElement(document, 'span', 'ok-native-list-market-subtitle', row.subtitle);
202
+ applyMarketTextStyle(subtitle, style?.subtitle, {
203
+ fontSize: 14,
204
+ lineHeight: 20,
205
+ weight: 400,
206
+ alignment: 'start'
207
+ });
208
+ applyValueSegments(subtitle, row.subtitleSegments, style?.subtitle?.fontSize ?? 14, style?.subtitle?.lineHeight ?? 20, fontWeight(style?.subtitle?.fontWeight, 400));
209
+ subtitle.style.flex = row.subtitlePrefix ? '0 0 auto' : '1 1 auto';
210
+ subtitleLine.appendChild(subtitle);
211
+ }
212
+ main.appendChild(subtitleLine);
213
+ }
214
+ body.appendChild(main);
215
+ const trailing = createElement(document, 'span', 'ok-native-list-market-trailing');
216
+ trailing.style.gap = String(layoutStyle.trailingGap) + 'px';
217
+ trailing.append(createElement(document, 'span', 'ok-native-list-market-price'), createElement(document, 'span', 'ok-native-list-market-change'));
218
+ body.appendChild(trailing);
219
+ setMarketQuoteContent(body, row);
220
+ for (const key of ['title', 'subtitle']) {
221
+ const text = body.querySelector(`.ok-native-list-market-${key}`);
222
+ if (text) applyTextStyleToSlot(text, style?.[key] ?? {}, 1);
223
+ }
224
+ const prefix = body.querySelector('.ok-native-list-market-subtitle-prefix');
225
+ if (prefix) applyTextStyleToSlot(prefix, row.subtitlePrefix?.style ?? {}, 1);
226
+ return body;
227
+ }
228
+ // A quote payload changes only the quote nodes; full binds retain equal image slots.
229
+
230
+ const views = new WeakMap();
231
+ function bind(body, row, primitives) {
232
+ const v = views.get(body);
233
+ v.primitives = primitives;
234
+ const content = JSON.stringify({
235
+ ...row,
236
+ price: undefined,
237
+ priceSegments: undefined,
238
+ change: undefined,
239
+ accessibilityLabel: undefined
240
+ });
241
+ if (v.content === content) {
242
+ setMarketQuoteContent(body, row);
243
+ return;
244
+ }
245
+ let index = 0;
246
+ function asset(source, createAsset) {
247
+ const slot = index++,
248
+ key = JSON.stringify([row.key, source]);
249
+ let entry = v.assets[slot];
250
+ if (entry?.key !== key) {
251
+ if (entry) primitives.dispose(entry.node);
252
+ const node = createAsset();
253
+ if (!node) return;
254
+ entry = {
255
+ key,
256
+ node,
257
+ defaults: new RowVisualStyle(node)
258
+ };
259
+ v.assets[slot] = entry;
260
+ }
261
+ entry.defaults.restore();
262
+ return entry.node;
263
+ }
264
+ const next = createMarketRow(body.ownerDocument, {
265
+ ...primitives,
266
+ visual: source => asset(source, () => primitives.visual(source)),
267
+ thumbnail: source => asset(source, () => primitives.thumbnail(source))
268
+ }, row);
269
+ v.assets.slice(index).forEach(slot => primitives.dispose(slot.node));
270
+ v.assets.length = index;
271
+ body.replaceChildren(...Array.from(next.childNodes));
272
+ body.className = next.className;
273
+ body.style.cssText = next.style.cssText;
274
+ body.dataset.variant = row.variant;
275
+ body.removeAttribute('data-nl-container-background');
276
+ body.removeAttribute('data-nl-container-border');
277
+ body.setAttribute('aria-label', next.getAttribute('aria-label') ?? '');
278
+ v.content = content;
279
+ }
280
+ function create(document, row, primitives) {
281
+ const body = document.createElement('div');
282
+ body.dataset.nlRenderer = 'market';
283
+ views.set(body, {
284
+ assets: [],
285
+ content: '',
286
+ primitives
287
+ });
288
+ bind(body, row, primitives);
289
+ return body;
290
+ }
291
+ function recycle(body) {
292
+ const v = views.get(body);
293
+ if (!v) return;
294
+ v.assets.forEach(slot => v.primitives.dispose(slot.node));
295
+ v.assets = [];
296
+ v.content = '';
297
+ body.replaceChildren();
298
+ }
299
+ export const marketRowRenderer = {
300
+ key: 'market',
301
+ create,
302
+ bind,
303
+ recycle,
304
+ measure: (row, _width) => {
305
+ const style = resolveWebMarketLayoutStyle(row);
306
+ return Math.max(row.variant === 'stock' ? 72 : 68, style.imageHeight + 2 * style.verticalPadding);
307
+ },
308
+ measureRendered: (_body, _row) => undefined
309
+ };
310
+ //# sourceMappingURL=MarketRowRenderer.js.map
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ const views = new WeakMap();
4
+ function bind(body, row, primitives) {
5
+ const v = views.get(body);
6
+ v.primitives = primitives;
7
+ const style = row.style;
8
+ body.style.cssText = '';
9
+ body.removeAttribute('data-nl-container-background');
10
+ body.removeAttribute('data-nl-container-border');
11
+ if (style?.horizontalPadding !== undefined) body.style.paddingInline = `${style.horizontalPadding}px`;
12
+ if (style?.verticalPadding !== undefined) body.style.paddingBlock = `${style.verticalPadding}px`;
13
+ const text = (node, value, roleStyle) => {
14
+ node.style.cssText = '';
15
+ node.textContent = value;
16
+ if (roleStyle) primitives.textStyle(node, roleStyle);
17
+ };
18
+ text(v.title, row.title, style?.title);
19
+ text(v.subtitle, row.subtitle || '-', style?.subtitle);
20
+ text(v.badge, row.badge?.text ?? '', style?.badge);
21
+ if (row.badge) {
22
+ v.metadata.appendChild(v.badge);
23
+ v.badge.dataset.tone = row.badge.tone ?? '';
24
+ } else v.badge.remove();
25
+ v.metadata.style.cssText = '';
26
+ if (style?.leadingGap !== undefined) v.metadata.style.paddingTop = `${style.leadingGap}px`;
27
+ if (style?.lineGap !== undefined) Object.assign(v.metadata.style, {
28
+ display: 'flex',
29
+ flexDirection: 'column',
30
+ rowGap: `${style.lineGap}px`
31
+ });
32
+ const imageKey = JSON.stringify([row.key, row.image, row.imageState]);
33
+ if (v.imageKey !== imageKey) {
34
+ if (v.image) {
35
+ primitives.dispose(v.image);
36
+ v.image.remove();
37
+ }
38
+ v.image = row.image && !row.imageState ? primitives.thumbnail(row.image) : undefined;
39
+ if (!v.image) {
40
+ v.image = body.ownerDocument.createElement('span');
41
+ v.image.dataset.state = row.imageState ?? 'empty';
42
+ v.image.textContent = row.imageState === 'error' ? '▧' : '';
43
+ }
44
+ v.image.className = 'ok-native-list-media-image';
45
+ body.insertBefore(v.image, v.metadata);
46
+ v.imageKey = imageKey;
47
+ }
48
+ const image = v.image;
49
+ // Only restore geometry; loading opacity is owned by the image primitive.
50
+ ['width', 'height', 'border-radius', 'overflow', 'object-fit'].forEach(key => image.style.removeProperty(key));
51
+ if (style?.image?.width !== undefined) image.style.width = `${style.image.width}px`;
52
+ if (style?.image?.height !== undefined) image.style.height = `${style.image.height}px`;
53
+ const shape = style?.image?.shape;
54
+ const radius = style?.image?.cornerRadius !== undefined ? `${style.image.cornerRadius}px` : shape === 'circle' ? '50%' : shape === 'square' ? '0px' : shape === 'rounded' ? '10px' : undefined;
55
+ if (radius !== undefined) image.style.setProperty('border-radius', radius, 'important');
56
+ const fit = style?.image?.contentFit ?? row.image?.contentFit;
57
+ if (fit) image.style.objectFit = fit === 'center' ? 'none' : fit;
58
+ const networkKey = JSON.stringify([row.key, row.networkImage]);
59
+ if (v.networkKey !== networkKey) {
60
+ if (v.network) {
61
+ primitives.dispose(v.network);
62
+ v.network.remove();
63
+ }
64
+ v.network = row.networkImage ? primitives.thumbnail(row.networkImage) : undefined;
65
+ if (v.network) {
66
+ v.network.className = 'ok-native-list-media-network';
67
+ v.subtitleLine.appendChild(v.network);
68
+ }
69
+ v.networkKey = networkKey;
70
+ }
71
+ if (row.closeActionKey) {
72
+ v.close.dataset.nativeListAction = row.closeActionKey;
73
+ body.appendChild(v.close);
74
+ } else v.close.remove();
75
+ }
76
+ function create(document, row, primitives) {
77
+ const node = (tag, className, slot) => {
78
+ const n = document.createElement(tag);
79
+ n.className = className;
80
+ if (slot) n.dataset.nlSlot = slot;
81
+ return n;
82
+ };
83
+ const body = node('div', 'ok-native-list-row ok-native-list-media');
84
+ body.dataset.nlRenderer = 'mediaTile';
85
+ const metadata = node('div', 'ok-native-list-media-meta');
86
+ const subtitleLine = node('div', 'ok-native-list-media-subtitle-row');
87
+ const title = node('div', 'ok-native-list-media-title', 'title');
88
+ const subtitle = node('span', 'ok-native-list-media-subtitle', 'subtitle');
89
+ const badge = node('span', 'ok-native-list-badge', 'badge');
90
+ const close = node('button', 'ok-native-list-media-close');
91
+ close.type = 'button';
92
+ close.textContent = '×';
93
+ close.setAttribute('aria-label', 'Close');
94
+ close.dataset.nativeListAnchorSource = 'mediaClose';
95
+ subtitleLine.appendChild(subtitle);
96
+ metadata.append(subtitleLine, title);
97
+ body.appendChild(metadata);
98
+ views.set(body, {
99
+ title,
100
+ subtitle,
101
+ badge,
102
+ metadata,
103
+ subtitleLine,
104
+ close,
105
+ primitives,
106
+ imageKey: '',
107
+ networkKey: ''
108
+ });
109
+ bind(body, row, primitives);
110
+ return body;
111
+ }
112
+ function recycle(body) {
113
+ const v = views.get(body);
114
+ if (!v) return;
115
+ [v.image, v.network].forEach(n => {
116
+ if (n) {
117
+ v.primitives.dispose(n);
118
+ n.remove();
119
+ }
120
+ });
121
+ v.image = v.network = undefined;
122
+ v.imageKey = v.networkKey = '';
123
+ }
124
+ export const mediaTileRowRenderer = {
125
+ key: 'mediaTile',
126
+ create,
127
+ bind,
128
+ recycle,
129
+ measure: (_row, _width) => 244,
130
+ measureRendered: (_body, _row) => undefined
131
+ };
132
+ //# sourceMappingURL=MediaTileRowRenderer.js.map
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+
3
+ import { RowVisualStyle } from "./RowVisual.js";
4
+ export function resolveMessageRow(row) {
5
+ const text = (value, style, fontSize, lineHeight, lines, color, fontWeight = 'regular') => ({
6
+ value,
7
+ style: {
8
+ fontSize,
9
+ lineHeight,
10
+ lines,
11
+ color,
12
+ fontWeight,
13
+ alignment: 'start',
14
+ ...style
15
+ }
16
+ });
17
+ return {
18
+ title: text(row.title, row.style?.title, 15, 20, 2, 'var(--nl-primary)', 'semibold'),
19
+ body: text(row.body, row.style?.body, 13, 18, row.bodyLines ?? 3, 'var(--nl-secondary)'),
20
+ time: text(row.time ?? '', row.style?.time, 11, 16, 1, 'var(--nl-secondary)'),
21
+ horizontalPadding: row.style?.horizontalPadding ?? 12,
22
+ verticalPadding: row.style?.verticalPadding ?? 8,
23
+ lineGap: row.style?.lineGap ?? 0,
24
+ leadingGap: row.style?.leadingGap ?? 12,
25
+ imageWidth: row.style?.image?.width ?? (row.leading?.kind === 'stackedImages' ? 48 : 40),
26
+ imageHeight: row.style?.image?.height ?? 40,
27
+ image: row.style?.image,
28
+ automaticHeight: (row.style?.container?.height ?? row.height) === undefined
29
+ };
30
+ }
31
+ const viewsByBody = new WeakMap();
32
+ const identity = (key, source) => JSON.stringify([key, source]);
33
+ export function classifyMessageUpdate(old, row) {
34
+ if (!old || old.key !== row.key) return 'replace';
35
+ if (JSON.stringify(old) === JSON.stringify(row)) return 'unchanged';
36
+ if (identity(row.key, old.leading) !== identity(row.key, row.leading) || identity(row.key, old.thumbnail) !== identity(row.key, row.thumbnail)) return 'assets';
37
+ return 'content';
38
+ }
39
+ export function bindMessageRow(body, row, primitives) {
40
+ const views = viewsByBody.get(body);
41
+ if (!views) throw new Error('Message renderer received an incompatible body');
42
+ const resolved = resolveMessageRow(row);
43
+ views.primitives = primitives;
44
+ const update = classifyMessageUpdate(views.row, row);
45
+ if (update === 'unchanged') return;
46
+ body.style.cssText = '';
47
+ body.removeAttribute('data-nl-container-background');
48
+ body.removeAttribute('data-nl-container-border');
49
+ body.style.padding = `${resolved.verticalPadding}px ${resolved.horizontalPadding}px`;
50
+ body.style.height = resolved.automaticHeight ? 'auto' : '100%';
51
+ views.column.style.cssText = '';
52
+ views.column.style.rowGap = `${resolved.lineGap}px`;
53
+ for (const [view, text] of [[views.title, resolved.title], [views.body, resolved.body], [views.time, resolved.time]]) {
54
+ view.style.cssText = '';
55
+ view.textContent = text.value;
56
+ primitives.textStyle(view, text.style);
57
+ }
58
+ views.unread.style.cssText = '';
59
+ if (row.body) {
60
+ if (!views.body.parentElement) views.column.appendChild(views.body);
61
+ } else views.body.remove();
62
+ if (row.unread) {
63
+ if (!views.unread.parentElement) body.insertBefore(views.unread, views.column);
64
+ } else views.unread.remove();
65
+ const leadingIdentity = identity(row.key, row.leading);
66
+ if (leadingIdentity !== views.leadingIdentity) {
67
+ if (views.leading) {
68
+ primitives.dispose(views.leading);
69
+ views.leading.remove();
70
+ }
71
+ views.leading = primitives.visual(row.leading);
72
+ views.leadingIdentity = leadingIdentity;
73
+ views.visualStyle = undefined;
74
+ if (views.leading) {
75
+ body.insertBefore(views.leading, body.firstChild);
76
+ views.visualStyle = new RowVisualStyle(views.leading);
77
+ }
78
+ }
79
+ views.visualStyle?.apply(resolved.image, resolved.imageWidth, resolved.imageHeight, resolved.leadingGap - 12);
80
+ const thumbnailIdentity = identity(row.key, row.thumbnail);
81
+ if (thumbnailIdentity !== views.thumbnailIdentity) {
82
+ if (views.thumbnail) {
83
+ primitives.dispose(views.thumbnail);
84
+ views.thumbnail.remove();
85
+ }
86
+ views.thumbnail = row.thumbnail ? primitives.thumbnail(row.thumbnail) : undefined;
87
+ views.thumbnailIdentity = thumbnailIdentity;
88
+ if (views.thumbnail) body.appendChild(views.thumbnail);
89
+ }
90
+ if (views.thumbnail) views.thumbnail.style.alignSelf = '';
91
+ views.row = row;
92
+ }
93
+ export function createMessageRow(document, row, primitives) {
94
+ const span = (className, role) => {
95
+ const view = document.createElement('span');
96
+ view.className = className;
97
+ if (role) view.dataset.nlSlot = role;
98
+ return view;
99
+ };
100
+ const body = document.createElement('div');
101
+ body.className = 'ok-native-list-row ok-native-list-standard';
102
+ body.dataset.nlRenderer = 'message';
103
+ const column = span('ok-native-list-flex');
104
+ const title = span('ok-native-list-title', 'title');
105
+ const text = span('ok-native-list-secondary', 'body');
106
+ const time = span('ok-native-list-time', 'time');
107
+ column.append(title, text);
108
+ body.append(column, time);
109
+ viewsByBody.set(body, {
110
+ column,
111
+ title,
112
+ body: text,
113
+ time,
114
+ unread: span('ok-native-list-unread'),
115
+ leadingIdentity: '',
116
+ thumbnailIdentity: '',
117
+ primitives
118
+ });
119
+ bindMessageRow(body, row, primitives);
120
+ return body;
121
+ }
122
+ export function recycleMessageRow(body) {
123
+ const views = viewsByBody.get(body);
124
+ if (!views) return;
125
+ if (views.leading) {
126
+ views.primitives.dispose(views.leading);
127
+ views.leading.remove();
128
+ }
129
+ if (views.thumbnail) {
130
+ views.primitives.dispose(views.thumbnail);
131
+ views.thumbnail.remove();
132
+ }
133
+ views.leading = undefined;
134
+ views.thumbnail = undefined;
135
+ views.row = undefined;
136
+ views.leadingIdentity = '';
137
+ views.thumbnailIdentity = '';
138
+ views.visualStyle = undefined;
139
+ }
140
+ export function measureMessageRow(row, availableWidth) {
141
+ const r = resolveMessageRow(row);
142
+ const estimate = (text, width) => {
143
+ if (!text.value) return 0;
144
+ const value = text.style.lines === 1 ? text.value.replace(/\r\n|[\r\n]/g, ' ') : text.value;
145
+ const lines = value.split(/\r\n|[\r\n]/).reduce((total, line) => total + Math.max(1, Math.ceil(Array.from(line).reduce((sum, char) => sum + (char.charCodeAt(0) > 255 ? text.style.fontSize : text.style.fontSize / 2), 0) / Math.max(1, width))), 0);
146
+ return Math.min(text.style.lines, lines) * text.style.lineHeight;
147
+ };
148
+ const timeWidth = Math.min(availableWidth / 3, Math.max(0, r.time.value.length * r.time.style.fontSize / 2));
149
+ const textWidth = availableWidth - r.horizontalPadding * 2 - (row.leading ? r.imageWidth + r.leadingGap : 0) - (row.thumbnail ? 76 : 0) - (row.unread ? 19 : 0) - timeWidth - 12;
150
+ const columnHeight = estimate(r.title, textWidth) + estimate(r.body, textWidth) + (row.body ? r.lineGap : 0);
151
+ return r.verticalPadding * 2 + Math.max(columnHeight, estimate(r.time, timeWidth), row.leading ? r.imageHeight : 0, row.thumbnail ? 64 : 0);
152
+ }
153
+ export const messageRowRenderer = {
154
+ key: 'message',
155
+ create: createMessageRow,
156
+ bind: bindMessageRow,
157
+ recycle: recycleMessageRow,
158
+ measure: measureMessageRow,
159
+ measureRendered: (body, row) => {
160
+ if (!resolveMessageRow(row).automaticHeight) return undefined;
161
+ const height = body.getBoundingClientRect().height;
162
+ return height > 0 ? Math.max(0, height + (row.size === 'small' ? -8 : row.size === 'large' ? 12 : 0)) : undefined;
163
+ }
164
+ };
165
+ //# sourceMappingURL=MessageRowRenderer.js.map