@simon_he/vue-tui 1.0.1 → 1.1.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 (128) hide show
  1. package/README.md +139 -46
  2. package/dist/TMermaidText-frVr8Ysb.js +885 -0
  3. package/dist/{TSelect-HzILuti9.js → TSelect-tJ87rKPM.js} +59 -242
  4. package/dist/{TTree-ChOot2Bh.js → TTree-CGdE-CYu.js} +138 -102
  5. package/dist/agent/mermaid.cjs +2 -0
  6. package/dist/agent/mermaid.d.cts +2 -0
  7. package/dist/agent/mermaid.d.ts +2 -0
  8. package/dist/agent/mermaid.js +1 -0
  9. package/dist/agent.cjs +31188 -24907
  10. package/dist/agent.d.cts +11 -1
  11. package/dist/agent.d.ts +11 -1
  12. package/dist/agent.js +516 -11
  13. package/dist/{block-source-CKUOnkgT.js → block-source-CrlmaBM5.js} +1039 -66
  14. package/dist/cli/input.d.ts +8 -0
  15. package/dist/cli/stdin-buffer.d.ts +1 -1
  16. package/dist/cli/video/ffmpeg-frame-source.d.ts +10 -0
  17. package/dist/cli/video/png-frame-parser.d.ts +4 -0
  18. package/dist/cli/video/raw-frame-parser.d.ts +1 -0
  19. package/dist/cli/video/yt-dlp-frame-source.d.ts +11 -0
  20. package/dist/cli.cjs +5470 -6176
  21. package/dist/cli.d.cts +6 -2
  22. package/dist/cli.d.ts +6 -2
  23. package/dist/cli.js +3747 -350
  24. package/dist/core/buffer/buffer.d.ts +2 -2
  25. package/dist/core/buffer/eaw-ranges-unicode-17.d.ts +14 -0
  26. package/dist/core/perf/instrumentation-noop.d.ts +48 -0
  27. package/dist/core/perf/instrumentation.d.ts +136 -0
  28. package/dist/core/terminal/create-terminal.d.ts +1 -0
  29. package/dist/core/types.d.ts +0 -4
  30. package/dist/core.cjs +851 -1462
  31. package/dist/core.js +4 -5
  32. package/dist/create-terminal-app.d.ts +24 -1
  33. package/dist/debug-logger-CmsGI4of.js +74 -0
  34. package/dist/{dom-renderer-BqGijQID.js → dom-renderer-DXx8fWzD.js} +2 -3
  35. package/dist/experimental/3d/bun/contributor-avatar-atlas.d.ts +12 -0
  36. package/dist/experimental/3d/bun/png.d.ts +1 -0
  37. package/dist/experimental/3d/bun/terminal-badge-scene.d.ts +11 -0
  38. package/dist/experimental/3d/bun/terminal-badge.wgsl.d.ts +1 -0
  39. package/dist/experimental/3d/bun/webgpu-renderer.d.ts +26 -0
  40. package/dist/experimental/3d/bun.cjs +7271 -0
  41. package/dist/experimental/3d/bun.d.cts +4 -0
  42. package/dist/experimental/3d/bun.d.ts +4 -0
  43. package/dist/experimental/3d/bun.js +7390 -0
  44. package/dist/experimental/video/node.cjs +497 -0
  45. package/dist/experimental/video/node.d.cts +4 -0
  46. package/dist/experimental/video/node.d.ts +4 -0
  47. package/dist/experimental/video/node.js +610 -0
  48. package/dist/experimental.cjs +6876 -6192
  49. package/dist/experimental.d.cts +7 -0
  50. package/dist/experimental.d.ts +7 -0
  51. package/dist/experimental.js +3005 -9
  52. package/dist/frame-perf-CHpWhbC4.js +111 -0
  53. package/dist/{create-terminal-C2oiWFJU.js → hyperlink-_1FAj7Wq.js} +455 -19
  54. package/dist/index.cjs +5025 -10332
  55. package/dist/index.js +14 -13
  56. package/dist/{linkify-D_gzn9Xq.js → linkify-D68T7rdW.js} +193 -3
  57. package/dist/markdown.cjs +21295 -12691
  58. package/dist/markdown.d.cts +1 -1
  59. package/dist/markdown.d.ts +1 -1
  60. package/dist/markdown.js +211 -51
  61. package/dist/mermaid-BNhM1jAZ.js +123 -0
  62. package/dist/mermaid.cjs +1707 -0
  63. package/dist/mermaid.d.cts +3 -0
  64. package/dist/mermaid.d.ts +3 -0
  65. package/dist/mermaid.js +6 -0
  66. package/dist/observability/frame-perf-store.d.ts +2 -1
  67. package/dist/observability/frame-perf.d.ts +33 -0
  68. package/dist/observability.cjs +106 -107
  69. package/dist/observability.d.cts +2 -2
  70. package/dist/observability.d.ts +2 -2
  71. package/dist/observability.js +3 -3
  72. package/dist/{wheel-scroll-vBRaQ7p-.js → rect-DUpeDfBg.js} +253 -117
  73. package/dist/renderer/cli/index.d.ts +1 -1
  74. package/dist/renderer/cli/stdout-metrics.d.ts +10 -0
  75. package/dist/renderer/cli/stdout-renderer.d.ts +53 -7
  76. package/dist/renderer/terminal-graphic-render-queue.d.ts +50 -0
  77. package/dist/renderer/terminal-graphics-trace.d.ts +53 -0
  78. package/dist/renderer/terminal-graphics.d.ts +147 -0
  79. package/dist/renderer-dom.cjs +364 -903
  80. package/dist/renderer-dom.js +4 -5
  81. package/dist/runtime/index.d.ts +2 -0
  82. package/dist/{runtime-rfcZCyJq.js → runtime-Byf8XXOT.js} +28 -15
  83. package/dist/runtime.cjs +427 -889
  84. package/dist/runtime.js +2 -2
  85. package/dist/terminal-graphics-Bbe83wSr.js +597 -0
  86. package/dist/{terminal-selection-DBinO6p5.js → terminal-selection-4W1SJj4c.js} +4 -1
  87. package/dist/{tlog-theme-CvLFNMwk.js → tlog-theme-Bul2Na3u.js} +1237 -12
  88. package/dist/{trace-CjzYeIxN.js → trace-Bh8WnoMo.js} +5 -0
  89. package/dist/vue/agent/create-png-terminal-graphic-renderer.d.ts +19 -0
  90. package/dist/vue/components/T3DViewport.d.ts +473 -0
  91. package/dist/vue/components/TAgentTerminalGraphic.d.ts +494 -0
  92. package/dist/vue/components/TCharts.d.ts +1121 -0
  93. package/dist/vue/components/TFeedback.d.ts +1 -1
  94. package/dist/vue/components/TFlex.d.ts +389 -0
  95. package/dist/vue/components/TForm.d.ts +4 -4
  96. package/dist/vue/components/TLogSearchBar.d.ts +3 -3
  97. package/dist/vue/components/TLogSearchPager.d.ts +2 -2
  98. package/dist/vue/components/TMarkdownText.d.ts +162 -4
  99. package/dist/vue/components/TMermaidText.d.ts +900 -0
  100. package/dist/vue/components/TVideo.d.ts +291 -0
  101. package/dist/vue/components/TVirtualList.d.ts +9 -0
  102. package/dist/vue/components/TVirtualMarkdown.d.ts +170 -9
  103. package/dist/vue/components/TVirtualRows.d.ts +9 -0
  104. package/dist/vue/components/TerminalProvider.d.ts +2 -0
  105. package/dist/vue/context.d.ts +24 -0
  106. package/dist/vue/index.d.ts +5 -0
  107. package/dist/vue/layout/flex.d.ts +67 -0
  108. package/dist/vue/markdown/ast.d.ts +5 -2
  109. package/dist/vue/markdown/document.d.ts +5 -0
  110. package/dist/vue/markdown/image-actions.d.ts +14 -0
  111. package/dist/vue/markdown/image.d.ts +11 -0
  112. package/dist/vue/markdown/link-actions.d.ts +14 -0
  113. package/dist/vue/markdown/math-actions.d.ts +14 -0
  114. package/dist/vue/markdown/math.d.ts +6 -0
  115. package/dist/vue/markdown/render.d.ts +28 -0
  116. package/dist/vue/markdown/types.d.ts +78 -0
  117. package/dist/vue/mermaid/beautiful-mermaid.d.ts +1436 -0
  118. package/dist/vue/render/render-manager.d.ts +7 -0
  119. package/dist/vue/video/types.d.ts +39 -0
  120. package/dist/vue.cjs +7215 -12430
  121. package/dist/vue.js +704 -38
  122. package/dist/wheel-scroll-DASkEZr-.js +106 -0
  123. package/dist/{hyperlink-Bn02UXJb.js → width-GqllnV8C.js} +166 -111
  124. package/package.json +141 -18
  125. package/dist/frame-perf-C6Xfg85O.js +0 -24
  126. package/dist/sgr-BmzxEjAO.js +0 -304
  127. /package/dist/{ansi-palette-CNXqFciC.js → ansi-palette-CH6jc2Z7.js} +0 -0
  128. /package/dist/{path-suggest-BNqcuE3-.js → path-suggest-Dndu4dTi.js} +0 -0
