panelui-native 0.22.6 → 0.25.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 (135) hide show
  1. package/README.md +1 -0
  2. package/lib/module/components/area-chart/index.js +826 -0
  3. package/lib/module/components/area-chart/index.js.map +1 -0
  4. package/lib/module/components/avatar/index.js +1 -1
  5. package/lib/module/components/avatar/index.js.map +1 -1
  6. package/lib/module/components/bar-chart/index.js +853 -0
  7. package/lib/module/components/bar-chart/index.js.map +1 -0
  8. package/lib/module/components/bottom-sheet/index.js +207 -23
  9. package/lib/module/components/bottom-sheet/index.js.map +1 -1
  10. package/lib/module/components/breadcrumb/index.js +275 -0
  11. package/lib/module/components/breadcrumb/index.js.map +1 -0
  12. package/lib/module/components/chip/index.js +2 -2
  13. package/lib/module/components/direction/index.js +13 -19
  14. package/lib/module/components/direction/index.js.map +1 -1
  15. package/lib/module/components/frame/index.js +17 -0
  16. package/lib/module/components/frame/index.js.map +1 -1
  17. package/lib/module/components/heatmap-chart/index.js +28 -8
  18. package/lib/module/components/heatmap-chart/index.js.map +1 -1
  19. package/lib/module/components/input-group/index.js +2 -2
  20. package/lib/module/components/input-group/index.js.map +1 -1
  21. package/lib/module/components/line-chart/index.js +4 -146
  22. package/lib/module/components/line-chart/index.js.map +1 -1
  23. package/lib/module/components/loader/index.js +758 -0
  24. package/lib/module/components/loader/index.js.map +1 -0
  25. package/lib/module/components/map/basemap.js +265 -0
  26. package/lib/module/components/map/basemap.js.map +1 -0
  27. package/lib/module/components/map/index.js +850 -0
  28. package/lib/module/components/map/index.js.map +1 -0
  29. package/lib/module/components/map/maplibre.js +87 -0
  30. package/lib/module/components/map/maplibre.js.map +1 -0
  31. package/lib/module/components/message/index.js +8 -7
  32. package/lib/module/components/message/index.js.map +1 -1
  33. package/lib/module/components/otp-input/index.js +2 -2
  34. package/lib/module/components/progress/index.js +8 -2
  35. package/lib/module/components/progress/index.js.map +1 -1
  36. package/lib/module/components/ring-chart/index.js +423 -0
  37. package/lib/module/components/ring-chart/index.js.map +1 -0
  38. package/lib/module/components/section-rail/index.js +2 -2
  39. package/lib/module/components/separator/index.js +76 -22
  40. package/lib/module/components/separator/index.js.map +1 -1
  41. package/lib/module/components/shimmer/index.js +10 -1
  42. package/lib/module/components/shimmer/index.js.map +1 -1
  43. package/lib/module/components/slider/index.js +19 -5
  44. package/lib/module/components/slider/index.js.map +1 -1
  45. package/lib/module/components/steps/index.js +1 -1
  46. package/lib/module/components/switch/index.js +6 -1
  47. package/lib/module/components/switch/index.js.map +1 -1
  48. package/lib/module/components/typography/index.js +5 -0
  49. package/lib/module/components/typography/index.js.map +1 -1
  50. package/lib/module/hooks/use-direction.js +43 -0
  51. package/lib/module/hooks/use-direction.js.map +1 -0
  52. package/lib/module/icons/index.js +117 -2
  53. package/lib/module/icons/index.js.map +1 -1
  54. package/lib/module/index.js +8 -2
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/primitives/text.js +30 -10
  57. package/lib/module/primitives/text.js.map +1 -1
  58. package/lib/module/utils/chart.js +279 -0
  59. package/lib/module/utils/chart.js.map +1 -0
  60. package/lib/typescript/src/components/area-chart/index.d.ts +197 -0
  61. package/lib/typescript/src/components/area-chart/index.d.ts.map +1 -0
  62. package/lib/typescript/src/components/bar-chart/index.d.ts +228 -0
  63. package/lib/typescript/src/components/bar-chart/index.d.ts.map +1 -0
  64. package/lib/typescript/src/components/bottom-sheet/index.d.ts +75 -4
  65. package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
  66. package/lib/typescript/src/components/breadcrumb/index.d.ts +100 -0
  67. package/lib/typescript/src/components/breadcrumb/index.d.ts.map +1 -0
  68. package/lib/typescript/src/components/direction/index.d.ts +11 -10
  69. package/lib/typescript/src/components/direction/index.d.ts.map +1 -1
  70. package/lib/typescript/src/components/frame/index.d.ts +17 -0
  71. package/lib/typescript/src/components/frame/index.d.ts.map +1 -1
  72. package/lib/typescript/src/components/heatmap-chart/index.d.ts +22 -3
  73. package/lib/typescript/src/components/heatmap-chart/index.d.ts.map +1 -1
  74. package/lib/typescript/src/components/line-chart/index.d.ts +1 -0
  75. package/lib/typescript/src/components/line-chart/index.d.ts.map +1 -1
  76. package/lib/typescript/src/components/loader/index.d.ts +38 -0
  77. package/lib/typescript/src/components/loader/index.d.ts.map +1 -0
  78. package/lib/typescript/src/components/map/basemap.d.ts +76 -0
  79. package/lib/typescript/src/components/map/basemap.d.ts.map +1 -0
  80. package/lib/typescript/src/components/map/index.d.ts +367 -0
  81. package/lib/typescript/src/components/map/index.d.ts.map +1 -0
  82. package/lib/typescript/src/components/map/maplibre.d.ts +193 -0
  83. package/lib/typescript/src/components/map/maplibre.d.ts.map +1 -0
  84. package/lib/typescript/src/components/message/index.d.ts.map +1 -1
  85. package/lib/typescript/src/components/progress/index.d.ts.map +1 -1
  86. package/lib/typescript/src/components/ring-chart/index.d.ts +156 -0
  87. package/lib/typescript/src/components/ring-chart/index.d.ts.map +1 -0
  88. package/lib/typescript/src/components/separator/index.d.ts +36 -1
  89. package/lib/typescript/src/components/separator/index.d.ts.map +1 -1
  90. package/lib/typescript/src/components/shimmer/index.d.ts.map +1 -1
  91. package/lib/typescript/src/components/slider/index.d.ts.map +1 -1
  92. package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
  93. package/lib/typescript/src/components/typography/index.d.ts +6 -0
  94. package/lib/typescript/src/components/typography/index.d.ts.map +1 -1
  95. package/lib/typescript/src/hooks/use-direction.d.ts +20 -0
  96. package/lib/typescript/src/hooks/use-direction.d.ts.map +1 -0
  97. package/lib/typescript/src/icons/index.d.ts +5 -0
  98. package/lib/typescript/src/icons/index.d.ts.map +1 -1
  99. package/lib/typescript/src/index.d.ts +9 -3
  100. package/lib/typescript/src/index.d.ts.map +1 -1
  101. package/lib/typescript/src/primitives/text.d.ts.map +1 -1
  102. package/lib/typescript/src/utils/chart.d.ts +96 -0
  103. package/lib/typescript/src/utils/chart.d.ts.map +1 -0
  104. package/package.json +9 -1
  105. package/src/components/area-chart/index.tsx +994 -0
  106. package/src/components/avatar/index.tsx +1 -1
  107. package/src/components/bar-chart/index.tsx +1048 -0
  108. package/src/components/bottom-sheet/index.tsx +280 -20
  109. package/src/components/breadcrumb/index.tsx +365 -0
  110. package/src/components/chip/index.tsx +2 -2
  111. package/src/components/direction/index.tsx +20 -21
  112. package/src/components/frame/index.tsx +17 -0
  113. package/src/components/heatmap-chart/index.tsx +58 -11
  114. package/src/components/input-group/index.tsx +2 -2
  115. package/src/components/line-chart/index.tsx +13 -181
  116. package/src/components/loader/index.tsx +812 -0
  117. package/src/components/map/basemap.ts +304 -0
  118. package/src/components/map/index.tsx +1118 -0
  119. package/src/components/map/maplibre.ts +201 -0
  120. package/src/components/message/index.tsx +8 -7
  121. package/src/components/otp-input/index.tsx +2 -2
  122. package/src/components/progress/index.tsx +10 -2
  123. package/src/components/ring-chart/index.tsx +543 -0
  124. package/src/components/section-rail/index.tsx +2 -2
  125. package/src/components/separator/index.tsx +77 -19
  126. package/src/components/shimmer/index.tsx +10 -1
  127. package/src/components/slider/index.tsx +20 -5
  128. package/src/components/steps/index.tsx +1 -1
  129. package/src/components/switch/index.tsx +6 -1
  130. package/src/components/typography/index.tsx +5 -0
  131. package/src/hooks/use-direction.ts +45 -0
  132. package/src/icons/index.tsx +66 -0
  133. package/src/index.ts +84 -0
  134. package/src/primitives/text.tsx +25 -7
  135. package/src/utils/chart.ts +355 -0
