@andrew_l/vue-stdout 0.0.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.
@@ -0,0 +1,608 @@
1
+ import * as vue from 'vue';
2
+ import { FunctionalComponent, MaybeRefOrGetter, ShallowRef } from 'vue';
3
+ import { ForegroundColorName } from 'ansi-styles';
4
+ import { Boxes, BoxStyle } from 'cli-boxes';
5
+ import { LiteralUnion } from 'type-fest';
6
+ import { ForegroundColorName as ForegroundColorName$1 } from 'chalk';
7
+ import { EventEmitter } from 'node:events';
8
+ import { Node } from 'yoga-wasm-web/auto';
9
+ import * as _vue_runtime_core from '@vue/runtime-core';
10
+ import * as _andrew_l_toolkit from '@andrew_l/toolkit';
11
+ import { AnyFunction, Fn } from '@andrew_l/toolkit';
12
+
13
+ type Styles = {
14
+ readonly textWrap?: 'wrap' | 'end' | 'middle' | 'truncate-end' | 'truncate' | 'truncate-middle' | 'truncate-start';
15
+ readonly position?: 'absolute' | 'relative';
16
+ /**
17
+ * Size of the gap between an element's columns.
18
+ */
19
+ readonly columnGap?: number;
20
+ /**
21
+ * Size of the gap between element's rows.
22
+ */
23
+ readonly rowGap?: number;
24
+ /**
25
+ * Size of the gap between an element's columns and rows. Shorthand for `columnGap` and `rowGap`.
26
+ */
27
+ readonly gap?: number;
28
+ /**
29
+ * Margin on all sides. Equivalent to setting `marginTop`, `marginBottom`, `marginLeft` and `marginRight`.
30
+ */
31
+ readonly margin?: number;
32
+ /**
33
+ * Horizontal margin. Equivalent to setting `marginLeft` and `marginRight`.
34
+ */
35
+ readonly marginX?: number;
36
+ /**
37
+ * Vertical margin. Equivalent to setting `marginTop` and `marginBottom`.
38
+ */
39
+ readonly marginY?: number;
40
+ /**
41
+ * Top margin.
42
+ */
43
+ readonly marginTop?: number;
44
+ /**
45
+ * Bottom margin.
46
+ */
47
+ readonly marginBottom?: number;
48
+ /**
49
+ * Left margin.
50
+ */
51
+ readonly marginLeft?: number;
52
+ /**
53
+ * Right margin.
54
+ */
55
+ readonly marginRight?: number;
56
+ /**
57
+ * Padding on all sides. Equivalent to setting `paddingTop`, `paddingBottom`, `paddingLeft` and `paddingRight`.
58
+ */
59
+ readonly padding?: number;
60
+ /**
61
+ * Horizontal padding. Equivalent to setting `paddingLeft` and `paddingRight`.
62
+ */
63
+ readonly paddingX?: number;
64
+ /**
65
+ * Vertical padding. Equivalent to setting `paddingTop` and `paddingBottom`.
66
+ */
67
+ readonly paddingY?: number;
68
+ /**
69
+ * Top padding.
70
+ */
71
+ readonly paddingTop?: number;
72
+ /**
73
+ * Bottom padding.
74
+ */
75
+ readonly paddingBottom?: number;
76
+ /**
77
+ * Left padding.
78
+ */
79
+ readonly paddingLeft?: number;
80
+ /**
81
+ * Right padding.
82
+ */
83
+ readonly paddingRight?: number;
84
+ /**
85
+ * This property defines the ability for a flex item to grow if necessary.
86
+ * See [flex-grow](https://css-tricks.com/almanac/properties/f/flex-grow/).
87
+ */
88
+ readonly flexGrow?: number;
89
+ /**
90
+ * It specifies the “flex shrink factor”, which determines how much the flex item will shrink relative to the rest of the flex items in the flex container when there isn’t enough space on the row.
91
+ * See [flex-shrink](https://css-tricks.com/almanac/properties/f/flex-shrink/).
92
+ */
93
+ readonly flexShrink?: number;
94
+ /**
95
+ * It establishes the main-axis, thus defining the direction flex items are placed in the flex container.
96
+ * See [flex-direction](https://css-tricks.com/almanac/properties/f/flex-direction/).
97
+ */
98
+ readonly flexDirection?: 'row' | 'column' | 'row-reverse' | 'column-reverse';
99
+ /**
100
+ * It specifies the initial size of the flex item, before any available space is distributed according to the flex factors.
101
+ * See [flex-basis](https://css-tricks.com/almanac/properties/f/flex-basis/).
102
+ */
103
+ readonly flexBasis?: number | string;
104
+ /**
105
+ * It defines whether the flex items are forced in a single line or can be flowed into multiple lines. If set to multiple lines, it also defines the cross-axis which determines the direction new lines are stacked in.
106
+ * See [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).
107
+ */
108
+ readonly flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
109
+ /**
110
+ * The align-items property defines the default behavior for how items are laid out along the cross axis (perpendicular to the main axis).
111
+ * See [align-items](https://css-tricks.com/almanac/properties/a/align-items/).
112
+ */
113
+ readonly alignItems?: 'flex-start' | 'center' | 'flex-end' | 'stretch';
114
+ /**
115
+ * It makes possible to override the align-items value for specific flex items.
116
+ * See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
117
+ */
118
+ readonly alignSelf?: 'flex-start' | 'center' | 'flex-end' | 'auto';
119
+ /**
120
+ * It defines the alignment along the main axis.
121
+ * See [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).
122
+ */
123
+ readonly justifyContent?: 'flex-start' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly' | 'center';
124
+ /**
125
+ * Width of the element in spaces.
126
+ * You can also set it in percent, which will calculate the width based on the width of parent element.
127
+ */
128
+ readonly width?: number | string;
129
+ /**
130
+ * Height of the element in lines (rows).
131
+ * You can also set it in percent, which will calculate the height based on the height of parent element.
132
+ */
133
+ readonly height?: number | string;
134
+ /**
135
+ * Sets a minimum width of the element.
136
+ */
137
+ readonly minWidth?: number | string;
138
+ /**
139
+ * Sets a minimum height of the element.
140
+ */
141
+ readonly minHeight?: number | string;
142
+ /**
143
+ * Set this property to `none` to hide the element.
144
+ */
145
+ readonly display?: 'flex' | 'none';
146
+ /**
147
+ * Add a border with a specified style.
148
+ * If `borderStyle` is `undefined` (which it is by default), no border will be added.
149
+ */
150
+ readonly borderStyle?: keyof Boxes | BoxStyle;
151
+ /**
152
+ * Determines whether top border is visible.
153
+ *
154
+ * @default true
155
+ */
156
+ readonly borderTop?: boolean;
157
+ /**
158
+ * Determines whether bottom border is visible.
159
+ *
160
+ * @default true
161
+ */
162
+ readonly borderBottom?: boolean;
163
+ /**
164
+ * Determines whether left border is visible.
165
+ *
166
+ * @default true
167
+ */
168
+ readonly borderLeft?: boolean;
169
+ /**
170
+ * Determines whether right border is visible.
171
+ *
172
+ * @default true
173
+ */
174
+ readonly borderRight?: boolean;
175
+ /**
176
+ * Change border color.
177
+ * Shorthand for setting `borderTopColor`, `borderRightColor`, `borderBottomColor` and `borderLeftColor`.
178
+ */
179
+ readonly borderColor?: LiteralUnion<ForegroundColorName, string>;
180
+ /**
181
+ * Change top border color.
182
+ * Accepts the same values as `color` in `Text` component.
183
+ */
184
+ readonly borderTopColor?: LiteralUnion<ForegroundColorName, string>;
185
+ /**
186
+ * Change bottom border color.
187
+ * Accepts the same values as `color` in `Text` component.
188
+ */
189
+ readonly borderBottomColor?: LiteralUnion<ForegroundColorName, string>;
190
+ /**
191
+ * Change left border color.
192
+ * Accepts the same values as `color` in `Text` component.
193
+ */
194
+ readonly borderLeftColor?: LiteralUnion<ForegroundColorName, string>;
195
+ /**
196
+ * Change right border color.
197
+ * Accepts the same values as `color` in `Text` component.
198
+ */
199
+ readonly borderRightColor?: LiteralUnion<ForegroundColorName, string>;
200
+ /**
201
+ * Dim the border color.
202
+ * Shorthand for setting `borderTopDimColor`, `borderBottomDimColor`, `borderLeftDimColor` and `borderRightDimColor`.
203
+ *
204
+ * @default false
205
+ */
206
+ readonly borderDimColor?: boolean;
207
+ /**
208
+ * Dim the top border color.
209
+ *
210
+ * @default false
211
+ */
212
+ readonly borderTopDimColor?: boolean;
213
+ /**
214
+ * Dim the bottom border color.
215
+ *
216
+ * @default false
217
+ */
218
+ readonly borderBottomDimColor?: boolean;
219
+ /**
220
+ * Dim the left border color.
221
+ *
222
+ * @default false
223
+ */
224
+ readonly borderLeftDimColor?: boolean;
225
+ /**
226
+ * Dim the right border color.
227
+ *
228
+ * @default false
229
+ */
230
+ readonly borderRightDimColor?: boolean;
231
+ /**
232
+ * Behavior for an element's overflow in both directions.
233
+ *
234
+ * @default 'visible'
235
+ */
236
+ readonly overflow?: 'visible' | 'hidden';
237
+ /**
238
+ * Behavior for an element's overflow in horizontal direction.
239
+ *
240
+ * @default 'visible'
241
+ */
242
+ readonly overflowX?: 'visible' | 'hidden';
243
+ /**
244
+ * Behavior for an element's overflow in vertical direction.
245
+ *
246
+ * @default 'visible'
247
+ */
248
+ readonly overflowY?: 'visible' | 'hidden';
249
+ };
250
+
251
+ interface BoxProps extends Styles {
252
+ }
253
+ declare const Box: FunctionalComponent<BoxProps>;
254
+
255
+ interface NewLineProps {
256
+ count?: number;
257
+ }
258
+ declare const NewLine: FunctionalComponent<NewLineProps>;
259
+
260
+ interface TextProps {
261
+ /**
262
+ * Change text color. Ink uses chalk under the hood, so all its functionality is supported.
263
+ */
264
+ readonly color?: LiteralUnion<ForegroundColorName$1, string>;
265
+ /**
266
+ * Same as `color`, but for background.
267
+ */
268
+ readonly backgroundColor?: LiteralUnion<ForegroundColorName$1, string>;
269
+ /**
270
+ * Dim the color (emit a small amount of light).
271
+ */
272
+ readonly dimColor?: boolean;
273
+ /**
274
+ * Make the text bold.
275
+ */
276
+ readonly bold?: boolean;
277
+ /**
278
+ * Make the text italic.
279
+ */
280
+ readonly italic?: boolean;
281
+ /**
282
+ * Make the text underlined.
283
+ */
284
+ readonly underline?: boolean;
285
+ /**
286
+ * Make the text crossed with a line.
287
+ */
288
+ readonly strikethrough?: boolean;
289
+ /**
290
+ * Inverse background and foreground colors.
291
+ */
292
+ readonly inverse?: boolean;
293
+ /**
294
+ * This property tells Ink to wrap or truncate text if its width is larger than container.
295
+ * If `wrap` is passed (by default), Ink will wrap text and split it into multiple lines.
296
+ * If `truncate-*` is passed, Ink will truncate text instead, which will result in one line of text with the rest cut off.
297
+ */
298
+ readonly wrap?: Styles['textWrap'];
299
+ }
300
+ declare const Text: FunctionalComponent<TextProps>;
301
+
302
+ interface ProgressBarProps {
303
+ value: number;
304
+ min?: number;
305
+ max?: number;
306
+ color?: TextProps['color'];
307
+ backgroundColor?: TextProps['backgroundColor'];
308
+ showPercent?: boolean;
309
+ variant?: Styles['borderStyle'];
310
+ }
311
+ declare const ProgressBar: vue.DefineSetupFnComponent<ProgressBarProps, {}, {}, ProgressBarProps & {}, vue.PublicProps>;
312
+
313
+ /**
314
+ * Basic node tree implementation
315
+ */
316
+ declare class NodeTree<T extends NodeTree<T>> extends EventEmitter {
317
+ readonly nodeName: string;
318
+ parentNode: T | null;
319
+ childNodes: T[];
320
+ getDisplayName(): string;
321
+ getDisplayData(): Record<string, any>;
322
+ toJSON(): any;
323
+ get lastChild(): T | null;
324
+ get firstChild(): T | null;
325
+ get nextSibling(): T | null;
326
+ get previousSibling(): T | null;
327
+ appendChild(node: T): void;
328
+ removeChild(node: T): void;
329
+ insertBefore(child: T, ref?: T | null): void;
330
+ remove(): void;
331
+ /** @internal */
332
+ destroy(): void;
333
+ }
334
+
335
+ declare enum DOMNodeType {
336
+ DOCUMENT = 0,
337
+ ELEMENT_NODE = 1,
338
+ TEXT_NODE = 3,
339
+ COMMENT_NODE = 8
340
+ }
341
+ interface DOMRect {
342
+ height: number;
343
+ width: number;
344
+ x: number;
345
+ y: number;
346
+ }
347
+ declare class DOMNode extends NodeTree<DOMNode> {
348
+ readonly id: number;
349
+ readonly nodeType: DOMNodeType;
350
+ readonly nodeName: string;
351
+ /** @internal */
352
+ computedBoundingClientRect: DOMRect;
353
+ /** @internal */
354
+ root: DOMDocument | null;
355
+ constructor();
356
+ insertBefore(child: DOMNode, ref?: DOMNode | null | undefined): void;
357
+ remove(): void;
358
+ setRootDocument(document: DOMDocument | null): void;
359
+ getBoundingClientRect(): DOMRect;
360
+ getDisplayData(): Record<string, any>;
361
+ emitRoot(eventName: string, ...args: any[]): void;
362
+ get textContent(): string | null;
363
+ set textContent(value: string | null);
364
+ }
365
+
366
+ declare class DOMComment extends DOMNode {
367
+ readonly nodeType: DOMNodeType.COMMENT_NODE;
368
+ readonly nodeName: string;
369
+ /** @internal */
370
+ textValue: string | null;
371
+ constructor(data?: string | null);
372
+ get textContent(): string | null;
373
+ set textContent(value: string | null);
374
+ getDisplayData(): Record<string, any>;
375
+ }
376
+
377
+ declare class DOMElement extends DOMNode {
378
+ readonly nodeType: DOMNodeType.ELEMENT_NODE;
379
+ readonly nodeName: string;
380
+ readonly tagName: string;
381
+ readonly attributes: Record<string, any>;
382
+ constructor(tagName: string);
383
+ getDisplayName(): string;
384
+ getDisplayData(): any;
385
+ getAttribute(name: string): any;
386
+ setAttribute(name: string, value: any): void;
387
+ removeAttribute(name: string): void;
388
+ set textContent(value: string);
389
+ get textContent(): string;
390
+ }
391
+
392
+ declare class DOMText extends DOMNode {
393
+ readonly nodeType = DOMNodeType.TEXT_NODE;
394
+ readonly nodeName: string;
395
+ /** @internal */
396
+ textValue: string | null;
397
+ constructor(data?: string | null);
398
+ get textContent(): string | null;
399
+ set textContent(value: string | null);
400
+ getDisplayData(): any;
401
+ getDisplayName(): string;
402
+ }
403
+
404
+ declare class DOMDocument extends DOMNode {
405
+ readonly nodeType: DOMNodeType.DOCUMENT;
406
+ readonly nodeName: string;
407
+ static createDocument(): DOMDocument;
408
+ static createTextNode(data?: string): DOMText;
409
+ static createComment(data?: string): DOMComment;
410
+ static createElement(tagName: string): DOMElement;
411
+ insertBefore(child: DOMNode, ref?: DOMNode | null | undefined): void;
412
+ get treeText(): string;
413
+ }
414
+
415
+ type OutputTransformer = (s: string, index: number) => string;
416
+ /**
417
+ * "Virtual" output class
418
+ *
419
+ * Handles the positioning and saving of the output of each node in the tree.
420
+ * Also responsible for applying transformations to each character of the output.
421
+ *
422
+ * Used to generate the final output of all nodes before writing it to actual output stream (e.g. stdout)
423
+ */
424
+ type Options = {
425
+ width: number;
426
+ height: number;
427
+ };
428
+ type Clip = {
429
+ x1: number | undefined;
430
+ x2: number | undefined;
431
+ y1: number | undefined;
432
+ y2: number | undefined;
433
+ };
434
+ declare class Layer {
435
+ width: number;
436
+ height: number;
437
+ frame: string;
438
+ frameHeight: number;
439
+ private readonly operations;
440
+ constructor(options: Options);
441
+ write(x: number, y: number, text: string, options: {
442
+ transformers: OutputTransformer[];
443
+ }): void;
444
+ clip(clip: Clip): void;
445
+ unclip(): void;
446
+ compute(): void;
447
+ }
448
+
449
+ declare enum RenderNodeType {
450
+ NODE = 1,
451
+ BLOCK = 2,
452
+ INLINE = 3,
453
+ TEXT = 4
454
+ }
455
+ interface RenderNodeRect {
456
+ height: number;
457
+ width: number;
458
+ x: number;
459
+ y: number;
460
+ }
461
+ declare class RenderNode extends NodeTree<RenderNode> {
462
+ readonly id: number;
463
+ readonly nodeType: RenderNodeType;
464
+ readonly nodeName: string;
465
+ transformers: OutputTransformer[];
466
+ /** @internal */
467
+ domNode: DOMNode | null;
468
+ /** @internal */
469
+ yogaNode: Node;
470
+ realX: number;
471
+ realY: number;
472
+ constructor();
473
+ getDisplayName(): string;
474
+ getDisplayData(): Record<string, any>;
475
+ remove(): void;
476
+ destroy(): void;
477
+ insertBefore(child: RenderNode, ref?: RenderNode | null | undefined): void;
478
+ getComputedRect(): RenderNodeRect;
479
+ getContentRect(): RenderNodeRect;
480
+ renderToLayer(layer: Layer): void;
481
+ computeStyles(): void;
482
+ }
483
+
484
+ interface RenderFlowOptions {
485
+ document: DOMDocument;
486
+ width: number;
487
+ height: number;
488
+ }
489
+ declare class RenderFlow extends RenderNode {
490
+ /** @internal */
491
+ document: DOMDocument;
492
+ readonly nodeType: RenderNodeType;
493
+ readonly nodeName: string;
494
+ height: number;
495
+ width: number;
496
+ layer: Layer;
497
+ reflowScheduled: boolean;
498
+ constructor({ document, width, height }: RenderFlowOptions);
499
+ get treeText(): string;
500
+ /** @internal */
501
+ onDOMChanged(): void;
502
+ render(): string;
503
+ /** @internal */
504
+ renderNode(node: RenderNode): void;
505
+ reflow(): void;
506
+ reflowSchedule(): void;
507
+ /** @internal */
508
+ reflowNode(domNode: DOMNode, renderNode: RenderNode): void;
509
+ /** @internal */
510
+ reflowAsBlock(domNode: DOMNode, renderNode: RenderNode): void;
511
+ /** @internal */
512
+ reflowAsInline(domNode: DOMNode, renderNode: RenderNode): void;
513
+ }
514
+
515
+ interface ContainerOptions {
516
+ stdout: NodeJS.WriteStream;
517
+ stdin: NodeJS.ReadStream;
518
+ stderr: NodeJS.WriteStream;
519
+ debug: boolean;
520
+ exitOnCtrlC: boolean;
521
+ }
522
+ declare class Container extends DOMDocument {
523
+ tagName: string;
524
+ stdout: NodeJS.WriteStream;
525
+ stdin: NodeJS.ReadStream;
526
+ stderr: NodeJS.WriteStream;
527
+ exitOnCtrlC: boolean;
528
+ flow: RenderFlow;
529
+ write: (...args: any[]) => void;
530
+ constructor({ debug, exitOnCtrlC, stderr, stdin, stdout }: ContainerOptions);
531
+ onResize(): void;
532
+ onFrame(): void;
533
+ }
534
+ declare function createContainer(options?: Partial<ContainerOptions>): Container;
535
+
536
+ declare const DOM: Readonly<{
537
+ readonly Document: typeof DOMDocument;
538
+ readonly Text: typeof DOMText;
539
+ readonly Comment: typeof DOMComment;
540
+ readonly Element: typeof DOMElement;
541
+ readonly Node: typeof DOMNode;
542
+ readonly Type: typeof DOMNodeType;
543
+ readonly createDocument: typeof DOMDocument.createDocument;
544
+ readonly createComment: typeof DOMDocument.createComment;
545
+ readonly createTextNode: typeof DOMDocument.createTextNode;
546
+ readonly createElement: typeof DOMDocument.createElement;
547
+ }>;
548
+
549
+ declare const createApp: _vue_runtime_core.CreateAppFunction<DOMElement | DOMDocument>;
550
+
551
+ declare class RenderBlock extends RenderNode {
552
+ readonly nodeType: RenderNodeType;
553
+ readonly nodeName: string;
554
+ constructor();
555
+ renderToLayer(layer: Layer): void;
556
+ }
557
+
558
+ declare class RenderInline extends RenderNode {
559
+ readonly nodeType: RenderNodeType.INLINE;
560
+ readonly nodeName: string;
561
+ constructor();
562
+ }
563
+
564
+ declare class RenderText extends RenderNode {
565
+ readonly nodeType: RenderNodeType;
566
+ readonly nodeName: string;
567
+ constructor();
568
+ getDisplayName(): string;
569
+ /**
570
+ * Measure the dimensions of the text associated
571
+ * callback for css-layout
572
+ * @param: width - input width extents
573
+ * @param: widthMeasureMode - mode to constrain width CSS_MEASURE_MODE_EXACTLY, CSS_MEASURE_MODE_UNDEFINED
574
+ * @param: height - input height extents
575
+ * @param: heightMeasureMode - mode to constrain height CSS_MEASURE_MODE_EXACTLY, CSS_MEASURE_MODE_UNDEFINED
576
+ * @return: object containing measured width and height
577
+ */
578
+ measure(width: number, widthMeasureMode: number, height: number, heightMeasureMode: number): {
579
+ width: number;
580
+ height: number;
581
+ };
582
+ getTextWrapStyle(): any;
583
+ static measureText: _andrew_l_toolkit.WithCacheResult<(text: string) => {
584
+ width: number;
585
+ height: number;
586
+ }>;
587
+ renderToLayer(layer: Layer): void;
588
+ computeStyles(): void;
589
+ }
590
+
591
+ declare const Render: Readonly<{
592
+ readonly Flow: typeof RenderFlow;
593
+ readonly Block: typeof RenderBlock;
594
+ readonly Inline: typeof RenderInline;
595
+ readonly RenderText: typeof RenderText;
596
+ readonly Type: typeof RenderNodeType;
597
+ }>;
598
+
599
+ declare function useContainerSize(target: MaybeRefOrGetter<DOMElement | null>): {
600
+ width: vue.Ref<number, number>;
601
+ height: vue.Ref<number, number>;
602
+ };
603
+
604
+ declare function useDOMElement(): ShallowRef<DOMElement | null>;
605
+
606
+ declare function useEventListener(target: MaybeRefOrGetter<DOMNode | null>, eventName: string, listener: AnyFunction): Fn;
607
+
608
+ export { Box, type BoxProps, DOM, DOMComment, DOMDocument, DOMElement, DOMNode, DOMNodeType, DOMText, NewLine, type NewLineProps, ProgressBar, type ProgressBarProps, Render, Text, type TextProps, createApp, createContainer, useContainerSize, useDOMElement, useEventListener };