@aiconstructions/graficos 0.0.0-stage → 0.2.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 (267) hide show
  1. package/ALTERACOES.md +53 -0
  2. package/LICENSE-BKLIT +21 -0
  3. package/LICENSE-visx-pattern +21 -0
  4. package/README.md +188 -2
  5. package/dist/aic/cores.js +83 -0
  6. package/dist/aic/index.js +22 -0
  7. package/dist/aic/interacao.js +55 -0
  8. package/dist/charts/animation.js +55 -0
  9. package/dist/charts/arc-geometry.js +58 -0
  10. package/dist/charts/arc-path.js +15 -0
  11. package/dist/charts/area-chart-loading.js +89 -0
  12. package/dist/charts/area-chart.js +149 -0
  13. package/dist/charts/area-gradient-defs.js +90 -0
  14. package/dist/charts/area-value-label-layout.js +70 -0
  15. package/dist/charts/area-value-labels.js +211 -0
  16. package/dist/charts/area.js +272 -0
  17. package/dist/charts/background.js +198 -0
  18. package/dist/charts/band-config.js +82 -0
  19. package/dist/charts/band-geometry.js +186 -0
  20. package/dist/charts/band.js +346 -0
  21. package/dist/charts/bar-chart-loading.js +27 -0
  22. package/dist/charts/bar-chart.js +545 -0
  23. package/dist/charts/bar-depth-geometry.js +18 -0
  24. package/dist/charts/bar-depth.js +608 -0
  25. package/dist/charts/bar-lollipop.js +278 -0
  26. package/dist/charts/bar-squares-layout.js +66 -0
  27. package/dist/charts/bar-squares.js +467 -0
  28. package/dist/charts/bar-value-label-layout.js +42 -0
  29. package/dist/charts/bar-x-axis.js +133 -0
  30. package/dist/charts/bar-y-axis.js +116 -0
  31. package/dist/charts/bar.js +457 -0
  32. package/dist/charts/bollinger.js +49 -0
  33. package/dist/charts/candlestick-chart.js +370 -0
  34. package/dist/charts/candlestick.js +368 -0
  35. package/dist/charts/chart-brush-handle.js +91 -0
  36. package/dist/charts/chart-brush-layout.js +91 -0
  37. package/dist/charts/chart-brush-selection-overlay.js +87 -0
  38. package/dist/charts/chart-brush-state.js +253 -0
  39. package/dist/charts/chart-brush-track-overlay.js +103 -0
  40. package/dist/charts/chart-brush.js +517 -0
  41. package/dist/charts/chart-center-typography.js +8 -0
  42. package/dist/charts/chart-child-passthrough.js +119 -0
  43. package/dist/charts/chart-config-context.js +56 -0
  44. package/dist/charts/chart-context.js +337 -0
  45. package/dist/charts/chart-crosshair.js +262 -0
  46. package/dist/charts/chart-data-override.js +186 -0
  47. package/dist/charts/chart-defs.js +56 -0
  48. package/dist/charts/chart-formatters.js +77 -0
  49. package/dist/charts/chart-legend-hover.js +27 -0
  50. package/dist/charts/chart-legend.js +163 -0
  51. package/dist/charts/chart-loading-label.js +52 -0
  52. package/dist/charts/chart-parent-size.js +138 -0
  53. package/dist/charts/chart-phase.js +29 -0
  54. package/dist/charts/chart-reveal-clip.js +62 -0
  55. package/dist/charts/chart-scale.js +19 -0
  56. package/dist/charts/chart-stat-flow.js +72 -0
  57. package/dist/charts/choropleth/choropleth-background.js +29 -0
  58. package/dist/charts/choropleth/choropleth-camera.js +379 -0
  59. package/dist/charts/choropleth/choropleth-chart.js +644 -0
  60. package/dist/charts/choropleth/choropleth-context.js +152 -0
  61. package/dist/charts/choropleth/choropleth-dot-grid.js +293 -0
  62. package/dist/charts/choropleth/choropleth-feature.js +291 -0
  63. package/dist/charts/choropleth/choropleth-graticule.js +40 -0
  64. package/dist/charts/choropleth/choropleth-marker.js +222 -0
  65. package/dist/charts/choropleth/choropleth-projection.js +37 -0
  66. package/dist/charts/choropleth/choropleth-tooltip.js +82 -0
  67. package/dist/charts/choropleth/choropleth-zoom-matrix.js +150 -0
  68. package/dist/charts/choropleth/index.js +44 -0
  69. package/dist/charts/choropleth/use-choropleth-zoom-state.js +636 -0
  70. package/dist/charts/composed-chart.js +346 -0
  71. package/dist/charts/crosshair-store.js +49 -0
  72. package/dist/charts/dash-tail-stroke.js +58 -0
  73. package/dist/charts/date-pill-store.js +50 -0
  74. package/dist/charts/date-ranges.js +131 -0
  75. package/dist/charts/deadline.js +295 -0
  76. package/dist/charts/decimate-time-series.js +112 -0
  77. package/dist/charts/fade-edges.js +171 -0
  78. package/dist/charts/fast-path.js +78 -0
  79. package/dist/charts/filter-data-by-x-domain.js +45 -0
  80. package/dist/charts/funnel-chart.js +773 -0
  81. package/dist/charts/gauge-arc-layers.js +479 -0
  82. package/dist/charts/gauge-dial.js +329 -0
  83. package/dist/charts/gauge-label-layout.js +148 -0
  84. package/dist/charts/gauge.js +946 -0
  85. package/dist/charts/generate-chart-skeleton-data.js +27 -0
  86. package/dist/charts/gradients.js +158 -0
  87. package/dist/charts/grid-lines.js +114 -0
  88. package/dist/charts/grid.js +225 -0
  89. package/dist/charts/heatmap/generate-heatmap-skeleton-data.js +13 -0
  90. package/dist/charts/heatmap/heatmap-animation.js +128 -0
  91. package/dist/charts/heatmap/heatmap-cells.js +519 -0
  92. package/dist/charts/heatmap/heatmap-chart-loading.js +44 -0
  93. package/dist/charts/heatmap/heatmap-chart.js +548 -0
  94. package/dist/charts/heatmap/heatmap-colors.js +127 -0
  95. package/dist/charts/heatmap/heatmap-context.js +107 -0
  96. package/dist/charts/heatmap/heatmap-legend-gradient.js +97 -0
  97. package/dist/charts/heatmap/heatmap-legend-swatch.js +76 -0
  98. package/dist/charts/heatmap/heatmap-legend.js +165 -0
  99. package/dist/charts/heatmap/heatmap-pattern-defs.js +37 -0
  100. package/dist/charts/heatmap/heatmap-rect-cells.js +39 -0
  101. package/dist/charts/heatmap/heatmap-resolve-separator.js +84 -0
  102. package/dist/charts/heatmap/heatmap-separator.js +168 -0
  103. package/dist/charts/heatmap/heatmap-tooltip.js +73 -0
  104. package/dist/charts/heatmap/heatmap-utils.js +633 -0
  105. package/dist/charts/heatmap/heatmap-x-axis.js +79 -0
  106. package/dist/charts/heatmap/heatmap-y-axis.js +72 -0
  107. package/dist/charts/heatmap/index.js +208 -0
  108. package/dist/charts/highlight-segment-bounds.js +34 -0
  109. package/dist/charts/highlight-segment.js +119 -0
  110. package/dist/charts/index.js +944 -0
  111. package/dist/charts/indicator-fade.js +44 -0
  112. package/dist/charts/legend/index.js +22 -0
  113. package/dist/charts/legend/legend-context.js +47 -0
  114. package/dist/charts/legend/legend-item.js +30 -0
  115. package/dist/charts/legend/legend-label.js +14 -0
  116. package/dist/charts/legend/legend-marker.js +18 -0
  117. package/dist/charts/legend/legend-progress.js +39 -0
  118. package/dist/charts/legend/legend-value.js +31 -0
  119. package/dist/charts/legend/legend.js +69 -0
  120. package/dist/charts/line-backdrop.js +129 -0
  121. package/dist/charts/line-chart-loading.js +85 -0
  122. package/dist/charts/line-chart.js +182 -0
  123. package/dist/charts/line-loading-pulse.js +185 -0
  124. package/dist/charts/line-loading-timing.js +12 -0
  125. package/dist/charts/line-path.js +58 -0
  126. package/dist/charts/line-series-terminal-marker.js +75 -0
  127. package/dist/charts/line.js +499 -0
  128. package/dist/charts/live-line-chart.js +494 -0
  129. package/dist/charts/live-line.js +277 -0
  130. package/dist/charts/live-x-axis.js +116 -0
  131. package/dist/charts/live-y-axis.js +164 -0
  132. package/dist/charts/loading-sweep.js +344 -0
  133. package/dist/charts/local-point.js +56 -0
  134. package/dist/charts/markers/chart-markers.js +149 -0
  135. package/dist/charts/markers/index.js +14 -0
  136. package/dist/charts/markers/marker-group.js +411 -0
  137. package/dist/charts/motion-utils.js +29 -0
  138. package/dist/charts/notch-gauge-shared.js +146 -0
  139. package/dist/charts/particle-line.js +1340 -0
  140. package/dist/charts/path-stroke-utils.js +51 -0
  141. package/dist/charts/pattern-area.js +127 -0
  142. package/dist/charts/pattern-preset.js +287 -0
  143. package/dist/charts/pattern-tile.js +31 -0
  144. package/dist/charts/patterns/circles.js +62 -0
  145. package/dist/charts/patterns/constants.js +9 -0
  146. package/dist/charts/patterns/hexagons.js +38 -0
  147. package/dist/charts/patterns/index.js +16 -0
  148. package/dist/charts/patterns/lines.js +65 -0
  149. package/dist/charts/patterns/path.js +37 -0
  150. package/dist/charts/patterns/pattern.js +16 -0
  151. package/dist/charts/patterns/waves.js +40 -0
  152. package/dist/charts/pie-center-shell.js +127 -0
  153. package/dist/charts/pie-center.js +87 -0
  154. package/dist/charts/pie-chart.js +377 -0
  155. package/dist/charts/pie-context.js +116 -0
  156. package/dist/charts/pie-slice.js +394 -0
  157. package/dist/charts/pie-ticks.js +332 -0
  158. package/dist/charts/profit-loss-legend-hover.js +18 -0
  159. package/dist/charts/profit-loss-legend.js +53 -0
  160. package/dist/charts/profit-loss-line.js +162 -0
  161. package/dist/charts/profit-loss-segments.js +88 -0
  162. package/dist/charts/projection-config.js +90 -0
  163. package/dist/charts/projection-line-end-marker.js +50 -0
  164. package/dist/charts/projection-line.js +466 -0
  165. package/dist/charts/projection-utils.js +303 -0
  166. package/dist/charts/radar-area.js +192 -0
  167. package/dist/charts/radar-axis.js +41 -0
  168. package/dist/charts/radar-chart.js +184 -0
  169. package/dist/charts/radar-context.js +104 -0
  170. package/dist/charts/radar-grid.js +121 -0
  171. package/dist/charts/radar-labels.js +62 -0
  172. package/dist/charts/radial-area.js +498 -0
  173. package/dist/charts/radial-axis.js +652 -0
  174. package/dist/charts/radial-bar.js +316 -0
  175. package/dist/charts/radial-center.js +67 -0
  176. package/dist/charts/radial-chart.js +740 -0
  177. package/dist/charts/radial-dot-bar-layout.js +68 -0
  178. package/dist/charts/radial-dot-bar.js +387 -0
  179. package/dist/charts/radial-geometry.js +114 -0
  180. package/dist/charts/radial-legend.js +66 -0
  181. package/dist/charts/radial-line.js +280 -0
  182. package/dist/charts/radial-ring-bar.js +255 -0
  183. package/dist/charts/radial-scrubber.js +120 -0
  184. package/dist/charts/radial-series-color.js +10 -0
  185. package/dist/charts/reference-area-config.js +43 -0
  186. package/dist/charts/reference-area-geometry.js +76 -0
  187. package/dist/charts/reference-area-registration-context.js +10 -0
  188. package/dist/charts/reference-area.js +241 -0
  189. package/dist/charts/responsive-chart-label-count.js +18 -0
  190. package/dist/charts/ring-center.js +78 -0
  191. package/dist/charts/ring-chart.js +362 -0
  192. package/dist/charts/ring-context.js +122 -0
  193. package/dist/charts/ring-grid.js +175 -0
  194. package/dist/charts/ring-labels.js +109 -0
  195. package/dist/charts/ring.js +237 -0
  196. package/dist/charts/sankey/index.js +22 -0
  197. package/dist/charts/sankey/sankey-chart.js +199 -0
  198. package/dist/charts/sankey/sankey-context.js +32 -0
  199. package/dist/charts/sankey/sankey-link.js +232 -0
  200. package/dist/charts/sankey/sankey-node.js +348 -0
  201. package/dist/charts/sankey/sankey-tooltip.js +94 -0
  202. package/dist/charts/scatter-chart-shell.js +279 -0
  203. package/dist/charts/scatter-chart.js +150 -0
  204. package/dist/charts/scatter-jitter.js +86 -0
  205. package/dist/charts/scatter-svg.js +17 -0
  206. package/dist/charts/scatter.js +92 -0
  207. package/dist/charts/segment.js +107 -0
  208. package/dist/charts/series-bar-layout.js +42 -0
  209. package/dist/charts/series-bar.js +241 -0
  210. package/dist/charts/series-dash-tail-overlay.js +53 -0
  211. package/dist/charts/series-highlight-layer.js +43 -0
  212. package/dist/charts/series-hover-dim.js +32 -0
  213. package/dist/charts/series-markers.js +239 -0
  214. package/dist/charts/series-path-utils.js +185 -0
  215. package/dist/charts/series-point-marker.js +150 -0
  216. package/dist/charts/sparkline-geometry.js +197 -0
  217. package/dist/charts/sparkline.js +910 -0
  218. package/dist/charts/static-chart-preview-context.js +16 -0
  219. package/dist/charts/sunburst-breadcrumb.js +33 -0
  220. package/dist/charts/sunburst-center.js +37 -0
  221. package/dist/charts/sunburst-chart.js +408 -0
  222. package/dist/charts/sunburst-context.js +140 -0
  223. package/dist/charts/sunburst-data.js +0 -0
  224. package/dist/charts/sunburst-hint.js +42 -0
  225. package/dist/charts/sunburst-labels.js +130 -0
  226. package/dist/charts/sunburst-segment.js +144 -0
  227. package/dist/charts/sunburst.js +419 -0
  228. package/dist/charts/time-series-chart-shell.js +688 -0
  229. package/dist/charts/tooltip/chart-tooltip.js +516 -0
  230. package/dist/charts/tooltip/cursor-tooltip-box.js +183 -0
  231. package/dist/charts/tooltip/date-ticker.js +376 -0
  232. package/dist/charts/tooltip/index.js +32 -0
  233. package/dist/charts/tooltip/liquid-glass.js +142 -0
  234. package/dist/charts/tooltip/tooltip-box.js +502 -0
  235. package/dist/charts/tooltip/tooltip-content.js +59 -0
  236. package/dist/charts/tooltip/tooltip-dot.js +170 -0
  237. package/dist/charts/tooltip/tooltip-indicator.js +175 -0
  238. package/dist/charts/tooltip/use-delayed-tooltip-data.js +41 -0
  239. package/dist/charts/tooltip/use-velocity-stretch.js +52 -0
  240. package/dist/charts/trend-line-utils.js +64 -0
  241. package/dist/charts/trend-line.js +318 -0
  242. package/dist/charts/use-animated-band.js +175 -0
  243. package/dist/charts/use-animated-series-path.js +208 -0
  244. package/dist/charts/use-animated-y-domains.js +192 -0
  245. package/dist/charts/use-category-slots.js +29 -0
  246. package/dist/charts/use-chart-interaction.js +296 -0
  247. package/dist/charts/use-chart-phase-orchestrator.js +183 -0
  248. package/dist/charts/use-enter-complete.js +18 -0
  249. package/dist/charts/use-grid-shimmer.js +88 -0
  250. package/dist/charts/use-highlight-segment.js +65 -0
  251. package/dist/charts/use-mount-progress.js +23 -0
  252. package/dist/charts/use-scatter-chart-interaction.js +364 -0
  253. package/dist/charts/use-scheduled-tooltip.js +84 -0
  254. package/dist/charts/visx-pattern.js +30 -0
  255. package/dist/charts/weekends.js +174 -0
  256. package/dist/charts/x-axis-hover.js +46 -0
  257. package/dist/charts/x-axis.js +523 -0
  258. package/dist/charts/y-axis-scales.js +71 -0
  259. package/dist/charts/y-axis-ticks.js +22 -0
  260. package/dist/charts/y-axis.js +233 -0
  261. package/dist/charts/y-domain-utils.js +189 -0
  262. package/dist/index.d.ts +7346 -0
  263. package/dist/index.js +2 -0
  264. package/dist/lib/utils.js +8 -0
  265. package/dist/shimmering-text.js +54 -0
  266. package/package.json +78 -4
  267. package/tema.css +202 -0
