@alchemy.run/sigil 0.0.0-alpha.1 → 0.0.0-alpha.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/README.md +299 -299
- package/dist/ansi.d.ts +223 -0
- package/dist/ansi.js +2 -0
- package/dist/{devtools-QpCMm9JH.mjs → devtools-BhYGjb7h.js} +1 -1
- package/dist/index-DDVME65c.d.ts +919 -0
- package/dist/index.d.ts +1657 -0
- package/dist/index.js +4643 -0
- package/dist/sgr-CMfEpjSk.d.ts +91 -0
- package/dist/truncate-CBiyyZzw.js +2156 -0
- package/dist/yoga-5jKhYCJC.js +3465 -0
- package/dist/yoga.d.ts +2 -0
- package/dist/yoga.js +2 -0
- package/package.json +37 -17
- package/src/ansi/chalk.ts +179 -0
- package/src/ansi/cursor.ts +48 -0
- package/src/ansi/east-asian-width.ts +215 -0
- package/src/ansi/escapes.ts +128 -0
- package/src/ansi/index.ts +27 -0
- package/src/ansi/sgr.ts +237 -0
- package/src/ansi/slice.ts +43 -0
- package/src/ansi/string-width.ts +236 -0
- package/src/ansi/strip.ts +33 -0
- package/src/ansi/supports-color.ts +213 -0
- package/src/ansi/tokenize.ts +453 -0
- package/src/ansi/truncate.ts +194 -0
- package/src/ansi/widest-line.ts +12 -0
- package/src/ansi/wrap.ts +766 -0
- package/src/ansi-tokenizer.ts +510 -0
- package/src/auto-bind.ts +41 -0
- package/src/boxes.ts +100 -0
- package/src/code-excerpt.ts +39 -0
- package/src/colorize.ts +60 -0
- package/src/components/AccessibilityContext.ts +5 -0
- package/src/components/AnimationContext.ts +24 -0
- package/src/components/App.tsx +781 -0
- package/src/components/AppContext.ts +111 -0
- package/src/components/BackgroundContext.ts +8 -0
- package/src/components/Box.tsx +116 -0
- package/src/components/CursorContext.ts +19 -0
- package/src/components/ErrorBoundary.tsx +38 -0
- package/src/components/ErrorOverview.tsx +133 -0
- package/src/components/FocusContext.ts +30 -0
- package/src/components/Newline.tsx +15 -0
- package/src/components/Spacer.tsx +10 -0
- package/src/components/Static.tsx +59 -0
- package/src/components/StderrContext.ts +26 -0
- package/src/components/StdinContext.ts +49 -0
- package/src/components/StdoutContext.ts +28 -0
- package/src/components/Text.tsx +144 -0
- package/src/components/Transform.tsx +37 -0
- package/src/cursor-position.ts +103 -0
- package/src/devtools-window-polyfill.ts +73 -0
- package/src/devtools.ts +43 -0
- package/src/dom.ts +292 -0
- package/src/get-max-width.ts +11 -0
- package/src/global.d.ts +36 -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-cursor.ts +33 -0
- package/src/hooks/use-focus-manager.ts +62 -0
- package/src/hooks/use-focus.ts +83 -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-window-size.ts +41 -0
- package/src/indent-string.ts +16 -0
- package/src/index.ts +44 -0
- package/src/ink.tsx +1506 -0
- package/src/input-parser.ts +283 -0
- package/src/instances.ts +9 -0
- package/src/is-in-ci.ts +7 -0
- package/src/kitty-keyboard.ts +57 -0
- package/src/log-update.ts +370 -0
- package/src/measure-element.ts +62 -0
- package/src/measure-text.ts +31 -0
- package/src/output.ts +308 -0
- package/src/parse-keypress.ts +516 -0
- package/src/parse-stack-line.ts +139 -0
- package/src/patch-console.ts +62 -0
- package/src/quick-lru.ts +85 -0
- package/src/reconciler.ts +451 -0
- package/src/render-background.ts +38 -0
- package/src/render-border.ts +134 -0
- package/src/render-node-to-output.ts +191 -0
- package/src/render-to-string.ts +131 -0
- package/src/render.ts +276 -0
- package/src/renderer.ts +73 -0
- package/src/sanitize-ansi.ts +33 -0
- package/src/signal-exit.ts +107 -0
- package/src/squash-text-nodes.ts +40 -0
- package/src/stream.ts +30 -0
- package/src/styles.ts +748 -0
- package/src/terminal-size.ts +57 -0
- package/src/throttle.ts +73 -0
- package/src/types.ts +15 -0
- package/src/utils.ts +40 -0
- package/src/wrap-text.ts +50 -0
- package/src/write-synchronized.ts +9 -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 +2920 -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,107 @@
|
|
|
1
|
+
// Derived from `signal-exit` v3 (ISC, Ben Coe / Isaac Z. Schlueter),
|
|
2
|
+
// covering the surface Ink uses: run handlers when the process exits normally
|
|
3
|
+
// or would die from a fatal signal, `alwaysLast` ordering, and unsubscribe.
|
|
4
|
+
// Handlers receive `null` (not `undefined`) like the original package did —
|
|
5
|
+
// Ink's unmount() relies on that to detect process shutdown.
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-restricted-types */
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
|
|
9
|
+
type ExitHandler = (code: number | null, signal: NodeJS.Signals | null) => void;
|
|
10
|
+
|
|
11
|
+
type Registration = {
|
|
12
|
+
handler: ExitHandler;
|
|
13
|
+
alwaysLast: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const signals: NodeJS.Signals[] =
|
|
17
|
+
process.platform === "win32"
|
|
18
|
+
? ["SIGHUP", "SIGINT", "SIGTERM", "SIGBREAK"]
|
|
19
|
+
: ["SIGHUP", "SIGINT", "SIGTERM", "SIGQUIT", "SIGUSR2"];
|
|
20
|
+
|
|
21
|
+
const registrations = new Set<Registration>();
|
|
22
|
+
const signalListeners = new Map<NodeJS.Signals, () => void>();
|
|
23
|
+
let loaded = false;
|
|
24
|
+
let emitted = false;
|
|
25
|
+
|
|
26
|
+
const emitExit = (code: number | null, signal: NodeJS.Signals | null): void => {
|
|
27
|
+
if (emitted) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
emitted = true;
|
|
32
|
+
|
|
33
|
+
const ordered = [...registrations].toSorted(
|
|
34
|
+
(a, b) => Number(a.alwaysLast) - Number(b.alwaysLast),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
for (const registration of ordered) {
|
|
38
|
+
registration.handler(code, signal);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const onExitEvent = (code: number): void => {
|
|
43
|
+
emitExit(code, null);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const unload = (): void => {
|
|
47
|
+
if (!loaded) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
loaded = false;
|
|
52
|
+
process.off("exit", onExitEvent);
|
|
53
|
+
|
|
54
|
+
for (const [signal, listener] of signalListeners) {
|
|
55
|
+
process.off(signal, listener);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
signalListeners.clear();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const load = (): void => {
|
|
62
|
+
if (loaded) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
loaded = true;
|
|
67
|
+
process.on("exit", onExitEvent);
|
|
68
|
+
|
|
69
|
+
for (const signal of signals) {
|
|
70
|
+
const listener = (): void => {
|
|
71
|
+
// Only act when nothing else is handling this signal, meaning the
|
|
72
|
+
// process would have died. Run handlers, then re-raise the signal with
|
|
73
|
+
// default behavior restored so the exit code reflects the signal.
|
|
74
|
+
if (process.listenerCount(signal) === 1) {
|
|
75
|
+
unload();
|
|
76
|
+
emitExit(null, signal);
|
|
77
|
+
process.kill(process.pid, signal);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
process.on(signal, listener);
|
|
83
|
+
signalListeners.set(signal, listener);
|
|
84
|
+
} catch {}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const signalExit = (
|
|
89
|
+
handler: ExitHandler,
|
|
90
|
+
options: { alwaysLast?: boolean } = {},
|
|
91
|
+
): (() => void) => {
|
|
92
|
+
const registration: Registration = {
|
|
93
|
+
handler,
|
|
94
|
+
alwaysLast: options.alwaysLast ?? false,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
registrations.add(registration);
|
|
98
|
+
load();
|
|
99
|
+
|
|
100
|
+
return () => {
|
|
101
|
+
registrations.delete(registration);
|
|
102
|
+
|
|
103
|
+
if (registrations.size === 0) {
|
|
104
|
+
unload();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type DOMElement } from "./dom.ts";
|
|
2
|
+
import { sanitizeAnsi } from "./sanitize-ansi.ts";
|
|
3
|
+
|
|
4
|
+
// Squashing text nodes allows to combine multiple text nodes into one and write
|
|
5
|
+
// to `Output` instance only once. For example, <Text>hello{' '}world</Text>
|
|
6
|
+
// is actually 3 text nodes, which would result 3 writes to `Output`.
|
|
7
|
+
//
|
|
8
|
+
// Also, this is necessary for libraries like ink-link (https://github.com/sindresorhus/ink-link),
|
|
9
|
+
// which need to wrap all children at once, instead of wrapping 3 text nodes separately.
|
|
10
|
+
export const squashTextNodes = (node: DOMElement): string => {
|
|
11
|
+
let text = "";
|
|
12
|
+
|
|
13
|
+
for (let index = 0; index < node.childNodes.length; index++) {
|
|
14
|
+
const childNode = node.childNodes[index];
|
|
15
|
+
|
|
16
|
+
if (childNode === undefined) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let nodeText = "";
|
|
21
|
+
|
|
22
|
+
if (childNode.nodeName === "#text") {
|
|
23
|
+
nodeText = childNode.nodeValue;
|
|
24
|
+
} else {
|
|
25
|
+
if (childNode.nodeName === "ink-text" || childNode.nodeName === "ink-virtual-text") {
|
|
26
|
+
nodeText = squashTextNodes(childNode);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Since these text nodes are being concatenated, `Output` instance won't be able to
|
|
30
|
+
// apply children transform, so we have to do it manually here for each text node
|
|
31
|
+
if (nodeText.length > 0 && typeof childNode.internal_transform === "function") {
|
|
32
|
+
nodeText = childNode.internal_transform(nodeText, index);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
text += nodeText;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return sanitizeAnsi(text);
|
|
40
|
+
};
|
package/src/stream.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type OutputStream = NodeJS.WritableStream & {
|
|
2
|
+
isTTY?: boolean;
|
|
3
|
+
columns?: number;
|
|
4
|
+
rows?: number;
|
|
5
|
+
destroyed?: boolean;
|
|
6
|
+
writableEnded?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type RawModeStream = NodeJS.ReadableStream & {
|
|
10
|
+
isTTY: true;
|
|
11
|
+
setRawMode: (mode: boolean) => void;
|
|
12
|
+
ref?: () => void;
|
|
13
|
+
unref?: () => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const isTty = (stream: NodeJS.ReadableStream): boolean => {
|
|
17
|
+
return "isTTY" in stream && stream.isTTY === true;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const isRawModeStream = (stdin: NodeJS.ReadableStream): stdin is RawModeStream => {
|
|
21
|
+
return isTty(stdin) && "setRawMode" in stdin && typeof stdin.setRawMode === "function";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const getRawModeStream = (stdin: NodeJS.ReadableStream): RawModeStream | undefined => {
|
|
25
|
+
if (!isRawModeStream(stdin)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return stdin;
|
|
30
|
+
};
|