@tuicomponents/gauge 0.1.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.
@@ -0,0 +1,270 @@
1
+ import * as zod from 'zod';
2
+ import { z } from 'zod';
3
+ import { BaseTuiComponent, ComponentMetadata, RenderContext, RenderResult, TuiTheme } from '@tuicomponents/core';
4
+
5
+ /**
6
+ * Semantic color options for gauge zones.
7
+ */
8
+ declare const gaugeZoneColorSchema: z.ZodEnum<["success", "warning", "error"]>;
9
+ type GaugeZoneColor = z.infer<typeof gaugeZoneColorSchema>;
10
+ /**
11
+ * Schema for a zone in the gauge.
12
+ * Zones define colored threshold regions.
13
+ */
14
+ declare const gaugeZoneSchema: z.ZodObject<{
15
+ /**
16
+ * Upper bound of this zone (inclusive).
17
+ * Value must be greater than the previous zone's threshold.
18
+ */
19
+ threshold: z.ZodNumber;
20
+ /**
21
+ * Optional semantic color for this zone.
22
+ * If not specified, uses default bar appearance.
23
+ */
24
+ color: z.ZodOptional<z.ZodEnum<["success", "warning", "error"]>>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ threshold: number;
27
+ color?: "success" | "warning" | "error" | undefined;
28
+ }, {
29
+ threshold: number;
30
+ color?: "success" | "warning" | "error" | undefined;
31
+ }>;
32
+ type GaugeZone = z.infer<typeof gaugeZoneSchema>;
33
+ /**
34
+ * Style options for gauge bar characters.
35
+ */
36
+ declare const gaugeStyleSchema: z.ZodEnum<["bar", "segments", "blocks"]>;
37
+ type GaugeStyle = z.infer<typeof gaugeStyleSchema>;
38
+ /**
39
+ * Schema for gauge component input.
40
+ */
41
+ declare const gaugeInputSchema: z.ZodObject<{
42
+ /**
43
+ * Current gauge value.
44
+ */
45
+ value: z.ZodNumber;
46
+ /**
47
+ * Minimum value on the scale.
48
+ * @default 0
49
+ */
50
+ min: z.ZodDefault<z.ZodNumber>;
51
+ /**
52
+ * Maximum value on the scale.
53
+ * @default 100
54
+ */
55
+ max: z.ZodDefault<z.ZodNumber>;
56
+ /**
57
+ * Optional zones for colored thresholds.
58
+ * Zones should be ordered by increasing threshold.
59
+ */
60
+ zones: z.ZodOptional<z.ZodArray<z.ZodObject<{
61
+ /**
62
+ * Upper bound of this zone (inclusive).
63
+ * Value must be greater than the previous zone's threshold.
64
+ */
65
+ threshold: z.ZodNumber;
66
+ /**
67
+ * Optional semantic color for this zone.
68
+ * If not specified, uses default bar appearance.
69
+ */
70
+ color: z.ZodOptional<z.ZodEnum<["success", "warning", "error"]>>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ threshold: number;
73
+ color?: "success" | "warning" | "error" | undefined;
74
+ }, {
75
+ threshold: number;
76
+ color?: "success" | "warning" | "error" | undefined;
77
+ }>, "many">>;
78
+ /**
79
+ * Width of the gauge bar in characters.
80
+ * @default 20
81
+ */
82
+ width: z.ZodDefault<z.ZodNumber>;
83
+ /**
84
+ * Style for gauge bar characters.
85
+ * @default "bar"
86
+ */
87
+ style: z.ZodDefault<z.ZodEnum<["bar", "segments", "blocks"]>>;
88
+ /**
89
+ * Optional label to display before the gauge.
90
+ */
91
+ label: z.ZodOptional<z.ZodString>;
92
+ /**
93
+ * Whether to show the current value.
94
+ * @default true
95
+ */
96
+ showValue: z.ZodDefault<z.ZodBoolean>;
97
+ /**
98
+ * Unit string to display after the value (e.g., "%", "°C").
99
+ * @default ""
100
+ */
101
+ unit: z.ZodDefault<z.ZodString>;
102
+ }, "strip", z.ZodTypeAny, {
103
+ value: number;
104
+ min: number;
105
+ max: number;
106
+ width: number;
107
+ style: "bar" | "segments" | "blocks";
108
+ showValue: boolean;
109
+ unit: string;
110
+ zones?: {
111
+ threshold: number;
112
+ color?: "success" | "warning" | "error" | undefined;
113
+ }[] | undefined;
114
+ label?: string | undefined;
115
+ }, {
116
+ value: number;
117
+ min?: number | undefined;
118
+ max?: number | undefined;
119
+ zones?: {
120
+ threshold: number;
121
+ color?: "success" | "warning" | "error" | undefined;
122
+ }[] | undefined;
123
+ width?: number | undefined;
124
+ style?: "bar" | "segments" | "blocks" | undefined;
125
+ label?: string | undefined;
126
+ showValue?: boolean | undefined;
127
+ unit?: string | undefined;
128
+ }>;
129
+ type GaugeInput = z.input<typeof gaugeInputSchema>;
130
+ type GaugeInputWithDefaults = z.output<typeof gaugeInputSchema>;
131
+
132
+ /**
133
+ * Gauge component for rendering meters with threshold zones.
134
+ */
135
+ declare class GaugeComponent extends BaseTuiComponent<GaugeInput, typeof gaugeInputSchema> {
136
+ readonly metadata: ComponentMetadata<GaugeInput>;
137
+ readonly schema: zod.ZodObject<{
138
+ value: zod.ZodNumber;
139
+ min: zod.ZodDefault<zod.ZodNumber>;
140
+ max: zod.ZodDefault<zod.ZodNumber>;
141
+ zones: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
142
+ threshold: zod.ZodNumber;
143
+ color: zod.ZodOptional<zod.ZodEnum<["success", "warning", "error"]>>;
144
+ }, "strip", zod.ZodTypeAny, {
145
+ threshold: number;
146
+ color?: "success" | "warning" | "error" | undefined;
147
+ }, {
148
+ threshold: number;
149
+ color?: "success" | "warning" | "error" | undefined;
150
+ }>, "many">>;
151
+ width: zod.ZodDefault<zod.ZodNumber>;
152
+ style: zod.ZodDefault<zod.ZodEnum<["bar", "segments", "blocks"]>>;
153
+ label: zod.ZodOptional<zod.ZodString>;
154
+ showValue: zod.ZodDefault<zod.ZodBoolean>;
155
+ unit: zod.ZodDefault<zod.ZodString>;
156
+ }, "strip", zod.ZodTypeAny, {
157
+ value: number;
158
+ min: number;
159
+ max: number;
160
+ width: number;
161
+ style: "bar" | "segments" | "blocks";
162
+ showValue: boolean;
163
+ unit: string;
164
+ zones?: {
165
+ threshold: number;
166
+ color?: "success" | "warning" | "error" | undefined;
167
+ }[] | undefined;
168
+ label?: string | undefined;
169
+ }, {
170
+ value: number;
171
+ min?: number | undefined;
172
+ max?: number | undefined;
173
+ zones?: {
174
+ threshold: number;
175
+ color?: "success" | "warning" | "error" | undefined;
176
+ }[] | undefined;
177
+ width?: number | undefined;
178
+ style?: "bar" | "segments" | "blocks" | undefined;
179
+ label?: string | undefined;
180
+ showValue?: boolean | undefined;
181
+ unit?: string | undefined;
182
+ }>;
183
+ /**
184
+ * Override getJsonSchema to use direct schema generation.
185
+ */
186
+ getJsonSchema(): object;
187
+ render(input: GaugeInput, context: RenderContext): RenderResult;
188
+ }
189
+ /**
190
+ * Factory function to create a gauge component.
191
+ */
192
+ declare function createGauge(): GaugeComponent;
193
+
194
+ /**
195
+ * Characters used for gauge rendering.
196
+ */
197
+ interface GaugeChars {
198
+ /** Filled portion character */
199
+ filled: string;
200
+ /** Empty portion character */
201
+ empty: string;
202
+ }
203
+ /**
204
+ * Get gauge characters for a given style.
205
+ */
206
+ declare function getGaugeChars(style: GaugeStyle): GaugeChars;
207
+
208
+ /**
209
+ * A segment of the gauge bar with its color.
210
+ */
211
+ interface GaugeSegment {
212
+ /** Number of characters in this segment */
213
+ length: number;
214
+ /** Whether this segment is filled */
215
+ filled: boolean;
216
+ /** Optional zone color for this segment */
217
+ color?: GaugeZoneColor | undefined;
218
+ }
219
+ /**
220
+ * Pre-computed layout for the gauge.
221
+ */
222
+ interface GaugeLayout {
223
+ /** Label to display (empty string if none) */
224
+ label: string;
225
+ /** Segments of the gauge bar (filled and empty portions with colors) */
226
+ segments: GaugeSegment[];
227
+ /** Character for filled portions */
228
+ filledChar: string;
229
+ /** Character for empty portions */
230
+ emptyChar: string;
231
+ /** Current value (clamped to min/max) */
232
+ displayValue: number;
233
+ /** Formatted value string (e.g., "75%") */
234
+ valueStr: string;
235
+ /** Total width of the bar */
236
+ barWidth: number;
237
+ /** Percentage (0-100) of fill */
238
+ percentage: number;
239
+ }
240
+ /**
241
+ * Compute the layout for a gauge.
242
+ *
243
+ * @param input - Validated gauge input with defaults applied
244
+ * @param chars - Character set to use
245
+ * @returns Computed layout ready for rendering
246
+ */
247
+ declare function computeGaugeLayout(input: GaugeInputWithDefaults, chars: GaugeChars): GaugeLayout;
248
+
249
+ /**
250
+ * Render a gauge using ANSI escape codes for rich terminal output.
251
+ *
252
+ * @param layout - Pre-computed gauge layout
253
+ * @param input - Original input with defaults
254
+ * @param theme - Optional theme for colors
255
+ * @returns ANSI-formatted gauge string
256
+ */
257
+ declare function renderGaugeAnsi(layout: GaugeLayout, input: GaugeInputWithDefaults, theme?: TuiTheme): string;
258
+ /**
259
+ * Render a gauge using markdown-friendly output.
260
+ *
261
+ * Consolidates adjacent emphasized segments to avoid double-backtick issues
262
+ * (e.g., `warning``error` renders incorrectly as two adjacent inline code spans).
263
+ *
264
+ * @param layout - Pre-computed gauge layout
265
+ * @param input - Original input with defaults
266
+ * @returns Markdown-friendly gauge string
267
+ */
268
+ declare function renderGaugeMarkdown(layout: GaugeLayout, input: GaugeInputWithDefaults): string;
269
+
270
+ export { type GaugeChars, GaugeComponent, type GaugeInput, type GaugeInputWithDefaults, type GaugeLayout, type GaugeSegment, type GaugeStyle, type GaugeZone, type GaugeZoneColor, computeGaugeLayout, createGauge, gaugeInputSchema, gaugeStyleSchema, gaugeZoneColorSchema, gaugeZoneSchema, getGaugeChars, renderGaugeAnsi, renderGaugeMarkdown };
@@ -0,0 +1,270 @@
1
+ import * as zod from 'zod';
2
+ import { z } from 'zod';
3
+ import { BaseTuiComponent, ComponentMetadata, RenderContext, RenderResult, TuiTheme } from '@tuicomponents/core';
4
+
5
+ /**
6
+ * Semantic color options for gauge zones.
7
+ */
8
+ declare const gaugeZoneColorSchema: z.ZodEnum<["success", "warning", "error"]>;
9
+ type GaugeZoneColor = z.infer<typeof gaugeZoneColorSchema>;
10
+ /**
11
+ * Schema for a zone in the gauge.
12
+ * Zones define colored threshold regions.
13
+ */
14
+ declare const gaugeZoneSchema: z.ZodObject<{
15
+ /**
16
+ * Upper bound of this zone (inclusive).
17
+ * Value must be greater than the previous zone's threshold.
18
+ */
19
+ threshold: z.ZodNumber;
20
+ /**
21
+ * Optional semantic color for this zone.
22
+ * If not specified, uses default bar appearance.
23
+ */
24
+ color: z.ZodOptional<z.ZodEnum<["success", "warning", "error"]>>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ threshold: number;
27
+ color?: "success" | "warning" | "error" | undefined;
28
+ }, {
29
+ threshold: number;
30
+ color?: "success" | "warning" | "error" | undefined;
31
+ }>;
32
+ type GaugeZone = z.infer<typeof gaugeZoneSchema>;
33
+ /**
34
+ * Style options for gauge bar characters.
35
+ */
36
+ declare const gaugeStyleSchema: z.ZodEnum<["bar", "segments", "blocks"]>;
37
+ type GaugeStyle = z.infer<typeof gaugeStyleSchema>;
38
+ /**
39
+ * Schema for gauge component input.
40
+ */
41
+ declare const gaugeInputSchema: z.ZodObject<{
42
+ /**
43
+ * Current gauge value.
44
+ */
45
+ value: z.ZodNumber;
46
+ /**
47
+ * Minimum value on the scale.
48
+ * @default 0
49
+ */
50
+ min: z.ZodDefault<z.ZodNumber>;
51
+ /**
52
+ * Maximum value on the scale.
53
+ * @default 100
54
+ */
55
+ max: z.ZodDefault<z.ZodNumber>;
56
+ /**
57
+ * Optional zones for colored thresholds.
58
+ * Zones should be ordered by increasing threshold.
59
+ */
60
+ zones: z.ZodOptional<z.ZodArray<z.ZodObject<{
61
+ /**
62
+ * Upper bound of this zone (inclusive).
63
+ * Value must be greater than the previous zone's threshold.
64
+ */
65
+ threshold: z.ZodNumber;
66
+ /**
67
+ * Optional semantic color for this zone.
68
+ * If not specified, uses default bar appearance.
69
+ */
70
+ color: z.ZodOptional<z.ZodEnum<["success", "warning", "error"]>>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ threshold: number;
73
+ color?: "success" | "warning" | "error" | undefined;
74
+ }, {
75
+ threshold: number;
76
+ color?: "success" | "warning" | "error" | undefined;
77
+ }>, "many">>;
78
+ /**
79
+ * Width of the gauge bar in characters.
80
+ * @default 20
81
+ */
82
+ width: z.ZodDefault<z.ZodNumber>;
83
+ /**
84
+ * Style for gauge bar characters.
85
+ * @default "bar"
86
+ */
87
+ style: z.ZodDefault<z.ZodEnum<["bar", "segments", "blocks"]>>;
88
+ /**
89
+ * Optional label to display before the gauge.
90
+ */
91
+ label: z.ZodOptional<z.ZodString>;
92
+ /**
93
+ * Whether to show the current value.
94
+ * @default true
95
+ */
96
+ showValue: z.ZodDefault<z.ZodBoolean>;
97
+ /**
98
+ * Unit string to display after the value (e.g., "%", "°C").
99
+ * @default ""
100
+ */
101
+ unit: z.ZodDefault<z.ZodString>;
102
+ }, "strip", z.ZodTypeAny, {
103
+ value: number;
104
+ min: number;
105
+ max: number;
106
+ width: number;
107
+ style: "bar" | "segments" | "blocks";
108
+ showValue: boolean;
109
+ unit: string;
110
+ zones?: {
111
+ threshold: number;
112
+ color?: "success" | "warning" | "error" | undefined;
113
+ }[] | undefined;
114
+ label?: string | undefined;
115
+ }, {
116
+ value: number;
117
+ min?: number | undefined;
118
+ max?: number | undefined;
119
+ zones?: {
120
+ threshold: number;
121
+ color?: "success" | "warning" | "error" | undefined;
122
+ }[] | undefined;
123
+ width?: number | undefined;
124
+ style?: "bar" | "segments" | "blocks" | undefined;
125
+ label?: string | undefined;
126
+ showValue?: boolean | undefined;
127
+ unit?: string | undefined;
128
+ }>;
129
+ type GaugeInput = z.input<typeof gaugeInputSchema>;
130
+ type GaugeInputWithDefaults = z.output<typeof gaugeInputSchema>;
131
+
132
+ /**
133
+ * Gauge component for rendering meters with threshold zones.
134
+ */
135
+ declare class GaugeComponent extends BaseTuiComponent<GaugeInput, typeof gaugeInputSchema> {
136
+ readonly metadata: ComponentMetadata<GaugeInput>;
137
+ readonly schema: zod.ZodObject<{
138
+ value: zod.ZodNumber;
139
+ min: zod.ZodDefault<zod.ZodNumber>;
140
+ max: zod.ZodDefault<zod.ZodNumber>;
141
+ zones: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
142
+ threshold: zod.ZodNumber;
143
+ color: zod.ZodOptional<zod.ZodEnum<["success", "warning", "error"]>>;
144
+ }, "strip", zod.ZodTypeAny, {
145
+ threshold: number;
146
+ color?: "success" | "warning" | "error" | undefined;
147
+ }, {
148
+ threshold: number;
149
+ color?: "success" | "warning" | "error" | undefined;
150
+ }>, "many">>;
151
+ width: zod.ZodDefault<zod.ZodNumber>;
152
+ style: zod.ZodDefault<zod.ZodEnum<["bar", "segments", "blocks"]>>;
153
+ label: zod.ZodOptional<zod.ZodString>;
154
+ showValue: zod.ZodDefault<zod.ZodBoolean>;
155
+ unit: zod.ZodDefault<zod.ZodString>;
156
+ }, "strip", zod.ZodTypeAny, {
157
+ value: number;
158
+ min: number;
159
+ max: number;
160
+ width: number;
161
+ style: "bar" | "segments" | "blocks";
162
+ showValue: boolean;
163
+ unit: string;
164
+ zones?: {
165
+ threshold: number;
166
+ color?: "success" | "warning" | "error" | undefined;
167
+ }[] | undefined;
168
+ label?: string | undefined;
169
+ }, {
170
+ value: number;
171
+ min?: number | undefined;
172
+ max?: number | undefined;
173
+ zones?: {
174
+ threshold: number;
175
+ color?: "success" | "warning" | "error" | undefined;
176
+ }[] | undefined;
177
+ width?: number | undefined;
178
+ style?: "bar" | "segments" | "blocks" | undefined;
179
+ label?: string | undefined;
180
+ showValue?: boolean | undefined;
181
+ unit?: string | undefined;
182
+ }>;
183
+ /**
184
+ * Override getJsonSchema to use direct schema generation.
185
+ */
186
+ getJsonSchema(): object;
187
+ render(input: GaugeInput, context: RenderContext): RenderResult;
188
+ }
189
+ /**
190
+ * Factory function to create a gauge component.
191
+ */
192
+ declare function createGauge(): GaugeComponent;
193
+
194
+ /**
195
+ * Characters used for gauge rendering.
196
+ */
197
+ interface GaugeChars {
198
+ /** Filled portion character */
199
+ filled: string;
200
+ /** Empty portion character */
201
+ empty: string;
202
+ }
203
+ /**
204
+ * Get gauge characters for a given style.
205
+ */
206
+ declare function getGaugeChars(style: GaugeStyle): GaugeChars;
207
+
208
+ /**
209
+ * A segment of the gauge bar with its color.
210
+ */
211
+ interface GaugeSegment {
212
+ /** Number of characters in this segment */
213
+ length: number;
214
+ /** Whether this segment is filled */
215
+ filled: boolean;
216
+ /** Optional zone color for this segment */
217
+ color?: GaugeZoneColor | undefined;
218
+ }
219
+ /**
220
+ * Pre-computed layout for the gauge.
221
+ */
222
+ interface GaugeLayout {
223
+ /** Label to display (empty string if none) */
224
+ label: string;
225
+ /** Segments of the gauge bar (filled and empty portions with colors) */
226
+ segments: GaugeSegment[];
227
+ /** Character for filled portions */
228
+ filledChar: string;
229
+ /** Character for empty portions */
230
+ emptyChar: string;
231
+ /** Current value (clamped to min/max) */
232
+ displayValue: number;
233
+ /** Formatted value string (e.g., "75%") */
234
+ valueStr: string;
235
+ /** Total width of the bar */
236
+ barWidth: number;
237
+ /** Percentage (0-100) of fill */
238
+ percentage: number;
239
+ }
240
+ /**
241
+ * Compute the layout for a gauge.
242
+ *
243
+ * @param input - Validated gauge input with defaults applied
244
+ * @param chars - Character set to use
245
+ * @returns Computed layout ready for rendering
246
+ */
247
+ declare function computeGaugeLayout(input: GaugeInputWithDefaults, chars: GaugeChars): GaugeLayout;
248
+
249
+ /**
250
+ * Render a gauge using ANSI escape codes for rich terminal output.
251
+ *
252
+ * @param layout - Pre-computed gauge layout
253
+ * @param input - Original input with defaults
254
+ * @param theme - Optional theme for colors
255
+ * @returns ANSI-formatted gauge string
256
+ */
257
+ declare function renderGaugeAnsi(layout: GaugeLayout, input: GaugeInputWithDefaults, theme?: TuiTheme): string;
258
+ /**
259
+ * Render a gauge using markdown-friendly output.
260
+ *
261
+ * Consolidates adjacent emphasized segments to avoid double-backtick issues
262
+ * (e.g., `warning``error` renders incorrectly as two adjacent inline code spans).
263
+ *
264
+ * @param layout - Pre-computed gauge layout
265
+ * @param input - Original input with defaults
266
+ * @returns Markdown-friendly gauge string
267
+ */
268
+ declare function renderGaugeMarkdown(layout: GaugeLayout, input: GaugeInputWithDefaults): string;
269
+
270
+ export { type GaugeChars, GaugeComponent, type GaugeInput, type GaugeInputWithDefaults, type GaugeLayout, type GaugeSegment, type GaugeStyle, type GaugeZone, type GaugeZoneColor, computeGaugeLayout, createGauge, gaugeInputSchema, gaugeStyleSchema, gaugeZoneColorSchema, gaugeZoneSchema, getGaugeChars, renderGaugeAnsi, renderGaugeMarkdown };