@simon_he/vue-tui 0.0.8 → 1.0.0

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 (249) hide show
  1. package/README.md +142 -30
  2. package/dist/TSelect-BwJJbuTt.js +6089 -0
  3. package/dist/TTree-DK_DQBYm.js +6480 -0
  4. package/dist/agent.cjs +39416 -0
  5. package/dist/agent.d.cts +44 -0
  6. package/dist/agent.d.ts +44 -0
  7. package/dist/agent.js +828 -0
  8. package/dist/ansi-palette-CNXqFciC.js +57 -0
  9. package/dist/ansi-styles.d.ts +200 -0
  10. package/dist/block-source-CKUOnkgT.js +1663 -0
  11. package/dist/cli/headless-renderer.d.ts +29 -0
  12. package/dist/cli/input.d.ts +49 -0
  13. package/dist/cli/node-file-writers.d.ts +13 -0
  14. package/dist/cli/node-module.d.ts +2 -0
  15. package/dist/cli/parse-kitty.d.ts +2 -0
  16. package/dist/cli/parse-mouse.d.ts +2 -0
  17. package/dist/cli/parse-utils.d.ts +14 -0
  18. package/dist/cli/parse-xterm.d.ts +2 -0
  19. package/dist/cli/path-provider-types.d.ts +1 -0
  20. package/dist/cli/path-provider.d.ts +4 -0
  21. package/dist/cli/path-suggest-core.d.ts +1 -0
  22. package/dist/cli/path-suggest.d.ts +15 -0
  23. package/dist/cli/recording.d.ts +4 -0
  24. package/dist/cli/stdin-buffer.d.ts +33 -0
  25. package/dist/cli.cjs +11061 -0
  26. package/dist/cli.d.cts +23 -0
  27. package/dist/cli.d.ts +23 -0
  28. package/dist/cli.js +9875 -0
  29. package/dist/core/ansi/capability.d.ts +20 -0
  30. package/dist/core/ansi/colors.d.ts +41 -0
  31. package/dist/core/ansi/sgr.d.ts +7 -0
  32. package/dist/core/ansi/theme.d.ts +6 -0
  33. package/dist/core/ansi-palette.d.ts +14 -0
  34. package/dist/core/buffer/buffer.d.ts +54 -0
  35. package/dist/core/buffer/width.d.ts +4 -0
  36. package/dist/core/debug-logger.d.ts +18 -0
  37. package/dist/core/hyperlink.d.ts +9 -0
  38. package/dist/core/index.d.ts +4 -0
  39. package/dist/core/path-provider-types.d.ts +24 -0
  40. package/dist/core/path-suggest.d.ts +35 -0
  41. package/dist/core/render-plane.d.ts +3 -0
  42. package/dist/core/terminal/create-terminal.d.ts +8 -0
  43. package/dist/core/terminal/emitter.d.ts +7 -0
  44. package/dist/core/types.d.ts +107 -0
  45. package/dist/core.cjs +3153 -0
  46. package/dist/core.d.cts +14 -0
  47. package/dist/core.d.ts +14 -0
  48. package/dist/core.js +424 -0
  49. package/dist/create-terminal-C2oiWFJU.js +1434 -0
  50. package/dist/create-terminal-app.d.ts +36 -0
  51. package/dist/dom-renderer-BqGijQID.js +1173 -0
  52. package/dist/env-Cl8qmNFN.js +19 -0
  53. package/dist/events/index.d.ts +6 -0
  54. package/dist/events/manager/cli-event-manager.d.ts +22 -0
  55. package/dist/events/manager/event-manager.d.ts +30 -0
  56. package/dist/events/manager/selection-suppression.d.ts +3 -0
  57. package/dist/events/manager/types.d.ts +108 -0
  58. package/dist/events/recording.d.ts +44 -0
  59. package/dist/experimental.cjs +4412 -1641
  60. package/dist/experimental.d.cts +42 -0
  61. package/dist/experimental.d.ts +42 -825
  62. package/dist/experimental.js +31 -7392
  63. package/dist/frame-perf-C6Xfg85O.js +24 -0
  64. package/dist/hyperlink-Bn02UXJb.js +419 -0
  65. package/dist/index.cjs +14765 -17582
  66. package/dist/index.d.cts +35 -0
  67. package/dist/index.d.ts +35 -1528
  68. package/dist/index.js +17 -20026
  69. package/dist/linkify-D_gzn9Xq.js +562 -0
  70. package/dist/markdown.cjs +9321 -7623
  71. package/dist/markdown.d.cts +11 -0
  72. package/dist/markdown.d.ts +11 -112
  73. package/dist/markdown.js +36 -1427
  74. package/dist/observability/cli-latency-node.d.ts +3 -0
  75. package/dist/observability/cli-latency-types.d.ts +41 -0
  76. package/dist/observability/cli-latency.d.ts +3 -0
  77. package/dist/observability/frame-perf-store.d.ts +18 -0
  78. package/dist/observability/frame-perf.d.ts +40 -0
  79. package/dist/observability/perf-sink.d.ts +56 -0
  80. package/dist/observability/trace.d.ts +40 -0
  81. package/dist/observability/tui-profiler.d.ts +33 -0
  82. package/dist/observability.cjs +221 -0
  83. package/dist/observability.d.cts +8 -0
  84. package/dist/observability.d.ts +8 -0
  85. package/dist/observability.js +4 -0
  86. package/dist/path-mnSgEpCm.js +81 -0
  87. package/dist/path-suggest-BNqcuE3-.js +274 -0
  88. package/dist/path-suggest-Dk9TRLh5.js +3 -0
  89. package/dist/{path-suggest-DmrmeueH.js → path-suggest-bvR9SY6Q.js} +86 -18
  90. package/dist/renderer/capabilities.d.ts +13 -0
  91. package/dist/renderer/cli/index.d.ts +2 -0
  92. package/dist/renderer/cli/stdout-metrics.d.ts +18 -0
  93. package/dist/renderer/cli/stdout-renderer.d.ts +48 -0
  94. package/dist/renderer/dom/dom-renderer.d.ts +157 -0
  95. package/dist/renderer/dom/index.d.ts +2 -0
  96. package/dist/renderer/index.d.ts +2 -0
  97. package/dist/renderer-dom.cjs +1505 -0
  98. package/dist/renderer-dom.d.cts +4 -0
  99. package/dist/renderer-dom.d.ts +4 -0
  100. package/dist/renderer-dom.js +7 -0
  101. package/dist/runtime/index.d.ts +36 -0
  102. package/dist/runtime/osc52.d.ts +9 -0
  103. package/dist/runtime-rfcZCyJq.js +1197 -0
  104. package/dist/runtime.cjs +1698 -0
  105. package/dist/runtime.d.cts +9 -0
  106. package/dist/runtime.d.ts +9 -0
  107. package/dist/runtime.js +4 -0
  108. package/dist/selection/terminal-selection.d.ts +123 -0
  109. package/dist/sgr-BmzxEjAO.js +304 -0
  110. package/dist/terminal-selection-DBinO6p5.js +330 -0
  111. package/dist/tlog-theme-qPBt5rge.js +9254 -0
  112. package/dist/trace-CjzYeIxN.js +182 -0
  113. package/dist/utils/env.d.ts +3 -0
  114. package/dist/utils/grapheme.d.ts +5 -0
  115. package/dist/utils/newlines.d.ts +1 -0
  116. package/dist/utils/path.d.ts +7 -0
  117. package/dist/utils/url-safety.d.ts +2 -0
  118. package/dist/vue/agent/view-models.d.ts +98 -0
  119. package/dist/vue/components/TAnchor.d.ts +108 -0
  120. package/dist/vue/components/TBox.d.ts +144 -0
  121. package/dist/vue/components/TCommandPalette.d.ts +587 -0
  122. package/dist/vue/components/TDataTable.d.ts +367 -0
  123. package/dist/vue/components/TDebugOverlay.d.ts +43 -0
  124. package/dist/vue/components/TDialog.d.ts +255 -0
  125. package/dist/vue/components/TFeedback.d.ts +635 -0
  126. package/dist/vue/components/TFlow.d.ts +85 -0
  127. package/dist/vue/components/TForm.d.ts +1230 -0
  128. package/dist/vue/components/TInput.d.ts +545 -0
  129. package/dist/vue/components/TInputBox.d.ts +158 -0
  130. package/dist/vue/components/TJsonEditor.d.ts +165 -0
  131. package/dist/vue/components/TLink.d.ts +239 -0
  132. package/dist/vue/components/TLinkifyText.d.ts +141 -0
  133. package/dist/vue/components/TList.d.ts +119 -0
  134. package/dist/vue/components/TLogLinksPanel.d.ts +238 -0
  135. package/dist/vue/components/TLogMinimap.d.ts +263 -0
  136. package/dist/vue/components/TLogScrollbar.d.ts +236 -0
  137. package/dist/vue/components/TLogSearchBar.d.ts +267 -0
  138. package/dist/vue/components/TLogSearchPager.d.ts +162 -0
  139. package/dist/vue/components/TLogSearchResults.d.ts +200 -0
  140. package/dist/vue/components/TLogView.d.ts +536 -0
  141. package/dist/vue/components/TLogVirtualLinksPanel.d.ts +141 -0
  142. package/dist/vue/components/TLogVirtualSearchResults.d.ts +146 -0
  143. package/dist/vue/components/TMarkdownText.d.ts +134 -0
  144. package/dist/vue/components/TMultilineModal.d.ts +62 -0
  145. package/dist/vue/components/TNavigation.d.ts +324 -0
  146. package/dist/vue/components/TOverlay.d.ts +366 -0
  147. package/dist/vue/components/TPanels.d.ts +244 -0
  148. package/dist/vue/components/TPathPicker.d.ts +213 -0
  149. package/dist/vue/components/TRenderLayer.d.ts +16 -0
  150. package/dist/vue/components/TRenderPlane.d.ts +17 -0
  151. package/dist/vue/components/TSelect.d.ts +335 -0
  152. package/dist/vue/components/TTable.d.ts +317 -0
  153. package/dist/vue/components/TText.d.ts +116 -0
  154. package/dist/vue/components/TThinkingView.d.ts +233 -0
  155. package/dist/vue/components/TToolCallView.d.ts +384 -0
  156. package/dist/vue/components/TTranscriptView.d.ts +221 -0
  157. package/dist/vue/components/TTransition.d.ts +83 -0
  158. package/dist/vue/components/TTree.d.ts +200 -0
  159. package/dist/vue/components/TUserMessageView.d.ts +344 -0
  160. package/dist/vue/components/TView.d.ts +127 -0
  161. package/dist/vue/components/TVirtualList.d.ts +182 -0
  162. package/dist/vue/components/TVirtualMarkdown.d.ts +168 -0
  163. package/dist/vue/components/TVirtualRows.d.ts +247 -0
  164. package/dist/vue/components/TerminalProvider.d.ts +218 -0
  165. package/dist/vue/components/input/host.d.ts +17 -0
  166. package/dist/vue/components/input/plugins/hostPlugin.d.ts +7 -0
  167. package/dist/vue/components/input/plugins/hostPlugin.node.d.ts +15 -0
  168. package/dist/vue/components/input/plugins/mentionUtils.d.ts +17 -0
  169. package/dist/vue/components/input/plugins/nodeMentionPathProvider.d.ts +2 -0
  170. package/dist/vue/components/input/plugins/promptMentionPlugin.d.ts +8 -0
  171. package/dist/vue/components/input/plugins/promptMentionState.d.ts +98 -0
  172. package/dist/vue/components/input/plugins/restrictText.d.ts +27 -0
  173. package/dist/vue/components/input/plugins/types.d.ts +90 -0
  174. package/dist/vue/components/input/utils/inlineText.d.ts +57 -0
  175. package/dist/vue/components/input/utils/inlineTextTokens.d.ts +34 -0
  176. package/dist/vue/components/input/utils/primitives.d.ts +3 -0
  177. package/dist/vue/components/input/utils/wordNavigation.d.ts +6 -0
  178. package/dist/vue/components/link/host.d.ts +15 -0
  179. package/dist/vue/components/list/list-geometry.d.ts +16 -0
  180. package/dist/vue/components/list/list-paint.d.ts +1 -0
  181. package/dist/vue/components/list/scroll-state.d.ts +25 -0
  182. package/dist/vue/components/list/selection-state.d.ts +6 -0
  183. package/dist/vue/components/simple-utils.d.ts +5 -0
  184. package/dist/vue/components/terminal-provider/copy-toast.d.ts +6 -0
  185. package/dist/vue/components/terminal-provider/portals.d.ts +17 -0
  186. package/dist/vue/components/terminal-provider/scheduler.d.ts +29 -0
  187. package/dist/vue/components/terminal-provider/selection-config.d.ts +15 -0
  188. package/dist/vue/components/terminal-provider/utils.d.ts +5 -0
  189. package/dist/vue/composables/use-layout.d.ts +2 -0
  190. package/dist/vue/composables/use-render-node.d.ts +19 -0
  191. package/dist/vue/composables/use-render-stack.d.ts +3 -0
  192. package/dist/vue/composables/use-runtime.d.ts +5 -0
  193. package/dist/vue/composables/use-terminal-node.d.ts +14 -0
  194. package/dist/vue/composables/use-terminal.d.ts +2 -0
  195. package/dist/vue/composables/use-visibility.d.ts +12 -0
  196. package/dist/vue/context.d.ts +153 -0
  197. package/dist/vue/index.d.ts +69 -0
  198. package/dist/vue/injection-key.d.ts +2 -0
  199. package/dist/vue/linkify.d.ts +11 -0
  200. package/dist/vue/log/append-only-log-store.d.ts +2 -0
  201. package/dist/vue/log/tlog-keymap.d.ts +28 -0
  202. package/dist/vue/log/tlog-plugins.d.ts +144 -0
  203. package/dist/vue/log/tlog-session.d.ts +81 -0
  204. package/dist/vue/log/tlog-theme.d.ts +68 -0
  205. package/dist/vue/log/types.d.ts +43 -0
  206. package/dist/vue/log/use-tlog-link-controller.d.ts +31 -0
  207. package/dist/vue/log/use-tlog-retained-index.d.ts +26 -0
  208. package/dist/vue/log/use-tlog-search-controller.d.ts +51 -0
  209. package/dist/vue/log/use-tlog-search-results-page.d.ts +31 -0
  210. package/dist/vue/log/use-tlog-virtual-search-results.d.ts +22 -0
  211. package/dist/vue/markdown/ast.d.ts +3 -0
  212. package/dist/vue/markdown/block-source.d.ts +22 -0
  213. package/dist/vue/markdown/document.d.ts +20 -0
  214. package/dist/vue/markdown/layout.d.ts +21 -0
  215. package/dist/vue/markdown/parser.d.ts +11 -0
  216. package/dist/vue/markdown/render.d.ts +10 -0
  217. package/dist/vue/markdown/theme.d.ts +186 -0
  218. package/dist/vue/markdown/types.d.ts +59 -0
  219. package/dist/vue/overlay.d.ts +27 -0
  220. package/dist/vue/render/context.d.ts +3 -0
  221. package/dist/vue/render/render-manager.d.ts +94 -0
  222. package/dist/vue/router/RouterView.d.ts +25 -0
  223. package/dist/vue/router/composables.d.ts +4 -0
  224. package/dist/vue/router/context.d.ts +4 -0
  225. package/dist/vue/router/router.d.ts +7 -0
  226. package/dist/vue/router/types.d.ts +29 -0
  227. package/dist/vue/scheduler/frame-mailbox.d.ts +55 -0
  228. package/dist/vue/scheduler/frame-scheduler.d.ts +51 -0
  229. package/dist/vue/theme.d.ts +48 -0
  230. package/dist/vue/transcript/hit-regions.d.ts +2 -0
  231. package/dist/vue/transcript/layout.d.ts +20 -0
  232. package/dist/vue/transcript/plain-text.d.ts +2 -0
  233. package/dist/vue/transcript/types.d.ts +122 -0
  234. package/dist/vue/utils/frame-task.d.ts +6 -0
  235. package/dist/vue/utils/rect.d.ts +4 -0
  236. package/dist/vue/utils/row-scroll.d.ts +25 -0
  237. package/dist/vue/utils/style-cache.d.ts +3 -0
  238. package/dist/vue/utils/text.d.ts +27 -0
  239. package/dist/vue/utils/wheel-scroll.d.ts +18 -0
  240. package/dist/vue.cjs +23668 -0
  241. package/dist/vue.d.cts +1 -0
  242. package/dist/vue.d.ts +1 -0
  243. package/dist/vue.js +3957 -0
  244. package/dist/{wheel-scroll-CiNsasLf.js → wheel-scroll-vBRaQ7p-.js} +404 -405
  245. package/package.json +185 -35
  246. package/dist/path-suggest-BeV6n7m-.js +0 -3
  247. package/dist/sgr-Tko2EQ0U.js +0 -484
  248. package/dist/theme-Bsm65g8k.d.ts +0 -32
  249. package/dist/types-ClIV2h1o.d.ts +0 -103
