@leonidstern/labit 0.6.0 → 0.6.2
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.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +66 -0
- package/README.md +24 -125
- package/api/lab-comments.mjs +16 -2
- package/dist/chunk-DIR2O7SK.mjs +13 -0
- package/dist/chunk-LNYMIFDQ.mjs +49 -0
- package/dist/chunk-X4RYDWNI.mjs +52 -0
- package/dist/chunk-XZUZQFBJ.mjs +65 -0
- package/dist/commands-LAQNMF2X.mjs +240 -0
- package/dist/devserver-KCLPMBNL.mjs +56 -0
- package/dist/flags-PGKWZHJC.mjs +10 -0
- package/dist/local.mjs +1631 -0
- package/dist/mcp-4UPGXLZR.mjs +236 -0
- package/dist/proxy-FLFZV6EI.mjs +74 -0
- package/dist/settings-XLFKONNN.mjs +175 -0
- package/package.json +8 -6
- package/public/_lab/comments.js +30 -3592
- package/public/_lab/favicon.svg +1 -0
- package/public/_lab/lab.css +12 -0
- package/skills/labit/SKILL.md +7 -3
- package/skills/labit/zoom.md +29 -0
- package/lib/dev.mjs +0 -128
- package/lib/devserver.mjs +0 -58
- package/lib/mcp.mjs +0 -207
- package/lib/proxy.mjs +0 -73
- package/local.mjs +0 -1552
package/public/_lab/comments.js
CHANGED
|
@@ -1,1320 +1,32 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
--_accent: var(--lab-accent, #141414); --_accent-fg: var(--lab-accent-fg, #fff);
|
|
8
|
-
|
|
9
|
-
/* Washes of black (white in dark mode), four steps: soft, hover, line, muted, as lab.css. */
|
|
10
|
-
--_soft: var(--lab-soft, rgba(0,0,0,.05)); --_hover: var(--lab-hover, rgba(0,0,0,.10)); --_line: var(--lab-line, rgba(0,0,0,.15)); --_edge: var(--lab-edge, #c7c7cc); --_muted: var(--lab-muted, rgba(0,0,0,.50));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
button:focus-visible { outline: 2px solid var(--_accent); outline-offset: 2px; }
|
|
27
|
-
.layer { position: absolute; top: 0; left: 0; width: 0; height: 0; }
|
|
28
|
-
.pin { position: absolute; width: 28px; height: 28px; margin: -28px 0 0 0; border-radius: 14px 14px 14px 2px;
|
|
29
|
-
background: var(--_bg); border: 0; box-shadow: 0 0 0 1px var(--_edge), 0 2px 8px rgba(0,0,0,.16);
|
|
30
|
-
display: grid; place-items: center; cursor: pointer; padding: 0; color: var(--_fg); font-size: 12px; font-weight: 500;
|
|
31
|
-
font-variant-numeric: tabular-nums; letter-spacing: 0; transform-origin: 0 100%;
|
|
32
|
-
transition: transform .16s var(--_ease), box-shadow .16s var(--_ease), opacity .16s; }
|
|
33
|
-
/* A 1 px edge in the text colour (dark on light pins, light in dark mode) so a pin shows on white and black alike;
|
|
34
|
-
the one you point at or have open gets a green edge. */
|
|
35
|
-
button.pin:hover, button.pin.open { transform: scale(1.08); box-shadow: 0 0 0 1.5px rgb(36, 160, 70), 0 4px 14px rgba(0,0,0,.2); }
|
|
36
|
-
button.pin:active { transform: scale(.96); }
|
|
37
|
-
.pin.in { animation: lab-pin .26s var(--_ease); }
|
|
38
|
-
/* A new comment lands with one faint halo from its pin. */
|
|
39
|
-
button.pin.in::before { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
|
|
40
|
-
animation: lab-halo .9s cubic-bezier(.2, .7, .3, 1) forwards; }
|
|
41
|
-
.pin.resolved { color: var(--_muted); }
|
|
42
|
-
/* Statuses. A go pin says "go": green in a green outline when placed, the turning stroke while the agent is on it,
|
|
43
|
-
white on green once done (a \u2713 is only ever a done comment). A comment pin: your initial, the stroke, then a green tick. */
|
|
44
|
-
button.pin.go { background: var(--_bg); color: rgb(36, 160, 70); font-size: 11px; font-weight: 600; letter-spacing: .006em;
|
|
45
|
-
box-shadow: inset 0 0 0 1.5px rgb(36, 160, 70), 0 2px 8px rgba(0,0,0,.16); }
|
|
46
|
-
button.pin.go.done { background: rgb(36, 160, 70); color: #fff; box-shadow: 0 0 0 .5px color-mix(in srgb, var(--_fg) 22%, transparent), 0 2px 8px rgba(0,0,0,.16); }
|
|
47
|
-
button.pin.done:not(.go) { color: rgb(36, 160, 70); }
|
|
48
|
-
.pin.moved { opacity: .5; scale: .8; }
|
|
49
|
-
button.pin.moved:hover, button.pin.moved.open { opacity: 1; }
|
|
50
|
-
.pin.grab { touch-action: none; }
|
|
51
|
-
button.pin.dragging { cursor: grabbing; transform: scale(1.1); opacity: 1; box-shadow: 0 0 0 .5px color-mix(in srgb, var(--_fg) 30%, transparent), 0 8px 20px rgba(0,0,0,.22); }
|
|
52
|
-
.zone { position: absolute; background: none;
|
|
53
|
-
border-radius: var(--_radius); pointer-events: none; }
|
|
54
|
-
.zone svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
|
|
55
|
-
.zone rect { fill: none; stroke-linecap: round; stroke-dasharray: 0 4; rx: var(--lab-radius, 12px); ry: var(--lab-radius, 12px); }
|
|
56
|
-
/* Green dots, the same green as quoted words, with no dark ring under them. */
|
|
57
|
-
.zone rect.ring { display: none; }
|
|
58
|
-
.zone rect.dots { stroke: rgb(52, 199, 89); stroke-width: 1.5; } /* 1.5 px round dots, 4 px apart */
|
|
59
|
-
.zone.live { left: 0; top: 0; will-change: transform, width, height; animation: lab-fade .12s ease-out; }
|
|
60
|
-
/* The agent is on it: a green stroke runs round the pin's own teardrop outline. The ring (a still 2 px teardrop mask)
|
|
61
|
-
holds a conic gradient that turns by transform, so the screen turns it without redrawing: 30 such pins cost ~1 ms
|
|
62
|
-
a second, against ~125 ms when the gradient's angle itself was animated. */
|
|
63
|
-
.pin .ring { position: absolute; inset: -4px; border-radius: 18px 18px 18px 6px; padding: 2px; overflow: hidden; pointer-events: none;
|
|
64
|
-
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
|
|
65
|
-
mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); }
|
|
66
|
-
.ring::before { content: ''; position: absolute; inset: -50%; will-change: transform;
|
|
67
|
-
background: conic-gradient(rgb(52, 199, 89) 0 28%, rgba(52, 199, 89, .22) 28% 100%); animation: lab-turn 1.2s linear infinite; }
|
|
68
|
-
@keyframes lab-turn { to { transform: rotate(360deg); } }
|
|
69
|
-
/* The drawn pointer: your pin, following the mouse (it moves without a transition; only its look eases). */
|
|
70
|
-
.ptr { position: fixed; left: 0; top: 0; width: 28px; height: 28px; border-radius: 14px 14px 14px 2px; corner-shape: round;
|
|
71
|
-
background: var(--_bg); box-shadow: 0 0 0 .5px color-mix(in srgb, var(--_fg) 30%, transparent), 0 2px 6px rgba(0,0,0,.18);
|
|
72
|
-
display: grid; place-items: center; pointer-events: none; z-index: 2147483647; opacity: 0; will-change: transform;
|
|
73
|
-
transition: opacity .12s ease-out, background-color .16s ease-out; }
|
|
74
|
-
.ptr.show { opacity: 1; }
|
|
75
|
-
.ptr span { grid-area: 1 / 1; font-size: 12px; letter-spacing: 0; font-weight: 600; line-height: 1; transition: opacity .16s ease-out, transform .16s ease-out; }
|
|
76
|
-
.ptr .tick { opacity: 0; transform: scale(.5); color: #fff; font-size: 11px; letter-spacing: .006em; }
|
|
77
|
-
.ptr.go { background: rgb(36, 160, 70); }
|
|
78
|
-
.ptr.go .ini { opacity: 0; transform: scale(.5); }
|
|
79
|
-
.ptr.go .tick { opacity: 1; transform: none; }
|
|
80
|
-
.pin.new::after { content: ''; position: absolute; top: -4px; right: -4px; width: 9px; height: 9px; border-radius: 50%;
|
|
81
|
-
background: var(--_fg); box-shadow: 0 0 0 2px var(--_bg); }
|
|
82
|
-
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--_accent); margin: 0 6px 1px 0; }
|
|
83
|
-
.card { position: absolute; width: 320px; max-width: calc(100vw - 24px); background: var(--_bg); border-radius: var(--_radius);
|
|
84
|
-
box-shadow: var(--_shadow); padding: 12px 14px 14px; transform-origin: 14px 0; z-index: 1;
|
|
85
|
-
display: flex; flex-direction: column; max-height: min(460px, 62vh); }
|
|
86
|
-
/* A long thread scrolls inside the card, which keeps one size; the step buttons and the reply box stay put. */
|
|
87
|
-
.card > .body { flex: 0 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin-right: -8px; padding-right: 8px; }
|
|
88
|
-
.card > .foot { flex: none; }
|
|
89
|
-
.card.in, .float.in { animation: lab-in .18s var(--_ease); }
|
|
90
|
-
.card.out, .float.out { animation: lab-out .14s ease-in forwards; pointer-events: none; }
|
|
91
|
-
.item { display: grid; row-gap: 3px; }
|
|
92
|
-
.item + .item { margin-top: 14px; }
|
|
93
|
-
.msg.item { display: block; } .msg.item + .msg.item { margin-top: 0; }
|
|
94
|
-
.meta { display: flex; align-items: baseline; gap: .5em; font-size: 12px; color: var(--_muted); margin: 0;
|
|
95
|
-
white-space: nowrap; letter-spacing: 0; font-variant-numeric: tabular-nums; }
|
|
96
|
-
.meta b { font-weight: 500; font-size: 13px; letter-spacing: -.006em; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
97
|
-
.meta .dot { flex: none; align-self: center; margin: 0; }
|
|
98
|
-
.meta .ago { white-space: nowrap; }
|
|
99
|
-
.text { white-space: pre-wrap; overflow-wrap: anywhere; text-wrap: pretty; }
|
|
100
|
-
.row { display: flex; gap: 12px; justify-content: flex-start; align-items: center; margin-top: 8px; }
|
|
101
|
-
/* A thread's reopen / resolve / delete: small, on the right, out of the reading flow. */
|
|
102
|
-
.card .row:not(.nav) { justify-content: flex-end; gap: 10px; } .card .row:not(.nav) button.btn { font-size: 12px; letter-spacing: 0; }
|
|
103
|
-
button.btn { border: 0; padding: 2px 0; cursor: pointer; background: none; color: var(--_muted); font-size: 12px;
|
|
104
|
-
letter-spacing: 0; border-radius: var(--_r-s); transition: color .12s; }
|
|
105
|
-
button.btn:hover { color: var(--_fg); }
|
|
106
|
-
button.btn.danger, button.btn.danger:hover { color: #e5484d; }
|
|
107
|
-
.row .ask { white-space: nowrap; color: var(--_fg); font-size: 12px; letter-spacing: 0; padding: 2px 0; animation: lab-fade .12s ease-out; }
|
|
108
|
-
.float { position: absolute; width: 320px; max-width: calc(100vw - 24px); transform-origin: 0 20px; z-index: 1; }
|
|
109
|
-
.card .composer { margin-top: 6px; } /* close under resolve / delete */
|
|
110
|
-
.card > .body > .row:not(.nav) { margin-right: 7px; } /* resolve / delete end where the send button does */
|
|
111
|
-
.box { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "text send"; align-items: center; column-gap: 8px;
|
|
112
|
-
border-radius: var(--_radius); padding: 7px 7px 7px 14px; margin: 0; transition: box-shadow .15s;
|
|
113
|
-
/* One box for the chat, threads and new comments: its look comes only from these two, which a place sets on
|
|
114
|
-
its container (never by restyling the box, idle or typing), so the three can't drift apart (Leo, 15 Nov). */
|
|
115
|
-
background: var(--_box-bg, var(--_soft)); box-shadow: var(--_box-edge, none); }
|
|
116
|
-
/* The new comment box on a computer floats over the page: the page's colour, the pins' 1 px edge in the text colour
|
|
117
|
-
(it shows on white and black pages alike) and a soft shadow. */
|
|
118
|
-
.float { --_box-bg: var(--_bg); --_box-edge: 0 0 0 1px var(--_edge), 0 1px 2px rgba(0,0,0,.06), 0 8px 26px rgba(0,0,0,.14); }
|
|
119
|
-
/* Same top and right padding open or closed: the text and the arrow's column stay put while the box grows. */
|
|
120
|
-
.box.open { grid-template-areas: "text text" "line line" "who send"; row-gap: 8px; padding: 7px 7px 8px 14px; }
|
|
121
|
-
/* One line of text is exactly as tall as the send button (20 + 2 + 2 = 24), so the text and the button share one middle. */
|
|
122
|
-
.box textarea { grid-area: text; width: 100%; border: 0; background: none; padding: 2px 0; line-height: 20px; margin: 0; resize: none;
|
|
123
|
-
min-height: 0; max-height: 200px; overflow-y: auto; outline: none; display: block; }
|
|
124
|
-
.box textarea::placeholder, .who input::placeholder { color: var(--_muted); opacity: 1; }
|
|
125
|
-
.line { grid-area: line; height: 0; border-top: var(--_hair); margin: 0 -7px 0 -14px; display: none; }
|
|
126
|
-
.who { grid-area: who; display: none; align-items: baseline; gap: 4px; min-width: 0; font-size: 13px; color: var(--_muted); letter-spacing: -.006em; }
|
|
127
|
-
.who * { font-size: 13px; letter-spacing: -.006em; }
|
|
128
|
-
.who span { color: var(--_muted); }
|
|
129
|
-
.who input { flex: 1; min-width: 0; border: 0; background: none; padding: 0; margin: 0; outline: none; color: var(--_muted); text-overflow: ellipsis; }
|
|
130
|
-
.who input:focus { color: var(--_fg); }
|
|
131
|
-
.box.open .line { display: block; animation: lab-fade .16s ease-out; }
|
|
132
|
-
.box.open .who { display: flex; animation: lab-fade .16s ease-out; }
|
|
133
|
-
/* One line once your name is known: text, a quiet "as <name>" (still editable) and the arrow, side by side.
|
|
134
|
-
The text grows upward; the name and arrow stay on its last line. Only a first comment, with no name yet, opens
|
|
135
|
-
the second row to ask for it. */
|
|
136
|
-
.box.one, .box.one.open { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "text who send"; align-items: end; row-gap: 0; padding: 7px 7px 7px 14px; }
|
|
137
|
-
.box.one .line { display: none !important; }
|
|
138
|
-
.box.one .who { align-self: end; line-height: 20px; padding-bottom: 2px; max-width: 40%; } /* the text's last line box, so they share a line */
|
|
139
|
-
.box.one .who input { flex: none; field-sizing: content; min-width: 2ch; max-width: 9em; }
|
|
140
|
-
.send { grid-area: send; width: 24px; height: 24px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
|
|
141
|
-
background: var(--_hover); color: var(--_muted); display: grid; place-items: center; transition: background .15s, color .15s, transform .15s var(--_ease); }
|
|
142
|
-
.send.ready:hover { transform: scale(1.06); }
|
|
143
|
-
.send.ready:active { transform: scale(.94); }
|
|
144
|
-
.send.ready { background: var(--_accent); color: var(--_accent-fg); }
|
|
145
|
-
/* The send sign: a paper plane, one filled shape cut with clip-path (crisp at any size, no joins); it flies off on send. */
|
|
146
|
-
.send .arr { display: block; position: relative; left: -1px; width: 12px; height: 11px; background: currentColor; clip-path: polygon(0 42%, 100% 0, 66% 100%, 46% 60%); }
|
|
147
|
-
.send * { color: inherit; }
|
|
148
|
-
.error { color: #e5484d; font-size: 12px; padding: 6px 8px 0; letter-spacing: 0; }
|
|
149
|
-
.error:empty { display: none; }
|
|
150
|
-
.error.wait { color: var(--_muted); }
|
|
151
|
-
.bar { position: fixed; right: 16px; bottom: 16px; display: flex; gap: 8px; align-items: center; }
|
|
152
|
-
.bar button { border: 0; border-radius: var(--_radius); padding: 9px 14px; cursor: pointer; background: var(--_bg); color: var(--_fg);
|
|
153
|
-
box-shadow: var(--_shadow); font-size: 13px; font-weight: 500; display: inline-flex; gap: 8px; align-items: center;
|
|
154
|
-
letter-spacing: -.006em; font-variant-numeric: tabular-nums; white-space: nowrap; transition: color .15s, transform .15s var(--_ease); }
|
|
155
|
-
.bar button:active { transform: scale(.97); }
|
|
156
|
-
/* The list and the chat: a header, a part that scrolls, and (the chat) a box at the bottom that doesn't. */
|
|
157
|
-
.list { position: fixed; right: 16px; bottom: 66px; width: min(340px, calc(100vw - 32px)); max-height: min(60vh, 460px); overflow: hidden;
|
|
158
|
-
display: flex; flex-direction: column; background: var(--_bg); color: var(--_fg); border-radius: var(--_radius); box-shadow: var(--_shadow); font-size: 13px; letter-spacing: -.006em; }
|
|
159
|
-
.list .tabs { display: flex; flex-wrap: wrap; gap: 2px; flex: none; padding: 12px 8px 6px; }
|
|
160
|
-
.list .items, .msgs { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
|
|
161
|
-
.list .items { padding: 0 6px 6px; }
|
|
162
|
-
.list .tabs button { border: 0; border-radius: var(--_r-s); padding: 4px 8px; white-space: nowrap; background: none; color: var(--_muted); cursor: pointer; font: inherit; }
|
|
163
|
-
.list .tabs button.on { background: var(--_fg); color: var(--_bg); }
|
|
164
|
-
.list .tabs .hold { margin-left: auto; }
|
|
165
|
-
.list .it { display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit; padding: 7px 8px; border-radius: var(--_r-s); cursor: pointer; font: inherit; }
|
|
166
|
-
.list .it:hover, .list .it.cur { background: var(--_hover); }
|
|
167
|
-
.list .it { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } /* one line per pin; the rest is in its thread */
|
|
168
|
-
.list .it span, .list .none { color: var(--_muted); }
|
|
169
|
-
.list .it .tag { display: inline-block; padding: 0 7px; border-radius: var(--_r-s); background: var(--_accent); color: var(--_accent-fg);
|
|
170
|
-
font-size: 12px; letter-spacing: 0; font-weight: 600; line-height: 18px; vertical-align: 1px; white-space: nowrap; }
|
|
171
|
-
.list .none { padding: 8px; }
|
|
172
|
-
/* Thin scrollbars inside the dialogs (chat, threads, the list), like macOS overlay ones, on a clear track. */
|
|
173
|
-
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--_fg) 24%, transparent) transparent; }
|
|
174
|
-
@supports not (scrollbar-width: thin) {
|
|
175
|
-
::-webkit-scrollbar { width: 6px; height: 6px; }
|
|
176
|
-
::-webkit-scrollbar-track { background: transparent; }
|
|
177
|
-
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--_fg) 24%, transparent); border-radius: 999px; }
|
|
178
|
-
}
|
|
179
|
-
.list .group { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--_muted); padding: 10px 8px 2px; }
|
|
180
|
-
.pin.held { border: 1.5px dashed var(--_muted); opacity: .85; }
|
|
181
|
-
/* Close: a round, quiet button with a drawn cross (not the \u2715 character), darker on hover. */
|
|
182
|
-
.list .tabs .show-done { color: var(--_muted); }
|
|
183
|
-
.chatwin .tabs b { display: none; } /* no "chat" title: the window speaks for itself */
|
|
184
|
-
.list .tabs .x { margin-left: auto; flex: none; width: 26px; height: 26px; padding: 0; border-radius: 50%; display: grid; place-items: center;
|
|
185
|
-
font-size: 0; color: var(--_muted); background: transparent; }
|
|
186
|
-
/* The cross is drawn with CSS: two thin bars, no picture. */
|
|
187
|
-
.list .tabs .x::before, .list .tabs .x::after { content: ''; grid-area: 1 / 1; width: 12px; height: 1.6px; border-radius: 1px; background: currentColor; transform: rotate(45deg); }
|
|
188
|
-
.list .tabs .x::after { transform: rotate(-45deg); }
|
|
189
|
-
.list .tabs .x:hover { color: var(--_fg); } /* hover: the cross darkens, nothing drawn behind it */
|
|
190
|
-
.list .tabs .x:focus-visible { outline: 2px solid var(--_accent); outline-offset: 1px; }
|
|
191
|
-
.chatwin .chat { flex: none; background: var(--_bg); padding: 6px 6px 8px; }
|
|
192
|
-
.chatwin .replying { flex: none; }
|
|
193
|
-
.chatwin .tabs b { padding: 4px 8px; font-weight: 600; margin-right: auto; }
|
|
194
|
-
.msgs { display: flex; flex-direction: column; gap: 8px; padding: 4px 10px 8px; overflow-x: hidden; }
|
|
195
|
-
.msgs > :first-child { margin-top: auto; } /* a short conversation sits by the box, like a chat */
|
|
196
|
-
/* Something just sent eases in; the arrow flies off and comes back. */
|
|
197
|
-
.fresh { animation: lab-rise .2s var(--_ease); }
|
|
198
|
-
.send.sent .arr { animation: lab-fly .32s var(--_ease); }
|
|
199
|
-
@keyframes lab-rise { from { opacity: 0; transform: translateY(6px); } }
|
|
200
|
-
@keyframes lab-fly { 45% { transform: translate(9px, -9px) scale(.6); opacity: 0; } 46% { transform: translate(-7px, 7px) scale(.6); opacity: 0; } }
|
|
201
|
-
.msg { max-width: 85%; padding: 7px 10px; border-radius: var(--_radius); background: var(--_soft); align-self: flex-start; }
|
|
202
|
-
.msg.mine { align-self: flex-end; background: color-mix(in srgb, rgb(52, 199, 89) 15%, var(--_bg)); color: var(--_fg); } /* yours: soft green, dark text */
|
|
203
|
-
.msg b { display: block; font-size: 12px; letter-spacing: 0; font-weight: 600; opacity: .7; margin-bottom: 1px; }
|
|
204
|
-
/* Each agent's messages in its own brand colour: the name in it, the bubble a soft wash of it (Leo, 15 Nov). */
|
|
205
|
-
.msg[data-agent=claude] { --_brand: #d97757; } .msg[data-agent=codex] { --_brand: #10a37f; } .msg[data-agent=cursor] { --_brand: #8a8a8e; }
|
|
206
|
-
.msg[data-agent=gemini] { --_brand: #4285f4; } .msg[data-agent=copilot] { --_brand: #8957e5; } .msg[data-agent=amp] { --_brand: #f34e3f; }
|
|
207
|
-
.msg[data-agent=opencode] { --_brand: #8a8a8e; }
|
|
208
|
-
.msg[data-agent] { background: color-mix(in srgb, var(--_brand) 11%, var(--_bg)); }
|
|
209
|
-
.msg[data-agent] > b { color: var(--_brand); opacity: 1; }
|
|
210
|
-
.msg.mine b { display: none; }
|
|
211
|
-
.msg { position: relative; } .mark { font-weight: 400; font-size: 11px; letter-spacing: .006em; color: var(--_muted); margin-left: 6px; white-space: nowrap; } .mark.done { color: rgb(36, 160, 70); font-weight: 600; font-size: 12px; letter-spacing: 0; } /* a small green tick, as the ticks on messages */
|
|
212
|
-
.msg .quote { display: block; border-left: 2px solid rgb(52, 199, 89); padding: 1px 0 1px 8px; margin: 3px 0 5px; font-size: 12px; letter-spacing: 0; line-height: 1.35;
|
|
213
|
-
color: var(--_muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
|
|
214
|
-
.msg .quote b { display: block; font-size: 12px; letter-spacing: 0; font-weight: 600; color: rgb(36, 160, 70); opacity: 1; margin: 0; } .mine .mark { color: inherit; opacity: .7; } a.link { color: inherit; text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; } .msg.to { box-shadow: 0 0 0 2px var(--_accent); }
|
|
215
|
-
.msg .p { display: block; white-space: pre-wrap; overflow-wrap: anywhere; text-wrap: pretty; } /* no lone last word */ .msg .p.gap { margin-top: 6px; }
|
|
216
|
-
.msg .p.li { padding-left: 14px; text-indent: -14px; } .msg .p.li .mk { display: inline-block; width: 14px; text-indent: 0; opacity: .6; }
|
|
217
|
-
.msg i { display: block; font-style: normal; font-size: 12px; letter-spacing: 0; opacity: .7; margin-bottom: 1px; }
|
|
218
|
-
.msg b, .msg i { color: inherit; }
|
|
219
|
-
.msg .stamp { text-indent: 0; color: inherit; position: absolute; right: 10px; bottom: 6px; font-size: 10px; letter-spacing: .012em; line-height: 1; opacity: .55; font-variant-numeric: tabular-nums; }
|
|
220
|
-
.msg .stamp-room { text-indent: 0; visibility: hidden; display: inline-block; margin-left: 10px; font-size: 10px; letter-spacing: .012em; line-height: 1; height: 10px; white-space: nowrap; }
|
|
221
|
-
.msg .stamp-room * { font-size: inherit; }
|
|
222
|
-
.msg .tick { color: inherit; margin-left: 4px; letter-spacing: -.34em; font-size: 10px; } /* \u2713 drawn as tall as the time's digits */
|
|
223
|
-
.msg .tick.got { font-weight: 600; }
|
|
224
|
-
/* Your message the agent is on: the pin's turning green ring, small, by its time; answered: a green \u2713. */
|
|
225
|
-
.msg .stamp:is(.busy, .ans) { opacity: 1; } .msg .stamp:is(.busy, .ans) .tm { opacity: .55; }
|
|
226
|
-
.msg .stamp .tm { font-size: inherit; line-height: inherit; color: inherit; } /* every element gets 14 px by default: the time keeps the stamp's 10 */
|
|
227
|
-
.msg :is(.stamp, .stamp-room) .ring { position: relative; display: inline-block; width: 9px; height: 9px; margin-left: 5px; vertical-align: -1px; border-radius: 50%; overflow: hidden;
|
|
228
|
-
-webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 1.6px), #000 calc(100% - 1.5px));
|
|
229
|
-
mask: radial-gradient(farthest-side, transparent calc(100% - 1.6px), #000 calc(100% - 1.5px)); }
|
|
230
|
-
.msg .stamp.ans .tick { color: rgb(36, 160, 70); letter-spacing: 0; font-weight: 600; }
|
|
231
|
-
/* One slot for the mark, whatever it is (\u2713, \u2713\u2713, the turning ring, the green \u2713): 12 px wide after a 4 px gap, so the
|
|
232
|
-
time doesn't shift when one turns into another (Leo, 15 Nov: it flicked as \u2713 became the ring). */
|
|
233
|
-
.msg :is(.stamp, .stamp-room) .tick { display: inline-block; width: 12px; height: 10px; line-height: 10px; text-align: center; margin-left: 4px; vertical-align: top; }
|
|
234
|
-
.msg :is(.stamp, .stamp-room) .ring { margin: .5px 1.5px 0 5.5px; vertical-align: top; } /* the same 10 px tall as a \u2713, so the bubble keeps its height */
|
|
235
|
-
.msg .stamp { height: 10px; }
|
|
236
|
-
.replying { display: flex; gap: 6px; align-items: center; font-size: 12px; letter-spacing: 0; color: var(--_muted); padding: 2px 6px; }
|
|
237
|
-
.replying button { border: 0; background: none; color: inherit; cursor: pointer; margin-left: auto; font: inherit; }
|
|
238
|
-
.bar button * { color: inherit; font-weight: inherit; }
|
|
239
|
-
.bar .toggle:not(.secondary)::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--_accent); }
|
|
240
|
-
.bar button.secondary { color: var(--_muted); }
|
|
241
|
-
.bar button.secondary.has-new { color: var(--_fg); font-weight: 600; }
|
|
242
|
-
.bar button.go-btn.on { color: #fff; background: rgb(36, 160, 70); }
|
|
243
|
-
.bar .new-prev, .bar .new-next { padding: 9px 11px; font-size: 15px; letter-spacing: -.016em; line-height: 1; color: var(--_fg); }
|
|
244
|
-
.bar .list-btn, .bar .done-btn { font-variant-numeric: tabular-nums; min-width: 4.6em; justify-content: center; }
|
|
245
|
-
.bar button.quiet { opacity: .45; cursor: default; box-shadow: var(--_shadow); }
|
|
246
|
-
.bar button.go-btn.on kbd { color: #fff !important; }
|
|
247
|
-
.newline { display: flex; align-items: center; gap: 8px; font-size: 12px; letter-spacing: 0; font-weight: 500; color: var(--_muted); }
|
|
248
|
-
.newline::before, .newline::after { content: ''; flex: 1; height: 1px; background: currentColor; opacity: .35; }
|
|
249
|
-
/* The left side: who's listening, then copy link; the right side is the bar. */
|
|
250
|
-
.left { position: fixed; left: 16px; bottom: 16px; display: flex; gap: 8px; align-items: center; }
|
|
251
|
-
.left .copy-all { border: 0; border-radius: var(--_radius); padding: 9px 14px; cursor: pointer; background: var(--_bg); color: var(--_muted);
|
|
252
|
-
box-shadow: var(--_shadow); font: inherit; font-size: 13px; letter-spacing: -.006em; font-weight: 500; white-space: nowrap; }
|
|
253
|
-
.listener { display: inline-flex; gap: 6px; align-items: center; padding: 9px 14px; border-radius: var(--_radius);
|
|
254
|
-
background: var(--_bg); color: var(--_fg); box-shadow: var(--_shadow); font-size: 13px; letter-spacing: -.006em; text-decoration: none; white-space: nowrap; }
|
|
255
|
-
.listener::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--_accent); margin-right: 2px; }
|
|
256
|
-
.listener span { color: var(--_muted); }
|
|
257
|
-
.listener.idle::before { background: var(--_muted); opacity: .5; }
|
|
258
|
-
/* Working: the dot turns green and sends out a soft ring, like a "live" light. */
|
|
259
|
-
/* The ping is a copy of the dot that grows and fades (transform and opacity only), so only it is redrawn. A growing
|
|
260
|
-
shadow repainted the whole layer with every pin on it, each frame: ~170 ms a second on a page with 40 pins. */
|
|
261
|
-
.listener { position: relative; }
|
|
262
|
-
.listener.working::before { background: rgb(36, 160, 70); }
|
|
263
|
-
.listener.working::after { content: ''; position: absolute; left: 14px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px;
|
|
264
|
-
border-radius: 50%; corner-shape: round; background: rgb(52, 199, 89); pointer-events: none; will-change: transform, opacity; animation: lab-ping 1.6s cubic-bezier(0, 0, .2, 1) infinite; }
|
|
265
|
-
@keyframes lab-ping { 0% { transform: scale(1); opacity: .55; } 80%, 100% { transform: scale(2.7); opacity: 0; } }
|
|
266
|
-
.listener { cursor: default; } /* a plain arrow, also where a tap copies the resume command */
|
|
267
|
-
/* Letter spacing follows the size, as Apple's SF text does: looser below 12 px, tighter above (11 +.006em,
|
|
268
|
-
13 \u2212.006, 15 \u2212.016, 17 \u2212.025). Uppercase labels and the \u2713\u2713 overlap keep their own. */
|
|
269
|
-
/* Keys whisper: a small grey letter, no chip; a bit clearer while the pointer is on the bar. */
|
|
270
|
-
kbd { font-size: 10px; letter-spacing: .012em; line-height: 17px; min-width: 0; padding: 0 1px; text-align: center; background: none;
|
|
271
|
-
color: var(--_muted) !important; opacity: .45; transition: opacity .15s; }
|
|
272
|
-
.bar:hover kbd { opacity: .75; }
|
|
273
|
-
.bar button kbd { margin-left: -4px; } /* the hint sits close to its word: chat (c) */
|
|
274
|
-
.bar button.go-btn kbd { font-size: inherit; line-height: inherit; opacity: 1; margin-left: 0; } /* (1/2/3) reads like (c)hat and ne(w) */
|
|
275
|
-
/* One bar of segments, a hairline between them; the less used ones in the \u22EF menu above it (phones too: same bar, bigger to tap). */
|
|
276
|
-
@media all {
|
|
277
|
-
.bar { gap: 0; background: var(--_bg); border-radius: var(--_radius); box-shadow: var(--_shadow); overflow: hidden; }
|
|
278
|
-
.bar > button { box-shadow: inset .5px 0 0 var(--_line); border-radius: 0; background: none; padding: 8px 12px; gap: 6px; }
|
|
279
|
-
.bar > button.first { box-shadow: none; }
|
|
280
|
-
.bar > button:not(:disabled):hover { background: var(--_hover); }
|
|
281
|
-
.bar > button:active { transform: none; background: var(--_hover); }
|
|
282
|
-
.bar > button.quiet { opacity: 1; box-shadow: inset .5px 0 0 var(--_line); color: var(--_muted); }
|
|
283
|
-
.bar > button.quiet.first { box-shadow: none; }
|
|
284
|
-
.bar .list-btn, .bar .done-btn { min-width: 0; }
|
|
285
|
-
.bar .mn { color: var(--_muted); font-weight: 400; }
|
|
286
|
-
/* Words stay grey (as the bar's buttons were); the count is the one thing in the text colour: a plain number. */
|
|
287
|
-
.bar > button.secondary, .bar > button.secondary.has-new { color: var(--_muted); font-weight: 500; }
|
|
288
|
-
.bar .chat-btn, .bar .list-btn { align-items: baseline; } /* the number sits on the word's line */
|
|
289
|
-
.bar .cnt { font-size: 12px; letter-spacing: 0; font-weight: 400; line-height: 16px; text-align: center; background: none; color: var(--_fg); font-variant-numeric: tabular-nums; }
|
|
290
|
-
.bar .cnt.zero { color: var(--_muted); }
|
|
291
|
-
.bar button.go-btn.on { background: none; color: var(--_fg); }
|
|
292
|
-
.bar button.go-btn.on kbd { color: var(--_muted) !important; }
|
|
293
|
-
.gp { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 11px 11px 11px 2px; font-size: 10px; letter-spacing: .012em; font-weight: 600;
|
|
294
|
-
color: rgb(36, 160, 70); box-shadow: inset 0 0 0 1.25px rgb(36, 160, 70); transition: background-color .2s, color .2s; }
|
|
295
|
-
.go-btn.on .gp { background: rgb(36, 160, 70); color: #fff; }
|
|
296
|
-
/* 1, comment: your own pin, small: your initial in a white pin with the pins' edge. */
|
|
297
|
-
.go-btn:not(.on):not(.cursor) .gp { color: var(--_fg); background: var(--_bg); box-shadow: inset 0 0 0 1px var(--_edge); font-size: 10px; letter-spacing: .012em; }
|
|
298
|
-
/* 3, cursor: the switch is the same pin in grey, saying "off" (regular, a touch bigger than go's bold). */
|
|
299
|
-
.go-btn.cursor .gp { box-shadow: inset 0 0 0 1.25px var(--_muted); color: transparent; position: relative; }
|
|
300
|
-
.go-btn.cursor .gp::after { content: 'off'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--_muted);
|
|
301
|
-
font-size: 10px; font-weight: 400; letter-spacing: .012em; }
|
|
302
|
-
.more { font-size: 15px !important; letter-spacing: .05em; }
|
|
303
|
-
.more-menu { position: fixed; right: 16px; bottom: 60px; display: grid; min-width: 180px; padding: 4px; background: var(--_bg);
|
|
304
|
-
border-radius: var(--_radius); box-shadow: var(--_shadow); animation: lab-fade .12s ease-out; }
|
|
305
|
-
.more-menu[hidden] { display: none; }
|
|
306
|
-
.more-menu button { border: 0; background: none; text-align: left; font: inherit; font-size: 13px; letter-spacing: -.006em; color: var(--_fg); padding: 7px 10px;
|
|
307
|
-
border-radius: var(--_r-s); cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 12px; white-space: nowrap; }
|
|
308
|
-
.more-menu button:hover:not(:disabled) { background: var(--_hover); }
|
|
309
|
-
.more-menu button:disabled { color: var(--_muted); cursor: default; }
|
|
310
|
-
.more-menu button[hidden] { display: none; }
|
|
311
|
-
.more-menu kbd { margin: 0; }
|
|
312
|
-
}
|
|
313
|
-
kbd::before { content: '('; } kbd::after { content: ')'; } /* read as a hint: chat (c) */
|
|
314
|
-
.hint { position: fixed; left: 50%; bottom: 64px; transform: translateX(-50%); background: var(--_bg); color: var(--_muted);
|
|
315
|
-
box-shadow: var(--_shadow); padding: 8px 14px; border-radius: var(--_radius); font-size: 13px; pointer-events: none; white-space: nowrap;
|
|
316
|
-
letter-spacing: -.006em; animation: lab-fade .2s ease-out; }
|
|
317
|
-
/* 16px fields keep iOS from zooming the page when one is focused. */
|
|
318
|
-
@media (pointer: coarse) { .box textarea, .who input { font-size: 16px; letter-spacing: -.019em; } kbd { display: none; }
|
|
319
|
-
.box textarea { line-height: 22px; padding: 7px 0; } /* phones: 22 + 7 + 7 = 36, the send button's size */
|
|
320
|
-
.box.one .who { line-height: 22px; padding-bottom: 7px; } }
|
|
321
|
-
@keyframes lab-fade { from { opacity: 0; } }
|
|
322
|
-
/* Movement only: a page in the background can stall an animation, and a card stalled mid-fade showed the page through it. */
|
|
323
|
-
@keyframes lab-in { from { transform: translateY(4px) scale(.98); } }
|
|
324
|
-
@keyframes lab-sheet-in { from { transform: translateY(100%); } }
|
|
325
|
-
@keyframes lab-sheet-out { to { transform: translateY(100%); } }
|
|
326
|
-
@keyframes lab-out { to { opacity: 0; transform: translateY(2px) scale(.985); } }
|
|
327
|
-
/* Continuous (Apple-style) corners where the browser draws them; plain rounding elsewhere. */
|
|
328
|
-
/* Apple's continuous corners (squircle) where the browser draws them (Safari 26, Chrome): the same three sizes, a
|
|
329
|
-
smooth curve instead of a circle arc (a squircle needs about 1.8 times the radius to look the same size).
|
|
330
|
-
Circles and the pin's teardrop stay as they are. */
|
|
331
|
-
@supports (corner-shape: squircle) {
|
|
332
|
-
:host { --_radius: calc(var(--lab-radius, 12px) * 1.8); --_r-s: 11px; }
|
|
333
|
-
*, *::before, *::after { corner-shape: squircle; }
|
|
334
|
-
.pin, .pin .ring, .pin.new::after, .dot, .send, .list .tabs .x, .bar .toggle:not(.secondary)::before,
|
|
335
|
-
.listener::before, .list-btn[data-agent]::before, .chat-btn[data-agent]::before, .msg :is(.stamp, .stamp-room) .ring, .gp { corner-shape: round; } /* circles stay circles */
|
|
336
|
-
}
|
|
337
|
-
@keyframes lab-pin { from { transform: scale(1.1); } }
|
|
338
|
-
@keyframes lab-halo { from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--_fg) 12%, transparent); }
|
|
339
|
-
to { box-shadow: 0 0 0 16px color-mix(in srgb, var(--_fg) 0%, transparent); } }
|
|
340
|
-
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
|
|
341
|
-
@media (max-width: 480px) { kbd { display: none; } }
|
|
342
|
-
.handle { display: none; }
|
|
343
|
-
/* Phones: a thread or a new comment opens as a sheet from the bottom, full width, instead of beside the pin. */
|
|
344
|
-
@media (pointer: coarse) and (max-width: 560px), (pointer: coarse) and (max-height: 500px) { /* phones, upright or on their side */
|
|
345
|
-
/* Sheets fit what the screen shows (--lab-vh, the visible height, and --lab-kb, the keyboard over the page's
|
|
346
|
-
bottom, are kept up to date from visualViewport); their bottom part is solid down past the screen's edge,
|
|
347
|
-
behind the home bar, the keyboard and Safari's toolbar, so nothing of the page shows below the box. */
|
|
348
|
-
:host { --_safe: env(safe-area-inset-bottom, 0px); --_kb: var(--lab-kb, 0px);
|
|
349
|
-
--_sheet-max: calc(min(72dvh, var(--lab-vh, 100dvh) - 24px) + var(--_kb)); --_pb: calc(12px + var(--_safe) + var(--_kb)); }
|
|
350
|
-
:host([data-kb]) { --_safe: 0px; --_kb: 0px; --_pb: 10px; }
|
|
351
|
-
/* Keyboard up: a thread, the list and the chat fill exactly what the screen shows, like a native composer, so iOS
|
|
352
|
-
panning the page can't push it up and nothing of the page shows above or below it. */
|
|
353
|
-
:host([data-kb]) :is(.card, .list:not([hidden])) { top: var(--lab-top, 0px) !important; bottom: auto !important;
|
|
354
|
-
height: var(--lab-vh, 100dvh) !important; max-height: none !important; border-radius: 0; }
|
|
355
|
-
/* A new comment stays small, just above the keyboard, with the page (dimmed) above it: you see what you comment on. */
|
|
356
|
-
:host([data-kb]) .float { top: auto !important; bottom: var(--lab-kb, 0px) !important; height: auto !important; border-radius: var(--_radius) var(--_radius) 0 0; }
|
|
357
|
-
.card, .float { position: fixed; left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; max-width: none;
|
|
358
|
-
max-height: var(--_sheet-max); display: flex; flex-direction: column; border-radius: var(--_radius) var(--_radius) 0 0; padding: 8px 0 0; z-index: 3; }
|
|
359
|
-
.card::after, .float::after, .list::after { content: ''; position: absolute; left: 0; right: 0; top: 100%; height: 100vh; background: var(--_bg); }
|
|
360
|
-
/* The same 12 px sides as the chat's, so a thread's reply box sits exactly where the chat's message box does. */
|
|
361
|
-
.card > .body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 12px 4px; margin-right: 0; }
|
|
362
|
-
/* A thread keeps one height, as the chat does (Leo, 15 Nov: it jumped while the chat stays put): the sheet's full
|
|
363
|
-
height whatever its length, a short thread sitting by the reply box, so new replies and the keyboard never
|
|
364
|
-
move its top. */
|
|
365
|
-
.card { height: var(--_sheet-max); }
|
|
366
|
-
.card > .foot, .float > .composer { flex: none; padding: 0 12px var(--_pb); }
|
|
367
|
-
.card > .foot { margin-top: 0; padding-top: 6px; }
|
|
368
|
-
.card .composer { margin-top: 0; }
|
|
369
|
-
.card > .nav { flex: none; margin: -6px 0 0; padding: 0 12px; gap: 20px; }
|
|
370
|
-
.card .nav .btn { font-size: 14px; letter-spacing: -.011em; padding: 0 2px; min-height: 44px; display: inline-flex; align-items: center; } /* 44 px tall to tap (iOS 44 pt) */
|
|
371
|
-
.card .nav { gap: 16px; }
|
|
372
|
-
.card .nav { flex-wrap: wrap; row-gap: 0; } /* too narrow for one row: reopen / delete drop under, on the right */
|
|
373
|
-
.card .nav .acts { margin: 0 0 0 auto; gap: 20px; }
|
|
374
|
-
.box.one .who span { font-size: 16px; letter-spacing: -.019em; } /* "as" the size of the name beside it */ /* reopen / delete share the prev / next row, on the right */
|
|
375
|
-
.card .nav .acts button.btn { font-size: 14px; letter-spacing: -.011em; }
|
|
376
|
-
.float { background: var(--_bg); box-shadow: var(--_shadow); }
|
|
377
|
-
/* The grab handle: the sheet's top strip, where a drag down moves it. The header of the list and the chat does the same. */
|
|
378
|
-
/* Reaching 60 px above the sheet's edge over the dimmed page (Leo, 15 Nov: "the whole top and a bit above", then
|
|
379
|
-
"do more"); the bar and the layout stay as they were. The chat's and the list's header reach up the same way. */
|
|
380
|
-
.handle { display: block; flex: none; height: 86px; margin-top: -68px; touch-action: none; position: relative;
|
|
381
|
-
background: linear-gradient(color-mix(in srgb, var(--_fg) 18%, transparent) 0 0) center 68px / 36px 4px no-repeat; }
|
|
382
|
-
.list .tabs { position: relative; }
|
|
383
|
-
.list .tabs::before { content: ''; position: absolute; left: 0; right: 0; top: -60px; height: 60px; }
|
|
384
|
-
.list .tabs { touch-action: pan-x; }
|
|
385
|
-
.chatwin .tabs { touch-action: none; }
|
|
386
|
-
.list .items, .msgs, .card > .body { touch-action: pan-y; }
|
|
387
|
-
.list .tabs .x { display: none; } /* the handle, a swipe down or a tap on the dimmed page closes it */
|
|
388
|
-
|
|
389
|
-
:host([data-sheet]) :is(.hint, .listener, .left) { visibility: hidden; }
|
|
390
|
-
/* The bar steps down under the screen's edge while a sheet is open and comes back as the sheet goes: --lab-p is
|
|
391
|
-
how far the sheet is on its way out (0 open, 1 gone), set while a finger drags it and while it slides away,
|
|
392
|
-
so the bar rises with it, in step, instead of after it (Leo, 15 Nov). */
|
|
393
|
-
.bar { transition: transform .34s cubic-bezier(.32, .72, 0, 1), opacity .2s; }
|
|
394
|
-
:host([data-sheet]) .bar { transform: translateY(calc((100% + 16px + env(safe-area-inset-bottom, 0px)) * (1 - var(--lab-p, 0))));
|
|
395
|
-
opacity: var(--lab-p, 0); pointer-events: none;
|
|
396
|
-
transition: transform .24s cubic-bezier(.4, 0, 1, 1), opacity .2s .04s; }
|
|
397
|
-
:host([data-sheet]) .bar button { pointer-events: none; }
|
|
398
|
-
/* A sheet stands apart from the page: the page dims behind it (a tap there closes it), and scrolling inside a
|
|
399
|
-
sheet never scrolls the page. */
|
|
400
|
-
:host([data-sheet]) .scrim { display: block; animation: lab-fade .22s ease-out; }
|
|
401
|
-
.card.in, .float.in, .list:not([hidden]) { animation: lab-sheet-in .28s cubic-bezier(.2, .8, .2, 1); }
|
|
402
|
-
.card.out, .float.out { animation: lab-sheet-out .22s cubic-bezier(.4, 0, 1, 1) forwards; }
|
|
403
|
-
.list { left: 0; right: 0; bottom: 0 !important; width: auto; max-height: var(--_sheet-max); overflow: visible; border-radius: var(--_radius) var(--_radius) 0 0;
|
|
404
|
-
font-size: 15px; letter-spacing: -.016em; z-index: 3; }
|
|
405
|
-
/* The chat keeps one height (new messages don't move its top) and opens at the newest. */
|
|
406
|
-
.chatwin { height: var(--_sheet-max); transition: height .38s cubic-bezier(.32, .72, 0, 1); }
|
|
407
|
-
/* Pulled up: the chat takes the whole screen, below the status bar (iOS large / Android expanded). */
|
|
408
|
-
.chatwin.full, .card.full { height: calc(var(--lab-vh, 100dvh) - env(safe-area-inset-top, 0px) - 10px + var(--_kb)); max-height: none; }
|
|
409
|
-
.card { transition: height .38s cubic-bezier(.32, .72, 0, 1); } /* a comment pulls up to full height as the chat does */
|
|
410
|
-
/* The header is the sheet's top edge, grab handle drawn on it; the list scrolls below it, never under or above it. */
|
|
411
|
-
.list .tabs { flex-wrap: nowrap; overflow-x: auto; padding: 18px 12px 8px; border-radius: var(--_radius) var(--_radius) 0 0;
|
|
412
|
-
background: linear-gradient(color-mix(in srgb, var(--_fg) 18%, transparent) 0 0) center 8px / 36px 4px no-repeat, var(--_bg); }
|
|
413
|
-
.list .items { padding: 0 12px calc(10px + var(--_safe)); }
|
|
414
|
-
.chatwin .msgs { padding: 4px 12px 8px; }
|
|
415
|
-
.chatwin .tabs { padding: 18px 12px 0; } /* just the grab strip, as tall as a thread's */
|
|
416
|
-
.chatwin .chat { padding: 6px 12px var(--_pb); }
|
|
417
|
-
/* Glass reply boxes (Leo, 15 Nov; iOS 26's look, Android too): the messages scroll on under the box and show
|
|
418
|
-
through it, blurred. Only the box's own strip overlaps; the new / resolve / delete row stays on the sheet. */
|
|
419
|
-
.chatwin .msgs { margin-bottom: calc(-56px - var(--_pb)); padding-bottom: calc(64px + var(--_pb)); }
|
|
420
|
-
.card > .body { margin-bottom: calc(-56px - var(--_pb)); padding-bottom: calc(64px + var(--_pb)); }
|
|
421
|
-
/* \u2026and fade out behind the box (iOS's scroll edge): from 4 px above its top to 12% at its bottom (Leo, 15 Nov:
|
|
422
|
-
"behind input bottom", "a bit more", "less, it's just black", then "more, darker there"). */
|
|
423
|
-
.chatwin .msgs { -webkit-mask-image: linear-gradient(#000 calc(100% - 60px - var(--_pb)), rgba(0,0,0,.12) calc(100% - var(--_pb)));
|
|
424
|
-
mask-image: linear-gradient(#000 calc(100% - 60px - var(--_pb)), rgba(0,0,0,.12) calc(100% - var(--_pb))); }
|
|
425
|
-
.card > .body { -webkit-mask-image: linear-gradient(#000 calc(100% - 60px - var(--_pb)), rgba(0,0,0,.12) calc(100% - var(--_pb)));
|
|
426
|
-
mask-image: linear-gradient(#000 calc(100% - 60px - var(--_pb)), rgba(0,0,0,.12) calc(100% - var(--_pb))); }
|
|
427
|
-
.chatwin .chat, .card > .foot { position: relative; z-index: 1; background: none; }
|
|
428
|
-
:host { --_box-bg: color-mix(in srgb, var(--_bg) 72%, transparent);
|
|
429
|
-
--_box-edge: inset 0 0 0 .5px color-mix(in srgb, var(--_fg) 16%, transparent), 0 4px 18px rgba(0, 0, 0, .08); }
|
|
430
|
-
.float { --_box-bg: inherit; --_box-edge: inherit; } /* phones: the new comment sheet's box is the same glass */
|
|
431
|
-
.box { -webkit-backdrop-filter: blur(18px) saturate(1.8); backdrop-filter: blur(18px) saturate(1.8); }
|
|
432
|
-
.list .it { padding: 11px 8px; }
|
|
433
|
-
/* Pins a size smaller (22 px), the tail still on the spot: 28 px covered words on a phone. Moved ones smaller still. */
|
|
434
|
-
.pin { scale: .8; }
|
|
435
|
-
/* Messages at 15 px (13 on computers): closer to the phone's own 17 px text, threads still short. */
|
|
436
|
-
.msg .p { font-size: 15px; letter-spacing: -.016em; line-height: 21px; }
|
|
437
|
-
.msg .quote { font-size: 14px; letter-spacing: -.011em; }
|
|
438
|
-
.msg b, .msg .quote b { font-size: 12px; letter-spacing: 0; }
|
|
439
|
-
.pin.moved { scale: .64; }
|
|
440
|
-
/* The same one bar as on computers, each segment 44 px tall to tap (iOS 44 pt); the menu opens above it. */
|
|
441
|
-
.bar > button { padding: 12px 14px; min-height: 44px; }
|
|
442
|
-
.more-menu { bottom: 72px; min-width: 200px; }
|
|
443
|
-
.more-menu button { padding: 11px 12px; font-size: 15px; letter-spacing: -.016em; }
|
|
444
|
-
}
|
|
445
|
-
/* Reaches past the screen's edges, under Safari's status bar and toolbar, so the page is dimmed everywhere. */
|
|
446
|
-
.scrim { cursor: pointer; display: none; position: fixed; inset: -50vh 0; background: rgba(0, 0, 0, .4); z-index: 2; touch-action: none; }
|
|
447
|
-
.sel-chip { position: fixed; transform: translateX(-50%); border: 0; border-radius: var(--_radius); padding: 8px 14px; background: var(--_fg);
|
|
448
|
-
color: var(--_bg); font: 500 14px/1 var(--_font, inherit); box-shadow: var(--_shadow); z-index: 4; }
|
|
449
|
-
/* Phones: the listening label is a light in the "list" button (steady: listening, blinking: working, grey:
|
|
450
|
-
nobody), the bar goes back to the bottom, and the send button is big enough for a thumb. */
|
|
451
|
-
@media (pointer: coarse) and (max-width: 560px), (pointer: coarse) and (max-height: 500px) { /* phones, upright or on their side */
|
|
452
|
-
.listener { display: none !important; }
|
|
453
|
-
.bar { bottom: 16px !important; }
|
|
454
|
-
.hint { bottom: 64px !important; }
|
|
455
|
-
.chat-btn[data-agent]::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--_accent); }
|
|
456
|
-
.chat-btn[data-agent=away]::before { background: var(--_muted); opacity: .5; }
|
|
457
|
-
.chat-btn[data-agent=working]::before { background: rgb(36, 160, 70); }
|
|
458
|
-
.chat-btn[data-agent] { position: relative; }
|
|
459
|
-
.chat-btn[data-agent=working]::after { content: ''; position: absolute; left: 14px; top: 50%; width: 8px; height: 8px; margin-top: -4px;
|
|
460
|
-
border-radius: 50%; corner-shape: round; background: rgb(52, 199, 89); pointer-events: none; will-change: transform, opacity; animation: lab-ping 1.6s cubic-bezier(0, 0, .2, 1) infinite; }
|
|
461
|
-
.send { width: 36px; height: 36px; }
|
|
462
|
-
.send .arr { width: 17px; height: 15px; margin: auto; }
|
|
463
|
-
}
|
|
464
|
-
/* Narrow screens: the buttons sit a row above the listening label, so neither covers the other. */
|
|
465
|
-
@media (max-width: 560px) { .bar { bottom: 64px; } .hint { bottom: 112px; } .list { bottom: 114px; } }
|
|
466
|
-
[hidden] { display: none !important; }
|
|
467
|
-
`;
|
|
468
|
-
|
|
469
|
-
// src/widget/anchoring.ts
|
|
470
|
-
var host;
|
|
471
|
-
var layer;
|
|
472
|
-
var el;
|
|
473
|
-
var store;
|
|
474
|
-
function bindAnchoring(deps) {
|
|
475
|
-
({ host, layer, el, store } = deps);
|
|
476
|
-
}
|
|
477
|
-
function selectorFor(node) {
|
|
478
|
-
const parts = [];
|
|
479
|
-
while (node && node.nodeType === 1 && node !== document.body && node !== document.documentElement) {
|
|
480
|
-
if (node.id && document.querySelectorAll(`#${CSS.escape(node.id)}`).length === 1) {
|
|
481
|
-
parts.unshift(`#${CSS.escape(node.id)}`);
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
const tag = node.localName;
|
|
485
|
-
let index = 1;
|
|
486
|
-
for (let sib = node.previousElementSibling; sib; sib = sib.previousElementSibling) if (sib.localName === tag) index++;
|
|
487
|
-
parts.unshift(`${tag}:nth-of-type(${index})`);
|
|
488
|
-
node = node.parentElement;
|
|
489
|
-
}
|
|
490
|
-
return parts.length ? (parts[0].startsWith("#") ? "" : "body > ") + parts.join(" > ") : "body";
|
|
491
|
-
}
|
|
492
|
-
var docWidth = () => Math.max(document.documentElement.scrollWidth, 1);
|
|
493
|
-
var clamp01 = (v) => Math.min(Math.max(v, 0), 1);
|
|
494
|
-
var short = (v, n) => (v || "").replace(/\s+/g, " ").trim().slice(0, n);
|
|
495
|
-
function fileHint(url) {
|
|
496
|
-
if (!url || url.startsWith("data:")) return "";
|
|
497
|
-
try {
|
|
498
|
-
const u = new URL(url, location.href);
|
|
499
|
-
const inner = u.searchParams.get("href") || u.searchParams.get("url");
|
|
500
|
-
if (inner && /\/_(image|vercel\/image|next\/image)/.test(u.pathname)) return fileHint(inner);
|
|
501
|
-
const parts = u.pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
502
|
-
let name = parts.pop() || "";
|
|
503
|
-
if (/^w?\d+(x\d+)?\.\w+$/i.test(name) && parts.length) name = parts.pop();
|
|
504
|
-
return name.replace(/\.(avif|webp|jpe?g|png|gif|svg|mp4|webm|mov)$/i, "").replace(/[._-][A-Za-z0-9_-]{8}$/, "");
|
|
505
|
-
} catch {
|
|
506
|
-
return "";
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
var mediaSrc = (m) => {
|
|
510
|
-
const src = m.currentSrc || m.getAttribute("src") || "";
|
|
511
|
-
if (src && !src.startsWith("data:")) return new URL(src, location.href).href;
|
|
512
|
-
const lazy = m.dataset?.src || (m.getAttribute("srcset") || m.dataset?.srcset || "").split(/\s+/)[0];
|
|
513
|
-
return lazy ? new URL(lazy, location.href).href : "";
|
|
514
|
-
};
|
|
515
|
-
function naturalSpot(m, rect, cx, cy, nw, nh) {
|
|
516
|
-
if (!nw || !nh || !rect.width || !rect.height) return null;
|
|
517
|
-
const cs = getComputedStyle(m);
|
|
518
|
-
const fit = cs.objectFit || "fill";
|
|
519
|
-
const pos = (cs.objectPosition || "50% 50%").split(/\s+/).map(
|
|
520
|
-
(v) => v.endsWith("%") ? parseFloat(v) / 100 : { left: 0, top: 0, right: 1, bottom: 1 }[v] ?? 0.5
|
|
521
|
-
);
|
|
522
|
-
const sx = rect.width / nw;
|
|
523
|
-
const sy = rect.height / nh;
|
|
524
|
-
const scale = { cover: Math.max(sx, sy), contain: Math.min(sx, sy), none: 1, "scale-down": Math.min(1, sx, sy) }[fit];
|
|
525
|
-
const dw = nw * (scale ?? sx);
|
|
526
|
-
const dh = nh * (scale ?? sy);
|
|
527
|
-
const ox = (rect.width - dw) * (pos[0] ?? 0.5);
|
|
528
|
-
const oy = (rect.height - dh) * (pos[1] ?? pos[0] ?? 0.5);
|
|
529
|
-
return { fit, nw, nh, imgX: clamp01((cx - rect.left - ox) / dw), imgY: clamp01((cy - rect.top - oy) / dh) };
|
|
530
|
-
}
|
|
531
|
-
function fileSize(img) {
|
|
532
|
-
let nw = img.naturalWidth;
|
|
533
|
-
let nh = img.naturalHeight;
|
|
534
|
-
const sets = [img.srcset, ...[...img.closest("picture")?.querySelectorAll("source") || []].map((s) => s.srcset)].filter(Boolean);
|
|
535
|
-
for (const set of sets) {
|
|
536
|
-
for (const part of set.split(/,\s+/)) {
|
|
537
|
-
const [url, d = "1x"] = part.trim().split(/\s+/);
|
|
538
|
-
let abs = "";
|
|
539
|
-
try {
|
|
540
|
-
abs = new URL(url, location.href).href;
|
|
541
|
-
} catch {
|
|
542
|
-
}
|
|
543
|
-
if (!url || abs !== img.currentSrc || !nw) continue;
|
|
544
|
-
const v = parseFloat(d);
|
|
545
|
-
if (d.endsWith("w") && v) return { nw: Math.round(v), nh: Math.round(v * nh / nw) };
|
|
546
|
-
if (d.endsWith("x") && v) return { nw: Math.round(nw * v), nh: Math.round(nh * v) };
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
return { nw, nh };
|
|
550
|
-
}
|
|
551
|
-
var PLAIN_NAME = /^[A-Z][A-Za-z0-9]{2,}$/;
|
|
552
|
-
var PLUMBING = /(Provider|Context|Consumer|Boundary|Slot|Portal|Fragment|Presence|Scope|Trap|Root)$/;
|
|
553
|
-
var variantOf = (p) => ["variant", "size", "tone", "intent", "kind"].flatMap((k) => (typeof p?.[k] === "string" || typeof p?.[k] === "number") && /^[\w.-]{1,20}$/.test(String(p[k])) ? [`${k}=${p[k]}`] : []).join(" ");
|
|
554
|
-
var repoPath = (url) => !/^[a-z-]+:\/\//i.test(url) ? url : decodeURIComponent(url.replace(/^[a-z-]+:\/\/\/?(\.\/)?/i, "/").replace(/^\/[^/]*:\d+/, "").split("?")[0]).replace(/^\/(@fs)?/, "").replace(/^\(app-pages-browser\)\/\.?\/?/, "");
|
|
555
|
-
function componentAt(el2) {
|
|
556
|
-
const name = (t, d = 0) => d > 3 ? "" : typeof t === "function" ? t.displayName || t.name || "" : t && typeof t === "object" ? t.displayName || name(t.render || t.type, d + 1) : "";
|
|
557
|
-
const plain = (n) => PLAIN_NAME.test(n) && !PLUMBING.test(n);
|
|
558
|
-
const srcOf = (f) => {
|
|
559
|
-
const d = f?._debugSource;
|
|
560
|
-
if (d?.fileName) return `${repoPath(String(d.fileName))}:${d.lineNumber || 0}`;
|
|
561
|
-
const st = f?._debugStack?.stack;
|
|
562
|
-
if (typeof st !== "string") return "";
|
|
563
|
-
for (const line of st.split("\n").slice(1)) {
|
|
564
|
-
const m = /((?:https?|webpack-internal|file):\/\/[^\s()]+?):(\d+):\d+\)?\s*$/.exec(line);
|
|
565
|
-
if (m && !/node_modules|react-dom|react-jsx|jsx-dev-runtime|react-server|scheduler/.test(m[1])) return `${repoPath(m[1])} (line ${m[2]} as served, may differ from the source)`;
|
|
566
|
-
}
|
|
567
|
-
return "";
|
|
568
|
-
};
|
|
569
|
-
const key = Object.keys(el2).find((k) => k.startsWith("__reactFiber$"));
|
|
570
|
-
if (key) {
|
|
571
|
-
const host2 = el2[key];
|
|
572
|
-
const parts = [];
|
|
573
|
-
let usedAt = "";
|
|
574
|
-
for (let f = host2?.return, i = 0; f && parts.length < 2 && i < 80; f = f.return, i++) {
|
|
575
|
-
if (typeof f.type === "string") continue;
|
|
576
|
-
const n = name(f.type);
|
|
577
|
-
if (!plain(n)) continue;
|
|
578
|
-
if (!parts.length) usedAt = srcOf(f);
|
|
579
|
-
const v = variantOf(f.memoizedProps);
|
|
580
|
-
parts.push(v ? `${n} ${v}` : n);
|
|
581
|
-
}
|
|
582
|
-
if (!parts.length) return srcOf(host2) ? { source: srcOf(host2) } : {};
|
|
583
|
-
return { component: parts.length > 1 ? `${parts[0]} (in ${parts[1]})` : parts[0], source: srcOf(host2) || void 0, usedAt: usedAt || void 0 };
|
|
584
|
-
}
|
|
585
|
-
const vue = el2.__vueParentComponent;
|
|
586
|
-
if (vue?.type) {
|
|
587
|
-
const n = vue.type.name || vue.type.__name || (vue.type.__file || "").replace(/^.*\//, "").replace(/\.vue$/, "");
|
|
588
|
-
const parent = vue.parent?.type;
|
|
589
|
-
const pn = parent && (parent.name || parent.__name);
|
|
590
|
-
const v = variantOf(vue.props);
|
|
591
|
-
return { component: `${n}${v ? " " + v : ""}${pn ? ` (in ${pn})` : ""}`, source: vue.type.__file ? repoPath(vue.type.__file) : void 0, usedAt: parent?.__file ? repoPath(parent.__file) : void 0 };
|
|
592
|
-
}
|
|
593
|
-
const loc = el2.__svelte_meta?.loc;
|
|
594
|
-
if (loc?.file) return { component: loc.file.replace(/^.*\//, "").replace(/\.svelte$/, ""), source: `${repoPath(loc.file)}:${loc.line ?? 0}` };
|
|
595
|
-
return {};
|
|
596
|
-
}
|
|
597
|
-
function looksOf(el2) {
|
|
598
|
-
const cs = getComputedStyle(el2);
|
|
599
|
-
const names = /* @__PURE__ */ new Map();
|
|
600
|
-
const NONE = "rgb(1, 2, 3)";
|
|
601
|
-
const wrap = document.createElement("i");
|
|
602
|
-
wrap.style.cssText = `display:none;color:${NONE}`;
|
|
603
|
-
const probe = wrap.appendChild(document.createElement("i"));
|
|
604
|
-
document.body.append(wrap);
|
|
605
|
-
for (const prop of [...getComputedStyle(document.documentElement)].filter((p) => p.startsWith("--")).slice(0, 400)) {
|
|
606
|
-
probe.style.color = "";
|
|
607
|
-
probe.style.color = `var(${prop})`;
|
|
608
|
-
const v = getComputedStyle(probe).color;
|
|
609
|
-
if (v && v !== NONE && !names.has(v)) names.set(v, prop);
|
|
610
|
-
}
|
|
611
|
-
wrap.remove();
|
|
612
|
-
const say = (v) => names.has(v) ? `${names.get(v)} ${v}` : v;
|
|
613
|
-
const out = [];
|
|
614
|
-
if (!/^(transparent|rgba\(0, 0, 0, 0\))$/.test(cs.backgroundColor)) out.push(`fill ${say(cs.backgroundColor)}`);
|
|
615
|
-
out.push(`text ${say(cs.color)} ${cs.fontSize}/${cs.fontWeight}`);
|
|
616
|
-
if (parseFloat(cs.borderTopLeftRadius)) out.push(`radius ${cs.borderTopLeftRadius}`);
|
|
617
|
-
return short(out.join(", "), 200);
|
|
618
|
-
}
|
|
619
|
-
function untransform(el2, cx, cy) {
|
|
620
|
-
const t = getComputedStyle(el2).transform;
|
|
621
|
-
if (!t || t === "none") return null;
|
|
622
|
-
const m = new DOMMatrix(t);
|
|
623
|
-
if (m.isIdentity) return null;
|
|
624
|
-
const w = el2.offsetWidth || el2.getBoundingClientRect().width;
|
|
625
|
-
const h = el2.offsetHeight || el2.getBoundingClientRect().height;
|
|
626
|
-
const [ox, oy] = getComputedStyle(el2).transformOrigin.split(" ").map(parseFloat);
|
|
627
|
-
const at = (x, y) => m.transformPoint(new DOMPoint(x - ox, y - oy));
|
|
628
|
-
const corners = [at(0, 0), at(w, 0), at(0, h), at(w, h)];
|
|
629
|
-
const r = el2.getBoundingClientRect();
|
|
630
|
-
const origin = { x: r.left - Math.min(...corners.map((p) => p.x)), y: r.top - Math.min(...corners.map((p) => p.y)) };
|
|
631
|
-
const q = m.inverse().transformPoint(new DOMPoint(cx - origin.x, cy - origin.y));
|
|
632
|
-
return { rect: { left: 0, top: 0, width: w, height: h }, x: q.x + ox, y: q.y + oy };
|
|
633
|
-
}
|
|
634
|
-
function svgImageSpot(el2, anchor, cx, cy) {
|
|
635
|
-
const r = el2.getBoundingClientRect();
|
|
636
|
-
const keep = (el2.getAttribute("preserveAspectRatio") || "xMidYMid meet").split(/\s+/);
|
|
637
|
-
const fill = (iw, ih) => {
|
|
638
|
-
if (!iw || !ih || !r.width || !r.height) return;
|
|
639
|
-
let [dw, dh] = [r.width, r.height];
|
|
640
|
-
if (keep[0] !== "none") {
|
|
641
|
-
const k = (keep[1] === "slice" ? Math.max : Math.min)(r.width / iw, r.height / ih);
|
|
642
|
-
[dw, dh] = [iw * k, ih * k];
|
|
643
|
-
}
|
|
644
|
-
const align = (v, room) => v === "Min" ? 0 : v === "Max" ? room : room / 2;
|
|
645
|
-
const ox = keep[0] === "none" ? 0 : align(keep[0].slice(1, 4), r.width - dw);
|
|
646
|
-
const oy = keep[0] === "none" ? 0 : align(keep[0].slice(5, 8), r.height - dh);
|
|
647
|
-
Object.assign(anchor, { nw: iw, nh: ih, imgX: clamp01((cx - r.left - ox) / dw), imgY: clamp01((cy - r.top - oy) / dh) });
|
|
648
|
-
};
|
|
649
|
-
const probe = new Image();
|
|
650
|
-
probe.onload = () => fill(probe.naturalWidth, probe.naturalHeight);
|
|
651
|
-
probe.src = anchor.src;
|
|
652
|
-
if (probe.complete) fill(probe.naturalWidth, probe.naturalHeight);
|
|
653
|
-
}
|
|
654
|
-
function backgroundSpot(n, url, anchor, cx, cy) {
|
|
655
|
-
const r = n.getBoundingClientRect();
|
|
656
|
-
const cs = getComputedStyle(n);
|
|
657
|
-
const layers = (v) => v.split(/,(?![^(]*\))/).map((x) => x.trim());
|
|
658
|
-
const at = Math.max(0, layers(cs.backgroundImage).findIndex((l) => l.includes(url)));
|
|
659
|
-
const pick = (v) => {
|
|
660
|
-
const l = layers(v);
|
|
661
|
-
return l[at % l.length];
|
|
662
|
-
};
|
|
663
|
-
const fill = (iw, ih) => {
|
|
664
|
-
if (!iw || !ih || !r.width || !r.height) return;
|
|
665
|
-
const size = pick(cs.backgroundSize);
|
|
666
|
-
let dw = iw;
|
|
667
|
-
let dh = ih;
|
|
668
|
-
if (size === "cover" || size === "contain") {
|
|
669
|
-
const k = (size === "cover" ? Math.max : Math.min)(r.width / iw, r.height / ih);
|
|
670
|
-
dw = iw * k;
|
|
671
|
-
dh = ih * k;
|
|
672
|
-
} else if (size !== "auto" && size !== "auto auto") {
|
|
673
|
-
const [w, h = "auto"] = size.split(/\s+/);
|
|
674
|
-
const len = (v, of) => v.endsWith("%") ? parseFloat(v) / 100 * of : parseFloat(v);
|
|
675
|
-
dw = w === "auto" ? NaN : len(w, r.width);
|
|
676
|
-
dh = h === "auto" ? NaN : len(h, r.height);
|
|
677
|
-
if (Number.isNaN(dw) && Number.isNaN(dh)) [dw, dh] = [iw, ih];
|
|
678
|
-
else if (Number.isNaN(dw)) dw = dh * iw / ih;
|
|
679
|
-
else if (Number.isNaN(dh)) dh = dw * ih / iw;
|
|
680
|
-
}
|
|
681
|
-
const [px = "50%", py = "50%"] = pick(cs.backgroundPosition).split(/\s+/);
|
|
682
|
-
const off = (v, room) => v.endsWith("%") ? parseFloat(v) / 100 * room : parseFloat(v) || 0;
|
|
683
|
-
const ox = off(px, r.width - dw);
|
|
684
|
-
const oy = off(py, r.height - dh);
|
|
685
|
-
Object.assign(anchor, { nw: iw, nh: ih, fit: `background ${size}`, imgX: clamp01((cx - r.left - ox) / dw), imgY: clamp01((cy - r.top - oy) / dh) });
|
|
686
|
-
};
|
|
687
|
-
const probe = new Image();
|
|
688
|
-
probe.onload = () => fill(probe.naturalWidth, probe.naturalHeight);
|
|
689
|
-
probe.src = url;
|
|
690
|
-
if (probe.complete) fill(probe.naturalWidth, probe.naturalHeight);
|
|
691
|
-
}
|
|
692
|
-
function between(target, cy) {
|
|
693
|
-
const kids = [...target.children].filter((k) => k !== host && k.getBoundingClientRect().height > 0);
|
|
694
|
-
let above = null;
|
|
695
|
-
let below = null;
|
|
696
|
-
for (const k of kids) {
|
|
697
|
-
const kr = k.getBoundingClientRect();
|
|
698
|
-
if (kr.bottom <= cy) above = k;
|
|
699
|
-
else if (kr.top >= cy && !below) below = k;
|
|
700
|
-
else if (kr.top < cy && kr.bottom > cy) return null;
|
|
701
|
-
}
|
|
702
|
-
const say = (k) => {
|
|
703
|
-
if (!k) return void 0;
|
|
704
|
-
const h = k.matches("h1, h2, h3, h4, h5, h6") ? k : k.querySelector("h1, h2, h3, h4, h5, h6");
|
|
705
|
-
return short(`${openingTag(k)} "${short((h || k).textContent, 60)}"`, 160);
|
|
706
|
-
};
|
|
707
|
-
return above || below ? { above: say(above), below: say(below) } : null;
|
|
708
|
-
}
|
|
709
|
-
function schemeAt(target) {
|
|
710
|
-
for (let n = target; n; n = n.parentElement) {
|
|
711
|
-
const m = getComputedStyle(n).backgroundColor.match(/rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?/);
|
|
712
|
-
if (!m || m[4] !== void 0 && parseFloat(m[4]) < 0.5) continue;
|
|
713
|
-
const [r, g, b] = [m[1], m[2], m[3]].map(Number);
|
|
714
|
-
const hex = "#" + [r, g, b].map((v) => Math.round(v).toString(16).padStart(2, "0")).join("");
|
|
715
|
-
return { scheme: 0.2126 * r + 0.7152 * g + 0.0722 * b < 128 ? "dark" : "light", background: hex };
|
|
716
|
-
}
|
|
717
|
-
return { scheme: matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" };
|
|
718
|
-
}
|
|
719
|
-
function quoteAt(cx, cy, shadowRoots = []) {
|
|
720
|
-
let node = null;
|
|
721
|
-
let offset = 0;
|
|
722
|
-
if (document.caretPositionFromPoint) {
|
|
723
|
-
const p = shadowRoots.length ? document.caretPositionFromPoint(cx, cy, { shadowRoots }) : document.caretPositionFromPoint(cx, cy);
|
|
724
|
-
if (p) {
|
|
725
|
-
node = p.offsetNode;
|
|
726
|
-
offset = p.offset;
|
|
727
|
-
}
|
|
728
|
-
} else if (document.caretRangeFromPoint) {
|
|
729
|
-
const r = document.caretRangeFromPoint(cx, cy);
|
|
730
|
-
if (r) {
|
|
731
|
-
node = r.startContainer;
|
|
732
|
-
offset = r.startOffset;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
if (!node || node.nodeType !== 3 || !node.data.trim()) return null;
|
|
736
|
-
const range = document.createRange();
|
|
737
|
-
range.selectNodeContents(node);
|
|
738
|
-
const hit = [...range.getClientRects()].some((r) => cx >= r.left - 4 && cx <= r.right + 4 && cy >= r.top - 4 && cy <= r.bottom + 4);
|
|
739
|
-
if (!hit) return null;
|
|
740
|
-
const text = node.data;
|
|
741
|
-
let a = offset;
|
|
742
|
-
let b = offset;
|
|
743
|
-
const seg = /[\u0e00-\u0e7f\u3040-\u30ff\u3400-\u9fff\uac00-\ud7af\uf900-\ufaff]/.test(text) && typeof Intl !== "undefined" && Intl.Segmenter ? new Intl.Segmenter(node.parentElement?.closest("[lang]")?.lang || void 0, { granularity: "word" }) : null;
|
|
744
|
-
if (seg) {
|
|
745
|
-
for (const w of seg.segment(text)) {
|
|
746
|
-
if (offset >= w.index && offset <= w.index + w.segment.length && w.segment.trim()) {
|
|
747
|
-
a = w.index;
|
|
748
|
-
b = w.index + w.segment.length;
|
|
749
|
-
if (offset < b) break;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
} else {
|
|
753
|
-
while (a > 0 && /\S/.test(text[a - 1])) a--;
|
|
754
|
-
while (b < text.length && /\S/.test(text[b])) b++;
|
|
755
|
-
}
|
|
756
|
-
const block = node.parentElement?.closest("p, li, h1, h2, h3, h4, h5, h6, td, th, figcaption, blockquote, a, button, label, span, div") || node.parentElement;
|
|
757
|
-
const full = block?.textContent || text;
|
|
758
|
-
const before = full.slice(0, full.indexOf(text) + a);
|
|
759
|
-
const after = full.slice(full.indexOf(text) + b);
|
|
760
|
-
const squash = (v) => v.replace(/\s+/g, " ");
|
|
761
|
-
const quote = {
|
|
762
|
-
exact: short(text.slice(a, b), 80),
|
|
763
|
-
prefix: squash(before.slice(-80)).replace(/^\s+/, "").slice(-40),
|
|
764
|
-
suffix: squash(after.slice(0, 80)).replace(/\s+$/, "").slice(0, 40)
|
|
765
|
-
};
|
|
766
|
-
const pre = node.parentElement?.closest("pre, [data-file]") || (getComputedStyle(node.parentElement).whiteSpace.startsWith("pre") ? node.parentElement : null);
|
|
767
|
-
const codeTable = !pre && node.parentElement?.closest('table[data-file], table[class*="code" i]');
|
|
768
|
-
if (pre || codeTable) {
|
|
769
|
-
const box = pre || codeTable;
|
|
770
|
-
const r = document.createRange();
|
|
771
|
-
r.setStart(box, 0);
|
|
772
|
-
r.setEnd(node, offset);
|
|
773
|
-
let upto = r.toString();
|
|
774
|
-
let all = box.textContent;
|
|
775
|
-
const breaks = [...box.querySelectorAll("br, tr")];
|
|
776
|
-
if ((box.localName === "table" || !all.includes("\n")) && breaks.length) {
|
|
777
|
-
const ends = box.querySelectorAll("br").length ? [...box.querySelectorAll("br")] : [...box.querySelectorAll("tr")].slice(0, -1);
|
|
778
|
-
const before2 = ends.filter((e) => e.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING && !e.contains(node)).length;
|
|
779
|
-
const lineRange = document.createRange();
|
|
780
|
-
if (before2) lineRange.setStartAfter(ends[before2 - 1]);
|
|
781
|
-
else lineRange.setStart(box, 0);
|
|
782
|
-
if (ends[before2]) lineRange.setEndBefore(ends[before2]);
|
|
783
|
-
else lineRange.setEnd(box, box.childNodes.length);
|
|
784
|
-
const row2 = box.querySelectorAll("br").length ? null : node.parentElement?.closest("tr");
|
|
785
|
-
quote.line = short((row2 ? row2.textContent : lineRange.toString()).trim(), 200);
|
|
786
|
-
quote.lineNo = before2 + 1;
|
|
787
|
-
quote.lines = ends.length + (box.querySelectorAll("br").length ? 0 : 1);
|
|
788
|
-
} else {
|
|
789
|
-
const from = upto.lastIndexOf("\n") + 1;
|
|
790
|
-
const to = all.indexOf("\n", upto.length);
|
|
791
|
-
quote.line = short(all.slice(from, to < 0 ? void 0 : to).trim(), 200);
|
|
792
|
-
quote.lineNo = upto.split("\n").length;
|
|
793
|
-
quote.lines = all.replace(/\n$/, "").split("\n").length;
|
|
794
|
-
}
|
|
795
|
-
const row = node.parentElement?.closest("tr, [data-line], [data-line-number]");
|
|
796
|
-
if (row) {
|
|
797
|
-
const cell = row.matches("[data-line], [data-line-number]") ? row : row.querySelector("[data-line], [data-line-number]");
|
|
798
|
-
const n = cell?.getAttribute("data-line") || cell?.getAttribute("data-line-number") || [...row.children].map((c) => c.textContent.trim()).find((t) => /^\d+$/.test(t));
|
|
799
|
-
if (n && /^\d+$/.test(n)) quote.pageLineNo = Number(n);
|
|
800
|
-
}
|
|
801
|
-
let label = box.closest("[data-file]")?.getAttribute("data-file") || box.getAttribute("title") || box.getAttribute("aria-label") || "";
|
|
802
|
-
for (let el2 = box.parentElement, i = 0; !label.trim() && el2 && el2 !== document.body && i < 3; el2 = el2.parentElement, i++) {
|
|
803
|
-
label = el2.querySelector(':scope > figcaption, :scope > [class*="title" i]')?.textContent || "";
|
|
804
|
-
}
|
|
805
|
-
if (label.trim()) quote.label = short(label.trim(), 120);
|
|
806
|
-
}
|
|
807
|
-
return quote;
|
|
808
|
-
}
|
|
809
|
-
function openingTag(node) {
|
|
810
|
-
const attrs = [...node.attributes].filter((a) => /^(id|class|alt|role|aria-label|href|data-[\w-]+)$/.test(a.name)).map((a) => `${a.name}="${short(a.value, 60)}"`);
|
|
811
|
-
return `<${node.localName}${attrs.length ? ` ${attrs.join(" ")}` : ""}>`.slice(0, 200);
|
|
812
|
-
}
|
|
813
|
-
function sameKind(node, tag) {
|
|
814
|
-
if (!tag) return true;
|
|
815
|
-
const want = /^<([\w-]+)/.exec(tag)?.[1];
|
|
816
|
-
if (node.localName !== want) return false;
|
|
817
|
-
const id = / id="([^"]*)"/.exec(tag)?.[1];
|
|
818
|
-
if ((id || "") !== short(node.id || "", 60)) return false;
|
|
819
|
-
const classes = (/ class="([^"]*)"/.exec(tag)?.[1] || "").split(/\s+/).filter((c) => c && c !== "\u2026" && !c.endsWith("\u2026"));
|
|
820
|
-
return !classes.length || classes.some((c) => node.classList.contains(c));
|
|
821
|
-
}
|
|
822
|
-
function anchorAt(clientX, clientY) {
|
|
823
|
-
let stack = document.elementsFromPoint(clientX, clientY).filter((n) => n !== host && n !== document.documentElement);
|
|
824
|
-
const shadowRoots = [];
|
|
825
|
-
let shadowHost = null;
|
|
826
|
-
for (let top = stack[0]; top?.shadowRoot && !host.contains(top) && shadowRoots.length < 5; top = stack[0]) {
|
|
827
|
-
shadowHost ||= top;
|
|
828
|
-
shadowRoots.push(top.shadowRoot);
|
|
829
|
-
const inner = top.shadowRoot.elementsFromPoint(clientX, clientY).filter((n) => n !== top);
|
|
830
|
-
if (!inner.length) break;
|
|
831
|
-
stack = [...inner, ...stack];
|
|
832
|
-
}
|
|
833
|
-
const target = stack[0]?.closest("[data-comment-target]") || stack[0] || document.body;
|
|
834
|
-
const rect = target.getBoundingClientRect();
|
|
835
|
-
const anchor = {
|
|
836
|
-
selector: selectorFor(target),
|
|
837
|
-
x: rect.width ? (clientX - rect.left) / rect.width : 0,
|
|
838
|
-
y: rect.height ? (clientY - rect.top) / rect.height : 0,
|
|
839
|
-
docX: (clientX + scrollX) / docWidth(),
|
|
840
|
-
docY: clientY + scrollY,
|
|
841
|
-
width: innerWidth,
|
|
842
|
-
height: innerHeight,
|
|
843
|
-
dpr: Math.round((devicePixelRatio || 1) * 100) / 100,
|
|
844
|
-
element: openingTag(target),
|
|
845
|
-
eh: Math.round(rect.height)
|
|
846
|
-
// its height then: a pin on a big container can tell if the page grew under it
|
|
847
|
-
};
|
|
848
|
-
const own = short(target.textContent, 200);
|
|
849
|
-
if (own && target !== document.body && (target.textContent || "").length < 400) anchor.text = short(own, 80);
|
|
850
|
-
const inside = target.parentElement?.closest("[id], [data-lab]");
|
|
851
|
-
if (inside) anchor.inside = inside.dataset.lab ? `[data-lab="${inside.dataset.lab}"]` : `#${inside.id}`;
|
|
852
|
-
let heading = null;
|
|
853
|
-
for (const h of document.querySelectorAll("h1, h2, h3")) {
|
|
854
|
-
if (h.compareDocumentPosition(target) & Node.DOCUMENT_POSITION_FOLLOWING || h.contains(target)) heading = h;
|
|
855
|
-
}
|
|
856
|
-
if (heading) anchor.section = short(heading.textContent, 100);
|
|
857
|
-
if (shadowHost) anchor.shadow = openingTag(shadowHost);
|
|
858
|
-
for (const [k, v] of Object.entries(componentAt(target))) if (v) anchor[k] = short(v, 200);
|
|
859
|
-
if (target !== document.body) anchor.looks = looksOf(target);
|
|
860
|
-
const select = target.closest?.("select");
|
|
861
|
-
if (select && select.selectedIndex >= 0) {
|
|
862
|
-
anchor.chosen = short(`${select.selectedIndex + 1} of ${select.options.length}: "${select.options[select.selectedIndex].text}"`, 120);
|
|
863
|
-
}
|
|
864
|
-
for (const el2 of [target, target.parentElement]) {
|
|
865
|
-
if (!el2 || el2 === document.body) continue;
|
|
866
|
-
for (const which of ["::before", "::after"]) {
|
|
867
|
-
const c = getComputedStyle(el2, which).content;
|
|
868
|
-
const m = c && c.match(/^"(.+)"$/);
|
|
869
|
-
if (m && m[1].trim()) {
|
|
870
|
-
anchor.cssText = short(`"${m[1]}" from ${which} of ${openingTag(el2)}`, 160);
|
|
871
|
-
break;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
if (anchor.cssText) break;
|
|
875
|
-
}
|
|
876
|
-
const build = document.querySelector('meta[name="lab-build"]')?.content;
|
|
877
|
-
if (build) anchor.build = short(build, 40);
|
|
878
|
-
const media = stack.slice(0, 5).find((n) => /^(img|video|canvas|svg|image)$/.test(n.localName) && !host.contains(n));
|
|
879
|
-
if (media?.localName === "image" && media.namespaceURI === "http://www.w3.org/2000/svg") {
|
|
880
|
-
anchor.kind = "image";
|
|
881
|
-
anchor.src = new URL(media.getAttribute("href") || media.getAttribute("xlink:href") || "", location.href).href;
|
|
882
|
-
anchor.file = fileHint(anchor.src);
|
|
883
|
-
svgImageSpot(media, anchor, clientX, clientY);
|
|
884
|
-
} else if (media) {
|
|
885
|
-
const r = media.getBoundingClientRect();
|
|
886
|
-
anchor.kind = media.localName === "img" ? "image" : media.localName;
|
|
887
|
-
if (media.localName === "img" || media.localName === "video") {
|
|
888
|
-
const img = media, video = media;
|
|
889
|
-
anchor.src = mediaSrc(media);
|
|
890
|
-
anchor.file = fileHint(anchor.src);
|
|
891
|
-
if (img.alt) anchor.alt = short(img.alt, 120);
|
|
892
|
-
const local = untransform(media, clientX, clientY);
|
|
893
|
-
const [box, px, py] = local ? [local.rect, local.x, local.y] : [r, clientX, clientY];
|
|
894
|
-
const spot = media.localName === "img" ? naturalSpot(media, box, px, py, fileSize(media).nw, fileSize(media).nh) : naturalSpot(media, box, px, py, video.videoWidth, video.videoHeight);
|
|
895
|
-
if (spot) Object.assign(anchor, spot);
|
|
896
|
-
if (local) anchor.transform = short(getComputedStyle(media).transform, 80);
|
|
897
|
-
if (media.localName === "img" && /\.(gif|webp|apng)(\?|#|$)/i.test(img.currentSrc || img.src)) {
|
|
898
|
-
const entry = performance.getEntriesByName(img.currentSrc || img.src)[0];
|
|
899
|
-
const since = entry ? (performance.now() - entry.responseEnd) / 1e3 : performance.now() / 1e3;
|
|
900
|
-
anchor.shownFor = Math.round(since * 10) / 10;
|
|
901
|
-
}
|
|
902
|
-
if (media.localName === "video") {
|
|
903
|
-
anchor.time = Math.round(video.currentTime * 10) / 10;
|
|
904
|
-
if (Number.isFinite(video.duration)) anchor.duration = Math.round(video.duration * 10) / 10;
|
|
905
|
-
if (!anchor.file && video.poster) anchor.file = fileHint(video.poster);
|
|
906
|
-
}
|
|
907
|
-
} else {
|
|
908
|
-
anchor.time = Math.round(performance.now() / 100) / 10;
|
|
909
|
-
anchor.imgX = clamp01((clientX - r.left) / (r.width || 1));
|
|
910
|
-
anchor.imgY = clamp01((clientY - r.top) / (r.height || 1));
|
|
911
|
-
anchor.nw = Math.round(r.width);
|
|
912
|
-
anchor.nh = Math.round(r.height);
|
|
913
|
-
}
|
|
914
|
-
} else {
|
|
915
|
-
const quote = quoteAt(clientX, clientY, shadowRoots);
|
|
916
|
-
if (quote) {
|
|
917
|
-
anchor.kind = "text";
|
|
918
|
-
anchor.quote = quote;
|
|
919
|
-
} else {
|
|
920
|
-
for (let n = target, i = 0; n && n !== document.documentElement && i < 4; n = n.parentElement, i++) {
|
|
921
|
-
const bg = getComputedStyle(n).backgroundImage.match(/url\(["']?(.+?)["']?\)/);
|
|
922
|
-
if (bg) {
|
|
923
|
-
anchor.kind = "background";
|
|
924
|
-
anchor.src = new URL(bg[1], location.href).href;
|
|
925
|
-
anchor.file = fileHint(anchor.src);
|
|
926
|
-
backgroundSpot(n, anchor.src, anchor, clientX, clientY);
|
|
927
|
-
break;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
anchor.kind ||= "element";
|
|
931
|
-
if (anchor.kind === "element") {
|
|
932
|
-
const gap = between(target, clientY);
|
|
933
|
-
if (gap) Object.assign(anchor, { gapAbove: gap.above, gapBelow: gap.below });
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
Object.assign(anchor, schemeAt(target));
|
|
938
|
-
return anchor;
|
|
939
|
-
}
|
|
940
|
-
function findTarget(anchor) {
|
|
941
|
-
let node = null;
|
|
942
|
-
try {
|
|
943
|
-
node = anchor.selector ? document.querySelector(anchor.selector) : null;
|
|
944
|
-
} catch {
|
|
945
|
-
}
|
|
946
|
-
const matches = (n) => {
|
|
947
|
-
if (!n) return false;
|
|
948
|
-
if (anchor.file && /^(image|video)$/.test(anchor.kind)) {
|
|
949
|
-
const m = n.closest?.("img, video") || n;
|
|
950
|
-
return fileHint(mediaSrc(m)) === anchor.file;
|
|
951
|
-
}
|
|
952
|
-
if (anchor.element && !sameKind(n, anchor.element)) return false;
|
|
953
|
-
if (anchor.quote?.exact) {
|
|
954
|
-
const t = (n.textContent || "").replace(/\s+/g, "");
|
|
955
|
-
const q = anchor.quote.exact.replace(/\s+/g, "").slice(0, 24);
|
|
956
|
-
const before = (anchor.quote.prefix || "").replace(/\s+/g, "").slice(-10);
|
|
957
|
-
const after = (anchor.quote.suffix || "").replace(/\s+/g, "").slice(0, 10);
|
|
958
|
-
return t.includes(q) && (q.length >= 16 || !before && !after || t.includes(before + q) || t.includes(q + after));
|
|
959
|
-
}
|
|
960
|
-
return true;
|
|
961
|
-
};
|
|
962
|
-
const said = short(anchor.text, 400);
|
|
963
|
-
const sectionOf = (n) => {
|
|
964
|
-
let heading = null;
|
|
965
|
-
for (const h of document.querySelectorAll("h1, h2, h3")) if (h.compareDocumentPosition(n) & Node.DOCUMENT_POSITION_FOLLOWING || h.contains(n)) heading = h;
|
|
966
|
-
return heading ? short(heading.textContent, 100) : "";
|
|
967
|
-
};
|
|
968
|
-
const squash = (t) => String(t || "").replace(/\s+/g, "");
|
|
969
|
-
const areaWords = squash(anchor.zoneText).slice(0, 30);
|
|
970
|
-
const saysSame = (n) => anchor.quote?.exact ? true : said ? short(n.textContent, 400).startsWith(said.slice(0, 40)) : areaWords ? squash(n.textContent).includes(areaWords) : anchor.section ? sectionOf(n) === anchor.section : true;
|
|
971
|
-
const atPath = node && node !== document.body && matches(node) ? node : null;
|
|
972
|
-
if (atPath && saysSame(atPath)) return atPath;
|
|
973
|
-
if (anchor.file && /^(image|video)$/.test(anchor.kind)) {
|
|
974
|
-
return [...document.querySelectorAll("img, video")].find((m) => fileHint(mediaSrc(m)) === anchor.file) || null;
|
|
975
|
-
}
|
|
976
|
-
const tag = /^<([\w-]+)/.exec(anchor.element || "")?.[1];
|
|
977
|
-
if (!tag || tag === "body" || tag === "html") return atPath;
|
|
978
|
-
const flat = (t) => short(t, 400);
|
|
979
|
-
let found = null;
|
|
980
|
-
let best = -1;
|
|
981
|
-
let near = Infinity;
|
|
982
|
-
const twins = [...document.querySelectorAll(tag)].slice(0, 400).filter((n) => !host.contains(n) && sameKind(n, anchor.element));
|
|
983
|
-
for (const n of twins) {
|
|
984
|
-
const t = flat(n.textContent);
|
|
985
|
-
let score = 0;
|
|
986
|
-
if (anchor.quote?.exact && matches(n)) score += 4;
|
|
987
|
-
if (said && t === said) score += 4;
|
|
988
|
-
if (areaWords && squash(n.textContent).includes(areaWords)) score += 4;
|
|
989
|
-
else if (said && t.startsWith(said.slice(0, 40))) score += 2;
|
|
990
|
-
if (!score && twins.length > 1) continue;
|
|
991
|
-
if (score && anchor.section && sectionOf(n) === anchor.section) score += 2;
|
|
992
|
-
const d = Math.abs(n.getBoundingClientRect().top + scrollY - (anchor.docY || 0));
|
|
993
|
-
if (score > best || score === best && d < near) [found, best, near] = [n, score, d];
|
|
994
|
-
}
|
|
995
|
-
return best > 0 || !atPath ? found : atPath;
|
|
996
|
-
}
|
|
997
|
-
var wordCache = null;
|
|
998
|
-
function wordSpot(anchor) {
|
|
999
|
-
const m = /^(?:…)?(.*?)\[([^\]]+)\](.*?)(?:…)?$/s.exec(anchor.text || "");
|
|
1000
|
-
if (!m) return null;
|
|
1001
|
-
const before = m[1].replace(/\s+/g, " ").slice(-24);
|
|
1002
|
-
const word = m[2];
|
|
1003
|
-
if (!wordCache || performance.now() - wordCache.at > 400) {
|
|
1004
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, { acceptNode: (t) => host.contains(t.parentNode) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT });
|
|
1005
|
-
let text2 = "";
|
|
1006
|
-
const at2 = [];
|
|
1007
|
-
for (let t = walker.nextNode(); t; t = walker.nextNode()) {
|
|
1008
|
-
const v = t.data.replace(/\s+/g, " ");
|
|
1009
|
-
for (let i2 = 0; i2 < v.length; i2++) at2.push([t, i2]);
|
|
1010
|
-
text2 += v;
|
|
1011
|
-
}
|
|
1012
|
-
wordCache = { at: performance.now(), text: text2, map: at2 };
|
|
1013
|
-
}
|
|
1014
|
-
const { text, map: at } = wordCache;
|
|
1015
|
-
let i = text.indexOf(before + word);
|
|
1016
|
-
if (i < 0) return { gone: true };
|
|
1017
|
-
i += before.length;
|
|
1018
|
-
const range = document.createRange();
|
|
1019
|
-
try {
|
|
1020
|
-
range.setStart(...at[i]);
|
|
1021
|
-
range.setEnd(at[i + word.length - 1][0], at[i + word.length - 1][1] + 1);
|
|
1022
|
-
} catch {
|
|
1023
|
-
return { gone: true };
|
|
1024
|
-
}
|
|
1025
|
-
const r = range.getBoundingClientRect();
|
|
1026
|
-
return r.width || r.height ? { left: r.left + scrollX + Math.min(6, r.width / 2), top: r.top + scrollY + r.height / 2 } : { gone: true };
|
|
1027
|
-
}
|
|
1028
|
-
var pageEnd = { at: -Infinity, y: 0 };
|
|
1029
|
-
var inPage = (y, h = 0) => {
|
|
1030
|
-
if (performance.now() - pageEnd.at > 300) {
|
|
1031
|
-
const bottoms = [...document.body.children].filter((c) => c !== host && !host.contains(c)).map((c) => c.getBoundingClientRect().bottom + scrollY);
|
|
1032
|
-
pageEnd = { at: performance.now(), y: Math.max(innerHeight, ...bottoms) };
|
|
1033
|
-
}
|
|
1034
|
-
return Math.max(0, Math.min(y, pageEnd.y - h - 40));
|
|
1035
|
-
};
|
|
1036
|
-
var pinOf = (zone, anchor) => ({ left: zone.left + (anchor.pinX ? zone.width : 0), top: zone.top + (anchor.pinY ? zone.height : 0) });
|
|
1037
|
-
var EDGE = 10;
|
|
1038
|
-
function position(anchor) {
|
|
1039
|
-
const at = spotOf(anchor);
|
|
1040
|
-
return at.moved ? { ...at, left: EDGE } : at;
|
|
1041
|
-
}
|
|
1042
|
-
function spotOf(anchor) {
|
|
1043
|
-
const node = findTarget(anchor);
|
|
1044
|
-
if (node && !anchor.zw && !anchor.docW && /^(html|body|main)$/.test(node.localName) && /\[[^\]]+\]/.test(anchor.text || "")) {
|
|
1045
|
-
const spot = wordSpot(anchor);
|
|
1046
|
-
if (spot && !spot.gone) return { left: spot.left, top: spot.top, zone: null };
|
|
1047
|
-
if (spot?.gone) return { left: anchor.docX * docWidth(), top: inPage(anchor.docY), zone: null, moved: true };
|
|
1048
|
-
}
|
|
1049
|
-
if (node && anchor.eh && !anchor.zw && !anchor.docW && /^(html|body|main)$/.test(node.localName) && !/\[[^\]]+\]/.test(anchor.text || "")) {
|
|
1050
|
-
if (Math.abs(node.getBoundingClientRect().height - anchor.eh) > 40) return { left: anchor.docX * docWidth(), top: inPage(anchor.docY), zone: null, moved: true };
|
|
1051
|
-
}
|
|
1052
|
-
if (node) {
|
|
1053
|
-
const rect = node.getBoundingClientRect();
|
|
1054
|
-
if (rect.width || rect.height) {
|
|
1055
|
-
const left2 = rect.left + scrollX + anchor.x * rect.width;
|
|
1056
|
-
const tall = anchor.zw && Number.isFinite(anchor.oy) && anchor.docH && rect.height > 2 * anchor.docH;
|
|
1057
|
-
const top2 = rect.top + scrollY + (tall ? anchor.oy : anchor.y * rect.height);
|
|
1058
|
-
const zone2 = anchor.zw ? { left: left2, top: top2, width: anchor.zw * rect.width, height: tall ? anchor.docH : anchor.zh * rect.height } : null;
|
|
1059
|
-
return zone2 ? { ...pinOf(zone2, anchor), zone: zone2 } : { left: left2, top: top2, zone: zone2 };
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
const left = anchor.docX * docWidth();
|
|
1063
|
-
const top = inPage(anchor.docY, anchor.docH || 0);
|
|
1064
|
-
const zone = anchor.docW ? { left, top, width: anchor.docW, height: anchor.docH } : null;
|
|
1065
|
-
if (zone) return { ...pinOf(zone, anchor), zone, moved: Boolean(anchor.selector) && anchor.selector !== "body" };
|
|
1066
|
-
return { left, top, zone, moved: Boolean(anchor.selector) && anchor.selector !== "body" };
|
|
1067
|
-
}
|
|
1068
|
-
function quoteRange(anchor) {
|
|
1069
|
-
const q = anchor?.quote;
|
|
1070
|
-
let node = q?.exact ? findTarget(anchor) : null;
|
|
1071
|
-
if (!node) return null;
|
|
1072
|
-
const want = q.exact.replace(/\s+/g, "");
|
|
1073
|
-
const tail = (q.prefix || "").replace(/\s+/g, "").slice(-12);
|
|
1074
|
-
for (let up = 0; node && up < 4; node = node.parentElement, up++) {
|
|
1075
|
-
let text = "";
|
|
1076
|
-
const at = [];
|
|
1077
|
-
const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT);
|
|
1078
|
-
for (let t = walker.nextNode(); t; t = walker.nextNode())
|
|
1079
|
-
for (let i = 0; i < t.data.length; i++) {
|
|
1080
|
-
if (/\s/.test(t.data[i])) continue;
|
|
1081
|
-
text += t.data[i];
|
|
1082
|
-
at.push([t, i]);
|
|
1083
|
-
}
|
|
1084
|
-
let first = null;
|
|
1085
|
-
for (let i = text.indexOf(want); i !== -1; i = text.indexOf(want, i + 1)) {
|
|
1086
|
-
const range = document.createRange();
|
|
1087
|
-
range.setStart(...at[i]);
|
|
1088
|
-
const [end, k] = at[i + want.length - 1];
|
|
1089
|
-
range.setEnd(end, k + 1);
|
|
1090
|
-
if (!tail || text.slice(0, i).endsWith(tail)) return range;
|
|
1091
|
-
first ||= range;
|
|
1092
|
-
}
|
|
1093
|
-
if (first) return first;
|
|
1094
|
-
}
|
|
1095
|
-
return null;
|
|
1096
|
-
}
|
|
1097
|
-
var nameLine = (name, done) => {
|
|
1098
|
-
const b = el("b", {}, String(name || "").replace(/\s*·\s*session\s+\S+$/i, ""));
|
|
1099
|
-
if (done) b.append(el("span", { class: "mark done", role: "img", "aria-label": "done" }, "\u2713"));
|
|
1100
|
-
return b;
|
|
1101
|
-
};
|
|
1102
|
-
var DRAFT_MODE = false;
|
|
1103
|
-
var drafting = () => DRAFT_MODE && store.get("lab-hold") === "1";
|
|
1104
|
-
var linked = (text) => {
|
|
1105
|
-
const out = [];
|
|
1106
|
-
let at = 0;
|
|
1107
|
-
for (const m of text.matchAll(/\bhttps?:\/\/[^\s<>"']*[^\s<>"'.,;:!?)\]]/g)) {
|
|
1108
|
-
if (m.index > at) out.push(document.createTextNode(text.slice(at, m.index)));
|
|
1109
|
-
const a = el("a", { href: m[0], target: "_blank", rel: "noopener noreferrer", class: "link" }, m[0]);
|
|
1110
|
-
a.addEventListener("click", (e) => e.stopPropagation());
|
|
1111
|
-
out.push(a);
|
|
1112
|
-
at = m.index + m[0].length;
|
|
1113
|
-
}
|
|
1114
|
-
if (at < text.length) out.push(document.createTextNode(text.slice(at)));
|
|
1115
|
-
return out;
|
|
1116
|
-
};
|
|
1117
|
-
var sentences = (t) => t.split(/(?<=[.!?])\s+(?=["'([]?[A-Z0-9])/);
|
|
1118
|
-
var readable = (text) => {
|
|
1119
|
-
const blocks = [];
|
|
1120
|
-
for (const [n, para] of String(text || "").trim().split(/\n\s*\n/).entries()) {
|
|
1121
|
-
const lines = para.split("\n");
|
|
1122
|
-
if (lines.length === 1 && para.length > 240) {
|
|
1123
|
-
const ss = sentences(para);
|
|
1124
|
-
for (let i = 0; i < ss.length; i += 2) blocks.push({ text: ss.slice(i, i + 2).join(" "), gap: n > 0 || i > 0 });
|
|
1125
|
-
continue;
|
|
1126
|
-
}
|
|
1127
|
-
lines.forEach((line, i) => {
|
|
1128
|
-
const item = /^\s*(?:[-•*]|\d+[.)])\s+/.exec(line);
|
|
1129
|
-
const prev = i > 0 ? blocks.at(-1) : null;
|
|
1130
|
-
if (item) blocks.push({ li: /\d/.test(item[0]) ? item[0].trim() : "\u2022", text: line.slice(item[0].length), gap: n > 0 && i === 0 });
|
|
1131
|
-
else if (prev && !prev.li) prev.text += `
|
|
1132
|
-
${line}`;
|
|
1133
|
-
else blocks.push({ text: line, gap: n > 0 && i === 0 || Boolean(prev) });
|
|
1134
|
-
});
|
|
1135
|
-
}
|
|
1136
|
-
return blocks.map((b) => {
|
|
1137
|
-
const node = el("span", { class: `p${b.li ? " li" : ""}${b.gap ? " gap" : ""}` });
|
|
1138
|
-
if (b.li) node.append(el("span", { class: "mk" }, b.li));
|
|
1139
|
-
node.append(...linked(b.text));
|
|
1140
|
-
return node;
|
|
1141
|
-
});
|
|
1142
|
-
};
|
|
1143
|
-
var canMark = typeof Highlight === "function" && Boolean(CSS.highlights);
|
|
1144
|
-
var markQuote = (anchor) => {
|
|
1145
|
-
if (!canMark) return;
|
|
1146
|
-
const range = anchor && quoteRange(anchor);
|
|
1147
|
-
if (range) CSS.highlights.set("lab-quote", new Highlight(range));
|
|
1148
|
-
else CSS.highlights.delete("lab-quote");
|
|
1149
|
-
};
|
|
1150
|
-
var zoneEl = (cls) => {
|
|
1151
|
-
const z = el("div", { class: `zone ${cls}` });
|
|
1152
|
-
z.innerHTML = '<svg aria-hidden="true"><rect class="ring" width="100%" height="100%"/><rect class="dots" width="100%" height="100%"/></svg>';
|
|
1153
|
-
return z;
|
|
1154
|
-
};
|
|
1155
|
-
var drawZone = (box, cls) => {
|
|
1156
|
-
if (!box) return;
|
|
1157
|
-
const z = zoneEl(cls);
|
|
1158
|
-
Object.assign(z.style, { left: `${box.left}px`, top: `${box.top}px`, width: `${box.width}px`, height: `${box.height}px` });
|
|
1159
|
-
layer.append(z);
|
|
1160
|
-
return z;
|
|
1161
|
-
};
|
|
1162
|
-
function zoneAnchor({ x0, y0, x1, y1 }) {
|
|
1163
|
-
const left = Math.min(x0, x1);
|
|
1164
|
-
const top = Math.min(y0, y1);
|
|
1165
|
-
const right = Math.max(x0, x1);
|
|
1166
|
-
const bottom = Math.max(y0, y1);
|
|
1167
|
-
const anchor = anchorAt((left + right) / 2, (top + bottom) / 2);
|
|
1168
|
-
let box = document.elementsFromPoint((left + right) / 2, (top + bottom) / 2).find((n) => n !== host && !host.contains(n));
|
|
1169
|
-
const area = Math.max(1, (right - left) * (bottom - top));
|
|
1170
|
-
const contains = (r2) => Math.max(0, Math.min(r2.right, right) - Math.max(r2.left, left)) * Math.max(0, Math.min(r2.bottom, bottom) - Math.max(r2.top, top)) / area >= 0.8;
|
|
1171
|
-
while (box && box !== document.body && !contains(box.getBoundingClientRect())) box = box.parentElement;
|
|
1172
|
-
box ||= document.body;
|
|
1173
|
-
const r = box.getBoundingClientRect();
|
|
1174
|
-
Object.assign(anchor, {
|
|
1175
|
-
selector: box === document.body ? "body" : selectorFor(box),
|
|
1176
|
-
element: openingTag(box),
|
|
1177
|
-
x: r.width ? (left - r.left) / r.width : 0,
|
|
1178
|
-
y: r.height ? (top - r.top) / r.height : 0,
|
|
1179
|
-
zw: r.width ? (right - left) / r.width : 0,
|
|
1180
|
-
// may pass 1 a little: the area can reach past its element's edge
|
|
1181
|
-
zh: r.height ? (bottom - top) / r.height : 0,
|
|
1182
|
-
oy: Math.round(top - r.top),
|
|
1183
|
-
// px below the element's top: a share of a tall box drifts when it grows (pictures load)
|
|
1184
|
-
docX: (left + scrollX) / docWidth(),
|
|
1185
|
-
docY: top + scrollY,
|
|
1186
|
-
docW: Math.round(right - left),
|
|
1187
|
-
docH: Math.round(bottom - top),
|
|
1188
|
-
pinX: x1 >= x0 ? 1 : 0,
|
|
1189
|
-
// the drag ended on the right / at the bottom: the pin goes there
|
|
1190
|
-
pinY: y1 >= y0 ? 1 : 0
|
|
1191
|
-
});
|
|
1192
|
-
Object.assign(anchor, schemeAt(box));
|
|
1193
|
-
if (anchor.kind === "text") {
|
|
1194
|
-
delete anchor.quote;
|
|
1195
|
-
anchor.kind = "element";
|
|
1196
|
-
}
|
|
1197
|
-
const boxText = box === document.body ? "" : short(box.textContent, 200);
|
|
1198
|
-
if (boxText && (box.textContent || "").length < 400) anchor.text = short(boxText, 80);
|
|
1199
|
-
else delete anchor.text;
|
|
1200
|
-
if (box !== document.body) anchor.looks = looksOf(box);
|
|
1201
|
-
const words = [];
|
|
1202
|
-
const walker = document.createTreeWalker(box, NodeFilter.SHOW_TEXT);
|
|
1203
|
-
const range = document.createRange();
|
|
1204
|
-
for (let n = walker.nextNode(); n && words.length < 80; n = walker.nextNode()) {
|
|
1205
|
-
if (host.contains(n)) continue;
|
|
1206
|
-
const pr = n.parentElement?.getBoundingClientRect();
|
|
1207
|
-
if (!pr || pr.bottom < top || pr.top > bottom || pr.right < left || pr.left > right) continue;
|
|
1208
|
-
for (const m of n.data.matchAll(/\S+/g)) {
|
|
1209
|
-
range.setStart(n, m.index);
|
|
1210
|
-
range.setEnd(n, m.index + m[0].length);
|
|
1211
|
-
const w = range.getBoundingClientRect();
|
|
1212
|
-
const cx = (w.left + w.right) / 2;
|
|
1213
|
-
const cy = (w.top + w.bottom) / 2;
|
|
1214
|
-
if (w.width && cx >= left && cx <= right && cy >= top && cy <= bottom) words.push(m[0]);
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
const text = short(words.join(" "), 300);
|
|
1218
|
-
if (text) anchor.zoneText = text;
|
|
1219
|
-
const inArea = [];
|
|
1220
|
-
const all = box.querySelectorAll("*");
|
|
1221
|
-
for (let i = 0; i < all.length && i < 3e3; i++) {
|
|
1222
|
-
const el2 = all[i];
|
|
1223
|
-
if (host.contains(el2) || inArea.some((x) => x.contains(el2))) continue;
|
|
1224
|
-
const er = el2.getBoundingClientRect();
|
|
1225
|
-
if (er.width < 8 || er.height < 8 || er.left < left - 4 || er.right > right + 4 || er.top < top - 4 || er.bottom > bottom + 4) continue;
|
|
1226
|
-
inArea.push(el2);
|
|
1227
|
-
}
|
|
1228
|
-
if (inArea.length) {
|
|
1229
|
-
anchor.zoneItems = inArea.slice(0, 5).map((el2) => {
|
|
1230
|
-
const c = componentAt(el2);
|
|
1231
|
-
const t = short(el2.textContent, 50);
|
|
1232
|
-
return short([openingTag(el2), t && `"${t}"`, c.component, c.source && `written at ${c.source}`, c.usedAt && `used at ${c.usedAt}`].filter(Boolean).join(" \xB7 "), 500);
|
|
1233
|
-
});
|
|
1234
|
-
if (inArea.length > 5) anchor.zoneItems.push(`and ${inArea.length - 5} more`);
|
|
1235
|
-
}
|
|
1236
|
-
if (/^(img|video)$/.test(box.localName)) {
|
|
1237
|
-
const nw = box.localName === "img" ? fileSize(box).nw : box.videoWidth;
|
|
1238
|
-
const nh = box.localName === "img" ? fileSize(box).nh : box.videoHeight;
|
|
1239
|
-
const a = naturalSpot(box, r, left, top, nw, nh);
|
|
1240
|
-
const b = naturalSpot(box, r, right, bottom, nw, nh);
|
|
1241
|
-
if (a && b) Object.assign(anchor, { imgX: a.imgX, imgY: a.imgY, imgX2: b.imgX, imgY2: b.imgY });
|
|
1242
|
-
} else if (anchor.kind === "image" || anchor.kind === "video") {
|
|
1243
|
-
delete anchor.imgX;
|
|
1244
|
-
delete anchor.imgY;
|
|
1245
|
-
anchor.kind = "element";
|
|
1246
|
-
}
|
|
1247
|
-
return anchor;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
// src/comments.js
|
|
1251
|
-
/*!
|
|
1252
|
-
* lab comments: anyone with the link clicks anywhere on a lab page to pin a comment. No login, just a name.
|
|
1253
|
-
* https://github.com/leonidstern/labit · MIT
|
|
1254
|
-
* Comments are off by default; the bar button or c turns them on (remembered per browser). When on, click anywhere that isn't a link or control to pin one (alt/option-click pins on those too). c (or the bar button) hides
|
|
1255
|
-
* and shows them; esc or a click outside closes an open comment. Dragging (mouse/pen) marks an area instead of a point.
|
|
1256
|
-
* Include on a page served through your lab domain:
|
|
1257
|
-
* <script src="https://lab.example.com/_lab/comments.js" defer><\/script>
|
|
1258
|
-
* The layer only turns on when the page is opened on the host the script is loaded from (or data-host),
|
|
1259
|
-
* so the deployment's own address and local dev stay clean. data-enable="always" turns it on everywhere.
|
|
1260
|
-
* Admin (resolve / delete / copy agent link): open any page once with ?lab-admin=<LAB_COMMENTS_ADMIN_TOKEN>; it is kept in this browser.
|
|
1261
|
-
*/
|
|
1262
|
-
(() => {
|
|
1263
|
-
const script = (
|
|
1264
|
-
/** @type {HTMLScriptElement | null} */
|
|
1265
|
-
document.currentScript
|
|
1266
|
-
);
|
|
1267
|
-
const labHost = script?.dataset.host || (script?.src ? new URL(script.src, location.href).hostname : location.hostname);
|
|
1268
|
-
const enabled = location.hostname === labHost || script?.dataset.enable === "always";
|
|
1269
|
-
if (!enabled || /** @type {any} */
|
|
1270
|
-
window.__labComments) return;
|
|
1271
|
-
window.__labComments = true;
|
|
1272
|
-
const API = script?.dataset.api || "/_lab/api/comments";
|
|
1273
|
-
const pageNow = () => script?.dataset.page || location.pathname.replace(/\/+$/, "") || "/";
|
|
1274
|
-
let page = pageNow();
|
|
1275
|
-
const store2 = {
|
|
1276
|
-
get: (k) => {
|
|
1277
|
-
try {
|
|
1278
|
-
return localStorage.getItem(k) || "";
|
|
1279
|
-
} catch {
|
|
1280
|
-
return "";
|
|
1281
|
-
}
|
|
1282
|
-
},
|
|
1283
|
-
set: (k, v) => {
|
|
1284
|
-
try {
|
|
1285
|
-
localStorage.setItem(k, v);
|
|
1286
|
-
} catch {
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
};
|
|
1290
|
-
const scopeOf = (key) => key.split(".").length === 3 ? key.split(".")[1] : "";
|
|
1291
|
-
const adminParam = new URLSearchParams(location.hash.slice(1)).get("lab-admin") || new URLSearchParams(location.search).get("lab-admin");
|
|
1292
|
-
if (adminParam) {
|
|
1293
|
-
const scope = scopeOf(adminParam);
|
|
1294
|
-
store2.set(scope ? `lab-admin:${scope}` : "lab-admin", adminParam);
|
|
1295
|
-
const url = new URL(location.href);
|
|
1296
|
-
url.searchParams.delete("lab-admin");
|
|
1297
|
-
if (/lab-admin=/.test(url.hash)) url.hash = "";
|
|
1298
|
-
history.replaceState(null, "", url);
|
|
1299
|
-
}
|
|
1300
|
-
const adminToken = script?.dataset.admin || store2.get(`lab-admin:${page.split("/")[1] || ""}`) || store2.get("lab-admin:*") || store2.get("lab-admin");
|
|
1301
|
-
let comments = [];
|
|
1302
|
-
let isAdmin = false;
|
|
1303
|
-
let on = store2.get("lab-on") ? store2.get("lab-on") === "1" : script?.dataset.on === "1";
|
|
1304
|
-
let openId = null;
|
|
1305
|
-
let closeFast = false;
|
|
1306
|
-
let cardFull = false;
|
|
1307
|
-
let draft = null;
|
|
1308
|
-
const host2 = document.createElement("div");
|
|
1309
|
-
host2.setAttribute("data-lab-comments", "");
|
|
1310
|
-
host2.style.cssText = "position:absolute;top:0;left:0;width:0;height:0;z-index:2147483000;";
|
|
1311
|
-
const root = host2.attachShadow({ mode: "open" });
|
|
1312
|
-
root.innerHTML = `
|
|
1313
|
-
<style>${styles_default}</style>
|
|
1
|
+
(()=>{var Gn=':host{all:initial;--_bg: var(--lab-bg, #fff);--_fg: var(--lab-fg, #141414);--_accent: var(--lab-accent, #141414);--_accent-fg: var(--lab-accent-fg, #fff);--_radius: var(--lab-radius, 12px);--_r-s: 6px ;--_soft: var(--lab-soft, rgba(0,0,0,.05));--_hover: var(--lab-hover, rgba(0,0,0,.1));--_line: var(--lab-line, rgba(0,0,0,.15));--_edge: var(--lab-edge, #c7c7cc);--_muted: var(--lab-muted, rgba(0,0,0,.5));--_hair: .5px solid color-mix(in srgb, var(--_fg) 16%, transparent);--_shadow: 0 0 0 .5px color-mix(in srgb, var(--_fg) 14%, transparent), 0 1px 2px rgba(0,0,0,.04), 0 8px 28px rgba(0,0,0,.08);--_ease: cubic-bezier(.2, .8, .2, 1)}@media(prefers-color-scheme:dark){:host{--_bg: var(--lab-bg, #1c1c1e);--_fg: var(--lab-fg, #f4f4f5);--_accent: var(--lab-accent, #f4f4f5);--_accent-fg: var(--lab-accent-fg, #141414);--_soft: var(--lab-soft, rgba(255,255,255,.05));--_hover: var(--lab-hover, rgba(255,255,255,.1));--_line: var(--lab-line, rgba(255,255,255,.15));--_edge: var(--lab-edge, #48484a);--_muted: var(--lab-muted, rgba(255,255,255,.5));--_shadow: 0 0 0 1px color-mix(in srgb, var(--_fg) 16%, transparent), 0 10px 32px rgba(0,0,0,.5)}}*{box-sizing:border-box;font-family:var(--lab-font, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);font-size:14px;line-height:1.4;font-weight:400;color:var(--_fg);letter-spacing:-.011em;font-feature-settings:var(--lab-font-features, normal);font-synthesis:none;font-optical-sizing:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility;caret-color:var(--_accent);-webkit-tap-highlight-color:transparent}::selection{background:color-mix(in srgb,var(--_accent) 38%,transparent);color:var(--_fg)}button:focus-visible{outline:2px solid var(--_accent);outline-offset:2px}.layer{position:absolute;top:0;left:0;width:0;height:0}.pin{position:absolute;width:28px;height:28px;margin:-28px 0 0;border-radius:14px 14px 14px 2px;background:var(--_bg);border:0;box-shadow:0 0 0 1px var(--_edge),0 2px 8px #00000029;display:grid;place-items:center;cursor:pointer;padding:0;color:var(--_fg);font-size:12px;font-weight:500;font-variant-numeric:tabular-nums;letter-spacing:0;transform-origin:0 100%;transition:transform .16s var(--_ease),box-shadow .16s var(--_ease),opacity .16s}button.pin:hover,button.pin.open{transform:scale(1.08);box-shadow:0 0 0 1.5px #24a046,0 4px 14px #0003}button.pin:active{transform:scale(.96)}.pin.in{animation:lab-pin .26s var(--_ease)}.pin.arrive{animation:lab-arrive .46s cubic-bezier(.34,1.56,.64,1) both}@keyframes lab-arrive{0%{opacity:0;transform:scale(.7)}}.pin.swap{animation:lab-swap .36s cubic-bezier(.3,.7,.4,1.25)}@keyframes lab-swap{0%{transform:scale(.72);opacity:.35}}.pin .ring.gone{animation:lab-gone .3s ease-in forwards}@keyframes lab-gone{to{opacity:0}}button.pin.in:before{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none;animation:lab-halo .9s cubic-bezier(.2,.7,.3,1) forwards}.pin.resolved{color:#24a046}button.pin.go{background:var(--_bg);color:#24a046;font-size:11px;font-weight:600;letter-spacing:.006em;box-shadow:inset 0 0 0 1.5px #24a046,0 2px 8px #00000029}button.pin.go.done{background:#24a046;color:#fff;box-shadow:0 0 0 .5px color-mix(in srgb,var(--_fg) 22%,transparent),0 2px 8px #00000029}button.pin.done:not(.go){color:#24a046}.pin.moved:not(.resolved,.done){opacity:.5;scale:.8}button.pin.moved:hover,button.pin.moved.open{opacity:1}.pin.grab{touch-action:none}button.pin.dragging{cursor:grabbing;transform:scale(1.1);opacity:1;box-shadow:0 0 0 .5px color-mix(in srgb,var(--_fg) 30%,transparent),0 8px 20px #00000038}.zone{position:absolute;background:none;border-radius:var(--_radius);pointer-events:none}.zone svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none}.zone rect{fill:none;stroke-linecap:round;stroke-dasharray:0 4;rx:var(--lab-radius, 12px);ry:var(--lab-radius, 12px)}.zone rect.ring{display:none}.zone rect.dots{stroke:#34c759;stroke-width:1.5}.zone.live{left:0;top:0;will-change:transform,width,height;animation:lab-fade .12s ease-out}.pin .ring{position:absolute;inset:-4px;border-radius:18px 18px 18px 6px;padding:2px;overflow:hidden;pointer-events:none;-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);-webkit-mask-composite:xor;mask:linear-gradient(#000 0 0) content-box exclude,linear-gradient(#000 0 0)}.ring:before{content:"";position:absolute;inset:-50%;will-change:transform;background:conic-gradient(rgb(52,199,89) 0 var(--lab-arc, 66%),rgba(52,199,89,.22) var(--lab-arc, 66%) 100%);animation:lab-turn 1.2s linear infinite}@keyframes lab-turn{to{transform:rotate(360deg)}}.pin .ring.come:before{animation:lab-draw .4s ease-out,lab-turn 1.2s linear infinite}@keyframes lab-draw{0%{--lab-arc: 0%}}.ptr{position:fixed;left:0;top:0;width:28px;height:28px;border-radius:14px 14px 14px 2px;corner-shape:round;background:var(--_bg);box-shadow:0 0 0 .5px color-mix(in srgb,var(--_fg) 30%,transparent),0 2px 6px #0000002e;display:grid;place-items:center;pointer-events:none;z-index:2147483647;opacity:0;will-change:transform;transition:opacity .12s ease-out,background-color .16s ease-out}.ptr.show{opacity:1}.ptr span{grid-area:1 / 1;font-size:12px;letter-spacing:0;font-weight:600;line-height:1;transition:opacity .16s ease-out,transform .16s ease-out}.ptr .tick{opacity:0;transform:scale(.5);color:#fff;font-size:11px;letter-spacing:.006em}.ptr.go{background:#24a046}.ptr.go .ini{opacity:0;transform:scale(.5)}.ptr.go .tick{opacity:1;transform:none}.pin.new:after{content:"";position:absolute;top:-4px;right:-4px;width:9px;height:9px;border-radius:50%;background:var(--_fg);box-shadow:0 0 0 2px var(--_bg)}.dot{display:inline-block;width:6px;height:6px;border-radius:50%;background:var(--_accent);margin:0 6px 1px 0}.card{position:absolute;width:320px;max-width:calc(100vw - 24px);background:var(--_bg);border-radius:var(--_radius);box-shadow:var(--_shadow);padding:12px 14px 14px;transform-origin:14px 0;z-index:1;display:flex;flex-direction:column;max-height:min(460px,62vh)}.card>.body{flex:0 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;margin-right:-8px;padding-right:8px}.card>.foot{flex:none}.card.in,.float.in{animation:lab-in .18s var(--_ease)}.card.out,.float.out{animation:lab-out .14s ease-in forwards;pointer-events:none}.item{display:grid;row-gap:3px}.item+.item{margin-top:14px}.msg.item{display:block}.msg.item+.msg.item{margin-top:0}.meta{display:flex;align-items:baseline;gap:.5em;font-size:12px;color:var(--_muted);margin:0;white-space:nowrap;letter-spacing:0;font-variant-numeric:tabular-nums}.meta b{font-weight:500;font-size:13px;letter-spacing:-.006em;min-width:0;overflow:hidden;text-overflow:ellipsis}.meta .dot{flex:none;align-self:center;margin:0}.meta .ago{white-space:nowrap}.text{white-space:pre-wrap;overflow-wrap:anywhere;text-wrap:pretty}.row{display:flex;gap:12px;justify-content:flex-start;align-items:center;margin-top:8px}.card .row:not(.nav){justify-content:flex-end;gap:10px}.card .row:not(.nav) button.btn{font-size:12px;letter-spacing:0}button.btn{border:0;padding:2px 0;cursor:pointer;background:none;color:var(--_muted);font-size:12px;letter-spacing:0;border-radius:var(--_r-s);transition:color .12s}button.btn:hover{color:var(--_fg)}button.btn.danger,button.btn.danger:hover{color:#e5484d}.row .ask{white-space:nowrap;color:var(--_fg);font-size:12px;letter-spacing:0;padding:2px 0;animation:lab-fade .12s ease-out}.float{position:absolute;width:320px;max-width:calc(100vw - 24px);transform-origin:0 20px;z-index:1}.card .composer{margin-top:6px}.card>.body>.row:not(.nav){margin-right:7px}.box{display:grid;grid-template-columns:1fr auto;grid-template-areas:"text send";align-items:center;column-gap:8px;border-radius:var(--_radius);padding:7px 7px 7px 14px;margin:0;transition:box-shadow .15s;background:var(--_box-bg, var(--_soft));box-shadow:var(--_box-edge, none)}.float{--_box-bg: var(--_bg);--_box-edge: 0 0 0 1px var(--_edge), 0 1px 2px rgba(0,0,0,.06), 0 8px 26px rgba(0,0,0,.14)}.box.open{grid-template-areas:"text text" "line line" "who send";row-gap:8px;padding:7px 7px 8px 14px}.box textarea{grid-area:text;width:100%;border:0;background:none;padding:2px 0;line-height:20px;margin:0;resize:none;min-height:0;max-height:200px;overflow-y:auto;outline:none;display:block}.box textarea::placeholder,.who input::placeholder{color:var(--_muted);opacity:1}.line{grid-area:line;height:0;border-top:var(--_hair);margin:0 -7px 0 -14px;display:none}.who{grid-area:who;display:none;align-items:baseline;gap:4px;min-width:0;font-size:13px;color:var(--_muted);letter-spacing:-.006em}.who *{font-size:13px;letter-spacing:-.006em}.who span{color:var(--_muted)}.who input{flex:1;min-width:0;border:0;background:none;padding:0;margin:0;outline:none;color:var(--_muted);text-overflow:ellipsis}.who input:focus{color:var(--_fg)}.box.open .line{display:block;animation:lab-fade .16s ease-out}.box.open .who{display:flex;animation:lab-fade .16s ease-out}.box.one,.box.one.open{grid-template-columns:minmax(0,1fr) auto auto;grid-template-areas:"text who send";align-items:end;row-gap:0;padding:7px 7px 7px 14px}.box.one .line{display:none!important}.box.one .who{align-self:end;line-height:20px;padding-bottom:2px;max-width:40%}.box.one .who input{flex:none;field-sizing:content;min-width:2ch;max-width:9em}.send{grid-area:send;width:24px;height:24px;border-radius:50%;border:0;padding:0;cursor:pointer;background:var(--_hover);color:var(--_muted);display:grid;place-items:center;transition:background .15s,color .15s,transform .15s var(--_ease)}.send.ready:hover{transform:scale(1.06)}.send.ready:active{transform:scale(.94)}.send.ready{background:var(--_accent);color:var(--_accent-fg);animation:lab-ready .16s ease-out}@keyframes lab-ready{50%{transform:scale(1.08)}}.send .arr{display:block;position:relative;left:-1px;width:12px;height:11px;background:currentColor;clip-path:polygon(0 42%,100% 0,66% 100%,46% 60%)}.send *{color:inherit}.error{color:#e5484d;font-size:12px;padding:6px 8px 0;letter-spacing:0}.error:empty{display:none}.error.wait{color:var(--_muted)}.bar{position:fixed;right:16px;bottom:16px;display:flex;gap:8px;align-items:center}.bar button{border:0;border-radius:var(--_radius);padding:9px 14px;cursor:pointer;background:var(--_bg);color:var(--_fg);box-shadow:var(--_shadow);font-size:13px;font-weight:500;display:inline-flex;gap:8px;align-items:center;letter-spacing:-.006em;font-variant-numeric:tabular-nums;white-space:nowrap;transition:color .15s,transform .15s var(--_ease)}.bar button:active{transform:scale(.97)}.list{position:fixed;right:16px;bottom:66px;width:min(340px,calc(100vw - 32px));max-height:min(60vh,460px);overflow:hidden;display:flex;flex-direction:column;background:var(--_bg);color:var(--_fg);border-radius:var(--_radius);box-shadow:var(--_shadow);font-size:13px;letter-spacing:-.006em}.list .tabs{display:flex;flex-wrap:wrap;gap:2px;flex:none;padding:12px 8px 6px}.list .items,.msgs{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain}.list .items{padding:0 6px 6px}.list .tabs button{border:0;border-radius:var(--_r-s);padding:4px 8px;white-space:nowrap;background:none;color:var(--_muted);cursor:pointer;font:inherit}.list .tabs button.on{background:var(--_fg);color:var(--_bg)}.list .tabs .hold{margin-left:auto}.list .it{display:block;width:100%;text-align:left;border:0;background:none;color:inherit;padding:7px 8px;border-radius:var(--_r-s);cursor:pointer;font:inherit}.list .it:hover,.list .it.cur{background:var(--_hover)}.list .it{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.list .it span,.list .none{color:var(--_muted)}.list .it .tag{display:inline-block;padding:0 7px;border-radius:var(--_r-s);background:var(--_accent);color:var(--_accent-fg);font-size:12px;letter-spacing:0;font-weight:600;line-height:18px;vertical-align:1px;white-space:nowrap}.list .none{padding:8px}*{scrollbar-width:thin;scrollbar-color:color-mix(in srgb,var(--_fg) 24%,transparent) transparent}@supports not (scrollbar-width: thin){::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:color-mix(in srgb,var(--_fg) 24%,transparent);border-radius:999px}}.list .group{font-size:11px;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--_muted);padding:10px 8px 2px}.pin.held{border:1.5px dashed var(--_muted);opacity:.85}.list .tabs .show-done{color:var(--_muted)}.chatwin .tabs b{display:none}.list .tabs .x{margin-left:auto;flex:none;width:26px;height:26px;padding:0;border-radius:50%;display:grid;place-items:center;font-size:0;color:var(--_muted);background:transparent}.list .tabs .x:before,.list .tabs .x:after{content:"";grid-area:1 / 1;width:12px;height:1.6px;border-radius:1px;background:currentColor;transform:rotate(45deg)}.list .tabs .x:after{transform:rotate(-45deg)}.list .tabs .x:hover{color:var(--_fg)}.list .tabs .x:focus-visible{outline:2px solid var(--_accent);outline-offset:1px}.chatwin .chat{flex:none;background:var(--_bg);padding:6px 6px 8px}.chatwin .replying{flex:none}.chatwin .tabs b{padding:4px 8px;font-weight:600;margin-right:auto}.msgs{display:flex;flex-direction:column;gap:8px;padding:4px 10px 8px;overflow-x:hidden}.msgs>:first-child{margin-top:auto}.fresh{animation:lab-rise .2s var(--_ease)}.send.sent .arr{animation:lab-fly .32s var(--_ease)}@keyframes lab-rise{0%{opacity:0;transform:translateY(6px)}}@keyframes lab-fly{45%{transform:translate(9px,-9px) scale(.6);opacity:0}46%{transform:translate(-7px,7px) scale(.6);opacity:0}}.msg{max-width:85%;padding:7px 10px;border-radius:var(--_radius);background:var(--_soft);align-self:flex-start}.msg.mine{align-self:flex-end;background:color-mix(in srgb,rgb(52,199,89) 15%,var(--_bg));color:var(--_fg)}.msg b{display:block;font-size:12px;letter-spacing:0;font-weight:600;opacity:.7;margin-bottom:1px}.msg[data-agent=claude]{--_brand: #d97757}.msg[data-agent=codex]{--_brand: #10a37f}.msg[data-agent=cursor]{--_brand: #8a8a8e}.msg[data-agent=gemini]{--_brand: #4285f4}.msg[data-agent=copilot]{--_brand: #8957e5}.msg[data-agent=amp]{--_brand: #f34e3f}.msg[data-agent=opencode]{--_brand: #8a8a8e}.msg[data-agent]{background:color-mix(in srgb,var(--_brand) 11%,var(--_bg))}.msg[data-agent]>b{color:var(--_brand);opacity:1}.msg.mine b{display:none}.msg{position:relative}.mark{font-weight:400;font-size:11px;letter-spacing:.006em;color:var(--_muted);margin-left:6px;white-space:nowrap}.mark.done{color:#24a046;font-weight:600;font-size:12px;letter-spacing:0}.msg .quote{display:block;border-left:2px solid rgb(52,199,89);padding:1px 0 1px 8px;margin:3px 0 5px;font-size:12px;letter-spacing:0;line-height:1.35;color:var(--_muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor:pointer}.msg .quote b{display:block;font-size:12px;letter-spacing:0;font-weight:600;color:#24a046;opacity:1;margin:0}.mine .mark{color:inherit;opacity:.7}a.link{color:inherit;text-decoration:underline;text-underline-offset:2px;overflow-wrap:anywhere}.msg.to{box-shadow:0 0 0 2px var(--_accent)}.msg .p{display:block;white-space:pre-wrap;overflow-wrap:anywhere;text-wrap:pretty}.msg .p.gap{margin-top:6px}.msg .p.li{padding-left:14px;text-indent:-14px}.msg .p.li .mk{display:inline-block;width:14px;text-indent:0;opacity:.6}.msg i{display:block;font-style:normal;font-size:12px;letter-spacing:0;opacity:.7;margin-bottom:1px}.msg b,.msg i{color:inherit}.msg .stamp{text-indent:0;color:inherit;position:absolute;right:10px;bottom:6px;font-size:10px;letter-spacing:.012em;line-height:1;opacity:.55;font-variant-numeric:tabular-nums}.msg .stamp-room{text-indent:0;visibility:hidden;display:inline-block;margin-left:10px;font-size:10px;letter-spacing:.012em;line-height:1;height:10px;white-space:nowrap}.msg .stamp-room *{font-size:inherit}.msg .tick{color:inherit;margin-left:4px;letter-spacing:-.34em;font-size:10px}.msg .tick.got{font-weight:600}.msg .stamp:is(.busy,.ans){opacity:1}.msg .stamp:is(.busy,.ans) .tm{opacity:.55}.msg .stamp .tm{font-size:inherit;line-height:inherit;color:inherit}.msg :is(.stamp,.stamp-room) .ring{position:relative;display:inline-block;width:9px;height:9px;margin-left:5px;vertical-align:-1px;border-radius:50%;overflow:hidden;-webkit-mask:radial-gradient(farthest-side,transparent calc(100% - 1.6px),#000 calc(100% - 1.5px));mask:radial-gradient(farthest-side,transparent calc(100% - 1.6px),#000 calc(100% - 1.5px))}.msg .stamp.ans .tick{color:#24a046;letter-spacing:0;font-weight:600}.msg :is(.stamp,.stamp-room) .tick{display:inline-block;width:12px;height:10px;line-height:10px;text-align:center;margin-left:4px;vertical-align:top}.msg :is(.stamp,.stamp-room) .ring{margin:.5px 1.5px 0 5.5px;vertical-align:top}.msg .stamp{height:10px}.replying{display:flex;gap:6px;align-items:center;font-size:12px;letter-spacing:0;color:var(--_muted);padding:2px 6px}.replying button{border:0;background:none;color:inherit;cursor:pointer;margin-left:auto;font:inherit}.bar button *{color:inherit;font-weight:inherit}.bar .toggle:not(.secondary):before{content:"";width:7px;height:7px;border-radius:50%;background:var(--_accent)}.bar button.secondary{color:var(--_muted)}.bar button.secondary.has-new{color:var(--_fg);font-weight:600}.bar button.go-btn.on{color:#fff;background:#24a046}.bar .new-prev,.bar .new-next{padding:9px 11px;font-size:15px;letter-spacing:-.016em;line-height:1;color:var(--_fg)}.bar .list-btn,.bar .done-btn{font-variant-numeric:tabular-nums;min-width:4.6em;justify-content:center}.bar button.quiet{opacity:.45;cursor:default;box-shadow:var(--_shadow)}.bar button.go-btn.on kbd{color:#fff!important}.newline{display:flex;align-items:center;gap:8px;font-size:12px;letter-spacing:0;font-weight:500;color:var(--_muted)}.newline:before,.newline:after{content:"";flex:1;height:1px;background:currentColor;opacity:.35}.left{position:fixed;left:16px;bottom:16px;display:flex;gap:8px;align-items:center}.left .copy-all{border:0;border-radius:var(--_radius);padding:9px 14px;cursor:pointer;background:var(--_bg);color:var(--_muted);box-shadow:var(--_shadow);font:inherit;font-size:13px;letter-spacing:-.006em;font-weight:500;white-space:nowrap}.listener{display:inline-flex;gap:6px;align-items:center;padding:9px 14px;border-radius:var(--_radius);background:var(--_bg);color:var(--_fg);box-shadow:var(--_shadow);font-size:13px;letter-spacing:-.006em;text-decoration:none;white-space:nowrap}.listener span{color:var(--_muted)}.listener .lbl{display:contents}.mark{width:16px;height:16px;flex:none;overflow:visible;fill:var(--_accent)}.mark .eye{fill:var(--_bg)}.listener .mark{margin:-2px 0 -1px -3px}.listener.idle .mark{fill:var(--_muted);opacity:.5}.listener.working .mark{fill:#24a046}.mark :is(.e1,.e2,.eye){transform-box:fill-box;transform-origin:35% 100%}.mark .eye{transform-origin:50% 50%}.listener:not(.idle,.working) .mark .eye{animation:lab-blink 3.2s ease-in-out infinite}.listener.working .mark :is(.e1,.e2){animation:lab-twitch 2.4s ease-in-out infinite}.listener.working .mark .e2{animation-delay:.18s}@keyframes lab-blink{0%,88%,to{transform:scaleY(1)}92%,96%{transform:scaleY(.08)}}@keyframes lab-twitch{0%,62%,to{transform:rotate(0)}70%{transform:rotate(-9deg)}80%{transform:rotate(5deg)}90%{transform:rotate(-3deg)}}.listener{cursor:default}kbd{font-size:10px;letter-spacing:.012em;line-height:17px;min-width:0;padding:0 1px;text-align:center;background:none;color:var(--_muted)!important;opacity:.45;transition:opacity .15s}.bar:hover kbd{opacity:.75}.bar button kbd{margin-left:-4px}.bar button.go-btn kbd{font-size:inherit;line-height:inherit;opacity:1;margin-left:0}@media all{.bar{gap:0;background:var(--_bg);border-radius:var(--_radius);box-shadow:var(--_shadow);overflow:hidden}.bar>button{box-shadow:inset .5px 0 0 var(--_line);border-radius:0;background:none;padding:8px 12px;gap:6px}.bar>button.first{box-shadow:none}@media(hover:hover)and (pointer:fine){.bar>button:not(:disabled):hover{background:var(--_soft)}.bar>button:active{background:var(--_soft)}}.bar>.more[aria-expanded=true]{background:var(--_soft)}.bar>button:active{transform:none}.bar>button.quiet{opacity:1;box-shadow:inset .5px 0 0 var(--_line);color:var(--_muted)}.bar>button.quiet.first{box-shadow:none}.bar .list-btn,.bar .done-btn{min-width:0}.bar .mn{color:var(--_muted);font-weight:400}.bar>button.secondary,.bar>button.secondary.has-new{color:var(--_muted);font-weight:500}.bar .chat-btn,.bar .list-btn{align-items:baseline}.bar .cnt{font-size:12px;letter-spacing:0;font-weight:400;line-height:16px;text-align:center;background:none;color:var(--_fg);font-variant-numeric:tabular-nums}.bar .cnt.zero{color:var(--_muted)}.bar .cnt:not(.zero){color:#24a046}.bar button.go-btn.on{background:none;color:var(--_fg)}.bar button.go-btn.on kbd{color:var(--_muted)!important}.gp{display:inline-grid;place-items:center;width:22px;height:22px;border-radius:11px 11px 11px 2px;font-size:10px;letter-spacing:.012em;font-weight:600;color:#24a046;box-shadow:inset 0 0 0 1.25px #24a046;transition:background-color .2s,color .2s}.go-btn.on .gp{background:#24a046;color:#fff}.go-btn:not(.on):not(.cursor) .gp{color:var(--_fg);background:var(--_bg);box-shadow:inset 0 0 0 1px var(--_edge);font-size:10px;letter-spacing:.012em}.go-btn.cursor .gp{color:transparent;background:var(--_bg);box-shadow:inset 0 0 0 1px var(--_edge);position:relative}.go-btn.cursor .gp:after{content:"off";position:absolute;inset:0;display:grid;place-items:center;color:var(--_muted);font-size:10px;font-weight:600;letter-spacing:0}.more{font-size:15px!important;letter-spacing:.05em}.more-menu{position:fixed;right:16px;bottom:60px;display:grid;min-width:180px;padding:4px;background:var(--_bg);border-radius:var(--_radius);box-shadow:var(--_shadow);animation:lab-fade .12s ease-out}.more-menu[hidden]{display:none}.more-menu button{border:0;background:none;text-align:left;font:inherit;font-size:13px;letter-spacing:-.006em;color:var(--_fg);padding:7px 10px;border-radius:var(--_r-s);cursor:pointer;display:flex;justify-content:space-between;align-items:center;gap:12px;white-space:nowrap}.more-menu button:hover:not(:disabled){background:var(--_soft)}.more-menu button:disabled{color:var(--_muted);cursor:default}.more-menu button[hidden]{display:none}.pin .agentmark{width:60%;height:60%;display:block}.more-menu .trying-head{margin:4px 10px 2px;padding-top:6px;border-top:var(--_hair);font-size:11px;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:var(--_muted)}.more-menu button.trying{justify-content:flex-start;gap:8px;white-space:normal}.more-menu button.trying .box{width:1em;color:var(--_muted)}.more-menu button.trying[aria-checked=true] .box{color:var(--_fg)}.more-menu kbd{margin:0}}kbd:before{content:"("}kbd:after{content:")"}.hint{position:fixed;left:50%;bottom:64px;transform:translate(-50%);background:var(--_bg);color:var(--_muted);box-shadow:var(--_shadow);padding:8px 14px;border-radius:var(--_radius);font-size:13px;pointer-events:none;white-space:nowrap;letter-spacing:-.006em;animation:lab-fade .2s ease-out}@media(pointer:coarse){.box textarea,.who input{font-size:16px;letter-spacing:-.019em}kbd{display:none}.box textarea{line-height:22px;padding:7px 0}.box.one .who{line-height:22px;padding-bottom:7px}}@keyframes lab-fade{0%{opacity:0}}@keyframes lab-in{0%{transform:translateY(4px) scale(.98)}}@keyframes lab-out{to{opacity:0;transform:translateY(2px) scale(.985)}}@supports (corner-shape: squircle){:host{--_radius: calc(var(--lab-radius, 12px) * 1.8);--_r-s: 11px}*,*:before,*:after{corner-shape:squircle}.pin,.pin .ring,.pin.new:after,.dot,.send,.list .tabs .x,.bar .toggle:not(.secondary):before,.msg :is(.stamp,.stamp-room) .ring,.gp{corner-shape:round}}@keyframes lab-pin{0%{transform:scale(1.1)}}@keyframes lab-halo{0%{box-shadow:0 0 color-mix(in srgb,var(--_fg) 12%,transparent)}to{box-shadow:0 0 0 16px color-mix(in srgb,var(--_fg) 0%,transparent)}}@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important}}@media(max-width:480px){kbd{display:none}}.handle{display:none}@media(pointer:coarse)and (max-width:560px),(pointer:coarse)and (max-height:500px){:host{--_safe: env(safe-area-inset-bottom, 0px);--_kb: var(--lab-kb, 0px);--_sheet-max: calc(min(72dvh, var(--lab-vh, 100dvh) - 24px) + var(--_kb));--_pb: calc(12px + var(--_safe) + var(--_kb))}:host([data-kb]){--_safe: 0px;--_kb: 0px;--_pb: 10px}:host([data-kb]) :is(.card,.list:not([hidden])){top:var(--lab-top, 0px)!important;bottom:auto!important;height:var(--lab-vh, 100dvh)!important;max-height:none!important;border-radius:0}:host([data-kb]) .float{top:auto!important;bottom:var(--lab-kb, 0px)!important;height:auto!important;border-radius:var(--_radius) var(--_radius) 0 0}.card,.float{position:fixed;left:0!important;right:0;top:auto!important;bottom:0;width:auto;max-width:none;max-height:var(--_sheet-max);display:flex;flex-direction:column;border-radius:var(--_radius) var(--_radius) 0 0;padding:8px 0 0;z-index:3}.card:after,.float:after,.list:after{content:"";position:absolute;left:0;right:0;top:100%;height:100vh;background:var(--_bg)}.card>.body{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:0 12px 4px;margin-right:0}.card{height:var(--_sheet-max)}.card>.foot,.float>.composer{flex:none;padding:0 12px var(--_pb)}.card>.foot{margin-top:0;padding-top:6px}.card .composer{margin-top:0}.card>.nav{flex:none;margin:-6px 0 0;padding:0 12px;gap:20px}.card .nav .btn{font-size:14px;letter-spacing:-.011em;padding:0 2px;min-height:44px;display:inline-flex;align-items:center}.card .nav{gap:16px}.card .nav{flex-wrap:wrap;row-gap:0}.card .nav .acts{margin:0 0 0 auto;gap:20px}.box.one .who span{font-size:16px;letter-spacing:-.019em}.card .nav .acts button.btn{font-size:14px;letter-spacing:-.011em}.float{background:var(--_bg);box-shadow:var(--_shadow)}.handle{display:block;flex:none;height:86px;margin-top:-68px;touch-action:none;position:relative}.list .tabs{position:relative}.handle:after,.list .tabs:after{content:"";position:absolute;left:50%;top:68px;width:36px;height:4px;margin-left:-18px;border-radius:2px;background:color-mix(in srgb,var(--_fg) 18%,transparent);pointer-events:none}.list .tabs:after{top:8px}.list .tabs:before{content:"";position:absolute;left:0;right:0;top:-60px;height:60px}.list .tabs{touch-action:pan-x}.chatwin .tabs{touch-action:none}.list .items,.msgs,.card>.body{touch-action:pan-y}.list .tabs .x{display:none}:host([data-sheet]) :is(.hint,.listener,.left){visibility:hidden}.bar{transition:transform .34s cubic-bezier(.32,.72,0,1),opacity .2s}:host([data-sheet]) .bar{transform:translateY(calc((100% + 16px + env(safe-area-inset-bottom,0px)) * (1 - var(--lab-p, 0))));opacity:var(--lab-p, 0);pointer-events:none;transition:transform .24s cubic-bezier(.4,0,1,1),opacity .2s .04s}:host([data-sheet]) .bar button{pointer-events:none}:host([data-sheet]) .scrim{display:block;animation:lab-fade .22s ease-out}:host([data-opening]) :is(.card.in,.float.in,.scrim){animation-play-state:paused}:host([data-leaving]) .scrim{display:block}.list{left:0;right:0;bottom:0!important;width:auto;max-height:var(--_sheet-max);overflow:visible;border-radius:var(--_radius) var(--_radius) 0 0;font-size:15px;letter-spacing:-.016em;z-index:3}.chatwin{height:var(--_sheet-max);transition:height .38s cubic-bezier(.32,.72,0,1)}.chatwin.full,.card.full{height:calc(var(--lab-vh, 100dvh) - env(safe-area-inset-top,0px) - 10px + var(--_kb));max-height:none}.card{transition:height .38s cubic-bezier(.32,.72,0,1)}.list .tabs{flex-wrap:nowrap;overflow-x:auto;padding:18px 12px 8px;border-radius:var(--_radius) var(--_radius) 0 0;background:var(--_bg)}.list .items{padding:0 12px calc(10px + var(--_safe))}.chatwin .msgs{padding:4px 12px 8px}.chatwin .tabs{padding:18px 12px 0}.chatwin .chat{padding:6px 12px var(--_pb)}.chatwin .msgs{margin-bottom:calc(-56px - var(--_pb));padding-bottom:calc(64px + var(--_pb))}.card>.body{margin-bottom:calc(-56px - var(--_pb));padding-bottom:calc(64px + var(--_pb))}.chatwin .msgs{-webkit-mask-image:linear-gradient(#000 calc(100% - 60px - var(--_pb)),rgba(0,0,0,.12) calc(100% - var(--_pb)));mask-image:linear-gradient(#000 calc(100% - 60px - var(--_pb)),#0000001f calc(100% - var(--_pb)))}.card>.body{-webkit-mask-image:linear-gradient(#000 calc(100% - 60px - var(--_pb)),rgba(0,0,0,.12) calc(100% - var(--_pb)));mask-image:linear-gradient(#000 calc(100% - 60px - var(--_pb)),#0000001f calc(100% - var(--_pb)))}.chatwin .chat,.card>.foot{position:relative;z-index:1;background:none}:host{--_box-bg: color-mix(in srgb, var(--_bg) 72%, transparent);--_box-edge: inset 0 0 0 .5px color-mix(in srgb, var(--_fg) 16%, transparent), 0 4px 18px rgba(0, 0, 0, .08)}.float{--_box-bg: inherit;--_box-edge: inherit}.box{-webkit-backdrop-filter:blur(18px) saturate(1.8);backdrop-filter:blur(18px) saturate(1.8)}.list .it{padding:11px 8px}.pin{scale:.8}.pin .hit{display:block;position:absolute;inset:-14px;border-radius:50%}.pin.moved:not(.resolved,.done) .hit{inset:-21px}.msg .p{font-size:15px;letter-spacing:-.016em;line-height:21px}.msg .quote{font-size:14px;letter-spacing:-.011em}.msg b,.msg .quote b{font-size:12px;letter-spacing:0}.pin.moved:not(.resolved,.done){scale:.64}.bar>button{padding:12px 14px;min-height:44px}.more-menu{bottom:72px;min-width:200px}.more-menu button{padding:11px 12px;font-size:15px;letter-spacing:-.016em}}.scrim{cursor:pointer;display:none;position:fixed;inset:-50vh 0;background:#0006;z-index:2;touch-action:none}.sel-chip{position:fixed;transform:translate(-50%);border:0;border-radius:var(--_radius);padding:8px 14px;background:var(--_fg);color:var(--_bg);font:500 14px/1 var(--_font, inherit);box-shadow:var(--_shadow);z-index:4}@media(pointer:coarse)and (max-width:560px),(pointer:coarse)and (max-height:500px){.listener{display:none!important}.bar{bottom:16px!important}.hint{bottom:64px!important}.chat-btn .mark{align-self:center;width:13px;height:13px;margin:0 -2.5px 0 -2px;translate:0 -1.5px}.chat-btn[data-agent=away] .mark{fill:var(--_muted);opacity:.5}.chat-btn[data-agent=working] .mark{fill:#24a046}.chat-btn[data-agent=listening] .mark .eye{animation:lab-blink 3.2s ease-in-out infinite}.chat-btn[data-agent=working] .mark :is(.e1,.e2){animation:lab-twitch 2.4s ease-in-out infinite}.chat-btn[data-agent=working] .mark .e2{animation-delay:.18s}.send{width:36px;height:36px}.send .arr{width:17px;height:15px;margin:auto}}@media(max-width:560px){.bar{bottom:64px}.hint{bottom:112px}.list{bottom:114px}}[hidden]{display:none!important}@media(pointer:coarse)and (max-width:560px),(pointer:coarse)and (max-height:500px){:host{--_gap: 8px;--_card-r: 30px}.card,.float,.list{left:var(--_gap)!important;right:var(--_gap);bottom:var(--_gap)!important;border-radius:var(--_card-r)!important;background:var(--_bg);box-shadow:0 0 0 .5px color-mix(in srgb,var(--_fg) 10%,transparent),0 12px 40px #0000002e;transform-origin:var(--lab-from, 50% 100%)}.list .tabs{border-radius:var(--_card-r) var(--_card-r) 0 0}.card:after,.float:after,.list:after{content:none}:host([data-kb]) :is(.card,.list:not([hidden])){top:calc(var(--lab-top, 0px) + var(--_gap))!important;height:calc(var(--lab-vh, 100dvh) - 2 * var(--_gap))!important}:host([data-kb]) .float{bottom:calc(var(--lab-kb, 0px) + var(--_gap))!important}.chatwin.full,.card.full{height:calc(var(--lab-vh, 100dvh) - env(safe-area-inset-top,0px) - 10px - var(--_gap) + var(--_kb))}.scrim{background:transparent}.card.in,.float.in,.list:not([hidden]){animation:lab-card-in .3s cubic-bezier(.2,.9,.25,1)}}@keyframes lab-card-in{0%{transform:scale(.3);opacity:0}40%{opacity:1}}.zi{display:inline-flex;align-items:center;justify-content:center}.zi svg{width:13px;height:13px;display:block}.go-btn .gp:has(.zw){display:inline-flex;align-items:center;gap:4px;width:auto;padding:0 8px 0 6px;border-radius:11px}.go-btn .gp .zw{line-height:1}.msg .rule{display:block;margin-top:6px;font-size:12px;opacity:.8;letter-spacing:0;line-height:1.35}.msg .rule b{display:inline;margin:0 6px 0 0;font-size:11px;font-weight:600;opacity:.7;text-transform:uppercase;letter-spacing:.04em}.msg .rule button.btn{margin-left:8px;font-size:11px;padding:0;color:inherit;opacity:.6;text-decoration:underline;text-underline-offset:2px}.msg button.offer{display:inline;padding:0;font:inherit;letter-spacing:inherit;line-height:inherit;color:inherit;opacity:1;pointer-events:auto}.msg :is(.stamp,.stamp-room).offering>:not(.offer){display:none}.msg .stamp.offering{opacity:1}.msg button.offer .tm{opacity:.55}.msg button.offer .tick{color:#24a046}.msg button.offer .tick svg{width:9px;height:9px;vertical-align:top;margin-top:.5px}.msg button :is(svg,svg *){color:inherit}';var pe,oo,ze,ao;function ro(e){({host:pe,layer:oo,el:ze,store:ao}=e)}function so(e){let n=[];for(;e&&e.nodeType===1&&e!==document.body&&e!==document.documentElement;){if(e.id&&document.querySelectorAll(`#${CSS.escape(e.id)}`).length===1){n.unshift(`#${CSS.escape(e.id)}`);break}let a=e.localName,o=1;for(let s=e.previousElementSibling;s;s=s.previousElementSibling)s.localName===a&&o++;n.unshift(`${a}:nth-of-type(${o})`),e=e.parentElement}return n.length?(n[0].startsWith("#")?"":"body > ")+n.join(" > "):"body"}var bt=()=>Math.max(document.documentElement.scrollWidth,1),Oe=e=>Math.min(Math.max(e,0),1),X=(e,n)=>(e||"").replace(/\s+/g," ").trim().slice(0,n);function Fe(e){if(!e||e.startsWith("data:"))return"";try{let n=new URL(e,location.href),a=n.searchParams.get("href")||n.searchParams.get("url");if(a&&/\/_(image|vercel\/image|next\/image)/.test(n.pathname))return Fe(a);let o=n.pathname.split("/").filter(Boolean).map(decodeURIComponent),s=o.pop()||"";return/^w?\d+(x\d+)?\.\w+$/i.test(s)&&o.length&&(s=o.pop()),s.replace(/\.(avif|webp|jpe?g|png|gif|svg|mp4|webm|mov)$/i,"").replace(/[._-][A-Za-z0-9_-]{8}$/,"")}catch{return""}}var gn=e=>{let n=e.currentSrc||e.getAttribute("src")||"";if(n&&!n.startsWith("data:"))return new URL(n,location.href).href;let a=e.dataset?.src||(e.getAttribute("srcset")||e.dataset?.srcset||"").split(/\s+/)[0];return a?new URL(a,location.href).href:""};function It(e,n,a,o,s,r){if(!s||!r||!n.width||!n.height)return null;let p=getComputedStyle(e),i=p.objectFit||"fill",c=(p.objectPosition||"50% 50%").split(/\s+/).map(x=>x.endsWith("%")?parseFloat(x)/100:{left:0,top:0,right:1,bottom:1}[x]??.5),d=n.width/s,k=n.height/r,u={cover:Math.max(d,k),contain:Math.min(d,k),none:1,"scale-down":Math.min(1,d,k)}[i],m=s*(u??d),b=r*(u??k),h=(n.width-m)*(c[0]??.5),v=(n.height-b)*(c[1]??c[0]??.5);return{fit:i,nw:s,nh:r,imgX:Oe((a-n.left-h)/m),imgY:Oe((o-n.top-v)/b)}}function Wt(e){let n=e.naturalWidth,a=e.naturalHeight,o=[e.srcset,...[...e.closest("picture")?.querySelectorAll("source")||[]].map(s=>s.srcset)].filter(Boolean);for(let s of o)for(let r of s.split(/,\s+/)){let[p,i="1x"]=r.trim().split(/\s+/),c="";try{c=new URL(p,location.href).href}catch{}if(!p||c!==e.currentSrc||!n)continue;let d=parseFloat(i);if(i.endsWith("w")&&d)return{nw:Math.round(d),nh:Math.round(d*a/n)};if(i.endsWith("x")&&d)return{nw:Math.round(n*d),nh:Math.round(a*d)}}return{nw:n,nh:a}}var ta=/^[A-Z][A-Za-z0-9]{2,}$/,na=/(Provider|Context|Consumer|Boundary|Slot|Portal|Fragment|Presence|Scope|Trap|Root)$/,Qn=e=>["variant","size","tone","intent","kind"].flatMap(n=>(typeof e?.[n]=="string"||typeof e?.[n]=="number")&&/^[\w.-]{1,20}$/.test(String(e[n]))?[`${n}=${e[n]}`]:[]).join(" "),ht=e=>/^[a-z-]+:\/\//i.test(e)?decodeURIComponent(e.replace(/^[a-z-]+:\/\/\/?(\.\/)?/i,"/").replace(/^\/[^/]*:\d+/,"").split("?")[0]).replace(/^\/(@fs)?/,"").replace(/^\(app-pages-browser\)\/\.?\/?/,""):e;function io(e){let n=(i,c=0)=>c>3?"":typeof i=="function"?i.displayName||i.name||"":i&&typeof i=="object"?i.displayName||n(i.render||i.type,c+1):"",a=i=>ta.test(i)&&!na.test(i),o=i=>{let c=i?._debugSource;if(c?.fileName)return`${ht(String(c.fileName))}:${c.lineNumber||0}`;let d=i?._debugStack?.stack;if(typeof d!="string")return"";for(let k of d.split(`
|
|
2
|
+
`).slice(1)){let u=/((?:https?|webpack-internal|file):\/\/[^\s()]+?):(\d+):\d+\)?\s*$/.exec(k);if(u&&!/node_modules|react-dom|react-jsx|jsx-dev-runtime|react-server|scheduler/.test(u[1]))return`${ht(u[1])} (line ${u[2]} as served, may differ from the source)`}return""},s=Object.keys(e).find(i=>i.startsWith("__reactFiber$"));if(s){let i=e[s],c=[],d="";for(let k=i?.return,u=0;k&&c.length<2&&u<80;k=k.return,u++){if(typeof k.type=="string")continue;let m=n(k.type);if(!a(m))continue;c.length||(d=o(k));let b=Qn(k.memoizedProps);c.push(b?`${m} ${b}`:m)}return c.length?{component:c.length>1?`${c[0]} (in ${c[1]})`:c[0],source:o(i)||void 0,usedAt:d||void 0}:o(i)?{source:o(i)}:{}}let r=e.__vueParentComponent;if(r?.type){let i=r.type.name||r.type.__name||(r.type.__file||"").replace(/^.*\//,"").replace(/\.vue$/,""),c=r.parent?.type,d=c&&(c.name||c.__name),k=Qn(r.props);return{component:`${i}${k?" "+k:""}${d?` (in ${d})`:""}`,source:r.type.__file?ht(r.type.__file):void 0,usedAt:c?.__file?ht(c.__file):void 0}}let p=e.__svelte_meta?.loc;return p?.file?{component:p.file.replace(/^.*\//,"").replace(/\.svelte$/,""),source:`${ht(p.file)}:${p.line??0}`}:{}}function lo(e){let n=getComputedStyle(e),a=new Map,o="rgb(1, 2, 3)",s=document.createElement("i");s.style.cssText=`display:none;color:${o}`;let r=s.appendChild(document.createElement("i"));document.body.append(s);for(let c of[...getComputedStyle(document.documentElement)].filter(d=>d.startsWith("--")).slice(0,400)){r.style.color="",r.style.color=`var(${c})`;let d=getComputedStyle(r).color;d&&d!==o&&!a.has(d)&&a.set(d,c)}s.remove();let p=c=>a.has(c)?`${a.get(c)} ${c}`:c,i=[];return/^(transparent|rgba\(0, 0, 0, 0\))$/.test(n.backgroundColor)||i.push(`fill ${p(n.backgroundColor)}`),i.push(`text ${p(n.color)} ${n.fontSize}/${n.fontWeight}`),parseFloat(n.borderTopLeftRadius)&&i.push(`radius ${n.borderTopLeftRadius}`),X(i.join(", "),200)}function oa(e,n,a){let o=getComputedStyle(e).transform;if(!o||o==="none")return null;let s=new DOMMatrix(o);if(s.isIdentity)return null;let r=e.offsetWidth||e.getBoundingClientRect().width,p=e.offsetHeight||e.getBoundingClientRect().height,[i,c]=getComputedStyle(e).transformOrigin.split(" ").map(parseFloat),d=(h,v)=>s.transformPoint(new DOMPoint(h-i,v-c)),k=[d(0,0),d(r,0),d(0,p),d(r,p)],u=e.getBoundingClientRect(),m={x:u.left-Math.min(...k.map(h=>h.x)),y:u.top-Math.min(...k.map(h=>h.y))},b=s.inverse().transformPoint(new DOMPoint(n-m.x,a-m.y));return{rect:{left:0,top:0,width:r,height:p},x:b.x+i,y:b.y+c}}function aa(e,n,a,o){let s=e.getBoundingClientRect(),r=(e.getAttribute("preserveAspectRatio")||"xMidYMid meet").split(/\s+/),p=(c,d)=>{if(!c||!d||!s.width||!s.height)return;let[k,u]=[s.width,s.height];if(r[0]!=="none"){let v=(r[1]==="slice"?Math.max:Math.min)(s.width/c,s.height/d);[k,u]=[c*v,d*v]}let m=(v,x)=>v==="Min"?0:v==="Max"?x:x/2,b=r[0]==="none"?0:m(r[0].slice(1,4),s.width-k),h=r[0]==="none"?0:m(r[0].slice(5,8),s.height-u);Object.assign(n,{nw:c,nh:d,imgX:Oe((a-s.left-b)/k),imgY:Oe((o-s.top-h)/u)})},i=new Image;i.onload=()=>p(i.naturalWidth,i.naturalHeight),i.src=n.src,i.complete&&p(i.naturalWidth,i.naturalHeight)}function ra(e,n,a,o,s){let r=e.getBoundingClientRect(),p=getComputedStyle(e),i=m=>m.split(/,(?![^(]*\))/).map(b=>b.trim()),c=Math.max(0,i(p.backgroundImage).findIndex(m=>m.includes(n))),d=m=>{let b=i(m);return b[c%b.length]},k=(m,b)=>{if(!m||!b||!r.width||!r.height)return;let h=d(p.backgroundSize),v=m,x=b;if(h==="cover"||h==="contain"){let O=(h==="cover"?Math.max:Math.min)(r.width/m,r.height/b);v=m*O,x=b*O}else if(h!=="auto"&&h!=="auto auto"){let[O,I="auto"]=h.split(/\s+/),Q=(D,B)=>D.endsWith("%")?parseFloat(D)/100*B:parseFloat(D);v=O==="auto"?NaN:Q(O,r.width),x=I==="auto"?NaN:Q(I,r.height),Number.isNaN(v)&&Number.isNaN(x)?[v,x]=[m,b]:Number.isNaN(v)?v=x*m/b:Number.isNaN(x)&&(x=v*b/m)}let[g="50%",_="50%"]=d(p.backgroundPosition).split(/\s+/),E=(O,I)=>O.endsWith("%")?parseFloat(O)/100*I:parseFloat(O)||0,$=E(g,r.width-v),T=E(_,r.height-x);Object.assign(a,{nw:m,nh:b,fit:`background ${h}`,imgX:Oe((o-r.left-$)/v),imgY:Oe((s-r.top-T)/x)})},u=new Image;u.onload=()=>k(u.naturalWidth,u.naturalHeight),u.src=n,u.complete&&k(u.naturalWidth,u.naturalHeight)}function sa(e,n){let a=[...e.children].filter(p=>p!==pe&&p.getBoundingClientRect().height>0),o=null,s=null;for(let p of a){let i=p.getBoundingClientRect();if(i.bottom<=n)o=p;else if(i.top>=n&&!s)s=p;else if(i.top<n&&i.bottom>n)return null}let r=p=>{if(!p)return;let i=p.matches("h1, h2, h3, h4, h5, h6")?p:p.querySelector("h1, h2, h3, h4, h5, h6");return X(`${tt(p)} "${X((i||p).textContent,60)}"`,160)};return o||s?{above:r(o),below:r(s)}:null}function co(e){for(let n=e;n;n=n.parentElement){let a=getComputedStyle(n).backgroundColor.match(/rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?/);if(!a||a[4]!==void 0&&parseFloat(a[4])<.5)continue;let[o,s,r]=[a[1],a[2],a[3]].map(Number),p="#"+[o,s,r].map(i=>Math.round(i).toString(16).padStart(2,"0")).join("");return{scheme:.2126*o+.7152*s+.0722*r<128?"dark":"light",background:p}}return{scheme:matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}}function ia(e,n,a=[]){let o=null,s=0;if(document.caretPositionFromPoint){let E=a.length?document.caretPositionFromPoint(e,n,{shadowRoots:a}):document.caretPositionFromPoint(e,n);E&&(o=E.offsetNode,s=E.offset)}else if(document.caretRangeFromPoint){let E=document.caretRangeFromPoint(e,n);E&&(o=E.startContainer,s=E.startOffset)}if(!o||o.nodeType!==3||!o.data.trim())return null;let r=document.createRange();if(r.selectNodeContents(o),![...r.getClientRects()].some(E=>e>=E.left-4&&e<=E.right+4&&n>=E.top-4&&n<=E.bottom+4))return null;let i=o.data,c=s,d=s,k=/[\u0e00-\u0e7f\u3040-\u30ff\u3400-\u9fff\uac00-\ud7af\uf900-\ufaff]/.test(i)&&typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(o.parentElement?.closest("[lang]")?.lang||void 0,{granularity:"word"}):null;if(k){for(let E of k.segment(i))if(s>=E.index&&s<=E.index+E.segment.length&&E.segment.trim()&&(c=E.index,d=E.index+E.segment.length,s<d))break}else{for(;c>0&&/\S/.test(i[c-1]);)c--;for(;d<i.length&&/\S/.test(i[d]);)d++}let m=(o.parentElement?.closest("p, li, h1, h2, h3, h4, h5, h6, td, th, figcaption, blockquote, a, button, label, span, div")||o.parentElement)?.textContent||i,b=m.slice(0,m.indexOf(i)+c),h=m.slice(m.indexOf(i)+d),v=E=>E.replace(/\s+/g," "),x={exact:X(i.slice(c,d),80),prefix:v(b.slice(-80)).replace(/^\s+/,"").slice(-40),suffix:v(h.slice(0,80)).replace(/\s+$/,"").slice(0,40)},g=o.parentElement?.closest("pre, [data-file]")||(getComputedStyle(o.parentElement).whiteSpace.startsWith("pre")?o.parentElement:null),_=!g&&o.parentElement?.closest('table[data-file], table[class*="code" i]');if(g||_){let E=g||_,$=document.createRange();$.setStart(E,0),$.setEnd(o,s);let T=$.toString(),O=E.textContent,I=[...E.querySelectorAll("br, tr")];if((E.localName==="table"||!O.includes(`
|
|
3
|
+
`))&&I.length){let B=E.querySelectorAll("br").length?[...E.querySelectorAll("br")]:[...E.querySelectorAll("tr")].slice(0,-1),F=B.filter(H=>H.compareDocumentPosition(o)&Node.DOCUMENT_POSITION_FOLLOWING&&!H.contains(o)).length,J=document.createRange();F?J.setStartAfter(B[F-1]):J.setStart(E,0),B[F]?J.setEndBefore(B[F]):J.setEnd(E,E.childNodes.length);let oe=E.querySelectorAll("br").length?null:o.parentElement?.closest("tr");x.line=X((oe?oe.textContent:J.toString()).trim(),200),x.lineNo=F+1,x.lines=B.length+(E.querySelectorAll("br").length?0:1)}else{let B=T.lastIndexOf(`
|
|
4
|
+
`)+1,F=O.indexOf(`
|
|
5
|
+
`,T.length);x.line=X(O.slice(B,F<0?void 0:F).trim(),200),x.lineNo=T.split(`
|
|
6
|
+
`).length,x.lines=O.replace(/\n$/,"").split(`
|
|
7
|
+
`).length}let Q=o.parentElement?.closest("tr, [data-line], [data-line-number]");if(Q){let B=Q.matches("[data-line], [data-line-number]")?Q:Q.querySelector("[data-line], [data-line-number]"),F=B?.getAttribute("data-line")||B?.getAttribute("data-line-number")||[...Q.children].map(J=>J.textContent.trim()).find(J=>/^\d+$/.test(J));F&&/^\d+$/.test(F)&&(x.pageLineNo=Number(F))}let D=E.closest("[data-file]")?.getAttribute("data-file")||E.getAttribute("title")||E.getAttribute("aria-label")||"";for(let B=E.parentElement,F=0;!D.trim()&&B&&B!==document.body&&F<3;B=B.parentElement,F++)D=B.querySelector(':scope > figcaption, :scope > [class*="title" i]')?.textContent||"";D.trim()&&(x.label=X(D.trim(),120))}return x}function tt(e){let n=[...e.attributes].filter(a=>/^(id|class|alt|role|aria-label|href|data-[\w-]+)$/.test(a.name)).map(a=>`${a.name}="${X(a.value,60)}"`);return`<${e.localName}${n.length?` ${n.join(" ")}`:""}>`.slice(0,200)}function eo(e,n){if(!n)return!0;let a=/^<([\w-]+)/.exec(n)?.[1];if(e.localName!==a||(/ id="([^"]*)"/.exec(n)?.[1]||"")!==X(e.id||"",60))return!1;let s=(/ class="([^"]*)"/.exec(n)?.[1]||"").split(/\s+/).filter(r=>r&&r!=="\u2026"&&!r.endsWith("\u2026"));return!s.length||s.some(r=>e.classList.contains(r))}function Ke(e,n){let a=document.elementsFromPoint(e,n).filter(h=>h!==pe&&h!==document.documentElement),o=[],s=null;for(let h=a[0];h?.shadowRoot&&!pe.contains(h)&&o.length<5;h=a[0]){s||=h,o.push(h.shadowRoot);let v=h.shadowRoot.elementsFromPoint(e,n).filter(x=>x!==h);if(!v.length)break;a=[...v,...a]}let r=a[0]?.closest("[data-comment-target]")||a[0]||document.body,p=r.getBoundingClientRect(),i={selector:so(r),x:p.width?(e-p.left)/p.width:0,y:p.height?(n-p.top)/p.height:0,docX:(e+scrollX)/bt(),docY:n+scrollY,width:innerWidth,height:innerHeight,dpr:Math.round((devicePixelRatio||1)*100)/100,element:tt(r),eh:Math.round(p.height)},c=X(r.textContent,200);c&&r!==document.body&&(r.textContent||"").length<400&&(i.text=X(c,80));let d=r.parentElement?.closest("[id], [data-lab]");d&&(i.inside=d.dataset.lab?`[data-lab="${d.dataset.lab}"]`:`#${d.id}`);let k=null;for(let h of document.querySelectorAll("h1, h2, h3"))(h.compareDocumentPosition(r)&Node.DOCUMENT_POSITION_FOLLOWING||h.contains(r))&&(k=h);k&&(i.section=X(k.textContent,100)),s&&(i.shadow=tt(s));for(let[h,v]of Object.entries(io(r)))v&&(i[h]=X(v,200));r!==document.body&&(i.looks=lo(r));let u=r.closest?.("select");u&&u.selectedIndex>=0&&(i.chosen=X(`${u.selectedIndex+1} of ${u.options.length}: "${u.options[u.selectedIndex].text}"`,120));for(let h of[r,r.parentElement])if(!(!h||h===document.body)){for(let v of["::before","::after"]){let x=getComputedStyle(h,v).content,g=x&&x.match(/^"(.+)"$/);if(g&&g[1].trim()){i.cssText=X(`"${g[1]}" from ${v} of ${tt(h)}`,160);break}}if(i.cssText)break}let m=document.querySelector('meta[name="lab-build"]')?.content;m&&(i.build=X(m,40));let b=a.slice(0,5).find(h=>/^(img|video|canvas|svg|image)$/.test(h.localName)&&!pe.contains(h));if(b?.localName==="image"&&b.namespaceURI==="http://www.w3.org/2000/svg")i.kind="image",i.src=new URL(b.getAttribute("href")||b.getAttribute("xlink:href")||"",location.href).href,i.file=Fe(i.src),aa(b,i,e,n);else if(b){let h=b.getBoundingClientRect();if(i.kind=b.localName==="img"?"image":b.localName,b.localName==="img"||b.localName==="video"){let v=b,x=b;i.src=gn(b),i.file=Fe(i.src),v.alt&&(i.alt=X(v.alt,120));let g=oa(b,e,n),[_,E,$]=g?[g.rect,g.x,g.y]:[h,e,n],T=b.localName==="img"?It(b,_,E,$,Wt(b).nw,Wt(b).nh):It(b,_,E,$,x.videoWidth,x.videoHeight);if(T&&Object.assign(i,T),g&&(i.transform=X(getComputedStyle(b).transform,80)),b.localName==="img"&&/\.(gif|webp|apng)(\?|#|$)/i.test(v.currentSrc||v.src)){let O=performance.getEntriesByName(v.currentSrc||v.src)[0],I=O?(performance.now()-O.responseEnd)/1e3:performance.now()/1e3;i.shownFor=Math.round(I*10)/10}b.localName==="video"&&(i.time=Math.round(x.currentTime*10)/10,Number.isFinite(x.duration)&&(i.duration=Math.round(x.duration*10)/10),!i.file&&x.poster&&(i.file=Fe(x.poster)))}else i.time=Math.round(performance.now()/100)/10,i.imgX=Oe((e-h.left)/(h.width||1)),i.imgY=Oe((n-h.top)/(h.height||1)),i.nw=Math.round(h.width),i.nh=Math.round(h.height)}else{let h=ia(e,n,o);if(h)i.kind="text",i.quote=h;else{for(let v=r,x=0;v&&v!==document.documentElement&&x<4;v=v.parentElement,x++){let g=getComputedStyle(v).backgroundImage.match(/url\(["']?(.+?)["']?\)/);if(g){i.kind="background",i.src=new URL(g[1],location.href).href,i.file=Fe(i.src),ra(v,i.src,i,e,n);break}}if(i.kind||="element",i.kind==="element"){let v=sa(r,n);v&&Object.assign(i,{gapAbove:v.above,gapBelow:v.below})}}}Object.assign(i,co(r));for(let h=r;h&&h!==document.body&&h!==document.documentElement;h=h.parentElement)if(h.id){i.block=h.id;break}return i}function po(e){let n=null;try{n=e.selector?document.querySelector(e.selector):null}catch{}let a=v=>{if(!v)return!1;if(e.file&&/^(image|video)$/.test(e.kind)){let x=v.closest?.("img, video")||v;return Fe(gn(x))===e.file}if(e.element&&!eo(v,e.element))return!1;if(e.quote?.exact){let x=(v.textContent||"").replace(/\s+/g,""),g=e.quote.exact.replace(/\s+/g,"").slice(0,24),_=(e.quote.prefix||"").replace(/\s+/g,"").slice(-10),E=(e.quote.suffix||"").replace(/\s+/g,"").slice(0,10);return x.includes(g)&&(g.length>=16||!_&&!E||x.includes(_+g)||x.includes(g+E))}return!0},o=X(e.text,400),s=v=>{let x=null;for(let g of document.querySelectorAll("h1, h2, h3"))(g.compareDocumentPosition(v)&Node.DOCUMENT_POSITION_FOLLOWING||g.contains(v))&&(x=g);return x?X(x.textContent,100):""},r=v=>String(v||"").replace(/\s+/g,""),p=r(e.zoneText).slice(0,30),i=v=>e.quote?.exact?!0:o?X(v.textContent,400).startsWith(o.slice(0,40)):p?r(v.textContent).includes(p):e.section?s(v)===e.section:!0,c=n&&n!==document.body&&a(n)?n:null;if(c&&i(c))return c;if(e.file&&/^(image|video)$/.test(e.kind))return[...document.querySelectorAll("img, video")].find(v=>Fe(gn(v))===e.file)||null;let d=/^<([\w-]+)/.exec(e.element||"")?.[1];if(!d||d==="body"||d==="html")return c;let k=v=>X(v,400),u=null,m=-1,b=1/0,h=[...document.querySelectorAll(d)].slice(0,400).filter(v=>!pe.contains(v)&&eo(v,e.element));for(let v of h){let x=k(v.textContent),g=0;if(e.quote?.exact&&a(v)&&(g+=4),o&&x===o&&(g+=4),p&&r(v.textContent).includes(p)?g+=4:o&&x.startsWith(o.slice(0,40))&&(g+=2),!g&&h.length>1)continue;g&&e.section&&s(v)===e.section&&(g+=2);let _=Math.abs(v.getBoundingClientRect().top+scrollY-(e.docY||0));(g>m||g===m&&_<b)&&([u,m,b]=[v,g,_])}return m>0||!c?u:c}var Ht=null;function la(e){let n=/^(?:…)?(.*?)\[([^\]]+)\](.*?)(?:…)?$/s.exec(e.text||"");if(!n)return null;let a=n[1].replace(/\s+/g," ").slice(-24),o=n[2];if(!Ht||performance.now()-Ht.at>400){let d=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT,{acceptNode:m=>pe.contains(m.parentNode)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}),k="",u=[];for(let m=d.nextNode();m;m=d.nextNode()){let b=m.data.replace(/\s+/g," ");for(let h=0;h<b.length;h++)u.push([m,h]);k+=b}Ht={at:performance.now(),text:k,map:u}}let{text:s,map:r}=Ht,p=s.indexOf(a+o);if(p<0)return{gone:!0};p+=a.length;let i=document.createRange();try{i.setStart(...r[p]),i.setEnd(r[p+o.length-1][0],r[p+o.length-1][1]+1)}catch{return{gone:!0}}let c=i.getBoundingClientRect();return c.width||c.height?{left:c.left+scrollX+Math.min(6,c.width/2),top:c.top+scrollY+c.height/2}:{gone:!0}}var xt={at:-1/0,y:0},yt=(e,n=0)=>{if(performance.now()-xt.at>300){let a=[...document.body.children].filter(o=>o!==pe&&!pe.contains(o)).map(o=>o.getBoundingClientRect().bottom+scrollY);xt={at:performance.now(),y:Math.max(innerHeight,...a)}}return Math.max(0,Math.min(e,xt.y-n-40))},to=(e,n)=>({left:e.left+(n.pinX?e.width:0),top:e.top+(n.pinY?e.height:0)}),no=10,ca=30;function da(e){let n=s=>Math.max(no,Math.round(s.left+scrollX-ca)),a=String(e?.selector||"").split(" > ");for(;a.length>1;){a.pop();let s=null;try{s=document.querySelector(a.join(" > "))}catch{}if(!s||/^(html|body)$/.test(s.localName)||pe.contains(s))continue;let r=s.getBoundingClientRect();if(r.width)return n(r)}let o=[...document.body.children].filter(s=>s!==pe&&!pe.contains(s)).map(s=>s.getBoundingClientRect()).filter(s=>s.width&&s.height);return o.length?n({left:Math.min(...o.map(s=>s.left))}):no}function je(e){let n=pa(e);return n.moved?{...n,left:da(e)}:n}function pa(e){let n=po(e);if(n&&!e.zw&&!e.docW&&/^(html|body|main)$/.test(n.localName)&&/\[[^\]]+\]/.test(e.text||"")){let r=la(e);if(r&&!r.gone)return{left:r.left,top:r.top,zone:null};if(r?.gone)return{left:e.docX*bt(),top:yt(e.docY),zone:null,moved:!0}}if(n&&e.eh&&!e.zw&&!e.docW&&/^(html|body|main)$/.test(n.localName)&&!/\[[^\]]+\]/.test(e.text||"")&&Math.abs(n.getBoundingClientRect().height-e.eh)>40)return{left:e.docX*bt(),top:yt(e.docY),zone:null,moved:!0};if(n){let r=n.getBoundingClientRect();if(r.width||r.height){let p=r.left+scrollX+e.x*r.width,i=e.zw&&Number.isFinite(e.oy)&&e.docH&&r.height>2*e.docH,c=r.top+scrollY+(i?e.oy:e.y*r.height),d=e.zw?{left:p,top:c,width:e.zw*r.width,height:i?e.docH:e.zh*r.height}:null;return d?{...to(d,e),zone:d}:{left:p,top:c,zone:d}}}let a=e.docX*bt(),o=yt(e.docY,e.docH||0),s=e.docW?{left:a,top:o,width:e.docW,height:e.docH}:null;return s?{...to(s,e),zone:s,moved:!!e.selector&&e.selector!=="body"}:{left:a,top:o,zone:s,moved:!!e.selector&&e.selector!=="body"}}function ua(e){let n=e?.quote,a=n?.exact?po(e):null;if(!a)return null;let o=n.exact.replace(/\s+/g,""),s=(n.prefix||"").replace(/\s+/g,"").slice(-12);for(let r=0;a&&r<4;a=a.parentElement,r++){let p="",i=[],c=document.createTreeWalker(a,NodeFilter.SHOW_TEXT);for(let k=c.nextNode();k;k=c.nextNode())for(let u=0;u<k.data.length;u++)/\s/.test(k.data[u])||(p+=k.data[u],i.push([k,u]));let d=null;for(let k=p.indexOf(o);k!==-1;k=p.indexOf(o,k+1)){let u=document.createRange();u.setStart(...i[k]);let[m,b]=i[k+o.length-1];if(u.setEnd(m,b+1),!s||p.slice(0,k).endsWith(s))return u;d||=u}if(d)return d}return null}var uo=(e,n)=>{let a=ze("b",{},String(e||"").replace(/\s*·\s*session\s+\S+$/i,""));return n&&a.append(ze("span",{class:"mark done",role:"img","aria-label":"done"},"\u2713")),a},hn=!1,vt=()=>hn&&ao.get("lab-hold")==="1",ma=e=>{let n=document.getElementById(e);return!!n&&!n.closest("[data-lab-comments]")},fa=e=>{let n=[],a=0;for(let o of e.matchAll(/\bhttps?:\/\/[^\s<>"']*[^\s<>"'.,;:!?)\]]|(?<![\w&/#])#([A-Za-z][\w:.-]*[\w])/g)){if(o[1]&&!ma(o[1]))continue;o.index>a&&n.push(document.createTextNode(e.slice(a,o.index)));let s=o[1]?ze("a",{href:`#${o[1]}`,class:"link"},o[0]):ze("a",{href:o[0],target:"_blank",rel:"noopener noreferrer",class:"link"},o[0]);s.addEventListener("click",r=>{r.stopPropagation(),o[1]&&(r.preventDefault(),dispatchEvent(new CustomEvent("lab-goto",{detail:o[1]})))}),n.push(s),a=o.index+o[0].length}return a<e.length&&n.push(document.createTextNode(e.slice(a))),n},ga=e=>e.split(/(?<=[.!?])\s+(?=["'([]?[A-Z0-9])/),mo=e=>{let n=[];for(let[a,o]of String(e||"").trim().split(/\n\s*\n/).entries()){let s=o.split(`
|
|
8
|
+
`);if(s.length===1&&o.length>240){let r=ga(o);for(let p=0;p<r.length;p+=2)n.push({text:r.slice(p,p+2).join(" "),gap:a>0||p>0});continue}s.forEach((r,p)=>{let i=/^\s*(?:[-•*]|\d+[.)])\s+/.exec(r),c=p>0?n.at(-1):null;i?n.push({li:/\d/.test(i[0])?i[0].trim():"\u2022",text:r.slice(i[0].length),gap:a>0&&p===0}):c&&!c.li?c.text+=`
|
|
9
|
+
${r}`:n.push({text:r,gap:a>0&&p===0||!!c})})}return n.map(a=>{let o=ze("span",{class:`p${a.li?" li":""}${a.gap?" gap":""}`});return a.li&&o.append(ze("span",{class:"mk"},a.li)),o.append(...fa(a.text)),o})},ha=typeof Highlight=="function"&&!!CSS.highlights,Ft=e=>{if(!ha)return;let n=e&&ua(e);n?CSS.highlights.set("lab-quote",new Highlight(n)):CSS.highlights.delete("lab-quote")},bn=e=>{let n=ze("div",{class:`zone ${e}`});return n.innerHTML='<svg aria-hidden="true"><rect class="ring" width="100%" height="100%"/><rect class="dots" width="100%" height="100%"/></svg>',n},Kt=(e,n)=>{if(!e)return;let a=bn(n);return Object.assign(a.style,{left:`${e.left}px`,top:`${e.top}px`,width:`${e.width}px`,height:`${e.height}px`}),oo.append(a),a};function fo({x0:e,y0:n,x1:a,y1:o}){let s=Math.min(e,a),r=Math.min(n,o),p=Math.max(e,a),i=Math.max(n,o),c=Ke((s+p)/2,(r+i)/2),d=document.elementsFromPoint((s+p)/2,(r+i)/2).find($=>$!==pe&&!pe.contains($)),k=Math.max(1,(p-s)*(i-r)),u=$=>Math.max(0,Math.min($.right,p)-Math.max($.left,s))*Math.max(0,Math.min($.bottom,i)-Math.max($.top,r))/k>=.8;for(;d&&d!==document.body&&!u(d.getBoundingClientRect());)d=d.parentElement;d||=document.body;let m=d.getBoundingClientRect();Object.assign(c,{selector:d===document.body?"body":so(d),element:tt(d),x:m.width?(s-m.left)/m.width:0,y:m.height?(r-m.top)/m.height:0,zw:m.width?(p-s)/m.width:0,zh:m.height?(i-r)/m.height:0,oy:Math.round(r-m.top),docX:(s+scrollX)/bt(),docY:r+scrollY,docW:Math.round(p-s),docH:Math.round(i-r),pinX:a>=e?1:0,pinY:o>=n?1:0}),Object.assign(c,co(d)),c.kind==="text"&&(delete c.quote,c.kind="element");let b=d===document.body?"":X(d.textContent,200);b&&(d.textContent||"").length<400?c.text=X(b,80):delete c.text,d!==document.body&&(c.looks=lo(d));let h=[],v=document.createTreeWalker(d,NodeFilter.SHOW_TEXT),x=document.createRange();for(let $=v.nextNode();$&&h.length<80;$=v.nextNode()){if(pe.contains($))continue;let T=$.parentElement?.getBoundingClientRect();if(!(!T||T.bottom<r||T.top>i||T.right<s||T.left>p))for(let O of $.data.matchAll(/\S+/g)){x.setStart($,O.index),x.setEnd($,O.index+O[0].length);let I=x.getBoundingClientRect(),Q=(I.left+I.right)/2,D=(I.top+I.bottom)/2;I.width&&Q>=s&&Q<=p&&D>=r&&D<=i&&h.push(O[0])}}let g=X(h.join(" "),300);g&&(c.zoneText=g);let _=[],E=d.querySelectorAll("*");for(let $=0;$<E.length&&$<3e3;$++){let T=E[$];if(pe.contains(T)||_.some(I=>I.contains(T)))continue;let O=T.getBoundingClientRect();O.width<8||O.height<8||O.left<s-4||O.right>p+4||O.top<r-4||O.bottom>i+4||_.push(T)}if(_.length&&(c.zoneItems=_.slice(0,5).map($=>{let T=io($),O=X($.textContent,50);return X([tt($),O&&`"${O}"`,T.component,T.source&&`written at ${T.source}`,T.usedAt&&`used at ${T.usedAt}`].filter(Boolean).join(" \xB7 "),500)}),_.length>5&&c.zoneItems.push(`and ${_.length-5} more`)),/^(img|video)$/.test(d.localName)){let $=d.localName==="img"?Wt(d).nw:d.videoWidth,T=d.localName==="img"?Wt(d).nh:d.videoHeight,O=It(d,m,s,r,$,T),I=It(d,m,p,i,$,T);O&&I&&Object.assign(c,{imgX:O.imgX,imgY:O.imgY,imgX2:I.imgX,imgY2:I.imgY})}else(c.kind==="image"||c.kind==="video")&&(delete c.imgX,delete c.imgY,c.kind="element");return c}var ba=()=>window.__lab||null;function jt(e){let n=ba();n&&(n.writing=Math.max(0,e),n.writing||n.flush())}var wt;function go(e){wt=e}var Ne=new Set,Yt=new Set,ho=()=>Ne.size>0,xa=e=>{e.value.trim()?Ne.add(e):Ne.delete(e),jt(Ne.size),wt?.whileWriting?.()},ya='<i class="arr" aria-hidden="true"></i>';function xn({placeholder:e,onSubmit:n,autofocus:a=!1,empty:o="",nameFirst:s=!1,draftKey:r=""}){let{el:p,store:i,root:c,refreshPinCursor:d,syncReads:k,rememberMe:u}=wt,m=p("div",{class:"composer"}),b=p("div",{class:"box"}),h=p("textarea",{placeholder:e,maxlength:"2000",rows:"1","aria-label":e,enterkeyhint:"send",autocomplete:"off",autocorrect:"off",spellcheck:"false",writingsuggestions:"false"}),v=p("label",{class:"who"}),x=p("span",{},"as"),g=p("input",{type:"text",name:"search-lab-who",placeholder:"your name",maxlength:"60",enterkeyhint:"send",autocomplete:"off",autocorrect:"off",autocapitalize:"words",spellcheck:"false",writingsuggestions:"false","data-1p-ignore":"","data-lpignore":"true"});if(g.value=i.get("lab-name"),r&&!Yt.has(r)){let H=i.get(r);H&&(h.value=H,queueMicrotask(()=>I()))}let _=()=>{r&&i.set(r,h.value.trim()?h.value:"")},E=()=>{Ne.delete(h),jt(Ne.size),wt?.whileWriting?.(),r&&i.set(r,"")};v.append(x,g);let $=p("button",{class:"send",type:"button","aria-label":"send"});$.addEventListener("pointerdown",H=>H.preventDefault()),$.addEventListener("mousedown",H=>H.preventDefault()),$.innerHTML=ya;let T=p("div",{class:"error"});b.append(h,p("div",{class:"line"}),v,$),m.append(b,T),b.addEventListener("click",H=>{H.target!==b&&!H.target.classList?.contains("line")||(h.focus({preventScroll:!0}),h.setSelectionRange(h.value.length,h.value.length))});let O=null;for(let H of[h,g])H.addEventListener("touchstart",se=>O={x:se.touches[0].clientX,y:se.touches[0].clientY},{passive:!0}),H.addEventListener("touchend",se=>{let ae=se.changedTouches[0];!O||Math.hypot(ae.clientX-O.x,ae.clientY-O.y)>10||c.activeElement===H||(se.preventDefault(),H.focus({preventScroll:!0}),H.setSelectionRange(H.value.length,H.value.length))},{passive:!1});let I=()=>{let H=s||h.value.length>0||c.activeElement===g||!!T.textContent,se=H!==b.classList.contains("open")&&!i.get("lab-name")&&b.isConnected&&!matchMedia("(prefers-reduced-motion: reduce)").matches,ae=se&&{arrow:$.getBoundingClientRect(),height:b.getBoundingClientRect().height},U=!!i.get("lab-name");if(b.classList.toggle("one",U),b.classList.toggle("open",H),x.hidden=!g.value.trim(),U&&!CSS.supports?.("field-sizing","content")&&(g.style.width=`${Math.max(2,g.value.length+1)}ch`),$.classList.toggle("ready",!!((h.value.trim()||o)&&g.value.trim())),xa(h),h.style.height="auto",h.style.height=`${h.scrollHeight}px`,se){let xe=$.getBoundingClientRect(),ye={duration:220,easing:"cubic-bezier(.2, .7, .3, 1)"};$.animate([{transform:`translate(${ae.arrow.left-xe.left}px, ${ae.arrow.top-xe.top}px)`},{transform:"none"}],ye),b.style.overflow="hidden",b.animate([{height:`${ae.height}px`},{height:`${b.getBoundingClientRect().height}px`}],ye).onfinish=()=>b.style.overflow=""}},Q=!1,D=async()=>{if(Q)return;let H=h.value.trim()||o;if(!H)return h.focus();if(!g.value.trim())return b.classList.add("open"),g.focus();i.set("lab-name",g.value.trim()),u(g.value.trim()),d(),k(),$.classList.remove("sent"),$.offsetWidth,$.classList.add("sent"),Q=!0;let se=h.value;r&&Yt.add(r),T.textContent="",T.classList.remove("wait");let ae=setTimeout(()=>{T.textContent="sending\u2026 it goes as soon as the lab is back",T.classList.add("wait")},1500);try{let U=await n(g.value.trim(),H);E(),r&&Yt.delete(r),clearTimeout(ae),T.textContent="",T.classList.remove("wait"),U?.keep&&(h.value="",I())}catch(U){clearTimeout(ae),T.classList.remove("wait"),T.textContent=U.message,r&&Yt.delete(r),h.value=se,_(),I()}Q=!1},B=H=>{H.key==="Enter"&&!H.shiftKey&&!H.isComposing&&(H.preventDefault(),D())};h.addEventListener("input",I),h.addEventListener("input",_),new MutationObserver(()=>{m.isConnected||(Ne.delete(h),jt(Ne.size),wt?.whileWriting?.())}).observe(document.documentElement,{childList:!0,subtree:!0}),g.addEventListener("input",I),g.addEventListener("blur",()=>setTimeout(I,0)),h.addEventListener("keydown",B),g.addEventListener("keydown",B);let F=0;$.addEventListener("touchend",H=>{H.preventDefault(),F=Date.now(),D()},{passive:!1}),$.addEventListener("click",()=>{Date.now()-F<700||D()}),$.addEventListener("mousedown",H=>H.preventDefault()),requestAnimationFrame(I);let J=s?g:h;s&&g.setAttribute("data-first","");let oe=()=>J.focus({preventScroll:!0});return a&&queueMicrotask(()=>J.isConnected?oe():setTimeout(oe,0)),m}var bo;function xo(e){bo=e}var yo=e=>{let n=e.anchor||{},a=n.quote?.exact||"",o=null;try{o=!a&&n.selector?document.querySelector(n.selector):null}catch{}for(let s=0;o&&o!==document.body&&s<5;o=o.parentElement,s++){let r=o.innerText?.replace(/\s+/g," ").trim()||"";if(r.length>=12){a=r;break}}return a=(a||n.text||n.section||"").replace(/\s+/g," ").trim(),a?`"${a.length>40?`${a.slice(0,39)}\u2026`:a}"`:""},vo=(e,n,a="")=>{let{el:o,mine:s,repliesOf:r,workState:p}=bo,i=new Date(e.createdAt),c=i.toDateString()===new Date().toDateString()?i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString([],{day:"numeric",month:"short"}),d=o("span",{class:"stamp"});if(d.append(o("span",{class:"tm"},a+c)),s(e)&&!e.session){let k=n?[n,...r(n.id)]:[e],u=!k.some(b=>!b.session&&b.createdAt>e.createdAt),m=k.some(b=>b.session&&b.createdAt>e.createdAt)||!!(n?.resolved&&u);if(!m&&u&&n&&p(n)[0]==="now")d.classList.add("busy"),d.append(o("span",{class:"ring",role:"img","aria-label":"the agent is on it"}));else if(m)d.classList.add("ans"),d.append(o("span",{class:"tick",role:"img","aria-label":"answered"},"\u2713"));else{let b=n?.handedAt&&n.handedAt>=e.createdAt;d.append(o("span",{class:`tick${b?" got":""}`,role:"img","aria-label":b?"delivered to the agent":"sent"},b?"\u2713\u2713":"\u2713"))}}return d};var S;function wo(e){S=e}var va=e=>!!e.closest?.(".handle, .tabs"),wa=(e,n)=>e.composedPath().find(a=>a instanceof HTMLElement&&n.contains(a)&&(a.localName==="textarea"||/auto|scroll/.test(getComputedStyle(a).overflowY))),kt="cubic-bezier(.32,.72,0,1)",ka=["top","bottom","height","max-height","transform","transition","animation","pointer-events","opacity","transform-origin"],yn={x:0,y:0,at:-1e9};function vn(e,n){let a=n||(performance.now()-yn.at<1500?yn:null);if(!a)return e.style.removeProperty("--lab-from");e.style.setProperty("--lab-from",`${Math.round(a.x-e.offsetLeft)}px ${Math.round(a.y-e.offsetTop)}px`)}var Ut=null;function ko(){!S.coarse||!S.host.hasAttribute("data-kb")||S.still.matches||(Ut??=S.el("input",{"aria-hidden":"true",tabindex:"-1",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",writingsuggestions:"false",style:"position:fixed;top:0;left:-200px;width:1px;height:1px;opacity:0;font-size:16px;pointer-events:none"}),Ut.isConnected||S.root.append(Ut),Ut.focus({preventScroll:!0}))}function wn(e,n=0,a){let o=a?360:n||200,s=n?"linear":"cubic-bezier(.4, 0, .9, .4)",r=0;try{r=new DOMMatrixReadOnly(getComputedStyle(e).transform).m42||0}catch{}let p=e.getBoundingClientRect(),i=p.top-r,c=getComputedStyle(S.scrim).opacity;for(let[m,b]of[["top",`${i}px`],["bottom","auto"],["height",`${p.height}px`],["max-height","none"],["animation","none"],["transition","none"],["transform",a?"":`translateY(${r}px)`],["pointer-events","none"]])e.style.setProperty(m,b,"important");S.host.setAttribute("data-leaving",""),S.scrim.style.transition="none",S.scrim.style.opacity=c;let d=()=>S.root.activeElement?.blur();a?setTimeout(d,o):d();let u=(a?null:S.root.querySelector(e.classList.contains("card")?".pin.open":e.classList.contains("float")?".pin.draft":"none"))?.getBoundingClientRect();if(u&&vn(e,{x:u.left+u.width/2,y:u.top+u.height/2}),e.offsetHeight,a){e.style.setProperty("transform-origin","50% 50%","important");let m=a.x-(p.left+p.width/2),b=a.y-(i+p.height/2),h=()=>{e.animate([{transform:"none"},{transform:`translate(${m}px, ${b}px) scale(${22/p.width}, ${22/p.height})`}],{duration:o,easing:kt,fill:"forwards"}),e.animate([{opacity:1},{opacity:1,offset:.7},{opacity:0}],{duration:o,fill:"forwards"})};requestAnimationFrame(()=>requestAnimationFrame(h))}else n?(e.style.setProperty("transition",`transform ${o}ms ${s}`,"important"),e.style.setProperty("transform",`translateY(${Math.max(p.height,innerHeight-i)+8}px)`,"important")):(e.style.setProperty("transition",`transform ${o}ms ${s}, opacity ${o}ms ease-in`,"important"),e.style.setProperty("transform",`translateY(${r}px) scale(.3)`,"important"),e.style.setProperty("opacity","0","important"));return S.scrim.style.transition=`opacity ${o}ms ${s}`,S.scrim.style.opacity="0",a?o+120:o}function kn(e){for(let n of ka)e.style.removeProperty(n);S.host.removeAttribute("data-leaving"),S.scrim.style.opacity=S.scrim.style.transition=""}function Xt(e,n,a=0){if(!S.coarse||!e||S.still.matches)return n();let o=wn(e,a);S.bar.style.transition=`transform ${o}ms cubic-bezier(.2, .6, .4, 1), opacity ${o}ms`,S.host.style.setProperty("--lab-p","1"),setTimeout(()=>{n(),kn(e),S.bar.style.transition="",S.host.style.removeProperty("--lab-p")},o)}function So(){let e=S.root.querySelector(".float:not(.out)"),n=S.root.querySelector(".pin.draft");if(!S.coarse||!e||!n||!S.vv)return;let a=innerHeight-S.vv.height,o=a>60?a:S.S.kbSeen||Math.round(innerHeight*.42),s=innerHeight-o-e.offsetHeight-8,r=n.getBoundingClientRect(),p=56;if(!(r.top<p||r.bottom>s-16))return;let i=Math.max(0,scrollY+(r.top+r.bottom)/2-(p+s)/2);S.S.revealed={from:scrollY,to:i},Zt(i)}function Sn(){let e=S.S.revealed;S.S.revealed=null,e&&S.coarse&&Math.abs(scrollY-e.to)<40&&Zt(e.from)}function Zt(e){if(S.coarse){let n=document.documentElement,a=parseFloat(n.style.getPropertyValue("--lab-room"))||0,o=Math.max(0,Math.ceil(e+innerHeight-(n.scrollHeight-a)));n.style.setProperty("--lab-room",`${o}px`),n.classList.toggle("lab-room",o>0)}scrollTo({top:Math.max(0,e),behavior:S.still.matches?"auto":"smooth"})}function En(){let e=matchMedia("(pointer: coarse)").matches&&S.host.hasAttribute("data-sheet");if(!e&&S.S.backWatcher){let n=S.S.backWatcher;S.S.backWatcher=null,n.destroy()}if(e&&!S.S.backWatcher&&"CloseWatcher"in window)try{let n=new window.CloseWatcher;n.onclose=()=>{S.S.backWatcher===n&&(S.S.backWatcher=null),S.closeOrNudge(),En()},S.S.backWatcher=n}catch{}}function St(e,n,a=!1){if(!S.coarse)return;let o=0,s=-1e9,r=-1e9;e.addEventListener("scroll",()=>s=performance.now(),{capture:!0,passive:!0}),e.addEventListener("click",g=>{performance.now()-r<200&&(g.preventDefault(),g.stopPropagation())},!0),e.addEventListener("focusin",g=>{performance.now()-r<200&&g.target.localName==="textarea"&&g.target.blur()});let p=0,i=0,c=0,d=0,k=null,u=null,m=null,b=!1,h=g=>{if(b=g.currentTarget===S.scrim,b&&S.openSheet()!==e)return void(u="off");let _=g.touches[0];p=_.clientX,i=_.clientY,c=d=o=0,k={y:i,at:g.timeStamp},m=b?null:wa(g,e),u=g.touches.length>1||m?.localName==="textarea"?"off":null};e.addEventListener("touchstart",h,{passive:!0}),S.scrim.addEventListener("touchstart",h,{passive:!0});let v=g=>{if(b!==(g.currentTarget===S.scrim))return;let _=g.touches[0];if(u==="off"&&m&&m.localName!=="textarea"&&g.touches.length===1&&g.cancelable&&m.scrollTop<=0&&_.clientY>k.y+1&&(u="drag",i=_.clientY,d=0,k={y:_.clientY,at:g.timeStamp}),u==="off")return void(k={y:_.clientY,at:g.timeStamp});if(u==="hold")return g.preventDefault();if(!u){let T=_.clientY-i,O=_.clientX-p;if(!T&&!O)return;let I=Math.abs(O)>Math.abs(T),Q=!I&&T>0&&i-e.getBoundingClientRect().top<e.offsetHeight*.25;if(b?u=I?"hold":"drag":va(g.target)?u=I&&g.target.closest(".tabs")?"off":"drag":Q&&m?.localName!=="textarea"?u="drag":m?u=!I&&T>0&&m.scrollTop<=0&&performance.now()-s>100?"drag":"off":u=I?"hold":"drag",S.S.dbg?.(`touch ${String(g.target.className||g.target.localName).slice(0,20)} at ${Math.round(i-e.getBoundingClientRect().top)}/${e.offsetHeight} down${Math.round(T)} \u2192 ${u}${g.cancelable?"":" (not cancelable)"}${m?` box${Math.round(m.scrollTop)}`:""}`),u==="off")return;if(u==="hold")return g.preventDefault()}g.preventDefault(),o=_.clientY-i;let E=e.offsetHeight||400;c=o>=0?o:-(1-1/(-o*.55/E+1))*E,g.timeStamp>k.at&&(d=.8*((_.clientY-k.y)/(g.timeStamp-k.at))+.2*d),k={y:_.clientY,at:g.timeStamp},e.style.transition=S.scrim.style.transition="none",e.style.transform=`translateY(${c}px)`;let $=Math.min(1,Math.max(0,c/Math.max(100,innerHeight-(e.getBoundingClientRect().top-c))));S.scrim.style.opacity=String(1-$),S.bar.style.transition="none",S.host.style.setProperty("--lab-p",String($))};e.addEventListener("touchmove",v,{passive:!1}),S.scrim.addEventListener("touchmove",v,{passive:!1});let x=g=>{if(b!==(g.currentTarget===S.scrim))return;let _=u;if(u=null,_==="drag"&&(S.S.sheetDraggedAt=performance.now()),_!=="drag")return;r=performance.now(),g.timeStamp-k.at>80&&(d=0);let E=e.offsetHeight||innerHeight,$=()=>{e.style.transition=`transform 380ms ${kt}, height 380ms ${kt}`,S.scrim.style.transition="opacity 300ms",e.style.transform=S.scrim.style.opacity="",S.bar.style.transition="",S.host.style.removeProperty("--lab-p"),setTimeout(()=>e.style.transition=S.scrim.style.transition="",400)};if(a&&!e.classList.contains("full")&&(o<-40||d<-.4))return e.classList.add("full"),e.classList.contains("card")&&(S.S.cardFull=!0),$();if(a&&e.classList.contains("full")&&d<1.2&&(o>60||d>.4))return e.classList.remove("full"),e.classList.contains("card")&&(S.S.cardFull=!1),$();let T=c+Math.max(0,d)*499;if(S.S.dbg?.(`let go: moved ${Math.round(c)} speed ${d.toFixed(2)} rest ${Math.round(T)} of half ${Math.round(E/2)} \u2192 ${d>-.1&&T>E/2?"close":"stay"}`),d>-.1&&T>E/2)return Xt(e,n,Math.min(320,Math.max(140,(innerHeight-e.getBoundingClientRect().top)/Math.max(d,1.2))));e.style.transition=`transform 380ms ${kt}`,S.scrim.style.transition="opacity 300ms",e.style.transform=S.scrim.style.opacity="",S.bar.style.transition="",S.host.style.removeProperty("--lab-p"),setTimeout(()=>e.style.transition=S.scrim.style.transition="",400)};e.addEventListener("touchend",x),S.scrim.addEventListener("touchend",x),S.scrim.addEventListener("touchcancel",x),e.addEventListener("touchcancel",x)}function Eo(){if(S.coarse&&S.vv){let e=S.el("i",{style:"position:fixed;top:0;bottom:0;left:0;width:0;visibility:hidden;pointer-events:none"}),n=S.el("i",{style:"position:absolute;left:0;width:100vw;display:none;background:var(--_bg);z-index:3;pointer-events:none"});S.root.append(e,n);let a="",o=()=>{let s=Math.abs(S.vv.scale-1)>.01,r=e.getBoundingClientRect(),p=S.root.activeElement||document.activeElement,i=/^(textarea|input|select)$/.test(p?.localName||"")||!!p?.isContentEditable,c=s||!i?0:S.vv.offsetTop,d=(c?c+r.top:0)+S.vv.height,k=s?0:Math.max(0,Math.round(r.bottom-d)),u=s?0:Math.max(0,Math.round(d-r.bottom)),m=s?0:Math.round(S.vv.height),b=S.host.hasAttribute("data-sheet"),h=`${k} ${m} ${u} ${b} ${scrollY} ${Math.round(c)}`;if(h===a){let E=b?S.openSheet():null;E?.offsetHeight&&!E.style.transform&&Object.assign(o,{sheet:E,top:E.offsetTop});return}a=h,S.host.style.setProperty("--lab-kb",`${k}px`),S.host.style.setProperty("--lab-top",`${Math.round(c)}px`),m?S.host.style.setProperty("--lab-vh",`${m}px`):S.host.style.removeProperty("--lab-vh"),S.host.toggleAttribute("data-kb",k>60),n.style.display=b&&u?"block":"none",n.style.top=`${Math.round(scrollY+r.bottom)}px`,n.style.height=`${u}px`;let v=b?S.openSheet():null,x=Math.abs((o.vh||m)-m)>60||o.kbUp!==k>60,g=v&&v===o.sheet&&x&&!v.style.transform&&!S.still.matches;g&&(v.style.transition="none",v.offsetHeight);let _=v?v.offsetTop:null;g&&Math.abs(o.top-_)<=8&&(v.style.transition=""),g&&Math.abs(o.top-_)>8&&(v.style.transform=`translateY(${o.top-_}px)`,v.offsetHeight,v.style.transition=`transform 340ms ${kt}`,v.style.transform="",clearTimeout(o.done),o.done=setTimeout(()=>!v.style.transform&&(v.style.transition=""),360)),Object.assign(o,{vh:m,kbUp:k>60},v?.offsetHeight?{sheet:v,top:_}:{sheet:null}),k>60&&(S.S.kbSeen=k)};if(S.S.refit=o,S.root.addEventListener("focusin",()=>setTimeout(o,50)),S.root.addEventListener("focusout",()=>setTimeout(o,50)),S.vv.addEventListener("resize",o),S.vv.addEventListener("scroll",o),addEventListener("pointerdown",s=>yn={x:s.clientX,y:s.clientY,at:performance.now()},{capture:!0,passive:!0}),o(),globalThis.__LAB_DEBUG__!==!1&&/[?&]kbdebug\b/.test(location.search)){let s=[],r=performance.now(),p=0,i=k=>{let u=S.openSheet(),m=u?.getBoundingClientRect();s.push(`${Math.round(performance.now()-r)} ${k} h${Math.round(S.vv.height)} top${Math.round(S.vv.offsetTop)} in${innerHeight} kb${S.host.hasAttribute("data-kb")?1:0}`+(m?` sheet${Math.round(m.top)}/${Math.round(m.height)}${u.getAnimations().length?" anim":""}`:"")+` [${[...document.getAnimations(),...S.root.getAnimations()].map(b=>b.animationName||b.transitionProperty||"js").slice(0,6).join(",")}] scrim${getComputedStyle(S.scrim).opacity.slice(0,4)} scroll${Math.round(scrollY)}`)},c=k=>{i(k);let u=performance.now()+1500,m="",b=()=>{let h=s.length;i("f");let v=s[s.length-1].replace(/^\d+ f /,"");v===m&&(s.length=h),m=v,performance.now()<u&&requestAnimationFrame(b)};requestAnimationFrame(b)};S.root.addEventListener("focusin",()=>(r=performance.now(),c("focus")));let d=()=>{clearTimeout(p),p=setTimeout(async()=>{let k=s.join(`
|
|
10
|
+
`);s=[];for(let u=0;u<k.length;u+=1900)await S.send({name:"kb-log",text:k.slice(u,u+1900),anchor:{kind:"page",selector:"body",x:0,y:0,docX:0,docY:0,width:innerWidth}}).catch(()=>{})},2e3)};S.root.addEventListener("focusout",()=>{s.push("--- let go"),r=performance.now(),c("blur"),d()}),S.S.dbg=k=>{s.push(`${Math.round(performance.now()-r)} ${k}`),d()},S.vv.addEventListener("resize",()=>{c("resize"),s.length>1&&d()})}}}var f;function $o(e){f=e}var nt=(e,n=!1)=>{f.S.stepping=!!f.S.openId,f.S.keepKeys=f.S.stepping&&(n||f.root.activeElement?.localName==="textarea"),f.S.openId=e.id,f.S.draft=null,f.coarse&&(f.S.listOpen=!1),f.render();let a=f.position(e.anchor||{}).top,o=a-Math.max(40,f.coarse&&f.S.openCard?.isConnected?(innerHeight-f.S.openCard.offsetHeight)/2:innerHeight/3);if(!f.coarse&&f.S.openCard?.isConnected){let r=f.S.openCard.getBoundingClientRect().bottom+scrollY-a+28;o=r<=innerHeight-80?a-28-(innerHeight-r)/2:a-40}Zt(o)};function Ye(){let e=f.threads();f.listBtn.hidden=!f.S.on||!f.coarse&&!e.length&&!f.held().length,f.goBtn.hidden=!f.S.on,f.goBtn.firstElementChild||f.goBtn.replaceChildren(f.el("span",{class:"gp"},"go"),f.el("kbd",{"aria-hidden":"true"},[f.KEYS.comment,f.KEYS.go,f.KEYS.zoom,f.KEYS.pointer].join("/"))),f.goFace(),f.goBtn.classList.toggle("on",(f.S.goMode||!!f.S.zoomMode)&&!f.S.cursorMode),f.goBtn.classList.toggle("cursor",f.S.cursorMode),f.goBtn.setAttribute("aria-pressed",String((f.S.goMode||!!f.S.zoomMode)&&!f.S.cursorMode));let n=e.filter(c=>!f.isPage(c)).reduce((c,d)=>c+f.unread(d).length,0);if(f.listBtn.replaceChildren(document.createTextNode(n?`list \xB7 ${n} new`:"list"),f.el("kbd",{"aria-hidden":"true"},"l")),f.newPrev.hidden=f.newNext.hidden=!f.S.on||!e.some(c=>!f.isPage(c)&&f.unread(c).length),!f.LIST_WINDOW){f.newPrev.hidden=f.newNext.hidden=!0,f.listBtn.hidden=!f.S.on,f.listBtn.replaceChildren(f.coarse?"new":f.keyLabel("new",f.KEYS.next),f.el("b",{class:`cnt${n?"":" zero"}`},String(n))),f.listBtn.setAttribute("aria-label",`next new comment, ${n} new`),f.listBtn.setAttribute("aria-keyshortcuts",f.KEYS.next),f.listBtn.title="next new comment: W, or Control-D while typing (Shift for the one before)",f.listBtn.disabled=!n,f.listBtn.classList.toggle("quiet",!n);let c=e.filter(d=>!f.isPage(d)&&(d.resolved||Re(d)[0]==="done")&&!f.unread(d).length).length;f.doneBtn.hidden=!f.S.on,f.doneBtn.disabled=!c&&!f.S.showDone,f.doneBtn.classList.toggle("quiet",f.doneBtn.disabled),f.doneBtn.replaceChildren(f.S.showDone?`hide done \xB7 ${c}`:`show done \xB7 ${c}`,f.el("kbd",{"aria-hidden":"true"},f.KEYS.done)),f.doneBtn.setAttribute("aria-keyshortcuts",f.KEYS.done)}f.placeBar();let a=e.reduce((c,d)=>c+f.unread(d).length,0);(!f.tabTitle.base||!document.title.startsWith("("))&&(f.tabTitle.base=document.title.replace(/^\(\d+\) /,""));let o=a?`(${a}) ${f.tabTitle.base}`:f.tabTitle.base;document.title!==o&&(document.title=o),f.listBtn.classList.toggle("has-new",n>0);let s=f.held().length;if(f.sendBtn.hidden=!s,f.sendBtn.textContent=`send ${s} draft${s===1?"":"s"}`,f.listEl.hidden=!f.S.on||!f.S.listOpen,f.listEl.hidden)return;for(let c of f.listEl.querySelectorAll("[data-f]"))c.classList.toggle("on",c.dataset.f===f.S.filter);let r=e.filter(c=>!f.isPage(c)&&f.unread(c).length).length;f.listEl.querySelector('[data-f="new"]').textContent=r?`new \xB7 ${r}`:"new";for(let c of["work","resolved","mine"])f.$(`[data-f="${c}"]`,f.listEl).hidden=!0;f.holdBtn.hidden=!f.DRAFT_MODE;let p=e.filter(c=>!f.isPage(c)&&(c.resolved||Re(c)[0]==="done")&&!f.unread(c).length).length;if(f.showDoneBtn.hidden=!p,f.showDoneBtn.textContent=f.S.showDone?`hide done \xB7 ${p}`:`show done \xB7 ${p}`,f.holdBtn.classList.toggle("on",f.drafting()),f.S.filter==="work")return f.listEl.querySelector(".items").replaceChildren(...Sa());let i=f.listed().map(c=>{let d=f.el("button",{class:`it${f.S.openId===c.id?" cur":""}`,type:"button"});return d.append(document.createTextNode(`${c.resolved?"\u2713":f.numberOf(c)} ${c.text.replace(/\s+/g," ").slice(0,70)} `),...f.onWhat(c)?[f.el("span",{},`on ${f.onWhat(c)} `)]:[],f.el("span",{},`\xB7 ${c.name}${!c.resolved&&f.isDone(c)?" \xB7 \u2705 done":""}`),...f.unread(c).length?[" ",f.el("span",{class:"tag"},`${f.unread(c).length} new`)]:[]),d.addEventListener("click",()=>nt(c)),d});f.listEl.querySelector(".items").replaceChildren(...i.length?i:[f.el("div",{class:"none"},"nothing here")])}var Re=e=>{let n=[e,...f.repliesOf(e.id)],a=n.filter(r=>!r.session).map(r=>r.createdAt).sort().at(-1)||"",o=n.filter(r=>r.session).sort((r,p)=>r.createdAt.localeCompare(p.createdAt)).at(-1),s=o&&o.createdAt>a;return e.resolved||s&&/^done\b/i.test(o.text)?["done",s?o.createdAt:e.createdAt]:s&&/^on it\b/i.test(o.text)?["now",o.createdAt]:!s&&e.handedAt&&e.handedAt>=a?["now",e.handedAt]:s?[null,""]:["next",a]};function Sa(){let e=new Date().toDateString(),n=[],a=[],o=[];for(let i of f.S.comments.filter(c=>!c.parent)){let[c,d]=Re(i);c==="now"?n.push([i,d]):c==="next"?a.push([i,d]):c==="done"&&new Date(d).toDateString()===e&&o.push([i,d])}let s=([i,c],d)=>{let k=f.el("button",{class:`it${f.S.openId===i.id?" cur":""}`,type:"button"});return k.append(document.createTextNode(`${f.isPage(i)?"chat":i.resolved?"\u2713":f.numberOf(i)} ${i.text.replace(/\s+/g," ").slice(0,70)} `),f.el("span",{},`\xB7 ${d(c)}`)),k.addEventListener("click",()=>f.isPage(i)?(f.S.chatOpen=!0,f.S.listOpen=!1,f.render()):nt(i)),k},r=(i,c,d,k=!1)=>c.length?[f.el("div",{class:"group"},`${i} \xB7 ${c.length}`),...c.sort((u,m)=>(k?-1:1)*u[1].localeCompare(m[1])).map(u=>s(u,d))]:[],p=[...r("Now",n,i=>`on it ${f.ago(i)}`.replace("on it just now","just started")),...r("Next",a,i=>`sent ${f.ago(i)} ago`.replace("just now ago","just now")),...r("Done today",o,i=>new Date(i).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),!0)];return p.length?p:[f.el("div",{class:"none"},"nothing in progress on this page")]}var ot=e=>{let n=f.threads().filter(c=>!f.isPage(c)&&f.unread(c).length);if(!n.length)return;let a=c=>f.position(c.anchor||{}).top;n.sort((c,d)=>a(c)-a(d));let o=f.S.openId&&f.threads().find(c=>c.id===f.S.openId),s=o?a(o):null,r=s==null?-1:n.findIndex(c=>a(c)>s),p=n.findIndex(c=>c.id===f.S.openId),i=p>=0?(p+e+n.length)%n.length:s==null?e>0?0:n.length-1:e>0?r<0?0:r:((r<0?n.length:r)-1+n.length)%n.length;f.S.chatOpen=!1,nt(n[i],!f.coarse)};var M;function Lo(e){M=e}var $n=(e,n)=>{let a=n.cloneNode(!0);a.classList.replace("stamp","stamp-room"),a.setAttribute("aria-hidden","true");for(let s of a.querySelectorAll("[role]"))s.removeAttribute("role");([...e.children].reverse().find(s=>s.classList?.contains("p"))||e).append(a),e.append(n)};function Jt(){let e=new Map(M.S.comments.map(m=>[m.id,m])),n=M.S.comments.filter(m=>M.isPage(m)||m.parent&&M.isPage(e.get(m.parent)||{})).sort((m,b)=>m.createdAt.localeCompare(b.createdAt)).slice(-150);M.S.on&&M.S.chatOpen&&M.chatEl.hidden&&(M.S.newFrom=n.find(M.isNew)?.id||null),M.S.chatOpen||(M.S.newFrom=null),M.S.on&&M.S.chatOpen&&M.markSeen(n.filter(M.isNew));let a=n.filter(M.isNew).length;M.chatBtn.hidden=!M.S.on;{let m=M.chatBtn.querySelector(".mark");for(;M.chatBtn.lastChild&&M.chatBtn.lastChild!==m;)M.chatBtn.lastChild.remove();M.chatBtn.append(M.coarse?"chat":M.keyLabel("chat",M.KEYS.chat),M.el("b",{class:`cnt${a?"":" zero"}`},String(a))),M.chatBtn.setAttribute("aria-label",`chat, ${a} new`),M.chatBtn.setAttribute("aria-keyshortcuts",M.KEYS.chat)}M.chatBtn.classList.toggle("has-new",a>0),M.placeBar();let o=M.chatEl.hidden;if(M.chatEl.hidden=!M.S.on||!M.S.chatOpen,M.chatEl.hidden&&M.chatEl.classList.remove("full"),M.chatEl.hidden&&M.chatEl.contains(M.root.activeElement)&&M.root.activeElement.blur(),M.chatEl.hidden)return;let s=M.$(".msgs",M.chatEl),r=o||s.scrollHeight-s.scrollTop-s.clientHeight<48,p=new Set(o?[]:[...s.children].map(m=>m.dataset.id)),i=new Map([...s.children].filter(m=>m.dataset.id).map(m=>[m.dataset.id,m])),c=m=>{let b=i.get(m.dataset?.id);return b&&b.outerHTML.replace(" fresh","")===m.outerHTML?b:m};M.patchKids(s,n.flatMap(m=>{let b=m.parent?e.get(m.parent):m,h=M.el("div",{class:`msg${M.mine(m)&&!m.session?" mine":""}${b&&M.S.replyTo===b.id?" to":""}${p.size&&!p.has(m.id)?" fresh":""}`,"data-id":m.id,...M.agentOf(m)?{"data-agent":M.agentOf(m)}:{}});if(h.append(M.nameLine(m.name,!1)),m.parent&&b){let v=M.el("div",{class:"quote"});v.append(M.el("b",{},String(b.name||"").replace(/\s*·\s*session\s+\S+$/i,"")),document.createTextNode(b.text.replace(/\s+/g," ").slice(0,90))),v.addEventListener("click",x=>{x.stopPropagation();let g=M.$(".msgs",M.chatEl),_=M.$(`[data-id="${b.id}"]`,g);_&&(g.scrollTo({top:_.offsetTop-g.offsetTop-12,behavior:M.still.matches?"auto":"smooth"}),_.animate?.([{boxShadow:"0 0 0 2px rgb(52,199,89)"},{boxShadow:"0 0 0 0 transparent"}],{duration:900}))}),h.append(v)}return h.append(...M.readable(m.text)),$n(h,M.stampOf(m,b)),m.id===M.S.newFrom&&m!==n[0]?[M.el("div",{class:"newline"},"new"),h]:[h]}).map(c));let d=M.$(".replying",M.chatEl),k=M.S.replyTo&&e.get(M.S.replyTo);if(d.hidden=!k,k){let m=M.el("button",{type:"button",title:"about the page instead"},"\u2715");m.addEventListener("click",()=>(M.S.replyTo=null,Jt())),d.replaceChildren(document.createTextNode(`\u21A9 ${k.name}: ${k.text.replace(/\s+/g," ").slice(0,40)}`),m)}s.firstChild||s.append(M.el("div",{class:"none"},"say something about the page as a whole"));let u=M.chatEl.querySelector(".chat");u.firstChild||u.append(M.composer({placeholder:"message",draftKey:`lab-typing:${M.S.page}:chat`,onSubmit:async(m,b)=>{let{comment:h}=await M.send(M.S.replyTo?{name:m,text:b,parent:M.S.replyTo}:{name:m,text:b,anchor:{kind:"page",width:innerWidth,height:innerHeight,dpr:devicePixelRatio||1}}),v=M.S.replyTo&&M.S.comments.find(x=>x.id===M.S.replyTo);return v?.resolved&&(v.resolved=!1),M.S.replyTo=null,M.S.comments.push(h),M.markSeen([h]),s.scrollTop=s.scrollHeight,M.render(),{keep:!0}}})),u.querySelector("textarea").placeholder=k?"reply":"message",r&&(s.scrollTop=s.scrollHeight)}var C;function _o(e){C=e}function Ln(e,n,a){C.layer.append(e);let o=e.offsetWidth,s=scrollX+document.documentElement.clientWidth-o-12;e.style.left=`${Math.max(scrollX+12,Math.min(n-14,s))}px`;let r=e.offsetHeight,p=a+10+r>C.contentEnd();e.style.top=`${p?Math.max(scrollY+8,a-40-r):a+10}px`,e.style.transformOrigin=p?"14px 100%":""}function Co(e,n,a){C.layer.append(e);let o=e.offsetWidth,s=scrollX+document.documentElement.clientWidth-12,r=e.offsetHeight,p=C.contentEnd();n+36+o<=s?(e.style.left=`${n+36}px`,e.style.top=`${Math.min(a-37,p-r-8)}px`):(e.style.left=`${Math.max(scrollX+12,Math.min(n-14,s-o))}px`,e.style.top=`${a+10+r>p?Math.max(scrollY+8,a-40-r):a+10}px`)}function Mo(e,n){e.addEventListener("pointerdown",a=>{if(a.button!==0)return;let o=e.getBoundingClientRect(),s={dx:a.clientX-o.left,dy:a.clientY-o.bottom},r={x:a.clientX,y:a.clientY,sx:scrollX,sy:scrollY,left:parseFloat(e.style.left),top:parseFloat(e.style.top)},p=!1,i=a;C.S.grabbing=!0,e.setPointerCapture(a.pointerId);let c=()=>{e.style.left=`${r.left+i.clientX-r.x+scrollX-r.sx}px`,e.style.top=`${r.top+i.clientY-r.y+scrollY-r.sy}px`},d=m=>{i=m,!(!p&&Math.hypot(m.clientX-r.x,m.clientY-r.y)<5)&&(p=!0,e.classList.add("dragging"),c())},k=()=>p&&c();addEventListener("scroll",k,!0),C.S.dropDrag=()=>{removeEventListener("scroll",k,!0),C.S.dropDrag=null};let u=async m=>{if(e.removeEventListener("pointermove",d),e.removeEventListener("pointerup",u),e.removeEventListener("pointercancel",u),e.removeEventListener("lostpointercapture",u),C.S.dropDrag?.(),!C.S.grabbing||(C.S.grabbing=!1,!p))return;e.dataset.dragged="1",setTimeout(()=>delete e.dataset.dragged,0);let b=m.clientX-s.dx,h=m.clientY-s.dy,v=document.elementsFromPoint(b,h).find(g=>g!==C.host);if(m.type==="pointercancel"||b<0||h<0||b>innerWidth||h>innerHeight||v?.closest(C.OFF))return C.render();let x=n.anchor;n.anchor={...C.anchorAt(b,h),...x?.zoom?{zoom:x.zoom}:{}},C.render();try{let{comment:g}=await C.send({action:"move",id:n.id,anchor:n.anchor,edit:C.store.get(`lab-edit:${n.id}`)||void 0});Object.assign(n,g)}catch{n.anchor=x,C.render()}};e.addEventListener("pointermove",d),e.addEventListener("pointerup",u),e.addEventListener("pointercancel",u),e.addEventListener("lostpointercapture",u)})}function To(e,n=new Set,a=!1){let o=C.el("div",{class:"card"}),s=C.el("div",{class:"body"}),r=C.el("div",{class:"foot"});o.append(C.el("div",{class:"handle"}),s,r),o.addEventListener("click",x=>x.stopPropagation()),s.classList.add("msgs");let p=!0;s.addEventListener("scroll",()=>p=s.scrollHeight-s.scrollTop-s.clientHeight<48,{passive:!0}),"ResizeObserver"in window&&new ResizeObserver(()=>p&&(s.scrollTop=s.scrollHeight)).observe(s),r.addEventListener("focusin",x=>{x.target.localName==="textarea"&&(p=!0,s.scrollTop=s.scrollHeight)});let i='<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 1.5l1.7 4.8L14.5 8l-4.8 1.7L8 14.5l-1.7-4.8L1.5 8l4.8-1.7z"/></svg>',c=x=>{let g=[e,...C.repliesOf(e.id)],_=g.slice(g.indexOf(x)+1).find(T=>T.session);if(!_?.suggest||_.suggestDone||_.rule)return null;let E=C.el("button",{class:"btn offer",type:"button",title:_.suggest});E.append(C.el("span",{class:"tm"},"rule?"));let $=C.el("span",{class:"tick"});return $.innerHTML=i,E.append($),E.addEventListener("click",async()=>{if(!(await fetch("/_lab/rule",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({page:C.S.page,id:_.id,action:"keep"})}).catch(()=>null))?.ok)return void(E.lastChild.textContent="failed, try again");_.suggestDone="kept",_.rule=_.suggest;for(let O of o.querySelectorAll(`.msg[data-id="${x.id}"] .offering`))O.classList.remove("offering");o.querySelectorAll(`.msg[data-id="${x.id}"] .offer`).forEach(O=>O.remove()),o.querySelector(`.msg[data-id="${_.id}"]`)?.append(d(_))}),E},d=x=>{let g=C.el("span",{class:"rule"});if(x.ruleUndone)return g.append(C.el("b",{},"rule removed")),g;let _=C.el("button",{class:"btn",type:"button"},"undo");return _.addEventListener("click",async()=>{if(!(await fetch("/_lab/rule",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({page:C.S.page,id:x.id})}).catch(()=>null))?.ok)return void(_.textContent="failed, try again");x.ruleUndone=!0,g.replaceWith(d(x))}),g.append(C.el("b",{},"rule"),document.createTextNode(x.rule),_),g},k=x=>{let g=C.el("div",{class:`item msg${C.mine(x)&&!x.session?" mine":""}`,"data-id":x.id,...C.agentOf(x)?{"data-agent":C.agentOf(x)}:{}});g.append(C.nameLine(x.name,!1));let _=x.to&&C.repliesOf(e.id).find(T=>T.id===x.to);if(_){let T=C.el("span",{class:"quote"});T.append(C.el("b",{},String(_.name||"").replace(/\s*·\s*session\s+\S+$/i,"")),document.createTextNode(_.text.replace(/\s+/g," ").slice(0,90))),T.addEventListener("click",()=>o.querySelector(`.msg[data-id="${_.id}"]`)?.scrollIntoView({block:"center",behavior:C.still.matches?"auto":"smooth"})),g.append(T)}g.append(...C.readable(x.text)),x.session&&x.rule&&g.append(d(x));let E=C.stampOf(x,e,x===e&&!e.resolved?`#${C.numberOf(e)} \xB7 `:""),$=!x.session&&c(x);return $&&(E.classList.add("offering"),E.prepend($)),C.stamped(g,E),g},u=new Set,m=[e,...C.repliesOf(e.id)],b=m.find(x=>n.has(x.id));for(let x of m)x===b&&x!==e&&s.append(C.el("div",{class:"newline"},"new")),s.append(k(x)),u.add(x.id);o.sync=()=>{let x=s.scrollHeight-s.scrollTop-s.clientHeight<48;for(let g of C.repliesOf(e.id)){if(u.has(g.id))continue;let _=o.querySelectorAll(".item"),E=k(g);E.classList.add("fresh"),_[_.length-1].after(E),u.add(g.id),C.markSeen([g])}x&&(s.scrollTop=s.scrollHeight)};let h=C.store.get(`lab-edit:${e.id}`),v=null;if(C.S.isAdmin||h){v=C.el("div",{class:"row acts"});let x=C.el("button",{class:"btn",type:"button"},e.resolved?"reopen":"resolve"),g=O=>O.textContent="failed, try again";x.addEventListener("click",async()=>{try{let O=!e.resolved,{comment:I}=await C.send({action:e.resolved?"reopen":"resolve",id:e.id,...h?{edit:h}:{}});if(Object.assign(e,I),O&&C.S.openId===e.id)return C.S.closeFast=!0,C.S.openId=null,C.render();C.render()}catch{g(x)}});let _=C.el("button",{class:"btn",type:"button"},"delete"),E=C.el("button",{class:"btn danger",type:"button"},"delete"),$=C.el("button",{class:"btn",type:"button"},"cancel"),T=()=>{v.replaceChildren(x,_),_.focus()};_.addEventListener("click",()=>{v.replaceChildren(C.el("span",{class:"ask"},C.repliesOf(e.id).length?"delete thread?":"delete comment?"),E,$),$.focus()}),$.addEventListener("click",T),v.addEventListener("keydown",O=>{O.key==="Escape"&&E.isConnected&&(O.stopPropagation(),T())}),E.addEventListener("click",async()=>{try{await C.send({action:"delete",id:e.id})}catch{return g(E)}C.S.comments=C.S.comments.filter(O=>O.id!==e.id&&O.parent!==e.id),C.S.openId=null,C.render()}),v.append(...C.S.isAdmin?[x,_]:[x]),s.append(v)}if(C.coarse){let x=$=>C.position($.anchor||{}).top,g=x(e),_=C.threads().filter($=>!C.isPage($)&&$.id!==e.id&&C.unread($).length).map($=>[$,x($)]);_.sort(($,T)=>($[1]>g?0:1)-(T[1]>g?0:1)||$[1]-T[1]);let E=C.el("div",{class:"row nav"});if(_.length){let $=C.el("button",{class:"btn",type:"button"},`new \xB7 ${_.length} \u203A`);$.addEventListener("pointerdown",T=>T.preventDefault()),$.addEventListener("click",()=>C.goTo(_[0][0])),E.append($)}v&&E.append(v),E.firstChild&&o.insertBefore(E,s)}return r.append(C.composer({placeholder:"reply",autofocus:a,draftKey:`lab-typing:${C.S.page}:${e.id}`,onSubmit:async(x,g)=>{let{comment:_}=await C.send({name:x,text:g,parent:e.id});if(C.S.comments.push(_),C.markSeen([_]),e.resolved){e.resolved=!1,C.render();let T=C.S.openCard?.querySelector(".body");return T&&(T.scrollTop=T.scrollHeight),C.S.openCard?.querySelector("textarea")?.focus({preventScroll:!0}),{keep:!0}}u.add(_.id);let E=o.querySelectorAll(".item"),$=k(_);return $.classList.add("fresh"),E[E.length-1].after($),s.scrollTop=s.scrollHeight,{keep:!0}}})),o}var q;function Ao(e){q=e}function zo(){if(q.script?.dataset.live){let Xe=function(y){{if(y.widget&&q.script.dataset.widget&&y.widget!==q.script.dataset.widget||(y.lab&&q.script.dataset.lab&&y.lab!==q.script.dataset.lab&&(q.script.dataset.lab=y.lab,q.script.dataset.version=String(y.files),h=y.hot,m=y.comments,H(),q.load()),String(y.files)!==q.script.dataset.version))return r();h!==null&&y.hot!==h&&(y.hot-h>1?se([{kind:"html"},{kind:"css",path:""}]):se(y.hotFiles||[])),h=y.hot,m!==null&&y.comments!==m&&q.loadChanges(m),m=y.comments,y.reads!==b&&(b=y.reads,q.syncReads());let A=y.session,P=A?y.mode||"listening":"away",W=ce=>Object.assign(document.createElement("span"),{textContent:ce}),N=A?.model?`${A.agent||"Claude"} \xB7 ${A.model}`:A?.agent||"Claude",K=A&&A.name!==(A.agent||"Claude")?[W(`(${A.name})`)]:[];P==="listening"?c.replaceChildren(W("talking to"),N,...K):P==="working"?c.replaceChildren(N,W("is working"),...K):c.replaceChildren(W("no agent listening")),p.classList.toggle("idle",P==="away"),p.classList.toggle("working",P==="working"),q.listBtn.dataset.agent=P,q.chatBtn.dataset.agent=P,q.coarse&&!q.chatBtn.querySelector(".mark")&&q.chatBtn.insertAdjacentHTML("afterbegin",i),q.coarse&&(q.chatBtn.title=p.textContent),p.setAttribute("aria-label",p.textContent),A?.url&&P!=="away"?Object.assign(p,{href:A.url,target:"_blank"}):p.removeAttribute("href"),p.title=P==="away"?"Ask your agent to run: npx @leonidstern/labit wait":A?.resume||"",p.hidden=!1}},e="lab-scroll:"+location.pathname;try{let y=JSON.parse(sessionStorage.getItem(e)||"null");y!==null&&(sessionStorage.removeItem(e),y.open&&(q.S.openId=y.open),y.list&&(q.S.listOpen=!0,q.S.filter=["new","open","resolved","mine"].includes(y.filter)?y.filter:q.S.filter),y.chat&&(q.S.chatOpen=!0),addEventListener("load",()=>scrollTo(0,+(y.y??y))))}catch{}let n=0;for(let y of["pointerdown","keydown","wheel","touchstart"])addEventListener(y,()=>n=performance.now(),{capture:!0,passive:!0});let a=()=>q.S.draft||q.S.grabbing||q.S.openId||q.S.chatOpen||q.S.listOpen||q.coarse&&/^(textarea|input)$/.test(q.root.activeElement?.localName||"")||[...q.root.querySelectorAll("textarea")].some(y=>y.value.trim())||performance.now()-n<1500,o=!1,s=0,r=()=>{if(document.hidden)return void(o=!0);if(a()){s||(s=setTimeout(()=>(s=0,r()),500));return}try{sessionStorage.setItem(e,JSON.stringify({y:scrollY,open:q.S.openId,list:q.S.listOpen,filter:q.S.filter,chat:q.S.chatOpen}))}catch{}location.reload()},p=document.createElement("a");p.className="listener";let i='<svg class="mark" viewBox="0 0 64 64" aria-hidden="true"><g transform="translate(-1 -.5)"><path class="e1" d="M18.9 24.67L24.4 3h11.5L31.28 21.2A22.8 22.8 0 0 0 18.9 24.67Z"/><path class="e2" d="M37.07 22.02L41.9 3h11.5L47.1 27.85A22.8 22.8 0 0 0 37.07 22.02Z"/><path d="M31 26a18 18 0 0 1 18 18 18 18 0 0 1-18 18H15.57a2.57 2.57 0 0 1-2.57-2.57V44A18 18 0 0 1 31 26Z"/><circle class="eye" cx="31" cy="45" r="6.2"/></g></svg>';p.innerHTML=i+'<div class="lbl"></div>';let c=p.querySelector(".lbl");p.hidden=!0,q.root.querySelector(".left").prepend(p),document.querySelector('link[rel~="icon"]')||fetch("/favicon.ico",{method:"HEAD"}).then(y=>y.ok&&(y.headers.get("content-type")||"").startsWith("image/")).catch(()=>!1).then(y=>{y||document.querySelector('link[rel~="icon"]')||document.head.append(Object.assign(document.createElement("link"),{rel:"icon",href:"/_lab/favicon.svg"}))});let d=null,k=0,u=y=>{c.replaceChildren(Object.assign(document.createElement("span"),{textContent:y})),p.setAttribute("aria-label",y),p.classList.add("idle"),p.classList.remove("working"),p.hidden=!1},m=null,b=null,h=null,v=y=>{let A=[...document.querySelectorAll('link[rel~="stylesheet"][href]:not([data-lab-swap])')].filter(W=>new URL(W.href,location.href).origin===location.origin),P=A.filter(W=>y.includes(decodeURIComponent(new URL(W.href,location.href).pathname)));for(let W of P.length?P:A){let N=new URL(W.href,location.href);N.searchParams.set("lab-v",Date.now().toString(36));let K=W.cloneNode();K.href=N.href,K.dataset.labSwap="";let ce=N.pathname;K.addEventListener("load",()=>{for(let j of document.querySelectorAll('link[rel~="stylesheet"][href]'))j!==K&&new URL(j.href,location.href).pathname===ce&&j.remove();delete K.dataset.labSwap},{once:!0}),K.addEventListener("error",()=>K.remove(),{once:!0}),W.after(K)}},x=y=>{let A=new URL(y,location.href);return A.searchParams.set("lab-v",Date.now().toString(36)),A.href},g=(y,A)=>{try{let P=new URL(y,location.href);return P.origin===location.origin&&A.includes(decodeURIComponent(P.pathname))}catch{return!1}},_=y=>{let A=0;for(let P of document.querySelectorAll('img, source, video[poster], image, use, link[rel~="icon"]')){if(q.host.contains(P))continue;for(let N of["src","href","poster","xlink:href"]){let K=P.getAttribute(N);if(!K||!g(K.split("#")[0],y))continue;let ce=x(K.split("#")[0]),j=new Image;j.src=ce,(j.decode?j.decode():Promise.resolve()).catch(()=>{}).finally(()=>P.setAttribute(N,ce+(K.includes("#")?K.slice(K.indexOf("#")):""))),A++}let W=P.getAttribute("srcset");W&&W.split(",").some(N=>g(N.trim().split(/\s+/)[0],y))&&(P.setAttribute("srcset",W.split(",").map(N=>{let[K,...ce]=N.trim().split(/\s+/);return[g(K,y)?x(K):K,...ce].join(" ")}).join(", ")),A++)}A||v([])},E=y=>{for(let A of document.styleSheets){let P;try{P=A.cssRules}catch{continue}for(let W of P||[]){if(!(W instanceof CSSFontFaceRule))continue;let N=W.style.getPropertyValue("src"),K=A.href||location.href;if(!/url\(/.test(N)||![...N.matchAll(/url\(["']?([^"')]+)/g)].some(te=>g(new URL(te[1],K).href,y)))continue;let ce=N.replace(/url\(["']?([^"')]+)["']?\)/g,(te,G)=>g(new URL(G,K).href,y)?`url("${x(new URL(G,K).href)}")`:te),j=te=>W.style.getPropertyValue(te)||void 0;try{new FontFace(j("font-family").replace(/^["']|["']$/g,""),ce,{weight:j("font-weight"),style:j("font-style"),stretch:j("font-stretch"),unicodeRange:j("unicode-range"),display:j("font-display")}).load().then(G=>document.fonts.add(G)).catch(()=>{})}catch{}}}},$=()=>new Set([q.fonts,q.pinCursorStyle]),T=y=>[...y.querySelectorAll("script")].filter(A=>!/\/_lab\/comments\.js/.test(A.getAttribute("src")||"")).map(A=>A.getAttribute("src")||A.textContent),O=y=>[...y.querySelectorAll('link[rel~="stylesheet"]')].map(A=>{try{return new URL(A.getAttribute("href"),location.href).pathname}catch{return""}}),I=y=>y===q.host||y.nodeType===1&&y.localName==="script",Q=(y,A)=>y.nodeType===A.nodeType&&y.nodeName===A.nodeName&&(y.nodeType!==1||(y.id||"")===(A.id||"")),D=(y,A)=>Q(y,A)&&(y.nodeType===1?!!y.id||y.getAttribute("class")===A.getAttribute("class"):y.nodeType!==3||y.data===A.data),B=(y,A)=>{let P=[...y.childNodes].filter(j=>!I(j)),W=[...A.childNodes].filter(j=>!(j.nodeType===1&&j.localName==="script")),N=0,K=null,ce=j=>{let te=document.importNode(j,!0);return y.insertBefore(te,K?K.nextSibling:P[N]||y.firstChild),te};W.forEach((j,te)=>{let G=P[N];if(!G)return void(K=ce(j));if(D(G,j))return K=F(G,j),void N++;if(W.slice(te+1,te+8).some(ie=>D(G,ie)))return void(K=ce(j));let me=P.slice(N+1,N+8).findIndex(ie=>D(ie,j));if(me>=0){for(let ie of P.slice(N,N+1+me))ie.remove();return N+=me+1,K=F(P[N],j),void N++}K=F(G,j),N++});for(let j of P.slice(N))j.remove()},F=(y,A)=>{if(y.nodeType!==A.nodeType||y.nodeName!==A.nodeName||y.nodeType===1&&(y.id||"")!==(A.id||"")){let P=document.importNode(A,!0);return y.replaceWith(P),P}if(y.nodeType===3||y.nodeType===8)return y.data!==A.data&&(y.data=A.data),y;if(y.nodeType!==1)return y;for(let{name:P}of Array.from(y.attributes))!A.hasAttribute(P)&&!(P==="open"&&/^(details|dialog)$/.test(y.localName))&&y.removeAttribute(P);for(let{name:P,value:W}of Array.from(A.attributes))y.getAttribute(P)!==W&&y.setAttribute(P,W);return y===document.activeElement||y.shadowRoot||/^(iframe|canvas|video|audio|textarea|select|input)$/.test(y.localName)||B(y,A),y},J=()=>T(document).length>0,oe=0,H=async()=>{if(J())return r();let y=++oe;try{let A=await fetch(location.href,{cache:"no-store",headers:{accept:"text/html"}});if(!A.ok)return r();let P=await A.text();if(y!==oe)return;let W=new DOMParser().parseFromString(P,"text/html");if(T(W).join(`
|
|
11
|
+
`)!==T(document).join(`
|
|
12
|
+
`)||O(W).join(`
|
|
13
|
+
`)!==O(document).join(`
|
|
14
|
+
`))return r();let N=null;for(let te of[Math.min(innerHeight/3,240),innerHeight/2,80]){let G=document.elementFromPoint(innerWidth/2,te);if(G&&G!==document.body&&G!==document.documentElement&&!q.host.contains(G)&&G!==q.host){N=G;break}}let K=N?.getBoundingClientRect().top,ce=()=>{W.title!==q.tabTitle.base&&(q.tabTitle.base=W.title,document.title=W.title,q.drawList());let te=$(),G=[...document.head.querySelectorAll("style")].filter(ie=>!te.has(ie)),me=[...W.head.querySelectorAll("style")];me.forEach((ie,De)=>G[De]?G[De].textContent!==ie.textContent&&(G[De].textContent=ie.textContent):document.head.append(document.importNode(ie,!0)));for(let ie of G.slice(me.length))ie.remove();if(B(document.body,W.body),N?.isConnected){let ie=N.getBoundingClientRect().top-K;Math.abs(ie)>1&&scrollBy(0,ie)}q.reflow(),q.drawZoom()},j=()=>{try{ce()}catch{r()}};document.startViewTransition&&!q.still.matches?document.startViewTransition(j):j()}catch{r()}},se=y=>{let A=W=>y.filter(N=>N.kind===W).map(N=>N.path),P=decodeURIComponent(location.pathname).replace(/\/$/,"/index").replace(/\.html?$/i,"");A("html").some(W=>!W||W.replace(/\.html?$/i,"")===P)&&H(),A("css").length&&v(A("css")),A("img").length&&_(A("img")),A("font").length&&E(A("font"))},ae=Math.random().toString(36).slice(2,12),U="BroadcastChannel"in window?new BroadcastChannel("labit-live"):null,xe=!!(U&&navigator.locks),ye=!xe,he=null,Ue=null,Be=y=>{k=Date.now(),Ue=y,Xe(y)};U&&(U.onmessage=({data:y})=>{y.t==="hello"&&d&&Ue&&U.postMessage({t:"state",v:Ue}),!d&&(y.t==="state"&&Be(y.v),y.t==="beat"&&(k=Date.now()),y.t==="down"&&u("reconnecting"))});let Ce=()=>{d||(d=new EventSource(`${q.script.dataset.live}?tab=${ae}`),k=Date.now(),d.addEventListener("beat",()=>{k=Date.now(),ye&&U?.postMessage({t:"beat"})}),d.onerror=()=>{u("reconnecting"),ye&&U?.postMessage({t:"down"})},d.onmessage=y=>{let A=JSON.parse(y.data);Be(A),ye&&U?.postMessage({t:"state",v:A})})},Pe=()=>navigator.locks.request("labit-live",()=>new Promise(y=>{he=y,ye=!0,Ce()}));document.addEventListener("visibilitychange",()=>{if(!document.hidden){if(o)return r();Ze()}}),addEventListener("pagehide",()=>{d?.close(),d=null,he?.(),he=null,ye=!xe,fetch(q.script.dataset.live.replace(/live$/,"bye"),{method:"POST",keepalive:!0,headers:{"content-type":"application/json"},body:JSON.stringify({tab:ae})}).catch(()=>{})}),addEventListener("pageshow",y=>y.persisted&&Je());let at=Date.now(),Gt=()=>{d?.close(),d=null,u("reconnecting"),Ce()},Ze=(y=!1)=>{let A=Date.now()-k>4e4;d&&(y||A)?Gt():!d&&A?Ce():!d&&y&&U?.postMessage({t:"hello"})};setInterval(()=>{let y=Date.now(),A=y-at>2e4;at=y,document.hidden||Ze(A)},5e3),addEventListener("online",()=>!document.hidden&&Ze(!0));let Je=()=>{if(!xe)return Ce();k=Date.now(),Pe(),U.postMessage({t:"hello"})};Je()}}var we;function Oo(e){we=e}function Et(e){let n=document.createElement("span");n.className="zi",n.setAttribute("aria-hidden","true");let a=e==="in"?"M14 2 9.5 6.5M9.5 3.2v3.3h3.3M2 14l4.5-4.5M6.5 12.8V9.5H3.2":"M9.5 6.5 14 2M10.7 2H14v3.3M6.5 9.5 2 14M2 10.7V14h3.3";return n.innerHTML=`<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="${a}"/></svg>`,n}var Vt=[];function _n(e,n){Vt.push({block:e,dir:n,at:Date.now()})}var Ea=(e,n)=>{let a=document.querySelector(`[data-zoom="${n}"][data-zoom-of="${CSS.escape(e)}"]`);return a&&!we.host.contains(a)?a:null};function Cn(e){let n=e.getBoundingClientRect(),a=matchMedia("(prefers-reduced-motion: reduce)").matches;scrollTo({top:Math.max(0,n.top+scrollY-24),behavior:a?"auto":"smooth"});let o="2px solid rgb(52, 199, 89)";e.animate([{outline:o,outlineOffset:"4px"},{outline:o,outlineOffset:"4px",offset:.7},{outline:"2px solid transparent",outlineOffset:"4px"}],{duration:2e3})}function Mn(){for(let e=Vt.length-1;e>=0;e--){let n=Vt[e],a=Ea(n.block,n.dir);(a||Date.now()-n.at>30*6e4)&&Vt.splice(e,1),a&&requestAnimationFrame(()=>Cn(a))}}function _e(e){e&&we.S.cursorMode&&we.setCursor(!1),we.S.zoomMode=e;try{sessionStorage.setItem("lab-zoom",e)}catch{}we.refreshPinCursor(),we.goFace(),we.recheck(),we.render()}function No(e,n){return e.key==="Escape"?(_e(""),!0):!1}function Ro(){try{let e=sessionStorage.getItem("lab-zoom");we.S.zoomMode=e==="in"||e==="out"?e:""}catch{we.S.zoomMode=""}}var Tn=e=>e==="out"?"zoom out: the bigger picture":"zoom in: dive deeper";/*!
|
|
15
|
+
* lab comments: anyone with the link clicks anywhere on a lab page to pin a comment. No login, just a name.
|
|
16
|
+
* https://github.com/leonidstern/labit · MIT
|
|
17
|
+
* Comments are off by default; the bar button or c turns them on (remembered per browser). When on, click anywhere that isn't a link or control to pin one (alt/option-click pins on those too). c (or the bar button) hides
|
|
18
|
+
* and shows them; esc or a click outside closes an open comment. Dragging (mouse/pen) marks an area instead of a point.
|
|
19
|
+
* Include on a page served through your lab domain:
|
|
20
|
+
* <script src="https://lab.example.com/_lab/comments.js" defer><\/script>
|
|
21
|
+
* The layer only turns on when the page is opened on the host the script is loaded from (or data-host),
|
|
22
|
+
* so the deployment's own address and local dev stay clean. data-enable="always" turns it on everywhere.
|
|
23
|
+
* Admin (resolve / delete / copy agent link): open any page once with ?lab-admin=<LAB_COMMENTS_ADMIN_TOKEN>; it is kept in this browser.
|
|
24
|
+
*/(()=>{let e={dbg:null},n={get $(){return F},get API(){return d},get headers(){return te},get DRAFT_MODE(){return hn},get LIST_WINDOW(){return at},get OFF(){return fe},get S(){return e},get agentOf(){return j},get ago(){return Ko},get anchorAt(){return Ke},get bar(){return se},get chatBtn(){return W},get chatEl(){return P},get closeOrNudge(){return jn},get coarse(){return re},get composer(){return xn},get contentEnd(){return Uo},get doneBtn(){return Ce},get drafting(){return vt},get drawList(){return Ye},get el(){return N},get fonts(){return ue},get goBtn(){return he},get goFace(){return nn},get goTo(){return nt},get held(){return it},get holdBtn(){return A},get host(){return D},get isDone(){return Io},get isNew(){return Rn},get isPage(){return On},get keyWord(){return tn},get KEYS(){return o},get keyLabel(){return p},get layer(){return J},get listBtn(){return ye},get listEl(){return y},get listed(){return Ho},get load(){return me},get loadChanges(){return ie},get markSeen(){return ct},get mine(){return Mt},get nameLine(){return uo},get newNext(){return Ze},get newPrev(){return Ue},get numberOf(){return on},get onWhat(){return yo},get openSheet(){return Kn},get patchKids(){return K},get pinCursorStyle(){return gt},get placeBar(){return Fo},get position(){return je},get readable(){return mo},get reflow(){return Bt},get drawZoom(){return Mn},get refreshPinCursor(){return un},get setCursor(){return Qt},get recheck(){return Me},get render(){return Y},get repliesOf(){return ln},get root(){return B},get scrim(){return dn},get script(){return a},get send(){return Ve},get sendBtn(){return Je},get showDoneBtn(){return Be},get stampOf(){return vo},get stamped(){return $n},get still(){return At},get store(){return u},get syncReads(){return sn},get tabTitle(){return Gt},get threads(){return st},get unread(){return lt},get vv(){return Go}};Ao(n),Oo(n),$o(n),Lo(n),_o(n),wo(n);let a=document.currentScript,o={toggle:"m",comment:"1",go:"2",zoom:"3",pointer:"4",chat:"c",next:"w",pause:"p",done:"d",reply:"r",resolve:"e"};try{Object.assign(o,JSON.parse(a?.dataset.keys||"{}"))}catch{}let s=t=>{let l=/^(Digit|Numpad)(\d)$/.exec(t.code||"");return l?l[2]:/^[a-z]$/i.test(t.key||"")?t.key.toLowerCase():/^Key[A-Z]$/.test(t.code||"")?t.code.slice(3).toLowerCase():""},r=t=>Object.keys(o).find(l=>o[l]===s(t))||"",p=(t,l)=>{let w=t.indexOf(l);return w>=0?tn(t.slice(0,w),l,t.slice(w+1)):tn(`${t} `,l,"")},i=a?.dataset.host||(a?.src?new URL(a.src,location.href).hostname:location.hostname);if(!(location.hostname===i||a?.dataset.enable==="always")||window.__labComments)return;window.__labComments=!0;let d=a?.dataset.api||"/_lab/api/comments",k=()=>a?.dataset.page||location.pathname.replace(/\/+$/,"")||"/";e.page=k();let u={get:t=>{try{return localStorage.getItem(t)||""}catch{return""}},set:(t,l)=>{try{localStorage.setItem(t,l)}catch{}}},m=a?.dataset.me||"";m&&!u.get("lab-name")&&u.set("lab-name",m);let b=a?.dataset.live?a.dataset.live.replace(/live$/,"me"):"",h=(()=>{try{return JSON.parse(a?.dataset.flags||"{}")}catch{return{}}})(),v=a?.dataset.live?a.dataset.live.replace(/live$/,"flags"):"",x=t=>h[t]?.on===!0,g=m,_=t=>{!b||!t||t===g||(g=t,fetch(b,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t})}).catch(()=>{}))},E=t=>t.split(".").length===3?t.split(".")[1]:"",$=new URLSearchParams(location.hash.slice(1)).get("lab-admin")||new URLSearchParams(location.search).get("lab-admin");if($){let t=E($);u.set(t?`lab-admin:${t}`:"lab-admin",$);let l=new URL(location.href);l.searchParams.delete("lab-admin"),/lab-admin=/.test(l.hash)&&(l.hash=""),history.replaceState(null,"",l)}let T=a?.dataset.admin||u.get(`lab-admin:${e.page.split("/")[1]||""}`)||u.get("lab-admin:*")||u.get("lab-admin");e.comments=[],e.isAdmin=!1,e.on=u.get("lab-on")?u.get("lab-on")==="1":a?.dataset.on==="1",e.openId=null,e.closeFast=!1,e.cardFull=!1,e.draft=null;let O=()=>`lab-spot:${e.page}`,I=t=>u.set(O(),t?JSON.stringify(t):""),Q=()=>{try{return JSON.parse(u.get(O())||"null")}catch{return null}},D=document.createElement("div");D.setAttribute("data-lab-comments",""),D.style.cssText="position:absolute;top:0;left:0;width:0;height:0;z-index:2147483000;";let B=D.attachShadow({mode:"open"});B.innerHTML=`
|
|
25
|
+
<style>${Gn}</style>
|
|
1314
26
|
<div class="scrim"></div>
|
|
1315
27
|
<div class="layer"></div>
|
|
1316
28
|
<button class="sel-chip" type="button" hidden>Comment</button>
|
|
1317
|
-
<div class="hint" role="status" hidden>click to comment \xB7 drag to mark an area \xB7 shift-drag to quote words \xB7
|
|
29
|
+
<div class="hint" role="status" hidden>click to comment \xB7 drag to mark an area \xB7 shift-drag to quote words \xB7 ${o.chat} chat \xB7 ${o.next} new \xB7 ${o.comment} comment \xB7 ${o.go} go \xB7 ${o.zoom} in, ${o.zoom} again out \xB7 ${o.pointer} pointer \xB7 ${o.pause} pause \xB7 ${o.toggle} hide</div>
|
|
1318
30
|
<div class="list" hidden><div class="tabs"><button type="button" data-f="new">new</button><button type="button" data-f="open">open</button><button type="button" data-f="work">work</button><button type="button" data-f="resolved">resolved</button><button type="button" data-f="mine">mine</button><button type="button" class="show-done" title="show or hide done pins on the page"></button><button type="button" class="hold" title="new pins wait here as drafts; send them together">draft mode</button><button type="button" class="x" aria-label="close">\u2715</button></div><div class="items"></div></div>
|
|
1319
31
|
<div class="list chatwin" hidden><div class="tabs"><b>chat</b></div><div class="msgs"></div><div class="replying" hidden></div><div class="chat"></div></div>
|
|
1320
32
|
<div class="left"><button class="secondary copy-all" type="button" hidden>copy link</button></div>
|
|
@@ -1325,2284 +37,10 @@ ${line}`;
|
|
|
1325
37
|
<button class="secondary list-btn" type="button" hidden>list</button>
|
|
1326
38
|
<button class="secondary new-next" type="button" hidden aria-label="next new comment">\u203A</button>
|
|
1327
39
|
<button class="secondary done-btn" type="button" hidden title="show or hide done pins on the page"></button>
|
|
1328
|
-
<button class="secondary
|
|
40
|
+
<button class="secondary pause-btn" type="button" aria-pressed="false" title="stop everything that moves on the page, to pin a moment (${o.pause})">pause motion</button>
|
|
41
|
+
<button class="secondary over-btn" type="button" aria-pressed="false" title="a click on the page's own links and buttons places a comment too, instead of being theirs (option-click always does)">pin over controls</button>
|
|
42
|
+
<button class="secondary go-btn" type="button" hidden title="tap: comment \u2192 go \u2192 zoom in \u2192 zoom out \xB7 keys: 1 comment \xB7 2 go: every click approves what it's on \xB7 3 zoom in, 3 again zoom out: ask the agent for a deeper look or the bigger picture \xB7 4 pointer: clicks are the page's own">go</button>
|
|
1329
43
|
<button class="toggle" type="button"></button>
|
|
1330
44
|
<button class="secondary more" type="button" hidden aria-label="more options" aria-expanded="false" aria-controls="lab-more">\u22EF</button>
|
|
1331
45
|
</div>
|
|
1332
|
-
<div class="more-menu" id="lab-more" hidden></div>`;
|
|
1333
|
-
const $ = (sel, box = root) => (
|
|
1334
|
-
/** @type {HTMLElement} */
|
|
1335
|
-
box.querySelector(sel)
|
|
1336
|
-
);
|
|
1337
|
-
const layer2 = $(".layer");
|
|
1338
|
-
const hint = $(".hint");
|
|
1339
|
-
if (matchMedia("(pointer: coarse)").matches) hint.textContent = "hold to comment";
|
|
1340
|
-
const toggleBtn = $(".toggle");
|
|
1341
|
-
const bar = (
|
|
1342
|
-
/** @type {HTMLElement} */
|
|
1343
|
-
root.querySelector(".bar")
|
|
1344
|
-
);
|
|
1345
|
-
const moreBtn = $(".more");
|
|
1346
|
-
const moreMenu = $(".more-menu");
|
|
1347
|
-
const copyBtn = $(".copy-all");
|
|
1348
|
-
const listBtn = (
|
|
1349
|
-
/** @type {HTMLButtonElement} */
|
|
1350
|
-
$(".list-btn")
|
|
1351
|
-
);
|
|
1352
|
-
const goBtn = $(".go-btn");
|
|
1353
|
-
const newPrev = $(".new-prev");
|
|
1354
|
-
const showDoneBtn = $(".show-done");
|
|
1355
|
-
const doneBtn = (
|
|
1356
|
-
/** @type {HTMLButtonElement} */
|
|
1357
|
-
$(".done-btn")
|
|
1358
|
-
);
|
|
1359
|
-
const LIST_WINDOW = false;
|
|
1360
|
-
const tabTitle = { base: "" };
|
|
1361
|
-
let showDone = store2.get("lab-show-done") === "1";
|
|
1362
|
-
const newNext = $(".new-next");
|
|
1363
|
-
const sendBtn = $(".send-all");
|
|
1364
|
-
const listEl = $(".list");
|
|
1365
|
-
const holdBtn = $(".hold", listEl);
|
|
1366
|
-
const chatEl = $(".chatwin");
|
|
1367
|
-
const chatBtn = (
|
|
1368
|
-
/** @type {HTMLElement} */
|
|
1369
|
-
root.querySelector(".chat-btn")
|
|
1370
|
-
);
|
|
1371
|
-
let listOpen = false;
|
|
1372
|
-
let filter = "open";
|
|
1373
|
-
let refit = () => {
|
|
1374
|
-
};
|
|
1375
|
-
let chatOpen = false;
|
|
1376
|
-
const el2 = (tag, attrs = {}, text) => {
|
|
1377
|
-
const node = document.createElement(tag);
|
|
1378
|
-
for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v);
|
|
1379
|
-
if (text != null) node.textContent = text;
|
|
1380
|
-
return node;
|
|
1381
|
-
};
|
|
1382
|
-
bindAnchoring({ host: host2, layer: layer2, el: el2, store: store2 });
|
|
1383
|
-
function patchKids(box, next) {
|
|
1384
|
-
const keep = new Set(next);
|
|
1385
|
-
for (const n of Array.from(box.childNodes)) if (!keep.has(n)) n.remove();
|
|
1386
|
-
let at = box.firstChild;
|
|
1387
|
-
for (const n of next) {
|
|
1388
|
-
if (n === at) at = at.nextSibling;
|
|
1389
|
-
else box.insertBefore(n, at);
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
const AGENT_KINDS = ["claude", "codex", "cursor", "gemini", "antigravity", "copilot", "amp", "opencode"];
|
|
1393
|
-
const agentOf = (m) => {
|
|
1394
|
-
if (!m?.session) return "";
|
|
1395
|
-
const k = String(m.session.kind || m.name || "").trim().split(/\W/)[0].toLowerCase();
|
|
1396
|
-
return AGENT_KINDS.includes(k) ? k === "antigravity" ? "gemini" : k : "";
|
|
1397
|
-
};
|
|
1398
|
-
const headers = () => ({ "content-type": "application/json", ...adminToken ? { "x-lab-admin": adminToken } : {} });
|
|
1399
|
-
let gone = false;
|
|
1400
|
-
let loaded = false;
|
|
1401
|
-
let retried = false;
|
|
1402
|
-
const typed = () => Boolean(root.activeElement) || [...root.querySelectorAll("textarea")].some((t) => t.value.trim());
|
|
1403
|
-
async function load() {
|
|
1404
|
-
try {
|
|
1405
|
-
const res = await fetch(`${API}?page=${encodeURIComponent(page)}`, { headers: headers(), cache: "no-store" });
|
|
1406
|
-
if (res.status === 404 && !loaded && script?.dataset.enable !== "always") {
|
|
1407
|
-
if (!retried) {
|
|
1408
|
-
retried = true;
|
|
1409
|
-
setTimeout(load, 1500);
|
|
1410
|
-
return;
|
|
1411
|
-
}
|
|
1412
|
-
gone = true;
|
|
1413
|
-
on = false;
|
|
1414
|
-
document.documentElement.classList.remove("lab-pinning");
|
|
1415
|
-
host2.remove();
|
|
1416
|
-
fonts.remove();
|
|
1417
|
-
return;
|
|
1418
|
-
}
|
|
1419
|
-
if (!res.ok) throw new Error(String(res.status));
|
|
1420
|
-
const data = await res.json();
|
|
1421
|
-
comments = data.comments || [];
|
|
1422
|
-
isAdmin = Boolean(data.admin);
|
|
1423
|
-
loaded = true;
|
|
1424
|
-
} catch {
|
|
1425
|
-
}
|
|
1426
|
-
shownAgain();
|
|
1427
|
-
}
|
|
1428
|
-
async function loadChanges(since) {
|
|
1429
|
-
try {
|
|
1430
|
-
const url = new URL("/_lab/api/changes", new URL(API, location.href));
|
|
1431
|
-
url.search = String(new URLSearchParams({ page, since: String(since) }));
|
|
1432
|
-
const res = await fetch(url, { cache: "no-store" });
|
|
1433
|
-
const data = res.ok ? await res.json() : { full: true };
|
|
1434
|
-
if (data.full || !loaded) return load();
|
|
1435
|
-
const gone2 = new Set(data.del);
|
|
1436
|
-
const fresh = new Map(data.set.map((c) => [c.id, c]));
|
|
1437
|
-
comments = comments.filter((c) => !gone2.has(c.id)).map((c) => fresh.get(c.id) || c);
|
|
1438
|
-
const had = new Set(comments.map((c) => c.id));
|
|
1439
|
-
for (const c of data.set) if (!had.has(c.id)) comments.push(c);
|
|
1440
|
-
comments.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
1441
|
-
} catch {
|
|
1442
|
-
return load();
|
|
1443
|
-
}
|
|
1444
|
-
shownAgain();
|
|
1445
|
-
}
|
|
1446
|
-
function shownAgain() {
|
|
1447
|
-
if (!typed() && !grabbing) render();
|
|
1448
|
-
else {
|
|
1449
|
-
if (openCard?.isConnected) openCard.sync();
|
|
1450
|
-
if (chatOpen) drawChat();
|
|
1451
|
-
drawList();
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
let goMode = store2.get("lab-go") === "1";
|
|
1455
|
-
let cursorMode = store2.get("lab-cursor") === "1";
|
|
1456
|
-
const setCursor = (v) => {
|
|
1457
|
-
cursorMode = v;
|
|
1458
|
-
store2.set("lab-cursor", v ? "1" : "");
|
|
1459
|
-
goBtn.classList.toggle("cursor", v);
|
|
1460
|
-
goBtn.classList.toggle("on", goMode && !v);
|
|
1461
|
-
goFace();
|
|
1462
|
-
document.documentElement.classList.toggle("lab-pinning", on && !v);
|
|
1463
|
-
document.documentElement.classList.toggle("lab-go", on && goMode && !v);
|
|
1464
|
-
recheck();
|
|
1465
|
-
};
|
|
1466
|
-
const setGo = (v) => {
|
|
1467
|
-
if (cursorMode) setCursor(false);
|
|
1468
|
-
goMode = v;
|
|
1469
|
-
queueMicrotask(goFace);
|
|
1470
|
-
store2.set("lab-go", v ? "1" : "");
|
|
1471
|
-
goBtn.classList.toggle("on", v);
|
|
1472
|
-
goBtn.setAttribute("aria-pressed", String(v && !cursorMode));
|
|
1473
|
-
document.documentElement.classList.toggle("lab-go", on && v);
|
|
1474
|
-
ptr.classList.toggle("go", v);
|
|
1475
|
-
recheck();
|
|
1476
|
-
};
|
|
1477
|
-
function begin(anchor) {
|
|
1478
|
-
const name = store2.get("lab-name").trim();
|
|
1479
|
-
if (!goMode || !name) {
|
|
1480
|
-
draft = { anchor };
|
|
1481
|
-
return render();
|
|
1482
|
-
}
|
|
1483
|
-
if (drafting()) {
|
|
1484
|
-
store2.set(heldKey(), JSON.stringify([...held(), { name, text: "go", anchor }]));
|
|
1485
|
-
return render();
|
|
1486
|
-
}
|
|
1487
|
-
send({ name, text: "go", anchor }).then(({ comment, edit }) => {
|
|
1488
|
-
if (edit) store2.set(`lab-edit:${comment.id}`, edit);
|
|
1489
|
-
comments.push(comment);
|
|
1490
|
-
markSeen([comment]);
|
|
1491
|
-
posted = comment.id;
|
|
1492
|
-
render();
|
|
1493
|
-
}).catch(() => (draft = { anchor }, render()));
|
|
1494
|
-
}
|
|
1495
|
-
async function send(payload) {
|
|
1496
|
-
let res = null;
|
|
1497
|
-
if (!payload.action && !payload.nonce) payload = { ...payload, nonce: Math.random().toString(36).slice(2) + Date.now().toString(36) };
|
|
1498
|
-
for (let tries = 0; !res; tries++) {
|
|
1499
|
-
try {
|
|
1500
|
-
res = await fetch(API, { method: "POST", headers: headers(), body: JSON.stringify({ page, ...payload }) });
|
|
1501
|
-
} catch {
|
|
1502
|
-
if (tries >= 150) throw new Error("couldn't reach the lab; your text is still here");
|
|
1503
|
-
await new Promise((r) => setTimeout(r, 2e3));
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
const data = await res.json().catch(() => ({}));
|
|
1507
|
-
if (!res.ok) throw new Error(data.error || `could not save (${res.status})`);
|
|
1508
|
-
if (data.comment && !payload.parent && !payload.action && payload.anchor?.kind !== "page") placed.push(data.comment.id);
|
|
1509
|
-
return data;
|
|
1510
|
-
}
|
|
1511
|
-
const placed = [];
|
|
1512
|
-
async function undoLast() {
|
|
1513
|
-
const id = placed.pop();
|
|
1514
|
-
const c = id && comments.find((x) => x.id === id);
|
|
1515
|
-
if (!c) return;
|
|
1516
|
-
const ownKey = store2.get(`lab-edit:${id}`);
|
|
1517
|
-
try {
|
|
1518
|
-
if (isAdmin) {
|
|
1519
|
-
await send({ action: "delete", id });
|
|
1520
|
-
comments = comments.filter((x) => x.id !== id && x.parent !== id);
|
|
1521
|
-
} else if (ownKey) {
|
|
1522
|
-
const { comment } = await send({ action: "resolve", id, edit: ownKey });
|
|
1523
|
-
Object.assign(c, comment);
|
|
1524
|
-
} else return void placed.push(id);
|
|
1525
|
-
} catch {
|
|
1526
|
-
return void placed.push(id);
|
|
1527
|
-
}
|
|
1528
|
-
if (openId === id) openId = null;
|
|
1529
|
-
render();
|
|
1530
|
-
say(`took back ${/^go$/i.test(c.text.trim()) ? "a go" : "a pin"} \xB7 ${placed.length ? "again for the one before" : "nothing more to take back"}`);
|
|
1531
|
-
}
|
|
1532
|
-
const said = { was: void 0, t: void 0 };
|
|
1533
|
-
function say(words) {
|
|
1534
|
-
said.was ??= hint.textContent;
|
|
1535
|
-
hint.textContent = words;
|
|
1536
|
-
hint.hidden = false;
|
|
1537
|
-
clearTimeout(said.t);
|
|
1538
|
-
said.t = setTimeout(() => {
|
|
1539
|
-
hint.hidden = true;
|
|
1540
|
-
hint.textContent = said.was;
|
|
1541
|
-
said.was = void 0;
|
|
1542
|
-
}, 1800);
|
|
1543
|
-
}
|
|
1544
|
-
const agentLink = () => new URL("/_lab/agent" + page, new URL(API, location.href)).href;
|
|
1545
|
-
async function copy(textPromise, button) {
|
|
1546
|
-
const textValue = await textPromise;
|
|
1547
|
-
try {
|
|
1548
|
-
await navigator.clipboard.writeText(textValue);
|
|
1549
|
-
} catch {
|
|
1550
|
-
const area = document.createElement("textarea");
|
|
1551
|
-
area.value = textValue;
|
|
1552
|
-
area.style.cssText = "position:fixed;opacity:0;";
|
|
1553
|
-
document.body.append(area);
|
|
1554
|
-
area.select();
|
|
1555
|
-
document.execCommand("copy");
|
|
1556
|
-
area.remove();
|
|
1557
|
-
}
|
|
1558
|
-
if (moreMenu.contains(button)) return say("link copied");
|
|
1559
|
-
const label = button.textContent;
|
|
1560
|
-
button.style.width = `${button.getBoundingClientRect().width}px`;
|
|
1561
|
-
button.style.justifyContent = "center";
|
|
1562
|
-
button.textContent = "copied";
|
|
1563
|
-
setTimeout(() => {
|
|
1564
|
-
button.textContent = label;
|
|
1565
|
-
button.style.width = button.style.justifyContent = "";
|
|
1566
|
-
}, 1400);
|
|
1567
|
-
}
|
|
1568
|
-
const threads = () => comments.filter((c) => !c.parent);
|
|
1569
|
-
const heldKey = () => `lab-held:${page}`;
|
|
1570
|
-
const held = () => {
|
|
1571
|
-
try {
|
|
1572
|
-
return JSON.parse(store2.get(heldKey()) || "[]");
|
|
1573
|
-
} catch {
|
|
1574
|
-
return [];
|
|
1575
|
-
}
|
|
1576
|
-
};
|
|
1577
|
-
const listed = () => threads().filter((c) => c.anchor?.kind !== "page").filter((c) => filter === "new" ? unread(c).length : filter === "open" ? !c.resolved : filter === "resolved" ? c.resolved : mine(c)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
1578
|
-
const onWhat = (c) => {
|
|
1579
|
-
const a = c.anchor || {};
|
|
1580
|
-
let w = a.quote?.exact || "";
|
|
1581
|
-
let n = null;
|
|
1582
|
-
try {
|
|
1583
|
-
n = !w && a.selector ? document.querySelector(a.selector) : null;
|
|
1584
|
-
} catch {
|
|
1585
|
-
}
|
|
1586
|
-
for (let up = 0; n && n !== document.body && up < 5; n = n.parentElement, up++) {
|
|
1587
|
-
const t = n.innerText?.replace(/\s+/g, " ").trim() || "";
|
|
1588
|
-
if (t.length >= 12) {
|
|
1589
|
-
w = t;
|
|
1590
|
-
break;
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
w = (w || a.text || a.section || "").replace(/\s+/g, " ").trim();
|
|
1594
|
-
return w ? `"${w.length > 40 ? `${w.slice(0, 39)}\u2026` : w}"` : "";
|
|
1595
|
-
};
|
|
1596
|
-
const isPage = (c) => c.anchor?.kind === "page";
|
|
1597
|
-
let stepping = false;
|
|
1598
|
-
let keepKeys = false;
|
|
1599
|
-
const goTo = (c, keys = false) => {
|
|
1600
|
-
stepping = Boolean(openId);
|
|
1601
|
-
keepKeys = stepping && (keys || root.activeElement?.localName === "textarea");
|
|
1602
|
-
openId = c.id;
|
|
1603
|
-
draft = null;
|
|
1604
|
-
if (coarse) listOpen = false;
|
|
1605
|
-
render();
|
|
1606
|
-
const pinTop = position(c.anchor || {}).top;
|
|
1607
|
-
let top = pinTop - Math.max(40, coarse && openCard?.isConnected ? (innerHeight - openCard.offsetHeight) / 2 : innerHeight / 3);
|
|
1608
|
-
if (!coarse && openCard?.isConnected) {
|
|
1609
|
-
const bottom = openCard.getBoundingClientRect().bottom + scrollY;
|
|
1610
|
-
const tall = bottom - pinTop + 28;
|
|
1611
|
-
top = tall <= innerHeight - 80 ? pinTop - 28 - (innerHeight - tall) / 2 : pinTop - 40;
|
|
1612
|
-
}
|
|
1613
|
-
if (coarse) {
|
|
1614
|
-
const de = document.documentElement;
|
|
1615
|
-
const had = parseFloat(de.style.getPropertyValue("--lab-room")) || 0;
|
|
1616
|
-
const room = Math.max(0, Math.ceil(top + innerHeight - (de.scrollHeight - had)));
|
|
1617
|
-
de.style.setProperty("--lab-room", `${room}px`);
|
|
1618
|
-
de.classList.toggle("lab-room", room > 0);
|
|
1619
|
-
}
|
|
1620
|
-
scrollTo({ top: Math.max(0, top), behavior: still.matches ? "auto" : "smooth" });
|
|
1621
|
-
};
|
|
1622
|
-
const isDone = (c) => c.resolved || workState(c)[0] === "done";
|
|
1623
|
-
const keyWord = (before, key, after) => {
|
|
1624
|
-
const w = el2("span", { class: "kw" });
|
|
1625
|
-
w.append(before, el2("span", { class: "mn", "aria-hidden": "true" }, `(${key})`), after);
|
|
1626
|
-
return w;
|
|
1627
|
-
};
|
|
1628
|
-
function placeBar() {
|
|
1629
|
-
const inMenu = on ? [doneBtn, copyBtn, toggleBtn] : [];
|
|
1630
|
-
for (const b of inMenu) if (b.parentNode !== moreMenu) moreMenu.append(b);
|
|
1631
|
-
if (!on && toggleBtn.parentNode !== bar) bar.insertBefore(toggleBtn, moreBtn);
|
|
1632
|
-
if (!on) root.querySelector(".left").append(copyBtn);
|
|
1633
|
-
moreBtn.hidden = !on;
|
|
1634
|
-
if (!on && !moreMenu.hidden) setMenu(false);
|
|
1635
|
-
let first = true;
|
|
1636
|
-
for (
|
|
1637
|
-
const b of
|
|
1638
|
-
/** @type {HTMLCollectionOf<HTMLElement>} */
|
|
1639
|
-
bar.children
|
|
1640
|
-
) {
|
|
1641
|
-
b.classList.toggle("first", first && !b.hidden);
|
|
1642
|
-
if (!b.hidden) first = false;
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
function goFace() {
|
|
1646
|
-
const gp = goBtn.querySelector(".gp");
|
|
1647
|
-
if (gp) gp.textContent = !goMode && !cursorMode ? initial(store2.get("lab-name")) || "+" : "go";
|
|
1648
|
-
goBtn.setAttribute("aria-label", `a click places: ${cursorMode ? "nothing (cursor)" : goMode ? "go" : "a comment"}`);
|
|
1649
|
-
goBtn.setAttribute("aria-keyshortcuts", "1 2 3");
|
|
1650
|
-
}
|
|
1651
|
-
function drawList() {
|
|
1652
|
-
const all = threads();
|
|
1653
|
-
listBtn.hidden = !on || !coarse && !all.length && !held().length;
|
|
1654
|
-
goBtn.hidden = !on;
|
|
1655
|
-
if (!goBtn.firstElementChild) goBtn.replaceChildren(el2("span", { class: "gp" }, "go"), el2("kbd", { "aria-hidden": "true" }, "1/2/3"));
|
|
1656
|
-
goFace();
|
|
1657
|
-
goBtn.classList.toggle("on", goMode && !cursorMode);
|
|
1658
|
-
goBtn.classList.toggle("cursor", cursorMode);
|
|
1659
|
-
goBtn.setAttribute("aria-pressed", String(goMode && !cursorMode));
|
|
1660
|
-
const freshAll = all.filter((c) => !isPage(c)).reduce((n, c) => n + unread(c).length, 0);
|
|
1661
|
-
listBtn.replaceChildren(document.createTextNode(freshAll ? `list \xB7 ${freshAll} new` : "list"), el2("kbd", { "aria-hidden": "true" }, "l"));
|
|
1662
|
-
newPrev.hidden = newNext.hidden = !on || !all.some((c) => !isPage(c) && unread(c).length);
|
|
1663
|
-
if (!LIST_WINDOW) {
|
|
1664
|
-
newPrev.hidden = newNext.hidden = true;
|
|
1665
|
-
listBtn.hidden = !on;
|
|
1666
|
-
{
|
|
1667
|
-
listBtn.replaceChildren(coarse ? "new" : keyWord("ne", "w", ""), el2("b", { class: `cnt${freshAll ? "" : " zero"}` }, String(freshAll)));
|
|
1668
|
-
listBtn.setAttribute("aria-label", `next new comment, ${freshAll} new`);
|
|
1669
|
-
listBtn.setAttribute("aria-keyshortcuts", "w");
|
|
1670
|
-
}
|
|
1671
|
-
listBtn.title = "next new comment: W, or Control-D while typing (Shift for the one before)";
|
|
1672
|
-
listBtn.disabled = !freshAll;
|
|
1673
|
-
listBtn.classList.toggle("quiet", !freshAll);
|
|
1674
|
-
const doneCount2 = all.filter((c) => !isPage(c) && (c.resolved || workState(c)[0] === "done") && !unread(c).length).length;
|
|
1675
|
-
doneBtn.hidden = !on;
|
|
1676
|
-
doneBtn.disabled = !doneCount2 && !showDone;
|
|
1677
|
-
doneBtn.classList.toggle("quiet", doneBtn.disabled);
|
|
1678
|
-
doneBtn.replaceChildren(showDone ? `hide done \xB7 ${doneCount2}` : `show done \xB7 ${doneCount2}`, el2("kbd", { "aria-hidden": "true" }, "d"));
|
|
1679
|
-
doneBtn.setAttribute("aria-keyshortcuts", "d");
|
|
1680
|
-
}
|
|
1681
|
-
placeBar();
|
|
1682
|
-
const tabNew = all.reduce((n, c) => n + unread(c).length, 0);
|
|
1683
|
-
if (!tabTitle.base || !document.title.startsWith("(")) tabTitle.base = document.title.replace(/^\(\d+\) /, "");
|
|
1684
|
-
const want = tabNew ? `(${tabNew}) ${tabTitle.base}` : tabTitle.base;
|
|
1685
|
-
if (document.title !== want) document.title = want;
|
|
1686
|
-
listBtn.classList.toggle("has-new", freshAll > 0);
|
|
1687
|
-
const h = held().length;
|
|
1688
|
-
sendBtn.hidden = !h;
|
|
1689
|
-
sendBtn.textContent = `send ${h} draft${h === 1 ? "" : "s"}`;
|
|
1690
|
-
listEl.hidden = !on || !listOpen;
|
|
1691
|
-
if (listEl.hidden) return;
|
|
1692
|
-
for (
|
|
1693
|
-
const b of
|
|
1694
|
-
/** @type {NodeListOf<HTMLElement>} */
|
|
1695
|
-
listEl.querySelectorAll("[data-f]")
|
|
1696
|
-
) b.classList.toggle("on", b.dataset.f === filter);
|
|
1697
|
-
const fresh = all.filter((c) => !isPage(c) && unread(c).length).length;
|
|
1698
|
-
listEl.querySelector('[data-f="new"]').textContent = fresh ? `new \xB7 ${fresh}` : "new";
|
|
1699
|
-
for (const f of ["work", "resolved", "mine"]) $(`[data-f="${f}"]`, listEl).hidden = true;
|
|
1700
|
-
holdBtn.hidden = !DRAFT_MODE;
|
|
1701
|
-
const doneCount = all.filter((c) => !isPage(c) && (c.resolved || workState(c)[0] === "done") && !unread(c).length).length;
|
|
1702
|
-
showDoneBtn.hidden = !doneCount;
|
|
1703
|
-
showDoneBtn.textContent = showDone ? `hide done \xB7 ${doneCount}` : `show done \xB7 ${doneCount}`;
|
|
1704
|
-
holdBtn.classList.toggle("on", drafting());
|
|
1705
|
-
if (filter === "work") return listEl.querySelector(".items").replaceChildren(...workItems());
|
|
1706
|
-
const items = listed().map((c) => {
|
|
1707
|
-
const b = el2("button", { class: `it${openId === c.id ? " cur" : ""}`, type: "button" });
|
|
1708
|
-
b.append(document.createTextNode(`${c.resolved ? "\u2713" : numberOf(c)} ${c.text.replace(/\s+/g, " ").slice(0, 70)} `), ...onWhat(c) ? [el2("span", {}, `on ${onWhat(c)} `)] : [], el2("span", {}, `\xB7 ${c.name}${!c.resolved && isDone(c) ? " \xB7 \u2705 done" : ""}`), ...unread(c).length ? [" ", el2("span", { class: "tag" }, `${unread(c).length} new`)] : []);
|
|
1709
|
-
b.addEventListener("click", () => goTo(c));
|
|
1710
|
-
return b;
|
|
1711
|
-
});
|
|
1712
|
-
listEl.querySelector(".items").replaceChildren(...items.length ? items : [el2("div", { class: "none" }, "nothing here")]);
|
|
1713
|
-
}
|
|
1714
|
-
const ago = (iso) => {
|
|
1715
|
-
const m = Math.max(0, Math.round((Date.now() - new Date(iso).getTime()) / 6e4));
|
|
1716
|
-
return m < 1 ? "just now" : m < 60 ? `${m} min` : `${Math.floor(m / 60)} h ${m % 60} min`;
|
|
1717
|
-
};
|
|
1718
|
-
const workState = (c) => {
|
|
1719
|
-
const thread = [c, ...repliesOf(c.id)];
|
|
1720
|
-
const lastPerson = thread.filter((m) => !m.session).map((m) => m.createdAt).sort().at(-1) || "";
|
|
1721
|
-
const answer = thread.filter((m) => m.session).sort((a, b) => a.createdAt.localeCompare(b.createdAt)).at(-1);
|
|
1722
|
-
const answered = answer && answer.createdAt > lastPerson;
|
|
1723
|
-
if (c.resolved || answered && /^done\b/i.test(answer.text)) return ["done", answered ? answer.createdAt : c.createdAt];
|
|
1724
|
-
if (answered && /^on it\b/i.test(answer.text)) return ["now", answer.createdAt];
|
|
1725
|
-
if (!answered && c.handedAt && c.handedAt >= lastPerson) return ["now", c.handedAt];
|
|
1726
|
-
return answered ? [null, ""] : ["next", lastPerson];
|
|
1727
|
-
};
|
|
1728
|
-
function workItems() {
|
|
1729
|
-
const today = (/* @__PURE__ */ new Date()).toDateString();
|
|
1730
|
-
const now = [];
|
|
1731
|
-
const next = [];
|
|
1732
|
-
const done = [];
|
|
1733
|
-
for (const c of comments.filter((x) => !x.parent)) {
|
|
1734
|
-
const [state, at] = workState(c);
|
|
1735
|
-
if (state === "now") now.push([c, at]);
|
|
1736
|
-
else if (state === "next") next.push([c, at]);
|
|
1737
|
-
else if (state === "done" && new Date(at).toDateString() === today) done.push([c, at]);
|
|
1738
|
-
}
|
|
1739
|
-
const row = ([c, at], when) => {
|
|
1740
|
-
const b = el2("button", { class: `it${openId === c.id ? " cur" : ""}`, type: "button" });
|
|
1741
|
-
b.append(document.createTextNode(`${isPage(c) ? "chat" : c.resolved ? "\u2713" : numberOf(c)} ${c.text.replace(/\s+/g, " ").slice(0, 70)} `), el2("span", {}, `\xB7 ${when(at)}`));
|
|
1742
|
-
b.addEventListener("click", () => isPage(c) ? (chatOpen = true, listOpen = false, render()) : goTo(c));
|
|
1743
|
-
return b;
|
|
1744
|
-
};
|
|
1745
|
-
const part = (title, list, when, newest = false) => list.length ? [el2("div", { class: "group" }, `${title} \xB7 ${list.length}`), ...list.sort((a, b) => (newest ? -1 : 1) * a[1].localeCompare(b[1])).map((x) => row(x, when))] : [];
|
|
1746
|
-
const out = [
|
|
1747
|
-
...part("Now", now, (at) => `on it ${ago(at)}`.replace("on it just now", "just started")),
|
|
1748
|
-
...part("Next", next, (at) => `sent ${ago(at)} ago`.replace("just now ago", "just now")),
|
|
1749
|
-
...part("Done today", done, (at) => new Date(at).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), true)
|
|
1750
|
-
];
|
|
1751
|
-
return out.length ? out : [el2("div", { class: "none" }, "nothing in progress on this page")];
|
|
1752
|
-
}
|
|
1753
|
-
const stamped = (bubble, stamp) => {
|
|
1754
|
-
const room = stamp.cloneNode(true);
|
|
1755
|
-
room.className = "stamp-room";
|
|
1756
|
-
room.setAttribute("aria-hidden", "true");
|
|
1757
|
-
for (const n of room.querySelectorAll("[role]")) n.removeAttribute("role");
|
|
1758
|
-
const last = [...bubble.children].reverse().find((n) => n.classList?.contains("p"));
|
|
1759
|
-
(last || bubble).append(room);
|
|
1760
|
-
bubble.append(stamp);
|
|
1761
|
-
};
|
|
1762
|
-
const stampOf = (m, root2, prefix = "") => {
|
|
1763
|
-
const at = new Date(m.createdAt);
|
|
1764
|
-
const time = at.toDateString() === (/* @__PURE__ */ new Date()).toDateString() ? at.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) : at.toLocaleDateString([], { day: "numeric", month: "short" });
|
|
1765
|
-
const stamp = el2("span", { class: "stamp" });
|
|
1766
|
-
stamp.append(el2("span", { class: "tm" }, prefix + time));
|
|
1767
|
-
if (mine(m) && !m.session) {
|
|
1768
|
-
const thread = root2 ? [root2, ...repliesOf(root2.id)] : [m];
|
|
1769
|
-
const answered = thread.some((x) => x.session && x.createdAt > m.createdAt);
|
|
1770
|
-
const latest = !thread.some((x) => !x.session && x.createdAt > m.createdAt);
|
|
1771
|
-
if (!answered && latest && root2 && workState(root2)[0] === "now") {
|
|
1772
|
-
stamp.classList.add("busy");
|
|
1773
|
-
stamp.append(el2("span", { class: "ring", role: "img", "aria-label": "the agent is on it" }));
|
|
1774
|
-
} else if (answered) {
|
|
1775
|
-
stamp.classList.add("ans");
|
|
1776
|
-
stamp.append(el2("span", { class: "tick", role: "img", "aria-label": "answered" }, "\u2713"));
|
|
1777
|
-
} else {
|
|
1778
|
-
const got = root2?.handedAt && root2.handedAt >= m.createdAt;
|
|
1779
|
-
stamp.append(el2("span", { class: `tick${got ? " got" : ""}`, role: "img", "aria-label": got ? "delivered to the agent" : "sent" }, got ? "\u2713\u2713" : "\u2713"));
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
return stamp;
|
|
1783
|
-
};
|
|
1784
|
-
let replyTo = null;
|
|
1785
|
-
let newFrom = null;
|
|
1786
|
-
function drawChat() {
|
|
1787
|
-
const byId = new Map(comments.map((c) => [c.id, c]));
|
|
1788
|
-
const msgs = comments.filter((c) => isPage(c) || c.parent && isPage(byId.get(c.parent) || {})).sort((a, b) => a.createdAt.localeCompare(b.createdAt)).slice(-150);
|
|
1789
|
-
if (on && chatOpen && chatEl.hidden) newFrom = msgs.find(isNew)?.id || null;
|
|
1790
|
-
if (!chatOpen) newFrom = null;
|
|
1791
|
-
if (on && chatOpen) markSeen(msgs.filter(isNew));
|
|
1792
|
-
const fresh = msgs.filter(isNew).length;
|
|
1793
|
-
chatBtn.hidden = !on;
|
|
1794
|
-
{
|
|
1795
|
-
chatBtn.replaceChildren(coarse ? "chat" : keyWord("", "c", "hat"), el2("b", { class: `cnt${fresh ? "" : " zero"}` }, String(fresh)));
|
|
1796
|
-
chatBtn.setAttribute("aria-label", `chat, ${fresh} new`);
|
|
1797
|
-
chatBtn.setAttribute("aria-keyshortcuts", "c");
|
|
1798
|
-
}
|
|
1799
|
-
chatBtn.classList.toggle("has-new", fresh > 0);
|
|
1800
|
-
placeBar();
|
|
1801
|
-
const opening = chatEl.hidden;
|
|
1802
|
-
chatEl.hidden = !on || !chatOpen;
|
|
1803
|
-
if (chatEl.hidden) chatEl.classList.remove("full");
|
|
1804
|
-
if (chatEl.hidden && chatEl.contains(root.activeElement)) root.activeElement.blur();
|
|
1805
|
-
if (chatEl.hidden) return;
|
|
1806
|
-
const box = $(".msgs", chatEl);
|
|
1807
|
-
const atEnd = opening || box.scrollHeight - box.scrollTop - box.clientHeight < 48;
|
|
1808
|
-
const before = new Set(opening ? [] : [.../** @type {HTMLCollectionOf<HTMLElement>} */
|
|
1809
|
-
box.children].map((n) => n.dataset.id));
|
|
1810
|
-
const kept = new Map([.../** @type {HTMLCollectionOf<HTMLElement>} */
|
|
1811
|
-
box.children].filter((n) => n.dataset.id).map((n) => [n.dataset.id, n]));
|
|
1812
|
-
const same = (n) => {
|
|
1813
|
-
const old = kept.get(n.dataset?.id);
|
|
1814
|
-
return old && old.outerHTML.replace(" fresh", "") === n.outerHTML ? old : n;
|
|
1815
|
-
};
|
|
1816
|
-
patchKids(box, msgs.flatMap((m) => {
|
|
1817
|
-
const root2 = m.parent ? byId.get(m.parent) : m;
|
|
1818
|
-
const b = el2("div", { class: `msg${mine(m) && !m.session ? " mine" : ""}${root2 && replyTo === root2.id ? " to" : ""}${before.size && !before.has(m.id) ? " fresh" : ""}`, "data-id": m.id, ...agentOf(m) ? { "data-agent": agentOf(m) } : {} });
|
|
1819
|
-
b.append(nameLine(m.name, false));
|
|
1820
|
-
if (m.parent && root2) {
|
|
1821
|
-
const q = el2("div", { class: "quote" });
|
|
1822
|
-
q.append(el2("b", {}, String(root2.name || "").replace(/\s*·\s*session\s+\S+$/i, "")), document.createTextNode(root2.text.replace(/\s+/g, " ").slice(0, 90)));
|
|
1823
|
-
q.addEventListener("click", (e) => {
|
|
1824
|
-
e.stopPropagation();
|
|
1825
|
-
const box2 = $(".msgs", chatEl);
|
|
1826
|
-
const to = $(`[data-id="${root2.id}"]`, box2);
|
|
1827
|
-
if (!to) return;
|
|
1828
|
-
box2.scrollTo({ top: to.offsetTop - box2.offsetTop - 12, behavior: still.matches ? "auto" : "smooth" });
|
|
1829
|
-
to.animate?.([{ boxShadow: "0 0 0 2px rgb(52,199,89)" }, { boxShadow: "0 0 0 0 transparent" }], { duration: 900 });
|
|
1830
|
-
});
|
|
1831
|
-
b.append(q);
|
|
1832
|
-
}
|
|
1833
|
-
b.append(...readable(m.text));
|
|
1834
|
-
stamped(b, stampOf(m, root2));
|
|
1835
|
-
return m.id === newFrom && m !== msgs[0] ? [el2("div", { class: "newline" }, "new"), b] : [b];
|
|
1836
|
-
}).map(same));
|
|
1837
|
-
const strip = $(".replying", chatEl);
|
|
1838
|
-
const target = replyTo && byId.get(replyTo);
|
|
1839
|
-
strip.hidden = !target;
|
|
1840
|
-
if (target) {
|
|
1841
|
-
const x = el2("button", { type: "button", title: "about the page instead" }, "\u2715");
|
|
1842
|
-
x.addEventListener("click", () => (replyTo = null, drawChat()));
|
|
1843
|
-
strip.replaceChildren(document.createTextNode(`\u21A9 ${target.name}: ${target.text.replace(/\s+/g, " ").slice(0, 40)}`), x);
|
|
1844
|
-
}
|
|
1845
|
-
if (!box.firstChild) box.append(el2("div", { class: "none" }, "say something about the page as a whole"));
|
|
1846
|
-
const chat = chatEl.querySelector(".chat");
|
|
1847
|
-
if (!chat.firstChild)
|
|
1848
|
-
chat.append(
|
|
1849
|
-
composer({
|
|
1850
|
-
placeholder: "message",
|
|
1851
|
-
onSubmit: async (name, text) => {
|
|
1852
|
-
const { comment } = await send(
|
|
1853
|
-
replyTo ? { name, text, parent: replyTo } : { name, text, anchor: { kind: "page", width: innerWidth, height: innerHeight, dpr: devicePixelRatio || 1 } }
|
|
1854
|
-
);
|
|
1855
|
-
const answered = replyTo && comments.find((x) => x.id === replyTo);
|
|
1856
|
-
if (answered?.resolved) answered.resolved = false;
|
|
1857
|
-
replyTo = null;
|
|
1858
|
-
comments.push(comment);
|
|
1859
|
-
markSeen([comment]);
|
|
1860
|
-
box.scrollTop = box.scrollHeight;
|
|
1861
|
-
render();
|
|
1862
|
-
return { keep: true };
|
|
1863
|
-
}
|
|
1864
|
-
})
|
|
1865
|
-
);
|
|
1866
|
-
chat.querySelector("textarea").placeholder = target ? "reply" : "message";
|
|
1867
|
-
if (atEnd) box.scrollTop = box.scrollHeight;
|
|
1868
|
-
}
|
|
1869
|
-
const numberOf = (c) => comments.filter((x) => !x.parent && !x.resolved).sort((a, b) => a.createdAt.localeCompare(b.createdAt)).indexOf(c) + 1;
|
|
1870
|
-
const seenKey = () => `lab-seen:${page}`;
|
|
1871
|
-
const readSeen = () => new Set(store2.get(seenKey()).split(",").filter(Boolean));
|
|
1872
|
-
let seen = readSeen();
|
|
1873
|
-
const plain = (n) => String(n || "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
1874
|
-
const mine = (c) => plain(c.name) && plain(c.name) === plain(store2.get("lab-name")) || Boolean(store2.get(`lab-edit:${c.id}`));
|
|
1875
|
-
const isNew = (c) => !seen.has(c.id) && !mine(c);
|
|
1876
|
-
const unread = (c) => [c, ...repliesOf(c.id)].filter(isNew);
|
|
1877
|
-
const markSeen = (items) => {
|
|
1878
|
-
const fresh = items.filter((item) => !seen.has(item.id)).map((item) => item.id);
|
|
1879
|
-
for (const item of items) seen.add(item.id);
|
|
1880
|
-
store2.set(seenKey(), [...seen].join(","));
|
|
1881
|
-
if (fresh.length) shareReads(fresh);
|
|
1882
|
-
};
|
|
1883
|
-
const READS = script?.dataset.live ? script.dataset.live.replace(/live$/, "api/reads") : "";
|
|
1884
|
-
const shareReads = (ids) => {
|
|
1885
|
-
const who = store2.get("lab-name").trim();
|
|
1886
|
-
if (!READS || !who || !ids.length) return;
|
|
1887
|
-
fetch(READS, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ name: who, page, ids }) }).catch(() => {
|
|
1888
|
-
});
|
|
1889
|
-
};
|
|
1890
|
-
async function syncReads() {
|
|
1891
|
-
const who = store2.get("lab-name").trim();
|
|
1892
|
-
if (!READS || !who) return;
|
|
1893
|
-
const at = page;
|
|
1894
|
-
try {
|
|
1895
|
-
const { ids } = await (await fetch(`${READS}?name=${encodeURIComponent(who)}&page=${encodeURIComponent(at)}`, { cache: "no-store" })).json();
|
|
1896
|
-
if (at !== page) return;
|
|
1897
|
-
const theirs = new Set(ids);
|
|
1898
|
-
const mineOnly = [...seen].filter((id) => !theirs.has(id));
|
|
1899
|
-
const added = ids.filter((id) => !seen.has(id));
|
|
1900
|
-
if (mineOnly.length) shareReads(mineOnly);
|
|
1901
|
-
if (!added.length) return;
|
|
1902
|
-
for (const id of added) seen.add(id);
|
|
1903
|
-
store2.set(seenKey(), [...seen].join(","));
|
|
1904
|
-
shownAgain();
|
|
1905
|
-
} catch {
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
const repliesOf = (id) => comments.filter((c) => c.parent === id);
|
|
1909
|
-
const initial = (name) => [...String(name || "").trim()][0]?.toUpperCase() || "";
|
|
1910
|
-
function placeCard(card, left, top) {
|
|
1911
|
-
layer2.append(card);
|
|
1912
|
-
const width = card.offsetWidth;
|
|
1913
|
-
const maxLeft = scrollX + document.documentElement.clientWidth - width - 12;
|
|
1914
|
-
card.style.left = `${Math.max(scrollX + 12, Math.min(left - 14, maxLeft))}px`;
|
|
1915
|
-
const h = card.offsetHeight;
|
|
1916
|
-
const below = top + 10 + h > contentEnd();
|
|
1917
|
-
card.style.top = `${below ? Math.max(scrollY + 8, top - 40 - h) : top + 10}px`;
|
|
1918
|
-
card.style.transformOrigin = below ? "14px 100%" : "";
|
|
1919
|
-
}
|
|
1920
|
-
const contentEnd = () => {
|
|
1921
|
-
inPage(0);
|
|
1922
|
-
return pageEnd.y;
|
|
1923
|
-
};
|
|
1924
|
-
const ARROW = '<i class="arr" aria-hidden="true"></i>';
|
|
1925
|
-
function composer({ placeholder, onSubmit, autofocus = false }) {
|
|
1926
|
-
const wrap = el2("div", { class: "composer" });
|
|
1927
|
-
const box = el2("div", { class: "box" });
|
|
1928
|
-
const text = el2("textarea", { placeholder, maxlength: "2000", rows: "1", "aria-label": placeholder, enterkeyhint: "send", autocomplete: "off", autocorrect: "off", spellcheck: "false", writingsuggestions: "false" });
|
|
1929
|
-
const who = el2("label", { class: "who" });
|
|
1930
|
-
const as = el2("span", {}, "as");
|
|
1931
|
-
const name = el2("input", { type: "text", placeholder: "your name", maxlength: "60", enterkeyhint: "send", autocomplete: "off", autocorrect: "off", autocapitalize: "words", spellcheck: "false", writingsuggestions: "false", "data-1p-ignore": "", "data-lpignore": "true" });
|
|
1932
|
-
name.value = store2.get("lab-name");
|
|
1933
|
-
who.append(as, name);
|
|
1934
|
-
const sendBtn2 = el2("button", { class: "send", type: "button", "aria-label": "send" });
|
|
1935
|
-
sendBtn2.addEventListener("pointerdown", (e) => e.preventDefault());
|
|
1936
|
-
sendBtn2.addEventListener("mousedown", (e) => e.preventDefault());
|
|
1937
|
-
sendBtn2.innerHTML = ARROW;
|
|
1938
|
-
const error = el2("div", { class: "error" });
|
|
1939
|
-
box.append(text, el2("div", { class: "line" }), who, sendBtn2);
|
|
1940
|
-
wrap.append(box, error);
|
|
1941
|
-
box.addEventListener("click", (e) => {
|
|
1942
|
-
if (e.target !== box && !e.target.classList?.contains("line")) return;
|
|
1943
|
-
text.focus({ preventScroll: true });
|
|
1944
|
-
text.setSelectionRange(text.value.length, text.value.length);
|
|
1945
|
-
});
|
|
1946
|
-
const sync = () => {
|
|
1947
|
-
const open = text.value.length > 0 || root.activeElement === name || !!error.textContent;
|
|
1948
|
-
const glide = open !== box.classList.contains("open") && !store2.get("lab-name") && box.isConnected && !matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1949
|
-
const from = glide && { arrow: sendBtn2.getBoundingClientRect(), height: box.getBoundingClientRect().height };
|
|
1950
|
-
const one = Boolean(store2.get("lab-name"));
|
|
1951
|
-
box.classList.toggle("one", one);
|
|
1952
|
-
box.classList.toggle("open", open);
|
|
1953
|
-
as.hidden = !name.value.trim();
|
|
1954
|
-
if (one && !CSS.supports?.("field-sizing", "content")) name.style.width = `${Math.max(2, name.value.length + 1)}ch`;
|
|
1955
|
-
sendBtn2.classList.toggle("ready", Boolean(text.value.trim() && name.value.trim()));
|
|
1956
|
-
text.style.height = "auto";
|
|
1957
|
-
text.style.height = `${text.scrollHeight}px`;
|
|
1958
|
-
if (glide) {
|
|
1959
|
-
const to = sendBtn2.getBoundingClientRect();
|
|
1960
|
-
const timing = { duration: 220, easing: "cubic-bezier(.2, .7, .3, 1)" };
|
|
1961
|
-
sendBtn2.animate([{ transform: `translate(${from.arrow.left - to.left}px, ${from.arrow.top - to.top}px)` }, { transform: "none" }], timing);
|
|
1962
|
-
box.style.overflow = "hidden";
|
|
1963
|
-
box.animate([{ height: `${from.height}px` }, { height: `${box.getBoundingClientRect().height}px` }], timing).onfinish = () => box.style.overflow = "";
|
|
1964
|
-
}
|
|
1965
|
-
};
|
|
1966
|
-
let busy = false;
|
|
1967
|
-
const go = async () => {
|
|
1968
|
-
if (busy) return;
|
|
1969
|
-
if (!text.value.trim()) return text.focus();
|
|
1970
|
-
if (!name.value.trim()) {
|
|
1971
|
-
box.classList.add("open");
|
|
1972
|
-
return name.focus();
|
|
1973
|
-
}
|
|
1974
|
-
store2.set("lab-name", name.value.trim());
|
|
1975
|
-
refreshPinCursor();
|
|
1976
|
-
syncReads();
|
|
1977
|
-
sendBtn2.classList.remove("sent");
|
|
1978
|
-
void sendBtn2.offsetWidth;
|
|
1979
|
-
sendBtn2.classList.add("sent");
|
|
1980
|
-
busy = true;
|
|
1981
|
-
error.textContent = "";
|
|
1982
|
-
error.classList.remove("wait");
|
|
1983
|
-
const slow = setTimeout(() => {
|
|
1984
|
-
error.textContent = "sending\u2026 it goes as soon as the lab is back";
|
|
1985
|
-
error.classList.add("wait");
|
|
1986
|
-
}, 1500);
|
|
1987
|
-
try {
|
|
1988
|
-
const result = await onSubmit(name.value.trim(), text.value.trim());
|
|
1989
|
-
clearTimeout(slow);
|
|
1990
|
-
error.textContent = "";
|
|
1991
|
-
error.classList.remove("wait");
|
|
1992
|
-
if (result?.keep) {
|
|
1993
|
-
text.value = "";
|
|
1994
|
-
sync();
|
|
1995
|
-
}
|
|
1996
|
-
} catch (e) {
|
|
1997
|
-
clearTimeout(slow);
|
|
1998
|
-
error.classList.remove("wait");
|
|
1999
|
-
error.textContent = e.message;
|
|
2000
|
-
sync();
|
|
2001
|
-
}
|
|
2002
|
-
busy = false;
|
|
2003
|
-
};
|
|
2004
|
-
const onKey = (e) => {
|
|
2005
|
-
if (e.key === "Enter" && !e.shiftKey && !e.isComposing) {
|
|
2006
|
-
e.preventDefault();
|
|
2007
|
-
go();
|
|
2008
|
-
}
|
|
2009
|
-
};
|
|
2010
|
-
text.addEventListener("input", sync);
|
|
2011
|
-
name.addEventListener("input", sync);
|
|
2012
|
-
name.addEventListener("blur", () => setTimeout(sync, 0));
|
|
2013
|
-
text.addEventListener("keydown", onKey);
|
|
2014
|
-
name.addEventListener("keydown", onKey);
|
|
2015
|
-
sendBtn2.addEventListener("click", go);
|
|
2016
|
-
sendBtn2.addEventListener("mousedown", (e) => e.preventDefault());
|
|
2017
|
-
requestAnimationFrame(sync);
|
|
2018
|
-
const focus = () => text.focus({ preventScroll: true });
|
|
2019
|
-
if (autofocus) queueMicrotask(() => text.isConnected ? focus() : setTimeout(focus, 0));
|
|
2020
|
-
return wrap;
|
|
2021
|
-
}
|
|
2022
|
-
function placeBeside(node, left, top) {
|
|
2023
|
-
layer2.append(node);
|
|
2024
|
-
const width = node.offsetWidth;
|
|
2025
|
-
const right = scrollX + document.documentElement.clientWidth - 12;
|
|
2026
|
-
const h = node.offsetHeight;
|
|
2027
|
-
const end = contentEnd();
|
|
2028
|
-
if (left + 36 + width <= right) {
|
|
2029
|
-
node.style.left = `${left + 36}px`;
|
|
2030
|
-
node.style.top = `${Math.min(top - 37, end - h - 8)}px`;
|
|
2031
|
-
} else {
|
|
2032
|
-
node.style.left = `${Math.max(scrollX + 12, Math.min(left - 14, right - width))}px`;
|
|
2033
|
-
node.style.top = `${top + 10 + h > end ? Math.max(scrollY + 8, top - 40 - h) : top + 10}px`;
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
|
-
let shown = null;
|
|
2037
|
-
let posted = null;
|
|
2038
|
-
const still = matchMedia("(prefers-reduced-motion: reduce)");
|
|
2039
|
-
const pinsById = /* @__PURE__ */ new Map();
|
|
2040
|
-
let dropDrag = null;
|
|
2041
|
-
function render() {
|
|
2042
|
-
grabbing = false;
|
|
2043
|
-
dropDrag?.();
|
|
2044
|
-
const prev = (
|
|
2045
|
-
/** @type {HTMLElement | null} */
|
|
2046
|
-
layer2.querySelector(".card:not(.out), .float:not(.out)")
|
|
2047
|
-
);
|
|
2048
|
-
const prevHeight = stepping && coarse && prev ? prev.offsetHeight : 0;
|
|
2049
|
-
const prevScroll = prev ? prev.querySelector(".body")?.scrollTop ?? null : null;
|
|
2050
|
-
const places = new Map(on ? threads().filter((c) => c.anchor?.kind !== "page").map((c) => [c.id, position(c.anchor || {})]) : []);
|
|
2051
|
-
layer2.replaceChildren();
|
|
2052
|
-
pinsById.clear();
|
|
2053
|
-
const now = on ? draft || openId : null;
|
|
2054
|
-
const appear = now !== shown;
|
|
2055
|
-
const anim = appear ? " in" : "";
|
|
2056
|
-
let quoted = null;
|
|
2057
|
-
const done = () => {
|
|
2058
|
-
if (closeFast && !now && prev) {
|
|
2059
|
-
closeFast = false;
|
|
2060
|
-
prev.inert = true;
|
|
2061
|
-
layer2.append(prev);
|
|
2062
|
-
const gone2 = () => prev.remove();
|
|
2063
|
-
if (still.matches || !prev.animate) gone2();
|
|
2064
|
-
else prev.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 120, easing: "ease-out", fill: "forwards" }).finished.then(gone2, gone2);
|
|
2065
|
-
} else if (coarse && !now && shown && prev && !still.matches && !prev.style.transform) {
|
|
2066
|
-
prev.classList.remove("in");
|
|
2067
|
-
prev.classList.add("out");
|
|
2068
|
-
prev.inert = true;
|
|
2069
|
-
layer2.append(prev);
|
|
2070
|
-
setTimeout(() => prev.remove(), coarse ? 230 : 150);
|
|
2071
|
-
}
|
|
2072
|
-
markQuote(quoted);
|
|
2073
|
-
shown = now;
|
|
2074
|
-
posted = null;
|
|
2075
|
-
};
|
|
2076
|
-
const list = threads();
|
|
2077
|
-
const open = list.filter((c) => !c.resolved && c.anchor?.kind !== "page").length;
|
|
2078
|
-
const fresh = list.filter((c) => !c.resolved && c.anchor?.kind !== "page").reduce((n, c) => n + unread(c).length, 0);
|
|
2079
|
-
toggleBtn.replaceChildren(
|
|
2080
|
-
document.createTextNode((on ? "hide comments" : open ? `comments \xB7 ${open}` : "comments") + (!on && fresh ? ` \xB7 ${fresh} new` : "")),
|
|
2081
|
-
el2("kbd", { "aria-hidden": "true" }, "m")
|
|
2082
|
-
);
|
|
2083
|
-
toggleBtn.classList.toggle("secondary", on);
|
|
2084
|
-
host2.toggleAttribute("data-sheet", Boolean(on && (draft || openId || listOpen || chatOpen)));
|
|
2085
|
-
document.documentElement.classList.toggle("lab-sheet", host2.hasAttribute("data-sheet"));
|
|
2086
|
-
backCloses();
|
|
2087
|
-
refit();
|
|
2088
|
-
document.documentElement.classList.toggle("lab-pinning", on && !cursorMode);
|
|
2089
|
-
document.documentElement.classList.toggle("lab-go", on && goMode && !cursorMode);
|
|
2090
|
-
copyBtn.hidden = !on || !isAdmin || list.every((c) => c.resolved);
|
|
2091
|
-
drawList();
|
|
2092
|
-
drawChat();
|
|
2093
|
-
if (!on) return done();
|
|
2094
|
-
for (const h of held()) {
|
|
2095
|
-
const { left, top } = position(h.anchor);
|
|
2096
|
-
const p = el2("div", { class: "pin held", title: `${h.name}: ${h.text} \xB7 draft, not sent yet` }, initial(h.name));
|
|
2097
|
-
p.style.left = `${left}px`;
|
|
2098
|
-
p.style.top = `${top}px`;
|
|
2099
|
-
layer2.append(p);
|
|
2100
|
-
}
|
|
2101
|
-
list.forEach((c) => {
|
|
2102
|
-
if (isPage(c)) return;
|
|
2103
|
-
if (!showDone && openId !== c.id && (c.resolved || workState(c)[0] === "done") && !unread(c).length) return;
|
|
2104
|
-
const { left, top, moved, zone } = places.get(c.id) || position(c.anchor || {});
|
|
2105
|
-
if (openId === c.id) drawZone(zone, `saved${anim}`);
|
|
2106
|
-
const news = unread(c);
|
|
2107
|
-
const movable = !zone && (isAdmin || store2.get(`lab-edit:${c.id}`));
|
|
2108
|
-
const [state] = workState(c);
|
|
2109
|
-
const pin = el2(
|
|
2110
|
-
"button",
|
|
2111
|
-
{
|
|
2112
|
-
class: `pin${/^go$/i.test(c.text.trim()) ? " go" : ""}${c.resolved ? " resolved" : ""}${state === "done" ? " done" : ""}${state === "now" ? " working" : ""}${news.length ? " new" : ""}${moved ? " moved" : ""}${posted === c.id ? " in" : ""}${movable ? " grab" : ""}${openId === c.id ? " open" : ""}`,
|
|
2113
|
-
type: "button",
|
|
2114
|
-
title: `${c.resolved ? "" : `${numberOf(c)} \xB7 `}${c.name}${moved ? " \xB7 the spot it was pinned to has changed" : ""}${movable ? " \xB7 drag to move" : ""}`,
|
|
2115
|
-
// Its state in words too (the ring, the tick and the new dot are only seen).
|
|
2116
|
-
"aria-label": `${/^go$/i.test(c.text.trim()) ? "go" : "comment"}${c.resolved ? "" : ` ${numberOf(c)}`} by ${c.name}${state === "now" ? ", agent working on it" : state === "done" || c.resolved ? ", done" : ""}${news.length ? `, ${news.length} new` : ""}${moved ? ", moved" : ""}`
|
|
2117
|
-
},
|
|
2118
|
-
/^go$/i.test(c.text.trim()) ? "go" : state === "done" || c.resolved ? "\u2713" : initial(c.name)
|
|
2119
|
-
);
|
|
2120
|
-
if (state === "now") pin.append(el2("i", { class: "ring", "aria-hidden": "true" }));
|
|
2121
|
-
pin.style.left = `${left}px`;
|
|
2122
|
-
pin.style.top = `${top}px`;
|
|
2123
|
-
if (movable) grab(pin, c);
|
|
2124
|
-
if (!coarse && zone && openId !== c.id) {
|
|
2125
|
-
let shown2 = null;
|
|
2126
|
-
pin.addEventListener("pointerenter", () => shown2 = drawZone(zone, "saved"));
|
|
2127
|
-
pin.addEventListener("pointerleave", () => (shown2?.remove(), shown2 = null));
|
|
2128
|
-
} else if (!coarse && c.anchor?.quote && !zone) {
|
|
2129
|
-
pin.addEventListener("pointerenter", () => markQuote(c.anchor));
|
|
2130
|
-
pin.addEventListener("pointerleave", () => markQuote(quoted));
|
|
2131
|
-
}
|
|
2132
|
-
pin.addEventListener("click", (e) => {
|
|
2133
|
-
e.stopPropagation();
|
|
2134
|
-
if (pin.dataset.dragged) return;
|
|
2135
|
-
if (coarse && openId !== c.id) return goTo(c);
|
|
2136
|
-
openId = openId === c.id ? null : c.id;
|
|
2137
|
-
draft = null;
|
|
2138
|
-
render();
|
|
2139
|
-
});
|
|
2140
|
-
layer2.append(pin);
|
|
2141
|
-
pinsById.set(c.id, pin);
|
|
2142
|
-
if (openId === c.id) {
|
|
2143
|
-
const card = threadCard(c, new Set(news.map((x) => x.id)), appear && (coarse ? keepKeys : !stepping || keepKeys));
|
|
2144
|
-
openCard = card;
|
|
2145
|
-
if (appear && !stepping) card.classList.add("in");
|
|
2146
|
-
if (prevHeight) card.style.minHeight = `min(${prevHeight}px, var(--_sheet-max))`;
|
|
2147
|
-
stepping = keepKeys = false;
|
|
2148
|
-
placeCard(card, zone ? left + 14 : left, zone ? zone.top + zone.height : top);
|
|
2149
|
-
if (!appear && prevScroll != null) card.querySelector(".body").scrollTop = prevScroll;
|
|
2150
|
-
else if (appear) {
|
|
2151
|
-
const body = card.querySelector(".body");
|
|
2152
|
-
const first = coarse ? null : body.querySelector(".fresh, .newline");
|
|
2153
|
-
body.scrollTop = first ? first.offsetTop - body.offsetTop - 8 : body.scrollHeight;
|
|
2154
|
-
}
|
|
2155
|
-
if (coarse && cardFull) card.classList.add("full");
|
|
2156
|
-
swipeDown(card, () => (openId = null, cardFull = false, render()), true);
|
|
2157
|
-
markSeen(news);
|
|
2158
|
-
if (news.length) drawList();
|
|
2159
|
-
quoted = zone ? null : c.anchor;
|
|
2160
|
-
}
|
|
2161
|
-
});
|
|
2162
|
-
if (draft) {
|
|
2163
|
-
const { anchor } = draft;
|
|
2164
|
-
const { left, top, zone } = position(anchor);
|
|
2165
|
-
drawZone(zone, "draft");
|
|
2166
|
-
quoted = zone ? null : anchor;
|
|
2167
|
-
const pin = el2("div", { class: `pin draft${anim}` }, initial(store2.get("lab-name")));
|
|
2168
|
-
pin.style.left = `${left}px`;
|
|
2169
|
-
pin.style.top = `${top}px`;
|
|
2170
|
-
layer2.append(pin);
|
|
2171
|
-
const float = el2("div", { class: `float${anim}` });
|
|
2172
|
-
float.append(
|
|
2173
|
-
el2("div", { class: "handle" }),
|
|
2174
|
-
composer({
|
|
2175
|
-
placeholder: "add a comment",
|
|
2176
|
-
autofocus: true,
|
|
2177
|
-
onSubmit: async (name, text) => {
|
|
2178
|
-
if (drafting()) {
|
|
2179
|
-
store2.set(heldKey(), JSON.stringify([...held(), { name, text, anchor }]));
|
|
2180
|
-
draft = null;
|
|
2181
|
-
return render();
|
|
2182
|
-
}
|
|
2183
|
-
const { comment, edit } = await send({ name, text, anchor });
|
|
2184
|
-
if (edit) store2.set(`lab-edit:${comment.id}`, edit);
|
|
2185
|
-
comments.push(comment);
|
|
2186
|
-
markSeen([comment]);
|
|
2187
|
-
draft = null;
|
|
2188
|
-
openId = null;
|
|
2189
|
-
posted = comment.id;
|
|
2190
|
-
render();
|
|
2191
|
-
}
|
|
2192
|
-
})
|
|
2193
|
-
);
|
|
2194
|
-
swipeDown(float, () => (draft = null, render()));
|
|
2195
|
-
if (zone) placeCard(float, left + 14, zone.top + zone.height);
|
|
2196
|
-
else placeBeside(float, left, top);
|
|
2197
|
-
}
|
|
2198
|
-
done();
|
|
2199
|
-
}
|
|
2200
|
-
let grabbing = false;
|
|
2201
|
-
function grab(pin, c) {
|
|
2202
|
-
pin.addEventListener("pointerdown", (e) => {
|
|
2203
|
-
if (e.button !== 0) return;
|
|
2204
|
-
const r = pin.getBoundingClientRect();
|
|
2205
|
-
const tip = { dx: e.clientX - r.left, dy: e.clientY - r.bottom };
|
|
2206
|
-
const start2 = { x: e.clientX, y: e.clientY, sx: scrollX, sy: scrollY, left: parseFloat(pin.style.left), top: parseFloat(pin.style.top) };
|
|
2207
|
-
let moving = false;
|
|
2208
|
-
let last = e;
|
|
2209
|
-
grabbing = true;
|
|
2210
|
-
pin.setPointerCapture(e.pointerId);
|
|
2211
|
-
const place2 = () => {
|
|
2212
|
-
pin.style.left = `${start2.left + last.clientX - start2.x + scrollX - start2.sx}px`;
|
|
2213
|
-
pin.style.top = `${start2.top + last.clientY - start2.y + scrollY - start2.sy}px`;
|
|
2214
|
-
};
|
|
2215
|
-
const move = (ev) => {
|
|
2216
|
-
last = ev;
|
|
2217
|
-
if (!moving && Math.hypot(ev.clientX - start2.x, ev.clientY - start2.y) < 5) return;
|
|
2218
|
-
moving = true;
|
|
2219
|
-
pin.classList.add("dragging");
|
|
2220
|
-
place2();
|
|
2221
|
-
};
|
|
2222
|
-
const scrolled = () => moving && place2();
|
|
2223
|
-
addEventListener("scroll", scrolled, true);
|
|
2224
|
-
dropDrag = () => {
|
|
2225
|
-
removeEventListener("scroll", scrolled, true);
|
|
2226
|
-
dropDrag = null;
|
|
2227
|
-
};
|
|
2228
|
-
const up = async (ev) => {
|
|
2229
|
-
pin.removeEventListener("pointermove", move);
|
|
2230
|
-
pin.removeEventListener("pointerup", up);
|
|
2231
|
-
pin.removeEventListener("pointercancel", up);
|
|
2232
|
-
pin.removeEventListener("lostpointercapture", up);
|
|
2233
|
-
dropDrag?.();
|
|
2234
|
-
if (!grabbing) return;
|
|
2235
|
-
grabbing = false;
|
|
2236
|
-
if (!moving) return;
|
|
2237
|
-
pin.dataset.dragged = "1";
|
|
2238
|
-
setTimeout(() => delete pin.dataset.dragged, 0);
|
|
2239
|
-
const x = ev.clientX - tip.dx;
|
|
2240
|
-
const y = ev.clientY - tip.dy;
|
|
2241
|
-
const under = document.elementsFromPoint(x, y).find((n) => n !== host2);
|
|
2242
|
-
if (ev.type === "pointercancel" || x < 0 || y < 0 || x > innerWidth || y > innerHeight || under?.closest(OFF)) return render();
|
|
2243
|
-
const before = c.anchor;
|
|
2244
|
-
c.anchor = anchorAt(x, y);
|
|
2245
|
-
render();
|
|
2246
|
-
try {
|
|
2247
|
-
const { comment } = await send({ action: "move", id: c.id, anchor: c.anchor, edit: store2.get(`lab-edit:${c.id}`) || void 0 });
|
|
2248
|
-
Object.assign(c, comment);
|
|
2249
|
-
} catch {
|
|
2250
|
-
c.anchor = before;
|
|
2251
|
-
render();
|
|
2252
|
-
}
|
|
2253
|
-
};
|
|
2254
|
-
pin.addEventListener("pointermove", move);
|
|
2255
|
-
pin.addEventListener("pointerup", up);
|
|
2256
|
-
pin.addEventListener("pointercancel", up);
|
|
2257
|
-
pin.addEventListener("lostpointercapture", up);
|
|
2258
|
-
});
|
|
2259
|
-
}
|
|
2260
|
-
let openCard = null;
|
|
2261
|
-
const coarse = matchMedia("(pointer: coarse)").matches;
|
|
2262
|
-
function threadCard(c, fresh = /* @__PURE__ */ new Set(), focus = false) {
|
|
2263
|
-
const card = el2("div", { class: "card" });
|
|
2264
|
-
const body = el2("div", { class: "body" });
|
|
2265
|
-
const foot = el2("div", { class: "foot" });
|
|
2266
|
-
card.append(el2("div", { class: "handle" }), body, foot);
|
|
2267
|
-
card.addEventListener("click", (e) => e.stopPropagation());
|
|
2268
|
-
body.classList.add("msgs");
|
|
2269
|
-
const itemEl = (item) => {
|
|
2270
|
-
const box = el2("div", { class: `item msg${mine(item) && !item.session ? " mine" : ""}`, "data-id": item.id, ...agentOf(item) ? { "data-agent": agentOf(item) } : {} });
|
|
2271
|
-
box.append(nameLine(item.name, false), ...readable(item.text));
|
|
2272
|
-
stamped(box, stampOf(item, c, item === c && !c.resolved ? `#${numberOf(c)} \xB7 ` : ""));
|
|
2273
|
-
return box;
|
|
2274
|
-
};
|
|
2275
|
-
const shown2 = /* @__PURE__ */ new Set();
|
|
2276
|
-
const all = [c, ...repliesOf(c.id)];
|
|
2277
|
-
const firstNew = all.find((x) => fresh.has(x.id));
|
|
2278
|
-
for (const item of all) {
|
|
2279
|
-
if (item === firstNew && item !== c) body.append(el2("div", { class: "newline" }, "new"));
|
|
2280
|
-
body.append(itemEl(item));
|
|
2281
|
-
shown2.add(item.id);
|
|
2282
|
-
}
|
|
2283
|
-
card.sync = () => {
|
|
2284
|
-
for (const r of repliesOf(c.id)) {
|
|
2285
|
-
if (shown2.has(r.id)) continue;
|
|
2286
|
-
const items = card.querySelectorAll(".item");
|
|
2287
|
-
const added = itemEl(r);
|
|
2288
|
-
added.classList.add("fresh");
|
|
2289
|
-
items[items.length - 1].after(added);
|
|
2290
|
-
shown2.add(r.id);
|
|
2291
|
-
markSeen([r]);
|
|
2292
|
-
}
|
|
2293
|
-
};
|
|
2294
|
-
const ownKey = store2.get(`lab-edit:${c.id}`);
|
|
2295
|
-
let actions = null;
|
|
2296
|
-
if (isAdmin || ownKey) {
|
|
2297
|
-
actions = el2("div", { class: "row acts" });
|
|
2298
|
-
const resolve = el2("button", { class: "btn", type: "button" }, c.resolved ? "reopen" : "resolve");
|
|
2299
|
-
const failed = (btn) => btn.textContent = "failed, try again";
|
|
2300
|
-
resolve.addEventListener("click", async () => {
|
|
2301
|
-
try {
|
|
2302
|
-
const closing = !c.resolved;
|
|
2303
|
-
const { comment } = await send({ action: c.resolved ? "reopen" : "resolve", id: c.id, ...ownKey ? { edit: ownKey } : {} });
|
|
2304
|
-
Object.assign(c, comment);
|
|
2305
|
-
if (closing && openId === c.id) return closeFast = true, openId = null, render();
|
|
2306
|
-
render();
|
|
2307
|
-
} catch {
|
|
2308
|
-
failed(resolve);
|
|
2309
|
-
}
|
|
2310
|
-
});
|
|
2311
|
-
const del = el2("button", { class: "btn", type: "button" }, "delete");
|
|
2312
|
-
const yes = el2("button", { class: "btn danger", type: "button" }, "delete");
|
|
2313
|
-
const no = el2("button", { class: "btn", type: "button" }, "cancel");
|
|
2314
|
-
const back = () => {
|
|
2315
|
-
actions.replaceChildren(resolve, del);
|
|
2316
|
-
del.focus();
|
|
2317
|
-
};
|
|
2318
|
-
del.addEventListener("click", () => {
|
|
2319
|
-
actions.replaceChildren(el2("span", { class: "ask" }, repliesOf(c.id).length ? "delete thread?" : "delete comment?"), yes, no);
|
|
2320
|
-
no.focus();
|
|
2321
|
-
});
|
|
2322
|
-
no.addEventListener("click", back);
|
|
2323
|
-
actions.addEventListener("keydown", (e) => {
|
|
2324
|
-
if (e.key === "Escape" && yes.isConnected) {
|
|
2325
|
-
e.stopPropagation();
|
|
2326
|
-
back();
|
|
2327
|
-
}
|
|
2328
|
-
});
|
|
2329
|
-
yes.addEventListener("click", async () => {
|
|
2330
|
-
try {
|
|
2331
|
-
await send({ action: "delete", id: c.id });
|
|
2332
|
-
} catch {
|
|
2333
|
-
return failed(yes);
|
|
2334
|
-
}
|
|
2335
|
-
comments = comments.filter((x) => x.id !== c.id && x.parent !== c.id);
|
|
2336
|
-
openId = null;
|
|
2337
|
-
render();
|
|
2338
|
-
});
|
|
2339
|
-
actions.append(...isAdmin ? [resolve, del] : [resolve]);
|
|
2340
|
-
body.append(actions);
|
|
2341
|
-
}
|
|
2342
|
-
if (coarse) {
|
|
2343
|
-
const topOf = (x) => position(x.anchor || {}).top;
|
|
2344
|
-
const here = topOf(c);
|
|
2345
|
-
const fresh2 = threads().filter((x) => !isPage(x) && x.id !== c.id && unread(x).length).map((x) => [x, topOf(x)]);
|
|
2346
|
-
fresh2.sort((p, q) => (p[1] > here ? 0 : 1) - (q[1] > here ? 0 : 1) || p[1] - q[1]);
|
|
2347
|
-
const nav = el2("div", { class: "row nav" });
|
|
2348
|
-
if (fresh2.length) {
|
|
2349
|
-
const b = el2("button", { class: "btn", type: "button" }, `new \xB7 ${fresh2.length} \u203A`);
|
|
2350
|
-
b.addEventListener("pointerdown", (e) => e.preventDefault());
|
|
2351
|
-
b.addEventListener("click", () => goTo(fresh2[0][0]));
|
|
2352
|
-
nav.append(b);
|
|
2353
|
-
}
|
|
2354
|
-
if (actions) nav.append(actions);
|
|
2355
|
-
if (nav.firstChild) card.insertBefore(nav, body);
|
|
2356
|
-
}
|
|
2357
|
-
foot.append(
|
|
2358
|
-
composer({
|
|
2359
|
-
placeholder: "reply",
|
|
2360
|
-
autofocus: focus,
|
|
2361
|
-
onSubmit: async (name, text) => {
|
|
2362
|
-
const { comment } = await send({ name, text, parent: c.id });
|
|
2363
|
-
comments.push(comment);
|
|
2364
|
-
markSeen([comment]);
|
|
2365
|
-
if (c.resolved) {
|
|
2366
|
-
c.resolved = false;
|
|
2367
|
-
render();
|
|
2368
|
-
const again = openCard?.querySelector(".body");
|
|
2369
|
-
if (again) again.scrollTop = again.scrollHeight;
|
|
2370
|
-
openCard?.querySelector("textarea")?.focus({ preventScroll: true });
|
|
2371
|
-
return { keep: true };
|
|
2372
|
-
}
|
|
2373
|
-
shown2.add(comment.id);
|
|
2374
|
-
const items = card.querySelectorAll(".item");
|
|
2375
|
-
const added = itemEl(comment);
|
|
2376
|
-
added.classList.add("fresh");
|
|
2377
|
-
items[items.length - 1].after(added);
|
|
2378
|
-
body.scrollTop = body.scrollHeight;
|
|
2379
|
-
return { keep: true };
|
|
2380
|
-
}
|
|
2381
|
-
})
|
|
2382
|
-
);
|
|
2383
|
-
return card;
|
|
2384
|
-
}
|
|
2385
|
-
const showHint = () => {
|
|
2386
|
-
if (store2.get("lab-hint-seen") === "1") return;
|
|
2387
|
-
hint.hidden = false;
|
|
2388
|
-
store2.set("lab-hint-seen", "1");
|
|
2389
|
-
setTimeout(() => hint.hidden = true, 5e3);
|
|
2390
|
-
};
|
|
2391
|
-
const setOn = (value) => {
|
|
2392
|
-
on = value;
|
|
2393
|
-
if (!on) ptr.classList.remove("show");
|
|
2394
|
-
else recheck();
|
|
2395
|
-
store2.set("lab-on", on ? "1" : "0");
|
|
2396
|
-
if (on) showHint();
|
|
2397
|
-
draft = null;
|
|
2398
|
-
openId = null;
|
|
2399
|
-
render();
|
|
2400
|
-
};
|
|
2401
|
-
toggleBtn.addEventListener("click", () => setOn(!on));
|
|
2402
|
-
function setMenu(open, refocus = false) {
|
|
2403
|
-
moreMenu.hidden = !open;
|
|
2404
|
-
moreBtn.setAttribute("aria-expanded", String(open));
|
|
2405
|
-
if (open) [...moreMenu.querySelectorAll("button")].find((b) => !b.hidden && !b.disabled)?.focus({ preventScroll: true });
|
|
2406
|
-
else if (refocus) moreBtn.focus({ preventScroll: true });
|
|
2407
|
-
}
|
|
2408
|
-
moreBtn.addEventListener("click", (e) => {
|
|
2409
|
-
e.stopPropagation();
|
|
2410
|
-
setMenu(moreMenu.hidden);
|
|
2411
|
-
});
|
|
2412
|
-
moreMenu.addEventListener("click", () => setTimeout(() => setMenu(false, true), 0));
|
|
2413
|
-
addEventListener("pointerdown", (e) => {
|
|
2414
|
-
if (!moreMenu.hidden && !e.composedPath().some((n) => n === moreMenu || n === moreBtn)) setMenu(false);
|
|
2415
|
-
}, true);
|
|
2416
|
-
addEventListener("keydown", (e) => {
|
|
2417
|
-
if (e.key === "Escape" && !moreMenu.hidden) {
|
|
2418
|
-
setMenu(false, true);
|
|
2419
|
-
e.stopPropagation();
|
|
2420
|
-
}
|
|
2421
|
-
}, true);
|
|
2422
|
-
goBtn.addEventListener("click", () => setGo(!goMode));
|
|
2423
|
-
const stepNew = (dir) => {
|
|
2424
|
-
const fresh = threads().filter((c) => !isPage(c) && unread(c).length);
|
|
2425
|
-
if (!fresh.length) return;
|
|
2426
|
-
const top = (c) => position(c.anchor || {}).top;
|
|
2427
|
-
fresh.sort((a, b) => top(a) - top(b));
|
|
2428
|
-
const open = openId && threads().find((c) => c.id === openId);
|
|
2429
|
-
const here = open ? top(open) : null;
|
|
2430
|
-
const after = here == null ? -1 : fresh.findIndex((c) => top(c) > here);
|
|
2431
|
-
const at = fresh.findIndex((c) => c.id === openId);
|
|
2432
|
-
const next = at >= 0 ? (at + dir + fresh.length) % fresh.length : here == null ? dir > 0 ? 0 : fresh.length - 1 : dir > 0 ? after < 0 ? 0 : after : ((after < 0 ? fresh.length : after) - 1 + fresh.length) % fresh.length;
|
|
2433
|
-
chatOpen = false;
|
|
2434
|
-
goTo(fresh[next], !coarse);
|
|
2435
|
-
};
|
|
2436
|
-
newPrev.addEventListener("click", () => stepNew(-1));
|
|
2437
|
-
doneBtn.addEventListener("click", () => showDoneBtn.click());
|
|
2438
|
-
showDoneBtn.addEventListener("click", () => {
|
|
2439
|
-
showDone = !showDone;
|
|
2440
|
-
store2.set("lab-show-done", showDone ? "1" : "");
|
|
2441
|
-
render();
|
|
2442
|
-
});
|
|
2443
|
-
newNext.addEventListener("click", () => stepNew(1));
|
|
2444
|
-
const showAgain = () => {
|
|
2445
|
-
if (on) return;
|
|
2446
|
-
on = true;
|
|
2447
|
-
store2.set("lab-on", "1");
|
|
2448
|
-
};
|
|
2449
|
-
copyBtn.addEventListener("click", () => copy(agentLink(), copyBtn));
|
|
2450
|
-
listBtn.addEventListener("click", () => LIST_WINDOW ? (listOpen = !listOpen, listOpen && (filter = "new"), chatOpen = false, hint.hidden = true, render()) : stepNew(1));
|
|
2451
|
-
listEl.querySelector(".x").addEventListener("click", () => slideAway(listEl, () => (listOpen = false, render())));
|
|
2452
|
-
chatBtn.addEventListener("click", () => {
|
|
2453
|
-
chatOpen = !chatOpen;
|
|
2454
|
-
listOpen = false;
|
|
2455
|
-
if (chatOpen && !coarse) {
|
|
2456
|
-
openId = null;
|
|
2457
|
-
if (draft && !/** @type {HTMLTextAreaElement | null} */
|
|
2458
|
-
root.querySelector(".float textarea")?.value.trim()) draft = null;
|
|
2459
|
-
}
|
|
2460
|
-
hint.hidden = true;
|
|
2461
|
-
render();
|
|
2462
|
-
if (chatOpen && !coarse) chatEl.querySelector(".chat textarea")?.focus({ preventScroll: true });
|
|
2463
|
-
});
|
|
2464
|
-
let closingClick = false;
|
|
2465
|
-
document.addEventListener("pointerdown", (e) => {
|
|
2466
|
-
closingClick = false;
|
|
2467
|
-
if (coarse || !chatOpen || e.button !== 0) return;
|
|
2468
|
-
const path = e.composedPath();
|
|
2469
|
-
if (path.includes(chatEl) || path.includes(chatBtn)) return;
|
|
2470
|
-
chatOpen = false;
|
|
2471
|
-
if (path.includes(host2)) return void addEventListener("click", () => render(), { once: true });
|
|
2472
|
-
closingClick = true;
|
|
2473
|
-
render();
|
|
2474
|
-
}, true);
|
|
2475
|
-
addEventListener("click", (e) => {
|
|
2476
|
-
if (!closingClick) return;
|
|
2477
|
-
closingClick = false;
|
|
2478
|
-
e.preventDefault();
|
|
2479
|
-
e.stopImmediatePropagation();
|
|
2480
|
-
}, true);
|
|
2481
|
-
for (
|
|
2482
|
-
const b of
|
|
2483
|
-
/** @type {NodeListOf<HTMLElement>} */
|
|
2484
|
-
listEl.querySelectorAll("[data-f]")
|
|
2485
|
-
) b.addEventListener("click", () => (filter = b.dataset.f, drawList()));
|
|
2486
|
-
holdBtn.addEventListener("click", () => (store2.set("lab-hold", drafting() ? "" : "1"), drawList()));
|
|
2487
|
-
sendBtn.addEventListener("click", async () => {
|
|
2488
|
-
const list = held();
|
|
2489
|
-
for (let i = 0; i < list.length; i++) {
|
|
2490
|
-
try {
|
|
2491
|
-
const { comment, edit } = await send(list[i]);
|
|
2492
|
-
if (edit) store2.set(`lab-edit:${comment.id}`, edit);
|
|
2493
|
-
comments.push(comment);
|
|
2494
|
-
markSeen([comment]);
|
|
2495
|
-
store2.set(heldKey(), JSON.stringify(list.slice(i + 1)));
|
|
2496
|
-
} catch {
|
|
2497
|
-
sendBtn.textContent = "send failed, try again";
|
|
2498
|
-
return;
|
|
2499
|
-
}
|
|
2500
|
-
}
|
|
2501
|
-
render();
|
|
2502
|
-
});
|
|
2503
|
-
const typing = (e) => e.composedPath().some((n) => n instanceof HTMLElement && (n.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(n.tagName)));
|
|
2504
|
-
document.addEventListener("keydown", (e) => {
|
|
2505
|
-
if (gone) return;
|
|
2506
|
-
const inOtherWidget = document.activeElement?.localName.includes("-") && document.activeElement !== host2;
|
|
2507
|
-
if ((e.key === "m" || e.key === "M" || e.code === "KeyM") && !e.metaKey && !e.ctrlKey && !e.altKey && !e.repeat && !typing(e) && !inOtherWidget) {
|
|
2508
|
-
e.preventDefault();
|
|
2509
|
-
setOn(!on);
|
|
2510
|
-
return;
|
|
2511
|
-
}
|
|
2512
|
-
if (on && (e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey && (/^z$/i.test(e.key || "") || !/^[a-z]$/i.test(e.key || "") && e.code === "KeyZ") && !typing(e) && !inOtherWidget && placed.length) {
|
|
2513
|
-
e.preventDefault();
|
|
2514
|
-
return void undoLast();
|
|
2515
|
-
}
|
|
2516
|
-
if (on && e.ctrlKey && !e.metaKey && !e.altKey && e.code === "KeyD" && !(typing(e) && !e.composedPath().includes(host2))) {
|
|
2517
|
-
e.preventDefault();
|
|
2518
|
-
const typed2 = (
|
|
2519
|
-
/** @type {HTMLTextAreaElement | null} */
|
|
2520
|
-
root.querySelector(".card textarea, .float textarea")
|
|
2521
|
-
);
|
|
2522
|
-
if (typed2?.value.trim()) return typed2.closest(".card, .float")?.animate([{ transform: "none" }, { transform: "translateX(-6px)" }, { transform: "translateX(6px)" }, { transform: "none" }], { duration: 260 });
|
|
2523
|
-
return stepNew(e.shiftKey ? -1 : 1);
|
|
2524
|
-
}
|
|
2525
|
-
if (on && /^(Digit|Numpad)[123]$/.test(e.code || "") && !e.metaKey && !e.ctrlKey && !e.altKey && !e.repeat && !typing(e) && !inOtherWidget) {
|
|
2526
|
-
e.preventDefault();
|
|
2527
|
-
if (e.code.endsWith("3")) setCursor(true);
|
|
2528
|
-
else setGo(e.code.endsWith("2"));
|
|
2529
|
-
return;
|
|
2530
|
-
}
|
|
2531
|
-
const letter = /^[a-z]$/i.test(e.key || "") ? e.key.toLowerCase() : /^Key[A-Z]$/.test(e.code || "") ? e.code.slice(3).toLowerCase() : "";
|
|
2532
|
-
if (on && !typing(e) && !inOtherWidget && !e.metaKey && !e.ctrlKey && !e.altKey && !e.repeat && /^[cwred]$/.test(letter)) {
|
|
2533
|
-
const k = letter;
|
|
2534
|
-
e.preventDefault();
|
|
2535
|
-
if (k === "c") return chatBtn.click();
|
|
2536
|
-
if (k === "w") return stepNew(e.shiftKey ? -1 : 1);
|
|
2537
|
-
if (k === "d") return showDoneBtn.click();
|
|
2538
|
-
if (k === "r" && openId) root.querySelector(".card textarea")?.focus({ preventScroll: true });
|
|
2539
|
-
else if (k === "e" && openId && isAdmin) [.../** @type {NodeListOf<HTMLElement>} */
|
|
2540
|
-
root.querySelectorAll(".card .btn")].find((b) => /^(resolve|reopen)$/.test(b.textContent))?.click();
|
|
2541
|
-
return;
|
|
2542
|
-
}
|
|
2543
|
-
if (e.key === "Escape" && (draft || openId)) {
|
|
2544
|
-
draft = null;
|
|
2545
|
-
openId = null;
|
|
2546
|
-
render();
|
|
2547
|
-
} else if (e.key === "Escape" && (chatOpen || listOpen)) {
|
|
2548
|
-
if (chatOpen) chatOpen = false;
|
|
2549
|
-
else listOpen = false;
|
|
2550
|
-
render();
|
|
2551
|
-
}
|
|
2552
|
-
});
|
|
2553
|
-
const INTERACTIVE = 'a, button, input, textarea, select, label, summary, video[controls], audio, iframe, [contenteditable], [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="option"], [role="checkbox"], [role="switch"], [tabindex]:not([tabindex="-1"]), [onclick]';
|
|
2554
|
-
const OFF = "[data-uncommentable]";
|
|
2555
|
-
let drag = null;
|
|
2556
|
-
let afterDrag = false;
|
|
2557
|
-
let liveZone = null;
|
|
2558
|
-
let zoneFrame = 0;
|
|
2559
|
-
const paintZone = () => {
|
|
2560
|
-
zoneFrame = 0;
|
|
2561
|
-
if (!drag?.active || !liveZone) return;
|
|
2562
|
-
const x = Math.min(drag.x0, drag.x1) + scrollX;
|
|
2563
|
-
const y = Math.min(drag.y0, drag.y1) + scrollY;
|
|
2564
|
-
liveZone.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
2565
|
-
liveZone.style.width = `${Math.abs(drag.x1 - drag.x0)}px`;
|
|
2566
|
-
liveZone.style.height = `${Math.abs(drag.y1 - drag.y0)}px`;
|
|
2567
|
-
};
|
|
2568
|
-
const draftHasText = () => Boolean(draft) && [.../** @type {NodeListOf<HTMLTextAreaElement>} */
|
|
2569
|
-
root.querySelectorAll(".float textarea")].some((t) => t.value.trim());
|
|
2570
|
-
function startDrag(e) {
|
|
2571
|
-
if (!on && !e.altKey || cursorMode && !e.altKey || draftHasText() || e.button !== 0 || e.pointerType === "touch" || e.metaKey || e.ctrlKey || e.shiftKey) return;
|
|
2572
|
-
if (e.composedPath().includes(host2)) return;
|
|
2573
|
-
if (!e.altKey && e.target instanceof Element && e.target.closest(INTERACTIVE)) return;
|
|
2574
|
-
if (e.target instanceof Element && e.target.closest(OFF)) return;
|
|
2575
|
-
drag = { x0: e.clientX, y0: e.clientY, x1: e.clientX, y1: e.clientY, active: false };
|
|
2576
|
-
}
|
|
2577
|
-
document.addEventListener(
|
|
2578
|
-
"pointerdown",
|
|
2579
|
-
(e) => {
|
|
2580
|
-
if (e.altKey) return;
|
|
2581
|
-
if (!on && !e.altKey || cursorMode && !e.altKey || draftHasText() || e.button !== 0 || e.pointerType === "touch" || e.metaKey || e.ctrlKey || e.shiftKey) return;
|
|
2582
|
-
if (e.composedPath().includes(host2)) return;
|
|
2583
|
-
if (!e.altKey && e.target instanceof Element && e.target.closest(INTERACTIVE)) return;
|
|
2584
|
-
if (e.target instanceof Element && e.target.closest(OFF)) return;
|
|
2585
|
-
drag = { x0: e.clientX, y0: e.clientY, x1: e.clientX, y1: e.clientY, active: false };
|
|
2586
|
-
},
|
|
2587
|
-
true
|
|
2588
|
-
);
|
|
2589
|
-
document.addEventListener(
|
|
2590
|
-
"pointermove",
|
|
2591
|
-
(e) => {
|
|
2592
|
-
if (!drag) return;
|
|
2593
|
-
drag.x1 = e.clientX;
|
|
2594
|
-
drag.y1 = e.clientY;
|
|
2595
|
-
if (!drag.active && Math.hypot(drag.x1 - drag.x0, drag.y1 - drag.y0) > 8) {
|
|
2596
|
-
drag.active = true;
|
|
2597
|
-
getSelection?.()?.removeAllRanges();
|
|
2598
|
-
document.documentElement.classList.add("lab-dragging");
|
|
2599
|
-
liveZone = zoneEl("draft live");
|
|
2600
|
-
layer2.append(liveZone);
|
|
2601
|
-
}
|
|
2602
|
-
if (!drag.active) return;
|
|
2603
|
-
e.preventDefault();
|
|
2604
|
-
zoneFrame ||= requestAnimationFrame(paintZone);
|
|
2605
|
-
},
|
|
2606
|
-
true
|
|
2607
|
-
);
|
|
2608
|
-
const endDrag = (e) => {
|
|
2609
|
-
if (!drag) return;
|
|
2610
|
-
const d = drag;
|
|
2611
|
-
drag = null;
|
|
2612
|
-
document.documentElement.classList.remove("lab-dragging");
|
|
2613
|
-
cancelAnimationFrame(zoneFrame);
|
|
2614
|
-
zoneFrame = 0;
|
|
2615
|
-
liveZone?.remove();
|
|
2616
|
-
liveZone = null;
|
|
2617
|
-
if (!d.active || e.type === "pointercancel") return;
|
|
2618
|
-
afterDrag = true;
|
|
2619
|
-
setTimeout(() => afterDrag = false, 0);
|
|
2620
|
-
getSelection?.()?.removeAllRanges();
|
|
2621
|
-
for (const [a, b] of [["x0", "x1"], ["y0", "y1"]]) {
|
|
2622
|
-
if (Math.abs(d[b] - d[a]) >= 12) continue;
|
|
2623
|
-
const mid = (d[a] + d[b]) / 2;
|
|
2624
|
-
d[a] = mid - 6;
|
|
2625
|
-
d[b] = mid + 6;
|
|
2626
|
-
}
|
|
2627
|
-
showAgain();
|
|
2628
|
-
openId = null;
|
|
2629
|
-
begin(zoneAnchor(d));
|
|
2630
|
-
};
|
|
2631
|
-
document.addEventListener("pointerup", endDrag, true);
|
|
2632
|
-
document.addEventListener("pointercancel", endDrag, true);
|
|
2633
|
-
document.addEventListener(
|
|
2634
|
-
"dragstart",
|
|
2635
|
-
(e) => {
|
|
2636
|
-
const media = on && e.target instanceof Element && e.target.closest("img, video") && !e.composedPath().includes(host2);
|
|
2637
|
-
if (drag || media) e.preventDefault();
|
|
2638
|
-
},
|
|
2639
|
-
true
|
|
2640
|
-
);
|
|
2641
|
-
document.addEventListener(
|
|
2642
|
-
"click",
|
|
2643
|
-
(e) => {
|
|
2644
|
-
if (!afterDrag) return;
|
|
2645
|
-
e.preventDefault();
|
|
2646
|
-
e.stopPropagation();
|
|
2647
|
-
},
|
|
2648
|
-
true
|
|
2649
|
-
);
|
|
2650
|
-
const optionPress = (e) => e.altKey && !e.metaKey && !e.ctrlKey && e.button === 0 && !e.composedPath().includes(host2) && !(e.target instanceof Element && e.target.closest(OFF));
|
|
2651
|
-
for (const type of ["pointerdown", "mousedown", "pointerup", "mouseup"]) {
|
|
2652
|
-
addEventListener(type, (e) => {
|
|
2653
|
-
if (!optionPress(e)) return;
|
|
2654
|
-
e.preventDefault();
|
|
2655
|
-
e.stopImmediatePropagation();
|
|
2656
|
-
if (type === "pointerdown") startDrag(e);
|
|
2657
|
-
if (type === "pointerup") endDrag(e);
|
|
2658
|
-
}, true);
|
|
2659
|
-
}
|
|
2660
|
-
addEventListener("click", (e) => {
|
|
2661
|
-
if (!optionPress(e)) return;
|
|
2662
|
-
e.preventDefault();
|
|
2663
|
-
e.stopImmediatePropagation();
|
|
2664
|
-
if (!afterDrag) onPageClick(e);
|
|
2665
|
-
}, true);
|
|
2666
|
-
document.addEventListener("click", (e) => onPageClick(e));
|
|
2667
|
-
let lastTouch = 0;
|
|
2668
|
-
let pinnedByHold = false;
|
|
2669
|
-
const selChip = (
|
|
2670
|
-
/** @type {HTMLElement} */
|
|
2671
|
-
root.querySelector(".sel-chip")
|
|
2672
|
-
);
|
|
2673
|
-
const scrim = (
|
|
2674
|
-
/** @type {HTMLElement} */
|
|
2675
|
-
root.querySelector(".scrim")
|
|
2676
|
-
);
|
|
2677
|
-
const openSheet = () => root.querySelector(".card:not(.out), .float:not(.out)") || (listOpen ? listEl : chatOpen ? chatEl : null);
|
|
2678
|
-
const closeAll = () => {
|
|
2679
|
-
draft = null;
|
|
2680
|
-
openId = null;
|
|
2681
|
-
listOpen = false;
|
|
2682
|
-
chatOpen = false;
|
|
2683
|
-
render();
|
|
2684
|
-
};
|
|
2685
|
-
const closeOrNudge = () => {
|
|
2686
|
-
const node = openSheet();
|
|
2687
|
-
if (![...root.querySelectorAll("textarea")].some((t) => t.value.trim() && !chatEl.contains(t))) return slideAway(node, closeAll);
|
|
2688
|
-
node?.animate?.([{ transform: "none" }, { transform: "translateY(12px)" }, { transform: "none" }], { duration: 260, easing: "ease-out" });
|
|
2689
|
-
};
|
|
2690
|
-
let sheetDraggedAt = -1e9;
|
|
2691
|
-
scrim.addEventListener("click", () => performance.now() - sheetDraggedAt > 300 && closeOrNudge());
|
|
2692
|
-
scrim.addEventListener("touchmove", (e) => e.preventDefault(), { passive: false });
|
|
2693
|
-
function slideAway(node, close, ms = 0) {
|
|
2694
|
-
if (!coarse || !node || still.matches) return close();
|
|
2695
|
-
if (!host2.hasAttribute("data-kb")) root.activeElement?.blur();
|
|
2696
|
-
node.style.pointerEvents = "none";
|
|
2697
|
-
node.style.transition = ms ? `transform ${ms}ms cubic-bezier(.2, .6, .4, 1)` : "transform .22s cubic-bezier(.4, 0, 1, 1)";
|
|
2698
|
-
scrim.style.transition = `opacity ${ms || 220}ms`;
|
|
2699
|
-
node.style.transform = "translateY(100%)";
|
|
2700
|
-
scrim.style.opacity = "0";
|
|
2701
|
-
bar.style.transition = `transform ${ms || 220}ms cubic-bezier(.2, .6, .4, 1), opacity ${ms || 220}ms`;
|
|
2702
|
-
host2.style.setProperty("--lab-p", "1");
|
|
2703
|
-
setTimeout(() => {
|
|
2704
|
-
root.activeElement?.blur();
|
|
2705
|
-
close();
|
|
2706
|
-
node.style.pointerEvents = "";
|
|
2707
|
-
node.style.transform = node.style.transition = scrim.style.opacity = scrim.style.transition = bar.style.transition = "";
|
|
2708
|
-
host2.style.removeProperty("--lab-p");
|
|
2709
|
-
}, ms || 220);
|
|
2710
|
-
}
|
|
2711
|
-
const grabArea = (t) => Boolean(t.closest?.(".handle, .tabs"));
|
|
2712
|
-
const scrollerIn = (e, node) => e.composedPath().find((n) => n instanceof HTMLElement && node.contains(n) && (n.localName === "textarea" || /auto|scroll/.test(getComputedStyle(n).overflowY)));
|
|
2713
|
-
const SPRING = "cubic-bezier(.32,.72,0,1)";
|
|
2714
|
-
let backWatcher = null;
|
|
2715
|
-
function backCloses() {
|
|
2716
|
-
const open = matchMedia("(pointer: coarse)").matches && host2.hasAttribute("data-sheet");
|
|
2717
|
-
if (!open && backWatcher) {
|
|
2718
|
-
const w = backWatcher;
|
|
2719
|
-
backWatcher = null;
|
|
2720
|
-
w.destroy();
|
|
2721
|
-
}
|
|
2722
|
-
if (open && !backWatcher && "CloseWatcher" in window) {
|
|
2723
|
-
try {
|
|
2724
|
-
const w = new /** @type {any} */
|
|
2725
|
-
window.CloseWatcher();
|
|
2726
|
-
w.onclose = () => {
|
|
2727
|
-
if (backWatcher === w) backWatcher = null;
|
|
2728
|
-
closeOrNudge();
|
|
2729
|
-
backCloses();
|
|
2730
|
-
};
|
|
2731
|
-
backWatcher = w;
|
|
2732
|
-
} catch {
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
}
|
|
2736
|
-
let dbg = null;
|
|
2737
|
-
function swipeDown(node, close, grows = false) {
|
|
2738
|
-
if (!coarse) return;
|
|
2739
|
-
let raw = 0;
|
|
2740
|
-
let scrolledAt = -1e9;
|
|
2741
|
-
let releasedAt = -1e9;
|
|
2742
|
-
node.addEventListener("scroll", () => scrolledAt = performance.now(), { capture: true, passive: true });
|
|
2743
|
-
node.addEventListener("click", (e) => {
|
|
2744
|
-
if (performance.now() - releasedAt < 200) {
|
|
2745
|
-
e.preventDefault();
|
|
2746
|
-
e.stopPropagation();
|
|
2747
|
-
}
|
|
2748
|
-
}, true);
|
|
2749
|
-
node.addEventListener("focusin", (e) => {
|
|
2750
|
-
if (performance.now() - releasedAt < 200 && e.target.localName === "textarea") e.target.blur();
|
|
2751
|
-
});
|
|
2752
|
-
let x0 = 0;
|
|
2753
|
-
let y0 = 0;
|
|
2754
|
-
let dy = 0;
|
|
2755
|
-
let v = 0;
|
|
2756
|
-
let last = null;
|
|
2757
|
-
let mode = null;
|
|
2758
|
-
let box = null;
|
|
2759
|
-
let fromScrim = false;
|
|
2760
|
-
const onStart = (e) => {
|
|
2761
|
-
fromScrim = e.currentTarget === scrim;
|
|
2762
|
-
if (fromScrim && openSheet() !== node) return void (mode = "off");
|
|
2763
|
-
const t = e.touches[0];
|
|
2764
|
-
x0 = t.clientX;
|
|
2765
|
-
y0 = t.clientY;
|
|
2766
|
-
dy = v = raw = 0;
|
|
2767
|
-
last = { y: y0, at: e.timeStamp };
|
|
2768
|
-
box = fromScrim ? null : scrollerIn(e, node);
|
|
2769
|
-
mode = e.touches.length > 1 || box?.localName === "textarea" ? "off" : null;
|
|
2770
|
-
};
|
|
2771
|
-
node.addEventListener("touchstart", onStart, { passive: true });
|
|
2772
|
-
scrim.addEventListener("touchstart", onStart, { passive: true });
|
|
2773
|
-
const onMove = (e) => {
|
|
2774
|
-
if (fromScrim !== (e.currentTarget === scrim)) return;
|
|
2775
|
-
const t = e.touches[0];
|
|
2776
|
-
if (mode === "off" && box && box.localName !== "textarea" && e.touches.length === 1 && e.cancelable && box.scrollTop <= 0 && t.clientY > last.y + 1) {
|
|
2777
|
-
mode = "drag";
|
|
2778
|
-
y0 = t.clientY;
|
|
2779
|
-
v = 0;
|
|
2780
|
-
last = { y: t.clientY, at: e.timeStamp };
|
|
2781
|
-
}
|
|
2782
|
-
if (mode === "off") return void (last = { y: t.clientY, at: e.timeStamp });
|
|
2783
|
-
if (mode === "hold") return e.preventDefault();
|
|
2784
|
-
if (!mode) {
|
|
2785
|
-
const down = t.clientY - y0;
|
|
2786
|
-
const across = t.clientX - x0;
|
|
2787
|
-
if (!down && !across) return;
|
|
2788
|
-
const sideways = Math.abs(across) > Math.abs(down);
|
|
2789
|
-
const nearTop = !sideways && down > 0 && y0 - node.getBoundingClientRect().top < node.offsetHeight * 0.25;
|
|
2790
|
-
if (fromScrim) mode = sideways ? "hold" : "drag";
|
|
2791
|
-
else if (grabArea(e.target)) mode = sideways && e.target.closest(".tabs") ? "off" : "drag";
|
|
2792
|
-
else if (nearTop && box?.localName !== "textarea") mode = "drag";
|
|
2793
|
-
else if (box) mode = !sideways && down > 0 && box.scrollTop <= 0 && performance.now() - scrolledAt > 100 ? "drag" : "off";
|
|
2794
|
-
else mode = sideways ? "hold" : "drag";
|
|
2795
|
-
dbg?.(`touch ${String(e.target.className || e.target.localName).slice(0, 20)} at ${Math.round(y0 - node.getBoundingClientRect().top)}/${node.offsetHeight} down${Math.round(down)} \u2192 ${mode}${e.cancelable ? "" : " (not cancelable)"}${box ? ` box${Math.round(box.scrollTop)}` : ""}`);
|
|
2796
|
-
if (mode === "off") return;
|
|
2797
|
-
if (mode === "hold") return e.preventDefault();
|
|
2798
|
-
}
|
|
2799
|
-
e.preventDefault();
|
|
2800
|
-
raw = t.clientY - y0;
|
|
2801
|
-
const size = node.offsetHeight || 400;
|
|
2802
|
-
dy = raw >= 0 ? raw : -(1 - 1 / (-raw * 0.55 / size + 1)) * size;
|
|
2803
|
-
if (e.timeStamp > last.at) v = 0.8 * ((t.clientY - last.y) / (e.timeStamp - last.at)) + 0.2 * v;
|
|
2804
|
-
last = { y: t.clientY, at: e.timeStamp };
|
|
2805
|
-
node.style.transition = scrim.style.transition = "none";
|
|
2806
|
-
node.style.transform = `translateY(${dy}px)`;
|
|
2807
|
-
scrim.style.opacity = String(Math.min(1, Math.max(0, 1 - dy / 320)));
|
|
2808
|
-
bar.style.transition = "none";
|
|
2809
|
-
host2.style.setProperty("--lab-p", String(Math.min(1, Math.max(0, dy / (node.offsetHeight || 400)))));
|
|
2810
|
-
};
|
|
2811
|
-
node.addEventListener("touchmove", onMove, { passive: false });
|
|
2812
|
-
scrim.addEventListener("touchmove", onMove, { passive: false });
|
|
2813
|
-
const end = (e) => {
|
|
2814
|
-
if (fromScrim !== (e.currentTarget === scrim)) return;
|
|
2815
|
-
const was = mode;
|
|
2816
|
-
mode = null;
|
|
2817
|
-
if (was === "drag") sheetDraggedAt = performance.now();
|
|
2818
|
-
if (was !== "drag") return;
|
|
2819
|
-
releasedAt = performance.now();
|
|
2820
|
-
if (e.timeStamp - last.at > 80) v = 0;
|
|
2821
|
-
const h = node.offsetHeight || innerHeight;
|
|
2822
|
-
const settle = () => {
|
|
2823
|
-
node.style.transition = `transform 380ms ${SPRING}, height 380ms ${SPRING}`;
|
|
2824
|
-
scrim.style.transition = "opacity 300ms";
|
|
2825
|
-
node.style.transform = scrim.style.opacity = "";
|
|
2826
|
-
bar.style.transition = "";
|
|
2827
|
-
host2.style.removeProperty("--lab-p");
|
|
2828
|
-
setTimeout(() => node.style.transition = scrim.style.transition = "", 400);
|
|
2829
|
-
};
|
|
2830
|
-
if (grows && !node.classList.contains("full") && (raw < -40 || v < -0.4)) return node.classList.add("full"), node.classList.contains("card") && (cardFull = true), settle();
|
|
2831
|
-
if (grows && node.classList.contains("full") && v < 1.2 && (raw > 60 || v > 0.4)) return node.classList.remove("full"), node.classList.contains("card") && (cardFull = false), settle();
|
|
2832
|
-
const rest = dy + Math.max(0, v) * 499;
|
|
2833
|
-
dbg?.(`let go: moved ${Math.round(dy)} speed ${v.toFixed(2)} rest ${Math.round(rest)} of half ${Math.round(h / 2)} \u2192 ${v > -0.1 && rest > h / 2 ? "close" : "stay"}`);
|
|
2834
|
-
if (v > -0.1 && rest > h / 2) return slideAway(node, close, Math.min(320, Math.max(140, (h - dy) / Math.max(v, 1.2))));
|
|
2835
|
-
node.style.transition = `transform 380ms ${SPRING}`;
|
|
2836
|
-
scrim.style.transition = "opacity 300ms";
|
|
2837
|
-
node.style.transform = scrim.style.opacity = "";
|
|
2838
|
-
bar.style.transition = "";
|
|
2839
|
-
host2.style.removeProperty("--lab-p");
|
|
2840
|
-
setTimeout(() => node.style.transition = scrim.style.transition = "", 400);
|
|
2841
|
-
};
|
|
2842
|
-
node.addEventListener("touchend", end);
|
|
2843
|
-
scrim.addEventListener("touchend", end);
|
|
2844
|
-
scrim.addEventListener("touchcancel", end);
|
|
2845
|
-
node.addEventListener("touchcancel", end);
|
|
2846
|
-
}
|
|
2847
|
-
const vv = window.visualViewport;
|
|
2848
|
-
if (coarse && vv) {
|
|
2849
|
-
const probe = el2("i", { style: "position:fixed;top:0;bottom:0;left:0;width:0;visibility:hidden;pointer-events:none" });
|
|
2850
|
-
const strip = el2("i", { style: "position:absolute;left:0;width:100vw;display:none;background:var(--_bg);z-index:3;pointer-events:none" });
|
|
2851
|
-
root.append(probe, strip);
|
|
2852
|
-
let fitted = "";
|
|
2853
|
-
const fit = () => {
|
|
2854
|
-
const zoomed = Math.abs(vv.scale - 1) > 0.01;
|
|
2855
|
-
const r = probe.getBoundingClientRect();
|
|
2856
|
-
const field = (
|
|
2857
|
-
/** @type {HTMLElement | null} */
|
|
2858
|
-
root.activeElement || document.activeElement
|
|
2859
|
-
);
|
|
2860
|
-
const typing2 = /^(textarea|input|select)$/.test(field?.localName || "") || Boolean(field?.isContentEditable);
|
|
2861
|
-
const top = zoomed || !typing2 ? 0 : vv.offsetTop;
|
|
2862
|
-
const seen2 = top + vv.height;
|
|
2863
|
-
const kb = zoomed ? 0 : Math.max(0, Math.round(r.bottom - seen2));
|
|
2864
|
-
const gap = zoomed ? 0 : Math.max(0, Math.round(seen2 - r.bottom));
|
|
2865
|
-
const vh = zoomed ? 0 : Math.round(vv.height);
|
|
2866
|
-
const sheet = host2.hasAttribute("data-sheet");
|
|
2867
|
-
const key = `${kb} ${vh} ${gap} ${sheet} ${scrollY} ${Math.round(top)}`;
|
|
2868
|
-
if (key === fitted) {
|
|
2869
|
-
const open2 = sheet ? openSheet() : null;
|
|
2870
|
-
if (open2?.offsetHeight && !open2.style.transform) Object.assign(fit, { sheet: open2, top: open2.getBoundingClientRect().top });
|
|
2871
|
-
return;
|
|
2872
|
-
}
|
|
2873
|
-
fitted = key;
|
|
2874
|
-
host2.style.setProperty("--lab-kb", `${kb}px`);
|
|
2875
|
-
host2.style.setProperty("--lab-top", `${Math.round(top)}px`);
|
|
2876
|
-
if (vh) host2.style.setProperty("--lab-vh", `${vh}px`);
|
|
2877
|
-
else host2.style.removeProperty("--lab-vh");
|
|
2878
|
-
host2.toggleAttribute("data-kb", kb > 60);
|
|
2879
|
-
strip.style.display = sheet && gap ? "block" : "none";
|
|
2880
|
-
strip.style.top = `${Math.round(scrollY + r.bottom)}px`;
|
|
2881
|
-
strip.style.height = `${gap}px`;
|
|
2882
|
-
const open = sheet ? openSheet() : null;
|
|
2883
|
-
const slid = (n) => {
|
|
2884
|
-
try {
|
|
2885
|
-
return new DOMMatrixReadOnly(getComputedStyle(n).transform).m42 || 0;
|
|
2886
|
-
} catch {
|
|
2887
|
-
return 0;
|
|
2888
|
-
}
|
|
2889
|
-
};
|
|
2890
|
-
const keyboardMoved = Math.abs((fit.vh || vh) - vh) > 60 || fit.kbUp !== kb > 60;
|
|
2891
|
-
const sliding = open && open === fit.sheet && keyboardMoved && !open.style.transform && !still.matches;
|
|
2892
|
-
if (sliding) {
|
|
2893
|
-
open.style.transition = "none";
|
|
2894
|
-
void open.offsetHeight;
|
|
2895
|
-
}
|
|
2896
|
-
const at = open ? open.getBoundingClientRect().top - slid(open) : null;
|
|
2897
|
-
if (sliding && Math.abs(fit.top - at) <= 8) open.style.transition = "";
|
|
2898
|
-
if (sliding && Math.abs(fit.top - at) > 8) {
|
|
2899
|
-
open.style.transform = `translateY(${fit.top - at}px)`;
|
|
2900
|
-
void open.offsetHeight;
|
|
2901
|
-
open.style.transition = `transform 340ms ${SPRING}`;
|
|
2902
|
-
open.style.transform = "";
|
|
2903
|
-
clearTimeout(fit.done);
|
|
2904
|
-
fit.done = setTimeout(() => !open.style.transform && (open.style.transition = ""), 360);
|
|
2905
|
-
}
|
|
2906
|
-
Object.assign(fit, { vh, kbUp: kb > 60 }, open?.offsetHeight ? { sheet: open, top: at } : { sheet: null });
|
|
2907
|
-
};
|
|
2908
|
-
refit = fit;
|
|
2909
|
-
root.addEventListener("focusin", () => setTimeout(fit, 50));
|
|
2910
|
-
root.addEventListener("focusout", () => setTimeout(fit, 50));
|
|
2911
|
-
vv.addEventListener("resize", fit);
|
|
2912
|
-
vv.addEventListener("scroll", fit);
|
|
2913
|
-
fit();
|
|
2914
|
-
if (globalThis.__LAB_DEBUG__ !== false && /[?&]kbdebug\b/.test(location.search)) {
|
|
2915
|
-
let lines = [];
|
|
2916
|
-
let t0 = performance.now();
|
|
2917
|
-
let sendTimer = 0;
|
|
2918
|
-
const row = (what) => {
|
|
2919
|
-
const open = openSheet();
|
|
2920
|
-
const r = open?.getBoundingClientRect();
|
|
2921
|
-
lines.push(`${Math.round(performance.now() - t0)} ${what} h${Math.round(vv.height)} top${Math.round(vv.offsetTop)} in${innerHeight} kb${host2.hasAttribute("data-kb") ? 1 : 0}` + (r ? ` sheet${Math.round(r.top)}/${Math.round(r.height)}${open.getAnimations().length ? " anim" : ""}` : "") + // What is moving anywhere (the page, the pins, the dimming): for a flicker that isn't the keyboard.
|
|
2922
|
-
` [${[...document.getAnimations(), ...root.getAnimations()].map((a) => (
|
|
2923
|
-
/** @type {any} */
|
|
2924
|
-
a.animationName || /** @type {any} */
|
|
2925
|
-
a.transitionProperty || "js"
|
|
2926
|
-
)).slice(0, 6).join(",")}] scrim${getComputedStyle(scrim).opacity.slice(0, 4)} scroll${Math.round(scrollY)}`);
|
|
2927
|
-
};
|
|
2928
|
-
const watch = (what) => {
|
|
2929
|
-
row(what);
|
|
2930
|
-
const end = performance.now() + 1500;
|
|
2931
|
-
let prev = "";
|
|
2932
|
-
const f = () => {
|
|
2933
|
-
const before = lines.length;
|
|
2934
|
-
row("f");
|
|
2935
|
-
const last = lines[lines.length - 1].replace(/^\d+ f /, "");
|
|
2936
|
-
if (last === prev) lines.length = before;
|
|
2937
|
-
prev = last;
|
|
2938
|
-
if (performance.now() < end) requestAnimationFrame(f);
|
|
2939
|
-
};
|
|
2940
|
-
requestAnimationFrame(f);
|
|
2941
|
-
};
|
|
2942
|
-
root.addEventListener("focusin", () => (t0 = performance.now(), watch("focus")));
|
|
2943
|
-
const sendSoon = () => {
|
|
2944
|
-
clearTimeout(sendTimer);
|
|
2945
|
-
sendTimer = setTimeout(async () => {
|
|
2946
|
-
const text = lines.join("\n");
|
|
2947
|
-
lines = [];
|
|
2948
|
-
for (let i = 0; i < text.length; i += 1900) {
|
|
2949
|
-
await send({ name: "kb-log", text: text.slice(i, i + 1900), anchor: { kind: "page", selector: "body", x: 0, y: 0, docX: 0, docY: 0, width: innerWidth } }).catch(() => {
|
|
2950
|
-
});
|
|
2951
|
-
}
|
|
2952
|
-
}, 2e3);
|
|
2953
|
-
};
|
|
2954
|
-
root.addEventListener("focusout", () => {
|
|
2955
|
-
lines.push("--- let go");
|
|
2956
|
-
t0 = performance.now();
|
|
2957
|
-
watch("blur");
|
|
2958
|
-
sendSoon();
|
|
2959
|
-
});
|
|
2960
|
-
dbg = (line) => {
|
|
2961
|
-
lines.push(`${Math.round(performance.now() - t0)} ${line}`);
|
|
2962
|
-
sendSoon();
|
|
2963
|
-
};
|
|
2964
|
-
vv.addEventListener("resize", () => {
|
|
2965
|
-
watch("resize");
|
|
2966
|
-
if (lines.length > 1) sendSoon();
|
|
2967
|
-
});
|
|
2968
|
-
}
|
|
2969
|
-
}
|
|
2970
|
-
const msgsEl = $(".msgs", chatEl);
|
|
2971
|
-
let stick = true;
|
|
2972
|
-
msgsEl.addEventListener("scroll", () => stick = msgsEl.scrollHeight - msgsEl.scrollTop - msgsEl.clientHeight < 48, { passive: true });
|
|
2973
|
-
if ("ResizeObserver" in window) new ResizeObserver(() => stick && (msgsEl.scrollTop = msgsEl.scrollHeight)).observe(msgsEl);
|
|
2974
|
-
swipeDown(listEl, () => (listOpen = false, render()));
|
|
2975
|
-
swipeDown(chatEl, () => (chatOpen = false, render()), true);
|
|
2976
|
-
let press = null;
|
|
2977
|
-
const stopPress = () => press && (clearTimeout(press.timer), press = null);
|
|
2978
|
-
document.addEventListener(
|
|
2979
|
-
"pointerdown",
|
|
2980
|
-
(e) => {
|
|
2981
|
-
stopPress();
|
|
2982
|
-
pinnedByHold = false;
|
|
2983
|
-
if (e.pointerType === "touch") lastTouch = Date.now();
|
|
2984
|
-
if (e.pointerType !== "touch" || draft || !(e.target instanceof Element) || e.composedPath().includes(host2) || e.target.closest(OFF)) return;
|
|
2985
|
-
const { clientX: x, clientY: y } = e;
|
|
2986
|
-
press = {
|
|
2987
|
-
x,
|
|
2988
|
-
y,
|
|
2989
|
-
timer: setTimeout(() => {
|
|
2990
|
-
press = null;
|
|
2991
|
-
pinnedByHold = true;
|
|
2992
|
-
navigator.vibrate?.(8);
|
|
2993
|
-
getSelection?.()?.removeAllRanges();
|
|
2994
|
-
afterDrag = true;
|
|
2995
|
-
setTimeout(() => afterDrag = false, 800);
|
|
2996
|
-
showAgain();
|
|
2997
|
-
openId = null;
|
|
2998
|
-
begin(anchorAt(x, y));
|
|
2999
|
-
}, 500)
|
|
3000
|
-
};
|
|
3001
|
-
},
|
|
3002
|
-
true
|
|
3003
|
-
);
|
|
3004
|
-
document.addEventListener("pointermove", (e) => press && Math.hypot(e.clientX - press.x, e.clientY - press.y) > 10 && stopPress(), true);
|
|
3005
|
-
document.addEventListener("pointerup", (e) => {
|
|
3006
|
-
if (e.pointerType === "touch") lastTouch = Date.now();
|
|
3007
|
-
stopPress();
|
|
3008
|
-
if (pinnedByHold) root.querySelector(".float textarea")?.focus({ preventScroll: true });
|
|
3009
|
-
}, true);
|
|
3010
|
-
document.addEventListener("touchend", (e) => {
|
|
3011
|
-
if (!pinnedByHold) return;
|
|
3012
|
-
pinnedByHold = false;
|
|
3013
|
-
e.preventDefault();
|
|
3014
|
-
root.querySelector(".float textarea")?.focus({ preventScroll: true });
|
|
3015
|
-
}, { capture: true, passive: false });
|
|
3016
|
-
document.addEventListener("pointercancel", stopPress, true);
|
|
3017
|
-
addEventListener("scroll", stopPress, { passive: true, capture: true });
|
|
3018
|
-
document.addEventListener("contextmenu", (e) => (press || afterDrag) && e.preventDefault(), true);
|
|
3019
|
-
let selRect = null;
|
|
3020
|
-
document.addEventListener("selectionchange", () => {
|
|
3021
|
-
const sel = getSelection?.();
|
|
3022
|
-
const range = sel?.rangeCount && sel.getRangeAt(0);
|
|
3023
|
-
const text = String(sel || "").trim();
|
|
3024
|
-
const inside = range && host2.contains(range.commonAncestorContainer);
|
|
3025
|
-
selRect = coarse && on && !draft && text && range && !inside ? range.getClientRects()[0] || range.getBoundingClientRect() : null;
|
|
3026
|
-
selChip.hidden = !selRect;
|
|
3027
|
-
if (!selRect) return;
|
|
3028
|
-
const below = selRect.bottom + 52 < innerHeight;
|
|
3029
|
-
selChip.style.left = `${Math.min(Math.max(selRect.left + selRect.width / 2, 60), innerWidth - 60)}px`;
|
|
3030
|
-
selChip.style.top = `${below ? selRect.bottom + 10 : Math.max(selRect.top - 46, 8)}px`;
|
|
3031
|
-
});
|
|
3032
|
-
const commentOnSelection = () => {
|
|
3033
|
-
const sel = getSelection?.();
|
|
3034
|
-
const range = sel?.rangeCount && sel.getRangeAt(0);
|
|
3035
|
-
const exact = String(sel || "").replace(/\s+/g, " ").trim();
|
|
3036
|
-
if (!range || !exact || host2.contains(range.commonAncestorContainer)) return false;
|
|
3037
|
-
const rects = range.getClientRects();
|
|
3038
|
-
const first = rects[0] || range.getBoundingClientRect();
|
|
3039
|
-
const last = rects[rects.length - 1] || first;
|
|
3040
|
-
const startEl = range.startContainer.nodeType === 1 ? range.startContainer : range.startContainer.parentElement;
|
|
3041
|
-
const endEl = range.endContainer.nodeType === 1 ? range.endContainer : range.endContainer.parentElement;
|
|
3042
|
-
const anchor = startEl && (startEl === endEl || startEl.contains(endEl)) ? anchorAt(Math.max(last.left, last.right - 2), last.top + last.height / 2) : anchorAt(first.left + 2, first.top + first.height / 2);
|
|
3043
|
-
const at = range.commonAncestorContainer;
|
|
3044
|
-
const block = (
|
|
3045
|
-
/** @type {Element | null} */
|
|
3046
|
-
(at.nodeType === 1 ? at : at.parentElement)?.closest("p, li, h1, h2, h3, h4, h5, h6, td, th, figcaption, blockquote, pre, section, article, div") || document.body
|
|
3047
|
-
);
|
|
3048
|
-
const side = (a, b) => {
|
|
3049
|
-
const r = document.createRange();
|
|
3050
|
-
r.setStart(...a);
|
|
3051
|
-
r.setEnd(...b);
|
|
3052
|
-
return String(r).replace(/\s+/g, " ");
|
|
3053
|
-
};
|
|
3054
|
-
anchor.kind = "text";
|
|
3055
|
-
anchor.quote = {
|
|
3056
|
-
exact: short(exact, 300),
|
|
3057
|
-
prefix: side([block, 0], [range.startContainer, range.startOffset]).replace(/^\s+/, "").slice(-40),
|
|
3058
|
-
suffix: side([range.endContainer, range.endOffset], [block, block.childNodes.length]).replace(/\s+$/, "").slice(0, 40)
|
|
3059
|
-
};
|
|
3060
|
-
sel.removeAllRanges();
|
|
3061
|
-
selChip.hidden = true;
|
|
3062
|
-
showAgain();
|
|
3063
|
-
openId = null;
|
|
3064
|
-
begin(anchor);
|
|
3065
|
-
return true;
|
|
3066
|
-
};
|
|
3067
|
-
selChip.addEventListener("click", (e) => {
|
|
3068
|
-
e.stopPropagation();
|
|
3069
|
-
if (selRect) commentOnSelection();
|
|
3070
|
-
});
|
|
3071
|
-
document.addEventListener("mouseup", (e) => {
|
|
3072
|
-
if (on && !cursorMode && !draft && e.shiftKey && e.button === 0 && !e.composedPath().includes(host2)) setTimeout(commentOnSelection, 0);
|
|
3073
|
-
}, true);
|
|
3074
|
-
function onPageClick(e) {
|
|
3075
|
-
if (e.composedPath().includes(host2)) return;
|
|
3076
|
-
if (draft || openId) {
|
|
3077
|
-
if ([...root.querySelectorAll("textarea")].some((t) => t.value.trim())) return;
|
|
3078
|
-
draft = null;
|
|
3079
|
-
openId = null;
|
|
3080
|
-
render();
|
|
3081
|
-
return;
|
|
3082
|
-
}
|
|
3083
|
-
if (!on && !e.altKey || cursorMode && !e.altKey || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) return;
|
|
3084
|
-
if (lastTouch && Date.now() - lastTouch < 800) return;
|
|
3085
|
-
if (e.altKey) e.preventDefault();
|
|
3086
|
-
else if (e.defaultPrevented || e.target instanceof Element && e.target.closest(INTERACTIVE)) return;
|
|
3087
|
-
if (e.target instanceof Element && e.target.closest(OFF)) return;
|
|
3088
|
-
if (String(getSelection?.() || "").trim()) return;
|
|
3089
|
-
showAgain();
|
|
3090
|
-
begin(anchorAt(e.clientX, e.clientY));
|
|
3091
|
-
}
|
|
3092
|
-
const movePins = () => {
|
|
3093
|
-
const list = threads().filter((c) => c.anchor?.kind !== "page");
|
|
3094
|
-
if (!on || openId || list.length !== pinsById.size) return render();
|
|
3095
|
-
const places = list.map((c) => [pinsById.get(c.id), position(c.anchor || {})]);
|
|
3096
|
-
if (places.some(([pin]) => !pin)) return render();
|
|
3097
|
-
for (const [pin, { left, top, moved }] of places) {
|
|
3098
|
-
pin.style.left = `${left}px`;
|
|
3099
|
-
pin.style.top = `${top}px`;
|
|
3100
|
-
pin.classList.toggle("moved", Boolean(moved));
|
|
3101
|
-
}
|
|
3102
|
-
};
|
|
3103
|
-
let frame = 0;
|
|
3104
|
-
const reflow = () => {
|
|
3105
|
-
cancelAnimationFrame(frame);
|
|
3106
|
-
frame = requestAnimationFrame(() => {
|
|
3107
|
-
if (draft || root.activeElement || grabbing) return;
|
|
3108
|
-
movePins();
|
|
3109
|
-
});
|
|
3110
|
-
};
|
|
3111
|
-
addEventListener("resize", reflow);
|
|
3112
|
-
addEventListener("scroll", (e) => e.target !== document && !host2.contains(
|
|
3113
|
-
/** @type {Node} */
|
|
3114
|
-
e.target
|
|
3115
|
-
) && reflow(), { capture: true, passive: true });
|
|
3116
|
-
const navigated = () => {
|
|
3117
|
-
if (gone) return;
|
|
3118
|
-
if (!host2.isConnected && document.body) document.body.append(host2);
|
|
3119
|
-
if (!fonts.isConnected) document.head.append(fonts);
|
|
3120
|
-
if (!pinCursorStyle.isConnected) document.head.append(pinCursorStyle);
|
|
3121
|
-
if (pageNow() === page) return;
|
|
3122
|
-
page = pageNow();
|
|
3123
|
-
seen = readSeen();
|
|
3124
|
-
syncReads();
|
|
3125
|
-
comments = [];
|
|
3126
|
-
draft = null;
|
|
3127
|
-
openId = null;
|
|
3128
|
-
render();
|
|
3129
|
-
load();
|
|
3130
|
-
};
|
|
3131
|
-
for (const m of ["pushState", "replaceState"]) {
|
|
3132
|
-
const original = history[m];
|
|
3133
|
-
history[m] = function(...args) {
|
|
3134
|
-
const out = original.apply(this, args);
|
|
3135
|
-
queueMicrotask(navigated);
|
|
3136
|
-
return out;
|
|
3137
|
-
};
|
|
3138
|
-
}
|
|
3139
|
-
addEventListener("popstate", navigated);
|
|
3140
|
-
document.addEventListener("astro:after-swap", navigated);
|
|
3141
|
-
document.addEventListener("visibilitychange", () => {
|
|
3142
|
-
if (document.visibilityState === "visible" && !draft && !root.activeElement) load();
|
|
3143
|
-
});
|
|
3144
|
-
if ("ResizeObserver" in window) new ResizeObserver(reflow).observe(document.body);
|
|
3145
|
-
const fonts = document.createElement("style");
|
|
3146
|
-
if (script?.dataset.fontUrl)
|
|
3147
|
-
fonts.textContent = `@font-face{font-family:'lab comments';font-display:swap;src:url('${new URL(script.dataset.fontUrl, script.src || location.href)}') format('woff2');}`;
|
|
3148
|
-
const fontName = script?.dataset.fontUrl ? "lab comments" : script?.dataset.font;
|
|
3149
|
-
if (fontName) host2.style.setProperty("--lab-font", `'${fontName.replace(/'/g, "")}', system-ui, sans-serif`);
|
|
3150
|
-
const pinCursorStyle = document.createElement("style");
|
|
3151
|
-
const ptr = el2("div", { class: "ptr", "aria-hidden": "true" });
|
|
3152
|
-
ptr.append(el2("span", { class: "ini" }, "+"), el2("span", { class: "tick" }, "go"));
|
|
3153
|
-
root.append(ptr);
|
|
3154
|
-
let mouse = null;
|
|
3155
|
-
const place = (x, y, target) => {
|
|
3156
|
-
const show = Boolean(target) && target !== host2 && !host2.contains(target) && getComputedStyle(target).cursor === "none";
|
|
3157
|
-
ptr.classList.toggle("show", show);
|
|
3158
|
-
ptr.classList.toggle("go", goMode);
|
|
3159
|
-
ptr.style.transform = `translate(${x - 1}px, ${y - 27}px)`;
|
|
3160
|
-
};
|
|
3161
|
-
const recheck = () => mouse && requestAnimationFrame(() => mouse && place(mouse.x, mouse.y, document.elementFromPoint(mouse.x, mouse.y)));
|
|
3162
|
-
addEventListener("pointermove", (e) => {
|
|
3163
|
-
if (e.pointerType !== "mouse") return;
|
|
3164
|
-
document.documentElement.classList.add("lab-drawn");
|
|
3165
|
-
mouse = { x: e.clientX, y: e.clientY };
|
|
3166
|
-
const t = e.composedPath()[0];
|
|
3167
|
-
place(e.clientX, e.clientY, t instanceof Element ? t : null);
|
|
3168
|
-
}, { capture: true, passive: true });
|
|
3169
|
-
addEventListener("scroll", recheck, { capture: true, passive: true });
|
|
3170
|
-
addEventListener("keydown", (e) => (e.key === "Shift" || e.key === "Alt") && recheck(), true);
|
|
3171
|
-
addEventListener("keyup", (e) => (e.key === "Shift" || e.key === "Alt") && recheck(), true);
|
|
3172
|
-
document.documentElement.addEventListener("mouseleave", () => (mouse = null, ptr.classList.remove("show")));
|
|
3173
|
-
addEventListener("blur", () => (mouse = null, ptr.classList.remove("show")));
|
|
3174
|
-
let cursorKey = "";
|
|
3175
|
-
function refreshPinCursor() {
|
|
3176
|
-
const ch = (initial(store2.get("lab-name")) || "+").replace(/[<>&'"]/g, "");
|
|
3177
|
-
if (ch === cursorKey) return;
|
|
3178
|
-
cursorKey = ch;
|
|
3179
|
-
ptr.querySelector(".ini").textContent = ch;
|
|
3180
|
-
const plain2 = `:not(${INTERACTIVE}, a *, button *, label *, [role="button"] *, [contenteditable], [contenteditable] *, ${OFF}, ${OFF} *, [data-lab-comments])`;
|
|
3181
|
-
const top = `dialog, dialog *, [popover], [popover] *, :fullscreen, :fullscreen *`;
|
|
3182
|
-
pinCursorStyle.textContent = `@layer lab-pointer { html.lab-pinning:not(.lab-shift) body, html.lab-pinning:not(.lab-shift) body *${plain2} { cursor: crosshair; } html.lab-drawn.lab-pinning:not(.lab-shift):not(.lab-dragging) body, html.lab-drawn.lab-pinning:not(.lab-shift):not(.lab-dragging) body *${plain2}:not(${top}) { cursor: none; } html.lab-pinning body :is([contenteditable], [contenteditable] *) { cursor: text; } html.lab-pinning body :is(${OFF}, ${OFF} *) { cursor: auto; } }html.lab-alt body, html.lab-alt body *:not([data-lab-comments], [data-lab-comments] *, ${OFF}, ${OFF} *) { cursor: crosshair !important; }html.lab-drawn.lab-alt body, html.lab-drawn.lab-alt body *:not([data-lab-comments], [data-lab-comments] *, ${OFF}, ${OFF} *, ${top}) { cursor: none !important; }html.lab-go:not(.lab-drawn) body, html.lab-go:not(.lab-drawn) body * { cursor: copy !important; }`;
|
|
3183
|
-
}
|
|
3184
|
-
fonts.textContent += `@media (pointer: fine) { html.lab-pinning:not(.lab-shift) body > :not([data-lab-comments]), html.lab-pinning:not(.lab-shift) body > :not([data-lab-comments]) :not(input, textarea, select, [contenteditable], [contenteditable] *) { -webkit-user-select: none; user-select: none; } }`;
|
|
3185
|
-
let shiftOff = 0;
|
|
3186
|
-
const shiftKey = (e) => {
|
|
3187
|
-
clearTimeout(shiftOff);
|
|
3188
|
-
if (e.shiftKey) document.documentElement.classList.add("lab-shift");
|
|
3189
|
-
else shiftOff = setTimeout(() => (document.documentElement.classList.remove("lab-shift"), recheck()), 400);
|
|
3190
|
-
};
|
|
3191
|
-
addEventListener("keydown", shiftKey, true);
|
|
3192
|
-
addEventListener("keyup", shiftKey, true);
|
|
3193
|
-
addEventListener("pointerdown", (e) => {
|
|
3194
|
-
if (e.shiftKey) return shiftKey(e);
|
|
3195
|
-
clearTimeout(shiftOff);
|
|
3196
|
-
document.documentElement.classList.remove("lab-shift");
|
|
3197
|
-
}, true);
|
|
3198
|
-
addEventListener("blur", () => document.documentElement.classList.remove("lab-shift"));
|
|
3199
|
-
fonts.textContent += "html.lab-dragging, html.lab-dragging * { user-select: none !important; -webkit-user-select: none !important; cursor: crosshair !important; }";
|
|
3200
|
-
fonts.textContent += "html.lab-sheet, html.lab-sheet body { overscroll-behavior-y: none; }";
|
|
3201
|
-
fonts.textContent += "html.lab-room body::after { content: ''; display: block; height: var(--lab-room, 0px); }";
|
|
3202
|
-
addEventListener("scroll", () => {
|
|
3203
|
-
const de = document.documentElement;
|
|
3204
|
-
const had = parseFloat(de.style.getPropertyValue("--lab-room")) || 0;
|
|
3205
|
-
if (!had || host2.hasAttribute("data-sheet")) return;
|
|
3206
|
-
const room = Math.max(0, Math.ceil(scrollY + innerHeight - (de.scrollHeight - had)));
|
|
3207
|
-
if (room >= had) return;
|
|
3208
|
-
de.style.setProperty("--lab-room", `${room}px`);
|
|
3209
|
-
if (!room) de.classList.remove("lab-room");
|
|
3210
|
-
}, { passive: true });
|
|
3211
|
-
fonts.textContent += "@media (pointer: coarse) { html.lab-sheet, html.lab-sheet body { overflow: hidden; } }";
|
|
3212
|
-
fonts.textContent += `html.lab-pinning body, html.lab-pinning body * { -webkit-touch-callout: none; }`;
|
|
3213
|
-
fonts.textContent += `@media (pointer: coarse) { html.lab-pinning body > :not([data-lab-comments]) { -webkit-user-select: none; user-select: none; } html.lab-pinning body > :not([data-lab-comments]), html.lab-pinning body > :not([data-lab-comments]) * { -webkit-user-drag: none; } }`;
|
|
3214
|
-
const setAlt = (down) => document.documentElement.classList.toggle("lab-alt", Boolean(down));
|
|
3215
|
-
addEventListener("keydown", (e) => e.key === "Alt" && setAlt(true), true);
|
|
3216
|
-
addEventListener("keyup", (e) => e.key === "Alt" && setAlt(false), true);
|
|
3217
|
-
addEventListener("pointermove", (e) => setAlt(e.altKey), { capture: true, passive: true });
|
|
3218
|
-
addEventListener("blur", () => setAlt(false));
|
|
3219
|
-
const start = () => {
|
|
3220
|
-
document.head.append(fonts, pinCursorStyle);
|
|
3221
|
-
refreshPinCursor();
|
|
3222
|
-
if (on) showHint();
|
|
3223
|
-
document.body.append(host2);
|
|
3224
|
-
const paint = "background-color: rgba(52, 199, 89, .3); color: inherit;";
|
|
3225
|
-
fonts.textContent += `html.lab-pinning ::selection { ${paint} } ::highlight(lab-quote) { ${paint} }`;
|
|
3226
|
-
load();
|
|
3227
|
-
};
|
|
3228
|
-
if (document.body) start();
|
|
3229
|
-
else document.addEventListener("DOMContentLoaded", start);
|
|
3230
|
-
if (script?.dataset.live) {
|
|
3231
|
-
let onState = function(v) {
|
|
3232
|
-
{
|
|
3233
|
-
if (v.widget && script.dataset.widget && v.widget !== script.dataset.widget) return reload();
|
|
3234
|
-
if (v.lab && script.dataset.lab && v.lab !== script.dataset.lab) {
|
|
3235
|
-
script.dataset.lab = v.lab;
|
|
3236
|
-
script.dataset.version = String(v.files);
|
|
3237
|
-
hotAt = v.hot;
|
|
3238
|
-
commentsRev = v.comments;
|
|
3239
|
-
morphPage();
|
|
3240
|
-
load();
|
|
3241
|
-
}
|
|
3242
|
-
if (String(v.files) !== script.dataset.version) return reload();
|
|
3243
|
-
if (hotAt !== null && v.hot !== hotAt) {
|
|
3244
|
-
if (v.hot - hotAt > 1) hotUpdate([{ kind: "html" }, { kind: "css", path: "" }]);
|
|
3245
|
-
else hotUpdate(v.hotFiles || []);
|
|
3246
|
-
}
|
|
3247
|
-
hotAt = v.hot;
|
|
3248
|
-
if (commentsRev !== null && v.comments !== commentsRev) loadChanges(commentsRev);
|
|
3249
|
-
commentsRev = v.comments;
|
|
3250
|
-
if (v.reads !== readsAt) {
|
|
3251
|
-
readsAt = v.reads;
|
|
3252
|
-
syncReads();
|
|
3253
|
-
}
|
|
3254
|
-
const s = v.session;
|
|
3255
|
-
const mode = s ? v.mode || "listening" : "away";
|
|
3256
|
-
const span = (t) => Object.assign(document.createElement("span"), { textContent: t });
|
|
3257
|
-
const agent = s?.agent || "Claude";
|
|
3258
|
-
const tag = s && s.name !== agent ? [span(`(${s.name})`)] : [];
|
|
3259
|
-
if (mode === "listening") who.replaceChildren(span("talking to"), agent, ...tag);
|
|
3260
|
-
else if (mode === "working") who.replaceChildren(agent, span("is working"), ...tag);
|
|
3261
|
-
else who.replaceChildren(span("no agent listening"));
|
|
3262
|
-
who.classList.toggle("idle", mode === "away");
|
|
3263
|
-
who.classList.toggle("working", mode === "working");
|
|
3264
|
-
listBtn.dataset.agent = mode;
|
|
3265
|
-
chatBtn.dataset.agent = mode;
|
|
3266
|
-
if (coarse) chatBtn.title = who.textContent;
|
|
3267
|
-
who.setAttribute("aria-label", who.textContent);
|
|
3268
|
-
if (s?.url && mode !== "away") Object.assign(who, { href: s.url, target: "_blank" });
|
|
3269
|
-
else who.removeAttribute("href");
|
|
3270
|
-
who.dataset.copy = !s?.url && s?.resume && mode !== "away" ? s.resume : "";
|
|
3271
|
-
who.title = mode === "away" ? "Ask your agent to run: npx @leonidstern/labit wait" : s?.resume ? `${s.resume}${who.dataset.copy ? " (tap to copy)" : ""}` : "";
|
|
3272
|
-
who.hidden = false;
|
|
3273
|
-
}
|
|
3274
|
-
};
|
|
3275
|
-
const key = "lab-scroll:" + location.pathname;
|
|
3276
|
-
try {
|
|
3277
|
-
const kept = JSON.parse(sessionStorage.getItem(key) || "null");
|
|
3278
|
-
if (kept !== null) {
|
|
3279
|
-
sessionStorage.removeItem(key);
|
|
3280
|
-
if (kept.open) openId = kept.open;
|
|
3281
|
-
if (kept.list) {
|
|
3282
|
-
listOpen = true;
|
|
3283
|
-
filter = ["new", "open", "resolved", "mine"].includes(kept.filter) ? kept.filter : filter;
|
|
3284
|
-
}
|
|
3285
|
-
if (kept.chat) chatOpen = true;
|
|
3286
|
-
addEventListener("load", () => scrollTo(0, +(kept.y ?? kept)));
|
|
3287
|
-
}
|
|
3288
|
-
} catch {
|
|
3289
|
-
}
|
|
3290
|
-
let touchedAt = 0;
|
|
3291
|
-
for (const t of ["pointerdown", "keydown", "wheel", "touchstart"]) addEventListener(t, () => touchedAt = performance.now(), { capture: true, passive: true });
|
|
3292
|
-
const busy = () => draft || grabbing || openId || chatOpen || listOpen || coarse && /^(textarea|input)$/.test(root.activeElement?.localName || "") || [...root.querySelectorAll("textarea")].some((t) => t.value.trim()) || performance.now() - touchedAt < 1500;
|
|
3293
|
-
let reloadWhenShown = false;
|
|
3294
|
-
let reloadTimer = 0;
|
|
3295
|
-
const reload = () => {
|
|
3296
|
-
if (document.hidden) return void (reloadWhenShown = true);
|
|
3297
|
-
if (busy()) {
|
|
3298
|
-
if (!reloadTimer) reloadTimer = setTimeout(() => (reloadTimer = 0, reload()), 500);
|
|
3299
|
-
return;
|
|
3300
|
-
}
|
|
3301
|
-
try {
|
|
3302
|
-
sessionStorage.setItem(key, JSON.stringify({ y: scrollY, open: openId, list: listOpen, filter, chat: chatOpen }));
|
|
3303
|
-
} catch {
|
|
3304
|
-
}
|
|
3305
|
-
location.reload();
|
|
3306
|
-
};
|
|
3307
|
-
const who = document.createElement("a");
|
|
3308
|
-
who.className = "listener";
|
|
3309
|
-
who.addEventListener("click", async () => {
|
|
3310
|
-
const text = who.dataset.copy;
|
|
3311
|
-
if (!text) return;
|
|
3312
|
-
try {
|
|
3313
|
-
await navigator.clipboard.writeText(text);
|
|
3314
|
-
const was = [...who.childNodes];
|
|
3315
|
-
who.replaceChildren("copied");
|
|
3316
|
-
setTimeout(() => who.textContent === "copied" && who.replaceChildren(...was), 1200);
|
|
3317
|
-
} catch {
|
|
3318
|
-
}
|
|
3319
|
-
});
|
|
3320
|
-
who.hidden = true;
|
|
3321
|
-
root.querySelector(".left").prepend(who);
|
|
3322
|
-
let stream = null;
|
|
3323
|
-
let beat = 0;
|
|
3324
|
-
const showAway = (word) => {
|
|
3325
|
-
who.replaceChildren(Object.assign(document.createElement("span"), { textContent: word }));
|
|
3326
|
-
who.setAttribute("aria-label", word);
|
|
3327
|
-
who.classList.add("idle");
|
|
3328
|
-
who.classList.remove("working");
|
|
3329
|
-
who.hidden = false;
|
|
3330
|
-
};
|
|
3331
|
-
let commentsRev = null;
|
|
3332
|
-
let readsAt = null;
|
|
3333
|
-
let hotAt = null;
|
|
3334
|
-
const swapCss = (files) => {
|
|
3335
|
-
const links = [.../** @type {NodeListOf<HTMLLinkElement>} */
|
|
3336
|
-
document.querySelectorAll('link[rel~="stylesheet"][href]:not([data-lab-swap])')].filter((l) => new URL(l.href, location.href).origin === location.origin);
|
|
3337
|
-
const named = links.filter((l) => files.includes(decodeURIComponent(new URL(l.href, location.href).pathname)));
|
|
3338
|
-
for (const link of named.length ? named : links) {
|
|
3339
|
-
const url = new URL(link.href, location.href);
|
|
3340
|
-
url.searchParams.set("lab-v", Date.now().toString(36));
|
|
3341
|
-
const next = (
|
|
3342
|
-
/** @type {HTMLLinkElement} */
|
|
3343
|
-
link.cloneNode()
|
|
3344
|
-
);
|
|
3345
|
-
next.href = url.href;
|
|
3346
|
-
next.dataset.labSwap = "";
|
|
3347
|
-
const path = url.pathname;
|
|
3348
|
-
next.addEventListener("load", () => {
|
|
3349
|
-
for (
|
|
3350
|
-
const l of
|
|
3351
|
-
/** @type {NodeListOf<HTMLLinkElement>} */
|
|
3352
|
-
document.querySelectorAll('link[rel~="stylesheet"][href]')
|
|
3353
|
-
) if (l !== next && new URL(l.href, location.href).pathname === path) l.remove();
|
|
3354
|
-
delete next.dataset.labSwap;
|
|
3355
|
-
}, { once: true });
|
|
3356
|
-
next.addEventListener("error", () => next.remove(), { once: true });
|
|
3357
|
-
link.after(next);
|
|
3358
|
-
}
|
|
3359
|
-
};
|
|
3360
|
-
const fresh = (u) => {
|
|
3361
|
-
const url = new URL(u, location.href);
|
|
3362
|
-
url.searchParams.set("lab-v", Date.now().toString(36));
|
|
3363
|
-
return url.href;
|
|
3364
|
-
};
|
|
3365
|
-
const samePath = (u, paths) => {
|
|
3366
|
-
try {
|
|
3367
|
-
const url = new URL(u, location.href);
|
|
3368
|
-
return url.origin === location.origin && paths.includes(decodeURIComponent(url.pathname));
|
|
3369
|
-
} catch {
|
|
3370
|
-
return false;
|
|
3371
|
-
}
|
|
3372
|
-
};
|
|
3373
|
-
const swapImages = (paths) => {
|
|
3374
|
-
let hit = 0;
|
|
3375
|
-
for (const n of document.querySelectorAll('img, source, video[poster], image, use, link[rel~="icon"]')) {
|
|
3376
|
-
if (host2.contains(n)) continue;
|
|
3377
|
-
for (const attr of ["src", "href", "poster", "xlink:href"]) {
|
|
3378
|
-
const v = n.getAttribute(attr);
|
|
3379
|
-
if (!v || !samePath(v.split("#")[0], paths)) continue;
|
|
3380
|
-
const next = fresh(v.split("#")[0]);
|
|
3381
|
-
const im = new Image();
|
|
3382
|
-
im.src = next;
|
|
3383
|
-
(im.decode ? im.decode() : Promise.resolve()).catch(() => {
|
|
3384
|
-
}).finally(() => n.setAttribute(attr, next + (v.includes("#") ? v.slice(v.indexOf("#")) : "")));
|
|
3385
|
-
hit++;
|
|
3386
|
-
}
|
|
3387
|
-
const set = n.getAttribute("srcset");
|
|
3388
|
-
if (set && set.split(",").some((c) => samePath(c.trim().split(/\s+/)[0], paths))) {
|
|
3389
|
-
n.setAttribute("srcset", set.split(",").map((c) => {
|
|
3390
|
-
const [u, ...rest] = c.trim().split(/\s+/);
|
|
3391
|
-
return [samePath(u, paths) ? fresh(u) : u, ...rest].join(" ");
|
|
3392
|
-
}).join(", "));
|
|
3393
|
-
hit++;
|
|
3394
|
-
}
|
|
3395
|
-
}
|
|
3396
|
-
if (!hit) swapCss([]);
|
|
3397
|
-
};
|
|
3398
|
-
const reloadFonts = (paths) => {
|
|
3399
|
-
for (const sheet of document.styleSheets) {
|
|
3400
|
-
let rules;
|
|
3401
|
-
try {
|
|
3402
|
-
rules = sheet.cssRules;
|
|
3403
|
-
} catch {
|
|
3404
|
-
continue;
|
|
3405
|
-
}
|
|
3406
|
-
for (const r of rules || []) {
|
|
3407
|
-
if (!(r instanceof CSSFontFaceRule)) continue;
|
|
3408
|
-
const src = r.style.getPropertyValue("src");
|
|
3409
|
-
const base = sheet.href || location.href;
|
|
3410
|
-
if (!/url\(/.test(src) || ![...src.matchAll(/url\(["']?([^"')]+)/g)].some((m) => samePath(new URL(m[1], base).href, paths))) continue;
|
|
3411
|
-
const again = src.replace(/url\(["']?([^"')]+)["']?\)/g, (all, u) => samePath(new URL(u, base).href, paths) ? `url("${fresh(new URL(u, base).href)}")` : all);
|
|
3412
|
-
const d = (k) => r.style.getPropertyValue(k) || void 0;
|
|
3413
|
-
try {
|
|
3414
|
-
const face = new FontFace(
|
|
3415
|
-
d("font-family").replace(/^["']|["']$/g, ""),
|
|
3416
|
-
again,
|
|
3417
|
-
/** @type {any} */
|
|
3418
|
-
{ weight: d("font-weight"), style: d("font-style"), stretch: d("font-stretch"), unicodeRange: d("unicode-range"), display: d("font-display") }
|
|
3419
|
-
);
|
|
3420
|
-
face.load().then((f) => document.fonts.add(f)).catch(() => {
|
|
3421
|
-
});
|
|
3422
|
-
} catch {
|
|
3423
|
-
}
|
|
3424
|
-
}
|
|
3425
|
-
}
|
|
3426
|
-
};
|
|
3427
|
-
const ownStyles = () => /* @__PURE__ */ new Set([fonts, pinCursorStyle]);
|
|
3428
|
-
const scriptsOf = (doc) => [...doc.querySelectorAll("script")].filter((x) => !/\/_lab\/comments\.js/.test(x.getAttribute("src") || "")).map((x) => x.getAttribute("src") || x.textContent);
|
|
3429
|
-
const sheetsOf = (doc) => [...doc.querySelectorAll('link[rel~="stylesheet"]')].map((l) => {
|
|
3430
|
-
try {
|
|
3431
|
-
return new URL(l.getAttribute("href"), location.href).pathname;
|
|
3432
|
-
} catch {
|
|
3433
|
-
return "";
|
|
3434
|
-
}
|
|
3435
|
-
});
|
|
3436
|
-
const keepOut = (n) => n === host2 || n.nodeType === 1 && n.localName === "script";
|
|
3437
|
-
const same = (o, n) => o.nodeType === n.nodeType && o.nodeName === n.nodeName && (o.nodeType !== 1 || (o.id || "") === (n.id || ""));
|
|
3438
|
-
const alike = (o, n) => same(o, n) && (o.nodeType === 1 ? Boolean(o.id) || o.getAttribute("class") === n.getAttribute("class") : o.nodeType !== 3 || o.data === n.data);
|
|
3439
|
-
const morphKids = (a, b) => {
|
|
3440
|
-
const olds = [...a.childNodes].filter((n) => !keepOut(n));
|
|
3441
|
-
const news = [...b.childNodes].filter((n) => !(n.nodeType === 1 && n.localName === "script"));
|
|
3442
|
-
let j = 0;
|
|
3443
|
-
let prev = null;
|
|
3444
|
-
const put = (n) => {
|
|
3445
|
-
const c = document.importNode(n, true);
|
|
3446
|
-
a.insertBefore(c, prev ? prev.nextSibling : olds[j] || a.firstChild);
|
|
3447
|
-
return c;
|
|
3448
|
-
};
|
|
3449
|
-
news.forEach((n, i) => {
|
|
3450
|
-
const o = olds[j];
|
|
3451
|
-
if (!o) return void (prev = put(n));
|
|
3452
|
-
if (alike(o, n)) return void (prev = morphNode(o, n), j++);
|
|
3453
|
-
if (news.slice(i + 1, i + 8).some((m) => alike(o, m))) return void (prev = put(n));
|
|
3454
|
-
const k = olds.slice(j + 1, j + 8).findIndex((m) => alike(m, n));
|
|
3455
|
-
if (k >= 0) {
|
|
3456
|
-
for (const gone2 of olds.slice(j, j + 1 + k)) gone2.remove();
|
|
3457
|
-
j += k + 1;
|
|
3458
|
-
return void (prev = morphNode(olds[j], n), j++);
|
|
3459
|
-
}
|
|
3460
|
-
prev = morphNode(o, n);
|
|
3461
|
-
j++;
|
|
3462
|
-
});
|
|
3463
|
-
for (const o of olds.slice(j)) o.remove();
|
|
3464
|
-
};
|
|
3465
|
-
const morphNode = (o, n) => {
|
|
3466
|
-
if (o.nodeType !== n.nodeType || o.nodeName !== n.nodeName || o.nodeType === 1 && (o.id || "") !== (n.id || "")) {
|
|
3467
|
-
const c = document.importNode(n, true);
|
|
3468
|
-
o.replaceWith(c);
|
|
3469
|
-
return c;
|
|
3470
|
-
}
|
|
3471
|
-
if (o.nodeType === 3 || o.nodeType === 8) {
|
|
3472
|
-
if (o.data !== n.data) o.data = n.data;
|
|
3473
|
-
return o;
|
|
3474
|
-
}
|
|
3475
|
-
if (o.nodeType !== 1) return o;
|
|
3476
|
-
for (const { name } of Array.from(o.attributes)) if (!n.hasAttribute(name) && !(name === "open" && /^(details|dialog)$/.test(o.localName))) o.removeAttribute(name);
|
|
3477
|
-
for (const { name, value } of Array.from(n.attributes)) if (o.getAttribute(name) !== value) o.setAttribute(name, value);
|
|
3478
|
-
if (o === document.activeElement || o.shadowRoot || /^(iframe|canvas|video|audio|textarea|select|input)$/.test(o.localName)) return o;
|
|
3479
|
-
morphKids(o, n);
|
|
3480
|
-
return o;
|
|
3481
|
-
};
|
|
3482
|
-
const ownScripts = () => scriptsOf(document).length > 0;
|
|
3483
|
-
let morphRun = 0;
|
|
3484
|
-
const morphPage = async () => {
|
|
3485
|
-
if (ownScripts()) return reload();
|
|
3486
|
-
const run = ++morphRun;
|
|
3487
|
-
try {
|
|
3488
|
-
const res = await fetch(location.href, { cache: "no-store", headers: { accept: "text/html" } });
|
|
3489
|
-
if (!res.ok) return reload();
|
|
3490
|
-
const html = await res.text();
|
|
3491
|
-
if (run !== morphRun) return;
|
|
3492
|
-
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
3493
|
-
if (scriptsOf(doc).join("\n") !== scriptsOf(document).join("\n") || sheetsOf(doc).join("\n") !== sheetsOf(document).join("\n")) return reload();
|
|
3494
|
-
let mark = null;
|
|
3495
|
-
for (const y of [Math.min(innerHeight / 3, 240), innerHeight / 2, 80]) {
|
|
3496
|
-
const e = document.elementFromPoint(innerWidth / 2, y);
|
|
3497
|
-
if (e && e !== document.body && e !== document.documentElement && !host2.contains(e) && e !== host2) {
|
|
3498
|
-
mark = e;
|
|
3499
|
-
break;
|
|
3500
|
-
}
|
|
3501
|
-
}
|
|
3502
|
-
const markTop = mark?.getBoundingClientRect().top;
|
|
3503
|
-
const apply = () => {
|
|
3504
|
-
if (doc.title !== tabTitle.base) {
|
|
3505
|
-
tabTitle.base = doc.title;
|
|
3506
|
-
document.title = doc.title;
|
|
3507
|
-
drawList();
|
|
3508
|
-
}
|
|
3509
|
-
const mine2 = ownStyles();
|
|
3510
|
-
const olds = [...document.head.querySelectorAll("style")].filter((x) => !mine2.has(x));
|
|
3511
|
-
const news = [...doc.head.querySelectorAll("style")];
|
|
3512
|
-
news.forEach((n, i) => olds[i] ? olds[i].textContent !== n.textContent && (olds[i].textContent = n.textContent) : document.head.append(document.importNode(n, true)));
|
|
3513
|
-
for (const o of olds.slice(news.length)) o.remove();
|
|
3514
|
-
morphKids(document.body, doc.body);
|
|
3515
|
-
if (mark?.isConnected) {
|
|
3516
|
-
const moved = mark.getBoundingClientRect().top - markTop;
|
|
3517
|
-
if (Math.abs(moved) > 1) scrollBy(0, moved);
|
|
3518
|
-
}
|
|
3519
|
-
reflow();
|
|
3520
|
-
};
|
|
3521
|
-
const safe = () => {
|
|
3522
|
-
try {
|
|
3523
|
-
apply();
|
|
3524
|
-
} catch {
|
|
3525
|
-
reload();
|
|
3526
|
-
}
|
|
3527
|
-
};
|
|
3528
|
-
if (document.startViewTransition && !still.matches) document.startViewTransition(safe);
|
|
3529
|
-
else safe();
|
|
3530
|
-
} catch {
|
|
3531
|
-
reload();
|
|
3532
|
-
}
|
|
3533
|
-
};
|
|
3534
|
-
const hotUpdate = (files) => {
|
|
3535
|
-
const of = (kind) => files.filter((f) => f.kind === kind).map((f) => f.path);
|
|
3536
|
-
const here = decodeURIComponent(location.pathname).replace(/\/$/, "/index").replace(/\.html?$/i, "");
|
|
3537
|
-
if (of("html").some((p) => !p || p.replace(/\.html?$/i, "") === here)) morphPage();
|
|
3538
|
-
if (of("css").length) swapCss(of("css"));
|
|
3539
|
-
if (of("img").length) swapImages(of("img"));
|
|
3540
|
-
if (of("font").length) reloadFonts(of("font"));
|
|
3541
|
-
};
|
|
3542
|
-
const tab = Math.random().toString(36).slice(2, 12);
|
|
3543
|
-
let pollTimer = 0;
|
|
3544
|
-
let dropTimer = 0;
|
|
3545
|
-
const poll = async () => {
|
|
3546
|
-
try {
|
|
3547
|
-
onState(await (await fetch(`${script.dataset.live.replace(/live$/, "state")}?tab=${tab}`, { cache: "no-store" })).json());
|
|
3548
|
-
} catch {
|
|
3549
|
-
}
|
|
3550
|
-
};
|
|
3551
|
-
const toBackground = () => {
|
|
3552
|
-
clearTimeout(dropTimer);
|
|
3553
|
-
dropTimer = setTimeout(() => {
|
|
3554
|
-
stream?.close();
|
|
3555
|
-
stream = null;
|
|
3556
|
-
clearInterval(pollTimer);
|
|
3557
|
-
pollTimer = setInterval(poll, 2e4);
|
|
3558
|
-
}, 3e4);
|
|
3559
|
-
};
|
|
3560
|
-
const toFront = () => {
|
|
3561
|
-
clearTimeout(dropTimer);
|
|
3562
|
-
clearInterval(pollTimer);
|
|
3563
|
-
pollTimer = 0;
|
|
3564
|
-
connect();
|
|
3565
|
-
};
|
|
3566
|
-
const connect = () => {
|
|
3567
|
-
if (stream) return;
|
|
3568
|
-
stream = new EventSource(`${script.dataset.live}?tab=${tab}`);
|
|
3569
|
-
beat = Date.now();
|
|
3570
|
-
stream.addEventListener("beat", () => beat = Date.now());
|
|
3571
|
-
stream.onerror = () => showAway("reconnecting");
|
|
3572
|
-
stream.onmessage = (e) => {
|
|
3573
|
-
beat = Date.now();
|
|
3574
|
-
onState(JSON.parse(e.data));
|
|
3575
|
-
};
|
|
3576
|
-
};
|
|
3577
|
-
document.addEventListener("visibilitychange", () => {
|
|
3578
|
-
if (document.hidden) return toBackground();
|
|
3579
|
-
if (reloadWhenShown) return reload();
|
|
3580
|
-
toFront();
|
|
3581
|
-
});
|
|
3582
|
-
addEventListener("pagehide", () => {
|
|
3583
|
-
stream?.close();
|
|
3584
|
-
stream = null;
|
|
3585
|
-
fetch(script.dataset.live.replace(/live$/, "bye"), { method: "POST", keepalive: true, headers: { "content-type": "application/json" }, body: JSON.stringify({ tab }) }).catch(() => {
|
|
3586
|
-
});
|
|
3587
|
-
});
|
|
3588
|
-
addEventListener("pageshow", (e) => e.persisted && connect());
|
|
3589
|
-
let tick = Date.now();
|
|
3590
|
-
const freshStream = () => {
|
|
3591
|
-
stream?.close();
|
|
3592
|
-
stream = null;
|
|
3593
|
-
showAway("reconnecting");
|
|
3594
|
-
connect();
|
|
3595
|
-
};
|
|
3596
|
-
setInterval(() => {
|
|
3597
|
-
const now = Date.now();
|
|
3598
|
-
const slept = now - tick > 2e4;
|
|
3599
|
-
tick = now;
|
|
3600
|
-
if (document.hidden) return;
|
|
3601
|
-
if (slept || stream && now - beat > 4e4) freshStream();
|
|
3602
|
-
}, 5e3);
|
|
3603
|
-
addEventListener("online", () => !document.hidden && freshStream());
|
|
3604
|
-
connect();
|
|
3605
|
-
if (document.hidden) toBackground();
|
|
3606
|
-
}
|
|
3607
|
-
})();
|
|
3608
|
-
})();
|
|
46
|
+
<div class="more-menu" id="lab-more" hidden></div>`;let F=(t,l=B)=>l.querySelector(t),J=F(".layer"),oe=F(".hint");matchMedia("(pointer: coarse)").matches&&(oe.textContent="hold to comment");let H=F(".toggle"),se=B.querySelector(".bar"),ae=F(".more"),U=F(".more-menu"),xe=F(".copy-all"),ye=F(".list-btn"),he=F(".go-btn"),Ue=F(".new-prev"),Be=F(".show-done"),Ce=F(".done-btn"),Pe=F(".pause-btn"),Xe=F(".over-btn"),at=!1,Gt={base:""};e.showDone=u.get("lab-show-done")==="1";let Ze=F(".new-next"),Je=F(".send-all"),y=F(".list"),A=F(".hold",y),P=F(".chatwin"),W=B.querySelector(".chat-btn");e.listOpen=!1,e.filter="open",e.refit=()=>{},e.chatOpen=!1;let N=(t,l={},w)=>{let z=document.createElement(t);for(let[R,Z]of Object.entries(l))z.setAttribute(R,Z);return w instanceof Node?z.append(w):w!=null&&(z.textContent=w),z};ro({host:D,layer:J,el:N,store:u}),go({el:N,store:u,root:B,refreshPinCursor:()=>un(),syncReads:()=>sn(),rememberMe:_,whileWriting:()=>$t()}),xo({el:N,mine:t=>Mt(t),repliesOf:t=>ln(t),workState:t=>Re(t)});function K(t,l){let w=new Set(l);for(let R of Array.from(t.childNodes))w.has(R)||R.remove();let z=t.firstChild;for(let R of l)R===z?z=z.nextSibling:t.insertBefore(R,z)}let ce=["claude","codex","cursor","gemini","antigravity","copilot","amp","opencode"],j=t=>{if(!t?.session)return"";let l=String(t.session.kind||t.name||"").trim().split(/\W/)[0].toLowerCase();return ce.includes(l)?l==="antigravity"?"gemini":l:""},te=()=>({"content-type":"application/json",...T?{"x-lab-admin":T}:{}});e.gone=!1,e.loaded=!1,e.retried=!1;let G=()=>!!B.activeElement||[...B.querySelectorAll("textarea")].some(t=>t.value.trim());async function me(){try{let t=await fetch(`${d}?page=${encodeURIComponent(e.page)}`,{headers:te(),cache:"no-store"});if(t.status===404&&!e.loaded&&a?.dataset.enable!=="always"){if(!e.retried){e.retried=!0,setTimeout(me,1500);return}e.gone=!0,e.on=!1,document.documentElement.classList.remove("lab-pinning"),D.remove(),ue.remove();return}if(!t.ok)throw new Error(String(t.status));let l=await t.json();if(e.comments=l.comments||[],e.isAdmin=!!l.admin,!e.loaded&&!e.openId){let w=e.comments.find(z=>!z.parent&&u.get(`lab-typing:${e.page}:${z.id}`));w?e.openId=w.id:!e.draft&&u.get(`lab-typing:${e.page}:new`)&&Q()&&(e.draft={anchor:Q()})}e.loaded=!0}catch{}De()}async function ie(t){try{let l=new URL("/_lab/api/changes",new URL(d,location.href));l.search=String(new URLSearchParams({page:e.page,since:String(t)}));let w=await fetch(l,{cache:"no-store"}),z=w.ok?await w.json():{full:!0};if(z.full||!e.loaded)return me();let R=new Set(z.del),Z=new Map(z.set.map(V=>[V.id,V]));e.comments=e.comments.filter(V=>!R.has(V.id)).map(V=>Z.get(V.id)||V);let de=new Set(e.comments.map(V=>V.id));for(let V of z.set)de.has(V.id)||e.comments.push(V);e.comments.sort((V,Ee)=>V.createdAt.localeCompare(Ee.createdAt))}catch{return me()}De()}function De(){!G()&&!e.grabbing?Y():(e.openCard?.isConnected&&e.openCard.sync(),e.chatOpen&&Jt(),Ye())}e.goMode=u.get("lab-go")==="1",e.cursorMode=u.get("lab-cursor")==="1",e.overControls=u.get("lab-over")==="1";let An=()=>{Xe.textContent=e.overControls?"controls keep clicks":"pin over controls",Xe.setAttribute("aria-pressed",String(e.overControls))},Bo=t=>{e.overControls=t,u.set("lab-over",t?"1":""),An(),e.ctlTarget=null,e.recheckCtl?.(),$t()};An();let $t=()=>{let t=e.on&&!e.cursorMode&&!ho();document.documentElement.classList.toggle("lab-pinning",t),document.documentElement.classList.toggle("lab-go",t&&e.goMode&&!e.zoomMode),Me()},Qt=t=>{t&&e.zoomMode&&_e(""),e.cursorMode=t,u.set("lab-cursor",t?"1":""),he.classList.toggle("cursor",t),he.classList.toggle("on",e.goMode&&!t),nn(),$t()},en=t=>{e.cursorMode&&Qt(!1),e.zoomMode&&_e(""),e.goMode=t,queueMicrotask(nn),u.set("lab-go",t?"1":""),he.classList.toggle("on",t),he.setAttribute("aria-pressed",String(t&&!e.cursorMode)),document.documentElement.classList.toggle("lab-go",e.on&&t),ke.classList.toggle("go",t),Me()};function Lt(t){let l=u.get("lab-name").trim(),w=e.zoomMode;if(w&&(t={...t,zoom:w}),!e.goMode&&!w||!l)return e.draft={anchor:t,go:e.goMode&&!w},I(t),Y();let z=w?Tn(w):"go";if(vt())return u.set(_t(),JSON.stringify([...it(),{name:l,text:z,anchor:t}])),Y();Ve({name:l,text:z,anchor:t}).then(({comment:R,edit:Z})=>{Z&&u.set(`lab-edit:${R.id}`,Z),e.comments.push(R),ct([R]),e.posted=R.id,w&&t.block&&_n(t.block,w),Y()}).catch(()=>(e.draft={anchor:t},I(t),Y()))}async function Ve(t){let l=null;!t.action&&!t.nonce&&(t={...t,nonce:Math.random().toString(36).slice(2)+Date.now().toString(36)});for(let z=0;!l;z++)try{l=await fetch(d,{method:"POST",headers:te(),body:JSON.stringify({page:e.page,...t})})}catch{if(z>=150)throw new Error("couldn't reach the lab; your text is still here");await new Promise(R=>setTimeout(R,2e3))}let w=await l.json().catch(()=>({}));if(!l.ok)throw new Error(w.error||`could not save (${l.status})`);return w.comment&&!t.parent&&!t.action&&t.anchor?.kind!=="page"&&Ge.push(w.comment.id),w}let Ge=[];async function Po(){let t=Ge.pop(),l=t&&e.comments.find(z=>z.id===t);if(!l)return;let w=u.get(`lab-edit:${t}`);try{if(e.isAdmin)await Ve({action:"delete",id:t}),e.comments=e.comments.filter(z=>z.id!==t&&z.parent!==t);else if(w){let{comment:z}=await Ve({action:"resolve",id:t,edit:w});Object.assign(l,z)}else return void Ge.push(t)}catch{return void Ge.push(t)}e.openId===t&&(e.openId=null),Y(),zn(`took back ${l.anchor?.zoom?"a zoom":/^go$/i.test(l.text.trim())?"a go":"a pin"} \xB7 ${Ge.length?"again for the one before":"nothing more to take back"}`)}let rt={was:void 0,t:void 0};function zn(t){rt.was??=oe.textContent,oe.textContent=t,oe.hidden=!1,clearTimeout(rt.t),rt.t=setTimeout(()=>{oe.hidden=!0,oe.textContent=rt.was,rt.was=void 0},1800)}let Do=()=>new URL("/_lab/agent"+e.page,new URL(d,location.href)).href;async function qo(t,l){let w=await t;try{await navigator.clipboard.writeText(w)}catch{let R=document.createElement("textarea");R.value=w,R.style.cssText="position:fixed;opacity:0;",document.body.append(R),R.select(),document.execCommand("copy"),R.remove()}if(U.contains(l))return zn("link copied");let z=l.textContent;l.style.width=`${l.getBoundingClientRect().width}px`,l.style.justifyContent="center",l.textContent="copied",setTimeout(()=>{l.textContent=z,l.style.width=l.style.justifyContent=""},1400)}let st=()=>e.comments.filter(t=>!t.parent),_t=()=>`lab-held:${e.page}`,it=()=>{try{return JSON.parse(u.get(_t())||"[]")}catch{return[]}},Ho=()=>st().filter(t=>t.anchor?.kind!=="page").filter(t=>e.filter==="new"?lt(t).length:e.filter==="open"?!t.resolved:e.filter==="resolved"?t.resolved:Mt(t)).sort((t,l)=>t.createdAt.localeCompare(l.createdAt)),On=t=>t.anchor?.kind==="page";e.stepping=!1,e.keepKeys=!1;let Io=t=>t.resolved||Re(t)[0]==="done",tn=(t,l,w)=>{let z=N("span",{class:"kw"});return z.append(t,N("span",{class:"mn","aria-hidden":"true"},`(${l})`),w),z},Ct=null,Wo=()=>{if(Ct)return Ct;let t=Object.keys(h);if(!t.length||!T||!v)return Ct=[];let l=N("div",{class:"trying-head"},"trying"),w=t.map(z=>{let R=N("button",{class:"trying",type:"button",role:"switch","aria-checked":String(x(z))});return R.append(N("span",{class:"box","aria-hidden":"true"},x(z)?"\u2611":"\u2610"),h[z].name),R.addEventListener("click",async()=>{let Z=!x(z);h[z].on=Z,R.setAttribute("aria-checked",String(Z)),R.querySelector(".box").textContent=Z?"\u2611":"\u2610";try{await fetch(v,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({flag:z,on:Z})})}catch{}}),R});return Ct=[l,...w]};function Fo(){let t=e.on?[Ce,Pe,Xe,xe,H,...Wo()]:[];for(let w of t)w.parentNode!==U&&U.append(w);!e.on&&H.parentNode!==se&&se.insertBefore(H,ae),e.on||B.querySelector(".left").append(xe),ae.hidden=!e.on,!e.on&&!U.hidden&&ut(!1);let l=!0;for(let w of se.children)w.classList.toggle("first",l&&!w.hidden),w.hidden||(l=!1)}function nn(){let t=he.querySelector(".gp");t&&t.replaceChildren(...e.zoomMode?[Et(e.zoomMode),...matchMedia("(pointer: coarse)").matches?[]:[N("span",{class:"zw"},e.zoomMode)]]:[!e.goMode&&!e.cursorMode?dt(u.get("lab-name"))||"+":"go"]),he.setAttribute("aria-label",`a click places: ${e.zoomMode?`a zoom ${e.zoomMode}`:e.cursorMode?"nothing (pointer)":e.goMode?"go":"a comment"}`),he.setAttribute("aria-keyshortcuts",[o.comment,o.go,o.zoom,o.pointer].join(" "))}let Ko=t=>{let l=Math.max(0,Math.round((Date.now()-new Date(t).getTime())/6e4));return l<1?"just now":l<60?`${l} min`:`${Math.floor(l/60)} h ${l%60} min`};e.replyTo=null,e.newFrom=null;let on=t=>e.comments.filter(l=>!l.parent&&!l.resolved).sort((l,w)=>l.createdAt.localeCompare(w.createdAt)).indexOf(t)+1,an=()=>`lab-seen:${e.page}`,Nn=()=>new Set(u.get(an()).split(",").filter(Boolean));e.seen=Nn();let rn=t=>String(t||"").replace(/\s+/g," ").trim().toLowerCase(),Mt=t=>rn(t.name)&&rn(t.name)===rn(u.get("lab-name"))||!!u.get(`lab-edit:${t.id}`),Rn=t=>!e.seen.has(t.id)&&!Mt(t),lt=t=>[t,...ln(t.id)].filter(Rn),ct=t=>{let l=t.filter(w=>!e.seen.has(w.id)).map(w=>w.id);for(let w of t)e.seen.add(w.id);u.set(an(),[...e.seen].join(",")),l.length&&Bn(l)},Tt=a?.dataset.live?a.dataset.live.replace(/live$/,"api/reads"):"",Bn=t=>{let l=u.get("lab-name").trim();!Tt||!l||!t.length||fetch(Tt,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:l,page:e.page,ids:t})}).catch(()=>{})};async function sn(){let t=u.get("lab-name").trim();if(!Tt||!t)return;let l=e.page;try{let{ids:w}=await(await fetch(`${Tt}?name=${encodeURIComponent(t)}&page=${encodeURIComponent(l)}`,{cache:"no-store"})).json();if(l!==e.page)return;let z=new Set(w),R=[...e.seen].filter(de=>!z.has(de)),Z=w.filter(de=>!e.seen.has(de));if(R.length&&Bn(R),!Z.length)return;for(let de of Z)e.seen.add(de);u.set(an(),[...e.seen].join(",")),De()}catch{}}let ln=t=>e.comments.filter(l=>l.parent===t),dt=t=>[...String(t||"").trim()][0]?.toUpperCase()||"",jo=()=>{let t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.setAttribute("viewBox","0 0 64 64"),t.setAttribute("class","agentmark"),t.setAttribute("aria-hidden","true"),t.innerHTML='<g transform="translate(-1 -.5)" fill="currentColor"><path d="M18.9 24.67L24.4 3h11.5L31.28 21.2A22.8 22.8 0 0 0 18.9 24.67Z"/><path d="M37.07 22.02L41.9 3h11.5L47.1 27.85A22.8 22.8 0 0 0 37.07 22.02Z"/><path d="M31 26a18 18 0 0 1 18 18 18 18 0 0 1-18 18H15.57a2.57 2.57 0 0 1-2.57-2.57V44A18 18 0 0 1 31 26Z"/><circle cx="31" cy="45" r="6.2" fill="var(--_bg)"/></g>',t},Yo=t=>!!t.session||t.from==="agent",Uo=()=>(yt(0),xt.y);e.shown=null,e.posted=null;let At=matchMedia("(prefers-reduced-motion: reduce)"),pt=new Map;e.faces=new Map,e.dropDrag=null;function Y(){e.grabbing=!1,e.dropDrag?.();let t=J.querySelector(".card:not(.out), .float:not(.out)"),l=e.stepping&&re&&t?t.offsetHeight:0,w=t?.querySelector(".body"),z=w?w.scrollTop:null,R=w?w.scrollHeight-w.scrollTop-w.clientHeight<48:!1,Z=new Map(e.on?st().filter(L=>L.anchor?.kind!=="page").map(L=>[L.id,je(L.anchor||{})]):[]);J.replaceChildren(),pt.clear();let de=e.on?e.draft||e.openId:null,V=de!==e.shown,Ee=V?" in":"",Te=null,et=()=>{if(e.closeFast&&!de&&t){e.closeFast=!1,t.inert=!0,J.append(t);let L=()=>t.remove();At.matches||!t.animate?L():t.animate([{opacity:1},{opacity:0}],{duration:120,easing:"ease-out",fill:"forwards"}).finished.then(L,L)}else if(re&&!de&&e.shown&&t&&!At.matches&&!t.style.transform){t.classList.remove("in"),t.classList.add("out"),t.inert=!0,J.append(t);let L=e.posted&&pt.get(e.posted),ne=L?.getBoundingClientRect();L&&(L.style.animationDelay="250ms");let $e=wn(t,0,ne&&{x:ne.left+ne.width/2,y:ne.top+ne.height/2});setTimeout(()=>(t.remove(),kn(t),t.classList.contains("float")&&Sn()),$e)}if(re&&t?.classList.contains("float")&&!t.classList.contains("out")&&!B.querySelector(".float:not(.out)")&&setTimeout(Sn,320),re){let L=B.querySelector(".card:not(.out), .float:not(.out)")||(e.listOpen?y:e.chatOpen?P:null),ne=L&&(e.draft?"draft":e.openId||(e.listOpen?"list":e.chatOpen?"chat":""));L&&ne!==e.sheetKey&&vn(L),e.sheetKey=ne,V&&e.draft&&requestAnimationFrame(So)}Ft(Te),e.shown=de,e.posted=null},He=st(),Dt=He.filter(L=>!L.resolved&&L.anchor?.kind!=="page").length,qt=He.filter(L=>!L.resolved&&L.anchor?.kind!=="page").reduce((L,ne)=>L+lt(ne).length,0);if(H.replaceChildren(document.createTextNode((e.on?"hide comments":Dt?`comments \xB7 ${Dt}`:"comments")+(!e.on&&qt?` \xB7 ${qt} new`:"")),N("kbd",{"aria-hidden":"true"},o.toggle)),H.classList.toggle("secondary",e.on),D.toggleAttribute("data-sheet",!!(e.on&&(e.draft||e.openId||e.listOpen||e.chatOpen))),re&&V&&de&&(D.setAttribute("data-opening",""),requestAnimationFrame(()=>requestAnimationFrame(()=>D.removeAttribute("data-opening")))),document.documentElement.classList.toggle("lab-sheet",D.hasAttribute("data-sheet")),En(),e.refit(),$t(),xe.hidden=!e.on||!e.isAdmin||He.every(L=>L.resolved),Ye(),Jt(),Mn(),!e.on)return et();for(let L of it()){let{left:ne,top:$e}=je(L.anchor),be=N("div",{class:"pin held",title:`${L.name}: ${L.text} \xB7 draft, not sent yet`},dt(L.name));be.style.left=`${ne}px`,be.style.top=`${$e}px`,J.append(be)}if(He.forEach(L=>{if(On(L)||!e.showDone&&e.openId!==L.id&&(L.resolved||Re(L)[0]==="done")&&!lt(L).length)return;let{left:ne,top:$e,moved:be,zone:ee}=Z.get(L.id)||je(L.anchor||{});e.openId===L.id&&Kt(ee,`saved${Ee}`);let ve=lt(L),Ae=!ee&&(e.isAdmin||u.get(`lab-edit:${L.id}`)),[Se]=Re(L),le=N("button",{class:`pin${/^go$/i.test(L.text.trim())?" go":""}${L.anchor?.zoom?" zoom":""}${L.resolved?" resolved":""}${Se==="done"?" done":""}${Se==="now"?" working":""}${ve.length?" new":""}${be?" moved":""}${e.posted===L.id?" in":""}${Ae?" grab":""}${e.openId===L.id?" open":""}`,type:"button",title:`${L.resolved?"":`${on(L)} \xB7 `}${L.name}${be?" \xB7 the spot it was pinned to has changed":""}${Ae?" \xB7 drag to move":""}`,"aria-label":`${/^go$/i.test(L.text.trim())?"go":L.anchor?.zoom?`zoom ${L.anchor.zoom}`:"comment"}${L.resolved?"":` ${on(L)}`} by ${L.name}${Se==="now"?", agent working on it":Se==="done"||L.resolved?", done":""}${ve.length?`, ${ve.length} new`:""}${be?", moved":""}`},Se==="done"||L.resolved?"\u2713":/^go$/i.test(L.text.trim())?"go":L.anchor?.zoom?Et(String(L.anchor.zoom).startsWith("in")?"in":"out"):x("agentPins")&&Yo(L)?jo():dt(L.name)),Ie=`${Se}${L.resolved?" resolved":""}${ve.length?" new":""}`,We=e.faces.get(L.id);e.faces.set(L.id,Ie);let fn=We!==void 0&&We!==Ie&&!At.matches;if(fn&&le.classList.add("swap"),Se==="now"?le.append(N("i",{class:`ring${fn&&!We.startsWith("now")?" come":""}`,"aria-hidden":"true"})):fn&&We.startsWith("now")&&le.append(N("i",{class:"ring gone","aria-hidden":"true"})),re&&le.append(N("i",{class:"hit","aria-hidden":"true"})),le.style.left=`${ne}px`,le.style.top=`${$e}px`,Ae&&Mo(le,L),!re&&ee&&e.openId!==L.id){let ge=null;le.addEventListener("pointerenter",()=>ge=Kt(ee,"saved")),le.addEventListener("pointerleave",()=>(ge?.remove(),ge=null))}else!re&&L.anchor?.quote&&!ee&&(le.addEventListener("pointerenter",()=>Ft(L.anchor)),le.addEventListener("pointerleave",()=>Ft(Te)));if(le.addEventListener("click",ge=>{if(ge.stopPropagation(),!le.dataset.dragged){if(re&&e.openId!==L.id)return nt(L);e.openId=e.openId===L.id?null:L.id,e.draft=null,Y()}}),J.append(le),pt.set(L.id,le),e.openId===L.id){let ge=To(L,new Set(ve.map(Le=>Le.id)),V&&(re?e.keepKeys:!e.stepping||e.keepKeys));if(e.openCard=ge,V&&!e.stepping&&ge.classList.add("in"),l&&(ge.style.minHeight=`min(${l}px, var(--_sheet-max))`),e.stepping=e.keepKeys=!1,Ln(ge,ee?ne+14:ne,ee?ee.top+ee.height:$e),!V&&z!=null){let Le=ge.querySelector(".body");Le.scrollTop=R?Le.scrollHeight:z}else if(V){let Le=ge.querySelector(".body"),Vn=re?null:Le.querySelector(".fresh, .newline");Le.scrollTop=Vn?Vn.offsetTop-Le.offsetTop-8:Le.scrollHeight}re&&e.cardFull&&ge.classList.add("full"),St(ge,()=>(e.openId=null,e.cardFull=!1,Y()),!0),ct(ve),ve.length&&Ye(),Te=ee?null:L.anchor}}),e.draft){let{anchor:L}=e.draft,{left:ne,top:$e,zone:be}=je(L);Kt(be,"draft"),Te=be?null:L;let ee=L.zoom,ve=N("div",{class:`pin draft${ee?" zoom":""}${Ee}`},ee?Et(ee):dt(u.get("lab-name")));ve.style.left=`${ne}px`,ve.style.top=`${$e}px`,J.append(ve);let Ae=N("div",{class:`float${Ee}`});Ae.append(N("div",{class:"handle"}),xn({placeholder:ee==="in"?"zoom in: what to go deeper into (or just send)":ee==="out"?"zoom out: what to see around it (or just send)":e.draft.go?"go":"add a comment",empty:ee?Tn(ee):e.draft.go?"go":"",nameFirst:!!(e.draft.go||ee),autofocus:!0,draftKey:`lab-typing:${e.page}:new`,onSubmit:async(Se,le)=>{if(vt())return u.set(_t(),JSON.stringify([...it(),{name:Se,text:le,anchor:L}])),e.draft=null,I(null),Y();let{comment:Ie,edit:We}=await Ve({name:Se,text:le,anchor:L});We&&u.set(`lab-edit:${Ie.id}`,We),ee&&L.block&&_n(L.block,ee),e.comments.push(Ie),ct([Ie]),e.draft=null,I(null),e.openId=null,e.posted=Ie.id,ko(),Y()}})),St(Ae,()=>(e.draft=null,I(null),Y())),be?Ln(Ae,ne+14,be.top+be.height):Co(Ae,ne,$e)}et()}e.grabbing=!1,e.openCard=null;let re=matchMedia("(pointer: coarse)").matches,Pn=()=>{u.get("lab-hint-seen")!=="1"&&(oe.hidden=!1,u.set("lab-hint-seen","1"),setTimeout(()=>oe.hidden=!0,5e3))},Dn=t=>{e.on=t,e.on?Me():ke.classList.remove("show"),u.set("lab-on",e.on?"1":"0"),e.on&&Pn(),e.draft=null,e.openId=null,Y()};H.addEventListener("click",()=>Dn(!e.on));function ut(t,l=!1){U.hidden=!t,ae.setAttribute("aria-expanded",String(t)),t?[...U.querySelectorAll("button")].find(w=>!w.hidden&&!w.disabled)?.focus({preventScroll:!0}):l&&ae.focus({preventScroll:!0})}ae.addEventListener("click",t=>{t.stopPropagation(),ut(U.hidden)}),U.addEventListener("click",()=>setTimeout(()=>ut(!1,!0),0)),addEventListener("pointerdown",t=>{!U.hidden&&!t.composedPath().some(l=>l===U||l===ae)&&ut(!1)},!0),addEventListener("keydown",t=>{t.key==="Escape"&&!U.hidden&&(ut(!1,!0),t.stopPropagation())},!0),he.addEventListener("click",()=>{if(e.zoomMode==="in")return _e("out");if(e.zoomMode==="out")return _e(""),en(!1);if(e.goMode&&!e.cursorMode)return _e("in");en(!0)}),Ue.addEventListener("click",()=>ot(-1)),Ce.addEventListener("click",()=>Be.click()),e.paused=null;let Xo=t=>{let l=t.effect?.target;return!!l&&l.getRootNode()!==B},qn=()=>{for(let t of document.getAnimations())!Xo(t)||t.playState!=="running"||(t.pause(),e.paused.anims.add(t));for(let t of document.querySelectorAll("video"))t.paused||(t.pause(),e.paused.videos.add(t))};Xe.addEventListener("click",()=>Bo(!e.overControls)),Pe.addEventListener("click",()=>{if(e.paused){clearInterval(e.paused.timer);for(let t of e.paused.anims)t.play();for(let t of e.paused.videos)t.play().catch(()=>{});e.paused=null}else e.paused={anims:new Set,videos:new Set,timer:setInterval(qn,100)},qn();Pe.textContent=e.paused?"play motion":"pause motion",Pe.setAttribute("aria-pressed",String(!!e.paused))}),Be.addEventListener("click",()=>{e.showDone=!e.showDone,u.set("lab-show-done",e.showDone?"1":""),Y()}),Ze.addEventListener("click",()=>ot(1));let zt=()=>{e.on||(e.on=!0,u.set("lab-on","1"))};xe.addEventListener("click",()=>qo(Do(),xe)),addEventListener("lab-goto",t=>{let l=document.getElementById(t.detail);l&&(re&&(e.openId=null,e.chatOpen=!1,e.listOpen=!1,Y()),setTimeout(()=>Cn(l),re?60:0))}),ye.addEventListener("click",()=>at?(e.listOpen=!e.listOpen,e.listOpen&&(e.filter="new"),e.chatOpen=!1,oe.hidden=!0,Y()):ot(1)),y.querySelector(".x").addEventListener("click",()=>Xt(y,()=>(e.listOpen=!1,Y()))),W.addEventListener("click",()=>{e.chatOpen=!e.chatOpen,e.listOpen=!1,e.chatOpen&&!re&&(e.openId=null,e.draft&&!B.querySelector(".float textarea")?.value.trim()&&(e.draft=null)),oe.hidden=!0,Y(),e.chatOpen&&!re&&P.querySelector(".chat textarea")?.focus({preventScroll:!0})}),e.closingClick=!1,document.addEventListener("pointerdown",t=>{if(e.closingClick=!1,re||!e.chatOpen||t.button!==0)return;let l=t.composedPath();if(!(l.includes(P)||l.includes(W))){if(e.chatOpen=!1,l.includes(D))return void addEventListener("click",()=>Y(),{once:!0});e.closingClick=!0,Y()}},!0),addEventListener("click",t=>{e.closingClick&&(e.closingClick=!1,t.preventDefault(),t.stopImmediatePropagation())},!0);for(let t of y.querySelectorAll("[data-f]"))t.addEventListener("click",()=>(e.filter=t.dataset.f,Ye()));A.addEventListener("click",()=>(u.set("lab-hold",vt()?"":"1"),Ye())),Je.addEventListener("click",async()=>{let t=it();for(let l=0;l<t.length;l++)try{let{comment:w,edit:z}=await Ve(t[l]);z&&u.set(`lab-edit:${w.id}`,z),e.comments.push(w),ct([w]),u.set(_t(),JSON.stringify(t.slice(l+1)))}catch{Je.textContent="send failed, try again";return}Y()});let Qe=t=>t.composedPath().some(l=>l instanceof HTMLElement&&(l.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(l.tagName)));document.addEventListener("keydown",t=>{if(e.gone)return;let l=document.activeElement?.localName.includes("-")&&document.activeElement!==D;if(r(t)==="toggle"&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.repeat&&!Qe(t)&&!l){t.preventDefault(),Dn(!e.on);return}if(e.on&&(t.metaKey||t.ctrlKey)&&!t.shiftKey&&!t.altKey&&(/^z$/i.test(t.key||"")||!/^[a-z]$/i.test(t.key||"")&&t.code==="KeyZ")&&!Qe(t)&&!l&&Ge.length)return t.preventDefault(),void Po();if(e.on&&t.ctrlKey&&!t.metaKey&&!t.altKey&&t.code==="KeyD"&&!(Qe(t)&&!t.composedPath().includes(D))){t.preventDefault();let R=B.querySelector(".card textarea, .float textarea");return R?.value.trim()?R.closest(".card, .float")?.animate([{transform:"none"},{transform:"translateX(-6px)"},{transform:"translateX(6px)"},{transform:"none"}],{duration:260}):ot(t.shiftKey?-1:1)}let w=r(t);if(e.on&&["comment","go","zoom","pointer"].includes(w)&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.repeat&&!Qe(t)&&!l){if(t.preventDefault(),w==="zoom")return _e(e.zoomMode==="in"?"out":"in");e.zoomMode&&_e(""),w==="pointer"?Qt(!0):en(w==="go");return}let z=/^[a-z]$/i.test(t.key||"")?t.key.toLowerCase():/^Key[A-Z]$/.test(t.code||"")?t.code.slice(3).toLowerCase():"";if(e.on&&e.zoomMode&&!e.draft&&!e.openId&&!Qe(t)&&!l&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.repeat&&No(t,z))return t.preventDefault();if(e.on&&!Qe(t)&&!l&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.repeat&&["pause","chat","next","done","reply","resolve"].includes(w)){let R=w;if(t.preventDefault(),R==="pause")return Pe.click();if(R==="chat")return W.click();if(R==="next")return ot(t.shiftKey?-1:1);if(R==="done")return Be.click();R==="reply"&&e.openId?B.querySelector(".card textarea")?.focus({preventScroll:!0}):R==="resolve"&&e.openId&&e.isAdmin&&[...B.querySelectorAll(".card .btn")].find(Z=>/^(resolve|reopen)$/.test(Z.textContent))?.click();return}t.key==="Escape"&&(e.draft||e.openId)?(e.draft=null,e.openId=null,Y()):t.key==="Escape"&&(e.chatOpen||e.listOpen)&&(e.chatOpen?e.chatOpen=!1:e.listOpen=!1,Y())});let Hn='a, button, input, textarea, select, label, summary, video[controls], audio, iframe, [contenteditable], [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="option"], [role="checkbox"], [role="switch"], [tabindex]:not([tabindex="-1"]), [onclick]',In=t=>document.documentElement.classList.toggle("lab-ctl",!e.overControls&&!D.contains(t)&&t!==D&&Ot(t));e.recheckCtl=()=>e.mouse&&In(document.elementFromPoint(e.mouse.x,e.mouse.y));let Ot=t=>{if(e.overControls)return!1;for(let l=t instanceof Element?t:null;l&&l!==document.body&&l!==document.documentElement;l=l.parentElement)if(l.matches(Hn)||getComputedStyle(l).cursor==="pointer")return!0;return!1},fe="[data-uncommentable]";e.drag=null,e.afterDrag=!1,e.liveZone=null,e.zoneFrame=0;let Nt=12,Zo=()=>{if(e.zoneFrame=0,!e.drag?.active||!e.liveZone)return;let t=(z,R)=>{let Z=Math.max(Math.abs(R-z),Nt);return{start:(z+R)/2-Z/2,size:Z}},l=t(e.drag.x0,e.drag.x1),w=t(e.drag.y0,e.drag.y1);e.liveZone.style.transform=`translate3d(${l.start+scrollX}px, ${w.start+scrollY}px, 0)`,e.liveZone.style.width=`${l.size}px`,e.liveZone.style.height=`${w.size}px`},Wn=()=>!!e.draft&&[...B.querySelectorAll(".float textarea")].some(t=>t.value.trim());function Jo(t){!e.on&&!t.altKey||e.cursorMode&&!t.altKey||Wn()||t.button!==0||t.pointerType==="touch"||t.metaKey||t.ctrlKey||t.shiftKey||t.composedPath().includes(D)||!t.altKey&&Ot(t.target)||t.target instanceof Element&&t.target.closest(fe)||(e.drag={x0:t.clientX,y0:t.clientY,x1:t.clientX,y1:t.clientY,active:!1})}document.addEventListener("pointerdown",t=>{t.altKey||!e.on&&!t.altKey||e.cursorMode&&!t.altKey||Wn()||t.button!==0||t.pointerType==="touch"||t.metaKey||t.ctrlKey||t.shiftKey||t.composedPath().includes(D)||!t.altKey&&Ot(t.target)||t.target instanceof Element&&t.target.closest(fe)||(e.drag={x0:t.clientX,y0:t.clientY,x1:t.clientX,y1:t.clientY,active:!1})},!0),document.addEventListener("pointermove",t=>{e.drag&&(e.drag.x1=t.clientX,e.drag.y1=t.clientY,!e.drag.active&&Math.hypot(e.drag.x1-e.drag.x0,e.drag.y1-e.drag.y0)>8&&(e.drag.active=!0,getSelection?.()?.removeAllRanges(),document.documentElement.classList.add("lab-dragging"),e.liveZone=bn("draft live"),J.append(e.liveZone)),e.drag.active&&(t.preventDefault(),e.zoneFrame||=requestAnimationFrame(Zo)))},!0);let cn=t=>{if(!e.drag)return;let l=e.drag;if(e.drag=null,document.documentElement.classList.remove("lab-dragging"),cancelAnimationFrame(e.zoneFrame),e.zoneFrame=0,e.liveZone?.remove(),e.liveZone=null,!(!l.active||t.type==="pointercancel")){e.afterDrag=!0,setTimeout(()=>e.afterDrag=!1,0),getSelection?.()?.removeAllRanges();for(let[w,z]of[["x0","x1"],["y0","y1"]]){if(Math.abs(l[z]-l[w])>=Nt)continue;let R=(l[w]+l[z])/2;l[w]=R-Nt/2,l[z]=R+Nt/2}zt(),e.openId=null,Lt(fo(l))}};document.addEventListener("pointerup",cn,!0),document.addEventListener("pointercancel",cn,!0),document.addEventListener("dragstart",t=>{let l=e.on&&t.target instanceof Element&&t.target.closest("img, video")&&!t.composedPath().includes(D);(e.drag||l)&&t.preventDefault()},!0),document.addEventListener("click",t=>{e.afterDrag&&(t.preventDefault(),t.stopPropagation())},!0);let Fn=t=>t.altKey&&!t.metaKey&&!t.ctrlKey&&t.button===0&&!t.composedPath().includes(D)&&!(t.target instanceof Element&&t.target.closest(fe));for(let t of["pointerdown","mousedown","pointerup","mouseup"])addEventListener(t,l=>{Fn(l)&&(l.preventDefault(),l.stopImmediatePropagation(),t==="pointerdown"&&Jo(l),t==="pointerup"&&cn(l))},!0);addEventListener("click",t=>{Fn(t)&&(t.preventDefault(),t.stopImmediatePropagation(),e.afterDrag||Un(t))},!0),e.ctlClick=!1,addEventListener("click",t=>e.ctlClick=Ot(t.target),!0),document.addEventListener("click",t=>Un(t)),e.lastTouch=0,e.pinnedByHold=!1;let mt=B.querySelector(".sel-chip"),dn=B.querySelector(".scrim"),Kn=()=>B.querySelector(".card:not(.out), .float:not(.out)")||(e.listOpen?y:e.chatOpen?P:null),Vo=()=>{e.draft=null,e.openId=null,e.listOpen=!1,e.chatOpen=!1,Y()},jn=()=>{let t=Kn();if(![...B.querySelectorAll("textarea")].some(l=>l.value.trim()&&!P.contains(l)))return Xt(t,Vo);t?.animate?.([{transform:"none"},{transform:"translateY(12px)"},{transform:"none"}],{duration:260,easing:"ease-out"})};e.sheetDraggedAt=-1e9,dn.addEventListener("click",()=>performance.now()-e.sheetDraggedAt>300&&jn()),dn.addEventListener("touchmove",t=>t.preventDefault(),{passive:!1}),e.backWatcher=null;let Go=window.visualViewport;Eo();let qe=F(".msgs",P);e.stick=!0,qe.addEventListener("scroll",()=>e.stick=qe.scrollHeight-qe.scrollTop-qe.clientHeight<48,{passive:!0}),"ResizeObserver"in window&&new ResizeObserver(()=>e.stick&&(qe.scrollTop=qe.scrollHeight)).observe(qe),St(y,()=>(e.listOpen=!1,Y())),St(P,()=>(e.chatOpen=!1,Y()),!0),e.press=null;let ft=()=>e.press&&(clearTimeout(e.press.timer),e.press=null),Rt=t=>{let l=document.documentElement;if(t)return l.classList.add("lab-press");l.classList.contains("lab-press")&&requestAnimationFrame(()=>{l.classList.remove("lab-press");let w=window.CSS?.highlights?.get("lab-quote");w&&CSS.highlights.set("lab-quote",new Highlight(...w))})};document.addEventListener("pointerdown",t=>{if(ft(),e.pinnedByHold=!1,t.pointerType==="touch"&&(e.lastTouch=Date.now()),t.pointerType!=="touch"||e.draft||!(t.target instanceof Element)||t.composedPath().includes(D)||t.target.closest(fe))return;let{clientX:l,clientY:w}=t;Rt(!0),e.press={x:l,y:w,timer:setTimeout(()=>{e.press=null,e.pinnedByHold=!0,navigator.vibrate?.(8),getSelection?.()?.removeAllRanges(),e.afterDrag=!0,setTimeout(()=>e.afterDrag=!1,800),zt(),e.openId=null,Lt(Ke(l,w))},400)}},!0),document.addEventListener("pointermove",t=>e.press&&Math.hypot(t.clientX-e.press.x,t.clientY-e.press.y)>10&&ft(),!0),document.addEventListener("pointerup",t=>{t.pointerType==="touch"&&(e.lastTouch=Date.now()),ft(),Rt(!1),e.pinnedByHold&&(B.querySelector(".float [data-first]")||B.querySelector(".float textarea"))?.focus({preventScroll:!0})},!0),document.addEventListener("touchend",t=>{Rt(!1),e.pinnedByHold&&(e.pinnedByHold=!1,t.preventDefault(),(B.querySelector(".float [data-first]")||B.querySelector(".float textarea"))?.focus({preventScroll:!0}))},{capture:!0,passive:!1}),document.addEventListener("pointercancel",()=>(ft(),Rt(!1)),!0),addEventListener("scroll",ft,{passive:!0,capture:!0}),document.addEventListener("contextmenu",t=>(e.press||e.afterDrag)&&t.preventDefault(),!0),e.selRect=null,document.addEventListener("selectionchange",()=>{let t=getSelection?.(),l=t?.rangeCount&&t.getRangeAt(0),w=String(t||"").trim(),z=l&&D.contains(l.commonAncestorContainer);if(e.selRect=re&&e.on&&!e.draft&&w&&l&&!z?l.getClientRects()[0]||l.getBoundingClientRect():null,mt.hidden=!e.selRect,!e.selRect)return;let R=e.selRect.bottom+52<innerHeight;mt.style.left=`${Math.min(Math.max(e.selRect.left+e.selRect.width/2,60),innerWidth-60)}px`,mt.style.top=`${R?e.selRect.bottom+10:Math.max(e.selRect.top-46,8)}px`});let Yn=()=>{let t=getSelection?.(),l=t?.rangeCount&&t.getRangeAt(0),w=String(t||"").replace(/\s+/g," ").trim();if(!l||!w||D.contains(l.commonAncestorContainer))return!1;let z=l.getClientRects(),R=z[0]||l.getBoundingClientRect(),Z=z[z.length-1]||R,de=l.startContainer.nodeType===1?l.startContainer:l.startContainer.parentElement,V=l.endContainer.nodeType===1?l.endContainer:l.endContainer.parentElement,Ee=de&&(de===V||de.contains(V))?Ke(Math.max(Z.left,Z.right-2),Z.top+Z.height/2):Ke(R.left+2,R.top+R.height/2),Te=l.commonAncestorContainer,et=(Te.nodeType===1?Te:Te.parentElement)?.closest("p, li, h1, h2, h3, h4, h5, h6, td, th, figcaption, blockquote, pre, section, article, div")||document.body,He=(Dt,qt)=>{let L=document.createRange();return L.setStart(...Dt),L.setEnd(...qt),String(L).replace(/\s+/g," ")};return Ee.kind="text",Ee.quote={exact:X(w,300),prefix:He([et,0],[l.startContainer,l.startOffset]).replace(/^\s+/,"").slice(-40),suffix:He([l.endContainer,l.endOffset],[et,et.childNodes.length]).replace(/\s+$/,"").slice(0,40)},t.removeAllRanges(),mt.hidden=!0,zt(),e.openId=null,Lt(Ee),!0};mt.addEventListener("click",t=>{t.stopPropagation(),e.selRect&&Yn()}),document.addEventListener("mouseup",t=>{e.on&&!e.cursorMode&&!e.draft&&t.shiftKey&&t.button===0&&!t.composedPath().includes(D)&&setTimeout(Yn,0)},!0);function Un(t){if(!t.composedPath().includes(D)){if(e.draft||e.openId){if([...B.querySelectorAll("textarea")].some(l=>l.value.trim()))return;e.draft=null,e.openId=null,Y();return}if(!(!e.on&&!t.altKey||e.cursorMode&&!t.altKey||t.button!==0||t.metaKey||t.ctrlKey||t.shiftKey)&&!(e.lastTouch&&Date.now()-e.lastTouch<800)){if(t.altKey)t.preventDefault();else if(t.defaultPrevented||e.ctlClick)return;t.target instanceof Element&&t.target.closest(fe)||String(getSelection?.()||"").trim()||(zt(),Lt(Ke(t.clientX,t.clientY)))}}}let Qo=()=>{let t=st().filter(w=>w.anchor?.kind!=="page");if(!e.on||e.openId||t.length!==pt.size)return Y();let l=t.map(w=>[pt.get(w.id),je(w.anchor||{})]);if(l.some(([w])=>!w))return Y();for(let[w,{left:z,top:R,moved:Z}]of l)w.style.left=`${z}px`,w.style.top=`${R}px`,w.classList.toggle("moved",!!Z)};e.frame=0;let Bt=()=>{cancelAnimationFrame(e.frame),e.frame=requestAnimationFrame(()=>{e.draft||B.activeElement||e.grabbing||Qo()})};addEventListener("resize",Bt),addEventListener("scroll",t=>t.target!==document&&!D.contains(t.target)&&Bt(),{capture:!0,passive:!0});let pn=()=>{e.gone||(!D.isConnected&&document.body&&document.body.append(D),ue.isConnected||document.head.append(ue),gt.isConnected||document.head.append(gt),k()!==e.page&&(e.page=k(),e.seen=Nn(),sn(),e.comments=[],e.draft=null,e.openId=null,Y(),me()))};for(let t of["pushState","replaceState"]){let l=history[t];history[t]=function(...w){let z=l.apply(this,w);return queueMicrotask(pn),z}}addEventListener("popstate",pn),document.addEventListener("astro:after-swap",pn),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&!e.draft&&!B.activeElement&&me()}),"ResizeObserver"in window&&new ResizeObserver(Bt).observe(document.body);let ue=document.createElement("style");a?.dataset.fontUrl&&(ue.textContent=`@font-face{font-family:'lab comments';font-display:swap;src:url('${new URL(a.dataset.fontUrl,a.src||location.href)}') format('woff2');}`);let Xn=a?.dataset.fontUrl?"lab comments":a?.dataset.font;Xn&&D.style.setProperty("--lab-font",`'${Xn.replace(/'/g,"")}', system-ui, sans-serif`);let gt=document.createElement("style"),ke=N("div",{class:"ptr","aria-hidden":"true"});ke.append(N("span",{class:"ini"},"+"),N("span",{class:"tick"},"go")),B.append(ke),e.mouse=null;let Zn=(t,l,w)=>{let z=!!w&&w!==D&&!D.contains(w)&&getComputedStyle(w).cursor==="none";ke.classList.toggle("show",z),ke.classList.toggle("go",e.goMode&&!e.zoomMode),ke.style.transform=`translate(${t-1}px, ${l-27}px)`},Me=()=>e.mouse&&requestAnimationFrame(()=>e.mouse&&Zn(e.mouse.x,e.mouse.y,document.elementFromPoint(e.mouse.x,e.mouse.y)));addEventListener("pointermove",t=>{if(t.pointerType!=="mouse")return;document.documentElement.classList.add("lab-drawn"),e.mouse={x:t.clientX,y:t.clientY};let l=t.composedPath()[0];l!==e.ctlTarget&&(e.ctlTarget=l,In(l)),Zn(t.clientX,t.clientY,l instanceof Element?l:null)},{capture:!0,passive:!0}),addEventListener("scroll",Me,{capture:!0,passive:!0}),addEventListener("keydown",t=>(t.key==="Shift"||t.key==="Alt")&&Me(),!0),addEventListener("keyup",t=>(t.key==="Shift"||t.key==="Alt")&&Me(),!0),document.documentElement.addEventListener("mouseleave",()=>(e.mouse=null,ke.classList.remove("show"))),addEventListener("blur",()=>(e.mouse=null,ke.classList.remove("show"))),e.cursorKey="";function un(){let t=e.zoomMode?`zoom-${e.zoomMode}`:(dt(u.get("lab-name"))||"+").replace(/[<>&'"]/g,"");if(t===e.cursorKey)return;e.cursorKey=t,ke.querySelector(".ini").replaceChildren(e.zoomMode?Et(e.zoomMode):t);let l=`:not(${Hn}, a *, button *, label *, [role="button"] *, [contenteditable], [contenteditable] *, ${fe}, ${fe} *, [data-lab-comments])`,w="dialog, dialog *, [popover], [popover] *, :fullscreen, :fullscreen *";gt.textContent=`@layer lab-pointer { html.lab-pinning:not(.lab-shift, .lab-ctl) body, html.lab-pinning:not(.lab-shift, .lab-ctl) body *${l} { cursor: crosshair; } html.lab-drawn.lab-pinning:not(.lab-shift, .lab-ctl):not(.lab-dragging) body, html.lab-drawn.lab-pinning:not(.lab-shift, .lab-ctl):not(.lab-dragging) body *${l}:not(${w}) { cursor: none; } html.lab-pinning body :is([contenteditable], [contenteditable] *) { cursor: text; } html.lab-pinning body :is(${fe}, ${fe} *) { cursor: auto; } }html.lab-alt body, html.lab-alt body *:not([data-lab-comments], [data-lab-comments] *, ${fe}, ${fe} *) { cursor: crosshair !important; }html.lab-drawn.lab-alt body, html.lab-drawn.lab-alt body *:not([data-lab-comments], [data-lab-comments] *, ${fe}, ${fe} *, ${w}) { cursor: none !important; }html.lab-go:not(.lab-drawn) body, html.lab-go:not(.lab-drawn) body * { cursor: copy !important; }`}ue.textContent+="@media (pointer: fine) { html.lab-pinning:not(.lab-shift) body > :not([data-lab-comments]), html.lab-pinning:not(.lab-shift) body > :not([data-lab-comments]) :not(input, textarea, select, [contenteditable], [contenteditable] *) { -webkit-user-select: none; user-select: none; } }",e.shiftOff=0;let mn=t=>{clearTimeout(e.shiftOff),t.shiftKey?document.documentElement.classList.add("lab-shift"):e.shiftOff=setTimeout(()=>(document.documentElement.classList.remove("lab-shift"),Me()),400)};addEventListener("keydown",mn,!0),addEventListener("keyup",mn,!0),addEventListener("pointerdown",t=>{if(t.shiftKey)return mn(t);clearTimeout(e.shiftOff),document.documentElement.classList.remove("lab-shift")},!0),addEventListener("blur",()=>document.documentElement.classList.remove("lab-shift")),ue.textContent+="html.lab-dragging, html.lab-dragging * { user-select: none !important; -webkit-user-select: none !important; cursor: crosshair !important; }",ue.textContent+="html.lab-sheet, html.lab-sheet body { overscroll-behavior-y: none; }",ue.textContent+='@property --lab-arc { syntax: "<percentage>"; inherits: false; initial-value: 66%; }',ue.textContent+="html.lab-room body::after { content: ''; display: block; height: var(--lab-room, 0px); }",addEventListener("scroll",()=>{let t=document.documentElement,l=parseFloat(t.style.getPropertyValue("--lab-room"))||0;if(!l||D.hasAttribute("data-sheet"))return;let w=Math.max(0,Math.ceil(scrollY+innerHeight-(t.scrollHeight-l)));w>=l||(t.style.setProperty("--lab-room",`${w}px`),w||t.classList.remove("lab-room"))},{passive:!0}),ue.textContent+="@media (pointer: coarse) { html.lab-sheet, html.lab-sheet body { overflow: hidden; } }",ue.textContent+="html.lab-pinning body, html.lab-pinning body * { -webkit-touch-callout: none; }",ue.textContent+="@media (pointer: coarse) { html.lab-pinning.lab-press body > :not([data-lab-comments]) { -webkit-user-select: none; user-select: none; } html.lab-pinning body > :not([data-lab-comments]), html.lab-pinning body > :not([data-lab-comments]) * { -webkit-user-drag: none; } }";let Pt=t=>document.documentElement.classList.toggle("lab-alt",!!t);addEventListener("keydown",t=>t.key==="Alt"&&Pt(!0),!0),addEventListener("keyup",t=>t.key==="Alt"&&Pt(!1),!0),addEventListener("pointermove",t=>Pt(t.altKey),{capture:!0,passive:!0}),addEventListener("blur",()=>Pt(!1));let Jn=()=>{document.head.append(ue,gt),un(),e.on&&Pn(),document.body.append(D);let t="background-color: rgba(52, 199, 89, .3); color: inherit;";ue.textContent+=`html.lab-pinning ::selection { ${t} } ::highlight(lab-quote) { ${t} }`,me()};document.body?Jn():document.addEventListener("DOMContentLoaded",Jn),Ro(),zo()})();})();
|