@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.
Files changed (121) hide show
  1. package/README.md +299 -299
  2. package/dist/ansi.d.ts +223 -0
  3. package/dist/ansi.js +2 -0
  4. package/dist/{devtools-QpCMm9JH.mjs → devtools-BhYGjb7h.js} +1 -1
  5. package/dist/index-DDVME65c.d.ts +919 -0
  6. package/dist/index.d.ts +1657 -0
  7. package/dist/index.js +4643 -0
  8. package/dist/sgr-CMfEpjSk.d.ts +91 -0
  9. package/dist/truncate-CBiyyZzw.js +2156 -0
  10. package/dist/yoga-5jKhYCJC.js +3465 -0
  11. package/dist/yoga.d.ts +2 -0
  12. package/dist/yoga.js +2 -0
  13. package/package.json +37 -17
  14. package/src/ansi/chalk.ts +179 -0
  15. package/src/ansi/cursor.ts +48 -0
  16. package/src/ansi/east-asian-width.ts +215 -0
  17. package/src/ansi/escapes.ts +128 -0
  18. package/src/ansi/index.ts +27 -0
  19. package/src/ansi/sgr.ts +237 -0
  20. package/src/ansi/slice.ts +43 -0
  21. package/src/ansi/string-width.ts +236 -0
  22. package/src/ansi/strip.ts +33 -0
  23. package/src/ansi/supports-color.ts +213 -0
  24. package/src/ansi/tokenize.ts +453 -0
  25. package/src/ansi/truncate.ts +194 -0
  26. package/src/ansi/widest-line.ts +12 -0
  27. package/src/ansi/wrap.ts +766 -0
  28. package/src/ansi-tokenizer.ts +510 -0
  29. package/src/auto-bind.ts +41 -0
  30. package/src/boxes.ts +100 -0
  31. package/src/code-excerpt.ts +39 -0
  32. package/src/colorize.ts +60 -0
  33. package/src/components/AccessibilityContext.ts +5 -0
  34. package/src/components/AnimationContext.ts +24 -0
  35. package/src/components/App.tsx +781 -0
  36. package/src/components/AppContext.ts +111 -0
  37. package/src/components/BackgroundContext.ts +8 -0
  38. package/src/components/Box.tsx +116 -0
  39. package/src/components/CursorContext.ts +19 -0
  40. package/src/components/ErrorBoundary.tsx +38 -0
  41. package/src/components/ErrorOverview.tsx +133 -0
  42. package/src/components/FocusContext.ts +30 -0
  43. package/src/components/Newline.tsx +15 -0
  44. package/src/components/Spacer.tsx +10 -0
  45. package/src/components/Static.tsx +59 -0
  46. package/src/components/StderrContext.ts +26 -0
  47. package/src/components/StdinContext.ts +49 -0
  48. package/src/components/StdoutContext.ts +28 -0
  49. package/src/components/Text.tsx +144 -0
  50. package/src/components/Transform.tsx +37 -0
  51. package/src/cursor-position.ts +103 -0
  52. package/src/devtools-window-polyfill.ts +73 -0
  53. package/src/devtools.ts +43 -0
  54. package/src/dom.ts +292 -0
  55. package/src/get-max-width.ts +11 -0
  56. package/src/global.d.ts +36 -0
  57. package/src/hooks/use-animation.ts +142 -0
  58. package/src/hooks/use-app.ts +8 -0
  59. package/src/hooks/use-box-metrics.ts +134 -0
  60. package/src/hooks/use-cursor.ts +33 -0
  61. package/src/hooks/use-focus-manager.ts +62 -0
  62. package/src/hooks/use-focus.ts +83 -0
  63. package/src/hooks/use-input.ts +267 -0
  64. package/src/hooks/use-is-screen-reader-enabled.ts +12 -0
  65. package/src/hooks/use-paste.ts +78 -0
  66. package/src/hooks/use-stderr.ts +8 -0
  67. package/src/hooks/use-stdin.ts +10 -0
  68. package/src/hooks/use-stdout.ts +8 -0
  69. package/src/hooks/use-window-size.ts +41 -0
  70. package/src/indent-string.ts +16 -0
  71. package/src/index.ts +44 -0
  72. package/src/ink.tsx +1506 -0
  73. package/src/input-parser.ts +283 -0
  74. package/src/instances.ts +9 -0
  75. package/src/is-in-ci.ts +7 -0
  76. package/src/kitty-keyboard.ts +57 -0
  77. package/src/log-update.ts +370 -0
  78. package/src/measure-element.ts +62 -0
  79. package/src/measure-text.ts +31 -0
  80. package/src/output.ts +308 -0
  81. package/src/parse-keypress.ts +516 -0
  82. package/src/parse-stack-line.ts +139 -0
  83. package/src/patch-console.ts +62 -0
  84. package/src/quick-lru.ts +85 -0
  85. package/src/reconciler.ts +451 -0
  86. package/src/render-background.ts +38 -0
  87. package/src/render-border.ts +134 -0
  88. package/src/render-node-to-output.ts +191 -0
  89. package/src/render-to-string.ts +131 -0
  90. package/src/render.ts +276 -0
  91. package/src/renderer.ts +73 -0
  92. package/src/sanitize-ansi.ts +33 -0
  93. package/src/signal-exit.ts +107 -0
  94. package/src/squash-text-nodes.ts +40 -0
  95. package/src/stream.ts +30 -0
  96. package/src/styles.ts +748 -0
  97. package/src/terminal-size.ts +57 -0
  98. package/src/throttle.ts +73 -0
  99. package/src/types.ts +15 -0
  100. package/src/utils.ts +40 -0
  101. package/src/wrap-text.ts +50 -0
  102. package/src/write-synchronized.ts +9 -0
  103. package/src/yoga/config.ts +57 -0
  104. package/src/yoga/core/absoluteLayout.ts +626 -0
  105. package/src/yoga/core/baseline.ts +66 -0
  106. package/src/yoga/core/cache.ts +136 -0
  107. package/src/yoga/core/calculateLayout.ts +2920 -0
  108. package/src/yoga/core/config.ts +104 -0
  109. package/src/yoga/core/flexLine.ts +177 -0
  110. package/src/yoga/core/helpers.ts +293 -0
  111. package/src/yoga/core/layoutResults.ts +167 -0
  112. package/src/yoga/core/node.ts +611 -0
  113. package/src/yoga/core/numeric.ts +44 -0
  114. package/src/yoga/core/pixelGrid.ts +151 -0
  115. package/src/yoga/core/style.ts +887 -0
  116. package/src/yoga/core/types.ts +224 -0
  117. package/src/yoga/generated/YGEnums.ts +263 -0
  118. package/src/yoga/index.ts +19 -0
  119. package/src/yoga/node.ts +1140 -0
  120. package/dist/index.d.mts +0 -2379
  121. package/dist/index.mjs +0 -10072
