@jrichman/ink 6.3.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.
- package/build/colorize.d.ts +3 -0
- package/build/colorize.js +48 -0
- package/build/colorize.js.map +1 -0
- package/build/components/AccessibilityContext.d.ts +3 -0
- package/build/components/AccessibilityContext.js +5 -0
- package/build/components/AccessibilityContext.js.map +1 -0
- package/build/components/App.d.ts +59 -0
- package/build/components/App.js +286 -0
- package/build/components/App.js.map +1 -0
- package/build/components/AppContext.d.ts +11 -0
- package/build/components/AppContext.js +11 -0
- package/build/components/AppContext.js.map +1 -0
- package/build/components/BackgroundContext.d.ts +4 -0
- package/build/components/BackgroundContext.js +3 -0
- package/build/components/BackgroundContext.js.map +1 -0
- package/build/components/Box.d.ts +122 -0
- package/build/components/Box.js +34 -0
- package/build/components/Box.js.map +1 -0
- package/build/components/ErrorOverview.d.ts +6 -0
- package/build/components/ErrorOverview.js +84 -0
- package/build/components/ErrorOverview.js.map +1 -0
- package/build/components/FocusContext.d.ts +16 -0
- package/build/components/FocusContext.js +17 -0
- package/build/components/FocusContext.js.map +1 -0
- package/build/components/Newline.d.ts +13 -0
- package/build/components/Newline.js +8 -0
- package/build/components/Newline.js.map +1 -0
- package/build/components/Spacer.d.ts +7 -0
- package/build/components/Spacer.js +11 -0
- package/build/components/Spacer.js.map +1 -0
- package/build/components/Static.d.ts +24 -0
- package/build/components/Static.js +28 -0
- package/build/components/Static.js.map +1 -0
- package/build/components/StderrContext.d.ts +15 -0
- package/build/components/StderrContext.js +13 -0
- package/build/components/StderrContext.js.map +1 -0
- package/build/components/StdinContext.d.ts +22 -0
- package/build/components/StdinContext.js +19 -0
- package/build/components/StdinContext.js.map +1 -0
- package/build/components/StdoutContext.d.ts +15 -0
- package/build/components/StdoutContext.js +13 -0
- package/build/components/StdoutContext.js.map +1 -0
- package/build/components/Text.d.ts +55 -0
- package/build/components/Text.js +50 -0
- package/build/components/Text.js.map +1 -0
- package/build/components/Transform.d.ts +16 -0
- package/build/components/Transform.js +15 -0
- package/build/components/Transform.js.map +1 -0
- package/build/devtools-window-polyfill.d.ts +1 -0
- package/build/devtools-window-polyfill.js +65 -0
- package/build/devtools-window-polyfill.js.map +1 -0
- package/build/devtools.d.ts +1 -0
- package/build/devtools.js +2 -0
- package/build/devtools.js.map +1 -0
- package/build/dom.d.ts +62 -0
- package/build/dom.js +123 -0
- package/build/dom.js.map +1 -0
- package/build/get-max-width.d.ts +3 -0
- package/build/get-max-width.js +10 -0
- package/build/get-max-width.js.map +1 -0
- package/build/hooks/use-app.d.ts +5 -0
- package/build/hooks/use-app.js +8 -0
- package/build/hooks/use-app.js.map +1 -0
- package/build/hooks/use-focus-manager.d.ts +28 -0
- package/build/hooks/use-focus-manager.js +17 -0
- package/build/hooks/use-focus-manager.js.map +1 -0
- package/build/hooks/use-focus.d.ts +29 -0
- package/build/hooks/use-focus.js +42 -0
- package/build/hooks/use-focus.js.map +1 -0
- package/build/hooks/use-input.d.ts +93 -0
- package/build/hooks/use-input.js +93 -0
- package/build/hooks/use-input.js.map +1 -0
- package/build/hooks/use-is-screen-reader-enabled.d.ts +5 -0
- package/build/hooks/use-is-screen-reader-enabled.js +11 -0
- package/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
- package/build/hooks/use-stderr.d.ts +5 -0
- package/build/hooks/use-stderr.js +8 -0
- package/build/hooks/use-stderr.js.map +1 -0
- package/build/hooks/use-stdin.d.ts +5 -0
- package/build/hooks/use-stdin.js +8 -0
- package/build/hooks/use-stdin.js.map +1 -0
- package/build/hooks/use-stdout.d.ts +5 -0
- package/build/hooks/use-stdout.js +8 -0
- package/build/hooks/use-stdout.js.map +1 -0
- package/build/index.d.ts +28 -0
- package/build/index.js +17 -0
- package/build/index.js.map +1 -0
- package/build/ink.d.ts +43 -0
- package/build/ink.js +315 -0
- package/build/ink.js.map +1 -0
- package/build/instances.d.ts +3 -0
- package/build/instances.js +8 -0
- package/build/instances.js.map +1 -0
- package/build/log-update.d.ts +15 -0
- package/build/log-update.js +109 -0
- package/build/log-update.js.map +1 -0
- package/build/measure-element.d.ts +38 -0
- package/build/measure-element.js +118 -0
- package/build/measure-element.js.map +1 -0
- package/build/measure-text.d.ts +6 -0
- package/build/measure-text.js +21 -0
- package/build/measure-text.js.map +1 -0
- package/build/output.d.ts +36 -0
- package/build/output.js +191 -0
- package/build/output.js.map +1 -0
- package/build/parse-keypress.d.ts +14 -0
- package/build/parse-keypress.js +225 -0
- package/build/parse-keypress.js.map +1 -0
- package/build/reconciler.d.ts +4 -0
- package/build/reconciler.js +254 -0
- package/build/reconciler.js.map +1 -0
- package/build/render-background.d.ts +4 -0
- package/build/render-background.js +25 -0
- package/build/render-background.js.map +1 -0
- package/build/render-border.d.ts +4 -0
- package/build/render-border.js +73 -0
- package/build/render-border.js.map +1 -0
- package/build/render-node-to-output.d.ts +14 -0
- package/build/render-node-to-output.js +296 -0
- package/build/render-node-to-output.js.map +1 -0
- package/build/render.d.ts +87 -0
- package/build/render.js +50 -0
- package/build/render.js.map +1 -0
- package/build/renderer.d.ts +8 -0
- package/build/renderer.js +55 -0
- package/build/renderer.js.map +1 -0
- package/build/scroll.d.ts +8 -0
- package/build/scroll.js +35 -0
- package/build/scroll.js.map +1 -0
- package/build/squash-text-nodes.d.ts +3 -0
- package/build/squash-text-nodes.js +35 -0
- package/build/squash-text-nodes.js.map +1 -0
- package/build/styles.d.ts +260 -0
- package/build/styles.js +257 -0
- package/build/styles.js.map +1 -0
- package/build/wrap-text.d.ts +3 -0
- package/build/wrap-text.js +31 -0
- package/build/wrap-text.js.map +1 -0
- package/license +9 -0
- package/package.json +194 -0
- package/readme.md +2331 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import widestLine from 'widest-line';
|
|
2
|
+
import indentString from 'indent-string';
|
|
3
|
+
import Yoga from 'yoga-layout';
|
|
4
|
+
import wrapText from './wrap-text.js';
|
|
5
|
+
import getMaxWidth from './get-max-width.js';
|
|
6
|
+
import squashTextNodes from './squash-text-nodes.js';
|
|
7
|
+
import renderBorder from './render-border.js';
|
|
8
|
+
import renderBackground from './render-background.js';
|
|
9
|
+
import { getScrollHeight, getScrollWidth } from './measure-element.js';
|
|
10
|
+
import colorize from './colorize.js';
|
|
11
|
+
// If parent container is `<Box>`, text nodes will be treated as separate nodes in
|
|
12
|
+
// the tree and will have their own coordinates in the layout.
|
|
13
|
+
// To ensure text nodes are aligned correctly, take X and Y of the first text node
|
|
14
|
+
// and use it as offset for the rest of the nodes
|
|
15
|
+
// Only first node is taken into account, because other text nodes can't have margin or padding,
|
|
16
|
+
// so their coordinates will be relative to the first node anyway
|
|
17
|
+
const applyPaddingToText = (node, text) => {
|
|
18
|
+
const yogaNode = node.childNodes[0]?.yogaNode;
|
|
19
|
+
if (yogaNode) {
|
|
20
|
+
const offsetX = yogaNode.getComputedLeft();
|
|
21
|
+
const offsetY = yogaNode.getComputedTop();
|
|
22
|
+
text = '\n'.repeat(offsetY) + indentString(text, offsetX);
|
|
23
|
+
}
|
|
24
|
+
return text;
|
|
25
|
+
};
|
|
26
|
+
export const renderNodeToScreenReaderOutput = (node, options = {}) => {
|
|
27
|
+
if (options.skipStaticElements && node.internal_static) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
if (node.yogaNode?.getDisplay() === Yoga.DISPLAY_NONE) {
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
let output = '';
|
|
34
|
+
if (node.nodeName === 'ink-text') {
|
|
35
|
+
output = squashTextNodes(node);
|
|
36
|
+
}
|
|
37
|
+
else if (node.nodeName === 'ink-box' || node.nodeName === 'ink-root') {
|
|
38
|
+
const separator = node.style.flexDirection === 'row' ||
|
|
39
|
+
node.style.flexDirection === 'row-reverse'
|
|
40
|
+
? ' '
|
|
41
|
+
: '\n';
|
|
42
|
+
const childNodes = node.style.flexDirection === 'row-reverse' ||
|
|
43
|
+
node.style.flexDirection === 'column-reverse'
|
|
44
|
+
? [...node.childNodes].reverse()
|
|
45
|
+
: [...node.childNodes];
|
|
46
|
+
output = childNodes
|
|
47
|
+
.map(childNode => {
|
|
48
|
+
const screenReaderOutput = renderNodeToScreenReaderOutput(childNode, {
|
|
49
|
+
parentRole: node.internal_accessibility?.role,
|
|
50
|
+
skipStaticElements: options.skipStaticElements,
|
|
51
|
+
});
|
|
52
|
+
return screenReaderOutput;
|
|
53
|
+
})
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.join(separator);
|
|
56
|
+
}
|
|
57
|
+
if (node.internal_accessibility) {
|
|
58
|
+
const { role, state } = node.internal_accessibility;
|
|
59
|
+
if (state) {
|
|
60
|
+
const stateKeys = Object.keys(state);
|
|
61
|
+
const stateDescription = stateKeys.filter(key => state[key]).join(', ');
|
|
62
|
+
if (stateDescription) {
|
|
63
|
+
output = `(${stateDescription}) ${output}`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (role && role !== options.parentRole) {
|
|
67
|
+
output = `${role}: ${output}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return output;
|
|
71
|
+
};
|
|
72
|
+
// After nodes are laid out, render each to output object, which later gets rendered to terminal
|
|
73
|
+
const renderNodeToOutput = (node, output, options) => {
|
|
74
|
+
const { offsetX = 0, offsetY = 0, transformers = [], skipStaticElements, } = options;
|
|
75
|
+
if (skipStaticElements && node.internal_static) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const { yogaNode } = node;
|
|
79
|
+
if (yogaNode) {
|
|
80
|
+
if (yogaNode.getDisplay() === Yoga.DISPLAY_NONE) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Left and top positions in Yoga are relative to their parent node
|
|
84
|
+
const x = offsetX + yogaNode.getComputedLeft();
|
|
85
|
+
const y = offsetY + yogaNode.getComputedTop();
|
|
86
|
+
// Transformers are functions that transform final text output of each component
|
|
87
|
+
// See Output class for logic that applies transformers
|
|
88
|
+
let newTransformers = transformers;
|
|
89
|
+
if (typeof node.internal_transform === 'function') {
|
|
90
|
+
newTransformers = [node.internal_transform, ...transformers];
|
|
91
|
+
}
|
|
92
|
+
if (node.nodeName === 'ink-text') {
|
|
93
|
+
let text = squashTextNodes(node);
|
|
94
|
+
if (text.length > 0) {
|
|
95
|
+
const currentWidth = widestLine(text);
|
|
96
|
+
const maxWidth = getMaxWidth(yogaNode);
|
|
97
|
+
if (currentWidth > maxWidth) {
|
|
98
|
+
const textWrap = node.style.textWrap ?? 'wrap';
|
|
99
|
+
text = wrapText(text, maxWidth, textWrap);
|
|
100
|
+
}
|
|
101
|
+
text = applyPaddingToText(node, text);
|
|
102
|
+
output.write(x, y, text, { transformers: newTransformers });
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let clipped = false;
|
|
107
|
+
let childrenOffsetY = y;
|
|
108
|
+
let childrenOffsetX = x;
|
|
109
|
+
let verticallyScrollable = false;
|
|
110
|
+
let horizontallyScrollable = false;
|
|
111
|
+
let isVerticalScrollbarVisible = false;
|
|
112
|
+
if (node.nodeName === 'ink-box') {
|
|
113
|
+
renderBackground(x, y, node, output);
|
|
114
|
+
renderBorder(x, y, node, output);
|
|
115
|
+
const overflow = node.style.overflow ?? 'visible';
|
|
116
|
+
const overflowX = node.style.overflowX ?? overflow;
|
|
117
|
+
const overflowY = node.style.overflowY ?? overflow;
|
|
118
|
+
verticallyScrollable = overflowY === 'scroll';
|
|
119
|
+
horizontallyScrollable = overflowX === 'scroll';
|
|
120
|
+
if (verticallyScrollable) {
|
|
121
|
+
calculateVerticalScroll(node);
|
|
122
|
+
childrenOffsetY -= node.internal_scrollTop ?? 0;
|
|
123
|
+
}
|
|
124
|
+
if (horizontallyScrollable) {
|
|
125
|
+
calculateHorizontalScroll(node);
|
|
126
|
+
childrenOffsetX -= node.internal_scrollLeft ?? 0;
|
|
127
|
+
}
|
|
128
|
+
isVerticalScrollbarVisible =
|
|
129
|
+
verticallyScrollable &&
|
|
130
|
+
(node.internal_scrollHeight ?? 0) > (node.internal_clientHeight ?? 0);
|
|
131
|
+
const clipHorizontally = overflowX === 'hidden' || overflowX === 'scroll';
|
|
132
|
+
const clipVertically = overflowY === 'hidden' || overflowY === 'scroll';
|
|
133
|
+
if (clipHorizontally || clipVertically) {
|
|
134
|
+
const x1 = clipHorizontally
|
|
135
|
+
? x + yogaNode.getComputedBorder(Yoga.EDGE_LEFT)
|
|
136
|
+
: undefined;
|
|
137
|
+
const x2 = clipHorizontally
|
|
138
|
+
? x +
|
|
139
|
+
yogaNode.getComputedWidth() -
|
|
140
|
+
yogaNode.getComputedBorder(Yoga.EDGE_RIGHT)
|
|
141
|
+
: undefined;
|
|
142
|
+
const y1 = clipVertically
|
|
143
|
+
? y + yogaNode.getComputedBorder(Yoga.EDGE_TOP)
|
|
144
|
+
: undefined;
|
|
145
|
+
const y2 = clipVertically
|
|
146
|
+
? y +
|
|
147
|
+
yogaNode.getComputedHeight() -
|
|
148
|
+
yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM)
|
|
149
|
+
: undefined;
|
|
150
|
+
output.clip({ x1, x2, y1, y2 });
|
|
151
|
+
clipped = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (node.nodeName === 'ink-root' || node.nodeName === 'ink-box') {
|
|
155
|
+
for (const childNode of node.childNodes) {
|
|
156
|
+
renderNodeToOutput(childNode, output, {
|
|
157
|
+
offsetX: childrenOffsetX,
|
|
158
|
+
offsetY: childrenOffsetY,
|
|
159
|
+
transformers: newTransformers,
|
|
160
|
+
skipStaticElements,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (clipped) {
|
|
164
|
+
output.unclip();
|
|
165
|
+
}
|
|
166
|
+
if (node.nodeName === 'ink-box') {
|
|
167
|
+
if (verticallyScrollable) {
|
|
168
|
+
renderVerticalScrollbar(node, x, y, output);
|
|
169
|
+
}
|
|
170
|
+
if (horizontallyScrollable) {
|
|
171
|
+
renderHorizontalScrollbar(node, x, y, output, {
|
|
172
|
+
verticallyScrollable: isVerticalScrollbarVisible,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
function calculateVerticalScroll(node) {
|
|
180
|
+
const { yogaNode } = node;
|
|
181
|
+
if (!yogaNode) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const clientHeight = yogaNode.getComputedHeight() -
|
|
185
|
+
yogaNode.getComputedBorder(Yoga.EDGE_TOP) -
|
|
186
|
+
yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM);
|
|
187
|
+
const scrollHeight = getScrollHeight(node);
|
|
188
|
+
const scrollTop = Math.max(0, Math.min(node.style.scrollTop ?? 0, scrollHeight - clientHeight));
|
|
189
|
+
node.internal_scrollTop = scrollTop;
|
|
190
|
+
node.internal_scrollHeight = scrollHeight;
|
|
191
|
+
node.internal_clientHeight = clientHeight;
|
|
192
|
+
}
|
|
193
|
+
function calculateHorizontalScroll(node) {
|
|
194
|
+
const { yogaNode } = node;
|
|
195
|
+
if (!yogaNode) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const clientWidth = yogaNode.getComputedWidth() -
|
|
199
|
+
yogaNode.getComputedBorder(Yoga.EDGE_LEFT) -
|
|
200
|
+
yogaNode.getComputedBorder(Yoga.EDGE_RIGHT);
|
|
201
|
+
const scrollWidth = getScrollWidth(node);
|
|
202
|
+
let scrollLeft = node.style.scrollLeft ?? 0;
|
|
203
|
+
scrollLeft = Math.max(0, Math.min(scrollLeft, scrollWidth - clientWidth));
|
|
204
|
+
node.internal_scrollLeft = scrollLeft;
|
|
205
|
+
node.internal_scrollWidth = scrollWidth;
|
|
206
|
+
node.internal_clientWidth = clientWidth;
|
|
207
|
+
}
|
|
208
|
+
function renderScrollbar(node, x, y, output, axis, options = {}) {
|
|
209
|
+
const { yogaNode } = node;
|
|
210
|
+
if (!yogaNode) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const clientDimension = axis === 'vertical'
|
|
214
|
+
? (node.internal_clientHeight ?? 0)
|
|
215
|
+
: (node.internal_clientWidth ?? 0);
|
|
216
|
+
const scrollDimension = axis === 'vertical'
|
|
217
|
+
? (node.internal_scrollHeight ?? 0)
|
|
218
|
+
: (node.internal_scrollWidth ?? 0);
|
|
219
|
+
const scrollPosition = axis === 'vertical'
|
|
220
|
+
? (node.internal_scrollTop ?? 0)
|
|
221
|
+
: (node.internal_scrollLeft ?? 0);
|
|
222
|
+
if (scrollDimension <= clientDimension) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const scrollbarX = axis === 'vertical'
|
|
226
|
+
? x +
|
|
227
|
+
yogaNode.getComputedWidth() -
|
|
228
|
+
1 -
|
|
229
|
+
yogaNode.getComputedBorder(Yoga.EDGE_RIGHT)
|
|
230
|
+
: x + yogaNode.getComputedBorder(Yoga.EDGE_LEFT);
|
|
231
|
+
const scrollbarY = axis === 'vertical'
|
|
232
|
+
? y + yogaNode.getComputedBorder(Yoga.EDGE_TOP)
|
|
233
|
+
: y +
|
|
234
|
+
yogaNode.getComputedHeight() -
|
|
235
|
+
1 -
|
|
236
|
+
yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM);
|
|
237
|
+
const scrollbarDimension = axis === 'vertical'
|
|
238
|
+
? yogaNode.getComputedHeight() -
|
|
239
|
+
yogaNode.getComputedBorder(Yoga.EDGE_TOP) -
|
|
240
|
+
yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM)
|
|
241
|
+
: yogaNode.getComputedWidth() -
|
|
242
|
+
yogaNode.getComputedBorder(Yoga.EDGE_LEFT) -
|
|
243
|
+
yogaNode.getComputedBorder(Yoga.EDGE_RIGHT) -
|
|
244
|
+
(options.verticallyScrollable ? 1 : 0);
|
|
245
|
+
if (scrollbarDimension <= 0) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const scrollbarDimensionHalves = scrollbarDimension * 2;
|
|
249
|
+
const thumbDimensionHalves = Math.max(axis === 'vertical' ? 2 : 1, Math.round((clientDimension / scrollDimension) * scrollbarDimensionHalves));
|
|
250
|
+
const maxScrollPosition = scrollDimension - clientDimension;
|
|
251
|
+
const maxThumbPosition = scrollbarDimensionHalves - thumbDimensionHalves;
|
|
252
|
+
const thumbPosition = maxScrollPosition > 0
|
|
253
|
+
? Math.round((scrollPosition / maxScrollPosition) * maxThumbPosition)
|
|
254
|
+
: 0;
|
|
255
|
+
const thumbColor = node.style.scrollbarThumbColor;
|
|
256
|
+
const thumbStartHalf = thumbPosition;
|
|
257
|
+
const thumbEndHalf = thumbPosition + thumbDimensionHalves;
|
|
258
|
+
const startIndex = Math.floor(thumbStartHalf / 2);
|
|
259
|
+
const endIndex = Math.min(scrollbarDimension, Math.ceil(thumbEndHalf / 2));
|
|
260
|
+
for (let index = startIndex; index < endIndex; index++) {
|
|
261
|
+
const cellStartHalf = index * 2;
|
|
262
|
+
const cellEndHalf = (index + 1) * 2;
|
|
263
|
+
const start = Math.max(cellStartHalf, thumbStartHalf);
|
|
264
|
+
const end = Math.min(cellEndHalf, thumbEndHalf);
|
|
265
|
+
const fill = end - start;
|
|
266
|
+
if (fill > 0) {
|
|
267
|
+
const char = axis === 'vertical'
|
|
268
|
+
? fill === 2
|
|
269
|
+
? '█'
|
|
270
|
+
: // Fill === 1
|
|
271
|
+
start % 2 === 0
|
|
272
|
+
? '▀' // Top half of the cell is filled
|
|
273
|
+
: '▄' // Bottom half of the cell is filled
|
|
274
|
+
: fill === 2
|
|
275
|
+
? '█'
|
|
276
|
+
: // Fill === 1
|
|
277
|
+
start % 2 === 0
|
|
278
|
+
? '▌' // Left half of the cell is filled
|
|
279
|
+
: '▐'; // Right half of the cell is filled
|
|
280
|
+
const outputX = axis === 'vertical' ? scrollbarX : scrollbarX + index;
|
|
281
|
+
const outputY = axis === 'vertical' ? scrollbarY + index : scrollbarY;
|
|
282
|
+
output.write(outputX, outputY, colorize(colorize(char, thumbColor, 'foreground'), node.style.backgroundColor, 'background'), { transformers: [] });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function renderVerticalScrollbar(node, x, y, output) {
|
|
287
|
+
renderScrollbar(node, x, y, output, 'vertical');
|
|
288
|
+
}
|
|
289
|
+
// eslint-disable-next-line max-params
|
|
290
|
+
function renderHorizontalScrollbar(node, x, y, output, { verticallyScrollable }) {
|
|
291
|
+
renderScrollbar(node, x, y, output, 'horizontal', {
|
|
292
|
+
verticallyScrollable,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
export default renderNodeToOutput;
|
|
296
|
+
//# sourceMappingURL=render-node-to-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-node-to-output.js","sourceRoot":"","sources":["../src/render-node-to-output.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,eAAe,MAAM,wBAAwB,CAAC;AACrD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,gBAAgB,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAErE,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,kFAAkF;AAClF,8DAA8D;AAC9D,kFAAkF;AAClF,iDAAiD;AACjD,gGAAgG;AAChG,iEAAiE;AACjE,MAAM,kBAAkB,GAAG,CAAC,IAAgB,EAAE,IAAY,EAAU,EAAE;IACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;IAE9C,IAAI,QAAQ,EAAE,CAAC;QACd,MAAM,OAAO,GAAG,QAAQ,CAAC,eAAe,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AAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC;AAED,sCAAsC;AACtC,SAAS,yBAAyB,CACjC,IAAgB,EAChB,CAAS,EACT,CAAS,EACT,MAAc,EACd,EAAC,oBAAoB,EAAkC;IAEvD,eAAe,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE;QACjD,oBAAoB;KACpB,CAAC,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import Ink from './ink.js';
|
|
3
|
+
export type RenderOptions = {
|
|
4
|
+
/**
|
|
5
|
+
Output stream where app will be rendered.
|
|
6
|
+
|
|
7
|
+
@default process.stdout
|
|
8
|
+
*/
|
|
9
|
+
stdout?: NodeJS.WriteStream;
|
|
10
|
+
/**
|
|
11
|
+
Input stream where app will listen for input.
|
|
12
|
+
|
|
13
|
+
@default process.stdin
|
|
14
|
+
*/
|
|
15
|
+
stdin?: NodeJS.ReadStream;
|
|
16
|
+
/**
|
|
17
|
+
Error stream.
|
|
18
|
+
@default process.stderr
|
|
19
|
+
*/
|
|
20
|
+
stderr?: NodeJS.WriteStream;
|
|
21
|
+
/**
|
|
22
|
+
If true, each update will be rendered as separate output, without replacing the previous one.
|
|
23
|
+
|
|
24
|
+
@default false
|
|
25
|
+
*/
|
|
26
|
+
debug?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
Configure whether Ink should listen for Ctrl+C keyboard input and exit the app. This is needed in case `process.stdin` is in raw mode, because then Ctrl+C is ignored by default and the process is expected to handle it manually.
|
|
29
|
+
|
|
30
|
+
@default true
|
|
31
|
+
*/
|
|
32
|
+
exitOnCtrlC?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
Patch console methods to ensure console output doesn't mix with Ink's output.
|
|
35
|
+
|
|
36
|
+
@default true
|
|
37
|
+
*/
|
|
38
|
+
patchConsole?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
Function to call after each render.
|
|
41
|
+
*/
|
|
42
|
+
onRender?: (renderTime: number) => void;
|
|
43
|
+
/**
|
|
44
|
+
Enable screen reader support. See https://github.com/vadimdemedes/ink/blob/master/readme.md#screen-reader-support
|
|
45
|
+
|
|
46
|
+
@default process.env['INK_SCREEN_READER'] === 'true'
|
|
47
|
+
*/
|
|
48
|
+
isScreenReaderEnabled?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
Maximum frames per second for render updates.
|
|
51
|
+
This controls how frequently the UI can update to prevent excessive re-rendering.
|
|
52
|
+
Higher values allow more frequent updates but may impact performance.
|
|
53
|
+
|
|
54
|
+
@default 30
|
|
55
|
+
*/
|
|
56
|
+
maxFps?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Render the app in an alternate screen buffer.
|
|
59
|
+
* This is useful for fullscreen applications.
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
alternateBuffer?: boolean;
|
|
63
|
+
};
|
|
64
|
+
export type Instance = {
|
|
65
|
+
/**
|
|
66
|
+
Replace the previous root node with a new one or update props of the current root node.
|
|
67
|
+
*/
|
|
68
|
+
rerender: Ink['render'];
|
|
69
|
+
/**
|
|
70
|
+
Manually unmount the whole Ink app.
|
|
71
|
+
*/
|
|
72
|
+
unmount: Ink['unmount'];
|
|
73
|
+
/**
|
|
74
|
+
Returns a promise that resolves when the app is unmounted.
|
|
75
|
+
*/
|
|
76
|
+
waitUntilExit: Ink['waitUntilExit'];
|
|
77
|
+
cleanup: () => void;
|
|
78
|
+
/**
|
|
79
|
+
Clear output.
|
|
80
|
+
*/
|
|
81
|
+
clear: () => void;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
Mount a component and render the output.
|
|
85
|
+
*/
|
|
86
|
+
declare const render: (node: ReactNode, options?: NodeJS.WriteStream | RenderOptions) => Instance;
|
|
87
|
+
export default render;
|
package/build/render.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Stream } from 'node:stream';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import Ink from './ink.js';
|
|
4
|
+
import instances from './instances.js';
|
|
5
|
+
/**
|
|
6
|
+
Mount a component and render the output.
|
|
7
|
+
*/
|
|
8
|
+
const render = (node, options) => {
|
|
9
|
+
const inkOptions = {
|
|
10
|
+
stdout: process.stdout,
|
|
11
|
+
stdin: process.stdin,
|
|
12
|
+
stderr: process.stderr,
|
|
13
|
+
debug: false,
|
|
14
|
+
exitOnCtrlC: true,
|
|
15
|
+
patchConsole: true,
|
|
16
|
+
maxFps: 30,
|
|
17
|
+
alternateBuffer: false,
|
|
18
|
+
...getOptions(options),
|
|
19
|
+
};
|
|
20
|
+
const instance = getInstance(inkOptions.stdout, () => new Ink(inkOptions));
|
|
21
|
+
instance.render(node);
|
|
22
|
+
return {
|
|
23
|
+
rerender: instance.render,
|
|
24
|
+
unmount() {
|
|
25
|
+
instance.unmount();
|
|
26
|
+
},
|
|
27
|
+
waitUntilExit: instance.waitUntilExit,
|
|
28
|
+
cleanup: () => instances.delete(inkOptions.stdout),
|
|
29
|
+
clear: instance.clear,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export default render;
|
|
33
|
+
const getOptions = (stdout = {}) => {
|
|
34
|
+
if (stdout instanceof Stream) {
|
|
35
|
+
return {
|
|
36
|
+
stdout,
|
|
37
|
+
stdin: process.stdin,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return stdout;
|
|
41
|
+
};
|
|
42
|
+
const getInstance = (stdout, createInstance) => {
|
|
43
|
+
let instance = instances.get(stdout);
|
|
44
|
+
if (!instance) {
|
|
45
|
+
instance = createInstance();
|
|
46
|
+
instances.set(stdout, instance);
|
|
47
|
+
}
|
|
48
|
+
return instance;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":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AM,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CACnB,MAA0B,EAC1B,cAAyB,EACnB,EAAE;IACR,IAAI,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAErC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,QAAQ,GAAG,cAAc,EAAE,CAAC;QAC5B,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import renderNodeToOutput, { renderNodeToScreenReaderOutput, } from './render-node-to-output.js';
|
|
2
|
+
import Output from './output.js';
|
|
3
|
+
const renderer = (node, isScreenReaderEnabled) => {
|
|
4
|
+
if (node.yogaNode) {
|
|
5
|
+
if (isScreenReaderEnabled) {
|
|
6
|
+
const output = renderNodeToScreenReaderOutput(node, {
|
|
7
|
+
skipStaticElements: true,
|
|
8
|
+
});
|
|
9
|
+
const outputHeight = output === '' ? 0 : output.split('\n').length;
|
|
10
|
+
let staticOutput = '';
|
|
11
|
+
if (node.staticNode) {
|
|
12
|
+
staticOutput = renderNodeToScreenReaderOutput(node.staticNode, {
|
|
13
|
+
skipStaticElements: false,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
output,
|
|
18
|
+
outputHeight,
|
|
19
|
+
staticOutput: staticOutput ? `${staticOutput}\n` : '',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const output = new Output({
|
|
23
|
+
width: node.yogaNode.getComputedWidth(),
|
|
24
|
+
height: node.yogaNode.getComputedHeight(),
|
|
25
|
+
});
|
|
26
|
+
renderNodeToOutput(node, output, {
|
|
27
|
+
skipStaticElements: true,
|
|
28
|
+
});
|
|
29
|
+
let staticOutput;
|
|
30
|
+
if (node.staticNode?.yogaNode) {
|
|
31
|
+
staticOutput = new Output({
|
|
32
|
+
width: node.staticNode.yogaNode.getComputedWidth(),
|
|
33
|
+
height: node.staticNode.yogaNode.getComputedHeight(),
|
|
34
|
+
});
|
|
35
|
+
renderNodeToOutput(node.staticNode, staticOutput, {
|
|
36
|
+
skipStaticElements: false,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const { output: generatedOutput, height: outputHeight } = output.get();
|
|
40
|
+
return {
|
|
41
|
+
output: generatedOutput,
|
|
42
|
+
outputHeight,
|
|
43
|
+
// Newline at the end is needed, because static output doesn't have one, so
|
|
44
|
+
// interactive output will override last line of static output
|
|
45
|
+
staticOutput: staticOutput ? `${staticOutput.get().output}\n` : '',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
output: '',
|
|
50
|
+
outputHeight: 0,
|
|
51
|
+
staticOutput: '',
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export default renderer;
|
|
55
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,EAAE,EAC1B,8BAA8B,GAC9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,MAAM,MAAM,aAAa,CAAC;AASjC,MAAM,QAAQ,GAAG,CAAC,IAAgB,EAAE,qBAA8B,EAAU,EAAE;IAC7E,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,IAAI,qBAAqB,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,8BAA8B,CAAC,IAAI,EAAE;gBACnD,kBAAkB,EAAE,IAAI;aACxB,CAAC,CAAC;YAEH,MAAM,YAAY,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;YAEnE,IAAI,YAAY,GAAG,EAAE,CAAC;YAEtB,IAAI,I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,EAAE;SAClE,CAAC;IACH,CAAC;IAED,OAAO;QACN,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,CAAC;QACf,YAAY,EAAE,EAAE;KAChB,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { type DOMElement } from './dom.js';
|
|
7
|
+
export declare function getScrollTop(node: DOMElement): number;
|
|
8
|
+
export declare function getScrollLeft(node: DOMElement): number;
|
package/build/scroll.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import Yoga from 'yoga-layout';
|
|
7
|
+
import { getScrollHeight, getScrollWidth } from './measure-element.js';
|
|
8
|
+
export function getScrollTop(node) {
|
|
9
|
+
const { yogaNode } = node;
|
|
10
|
+
if (!yogaNode) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
const clientHeight = yogaNode.getComputedHeight() -
|
|
14
|
+
yogaNode.getComputedBorder(Yoga.EDGE_TOP) -
|
|
15
|
+
yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM);
|
|
16
|
+
const scrollHeight = getScrollHeight(node);
|
|
17
|
+
let { scrollTop } = node.style;
|
|
18
|
+
if (typeof scrollTop !== 'number') {
|
|
19
|
+
scrollTop = 0;
|
|
20
|
+
}
|
|
21
|
+
return Math.max(0, Math.min(scrollTop, scrollHeight - clientHeight));
|
|
22
|
+
}
|
|
23
|
+
export function getScrollLeft(node) {
|
|
24
|
+
const { yogaNode } = node;
|
|
25
|
+
if (!yogaNode) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
const clientWidth = yogaNode.getComputedWidth() -
|
|
29
|
+
yogaNode.getComputedBorder(Yoga.EDGE_LEFT) -
|
|
30
|
+
yogaNode.getComputedBorder(Yoga.EDGE_RIGHT);
|
|
31
|
+
const scrollWidth = getScrollWidth(node);
|
|
32
|
+
const scrollLeft = node.style.scrollLeft ?? 0;
|
|
33
|
+
return Math.max(0, Math.min(scrollLeft, scrollWidth - clientWidth));
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=scroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../src/scroll.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,aAAa,CAAC;AAE/B,OAAO,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAErE,MAAM,UAAU,YAAY,CAAC,IAAgB;IAC5C,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,YAAY,GACjB,QAAQ,CAAC,iBAAiB,EAAE;QAC5B,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC;QACzC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE9C,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAE3C,IAAI,EAAC,SAAS,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;IAC7B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QACnC,SAAS,GAAG,CAAC,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC7C,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,WAAW,GAChB,QAAQ,CAAC,gBAAgB,EAAE;QAC3B,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC;QAC1C,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAE7C,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Squashing text nodes allows to combine multiple text nodes into one and write
|
|
2
|
+
// to `Output` instance only once. For example, <Text>hello{' '}world</Text>
|
|
3
|
+
// is actually 3 text nodes, which would result 3 writes to `Output`.
|
|
4
|
+
//
|
|
5
|
+
// Also, this is necessary for libraries like ink-link (https://github.com/sindresorhus/ink-link),
|
|
6
|
+
// which need to wrap all children at once, instead of wrapping 3 text nodes separately.
|
|
7
|
+
const squashTextNodes = (node) => {
|
|
8
|
+
let text = '';
|
|
9
|
+
for (let index = 0; index < node.childNodes.length; index++) {
|
|
10
|
+
const childNode = node.childNodes[index];
|
|
11
|
+
if (childNode === undefined) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
let nodeText = '';
|
|
15
|
+
if (childNode.nodeName === '#text') {
|
|
16
|
+
nodeText = childNode.nodeValue;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
if (childNode.nodeName === 'ink-text' ||
|
|
20
|
+
childNode.nodeName === 'ink-virtual-text') {
|
|
21
|
+
nodeText = squashTextNodes(childNode);
|
|
22
|
+
}
|
|
23
|
+
// Since these text nodes are being concatenated, `Output` instance won't be able to
|
|
24
|
+
// apply children transform, so we have to do it manually here for each text node
|
|
25
|
+
if (nodeText.length > 0 &&
|
|
26
|
+
typeof childNode.internal_transform === 'function') {
|
|
27
|
+
nodeText = childNode.internal_transform(nodeText, index);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
text += nodeText;
|
|
31
|
+
}
|
|
32
|
+
return text;
|
|
33
|
+
};
|
|
34
|
+
export default squashTextNodes;
|
|
35
|
+
//# sourceMappingURL=squash-text-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"squash-text-nodes.js","sourceRoot":"","sources":["../src/squash-text-nodes.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,4EAA4E;AAC5E,qEAAqE;AACrE,EAAE;AACF,kGAAkG;AAClG,wFAAwF;AACxF,MAAM,eAAe,GAAG,CAAC,IAAgB,EAAU,EAAE;IACpD,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC7D,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAEzC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC7B,SAAS;QACV,CAAC;QAED,IAAI,QAAQ,GAAG,EAAE,CAAC;QAElB,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACpC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,IACC,SAAS,CAAC,QAAQ,KAAK,UAAU;gBACjC,SAAS,CAAC,QAAQ,KAAK,kBAAkB,EACxC,CAAC;gBACF,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;YACvC,CAAC;YAED,oFAAoF;YACpF,iFAAiF;YACjF,IACC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBACnB,OAAO,SAAS,CAAC,kBAAkB,KAAK,UAAU,EACjD,CAAC;gBACF,QAAQ,GAAG,SAAS,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC1D,CAAC;QACF,CAAC;QAED,IAAI,IAAI,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|