@aiconstructions/graficos 0.0.0-stage → 0.2.2
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.
- package/ALTERACOES.md +57 -0
- package/LICENSE-BKLIT +21 -0
- package/LICENSE-visx-pattern +21 -0
- package/README.md +189 -2
- package/dist/aic/cores.js +83 -0
- package/dist/aic/index.js +22 -0
- package/dist/aic/interacao.js +55 -0
- package/dist/charts/animation.js +55 -0
- package/dist/charts/arc-geometry.js +58 -0
- package/dist/charts/arc-path.js +15 -0
- package/dist/charts/area-chart-loading.js +89 -0
- package/dist/charts/area-chart.js +149 -0
- package/dist/charts/area-gradient-defs.js +90 -0
- package/dist/charts/area-value-label-layout.js +70 -0
- package/dist/charts/area-value-labels.js +211 -0
- package/dist/charts/area.js +272 -0
- package/dist/charts/background.js +198 -0
- package/dist/charts/band-config.js +82 -0
- package/dist/charts/band-geometry.js +186 -0
- package/dist/charts/band.js +346 -0
- package/dist/charts/bar-chart-loading.js +27 -0
- package/dist/charts/bar-chart.js +545 -0
- package/dist/charts/bar-depth-geometry.js +18 -0
- package/dist/charts/bar-depth.js +608 -0
- package/dist/charts/bar-lollipop.js +278 -0
- package/dist/charts/bar-squares-layout.js +66 -0
- package/dist/charts/bar-squares.js +467 -0
- package/dist/charts/bar-value-label-layout.js +42 -0
- package/dist/charts/bar-x-axis.js +133 -0
- package/dist/charts/bar-y-axis.js +116 -0
- package/dist/charts/bar.js +457 -0
- package/dist/charts/bollinger.js +49 -0
- package/dist/charts/candlestick-chart.js +370 -0
- package/dist/charts/candlestick.js +368 -0
- package/dist/charts/chart-brush-handle.js +91 -0
- package/dist/charts/chart-brush-layout.js +91 -0
- package/dist/charts/chart-brush-selection-overlay.js +87 -0
- package/dist/charts/chart-brush-state.js +253 -0
- package/dist/charts/chart-brush-track-overlay.js +103 -0
- package/dist/charts/chart-brush.js +517 -0
- package/dist/charts/chart-center-typography.js +8 -0
- package/dist/charts/chart-child-passthrough.js +119 -0
- package/dist/charts/chart-config-context.js +56 -0
- package/dist/charts/chart-context.js +337 -0
- package/dist/charts/chart-crosshair.js +262 -0
- package/dist/charts/chart-data-override.js +186 -0
- package/dist/charts/chart-defs.js +56 -0
- package/dist/charts/chart-formatters.js +77 -0
- package/dist/charts/chart-legend-hover.js +27 -0
- package/dist/charts/chart-legend.js +163 -0
- package/dist/charts/chart-loading-label.js +52 -0
- package/dist/charts/chart-parent-size.js +138 -0
- package/dist/charts/chart-phase.js +29 -0
- package/dist/charts/chart-reveal-clip.js +62 -0
- package/dist/charts/chart-scale.js +19 -0
- package/dist/charts/chart-stat-flow.js +72 -0
- package/dist/charts/choropleth/choropleth-background.js +29 -0
- package/dist/charts/choropleth/choropleth-camera.js +379 -0
- package/dist/charts/choropleth/choropleth-chart.js +644 -0
- package/dist/charts/choropleth/choropleth-context.js +152 -0
- package/dist/charts/choropleth/choropleth-dot-grid.js +293 -0
- package/dist/charts/choropleth/choropleth-feature.js +291 -0
- package/dist/charts/choropleth/choropleth-graticule.js +40 -0
- package/dist/charts/choropleth/choropleth-marker.js +222 -0
- package/dist/charts/choropleth/choropleth-projection.js +37 -0
- package/dist/charts/choropleth/choropleth-tooltip.js +82 -0
- package/dist/charts/choropleth/choropleth-zoom-matrix.js +150 -0
- package/dist/charts/choropleth/index.js +44 -0
- package/dist/charts/choropleth/use-choropleth-zoom-state.js +636 -0
- package/dist/charts/composed-chart.js +346 -0
- package/dist/charts/crosshair-store.js +49 -0
- package/dist/charts/dash-tail-stroke.js +58 -0
- package/dist/charts/date-pill-store.js +50 -0
- package/dist/charts/date-ranges.js +131 -0
- package/dist/charts/deadline.js +295 -0
- package/dist/charts/decimate-time-series.js +112 -0
- package/dist/charts/fade-edges.js +171 -0
- package/dist/charts/fast-path.js +78 -0
- package/dist/charts/filter-data-by-x-domain.js +45 -0
- package/dist/charts/funnel-chart.js +773 -0
- package/dist/charts/gauge-arc-layers.js +479 -0
- package/dist/charts/gauge-dial.js +329 -0
- package/dist/charts/gauge-label-layout.js +148 -0
- package/dist/charts/gauge.js +946 -0
- package/dist/charts/generate-chart-skeleton-data.js +27 -0
- package/dist/charts/gradients.js +158 -0
- package/dist/charts/grid-lines.js +114 -0
- package/dist/charts/grid.js +225 -0
- package/dist/charts/heatmap/generate-heatmap-skeleton-data.js +13 -0
- package/dist/charts/heatmap/heatmap-animation.js +128 -0
- package/dist/charts/heatmap/heatmap-cells.js +519 -0
- package/dist/charts/heatmap/heatmap-chart-loading.js +44 -0
- package/dist/charts/heatmap/heatmap-chart.js +548 -0
- package/dist/charts/heatmap/heatmap-colors.js +127 -0
- package/dist/charts/heatmap/heatmap-context.js +107 -0
- package/dist/charts/heatmap/heatmap-legend-gradient.js +97 -0
- package/dist/charts/heatmap/heatmap-legend-swatch.js +76 -0
- package/dist/charts/heatmap/heatmap-legend.js +165 -0
- package/dist/charts/heatmap/heatmap-pattern-defs.js +37 -0
- package/dist/charts/heatmap/heatmap-rect-cells.js +39 -0
- package/dist/charts/heatmap/heatmap-resolve-separator.js +84 -0
- package/dist/charts/heatmap/heatmap-separator.js +168 -0
- package/dist/charts/heatmap/heatmap-tooltip.js +73 -0
- package/dist/charts/heatmap/heatmap-utils.js +633 -0
- package/dist/charts/heatmap/heatmap-x-axis.js +79 -0
- package/dist/charts/heatmap/heatmap-y-axis.js +72 -0
- package/dist/charts/heatmap/index.js +208 -0
- package/dist/charts/highlight-segment-bounds.js +34 -0
- package/dist/charts/highlight-segment.js +119 -0
- package/dist/charts/index.js +944 -0
- package/dist/charts/indicator-fade.js +44 -0
- package/dist/charts/legend/index.js +22 -0
- package/dist/charts/legend/legend-context.js +47 -0
- package/dist/charts/legend/legend-item.js +30 -0
- package/dist/charts/legend/legend-label.js +14 -0
- package/dist/charts/legend/legend-marker.js +18 -0
- package/dist/charts/legend/legend-progress.js +39 -0
- package/dist/charts/legend/legend-value.js +31 -0
- package/dist/charts/legend/legend.js +69 -0
- package/dist/charts/line-backdrop.js +129 -0
- package/dist/charts/line-chart-loading.js +85 -0
- package/dist/charts/line-chart.js +182 -0
- package/dist/charts/line-loading-pulse.js +185 -0
- package/dist/charts/line-loading-timing.js +12 -0
- package/dist/charts/line-path.js +58 -0
- package/dist/charts/line-series-terminal-marker.js +75 -0
- package/dist/charts/line.js +499 -0
- package/dist/charts/live-line-chart.js +494 -0
- package/dist/charts/live-line.js +277 -0
- package/dist/charts/live-x-axis.js +116 -0
- package/dist/charts/live-y-axis.js +164 -0
- package/dist/charts/loading-sweep.js +344 -0
- package/dist/charts/local-point.js +56 -0
- package/dist/charts/markers/chart-markers.js +149 -0
- package/dist/charts/markers/index.js +14 -0
- package/dist/charts/markers/marker-group.js +411 -0
- package/dist/charts/motion-utils.js +29 -0
- package/dist/charts/notch-gauge-shared.js +146 -0
- package/dist/charts/particle-line.js +1340 -0
- package/dist/charts/path-stroke-utils.js +51 -0
- package/dist/charts/pattern-area.js +127 -0
- package/dist/charts/pattern-preset.js +287 -0
- package/dist/charts/pattern-tile.js +31 -0
- package/dist/charts/patterns/circles.js +62 -0
- package/dist/charts/patterns/constants.js +9 -0
- package/dist/charts/patterns/hexagons.js +38 -0
- package/dist/charts/patterns/index.js +16 -0
- package/dist/charts/patterns/lines.js +65 -0
- package/dist/charts/patterns/path.js +37 -0
- package/dist/charts/patterns/pattern.js +16 -0
- package/dist/charts/patterns/waves.js +40 -0
- package/dist/charts/pie-center-shell.js +127 -0
- package/dist/charts/pie-center.js +87 -0
- package/dist/charts/pie-chart.js +377 -0
- package/dist/charts/pie-context.js +116 -0
- package/dist/charts/pie-slice.js +394 -0
- package/dist/charts/pie-ticks.js +332 -0
- package/dist/charts/profit-loss-legend-hover.js +18 -0
- package/dist/charts/profit-loss-legend.js +53 -0
- package/dist/charts/profit-loss-line.js +162 -0
- package/dist/charts/profit-loss-segments.js +88 -0
- package/dist/charts/projection-config.js +90 -0
- package/dist/charts/projection-line-end-marker.js +50 -0
- package/dist/charts/projection-line.js +466 -0
- package/dist/charts/projection-utils.js +303 -0
- package/dist/charts/radar-area.js +192 -0
- package/dist/charts/radar-axis.js +41 -0
- package/dist/charts/radar-chart.js +184 -0
- package/dist/charts/radar-context.js +104 -0
- package/dist/charts/radar-grid.js +121 -0
- package/dist/charts/radar-labels.js +62 -0
- package/dist/charts/radial-area.js +498 -0
- package/dist/charts/radial-axis.js +652 -0
- package/dist/charts/radial-bar.js +316 -0
- package/dist/charts/radial-center.js +67 -0
- package/dist/charts/radial-chart.js +740 -0
- package/dist/charts/radial-dot-bar-layout.js +68 -0
- package/dist/charts/radial-dot-bar.js +387 -0
- package/dist/charts/radial-geometry.js +114 -0
- package/dist/charts/radial-legend.js +66 -0
- package/dist/charts/radial-line.js +280 -0
- package/dist/charts/radial-ring-bar.js +255 -0
- package/dist/charts/radial-scrubber.js +120 -0
- package/dist/charts/radial-series-color.js +10 -0
- package/dist/charts/reference-area-config.js +43 -0
- package/dist/charts/reference-area-geometry.js +76 -0
- package/dist/charts/reference-area-registration-context.js +10 -0
- package/dist/charts/reference-area.js +241 -0
- package/dist/charts/responsive-chart-label-count.js +18 -0
- package/dist/charts/ring-center.js +78 -0
- package/dist/charts/ring-chart.js +362 -0
- package/dist/charts/ring-context.js +122 -0
- package/dist/charts/ring-grid.js +175 -0
- package/dist/charts/ring-labels.js +109 -0
- package/dist/charts/ring.js +237 -0
- package/dist/charts/sankey/index.js +22 -0
- package/dist/charts/sankey/sankey-chart.js +199 -0
- package/dist/charts/sankey/sankey-context.js +32 -0
- package/dist/charts/sankey/sankey-link.js +232 -0
- package/dist/charts/sankey/sankey-node.js +348 -0
- package/dist/charts/sankey/sankey-tooltip.js +94 -0
- package/dist/charts/scatter-chart-shell.js +279 -0
- package/dist/charts/scatter-chart.js +150 -0
- package/dist/charts/scatter-jitter.js +86 -0
- package/dist/charts/scatter-svg.js +17 -0
- package/dist/charts/scatter.js +92 -0
- package/dist/charts/segment.js +107 -0
- package/dist/charts/series-bar-layout.js +42 -0
- package/dist/charts/series-bar.js +241 -0
- package/dist/charts/series-dash-tail-overlay.js +53 -0
- package/dist/charts/series-highlight-layer.js +43 -0
- package/dist/charts/series-hover-dim.js +32 -0
- package/dist/charts/series-markers.js +239 -0
- package/dist/charts/series-path-utils.js +185 -0
- package/dist/charts/series-point-marker.js +150 -0
- package/dist/charts/sparkline-geometry.js +197 -0
- package/dist/charts/sparkline.js +910 -0
- package/dist/charts/static-chart-preview-context.js +16 -0
- package/dist/charts/sunburst-breadcrumb.js +33 -0
- package/dist/charts/sunburst-center.js +37 -0
- package/dist/charts/sunburst-chart.js +408 -0
- package/dist/charts/sunburst-context.js +140 -0
- package/dist/charts/sunburst-data.js +0 -0
- package/dist/charts/sunburst-hint.js +42 -0
- package/dist/charts/sunburst-labels.js +130 -0
- package/dist/charts/sunburst-segment.js +144 -0
- package/dist/charts/sunburst.js +419 -0
- package/dist/charts/time-series-chart-shell.js +688 -0
- package/dist/charts/tooltip/chart-tooltip.js +516 -0
- package/dist/charts/tooltip/cursor-tooltip-box.js +183 -0
- package/dist/charts/tooltip/date-ticker.js +376 -0
- package/dist/charts/tooltip/index.js +32 -0
- package/dist/charts/tooltip/liquid-glass.js +142 -0
- package/dist/charts/tooltip/tooltip-box.js +502 -0
- package/dist/charts/tooltip/tooltip-content.js +59 -0
- package/dist/charts/tooltip/tooltip-dot.js +170 -0
- package/dist/charts/tooltip/tooltip-indicator.js +175 -0
- package/dist/charts/tooltip/use-delayed-tooltip-data.js +41 -0
- package/dist/charts/tooltip/use-velocity-stretch.js +52 -0
- package/dist/charts/trend-line-utils.js +64 -0
- package/dist/charts/trend-line.js +318 -0
- package/dist/charts/use-animated-band.js +175 -0
- package/dist/charts/use-animated-series-path.js +208 -0
- package/dist/charts/use-animated-y-domains.js +192 -0
- package/dist/charts/use-category-slots.js +29 -0
- package/dist/charts/use-chart-interaction.js +296 -0
- package/dist/charts/use-chart-phase-orchestrator.js +183 -0
- package/dist/charts/use-enter-complete.js +18 -0
- package/dist/charts/use-grid-shimmer.js +88 -0
- package/dist/charts/use-highlight-segment.js +65 -0
- package/dist/charts/use-mount-progress.js +23 -0
- package/dist/charts/use-scatter-chart-interaction.js +364 -0
- package/dist/charts/use-scheduled-tooltip.js +84 -0
- package/dist/charts/visx-pattern.js +30 -0
- package/dist/charts/weekends.js +174 -0
- package/dist/charts/x-axis-hover.js +46 -0
- package/dist/charts/x-axis.js +523 -0
- package/dist/charts/y-axis-scales.js +71 -0
- package/dist/charts/y-axis-ticks.js +22 -0
- package/dist/charts/y-axis.js +233 -0
- package/dist/charts/y-domain-utils.js +189 -0
- package/dist/index.d.ts +7346 -0
- package/dist/index.js +2 -0
- package/dist/lib/utils.js +8 -0
- package/dist/shimmering-text.js +54 -0
- package/package.json +78 -4
- package/tema.css +202 -0
|
@@ -0,0 +1,1340 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { curveMonotoneX } from "d3-shape";
|
|
4
|
+
import { animate, m, useMotionValue } from "motion/react";
|
|
5
|
+
import {
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useId,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState
|
|
13
|
+
} from "react";
|
|
14
|
+
import { createPortal } from "react-dom";
|
|
15
|
+
import {
|
|
16
|
+
selectIsChartHovering,
|
|
17
|
+
useChartHoverSelector,
|
|
18
|
+
useChartPortalContainer,
|
|
19
|
+
useChartStable,
|
|
20
|
+
useYScale
|
|
21
|
+
} from "./chart-context";
|
|
22
|
+
import { HighlightSegment } from "./highlight-segment";
|
|
23
|
+
import { linePathD } from "./line-path";
|
|
24
|
+
import { SeriesHoverDim } from "./series-hover-dim";
|
|
25
|
+
import { useHighlightSegment } from "./use-highlight-segment";
|
|
26
|
+
const PARTICLE_LINE_GOLD = [
|
|
27
|
+
"#c8891a",
|
|
28
|
+
"#ffd45e",
|
|
29
|
+
"#f2a91f",
|
|
30
|
+
"#ffe9a3"
|
|
31
|
+
];
|
|
32
|
+
const EFFECTS = {
|
|
33
|
+
assemble: {
|
|
34
|
+
mode: 0,
|
|
35
|
+
life: [0.1, 0.7],
|
|
36
|
+
speed: [0, 0],
|
|
37
|
+
backward: 0,
|
|
38
|
+
gravity: 0,
|
|
39
|
+
drag: 0,
|
|
40
|
+
size: [1.2, 3.6],
|
|
41
|
+
twinkle: 0.45,
|
|
42
|
+
cooling: 0,
|
|
43
|
+
flare: 0,
|
|
44
|
+
heatGain: 1
|
|
45
|
+
},
|
|
46
|
+
comet: {
|
|
47
|
+
mode: 1,
|
|
48
|
+
life: [0.8, 1.9],
|
|
49
|
+
speed: [50, 190],
|
|
50
|
+
backward: 0.93,
|
|
51
|
+
gravity: -12,
|
|
52
|
+
drag: 0.9,
|
|
53
|
+
size: [1.6, 5.2],
|
|
54
|
+
twinkle: 0.3,
|
|
55
|
+
cooling: 2.4,
|
|
56
|
+
flare: 38,
|
|
57
|
+
heatGain: 2.1
|
|
58
|
+
},
|
|
59
|
+
stardust: {
|
|
60
|
+
mode: 1,
|
|
61
|
+
life: [1, 2.4],
|
|
62
|
+
speed: [8, 45],
|
|
63
|
+
backward: 0.25,
|
|
64
|
+
gravity: -30,
|
|
65
|
+
drag: 0.9,
|
|
66
|
+
size: [1, 3.4],
|
|
67
|
+
twinkle: 1,
|
|
68
|
+
cooling: 1.3,
|
|
69
|
+
flare: 22,
|
|
70
|
+
heatGain: 1.3
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const GLOW_WIDTH_SCALE = 1.5;
|
|
74
|
+
const GLOW_BLUR = 3.5;
|
|
75
|
+
const GLOW_OPACITY = 0.6;
|
|
76
|
+
const RIBBON_PAD = 12;
|
|
77
|
+
const MAX_PARTICLES = 14e3;
|
|
78
|
+
const MAX_DPR = 2;
|
|
79
|
+
const HEAT_FADE_S = 0.9;
|
|
80
|
+
const PARTICLE_STRIDE = 10;
|
|
81
|
+
const RIBBON_STRIDE = 5;
|
|
82
|
+
const PALETTE_GLSL = `
|
|
83
|
+
uniform vec3 u_hot;
|
|
84
|
+
uniform vec3 u_c0;
|
|
85
|
+
uniform vec3 u_c1;
|
|
86
|
+
uniform vec3 u_c2;
|
|
87
|
+
uniform vec3 u_c3;
|
|
88
|
+
vec3 palette(float t) {
|
|
89
|
+
t = clamp(t, 0.0, 1.0) * 3.0;
|
|
90
|
+
vec3 c = mix(u_c0, u_c1, clamp(t, 0.0, 1.0));
|
|
91
|
+
c = mix(c, u_c2, clamp(t - 1.0, 0.0, 1.0));
|
|
92
|
+
return mix(c, u_c3, clamp(t - 2.0, 0.0, 1.0));
|
|
93
|
+
}`;
|
|
94
|
+
const HOT = "u_hot";
|
|
95
|
+
const HOT_ON_DARK = [1, 0.97, 0.88];
|
|
96
|
+
const RIBBON_VS = `
|
|
97
|
+
attribute vec2 a_pos;
|
|
98
|
+
attribute float a_s;
|
|
99
|
+
attribute float a_side;
|
|
100
|
+
attribute float a_cx;
|
|
101
|
+
uniform vec2 u_res;
|
|
102
|
+
varying float v_s;
|
|
103
|
+
varying float v_side;
|
|
104
|
+
varying float v_cx;
|
|
105
|
+
void main() {
|
|
106
|
+
v_s = a_s;
|
|
107
|
+
v_side = a_side;
|
|
108
|
+
// The fragment's own x \u2014 SVG gradients and the hover mask key off pixel x.
|
|
109
|
+
v_cx = a_pos.x;
|
|
110
|
+
vec2 clip = (a_pos / u_res) * 2.0 - 1.0;
|
|
111
|
+
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
112
|
+
}`;
|
|
113
|
+
const STROKE_FS = `
|
|
114
|
+
precision highp float;
|
|
115
|
+
varying float v_s;
|
|
116
|
+
varying float v_side;
|
|
117
|
+
varying float v_cx;
|
|
118
|
+
uniform float u_front;
|
|
119
|
+
uniform float u_total;
|
|
120
|
+
uniform float u_trail;
|
|
121
|
+
uniform float u_heat;
|
|
122
|
+
uniform float u_heatMix;
|
|
123
|
+
uniform float u_radius;
|
|
124
|
+
uniform float u_halfW;
|
|
125
|
+
uniform float u_dpr;
|
|
126
|
+
uniform float u_xStart;
|
|
127
|
+
uniform float u_xSpan;
|
|
128
|
+
${PALETTE_GLSL}
|
|
129
|
+
void main() {
|
|
130
|
+
// Distance to the drawn centreline segment [0, end] \u2014 round caps at both
|
|
131
|
+
// ends and at the moving tip fall out of the same measure.
|
|
132
|
+
float end = min(u_front, u_total);
|
|
133
|
+
float across = abs(v_side) * u_halfW;
|
|
134
|
+
float along = v_s < 0.0 ? -v_s : max(v_s - end, 0.0);
|
|
135
|
+
float dist = length(vec2(along, across));
|
|
136
|
+
// Same coverage ramp as a rasterised SVG stroke: 1 device px wide.
|
|
137
|
+
float cov = clamp((u_radius - dist) * u_dpr + 0.5, 0.0, 1.0);
|
|
138
|
+
|
|
139
|
+
// Reveal-only: white-hot trail and metallic sheen, zero once cooled.
|
|
140
|
+
float heat = exp(-max(end - v_s, 0.0) / u_trail) * u_heat * u_heatMix;
|
|
141
|
+
float h = clamp(heat, 0.0, 1.0);
|
|
142
|
+
float sheen = mix(1.0, 0.85 + 0.25 * (-v_side), h);
|
|
143
|
+
float t = clamp((v_cx - u_xStart) / u_xSpan, 0.0, 1.0);
|
|
144
|
+
vec3 col = mix(palette(t), ${HOT}, h * 0.75) * sheen;
|
|
145
|
+
gl_FragColor = vec4(col * cov, cov);
|
|
146
|
+
}`;
|
|
147
|
+
const BLOOM_FS = `
|
|
148
|
+
precision highp float;
|
|
149
|
+
varying float v_s;
|
|
150
|
+
varying float v_side;
|
|
151
|
+
uniform float u_front;
|
|
152
|
+
uniform float u_total;
|
|
153
|
+
uniform float u_trail;
|
|
154
|
+
uniform float u_heat;
|
|
155
|
+
uniform float u_halfW;
|
|
156
|
+
${PALETTE_GLSL}
|
|
157
|
+
void main() {
|
|
158
|
+
float end = min(u_front, u_total);
|
|
159
|
+
float across = abs(v_side) * u_halfW;
|
|
160
|
+
float along = v_s < 0.0 ? -v_s : max(v_s - end, 0.0);
|
|
161
|
+
float dist = length(vec2(along, across));
|
|
162
|
+
float heat = exp(-max(end - v_s, 0.0) / u_trail) * u_heat;
|
|
163
|
+
float b = exp(-(dist * dist) / (u_halfW * u_halfW * 0.06)) * heat;
|
|
164
|
+
gl_FragColor = vec4(${HOT} * b, b);
|
|
165
|
+
}`;
|
|
166
|
+
const QUAD_VS = `
|
|
167
|
+
attribute vec2 a_pos;
|
|
168
|
+
varying vec2 v_uv;
|
|
169
|
+
void main() {
|
|
170
|
+
v_uv = a_pos * 0.5 + 0.5;
|
|
171
|
+
gl_Position = vec4(a_pos, 0.0, 1.0);
|
|
172
|
+
}`;
|
|
173
|
+
const BLUR_FS = `
|
|
174
|
+
precision highp float;
|
|
175
|
+
varying vec2 v_uv;
|
|
176
|
+
uniform sampler2D u_tex;
|
|
177
|
+
uniform vec2 u_step;
|
|
178
|
+
uniform float u_sigma;
|
|
179
|
+
void main() {
|
|
180
|
+
float reach = ceil(u_sigma * 3.0);
|
|
181
|
+
vec4 sum = vec4(0.0);
|
|
182
|
+
float total = 0.0;
|
|
183
|
+
for (int i = -48; i <= 48; i++) {
|
|
184
|
+
float fi = float(i);
|
|
185
|
+
if (abs(fi) > reach) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
float w = exp(-0.5 * fi * fi / (u_sigma * u_sigma));
|
|
189
|
+
sum += texture2D(u_tex, v_uv + u_step * fi) * w;
|
|
190
|
+
total += w;
|
|
191
|
+
}
|
|
192
|
+
gl_FragColor = sum / total;
|
|
193
|
+
}`;
|
|
194
|
+
const COMPOSITE_FS = `
|
|
195
|
+
precision highp float;
|
|
196
|
+
varying vec2 v_uv;
|
|
197
|
+
uniform sampler2D u_core;
|
|
198
|
+
uniform sampler2D u_glow;
|
|
199
|
+
uniform vec2 u_res;
|
|
200
|
+
uniform float u_glowOpacity;
|
|
201
|
+
uniform float u_hover;
|
|
202
|
+
uniform vec2 u_seg;
|
|
203
|
+
uniform float u_segFade;
|
|
204
|
+
uniform float u_dim;
|
|
205
|
+
void main() {
|
|
206
|
+
vec4 core = texture2D(u_core, v_uv);
|
|
207
|
+
vec4 glow = texture2D(u_glow, v_uv) * u_glowOpacity * (1.0 - u_hover);
|
|
208
|
+
vec4 line = core + glow * (1.0 - core.a);
|
|
209
|
+
float x = v_uv.x * u_res.x;
|
|
210
|
+
float inSegment =
|
|
211
|
+
clamp((x - u_seg.x) / u_segFade, 0.0, 1.0) *
|
|
212
|
+
clamp((u_seg.y - x) / u_segFade, 0.0, 1.0);
|
|
213
|
+
gl_FragColor = line * mix(1.0, mix(u_dim, 1.0, inSegment), u_hover);
|
|
214
|
+
}`;
|
|
215
|
+
const PARTICLE_VS = `
|
|
216
|
+
attribute vec2 a_target;
|
|
217
|
+
attribute float a_s;
|
|
218
|
+
attribute vec2 a_tan;
|
|
219
|
+
attribute vec4 a_rand;
|
|
220
|
+
attribute float a_when;
|
|
221
|
+
uniform vec2 u_res;
|
|
222
|
+
uniform float u_time;
|
|
223
|
+
uniform float u_delay;
|
|
224
|
+
uniform float u_duration;
|
|
225
|
+
uniform float u_spread;
|
|
226
|
+
uniform float u_dpr;
|
|
227
|
+
uniform float u_mode;
|
|
228
|
+
uniform vec2 u_life;
|
|
229
|
+
uniform vec2 u_speed;
|
|
230
|
+
uniform vec2 u_size;
|
|
231
|
+
uniform float u_backward;
|
|
232
|
+
uniform float u_gravity;
|
|
233
|
+
uniform float u_drag;
|
|
234
|
+
uniform float u_twinkle;
|
|
235
|
+
uniform float u_cooling;
|
|
236
|
+
varying float v_alpha;
|
|
237
|
+
varying float v_heat;
|
|
238
|
+
varying float v_s;
|
|
239
|
+
|
|
240
|
+
vec2 rotate(vec2 v, float a) {
|
|
241
|
+
float c = cos(a);
|
|
242
|
+
float s = sin(a);
|
|
243
|
+
return vec2(c * v.x - s * v.y, s * v.x + c * v.y);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
void hide() {
|
|
247
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
248
|
+
gl_PointSize = 0.0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
void main() {
|
|
252
|
+
float pass = u_delay + a_when * u_duration;
|
|
253
|
+
float t = u_time - pass;
|
|
254
|
+
float life = mix(u_life.x, u_life.y, a_rand.y);
|
|
255
|
+
float twinkle = 1.0 - u_twinkle * (0.5 + 0.5 * sin(u_time * 18.0 + a_rand.w * 60.0));
|
|
256
|
+
vec2 pos;
|
|
257
|
+
|
|
258
|
+
if (u_mode < 0.5) {
|
|
259
|
+
// Assemble: fly in from up-right, swirl, land, glow briefly.
|
|
260
|
+
float flight = mix(0.55, 1.5, a_rand.x);
|
|
261
|
+
if (t < -flight || t > life) { hide(); return; }
|
|
262
|
+
float k = clamp((t + flight) / flight, 0.0, 1.0);
|
|
263
|
+
float e = 1.0 - pow(1.0 - k, 3.0);
|
|
264
|
+
vec2 offset = vec2(
|
|
265
|
+
mix(0.15, 1.0, a_rand.z) * u_spread,
|
|
266
|
+
-mix(-0.35, 1.0, a_rand.w) * u_spread * 0.85
|
|
267
|
+
);
|
|
268
|
+
offset = rotate(offset, (1.0 - e) * mix(-2.2, 2.2, a_rand.x));
|
|
269
|
+
pos = a_target + offset * (1.0 - e);
|
|
270
|
+
pos += vec2(
|
|
271
|
+
sin(u_time * 3.1 + a_rand.y * 40.0),
|
|
272
|
+
cos(u_time * 2.6 + a_rand.z * 40.0)
|
|
273
|
+
) * 7.0 * (1.0 - e);
|
|
274
|
+
float landed = step(0.0, t);
|
|
275
|
+
float afterglow = 1.0 - clamp(t / life, 0.0, 1.0);
|
|
276
|
+
v_alpha = smoothstep(0.0, 0.3, k) * mix(1.0, afterglow, landed) * twinkle;
|
|
277
|
+
v_heat = mix(e * e, afterglow, landed);
|
|
278
|
+
} else {
|
|
279
|
+
// Emit: born at the head, thrown off, cooling as it trails away.
|
|
280
|
+
if (t < 0.0 || t > life) { hide(); return; }
|
|
281
|
+
float angle = a_rand.z * 6.2831853;
|
|
282
|
+
vec2 dir = normalize(mix(vec2(cos(angle), sin(angle)), -a_tan, u_backward) + 1e-4);
|
|
283
|
+
float speed = mix(u_speed.x, u_speed.y, a_rand.x * a_rand.x) * (u_spread / 150.0);
|
|
284
|
+
float travel = u_drag > 0.0 ? (1.0 - exp(-u_drag * t)) / u_drag : t;
|
|
285
|
+
pos = a_target + dir * speed * travel + vec2(0.0, 0.5 * u_gravity * t * t);
|
|
286
|
+
float fade = 1.0 - t / life;
|
|
287
|
+
v_alpha = fade * fade * twinkle;
|
|
288
|
+
v_heat = exp(-t * u_cooling);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
v_s = a_s;
|
|
292
|
+
gl_PointSize = mix(u_size.x, u_size.y, a_rand.w * a_rand.z) * (0.7 + 0.6 * v_heat) * u_dpr;
|
|
293
|
+
vec2 clip = (pos / u_res) * 2.0 - 1.0;
|
|
294
|
+
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
295
|
+
}`;
|
|
296
|
+
const PARTICLE_FS = `
|
|
297
|
+
precision highp float;
|
|
298
|
+
varying float v_alpha;
|
|
299
|
+
varying float v_heat;
|
|
300
|
+
varying float v_s;
|
|
301
|
+
${PALETTE_GLSL}
|
|
302
|
+
void main() {
|
|
303
|
+
vec2 uv = gl_PointCoord - 0.5;
|
|
304
|
+
float d = length(uv) * 2.0;
|
|
305
|
+
float a = exp(-d * d * 3.5) * v_alpha;
|
|
306
|
+
vec3 col = mix(palette(v_s), ${HOT}, v_heat * 0.6);
|
|
307
|
+
gl_FragColor = vec4(col * a, a);
|
|
308
|
+
}`;
|
|
309
|
+
const FLARE_VS = `
|
|
310
|
+
attribute vec2 a_pos;
|
|
311
|
+
uniform vec2 u_res;
|
|
312
|
+
uniform float u_size;
|
|
313
|
+
uniform float u_dpr;
|
|
314
|
+
void main() {
|
|
315
|
+
vec2 clip = (a_pos / u_res) * 2.0 - 1.0;
|
|
316
|
+
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
317
|
+
gl_PointSize = u_size * u_dpr;
|
|
318
|
+
}`;
|
|
319
|
+
const FLARE_FS = `
|
|
320
|
+
precision highp float;
|
|
321
|
+
uniform float u_alpha;
|
|
322
|
+
uniform float u_time;
|
|
323
|
+
uniform float u_tint;
|
|
324
|
+
${PALETTE_GLSL}
|
|
325
|
+
void main() {
|
|
326
|
+
vec2 uv = (gl_PointCoord - 0.5) * 2.0;
|
|
327
|
+
float d = length(uv);
|
|
328
|
+
float core = exp(-d * d * 40.0);
|
|
329
|
+
float halo = exp(-d * d * 5.0) * 0.55;
|
|
330
|
+
float flicker = 0.85 + 0.15 * sin(u_time * 40.0);
|
|
331
|
+
float rays = (exp(-abs(uv.y) * 28.0) + exp(-abs(uv.x) * 28.0)) * max(0.0, 1.0 - d) * 0.7;
|
|
332
|
+
float a = clamp((core + halo + rays) * u_alpha * flicker, 0.0, 1.0);
|
|
333
|
+
vec3 col = mix(palette(u_tint), ${HOT}, clamp(core * 2.0 + 0.4, 0.0, 1.0));
|
|
334
|
+
gl_FragColor = vec4(col * a, a);
|
|
335
|
+
}`;
|
|
336
|
+
function compile(gl, type, source) {
|
|
337
|
+
const shader = gl.createShader(type);
|
|
338
|
+
if (!shader) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
gl.shaderSource(shader, source);
|
|
342
|
+
gl.compileShader(shader);
|
|
343
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
344
|
+
console.warn("[ParticleLine]", gl.getShaderInfoLog(shader));
|
|
345
|
+
gl.deleteShader(shader);
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
return shader;
|
|
349
|
+
}
|
|
350
|
+
function link(gl, vsSource, fsSource) {
|
|
351
|
+
const vs = compile(gl, gl.VERTEX_SHADER, vsSource);
|
|
352
|
+
const fs = compile(gl, gl.FRAGMENT_SHADER, fsSource);
|
|
353
|
+
const program = gl.createProgram();
|
|
354
|
+
if (!(vs && fs && program)) {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
gl.attachShader(program, vs);
|
|
358
|
+
gl.attachShader(program, fs);
|
|
359
|
+
gl.linkProgram(program);
|
|
360
|
+
gl.deleteShader(vs);
|
|
361
|
+
gl.deleteShader(fs);
|
|
362
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
363
|
+
console.warn("[ParticleLine]", gl.getProgramInfoLog(program));
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
const uniforms = /* @__PURE__ */ new Map();
|
|
367
|
+
return {
|
|
368
|
+
program,
|
|
369
|
+
uniform: (name) => {
|
|
370
|
+
if (!uniforms.has(name)) {
|
|
371
|
+
uniforms.set(name, gl.getUniformLocation(program, name));
|
|
372
|
+
}
|
|
373
|
+
return uniforms.get(name) ?? null;
|
|
374
|
+
},
|
|
375
|
+
attrib: (name) => gl.getAttribLocation(program, name)
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function bindAttribs(gl, program, layout) {
|
|
379
|
+
const stride = layout.reduce((sum, [, size]) => sum + size, 0) * 4;
|
|
380
|
+
const enabled = [];
|
|
381
|
+
let offset = 0;
|
|
382
|
+
for (const [name, size] of layout) {
|
|
383
|
+
const loc = program.attrib(name);
|
|
384
|
+
if (loc >= 0) {
|
|
385
|
+
gl.enableVertexAttribArray(loc);
|
|
386
|
+
gl.vertexAttribPointer(loc, size, gl.FLOAT, false, stride, offset);
|
|
387
|
+
enabled.push(loc);
|
|
388
|
+
}
|
|
389
|
+
offset += size * 4;
|
|
390
|
+
}
|
|
391
|
+
return enabled;
|
|
392
|
+
}
|
|
393
|
+
function hexToRgb(hex) {
|
|
394
|
+
let h = hex.trim().replace("#", "");
|
|
395
|
+
if (h.length === 3) {
|
|
396
|
+
h = [...h].map((c) => c + c).join("");
|
|
397
|
+
}
|
|
398
|
+
const rgb = [0, 2, 4].map((i) => Number.parseInt(h.slice(i, i + 2), 16));
|
|
399
|
+
if (rgb.some(Number.isNaN)) {
|
|
400
|
+
return [1, 1, 1];
|
|
401
|
+
}
|
|
402
|
+
return [(rgb[0] ?? 255) / 255, (rgb[1] ?? 255) / 255, (rgb[2] ?? 255) / 255];
|
|
403
|
+
}
|
|
404
|
+
function seededRandom(seed) {
|
|
405
|
+
let state = seed;
|
|
406
|
+
return () => {
|
|
407
|
+
state = (state * 1664525 + 1013904223) % 4294967296;
|
|
408
|
+
return state / 4294967296;
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
const CUBIC_BEZIER_RE = /cubic-bezier\(([^)]+)\)/;
|
|
412
|
+
const DEFAULT_EASE = [0.85, 0, 0.15, 1];
|
|
413
|
+
function bezierAxis(p1, p2, t) {
|
|
414
|
+
const u = 1 - t;
|
|
415
|
+
return 3 * u * u * t * p1 + 3 * u * t * t * p2 + t * t * t;
|
|
416
|
+
}
|
|
417
|
+
function solveBezier(p1, p2, value) {
|
|
418
|
+
let lo = 0;
|
|
419
|
+
let hi = 1;
|
|
420
|
+
for (let i = 0; i < 32; i++) {
|
|
421
|
+
const mid = (lo + hi) / 2;
|
|
422
|
+
if (bezierAxis(p1, p2, mid) < value) {
|
|
423
|
+
lo = mid;
|
|
424
|
+
} else {
|
|
425
|
+
hi = mid;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return (lo + hi) / 2;
|
|
429
|
+
}
|
|
430
|
+
function easeAt([x1, y1, x2, y2], time) {
|
|
431
|
+
return bezierAxis(y1, y2, solveBezier(x1, x2, time));
|
|
432
|
+
}
|
|
433
|
+
function timeAtProgress([x1, y1, x2, y2], progress) {
|
|
434
|
+
return bezierAxis(x1, x2, solveBezier(y1, y2, progress));
|
|
435
|
+
}
|
|
436
|
+
function isBezier(value) {
|
|
437
|
+
return Array.isArray(value) && value.length === 4 && value.every((n) => typeof n === "number");
|
|
438
|
+
}
|
|
439
|
+
function resolveChartEase(enterEase, animationEasing) {
|
|
440
|
+
if (isBezier(enterEase)) {
|
|
441
|
+
return enterEase;
|
|
442
|
+
}
|
|
443
|
+
const match = animationEasing?.match(CUBIC_BEZIER_RE);
|
|
444
|
+
const parsed = match?.[1]?.split(",").map(Number);
|
|
445
|
+
if (isBezier(parsed) && parsed.every(Number.isFinite)) {
|
|
446
|
+
return parsed;
|
|
447
|
+
}
|
|
448
|
+
return DEFAULT_EASE;
|
|
449
|
+
}
|
|
450
|
+
function sampleLine(path, offsetX, offsetY, plotWidth) {
|
|
451
|
+
const total = path.getTotalLength();
|
|
452
|
+
if (!(total > 1)) {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
const count = Math.ceil(total) + 1;
|
|
456
|
+
const points = new Float32Array(count * 2);
|
|
457
|
+
const lengths = new Float32Array(count);
|
|
458
|
+
for (let i = 0; i < count; i++) {
|
|
459
|
+
const at = Math.min(i, total);
|
|
460
|
+
const p = path.getPointAtLength(at);
|
|
461
|
+
points[i * 2] = p.x + offsetX;
|
|
462
|
+
points[i * 2 + 1] = p.y + offsetY;
|
|
463
|
+
lengths[i] = at;
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
points,
|
|
467
|
+
lengths,
|
|
468
|
+
total,
|
|
469
|
+
xStart: offsetX,
|
|
470
|
+
xEnd: offsetX + Math.max(plotWidth, 1)
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
function pointAt(samples, length) {
|
|
474
|
+
const last = samples.lengths.length - 1;
|
|
475
|
+
const i = Math.min(last, Math.max(0, Math.round(length)));
|
|
476
|
+
return [samples.points[i * 2] ?? 0, samples.points[i * 2 + 1] ?? 0];
|
|
477
|
+
}
|
|
478
|
+
function xFraction(samples, i) {
|
|
479
|
+
const x = samples.points[i * 2] ?? samples.xStart;
|
|
480
|
+
const span = samples.xEnd - samples.xStart;
|
|
481
|
+
return Math.min(Math.max((x - samples.xStart) / span, 0), 1);
|
|
482
|
+
}
|
|
483
|
+
function lengthAtXFraction(samples, fraction) {
|
|
484
|
+
const target = samples.xStart + fraction * (samples.xEnd - samples.xStart);
|
|
485
|
+
let lo = 0;
|
|
486
|
+
let hi = samples.lengths.length - 1;
|
|
487
|
+
while (lo < hi) {
|
|
488
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
489
|
+
if ((samples.points[mid * 2] ?? 0) < target) {
|
|
490
|
+
lo = mid + 1;
|
|
491
|
+
} else {
|
|
492
|
+
hi = mid;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return samples.lengths[lo] ?? samples.total;
|
|
496
|
+
}
|
|
497
|
+
function tangentAt(samples, i) {
|
|
498
|
+
const n = samples.lengths.length;
|
|
499
|
+
const a = Math.max(0, i - 2);
|
|
500
|
+
const b = Math.min(n - 1, i + 2);
|
|
501
|
+
const dx = (samples.points[b * 2] ?? 0) - (samples.points[a * 2] ?? 0);
|
|
502
|
+
const dy = (samples.points[b * 2 + 1] ?? 0) - (samples.points[a * 2 + 1] ?? 0);
|
|
503
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
504
|
+
return [dx / len, dy / len];
|
|
505
|
+
}
|
|
506
|
+
function buildRibbon(samples, halfWidth) {
|
|
507
|
+
const n = samples.lengths.length;
|
|
508
|
+
const out = new Float32Array((n + 2) * 2 * RIBBON_STRIDE);
|
|
509
|
+
const write = (slot, x, y, [tx, ty], s) => {
|
|
510
|
+
for (const [j, side] of [
|
|
511
|
+
[0, -1],
|
|
512
|
+
[1, 1]
|
|
513
|
+
]) {
|
|
514
|
+
const o = (slot * 2 + j) * RIBBON_STRIDE;
|
|
515
|
+
out[o] = x - ty * side * halfWidth;
|
|
516
|
+
out[o + 1] = y + tx * side * halfWidth;
|
|
517
|
+
out[o + 2] = s;
|
|
518
|
+
out[o + 3] = side;
|
|
519
|
+
out[o + 4] = x;
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
const first = tangentAt(samples, 0);
|
|
523
|
+
const last = tangentAt(samples, n - 1);
|
|
524
|
+
const x0 = samples.points[0] ?? 0;
|
|
525
|
+
const y0 = samples.points[1] ?? 0;
|
|
526
|
+
write(
|
|
527
|
+
0,
|
|
528
|
+
x0 - first[0] * halfWidth,
|
|
529
|
+
y0 - first[1] * halfWidth,
|
|
530
|
+
first,
|
|
531
|
+
-halfWidth
|
|
532
|
+
);
|
|
533
|
+
for (let i = 0; i < n; i++) {
|
|
534
|
+
write(
|
|
535
|
+
i + 1,
|
|
536
|
+
samples.points[i * 2] ?? 0,
|
|
537
|
+
samples.points[i * 2 + 1] ?? 0,
|
|
538
|
+
tangentAt(samples, i),
|
|
539
|
+
samples.lengths[i] ?? 0
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
const xn = samples.points[(n - 1) * 2] ?? 0;
|
|
543
|
+
const yn = samples.points[(n - 1) * 2 + 1] ?? 0;
|
|
544
|
+
write(
|
|
545
|
+
n + 1,
|
|
546
|
+
xn + last[0] * halfWidth,
|
|
547
|
+
yn + last[1] * halfWidth,
|
|
548
|
+
last,
|
|
549
|
+
samples.total + halfWidth
|
|
550
|
+
);
|
|
551
|
+
return out;
|
|
552
|
+
}
|
|
553
|
+
function buildParticles(samples, density, strokeWidth, timeAt) {
|
|
554
|
+
const count = Math.min(
|
|
555
|
+
MAX_PARTICLES,
|
|
556
|
+
Math.max(1, Math.round(samples.total * density))
|
|
557
|
+
);
|
|
558
|
+
const random = seededRandom(73313);
|
|
559
|
+
const out = new Float32Array(count * PARTICLE_STRIDE);
|
|
560
|
+
const last = samples.lengths.length - 1;
|
|
561
|
+
for (let p = 0; p < count; p++) {
|
|
562
|
+
const s = random();
|
|
563
|
+
const i = Math.min(last, Math.round(s * last));
|
|
564
|
+
const [tx, ty] = tangentAt(samples, i);
|
|
565
|
+
const across = (random() - 0.5) * strokeWidth * 1.6;
|
|
566
|
+
const o = p * PARTICLE_STRIDE;
|
|
567
|
+
out[o] = (samples.points[i * 2] ?? 0) - ty * across;
|
|
568
|
+
out[o + 1] = (samples.points[i * 2 + 1] ?? 0) + tx * across;
|
|
569
|
+
out[o + 2] = xFraction(samples, i);
|
|
570
|
+
out[o + 3] = tx;
|
|
571
|
+
out[o + 4] = ty;
|
|
572
|
+
out[o + 5] = random();
|
|
573
|
+
out[o + 6] = random();
|
|
574
|
+
out[o + 7] = random();
|
|
575
|
+
out[o + 8] = random();
|
|
576
|
+
out[o + 9] = timeAt(xFraction(samples, i));
|
|
577
|
+
}
|
|
578
|
+
return out;
|
|
579
|
+
}
|
|
580
|
+
function createTarget(gl) {
|
|
581
|
+
const texture = gl.createTexture();
|
|
582
|
+
const framebuffer = gl.createFramebuffer();
|
|
583
|
+
if (!(texture && framebuffer)) {
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
587
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
588
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
589
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
590
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
591
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
592
|
+
gl.framebufferTexture2D(
|
|
593
|
+
gl.FRAMEBUFFER,
|
|
594
|
+
gl.COLOR_ATTACHMENT0,
|
|
595
|
+
gl.TEXTURE_2D,
|
|
596
|
+
texture,
|
|
597
|
+
0
|
|
598
|
+
);
|
|
599
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
600
|
+
return { texture, framebuffer };
|
|
601
|
+
}
|
|
602
|
+
const RIBBON_LAYOUT = [
|
|
603
|
+
["a_pos", 2],
|
|
604
|
+
["a_s", 1],
|
|
605
|
+
["a_side", 1],
|
|
606
|
+
["a_cx", 1]
|
|
607
|
+
];
|
|
608
|
+
function createRenderer(canvas, settings) {
|
|
609
|
+
const gl = canvas.getContext("webgl", {
|
|
610
|
+
alpha: true,
|
|
611
|
+
antialias: false,
|
|
612
|
+
premultipliedAlpha: true
|
|
613
|
+
});
|
|
614
|
+
if (!gl) {
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
const minmax = gl.getExtension("EXT_blend_minmax");
|
|
618
|
+
const stroke = link(gl, RIBBON_VS, STROKE_FS);
|
|
619
|
+
const bloom = link(gl, RIBBON_VS, BLOOM_FS);
|
|
620
|
+
const blur = link(gl, QUAD_VS, BLUR_FS);
|
|
621
|
+
const composite = link(gl, QUAD_VS, COMPOSITE_FS);
|
|
622
|
+
const particles = link(gl, PARTICLE_VS, PARTICLE_FS);
|
|
623
|
+
const flare = link(gl, FLARE_VS, FLARE_FS);
|
|
624
|
+
const narrowBuffer = gl.createBuffer();
|
|
625
|
+
const wideBuffer = gl.createBuffer();
|
|
626
|
+
const quadBuffer = gl.createBuffer();
|
|
627
|
+
const particleBuffer = gl.createBuffer();
|
|
628
|
+
const flareBuffer = gl.createBuffer();
|
|
629
|
+
const coreTarget = createTarget(gl);
|
|
630
|
+
const glowTarget = createTarget(gl);
|
|
631
|
+
const scratchTarget = createTarget(gl);
|
|
632
|
+
if (!(stroke && bloom && blur && composite && particles && flare && narrowBuffer && wideBuffer && quadBuffer && particleBuffer && flareBuffer && coreTarget && glowTarget && scratchTarget)) {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
const targets = [coreTarget, glowTarget, scratchTarget];
|
|
636
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
637
|
+
gl.bufferData(
|
|
638
|
+
gl.ARRAY_BUFFER,
|
|
639
|
+
new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
|
|
640
|
+
gl.STATIC_DRAW
|
|
641
|
+
);
|
|
642
|
+
const headData = new Float32Array(2);
|
|
643
|
+
let narrowCount = 0;
|
|
644
|
+
let wideCount = 0;
|
|
645
|
+
let particleCount = 0;
|
|
646
|
+
let cssWidth = 1;
|
|
647
|
+
let cssHeight = 1;
|
|
648
|
+
let dpr = 1;
|
|
649
|
+
let palette = [];
|
|
650
|
+
let hot = HOT_ON_DARK;
|
|
651
|
+
const usePalette = (program) => {
|
|
652
|
+
gl.uniform3f(program.uniform("u_hot"), hot[0], hot[1], hot[2]);
|
|
653
|
+
palette.forEach(([r, g, b], i) => {
|
|
654
|
+
gl.uniform3f(program.uniform(`u_c${i}`), r, g, b);
|
|
655
|
+
});
|
|
656
|
+
};
|
|
657
|
+
const disable = (locations) => {
|
|
658
|
+
for (const loc of locations) {
|
|
659
|
+
gl.disableVertexAttribArray(loc);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
const bindTarget = (target) => {
|
|
663
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, target?.framebuffer ?? null);
|
|
664
|
+
gl.viewport(0, 0, canvas.width, canvas.height);
|
|
665
|
+
gl.clearColor(0, 0, 0, 0);
|
|
666
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
667
|
+
};
|
|
668
|
+
const drawQuad = (program) => {
|
|
669
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
670
|
+
const enabled = bindAttribs(gl, program, [["a_pos", 2]]);
|
|
671
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
672
|
+
disable(enabled);
|
|
673
|
+
};
|
|
674
|
+
const bindTexture = (program, name, unit, target) => {
|
|
675
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
676
|
+
gl.bindTexture(gl.TEXTURE_2D, target.texture);
|
|
677
|
+
gl.uniform1i(program.uniform(name), unit);
|
|
678
|
+
};
|
|
679
|
+
const drawStroke = (target, frame, s, radius, heatMix) => {
|
|
680
|
+
bindTarget(target);
|
|
681
|
+
gl.enable(gl.BLEND);
|
|
682
|
+
if (minmax) {
|
|
683
|
+
gl.blendEquation(minmax.MAX_EXT);
|
|
684
|
+
gl.blendFunc(gl.ONE, gl.ONE);
|
|
685
|
+
} else {
|
|
686
|
+
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
687
|
+
}
|
|
688
|
+
gl.useProgram(stroke.program);
|
|
689
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, narrowBuffer);
|
|
690
|
+
const enabled = bindAttribs(gl, stroke, RIBBON_LAYOUT);
|
|
691
|
+
const u = stroke.uniform;
|
|
692
|
+
gl.uniform2f(u("u_res"), cssWidth, cssHeight);
|
|
693
|
+
gl.uniform1f(u("u_front"), frame.front);
|
|
694
|
+
gl.uniform1f(u("u_total"), frame.total);
|
|
695
|
+
gl.uniform1f(u("u_trail"), s.trail);
|
|
696
|
+
gl.uniform1f(u("u_heat"), frame.heat * s.effect.heatGain);
|
|
697
|
+
gl.uniform1f(u("u_heatMix"), heatMix);
|
|
698
|
+
gl.uniform1f(u("u_radius"), radius);
|
|
699
|
+
gl.uniform1f(u("u_halfW"), s.narrowHalfWidth);
|
|
700
|
+
gl.uniform1f(u("u_dpr"), dpr);
|
|
701
|
+
gl.uniform1f(u("u_xStart"), frame.xStart);
|
|
702
|
+
gl.uniform1f(u("u_xSpan"), Math.max(frame.xSpan, 1));
|
|
703
|
+
usePalette(stroke);
|
|
704
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, narrowCount);
|
|
705
|
+
disable(enabled);
|
|
706
|
+
gl.blendEquation(gl.FUNC_ADD);
|
|
707
|
+
};
|
|
708
|
+
const drawBlur = (from, to, dx, dy) => {
|
|
709
|
+
bindTarget(to);
|
|
710
|
+
gl.disable(gl.BLEND);
|
|
711
|
+
gl.useProgram(blur.program);
|
|
712
|
+
bindTexture(blur, "u_tex", 0, from);
|
|
713
|
+
gl.uniform2f(blur.uniform("u_step"), dx / canvas.width, dy / canvas.height);
|
|
714
|
+
gl.uniform1f(blur.uniform("u_sigma"), Math.min(GLOW_BLUR * dpr, 16));
|
|
715
|
+
drawQuad(blur);
|
|
716
|
+
};
|
|
717
|
+
const drawComposite = (frame) => {
|
|
718
|
+
bindTarget(null);
|
|
719
|
+
gl.disable(gl.BLEND);
|
|
720
|
+
gl.useProgram(composite.program);
|
|
721
|
+
bindTexture(composite, "u_core", 0, coreTarget);
|
|
722
|
+
bindTexture(composite, "u_glow", 1, glowTarget);
|
|
723
|
+
const u = composite.uniform;
|
|
724
|
+
gl.uniform2f(u("u_res"), cssWidth, cssHeight);
|
|
725
|
+
gl.uniform1f(u("u_glowOpacity"), GLOW_OPACITY);
|
|
726
|
+
gl.uniform1f(u("u_hover"), frame.hover.amount);
|
|
727
|
+
gl.uniform2f(u("u_seg"), frame.hover.start, frame.hover.end);
|
|
728
|
+
gl.uniform1f(u("u_segFade"), frame.hover.fade);
|
|
729
|
+
gl.uniform1f(u("u_dim"), frame.hover.dim);
|
|
730
|
+
drawQuad(composite);
|
|
731
|
+
};
|
|
732
|
+
const drawBloom = (frame, s) => {
|
|
733
|
+
gl.enable(gl.BLEND);
|
|
734
|
+
gl.blendFunc(gl.ONE, gl.ONE);
|
|
735
|
+
gl.useProgram(bloom.program);
|
|
736
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, wideBuffer);
|
|
737
|
+
const enabled = bindAttribs(gl, bloom, RIBBON_LAYOUT);
|
|
738
|
+
const u = bloom.uniform;
|
|
739
|
+
gl.uniform2f(u("u_res"), cssWidth, cssHeight);
|
|
740
|
+
gl.uniform1f(u("u_front"), frame.front);
|
|
741
|
+
gl.uniform1f(u("u_total"), frame.total);
|
|
742
|
+
gl.uniform1f(u("u_trail"), s.trail);
|
|
743
|
+
gl.uniform1f(u("u_heat"), frame.heat * s.effect.heatGain);
|
|
744
|
+
gl.uniform1f(u("u_halfW"), s.halfWidth);
|
|
745
|
+
usePalette(bloom);
|
|
746
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, wideCount);
|
|
747
|
+
disable(enabled);
|
|
748
|
+
};
|
|
749
|
+
const drawParticles = (frame, s) => {
|
|
750
|
+
const fx = s.effect;
|
|
751
|
+
gl.enable(gl.BLEND);
|
|
752
|
+
gl.blendFunc(gl.ONE, gl.ONE);
|
|
753
|
+
gl.useProgram(particles.program);
|
|
754
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, particleBuffer);
|
|
755
|
+
const enabled = bindAttribs(gl, particles, [
|
|
756
|
+
["a_target", 2],
|
|
757
|
+
["a_s", 1],
|
|
758
|
+
["a_tan", 2],
|
|
759
|
+
["a_rand", 4],
|
|
760
|
+
["a_when", 1]
|
|
761
|
+
]);
|
|
762
|
+
const u = particles.uniform;
|
|
763
|
+
gl.uniform2f(u("u_res"), cssWidth, cssHeight);
|
|
764
|
+
gl.uniform1f(u("u_time"), frame.time);
|
|
765
|
+
gl.uniform1f(u("u_delay"), s.delay);
|
|
766
|
+
gl.uniform1f(u("u_duration"), s.duration);
|
|
767
|
+
gl.uniform1f(u("u_spread"), s.spread);
|
|
768
|
+
gl.uniform1f(u("u_dpr"), dpr);
|
|
769
|
+
gl.uniform1f(u("u_mode"), fx.mode);
|
|
770
|
+
gl.uniform2f(u("u_life"), fx.life[0], fx.life[1]);
|
|
771
|
+
gl.uniform2f(u("u_speed"), fx.speed[0], fx.speed[1]);
|
|
772
|
+
gl.uniform2f(u("u_size"), fx.size[0], fx.size[1]);
|
|
773
|
+
gl.uniform1f(u("u_backward"), fx.backward);
|
|
774
|
+
gl.uniform1f(u("u_gravity"), fx.gravity);
|
|
775
|
+
gl.uniform1f(u("u_drag"), fx.drag);
|
|
776
|
+
gl.uniform1f(u("u_twinkle"), fx.twinkle);
|
|
777
|
+
gl.uniform1f(u("u_cooling"), fx.cooling);
|
|
778
|
+
usePalette(particles);
|
|
779
|
+
gl.drawArrays(gl.POINTS, 0, particleCount);
|
|
780
|
+
disable(enabled);
|
|
781
|
+
};
|
|
782
|
+
const drawFlare = (frame, s) => {
|
|
783
|
+
headData[0] = frame.head[0];
|
|
784
|
+
headData[1] = frame.head[1];
|
|
785
|
+
gl.enable(gl.BLEND);
|
|
786
|
+
gl.blendFunc(gl.ONE, gl.ONE);
|
|
787
|
+
gl.useProgram(flare.program);
|
|
788
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, flareBuffer);
|
|
789
|
+
gl.bufferData(gl.ARRAY_BUFFER, headData, gl.DYNAMIC_DRAW);
|
|
790
|
+
const enabled = bindAttribs(gl, flare, [["a_pos", 2]]);
|
|
791
|
+
gl.uniform2f(flare.uniform("u_res"), cssWidth, cssHeight);
|
|
792
|
+
gl.uniform1f(flare.uniform("u_size"), s.effect.flare);
|
|
793
|
+
gl.uniform1f(flare.uniform("u_dpr"), dpr);
|
|
794
|
+
gl.uniform1f(flare.uniform("u_alpha"), frame.flareAlpha);
|
|
795
|
+
gl.uniform1f(flare.uniform("u_time"), frame.time);
|
|
796
|
+
gl.uniform1f(
|
|
797
|
+
flare.uniform("u_tint"),
|
|
798
|
+
frame.total > 0 ? frame.front / frame.total : 0
|
|
799
|
+
);
|
|
800
|
+
usePalette(flare);
|
|
801
|
+
gl.drawArrays(gl.POINTS, 0, 1);
|
|
802
|
+
disable(enabled);
|
|
803
|
+
};
|
|
804
|
+
return {
|
|
805
|
+
setSize: (width, height, ratio) => {
|
|
806
|
+
cssWidth = width;
|
|
807
|
+
cssHeight = height;
|
|
808
|
+
dpr = ratio;
|
|
809
|
+
canvas.width = Math.max(1, Math.round(width * ratio));
|
|
810
|
+
canvas.height = Math.max(1, Math.round(height * ratio));
|
|
811
|
+
for (const target of targets) {
|
|
812
|
+
gl.bindTexture(gl.TEXTURE_2D, target.texture);
|
|
813
|
+
gl.texImage2D(
|
|
814
|
+
gl.TEXTURE_2D,
|
|
815
|
+
0,
|
|
816
|
+
gl.RGBA,
|
|
817
|
+
canvas.width,
|
|
818
|
+
canvas.height,
|
|
819
|
+
0,
|
|
820
|
+
gl.RGBA,
|
|
821
|
+
gl.UNSIGNED_BYTE,
|
|
822
|
+
null
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
setGeometry: (narrowData, wideData, particleData) => {
|
|
827
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, narrowBuffer);
|
|
828
|
+
gl.bufferData(gl.ARRAY_BUFFER, narrowData, gl.STATIC_DRAW);
|
|
829
|
+
narrowCount = narrowData.length / RIBBON_STRIDE;
|
|
830
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, wideBuffer);
|
|
831
|
+
gl.bufferData(gl.ARRAY_BUFFER, wideData, gl.STATIC_DRAW);
|
|
832
|
+
wideCount = wideData.length / RIBBON_STRIDE;
|
|
833
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, particleBuffer);
|
|
834
|
+
gl.bufferData(gl.ARRAY_BUFFER, particleData, gl.STATIC_DRAW);
|
|
835
|
+
particleCount = particleData.length / PARTICLE_STRIDE;
|
|
836
|
+
},
|
|
837
|
+
setColors: (colors, darkSurface) => {
|
|
838
|
+
palette = [0, 1, 2, 3].map(
|
|
839
|
+
(i) => hexToRgb(colors[i % Math.max(colors.length, 1)] ?? "#ffffff")
|
|
840
|
+
);
|
|
841
|
+
hot = darkSurface ? HOT_ON_DARK : palette[0] ?? HOT_ON_DARK;
|
|
842
|
+
},
|
|
843
|
+
draw: (frame) => {
|
|
844
|
+
const s = settings.current;
|
|
845
|
+
drawStroke(coreTarget, frame, s, s.strokeWidth / 2, 1);
|
|
846
|
+
drawStroke(
|
|
847
|
+
glowTarget,
|
|
848
|
+
frame,
|
|
849
|
+
s,
|
|
850
|
+
s.strokeWidth * GLOW_WIDTH_SCALE / 2,
|
|
851
|
+
0
|
|
852
|
+
);
|
|
853
|
+
drawBlur(glowTarget, scratchTarget, 1, 0);
|
|
854
|
+
drawBlur(scratchTarget, glowTarget, 0, 1);
|
|
855
|
+
drawComposite(frame);
|
|
856
|
+
if (frame.heat > 0) {
|
|
857
|
+
drawBloom(frame, s);
|
|
858
|
+
}
|
|
859
|
+
if (frame.time < s.delay + s.duration + s.effect.life[1]) {
|
|
860
|
+
drawParticles(frame, s);
|
|
861
|
+
}
|
|
862
|
+
if (s.effect.flare > 0 && frame.flareAlpha > 0) {
|
|
863
|
+
drawFlare(frame, s);
|
|
864
|
+
}
|
|
865
|
+
},
|
|
866
|
+
dispose: () => {
|
|
867
|
+
for (const buffer of [
|
|
868
|
+
narrowBuffer,
|
|
869
|
+
wideBuffer,
|
|
870
|
+
quadBuffer,
|
|
871
|
+
particleBuffer,
|
|
872
|
+
flareBuffer
|
|
873
|
+
]) {
|
|
874
|
+
gl.deleteBuffer(buffer);
|
|
875
|
+
}
|
|
876
|
+
for (const target of targets) {
|
|
877
|
+
gl.deleteFramebuffer(target.framebuffer);
|
|
878
|
+
gl.deleteTexture(target.texture);
|
|
879
|
+
}
|
|
880
|
+
for (const program of [
|
|
881
|
+
stroke,
|
|
882
|
+
bloom,
|
|
883
|
+
blur,
|
|
884
|
+
composite,
|
|
885
|
+
particles,
|
|
886
|
+
flare
|
|
887
|
+
]) {
|
|
888
|
+
gl.deleteProgram(program.program);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
function isDarkSurface(element) {
|
|
894
|
+
const match = getComputedStyle(element).color.match(/[\d.]+/g);
|
|
895
|
+
if (!match || match.length < 3) {
|
|
896
|
+
return true;
|
|
897
|
+
}
|
|
898
|
+
const [r = 0, g = 0, b = 0] = match.map(Number);
|
|
899
|
+
return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255 > 0.5;
|
|
900
|
+
}
|
|
901
|
+
function prefersReducedMotion() {
|
|
902
|
+
return typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
|
|
903
|
+
}
|
|
904
|
+
const GLOW_FILTER_BLEED = 40;
|
|
905
|
+
function ParticleLineGlow({
|
|
906
|
+
d,
|
|
907
|
+
filter,
|
|
908
|
+
stroke,
|
|
909
|
+
strokeWidth
|
|
910
|
+
}) {
|
|
911
|
+
const hovering = useChartHoverSelector(selectIsChartHovering);
|
|
912
|
+
return /* @__PURE__ */ jsx(
|
|
913
|
+
m.path,
|
|
914
|
+
{
|
|
915
|
+
animate: { opacity: hovering ? 0 : 1 },
|
|
916
|
+
d,
|
|
917
|
+
fill: "none",
|
|
918
|
+
filter,
|
|
919
|
+
initial: false,
|
|
920
|
+
stroke,
|
|
921
|
+
strokeLinecap: "round",
|
|
922
|
+
strokeLinejoin: "round",
|
|
923
|
+
strokeOpacity: GLOW_OPACITY,
|
|
924
|
+
strokeWidth,
|
|
925
|
+
transition: { duration: 0.4, ease: "easeInOut" }
|
|
926
|
+
}
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
const pendingContextRelease = /* @__PURE__ */ new WeakMap();
|
|
930
|
+
function scheduleContextRelease(canvas) {
|
|
931
|
+
const timer = window.setTimeout(() => {
|
|
932
|
+
pendingContextRelease.delete(canvas);
|
|
933
|
+
canvas.getContext("webgl")?.getExtension("WEBGL_lose_context")?.loseContext();
|
|
934
|
+
}, 0);
|
|
935
|
+
pendingContextRelease.set(canvas, timer);
|
|
936
|
+
}
|
|
937
|
+
function cancelContextRelease(canvas) {
|
|
938
|
+
const timer = pendingContextRelease.get(canvas);
|
|
939
|
+
if (timer !== void 0) {
|
|
940
|
+
window.clearTimeout(timer);
|
|
941
|
+
pendingContextRelease.delete(canvas);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
function ParticleLine({
|
|
945
|
+
dataKey,
|
|
946
|
+
yAxisId,
|
|
947
|
+
curve = curveMonotoneX,
|
|
948
|
+
strokeWidth = 2.5,
|
|
949
|
+
colors = PARTICLE_LINE_GOLD,
|
|
950
|
+
effect = "assemble",
|
|
951
|
+
duration: durationProp,
|
|
952
|
+
delay = 0,
|
|
953
|
+
easing,
|
|
954
|
+
density = 7,
|
|
955
|
+
spread = 150,
|
|
956
|
+
trail = 90,
|
|
957
|
+
highlight
|
|
958
|
+
}) {
|
|
959
|
+
const {
|
|
960
|
+
renderData,
|
|
961
|
+
xScale,
|
|
962
|
+
xAccessor,
|
|
963
|
+
width,
|
|
964
|
+
height,
|
|
965
|
+
innerWidth,
|
|
966
|
+
innerHeight,
|
|
967
|
+
lines,
|
|
968
|
+
margin,
|
|
969
|
+
containerRef,
|
|
970
|
+
revealEpoch,
|
|
971
|
+
animationDuration,
|
|
972
|
+
animationEasing,
|
|
973
|
+
enterTransition
|
|
974
|
+
} = useChartStable();
|
|
975
|
+
const yScale = useYScale(yAxisId);
|
|
976
|
+
const container = useChartPortalContainer(containerRef);
|
|
977
|
+
const pathRef = useRef(null);
|
|
978
|
+
const canvasRef = useRef(null);
|
|
979
|
+
const rendererRef = useRef(null);
|
|
980
|
+
const samplesRef = useRef(null);
|
|
981
|
+
const startRef = useRef(null);
|
|
982
|
+
const [canvasReady, setCanvasReady] = useState(false);
|
|
983
|
+
const [phase, setPhase] = useState("webgl");
|
|
984
|
+
const uniqueId = useId().replace(/:/g, "");
|
|
985
|
+
const gradientId = `particle-line-${uniqueId}`;
|
|
986
|
+
const glowFilterId = `${gradientId}-glow`;
|
|
987
|
+
const svgPathRef = useRef(null);
|
|
988
|
+
const preset = EFFECTS[effect];
|
|
989
|
+
const duration = durationProp ?? animationDuration;
|
|
990
|
+
const chartEase = resolveChartEase(enterTransition?.ease, animationEasing);
|
|
991
|
+
const ease = easing ?? chartEase;
|
|
992
|
+
const easeKey = ease.join(",");
|
|
993
|
+
const halfWidth = strokeWidth * GLOW_WIDTH_SCALE / 2 + RIBBON_PAD;
|
|
994
|
+
const narrowHalfWidth = strokeWidth * GLOW_WIDTH_SCALE / 2 + 1.5;
|
|
995
|
+
const settings = {
|
|
996
|
+
delay: delay / 1e3,
|
|
997
|
+
duration: duration / 1e3,
|
|
998
|
+
spread,
|
|
999
|
+
trail,
|
|
1000
|
+
strokeWidth,
|
|
1001
|
+
halfWidth,
|
|
1002
|
+
narrowHalfWidth,
|
|
1003
|
+
effect: preset,
|
|
1004
|
+
ease
|
|
1005
|
+
};
|
|
1006
|
+
const settingsRef = useRef(settings);
|
|
1007
|
+
settingsRef.current = settings;
|
|
1008
|
+
const stopAt = settings.delay + settings.duration + preset.life[1] + HEAT_FADE_S;
|
|
1009
|
+
const highlightEnabled = highlight !== false;
|
|
1010
|
+
const span = (highlight || void 0)?.span ?? 3;
|
|
1011
|
+
const fadeLength = Math.min(
|
|
1012
|
+
50,
|
|
1013
|
+
Math.max(0, (highlight || void 0)?.fadeLength ?? 40)
|
|
1014
|
+
);
|
|
1015
|
+
const dimOpacity = (highlight || void 0)?.dimOpacity ?? 0.25;
|
|
1016
|
+
const {
|
|
1017
|
+
xSpring: segmentX,
|
|
1018
|
+
widthSpring: segmentWidth,
|
|
1019
|
+
isActive: hoverActive
|
|
1020
|
+
} = useHighlightSegment({ enabled: highlightEnabled, span });
|
|
1021
|
+
const hoverAmount = useMotionValue(0);
|
|
1022
|
+
useEffect(() => {
|
|
1023
|
+
const controls = animate(hoverAmount, hoverActive ? 1 : 0, {
|
|
1024
|
+
duration: 0.4,
|
|
1025
|
+
ease: "easeInOut"
|
|
1026
|
+
});
|
|
1027
|
+
return () => controls.stop();
|
|
1028
|
+
}, [hoverActive, hoverAmount]);
|
|
1029
|
+
const hoverRef = useRef({ fadeLength, dimOpacity, marginLeft: margin.left });
|
|
1030
|
+
hoverRef.current = { fadeLength, dimOpacity, marginLeft: margin.left };
|
|
1031
|
+
const animatingRef = useRef(false);
|
|
1032
|
+
const getX = useCallback(
|
|
1033
|
+
(d) => xScale(xAccessor(d)) ?? 0,
|
|
1034
|
+
[xAccessor, xScale]
|
|
1035
|
+
);
|
|
1036
|
+
const getY = useCallback(
|
|
1037
|
+
(d) => yScale(Number(d[dataKey])) ?? 0,
|
|
1038
|
+
[dataKey, yScale]
|
|
1039
|
+
);
|
|
1040
|
+
const defined = useCallback(
|
|
1041
|
+
(d) => typeof d[dataKey] === "number",
|
|
1042
|
+
[dataKey]
|
|
1043
|
+
);
|
|
1044
|
+
const lineD = useMemo(
|
|
1045
|
+
() => linePathD(renderData, { curve, defined, x: getX, y: getY }),
|
|
1046
|
+
[curve, defined, getX, getY, renderData]
|
|
1047
|
+
);
|
|
1048
|
+
const readHover = useCallback(() => {
|
|
1049
|
+
const {
|
|
1050
|
+
fadeLength: fadePct,
|
|
1051
|
+
dimOpacity: dim,
|
|
1052
|
+
marginLeft
|
|
1053
|
+
} = hoverRef.current;
|
|
1054
|
+
const start = segmentX.get() + marginLeft;
|
|
1055
|
+
const width2 = segmentWidth.get();
|
|
1056
|
+
return {
|
|
1057
|
+
amount: hoverAmount.get(),
|
|
1058
|
+
start,
|
|
1059
|
+
end: start + width2,
|
|
1060
|
+
fade: Math.max(width2 * fadePct / 100, 0.5),
|
|
1061
|
+
dim
|
|
1062
|
+
};
|
|
1063
|
+
}, [hoverAmount, segmentWidth, segmentX]);
|
|
1064
|
+
const drawAt = useCallback(
|
|
1065
|
+
(time) => {
|
|
1066
|
+
const renderer = rendererRef.current;
|
|
1067
|
+
const samples = samplesRef.current;
|
|
1068
|
+
if (!(renderer && samples)) {
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
const s = settingsRef.current;
|
|
1072
|
+
const linear = Math.min(Math.max((time - s.delay) / s.duration, 0), 1);
|
|
1073
|
+
const progress = easeAt(s.ease, linear);
|
|
1074
|
+
const front = progress >= 1 ? samples.total : lengthAtXFraction(samples, progress);
|
|
1075
|
+
const pastEnd = time - (s.delay + s.duration);
|
|
1076
|
+
const cooldown = pastEnd > 0 ? Math.max(0, 1 - pastEnd / HEAT_FADE_S) : 1;
|
|
1077
|
+
let flareAlpha = 0;
|
|
1078
|
+
if (time >= s.delay) {
|
|
1079
|
+
flareAlpha = Math.min(1, (time - s.delay) / 0.15) * cooldown ** 2;
|
|
1080
|
+
}
|
|
1081
|
+
renderer.draw({
|
|
1082
|
+
time,
|
|
1083
|
+
total: samples.total,
|
|
1084
|
+
// Nothing (not even the start cap) before the reveal begins.
|
|
1085
|
+
front: progress > 0 ? front : -1e4,
|
|
1086
|
+
heat: cooldown,
|
|
1087
|
+
head: pointAt(samples, front),
|
|
1088
|
+
flareAlpha,
|
|
1089
|
+
hover: readHover(),
|
|
1090
|
+
xStart: samples.xStart,
|
|
1091
|
+
xSpan: samples.xEnd - samples.xStart
|
|
1092
|
+
});
|
|
1093
|
+
},
|
|
1094
|
+
[readHover]
|
|
1095
|
+
);
|
|
1096
|
+
const currentTime = useCallback(() => {
|
|
1097
|
+
if (startRef.current === null) {
|
|
1098
|
+
return 0;
|
|
1099
|
+
}
|
|
1100
|
+
return (performance.now() - startRef.current) / 1e3;
|
|
1101
|
+
}, []);
|
|
1102
|
+
useEffect(() => {
|
|
1103
|
+
const canvas = canvasRef.current;
|
|
1104
|
+
if (!(canvas && container)) {
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
cancelContextRelease(canvas);
|
|
1108
|
+
const renderer = createRenderer(canvas, settingsRef);
|
|
1109
|
+
rendererRef.current = renderer;
|
|
1110
|
+
setCanvasReady(renderer !== null);
|
|
1111
|
+
return () => {
|
|
1112
|
+
renderer?.dispose();
|
|
1113
|
+
rendererRef.current = null;
|
|
1114
|
+
setCanvasReady(false);
|
|
1115
|
+
scheduleContextRelease(canvas);
|
|
1116
|
+
};
|
|
1117
|
+
}, [container, phase]);
|
|
1118
|
+
const colorKey = colors.join(",");
|
|
1119
|
+
useLayoutEffect(() => {
|
|
1120
|
+
const renderer = rendererRef.current;
|
|
1121
|
+
const path = pathRef.current;
|
|
1122
|
+
if (!(canvasReady && renderer && path && lineD)) {
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
renderer.setSize(
|
|
1126
|
+
width,
|
|
1127
|
+
height,
|
|
1128
|
+
Math.min(window.devicePixelRatio || 1, MAX_DPR)
|
|
1129
|
+
);
|
|
1130
|
+
renderer.setColors(
|
|
1131
|
+
colorKey.split(","),
|
|
1132
|
+
isDarkSurface(container ?? path.ownerDocument.body)
|
|
1133
|
+
);
|
|
1134
|
+
const samples = sampleLine(path, margin.left, margin.top, innerWidth);
|
|
1135
|
+
samplesRef.current = samples;
|
|
1136
|
+
if (!samples) {
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
renderer.setGeometry(
|
|
1140
|
+
buildRibbon(samples, narrowHalfWidth),
|
|
1141
|
+
buildRibbon(samples, halfWidth),
|
|
1142
|
+
buildParticles(
|
|
1143
|
+
samples,
|
|
1144
|
+
density,
|
|
1145
|
+
strokeWidth,
|
|
1146
|
+
(progress) => timeAtProgress(settingsRef.current.ease, progress)
|
|
1147
|
+
)
|
|
1148
|
+
);
|
|
1149
|
+
drawAt(Math.min(currentTime(), stopAt));
|
|
1150
|
+
}, [
|
|
1151
|
+
canvasReady,
|
|
1152
|
+
colorKey,
|
|
1153
|
+
container,
|
|
1154
|
+
currentTime,
|
|
1155
|
+
density,
|
|
1156
|
+
easeKey,
|
|
1157
|
+
drawAt,
|
|
1158
|
+
halfWidth,
|
|
1159
|
+
narrowHalfWidth,
|
|
1160
|
+
height,
|
|
1161
|
+
innerWidth,
|
|
1162
|
+
lineD,
|
|
1163
|
+
margin.left,
|
|
1164
|
+
margin.top,
|
|
1165
|
+
stopAt,
|
|
1166
|
+
strokeWidth,
|
|
1167
|
+
width
|
|
1168
|
+
]);
|
|
1169
|
+
useEffect(() => {
|
|
1170
|
+
if (!canvasReady) {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
if (prefersReducedMotion()) {
|
|
1174
|
+
startRef.current = Number.NEGATIVE_INFINITY;
|
|
1175
|
+
setPhase("svg");
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
startRef.current = performance.now();
|
|
1179
|
+
animatingRef.current = true;
|
|
1180
|
+
let frame = 0;
|
|
1181
|
+
const tick = () => {
|
|
1182
|
+
const time = currentTime();
|
|
1183
|
+
drawAt(Math.min(time, stopAt));
|
|
1184
|
+
if (time < stopAt) {
|
|
1185
|
+
frame = requestAnimationFrame(tick);
|
|
1186
|
+
} else {
|
|
1187
|
+
animatingRef.current = false;
|
|
1188
|
+
setPhase("svg");
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
frame = requestAnimationFrame(tick);
|
|
1192
|
+
return () => {
|
|
1193
|
+
cancelAnimationFrame(frame);
|
|
1194
|
+
animatingRef.current = false;
|
|
1195
|
+
};
|
|
1196
|
+
}, [canvasReady, currentTime, drawAt, effect, revealEpoch, stopAt]);
|
|
1197
|
+
const lastEpochRef = useRef(revealEpoch);
|
|
1198
|
+
useEffect(() => {
|
|
1199
|
+
if (lastEpochRef.current === revealEpoch) {
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
lastEpochRef.current = revealEpoch;
|
|
1203
|
+
setPhase("webgl");
|
|
1204
|
+
}, [revealEpoch]);
|
|
1205
|
+
useEffect(() => {
|
|
1206
|
+
if (!canvasReady) {
|
|
1207
|
+
return;
|
|
1208
|
+
}
|
|
1209
|
+
let frame = 0;
|
|
1210
|
+
const request = () => {
|
|
1211
|
+
if (animatingRef.current || frame) {
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
frame = requestAnimationFrame(() => {
|
|
1215
|
+
frame = 0;
|
|
1216
|
+
drawAt(Math.min(currentTime(), stopAt));
|
|
1217
|
+
});
|
|
1218
|
+
};
|
|
1219
|
+
const unsubscribe = [segmentX, segmentWidth, hoverAmount].map(
|
|
1220
|
+
(value) => value.on("change", request)
|
|
1221
|
+
);
|
|
1222
|
+
return () => {
|
|
1223
|
+
cancelAnimationFrame(frame);
|
|
1224
|
+
for (const off of unsubscribe) {
|
|
1225
|
+
off();
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
}, [
|
|
1229
|
+
canvasReady,
|
|
1230
|
+
currentTime,
|
|
1231
|
+
drawAt,
|
|
1232
|
+
hoverAmount,
|
|
1233
|
+
segmentWidth,
|
|
1234
|
+
segmentX,
|
|
1235
|
+
stopAt
|
|
1236
|
+
]);
|
|
1237
|
+
const palette = [0, 1, 2, 3].map(
|
|
1238
|
+
(i) => colors[i % Math.max(colors.length, 1)] ?? "#ffffff"
|
|
1239
|
+
);
|
|
1240
|
+
const seriesIndex = Math.max(
|
|
1241
|
+
0,
|
|
1242
|
+
lines.findIndex((line) => line.dataKey === dataKey)
|
|
1243
|
+
);
|
|
1244
|
+
const glowWidth = strokeWidth * GLOW_WIDTH_SCALE;
|
|
1245
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1246
|
+
/* @__PURE__ */ jsx("path", { d: lineD, fill: "none", ref: pathRef, stroke: "none" }),
|
|
1247
|
+
phase === "svg" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1248
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
1249
|
+
/* @__PURE__ */ jsx(
|
|
1250
|
+
"linearGradient",
|
|
1251
|
+
{
|
|
1252
|
+
gradientUnits: "userSpaceOnUse",
|
|
1253
|
+
id: gradientId,
|
|
1254
|
+
x1: 0,
|
|
1255
|
+
x2: Math.max(innerWidth, 1),
|
|
1256
|
+
y1: 0,
|
|
1257
|
+
y2: 0,
|
|
1258
|
+
children: palette.map((color, i) => /* @__PURE__ */ jsx("stop", { offset: i / 3, stopColor: color }, `${i}-${color}`))
|
|
1259
|
+
}
|
|
1260
|
+
),
|
|
1261
|
+
/* @__PURE__ */ jsx(
|
|
1262
|
+
"filter",
|
|
1263
|
+
{
|
|
1264
|
+
colorInterpolationFilters: "sRGB",
|
|
1265
|
+
filterUnits: "userSpaceOnUse",
|
|
1266
|
+
height: innerHeight + GLOW_FILTER_BLEED * 2,
|
|
1267
|
+
id: glowFilterId,
|
|
1268
|
+
width: innerWidth + GLOW_FILTER_BLEED * 2,
|
|
1269
|
+
x: -GLOW_FILTER_BLEED,
|
|
1270
|
+
y: -GLOW_FILTER_BLEED,
|
|
1271
|
+
children: /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: GLOW_BLUR })
|
|
1272
|
+
}
|
|
1273
|
+
)
|
|
1274
|
+
] }),
|
|
1275
|
+
/* @__PURE__ */ jsxs(
|
|
1276
|
+
SeriesHoverDim,
|
|
1277
|
+
{
|
|
1278
|
+
dimOpacity,
|
|
1279
|
+
enabled: highlightEnabled,
|
|
1280
|
+
seriesIndex,
|
|
1281
|
+
children: [
|
|
1282
|
+
/* @__PURE__ */ jsx(
|
|
1283
|
+
ParticleLineGlow,
|
|
1284
|
+
{
|
|
1285
|
+
d: lineD,
|
|
1286
|
+
filter: `url(#${glowFilterId})`,
|
|
1287
|
+
stroke: `url(#${gradientId})`,
|
|
1288
|
+
strokeWidth: glowWidth
|
|
1289
|
+
}
|
|
1290
|
+
),
|
|
1291
|
+
/* @__PURE__ */ jsx(
|
|
1292
|
+
"path",
|
|
1293
|
+
{
|
|
1294
|
+
d: lineD,
|
|
1295
|
+
fill: "none",
|
|
1296
|
+
ref: svgPathRef,
|
|
1297
|
+
stroke: `url(#${gradientId})`,
|
|
1298
|
+
strokeLinecap: "round",
|
|
1299
|
+
strokeLinejoin: "round",
|
|
1300
|
+
strokeWidth
|
|
1301
|
+
}
|
|
1302
|
+
)
|
|
1303
|
+
]
|
|
1304
|
+
}
|
|
1305
|
+
),
|
|
1306
|
+
/* @__PURE__ */ jsx(
|
|
1307
|
+
HighlightSegment,
|
|
1308
|
+
{
|
|
1309
|
+
fadeLength,
|
|
1310
|
+
height: innerHeight,
|
|
1311
|
+
pathRef: svgPathRef,
|
|
1312
|
+
stroke: `url(#${gradientId})`,
|
|
1313
|
+
strokeWidth,
|
|
1314
|
+
visible: highlightEnabled && hoverActive,
|
|
1315
|
+
width: segmentWidth,
|
|
1316
|
+
x: segmentX
|
|
1317
|
+
}
|
|
1318
|
+
)
|
|
1319
|
+
] }) : null,
|
|
1320
|
+
container && phase === "webgl" ? createPortal(
|
|
1321
|
+
/* @__PURE__ */ jsx(
|
|
1322
|
+
"canvas",
|
|
1323
|
+
{
|
|
1324
|
+
"aria-hidden": true,
|
|
1325
|
+
className: "pointer-events-none absolute top-0 left-0",
|
|
1326
|
+
ref: canvasRef,
|
|
1327
|
+
style: { width, height }
|
|
1328
|
+
}
|
|
1329
|
+
),
|
|
1330
|
+
container
|
|
1331
|
+
) : null
|
|
1332
|
+
] });
|
|
1333
|
+
}
|
|
1334
|
+
ParticleLine.displayName = "ParticleLine";
|
|
1335
|
+
var particle_line_default = ParticleLine;
|
|
1336
|
+
export {
|
|
1337
|
+
PARTICLE_LINE_GOLD,
|
|
1338
|
+
ParticleLine,
|
|
1339
|
+
particle_line_default as default
|
|
1340
|
+
};
|