@nous-research/ui 0.13.2 → 0.14.1

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 (320) hide show
  1. package/README.md +16 -0
  2. package/dist/assets/filler-bg0.webp +0 -0
  3. package/dist/assets.d.ts +38 -0
  4. package/dist/fonts.d.ts +0 -1
  5. package/dist/fonts.js +5 -7
  6. package/dist/hooks/use-capped-frame.d.ts +0 -1
  7. package/dist/hooks/use-capped-frame.js +12 -13
  8. package/dist/hooks/use-css-var-dims.d.ts +0 -1
  9. package/dist/hooks/use-css-var-dims.js +26 -21
  10. package/dist/hooks/use-gpu-tier.d.ts +0 -1
  11. package/dist/hooks/use-gpu-tier.js +90 -110
  12. package/dist/hooks/use-render-loop.d.ts +0 -1
  13. package/dist/hooks/use-render-loop.js +58 -58
  14. package/dist/hooks/use-smooth-controls.d.ts +0 -1
  15. package/dist/hooks/use-smooth-controls.js +204 -206
  16. package/dist/index.d.ts +0 -1
  17. package/dist/index.js +84 -58
  18. package/dist/ui/basic-page.d.ts +1 -2
  19. package/dist/ui/basic-page.js +15 -7
  20. package/dist/ui/build.css +1 -0
  21. package/dist/ui/components/animated-count.d.ts +1 -2
  22. package/dist/ui/components/animated-count.js +109 -85
  23. package/dist/ui/components/ascii.d.ts +2 -3
  24. package/dist/ui/components/ascii.js +75 -59
  25. package/dist/ui/components/badge.d.ts +1 -2
  26. package/dist/ui/components/badge.js +35 -18
  27. package/dist/ui/components/badges/nous-girl.d.ts +1 -2
  28. package/dist/ui/components/badges/nous-girl.js +80 -3
  29. package/dist/ui/components/blend-mode.d.ts +1 -2
  30. package/dist/ui/components/blend-mode.js +55 -63
  31. package/dist/ui/components/blink.d.ts +1 -2
  32. package/dist/ui/components/blink.js +15 -6
  33. package/dist/ui/components/button.d.ts +2 -3
  34. package/dist/ui/components/button.js +139 -90
  35. package/dist/ui/components/command-block.d.ts +2 -3
  36. package/dist/ui/components/command-block.js +52 -24
  37. package/dist/ui/components/cursor.d.ts +1 -2
  38. package/dist/ui/components/cursor.js +93 -54
  39. package/dist/ui/components/dropdown-menu.d.ts +1 -2
  40. package/dist/ui/components/dropdown-menu.js +99 -51
  41. package/dist/ui/components/fit-text/index.d.ts +0 -1
  42. package/dist/ui/components/fit-text/index.js +21 -13
  43. package/dist/ui/components/graphs/bar-chart.d.ts +1 -2
  44. package/dist/ui/components/graphs/bar-chart.js +116 -63
  45. package/dist/ui/components/graphs/index.d.ts +0 -1
  46. package/dist/ui/components/graphs/index.js +3 -4
  47. package/dist/ui/components/graphs/line-chart.d.ts +1 -2
  48. package/dist/ui/components/graphs/line-chart.js +159 -102
  49. package/dist/ui/components/graphs/utils.d.ts +2 -3
  50. package/dist/ui/components/graphs/utils.js +147 -114
  51. package/dist/ui/components/grid/index.d.ts +0 -1
  52. package/dist/ui/components/grid/index.js +12 -9
  53. package/dist/ui/components/hover-bg.d.ts +0 -1
  54. package/dist/ui/components/hover-bg.js +11 -6
  55. package/dist/ui/components/icons/arrow.d.ts +1 -2
  56. package/dist/ui/components/icons/arrow.js +42 -5
  57. package/dist/ui/components/icons/chevron.d.ts +1 -2
  58. package/dist/ui/components/icons/chevron.js +49 -5
  59. package/dist/ui/components/icons/discord.d.ts +1 -2
  60. package/dist/ui/components/icons/discord.js +12 -4
  61. package/dist/ui/components/icons/eye.d.ts +1 -2
  62. package/dist/ui/components/icons/eye.js +5 -3
  63. package/dist/ui/components/icons/gear.d.ts +1 -2
  64. package/dist/ui/components/icons/gear.js +28 -14
  65. package/dist/ui/components/icons/github.d.ts +1 -2
  66. package/dist/ui/components/icons/github.js +12 -4
  67. package/dist/ui/components/icons/hamburger.d.ts +1 -2
  68. package/dist/ui/components/icons/hamburger.js +54 -5
  69. package/dist/ui/components/icons/heart.d.ts +1 -2
  70. package/dist/ui/components/icons/heart.js +8 -3
  71. package/dist/ui/components/icons/index.d.ts +0 -1
  72. package/dist/ui/components/icons/index.js +11 -12
  73. package/dist/ui/components/icons/link.d.ts +1 -2
  74. package/dist/ui/components/icons/link.js +10 -3
  75. package/dist/ui/components/icons/minus.d.ts +1 -2
  76. package/dist/ui/components/icons/minus.js +10 -3
  77. package/dist/ui/components/icons/search.d.ts +1 -2
  78. package/dist/ui/components/icons/search.js +30 -3
  79. package/dist/ui/components/image-distortion.d.ts +1 -2
  80. package/dist/ui/components/image-distortion.js +300 -265
  81. package/dist/ui/components/leva-client.d.ts +1 -2
  82. package/dist/ui/components/leva-client.js +9 -10
  83. package/dist/ui/components/list-item.d.ts +0 -1
  84. package/dist/ui/components/list-item.js +26 -10
  85. package/dist/ui/components/modal/index.d.ts +1 -2
  86. package/dist/ui/components/modal/index.js +33 -14
  87. package/dist/ui/components/overlays/blend-modes.d.ts +0 -1
  88. package/dist/ui/components/overlays/blend-modes.js +11 -12
  89. package/dist/ui/components/overlays/glitch.d.ts +1 -2
  90. package/dist/ui/components/overlays/glitch.js +115 -110
  91. package/dist/ui/components/overlays/greys.d.ts +1 -2
  92. package/dist/ui/components/overlays/greys.js +200 -179
  93. package/dist/ui/components/overlays/index.d.ts +1 -2
  94. package/dist/ui/components/overlays/index.js +31 -17
  95. package/dist/ui/components/overlays/lens-layers.d.ts +1 -2
  96. package/dist/ui/components/overlays/lens-layers.js +89 -65
  97. package/dist/ui/components/overlays/lens.d.ts +0 -1
  98. package/dist/ui/components/overlays/lens.js +46 -52
  99. package/dist/ui/components/overlays/noise.d.ts +1 -2
  100. package/dist/ui/components/overlays/noise.js +112 -113
  101. package/dist/ui/components/overlays/vignette.d.ts +1 -2
  102. package/dist/ui/components/overlays/vignette.js +44 -38
  103. package/dist/ui/components/poster.d.ts +1 -2
  104. package/dist/ui/components/poster.js +240 -87
  105. package/dist/ui/components/progress.d.ts +1 -2
  106. package/dist/ui/components/progress.js +52 -12
  107. package/dist/ui/components/scene-canvas.d.ts +1 -2
  108. package/dist/ui/components/scene-canvas.js +169 -119
  109. package/dist/ui/components/scramble.d.ts +1 -2
  110. package/dist/ui/components/scramble.js +60 -59
  111. package/dist/ui/components/segmented.d.ts +2 -3
  112. package/dist/ui/components/segmented.js +47 -12
  113. package/dist/ui/components/select.d.ts +1 -2
  114. package/dist/ui/components/select.js +207 -120
  115. package/dist/ui/components/selection-switcher.d.ts +0 -1
  116. package/dist/ui/components/selection-switcher.js +29 -25
  117. package/dist/ui/components/shader.d.ts +1 -2
  118. package/dist/ui/components/shader.js +56 -38
  119. package/dist/ui/components/socials.d.ts +1 -2
  120. package/dist/ui/components/socials.js +18 -7
  121. package/dist/ui/components/spinner.d.ts +1 -2
  122. package/dist/ui/components/spinner.js +36 -25
  123. package/dist/ui/components/stats.d.ts +1 -2
  124. package/dist/ui/components/stats.js +33 -9
  125. package/dist/ui/components/switch.d.ts +0 -1
  126. package/dist/ui/components/switch.js +35 -11
  127. package/dist/ui/components/tabs.d.ts +3 -4
  128. package/dist/ui/components/tabs.js +38 -12
  129. package/dist/ui/components/terminal-demo.d.ts +1 -2
  130. package/dist/ui/components/terminal-demo.js +119 -74
  131. package/dist/ui/components/theme-toggle.d.ts +1 -2
  132. package/dist/ui/components/theme-toggle.js +63 -8
  133. package/dist/ui/components/tier-card.d.ts +1 -2
  134. package/dist/ui/components/tier-card.js +144 -24
  135. package/dist/ui/components/tv.d.ts +1 -2
  136. package/dist/ui/components/tv.js +138 -90
  137. package/dist/ui/components/typography/h1.d.ts +0 -1
  138. package/dist/ui/components/typography/h1.js +17 -8
  139. package/dist/ui/components/typography/h2.d.ts +0 -1
  140. package/dist/ui/components/typography/h2.js +17 -8
  141. package/dist/ui/components/typography/index.d.ts +0 -1
  142. package/dist/ui/components/typography/index.js +35 -24
  143. package/dist/ui/components/typography/legend.d.ts +1 -2
  144. package/dist/ui/components/typography/legend.js +18 -6
  145. package/dist/ui/components/typography/small.d.ts +0 -1
  146. package/dist/ui/components/typography/small.js +8 -7
  147. package/dist/ui/components/watchlist.d.ts +1 -2
  148. package/dist/ui/components/watchlist.js +77 -25
  149. package/dist/ui/fonts.css +7 -7
  150. package/dist/ui/footer.d.ts +1 -2
  151. package/dist/ui/footer.js +61 -25
  152. package/dist/ui/globals.css +5 -1
  153. package/dist/ui/header.d.ts +1 -2
  154. package/dist/ui/header.js +255 -60
  155. package/dist/ui/layout-wrapper.d.ts +1 -2
  156. package/dist/ui/layout-wrapper.js +5 -4
  157. package/dist/utils/color.d.ts +0 -1
  158. package/dist/utils/color.js +8 -9
  159. package/dist/utils/index.d.ts +0 -1
  160. package/dist/utils/index.js +37 -38
  161. package/dist/utils/poly.d.ts +0 -1
  162. package/dist/utils/poly.js +1 -2
  163. package/package.json +42 -24
  164. package/dist/assets/filler-bg0.jpg +0 -0
  165. package/dist/fonts.d.ts.map +0 -1
  166. package/dist/fonts.js.map +0 -1
  167. package/dist/hooks/use-capped-frame.d.ts.map +0 -1
  168. package/dist/hooks/use-capped-frame.js.map +0 -1
  169. package/dist/hooks/use-css-var-dims.d.ts.map +0 -1
  170. package/dist/hooks/use-css-var-dims.js.map +0 -1
  171. package/dist/hooks/use-gpu-tier.d.ts.map +0 -1
  172. package/dist/hooks/use-gpu-tier.js.map +0 -1
  173. package/dist/hooks/use-render-loop.d.ts.map +0 -1
  174. package/dist/hooks/use-render-loop.js.map +0 -1
  175. package/dist/hooks/use-smooth-controls.d.ts.map +0 -1
  176. package/dist/hooks/use-smooth-controls.js.map +0 -1
  177. package/dist/index.d.ts.map +0 -1
  178. package/dist/index.js.map +0 -1
  179. package/dist/ui/basic-page.d.ts.map +0 -1
  180. package/dist/ui/basic-page.js.map +0 -1
  181. package/dist/ui/components/animated-count.d.ts.map +0 -1
  182. package/dist/ui/components/animated-count.js.map +0 -1
  183. package/dist/ui/components/ascii.d.ts.map +0 -1
  184. package/dist/ui/components/ascii.js.map +0 -1
  185. package/dist/ui/components/badge.d.ts.map +0 -1
  186. package/dist/ui/components/badge.js.map +0 -1
  187. package/dist/ui/components/badges/nous-girl.d.ts.map +0 -1
  188. package/dist/ui/components/badges/nous-girl.js.map +0 -1
  189. package/dist/ui/components/blend-mode.d.ts.map +0 -1
  190. package/dist/ui/components/blend-mode.js.map +0 -1
  191. package/dist/ui/components/blink.d.ts.map +0 -1
  192. package/dist/ui/components/blink.js.map +0 -1
  193. package/dist/ui/components/button.d.ts.map +0 -1
  194. package/dist/ui/components/button.js.map +0 -1
  195. package/dist/ui/components/command-block.d.ts.map +0 -1
  196. package/dist/ui/components/command-block.js.map +0 -1
  197. package/dist/ui/components/cursor.d.ts.map +0 -1
  198. package/dist/ui/components/cursor.js.map +0 -1
  199. package/dist/ui/components/dropdown-menu.d.ts.map +0 -1
  200. package/dist/ui/components/dropdown-menu.js.map +0 -1
  201. package/dist/ui/components/fit-text/index.d.ts.map +0 -1
  202. package/dist/ui/components/fit-text/index.js.map +0 -1
  203. package/dist/ui/components/graphs/bar-chart.d.ts.map +0 -1
  204. package/dist/ui/components/graphs/bar-chart.js.map +0 -1
  205. package/dist/ui/components/graphs/index.d.ts.map +0 -1
  206. package/dist/ui/components/graphs/index.js.map +0 -1
  207. package/dist/ui/components/graphs/line-chart.d.ts.map +0 -1
  208. package/dist/ui/components/graphs/line-chart.js.map +0 -1
  209. package/dist/ui/components/graphs/utils.d.ts.map +0 -1
  210. package/dist/ui/components/graphs/utils.js.map +0 -1
  211. package/dist/ui/components/grid/index.d.ts.map +0 -1
  212. package/dist/ui/components/grid/index.js.map +0 -1
  213. package/dist/ui/components/hover-bg.d.ts.map +0 -1
  214. package/dist/ui/components/hover-bg.js.map +0 -1
  215. package/dist/ui/components/icons/arrow.d.ts.map +0 -1
  216. package/dist/ui/components/icons/arrow.js.map +0 -1
  217. package/dist/ui/components/icons/chevron.d.ts.map +0 -1
  218. package/dist/ui/components/icons/chevron.js.map +0 -1
  219. package/dist/ui/components/icons/discord.d.ts.map +0 -1
  220. package/dist/ui/components/icons/discord.js.map +0 -1
  221. package/dist/ui/components/icons/eye.d.ts.map +0 -1
  222. package/dist/ui/components/icons/eye.js.map +0 -1
  223. package/dist/ui/components/icons/gear.d.ts.map +0 -1
  224. package/dist/ui/components/icons/gear.js.map +0 -1
  225. package/dist/ui/components/icons/github.d.ts.map +0 -1
  226. package/dist/ui/components/icons/github.js.map +0 -1
  227. package/dist/ui/components/icons/hamburger.d.ts.map +0 -1
  228. package/dist/ui/components/icons/hamburger.js.map +0 -1
  229. package/dist/ui/components/icons/heart.d.ts.map +0 -1
  230. package/dist/ui/components/icons/heart.js.map +0 -1
  231. package/dist/ui/components/icons/index.d.ts.map +0 -1
  232. package/dist/ui/components/icons/index.js.map +0 -1
  233. package/dist/ui/components/icons/link.d.ts.map +0 -1
  234. package/dist/ui/components/icons/link.js.map +0 -1
  235. package/dist/ui/components/icons/minus.d.ts.map +0 -1
  236. package/dist/ui/components/icons/minus.js.map +0 -1
  237. package/dist/ui/components/icons/search.d.ts.map +0 -1
  238. package/dist/ui/components/icons/search.js.map +0 -1
  239. package/dist/ui/components/image-distortion.d.ts.map +0 -1
  240. package/dist/ui/components/image-distortion.js.map +0 -1
  241. package/dist/ui/components/leva-client.d.ts.map +0 -1
  242. package/dist/ui/components/leva-client.js.map +0 -1
  243. package/dist/ui/components/list-item.d.ts.map +0 -1
  244. package/dist/ui/components/list-item.js.map +0 -1
  245. package/dist/ui/components/modal/index.d.ts.map +0 -1
  246. package/dist/ui/components/modal/index.js.map +0 -1
  247. package/dist/ui/components/overlays/blend-modes.d.ts.map +0 -1
  248. package/dist/ui/components/overlays/blend-modes.js.map +0 -1
  249. package/dist/ui/components/overlays/glitch.d.ts.map +0 -1
  250. package/dist/ui/components/overlays/glitch.js.map +0 -1
  251. package/dist/ui/components/overlays/greys.d.ts.map +0 -1
  252. package/dist/ui/components/overlays/greys.js.map +0 -1
  253. package/dist/ui/components/overlays/index.d.ts.map +0 -1
  254. package/dist/ui/components/overlays/index.js.map +0 -1
  255. package/dist/ui/components/overlays/lens-layers.d.ts.map +0 -1
  256. package/dist/ui/components/overlays/lens-layers.js.map +0 -1
  257. package/dist/ui/components/overlays/lens.d.ts.map +0 -1
  258. package/dist/ui/components/overlays/lens.js.map +0 -1
  259. package/dist/ui/components/overlays/noise.d.ts.map +0 -1
  260. package/dist/ui/components/overlays/noise.js.map +0 -1
  261. package/dist/ui/components/overlays/vignette.d.ts.map +0 -1
  262. package/dist/ui/components/overlays/vignette.js.map +0 -1
  263. package/dist/ui/components/poster.d.ts.map +0 -1
  264. package/dist/ui/components/poster.js.map +0 -1
  265. package/dist/ui/components/progress.d.ts.map +0 -1
  266. package/dist/ui/components/progress.js.map +0 -1
  267. package/dist/ui/components/scene-canvas.d.ts.map +0 -1
  268. package/dist/ui/components/scene-canvas.js.map +0 -1
  269. package/dist/ui/components/scramble.d.ts.map +0 -1
  270. package/dist/ui/components/scramble.js.map +0 -1
  271. package/dist/ui/components/segmented.d.ts.map +0 -1
  272. package/dist/ui/components/segmented.js.map +0 -1
  273. package/dist/ui/components/select.d.ts.map +0 -1
  274. package/dist/ui/components/select.js.map +0 -1
  275. package/dist/ui/components/selection-switcher.d.ts.map +0 -1
  276. package/dist/ui/components/selection-switcher.js.map +0 -1
  277. package/dist/ui/components/shader.d.ts.map +0 -1
  278. package/dist/ui/components/shader.js.map +0 -1
  279. package/dist/ui/components/socials.d.ts.map +0 -1
  280. package/dist/ui/components/socials.js.map +0 -1
  281. package/dist/ui/components/spinner.d.ts.map +0 -1
  282. package/dist/ui/components/spinner.js.map +0 -1
  283. package/dist/ui/components/stats.d.ts.map +0 -1
  284. package/dist/ui/components/stats.js.map +0 -1
  285. package/dist/ui/components/switch.d.ts.map +0 -1
  286. package/dist/ui/components/switch.js.map +0 -1
  287. package/dist/ui/components/tabs.d.ts.map +0 -1
  288. package/dist/ui/components/tabs.js.map +0 -1
  289. package/dist/ui/components/terminal-demo.d.ts.map +0 -1
  290. package/dist/ui/components/terminal-demo.js.map +0 -1
  291. package/dist/ui/components/theme-toggle.d.ts.map +0 -1
  292. package/dist/ui/components/theme-toggle.js.map +0 -1
  293. package/dist/ui/components/tier-card.d.ts.map +0 -1
  294. package/dist/ui/components/tier-card.js.map +0 -1
  295. package/dist/ui/components/tv.d.ts.map +0 -1
  296. package/dist/ui/components/tv.js.map +0 -1
  297. package/dist/ui/components/typography/h1.d.ts.map +0 -1
  298. package/dist/ui/components/typography/h1.js.map +0 -1
  299. package/dist/ui/components/typography/h2.d.ts.map +0 -1
  300. package/dist/ui/components/typography/h2.js.map +0 -1
  301. package/dist/ui/components/typography/index.d.ts.map +0 -1
  302. package/dist/ui/components/typography/index.js.map +0 -1
  303. package/dist/ui/components/typography/legend.d.ts.map +0 -1
  304. package/dist/ui/components/typography/legend.js.map +0 -1
  305. package/dist/ui/components/typography/small.d.ts.map +0 -1
  306. package/dist/ui/components/typography/small.js.map +0 -1
  307. package/dist/ui/components/watchlist.d.ts.map +0 -1
  308. package/dist/ui/components/watchlist.js.map +0 -1
  309. package/dist/ui/footer.d.ts.map +0 -1
  310. package/dist/ui/footer.js.map +0 -1
  311. package/dist/ui/header.d.ts.map +0 -1
  312. package/dist/ui/header.js.map +0 -1
  313. package/dist/ui/layout-wrapper.d.ts.map +0 -1
  314. package/dist/ui/layout-wrapper.js.map +0 -1
  315. package/dist/utils/color.d.ts.map +0 -1
  316. package/dist/utils/color.js.map +0 -1
  317. package/dist/utils/index.d.ts.map +0 -1
  318. package/dist/utils/index.js.map +0 -1
  319. package/dist/utils/poly.d.ts.map +0 -1
  320. package/dist/utils/poly.js.map +0 -1
