@termuijs/widgets 0.1.1 → 0.1.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/LICENSE +21 -0
- package/README.md +57 -29
- package/dist/index.cjs +511 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -2
- package/dist/index.d.ts +157 -2
- package/dist/index.js +514 -21
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -136,19 +136,31 @@ interface TextProps {
|
|
|
136
136
|
content: string;
|
|
137
137
|
wrap?: boolean;
|
|
138
138
|
align?: 'left' | 'center' | 'right';
|
|
139
|
+
/** Vertical scroll offset (lines to skip from top). Default: 0. */
|
|
140
|
+
scrollY?: number;
|
|
141
|
+
/** Horizontal scroll offset (columns to skip from left). Default: 0. */
|
|
142
|
+
scrollX?: number;
|
|
139
143
|
}
|
|
140
144
|
/**
|
|
141
|
-
* Text — renders a string of text with word-wrapping and
|
|
145
|
+
* Text — renders a string of text with word-wrapping, alignment, and scrolling.
|
|
142
146
|
*/
|
|
143
147
|
declare class Text extends Widget {
|
|
144
148
|
private _content;
|
|
145
149
|
private _wrap;
|
|
146
150
|
private _align;
|
|
151
|
+
private _scrollY;
|
|
152
|
+
private _scrollX;
|
|
147
153
|
constructor(content: string, style?: Partial<Style>, props?: Partial<TextProps>);
|
|
148
154
|
/** Update the text content */
|
|
149
155
|
setContent(content: string): void;
|
|
150
156
|
/** Get current text content */
|
|
151
157
|
getContent(): string;
|
|
158
|
+
/** Set vertical scroll offset (lines to skip). */
|
|
159
|
+
setScrollY(offset: number): void;
|
|
160
|
+
/** Set horizontal scroll offset (columns to skip). */
|
|
161
|
+
setScrollX(offset: number): void;
|
|
162
|
+
/** Get the total number of lines after wrapping. */
|
|
163
|
+
getLineCount(): number;
|
|
152
164
|
protected _renderSelf(screen: Screen): void;
|
|
153
165
|
}
|
|
154
166
|
|
|
@@ -259,6 +271,70 @@ declare class TextInput extends Widget {
|
|
|
259
271
|
protected _renderSelf(screen: Screen): void;
|
|
260
272
|
}
|
|
261
273
|
|
|
274
|
+
interface VirtualListOptions {
|
|
275
|
+
/** Total number of items (the full dataset size) */
|
|
276
|
+
totalItems: number;
|
|
277
|
+
/** Height of each item in rows (default: 1) */
|
|
278
|
+
itemHeight?: number;
|
|
279
|
+
/** Render function: returns the string content for an item at a given index */
|
|
280
|
+
renderItem: (index: number) => string;
|
|
281
|
+
/** Style overrides */
|
|
282
|
+
style?: Partial<Style>;
|
|
283
|
+
/** Callback when an item is selected (Enter key) */
|
|
284
|
+
onSelect?: (index: number) => void;
|
|
285
|
+
/** Number of overscan rows to render above/below the viewport (default: 2) */
|
|
286
|
+
overscan?: number;
|
|
287
|
+
/** Show scrollbar (default: true) */
|
|
288
|
+
showScrollbar?: boolean;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* VirtualList — a scroll-virtualized list widget.
|
|
292
|
+
*
|
|
293
|
+
* Only renders the items visible in the viewport plus
|
|
294
|
+
* a small overscan buffer, enabling smooth scrolling
|
|
295
|
+
* through datasets of any size.
|
|
296
|
+
*
|
|
297
|
+
* Performance:
|
|
298
|
+
* - 100 items → renders ~26 rows
|
|
299
|
+
* - 1,000,000 items → still renders only ~26 rows
|
|
300
|
+
*/
|
|
301
|
+
declare class VirtualList extends Widget {
|
|
302
|
+
private _totalItems;
|
|
303
|
+
private _itemHeight;
|
|
304
|
+
private _renderItem;
|
|
305
|
+
private _onSelect?;
|
|
306
|
+
private _selectedIndex;
|
|
307
|
+
private _scrollOffset;
|
|
308
|
+
private _overscan;
|
|
309
|
+
private _showScrollbar;
|
|
310
|
+
constructor(options: VirtualListOptions);
|
|
311
|
+
get totalItems(): number;
|
|
312
|
+
get selectedIndex(): number;
|
|
313
|
+
get scrollOffset(): number;
|
|
314
|
+
/** Update the total item count (e.g., after data refresh) */
|
|
315
|
+
setTotalItems(count: number): void;
|
|
316
|
+
/** Update the render function (e.g., when data changes) */
|
|
317
|
+
setRenderItem(fn: (index: number) => string): void;
|
|
318
|
+
/** Move selection up by one */
|
|
319
|
+
selectPrev(): void;
|
|
320
|
+
/** Move selection down by one */
|
|
321
|
+
selectNext(): void;
|
|
322
|
+
/** Jump to the first item */
|
|
323
|
+
selectFirst(): void;
|
|
324
|
+
/** Jump to the last item */
|
|
325
|
+
selectLast(): void;
|
|
326
|
+
/** Page up — move by viewport height */
|
|
327
|
+
pageUp(): void;
|
|
328
|
+
/** Page down — move by viewport height */
|
|
329
|
+
pageDown(): void;
|
|
330
|
+
/** Scroll to a specific index */
|
|
331
|
+
scrollTo(index: number): void;
|
|
332
|
+
/** Confirm the current selection */
|
|
333
|
+
confirm(): void;
|
|
334
|
+
protected _renderSelf(screen: Screen): void;
|
|
335
|
+
private _clampScroll;
|
|
336
|
+
}
|
|
337
|
+
|
|
262
338
|
interface TableColumn {
|
|
263
339
|
/** Column header label */
|
|
264
340
|
header: string;
|
|
@@ -380,6 +456,53 @@ declare class StatusIndicator extends Widget {
|
|
|
380
456
|
protected _renderSelf(screen: Screen): void;
|
|
381
457
|
}
|
|
382
458
|
|
|
459
|
+
interface Bar {
|
|
460
|
+
value: number;
|
|
461
|
+
label?: string;
|
|
462
|
+
color?: Color;
|
|
463
|
+
}
|
|
464
|
+
interface BarGroup {
|
|
465
|
+
label?: string;
|
|
466
|
+
bars: Bar[];
|
|
467
|
+
}
|
|
468
|
+
type BarChartDirection = 'vertical' | 'horizontal';
|
|
469
|
+
interface BarChartOptions {
|
|
470
|
+
/** Direction bars grow. Default: 'vertical'. */
|
|
471
|
+
direction?: BarChartDirection;
|
|
472
|
+
/** Width of each bar in cells. Default: 1. */
|
|
473
|
+
barWidth?: number;
|
|
474
|
+
/** Gap between bars in a group. Default: 1. */
|
|
475
|
+
barGap?: number;
|
|
476
|
+
/** Gap between groups. Default: 2. */
|
|
477
|
+
groupGap?: number;
|
|
478
|
+
/** Max value for scaling. Auto-detected if not set. */
|
|
479
|
+
max?: number;
|
|
480
|
+
/** Color for bars without a per-bar color. */
|
|
481
|
+
barColor?: Color;
|
|
482
|
+
/** Color for value labels. */
|
|
483
|
+
valueColor?: Color;
|
|
484
|
+
/** Color for text labels. */
|
|
485
|
+
labelColor?: Color;
|
|
486
|
+
}
|
|
487
|
+
declare class BarChart extends Widget {
|
|
488
|
+
private _data;
|
|
489
|
+
private _direction;
|
|
490
|
+
private _barWidth;
|
|
491
|
+
private _barGap;
|
|
492
|
+
private _groupGap;
|
|
493
|
+
private _max?;
|
|
494
|
+
private _barColor;
|
|
495
|
+
private _valueColor;
|
|
496
|
+
private _labelColor;
|
|
497
|
+
constructor(data: BarGroup[], style?: Partial<Style>, opts?: BarChartOptions);
|
|
498
|
+
setData(data: BarGroup[]): void;
|
|
499
|
+
setMax(max: number | undefined): void;
|
|
500
|
+
protected _renderSelf(screen: Screen): void;
|
|
501
|
+
private _computeMax;
|
|
502
|
+
private _renderVertical;
|
|
503
|
+
private _renderHorizontal;
|
|
504
|
+
}
|
|
505
|
+
|
|
383
506
|
interface ProgressBarOptions {
|
|
384
507
|
/** Current value (0–1) */
|
|
385
508
|
value?: number;
|
|
@@ -466,4 +589,36 @@ declare class Spinner extends Widget {
|
|
|
466
589
|
protected _renderSelf(screen: Screen): void;
|
|
467
590
|
}
|
|
468
591
|
|
|
469
|
-
|
|
592
|
+
type ScrollbarOrientation = 'verticalRight' | 'verticalLeft' | 'horizontalBottom' | 'horizontalTop';
|
|
593
|
+
interface ScrollbarOptions {
|
|
594
|
+
/** Total number of content items. */
|
|
595
|
+
contentLength: number;
|
|
596
|
+
/** Number of items visible in the viewport. */
|
|
597
|
+
viewportLength: number;
|
|
598
|
+
/** Current scroll position (0-based). */
|
|
599
|
+
position?: number;
|
|
600
|
+
/** Scrollbar orientation. Default: 'verticalRight'. */
|
|
601
|
+
orientation?: ScrollbarOrientation;
|
|
602
|
+
/** Color of the thumb. */
|
|
603
|
+
thumbColor?: Color;
|
|
604
|
+
/** Color of the track. */
|
|
605
|
+
trackColor?: Color;
|
|
606
|
+
/** Show begin/end arrow symbols. Default: true. */
|
|
607
|
+
showArrows?: boolean;
|
|
608
|
+
}
|
|
609
|
+
declare class Scrollbar extends Widget {
|
|
610
|
+
private _contentLength;
|
|
611
|
+
private _viewportLength;
|
|
612
|
+
private _position;
|
|
613
|
+
private _orientation;
|
|
614
|
+
private _thumbColor;
|
|
615
|
+
private _trackColor;
|
|
616
|
+
private _showArrows;
|
|
617
|
+
constructor(style: Partial<Style> | undefined, opts: ScrollbarOptions);
|
|
618
|
+
setPosition(position: number): void;
|
|
619
|
+
setContentLength(length: number): void;
|
|
620
|
+
setViewportLength(length: number): void;
|
|
621
|
+
protected _renderSelf(screen: Screen): void;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export { type Bar, BarChart, type BarChartDirection, type BarChartOptions, type BarGroup, Box, Gauge, type GaugeOptions, List, type ListItem, LogView, type LogViewOptions, ProgressBar, type ProgressBarOptions, SPINNER_FRAMES, Scrollbar, type ScrollbarOptions, type ScrollbarOrientation, Sparkline, type SparklineOptions, Spinner, type SpinnerOptions, StatusIndicator, type StatusIndicatorOptions, Table, type TableColumn, type TableOptions, type TableRow, Text, TextInput, type TextProps, VirtualList, type VirtualListOptions, Widget, type WidgetEvents };
|
package/dist/index.d.ts
CHANGED
|
@@ -136,19 +136,31 @@ interface TextProps {
|
|
|
136
136
|
content: string;
|
|
137
137
|
wrap?: boolean;
|
|
138
138
|
align?: 'left' | 'center' | 'right';
|
|
139
|
+
/** Vertical scroll offset (lines to skip from top). Default: 0. */
|
|
140
|
+
scrollY?: number;
|
|
141
|
+
/** Horizontal scroll offset (columns to skip from left). Default: 0. */
|
|
142
|
+
scrollX?: number;
|
|
139
143
|
}
|
|
140
144
|
/**
|
|
141
|
-
* Text — renders a string of text with word-wrapping and
|
|
145
|
+
* Text — renders a string of text with word-wrapping, alignment, and scrolling.
|
|
142
146
|
*/
|
|
143
147
|
declare class Text extends Widget {
|
|
144
148
|
private _content;
|
|
145
149
|
private _wrap;
|
|
146
150
|
private _align;
|
|
151
|
+
private _scrollY;
|
|
152
|
+
private _scrollX;
|
|
147
153
|
constructor(content: string, style?: Partial<Style>, props?: Partial<TextProps>);
|
|
148
154
|
/** Update the text content */
|
|
149
155
|
setContent(content: string): void;
|
|
150
156
|
/** Get current text content */
|
|
151
157
|
getContent(): string;
|
|
158
|
+
/** Set vertical scroll offset (lines to skip). */
|
|
159
|
+
setScrollY(offset: number): void;
|
|
160
|
+
/** Set horizontal scroll offset (columns to skip). */
|
|
161
|
+
setScrollX(offset: number): void;
|
|
162
|
+
/** Get the total number of lines after wrapping. */
|
|
163
|
+
getLineCount(): number;
|
|
152
164
|
protected _renderSelf(screen: Screen): void;
|
|
153
165
|
}
|
|
154
166
|
|
|
@@ -259,6 +271,70 @@ declare class TextInput extends Widget {
|
|
|
259
271
|
protected _renderSelf(screen: Screen): void;
|
|
260
272
|
}
|
|
261
273
|
|
|
274
|
+
interface VirtualListOptions {
|
|
275
|
+
/** Total number of items (the full dataset size) */
|
|
276
|
+
totalItems: number;
|
|
277
|
+
/** Height of each item in rows (default: 1) */
|
|
278
|
+
itemHeight?: number;
|
|
279
|
+
/** Render function: returns the string content for an item at a given index */
|
|
280
|
+
renderItem: (index: number) => string;
|
|
281
|
+
/** Style overrides */
|
|
282
|
+
style?: Partial<Style>;
|
|
283
|
+
/** Callback when an item is selected (Enter key) */
|
|
284
|
+
onSelect?: (index: number) => void;
|
|
285
|
+
/** Number of overscan rows to render above/below the viewport (default: 2) */
|
|
286
|
+
overscan?: number;
|
|
287
|
+
/** Show scrollbar (default: true) */
|
|
288
|
+
showScrollbar?: boolean;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* VirtualList — a scroll-virtualized list widget.
|
|
292
|
+
*
|
|
293
|
+
* Only renders the items visible in the viewport plus
|
|
294
|
+
* a small overscan buffer, enabling smooth scrolling
|
|
295
|
+
* through datasets of any size.
|
|
296
|
+
*
|
|
297
|
+
* Performance:
|
|
298
|
+
* - 100 items → renders ~26 rows
|
|
299
|
+
* - 1,000,000 items → still renders only ~26 rows
|
|
300
|
+
*/
|
|
301
|
+
declare class VirtualList extends Widget {
|
|
302
|
+
private _totalItems;
|
|
303
|
+
private _itemHeight;
|
|
304
|
+
private _renderItem;
|
|
305
|
+
private _onSelect?;
|
|
306
|
+
private _selectedIndex;
|
|
307
|
+
private _scrollOffset;
|
|
308
|
+
private _overscan;
|
|
309
|
+
private _showScrollbar;
|
|
310
|
+
constructor(options: VirtualListOptions);
|
|
311
|
+
get totalItems(): number;
|
|
312
|
+
get selectedIndex(): number;
|
|
313
|
+
get scrollOffset(): number;
|
|
314
|
+
/** Update the total item count (e.g., after data refresh) */
|
|
315
|
+
setTotalItems(count: number): void;
|
|
316
|
+
/** Update the render function (e.g., when data changes) */
|
|
317
|
+
setRenderItem(fn: (index: number) => string): void;
|
|
318
|
+
/** Move selection up by one */
|
|
319
|
+
selectPrev(): void;
|
|
320
|
+
/** Move selection down by one */
|
|
321
|
+
selectNext(): void;
|
|
322
|
+
/** Jump to the first item */
|
|
323
|
+
selectFirst(): void;
|
|
324
|
+
/** Jump to the last item */
|
|
325
|
+
selectLast(): void;
|
|
326
|
+
/** Page up — move by viewport height */
|
|
327
|
+
pageUp(): void;
|
|
328
|
+
/** Page down — move by viewport height */
|
|
329
|
+
pageDown(): void;
|
|
330
|
+
/** Scroll to a specific index */
|
|
331
|
+
scrollTo(index: number): void;
|
|
332
|
+
/** Confirm the current selection */
|
|
333
|
+
confirm(): void;
|
|
334
|
+
protected _renderSelf(screen: Screen): void;
|
|
335
|
+
private _clampScroll;
|
|
336
|
+
}
|
|
337
|
+
|
|
262
338
|
interface TableColumn {
|
|
263
339
|
/** Column header label */
|
|
264
340
|
header: string;
|
|
@@ -380,6 +456,53 @@ declare class StatusIndicator extends Widget {
|
|
|
380
456
|
protected _renderSelf(screen: Screen): void;
|
|
381
457
|
}
|
|
382
458
|
|
|
459
|
+
interface Bar {
|
|
460
|
+
value: number;
|
|
461
|
+
label?: string;
|
|
462
|
+
color?: Color;
|
|
463
|
+
}
|
|
464
|
+
interface BarGroup {
|
|
465
|
+
label?: string;
|
|
466
|
+
bars: Bar[];
|
|
467
|
+
}
|
|
468
|
+
type BarChartDirection = 'vertical' | 'horizontal';
|
|
469
|
+
interface BarChartOptions {
|
|
470
|
+
/** Direction bars grow. Default: 'vertical'. */
|
|
471
|
+
direction?: BarChartDirection;
|
|
472
|
+
/** Width of each bar in cells. Default: 1. */
|
|
473
|
+
barWidth?: number;
|
|
474
|
+
/** Gap between bars in a group. Default: 1. */
|
|
475
|
+
barGap?: number;
|
|
476
|
+
/** Gap between groups. Default: 2. */
|
|
477
|
+
groupGap?: number;
|
|
478
|
+
/** Max value for scaling. Auto-detected if not set. */
|
|
479
|
+
max?: number;
|
|
480
|
+
/** Color for bars without a per-bar color. */
|
|
481
|
+
barColor?: Color;
|
|
482
|
+
/** Color for value labels. */
|
|
483
|
+
valueColor?: Color;
|
|
484
|
+
/** Color for text labels. */
|
|
485
|
+
labelColor?: Color;
|
|
486
|
+
}
|
|
487
|
+
declare class BarChart extends Widget {
|
|
488
|
+
private _data;
|
|
489
|
+
private _direction;
|
|
490
|
+
private _barWidth;
|
|
491
|
+
private _barGap;
|
|
492
|
+
private _groupGap;
|
|
493
|
+
private _max?;
|
|
494
|
+
private _barColor;
|
|
495
|
+
private _valueColor;
|
|
496
|
+
private _labelColor;
|
|
497
|
+
constructor(data: BarGroup[], style?: Partial<Style>, opts?: BarChartOptions);
|
|
498
|
+
setData(data: BarGroup[]): void;
|
|
499
|
+
setMax(max: number | undefined): void;
|
|
500
|
+
protected _renderSelf(screen: Screen): void;
|
|
501
|
+
private _computeMax;
|
|
502
|
+
private _renderVertical;
|
|
503
|
+
private _renderHorizontal;
|
|
504
|
+
}
|
|
505
|
+
|
|
383
506
|
interface ProgressBarOptions {
|
|
384
507
|
/** Current value (0–1) */
|
|
385
508
|
value?: number;
|
|
@@ -466,4 +589,36 @@ declare class Spinner extends Widget {
|
|
|
466
589
|
protected _renderSelf(screen: Screen): void;
|
|
467
590
|
}
|
|
468
591
|
|
|
469
|
-
|
|
592
|
+
type ScrollbarOrientation = 'verticalRight' | 'verticalLeft' | 'horizontalBottom' | 'horizontalTop';
|
|
593
|
+
interface ScrollbarOptions {
|
|
594
|
+
/** Total number of content items. */
|
|
595
|
+
contentLength: number;
|
|
596
|
+
/** Number of items visible in the viewport. */
|
|
597
|
+
viewportLength: number;
|
|
598
|
+
/** Current scroll position (0-based). */
|
|
599
|
+
position?: number;
|
|
600
|
+
/** Scrollbar orientation. Default: 'verticalRight'. */
|
|
601
|
+
orientation?: ScrollbarOrientation;
|
|
602
|
+
/** Color of the thumb. */
|
|
603
|
+
thumbColor?: Color;
|
|
604
|
+
/** Color of the track. */
|
|
605
|
+
trackColor?: Color;
|
|
606
|
+
/** Show begin/end arrow symbols. Default: true. */
|
|
607
|
+
showArrows?: boolean;
|
|
608
|
+
}
|
|
609
|
+
declare class Scrollbar extends Widget {
|
|
610
|
+
private _contentLength;
|
|
611
|
+
private _viewportLength;
|
|
612
|
+
private _position;
|
|
613
|
+
private _orientation;
|
|
614
|
+
private _thumbColor;
|
|
615
|
+
private _trackColor;
|
|
616
|
+
private _showArrows;
|
|
617
|
+
constructor(style: Partial<Style> | undefined, opts: ScrollbarOptions);
|
|
618
|
+
setPosition(position: number): void;
|
|
619
|
+
setContentLength(length: number): void;
|
|
620
|
+
setViewportLength(length: number): void;
|
|
621
|
+
protected _renderSelf(screen: Screen): void;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export { type Bar, BarChart, type BarChartDirection, type BarChartOptions, type BarGroup, Box, Gauge, type GaugeOptions, List, type ListItem, LogView, type LogViewOptions, ProgressBar, type ProgressBarOptions, SPINNER_FRAMES, Scrollbar, type ScrollbarOptions, type ScrollbarOrientation, Sparkline, type SparklineOptions, Spinner, type SpinnerOptions, StatusIndicator, type StatusIndicatorOptions, Table, type TableColumn, type TableOptions, type TableRow, Text, TextInput, type TextProps, VirtualList, type VirtualListOptions, Widget, type WidgetEvents };
|