@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
package/dist/runtime.cjs CHANGED
@@ -5,17 +5,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __export = (target, all) => {
7
7
  for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
12
11
  for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
13
  return to;
17
14
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
19
16
 
20
17
  // src/runtime.ts
21
18
  var runtime_exports = {};
@@ -29,16 +26,14 @@ __export(runtime_exports, {
29
26
  module.exports = __toCommonJS(runtime_exports);
30
27
 
31
28
  // src/events/manager/selection-suppression.ts
32
- var SUPPRESS_TERMINAL_POINTER_UP = "__vueTuiSuppressTerminalPointerUp";
33
- var SUPPRESS_TERMINAL_POINTER_DOWN = "__vueTuiSuppressTerminalPointerDown";
34
- var SUPPRESS_TERMINAL_POINTER_MOVE = "__vueTuiSuppressTerminalPointerMove";
29
+ var SUPPRESS_TERMINAL_POINTER_UP = "__vueTuiSuppressTerminalPointerUp", SUPPRESS_TERMINAL_POINTER_DOWN = "__vueTuiSuppressTerminalPointerDown", SUPPRESS_TERMINAL_POINTER_MOVE = "__vueTuiSuppressTerminalPointerMove";
35
30
 
36
31
  // src/events/manager/event-manager.ts
37
32
  function contains(rect, x, y) {
38
33
  return x >= rect.x && y >= rect.y && x < rect.x + rect.w && y < rect.y + rect.h;
39
34
  }
40
35
  function isVisible(node) {
41
- return node.visible !== false;
36
+ return node.visible !== !1;
42
37
  }
43
38
  function containsRect(outer, inner) {
44
39
  return inner.x >= outer.x && inner.y >= outer.y && inner.x + inner.w <= outer.x + outer.w && inner.y + inner.h <= outer.y + outer.h;
@@ -50,152 +45,89 @@ function sameRect(a, b) {
50
45
  return a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
51
46
  }
52
47
  function now() {
53
- return typeof performance !== "undefined" ? performance.now() : Date.now();
48
+ return typeof performance < "u" ? performance.now() : Date.now();
54
49
  }
55
50
  function rectRowRange(rect) {
56
- const y0 = Math.floor(rect.y);
57
- const y1 = Math.ceil(rect.y + rect.h) - 1;
58
- if (!Number.isFinite(y0) || !Number.isFinite(y1))
59
- return null;
60
- if (y1 < y0)
61
- return null;
62
- return { y0, y1 };
51
+ let y0 = Math.floor(rect.y), y1 = Math.ceil(rect.y + rect.h) - 1;
52
+ return !Number.isFinite(y0) || !Number.isFinite(y1) || y1 < y0 ? null : { y0, y1 };
63
53
  }
64
54
  var nextId = 0;
65
55
  function createEventManager(container, metrics, options) {
66
- let currentMetrics = metrics;
67
- const nodes = /* @__PURE__ */ new Map();
68
- const rowBuckets = /* @__PURE__ */ new Map();
69
- const rowRangeById = /* @__PURE__ */ new Map();
70
- let focusedId = null;
71
- let capturedId = null;
72
- let hoverPath = [];
73
- let lastPointerMoveEvent = null;
74
- const rawRecord = options?.record;
75
- const recordStart = now();
76
- const record = rawRecord ? (event) => {
56
+ let currentMetrics = metrics, nodes = /* @__PURE__ */ new Map(), rowBuckets = /* @__PURE__ */ new Map(), rowRangeById = /* @__PURE__ */ new Map(), focusedId = null, capturedId = null, hoverPath = [], lastPointerMoveEvent = null, rawRecord = options?.record, recordStart = now(), record = rawRecord ? (event) => {
77
57
  rawRecord({ ...event, time: now() - recordStart });
78
- } : void 0;
79
- const onFocusChange = options?.onFocusChange;
80
- const textInputTarget = options?.textInputTarget ?? null;
81
- const MODAL_FOCUS_Z_THRESHOLD = 100;
82
- const MODAL_ROOT_MIN_AREA = 40;
58
+ } : void 0, onFocusChange = options?.onFocusChange, textInputTarget = options?.textInputTarget ?? null, MODAL_FOCUS_Z_THRESHOLD = 100, MODAL_ROOT_MIN_AREA = 40;
83
59
  function focusLockTarget() {
84
- let bestRoot = null;
85
- let bestAny = null;
86
- for (const n of nodes.values()) {
60
+ let bestRoot = null, bestAny = null;
61
+ for (let n of nodes.values()) {
87
62
  if (!n.focusable || !isVisible(n))
88
63
  continue;
89
- const z = n.zIndex ?? 0;
64
+ let z = n.zIndex ?? 0;
90
65
  if (z < MODAL_FOCUS_Z_THRESHOLD)
91
66
  continue;
92
- const a = area(n.rect);
93
- if (!bestAny || z > bestAny.zIndex || z === bestAny.zIndex && a > bestAny.area) {
94
- bestAny = { id: n.id, zIndex: z, area: a };
95
- }
96
- if (a >= MODAL_ROOT_MIN_AREA && (!bestRoot || z > bestRoot.zIndex || z === bestRoot.zIndex && a > bestRoot.area)) {
97
- bestRoot = { id: n.id, zIndex: z, area: a };
98
- }
67
+ let a = area(n.rect);
68
+ (!bestAny || z > bestAny.zIndex || z === bestAny.zIndex && a > bestAny.area) && (bestAny = { id: n.id, zIndex: z, area: a }), a >= MODAL_ROOT_MIN_AREA && (!bestRoot || z > bestRoot.zIndex || z === bestRoot.zIndex && a > bestRoot.area) && (bestRoot = { id: n.id, zIndex: z, area: a });
99
69
  }
100
- const best = bestRoot ?? bestAny;
70
+ let best = bestRoot ?? bestAny;
101
71
  return best ? { id: best.id, zIndex: best.zIndex } : null;
102
72
  }
103
73
  function resolveLockedFocusTarget(type) {
104
- const lock = focusLockTarget();
105
- let target = focusedId ? nodes.get(focusedId) ?? null : null;
106
- const shouldRetarget = lock && (!target || !isVisible(target) || (target.zIndex ?? 0) < lock.zIndex);
107
- if (!shouldRetarget || !lock)
74
+ let lock = focusLockTarget(), target = focusedId ? nodes.get(focusedId) ?? null : null;
75
+ if (!(lock && (!target || !isVisible(target) || (target.zIndex ?? 0) < lock.zIndex)) || !lock)
108
76
  return target;
109
- let best = null;
110
- let bestScore = -Infinity;
111
- for (const node of nodes.values()) {
77
+ let best = null, bestScore = -1 / 0;
78
+ for (let node of nodes.values()) {
112
79
  if (!node.focusable || !isVisible(node))
113
80
  continue;
114
- const z = node.zIndex ?? 0;
81
+ let z = node.zIndex ?? 0;
115
82
  if (z < lock.zIndex)
116
83
  continue;
117
- const handlers = node.handlers ?? {};
118
- const canHandle = type ? typeof handlers[type] === "function" : false;
119
- const a = area(node.rect);
120
- const score = z * 1e9 + (canHandle ? 1e6 : 0) - a;
121
- if (score > bestScore) {
122
- bestScore = score;
123
- best = node;
124
- }
84
+ let handlers = node.handlers ?? {}, canHandle = type ? typeof handlers[type] == "function" : !1, a = area(node.rect), score = z * 1e9 + (canHandle ? 1e6 : 0) - a;
85
+ score > bestScore && (bestScore = score, best = node);
125
86
  }
126
- if (best) {
127
- setFocus(best.id);
128
- target = best;
129
- }
130
- return target;
87
+ return best && (setFocus(best.id), target = best), target;
131
88
  }
132
89
  function resolveModalLockNode() {
133
- const lock = focusLockTarget();
90
+ let lock = focusLockTarget();
134
91
  if (!lock)
135
92
  return null;
136
- const node = nodes.get(lock.id) ?? null;
93
+ let node = nodes.get(lock.id) ?? null;
137
94
  return node && isVisible(node) ? node : null;
138
95
  }
139
96
  function isAllowedModalPointerNode(node, target, lockNode) {
140
- const nodeZ = node.zIndex ?? 0;
141
- const targetZ = target.zIndex ?? 0;
142
- const lockZ = lockNode.zIndex ?? 0;
143
- if (nodeZ >= lockZ)
144
- return true;
145
- return targetZ < lockZ && nodeZ >= targetZ && containsRect(node.rect, lockNode.rect);
97
+ let nodeZ = node.zIndex ?? 0, targetZ = target.zIndex ?? 0, lockZ = lockNode.zIndex ?? 0;
98
+ return nodeZ >= lockZ ? !0 : targetZ < lockZ && nodeZ >= targetZ && containsRect(node.rect, lockNode.rect);
146
99
  }
147
- const shouldDebugIme = () => Boolean(options?.debugIme) || Boolean(globalThis.__VT_DEBUG_IME__);
148
- const imeLog = (msg, extra) => {
149
- if (!shouldDebugIme())
150
- return;
151
- console.debug(`[vue-terminal][ime] ${msg}`, extra ?? {});
152
- };
153
- let domComposing = false;
154
- const defaultUserSelect = container.style.userSelect || "text";
155
- if (!container.hasAttribute("tabindex"))
156
- container.tabIndex = 0;
157
- if (!container.style.userSelect)
158
- container.style.userSelect = defaultUserSelect;
159
- let containerRect = null;
160
- let containerRectDirty = true;
100
+ let shouldDebugIme = () => !!options?.debugIme || !!globalThis.__VT_DEBUG_IME__, imeLog = (msg, extra) => {
101
+ shouldDebugIme() && console.debug(`[vue-terminal][ime] ${msg}`, extra ?? {});
102
+ }, domComposing = !1, defaultUserSelect = container.style.userSelect || "text";
103
+ container.hasAttribute("tabindex") || (container.tabIndex = 0), container.style.userSelect || (container.style.userSelect = defaultUserSelect);
104
+ let containerRect = null, containerRectDirty = !0;
161
105
  function markContainerRectDirty() {
162
- containerRectDirty = true;
106
+ containerRectDirty = !0;
163
107
  }
164
108
  function getContainerRect() {
165
- if (!containerRect || containerRectDirty) {
166
- containerRect = container.getBoundingClientRect();
167
- containerRectDirty = false;
168
- }
169
- return containerRect;
109
+ return (!containerRect || containerRectDirty) && (containerRect = container.getBoundingClientRect(), containerRectDirty = !1), containerRect;
170
110
  }
171
111
  function removeFromRowBuckets(id) {
172
- const prev = rowRangeById.get(id);
173
- if (!prev)
174
- return;
175
- for (let y = prev.y0; y <= prev.y1; y++) {
176
- const bucket = rowBuckets.get(y);
177
- if (!bucket)
178
- continue;
179
- bucket.delete(id);
180
- if (bucket.size === 0)
181
- rowBuckets.delete(y);
112
+ let prev = rowRangeById.get(id);
113
+ if (prev) {
114
+ for (let y = prev.y0; y <= prev.y1; y++) {
115
+ let bucket = rowBuckets.get(y);
116
+ bucket && (bucket.delete(id), bucket.size === 0 && rowBuckets.delete(y));
117
+ }
118
+ rowRangeById.delete(id);
182
119
  }
183
- rowRangeById.delete(id);
184
120
  }
185
121
  function addToRowBuckets(id, node) {
186
122
  if (!isVisible(node))
187
123
  return;
188
- const range = rectRowRange(node.rect);
189
- if (!range)
190
- return;
191
- rowRangeById.set(id, range);
192
- for (let y = range.y0; y <= range.y1; y++) {
193
- let bucket = rowBuckets.get(y);
194
- if (!bucket) {
195
- bucket = /* @__PURE__ */ new Set();
196
- rowBuckets.set(y, bucket);
124
+ let range = rectRowRange(node.rect);
125
+ if (range) {
126
+ rowRangeById.set(id, range);
127
+ for (let y = range.y0; y <= range.y1; y++) {
128
+ let bucket = rowBuckets.get(y);
129
+ bucket || (bucket = /* @__PURE__ */ new Set(), rowBuckets.set(y, bucket)), bucket.add(id);
197
130
  }
198
- bucket.add(id);
199
131
  }
200
132
  }
201
133
  function updateRowBuckets(id, node) {
@@ -203,38 +135,26 @@ function createEventManager(container, metrics, options) {
203
135
  removeFromRowBuckets(id);
204
136
  return;
205
137
  }
206
- const next = rectRowRange(node.rect);
207
- const prev = rowRangeById.get(id);
138
+ let next = rectRowRange(node.rect), prev = rowRangeById.get(id);
208
139
  if (!next) {
209
140
  removeFromRowBuckets(id);
210
141
  return;
211
142
  }
212
- if (prev && prev.y0 === next.y0 && prev.y1 === next.y1)
213
- return;
214
- removeFromRowBuckets(id);
215
- rowRangeById.set(id, next);
216
- for (let y = next.y0; y <= next.y1; y++) {
217
- let bucket = rowBuckets.get(y);
218
- if (!bucket) {
219
- bucket = /* @__PURE__ */ new Set();
220
- rowBuckets.set(y, bucket);
143
+ if (!(prev && prev.y0 === next.y0 && prev.y1 === next.y1)) {
144
+ removeFromRowBuckets(id), rowRangeById.set(id, next);
145
+ for (let y = next.y0; y <= next.y1; y++) {
146
+ let bucket = rowBuckets.get(y);
147
+ bucket || (bucket = /* @__PURE__ */ new Set(), rowBuckets.set(y, bucket)), bucket.add(id);
221
148
  }
222
- bucket.add(id);
223
149
  }
224
150
  }
225
151
  function candidatesAt(cellX, cellY) {
226
- const list = [];
227
- const bucket = rowBuckets.get(cellY);
152
+ let list = [], bucket = rowBuckets.get(cellY);
228
153
  if (!bucket)
229
154
  return list;
230
- for (const id of bucket) {
231
- const node = nodes.get(id);
232
- if (!node)
233
- continue;
234
- if (!isVisible(node))
235
- continue;
236
- if (contains(node.rect, cellX, cellY))
237
- list.push(node);
155
+ for (let id of bucket) {
156
+ let node = nodes.get(id);
157
+ node && isVisible(node) && contains(node.rect, cellX, cellY) && list.push(node);
238
158
  }
239
159
  return list.sort((a, b) => area(b.rect) - area(a.rect) || a.zIndex - b.zIndex);
240
160
  }
@@ -242,180 +162,130 @@ function createEventManager(container, metrics, options) {
242
162
  if (list.length === 0)
243
163
  return null;
244
164
  let target = list[0];
245
- for (const n of list) {
246
- if (n.zIndex > target.zIndex)
247
- target = n;
248
- else if (n.zIndex === target.zIndex && area(n.rect) <= area(target.rect))
249
- target = n;
250
- }
165
+ for (let n of list)
166
+ (n.zIndex > target.zIndex || n.zIndex === target.zIndex && area(n.rect) <= area(target.rect)) && (target = n);
251
167
  return target;
252
168
  }
253
169
  function pathOuterToInner(list, target) {
254
- if (!target)
255
- return [];
256
- const filtered = list.filter(
170
+ return target ? [...list.filter(
257
171
  (n) => n.id !== target.id && (!n.focusable || !target.focusable || n.zIndex !== target.zIndex || !sameRect(n.rect, target.rect))
258
- );
259
- return [...filtered, target];
172
+ ), target] : [];
260
173
  }
261
174
  function ancestorsForTarget(target) {
262
- const range = rectRowRange(target.rect);
263
- const seedBucket = range ? rowBuckets.get(range.y0) : null;
175
+ let range = rectRowRange(target.rect), seedBucket = range ? rowBuckets.get(range.y0) : null;
264
176
  if (!seedBucket) {
265
- const list2 = [];
266
- for (const node of nodes.values()) {
267
- if (!isVisible(node))
268
- continue;
269
- if (containsRect(node.rect, target.rect))
270
- list2.push(node);
271
- }
272
- const sorted2 = list2.sort((a, b) => a.zIndex - b.zIndex || area(b.rect) - area(a.rect));
177
+ let list2 = [];
178
+ for (let node of nodes.values())
179
+ isVisible(node) && containsRect(node.rect, target.rect) && list2.push(node);
180
+ let sorted2 = list2.sort((a, b) => a.zIndex - b.zIndex || area(b.rect) - area(a.rect));
273
181
  return pathOuterToInner(sorted2, target);
274
182
  }
275
- const list = [];
276
- for (const id of seedBucket) {
277
- const node = nodes.get(id);
278
- if (!node)
279
- continue;
280
- if (!isVisible(node))
281
- continue;
282
- if (containsRect(node.rect, target.rect))
283
- list.push(node);
183
+ let list = [];
184
+ for (let id of seedBucket) {
185
+ let node = nodes.get(id);
186
+ node && isVisible(node) && containsRect(node.rect, target.rect) && list.push(node);
284
187
  }
285
- const sorted = list.sort((a, b) => a.zIndex - b.zIndex || area(b.rect) - area(a.rect));
188
+ let sorted = list.sort((a, b) => a.zIndex - b.zIndex || area(b.rect) - area(a.rect));
286
189
  return pathOuterToInner(sorted, target);
287
190
  }
288
191
  function makeBaseEvent(type, path, nativeEvent) {
289
- const e = {
192
+ return {
290
193
  type,
291
194
  target: null,
292
195
  currentTarget: null,
293
196
  eventPhase: 2,
294
- bubbles: true,
295
- cancelable: true,
296
- defaultPrevented: Boolean(nativeEvent?.defaultPrevented),
197
+ bubbles: !0,
198
+ cancelable: !0,
199
+ defaultPrevented: !!nativeEvent?.defaultPrevented,
297
200
  timeStamp: now(),
298
- __stopped: false,
201
+ __stopped: !1,
299
202
  stopPropagation() {
300
- this.__stopped = true;
203
+ this.__stopped = !0;
301
204
  },
302
205
  preventDefault() {
303
- this.defaultPrevented = true;
304
- nativeEvent?.preventDefault?.();
206
+ this.defaultPrevented = !0, nativeEvent?.preventDefault?.();
305
207
  },
306
208
  composedPath() {
307
209
  return [...path].reverse();
308
210
  },
309
211
  nativeEvent
310
212
  };
311
- return e;
312
213
  }
313
214
  function dispatchToNode(handlerKey, node, event) {
314
- event.currentTarget = node;
315
- if (!node)
215
+ if (event.currentTarget = node, !node)
316
216
  return;
317
- const handler = node.handlers[handlerKey];
217
+ let handler = node.handlers[handlerKey];
318
218
  handler?.(event);
319
219
  }
320
220
  function dispatchWithPhases(type, path, target, event) {
321
221
  event.target = target;
322
- const captureKey = `${type}Capture`;
222
+ let captureKey = `${type}Capture`;
323
223
  event.eventPhase = 1;
324
- for (const node of path) {
325
- dispatchToNode(captureKey, node, event);
326
- if (event.__stopped)
327
- return;
328
- }
329
- if (target) {
330
- event.eventPhase = 2;
331
- dispatchToNode(type, target, event);
332
- if (event.__stopped)
333
- return;
334
- }
335
- if (!event.bubbles)
336
- return;
337
- event.eventPhase = 3;
338
- for (let i = path.length - 2; i >= 0; i--) {
339
- dispatchToNode(type, path[i], event);
340
- if (event.__stopped)
224
+ for (let node of path)
225
+ if (dispatchToNode(captureKey, node, event), event.__stopped)
341
226
  return;
227
+ if (!(target && (event.eventPhase = 2, dispatchToNode(type, target, event), event.__stopped)) && event.bubbles) {
228
+ event.eventPhase = 3;
229
+ for (let i = path.length - 2; i >= 0; i--)
230
+ if (dispatchToNode(type, path[i], event), event.__stopped)
231
+ return;
342
232
  }
343
233
  }
344
234
  function sharedPrefixLenById(a, b) {
345
- const min = Math.min(a.length, b.length);
346
- let i = 0;
347
- for (; i < min; i++) {
348
- if (a[i].id !== b[i].id)
349
- break;
350
- }
235
+ let min = Math.min(a.length, b.length), i = 0;
236
+ for (; i < min && a[i].id === b[i].id; i++)
237
+ ;
351
238
  return i;
352
239
  }
353
240
  function updateHover(nextTarget, native) {
354
- const nextPath = nextTarget ? ancestorsForTarget(nextTarget) : [];
355
- const shared = sharedPrefixLenById(hoverPath, nextPath);
241
+ let nextPath = nextTarget ? ancestorsForTarget(nextTarget) : [], shared = sharedPrefixLenById(hoverPath, nextPath);
356
242
  for (let i = hoverPath.length - 1; i >= shared; i--) {
357
- const target = hoverPath[i] ?? null;
243
+ let target = hoverPath[i] ?? null;
358
244
  if (!target)
359
245
  continue;
360
- const path = hoverPath.slice(0, i + 1);
361
- const ev = buildPointerEvent("pointerleave", path, native);
362
- ev.bubbles = false;
363
- dispatchWithPhases("pointerleave", path, target, ev);
246
+ let path = hoverPath.slice(0, i + 1), ev = buildPointerEvent("pointerleave", path, native);
247
+ ev.bubbles = !1, dispatchWithPhases("pointerleave", path, target, ev);
364
248
  }
365
249
  for (let i = shared; i < nextPath.length; i++) {
366
- const target = nextPath[i] ?? null;
250
+ let target = nextPath[i] ?? null;
367
251
  if (!target)
368
252
  continue;
369
- const path = nextPath.slice(0, i + 1);
370
- const ev = buildPointerEvent("pointerenter", path, native);
371
- ev.bubbles = false;
372
- dispatchWithPhases("pointerenter", path, target, ev);
253
+ let path = nextPath.slice(0, i + 1), ev = buildPointerEvent("pointerenter", path, native);
254
+ ev.bubbles = !1, dispatchWithPhases("pointerenter", path, target, ev);
373
255
  }
374
256
  hoverPath = nextPath;
375
257
  }
376
258
  function setFocus(nextId2) {
377
- const lock = focusLockTarget();
378
- if (lock) {
379
- if (!nextId2) {
259
+ let lock = focusLockTarget();
260
+ if (lock)
261
+ if (!nextId2)
380
262
  nextId2 = lock.id;
381
- } else {
382
- const want = nodes.get(nextId2) ?? null;
383
- const wantZ = want?.zIndex ?? 0;
384
- if (want && isVisible(want) && wantZ < lock.zIndex) {
263
+ else {
264
+ let want = nodes.get(nextId2) ?? null, wantZ = want?.zIndex ?? 0;
265
+ if (want && isVisible(want) && wantZ < lock.zIndex)
385
266
  return;
386
- }
387
267
  }
388
- }
389
268
  if (focusedId === nextId2)
390
269
  return;
391
- const prev = focusedId ? nodes.get(focusedId) ?? null : null;
392
- const nextRaw = nextId2 ? nodes.get(nextId2) ?? null : null;
393
- const next = nextRaw && isVisible(nextRaw) ? nextRaw : null;
394
- focusedId = next?.id ?? null;
395
- onFocusChange?.(prev?.id ?? null, focusedId);
396
- if (prev) {
397
- const path = ancestorsForTarget(prev);
398
- const ev = makeBaseEvent("blur", path);
270
+ let prev = focusedId ? nodes.get(focusedId) ?? null : null, nextRaw = nextId2 ? nodes.get(nextId2) ?? null : null, next = nextRaw && isVisible(nextRaw) ? nextRaw : null;
271
+ if (focusedId = next?.id ?? null, onFocusChange?.(prev?.id ?? null, focusedId), prev) {
272
+ let path = ancestorsForTarget(prev), ev = makeBaseEvent("blur", path);
399
273
  dispatchWithPhases("blur", path, prev, ev);
400
274
  }
401
275
  if (next) {
402
- const path = ancestorsForTarget(next);
403
- const ev = makeBaseEvent("focus", path);
276
+ let path = ancestorsForTarget(next), ev = makeBaseEvent("focus", path);
404
277
  dispatchWithPhases("focus", path, next, ev);
405
278
  }
406
279
  }
407
280
  function toCell(clientX, clientY) {
408
- const rect = getContainerRect();
409
- const x = clientX - rect.left;
410
- const y = clientY - rect.top;
281
+ let rect = getContainerRect(), x = clientX - rect.left, y = clientY - rect.top;
411
282
  return {
412
283
  cellX: Math.max(0, Math.floor(x / currentMetrics.cellWidth)),
413
284
  cellY: Math.max(0, Math.floor(y / currentMetrics.cellHeight))
414
285
  };
415
286
  }
416
287
  function buildPointerEvent(type, path, native) {
417
- const base = makeBaseEvent(type, path, native);
418
- const { cellX, cellY } = toCell(native.clientX, native.clientY);
288
+ let base = makeBaseEvent(type, path, native), { cellX, cellY } = toCell(native.clientX, native.clientY);
419
289
  return Object.assign(base, {
420
290
  clientX: native.clientX,
421
291
  clientY: native.clientY,
@@ -433,19 +303,10 @@ function createEventManager(container, metrics, options) {
433
303
  }
434
304
  function keyCombo(native) {
435
305
  let out = "";
436
- if (native.metaKey)
437
- out += "Meta+";
438
- if (native.ctrlKey)
439
- out += "Ctrl+";
440
- if (native.altKey)
441
- out += "Alt+";
442
- if (native.shiftKey)
443
- out += "Shift+";
444
- out += native.key;
445
- return out;
306
+ return native.metaKey && (out += "Meta+"), native.ctrlKey && (out += "Ctrl+"), native.altKey && (out += "Alt+"), native.shiftKey && (out += "Shift+"), out += native.key, out;
446
307
  }
447
308
  function buildKeyboardEvent(type, path, native) {
448
- const base = makeBaseEvent(type, path, native);
309
+ let base = makeBaseEvent(type, path, native);
449
310
  return Object.assign(base, {
450
311
  key: native.key,
451
312
  code: native.code,
@@ -458,74 +319,46 @@ function createEventManager(container, metrics, options) {
458
319
  });
459
320
  }
460
321
  function dispatchPointer(type, native, targetOverride) {
461
- const { cellX, cellY } = toCell(native.clientX, native.clientY);
462
- const list = candidatesAt(cellX, cellY);
463
- const target = targetOverride ?? pickTarget(list);
464
- const lockNode = resolveModalLockNode();
322
+ let { cellX, cellY } = toCell(native.clientX, native.clientY), list = candidatesAt(cellX, cellY), target = targetOverride ?? pickTarget(list), lockNode = resolveModalLockNode();
465
323
  if (lockNode && target && !isAllowedModalPointerNode(target, target, lockNode))
466
324
  return;
467
325
  let path = target ? ancestorsForTarget(target) : [];
468
- if (lockNode && target && path.length > 0) {
469
- path = path.filter((n) => isAllowedModalPointerNode(n, target, lockNode));
470
- }
471
- const ev = buildPointerEvent(type, path, native);
326
+ lockNode && target && path.length > 0 && (path = path.filter((n) => isAllowedModalPointerNode(n, target, lockNode)));
327
+ let ev = buildPointerEvent(type, path, native);
472
328
  dispatchWithPhases(type, path, target, ev);
473
329
  }
474
330
  function dispatchToFocused(type, native) {
475
- const target = resolveLockedFocusTarget(type);
476
- const path = target ? ancestorsForTarget(target) : [];
477
- const ev = buildKeyboardEvent(type, path, native);
478
- dispatchWithPhases(type, path, target, ev);
479
- if (ev.defaultPrevented)
480
- native.preventDefault();
331
+ let target = resolveLockedFocusTarget(type), path = target ? ancestorsForTarget(target) : [], ev = buildKeyboardEvent(type, path, native);
332
+ dispatchWithPhases(type, path, target, ev), ev.defaultPrevented && native.preventDefault();
481
333
  }
482
334
  function buildInputEvent(type, path, native) {
483
- const base = makeBaseEvent(type, path, native);
484
- const anyNative = native;
485
- const data = typeof anyNative.data === "string" ? anyNative.data : void 0;
486
- const inputType = typeof anyNative.inputType === "string" ? anyNative.inputType : void 0;
487
- const isComposing = Boolean(anyNative.isComposing);
488
- let text;
335
+ let base = makeBaseEvent(type, path, native), anyNative = native, data = typeof anyNative.data == "string" ? anyNative.data : void 0, inputType = typeof anyNative.inputType == "string" ? anyNative.inputType : void 0, isComposing = !!anyNative.isComposing, text;
489
336
  if (type === "paste") {
490
- const clipboard = anyNative.clipboardData;
491
- if (clipboard?.getData) {
492
- text = clipboard.getData("text/plain") || clipboard.getData("text") || "";
493
- }
337
+ let clipboard = anyNative.clipboardData;
338
+ clipboard?.getData && (text = clipboard.getData("text/plain") || clipboard.getData("text") || "");
494
339
  }
495
340
  return Object.assign(base, { data, inputType, isComposing, text });
496
341
  }
497
342
  function dispatchToFocusedText(type, native) {
498
- const target = resolveLockedFocusTarget(type);
499
- const path = target ? ancestorsForTarget(target) : [];
500
- const ev = buildInputEvent(type, path, native);
501
- dispatchWithPhases(type, path, target, ev);
502
- if (ev.defaultPrevented)
503
- native.preventDefault?.();
343
+ let target = resolveLockedFocusTarget(type), path = target ? ancestorsForTarget(target) : [], ev = buildInputEvent(type, path, native);
344
+ dispatchWithPhases(type, path, target, ev), ev.defaultPrevented && native.preventDefault?.();
504
345
  }
505
346
  function onPointerDown(e) {
506
347
  if (e[SUPPRESS_TERMINAL_POINTER_DOWN]) {
507
- if (textInputTarget && !container.contains(textInputTarget)) {
348
+ if (textInputTarget && !container.contains(textInputTarget))
508
349
  try {
509
- textInputTarget.focus?.({ preventScroll: true });
350
+ textInputTarget.focus?.({ preventScroll: !0 });
510
351
  } catch {
511
352
  textInputTarget.focus?.();
512
353
  }
513
- } else {
354
+ else
514
355
  try {
515
- container.focus?.({ preventScroll: true });
356
+ container.focus?.({ preventScroll: !0 });
516
357
  } catch {
517
358
  container.focus?.();
518
359
  }
519
- }
520
- const { cellX: cellX2, cellY: cellY2 } = toCell(e.clientX, e.clientY);
521
- const list2 = candidatesAt(cellX2, cellY2);
522
- const target2 = pickTarget(list2);
523
- if (target2?.focusable) {
524
- setFocus(target2.id);
525
- }
526
- capturedId = target2?.id ?? null;
527
- updateHover(target2, e);
528
- record?.({
360
+ let { cellX: cellX2, cellY: cellY2 } = toCell(e.clientX, e.clientY), list2 = candidatesAt(cellX2, cellY2), target2 = pickTarget(list2);
361
+ target2?.focusable && setFocus(target2.id), capturedId = target2?.id ?? null, updateHover(target2, e), record?.({
529
362
  type: "pointerdown",
530
363
  cellX: cellX2,
531
364
  cellY: cellY2,
@@ -542,49 +375,38 @@ function createEventManager(container, metrics, options) {
542
375
  }
543
376
  if (textInputTarget && !container.contains(textInputTarget)) {
544
377
  try {
545
- textInputTarget.focus?.({ preventScroll: true });
378
+ textInputTarget.focus?.({ preventScroll: !0 });
546
379
  } catch {
547
380
  textInputTarget.focus?.();
548
381
  }
549
382
  if (shouldDebugIme()) {
550
- const active = typeof document !== "undefined" ? document.activeElement?.tagName ?? null : null;
383
+ let active = typeof document < "u" ? document.activeElement?.tagName ?? null : null;
551
384
  imeLog("pointerdown focus textInputTarget", { active });
552
385
  }
553
- } else {
386
+ } else
554
387
  try {
555
- container.focus?.({ preventScroll: true });
388
+ container.focus?.({ preventScroll: !0 });
556
389
  } catch {
557
390
  container.focus?.();
558
391
  }
559
- }
560
- const { cellX, cellY } = toCell(e.clientX, e.clientY);
561
- const list = candidatesAt(cellX, cellY);
562
- const target = pickTarget(list);
563
- const lockNode = resolveModalLockNode();
392
+ let { cellX, cellY } = toCell(e.clientX, e.clientY), list = candidatesAt(cellX, cellY), target = pickTarget(list), lockNode = resolveModalLockNode();
564
393
  if (lockNode && target && !isAllowedModalPointerNode(target, target, lockNode))
565
394
  return;
566
395
  let path = target ? ancestorsForTarget(target) : [];
567
- if (lockNode && target && path.length > 0) {
568
- path = path.filter((n) => isAllowedModalPointerNode(n, target, lockNode));
569
- }
570
- const allowSelection = target ? target.selectable ?? !target.focusable : true;
571
- container.style.userSelect = allowSelection ? defaultUserSelect : "none";
572
- if (target) {
573
- if (target.focusable) {
396
+ lockNode && target && path.length > 0 && (path = path.filter((n) => isAllowedModalPointerNode(n, target, lockNode)));
397
+ let allowSelection = target ? target.selectable ?? !target.focusable : !0;
398
+ if (container.style.userSelect = allowSelection ? defaultUserSelect : "none", target)
399
+ if (target.focusable)
574
400
  setFocus(target.id);
575
- } else {
401
+ else
576
402
  for (let i = path.length - 2; i >= 0; i--) {
577
- const n = path[i];
403
+ let n = path[i];
578
404
  if (n?.focusable) {
579
405
  setFocus(n.id);
580
406
  break;
581
407
  }
582
408
  }
583
- }
584
- }
585
- capturedId = target?.id ?? null;
586
- updateHover(target, e);
587
- record?.({
409
+ capturedId = target?.id ?? null, updateHover(target, e), record?.({
588
410
  type: "pointerdown",
589
411
  cellX,
590
412
  cellY,
@@ -597,30 +419,27 @@ function createEventManager(container, metrics, options) {
597
419
  altKey: e.altKey,
598
420
  metaKey: e.metaKey
599
421
  });
600
- const ev = buildPointerEvent("pointerdown", path, e);
422
+ let ev = buildPointerEvent("pointerdown", path, e);
601
423
  dispatchWithPhases("pointerdown", path, target, ev);
602
424
  }
603
425
  function onMouseDown(e) {
604
426
  onPointerDown(e);
605
427
  }
606
428
  function onMouseMove(e) {
607
- lastPointerMoveEvent = e;
608
- onPointerMove(e);
429
+ lastPointerMoveEvent = e, onPointerMove(e);
609
430
  }
610
431
  function onMouseUp(e) {
611
432
  onPointerUp(e);
612
433
  }
613
434
  function onMouseLeave(e) {
614
- const native = lastPointerMoveEvent ?? e;
615
- updateHover(null, native);
435
+ updateHover(null, lastPointerMoveEvent ?? e);
616
436
  }
617
437
  function onPointerMove(e) {
618
- if (e[SUPPRESS_TERMINAL_POINTER_MOVE]) {
438
+ if (e[SUPPRESS_TERMINAL_POINTER_MOVE])
619
439
  return;
620
- }
621
440
  lastPointerMoveEvent = e;
622
- const { cellX, cellY } = toCell(e.clientX, e.clientY);
623
- record?.({
441
+ let { cellX, cellY } = toCell(e.clientX, e.clientY);
442
+ if (record?.({
624
443
  type: "pointermove",
625
444
  cellX,
626
445
  cellY,
@@ -632,25 +451,21 @@ function createEventManager(container, metrics, options) {
632
451
  shiftKey: e.shiftKey,
633
452
  altKey: e.altKey,
634
453
  metaKey: e.metaKey
635
- });
636
- if (capturedId) {
637
- const target2 = nodes.get(capturedId) ?? null;
454
+ }), capturedId) {
455
+ let target2 = nodes.get(capturedId) ?? null;
638
456
  if (!target2)
639
457
  return;
640
458
  updateHover(target2, e);
641
- const path = ancestorsForTarget(target2);
642
- const ev = buildPointerEvent("pointermove", path, e);
459
+ let path = ancestorsForTarget(target2), ev = buildPointerEvent("pointermove", path, e);
643
460
  dispatchWithPhases("pointermove", path, target2, ev);
644
461
  return;
645
462
  }
646
- const list = candidatesAt(cellX, cellY);
647
- const target = pickTarget(list);
648
- updateHover(target, e);
649
- dispatchPointer("pointermove", e, target);
463
+ let list = candidatesAt(cellX, cellY), target = pickTarget(list);
464
+ updateHover(target, e), dispatchPointer("pointermove", e, target);
650
465
  }
651
466
  function onPointerUp(e) {
652
- const { cellX, cellY } = toCell(e.clientX, e.clientY);
653
- record?.({
467
+ let { cellX, cellY } = toCell(e.clientX, e.clientY);
468
+ if (record?.({
654
469
  type: "pointerup",
655
470
  cellX,
656
471
  cellY,
@@ -662,25 +477,19 @@ function createEventManager(container, metrics, options) {
662
477
  shiftKey: e.shiftKey,
663
478
  altKey: e.altKey,
664
479
  metaKey: e.metaKey
665
- });
666
- if (e[SUPPRESS_TERMINAL_POINTER_UP]) {
667
- capturedId = null;
668
- container.style.userSelect = defaultUserSelect;
480
+ }), e[SUPPRESS_TERMINAL_POINTER_UP]) {
481
+ capturedId = null, container.style.userSelect = defaultUserSelect;
669
482
  return;
670
483
  }
671
484
  if (capturedId) {
672
- const target = nodes.get(capturedId) ?? null;
673
- const path = target ? ancestorsForTarget(target) : [];
674
- const ev = buildPointerEvent("pointerup", path, e);
485
+ let target = nodes.get(capturedId) ?? null, path = target ? ancestorsForTarget(target) : [], ev = buildPointerEvent("pointerup", path, e);
675
486
  dispatchWithPhases("pointerup", path, target, ev);
676
- } else {
487
+ } else
677
488
  dispatchPointer("pointerup", e);
678
- }
679
- capturedId = null;
680
- container.style.userSelect = defaultUserSelect;
489
+ capturedId = null, container.style.userSelect = defaultUserSelect;
681
490
  }
682
491
  function onClick(e) {
683
- const { cellX, cellY } = toCell(e.clientX, e.clientY);
492
+ let { cellX, cellY } = toCell(e.clientX, e.clientY);
684
493
  record?.({
685
494
  type: "click",
686
495
  cellX,
@@ -693,11 +502,10 @@ function createEventManager(container, metrics, options) {
693
502
  shiftKey: e.shiftKey,
694
503
  altKey: e.altKey,
695
504
  metaKey: e.metaKey
696
- });
697
- dispatchPointer("click", e);
505
+ }), dispatchPointer("click", e);
698
506
  }
699
507
  function onDblClick(e) {
700
- const { cellX, cellY } = toCell(e.clientX, e.clientY);
508
+ let { cellX, cellY } = toCell(e.clientX, e.clientY);
701
509
  record?.({
702
510
  type: "dblclick",
703
511
  cellX,
@@ -710,11 +518,10 @@ function createEventManager(container, metrics, options) {
710
518
  shiftKey: e.shiftKey,
711
519
  altKey: e.altKey,
712
520
  metaKey: e.metaKey
713
- });
714
- dispatchPointer("dblclick", e);
521
+ }), dispatchPointer("dblclick", e);
715
522
  }
716
523
  function onContextMenu(e) {
717
- const { cellX, cellY } = toCell(e.clientX, e.clientY);
524
+ let { cellX, cellY } = toCell(e.clientX, e.clientY);
718
525
  record?.({
719
526
  type: "contextmenu",
720
527
  cellX,
@@ -728,20 +535,12 @@ function createEventManager(container, metrics, options) {
728
535
  altKey: e.altKey,
729
536
  metaKey: e.metaKey
730
537
  });
731
- const list = candidatesAt(cellX, cellY);
732
- const target = pickTarget(list);
733
- const path = target ? ancestorsForTarget(target) : [];
734
- const ev = buildPointerEvent("contextmenu", path, e);
735
- dispatchWithPhases("contextmenu", path, target, ev);
736
- if (ev.defaultPrevented)
737
- e.preventDefault();
538
+ let list = candidatesAt(cellX, cellY), target = pickTarget(list), path = target ? ancestorsForTarget(target) : [], ev = buildPointerEvent("contextmenu", path, e);
539
+ dispatchWithPhases("contextmenu", path, target, ev), ev.defaultPrevented && e.preventDefault();
738
540
  }
739
541
  function onWheel(e) {
740
- const { cellX, cellY } = toCell(e.clientX, e.clientY);
741
- const list = candidatesAt(cellX, cellY);
742
- if (list.length > 0)
743
- e.preventDefault();
744
- record?.({
542
+ let { cellX, cellY } = toCell(e.clientX, e.clientY);
543
+ candidatesAt(cellX, cellY).length > 0 && e.preventDefault(), record?.({
745
544
  type: "wheel",
746
545
  cellX,
747
546
  cellY,
@@ -753,20 +552,12 @@ function createEventManager(container, metrics, options) {
753
552
  altKey: e.altKey,
754
553
  metaKey: e.metaKey,
755
554
  deltaMode: e.deltaMode
756
- });
757
- dispatchPointer("wheel", e);
555
+ }), dispatchPointer("wheel", e);
758
556
  }
759
557
  function onKeyDown(e) {
760
- const targetIsTextInput = Boolean(
761
- textInputTarget && (e.target === textInputTarget || e.target instanceof Node && textInputTarget.contains(e.target))
762
- );
763
- if (targetIsTextInput) {
764
- const anyNative = e;
765
- const isComposing = Boolean(anyNative.isComposing);
766
- const keyCode = typeof anyNative.keyCode === "number" ? anyNative.keyCode : void 0;
767
- const key = e.key;
768
- const isImeKey = domComposing || isComposing || key === "Process" || key === "Unidentified" || keyCode === 229;
769
- if (isImeKey) {
558
+ if (!!(textInputTarget && (e.target === textInputTarget || e.target instanceof Node && textInputTarget.contains(e.target)))) {
559
+ let anyNative = e, isComposing = !!anyNative.isComposing, keyCode = typeof anyNative.keyCode == "number" ? anyNative.keyCode : void 0, key = e.key;
560
+ if (domComposing || isComposing || key === "Process" || key === "Unidentified" || keyCode === 229) {
770
561
  imeLog("keydown ignored (ime composing)", {
771
562
  key,
772
563
  code: e.code,
@@ -777,8 +568,7 @@ function createEventManager(container, metrics, options) {
777
568
  });
778
569
  return;
779
570
  }
780
- const isPlainTextKey = key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
781
- if (isPlainTextKey) {
571
+ if (key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
782
572
  imeLog("keydown ignored (textInput)", {
783
573
  key,
784
574
  code: e.code,
@@ -799,20 +589,12 @@ function createEventManager(container, metrics, options) {
799
589
  altKey: e.altKey,
800
590
  metaKey: e.metaKey,
801
591
  repeat: e.repeat
802
- });
803
- dispatchToFocused("keydown", e);
592
+ }), dispatchToFocused("keydown", e);
804
593
  }
805
594
  function onKeyUp(e) {
806
- const targetIsTextInput = Boolean(
807
- textInputTarget && (e.target === textInputTarget || e.target instanceof Node && textInputTarget.contains(e.target))
808
- );
809
- if (targetIsTextInput) {
810
- const anyNative = e;
811
- const isComposing = Boolean(anyNative.isComposing);
812
- const keyCode = typeof anyNative.keyCode === "number" ? anyNative.keyCode : void 0;
813
- const key = e.key;
814
- const isImeKey = domComposing || isComposing || key === "Process" || key === "Unidentified" || keyCode === 229;
815
- if (isImeKey) {
595
+ if (!!(textInputTarget && (e.target === textInputTarget || e.target instanceof Node && textInputTarget.contains(e.target)))) {
596
+ let anyNative = e, isComposing = !!anyNative.isComposing, keyCode = typeof anyNative.keyCode == "number" ? anyNative.keyCode : void 0, key = e.key;
597
+ if (domComposing || isComposing || key === "Process" || key === "Unidentified" || keyCode === 229) {
816
598
  imeLog("keyup ignored (ime composing)", {
817
599
  key,
818
600
  code: e.code,
@@ -823,8 +605,7 @@ function createEventManager(container, metrics, options) {
823
605
  });
824
606
  return;
825
607
  }
826
- const isPlainTextKey = key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
827
- if (isPlainTextKey) {
608
+ if (key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
828
609
  imeLog("keyup ignored (textInput)", {
829
610
  key,
830
611
  code: e.code,
@@ -845,110 +626,85 @@ function createEventManager(container, metrics, options) {
845
626
  altKey: e.altKey,
846
627
  metaKey: e.metaKey,
847
628
  repeat: e.repeat
848
- });
849
- dispatchToFocused("keyup", e);
629
+ }), dispatchToFocused("keyup", e);
850
630
  }
851
631
  function onBeforeInput(e) {
852
- const anyNative = e;
853
- if (anyNative && typeof anyNative.isComposing === "boolean")
854
- domComposing = anyNative.isComposing;
855
- const targetIsTextInput = Boolean(
856
- textInputTarget && (e.target === textInputTarget || e.target instanceof Node && textInputTarget.contains(e.target))
857
- );
858
- const data = typeof anyNative.data === "string" ? anyNative.data : void 0;
859
- const inputType = typeof anyNative.inputType === "string" ? anyNative.inputType : void 0;
860
- const isPasteLike = inputType === "insertFromPaste" || inputType === "insertFromDrop";
632
+ let anyNative = e;
633
+ anyNative && typeof anyNative.isComposing == "boolean" && (domComposing = anyNative.isComposing);
634
+ let targetIsTextInput = !!(textInputTarget && (e.target === textInputTarget || e.target instanceof Node && textInputTarget.contains(e.target))), data = typeof anyNative.data == "string" ? anyNative.data : void 0, inputType = typeof anyNative.inputType == "string" ? anyNative.inputType : void 0, isPasteLike = inputType === "insertFromPaste" || inputType === "insertFromDrop";
861
635
  if (targetIsTextInput && isPasteLike) {
862
- anyNative?.preventDefault?.();
863
- e?.preventDefault?.();
636
+ anyNative?.preventDefault?.(), e?.preventDefault?.();
864
637
  return;
865
638
  }
866
- const isLineBreakLike = inputType === "insertLineBreak" || inputType === "insertParagraph" || data?.includes("\n") && !isPasteLike;
639
+ let isLineBreakLike = inputType === "insertLineBreak" || inputType === "insertParagraph" || data?.includes(`
640
+ `) && !isPasteLike;
867
641
  if (targetIsTextInput && isLineBreakLike) {
868
- anyNative?.preventDefault?.();
869
- e?.preventDefault?.();
642
+ anyNative?.preventDefault?.(), e?.preventDefault?.();
870
643
  return;
871
644
  }
872
645
  record?.({
873
646
  type: "beforeinput",
874
647
  data,
875
648
  inputType,
876
- isComposing: Boolean(anyNative.isComposing)
877
- });
878
- dispatchToFocusedText("beforeinput", e);
649
+ isComposing: !!anyNative.isComposing
650
+ }), dispatchToFocusedText("beforeinput", e);
879
651
  }
880
652
  function onInput(e) {
881
- const anyNative = e;
882
- if (anyNative && typeof anyNative.isComposing === "boolean")
883
- domComposing = anyNative.isComposing;
884
- const targetIsTextInput = Boolean(
885
- textInputTarget && (e.target === textInputTarget || e.target instanceof Node && textInputTarget.contains(e.target))
886
- );
887
- const data = typeof anyNative.data === "string" ? anyNative.data : void 0;
888
- const inputType = typeof anyNative.inputType === "string" ? anyNative.inputType : void 0;
889
- const isPasteLike = inputType === "insertFromPaste" || inputType === "insertFromDrop";
653
+ let anyNative = e;
654
+ anyNative && typeof anyNative.isComposing == "boolean" && (domComposing = anyNative.isComposing);
655
+ let targetIsTextInput = !!(textInputTarget && (e.target === textInputTarget || e.target instanceof Node && textInputTarget.contains(e.target))), data = typeof anyNative.data == "string" ? anyNative.data : void 0, inputType = typeof anyNative.inputType == "string" ? anyNative.inputType : void 0, isPasteLike = inputType === "insertFromPaste" || inputType === "insertFromDrop";
890
656
  if (targetIsTextInput && isPasteLike) {
891
- anyNative?.preventDefault?.();
892
- e?.preventDefault?.();
657
+ anyNative?.preventDefault?.(), e?.preventDefault?.();
893
658
  return;
894
659
  }
895
- const isLineBreakLike = inputType === "insertLineBreak" || inputType === "insertParagraph" || data?.includes("\n") && !isPasteLike;
660
+ let isLineBreakLike = inputType === "insertLineBreak" || inputType === "insertParagraph" || data?.includes(`
661
+ `) && !isPasteLike;
896
662
  if (targetIsTextInput && isLineBreakLike) {
897
- anyNative?.preventDefault?.();
898
- e?.preventDefault?.();
663
+ anyNative?.preventDefault?.(), e?.preventDefault?.();
899
664
  return;
900
665
  }
901
666
  record?.({
902
667
  type: "input",
903
668
  data,
904
669
  inputType,
905
- isComposing: Boolean(anyNative.isComposing)
906
- });
907
- dispatchToFocusedText("input", e);
670
+ isComposing: !!anyNative.isComposing
671
+ }), dispatchToFocusedText("input", e);
908
672
  }
909
673
  function onCompositionStart(e) {
910
- const anyNative = e;
911
- domComposing = true;
912
- record?.({
674
+ let anyNative = e;
675
+ domComposing = !0, record?.({
913
676
  type: "compositionstart",
914
- data: typeof anyNative.data === "string" ? anyNative.data : void 0,
915
- isComposing: Boolean(anyNative.isComposing)
916
- });
917
- imeLog("compositionstart", {
918
- data: typeof anyNative.data === "string" ? anyNative.data : void 0,
919
- isComposing: Boolean(anyNative.isComposing),
677
+ data: typeof anyNative.data == "string" ? anyNative.data : void 0,
678
+ isComposing: !!anyNative.isComposing
679
+ }), imeLog("compositionstart", {
680
+ data: typeof anyNative.data == "string" ? anyNative.data : void 0,
681
+ isComposing: !!anyNative.isComposing,
920
682
  focusedId
921
- });
922
- dispatchToFocusedText("compositionstart", e);
683
+ }), dispatchToFocusedText("compositionstart", e);
923
684
  }
924
685
  function onCompositionUpdate(e) {
925
- const anyNative = e;
686
+ let anyNative = e;
926
687
  record?.({
927
688
  type: "compositionupdate",
928
- data: typeof anyNative.data === "string" ? anyNative.data : void 0,
929
- isComposing: Boolean(anyNative.isComposing)
930
- });
931
- imeLog("compositionupdate", {
932
- data: typeof anyNative.data === "string" ? anyNative.data : void 0,
933
- isComposing: Boolean(anyNative.isComposing),
689
+ data: typeof anyNative.data == "string" ? anyNative.data : void 0,
690
+ isComposing: !!anyNative.isComposing
691
+ }), imeLog("compositionupdate", {
692
+ data: typeof anyNative.data == "string" ? anyNative.data : void 0,
693
+ isComposing: !!anyNative.isComposing,
934
694
  focusedId
935
- });
936
- dispatchToFocusedText("compositionupdate", e);
695
+ }), dispatchToFocusedText("compositionupdate", e);
937
696
  }
938
697
  function onCompositionEnd(e) {
939
- const anyNative = e;
940
- domComposing = false;
941
- record?.({
698
+ let anyNative = e;
699
+ domComposing = !1, record?.({
942
700
  type: "compositionend",
943
- data: typeof anyNative.data === "string" ? anyNative.data : void 0,
944
- isComposing: Boolean(anyNative.isComposing)
945
- });
946
- imeLog("compositionend", {
947
- data: typeof anyNative.data === "string" ? anyNative.data : void 0,
948
- isComposing: Boolean(anyNative.isComposing),
701
+ data: typeof anyNative.data == "string" ? anyNative.data : void 0,
702
+ isComposing: !!anyNative.isComposing
703
+ }), imeLog("compositionend", {
704
+ data: typeof anyNative.data == "string" ? anyNative.data : void 0,
705
+ isComposing: !!anyNative.isComposing,
949
706
  focusedId
950
- });
951
- dispatchToFocusedText("compositionend", e);
707
+ }), dispatchToFocusedText("compositionend", e);
952
708
  }
953
709
  function onDragOver(e) {
954
710
  e.preventDefault();
@@ -956,153 +712,88 @@ function createEventManager(container, metrics, options) {
956
712
  function onDrop(e) {
957
713
  e.preventDefault();
958
714
  let text = "";
959
- if (e.dataTransfer) {
960
- if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
961
- const files = Array.from(e.dataTransfer.files);
962
- const paths = files.map((file) => String(file?.path || file?.name || "").trim()).filter(Boolean);
963
- text = paths.join("\n");
964
- } else if (e.dataTransfer.types.includes("text/plain")) {
965
- text = e.dataTransfer.getData("text/plain");
966
- }
967
- }
968
- if (text) {
969
- record?.({
715
+ if (e.dataTransfer && (e.dataTransfer.files && e.dataTransfer.files.length > 0 ? text = Array.from(e.dataTransfer.files).map((file) => String(file?.path || file?.name || "").trim()).filter(Boolean).join(`
716
+ `) : e.dataTransfer.types.includes("text/plain") && (text = e.dataTransfer.getData("text/plain"))), text) {
717
+ if (record?.({
970
718
  type: "paste",
971
719
  text
972
- });
973
- if (textInputTarget) {
720
+ }), textInputTarget)
974
721
  try {
975
- textInputTarget.focus?.({ preventScroll: true });
722
+ textInputTarget.focus?.({ preventScroll: !0 });
976
723
  } catch {
977
724
  textInputTarget.focus?.();
978
725
  }
979
- } else {
726
+ else
980
727
  try {
981
- container.focus?.({ preventScroll: true });
728
+ container.focus?.({ preventScroll: !0 });
982
729
  } catch {
983
730
  container.focus?.();
984
731
  }
985
- }
986
- const focusableNodes = Array.from(nodes.values()).filter((n) => n.focusable && isVisible(n));
732
+ let focusableNodes = Array.from(nodes.values()).filter((n) => n.focusable && isVisible(n));
987
733
  if (focusableNodes.length > 0) {
988
- const targetNode = focusableNodes[0];
734
+ let targetNode = focusableNodes[0];
989
735
  setFocus(targetNode.id);
990
- const path = targetNode ? ancestorsForTarget(targetNode) : [];
991
- const ev = buildInputEvent("paste", path, e);
992
- ev.text = text;
993
- dispatchWithPhases("paste", path, targetNode, ev);
736
+ let path = targetNode ? ancestorsForTarget(targetNode) : [], ev = buildInputEvent("paste", path, e);
737
+ ev.text = text, dispatchWithPhases("paste", path, targetNode, ev);
994
738
  }
995
739
  }
996
740
  }
997
741
  function onPaste(e) {
998
- const anyNative = e;
999
- const clipboard = anyNative.clipboardData;
1000
- let text = "";
742
+ let anyNative = e, clipboard = anyNative.clipboardData, text = "";
1001
743
  if (clipboard?.files && clipboard.files.length > 0) {
1002
- const file = clipboard.files[0];
744
+ let file = clipboard.files[0];
1003
745
  text = file.path || file.name;
1004
- } else if (clipboard?.getData) {
1005
- text = clipboard.getData("text/plain") || clipboard.getData("text") || "";
1006
- }
1007
- record?.({
746
+ } else
747
+ clipboard?.getData && (text = clipboard.getData("text/plain") || clipboard.getData("text") || "");
748
+ if (record?.({
1008
749
  type: "paste",
1009
750
  text
1010
- });
1011
- if (focusedId) {
1012
- const targetNode = nodes.get(focusedId);
751
+ }), focusedId) {
752
+ let targetNode = nodes.get(focusedId);
1013
753
  if (targetNode) {
1014
- const path = ancestorsForTarget(targetNode);
1015
- const ev = buildInputEvent("paste", path, e);
1016
- ev.text = text;
1017
- dispatchWithPhases("paste", path, targetNode, ev);
1018
- if (ev.defaultPrevented) {
1019
- anyNative?.preventDefault?.();
1020
- e?.preventDefault?.();
1021
- }
754
+ let path = ancestorsForTarget(targetNode), ev = buildInputEvent("paste", path, e);
755
+ ev.text = text, dispatchWithPhases("paste", path, targetNode, ev), ev.defaultPrevented && (anyNative?.preventDefault?.(), e?.preventDefault?.());
1022
756
  }
1023
757
  }
1024
758
  }
1025
- const textTargets = [container];
1026
- if (textInputTarget && textInputTarget !== container && !container.contains(textInputTarget)) {
1027
- textTargets.push(textInputTarget);
1028
- }
1029
- const keyboardTargets = [container];
1030
- if (textInputTarget && textInputTarget !== container && !container.contains(textInputTarget)) {
1031
- keyboardTargets.push(textInputTarget);
1032
- }
1033
- let attached = false;
759
+ let textTargets = [container];
760
+ textInputTarget && textInputTarget !== container && !container.contains(textInputTarget) && textTargets.push(textInputTarget);
761
+ let keyboardTargets = [container];
762
+ textInputTarget && textInputTarget !== container && !container.contains(textInputTarget) && keyboardTargets.push(textInputTarget);
763
+ let attached = !1;
1034
764
  function attach() {
1035
- if (attached)
1036
- return;
1037
- attached = true;
1038
- container.addEventListener("pointerdown", onPointerDown);
1039
- container.addEventListener("pointermove", onPointerMove);
1040
- container.addEventListener("pointerup", onPointerUp);
1041
- container.addEventListener("mousedown", onMouseDown);
1042
- container.addEventListener("mousemove", onMouseMove);
1043
- container.addEventListener("mouseup", onMouseUp);
1044
- container.addEventListener("mouseleave", onMouseLeave);
1045
- container.addEventListener("click", onClick);
1046
- container.addEventListener("dblclick", onDblClick);
1047
- container.addEventListener("contextmenu", onContextMenu);
1048
- container.addEventListener("wheel", onWheel, { passive: false });
1049
- container.addEventListener("dragover", onDragOver);
1050
- container.addEventListener("drop", onDrop);
1051
- for (const target of keyboardTargets) {
1052
- target.addEventListener("keydown", onKeyDown);
1053
- target.addEventListener("keyup", onKeyUp);
1054
- }
1055
- for (const target of textTargets) {
1056
- target.addEventListener("beforeinput", onBeforeInput);
1057
- target.addEventListener("input", onInput);
1058
- target.addEventListener("compositionstart", onCompositionStart);
1059
- target.addEventListener("compositionupdate", onCompositionUpdate);
1060
- target.addEventListener("compositionend", onCompositionEnd);
1061
- target.addEventListener("paste", onPaste);
765
+ if (!attached) {
766
+ attached = !0, container.addEventListener("pointerdown", onPointerDown), container.addEventListener("pointermove", onPointerMove), container.addEventListener("pointerup", onPointerUp), container.addEventListener("mousedown", onMouseDown), container.addEventListener("mousemove", onMouseMove), container.addEventListener("mouseup", onMouseUp), container.addEventListener("mouseleave", onMouseLeave), container.addEventListener("click", onClick), container.addEventListener("dblclick", onDblClick), container.addEventListener("contextmenu", onContextMenu), container.addEventListener("wheel", onWheel, { passive: !1 }), container.addEventListener("dragover", onDragOver), container.addEventListener("drop", onDrop);
767
+ for (let target of keyboardTargets)
768
+ target.addEventListener("keydown", onKeyDown), target.addEventListener("keyup", onKeyUp);
769
+ for (let target of textTargets)
770
+ target.addEventListener("beforeinput", onBeforeInput), target.addEventListener("input", onInput), target.addEventListener("compositionstart", onCompositionStart), target.addEventListener("compositionupdate", onCompositionUpdate), target.addEventListener("compositionend", onCompositionEnd), target.addEventListener("paste", onPaste);
771
+ window.addEventListener("scroll", markContainerRectDirty, {
772
+ capture: !0,
773
+ passive: !0
774
+ }), window.addEventListener("resize", markContainerRectDirty, { passive: !0 });
1062
775
  }
1063
- window.addEventListener("scroll", markContainerRectDirty, {
1064
- capture: true,
1065
- passive: true
1066
- });
1067
- window.addEventListener("resize", markContainerRectDirty, { passive: true });
1068
- }
1069
- if (!options?.deferAttach) {
1070
- attach();
1071
776
  }
1072
- return {
777
+ return options?.deferAttach || attach(), {
1073
778
  register(node) {
1074
- const id = node.id ?? `n${nextId++}`;
1075
- const focusable = node.focusable;
1076
- const full = {
779
+ let id = node.id ?? `n${nextId++}`, focusable = node.focusable, full = {
1077
780
  id,
1078
781
  rect: node.rect,
1079
782
  zIndex: node.zIndex ?? 0,
1080
- visible: node.visible ?? true,
783
+ visible: node.visible ?? !0,
1081
784
  focusable,
1082
785
  selectable: node.selectable ?? !focusable,
1083
786
  selectionScrollBy: node.selectionScrollBy,
1084
787
  handlers: node.handlers ?? {}
1085
788
  };
1086
- if (nodes.has(id))
1087
- removeFromRowBuckets(id);
1088
- nodes.set(id, full);
1089
- addToRowBuckets(id, full);
1090
- return full;
789
+ return nodes.has(id) && removeFromRowBuckets(id), nodes.set(id, full), addToRowBuckets(id, full), full;
1091
790
  },
1092
791
  update(id, next) {
1093
- const prev = nodes.get(id);
792
+ let prev = nodes.get(id);
1094
793
  if (!prev)
1095
794
  return;
1096
- const nextVisible = next.visible ?? prev.visible;
1097
- if (nextVisible === false) {
1098
- if (focusedId === id)
1099
- setFocus(null);
1100
- if (capturedId === id)
1101
- capturedId = null;
1102
- if (hoverPath.some((n) => n.id === id))
1103
- hoverPath = [];
1104
- }
1105
- nodes.set(id, {
795
+ let nextVisible = next.visible ?? prev.visible;
796
+ nextVisible === !1 && (focusedId === id && setFocus(null), capturedId === id && (capturedId = null), hoverPath.some((n) => n.id === id) && (hoverPath = [])), nodes.set(id, {
1106
797
  ...prev,
1107
798
  ...next,
1108
799
  rect: next.rect ?? prev.rect,
@@ -1110,65 +801,38 @@ function createEventManager(container, metrics, options) {
1110
801
  visible: nextVisible,
1111
802
  handlers: next.handlers ?? prev.handlers
1112
803
  });
1113
- const updated = nodes.get(id);
1114
- if (updated)
1115
- updateRowBuckets(id, updated);
804
+ let updated = nodes.get(id);
805
+ updated && updateRowBuckets(id, updated);
1116
806
  },
1117
807
  unregister(id) {
1118
- if (capturedId === id)
1119
- capturedId = null;
1120
- if (hoverPath.some((n) => n.id === id))
1121
- hoverPath = [];
1122
- removeFromRowBuckets(id);
1123
- nodes.delete(id);
1124
- if (focusedId === id)
1125
- setFocus(null);
808
+ capturedId === id && (capturedId = null), hoverPath.some((n) => n.id === id) && (hoverPath = []), removeFromRowBuckets(id), nodes.delete(id), focusedId === id && setFocus(null);
1126
809
  },
1127
810
  setMetrics(next) {
1128
- currentMetrics = next;
1129
- markContainerRectDirty();
811
+ currentMetrics = next, markContainerRectDirty();
1130
812
  },
1131
813
  canSelectAt(cellX, cellY) {
1132
- const list = candidatesAt(cellX, cellY);
1133
- const target = pickTarget(list);
1134
- const lockNode = resolveModalLockNode();
1135
- if (lockNode) {
1136
- if (!target)
1137
- return false;
1138
- if (!isAllowedModalPointerNode(target, target, lockNode))
1139
- return false;
1140
- }
1141
- return target ? Boolean(target.selectable) : true;
814
+ let list = candidatesAt(cellX, cellY), target = pickTarget(list), lockNode = resolveModalLockNode();
815
+ return lockNode && (!target || !isAllowedModalPointerNode(target, target, lockNode)) ? !1 : target ? !!target.selectable : !0;
1142
816
  },
1143
817
  autoScrollSelectionAt(originCellX, originCellY, pointerCellY) {
1144
- const target = pickTarget(candidatesAt(originCellX, originCellY));
818
+ let target = pickTarget(candidatesAt(originCellX, originCellY));
1145
819
  if (!target)
1146
820
  return 0;
1147
- const lockNode = resolveModalLockNode();
821
+ let lockNode = resolveModalLockNode();
1148
822
  if (lockNode && !isAllowedModalPointerNode(target, target, lockNode))
1149
823
  return 0;
1150
- const path = ancestorsForTarget(target);
1151
- let owner = null;
824
+ let path = ancestorsForTarget(target), owner = null;
1152
825
  for (let i = path.length - 1; i >= 0; i--) {
1153
- const node = path[i];
1154
- if (typeof node.selectionScrollBy === "function") {
826
+ let node = path[i];
827
+ if (typeof node.selectionScrollBy == "function") {
1155
828
  owner = node;
1156
829
  break;
1157
830
  }
1158
831
  }
1159
832
  if (!owner)
1160
833
  return 0;
1161
- const rect = owner.rect;
1162
- const y = Math.floor(pointerCellY);
1163
- let delta = 0;
1164
- if (y <= rect.y)
1165
- delta = -1;
1166
- else if (y >= rect.y + rect.h - 1)
1167
- delta = 1;
1168
- if (!delta)
1169
- return 0;
1170
- const scrolled = owner.selectionScrollBy?.(delta);
1171
- return scrolled === false ? 0 : delta;
834
+ let rect = owner.rect, y = Math.floor(pointerCellY), delta = 0;
835
+ return y <= rect.y ? delta = -1 : y >= rect.y + rect.h - 1 && (delta = 1), delta ? owner.selectionScrollBy?.(delta) === !1 ? 0 : delta : 0;
1172
836
  },
1173
837
  focus(id) {
1174
838
  setFocus(id);
@@ -1182,65 +846,35 @@ function createEventManager(container, metrics, options) {
1182
846
  rect: n.rect,
1183
847
  zIndex: n.zIndex,
1184
848
  visible: isVisible(n),
1185
- focusable: Boolean(n.focusable)
849
+ focusable: !!n.focusable
1186
850
  }));
1187
851
  },
1188
852
  attach,
1189
853
  dispose() {
1190
- window.removeEventListener("scroll", markContainerRectDirty, true);
1191
- window.removeEventListener("resize", markContainerRectDirty);
1192
- if (!attached)
1193
- return;
1194
- attached = false;
1195
- container.removeEventListener("pointerdown", onPointerDown);
1196
- container.removeEventListener("pointermove", onPointerMove);
1197
- container.removeEventListener("pointerup", onPointerUp);
1198
- container.removeEventListener("mousedown", onMouseDown);
1199
- container.removeEventListener("mousemove", onMouseMove);
1200
- container.removeEventListener("mouseup", onMouseUp);
1201
- container.removeEventListener("mouseleave", onMouseLeave);
1202
- container.removeEventListener("click", onClick);
1203
- container.removeEventListener("dblclick", onDblClick);
1204
- container.removeEventListener("contextmenu", onContextMenu);
1205
- container.removeEventListener("wheel", onWheel);
1206
- for (const target of keyboardTargets) {
1207
- target.removeEventListener("keydown", onKeyDown);
1208
- target.removeEventListener("keyup", onKeyUp);
1209
- }
1210
- for (const target of textTargets) {
1211
- target.removeEventListener("beforeinput", onBeforeInput);
1212
- target.removeEventListener("input", onInput);
1213
- target.removeEventListener("compositionstart", onCompositionStart);
1214
- target.removeEventListener("compositionupdate", onCompositionUpdate);
1215
- target.removeEventListener("compositionend", onCompositionEnd);
1216
- target.removeEventListener("paste", onPaste);
854
+ if (window.removeEventListener("scroll", markContainerRectDirty, !0), window.removeEventListener("resize", markContainerRectDirty), !!attached) {
855
+ attached = !1, container.removeEventListener("pointerdown", onPointerDown), container.removeEventListener("pointermove", onPointerMove), container.removeEventListener("pointerup", onPointerUp), container.removeEventListener("mousedown", onMouseDown), container.removeEventListener("mousemove", onMouseMove), container.removeEventListener("mouseup", onMouseUp), container.removeEventListener("mouseleave", onMouseLeave), container.removeEventListener("click", onClick), container.removeEventListener("dblclick", onDblClick), container.removeEventListener("contextmenu", onContextMenu), container.removeEventListener("wheel", onWheel);
856
+ for (let target of keyboardTargets)
857
+ target.removeEventListener("keydown", onKeyDown), target.removeEventListener("keyup", onKeyUp);
858
+ for (let target of textTargets)
859
+ target.removeEventListener("beforeinput", onBeforeInput), target.removeEventListener("input", onInput), target.removeEventListener("compositionstart", onCompositionStart), target.removeEventListener("compositionupdate", onCompositionUpdate), target.removeEventListener("compositionend", onCompositionEnd), target.removeEventListener("paste", onPaste);
860
+ rowBuckets.clear(), rowRangeById.clear(), nodes.clear(), focusedId = null, capturedId = null, hoverPath = [];
1217
861
  }
1218
- rowBuckets.clear();
1219
- rowRangeById.clear();
1220
- nodes.clear();
1221
- focusedId = null;
1222
- capturedId = null;
1223
- hoverPath = [];
1224
862
  }
1225
863
  };
1226
864
  }
1227
865
 
1228
866
  // src/runtime/index.ts
1229
867
  function isNodeLike() {
1230
- const proc = globalThis.process;
1231
- return typeof proc?.versions?.node === "string";
868
+ return typeof globalThis.process?.versions?.node == "string";
1232
869
  }
1233
870
  function detectEnv() {
1234
- const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
1235
- if (isBrowser)
1236
- return "browser";
1237
- if (isNodeLike())
1238
- return "terminal";
1239
- return "unknown";
871
+ return typeof window < "u" && typeof document < "u" ? "browser" : isNodeLike() ? "terminal" : "unknown";
1240
872
  }
1241
873
  function createUnsupportedClipboard() {
1242
874
  return {
1243
- supported: false,
875
+ supported: !1,
876
+ canRead: !1,
877
+ canWrite: !1,
1244
878
  async readText() {
1245
879
  throw new Error("Clipboard not available in this runtime");
1246
880
  },
@@ -1249,37 +883,44 @@ function createUnsupportedClipboard() {
1249
883
  }
1250
884
  };
1251
885
  }
886
+ function browserClipboard() {
887
+ return typeof navigator < "u" ? navigator.clipboard : void 0;
888
+ }
1252
889
  function createClipboard(kind) {
1253
- if (kind === "browser") {
1254
- const supported = typeof navigator !== "undefined" && !!navigator.clipboard?.writeText && !!navigator.clipboard?.readText;
1255
- return {
1256
- supported,
1257
- async readText() {
1258
- if (!supported)
1259
- throw new Error("Clipboard not available in this runtime");
1260
- return navigator.clipboard.readText();
1261
- },
1262
- async writeText(text) {
1263
- if (!supported)
1264
- throw new Error("Clipboard not available in this runtime");
1265
- await navigator.clipboard.writeText(text);
1266
- }
1267
- };
1268
- }
1269
- return createUnsupportedClipboard();
890
+ return kind !== "browser" ? createUnsupportedClipboard() : {
891
+ get supported() {
892
+ let clipboard = browserClipboard();
893
+ return typeof clipboard?.readText == "function" && typeof clipboard?.writeText == "function";
894
+ },
895
+ get canRead() {
896
+ return typeof browserClipboard()?.readText == "function";
897
+ },
898
+ get canWrite() {
899
+ return typeof browserClipboard()?.writeText == "function";
900
+ },
901
+ async readText() {
902
+ let clipboard = browserClipboard();
903
+ if (typeof clipboard?.readText != "function")
904
+ throw new Error("Clipboard read not available in this runtime");
905
+ return clipboard.readText();
906
+ },
907
+ async writeText(text) {
908
+ let clipboard = browserClipboard();
909
+ if (typeof clipboard?.writeText != "function")
910
+ throw new Error("Clipboard write not available in this runtime");
911
+ await clipboard.writeText(text);
912
+ }
913
+ };
1270
914
  }
1271
915
  function nowMs() {
1272
- return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
916
+ return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
1273
917
  }
1274
918
  function createRaf(kind, timer) {
1275
- const g = globalThis;
1276
- if (kind === "browser" && typeof g.requestAnimationFrame === "function" && typeof g.cancelAnimationFrame === "function") {
1277
- return {
1278
- request: (cb) => g.requestAnimationFrame(cb),
1279
- cancel: (id) => g.cancelAnimationFrame(id)
1280
- };
1281
- }
1282
- return {
919
+ let g = globalThis;
920
+ return kind === "browser" && typeof g.requestAnimationFrame == "function" && typeof g.cancelAnimationFrame == "function" ? {
921
+ request: (cb) => g.requestAnimationFrame(cb),
922
+ cancel: (id) => g.cancelAnimationFrame(id)
923
+ } : {
1283
924
  request(cb) {
1284
925
  return timer.setTimeout(() => cb(nowMs()), 16);
1285
926
  },
@@ -1289,34 +930,29 @@ function createRaf(kind, timer) {
1289
930
  };
1290
931
  }
1291
932
  function createMeasureText(kind) {
1292
- if (kind !== "browser")
1293
- return () => null;
1294
- return (text, opts) => {
933
+ return kind !== "browser" ? () => null : (text, opts) => {
1295
934
  try {
1296
- const doc = typeof document !== "undefined" ? document : null;
935
+ let doc = typeof document < "u" ? document : null;
1297
936
  if (!doc || !("createElement" in doc))
1298
937
  return null;
1299
- const canvas = doc.createElement("canvas");
1300
- const ctx = canvas?.getContext?.("2d");
938
+ let ctx = doc.createElement("canvas")?.getContext?.("2d");
1301
939
  if (!ctx)
1302
940
  return null;
1303
- if (opts?.font)
1304
- ctx.font = opts.font;
1305
- const m = ctx.measureText(text);
1306
- return typeof m.width === "number" && Number.isFinite(m.width) ? m.width : null;
941
+ opts?.font && (ctx.font = opts.font);
942
+ let m = ctx.measureText(text);
943
+ return typeof m.width == "number" && Number.isFinite(m.width) ? m.width : null;
1307
944
  } catch {
1308
945
  return null;
1309
946
  }
1310
947
  };
1311
948
  }
1312
949
  function createRuntime(kind = detectEnv(), options = {}) {
1313
- const timer = {
950
+ let timer = {
1314
951
  setTimeout: globalThis.setTimeout.bind(globalThis),
1315
952
  clearTimeout: globalThis.clearTimeout.bind(globalThis),
1316
953
  setInterval: globalThis.setInterval.bind(globalThis),
1317
954
  clearInterval: globalThis.clearInterval.bind(globalThis)
1318
- };
1319
- const env = Object.freeze({
955
+ }, env = Object.freeze({
1320
956
  kind,
1321
957
  isBrowser: kind === "browser",
1322
958
  isTerminal: kind === "terminal"
@@ -1330,23 +966,22 @@ function createRuntime(kind = detectEnv(), options = {}) {
1330
966
  raf: createRaf(kind, timer),
1331
967
  clipboard: options.clipboard ?? createClipboard(kind),
1332
968
  getWindow() {
1333
- return env.isBrowser && typeof window !== "undefined" ? window : null;
969
+ return env.isBrowser && typeof window < "u" ? window : null;
1334
970
  },
1335
971
  getDocument() {
1336
- return env.isBrowser && typeof document !== "undefined" ? document : null;
972
+ return env.isBrowser && typeof document < "u" ? document : null;
1337
973
  },
1338
974
  measureText: createMeasureText(kind)
1339
975
  };
1340
976
  }
1341
977
 
1342
978
  // src/selection/terminal-selection.ts
1343
- var import_vue = require("vue");
1344
- var EMPTY_STATE = Object.freeze({
1345
- active: false,
979
+ var import_vue = require("vue"), EMPTY_STATE = Object.freeze({
980
+ active: !1,
1346
981
  anchor: null,
1347
982
  focus: null,
1348
983
  text: "",
1349
- hasRange: false
984
+ hasRange: !1
1350
985
  });
1351
986
  function clampPoint(point, cols, rows) {
1352
987
  return {
@@ -1361,64 +996,50 @@ function pointKey(point) {
1361
996
  return `${point.x}:${point.y}`;
1362
997
  }
1363
998
  function providerPointsDiffer(a, b) {
1364
- return Boolean(
1365
- a && b && a.providerId === b.providerId && pointKey(a.point) !== pointKey(b.point)
1366
- );
999
+ return !!(a && b && a.providerId === b.providerId && pointKey(a.point) !== pointKey(b.point));
1367
1000
  }
1368
1001
  function terminalSelectionRowSpans(range, cols, rows) {
1369
1002
  if (cols <= 0 || rows <= 0)
1370
1003
  return [];
1371
- const anchor = clampPoint(range.anchor, cols, rows);
1372
- const focus = clampPoint(range.focus, cols, rows);
1004
+ let anchor = clampPoint(range.anchor, cols, rows), focus = clampPoint(range.focus, cols, rows);
1373
1005
  if (pointKey(anchor) === pointKey(focus))
1374
1006
  return [];
1375
- const start = comparePoints(anchor, focus) <= 0 ? anchor : focus;
1376
- const end = start === anchor ? focus : anchor;
1377
- const spans = [];
1007
+ let start = comparePoints(anchor, focus) <= 0 ? anchor : focus, end = start === anchor ? focus : anchor, spans = [];
1378
1008
  for (let y = start.y; y <= end.y; y++) {
1379
- const x0 = y === start.y ? start.x : 0;
1380
- const x1 = y === end.y ? end.x + 1 : cols;
1381
- if (x1 > x0)
1382
- spans.push({ y, x0, x1 });
1009
+ let x0 = y === start.y ? start.x : 0, x1 = y === end.y ? end.x + 1 : cols;
1010
+ x1 > x0 && spans.push({ y, x0, x1 });
1383
1011
  }
1384
1012
  return spans;
1385
1013
  }
1386
1014
  function terminalSelectionVisibleRowSpans(range, cols, rows, visibleStartY, visibleEndY) {
1387
1015
  if (cols <= 0 || rows <= 0)
1388
1016
  return [];
1389
- const anchor = clampPoint(range.anchor, cols, rows);
1390
- const focus = clampPoint(range.focus, cols, rows);
1017
+ let anchor = clampPoint(range.anchor, cols, rows), focus = clampPoint(range.focus, cols, rows);
1391
1018
  if (pointKey(anchor) === pointKey(focus))
1392
1019
  return [];
1393
- const start = comparePoints(anchor, focus) <= 0 ? anchor : focus;
1394
- const end = start === anchor ? focus : anchor;
1395
- const fromY = Math.max(start.y, Math.floor(visibleStartY), 0);
1396
- const toY = Math.min(end.y, Math.ceil(visibleEndY) - 1, rows - 1);
1020
+ let start = comparePoints(anchor, focus) <= 0 ? anchor : focus, end = start === anchor ? focus : anchor, fromY = Math.max(start.y, Math.floor(visibleStartY), 0), toY = Math.min(end.y, Math.ceil(visibleEndY) - 1, rows - 1);
1397
1021
  if (toY < fromY)
1398
1022
  return [];
1399
- const spans = [];
1023
+ let spans = [];
1400
1024
  for (let y = fromY; y <= toY; y++) {
1401
- const x0 = y === start.y ? start.x : 0;
1402
- const x1 = y === end.y ? end.x + 1 : cols;
1403
- if (x1 > x0)
1404
- spans.push({ y, x0, x1 });
1025
+ let x0 = y === start.y ? start.x : 0, x1 = y === end.y ? end.x + 1 : cols;
1026
+ x1 > x0 && spans.push({ y, x0, x1 });
1405
1027
  }
1406
1028
  return spans;
1407
1029
  }
1408
1030
  function selectedRowText(row, x0, x1, cols) {
1409
1031
  let out = "";
1410
1032
  for (let x = x0; x < x1; x++) {
1411
- const cell = row[x];
1412
- if (!cell || cell.continuation)
1413
- continue;
1414
- out += cell.ch || " ";
1033
+ let cell = row[x];
1034
+ !cell || cell.continuation || (out += cell.ch || " ");
1415
1035
  }
1416
1036
  return x1 >= cols ? out.trimEnd() : out;
1417
1037
  }
1418
1038
  function copyPayload(text, ok, error) {
1419
1039
  return {
1420
1040
  text,
1421
- rows: text ? text.split("\n").length : 0,
1041
+ rows: text ? text.split(`
1042
+ `).length : 0,
1422
1043
  chars: text.length,
1423
1044
  ok,
1424
1045
  ...error === void 0 ? {} : { error }
@@ -1430,89 +1051,62 @@ function clampPointToRect(point, rect) {
1430
1051
  y: Math.max(rect.y, Math.min(rect.y + Math.max(0, rect.h - 1), Math.floor(point.y)))
1431
1052
  };
1432
1053
  }
1054
+ function clipboardCanWrite(api) {
1055
+ return api.canWrite ?? api.supported;
1056
+ }
1433
1057
  function createTerminalSelectionController(options) {
1434
- const state = (0, import_vue.shallowRef)(EMPTY_STATE);
1435
- let range = null;
1436
- let providerAnchor = null;
1437
- let providerFocus = null;
1438
- let overlaySpans = /* @__PURE__ */ new Map();
1439
- let dirtyRows = /* @__PURE__ */ new Set();
1440
- const readOptions = () => ({
1441
- autoCopy: true,
1442
- copyOnMouseUp: true,
1443
- style: { inverse: true },
1058
+ let state = (0, import_vue.shallowRef)(EMPTY_STATE), range = null, providerAnchor = null, providerFocus = null, overlaySpans = /* @__PURE__ */ new Map(), dirtyRows = /* @__PURE__ */ new Set(), readOptions = () => ({
1059
+ autoCopy: !0,
1060
+ copyOnMouseUp: !0,
1061
+ style: { inverse: !0 },
1444
1062
  ...options.getOptions?.() ?? {}
1445
- });
1446
- const markDirty = (prev, next) => {
1447
- const rows = /* @__PURE__ */ new Set();
1448
- for (const y of prev)
1063
+ }), markDirty = (prev, next) => {
1064
+ let rows = /* @__PURE__ */ new Set();
1065
+ for (let y of prev)
1449
1066
  rows.add(y);
1450
- for (const y of next)
1067
+ for (let y of next)
1451
1068
  rows.add(y);
1452
- if (rows.size)
1453
- options.onDirtyRows?.(Array.from(rows).sort((a, b) => a - b));
1454
- };
1455
- const providers = () => options.getTextProviders?.() ?? [];
1456
- const getRow = (y) => options.getRow?.(y) ?? options.terminal.getRow(y);
1457
- const providerById = (id) => providers().find((provider) => provider.id === id) ?? null;
1458
- const providerForCell = (point) => {
1459
- let best = null;
1460
- let bestArea = Infinity;
1461
- for (const provider of providers()) {
1462
- const rect = provider.rect;
1463
- if (point.x < rect.x || point.y < rect.y || point.x >= rect.x + rect.w || point.y >= rect.y + rect.h) {
1069
+ rows.size && options.onDirtyRows?.(Array.from(rows).sort((a, b) => a - b));
1070
+ }, providers = () => options.getTextProviders?.() ?? [], getRow = (y) => options.getRow?.(y) ?? options.terminal.getRow(y), providerById = (id) => providers().find((provider) => provider.id === id) ?? null, providerForCell = (point) => {
1071
+ let best = null, bestArea = 1 / 0;
1072
+ for (let provider of providers()) {
1073
+ let rect = provider.rect;
1074
+ if (point.x < rect.x || point.y < rect.y || point.x >= rect.x + rect.w || point.y >= rect.y + rect.h)
1464
1075
  continue;
1465
- }
1466
- const area2 = Math.max(0, rect.w) * Math.max(0, rect.h);
1467
- if (area2 < bestArea) {
1468
- best = provider;
1469
- bestArea = area2;
1470
- }
1076
+ let area2 = Math.max(0, rect.w) * Math.max(0, rect.h);
1077
+ area2 < bestArea && (best = provider, bestArea = area2);
1471
1078
  }
1472
1079
  return best;
1473
- };
1474
- const providerPointForCell = (provider, point, options2) => {
1475
- const inputPoint = options2?.clampToRect ? clampPointToRect(point, provider.rect) : point;
1476
- const providerPoint = provider.pointForCell?.(inputPoint) ?? inputPoint;
1080
+ }, providerPointForCell = (provider, point, options2) => {
1081
+ let inputPoint = options2?.clampToRect ? clampPointToRect(point, provider.rect) : point, providerPoint = provider.pointForCell?.(inputPoint) ?? inputPoint;
1477
1082
  return providerPoint ? { providerId: provider.id, point: providerPoint } : null;
1478
- };
1479
- const textFromTerminalBuffer = (nextRange) => {
1480
- const size = options.terminal.size();
1481
- const spans = terminalSelectionRowSpans(nextRange, size.cols, size.rows);
1482
- const lines = [];
1483
- for (const span of spans) {
1083
+ }, textFromTerminalBuffer = (nextRange) => {
1084
+ let size = options.terminal.size(), spans = terminalSelectionRowSpans(nextRange, size.cols, size.rows), lines = [];
1085
+ for (let span of spans)
1484
1086
  lines.push(selectedRowText(getRow(span.y), span.x0, span.x1, size.cols));
1485
- }
1486
- return lines.join("\n");
1487
- };
1488
- const providerRangeFor = (provider, screenRange, anchorOverride, focusOverride) => {
1489
- if (anchorOverride && focusOverride && anchorOverride.providerId === provider.id && focusOverride.providerId === provider.id) {
1087
+ return lines.join(`
1088
+ `);
1089
+ }, providerRangeFor = (provider, screenRange, anchorOverride, focusOverride) => {
1090
+ if (anchorOverride && focusOverride && anchorOverride.providerId === provider.id && focusOverride.providerId === provider.id)
1490
1091
  return {
1491
1092
  anchor: anchorOverride.point,
1492
1093
  focus: focusOverride.point,
1493
1094
  mode: screenRange.mode
1494
1095
  };
1495
- }
1496
- const anchor = providerPointForCell(provider, screenRange.anchor, { clampToRect: true });
1497
- const focus = providerPointForCell(provider, screenRange.focus, { clampToRect: true });
1498
- if (!anchor || !focus)
1499
- return null;
1500
- if (anchor.providerId !== provider.id || focus.providerId !== provider.id)
1501
- return null;
1502
- return {
1096
+ let anchor = providerPointForCell(provider, screenRange.anchor, { clampToRect: !0 }), focus = providerPointForCell(provider, screenRange.focus, { clampToRect: !0 });
1097
+ return !anchor || !focus || anchor.providerId !== provider.id || focus.providerId !== provider.id ? null : {
1503
1098
  anchor: anchor.point,
1504
1099
  focus: focus.point,
1505
1100
  mode: screenRange.mode
1506
1101
  };
1507
- };
1508
- const selectedText = () => {
1102
+ }, selectedText = () => {
1509
1103
  if (!range)
1510
1104
  return "";
1511
- const currentRange = range;
1105
+ let currentRange = range;
1512
1106
  if (providerAnchor && providerFocus && providerAnchor.providerId === providerFocus.providerId) {
1513
- const provider2 = providerById(providerAnchor.providerId);
1107
+ let provider2 = providerById(providerAnchor.providerId);
1514
1108
  if (provider2) {
1515
- const providerRange = providerRangeFor(
1109
+ let providerRange = providerRangeFor(
1516
1110
  provider2,
1517
1111
  currentRange,
1518
1112
  providerAnchor,
@@ -1522,94 +1116,54 @@ function createTerminalSelectionController(options) {
1522
1116
  return provider2.getText(providerRange);
1523
1117
  }
1524
1118
  }
1525
- const provider = providers().find((candidate) => candidate.canHandle(currentRange));
1119
+ let provider = providers().find((candidate) => candidate.canHandle(currentRange));
1526
1120
  if (provider) {
1527
- const providerRange = providerRangeFor(provider, currentRange);
1121
+ let providerRange = providerRangeFor(provider, currentRange);
1528
1122
  if (providerRange)
1529
1123
  return provider.getText(providerRange);
1530
1124
  }
1531
1125
  return textFromTerminalBuffer(currentRange);
1532
- };
1533
- const setResolvedText = (text) => {
1534
- if (!range || !state.value.active || state.value.text === text)
1535
- return;
1536
- state.value = { ...state.value, text };
1537
- };
1538
- const resolveProvider = (nextRange, nextProviderAnchor) => {
1126
+ }, setResolvedText = (text) => {
1127
+ !range || !state.value.active || state.value.text === text || (state.value = { ...state.value, text });
1128
+ }, resolveProvider = (nextRange, nextProviderAnchor) => {
1539
1129
  if (!nextRange)
1540
1130
  return null;
1541
1131
  if (nextProviderAnchor) {
1542
- const provider = providerById(nextProviderAnchor.providerId);
1132
+ let provider = providerById(nextProviderAnchor.providerId);
1543
1133
  if (provider)
1544
1134
  return provider;
1545
1135
  }
1546
1136
  return providers().find((candidate) => candidate.canHandle(nextRange)) ?? null;
1547
- };
1548
- const rebuild = (nextRange, nextProviderAnchor, nextProviderFocus) => {
1549
- const previousRows = dirtyRows;
1550
- const size = options.terminal.size();
1551
- const nextOverlaySpans = /* @__PURE__ */ new Map();
1552
- const nextDirtyRows = /* @__PURE__ */ new Set();
1553
- let hasRange = false;
1137
+ }, rebuild = (nextRange, nextProviderAnchor, nextProviderFocus) => {
1138
+ let previousRows = dirtyRows, size = options.terminal.size(), nextOverlaySpans = /* @__PURE__ */ new Map(), nextDirtyRows = /* @__PURE__ */ new Set(), hasRange = !1;
1554
1139
  if (nextRange) {
1555
- const activeProvider = resolveProvider(nextRange, nextProviderAnchor);
1556
- let spans;
1557
- const providerRange = activeProvider != null ? providerRangeFor(activeProvider, nextRange, nextProviderAnchor, nextProviderFocus) : null;
1558
- if (activeProvider?.getVisibleSpans && providerRange) {
1559
- spans = activeProvider.getVisibleSpans(providerRange, nextRange);
1560
- } else {
1561
- spans = terminalSelectionRowSpans(nextRange, size.cols, size.rows);
1562
- }
1563
- hasRange = spans.length > 0 || providerPointsDiffer(nextProviderAnchor, nextProviderFocus);
1564
- for (const span of spans) {
1565
- const x0 = Math.max(0, Math.min(size.cols, Math.floor(span.x0)));
1566
- const x1 = Math.max(0, Math.min(size.cols, Math.floor(span.x1)));
1567
- const y = Math.floor(span.y);
1140
+ let activeProvider = resolveProvider(nextRange, nextProviderAnchor), spans, providerRange = activeProvider != null ? providerRangeFor(activeProvider, nextRange, nextProviderAnchor, nextProviderFocus) : null;
1141
+ activeProvider?.getVisibleSpans && providerRange ? spans = activeProvider.getVisibleSpans(providerRange, nextRange) : spans = terminalSelectionRowSpans(nextRange, size.cols, size.rows), hasRange = spans.length > 0 || providerPointsDiffer(nextProviderAnchor, nextProviderFocus);
1142
+ for (let span of spans) {
1143
+ let x0 = Math.max(0, Math.min(size.cols, Math.floor(span.x0))), x1 = Math.max(0, Math.min(size.cols, Math.floor(span.x1))), y = Math.floor(span.y);
1568
1144
  if (y < 0 || y >= size.rows || x1 <= x0)
1569
1145
  continue;
1570
1146
  let list = nextOverlaySpans.get(y);
1571
- if (!list) {
1572
- list = [];
1573
- nextOverlaySpans.set(y, list);
1574
- }
1575
- list.push({ y, x0, x1 });
1576
- nextDirtyRows.add(y);
1147
+ list || (list = [], nextOverlaySpans.set(y, list)), list.push({ y, x0, x1 }), nextDirtyRows.add(y);
1577
1148
  }
1578
1149
  }
1579
- range = nextRange;
1580
- providerAnchor = nextProviderAnchor;
1581
- providerFocus = nextProviderFocus;
1582
- overlaySpans = nextOverlaySpans;
1583
- dirtyRows = nextDirtyRows;
1584
- state.value = nextRange ? {
1585
- active: true,
1150
+ range = nextRange, providerAnchor = nextProviderAnchor, providerFocus = nextProviderFocus, overlaySpans = nextOverlaySpans, dirtyRows = nextDirtyRows, state.value = nextRange ? {
1151
+ active: !0,
1586
1152
  anchor: nextRange.anchor,
1587
1153
  focus: nextRange.focus,
1588
1154
  text: "",
1589
1155
  hasRange
1590
- } : EMPTY_STATE;
1591
- markDirty(previousRows, nextDirtyRows);
1592
- };
1593
- const controller = {
1156
+ } : EMPTY_STATE, markDirty(previousRows, nextDirtyRows);
1157
+ }, controller = {
1594
1158
  state,
1595
1159
  start(point, startOptions) {
1596
- const size = options.terminal.size();
1597
- const focus = clampPoint(point, size.cols, size.rows);
1598
- const anchor = startOptions?.extend && range?.anchor ? clampPoint(range.anchor, size.cols, size.rows) : focus;
1599
- const anchorProvider = providerForCell(anchor);
1600
- const focusProvider = providerForCell(focus);
1601
- const activeProvider = startOptions?.extend && providerAnchor ? providerById(providerAnchor.providerId) : null;
1602
- const nextProviderAnchor = startOptions?.extend && providerAnchor ? providerAnchor : anchorProvider ? providerPointForCell(anchorProvider, anchor) : null;
1603
- const nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, focus, { clampToRect: true }) : nextProviderAnchor && focusProvider?.id === nextProviderAnchor.providerId ? providerPointForCell(focusProvider, focus) : null;
1160
+ let size = options.terminal.size(), focus = clampPoint(point, size.cols, size.rows), anchor = startOptions?.extend && range?.anchor ? clampPoint(range.anchor, size.cols, size.rows) : focus, anchorProvider = providerForCell(anchor), focusProvider = providerForCell(focus), activeProvider = startOptions?.extend && providerAnchor ? providerById(providerAnchor.providerId) : null, nextProviderAnchor = startOptions?.extend && providerAnchor ? providerAnchor : anchorProvider ? providerPointForCell(anchorProvider, anchor) : null, nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, focus, { clampToRect: !0 }) : nextProviderAnchor && focusProvider?.id === nextProviderAnchor.providerId ? providerPointForCell(focusProvider, focus) : null;
1604
1161
  rebuild({ anchor, focus, mode: "linear" }, nextProviderAnchor, nextProviderFocus);
1605
1162
  },
1606
1163
  update(point) {
1607
1164
  if (!range)
1608
1165
  return;
1609
- const size = options.terminal.size();
1610
- const focus = clampPoint(point, size.cols, size.rows);
1611
- const activeProvider = providerAnchor ? providerById(providerAnchor.providerId) : null;
1612
- const nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, focus, { clampToRect: true }) : null;
1166
+ let size = options.terminal.size(), focus = clampPoint(point, size.cols, size.rows), activeProvider = providerAnchor ? providerById(providerAnchor.providerId) : null, nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, focus, { clampToRect: !0 }) : null;
1613
1167
  rebuild(
1614
1168
  {
1615
1169
  ...range,
@@ -1626,72 +1180,56 @@ function createTerminalSelectionController(options) {
1626
1180
  controller.clear();
1627
1181
  return;
1628
1182
  }
1629
- const current = readOptions();
1630
- if (!current.autoCopy || !current.copyOnMouseUp) {
1631
- return;
1632
- }
1633
- await controller.copy();
1183
+ let current = readOptions();
1184
+ !current.autoCopy || !current.copyOnMouseUp || await controller.copy();
1634
1185
  },
1635
1186
  clear() {
1636
- if (!range && !dirtyRows.size)
1637
- return;
1638
- rebuild(null, null, null);
1187
+ !range && !dirtyRows.size || rebuild(null, null, null);
1639
1188
  },
1640
1189
  async copy() {
1641
- const text = state.value.text || selectedText();
1190
+ let text = state.value.text || selectedText();
1642
1191
  if (!text)
1643
- return false;
1644
- setResolvedText(text);
1645
- if (!options.clipboard.supported) {
1646
- options.onCopy?.(copyPayload(text, false, new Error("Clipboard unavailable")));
1647
- return false;
1648
- }
1192
+ return !1;
1193
+ if (setResolvedText(text), !clipboardCanWrite(options.clipboard))
1194
+ return options.onCopy?.(copyPayload(text, !1, new Error("Clipboard unavailable"))), !1;
1649
1195
  try {
1650
- await options.clipboard.writeText(text);
1651
- options.onCopy?.(copyPayload(text, true));
1652
- return true;
1196
+ return await options.clipboard.writeText(text), options.onCopy?.(copyPayload(text, !0)), !0;
1653
1197
  } catch (error) {
1654
- options.onCopy?.(copyPayload(text, false, error));
1655
- return false;
1198
+ return options.onCopy?.(copyPayload(text, !1, error)), !1;
1656
1199
  }
1657
1200
  },
1658
1201
  paint(dirtyRowsHint) {
1659
- const rows = dirtyRowsHint ?? Array.from(overlaySpans.keys());
1660
- const selectionStyle = readOptions().style;
1661
- for (const y of rows) {
1662
- const spans = overlaySpans.get(y);
1202
+ let rows = dirtyRowsHint ?? Array.from(overlaySpans.keys()), selectionStyle = readOptions().style;
1203
+ for (let y of rows) {
1204
+ let spans = overlaySpans.get(y);
1663
1205
  if (!spans?.length)
1664
1206
  continue;
1665
- const row = getRow(y);
1666
- for (const span of spans) {
1207
+ let row = getRow(y);
1208
+ for (let span of spans)
1667
1209
  for (let x = span.x0; x < span.x1; x++) {
1668
- const cell = row[x];
1210
+ let cell = row[x];
1669
1211
  if (!cell || cell.continuation)
1670
1212
  continue;
1671
- const { href: _href, ...baseStyle } = cell.style;
1213
+ let { href: _href, ...baseStyle } = cell.style;
1672
1214
  options.overlayTerminal.put(x, y, cell.ch || " ", {
1673
1215
  ...baseStyle,
1674
1216
  ...selectionStyle
1675
1217
  });
1676
1218
  }
1677
- }
1678
1219
  }
1679
1220
  },
1680
1221
  refresh(refreshOptions) {
1681
- if (!range)
1682
- return;
1683
- if (refreshOptions?.remapFocus) {
1684
- const activeProvider = providerAnchor ? providerById(providerAnchor.providerId) : resolveProvider(range, null);
1685
- const nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, range.focus, { clampToRect: true }) : providerFocus;
1686
- rebuild(range, providerAnchor, nextProviderFocus);
1687
- return;
1222
+ if (range) {
1223
+ if (refreshOptions?.remapFocus) {
1224
+ let activeProvider = providerAnchor ? providerById(providerAnchor.providerId) : resolveProvider(range, null), nextProviderFocus = activeProvider ? providerPointForCell(activeProvider, range.focus, { clampToRect: !0 }) : providerFocus;
1225
+ rebuild(range, providerAnchor, nextProviderFocus);
1226
+ return;
1227
+ }
1228
+ rebuild(range, providerAnchor, providerFocus);
1688
1229
  }
1689
- rebuild(range, providerAnchor, providerFocus);
1690
1230
  },
1691
1231
  clearProvider(providerId) {
1692
- if (providerAnchor?.providerId === providerId || providerFocus?.providerId === providerId) {
1693
- controller.clear();
1694
- }
1232
+ (providerAnchor?.providerId === providerId || providerFocus?.providerId === providerId) && controller.clear();
1695
1233
  }
1696
1234
  };
1697
1235
  return controller;