itsi 0.2.15 → 0.2.17

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 (182) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/Cargo.lock +76 -74
  4. data/crates/itsi_acme/Cargo.toml +1 -1
  5. data/crates/itsi_scheduler/Cargo.toml +1 -1
  6. data/crates/itsi_scheduler/extconf.rb +3 -1
  7. data/crates/itsi_server/Cargo.lock +1 -1
  8. data/crates/itsi_server/Cargo.toml +3 -1
  9. data/crates/itsi_server/extconf.rb +3 -1
  10. data/crates/itsi_server/src/lib.rs +7 -1
  11. data/crates/itsi_server/src/ruby_types/itsi_body_proxy/mod.rs +2 -0
  12. data/crates/itsi_server/src/ruby_types/itsi_grpc_call.rs +6 -6
  13. data/crates/itsi_server/src/ruby_types/itsi_grpc_response_stream/mod.rs +14 -13
  14. data/crates/itsi_server/src/ruby_types/itsi_http_request.rs +71 -42
  15. data/crates/itsi_server/src/ruby_types/itsi_http_response.rs +151 -152
  16. data/crates/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +6 -15
  17. data/crates/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +32 -6
  18. data/crates/itsi_server/src/ruby_types/itsi_server.rs +1 -1
  19. data/crates/itsi_server/src/server/binds/listener.rs +49 -8
  20. data/crates/itsi_server/src/server/frame_stream.rs +142 -0
  21. data/crates/itsi_server/src/server/http_message_types.rs +143 -10
  22. data/crates/itsi_server/src/server/io_stream.rs +28 -5
  23. data/crates/itsi_server/src/server/lifecycle_event.rs +1 -1
  24. data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_basic.rs +2 -3
  25. data/crates/itsi_server/src/server/middleware_stack/middlewares/compression.rs +8 -10
  26. data/crates/itsi_server/src/server/middleware_stack/middlewares/cors.rs +2 -3
  27. data/crates/itsi_server/src/server/middleware_stack/middlewares/csp.rs +3 -3
  28. data/crates/itsi_server/src/server/middleware_stack/middlewares/error_response/default_responses.rs +54 -58
  29. data/crates/itsi_server/src/server/middleware_stack/middlewares/error_response.rs +6 -9
  30. data/crates/itsi_server/src/server/middleware_stack/middlewares/etag.rs +27 -42
  31. data/crates/itsi_server/src/server/middleware_stack/middlewares/log_requests.rs +65 -14
  32. data/crates/itsi_server/src/server/middleware_stack/middlewares/max_body.rs +1 -1
  33. data/crates/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +8 -11
  34. data/crates/itsi_server/src/server/middleware_stack/middlewares/rate_limit.rs +21 -8
  35. data/crates/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +2 -3
  36. data/crates/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +1 -5
  37. data/crates/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +1 -2
  38. data/crates/itsi_server/src/server/middleware_stack/middlewares/static_response.rs +13 -6
  39. data/crates/itsi_server/src/server/mod.rs +1 -0
  40. data/crates/itsi_server/src/server/process_worker.rs +5 -5
  41. data/crates/itsi_server/src/server/serve_strategy/acceptor.rs +100 -0
  42. data/crates/itsi_server/src/server/serve_strategy/cluster_mode.rs +87 -31
  43. data/crates/itsi_server/src/server/serve_strategy/mod.rs +1 -0
  44. data/crates/itsi_server/src/server/serve_strategy/single_mode.rs +166 -206
  45. data/crates/itsi_server/src/server/signal.rs +37 -9
  46. data/crates/itsi_server/src/server/thread_worker.rs +92 -70
  47. data/crates/itsi_server/src/services/itsi_http_service.rs +67 -62
  48. data/crates/itsi_server/src/services/mime_types.rs +185 -183
  49. data/crates/itsi_server/src/services/rate_limiter.rs +16 -34
  50. data/crates/itsi_server/src/services/static_file_server.rs +35 -60
  51. data/docs/benchmark-dashboard/.gitignore +27 -0
  52. data/docs/benchmark-dashboard/app/api/benchmarks/route.ts +22 -0
  53. data/docs/benchmark-dashboard/app/globals.css +94 -0
  54. data/docs/benchmark-dashboard/app/layout.tsx +20 -0
  55. data/docs/benchmark-dashboard/app/page.tsx +252 -0
  56. data/docs/benchmark-dashboard/components/benchmark-dashboard.tsx +1663 -0
  57. data/docs/benchmark-dashboard/components/theme-provider.tsx +11 -0
  58. data/docs/benchmark-dashboard/components/ui/accordion.tsx +58 -0
  59. data/docs/benchmark-dashboard/components/ui/alert-dialog.tsx +141 -0
  60. data/docs/benchmark-dashboard/components/ui/alert.tsx +59 -0
  61. data/docs/benchmark-dashboard/components/ui/aspect-ratio.tsx +7 -0
  62. data/docs/benchmark-dashboard/components/ui/avatar.tsx +50 -0
  63. data/docs/benchmark-dashboard/components/ui/badge.tsx +36 -0
  64. data/docs/benchmark-dashboard/components/ui/breadcrumb.tsx +115 -0
  65. data/docs/benchmark-dashboard/components/ui/button.tsx +56 -0
  66. data/docs/benchmark-dashboard/components/ui/calendar.tsx +66 -0
  67. data/docs/benchmark-dashboard/components/ui/card.tsx +79 -0
  68. data/docs/benchmark-dashboard/components/ui/carousel.tsx +262 -0
  69. data/docs/benchmark-dashboard/components/ui/chart.tsx +365 -0
  70. data/docs/benchmark-dashboard/components/ui/checkbox.tsx +30 -0
  71. data/docs/benchmark-dashboard/components/ui/collapsible.tsx +11 -0
  72. data/docs/benchmark-dashboard/components/ui/command.tsx +153 -0
  73. data/docs/benchmark-dashboard/components/ui/context-menu.tsx +200 -0
  74. data/docs/benchmark-dashboard/components/ui/dialog.tsx +122 -0
  75. data/docs/benchmark-dashboard/components/ui/drawer.tsx +118 -0
  76. data/docs/benchmark-dashboard/components/ui/dropdown-menu.tsx +200 -0
  77. data/docs/benchmark-dashboard/components/ui/form.tsx +178 -0
  78. data/docs/benchmark-dashboard/components/ui/hover-card.tsx +29 -0
  79. data/docs/benchmark-dashboard/components/ui/input-otp.tsx +71 -0
  80. data/docs/benchmark-dashboard/components/ui/input.tsx +22 -0
  81. data/docs/benchmark-dashboard/components/ui/label.tsx +26 -0
  82. data/docs/benchmark-dashboard/components/ui/loading-spinner.tsx +12 -0
  83. data/docs/benchmark-dashboard/components/ui/menubar.tsx +236 -0
  84. data/docs/benchmark-dashboard/components/ui/navigation-menu.tsx +128 -0
  85. data/docs/benchmark-dashboard/components/ui/pagination.tsx +117 -0
  86. data/docs/benchmark-dashboard/components/ui/popover.tsx +31 -0
  87. data/docs/benchmark-dashboard/components/ui/progress.tsx +28 -0
  88. data/docs/benchmark-dashboard/components/ui/radio-group.tsx +44 -0
  89. data/docs/benchmark-dashboard/components/ui/resizable.tsx +45 -0
  90. data/docs/benchmark-dashboard/components/ui/scroll-area.tsx +48 -0
  91. data/docs/benchmark-dashboard/components/ui/select.tsx +160 -0
  92. data/docs/benchmark-dashboard/components/ui/separator.tsx +31 -0
  93. data/docs/benchmark-dashboard/components/ui/sheet.tsx +140 -0
  94. data/docs/benchmark-dashboard/components/ui/sidebar.tsx +763 -0
  95. data/docs/benchmark-dashboard/components/ui/skeleton.tsx +15 -0
  96. data/docs/benchmark-dashboard/components/ui/slider.tsx +28 -0
  97. data/docs/benchmark-dashboard/components/ui/sonner.tsx +31 -0
  98. data/docs/benchmark-dashboard/components/ui/switch.tsx +29 -0
  99. data/docs/benchmark-dashboard/components/ui/table.tsx +117 -0
  100. data/docs/benchmark-dashboard/components/ui/tabs.tsx +55 -0
  101. data/docs/benchmark-dashboard/components/ui/textarea.tsx +22 -0
  102. data/docs/benchmark-dashboard/components/ui/toast.tsx +129 -0
  103. data/docs/benchmark-dashboard/components/ui/toaster.tsx +35 -0
  104. data/docs/benchmark-dashboard/components/ui/toggle-group.tsx +61 -0
  105. data/docs/benchmark-dashboard/components/ui/toggle.tsx +45 -0
  106. data/docs/benchmark-dashboard/components/ui/tooltip.tsx +30 -0
  107. data/docs/benchmark-dashboard/components/ui/use-mobile.tsx +19 -0
  108. data/docs/benchmark-dashboard/components/ui/use-toast.ts +194 -0
  109. data/docs/benchmark-dashboard/components.json +21 -0
  110. data/docs/benchmark-dashboard/dist/benchmark-dashboard.css +1 -0
  111. data/docs/benchmark-dashboard/dist/benchmark-dashboard.iife.js +211 -0
  112. data/docs/benchmark-dashboard/dist/placeholder-logo.png +0 -0
  113. data/docs/benchmark-dashboard/dist/placeholder-logo.svg +1 -0
  114. data/docs/benchmark-dashboard/dist/placeholder-user.jpg +0 -0
  115. data/docs/benchmark-dashboard/dist/placeholder.jpg +0 -0
  116. data/docs/benchmark-dashboard/dist/placeholder.svg +1 -0
  117. data/docs/benchmark-dashboard/embed.tsx +13 -0
  118. data/docs/benchmark-dashboard/hooks/use-mobile.tsx +19 -0
  119. data/docs/benchmark-dashboard/hooks/use-toast.ts +194 -0
  120. data/docs/benchmark-dashboard/lib/benchmark-utils.ts +54 -0
  121. data/docs/benchmark-dashboard/lib/utils.ts +6 -0
  122. data/docs/benchmark-dashboard/next.config.mjs +14 -0
  123. data/docs/benchmark-dashboard/package-lock.json +5859 -0
  124. data/docs/benchmark-dashboard/package.json +72 -0
  125. data/docs/benchmark-dashboard/pnpm-lock.yaml +5 -0
  126. data/docs/benchmark-dashboard/postcss.config.mjs +8 -0
  127. data/docs/benchmark-dashboard/styles/globals.css +94 -0
  128. data/docs/benchmark-dashboard/tailwind.config.ts +96 -0
  129. data/docs/benchmark-dashboard/tsconfig.json +27 -0
  130. data/docs/benchmark-dashboard/vite.config.ts +24 -0
  131. data/docs/build.rb +52 -0
  132. data/docs/content/benchmarks/index.md +96 -0
  133. data/docs/content/features/_index.md +1 -1
  134. data/docs/content/getting_started/_index.md +76 -46
  135. data/docs/hugo.yaml +3 -0
  136. data/docs/static/results.json +1 -0
  137. data/docs/static/scripts/benchmark-dashboard.iife.js +211 -0
  138. data/docs/static/styles/benchmark-dashboard.css +1 -0
  139. data/examples/rails_with_static_assets/Gemfile.lock +1 -1
  140. data/examples/rails_with_static_assets/Itsi.rb +4 -1
  141. data/gems/scheduler/Cargo.lock +15 -15
  142. data/gems/scheduler/lib/itsi/scheduler/version.rb +1 -1
  143. data/gems/server/Cargo.lock +75 -73
  144. data/gems/server/exe/itsi +6 -1
  145. data/gems/server/lib/itsi/http_request.rb +31 -39
  146. data/gems/server/lib/itsi/http_response.rb +5 -0
  147. data/gems/server/lib/itsi/rack_env_pool.rb +59 -0
  148. data/gems/server/lib/itsi/server/config/config_helpers.rb +1 -2
  149. data/gems/server/lib/itsi/server/config/dsl.rb +5 -4
  150. data/gems/server/lib/itsi/server/config/middleware/etag.md +3 -7
  151. data/gems/server/lib/itsi/server/config/middleware/etag.rb +2 -4
  152. data/gems/server/lib/itsi/server/config/middleware/proxy.rb +1 -1
  153. data/gems/server/lib/itsi/server/config/middleware/rackup_file.rb +2 -2
  154. data/gems/server/lib/itsi/server/config/options/auto_reload_config.rb +6 -2
  155. data/gems/server/lib/itsi/server/config/options/include.rb +5 -2
  156. data/gems/server/lib/itsi/server/config/options/listen_backlog.rb +1 -1
  157. data/gems/server/lib/itsi/server/config/options/pipeline_flush.md +16 -0
  158. data/gems/server/lib/itsi/server/config/options/pipeline_flush.rb +19 -0
  159. data/gems/server/lib/itsi/server/config/options/send_buffer_size.md +15 -0
  160. data/gems/server/lib/itsi/server/config/options/send_buffer_size.rb +19 -0
  161. data/gems/server/lib/itsi/server/config/options/writev.md +25 -0
  162. data/gems/server/lib/itsi/server/config/options/writev.rb +19 -0
  163. data/gems/server/lib/itsi/server/config.rb +43 -31
  164. data/gems/server/lib/itsi/server/default_config/Itsi.rb +1 -4
  165. data/gems/server/lib/itsi/server/grpc/grpc_call.rb +2 -0
  166. data/gems/server/lib/itsi/server/grpc/grpc_interface.rb +2 -2
  167. data/gems/server/lib/itsi/server/rack/handler/itsi.rb +3 -1
  168. data/gems/server/lib/itsi/server/rack_interface.rb +17 -12
  169. data/gems/server/lib/itsi/server/route_tester.rb +1 -1
  170. data/gems/server/lib/itsi/server/scheduler_interface.rb +2 -0
  171. data/gems/server/lib/itsi/server/version.rb +1 -1
  172. data/gems/server/lib/itsi/server.rb +1 -0
  173. data/gems/server/lib/ruby_lsp/itsi/addon.rb +12 -13
  174. data/gems/server/test/helpers/test_helper.rb +12 -13
  175. data/gems/server/test/middleware/etag.rb +3 -3
  176. data/gems/server/test/middleware/grpc/grpc.rb +13 -14
  177. data/gems/server/test/middleware/grpc/test_service_impl.rb +3 -3
  178. data/gems/server/test/middleware/proxy.rb +262 -268
  179. data/gems/server/test/options/ruby_thread_request_backlog_size.rb +2 -3
  180. data/lib/itsi/version.rb +1 -1
  181. metadata +99 -6
  182. data/tasks.txt +0 -27