@@ -1,117 +1,174 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import * as Plot from '@observablehq/plot';
4
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
- import { cn } from '../../../utils';
6
- import { accessor, CHART_MARGINS, CHART_STYLE, Crosshair, setupCrosshair, stylePlot, useDims, withChartBlend } from './utils';
7
- export const LineChart = withChartBlend(({ backgroundColor: _, className, color: strokeColor, curve = 'natural', data = [], formatTooltip, formatX: formatXProp, formatY: formatYProp, series = 'series', showArea = false, x = 'label', xTicks, y = 'value', yDomain = [0, 0.5], yTicks = 4, ...props }) => {
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as Plot from "@observablehq/plot";
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
+ import { cn } from "../../../utils/index.js";
6
+ import {
7
+ accessor,
8
+ CHART_MARGINS,
9
+ CHART_STYLE,
10
+ Crosshair,
11
+ setupCrosshair,
12
+ stylePlot,
13
+ useDims,
14
+ withChartBlend
15
+ } from "./utils.js";
16
+ export const LineChart = withChartBlend(
17
+ ({
18
+ backgroundColor: _,
19
+ className,
20
+ color: strokeColor,
21
+ curve = "natural",
22
+ data = [],
23
+ formatTooltip,
24
+ formatX: formatXProp,
25
+ formatY: formatYProp,
26
+ series = "series",
27
+ showArea = false,
28
+ x = "label",
29
+ xTicks,
30
+ y = "value",
31
+ yDomain = [0, 0.5],
32
+ yTicks = 4,
33
+ ...props
34
+ }) => {
8
35
  const ref = useRef(null);
9
36
  const plotRef = useRef(null);
10
37
  const [hovered, setHovered] = useState(null);
11
38
  const [crosshair, setCrosshair] = useState({ x: null });
12
39
  const dims = useDims(ref);
13
- const formatX = useCallback((v) => formatXProp?.(v) ??
14
- (v >= 1e3 ? `${v / 1e3}k` : `${v}`), [formatXProp]);
15
- const formatY = useCallback((v) => formatYProp?.(v) ?? `${Math.round(v * 100)}%`, [formatYProp]);
40
+ const formatX = useCallback(
41
+ (v) => formatXProp?.(v) ?? (v >= 1e3 ? `${v / 1e3}k` : `${v}`),
42
+ [formatXProp]
43
+ );
44
+ const formatY = useCallback(
45
+ (v) => formatYProp?.(v) ?? `${Math.round(v * 100)}%`,
46
+ [formatYProp]
47
+ );
16
48
  const getX = useMemo(() => accessor(x), [x]);
17
49
  const getY = useMemo(() => accessor(y), [y]);
18
50
  const getZ = useCallback((d) => d[series], [series]);
19
51
  useEffect(() => {
20
- if (!ref.current ||
21
- !plotRef.current ||
22
- !data.length ||
23
- !dims.h ||
24
- !dims.w) {
25
- return;
52
+ if (!ref.current || !plotRef.current || !data.length || !dims.h || !dims.w) {
53
+ return;
54
+ }
55
+ plotRef.current.innerHTML = "";
56
+ const hasSeries = data.some((d) => d[series] !== void 0);
57
+ const seriesIdx = hasSeries ? data.reduce(
58
+ (acc, d, i) => (acc[d[series]] ??= i, acc),
59
+ {}
60
+ ) : {};
61
+ const n = Object.keys(seriesIdx).length;
62
+ const opacity = (d) => {
63
+ if (!hasSeries) {
64
+ return 1;
26
65
  }
27
- plotRef.current.innerHTML = '';
28
- const hasSeries = data.some(d => d[series] !== undefined);
29
- const seriesIdx = hasSeries
30
- ? data.reduce((acc, d, i) => { var _a; return ((acc[_a = d[series]] ?? (acc[_a] = i)), acc); }, {})
31
- : {};
32
- const n = Object.keys(seriesIdx).length;
33
- const opacity = (d) => {
34
- if (!hasSeries) {
35
- return 1;
36
- }
37
- if (hovered) {
38
- return d[series] === hovered[series] ? 1 : 0.2;
39
- }
40
- return 1 - (seriesIdx[d[series]] / Math.max(n - 1, 1)) * 0.2;
41
- };
42
- const lineOpts = {
43
- curve,
44
- x: getX,
45
- y: getY,
46
- ...(hasSeries && { z: getZ })
47
- };
48
- const plot = Plot.plot({
49
- ...CHART_MARGINS,
50
- height: dims.h,
51
- marks: [
52
- ...(showArea
53
- ? [
54
- Plot.areaY(data, {
55
- ...lineOpts,
56
- fill: strokeColor,
57
- fillOpacity: 0.15,
58
- y1: yDomain[0]
59
- })
60
- ]
61
- : []),
62
- Plot.lineY(data, {
63
- ...lineOpts,
64
- stroke: 'transparent',
65
- strokeWidth: 16
66
- }),
67
- Plot.lineY(data, {
68
- ...lineOpts,
69
- stroke: strokeColor,
70
- strokeOpacity: opacity,
71
- strokeWidth: 1.5
72
- })
73
- ],
74
- style: { ...CHART_STYLE, fontStretch: 'expanded' },
75
- width: dims.w,
76
- x: { label: null, tickFormat: formatX, ticks: xTicks },
77
- y: {
78
- domain: yDomain,
79
- grid: true,
80
- label: null,
81
- tickFormat: formatY,
82
- ticks: yTicks
83
- }
84
- });
85
- plot.addEventListener('input', () => setHovered(plot.value));
86
- stylePlot(plot);
87
- plot.querySelectorAll('g[aria-label="line"] path').forEach(el => Object.assign(el.style, {
88
- transition: 'stroke-opacity 0.2s'
89
- }));
90
- plotRef.current.appendChild(plot);
91
- const cleanup = setupCrosshair(ref.current, data, d => getX(d), getY, yDomain, d => formatTooltip?.(d) ?? `${formatX(getX(d))}: ${formatY(getY(d))}`, setCrosshair, hasSeries ? d => getZ(d) : undefined);
92
- return () => {
93
- cleanup();
94
- plot.parentNode && plot.remove();
95
- };
96
- }, [
66
+ if (hovered) {
67
+ return d[series] === hovered[series] ? 1 : 0.2;
68
+ }
69
+ return 1 - seriesIdx[d[series]] / Math.max(n - 1, 1) * 0.2;
70
+ };
71
+ const lineOpts = {
97
72
  curve,
73
+ x: getX,
74
+ y: getY,
75
+ ...hasSeries && { z: getZ }
76
+ };
77
+ const plot = Plot.plot({
78
+ ...CHART_MARGINS,
79
+ height: dims.h,
80
+ marks: [
81
+ ...showArea ? [
82
+ Plot.areaY(data, {
83
+ ...lineOpts,
84
+ fill: strokeColor,
85
+ fillOpacity: 0.15,
86
+ y1: yDomain[0]
87
+ })
88
+ ] : [],
89
+ Plot.lineY(data, {
90
+ ...lineOpts,
91
+ stroke: "transparent",
92
+ strokeWidth: 16
93
+ }),
94
+ Plot.lineY(data, {
95
+ ...lineOpts,
96
+ stroke: strokeColor,
97
+ strokeOpacity: opacity,
98
+ strokeWidth: 1.5
99
+ })
100
+ ],
101
+ style: { ...CHART_STYLE, fontStretch: "expanded" },
102
+ width: dims.w,
103
+ x: { label: null, tickFormat: formatX, ticks: xTicks },
104
+ y: {
105
+ domain: yDomain,
106
+ grid: true,
107
+ label: null,
108
+ tickFormat: formatY,
109
+ ticks: yTicks
110
+ }
111
+ });
112
+ plot.addEventListener("input", () => setHovered(plot.value));
113
+ stylePlot(plot);
114
+ plot.querySelectorAll('g[aria-label="line"] path').forEach(
115
+ (el) => Object.assign(el.style, {
116
+ transition: "stroke-opacity 0.2s"
117
+ })
118
+ );
119
+ plotRef.current.appendChild(plot);
120
+ const cleanup = setupCrosshair(
121
+ ref.current,
98
122
  data,
99
- dims.h,
100
- dims.w,
101
- formatTooltip,
102
- formatX,
103
- formatY,
104
- getX,
123
+ (d) => getX(d),
105
124
  getY,
106
- getZ,
107
- hovered,
108
- series,
109
- showArea,
110
- strokeColor,
111
- xTicks,
112
125
  yDomain,
113
- yTicks
126
+ (d) => formatTooltip?.(d) ?? `${formatX(getX(d))}: ${formatY(getY(d))}`,
127
+ setCrosshair,
128
+ hasSeries ? (d) => getZ(d) : void 0
129
+ );
130
+ return () => {
131
+ cleanup();
132
+ plot.parentNode && plot.remove();
133
+ };
134
+ }, [
135
+ curve,
136
+ data,
137
+ dims.h,
138
+ dims.w,
139
+ formatTooltip,
140
+ formatX,
141
+ formatY,
142
+ getX,
143
+ getY,
144
+ getZ,
145
+ hovered,
146
+ series,
147
+ showArea,
148
+ strokeColor,
149
+ xTicks,
150
+ yDomain,
151
+ yTicks
114
152
  ]);
115
- return (_jsxs("div", { className: cn('relative aspect-4/1 w-full overflow-clip', className), ref: ref, ...props, children: [_jsx("div", { className: "absolute inset-0", ref: plotRef }), _jsx(Crosshair, { color: strokeColor, containerWidth: dims.w, height: dims.h, ...crosshair })] }));
116
- });
117
- //# sourceMappingURL=line-chart.js.map
153
+ return /* @__PURE__ */ jsxs(
154
+ "div",
155
+ {
156
+ className: cn("relative aspect-4/1 w-full overflow-clip", className),
157
+ ref,
158
+ ...props,
159
+ children: [
160
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0", ref: plotRef }),
161
+ /* @__PURE__ */ jsx(
162
+ Crosshair,
163
+ {
164
+ color: strokeColor,
165
+ containerWidth: dims.w,
166
+ height: dims.h,
167
+ ...crosshair
168
+ }
169
+ )
170
+ ]
171
+ }
172
+ );
173
+ }
174
+ );
@@ -23,10 +23,10 @@ export declare const Crosshair: ({ color, containerWidth, height, points, x }: C
23
23
  color?: string;
24
24
  containerWidth: number;
25
25
  height: number;
26
- }) => import("react/jsx-runtime").JSX.Element | null;
26
+ }) => import("react").JSX.Element | null;
27
27
  export declare const setupCrosshair: <T extends DataPoint>(container: HTMLElement, data: T[], getX: (d: T) => number, getY: (d: T) => number, yDomain: [number, number], formatTooltip: (d: T) => string, onUpdate: (state: CrosshairState) => void, getZ?: (d: T) => unknown) => () => void;