package/dist/core.cjs ADDED
@@ -0,0 +1,3153 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/core.ts
21
+ var core_exports = {};
22
+ __export(core_exports, {
23
+ ANSI16_COLORS: () => ANSI16_COLORS,
24
+ ANSI256_COLORS: () => ANSI256_COLORS,
25
+ ANSI8_COLORS: () => ANSI8_COLORS,
26
+ SGR_RESET: () => SGR_RESET,
27
+ TERMINAL_RENDER_PLANES: () => TERMINAL_RENDER_PLANES,
28
+ ansiColors: () => ansiColors,
29
+ ansiStyles: () => ansiStyles,
30
+ charCellWidth: () => charCellWidth,
31
+ createTerminal: () => createTerminal,
32
+ detectTerminalColorCapability: () => detectTerminalColorCapability,
33
+ isSafeRelativeHref: () => isSafeRelativeHref,
34
+ normalizeNewlines: () => normalizeNewlines,
35
+ parseAnsiSgr: () => parseAnsiSgr,
36
+ parsePathQuery: () => parsePathQuery,
37
+ resolveUserPath: () => resolveUserPath,
38
+ rgbToAnsi256: () => rgbToAnsi256,
39
+ sanitizeDomHref: () => sanitizeDomHref,
40
+ sanitizeTerminalHref: () => sanitizeTerminalHref,
41
+ suggestParentHint: () => suggestParentHint,
42
+ suggestPaths: () => suggestPaths,
43
+ truecolorBgOpen: () => truecolorBgOpen,
44
+ truecolorFgOpen: () => truecolorFgOpen
45
+ });
46
+ module.exports = __toCommonJS(core_exports);
47
+
48
+ // src/core/ansi-palette.ts
49
+ var ANSI_PALETTE_HEX = Object.freeze({
50
+ black: "#000000",
51
+ red: "#c91b00",
52
+ green: "#00c200",
53
+ yellow: "#c7c400",
54
+ blue: "#0225c7",
55
+ magenta: "#c930c7",
56
+ cyan: "#00c5c7",
57
+ white: "#c7c7c7",
58
+ blackBright: "#686868",
59
+ redBright: "#ff6e67",
60
+ greenBright: "#5ffa68",
61
+ yellowBright: "#fffc67",
62
+ blueBright: "#6871ff",
63
+ magentaBright: "#ff76ff",
64
+ cyanBright: "#5ffdff",
65
+ whiteBright: "#ffffff"
66
+ });
67
+ function ansiHexToRgb(hex) {
68
+ const h = hex.startsWith("#") ? hex.slice(1) : hex;
69
+ if (h.length !== 6)
70
+ return void 0;
71
+ const r = Number.parseInt(h.slice(0, 2), 16);
72
+ const g = Number.parseInt(h.slice(2, 4), 16);
73
+ const b = Number.parseInt(h.slice(4, 6), 16);
74
+ if (!Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b))
75
+ return void 0;
76
+ return { r, g, b };
77
+ }
78
+ var ANSI_PALETTE_RGB = Object.freeze(
79
+ Object.fromEntries(
80
+ Object.entries(ANSI_PALETTE_HEX).map(([k, v]) => [k, ansiHexToRgb(v)])
81
+ )
82
+ );
83
+ function isAnsiColorName(name) {
84
+ return typeof name === "string" && Object.prototype.hasOwnProperty.call(ANSI_PALETTE_HEX, name);
85
+ }
86
+ function ansiColorRgb(name, palette) {
87
+ if (!isAnsiColorName(name))
88
+ return void 0;
89
+ const custom = palette?.[name];
90
+ if (custom)
91
+ return ansiHexToRgb(custom) ?? ANSI_PALETTE_RGB[name];
92
+ return ANSI_PALETTE_RGB[name];
93
+ }
94
+
95
+ // src/core/ansi/colors.ts
96
+ var ANSI8_COLOR_NAMES = Object.freeze([
97
+ "black",
98
+ "red",
99
+ "green",
100
+ "yellow",
101
+ "blue",
102
+ "magenta",
103
+ "cyan",
104
+ "white"
105
+ ]);
106
+ var ANSI16_COLOR_NAMES = Object.freeze([
107
+ "black",
108
+ "red",
109
+ "green",
110
+ "yellow",
111
+ "blue",
112
+ "magenta",
113
+ "cyan",
114
+ "white",
115
+ "blackBright",
116
+ "redBright",
117
+ "greenBright",
118
+ "yellowBright",
119
+ "blueBright",
120
+ "magentaBright",
121
+ "cyanBright",
122
+ "whiteBright"
123
+ ]);
124
+ var ESC = "\x1B[";
125
+ var SGR_RESET = `${ESC}0m`;
126
+ var SGR_BOLD = `${ESC}1m`;
127
+ var SGR_DIM = `${ESC}2m`;
128
+ var SGR_ITALIC = `${ESC}3m`;
129
+ var SGR_UNDERLINE = `${ESC}4m`;
130
+ var SGR_INVERSE = `${ESC}7m`;
131
+ function toAnsi8ColorName(name) {
132
+ switch (name) {
133
+ case "black":
134
+ case "red":
135
+ case "green":
136
+ case "yellow":
137
+ case "blue":
138
+ case "magenta":
139
+ case "cyan":
140
+ case "white":
141
+ return name;
142
+ case "blackBright":
143
+ return "black";
144
+ case "redBright":
145
+ return "red";
146
+ case "greenBright":
147
+ return "green";
148
+ case "yellowBright":
149
+ return "yellow";
150
+ case "blueBright":
151
+ return "blue";
152
+ case "magentaBright":
153
+ return "magenta";
154
+ case "cyanBright":
155
+ return "cyan";
156
+ case "whiteBright":
157
+ return "white";
158
+ }
159
+ }
160
+ var ANSI16_FG_CODE = Object.freeze({
161
+ black: 30,
162
+ red: 31,
163
+ green: 32,
164
+ yellow: 33,
165
+ blue: 34,
166
+ magenta: 35,
167
+ cyan: 36,
168
+ white: 37,
169
+ blackBright: 90,
170
+ redBright: 91,
171
+ greenBright: 92,
172
+ yellowBright: 93,
173
+ blueBright: 94,
174
+ magentaBright: 95,
175
+ cyanBright: 96,
176
+ whiteBright: 97
177
+ });
178
+ var ANSI16_BG_CODE = Object.freeze({
179
+ black: 40,
180
+ red: 41,
181
+ green: 42,
182
+ yellow: 43,
183
+ blue: 44,
184
+ magenta: 45,
185
+ cyan: 46,
186
+ white: 47,
187
+ blackBright: 100,
188
+ redBright: 101,
189
+ greenBright: 102,
190
+ yellowBright: 103,
191
+ blueBright: 104,
192
+ magentaBright: 105,
193
+ cyanBright: 106,
194
+ whiteBright: 107
195
+ });
196
+ function ansi8FgOpen(name) {
197
+ const base = toAnsi8ColorName(name);
198
+ const idx = ANSI8_COLOR_NAMES.indexOf(base);
199
+ return `${ESC}${30 + (idx < 0 ? 7 : idx)}m`;
200
+ }
201
+ function ansi8BgOpen(name) {
202
+ const base = toAnsi8ColorName(name);
203
+ const idx = ANSI8_COLOR_NAMES.indexOf(base);
204
+ return `${ESC}${40 + (idx < 0 ? 0 : idx)}m`;
205
+ }
206
+ function ansi16FgOpen(name) {
207
+ return `${ESC}${ANSI16_FG_CODE[name]}m`;
208
+ }
209
+ function ansi16BgOpen(name) {
210
+ return `${ESC}${ANSI16_BG_CODE[name]}m`;
211
+ }
212
+ function ansi256FgOpen(index) {
213
+ const n = clampAnsiIndex(index);
214
+ return `${ESC}38;5;${n}m`;
215
+ }
216
+ function ansi256BgOpen(index) {
217
+ const n = clampAnsiIndex(index);
218
+ return `${ESC}48;5;${n}m`;
219
+ }
220
+ function truecolorFgOpen(rgb) {
221
+ return `${ESC}38;2;${clampByte(rgb.r)};${clampByte(rgb.g)};${clampByte(rgb.b)}m`;
222
+ }
223
+ function truecolorBgOpen(rgb) {
224
+ return `${ESC}48;2;${clampByte(rgb.r)};${clampByte(rgb.g)};${clampByte(rgb.b)}m`;
225
+ }
226
+ function ansi256ToRgb(index) {
227
+ const n = clampAnsiIndex(index);
228
+ if (n < 16) {
229
+ const name = ANSI16_COLOR_NAMES[n] ?? "white";
230
+ return ansiColorRgb(name) ?? { r: 255, g: 255, b: 255 };
231
+ }
232
+ if (n >= 232) {
233
+ const c = 8 + (n - 232) * 10;
234
+ return { r: c, g: c, b: c };
235
+ }
236
+ const i = n - 16;
237
+ const rr = Math.floor(i / 36);
238
+ const gg = Math.floor(i % 36 / 6);
239
+ const bb = i % 6;
240
+ const levels = [0, 95, 135, 175, 215, 255];
241
+ return { r: levels[rr], g: levels[gg], b: levels[bb] };
242
+ }
243
+ function rgbToAnsi256(rgb) {
244
+ const r = clampByte(rgb.r);
245
+ const g = clampByte(rgb.g);
246
+ const b = clampByte(rgb.b);
247
+ const levels = [0, 95, 135, 175, 215, 255];
248
+ const nearestLevelIndex = (v) => {
249
+ let best = 0;
250
+ let bestDist = Number.POSITIVE_INFINITY;
251
+ for (let i = 0; i < levels.length; i++) {
252
+ const d = (v - levels[i]) ** 2;
253
+ if (d < bestDist) {
254
+ bestDist = d;
255
+ best = i;
256
+ }
257
+ }
258
+ return best;
259
+ };
260
+ const ri = nearestLevelIndex(r);
261
+ const gi = nearestLevelIndex(g);
262
+ const bi = nearestLevelIndex(b);
263
+ const cubeIndex = 16 + 36 * ri + 6 * gi + bi;
264
+ const cube = ansi256ToRgb(cubeIndex);
265
+ const cubeDist = (r - cube.r) ** 2 + (g - cube.g) ** 2 + (b - cube.b) ** 2;
266
+ const gray = Math.round((r + g + b) / 3);
267
+ const grayIndex = gray < 8 ? 16 : gray > 248 ? 231 : 232 + Math.round((gray - 8) / 10);
268
+ const grayRgb = ansi256ToRgb(grayIndex);
269
+ const grayDist = (r - grayRgb.r) ** 2 + (g - grayRgb.g) ** 2 + (b - grayRgb.b) ** 2;
270
+ return grayDist < cubeDist ? grayIndex : cubeIndex;
271
+ }
272
+ function ansi8Palette() {
273
+ return ANSI8_COLOR_NAMES.map((name, index) => {
274
+ const rgb = ansiColorRgb(name) ?? { r: 255, g: 255, b: 255 };
275
+ return Object.freeze({
276
+ level: 8,
277
+ index,
278
+ name,
279
+ rgb,
280
+ fgOpen: ansi8FgOpen(name),
281
+ bgOpen: ansi8BgOpen(name)
282
+ });
283
+ });
284
+ }
285
+ function ansi16Palette() {
286
+ return ANSI16_COLOR_NAMES.map((name, index) => {
287
+ const rgb = ansiColorRgb(name) ?? { r: 255, g: 255, b: 255 };
288
+ return Object.freeze({
289
+ level: 16,
290
+ index,
291
+ name,
292
+ rgb,
293
+ fgOpen: ansi16FgOpen(name),
294
+ bgOpen: ansi16BgOpen(name)
295
+ });
296
+ });
297
+ }
298
+ function ansi256Palette() {
299
+ const out = [];
300
+ for (let index = 0; index < 256; index++) {
301
+ out.push(
302
+ Object.freeze({
303
+ level: 256,
304
+ index,
305
+ rgb: ansi256ToRgb(index),
306
+ fgOpen: ansi256FgOpen(index),
307
+ bgOpen: ansi256BgOpen(index)
308
+ })
309
+ );
310
+ }
311
+ return Object.freeze(out);
312
+ }
313
+ function clampAnsiIndex(n) {
314
+ if (!Number.isFinite(n))
315
+ return 0;
316
+ return Math.max(0, Math.min(255, Math.trunc(n)));
317
+ }
318
+ function clampByte(n) {
319
+ if (!Number.isFinite(n))
320
+ return 0;
321
+ return Math.max(0, Math.min(255, Math.round(n)));
322
+ }
323
+
324
+ // src/ansi-styles.ts
325
+ var ESC2 = "\x1B[";
326
+ function createStyle(open, close) {
327
+ return Object.freeze({ open, close });
328
+ }
329
+ var ansiStyles = Object.freeze({
330
+ reset: createStyle(SGR_RESET, SGR_RESET),
331
+ bold: createStyle(SGR_BOLD, `${ESC2}22m`),
332
+ dim: createStyle(SGR_DIM, `${ESC2}22m`),
333
+ italic: createStyle(SGR_ITALIC, `${ESC2}23m`),
334
+ underline: createStyle(SGR_UNDERLINE, `${ESC2}24m`),
335
+ inverse: createStyle(SGR_INVERSE, `${ESC2}27m`),
336
+ // 16-color named helpers (common subset of `ansi-styles`).
337
+ black: createStyle(ansi16FgOpen("black"), `${ESC2}39m`),
338
+ red: createStyle(ansi16FgOpen("red"), `${ESC2}39m`),
339
+ green: createStyle(ansi16FgOpen("green"), `${ESC2}39m`),
340
+ yellow: createStyle(ansi16FgOpen("yellow"), `${ESC2}39m`),
341
+ blue: createStyle(ansi16FgOpen("blue"), `${ESC2}39m`),
342
+ magenta: createStyle(ansi16FgOpen("magenta"), `${ESC2}39m`),
343
+ cyan: createStyle(ansi16FgOpen("cyan"), `${ESC2}39m`),
344
+ white: createStyle(ansi16FgOpen("white"), `${ESC2}39m`),
345
+ blackBright: createStyle(ansi16FgOpen("blackBright"), `${ESC2}39m`),
346
+ redBright: createStyle(ansi16FgOpen("redBright"), `${ESC2}39m`),
347
+ greenBright: createStyle(ansi16FgOpen("greenBright"), `${ESC2}39m`),
348
+ yellowBright: createStyle(ansi16FgOpen("yellowBright"), `${ESC2}39m`),
349
+ blueBright: createStyle(ansi16FgOpen("blueBright"), `${ESC2}39m`),
350
+ magentaBright: createStyle(ansi16FgOpen("magentaBright"), `${ESC2}39m`),
351
+ cyanBright: createStyle(ansi16FgOpen("cyanBright"), `${ESC2}39m`),
352
+ whiteBright: createStyle(ansi16FgOpen("whiteBright"), `${ESC2}39m`),
353
+ bgBlack: createStyle(ansi16BgOpen("black"), `${ESC2}49m`),
354
+ bgRed: createStyle(ansi16BgOpen("red"), `${ESC2}49m`),
355
+ bgGreen: createStyle(ansi16BgOpen("green"), `${ESC2}49m`),
356
+ bgYellow: createStyle(ansi16BgOpen("yellow"), `${ESC2}49m`),
357
+ bgBlue: createStyle(ansi16BgOpen("blue"), `${ESC2}49m`),
358
+ bgMagenta: createStyle(ansi16BgOpen("magenta"), `${ESC2}49m`),
359
+ bgCyan: createStyle(ansi16BgOpen("cyan"), `${ESC2}49m`),
360
+ bgWhite: createStyle(ansi16BgOpen("white"), `${ESC2}49m`),
361
+ bgBlackBright: createStyle(ansi16BgOpen("blackBright"), `${ESC2}49m`),
362
+ bgRedBright: createStyle(ansi16BgOpen("redBright"), `${ESC2}49m`),
363
+ bgGreenBright: createStyle(ansi16BgOpen("greenBright"), `${ESC2}49m`),
364
+ bgYellowBright: createStyle(ansi16BgOpen("yellowBright"), `${ESC2}49m`),
365
+ bgBlueBright: createStyle(ansi16BgOpen("blueBright"), `${ESC2}49m`),
366
+ bgMagentaBright: createStyle(ansi16BgOpen("magentaBright"), `${ESC2}49m`),
367
+ bgCyanBright: createStyle(ansi16BgOpen("cyanBright"), `${ESC2}49m`),
368
+ bgWhiteBright: createStyle(ansi16BgOpen("whiteBright"), `${ESC2}49m`),
369
+ color: Object.freeze({
370
+ ansi256: (idx) => ansi256FgOpen(idx),
371
+ ansi16m: (r, g, b) => truecolorFgOpen({ r, g, b })
372
+ }),
373
+ bgColor: Object.freeze({
374
+ ansi256: (idx) => ansi256BgOpen(idx),
375
+ ansi16m: (r, g, b) => truecolorBgOpen({ r, g, b })
376
+ })
377
+ });
378
+ var ANSI8_COLORS = ansi8Palette();
379
+ var ANSI16_COLORS = ansi16Palette();
380
+ var ANSI256_COLORS = ansi256Palette();
381
+ function ansiColors(level) {
382
+ if (level === 8)
383
+ return ANSI8_COLORS;
384
+ if (level === 16)
385
+ return ANSI16_COLORS;
386
+ return ANSI256_COLORS;
387
+ }
388
+
389
+ // src/utils/env.ts
390
+ function firstNonEmptyEnv(env, primary, legacy) {
391
+ const primaryValue = env?.[primary];
392
+ if (String(primaryValue ?? "").trim() !== "")
393
+ return primaryValue;
394
+ if (!legacy)
395
+ return void 0;
396
+ const legacyValue = env?.[legacy];
397
+ if (String(legacyValue ?? "").trim() !== "")
398
+ return legacyValue;
399
+ return void 0;
400
+ }
401
+
402
+ // src/core/ansi/capability.ts
403
+ function parseColorMode(raw) {
404
+ const v = String(raw ?? "").trim().toLowerCase();
405
+ if (!v)
406
+ return null;
407
+ if (v === "truecolor" || v === "24bit" || v === "rgb")
408
+ return "truecolor";
409
+ if (v === "ansi256" || v === "256" || v === "xterm256" || v === "xterm-256color") {
410
+ return "ansi256";
411
+ }
412
+ if (v === "ansi16" || v === "16")
413
+ return "ansi16";
414
+ if (v === "ansi8" || v === "8")
415
+ return "ansi8";
416
+ return null;
417
+ }
418
+ function levelForMode(mode) {
419
+ if (mode === "ansi8")
420
+ return 8;
421
+ if (mode === "ansi16")
422
+ return 16;
423
+ return 256;
424
+ }
425
+ function detectTerminalColorCapability(opts) {
426
+ const env = opts?.env ?? {};
427
+ const isTTY = opts?.isTTY ?? false;
428
+ const platform = String(opts?.platform ?? "").trim().toLowerCase();
429
+ const isWindows = platform === "win32" || String(env.OS ?? "").trim().toLowerCase() === "windows_nt";
430
+ const forced = parseColorMode(firstNonEmptyEnv(env, "VUE_TUI_COLOR_MODE", "DIMCODE_COLOR_MODE"));
431
+ if (forced)
432
+ return { mode: forced, level: levelForMode(forced) };
433
+ if (!isTTY)
434
+ return { mode: "truecolor", level: 256 };
435
+ const termProgram = String(env.TERM_PROGRAM ?? "").toLowerCase();
436
+ const isAppleTerminal = termProgram.includes("apple_terminal");
437
+ const colorterm = String(env.COLORTERM ?? "").toLowerCase();
438
+ if (!isAppleTerminal && (colorterm.includes("truecolor") || colorterm.includes("24bit"))) {
439
+ return { mode: "truecolor", level: 256 };
440
+ }
441
+ if (termProgram.includes("vscode"))
442
+ return { mode: "truecolor", level: 256 };
443
+ if (termProgram.includes("wezterm") || termProgram.includes("alacritty") || termProgram.includes("ghostty") || termProgram.includes("kitty") || termProgram.includes("iterm") || termProgram.includes("windows terminal") || termProgram.includes("windowsterminal") || termProgram.includes("tabby") || termProgram.includes("hyper") || termProgram.includes("rio") || termProgram.includes("contour")) {
444
+ return { mode: "truecolor", level: 256 };
445
+ }
446
+ const term = String(env.TERM ?? "").toLowerCase();
447
+ if (isWindows) {
448
+ const hasWindowsTerminal = "WT_SESSION" in env || "WT_PROFILE_ID" in env || "WT_ID" in env;
449
+ const hasWezterm = "WEZTERM_EXECUTABLE" in env || "WEZTERM_PANE" in env;
450
+ const hasAlacritty = "ALACRITTY_LOG" in env || "ALACRITTY_WINDOW_ID" in env;
451
+ const hasTabby = "TABBY_CONFIG_DIRECTORY" in env;
452
+ if (hasWindowsTerminal || hasWezterm || hasAlacritty || hasTabby)
453
+ return { mode: "truecolor", level: 256 };
454
+ if (term.includes("xterm") && term.includes("256color"))
455
+ return { mode: "truecolor", level: 256 };
456
+ }
457
+ if (term.includes("256color"))
458
+ return { mode: "ansi256", level: 256 };
459
+ if (term.includes("color"))
460
+ return { mode: "ansi16", level: 16 };
461
+ if (term.includes("dumb"))
462
+ return { mode: "ansi8", level: 8 };
463
+ return { mode: "ansi16", level: 16 };
464
+ }
465
+
466
+ // src/core/ansi/sgr.ts
467
+ var ESC3 = "\x1B";
468
+ function ansi16ToColorName(code) {
469
+ switch (code) {
470
+ case 30:
471
+ return "black";
472
+ case 31:
473
+ return "red";
474
+ case 32:
475
+ return "green";
476
+ case 33:
477
+ return "yellow";
478
+ case 34:
479
+ return "blue";
480
+ case 35:
481
+ return "magenta";
482
+ case 36:
483
+ return "cyan";
484
+ case 37:
485
+ return "white";
486
+ case 90:
487
+ return "blackBright";
488
+ case 91:
489
+ return "redBright";
490
+ case 92:
491
+ return "greenBright";
492
+ case 93:
493
+ return "yellowBright";
494
+ case 94:
495
+ return "blueBright";
496
+ case 95:
497
+ return "magentaBright";
498
+ case 96:
499
+ return "cyanBright";
500
+ case 97:
501
+ return "whiteBright";
502
+ default:
503
+ return void 0;
504
+ }
505
+ }
506
+ function ansi16BgToColorName(code) {
507
+ const fgCode = code >= 40 && code <= 47 ? code - 10 : code >= 100 && code <= 107 ? code - 10 : null;
508
+ if (fgCode == null)
509
+ return void 0;
510
+ return ansi16ToColorName(fgCode);
511
+ }
512
+ var ANSI16_RGB = {
513
+ black: { r: 0, g: 0, b: 0 },
514
+ red: { r: 201, g: 27, b: 0 },
515
+ green: { r: 0, g: 194, b: 0 },
516
+ yellow: { r: 199, g: 196, b: 0 },
517
+ blue: { r: 2, g: 37, b: 199 },
518
+ magenta: { r: 201, g: 48, b: 199 },
519
+ cyan: { r: 0, g: 197, b: 199 },
520
+ white: { r: 199, g: 199, b: 199 },
521
+ blackBright: { r: 104, g: 104, b: 104 },
522
+ redBright: { r: 255, g: 110, b: 103 },
523
+ greenBright: { r: 95, g: 250, b: 104 },
524
+ yellowBright: { r: 255, g: 252, b: 103 },
525
+ blueBright: { r: 104, g: 113, b: 255 },
526
+ magentaBright: { r: 255, g: 118, b: 255 },
527
+ cyanBright: { r: 95, g: 253, b: 255 },
528
+ whiteBright: { r: 255, g: 255, b: 255 }
529
+ };
530
+ function nearestAnsi16(r, g, b) {
531
+ let best = "white";
532
+ let bestDist = Number.POSITIVE_INFINITY;
533
+ for (const [name, rgb] of Object.entries(ANSI16_RGB)) {
534
+ const dr = r - rgb.r;
535
+ const dg = g - rgb.g;
536
+ const db = b - rgb.b;
537
+ const d = dr * dr + dg * dg + db * db;
538
+ if (d < bestDist) {
539
+ bestDist = d;
540
+ best = name;
541
+ }
542
+ }
543
+ return best;
544
+ }
545
+ function ansi256ToRgb2(index) {
546
+ const n = Math.max(0, Math.min(255, Math.trunc(index)));
547
+ if (n < 16) {
548
+ const map = [
549
+ "black",
550
+ "red",
551
+ "green",
552
+ "yellow",
553
+ "blue",
554
+ "magenta",
555
+ "cyan",
556
+ "white",
557
+ "blackBright",
558
+ "redBright",
559
+ "greenBright",
560
+ "yellowBright",
561
+ "blueBright",
562
+ "magentaBright",
563
+ "cyanBright",
564
+ "whiteBright"
565
+ ];
566
+ const name = map[n] ?? "white";
567
+ return ANSI16_RGB[name];
568
+ }
569
+ if (n >= 232) {
570
+ const c = 8 + (n - 232) * 10;
571
+ return { r: c, g: c, b: c };
572
+ }
573
+ const i = n - 16;
574
+ const rr = Math.floor(i / 36);
575
+ const gg = Math.floor(i % 36 / 6);
576
+ const bb = i % 6;
577
+ const toComponent = (v) => v === 0 ? 0 : 55 + v * 40;
578
+ return { r: toComponent(rr), g: toComponent(gg), b: toComponent(bb) };
579
+ }
580
+ function applyAnsiSgrStyle(current, codes) {
581
+ let next = { ...current };
582
+ for (let i = 0; i < codes.length; i++) {
583
+ const code = codes[i];
584
+ if (code === 0) {
585
+ next = {};
586
+ continue;
587
+ }
588
+ if (code === 1) {
589
+ next = { ...next, bold: true };
590
+ } else if (code === 2) {
591
+ next = { ...next, dim: true };
592
+ } else if (code === 3) {
593
+ next = { ...next, italic: true };
594
+ } else if (code === 4) {
595
+ next = { ...next, underline: true };
596
+ } else if (code === 7) {
597
+ next = { ...next, inverse: true };
598
+ } else if (code === 22) {
599
+ next = { ...next, bold: false, dim: false };
600
+ } else if (code === 23) {
601
+ next = { ...next, italic: false };
602
+ } else if (code === 24) {
603
+ next = { ...next, underline: false };
604
+ } else if (code === 27) {
605
+ next = { ...next, inverse: false };
606
+ } else if (code === 39) {
607
+ next = { ...next, fg: void 0 };
608
+ } else if (code === 49) {
609
+ next = { ...next, bg: void 0 };
610
+ } else if (code >= 30 && code <= 37 || code >= 90 && code <= 97) {
611
+ const fg = ansi16ToColorName(code);
612
+ next = { ...next, fg: fg ?? next.fg };
613
+ } else if (code >= 40 && code <= 47 || code >= 100 && code <= 107) {
614
+ const bg = ansi16BgToColorName(code);
615
+ next = { ...next, bg: bg ?? next.bg };
616
+ } else if (code === 38 || code === 48) {
617
+ const mode = codes[i + 1];
618
+ if (mode === 5) {
619
+ const idx = codes[i + 2];
620
+ if (idx != null) {
621
+ const { r, g, b } = ansi256ToRgb2(idx);
622
+ const name = nearestAnsi16(r, g, b);
623
+ next = code === 38 ? { ...next, fg: name } : { ...next, bg: name };
624
+ }
625
+ i += 2;
626
+ } else if (mode === 2) {
627
+ const r = codes[i + 2];
628
+ const g = codes[i + 3];
629
+ const b = codes[i + 4];
630
+ if (r != null && g != null && b != null) {
631
+ const name = nearestAnsi16(r, g, b);
632
+ next = code === 38 ? { ...next, fg: name } : { ...next, bg: name };
633
+ }
634
+ i += 4;
635
+ }
636
+ }
637
+ }
638
+ return next;
639
+ }
640
+ function parseAnsiSgr(input, baseStyle = {}) {
641
+ const segments = [];
642
+ let style = { ...baseStyle };
643
+ let lastIndex = 0;
644
+ for (let i = 0; i < input.length; i++) {
645
+ if (input[i] !== ESC3 || input[i + 1] !== "[")
646
+ continue;
647
+ let j = i + 2;
648
+ while (j < input.length) {
649
+ const c = input.charCodeAt(j);
650
+ if (c >= 48 && c <= 57 || c === 59) {
651
+ j++;
652
+ continue;
653
+ }
654
+ break;
655
+ }
656
+ if (j >= input.length || input[j] !== "m")
657
+ continue;
658
+ if (i > lastIndex)
659
+ segments.push({ text: input.slice(lastIndex, i), style });
660
+ const body = input.slice(i + 2, j);
661
+ const codes = body.split(";").filter(Boolean).map((n) => Number.parseInt(n, 10)).filter((n) => Number.isFinite(n));
662
+ style = applyAnsiSgrStyle(style, codes.length ? codes : [0]);
663
+ lastIndex = j + 1;
664
+ i = j;
665
+ }
666
+ if (lastIndex < input.length)
667
+ segments.push({ text: input.slice(lastIndex), style });
668
+ return segments;
669
+ }
670
+
671
+ // src/core/buffer/width.ts
672
+ var fullWidthRanges = [
673
+ [4352, 4447],
674
+ [9001, 9002],
675
+ [11904, 42191],
676
+ [44032, 55203],
677
+ [63744, 64255],
678
+ [65040, 65049],
679
+ [65072, 65135],
680
+ [65280, 65376],
681
+ [65504, 65510]
682
+ ];
683
+ var ambiguousWidthRanges = [
684
+ [161, 161],
685
+ [164, 164],
686
+ [167, 168],
687
+ [170, 170],
688
+ [173, 174],
689
+ [176, 180],
690
+ [182, 186],
691
+ [188, 191],
692
+ [198, 198],
693
+ [208, 208],
694
+ [215, 216],
695
+ [222, 225],
696
+ [230, 230],
697
+ [232, 234],
698
+ [236, 237],
699
+ [240, 240],
700
+ [242, 243],
701
+ [247, 250],
702
+ [252, 252],
703
+ [254, 254],
704
+ [257, 257],
705
+ [273, 273],
706
+ [275, 275],
707
+ [283, 283],
708
+ [294, 295],
709
+ [299, 299],
710
+ [305, 307],
711
+ [312, 312],
712
+ [319, 322],
713
+ [324, 324],
714
+ [328, 331],
715
+ [333, 333],
716
+ [338, 339],
717
+ [358, 359],
718
+ [363, 363],
719
+ [462, 462],
720
+ [464, 464],
721
+ [466, 466],
722
+ [468, 468],
723
+ [470, 470],
724
+ [472, 472],
725
+ [474, 474],
726
+ [476, 476],
727
+ [593, 593],
728
+ [609, 609],
729
+ [708, 708],
730
+ [711, 711],
731
+ [713, 715],
732
+ [717, 717],
733
+ [720, 720],
734
+ [728, 731],
735
+ [733, 733],
736
+ [735, 735],
737
+ [913, 929],
738
+ [931, 937],
739
+ [945, 961],
740
+ [963, 969],
741
+ [1025, 1025],
742
+ [1040, 1103],
743
+ [1105, 1105],
744
+ [8208, 8213],
745
+ [8216, 8217],
746
+ [8220, 8221],
747
+ [8224, 8226],
748
+ [8228, 8231],
749
+ [8240, 8240],
750
+ [8242, 8243],
751
+ [8245, 8245],
752
+ [8251, 8251],
753
+ [8254, 8254],
754
+ [8308, 8308],
755
+ [8319, 8319],
756
+ [8321, 8324],
757
+ [8364, 8364],
758
+ [8451, 8451],
759
+ [8453, 8453],
760
+ [8457, 8457],
761
+ [8467, 8467],
762
+ [8470, 8470],
763
+ [8481, 8482],
764
+ [8486, 8486],
765
+ [8491, 8491],
766
+ [8531, 8532],
767
+ [8539, 8542],
768
+ [8544, 8555],
769
+ [8560, 8569],
770
+ [8585, 8585],
771
+ [8592, 8601],
772
+ [8632, 8633],
773
+ [8658, 8658],
774
+ [8660, 8660],
775
+ [8679, 8679],
776
+ [8704, 8704],
777
+ [8706, 8707],
778
+ [8711, 8712],
779
+ [8715, 8715],
780
+ [8719, 8719],
781
+ [8721, 8721],
782
+ [8725, 8725],
783
+ [8730, 8730],
784
+ [8733, 8736],
785
+ [8739, 8739],
786
+ [8741, 8741],
787
+ [8743, 8748],
788
+ [8750, 8750],
789
+ [8756, 8759],
790
+ [8764, 8765],
791
+ [8776, 8776],
792
+ [8780, 8780],
793
+ [8786, 8786],
794
+ [8800, 8801],
795
+ [8804, 8807],
796
+ [8810, 8811],
797
+ [8814, 8815],
798
+ [8834, 8835],
799
+ [8838, 8839],
800
+ [8853, 8853],
801
+ [8857, 8857],
802
+ [8869, 8869],
803
+ [8895, 8895],
804
+ [8978, 8978],
805
+ [9312, 9449],
806
+ [9451, 9471],
807
+ [9600, 9615],
808
+ [9618, 9621],
809
+ [9632, 9633],
810
+ [9635, 9641],
811
+ [9650, 9651],
812
+ [9654, 9655],
813
+ [9660, 9661],
814
+ [9664, 9665],
815
+ [9670, 9672],
816
+ [9675, 9675],
817
+ [9678, 9681],
818
+ [9698, 9701],
819
+ [9711, 9711],
820
+ [9733, 9734],
821
+ [9737, 9737],
822
+ [9742, 9743],
823
+ [9756, 9756],
824
+ [9758, 9758],
825
+ [9792, 9792],
826
+ [9794, 9794],
827
+ [9824, 9825],
828
+ [9827, 9829],
829
+ [9831, 9834],
830
+ [9836, 9837],
831
+ [9839, 9839],
832
+ [10045, 10045],
833
+ [10102, 10111],
834
+ [11094, 11094],
835
+ [57344, 63743],
836
+ [65533, 65533]
837
+ ];
838
+ function isFullWidthCodePoint(codePoint) {
839
+ if (codePoint < 4352 || codePoint > 65510)
840
+ return false;
841
+ for (const [start, end] of fullWidthRanges) {
842
+ if (codePoint < start)
843
+ return false;
844
+ if (codePoint <= end)
845
+ return true;
846
+ }
847
+ return false;
848
+ }
849
+ function isAmbiguousWidthCodePoint(codePoint) {
850
+ if (codePoint < 161 || codePoint > 65533)
851
+ return false;
852
+ for (const [start, end] of ambiguousWidthRanges) {
853
+ if (codePoint < start)
854
+ return false;
855
+ if (codePoint <= end)
856
+ return true;
857
+ }
858
+ return false;
859
+ }
860
+ function isEmojiLike(codePoint) {
861
+ return codePoint >= 127744 && codePoint <= 129791 || codePoint >= 127462 && codePoint <= 127487;
862
+ }
863
+ var extendedPictographicRe = null;
864
+ try {
865
+ extendedPictographicRe = new RegExp("\\p{Extended_Pictographic}", "u");
866
+ } catch {
867
+ extendedPictographicRe = null;
868
+ }
869
+ var emojiPresentationRe = null;
870
+ try {
871
+ emojiPresentationRe = new RegExp("\\p{Emoji_Presentation}", "u");
872
+ } catch {
873
+ emojiPresentationRe = null;
874
+ }
875
+ var emojiRe = null;
876
+ try {
877
+ emojiRe = new RegExp("\\p{Emoji}", "u");
878
+ } catch {
879
+ emojiRe = null;
880
+ }
881
+ function normalizeCustomWidth(width) {
882
+ return width === 2 ? 2 : 1;
883
+ }
884
+ function charCellWidth(text, provider = "default") {
885
+ if (!text)
886
+ return 1;
887
+ if (typeof provider === "function")
888
+ return normalizeCustomWidth(provider(text));
889
+ if (provider !== "cjk" && text.length === 1) {
890
+ const code = text.charCodeAt(0);
891
+ if (code < 4352)
892
+ return 1;
893
+ }
894
+ const codePoint = text.codePointAt(0);
895
+ if (codePoint == null)
896
+ return 1;
897
+ const hasVs16 = text.includes("\uFE0F");
898
+ if (isFullWidthCodePoint(codePoint))
899
+ return 2;
900
+ if (provider === "cjk" && isAmbiguousWidthCodePoint(codePoint))
901
+ return 2;
902
+ if (isEmojiLike(codePoint))
903
+ return 2;
904
+ if (emojiPresentationRe?.test(text))
905
+ return 2;
906
+ if (text.includes("\u20E3"))
907
+ return 2;
908
+ if (hasVs16 && emojiRe?.test(text))
909
+ return 2;
910
+ if (extendedPictographicRe?.test(text)) {
911
+ if (codePoint <= 65535)
912
+ return hasVs16 ? 2 : 1;
913
+ return 2;
914
+ }
915
+ return 1;
916
+ }
917
+
918
+ // src/utils/url-safety.ts
919
+ var ENCODED_ASCII_CONTROL_RE = /%(?:0[0-9a-f]|1[0-9a-f]|7f)/i;
920
+ function hasControlCodePoint(value) {
921
+ for (let i = 0; i < value.length; i++) {
922
+ const code = value.charCodeAt(i);
923
+ if (code <= 31 || code >= 127 && code <= 159)
924
+ return true;
925
+ }
926
+ return false;
927
+ }
928
+ function hasEncodedControl(value) {
929
+ let current = String(value ?? "");
930
+ for (let depth = 0; depth < 3; depth++) {
931
+ if (ENCODED_ASCII_CONTROL_RE.test(current))
932
+ return true;
933
+ let decoded;
934
+ try {
935
+ decoded = decodeURIComponent(current);
936
+ } catch {
937
+ return true;
938
+ }
939
+ if (hasControlCodePoint(decoded))
940
+ return true;
941
+ if (decoded === current)
942
+ return false;
943
+ current = decoded;
944
+ }
945
+ return ENCODED_ASCII_CONTROL_RE.test(current) || hasControlCodePoint(current);
946
+ }
947
+
948
+ // src/core/hyperlink.ts
949
+ var SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;
950
+ var BLOCKED_SCHEME_RE = /^(?:javascript|data|vbscript):/i;
951
+ var SAFE_RELATIVE_HREF_RE = /^(?:[A-Za-z0-9._~!$&()*+,;=:@/?#-]|%[0-9A-Fa-f]{2})+$/u;
952
+ function normalizeRawHref(value) {
953
+ if (typeof value !== "string")
954
+ return null;
955
+ const raw = value.trim();
956
+ if (!raw)
957
+ return null;
958
+ if (raw !== value)
959
+ return null;
960
+ for (let i = 0; i < value.length; i++) {
961
+ const code = value.charCodeAt(i);
962
+ if (code <= 31 || code >= 127 && code <= 159)
963
+ return null;
964
+ }
965
+ if (/\s/u.test(raw))
966
+ return null;
967
+ if (raw.startsWith("//"))
968
+ return null;
969
+ if (BLOCKED_SCHEME_RE.test(raw))
970
+ return null;
971
+ if (hasEncodedControl(raw))
972
+ return null;
973
+ return raw;
974
+ }
975
+ function hrefScheme(raw) {
976
+ return raw.match(SCHEME_RE)?.[0].toLowerCase() ?? null;
977
+ }
978
+ function parseSafeAbsoluteUrl(raw) {
979
+ if (raw.includes("\\"))
980
+ return null;
981
+ try {
982
+ return new URL(raw);
983
+ } catch {
984
+ return null;
985
+ }
986
+ }
987
+ function sanitizeAbsoluteHref(raw, options = {}) {
988
+ const url = parseSafeAbsoluteUrl(raw);
989
+ if (!url)
990
+ return null;
991
+ if (url.protocol === "http:" || url.protocol === "https:") {
992
+ if (!/^https?:\/\//i.test(raw))
993
+ return null;
994
+ return options.preserveHttpHref ? raw : url.toString();
995
+ }
996
+ if (url.protocol === "mailto:")
997
+ return raw;
998
+ return null;
999
+ }
1000
+ function isSafeNormalizedRelativeHref(raw) {
1001
+ if (raw.includes("\\"))
1002
+ return false;
1003
+ if (raw.startsWith("//"))
1004
+ return false;
1005
+ if (SCHEME_RE.test(raw))
1006
+ return false;
1007
+ if (hasEncodedControl(raw))
1008
+ return false;
1009
+ if (!SAFE_RELATIVE_HREF_RE.test(raw))
1010
+ return false;
1011
+ return raw.startsWith("#") || raw.startsWith("?") || raw.startsWith("/") || raw.startsWith("./") || raw.startsWith("../") || /^[A-Za-z0-9._~-]/u.test(raw);
1012
+ }
1013
+ function isSafeRelativeHref(value) {
1014
+ const raw = normalizeRawHref(value);
1015
+ return raw != null && isSafeNormalizedRelativeHref(raw);
1016
+ }
1017
+ function sanitizeTerminalHref(value, options = {}) {
1018
+ const raw = normalizeRawHref(value);
1019
+ if (!raw)
1020
+ return null;
1021
+ const sanitized = sanitizeAbsoluteHref(raw, { preserveHttpHref: true });
1022
+ if (sanitized)
1023
+ return sanitized;
1024
+ if (options.allowFileUrls) {
1025
+ const url = parseSafeAbsoluteUrl(raw);
1026
+ if (url?.protocol === "file:")
1027
+ return url.toString();
1028
+ }
1029
+ return null;
1030
+ }
1031
+ function sanitizeDomHref(value, options = {}) {
1032
+ const raw = normalizeRawHref(value);
1033
+ if (!raw)
1034
+ return null;
1035
+ const scheme = hrefScheme(raw);
1036
+ if (!scheme) {
1037
+ return options.allowRelative !== false && isSafeNormalizedRelativeHref(raw) ? raw : null;
1038
+ }
1039
+ return sanitizeAbsoluteHref(raw);
1040
+ }
1041
+
1042
+ // src/core/render-plane.ts
1043
+ var TERMINAL_RENDER_PLANES = ["default", "transcript", "chrome", "overlay"];
1044
+
1045
+ // src/utils/grapheme.ts
1046
+ var graphemeSegmenter = null;
1047
+ try {
1048
+ const Segmenter = typeof Intl !== "undefined" ? Intl.Segmenter : void 0;
1049
+ graphemeSegmenter = Segmenter ? new Segmenter(void 0, { granularity: "grapheme" }) : null;
1050
+ } catch {
1051
+ graphemeSegmenter = null;
1052
+ }
1053
+ var unicodeMarkRe = null;
1054
+ try {
1055
+ unicodeMarkRe = new RegExp("\\p{Mark}", "u");
1056
+ } catch {
1057
+ unicodeMarkRe = null;
1058
+ }
1059
+ function needsGraphemeSegmentation(text) {
1060
+ for (const ch of text) {
1061
+ const cp = ch.codePointAt(0);
1062
+ if (cp === 8205)
1063
+ return true;
1064
+ if (cp >= 65024 && cp <= 65039 || cp >= 917760 && cp <= 917999)
1065
+ return true;
1066
+ if (isCombiningMark(cp))
1067
+ return true;
1068
+ if (cp >= 127995 && cp <= 127999)
1069
+ return true;
1070
+ if (cp >= 127462 && cp <= 127487)
1071
+ return true;
1072
+ if (cp >= 917504 && cp <= 917631)
1073
+ return true;
1074
+ }
1075
+ return false;
1076
+ }
1077
+ function isVariationSelector(codePoint) {
1078
+ return codePoint >= 65024 && codePoint <= 65039 || codePoint >= 917760 && codePoint <= 917999;
1079
+ }
1080
+ function isCombiningMark(codePoint) {
1081
+ return codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071 || isDevanagariMark(codePoint) || unicodeMarkRe?.test(String.fromCodePoint(codePoint)) === true;
1082
+ }
1083
+ function isDevanagariMark(codePoint) {
1084
+ return codePoint >= 2304 && codePoint <= 2307 || codePoint >= 2362 && codePoint <= 2364 || codePoint >= 2366 && codePoint <= 2383 || codePoint >= 2385 && codePoint <= 2391 || codePoint >= 2402 && codePoint <= 2403;
1085
+ }
1086
+ function isVirama(codePoint) {
1087
+ return codePoint === 2381;
1088
+ }
1089
+ function isEmojiModifier(codePoint) {
1090
+ return codePoint >= 127995 && codePoint <= 127999;
1091
+ }
1092
+ function isRegionalIndicator(codePoint) {
1093
+ return codePoint >= 127462 && codePoint <= 127487;
1094
+ }
1095
+ function isEmojiTag(codePoint) {
1096
+ return codePoint >= 917504 && codePoint <= 917631;
1097
+ }
1098
+ function fallbackGraphemeSegments(text) {
1099
+ const out = [];
1100
+ let segment = "";
1101
+ let segmentStart = 0;
1102
+ let pos = 0;
1103
+ let regionalIndicators = 0;
1104
+ let joinNext = false;
1105
+ const pushSegment = () => {
1106
+ if (segment)
1107
+ out.push({ segment, index: segmentStart });
1108
+ };
1109
+ for (const ch of text) {
1110
+ const codePoint = ch.codePointAt(0);
1111
+ const chStart = pos;
1112
+ pos += ch.length;
1113
+ const attach = segment !== "" && (joinNext || codePoint === 8205 || isVariationSelector(codePoint) || isCombiningMark(codePoint) || isEmojiModifier(codePoint) || isEmojiTag(codePoint) || isRegionalIndicator(codePoint) && regionalIndicators === 1);
1114
+ if (!attach) {
1115
+ pushSegment();
1116
+ segment = ch;
1117
+ segmentStart = chStart;
1118
+ regionalIndicators = isRegionalIndicator(codePoint) ? 1 : 0;
1119
+ } else {
1120
+ segment += ch;
1121
+ if (isRegionalIndicator(codePoint))
1122
+ regionalIndicators++;
1123
+ else if (!isVariationSelector(codePoint) && !isCombiningMark(codePoint))
1124
+ regionalIndicators = 0;
1125
+ }
1126
+ if (codePoint === 8205 || isVirama(codePoint))
1127
+ joinNext = true;
1128
+ else if (joinNext && !isVariationSelector(codePoint) && !isCombiningMark(codePoint)) {
1129
+ joinNext = false;
1130
+ }
1131
+ }
1132
+ pushSegment();
1133
+ return out;
1134
+ }
1135
+ function segmentedGraphemes(text) {
1136
+ if (!needsGraphemeSegmentation(text))
1137
+ return null;
1138
+ if (graphemeSegmenter)
1139
+ return graphemeSegmenter.segment(text);
1140
+ return fallbackGraphemeSegments(text);
1141
+ }
1142
+
1143
+ // src/core/buffer/buffer.ts
1144
+ var DEFAULT_STYLE = Object.freeze({});
1145
+ var styleCache = /* @__PURE__ */ new WeakMap();
1146
+ var blankCellCache = /* @__PURE__ */ new WeakMap();
1147
+ var continuationCellCache = /* @__PURE__ */ new WeakMap();
1148
+ var cellCacheWidth1 = /* @__PURE__ */ new WeakMap();
1149
+ var cellCacheWidth2 = /* @__PURE__ */ new WeakMap();
1150
+ var MAX_CACHED_CELLS_PER_STYLE = 128;
1151
+ function normalizeStyle(style) {
1152
+ if (!style)
1153
+ return DEFAULT_STYLE;
1154
+ if (Object.isFrozen(style))
1155
+ return style;
1156
+ const cached = styleCache.get(style);
1157
+ if (cached)
1158
+ return cached;
1159
+ const frozen = Object.freeze({ ...style });
1160
+ styleCache.set(style, frozen);
1161
+ return frozen;
1162
+ }
1163
+ function getOrCreateCellCache(map, style) {
1164
+ const cached = map.get(style);
1165
+ if (cached)
1166
+ return cached;
1167
+ const next = /* @__PURE__ */ new Map();
1168
+ map.set(style, next);
1169
+ return next;
1170
+ }
1171
+ function createCell(ch, style, widthProvider) {
1172
+ if (ch === " ")
1173
+ return createBlankCell(style);
1174
+ const normalizedStyle = normalizeStyle(style);
1175
+ const width = charCellWidth(ch, widthProvider);
1176
+ const map = width === 2 ? getOrCreateCellCache(cellCacheWidth2, normalizedStyle) : getOrCreateCellCache(cellCacheWidth1, normalizedStyle);
1177
+ const cached = map.get(ch);
1178
+ if (cached)
1179
+ return cached;
1180
+ const cell = { ch, width, style: normalizedStyle };
1181
+ map.set(ch, cell);
1182
+ if (map.size > MAX_CACHED_CELLS_PER_STYLE)
1183
+ map.clear();
1184
+ return cell;
1185
+ }
1186
+ function createBlankCell(style) {
1187
+ const normalizedStyle = normalizeStyle(style);
1188
+ const cached = blankCellCache.get(normalizedStyle);
1189
+ if (cached)
1190
+ return cached;
1191
+ const cell = Object.freeze({
1192
+ ch: " ",
1193
+ width: 1,
1194
+ style: normalizedStyle
1195
+ });
1196
+ blankCellCache.set(normalizedStyle, cell);
1197
+ return cell;
1198
+ }
1199
+ function createContinuationCell(style) {
1200
+ const normalizedStyle = normalizeStyle(style);
1201
+ const cached = continuationCellCache.get(normalizedStyle);
1202
+ if (cached)
1203
+ return cached;
1204
+ const cell = Object.freeze({
1205
+ ch: "",
1206
+ width: 1,
1207
+ continuation: true,
1208
+ style: normalizedStyle
1209
+ });
1210
+ continuationCellCache.set(normalizedStyle, cell);
1211
+ return cell;
1212
+ }
1213
+ function createGridBuffer(cols, rows, options = {}) {
1214
+ const safeCols = Math.max(0, Math.floor(cols));
1215
+ const safeRows = Math.max(0, Math.floor(rows));
1216
+ const blank = createBlankCell();
1217
+ const grid = Array.from(
1218
+ { length: safeRows },
1219
+ () => Array.from({ length: safeCols }, () => blank)
1220
+ );
1221
+ return {
1222
+ cols: safeCols,
1223
+ rows: safeRows,
1224
+ grid,
1225
+ gridStart: 0,
1226
+ dirtyBits: new Uint8Array(safeRows),
1227
+ dirtyCount: safeRows || 0,
1228
+ dirtyMin: safeRows ? 0 : Number.POSITIVE_INFINITY,
1229
+ dirtyMax: safeRows ? safeRows - 1 : -1,
1230
+ dirtyAll: safeRows > 0,
1231
+ cursorX: 0,
1232
+ cursorY: 0,
1233
+ cursorVisible: true,
1234
+ cursorStyle: DEFAULT_STYLE,
1235
+ scrollback: [],
1236
+ scrollbackLimit: 1e3,
1237
+ rowPool: [],
1238
+ soaFingerprints: null,
1239
+ fingerprintFn: null,
1240
+ widthProvider: options.widthProvider ?? "default"
1241
+ };
1242
+ }
1243
+ function clamp(n, min, max) {
1244
+ return Math.max(min, Math.min(max, n));
1245
+ }
1246
+ function setFingerprintFn(buffer, fn) {
1247
+ buffer.fingerprintFn = fn;
1248
+ const len = buffer.rows * buffer.cols;
1249
+ if (!len) {
1250
+ buffer.soaFingerprints = null;
1251
+ return;
1252
+ }
1253
+ buffer.soaFingerprints = new Uint32Array(len);
1254
+ for (let y = 0; y < buffer.rows; y++) {
1255
+ const row = getBufferRow(buffer, y);
1256
+ const physY = physicalRowIndex(buffer, y);
1257
+ const base = physY * buffer.cols;
1258
+ for (let x = 0; x < buffer.cols; x++) {
1259
+ const cell = row[x];
1260
+ buffer.soaFingerprints[base + x] = fn(cell.ch, cell.style);
1261
+ }
1262
+ }
1263
+ }
1264
+ function getRowFingerprints(buffer, y) {
1265
+ if (!buffer.soaFingerprints)
1266
+ return null;
1267
+ const physY = physicalRowIndex(buffer, y);
1268
+ const base = physY * buffer.cols;
1269
+ return buffer.soaFingerprints.subarray(base, base + buffer.cols);
1270
+ }
1271
+ function updateCellFingerprint(buffer, physY, x, ch, style) {
1272
+ if (!buffer.soaFingerprints || !buffer.fingerprintFn)
1273
+ return;
1274
+ buffer.soaFingerprints[physY * buffer.cols + x] = buffer.fingerprintFn(ch, style);
1275
+ }
1276
+ function updateRangeFingerprint(buffer, physY, x0, x1, ch, style) {
1277
+ if (!buffer.soaFingerprints || !buffer.fingerprintFn)
1278
+ return;
1279
+ const fp = buffer.fingerprintFn(ch, style);
1280
+ const base = physY * buffer.cols;
1281
+ for (let x = x0; x < x1; x++) {
1282
+ buffer.soaFingerprints[base + x] = fp;
1283
+ }
1284
+ }
1285
+ function physicalRowIndex(buffer, y) {
1286
+ return (buffer.gridStart + y) % buffer.rows;
1287
+ }
1288
+ function getBufferRow(buffer, y) {
1289
+ return buffer.grid[physicalRowIndex(buffer, y)];
1290
+ }
1291
+ function getBufferCell(buffer, x, y) {
1292
+ return getBufferRow(buffer, y)[x];
1293
+ }
1294
+ function markAllDirty(buffer) {
1295
+ if (buffer.rows <= 0)
1296
+ return;
1297
+ buffer.dirtyAll = true;
1298
+ buffer.dirtyCount = buffer.rows;
1299
+ buffer.dirtyMin = 0;
1300
+ buffer.dirtyMax = buffer.rows - 1;
1301
+ }
1302
+ function markDirty(buffer, y) {
1303
+ if (buffer.dirtyAll)
1304
+ return;
1305
+ if (y < 0 || y >= buffer.rows)
1306
+ return;
1307
+ if (buffer.dirtyBits[y]) {
1308
+ return;
1309
+ }
1310
+ buffer.dirtyBits[y] = 1;
1311
+ buffer.dirtyCount++;
1312
+ if (y < buffer.dirtyMin)
1313
+ buffer.dirtyMin = y;
1314
+ if (y > buffer.dirtyMax)
1315
+ buffer.dirtyMax = y;
1316
+ }
1317
+ function clearCellRange(row, startX, endXExclusive) {
1318
+ const blank = createBlankCell();
1319
+ for (let x = startX; x < endXExclusive; x++)
1320
+ row[x] = blank;
1321
+ }
1322
+ function clearWideIfOverwriting(row, x) {
1323
+ const cell = row[x];
1324
+ if (!cell)
1325
+ return;
1326
+ if (cell.continuation) {
1327
+ if (x - 1 >= 0)
1328
+ row[x - 1] = createBlankCell();
1329
+ row[x] = createBlankCell();
1330
+ return;
1331
+ }
1332
+ if (cell.width === 2) {
1333
+ row[x] = createBlankCell();
1334
+ if (x + 1 < row.length)
1335
+ row[x + 1] = createBlankCell();
1336
+ }
1337
+ }
1338
+ function putCell(buffer, x, y, ch, style) {
1339
+ if (y < 0 || y >= buffer.rows)
1340
+ return;
1341
+ if (x < 0 || x >= buffer.cols)
1342
+ return;
1343
+ const row = getBufferRow(buffer, y);
1344
+ const width = charCellWidth(ch, buffer.widthProvider);
1345
+ const previous = row[x];
1346
+ const next = width === 2 && x + 1 < buffer.cols ? row[x + 1] : void 0;
1347
+ const previousWideOverlap = Boolean(
1348
+ previous?.continuation || previous?.width === 2 || next?.continuation || next?.width === 2
1349
+ );
1350
+ clearWideIfOverwriting(row, x);
1351
+ if (width === 2 && x + 1 < buffer.cols)
1352
+ clearWideIfOverwriting(row, x + 1);
1353
+ if (width === 2 && x + 1 >= buffer.cols) {
1354
+ const blank = createBlankCell();
1355
+ row[x] = blank;
1356
+ if (buffer.soaFingerprints) {
1357
+ if (previousWideOverlap) {
1358
+ recomputeFingerprintsForRows(buffer, y, y + 1);
1359
+ } else {
1360
+ const physY = physicalRowIndex(buffer, y);
1361
+ updateCellFingerprint(buffer, physY, x, blank.ch, blank.style);
1362
+ }
1363
+ }
1364
+ markDirty(buffer, y);
1365
+ return;
1366
+ }
1367
+ const cell = createCell(ch, style, buffer.widthProvider);
1368
+ row[x] = cell;
1369
+ if (width === 2 && x + 1 < buffer.cols)
1370
+ row[x + 1] = createContinuationCell(style);
1371
+ if (buffer.soaFingerprints) {
1372
+ if (previousWideOverlap) {
1373
+ recomputeFingerprintsForRows(buffer, y, y + 1);
1374
+ } else {
1375
+ const physY = physicalRowIndex(buffer, y);
1376
+ updateCellFingerprint(buffer, physY, x, cell.ch, cell.style);
1377
+ if (width === 2 && x + 1 < buffer.cols) {
1378
+ updateCellFingerprint(buffer, physY, x + 1, "", cell.style);
1379
+ }
1380
+ }
1381
+ }
1382
+ markDirty(buffer, y);
1383
+ }
1384
+ function fillRect(buffer, x, y, w, h, ch = " ", style) {
1385
+ if (w <= 0 || h <= 0 || buffer.cols === 0 || buffer.rows === 0)
1386
+ return;
1387
+ const x0 = clamp(Math.floor(x), 0, buffer.cols);
1388
+ const y0 = clamp(Math.floor(y), 0, buffer.rows);
1389
+ const x1 = clamp(Math.floor(x + w), 0, buffer.cols);
1390
+ const y1 = clamp(Math.floor(y + h), 0, buffer.rows);
1391
+ if (x1 <= x0 || y1 <= y0)
1392
+ return;
1393
+ const width = charCellWidth(ch, buffer.widthProvider);
1394
+ if (width === 1) {
1395
+ const fillCell2 = createCell(ch, style, buffer.widthProvider);
1396
+ const blank2 = createBlankCell();
1397
+ for (let yy = y0; yy < y1; yy++) {
1398
+ const row = getBufferRow(buffer, yy);
1399
+ const clearsLeftWideBase = Boolean(row[x0]?.continuation);
1400
+ const clearsRightContinuation = Boolean(x1 < buffer.cols && row[x1]?.continuation);
1401
+ if (clearsLeftWideBase)
1402
+ clearWideIfOverwriting(row, x0);
1403
+ row.fill(fillCell2, x0, x1);
1404
+ if (clearsRightContinuation)
1405
+ row[x1] = blank2;
1406
+ if (buffer.soaFingerprints) {
1407
+ if (clearsLeftWideBase || clearsRightContinuation) {
1408
+ recomputeFingerprintsForRows(buffer, yy, yy + 1);
1409
+ } else {
1410
+ const physY = physicalRowIndex(buffer, yy);
1411
+ updateRangeFingerprint(buffer, physY, x0, x1, fillCell2.ch, fillCell2.style);
1412
+ }
1413
+ }
1414
+ markDirty(buffer, yy);
1415
+ }
1416
+ return;
1417
+ }
1418
+ const fillCell = createCell(ch, style, buffer.widthProvider);
1419
+ const continuationCell = createContinuationCell(style);
1420
+ const blank = createBlankCell();
1421
+ for (let yy = y0; yy < y1; yy++) {
1422
+ const row = getBufferRow(buffer, yy);
1423
+ for (let xx = x0; xx < x1; ) {
1424
+ clearWideIfOverwriting(row, xx);
1425
+ if (xx + 1 >= x1 || xx + 1 >= buffer.cols) {
1426
+ row[xx] = blank;
1427
+ xx += 1;
1428
+ continue;
1429
+ }
1430
+ clearWideIfOverwriting(row, xx + 1);
1431
+ row[xx] = fillCell;
1432
+ row[xx + 1] = continuationCell;
1433
+ xx += 2;
1434
+ }
1435
+ recomputeFingerprintsForRows(buffer, yy, yy + 1);
1436
+ markDirty(buffer, yy);
1437
+ }
1438
+ }
1439
+ function clearRect(buffer, x, y, w, h) {
1440
+ if (buffer.cols === 0 || buffer.rows === 0)
1441
+ return;
1442
+ if (x == null || y == null || w == null || h == null) {
1443
+ const blank = createBlankCell();
1444
+ for (let yy = 0; yy < buffer.rows; yy++) {
1445
+ const row = getBufferRow(buffer, yy);
1446
+ row.length = buffer.cols;
1447
+ for (let xx = 0; xx < buffer.cols; xx++)
1448
+ row[xx] = blank;
1449
+ }
1450
+ recomputeFingerprintsForRows(buffer, 0, buffer.rows);
1451
+ markAllDirty(buffer);
1452
+ buffer.cursorX = 0;
1453
+ buffer.cursorY = 0;
1454
+ return;
1455
+ }
1456
+ if (w <= 0 || h <= 0)
1457
+ return;
1458
+ const x0 = clamp(Math.floor(x), 0, buffer.cols);
1459
+ const y0 = clamp(Math.floor(y), 0, buffer.rows);
1460
+ const x1 = clamp(Math.floor(x + w), 0, buffer.cols);
1461
+ const y1 = clamp(Math.floor(y + h), 0, buffer.rows);
1462
+ if (x1 <= x0 || y1 <= y0)
1463
+ return;
1464
+ for (let yy = y0; yy < y1; yy++) {
1465
+ const row = getBufferRow(buffer, yy);
1466
+ if (row[x0]?.continuation)
1467
+ clearWideIfOverwriting(row, x0);
1468
+ clearCellRange(row, x0, x1);
1469
+ if (x1 < buffer.cols && row[x1]?.continuation)
1470
+ row[x1] = createBlankCell();
1471
+ recomputeFingerprintsForRows(buffer, yy, yy + 1);
1472
+ markDirty(buffer, yy);
1473
+ }
1474
+ }
1475
+ function takePooledRow(buffer) {
1476
+ const row = buffer.rowPool.pop();
1477
+ return row ?? null;
1478
+ }
1479
+ function blankRow(buffer) {
1480
+ const pooled = takePooledRow(buffer);
1481
+ if (!pooled)
1482
+ return Array.from({ length: buffer.cols }, () => createBlankCell());
1483
+ pooled.length = buffer.cols;
1484
+ const blank = createBlankCell();
1485
+ for (let x = 0; x < buffer.cols; x++)
1486
+ pooled[x] = blank;
1487
+ return pooled;
1488
+ }
1489
+ function recomputeFingerprintsForRows(buffer, startY, endY) {
1490
+ if (!buffer.soaFingerprints || !buffer.fingerprintFn)
1491
+ return;
1492
+ for (let y = startY; y < endY; y++) {
1493
+ const row = getBufferRow(buffer, y);
1494
+ const physY = physicalRowIndex(buffer, y);
1495
+ const base = physY * buffer.cols;
1496
+ for (let x = 0; x < buffer.cols; x++) {
1497
+ const cell = row[x];
1498
+ buffer.soaFingerprints[base + x] = buffer.fingerprintFn(cell.ch, cell.style);
1499
+ }
1500
+ }
1501
+ }
1502
+ function recomputeAllVisibleFingerprints(buffer) {
1503
+ recomputeFingerprintsForRows(buffer, 0, buffer.rows);
1504
+ }
1505
+ function scrollBuffer(buffer, lines) {
1506
+ const raw = Math.trunc(lines);
1507
+ if (raw === 0 || buffer.rows === 0)
1508
+ return;
1509
+ const abs = Math.min(Math.abs(raw), buffer.rows);
1510
+ const n = raw > 0 ? abs : -abs;
1511
+ if (n > 0) {
1512
+ for (let i = 0; i < n; i++) {
1513
+ const removedIdx = buffer.gridStart;
1514
+ const removed = buffer.grid[removedIdx];
1515
+ if (buffer.scrollbackLimit > 0) {
1516
+ buffer.scrollback.push(removed);
1517
+ if (buffer.scrollback.length > buffer.scrollbackLimit) {
1518
+ const excess = buffer.scrollback.length - buffer.scrollbackLimit;
1519
+ const dropped = buffer.scrollback.splice(0, excess);
1520
+ buffer.rowPool.push(...dropped);
1521
+ }
1522
+ } else {
1523
+ buffer.rowPool.push(removed);
1524
+ }
1525
+ buffer.gridStart = (buffer.gridStart + 1) % buffer.rows;
1526
+ const bottomIdx = (buffer.gridStart + buffer.rows - 1) % buffer.rows;
1527
+ buffer.grid[bottomIdx] = blankRow(buffer);
1528
+ }
1529
+ } else {
1530
+ for (let i = 0; i < -n; i++) {
1531
+ const bottomIdx = (buffer.gridStart + buffer.rows - 1) % buffer.rows;
1532
+ const removed = buffer.grid[bottomIdx];
1533
+ buffer.rowPool.push(removed);
1534
+ buffer.gridStart = (buffer.gridStart - 1 + buffer.rows) % buffer.rows;
1535
+ buffer.grid[buffer.gridStart] = blankRow(buffer);
1536
+ }
1537
+ }
1538
+ const inserted = Math.abs(n);
1539
+ if (inserted >= buffer.rows) {
1540
+ recomputeAllVisibleFingerprints(buffer);
1541
+ } else if (n > 0) {
1542
+ recomputeFingerprintsForRows(buffer, buffer.rows - inserted, buffer.rows);
1543
+ } else {
1544
+ recomputeFingerprintsForRows(buffer, 0, inserted);
1545
+ }
1546
+ markAllDirty(buffer);
1547
+ buffer.cursorY = clamp(buffer.cursorY - n, 0, Math.max(0, buffer.rows - 1));
1548
+ }
1549
+ function scrollBufferRegion(buffer, startY, endY, lines) {
1550
+ const n = Math.trunc(lines);
1551
+ if (n === 0 || buffer.rows === 0)
1552
+ return [];
1553
+ const start = clamp(Math.floor(startY), 0, buffer.rows);
1554
+ const end = clamp(Math.floor(endY), 0, buffer.rows);
1555
+ const height = end - start;
1556
+ if (height <= 0)
1557
+ return [];
1558
+ const absDelta = Math.abs(n);
1559
+ const insertedRows = [];
1560
+ const replaceRegionWithBlankRows = () => {
1561
+ for (let y = start; y < end; y++) {
1562
+ const physY = physicalRowIndex(buffer, y);
1563
+ buffer.rowPool.push(buffer.grid[physY]);
1564
+ buffer.grid[physY] = blankRow(buffer);
1565
+ markDirty(buffer, y);
1566
+ insertedRows.push(y);
1567
+ }
1568
+ };
1569
+ if (absDelta >= height) {
1570
+ replaceRegionWithBlankRows();
1571
+ recomputeFingerprintsForRows(buffer, start, end);
1572
+ if (buffer.cursorY >= start && buffer.cursorY < end)
1573
+ buffer.cursorY = clamp(buffer.cursorY - n, start, Math.max(start, end - 1));
1574
+ return insertedRows;
1575
+ }
1576
+ const regionRows = [];
1577
+ for (let y = start; y < end; y++)
1578
+ regionRows.push(getBufferRow(buffer, y));
1579
+ const nextRows = Array.from({ length: height }, () => []);
1580
+ if (n > 0) {
1581
+ const movedCount = height - n;
1582
+ for (let i = 0; i < movedCount; i++)
1583
+ nextRows[i] = regionRows[i + n];
1584
+ for (let i = 0; i < n; i++) {
1585
+ buffer.rowPool.push(regionRows[i]);
1586
+ const y = end - n + i;
1587
+ nextRows[movedCount + i] = blankRow(buffer);
1588
+ markDirty(buffer, y);
1589
+ insertedRows.push(y);
1590
+ }
1591
+ } else {
1592
+ const insertedCount = -n;
1593
+ const movedCount = height - insertedCount;
1594
+ for (let i = 0; i < insertedCount; i++) {
1595
+ buffer.rowPool.push(regionRows[height - insertedCount + i]);
1596
+ const y = start + i;
1597
+ nextRows[i] = blankRow(buffer);
1598
+ markDirty(buffer, y);
1599
+ insertedRows.push(y);
1600
+ }
1601
+ for (let i = 0; i < movedCount; i++)
1602
+ nextRows[insertedCount + i] = regionRows[i];
1603
+ }
1604
+ for (let i = 0; i < height; i++) {
1605
+ const physY = physicalRowIndex(buffer, start + i);
1606
+ buffer.grid[physY] = nextRows[i];
1607
+ }
1608
+ recomputeFingerprintsForRows(buffer, start, end);
1609
+ if (buffer.cursorY >= start && buffer.cursorY < end)
1610
+ buffer.cursorY = clamp(buffer.cursorY - n, start, Math.max(start, end - 1));
1611
+ return insertedRows;
1612
+ }
1613
+ function resizeBuffer(buffer, cols, rows) {
1614
+ const nextCols = Math.max(0, Math.floor(cols));
1615
+ const nextRows = Math.max(0, Math.floor(rows));
1616
+ if (nextCols === buffer.cols && nextRows === buffer.rows)
1617
+ return;
1618
+ const blank = createBlankCell();
1619
+ const nextGrid = Array.from(
1620
+ { length: nextRows },
1621
+ () => Array.from({ length: nextCols }, () => blank)
1622
+ );
1623
+ const copyRows = Math.min(buffer.rows, nextRows);
1624
+ const copyCols = Math.min(buffer.cols, nextCols);
1625
+ for (let y = 0; y < copyRows; y++) {
1626
+ const src = getBufferRow(buffer, y);
1627
+ const dst = nextGrid[y];
1628
+ for (let x = 0; x < copyCols; x++)
1629
+ dst[x] = src[x];
1630
+ }
1631
+ if (nextCols > 0) {
1632
+ for (let y = 0; y < nextGrid.length; y++) {
1633
+ const row = nextGrid[y];
1634
+ for (let x = 0; x < nextCols; x++) {
1635
+ const cell = row[x];
1636
+ if (cell.continuation) {
1637
+ if (x === 0 || row[x - 1]?.width !== 2 || row[x - 1]?.continuation)
1638
+ row[x] = blank;
1639
+ continue;
1640
+ }
1641
+ if (cell.width === 2 && (x + 1 >= nextCols || !row[x + 1]?.continuation)) {
1642
+ row[x] = blank;
1643
+ }
1644
+ }
1645
+ }
1646
+ }
1647
+ for (let y = 0; y < buffer.rows; y++)
1648
+ buffer.rowPool.push(getBufferRow(buffer, y));
1649
+ buffer.grid = nextGrid;
1650
+ buffer.gridStart = 0;
1651
+ buffer.cols = nextCols;
1652
+ buffer.rows = nextRows;
1653
+ buffer.dirtyBits = new Uint8Array(nextRows);
1654
+ buffer.dirtyCount = nextRows || 0;
1655
+ buffer.dirtyMin = nextRows ? 0 : Number.POSITIVE_INFINITY;
1656
+ buffer.dirtyMax = nextRows ? nextRows - 1 : -1;
1657
+ buffer.dirtyAll = nextRows > 0;
1658
+ buffer.cursorX = clamp(buffer.cursorX, 0, Math.max(0, nextCols));
1659
+ buffer.cursorY = clamp(buffer.cursorY, 0, Math.max(0, nextRows - 1));
1660
+ if (buffer.fingerprintFn) {
1661
+ const len = nextRows * nextCols;
1662
+ if (len > 0) {
1663
+ buffer.soaFingerprints = new Uint32Array(len);
1664
+ for (let y = 0; y < nextRows; y++) {
1665
+ const row = nextGrid[y];
1666
+ const base = y * nextCols;
1667
+ for (let x = 0; x < nextCols; x++) {
1668
+ const cell = row[x];
1669
+ buffer.soaFingerprints[base + x] = buffer.fingerprintFn(cell.ch, cell.style);
1670
+ }
1671
+ }
1672
+ } else {
1673
+ buffer.soaFingerprints = null;
1674
+ }
1675
+ }
1676
+ }
1677
+ function snapshotText(buffer) {
1678
+ const out = [];
1679
+ for (let y = 0; y < buffer.rows; y++) {
1680
+ const row = getBufferRow(buffer, y);
1681
+ out.push(row.map((cell) => cell.continuation ? " " : cell.ch || " ").join(""));
1682
+ }
1683
+ return out;
1684
+ }
1685
+
1686
+ // src/core/terminal/emitter.ts
1687
+ var emitterListeners = /* @__PURE__ */ new WeakMap();
1688
+ var Emitter = class {
1689
+ constructor() {
1690
+ emitterListeners.set(this, /* @__PURE__ */ new Map());
1691
+ }
1692
+ getListeners() {
1693
+ return emitterListeners.get(this);
1694
+ }
1695
+ on(event, cb) {
1696
+ const listeners = this.getListeners();
1697
+ let set = listeners.get(event);
1698
+ if (!set) {
1699
+ set = /* @__PURE__ */ new Set();
1700
+ listeners.set(event, set);
1701
+ }
1702
+ set.add(cb);
1703
+ return () => {
1704
+ set.delete(cb);
1705
+ if (set.size === 0)
1706
+ listeners.delete(event);
1707
+ };
1708
+ }
1709
+ emit(event, payload) {
1710
+ const set = this.getListeners().get(event);
1711
+ if (!set)
1712
+ return;
1713
+ for (const cb of set)
1714
+ cb(payload);
1715
+ }
1716
+ clear() {
1717
+ this.getListeners().clear();
1718
+ }
1719
+ };
1720
+
1721
+ // src/core/terminal/create-terminal.ts
1722
+ function isControlChar(ch) {
1723
+ return ch === "\n" || ch === "\r" || ch === " ";
1724
+ }
1725
+ function mergePlanes(prev, next) {
1726
+ if (!prev?.length)
1727
+ return next?.length ? [...next] : null;
1728
+ if (!next?.length)
1729
+ return prev;
1730
+ const merged = new Set(prev);
1731
+ for (const plane of next)
1732
+ merged.add(plane);
1733
+ return Array.from(merged);
1734
+ }
1735
+ var TERMINAL_PLANE_INTERNALS = Symbol.for("@simon_he/vue-tui:v1:terminal-plane-internals");
1736
+ function createCoverage(cols, rows) {
1737
+ return Array.from({ length: rows }, () => new Uint8Array(cols));
1738
+ }
1739
+ function resizeCoverage(prev, cols, rows) {
1740
+ const next = createCoverage(cols, rows);
1741
+ const copyRows = Math.min(prev.length, rows);
1742
+ for (let y = 0; y < copyRows; y++) {
1743
+ const src = prev[y];
1744
+ const dst = next[y];
1745
+ dst.set(src.subarray(0, Math.min(src.length, cols)));
1746
+ }
1747
+ return next;
1748
+ }
1749
+ function setBufferClean(buffer) {
1750
+ buffer.dirtyBits.fill(0);
1751
+ buffer.dirtyCount = 0;
1752
+ buffer.dirtyMin = Number.POSITIVE_INFINITY;
1753
+ buffer.dirtyMax = -1;
1754
+ buffer.dirtyAll = false;
1755
+ }
1756
+ function createPlaneState(cols, rows, widthProvider) {
1757
+ const buffer = createGridBuffer(cols, rows, { widthProvider });
1758
+ setBufferClean(buffer);
1759
+ buffer.cursorVisible = false;
1760
+ return {
1761
+ buffer,
1762
+ coverage: createCoverage(cols, rows)
1763
+ };
1764
+ }
1765
+ function collectAndClearDirtyRows(buffer) {
1766
+ if (buffer.rows === 0)
1767
+ return [];
1768
+ if (buffer.dirtyAll) {
1769
+ buffer.dirtyAll = false;
1770
+ buffer.dirtyBits.fill(0);
1771
+ buffer.dirtyCount = 0;
1772
+ buffer.dirtyMin = Number.POSITIVE_INFINITY;
1773
+ buffer.dirtyMax = -1;
1774
+ return null;
1775
+ }
1776
+ if (buffer.dirtyCount === 0)
1777
+ return [];
1778
+ const out = [];
1779
+ const start = Math.max(0, buffer.dirtyMin);
1780
+ const end = Math.min(buffer.rows - 1, buffer.dirtyMax);
1781
+ for (let y = start; y <= end; y++) {
1782
+ if (buffer.dirtyBits[y]) {
1783
+ buffer.dirtyBits[y] = 0;
1784
+ out.push(y);
1785
+ if (out.length === buffer.dirtyCount)
1786
+ break;
1787
+ }
1788
+ }
1789
+ buffer.dirtyCount = 0;
1790
+ buffer.dirtyMin = Number.POSITIVE_INFINITY;
1791
+ buffer.dirtyMax = -1;
1792
+ return out;
1793
+ }
1794
+ function peekDirtyRows(buffer) {
1795
+ if (buffer.rows === 0)
1796
+ return [];
1797
+ if (buffer.dirtyAll)
1798
+ return null;
1799
+ if (buffer.dirtyCount === 0)
1800
+ return [];
1801
+ const out = [];
1802
+ const start = Math.max(0, buffer.dirtyMin);
1803
+ const end = Math.min(buffer.rows - 1, buffer.dirtyMax);
1804
+ for (let y = start; y <= end; y++) {
1805
+ if (buffer.dirtyBits[y]) {
1806
+ out.push(y);
1807
+ if (out.length === buffer.dirtyCount)
1808
+ break;
1809
+ }
1810
+ }
1811
+ return out;
1812
+ }
1813
+ function clearPlaneCoverageRow(state, y) {
1814
+ if (y < 0 || y >= state.buffer.rows)
1815
+ return;
1816
+ const row = getBufferRow(state.buffer, y);
1817
+ const blank = createBlankCell();
1818
+ row.length = state.buffer.cols;
1819
+ for (let x = 0; x < state.buffer.cols; x++)
1820
+ row[x] = blank;
1821
+ state.coverage[y]?.fill(0);
1822
+ markDirty(state.buffer, y);
1823
+ }
1824
+ function markPlaneCoverageRange(state, x0, y0, x1, y1, value) {
1825
+ for (let y = y0; y < y1; y++) {
1826
+ const row = state.coverage[y];
1827
+ if (!row)
1828
+ continue;
1829
+ row.fill(value, x0, x1);
1830
+ }
1831
+ }
1832
+ function markPlaneCoverageForPut(state, x, y, ch, prevCell) {
1833
+ const row = state.coverage[y];
1834
+ if (!row)
1835
+ return;
1836
+ if (prevCell?.continuation && x > 0)
1837
+ row[x - 1] = 1;
1838
+ if (prevCell?.width === 2 && x + 1 < row.length)
1839
+ row[x + 1] = 1;
1840
+ row[x] = 1;
1841
+ if (ch !== " " && x + 1 < row.length) {
1842
+ const next = getBufferCell(state.buffer, x, y);
1843
+ if (next.width === 2)
1844
+ row[x + 1] = 1;
1845
+ }
1846
+ }
1847
+ function scrollPlaneCoverage(state, lines) {
1848
+ const n = Math.trunc(lines);
1849
+ if (n === 0 || state.coverage.length === 0)
1850
+ return;
1851
+ const rows = state.coverage.length;
1852
+ const cols = state.buffer.cols;
1853
+ if (Math.abs(n) >= rows) {
1854
+ for (const row of state.coverage)
1855
+ row.fill(0);
1856
+ return;
1857
+ }
1858
+ if (n > 0) {
1859
+ state.coverage.splice(0, n);
1860
+ for (let i = 0; i < n; i++)
1861
+ state.coverage.push(new Uint8Array(cols));
1862
+ return;
1863
+ }
1864
+ state.coverage.splice(rows + n, -n);
1865
+ for (let i = 0; i < -n; i++)
1866
+ state.coverage.unshift(new Uint8Array(cols));
1867
+ }
1868
+ function scrollPlaneCoverageRegion(state, startY, endY, lines) {
1869
+ const n = Math.trunc(lines);
1870
+ if (n === 0 || state.coverage.length === 0)
1871
+ return;
1872
+ const start = Math.max(0, Math.min(state.coverage.length, Math.floor(startY)));
1873
+ const end = Math.max(0, Math.min(state.coverage.length, Math.floor(endY)));
1874
+ const height = end - start;
1875
+ if (height <= 0)
1876
+ return;
1877
+ const cols = state.buffer.cols;
1878
+ if (Math.abs(n) >= height) {
1879
+ for (let y = start; y < end; y++)
1880
+ state.coverage[y] = new Uint8Array(cols);
1881
+ return;
1882
+ }
1883
+ const region = state.coverage.slice(start, end);
1884
+ const next = Array.from({ length: height }, () => new Uint8Array(0));
1885
+ if (n > 0) {
1886
+ const movedCount = height - n;
1887
+ for (let i = 0; i < movedCount; i++)
1888
+ next[i] = region[i + n];
1889
+ for (let i = 0; i < n; i++)
1890
+ next[movedCount + i] = new Uint8Array(cols);
1891
+ } else {
1892
+ const insertedCount = -n;
1893
+ const movedCount = height - insertedCount;
1894
+ for (let i = 0; i < insertedCount; i++)
1895
+ next[i] = new Uint8Array(cols);
1896
+ for (let i = 0; i < movedCount; i++)
1897
+ next[insertedCount + i] = region[i];
1898
+ }
1899
+ for (let i = 0; i < height; i++)
1900
+ state.coverage[start + i] = next[i];
1901
+ }
1902
+ function resizePlaneState(state, cols, rows) {
1903
+ resizeBuffer(state.buffer, cols, rows);
1904
+ state.coverage = resizeCoverage(state.coverage, state.buffer.cols, state.buffer.rows);
1905
+ }
1906
+ function normalizeDirtyRows(rows, totalRows) {
1907
+ if (rows === null)
1908
+ return null;
1909
+ if (rows.length === 0)
1910
+ return rows;
1911
+ const out = [];
1912
+ for (const y of rows) {
1913
+ const yy = Math.floor(y);
1914
+ if (yy < 0 || yy >= totalRows)
1915
+ continue;
1916
+ if (out[out.length - 1] === yy)
1917
+ continue;
1918
+ out.push(yy);
1919
+ }
1920
+ return out;
1921
+ }
1922
+ function createTerminal(opts) {
1923
+ const widthProvider = opts.widthProvider ?? "default";
1924
+ const emitter = new Emitter();
1925
+ const compositeBuffer = createGridBuffer(opts.cols, opts.rows, {
1926
+ widthProvider
1927
+ });
1928
+ const planeStates = /* @__PURE__ */ new Map();
1929
+ let disposed = false;
1930
+ let batchingDepth = 0;
1931
+ let pendingCommit = false;
1932
+ let pendingCommitAllPlanes = false;
1933
+ let pendingCommitPlanes = null;
1934
+ const pendingPlaneScrollOps = /* @__PURE__ */ new Map();
1935
+ const planeTerminals = /* @__PURE__ */ new Map();
1936
+ let base;
1937
+ compositeBuffer.cursorVisible = false;
1938
+ function assertNotDisposed() {
1939
+ if (disposed)
1940
+ throw new Error("Terminal is disposed");
1941
+ }
1942
+ function getPlaneState(plane) {
1943
+ let state = planeStates.get(plane);
1944
+ if (!state) {
1945
+ state = createPlaneState(compositeBuffer.cols, compositeBuffer.rows, widthProvider);
1946
+ planeStates.set(plane, state);
1947
+ }
1948
+ return state;
1949
+ }
1950
+ function setCursorForPlane(plane, x, y, visible = true) {
1951
+ const state = getPlaneState(plane);
1952
+ state.buffer.cursorX = Math.max(0, Math.min(state.buffer.cols, Math.floor(x)));
1953
+ state.buffer.cursorY = Math.max(
1954
+ 0,
1955
+ Math.min(state.buffer.rows ? state.buffer.rows - 1 : 0, Math.floor(y))
1956
+ );
1957
+ state.buffer.cursorVisible = visible;
1958
+ markDirty(state.buffer, state.buffer.cursorY);
1959
+ }
1960
+ function putForPlane(plane, x, y, ch, style) {
1961
+ const state = getPlaneState(plane);
1962
+ if (y < 0 || y >= state.buffer.rows || x < 0 || x >= state.buffer.cols)
1963
+ return;
1964
+ const prevCell = getBufferCell(state.buffer, x, y);
1965
+ putCell(state.buffer, x, y, ch, style);
1966
+ markPlaneCoverageForPut(state, x, y, ch, prevCell);
1967
+ }
1968
+ function writeAtForPlane(plane, text, x, y, style) {
1969
+ const state = getPlaneState(plane);
1970
+ let cx = x;
1971
+ let cy = y;
1972
+ if (state.buffer.cols === 0 || state.buffer.rows === 0)
1973
+ return { x: cx, y: cy };
1974
+ const writeChar = (ch) => {
1975
+ if (isControlChar(ch)) {
1976
+ if (ch === "\n") {
1977
+ cx = 0;
1978
+ cy += 1;
1979
+ if (cy >= state.buffer.rows) {
1980
+ scrollBuffer(state.buffer, 1);
1981
+ scrollPlaneCoverage(state, 1);
1982
+ cy = state.buffer.rows - 1;
1983
+ }
1984
+ } else if (ch === "\r") {
1985
+ cx = 0;
1986
+ } else if (ch === " ") {
1987
+ const tabSize = 4;
1988
+ const next = Math.min(state.buffer.cols, cx + (tabSize - cx % tabSize));
1989
+ for (; cx < next; cx++)
1990
+ putForPlane(plane, cx, cy, " ", style);
1991
+ }
1992
+ return true;
1993
+ }
1994
+ if (cy < 0 || cy >= state.buffer.rows)
1995
+ return false;
1996
+ if (cx >= state.buffer.cols) {
1997
+ cx = 0;
1998
+ cy += 1;
1999
+ }
2000
+ if (cy >= state.buffer.rows) {
2001
+ scrollBuffer(state.buffer, 1);
2002
+ scrollPlaneCoverage(state, 1);
2003
+ cy = state.buffer.rows - 1;
2004
+ }
2005
+ putForPlane(plane, cx, cy, ch, style);
2006
+ const width = ch === " " ? 1 : getBufferCell(state.buffer, cx, cy).width || 1;
2007
+ cx += width;
2008
+ return true;
2009
+ };
2010
+ const segments = segmentedGraphemes(text);
2011
+ if (segments) {
2012
+ for (const seg of segments) {
2013
+ if (!writeChar(seg.segment))
2014
+ break;
2015
+ }
2016
+ return { x: cx, y: cy };
2017
+ }
2018
+ let i = 0;
2019
+ for (; i < text.length; i++) {
2020
+ const code = text.charCodeAt(i);
2021
+ if (code > 127)
2022
+ break;
2023
+ if (!writeChar(text[i]))
2024
+ return { x: cx, y: cy };
2025
+ }
2026
+ if (i < text.length) {
2027
+ const rest = text.slice(i);
2028
+ const restSegments = segmentedGraphemes(rest);
2029
+ if (restSegments) {
2030
+ for (const seg of restSegments) {
2031
+ if (!writeChar(seg.segment))
2032
+ break;
2033
+ }
2034
+ } else {
2035
+ for (const ch of rest) {
2036
+ if (!writeChar(ch))
2037
+ break;
2038
+ }
2039
+ }
2040
+ }
2041
+ return { x: cx, y: cy };
2042
+ }
2043
+ function clearForPlane(plane, x, y, w, h) {
2044
+ const state = getPlaneState(plane);
2045
+ clearRect(state.buffer, x, y, w, h);
2046
+ if (x == null || y == null || w == null || h == null) {
2047
+ for (const row of state.coverage)
2048
+ row.fill(1);
2049
+ return;
2050
+ }
2051
+ if (w <= 0 || h <= 0)
2052
+ return;
2053
+ const x0 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x)));
2054
+ const y0 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y)));
2055
+ const x1 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x + w)));
2056
+ const y1 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y + h)));
2057
+ if (x1 <= x0 || y1 <= y0)
2058
+ return;
2059
+ markPlaneCoverageRange(state, x0, y0, x1, y1, 1);
2060
+ }
2061
+ function fillForPlane(plane, x, y, w, h, ch, style) {
2062
+ const state = getPlaneState(plane);
2063
+ fillRect(state.buffer, x, y, w, h, ch ?? " ", style);
2064
+ if (w <= 0 || h <= 0 || state.buffer.cols === 0 || state.buffer.rows === 0)
2065
+ return;
2066
+ const x0 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x)));
2067
+ const y0 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y)));
2068
+ const x1 = Math.max(0, Math.min(state.buffer.cols, Math.floor(x + w)));
2069
+ const y1 = Math.max(0, Math.min(state.buffer.rows, Math.floor(y + h)));
2070
+ if (x1 <= x0 || y1 <= y0)
2071
+ return;
2072
+ markPlaneCoverageRange(state, x0, y0, x1, y1, 1);
2073
+ }
2074
+ function scrollForPlane(plane, lines) {
2075
+ const state = getPlaneState(plane);
2076
+ scrollBuffer(state.buffer, lines);
2077
+ scrollPlaneCoverage(state, lines);
2078
+ }
2079
+ function normalizeScrollOperation(startY, endY, delta, totalRows) {
2080
+ const start = Math.max(0, Math.min(totalRows, Math.floor(startY)));
2081
+ const end = Math.max(0, Math.min(totalRows, Math.floor(endY)));
2082
+ const height = end - start;
2083
+ const lines = Math.trunc(delta);
2084
+ if (height <= 0 || lines === 0 || Math.abs(lines) >= height)
2085
+ return null;
2086
+ return { startY: start, endY: end, delta: lines };
2087
+ }
2088
+ function recordPendingScrollOp(plane, op) {
2089
+ const list = pendingPlaneScrollOps.get(plane) ?? [];
2090
+ const last = list[list.length - 1];
2091
+ if (last && last.startY === op.startY && last.endY === op.endY && Math.sign(last.delta) === Math.sign(op.delta)) {
2092
+ const next = normalizeScrollOperation(
2093
+ op.startY,
2094
+ op.endY,
2095
+ last.delta + op.delta,
2096
+ compositeBuffer.rows
2097
+ );
2098
+ if (next)
2099
+ list[list.length - 1] = next;
2100
+ else
2101
+ list.push(op);
2102
+ } else {
2103
+ list.push(op);
2104
+ }
2105
+ pendingPlaneScrollOps.set(plane, list);
2106
+ }
2107
+ function takePendingScrollOps(planes) {
2108
+ const planesToTake = planes?.length ? planes : TERMINAL_RENDER_PLANES;
2109
+ const out = [];
2110
+ for (const plane of planesToTake) {
2111
+ const ops = pendingPlaneScrollOps.get(plane);
2112
+ if (!ops?.length)
2113
+ continue;
2114
+ pendingPlaneScrollOps.delete(plane);
2115
+ for (const op of ops)
2116
+ out.push({ plane, ...op });
2117
+ }
2118
+ return out.length ? out : null;
2119
+ }
2120
+ function higherPlanesFor(plane) {
2121
+ const planeIndex = TERMINAL_RENDER_PLANES.indexOf(plane);
2122
+ if (planeIndex < 0)
2123
+ return [];
2124
+ return TERMINAL_RENDER_PLANES.slice(planeIndex + 1);
2125
+ }
2126
+ function higherPlaneCoverageKind(plane, y) {
2127
+ const higherPlanes = higherPlanesFor(plane);
2128
+ if (!higherPlanes.length || y < 0 || y >= compositeBuffer.rows)
2129
+ return 0;
2130
+ let covered = 0;
2131
+ for (let x = 0; x < compositeBuffer.cols; x++) {
2132
+ let cellCovered = false;
2133
+ for (const higherPlane of higherPlanes) {
2134
+ const state = planeStates.get(higherPlane);
2135
+ if (state?.coverage[y]?.[x]) {
2136
+ cellCovered = true;
2137
+ break;
2138
+ }
2139
+ }
2140
+ if (cellCovered)
2141
+ covered++;
2142
+ }
2143
+ if (covered === 0)
2144
+ return 0;
2145
+ if (covered >= compositeBuffer.cols)
2146
+ return 2;
2147
+ return 1;
2148
+ }
2149
+ function addAffectedRows(out, op) {
2150
+ for (let y = op.startY; y < op.endY; y++)
2151
+ out.add(y);
2152
+ }
2153
+ function areDisjointSorted(ops) {
2154
+ for (let i = 1; i < ops.length; i++) {
2155
+ if (ops[i - 1].endY > ops[i].startY)
2156
+ return false;
2157
+ }
2158
+ return true;
2159
+ }
2160
+ function groupedPendingScrollOps(pendingOps) {
2161
+ const grouped = /* @__PURE__ */ new Map();
2162
+ for (const pending of pendingOps) {
2163
+ const list = grouped.get(pending.plane) ?? [];
2164
+ list.push({
2165
+ startY: pending.startY,
2166
+ endY: pending.endY,
2167
+ delta: pending.delta
2168
+ });
2169
+ grouped.set(pending.plane, list);
2170
+ }
2171
+ return grouped;
2172
+ }
2173
+ function prepareCompositeScrollOps(pendingOps) {
2174
+ if (!pendingOps?.length) {
2175
+ return {
2176
+ scrollOperations: null,
2177
+ extraDirtyRows: []
2178
+ };
2179
+ }
2180
+ const scrollOperations = [];
2181
+ const extraDirtyRows = /* @__PURE__ */ new Set();
2182
+ const grouped = groupedPendingScrollOps(pendingOps);
2183
+ for (const [plane, ops] of grouped) {
2184
+ const sorted = [...ops].sort((a, b) => a.startY - b.startY || a.endY - b.endY);
2185
+ if (!areDisjointSorted(sorted)) {
2186
+ for (const op of ops)
2187
+ addAffectedRows(extraDirtyRows, op);
2188
+ continue;
2189
+ }
2190
+ for (const op of sorted) {
2191
+ const blockedRows = /* @__PURE__ */ new Set();
2192
+ const partiallyBlockedRows = /* @__PURE__ */ new Set();
2193
+ for (let y = op.startY; y < op.endY; y++) {
2194
+ const coverageKind = higherPlaneCoverageKind(plane, y);
2195
+ if (coverageKind === 0)
2196
+ continue;
2197
+ blockedRows.add(y);
2198
+ if (coverageKind === 1)
2199
+ partiallyBlockedRows.add(y);
2200
+ }
2201
+ if (!blockedRows.size) {
2202
+ scrollOperations.push({
2203
+ startY: op.startY,
2204
+ endY: op.endY,
2205
+ delta: op.delta
2206
+ });
2207
+ continue;
2208
+ }
2209
+ const absDelta = Math.abs(op.delta);
2210
+ for (let y = op.startY; y < op.endY; y++) {
2211
+ if (partiallyBlockedRows.has(y))
2212
+ extraDirtyRows.add(y);
2213
+ }
2214
+ let bandStart = -1;
2215
+ const flushBand = (bandEnd) => {
2216
+ if (bandStart < 0 || bandEnd <= bandStart)
2217
+ return;
2218
+ const bandHeight = bandEnd - bandStart;
2219
+ if (absDelta >= bandHeight) {
2220
+ for (let y = bandStart; y < bandEnd; y++)
2221
+ extraDirtyRows.add(y);
2222
+ bandStart = -1;
2223
+ return;
2224
+ }
2225
+ scrollOperations.push({
2226
+ startY: bandStart,
2227
+ endY: bandEnd,
2228
+ delta: op.delta
2229
+ });
2230
+ if (op.delta > 0) {
2231
+ for (let y = bandEnd - absDelta; y < bandEnd; y++)
2232
+ extraDirtyRows.add(y);
2233
+ } else {
2234
+ for (let y = bandStart; y < bandStart + absDelta; y++)
2235
+ extraDirtyRows.add(y);
2236
+ }
2237
+ bandStart = -1;
2238
+ };
2239
+ for (let y = op.startY; y < op.endY; y++) {
2240
+ if (blockedRows.has(y)) {
2241
+ flushBand(y);
2242
+ continue;
2243
+ }
2244
+ if (bandStart < 0)
2245
+ bandStart = y;
2246
+ }
2247
+ flushBand(op.endY);
2248
+ }
2249
+ }
2250
+ return {
2251
+ scrollOperations: scrollOperations.length ? scrollOperations : null,
2252
+ extraDirtyRows: Array.from(extraDirtyRows).sort((a, b) => a - b)
2253
+ };
2254
+ }
2255
+ function dirtyRowsCoverRange(rows, startY, endY) {
2256
+ if (rows === null)
2257
+ return true;
2258
+ if (!rows.length)
2259
+ return false;
2260
+ let idx = 0;
2261
+ while (idx < rows.length && (rows[idx] ?? -1) < startY)
2262
+ idx++;
2263
+ for (let y = startY; y < endY; y++) {
2264
+ if (rows[idx] !== y)
2265
+ return false;
2266
+ idx++;
2267
+ }
2268
+ return true;
2269
+ }
2270
+ function dropScrollOpsCoveredByDirtyRows(ops, dirtyRows) {
2271
+ if (!ops?.length)
2272
+ return null;
2273
+ const next = ops.filter((op) => !dirtyRowsCoverRange(dirtyRows, op.startY, op.endY));
2274
+ return next.length ? next : null;
2275
+ }
2276
+ function scrollRowsForPlane(plane, startY, endY, lines) {
2277
+ const state = getPlaneState(plane);
2278
+ const op = normalizeScrollOperation(startY, endY, lines, state.buffer.rows);
2279
+ if (!op)
2280
+ return;
2281
+ scrollBufferRegion(state.buffer, op.startY, op.endY, op.delta);
2282
+ scrollPlaneCoverageRegion(state, op.startY, op.endY, op.delta);
2283
+ recordPendingScrollOp(plane, op);
2284
+ }
2285
+ function composeRows(rows, planes = TERMINAL_RENDER_PLANES) {
2286
+ const blank = createBlankCell();
2287
+ const fpFn = compositeBuffer.fingerprintFn;
2288
+ const fpArr = compositeBuffer.soaFingerprints;
2289
+ const rowList = rows ?? Array.from({ length: compositeBuffer.rows }, (_, index) => index);
2290
+ for (const y of rowList) {
2291
+ if (y < 0 || y >= compositeBuffer.rows)
2292
+ continue;
2293
+ const dst = getBufferRow(compositeBuffer, y);
2294
+ dst.length = compositeBuffer.cols;
2295
+ for (let x = 0; x < compositeBuffer.cols; x++)
2296
+ dst[x] = blank;
2297
+ for (const plane of planes) {
2298
+ const state = planeStates.get(plane);
2299
+ if (!state)
2300
+ continue;
2301
+ const src = getBufferRow(state.buffer, y);
2302
+ const coverage = state.coverage[y];
2303
+ if (!coverage)
2304
+ continue;
2305
+ for (let x = 0; x < compositeBuffer.cols; x++) {
2306
+ if (coverage[x])
2307
+ dst[x] = src[x];
2308
+ }
2309
+ }
2310
+ const cols = compositeBuffer.cols;
2311
+ for (let x = 0; x < cols; x++) {
2312
+ const cell = dst[x];
2313
+ if (cell.width === 2 && !cell.continuation) {
2314
+ if (x + 1 >= cols || !dst[x + 1].continuation) {
2315
+ dst[x] = blank;
2316
+ }
2317
+ } else if (cell.continuation) {
2318
+ if (x === 0 || dst[x - 1].width !== 2 || dst[x - 1].continuation) {
2319
+ dst[x] = blank;
2320
+ }
2321
+ }
2322
+ }
2323
+ if (fpFn && fpArr) {
2324
+ const physY = (compositeBuffer.gridStart + y) % compositeBuffer.rows;
2325
+ const base2 = physY * cols;
2326
+ for (let x = 0; x < cols; x++) {
2327
+ const cell = dst[x];
2328
+ fpArr[base2 + x] = fpFn(cell.ch, cell.style);
2329
+ }
2330
+ }
2331
+ markDirty(compositeBuffer, y);
2332
+ }
2333
+ }
2334
+ function syncCompositeCursor() {
2335
+ const prevVisible = compositeBuffer.cursorVisible;
2336
+ const prevY = compositeBuffer.cursorY;
2337
+ let nextPlane = null;
2338
+ for (const plane of ["overlay", "chrome", "transcript", "default"]) {
2339
+ const state = planeStates.get(plane);
2340
+ if (state?.buffer.cursorVisible) {
2341
+ nextPlane = state;
2342
+ break;
2343
+ }
2344
+ }
2345
+ compositeBuffer.cursorVisible = Boolean(nextPlane);
2346
+ compositeBuffer.cursorX = nextPlane?.buffer.cursorX ?? 0;
2347
+ compositeBuffer.cursorY = nextPlane?.buffer.cursorY ?? 0;
2348
+ if (prevVisible)
2349
+ markDirty(compositeBuffer, prevY);
2350
+ if (compositeBuffer.cursorVisible)
2351
+ markDirty(compositeBuffer, compositeBuffer.cursorY);
2352
+ }
2353
+ function syncCompositeForRead(planes) {
2354
+ const planesToCompose = planes?.length ? planes : TERMINAL_RENDER_PLANES;
2355
+ let composeAllRows = false;
2356
+ const dirtyRows = /* @__PURE__ */ new Set();
2357
+ for (const plane of planesToCompose) {
2358
+ const state = planeStates.get(plane);
2359
+ if (!state)
2360
+ continue;
2361
+ const rows = peekDirtyRows(state.buffer);
2362
+ if (rows === null) {
2363
+ composeAllRows = true;
2364
+ break;
2365
+ }
2366
+ for (const y of rows)
2367
+ dirtyRows.add(y);
2368
+ }
2369
+ if (composeAllRows || dirtyRows.size > 0)
2370
+ composeRows(
2371
+ composeAllRows ? null : Array.from(dirtyRows).sort((a, b) => a - b),
2372
+ planesToCompose
2373
+ );
2374
+ syncCompositeCursor();
2375
+ }
2376
+ function readRowForPlanes(y, planes) {
2377
+ assertNotDisposed();
2378
+ if (y < 0 || y >= compositeBuffer.rows)
2379
+ throw new RangeError("Row out of bounds");
2380
+ composeRows([y], planes?.length ? planes : TERMINAL_RENDER_PLANES);
2381
+ return getBufferRow(compositeBuffer, y);
2382
+ }
2383
+ function pendingDirtyRowsForPlanes(planes) {
2384
+ const planesToCheck = planes?.length ? planes : TERMINAL_RENDER_PLANES;
2385
+ let full = false;
2386
+ const rows = /* @__PURE__ */ new Set();
2387
+ for (const plane of planesToCheck) {
2388
+ const state = planeStates.get(plane);
2389
+ if (!state)
2390
+ continue;
2391
+ const dirty = peekDirtyRows(state.buffer);
2392
+ if (dirty === null) {
2393
+ full = true;
2394
+ break;
2395
+ }
2396
+ for (const y of dirty)
2397
+ rows.add(y);
2398
+ }
2399
+ if (full)
2400
+ return null;
2401
+ return Array.from(rows).sort((a, b) => a - b);
2402
+ }
2403
+ function createPlaneTerminalApi(plane) {
2404
+ const existing = planeTerminals.get(plane);
2405
+ if (existing)
2406
+ return existing;
2407
+ const api = {
2408
+ resize(cols, rows) {
2409
+ assertNotDisposed();
2410
+ base.resize(cols, rows);
2411
+ },
2412
+ clear(x, y, w, h) {
2413
+ assertNotDisposed();
2414
+ clearForPlane(plane, x, y, w, h);
2415
+ },
2416
+ write(text, opts2) {
2417
+ assertNotDisposed();
2418
+ const state = getPlaneState(plane);
2419
+ const x = opts2?.x;
2420
+ const y = opts2?.y;
2421
+ const style = opts2?.style;
2422
+ if (x == null || y == null) {
2423
+ const next = writeAtForPlane(
2424
+ plane,
2425
+ text,
2426
+ state.buffer.cursorX,
2427
+ state.buffer.cursorY,
2428
+ style ?? state.buffer.cursorStyle
2429
+ );
2430
+ state.buffer.cursorX = next.x;
2431
+ state.buffer.cursorY = next.y;
2432
+ } else {
2433
+ writeAtForPlane(plane, text, x, y, style);
2434
+ }
2435
+ },
2436
+ writeAnsi(text, opts2) {
2437
+ assertNotDisposed();
2438
+ const state = getPlaneState(plane);
2439
+ const x = opts2?.x;
2440
+ const y = opts2?.y;
2441
+ const positionedWrite = x != null && y != null;
2442
+ let cx = positionedWrite ? x : state.buffer.cursorX;
2443
+ let cy = positionedWrite ? y : state.buffer.cursorY;
2444
+ let style = positionedWrite ? {} : state.buffer.cursorStyle;
2445
+ for (const seg of parseAnsiSgr(text, style)) {
2446
+ const next = writeAtForPlane(plane, seg.text, cx, cy, seg.style);
2447
+ cx = next.x;
2448
+ cy = next.y;
2449
+ style = seg.style;
2450
+ }
2451
+ if (!positionedWrite) {
2452
+ state.buffer.cursorX = cx;
2453
+ state.buffer.cursorY = cy;
2454
+ state.buffer.cursorStyle = style;
2455
+ }
2456
+ },
2457
+ put(x, y, ch, style) {
2458
+ assertNotDisposed();
2459
+ putForPlane(plane, x, y, ch, style);
2460
+ },
2461
+ fill(x, y, w, h, ch, style) {
2462
+ assertNotDisposed();
2463
+ fillForPlane(plane, x, y, w, h, ch, style);
2464
+ },
2465
+ scroll(lines) {
2466
+ assertNotDisposed();
2467
+ scrollForPlane(plane, lines);
2468
+ },
2469
+ setCursor(x, y, visible) {
2470
+ assertNotDisposed();
2471
+ setCursorForPlane(plane, x, y, visible);
2472
+ },
2473
+ batch(fn) {
2474
+ assertNotDisposed();
2475
+ return base.batch(fn);
2476
+ },
2477
+ commit(meta) {
2478
+ assertNotDisposed();
2479
+ return base.commit({ planes: meta?.planes ?? [plane], sync: meta?.sync });
2480
+ },
2481
+ on(event, cb) {
2482
+ assertNotDisposed();
2483
+ return base.on(event, cb);
2484
+ },
2485
+ dispose() {
2486
+ base.dispose();
2487
+ },
2488
+ size() {
2489
+ assertNotDisposed();
2490
+ return base.size();
2491
+ },
2492
+ snapshot() {
2493
+ assertNotDisposed();
2494
+ const state = getPlaneState(plane);
2495
+ return {
2496
+ cols: state.buffer.cols,
2497
+ rows: state.buffer.rows,
2498
+ lines: snapshotText(state.buffer)
2499
+ };
2500
+ },
2501
+ getCell(x, y) {
2502
+ assertNotDisposed();
2503
+ const state = getPlaneState(plane);
2504
+ if (y < 0 || y >= state.buffer.rows || x < 0 || x >= state.buffer.cols)
2505
+ throw new RangeError("Cell out of bounds");
2506
+ return getBufferCell(state.buffer, x, y);
2507
+ },
2508
+ getRow(y) {
2509
+ assertNotDisposed();
2510
+ const state = getPlaneState(plane);
2511
+ if (y < 0 || y >= state.buffer.rows)
2512
+ throw new RangeError("Row out of bounds");
2513
+ return getBufferRow(state.buffer, y);
2514
+ },
2515
+ setScrollbackLimit(limit) {
2516
+ assertNotDisposed();
2517
+ const state = getPlaneState(plane);
2518
+ state.buffer.scrollbackLimit = Math.max(0, Math.floor(limit));
2519
+ if (state.buffer.scrollback.length > state.buffer.scrollbackLimit) {
2520
+ state.buffer.scrollback.splice(
2521
+ 0,
2522
+ state.buffer.scrollback.length - state.buffer.scrollbackLimit
2523
+ );
2524
+ }
2525
+ },
2526
+ getScrollbackLines(count) {
2527
+ assertNotDisposed();
2528
+ const state = getPlaneState(plane);
2529
+ const all = state.buffer.scrollback.map(
2530
+ (row) => row.map((cell) => cell.continuation ? " " : cell.ch || " ").join("")
2531
+ );
2532
+ if (count == null)
2533
+ return all;
2534
+ return all.slice(Math.max(0, all.length - Math.max(0, Math.floor(count))));
2535
+ },
2536
+ setFingerprintFn(fn) {
2537
+ assertNotDisposed();
2538
+ base.setFingerprintFn(fn);
2539
+ },
2540
+ getRowFingerprints(y) {
2541
+ assertNotDisposed();
2542
+ return base.getRowFingerprints(y);
2543
+ }
2544
+ };
2545
+ planeTerminals.set(plane, api);
2546
+ return api;
2547
+ }
2548
+ base = {
2549
+ resize(cols, rows) {
2550
+ assertNotDisposed();
2551
+ const prevCols = compositeBuffer.cols;
2552
+ const prevRows = compositeBuffer.rows;
2553
+ resizeBuffer(compositeBuffer, cols, rows);
2554
+ for (const state of planeStates.values())
2555
+ resizePlaneState(state, cols, rows);
2556
+ if (compositeBuffer.cols !== prevCols || compositeBuffer.rows !== prevRows)
2557
+ emitter.emit("resize", { cols: compositeBuffer.cols, rows: compositeBuffer.rows });
2558
+ },
2559
+ clear(x, y, w, h) {
2560
+ assertNotDisposed();
2561
+ clearForPlane("default", x, y, w, h);
2562
+ },
2563
+ write(text, opts2) {
2564
+ assertNotDisposed();
2565
+ createPlaneTerminalApi("default").write(text, opts2);
2566
+ },
2567
+ writeAnsi(text, opts2) {
2568
+ assertNotDisposed();
2569
+ createPlaneTerminalApi("default").writeAnsi(text, opts2);
2570
+ },
2571
+ put(x, y, ch, style) {
2572
+ assertNotDisposed();
2573
+ putForPlane("default", x, y, ch, style);
2574
+ },
2575
+ fill(x, y, w, h, ch, style) {
2576
+ assertNotDisposed();
2577
+ fillForPlane("default", x, y, w, h, ch, style);
2578
+ },
2579
+ scroll(lines) {
2580
+ assertNotDisposed();
2581
+ scrollForPlane("default", lines);
2582
+ },
2583
+ setCursor(x, y, visible = true) {
2584
+ assertNotDisposed();
2585
+ setCursorForPlane("default", x, y, visible);
2586
+ },
2587
+ batch(fn) {
2588
+ assertNotDisposed();
2589
+ batchingDepth++;
2590
+ try {
2591
+ return fn();
2592
+ } finally {
2593
+ batchingDepth--;
2594
+ if (batchingDepth === 0 && pendingCommit) {
2595
+ pendingCommit = false;
2596
+ const planes = pendingCommitAllPlanes ? null : pendingCommitPlanes;
2597
+ pendingCommitAllPlanes = false;
2598
+ pendingCommitPlanes = null;
2599
+ base.commit({ planes });
2600
+ }
2601
+ }
2602
+ },
2603
+ commit(meta) {
2604
+ assertNotDisposed();
2605
+ if (batchingDepth > 0) {
2606
+ pendingCommit = true;
2607
+ if (!meta?.planes?.length) {
2608
+ pendingCommitAllPlanes = true;
2609
+ pendingCommitPlanes = null;
2610
+ } else if (!pendingCommitAllPlanes) {
2611
+ pendingCommitPlanes = mergePlanes(pendingCommitPlanes, meta.planes);
2612
+ }
2613
+ return pendingDirtyRowsForPlanes(meta?.planes ?? null);
2614
+ }
2615
+ const planesToCompose = meta?.planes?.length ? meta.planes : TERMINAL_RENDER_PLANES;
2616
+ const pendingScrollOps = takePendingScrollOps(planesToCompose);
2617
+ const preparedScroll = prepareCompositeScrollOps(pendingScrollOps);
2618
+ let scrollOperations = preparedScroll.scrollOperations;
2619
+ let composeAllRows = false;
2620
+ const dirtyRows = /* @__PURE__ */ new Set();
2621
+ for (const plane of planesToCompose) {
2622
+ const state = planeStates.get(plane);
2623
+ if (!state)
2624
+ continue;
2625
+ const rows = collectAndClearDirtyRows(state.buffer);
2626
+ if (rows === null) {
2627
+ composeAllRows = true;
2628
+ break;
2629
+ }
2630
+ for (const y of rows)
2631
+ dirtyRows.add(y);
2632
+ }
2633
+ for (const y of preparedScroll.extraDirtyRows)
2634
+ dirtyRows.add(y);
2635
+ const normalizedDirtyRows = composeAllRows ? null : Array.from(dirtyRows).sort((a, b) => a - b);
2636
+ scrollOperations = dropScrollOpsCoveredByDirtyRows(scrollOperations, normalizedDirtyRows);
2637
+ if (scrollOperations) {
2638
+ for (const op of scrollOperations)
2639
+ scrollBufferRegion(compositeBuffer, op.startY, op.endY, op.delta);
2640
+ }
2641
+ if (normalizedDirtyRows !== null && normalizedDirtyRows.length === 0) {
2642
+ const pendingCompositeRows = collectAndClearDirtyRows(compositeBuffer);
2643
+ if (pendingCompositeRows !== null && pendingCompositeRows.length === 0)
2644
+ return pendingCompositeRows;
2645
+ emitter.emit("commit", {
2646
+ dirtyRows: pendingCompositeRows,
2647
+ planes: meta?.planes ?? null,
2648
+ sync: meta?.sync,
2649
+ scrollOperations
2650
+ });
2651
+ return pendingCompositeRows;
2652
+ }
2653
+ composeRows(normalizedDirtyRows);
2654
+ if (normalizedDirtyRows === null)
2655
+ markAllDirty(compositeBuffer);
2656
+ syncCompositeCursor();
2657
+ const committedRows = collectAndClearDirtyRows(compositeBuffer);
2658
+ if (committedRows !== null && committedRows.length === 0)
2659
+ return committedRows;
2660
+ emitter.emit("commit", {
2661
+ dirtyRows: committedRows,
2662
+ planes: meta?.planes ?? null,
2663
+ sync: meta?.sync,
2664
+ scrollOperations
2665
+ });
2666
+ return committedRows;
2667
+ },
2668
+ on(event, cb) {
2669
+ assertNotDisposed();
2670
+ return emitter.on(event, cb);
2671
+ },
2672
+ dispose() {
2673
+ disposed = true;
2674
+ emitter.clear();
2675
+ },
2676
+ size() {
2677
+ assertNotDisposed();
2678
+ return { cols: compositeBuffer.cols, rows: compositeBuffer.rows };
2679
+ },
2680
+ snapshot() {
2681
+ assertNotDisposed();
2682
+ if (batchingDepth === 0)
2683
+ syncCompositeForRead();
2684
+ const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
2685
+ return {
2686
+ cols: source.cols,
2687
+ rows: source.rows,
2688
+ lines: snapshotText(source)
2689
+ };
2690
+ },
2691
+ getCell(x, y) {
2692
+ assertNotDisposed();
2693
+ if (batchingDepth === 0)
2694
+ syncCompositeForRead();
2695
+ const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
2696
+ if (y < 0 || y >= source.rows || x < 0 || x >= source.cols)
2697
+ throw new RangeError("Cell out of bounds");
2698
+ return getBufferCell(source, x, y);
2699
+ },
2700
+ getRow(y) {
2701
+ assertNotDisposed();
2702
+ if (batchingDepth === 0)
2703
+ syncCompositeForRead();
2704
+ const source = batchingDepth > 0 ? getPlaneState("default").buffer : compositeBuffer;
2705
+ if (y < 0 || y >= source.rows)
2706
+ throw new RangeError("Row out of bounds");
2707
+ return getBufferRow(source, y);
2708
+ },
2709
+ setScrollbackLimit(limit) {
2710
+ assertNotDisposed();
2711
+ const state = getPlaneState("default");
2712
+ state.buffer.scrollbackLimit = Math.max(0, Math.floor(limit));
2713
+ if (state.buffer.scrollback.length > state.buffer.scrollbackLimit) {
2714
+ state.buffer.scrollback.splice(
2715
+ 0,
2716
+ state.buffer.scrollback.length - state.buffer.scrollbackLimit
2717
+ );
2718
+ }
2719
+ },
2720
+ getScrollbackLines(count) {
2721
+ assertNotDisposed();
2722
+ const state = getPlaneState("default");
2723
+ const all = state.buffer.scrollback.map(
2724
+ (row) => row.map((cell) => cell.continuation ? " " : cell.ch || " ").join("")
2725
+ );
2726
+ if (count == null)
2727
+ return all;
2728
+ return all.slice(Math.max(0, all.length - Math.max(0, Math.floor(count))));
2729
+ },
2730
+ setFingerprintFn(fn) {
2731
+ assertNotDisposed();
2732
+ setFingerprintFn(compositeBuffer, fn);
2733
+ },
2734
+ getRowFingerprints(y) {
2735
+ assertNotDisposed();
2736
+ return getRowFingerprints(compositeBuffer, y);
2737
+ }
2738
+ };
2739
+ base[TERMINAL_PLANE_INTERNALS] = {
2740
+ getPlaneTerminal: createPlaneTerminalApi,
2741
+ readRowForPlanes,
2742
+ resetRowsForRender(plane, dirtyRows) {
2743
+ const state = getPlaneState(plane);
2744
+ const rows = normalizeDirtyRows(dirtyRows, state.buffer.rows);
2745
+ if (rows === null) {
2746
+ for (let y = 0; y < state.buffer.rows; y++)
2747
+ clearPlaneCoverageRow(state, y);
2748
+ return;
2749
+ }
2750
+ for (const y of rows)
2751
+ clearPlaneCoverageRow(state, y);
2752
+ },
2753
+ getRowCoverageKind(plane, y) {
2754
+ const state = getPlaneState(plane);
2755
+ if (y < 0 || y >= state.coverage.length)
2756
+ return 0;
2757
+ const row = state.coverage[y];
2758
+ if (!row?.length)
2759
+ return 0;
2760
+ let covered = 0;
2761
+ for (let x = 0; x < row.length; x++) {
2762
+ if (row[x])
2763
+ covered++;
2764
+ }
2765
+ if (covered === 0)
2766
+ return 0;
2767
+ if (covered >= row.length)
2768
+ return 2;
2769
+ return 1;
2770
+ },
2771
+ scrollRows(plane, startY, endY, lines) {
2772
+ scrollRowsForPlane(plane, startY, endY, lines);
2773
+ }
2774
+ };
2775
+ return base;
2776
+ }
2777
+
2778
+ // src/utils/path.ts
2779
+ function normalizeSeparators(input) {
2780
+ let out = "";
2781
+ for (let i = 0; i < input.length; i++) {
2782
+ const ch = input[i];
2783
+ out += ch === "\\" ? "/" : ch;
2784
+ }
2785
+ return out;
2786
+ }
2787
+ function isAbsolutePath(path) {
2788
+ const p = normalizeSeparators(path);
2789
+ if (p.startsWith("/"))
2790
+ return true;
2791
+ return /^[A-Z]:\//i.test(p);
2792
+ }
2793
+ function stripTrailingSlash(path) {
2794
+ const p = normalizeSeparators(path);
2795
+ if (p === "/")
2796
+ return p;
2797
+ let end = p.length;
2798
+ while (end > 0 && p.charCodeAt(end - 1) === 47)
2799
+ end--;
2800
+ return end === p.length ? p : p.slice(0, end);
2801
+ }
2802
+ function joinPath(base, next) {
2803
+ const a = normalizeSeparators(base);
2804
+ const b = normalizeSeparators(next);
2805
+ if (!a)
2806
+ return b;
2807
+ if (!b)
2808
+ return a;
2809
+ if (a.endsWith("/"))
2810
+ return `${a}${b.startsWith("/") ? b.slice(1) : b}`;
2811
+ return `${a}/${b.startsWith("/") ? b.slice(1) : b}`;
2812
+ }
2813
+ function dirname(path) {
2814
+ const p = stripTrailingSlash(path);
2815
+ const normalized = normalizeSeparators(p);
2816
+ if (normalized === "/")
2817
+ return "/";
2818
+ const drive = normalized.match(/^([A-Z]:)\//i)?.[1] ?? null;
2819
+ const start = drive ? drive.length + 1 : 0;
2820
+ const idx = normalized.lastIndexOf("/");
2821
+ if (idx < start)
2822
+ return drive ? `${drive}/` : "";
2823
+ const out = normalized.slice(0, idx) || (drive ? `${drive}/` : "/");
2824
+ return out;
2825
+ }
2826
+ function normalizePath(path) {
2827
+ const raw = normalizeSeparators(path);
2828
+ if (!raw)
2829
+ return "";
2830
+ const drive = raw.match(/^([A-Z]:)(\/|$)/i)?.[1] ?? null;
2831
+ const rest = drive ? raw.slice(drive.length) : raw;
2832
+ const absolute = rest.startsWith("/");
2833
+ const parts = rest.split("/").filter(Boolean);
2834
+ const stack = [];
2835
+ for (const part of parts) {
2836
+ if (part === ".")
2837
+ continue;
2838
+ if (part === "..") {
2839
+ if (stack.length > 0 && stack[stack.length - 1] !== "..") {
2840
+ stack.pop();
2841
+ continue;
2842
+ }
2843
+ if (!absolute)
2844
+ stack.push("..");
2845
+ continue;
2846
+ }
2847
+ stack.push(part);
2848
+ }
2849
+ const prefix = drive ? `${drive}${absolute ? "/" : ""}` : absolute ? "/" : "";
2850
+ const joined = stack.join("/");
2851
+ const out = `${prefix}${joined}`;
2852
+ return out || (absolute ? drive ? `${drive}/` : "/" : "");
2853
+ }
2854
+ function resolvePath(baseAbs, input) {
2855
+ const b = normalizePath(baseAbs);
2856
+ const i = normalizePath(input);
2857
+ if (!b)
2858
+ return i;
2859
+ if (isAbsolutePath(i))
2860
+ return i;
2861
+ return normalizePath(joinPath(b, i));
2862
+ }
2863
+
2864
+ // src/core/path-suggest.ts
2865
+ function lower(s) {
2866
+ return s.toLowerCase();
2867
+ }
2868
+ function normalizePathInputSeparators(input) {
2869
+ let out = "";
2870
+ for (let i = 0; i < input.length; i++) {
2871
+ const ch = input[i];
2872
+ if (ch === "\r")
2873
+ continue;
2874
+ out += ch === "\\" ? "/" : ch;
2875
+ }
2876
+ return out;
2877
+ }
2878
+ function stripCarriageReturns(input) {
2879
+ let out = "";
2880
+ for (let i = 0; i < input.length; i++) {
2881
+ const ch = input[i];
2882
+ if (ch !== "\r")
2883
+ out += ch;
2884
+ }
2885
+ return out;
2886
+ }
2887
+ function stripLeadingDotSlash(input) {
2888
+ let i = 0;
2889
+ while (i + 1 < input.length && input.charCodeAt(i) === 46 && input.charCodeAt(i + 1) === 47) {
2890
+ i += 2;
2891
+ }
2892
+ return i === 0 ? input : input.slice(i);
2893
+ }
2894
+ function stripLeadingSlashes(input) {
2895
+ let i = 0;
2896
+ while (i < input.length && input.charCodeAt(i) === 47)
2897
+ i++;
2898
+ return i === 0 ? input : input.slice(i);
2899
+ }
2900
+ function stripTrailingSlashes(input) {
2901
+ let end = input.length;
2902
+ while (end > 0 && input.charCodeAt(end - 1) === 47)
2903
+ end--;
2904
+ return end === input.length ? input : input.slice(0, end);
2905
+ }
2906
+ function collapseSlashes(input) {
2907
+ let out = "";
2908
+ let previousWasSlash = false;
2909
+ for (let i = 0; i < input.length; i++) {
2910
+ const ch = input[i];
2911
+ const isSlash = ch === "/";
2912
+ if (isSlash) {
2913
+ if (!previousWasSlash)
2914
+ out += "/";
2915
+ previousWasSlash = true;
2916
+ continue;
2917
+ }
2918
+ out += ch;
2919
+ previousWasSlash = false;
2920
+ }
2921
+ return out;
2922
+ }
2923
+ function normalizeRelativePathForIgnore(input) {
2924
+ return stripTrailingSlashes(
2925
+ collapseSlashes(stripLeadingSlashes(stripLeadingDotSlash(normalizePathInputSeparators(input))))
2926
+ );
2927
+ }
2928
+ function fuzzyScore(name, query) {
2929
+ const n = lower(name);
2930
+ const q = lower(query);
2931
+ if (!q)
2932
+ return 0;
2933
+ if (n === q)
2934
+ return 2e3;
2935
+ if (n.startsWith(q))
2936
+ return 1500 - (n.length - q.length);
2937
+ const idx = n.indexOf(q);
2938
+ if (idx >= 0)
2939
+ return 1200 - idx;
2940
+ let ni = 0;
2941
+ let qi = 0;
2942
+ let gaps = 0;
2943
+ let lastMatch = -1;
2944
+ while (ni < n.length && qi < q.length) {
2945
+ if (n[ni] === q[qi]) {
2946
+ if (lastMatch >= 0)
2947
+ gaps += ni - lastMatch - 1;
2948
+ lastMatch = ni;
2949
+ qi++;
2950
+ }
2951
+ ni++;
2952
+ }
2953
+ if (qi !== q.length)
2954
+ return null;
2955
+ const maxGaps = Math.max(4, q.length * 2);
2956
+ if (gaps > maxGaps)
2957
+ return null;
2958
+ return 800 - gaps;
2959
+ }
2960
+ function parsePathQuery(rawInput) {
2961
+ const input = normalizePathInputSeparators(rawInput);
2962
+ const lastSlash = input.lastIndexOf("/");
2963
+ if (lastSlash < 0)
2964
+ return { dirPrefix: "", query: input };
2965
+ return {
2966
+ dirPrefix: input.slice(0, lastSlash + 1),
2967
+ query: input.slice(lastSlash + 1)
2968
+ };
2969
+ }
2970
+ async function suggestPaths(options) {
2971
+ const rawWorkspace = String(options.workspaceAbs ?? "");
2972
+ const rawInput = String(options.input ?? "");
2973
+ if (!rawWorkspace || rawWorkspace.includes("\0") || rawInput.includes("\0")) {
2974
+ const safeWorkspaceAbs = normalizePath(rawWorkspace || ".");
2975
+ return {
2976
+ baseDirAbs: resolvePath(safeWorkspaceAbs, "."),
2977
+ dirPrefix: "",
2978
+ query: "",
2979
+ suggestions: []
2980
+ };
2981
+ }
2982
+ const workspaceAbs = normalizePath(rawWorkspace);
2983
+ const input = normalizePathInputSeparators(rawInput);
2984
+ const parsed = parsePathQuery(input);
2985
+ let dirPrefix = parsed.dirPrefix;
2986
+ let query = parsed.query;
2987
+ let baseDirAbs = resolvePath(workspaceAbs, dirPrefix || ".");
2988
+ let maxDepth = options.maxDepth ?? 0;
2989
+ if (!query)
2990
+ maxDepth = 0;
2991
+ const allowHidden = Boolean(options.showHidden);
2992
+ const allowDir = options.mode === "directory" || options.mode === "any" || options.mode === "file";
2993
+ const allowFile = options.mode === "file" || options.mode === "any";
2994
+ const max = Math.max(0, Math.floor(options.max));
2995
+ if (max <= 0) {
2996
+ return { baseDirAbs, dirPrefix, query, suggestions: [] };
2997
+ }
2998
+ const maxDepthClamped = Math.max(0, Math.floor(maxDepth || 0));
2999
+ const keepCapacity = Math.max(500, Math.min(8e3, max * 40));
3000
+ const maxScannedDirs = Math.max(200, Math.min(6e3, 800 + maxDepthClamped * 600));
3001
+ const maxScannedEntries = Math.max(2e3, Math.min(8e4, max * 2e3));
3002
+ const scored = [];
3003
+ let scannedDirs = 0;
3004
+ let scannedEntries = 0;
3005
+ let scanAborted = false;
3006
+ function cmpScored(a, b) {
3007
+ if (a.score !== b.score)
3008
+ return b.score - a.score;
3009
+ if (a.depth !== b.depth)
3010
+ return a.depth - b.depth;
3011
+ return a.name.localeCompare(b.name);
3012
+ }
3013
+ function pruneScored() {
3014
+ if (scored.length <= keepCapacity)
3015
+ return;
3016
+ scored.sort(cmpScored);
3017
+ scored.length = keepCapacity;
3018
+ }
3019
+ function scoreItem(name, relPath, q) {
3020
+ const byName = fuzzyScore(name, q);
3021
+ const byPath = fuzzyScore(relPath, q);
3022
+ if (byName == null && byPath == null)
3023
+ return null;
3024
+ if (byName != null && byPath != null)
3025
+ return Math.max(byName + 50, byPath);
3026
+ return byName ?? byPath;
3027
+ }
3028
+ async function searchDir(dirAbs, currentDepth, currentRelPath, preloadedEntries) {
3029
+ if (scanAborted)
3030
+ return;
3031
+ if (currentDepth > maxDepth)
3032
+ return;
3033
+ if (dirAbs.includes("\0")) {
3034
+ scanAborted = true;
3035
+ return;
3036
+ }
3037
+ scannedDirs++;
3038
+ if (scannedDirs > maxScannedDirs) {
3039
+ scanAborted = true;
3040
+ return;
3041
+ }
3042
+ let entries = [];
3043
+ try {
3044
+ entries = preloadedEntries ?? await options.listDir(dirAbs);
3045
+ } catch {
3046
+ return;
3047
+ }
3048
+ for (const e of entries) {
3049
+ if (scanAborted)
3050
+ return;
3051
+ scannedEntries++;
3052
+ if (scannedEntries > maxScannedEntries) {
3053
+ scanAborted = true;
3054
+ return;
3055
+ }
3056
+ if (!allowHidden && !query && e.name.startsWith("."))
3057
+ continue;
3058
+ const itemRelPath = currentRelPath ? `${currentRelPath}/${e.name}` : e.name;
3059
+ const normalizedRelPath = normalizeRelativePathForIgnore(`${dirPrefix}${itemRelPath}`);
3060
+ const isDir = e.kind === "directory";
3061
+ if (options.shouldIgnore?.({ normalizedRelPath, isDir }))
3062
+ continue;
3063
+ if (e.kind === "directory") {
3064
+ if (!allowDir)
3065
+ continue;
3066
+ const score = scoreItem(e.name, itemRelPath, query);
3067
+ if (score != null) {
3068
+ scored.push({
3069
+ score,
3070
+ name: e.name,
3071
+ kind: "directory",
3072
+ depth: currentDepth,
3073
+ relPath: itemRelPath
3074
+ });
3075
+ if (scored.length > keepCapacity * 2)
3076
+ pruneScored();
3077
+ }
3078
+ await searchDir(`${dirAbs}/${e.name}`, currentDepth + 1, itemRelPath);
3079
+ continue;
3080
+ }
3081
+ if (e.kind === "file") {
3082
+ if (!allowFile)
3083
+ continue;
3084
+ const score = scoreItem(e.name, itemRelPath, query);
3085
+ if (score != null) {
3086
+ scored.push({
3087
+ score,
3088
+ name: e.name,
3089
+ kind: "file",
3090
+ depth: currentDepth,
3091
+ relPath: itemRelPath
3092
+ });
3093
+ if (scored.length > keepCapacity * 2)
3094
+ pruneScored();
3095
+ }
3096
+ }
3097
+ }
3098
+ }
3099
+ let ok = true;
3100
+ let baseEntries = null;
3101
+ try {
3102
+ baseEntries = await options.listDir(baseDirAbs);
3103
+ } catch {
3104
+ ok = false;
3105
+ }
3106
+ if (!ok && dirPrefix) {
3107
+ const fallbackQuery = stripTrailingSlashes(input);
3108
+ dirPrefix = "";
3109
+ query = fallbackQuery;
3110
+ baseDirAbs = workspaceAbs;
3111
+ maxDepth = options.maxDepth ?? 0;
3112
+ if (!query)
3113
+ maxDepth = 0;
3114
+ baseEntries = null;
3115
+ }
3116
+ await searchDir(baseDirAbs, 0, "", baseEntries ?? void 0);
3117
+ pruneScored();
3118
+ scored.sort(cmpScored);
3119
+ const list = max ? scored.slice(0, max) : [];
3120
+ const suggestions = list.map((s) => {
3121
+ const suffix = s.kind === "directory" ? "/" : "";
3122
+ const completion = `${dirPrefix}${s.relPath}${suffix}`;
3123
+ const absPath = resolvePath(workspaceAbs, `${dirPrefix}${s.relPath}`);
3124
+ return { kind: s.kind, display: completion, completion, absPath };
3125
+ });
3126
+ return { baseDirAbs, dirPrefix, query, suggestions };
3127
+ }
3128
+ function resolveUserPath(workspaceAbs, input, options) {
3129
+ const raw = stripCarriageReturns(input ?? "").trim();
3130
+ if (!raw)
3131
+ return resolvePath(normalizePath(workspaceAbs), ".");
3132
+ if (raw === "~" || raw.startsWith("~/")) {
3133
+ const home = String(options?.homeDir ?? "").trim();
3134
+ if (home) {
3135
+ const rest = raw === "~" ? "" : raw.slice(2);
3136
+ return resolvePath(normalizePath(home), rest);
3137
+ }
3138
+ }
3139
+ const normalized = normalizePathInputSeparators(raw);
3140
+ if (isAbsolutePath(normalized))
3141
+ return normalizePath(normalized);
3142
+ return resolvePath(normalizePath(workspaceAbs), normalized);
3143
+ }
3144
+ function suggestParentHint(path) {
3145
+ const p = normalizePath(path);
3146
+ const d = dirname(p);
3147
+ return d ? joinPath(d, "..") : "..";
3148
+ }
3149
+
3150
+ // src/utils/newlines.ts
3151
+ function normalizeNewlines(text) {
3152
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
3153
+ }