x-shell.js 0.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 (38) hide show
  1. package/README.md +304 -0
  2. package/dist/client/browser-bundle.js +314 -0
  3. package/dist/client/browser-bundle.js.map +7 -0
  4. package/dist/client/index.d.ts +7 -0
  5. package/dist/client/index.d.ts.map +1 -0
  6. package/dist/client/index.js +5 -0
  7. package/dist/client/index.js.map +1 -0
  8. package/dist/client/terminal-client.d.ts +122 -0
  9. package/dist/client/terminal-client.d.ts.map +1 -0
  10. package/dist/client/terminal-client.js +328 -0
  11. package/dist/client/terminal-client.js.map +1 -0
  12. package/dist/server/index.d.ts +7 -0
  13. package/dist/server/index.d.ts.map +1 -0
  14. package/dist/server/index.js +5 -0
  15. package/dist/server/index.js.map +1 -0
  16. package/dist/server/terminal-server.d.ts +107 -0
  17. package/dist/server/terminal-server.d.ts.map +1 -0
  18. package/dist/server/terminal-server.js +392 -0
  19. package/dist/server/terminal-server.js.map +1 -0
  20. package/dist/shared/types.d.ts +133 -0
  21. package/dist/shared/types.d.ts.map +1 -0
  22. package/dist/shared/types.js +5 -0
  23. package/dist/shared/types.js.map +1 -0
  24. package/dist/ui/browser-bundle.js +1654 -0
  25. package/dist/ui/browser-bundle.js.map +7 -0
  26. package/dist/ui/index.d.ts +6 -0
  27. package/dist/ui/index.d.ts.map +1 -0
  28. package/dist/ui/index.js +6 -0
  29. package/dist/ui/index.js.map +1 -0
  30. package/dist/ui/styles.d.ts +16 -0
  31. package/dist/ui/styles.d.ts.map +1 -0
  32. package/dist/ui/styles.js +125 -0
  33. package/dist/ui/styles.js.map +1 -0
  34. package/dist/ui/x-shell-terminal.d.ts +100 -0
  35. package/dist/ui/x-shell-terminal.d.ts.map +1 -0
  36. package/dist/ui/x-shell-terminal.js +540 -0
  37. package/dist/ui/x-shell-terminal.js.map +1 -0
  38. package/package.json +94 -0