@@ -0,0 +1,262 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import useEmblaCarousel, {
5
+ type UseEmblaCarouselType,
6
+ } from "embla-carousel-react"
7
+ import { ArrowLeft, ArrowRight } from "lucide-react"
8
+
9
+ import { cn } from "@/lib/utils"
10
+ import { Button } from "@/components/ui/button"
11
+
12
+ type CarouselApi = UseEmblaCarouselType[1]
13
+ type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
14
+ type CarouselOptions = UseCarouselParameters[0]
15
+ type CarouselPlugin = UseCarouselParameters[1]
16
+
17
+ type CarouselProps = {
18
+ opts?: CarouselOptions
19
+ plugins?: CarouselPlugin
20
+ orientation?: "horizontal" | "vertical"
21
+ setApi?: (api: CarouselApi) => void
22
+ }
23
+
24
+ type CarouselContextProps = {
25
+ carouselRef: ReturnType<typeof useEmblaCarousel>[0]
26
+ api: ReturnType<typeof useEmblaCarousel>[1]
27
+ scrollPrev: () => void
28
+ scrollNext: () => void
29
+ canScrollPrev: boolean
30
+ canScrollNext: boolean
31
+ } & CarouselProps
32
+
33
+ const CarouselContext = React.createContext<CarouselContextProps | null>(null)
34
+
35
+ function useCarousel() {
36
+ const context = React.useContext(CarouselContext)
37
+
38
+ if (!context) {
39
+ throw new Error("useCarousel must be used within a <Carousel />")
40
+ }
41
+
42
+ return context
43
+ }
44
+
45
+ const Carousel = React.forwardRef<
46
+ HTMLDivElement,
47
+ React.HTMLAttributes<HTMLDivElement> & CarouselProps
48
+ >(
49
+ (
50
+ {
51
+ orientation = "horizontal",
52
+ opts,
53
+ setApi,
54
+ plugins,
55
+ className,
56
+ children,
57
+ ...props
58
+ },
59
+ ref
60
+ ) => {
61
+ const [carouselRef, api] = useEmblaCarousel(
62
+ {
63
+ ...opts,
64
+ axis: orientation === "horizontal" ? "x" : "y",
65
+ },
66
+ plugins
67
+ )
68
+ const [canScrollPrev, setCanScrollPrev] = React.useState(false)
69
+ const [canScrollNext, setCanScrollNext] = React.useState(false)
70
+
71
+ const onSelect = React.useCallback((api: CarouselApi) => {
72
+ if (!api) {
73
+ return
74
+ }
75
+
76
+ setCanScrollPrev(api.canScrollPrev())
77
+ setCanScrollNext(api.canScrollNext())
78
+ }, [])
79
+
80
+ const scrollPrev = React.useCallback(() => {
81
+ api?.scrollPrev()
82
+ }, [api])
83
+
84
+ const scrollNext = React.useCallback(() => {
85
+ api?.scrollNext()
86
+ }, [api])
87
+
88
+ const handleKeyDown = React.useCallback(
89
+ (event: React.KeyboardEvent<HTMLDivElement>) => {
90
+ if (event.key === "ArrowLeft") {
91
+ event.preventDefault()
92
+ scrollPrev()
93
+ } else if (event.key === "ArrowRight") {
94
+ event.preventDefault()
95
+ scrollNext()
96
+ }
97
+ },
98
+ [scrollPrev, scrollNext]
99
+ )
100
+
101
+ React.useEffect(() => {
102
+ if (!api || !setApi) {
103
+ return
104
+ }
105
+
106
+ setApi(api)
107
+ }, [api, setApi])
108
+
109
+ React.useEffect(() => {
110
+ if (!api) {
111
+ return
112
+ }
113
+
114
+ onSelect(api)
115
+ api.on("reInit", onSelect)
116
+ api.on("select", onSelect)
117
+
118
+ return () => {
119
+ api?.off("select", onSelect)
120
+ }
121
+ }, [api, onSelect])
122
+
123
+ return (
124
+ <CarouselContext.Provider
125
+ value={{
126
+ carouselRef,
127
+ api: api,
128
+ opts,
129
+ orientation:
130
+ orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
131
+ scrollPrev,
132
+ scrollNext,
133
+ canScrollPrev,
134
+ canScrollNext,
135
+ }}
136
+ >
137
+ <div
138
+ ref={ref}
139
+ onKeyDownCapture={handleKeyDown}
140
+ className={cn("relative", className)}
141
+ role="region"
142
+ aria-roledescription="carousel"
143
+ {...props}
144
+ >
145
+ {children}
146
+ </div>
147
+ </CarouselContext.Provider>
148
+ )
149
+ }
150
+ )
151
+ Carousel.displayName = "Carousel"
152
+
153
+ const CarouselContent = React.forwardRef<
154
+ HTMLDivElement,
155
+ React.HTMLAttributes<HTMLDivElement>
156
+ >(({ className, ...props }, ref) => {
157
+ const { carouselRef, orientation } = useCarousel()
158
+
159
+ return (
160
+ <div ref={carouselRef} className="overflow-hidden">
161
+ <div
162
+ ref={ref}
163
+ className={cn(
164
+ "flex",
165
+ orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
166
+ className
167
+ )}
168
+ {...props}
169
+ />
170
+ </div>
171
+ )
172
+ })
173
+ CarouselContent.displayName = "CarouselContent"
174
+
175
+ const CarouselItem = React.forwardRef<
176
+ HTMLDivElement,
177
+ React.HTMLAttributes<HTMLDivElement>
178
+ >(({ className, ...props }, ref) => {
179
+ const { orientation } = useCarousel()
180
+
181
+ return (
182
+ <div
183
+ ref={ref}
184
+ role="group"
185
+ aria-roledescription="slide"
186
+ className={cn(
187
+ "min-w-0 shrink-0 grow-0 basis-full",
188
+ orientation === "horizontal" ? "pl-4" : "pt-4",
189
+ className
190
+ )}
191
+ {...props}
192
+ />
193
+ )
194
+ })
195
+ CarouselItem.displayName = "CarouselItem"
196
+
197
+ const CarouselPrevious = React.forwardRef<
198
+ HTMLButtonElement,
199
+ React.ComponentProps<typeof Button>
200
+ >(({ className, variant = "outline", size = "icon", ...props }, ref) => {
201
+ const { orientation, scrollPrev, canScrollPrev } = useCarousel()
202
+
203
+ return (
204
+ <Button
205
+ ref={ref}
206
+ variant={variant}
207
+ size={size}
208
+ className={cn(
209
+ "absolute h-8 w-8 rounded-full",
210
+ orientation === "horizontal"
211
+ ? "-left-12 top-1/2 -translate-y-1/2"
212
+ : "-top-12 left-1/2 -translate-x-1/2 rotate-90",
213
+ className
214
+ )}
215
+ disabled={!canScrollPrev}
216
+ onClick={scrollPrev}
217
+ {...props}
218
+ >
219
+ <ArrowLeft className="h-4 w-4" />
220
+ <span className="sr-only">Previous slide</span>
221
+ </Button>
222
+ )
223
+ })
224
+ CarouselPrevious.displayName = "CarouselPrevious"
225
+
226
+ const CarouselNext = React.forwardRef<
227
+ HTMLButtonElement,
228
+ React.ComponentProps<typeof Button>
229
+ >(({ className, variant = "outline", size = "icon", ...props }, ref) => {
230
+ const { orientation, scrollNext, canScrollNext } = useCarousel()
231
+
232
+ return (
233
+ <Button
234
+ ref={ref}
235
+ variant={variant}
236
+ size={size}
237
+ className={cn(
238
+ "absolute h-8 w-8 rounded-full",
239
+ orientation === "horizontal"
240
+ ? "-right-12 top-1/2 -translate-y-1/2"
241
+ : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
242
+ className
243
+ )}
244
+ disabled={!canScrollNext}
245
+ onClick={scrollNext}
246
+ {...props}
247
+ >
248
+ <ArrowRight className="h-4 w-4" />
249
+ <span className="sr-only">Next slide</span>
250
+ </Button>
251
+ )
252
+ })
253
+ CarouselNext.displayName = "CarouselNext"
254
+
255
+ export {
256
+ type CarouselApi,
257
+ Carousel,
258
+ CarouselContent,
259
+ CarouselItem,
260
+ CarouselPrevious,
261
+ CarouselNext,
262
+ }
@@ -0,0 +1,365 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as RechartsPrimitive from "recharts"
5
+
6
+ import { cn } from "@/lib/utils"
7
+
8
+ // Format: { THEME_NAME: CSS_SELECTOR }
9
+ const THEMES = { light: "", dark: ".dark" } as const
10
+
11
+ export type ChartConfig = {
12
+ [k in string]: {
13
+ label?: React.ReactNode
14
+ icon?: React.ComponentType
15
+ } & (
16
+ | { color?: string; theme?: never }
17
+ | { color?: never; theme: Record<keyof typeof THEMES, string> }
18
+ )
19
+ }
20
+
21
+ type ChartContextProps = {
22
+ config: ChartConfig
23
+ }
24
+
25
+ const ChartContext = React.createContext<ChartContextProps | null>(null)
26
+
27
+ function useChart() {
28
+ const context = React.useContext(ChartContext)
29
+
30
+ if (!context) {
31
+ throw new Error("useChart must be used within a <ChartContainer />")
32
+ }
33
+
34
+ return context
35
+ }
36
+
37
+ const ChartContainer = React.forwardRef<
38
+ HTMLDivElement,
39
+ React.ComponentProps<"div"> & {
40
+ config: ChartConfig
41
+ children: React.ComponentProps<
42
+ typeof RechartsPrimitive.ResponsiveContainer
43
+ >["children"]
44
+ }
45
+ >(({ id, className, children, config, ...props }, ref) => {
46
+ const uniqueId = React.useId()
47
+ const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
48
+
49
+ return (
50
+ <ChartContext.Provider value={{ config }}>
51
+ <div
52
+ data-chart={chartId}
53
+ ref={ref}
54
+ className={cn(
55
+ "flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",
56
+ className
57
+ )}
58
+ {...props}
59
+ >
60
+ <ChartStyle id={chartId} config={config} />
61
+ <RechartsPrimitive.ResponsiveContainer>
62
+ {children}
63
+ </RechartsPrimitive.ResponsiveContainer>
64
+ </div>
65
+ </ChartContext.Provider>
66
+ )
67
+ })
68
+ ChartContainer.displayName = "Chart"
69
+
70
+ const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
71
+ const colorConfig = Object.entries(config).filter(
72
+ ([_, config]) => config.theme || config.color
73
+ )
74
+
75
+ if (!colorConfig.length) {
76
+ return null
77
+ }
78
+
79
+ return (
80
+ <style
81
+ dangerouslySetInnerHTML={{
82
+ __html: Object.entries(THEMES)
83
+ .map(
84
+ ([theme, prefix]) => `
85
+ ${prefix} [data-chart=${id}] {
86
+ ${colorConfig
87
+ .map(([key, itemConfig]) => {
88
+ const color =
89
+ itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
90
+ itemConfig.color
91
+ return color ? ` --color-${key}: ${color};` : null
92
+ })
93
+ .join("\n")}
94
+ }
95
+ `
96
+ )
97
+ .join("\n"),
98
+ }}
99
+ />
100
+ )
101
+ }
102
+
103
+ const ChartTooltip = RechartsPrimitive.Tooltip
104
+
105
+ const ChartTooltipContent = React.forwardRef<
106
+ HTMLDivElement,
107
+ React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
108
+ React.ComponentProps<"div"> & {
109
+ hideLabel?: boolean
110
+ hideIndicator?: boolean
111
+ indicator?: "line" | "dot" | "dashed"
112
+ nameKey?: string
113
+ labelKey?: string
114
+ }
115
+ >(
116
+ (
117
+ {
118
+ active,
119
+ payload,
120
+ className,
121
+ indicator = "dot",
122
+ hideLabel = false,
123
+ hideIndicator = false,
124
+ label,
125
+ labelFormatter,
126
+ labelClassName,
127
+ formatter,
128
+ color,
129
+ nameKey,
130
+ labelKey,
131
+ },
132
+ ref
133
+ ) => {
134
+ const { config } = useChart()
135
+
136
+ const tooltipLabel = React.useMemo(() => {
137
+ if (hideLabel || !payload?.length) {
138
+ return null
139
+ }
140
+
141
+ const [item] = payload
142
+ const key = `${labelKey || item.dataKey || item.name || "value"}`
143
+ const itemConfig = getPayloadConfigFromPayload(config, item, key)
144
+ const value =
145
+ !labelKey && typeof label === "string"
146
+ ? config[label as keyof typeof config]?.label || label
147
+ : itemConfig?.label
148
+
149
+ if (labelFormatter) {
150
+ return (
151
+ <div className={cn("font-medium", labelClassName)}>
152
+ {labelFormatter(value, payload)}
153
+ </div>
154
+ )
155
+ }
156
+
157
+ if (!value) {
158
+ return null
159
+ }
160
+
161
+ return <div className={cn("font-medium", labelClassName)}>{value}</div>
162
+ }, [
163
+ label,
164
+ labelFormatter,
165
+ payload,
166
+ hideLabel,
167
+ labelClassName,
168
+ config,
169
+ labelKey,
170
+ ])
171
+
172
+ if (!active || !payload?.length) {
173
+ return null
174
+ }
175
+
176
+ const nestLabel = payload.length === 1 && indicator !== "dot"
177
+
178
+ return (
179
+ <div
180
+ ref={ref}
181
+ className={cn(
182
+ "grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
183
+ className
184
+ )}
185
+ >
186
+ {!nestLabel ? tooltipLabel : null}
187
+ <div className="grid gap-1.5">
188
+ {payload.map((item, index) => {
189
+ const key = `${nameKey || item.name || item.dataKey || "value"}`
190
+ const itemConfig = getPayloadConfigFromPayload(config, item, key)
191
+ const indicatorColor = color || item.payload.fill || item.color
192
+
193
+ return (
194
+ <div
195
+ key={item.dataKey}
196
+ className={cn(
197
+ "flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
198
+ indicator === "dot" && "items-center"
199
+ )}
200
+ >
201
+ {formatter && item?.value !== undefined && item.name ? (
202
+ formatter(item.value, item.name, item, index, item.payload)
203
+ ) : (
204
+ <>
205
+ {itemConfig?.icon ? (
206
+ <itemConfig.icon />
207
+ ) : (
208
+ !hideIndicator && (
209
+ <div
210
+ className={cn(
211
+ "shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",
212
+ {
213
+ "h-2.5 w-2.5": indicator === "dot",
214
+ "w-1": indicator === "line",
215
+ "w-0 border-[1.5px] border-dashed bg-transparent":
216
+ indicator === "dashed",
217
+ "my-0.5": nestLabel && indicator === "dashed",
218
+ }
219
+ )}
220
+ style={
221
+ {
222
+ "--color-bg": indicatorColor,
223
+ "--color-border": indicatorColor,
224
+ } as React.CSSProperties
225
+ }
226
+ />
227
+ )
228
+ )}
229
+ <div
230
+ className={cn(
231
+ "flex flex-1 justify-between leading-none",
232
+ nestLabel ? "items-end" : "items-center"
233
+ )}
234
+ >
235
+ <div className="grid gap-1.5">
236
+ {nestLabel ? tooltipLabel : null}
237
+ <span className="text-muted-foreground">
238
+ {itemConfig?.label || item.name}
239
+ </span>
240
+ </div>
241
+ {item.value && (
242
+ <span className="font-mono font-medium tabular-nums text-foreground">
243
+ {item.value.toLocaleString()}
244
+ </span>
245
+ )}
246
+ </div>
247
+ </>
248
+ )}
249
+ </div>
250
+ )
251
+ })}
252
+ </div>
253
+ </div>
254
+ )
255
+ }
256
+ )
257
+ ChartTooltipContent.displayName = "ChartTooltip"
258
+
259
+ const ChartLegend = RechartsPrimitive.Legend
260
+
261
+ const ChartLegendContent = React.forwardRef<
262
+ HTMLDivElement,
263
+ React.ComponentProps<"div"> &
264
+ Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
265
+ hideIcon?: boolean
266
+ nameKey?: string
267
+ }
268
+ >(
269
+ (
270
+ { className, hideIcon = false, payload, verticalAlign = "bottom", nameKey },
271
+ ref
272
+ ) => {
273
+ const { config } = useChart()
274
+
275
+ if (!payload?.length) {
276
+ return null
277
+ }
278
+
279
+ return (
280
+ <div
281
+ ref={ref}
282
+ className={cn(
283
+ "flex items-center justify-center gap-4",
284
+ verticalAlign === "top" ? "pb-3" : "pt-3",
285
+ className
286
+ )}
287
+ >
288
+ {payload.map((item) => {
289
+ const key = `${nameKey || item.dataKey || "value"}`
290
+ const itemConfig = getPayloadConfigFromPayload(config, item, key)
291
+
292
+ return (
293
+ <div
294
+ key={item.value}
295
+ className={cn(
296
+ "flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"
297
+ )}
298
+ >
299
+ {itemConfig?.icon && !hideIcon ? (
300
+ <itemConfig.icon />
301
+ ) : (
302
+ <div
303
+ className="h-2 w-2 shrink-0 rounded-[2px]"
304
+ style={{
305
+ backgroundColor: item.color,
306
+ }}
307
+ />
308
+ )}
309
+ {itemConfig?.label}
310
+ </div>
311
+ )
312
+ })}
313
+ </div>
314
+ )
315
+ }
316
+ )
317
+ ChartLegendContent.displayName = "ChartLegend"
318
+
319
+ // Helper to extract item config from a payload.
320
+ function getPayloadConfigFromPayload(
321
+ config: ChartConfig,
322
+ payload: unknown,
323
+ key: string
324
+ ) {
325
+ if (typeof payload !== "object" || payload === null) {
326
+ return undefined
327
+ }
328
+
329
+ const payloadPayload =
330
+ "payload" in payload &&
331
+ typeof payload.payload === "object" &&
332
+ payload.payload !== null
333
+ ? payload.payload
334
+ : undefined
335
+
336
+ let configLabelKey: string = key
337
+
338
+ if (
339
+ key in payload &&
340
+ typeof payload[key as keyof typeof payload] === "string"
341
+ ) {
342
+ configLabelKey = payload[key as keyof typeof payload] as string
343
+ } else if (
344
+ payloadPayload &&
345
+ key in payloadPayload &&
346
+ typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
347
+ ) {
348
+ configLabelKey = payloadPayload[
349
+ key as keyof typeof payloadPayload
350
+ ] as string
351
+ }
352
+
353
+ return configLabelKey in config
354
+ ? config[configLabelKey]
355
+ : config[key as keyof typeof config]
356
+ }
357
+
358
+ export {
359
+ ChartContainer,
360
+ ChartTooltip,
361
+ ChartTooltipContent,
362
+ ChartLegend,
363
+ ChartLegendContent,
364
+ ChartStyle,
365
+ }
@@ -0,0 +1,30 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
5
+ import { Check } from "lucide-react"
6
+
7
+ import { cn } from "@/lib/utils"
8
+
9
+ const Checkbox = React.forwardRef<
10
+ React.ElementRef<typeof CheckboxPrimitive.Root>,
11
+ React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
12
+ >(({ className, ...props }, ref) => (
13
+ <CheckboxPrimitive.Root
14
+ ref={ref}
15
+ className={cn(
16
+ "peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
17
+ className
18
+ )}
19
+ {...props}
20
+ >
21
+ <CheckboxPrimitive.Indicator
22
+ className={cn("flex items-center justify-center text-current")}
23
+ >
24
+ <Check className="h-4 w-4" />
25
+ </CheckboxPrimitive.Indicator>
26
+ </CheckboxPrimitive.Root>
27
+ ))
28
+ Checkbox.displayName = CheckboxPrimitive.Root.displayName
29
+
30
+ export { Checkbox }
@@ -0,0 +1,11 @@
1
+ "use client"
2
+
3
+ import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
4
+
5
+ const Collapsible = CollapsiblePrimitive.Root
6
+
7
+ const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger
8
+
9
+ const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent
10
+
11
+ export { Collapsible, CollapsibleTrigger, CollapsibleContent }