@teamofsilicons/silicon-ui 0.0.0-stage → 0.2.0

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 (354) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +81 -2
  3. package/check.mjs +236 -0
  4. package/components/accordion/accordion.d.ts +13 -0
  5. package/components/accordion/accordion.js +35 -0
  6. package/components/accordion/accordion.module.css +15 -0
  7. package/components/action-button/action-button.d.ts +11 -0
  8. package/components/action-button/action-button.js +57 -0
  9. package/components/action-button/action-button.module.css +15 -0
  10. package/components/activity-heatmap/activity-heatmap.d.ts +37 -0
  11. package/components/activity-heatmap/activity-heatmap.js +303 -0
  12. package/components/activity-heatmap/activity-heatmap.module.css +83 -0
  13. package/components/alert/alert.d.ts +13 -0
  14. package/components/alert/alert.js +79 -0
  15. package/components/alert/alert.module.css +15 -0
  16. package/components/animated-counter/animated-counter.d.ts +13 -0
  17. package/components/animated-counter/animated-counter.js +73 -0
  18. package/components/animated-counter/animated-counter.module.css +12 -0
  19. package/components/announcement-bar/announcement-bar.d.ts +53 -0
  20. package/components/announcement-bar/announcement-bar.js +187 -0
  21. package/components/announcement-bar/announcement-bar.module.css +60 -0
  22. package/components/avatar/avatar.d.ts +8 -0
  23. package/components/avatar/avatar.js +18 -0
  24. package/components/avatar/avatar.module.css +60 -0
  25. package/components/avatar-group/avatar-group.d.ts +13 -0
  26. package/components/avatar-group/avatar-group.js +24 -0
  27. package/components/avatar-group/avatar-group.module.css +27 -0
  28. package/components/badge/badge.d.ts +10 -0
  29. package/components/badge/badge.js +66 -0
  30. package/components/badge/badge.module.css +52 -0
  31. package/components/bar-chart/bar-chart.d.ts +32 -0
  32. package/components/bar-chart/bar-chart.js +327 -0
  33. package/components/bar-chart/bar-chart.module.css +49 -0
  34. package/components/billing-toggle/billing-toggle.d.ts +35 -0
  35. package/components/billing-toggle/billing-toggle.js +83 -0
  36. package/components/billing-toggle/billing-toggle.module.css +139 -0
  37. package/components/bottom-sheet/bottom-sheet.d.ts +27 -0
  38. package/components/bottom-sheet/bottom-sheet.js +386 -0
  39. package/components/bottom-sheet/bottom-sheet.module.css +69 -0
  40. package/components/breadcrumb/breadcrumb.d.ts +13 -0
  41. package/components/breadcrumb/breadcrumb.js +19 -0
  42. package/components/breadcrumb/breadcrumb.module.css +12 -0
  43. package/components/brush-chart/brush-chart.d.ts +45 -0
  44. package/components/brush-chart/brush-chart.js +426 -0
  45. package/components/brush-chart/brush-chart.module.css +69 -0
  46. package/components/button/button.d.ts +10 -0
  47. package/components/button/button.js +97 -0
  48. package/components/button/button.module.css +39 -0
  49. package/components/button-group/button-group.d.ts +59 -0
  50. package/components/button-group/button-group.js +280 -0
  51. package/components/button-group/button-group.module.css +87 -0
  52. package/components/button-link/button-link.d.ts +24 -0
  53. package/components/button-link/button-link.js +11 -0
  54. package/components/button-link/button-link.module.css +7 -0
  55. package/components/calendar/calendar.d.ts +22 -0
  56. package/components/calendar/calendar.js +253 -0
  57. package/components/calendar/calendar.module.css +51 -0
  58. package/components/card/card.d.ts +19 -0
  59. package/components/card/card.js +108 -0
  60. package/components/card/card.module.css +51 -0
  61. package/components/card-stack/card-stack.d.ts +34 -0
  62. package/components/card-stack/card-stack.js +291 -0
  63. package/components/card-stack/card-stack.module.css +63 -0
  64. package/components/carousel/carousel.d.ts +28 -0
  65. package/components/carousel/carousel.js +332 -0
  66. package/components/carousel/carousel.module.css +42 -0
  67. package/components/chat-thread/chat-thread.d.ts +135 -0
  68. package/components/chat-thread/chat-thread.js +406 -0
  69. package/components/chat-thread/chat-thread.module.css +242 -0
  70. package/components/checkbox/checkbox.d.ts +7 -0
  71. package/components/checkbox/checkbox.js +23 -0
  72. package/components/checkbox/checkbox.module.css +15 -0
  73. package/components/chip-group/chip-group.d.ts +24 -0
  74. package/components/chip-group/chip-group.js +196 -0
  75. package/components/chip-group/chip-group.module.css +38 -0
  76. package/components/code-block/code-block.d.ts +11 -0
  77. package/components/code-block/code-block.js +133 -0
  78. package/components/code-block/code-block.module.css +43 -0
  79. package/components/color-picker/color-picker.d.ts +40 -0
  80. package/components/color-picker/color-picker.js +449 -0
  81. package/components/color-picker/color-picker.module.css +111 -0
  82. package/components/combobox/combobox.d.ts +19 -0
  83. package/components/combobox/combobox.js +167 -0
  84. package/components/combobox/combobox.module.css +28 -0
  85. package/components/command-palette/command-palette.d.ts +20 -0
  86. package/components/command-palette/command-palette.js +151 -0
  87. package/components/command-palette/command-palette.module.css +94 -0
  88. package/components/comment-thread/comment-thread.d.ts +120 -0
  89. package/components/comment-thread/comment-thread.js +343 -0
  90. package/components/comment-thread/comment-thread.module.css +195 -0
  91. package/components/confirm-morph/confirm-morph.d.ts +65 -0
  92. package/components/confirm-morph/confirm-morph.js +355 -0
  93. package/components/confirm-morph/confirm-morph.module.css +146 -0
  94. package/components/context-menu/context-menu.d.ts +18 -0
  95. package/components/context-menu/context-menu.js +148 -0
  96. package/components/context-menu/context-menu.module.css +17 -0
  97. package/components/copy-button/copy-button.d.ts +10 -0
  98. package/components/copy-button/copy-button.js +69 -0
  99. package/components/copy-button/copy-button.module.css +21 -0
  100. package/components/countdown/countdown.d.ts +31 -0
  101. package/components/countdown/countdown.js +177 -0
  102. package/components/countdown/countdown.module.css +49 -0
  103. package/components/date-picker/date-picker.d.ts +17 -0
  104. package/components/date-picker/date-picker.js +100 -0
  105. package/components/date-picker/date-picker.module.css +34 -0
  106. package/components/date-range-picker/date-range-picker.d.ts +44 -0
  107. package/components/date-range-picker/date-range-picker.js +534 -0
  108. package/components/date-range-picker/date-range-picker.module.css +214 -0
  109. package/components/dialog/dialog.d.ts +11 -0
  110. package/components/dialog/dialog.js +52 -0
  111. package/components/dialog/dialog.module.css +36 -0
  112. package/components/donut-chart/donut-chart.d.ts +46 -0
  113. package/components/donut-chart/donut-chart.js +382 -0
  114. package/components/donut-chart/donut-chart.module.css +48 -0
  115. package/components/drawer/drawer.d.ts +20 -0
  116. package/components/drawer/drawer.js +111 -0
  117. package/components/drawer/drawer.module.css +97 -0
  118. package/components/dropdown-menu/dropdown-menu.d.ts +16 -0
  119. package/components/dropdown-menu/dropdown-menu.js +39 -0
  120. package/components/dropdown-menu/dropdown-menu.module.css +38 -0
  121. package/components/elastic-slider/elastic-slider.d.ts +39 -0
  122. package/components/elastic-slider/elastic-slider.js +261 -0
  123. package/components/elastic-slider/elastic-slider.module.css +40 -0
  124. package/components/empty-state/empty-state.d.ts +12 -0
  125. package/components/empty-state/empty-state.js +69 -0
  126. package/components/empty-state/empty-state.module.css +13 -0
  127. package/components/expandable-card/expandable-card.d.ts +13 -0
  128. package/components/expandable-card/expandable-card.js +89 -0
  129. package/components/expandable-card/expandable-card.module.css +22 -0
  130. package/components/expanding-button-group/expanding-button-group.d.ts +41 -0
  131. package/components/expanding-button-group/expanding-button-group.js +258 -0
  132. package/components/expanding-button-group/expanding-button-group.module.css +44 -0
  133. package/components/expanding-search/expanding-search.d.ts +38 -0
  134. package/components/expanding-search/expanding-search.js +242 -0
  135. package/components/expanding-search/expanding-search.module.css +52 -0
  136. package/components/file-dropzone/file-dropzone.d.ts +44 -0
  137. package/components/file-dropzone/file-dropzone.js +379 -0
  138. package/components/file-dropzone/file-dropzone.module.css +115 -0
  139. package/components/file-upload/file-upload.d.ts +22 -0
  140. package/components/file-upload/file-upload.js +192 -0
  141. package/components/file-upload/file-upload.module.css +49 -0
  142. package/components/filter-toolbar/filter-toolbar.d.ts +48 -0
  143. package/components/filter-toolbar/filter-toolbar.js +446 -0
  144. package/components/filter-toolbar/filter-toolbar.module.css +70 -0
  145. package/components/floating-button-group/floating-button-group.d.ts +51 -0
  146. package/components/floating-button-group/floating-button-group.js +215 -0
  147. package/components/floating-button-group/floating-button-group.module.css +74 -0
  148. package/components/gauge/gauge.d.ts +18 -0
  149. package/components/gauge/gauge.js +101 -0
  150. package/components/gauge/gauge.module.css +22 -0
  151. package/components/hold-to-confirm/hold-to-confirm.d.ts +25 -0
  152. package/components/hold-to-confirm/hold-to-confirm.js +165 -0
  153. package/components/hold-to-confirm/hold-to-confirm.module.css +20 -0
  154. package/components/hover-card/hover-card.d.ts +38 -0
  155. package/components/hover-card/hover-card.js +145 -0
  156. package/components/hover-card/hover-card.module.css +20 -0
  157. package/components/image-compare/image-compare.d.ts +27 -0
  158. package/components/image-compare/image-compare.js +267 -0
  159. package/components/image-compare/image-compare.module.css +25 -0
  160. package/components/in-view-title/in-view-title.d.ts +17 -0
  161. package/components/in-view-title/in-view-title.js +70 -0
  162. package/components/in-view-title/in-view-title.module.css +13 -0
  163. package/components/inline-edit/inline-edit.d.ts +27 -0
  164. package/components/inline-edit/inline-edit.js +315 -0
  165. package/components/inline-edit/inline-edit.module.css +73 -0
  166. package/components/input/input.d.ts +7 -0
  167. package/components/input/input.js +60 -0
  168. package/components/input/input.module.css +22 -0
  169. package/components/json-viewer/json-viewer.d.ts +48 -0
  170. package/components/json-viewer/json-viewer.js +463 -0
  171. package/components/json-viewer/json-viewer.module.css +92 -0
  172. package/components/line-chart/line-chart.d.ts +58 -0
  173. package/components/line-chart/line-chart.js +383 -0
  174. package/components/line-chart/line-chart.module.css +60 -0
  175. package/components/mention-input/mention-input.d.ts +72 -0
  176. package/components/mention-input/mention-input.js +417 -0
  177. package/components/mention-input/mention-input.module.css +134 -0
  178. package/components/metric-card/metric-card.d.ts +8 -0
  179. package/components/metric-card/metric-card.js +44 -0
  180. package/components/metric-card/metric-card.module.css +18 -0
  181. package/components/money-input/money-input.d.ts +48 -0
  182. package/components/money-input/money-input.js +503 -0
  183. package/components/money-input/money-input.module.css +77 -0
  184. package/components/morph-select/morph-select.d.ts +50 -0
  185. package/components/morph-select/morph-select.js +395 -0
  186. package/components/morph-select/morph-select.module.css +88 -0
  187. package/components/multi-select/multi-select.d.ts +18 -0
  188. package/components/multi-select/multi-select.js +105 -0
  189. package/components/multi-select/multi-select.module.css +37 -0
  190. package/components/notification-center/notification-center.d.ts +24 -0
  191. package/components/notification-center/notification-center.js +146 -0
  192. package/components/notification-center/notification-center.module.css +79 -0
  193. package/components/number-field/number-field.d.ts +41 -0
  194. package/components/number-field/number-field.js +455 -0
  195. package/components/number-field/number-field.module.css +71 -0
  196. package/components/otp-input/otp-input.d.ts +13 -0
  197. package/components/otp-input/otp-input.js +129 -0
  198. package/components/otp-input/otp-input.module.css +28 -0
  199. package/components/pagination/pagination.d.ts +7 -0
  200. package/components/pagination/pagination.js +60 -0
  201. package/components/pagination/pagination.module.css +16 -0
  202. package/components/password-field/password-field.d.ts +14 -0
  203. package/components/password-field/password-field.js +51 -0
  204. package/components/password-field/password-field.module.css +27 -0
  205. package/components/password-strength/password-strength.d.ts +107 -0
  206. package/components/password-strength/password-strength.js +161 -0
  207. package/components/password-strength/password-strength.module.css +57 -0
  208. package/components/phone-input/phone-input.d.ts +73 -0
  209. package/components/phone-input/phone-input.js +612 -0
  210. package/components/phone-input/phone-input.module.css +98 -0
  211. package/components/popover/popover.d.ts +6 -0
  212. package/components/popover/popover.js +19 -0
  213. package/components/popover/popover.module.css +32 -0
  214. package/components/progress/progress.d.ts +8 -0
  215. package/components/progress/progress.js +42 -0
  216. package/components/progress/progress.module.css +1 -0
  217. package/components/radio-cards/radio-cards.d.ts +35 -0
  218. package/components/radio-cards/radio-cards.js +110 -0
  219. package/components/radio-cards/radio-cards.module.css +84 -0
  220. package/components/radio-group/radio-group.d.ts +13 -0
  221. package/components/radio-group/radio-group.js +55 -0
  222. package/components/radio-group/radio-group.module.css +30 -0
  223. package/components/resizable-panels/resizable-panels.d.ts +37 -0
  224. package/components/resizable-panels/resizable-panels.js +338 -0
  225. package/components/resizable-panels/resizable-panels.module.css +40 -0
  226. package/components/rich-text-editor/rich-text-editor.d.ts +55 -0
  227. package/components/rich-text-editor/rich-text-editor.js +1733 -0
  228. package/components/rich-text-editor/rich-text-editor.module.css +201 -0
  229. package/components/ridgeline/ridgeline.d.ts +37 -0
  230. package/components/ridgeline/ridgeline.js +346 -0
  231. package/components/ridgeline/ridgeline.module.css +58 -0
  232. package/components/scroll-area/scroll-area.d.ts +40 -0
  233. package/components/scroll-area/scroll-area.js +153 -0
  234. package/components/scroll-area/scroll-area.module.css +79 -0
  235. package/components/search-field/search-field.d.ts +7 -0
  236. package/components/search-field/search-field.js +20 -0
  237. package/components/search-field/search-field.module.css +17 -0
  238. package/components/segmented-control/segmented-control.d.ts +16 -0
  239. package/components/segmented-control/segmented-control.js +56 -0
  240. package/components/segmented-control/segmented-control.module.css +15 -0
  241. package/components/select/select.d.ts +15 -0
  242. package/components/select/select.js +36 -0
  243. package/components/select/select.module.css +35 -0
  244. package/components/shortcut-recorder/shortcut-recorder.d.ts +108 -0
  245. package/components/shortcut-recorder/shortcut-recorder.js +380 -0
  246. package/components/shortcut-recorder/shortcut-recorder.module.css +85 -0
  247. package/components/signature-pad/signature-pad.d.ts +72 -0
  248. package/components/signature-pad/signature-pad.js +450 -0
  249. package/components/signature-pad/signature-pad.module.css +84 -0
  250. package/components/skeleton/skeleton.d.ts +13 -0
  251. package/components/skeleton/skeleton.js +53 -0
  252. package/components/skeleton/skeleton.module.css +11 -0
  253. package/components/slider/slider.d.ts +45 -0
  254. package/components/slider/slider.js +347 -0
  255. package/components/slider/slider.module.css +45 -0
  256. package/components/slope-chart/slope-chart.d.ts +38 -0
  257. package/components/slope-chart/slope-chart.js +183 -0
  258. package/components/slope-chart/slope-chart.module.css +51 -0
  259. package/components/slot-text/slot-text.d.ts +26 -0
  260. package/components/slot-text/slot-text.js +119 -0
  261. package/components/slot-text/slot-text.module.css +19 -0
  262. package/components/sortable-data-table/sortable-data-table.d.ts +38 -0
  263. package/components/sortable-data-table/sortable-data-table.js +240 -0
  264. package/components/sortable-data-table/sortable-data-table.module.css +116 -0
  265. package/components/sparkline/sparkline.d.ts +19 -0
  266. package/components/sparkline/sparkline.js +239 -0
  267. package/components/sparkline/sparkline.module.css +26 -0
  268. package/components/split-button/split-button.d.ts +19 -0
  269. package/components/split-button/split-button.js +33 -0
  270. package/components/split-button/split-button.module.css +51 -0
  271. package/components/stepper/stepper.d.ts +36 -0
  272. package/components/stepper/stepper.js +108 -0
  273. package/components/stepper/stepper.module.css +74 -0
  274. package/components/streamgraph/streamgraph.d.ts +51 -0
  275. package/components/streamgraph/streamgraph.js +376 -0
  276. package/components/streamgraph/streamgraph.module.css +55 -0
  277. package/components/swipe-actions/swipe-actions.d.ts +35 -0
  278. package/components/swipe-actions/swipe-actions.js +330 -0
  279. package/components/swipe-actions/swipe-actions.module.css +64 -0
  280. package/components/switch/switch.d.ts +7 -0
  281. package/components/switch/switch.js +45 -0
  282. package/components/switch/switch.module.css +12 -0
  283. package/components/tabs/tabs.d.ts +8 -0
  284. package/components/tabs/tabs.js +138 -0
  285. package/components/tabs/tabs.module.css +27 -0
  286. package/components/tag-input/tag-input.d.ts +15 -0
  287. package/components/tag-input/tag-input.js +150 -0
  288. package/components/tag-input/tag-input.module.css +34 -0
  289. package/components/text-morph/text-morph.d.ts +13 -0
  290. package/components/text-morph/text-morph.js +69 -0
  291. package/components/text-morph/text-morph.module.css +8 -0
  292. package/components/text-reveal/text-reveal.d.ts +14 -0
  293. package/components/text-reveal/text-reveal.js +20 -0
  294. package/components/text-reveal/text-reveal.module.css +13 -0
  295. package/components/text-shimmer/text-shimmer.d.ts +18 -0
  296. package/components/text-shimmer/text-shimmer.js +90 -0
  297. package/components/text-shimmer/text-shimmer.module.css +9 -0
  298. package/components/textarea/textarea.d.ts +7 -0
  299. package/components/textarea/textarea.js +56 -0
  300. package/components/textarea/textarea.module.css +22 -0
  301. package/components/theme-switch/theme-switch.d.ts +11 -0
  302. package/components/theme-switch/theme-switch.js +37 -0
  303. package/components/theme-switch/theme-switch.module.css +31 -0
  304. package/components/time-picker/time-picker.d.ts +13 -0
  305. package/components/time-picker/time-picker.js +95 -0
  306. package/components/time-picker/time-picker.module.css +23 -0
  307. package/components/timeline/timeline.d.ts +47 -0
  308. package/components/timeline/timeline.js +171 -0
  309. package/components/timeline/timeline.module.css +51 -0
  310. package/components/toast/toast.d.ts +8 -0
  311. package/components/toast/toast.js +118 -0
  312. package/components/toast/toast.module.css +100 -0
  313. package/components/toast-stack/toast-stack.d.ts +57 -0
  314. package/components/toast-stack/toast-stack.js +399 -0
  315. package/components/toast-stack/toast-stack.module.css +61 -0
  316. package/components/tooltip/tooltip.d.ts +8 -0
  317. package/components/tooltip/tooltip.js +62 -0
  318. package/components/tooltip/tooltip.module.css +18 -0
  319. package/components/tree-view/tree-view.d.ts +17 -0
  320. package/components/tree-view/tree-view.js +147 -0
  321. package/components/tree-view/tree-view.module.css +22 -0
  322. package/components/treemap/treemap.d.ts +35 -0
  323. package/components/treemap/treemap.js +375 -0
  324. package/components/treemap/treemap.module.css +59 -0
  325. package/components/usage-meter/usage-meter.d.ts +24 -0
  326. package/components/usage-meter/usage-meter.js +296 -0
  327. package/components/usage-meter/usage-meter.module.css +61 -0
  328. package/components/user-menu/user-menu.d.ts +62 -0
  329. package/components/user-menu/user-menu.js +316 -0
  330. package/components/user-menu/user-menu.module.css +97 -0
  331. package/components/waffle-chart/waffle-chart.d.ts +39 -0
  332. package/components/waffle-chart/waffle-chart.js +244 -0
  333. package/components/waffle-chart/waffle-chart.module.css +52 -0
  334. package/components.json +1330 -0
  335. package/eslint.js +53 -0
  336. package/lib/escape.d.ts +19 -0
  337. package/lib/escape.js +50 -0
  338. package/lib/media.d.ts +353 -0
  339. package/lib/media.js +65 -0
  340. package/lib/menu-highlight.d.ts +28 -0
  341. package/lib/menu-highlight.js +43 -0
  342. package/lib/motion-tokens.d.ts +60 -0
  343. package/lib/motion-tokens.js +25 -0
  344. package/lib/return-focus.d.ts +9 -0
  345. package/lib/return-focus.js +53 -0
  346. package/lib/silicon-provider.d.ts +60 -0
  347. package/lib/silicon-provider.js +47 -0
  348. package/lib/use-copy-feedback.d.ts +8 -0
  349. package/lib/use-copy-feedback.js +36 -0
  350. package/lib/use-today.d.ts +2 -0
  351. package/lib/use-today.js +29 -0
  352. package/package.json +76 -4
  353. package/styles.css +218 -0
  354. package/styles.css.d.ts +1 -0