@@ -81,6 +81,16 @@ import Svg, {
81
81
  } from 'react-native-svg';
82
82
  import { useCSSVariable } from 'uniwind';
83
83
  import { Text } from '../../primitives/text';
84
+ import {
85
+ areaPath,
86
+ columnValues,
87
+ compactNumber,
88
+ linePath,
89
+ useSeriesColor,
90
+ xOf,
91
+ yOf,
92
+ type Plot,
93
+ } from '../../utils/chart';
84
94
  import { cn } from '../../utils/cn';
85
95
 
86
96
  const AnimatedPath = Animated.createAnimatedComponent(Path);
@@ -102,13 +112,6 @@ export type LineChartStatus = 'loading' | 'ready';
102
112
  export type LineChartCurve = 'monotone' | 'linear';
103
113
  export type LineChartDatum = Record<string, string | number | null | undefined>;
104
114
 
105
- interface Plot {
106
- width: number;
107
- height: number;
108
- left: number;
109
- top: number;
110
- }
111
-
112
115
  interface LineChartContextValue {
113
116
  data: LineChartDatum[];
114
117
  xDataKey: string;
@@ -524,7 +527,7 @@ function LineChartLine({
524
527
  return () => unregisterSeries(dataKey);
525
528
  }, [dataKey, stroke, registerSeries, unregisterSeries]);
526
529
 
527
- const values = useMemo(() => numbersOf(data, dataKey), [data, dataKey]);
530
+ const values = useMemo(() => columnValues(data, dataKey), [data, dataKey]);
528
531
  const loading = status === 'loading';
529
532
 
530
533
  const animatedProps = useAnimatedProps(() => ({
@@ -609,7 +612,7 @@ function LineChartArea({ dataKey, color, colorIndex = 1, opacity = 0.18 }: LineC
609
612
  const fill = useSeriesColor(color, colorIndex);
610
613
  const gradientId = useRef(`panelui-area-${Math.random().toString(36).slice(2, 9)}`).current;
611
614
 
612
- const values = useMemo(() => numbersOf(data, dataKey), [data, dataKey]);
615
+ const values = useMemo(() => columnValues(data, dataKey), [data, dataKey]);
613
616
  const loading = status === 'loading';
614
617
 
615
618
  const animatedProps = useAnimatedProps(() => ({
@@ -893,7 +896,7 @@ function LineChartTooltip({ color, showLabel = true, formatValue, formatX }: Lin
893
896
  {series.map(([key, seriesColor]) => (
894
897
  <TooltipDot
895
898
  key={key}
896
- values={numbersOf(data, key)}
899
+ values={columnValues(data, key)}
897
900
  plot={plot}
898
901
  domainMin={domainMin}
899
902
  domainMax={domainMax}
@@ -953,13 +956,6 @@ LineChartTooltip.layer = 'overlay' as Layer;
953
956
  const LABEL_WIDTH = 112;
954
957
 
955
958
  /** A compact number for the crosshair label: 1204 → "1.2k", 24801 → "24.8k". */
956
- function compactNumber(value: number): string {
957
- const abs = Math.abs(value);
958
- if (abs >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`;
959
- if (abs >= 1_000) return `${(value / 1_000).toFixed(1)}k`;
960
- return `${Math.round(value)}`;
961
- }
962
-
963
959
  const DOT = 9;
964
960
 
965
961
  /** The dot riding one series under the crosshair. */
@@ -1048,170 +1044,6 @@ LineChartLegend.layer = 'overlay' as Layer;
1048
1044
  /* -------------------------------------------------------------------------- */
1049
1045
 
1050
1046
  /** Only reached if the theme CSS was never imported. */
1051
- const FALLBACK_SERIES = ['#3b82f6', '#10b981', '#f59e0b', '#8b5cf6', '#ec4899'];
1052
-
1053
- /** Series colour: an explicit one, else the `--color-chart-*` token. */
1054
- function useSeriesColor(explicit: string | undefined, index: 1 | 2 | 3 | 4 | 5): string {
1055
- const token = useCSSVariable(`--color-chart-${index}`);
1056
- return explicit ?? (typeof token === 'string' ? token : FALLBACK_SERIES[index - 1]!);
1057
- }
1058
-
1059
- function numbersOf(data: LineChartDatum[], key: string): (number | null)[] {
1060
- return data.map((row) => {
1061
- const value = row[key];
1062
- return typeof value === 'number' && !Number.isNaN(value) ? value : null;
1063
- });
1064
- }
1065
-
1066
- function xOf(index: number, total: number, plot: Plot): number {
1067
- 'worklet';
1068
- if (total <= 1) return plot.left + plot.width / 2;
1069
- return plot.left + (plot.width * index) / (total - 1);
1070
- }
1071
-
1072
- function yOf(value: number, plot: Plot, min: number, max: number): number {
1073
- 'worklet';
1074
- const span = max - min || 1;
1075
- return plot.top + plot.height - ((value - min) / span) * plot.height;
1076
- }
1077
-
1078
- /**
1079
- * Monotone cubic tangents.
1080
- *
1081
- * Written out rather than taken from a charting dependency, because it is forty
1082
- * lines and it has to run inside a worklet — the path is rebuilt on the UI
1083
- * thread on every frame the y-domain is tweening.
1084
- *
1085
- * Monotone is the right default for a time series. A plain cubic spline
1086
- * overshoots between points, so a series that never goes below zero draws a dip
1087
- * under the axis between two low values — a shape that is not in the data. This
1088
- * one cannot, because the tangent at each point is clamped against the slopes
1089
- * either side of it, and a local peak or trough is given a flat one.
1090
- */
1091
- function tangents(xs: number[], ys: number[]): number[] {
1092
- 'worklet';
1093
- const n = xs.length;
1094
- const slopes: number[] = [];
1095
- for (let i = 0; i < n - 1; i += 1) {
1096
- slopes.push((ys[i + 1]! - ys[i]!) / (xs[i + 1]! - xs[i]! || 1));
1097
- }
1098
-
1099
- const result: number[] = new Array(n).fill(0);
1100
- result[0] = slopes[0] ?? 0;
1101
- result[n - 1] = slopes[n - 2] ?? 0;
1102
-
1103
- for (let i = 1; i < n - 1; i += 1) {
1104
- const previous = slopes[i - 1]!;
1105
- const next = slopes[i]!;
1106
- result[i] = previous * next <= 0 ? 0 : (previous + next) / 2;
1107
- }
1108
-
1109
- // Fritsch–Carlson: pull any tangent back inside the circle of radius 3, which
1110
- // is the condition for the segment to stay monotone.
1111
- for (let i = 0; i < n - 1; i += 1) {
1112
- const slope = slopes[i]!;
1113
- if (slope === 0) {
1114
- result[i] = 0;
1115
- result[i + 1] = 0;
1116
- continue;
1117
- }
1118
- const a = result[i]! / slope;
1119
- const b = result[i + 1]! / slope;
1120
- const magnitude = Math.sqrt(a * a + b * b);
1121
- if (magnitude > 3) {
1122
- result[i] = (3 / magnitude) * a * slope;
1123
- result[i + 1] = (3 / magnitude) * b * slope;
1124
- }
1125
- }
1126
-
1127
- return result;
1128
- }
1129
-
1130
- /** Points, split at the gaps — a null breaks the series rather than crossing it. */
1131
- function runsOf(
1132
- values: (number | null)[],
1133
- plot: Plot,
1134
- min: number,
1135
- max: number
1136
- ): { x: number; y: number }[][] {
1137
- 'worklet';
1138
- const runs: { x: number; y: number }[][] = [];
1139
- let run: { x: number; y: number }[] = [];
1140
-
1141
- for (let i = 0; i < values.length; i += 1) {
1142
- const value = values[i];
1143
- if (value === null || value === undefined) {
1144
- if (run.length) runs.push(run);
1145
- run = [];
1146
- continue;
1147
- }
1148
- run.push({ x: xOf(i, values.length, plot), y: yOf(value, plot, min, max) });
1149
- }
1150
- if (run.length) runs.push(run);
1151
- return runs;
1152
- }
1153
-
1154
- function segment(points: { x: number; y: number }[], curve: LineChartCurve): string {
1155
- 'worklet';
1156
- if (!points.length) return '';
1157
- if (points.length < 3 || curve === 'linear') {
1158
- return points.map((p, i) => `${i === 0 ? 'M' : 'L'}${p.x},${p.y}`).join(' ');
1159
- }
1160
-
1161
- const xs = points.map((p) => p.x);
1162
- const ys = points.map((p) => p.y);
1163
- const ms = tangents(xs, ys);
1164
-
1165
- let d = `M${xs[0]},${ys[0]}`;
1166
- for (let i = 0; i < points.length - 1; i += 1) {
1167
- const dx = (xs[i + 1]! - xs[i]!) / 3;
1168
- d += ` C${xs[i]! + dx},${ys[i]! + ms[i]! * dx} ${xs[i + 1]! - dx},${ys[i + 1]! - ms[i + 1]! * dx} ${xs[i + 1]},${ys[i + 1]}`;
1169
- }
1170
- return d;
1171
- }
1172
-
1173
- function linePath(
1174
- values: (number | null)[],
1175
- plot: Plot,
1176
- min: number,
1177
- max: number,
1178
- curve: LineChartCurve,
1179
- loading: boolean
1180
- ): string {
1181
- 'worklet';
1182
- if (loading || plot.width <= 0) {
1183
- // Flat down the middle: the shape the skeleton holds, and the shape the
1184
- // real series grows out of once the data arrives.
1185
- const y = plot.top + plot.height / 2;
1186
- return `M${plot.left},${y} L${plot.left + plot.width},${y}`;
1187
- }
1188
- return runsOf(values, plot, min, max)
1189
- .map((run) => segment(run, curve))
1190
- .join(' ');
1191
- }
1192
-
1193
- function areaPath(
1194
- values: (number | null)[],
1195
- plot: Plot,
1196
- min: number,
1197
- max: number,
1198
- curve: LineChartCurve,
1199
- loading: boolean
1200
- ): string {
1201
- 'worklet';
1202
- if (loading || plot.width <= 0) return '';
1203
-
1204
- const baseline = plot.top + plot.height;
1205
- return runsOf(values, plot, min, max)
1206
- .map((run) => {
1207
- const top = segment(run, curve);
1208
- if (!top) return '';
1209
- const first = run[0]!;
1210
- const last = run[run.length - 1]!;
1211
- return `${top} L${last.x},${baseline} L${first.x},${baseline} Z`;
1212
- })
1213
- .join(' ');
1214
- }
1215
1047
 
1216
1048
  export const LineChart = Object.assign(LineChartRoot, {
1217
1049
  Grid: LineChartGrid,