@alchemy.run/sigil 0.0.0-alpha.1 → 0.0.0-alpha.11
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/README.md +499 -313
- package/THIRD_PARTY_NOTICES.md +98 -23
- package/dist/Text-DV9CuzAT.d.ts +452 -0
- package/dist/ansi.d.ts +217 -0
- package/dist/ansi.js +87 -0
- package/dist/capabilities.d.ts +5 -0
- package/dist/capabilities.js +3 -0
- package/dist/cell-_ZVhbfl0.js +44 -0
- package/dist/color-CkbalRqK.js +2 -0
- package/dist/color-policy-BAC9-TZX.js +592 -0
- package/dist/color-policy-CCxuHIdD.d.ts +22 -0
- package/dist/color-profile-CyeHnG1T.d.ts +97 -0
- package/dist/color-profile-DHhQHY55.js +36 -0
- package/dist/color.d.ts +21 -0
- package/dist/color.js +3 -0
- package/dist/cursor-position-D2LAkRG0.d.ts +7 -0
- package/dist/detect-B3dL4Q11.js +374 -0
- package/dist/detect-Db6GbKOm.d.ts +195 -0
- package/dist/{devtools-QpCMm9JH.mjs → devtools-DbthxoD1.js} +23 -24
- package/dist/env-YVw64yZS.js +9 -0
- package/dist/escapes-CB_6CWOE.d.ts +72 -0
- package/dist/geometry-BxXOzJgo.d.ts +11 -0
- package/dist/index-D48vQhhe.d.ts +21 -0
- package/dist/index-DDVME65c.d.ts +919 -0
- package/dist/index.d.ts +1310 -0
- package/dist/index.js +3211 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.js +227 -0
- package/dist/jsx-runtime-XtwIVFsg.js +255 -0
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.js +8 -0
- package/dist/osc-BFKKSqpg.js +71 -0
- package/dist/osc-Cn0fw77g.d.ts +23 -0
- package/dist/paint-Cx-zC_sX.d.ts +81 -0
- package/dist/query-BNc2B8GD.d.ts +152 -0
- package/dist/react-CTZ_8dwh.js +1197 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +49 -0
- package/dist/router.d.ts +392 -0
- package/dist/router.js +711 -0
- package/dist/sample-Cqw1bjUL.js +445 -0
- package/dist/screen-CgC2WlVM.d.ts +49 -0
- package/dist/screen-CiPytswf.js +342 -0
- package/dist/screen.d.ts +5 -0
- package/dist/screen.js +5 -0
- package/dist/semantic-text-style-DIMzC7xt.js +91 -0
- package/dist/serialize-BTkAZgw1.js +79 -0
- package/dist/session-DDQ5V300.js +723 -0
- package/dist/sgr-BhwaWAJB.js +246 -0
- package/dist/store-C1P5fOUi.d.ts +72 -0
- package/dist/string-width-CijQwpIk.js +69 -0
- package/dist/strip-BvU4toXG.js +6 -0
- package/dist/terminal.d.ts +121 -0
- package/dist/terminal.js +2 -0
- package/dist/tokenize-AjqbvtiT.js +1242 -0
- package/dist/tokenize-Dx1y_l5H.d.ts +57 -0
- package/dist/truncate-D31fhU6i.js +562 -0
- package/dist/use-focus-B5npZrJU.js +18736 -0
- package/dist/yoga-5jKhYCJC.js +3465 -0
- package/dist/yoga.d.ts +2 -0
- package/dist/yoga.js +2 -0
- package/package.json +89 -29
- package/src/ansi/chalk.ts +138 -0
- package/src/ansi/cursor.ts +46 -0
- package/src/ansi/east-asian-width.ts +259 -0
- package/src/ansi/escapes.ts +120 -0
- package/src/ansi/graphemes.ts +8 -0
- package/src/ansi/hyperlink.ts +44 -0
- package/src/ansi/index.ts +27 -0
- package/src/ansi/osc.ts +77 -0
- package/src/ansi/sgr.ts +234 -0
- package/src/ansi/slice.ts +43 -0
- package/src/ansi/string-width.ts +121 -0
- package/src/ansi/strip.ts +13 -0
- package/src/ansi/tokenize.ts +380 -0
- package/src/ansi/truncate.ts +196 -0
- package/src/ansi/wrap.ts +765 -0
- package/src/ansi-tokenizer.ts +510 -0
- package/src/capabilities/color-policy.ts +34 -0
- package/src/capabilities/detect.ts +608 -0
- package/src/capabilities/index.ts +37 -0
- package/src/capabilities/query.ts +679 -0
- package/src/capabilities/store.ts +394 -0
- package/src/code-excerpt.ts +39 -0
- package/src/color/index.ts +3 -0
- package/src/color/paint.ts +169 -0
- package/src/color/palette.ts +48 -0
- package/src/color/sample.ts +323 -0
- package/src/color.ts +1 -0
- package/src/components/AccessibilityContext.ts +5 -0
- package/src/components/AnimationContext.ts +24 -0
- package/src/components/AnsiText.tsx +42 -0
- package/src/components/App.tsx +878 -0
- package/src/components/AppContext.ts +111 -0
- package/src/components/BackgroundContext.ts +7 -0
- package/src/components/Box.tsx +100 -0
- package/src/components/CursorContext.ts +19 -0
- package/src/components/ErrorBoundary.tsx +39 -0
- package/src/components/ErrorOverview.tsx +135 -0
- package/src/components/FocusContext.ts +30 -0
- package/src/components/Hyperlink.tsx +56 -0
- package/src/components/Newline.tsx +16 -0
- package/src/components/Spacer.tsx +11 -0
- package/src/components/Static.tsx +60 -0
- package/src/components/StderrContext.ts +24 -0
- package/src/components/StdinContext.ts +48 -0
- package/src/components/StdoutContext.ts +26 -0
- package/src/components/TerminalOscContext.ts +25 -0
- package/src/components/Text.tsx +122 -0
- package/src/components/Transform.tsx +38 -0
- package/src/components/VirtualList.tsx +128 -0
- package/src/cursor-position.ts +103 -0
- package/src/devtools.ts +103 -0
- package/src/dom.ts +301 -0
- package/src/env.ts +12 -0
- package/src/get-max-width.ts +11 -0
- package/src/global.d.ts +38 -0
- package/src/glyphs.ts +99 -0
- package/src/hooks/use-animation.ts +142 -0
- package/src/hooks/use-app.ts +8 -0
- package/src/hooks/use-box-metrics.ts +134 -0
- package/src/hooks/use-capabilities.ts +73 -0
- package/src/hooks/use-cursor.ts +33 -0
- package/src/hooks/use-focus-manager.ts +62 -0
- package/src/hooks/use-focus.ts +82 -0
- package/src/hooks/use-input.ts +267 -0
- package/src/hooks/use-is-screen-reader-enabled.ts +12 -0
- package/src/hooks/use-paste.ts +78 -0
- package/src/hooks/use-stderr.ts +8 -0
- package/src/hooks/use-stdin.ts +10 -0
- package/src/hooks/use-stdout.ts +8 -0
- package/src/hooks/use-terminal-osc.ts +59 -0
- package/src/hooks/use-virtual-scroll.ts +84 -0
- package/src/hooks/use-window-size.ts +37 -0
- package/src/index.ts +96 -0
- package/src/ink.tsx +1452 -0
- package/src/input-parser.ts +303 -0
- package/src/instances.ts +9 -0
- package/src/jsx-dev-runtime.ts +3 -0
- package/src/jsx-runtime.ts +6 -0
- package/src/kitty-keyboard.ts +185 -0
- package/src/measure-element.ts +62 -0
- package/src/measure-text.ts +31 -0
- package/src/paint-tree.ts +220 -0
- package/src/parse-keypress.ts +515 -0
- package/src/parse-stack-line.ts +138 -0
- package/src/patch-console.ts +106 -0
- package/src/quick-lru.ts +85 -0
- package/src/react.ts +53 -0
- package/src/reconciler.ts +476 -0
- package/src/render-background.ts +59 -0
- package/src/render-border.ts +167 -0
- package/src/render-frame.ts +83 -0
- package/src/render-to-string.ts +146 -0
- package/src/render.ts +284 -0
- package/src/router/components.tsx +343 -0
- package/src/router/context.ts +41 -0
- package/src/router/history.ts +194 -0
- package/src/router/hooks.tsx +391 -0
- package/src/router/index.ts +34 -0
- package/src/router/matcher.ts +571 -0
- package/src/sanitize-ansi.ts +33 -0
- package/src/screen/ansi.ts +184 -0
- package/src/screen/canvas.ts +160 -0
- package/src/screen/cell.ts +138 -0
- package/src/screen/color-profile.ts +47 -0
- package/src/screen/geometry.ts +9 -0
- package/src/screen/index.ts +6 -0
- package/src/screen/screen.ts +305 -0
- package/src/screen/serialize.ts +129 -0
- package/src/screen.ts +1 -0
- package/src/semantic-text-style.ts +118 -0
- package/src/signal-exit.ts +106 -0
- package/src/squash-text-nodes.ts +37 -0
- package/src/stream.ts +28 -0
- package/src/structured-text.ts +325 -0
- package/src/styles.ts +753 -0
- package/src/terminal/index.ts +2 -0
- package/src/terminal/inline-presenter.ts +120 -0
- package/src/terminal/input.ts +92 -0
- package/src/terminal/render-scheduler.ts +37 -0
- package/src/terminal/screen-presenter.ts +242 -0
- package/src/terminal/session.ts +408 -0
- package/src/terminal-size.ts +58 -0
- package/src/terminal.ts +1 -0
- package/src/testing/browser.ts +588 -0
- package/src/testing/emulators.ts +205 -0
- package/src/testing/explorer-app/index.html +12 -0
- package/src/testing/explorer-app/main.ts +381 -0
- package/src/testing/explorer-app/style.css +194 -0
- package/src/testing/explorer-app/tsconfig.json +15 -0
- package/src/testing/explorer-app/vite-env.d.ts +1 -0
- package/src/testing/index.ts +26 -0
- package/src/testing/keys.ts +56 -0
- package/src/testing/live.ts +85 -0
- package/src/testing/matchers.ts +70 -0
- package/src/testing/public.ts +94 -0
- package/src/testing/terminal.ts +361 -0
- package/src/testing/vitest.ts +157 -0
- package/src/throttle.ts +73 -0
- package/src/transform-adapter.ts +14 -0
- package/src/types.ts +10 -0
- package/src/virtual-scroll.ts +133 -0
- package/src/wrap-text.ts +54 -0
- package/src/yoga/config.ts +57 -0
- package/src/yoga/core/absoluteLayout.ts +626 -0
- package/src/yoga/core/baseline.ts +66 -0
- package/src/yoga/core/cache.ts +136 -0
- package/src/yoga/core/calculateLayout.ts +2926 -0
- package/src/yoga/core/config.ts +104 -0
- package/src/yoga/core/flexLine.ts +177 -0
- package/src/yoga/core/helpers.ts +293 -0
- package/src/yoga/core/layoutResults.ts +167 -0
- package/src/yoga/core/node.ts +611 -0
- package/src/yoga/core/numeric.ts +44 -0
- package/src/yoga/core/pixelGrid.ts +151 -0
- package/src/yoga/core/style.ts +887 -0
- package/src/yoga/core/types.ts +224 -0
- package/src/yoga/generated/YGEnums.ts +263 -0
- package/src/yoga/index.ts +19 -0
- package/src/yoga/node.ts +1140 -0
- package/dist/index.d.mts +0 -2379
- package/dist/index.mjs +0 -10072
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { type DOMElement } from "#/dom.ts";
|
|
2
|
+
import { getMaxWidth } from "#/get-max-width.ts";
|
|
3
|
+
import { renderBackground } from "#/render-background.ts";
|
|
4
|
+
import { renderBorder } from "#/render-border.ts";
|
|
5
|
+
import type { Canvas } from "#/screen/canvas.ts";
|
|
6
|
+
import { serializeLine } from "#/screen/serialize.ts";
|
|
7
|
+
import { squashTextNodes } from "#/squash-text-nodes.ts";
|
|
8
|
+
import {
|
|
9
|
+
hasCompatibilityText,
|
|
10
|
+
structuredTextBaseStyle,
|
|
11
|
+
structuredTextLines,
|
|
12
|
+
wrapStructuredText,
|
|
13
|
+
sampleStructuredText,
|
|
14
|
+
} from "#/structured-text.ts";
|
|
15
|
+
import type { AnsiTransformer } from "#/transform-adapter.ts";
|
|
16
|
+
import { Yoga } from "#/yoga/index.ts";
|
|
17
|
+
|
|
18
|
+
export const renderAccessibleText = (
|
|
19
|
+
node: DOMElement,
|
|
20
|
+
options: {
|
|
21
|
+
parentRole?: string;
|
|
22
|
+
skipStaticElements?: boolean;
|
|
23
|
+
} = {},
|
|
24
|
+
): string => {
|
|
25
|
+
if (options.skipStaticElements && node.internal_static) {
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (node.yogaNode?.getDisplay() === Yoga.DISPLAY_NONE) {
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let output = "";
|
|
34
|
+
|
|
35
|
+
if (node.nodeName === "ink-text") {
|
|
36
|
+
output = squashTextNodes(node);
|
|
37
|
+
} else if (node.nodeName === "ink-box" || node.nodeName === "ink-root") {
|
|
38
|
+
const separator =
|
|
39
|
+
node.style.flexDirection === "row" || node.style.flexDirection === "row-reverse" ? " " : "\n";
|
|
40
|
+
|
|
41
|
+
const childNodes =
|
|
42
|
+
node.style.flexDirection === "row-reverse" || node.style.flexDirection === "column-reverse"
|
|
43
|
+
? [...node.childNodes].reverse()
|
|
44
|
+
: [...node.childNodes];
|
|
45
|
+
|
|
46
|
+
output = childNodes
|
|
47
|
+
.map((childNode) => {
|
|
48
|
+
const screenReaderOutput = renderAccessibleText(childNode as DOMElement, {
|
|
49
|
+
parentRole: node.internal_accessibility?.role,
|
|
50
|
+
skipStaticElements: options.skipStaticElements,
|
|
51
|
+
});
|
|
52
|
+
return screenReaderOutput;
|
|
53
|
+
})
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.join(separator);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (node.internal_accessibility) {
|
|
59
|
+
const { role, state } = node.internal_accessibility;
|
|
60
|
+
|
|
61
|
+
if (state) {
|
|
62
|
+
const stateKeys = Object.keys(state) as Array<keyof typeof state>;
|
|
63
|
+
const stateDescription = stateKeys.filter((key) => state[key]).join(", ");
|
|
64
|
+
|
|
65
|
+
if (stateDescription) {
|
|
66
|
+
output = `(${stateDescription}) ${output}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (role && role !== options.parentRole) {
|
|
71
|
+
output = `${role}: ${output}`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return output;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// After nodes are laid out, render each to output object, which later gets rendered to terminal
|
|
79
|
+
export const paintTree = (
|
|
80
|
+
node: DOMElement,
|
|
81
|
+
output: Canvas,
|
|
82
|
+
options: {
|
|
83
|
+
offsetX?: number;
|
|
84
|
+
offsetY?: number;
|
|
85
|
+
transformers?: AnsiTransformer[];
|
|
86
|
+
skipStaticElements: boolean;
|
|
87
|
+
},
|
|
88
|
+
) => {
|
|
89
|
+
const { offsetX = 0, offsetY = 0, transformers = [], skipStaticElements } = options;
|
|
90
|
+
|
|
91
|
+
if (skipStaticElements && node.internal_static) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { yogaNode } = node;
|
|
96
|
+
|
|
97
|
+
if (yogaNode) {
|
|
98
|
+
if (yogaNode.getDisplay() === Yoga.DISPLAY_NONE) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Left and top positions in Yoga are relative to their parent node
|
|
103
|
+
const x = offsetX + yogaNode.getComputedLeft();
|
|
104
|
+
const y = offsetY + yogaNode.getComputedTop();
|
|
105
|
+
|
|
106
|
+
// Transformers are functions that transform final text output of each component
|
|
107
|
+
// The canvas applies explicit compatibility transformers at this boundary.
|
|
108
|
+
const newTransformers = node.internal_transform
|
|
109
|
+
? [node.internal_transform, ...transformers]
|
|
110
|
+
: transformers;
|
|
111
|
+
|
|
112
|
+
if (node.nodeName === "ink-text") {
|
|
113
|
+
const text = squashTextNodes(node);
|
|
114
|
+
|
|
115
|
+
if (text.length > 0) {
|
|
116
|
+
const maxWidth = getMaxWidth(yogaNode);
|
|
117
|
+
const firstChildYoga = node.childNodes[0]?.yogaNode;
|
|
118
|
+
const paddingX = firstChildYoga?.getComputedLeft() ?? 0;
|
|
119
|
+
const paddingY = firstChildYoga?.getComputedTop() ?? 0;
|
|
120
|
+
const textWrap = node.style.textWrap ?? "wrap";
|
|
121
|
+
// `none` text may paint past the screen's nominal width; the screen
|
|
122
|
+
// grows the touched rows on demand. Clip rects still apply.
|
|
123
|
+
const overflow = textWrap === "none";
|
|
124
|
+
const lines = wrapStructuredText(
|
|
125
|
+
structuredTextLines(node),
|
|
126
|
+
maxWidth,
|
|
127
|
+
textWrap,
|
|
128
|
+
structuredTextBaseStyle(node),
|
|
129
|
+
);
|
|
130
|
+
const paintBounds = {
|
|
131
|
+
x: x + paddingX,
|
|
132
|
+
y: y + paddingY,
|
|
133
|
+
width: Math.max(
|
|
134
|
+
1,
|
|
135
|
+
...lines.map((line) => line.reduce((width, cell) => width + cell.width, 0)),
|
|
136
|
+
),
|
|
137
|
+
height: lines.length,
|
|
138
|
+
};
|
|
139
|
+
const sampled = sampleStructuredText(lines, paintBounds, output.paintContext);
|
|
140
|
+
|
|
141
|
+
if (hasCompatibilityText(node)) {
|
|
142
|
+
const textTransformers = collectTransformers(node, transformers);
|
|
143
|
+
output.writeAnsi(
|
|
144
|
+
paintBounds.x,
|
|
145
|
+
paintBounds.y,
|
|
146
|
+
sampled
|
|
147
|
+
.map((line) =>
|
|
148
|
+
serializeLine(line, {
|
|
149
|
+
colorProfile: output.paintContext.profile ?? "truecolor",
|
|
150
|
+
trimEnd: false,
|
|
151
|
+
}),
|
|
152
|
+
)
|
|
153
|
+
.join("\n"),
|
|
154
|
+
{ transformers: textTransformers, overflow },
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
output.writeCells(paintBounds.x, paintBounds.y, sampled, { overflow });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let clipped = false;
|
|
165
|
+
|
|
166
|
+
if (node.nodeName === "ink-box") {
|
|
167
|
+
renderBackground(x, y, node, output);
|
|
168
|
+
renderBorder(x, y, node, output);
|
|
169
|
+
|
|
170
|
+
const clipHorizontally =
|
|
171
|
+
node.style.overflowX === "hidden" || node.style.overflow === "hidden";
|
|
172
|
+
const clipVertically = node.style.overflowY === "hidden" || node.style.overflow === "hidden";
|
|
173
|
+
|
|
174
|
+
if (clipHorizontally || clipVertically) {
|
|
175
|
+
const x1 = clipHorizontally ? x + yogaNode.getComputedBorder(Yoga.EDGE_LEFT) : undefined;
|
|
176
|
+
|
|
177
|
+
const x2 = clipHorizontally
|
|
178
|
+
? x + yogaNode.getComputedWidth() - yogaNode.getComputedBorder(Yoga.EDGE_RIGHT)
|
|
179
|
+
: undefined;
|
|
180
|
+
|
|
181
|
+
const y1 = clipVertically ? y + yogaNode.getComputedBorder(Yoga.EDGE_TOP) : undefined;
|
|
182
|
+
|
|
183
|
+
const y2 = clipVertically
|
|
184
|
+
? y + yogaNode.getComputedHeight() - yogaNode.getComputedBorder(Yoga.EDGE_BOTTOM)
|
|
185
|
+
: undefined;
|
|
186
|
+
|
|
187
|
+
output.clip({ x1, x2, y1, y2 });
|
|
188
|
+
clipped = true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (node.nodeName === "ink-root" || node.nodeName === "ink-box") {
|
|
193
|
+
for (const childNode of node.childNodes) {
|
|
194
|
+
paintTree(childNode as DOMElement, output, {
|
|
195
|
+
offsetX: x,
|
|
196
|
+
offsetY: y,
|
|
197
|
+
transformers: newTransformers,
|
|
198
|
+
skipStaticElements,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (clipped) {
|
|
203
|
+
output.unclip();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
function collectTransformers(
|
|
210
|
+
node: DOMElement,
|
|
211
|
+
inherited: readonly AnsiTransformer[],
|
|
212
|
+
): AnsiTransformer[] {
|
|
213
|
+
return [
|
|
214
|
+
...node.childNodes.flatMap((child) =>
|
|
215
|
+
child.nodeName === "#text" ? [] : collectTransformers(child, []),
|
|
216
|
+
),
|
|
217
|
+
...(node.internal_transform ? [node.internal_transform] : []),
|
|
218
|
+
...inherited,
|
|
219
|
+
];
|
|
220
|
+
}
|