@alchemy.run/sigil 0.0.0-alpha.4 → 0.0.0-alpha.5

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 (137) hide show
  1. package/README.md +21 -9
  2. package/THIRD_PARTY_NOTICES.md +39 -1
  3. package/dist/Text-D5HUf3Fj.d.ts +452 -0
  4. package/dist/ansi.d.ts +122 -131
  5. package/dist/ansi.js +86 -6
  6. package/dist/capabilities.d.ts +5 -0
  7. package/dist/capabilities.js +3 -0
  8. package/dist/cell-_ZVhbfl0.js +44 -0
  9. package/dist/color-CkbalRqK.js +2 -0
  10. package/dist/color-policy-BMzMwV7Q.d.ts +22 -0
  11. package/dist/color-policy-SVj1pYTA.js +560 -0
  12. package/dist/color-profile-DHhQHY55.js +36 -0
  13. package/dist/color-profile-u0Nhe9Nv.d.ts +97 -0
  14. package/dist/color.d.ts +21 -0
  15. package/dist/color.js +3 -0
  16. package/dist/cursor-position-D2LAkRG0.d.ts +7 -0
  17. package/dist/detect-Bh4yGP6w.d.ts +186 -0
  18. package/dist/detect-BuTXtY6e.js +373 -0
  19. package/dist/env-YVw64yZS.js +9 -0
  20. package/dist/escapes-CB_6CWOE.d.ts +72 -0
  21. package/dist/geometry-BxXOzJgo.d.ts +11 -0
  22. package/dist/index-Bmc2tRPk.d.ts +21 -0
  23. package/dist/index.d.ts +143 -498
  24. package/dist/index.js +1016 -2242
  25. package/dist/osc-CCH7xDoS.js +71 -0
  26. package/dist/osc-Cn0fw77g.d.ts +23 -0
  27. package/dist/paint-C19minOS.d.ts +81 -0
  28. package/dist/query-vaIeGOkH.d.ts +152 -0
  29. package/dist/router.d.ts +392 -0
  30. package/dist/router.js +709 -0
  31. package/dist/sample-Cqw1bjUL.js +445 -0
  32. package/dist/screen-BOh__-65.js +324 -0
  33. package/dist/screen-BReKIheE.d.ts +40 -0
  34. package/dist/screen.d.ts +5 -0
  35. package/dist/screen.js +5 -0
  36. package/dist/semantic-text-style-DIMzC7xt.js +91 -0
  37. package/dist/serialize-BTkAZgw1.js +79 -0
  38. package/dist/session-BJmzX2NJ.js +664 -0
  39. package/dist/sgr-BhwaWAJB.js +246 -0
  40. package/dist/store-CgrG9K4y.d.ts +72 -0
  41. package/dist/string-width-CijQwpIk.js +69 -0
  42. package/dist/strip-BvU4toXG.js +6 -0
  43. package/dist/terminal.d.ts +118 -0
  44. package/dist/terminal.js +2 -0
  45. package/dist/tokenize-AjqbvtiT.js +1242 -0
  46. package/dist/tokenize-Dx1y_l5H.d.ts +57 -0
  47. package/dist/truncate-D31fhU6i.js +562 -0
  48. package/dist/use-focus-C2sciZOo.js +1335 -0
  49. package/package.json +41 -9
  50. package/src/ansi/chalk.ts +5 -3
  51. package/src/ansi/escapes.ts +14 -0
  52. package/src/ansi/graphemes.ts +8 -0
  53. package/src/ansi/hyperlink.ts +44 -0
  54. package/src/ansi/index.ts +3 -1
  55. package/src/ansi/osc.ts +77 -0
  56. package/src/ansi/tokenize.ts +3 -4
  57. package/src/capabilities/color-policy.ts +34 -0
  58. package/src/capabilities/detect.ts +594 -0
  59. package/src/capabilities/index.ts +37 -0
  60. package/src/capabilities/query.ts +657 -0
  61. package/src/capabilities/store.ts +379 -0
  62. package/src/color/index.ts +3 -0
  63. package/src/color/paint.ts +169 -0
  64. package/src/color/palette.ts +48 -0
  65. package/src/color/sample.ts +323 -0
  66. package/src/color.ts +1 -0
  67. package/src/components/AnsiText.tsx +42 -0
  68. package/src/components/App.tsx +98 -10
  69. package/src/components/BackgroundContext.ts +2 -3
  70. package/src/components/Box.tsx +0 -8
  71. package/src/components/CursorContext.ts +1 -1
  72. package/src/components/Hyperlink.tsx +56 -0
  73. package/src/components/TerminalOscContext.ts +25 -0
  74. package/src/components/Text.tsx +21 -44
  75. package/src/components/Transform.tsx +1 -1
  76. package/src/dom.ts +5 -2
  77. package/src/global.d.ts +3 -0
  78. package/src/hooks/use-capabilities.ts +73 -0
  79. package/src/hooks/use-cursor.ts +2 -2
  80. package/src/hooks/use-terminal-osc.ts +59 -0
  81. package/src/index.ts +45 -1
  82. package/src/ink.tsx +213 -153
  83. package/src/{render-node-to-output.ts → paint-tree.ts} +71 -48
  84. package/src/reconciler.ts +24 -3
  85. package/src/render-background.ts +36 -15
  86. package/src/render-border.ts +94 -61
  87. package/src/render-frame.ts +83 -0
  88. package/src/render-to-string.ts +21 -6
  89. package/src/render.ts +15 -6
  90. package/src/router/components.tsx +343 -0
  91. package/src/router/context.ts +41 -0
  92. package/src/router/history.ts +194 -0
  93. package/src/router/hooks.tsx +391 -0
  94. package/src/router/index.ts +34 -0
  95. package/src/router/matcher.ts +571 -0
  96. package/src/screen/ansi.ts +184 -0
  97. package/src/screen/canvas.ts +137 -0
  98. package/src/screen/cell.ts +138 -0
  99. package/src/screen/color-profile.ts +47 -0
  100. package/src/screen/geometry.ts +9 -0
  101. package/src/screen/index.ts +6 -0
  102. package/src/screen/screen.ts +272 -0
  103. package/src/screen/serialize.ts +129 -0
  104. package/src/screen.ts +1 -0
  105. package/src/semantic-text-style.ts +118 -0
  106. package/src/squash-text-nodes.ts +2 -5
  107. package/src/structured-text.ts +321 -0
  108. package/src/styles.ts +12 -13
  109. package/src/terminal/index.ts +2 -0
  110. package/src/terminal/inline-presenter.ts +120 -0
  111. package/src/terminal/input.ts +86 -0
  112. package/src/terminal/render-scheduler.ts +37 -0
  113. package/src/terminal/screen-presenter.ts +188 -0
  114. package/src/terminal/session.ts +407 -0
  115. package/src/terminal.ts +1 -0
  116. package/src/testing/browser.ts +588 -0
  117. package/src/testing/emulators.ts +205 -0
  118. package/src/testing/explorer-app/index.html +12 -0
  119. package/src/testing/explorer-app/main.ts +381 -0
  120. package/src/testing/explorer-app/style.css +194 -0
  121. package/src/testing/explorer-app/tsconfig.json +15 -0
  122. package/src/testing/explorer-app/vite-env.d.ts +1 -0
  123. package/src/testing/index.ts +26 -0
  124. package/src/testing/keys.ts +56 -0
  125. package/src/testing/live.ts +85 -0
  126. package/src/testing/matchers.ts +70 -0
  127. package/src/testing/public.ts +94 -0
  128. package/src/testing/terminal.ts +349 -0
  129. package/src/testing/vitest.ts +157 -0
  130. package/src/transform-adapter.ts +14 -0
  131. package/dist/sgr-CMfEpjSk.d.ts +0 -91
  132. package/dist/truncate-Cr6xVFMa.js +0 -2330
  133. package/src/ansi/supports-color.ts +0 -207
  134. package/src/colorize.ts +0 -60
  135. package/src/log-update.ts +0 -370
  136. package/src/output.ts +0 -308
  137. package/src/renderer.ts +0 -73