28
28
  export declare const withChartBlend: <P extends BlendModeProps>(Component: ComponentType<P>) => {
29
- (props: Omit<P, keyof BlendColors>): import("react/jsx-runtime").JSX.Element;
29
+ (props: Omit<P, keyof BlendColors>): import("react").JSX.Element;
30
30
  displayName: string;
31
31
  };
32
32
  export type DataPoint = Record<string, unknown>;
@@ -50,4 +50,3 @@ export interface ChartProps<T = DataPoint> extends Omit<HTMLAttributes<HTMLDivEl
50
50
  yDomain?: [number, number];
51
51
  yTicks?: number | number[];
52
52
  }
53
- //# sourceMappingURL=utils.d.ts.map
@@ -1,128 +1,161 @@
1
- 'use client';
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useState } from 'react';
4
- import { useSmoothControls } from '../../../hooks/use-smooth-controls';
5
- export const accessor = (key) => typeof key === 'function' ? key : (d) => d[key];
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import {
4
+ useEffect,
5
+ useState
6
+ } from "react";
7
+ import { useSmoothControls } from "../../../hooks/use-smooth-controls.js";
8
+ export const accessor = (key) => typeof key === "function" ? key : (d) => d[key];
6
9
  export const CHART_MARGINS = {
7
- marginBottom: 24,
8
- marginLeft: 36,
9
- marginRight: 12,
10
- marginTop: 8
10
+ marginBottom: 24,
11
+ marginLeft: 36,
12
+ marginRight: 12,
13
+ marginTop: 8
11
14
  };
