@fuzdev/fuz_ui 0.206.8 → 0.207.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/DeclarationDetail.svelte +55 -20
  2. package/dist/DeclarationDetail.svelte.d.ts +1 -1
  3. package/dist/DeclarationDetail.svelte.d.ts.map +1 -1
  4. package/dist/ProjectActivityChart.svelte +137 -0
  5. package/dist/ProjectActivityChart.svelte.d.ts +30 -0
  6. package/dist/ProjectActivityChart.svelte.d.ts.map +1 -0
  7. package/dist/ProjectLinks.svelte +31 -46
  8. package/dist/ProjectLinks.svelte.d.ts.map +1 -1
  9. package/dist/Sparkline.svelte +131 -0
  10. package/dist/Sparkline.svelte.d.ts +42 -0
  11. package/dist/Sparkline.svelte.d.ts.map +1 -0
  12. package/dist/TypeJsonView.svelte +90 -0
  13. package/dist/TypeJsonView.svelte.d.ts +26 -0
  14. package/dist/TypeJsonView.svelte.d.ts.map +1 -0
  15. package/dist/TypeLink.svelte +17 -1
  16. package/dist/TypeLink.svelte.d.ts +10 -0
  17. package/dist/TypeLink.svelte.d.ts.map +1 -1
  18. package/dist/declaration.svelte.d.ts +25 -5
  19. package/dist/declaration.svelte.d.ts.map +1 -1
  20. package/dist/declaration.svelte.js +31 -5
  21. package/dist/project_stats.d.ts +121 -0
  22. package/dist/project_stats.d.ts.map +1 -0
  23. package/dist/project_stats.js +153 -0
  24. package/dist/project_stats_data.d.ts +3 -0
  25. package/dist/project_stats_data.d.ts.map +1 -0
  26. package/dist/project_stats_data.js +469 -0
  27. package/dist/project_stats_update.task.d.ts +4 -0
  28. package/dist/project_stats_update.task.d.ts.map +1 -0
  29. package/dist/project_stats_update.task.js +50 -0
  30. package/dist/projects.d.ts +17 -0
  31. package/dist/projects.d.ts.map +1 -0
  32. package/dist/projects.js +20 -0
  33. package/dist/publish.task.d.ts +3 -0
  34. package/dist/publish.task.d.ts.map +1 -0
  35. package/dist/publish.task.js +23 -0
  36. package/dist/sparkline.d.ts +102 -0
  37. package/dist/sparkline.d.ts.map +1 -0
  38. package/dist/sparkline.js +63 -0
  39. package/package.json +2 -2
  40. package/src/lib/declaration.svelte.ts +37 -7
  41. package/src/lib/project_stats.ts +220 -0
  42. package/src/lib/project_stats_data.ts +472 -0
  43. package/src/lib/project_stats_update.task.ts +53 -0
  44. package/src/lib/projects.ts +49 -0
  45. package/src/lib/publish.task.ts +22 -0
  46. package/src/lib/sparkline.ts +173 -0
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Pure geometry helpers behind `Sparkline` and `ProjectActivityChart`.
3
+ *
4
+ * Computes polyline points, alpha-fade gradient stops, and the end-dot
5
+ * position for a series of values, so components stay thin and the math is
6
+ * testable and reusable outside Svelte.
7
+ *
8
+ * @module
9
+ */
10
+
11
+ /**
12
+ * Vertical scale for a sparkline's geometry. The nonlinear options compress
13
+ * the top of the range so small values stay legible under a large shared
14
+ * max — increasingly so from `'sqrt'` to smaller power exponents (a number
15
+ * in `(0, 1]`, where `1` is linear and `1 / 3` is cube root) to `'log'`.
16
+ */
17
+ export type SparklineScale = 'linear' | 'sqrt' | 'log' | number;
18
+
19
+ export interface SparklineOptions {
20
+ /**
21
+ * Width of the drawing area in px.
22
+ */
23
+ width: number;
24
+ /**
25
+ * Height of the drawing area in px.
26
+ */
27
+ height: number;
28
+ /**
29
+ * The value rendered at full height and full alpha.
30
+ * Pass a shared max across sparklines for comparable scales.
31
+ * Defaults to the local max of the values.
32
+ */
33
+ max?: number;
34
+ /**
35
+ * Vertical scale for the line's geometry. The alpha fade always tracks
36
+ * the linear ratio regardless of `scale`.
37
+ *
38
+ * @default 'linear'
39
+ */
40
+ scale?: SparklineScale;
41
+ /**
42
+ * @default 2
43
+ */
44
+ stroke_width?: number;
45
+ /**
46
+ * Alpha at a value of 0, scaling linearly to 1 at the max.
47
+ *
48
+ * @default 0.4
49
+ */
50
+ alpha_floor?: number;
51
+ /**
52
+ * Reserve padding for an end dot of radius `stroke_width` at the final point.
53
+ *
54
+ * @default false
55
+ */
56
+ end_dot?: boolean;
57
+ }
58
+
59
+ /**
60
+ * A gradient stop for the per-point alpha fade.
61
+ */
62
+ export interface SparklineStop {
63
+ /**
64
+ * Gradient offset in `[0, 1]`.
65
+ */
66
+ offset: number;
67
+ /**
68
+ * Stop opacity in `[alpha_floor, 1]`.
69
+ */
70
+ opacity: number;
71
+ }
72
+
73
+ export interface SparklineGeometry {
74
+ /**
75
+ * SVG polyline `points` string.
76
+ */
77
+ points: string;
78
+ /**
79
+ * Alpha-fade gradient stops, thinned to runs' boundaries so long flat
80
+ * stretches (like all-zero history) cost a constant number of stops.
81
+ */
82
+ stops: Array<SparklineStop>;
83
+ /**
84
+ * X coordinate of the final point.
85
+ */
86
+ end_x: number;
87
+ /**
88
+ * Y coordinate of the final point.
89
+ */
90
+ end_y: number;
91
+ /**
92
+ * Alpha of the final point.
93
+ */
94
+ end_alpha: number;
95
+ /**
96
+ * Radius for an end dot, equal to the stroke width.
97
+ */
98
+ dot_radius: number;
99
+ }
100
+
101
+ const round = (n: number): number => Math.round(n * 100) / 100;
102
+
103
+ /**
104
+ * Computes the rendering geometry for a sparkline of `values`.
105
+ *
106
+ * Returns `null` when `values` has fewer than 2 points, which cannot form a line.
107
+ */
108
+ export const sparkline_geometry = (
109
+ values: Array<number>,
110
+ options: SparklineOptions
111
+ ): SparklineGeometry | null => {
112
+ if (values.length < 2) return null;
113
+ const {
114
+ width,
115
+ height,
116
+ max,
117
+ scale = 'linear',
118
+ stroke_width = 2,
119
+ alpha_floor = 0.4,
120
+ end_dot = false
121
+ } = options;
122
+ const local_max = max ?? Math.max(0, ...values);
123
+ const scale_max = local_max > 0 ? local_max : 1;
124
+ const dot_radius = stroke_width;
125
+ // inset by half the stroke (or the dot radius) so the extremes aren't clipped
126
+ const pad = end_dot ? Math.max(stroke_width / 2, dot_radius) : stroke_width / 2;
127
+ const x_coord = (index: number): number =>
128
+ pad + (index * (width - 2 * pad)) / (values.length - 1);
129
+ const y_coord = (value: number): number => {
130
+ const clamped = Math.min(value, scale_max);
131
+ const ratio = clamped / scale_max;
132
+ const scaled =
133
+ scale === 'linear'
134
+ ? ratio
135
+ : scale === 'sqrt'
136
+ ? Math.sqrt(ratio)
137
+ : scale === 'log'
138
+ ? Math.log1p(clamped) / Math.log1p(scale_max)
139
+ : ratio ** scale;
140
+ return height - pad - scaled * (height - 2 * pad);
141
+ };
142
+ const alpha = (value: number): number =>
143
+ alpha_floor + (1 - alpha_floor) * (Math.min(value, scale_max) / scale_max);
144
+
145
+ const points = values
146
+ .map((value, index) => `${round(x_coord(index))},${round(y_coord(value))}`)
147
+ .join(' ');
148
+
149
+ const opacities = values.map((value) => round(alpha(value)));
150
+ const stops: Array<SparklineStop> = [];
151
+ for (let i = 0; i < values.length; i++) {
152
+ const opacity = opacities[i]!;
153
+ // keep the first and last stops and each run's boundaries; drop run interiors
154
+ if (
155
+ i > 0 &&
156
+ i < values.length - 1 &&
157
+ opacity === opacities[i - 1] &&
158
+ opacity === opacities[i + 1]
159
+ ) {
160
+ continue;
161
+ }
162
+ stops.push({ offset: round(x_coord(i) / width), opacity });
163
+ }
164
+
165
+ return {
166
+ points,
167
+ stops,
168
+ end_x: round(x_coord(values.length - 1)),
169
+ end_y: round(y_coord(values[values.length - 1]!)),
170
+ end_alpha: opacities[values.length - 1]!,
171
+ dot_radius
172
+ };
173
+ };