@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
@@ -0,0 +1,330 @@
1
+ import { shallowRef } from "vue";
2
+
3
+ //#region src/selection/terminal-selection.ts
4
+ const EMPTY_STATE = Object.freeze({
5
+ active: false,
6
+ anchor: null,
7
+ focus: null,
8
+ text: "",
9
+ hasRange: false
10
+ });
11
+ function clampPoint(point, cols, rows) {
12
+ return {
13
+ x: Math.max(0, Math.min(Math.max(0, cols - 1), Math.floor(point.x))),
14
+ y: Math.max(0, Math.min(Math.max(0, rows - 1), Math.floor(point.y)))
15
+ };
16
+ }
17
+ function comparePoints(a, b) {
18
+ return a.y - b.y || a.x - b.x;
19
+ }
20
+ function pointKey(point) {
21
+ return `${point.x}:${point.y}`;
22
+ }
23
+ function providerPointsDiffer(a, b) {
24
+ return Boolean(a && b && a.providerId === b.providerId && pointKey(a.point) !== pointKey(b.point));
25
+ }
26
+ function terminalSelectionRowSpans(range, cols, rows) {
27
+ if (cols <= 0 || rows <= 0) return [];
28
+ const anchor = clampPoint(range.anchor, cols, rows);
29
+ const focus = clampPoint(range.focus, cols, rows);
30
+ if (pointKey(anchor) === pointKey(focus)) return [];
31
+ const start = comparePoints(anchor, focus) <= 0 ? anchor : focus;
32
+ const end = start === anchor ? focus : anchor;
33
+ const spans = [];
34
+ for (let y = start.y; y <= end.y; y++) {
35
+ const x0 = y === start.y ? start.x : 0;
36
+ const x1 = y === end.y ? end.x + 1 : cols;
37
+ if (x1 > x0) spans.push({
38
+ y,
39
+ x0,
40
+ x1
41
+ });
42
+ }
43
+ return spans;
44
+ }
45
+ function terminalSelectionVisibleRowSpans(range, cols, rows, visibleStartY, visibleEndY) {
46
+ if (cols <= 0 || rows <= 0) return [];
47
+ const anchor = clampPoint(range.anchor, cols, rows);
48
+ const focus = clampPoint(range.focus, cols, rows);
49
+ if (pointKey(anchor) === pointKey(focus)) return [];
50
+ const start = comparePoints(anchor, focus) <= 0 ? anchor : focus;
51
+ const end = start === anchor ? focus : anchor;
52
+ const fromY = Math.max(start.y, Math.floor(visibleStartY), 0);
53
+ const toY = Math.min(end.y, Math.ceil(visibleEndY) - 1, rows - 1);
54
+ if (toY < fromY) return [];
55
+ const spans = [];
56
+ for (let y = fromY; y <= toY; y++) {
57
+ const x0 = y === start.y ? start.x : 0;
58
+ const x1 = y === end.y ? end.x + 1 : cols;
59
+ if (x1 > x0) spans.push({
60
+ y,
61
+ x0,
62
+ x1
63
+ });
64
+ }
65
+ return spans;
66
+ }
67
+ function selectedRowText(row, x0, x1, cols) {
68
+ let out = "";
69
+ for (let x = x0; x < x1; x++) {
70
+ const cell = row[x];
71
+ if (!cell || cell.continuation) continue;
72
+ out += cell.ch || " ";
73
+ }
74
+ return x1 >= cols ? out.trimEnd() : out;
75
+ }
76
+ function copyPayload(text, ok, error) {
77
+ return {
78
+ text,
79
+ rows: text ? text.split("\n").length : 0,
80
+ chars: text.length,
81
+ ok,
82
+ ...error === void 0 ? {} : { error }
83
+ };
84
+ }
85
+ function clampPointToRect(point, rect) {
86
+ return {
87
+ x: Math.max(rect.x, Math.min(rect.x + Math.max(0, rect.w - 1), Math.floor(point.x))),
88
+ y: Math.max(rect.y, Math.min(rect.y + Math.max(0, rect.h - 1), Math.floor(point.y)))
89
+ };
90
+ }
91
+ function createTerminalSelectionController(options) {
92
+ const state = shallowRef(EMPTY_STATE);
93
+ let range = null;
94
+ let providerAnchor = null;
95
+ let providerFocus = null;
96
+ let overlaySpans = new Map();
97
+ let dirtyRows = new Set();
98
+ const readOptions = () => ({
99
+ autoCopy: true,
100
+ copyOnMouseUp: true,
101
+ style: { inverse: true },
102
+ ...options.getOptions?.() ?? {}
103
+ });
104
+ const markDirty = (prev, next) => {
105
+ const rows = new Set();
106
+ for (const y of prev) rows.add(y);
107
+ for (const y of next) rows.add(y);
108
+ if (rows.size) options.onDirtyRows?.(Array.from(rows).sort((a, b) => a - b));
109
+ };
110
+ const providers = () => options.getTextProviders?.() ?? [];
111
+ const getRow = (y) => options.getRow?.(y) ?? options.terminal.getRow(y);
112
+ const providerById = (id) => providers().find((provider) => provider.id === id) ?? null;
113
+ const providerForCell = (point) => {
114
+ let best = null;
115
+ let bestArea = Infinity;
116
+ for (const provider of providers()) {
117
+ const rect = provider.rect;
118
+ if (point.x < rect.x || point.y < rect.y || point.x >= rect.x + rect.w || point.y >= rect.y + rect.h) continue;
119
+ const area = Math.max(0, rect.w) * Math.max(0, rect.h);
120
+ if (area < bestArea) {
121
+ best = provider;
122
+ bestArea = area;
123
+ }
124
+ }
125
+ return best;
126
+ };
127
+ const providerPointForCell = (provider, point, options$1) => {
128
+ const inputPoint = options$1?.clampToRect ? clampPointToRect(point, provider.rect) : point;
129
+ const providerPoint = provider.pointForCell?.(inputPoint) ?? inputPoint;
130
+ return providerPoint ? {
131
+ providerId: provider.id,
132
+ point: providerPoint
133
+ } : null;
134
+ };
135
+ const textFromTerminalBuffer = (nextRange) => {
136
+ const size = options.terminal.size();
137
+ const spans = terminalSelectionRowSpans(nextRange, size.cols, size.rows);
138
+ const lines = [];
139
+ for (const span of spans) lines.push(selectedRowText(getRow(span.y), span.x0, span.x1, size.cols));
140
+ return lines.join("\n");
141
+ };
142
+ const providerRangeFor = (provider, screenRange, anchorOverride, focusOverride) => {
143
+ if (anchorOverride && focusOverride && anchorOverride.providerId === provider.id && focusOverride.providerId === provider.id) return {
144
+ anchor: anchorOverride.point,
145
+ focus: focusOverride.point,
146
+ mode: screenRange.mode
147
+ };
148
+ const anchor = providerPointForCell(provider, screenRange.anchor, { clampToRect: true });
149
+ const focus = providerPointForCell(provider, screenRange.focus, { clampToRect: true });
150
+ if (!anchor || !focus) return null;
151
+ if (anchor.providerId !== provider.id || focus.providerId !== provider.id) return null;
152
+ return {
153
+ anchor: anchor.point,
154
+ focus: focus.point,
155
+ mode: screenRange.mode
156
+ };
157
+ };
158
+ const selectedText = () => {
159
+ if (!range) return "";
160
+ const currentRange = range;
161
+ if (providerAnchor && providerFocus && providerAnchor.providerId === providerFocus.providerId) {
162
+ const provider$1 = providerById(providerAnchor.providerId);
163
+ if (provider$1) {
164
+ const providerRange = providerRangeFor(provider$1, currentRange, providerAnchor, providerFocus);
165
+ if (providerRange) return provider$1.getText(providerRange);
166
+ }
167
+ }
168
+ const provider = providers().find((candidate) => candidate.canHandle(currentRange));
169
+ if (provider) {
170
+ const providerRange = providerRangeFor(provider, currentRange);
171
+ if (providerRange) return provider.getText(providerRange);
172
+ }
173
+ return textFromTerminalBuffer(currentRange);
174
+ };
175
+ const setResolvedText = (text) => {
176
+ if (!range || !state.value.active || state.value.text === text) return;
177
+ state.value = {
178
+ ...state.value,
179
+ text
180
+ };
181
+ };
182
+ const resolveProvider = (nextRange, nextProviderAnchor) => {
183
+ if (!nextRange) return null;
184
+ if (nextProviderAnchor) {
185
+ const provider = providerById(nextProviderAnchor.providerId);
186
+ if (provider) return provider;
187
+ }
188
+ return providers().find((candidate) => candidate.canHandle(nextRange)) ?? null;
189
+ };
190
+ const rebuild = (nextRange, nextProviderAnchor, nextProviderFocus) => {
191
+ const previousRows = dirtyRows;
192
+ const size = options.terminal.size();
193
+ const nextOverlaySpans = new Map();
194
+ const nextDirtyRows = new Set();
195
+ let hasRange = false;
196
+ if (nextRange) {
197
+ const activeProvider = resolveProvider(nextRange, nextProviderAnchor);
198
+ let spans;
199
+ const providerRange = activeProvider != null ? providerRangeFor(activeProvider, nextRange, nextProviderAnchor, nextProviderFocus) : null;
200
+ if (activeProvider?.getVisibleSpans && providerRange) spans = activeProvider.getVisibleSpans(providerRange, nextRange);
201
+ else spans = terminalSelectionRowSpans(nextRange, size.cols, size.rows);
202
+ hasRange = spans.length > 0 || providerPointsDiffer(nextProviderAnchor, nextProviderFocus);
203
+ for (const span of spans) {
204
+ const x0 = Math.max(0, Math.min(size.cols, Math.floor(span.x0)));
205
+ const x1 = Math.max(0, Math.min(size.cols, Math.floor(span.x1)));
206
+ const y = Math.floor(span.y);
207
+ if (y < 0 || y >= size.rows || x1 <= x0) continue;
208
+ let list = nextOverlaySpans.get(y);
209
+ if (!list) {
210
+ list = [];
211
+ nextOverlaySpans.set(y, list);
212
+ }
213
+ list.push({
214
+ y,
215
+ x0,
216
+ x1
217
+ });
218
+ nextDirtyRows.add(y);
219
+ }
220
+ }
221
+ range = nextRange;
222
+ providerAnchor = nextProviderAnchor;
223
+ providerFocus = nextProviderFocus;
224
+ overlaySpans = nextOverlaySpans;
225
+ dirtyRows = nextDirtyRows;
226
+ state.value = nextRange ? {
227
+ active: true,
228
+ anchor: nextRange.anchor,
229
+ focus: nextRange.focus,
230
+ text: "",
231
+ hasRange
232
+ } : EMPTY_STATE;
233
+ markDirty(previousRows, nextDirtyRows);
234
+ };
235
+ const controller = {
236
+ state,
237
+ start(point, startOptions) {
238
+ const size = options.terminal.size();
239
+ const focus = clampPoint(point, size.cols, size.rows);
240
+ const anchor = startOptions?.extend && range?.anchor ? clampPoint(range.anchor, size.cols, size.rows) : focus;
241
+ const anchorProvider = providerForCell(anchor);
242
+ const focusProvider = providerForCell(focus);
243
+ const activeProvider = startOptions?.extend && providerAnchor ? providerById(providerAnchor.providerId) : null;
244
+ const nextProviderAnchor = startOptions?.extend && providerAnchor ? providerAnchor : anchorProvider ? providerPointForCell(anchorProvider, anchor) : null;
245
+ const nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, focus, { clampToRect: true }) : nextProviderAnchor && focusProvider?.id === nextProviderAnchor.providerId ? providerPointForCell(focusProvider, focus) : null;
246
+ rebuild({
247
+ anchor,
248
+ focus,
249
+ mode: "linear"
250
+ }, nextProviderAnchor, nextProviderFocus);
251
+ },
252
+ update(point) {
253
+ if (!range) return;
254
+ const size = options.terminal.size();
255
+ const focus = clampPoint(point, size.cols, size.rows);
256
+ const activeProvider = providerAnchor ? providerById(providerAnchor.providerId) : null;
257
+ const nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, focus, { clampToRect: true }) : null;
258
+ rebuild({
259
+ ...range,
260
+ focus
261
+ }, providerAnchor, nextProviderFocus);
262
+ },
263
+ async finish() {
264
+ if (!range) return;
265
+ if (!state.value.hasRange) {
266
+ controller.clear();
267
+ return;
268
+ }
269
+ const current = readOptions();
270
+ if (!current.autoCopy || !current.copyOnMouseUp) return;
271
+ await controller.copy();
272
+ },
273
+ clear() {
274
+ if (!range && !dirtyRows.size) return;
275
+ rebuild(null, null, null);
276
+ },
277
+ async copy() {
278
+ const text = state.value.text || selectedText();
279
+ if (!text) return false;
280
+ setResolvedText(text);
281
+ if (!options.clipboard.supported) {
282
+ options.onCopy?.(copyPayload(text, false, new Error("Clipboard unavailable")));
283
+ return false;
284
+ }
285
+ try {
286
+ await options.clipboard.writeText(text);
287
+ options.onCopy?.(copyPayload(text, true));
288
+ return true;
289
+ } catch (error) {
290
+ options.onCopy?.(copyPayload(text, false, error));
291
+ return false;
292
+ }
293
+ },
294
+ paint(dirtyRowsHint) {
295
+ const rows = dirtyRowsHint ?? Array.from(overlaySpans.keys());
296
+ const selectionStyle = readOptions().style;
297
+ for (const y of rows) {
298
+ const spans = overlaySpans.get(y);
299
+ if (!spans?.length) continue;
300
+ const row = getRow(y);
301
+ for (const span of spans) for (let x = span.x0; x < span.x1; x++) {
302
+ const cell = row[x];
303
+ if (!cell || cell.continuation) continue;
304
+ const { href: _href,...baseStyle } = cell.style;
305
+ options.overlayTerminal.put(x, y, cell.ch || " ", {
306
+ ...baseStyle,
307
+ ...selectionStyle
308
+ });
309
+ }
310
+ }
311
+ },
312
+ refresh(refreshOptions) {
313
+ if (!range) return;
314
+ if (refreshOptions?.remapFocus) {
315
+ const activeProvider = providerAnchor ? providerById(providerAnchor.providerId) : resolveProvider(range, null);
316
+ const nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, range.focus, { clampToRect: true }) : providerFocus;
317
+ rebuild(range, providerAnchor, nextProviderFocus);
318
+ return;
319
+ }
320
+ rebuild(range, providerAnchor, providerFocus);
321
+ },
322
+ clearProvider(providerId) {
323
+ if (providerAnchor?.providerId === providerId || providerFocus?.providerId === providerId) controller.clear();
324
+ }
325
+ };
326
+ return controller;
327
+ }
328
+
329
+ //#endregion
330
+ export { createTerminalSelectionController, terminalSelectionRowSpans, terminalSelectionVisibleRowSpans };