@@ -0,0 +1,57 @@
1
+ import fs from "node:fs";
2
+ // Derived from `terminal-size` (MIT, Sindre Sorhus), reduced for Ink's usage as a
3
+ // fallback when the stdout stream reports no dimensions. Unlike the original,
4
+ // this never shells out to `tput`/`resize` — it checks the process streams,
5
+ // the COLUMNS/LINES environment variables and /dev/tty, then falls back to
6
+ // the standard 80×24.
7
+ import process from "node:process";
8
+ import tty from "node:tty";
9
+
10
+ type TerminalSize = {
11
+ columns: number;
12
+ rows: number;
13
+ };
14
+
15
+ const create = (columns: number | string, rows: number | string): TerminalSize => ({
16
+ columns: Number.parseInt(String(columns), 10),
17
+ rows: Number.parseInt(String(rows), 10),
18
+ });
19
+
20
+ const devTty = (): TerminalSize | undefined => {
21
+ try {
22
+ // O_EVTONLY is macOS-only and missing from the Node type definitions.
23
+ const { O_EVTONLY: evtOnly } = fs.constants as { O_EVTONLY?: number };
24
+ const flags =
25
+ process.platform === "darwin" && evtOnly !== undefined
26
+ ? // eslint-disable-next-line no-bitwise
27
+ evtOnly | fs.constants.O_NONBLOCK
28
+ : fs.constants.O_NONBLOCK;
29
+
30
+ const { columns, rows } = new tty.WriteStream(fs.openSync("/dev/tty", flags));
31
+
32
+ if (columns && rows) {
33
+ return { columns, rows };
34
+ }
35
+ } catch {}
36
+
37
+ return;
38
+ };
39
+
40
+ export const terminalSize = (): TerminalSize => {
41
+ const { env, stdout, stderr } = process;
42
+
43
+ if (stdout?.columns && stdout?.rows) {
44
+ return create(stdout.columns, stdout.rows);
45
+ }
46
+
47
+ if (stderr?.columns && stderr?.rows) {
48
+ return create(stderr.columns, stderr.rows);
49
+ }
50
+
51
+ // These values are static, so not the first choice.
52
+ if (env["COLUMNS"] && env["LINES"]) {
53
+ return create(env["COLUMNS"], env["LINES"]);
54
+ }
55
+
56
+ return devTty() ?? { columns: 80, rows: 24 };
57
+ };
@@ -0,0 +1,73 @@
1
+ // Derived from `throttle` from `es-toolkit/compat` (lodash-style),
2
+ // covering the surface Ink uses: leading + trailing edges, cancel() and flush().
3
+
4
+ export type Throttled<Arguments extends unknown[]> = {
5
+ (...args: Arguments): void;
6
+ cancel: () => void;
7
+ flush: () => void;
8
+ };
9
+
10
+ /**
11
+ Invokes `fn` at most once per `wait` milliseconds.
12
+
13
+ The first call in a window fires immediately (leading edge). Calls made while
14
+ the window is open are coalesced into a single trailing invocation with the
15
+ latest arguments. Matches the lodash semantics Ink relied on: a single call
16
+ produces only a leading invocation, no trailing one.
17
+ */
18
+ export const throttle = <Arguments extends unknown[]>(
19
+ fn: (...args: Arguments) => void,
20
+ wait = 0,
21
+ ): Throttled<Arguments> => {
22
+ let timer: NodeJS.Timeout | undefined;
23
+ let pendingArgs: Arguments | undefined;
24
+
25
+ const invokePending = (): void => {
26
+ const args = pendingArgs!;
27
+ pendingArgs = undefined;
28
+ fn(...args);
29
+ };
30
+
31
+ const onTimer = (): void => {
32
+ if (pendingArgs) {
33
+ invokePending();
34
+ timer = setTimeout(onTimer, wait);
35
+ } else {
36
+ timer = undefined;
37
+ }
38
+ };
39
+
40
+ const throttled = (...args: Arguments): void => {
41
+ if (timer) {
42
+ pendingArgs = args;
43
+ return;
44
+ }
45
+
46
+ fn(...args);
47
+ timer = setTimeout(onTimer, wait);
48
+ };
49
+
50
+ throttled.cancel = (): void => {
51
+ if (timer) {
52
+ clearTimeout(timer);
53
+ timer = undefined;
54
+ }
55
+
56
+ pendingArgs = undefined;
57
+ };
58
+
59
+ throttled.flush = (): void => {
60
+ if (!pendingArgs) {
61
+ return;
62
+ }
63
+
64
+ if (timer) {
65
+ clearTimeout(timer);
66
+ timer = undefined;
67
+ }
68
+
69
+ invokePending();
70
+ };
71
+
72
+ return throttled;
73
+ };
package/src/types.ts ADDED
@@ -0,0 +1,15 @@
1
+ // The two `type-fest` types Ink used, inlined (MIT, Sindre Sorhus).
2
+
3
+ /**
4
+ Allows creating a union type by combining primitive types and literal types
5
+ without sacrificing auto-completion in IDEs for the literal type part of the
6
+ union.
7
+ */
8
+ export type LiteralUnion<LiteralType, BaseType extends string | number> =
9
+ | LiteralType
10
+ | (BaseType & Record<never, never>);
11
+
12
+ /**
13
+ Create a type from an object type without certain keys.
14
+ */
15
+ export type Except<ObjectType, KeysType extends keyof ObjectType> = Omit<ObjectType, KeysType>;
package/src/utils.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type { OutputStream } from "./stream.ts";
2
+ import { terminalSize } from "./terminal-size.ts";
3
+
4
+ const resolveDimension = (
5
+ value: number | undefined,
6
+ fallback: number | undefined,
7
+ defaultValue: number,
8
+ ): number => {
9
+ if (value !== undefined && value > 0) {
10
+ return value;
11
+ }
12
+
13
+ if (fallback !== undefined && fallback > 0) {
14
+ return fallback;
15
+ }
16
+
17
+ return defaultValue;
18
+ };
19
+
20
+ /**
21
+ Get the effective terminal dimensions from the given stdout stream.
22
+
23
+ Falls back to `terminal-size` for columns in piped processes where `stdout.columns` is 0, and uses standard defaults (80×24) when dimensions cannot be determined.
24
+ */
25
+ export const getWindowSize = (stdout: OutputStream): { columns: number; rows: number } => {
26
+ // `stdout.columns`/`rows` can be 0 or undefined in non-TTY environments.
27
+ const columns = stdout.columns ?? 0;
28
+ const rows = stdout.rows ?? 0;
29
+
30
+ if (columns && rows) {
31
+ return { columns, rows };
32
+ }
33
+
34
+ const fallbackSize = terminalSize();
35
+
36
+ return {
37
+ columns: resolveDimension(columns, fallbackSize.columns, 80),
38
+ rows: resolveDimension(rows, fallbackSize.rows, 24),
39
+ };
40
+ };
@@ -0,0 +1,50 @@
1
+ import { cliTruncate } from "./ansi/truncate.ts";
2
+ import { wrapAnsi } from "./ansi/wrap.ts";
3
+ import { QuickLru as QuickLRU } from "./quick-lru.ts";
4
+ import { type Styles } from "./styles.ts";
5
+
6
+ export const wrapTextCache = new QuickLRU<string, string>({ maxSize: 4096 });
7
+
8
+ export const wrapText = (text: string, maxWidth: number, wrapType: Styles["textWrap"]): string => {
9
+ const cacheKey = text + String(maxWidth) + String(wrapType);
10
+ const cachedText = wrapTextCache.get(cacheKey);
11
+
12
+ if (cachedText !== undefined) {
13
+ return cachedText;
14
+ }
15
+
16
+ let wrappedText = text;
17
+
18
+ if (wrapType === "wrap") {
19
+ wrappedText = wrapAnsi(text, maxWidth, {
20
+ trim: false,
21
+ hard: true,
22
+ });
23
+ }
24
+
25
+ if (wrapType === "hard") {
26
+ wrappedText = wrapAnsi(text, maxWidth, {
27
+ trim: false,
28
+ hard: true,
29
+ wordWrap: false,
30
+ });
31
+ }
32
+
33
+ if (wrapType!.startsWith("truncate")) {
34
+ let position: "end" | "middle" | "start" = "end";
35
+
36
+ if (wrapType === "truncate-middle") {
37
+ position = "middle";
38
+ }
39
+
40
+ if (wrapType === "truncate-start") {
41
+ position = "start";
42
+ }
43
+
44
+ wrappedText = cliTruncate(text, maxWidth, { position });
45
+ }
46
+
47
+ wrapTextCache.set(cacheKey, wrappedText);
48
+
49
+ return wrappedText;
50
+ };
@@ -0,0 +1,9 @@
1
+ import { isInCi } from "./is-in-ci.ts";
2
+
3
+ export function shouldSynchronize(stream: NodeJS.WritableStream, interactive?: boolean): boolean {
4
+ return (
5
+ "isTTY" in stream &&
6
+ (stream as NodeJS.WritableStream & { isTTY: boolean }).isTTY &&
7
+ (interactive ?? !isInCi)
8
+ );
9
+ }
@@ -0,0 +1,57 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Derived from Yoga. See THIRD_PARTY_NOTICES.md.
3
+
4
+ import { Config as CoreConfig } from "./core/config.ts";
5
+ import type { Errata, ExperimentalFeature } from "./generated/YGEnums.ts";
6
+
7
+ /**
8
+ * Public Config wrapper over the core config, exposing the same surface as
9
+ * the WASM binding's ConfigImpl.
10
+ */
11
+ export class Config {
12
+ /** @internal */
13
+ core: CoreConfig = new CoreConfig();
14
+
15
+ static create(): Config {
16
+ return new Config();
17
+ }
18
+
19
+ /**
20
+ @deprecated No-op in the TypeScript port: the garbage collector owns this
21
+ config's lifetime. Kept only for yoga-layout binding compatibility.
22
+ */
23
+ free(): void {
24
+ // No-op.
25
+ }
26
+
27
+ setExperimentalFeatureEnabled(feature: ExperimentalFeature, enabled: boolean): void {
28
+ this.core.setExperimentalFeatureEnabled(feature, enabled);
29
+ }
30
+
31
+ isExperimentalFeatureEnabled(feature: ExperimentalFeature): boolean {
32
+ return this.core.isExperimentalFeatureEnabled(feature);
33
+ }
34
+
35
+ setPointScaleFactor(factor: number): void {
36
+ if (!(factor >= 0)) {
37
+ throw new Error("Scale factor should not be less than zero");
38
+ }
39
+ this.core.setPointScaleFactor(factor);
40
+ }
41
+
42
+ getErrata(): Errata {
43
+ return this.core.getErrata();
44
+ }
45
+
46
+ setErrata(errata: Errata): void {
47
+ this.core.setErrata(errata);
48
+ }
49
+
50
+ useWebDefaults(): boolean {
51
+ return this.core.useWebDefaults();
52
+ }
53
+
54
+ setUseWebDefaults(useWebDefaults: boolean): void {
55
+ this.core.setUseWebDefaults(useWebDefaults);
56
+ }
57
+ }