12
15
  export const CHART_STYLE = {
13
- background: 'transparent',
14
- color: 'var(--midground)',
15
- fontFamily: 'var(--font-mono), monospace',
16
- fontSize: '11px',
17
- overflow: 'hidden'
16
+ background: "transparent",
17
+ color: "var(--midground)",
18
+ fontFamily: "var(--font-mono), monospace",
19
+ fontSize: "11px",
20
+ overflow: "hidden"
18
21
  };
19
22
  export const stylePlot = (plot) => {
20
- plot.querySelectorAll('[aria-label*="grid"] line').forEach(el => Object.assign(el.style, {
21
- stroke: 'currentColor',
22
- strokeDasharray: '2,4',
23
- strokeOpacity: '0.3'
24
- }));
25
- plot.querySelectorAll('text').forEach(el => Object.assign(el.style, {
26
- fontSize: '11px',
27
- fontWeight: '600'
28
- }));
29
- plot
30
- .querySelectorAll('[aria-label*="label"] text')
31
- .forEach(el => (el.style.opacity = '0.4'));
32
- const svg = plot.querySelector('svg');
33
- svg && (svg.style.display = 'block');
23
+ plot.querySelectorAll('[aria-label*="grid"] line').forEach(
24
+ (el) => Object.assign(el.style, {
25
+ stroke: "currentColor",
26
+ strokeDasharray: "2,4",
27
+ strokeOpacity: "0.3"
28
+ })
29
+ );
30
+ plot.querySelectorAll("text").forEach(
31
+ (el) => Object.assign(el.style, {
32
+ fontSize: "11px",
33
+ fontWeight: "600"
34
+ })
35
+ );
36
+ plot.querySelectorAll('[aria-label*="label"] text').forEach((el) => el.style.opacity = "0.4");
37
+ const svg = plot.querySelector("svg");
38
+ svg && (svg.style.display = "block");
34
39
  };
