pinwright 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +245 -2
- package/dist/agent.d.ts +16 -0
- package/dist/agent.js +292 -0
- package/dist/astro.d.ts +16 -0
- package/dist/astro.js +29 -0
- package/dist/bus.d.ts +16 -0
- package/dist/bus.js +13 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +125 -0
- package/dist/cloudflared.d.ts +10 -0
- package/dist/cloudflared.js +98 -0
- package/dist/collab.d.ts +56 -0
- package/dist/collab.js +183 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.js +59 -0
- package/dist/context.d.ts +18 -0
- package/dist/context.js +11 -0
- package/dist/db.d.ts +2 -0
- package/dist/db.js +74 -0
- package/dist/guard.d.ts +26 -0
- package/dist/guard.js +137 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +70 -0
- package/dist/inject.d.ts +7 -0
- package/dist/inject.js +82 -0
- package/dist/locks.d.ts +14 -0
- package/dist/locks.js +51 -0
- package/dist/next-script.d.ts +6 -0
- package/dist/next-script.js +12 -0
- package/dist/next.d.ts +10 -0
- package/dist/next.js +28 -0
- package/dist/nuxt.d.ts +18 -0
- package/dist/nuxt.js +17 -0
- package/dist/ops.d.ts +39 -0
- package/dist/ops.js +146 -0
- package/dist/planner.d.ts +10 -0
- package/dist/planner.js +65 -0
- package/dist/plugin.d.ts +13 -0
- package/dist/plugin.js +58 -0
- package/dist/rebuild.d.ts +23 -0
- package/dist/rebuild.js +67 -0
- package/dist/scheduler.d.ts +26 -0
- package/dist/scheduler.js +150 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +355 -0
- package/dist/shots.d.ts +25 -0
- package/dist/shots.js +86 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +159 -0
- package/dist/tools.d.ts +11 -0
- package/dist/tools.js +27 -0
- package/dist/vite.d.ts +33 -0
- package/dist/vite.js +37 -0
- package/dist/webpack.d.ts +36 -0
- package/dist/webpack.js +58 -0
- package/dist/ws.d.ts +25 -0
- package/dist/ws.js +115 -0
- package/overlay/overlay.js +1379 -0
- package/package.json +59 -4
|
@@ -0,0 +1,1379 @@
|
|
|
1
|
+
// pinwright overlay. "N" (or ⌥N, or the button) toggles note mode; a click drops a pin on an
|
|
2
|
+
// element and asks for the note. Agents pick notes up on the daemon; pins show their progress.
|
|
3
|
+
// Everything lives in a shadow root, so the page's CSS and ours never meet.
|
|
4
|
+
;(() => {
|
|
5
|
+
if (navigator.webdriver || window.__pinwrightLoaded) return
|
|
6
|
+
window.__pinwrightLoaded = true
|
|
7
|
+
|
|
8
|
+
const script = document.currentScript
|
|
9
|
+
const BASE = script && script.src ? new URL(script.src).origin : location.origin
|
|
10
|
+
const API = `${BASE}/__pw`
|
|
11
|
+
const CFG = window.__pinwright || {}
|
|
12
|
+
const LANG = String(CFG.lang || 'en').slice(0, 2) === 'it' ? 'it' : 'en'
|
|
13
|
+
const tokensOf = (t) => (!t ? '0' : t >= 1e6 ? `${(t / 1e6).toFixed(1)}M` : t >= 1e3 ? `${Math.round(t / 1e3)}k` : String(t))
|
|
14
|
+
const T = {
|
|
15
|
+
it: {
|
|
16
|
+
notes: (n) => `Note (${n})`,
|
|
17
|
+
waiting: (n) => ` · ${n} da rispondere`,
|
|
18
|
+
mode: 'Cosa non va? Cliccalo.',
|
|
19
|
+
notesN: (n) => `Note ${n}`,
|
|
20
|
+
write: 'Scrivi la nota…',
|
|
21
|
+
cancel: 'Annulla',
|
|
22
|
+
save: 'Salva',
|
|
23
|
+
close: 'Chiudi',
|
|
24
|
+
del: 'Elimina',
|
|
25
|
+
sure: 'Sicuro? Elimina',
|
|
26
|
+
reply: 'Rispondi',
|
|
27
|
+
answer: 'Rispondi…',
|
|
28
|
+
follow: 'Non proprio…',
|
|
29
|
+
send: 'Invia',
|
|
30
|
+
archive: 'Archivia',
|
|
31
|
+
undo: 'Annulla modifica',
|
|
32
|
+
retry: 'Riprova',
|
|
33
|
+
handoff: 'Passa a Claude Code',
|
|
34
|
+
changes: (n) => `Modifiche (${n} file)`,
|
|
35
|
+
before: 'Prima',
|
|
36
|
+
after: 'Dopo',
|
|
37
|
+
you: 'Tu',
|
|
38
|
+
agent: 'Claude',
|
|
39
|
+
system: 'pinwright',
|
|
40
|
+
take: (id) => `Da prendere in Claude Code: pinwright take ${id}`,
|
|
41
|
+
empty: 'Nessuna nota. ⌥ + clic o N per aggiungerne.',
|
|
42
|
+
share: 'Vai live',
|
|
43
|
+
sharing: 'Apro il link…',
|
|
44
|
+
shareHint: 'Sito e note con chi ha il link. Max 8 persone.',
|
|
45
|
+
live: 'Live',
|
|
46
|
+
minimize: 'Riduci',
|
|
47
|
+
rename: 'clicca per cambiare nome',
|
|
48
|
+
expand: 'Espandi',
|
|
49
|
+
yolo: 'YOLO mode',
|
|
50
|
+
linkAutoHint: 'Le note partono subito.',
|
|
51
|
+
linkReviewHint: 'Le note aspettano la tua approvazione.',
|
|
52
|
+
approve: 'Approva',
|
|
53
|
+
discard: 'Scarta',
|
|
54
|
+
awaiting: 'In attesa di approvazione.',
|
|
55
|
+
reviewHost: 'Parte solo se la approvi.',
|
|
56
|
+
toApprove: (n) => ` · ${n} da approvare`,
|
|
57
|
+
copy: 'Copia',
|
|
58
|
+
copied: 'Copiato',
|
|
59
|
+
stopShare: 'Interrompi',
|
|
60
|
+
full: 'Sessione piena (max 8)',
|
|
61
|
+
here: (n) => `${n} qui`,
|
|
62
|
+
other: 'Su altre pagine',
|
|
63
|
+
showDone: (n) => `Mostra fatte (${n})`,
|
|
64
|
+
hideDone: 'Nascondi fatte',
|
|
65
|
+
offline: 'pinwright non raggiungibile',
|
|
66
|
+
click: 'clicca per aprire',
|
|
67
|
+
cost: (n) => `${n.tokens ? `${tokensOf(n.tokens)} token · ` : ""}$${n.costUsd.toFixed(n.costUsd < 0.01 ? 3 : 2)}`,
|
|
68
|
+
st: { review: 'Da approvare', queued: 'In coda', planning: 'Pianifica', working: 'Ci lavora', done: 'Fatto', asking: 'Domanda', handoff: 'A mano', failed: 'Fallita' },
|
|
69
|
+
},
|
|
70
|
+
en: {
|
|
71
|
+
notes: (n) => `Notes (${n})`,
|
|
72
|
+
waiting: (n) => ` · ${n} to answer`,
|
|
73
|
+
mode: 'What’s off? Click it.',
|
|
74
|
+
notesN: (n) => `Notes ${n}`,
|
|
75
|
+
write: 'Write the note…',
|
|
76
|
+
cancel: 'Cancel',
|
|
77
|
+
save: 'Save',
|
|
78
|
+
close: 'Close',
|
|
79
|
+
del: 'Delete',
|
|
80
|
+
sure: 'Sure? Delete',
|
|
81
|
+
reply: 'Reply',
|
|
82
|
+
answer: 'Answer…',
|
|
83
|
+
follow: 'Not quite…',
|
|
84
|
+
send: 'Send',
|
|
85
|
+
archive: 'Archive',
|
|
86
|
+
undo: 'Undo change',
|
|
87
|
+
retry: 'Retry',
|
|
88
|
+
handoff: 'Hand off to Claude Code',
|
|
89
|
+
changes: (n) => `Changes (${n} file${n === 1 ? '' : 's'})`,
|
|
90
|
+
before: 'Before',
|
|
91
|
+
after: 'After',
|
|
92
|
+
you: 'You',
|
|
93
|
+
agent: 'Claude',
|
|
94
|
+
system: 'pinwright',
|
|
95
|
+
take: (id) => `Take it in Claude Code: pinwright take ${id}`,
|
|
96
|
+
empty: 'No notes. ⌥ + click or N to add one.',
|
|
97
|
+
share: 'Go live',
|
|
98
|
+
sharing: 'Opening the link…',
|
|
99
|
+
shareHint: 'Site and notes, for whoever has the link. Max 8 people.',
|
|
100
|
+
live: 'Live',
|
|
101
|
+
minimize: 'Minimize',
|
|
102
|
+
rename: 'click to change your name',
|
|
103
|
+
expand: 'Expand',
|
|
104
|
+
yolo: 'YOLO mode',
|
|
105
|
+
linkAutoHint: 'Notes run right away.',
|
|
106
|
+
linkReviewHint: 'Notes wait for your approval.',
|
|
107
|
+
approve: 'Approve',
|
|
108
|
+
discard: 'Discard',
|
|
109
|
+
awaiting: 'Waiting for approval.',
|
|
110
|
+
reviewHost: 'Runs only once you approve it.',
|
|
111
|
+
toApprove: (n) => ` · ${n} to approve`,
|
|
112
|
+
copy: 'Copy',
|
|
113
|
+
copied: 'Copied',
|
|
114
|
+
stopShare: 'Stop',
|
|
115
|
+
full: 'Session full (max 8)',
|
|
116
|
+
here: (n) => `${n} here`,
|
|
117
|
+
other: 'On other pages',
|
|
118
|
+
showDone: (n) => `Show done (${n})`,
|
|
119
|
+
hideDone: 'Hide done',
|
|
120
|
+
offline: 'pinwright not reachable',
|
|
121
|
+
click: 'click to open',
|
|
122
|
+
cost: (n) => `${n.tokens ? `${tokensOf(n.tokens)} tokens · ` : ""}$${n.costUsd.toFixed(n.costUsd < 0.01 ? 3 : 2)}`,
|
|
123
|
+
st: { review: 'To approve', queued: 'Queued', planning: 'Planning', working: 'Working', done: 'Done', asking: 'Question', handoff: 'Hand off', failed: 'Failed' },
|
|
124
|
+
},
|
|
125
|
+
}[LANG]
|
|
126
|
+
|
|
127
|
+
const css = `
|
|
128
|
+
*{box-sizing:border-box}
|
|
129
|
+
.ui{pointer-events:auto;cursor:default;font:14px/1.45 system-ui,-apple-system,sans-serif;color:#121318;letter-spacing:normal;text-transform:none;text-align:left}
|
|
130
|
+
button{font:700 13px system-ui,-apple-system,sans-serif;cursor:pointer}
|
|
131
|
+
button.ui{cursor:pointer}
|
|
132
|
+
input,textarea{cursor:text}
|
|
133
|
+
.dock{position:fixed;right:16px;bottom:16px;display:flex;gap:8px;align-items:flex-end}
|
|
134
|
+
.dock .people{align-self:flex-end;padding-bottom:7px}
|
|
135
|
+
.people{display:flex}
|
|
136
|
+
.people span{display:grid;place-items:center;width:30px;height:30px;margin-left:-6px;border:2px solid #fff;border-radius:50%;background:var(--pc);color:#fff;font:800 11px system-ui,sans-serif;box-shadow:0 4px 12px rgb(0 0 0/.2)}
|
|
137
|
+
.people span.me{cursor:pointer;outline:2px solid var(--pc);outline-offset:1px}
|
|
138
|
+
/* The hub: a pill when closed, the dark notes card when open; one element, morphing between the two. */
|
|
139
|
+
.hub{position:relative;display:flex;flex-direction:column;align-items:flex-end;justify-content:flex-end;border-radius:22px;background:#ff3b6b;color:#fff;box-shadow:0 10px 30px rgb(0 0 0/.3);transition:width .34s cubic-bezier(.2,.8,.2,1),height .34s cubic-bezier(.2,.8,.2,1),border-radius .34s ease,background-color .34s ease}
|
|
140
|
+
.hub[data-on],.hub[data-open]{background:#121318}
|
|
141
|
+
.hub[data-open]{border-radius:16px}
|
|
142
|
+
.hub[data-on]:not([data-open]){outline:3px solid #ff3b6b}
|
|
143
|
+
.hub[data-off]{background:#8a8f9c}
|
|
144
|
+
.hub[data-morph]{overflow:hidden}
|
|
145
|
+
.hub[data-yolo]::before{content:"";position:absolute;inset:-2px;padding:2px;border-radius:inherit;background:conic-gradient(from var(--a,0deg),#ff3b6b,#f59e0b,#16a34a,#12a9c8,#7a5cff,#db2777,#ff3b6b);-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);-webkit-mask-composite:xor;mask-composite:exclude;pointer-events:none}
|
|
146
|
+
.hub[data-yolo]::after{content:"";position:absolute;inset:-2px;padding:2px;border-radius:inherit;background:radial-gradient(circle 70px at var(--mx,50%) var(--my,50%),#fff,transparent 70%);-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);-webkit-mask-composite:xor;mask-composite:exclude;pointer-events:none}
|
|
147
|
+
.face{display:flex;align-items:center;gap:8px;padding:12px 16px;white-space:nowrap;font:700 14px system-ui,-apple-system,sans-serif;cursor:pointer;animation:fade .2s ease .1s both}
|
|
148
|
+
.face[hidden],.list[hidden],.toasts[hidden]{display:none}
|
|
149
|
+
.face .n{display:grid;place-items:center;min-width:20px;height:20px;padding:0 6px;border-radius:999px;background:rgb(255 255 255/.25);font-size:11px}
|
|
150
|
+
.face .n.q{background:#12a9c8}
|
|
151
|
+
.face .n.a{background:#b45309}
|
|
152
|
+
.face .lv{display:flex;align-items:center;gap:6px;padding-left:8px;border-left:1px solid rgb(255 255 255/.3);font-size:12px}
|
|
153
|
+
.face .lv i{width:8px;height:8px;border-radius:50%;background:#4ade80;box-shadow:0 0 0 3px rgb(74 222 128/.25)}
|
|
154
|
+
.face .lv button{display:grid;place-items:center;width:22px;height:22px;padding:0;border:0;border-radius:50%;background:rgb(255 255 255/.18);color:#fff}
|
|
155
|
+
.face .lv svg{width:12px;height:12px}
|
|
156
|
+
@keyframes fade{from{opacity:0}}
|
|
157
|
+
kbd{margin-left:8px;padding:1px 6px;border:1px solid rgb(255 255 255/.25);border-radius:5px;font:600 10px ui-monospace,monospace;color:rgb(255 255 255/.6);vertical-align:1px}
|
|
158
|
+
.list{width:340px;max-height:60vh;overflow:auto;padding:6px 10px 10px;color:#e8e9ee;animation:fade .2s ease .12s both}
|
|
159
|
+
.list .bar{display:flex;align-items:center;gap:8px;margin:2px 0 6px;padding:6px 4px 6px 6px;font-size:12px;font-weight:600;color:#a3a8b5}
|
|
160
|
+
.list .bar span{flex:1}
|
|
161
|
+
.list .bar button{display:grid;place-items:center;width:24px;height:24px;padding:0;border:0;border-radius:50%;background:none;color:#a3a8b5;font-size:16px;line-height:1}
|
|
162
|
+
.list .bar button:hover{background:#2a2d36;color:#fff}
|
|
163
|
+
.list ol{margin:0;padding:0}
|
|
164
|
+
.list li{display:flex;gap:8px;align-items:flex-start;padding:8px;border-radius:10px;list-style:none;cursor:pointer}
|
|
165
|
+
.list li:hover{background:#1f2129}
|
|
166
|
+
.list li b{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:50%;background:var(--c);color:#fff;font-size:12px}
|
|
167
|
+
.list li small{filter:brightness(1.35)}
|
|
168
|
+
.list li span{flex:1;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
169
|
+
.list li small{flex:none;color:var(--c);font-weight:700;font-size:11px;text-transform:uppercase;letter-spacing:.04em;padding-top:3px}
|
|
170
|
+
.list h4{margin:10px 8px 4px;font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:#8a8f9c}
|
|
171
|
+
.list p{margin:6px}
|
|
172
|
+
.list em.cost{display:block;margin-top:2px;font-style:normal;color:#8a8f9c;font-size:12px}
|
|
173
|
+
.share{margin:0 0 8px;padding:10px;border-radius:10px;background:#1c1e25}
|
|
174
|
+
.share p{margin:0 0 8px;color:#a3a8b5;font-size:12px}
|
|
175
|
+
.share input{width:100%;padding:6px 8px;border:1px solid #2a2d36;border-radius:6px;font:12px ui-monospace,monospace;color:#d6d8de;background:#0f1117}
|
|
176
|
+
.share .row{margin-top:6px}
|
|
177
|
+
.share .sw{display:flex;align-items:center;gap:8px;margin:0 0 4px;padding:0;border:0;background:none;color:#fff;font-size:13px;text-align:left}
|
|
178
|
+
.share .sw i{flex:none;position:relative;width:30px;height:18px;border-radius:999px;background:#3a3d47;transition:background .15s}
|
|
179
|
+
.share .sw i::after{content:"";position:absolute;left:2px;top:2px;width:14px;height:14px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgb(0 0 0/.3);transition:translate .15s}
|
|
180
|
+
.share .sw[aria-checked="true"] i{background:linear-gradient(90deg,#ff3b6b,#f59e0b,#16a34a,#12a9c8,#7a5cff,#db2777,#ff3b6b) 0 0/300% 100%;animation:flow 2.4s linear infinite}
|
|
181
|
+
@keyframes flow{to{background-position:300% 0}}
|
|
182
|
+
@media (prefers-reduced-motion:reduce){.share .sw[aria-checked="true"] i{animation:none}}
|
|
183
|
+
.card.namecard{display:flex;gap:6px;width:260px;padding:8px;border-radius:12px}
|
|
184
|
+
.namecard input{flex:1;min-width:0;padding:6px 8px;border:1px solid #d6d8de;border-radius:8px;font:14px system-ui,sans-serif;color:#121318}
|
|
185
|
+
.namecard button{flex:none;padding:6px 12px;border:0;border-radius:999px;background:#121318;color:#fff}
|
|
186
|
+
button.ib{position:relative;display:grid;place-items:center;width:32px;height:32px;padding:0;border:0;border-radius:50%;background:#eef1f5;color:#121318}
|
|
187
|
+
button.ib svg{width:16px;height:16px}
|
|
188
|
+
button.ib.ok{background:#121318;color:#fff}
|
|
189
|
+
button.ib.del{background:none;color:#c4243f}
|
|
190
|
+
button.ib.del[data-sure]{background:#c4243f;color:#fff}
|
|
191
|
+
button.ib.flat{width:26px;height:26px;background:none;color:#5f6474}
|
|
192
|
+
button.ib.flat:hover{background:#e3e5ea}
|
|
193
|
+
button.ib.sm{width:24px;height:24px}
|
|
194
|
+
button.ib.sm svg{width:13px;height:13px}
|
|
195
|
+
button.ib[data-tip]:hover::after{content:attr(data-tip);position:absolute;bottom:calc(100% + 6px);right:0;padding:4px 8px;border-radius:6px;background:#121318;color:#fff;font:600 11px system-ui,sans-serif;white-space:nowrap;pointer-events:none;z-index:2}
|
|
196
|
+
button.ib.del[data-tip]:hover::after{right:auto;left:0}
|
|
197
|
+
.share .top button.ib[data-tip]:hover::after{bottom:auto;top:calc(100% + 6px)}
|
|
198
|
+
.list button.ib.ok{background:#fff;color:#121318}
|
|
199
|
+
.list button.ib.flat{color:#a3a8b5}
|
|
200
|
+
.list button.ib.flat:hover{background:#2a2d36;color:#fff}
|
|
201
|
+
.list button.ib[data-tip]:hover::after{background:#fff;color:#121318}
|
|
202
|
+
.list .err{color:#ff6b81}
|
|
203
|
+
.share .top{display:flex;align-items:center;gap:8px;margin:0 0 6px}
|
|
204
|
+
.share .top b{flex:1;font-size:12px;text-transform:uppercase;letter-spacing:.06em;color:#a3a8b5}
|
|
205
|
+
.share .top{gap:2px}
|
|
206
|
+
|
|
207
|
+
.share .sw[aria-checked="true"] i::after{translate:12px 0}
|
|
208
|
+
.share small{display:block;margin:0 0 8px 38px;color:#a3a8b5;font-size:11px}
|
|
209
|
+
.share .link{display:flex;gap:6px}
|
|
210
|
+
.share .link input{flex:1;min-width:0}
|
|
211
|
+
.cursor{position:fixed;left:0;top:0;pointer-events:none;transition:transform .08s linear;will-change:transform}
|
|
212
|
+
.cursor svg{display:block;filter:drop-shadow(0 1px 2px rgb(0 0 0/.35))}
|
|
213
|
+
.cursor b{position:absolute;left:14px;top:16px;padding:2px 7px;border-radius:999px;background:var(--pc);color:#fff;font:700 11px system-ui,sans-serif;white-space:nowrap}
|
|
214
|
+
.list .toggle{display:block;padding:0;border:0;background:none;color:#a3a8b5;font-size:12px;text-decoration:underline}
|
|
215
|
+
.list .foot{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:8px 6px 2px}
|
|
216
|
+
.list .live{display:flex;align-items:center;gap:6px;padding:5px 10px 5px 8px;border:0;border-radius:999px;background:#24262e;color:#fff;font-size:12px}
|
|
217
|
+
.list .live:hover{background:#2f323b}
|
|
218
|
+
.list .live svg{width:14px;height:14px}
|
|
219
|
+
.list .live[data-tip]:hover::after{content:attr(data-tip);position:absolute;bottom:calc(100% + 6px);right:0;padding:4px 8px;border-radius:6px;background:#fff;color:#121318;font:600 11px system-ui,sans-serif;white-space:nowrap;pointer-events:none}
|
|
220
|
+
.list .live{position:relative}
|
|
221
|
+
.hl{position:fixed;pointer-events:none;outline:2px dashed #ff3b6b;outline-offset:2px;border-radius:2px;display:none}
|
|
222
|
+
.pin{position:fixed;display:grid;place-items:center;width:28px;height:28px;margin:-28px 0 0 0;border-radius:50% 50% 50% 0;background:var(--c);color:#fff;font:800 13px system-ui,sans-serif;box-shadow:0 4px 12px rgb(0 0 0/.35);cursor:pointer;transform:rotate(-45deg);transform-origin:0 100%}
|
|
223
|
+
.pin i{font-style:normal;transform:rotate(45deg)}
|
|
224
|
+
.pin:hover::after{content:attr(data-text);position:absolute;left:34px;top:0;width:max-content;max-width:280px;padding:8px 10px;border-radius:10px;background:#121318;color:#fff;font:500 13px/1.35 system-ui,sans-serif;white-space:pre-wrap;transform:rotate(45deg);transform-origin:0 0}
|
|
225
|
+
.s-queued{--c:#ff3b6b}
|
|
226
|
+
.s-review{--c:#b45309}
|
|
227
|
+
.s-planning,.s-working{--c:#7a5cff}
|
|
228
|
+
.s-asking{--c:#12a9c8}
|
|
229
|
+
.s-done{--c:#16a34a}
|
|
230
|
+
.s-failed{--c:#dc2626}
|
|
231
|
+
.s-handoff{--c:#f97316}
|
|
232
|
+
.pin .dots{display:flex;gap:2px}
|
|
233
|
+
.pin .dots b{width:4px;height:4px;border-radius:50%;background:#fff;animation:dot 1s ease-in-out infinite}
|
|
234
|
+
.pin .dots b:nth-child(2){animation-delay:.15s}
|
|
235
|
+
.pin .dots b:nth-child(3){animation-delay:.3s}
|
|
236
|
+
@keyframes dot{0%,60%,100%{translate:0 0;opacity:.5}30%{translate:0 -3px;opacity:1}}
|
|
237
|
+
@keyframes spin{to{transform:rotate(360deg)}}
|
|
238
|
+
.pin.s-asking{animation:bounce 1.4s ease-in-out infinite}
|
|
239
|
+
@keyframes bounce{50%{translate:3px -3px}}
|
|
240
|
+
.pin.s-asking i::after{content:"?";margin-left:1px}
|
|
241
|
+
.pin.s-done i{font-size:0}
|
|
242
|
+
.pin.s-done i::after{content:"✓";font-size:15px}
|
|
243
|
+
.card{position:fixed;width:320px;padding:12px;border-radius:14px;background:#fff;box-shadow:0 20px 50px rgb(0 0 0/.35)}
|
|
244
|
+
.panel{width:400px;max-height:75vh;overflow:auto;padding:14px}
|
|
245
|
+
textarea{display:block;width:100%;min-height:70px;padding:8px;border:1px solid #d6d8de;border-radius:8px;font:14px/1.4 system-ui,sans-serif;color:#121318;background:#fff;resize:vertical}
|
|
246
|
+
.row{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px;margin-top:8px}
|
|
247
|
+
.row button:not(.ib){padding:8px 14px;border:0;border-radius:999px;background:#eef1f5;color:#121318}
|
|
248
|
+
.row .ok{background:#121318;color:#fff}
|
|
249
|
+
.row .del{margin-right:auto;background:none;color:#c4243f}
|
|
250
|
+
.row .del[data-sure]{background:#c4243f;color:#fff}
|
|
251
|
+
.head{display:flex;align-items:center;gap:8px;margin-bottom:10px}
|
|
252
|
+
.head b{display:grid;place-items:center;width:24px;height:24px;border-radius:50%;background:var(--c);color:#fff;font-size:12px}
|
|
253
|
+
.head span{color:var(--c);font-weight:700;font-size:12px;text-transform:uppercase;letter-spacing:.04em}
|
|
254
|
+
.head small{color:#8a8f9c;font-size:12px}
|
|
255
|
+
.head button{margin-left:auto;border:0;background:none;color:#8a8f9c;font-size:18px;line-height:1}
|
|
256
|
+
.msg{margin:0 0 8px;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
257
|
+
.msg em{display:block;font-style:normal;font-weight:700;font-size:12px;color:#5f6474;margin-bottom:2px}
|
|
258
|
+
.msg.agent{padding:8px 10px;border-radius:10px;background:#eef1f5}
|
|
259
|
+
.msg.system{color:#8a8f9c;font-size:13px}
|
|
260
|
+
.act{display:flex;gap:8px;align-items:center;margin:4px 0 8px;color:#7a5cff;font-weight:600;font-size:13px}
|
|
261
|
+
.act::before{content:"";width:12px;height:12px;flex:none;border-radius:50%;border:2px solid #7a5cff;border-top-color:transparent;animation:spin .8s linear infinite}
|
|
262
|
+
.hint{margin:6px 0;padding:8px 10px;border-radius:8px;background:#fff4ec;color:#9a3412;font:12px/1.4 ui-monospace,monospace;user-select:all}
|
|
263
|
+
.err{margin:6px 0;color:#c4243f;font-size:13px}
|
|
264
|
+
details{margin:8px 0}
|
|
265
|
+
summary{cursor:pointer;font-weight:700;font-size:13px}
|
|
266
|
+
pre{margin:6px 0 0;padding:8px;max-height:260px;overflow:auto;border-radius:8px;background:#0f1117;color:#d6d8de;font:11.5px/1.45 ui-monospace,monospace;white-space:pre}
|
|
267
|
+
pre .a{color:#4ade80}
|
|
268
|
+
pre .d{color:#f87171}
|
|
269
|
+
pre .h{color:#93c5fd}
|
|
270
|
+
.shots{display:grid;grid-template-columns:1fr 1fr;gap:6px;margin:8px 0}
|
|
271
|
+
.shots h5{margin:0;font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:#8a8f9c}
|
|
272
|
+
.shots a{display:block;border-radius:6px;overflow:hidden;border:1px solid #e3e5ea;background:#f5f6f8}
|
|
273
|
+
.shots img{display:block;width:100%;height:150px;object-fit:cover;object-position:top}
|
|
274
|
+
.cost{color:#8a8f9c;font-size:11px;margin-top:6px;text-align:right}
|
|
275
|
+
.toasts{position:fixed;right:16px;bottom:72px;display:flex;flex-direction:column;gap:8px;width:340px}
|
|
276
|
+
.toast{position:relative;padding:10px 32px 10px 14px;border-radius:12px;border:2px solid var(--c);background:#fff;box-shadow:0 12px 32px rgb(0 0 0/.25);cursor:pointer;animation:toast-in .2s ease-out}
|
|
277
|
+
.toast b{display:block;color:var(--c);font-size:12px;text-transform:uppercase;letter-spacing:.04em}
|
|
278
|
+
.toast p{margin:2px 0 0;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
279
|
+
.toast small{display:block;margin-top:4px;color:#8a8f9c;font-size:12px}
|
|
280
|
+
.toast button{position:absolute;top:6px;right:8px;border:0;background:none;color:#8a8f9c;font-size:16px;line-height:1}
|
|
281
|
+
@keyframes toast-in{from{opacity:0;translate:0 8px}}
|
|
282
|
+
`
|
|
283
|
+
|
|
284
|
+
// --- host: one element, in the top layer so it stays above (and usable over) a modal dialog.
|
|
285
|
+
const host = document.createElement('pinwright-root')
|
|
286
|
+
host.setAttribute('popover', 'manual')
|
|
287
|
+
host.style.cssText =
|
|
288
|
+
'position:fixed;inset:0;width:100vw;height:100vh;max-width:none;max-height:none;margin:0;padding:0;border:0;background:transparent;overflow:visible;pointer-events:none;z-index:2147483647;color-scheme:light'
|
|
289
|
+
const root = host.attachShadow({ mode: 'open' })
|
|
290
|
+
const style = document.createElement('style')
|
|
291
|
+
style.textContent = css
|
|
292
|
+
root.append(style)
|
|
293
|
+
document.body.append(host)
|
|
294
|
+
// A modal dialog makes the rest of the page inert: the host moves inside it while it's open.
|
|
295
|
+
const raise = () => {
|
|
296
|
+
try {
|
|
297
|
+
const modal = [...document.querySelectorAll('dialog[open]')].filter((d) => d.matches(':modal')).at(-1)
|
|
298
|
+
const home = modal ?? document.body
|
|
299
|
+
if (host.parentElement !== home) home.append(host)
|
|
300
|
+
if (host.matches(':popover-open')) host.hidePopover()
|
|
301
|
+
host.showPopover()
|
|
302
|
+
} catch {}
|
|
303
|
+
}
|
|
304
|
+
raise()
|
|
305
|
+
new MutationObserver(() => setTimeout(raise, 0)).observe(document.body, { subtree: true, attributes: true, attributeFilter: ['open'] })
|
|
306
|
+
|
|
307
|
+
/** Tiny DOM helper: h('div.card.ui', {onclick}, child, 'text'). */
|
|
308
|
+
function h(tag, props, ...kids) {
|
|
309
|
+
const [name, ...cls] = tag.split('.')
|
|
310
|
+
const el = document.createElement(name || 'div')
|
|
311
|
+
if (cls.length) el.className = cls.join(' ')
|
|
312
|
+
for (const [k, v] of Object.entries(props || {})) {
|
|
313
|
+
if (v === undefined || v === null || v === false) continue
|
|
314
|
+
if (k.startsWith('on')) el.addEventListener(k.slice(2), v)
|
|
315
|
+
else if (k === 'text') el.textContent = v
|
|
316
|
+
else if (k in el && k !== 'list') el[k] = v
|
|
317
|
+
else el.setAttribute(k, v === true ? '' : v)
|
|
318
|
+
}
|
|
319
|
+
for (const c of kids.flat()) if (c !== null && c !== undefined && c !== false) el.append(c)
|
|
320
|
+
return el
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const ICONS = {
|
|
324
|
+
copy: '<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>',
|
|
325
|
+
check: '<path d="M20 6 9 17l-5-5"/>',
|
|
326
|
+
minus: '<path d="M5 12h14"/>',
|
|
327
|
+
power: '<path d="M12 2v10"/><path d="M18.4 6.6a9 9 0 1 1-12.77.04"/>',
|
|
328
|
+
trash: '<path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>',
|
|
329
|
+
undo: '<path d="M9 14 4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-4"/>',
|
|
330
|
+
archive: '<rect x="2" y="3" width="20" height="5" rx="1"/><path d="M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8"/><path d="M10 12h4"/>',
|
|
331
|
+
retry: '<path d="M21 12a9 9 0 1 1-3-6.7L21 8"/><path d="M21 3v5h-5"/>',
|
|
332
|
+
terminal: '<path d="m4 17 6-6-6-6"/><path d="M12 19h8"/>',
|
|
333
|
+
send: '<path d="m22 2-7 20-4-9-9-4Z"/><path d="M22 2 11 13"/>',
|
|
334
|
+
link: '<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>',
|
|
335
|
+
}
|
|
336
|
+
const svg = (name) => {
|
|
337
|
+
const t = document.createElement('template')
|
|
338
|
+
t.innerHTML = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[name]}</svg>`
|
|
339
|
+
return t.content.firstChild
|
|
340
|
+
}
|
|
341
|
+
/** An icon button; what it does shows on hover (and to screen readers). */
|
|
342
|
+
const ib = (name, tip, onclick, cls = '') => {
|
|
343
|
+
const b = h(`button.ib${cls}`, { 'data-tip': tip, 'aria-label': tip, onclick }, svg(name))
|
|
344
|
+
b.setIcon = (n) => b.replaceChildren(svg(n))
|
|
345
|
+
return b
|
|
346
|
+
}
|
|
347
|
+
/** Copies, then shows a tick for a moment. */
|
|
348
|
+
const copyIb = (getText, cls = '') => {
|
|
349
|
+
const b = ib(
|
|
350
|
+
'copy',
|
|
351
|
+
T.copy,
|
|
352
|
+
async (e) => {
|
|
353
|
+
e.stopPropagation()
|
|
354
|
+
try {
|
|
355
|
+
await navigator.clipboard.writeText(getText())
|
|
356
|
+
} catch {}
|
|
357
|
+
b.setIcon('check')
|
|
358
|
+
b.dataset.tip = T.copied
|
|
359
|
+
setTimeout(() => (b.setIcon('copy'), (b.dataset.tip = T.copy)), 1500)
|
|
360
|
+
},
|
|
361
|
+
cls,
|
|
362
|
+
)
|
|
363
|
+
return b
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const page = location.pathname
|
|
367
|
+
const VISIBLE = ['queued', 'planning', 'working', 'done', 'asking', 'handoff', 'failed']
|
|
368
|
+
let notes = []
|
|
369
|
+
const activity = {}
|
|
370
|
+
let on = false
|
|
371
|
+
let target = null
|
|
372
|
+
let panelId = null
|
|
373
|
+
// Done notes stay out of the way unless asked for; the choice sticks per browser.
|
|
374
|
+
let showDone = false
|
|
375
|
+
try {
|
|
376
|
+
showDone = localStorage.getItem('pw-show-done') === '1'
|
|
377
|
+
} catch {}
|
|
378
|
+
const shown = (n) => showDone || n.status !== 'done'
|
|
379
|
+
let online = true
|
|
380
|
+
// Live session: me, the others (max 8 people), their cursors, the share link (host only).
|
|
381
|
+
let pid = null
|
|
382
|
+
try {
|
|
383
|
+
pid = sessionStorage.getItem('pw-pid')
|
|
384
|
+
if (!pid) sessionStorage.setItem('pw-pid', (pid = Math.random().toString(36).slice(2, 12)))
|
|
385
|
+
} catch {
|
|
386
|
+
pid = Math.random().toString(36).slice(2, 12)
|
|
387
|
+
}
|
|
388
|
+
let me = null
|
|
389
|
+
let full = false
|
|
390
|
+
let peers = []
|
|
391
|
+
let shareLinks = null
|
|
392
|
+
// Which of the two links the share box shows: the one that waits for my approval, unless YOLO mode is on.
|
|
393
|
+
// YOLO is a per-moment choice: every page load starts with it off.
|
|
394
|
+
let yolo = false
|
|
395
|
+
|
|
396
|
+
let access = 'host'
|
|
397
|
+
let sharing = false
|
|
398
|
+
const cursors = new Map()
|
|
399
|
+
// Holding ⌥ is a temporary note mode.
|
|
400
|
+
let held = false
|
|
401
|
+
const active = () => on || held
|
|
402
|
+
|
|
403
|
+
const hl = h('div.hl')
|
|
404
|
+
const face = h('div.face')
|
|
405
|
+
const list = h('div.list', { hidden: true })
|
|
406
|
+
const hub = h('div.hub.ui', {}, list, face)
|
|
407
|
+
let isOpen = false
|
|
408
|
+
const people = h('div.people.ui')
|
|
409
|
+
const dock = h('div.dock', {}, people, hub)
|
|
410
|
+
const pins = h('div')
|
|
411
|
+
const cursorLayer = h('div')
|
|
412
|
+
const toasts = h('div.toasts')
|
|
413
|
+
root.append(hl, pins, cursorLayer, toasts, dock)
|
|
414
|
+
|
|
415
|
+
// The page's own cursor during note mode: a pin in my colour, tip on the hotspot. Needs a light-DOM rule.
|
|
416
|
+
const modeStyle = document.createElement('style')
|
|
417
|
+
document.head.append(modeStyle)
|
|
418
|
+
function modeCursor() {
|
|
419
|
+
const c = (me && me.color) || '#ff3b6b'
|
|
420
|
+
const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 26 26'><path d='M2 24V13A11 11 0 1 1 13 24Z' fill='${c}' stroke='white' stroke-width='2'/></svg>`
|
|
421
|
+
// Our own cards keep the normal cursor: the pin is only for the page.
|
|
422
|
+
modeStyle.textContent = `html[data-pw-mode],html[data-pw-mode] *{cursor:url("data:image/svg+xml,${encodeURIComponent(svg)}") 2 24,crosshair!important}html[data-pw-mode] pinwright-root{cursor:default!important}`
|
|
423
|
+
}
|
|
424
|
+
modeCursor()
|
|
425
|
+
|
|
426
|
+
const api = async (path, opts = {}) => {
|
|
427
|
+
const r = await fetch(API + path, { ...opts, credentials: 'same-origin', headers: { 'content-type': 'application/json' }, body: opts.body ? JSON.stringify(opts.body) : undefined })
|
|
428
|
+
const data = await r.json().catch(() => ({}))
|
|
429
|
+
if (!r.ok) throw new Error(data.error || r.statusText)
|
|
430
|
+
return data
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const sel = (el) => {
|
|
434
|
+
if (el.id) return `#${CSS.escape(el.id)}`
|
|
435
|
+
const parts = []
|
|
436
|
+
while (el && el !== document.body && el !== document.documentElement && parts.length < 8) {
|
|
437
|
+
let s = el.tagName.toLowerCase()
|
|
438
|
+
const cls = [...el.classList].filter((c) => !/^(in|out|live|active|hover|focus|open|is-.*|astro-.*)$/.test(c)).slice(0, 2)
|
|
439
|
+
if (cls.length) s += `.${cls.map(CSS.escape).join('.')}`
|
|
440
|
+
const p = el.parentElement
|
|
441
|
+
if (p) {
|
|
442
|
+
const same = [...p.children].filter((c) => c.tagName === el.tagName)
|
|
443
|
+
if (same.length > 1) s += `:nth-of-type(${same.indexOf(el) + 1})`
|
|
444
|
+
}
|
|
445
|
+
parts.unshift(s)
|
|
446
|
+
el = p
|
|
447
|
+
if (el && el.id) {
|
|
448
|
+
parts.unshift(`#${CSS.escape(el.id)}`)
|
|
449
|
+
break
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return parts.join(' > ')
|
|
453
|
+
}
|
|
454
|
+
const textOf = (el) => (el.innerText || el.getAttribute('alt') || el.getAttribute('aria-label') || '').trim().replace(/\s+/g, ' ').slice(0, 200)
|
|
455
|
+
const STYLE_KEYS = ['display', 'position', 'width', 'height', 'margin', 'padding', 'color', 'background-color', 'font-family', 'font-size', 'font-weight', 'line-height', 'letter-spacing', 'text-align', 'border', 'border-radius', 'gap', 'flex-direction', 'justify-content', 'align-items', 'grid-template-columns', 'opacity', 'z-index']
|
|
456
|
+
const stylesOf = (el) => {
|
|
457
|
+
const cs = getComputedStyle(el)
|
|
458
|
+
const out = {}
|
|
459
|
+
for (const k of STYLE_KEYS) {
|
|
460
|
+
const v = cs.getPropertyValue(k)
|
|
461
|
+
if (v && v !== 'none' && v !== 'normal' && v !== 'auto' && v !== '0px') out[k] = v
|
|
462
|
+
}
|
|
463
|
+
return out
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const visible = () => notes.filter((n) => VISIBLE.includes(n.status))
|
|
467
|
+
const mine = () => visible().filter((n) => n.page === page)
|
|
468
|
+
const numberOf = (id) => mine().findIndex((n) => n.id === id) + 1
|
|
469
|
+
const findEl = (n) => {
|
|
470
|
+
try {
|
|
471
|
+
return n.selector ? document.querySelector(n.selector) : null
|
|
472
|
+
} catch {
|
|
473
|
+
return null
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
const busy = (n) => n.status === 'working' || n.status === 'planning'
|
|
477
|
+
/** A queued note from the review link shows as waiting for approval. */
|
|
478
|
+
const stOf = (n) => (n.status === 'queued' && n.approved === false ? 'review' : n.status)
|
|
479
|
+
const short = (s, n = 140) => (s.length > n ? `${s.slice(0, n)}…` : s)
|
|
480
|
+
|
|
481
|
+
/** Pins sit on their element, in viewport coordinates: set again on scroll, resize and layout shifts. */
|
|
482
|
+
function place() {
|
|
483
|
+
for (const pin of pins.children) {
|
|
484
|
+
const n = notes.find((x) => x.id === pin.dataset.id)
|
|
485
|
+
if (!n) continue
|
|
486
|
+
const el = findEl(n)
|
|
487
|
+
let x = (n.pageX ?? 0) - scrollX
|
|
488
|
+
let y = (n.pageY ?? 0) - scrollY
|
|
489
|
+
if (el) {
|
|
490
|
+
const r = el.getBoundingClientRect()
|
|
491
|
+
if (r.width || r.height) {
|
|
492
|
+
x = r.left + r.width * (n.fx ?? 0)
|
|
493
|
+
y = r.top + r.height * (n.fy ?? 0)
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
pin.style.left = `${x}px`
|
|
497
|
+
pin.style.top = `${y}px`
|
|
498
|
+
}
|
|
499
|
+
const panel = root.querySelector('.panel')
|
|
500
|
+
if (panel) {
|
|
501
|
+
const pin = [...pins.children].find((p) => p.dataset.id === panel.dataset.id)
|
|
502
|
+
if (pin) position(panel, pin.getBoundingClientRect())
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function position(card, r) {
|
|
506
|
+
const w = card.offsetWidth || 400
|
|
507
|
+
const hgt = card.offsetHeight || 300
|
|
508
|
+
let left = r.right + 10
|
|
509
|
+
if (left + w > innerWidth - 8) left = r.left - w - 10
|
|
510
|
+
left = Math.max(8, Math.min(left, innerWidth - w - 8))
|
|
511
|
+
const top = Math.max(8, Math.min(r.top - 10, innerHeight - hgt - 8))
|
|
512
|
+
card.style.left = `${left}px`
|
|
513
|
+
card.style.top = `${top}px`
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function render() {
|
|
517
|
+
const all = mine()
|
|
518
|
+
const ns = all.filter(shown)
|
|
519
|
+
const open = all.filter((n) => n.status !== 'done').length
|
|
520
|
+
const waiting = all.filter((n) => n.status === 'asking').length
|
|
521
|
+
const toApprove = access === 'host' ? visible().filter((n) => stOf(n) === 'review').length : 0
|
|
522
|
+
renderFace(open, waiting, toApprove)
|
|
523
|
+
document.documentElement.toggleAttribute('data-pw-mode', active())
|
|
524
|
+
renderPeople()
|
|
525
|
+
hub.toggleAttribute('data-on', on)
|
|
526
|
+
hub.toggleAttribute('data-open', isOpen)
|
|
527
|
+
hub.toggleAttribute('data-off', !online)
|
|
528
|
+
hub.toggleAttribute('data-yolo', Boolean(shareLinks && yolo && me && !me.guest))
|
|
529
|
+
toasts.hidden = isOpen
|
|
530
|
+
// Pins are rebuilt only when what they show changed, so one never vanishes under the pointer.
|
|
531
|
+
const sig = JSON.stringify(ns.map((n) => [n.id, stOf(n), n.text, activity[n.id]]))
|
|
532
|
+
if (pins.dataset.sig !== sig) {
|
|
533
|
+
pins.dataset.sig = sig
|
|
534
|
+
pins.replaceChildren(
|
|
535
|
+
...ns.map((n) => {
|
|
536
|
+
const i = all.indexOf(n)
|
|
537
|
+
const act = activity[n.id]
|
|
538
|
+
const tip = `${T.st[stOf(n)]}${act ? ` · ${act}` : ''}\n\n${short(n.text, 200)}\n\n(${T.click})`
|
|
539
|
+
return h(`div.pin.ui.s-${stOf(n)}`, { 'data-id': n.id, 'data-text': tip, onclick: (e) => (e.stopPropagation(), openPanel(n.id)) }, busy(n) ? h('i.dots', {}, h('b'), h('b'), h('b')) : h('i', { text: String(i + 1) }))
|
|
540
|
+
}),
|
|
541
|
+
)
|
|
542
|
+
}
|
|
543
|
+
place()
|
|
544
|
+
renderList()
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** The closed hub: the count, what waits for me, and the live state with a copy button. */
|
|
548
|
+
function renderFace(open, waiting, toApprove) {
|
|
549
|
+
const live = shareLinks && me && !me.guest
|
|
550
|
+
const sig = JSON.stringify([full, online, on, open, waiting, toApprove, live && yolo, live && shareLinks.auto])
|
|
551
|
+
if (face.dataset.sig === sig) return
|
|
552
|
+
face.dataset.sig = sig
|
|
553
|
+
if (full || !online) return void face.replaceChildren(full ? T.full : T.offline)
|
|
554
|
+
if (on) return void face.replaceChildren(T.mode, h('kbd', { text: 'esc' }))
|
|
555
|
+
const url = () => (yolo ? shareLinks.auto : shareLinks.review)
|
|
556
|
+
const copy = live
|
|
557
|
+
? h(
|
|
558
|
+
'button',
|
|
559
|
+
{
|
|
560
|
+
title: T.copy,
|
|
561
|
+
'aria-label': T.copy,
|
|
562
|
+
onclick: async (e) => {
|
|
563
|
+
e.stopPropagation()
|
|
564
|
+
try {
|
|
565
|
+
await navigator.clipboard.writeText(url())
|
|
566
|
+
} catch {}
|
|
567
|
+
copy.replaceChildren(svg('check'))
|
|
568
|
+
setTimeout(() => copy.replaceChildren(svg('copy')), 1500)
|
|
569
|
+
},
|
|
570
|
+
},
|
|
571
|
+
svg('copy'),
|
|
572
|
+
)
|
|
573
|
+
: null
|
|
574
|
+
// replaceChildren would print a null as the text "null".
|
|
575
|
+
face.replaceChildren(
|
|
576
|
+
...[
|
|
577
|
+
T.notesN(open),
|
|
578
|
+
waiting ? h('span.n.q', { text: String(waiting), title: T.waiting(waiting).replace(' · ', '') }) : null,
|
|
579
|
+
toApprove ? h('span.n.a', { text: String(toApprove), title: T.toApprove(toApprove).replace(' · ', '') }) : null,
|
|
580
|
+
live ? h('span.lv', {}, h('i'), yolo ? 'YOLO' : T.live, copy) : null,
|
|
581
|
+
].filter(Boolean),
|
|
582
|
+
)
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** Opens or closes the hub, morphing size, corners and colour from one state to the other. */
|
|
586
|
+
function setOpen(v) {
|
|
587
|
+
if (v === isOpen) return
|
|
588
|
+
const from = hub.getBoundingClientRect()
|
|
589
|
+
isOpen = v
|
|
590
|
+
list.hidden = !v
|
|
591
|
+
face.hidden = v
|
|
592
|
+
render()
|
|
593
|
+
hub.style.width = ''
|
|
594
|
+
hub.style.height = ''
|
|
595
|
+
const to = hub.getBoundingClientRect()
|
|
596
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return
|
|
597
|
+
hub.setAttribute('data-morph', '')
|
|
598
|
+
// Back to the old size without animating it (colour and corners keep transitioning), then grow to the new one.
|
|
599
|
+
hub.style.transitionProperty = 'background-color,border-radius'
|
|
600
|
+
hub.style.width = `${from.width}px`
|
|
601
|
+
hub.style.height = `${from.height}px`
|
|
602
|
+
hub.offsetWidth
|
|
603
|
+
hub.style.transitionProperty = ''
|
|
604
|
+
hub.style.width = `${to.width}px`
|
|
605
|
+
hub.style.height = `${to.height}px`
|
|
606
|
+
clearTimeout(hub.morphTimer)
|
|
607
|
+
hub.morphTimer = setTimeout(() => {
|
|
608
|
+
hub.removeAttribute('data-morph')
|
|
609
|
+
hub.style.width = ''
|
|
610
|
+
hub.style.height = ''
|
|
611
|
+
}, 380)
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function renderList() {
|
|
615
|
+
if (!isOpen) return
|
|
616
|
+
const all = mine()
|
|
617
|
+
const ns = all.filter(shown)
|
|
618
|
+
const others = visible().filter((n) => n.page !== page && shown(n))
|
|
619
|
+
const done = visible().filter((n) => n.status === 'done').length
|
|
620
|
+
const item = (n, i, here) =>
|
|
621
|
+
h(
|
|
622
|
+
`li.s-${stOf(n)}`,
|
|
623
|
+
{ onclick: () => (here ? focusPin(n.id) : (location.href = n.page)) },
|
|
624
|
+
h('b', { text: here ? String(i + 1) : '•' }),
|
|
625
|
+
h(
|
|
626
|
+
'span',
|
|
627
|
+
{},
|
|
628
|
+
here ? short(n.text) : `${n.page} ${short(n.text, 80)}`,
|
|
629
|
+
n.status === 'done' && n.costUsd ? h('em.cost', { text: T.cost(n) }) : null,
|
|
630
|
+
),
|
|
631
|
+
h('small', { text: T.st[stOf(n)] }),
|
|
632
|
+
)
|
|
633
|
+
const bar = h(
|
|
634
|
+
'div.bar',
|
|
635
|
+
{},
|
|
636
|
+
h('span', {}, on ? [T.mode, h('kbd', { text: 'esc' })] : T.notesN(all.filter((n) => n.status !== 'done').length)),
|
|
637
|
+
h('button', { text: '×', title: T.close, 'aria-label': T.close, onclick: (e) => (e.stopPropagation(), setOn(false), setOpen(false)) }),
|
|
638
|
+
)
|
|
639
|
+
const parts = [
|
|
640
|
+
bar,
|
|
641
|
+
shareBox(),
|
|
642
|
+
ns.length ? h('ol', {}, ns.map((n) => item(n, all.indexOf(n), true))) : null,
|
|
643
|
+
others.length ? [h('h4', { text: T.other }), h('ol', {}, others.map((n, i) => item(n, i, false)))] : null,
|
|
644
|
+
h(
|
|
645
|
+
'div.foot',
|
|
646
|
+
{},
|
|
647
|
+
done || showDone
|
|
648
|
+
? h('button.toggle', {
|
|
649
|
+
text: showDone ? T.hideDone : T.showDone(done),
|
|
650
|
+
onclick: (e) => {
|
|
651
|
+
e.stopPropagation()
|
|
652
|
+
showDone = !showDone
|
|
653
|
+
try {
|
|
654
|
+
localStorage.setItem('pw-show-done', showDone ? '1' : '0')
|
|
655
|
+
} catch {}
|
|
656
|
+
if (!showDone && panelId && notes.find((n) => n.id === panelId)?.status === 'done') closePanel()
|
|
657
|
+
render()
|
|
658
|
+
},
|
|
659
|
+
})
|
|
660
|
+
: h('span'),
|
|
661
|
+
goLive(),
|
|
662
|
+
),
|
|
663
|
+
]
|
|
664
|
+
// replaceChildren would print a null as the text "null".
|
|
665
|
+
list.replaceChildren(...parts.flat().filter(Boolean))
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function initials(name) {
|
|
669
|
+
return name
|
|
670
|
+
.split(' ')
|
|
671
|
+
.map((w) => w[0])
|
|
672
|
+
.join('')
|
|
673
|
+
.slice(0, 2)
|
|
674
|
+
.toUpperCase()
|
|
675
|
+
}
|
|
676
|
+
function renderPeople() {
|
|
677
|
+
const sig = JSON.stringify(peers.map((p) => [p.id, p.name]))
|
|
678
|
+
if (people.dataset.sig === sig) return
|
|
679
|
+
people.dataset.sig = sig
|
|
680
|
+
// Alone, nothing to show.
|
|
681
|
+
const ps = peers.length > 1 ? peers : []
|
|
682
|
+
people.replaceChildren(
|
|
683
|
+
...ps.map((p) => {
|
|
684
|
+
const mine = p.id === pid
|
|
685
|
+
const chip = h(mine ? 'span.me' : 'span', {
|
|
686
|
+
title: mine ? `${p.name} (${T.you}) · ${T.rename}` : p.name,
|
|
687
|
+
text: initials(p.name),
|
|
688
|
+
onclick: mine ? (e) => (e.stopPropagation(), nameCard(chip)) : undefined,
|
|
689
|
+
})
|
|
690
|
+
chip.style.setProperty('--pc', p.color)
|
|
691
|
+
return chip
|
|
692
|
+
}),
|
|
693
|
+
)
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// The YOLO border follows the pointer: the colours turn towards it and a highlight sits where it's nearest.
|
|
697
|
+
let glowFrame = 0
|
|
698
|
+
let lastMove = null
|
|
699
|
+
addEventListener(
|
|
700
|
+
'pointermove',
|
|
701
|
+
(ev) => {
|
|
702
|
+
lastMove = ev
|
|
703
|
+
if (glowFrame) return
|
|
704
|
+
glowFrame = requestAnimationFrame(() => {
|
|
705
|
+
glowFrame = 0
|
|
706
|
+
const e = lastMove
|
|
707
|
+
const box = hub.hasAttribute('data-yolo') ? hub : null
|
|
708
|
+
if (!box) return
|
|
709
|
+
const r = box.getBoundingClientRect()
|
|
710
|
+
const a = (Math.atan2(e.clientY - (r.top + r.height / 2), e.clientX - (r.left + r.width / 2)) * 180) / Math.PI + 90
|
|
711
|
+
box.style.setProperty('--a', `${a}deg`)
|
|
712
|
+
box.style.setProperty('--mx', `${Math.max(0, Math.min(r.width, e.clientX - r.left)) + 2}px`)
|
|
713
|
+
box.style.setProperty('--my', `${Math.max(0, Math.min(r.height, e.clientY - r.top)) + 2}px`)
|
|
714
|
+
})
|
|
715
|
+
},
|
|
716
|
+
{ passive: true },
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
/** A small card above my chip to choose my name; it sticks in this browser. */
|
|
720
|
+
function nameCard(chip) {
|
|
721
|
+
root.querySelector('.namecard')?.remove()
|
|
722
|
+
const save = () => {
|
|
723
|
+
const name = input.value.replace(/\s+/g, ' ').trim().slice(0, 30)
|
|
724
|
+
card.remove()
|
|
725
|
+
if (!name || !ws || ws.readyState !== 1) return
|
|
726
|
+
try {
|
|
727
|
+
localStorage.setItem('pw-name', name)
|
|
728
|
+
} catch {}
|
|
729
|
+
ws.send(JSON.stringify({ t: 'name', name }))
|
|
730
|
+
}
|
|
731
|
+
const input = h('input', {
|
|
732
|
+
value: me ? me.name : '',
|
|
733
|
+
maxLength: 30,
|
|
734
|
+
onkeydown: (e) => {
|
|
735
|
+
e.stopPropagation()
|
|
736
|
+
if (e.key === 'Enter') save()
|
|
737
|
+
if (e.key === 'Escape') card.remove()
|
|
738
|
+
},
|
|
739
|
+
})
|
|
740
|
+
const card = h('div.card.namecard.ui', { onclick: (e) => e.stopPropagation() }, input, h('button', { text: T.save, onclick: save }))
|
|
741
|
+
root.append(card)
|
|
742
|
+
const r = chip.getBoundingClientRect()
|
|
743
|
+
card.style.left = `${Math.max(8, Math.min(r.left, innerWidth - card.offsetWidth - 8))}px`
|
|
744
|
+
card.style.top = `${r.top - card.offsetHeight - 8}px`
|
|
745
|
+
input.focus()
|
|
746
|
+
input.select()
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/** The host's two links to the live session, in the list. Guests don't get them. */
|
|
750
|
+
let shareError = null
|
|
751
|
+
async function startShare() {
|
|
752
|
+
if (sharing) return
|
|
753
|
+
sharing = true
|
|
754
|
+
shareError = null
|
|
755
|
+
render()
|
|
756
|
+
try {
|
|
757
|
+
const r = await api('/share', { method: 'POST', body: { page: location.pathname + location.search } })
|
|
758
|
+
shareLinks = r.links
|
|
759
|
+
} catch (err) {
|
|
760
|
+
shareError = err.message
|
|
761
|
+
setOpen(true)
|
|
762
|
+
} finally {
|
|
763
|
+
sharing = false
|
|
764
|
+
render()
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/** Off: just a small button at the bottom of the list. */
|
|
769
|
+
function goLive() {
|
|
770
|
+
if (!me || me.guest || shareLinks) return null
|
|
771
|
+
return h('button.live', { 'data-tip': T.shareHint, disabled: sharing, onclick: (e) => (e.stopPropagation(), startShare()) }, svg('link'), sharing ? T.sharing : T.share)
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function shareBox() {
|
|
775
|
+
if (!me || me.guest) return null
|
|
776
|
+
if (!shareLinks) return shareError ? h('p.err', { text: shareError }) : null
|
|
777
|
+
const url = yolo ? shareLinks.auto : shareLinks.review
|
|
778
|
+
const input = h('input', { value: url, readOnly: true, onclick: (e) => (e.stopPropagation(), e.target.select()) })
|
|
779
|
+
const stop = ib(
|
|
780
|
+
'power',
|
|
781
|
+
T.stopShare,
|
|
782
|
+
async (e) => {
|
|
783
|
+
e.stopPropagation()
|
|
784
|
+
await api('/share', { method: 'DELETE' }).catch(() => {})
|
|
785
|
+
shareLinks = null
|
|
786
|
+
render()
|
|
787
|
+
},
|
|
788
|
+
'.flat',
|
|
789
|
+
)
|
|
790
|
+
const top = h('div.top', {}, h('b', { text: yolo ? `${T.live} · YOLO` : T.live }), stop)
|
|
791
|
+
const toggle = h(
|
|
792
|
+
'button.sw',
|
|
793
|
+
{
|
|
794
|
+
role: 'switch',
|
|
795
|
+
'aria-checked': String(yolo),
|
|
796
|
+
onclick: (e) => {
|
|
797
|
+
e.stopPropagation()
|
|
798
|
+
yolo = !yolo
|
|
799
|
+
render()
|
|
800
|
+
},
|
|
801
|
+
},
|
|
802
|
+
h('i'),
|
|
803
|
+
T.yolo,
|
|
804
|
+
)
|
|
805
|
+
return h(
|
|
806
|
+
'div.share',
|
|
807
|
+
{},
|
|
808
|
+
top,
|
|
809
|
+
toggle,
|
|
810
|
+
h('small', { text: yolo ? T.linkAutoHint : T.linkReviewHint }),
|
|
811
|
+
h('div.link', {}, input, copyIb(() => url, '.ok')),
|
|
812
|
+
)
|
|
813
|
+
}
|
|
814
|
+
function alertIn(box, msg) {
|
|
815
|
+
box.querySelector('.err')?.remove()
|
|
816
|
+
box.prepend(h('p.err', { text: msg }))
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// --- cursors: mine goes out (throttled) anchored to the element under it; the others' come in.
|
|
820
|
+
let lastPointer = null
|
|
821
|
+
let sendTimer = null
|
|
822
|
+
let lastSent = 0
|
|
823
|
+
function cursorPayload(hidden) {
|
|
824
|
+
if (hidden || !lastPointer) return { pid, page, hidden: true }
|
|
825
|
+
const { x, y } = lastPointer
|
|
826
|
+
const el = document.elementFromPoint(x, y)
|
|
827
|
+
const d = { pid, page, x: x / innerWidth, y: y + scrollY, hidden: false }
|
|
828
|
+
if (el && el !== host && el !== document.documentElement && el !== document.body) {
|
|
829
|
+
const r = el.getBoundingClientRect()
|
|
830
|
+
if (r.width && r.height) Object.assign(d, { sel: sel(el), fx: (x - r.left) / r.width, fy: (y - r.top) / r.height })
|
|
831
|
+
}
|
|
832
|
+
return d
|
|
833
|
+
}
|
|
834
|
+
function sendCursor(hidden = false) {
|
|
835
|
+
if (!me || peers.length < 2) return
|
|
836
|
+
const go = () => {
|
|
837
|
+
sendTimer = null
|
|
838
|
+
lastSent = Date.now()
|
|
839
|
+
if (ws && ws.readyState === 1) ws.send(JSON.stringify({ t: 'cursor', ...cursorPayload(hidden) }))
|
|
840
|
+
}
|
|
841
|
+
if (hidden) return go()
|
|
842
|
+
if (sendTimer) return
|
|
843
|
+
sendTimer = setTimeout(go, Math.max(0, 60 - (Date.now() - lastSent)))
|
|
844
|
+
}
|
|
845
|
+
addEventListener(
|
|
846
|
+
'pointermove',
|
|
847
|
+
(e) => {
|
|
848
|
+
lastPointer = { x: e.clientX, y: e.clientY }
|
|
849
|
+
sendCursor()
|
|
850
|
+
if (held && !fromUs(e)) highlight(e.target)
|
|
851
|
+
},
|
|
852
|
+
{ passive: true, capture: true },
|
|
853
|
+
)
|
|
854
|
+
document.addEventListener('pointerleave', () => sendCursor(true))
|
|
855
|
+
addEventListener('blur', () => {
|
|
856
|
+
held = false
|
|
857
|
+
render()
|
|
858
|
+
})
|
|
859
|
+
|
|
860
|
+
function arrow(color) {
|
|
861
|
+
const ns = 'http://www.w3.org/2000/svg'
|
|
862
|
+
const svg = document.createElementNS(ns, 'svg')
|
|
863
|
+
svg.setAttribute('width', '18')
|
|
864
|
+
svg.setAttribute('height', '22')
|
|
865
|
+
svg.setAttribute('viewBox', '0 0 18 22')
|
|
866
|
+
const path = document.createElementNS(ns, 'path')
|
|
867
|
+
path.setAttribute('d', 'M1 1v17l4.5-4.2 3.2 7.2 3-1.3-3.2-7H15z')
|
|
868
|
+
path.setAttribute('fill', color)
|
|
869
|
+
path.setAttribute('stroke', '#fff')
|
|
870
|
+
path.setAttribute('stroke-width', '1.5')
|
|
871
|
+
path.setAttribute('stroke-linejoin', 'round')
|
|
872
|
+
svg.append(path)
|
|
873
|
+
return svg
|
|
874
|
+
}
|
|
875
|
+
function placeCursors() {
|
|
876
|
+
for (const [id, c] of cursors) {
|
|
877
|
+
const d = c.data
|
|
878
|
+
const stale = Date.now() - c.at > 20000
|
|
879
|
+
if (d.hidden || d.page !== page || stale || !peers.some((p) => p.id === id)) {
|
|
880
|
+
c.el.style.display = 'none'
|
|
881
|
+
continue
|
|
882
|
+
}
|
|
883
|
+
let x = d.x * innerWidth
|
|
884
|
+
let y = d.y - scrollY
|
|
885
|
+
if (d.sel) {
|
|
886
|
+
try {
|
|
887
|
+
const el = document.querySelector(d.sel)
|
|
888
|
+
const r = el && el.getBoundingClientRect()
|
|
889
|
+
if (r && (r.width || r.height)) {
|
|
890
|
+
x = r.left + r.width * d.fx
|
|
891
|
+
y = r.top + r.height * d.fy
|
|
892
|
+
}
|
|
893
|
+
} catch {}
|
|
894
|
+
}
|
|
895
|
+
c.el.style.display = 'block'
|
|
896
|
+
c.el.style.transform = `translate(${x}px, ${y}px)`
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
function onCursor(d) {
|
|
900
|
+
let c = cursors.get(d.pid)
|
|
901
|
+
if (!c) {
|
|
902
|
+
const el = h('div.cursor', {}, arrow(d.color), h('b', { text: d.name }))
|
|
903
|
+
el.style.setProperty('--pc', d.color)
|
|
904
|
+
cursorLayer.append(el)
|
|
905
|
+
c = { el, data: d, at: Date.now() }
|
|
906
|
+
cursors.set(d.pid, c)
|
|
907
|
+
}
|
|
908
|
+
c.data = d
|
|
909
|
+
c.at = Date.now()
|
|
910
|
+
placeCursors()
|
|
911
|
+
}
|
|
912
|
+
setInterval(placeCursors, 2000)
|
|
913
|
+
|
|
914
|
+
function focusPin(id) {
|
|
915
|
+
const n = notes.find((x) => x.id === id)
|
|
916
|
+
const el = n && findEl(n)
|
|
917
|
+
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
918
|
+
else if (n) scrollTo({ top: (n.pageY ?? 0) - innerHeight / 2, behavior: 'smooth' })
|
|
919
|
+
setTimeout(() => openPanel(id), 350)
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// --- data: one fetch, then server-sent events.
|
|
923
|
+
const upsert = (n) => {
|
|
924
|
+
const i = notes.findIndex((x) => x.id === n.id)
|
|
925
|
+
if (i >= 0) notes[i] = n
|
|
926
|
+
else notes.push(n)
|
|
927
|
+
}
|
|
928
|
+
const loadAll = () =>
|
|
929
|
+
api('/notes')
|
|
930
|
+
.then((d) => {
|
|
931
|
+
notes = d
|
|
932
|
+
online = true
|
|
933
|
+
render()
|
|
934
|
+
})
|
|
935
|
+
.catch(() => {
|
|
936
|
+
online = false
|
|
937
|
+
render()
|
|
938
|
+
})
|
|
939
|
+
|
|
940
|
+
// The live channel is a WebSocket: tunnels (the shared link) hold back SSE but pass these through.
|
|
941
|
+
const handlers = {}
|
|
942
|
+
const handle = (event, fn) => (handlers[event] = fn)
|
|
943
|
+
let ws = null
|
|
944
|
+
let retry = 0
|
|
945
|
+
function connect() {
|
|
946
|
+
const u = new URL(`${API}/ws`)
|
|
947
|
+
u.protocol = u.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
948
|
+
u.searchParams.set('pid', pid)
|
|
949
|
+
u.searchParams.set('page', page)
|
|
950
|
+
try {
|
|
951
|
+
const name = localStorage.getItem('pw-name')
|
|
952
|
+
if (name) u.searchParams.set('name', name)
|
|
953
|
+
} catch {}
|
|
954
|
+
const sock = new WebSocket(u)
|
|
955
|
+
ws = sock
|
|
956
|
+
sock.onopen = () => (retry = 0)
|
|
957
|
+
sock.onmessage = (e) => {
|
|
958
|
+
try {
|
|
959
|
+
const { event, data } = JSON.parse(e.data)
|
|
960
|
+
if (handlers[event]) handlers[event](data)
|
|
961
|
+
} catch {}
|
|
962
|
+
}
|
|
963
|
+
sock.onclose = () => {
|
|
964
|
+
if (ws !== sock) return
|
|
965
|
+
ws = null
|
|
966
|
+
if (full) return
|
|
967
|
+
online = false
|
|
968
|
+
render()
|
|
969
|
+
setTimeout(connect, Math.min(10000, 500 * 2 ** retry++))
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
handle('hello', (d) => {
|
|
973
|
+
for (const k of Object.keys(activity)) delete activity[k]
|
|
974
|
+
Object.assign(activity, d.activity || {})
|
|
975
|
+
me = d.me || null
|
|
976
|
+
peers = d.peers || []
|
|
977
|
+
access = d.access || 'host'
|
|
978
|
+
if (d.share) shareLinks = d.share.links
|
|
979
|
+
full = false
|
|
980
|
+
modeCursor()
|
|
981
|
+
loadAll()
|
|
982
|
+
})
|
|
983
|
+
handle('full', () => {
|
|
984
|
+
full = true
|
|
985
|
+
render()
|
|
986
|
+
})
|
|
987
|
+
handle('peers', (d) => {
|
|
988
|
+
peers = d
|
|
989
|
+
me = peers.find((p) => p.id === pid) || me
|
|
990
|
+
for (const [id, c] of cursors) {
|
|
991
|
+
if (!peers.some((p) => p.id === id)) {
|
|
992
|
+
c.el.remove()
|
|
993
|
+
cursors.delete(id)
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
render()
|
|
997
|
+
// Somebody new: tell them where my pointer is.
|
|
998
|
+
sendCursor()
|
|
999
|
+
})
|
|
1000
|
+
handle('cursor', onCursor)
|
|
1001
|
+
handle('share', (d) => {
|
|
1002
|
+
shareLinks = d.links
|
|
1003
|
+
render()
|
|
1004
|
+
})
|
|
1005
|
+
handle('note', (n) => {
|
|
1006
|
+
const prev = notes.find((x) => x.id === n.id)
|
|
1007
|
+
if (prev && prev.status !== n.status && ['done', 'failed', 'handoff'].includes(n.status)) toast(n)
|
|
1008
|
+
// The host hears about notes and replies from the review link as they arrive.
|
|
1009
|
+
else if (access === 'host' && stOf(n) === 'review' && (!prev || stOf(prev) !== 'review')) toast(n)
|
|
1010
|
+
upsert(n)
|
|
1011
|
+
render()
|
|
1012
|
+
if (panelId === n.id) {
|
|
1013
|
+
if (!VISIBLE.includes(n.status)) closePanel()
|
|
1014
|
+
else refreshPanel()
|
|
1015
|
+
}
|
|
1016
|
+
})
|
|
1017
|
+
handle('activity', ({ id, text }) => {
|
|
1018
|
+
if (text) activity[id] = text
|
|
1019
|
+
else delete activity[id]
|
|
1020
|
+
render()
|
|
1021
|
+
const line = panelId === id && root.querySelector('.panel .act')
|
|
1022
|
+
if (line && text) line.textContent = text
|
|
1023
|
+
})
|
|
1024
|
+
handle('reload', () => reload())
|
|
1025
|
+
connect()
|
|
1026
|
+
|
|
1027
|
+
/** Closes every open card: the note being written, the panel, the list. */
|
|
1028
|
+
function closeAll() {
|
|
1029
|
+
root.querySelector('.form')?.remove()
|
|
1030
|
+
root.querySelector('.namecard')?.remove()
|
|
1031
|
+
closePanel()
|
|
1032
|
+
setOpen(false)
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/** Bottom-right notice when a note finishes; a click opens its panel. Stays while hovered. */
|
|
1036
|
+
function toast(n) {
|
|
1037
|
+
const close = () => t.remove()
|
|
1038
|
+
const what = n.status === 'done' ? n.summary || n.text : n.status === 'handoff' ? T.take(n.id) : n.text
|
|
1039
|
+
const t = h(
|
|
1040
|
+
`div.toast.ui.s-${stOf(n)}`,
|
|
1041
|
+
{
|
|
1042
|
+
onclick: (e) => {
|
|
1043
|
+
e.stopPropagation()
|
|
1044
|
+
close()
|
|
1045
|
+
openPanel(n.id)
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
1048
|
+
h('b', { text: n.page === page ? T.st[stOf(n)] : `${T.st[stOf(n)]} · ${n.page}` }),
|
|
1049
|
+
h('p', { text: short(what, 220) }),
|
|
1050
|
+
n.status === 'done' && n.costUsd ? h('small', { text: T.cost(n) }) : null,
|
|
1051
|
+
h('button', { text: '×', title: T.close, onclick: (e) => (e.stopPropagation(), close()) }),
|
|
1052
|
+
)
|
|
1053
|
+
toasts.append(t)
|
|
1054
|
+
let timer
|
|
1055
|
+
const arm = () => (timer = setTimeout(close, 12000))
|
|
1056
|
+
t.addEventListener('mouseenter', () => clearTimeout(timer))
|
|
1057
|
+
t.addEventListener('mouseleave', arm)
|
|
1058
|
+
arm()
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// --- note mode.
|
|
1062
|
+
const setOn = (v) => {
|
|
1063
|
+
on = v
|
|
1064
|
+
if (!active()) hl.style.display = 'none'
|
|
1065
|
+
render()
|
|
1066
|
+
}
|
|
1067
|
+
function highlight(t) {
|
|
1068
|
+
if (!t || t === host || !t.getBoundingClientRect) return
|
|
1069
|
+
target = t
|
|
1070
|
+
const r = t.getBoundingClientRect()
|
|
1071
|
+
Object.assign(hl.style, { display: 'block', left: `${r.left}px`, top: `${r.top}px`, width: `${r.width}px`, height: `${r.height}px` })
|
|
1072
|
+
}
|
|
1073
|
+
hub.addEventListener('click', (e) => {
|
|
1074
|
+
e.stopPropagation()
|
|
1075
|
+
if (isOpen) return
|
|
1076
|
+
if (on) return setOn(false)
|
|
1077
|
+
setOn(true)
|
|
1078
|
+
setOpen(true)
|
|
1079
|
+
})
|
|
1080
|
+
|
|
1081
|
+
const fromUs = (e) => e.composedPath().includes(host)
|
|
1082
|
+
const typing = (e) => {
|
|
1083
|
+
const t = e.composedPath()[0]
|
|
1084
|
+
return t && t.nodeType === 1 && (t.closest('textarea,input,select,[contenteditable=""],[contenteditable=true]') || t.isContentEditable)
|
|
1085
|
+
}
|
|
1086
|
+
document.addEventListener('keyup', (e) => {
|
|
1087
|
+
if (e.key !== 'Alt' || !held) return
|
|
1088
|
+
held = false
|
|
1089
|
+
if (!active()) hl.style.display = 'none'
|
|
1090
|
+
render()
|
|
1091
|
+
})
|
|
1092
|
+
document.addEventListener('keydown', (e) => {
|
|
1093
|
+
// Hold ⌥ (alone): the cursor turns into a pin and a click drops a note.
|
|
1094
|
+
if (e.key === 'Alt' && !e.repeat && !e.metaKey && !e.ctrlKey && !e.shiftKey && !typing(e)) {
|
|
1095
|
+
held = true
|
|
1096
|
+
if (lastPointer) {
|
|
1097
|
+
const t = document.elementFromPoint(lastPointer.x, lastPointer.y)
|
|
1098
|
+
if (t && t !== host) highlight(t)
|
|
1099
|
+
}
|
|
1100
|
+
render()
|
|
1101
|
+
return
|
|
1102
|
+
}
|
|
1103
|
+
if (e.code === 'KeyN' && e.altKey && !e.metaKey && !e.ctrlKey) {
|
|
1104
|
+
e.preventDefault()
|
|
1105
|
+
return setOn(!on)
|
|
1106
|
+
}
|
|
1107
|
+
if (e.key === 'Escape') {
|
|
1108
|
+
const open = root.querySelector('.form') || panelId || isOpen
|
|
1109
|
+
closeAll()
|
|
1110
|
+
if (!open && on) setOn(false)
|
|
1111
|
+
return
|
|
1112
|
+
}
|
|
1113
|
+
if (typing(e) || e.metaKey || e.ctrlKey || e.altKey) return
|
|
1114
|
+
if (e.key === 'n' || e.key === 'N') setOn(!on)
|
|
1115
|
+
})
|
|
1116
|
+
document.addEventListener(
|
|
1117
|
+
'mouseover',
|
|
1118
|
+
(e) => {
|
|
1119
|
+
if (!active()) return
|
|
1120
|
+
if (fromUs(e)) return void (hl.style.display = 'none')
|
|
1121
|
+
highlight(e.target)
|
|
1122
|
+
},
|
|
1123
|
+
true,
|
|
1124
|
+
)
|
|
1125
|
+
document.addEventListener(
|
|
1126
|
+
'click',
|
|
1127
|
+
(e) => {
|
|
1128
|
+
if (fromUs(e)) return
|
|
1129
|
+
// A click outside closes whatever is open. If a card was open, the click only closes it.
|
|
1130
|
+
const card = root.querySelector('.form') || panelId
|
|
1131
|
+
closeAll()
|
|
1132
|
+
// ⌥ held at click time counts even if its keydown never reached the page (focus elsewhere).
|
|
1133
|
+
if (!active() && !(e.altKey && !e.metaKey && !e.ctrlKey && !e.shiftKey)) return
|
|
1134
|
+
e.preventDefault()
|
|
1135
|
+
e.stopPropagation()
|
|
1136
|
+
if (card) return
|
|
1137
|
+
const el = e.target
|
|
1138
|
+
hl.style.display = 'none'
|
|
1139
|
+
const r = el.getBoundingClientRect()
|
|
1140
|
+
const at = {
|
|
1141
|
+
page,
|
|
1142
|
+
url: location.href,
|
|
1143
|
+
selector: sel(el),
|
|
1144
|
+
element: textOf(el),
|
|
1145
|
+
html: el.outerHTML.slice(0, 1500),
|
|
1146
|
+
styles: stylesOf(el),
|
|
1147
|
+
fx: r.width ? (e.clientX - r.left) / r.width : 0,
|
|
1148
|
+
fy: r.height ? (e.clientY - r.top) / r.height : 0,
|
|
1149
|
+
pageX: e.pageX,
|
|
1150
|
+
pageY: e.pageY,
|
|
1151
|
+
viewport: `${innerWidth}x${innerHeight}`,
|
|
1152
|
+
}
|
|
1153
|
+
writeNote(at, e.clientX, e.clientY)
|
|
1154
|
+
},
|
|
1155
|
+
true,
|
|
1156
|
+
)
|
|
1157
|
+
|
|
1158
|
+
/** A card with a textarea: Enter submits, Shift+Enter breaks the line, Esc closes. */
|
|
1159
|
+
function textBox(placeholder, onSubmit, onEscape) {
|
|
1160
|
+
const ta = h('textarea', { placeholder })
|
|
1161
|
+
ta.addEventListener('keydown', (e) => {
|
|
1162
|
+
e.stopPropagation()
|
|
1163
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) {
|
|
1164
|
+
e.preventDefault()
|
|
1165
|
+
onSubmit(ta.value.trim())
|
|
1166
|
+
}
|
|
1167
|
+
if (e.key === 'Escape') {
|
|
1168
|
+
e.preventDefault()
|
|
1169
|
+
onEscape()
|
|
1170
|
+
}
|
|
1171
|
+
})
|
|
1172
|
+
return ta
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
function writeNote(at, x, y) {
|
|
1176
|
+
closePanel()
|
|
1177
|
+
const close = () => form.remove()
|
|
1178
|
+
const save = async (text) => {
|
|
1179
|
+
if (!text) return close()
|
|
1180
|
+
try {
|
|
1181
|
+
const n = await api('/notes', { method: 'POST', body: { ...at, text, author: me ? me.name : null } })
|
|
1182
|
+
upsert(n)
|
|
1183
|
+
close()
|
|
1184
|
+
render()
|
|
1185
|
+
} catch (err) {
|
|
1186
|
+
form.querySelector('.err')?.remove()
|
|
1187
|
+
form.append(h('p.err', { text: err.message }))
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
const ta = textBox(T.write, save, close)
|
|
1191
|
+
const form = h(
|
|
1192
|
+
'div.card.form.ui',
|
|
1193
|
+
{},
|
|
1194
|
+
ta,
|
|
1195
|
+
h('div.row', {}, h('button', { text: T.cancel, onclick: close }), h('button.ok', { text: T.save, onclick: () => save(ta.value.trim()) })),
|
|
1196
|
+
)
|
|
1197
|
+
form.style.left = `${Math.max(8, Math.min(x, innerWidth - 330))}px`
|
|
1198
|
+
form.style.top = `${Math.max(8, Math.min(y + 18, innerHeight - 190))}px`
|
|
1199
|
+
root.append(form)
|
|
1200
|
+
ta.focus()
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
// --- the panel on a pin.
|
|
1204
|
+
function closePanel() {
|
|
1205
|
+
root.querySelector('.panel')?.remove()
|
|
1206
|
+
panelId = null
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
async function openPanel(id) {
|
|
1210
|
+
root.querySelector('.form')?.remove()
|
|
1211
|
+
closePanel()
|
|
1212
|
+
panelId = id
|
|
1213
|
+
await refreshPanel()
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
let refreshing = null
|
|
1217
|
+
async function refreshPanel() {
|
|
1218
|
+
const id = panelId
|
|
1219
|
+
if (!id) return
|
|
1220
|
+
// Don't throw away what the reviewer is typing: keep the text and the focus across a redraw.
|
|
1221
|
+
const old = root.querySelector('.panel')
|
|
1222
|
+
const oldTa = old && old.querySelector('textarea')
|
|
1223
|
+
const draft = oldTa ? oldTa.value : ''
|
|
1224
|
+
const focused = oldTa && root.activeElement === oldTa
|
|
1225
|
+
const err = old && old.querySelector('.err')?.textContent
|
|
1226
|
+
const openDiff = old && old.querySelector('details')?.open
|
|
1227
|
+
const req = (refreshing = api(`/notes/${id}`).catch(() => null))
|
|
1228
|
+
const n = await req
|
|
1229
|
+
if (refreshing !== req || panelId !== id) return
|
|
1230
|
+
if (!n) return closePanel()
|
|
1231
|
+
const panel = buildPanel(n)
|
|
1232
|
+
const ta = panel.querySelector('textarea')
|
|
1233
|
+
if (ta && draft) ta.value = draft
|
|
1234
|
+
if (err) panel.querySelector('.row')?.before(h('p.err', { text: err }))
|
|
1235
|
+
if (openDiff && panel.querySelector('details')) panel.querySelector('details').open = true
|
|
1236
|
+
root.querySelector('.panel')?.remove()
|
|
1237
|
+
root.append(panel)
|
|
1238
|
+
const pin = [...pins.children].find((p) => p.dataset.id === id)
|
|
1239
|
+
if (pin) position(panel, pin.getBoundingClientRect())
|
|
1240
|
+
else {
|
|
1241
|
+
position(panel, { left: innerWidth - 16, right: innerWidth - 16, top: innerHeight })
|
|
1242
|
+
panel.style.top = `${Math.max(8, innerHeight - panel.offsetHeight - 72)}px` // above the button
|
|
1243
|
+
}
|
|
1244
|
+
if (ta && (focused || n.status === 'asking')) ta.focus()
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function diffView(diff) {
|
|
1248
|
+
const pre = h('pre')
|
|
1249
|
+
for (const line of diff.split('\n')) {
|
|
1250
|
+
const c = line.startsWith('+++') || line.startsWith('---') || line.startsWith('@@') ? 'h' : line.startsWith('+') ? 'a' : line.startsWith('-') ? 'd' : ''
|
|
1251
|
+
pre.append(c ? h(`span.${c}`, { text: line }) : line, '\n')
|
|
1252
|
+
}
|
|
1253
|
+
return pre
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
function shotsView(shots) {
|
|
1257
|
+
const before = shots.before || []
|
|
1258
|
+
const after = shots.after || []
|
|
1259
|
+
if (!before.length && !after.length) return null
|
|
1260
|
+
const img = (f) => (f ? h('a', { href: `${API}/shots/${f}`, target: '_blank', rel: 'noopener' }, h('img', { src: `${API}/shots/${f}`, loading: 'lazy', alt: '' })) : h('div'))
|
|
1261
|
+
const rows = []
|
|
1262
|
+
for (let i = 0; i < Math.max(before.length, after.length); i++) rows.push(img(before[i]), img(after[i]))
|
|
1263
|
+
return h('div.shots', {}, h('h5', { text: T.before }), h('h5', { text: T.after }), rows)
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function buildPanel(n) {
|
|
1267
|
+
const act = (fn) => async (e) => {
|
|
1268
|
+
const b = e.currentTarget
|
|
1269
|
+
b.disabled = true
|
|
1270
|
+
try {
|
|
1271
|
+
await fn()
|
|
1272
|
+
} catch (err) {
|
|
1273
|
+
const p = root.querySelector('.panel')
|
|
1274
|
+
p?.querySelector('.err')?.remove()
|
|
1275
|
+
p?.querySelector('.row')?.before(h('p.err', { text: err.message }))
|
|
1276
|
+
} finally {
|
|
1277
|
+
b.disabled = false
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
const post = (what, body) => api(`/notes/${n.id}/${what}`, { method: 'POST', body: body || {} })
|
|
1281
|
+
const send = async (text) => {
|
|
1282
|
+
if (!text) return
|
|
1283
|
+
await post('reply', { text, author: me ? me.name : null })
|
|
1284
|
+
const ta = root.querySelector('.panel textarea')
|
|
1285
|
+
if (ta) ta.value = ''
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
const del = ib(
|
|
1289
|
+
'trash',
|
|
1290
|
+
T.del,
|
|
1291
|
+
act(async () => {
|
|
1292
|
+
if (!del.dataset.sure) {
|
|
1293
|
+
del.dataset.sure = '1'
|
|
1294
|
+
del.dataset.tip = T.sure
|
|
1295
|
+
return
|
|
1296
|
+
}
|
|
1297
|
+
await api(`/notes/${n.id}`, { method: 'DELETE' })
|
|
1298
|
+
closePanel()
|
|
1299
|
+
}),
|
|
1300
|
+
'.del',
|
|
1301
|
+
)
|
|
1302
|
+
|
|
1303
|
+
const review = stOf(n) === 'review'
|
|
1304
|
+
const running = ['queued', 'planning', 'working'].includes(n.status)
|
|
1305
|
+
if (review && access === 'host') del.dataset.tip = T.discard
|
|
1306
|
+
const buttons = [del]
|
|
1307
|
+
if (n.status === 'done' && n.files && n.files.length) buttons.push(ib('undo', T.undo, act(() => post('undo'))))
|
|
1308
|
+
if (!['handoff', 'done'].includes(n.status)) buttons.push(ib('terminal', T.handoff, act(() => post('handoff'))))
|
|
1309
|
+
if (n.status === 'done') buttons.push(ib('archive', T.archive, act(() => post('archive'))))
|
|
1310
|
+
if (n.status === 'failed') buttons.push(ib('retry', T.retry, act(() => post('retry')), '.ok'))
|
|
1311
|
+
if (review && access === 'host') buttons.push(ib('check', T.approve, act(() => post('approve')), '.ok'))
|
|
1312
|
+
|
|
1313
|
+
let box = null
|
|
1314
|
+
if (!running) {
|
|
1315
|
+
const ph = n.status === 'asking' ? T.answer : T.follow
|
|
1316
|
+
box = textBox(ph, (text) => act(() => send(text))({ currentTarget: box }), closePanel)
|
|
1317
|
+
buttons.push(ib('send', n.status === 'asking' ? T.reply : T.send, act(() => send(box.value.trim())), '.ok'))
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
const who = { user: T.you, agent: T.agent, system: T.system }
|
|
1321
|
+
return h(
|
|
1322
|
+
`div.card.panel.ui.s-${stOf(n)}`,
|
|
1323
|
+
{ 'data-id': n.id, onclick: (e) => e.stopPropagation() },
|
|
1324
|
+
h(
|
|
1325
|
+
'div.head',
|
|
1326
|
+
{},
|
|
1327
|
+
h('b', { text: n.page === page ? String(numberOf(n.id) || '•') : '•' }),
|
|
1328
|
+
h('span', { text: T.st[stOf(n)] }),
|
|
1329
|
+
h('small', { text: n.id }),
|
|
1330
|
+
h('button', { text: '×', title: T.close, onclick: closePanel }),
|
|
1331
|
+
),
|
|
1332
|
+
(n.messages || []).map((m) => {
|
|
1333
|
+
const label = m.role === 'user' && m.author && (!me || m.author !== me.name) ? m.author : who[m.role] || m.role
|
|
1334
|
+
return h(`p.msg.${m.role}`, {}, h('em', { text: label }), m.text)
|
|
1335
|
+
}),
|
|
1336
|
+
review ? h('p.msg.system', { text: access === 'host' ? T.reviewHost : T.awaiting }) : running ? h('div.act', { text: activity[n.id] || n.activity || T.st[n.status] }) : null,
|
|
1337
|
+
n.status === 'handoff' ? h('p.hint', { text: T.take(n.id) }) : null,
|
|
1338
|
+
n.diff ? h('details', {}, h('summary', { text: T.changes((n.files || []).length) }), diffView(n.diff)) : null,
|
|
1339
|
+
shotsView(n.shots || {}),
|
|
1340
|
+
box,
|
|
1341
|
+
h('div.row', {}, buttons),
|
|
1342
|
+
n.costUsd ? h('div.cost', { text: T.cost(n) }) : null,
|
|
1343
|
+
)
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
addEventListener('resize', () => (place(), placeCursors()))
|
|
1347
|
+
addEventListener('scroll', () => requestAnimationFrame(placeCursors), { passive: true, capture: true })
|
|
1348
|
+
addEventListener('scroll', () => sendCursor(), { passive: true })
|
|
1349
|
+
addEventListener('scroll', () => requestAnimationFrame(place), { passive: true, capture: true })
|
|
1350
|
+
addEventListener('load', place)
|
|
1351
|
+
setInterval(place, 1000)
|
|
1352
|
+
render()
|
|
1353
|
+
|
|
1354
|
+
// --- reloads (ours after a rebuild, or the dev server's HMR): back at the same scroll, mode and panel.
|
|
1355
|
+
try {
|
|
1356
|
+
const saved = JSON.parse(sessionStorage.getItem('pw-state') || 'null')
|
|
1357
|
+
sessionStorage.removeItem('pw-state')
|
|
1358
|
+
const nav = performance.getEntriesByType('navigation')[0]
|
|
1359
|
+
if (saved && saved.path === location.pathname + location.search && (!nav || nav.type === 'reload')) {
|
|
1360
|
+
const back = () => scrollTo(0, saved.y)
|
|
1361
|
+
document.readyState === 'complete' ? back() : addEventListener('load', back)
|
|
1362
|
+
setTimeout(back, 300)
|
|
1363
|
+
if (saved.on) setTimeout(() => setOn(true), 50)
|
|
1364
|
+
if (saved.panel) setTimeout(() => openPanel(saved.panel), 300)
|
|
1365
|
+
}
|
|
1366
|
+
} catch {}
|
|
1367
|
+
addEventListener('pagehide', () => {
|
|
1368
|
+
try {
|
|
1369
|
+
sessionStorage.setItem('pw-state', JSON.stringify({ path: location.pathname + location.search, y: scrollY, on, panel: panelId }))
|
|
1370
|
+
} catch {}
|
|
1371
|
+
})
|
|
1372
|
+
let pending = false
|
|
1373
|
+
function reload() {
|
|
1374
|
+
const busy = root.querySelector('.form') || [...root.querySelectorAll('textarea')].some((t) => t.value.trim())
|
|
1375
|
+
if (busy) return void (pending = true)
|
|
1376
|
+
location.reload()
|
|
1377
|
+
}
|
|
1378
|
+
setInterval(() => pending && reload(), 1000)
|
|
1379
|
+
})()
|