@@ -0,0 +1,502 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { createElement } from "react";
4
+ import {
5
+ AnimatePresence,
6
+ animate,
7
+ cancelFrame,
8
+ domAnimation,
9
+ frame,
10
+ frameData,
11
+ LazyMotion,
12
+ m,
13
+ useReducedMotion,
14
+ useReducedMotionConfig,
15
+ useSpring
16
+ } from "motion/react";
17
+ import { useLayoutEffect, useRef, useState } from "react";
18
+ import { createPortal, flushSync } from "react-dom";
19
+ import { cn } from "../../lib/utils";
20
+ import { useChartConfig } from "../chart-config-context";
21
+ import { chartCssVars, useChartPortalContainer } from "../chart-context";
22
+ const TOOLTIP_PANEL_CLASS_NAME = "relative min-w-[160px] rounded-xl border not-dark:bg-clip-padding text-chart-tooltip-foreground shadow-lg/5 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--chart-radius)-1px)] before:shadow-[0_1px_rgb(0_0_0/0.04)] dark:before:shadow-[0_-1px_rgb(255_255_255/0.06)]";
23
+ const TOOLTIP_PANEL_INNER_CLASS_NAME = "overflow-hidden rounded-[calc(var(--chart-radius)-1px)]";
24
+ const PANEL_ENTRANCE_SPRING = {
25
+ type: "spring",
26
+ stiffness: 300,
27
+ damping: 25
28
+ };
29
+ const PANEL_SIZE_SPRING = {
30
+ type: "spring",
31
+ stiffness: 500,
32
+ damping: 45
33
+ };
34
+ const mixNumber = (from, to, progress) => from + (to - from) * progress;
35
+ function mixPanelSizes(from, to, progress) {
36
+ return {
37
+ panelWidth: mixNumber(from.panelWidth, to.panelWidth, progress),
38
+ panelHeight: mixNumber(from.panelHeight, to.panelHeight, progress),
39
+ clipWidth: mixNumber(from.clipWidth, to.clipWidth, progress),
40
+ clipHeight: mixNumber(from.clipHeight, to.clipHeight, progress)
41
+ };
42
+ }
43
+ const FRAME_MS = 1e3 / 60;
44
+ const BORDER_BOX = { box: "border-box" };
45
+ const samePanelSizes = (a, b) => a.panelWidth === b.panelWidth && a.panelHeight === b.panelHeight && a.clipWidth === b.clipWidth && a.clipHeight === b.clipHeight;
46
+ function readPxRadius(element) {
47
+ const value = getComputedStyle(element).borderTopLeftRadius;
48
+ return value.endsWith("px") ? Number.parseFloat(value) : null;
49
+ }
50
+ function correctedRadius(r, width, height) {
51
+ const x = width === 0 ? 0 : r / width * 100;
52
+ const y = height === 0 ? 0 : r / height * 100;
53
+ return `${x}% / ${y}%`;
54
+ }
55
+ const ratio = (drawn, layout) => layout === 0 ? 1 : drawn / layout;
56
+ function readBorderBox(element) {
57
+ const style = getComputedStyle(element);
58
+ let width = Number.parseFloat(style.width);
59
+ let height = Number.parseFloat(style.height);
60
+ if (!(Number.isFinite(width) && Number.isFinite(height))) {
61
+ return [element.offsetWidth, element.offsetHeight];
62
+ }
63
+ if (style.boxSizing !== "border-box") {
64
+ width += Number.parseFloat(style.paddingLeft) + Number.parseFloat(style.paddingRight) + Number.parseFloat(style.borderLeftWidth) + Number.parseFloat(style.borderRightWidth);
65
+ height += Number.parseFloat(style.paddingTop) + Number.parseFloat(style.paddingBottom) + Number.parseFloat(style.borderTopWidth) + Number.parseFloat(style.borderBottomWidth);
66
+ }
67
+ return [width, height];
68
+ }
69
+ function readPanelSizes(panel, clip) {
70
+ const [panelWidth, panelHeight] = readBorderBox(panel);
71
+ const [clipWidth, clipHeight] = readBorderBox(clip);
72
+ return { panelWidth, panelHeight, clipWidth, clipHeight };
73
+ }
74
+ function drawPanelTween({
75
+ panel,
76
+ clip,
77
+ content
78
+ }, radii, from, target, progress) {
79
+ const drawn = mixPanelSizes(from, target, progress);
80
+ const scaleX = ratio(drawn.panelWidth, target.panelWidth);
81
+ const scaleY = ratio(drawn.panelHeight, target.panelHeight);
82
+ const clipScaleX = ratio(drawn.clipWidth, target.clipWidth);
83
+ const clipScaleY = ratio(drawn.clipHeight, target.clipHeight);
84
+ panel.style.transform = `scale(${scaleX}, ${scaleY})`;
85
+ const offsetX = clip.offsetLeft / scaleX - clip.offsetLeft;
86
+ const offsetY = clip.offsetTop / scaleY - clip.offsetTop;
87
+ const translate = offsetX || offsetY ? `translate3d(${offsetX}px, ${offsetY}px, 0px) ` : "";
88
+ clip.style.transform = `${translate}scale(${clipScaleX / scaleX}, ${clipScaleY / scaleY})`;
89
+ content.style.transform = `scale(${1 / clipScaleX}, ${1 / clipScaleY})`;
90
+ if (radii.panel !== null) {
91
+ panel.style.borderRadius = correctedRadius(
92
+ radii.panel,
93
+ drawn.panelWidth,
94
+ drawn.panelHeight
95
+ );
96
+ }
97
+ if (radii.clip !== null) {
98
+ clip.style.borderRadius = correctedRadius(
99
+ radii.clip,
100
+ drawn.clipWidth,
101
+ drawn.clipHeight
102
+ );
103
+ }
104
+ }
105
+ function usePanelSizeTween(panelRef, clipRef, contentRef, enabled) {
106
+ const checkRef = useRef(null);
107
+ useLayoutEffect(() => {
108
+ const panel = panelRef.current;
109
+ const clip = clipRef.current;
110
+ const content = contentRef.current;
111
+ if (!(enabled && panel && clip && content)) {
112
+ return;
113
+ }
114
+ const observing = typeof ResizeObserver !== "undefined";
115
+ let target = readPanelSizes(panel, clip);
116
+ let from = null;
117
+ let progress = 1;
118
+ let controls;
119
+ let pendingStart;
120
+ let radii = null;
121
+ const stop = () => {
122
+ if (pendingStart) {
123
+ cancelFrame(pendingStart);
124
+ pendingStart = void 0;
125
+ }
126
+ controls?.stop();
127
+ controls = void 0;
128
+ };
129
+ const reset = () => {
130
+ panel.style.transform = "";
131
+ clip.style.transform = "";
132
+ content.style.transform = "";
133
+ if (radii) {
134
+ panel.style.borderRadius = radii.panelInline;
135
+ clip.style.borderRadius = radii.clipInline;
136
+ radii = null;
137
+ }
138
+ };
139
+ const draw = (latest) => {
140
+ progress = latest;
141
+ if (from && radii) {
142
+ drawPanelTween({ panel, clip, content }, radii, from, target, latest);
143
+ }
144
+ };
145
+ const check = () => {
146
+ const next = readPanelSizes(panel, clip);
147
+ if (samePanelSizes(next, target)) {
148
+ return;
149
+ }
150
+ from = from && progress < 1 ? mixPanelSizes(from, target, progress) : target;
151
+ target = next;
152
+ stop();
153
+ radii ??= {
154
+ panel: readPxRadius(panel),
155
+ clip: readPxRadius(clip),
156
+ panelInline: panel.style.borderRadius,
157
+ clipInline: clip.style.borderRadius
158
+ };
159
+ draw(0);
160
+ const startTween = (elapsed) => {
161
+ controls = animate(0, 1e3, {
162
+ ...PANEL_SIZE_SPRING,
163
+ elapsed,
164
+ velocity: 0,
165
+ onUpdate: (latest) => draw(latest / 1e3),
166
+ onComplete: () => {
167
+ progress = 1;
168
+ from = null;
169
+ controls = void 0;
170
+ reset();
171
+ }
172
+ });
173
+ };
174
+ if (observing) {
175
+ const sinceFrame = performance.now() - frameData.timestamp;
176
+ startTween(sinceFrame >= 0 && sinceFrame < FRAME_MS ? sinceFrame : 0);
177
+ return;
178
+ }
179
+ pendingStart = frame.update(() => {
180
+ pendingStart = void 0;
181
+ startTween(0);
182
+ });
183
+ };
184
+ if (!observing) {
185
+ checkRef.current = check;
186
+ return () => {
187
+ checkRef.current = null;
188
+ stop();
189
+ reset();
190
+ };
191
+ }
192
+ const observer = new ResizeObserver(check);
193
+ observer.observe(panel, BORDER_BOX);
194
+ observer.observe(clip, BORDER_BOX);
195
+ return () => {
196
+ observer.disconnect();
197
+ stop();
198
+ reset();
199
+ };
200
+ }, [panelRef, clipRef, contentRef, enabled]);
201
+ useLayoutEffect(() => {
202
+ checkRef.current?.();
203
+ });
204
+ }
205
+ const ORIGIN_TOP_LEFT = { transformOrigin: "0 0" };
206
+ function TooltipPanel({
207
+ animateSize,
208
+ entrance,
209
+ transformOrigin,
210
+ className,
211
+ style,
212
+ children
213
+ }) {
214
+ const panelRef = useRef(null);
215
+ const clipRef = useRef(null);
216
+ const contentRef = useRef(null);
217
+ const reducedMotionConfig = useReducedMotionConfig() === true;
218
+ usePanelSizeTween(
219
+ panelRef,
220
+ clipRef,
221
+ contentRef,
222
+ animateSize && !reducedMotionConfig
223
+ );
224
+ return /* @__PURE__ */ jsx(
225
+ m.div,
226
+ {
227
+ animate: { scale: 1, x: 0 },
228
+ initial: entrance === false ? false : { x: 0, ...entrance },
229
+ style: { transformOrigin },
230
+ transition: PANEL_ENTRANCE_SPRING,
231
+ children: /* @__PURE__ */ jsx(
232
+ m.div,
233
+ {
234
+ animate: { opacity: 1 },
235
+ className,
236
+ initial: { opacity: 0 },
237
+ ref: panelRef,
238
+ style: { ...style, ...ORIGIN_TOP_LEFT },
239
+ transition: PANEL_ENTRANCE_SPRING,
240
+ children: /* @__PURE__ */ jsx(
241
+ "div",
242
+ {
243
+ className: TOOLTIP_PANEL_INNER_CLASS_NAME,
244
+ ref: clipRef,
245
+ style: ORIGIN_TOP_LEFT,
246
+ children: /* @__PURE__ */ jsx("div", { ref: contentRef, style: ORIGIN_TOP_LEFT, children })
247
+ }
248
+ )
249
+ }
250
+ )
251
+ }
252
+ );
253
+ }
254
+ function moveTo(spring, value, snap) {
255
+ if (snap) {
256
+ spring.jump(value);
257
+ } else {
258
+ spring.set(value);
259
+ }
260
+ }
261
+ const DEFAULT_TOOLTIP_WIDTH = 180;
262
+ const DEFAULT_TOOLTIP_HEIGHT = 80;
263
+ function readPanelBoxSize(el, widthRef, heightRef) {
264
+ const w = el.offsetWidth;
265
+ const h = el.offsetHeight;
266
+ const changed = w > 0 && w !== widthRef.current || h > 0 && h !== heightRef.current;
267
+ if (w > 0) {
268
+ widthRef.current = w;
269
+ }
270
+ if (h > 0) {
271
+ heightRef.current = h;
272
+ }
273
+ return changed;
274
+ }
275
+ function resolveTooltipTarget({
276
+ x,
277
+ flipX = x,
278
+ y,
279
+ width,
280
+ height,
281
+ offset,
282
+ containerWidth,
283
+ containerHeight
284
+ }) {
285
+ const flipped = flipX + width + offset > containerWidth;
286
+ return {
287
+ flipped,
288
+ left: flipped ? x - offset - width : x + offset,
289
+ top: Math.max(
290
+ offset,
291
+ Math.min(y - height / 2, containerHeight - height - offset)
292
+ )
293
+ };
294
+ }
295
+ function TooltipBox(props) {
296
+ const container = useChartPortalContainer(props.containerRef);
297
+ if (!container) {
298
+ return null;
299
+ }
300
+ const inner = props.visible ? /* @__PURE__ */ createElement(TooltipBoxInner, { ...props, container, key: "tooltip-box" }) : null;
301
+ return /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: props.exit !== false && props.entrance !== false ? /* @__PURE__ */ jsx(AnimatePresence, { children: inner }) : inner });
302
+ }
303
+ function TooltipBoxInner({
304
+ x,
305
+ y,
306
+ containerWidth,
307
+ containerHeight,
308
+ offset = 16,
309
+ className = "",
310
+ children,
311
+ left: leftOverride,
312
+ top: topOverride,
313
+ flipped: flippedOverride,
314
+ flipX,
315
+ springConfig,
316
+ animate: animate2 = true,
317
+ entrance = true,
318
+ exit: _exit,
319
+ replayOnFlip = true,
320
+ animateSize = true,
321
+ panelStyle,
322
+ backgroundColor = chartCssVars.tooltipBackground,
323
+ container
324
+ }) {
325
+ const { tooltipBoxSpring } = useChartConfig();
326
+ const reducedMotion = useReducedMotion() === true;
327
+ const effectiveSpring = springConfig ?? tooltipBoxSpring;
328
+ const tooltipRef = useRef(null);
329
+ const tooltipWidthRef = useRef(DEFAULT_TOOLTIP_WIDTH);
330
+ const tooltipHeightRef = useRef(DEFAULT_TOOLTIP_HEIGHT);
331
+ const [staticPosition] = useState(() => ({ left: x, top: y }));
332
+ const hasPositionedRef = useRef(false);
333
+ const [flip, setFlip] = useState(() => ({
334
+ flipped: (flipX ?? x) + DEFAULT_TOOLTIP_WIDTH + offset > containerWidth,
335
+ key: 0
336
+ }));
337
+ const shouldFlipX = flip.flipped;
338
+ const [initialTarget] = useState(
339
+ () => resolveTooltipTarget({
340
+ x,
341
+ flipX,
342
+ y,
343
+ width: DEFAULT_TOOLTIP_WIDTH,
344
+ height: DEFAULT_TOOLTIP_HEIGHT,
345
+ offset,
346
+ containerWidth,
347
+ containerHeight
348
+ })
349
+ );
350
+ const animatedLeft = useSpring(initialTarget.left, effectiveSpring);
351
+ const animatedTop = useSpring(initialTarget.top, effectiveSpring);
352
+ const placeRef = useRef(null);
353
+ const sizeObservedRef = useRef(false);
354
+ useLayoutEffect(() => {
355
+ const el = tooltipRef.current;
356
+ if (!el) {
357
+ return;
358
+ }
359
+ if (!sizeObservedRef.current) {
360
+ readPanelBoxSize(el, tooltipWidthRef, tooltipHeightRef);
361
+ sizeObservedRef.current = typeof ResizeObserver !== "undefined";
362
+ }
363
+ const place = (fromObserver) => {
364
+ const target = resolveTooltipTarget({
365
+ x,
366
+ flipX,
367
+ y,
368
+ width: tooltipWidthRef.current,
369
+ height: tooltipHeightRef.current,
370
+ offset,
371
+ containerWidth,
372
+ containerHeight
373
+ });
374
+ const updateFlip = () => setFlip(
375
+ (prev) => prev.flipped === target.flipped ? prev : { flipped: target.flipped, key: prev.key + 1 }
376
+ );
377
+ if (fromObserver) {
378
+ flushSync(updateFlip);
379
+ } else {
380
+ updateFlip();
381
+ }
382
+ const tx = target.left;
383
+ const ty = target.top;
384
+ if (!animate2) {
385
+ const left = `${tx}px`;
386
+ const top = `${ty}px`;
387
+ if (el.style.left !== left) {
388
+ el.style.left = left;
389
+ }
390
+ if (el.style.top !== top) {
391
+ el.style.top = top;
392
+ }
393
+ return;
394
+ }
395
+ const snap = reducedMotion || !hasPositionedRef.current;
396
+ hasPositionedRef.current = true;
397
+ if (leftOverride === void 0) {
398
+ moveTo(animatedLeft, tx, snap);
399
+ }
400
+ if (topOverride === void 0) {
401
+ moveTo(animatedTop, ty, snap);
402
+ }
403
+ };
404
+ placeRef.current = place;
405
+ place(false);
406
+ }, [
407
+ x,
408
+ flipX,
409
+ y,
410
+ containerWidth,
411
+ containerHeight,
412
+ offset,
413
+ leftOverride,
414
+ topOverride,
415
+ animate2,
416
+ animatedLeft,
417
+ animatedTop,
418
+ reducedMotion
419
+ ]);
420
+ useLayoutEffect(() => {
421
+ const el = tooltipRef.current;
422
+ if (!el || typeof ResizeObserver === "undefined") {
423
+ return;
424
+ }
425
+ const observer = new ResizeObserver(() => {
426
+ if (readPanelBoxSize(el, tooltipWidthRef, tooltipHeightRef)) {
427
+ placeRef.current?.(true);
428
+ }
429
+ });
430
+ observer.observe(el, BORDER_BOX);
431
+ return () => observer.disconnect();
432
+ }, []);
433
+ const flipKey = replayOnFlip ? flip.key : 0;
434
+ const finalLeft = animate2 ? leftOverride ?? animatedLeft : staticPosition.left;
435
+ const finalTop = animate2 ? topOverride ?? animatedTop : staticPosition.top;
436
+ const isFlipped = flippedOverride ?? shouldFlipX;
437
+ const transformOrigin = isFlipped ? "right top" : "left top";
438
+ const panelClassName = `${TOOLTIP_PANEL_CLASS_NAME}${panelStyle?.backgroundColor === void 0 && backgroundColor === chartCssVars.tooltipBackground ? " bg-chart-tooltip-background" : ""}${panelStyle?.backdropFilter === void 0 ? " backdrop-blur-md" : ""}`;
439
+ const panelStyleResolved = {
440
+ ...panelStyle?.backgroundColor === void 0 && {
441
+ backgroundColor
442
+ },
443
+ ...panelStyle
444
+ };
445
+ if (!entrance) {
446
+ return createPortal(
447
+ /* @__PURE__ */ jsx(
448
+ "div",
449
+ {
450
+ className: cn("pointer-events-none absolute z-50", className),
451
+ ref: tooltipRef,
452
+ style: { left: staticPosition.left, top: staticPosition.top },
453
+ children: /* @__PURE__ */ jsx(
454
+ "div",
455
+ {
456
+ className: panelClassName,
457
+ style: { transformOrigin, ...panelStyleResolved },
458
+ children: /* @__PURE__ */ jsx("div", { className: TOOLTIP_PANEL_INNER_CLASS_NAME, children })
459
+ }
460
+ )
461
+ }
462
+ ),
463
+ container
464
+ );
465
+ }
466
+ return createPortal(
467
+ /* @__PURE__ */ jsx(
468
+ m.div,
469
+ {
470
+ animate: { opacity: 1 },
471
+ className: cn("pointer-events-none absolute z-50", className),
472
+ exit: { opacity: 0 },
473
+ initial: { opacity: 0 },
474
+ ref: tooltipRef,
475
+ style: { left: finalLeft, top: finalTop },
476
+ transition: { duration: 0.1 },
477
+ children: /* @__PURE__ */ jsx(
478
+ TooltipPanel,
479
+ {
480
+ animateSize: animateSize && animate2 && !reducedMotion,
481
+ className: panelClassName,
482
+ entrance: reducedMotion ? false : { scale: 0.85, x: isFlipped ? 20 : -20 },
483
+ style: panelStyleResolved,
484
+ transformOrigin,
485
+ children
486
+ },
487
+ flipKey
488
+ )
489
+ }
490
+ ),
491
+ container
492
+ );
493
+ }
494
+ TooltipBox.displayName = "TooltipBox";
495
+ var tooltip_box_default = TooltipBox;
496
+ export {
497
+ TOOLTIP_PANEL_CLASS_NAME,
498
+ TOOLTIP_PANEL_INNER_CLASS_NAME,
499
+ TooltipBox,
500
+ TooltipPanel,
501
+ tooltip_box_default as default
502
+ };
@@ -0,0 +1,59 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { cn } from "../../lib/utils";
4
+ import { intFmt } from "../chart-formatters";
5
+ function TooltipHeader({ children, className }) {
6
+ return /* @__PURE__ */ jsx(
7
+ "div",
8
+ {
9
+ className: cn(
10
+ "border-b px-3.5 py-2.5 text-left font-medium text-chart-tooltip-foreground text-sm",
11
+ className
12
+ ),
13
+ children
14
+ }
15
+ );
16
+ }
17
+ TooltipHeader.displayName = "TooltipHeader";
18
+ function TooltipContent({ title, rows, children }) {
19
+ const hasBody = rows.length > 0 || Boolean(children);
20
+ return /* @__PURE__ */ jsxs("div", { children: [
21
+ title && /* @__PURE__ */ jsx(TooltipHeader, { children: title }),
22
+ hasBody && /* @__PURE__ */ jsxs("div", { className: "px-3.5 py-3", children: [
23
+ rows.length > 0 && /* @__PURE__ */ jsx("div", { className: "space-y-2", children: rows.map((row) => /* @__PURE__ */ jsxs(
24
+ "div",
25
+ {
26
+ className: "flex items-center justify-between gap-6",
27
+ children: [
28
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
29
+ /* @__PURE__ */ jsx(
30
+ "span",
31
+ {
32
+ className: "size-2 shrink-0 rounded-full",
33
+ style: { backgroundColor: row.color }
34
+ }
35
+ ),
36
+ /* @__PURE__ */ jsx("span", { className: "truncate text-chart-tooltip-muted text-sm", children: row.label })
37
+ ] }),
38
+ /* @__PURE__ */ jsx("span", { className: "text-right font-medium text-chart-tooltip-foreground text-sm tabular-nums", children: typeof row.value === "number" ? intFmt(row.value) : row.value })
39
+ ]
40
+ },
41
+ `${row.label}-${row.color}`
42
+ )) }),
43
+ children && /* @__PURE__ */ jsx(
44
+ "div",
45
+ {
46
+ className: rows.length > 0 ? "mt-2 transition-opacity duration-200 ease-out" : "transition-opacity duration-200 ease-out",
47
+ children
48
+ }
49
+ )
50
+ ] })
51
+ ] });
52
+ }
53
+ TooltipContent.displayName = "TooltipContent";
54
+ var tooltip_content_default = TooltipContent;
55
+ export {
56
+ TooltipContent,
57
+ TooltipHeader,
58
+ tooltip_content_default as default
59
+ };