@@ -0,0 +1,48 @@
1
+ export type JsonValueType = "object" | "array" | "string" | "number" | "boolean" | "null" | "other";
2
+ export interface JsonViewerCopyDetail {
3
+ kind: "value" | "path";
4
+ path: string;
5
+ text: string;
6
+ }
7
+ /**
8
+ * A collapsible tree for JSON. Values are colored by type, branches unfold row by row, search highlights every match and
9
+ * opens the branches that hold them, long arrays and objects load in pages, and each row can copy its value or path.
10
+ * The tree follows the WAI-ARIA tree pattern: arrows move and open, Home and End jump, Enter toggles, and the modifier
11
+ * key with C copies the focused value.
12
+ */
13
+ export interface JsonViewerProps {
14
+ data: unknown;
15
+ /** Name of the root in paths, as in `root.users[0].name`. Defaults to "root". */
16
+ rootName?: string;
17
+ /** Levels open on first render when `defaultExpanded` is not set. Defaults to 1, which opens the root. */
18
+ defaultExpandDepth?: number;
19
+ /** Paths of open branches. */
20
+ expanded?: string[];
21
+ defaultExpanded?: string[];
22
+ onExpandedChange?: (paths: string[]) => void;
23
+ /** Show the search field. Defaults to true. */
24
+ searchable?: boolean;
25
+ query?: string;
26
+ defaultQuery?: string;
27
+ onQueryChange?: (query: string) => void;
28
+ /** Children shown per page in a long array or object. Defaults to 50. */
29
+ pageSize?: number;
30
+ /** Show copy value and copy path actions. Defaults to true. */
31
+ copyable?: boolean;
32
+ onCopy?: (detail: JsonViewerCopyDetail) => void;
33
+ /** Called when a row becomes the current one. */
34
+ onSelect?: (detail: {
35
+ path: string;
36
+ value: unknown;
37
+ type: JsonValueType;
38
+ }) => void;
39
+ /** Show the path of the current row under the tree. Defaults to true. */
40
+ showPath?: boolean;
41
+ /** Height of the scrolling tree area. Defaults to 420px. */
42
+ maxHeight?: number | string;
43
+ /** Accessible name of the tree. */
44
+ label?: string;
45
+ className?: string;
46
+ }
47
+ export declare const JsonViewer: import("react").ForwardRefExoticComponent<JsonViewerProps & import("react").RefAttributes<HTMLDivElement>>;
48
+ export default JsonViewer;
@@ -0,0 +1,463 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
4
+ import { AnimatePresence, LayoutGroup, animate, motion, useReducedMotion } from "motion/react";
5
+ import { Check, ChevronDown, ChevronRight, ChevronUp, ChevronsDownUp, ChevronsUpDown, Copy, Link2, Search, X } from "lucide-react";
6
+ import { motionTokens } from "../../lib/motion-tokens.js";
7
+ import styles from "./json-viewer.module.css";
8
+ const ROW = 30;
9
+ const IDENT = /^[A-Za-z_$][\w$]*$/;
10
+ function typeOf(value) {
11
+ if (value === null)
12
+ return "null";
13
+ if (Array.isArray(value))
14
+ return "array";
15
+ switch (typeof value) {
16
+ case "object": return "object";
17
+ case "string": return "string";
18
+ case "number":
19
+ case "bigint": return "number";
20
+ case "boolean": return "boolean";
21
+ default: return "other";
22
+ }
23
+ }
24
+ const isBranch = (type) => type === "object" || type === "array";
25
+ function entries(value) {
26
+ if (Array.isArray(value))
27
+ return value.map((item, index) => [index, item]);
28
+ if (value && typeof value === "object")
29
+ return Object.entries(value);
30
+ return [];
31
+ }
32
+ const childPath = (parent, key) => typeof key === "number" ? `${parent}[${key}]` : IDENT.test(key) ? `${parent}.${key}` : `${parent}[${JSON.stringify(key)}]`;
33
+ const within = (ancestor, id) => id === ancestor || id.startsWith(`${ancestor}.`) || id.startsWith(`${ancestor}[`);
34
+ function primitiveText(value, type) {
35
+ if (type === "string")
36
+ return value;
37
+ if (type === "null")
38
+ return "null";
39
+ return String(value);
40
+ }
41
+ function copyText(value, type) {
42
+ if (type === "string")
43
+ return value;
44
+ if (isBranch(type))
45
+ return JSON.stringify(value, null, 2);
46
+ return primitiveText(value, type);
47
+ }
48
+ const plural = (count, one, many) => `${count} ${count === 1 ? one : many}`;
49
+ const countLabel = (row) => row.type === "array" ? plural(row.count, "item", "items") : plural(row.count, "key", "keys");
50
+ /** Every container path, for expand all. */
51
+ function allBranches(data, rootName) {
52
+ const out = [];
53
+ const visit = (value, id) => {
54
+ if (!isBranch(typeOf(value)))
55
+ return;
56
+ out.push(id);
57
+ for (const [key, child] of entries(value))
58
+ visit(child, childPath(id, key));
59
+ };
60
+ visit(data, rootName);
61
+ return out;
62
+ }
63
+ function branchesToDepth(data, rootName, depth) {
64
+ const out = [];
65
+ const visit = (value, id, level) => {
66
+ if (level >= depth || !isBranch(typeOf(value)))
67
+ return;
68
+ out.push(id);
69
+ for (const [key, child] of entries(value))
70
+ visit(child, childPath(id, key), level + 1);
71
+ };
72
+ visit(data, rootName, 0);
73
+ return out;
74
+ }
75
+ /** Finds keys and primitive values that contain the query, the branches that hold them, and how far each page must reach. */
76
+ function searchJson(data, rootName, needle) {
77
+ const matches = [];
78
+ const ancestors = new Set();
79
+ const needed = new Map();
80
+ const frames = [];
81
+ const visit = (value, id, name) => {
82
+ if (matches.length >= 2000)
83
+ return;
84
+ const type = typeOf(value);
85
+ const keyHit = typeof name === "string" && name.toLowerCase().includes(needle);
86
+ const valueHit = !isBranch(type) && primitiveText(value, type).toLowerCase().includes(needle);
87
+ if (keyHit || valueHit) {
88
+ matches.push(id);
89
+ for (const [frame, index] of frames) {
90
+ ancestors.add(frame);
91
+ needed.set(frame, Math.max(needed.get(frame) ?? 0, index + 1));
92
+ }
93
+ }
94
+ if (!isBranch(type))
95
+ return;
96
+ entries(value).forEach(([key, child], index) => {
97
+ frames.push([id, index]);
98
+ visit(child, childPath(id, key), key);
99
+ frames.pop();
100
+ });
101
+ };
102
+ visit(data, rootName, null);
103
+ return { matches, ancestors, needed };
104
+ }
105
+ function Highlight({ text, needle, current }) {
106
+ if (!needle)
107
+ return _jsx(_Fragment, { children: text });
108
+ const lower = text.toLowerCase();
109
+ const parts = [];
110
+ let from = 0, at = lower.indexOf(needle);
111
+ while (at !== -1) {
112
+ if (at > from)
113
+ parts.push(text.slice(from, at));
114
+ parts.push(_jsx("mark", { className: styles.mark, "data-current": current || undefined, children: text.slice(at, at + needle.length) }, at));
115
+ from = at + needle.length;
116
+ at = lower.indexOf(needle, from);
117
+ }
118
+ if (from < text.length)
119
+ parts.push(text.slice(from));
120
+ return _jsx(_Fragment, { children: parts });
121
+ }
122
+ /** Icon-only copy action. The glyph swaps in place, so the button never changes width. */
123
+ function CopyButton({ label, icon, onCopy, reduced, className, focusable = false }) {
124
+ const [state, setState] = useState("idle");
125
+ const timer = useRef(0);
126
+ useEffect(() => () => window.clearTimeout(timer.current), []);
127
+ const run = async () => {
128
+ window.clearTimeout(timer.current);
129
+ try {
130
+ await onCopy();
131
+ setState("done");
132
+ }
133
+ catch {
134
+ setState("error");
135
+ }
136
+ timer.current = window.setTimeout(() => setState("idle"), 1400);
137
+ };
138
+ const glyph = state === "done" ? _jsx(Check, { size: 14, strokeWidth: 2, "aria-hidden": "true" }) : state === "error" ? _jsx(X, { size: 14, strokeWidth: 2, "aria-hidden": "true" }) : icon;
139
+ return _jsx("button", { type: "button", tabIndex: focusable ? undefined : -1, className: [styles.action, className].filter(Boolean).join(" "), "data-state": state, "aria-label": state === "done" ? "Copied" : state === "error" ? "Copy failed" : label, title: label, onClick: event => { event.stopPropagation(); void run(); }, children: _jsx(AnimatePresence, { initial: false, mode: "popLayout", children: _jsx(motion.span, { className: styles.actionGlyph, initial: reduced ? { opacity: 0 } : { opacity: 0, scale: .6, filter: `blur(${motionTokens.blur.subtle}px)` }, animate: { opacity: 1, scale: 1, filter: "blur(0px)" }, exit: reduced ? { opacity: 0 } : { opacity: 0, scale: .6, filter: `blur(${motionTokens.blur.subtle}px)` }, transition: reduced ? { duration: motionTokens.duration.instant } : { ...motionTokens.spring.snappy, opacity: { duration: motionTokens.duration.instant }, filter: { duration: motionTokens.duration.instant } }, children: glyph }, state) }) });
140
+ }
141
+ async function writeClipboard(text) {
142
+ if (!navigator.clipboard?.writeText)
143
+ throw new Error("Clipboard unavailable");
144
+ await navigator.clipboard.writeText(text);
145
+ }
146
+ /* Scroll, row heights and the current-row highlight share one critically damped spring, so a highlight that moves while
147
+ * the tree scrolls travels straight to its row instead of overshooting the viewport. */
148
+ const scrollSpring = motionTokens.spring.smooth;
149
+ export const JsonViewer = forwardRef(function JsonViewer({ data, rootName = "root", defaultExpandDepth = 1, expanded: expandedProp, defaultExpanded, onExpandedChange, searchable = true, query: queryProp, defaultQuery = "", onQueryChange, pageSize = 50, copyable = true, onCopy, onSelect, showPath = true, maxHeight = 420, label = "JSON", className, }, ref) {
150
+ const reduced = !!useReducedMotion();
151
+ const uid = useId();
152
+ const treeRef = useRef(null);
153
+ const searchRef = useRef(null);
154
+ const rowRefs = useRef(new Map());
155
+ /* Open branches. */
156
+ const [expandedInternal, setExpandedInternal] = useState(() => defaultExpanded ?? branchesToDepth(data, rootName, defaultExpandDepth));
157
+ const expandedList = expandedProp ?? expandedInternal;
158
+ const base = useMemo(() => new Set(expandedList), [expandedList]);
159
+ const setExpanded = useCallback((next) => {
160
+ const list = [...next];
161
+ if (expandedProp === undefined)
162
+ setExpandedInternal(list);
163
+ onExpandedChange?.(list);
164
+ }, [expandedProp, onExpandedChange]);
165
+ /* Search. Branches holding a match open on their own; closing one while searching is remembered until the query changes. */
166
+ const [queryInternal, setQueryInternal] = useState(defaultQuery);
167
+ const query = queryProp ?? queryInternal;
168
+ const needle = query.trim().toLowerCase();
169
+ const setQuery = (next) => {
170
+ if (queryProp === undefined)
171
+ setQueryInternal(next);
172
+ onQueryChange?.(next);
173
+ };
174
+ const search = useMemo(() => needle ? searchJson(data, rootName, needle) : null, [data, needle, rootName]);
175
+ const [closedWhileSearching, setClosedWhileSearching] = useState({ needle: "", ids: new Set() });
176
+ const closed = closedWhileSearching.needle === needle ? closedWhileSearching.ids : null;
177
+ const [matchIndex, setMatchIndex] = useState(0);
178
+ const matchCount = search?.matches.length ?? 0;
179
+ const matchSet = useMemo(() => new Set(search?.matches ?? []), [search]);
180
+ const currentMatch = search && matchCount ? search.matches[Math.min(matchIndex, matchCount - 1)] : null;
181
+ const isOpen = useCallback((id) => {
182
+ if (search && search.ancestors.has(id))
183
+ return !closed?.has(id);
184
+ return base.has(id);
185
+ }, [base, closed, search]);
186
+ /* Pages for long branches. */
187
+ const [pages, setPages] = useState({});
188
+ const limitOf = useCallback((id) => Math.max((pages[id] ?? 1) * pageSize, search?.needed.get(id) ?? 0), [pageSize, pages, search]);
189
+ /* The visible rows, flat. Each row unfolds its own height, so nested branches, pages, and expand all share one motion. */
190
+ const rows = useMemo(() => {
191
+ const out = [];
192
+ const visit = (value, id, name, level, parent, posinset, setsize) => {
193
+ const type = typeOf(value);
194
+ const list = isBranch(type) ? entries(value) : [];
195
+ const open = isBranch(type) && isOpen(id);
196
+ out.push({ id, kind: "node", level, name, value, type, count: list.length, open, parent, posinset, setsize });
197
+ if (!open)
198
+ return;
199
+ const limit = limitOf(id);
200
+ const shown = list.slice(0, limit);
201
+ const more = list.length - shown.length;
202
+ const size = shown.length + (more > 0 ? 1 : 0);
203
+ shown.forEach(([key, child], index) => visit(child, childPath(id, key), key, level + 1, id, index + 1, size));
204
+ if (more > 0)
205
+ out.push({ id: `${id}::more`, kind: "more", level: level + 1, name: null, value: null, type: "other", count: 0, open: false, parent: id, posinset: size, setsize: size, hidden: more });
206
+ };
207
+ visit(data, rootName, null, 1, null, 1, 1);
208
+ return out;
209
+ }, [data, isOpen, limitOf, rootName]);
210
+ /* The current row. When it is folded away, the nearest visible branch that holds it takes over. */
211
+ const [activeRaw, setActiveRaw] = useState(rootName);
212
+ const active = useMemo(() => {
213
+ if (rows.some(row => row.id === activeRaw))
214
+ return activeRaw;
215
+ let best = rootName;
216
+ for (const row of rows)
217
+ if (row.kind === "node" && within(row.id, activeRaw) && row.id.length > best.length)
218
+ best = row.id;
219
+ return best;
220
+ }, [activeRaw, rootName, rows]);
221
+ const activeIndex = Math.max(0, rows.findIndex(row => row.id === active));
222
+ /* The current row folded away and a branch above took over. The highlight lands there directly instead of flying from a row that is collapsing out of view. */
223
+ const folded = active !== activeRaw;
224
+ const activeRow = rows[activeIndex];
225
+ const onSelectRef = useRef(onSelect);
226
+ useEffect(() => { onSelectRef.current = onSelect; }, [onSelect]);
227
+ const lastReported = useRef(null);
228
+ useEffect(() => {
229
+ if (!activeRow || activeRow.kind !== "node" || lastReported.current === activeRow.id)
230
+ return;
231
+ lastReported.current = activeRow.id;
232
+ onSelectRef.current?.({ path: activeRow.id, value: activeRow.value, type: activeRow.type });
233
+ }, [activeRow]);
234
+ /* Scrolling keeps the current row in view, springing to where it will sit once rows finish unfolding. */
235
+ const scrollFlight = useRef(null);
236
+ const reveal = useCallback((index, center) => {
237
+ const tree = treeRef.current;
238
+ if (!tree)
239
+ return;
240
+ const top = index * ROW, bottom = top + ROW, view = tree.clientHeight, now = tree.scrollTop;
241
+ let target = now;
242
+ if (center)
243
+ target = top - view / 2 + ROW / 2;
244
+ else if (top < now + 4)
245
+ target = top - 4;
246
+ else if (bottom > now + view - 4)
247
+ target = bottom - view + 4;
248
+ target = Math.max(0, target);
249
+ if (Math.abs(target - now) < 1)
250
+ return;
251
+ scrollFlight.current?.stop();
252
+ if (reduced) {
253
+ tree.scrollTop = target;
254
+ return;
255
+ }
256
+ scrollFlight.current = animate(now, target, { ...scrollSpring, onUpdate: value => { tree.scrollTop = value; } });
257
+ }, [reduced]);
258
+ useEffect(() => () => scrollFlight.current?.stop(), []);
259
+ const pendingFocus = useRef(false);
260
+ const pendingReveal = useRef(null);
261
+ /* Bumped on every navigation, so moving to the row that is already current still focuses and reveals it. */
262
+ const [navigation, setNavigation] = useState(0);
263
+ useEffect(() => {
264
+ if (pendingFocus.current) {
265
+ pendingFocus.current = false;
266
+ rowRefs.current.get(active)?.focus({ preventScroll: true });
267
+ }
268
+ if (pendingReveal.current) {
269
+ reveal(activeIndex, pendingReveal.current === "center");
270
+ pendingReveal.current = null;
271
+ }
272
+ }, [active, activeIndex, reveal, navigation]);
273
+ const moveTo = (id, focus = true, how = "nearest") => {
274
+ pendingFocus.current = focus;
275
+ pendingReveal.current = how;
276
+ setActiveRaw(id);
277
+ setNavigation(count => count + 1);
278
+ };
279
+ const toggle = (id, next) => {
280
+ const open = isOpen(id);
281
+ const want = next ?? !open;
282
+ if (want === open)
283
+ return;
284
+ if (search?.ancestors.has(id)) {
285
+ const ids = new Set(closed ?? []);
286
+ if (want)
287
+ ids.delete(id);
288
+ else
289
+ ids.add(id);
290
+ setClosedWhileSearching({ needle, ids });
291
+ if (want && !base.has(id))
292
+ setExpanded(new Set(base).add(id));
293
+ return;
294
+ }
295
+ const nextSet = new Set(base);
296
+ if (want)
297
+ nextSet.add(id);
298
+ else
299
+ nextSet.delete(id);
300
+ setExpanded(nextSet);
301
+ };
302
+ const expandAll = () => {
303
+ setExpanded(new Set(allBranches(data, rootName)));
304
+ setClosedWhileSearching({ needle, ids: new Set() });
305
+ // Branches above the current row unfold and push it down; follow it to where it settles.
306
+ moveTo(active, false, "nearest");
307
+ };
308
+ const collapseAll = () => {
309
+ const rootOpen = isBranch(typeOf(data)) ? [rootName] : [];
310
+ setExpanded(new Set(rootOpen));
311
+ setClosedWhileSearching({ needle, ids: new Set([...(search?.ancestors ?? [])].filter(id => id !== rootName)) });
312
+ setPages({});
313
+ moveTo(rootName, false, "nearest");
314
+ };
315
+ const showMore = (parent) => setPages(current => ({ ...current, [parent]: Math.ceil(limitOf(parent) / pageSize) + 1 }));
316
+ /* Copy. */
317
+ const [announcement, setAnnouncement] = useState("");
318
+ const copy = async (row, kind) => {
319
+ const text = kind === "path" ? row.id : copyText(row.value, row.type);
320
+ try {
321
+ await writeClipboard(text);
322
+ setAnnouncement(`Copied ${kind === "path" ? "path" : "value of"} ${row.id}`);
323
+ onCopy?.({ kind, path: row.id, text });
324
+ }
325
+ catch (error) {
326
+ setAnnouncement("Copy failed");
327
+ throw error;
328
+ }
329
+ };
330
+ /* Search navigation. */
331
+ const stepMatch = (step) => {
332
+ if (!search || !matchCount)
333
+ return;
334
+ const next = ((Math.min(matchIndex, matchCount - 1) + step) % matchCount + matchCount) % matchCount;
335
+ setMatchIndex(next);
336
+ moveTo(search.matches[next], false, "center");
337
+ };
338
+ const onQuery = (next) => {
339
+ setQuery(next);
340
+ setMatchIndex(0);
341
+ const trimmed = next.trim().toLowerCase();
342
+ if (trimmed) {
343
+ const first = searchJson(data, rootName, trimmed).matches[0];
344
+ if (first)
345
+ moveTo(first, false, "center");
346
+ }
347
+ else if (needle) {
348
+ // Clearing folds the branches search opened. Aim the scroll at where the current row settles, so it stays in view.
349
+ moveTo(activeRaw, false, "nearest");
350
+ }
351
+ };
352
+ const onSearchKeyDown = (event) => {
353
+ if (event.key === "Enter") {
354
+ event.preventDefault();
355
+ stepMatch(event.shiftKey ? -1 : 1);
356
+ }
357
+ else if (event.key === "Escape" && query) {
358
+ event.preventDefault();
359
+ event.stopPropagation();
360
+ onQuery("");
361
+ }
362
+ else if (event.key === "ArrowDown" && !event.altKey) {
363
+ event.preventDefault();
364
+ moveTo(active, true);
365
+ }
366
+ };
367
+ const onTreeKeyDown = (event) => {
368
+ const row = rows[activeIndex];
369
+ if (!row || event.altKey)
370
+ return;
371
+ const mod = event.metaKey || event.ctrlKey;
372
+ if (mod && event.key.toLowerCase() === "c") {
373
+ if (row.kind === "node" && !window.getSelection()?.toString()) {
374
+ event.preventDefault();
375
+ void copy(row, event.shiftKey ? "path" : "value").catch(() => { });
376
+ }
377
+ return;
378
+ }
379
+ if (mod)
380
+ return;
381
+ const go = (index) => { event.preventDefault(); const target = rows[Math.max(0, Math.min(rows.length - 1, index))]; if (target)
382
+ moveTo(target.id); };
383
+ switch (event.key) {
384
+ case "ArrowDown":
385
+ go(activeIndex + 1);
386
+ break;
387
+ case "ArrowUp":
388
+ go(activeIndex - 1);
389
+ break;
390
+ case "Home":
391
+ go(0);
392
+ break;
393
+ case "End":
394
+ go(rows.length - 1);
395
+ break;
396
+ case "ArrowRight":
397
+ event.preventDefault();
398
+ if (row.kind === "node" && isBranch(row.type)) {
399
+ if (!row.open)
400
+ toggle(row.id, true);
401
+ else if (row.count)
402
+ go(activeIndex + 1);
403
+ }
404
+ break;
405
+ case "ArrowLeft":
406
+ event.preventDefault();
407
+ if (row.kind === "node" && row.open)
408
+ toggle(row.id, false);
409
+ else if (row.parent)
410
+ moveTo(row.parent);
411
+ break;
412
+ case "Enter":
413
+ case " ":
414
+ event.preventDefault();
415
+ if (row.kind === "more")
416
+ showMore(row.parent);
417
+ else if (isBranch(row.type))
418
+ toggle(row.id);
419
+ break;
420
+ case "/":
421
+ if (searchable) {
422
+ event.preventDefault();
423
+ searchRef.current?.focus();
424
+ searchRef.current?.select();
425
+ }
426
+ break;
427
+ default:
428
+ }
429
+ };
430
+ const heightStyle = { "--json-max-height": typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight };
431
+ const bulk = rows.length > 400;
432
+ const rowTransition = reduced || bulk ? { duration: 0 } : { height: motionTokens.spring.smooth, opacity: { duration: motionTokens.duration.fast, ease: [...motionTokens.ease.standard] } };
433
+ const describe = (row) => {
434
+ const name = row.name === null ? rootName : String(row.name);
435
+ if (row.kind === "more")
436
+ return `Show ${Math.min(pageSize, row.hidden ?? 0)} more, ${row.hidden} hidden`;
437
+ return isBranch(row.type) ? `${name}, ${row.type}, ${countLabel(row)}` : `${name}: ${primitiveText(row.value, row.type)}`;
438
+ };
439
+ return _jsxs("div", { ref: ref, className: [styles.root, className].filter(Boolean).join(" "), style: heightStyle, children: [searchable || rows.length > 1 ? _jsxs("div", { className: styles.toolbar, children: [searchable ? _jsxs("label", { className: styles.search, children: [_jsx(Search, { size: 15, strokeWidth: 1.75, "aria-hidden": "true", className: styles.searchIcon }), _jsx("input", { ref: searchRef, type: "search", className: styles.input, value: query, placeholder: "Search keys and values", "aria-label": "Search JSON", "aria-controls": `${uid}-tree`, onChange: event => onQuery(event.target.value), onKeyDown: onSearchKeyDown, spellCheck: false, autoComplete: "off" }), _jsx(AnimatePresence, { initial: false, children: needle ? _jsxs(motion.span, { className: styles.matches, initial: reduced ? { opacity: 0 } : { opacity: 0, x: 6 }, animate: { opacity: 1, x: 0 }, exit: reduced ? { opacity: 0 } : { opacity: 0, x: 6 }, transition: { duration: motionTokens.duration.fast, ease: [...motionTokens.ease.enter] }, children: [_jsx("span", { className: styles.count, "aria-live": "polite", children: matchCount ? `${Math.min(matchIndex, matchCount - 1) + 1}/${matchCount}` : "0/0" }), _jsx("button", { type: "button", className: styles.tool, "aria-label": "Previous match", disabled: !matchCount, onClick: () => stepMatch(-1), children: _jsx(ChevronUp, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }) }), _jsx("button", { type: "button", className: styles.tool, "aria-label": "Next match", disabled: !matchCount, onClick: () => stepMatch(1), children: _jsx(ChevronDown, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }) })] }, "matches") : null })] }) : _jsx("span", { className: styles.grow }), _jsx("span", { className: styles.divider, "aria-hidden": "true" }), _jsx("button", { type: "button", className: styles.tool, "aria-label": "Expand all", title: "Expand all", onClick: expandAll, children: _jsx(ChevronsUpDown, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }) }), _jsx("button", { type: "button", className: styles.tool, "aria-label": "Collapse all", title: "Collapse all", onClick: collapseAll, children: _jsx(ChevronsDownUp, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }) })] }) : null, _jsx(LayoutGroup, { id: uid, children: _jsx(motion.div, { ref: treeRef, layoutScroll: true, id: `${uid}-tree`, role: "tree", "aria-label": label, className: styles.tree, onKeyDown: onTreeKeyDown, children: _jsx(AnimatePresence, { initial: false, children: rows.map(row => {
440
+ const isActive = row.id === active;
441
+ const branch = isBranch(row.type);
442
+ const matched = !!search && row.kind === "node" && matchSet.has(row.id);
443
+ const isCurrentMatch = row.id === currentMatch;
444
+ const mark = matched ? needle : "";
445
+ return _jsxs(motion.div, { ref: (node) => { if (node)
446
+ rowRefs.current.set(row.id, node);
447
+ else
448
+ rowRefs.current.delete(row.id); }, role: "treeitem", tabIndex: isActive ? 0 : -1, "aria-level": row.level, "aria-posinset": row.posinset, "aria-setsize": row.setsize, "aria-expanded": row.kind === "node" && branch ? row.open : undefined, "aria-selected": isActive, "aria-label": describe(row), className: styles.row, "data-kind": row.kind, "data-active": isActive || undefined, style: { "--level": row.level - 1 }, initial: { height: 0, opacity: 0, overflow: "hidden" }, animate: { height: ROW, opacity: 1, transitionEnd: { overflow: "visible" } }, exit: { height: 0, opacity: 0, overflow: "hidden" }, transition: rowTransition, onFocus: event => { if (event.target === event.currentTarget && row.id !== active)
449
+ setActiveRaw(row.id); }, onClick: () => {
450
+ if (row.kind === "more") {
451
+ showMore(row.parent);
452
+ moveTo(row.id);
453
+ return;
454
+ }
455
+ if (branch)
456
+ toggle(row.id);
457
+ moveTo(row.id);
458
+ }, children: [isActive ? _jsx(motion.span, { layoutId: "json-active", className: styles.highlight, transition: reduced || folded ? { duration: 0 } : scrollSpring, "aria-hidden": "true" }) : null, _jsx("span", { className: styles.line, children: row.kind === "more" ? _jsxs("span", { className: styles.more, children: [_jsxs("span", { className: styles.moreLabel, children: ["Show ", Math.min(pageSize, row.hidden ?? 0), " more"] }), _jsxs("span", { className: styles.muted, children: [row.hidden, " hidden"] })] }) : _jsxs(_Fragment, { children: [_jsx("span", { className: styles.chevron, "data-open": row.open || undefined, "data-branch": branch || undefined, "aria-hidden": "true", children: branch ? _jsx(ChevronRight, { size: 14, strokeWidth: 1.75 }) : null }), _jsx("span", { className: typeof row.name === "number" ? styles.index : styles.key, children: row.name === null ? rootName : typeof row.name === "number" ? row.name : _jsx(Highlight, { text: row.name, needle: mark, current: isCurrentMatch }) }), _jsx("span", { className: styles.colon, "aria-hidden": "true", children: row.name === null && branch ? "" : ":" }), branch
459
+ ? _jsxs("span", { className: styles.summary, children: [!row.open ? _jsx("span", { className: styles.preview, children: row.type === "array" ? "[…]" : `{ ${entries(row.value).slice(0, 3).map(([key]) => key).join(", ")}${row.count > 3 ? ", …" : ""} }` }) : null, _jsx("span", { className: styles.countLabel, children: countLabel(row) })] })
460
+ : _jsx("span", { className: styles.value, "data-type": row.type, title: row.type === "string" && row.value.length > 40 ? row.value : undefined, children: row.type === "string" ? _jsxs(_Fragment, { children: ["\"", _jsx(Highlight, { text: row.value, needle: mark, current: isCurrentMatch }), "\""] }) : _jsx(Highlight, { text: primitiveText(row.value, row.type), needle: mark, current: isCurrentMatch }) }), copyable ? _jsxs("span", { className: styles.actions, children: [_jsx(CopyButton, { label: "Copy value", icon: _jsx(Copy, { size: 14, strokeWidth: 1.75, "aria-hidden": "true" }), reduced: reduced, onCopy: () => copy(row, "value") }), _jsx(CopyButton, { label: "Copy path", icon: _jsx(Link2, { size: 14, strokeWidth: 1.75, "aria-hidden": "true" }), reduced: reduced, onCopy: () => copy(row, "path") })] }) : null] }) })] }, row.id);
461
+ }) }) }) }), showPath && activeRow ? _jsxs("div", { className: styles.pathBar, children: [_jsx("code", { className: styles.path, title: activeRow.kind === "node" ? activeRow.id : activeRow.parent ?? "", children: activeRow.kind === "node" ? activeRow.id : activeRow.parent }), _jsx("span", { className: styles.pathType, children: activeRow.kind === "node" ? isBranch(activeRow.type) ? `${activeRow.type}, ${countLabel(activeRow)}` : activeRow.type : "page" }), copyable && activeRow.kind === "node" ? _jsx(CopyButton, { focusable: true, className: styles.pathCopy, label: "Copy path", icon: _jsx(Copy, { size: 14, strokeWidth: 1.75, "aria-hidden": "true" }), reduced: reduced, onCopy: () => copy(activeRow, "path") }, activeRow.id) : null] }) : null, _jsx("span", { className: styles.srOnly, role: "status", children: announcement })] });
462
+ });
463
+ export default JsonViewer;
@@ -0,0 +1,92 @@
1
+ .root { --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace; --indent: 16px; display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-container); background: var(--surface); color: var(--foreground); font-family: var(--font-body); letter-spacing: var(--tracking-body); }
2
+
3
+ /* Toolbar: search with a match counter, then expand and collapse all. */
4
+ .toolbar { display: flex; align-items: center; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border-subtle); }
5
+ .search { position: relative; display: flex; min-width: 0; flex: 1; align-items: center; gap: 4px; min-height: 34px; padding: 0 4px 0 10px; border-radius: var(--radius-control); background: var(--surface-muted); cursor: text; }
6
+ .searchIcon { flex: none; color: var(--text-muted); }
7
+ .input { min-width: 0; flex: 1; height: 34px; padding: 0 4px; border: 0; background: transparent; color: var(--foreground); font: inherit; font-size: var(--text-sm); outline: none; }
8
+ .input::placeholder { color: var(--text-muted); }
9
+ .input::-webkit-search-cancel-button { display: none; }
10
+ .matches { display: inline-flex; flex: none; align-items: center; gap: 0; }
11
+ .count { min-width: 3.5ch; padding-inline: 4px; color: var(--text-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; text-align: right; }
12
+ .grow { flex: 1; }
13
+ .divider { width: 1px; height: 18px; margin-inline: 4px; background: var(--border-subtle); }
14
+ .tool { display: inline-grid; width: 34px; height: 34px; flex: none; place-items: center; padding: 0; border: 0; border-radius: var(--radius-control); background: transparent; color: var(--text-secondary); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: color var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard), opacity var(--duration-fast) var(--ease-standard); }
15
+ .tool:disabled { cursor: default; opacity: .4; }
16
+ .tool:active:not(:disabled) { background: var(--surface-muted); color: var(--foreground); }
17
+ .search .tool { width: 26px; height: 26px; border-radius: var(--radius-detail); }
18
+ .search .tool:active:not(:disabled) { background: var(--surface); }
19
+
20
+ /* Tree. Rows are one fixed height, so scrolling can aim at where a row will settle. */
21
+ .tree { position: relative; max-height: var(--json-max-height, 420px); padding: 6px; overflow: auto; overflow-anchor: none; overscroll-behavior: contain; font-family: var(--mono); font-size: 13px; font-variant-ligatures: none; letter-spacing: 0; scrollbar-width: thin; }
22
+ .row { position: relative; border-radius: var(--radius-detail); cursor: default; outline: none; -webkit-tap-highlight-color: transparent; }
23
+ .highlight { position: absolute; inset: 1px 0; border-radius: var(--radius-detail); background: var(--surface-muted); }
24
+ .line { position: relative; display: flex; height: 30px; min-width: 0; align-items: center; gap: 6px; padding-right: 6px; padding-left: calc(4px + var(--level, 0) * var(--indent)); white-space: nowrap; }
25
+ .row[data-kind="node"] .line { cursor: pointer; }
26
+
27
+ .chevron { display: inline-grid; width: 14px; height: 14px; flex: none; place-items: center; color: var(--text-muted); transition: transform var(--duration-spring) var(--ease-spring), color var(--duration-fast) var(--ease-standard); }
28
+ .chevron[data-open] { transform: rotate(90deg); }
29
+ .row[data-active] .chevron[data-branch] { color: var(--foreground); }
30
+
31
+ .key { flex: none; max-width: 45%; overflow: hidden; color: var(--foreground); text-overflow: ellipsis; }
32
+ .index { flex: none; color: var(--text-muted); font-variant-numeric: tabular-nums; }
33
+ .colon { flex: none; margin-left: -5px; color: var(--text-muted); }
34
+ .summary { display: inline-flex; min-width: 0; align-items: baseline; gap: 8px; overflow: hidden; }
35
+ .preview { min-width: 0; overflow: hidden; color: var(--text-muted); text-overflow: ellipsis; }
36
+ .countLabel { flex: none; color: var(--text-muted); font-family: var(--font-body); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
37
+
38
+ /* Type colors lean on the semantic roles, so both themes stay legible. */
39
+ .value { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
40
+ .value[data-type="string"] { color: var(--success); }
41
+ .value[data-type="number"] { color: var(--accent); font-variant-numeric: tabular-nums; }
42
+ .value[data-type="boolean"] { color: var(--warning); }
43
+ .value[data-type="null"], .value[data-type="other"] { color: var(--text-muted); }
44
+
45
+ .mark { border-radius: var(--radius-detail); background: color-mix(in oklab, var(--warning) 22%, transparent); color: inherit; box-shadow: 0 0 0 1px color-mix(in oklab, var(--warning) 22%, transparent); transition: background-color var(--duration-fast) var(--ease-standard); }
46
+ .mark[data-current] { background: color-mix(in oklab, var(--warning) 48%, transparent); }
47
+
48
+ .more { display: inline-flex; align-items: baseline; gap: 10px; padding-left: 20px; font-family: var(--font-body); font-size: var(--text-sm); }
49
+ .moreLabel { color: var(--foreground); font-weight: 500; }
50
+ .row[data-kind="more"] { cursor: pointer; }
51
+ .muted { color: var(--text-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
52
+
53
+ /* Copy actions appear at the row's end over a soft fade, on hover or on the current row. */
54
+ /* Inset like the highlight, with its right corners, so the fade never shows a square edge past the row's rounded end. */
55
+ .actions { position: absolute; top: 1px; right: 0; bottom: 1px; display: flex; align-items: center; gap: 0; padding-right: 1px; padding-left: 24px; border-radius: 0 var(--radius-detail) var(--radius-detail) 0; background: linear-gradient(to right, transparent, var(--surface) 22px); opacity: 0; pointer-events: none; transition: opacity var(--duration-fast) var(--ease-standard); }
56
+ .row[data-active] .actions { background: linear-gradient(to right, transparent, var(--surface-muted) 22px); }
57
+ .action { position: relative; display: inline-grid; width: 26px; height: 26px; place-items: center; padding: 0; border: 0; border-radius: var(--radius-detail); background: transparent; color: var(--text-secondary); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: color var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard); }
58
+ .action[data-state="done"] { color: var(--success); }
59
+ .action[data-state="error"] { color: var(--danger); }
60
+ .action:active { background: color-mix(in oklab, var(--foreground) 8%, transparent); }
61
+ .actionGlyph { display: grid; place-items: center; }
62
+ .row[data-active] .actions, .row:focus-within .actions { opacity: 1; pointer-events: auto; }
63
+
64
+ /* The current path, always readable in full through its copy action. */
65
+ .pathBar { display: flex; min-width: 0; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; border-top: 1px solid var(--border-subtle); }
66
+ .path { min-width: 0; flex: 1; overflow: hidden; color: var(--text-secondary); font-family: var(--mono); font-size: var(--text-xs); letter-spacing: 0; text-overflow: ellipsis; white-space: nowrap; }
67
+ .pathType { flex: none; color: var(--text-muted); font-size: var(--text-xs); }
68
+ .pathCopy { width: 30px; height: 30px; border-radius: var(--radius-detail); }
69
+
70
+ .srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
71
+
72
+ @media (hover: hover) and (pointer: fine) {
73
+ .row:hover .actions { opacity: 1; pointer-events: auto; }
74
+ /* Same inset and corner as the current-row highlight, so hover and selection share one shape. */
75
+ .row:not([data-active]):hover { --row-hover: color-mix(in oklab, var(--foreground) 3.5%, var(--surface)); }
76
+ .row:not([data-active]):hover::before { content: ""; position: absolute; inset: 1px 0; border-radius: var(--radius-detail); background: var(--row-hover); pointer-events: none; }
77
+ .row:not([data-active]):hover .actions { background: linear-gradient(to right, transparent, var(--row-hover) 22px); }
78
+ .row:hover .chevron[data-branch] { color: var(--foreground); }
79
+ .tool:hover:not(:disabled), .action:hover { background: var(--surface-muted); color: var(--foreground); }
80
+ .search .tool:hover:not(:disabled) { background: var(--surface); }
81
+ .action[data-state="done"]:hover { color: var(--success); }
82
+ }
83
+
84
+ @media (max-width: 420px) {
85
+ .tree { --indent: 12px; }
86
+ .key { max-width: 40%; }
87
+ .pathType { display: none; }
88
+ }
89
+
90
+ @media (prefers-reduced-motion: reduce) {
91
+ .chevron, .actions, .tool, .action, .mark { transition: none; }
92
+ }