35
40
  export const useDims = (ref) => {
36
- const [dims, setDims] = useState({ h: 0, w: 0 });
37
- useEffect(() => {
38
- if (!ref.current) {
39
- return;
40
- }
41
- const update = () => {
42
- const { height: h, width: w } = ref.current.getBoundingClientRect();
43
- const [rh, rw] = [Math.round(h), Math.round(w)];
44
- rh &&
45
- rw &&
46
- setDims(st => (st.h === rh && st.w === rw ? st : { h: rh, w: rw }));
47
- };
48
- update();
49
- const ro = new ResizeObserver(update);
50
- ro.observe(ref.current);
51
- return () => ro.disconnect();
52
- }, [ref]);
53
- return dims;
54
- };
55
- export const Crosshair = ({ color = 'var(--foreground)', containerWidth, height, points, x }) => {
56
- if (x === null) {
57
- return null;
41
+ const [dims, setDims] = useState({ h: 0, w: 0 });
42
+ useEffect(() => {
43
+ if (!ref.current) {
44
+ return;
58
45
  }
59
- const nearRight = x > containerWidth * 0.7;
60
- return (_jsxs(_Fragment, { children: [_jsx("div", { className: "pointer-events-none absolute top-0 w-px", style: { background: color, height, left: x, opacity: 0.4 } }), points?.map((pt, i) => (_jsx("div", { className: "pointer-events-none absolute size-2 -translate-x-1/2 -translate-y-1/2 rounded-full", style: { background: color, left: x, top: pt.dotY } }, i))), points?.map((pt, i) => (_jsx("div", { className: "tooltip absolute -translate-y-1/2", style: {
61
- left: nearRight ? undefined : x + 12,
62
- right: nearRight ? containerWidth - x + 12 : undefined,
63
- top: pt.dotY
64
- }, children: pt.tooltip }, i)))] }));
46
+ const update = () => {
47
+ const { height: h, width: w } = ref.current.getBoundingClientRect();
48
+ const [rh, rw] = [Math.round(h), Math.round(w)];
49
+ rh && rw && setDims((st) => st.h === rh && st.w === rw ? st : { h: rh, w: rw });
50
+ };
51
+ update();
52
+ const ro = new ResizeObserver(update);
53
+ ro.observe(ref.current);
54
+ return () => ro.disconnect();
55
+ }, [ref]);
56
+ return dims;
57
+ };
58
+ export const Crosshair = ({
59
+ color = "var(--foreground)",
60
+ containerWidth,
61
+ height,
62
+ points,
63
+ x
64
+ }) => {
65
+ if (x === null) {
66
+ return null;
67
+ }
68
+ const nearRight = x > containerWidth * 0.7;
69
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
70
+ /* @__PURE__ */ jsx(
71
+ "div",
72
+ {
73
+ className: "pointer-events-none absolute top-0 w-px",
74
+ style: { background: color, height, left: x, opacity: 0.4 }
75
+ }
76
+ ),
77
+ points?.map((pt, i) => /* @__PURE__ */ jsx(
78
+ "div",
79
+ {
80
+ className: "pointer-events-none absolute size-2 -translate-x-1/2 -translate-y-1/2 rounded-full",
81
+ style: { background: color, left: x, top: pt.dotY }
82
+ },
83
+ i
84
+ )),
85
+ points?.map((pt, i) => /* @__PURE__ */ jsx(
86
+ "div",
87
+ {
88
+ className: "tooltip absolute -translate-y-1/2",
89
+ style: {
90
+ left: nearRight ? void 0 : x + 12,
91
+ right: nearRight ? containerWidth - x + 12 : void 0,
92
+ top: pt.dotY
93
+ },
94
+ children: pt.tooltip
95
+ },
96
+ i
97
+ ))
98
+ ] });
65
99
  };