@@ -0,0 +1,1654 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i5 = decorators.length - 1, decorator; i5 >= 0; i5--)
6
+ if (decorator = decorators[i5])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+
13
+ // node_modules/@lit/reactive-element/css-tag.js
14
+ var t = globalThis;
15
+ var e = t.ShadowRoot && (void 0 === t.ShadyCSS || t.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype;
16
+ var s = Symbol();
17
+ var o = /* @__PURE__ */ new WeakMap();
18
+ var n = class {
19
+ constructor(t4, e5, o6) {
20
+ if (this._$cssResult$ = true, o6 !== s)
21
+ throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
22
+ this.cssText = t4, this.t = e5;
23
+ }
24
+ get styleSheet() {
25
+ let t4 = this.o;
26
+ const s4 = this.t;
27
+ if (e && void 0 === t4) {
28
+ const e5 = void 0 !== s4 && 1 === s4.length;
29
+ e5 && (t4 = o.get(s4)), void 0 === t4 && ((this.o = t4 = new CSSStyleSheet()).replaceSync(this.cssText), e5 && o.set(s4, t4));
30
+ }
31
+ return t4;
32
+ }
33
+ toString() {
34
+ return this.cssText;
35
+ }
36
+ };
37
+ var r = (t4) => new n("string" == typeof t4 ? t4 : t4 + "", void 0, s);
38
+ var i = (t4, ...e5) => {
39
+ const o6 = 1 === t4.length ? t4[0] : e5.reduce((e6, s4, o7) => e6 + ((t5) => {
40
+ if (true === t5._$cssResult$)
41
+ return t5.cssText;
42
+ if ("number" == typeof t5)
43
+ return t5;
44
+ throw Error("Value passed to 'css' function must be a 'css' function result: " + t5 + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
45
+ })(s4) + t4[o7 + 1], t4[0]);
46
+ return new n(o6, t4, s);
47
+ };
48
+ var S = (s4, o6) => {
49
+ if (e)
50
+ s4.adoptedStyleSheets = o6.map((t4) => t4 instanceof CSSStyleSheet ? t4 : t4.styleSheet);
51
+ else
52
+ for (const e5 of o6) {
53
+ const o7 = document.createElement("style"), n5 = t.litNonce;
54
+ void 0 !== n5 && o7.setAttribute("nonce", n5), o7.textContent = e5.cssText, s4.appendChild(o7);
55
+ }
56
+ };
57
+ var c = e ? (t4) => t4 : (t4) => t4 instanceof CSSStyleSheet ? ((t5) => {
58
+ let e5 = "";
59
+ for (const s4 of t5.cssRules)
60
+ e5 += s4.cssText;
61
+ return r(e5);
62
+ })(t4) : t4;
63
+
64
+ // node_modules/@lit/reactive-element/reactive-element.js
65
+ var { is: i2, defineProperty: e2, getOwnPropertyDescriptor: h, getOwnPropertyNames: r2, getOwnPropertySymbols: o2, getPrototypeOf: n2 } = Object;
66
+ var a = globalThis;
67
+ var c2 = a.trustedTypes;
68
+ var l = c2 ? c2.emptyScript : "";
69
+ var p = a.reactiveElementPolyfillSupport;
70
+ var d = (t4, s4) => t4;
71
+ var u = { toAttribute(t4, s4) {
72
+ switch (s4) {
73
+ case Boolean:
74
+ t4 = t4 ? l : null;
75
+ break;
76
+ case Object:
77
+ case Array:
78
+ t4 = null == t4 ? t4 : JSON.stringify(t4);
79
+ }
80
+ return t4;
81
+ }, fromAttribute(t4, s4) {
82
+ let i5 = t4;
83
+ switch (s4) {
84
+ case Boolean:
85
+ i5 = null !== t4;
86
+ break;
87
+ case Number:
88
+ i5 = null === t4 ? null : Number(t4);
89
+ break;
90
+ case Object:
91
+ case Array:
92
+ try {
93
+ i5 = JSON.parse(t4);
94
+ } catch (t5) {
95
+ i5 = null;
96
+ }
97
+ }
98
+ return i5;
99
+ } };
100
+ var f = (t4, s4) => !i2(t4, s4);
101
+ var b = { attribute: true, type: String, converter: u, reflect: false, useDefault: false, hasChanged: f };
102
+ Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), a.litPropertyMetadata ?? (a.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
103
+ var y = class extends HTMLElement {
104
+ static addInitializer(t4) {
105
+ this._$Ei(), (this.l ?? (this.l = [])).push(t4);
106
+ }
107
+ static get observedAttributes() {
108
+ return this.finalize(), this._$Eh && [...this._$Eh.keys()];
109
+ }
110
+ static createProperty(t4, s4 = b) {
111
+ if (s4.state && (s4.attribute = false), this._$Ei(), this.prototype.hasOwnProperty(t4) && ((s4 = Object.create(s4)).wrapped = true), this.elementProperties.set(t4, s4), !s4.noAccessor) {
112
+ const i5 = Symbol(), h3 = this.getPropertyDescriptor(t4, i5, s4);
113
+ void 0 !== h3 && e2(this.prototype, t4, h3);
114
+ }
115
+ }
116
+ static getPropertyDescriptor(t4, s4, i5) {
117
+ const { get: e5, set: r6 } = h(this.prototype, t4) ?? { get() {
118
+ return this[s4];
119
+ }, set(t5) {
120
+ this[s4] = t5;
121
+ } };
122
+ return { get: e5, set(s5) {
123
+ const h3 = e5?.call(this);
124
+ r6?.call(this, s5), this.requestUpdate(t4, h3, i5);
125
+ }, configurable: true, enumerable: true };
126
+ }
127
+ static getPropertyOptions(t4) {
128
+ return this.elementProperties.get(t4) ?? b;
129
+ }
130
+ static _$Ei() {
131
+ if (this.hasOwnProperty(d("elementProperties")))
132
+ return;
133
+ const t4 = n2(this);
134
+ t4.finalize(), void 0 !== t4.l && (this.l = [...t4.l]), this.elementProperties = new Map(t4.elementProperties);
135
+ }
136
+ static finalize() {
137
+ if (this.hasOwnProperty(d("finalized")))
138
+ return;
139
+ if (this.finalized = true, this._$Ei(), this.hasOwnProperty(d("properties"))) {
140
+ const t5 = this.properties, s4 = [...r2(t5), ...o2(t5)];
141
+ for (const i5 of s4)
142
+ this.createProperty(i5, t5[i5]);
143
+ }
144
+ const t4 = this[Symbol.metadata];
145
+ if (null !== t4) {
146
+ const s4 = litPropertyMetadata.get(t4);
147
+ if (void 0 !== s4)
148
+ for (const [t5, i5] of s4)
149
+ this.elementProperties.set(t5, i5);
150
+ }
151
+ this._$Eh = /* @__PURE__ */ new Map();
152
+ for (const [t5, s4] of this.elementProperties) {
153
+ const i5 = this._$Eu(t5, s4);
154
+ void 0 !== i5 && this._$Eh.set(i5, t5);
155
+ }
156
+ this.elementStyles = this.finalizeStyles(this.styles);
157
+ }
158
+ static finalizeStyles(s4) {
159
+ const i5 = [];
160
+ if (Array.isArray(s4)) {
161
+ const e5 = new Set(s4.flat(1 / 0).reverse());
162
+ for (const s5 of e5)
163
+ i5.unshift(c(s5));
164
+ } else
165
+ void 0 !== s4 && i5.push(c(s4));
166
+ return i5;
167
+ }
168
+ static _$Eu(t4, s4) {
169
+ const i5 = s4.attribute;
170
+ return false === i5 ? void 0 : "string" == typeof i5 ? i5 : "string" == typeof t4 ? t4.toLowerCase() : void 0;
171
+ }
172
+ constructor() {
173
+ super(), this._$Ep = void 0, this.isUpdatePending = false, this.hasUpdated = false, this._$Em = null, this._$Ev();
174
+ }
175
+ _$Ev() {
176
+ this._$ES = new Promise((t4) => this.enableUpdating = t4), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), this.constructor.l?.forEach((t4) => t4(this));
177
+ }
178
+ addController(t4) {
179
+ (this._$EO ?? (this._$EO = /* @__PURE__ */ new Set())).add(t4), void 0 !== this.renderRoot && this.isConnected && t4.hostConnected?.();
180
+ }
181
+ removeController(t4) {
182
+ this._$EO?.delete(t4);
183
+ }
184
+ _$E_() {
185
+ const t4 = /* @__PURE__ */ new Map(), s4 = this.constructor.elementProperties;
186
+ for (const i5 of s4.keys())
187
+ this.hasOwnProperty(i5) && (t4.set(i5, this[i5]), delete this[i5]);
188
+ t4.size > 0 && (this._$Ep = t4);
189
+ }
190
+ createRenderRoot() {
191
+ const t4 = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
192
+ return S(t4, this.constructor.elementStyles), t4;
193
+ }
194
+ connectedCallback() {
195
+ this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(true), this._$EO?.forEach((t4) => t4.hostConnected?.());
196
+ }
197
+ enableUpdating(t4) {
198
+ }
199
+ disconnectedCallback() {
200
+ this._$EO?.forEach((t4) => t4.hostDisconnected?.());
201
+ }
202
+ attributeChangedCallback(t4, s4, i5) {
203
+ this._$AK(t4, i5);
204
+ }
205
+ _$ET(t4, s4) {
206
+ const i5 = this.constructor.elementProperties.get(t4), e5 = this.constructor._$Eu(t4, i5);
207
+ if (void 0 !== e5 && true === i5.reflect) {
208
+ const h3 = (void 0 !== i5.converter?.toAttribute ? i5.converter : u).toAttribute(s4, i5.type);
209
+ this._$Em = t4, null == h3 ? this.removeAttribute(e5) : this.setAttribute(e5, h3), this._$Em = null;
210
+ }
211
+ }
212
+ _$AK(t4, s4) {
213
+ const i5 = this.constructor, e5 = i5._$Eh.get(t4);
214
+ if (void 0 !== e5 && this._$Em !== e5) {
215
+ const t5 = i5.getPropertyOptions(e5), h3 = "function" == typeof t5.converter ? { fromAttribute: t5.converter } : void 0 !== t5.converter?.fromAttribute ? t5.converter : u;
216
+ this._$Em = e5;
217
+ const r6 = h3.fromAttribute(s4, t5.type);
218
+ this[e5] = r6 ?? this._$Ej?.get(e5) ?? r6, this._$Em = null;
219
+ }
220
+ }
221
+ requestUpdate(t4, s4, i5, e5 = false, h3) {
222
+ if (void 0 !== t4) {
223
+ const r6 = this.constructor;
224
+ if (false === e5 && (h3 = this[t4]), i5 ?? (i5 = r6.getPropertyOptions(t4)), !((i5.hasChanged ?? f)(h3, s4) || i5.useDefault && i5.reflect && h3 === this._$Ej?.get(t4) && !this.hasAttribute(r6._$Eu(t4, i5))))
225
+ return;
226
+ this.C(t4, s4, i5);
227
+ }
228
+ false === this.isUpdatePending && (this._$ES = this._$EP());
229
+ }
230
+ C(t4, s4, { useDefault: i5, reflect: e5, wrapped: h3 }, r6) {
231
+ i5 && !(this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Map())).has(t4) && (this._$Ej.set(t4, r6 ?? s4 ?? this[t4]), true !== h3 || void 0 !== r6) || (this._$AL.has(t4) || (this.hasUpdated || i5 || (s4 = void 0), this._$AL.set(t4, s4)), true === e5 && this._$Em !== t4 && (this._$Eq ?? (this._$Eq = /* @__PURE__ */ new Set())).add(t4));
232
+ }
233
+ async _$EP() {
234
+ this.isUpdatePending = true;
235
+ try {
236
+ await this._$ES;
237
+ } catch (t5) {
238
+ Promise.reject(t5);
239
+ }
240
+ const t4 = this.scheduleUpdate();
241
+ return null != t4 && await t4, !this.isUpdatePending;
242
+ }
243
+ scheduleUpdate() {
244
+ return this.performUpdate();
245
+ }
246
+ performUpdate() {
247
+ if (!this.isUpdatePending)
248
+ return;
249
+ if (!this.hasUpdated) {
250
+ if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) {
251
+ for (const [t6, s5] of this._$Ep)
252
+ this[t6] = s5;
253
+ this._$Ep = void 0;
254
+ }
255
+ const t5 = this.constructor.elementProperties;
256
+ if (t5.size > 0)
257
+ for (const [s5, i5] of t5) {
258
+ const { wrapped: t6 } = i5, e5 = this[s5];
259
+ true !== t6 || this._$AL.has(s5) || void 0 === e5 || this.C(s5, void 0, i5, e5);
260
+ }
261
+ }
262
+ let t4 = false;
263
+ const s4 = this._$AL;
264
+ try {
265
+ t4 = this.shouldUpdate(s4), t4 ? (this.willUpdate(s4), this._$EO?.forEach((t5) => t5.hostUpdate?.()), this.update(s4)) : this._$EM();
266
+ } catch (s5) {
267
+ throw t4 = false, this._$EM(), s5;
268
+ }
269
+ t4 && this._$AE(s4);
270
+ }
271
+ willUpdate(t4) {
272
+ }
273
+ _$AE(t4) {
274
+ this._$EO?.forEach((t5) => t5.hostUpdated?.()), this.hasUpdated || (this.hasUpdated = true, this.firstUpdated(t4)), this.updated(t4);
275
+ }
276
+ _$EM() {
277
+ this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = false;
278
+ }
279
+ get updateComplete() {
280
+ return this.getUpdateComplete();
281
+ }
282
+ getUpdateComplete() {
283
+ return this._$ES;
284
+ }
285
+ shouldUpdate(t4) {
286
+ return true;
287
+ }
288
+ update(t4) {
289
+ this._$Eq && (this._$Eq = this._$Eq.forEach((t5) => this._$ET(t5, this[t5]))), this._$EM();
290
+ }
291
+ updated(t4) {
292
+ }
293
+ firstUpdated(t4) {
294
+ }
295
+ };
296
+ y.elementStyles = [], y.shadowRootOptions = { mode: "open" }, y[d("elementProperties")] = /* @__PURE__ */ new Map(), y[d("finalized")] = /* @__PURE__ */ new Map(), p?.({ ReactiveElement: y }), (a.reactiveElementVersions ?? (a.reactiveElementVersions = [])).push("2.1.2");
297
+
298
+ // node_modules/lit-html/lit-html.js
299
+ var t2 = globalThis;
300
+ var i3 = (t4) => t4;
301
+ var s2 = t2.trustedTypes;
302
+ var e3 = s2 ? s2.createPolicy("lit-html", { createHTML: (t4) => t4 }) : void 0;
303
+ var h2 = "$lit$";
304
+ var o3 = `lit$${Math.random().toFixed(9).slice(2)}$`;
305
+ var n3 = "?" + o3;
306
+ var r3 = `<${n3}>`;
307
+ var l2 = document;
308
+ var c3 = () => l2.createComment("");
309
+ var a2 = (t4) => null === t4 || "object" != typeof t4 && "function" != typeof t4;
310
+ var u2 = Array.isArray;
311
+ var d2 = (t4) => u2(t4) || "function" == typeof t4?.[Symbol.iterator];
312
+ var f2 = "[ \n\f\r]";
313
+ var v = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;
314
+ var _ = /-->/g;
315
+ var m = />/g;
316
+ var p2 = RegExp(`>|${f2}(?:([^\\s"'>=/]+)(${f2}*=${f2}*(?:[^
317
+ \f\r"'\`<>=]|("|')|))|$)`, "g");
318
+ var g = /'/g;
319
+ var $ = /"/g;
320
+ var y2 = /^(?:script|style|textarea|title)$/i;
321
+ var x = (t4) => (i5, ...s4) => ({ _$litType$: t4, strings: i5, values: s4 });
322
+ var b2 = x(1);
323
+ var w = x(2);
324
+ var T = x(3);
325
+ var E = Symbol.for("lit-noChange");
326
+ var A = Symbol.for("lit-nothing");
327
+ var C = /* @__PURE__ */ new WeakMap();
328
+ var P = l2.createTreeWalker(l2, 129);
329
+ function V(t4, i5) {
330
+ if (!u2(t4) || !t4.hasOwnProperty("raw"))
331
+ throw Error("invalid template strings array");
332
+ return void 0 !== e3 ? e3.createHTML(i5) : i5;
333
+ }
334
+ var N = (t4, i5) => {
335
+ const s4 = t4.length - 1, e5 = [];
336
+ let n5, l3 = 2 === i5 ? "<svg>" : 3 === i5 ? "<math>" : "", c4 = v;
337
+ for (let i6 = 0; i6 < s4; i6++) {
338
+ const s5 = t4[i6];
339
+ let a3, u3, d3 = -1, f3 = 0;
340
+ for (; f3 < s5.length && (c4.lastIndex = f3, u3 = c4.exec(s5), null !== u3); )
341
+ f3 = c4.lastIndex, c4 === v ? "!--" === u3[1] ? c4 = _ : void 0 !== u3[1] ? c4 = m : void 0 !== u3[2] ? (y2.test(u3[2]) && (n5 = RegExp("</" + u3[2], "g")), c4 = p2) : void 0 !== u3[3] && (c4 = p2) : c4 === p2 ? ">" === u3[0] ? (c4 = n5 ?? v, d3 = -1) : void 0 === u3[1] ? d3 = -2 : (d3 = c4.lastIndex - u3[2].length, a3 = u3[1], c4 = void 0 === u3[3] ? p2 : '"' === u3[3] ? $ : g) : c4 === $ || c4 === g ? c4 = p2 : c4 === _ || c4 === m ? c4 = v : (c4 = p2, n5 = void 0);
342
+ const x2 = c4 === p2 && t4[i6 + 1].startsWith("/>") ? " " : "";
343
+ l3 += c4 === v ? s5 + r3 : d3 >= 0 ? (e5.push(a3), s5.slice(0, d3) + h2 + s5.slice(d3) + o3 + x2) : s5 + o3 + (-2 === d3 ? i6 : x2);
344
+ }
345
+ return [V(t4, l3 + (t4[s4] || "<?>") + (2 === i5 ? "</svg>" : 3 === i5 ? "</math>" : "")), e5];
346
+ };
347
+ var S2 = class _S {
348
+ constructor({ strings: t4, _$litType$: i5 }, e5) {
349
+ let r6;
350
+ this.parts = [];
351
+ let l3 = 0, a3 = 0;
352
+ const u3 = t4.length - 1, d3 = this.parts, [f3, v2] = N(t4, i5);
353
+ if (this.el = _S.createElement(f3, e5), P.currentNode = this.el.content, 2 === i5 || 3 === i5) {
354
+ const t5 = this.el.content.firstChild;
355
+ t5.replaceWith(...t5.childNodes);
356
+ }
357
+ for (; null !== (r6 = P.nextNode()) && d3.length < u3; ) {
358
+ if (1 === r6.nodeType) {
359
+ if (r6.hasAttributes())
360
+ for (const t5 of r6.getAttributeNames())
361
+ if (t5.endsWith(h2)) {
362
+ const i6 = v2[a3++], s4 = r6.getAttribute(t5).split(o3), e6 = /([.?@])?(.*)/.exec(i6);
363
+ d3.push({ type: 1, index: l3, name: e6[2], strings: s4, ctor: "." === e6[1] ? I : "?" === e6[1] ? L : "@" === e6[1] ? z : H }), r6.removeAttribute(t5);
364
+ } else
365
+ t5.startsWith(o3) && (d3.push({ type: 6, index: l3 }), r6.removeAttribute(t5));
366
+ if (y2.test(r6.tagName)) {
367
+ const t5 = r6.textContent.split(o3), i6 = t5.length - 1;
368
+ if (i6 > 0) {
369
+ r6.textContent = s2 ? s2.emptyScript : "";
370
+ for (let s4 = 0; s4 < i6; s4++)
371
+ r6.append(t5[s4], c3()), P.nextNode(), d3.push({ type: 2, index: ++l3 });
372
+ r6.append(t5[i6], c3());
373
+ }
374
+ }
375
+ } else if (8 === r6.nodeType)
376
+ if (r6.data === n3)
377
+ d3.push({ type: 2, index: l3 });
378
+ else {
379
+ let t5 = -1;
380
+ for (; -1 !== (t5 = r6.data.indexOf(o3, t5 + 1)); )
381
+ d3.push({ type: 7, index: l3 }), t5 += o3.length - 1;
382
+ }
383
+ l3++;
384
+ }
385
+ }
386
+ static createElement(t4, i5) {
387
+ const s4 = l2.createElement("template");
388
+ return s4.innerHTML = t4, s4;
389
+ }
390
+ };
391
+ function M(t4, i5, s4 = t4, e5) {
392
+ if (i5 === E)
393
+ return i5;
394
+ let h3 = void 0 !== e5 ? s4._$Co?.[e5] : s4._$Cl;
395
+ const o6 = a2(i5) ? void 0 : i5._$litDirective$;
396
+ return h3?.constructor !== o6 && (h3?._$AO?.(false), void 0 === o6 ? h3 = void 0 : (h3 = new o6(t4), h3._$AT(t4, s4, e5)), void 0 !== e5 ? (s4._$Co ?? (s4._$Co = []))[e5] = h3 : s4._$Cl = h3), void 0 !== h3 && (i5 = M(t4, h3._$AS(t4, i5.values), h3, e5)), i5;
397
+ }
398
+ var R = class {
399
+ constructor(t4, i5) {
400
+ this._$AV = [], this._$AN = void 0, this._$AD = t4, this._$AM = i5;
401
+ }
402
+ get parentNode() {
403
+ return this._$AM.parentNode;
404
+ }
405
+ get _$AU() {
406
+ return this._$AM._$AU;
407
+ }
408
+ u(t4) {
409
+ const { el: { content: i5 }, parts: s4 } = this._$AD, e5 = (t4?.creationScope ?? l2).importNode(i5, true);
410
+ P.currentNode = e5;
411
+ let h3 = P.nextNode(), o6 = 0, n5 = 0, r6 = s4[0];
412
+ for (; void 0 !== r6; ) {
413
+ if (o6 === r6.index) {
414
+ let i6;
415
+ 2 === r6.type ? i6 = new k(h3, h3.nextSibling, this, t4) : 1 === r6.type ? i6 = new r6.ctor(h3, r6.name, r6.strings, this, t4) : 6 === r6.type && (i6 = new Z(h3, this, t4)), this._$AV.push(i6), r6 = s4[++n5];
416
+ }
417
+ o6 !== r6?.index && (h3 = P.nextNode(), o6++);
418
+ }
419
+ return P.currentNode = l2, e5;
420
+ }
421
+ p(t4) {
422
+ let i5 = 0;
423
+ for (const s4 of this._$AV)
424
+ void 0 !== s4 && (void 0 !== s4.strings ? (s4._$AI(t4, s4, i5), i5 += s4.strings.length - 2) : s4._$AI(t4[i5])), i5++;
425
+ }
426
+ };
427
+ var k = class _k {
428
+ get _$AU() {
429
+ return this._$AM?._$AU ?? this._$Cv;
430
+ }
431
+ constructor(t4, i5, s4, e5) {
432
+ this.type = 2, this._$AH = A, this._$AN = void 0, this._$AA = t4, this._$AB = i5, this._$AM = s4, this.options = e5, this._$Cv = e5?.isConnected ?? true;
433
+ }
434
+ get parentNode() {
435
+ let t4 = this._$AA.parentNode;
436
+ const i5 = this._$AM;
437
+ return void 0 !== i5 && 11 === t4?.nodeType && (t4 = i5.parentNode), t4;
438
+ }
439
+ get startNode() {
440
+ return this._$AA;
441
+ }
442
+ get endNode() {
443
+ return this._$AB;
444
+ }
445
+ _$AI(t4, i5 = this) {
446
+ t4 = M(this, t4, i5), a2(t4) ? t4 === A || null == t4 || "" === t4 ? (this._$AH !== A && this._$AR(), this._$AH = A) : t4 !== this._$AH && t4 !== E && this._(t4) : void 0 !== t4._$litType$ ? this.$(t4) : void 0 !== t4.nodeType ? this.T(t4) : d2(t4) ? this.k(t4) : this._(t4);
447
+ }
448
+ O(t4) {
449
+ return this._$AA.parentNode.insertBefore(t4, this._$AB);
450
+ }
451
+ T(t4) {
452
+ this._$AH !== t4 && (this._$AR(), this._$AH = this.O(t4));
453
+ }
454
+ _(t4) {
455
+ this._$AH !== A && a2(this._$AH) ? this._$AA.nextSibling.data = t4 : this.T(l2.createTextNode(t4)), this._$AH = t4;
456
+ }
457
+ $(t4) {
458
+ const { values: i5, _$litType$: s4 } = t4, e5 = "number" == typeof s4 ? this._$AC(t4) : (void 0 === s4.el && (s4.el = S2.createElement(V(s4.h, s4.h[0]), this.options)), s4);
459
+ if (this._$AH?._$AD === e5)
460
+ this._$AH.p(i5);
461
+ else {
462
+ const t5 = new R(e5, this), s5 = t5.u(this.options);
463
+ t5.p(i5), this.T(s5), this._$AH = t5;
464
+ }
465
+ }
466
+ _$AC(t4) {
467
+ let i5 = C.get(t4.strings);
468
+ return void 0 === i5 && C.set(t4.strings, i5 = new S2(t4)), i5;
469
+ }
470
+ k(t4) {
471
+ u2(this._$AH) || (this._$AH = [], this._$AR());
472
+ const i5 = this._$AH;
473
+ let s4, e5 = 0;
474
+ for (const h3 of t4)
475
+ e5 === i5.length ? i5.push(s4 = new _k(this.O(c3()), this.O(c3()), this, this.options)) : s4 = i5[e5], s4._$AI(h3), e5++;
476
+ e5 < i5.length && (this._$AR(s4 && s4._$AB.nextSibling, e5), i5.length = e5);
477
+ }
478
+ _$AR(t4 = this._$AA.nextSibling, s4) {
479
+ for (this._$AP?.(false, true, s4); t4 !== this._$AB; ) {
480
+ const s5 = i3(t4).nextSibling;
481
+ i3(t4).remove(), t4 = s5;
482
+ }
483
+ }
484
+ setConnected(t4) {
485
+ void 0 === this._$AM && (this._$Cv = t4, this._$AP?.(t4));
486
+ }
487
+ };
488
+ var H = class {
489
+ get tagName() {
490
+ return this.element.tagName;
491
+ }
492
+ get _$AU() {
493
+ return this._$AM._$AU;
494
+ }
495
+ constructor(t4, i5, s4, e5, h3) {
496
+ this.type = 1, this._$AH = A, this._$AN = void 0, this.element = t4, this.name = i5, this._$AM = e5, this.options = h3, s4.length > 2 || "" !== s4[0] || "" !== s4[1] ? (this._$AH = Array(s4.length - 1).fill(new String()), this.strings = s4) : this._$AH = A;
497
+ }
498
+ _$AI(t4, i5 = this, s4, e5) {
499
+ const h3 = this.strings;
500
+ let o6 = false;
501
+ if (void 0 === h3)
502
+ t4 = M(this, t4, i5, 0), o6 = !a2(t4) || t4 !== this._$AH && t4 !== E, o6 && (this._$AH = t4);
503
+ else {
504
+ const e6 = t4;
505
+ let n5, r6;
506
+ for (t4 = h3[0], n5 = 0; n5 < h3.length - 1; n5++)
507
+ r6 = M(this, e6[s4 + n5], i5, n5), r6 === E && (r6 = this._$AH[n5]), o6 || (o6 = !a2(r6) || r6 !== this._$AH[n5]), r6 === A ? t4 = A : t4 !== A && (t4 += (r6 ?? "") + h3[n5 + 1]), this._$AH[n5] = r6;
508
+ }
509
+ o6 && !e5 && this.j(t4);
510
+ }
511
+ j(t4) {
512
+ t4 === A ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t4 ?? "");
513
+ }
514
+ };
515
+ var I = class extends H {
516
+ constructor() {
517
+ super(...arguments), this.type = 3;
518
+ }
519
+ j(t4) {
520
+ this.element[this.name] = t4 === A ? void 0 : t4;
521
+ }
522
+ };
523
+ var L = class extends H {
524
+ constructor() {
525
+ super(...arguments), this.type = 4;
526
+ }
527
+ j(t4) {
528
+ this.element.toggleAttribute(this.name, !!t4 && t4 !== A);
529
+ }
530
+ };
531
+ var z = class extends H {
532
+ constructor(t4, i5, s4, e5, h3) {
533
+ super(t4, i5, s4, e5, h3), this.type = 5;
534
+ }
535
+ _$AI(t4, i5 = this) {
536
+ if ((t4 = M(this, t4, i5, 0) ?? A) === E)
537
+ return;
538
+ const s4 = this._$AH, e5 = t4 === A && s4 !== A || t4.capture !== s4.capture || t4.once !== s4.once || t4.passive !== s4.passive, h3 = t4 !== A && (s4 === A || e5);
539
+ e5 && this.element.removeEventListener(this.name, this, s4), h3 && this.element.addEventListener(this.name, this, t4), this._$AH = t4;
540
+ }
541
+ handleEvent(t4) {
542
+ "function" == typeof this._$AH ? this._$AH.call(this.options?.host ?? this.element, t4) : this._$AH.handleEvent(t4);
543
+ }
544
+ };
545
+ var Z = class {
546
+ constructor(t4, i5, s4) {
547
+ this.element = t4, this.type = 6, this._$AN = void 0, this._$AM = i5, this.options = s4;
548
+ }
549
+ get _$AU() {
550
+ return this._$AM._$AU;
551
+ }
552
+ _$AI(t4) {
553
+ M(this, t4);
554
+ }
555
+ };
556
+ var B = t2.litHtmlPolyfillSupport;
557
+ B?.(S2, k), (t2.litHtmlVersions ?? (t2.litHtmlVersions = [])).push("3.3.2");
558
+ var D = (t4, i5, s4) => {
559
+ const e5 = s4?.renderBefore ?? i5;
560
+ let h3 = e5._$litPart$;
561
+ if (void 0 === h3) {
562
+ const t5 = s4?.renderBefore ?? null;
563
+ e5._$litPart$ = h3 = new k(i5.insertBefore(c3(), t5), t5, void 0, s4 ?? {});
564
+ }
565
+ return h3._$AI(t4), h3;
566
+ };
567
+
568
+ // node_modules/lit-element/lit-element.js
569
+ var s3 = globalThis;
570
+ var i4 = class extends y {
571
+ constructor() {
572
+ super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0;
573
+ }
574
+ createRenderRoot() {
575
+ var _a;
576
+ const t4 = super.createRenderRoot();
577
+ return (_a = this.renderOptions).renderBefore ?? (_a.renderBefore = t4.firstChild), t4;
578
+ }
579
+ update(t4) {
580
+ const r6 = this.render();
581
+ this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t4), this._$Do = D(r6, this.renderRoot, this.renderOptions);
582
+ }
583
+ connectedCallback() {
584
+ super.connectedCallback(), this._$Do?.setConnected(true);
585
+ }
586
+ disconnectedCallback() {
587
+ super.disconnectedCallback(), this._$Do?.setConnected(false);
588
+ }
589
+ render() {
590
+ return E;
591
+ }
592
+ };
593
+ i4._$litElement$ = true, i4["finalized"] = true, s3.litElementHydrateSupport?.({ LitElement: i4 });
594
+ var o4 = s3.litElementPolyfillSupport;
595
+ o4?.({ LitElement: i4 });
596
+ (s3.litElementVersions ?? (s3.litElementVersions = [])).push("4.2.2");
597
+
598
+ // node_modules/@lit/reactive-element/decorators/custom-element.js
599
+ var t3 = (t4) => (e5, o6) => {
600
+ void 0 !== o6 ? o6.addInitializer(() => {
601
+ customElements.define(t4, e5);
602
+ }) : customElements.define(t4, e5);
603
+ };
604
+
605
+ // node_modules/@lit/reactive-element/decorators/property.js
606
+ var o5 = { attribute: true, type: String, converter: u, reflect: false, hasChanged: f };
607
+ var r4 = (t4 = o5, e5, r6) => {
608
+ const { kind: n5, metadata: i5 } = r6;
609
+ let s4 = globalThis.litPropertyMetadata.get(i5);
610
+ if (void 0 === s4 && globalThis.litPropertyMetadata.set(i5, s4 = /* @__PURE__ */ new Map()), "setter" === n5 && ((t4 = Object.create(t4)).wrapped = true), s4.set(r6.name, t4), "accessor" === n5) {
611
+ const { name: o6 } = r6;
612
+ return { set(r7) {
613
+ const n6 = e5.get.call(this);
614
+ e5.set.call(this, r7), this.requestUpdate(o6, n6, t4, true, r7);
615
+ }, init(e6) {
616
+ return void 0 !== e6 && this.C(o6, void 0, t4, e6), e6;
617
+ } };
618
+ }
619
+ if ("setter" === n5) {
620
+ const { name: o6 } = r6;
621
+ return function(r7) {
622
+ const n6 = this[o6];
623
+ e5.call(this, r7), this.requestUpdate(o6, n6, t4, true, r7);
624
+ };
625
+ }
626
+ throw Error("Unsupported decorator location: " + n5);
627
+ };
628
+ function n4(t4) {
629
+ return (e5, o6) => "object" == typeof o6 ? r4(t4, e5, o6) : ((t5, e6, o7) => {
630
+ const r6 = e6.hasOwnProperty(o7);
631
+ return e6.constructor.createProperty(o7, t5), r6 ? Object.getOwnPropertyDescriptor(e6, o7) : void 0;
632
+ })(t4, e5, o6);
633
+ }
634
+
635
+ // node_modules/@lit/reactive-element/decorators/state.js
636
+ function r5(r6) {
637
+ return n4({ ...r6, state: true, attribute: false });
638
+ }
639
+
640
+ // src/ui/styles.ts
641
+ var themeStyles = i`
642
+ /* Light theme */
643
+ :host([theme='light']) {
644
+ --xs-bg: #ffffff;
645
+ --xs-bg-header: #f5f5f5;
646
+ --xs-text: #1f2937;
647
+ --xs-text-muted: #6b7280;
648
+ --xs-border: #e5e7eb;
649
+ --xs-terminal-bg: #ffffff;
650
+ --xs-terminal-fg: #1f2937;
651
+ --xs-terminal-cursor: #1f2937;
652
+ --xs-terminal-selection: #b4d5fe;
653
+ --xs-btn-bg: #e5e7eb;
654
+ --xs-btn-text: #374151;
655
+ --xs-btn-hover: #d1d5db;
656
+ --xs-status-connected: #22c55e;
657
+ --xs-status-disconnected: #ef4444;
658
+ }
659
+
660
+ /* Dark theme (default) */
661
+ :host,
662
+ :host([theme='dark']) {
663
+ --xs-bg: #1e1e1e;
664
+ --xs-bg-header: #2d2d2d;
665
+ --xs-text: #cccccc;
666
+ --xs-text-muted: #808080;
667
+ --xs-border: #3e3e3e;
668
+ --xs-terminal-bg: #1e1e1e;
669
+ --xs-terminal-fg: #cccccc;
670
+ --xs-terminal-cursor: #ffffff;
671
+ --xs-terminal-selection: #264f78;
672
+ --xs-btn-bg: #3c3c3c;
673
+ --xs-btn-text: #cccccc;
674
+ --xs-btn-hover: #4a4a4a;
675
+ --xs-status-connected: #22c55e;
676
+ --xs-status-disconnected: #ef4444;
677
+ }
678
+
679
+ /* Auto theme - follows system preference */
680
+ :host([theme='auto']) {
681
+ --xs-bg: #1e1e1e;
682
+ --xs-bg-header: #2d2d2d;
683
+ --xs-text: #cccccc;
684
+ --xs-text-muted: #808080;
685
+ --xs-border: #3e3e3e;
686
+ --xs-terminal-bg: #1e1e1e;
687
+ --xs-terminal-fg: #cccccc;
688
+ --xs-terminal-cursor: #ffffff;
689
+ --xs-terminal-selection: #264f78;
690
+ --xs-btn-bg: #3c3c3c;
691
+ --xs-btn-text: #cccccc;
692
+ --xs-btn-hover: #4a4a4a;
693
+ --xs-status-connected: #22c55e;
694
+ --xs-status-disconnected: #ef4444;
695
+ }
696
+
697
+ @media (prefers-color-scheme: light) {
698
+ :host([theme='auto']) {
699
+ --xs-bg: #ffffff;
700
+ --xs-bg-header: #f5f5f5;
701
+ --xs-text: #1f2937;
702
+ --xs-text-muted: #6b7280;
703
+ --xs-border: #e5e7eb;
704
+ --xs-terminal-bg: #ffffff;
705
+ --xs-terminal-fg: #1f2937;
706
+ --xs-terminal-cursor: #1f2937;
707
+ --xs-terminal-selection: #b4d5fe;
708
+ --xs-btn-bg: #e5e7eb;
709
+ --xs-btn-text: #374151;
710
+ --xs-btn-hover: #d1d5db;
711
+ }
712
+ }
713
+ `;
714
+ var sharedStyles = i`
715
+ :host {
716
+ display: block;
717
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
718
+ Ubuntu, Cantarell, sans-serif;
719
+ font-size: 14px;
720
+ color: var(--xs-text);
721
+ background: var(--xs-bg);
722
+ }
723
+
724
+ * {
725
+ box-sizing: border-box;
726
+ }
727
+ `;
728
+ var buttonStyles = i`
729
+ button {
730
+ display: inline-flex;
731
+ align-items: center;
732
+ gap: 4px;
733
+ padding: 6px 12px;
734
+ border: none;
735
+ border-radius: 4px;
736
+ background: var(--xs-btn-bg);
737
+ color: var(--xs-btn-text);
738
+ font-size: 13px;
739
+ cursor: pointer;
740
+ transition: background-color 0.15s;
741
+ }
742
+
743
+ button:hover {
744
+ background: var(--xs-btn-hover);
745
+ }
746
+
747
+ button:disabled {
748
+ opacity: 0.5;
749
+ cursor: not-allowed;
750
+ }
751
+ `;
752
+
753
+ // src/client/terminal-client.ts
754
+ var TerminalClient = class {
755
+ constructor(config) {
756
+ this.ws = null;
757
+ this.state = "disconnected";
758
+ this.sessionId = null;
759
+ this.sessionInfo = null;
760
+ this.reconnectAttempts = 0;
761
+ this.reconnectTimeout = null;
762
+ // Event handlers
763
+ this.connectHandlers = [];
764
+ this.disconnectHandlers = [];
765
+ this.dataHandlers = [];
766
+ this.exitHandlers = [];
767
+ this.errorHandlers = [];
768
+ this.spawnedHandlers = [];
769
+ // Promise resolvers for spawn
770
+ this.spawnResolve = null;
771
+ this.spawnReject = null;
772
+ this.config = {
773
+ url: config.url,
774
+ reconnect: config.reconnect ?? true,
775
+ maxReconnectAttempts: config.maxReconnectAttempts ?? 10,
776
+ reconnectDelay: config.reconnectDelay ?? 1e3
777
+ };
778
+ }
779
+ /**
780
+ * Connect to the terminal server
781
+ */
782
+ connect() {
783
+ return new Promise((resolve, reject) => {
784
+ if (this.state === "connected") {
785
+ resolve();
786
+ return;
787
+ }
788
+ this.state = "connecting";
789
+ try {
790
+ this.ws = new WebSocket(this.config.url);
791
+ } catch (error) {
792
+ this.state = "disconnected";
793
+ reject(error);
794
+ return;
795
+ }
796
+ this.ws.onopen = () => {
797
+ this.state = "connected";
798
+ this.reconnectAttempts = 0;
799
+ this.connectHandlers.forEach((handler) => handler());
800
+ resolve();
801
+ };
802
+ this.ws.onclose = () => {
803
+ const wasConnected = this.state === "connected";
804
+ this.state = "disconnected";
805
+ this.sessionId = null;
806
+ this.sessionInfo = null;
807
+ if (wasConnected) {
808
+ this.disconnectHandlers.forEach((handler) => handler());
809
+ }
810
+ if (this.config.reconnect && this.reconnectAttempts < this.config.maxReconnectAttempts) {
811
+ this.scheduleReconnect();
812
+ }
813
+ };
814
+ this.ws.onerror = (event) => {
815
+ const error = new Error("WebSocket error");
816
+ this.errorHandlers.forEach((handler) => handler(error));
817
+ if (this.state === "connecting") {
818
+ reject(error);
819
+ }
820
+ };
821
+ this.ws.onmessage = (event) => {
822
+ this.handleMessage(event.data);
823
+ };
824
+ });
825
+ }
826
+ /**
827
+ * Disconnect from the terminal server
828
+ */
829
+ disconnect() {
830
+ this.config.reconnect = false;
831
+ if (this.reconnectTimeout) {
832
+ clearTimeout(this.reconnectTimeout);
833
+ this.reconnectTimeout = null;
834
+ }
835
+ if (this.ws) {
836
+ this.ws.close();
837
+ this.ws = null;
838
+ }
839
+ this.state = "disconnected";
840
+ this.sessionId = null;
841
+ this.sessionInfo = null;
842
+ }
843
+ /**
844
+ * Schedule a reconnection attempt
845
+ */
846
+ scheduleReconnect() {
847
+ if (this.reconnectTimeout)
848
+ return;
849
+ const delay = this.config.reconnectDelay * Math.pow(2, this.reconnectAttempts);
850
+ const maxDelay = 3e4;
851
+ this.reconnectTimeout = setTimeout(() => {
852
+ this.reconnectTimeout = null;
853
+ this.reconnectAttempts++;
854
+ this.connect().catch(() => {
855
+ });
856
+ }, Math.min(delay, maxDelay));
857
+ }
858
+ /**
859
+ * Handle incoming message
860
+ */
861
+ handleMessage(data) {
862
+ let message;
863
+ try {
864
+ message = JSON.parse(data);
865
+ } catch {
866
+ console.error("[x-shell] Invalid message:", data);
867
+ return;
868
+ }
869
+ switch (message.type) {
870
+ case "spawned":
871
+ this.sessionId = message.sessionId;
872
+ this.sessionInfo = {
873
+ sessionId: message.sessionId,
874
+ shell: message.shell,
875
+ cwd: message.cwd,
876
+ cols: message.cols,
877
+ rows: message.rows,
878
+ createdAt: /* @__PURE__ */ new Date()
879
+ };
880
+ this.spawnedHandlers.forEach((handler) => handler(this.sessionInfo));
881
+ if (this.spawnResolve) {
882
+ this.spawnResolve(this.sessionInfo);
883
+ this.spawnResolve = null;
884
+ this.spawnReject = null;
885
+ }
886
+ break;
887
+ case "data":
888
+ this.dataHandlers.forEach((handler) => handler(message.data));
889
+ break;
890
+ case "exit":
891
+ const exitCode = message.exitCode;
892
+ this.exitHandlers.forEach((handler) => handler(exitCode));
893
+ this.sessionId = null;
894
+ this.sessionInfo = null;
895
+ break;
896
+ case "error":
897
+ const error = new Error(message.error);
898
+ this.errorHandlers.forEach((handler) => handler(error));
899
+ if (this.spawnReject) {
900
+ this.spawnReject(error);
901
+ this.spawnResolve = null;
902
+ this.spawnReject = null;
903
+ }
904
+ break;
905
+ }
906
+ }
907
+ /**
908
+ * Spawn a terminal session
909
+ */
910
+ spawn(options = {}) {
911
+ return new Promise((resolve, reject) => {
912
+ if (this.state !== "connected" || !this.ws) {
913
+ reject(new Error("Not connected to server"));
914
+ return;
915
+ }
916
+ if (this.sessionId) {
917
+ reject(new Error("Session already spawned. Call kill() first."));
918
+ return;
919
+ }
920
+ this.spawnResolve = resolve;
921
+ this.spawnReject = reject;
922
+ this.ws.send(
923
+ JSON.stringify({
924
+ type: "spawn",
925
+ options
926
+ })
927
+ );
928
+ });
929
+ }
930
+ /**
931
+ * Write data to the terminal
932
+ */
933
+ write(data) {
934
+ if (!this.ws || this.state !== "connected") {
935
+ console.error("[x-shell] Cannot write: not connected");
936
+ return;
937
+ }
938
+ if (!this.sessionId) {
939
+ console.error("[x-shell] Cannot write: no active session");
940
+ return;
941
+ }
942
+ this.ws.send(
943
+ JSON.stringify({
944
+ type: "data",
945
+ sessionId: this.sessionId,
946
+ data
947
+ })
948
+ );
949
+ }
950
+ /**
951
+ * Resize the terminal
952
+ */
953
+ resize(cols, rows) {
954
+ if (!this.ws || this.state !== "connected") {
955
+ console.error("[x-shell] Cannot resize: not connected");
956
+ return;
957
+ }
958
+ if (!this.sessionId) {
959
+ console.error("[x-shell] Cannot resize: no active session");
960
+ return;
961
+ }
962
+ this.ws.send(
963
+ JSON.stringify({
964
+ type: "resize",
965
+ sessionId: this.sessionId,
966
+ cols,
967
+ rows
968
+ })
969
+ );
970
+ }
971
+ /**
972
+ * Kill the terminal session
973
+ */
974
+ kill() {
975
+ if (!this.ws || this.state !== "connected") {
976
+ return;
977
+ }
978
+ if (!this.sessionId) {
979
+ return;
980
+ }
981
+ this.ws.send(
982
+ JSON.stringify({
983
+ type: "close",
984
+ sessionId: this.sessionId
985
+ })
986
+ );
987
+ this.sessionId = null;
988
+ this.sessionInfo = null;
989
+ }
990
+ // ==========================================
991
+ // Event handlers
992
+ // ==========================================
993
+ /**
994
+ * Called when connected to server
995
+ */
996
+ onConnect(handler) {
997
+ this.connectHandlers.push(handler);
998
+ }
999
+ /**
1000
+ * Called when disconnected from server
1001
+ */
1002
+ onDisconnect(handler) {
1003
+ this.disconnectHandlers.push(handler);
1004
+ }
1005
+ /**
1006
+ * Called when data is received from the terminal
1007
+ */
1008
+ onData(handler) {
1009
+ this.dataHandlers.push(handler);
1010
+ }
1011
+ /**
1012
+ * Called when the terminal session exits
1013
+ */
1014
+ onExit(handler) {
1015
+ this.exitHandlers.push(handler);
1016
+ }
1017
+ /**
1018
+ * Called when an error occurs
1019
+ */
1020
+ onError(handler) {
1021
+ this.errorHandlers.push(handler);
1022
+ }
1023
+ /**
1024
+ * Called when a session is spawned
1025
+ */
1026
+ onSpawned(handler) {
1027
+ this.spawnedHandlers.push(handler);
1028
+ }
1029
+ // ==========================================
1030
+ // Getters
1031
+ // ==========================================
1032
+ /**
1033
+ * Get current connection state
1034
+ */
1035
+ getState() {
1036
+ return this.state;
1037
+ }
1038
+ /**
1039
+ * Check if connected
1040
+ */
1041
+ isConnected() {
1042
+ return this.state === "connected";
1043
+ }
1044
+ /**
1045
+ * Get current session ID
1046
+ */
1047
+ getSessionId() {
1048
+ return this.sessionId;
1049
+ }
1050
+ /**
1051
+ * Get current session info
1052
+ */
1053
+ getSessionInfo() {
1054
+ return this.sessionInfo;
1055
+ }
1056
+ /**
1057
+ * Check if a session is active
1058
+ */
1059
+ hasActiveSession() {
1060
+ return this.sessionId !== null;
1061
+ }
1062
+ };
1063
+
1064
+ // src/ui/x-shell-terminal.ts
1065
+ var XShellTerminal = class extends i4 {
1066
+ constructor() {
1067
+ super(...arguments);
1068
+ this.url = "";
1069
+ this.shell = "";
1070
+ this.cwd = "";
1071
+ this.cols = 80;
1072
+ this.rows = 24;
1073
+ this.theme = "dark";
1074
+ this.noHeader = false;
1075
+ this.autoConnect = false;
1076
+ this.autoSpawn = false;
1077
+ this.fontSize = 14;
1078
+ this.fontFamily = 'Menlo, Monaco, "Courier New", monospace';
1079
+ this.client = null;
1080
+ this.terminal = null;
1081
+ this.fitAddon = null;
1082
+ this.connected = false;
1083
+ this.sessionActive = false;
1084
+ this.loading = false;
1085
+ this.error = null;
1086
+ this.sessionInfo = null;
1087
+ // xterm.js module (loaded dynamically)
1088
+ this.xtermModule = null;
1089
+ this.fitAddonModule = null;
1090
+ this.resizeObserver = null;
1091
+ }
1092
+ connectedCallback() {
1093
+ super.connectedCallback();
1094
+ if (this.autoConnect && this.url) {
1095
+ this.connect();
1096
+ }
1097
+ }
1098
+ disconnectedCallback() {
1099
+ super.disconnectedCallback();
1100
+ this.cleanup();
1101
+ }
1102
+ /**
1103
+ * Load xterm.js dynamically
1104
+ */
1105
+ async loadXterm() {
1106
+ if (this.xtermModule)
1107
+ return;
1108
+ try {
1109
+ this.xtermModule = await import("https://cdn.jsdelivr.net/npm/xterm@5.3.0/+esm");
1110
+ this.fitAddonModule = await import("https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.8.0/+esm");
1111
+ } catch (e5) {
1112
+ try {
1113
+ this.xtermModule = await import("xterm");
1114
+ this.fitAddonModule = await import("xterm-addon-fit");
1115
+ } catch {
1116
+ throw new Error("Failed to load xterm.js. Make sure it is available.");
1117
+ }
1118
+ }
1119
+ }
1120
+ /**
1121
+ * Connect to the terminal server
1122
+ */
1123
+ async connect() {
1124
+ if (!this.url) {
1125
+ this.error = "No URL specified";
1126
+ return;
1127
+ }
1128
+ this.loading = true;
1129
+ this.error = null;
1130
+ try {
1131
+ await this.loadXterm();
1132
+ this.client = new TerminalClient({ url: this.url });
1133
+ this.client.onConnect(() => {
1134
+ this.connected = true;
1135
+ this.dispatchEvent(new CustomEvent("connect", { bubbles: true, composed: true }));
1136
+ if (this.autoSpawn) {
1137
+ this.spawn();
1138
+ }
1139
+ });
1140
+ this.client.onDisconnect(() => {
1141
+ this.connected = false;
1142
+ this.sessionActive = false;
1143
+ this.dispatchEvent(new CustomEvent("disconnect", { bubbles: true, composed: true }));
1144
+ });
1145
+ this.client.onError((err) => {
1146
+ this.error = err.message;
1147
+ this.dispatchEvent(
1148
+ new CustomEvent("error", { detail: { error: err }, bubbles: true, composed: true })
1149
+ );
1150
+ });
1151
+ this.client.onData((data) => {
1152
+ if (this.terminal) {
1153
+ this.terminal.write(data);
1154
+ }
1155
+ });
1156
+ this.client.onExit((code) => {
1157
+ this.sessionActive = false;
1158
+ this.sessionInfo = null;
1159
+ if (this.terminal) {
1160
+ this.terminal.writeln("");
1161
+ this.terminal.writeln(`\x1B[1;33m[Process exited with code: ${code}]\x1B[0m`);
1162
+ }
1163
+ this.dispatchEvent(
1164
+ new CustomEvent("exit", { detail: { exitCode: code }, bubbles: true, composed: true })
1165
+ );
1166
+ });
1167
+ this.client.onSpawned((info) => {
1168
+ this.sessionInfo = info;
1169
+ this.dispatchEvent(
1170
+ new CustomEvent("spawned", { detail: { session: info }, bubbles: true, composed: true })
1171
+ );
1172
+ });
1173
+ await this.client.connect();
1174
+ } catch (err) {
1175
+ this.error = err instanceof Error ? err.message : "Connection failed";
1176
+ } finally {
1177
+ this.loading = false;
1178
+ }
1179
+ }
1180
+ /**
1181
+ * Disconnect from the server
1182
+ */
1183
+ disconnect() {
1184
+ if (this.client) {
1185
+ this.client.disconnect();
1186
+ this.client = null;
1187
+ }
1188
+ this.connected = false;
1189
+ this.sessionActive = false;
1190
+ }
1191
+ /**
1192
+ * Spawn a terminal session
1193
+ */
1194
+ async spawn(options) {
1195
+ if (!this.client || !this.connected) {
1196
+ throw new Error("Not connected to server");
1197
+ }
1198
+ this.loading = true;
1199
+ this.error = null;
1200
+ try {
1201
+ await this.initTerminalUI();
1202
+ const spawnOptions = {
1203
+ shell: options?.shell || this.shell || void 0,
1204
+ cwd: options?.cwd || this.cwd || void 0,
1205
+ cols: this.terminal?.cols || this.cols,
1206
+ rows: this.terminal?.rows || this.rows,
1207
+ env: options?.env
1208
+ };
1209
+ const info = await this.client.spawn(spawnOptions);
1210
+ this.sessionActive = true;
1211
+ this.sessionInfo = info;
1212
+ if (this.terminal) {
1213
+ this.terminal.focus();
1214
+ }
1215
+ } catch (err) {
1216
+ this.error = err instanceof Error ? err.message : "Failed to spawn session";
1217
+ } finally {
1218
+ this.loading = false;
1219
+ }
1220
+ }
1221
+ /**
1222
+ * Initialize xterm.js UI
1223
+ */
1224
+ async initTerminalUI() {
1225
+ if (this.terminal)
1226
+ return;
1227
+ await this.loadXterm();
1228
+ await this.updateComplete;
1229
+ const container = this.shadowRoot?.querySelector(".terminal-container");
1230
+ if (!container)
1231
+ return;
1232
+ const terminalTheme = this.getTerminalTheme();
1233
+ const Terminal = this.xtermModule.Terminal;
1234
+ const term = new Terminal({
1235
+ cursorBlink: true,
1236
+ fontSize: this.fontSize,
1237
+ fontFamily: this.fontFamily,
1238
+ theme: terminalTheme,
1239
+ cols: this.cols,
1240
+ rows: this.rows
1241
+ });
1242
+ const FitAddon = this.fitAddonModule.FitAddon;
1243
+ const fit = new FitAddon();
1244
+ this.terminal = term;
1245
+ this.fitAddon = fit;
1246
+ term.loadAddon(fit);
1247
+ term.open(container);
1248
+ fit.fit();
1249
+ term.onData((data) => {
1250
+ if (this.client && this.sessionActive) {
1251
+ this.client.write(data);
1252
+ }
1253
+ });
1254
+ term.onResize(({ cols, rows }) => {
1255
+ if (this.client && this.sessionActive) {
1256
+ this.client.resize(cols, rows);
1257
+ }
1258
+ });
1259
+ this.resizeObserver = new ResizeObserver(() => {
1260
+ if (this.fitAddon) {
1261
+ this.fitAddon.fit();
1262
+ }
1263
+ });
1264
+ this.resizeObserver.observe(container);
1265
+ }
1266
+ /**
1267
+ * Get terminal theme based on component theme
1268
+ */
1269
+ getTerminalTheme() {
1270
+ if (this.theme === "light") {
1271
+ return {
1272
+ background: "#ffffff",
1273
+ foreground: "#1f2937",
1274
+ cursor: "#1f2937",
1275
+ selection: "#b4d5fe"
1276
+ };
1277
+ }
1278
+ return {
1279
+ background: "#1e1e1e",
1280
+ foreground: "#cccccc",
1281
+ cursor: "#ffffff",
1282
+ selection: "#264f78"
1283
+ };
1284
+ }
1285
+ /**
1286
+ * Kill the current session
1287
+ */
1288
+ kill() {
1289
+ if (this.client) {
1290
+ this.client.kill();
1291
+ }
1292
+ this.sessionActive = false;
1293
+ this.sessionInfo = null;
1294
+ }
1295
+ /**
1296
+ * Clear the terminal
1297
+ */
1298
+ clear() {
1299
+ if (this.terminal) {
1300
+ this.terminal.clear();
1301
+ }
1302
+ }
1303
+ /**
1304
+ * Write data to the terminal (display only, not sent to server)
1305
+ */
1306
+ write(data) {
1307
+ if (this.terminal) {
1308
+ this.terminal.write(data);
1309
+ }
1310
+ }
1311
+ /**
1312
+ * Write line to the terminal (display only, not sent to server)
1313
+ */
1314
+ writeln(data) {
1315
+ if (this.terminal) {
1316
+ this.terminal.writeln(data);
1317
+ }
1318
+ }
1319
+ /**
1320
+ * Focus the terminal
1321
+ */
1322
+ focus() {
1323
+ if (this.terminal) {
1324
+ this.terminal.focus();
1325
+ }
1326
+ }
1327
+ /**
1328
+ * Cleanup resources
1329
+ */
1330
+ cleanup() {
1331
+ if (this.resizeObserver) {
1332
+ this.resizeObserver.disconnect();
1333
+ this.resizeObserver = null;
1334
+ }
1335
+ if (this.terminal) {
1336
+ this.terminal.dispose();
1337
+ this.terminal = null;
1338
+ }
1339
+ if (this.client) {
1340
+ this.client.disconnect();
1341
+ this.client = null;
1342
+ }
1343
+ this.fitAddon = null;
1344
+ }
1345
+ render() {
1346
+ return b2`
1347
+ ${this.noHeader ? A : b2`
1348
+ <div class="header">
1349
+ <div class="header-title">
1350
+ <span>Terminal</span>
1351
+ ${this.sessionInfo ? b2`<span style="font-weight: normal; font-size: 12px; color: var(--xs-text-muted)">
1352
+ ${this.sessionInfo.shell}
1353
+ </span>` : A}
1354
+ </div>
1355
+ <div class="header-actions">
1356
+ ${!this.connected ? b2`<button @click=${this.connect} ?disabled=${this.loading}>
1357
+ ${this.loading ? "Connecting..." : "Connect"}
1358
+ </button>` : !this.sessionActive ? b2`<button @click=${() => this.spawn()} ?disabled=${this.loading}>
1359
+ ${this.loading ? "Spawning..." : "Start"}
1360
+ </button>` : b2`<button @click=${this.kill}>Stop</button>`}
1361
+ <button @click=${this.clear} ?disabled=${!this.sessionActive}>Clear</button>
1362
+ <div class="status">
1363
+ <span class="status-dot ${this.connected ? "connected" : ""}"></span>
1364
+ <span>${this.connected ? "Connected" : "Disconnected"}</span>
1365
+ </div>
1366
+ </div>
1367
+ </div>
1368
+ `}
1369
+
1370
+ <div class="terminal-container">
1371
+ ${this.loading && !this.terminal ? b2`<div class="loading"><span class="loading-spinner">⏳</span> Loading...</div>` : this.error && !this.terminal ? b2`<div class="error">❌ ${this.error}</div>` : A}
1372
+ </div>
1373
+ `;
1374
+ }
1375
+ };
1376
+ XShellTerminal.styles = [
1377
+ sharedStyles,
1378
+ themeStyles,
1379
+ buttonStyles,
1380
+ i`
1381
+ :host {
1382
+ display: flex;
1383
+ flex-direction: column;
1384
+ height: 100%;
1385
+ min-height: 200px;
1386
+ border: 1px solid var(--xs-border);
1387
+ border-radius: 4px;
1388
+ overflow: hidden;
1389
+ }
1390
+
1391
+ .header {
1392
+ display: flex;
1393
+ align-items: center;
1394
+ justify-content: space-between;
1395
+ padding: 8px 12px;
1396
+ background: var(--xs-bg-header);
1397
+ border-bottom: 1px solid var(--xs-border);
1398
+ }
1399
+
1400
+ .header-title {
1401
+ display: flex;
1402
+ align-items: center;
1403
+ gap: 8px;
1404
+ font-weight: 600;
1405
+ }
1406
+
1407
+ .header-actions {
1408
+ display: flex;
1409
+ gap: 8px;
1410
+ }
1411
+
1412
+ .status {
1413
+ display: flex;
1414
+ align-items: center;
1415
+ gap: 6px;
1416
+ font-size: 12px;
1417
+ color: var(--xs-text-muted);
1418
+ }
1419
+
1420
+ .status-dot {
1421
+ width: 8px;
1422
+ height: 8px;
1423
+ border-radius: 50%;
1424
+ background: var(--xs-status-disconnected);
1425
+ }
1426
+
1427
+ .status-dot.connected {
1428
+ background: var(--xs-status-connected);
1429
+ }
1430
+
1431
+ .terminal-container {
1432
+ flex: 1;
1433
+ padding: 4px;
1434
+ background: var(--xs-terminal-bg);
1435
+ overflow: hidden;
1436
+ }
1437
+
1438
+ .terminal-container .xterm {
1439
+ height: 100%;
1440
+ }
1441
+
1442
+ .terminal-container .xterm-viewport {
1443
+ overflow-y: auto;
1444
+ }
1445
+
1446
+ .loading,
1447
+ .error {
1448
+ display: flex;
1449
+ align-items: center;
1450
+ justify-content: center;
1451
+ height: 100%;
1452
+ padding: 20px;
1453
+ text-align: center;
1454
+ color: var(--xs-text-muted);
1455
+ }
1456
+
1457
+ .error {
1458
+ color: #ef4444;
1459
+ }
1460
+
1461
+ .loading-spinner {
1462
+ animation: spin 1s linear infinite;
1463
+ margin-right: 8px;
1464
+ }
1465
+
1466
+ @keyframes spin {
1467
+ from {
1468
+ transform: rotate(0deg);
1469
+ }
1470
+ to {
1471
+ transform: rotate(360deg);
1472
+ }
1473
+ }
1474
+
1475
+ /* Hide header if requested */
1476
+ :host([no-header]) .header {
1477
+ display: none;
1478
+ }
1479
+ `
1480
+ ];
1481
+ __decorateClass([
1482
+ n4({ type: String })
1483
+ ], XShellTerminal.prototype, "url", 2);
1484
+ __decorateClass([
1485
+ n4({ type: String })
1486
+ ], XShellTerminal.prototype, "shell", 2);
1487
+ __decorateClass([
1488
+ n4({ type: String })
1489
+ ], XShellTerminal.prototype, "cwd", 2);
1490
+ __decorateClass([
1491
+ n4({ type: Number })
1492
+ ], XShellTerminal.prototype, "cols", 2);
1493
+ __decorateClass([
1494
+ n4({ type: Number })
1495
+ ], XShellTerminal.prototype, "rows", 2);
1496
+ __decorateClass([
1497
+ n4({ type: String, reflect: true })
1498
+ ], XShellTerminal.prototype, "theme", 2);
1499
+ __decorateClass([
1500
+ n4({ type: Boolean, attribute: "no-header" })
1501
+ ], XShellTerminal.prototype, "noHeader", 2);
1502
+ __decorateClass([
1503
+ n4({ type: Boolean, attribute: "auto-connect" })
1504
+ ], XShellTerminal.prototype, "autoConnect", 2);
1505
+ __decorateClass([
1506
+ n4({ type: Boolean, attribute: "auto-spawn" })
1507
+ ], XShellTerminal.prototype, "autoSpawn", 2);
1508
+ __decorateClass([
1509
+ n4({ type: Number, attribute: "font-size" })
1510
+ ], XShellTerminal.prototype, "fontSize", 2);
1511
+ __decorateClass([
1512
+ n4({ type: String, attribute: "font-family" })
1513
+ ], XShellTerminal.prototype, "fontFamily", 2);
1514
+ __decorateClass([
1515
+ r5()
1516
+ ], XShellTerminal.prototype, "client", 2);
1517
+ __decorateClass([
1518
+ r5()
1519
+ ], XShellTerminal.prototype, "terminal", 2);
1520
+ __decorateClass([
1521
+ r5()
1522
+ ], XShellTerminal.prototype, "fitAddon", 2);
1523
+ __decorateClass([
1524
+ r5()
1525
+ ], XShellTerminal.prototype, "connected", 2);
1526
+ __decorateClass([
1527
+ r5()
1528
+ ], XShellTerminal.prototype, "sessionActive", 2);
1529
+ __decorateClass([
1530
+ r5()
1531
+ ], XShellTerminal.prototype, "loading", 2);
1532
+ __decorateClass([
1533
+ r5()
1534
+ ], XShellTerminal.prototype, "error", 2);
1535
+ __decorateClass([
1536
+ r5()
1537
+ ], XShellTerminal.prototype, "sessionInfo", 2);
1538
+ XShellTerminal = __decorateClass([
1539
+ t3("x-shell-terminal")
1540
+ ], XShellTerminal);
1541
+ export {
1542
+ XShellTerminal,
1543
+ buttonStyles,
1544
+ sharedStyles,
1545
+ themeStyles
1546
+ };
1547
+ /*! Bundled license information:
1548
+
1549
+ @lit/reactive-element/css-tag.js:
1550
+ (**
1551
+ * @license
1552
+ * Copyright 2019 Google LLC
1553
+ * SPDX-License-Identifier: BSD-3-Clause
1554
+ *)
1555
+
1556
+ @lit/reactive-element/reactive-element.js:
1557
+ (**
1558
+ * @license
1559
+ * Copyright 2017 Google LLC
1560
+ * SPDX-License-Identifier: BSD-3-Clause
1561
+ *)
1562
+
1563
+ lit-html/lit-html.js:
1564
+ (**
1565
+ * @license
1566
+ * Copyright 2017 Google LLC
1567
+ * SPDX-License-Identifier: BSD-3-Clause
1568
+ *)
1569
+
1570
+ lit-element/lit-element.js:
1571
+ (**
1572
+ * @license
1573
+ * Copyright 2017 Google LLC
1574
+ * SPDX-License-Identifier: BSD-3-Clause
1575
+ *)
1576
+
1577
+ lit-html/is-server.js:
1578
+ (**
1579
+ * @license
1580
+ * Copyright 2022 Google LLC
1581
+ * SPDX-License-Identifier: BSD-3-Clause
1582
+ *)
1583
+
1584
+ @lit/reactive-element/decorators/custom-element.js:
1585
+ (**
1586
+ * @license
1587
+ * Copyright 2017 Google LLC
1588
+ * SPDX-License-Identifier: BSD-3-Clause
1589
+ *)
1590
+
1591
+ @lit/reactive-element/decorators/property.js:
1592
+ (**
1593
+ * @license
1594
+ * Copyright 2017 Google LLC
1595
+ * SPDX-License-Identifier: BSD-3-Clause
1596
+ *)
1597
+
1598
+ @lit/reactive-element/decorators/state.js:
1599
+ (**
1600
+ * @license
1601
+ * Copyright 2017 Google LLC
1602
+ * SPDX-License-Identifier: BSD-3-Clause
1603
+ *)
1604
+
1605
+ @lit/reactive-element/decorators/event-options.js:
1606
+ (**
1607
+ * @license
1608
+ * Copyright 2017 Google LLC
1609
+ * SPDX-License-Identifier: BSD-3-Clause
1610
+ *)
1611
+
1612
+ @lit/reactive-element/decorators/base.js:
1613
+ (**
1614
+ * @license
1615
+ * Copyright 2017 Google LLC
1616
+ * SPDX-License-Identifier: BSD-3-Clause
1617
+ *)
1618
+
1619
+ @lit/reactive-element/decorators/query.js:
1620
+ (**
1621
+ * @license
1622
+ * Copyright 2017 Google LLC
1623
+ * SPDX-License-Identifier: BSD-3-Clause
1624
+ *)
1625
+
1626
+ @lit/reactive-element/decorators/query-all.js:
1627
+ (**
1628
+ * @license
1629
+ * Copyright 2017 Google LLC
1630
+ * SPDX-License-Identifier: BSD-3-Clause
1631
+ *)
1632
+
1633
+ @lit/reactive-element/decorators/query-async.js:
1634
+ (**
1635
+ * @license
1636
+ * Copyright 2017 Google LLC
1637
+ * SPDX-License-Identifier: BSD-3-Clause
1638
+ *)
1639
+
1640
+ @lit/reactive-element/decorators/query-assigned-elements.js:
1641
+ (**
1642
+ * @license
1643
+ * Copyright 2021 Google LLC
1644
+ * SPDX-License-Identifier: BSD-3-Clause
1645
+ *)
1646
+
1647
+ @lit/reactive-element/decorators/query-assigned-nodes.js:
1648
+ (**
1649
+ * @license
1650
+ * Copyright 2017 Google LLC
1651
+ * SPDX-License-Identifier: BSD-3-Clause
1652
+ *)
1653
+ */
1654
+ //# sourceMappingURL=browser-bundle.js.map