@useonsite/vite 0.0.0-stage → 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.
@@ -0,0 +1,4393 @@
1
+ // ../core/src/contracts.ts
2
+ var e = "data-onsite-src", t = "data-onsite-comp", n = 8192, r = (e, t) => `${e} ${t}${e === 1 ? "" : "s"}`, i = (e) => e.split("/").pop() ?? e, a = (e) => {
3
+ let t = e.lastIndexOf("/");
4
+ return t < 0 ? "" : e.slice(0, t + 1);
5
+ }, o = (e) => e.replace(/:\d+(:\d+)?$/, ""), s = (e) => /:(\d+)(?::\d+)?$/.exec(e)?.[1] ?? "";
6
+ function c(e) {
7
+ let t = s(e);
8
+ return `${i(o(e))}${t ? `:${t}` : ""}`;
9
+ }
10
+ function l(e) {
11
+ let t = s(e.src), n = `${o(e.src)}${t ? `:${t}` : ""}`;
12
+ return e.comp ? `${e.comp} · ${n}` : n;
13
+ }
14
+ var u = (e) => `Take ${e}`;
15
+ function d(e) {
16
+ return `Queued · ${[
17
+ "next",
18
+ "2nd",
19
+ "3rd"
20
+ ][e] ?? `${e + 1}th`}`;
21
+ }
22
+ function f(e) {
23
+ return e.length === 0 ? "" : e.length === 1 ? u(e[0]) : `Takes ${e.slice(0, -1).join(", ")} and ${e.at(-1)}`;
24
+ }
25
+ function p(e, t = !1) {
26
+ return t && e.label ? `${u(e.no)} · ${e.label}` : u(e.no);
27
+ }
28
+ function m(e, t, n) {
29
+ let r = new Set(t.map((e) => e.of)).size > 1, i = n.indexOf(e.of) + 1;
30
+ return r && i > 0 ? `${u(e.no)} · ask ${i}` : u(e.no);
31
+ }
32
+ var h = "Older code";
33
+ function g(e) {
34
+ return `${u(e.no)} was made on an older version of ${_(e.stale ?? [])}. Showing it may break the page.`;
35
+ }
36
+ function _(e) {
37
+ let t = e.map(i);
38
+ return t.length < 2 ? t[0] ?? "" : `${t.slice(0, -1).join(", ")} and ${t.at(-1)}`;
39
+ }
40
+ function ee(e, t, n) {
41
+ if (!e.covered?.length) return null;
42
+ let r = /* @__PURE__ */ new Map();
43
+ for (let i of e.covered) {
44
+ let e = t.find((e) => e.id === i.by), a = e ? n.indexOf(e.of) + 1 : 0, o = r.get(a) ?? {
45
+ take: e,
46
+ paths: []
47
+ };
48
+ o.paths.push(i.path), r.set(a, o);
49
+ }
50
+ let i = (e) => e > 0 ? `ask ${e}` : "a newer ask", a = _(e.covered.map((e) => e.path)), o = r.size === 1 ? `${te(i([...r.keys()][0]))} holds ${a}` : `Newer asks hold ${a}`, s = [...r].map(([e, t]) => `${_(t.paths)} shows ${t.take ? `${u(t.take.no)} of ${i(e)}` : i(e)}, which is newer.`), c = r.size === 1 ? `Show the original for ${i([...r.keys()][0])} to see ${u(e.no)}'s version.` : `Show the original for those asks to see ${u(e.no)}'s version.`;
51
+ return {
52
+ text: o,
53
+ title: [...s, c].join(" ")
54
+ };
55
+ }
56
+ var te = (e) => e.charAt(0).toUpperCase() + e.slice(1);
57
+ function ne(e) {
58
+ return `${u(e.no)} was made on an older version of ${_(e.stale ?? [])}, so Onsite shows the original.`;
59
+ }
60
+ function v(e, t) {
61
+ if (e.tool === "src_read") return `Read ${i(e.path)}`;
62
+ if (e.tool === "src_list") return `Listed ${e.path || "the source folder"}`;
63
+ let n = "";
64
+ e.from !== void 0 && e.to !== void 0 && (n = e.from > e.to ? ` · removed lines at ${e.from}` : e.from === e.to ? ` · line ${e.from}` : ` · lines ${e.from}–${e.to}`);
65
+ let r = t && e.take ? ` · ${u(e.take)}` : "";
66
+ return `${i(e.path)}${n}${r}`;
67
+ }
68
+ function re(e, t) {
69
+ let n = Date.parse(t ?? "") - Date.parse(e ?? "");
70
+ return !Number.isFinite(n) || n < 0 ? "" : n < 6e4 ? `${(n / 1e3).toFixed(1)} s` : `${Math.floor(n / 6e4)} min ${Math.round(n % 6e4 / 1e3)} s`;
71
+ }
72
+ var ie = (e) => e === void 0 ? "" : `$${e < .01 && e > 0 ? e.toFixed(3) : e.toFixed(2)}`;
73
+ function ae(e) {
74
+ return new Set(e.flatMap((e) => e.files.map((e) => e.path))).size;
75
+ }
76
+ function oe(e, t, n) {
77
+ let i = e.takes ?? [], a = n.filter((t) => t.of === e.id && i.includes(t.no)), o = e.files?.length ?? ae(a), s = [i.length ? f(i) : "No take", o ? r(o, "file") : ""];
78
+ return s.push(re(t?.at, e.at), ie(e.costUSD)), s.filter(Boolean).join(" · ");
79
+ }
80
+ function se(e, t) {
81
+ let n = e.takes ?? [], i = ae(t.filter((t) => t.of === e.id && n.includes(t.no)));
82
+ return !n.length || !i ? "Stopped before any change" : `Stopped · ${n.length === 1 ? u(n[0]) : "The takes"} ${n.length === 1 ? "keeps" : "keep"} the ${r(i, "file")} written so far`;
83
+ }
84
+ function ce(e) {
85
+ let t = e.take ? u(e.take) : "the take", n = e.files?.length ?? 0;
86
+ return e.kind === "keep" ? `Kept ${t}${n ? ` · ${r(n, "file")} written` : ""}` : e.kind === "skip" ? `Skipped ${t} · no file changed` : "Undone";
87
+ }
88
+ var le = {
89
+ pages: "Pages",
90
+ components: "Components",
91
+ styles: "Styles",
92
+ other: "Other"
93
+ };
94
+ // src/base.ts
95
+ function ue(e, t) {
96
+ let n = (t) => e.takes.find((e) => e.id === t), r = (t) => t?.state === "open" && t.of !== e.running && !e.queue?.includes(t.of), i = e.showing.flatMap((e) => {
97
+ let t = n(e);
98
+ return t?.state === "open" ? [t] : [];
99
+ }), a = /* @__PURE__ */ new Set();
100
+ for (let e of t) {
101
+ let t = e ? o(e) : "", n = t ? i.findLast((e) => e.files.some((e) => e.path === t)) : void 0;
102
+ n && a.add(n);
103
+ }
104
+ if (a.size > 0) {
105
+ let e = i.filter((e) => a.has(e)).findLast(r);
106
+ return e ? {
107
+ take: e,
108
+ asks: new Set([...a].map((e) => e.of)).size
109
+ } : void 0;
110
+ }
111
+ let s = e.shown ? n(e.shown) : void 0;
112
+ return r(s) ? {
113
+ take: s,
114
+ asks: 0
115
+ } : void 0;
116
+ }
117
+ function de(e, t, n, r) {
118
+ let i = n.indexOf(e.take.of) + 1, a = e.asks > 1 && i > 0, o = a ? `${u(e.take.no)} of ask ${i}` : t;
119
+ return r ? `it builds on ${o}` : a ? `On ${o}, the newer ask` : `On ${o}`;
120
+ }
121
+ // src/client.ts
122
+ var fe = class extends Error {
123
+ code;
124
+ status;
125
+ constructor(e, t, n) {
126
+ super(t), this.name = "RouteError", this.code = e, this.status = n;
127
+ }
128
+ };
129
+ function pe(e = {}) {
130
+ let t = e.prefix ?? "/__onsite/";
131
+ return { async call(n, r) {
132
+ let [i, a] = n.split(" "), o = t + a, s = {
133
+ method: i,
134
+ credentials: "same-origin",
135
+ headers: { Accept: "application/json" }
136
+ };
137
+ if (i === "GET") {
138
+ let e = new URLSearchParams();
139
+ for (let [t, n] of Object.entries(r)) n !== void 0 && e.set(t, String(n));
140
+ let t = e.toString();
141
+ t && (o += `?${t}`);
142
+ } else s.headers = {
143
+ Accept: "application/json",
144
+ "Content-Type": "application/json"
145
+ }, s.body = JSON.stringify(r);
146
+ let c;
147
+ try {
148
+ c = await (e.fetch ?? fetch)(o, s);
149
+ } catch (e) {
150
+ throw new fe("internal", `Onsite did not answer: ${e.message}`, 0);
151
+ }
152
+ let l = await c.json().catch(() => null);
153
+ if (!c.ok) {
154
+ let e = l?.error;
155
+ throw new fe(e?.code ?? "internal", e?.message ?? `Onsite answered ${c.status}.`, c.status);
156
+ }
157
+ return l;
158
+ } };
159
+ }
160
+ async function me(e = "/__onsite/overlay.js") {
161
+ try {
162
+ return (await import(
163
+ /* @vite-ignore */
164
+ "/@vite/client"
165
+ )).createHotContext?.(e) ?? null;
166
+ } catch {
167
+ return null;
168
+ }
169
+ }
170
+ function he(e, t, n) {
171
+ e.on(t, (e) => n(e));
172
+ }
173
+ function ge(e, t, n) {
174
+ let r = -1, i = 0, a = (e) => {
175
+ e.seq < r || (r = e.seq, n.state(e));
176
+ }, o = async () => {
177
+ let t = i;
178
+ try {
179
+ let a = await e.call("GET state", {});
180
+ if (i !== t && a.seq < r) return;
181
+ r = a.seq, n.state(a);
182
+ } catch (e) {
183
+ n.error?.(e);
184
+ }
185
+ };
186
+ return t && (he(t, "onsite:state", (e) => {
187
+ i += 1, a(e);
188
+ }), he(t, "onsite:text", (e) => n.text(e)), he(t, "onsite:flash", (e) => n.flash(e)), t.on("vite:afterUpdate", () => n.afterUpdate()), t.on("vite:ws:connect", () => void o())), o(), { refresh: o };
189
+ }
190
+ // src/context/cut.ts
191
+ var _e = new TextEncoder(), ve = new TextDecoder();
192
+ function ye(e, t) {
193
+ let n = _e.encode(e);
194
+ if (n.length <= t) return {
195
+ text: e,
196
+ cut: !1
197
+ };
198
+ let r = t;
199
+ for (; r > 0 && ((n[r] ?? 0) & 192) == 128;) r--;
200
+ return {
201
+ text: ve.decode(n.subarray(0, r)),
202
+ cut: !0
203
+ };
204
+ }
205
+ function be(e) {
206
+ for (let t = e; t; t = t.parentElement) for (let e of Object.keys(t)) if (e.startsWith("__reactFiber$") || e.startsWith("__reactInternalInstance$")) return t[e] ?? null;
207
+ return null;
208
+ }
209
+ function y(e, t = 0) {
210
+ if (t > 3 || !e) return null;
211
+ if (typeof e == "function") {
212
+ let t = e;
213
+ return typeof t.displayName == "string" && t.displayName || typeof t.name == "string" && t.name || null;
214
+ }
215
+ if (typeof e == "object") {
216
+ let n = e;
217
+ return typeof n.displayName == "string" && n.displayName ? n.displayName : y(n.render, t + 1) ?? y(n.type, t + 1);
218
+ }
219
+ return null;
220
+ }
221
+ function xe(e) {
222
+ return typeof e.type == "function" || typeof e.type == "object" && e.type !== null && y(e.type) !== null;
223
+ }
224
+ var b = Symbol("left out"), Se = 8, Ce = 100;
225
+ function we(e) {
226
+ let t = e.$$typeof;
227
+ return typeof t == "symbol" || typeof t == "number";
228
+ }
229
+ function Te(e) {
230
+ let t = e;
231
+ return typeof t.nodeType == "number" && typeof t.nodeName == "string";
232
+ }
233
+ function Ee(e, t = [], n = 0) {
234
+ if (e === null || typeof e == "boolean" || typeof e == "string") return e;
235
+ if (typeof e == "number") return Number.isFinite(e) ? e : null;
236
+ if (typeof e == "bigint") return e.toString();
237
+ if (typeof e != "object" || t.includes(e) || we(e) || Te(e)) return b;
238
+ if (n >= Se) return "…";
239
+ if (e instanceof Date) return Number.isNaN(e.getTime()) ? null : e.toISOString();
240
+ if (e instanceof RegExp) return String(e);
241
+ t.push(e);
242
+ try {
243
+ if (Array.isArray(e) || e instanceof Set) {
244
+ let r = [];
245
+ for (let i of e) {
246
+ if (r.length >= Ce) break;
247
+ let e = Ee(i, t, n + 1);
248
+ e !== b && r.push(e);
249
+ }
250
+ return r;
251
+ }
252
+ let r = e instanceof Map ? [...e].map(([e, t]) => [String(e), t]) : Object.keys(e).map((e) => [e, void 0]), i = {}, a = 0;
253
+ for (let [o, s] of r) {
254
+ if (a >= Ce) break;
255
+ let r = s;
256
+ if (!(e instanceof Map)) try {
257
+ r = e[o];
258
+ } catch {
259
+ continue;
260
+ }
261
+ let c = Ee(r, t, n + 1);
262
+ c !== b && (i[o] = c, a++);
263
+ }
264
+ return i;
265
+ } finally {
266
+ t.pop();
267
+ }
268
+ }
269
+ function De(e, t = 2048) {
270
+ let n = Ee(e), { text: r, cut: i } = ye(JSON.stringify(n === b ? {} : n) ?? "{}", t);
271
+ return {
272
+ json: r,
273
+ cut: i
274
+ };
275
+ }
276
+ function Oe(e) {
277
+ let t = [], n = b, r = 0;
278
+ for (let i = be(e); i && t.length < 3 && r < 500; i = i.return ?? null, r++) {
279
+ if (!xe(i)) continue;
280
+ let e = y(i.type) ?? "Anonymous";
281
+ if (i.memoizedProps === n || t.at(-1)?.comp === e) continue;
282
+ n = i.memoizedProps;
283
+ let { json: r, cut: a } = De(i.memoizedProps ?? {}), o = {
284
+ comp: e,
285
+ json: r,
286
+ cut: a
287
+ }, s = i._debugSource;
288
+ s?.fileName && s.lineNumber && (o.src = `${s.fileName}:${s.lineNumber}:${s.columnNumber ?? 1}`), t.push(o);
289
+ }
290
+ return t;
291
+ }
292
+ // src/context/snapshot.ts
293
+ var ke = /* @__PURE__ */ new Set([
294
+ "SCRIPT",
295
+ "STYLE",
296
+ "NOSCRIPT",
297
+ "TEMPLATE",
298
+ "HEAD",
299
+ "META",
300
+ "LINK",
301
+ "svg",
302
+ "SVG",
303
+ "IFRAME",
304
+ "OBJECT"
305
+ ]), Ae = /* @__PURE__ */ new Set(/* @__PURE__ */ "ADDRESS.ARTICLE.ASIDE.BLOCKQUOTE.BODY.DD.DETAILS.DIALOG.DIV.DL.DT.FIELDSET.FIGCAPTION.FIGURE.FOOTER.FORM.H1.H2.H3.H4.H5.H6.HEADER.HR.LI.MAIN.NAV.OL.P.PRE.SECTION.SUMMARY.TABLE.TD.TH.TR.UL".split(".")), je = {
306
+ HEADER: "header",
307
+ NAV: "nav",
308
+ MAIN: "main",
309
+ ASIDE: "aside",
310
+ FOOTER: "footer",
311
+ FORM: "form",
312
+ DIALOG: "dialog"
313
+ }, Me = /* @__PURE__ */ new Set([
314
+ "banner",
315
+ "navigation",
316
+ "main",
317
+ "complementary",
318
+ "contentinfo",
319
+ "region",
320
+ "search",
321
+ "form",
322
+ "dialog",
323
+ "alertdialog",
324
+ "toolbar",
325
+ "tablist",
326
+ "menu",
327
+ "group"
328
+ ]), Ne = 80, Pe = 400, x = 6, S = (e) => (e ?? "").replace(/\s+/g, " ").trim(), C = (e) => e.length > Ne ? `${e.slice(0, 79)}…` : e, Fe = class {
329
+ doc;
330
+ host;
331
+ seen = /* @__PURE__ */ new Map();
332
+ view;
333
+ w;
334
+ h;
335
+ constructor(e, t) {
336
+ this.doc = e, this.host = t, this.view = e.defaultView ?? window, this.w = this.view.innerWidth, this.h = this.view.innerHeight;
337
+ }
338
+ visible(e) {
339
+ let t = this.seen.get(e);
340
+ if (t !== void 0) return t;
341
+ let n = !0;
342
+ if (e === this.host || ke.has(e.tagName)) n = !1;
343
+ else if (e.hasAttribute("hidden") || e.getAttribute("aria-hidden") === "true") n = !1;
344
+ else {
345
+ let t = this.view.getComputedStyle(e);
346
+ if (t.display === "none" || t.visibility === "hidden" || t.visibility === "collapse") n = !1;
347
+ else {
348
+ let t = e.getBoundingClientRect();
349
+ (t.width > 0 || t.height > 0) && (t.bottom < 0 || t.right < 0 || t.top > this.h || t.left > this.w) && (n = !1);
350
+ }
351
+ }
352
+ return n && e.parentElement && e.parentElement !== this.doc.documentElement && (n = this.visible(e.parentElement)), this.seen.set(e, n), n;
353
+ }
354
+ kids(e) {
355
+ return [...e.children].filter((e) => this.visible(e));
356
+ }
357
+ };
358
+ function w(e) {
359
+ let t = e.getAttribute("role");
360
+ if (t) return t.split(/\s+/)[0] ?? "";
361
+ let n = e.tagName;
362
+ if (/^H[1-6]$/.test(n)) return "heading";
363
+ if (n === "BUTTON" || n === "SUMMARY") return "button";
364
+ if (n === "A" && e.hasAttribute("href")) return "link";
365
+ if (n === "TABLE") return "table";
366
+ if (n === "UL" || n === "OL") return "list";
367
+ if (n === "SELECT") return "combobox";
368
+ if (n === "TEXTAREA") return "textbox";
369
+ if (n === "IMG") return e.getAttribute("alt") ? "img" : "";
370
+ if (n === "INPUT") {
371
+ let t = e.type;
372
+ return [
373
+ "button",
374
+ "submit",
375
+ "reset"
376
+ ].includes(t) ? "button" : t === "hidden" ? "" : t === "search" ? "searchbox" : t === "checkbox" ? "checkbox" : t === "radio" ? "radio" : "textbox";
377
+ }
378
+ return "";
379
+ }
380
+ function T(e) {
381
+ let t = S(e.getAttribute("aria-label"));
382
+ if (t) return C(t);
383
+ let n = e.getAttribute("aria-labelledby");
384
+ if (n) {
385
+ let t = S(n.split(/\s+/).map((t) => e.ownerDocument.getElementById(t)?.textContent ?? "").join(" "));
386
+ if (t) return C(t);
387
+ }
388
+ if (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement) {
389
+ let t = S(e.labels?.[0]?.textContent);
390
+ if (t) return C(t);
391
+ let n = S(e.getAttribute("placeholder"));
392
+ return n ? C(n) : e instanceof HTMLInputElement && [
393
+ "button",
394
+ "submit",
395
+ "reset"
396
+ ].includes(e.type) ? C(S(e.value)) : C(S(e.getAttribute("name")));
397
+ }
398
+ return e.tagName === "IMG" ? C(S(e.getAttribute("alt"))) : C(S(e.textContent) || S(e.getAttribute("title")));
399
+ }
400
+ function Ie(e, t) {
401
+ let n = je[e.tagName], r = S(e.getAttribute("aria-label"));
402
+ return t && Me.has(t) ? r ? `${t} "${C(r)}"` : t : n ? r ? `${n} "${C(r)}"` : n : e.tagName === "SECTION" && r ? `region "${C(r)}"` : "";
403
+ }
404
+ function Le(e) {
405
+ let t = [...e.classList].slice(0, 2).join(".");
406
+ return e.tagName.toLowerCase() + (t ? `.${t}` : "");
407
+ }
408
+ var Re = class {
409
+ page;
410
+ lines = [];
411
+ full = !1;
412
+ constructor(e) {
413
+ this.page = e;
414
+ }
415
+ add(e, t) {
416
+ this.lines.length >= Pe ? this.full = !0 : this.lines.push(`${" ".repeat(e)}${t}`);
417
+ }
418
+ children(e, t) {
419
+ let n = this.page.kids(e), r = /* @__PURE__ */ new Map();
420
+ for (let e of n) {
421
+ let t = Le(e), n = r.get(t);
422
+ n ? n.push(e) : r.set(t, [e]);
423
+ }
424
+ let i = /* @__PURE__ */ new Set();
425
+ for (let e of n) {
426
+ let n = Le(e), a = r.get(n) ?? [e];
427
+ a.length < 3 || !this.repeatable(e) ? this.element(e, t) : i.has(n) || (i.add(n), this.repeated(a, n, t));
428
+ }
429
+ }
430
+ repeatable(e) {
431
+ let t = w(e);
432
+ return t !== "heading" && !Ie(e, t);
433
+ }
434
+ repeated(e, t, n) {
435
+ let r = w(e[0]);
436
+ if (r === "button" || r === "link") {
437
+ let t = e.slice(0, x).map((e) => `"${T(e)}"`);
438
+ e.length > x && t.push("…"), this.add(n, `${r}s: ${e.length} (${t.join(", ")})`);
439
+ } else this.add(n, `repeated ${t}: ${e.length} items, the first:`), this.element(e[0], n + 1);
440
+ }
441
+ element(e, t) {
442
+ let n = w(e), r = Ie(e, n);
443
+ if (r) this.add(t, r), this.children(e, t + 1);
444
+ else {
445
+ switch (n) {
446
+ case "heading": {
447
+ let n = /^H([1-6])$/.exec(e.tagName)?.[1] ?? e.getAttribute("aria-level") ?? "2";
448
+ this.add(t, `h${n}: ${T(e)}`);
449
+ return;
450
+ }
451
+ case "button":
452
+ case "link":
453
+ case "checkbox":
454
+ case "radio":
455
+ case "combobox":
456
+ case "img":
457
+ this.add(t, `${n === "img" ? "image" : n}: ${T(e)}`);
458
+ return;
459
+ case "textbox":
460
+ case "searchbox":
461
+ this.add(t, `${n === "searchbox" ? "search field" : "field"}: ${T(e)}`);
462
+ return;
463
+ case "table":
464
+ case "grid": {
465
+ let n = e.querySelectorAll("tbody tr, [role=row]").length || e.querySelectorAll("tr").length, r = [...e.querySelectorAll("th, [role=columnheader]")].slice(0, 8).map((e) => S(e.textContent));
466
+ this.add(t, `table: ${n} rows${r.length ? ` (${r.filter(Boolean).join(" · ")})` : ""}`);
467
+ return;
468
+ }
469
+ case "list": {
470
+ let n = [...e.children].filter((e) => e.tagName === "LI" || e.getAttribute("role") === "listitem"), r = n.map((e) => {
471
+ let t = this.page.kids(e);
472
+ return t.length === 1 && ["link", "button"].includes(w(t[0])) ? t[0] : null;
473
+ });
474
+ if (n.length && r.every(Boolean)) {
475
+ let e = r.slice(0, x).map((e) => `"${T(e)}"`);
476
+ n.length > x && e.push("…"), this.add(t, `list: ${n.length} items (${e.join(", ")})`);
477
+ return;
478
+ }
479
+ this.add(t, `list: ${n.length} items${n.length > 1 ? ", the first:" : ""}`), n[0] && this.page.visible(n[0]) && this.children(n[0], t + 1);
480
+ return;
481
+ }
482
+ }
483
+ this.children(e, t);
484
+ }
485
+ }
486
+ };
487
+ function ze(e) {
488
+ let t = e.doc, n = t.body;
489
+ if (!n) return "";
490
+ let r = t.createTreeWalker(n, NodeFilter.SHOW_TEXT), i = [], a = null;
491
+ for (let t = r.nextNode(); t; t = r.nextNode()) {
492
+ let n = S(t.nodeValue), r = t.parentElement;
493
+ if (!n || !r || !e.visible(r)) continue;
494
+ let o = r;
495
+ for (; o && !Ae.has(o.tagName);) o = o.parentElement;
496
+ if (i.length && o !== a) {
497
+ let e = o?.parentElement && o.parentElement === a?.parentElement;
498
+ i.push(e && (o?.tagName === "TD" || o?.tagName === "TH") ? " · " : "\n");
499
+ } else i.length && i.push(" ");
500
+ i.push(n), a = o;
501
+ }
502
+ return i.join("").replace(/ *\n */g, "\n").replace(/\n{2,}/g, "\n");
503
+ }
504
+ function Be(e = {}) {
505
+ let t = e.doc ?? document, r = t.defaultView ?? window, i = new Fe(t, e.host ?? null), a = new Re(i);
506
+ t.body && a.children(t.body, 0);
507
+ let o = ye(a.lines.join("\n"), n), s = ye(ze(i), n), c = r.location;
508
+ return {
509
+ route: c.pathname + c.search + c.hash,
510
+ title: t.title,
511
+ viewport: {
512
+ w: r.innerWidth,
513
+ h: r.innerHeight
514
+ },
515
+ scheme: e.scheme ?? "light",
516
+ outline: o.text,
517
+ text: s.text,
518
+ cut: o.cut || s.cut || a.full
519
+ };
520
+ }
521
+ // src/context/index.ts
522
+ var Ve = RegExp(` (?:${e}|${t})="[^"]*"`, "g");
523
+ function He(e) {
524
+ let n = { src: e.getAttribute("data-onsite-src") ?? "" }, r = e.getAttribute(t);
525
+ r && (n.comp = r), n.tag = e.tagName.toLowerCase(), n.html = e.outerHTML.replace(Ve, "").slice(0, 1500);
526
+ let i = e.getBoundingClientRect();
527
+ n.w = Math.round(i.width), n.h = Math.round(i.height);
528
+ let a = Oe(e);
529
+ return a.length && (n.props = a), n;
530
+ }
531
+ function Ue(e, t = {}) {
532
+ return {
533
+ selection: e.filter((e) => e.isConnected).map(He),
534
+ page: Be(t)
535
+ };
536
+ }
537
+ // src/dock.ts
538
+ var We = [
539
+ "top-left",
540
+ "top-center",
541
+ "top-right",
542
+ "bottom-left",
543
+ "bottom-center",
544
+ "bottom-right"
545
+ ], Ge = "bottom-right";
546
+ function Ke(e) {
547
+ return typeof e == "string" && We.includes(e);
548
+ }
549
+ function qe(e) {
550
+ return Ke(e) ? e : Ge;
551
+ }
552
+ var E = (e) => e.startsWith("top") ? "top" : "bottom", D = (e) => e.endsWith("left") ? "left" : e.endsWith("right") ? "right" : "center", O = [
553
+ "left",
554
+ "center",
555
+ "right"
556
+ ], k = (e, t) => `${e}-${t}`;
557
+ function Je(e, t, n) {
558
+ let r = e === "left" ? 24 : e === "right" ? n.w - 24 - t : (n.w - t) / 2;
559
+ return Math.max(0, r);
560
+ }
561
+ function A(e, t) {
562
+ let n = E(e) === "top" ? 24 : t.h - 24 - 48;
563
+ return {
564
+ left: Je(D(e), 48, t),
565
+ top: Math.max(0, n),
566
+ width: 48,
567
+ height: 48
568
+ };
569
+ }
570
+ function Ye(e, t) {
571
+ let n = A(e, t);
572
+ return {
573
+ x: n.left + n.width / 2,
574
+ y: n.top + n.height / 2
575
+ };
576
+ }
577
+ function Xe(e, t, n, r = 12) {
578
+ let i = Math.max(0, Math.min(n, t.w - 48)), a = Je(D(e), i, t), o = 72 + r, s = Math.max(0, t.h - o - 24);
579
+ return E(e) === "top" ? {
580
+ left: a,
581
+ width: i,
582
+ top: o,
583
+ maxHeight: s
584
+ } : {
585
+ left: a,
586
+ width: i,
587
+ bottom: o,
588
+ maxHeight: s
589
+ };
590
+ }
591
+ function Ze(e, t, n, r, i = 12) {
592
+ let a = Xe(e, t, n, i), o = Math.min(r, a.maxHeight), s = a.top ?? t.h - (a.bottom ?? 0) - o;
593
+ return {
594
+ left: a.left,
595
+ top: s,
596
+ width: a.width,
597
+ height: o
598
+ };
599
+ }
600
+ function Qe(e, t, n) {
601
+ let r = Ge, i = 1e400;
602
+ for (let a of We) {
603
+ let o = Ye(a, n), s = (o.x - e) ** 2 + (o.y - t) ** 2;
604
+ s < i && (r = a, i = s);
605
+ }
606
+ return r;
607
+ }
608
+ function $e(e, t) {
609
+ let n = O.indexOf(D(e));
610
+ return t === "ArrowLeft" ? k(E(e), O[Math.max(0, n - 1)] ?? "left") : t === "ArrowRight" ? k(E(e), O[Math.min(2, n + 1)] ?? "right") : t === "ArrowUp" ? k("top", D(e)) : t === "ArrowDown" ? k("bottom", D(e)) : e;
611
+ }
612
+ function et(e, t) {
613
+ let n = Math.max(0, e.left), r = Math.max(0, e.top), i = Math.min(t.w, e.left + e.width), a = Math.min(t.h, e.top + e.height);
614
+ return i > n && a > r ? {
615
+ left: n,
616
+ top: r,
617
+ width: i - n,
618
+ height: a - r
619
+ } : null;
620
+ }
621
+ function tt(e, t) {
622
+ let n = Math.min(e.left + e.width, t.left + t.width) - Math.max(e.left, t.left), r = Math.min(e.top + e.height, t.top + t.height) - Math.max(e.top, t.top);
623
+ return n > 0 && r > 0 ? n * r : 0;
624
+ }
625
+ function nt(e, t) {
626
+ return Math.abs(O.indexOf(D(e)) - O.indexOf(D(t))) + (E(e) === E(t) ? 0 : 1);
627
+ }
628
+ function rt(e, t, n) {
629
+ let r = (e) => {
630
+ let r = 0;
631
+ for (let i of t(e)) for (let e of n) r += tt(i, e);
632
+ return r;
633
+ };
634
+ if (r(e) === 0) return e;
635
+ let i = We.map((t, n) => ({
636
+ a: t,
637
+ key: [
638
+ r(t),
639
+ E(t) === E(e) ? 0 : 1,
640
+ nt(t, e),
641
+ t === "bottom-right" ? 0 : 1,
642
+ n
643
+ ]
644
+ }));
645
+ return i.sort((e, t) => {
646
+ for (let n = 0; n < e.key.length; n++) {
647
+ let r = (e.key[n] ?? 0) - (t.key[n] ?? 0);
648
+ if (r !== 0) return r;
649
+ }
650
+ return 0;
651
+ }), i[0]?.a ?? e;
652
+ }
653
+ // src/dom.ts
654
+ function it(e, t) {
655
+ for (let n of t) n != null && n !== !1 && (Array.isArray(n) ? it(e, n) : e.appendChild(typeof n == "string" || typeof n == "number" ? document.createTextNode(String(n)) : n));
656
+ }
657
+ function j(e, t, ...n) {
658
+ let r = document.createElement(e);
659
+ for (let [e, n] of Object.entries(t ?? {})) if (e === "on") for (let [e, t] of Object.entries(n)) r.addEventListener(e, t);
660
+ else n === !0 ? r.setAttribute(e, "") : n !== !1 && n != null && r.setAttribute(e, String(n));
661
+ return it(r, n), r;
662
+ }
663
+ var at = /* @__PURE__ */ new Map();
664
+ function M(e) {
665
+ let t = at.get(e);
666
+ if (!t) {
667
+ let n = document.createElement("template");
668
+ n.innerHTML = e.trim(), t = n.content.firstElementChild ?? document.createElement("span"), at.set(e, t);
669
+ }
670
+ return t.cloneNode(!0);
671
+ }
672
+ function ot(e, t, n = 0) {
673
+ e.style.left = `${t.left - n}px`, e.style.top = `${t.top - n}px`, e.style.width = `${t.width + n * 2}px`, e.style.height = `${t.height + n * 2}px`;
674
+ }
675
+ var N = () => new Promise((e) => requestAnimationFrame(() => e())), st = (e) => new Promise((t) => setTimeout(t, e));
676
+ function P() {
677
+ try {
678
+ return matchMedia("(prefers-reduced-motion: reduce)").matches;
679
+ } catch {
680
+ return !1;
681
+ }
682
+ }
683
+ function ct() {
684
+ return /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
685
+ }
686
+ function F() {
687
+ return ct() ? "⌥" : "Alt";
688
+ }
689
+ function lt(e) {
690
+ return e ? e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement ? !0 : e instanceof HTMLInputElement ? ![
691
+ "button",
692
+ "submit",
693
+ "checkbox",
694
+ "radio",
695
+ "reset"
696
+ ].includes(e.type) : e.isContentEditable === !0 : !1;
697
+ }
698
+ // src/icons.ts
699
+ var ut = "<path d=\"M5 11V5h6\"/><path d=\"M21 5h6v6\"/><path d=\"M27 21v6h-6\"/><path d=\"M11 27H5v-6\"/>";
700
+ function I(e, t, n = !1) {
701
+ return `<svg width="${e}" height="${e}" viewBox="0 0 32 32" aria-hidden="true" style="overflow:visible"><g fill="none" stroke="var(--os-ink)" stroke-width="${t}" stroke-linecap="round" stroke-linejoin="round">${ut}</g>${n ? "<circle class=\"dotpulse\" cx=\"16\" cy=\"16\" r=\"4.5\" fill=\"var(--os-mark)\"/>" : ""}<circle cx="16" cy="16" r="4.5" fill="var(--os-mark)"/></svg>`;
702
+ }
703
+ var L = (e, t = 14, n = "") => `<svg width="${t}" height="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"${n}>${e}</svg>`, R = {
704
+ select: L("<path d=\"M4 4l7 17 2.5-7.5L21 11z\"/>"),
705
+ alt: L("<rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"3\" stroke-dasharray=\"3 3\"/>"),
706
+ scheme: L("<circle cx=\"12\" cy=\"12\" r=\"8.5\"/><path d=\"M12 3.5v17\"/><path d=\"M12 3.5a8.5 8.5 0 0 1 0 17z\" fill=\"currentColor\" stroke=\"none\"/>", 15),
707
+ close: L("<path d=\"M6 9l6 6 6-6\"/>", 16),
708
+ read: L("<path d=\"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>"),
709
+ list: L("<path d=\"M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01\"/>"),
710
+ write: L("<path d=\"M4 20h4L19 9l-4-4L4 16z\"/>", 14, " style=\"color:var(--os-accent-text)\""),
711
+ done: L("<path d=\"M5 12l5 5 9-10\"/>", 14, " style=\"color:var(--os-add)\" stroke-width=\"2.4\""),
712
+ error: L("<circle cx=\"12\" cy=\"12\" r=\"9\"/><path d=\"M12 7v6M12 16.5v.5\"/>", 14),
713
+ keep: L("<path d=\"M12 4v12M6 10l6 6 6-6M5 20h14\"/>", 14),
714
+ undo: L("<path d=\"M9 14L4 9l5-5\"/><path d=\"M4 9h10a6 6 0 0 1 0 12h-3\"/>", 14),
715
+ more: L("<path d=\"M6 9l6 6 6-6\"/>", 12),
716
+ dots: L("<circle cx=\"5\" cy=\"12\" r=\"1.6\" fill=\"currentColor\" stroke=\"none\"/><circle cx=\"12\" cy=\"12\" r=\"1.6\" fill=\"currentColor\" stroke=\"none\"/><circle cx=\"19\" cy=\"12\" r=\"1.6\" fill=\"currentColor\" stroke=\"none\"/>", 14),
717
+ back: L("<path d=\"M15 6l-6 6 6 6\"/>", 16),
718
+ next: L("<path d=\"M9 6l6 6-6 6\"/>", 14),
719
+ export: L("<path d=\"M12 15V4M7 9l5-5 5 5M5 14v5h14v-5\"/>", 14),
720
+ skills: L("<path d=\"M4 5a2 2 0 0 1 2-2h13v15H6a2 2 0 0 0-2 2z\"/><path d=\"M4 20a2 2 0 0 0 2 2h13v-4\"/>", 14),
721
+ preset: L("<path d=\"M13 3L5 14h6l-1 7 8-11h-6z\"/>", 14),
722
+ settings: L("<circle cx=\"12\" cy=\"12\" r=\"3\"/><path d=\"M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z\"/>", 14),
723
+ hide: L("<path d=\"M3 3l18 18\"/><path d=\"M10.6 5.1A10 10 0 0 1 12 5c6.5 0 10 7 10 7a17 17 0 0 1-3.2 4.1M6.6 6.6C3.9 8.4 2 12 2 12s3.5 7 10 7a9.7 9.7 0 0 0 5.4-1.6\"/><path d=\"M9.9 9.9a3 3 0 0 0 4.2 4.2\"/>", 14),
724
+ show: L("<path d=\"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>", 14),
725
+ edit: L("<path d=\"M4 20h4L19 9l-4-4L4 16z\"/>", 14),
726
+ trash: L("<path d=\"M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3\"/>", 14),
727
+ plus: L("<path d=\"M12 5v14M5 12h14\"/>", 14),
728
+ layers: L("<path d=\"M12 3l9 5-9 5-9-5z\"/><path d=\"M3 13l9 5 9-5\"/>", 12),
729
+ original: L("<path d=\"M14 3H6v18h12V7z\"/><path d=\"M14 3v4h4\"/>", 14),
730
+ send: L("<path d=\"m5 12 7-7 7 7\"/><path d=\"M12 19V5\"/>", 18),
731
+ queue: L("<path d=\"M11 12H3\"/><path d=\"M16 6H3\"/><path d=\"M16 18H3\"/><path d=\"M18 9v6\"/><path d=\"M21 12h-6\"/>", 17),
732
+ pinComment: L("<path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\"/><path d=\"M12 7v6\"/><path d=\"M9 10h6\"/>", 16),
733
+ takes: L("<path d=\"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z\"/><path d=\"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65\"/><path d=\"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65\"/>", 16),
734
+ stop: L("<rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"2\" fill=\"currentColor\"/>", 16),
735
+ x: L("<path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/>", 12),
736
+ element: L("<path d=\"M3 7V5a2 2 0 0 1 2-2h2\"/><path d=\"M17 3h2a2 2 0 0 1 2 2v2\"/><path d=\"M21 17v2a2 2 0 0 1-2 2h-2\"/><path d=\"M7 21H5a2 2 0 0 1-2-2v-2\"/>", 12),
737
+ commentChip: L("<path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\"/>", 12),
738
+ comment: L("<path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\"/>", 14),
739
+ mouse: L("<rect x=\"6\" y=\"3\" width=\"12\" height=\"18\" rx=\"6\"/><path d=\"M12 3v6\"/><path d=\"M12 3a6 6 0 0 0-6 6h6z\" fill=\"currentColor\" stroke=\"none\"/>", 14)
740
+ };
741
+ // src/frames.ts
742
+ function dt(e, t) {
743
+ let n = [];
744
+ for (let r of e.entries) {
745
+ if (r.who !== "person" || t.has(r.id)) continue;
746
+ let i = e.running === r.id, a = (e.queue?.indexOf(r.id) ?? -1) + 1, o = e.takes.filter((e) => e.of === r.id && e.state === "open").sort((e, t) => e.no - t.no);
747
+ (i || a || o.length !== 0) && n.push({
748
+ run: r.id,
749
+ running: i,
750
+ queued: a,
751
+ takes: o,
752
+ selected: (r.selection ?? []).map((e) => e.src).filter(Boolean),
753
+ step: ft(r.steps, r.kind === "takes")
754
+ });
755
+ }
756
+ return n;
757
+ }
758
+ function ft(e, t) {
759
+ let n = e?.at(-1);
760
+ if (!n) return "Working…";
761
+ if (n.tool === "src_read") return `Reading ${i(n.path)}`;
762
+ if (n.tool === "src_list") return `Looking through ${n.path || "the source folder"}`;
763
+ let r = t && n.take ? ` · ${u(n.take)}` : "";
764
+ return `Editing ${i(n.path)}${r}`;
765
+ }
766
+ function pt(e, t, n) {
767
+ let r = t.find((e) => e.id === n);
768
+ return r ? r.of === e : n.startsWith(`${e}-`);
769
+ }
770
+ var z = (e) => e.showing ?? (e.shown ? [e.shown] : []);
771
+ function mt(e, t, n) {
772
+ return n.find((n) => pt(e, t, n)) ?? "";
773
+ }
774
+ function ht(e, t, n, r) {
775
+ let i = {
776
+ stamps: [],
777
+ selectors: []
778
+ }, a = {
779
+ stamps: [],
780
+ selectors: []
781
+ }, o = mt(e, t, r);
782
+ for (let r of n?.groups ?? []) {
783
+ let n = r.takes.filter((n) => pt(e, t, n));
784
+ n.length !== 0 && (B(i, r), o && n.includes(o) && B(a, r));
785
+ }
786
+ return {
787
+ all: i,
788
+ strong: a
789
+ };
790
+ }
791
+ function B(e, t) {
792
+ for (let n of t.stamps ?? []) e.stamps.includes(n) || e.stamps.push(n);
793
+ for (let n of t.selectors ?? []) e.selectors.includes(n) || e.selectors.push(n);
794
+ }
795
+ function gt(e, t) {
796
+ if (t === "") return "";
797
+ let n = e.filter((e) => !e.running && !e.queued);
798
+ return t && n.some((e) => e.run === t) ? t : e.findLast((e) => !e.queued)?.running ? "" : n.at(-1)?.run ?? "";
799
+ }
800
+ function _t(e, t, n) {
801
+ let r = Math.max(8, Math.min(e.left, n.w - t.w - 8)), i = e.top - 8 - t.h;
802
+ if (i >= 8) return {
803
+ left: r,
804
+ top: i,
805
+ side: "above"
806
+ };
807
+ let a = e.top + e.height + 8;
808
+ if (a + t.h <= n.h - 8) return {
809
+ left: r,
810
+ top: a,
811
+ side: "below"
812
+ };
813
+ let o = Math.max(8, Math.min(e.top + 8, n.h - t.h - 8)), s = e.left - 8 - t.w;
814
+ if (s >= 8) return {
815
+ left: s,
816
+ top: o,
817
+ side: "left"
818
+ };
819
+ let c = e.left + e.width + 8;
820
+ return c + t.w <= n.w - 8 ? {
821
+ left: c,
822
+ top: o,
823
+ side: "right"
824
+ } : {
825
+ left: r,
826
+ top: Math.max(8, Math.min(e.top + e.height - 8 - t.h, n.h - t.h - 8)),
827
+ side: "inside"
828
+ };
829
+ }
830
+ function vt(e, t, n) {
831
+ let r = { ...e }, i = (e) => r.left < e.left + e.width && r.left + r.width > e.left && r.top < e.top + e.height && r.top + r.height > e.top;
832
+ for (let a = 0; a < 12; a++) {
833
+ let a = t.find(i);
834
+ if (!a) break;
835
+ r.left = a.left + a.width + 4, r.left + r.width > n.w - 8 && (r.left = e.left, r.top = Math.min(a.top + a.height + 4, n.h - r.height - 8));
836
+ }
837
+ return r;
838
+ }
839
+ var V = (e, t) => e.left < t.left + t.width && e.left + e.width > t.left && e.top < t.top + t.height && e.top + e.height > t.top, yt = (e, t) => e.left <= t.left && e.top <= t.top && e.left + e.width >= t.left + t.width && e.top + e.height >= t.top + t.height, bt = (e, t) => Math.max(0, t.left - (e.left + e.width), e.left - (t.left + t.width)) + Math.max(0, t.top - (e.top + e.height), e.top - (t.top + t.height));
840
+ function xt(e, t) {
841
+ let n = [];
842
+ return e.map((r, i) => {
843
+ let { anchor: a, size: o } = r, s = e.flatMap((e, t) => t === i ? [] : e.own), c = s.filter((e) => yt(e, a)), l = s.filter((e) => !yt(e, a)), u = (e, n) => ({
844
+ left: Math.max(4, Math.min(e, t.w - o.w - 4)),
845
+ top: Math.max(4, Math.min(n, t.h - o.h - 4)),
846
+ width: o.w,
847
+ height: o.h
848
+ }), d = [], f = (e) => {
849
+ d.push(u(a.left + a.width - o.w, e), u(a.left, e));
850
+ for (let t of n) d.push(u(t.left - 4 - o.w, e), u(t.left + t.width + 4, e));
851
+ }, p = (e) => {
852
+ d.push(u(e, a.top));
853
+ for (let t of n) d.push(u(e, t.top + t.height + 4));
854
+ };
855
+ for (let e = 0; e < 3; e++) f(a.top - 4 - o.h - e * (o.h + 4)), f(a.top + a.height + 4 + e * (o.h + 4)), e === 0 && (p(a.left - 4 - o.w), p(a.left + a.width + 4));
856
+ d.push(u(a.left + a.width - 4 - o.w, a.top + a.height - 4 - o.h));
857
+ let m = null, h = 1e400;
858
+ for (let [e, t] of d.entries()) {
859
+ if (n.some((e) => V(t, e))) continue;
860
+ let i = (r.own.some((e) => V(t, e)) ? 1e3 : 0) + 100 * l.filter((e) => V(t, e)).length + 20 * c.filter((e) => V(t, e)).length + bt(t, a) + e / 1e3;
861
+ i < h && (m = t, h = i);
862
+ }
863
+ let g = m ?? vt(d[0], n, t);
864
+ return n.push(g), g;
865
+ });
866
+ }
867
+ function H(e, t, n, r) {
868
+ return t.find((e) => n.includes(e.id)) ?? t.find((t) => t.id === r.get(e)) ?? t[0];
869
+ }
870
+ var St = (e, t) => !e.some((e) => t.includes(e.id));
871
+ function Ct(e) {
872
+ return j("div", {
873
+ class: "frametag",
874
+ "data-frametag": e.run,
875
+ role: "status"
876
+ }, j("span", {
877
+ class: "spin",
878
+ "aria-hidden": "true"
879
+ }), j("span", null, e.step));
880
+ }
881
+ function wt(e, t) {
882
+ return j("div", {
883
+ class: "framequeue",
884
+ "data-framequeue": e.run
885
+ }, j("span", null, d(e.queued - 1)), j("button", {
886
+ type: "button",
887
+ "aria-label": "Cancel this ask. It has not started.",
888
+ title: "Cancel this ask. It has not started.",
889
+ "data-fkey": `cancel:${e.run}`,
890
+ "data-frame-cancel": "",
891
+ on: { click: (n) => {
892
+ n.stopPropagation(), t.cancel(e.run);
893
+ } }
894
+ }, "×"));
895
+ }
896
+ function Tt(e, t) {
897
+ let n = f(e.takes.map((e) => e.no));
898
+ return j("button", {
899
+ class: "framefold",
900
+ type: "button",
901
+ "aria-label": `Open the bar of ${n}`,
902
+ title: `${n}: switch, keep or skip`,
903
+ "data-framefold": e.run,
904
+ "data-fkey": `fold:${e.run}`,
905
+ on: { click: (n) => {
906
+ n.stopPropagation(), t.openFrame(e.run);
907
+ } }
908
+ }, n, M(R.more));
909
+ }
910
+ function Et(e, t, n, r) {
911
+ return j("div", {
912
+ class: "framebar",
913
+ role: "toolbar",
914
+ tabindex: 0,
915
+ "aria-label": `${e.takes.length > 1 ? "Takes" : "Take"} of this change. Left and Right switch takes, O shows the original, Enter keeps, Escape closes.`,
916
+ "data-framebar": e.run,
917
+ "aria-busy": n ? "true" : null,
918
+ "data-fkey": `bar:${e.run}`
919
+ }, j("span", {
920
+ class: "framemark",
921
+ "aria-hidden": "true"
922
+ }, M(I(14, 3.2))), Dt(e.run, e.takes, t, r, `f:${e.run}`), j("button", {
923
+ class: "btn ghost icon",
924
+ type: "button",
925
+ "aria-label": "Hide this frame. The takes stay open.",
926
+ title: "Hide this frame. The takes stay open.",
927
+ "data-fkey": `hide:${e.run}`,
928
+ "data-frame-hide": "",
929
+ on: { click: () => r.hideFrame(e.run) }
930
+ }, "×"));
931
+ }
932
+ function Dt(e, t, n, r, i) {
933
+ let a = H(e, t, n.showing, n.picked), o = St(t, n.showing), s = !o && a ? ee(a, n.all, n.asks) : null, c = document.createDocumentFragment();
934
+ return c.append(j("button", {
935
+ class: "btn origin",
936
+ type: "button",
937
+ "aria-pressed": String(o),
938
+ title: o ? `Showing your code as it is on disk. Press to show ${a ? u(a.no) : "the take"} again.` : "Show your code as it is on disk",
939
+ "data-fkey": `orig:${i}`,
940
+ "data-original": "",
941
+ on: { click: () => r.toggleOriginal(e) }
942
+ }, "Original"), j("div", {
943
+ class: `seg${o ? " dim" : ""}`,
944
+ role: "group",
945
+ "aria-label": "Takes"
946
+ }, t.map((e) => j("button", {
947
+ type: "button",
948
+ ...e.stale?.length ? { class: "stale" } : {},
949
+ "aria-pressed": String(e.id === a?.id),
950
+ "aria-label": e.stale?.length ? `${u(e.no)}, ${h.toLowerCase()}` : u(e.no),
951
+ title: [[
952
+ p(e, !0),
953
+ e.stopped ? "stopped" : "",
954
+ e.stale?.length ? h : ""
955
+ ].filter(Boolean).join(" · "), e.note ?? ""].filter(Boolean).join("\n"),
956
+ "data-fkey": `seg:${i}:${e.id}`,
957
+ "data-take": e.id,
958
+ on: { click: () => r.show(e.id) }
959
+ }, String(e.no)))), ...s ? [j("span", {
960
+ class: "covered",
961
+ title: s.title,
962
+ "data-covered": ""
963
+ }, M(R.layers), s.text)] : [], ...a?.stale?.length ? [j("button", {
964
+ class: "btn ghost",
965
+ type: "button",
966
+ title: `Ask again on the new code. ${u(a.no)} was made on an older version of ${_(a.stale)}.`,
967
+ "data-fkey": `again:${i}`,
968
+ "data-frame-again": "",
969
+ on: { click: () => r.again(a) }
970
+ }, "Ask again")] : [], j("button", {
971
+ class: "btn ghost",
972
+ type: "button",
973
+ "aria-disabled": a ? null : "true",
974
+ title: a ? `Drop ${u(a.no)}. No file changes.` : "No take to skip",
975
+ "data-fkey": `skip:${i}`,
976
+ "data-frame-skip": "",
977
+ on: { click: () => a && r.skip(a) }
978
+ }, "Skip"), j("button", {
979
+ class: "btn primary",
980
+ type: "button",
981
+ "aria-disabled": a ? null : "true",
982
+ title: a ? `Write ${u(a.no)} to your files` : "No take to keep",
983
+ "data-fkey": `keep:${i}`,
984
+ "data-frame-keep": "",
985
+ on: { click: () => a && r.keep(a) }
986
+ }, a && t.length > 1 ? `Keep ${a.no}` : "Keep")), c;
987
+ }
988
+ function Ot(e, t, n) {
989
+ if (e.queued) return;
990
+ let r = H(e.run, e.takes, t, n);
991
+ return r?.note ? r : void 0;
992
+ }
993
+ function kt(e, t, n, r) {
994
+ let i = u(t.no);
995
+ return j("button", {
996
+ class: `notepin${n ? " on" : ""}`,
997
+ type: "button",
998
+ "aria-label": `Note on ${i}`,
999
+ "aria-expanded": String(n),
1000
+ title: n ? `Close the note on ${i}` : `Read the idea of ${i}`,
1001
+ "data-notepin": e.run,
1002
+ "data-fkey": `note:${e.run}`,
1003
+ on: { click: (e) => {
1004
+ e.stopPropagation(), r();
1005
+ } }
1006
+ }, M(R.comment));
1007
+ }
1008
+ function At(e, t) {
1009
+ return j("div", {
1010
+ class: "popover notecard",
1011
+ role: "dialog",
1012
+ "aria-label": `Note on ${u(t.no)}`,
1013
+ "data-notecard": e.run
1014
+ }, j("div", { class: "notehead" }, p(t, !0)), j("div", { class: "text" }, t.note ?? ""));
1015
+ }
1016
+ function jt(e, t, n, r = 24) {
1017
+ let i = r / 2, a = (e, t) => ({
1018
+ left: Math.max(4, Math.min(e, n.w - r - 4)),
1019
+ top: Math.max(4, Math.min(t, n.h - r - 4)),
1020
+ width: r,
1021
+ height: r
1022
+ }), o = e.left + e.width, s = e.top + e.height, c = [
1023
+ a(e.left - i, e.top - i),
1024
+ a(e.left - i, s - i),
1025
+ a(o - i, s - i),
1026
+ a(o - i, e.top - i)
1027
+ ];
1028
+ return c.find((e) => !t.some((t) => V(e, t))) ?? vt(c[0], t, n);
1029
+ }
1030
+ function Mt(e, t, n, r) {
1031
+ let i = Math.max(8, Math.min(e.left, n.w - t.w - 8));
1032
+ r && i + t.w > r.left && i < r.left + r.width && (i = Math.max(8, r.left - t.w - 8));
1033
+ let a = e.top + e.height + 4, o = e.top - 4 - t.h, s = a + t.h <= n.h - 8 || o < 8 ? a : o;
1034
+ return {
1035
+ left: i,
1036
+ top: Math.max(8, Math.min(s, n.h - t.h - 8))
1037
+ };
1038
+ }
1039
+ // src/styles.ts
1040
+ var Nt = {
1041
+ panel: "#17181b",
1042
+ surface: "#1f2024",
1043
+ soft: "#1b1c20",
1044
+ seg: "#26272c",
1045
+ ink: "#eceae6",
1046
+ muted: "#a3a09a",
1047
+ line: "#2e2f34",
1048
+ hover: "rgba(255,255,255,.06)",
1049
+ accent: "#f2a65e",
1050
+ "accent-hover": "#f6b97c",
1051
+ "on-accent": "#2a1403",
1052
+ "accent-text": "#f2a65e",
1053
+ mark: "#f2a65e",
1054
+ "mark-tint": "rgba(242,166,94,.10)",
1055
+ "on-mark": "#2a1403",
1056
+ bubble: "#2f3036",
1057
+ "on-bubble": "#eceae6",
1058
+ "chip-bg": "#3a2a1a",
1059
+ "chip-ink": "#f6c591",
1060
+ add: "#6fd49b",
1061
+ del: "#ff8a7a",
1062
+ shadow: "0 24px 60px rgba(0,0,0,.6)",
1063
+ "shadow-sm": "0 1px 2px rgba(0,0,0,.4)",
1064
+ "shadow-md": "0 8px 24px rgba(0,0,0,.45)"
1065
+ }, Pt = {
1066
+ panel: "#f7f7f6",
1067
+ surface: "#ffffff",
1068
+ soft: "#f1f1ef",
1069
+ seg: "#e8e8e6",
1070
+ ink: "#17181b",
1071
+ muted: "#5e5c58",
1072
+ line: "#deddda",
1073
+ hover: "rgba(0,0,0,.05)",
1074
+ accent: "#f2a65e",
1075
+ "accent-hover": "#ee9746",
1076
+ "on-accent": "#2a1403",
1077
+ "accent-text": "#9a4f0b",
1078
+ mark: "#c96a10",
1079
+ "mark-tint": "rgba(201,106,16,.08)",
1080
+ "on-mark": "#1d0f02",
1081
+ bubble: "#17181b",
1082
+ "on-bubble": "#eceae6",
1083
+ "chip-bg": "#f6e3cc",
1084
+ "chip-ink": "#6b3608",
1085
+ add: "#1f7a4a",
1086
+ del: "#c0262d",
1087
+ shadow: "0 24px 60px rgba(17,18,20,.18)",
1088
+ "shadow-sm": "0 1px 2px rgba(17,18,20,.14)",
1089
+ "shadow-md": "0 8px 24px rgba(17,18,20,.16)"
1090
+ }, Ft = (e) => Object.entries(e).map(([e, t]) => `--os-${e}:${t};`).join(""), U = "cubic-bezier(.2,.8,.2,1)", W = {
1091
+ panel: 180,
1092
+ step: 140,
1093
+ flash: 720,
1094
+ swap: 160,
1095
+ alt: 90,
1096
+ press: 80,
1097
+ snap: 240,
1098
+ tip: 140,
1099
+ stillFlash: 900,
1100
+ ants: 900
1101
+ }, G = "Inter, system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif", K = "\"JetBrains Mono\", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", It = `
1102
+ :host { all: initial; }
1103
+ :host([data-scheme="dark"]), .page[data-scheme="dark"] { ${Ft(Nt)} }
1104
+ :host([data-scheme="light"]), .page[data-scheme="light"] { ${Ft(Pt)} }
1105
+ *, *::before, *::after { box-sizing: border-box; }
1106
+ .ui, .page { font-family: ${G}; color: var(--os-ink); -webkit-font-smoothing: antialiased; font-size: 13px; line-height: 1.4; }
1107
+ .mono { font-family: ${K}; }
1108
+ button { font: inherit; color: inherit; }
1109
+ .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
1110
+ [hidden] { display: none !important; }
1111
+
1112
+ /* Buttons */
1113
+ .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 8px;
1114
+ border: 1px solid var(--os-line); background: var(--os-surface); color: var(--os-ink); font: 500 13px/1 ${G}; cursor: pointer;
1115
+ white-space: nowrap; flex: 0 0 auto;
1116
+ transition: background-color .12s ${U}, border-color .12s ${U}, color .12s ${U}, transform ${W.press}ms ${U}; }
1117
+ .btn:hover { background: var(--os-hover); }
1118
+ .btn:active { transform: scale(.96); }
1119
+ .btn:disabled { opacity: .5; cursor: default; transform: none; }
1120
+ .btn[aria-pressed="true"] { background: var(--os-ink); border-color: var(--os-ink); color: var(--os-panel); }
1121
+ .btn .key { font-family: ${K}; opacity: .65; font-size: 11px; }
1122
+ .primary { background: var(--os-accent); border-color: var(--os-accent); color: var(--os-on-accent); font-weight: 600; }
1123
+ .primary:hover { background: var(--os-accent-hover); border-color: var(--os-accent-hover); }
1124
+ .ghost { border-color: transparent; background: transparent; }
1125
+ .ghost:hover { background: var(--os-hover); }
1126
+ .icon { width: 36px; padding: 0; }
1127
+ .link { border: 0; background: none; padding: 0; color: var(--os-accent-text); font: 500 12px/1.4 ${G}; cursor: pointer; }
1128
+ .link:hover { text-decoration: underline; }
1129
+ .btn:focus-visible, .tab:focus-visible, .seg button:focus-visible, .link:focus-visible, .altlabel:focus-visible,
1130
+ .menu button:focus-visible, .cpin:focus-visible, .row:focus-visible, textarea:focus-visible, .check input:focus-visible, .grip:focus-visible {
1131
+ outline: 2px solid var(--os-accent); outline-offset: 2px; }
1132
+
1133
+ /* Tabs and segmented controls */
1134
+ .tabs { display: flex; gap: 2px; padding: 3px; border-radius: 8px; background: var(--os-seg); }
1135
+ .tab { min-height: 32px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--os-muted);
1136
+ font: 500 13px/1 ${G}; cursor: pointer; white-space: nowrap; transition: background-color .12s ${U}, color .12s ${U}; }
1137
+ .tab:hover { color: var(--os-ink); }
1138
+ .tab[aria-selected="true"] { background: var(--os-surface); color: var(--os-ink); box-shadow: var(--os-shadow-sm); }
1139
+ .tab .count { color: var(--os-accent-text); margin-left: 4px; }
1140
+ .seg { display: flex; flex-wrap: nowrap; padding: 3px; gap: 2px; border-radius: 9px; background: var(--os-seg); min-width: 0; }
1141
+ .seg button { flex: 1 0 auto; min-height: 32px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--os-muted);
1142
+ font: 500 12.5px/1 ${G}; cursor: pointer; white-space: nowrap; transition: background-color .14s ${U}, color .14s ${U}; }
1143
+ .seg button:hover { color: var(--os-ink); }
1144
+ .seg button[aria-pressed="true"] { background: var(--os-surface); color: var(--os-ink); box-shadow: var(--os-shadow-sm); }
1145
+ .seg button:disabled { cursor: default; opacity: .6; }
1146
+ .seg.small button { min-height: 26px; padding: 0 8px; font-size: 12px; }
1147
+
1148
+ /* Chips */
1149
+ .chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border-radius: 5px; background: var(--os-chip-bg);
1150
+ color: var(--os-chip-ink); font: 500 11.5px/1 ${K}; white-space: nowrap; max-width: 100%; }
1151
+ .chip > span { overflow: hidden; text-overflow: ellipsis; }
1152
+ .chip button { border: 0; background: none; padding: 0 0 0 2px; color: inherit; font: 600 13px/1 ${G}; cursor: pointer; opacity: .7; }
1153
+ .chip button:hover { opacity: 1; }
1154
+ .chip-dark { display: inline-flex; align-items: center; height: 22px; padding: 0 7px; border-radius: 5px; background: rgba(255,255,255,.12);
1155
+ color: var(--os-on-bubble); font: 500 11px/1 ${K}; }
1156
+ .chips { display: flex; flex-wrap: wrap; gap: 4px; }
1157
+
1158
+ /* The mover holds the dock and the panel. A drag moves it with a transform;
1159
+ the code sets each box's place for the anchor (dock.ts). */
1160
+ .mover { position: fixed; inset: 0; pointer-events: none; }
1161
+ .mover.dragging, .mover.dragging * { cursor: grabbing !important; }
1162
+ .snapping { transition: transform ${W.snap}ms ${U} !important; }
1163
+ .snaphint { position: fixed; width: 48px; height: 48px; border-radius: 50%; border: 1.5px dashed var(--os-accent); background: var(--os-mark-tint);
1164
+ pointer-events: none; opacity: .8; animation: os-fade ${W.alt}ms ${U}; }
1165
+
1166
+ /* Dock */
1167
+ .dock { position: fixed; display: inline-flex; touch-action: none; user-select: none; -webkit-user-select: none; align-items: center; justify-content: center; width: 48px; height: 48px;
1168
+ padding: 0; border-radius: 50%; border: 1px solid var(--os-line); background: var(--os-panel); cursor: pointer; box-shadow: var(--os-shadow);
1169
+ transition: transform .12s ${U}, background-color .2s ${U}, border-color .2s ${U}; pointer-events: auto; }
1170
+ .dock:hover { transform: scale(1.06); }
1171
+ .dock:active { transform: scale(.96); }
1172
+ .dock:focus-visible { outline: 2px solid var(--os-accent); outline-offset: 3px; }
1173
+ .dock .badge { position: absolute; top: -4px; right: -4px; display: inline-flex; align-items: center; justify-content: center; min-width: 20px;
1174
+ height: 20px; padding: 0 5px; border-radius: 10px; background: var(--os-accent); color: var(--os-on-accent); border: 2px solid var(--os-panel);
1175
+ font: 700 11px/1 ${G}; }
1176
+ .dotpulse { transform-origin: center; transform-box: fill-box; animation: os-dotpulse 1.4s ${U} infinite; }
1177
+
1178
+ /* The menu button on the dock's corner: it shows on hover or focus, and stays a moment so the pointer can reach it */
1179
+ .dockmore { position: fixed; z-index: 1; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; padding: 0;
1180
+ border-radius: 50%; border: 1px solid var(--os-line); background: var(--os-panel); color: var(--os-ink); cursor: pointer;
1181
+ box-shadow: var(--os-shadow-sm); pointer-events: auto; opacity: 0; visibility: hidden;
1182
+ transition: opacity ${W.tip}ms ${U}, visibility 0s linear 400ms; }
1183
+ .dock:hover + .dockmore, .dock:focus-visible + .dockmore, .dockmore:hover, .dockmore:focus-visible, .dockmore[aria-expanded="true"] {
1184
+ opacity: 1; visibility: visible; transition-delay: 0s; }
1185
+ .dockmore:hover { background: var(--os-surface); }
1186
+ .dockmore:focus-visible { outline: 2px solid var(--os-accent); outline-offset: 2px; }
1187
+
1188
+ /* The menu on the Onsite button (menu.ts): a root list, and Skills, Presets and Settings as sections */
1189
+ .smenu { position: fixed; display: flex; flex-direction: column; border-radius: 12px; background: var(--os-panel); border: 1px solid var(--os-line);
1190
+ box-shadow: var(--os-shadow); color: var(--os-ink); overflow: hidden; pointer-events: auto; }
1191
+ .smenu.opening { animation: os-pop ${W.panel}ms ${U}; }
1192
+ .mover[data-row="top"] ~ .smenu.opening { animation-name: os-drop; }
1193
+ .mbrand { display: flex; align-items: center; gap: 7px; padding: 12px 14px 6px; font: 700 13px/1 ${G}; letter-spacing: -.01em; }
1194
+ .mbrand .mhint { margin-left: auto; font-weight: 500; }
1195
+ .mlist { display: flex; flex-direction: column; padding: 4px 6px 6px; }
1196
+ .mitem { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent;
1197
+ color: var(--os-ink); font: 500 13px/1 ${G}; cursor: pointer; text-align: left; }
1198
+ .mitem:hover, .mitem:focus-visible { background: var(--os-hover); }
1199
+ .mitem svg { flex: 0 0 auto; color: var(--os-muted); }
1200
+ .mitem .grow { flex-grow: 1; }
1201
+ .mhint { font: 500 11.5px/1.3 ${G}; color: var(--os-muted); }
1202
+ .msep { height: 1px; margin: 4px 8px; background: var(--os-line); }
1203
+ .mhead { display: flex; align-items: center; gap: 4px; padding: 8px 10px 8px 6px; border-bottom: 1px solid var(--os-line); }
1204
+ .mhead h2 { margin: 0; font: 600 13.5px/1 ${G}; }
1205
+ .mhead .icon { width: 32px; min-height: 32px; }
1206
+ .sbody { display: flex; flex-direction: column; gap: 14px; padding: 12px 14px 14px; overflow-y: auto; min-height: 0; }
1207
+ .mnote { margin: 0; font-size: 12.5px; line-height: 18px; color: var(--os-muted); }
1208
+ .mgroup { display: flex; flex-direction: column; gap: 6px; }
1209
+ .mgroup h3 { display: flex; align-items: baseline; gap: 8px; margin: 0; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
1210
+ color: var(--os-muted); }
1211
+ .mgroup h3 .mhint { letter-spacing: 0; text-transform: none; font-weight: 500; font-size: 11px; }
1212
+ .mgroup > .btn { align-self: flex-start; margin-top: 2px; }
1213
+ .mrow { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--os-surface); border: 1px solid var(--os-line); min-width: 0; }
1214
+ .mrow .grow { flex-grow: 1; min-width: 0; }
1215
+ .mrow .icon { width: 30px; min-height: 30px; color: var(--os-muted); }
1216
+ .mrow .danger { min-height: 30px; padding: 0 8px; color: var(--os-del); font-size: 12px; }
1217
+ .mname { display: block; font: 600 12.5px/1.3 ${G}; color: var(--os-ink); }
1218
+ .mname .mhint { margin-left: 6px; white-space: nowrap; }
1219
+ .mname.mono { font: 600 12px/1.3 ${K}; }
1220
+ .mdesc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; font-size: 12px; line-height: 17px;
1221
+ color: var(--os-muted); }
1222
+ .mrun { display: flex; flex-direction: column; align-items: stretch; flex-grow: 1; min-width: 0; padding: 2px; border: 0; border-radius: 6px; background: none;
1223
+ color: inherit; font: inherit; text-align: left; cursor: pointer; }
1224
+ .mrun:hover .mname { color: var(--os-accent-text); }
1225
+ .switch { position: relative; flex: 0 0 auto; width: 32px; height: 18px; padding: 0; border: 0; border-radius: 9px; background: var(--os-seg); cursor: pointer;
1226
+ box-shadow: inset 0 0 0 1px var(--os-line); transition: background-color .14s ${U}; }
1227
+ .switch .knob { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--os-surface);
1228
+ box-shadow: var(--os-shadow-sm); transition: transform .14s ${U}; }
1229
+ .switch[aria-checked="true"] { background: var(--os-accent); box-shadow: none; }
1230
+ .switch[aria-checked="true"] .knob { transform: translateX(14px); background: #fff; }
1231
+ .mform { display: flex; flex-direction: column; gap: 10px; }
1232
+ .mform label, .mfield { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--os-muted); }
1233
+ .mform input, .mform textarea, .mset select { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--os-line); background: var(--os-surface);
1234
+ color: var(--os-ink); font: 400 13px/1.4 ${G}; outline: none; resize: vertical; }
1235
+ .mform input:focus-visible, .mform textarea:focus-visible, .mset select:focus-visible { border-color: var(--os-accent); box-shadow: 0 0 0 2px var(--os-mark-tint); }
1236
+ .mfield .seg { align-self: flex-start; }
1237
+ .mset { display: flex; flex-direction: column; gap: 6px; }
1238
+ .mset > label, .mset > span { font-size: 12px; font-weight: 600; color: var(--os-ink); }
1239
+ .mset .seg { align-self: flex-start; }
1240
+ .mset .mhint { margin: 0; }
1241
+ .mset select { appearance: auto; }
1242
+ .anchors { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(2, 22px); gap: 2px; justify-content: space-between;
1243
+ width: 132px; padding: 4px; border-radius: 8px; border: 1px solid var(--os-line); background: var(--os-soft); }
1244
+ .anchors button { display: flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 5px; background: transparent; cursor: pointer; }
1245
+ .anchors button:nth-child(-n+3) { align-items: flex-start; }
1246
+ .anchors button:nth-child(n+4) { align-items: flex-end; }
1247
+ .anchors button:hover { background: var(--os-hover); }
1248
+ .anchors .dot { width: 12px; height: 12px; margin: 2px; border-radius: 50%; border: 1.5px solid var(--os-muted); }
1249
+ .anchors button[aria-pressed="true"] .dot { border-color: var(--os-accent); background: var(--os-accent); }
1250
+ .minfo { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 2px 0 0; padding-top: 12px; border-top: 1px solid var(--os-line); font-size: 12px; }
1251
+ .minfo dt { color: var(--os-muted); }
1252
+ .minfo dd { margin: 0; color: var(--os-ink); overflow-wrap: anywhere; }
1253
+ .mitem:focus-visible, .mrun:focus-visible, .switch:focus-visible, .anchors button:focus-visible { outline: 2px solid var(--os-accent); outline-offset: 1px; }
1254
+ .hiddenbar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--os-line); background: var(--os-soft);
1255
+ font-size: 12px; color: var(--os-muted); }
1256
+ .hiddenbar .grow { flex-grow: 1; min-width: 0; }
1257
+ .hiddenbar .link { white-space: nowrap; }
1258
+
1259
+ /* The dock's tooltip: the shortcuts */
1260
+ .tip { position: fixed; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 11px; border-radius: 10px; background: var(--os-panel);
1261
+ border: 1px solid var(--os-line); box-shadow: var(--os-shadow); color: var(--os-ink); pointer-events: none;
1262
+ animation: os-tip ${W.tip}ms ${U}; }
1263
+ .mover[data-row="top"] .tip { animation-name: os-tip-down; }
1264
+ .tip .brand { display: flex; align-items: center; gap: 7px; font: 700 13px/1 ${G}; letter-spacing: -.01em; }
1265
+ .tip dl { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 6px 12px; margin: 0; }
1266
+ .tip dt { font-size: 12px; color: var(--os-muted); }
1267
+ .tip dd { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin: 0; font-size: 11.5px; color: var(--os-muted); white-space: nowrap; }
1268
+ .tip dd svg { color: var(--os-ink); }
1269
+ kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 5px;
1270
+ border: 1px solid var(--os-line); border-bottom-width: 2px; background: var(--os-surface); color: var(--os-ink); font: 500 12px/1 ${G}; }
1271
+
1272
+ /* Panel */
1273
+ .panel { position: fixed; display: flex; flex-direction: column; border-radius: 14px; background: var(--os-panel); border: 1px solid var(--os-line);
1274
+ box-shadow: var(--os-shadow); overflow: hidden; pointer-events: auto; transition: background-color .2s ${U}, border-color .2s ${U}; }
1275
+ .panel.opening { animation: os-pop ${W.panel}ms ${U}; }
1276
+ .mover[data-row="top"] .panel.opening { animation-name: os-drop; }
1277
+ .head { display: flex; align-items: center; gap: 6px; padding: 10px 6px 10px 10px; border-bottom: 1px solid var(--os-line); min-width: 0;
1278
+ cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
1279
+ .grip { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px;
1280
+ background: transparent; cursor: grab; flex: 0 0 auto; touch-action: none; }
1281
+ .grip:hover { background: var(--os-hover); }
1282
+ .head .grow { flex-grow: 1; min-width: 0; }
1283
+ .head .tab { padding: 0 8px; }
1284
+ .head .icon { width: 32px; }
1285
+ .scheme { padding: 0 6px; gap: 4px; font-size: 11.5px; color: var(--os-muted); flex: 0 1 auto; min-width: 0; overflow: hidden; }
1286
+ .modes { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--os-line); }
1287
+ .modes .btn { padding: 0 10px; }
1288
+ .body { flex: 1 1 auto; min-height: 220px; max-height: 420px; overflow-y: auto; padding: 14px; }
1289
+ .scroll { scrollbar-width: thin; scrollbar-color: var(--os-line) transparent; }
1290
+ .empty { display: flex; flex-direction: column; gap: 10px; padding: 18px 6px; color: var(--os-muted); font-size: 13px; line-height: 20px; }
1291
+ .empty p { margin: 0; }
1292
+ .empty .lead { color: var(--os-ink); font-weight: 600; }
1293
+ .muted { color: var(--os-muted); }
1294
+ .note { margin: 0; font-size: 13px; line-height: 20px; color: var(--os-muted); }
1295
+
1296
+ /* Thread */
1297
+ .thread { display: flex; flex-direction: column; gap: 18px; }
1298
+ .turn { display: flex; flex-direction: column; gap: 10px; }
1299
+ .ask { align-self: flex-end; max-width: 90%; padding: 10px 12px; border-radius: 10px 10px 3px 10px; background: var(--os-bubble);
1300
+ color: var(--os-on-bubble); font-size: 13px; line-height: 19px; white-space: pre-wrap; overflow-wrap: anywhere; }
1301
+ .ask .chips { margin-top: 8px; }
1302
+ .steps { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
1303
+ .step { display: flex; align-items: center; gap: 8px; min-height: 24px; font: 12px/1.3 ${K}; color: var(--os-muted); min-width: 0; }
1304
+ .step > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1305
+ .step.write { color: var(--os-ink); }
1306
+ .step svg { flex: 0 0 auto; }
1307
+ .reply { margin: 0; font-size: 13.5px; line-height: 21px; color: var(--os-ink); overflow-wrap: anywhere; }
1308
+ .reply p { margin: 0 0 8px; white-space: pre-wrap; }
1309
+ .reply p:last-child { margin-bottom: 0; }
1310
+ .reply code { font: 12px/1 ${K}; padding: 2px 4px; border-radius: 4px; background: var(--os-seg); }
1311
+ .reply pre { margin: 0 0 8px; padding: 10px; border-radius: 8px; background: var(--os-soft); border: 1px solid var(--os-line);
1312
+ font: 11.5px/17px ${K}; white-space: pre-wrap; overflow-wrap: anywhere; }
1313
+ .reply pre code { padding: 0; background: none; font: inherit; }
1314
+ .status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--os-muted); }
1315
+ .status .qdot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px dashed var(--os-mark); }
1316
+ .status .square { width: 10px; height: 10px; border-radius: 2px; background: var(--os-muted); }
1317
+ .system { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--os-muted); }
1318
+ .system.error { color: var(--os-del); }
1319
+ .caret { display: inline-block; width: 7px; height: 14px; margin-left: 2px; vertical-align: -2px; background: var(--os-accent);
1320
+ animation: os-blink 1s steps(1) infinite; }
1321
+ .spin { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--os-line); border-top-color: var(--os-accent);
1322
+ animation: os-rot .7s linear infinite; }
1323
+ .in { animation: os-in ${W.step}ms ${U}; }
1324
+
1325
+ /* Changes */
1326
+ .view { display: flex; flex-direction: column; gap: 16px; }
1327
+ .group { display: flex; flex-direction: column; gap: 6px; }
1328
+ .group h3 { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--os-muted); }
1329
+ .card { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 8px; background: var(--os-surface);
1330
+ border: 1px solid var(--os-line); min-width: 0; }
1331
+ .row { display: flex; flex-direction: column; gap: 6px; width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; color: inherit; }
1332
+ .line { display: flex; align-items: center; gap: 8px; min-width: 0; }
1333
+ .line .grow { flex-grow: 1; }
1334
+ .fname { font: 500 12.5px/1.3 ${K}; color: var(--os-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1335
+ .fdir { font: 12px/1.3 ${K}; color: var(--os-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1336
+ .new { font-size: 11px; font-weight: 600; color: var(--os-add); }
1337
+ .add { font: 12px/1 ${K}; color: var(--os-add); }
1338
+ .del { font: 12px/1 ${K}; color: var(--os-del); }
1339
+ .meta { font-size: 12px; color: var(--os-muted); }
1340
+ .diff { margin: 0; max-height: 220px; overflow: auto; padding: 8px 0; border-radius: 8px; background: var(--os-soft); border: 1px solid var(--os-line);
1341
+ font: 11.5px/17px ${K}; color: var(--os-ink); }
1342
+ .diff span { display: block; padding: 0 10px; white-space: pre; }
1343
+ .diff .plus { color: var(--os-add); }
1344
+ .diff .minus { color: var(--os-del); }
1345
+ .diff .hunk { color: var(--os-muted); }
1346
+ .note-no { flex: 0 0 22px; display: inline-flex; align-items: center; justify-content: center; height: 22px; border-radius: 11px 11px 11px 3px;
1347
+ background: var(--os-bubble); color: var(--os-on-bubble); font-size: 11px; font-weight: 700; }
1348
+ .comment { display: flex; gap: 10px; }
1349
+ .comment .text { font-size: 13px; line-height: 19px; overflow-wrap: anywhere; }
1350
+ .comment .where { font: 11.5px/1.3 ${K}; color: var(--os-muted); overflow-wrap: anywhere; }
1351
+ .comment.resolved .text { text-decoration: line-through; color: var(--os-muted); }
1352
+ .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
1353
+
1354
+ /* Export */
1355
+ .picks { display: flex; flex-direction: column; gap: 6px; }
1356
+ .check { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; line-height: 18px; cursor: pointer; min-width: 0; }
1357
+ .check input { margin: 2px 0 0; accent-color: var(--os-accent); }
1358
+ .check span { overflow-wrap: anywhere; }
1359
+ .prompt { margin: 0; max-height: 210px; overflow: auto; padding: 12px; border-radius: 8px; background: var(--os-soft); border: 1px solid var(--os-line);
1360
+ color: var(--os-ink); font: 11.5px/17px ${K}; white-space: pre-wrap; overflow-wrap: anywhere; }
1361
+ .buttons { display: flex; gap: 8px; }
1362
+ .buttons .grow { flex-grow: 1; }
1363
+
1364
+ /* Take bar */
1365
+ .takebar { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--os-line);
1366
+ background: var(--os-soft); min-width: 0; }
1367
+ .takebar .seg { flex: 0 1 auto; overflow: hidden; }
1368
+ .takebar .seg button { flex: 0 0 auto; min-width: 32px; padding: 0 8px; }
1369
+ .takebar .btn { padding: 0 10px; }
1370
+ .takebar [data-frame-skip] { margin-left: auto; }
1371
+ .takebar .takeof { display: inline-flex; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 600; color: var(--os-muted); white-space: nowrap; }
1372
+ .askstep { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 26px; padding: 0; border: 0; border-radius: 5px;
1373
+ background: none; color: var(--os-muted); cursor: pointer; }
1374
+ .askstep:hover { background: var(--os-hover); color: var(--os-ink); }
1375
+ .askstep:focus-visible { outline: 2px solid var(--os-accent); outline-offset: 1px; }
1376
+ /* The take switch (frames.ts): Original is a toggle apart from the takes. While it is on, the chosen take keeps a quiet mark. */
1377
+ .origin[aria-pressed="true"] { background: var(--os-ink); border-color: var(--os-ink); color: var(--os-panel); }
1378
+ .seg button.stale { opacity: .5; }
1379
+ .seg button.stale[aria-pressed="true"] { opacity: .7; }
1380
+ .seg.dim button[aria-pressed="true"] { background: transparent; box-shadow: inset 0 0 0 1px var(--os-line); color: var(--os-ink); }
1381
+ /* A newer ask's shown take holds a file of this take (T-019). */
1382
+ .covered { display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 180px; padding: 0 4px; font-size: 11.5px;
1383
+ font-weight: 500; color: var(--os-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }
1384
+ .covered svg { flex: 0 0 auto; }
1385
+
1386
+ /* The composer (T-025), version A "Pill": a round box with the text and icon buttons. The buttons show only the icon, with no
1387
+ fill in any state. One outline (four 1 px drop shadows) wraps the box and the quick chat's tab as one shape. In the panel the
1388
+ chips sit inside the box. In the quick chat (quick.ts), two or more elements or a chosen comment ride on a tab that docks to
1389
+ the element's frame; its corners curve inward into the box. */
1390
+ .composer { padding: 10px 12px 12px; border-top: 1px solid var(--os-line); background: var(--os-panel); }
1391
+ .pill { --ol: color-mix(in srgb, var(--os-ink) 20%, transparent); --sh: rgba(17,18,20,.10); position: relative; display: flex;
1392
+ flex-direction: column; align-items: flex-start;
1393
+ filter: drop-shadow(1px 0 0 var(--ol)) drop-shadow(-1px 0 0 var(--ol)) drop-shadow(0 1px 0 var(--ol)) drop-shadow(0 -1px 0 var(--ol))
1394
+ drop-shadow(0 6px 14px var(--sh)); }
1395
+ :host([data-scheme="dark"]) .pill { --ol: color-mix(in srgb, var(--os-ink) 22%, transparent); --sh: rgba(0,0,0,.45); }
1396
+ .pill:focus-within, :host([data-scheme="dark"]) .pill:focus-within { --ol: var(--os-mark); }
1397
+ .pbox { align-self: stretch; display: flex; flex-direction: column; gap: 4px; min-height: 44px; padding: 6px 6px 6px 16px; border-radius: 22px;
1398
+ background: var(--os-surface); }
1399
+ .pbox > .chips { padding: 4px 10px 0 0; }
1400
+ .prow { display: flex; align-items: flex-end; gap: 2px; min-width: 0; }
1401
+ .prow .field { display: flex; flex: 1 1 auto; align-self: center; min-width: 0; }
1402
+ .pill textarea { display: block; width: 100%; min-height: 32px; max-height: 120px; padding: 6px 0; border: 0; outline: none; resize: none;
1403
+ background: transparent; color: var(--os-ink); font: 400 14px/20px ${G}; overflow-y: auto; scrollbar-width: thin; }
1404
+ .pill textarea::placeholder { color: var(--os-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
1405
+ .pill textarea:focus-visible { outline: none; }
1406
+ .tools { display: flex; align-items: center; flex: 0 0 auto; }
1407
+ .ib { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 0;
1408
+ border-radius: 8px; background: none; color: var(--os-muted); cursor: pointer; flex: 0 0 auto;
1409
+ transition: color .12s ${U}, opacity .12s ${U}, transform ${W.press}ms ${U}; }
1410
+ .ib:hover { color: var(--os-ink); }
1411
+ .ib:active { transform: scale(.9); }
1412
+ .ib:focus-visible { outline: 2px solid var(--os-accent); outline-offset: -1px; color: var(--os-ink); }
1413
+ .ib[aria-disabled="true"] { color: var(--os-muted); opacity: .45; cursor: default; transform: none; }
1414
+ .ib.go { color: var(--os-accent-text); }
1415
+ .ib.go:hover, .ib.go:focus-visible { color: color-mix(in srgb, var(--os-accent-text) 72%, var(--os-ink)); }
1416
+ .ib.go[aria-disabled="true"] { color: var(--os-muted); opacity: .55; }
1417
+ .ib.stop { color: var(--os-ink); }
1418
+ .ib .tbadge { position: absolute; top: 1px; right: -3px; min-width: 20px; height: 16px; padding: 0 3px; border-radius: 8px; background: var(--os-seg);
1419
+ color: var(--os-muted); font: 700 10.5px/16px ${G}; text-align: center; box-shadow: 0 0 0 2px var(--os-surface); pointer-events: none; }
1420
+ .ib.takes[data-n="2"] .tbadge, .ib.takes[data-n="3"] .tbadge { background: var(--os-accent); color: var(--os-on-accent); }
1421
+ .ib.takes.bump .tbadge { animation: os-bump 220ms ${U}; }
1422
+ .pill .chips { gap: 4px; }
1423
+ .pill .chip { gap: 5px; padding: 0 2px 0 7px; border-radius: 6px; }
1424
+ .pill .chip > svg { flex: 0 0 auto; opacity: .8; }
1425
+ .pill .chip .x { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; padding: 0; border: 0;
1426
+ border-radius: 4px; background: none; color: inherit; opacity: .65; cursor: pointer; }
1427
+ .pill .chip .x:hover { opacity: 1; }
1428
+ .pill .chip .x:focus-visible { opacity: 1; outline: 2px solid var(--os-accent); outline-offset: 0; }
1429
+ /* The tab: white, out of the box's top edge, at --tab-x from the card's left edge (quick.ts, TAB_INSET at least) */
1430
+ .ptab { position: relative; margin-left: var(--tab-x, 30px); max-width: calc(100% - var(--tab-x, 30px) - 30px); padding: 5px 5px 3px;
1431
+ border-radius: 10px 10px 0 0; background: var(--os-surface); }
1432
+ .ptab::before, .ptab::after { content: ""; position: absolute; bottom: 0; width: 10px; height: 10px; }
1433
+ .ptab::before { right: 100%; background: radial-gradient(circle at 0 0, transparent 10px, var(--os-surface) 10.5px); }
1434
+ .ptab::after { left: 100%; background: radial-gradient(circle at 100% 0, transparent 10px, var(--os-surface) 10.5px); }
1435
+
1436
+ /* The quick chat (quick.ts): the composer in a card beside the selected element. Only the box and the tab take the pointer. */
1437
+ .quick { position: fixed; pointer-events: none; }
1438
+ .quick .composer { padding: 0; border: 0; background: none; }
1439
+ .quick .pbox, .quick .ptab { pointer-events: auto; }
1440
+ .quick.opening { animation: os-dock-down ${W.step}ms ${U}; }
1441
+ .quick[data-side="above"].opening { animation-name: os-dock-up; }
1442
+ /* Above the element, the tab sits on the box's bottom edge and touches the frame's top edge. */
1443
+ .quick[data-side="above"] .pill { flex-direction: column-reverse; }
1444
+ .quick[data-side="above"] .ptab { padding: 3px 5px 5px; border-radius: 0 0 10px 10px; }
1445
+ .quick[data-side="above"] .ptab::before, .quick[data-side="above"] .ptab::after { top: 0; bottom: auto; }
1446
+ .quick[data-side="above"] .ptab::before { background: radial-gradient(circle at 0 100%, transparent 10px, var(--os-surface) 10.5px); }
1447
+ .quick[data-side="above"] .ptab::after { background: radial-gradient(circle at 100% 100%, transparent 10px, var(--os-surface) 10.5px); }
1448
+
1449
+ /* The tooltip of the composer's icon buttons (tooltip.ts): the label, the keys, and a line with more words */
1450
+ .icontip { position: fixed; z-index: 4; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; max-width: 260px; padding: 6px 8px;
1451
+ border-radius: 7px; background: var(--os-bubble); color: var(--os-on-bubble); font: 500 12.5px/1.3 ${G}; box-shadow: var(--os-shadow-md);
1452
+ pointer-events: none; animation: os-in ${W.tip}ms ${U}; }
1453
+ .icontip .tl { margin-right: 2px; }
1454
+ .icontip kbd { min-width: 18px; height: 18px; padding: 0 4px; border: 0; border-radius: 4px; background: rgba(255,255,255,.14); color: inherit;
1455
+ font: 600 11.5px/1 ${G}; }
1456
+ .icontip .tm { flex-basis: 100%; color: color-mix(in srgb, var(--os-on-bubble) 72%, transparent); font-weight: 400; }
1457
+ @keyframes os-bump { 50% { transform: scale(1.25); } }
1458
+ @keyframes os-dock-down { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
1459
+ @keyframes os-dock-up { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
1460
+
1461
+ /* Menus and toasts */
1462
+ .menu { position: fixed; z-index: 3; width: 220px; padding: 6px; border-radius: 10px; background: var(--os-panel); border: 1px solid var(--os-line);
1463
+ box-shadow: var(--os-shadow); pointer-events: auto; animation: os-pop 140ms ${U}; }
1464
+ .menu button { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; min-height: 34px; padding: 0 10px;
1465
+ border: 0; border-radius: 6px; background: transparent; color: var(--os-ink); font: 500 13px/1 ${G}; cursor: pointer; text-align: left; }
1466
+ .menu button:hover, .menu button[aria-checked="true"] { background: var(--os-hover); }
1467
+ .menu button span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1468
+ .menu .on { color: var(--os-accent-text); flex: 0 0 auto; }
1469
+ .menu .hint { padding: 6px 10px 2px; font-size: 11px; color: var(--os-muted); }
1470
+ .toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
1471
+ padding: 10px 10px 10px 16px; border-radius: 10px; background: var(--os-panel); border: 1px solid var(--os-line); color: var(--os-ink);
1472
+ font-size: 13px; box-shadow: var(--os-shadow); pointer-events: auto; animation: os-toast 200ms ${U}; }
1473
+ [data-toast="top"] > .toast { top: 28px; bottom: auto; }
1474
+ .toast.plain { padding-right: 16px; }
1475
+ .toast .btn { min-height: 30px; color: var(--os-accent-text); }
1476
+
1477
+ /* The page layer: everything drawn over the app */
1478
+ .page { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
1479
+ .box { position: fixed; pointer-events: none; border-radius: 8px; }
1480
+ .hover { background: var(--os-mark-tint); box-shadow: inset 0 0 0 2px var(--os-mark); }
1481
+ .tag { position: absolute; left: 0; bottom: calc(100% + 6px); padding: 6px 8px; border-radius: 5px; background: var(--os-panel);
1482
+ border: 1px solid var(--os-mark); color: var(--os-ink); font: 500 11px/1 ${K}; white-space: nowrap; }
1483
+ .pinned { box-shadow: inset 0 0 0 2px var(--os-mark); animation: os-fade 100ms ${U}; }
1484
+ .pinno { position: absolute; top: -11px; left: -11px; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
1485
+ border-radius: 50%; background: var(--os-mark); color: var(--os-on-mark); font: 700 11px/1 ${G}; }
1486
+ .flash { animation: os-flash ${W.flash}ms ${U} forwards; }
1487
+ .flash .updated { position: absolute; left: 0; bottom: calc(100% + 4px); padding: 4px 6px; border-radius: 5px; background: var(--os-mark);
1488
+ color: var(--os-on-mark); font: 600 11px/1 ${K}; white-space: nowrap; }
1489
+ .swap { backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); animation: os-swap ${W.swap}ms ${U} forwards; }
1490
+ .alt { border: 1.5px dashed var(--os-mark); animation: os-fade ${W.alt}ms ${U}; }
1491
+ .altlabel { position: fixed; display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border-radius: 5px; border: 0;
1492
+ background: var(--os-mark); color: var(--os-on-mark); font: 600 11px/1 ${K}; cursor: pointer; pointer-events: auto; white-space: nowrap;
1493
+ animation: os-in ${W.alt}ms ${U}; }
1494
+ .cpin { position: fixed; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0;
1495
+ border-radius: 12px 12px 12px 3px; background: var(--os-panel); border: 1px solid var(--os-line); color: var(--os-ink); font: 700 11px/1 ${G};
1496
+ box-shadow: var(--os-shadow-sm); cursor: pointer; pointer-events: auto; }
1497
+ .cpin.on { background: var(--os-mark); border-color: var(--os-mark); color: var(--os-on-mark); }
1498
+ .popover { position: fixed; width: 260px; padding: 12px; border-radius: 10px; background: var(--os-panel); border: 1px solid var(--os-line);
1499
+ box-shadow: var(--os-shadow); pointer-events: auto; display: flex; flex-direction: column; gap: 8px; animation: os-pop 140ms ${U}; }
1500
+ /* The frame of a run (frames.ts): a moving dashed border while it works, a still outline after it */
1501
+ .frame { border-radius: 4px; }
1502
+ .frame.fresh { animation: os-fade ${W.alt}ms ${U}; }
1503
+ .frame.working {
1504
+ background:
1505
+ linear-gradient(90deg, var(--os-mark) 60%, transparent 0) 0 0 / 10px 1.5px repeat-x,
1506
+ linear-gradient(90deg, var(--os-mark) 60%, transparent 0) 0 100% / 10px 1.5px repeat-x,
1507
+ linear-gradient(0deg, var(--os-mark) 60%, transparent 0) 0 0 / 1.5px 10px repeat-y,
1508
+ linear-gradient(0deg, var(--os-mark) 60%, transparent 0) 100% 0 / 1.5px 10px repeat-y;
1509
+ animation: os-ants ${W.ants}ms linear infinite; }
1510
+ .frame.done { box-shadow: inset 0 0 0 1.5px var(--os-mark); }
1511
+ /* An ask that waits in the queue (T-016): a still, faint dashed border, and a tag with × to cancel. */
1512
+ .frame.queued { border: 1.5px dashed color-mix(in srgb, var(--os-mark) 55%, transparent); }
1513
+ .framequeue { position: fixed; display: inline-flex; align-items: center; gap: 2px; height: 24px; padding: 0 2px 0 8px; border-radius: 5px;
1514
+ border: 1px solid var(--os-mark); background: var(--os-panel); color: var(--os-ink); font: 600 11px/1 ${K}; white-space: nowrap;
1515
+ pointer-events: auto; box-shadow: var(--os-shadow-sm); animation: os-in ${W.alt}ms ${U}; }
1516
+ .framequeue button { width: 20px; height: 20px; padding: 0; border: 0; border-radius: 4px; background: none; color: var(--os-muted);
1517
+ font-size: 14px; line-height: 1; cursor: pointer; }
1518
+ .framequeue button:hover { background: var(--os-hover); color: var(--os-ink); }
1519
+ .framequeue button:focus-visible { outline: 2px solid var(--os-accent); outline-offset: 1px; }
1520
+ /* A write inside a frame: the frame glows once, with no tint over the change. */
1521
+ .framepulse { border-radius: 4px; box-shadow: 0 0 0 1.5px var(--os-mark), 0 0 14px 2px var(--os-mark-tint);
1522
+ animation: os-framepulse ${W.flash}ms ${U} forwards; }
1523
+ @keyframes os-framepulse { from { opacity: 1; } to { opacity: 0; } }
1524
+ .frametag { position: fixed; display: inline-flex; align-items: center; gap: 6px; height: 24px; max-width: 320px; padding: 0 8px; border-radius: 5px;
1525
+ background: var(--os-mark); color: var(--os-on-mark); font: 600 11px/1 ${K}; white-space: nowrap; pointer-events: none;
1526
+ animation: os-in ${W.alt}ms ${U}; }
1527
+ .frametag > span:last-child { overflow: hidden; text-overflow: ellipsis; }
1528
+ .frametag .spin { width: 10px; height: 10px; border-width: 1.5px; border-color: rgba(0,0,0,.18); border-top-color: var(--os-on-mark); flex: 0 0 auto; }
1529
+ .framefold { position: fixed; display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 6px 0 8px; border-radius: 5px;
1530
+ border: 1px solid var(--os-mark); background: var(--os-panel); color: var(--os-ink); font: 600 11px/1 ${K}; cursor: pointer;
1531
+ pointer-events: auto; white-space: nowrap; box-shadow: var(--os-shadow-sm); animation: os-in ${W.alt}ms ${U}; }
1532
+ .framefold:hover { background: var(--os-surface); }
1533
+ .framebar { position: fixed; display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 10px; background: var(--os-panel);
1534
+ border: 1px solid var(--os-line); box-shadow: var(--os-shadow-md); pointer-events: auto; white-space: nowrap;
1535
+ animation: os-in ${W.step}ms ${U}; }
1536
+ .framebar .framemark { display: inline-flex; padding: 0 4px 0 5px; }
1537
+ .framebar .seg { padding: 2px; border-radius: 7px; }
1538
+ .framebar .seg button { flex: 0 0 auto; min-width: 28px; min-height: 26px; padding: 0 9px; border-radius: 5px; font-size: 12px; }
1539
+ .framebar .btn { min-height: 30px; padding: 0 10px; border-radius: 7px; font-size: 12.5px; }
1540
+ .framebar .icon { width: 30px; padding: 0; font-size: 16px; color: var(--os-muted); }
1541
+ .framebar [aria-disabled="true"] { opacity: .45; cursor: default; }
1542
+ .framebar[aria-busy="true"], .framebar[aria-busy="true"] button { cursor: progress; }
1543
+ .framebar .btn[aria-disabled="true"]:active { transform: none; }
1544
+ .framebar:focus-visible, .framefold:focus-visible { outline: 2px solid var(--os-accent); outline-offset: 2px; }
1545
+ /* The note of a take (T-024): a speech-bubble pin in the mark colour, the shape of a comment pin, and its card */
1546
+ .notepin { position: fixed; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0;
1547
+ border-radius: 12px 12px 12px 3px; background: var(--os-mark); border: 1px solid var(--os-mark); color: var(--os-on-mark);
1548
+ box-shadow: var(--os-shadow-sm); cursor: pointer; pointer-events: auto; }
1549
+ .notepin svg { width: 13px; height: 13px; }
1550
+ .notepin:hover, .notepin.on { box-shadow: 0 0 0 3px var(--os-mark-tint), var(--os-shadow-sm); }
1551
+ .notepin:focus-visible { outline: 2px solid var(--os-accent); outline-offset: 2px; }
1552
+ .notehead { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; line-height: 16px; overflow-wrap: anywhere; }
1553
+ .notehead::before { content: ""; flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--os-mark); }
1554
+ /* The question card (question.ts): asks before a stale take shows */
1555
+ .question { position: fixed; display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: 10px; background: var(--os-panel);
1556
+ border: 1px solid var(--os-line); box-shadow: var(--os-shadow); color: var(--os-ink); pointer-events: auto; z-index: 1;
1557
+ animation: os-pop ${W.step}ms ${U}; }
1558
+ .question[data-side="below"] { animation-name: os-drop; }
1559
+ .question .text { margin: 0; font-size: 13px; line-height: 19px; overflow-wrap: anywhere; }
1560
+ .question .btn { min-height: 32px; }
1561
+ .popover .text { font-size: 13px; line-height: 19px; overflow-wrap: anywhere; }
1562
+ .popover .where { font: 11.5px/1.3 ${K}; color: var(--os-muted); overflow-wrap: anywhere; }
1563
+
1564
+ @keyframes os-dotpulse { 0% { opacity: .9; transform: scale(1); } 70%, 100% { opacity: 0; transform: scale(2.6); } }
1565
+ @keyframes os-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
1566
+ @keyframes os-drop { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }
1567
+ @keyframes os-tip { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
1568
+ @keyframes os-tip-down { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
1569
+ @keyframes os-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
1570
+ @keyframes os-fade { from { opacity: 0; } to { opacity: 1; } }
1571
+ @keyframes os-swap { from { opacity: 1; } to { opacity: 0; } }
1572
+ @keyframes os-blink { 50% { opacity: 0; } }
1573
+ @keyframes os-rot { to { transform: rotate(360deg); } }
1574
+ @keyframes os-toast { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
1575
+ @keyframes os-flash { 0% { background: var(--os-mark-tint); box-shadow: 0 0 0 0 var(--os-mark); }
1576
+ 35% { box-shadow: 0 0 0 4px var(--os-mark); } 100% { background: transparent; box-shadow: 0 0 0 14px transparent; } }
1577
+ @keyframes os-still { 0% { box-shadow: inset 0 0 0 2px var(--os-mark); } 100% { box-shadow: none; } }
1578
+ @keyframes os-ants { to { background-position: 10px 0, -10px 100%, 0 -10px, 100% 10px; } }
1579
+
1580
+ @media (prefers-reduced-motion: reduce) {
1581
+ .panel.opening, .in, .menu, .toast, .pinned, .alt, .altlabel, .popover, .caret, .dotpulse, .swap, .tip, .snaphint,
1582
+ .frame.fresh, .frame.working, .frametag, .framefold, .framebar, .framepulse, .framequeue, .smenu.opening, .quick.opening,
1583
+ .question { animation: none; }
1584
+ .switch, .switch .knob { transition: none; }
1585
+ /* No fade, but the menu button still stays a moment so the pointer can reach it. */
1586
+ .dockmore { transition: visibility 0s linear 400ms; }
1587
+ .dotpulse, .swap { display: none; }
1588
+ .flash { animation: os-still ${W.stillFlash}ms steps(1) forwards; }
1589
+ .spin { animation-duration: 2s; }
1590
+ .btn, .tab, .seg button, .dock, .panel { transition: none; }
1591
+ .snapping { transition: none !important; }
1592
+ .btn:active, .dock:hover, .dock:active { transform: none; }
1593
+ /* The composer (T-025) */
1594
+ .quick.opening, .quick[data-side="above"].opening, .ib.takes.bump .tbadge, .icontip { animation: none; }
1595
+ .ib { transition: none; }
1596
+ .ib:active { transform: none; }
1597
+ }
1598
+ `;
1599
+ function q(t, n, r = 30) {
1600
+ let i = /* @__PURE__ */ new Set(), a = (e) => {
1601
+ let t = 0;
1602
+ for (let a of e) {
1603
+ if (t >= r) return;
1604
+ a === document.documentElement || a === document.body || a === n || n?.contains(a) || (i.add(a), t++);
1605
+ }
1606
+ };
1607
+ for (let n of t.stamps ?? []) a(document.querySelectorAll(`[${e}="${CSS.escape(n)}"]`));
1608
+ for (let e of t.selectors ?? []) try {
1609
+ a(document.querySelectorAll(e));
1610
+ } catch {}
1611
+ return [...i];
1612
+ }
1613
+ function Lt(t) {
1614
+ return t instanceof Element ? t.closest(`[${e}]`) : null;
1615
+ }
1616
+ var J = (e) => e.width > 0 && e.height > 0 && e.bottom > 0 && e.right > 0 && e.top < innerHeight && e.left < innerWidth, Rt = class {
1617
+ host;
1618
+ read;
1619
+ act;
1620
+ root;
1621
+ drawn = [];
1622
+ temp = [];
1623
+ frameId = 0;
1624
+ altGroups = [];
1625
+ menu = null;
1626
+ card = null;
1627
+ frames = [];
1628
+ ctls = /* @__PURE__ */ new Map();
1629
+ framesKey = "";
1630
+ seen = /* @__PURE__ */ new Map();
1631
+ redrawId = 0;
1632
+ openNote = "";
1633
+ outside = (e) => {
1634
+ let t = e.composedPath(), n = this.frames.find((e) => e.run === this.openNote);
1635
+ [n?.note, n?.noteCard].some((e) => e && t.includes(e)) || this.toggleNote("");
1636
+ };
1637
+ toggleNote(e) {
1638
+ this.openNote = e, e ? window.addEventListener("pointerdown", this.outside, !0) : window.removeEventListener("pointerdown", this.outside, !0), this.draw();
1639
+ }
1640
+ constructor(e, t, n) {
1641
+ this.host = e, this.read = t, this.act = n, this.root = j("div", {
1642
+ class: "page",
1643
+ "data-layer": "page",
1644
+ "aria-live": "off"
1645
+ });
1646
+ }
1647
+ draw() {
1648
+ let e = this.read();
1649
+ this.root.dataset.scheme = e.pageScheme;
1650
+ let n = this.root.isConnected ? this.root.getRootNode().activeElement : null, r = n && this.root.contains(n) ? n.getAttribute("data-fkey") : null;
1651
+ for (let e of this.drawn) e.box.remove();
1652
+ for (let e of this.altGroups) e.label.remove();
1653
+ for (let e of this.frames) e.note?.remove(), e.noteCard?.remove();
1654
+ if (this.menu?.remove(), this.card?.box.remove(), this.drawn = [], this.altGroups = [], this.frames = [], this.menu = null, this.card = null, e.alt === "off" ? this.drawFrames(e) : (this.dropCtls(/* @__PURE__ */ new Set()), e.altMarks && this.drawAlt(e)), e.pins.forEach((e, t) => {
1655
+ let n = j("div", { class: "box pinned" }, j("span", { class: "pinno" }, String(t + 1)));
1656
+ this.keep({
1657
+ el: e,
1658
+ box: n,
1659
+ pad: 4
1660
+ });
1661
+ }), e.hover && !e.pins.includes(e.hover)) {
1662
+ let n = e.hover.getAttribute("data-onsite-src") ?? "", r = e.hover.getAttribute(t), i = j("div", { class: "box hover" }, j("span", { class: "tag" }, `${r ? `${r} · ` : ""}${c(n)}`));
1663
+ this.keep({
1664
+ el: e.hover,
1665
+ box: i,
1666
+ pad: 4
1667
+ });
1668
+ }
1669
+ this.drawCommentPins(e), this.position(), r && [...this.root.querySelectorAll("[data-fkey]")].find((e) => e.getAttribute("data-fkey") === r)?.focus({ preventScroll: !0 });
1670
+ let i = this.frames.map((e) => `${e.run}:${e.els.length}:${e.ctl.className}`).join(" ");
1671
+ i !== this.framesKey && (this.framesKey = i, this.act.framesChanged());
1672
+ }
1673
+ drawFrames(e) {
1674
+ let t = `-${Math.round(performance.now() % W.ants)}ms`;
1675
+ for (let n of e.frames) {
1676
+ let r = q({ stamps: n.selected }, this.host);
1677
+ if (r.length === 0) {
1678
+ let t = ht(n.run, n.takes, e.frameMarks, e.showing), i = e.liveMarks.get(n.run);
1679
+ i && B(t.all, i), r = q(t.all, this.host).slice(0, 1);
1680
+ }
1681
+ let i = r[0];
1682
+ if (!i) {
1683
+ let e = this.ctls.get(n.run);
1684
+ e && (e.hidden = !0);
1685
+ continue;
1686
+ }
1687
+ let a = this.seen.get(n.run);
1688
+ a || (a = /* @__PURE__ */ new WeakSet(), this.seen.set(n.run, a));
1689
+ for (let e of r) {
1690
+ let r = j("div", {
1691
+ class: `box frame ${n.running ? "working" : n.queued ? "queued" : "done"}${a.has(e) ? "" : " fresh"}`,
1692
+ "data-frame": n.run
1693
+ });
1694
+ n.running && (r.style.animationDelay = t), a.add(e), this.keep({
1695
+ el: e,
1696
+ box: r,
1697
+ pad: 4
1698
+ });
1699
+ }
1700
+ let o = this.keepCtl(n.run, n.running ? Ct(n) : n.queued ? wt(n, this.act) : n.run === e.barRun ? Et(n, {
1701
+ showing: e.showing,
1702
+ picked: e.picked,
1703
+ all: e.takes,
1704
+ asks: e.asks
1705
+ }, e.busy, this.act) : Tt(n, this.act)), s = {
1706
+ run: n.run,
1707
+ els: r,
1708
+ main: i,
1709
+ ctl: o
1710
+ }, c = Ot(n, e.showing, e.picked);
1711
+ if (c) {
1712
+ let e = this.openNote === n.run;
1713
+ s.note = kt(n, c, e, () => this.toggleNote(e ? "" : n.run)), this.root.append(s.note), e && (s.noteCard = this.root.appendChild(At(n, c)));
1714
+ }
1715
+ this.frames.push(s);
1716
+ }
1717
+ this.dropCtls(new Set(e.frames.map((e) => e.run))), this.openNote && !this.frames.some((e) => e.run === this.openNote && e.note) && (this.openNote = "", window.removeEventListener("pointerdown", this.outside, !0));
1718
+ }
1719
+ keepCtl(e, t) {
1720
+ let n = P() ? 2e3 : 700;
1721
+ for (let e of t.querySelectorAll(".spin")) e.style.animationDelay = `-${Math.round(performance.now() % n)}ms`;
1722
+ let r = this.ctls.get(e);
1723
+ if (!r || r.tagName !== t.tagName || r.className !== t.className) return r?.remove(), this.root.append(t), this.ctls.set(e, t), t;
1724
+ for (let e of [...r.attributes]) t.hasAttribute(e.name) || r.removeAttribute(e.name);
1725
+ for (let e of [...t.attributes]) r.getAttribute(e.name) !== e.value && r.setAttribute(e.name, e.value);
1726
+ return r.replaceChildren(...t.childNodes), r.hidden = !1, r.isConnected || this.root.append(r), r;
1727
+ }
1728
+ dropCtls(e) {
1729
+ for (let [t, n] of this.ctls) e.has(t) || (n.remove(), this.ctls.delete(t));
1730
+ }
1731
+ frameTargets() {
1732
+ let e = this.read(), t = this.frames.find((t) => t.run === e.barRun) ?? this.frames.find((t) => e.frames.some((e) => e.run === t.run && e.running));
1733
+ return t ? [t.main, t.ctl] : [];
1734
+ }
1735
+ frameKey(e) {
1736
+ if (e.key === "Escape" && this.openNote && e.composedPath().some((e) => e instanceof HTMLElement && (e.hasAttribute("data-notepin") || e.hasAttribute("data-notecard")))) return this.toggleNote(""), !0;
1737
+ let t = e.composedPath().find((e) => e instanceof HTMLElement && e.hasAttribute("data-framebar"));
1738
+ if (!t) return !1;
1739
+ let n = this.read(), r = n.frames.find((e) => e.run === t.getAttribute("data-framebar"));
1740
+ if (!r) return !1;
1741
+ let i = H(r.run, r.takes, n.showing, n.picked);
1742
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
1743
+ let t = Math.max(0, r.takes.findIndex((e) => e.id === i?.id)), a = r.takes[Math.max(0, Math.min(r.takes.length - 1, t + (e.key === "ArrowLeft" ? -1 : 1)))];
1744
+ return a && !n.showing.includes(a.id) && !n.busy && this.act.show(a.id), !0;
1745
+ }
1746
+ if (e.key === "o" || e.key === "O") return n.busy || this.act.toggleOriginal(r.run), !0;
1747
+ if (e.key === "Enter") {
1748
+ let t = e.composedPath()[0];
1749
+ return t instanceof HTMLElement && t.matches("button:not([data-frame-keep])") ? !1 : (i && !n.busy && this.act.keep(i), !0);
1750
+ }
1751
+ return e.key === "Escape" && (this.act.openFrame(""), !0);
1752
+ }
1753
+ keep(e) {
1754
+ this.root.append(e.box), this.drawn.push(e);
1755
+ }
1756
+ drawCommentPins(e) {
1757
+ let t = /* @__PURE__ */ new Map();
1758
+ e.comments.forEach((n, r) => {
1759
+ if (n.resolved) return;
1760
+ let i = q({ stamps: [n.stamp.src] }, this.host, 1)[0];
1761
+ if (!i) return;
1762
+ let a = t.get(i) ?? 0;
1763
+ t.set(i, a + 1);
1764
+ let o = r + 1, s = j("button", {
1765
+ class: `cpin${e.chosen.includes(n.id) || e.openComment === n.id ? " on" : ""}`,
1766
+ type: "button",
1767
+ "aria-label": `Comment ${o}: ${n.text}`,
1768
+ title: n.text,
1769
+ on: { click: (t) => {
1770
+ t.stopPropagation(), this.act.openComment(e.openComment === n.id ? "" : n.id);
1771
+ } }
1772
+ }, String(o));
1773
+ this.keep({
1774
+ el: i,
1775
+ box: s,
1776
+ pad: 0,
1777
+ at: (e) => ({
1778
+ left: e.right - 36 - a * 30,
1779
+ top: e.top - 12
1780
+ })
1781
+ }), e.openComment === n.id && this.drawCard(i, n, o, e);
1782
+ });
1783
+ }
1784
+ drawCard(e, t, n, r) {
1785
+ let i = r.chosen.includes(t.id), a = r.takes.find((e) => e.id === t.take), o = r.takes.filter((e) => e.state === "open" || e.state === "kept"), s = t.take ? `on ${a ? m(a, o, r.asks) : u(t.takeNo ?? 0)}` : "on the original", c = j("div", {
1786
+ class: "popover",
1787
+ role: "dialog",
1788
+ "aria-label": `Comment ${n}`
1789
+ }, j("div", { class: "text" }, t.text), j("div", { class: "where" }, `${l(t.stamp)} · ${s}`), j("div", { class: "actions" }, j("button", {
1790
+ class: "btn",
1791
+ type: "button",
1792
+ on: { click: () => this.act.chooseComment(t.id) }
1793
+ }, i ? "Leave out of the ask" : "Add to the ask"), j("button", {
1794
+ class: "btn ghost",
1795
+ type: "button",
1796
+ on: { click: () => this.act.resolve(t.id) }
1797
+ }, "Resolve")));
1798
+ this.root.append(c), this.card = {
1799
+ el: e,
1800
+ box: c
1801
+ };
1802
+ }
1803
+ drawAlt(e) {
1804
+ let t = e.altMarks, n = /* @__PURE__ */ new Set();
1805
+ for (let r of t.groups) {
1806
+ let t = q(r, this.host);
1807
+ if (!t.length) continue;
1808
+ for (let e of t) n.has(e) || (n.add(e), this.keep({
1809
+ el: e,
1810
+ box: j("div", { class: "box alt" }),
1811
+ pad: 4
1812
+ }));
1813
+ let a = [...r.takes].sort().join(" "), s = r.stamps[0], c = s ? i(o(s)) : r.selectors[0] ?? "Styles", l = j("button", {
1814
+ class: "altlabel",
1815
+ type: "button",
1816
+ "aria-haspopup": "menu",
1817
+ "aria-expanded": String(e.altMenu === a),
1818
+ "aria-label": `Versions of ${c}`,
1819
+ on: { click: (e) => {
1820
+ e.stopPropagation(), this.act.toggleAltMenu(a);
1821
+ } }
1822
+ }, `${c} · ${r.takes.length + 1} versions ▾`);
1823
+ this.root.append(l), this.altGroups.push({
1824
+ key: a,
1825
+ takes: r.takes,
1826
+ els: t,
1827
+ label: l
1828
+ });
1829
+ }
1830
+ let r = this.altGroups.find((t) => t.key === e.altMenu);
1831
+ r && (this.menu = this.root.appendChild(this.versionMenu(r.takes, e)));
1832
+ }
1833
+ versionMenu(e, t) {
1834
+ let n = e.map((e) => t.takes.find((t) => t.id === e)).filter((e) => !!e).sort((e, t) => e.no - t.no), r = t.showing.findLast((t) => e.includes(t)) ?? "", i = (t, n) => j("button", {
1835
+ type: "button",
1836
+ role: "menuitemradio",
1837
+ "aria-checked": String(t === r),
1838
+ on: { click: (n) => {
1839
+ n.stopPropagation(), t === "" ? r && this.act.hideTakes(e) : this.act.show(t);
1840
+ } }
1841
+ }, j("span", null, n), j("span", { class: "on" }, t === r ? "Shown" : ""));
1842
+ return j("div", {
1843
+ class: "menu",
1844
+ role: "menu",
1845
+ "aria-label": "Versions"
1846
+ }, i("", "Original"), n.map((e) => i(e.id, [m(e, n, t.asks), e.label].filter(Boolean).join(" · "))), t.alt === "held" ? j("div", { class: "hint" }, `Release ${this.act.altKeyName()} to close`) : null);
1847
+ }
1848
+ position() {
1849
+ let e = /* @__PURE__ */ new Map(), t = (t) => {
1850
+ let n = e.get(t);
1851
+ return n || (n = t.isConnected ? t.getBoundingClientRect() : new DOMRect(), e.set(t, n)), n;
1852
+ };
1853
+ for (let e of [...this.drawn, ...this.temp]) {
1854
+ let n = t(e.el), r = e.el.isConnected && (J(n) || e.at !== void 0 && n.width + n.height > 0);
1855
+ if (e.box.hidden = !r, r) {
1856
+ if (e.at) {
1857
+ let t = e.at(n, e.box);
1858
+ if (!t) {
1859
+ e.box.hidden = !0;
1860
+ continue;
1861
+ }
1862
+ e.box.style.left = `${Math.max(2, Math.min(t.left, innerWidth - 28))}px`, e.box.style.top = `${Math.max(2, t.top)}px`;
1863
+ } else ot(e.box, n, e.pad);
1864
+ }
1865
+ }
1866
+ if (this.positionAlt(t), this.positionFrames(t), this.card) {
1867
+ let e = t(this.card.el), n = Math.max(8, Math.min(e.right - 260, innerWidth - 268)), r = this.read().avoid;
1868
+ r && n + 260 > r.left && (n = Math.max(8, r.left - 268));
1869
+ let i = e.top + 18, a = this.card.box.offsetHeight || 120;
1870
+ this.card.box.style.left = `${n}px`, this.card.box.style.top = `${Math.max(8, Math.min(i, innerHeight - a - 8))}px`;
1871
+ }
1872
+ this.act.positioned?.();
1873
+ }
1874
+ positionAlt(e) {
1875
+ let t = null, n = this.read().altMenu, r = (e) => ({
1876
+ left: e.left - 4,
1877
+ top: e.top - 4,
1878
+ width: e.width + 8,
1879
+ height: e.height + 8
1880
+ }), i = [], a = [];
1881
+ for (let t of this.altGroups) {
1882
+ let n = null, o = [];
1883
+ for (let i of t.els) {
1884
+ let t = e(i);
1885
+ J(t) && (o.push(r(t)), (!n || t.top < n.top - 1 || Math.abs(t.top - n.top) <= 1 && t.left < n.left) && (n = t));
1886
+ }
1887
+ t.label.hidden = !n, n && (i.push({
1888
+ anchor: r(n),
1889
+ own: o,
1890
+ size: {
1891
+ w: t.label.offsetWidth || 160,
1892
+ h: t.label.offsetHeight || 24
1893
+ }
1894
+ }), a.push(t));
1895
+ }
1896
+ let o = xt(i, {
1897
+ w: document.documentElement.clientWidth || innerWidth,
1898
+ h: document.documentElement.clientHeight || innerHeight
1899
+ });
1900
+ for (let [e, r] of a.entries()) {
1901
+ let i = o[e];
1902
+ r.label.style.left = `${i.left}px`, r.label.style.top = `${i.top}px`, r.key === n && (t = {
1903
+ left: i.left + i.width - 220,
1904
+ top: i.top + i.height + 4
1905
+ });
1906
+ }
1907
+ if (this.menu && (this.menu.hidden = !t, t)) {
1908
+ let e = this.menu.offsetHeight || 140;
1909
+ this.menu.style.left = `${Math.max(2, Math.min(t.left, innerWidth - 224))}px`, this.menu.style.top = `${Math.max(2, Math.min(t.top, innerHeight - e - 4))}px`;
1910
+ }
1911
+ }
1912
+ positionFrames(e) {
1913
+ let t = {
1914
+ w: document.documentElement.clientWidth || innerWidth,
1915
+ h: document.documentElement.clientHeight || innerHeight
1916
+ }, n = !1, r = [];
1917
+ for (let i of [...this.frames].reverse()) {
1918
+ i.els.some((e) => !e.isConnected) && (n = !0);
1919
+ let a = [i.main, ...i.els].find((t) => t.isConnected && J(e(t)));
1920
+ if (i.ctl.hidden = !a, !a) continue;
1921
+ let o = e(a), s = {
1922
+ w: i.ctl.offsetWidth || 120,
1923
+ h: i.ctl.offsetHeight || 32
1924
+ }, c = _t({
1925
+ left: o.left - 4,
1926
+ top: o.top - 4,
1927
+ width: o.width + 8,
1928
+ height: o.height + 8
1929
+ }, s, t), l = vt({
1930
+ left: c.left,
1931
+ top: c.top,
1932
+ width: s.w,
1933
+ height: s.h
1934
+ }, r, t);
1935
+ r.push(l), i.ctl.style.left = `${l.left}px`, i.ctl.style.top = `${l.top}px`, i.ctl.dataset.side = c.side;
1936
+ }
1937
+ this.positionNotes(e, r, t), n && !this.redrawId && (this.redrawId = requestAnimationFrame(() => {
1938
+ this.redrawId = 0, this.draw();
1939
+ }));
1940
+ }
1941
+ positionNotes(e, t, n) {
1942
+ let r = (e) => ({
1943
+ left: Number.parseFloat(e.style.left) || 0,
1944
+ top: Number.parseFloat(e.style.top) || 0,
1945
+ width: e.offsetWidth || 24,
1946
+ height: e.offsetHeight || 24
1947
+ }), i = [...t, ...this.drawn.filter((e) => e.box.classList.contains("cpin") && !e.box.hidden).map((e) => r(e.box))], a = this.read().avoid;
1948
+ for (let t of [...this.frames].reverse()) {
1949
+ if (!t.note) continue;
1950
+ let r = t.ctl.hidden ? void 0 : [t.main, ...t.els].find((t) => t.isConnected && J(e(t)));
1951
+ if (t.note.hidden = !r, t.noteCard && (t.noteCard.hidden = !r), !r) continue;
1952
+ let o = e(r), s = jt({
1953
+ left: o.left - 4,
1954
+ top: o.top - 4,
1955
+ width: o.width + 8,
1956
+ height: o.height + 8
1957
+ }, i, n);
1958
+ if (i.push(s), t.note.style.left = `${s.left}px`, t.note.style.top = `${s.top}px`, t.noteCard) {
1959
+ let e = Mt(s, {
1960
+ w: t.noteCard.offsetWidth || 260,
1961
+ h: t.noteCard.offsetHeight || 120
1962
+ }, n, a ? {
1963
+ left: a.left,
1964
+ top: a.top,
1965
+ width: a.width,
1966
+ height: a.height
1967
+ } : null);
1968
+ t.noteCard.style.left = `${e.left}px`, t.noteCard.style.top = `${e.top}px`;
1969
+ }
1970
+ }
1971
+ }
1972
+ schedule() {
1973
+ this.frameId ||= requestAnimationFrame(() => {
1974
+ this.frameId = 0, this.position();
1975
+ });
1976
+ }
1977
+ menuTargets() {
1978
+ let e = this.read().altMenu;
1979
+ return e ? this.altGroups.find((t) => t.key === e)?.els ?? [] : [];
1980
+ }
1981
+ busy() {
1982
+ return this.drawn.length > 0 || this.temp.length > 0;
1983
+ }
1984
+ flash(e) {
1985
+ let t = P(), n = q(e, this.host).filter((e) => J(e.getBoundingClientRect()) || !zt()), r = this.frames.flatMap((e) => e.els), i = /* @__PURE__ */ new Set(), a = n.filter((e) => {
1986
+ let t = r.find((t) => t === e || t.contains(e) || e.contains(t));
1987
+ return t && i.add(t), !t;
1988
+ });
1989
+ for (let e of i) this.addTemp({
1990
+ el: e,
1991
+ box: j("div", {
1992
+ class: "box framepulse",
1993
+ "data-pulse": ""
1994
+ }),
1995
+ pad: 4
1996
+ }, t ? W.stillFlash : W.flash);
1997
+ return a.forEach((e, n) => {
1998
+ let r = j("div", {
1999
+ class: "box flash",
2000
+ "data-flash": ""
2001
+ }, n === 0 ? j("span", { class: "updated" }, "updated") : null);
2002
+ this.addTemp({
2003
+ el: e,
2004
+ box: r,
2005
+ pad: 6
2006
+ }, t ? W.stillFlash : W.flash);
2007
+ }), this.position(), a.length + i.size;
2008
+ }
2009
+ swap(e) {
2010
+ if (!P()) {
2011
+ for (let t of e.slice(0, 30)) this.addTemp({
2012
+ el: t,
2013
+ box: j("div", { class: "box swap" }),
2014
+ pad: 4
2015
+ }, W.swap);
2016
+ this.position();
2017
+ }
2018
+ }
2019
+ addTemp(e, t) {
2020
+ this.root.append(e.box), this.temp.push(e), setTimeout(() => {
2021
+ e.box.remove(), this.temp = this.temp.filter((t) => t !== e);
2022
+ }, t + 40);
2023
+ }
2024
+ };
2025
+ function zt() {
2026
+ let e = document.documentElement.getBoundingClientRect();
2027
+ return e.width > 0 || e.height > 0;
2028
+ }
2029
+ // src/menu.ts
2030
+ var Bt = [
2031
+ "claude-haiku-4-5",
2032
+ "claude-sonnet-5-5",
2033
+ "claude-opus-5-5"
2034
+ ], Vt = {
2035
+ skills: "Skills",
2036
+ presets: "Presets",
2037
+ settings: "Settings"
2038
+ }, Ht = {
2039
+ "top-left": "Top left",
2040
+ "top-center": "Top middle",
2041
+ "top-right": "Top right",
2042
+ "bottom-left": "Bottom left",
2043
+ "bottom-center": "Bottom middle",
2044
+ "bottom-right": "Bottom right"
2045
+ }, Ut = class {
2046
+ o;
2047
+ el;
2048
+ open = !1;
2049
+ view = "root";
2050
+ info = null;
2051
+ skills = null;
2052
+ presets = null;
2053
+ failed = /* @__PURE__ */ new Set();
2054
+ draft = null;
2055
+ confirmDelete = "";
2056
+ confirmTimer = 0;
2057
+ constructor(e) {
2058
+ this.o = e, this.el = j("div", {
2059
+ class: "smenu",
2060
+ hidden: !0,
2061
+ "data-menu": ""
2062
+ });
2063
+ }
2064
+ show() {
2065
+ this.o.open && this.o.setOpen(!1), this.o.setTip(!1), this.open = !0, this.view = "root", this.draft = null, this.confirmDelete = "", this.el.hidden = !1, this.el.classList.add("opening"), this.draw(), this.o.place(), this.focusFirst(), this.load();
2066
+ }
2067
+ close(e = !1) {
2068
+ this.open && (this.open = !1, this.draft = null, this.el.hidden = !0, this.el.replaceChildren(), clearTimeout(this.confirmTimer), e && this.o.focusDock());
2069
+ }
2070
+ toggle() {
2071
+ this.open ? this.close(!0) : this.show();
2072
+ }
2073
+ async load() {
2074
+ let e = this.o.client, [t, n, r] = await Promise.allSettled([
2075
+ e.call("GET info", {}),
2076
+ e.call("GET skills", {}),
2077
+ e.call("GET presets", {})
2078
+ ]);
2079
+ this.failed.clear(), t.status === "fulfilled" ? this.info = t.value : this.failed.add("info"), n.status === "fulfilled" ? this.skills = n.value.skills : this.failed.add("skills"), r.status === "fulfilled" ? this.presets = r.value.presets : this.failed.add("presets"), this.open && this.draw();
2080
+ }
2081
+ go(e) {
2082
+ let t = this.view;
2083
+ this.view = e, this.draft = null, this.confirmDelete = "", this.draw(), e === "root" && t !== "root" ? this.focus(`[data-mkey="item:${t}"]`) : this.focusFirst();
2084
+ }
2085
+ draw() {
2086
+ if (!this.open) return;
2087
+ this.readDraft();
2088
+ let e = this.o.shadow.activeElement, t = e && this.el.contains(e) ? e.getAttribute("data-mkey") : null, n = this.el.querySelector(".sbody")?.scrollTop ?? 0, r = this.el.dataset.view === this.view;
2089
+ if (this.el.dataset.view = this.view, this.el.setAttribute("role", this.view === "root" ? "menu" : "dialog"), this.el.setAttribute("aria-label", this.view === "root" ? "Onsite menu" : Vt[this.view]), this.el.replaceChildren(...this.view === "root" ? this.root() : this.section(this.view)), r) {
2090
+ let e = this.el.querySelector(".sbody");
2091
+ e && (e.scrollTop = n);
2092
+ }
2093
+ t && this.focus(`[data-mkey="${CSS.escape(t)}"]`), setTimeout(() => this.el.classList.remove("opening"), 200);
2094
+ }
2095
+ root() {
2096
+ let e = this.skills?.filter((e) => e.enabled).length, t = this.presets?.length, n = (e, t, n, r) => j("button", {
2097
+ class: "mitem",
2098
+ type: "button",
2099
+ role: "menuitem",
2100
+ "aria-haspopup": r.sub ? "dialog" : null,
2101
+ "data-mnav": "",
2102
+ "data-mkey": `item:${e}`,
2103
+ ...r.sub ? { "data-sub": e } : {},
2104
+ on: { click: r.click }
2105
+ }, M(t), j("span", { class: "grow" }, n), r.hint ? j("span", { class: "mhint" }, r.hint) : null, r.sub ? M(R.next) : null), r = this.o.hidden, i = this.o.everywhere();
2106
+ return [j("div", {
2107
+ class: "mbrand",
2108
+ "aria-hidden": "true"
2109
+ }, M(I(14, 3.2)), j("span", null, "onsite"), this.info ? j("span", { class: "mhint" }, `v${this.info.version}`) : null), j("div", { class: "mlist" }, n("changes", R.alt, "Changes", { click: () => this.openTab("changes") }), n("export", R.export, "Export", { click: () => this.openTab("export") }), i ? n("original", i === "original" ? R.original : R.undo, i === "original" ? "Show the original everywhere" : "Show the takes again", {
2110
+ hint: this.everywhereHint(i),
2111
+ click: () => void this.toggleEverywhere()
2112
+ }) : null, j("div", {
2113
+ class: "msep",
2114
+ role: "separator"
2115
+ }), n("skills", R.skills, "Skills", {
2116
+ sub: !0,
2117
+ hint: e === void 0 ? "" : `${e} on`,
2118
+ click: () => this.go("skills")
2119
+ }), n("presets", R.preset, "Presets", {
2120
+ sub: !0,
2121
+ hint: t === void 0 ? "" : String(t),
2122
+ click: () => this.go("presets")
2123
+ }), n("settings", R.settings, "Settings", {
2124
+ sub: !0,
2125
+ click: () => this.go("settings")
2126
+ }), j("div", {
2127
+ class: "msep",
2128
+ role: "separator"
2129
+ }), n("hide", r ? R.show : R.hide, r ? "Show icon" : "Hide icon", {
2130
+ hint: r ? "" : `2× ${F()} opens`,
2131
+ click: () => {
2132
+ this.close(), this.o.setHidden(!r);
2133
+ }
2134
+ }))];
2135
+ }
2136
+ everywhereHint(e) {
2137
+ let t = this.o, n = e === "original" ? z(t.thread) : t.beforeOriginal?.showing ?? [];
2138
+ return r(new Set(n.map((e) => t.thread.takes.find((t) => t.id === e)?.of ?? e)).size, "ask");
2139
+ }
2140
+ async toggleEverywhere() {
2141
+ await this.o.toggleEverywhere(), this.draw();
2142
+ }
2143
+ openTab(e) {
2144
+ this.close(), this.o.setOpen(!0), this.o.setTab(e);
2145
+ }
2146
+ section(e) {
2147
+ let t = j("div", { class: "mhead" }, j("button", {
2148
+ class: "btn ghost icon",
2149
+ type: "button",
2150
+ "aria-label": "Back to the menu",
2151
+ "data-mnav": "",
2152
+ "data-mkey": "back",
2153
+ on: { click: () => this.go("root") }
2154
+ }, M(R.back)), j("h2", null, Vt[e])), n = j("div", { class: "sbody scroll" });
2155
+ return e === "skills" ? n.append(...this.skillsView()) : e === "presets" ? n.append(...this.presetsView()) : n.append(...this.settingsView()), [t, n];
2156
+ }
2157
+ skillsView() {
2158
+ if (!this.skills) return [this.waiting("skills")];
2159
+ let e = j("p", { class: "mnote" }, "The agent sees the name and description of each skill that is on, and reads it when your ask matches. Onsite never runs a skill's scripts.");
2160
+ if (this.skills.length === 0) return [e, j("p", { class: "mnote" }, "No skills found. Add a folder with a SKILL.md to .claude/skills/ in your project, or to ~/.claude/skills/.")];
2161
+ let t = (e, t, n) => {
2162
+ let r = this.skills.filter((t) => t.source === e);
2163
+ return r.length ? j("section", { class: "mgroup" }, j("h3", null, t, j("span", { class: "mhint" }, n)), r.map((e) => this.skillRow(e))) : null;
2164
+ };
2165
+ return [e, ...[t("project", "This project", ".claude/skills"), t("user", "Your own", "~/.claude/skills · off by default")].filter((e) => e !== null)];
2166
+ }
2167
+ skillRow(e) {
2168
+ let t = `os-skill-${e.id.replace(/[^A-Za-z0-9_-]/g, "-")}`;
2169
+ return j("div", { class: "mrow" }, j("div", { class: "grow" }, j("div", {
2170
+ class: "mname mono",
2171
+ id: t
2172
+ }, e.name), j("div", {
2173
+ class: "mdesc",
2174
+ title: e.path
2175
+ }, e.description)), j("button", {
2176
+ class: "switch",
2177
+ type: "button",
2178
+ role: "switch",
2179
+ "aria-checked": String(e.enabled),
2180
+ "aria-labelledby": t,
2181
+ "data-mnav": "",
2182
+ "data-mkey": `skill:${e.id}`,
2183
+ on: { click: () => void this.toggleSkill(e) }
2184
+ }, j("span", {
2185
+ class: "knob",
2186
+ "aria-hidden": "true"
2187
+ })));
2188
+ }
2189
+ async toggleSkill(e) {
2190
+ let t = !e.enabled;
2191
+ e.enabled = t, this.draw();
2192
+ try {
2193
+ await this.o.savePrefs({ skills: { [e.id]: t } });
2194
+ } catch (n) {
2195
+ e.enabled = !t, this.draw(), this.o.showToast(`Could not change the skill: ${n.message}`);
2196
+ }
2197
+ }
2198
+ presetsView() {
2199
+ if (!this.presets) return [this.waiting("presets")];
2200
+ if (this.draft) return [this.presetForm(this.draft)];
2201
+ let e = this.o.pins.length, t = j("p", { class: "mnote" }, e ? `A preset runs as an ask on the ${r(e, "selected element")}.` : `A preset runs as an ask. Select elements first (${F()}-click) to aim it.`), n = this.presets.filter((e) => e.source === "builtin"), i = this.presets.filter((e) => e.source === "project");
2202
+ return [
2203
+ t,
2204
+ j("section", { class: "mgroup" }, j("h3", null, "Onsite"), n.map((e) => this.presetRow(e))),
2205
+ j("section", { class: "mgroup" }, j("h3", null, "This project", j("span", { class: "mhint" }, ".onsite/presets.json")), i.length ? i.map((e) => this.presetRow(e)) : j("p", { class: "mnote" }, "None yet."), j("button", {
2206
+ class: "btn",
2207
+ type: "button",
2208
+ "data-mnav": "",
2209
+ "data-mkey": "preset:new",
2210
+ on: { click: () => this.edit({
2211
+ name: "",
2212
+ message: ""
2213
+ }) }
2214
+ }, M(R.plus), "New preset"))
2215
+ ];
2216
+ }
2217
+ presetRow(e) {
2218
+ let t = e.count ?? this.o.takes, n = j("button", {
2219
+ class: "mrun",
2220
+ type: "button",
2221
+ title: e.message,
2222
+ "data-mnav": "",
2223
+ "data-mkey": `preset:${e.id}`,
2224
+ on: { click: () => void this.runPreset(e) }
2225
+ }, j("span", { class: "mname" }, e.name, j("span", { class: "mhint" }, r(t, "take"))), j("span", { class: "mdesc" }, e.message));
2226
+ if (e.source !== "project") return j("div", { class: "mrow" }, n);
2227
+ let i = this.confirmDelete === e.id;
2228
+ return j("div", { class: "mrow" }, n, j("button", {
2229
+ class: "btn ghost icon",
2230
+ type: "button",
2231
+ "aria-label": `Edit ${e.name}`,
2232
+ title: "Edit",
2233
+ "data-mkey": `edit:${e.id}`,
2234
+ on: { click: () => this.edit({
2235
+ id: e.id,
2236
+ name: e.name,
2237
+ message: e.message,
2238
+ ...e.count ? { count: e.count } : {}
2239
+ }) }
2240
+ }, M(R.edit)), j("button", {
2241
+ class: `btn ghost${i ? " danger" : " icon"}`,
2242
+ type: "button",
2243
+ "aria-label": i ? `Delete ${e.name}: press again to delete` : `Delete ${e.name}`,
2244
+ title: i ? "Press again to delete" : "Delete",
2245
+ "data-mkey": `delete:${e.id}`,
2246
+ on: { click: () => void this.deletePreset(e) }
2247
+ }, i ? "Delete?" : M(R.trash)));
2248
+ }
2249
+ presetForm(e) {
2250
+ let t = (t, n) => j("button", {
2251
+ type: "button",
2252
+ "aria-pressed": String(e.count === t),
2253
+ "data-mkey": `count:${t ?? "default"}`,
2254
+ on: { click: () => {
2255
+ e.count = t, this.draw();
2256
+ } }
2257
+ }, n);
2258
+ return j("form", {
2259
+ class: "mform",
2260
+ "aria-label": e.id ? "Edit the preset" : "New preset",
2261
+ on: { submit: (e) => {
2262
+ e.preventDefault(), this.savePreset();
2263
+ } }
2264
+ }, j("label", null, j("span", null, "Name"), j("input", {
2265
+ type: "text",
2266
+ name: "name",
2267
+ maxlength: 60,
2268
+ required: !0,
2269
+ value: e.name,
2270
+ "data-mkey": "f:name"
2271
+ })), j("label", null, j("span", null, "Ask"), j("textarea", {
2272
+ name: "message",
2273
+ rows: 4,
2274
+ maxlength: 4e3,
2275
+ required: !0,
2276
+ "data-mkey": "f:message"
2277
+ }, e.message)), j("div", { class: "mfield" }, j("span", null, "Takes"), j("div", {
2278
+ class: "seg small",
2279
+ role: "group",
2280
+ "aria-label": "Takes"
2281
+ }, t(void 0, `Default (${this.o.takes})`), Array.from({ length: 3 }, (e, n) => t(n + 1, String(n + 1))))), j("div", { class: "buttons" }, j("span", { class: "grow" }), j("button", {
2282
+ class: "btn ghost",
2283
+ type: "button",
2284
+ "data-mkey": "f:cancel",
2285
+ on: { click: () => this.edit(null) }
2286
+ }, "Cancel"), j("button", {
2287
+ class: "btn primary",
2288
+ type: "submit",
2289
+ "data-mkey": "f:save"
2290
+ }, e.id ? "Save" : "Add preset")));
2291
+ }
2292
+ readDraft() {
2293
+ let e = this.el.querySelector(".mform");
2294
+ e && this.draft && (this.draft.name = e.elements.namedItem("name")?.value ?? this.draft.name, this.draft.message = e.elements.namedItem("message")?.value ?? this.draft.message);
2295
+ }
2296
+ edit(e) {
2297
+ this.el.querySelector(".mform")?.remove(), this.draft = e, this.confirmDelete = "", this.draw(), e ? this.focus("[data-mkey=\"f:name\"]") : this.focusFirst();
2298
+ }
2299
+ async savePreset() {
2300
+ this.readDraft();
2301
+ let e = this.draft;
2302
+ if (e) try {
2303
+ let t = await this.o.client.call("POST preset", {
2304
+ ...e.id ? { id: e.id } : {},
2305
+ name: e.name,
2306
+ message: e.message,
2307
+ ...e.count ? { count: e.count } : {}
2308
+ }), n = this.presets ?? [], r = n.findIndex((e) => e.id === t.id);
2309
+ this.presets = r >= 0 ? n.map((e) => e.id === t.id ? t : e) : [...n, t], this.draft = null, this.draw(), this.focus(`[data-mkey="preset:${CSS.escape(t.id)}"]`);
2310
+ } catch (e) {
2311
+ this.o.showToast(e.message);
2312
+ }
2313
+ }
2314
+ async deletePreset(e) {
2315
+ if (this.confirmDelete !== e.id) this.confirmDelete = e.id, this.draw(), clearTimeout(this.confirmTimer), this.confirmTimer = window.setTimeout(() => {
2316
+ this.confirmDelete === e.id && (this.confirmDelete = "", this.draw());
2317
+ }, 4e3);
2318
+ else {
2319
+ this.confirmDelete = "";
2320
+ try {
2321
+ await this.o.client.call("POST delete-preset", { id: e.id }), this.presets = (this.presets ?? []).filter((t) => t.id !== e.id), this.draw(), this.focus("[data-mkey=\"preset:new\"]"), this.o.showToast(`Deleted the preset ${e.name}`);
2322
+ } catch (e) {
2323
+ this.draw(), this.o.showToast(e.message);
2324
+ }
2325
+ }
2326
+ }
2327
+ async runPreset(e) {
2328
+ this.o.thread.running ? this.o.showToast("A change is running. Wait for it, or stop it.") : (this.close(), this.o.setOpen(!0), await this.o.ask(e.message, e.count ?? this.o.takes));
2329
+ }
2330
+ settingsView() {
2331
+ let e = this.o, t = this.info, n = j("select", {
2332
+ id: "os-model",
2333
+ "data-mkey": "set:model",
2334
+ on: { change: (e) => void this.setModel(e.target.value) }
2335
+ }, j("option", { value: "" }, t?.pluginModel ? `Plugin default · ${t.pluginModel}` : "Plugin default"), Bt.map((e) => j("option", { value: e }, e)));
2336
+ e.model && !Bt.includes(e.model) && n.append(j("option", { value: e.model }, e.model)), n.value = e.model ?? "";
2337
+ let r = (e, t, n, r) => j("div", {
2338
+ class: "seg small",
2339
+ role: "group",
2340
+ "aria-label": e
2341
+ }, n.map(([n, i]) => j("button", {
2342
+ type: "button",
2343
+ "aria-pressed": String(t === n),
2344
+ "data-mkey": `set:${e}:${n}`,
2345
+ on: { click: () => r(n) }
2346
+ }, i))), i = (e, t, n, r) => j("div", { class: "mset" }, r ? j("label", { for: r }, e) : j("span", null, e), t, n ? j("p", { class: "mhint" }, n) : null), a = j("div", {
2347
+ class: "anchors",
2348
+ role: "group",
2349
+ "aria-label": "Dock position"
2350
+ }, We.map((t) => j("button", {
2351
+ type: "button",
2352
+ "aria-pressed": String(e.saved === t),
2353
+ "aria-label": Ht[t],
2354
+ title: Ht[t],
2355
+ "data-mkey": `set:dock:${t}`,
2356
+ on: { click: () => {
2357
+ e.moveDock(t), this.draw();
2358
+ } }
2359
+ }, j("span", {
2360
+ class: "dot",
2361
+ "aria-hidden": "true"
2362
+ })))), o = t ? `Next runs use ${t.model || "the Agent SDK's default"}.` : null;
2363
+ return [
2364
+ i("Model", n, this.failed.has("info") ? "Could not read the current model." : o, "os-model"),
2365
+ i("Default takes", r("Default takes", e.takes, [
2366
+ 1,
2367
+ 2,
2368
+ 3
2369
+ ].map((e) => [e, String(e)]), (e) => void this.setTakes(e)), "How many takes the composer asks for, until you change it."),
2370
+ i("Scheme", r("Scheme", e.pref, [
2371
+ ["auto", "Auto"],
2372
+ ["light", "Light"],
2373
+ ["dark", "Dark"]
2374
+ ], (t) => {
2375
+ e.setScheme(t), this.draw();
2376
+ }), "Auto follows the page under the icon."),
2377
+ i("Dock position", a, "Or drag the icon, or press Shift and an arrow key."),
2378
+ j("dl", { class: "minfo" }, j("dt", null, "Version"), j("dd", { class: "mono" }, t?.version ?? "…"), j("dt", null, "Source folders"), j("dd", { class: "mono" }, t ? t.src.join(", ") : "…"))
2379
+ ];
2380
+ }
2381
+ async setModel(e) {
2382
+ try {
2383
+ await this.o.savePrefs({ model: e || null }), this.info = await this.o.client.call("GET info", {});
2384
+ } catch (e) {
2385
+ this.o.showToast(`Could not change the model: ${e.message}`);
2386
+ }
2387
+ this.draw();
2388
+ }
2389
+ async setTakes(e) {
2390
+ try {
2391
+ await this.o.savePrefs({ takes: e }), this.o.setCount(e);
2392
+ } catch (e) {
2393
+ this.o.showToast(`Could not change the default takes: ${e.message}`);
2394
+ }
2395
+ this.draw();
2396
+ }
2397
+ waiting(e) {
2398
+ return j("p", { class: "mnote" }, this.failed.has(e) ? `Could not read the ${e}. Close the menu and open it again.` : "Reading…");
2399
+ }
2400
+ focus(e) {
2401
+ this.el.querySelector(e)?.focus({ preventScroll: !0 });
2402
+ }
2403
+ focusFirst() {
2404
+ this.el.querySelector("[data-mnav]")?.focus({ preventScroll: !0 });
2405
+ }
2406
+ key(e) {
2407
+ if (!this.open) return !1;
2408
+ let t = e.composedPath()[0], n = t instanceof Element && lt(t);
2409
+ if (e.key === "Escape") return this.draft ? this.edit(null) : this.view === "root" ? this.close(!0) : this.go("root"), !0;
2410
+ if (n || !(t instanceof Node && this.el.contains(t))) return !1;
2411
+ let r = [...this.el.querySelectorAll("[data-mnav]")], i = r.indexOf(t), a = (e) => r[(e + r.length) % r.length]?.focus({ preventScroll: !0 });
2412
+ if (e.key === "ArrowDown") a(i + 1);
2413
+ else if (e.key === "ArrowUp") a(i < 0 ? r.length - 1 : i - 1);
2414
+ else if (e.key === "Home") a(0);
2415
+ else if (e.key === "End") a(r.length - 1);
2416
+ else if (e.key === "ArrowRight" && t instanceof HTMLElement && t.dataset.sub) this.go(t.dataset.sub);
2417
+ else if (e.key === "ArrowLeft" && this.view !== "root") this.go("root");
2418
+ else return !1;
2419
+ return !0;
2420
+ }
2421
+ }, Wt = (e) => e.w >= 384 ? 12 : 8, Gt = (e) => Math.max(200, Math.min(360, e.w - Wt(e) * 2));
2422
+ function Kt(e, t, n, r = {
2423
+ edge: 8,
2424
+ y: 8,
2425
+ x: 8,
2426
+ left: e.left
2427
+ }) {
2428
+ let { edge: i, y: a, x: o } = r, s = Math.max(i, Math.min(r.left, n.w - t.w - i)), c = e.top + e.height + a;
2429
+ if (c + t.h <= n.h - i) return {
2430
+ left: s,
2431
+ top: c,
2432
+ side: "below"
2433
+ };
2434
+ let l = e.top - a - t.h;
2435
+ if (l >= i) return {
2436
+ left: s,
2437
+ top: l,
2438
+ side: "above"
2439
+ };
2440
+ let u = Math.max(i, Math.min(e.top, n.h - t.h - i)), d = e.left + e.width + o;
2441
+ if (d + t.w <= n.w - i) return {
2442
+ left: d,
2443
+ top: u,
2444
+ side: "right"
2445
+ };
2446
+ let f = e.left - o - t.w;
2447
+ return f >= i ? {
2448
+ left: f,
2449
+ top: u,
2450
+ side: "left"
2451
+ } : {
2452
+ left: s,
2453
+ top: Math.max(i, Math.min(e.top + e.height - o - t.h, n.h - t.h - i)),
2454
+ side: "inside"
2455
+ };
2456
+ }
2457
+ function qt(e, t, n) {
2458
+ let r = t.tab, i = Kt(e, t, n, {
2459
+ edge: Wt(n),
2460
+ y: r ? 0 : 6,
2461
+ x: 6,
2462
+ left: r ? e.left - 30 : e.left
2463
+ });
2464
+ if (!r) return {
2465
+ ...i,
2466
+ tabX: 0
2467
+ };
2468
+ let a = i.side === "below" || i.side === "above" ? Math.max(30, Math.min(e.left - i.left, t.w - r.w - 30)) : 30;
2469
+ return {
2470
+ ...i,
2471
+ tabX: a
2472
+ };
2473
+ }
2474
+ var Jt = ["data-fkey", "data-mkey"];
2475
+ function Yt(e, t, n, r) {
2476
+ let i = (e) => Math.max(8, Math.min(e, r.w - n.w - 8)), a = (e) => Math.max(8, Math.min(e, r.h - n.h - 8));
2477
+ return t ? {
2478
+ left: i(t.left + (t.width - n.w) / 2),
2479
+ top: a(t.top + (t.height - n.h) / 2),
2480
+ side: "center"
2481
+ } : e ? Kt(e, n, r) : {
2482
+ left: i((r.w - n.w) / 2),
2483
+ top: a((r.h - n.h) / 2),
2484
+ side: "center"
2485
+ };
2486
+ }
2487
+ var Xt = class {
2488
+ shadow;
2489
+ viewport;
2490
+ el;
2491
+ last = null;
2492
+ open = null;
2493
+ back = null;
2494
+ constructor(e, t) {
2495
+ this.shadow = e, this.viewport = t, this.el = j("div", { "data-questionbox": "" });
2496
+ let n = (e) => {
2497
+ let t = e.composedPath()[0];
2498
+ t instanceof Element && !this.el.contains(t) && (this.last = t.closest("button, [tabindex], a, input") ?? t);
2499
+ };
2500
+ e.addEventListener("pointerdown", n, !0), e.addEventListener("keydown", n, !0);
2501
+ }
2502
+ get asking() {
2503
+ return this.open !== null;
2504
+ }
2505
+ ask(e) {
2506
+ this.close(!1);
2507
+ let t = this.control(), n = Zt(t);
2508
+ return new Promise((r) => {
2509
+ let i = "os-question-text", a = j("button", {
2510
+ class: "btn ghost",
2511
+ type: "button",
2512
+ "data-question-no": "",
2513
+ on: { click: () => this.close(!1) }
2514
+ }, "Cancel"), o = j("button", {
2515
+ class: "btn primary",
2516
+ type: "button",
2517
+ "data-question-yes": "",
2518
+ on: { click: () => this.close(!0) }
2519
+ }, e.yes), s = j("div", {
2520
+ class: "question",
2521
+ role: "alertdialog",
2522
+ "aria-modal": "false",
2523
+ "aria-label": e.label,
2524
+ "aria-describedby": i,
2525
+ "data-question": ""
2526
+ }, j("p", {
2527
+ class: "text",
2528
+ id: i
2529
+ }, e.text), j("div", { class: "buttons" }, j("span", { class: "grow" }), a, o));
2530
+ this.open = {
2531
+ card: s,
2532
+ yes: o,
2533
+ no: a,
2534
+ answer: r,
2535
+ from: t,
2536
+ key: n,
2537
+ at: {
2538
+ control: null,
2539
+ panel: null
2540
+ }
2541
+ }, this.el.replaceChildren(s), this.place(), addEventListener("pointerdown", this.onOutside, !0), o.focus({ preventScroll: !0 });
2542
+ });
2543
+ }
2544
+ close(e) {
2545
+ let t = this.open;
2546
+ t && (this.open = null, removeEventListener("pointerdown", this.onOutside, !0), this.el.replaceChildren(), this.back = {
2547
+ from: t.from,
2548
+ key: t.key
2549
+ }, this.refocus(), t.answer(e));
2550
+ }
2551
+ refocus() {
2552
+ let e = this.back;
2553
+ if (!e) return;
2554
+ let t = e.from?.isConnected ? e.from : null;
2555
+ !t && e.key && (t = [...this.shadow.querySelectorAll(`[${e.key.attr}]`)].find((t) => t.getAttribute(e.key.attr) === e.key.value) ?? null), t instanceof HTMLElement && t.focus({ preventScroll: !0 });
2556
+ }
2557
+ key(e) {
2558
+ let t = this.open;
2559
+ if (!t) return !1;
2560
+ let n = e.composedPath()[0];
2561
+ return e.key === "Escape" ? (this.close(!1), !0) : e.key === "Enter" ? (e.repeat || (n === t.yes ? this.close(!0) : n === t.no && this.close(!1)), !0) : e.key === "Tab" && ((n === t.yes ? t.no : t.yes).focus({ preventScroll: !0 }), !0);
2562
+ }
2563
+ place() {
2564
+ let e = this.open;
2565
+ if (!e) return;
2566
+ let t = this.viewport(), n = Math.max(200, Math.min(300, t.w - 16));
2567
+ if (e.card.style.width = `${n}px`, e.from?.isConnected) {
2568
+ let t = e.from.closest(".panel"), n = e.from.getBoundingClientRect();
2569
+ e.at = {
2570
+ control: n.width > 0 || n.height > 0 ? Qt(n, 4) : null,
2571
+ panel: t ? Qt(t.getBoundingClientRect()) : null
2572
+ };
2573
+ }
2574
+ let r = Yt(e.at.control, e.at.panel, {
2575
+ w: n,
2576
+ h: e.card.offsetHeight || 110
2577
+ }, t);
2578
+ e.card.style.left = `${r.left}px`, e.card.style.top = `${r.top}px`, e.card.dataset.side = r.side;
2579
+ }
2580
+ control() {
2581
+ return this.last?.isConnected ? this.last : this.shadow.activeElement;
2582
+ }
2583
+ onOutside = (e) => {
2584
+ this.open && !e.composedPath().includes(this.open.card) && this.close(!1);
2585
+ };
2586
+ };
2587
+ function Zt(e) {
2588
+ for (let t of Jt) {
2589
+ let n = e?.getAttribute(t);
2590
+ if (n) return {
2591
+ attr: t,
2592
+ value: n
2593
+ };
2594
+ }
2595
+ return null;
2596
+ }
2597
+ var Qt = (e, t = 0) => ({
2598
+ left: e.left - t,
2599
+ top: e.top - t,
2600
+ width: e.width + t * 2,
2601
+ height: e.height + t * 2
2602
+ }), Y = (e, t) => e.endsWith("%") ? Number.parseFloat(e) / 100 * t : Number.parseFloat(e);
2603
+ function $t(e) {
2604
+ let t = e.trim().toLowerCase();
2605
+ if (t === "" || t === "transparent" || t === "none") return {
2606
+ r: 0,
2607
+ g: 0,
2608
+ b: 0,
2609
+ a: 0
2610
+ };
2611
+ if (t.startsWith("#")) {
2612
+ let e = t.slice(1), n = e.length === 3 || e.length === 4 ? [...e].map((e) => e + e).join("") : e.length === 6 || e.length === 8 ? e : "";
2613
+ if (!n || /[^0-9a-f]/.test(n)) return null;
2614
+ let r = (e) => Number.parseInt(n.slice(e, e + 2), 16);
2615
+ return {
2616
+ r: r(0),
2617
+ g: r(2),
2618
+ b: r(4),
2619
+ a: n.length === 8 ? r(6) / 255 : 1
2620
+ };
2621
+ }
2622
+ let n = /^([a-z]+)\((.*)\)$/.exec(t);
2623
+ if (!n) return null;
2624
+ let [, r = "", i = ""] = n, [a = "", o] = i.split("/"), s = a.replace(/,/g, " ").trim().split(/\s+/), c = 1;
2625
+ if (o === void 0 ? (r === "rgba" || r === "rgb") && s.length === 4 && (c = Y(s[3] ?? "1", 1)) : c = Y(o.trim(), 1), Number.isNaN(c) && (c = 1), r === "rgb" || r === "rgba") {
2626
+ let [e, t, n] = s.slice(0, 3).map((e) => Y(e, 255));
2627
+ return e === void 0 || t === void 0 || n === void 0 || [
2628
+ e,
2629
+ t,
2630
+ n
2631
+ ].some(Number.isNaN) ? null : {
2632
+ r: e,
2633
+ g: t,
2634
+ b: n,
2635
+ a: c
2636
+ };
2637
+ }
2638
+ if (r === "color" && s[0] === "srgb") {
2639
+ let [e, t, n] = s.slice(1, 4).map((e) => Y(e, 1) * 255);
2640
+ return e === void 0 || t === void 0 || n === void 0 || [
2641
+ e,
2642
+ t,
2643
+ n
2644
+ ].some(Number.isNaN) ? null : {
2645
+ r: e,
2646
+ g: t,
2647
+ b: n,
2648
+ a: c
2649
+ };
2650
+ }
2651
+ let l = NaN;
2652
+ if ((r === "oklch" || r === "oklab") && (l = Y(s[0] ?? "", 1)), (r === "lab" || r === "lch") && (l = Y(s[0] ?? "", 100) / 100), Number.isNaN(l)) return null;
2653
+ let u = Math.round(Math.max(0, Math.min(1, r.startsWith("ok") ? l ** 3 : en(l))) ** (1 / 2.2) * 255);
2654
+ return {
2655
+ r: u,
2656
+ g: u,
2657
+ b: u,
2658
+ a: c
2659
+ };
2660
+ }
2661
+ function en(e) {
2662
+ let t = e * 100;
2663
+ return t > 8 ? ((t + 16) / 116) ** 3 : t / 903.3;
2664
+ }
2665
+ function tn(e) {
2666
+ let t = (e) => {
2667
+ let t = e / 255;
2668
+ return t <= .04045 ? t / 12.92 : ((t + .055) / 1.055) ** 2.4;
2669
+ };
2670
+ return .2126 * t(e.r) + .7152 * t(e.g) + .0722 * t(e.b);
2671
+ }
2672
+ function nn() {
2673
+ try {
2674
+ return matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2675
+ } catch {
2676
+ return "light";
2677
+ }
2678
+ }
2679
+ function rn(e) {
2680
+ let { x: t, y: n } = e.point(), r = typeof e.doc.elementsFromPoint == "function" ? e.doc.elementsFromPoint(t, n) : [];
2681
+ for (let t of r) if (t !== e.host && !e.host?.contains(t)) return t;
2682
+ return e.doc.body ?? e.doc.documentElement;
2683
+ }
2684
+ function an(e) {
2685
+ let t = e.doc.defaultView ?? window, n = e.doc.documentElement, r = e.doc.body, i = (e) => {
2686
+ if (!e) return null;
2687
+ let n = $t(t.getComputedStyle(e).backgroundColor);
2688
+ return n && n.a >= .99 ? n : null;
2689
+ }, a = (e) => tn(e) < .4 ? "dark" : "light";
2690
+ for (let t = rn(e); t && t !== n; t = t.parentElement) {
2691
+ let e = i(t);
2692
+ if (e) return a(e);
2693
+ }
2694
+ let o = i(n) ?? i(r);
2695
+ return o ? a(o) : nn();
2696
+ }
2697
+ function on(e, t) {
2698
+ let n = e.doc.defaultView ?? window, r = an(e), i = 0, a = () => {
2699
+ i = 0;
2700
+ let n = an(e);
2701
+ n !== r && (r = n, d.scheme = n, t(n));
2702
+ }, o = () => {
2703
+ i ||= n.setTimeout(a, 0), n.setTimeout(a, 300);
2704
+ }, s = new n.MutationObserver(o), c = (e) => e && s.observe(e, {
2705
+ attributes: !0,
2706
+ attributeFilter: [
2707
+ "class",
2708
+ "data-theme",
2709
+ "style"
2710
+ ]
2711
+ });
2712
+ c(e.doc.documentElement), c(e.doc.body);
2713
+ let l = ln(n, o), u = null;
2714
+ try {
2715
+ u = n.matchMedia("(prefers-color-scheme: dark)"), u.addEventListener?.("change", o);
2716
+ } catch {
2717
+ u = null;
2718
+ }
2719
+ let d = {
2720
+ scheme: r,
2721
+ recheck: o,
2722
+ stop() {
2723
+ s.disconnect(), l(), u?.removeEventListener?.("change", o), i && n.clearTimeout(i);
2724
+ }
2725
+ };
2726
+ return d;
2727
+ }
2728
+ var sn = "onsite:route", cn = /* @__PURE__ */ new WeakSet();
2729
+ function ln(e, t) {
2730
+ let n = e.history;
2731
+ if (n && !cn.has(n)) {
2732
+ cn.add(n);
2733
+ for (let t of ["pushState", "replaceState"]) {
2734
+ let r = n[t];
2735
+ n[t] = function(...t) {
2736
+ let n = r.apply(this, t);
2737
+ return e.dispatchEvent(new Event(sn)), n;
2738
+ };
2739
+ }
2740
+ }
2741
+ return e.addEventListener(sn, t), e.addEventListener("popstate", t), () => {
2742
+ e.removeEventListener(sn, t), e.removeEventListener("popstate", t);
2743
+ };
2744
+ }
2745
+ // src/tooltip.ts
2746
+ var un = "os-icontip", X = 8, dn = (e) => e instanceof Element ? e.closest("[data-tip]") : null, fn = class {
2747
+ root;
2748
+ el;
2749
+ at = null;
2750
+ timer = 0;
2751
+ constructor(e) {
2752
+ this.root = e, this.el = j("div", {
2753
+ class: "icontip",
2754
+ id: un,
2755
+ role: "tooltip",
2756
+ hidden: !0,
2757
+ "data-icontip": ""
2758
+ }), e.addEventListener("pointerover", (e) => {
2759
+ let t = dn(e.target);
2760
+ if (!t) return this.hide();
2761
+ t !== this.at && (this.at ? this.show(t) : this.soon(t));
2762
+ }), e.addEventListener("pointerout", (e) => {
2763
+ dn(e.relatedTarget) || this.hide();
2764
+ }), e.addEventListener("focusin", (e) => {
2765
+ let t = dn(e.target);
2766
+ t?.matches(":focus-visible") && this.show(t);
2767
+ }), e.addEventListener("focusout", (e) => {
2768
+ e.target === this.at && this.hide();
2769
+ }), e.addEventListener("pointerdown", () => this.hide());
2770
+ }
2771
+ soon(e) {
2772
+ clearTimeout(this.timer), this.timer = window.setTimeout(() => {
2773
+ let t = this.current(e);
2774
+ t && this.show(t);
2775
+ }, 250);
2776
+ }
2777
+ current(e) {
2778
+ if (e.isConnected) return e;
2779
+ let t = e.dataset.tipKey;
2780
+ return t ? this.root.querySelector(`[data-tip-key="${t}"]`) : null;
2781
+ }
2782
+ show(e) {
2783
+ clearTimeout(this.timer), this.at && this.at !== e && this.at.removeAttribute("aria-describedby"), this.at = e;
2784
+ let t = (e.dataset.tipKeys ?? "").split(" ").filter(Boolean), n = e.dataset.tipMore;
2785
+ this.el.replaceChildren(j("span", { class: "tl" }, e.dataset.tip ?? ""), ...t.map((e) => j("kbd", null, e))), n && this.el.append(j("span", { class: "tm" }, n)), n && e.setAttribute("aria-describedby", un), this.el.hidden = !1, this.place();
2786
+ }
2787
+ place() {
2788
+ let e = this.at;
2789
+ if (!e) return;
2790
+ let t = e.getBoundingClientRect(), n = this.el.offsetWidth, r = this.el.offsetHeight, i = t.top - X - r;
2791
+ i < X && (i = t.bottom + X);
2792
+ let a = Math.max(X, Math.min(t.left + t.width / 2 - n / 2, innerWidth - n - X));
2793
+ this.el.style.left = `${a}px`, this.el.style.top = `${i}px`;
2794
+ }
2795
+ hide() {
2796
+ clearTimeout(this.timer), this.at?.removeAttribute("aria-describedby"), this.at = null, this.el.hidden = !0;
2797
+ }
2798
+ refresh() {
2799
+ let e = this.at;
2800
+ if (!e || e.isConnected) return;
2801
+ let t = this.current(e);
2802
+ t ? this.show(t) : this.hide();
2803
+ }
2804
+ }, pn = /(`[^`\n]+`)/, mn = /(`[^`\n]+`|\*\*(?=\S)(?:`[^`\n]+`|[^`\n])+?(?<=\S)\*\*)/;
2805
+ function hn(e, t, n = !0) {
2806
+ t.split(n ? mn : pn).forEach((t, n) => {
2807
+ if (n % 2 == 0) t && e.append(document.createTextNode(t));
2808
+ else if (t.startsWith("`")) {
2809
+ let n = document.createElement("code");
2810
+ n.textContent = t.slice(1, -1), e.append(n);
2811
+ } else {
2812
+ let n = document.createElement("strong");
2813
+ hn(n, t.slice(2, -2), !1), e.append(n);
2814
+ }
2815
+ });
2816
+ }
2817
+ function gn(e) {
2818
+ let t = document.createDocumentFragment();
2819
+ return e.split(/```[^\n`]*\n?([\s\S]*?)(?:```|$)/).forEach((e, n) => {
2820
+ if (n % 2 == 1) {
2821
+ let n = document.createElement("pre"), r = document.createElement("code");
2822
+ r.textContent = e.replace(/\n$/, ""), n.append(r), t.append(n);
2823
+ } else for (let n of e.split(/\n{2,}/)) {
2824
+ if (!n.trim()) continue;
2825
+ let e = document.createElement("p");
2826
+ hn(e, n.replace(/^\n+|\n+$/g, "")), t.append(e);
2827
+ }
2828
+ }), t;
2829
+ }
2830
+ // src/views.ts
2831
+ function _n(e) {
2832
+ let t = !!e.thread.running, n = e.openTakes().length, i = e.thread.queue?.length ?? 0, a = t ? ` · working${i ? `, ${i} waiting` : ""}` : n ? ` · ${r(n, "take")} to keep or skip` : "";
2833
+ return [j("button", {
2834
+ class: "dock",
2835
+ type: "button",
2836
+ "aria-label": e.open ? "Close Onsite · drag to move" : `Open Onsite${a} · drag to move`,
2837
+ "aria-expanded": String(e.open),
2838
+ "aria-describedby": e.open ? null : yn,
2839
+ "data-dock": "",
2840
+ on: {
2841
+ click: () => e.dockClick(),
2842
+ contextmenu: (t) => {
2843
+ t.preventDefault(), e.menu.show();
2844
+ },
2845
+ pointerdown: (t) => e.dragStart(t, "dock"),
2846
+ pointerenter: (t) => e.tipSoon(t),
2847
+ pointerleave: () => e.setTip(!1),
2848
+ focus: () => e.tipFocus(),
2849
+ blur: () => e.setTip(!1)
2850
+ }
2851
+ }, M(I(26, 2.8, t)), t && i ? j("span", {
2852
+ class: "badge",
2853
+ "aria-hidden": "true",
2854
+ title: `1 working, ${i} waiting`
2855
+ }, String(i + 1)) : !t && n ? j("span", {
2856
+ class: "badge",
2857
+ "aria-hidden": "true"
2858
+ }, String(n)) : null), vn(e, "dockmore")];
2859
+ }
2860
+ function vn(e, t) {
2861
+ return j("button", {
2862
+ class: t,
2863
+ type: "button",
2864
+ "aria-label": "Onsite menu: changes, export, skills, presets, settings",
2865
+ title: t === "dockmore" ? null : "Menu",
2866
+ "aria-haspopup": "menu",
2867
+ "aria-expanded": String(e.menu.open),
2868
+ "data-menu-button": "",
2869
+ ...t === "dockmore" ? { "data-dockmore": "" } : {},
2870
+ on: { click: (t) => {
2871
+ t.stopPropagation(), e.menu.toggle();
2872
+ } }
2873
+ }, M(R.dots));
2874
+ }
2875
+ var yn = "os-tip";
2876
+ function bn() {
2877
+ let e = F(), t = (e) => j("kbd", null, e), n = (e, ...t) => [j("dt", null, e), j("dd", null, ...t)];
2878
+ return j("div", {
2879
+ class: "tip",
2880
+ id: yn,
2881
+ role: "tooltip",
2882
+ hidden: !0,
2883
+ "data-tip": ""
2884
+ }, j("div", { class: "brand" }, M(I(14, 3.2)), j("span", null, "onsite")), j("dl", null, n("Open", "2×", t(e)), n("Select", M(R.mouse), j("span", { class: "sr" }, "click"), "+", t(e)), n("Changes", "hold", t(e)), n("Comment", "type, then", t(e), "+", t("↵")), n("Menu", "right-click or ⋯"), n("Move", "drag or", t("⇧"), "+", t("arrows"))));
2885
+ }
2886
+ function xn(e) {
2887
+ let t = e.toast;
2888
+ if (!t) return null;
2889
+ let n = t.undo;
2890
+ return j("div", {
2891
+ class: `toast${n ? "" : " plain"}`,
2892
+ role: "status"
2893
+ }, j("span", null, t.text), n ? j("button", {
2894
+ class: "btn ghost",
2895
+ type: "button",
2896
+ on: { click: () => void e.undo(n) }
2897
+ }, "Undo") : null);
2898
+ }
2899
+ function Sn(e, t) {
2900
+ return j("aside", {
2901
+ class: `panel scroll${t ? " opening" : ""}`,
2902
+ "aria-label": "Onsite",
2903
+ "data-panel": ""
2904
+ }, Cn(e), e.hidden ? j("div", {
2905
+ class: "hiddenbar",
2906
+ "data-hiddenbar": ""
2907
+ }, M(R.hide), j("span", { class: "grow" }, `The icon is hidden. Double-tap ${F()} opens Onsite.`), j("button", {
2908
+ class: "link",
2909
+ type: "button",
2910
+ on: { click: () => void e.setHidden(!1) }
2911
+ }, "Show icon")) : null, wn(e), j("div", {
2912
+ class: "body scroll",
2913
+ id: "os-view",
2914
+ role: "tabpanel",
2915
+ "aria-label": e.tab
2916
+ }, e.tab === "thread" ? On(e) : e.tab === "changes" ? Mn(e) : Pn(e)), In(e), Bn(e));
2917
+ }
2918
+ function Cn(e) {
2919
+ let t = (t, n, r) => j("button", {
2920
+ class: "tab",
2921
+ type: "button",
2922
+ role: "tab",
2923
+ "aria-selected": String(e.tab === t),
2924
+ "aria-controls": "os-view",
2925
+ on: { click: () => e.setTab(t) }
2926
+ }, n, r ? j("span", { class: "count" }, r) : null), n = (e.changes?.groups.reduce((e, t) => e + t.files.length, 0) ?? 0) + Tn(e).length, r = {
2927
+ auto: "Auto",
2928
+ dark: "Dark",
2929
+ light: "Light"
2930
+ }, i = e.pref === "auto" ? `Auto · ${r[e.pageScheme]}` : r[e.pref];
2931
+ return j("div", {
2932
+ class: "head",
2933
+ "data-head": "",
2934
+ on: { pointerdown: (t) => e.dragStart(t, "head") }
2935
+ }, j("button", {
2936
+ class: "grip",
2937
+ type: "button",
2938
+ "aria-label": "Move Onsite: drag to move, or press Shift and an arrow key",
2939
+ "data-grip": ""
2940
+ }, M(I(18, 3))), j("div", {
2941
+ class: "tabs",
2942
+ role: "tablist",
2943
+ "aria-label": "Onsite views"
2944
+ }, t("thread", "Thread"), t("changes", "Changes", n ? String(n) : ""), t("export", "Export")), j("span", { class: "grow" }), vn(e, "btn ghost icon"), j("button", {
2945
+ class: "btn ghost scheme",
2946
+ type: "button",
2947
+ "aria-label": `Onsite's scheme: ${r[e.pref]}. Change it`,
2948
+ title: "Auto follows the page. Pin Dark or Light here.",
2949
+ "data-scheme-button": "",
2950
+ on: { click: () => void e.cycleScheme() }
2951
+ }, M(R.scheme), i), j("button", {
2952
+ class: "btn ghost icon",
2953
+ type: "button",
2954
+ "aria-label": "Close Onsite",
2955
+ on: { click: () => e.setOpen(!1) }
2956
+ }, M(R.close)));
2957
+ }
2958
+ function wn(e) {
2959
+ let t = F(), n = (e, t, n, r, i, a) => j("button", {
2960
+ class: "btn",
2961
+ type: "button",
2962
+ "aria-pressed": String(e),
2963
+ title: i,
2964
+ on: { click: a }
2965
+ }, M(t), n, j("span", {
2966
+ class: "key",
2967
+ "aria-hidden": "true"
2968
+ }, r));
2969
+ return j("div", { class: "modes" }, n(e.mode === "select", R.select, "Select", t, `Click elements to mention them. ${t}-click works too.`, () => e.setMode(e.mode === "select" ? "idle" : "select")), n(e.alt !== "off", R.alt, "Changes", `hold ${t}`, `Outline what the takes changed. Hold ${t} to peek.`, () => e.toggleAltView()));
2970
+ }
2971
+ var Tn = (e) => e.thread.comments.filter((e) => !e.resolved), En = (e, t) => e.thread.comments.findIndex((e) => e.id === t) + 1;
2972
+ function Dn(e, t) {
2973
+ return e.drawn.has(t) ? "" : (e.drawn.add(t), " in");
2974
+ }
2975
+ function On(e) {
2976
+ let { entries: t } = e.thread;
2977
+ if (!t.length) return j("div", { class: "empty" }, j("p", { class: "lead" }, "Point at the page, then say what to change."), j("p", null, `Hold ${F()} and click elements to mention them. Every change lands as a take you can switch, keep or skip. Nothing reaches your files until you keep it.`));
2978
+ let n = j("div", {
2979
+ class: "thread",
2980
+ role: "log",
2981
+ "aria-label": "Thread"
2982
+ }), r = /* @__PURE__ */ new Map();
2983
+ for (let e of t) e.who !== "person" && r.set(`${e.id}:${e.who}`, e);
2984
+ let i = new Set(t.filter((e) => e.who === "person").map((e) => e.id)), a = e.lastChange();
2985
+ for (let o of t) if (o.who === "person") n.append(kn(e, o, r.get(`${o.id}:agent`), r.get(`${o.id}:error`)));
2986
+ else if (i.has(o.id)) continue;
2987
+ else o.who === "error" ? n.append(j("div", { class: `system error${Dn(e, `x:${o.id}`)}` }, M(R.error), o.text)) : n.append(jn(e, o, o.id === a));
2988
+ return n;
2989
+ }
2990
+ function kn(e, t, n, i) {
2991
+ let a = e.thread.running === t.id, o = t.kind === "takes" || (n?.takes?.length ?? 0) > 1, s = t.steps ?? [], f = [...(t.selection ?? []).map((e) => j("span", {
2992
+ class: "chip-dark",
2993
+ title: l(e)
2994
+ }, c(e.src))), ...(t.comments ?? []).map((t) => j("span", { class: "chip-dark" }, `Comment ${En(e, t) || "?"}`))], p = j("div", {
2995
+ class: `turn${Dn(e, `t:${t.id}`)}`,
2996
+ "data-run": t.id
2997
+ }, j("div", { class: "ask" }, t.text, f.length ? j("div", { class: "chips" }, f) : null)), m = (n) => j("ul", {
2998
+ class: "steps",
2999
+ "aria-label": "Steps"
3000
+ }, (n ? s : []).map((n, r) => {
3001
+ let i = n.tool === "src_write" || n.tool === "src_edit";
3002
+ return j("li", { class: `step${i ? " write" : ""}${Dn(e, `s:${t.id}:${r}`)}` }, M(i ? R.write : n.tool === "src_list" ? R.list : R.read), j("span", null, v(n, o)));
3003
+ }));
3004
+ a && s.length && p.append(m(!0));
3005
+ let h = a ? e.live?.run === t.id ? e.live.text : "" : n?.text ?? "";
3006
+ if (a) p.append(j("p", {
3007
+ class: "reply",
3008
+ "data-live": "",
3009
+ "aria-live": "off"
3010
+ }, h, j("span", {
3011
+ class: "caret",
3012
+ "aria-hidden": "true"
3013
+ })));
3014
+ else if (h) {
3015
+ let e = j("div", { class: "reply" });
3016
+ e.append(gn(h)), p.append(e);
3017
+ }
3018
+ let g = j("div", {
3019
+ class: "status",
3020
+ role: a ? "status" : null
3021
+ }), _ = e.thread.queue?.indexOf(t.id) ?? -1;
3022
+ if (_ >= 0) g.classList.add("queued"), g.append(j("span", {
3023
+ class: "qdot",
3024
+ "aria-hidden": "true"
3025
+ }), j("span", null, d(_)), j("button", {
3026
+ class: "link",
3027
+ type: "button",
3028
+ "data-cancel": t.id,
3029
+ on: { click: () => void e.cancel(t.id) }
3030
+ }, "Cancel"));
3031
+ else if (a) {
3032
+ let t = s.filter((e) => e.take).at(-1)?.take ?? An(e);
3033
+ g.append(j("span", {
3034
+ class: "spin",
3035
+ "aria-hidden": "true"
3036
+ }), j("span", null, `Working on ${u(t)}`));
3037
+ } else i ? (g.classList.add("error"), g.append(M(R.error), j("span", null, i.text))) : n?.stopped ? g.append(j("span", {
3038
+ class: "square",
3039
+ "aria-hidden": "true"
3040
+ }), j("span", null, se(n, e.thread.takes))) : n && g.append(M(R.done), j("span", null, oe(n, t, e.thread.takes)));
3041
+ if (!a && s.length) {
3042
+ let n = e.openSteps.has(t.id);
3043
+ g.append(j("button", {
3044
+ class: "link",
3045
+ type: "button",
3046
+ "aria-expanded": String(n),
3047
+ on: { click: () => {
3048
+ n ? e.openSteps.delete(t.id) : e.openSteps.add(t.id), e.render();
3049
+ } }
3050
+ }, r(s.length, "step")));
3051
+ }
3052
+ return g.childNodes.length && p.append(g), !a && e.openSteps.has(t.id) && p.append(m(!0)), p;
3053
+ }
3054
+ function An(e) {
3055
+ let t = e.thread.running, n = e.thread.takes.filter((e) => e.of === t);
3056
+ return n.length ? Math.max(...n.map((e) => e.no)) : 1;
3057
+ }
3058
+ function jn(e, t, n) {
3059
+ let r = t.kind === "undo" ? R.undo : R.keep, i = t.text && !/^(Kept|Skipped|Undone)\.?$/.test(t.text) ? t.text : "";
3060
+ return j("div", { class: `system${Dn(e, `c:${t.id}`)}` }, M(r), j("span", null, ce(t)), t.undone ? j("span", null, "· undone") : null, n ? j("button", {
3061
+ class: "link",
3062
+ type: "button",
3063
+ disabled: !!e.busy,
3064
+ on: { click: () => void e.undo(t.id) }
3065
+ }, "Undo") : null, i ? j("span", { class: "muted" }, i) : null);
3066
+ }
3067
+ function Mn(e) {
3068
+ let t = j("div", { class: "view" }), n = (e.changes?.groups ?? []).filter((e) => e.files.length), r = Tn(e);
3069
+ if (!n.length && !r.length) return t.append(j("p", { class: "note" }, "No open takes yet. When a take changes files, they show here by kind, with the takes that touch each one.")), t;
3070
+ for (let r of n) t.append(j("section", { class: "group" }, j("h3", null, le[r.kind]), r.files.map((t) => Nn(e, t))));
3071
+ return r.length && t.append(j("section", { class: "group" }, j("h3", null, "Comments"), r.map((t) => {
3072
+ let n = En(e, t.id), r = e.chosen.includes(t.id), i = t.take ? ` · on ${Z(e, t.take)}` : "";
3073
+ return j("div", { class: "card" }, j("div", { class: "comment" }, j("span", { class: "note-no" }, String(n)), j("div", {
3074
+ class: "line",
3075
+ style: "flex-direction:column;align-items:stretch;gap:4px;flex-grow:1"
3076
+ }, j("span", { class: "text" }, t.text), j("span", { class: "where" }, `${l(t.stamp)}${i}`), j("div", { class: "actions" }, j("button", {
3077
+ class: "link",
3078
+ type: "button",
3079
+ on: { click: () => e.chooseComment(t.id) }
3080
+ }, r ? "Leave out of the ask" : "Add to the ask"), j("button", {
3081
+ class: "link",
3082
+ type: "button",
3083
+ on: { click: () => void e.resolve(t.id, !0) }
3084
+ }, "Resolve")))));
3085
+ }))), t;
3086
+ }
3087
+ function Nn(e, t) {
3088
+ let n = e.openFile === t.path, o = t.takes.reduce((e, t) => Math.max(e, t.added), 0), s = t.takes.reduce((e, t) => Math.max(e, t.removed), 0), c = j("div", { class: "card" }, j("button", {
3089
+ class: "row",
3090
+ type: "button",
3091
+ "aria-expanded": String(n),
3092
+ title: t.path,
3093
+ on: { click: () => e.toggleFile(t.path) }
3094
+ }, j("span", { class: "line" }, j("span", { class: "fname" }, i(t.path)), t.status === "added" ? j("span", { class: "new" }, "new") : null, t.status === "deleted" ? j("span", { class: "del" }, "deleted") : null, j("span", { class: "grow" }), o ? j("span", { class: "add" }, `+${o}`) : null, s ? j("span", { class: "del" }, `−${s}`) : null), j("span", { class: "line" }, j("span", { class: "fdir" }, a(t.path)), j("span", { class: "grow" }), t.takes.map((t) => j("span", { class: "chip" }, Z(e, t.take)))), t.comps.length || t.comments.length ? j("span", { class: "meta" }, [t.comps.length ? t.comps.join(", ") : "", t.comments.length ? r(t.comments.length, "comment") : ""].filter(Boolean).join(" · ")) : null));
3095
+ if (n) {
3096
+ let n = j("div", { class: "actions" }, t.takes.map((n) => {
3097
+ let r = e.diff?.path === t.path && e.diff.take === n.take;
3098
+ return j("button", {
3099
+ class: "btn",
3100
+ type: "button",
3101
+ "aria-pressed": String(r),
3102
+ on: { click: () => void e.openDiff(t.path, n.take) }
3103
+ }, `${Z(e, n.take)} `, j("span", { class: "add" }, `+${n.added}`), j("span", { class: "del" }, `−${n.removed}`));
3104
+ }));
3105
+ c.append(n);
3106
+ let r = e.diff?.path === t.path ? e.diff : null;
3107
+ if (r) {
3108
+ let t = j("pre", {
3109
+ class: "diff scroll",
3110
+ "aria-label": `Diff of ${i(r.path)}`
3111
+ });
3112
+ for (let e of r.diff.split("\n")) {
3113
+ let n = e.startsWith("@@") ? "hunk" : e.startsWith("+") && !e.startsWith("+++") ? "plus" : e.startsWith("-") && !e.startsWith("---") ? "minus" : "";
3114
+ t.append(j("span", n ? { class: n } : null, e || " "));
3115
+ }
3116
+ let n = e.thread.takes.find((e) => e.id === r.take), a = z(e.thread).includes(r.take);
3117
+ c.append(t), n && n.state === "open" && c.append(j("div", { class: "actions" }, j("button", {
3118
+ class: "btn",
3119
+ type: "button",
3120
+ disabled: a || !!e.busy,
3121
+ on: { click: () => void e.show(r.take) }
3122
+ }, a ? `${Z(e, n.id)} shows` : `Show ${Z(e, n.id)}`)));
3123
+ }
3124
+ }
3125
+ return c;
3126
+ }
3127
+ function Z(e, t) {
3128
+ let n = e.thread.takes.find((e) => e.id === t);
3129
+ if (!n) return "Take";
3130
+ let r = e.thread.entries.filter((e) => e.who === "person").map((e) => e.id);
3131
+ return m(n, e.exportable(), r);
3132
+ }
3133
+ function Pn(e) {
3134
+ let t = e.exportable(), n = e.exportChosen(), r = Tn(e), i = e.exportCommentsChosen(), a = j("div", {
3135
+ class: "view",
3136
+ style: "gap:12px"
3137
+ }, j("p", { class: "note" }, "One prompt for your own coding agent: what you asked, the takes as a design reference, your comments, and how to build it properly in this repository."));
3138
+ t.length && a.append(j("div", {
3139
+ class: "seg",
3140
+ role: "group",
3141
+ "aria-label": "Takes to export"
3142
+ }, t.map((t) => j("button", {
3143
+ type: "button",
3144
+ "aria-pressed": String(n.includes(t.id)),
3145
+ title: [t.label, t.state === "kept" ? "kept" : ""].filter(Boolean).join(" · ") || null,
3146
+ on: { click: () => e.toggleExportTake(t.id) }
3147
+ }, `${Z(e, t.id)}${t.state === "kept" ? " · kept" : ""}`)))), r.length && a.append(j("div", {
3148
+ class: "picks",
3149
+ role: "group",
3150
+ "aria-label": "Comments to export"
3151
+ }, r.map((t) => j("label", { class: "check" }, j("input", {
3152
+ type: "checkbox",
3153
+ checked: i.includes(t.id),
3154
+ on: { change: () => e.toggleExportComment(t.id) }
3155
+ }), j("span", null, `${En(e, t.id)}. ${t.text}`)))));
3156
+ let o = e.exportOut?.markdown ?? "";
3157
+ return a.append(j("pre", {
3158
+ class: "prompt scroll",
3159
+ "aria-label": "The prompt",
3160
+ tabindex: 0
3161
+ }, o || "Building the prompt…"), j("div", { class: "buttons" }, j("button", {
3162
+ class: "btn primary grow",
3163
+ type: "button",
3164
+ disabled: !o,
3165
+ on: { click: () => void e.copyExport() }
3166
+ }, e.copied ? "Copied" : "Copy prompt"), j("button", {
3167
+ class: "btn",
3168
+ type: "button",
3169
+ disabled: !o,
3170
+ title: "Download the prompt as a Markdown file",
3171
+ on: { click: () => e.downloadExport() }
3172
+ }, "Save as .md"), j("button", {
3173
+ class: "btn ghost",
3174
+ type: "button",
3175
+ title: "Save the prompt in the project, under .onsite/exports/",
3176
+ on: { click: () => void e.saveExport() }
3177
+ }, "Save to .onsite"))), a;
3178
+ }
3179
+ function Fn(e, t, n) {
3180
+ let r = (t) => j("button", {
3181
+ class: "askstep",
3182
+ type: "button",
3183
+ "aria-label": t < 0 ? "Takes of the previous ask" : "Takes of the next ask",
3184
+ title: t < 0 ? "Takes of the previous ask" : "Takes of the next ask",
3185
+ "data-askstep": String(t),
3186
+ on: { click: () => e.stepAsk(t) }
3187
+ }, M(t < 0 ? R.back : R.next));
3188
+ return j("span", { class: "takeof" }, r(-1), j("span", { title: n }, `Ask ${t}`), r(1));
3189
+ }
3190
+ function In(e) {
3191
+ let t = e.takeRun();
3192
+ if (!t) return null;
3193
+ let n = e.openTakes(), r = n.filter((e) => e.of === t).sort((e, t) => e.no - t.no), i = new Set(n.map((e) => e.of)).size, a = e.thread.entries.filter((e) => e.who === "person"), o = a.findIndex((e) => e.id === t) + 1, s = {
3194
+ show: (t, n) => void e.show(t, n),
3195
+ toggleOriginal: (t) => e.toggleOriginal(t),
3196
+ keep: (t) => void e.keep(t),
3197
+ skip: (t) => void e.skip(t),
3198
+ hideFrame: (t) => e.hideFrame(t),
3199
+ openFrame: (t) => e.openFrame(t),
3200
+ cancel: (t) => void e.cancel(t),
3201
+ again: (t) => void e.again(t)
3202
+ }, c = j("div", {
3203
+ class: "takebar",
3204
+ role: "group",
3205
+ "aria-label": i > 1 && o ? `Takes of ask ${o}` : "Takes",
3206
+ "aria-busy": e.busy ? "true" : null,
3207
+ "data-takebar": t
3208
+ }, i > 1 && o ? Fn(e, o, a[o - 1]?.text ?? "") : null), l = {
3209
+ showing: z(e.thread),
3210
+ picked: e.picked,
3211
+ all: e.thread.takes,
3212
+ asks: a.map((e) => e.id)
3213
+ };
3214
+ if (c.append(Dt(t, r, l, s, `p:${t}`)), t === e.thread.running) for (let e of c.querySelectorAll("[data-frame-skip], [data-frame-keep]")) e.remove();
3215
+ return c;
3216
+ }
3217
+ function Ln(e) {
3218
+ let t = j("button", {
3219
+ class: `ib${e.cls ? ` ${e.cls}` : ""}`,
3220
+ type: "button",
3221
+ "aria-label": e.label,
3222
+ "aria-disabled": e.off ? "true" : null,
3223
+ "aria-keyshortcuts": e.shortcut ?? null,
3224
+ "data-tip": e.label,
3225
+ "data-tip-more": e.more || null,
3226
+ "data-tip-keys": e.keys?.join(" ") || null,
3227
+ "data-tip-key": e.hook,
3228
+ [e.hook]: "",
3229
+ on: { click: () => {
3230
+ t.getAttribute("aria-disabled") !== "true" && e.click();
3231
+ } }
3232
+ }, M(e.icon), e.extra);
3233
+ return t;
3234
+ }
3235
+ function Rn(e) {
3236
+ let t = (e, t, n, r, i) => j("span", {
3237
+ class: "chip",
3238
+ "data-tip": n || null
3239
+ }, M(e), j("span", null, t), j("button", {
3240
+ class: "x",
3241
+ type: "button",
3242
+ "aria-label": r,
3243
+ "data-tip": r,
3244
+ on: { click: i }
3245
+ }, M(R.x)));
3246
+ return [...e.pins.map((n, r) => {
3247
+ let i = n.getAttribute("data-onsite-src") ?? "", a = n.getAttribute("data-onsite-comp") ?? void 0;
3248
+ return t(R.element, `${r + 1} · ${a ?? c(i)}`, l({
3249
+ src: i,
3250
+ comp: a
3251
+ }), `Leave out element ${r + 1}`, () => e.togglePin(n));
3252
+ }), ...e.chosen.map((n) => {
3253
+ let r = En(e, n), i = e.thread.comments.find((e) => e.id === n)?.text ?? "";
3254
+ return t(R.commentChip, `Comment ${r}`, i, `Leave out comment ${r}`, () => e.chooseComment(n));
3255
+ })];
3256
+ }
3257
+ var zn = /* @__PURE__ */ new WeakMap();
3258
+ function Bn(e) {
3259
+ let t = e.basePick(), n = !!e.thread.running, i = e.thread.entries.filter((e) => e.who === "person").map((e) => e.id), a = t ? Z(e, t.take.id) : "", o = (e) => t ? de(t, a, i, e) : "", s = e.pins[0], l = s ? s.getAttribute("data-onsite-comp") ?? c(s.getAttribute("data-onsite-src") ?? "") : "", u = e.textarea;
3260
+ u.value !== e.draft && (u.value = e.draft), u.rows = 1, u.placeholder = e.mode === "select" ? "Click elements to mention them" : t ? `Refine ${a}, or ask for something else` : "Say what to change";
3261
+ let d = e.pins.length > 1 ? ` and ${r(e.pins.length - 1, "more element")}` : "";
3262
+ u.setAttribute("aria-label", s ? `Message to Onsite about ${l}${d}` : "Message to Onsite");
3263
+ let f = ct(), p = e.count, m = zn.has(e) && zn.get(e) !== p;
3264
+ zn.set(e, p);
3265
+ let h = Ln({
3266
+ label: `Takes to make: ${p}`,
3267
+ more: `Click for ${p % 3 + 1}`,
3268
+ icon: R.takes,
3269
+ cls: `takes${m ? " bump" : ""}`,
3270
+ hook: "data-takes",
3271
+ click: () => e.setCount(e.count % 3 + 1),
3272
+ extra: j("b", {
3273
+ class: "tbadge",
3274
+ "aria-hidden": "true"
3275
+ }, `×${p}`)
3276
+ });
3277
+ h.dataset.n = String(p);
3278
+ let g = Ln({
3279
+ label: "Pin as comment",
3280
+ more: s ? e.pins.length > 1 ? `Pins on ${l}, the first selected element. It starts no run.` : `Pins on ${l}. It starts no run.` : "Choose an element to pin a comment on it",
3281
+ keys: f ? ["⌥", "↵"] : ["Alt", "↵"],
3282
+ shortcut: "Alt+Enter",
3283
+ icon: R.pinComment,
3284
+ hook: "data-pin-comment",
3285
+ off: !e.canPin(),
3286
+ click: () => void e.pinComment()
3287
+ }), _ = f ? ["⌘", "↵"] : ["Ctrl", "↵"], ee = n ? Ln({
3288
+ label: "Stop",
3289
+ more: "The takes keep what the agent wrote.",
3290
+ icon: R.stop,
3291
+ cls: "stop",
3292
+ hook: "data-stop",
3293
+ click: () => void e.stop()
3294
+ }) : null, te = Ln(n ? {
3295
+ label: "Queue",
3296
+ more: e.queueFull() ? "3 asks wait already. Send again when one starts." : t ? `Waits its turn, and ${o(!0)}` : "Waits its turn: it starts when the run before it ends",
3297
+ keys: _,
3298
+ shortcut: "Control+Enter Meta+Enter",
3299
+ icon: R.queue,
3300
+ cls: "go",
3301
+ hook: "data-send",
3302
+ off: !e.canSend(),
3303
+ click: () => void e.send()
3304
+ } : {
3305
+ label: "Send",
3306
+ more: o(!1),
3307
+ keys: _,
3308
+ shortcut: "Control+Enter Meta+Enter",
3309
+ icon: R.send,
3310
+ cls: "go",
3311
+ hook: "data-send",
3312
+ off: !e.canSend(),
3313
+ click: () => void e.send()
3314
+ }), ne = j("div", { class: "prow" }, j("label", { class: "field" }, u), j("div", { class: "tools" }, h, g, ee, te)), v = Rn(e), re = e.quick && (e.pins.length > 1 || e.chosen.length > 0), ie = j("div", { class: "pbox" }, !e.quick && v.length ? j("div", { class: "chips" }, v) : null, ne);
3315
+ return j("div", { class: "composer" }, j("div", { class: `pill${re ? " tabbed" : ""}` }, re ? j("div", {
3316
+ class: "ptab",
3317
+ "data-tab": ""
3318
+ }, j("div", { class: "chips" }, v)) : null, ie));
3319
+ }
3320
+ function Vn(e, t) {
3321
+ return j("div", {
3322
+ class: `quick${t ? " opening" : ""}`,
3323
+ role: "dialog",
3324
+ "aria-label": "Quick chat",
3325
+ "data-quick": ""
3326
+ }, Bn(e));
3327
+ }
3328
+ // src/overlay.ts
3329
+ var Hn = "onsite-overlay", Un = 250, Wn = 400, Gn = 150, Kn = 400, qn = 400, Jn = 200, Yn = 560, Xn = 120;
3330
+ function Q() {
3331
+ let e = document.documentElement;
3332
+ return {
3333
+ w: e?.clientWidth || innerWidth,
3334
+ h: e?.clientHeight || innerHeight
3335
+ };
3336
+ }
3337
+ var Zn = {
3338
+ entries: [],
3339
+ takes: [],
3340
+ comments: [],
3341
+ shown: "",
3342
+ showing: [],
3343
+ running: "",
3344
+ seq: 0
3345
+ }, $ = {
3346
+ get(e) {
3347
+ try {
3348
+ return sessionStorage.getItem(`onsite:${e}`);
3349
+ } catch {
3350
+ return null;
3351
+ }
3352
+ },
3353
+ set(e, t) {
3354
+ try {
3355
+ t === null ? sessionStorage.removeItem(`onsite:${e}`) : sessionStorage.setItem(`onsite:${e}`, t);
3356
+ } catch {}
3357
+ }
3358
+ }, Qn = {
3359
+ get(e) {
3360
+ try {
3361
+ return localStorage.getItem(`onsite:${e}`);
3362
+ } catch {
3363
+ return null;
3364
+ }
3365
+ },
3366
+ set(e, t) {
3367
+ try {
3368
+ localStorage.setItem(`onsite:${e}`, t);
3369
+ } catch {}
3370
+ }
3371
+ }, $n = class {
3372
+ host;
3373
+ shadow;
3374
+ ui;
3375
+ layer;
3376
+ client;
3377
+ conn = null;
3378
+ thread = Zn;
3379
+ live = null;
3380
+ pref = "auto";
3381
+ pageScheme = "light";
3382
+ changes = null;
3383
+ hidden = !1;
3384
+ model = void 0;
3385
+ takes = 1;
3386
+ open = $.get("open") === "1";
3387
+ tab = $.get("tab") ?? "thread";
3388
+ mode = "idle";
3389
+ pins = [];
3390
+ quick = !1;
3391
+ chosen = [];
3392
+ openComment = "";
3393
+ draft = "";
3394
+ count = 1;
3395
+ busy = "";
3396
+ openSteps = /* @__PURE__ */ new Set();
3397
+ openFile = "";
3398
+ diff = null;
3399
+ exportTakes = null;
3400
+ exportComments = null;
3401
+ exportOut = null;
3402
+ copied = !1;
3403
+ toast = null;
3404
+ saved = qe($.get("dock"));
3405
+ anchor = this.saved;
3406
+ tip = !1;
3407
+ drag = null;
3408
+ hover = null;
3409
+ alt = "off";
3410
+ altMarks = null;
3411
+ altMenu = "";
3412
+ frameMarks = null;
3413
+ liveMarks = /* @__PURE__ */ new Map();
3414
+ hiddenFrames = new Set(rr($.get("hidden-frames")));
3415
+ chosenBar = void 0;
3416
+ picked = /* @__PURE__ */ new Map();
3417
+ lastRun = "";
3418
+ barAsk = "";
3419
+ beforeOriginal = null;
3420
+ drawn = /* @__PURE__ */ new Set();
3421
+ textarea;
3422
+ mover;
3423
+ hint;
3424
+ extras;
3425
+ tipEl;
3426
+ menu;
3427
+ quickBox;
3428
+ iconTip;
3429
+ question;
3430
+ stateSeen = !1;
3431
+ wasOpen = !1;
3432
+ quickWas = !1;
3433
+ tipTimer = 0;
3434
+ resizeTimer = 0;
3435
+ snapTimer = 0;
3436
+ stale = !1;
3437
+ checkLater = !1;
3438
+ noClick = !1;
3439
+ refocusing = !1;
3440
+ altTimer = 0;
3441
+ altAlone = !1;
3442
+ altDownAt = 0;
3443
+ lastTapAt = 0;
3444
+ toastTimer = 0;
3445
+ copyTimer = 0;
3446
+ changesTimer = 0;
3447
+ exportTimer = 0;
3448
+ frameTimer = 0;
3449
+ stopScheme = () => {};
3450
+ recheckScheme = () => {};
3451
+ update = null;
3452
+ flashes = Promise.resolve();
3453
+ updateWait;
3454
+ cleanups = [];
3455
+ constructor(e = {}) {
3456
+ this.client = e.client ?? pe(), this.updateWait = e.updateWait ?? 1e3, this.host = document.createElement(Hn), this.host.setAttribute("data-onsite-overlay", ""), this.host.style.cssText = "position:fixed;top:0;left:0;width:0;height:0;margin:0;padding:0;border:0;z-index:2147483647;display:block;", this.shadow = this.host.attachShadow({ mode: "open" }), this.shadow.append(j("style", null, It)), this.layer = new Rt(this.host, () => this.layerState(), {
3457
+ show: (e, t) => this.show(e, t),
3458
+ hideTakes: (e) => void this.hideTakes(e),
3459
+ toggleAltMenu: (e) => {
3460
+ this.altMenu = this.altMenu === e ? "" : e, this.layer.draw(), this.altMenu ? this.avoid() : this.goBack();
3461
+ },
3462
+ openComment: (e) => {
3463
+ this.openComment = e, this.layer.draw();
3464
+ },
3465
+ resolve: (e) => void this.resolve(e, !0),
3466
+ chooseComment: (e) => this.chooseComment(e),
3467
+ altKeyName: F,
3468
+ keep: (e) => void this.keep(e),
3469
+ skip: (e) => void this.skip(e),
3470
+ toggleOriginal: (e) => this.toggleOriginal(e),
3471
+ cancel: (e) => void this.cancel(e),
3472
+ again: (e) => void this.again(e),
3473
+ hideFrame: (e) => this.hideFrame(e),
3474
+ openFrame: (e) => this.openFrame(e),
3475
+ framesChanged: () => queueMicrotask(() => this.avoid()),
3476
+ positioned: () => this.placeQuick()
3477
+ }), this.ui = j("div", {
3478
+ class: "ui",
3479
+ "data-layer": "ui"
3480
+ }), this.mover = j("div", {
3481
+ class: "mover",
3482
+ "data-mover": ""
3483
+ }), this.quickBox = j("div", { "data-quickbox": "" }), this.hint = j("div", {
3484
+ class: "snaphint",
3485
+ hidden: !0,
3486
+ "aria-hidden": "true",
3487
+ "data-snaphint": ""
3488
+ }), this.extras = j("div", null), this.tipEl = bn(), this.menu = new Ut(this), this.question = new Xt(this.shadow, Q), this.iconTip = new fn(this.ui), this.ui.append(this.quickBox, this.mover, this.hint, this.menu.el, this.extras, this.question.el, this.iconTip.el), this.shadow.append(this.layer.root, this.ui), this.textarea = j("textarea", { rows: 1 }), this.textarea.addEventListener("input", () => {
3489
+ this.draft = this.textarea.value, this.renderComposerState(), this.fitText(), this.quick && this.placeQuick();
3490
+ }), this.textarea.addEventListener("keydown", (e) => {
3491
+ e.key === "Enter" && (e.metaKey || e.ctrlKey ? (e.preventDefault(), this.quick && e.shiftKey ? this.expandQuick() : this.send()) : e.altKey && (e.preventDefault(), this.dropAltView(), this.pinComment()));
3492
+ }), (document.documentElement ?? document.body).append(this.host);
3493
+ let t = on({
3494
+ doc: document,
3495
+ host: this.host,
3496
+ point: () => Ye(this.anchor, Q())
3497
+ }, (e) => {
3498
+ this.pageScheme = e, this.render();
3499
+ });
3500
+ this.pageScheme = t.scheme, this.stopScheme = t.stop, this.recheckScheme = t.recheck, this.listen(), this.render(), this.start(e.hot === void 0 ? me() : e.hot);
3501
+ }
3502
+ async start(e) {
3503
+ let t = await e;
3504
+ this.conn = ge(this.client, t, {
3505
+ state: (e) => this.onState(e),
3506
+ text: (e) => {
3507
+ e.run === this.thread.running && (this.live = {
3508
+ run: e.run,
3509
+ text: e.text
3510
+ }, this.renderLive());
3511
+ },
3512
+ flash: (e) => this.onFlash(e),
3513
+ afterUpdate: () => this.afterUpdate(),
3514
+ error: (e) => this.showToast(`Onsite did not answer: ${e.message}`)
3515
+ });
3516
+ try {
3517
+ let e = await this.client.call("GET prefs", {});
3518
+ this.pref = e.scheme, this.hidden = e.hidden === !0, this.model = e.model || void 0, this.takes = nr(e.takes), this.count === 1 && (this.count = this.takes);
3519
+ let t = qe(e.dock);
3520
+ if (t !== this.saved && !this.drag) {
3521
+ let e = this.anchor !== this.saved;
3522
+ this.saved = t, $.set("dock", t), e || (this.anchor = t);
3523
+ }
3524
+ this.render(), this.recheckScheme();
3525
+ } catch {}
3526
+ }
3527
+ refresh() {
3528
+ return this.conn?.refresh() ?? Promise.resolve();
3529
+ }
3530
+ onState(e) {
3531
+ let t = this.thread;
3532
+ this.thread = e, this.sayStale(t, e);
3533
+ for (let t of z(e)) {
3534
+ let n = e.takes.find((e) => e.id === t);
3535
+ n && this.picked.set(n.of, n.id);
3536
+ }
3537
+ let n = e.takes.find((t) => t.id === e.shown);
3538
+ e.shown !== t.shown && (this.barAsk = ""), n && (this.lastRun = n.of), e.running ? e.live?.run === e.running && (this.live?.run !== e.running || e.live.text.length >= this.live.text.length) ? this.live = {
3539
+ run: e.running,
3540
+ text: e.live.text
3541
+ } : this.live && this.live.run !== e.running && (this.live = null) : this.live = null, this.chosen = this.chosen.filter((t) => e.comments.some((e) => e.id === t && !e.resolved)), this.openComment && !e.comments.some((e) => e.id === this.openComment && !e.resolved) && (this.openComment = "");
3542
+ let r = t.shown !== e.shown || z(t).join(" ") !== z(e).join(" ") || JSON.stringify(t.takes.map(er)) !== JSON.stringify(e.takes.map(er));
3543
+ r && this.alt !== "off" && this.loadMarks(), r && (this.diff = null), e.running && e.running !== t.running && (this.chosenBar = void 0), (r || e.running !== t.running || tr(e) !== tr(t)) && this.loadFrameMarksSoon(), this.render(), this.loadChangesSoon(), this.open && this.tab === "export" && this.loadExportSoon();
3544
+ }
3545
+ sayStale(e, t) {
3546
+ let n = this.stateSeen ? z(e) : ($.get("shown") ?? "").split(" ").filter(Boolean);
3547
+ this.stateSeen = !0;
3548
+ let r = z(t);
3549
+ if ($.set("shown", r.join(" ") || null), this.busy === "show") return;
3550
+ let i = n.filter((e) => !r.includes(e)), a = t.takes.find((e) => i.includes(e.id) && e.state === "open" && e.stale?.length);
3551
+ a && this.showToast(ne(a));
3552
+ }
3553
+ onFlash(e) {
3554
+ let t = this.thread.takes.find((t) => t.id === e.take)?.of ?? (this.thread.running && pt(this.thread.running, this.thread.takes, e.take) ? this.thread.running : "");
3555
+ if (t) {
3556
+ let n = this.liveMarks.get(t) ?? {
3557
+ stamps: [],
3558
+ selectors: []
3559
+ };
3560
+ B(n, e.marks), this.liveMarks.set(t, n);
3561
+ }
3562
+ let n = this.waitUpdate();
3563
+ this.flashes = this.flashes.then(async () => {
3564
+ await n, await st(60), await N(), await N(), this.layer.draw(), this.layer.flash(e.marks) === 0 && (await st(250), this.layer.flash(e.marks));
3565
+ }).catch(() => void 0);
3566
+ }
3567
+ waitUpdate() {
3568
+ if (!this.update) {
3569
+ let e = () => {}, t = new Promise((t) => {
3570
+ e = t;
3571
+ });
3572
+ this.update = {
3573
+ promise: t,
3574
+ done: e
3575
+ };
3576
+ }
3577
+ let e = this.update.promise;
3578
+ return Promise.race([e, st(this.updateWait)]);
3579
+ }
3580
+ afterUpdate() {
3581
+ this.update?.done(), this.update = null, this.recheckScheme(), this.layer.draw(), this.alt !== "off" && this.loadMarks(), this.loadFrameMarksSoon();
3582
+ }
3583
+ isOurs(e) {
3584
+ return e.composedPath().includes(this.host);
3585
+ }
3586
+ listen() {
3587
+ let e = (e, t, n = { capture: !0 }) => {
3588
+ addEventListener(e, t, n), this.cleanups.push(() => removeEventListener(e, t, n));
3589
+ };
3590
+ e("mousemove", (e) => this.onMove(e), {
3591
+ capture: !0,
3592
+ passive: !0
3593
+ }), e("pointerdown", (e) => this.onDown(e)), e("mousedown", (e) => this.onDown(e)), e("click", (e) => this.onClick(e)), e("keydown", (e) => this.onKey(e)), e("keyup", (e) => this.onKeyUp(e)), e("blur", () => this.altUp(), { capture: !1 }), e("scroll", () => this.layer.schedule(), {
3594
+ capture: !0,
3595
+ passive: !0
3596
+ }), e("resize", () => {
3597
+ this.place(), this.layer.schedule(), this.recheckScheme(), clearTimeout(this.resizeTimer), this.resizeTimer = window.setTimeout(() => this.avoid(), Jn);
3598
+ });
3599
+ let t = new MutationObserver(() => this.layer.schedule());
3600
+ document.body && t.observe(document.body, {
3601
+ subtree: !0,
3602
+ childList: !0,
3603
+ attributes: !0,
3604
+ characterData: !0
3605
+ }), this.cleanups.push(() => t.disconnect());
3606
+ let n = setInterval(() => {
3607
+ this.layer.busy() && this.layer.schedule();
3608
+ }, 500);
3609
+ this.cleanups.push(() => clearInterval(n));
3610
+ }
3611
+ picking(e) {
3612
+ return this.mode !== "idle" || e.altKey;
3613
+ }
3614
+ onMove(e) {
3615
+ if (this.isOurs(e)) return;
3616
+ let t = this.picking(e) ? Lt(e.target) : null;
3617
+ t !== this.hover && (this.hover = t, this.layer.draw());
3618
+ }
3619
+ onDown(e) {
3620
+ this.menu.open && !e.composedPath().some((e) => e === this.menu.el || e instanceof Element && e.matches("[data-dock], [data-menu-button]")) && this.menu.close(), !this.isOurs(e) && this.picking(e) && Lt(e.target) && (e.preventDefault(), e.stopPropagation());
3621
+ }
3622
+ onClick(e) {
3623
+ if (this.isOurs(e)) return;
3624
+ if (this.openComment && (this.openComment = "", this.layer.draw()), this.quick && !this.picking(e)) return this.closeQuick();
3625
+ if (!this.picking(e)) return;
3626
+ let t = Lt(e.target);
3627
+ t && (e.preventDefault(), e.stopPropagation(), this.altAlone = !1, this.togglePin(t));
3628
+ }
3629
+ togglePin(e) {
3630
+ let t = this.pins.indexOf(e);
3631
+ t >= 0 ? this.pins.splice(t, 1) : this.pins.push(e), this.open || (this.quick = this.pins.length > 0, this.setTip(!1), this.menu.close()), this.render(), this.quick && this.textarea.focus({ preventScroll: !0 }), t < 0 && this.avoid();
3632
+ }
3633
+ closeQuick() {
3634
+ this.quick && (this.quick = !1, this.pins = [], this.hover = null, this.render());
3635
+ }
3636
+ expandQuick() {
3637
+ this.quick = !1, this.setOpen(!0);
3638
+ }
3639
+ placeQuick() {
3640
+ let e = this.quickBox.firstElementChild;
3641
+ if (!e) return;
3642
+ let t = this.pins[0], n = t?.isConnected ? t.getBoundingClientRect() : null, r = Q();
3643
+ if (e.style.width = `${Gt(r)}px`, !n || n.width === 0 && n.height === 0 && zt()) {
3644
+ e.style.visibility = "hidden";
3645
+ return;
3646
+ }
3647
+ e.style.visibility = "";
3648
+ let i = e.querySelector("[data-tab]"), a = qt({
3649
+ left: n.left - 4,
3650
+ top: n.top - 4,
3651
+ width: n.width + 8,
3652
+ height: n.height + 8
3653
+ }, {
3654
+ w: e.offsetWidth || Gt(r),
3655
+ h: e.offsetHeight || 80,
3656
+ tab: i ? {
3657
+ w: i.offsetWidth,
3658
+ h: i.offsetHeight
3659
+ } : void 0
3660
+ }, r);
3661
+ e.style.left = `${a.left}px`, e.style.top = `${a.top}px`, e.style.setProperty("--tab-x", `${a.tabX}px`), e.dataset.side = a.side;
3662
+ }
3663
+ fitText() {
3664
+ let e = this.textarea;
3665
+ if (!e.isConnected) return;
3666
+ e.style.height = "auto";
3667
+ let t = e.scrollHeight;
3668
+ e.style.height = t > 0 ? `${Math.min(t, Xn)}px` : "";
3669
+ }
3670
+ activeInside() {
3671
+ let e = document.activeElement;
3672
+ for (; e?.shadowRoot?.activeElement;) e = e.shadowRoot.activeElement;
3673
+ return e;
3674
+ }
3675
+ onKey(e) {
3676
+ if (this.question.key(e)) e.preventDefault(), e.stopPropagation();
3677
+ else if (!e.altKey && !e.metaKey && !e.ctrlKey && this.menu.key(e)) e.preventDefault(), e.stopPropagation();
3678
+ else if (!e.altKey && !e.metaKey && !e.ctrlKey && this.isOurs(e) && this.layer.frameKey(e)) e.preventDefault(), e.stopPropagation();
3679
+ else if (e.key === "Alt") {
3680
+ if (!e.repeat) {
3681
+ this.altAlone = !0, this.altDownAt = performance.now(), clearTimeout(this.altTimer);
3682
+ let e = this.activeInside() === this.textarea ? Kn : Gn;
3683
+ this.altTimer = window.setTimeout(() => this.altDown(), e);
3684
+ }
3685
+ } else if (e.altKey && (this.altAlone = !1, this.alt !== "held" && (clearTimeout(this.altTimer), this.altTimer = 0)), e.shiftKey && !e.altKey && !e.metaKey && !e.ctrlKey && e.key.startsWith("Arrow") && this.onHandle()) {
3686
+ if (e.preventDefault(), this.drag) return;
3687
+ this.setTip(!1), this.snapTo($e(this.anchor, e.key), "person");
3688
+ } else if (e.key === "Escape" && this.drag) this.endDrag(!0);
3689
+ else if (e.key === "Escape" && this.tip) this.setTip(!1);
3690
+ else if (e.key === "Escape") {
3691
+ if (this.openComment) this.openComment = "";
3692
+ else if (this.altMenu) this.altMenu = "";
3693
+ else if (this.mode !== "idle") this.setMode("idle");
3694
+ else if (this.quick) this.quick = !1, this.pins = [], this.hover = null;
3695
+ else if (this.open && this.isOurs(e)) this.setOpen(!1);
3696
+ else return;
3697
+ this.render();
3698
+ }
3699
+ }
3700
+ onKeyUp(e) {
3701
+ if (e.key !== "Alt") return;
3702
+ this.altAlone && e.preventDefault();
3703
+ let t = this.altAlone && performance.now() - this.altDownAt < Un;
3704
+ if (this.altAlone = !1, this.altUp(), !t) {
3705
+ this.lastTapAt = 0;
3706
+ return;
3707
+ }
3708
+ let n = performance.now();
3709
+ this.lastTapAt && n - this.lastTapAt < Wn ? (this.lastTapAt = 0, this.setOpen(!this.open)) : this.lastTapAt = n;
3710
+ }
3711
+ altDown() {
3712
+ this.altTimer = 0, this.alt === "off" && (this.alt = "held", this.altMenu = "", this.loadMarks(), this.render());
3713
+ }
3714
+ altUp() {
3715
+ clearTimeout(this.altTimer), this.altTimer = 0, this.hover && this.mode === "idle" && (this.hover = null), this.alt === "held" && (this.alt = "off", this.altMarks = null, this.altMenu = ""), this.render();
3716
+ }
3717
+ dropAltView() {
3718
+ clearTimeout(this.altTimer), this.altTimer = 0, this.alt === "held" && (this.alt = "off", this.altMarks = null, this.altMenu = "", this.render());
3719
+ }
3720
+ toggleAltView() {
3721
+ this.alt === "pinned" ? (this.alt = "off", this.altMarks = null, this.altMenu = "") : (this.alt = "pinned", this.loadMarks()), this.render();
3722
+ }
3723
+ async loadMarks() {
3724
+ try {
3725
+ let e = await this.client.call("GET marks", {});
3726
+ if (this.alt === "off") return;
3727
+ await N(), this.altMarks = e, this.layer.draw();
3728
+ } catch {}
3729
+ }
3730
+ frames() {
3731
+ return dt(this.thread, this.hiddenFrames);
3732
+ }
3733
+ loadFrameMarksSoon(e = 120) {
3734
+ clearTimeout(this.frameTimer), this.frameTimer = window.setTimeout(async () => {
3735
+ if (this.frames().length === 0) this.frameMarks = null;
3736
+ else try {
3737
+ let e = await this.client.call("GET marks", {});
3738
+ await N(), this.frameMarks = e, this.layer.draw();
3739
+ } catch {}
3740
+ }, e);
3741
+ }
3742
+ hideFrame(e) {
3743
+ this.hiddenFrames.add(e), $.set("hidden-frames", JSON.stringify([...this.hiddenFrames])), this.render();
3744
+ }
3745
+ openFrame(e) {
3746
+ this.chosenBar = e, this.layer.draw(), e && this.layer.root.querySelector(`[data-framebar="${CSS.escape(e)}"]`)?.focus({ preventScroll: !0 });
3747
+ }
3748
+ async savePrefs(e) {
3749
+ let t = await this.client.call("POST prefs", e);
3750
+ return this.pref = t.scheme, this.hidden = t.hidden === !0, this.model = t.model || void 0, this.takes = nr(t.takes), t;
3751
+ }
3752
+ async setHidden(e) {
3753
+ let t = this.hidden;
3754
+ this.hidden = e, this.setTip(!1), this.render();
3755
+ try {
3756
+ await this.savePrefs({ hidden: e || null }), e && !Qn.get("hid-once") && (Qn.set("hid-once", "1"), this.showToast(`The Onsite icon is hidden. Double-tap ${F()} to open Onsite, then choose Show icon.`));
3757
+ } catch (n) {
3758
+ this.hidden = t, this.showToast(`Could not ${e ? "hide" : "show"} the icon: ${n.message}`);
3759
+ }
3760
+ this.render();
3761
+ }
3762
+ async setScheme(e) {
3763
+ this.pref = e, this.render();
3764
+ try {
3765
+ await this.savePrefs({ scheme: e }), this.render();
3766
+ } catch (e) {
3767
+ this.showToast(`Could not keep the scheme: ${e.message}`);
3768
+ }
3769
+ }
3770
+ moveDock(e) {
3771
+ this.snapTo(e, "person");
3772
+ }
3773
+ focusDock() {
3774
+ this.mover.querySelector("[data-dock], [data-menu-button]")?.focus({ preventScroll: !0 });
3775
+ }
3776
+ setOpen(e) {
3777
+ this.open = e, $.set("open", e ? "1" : null), e && this.setTip(!1), e && this.menu.close(), e && (this.quick = !1), e || (this.mode = "idle", this.alt === "pinned" && (this.alt = "off", this.altMarks = null)), this.render(), e && (this.loadChangesSoon(), queueMicrotask(() => this.textarea.focus()), this.avoid());
3778
+ }
3779
+ dockClick() {
3780
+ if (this.noClick) this.noClick = !1;
3781
+ else {
3782
+ if (this.menu.open) return this.menu.close();
3783
+ this.setOpen(!this.open);
3784
+ }
3785
+ }
3786
+ onHandle() {
3787
+ let e = this.activeInside();
3788
+ return !!(e && this.shadow.contains(e) && (e.matches(".dock") || e.closest(".head")));
3789
+ }
3790
+ dragStart(e, t) {
3791
+ if (e.button !== 0 || this.drag || t === "head" && e.target?.closest?.("button:not(.grip), input, textarea, select, a, label, [role=tab]")) return;
3792
+ let n = e.currentTarget;
3793
+ this.noClick = !1;
3794
+ try {
3795
+ n.setPointerCapture(e.pointerId);
3796
+ } catch {}
3797
+ this.drag = {
3798
+ pointer: e.pointerId,
3799
+ el: n,
3800
+ from: t,
3801
+ x: e.clientX,
3802
+ y: e.clientY,
3803
+ moved: !1,
3804
+ target: this.anchor
3805
+ }, n.addEventListener("pointermove", this.onDragMove), n.addEventListener("pointerup", this.onDragUp), n.addEventListener("pointercancel", this.onDragCancel), n.addEventListener("lostpointercapture", this.onDragCancel);
3806
+ }
3807
+ onDragMove = (e) => {
3808
+ let t = this.drag;
3809
+ if (!t || e.pointerId !== t.pointer) return;
3810
+ let n = e.clientX - t.x, r = e.clientY - t.y;
3811
+ if (!t.moved && Math.hypot(n, r) < 4) return;
3812
+ t.moved || (t.moved = !0, this.setTip(!1), this.menu.close(), this.mover.classList.add("dragging")), e.preventDefault(), this.mover.style.transform = `translate(${n}px, ${r}px)`, t.target = Qe(e.clientX, e.clientY, Q());
3813
+ let i = A(t.target, Q());
3814
+ this.hint.style.left = `${i.left}px`, this.hint.style.top = `${i.top}px`, this.hint.hidden = !1;
3815
+ };
3816
+ onDragUp = (e) => {
3817
+ this.drag && e.pointerId === this.drag.pointer && this.endDrag(!1);
3818
+ };
3819
+ onDragCancel = (e) => {
3820
+ this.drag && e.pointerId === this.drag.pointer && this.endDrag(!0);
3821
+ };
3822
+ endDrag(e) {
3823
+ let t = this.drag;
3824
+ if (t) {
3825
+ t.el.removeEventListener("pointermove", this.onDragMove), t.el.removeEventListener("pointerup", this.onDragUp), t.el.removeEventListener("pointercancel", this.onDragCancel), t.el.removeEventListener("lostpointercapture", this.onDragCancel);
3826
+ try {
3827
+ t.el.hasPointerCapture?.(t.pointer) && t.el.releasePointerCapture(t.pointer);
3828
+ } catch {}
3829
+ this.hint.hidden = !0, this.mover.classList.remove("dragging"), t.moved ? (t.from === "dock" && (this.noClick = !0), e ? this.snapTo(this.anchor, "back") : this.snapTo(t.target, "person")) : (this.drag = null, this.stale && this.render());
3830
+ }
3831
+ }
3832
+ snapTo(e, t) {
3833
+ let n = [...this.mover.querySelectorAll(".dock, .panel")], r = n.map((e) => e.getBoundingClientRect());
3834
+ t === "person" && e !== this.saved ? (this.saved = e, $.set("dock", e), this.saveDock(e)) : t === "person" && (this.saved = e), this.anchor = e, this.drag = null, this.mover.style.transform = "", this.place(), this.recheckScheme();
3835
+ let i = n.flatMap((e, t) => {
3836
+ let n = r[t], i = e.getBoundingClientRect(), a = n ? n.left - i.left : 0, o = n ? n.top - i.top : 0;
3837
+ return a === 0 && o === 0 || e.classList.contains("opening") ? [] : [{
3838
+ el: e,
3839
+ dx: a,
3840
+ dy: o
3841
+ }];
3842
+ });
3843
+ if (P() || i.length === 0) return this.snapDone();
3844
+ for (let e of i) e.el.style.transition = "none", e.el.style.transform = `translate(${e.dx}px, ${e.dy}px)`;
3845
+ this.mover.offsetWidth;
3846
+ for (let e of i) e.el.classList.add("snapping"), e.el.style.transition = "", e.el.style.transform = "";
3847
+ clearTimeout(this.snapTimer), this.snapTimer = window.setTimeout(() => this.snapDone(), W.snap + 40);
3848
+ }
3849
+ snapDone() {
3850
+ clearTimeout(this.snapTimer), this.snapTimer = 0;
3851
+ for (let e of this.mover.querySelectorAll(".snapping")) e.classList.remove("snapping");
3852
+ this.stale ? this.render() : this.goBack(), this.checkLater && (this.checkLater = !1, this.avoid());
3853
+ }
3854
+ async saveDock(e) {
3855
+ try {
3856
+ await this.client.call("POST prefs", {
3857
+ scheme: this.pref,
3858
+ dock: e
3859
+ });
3860
+ } catch (e) {
3861
+ this.showToast(`Could not keep the place of Onsite: ${e.message}`);
3862
+ }
3863
+ }
3864
+ targets() {
3865
+ return [
3866
+ ...this.pins,
3867
+ ...this.layer.menuTargets(),
3868
+ ...this.layer.frameTargets()
3869
+ ];
3870
+ }
3871
+ avoid() {
3872
+ if (!this.open || this.drag) return;
3873
+ if (this.snapTimer) {
3874
+ this.checkLater = !0;
3875
+ return;
3876
+ }
3877
+ let e = Q(), t = this.targets().map((t) => et(t.getBoundingClientRect(), e)).filter((e) => e !== null);
3878
+ if (!t.length) return;
3879
+ let n = this.mover.querySelector(".panel")?.offsetHeight || Yn, r = rt(this.saved, (t) => [Ze(t, e, 400, n), A(t, e)], t);
3880
+ r !== this.anchor && this.snapTo(r, "avoid");
3881
+ }
3882
+ goBack() {
3883
+ if (this.anchor === this.saved || this.drag || this.snapTimer) return;
3884
+ let e = this.pins.length > 0 || this.altMenu !== "" || this.layer.frameTargets().length > 0;
3885
+ this.open && e || this.snapTo(this.saved, "back");
3886
+ }
3887
+ place() {
3888
+ let e = Q(), t = this.anchor;
3889
+ this.mover.dataset.row = E(t), this.extras.dataset.toast = t === "bottom-center" ? "top" : "bottom";
3890
+ let n = this.mover.querySelector(".dock");
3891
+ if (n) {
3892
+ let r = A(t, e);
3893
+ n.style.left = `${r.left}px`, n.style.top = `${r.top}px`;
3894
+ }
3895
+ let r = this.mover.querySelector("[data-dockmore]");
3896
+ if (r) {
3897
+ let n = A(t, e);
3898
+ r.style.left = `${n.left - 6}px`, r.style.top = `${n.top - 6}px`;
3899
+ }
3900
+ let i = (n, r, i) => {
3901
+ if (!n) return;
3902
+ let a = Xe(t, e, r, i);
3903
+ n.style.left = `${a.left}px`, n.style.width = `${a.width}px`, n.style.top = a.top === void 0 ? "" : `${a.top}px`, n.style.bottom = a.bottom === void 0 ? "" : `${a.bottom}px`, n.style.maxHeight = `${a.maxHeight}px`;
3904
+ };
3905
+ i(this.mover.querySelector(".panel"), 400), i(this.tipEl, 220, 8), this.menu.open && i(this.menu.el, 340, 8), this.question.place();
3906
+ }
3907
+ tipSoon(e) {
3908
+ e.pointerType && e.pointerType !== "mouse" || (clearTimeout(this.tipTimer), this.tipTimer = window.setTimeout(() => this.setTip(!0), qn));
3909
+ }
3910
+ tipFocus() {
3911
+ this.refocusing || this.drag || this.setTip(!0);
3912
+ }
3913
+ setTip(e) {
3914
+ clearTimeout(this.tipTimer);
3915
+ let t = e && !this.open && !this.menu.open && !this.hidden && !this.drag?.moved;
3916
+ this.tip !== t && (this.tip = t, this.tipEl.hidden = !t);
3917
+ }
3918
+ setTab(e) {
3919
+ this.tab = e, $.set("tab", e), e === "export" && (this.copied = !1, this.loadExportSoon(0)), e === "changes" && this.loadChangesSoon(0), this.render();
3920
+ }
3921
+ setMode(e) {
3922
+ this.mode = e, e === "idle" && (this.hover = null), this.render(), e !== "idle" && this.textarea.focus();
3923
+ }
3924
+ setCount(e) {
3925
+ this.count = Math.max(1, Math.min(3, e)), this.render();
3926
+ }
3927
+ async cycleScheme() {
3928
+ let e = [
3929
+ "auto",
3930
+ "dark",
3931
+ "light"
3932
+ ], t = e[(e.indexOf(this.pref) + 1) % e.length] ?? "auto";
3933
+ this.pref = t, this.render();
3934
+ try {
3935
+ this.pref = (await this.client.call("POST prefs", { scheme: t })).scheme, this.render();
3936
+ } catch (e) {
3937
+ this.showToast(`Could not keep the scheme: ${e.message}`);
3938
+ }
3939
+ }
3940
+ panelScheme() {
3941
+ return this.pref === "auto" ? this.pageScheme : this.pref;
3942
+ }
3943
+ openTakes() {
3944
+ return this.thread.takes.filter((e) => e.state === "open");
3945
+ }
3946
+ shownTake() {
3947
+ return this.thread.shown ? this.thread.takes.find((e) => e.id === this.thread.shown) : void 0;
3948
+ }
3949
+ queueFull() {
3950
+ return !!this.thread.running && (this.thread.queue?.length ?? 0) >= 3;
3951
+ }
3952
+ basePick() {
3953
+ return ue(this.thread, this.pins.map((e) => e.getAttribute("data-onsite-src") ?? ""));
3954
+ }
3955
+ baseTake() {
3956
+ return this.basePick()?.take;
3957
+ }
3958
+ canSend() {
3959
+ return !this.busy && !this.queueFull() && (this.draft.trim() !== "" || this.chosen.length > 0);
3960
+ }
3961
+ async send() {
3962
+ if (!this.canSend()) return;
3963
+ let e = this.draft.trim() || "Work on the comments I chose.";
3964
+ await this.ask(e, this.count, [...this.chosen]) && (this.draft = "", this.textarea.value = "", this.chosen = [], this.render());
3965
+ }
3966
+ async ask(e, t, n = []) {
3967
+ if (this.busy || this.queueFull()) return !1;
3968
+ let r = Ue(this.pins, {
3969
+ host: this.host,
3970
+ scheme: this.pageScheme
3971
+ }), i = this.baseTake();
3972
+ this.busy = "ask", this.render();
3973
+ try {
3974
+ let a = await this.client.call("POST ask", {
3975
+ message: e,
3976
+ count: Math.max(1, Math.min(3, t)),
3977
+ ...i ? { base: i.id } : {},
3978
+ context: r,
3979
+ ...n.length ? { comments: n } : {}
3980
+ });
3981
+ return a.queued && this.showToast(a.queued === 1 ? "Queued. It starts when the run that works ends." : `Queued, ${a.queued} in line. Each ask starts when the one before it ends.`), this.pins = [], this.quick = !1, this.count = this.takes, this.mode = "idle", this.tab = "thread", $.set("tab", "thread"), !0;
3982
+ } catch (e) {
3983
+ return this.showToast(e.message), !1;
3984
+ } finally {
3985
+ this.busy = "", this.render();
3986
+ }
3987
+ }
3988
+ async cancel(e) {
3989
+ try {
3990
+ await this.client.call("POST cancel", { run: e });
3991
+ } catch (e) {
3992
+ this.showToast(e.message);
3993
+ }
3994
+ }
3995
+ async stop() {
3996
+ let e = this.thread.running;
3997
+ if (e) try {
3998
+ await this.client.call("POST stop", { run: e });
3999
+ } catch (e) {
4000
+ this.showToast(e.message);
4001
+ }
4002
+ }
4003
+ toggleOriginal(e) {
4004
+ let t = this.openTakes().filter((t) => t.of === e), n = z(this.thread);
4005
+ if (!St(t, n)) return void this.show("", e);
4006
+ let r = H(e, t, n, this.picked);
4007
+ r && this.show(r.id);
4008
+ }
4009
+ takeRun() {
4010
+ let e = this.openTakes();
4011
+ if (this.barAsk && e.some((e) => e.of === this.barAsk)) return this.barAsk;
4012
+ let t = e.find((e) => e.id === this.thread.shown);
4013
+ return t ? t.of : this.lastRun && e.some((e) => e.of === this.lastRun) ? this.lastRun : e.at(-1)?.of ?? "";
4014
+ }
4015
+ takeRuns() {
4016
+ let e = new Set(this.openTakes().map((e) => e.of));
4017
+ return this.thread.entries.filter((t) => t.who === "person" && e.has(t.id)).map((e) => e.id);
4018
+ }
4019
+ stepAsk(e) {
4020
+ let t = this.takeRuns();
4021
+ if (t.length < 2) return;
4022
+ let n = Math.max(0, t.indexOf(this.takeRun()));
4023
+ this.barAsk = t[(n + e + t.length) % t.length], this.render();
4024
+ }
4025
+ async show(e, t) {
4026
+ if (this.busy) return;
4027
+ let n = z(this.thread), r = (e) => this.thread.takes.find((t) => t.id === e)?.of ?? e.replace(/-\d+$/, ""), i = e === "" ? t ? n.filter((e) => r(e) === t) : n : n.filter((t) => r(t) === r(e));
4028
+ if (e === "" ? i.length === 0 : n.includes(e)) return;
4029
+ let a = this.thread.takes.find((t) => t.id === e), o = !!a?.stale?.length;
4030
+ if (a && o && (!await this.askFirst(a) || this.busy)) return;
4031
+ a && (this.picked.set(a.of, a.id), this.lastRun = a.of, this.barAsk = "", this.beforeOriginal = null), this.busy = "show", this.render();
4032
+ let s = null;
4033
+ try {
4034
+ s = await this.client.call("GET marks", {});
4035
+ } catch {
4036
+ s = null;
4037
+ }
4038
+ let c = this.waitUpdate();
4039
+ try {
4040
+ let n = await this.client.call("POST show", e === "" && t ? {
4041
+ take: e,
4042
+ run: t
4043
+ } : { take: e });
4044
+ if (this.thread = {
4045
+ ...this.thread,
4046
+ shown: n.take,
4047
+ showing: n.showing ?? (n.take ? [n.take] : [])
4048
+ }, n.files.length) {
4049
+ await c, await N();
4050
+ let t = (s?.groups ?? []).filter((t) => t.takes.some((t) => t === e || i.includes(t)));
4051
+ this.layer.swap(t.flatMap((e) => q(e, this.host)));
4052
+ }
4053
+ } catch (e) {
4054
+ this.showToast(e.message);
4055
+ } finally {
4056
+ this.busy = "", this.render(), this.alt !== "off" && this.loadMarks(), o && !this.shadow.activeElement && this.question.refocus();
4057
+ }
4058
+ }
4059
+ askFirst(e) {
4060
+ return this.question.ask({
4061
+ label: "Show a take made on older code?",
4062
+ text: g(e),
4063
+ yes: "Show anyway"
4064
+ });
4065
+ }
4066
+ everywhere() {
4067
+ return z(this.thread).length > 0 ? "original" : this.takesBefore().length > 0 ? "back" : "";
4068
+ }
4069
+ takesBefore() {
4070
+ let e = this.beforeOriginal;
4071
+ return e ? [...e.showing.filter((t) => t !== e.shown), ...e.showing.includes(e.shown) ? [e.shown] : []].map((e) => this.thread.takes.find((t) => t.id === e)).filter((e) => e?.state === "open" && !e.stale?.length) : [];
4072
+ }
4073
+ async toggleEverywhere() {
4074
+ if (this.busy) return;
4075
+ let e = this.everywhere();
4076
+ if (e === "original") {
4077
+ let e = {
4078
+ showing: z(this.thread),
4079
+ shown: this.thread.shown
4080
+ };
4081
+ await this.show(""), z(this.thread).length === 0 && (this.beforeOriginal = e);
4082
+ return;
4083
+ }
4084
+ if (e !== "back") return;
4085
+ let t = this.beforeOriginal, n = this.takesBefore();
4086
+ this.beforeOriginal = null;
4087
+ let r = (t?.showing ?? []).map((e) => this.thread.takes.find((t) => t.id === e)).find((e) => e?.state === "open" && e.stale?.length);
4088
+ for (let e of n) await this.show(e.id);
4089
+ r && this.showToast(ne(r));
4090
+ }
4091
+ async hideTakes(e) {
4092
+ if (this.busy) return;
4093
+ let t = z(this.thread), n = t.filter((t) => e.includes(t));
4094
+ if (n.length === 0) return;
4095
+ if (n.length === t.length) return this.show("");
4096
+ let r = new Set(n.map((e) => this.thread.takes.find((t) => t.id === e)?.of).filter((e) => !!e));
4097
+ for (let e of r) await this.show("", e);
4098
+ }
4099
+ async keep(e) {
4100
+ if (!this.busy) {
4101
+ this.busy = "keep", this.render();
4102
+ try {
4103
+ let t = await this.client.call("POST keep", { take: e.id }), n = t.files.length ? ` · ${r(t.files.length, "file")} written` : "";
4104
+ this.showToast(`Kept ${u(e.no)}${n}${t.note ? `. ${t.note}` : ""}`, t.change);
4105
+ } catch (e) {
4106
+ this.showToast(e.message);
4107
+ } finally {
4108
+ this.busy = "", this.render();
4109
+ }
4110
+ }
4111
+ }
4112
+ async skip(e) {
4113
+ if (!this.busy) {
4114
+ this.busy = "skip", this.render();
4115
+ try {
4116
+ let t = await this.client.call("POST skip", { take: e.id });
4117
+ this.showToast(`${u(e.no)} skipped · no file changed${t.note ? `. ${t.note}` : ""}`);
4118
+ } catch (e) {
4119
+ this.showToast(e.message);
4120
+ } finally {
4121
+ this.busy = "", this.render();
4122
+ }
4123
+ }
4124
+ }
4125
+ async again(e) {
4126
+ if (!this.busy) {
4127
+ this.busy = "again", this.render();
4128
+ try {
4129
+ let t = await this.client.call("POST again", { take: e.id });
4130
+ this.showToast(`Asked again for ${u(e.no)} on the new code${t.queued ? ` · ${d(t.queued - 1)}` : ""}`);
4131
+ } catch (e) {
4132
+ this.showToast(e.message);
4133
+ } finally {
4134
+ this.busy = "", this.render();
4135
+ }
4136
+ }
4137
+ }
4138
+ async undo(e) {
4139
+ if (!this.busy) {
4140
+ this.busy = "undo", this.toast = null, this.render();
4141
+ try {
4142
+ let t = await this.client.call("POST undo", { change: e }), n = this.thread.entries.find((t) => t.id === e);
4143
+ this.showToast(`Undone: ${n ? ce(n).split(" · ")[0]?.toLowerCase() : "the change"}${t.note ? `. ${t.note}` : ""}`);
4144
+ } catch (e) {
4145
+ this.showToast(e.message);
4146
+ } finally {
4147
+ this.busy = "", this.render();
4148
+ }
4149
+ }
4150
+ }
4151
+ lastChange() {
4152
+ let e = [...this.thread.entries].reverse().find((e) => e.who === "agent" && (e.kind === "keep" || e.kind === "skip" || e.kind === "undo"));
4153
+ return e && e.kind !== "undo" && !e.undone ? e.id : "";
4154
+ }
4155
+ canPin() {
4156
+ return !this.busy && this.draft.trim() !== "" && this.pins.length > 0;
4157
+ }
4158
+ async pinComment() {
4159
+ let e = this.pins[0], t = this.draft.trim();
4160
+ if (t && !this.busy) {
4161
+ if (!e) this.showToast(`Choose an element first: ${F()}-click it, then pin.`);
4162
+ else {
4163
+ this.busy = "comment", this.render();
4164
+ try {
4165
+ let n = e.getAttribute("data-onsite-comp"), r = await this.client.call("POST comment", {
4166
+ text: t,
4167
+ stamp: {
4168
+ src: e.getAttribute("data-onsite-src") ?? "",
4169
+ ...n ? { comp: n } : {}
4170
+ },
4171
+ context: Ue([e], {
4172
+ host: this.host,
4173
+ scheme: this.pageScheme
4174
+ })
4175
+ }), i = this.thread.comments.findIndex((e) => e.id === r.id) + 1 || this.thread.comments.length + 1;
4176
+ this.draft = "", this.textarea.value = "", this.pins = [], this.quick = !1, this.hover = null, this.showToast(`Comment ${i} pinned · it starts no run`);
4177
+ } catch (e) {
4178
+ this.showToast(e.message);
4179
+ } finally {
4180
+ this.busy = "", this.render();
4181
+ }
4182
+ }
4183
+ }
4184
+ }
4185
+ async resolve(e, t) {
4186
+ try {
4187
+ await this.client.call("POST resolve", {
4188
+ id: e,
4189
+ resolved: t
4190
+ }), t && (this.chosen = this.chosen.filter((t) => t !== e)), this.openComment = "";
4191
+ } catch (e) {
4192
+ this.showToast(e.message);
4193
+ }
4194
+ this.render();
4195
+ }
4196
+ chooseComment(e) {
4197
+ this.chosen = this.chosen.includes(e) ? this.chosen.filter((t) => t !== e) : [...this.chosen, e], this.render();
4198
+ }
4199
+ loadChangesSoon(e = 150) {
4200
+ this.open && (clearTimeout(this.changesTimer), this.changesTimer = window.setTimeout(async () => {
4201
+ try {
4202
+ this.changes = await this.client.call("GET changes", {}), this.render();
4203
+ } catch {}
4204
+ }, e));
4205
+ }
4206
+ async openDiff(e, t) {
4207
+ if (this.diff && this.diff.path === e && this.diff.take === t) this.diff = null, this.render();
4208
+ else {
4209
+ try {
4210
+ this.diff = await this.client.call("GET diff", {
4211
+ take: t,
4212
+ path: e
4213
+ });
4214
+ } catch (e) {
4215
+ this.showToast(e.message);
4216
+ }
4217
+ this.render();
4218
+ }
4219
+ }
4220
+ toggleFile(e) {
4221
+ this.openFile = this.openFile === e ? "" : e, this.diff?.path !== this.openFile && (this.diff = null), this.render();
4222
+ }
4223
+ exportable() {
4224
+ return this.thread.takes.filter((e) => e.state === "open" || e.state === "kept");
4225
+ }
4226
+ exportChosen() {
4227
+ let e = this.exportable().map((e) => e.id);
4228
+ if (this.exportTakes) return this.exportTakes.filter((t) => e.includes(t));
4229
+ let t = z(this.thread).filter((t) => e.includes(t));
4230
+ if (t.length > 0) return t;
4231
+ let n = e.at(-1);
4232
+ return n ? [n] : [];
4233
+ }
4234
+ exportCommentsChosen() {
4235
+ let e = this.thread.comments.filter((e) => !e.resolved).map((e) => e.id);
4236
+ return this.exportComments ? this.exportComments.filter((t) => e.includes(t)) : e;
4237
+ }
4238
+ toggleExportTake(e) {
4239
+ let t = this.exportChosen();
4240
+ this.exportTakes = t.includes(e) ? t.filter((t) => t !== e) : [...t, e], this.copied = !1, this.loadExportSoon(0), this.render();
4241
+ }
4242
+ toggleExportComment(e) {
4243
+ let t = this.exportCommentsChosen();
4244
+ this.exportComments = t.includes(e) ? t.filter((t) => t !== e) : [...t, e], this.copied = !1, this.loadExportSoon(0), this.render();
4245
+ }
4246
+ loadExportSoon(e = 150) {
4247
+ clearTimeout(this.exportTimer), this.exportTimer = window.setTimeout(async () => {
4248
+ try {
4249
+ this.exportOut = await this.client.call("POST export", {
4250
+ takes: this.exportChosen(),
4251
+ comments: this.exportCommentsChosen()
4252
+ });
4253
+ } catch (e) {
4254
+ this.exportOut = null, this.showToast(e.message);
4255
+ }
4256
+ this.render();
4257
+ }, e);
4258
+ }
4259
+ async copyExport() {
4260
+ let e = this.exportOut?.markdown;
4261
+ if (e) {
4262
+ try {
4263
+ await navigator.clipboard.writeText(e), this.copied = !0, clearTimeout(this.copyTimer), this.copyTimer = window.setTimeout(() => {
4264
+ this.copied = !1, this.render();
4265
+ }, 2e3);
4266
+ } catch {
4267
+ this.showToast("The browser did not allow the copy. Select the prompt and copy it.");
4268
+ }
4269
+ this.render();
4270
+ }
4271
+ }
4272
+ downloadExport() {
4273
+ let e = this.exportOut;
4274
+ if (!e) return;
4275
+ let t = URL.createObjectURL(new Blob([e.markdown], { type: "text/markdown" })), n = j("a", {
4276
+ href: t,
4277
+ download: e.filename
4278
+ });
4279
+ this.shadow.append(n), n.click(), n.remove(), setTimeout(() => URL.revokeObjectURL(t), 1e3);
4280
+ }
4281
+ async saveExport() {
4282
+ try {
4283
+ let e = await this.client.call("POST export", {
4284
+ takes: this.exportChosen(),
4285
+ comments: this.exportCommentsChosen(),
4286
+ save: !0
4287
+ });
4288
+ this.exportOut = e, this.showToast(e.path ? `Saved to ${e.path}` : "Saved");
4289
+ } catch (e) {
4290
+ this.showToast(e.message);
4291
+ }
4292
+ this.render();
4293
+ }
4294
+ showToast(e, t) {
4295
+ clearTimeout(this.toastTimer), this.toast = t ? {
4296
+ text: e,
4297
+ undo: t
4298
+ } : { text: e }, this.toastTimer = window.setTimeout(() => {
4299
+ this.toast = null, this.render();
4300
+ }, 4e3), this.render();
4301
+ }
4302
+ layerState() {
4303
+ let e = this.frames();
4304
+ return {
4305
+ pageScheme: this.pageScheme,
4306
+ hover: this.hover,
4307
+ pins: this.pins,
4308
+ comments: this.thread.comments,
4309
+ chosen: this.chosen,
4310
+ openComment: this.openComment,
4311
+ takes: this.thread.takes,
4312
+ shown: this.thread.shown,
4313
+ showing: z(this.thread),
4314
+ alt: this.alt,
4315
+ altMarks: this.altMarks,
4316
+ altMenu: this.altMenu,
4317
+ avoid: this.ui.querySelector(".panel")?.getBoundingClientRect() ?? null,
4318
+ frames: e,
4319
+ barRun: gt(e, this.chosenBar),
4320
+ frameMarks: this.frameMarks,
4321
+ liveMarks: this.liveMarks,
4322
+ busy: !!this.busy,
4323
+ picked: this.picked,
4324
+ asks: this.thread.entries.filter((e) => e.who === "person").map((e) => e.id)
4325
+ };
4326
+ }
4327
+ render() {
4328
+ this.host.dataset.scheme = this.panelScheme(), this.host.dataset.motion = P() ? "reduce" : "full", this.drag || this.snapTimer ? this.stale = !0 : this.renderMover(), this.renderQuick(), this.iconTip.refresh();
4329
+ let e = xn(this);
4330
+ this.extras.replaceChildren(...e ? [e] : []), this.place(), this.layer.draw(), this.goBack();
4331
+ }
4332
+ renderMover() {
4333
+ this.stale = !1;
4334
+ let e = this.ui.querySelector(".body"), t = !e || e.scrollHeight - e.scrollTop - e.clientHeight < 24, n = e?.scrollTop ?? 0, r = this.open && !this.wasOpen;
4335
+ this.wasOpen = this.open;
4336
+ let i = this.shadow.activeElement, a = [
4337
+ ".dock",
4338
+ ".dockmore",
4339
+ ".grip",
4340
+ "[data-menu-button]"
4341
+ ], o = i instanceof HTMLElement && this.mover.contains(i) ? i.dataset.tipKey : void 0, s = i === this.textarea ? "textarea" : o ? `[data-tip-key="${o}"]` : a.find((e) => i?.matches(e) && this.mover.contains(i)) ?? "", { selectionStart: c, selectionEnd: l } = this.textarea, u = this.hidden ? [] : _n(this);
4342
+ this.mover.replaceChildren(...u, this.open ? Sn(this, r) : this.tipEl), s === "textarea" && this.textarea.isConnected ? (this.textarea.focus({ preventScroll: !0 }), this.textarea.setSelectionRange(c, l)) : s && (this.refocusing = !0, this.mover.querySelector(s)?.focus({ preventScroll: !0 }), this.refocusing = !1);
4343
+ let d = this.ui.querySelector(".body");
4344
+ d && (d.scrollTop = t ? d.scrollHeight : n), this.open && this.fitText();
4345
+ }
4346
+ renderQuick() {
4347
+ if (this.quick && (this.open || this.pins.length === 0) && (this.quick = !1), !this.quick) {
4348
+ this.quickWas = !1, this.quickBox.firstChild && this.quickBox.replaceChildren();
4349
+ return;
4350
+ }
4351
+ let e = this.shadow.activeElement, t = e === this.textarea, n = e instanceof HTMLElement && this.quickBox.contains(e) ? e.dataset.tipKey : void 0, { selectionStart: r, selectionEnd: i } = this.textarea, a = Vn(this, !this.quickWas);
4352
+ a.style.width = `${Gt(Q())}px`, this.quickBox.replaceChildren(a), this.quickWas = !0, t ? (this.textarea.focus({ preventScroll: !0 }), this.textarea.setSelectionRange(r, i)) : n && this.quickBox.querySelector(`[data-tip-key="${n}"]`)?.focus({ preventScroll: !0 }), this.fitText(), this.placeQuick();
4353
+ }
4354
+ renderLive() {
4355
+ let e = this.ui.querySelector("[data-live]");
4356
+ if (!e || !this.live) return this.render();
4357
+ e.replaceChildren(document.createTextNode(this.live.text), j("span", {
4358
+ class: "caret",
4359
+ "aria-hidden": "true"
4360
+ }));
4361
+ let t = this.ui.querySelector(".body");
4362
+ t && t.scrollHeight - t.scrollTop - t.clientHeight < 80 && (t.scrollTop = t.scrollHeight);
4363
+ }
4364
+ renderComposerState() {
4365
+ let e = (e, t) => {
4366
+ let n = this.ui.querySelector(e);
4367
+ n && (t ? n.setAttribute("aria-disabled", "true") : n.removeAttribute("aria-disabled"));
4368
+ };
4369
+ e("[data-send]", !this.canSend()), e("[data-pin-comment]", !this.canPin());
4370
+ }
4371
+ destroy() {
4372
+ this.question.close(!1);
4373
+ for (let e of this.cleanups) e();
4374
+ this.stopScheme(), clearTimeout(this.toastTimer), clearTimeout(this.changesTimer), clearTimeout(this.exportTimer), clearTimeout(this.tipTimer), clearTimeout(this.resizeTimer), clearTimeout(this.snapTimer), clearTimeout(this.frameTimer), this.host.remove();
4375
+ }
4376
+ }, er = (e) => `${e.id}:${e.state}`, tr = (e) => e.running ? (e.entries.find((t) => t.id === e.running && t.who === "person")?.steps ?? []).filter((e) => e.take).length : 0;
4377
+ function nr(e) {
4378
+ return typeof e == "number" && Number.isInteger(e) ? Math.max(1, Math.min(3, e)) : 1;
4379
+ }
4380
+ function rr(e) {
4381
+ try {
4382
+ let t = JSON.parse(e ?? "[]");
4383
+ return Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
4384
+ } catch {
4385
+ return [];
4386
+ }
4387
+ }
4388
+ // src/index.ts
4389
+ function ir(e = {}) {
4390
+ return typeof document > "u" || document.querySelector("onsite-overlay") ? null : new $n(e);
4391
+ }
4392
+ typeof document < "u" && !globalThis.__ONSITE_NO_BOOT__ && ir();
4393
+ export { Hn as HOST_TAG, $n as Overlay, ir as mount, Ue as pageContext, Oe as propsOf, Be as snapshot };