@@ -0,0 +1,1707 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: !0 });
10
+ }, __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from == "object" || typeof from == "function")
12
+ for (let key of __getOwnPropNames(from))
13
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
22
+ mod
23
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
24
+
25
+ // src/mermaid.ts
26
+ var mermaid_exports = {};
27
+ __export(mermaid_exports, {
28
+ TBeautifulMermaid: () => TBeautifulMermaid,
29
+ TBeautifulMermaidText: () => TBeautifulMermaidText,
30
+ TMermaid: () => TMermaid,
31
+ TMermaidText: () => TMermaidText2,
32
+ beautifulMermaidRenderer: () => beautifulMermaidRenderer,
33
+ createBeautifulMermaidRenderer: () => createBeautifulMermaidRenderer,
34
+ isSimpleMermaidFlowchartSource: () => isSimpleMermaidFlowchartSource,
35
+ markMermaidRenderErrorFatal: () => markMermaidRenderErrorFatal
36
+ });
37
+ module.exports = __toCommonJS(mermaid_exports);
38
+
39
+ // src/vue/components/TMermaidText.ts
40
+ var import_vue8 = require("vue");
41
+
42
+ // src/vue/context.ts
43
+ var import_vue = require("vue");
44
+
45
+ // src/vue/injection-key.ts
46
+ var VUE_TUI_INJECTION_PROTOCOL = "v1";
47
+ function injectionKey(name) {
48
+ return Symbol.for(`@simon_he/vue-tui:${VUE_TUI_INJECTION_PROTOCOL}:${name}`);
49
+ }
50
+
51
+ // src/vue/context.ts
52
+ var TerminalContextKey = injectionKey("TerminalContext"), LayoutContextKey = injectionKey("LayoutContext"), VisibilityContextKey = injectionKey("VisibilityContext"), EventZIndexContextKey = injectionKey("EventZIndex"), RenderPlaneContextKey = injectionKey("RenderPlane"), ImeAnchorContextKey = injectionKey("ImeAnchor"), TInputPluginsContextKey = injectionKey("TInputPlugins"), TPathPickerProviderContextKey = injectionKey("TPathPickerProvider"), TerminalGraphicsActivityKey = injectionKey(
53
+ "TerminalGraphicsActivity"
54
+ ), DialogContextKey = injectionKey("DialogContext");
55
+
56
+ // src/vue/composables/use-layout.ts
57
+ var import_vue2 = require("vue");
58
+ function useLayout() {
59
+ let ctx = (0, import_vue2.inject)(LayoutContextKey, null);
60
+ if (!ctx)
61
+ throw new Error("LayoutContext is missing (TerminalProvider/TView)");
62
+ return ctx;
63
+ }
64
+
65
+ // src/vue/composables/use-render-node.ts
66
+ var import_vue5 = require("vue");
67
+
68
+ // src/vue/composables/use-render-stack.ts
69
+ var import_vue3 = require("vue");
70
+
71
+ // src/vue/render/context.ts
72
+ var RenderStackKey = injectionKey("RenderStack");
73
+
74
+ // src/vue/composables/use-render-stack.ts
75
+ function useRenderStack() {
76
+ let stack = (0, import_vue3.inject)(RenderStackKey, null);
77
+ if (!stack)
78
+ throw new Error("RenderStack is missing");
79
+ return stack;
80
+ }
81
+
82
+ // src/vue/composables/use-terminal.ts
83
+ var import_vue4 = require("vue");
84
+ function useTerminal() {
85
+ let ctx = (0, import_vue4.inject)(TerminalContextKey, null);
86
+ if (!ctx)
87
+ throw new Error("TerminalProvider is missing");
88
+ return ctx;
89
+ }
90
+
91
+ // src/core/buffer/eaw-ranges-unicode-17.ts
92
+ var fullWidthRanges = [
93
+ [4352, 4447],
94
+ [8986, 8987],
95
+ [9001, 9002],
96
+ [9193, 9196],
97
+ [9200, 9200],
98
+ [9203, 9203],
99
+ [9725, 9726],
100
+ [9748, 9749],
101
+ [9776, 9783],
102
+ [9800, 9811],
103
+ [9855, 9855],
104
+ [9866, 9871],
105
+ [9875, 9875],
106
+ [9889, 9889],
107
+ [9898, 9899],
108
+ [9917, 9918],
109
+ [9924, 9925],
110
+ [9934, 9934],
111
+ [9940, 9940],
112
+ [9962, 9962],
113
+ [9970, 9971],
114
+ [9973, 9973],
115
+ [9978, 9978],
116
+ [9981, 9981],
117
+ [9989, 9989],
118
+ [9994, 9995],
119
+ [10024, 10024],
120
+ [10060, 10060],
121
+ [10062, 10062],
122
+ [10067, 10069],
123
+ [10071, 10071],
124
+ [10133, 10135],
125
+ [10160, 10160],
126
+ [10175, 10175],
127
+ [11035, 11036],
128
+ [11088, 11088],
129
+ [11093, 11093],
130
+ [11904, 11929],
131
+ [11931, 12019],
132
+ [12032, 12245],
133
+ [12272, 12350],
134
+ [12353, 12438],
135
+ [12441, 12543],
136
+ [12549, 12591],
137
+ [12593, 12686],
138
+ [12688, 12773],
139
+ [12783, 12830],
140
+ [12832, 12871],
141
+ [12880, 42124],
142
+ [42128, 42182],
143
+ [43360, 43388],
144
+ [44032, 55203],
145
+ [63744, 64255],
146
+ [65040, 65049],
147
+ [65072, 65106],
148
+ [65108, 65126],
149
+ [65128, 65131],
150
+ [65281, 65376],
151
+ [65504, 65510],
152
+ [94176, 94180],
153
+ [94192, 94198],
154
+ [94208, 101589],
155
+ [101631, 101662],
156
+ [101760, 101874],
157
+ [110576, 110579],
158
+ [110581, 110587],
159
+ [110589, 110590],
160
+ [110592, 110882],
161
+ [110898, 110898],
162
+ [110928, 110930],
163
+ [110933, 110933],
164
+ [110948, 110951],
165
+ [110960, 111355],
166
+ [119552, 119638],
167
+ [119648, 119670],
168
+ [126980, 126980],
169
+ [127183, 127183],
170
+ [127374, 127374],
171
+ [127377, 127386],
172
+ [127488, 127490],
173
+ [127504, 127547],
174
+ [127552, 127560],
175
+ [127568, 127569],
176
+ [127584, 127589],
177
+ [127744, 127776],
178
+ [127789, 127797],
179
+ [127799, 127868],
180
+ [127870, 127891],
181
+ [127904, 127946],
182
+ [127951, 127955],
183
+ [127968, 127984],
184
+ [127988, 127988],
185
+ [127992, 128062],
186
+ [128064, 128064],
187
+ [128066, 128252],
188
+ [128255, 128317],
189
+ [128331, 128334],
190
+ [128336, 128359],
191
+ [128378, 128378],
192
+ [128405, 128406],
193
+ [128420, 128420],
194
+ [128507, 128591],
195
+ [128640, 128709],
196
+ [128716, 128716],
197
+ [128720, 128722],
198
+ [128725, 128728],
199
+ [128732, 128735],
200
+ [128747, 128748],
201
+ [128756, 128764],
202
+ [128992, 129003],
203
+ [129008, 129008],
204
+ [129292, 129338],
205
+ [129340, 129349],
206
+ [129351, 129535],
207
+ [129648, 129660],
208
+ [129664, 129674],
209
+ [129678, 129734],
210
+ [129736, 129736],
211
+ [129741, 129756],
212
+ [129759, 129770],
213
+ [129775, 129784],
214
+ [131072, 196605],
215
+ [196608, 262141]
216
+ ], ambiguousWidthRanges = [
217
+ [161, 161],
218
+ [164, 164],
219
+ [167, 168],
220
+ [170, 170],
221
+ [173, 174],
222
+ [176, 180],
223
+ [182, 186],
224
+ [188, 191],
225
+ [198, 198],
226
+ [208, 208],
227
+ [215, 216],
228
+ [222, 225],
229
+ [230, 230],
230
+ [232, 234],
231
+ [236, 237],
232
+ [240, 240],
233
+ [242, 243],
234
+ [247, 250],
235
+ [252, 252],
236
+ [254, 254],
237
+ [257, 257],
238
+ [273, 273],
239
+ [275, 275],
240
+ [283, 283],
241
+ [294, 295],
242
+ [299, 299],
243
+ [305, 307],
244
+ [312, 312],
245
+ [319, 322],
246
+ [324, 324],
247
+ [328, 331],
248
+ [333, 333],
249
+ [338, 339],
250
+ [358, 359],
251
+ [363, 363],
252
+ [462, 462],
253
+ [464, 464],
254
+ [466, 466],
255
+ [468, 468],
256
+ [470, 470],
257
+ [472, 472],
258
+ [474, 474],
259
+ [476, 476],
260
+ [593, 593],
261
+ [609, 609],
262
+ [708, 708],
263
+ [711, 711],
264
+ [713, 715],
265
+ [717, 717],
266
+ [720, 720],
267
+ [728, 731],
268
+ [733, 733],
269
+ [735, 735],
270
+ [768, 879],
271
+ [913, 929],
272
+ [931, 937],
273
+ [945, 961],
274
+ [963, 969],
275
+ [1025, 1025],
276
+ [1040, 1103],
277
+ [1105, 1105],
278
+ [8208, 8208],
279
+ [8211, 8214],
280
+ [8216, 8217],
281
+ [8220, 8221],
282
+ [8224, 8226],
283
+ [8228, 8231],
284
+ [8240, 8240],
285
+ [8242, 8243],
286
+ [8245, 8245],
287
+ [8251, 8251],
288
+ [8254, 8254],
289
+ [8308, 8308],
290
+ [8319, 8319],
291
+ [8321, 8324],
292
+ [8364, 8364],
293
+ [8451, 8451],
294
+ [8453, 8453],
295
+ [8457, 8457],
296
+ [8467, 8467],
297
+ [8470, 8470],
298
+ [8481, 8482],
299
+ [8486, 8486],
300
+ [8491, 8491],
301
+ [8531, 8532],
302
+ [8539, 8542],
303
+ [8544, 8555],
304
+ [8560, 8569],
305
+ [8585, 8585],
306
+ [8592, 8601],
307
+ [8632, 8633],
308
+ [8658, 8658],
309
+ [8660, 8660],
310
+ [8679, 8679],
311
+ [8704, 8704],
312
+ [8706, 8707],
313
+ [8711, 8712],
314
+ [8715, 8715],
315
+ [8719, 8719],
316
+ [8721, 8721],
317
+ [8725, 8725],
318
+ [8730, 8730],
319
+ [8733, 8736],
320
+ [8739, 8739],
321
+ [8741, 8741],
322
+ [8743, 8748],
323
+ [8750, 8750],
324
+ [8756, 8759],
325
+ [8764, 8765],
326
+ [8776, 8776],
327
+ [8780, 8780],
328
+ [8786, 8786],
329
+ [8800, 8801],
330
+ [8804, 8807],
331
+ [8810, 8811],
332
+ [8814, 8815],
333
+ [8834, 8835],
334
+ [8838, 8839],
335
+ [8853, 8853],
336
+ [8857, 8857],
337
+ [8869, 8869],
338
+ [8895, 8895],
339
+ [8978, 8978],
340
+ [9312, 9449],
341
+ [9451, 9547],
342
+ [9552, 9587],
343
+ [9600, 9615],
344
+ [9618, 9621],
345
+ [9632, 9633],
346
+ [9635, 9641],
347
+ [9650, 9651],
348
+ [9654, 9655],
349
+ [9660, 9661],
350
+ [9664, 9665],
351
+ [9670, 9672],
352
+ [9675, 9675],
353
+ [9678, 9681],
354
+ [9698, 9701],
355
+ [9711, 9711],
356
+ [9733, 9734],
357
+ [9737, 9737],
358
+ [9742, 9743],
359
+ [9756, 9756],
360
+ [9758, 9758],
361
+ [9792, 9792],
362
+ [9794, 9794],
363
+ [9824, 9825],
364
+ [9827, 9829],
365
+ [9831, 9834],
366
+ [9836, 9837],
367
+ [9839, 9839],
368
+ [9886, 9887],
369
+ [9919, 9919],
370
+ [9926, 9933],
371
+ [9935, 9939],
372
+ [9941, 9953],
373
+ [9955, 9955],
374
+ [9960, 9961],
375
+ [9963, 9969],
376
+ [9972, 9972],
377
+ [9974, 9977],
378
+ [9979, 9980],
379
+ [9982, 9983],
380
+ [10045, 10045],
381
+ [10102, 10111],
382
+ [11094, 11097],
383
+ [12872, 12879],
384
+ [57344, 63743],
385
+ [65024, 65039],
386
+ [65533, 65533],
387
+ [127232, 127242],
388
+ [127248, 127277],
389
+ [127280, 127337],
390
+ [127344, 127373],
391
+ [127375, 127376],
392
+ [127387, 127404],
393
+ [917760, 917999],
394
+ [983040, 1048573],
395
+ [1048576, 1114109]
396
+ ];
397
+
398
+ // src/core/buffer/width.ts
399
+ function isFullWidthCodePoint(codePoint) {
400
+ if (codePoint < 4352)
401
+ return !1;
402
+ for (let [start, end] of fullWidthRanges) {
403
+ if (codePoint < start)
404
+ return !1;
405
+ if (codePoint <= end)
406
+ return !0;
407
+ }
408
+ return !1;
409
+ }
410
+ function isAmbiguousWidthCodePoint(codePoint) {
411
+ let first = ambiguousWidthRanges[0], last = ambiguousWidthRanges[ambiguousWidthRanges.length - 1];
412
+ if (!first || !last || codePoint < first[0] || codePoint > last[1])
413
+ return !1;
414
+ for (let [start, end] of ambiguousWidthRanges) {
415
+ if (codePoint < start)
416
+ return !1;
417
+ if (codePoint <= end)
418
+ return !0;
419
+ }
420
+ return !1;
421
+ }
422
+ function isVariationSelectorCodePoint(codePoint) {
423
+ return codePoint >= 65024 && codePoint <= 65039 || codePoint >= 917760 && codePoint <= 917999;
424
+ }
425
+ function isCombiningMarkCodePoint(codePoint) {
426
+ return codePoint >= 768 && codePoint <= 879 || // Combining Diacritical Marks
427
+ codePoint >= 6832 && codePoint <= 6911 || // Combining Diacritical Marks Extended
428
+ codePoint >= 7616 && codePoint <= 7679 || // Combining Diacritical Marks Supplement
429
+ codePoint >= 8400 && codePoint <= 8447 || // Combining Diacritical Marks for Symbols
430
+ codePoint >= 65056 && codePoint <= 65071 || // Combining Half Marks
431
+ codePoint >= 12330 && codePoint <= 12335 || // EAW=W: Ideographic level tone marks
432
+ codePoint >= 12441 && codePoint <= 12442 || // EAW=W: Combining Katakana-Hiragana marks
433
+ codePoint === 94180;
434
+ }
435
+ function isEmojiLike(codePoint) {
436
+ return codePoint >= 127744 && codePoint <= 129791 || codePoint >= 127462 && codePoint <= 127487;
437
+ }
438
+ var extendedPictographicRe = null;
439
+ try {
440
+ extendedPictographicRe = new RegExp("\\p{Extended_Pictographic}", "u");
441
+ } catch {
442
+ extendedPictographicRe = null;
443
+ }
444
+ var emojiPresentationRe = null;
445
+ try {
446
+ emojiPresentationRe = new RegExp("\\p{Emoji_Presentation}", "u");
447
+ } catch {
448
+ emojiPresentationRe = null;
449
+ }
450
+ var emojiRe = null;
451
+ try {
452
+ emojiRe = new RegExp("\\p{Emoji}", "u");
453
+ } catch {
454
+ emojiRe = null;
455
+ }
456
+ function normalizeCustomWidth(width) {
457
+ return width === 2 ? 2 : 1;
458
+ }
459
+ function charCellWidth(text, provider = "default") {
460
+ if (!text)
461
+ return 1;
462
+ if (typeof provider == "function")
463
+ return normalizeCustomWidth(provider(text));
464
+ if (provider !== "cjk" && text.length === 1 && text.charCodeAt(0) < 4352)
465
+ return 1;
466
+ let codePoint = text.codePointAt(0);
467
+ if (codePoint == null)
468
+ return 1;
469
+ let hasVs16 = text.includes("\uFE0F");
470
+ return isVariationSelectorCodePoint(codePoint) || isCombiningMarkCodePoint(codePoint) || codePoint >= 9472 && codePoint <= 9599 ? 1 : isFullWidthCodePoint(codePoint) || provider === "cjk" && isAmbiguousWidthCodePoint(codePoint) || isEmojiLike(codePoint) || emojiPresentationRe?.test(text) || text.includes("\u20E3") || hasVs16 && emojiRe?.test(text) ? 2 : extendedPictographicRe?.test(text) ? codePoint <= 65535 ? hasVs16 ? 2 : 1 : 2 : 1;
471
+ }
472
+
473
+ // src/utils/grapheme.ts
474
+ var graphemeSegmenter = null;
475
+ try {
476
+ let Segmenter = typeof Intl < "u" ? Intl.Segmenter : void 0;
477
+ graphemeSegmenter = Segmenter ? new Segmenter(void 0, { granularity: "grapheme" }) : null;
478
+ } catch {
479
+ graphemeSegmenter = null;
480
+ }
481
+ var unicodeMarkRe = null;
482
+ try {
483
+ unicodeMarkRe = new RegExp("\\p{Mark}", "u");
484
+ } catch {
485
+ unicodeMarkRe = null;
486
+ }
487
+ function needsGraphemeSegmentation(text) {
488
+ for (let ch of text) {
489
+ let cp = ch.codePointAt(0);
490
+ if (cp === 8205 || cp >= 65024 && cp <= 65039 || cp >= 917760 && cp <= 917999 || isCombiningMark(cp) || cp >= 127995 && cp <= 127999 || cp >= 127462 && cp <= 127487 || cp >= 917504 && cp <= 917631)
491
+ return !0;
492
+ }
493
+ return !1;
494
+ }
495
+ function isVariationSelector(codePoint) {
496
+ return codePoint >= 65024 && codePoint <= 65039 || codePoint >= 917760 && codePoint <= 917999;
497
+ }
498
+ function isCombiningMark(codePoint) {
499
+ 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)) === !0;
500
+ }
501
+ function isDevanagariMark(codePoint) {
502
+ return codePoint >= 2304 && codePoint <= 2307 || codePoint >= 2362 && codePoint <= 2364 || codePoint >= 2366 && codePoint <= 2383 || codePoint >= 2385 && codePoint <= 2391 || codePoint >= 2402 && codePoint <= 2403;
503
+ }
504
+ function isVirama(codePoint) {
505
+ return codePoint === 2381;
506
+ }
507
+ function isEmojiModifier(codePoint) {
508
+ return codePoint >= 127995 && codePoint <= 127999;
509
+ }
510
+ function isRegionalIndicator(codePoint) {
511
+ return codePoint >= 127462 && codePoint <= 127487;
512
+ }
513
+ function isEmojiTag(codePoint) {
514
+ return codePoint >= 917504 && codePoint <= 917631;
515
+ }
516
+ function fallbackGraphemeSegments(text) {
517
+ let out = [], segment = "", segmentStart = 0, pos = 0, regionalIndicators = 0, joinNext = !1, pushSegment = () => {
518
+ segment && out.push({ segment, index: segmentStart });
519
+ };
520
+ for (let ch of text) {
521
+ let codePoint = ch.codePointAt(0), chStart = pos;
522
+ pos += ch.length, segment !== "" && (joinNext || codePoint === 8205 || isVariationSelector(codePoint) || isCombiningMark(codePoint) || isEmojiModifier(codePoint) || isEmojiTag(codePoint) || isRegionalIndicator(codePoint) && regionalIndicators === 1) ? (segment += ch, isRegionalIndicator(codePoint) ? regionalIndicators++ : !isVariationSelector(codePoint) && !isCombiningMark(codePoint) && (regionalIndicators = 0)) : (pushSegment(), segment = ch, segmentStart = chStart, regionalIndicators = isRegionalIndicator(codePoint) ? 1 : 0), codePoint === 8205 || isVirama(codePoint) ? joinNext = !0 : joinNext && !isVariationSelector(codePoint) && !isCombiningMark(codePoint) && (joinNext = !1);
523
+ }
524
+ return pushSegment(), out;
525
+ }
526
+ function segmentedGraphemes(text) {
527
+ return needsGraphemeSegmentation(text) ? graphemeSegmenter ? graphemeSegmenter.segment(text) : fallbackGraphemeSegments(text) : null;
528
+ }
529
+
530
+ // src/vue/utils/text.ts
531
+ var renderPassDepth = 0, renderPassTextWidthCache = /* @__PURE__ */ new Map(), textWidthProviderStack = [];
532
+ function currentTextWidthProvider() {
533
+ return textWidthProviderStack[textWidthProviderStack.length - 1] ?? "default";
534
+ }
535
+ function hasAsciiFastPath(provider) {
536
+ return typeof provider != "function";
537
+ }
538
+ function canUseDefaultTextCache(provider) {
539
+ return provider === "default" || provider === "narrow-ambiguous";
540
+ }
541
+ function withTextWidthProvider(provider, fn) {
542
+ textWidthProviderStack.push(provider ?? "default");
543
+ try {
544
+ return fn();
545
+ } finally {
546
+ textWidthProviderStack.pop();
547
+ }
548
+ }
549
+ function isAscii(text) {
550
+ for (let i = 0; i < text.length; i++)
551
+ if (text.charCodeAt(i) > 127)
552
+ return !1;
553
+ return !0;
554
+ }
555
+ var UNSAFE_FORMAT_CONTROL_RE = /[\u061C\u00AD\u180E\u200B\u200C\u200E\u200F\u202A-\u202E\u2060-\u206F\uFEFF]/u;
556
+ function isUnsafeFormatControl(codePoint) {
557
+ return codePoint === 1564 || codePoint === 173 || codePoint === 6158 || codePoint === 8203 || codePoint === 8204 || codePoint === 8206 || codePoint === 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8288 && codePoint <= 8303 || codePoint === 65279;
558
+ }
559
+ function hasInlineAsciiControl(text) {
560
+ for (let i = 0; i < text.length; i++) {
561
+ let code = text.charCodeAt(i);
562
+ if (code === 10 || code === 13 || code === 9)
563
+ return !0;
564
+ }
565
+ return !1;
566
+ }
567
+ function hasTextBlockAsciiControl(text) {
568
+ for (let i = 0; i < text.length; i++) {
569
+ let code = text.charCodeAt(i);
570
+ if (code === 9 || code <= 31 && code !== 10 || code === 127)
571
+ return !0;
572
+ }
573
+ return !1;
574
+ }
575
+ function forEachGrapheme(text, cb) {
576
+ if (!text)
577
+ return;
578
+ let segments = segmentedGraphemes(text);
579
+ if (!segments) {
580
+ for (let ch of text)
581
+ if (cb(ch) === !1)
582
+ return;
583
+ return;
584
+ }
585
+ for (let part of segments)
586
+ if (cb(part.segment) === !1)
587
+ return;
588
+ }
589
+ function sanitizeInlineText(text) {
590
+ if (!text)
591
+ return "";
592
+ if (!UNSAFE_FORMAT_CONTROL_RE.test(text) && !hasInlineAsciiControl(text))
593
+ return text;
594
+ let out = [];
595
+ for (let ch of text) {
596
+ let cp = ch.codePointAt(0);
597
+ if (cp === 10 || cp === 13 || cp === 9) {
598
+ out.push(" ");
599
+ continue;
600
+ }
601
+ isUnsafeFormatControl(cp) || out.push(ch);
602
+ }
603
+ return out.join("");
604
+ }
605
+ function sanitizeTextBlock(text) {
606
+ if (!text)
607
+ return "";
608
+ if (!UNSAFE_FORMAT_CONTROL_RE.test(text) && !hasTextBlockAsciiControl(text))
609
+ return text;
610
+ let out = [];
611
+ out.length = 0;
612
+ for (let ch of text) {
613
+ let cp = ch.codePointAt(0);
614
+ if (cp !== 13) {
615
+ if (cp === 9) {
616
+ out.push(" ");
617
+ continue;
618
+ }
619
+ cp <= 31 && cp !== 10 || cp === 127 || isUnsafeFormatControl(cp) || out.push(ch);
620
+ }
621
+ }
622
+ return out.join("");
623
+ }
624
+ function textCellWidth(text, provider = currentTextWidthProvider()) {
625
+ if (!text)
626
+ return 0;
627
+ if (hasAsciiFastPath(provider) && isAscii(text))
628
+ return text.length;
629
+ let useCache = canUseDefaultTextCache(provider);
630
+ if (useCache && renderPassDepth > 0) {
631
+ let cached = renderPassTextWidthCache.get(text);
632
+ if (cached != null)
633
+ return cached;
634
+ }
635
+ if (useCache) {
636
+ let cached = textWidthCacheGet(text);
637
+ if (cached != null)
638
+ return cached;
639
+ }
640
+ let cells = 0;
641
+ return forEachGrapheme(text, (g) => {
642
+ cells += charCellWidth(g, provider);
643
+ }), useCache && renderPassDepth > 0 && renderPassTextWidthCache.set(text, cells), useCache && textWidthCacheSet(text, cells), cells;
644
+ }
645
+ var spaceCache = /* @__PURE__ */ new Map(), MAX_CACHED_SPACES = 256;
646
+ function spaces(count) {
647
+ if (count = Math.max(0, Math.floor(count)), count === 0)
648
+ return "";
649
+ let cached = spaceCache.get(count);
650
+ if (cached)
651
+ return cached;
652
+ let v = " ".repeat(count);
653
+ return spaceCache.size >= MAX_CACHED_SPACES && spaceCache.clear(), spaceCache.set(count, v), v;
654
+ }
655
+ var repeatCharCache = /* @__PURE__ */ new Map(), MAX_REPEAT_CHAR_KEYS = 8, MAX_CACHED_REPEAT_CHAR = 256;
656
+ function repeatChar(ch, count) {
657
+ if (count = Math.max(0, Math.floor(count)), count === 0 || !ch)
658
+ return "";
659
+ let bucket = repeatCharCache.get(ch);
660
+ bucket || (repeatCharCache.size >= MAX_REPEAT_CHAR_KEYS && repeatCharCache.clear(), bucket = /* @__PURE__ */ new Map(), repeatCharCache.set(ch, bucket));
661
+ let cached = bucket.get(count);
662
+ if (cached)
663
+ return cached;
664
+ let v = ch.repeat(count);
665
+ return bucket.size >= MAX_CACHED_REPEAT_CHAR && bucket.clear(), bucket.set(count, v), v;
666
+ }
667
+ function sliceByCells(text, maxCells, provider = currentTextWidthProvider()) {
668
+ if (maxCells = Math.max(0, Math.floor(maxCells)), maxCells <= 0)
669
+ return "";
670
+ if (text && hasAsciiFastPath(provider) && isAscii(text))
671
+ return text.slice(0, maxCells);
672
+ let out = [], cells = 0;
673
+ return forEachGrapheme(text, (g) => {
674
+ let w = charCellWidth(g, provider);
675
+ if (cells + w > maxCells)
676
+ return !1;
677
+ out.push(g), cells += w;
678
+ }), out.length ? out.join("") : "";
679
+ }
680
+ function sliceByCellsRange(text, startCells, endCells, provider = currentTextWidthProvider()) {
681
+ if (startCells = Math.max(0, Math.floor(startCells)), endCells = Math.max(0, Math.floor(endCells)), endCells <= startCells || !text)
682
+ return "";
683
+ if (hasAsciiFastPath(provider) && isAscii(text))
684
+ return text.slice(startCells, endCells);
685
+ let out = [], cells = 0;
686
+ return forEachGrapheme(text, (g) => {
687
+ let w = charCellWidth(g, provider), next = cells + w;
688
+ if (cells >= endCells)
689
+ return !1;
690
+ if (next <= startCells) {
691
+ cells = next;
692
+ return;
693
+ }
694
+ if (cells < startCells && next > startCells) {
695
+ out.push(spaces(Math.min(next, endCells) - startCells)), cells = next;
696
+ return;
697
+ }
698
+ if (next > endCells)
699
+ return out.push(spaces(endCells - cells)), !1;
700
+ out.push(g), cells = next;
701
+ }), out.length ? out.join("") : "";
702
+ }
703
+ function padEndByCells(text, width, provider = currentTextWidthProvider()) {
704
+ width = Math.max(0, Math.floor(width));
705
+ let cells = text && hasAsciiFastPath(provider) && isAscii(text) ? text.length : textCellWidth(text, provider);
706
+ return cells >= width ? text : `${text}${spaces(width - cells)}`;
707
+ }
708
+ var textWidthCache = /* @__PURE__ */ new Map(), MAX_TEXT_WIDTH_CACHE = 1024;
709
+ function textWidthCacheGet(text) {
710
+ let cached = textWidthCache.get(text);
711
+ return cached == null ? null : (textWidthCache.delete(text), textWidthCache.set(text, cached), cached);
712
+ }
713
+ function textWidthCacheSet(text, cells) {
714
+ if (textWidthCache.set(text, cells), textWidthCache.size > MAX_TEXT_WIDTH_CACHE) {
715
+ let firstKey = textWidthCache.keys().next().value;
716
+ firstKey != null && textWidthCache.delete(firstKey);
717
+ }
718
+ }
719
+
720
+ // src/vue/composables/use-render-node.ts
721
+ var pendingInvalidateByScheduler = /* @__PURE__ */ new WeakMap();
722
+ function mergePriority(prev, next) {
723
+ return prev === "high" || next === "high" ? "high" : prev === "normal" || next === "normal" ? "normal" : "low";
724
+ }
725
+ function requestBatchedInvalidate(scheduler, plane, priority) {
726
+ let state = pendingInvalidateByScheduler.get(scheduler);
727
+ if (state || (state = { queued: !1, plane: null, priority: "low" }, pendingInvalidateByScheduler.set(scheduler, state)), state.queued) {
728
+ state.plane !== null && state.plane !== plane && (state.plane = null), state.priority = mergePriority(state.priority, priority);
729
+ return;
730
+ }
731
+ state.plane = plane, state.priority = priority, state.queued = !0, queueMicrotask(() => {
732
+ state.queued = !1;
733
+ let queuedPlane = state.plane, queuedPriority = state.priority;
734
+ state.plane = null, state.priority = "low", scheduler.invalidate({
735
+ plane: queuedPlane ?? void 0,
736
+ priority: queuedPriority
737
+ });
738
+ });
739
+ }
740
+ function sameRenderRect(a, b) {
741
+ return a === b ? !0 : !a || !b ? !1 : a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
742
+ }
743
+ function sameDeps(a, b) {
744
+ if (Object.is(a, b))
745
+ return !0;
746
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length)
747
+ return !1;
748
+ for (let i = 0; i < a.length; i++)
749
+ if (!Object.is(a[i], b[i]))
750
+ return !1;
751
+ return !0;
752
+ }
753
+ function useRenderNode(getOptions) {
754
+ let { scheduler, render, widthProvider } = useTerminal(), parentStack = useRenderStack(), plane = (0, import_vue5.inject)(RenderPlaneContextKey, (0, import_vue5.ref)("default")), id = (0, import_vue5.ref)(null), lastPlane = (0, import_vue5.ref)(plane.value), lastStack = null, lastZIndex = 0, lastHasRect = !1, lastRect = null, lastDeps, lastHasDeps = !1, options = (0, import_vue5.computed)(() => withTextWidthProvider(widthProvider, getOptions)), stop = (0, import_vue5.watchEffect)(
755
+ () => {
756
+ let opt = options.value;
757
+ opt.deps;
758
+ let stack = opt.stack ?? parentStack.value, nextPlane = plane.value, hasRect = Object.prototype.hasOwnProperty.call(opt, "rect"), nextRect = hasRect ? opt.rect ?? null : null, nextZIndex = opt.zIndex ?? 0, hasDeps = Object.prototype.hasOwnProperty.call(opt, "deps");
759
+ if (!stack)
760
+ return;
761
+ if (!id.value) {
762
+ let node = render.register({
763
+ stack,
764
+ zIndex: nextZIndex,
765
+ rect: hasRect ? nextRect : void 0,
766
+ plane: nextPlane,
767
+ paint: opt.paint
768
+ });
769
+ id.value = node.id, lastPlane.value = nextPlane, lastStack = stack, lastZIndex = nextZIndex, lastHasRect = hasRect, lastRect = nextRect, lastHasDeps = hasDeps, lastDeps = opt.deps, requestBatchedInvalidate(scheduler, nextPlane, opt.priority ?? "normal");
770
+ return;
771
+ }
772
+ let prevPlane = lastPlane.value;
773
+ if (hasDeps && lastHasDeps && !opt.dirtyRowsHint?.length && lastStack === stack && lastZIndex === nextZIndex && prevPlane === nextPlane && lastHasRect === hasRect && (!hasRect || sameRenderRect(lastRect, nextRect)) && sameDeps(lastDeps, opt.deps))
774
+ return;
775
+ let updatePayload = {
776
+ stack,
777
+ zIndex: nextZIndex,
778
+ dirtyRowsHint: opt.dirtyRowsHint,
779
+ plane: nextPlane,
780
+ paint: opt.paint
781
+ };
782
+ hasRect && (updatePayload.rect = nextRect), render.update(id.value, updatePayload), lastPlane.value = nextPlane, lastStack = stack, lastZIndex = nextZIndex, lastHasRect = hasRect, lastRect = nextRect, lastHasDeps = hasDeps, lastDeps = opt.deps;
783
+ let priority = opt.priority ?? "normal";
784
+ requestBatchedInvalidate(scheduler, prevPlane, priority), prevPlane !== nextPlane && requestBatchedInvalidate(scheduler, nextPlane, priority);
785
+ },
786
+ { flush: "sync" }
787
+ );
788
+ return (0, import_vue5.onBeforeUnmount)(() => {
789
+ stop(), id.value && (render.unregister(id.value), requestBatchedInvalidate(scheduler, lastPlane.value, "normal"));
790
+ }), { id };
791
+ }
792
+
793
+ // src/vue/composables/use-terminal-node.ts
794
+ var import_vue6 = require("vue");
795
+ function wrapHandlers(handlers, widthProvider) {
796
+ if (!handlers)
797
+ return {};
798
+ let out = {};
799
+ for (let key of Object.keys(handlers)) {
800
+ let handler = handlers[key];
801
+ handler && (out[key] = (event) => withTextWidthProvider(widthProvider, () => handler(event)));
802
+ }
803
+ return out;
804
+ }
805
+ function useTerminalNode(getOptions) {
806
+ let { events, widthProvider } = useTerminal(), id = (0, import_vue6.ref)(null), options = (0, import_vue6.computed)(() => withTextWidthProvider(widthProvider, getOptions)), stop = (0, import_vue6.watchEffect)(() => {
807
+ let manager = events.value;
808
+ if (!manager)
809
+ return;
810
+ let opt = options.value;
811
+ if (!id.value) {
812
+ let node = manager.register({
813
+ rect: opt.rect,
814
+ zIndex: opt.zIndex ?? 0,
815
+ visible: opt.visible,
816
+ focusable: opt.focusable,
817
+ selectable: opt.selectable,
818
+ selectionScrollBy: opt.selectionScrollBy,
819
+ handlers: wrapHandlers(opt.handlers, widthProvider)
820
+ });
821
+ id.value = node.id;
822
+ return;
823
+ }
824
+ manager.update(id.value, {
825
+ rect: opt.rect,
826
+ zIndex: opt.zIndex ?? 0,
827
+ visible: opt.visible,
828
+ focusable: opt.focusable,
829
+ selectable: opt.selectable,
830
+ selectionScrollBy: opt.selectionScrollBy,
831
+ handlers: wrapHandlers(opt.handlers, widthProvider)
832
+ });
833
+ });
834
+ return (0, import_vue6.onBeforeUnmount)(() => {
835
+ stop();
836
+ let manager = events.value;
837
+ manager && id.value && manager.unregister(id.value);
838
+ }), { id };
839
+ }
840
+
841
+ // src/vue/composables/use-visibility.ts
842
+ var import_vue7 = require("vue");
843
+ var VUE_TERMINAL_SHOW_CB = "__vueTerminalOnShow", vShowPatched = !1;
844
+ function patchVShow() {
845
+ if (vShowPatched)
846
+ return;
847
+ vShowPatched = !0;
848
+ let dir = import_vue7.vShow, origBeforeMount = dir.beforeMount, origUpdated = dir.updated, origBeforeUnmount = dir.beforeUnmount, notify = (el, value) => {
849
+ if (!el || typeof el != "object")
850
+ return;
851
+ let cb = el[VUE_TERMINAL_SHOW_CB];
852
+ cb?.(!!value);
853
+ };
854
+ typeof origBeforeMount == "function" && (dir.beforeMount = (el, binding, vnode) => {
855
+ origBeforeMount(el, binding, vnode), notify(el, binding?.value);
856
+ }), typeof origUpdated == "function" && (dir.updated = (el, binding, vnode) => {
857
+ origUpdated(el, binding, vnode), notify(el, binding?.value);
858
+ }), typeof origBeforeUnmount == "function" && (dir.beforeUnmount = (el, binding, vnode) => {
859
+ origBeforeUnmount(el, binding, vnode), notify(el, binding?.value);
860
+ });
861
+ }
862
+ var PLACEHOLDER_STYLE = Object.freeze({
863
+ position: "absolute",
864
+ left: "-9999px",
865
+ top: "0",
866
+ width: "0",
867
+ height: "0",
868
+ overflow: "hidden"
869
+ });
870
+ function useVisibility(options) {
871
+ patchVShow();
872
+ let { scheduler } = useTerminal(), parentVisible = (0, import_vue7.inject)(VisibilityContextKey, (0, import_vue7.ref)(!0)), localVisible = (0, import_vue7.ref)(!0), visible = (0, import_vue7.computed)(() => parentVisible.value && localVisible.value);
873
+ options?.provide && (0, import_vue7.provide)(VisibilityContextKey, visible);
874
+ let onShow = (value) => {
875
+ localVisible.value = value, scheduler.invalidate();
876
+ };
877
+ return { visible, rootProps: {
878
+ style: PLACEHOLDER_STYLE,
879
+ onVnodeBeforeMount: (vnode) => {
880
+ let el = vnode.el;
881
+ el && typeof el == "object" && (el[VUE_TERMINAL_SHOW_CB] = onShow);
882
+ },
883
+ onVnodeBeforeUnmount: (vnode) => {
884
+ let el = vnode.el;
885
+ el && typeof el == "object" && el[VUE_TERMINAL_SHOW_CB] === onShow && delete el[VUE_TERMINAL_SHOW_CB];
886
+ }
887
+ } };
888
+ }
889
+
890
+ // src/vue/utils/rect.ts
891
+ function intersectRect(a, b) {
892
+ let x0 = Math.max(a.x, b.x), y0 = Math.max(a.y, b.y), x1 = Math.min(a.x + a.w, b.x + b.w), y1 = Math.min(a.y + a.h, b.y + b.h);
893
+ return x1 <= x0 || y1 <= y0 ? null : { x: x0, y: y0, w: x1 - x0, h: y1 - y0 };
894
+ }
895
+ function translateRect(rect, dx, dy) {
896
+ return { x: rect.x + dx, y: rect.y + dy, w: rect.w, h: rect.h };
897
+ }
898
+
899
+ // src/vue/components/TMermaidText.ts
900
+ var TUI_MERMAID_FATAL_RENDER_ERROR = "__vueTuiMermaidFatalRenderError", fatalMermaidRenderErrors = /* @__PURE__ */ new WeakSet(), DEFAULT_MERMAID_RENDER_TIMEOUT_MS = 2500, DEFAULT_MERMAID_MAX_RENDER_SOURCE_CHARS = 2e4, DEFAULT_MERMAID_MAX_RENDER_SOURCE_LINES = 400, DEFAULT_MERMAID_COPIED_DURATION_MS = 1200, UNICODE_MERMAID_BOX_CHARS = Object.freeze({
901
+ tl: "\u250C",
902
+ tr: "\u2510",
903
+ bl: "\u2514",
904
+ br: "\u2518",
905
+ h: "\u2500",
906
+ v: "\u2502"
907
+ }), ASCII_MERMAID_BOX_CHARS = Object.freeze({
908
+ tl: "+",
909
+ tr: "+",
910
+ bl: "+",
911
+ br: "+",
912
+ h: "-",
913
+ v: "|"
914
+ }), DEFAULT_MERMAID_MAX_RENDER_FLOW_STATEMENTS = 120, SIMPLE_MERMAID_DIRECTIVE_RE = /^(?:graph|flowchart)\s+(?:TB|TD|BT|LR|RL)\s*$/i, MERMAID_INIT_DIRECTIVE_RE = /^%%\{/, MERMAID_COMMENT_RE = /^%%/, MERMAID_FRONTMATTER_DELIMITER_RE = /^---\s*$/, SIMPLE_MERMAID_FLOW_STATEMENT_START_RE = /^(?:"[^"]+"|'[^']+'|`[^`]+`|[A-Za-z0-9_][A-Za-z0-9_-]*)/, COMPLEX_MERMAID_FLOW_FEATURE_RE = /^(?:subgraph|end|classDef|class|click|style|linkStyle|accTitle|accDescr|direction)\b/i, ESC = "\x1B", BEL = "\x07", TERMINAL_ESCAPE_RE = new RegExp(
915
+ [
916
+ `${ESC}\\][\\s\\S]*?(?:${BEL}|${ESC}\\\\)`,
917
+ `${ESC}[PX^_][\\s\\S]*?${ESC}\\\\`,
918
+ `${ESC}\\[[0-?]*[ -/]*[@-~]`,
919
+ `${ESC}[@-Z\\\\-_]`
920
+ ].join("|"),
921
+ "g"
922
+ );
923
+ function stripTerminalEscapes(value) {
924
+ return value.replace(TERMINAL_ESCAPE_RE, "");
925
+ }
926
+ function normalizeNonNegativeInt(value, fallback) {
927
+ let n = Number(value);
928
+ return Number.isFinite(n) ? Math.max(0, Math.floor(n)) : fallback;
929
+ }
930
+ function countLinesUpTo(value, max) {
931
+ if (max <= 0)
932
+ return 0;
933
+ let lines = 1;
934
+ for (let index = 0; index < value.length; index++) {
935
+ let code = value.charCodeAt(index);
936
+ if (!(code !== 10 && code !== 13) && (lines++, code === 13 && value.charCodeAt(index + 1) === 10 && index++, lines > max))
937
+ return lines;
938
+ }
939
+ return lines;
940
+ }
941
+ function createMermaidScannerState() {
942
+ return {
943
+ quote: "",
944
+ escaped: !1,
945
+ squareDepth: 0,
946
+ parenDepth: 0,
947
+ braceDepth: 0,
948
+ pipeLabel: !1
949
+ };
950
+ }
951
+ function scannerAtTopLevel(state) {
952
+ return !state.quote && !state.pipeLabel && state.squareDepth === 0 && state.parenDepth === 0 && state.braceDepth === 0;
953
+ }
954
+ function advanceMermaidScannerState(state, ch) {
955
+ if (state.pipeLabel) {
956
+ if (state.escaped) {
957
+ state.escaped = !1;
958
+ return;
959
+ }
960
+ if (ch === "\\") {
961
+ state.escaped = !0;
962
+ return;
963
+ }
964
+ ch === "|" && (state.pipeLabel = !1);
965
+ return;
966
+ }
967
+ if (state.quote) {
968
+ if (state.escaped) {
969
+ state.escaped = !1;
970
+ return;
971
+ }
972
+ if (ch === "\\") {
973
+ state.escaped = !0;
974
+ return;
975
+ }
976
+ ch === state.quote && (state.quote = "");
977
+ return;
978
+ }
979
+ if (ch === '"' || ch === "'" || ch === "`") {
980
+ state.quote = ch, state.escaped = !1;
981
+ return;
982
+ }
983
+ if (ch === "|" && scannerAtTopLevel(state)) {
984
+ state.pipeLabel = !0, state.escaped = !1;
985
+ return;
986
+ }
987
+ if (ch === "[") {
988
+ state.squareDepth++;
989
+ return;
990
+ }
991
+ if (ch === "]") {
992
+ state.squareDepth = Math.max(0, state.squareDepth - 1);
993
+ return;
994
+ }
995
+ if (ch === "(") {
996
+ state.parenDepth++;
997
+ return;
998
+ }
999
+ if (ch === ")") {
1000
+ state.parenDepth = Math.max(0, state.parenDepth - 1);
1001
+ return;
1002
+ }
1003
+ if (ch === "{") {
1004
+ state.braceDepth++;
1005
+ return;
1006
+ }
1007
+ ch === "}" && (state.braceDepth = Math.max(0, state.braceDepth - 1));
1008
+ }
1009
+ function splitMermaidLineStatements(line) {
1010
+ let out = [], state = createMermaidScannerState(), start = 0;
1011
+ for (let index = 0; index < line.length; index++) {
1012
+ let ch = line[index] ?? "";
1013
+ if (ch === ";" && scannerAtTopLevel(state)) {
1014
+ let statement = line.slice(start, index).trim();
1015
+ statement && out.push(statement), start = index + 1;
1016
+ continue;
1017
+ }
1018
+ advanceMermaidScannerState(state, ch);
1019
+ }
1020
+ let tail = line.slice(start).trim();
1021
+ return tail && out.push(tail), out;
1022
+ }
1023
+ function stripTopLevelMermaidComment(statement) {
1024
+ let state = createMermaidScannerState();
1025
+ for (let index = 0; index < statement.length; index++) {
1026
+ let ch = statement[index] ?? "";
1027
+ if (ch === "%" && statement[index + 1] === "%" && scannerAtTopLevel(state))
1028
+ return statement.slice(0, index).trim();
1029
+ advanceMermaidScannerState(state, ch);
1030
+ }
1031
+ return statement.trim();
1032
+ }
1033
+ function mermaidSourceLines(code) {
1034
+ return String(code ?? "").replace(/\r\n?/g, `
1035
+ `).split(`
1036
+ `);
1037
+ }
1038
+ function mermaidSourceStatements(code) {
1039
+ let statements = [];
1040
+ for (let rawLine of mermaidSourceLines(code)) {
1041
+ let line = rawLine.trim();
1042
+ if (line) {
1043
+ if (MERMAID_INIT_DIRECTIVE_RE.test(line) || MERMAID_FRONTMATTER_DELIMITER_RE.test(line)) {
1044
+ statements.push(line);
1045
+ continue;
1046
+ }
1047
+ if (!MERMAID_COMMENT_RE.test(line))
1048
+ for (let rawStatement of splitMermaidLineStatements(line)) {
1049
+ let statement = stripTopLevelMermaidComment(rawStatement);
1050
+ !statement || MERMAID_COMMENT_RE.test(statement) || statements.push(statement);
1051
+ }
1052
+ }
1053
+ }
1054
+ return statements;
1055
+ }
1056
+ function isForbiddenMermaidFlowStatement(statement) {
1057
+ return MERMAID_INIT_DIRECTIVE_RE.test(statement) || MERMAID_FRONTMATTER_DELIMITER_RE.test(statement) || COMPLEX_MERMAID_FLOW_FEATURE_RE.test(statement);
1058
+ }
1059
+ function hasTopLevelMermaidComplexToken(statement) {
1060
+ let state = createMermaidScannerState();
1061
+ for (let index = 0; index < statement.length; index++) {
1062
+ let ch = statement[index] ?? "";
1063
+ if (scannerAtTopLevel(state) && (ch === "@" || statement.startsWith(":::", index) && /[A-Za-z_]/.test(statement[index + 3] ?? "")))
1064
+ return !0;
1065
+ advanceMermaidScannerState(state, ch);
1066
+ }
1067
+ return !1;
1068
+ }
1069
+ function isSimpleMermaidFlowStatement(statement) {
1070
+ return SIMPLE_MERMAID_DIRECTIVE_RE.test(statement) || isForbiddenMermaidFlowStatement(statement) || hasTopLevelMermaidComplexToken(statement) ? !1 : SIMPLE_MERMAID_FLOW_STATEMENT_START_RE.test(statement);
1071
+ }
1072
+ function isSimpleMermaidFlowchartSource(code) {
1073
+ let statements = mermaidSourceStatements(code), sawDirective = !1, renderableStatements = 0;
1074
+ for (let statement of statements) {
1075
+ if (!sawDirective) {
1076
+ if (!SIMPLE_MERMAID_DIRECTIVE_RE.test(statement))
1077
+ return !1;
1078
+ sawDirective = !0;
1079
+ continue;
1080
+ }
1081
+ if (!isSimpleMermaidFlowStatement(statement) || (renderableStatements++, renderableStatements > DEFAULT_MERMAID_MAX_RENDER_FLOW_STATEMENTS))
1082
+ return !1;
1083
+ }
1084
+ return sawDirective && renderableStatements > 0;
1085
+ }
1086
+ function clipboardCanWrite(api) {
1087
+ return api.canWrite ?? api.supported;
1088
+ }
1089
+ var MERMAID_RENDER_TIMEOUT = Symbol("MERMAID_RENDER_TIMEOUT");
1090
+ function markMermaidRenderErrorFatal(error) {
1091
+ let normalized = error instanceof Error ? error : new Error(String(error));
1092
+ fatalMermaidRenderErrors.add(normalized);
1093
+ try {
1094
+ Object.defineProperty(normalized, TUI_MERMAID_FATAL_RENDER_ERROR, {
1095
+ value: !0,
1096
+ configurable: !0
1097
+ });
1098
+ } catch {
1099
+ try {
1100
+ normalized[TUI_MERMAID_FATAL_RENDER_ERROR] = !0;
1101
+ } catch {
1102
+ }
1103
+ }
1104
+ return normalized;
1105
+ }
1106
+ function splitRenderedOutput(value) {
1107
+ let lines = sanitizeTextBlock(
1108
+ stripTerminalEscapes(String(value ?? "")).replace(/\r\n?/g, `
1109
+ `)
1110
+ ).split(`
1111
+ `);
1112
+ return lines.length ? lines : [""];
1113
+ }
1114
+ function hasVisibleRenderedOutput(value) {
1115
+ return value.some((line) => line.trim().length > 0);
1116
+ }
1117
+ var tMermaidTextProps = {
1118
+ x: { type: Number, required: !0 },
1119
+ y: { type: Number, required: !0 },
1120
+ w: { type: Number, required: !0 },
1121
+ h: { type: Number, default: void 0 },
1122
+ zIndex: { type: Number, default: 0 },
1123
+ content: { type: String, default: "" },
1124
+ code: { type: String, default: void 0 },
1125
+ style: { type: Object, default: void 0 },
1126
+ loadingStyle: { type: Object, default: void 0 },
1127
+ errorStyle: { type: Object, default: void 0 },
1128
+ clear: { type: Boolean, default: !0 },
1129
+ final: { type: Boolean, default: !0 },
1130
+ streaming: { type: Boolean, default: !1 },
1131
+ ascii: { type: Boolean, default: !1 },
1132
+ paddingX: { type: Number, default: void 0 },
1133
+ paddingY: { type: Number, default: void 0 },
1134
+ boxBorderPadding: { type: Number, default: void 0 },
1135
+ options: {
1136
+ type: Object,
1137
+ default: void 0
1138
+ },
1139
+ renderer: {
1140
+ type: Function,
1141
+ default: void 0
1142
+ },
1143
+ // Deprecated source-first compatibility props.
1144
+ // Source-first Mermaid never paints loading/incomplete/error placeholders;
1145
+ // renderer failure keeps source visible. These props remain for source compatibility.
1146
+ isTransientError: {
1147
+ type: Function,
1148
+ default: void 0
1149
+ },
1150
+ shouldRenderSource: {
1151
+ type: Function,
1152
+ default: void 0
1153
+ },
1154
+ // Deprecated source-first compatibility text props.
1155
+ // Kept so existing callers do not break, but not used by the source-first renderer.
1156
+ loadingText: {
1157
+ type: String,
1158
+ default: "Rendering Mermaid diagram..."
1159
+ },
1160
+ incompleteText: {
1161
+ type: String,
1162
+ default: "Waiting for complete Mermaid diagram..."
1163
+ },
1164
+ missingDependencyText: {
1165
+ type: String,
1166
+ default: "Install the Mermaid renderer package and use TMermaidText from @simon_he/vue-tui/mermaid or @simon_he/vue-tui/agent/mermaid, or pass a renderer prop."
1167
+ },
1168
+ errorText: {
1169
+ type: String,
1170
+ default: "Mermaid render failed"
1171
+ },
1172
+ showErrorDetails: {
1173
+ type: Boolean,
1174
+ default: !0
1175
+ },
1176
+ box: { type: Boolean, default: !0 },
1177
+ title: { type: String, default: "mermaid" },
1178
+ copyButton: { type: Boolean, default: !0 },
1179
+ copyText: { type: String, default: "copy" },
1180
+ copiedText: { type: String, default: "copied" },
1181
+ renderTimeoutMs: { type: Number, default: DEFAULT_MERMAID_RENDER_TIMEOUT_MS },
1182
+ maxRenderSourceChars: { type: Number, default: DEFAULT_MERMAID_MAX_RENDER_SOURCE_CHARS },
1183
+ maxRenderSourceLines: { type: Number, default: DEFAULT_MERMAID_MAX_RENDER_SOURCE_LINES },
1184
+ copiedDurationMs: { type: Number, default: DEFAULT_MERMAID_COPIED_DURATION_MS }
1185
+ }, TMermaidText = (0, import_vue8.defineComponent)({
1186
+ name: "TMermaidText",
1187
+ props: tMermaidTextProps,
1188
+ emits: {
1189
+ copy: (_payload) => !0
1190
+ },
1191
+ setup(props, { emit }) {
1192
+ let instance = (0, import_vue8.getCurrentInstance)(), terminalContext = useTerminal(), { terminal, defaultStyle, scheduler, widthProvider } = terminalContext, layout = useLayout(), { visible, rootProps } = useVisibility(), parentEventZ = (0, import_vue8.inject)(EventZIndexContextKey, (0, import_vue8.computed)(() => 0)), renderedSnapshot = (0, import_vue8.shallowRef)(null), documentVersion = (0, import_vue8.shallowRef)(0), copied = (0, import_vue8.shallowRef)(!1), builtOnce = !1, renderVersion = 0, alive = !0, frameTaskId = `TMermaidText:${instance?.uid ?? "unknown"}:mermaid`, copiedTimer = null, copyRequestVersion = 0, source = (0, import_vue8.computed)(() => props.code ?? props.content ?? ""), waitingForStreamingSourceToFinish = (0, import_vue8.computed)(() => props.streaming && !props.final);
1193
+ function bump() {
1194
+ documentVersion.value++;
1195
+ }
1196
+ function resolveAsciiOptions() {
1197
+ let base = props.options ?? {};
1198
+ return {
1199
+ ...base,
1200
+ useAscii: props.ascii,
1201
+ paddingX: props.paddingX ?? base.paddingX,
1202
+ paddingY: props.paddingY ?? base.paddingY,
1203
+ boxBorderPadding: props.boxBorderPadding ?? base.boxBorderPadding,
1204
+ colorMode: "none"
1205
+ };
1206
+ }
1207
+ function clearCopiedTimer() {
1208
+ copiedTimer != null && (clearTimeout(copiedTimer), copiedTimer = null);
1209
+ }
1210
+ function setCopied(next, repaint = !0) {
1211
+ next || clearCopiedTimer(), copied.value !== next && (copied.value = next, repaint && bump());
1212
+ }
1213
+ function resetCopyFeedback(repaint = !0) {
1214
+ copyRequestVersion++, setCopied(!1, repaint);
1215
+ }
1216
+ function clearRenderedSnapshot() {
1217
+ return renderedSnapshot.value == null ? !1 : (renderedSnapshot.value = null, !0);
1218
+ }
1219
+ function showCopiedFeedback() {
1220
+ clearCopiedTimer();
1221
+ let duration = normalizeNonNegativeInt(
1222
+ props.copiedDurationMs,
1223
+ DEFAULT_MERMAID_COPIED_DURATION_MS
1224
+ );
1225
+ if (duration <= 0) {
1226
+ setCopied(!1);
1227
+ return;
1228
+ }
1229
+ setCopied(!0), copiedTimer = setTimeout(() => {
1230
+ copiedTimer = null, alive && setCopied(!1);
1231
+ }, duration);
1232
+ }
1233
+ function shouldSkipRenderForSize(code) {
1234
+ let maxChars = normalizeNonNegativeInt(
1235
+ props.maxRenderSourceChars,
1236
+ DEFAULT_MERMAID_MAX_RENDER_SOURCE_CHARS
1237
+ );
1238
+ if (maxChars > 0 && code.length > maxChars)
1239
+ return !0;
1240
+ let maxLines = normalizeNonNegativeInt(
1241
+ props.maxRenderSourceLines,
1242
+ DEFAULT_MERMAID_MAX_RENDER_SOURCE_LINES
1243
+ );
1244
+ return maxLines > 0 && countLinesUpTo(code, maxLines) > maxLines;
1245
+ }
1246
+ function shouldSkipRender(code) {
1247
+ if (shouldSkipRenderForSize(code))
1248
+ return !0;
1249
+ let shouldRenderSource = props.shouldRenderSource;
1250
+ if (!shouldRenderSource)
1251
+ return !1;
1252
+ try {
1253
+ return !shouldRenderSource(code, {
1254
+ final: props.final,
1255
+ streaming: props.streaming
1256
+ });
1257
+ } catch {
1258
+ return !0;
1259
+ }
1260
+ }
1261
+ async function renderWithTimeout(renderer, code, options) {
1262
+ let timeoutMs = normalizeNonNegativeInt(
1263
+ props.renderTimeoutMs,
1264
+ DEFAULT_MERMAID_RENDER_TIMEOUT_MS
1265
+ );
1266
+ if (timeoutMs <= 0)
1267
+ return await renderer(code, options);
1268
+ let timer = null;
1269
+ try {
1270
+ return await Promise.race([
1271
+ Promise.resolve().then(() => renderer(code, options)),
1272
+ new Promise((_resolve, reject) => {
1273
+ timer = setTimeout(() => reject(MERMAID_RENDER_TIMEOUT), timeoutMs);
1274
+ })
1275
+ ]);
1276
+ } finally {
1277
+ timer != null && clearTimeout(timer);
1278
+ }
1279
+ }
1280
+ function clearRenderState() {
1281
+ renderedSnapshot.value = null;
1282
+ }
1283
+ function acceptRenderedSnapshot(code, rendered) {
1284
+ let renderedLines = splitRenderedOutput(rendered);
1285
+ if (!hasVisibleRenderedOutput(renderedLines)) {
1286
+ renderedSnapshot.value = null;
1287
+ return;
1288
+ }
1289
+ renderedSnapshot.value = (0, import_vue8.markRaw)({
1290
+ source: code,
1291
+ lines: (0, import_vue8.markRaw)(renderedLines)
1292
+ });
1293
+ }
1294
+ async function renderNow(version) {
1295
+ let code = source.value;
1296
+ if (!code.trim()) {
1297
+ if (!alive || version !== renderVersion)
1298
+ return;
1299
+ clearRenderState(), bump();
1300
+ return;
1301
+ }
1302
+ if (waitingForStreamingSourceToFinish.value) {
1303
+ if (!alive || version !== renderVersion)
1304
+ return;
1305
+ clearRenderState(), bump();
1306
+ return;
1307
+ }
1308
+ if (shouldSkipRender(code)) {
1309
+ if (!alive || version !== renderVersion)
1310
+ return;
1311
+ clearRenderState(), bump();
1312
+ return;
1313
+ }
1314
+ renderedSnapshot.value = null, bump();
1315
+ try {
1316
+ let renderer = props.renderer;
1317
+ if (!renderer) {
1318
+ if (!alive || version !== renderVersion)
1319
+ return;
1320
+ clearRenderState(), bump();
1321
+ return;
1322
+ }
1323
+ let rendered = await renderWithTimeout(renderer, code, resolveAsciiOptions());
1324
+ if (!alive || version !== renderVersion)
1325
+ return;
1326
+ acceptRenderedSnapshot(code, rendered), bump();
1327
+ } catch {
1328
+ if (!alive || version !== renderVersion)
1329
+ return;
1330
+ clearRenderState(), bump();
1331
+ }
1332
+ }
1333
+ function scheduleRender() {
1334
+ let version = ++renderVersion, copiedWasVisible = copied.value;
1335
+ resetCopyFeedback(!1);
1336
+ let snapshotCleared = clearRenderedSnapshot();
1337
+ if (waitingForStreamingSourceToFinish.value) {
1338
+ builtOnce = !0, scheduler.cancelFrameTask?.(frameTaskId), (copiedWasVisible || snapshotCleared) && bump();
1339
+ return;
1340
+ }
1341
+ if (!builtOnce || !props.streaming) {
1342
+ builtOnce = !0, renderNow(version);
1343
+ return;
1344
+ }
1345
+ (copiedWasVisible || snapshotCleared) && bump(), scheduler.queueFrameTask({
1346
+ id: frameTaskId,
1347
+ reason: "stream",
1348
+ priority: "low",
1349
+ sync: !1,
1350
+ run: () => {
1351
+ alive && version === renderVersion && renderNow(version);
1352
+ }
1353
+ }) === !1 && renderNow(version);
1354
+ }
1355
+ (0, import_vue8.watch)(
1356
+ [
1357
+ source,
1358
+ () => props.renderer,
1359
+ () => props.ascii,
1360
+ () => props.paddingX,
1361
+ () => props.paddingY,
1362
+ () => props.boxBorderPadding,
1363
+ () => props.options,
1364
+ () => props.streaming,
1365
+ () => props.final,
1366
+ () => props.renderTimeoutMs,
1367
+ () => props.maxRenderSourceChars,
1368
+ () => props.maxRenderSourceLines,
1369
+ () => props.shouldRenderSource
1370
+ ],
1371
+ () => {
1372
+ scheduleRender();
1373
+ },
1374
+ { immediate: !0, deep: !0 }
1375
+ ), (0, import_vue8.onBeforeUnmount)(() => {
1376
+ alive = !1, renderVersion++, clearCopiedTimer(), scheduler.cancelFrameTask?.(frameTaskId);
1377
+ });
1378
+ let hasBox = (0, import_vue8.computed)(() => props.box !== !1), normalizedWidth = (0, import_vue8.computed)(() => {
1379
+ let width = Math.floor(Number(props.w));
1380
+ return Number.isFinite(width) ? Math.max(0, width) : 0;
1381
+ }), reservesBoxRows = (0, import_vue8.computed)(() => hasBox.value && normalizedWidth.value >= 2), boxChars = (0, import_vue8.computed)(
1382
+ () => props.ascii ? ASCII_MERMAID_BOX_CHARS : UNICODE_MERMAID_BOX_CHARS
1383
+ ), sourceLines = (0, import_vue8.computed)(() => splitRenderedOutput(source.value)), displayLines = (0, import_vue8.computed)(() => {
1384
+ let snapshot = renderedSnapshot.value;
1385
+ return snapshot && snapshot.source === source.value && hasVisibleRenderedOutput(snapshot.lines) ? snapshot.lines : sourceLines.value;
1386
+ }), currentStyle = (0, import_vue8.computed)(() => props.style ?? defaultStyle.value), fullHeight = (0, import_vue8.computed)(() => {
1387
+ if (props.h != null) {
1388
+ let h3 = Math.floor(Number(props.h));
1389
+ return Number.isFinite(h3) ? Math.max(0, h3) : 0;
1390
+ }
1391
+ let autoContentHeight = Math.max(1, displayLines.value.length);
1392
+ return reservesBoxRows.value ? autoContentHeight + 2 : autoContentHeight;
1393
+ }), fullRect = (0, import_vue8.computed)(() => translateRect(
1394
+ { x: props.x, y: props.y, w: props.w, h: fullHeight.value },
1395
+ layout.originX,
1396
+ layout.originY
1397
+ )), absRect = (0, import_vue8.computed)(() => {
1398
+ let translated = fullRect.value;
1399
+ return layout.clipRect ? intersectRect(translated, layout.clipRect) ?? { x: 0, y: 0, w: 0, h: 0 } : translated;
1400
+ }), copyLabel = (0, import_vue8.computed)(() => copied.value ? props.copiedText : props.copyText);
1401
+ function cellWidth(value) {
1402
+ return withTextWidthProvider(widthProvider, () => textCellWidth(value));
1403
+ }
1404
+ function sliceCells(text, maxCells) {
1405
+ return withTextWidthProvider(widthProvider, () => sliceByCells(text, maxCells));
1406
+ }
1407
+ function sliceCellsRange(text, startCells, endCells) {
1408
+ return withTextWidthProvider(
1409
+ widthProvider,
1410
+ () => sliceByCellsRange(text, startCells, endCells)
1411
+ );
1412
+ }
1413
+ function padCells(text, width) {
1414
+ return withTextWidthProvider(widthProvider, () => padEndByCells(text, width));
1415
+ }
1416
+ function canDrawBox(width, height) {
1417
+ return hasBox.value && Math.floor(width) >= 2 && Math.floor(height) >= 2;
1418
+ }
1419
+ function segmentCells(text) {
1420
+ return cellWidth(text);
1421
+ }
1422
+ function headerCopySegment(width) {
1423
+ if (!hasBox.value || !props.copyButton)
1424
+ return null;
1425
+ let rowWidth = Math.max(0, Math.floor(width));
1426
+ if (rowWidth < 4)
1427
+ return null;
1428
+ let label = sanitizeInlineText(copyLabel.value);
1429
+ if (!label)
1430
+ return null;
1431
+ let maxCells = Math.max(0, rowWidth - 2), text = sliceCells(` ${label} `, maxCells), cells = segmentCells(text);
1432
+ return !text || cells <= 0 ? null : {
1433
+ text,
1434
+ start: Math.max(1, rowWidth - cells - 1),
1435
+ cells
1436
+ };
1437
+ }
1438
+ function headerTitleSegment(width, copy) {
1439
+ if (!hasBox.value)
1440
+ return null;
1441
+ let rowWidth = Math.max(0, Math.floor(width));
1442
+ if (rowWidth < 4)
1443
+ return null;
1444
+ let title = sanitizeInlineText(props.title);
1445
+ if (!title)
1446
+ return null;
1447
+ let titleStart = 1, titleEnd = copy ? Math.max(titleStart, copy.start - 1) : rowWidth - 1, maxCells = Math.max(0, titleEnd - titleStart);
1448
+ if (maxCells <= 0)
1449
+ return null;
1450
+ let text = sliceCells(` ${title} `, maxCells), cells = segmentCells(text);
1451
+ return !text || cells <= 0 ? null : {
1452
+ text,
1453
+ start: titleStart,
1454
+ cells
1455
+ };
1456
+ }
1457
+ let copyHitRect = (0, import_vue8.computed)(() => {
1458
+ let full = fullRect.value;
1459
+ if (!visible.value || !props.copyButton || !canDrawBox(full.w, full.h))
1460
+ return { x: 0, y: 0, w: 0, h: 0 };
1461
+ let copy = headerCopySegment(Math.max(0, Math.floor(full.w)));
1462
+ if (!copy)
1463
+ return { x: 0, y: 0, w: 0, h: 0 };
1464
+ let raw = {
1465
+ x: Math.floor(full.x) + copy.start,
1466
+ y: Math.floor(full.y),
1467
+ w: copy.cells,
1468
+ h: 1
1469
+ };
1470
+ return layout.clipRect ? intersectRect(raw, layout.clipRect) ?? { x: 0, y: 0, w: 0, h: 0 } : raw;
1471
+ });
1472
+ async function writeClipboardText(text) {
1473
+ let contextClipboard = terminalContext.clipboard;
1474
+ if (contextClipboard) {
1475
+ if (!clipboardCanWrite(contextClipboard))
1476
+ throw new Error("Clipboard write not available in this runtime");
1477
+ await contextClipboard.writeText(text);
1478
+ return;
1479
+ }
1480
+ let navClipboard = globalThis.navigator?.clipboard;
1481
+ if (navClipboard && typeof navClipboard.writeText == "function") {
1482
+ await navClipboard.writeText(text);
1483
+ return;
1484
+ }
1485
+ throw new Error("Clipboard write not available in this runtime");
1486
+ }
1487
+ async function copySource() {
1488
+ let text = source.value, requestVersion = ++copyRequestVersion, ok = !1, copyError;
1489
+ try {
1490
+ await writeClipboardText(text), ok = !0;
1491
+ } catch (err) {
1492
+ copyError = err;
1493
+ }
1494
+ if (!alive)
1495
+ return;
1496
+ requestVersion === copyRequestVersion && source.value === text && (ok ? showCopiedFeedback() : setCopied(!1)), emit("copy", ok ? { text, ok } : { text, ok, error: copyError });
1497
+ }
1498
+ function onCopyClick(event) {
1499
+ event.preventDefault(), event.stopPropagation(), copySource();
1500
+ }
1501
+ function onCopyKeydown(event) {
1502
+ event.key !== "Enter" && event.key !== " " || (event.preventDefault(), event.stopPropagation(), copySource());
1503
+ }
1504
+ let copyNodeActive = (0, import_vue8.computed)(
1505
+ () => visible.value && props.copyButton && copyHitRect.value.w > 0 && copyHitRect.value.h > 0
1506
+ );
1507
+ useTerminalNode(() => ({
1508
+ rect: copyHitRect.value,
1509
+ zIndex: (parentEventZ.value ?? 0) + props.zIndex + 1,
1510
+ visible: copyNodeActive.value,
1511
+ focusable: copyNodeActive.value,
1512
+ selectable: !1,
1513
+ handlers: copyNodeActive.value ? {
1514
+ click: onCopyClick,
1515
+ keydown: onCopyKeydown
1516
+ } : {}
1517
+ }));
1518
+ function overlayCells(row, segment, width) {
1519
+ let rowWidth = Math.max(0, Math.floor(width)), start = Math.max(0, Math.floor(segment.start));
1520
+ if (rowWidth <= 1 || start >= rowWidth - 1 || segment.cells <= 0)
1521
+ return row;
1522
+ let maxCells = Math.max(0, rowWidth - 1 - start), text = sliceCells(segment.text, maxCells), cells = segmentCells(text);
1523
+ return !text || cells <= 0 ? row : `${sliceCells(row, start)}${text}${sliceCellsRange(row, start + cells, rowWidth)}`;
1524
+ }
1525
+ function contentLine(rowIndex, width, pad) {
1526
+ let src = displayLines.value[rowIndex] ?? "", clipped = sliceCells(src, width);
1527
+ return pad ? padCells(clipped, width) : clipped;
1528
+ }
1529
+ function boxRow(rowIndex, width, height) {
1530
+ let rowWidth = Math.max(0, Math.floor(width)), rowHeight = Math.max(0, Math.floor(height));
1531
+ if (!canDrawBox(rowWidth, rowHeight))
1532
+ return contentLine(rowIndex, rowWidth, props.clear);
1533
+ let chars = boxChars.value, innerW = Math.max(0, rowWidth - 2);
1534
+ if (rowIndex === 0) {
1535
+ let row = `${chars.tl}${repeatChar(chars.h, innerW)}${chars.tr}`, copy = headerCopySegment(rowWidth), title = headerTitleSegment(rowWidth, copy);
1536
+ return title && (row = overlayCells(row, title, rowWidth)), copy && (row = overlayCells(row, copy, rowWidth)), row;
1537
+ }
1538
+ return rowIndex === rowHeight - 1 ? `${chars.bl}${repeatChar(chars.h, innerW)}${chars.br}` : `${chars.v}${contentLine(rowIndex - 1, innerW, !0)}${chars.v}`;
1539
+ }
1540
+ return useRenderNode(() => ({
1541
+ zIndex: props.zIndex,
1542
+ rect: visible.value ? absRect.value : { x: 0, y: 0, w: 0, h: 0 },
1543
+ deps: [
1544
+ visible.value,
1545
+ absRect.value,
1546
+ fullRect.value,
1547
+ displayLines.value,
1548
+ currentStyle.value,
1549
+ props.clear,
1550
+ renderedSnapshot.value,
1551
+ hasBox.value,
1552
+ boxChars.value,
1553
+ props.title,
1554
+ props.copyButton,
1555
+ copyLabel.value,
1556
+ documentVersion.value
1557
+ ],
1558
+ paint: (dirtyRows) => {
1559
+ withTextWidthProvider(widthProvider, () => {
1560
+ if (!visible.value)
1561
+ return;
1562
+ let r = absRect.value, full = fullRect.value;
1563
+ if (r.w <= 0 || r.h <= 0)
1564
+ return;
1565
+ let style = currentStyle.value, dx = Math.max(0, Math.floor(r.x - full.x)), fullY = Math.floor(full.y), fullW = Math.max(0, Math.floor(full.w)), fullH = Math.max(0, Math.floor(full.h)), blank = props.clear ? spaces(r.w) : "", paintRow = (y) => {
1566
+ if (y < r.y || y >= r.y + r.h)
1567
+ return;
1568
+ let rowIndex = y - fullY;
1569
+ if (rowIndex < 0 || rowIndex >= fullH) {
1570
+ props.clear && terminal.write(blank, { x: r.x, y, style });
1571
+ return;
1572
+ }
1573
+ let src = boxRow(rowIndex, fullW, fullH), clipped = dx > 0 ? sliceCellsRange(src, dx, dx + r.w) : sliceCells(src, r.w), value = props.clear ? padCells(clipped, r.w) : clipped;
1574
+ (value || props.clear) && terminal.write(value, { x: r.x, y, style });
1575
+ };
1576
+ if (dirtyRows?.length) {
1577
+ for (let y of dirtyRows)
1578
+ paintRow(y);
1579
+ return;
1580
+ }
1581
+ for (let y = r.y; y < r.y + r.h; y++)
1582
+ paintRow(y);
1583
+ });
1584
+ }
1585
+ })), () => (0, import_vue8.h)("span", rootProps);
1586
+ }
1587
+ });
1588
+
1589
+ // src/vue/mermaid/beautiful-mermaid.ts
1590
+ var import_vue9 = require("vue");
1591
+ var BEAUTIFUL_MERMAID_INSTALL_HINT = "Install beautiful-mermaid and use TMermaidText from @simon_he/vue-tui/mermaid or @simon_he/vue-tui/agent/mermaid, or pass a custom renderer prop.", MISSING_BEAUTIFUL_MERMAID_ERROR_CODE = "VUE_TUI_MISSING_BEAUTIFUL_MERMAID", INVALID_BEAUTIFUL_MERMAID_EXPORT_ERROR_CODE = "VUE_TUI_INVALID_BEAUTIFUL_MERMAID_EXPORT", cachedBeautifulMermaid = null;
1592
+ function functionValue(value) {
1593
+ return typeof value == "function" ? value : null;
1594
+ }
1595
+ function functionProp(target, key) {
1596
+ if (!target || typeof target != "object" || !(key in target))
1597
+ return null;
1598
+ let value = target[key];
1599
+ return typeof value == "function" ? value : null;
1600
+ }
1601
+ function errorMessage(error) {
1602
+ return error instanceof Error ? error.message : String(error);
1603
+ }
1604
+ function codedError(message, code) {
1605
+ let error = new Error(message);
1606
+ return error.code = code, error;
1607
+ }
1608
+ function missingBeautifulMermaidError(error) {
1609
+ if (error && typeof error == "object" && errorCode(error) === MISSING_BEAUTIFUL_MERMAID_ERROR_CODE)
1610
+ return markMermaidRenderErrorFatal(error);
1611
+ let detail = errorMessage(error);
1612
+ return markMermaidRenderErrorFatal(
1613
+ codedError(
1614
+ `${BEAUTIFUL_MERMAID_INSTALL_HINT} (${detail})`,
1615
+ MISSING_BEAUTIFUL_MERMAID_ERROR_CODE
1616
+ )
1617
+ );
1618
+ }
1619
+ function errorCode(error) {
1620
+ if (!error || typeof error != "object")
1621
+ return "";
1622
+ let value = error.code;
1623
+ return typeof value == "string" ? value : "";
1624
+ }
1625
+ function errorCause(error) {
1626
+ if (!(!error || typeof error != "object"))
1627
+ return error.cause;
1628
+ }
1629
+ function isMissingBeautifulMermaid(error) {
1630
+ return isMissingBeautifulMermaidWithSeen(error, /* @__PURE__ */ new WeakSet());
1631
+ }
1632
+ function isMissingBeautifulMermaidWithSeen(error, seen) {
1633
+ if (error && typeof error == "object") {
1634
+ if (seen.has(error))
1635
+ return !1;
1636
+ seen.add(error);
1637
+ }
1638
+ let message = errorMessage(error), code = errorCode(error);
1639
+ if (code === MISSING_BEAUTIFUL_MERMAID_ERROR_CODE || (/Cannot find package ['"]beautiful-mermaid['"]/.test(message) || /Cannot find module ['"]beautiful-mermaid['"]/.test(message) || /Cannot resolve module ['"]beautiful-mermaid['"]/.test(message) || /Can't resolve ['"]beautiful-mermaid['"]/.test(message) || /Failed to resolve module specifier ['"]beautiful-mermaid['"]/.test(message) || /Failed to resolve import ['"]beautiful-mermaid['"]/.test(message) || /Could not resolve ['"]beautiful-mermaid['"]/.test(message)) && (code === "" || code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || code === "UNRESOLVED_IMPORT"))
1640
+ return !0;
1641
+ let cause = errorCause(error);
1642
+ return cause !== void 0 && isMissingBeautifulMermaidWithSeen(cause, seen);
1643
+ }
1644
+ function resolveBeautifulMermaidRenderer(mod) {
1645
+ let renderer = functionProp(mod, "renderMermaidASCII") ?? functionProp(mod, "renderMermaidAscii") ?? functionValue(mod.default) ?? functionProp(mod.default, "renderMermaidASCII") ?? functionProp(mod.default, "renderMermaidAscii");
1646
+ if (!renderer)
1647
+ throw markMermaidRenderErrorFatal(
1648
+ codedError(
1649
+ "beautiful-mermaid is installed but does not export renderMermaidASCII.",
1650
+ INVALID_BEAUTIFUL_MERMAID_EXPORT_ERROR_CODE
1651
+ )
1652
+ );
1653
+ return renderer;
1654
+ }
1655
+ function hasErrorCode(error, code, seen = /* @__PURE__ */ new WeakSet()) {
1656
+ if (!error || typeof error != "object" || seen.has(error))
1657
+ return !1;
1658
+ if (seen.add(error), errorCode(error) === code)
1659
+ return !0;
1660
+ let cause = errorCause(error);
1661
+ return cause !== void 0 && hasErrorCode(cause, code, seen);
1662
+ }
1663
+ function isBeautifulMermaidExportError(error) {
1664
+ return hasErrorCode(error, INVALID_BEAUTIFUL_MERMAID_EXPORT_ERROR_CODE);
1665
+ }
1666
+ var isTransientBeautifulMermaidRenderError = (error) => !(isMissingBeautifulMermaid(error) || isBeautifulMermaidExportError(error));
1667
+ async function loadBeautifulMermaid() {
1668
+ return cachedBeautifulMermaid || (cachedBeautifulMermaid = import("beautiful-mermaid").then((mod) => mod).catch((error) => {
1669
+ throw cachedBeautifulMermaid = null, isMissingBeautifulMermaid(error) ? missingBeautifulMermaidError(error) : markMermaidRenderErrorFatal(error);
1670
+ })), cachedBeautifulMermaid;
1671
+ }
1672
+ var beautifulMermaidRenderer = async (code, options) => {
1673
+ try {
1674
+ let mod = await loadBeautifulMermaid();
1675
+ return await resolveBeautifulMermaidRenderer(mod)(code, options);
1676
+ } catch (error) {
1677
+ throw isMissingBeautifulMermaid(error) ? missingBeautifulMermaidError(error) : error;
1678
+ }
1679
+ };
1680
+ function createBeautifulMermaidRenderer() {
1681
+ return beautifulMermaidRenderer;
1682
+ }
1683
+ var TMermaidText2 = (0, import_vue9.defineComponent)({
1684
+ name: "TMermaidText",
1685
+ inheritAttrs: !1,
1686
+ props: tMermaidTextProps,
1687
+ emits: {
1688
+ copy: (_payload) => !0
1689
+ },
1690
+ setup(props, { attrs, emit, slots }) {
1691
+ return () => {
1692
+ let renderer = props.renderer ?? beautifulMermaidRenderer, shouldRenderSource = props.shouldRenderSource ?? isSimpleMermaidFlowchartSource;
1693
+ return (0, import_vue9.h)(
1694
+ TMermaidText,
1695
+ {
1696
+ ...attrs,
1697
+ ...props,
1698
+ renderer,
1699
+ shouldRenderSource,
1700
+ isTransientError: props.isTransientError ?? isTransientBeautifulMermaidRenderError,
1701
+ onCopy: (payload) => emit("copy", payload)
1702
+ },
1703
+ slots
1704
+ );
1705
+ };
1706
+ }
1707
+ }), TMermaid = TMermaidText2, TBeautifulMermaidText = TMermaidText2, TBeautifulMermaid = TMermaidText2;