66
100
  export const setupCrosshair = (container, data, getX, getY, yDomain, formatTooltip, onUpdate, getZ) => {
67
- if (!data.length) {
68
- return () => { };
69
- }
70
- const { marginBottom, marginLeft, marginRight, marginTop } = CHART_MARGINS;
71
- const seriesMap = data.reduce((m, d) => {
72
- const key = getZ?.(d) ?? '__single__';
73
- m.set(key, [...(m.get(key) ?? []), d]);
74
- return m;
75
- }, new Map());
76
- const sortedSeries = [...seriesMap.values()].map(s => [...s].sort((a, b) => getX(a) - getX(b)));
77
- const allX = data.map(getX);
78
- const [xMin, xMax] = [Math.min(...allX), Math.max(...allX)];
79
- const onMove = (e) => {
80
- const rect = container.getBoundingClientRect();
81
- const [localX, localY] = [e.clientX - rect.left, e.clientY - rect.top];
82
- if (localX < 0 ||
83
- localX > rect.width ||
84
- localY < 0 ||
85
- localY > rect.height) {
86
- return onUpdate({ x: null });
87
- }
88
- const [chartLeft, chartRight] = [marginLeft, rect.width - marginRight];
89
- const [chartTop, chartBottom] = [marginTop, rect.height - marginBottom];
90
- if (localX < chartLeft || localX > chartRight) {
91
- return onUpdate({ x: null });
92
- }
93
- const pct = (localX - chartLeft) / (chartRight - chartLeft);
94
- const xVal = xMin + pct * (xMax - xMin);
95
- const points = sortedSeries.map(sorted => {
96
- const idx = sorted.findIndex(d => getX(d) >= xVal);
97
- const [closest, yVal] = idx <= 0
98
- ? [sorted[0], getY(sorted[0])]
99
- : idx >= sorted.length
100
- ? [sorted.at(-1), getY(sorted.at(-1))]
101
- : (() => {
102
- const [left, right] = [sorted[idx - 1], sorted[idx]];
103
- const t = (xVal - getX(left)) / (getX(right) - getX(left));
104
- return [
105
- t < 0.5 ? left : right,
106
- getY(left) + t * (getY(right) - getY(left))
107
- ];
108
- })();
109
- const yPct = (yVal - yDomain[0]) / (yDomain[1] - yDomain[0]);
110
- return {
111
- dotY: chartBottom - yPct * (chartBottom - chartTop),
112
- tooltip: formatTooltip(closest)
113
- };
114
- });
115
- onUpdate({ points, x: localX });
101
+ if (!data.length) {
102
+ return () => {
116
103
  };
117
- document.addEventListener('mousemove', onMove);
118
- return () => document.removeEventListener('mousemove', onMove);
104
+ }
105
+ const { marginBottom, marginLeft, marginRight, marginTop } = CHART_MARGINS;
106
+ const seriesMap = data.reduce((m, d) => {
107
+ const key = getZ?.(d) ?? "__single__";
108
+ m.set(key, [...m.get(key) ?? [], d]);
109
+ return m;
110
+ }, /* @__PURE__ */ new Map());
111
+ const sortedSeries = [...seriesMap.values()].map(
112
+ (s) => [...s].sort((a, b) => getX(a) - getX(b))
113
+ );
114
+ const allX = data.map(getX);
115
+ const [xMin, xMax] = [Math.min(...allX), Math.max(...allX)];
116
+ const onMove = (e) => {
117
+ const rect = container.getBoundingClientRect();
118
+ const [localX, localY] = [e.clientX - rect.left, e.clientY - rect.top];
119
+ if (localX < 0 || localX > rect.width || localY < 0 || localY > rect.height) {
120
+ return onUpdate({ x: null });
121
+ }
122
+ const [chartLeft, chartRight] = [marginLeft, rect.width - marginRight];
123
+ const [chartTop, chartBottom] = [marginTop, rect.height - marginBottom];
124
+ if (localX < chartLeft || localX > chartRight) {
125
+ return onUpdate({ x: null });
126
+ }
127
+ const pct = (localX - chartLeft) / (chartRight - chartLeft);
128
+ const xVal = xMin + pct * (xMax - xMin);
129
+ const points = sortedSeries.map((sorted) => {
130
+ const idx = sorted.findIndex((d) => getX(d) >= xVal);
131
+ const [closest, yVal] = idx <= 0 ? [sorted[0], getY(sorted[0])] : idx >= sorted.length ? [sorted.at(-1), getY(sorted.at(-1))] : (() => {
132
+ const [left, right] = [sorted[idx - 1], sorted[idx]];
133
+ const t = (xVal - getX(left)) / (getX(right) - getX(left));
134
+ return [
135
+ t < 0.5 ? left : right,
136
+ getY(left) + t * (getY(right) - getY(left))
137
+ ];
138
+ })();
139
+ const yPct = (yVal - yDomain[0]) / (yDomain[1] - yDomain[0]);
140
+ return {
141
+ dotY: chartBottom - yPct * (chartBottom - chartTop),
142
+ tooltip: formatTooltip(closest)
143
+ };
144
+ });
145
+ onUpdate({ points, x: localX });
146
+ };
147
+ document.addEventListener("mousemove", onMove);
148
+ return () => document.removeEventListener("mousemove", onMove);
119
149
  };
120
150
  export const withChartBlend = (Component) => {
121
- const Wrapped = (props) => {
122
- const { color } = useSmoothControls('Charts', { color: { value: '#709fea' } }, { collapsed: true });
123
- return _jsx(Component, { ...props, color: color });
124
- };
125
- Wrapped.displayName = `withChartBlend(${Component.displayName ?? Component.name})`;
126
- return Wrapped;
151
+ const Wrapped = (props) => {
152
+ const { color } = useSmoothControls(
153
+ "Charts",
154
+ { color: { value: "#709fea" } },
155
+ { collapsed: true }
156
+ );
157
+ return /* @__PURE__ */ jsx(Component, { ...props, color });
158
+ };
159
+ Wrapped.displayName = `withChartBlend(${Component.displayName ?? Component.name})`;
160
+ return Wrapped;
127
161
  };
128
- //# sourceMappingURL=utils.js.map
@@ -1,3 +1,2 @@
1
1
  export declare const Grid: import("../../..").PolyComponent<"div", object>;
2
2
  export declare const Cell: import("../../..").PolyComponent<"div", object>;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,13 +1,16 @@
1
- import { createElement } from 'react';
2
- import { cn, polyRef } from '../../../utils';
3
- export const Grid = polyRef(({ as, className, ...rest }, ref) => createElement((as ?? 'div'), {
1
+ import { createElement } from "react";
2
+ import { cn, polyRef } from "../../../utils/index.js";
3
+ export const Grid = polyRef(
4
+ ({ as, className, ...rest }, ref) => createElement(as ?? "div", {
4
5
  ...rest,
5
- className: cn('g', className),
6
+ className: cn("g", className),
6
7
  ref
7
- }));
8
- export const Cell = polyRef(({ as, className, ...rest }, ref) => createElement((as ?? 'div'), {
8
+ })
9
+ );
10
+ export const Cell = polyRef(
11
+ ({ as, className, ...rest }, ref) => createElement(as ?? "div", {
9
12
  ...rest,
10
- className: cn('gc', className),
13
+ className: cn("gc", className),
11
14
  ref
12
- }));
13
- //# sourceMappingURL=index.js.map
15
+ })
16
+ );
@@ -1,2 +1 @@
1
1
  export declare const HoverBg: import("../..").PolyComponent<"span", object>;
2
- //# sourceMappingURL=hover-bg.d.ts.map
@@ -1,8 +1,13 @@
1
- import { createElement } from 'react';
2
- import { cn, polyRef } from '../../utils';
3
- export const HoverBg = polyRef(({ as, className, ...rest }, ref) => createElement((as ?? 'span'), {
1
+ import { createElement } from "react";
2
+ import { cn, polyRef } from "../../utils/index.js";
3
+ export const HoverBg = polyRef(
4
+ ({ as, className, ...rest }, ref) => createElement(as ?? "span", {
4
5
  ...rest,
5
- className: cn('absolute inset-1 bg-midground pointer-events-none', 'opacity-5 transition-opacity duration-250 group-hover:opacity-5 opacity-0 group-hover:duration-0', className),
6
+ className: cn(
7
+ "absolute inset-1 bg-midground pointer-events-none",
8
+ "opacity-5 transition-opacity duration-250 group-hover:opacity-5 opacity-0 group-hover:duration-0",
9
+ className
10
+ ),
6
11
  ref
7
- }));
8
- //# sourceMappingURL=hover-bg.js.map
12
+ })
13
+ );
@@ -1,7 +1,6 @@
1
1
  import type { SVGProps } from 'react';
2
- export declare function ArrowIcon({ className, direction, ...props }: ArrowIconProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function ArrowIcon({ className, direction, ...props }: ArrowIconProps): import("react").JSX.Element;
3
3
  interface ArrowIconProps extends SVGProps<SVGSVGElement> {
4
4
  direction?: 'down' | 'left' | 'right' | 'up';
5
5
  }
6
6
  export {};
7
- //# sourceMappingURL=arrow.d.ts.map