@@ -0,0 +1,71 @@
1
+ import { D as cursorHide, b as OSC, j as cursorShow, x as ST } from "./sgr-BhwaWAJB.js";
2
+ import { c as signalExit } from "./detect-BuTXtY6e.js";
3
+ import { pathToFileURL } from "node:url";
4
+ //#region src/ansi/cursor.ts
5
+ let restoreRegistered = false;
6
+ const registerRestore = () => {
7
+ if (restoreRegistered) return;
8
+ restoreRegistered = true;
9
+ signalExit(() => {
10
+ process.stderr.write(cursorShow);
11
+ }, { alwaysLast: true });
12
+ };
13
+ const cliCursor = {
14
+ show(writableStream = process.stderr) {
15
+ if (!writableStream.isTTY) return;
16
+ writableStream.write(cursorShow);
17
+ },
18
+ hide(writableStream = process.stderr) {
19
+ if (!writableStream.isTTY) return;
20
+ registerRestore();
21
+ writableStream.write(cursorHide);
22
+ }
23
+ };
24
+ //#endregion
25
+ //#region src/ansi/osc.ts
26
+ const clipboardCode = {
27
+ clipboard: "c",
28
+ primary: "p",
29
+ selection: "s"
30
+ };
31
+ const progressCode = {
32
+ inactive: 0,
33
+ normal: 1,
34
+ error: 2,
35
+ indeterminate: 3,
36
+ paused: 4
37
+ };
38
+ const field = (value) => value.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
39
+ const command = (code, payload) => `${OSC}${code};${payload}${ST}`;
40
+ /** Change the terminal window title (OSC 2). */
41
+ const setWindowTitle = (title) => command(2, field(title));
42
+ /** Announce the current directory as a file URI (OSC 7). */
43
+ const setWorkingDirectory = (directory) => {
44
+ const uri = directory instanceof URL ? directory : directory.startsWith("file:") ? new URL(directory) : pathToFileURL(directory);
45
+ if (uri.protocol !== "file:") throw new Error("Terminal working directory must be a file URI");
46
+ return command(7, uri.href);
47
+ };
48
+ /** Show a desktop notification (OSC 9). */
49
+ const notify = (title) => {
50
+ const safe = field(title);
51
+ return command(9, /^\d+;/.test(safe) ? ` ${safe}` : safe);
52
+ };
53
+ /** Change the terminal pointer shape (OSC 22; terminal support varies). */
54
+ const setPointerShape = (shape) => command(22, field(shape));
55
+ /** Write UTF-8 text to a terminal clipboard using OSC 52. */
56
+ const setClipboard = (text, selection = "clipboard") => command(52, `${clipboardCode[selection]};${Buffer.from(text).toString("base64")}`);
57
+ /** Request clipboard contents. The response is another OSC 52 sequence. */
58
+ const queryClipboard = (selection = "clipboard") => command(52, `${clipboardCode[selection]};?`);
59
+ /** Clear a terminal clipboard. */
60
+ const clearClipboard = (selection = "clipboard") => command(52, `${clipboardCode[selection]};`);
61
+ /** Report terminal-native progress using OSC 9;4. */
62
+ const setTerminalProgress = (state, value) => {
63
+ const code = progressCode[state];
64
+ if (state === "inactive" || state === "indeterminate") return command(9, `4;${code}`);
65
+ if (value === void 0 && (state === "error" || state === "paused")) return command(9, `4;${code}`);
66
+ return command(9, `4;${code};${Math.max(0, Math.min(100, Math.round(value ?? 0)))}`);
67
+ };
68
+ /** Wrap a sequence for transport through tmux's DCS passthrough. */
69
+ const tmuxPassthrough = (sequence) => `Ptmux;${sequence.replaceAll("\x1B", ``)}${ST}`;
70
+ //#endregion
71
+ export { setPointerShape as a, setWorkingDirectory as c, setClipboard as i, tmuxPassthrough as l, notify as n, setTerminalProgress as o, queryClipboard as r, setWindowTitle as s, clearClipboard as t, cliCursor as u };
@@ -0,0 +1,23 @@
1
+ //#region src/ansi/osc.d.ts
2
+ type ClipboardSelection = "clipboard" | "primary" | "selection";
3
+ type TerminalProgressState = "inactive" | "normal" | "error" | "indeterminate" | "paused";
4
+ /** Change the terminal window title (OSC 2). */
5
+ declare const setWindowTitle: (title: string) => string;
6
+ /** Announce the current directory as a file URI (OSC 7). */
7
+ declare const setWorkingDirectory: (directory: URL | string) => string;
8
+ /** Show a desktop notification (OSC 9). */
9
+ declare const notify: (title: string) => string;
10
+ /** Change the terminal pointer shape (OSC 22; terminal support varies). */
11
+ declare const setPointerShape: (shape: string) => string;
12
+ /** Write UTF-8 text to a terminal clipboard using OSC 52. */
13
+ declare const setClipboard: (text: string, selection?: ClipboardSelection) => string;
14
+ /** Request clipboard contents. The response is another OSC 52 sequence. */
15
+ declare const queryClipboard: (selection?: ClipboardSelection) => string;
16
+ /** Clear a terminal clipboard. */
17
+ declare const clearClipboard: (selection?: ClipboardSelection) => string;
18
+ /** Report terminal-native progress using OSC 9;4. */
19
+ declare const setTerminalProgress: (state: TerminalProgressState, value?: number) => string;
20
+ /** Wrap a sequence for transport through tmux's DCS passthrough. */
21
+ declare const tmuxPassthrough: (sequence: string) => string;
22
+ //#endregion
23
+ export { queryClipboard as a, setTerminalProgress as c, tmuxPassthrough as d, notify as i, setWindowTitle as l, TerminalProgressState as n, setClipboard as o, clearClipboard as r, setPointerShape as s, ClipboardSelection as t, setWorkingDirectory as u };
@@ -0,0 +1,81 @@
1
+ import { c as TerminalAppearance } from "./detect-Bh4yGP6w.js";
2
+ import { c as Color, d as RgbColor, t as ColorProfile } from "./color-profile-u0Nhe9Nv.js";
3
+ //#region src/color/paint.d.ts
4
+ type ColorInput = Color | string;
5
+ type InterpolationSpace = "oklab" | "lab" | "rgb" | "hsv";
6
+ type GradientStop = {
7
+ readonly offset?: number;
8
+ readonly color: ColorInput;
9
+ };
10
+ type LinearGradient = {
11
+ readonly type: "linear-gradient";
12
+ readonly stops: readonly GradientStop[];
13
+ /** Degrees clockwise: 0 points left-to-right, 90 top-to-bottom. */
14
+ readonly angle: number;
15
+ readonly space: InterpolationSpace;
16
+ };
17
+ /** A one-dimensional gradient wrapped clockwise around a rectangle's edge. */
18
+ type PerimeterGradient = {
19
+ readonly type: "perimeter-gradient";
20
+ readonly stops: readonly GradientStop[];
21
+ /** Rotation in terminal cells, starting at the top-left corner. */
22
+ readonly offset: number;
23
+ readonly space: InterpolationSpace;
24
+ };
25
+ type AdaptiveColor = {
26
+ readonly type: "adaptive-color";
27
+ readonly light: ColorInput;
28
+ readonly dark: ColorInput;
29
+ };
30
+ type ProfileColor = {
31
+ readonly type: "profile-color";
32
+ readonly colors: Partial<Record<ColorProfile, ColorInput>>;
33
+ readonly fallback: ColorInput;
34
+ };
35
+ type Paint = ColorInput | LinearGradient | PerimeterGradient | AdaptiveColor | ProfileColor;
36
+ type PaintContext = {
37
+ readonly appearance?: TerminalAppearance;
38
+ readonly profile?: ColorProfile;
39
+ readonly palette?: readonly {
40
+ r: number;
41
+ g: number;
42
+ b: number;
43
+ }[];
44
+ };
45
+ declare const rgb: (red: number, green: number, blue: number, alpha?: number) => RgbColor;
46
+ declare const ansi: (index: number) => Color;
47
+ declare const ansi256: (index: number) => Color;
48
+ declare const namedIndexes: {
49
+ readonly black: 0;
50
+ readonly red: 1;
51
+ readonly green: 2;
52
+ readonly yellow: 3;
53
+ readonly blue: 4;
54
+ readonly magenta: 5;
55
+ readonly cyan: 6;
56
+ readonly white: 7;
57
+ readonly blackBright: 8;
58
+ readonly gray: 8;
59
+ readonly grey: 8;
60
+ readonly redBright: 9;
61
+ readonly greenBright: 10;
62
+ readonly yellowBright: 11;
63
+ readonly blueBright: 12;
64
+ readonly magentaBright: 13;
65
+ readonly cyanBright: 14;
66
+ readonly whiteBright: 15;
67
+ };
68
+ type NamedColor = keyof typeof namedIndexes;
69
+ declare const named: (color: NamedColor) => Color;
70
+ declare const adaptive: (light: ColorInput, dark: ColorInput) => AdaptiveColor;
71
+ declare const perProfile: (colors: Partial<Record<ColorProfile, ColorInput>>, fallback: ColorInput) => ProfileColor;
72
+ declare const linearGradient: (stops: readonly (GradientStop | ColorInput)[], options?: {
73
+ angle?: number;
74
+ space?: InterpolationSpace;
75
+ }) => LinearGradient;
76
+ declare const perimeterGradient: (stops: readonly ColorInput[], options?: {
77
+ offset?: number;
78
+ space?: InterpolationSpace;
79
+ }) => PerimeterGradient;
80
+ //#endregion
81
+ export { perimeterGradient as _, LinearGradient as a, PaintContext as c, adaptive as d, ansi as f, perProfile as g, named as h, InterpolationSpace as i, PerimeterGradient as l, linearGradient as m, ColorInput as n, NamedColor as o, ansi256 as p, GradientStop as r, Paint as s, AdaptiveColor as t, ProfileColor as u, rgb as v };
@@ -0,0 +1,152 @@
1
+ import { c as TerminalAppearance, s as RgbColor, t as Capabilities } from "./detect-Bh4yGP6w.js";
2
+ //#region src/capabilities/query.d.ts
3
+ type PixelSize = {
4
+ width: number;
5
+ height: number;
6
+ };
7
+ type TerminalQueryResult = {
8
+ foreground: RgbColor | undefined;
9
+ background: RgbColor | undefined;
10
+ cursorColor: RgbColor | undefined;
11
+ /**
12
+ The user's 16-color ANSI palette, when the terminal reports it.
13
+ */
14
+ palette: RgbColor[] | undefined;
15
+ /**
16
+ The terminal's own appearance, derived from the actual background color's
17
+ luminance — a dark terminal theme on a light OS stays "dark". Falls back
18
+ to the OS color scheme report when the background is unknown.
19
+ */
20
+ appearance: TerminalAppearance | undefined;
21
+ /**
22
+ The operating system's color preference, from the color scheme report
23
+ (`CSI ? 996 n`). Independent of the terminal's own theme.
24
+ */
25
+ systemAppearance: TerminalAppearance | undefined;
26
+ /**
27
+ The terminal answered the kitty keyboard protocol query.
28
+ */
29
+ kittyKeyboard: boolean;
30
+ /**
31
+ The terminal answered the kitty graphics protocol probe.
32
+ */
33
+ kittyGraphics: boolean;
34
+ /**
35
+ The terminal reports sixel graphics in its DA1 device attributes.
36
+ */
37
+ sixel: boolean;
38
+ /**
39
+ Raw DA1 device attribute parameters, for capabilities not modeled here.
40
+ */
41
+ deviceAttributes: number[] | undefined;
42
+ /**
43
+ The terminal confirmed truecolor via XTGETTCAP ("RGB").
44
+ */
45
+ trueColor: boolean;
46
+ /**
47
+ Focus in/out reporting (mode 1004).
48
+ */
49
+ focusEvents: boolean;
50
+ /**
51
+ SGR mouse reporting (mode 1006).
52
+ */
53
+ sgrMouse: boolean;
54
+ /**
55
+ SGR pixel-precision mouse reporting (mode 1016).
56
+ */
57
+ sgrPixelMouse: boolean;
58
+ /**
59
+ Bracketed paste (mode 2004).
60
+ */
61
+ bracketedPaste: boolean;
62
+ /**
63
+ Synchronized output (mode 2026).
64
+ */
65
+ synchronizedOutput: boolean;
66
+ /**
67
+ Grapheme cluster width handling (mode 2027).
68
+ */
69
+ graphemeClustering: boolean;
70
+ /**
71
+ Push notifications of light/dark scheme changes (mode 2031).
72
+ */
73
+ colorSchemeUpdates: boolean;
74
+ /**
75
+ In-band window resize notifications (mode 2048).
76
+ */
77
+ inBandResize: boolean;
78
+ /**
79
+ Text area size in pixels (XTWINOPS 14).
80
+ */
81
+ textAreaPixels: PixelSize | undefined;
82
+ /**
83
+ Size of a single character cell in pixels (XTWINOPS 16).
84
+ */
85
+ cellPixels: PixelSize | undefined;
86
+ /**
87
+ The terminal's self-reported name and version (XTVERSION).
88
+ */
89
+ terminal: {
90
+ raw: string;
91
+ name: string | undefined;
92
+ version: string | undefined;
93
+ } | undefined;
94
+ };
95
+ type TerminalQueryOptions = {
96
+ /**
97
+ How long to wait for the DA1 sentinel before giving up, in milliseconds.
98
+ */
99
+ timeout?: number;
100
+ /**
101
+ Also query the 16-color palette (16 extra OSC 4 queries).
102
+
103
+ @default true
104
+ */
105
+ palette?: boolean;
106
+ /**
107
+ Which queries to send. `"full"` asks everything; `"dynamic"` asks only the
108
+ facts that change over a session — colors/theme and pixel geometry — and
109
+ is what `refreshTerminalQuery` uses. Mode support, protocol support, and
110
+ the terminal's identity are static and never need re-asking.
111
+
112
+ @default "full"
113
+ */
114
+ scope?: "full" | "dynamic";
115
+ };
116
+ /**
117
+ Sends a batch of terminal queries and collects the responses. Resolves when
118
+ the terminal answers the DA1 sentinel, or after `timeout` with whatever was
119
+ gathered. Stdin bytes that are not query responses are pushed back into the
120
+ stream.
121
+
122
+ The query is lazy: nothing is sent until something asks. Inside an Ink app,
123
+ use `useCapabilities` — it triggers the query through Ink's input pipeline so
124
+ responses can't collide with key handling. Call this directly only outside of
125
+ Ink, before any other stdin consumer is attached.
126
+ */
127
+ declare const queryTerminal: (stdin: NodeJS.ReadableStream, stdout: {
128
+ write: (data: string) => unknown;
129
+ }, { timeout, palette, scope }?: TerminalQueryOptions) => Promise<TerminalQueryResult>;
130
+ /**
131
+ The completed query result for a stdout stream, if the query has finished.
132
+ */
133
+ declare const getTerminalQuery: (stdout: object) => TerminalQueryResult | undefined;
134
+ /**
135
+ Re-asks the terminal only the dynamic questions — colors/theme and pixel
136
+ geometry, which change when the user switches themes or resizes — and merges
137
+ the answers into the cached result. Static facts (mode and protocol support,
138
+ identity) are kept from the original query. Falls back to a full query when
139
+ none has completed yet; concurrent refreshes share one round-trip.
140
+ */
141
+ declare const refreshTerminalQuery: (stdin: NodeJS.ReadableStream, stdout: {
142
+ write: (data: string) => unknown;
143
+ }, options?: TerminalQueryOptions) => Promise<TerminalQueryResult>;
144
+ /**
145
+ Merges an async query result into a synchronous capabilities snapshot,
146
+ producing the complete picture. The query is authoritative where it answered:
147
+ a terminal that confirms truecolor via XTGETTCAP upgrades the sniffed color
148
+ level.
149
+ */
150
+ declare const applyTerminalQuery: (capabilities: Capabilities, query: TerminalQueryResult) => Capabilities;
151
+ //#endregion
152
+ export { getTerminalQuery as a, applyTerminalQuery as i, TerminalQueryOptions as n, queryTerminal as o, TerminalQueryResult as r, refreshTerminalQuery as s, PixelSize as t };