@spectosh/browser 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,475 @@
1
+ // How people find Point (VISION.md §4.10), each one the project's choice in
2
+ // Settings → Point:
3
+ // launcher a small "Report a problem" pill (on by default): label,
4
+ // corner or edge tab, colour, which pages
5
+ // nudge "That didn't work? Show us" right after an error, a failed
6
+ // request, rage or dead clicks (off by default): once per visit,
7
+ // never while someone is typing
8
+ // reminder a one-time card that explains Point (off by default): on the
9
+ // 3rd visit, every 30 days or each release; only for people who
10
+ // have never opened Point
11
+ // right-click Shift (or Alt) + right-click on anything opens Point with it
12
+ // marked; or, if the project chose so, every right-click offers
13
+ // "Report a problem here" (the browser's own menu stays on Shift,
14
+ // on links, fields and selected text)
15
+ // The visitor has a say over the launcher too: right-click (or long-press)
16
+ // it to make it smaller, move it to the other side or hide it for this
17
+ // visit, or drag it where it is out of the way — remembered in this browser.
18
+ // Loaded on idle by the trigger once this visitor may use Point; drawn in
19
+ // its own shadow root inside a `specto-block` host, so the recording never
20
+ // shows it and the page's CSS never reaches it. Each opening tells Point
21
+ // where it came from (`via`), so the report says which entry point worked.
22
+
23
+ const USED_KEY = 'specto-point-used'
24
+ const VISITS_KEY = 'specto-point-visits'
25
+ const VISIT_FLAG = 'specto-point-visit'
26
+ const HINT_KEY = 'specto-point-hint' // { at, release } of the last reminder
27
+ const NUDGED = 'specto-point-nudged' // per tab: once per visit
28
+ const ME_KEY = 'specto-point-me' // the visitor's own say: { compact, side, y }
29
+ const HIDDEN_KEY = 'specto-point-hidden' // "hide for this visit" (per tab)
30
+ const NUDGE_MS = 12_000
31
+ // reports this browser asked to hear about: [{ r, at }] (bugs/notify.js) —
32
+ // read by the base snippet (trigger.js), which asks /api/point-status
33
+ export const RECEIPTS_KEY = 'specto-point-receipts'
34
+ const RECEIPT_MS = 90 * 86_400_000
35
+ const receipts = () => { try { return (JSON.parse(localStorage.getItem(RECEIPTS_KEY) || '[]') || []).filter((x) => x && x.r && Date.now() - x.at < RECEIPT_MS) } catch { return [] } }
36
+ const saveReceipts = (list) => store.set(localStorage, RECEIPTS_KEY, JSON.stringify(list.slice(-20)))
37
+ export const keepReceipt = (r) => { const l = receipts().filter((x) => x.r !== r); l.push({ r, at: Date.now() }); saveReceipts(l); store.set(localStorage, `${RECEIPTS_KEY}-at`, String(Date.now())) }
38
+ export const dropReceipt = (r) => saveReceipts(receipts().filter((x) => x.r !== r))
39
+ const TYPING_MS = 2000
40
+ const MONTH = 30 * 86_400_000
41
+
42
+ const store = {
43
+ get: (s, k) => { try { return s.getItem(k) } catch { return null } },
44
+ set: (s, k, v) => { try { s.setItem(k, v) } catch { /* private mode */ } },
45
+ }
46
+
47
+ // '/checkout/*' and friends against the current path; no patterns: everywhere
48
+ export function pageMatches(patterns, path = location.pathname) {
49
+ if (!patterns?.length) return true
50
+ return patterns.some((p) => new RegExp(`^${p.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*')}$`).test(path))
51
+ }
52
+
53
+ // white or dark ink on the customer's colour, whichever reads
54
+ export function inkOn(hex) {
55
+ const n = parseInt(String(hex).slice(1), 16)
56
+ if (!Number.isFinite(n)) return '#fff'
57
+ const [r, g, b] = [n >> 16, (n >> 8) & 255, n & 255].map((c) => { c /= 255; return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4 })
58
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.4 ? '#0E1320' : '#fff'
59
+ }
60
+
61
+ const isMac = () => /Mac|iPhone|iPad/.test(globalThis.navigator?.platform || '')
62
+
63
+ // the shortcut as keycaps — ['Ctrl', 'Ctrl'], ['Alt', 'Shift', 'P'] — and in
64
+ // words; none when there is no shortcut
65
+ export function keyCaps(cfg, mac = isMac()) {
66
+ if (cfg.trigger === 'double-ctrl') return mac ? ['⌘', '⌘'] : ['Ctrl', 'Ctrl']
67
+ if (cfg.trigger === 'chord') return ['Alt', 'Shift', 'P']
68
+ if (cfg.trigger === 'hold-alt') return [mac ? '⌥' : 'Alt']
69
+ if (cfg.trigger === 'hold-ctrl') return ['Ctrl']
70
+ if (cfg.trigger === 'custom') return String(cfg.shortcut?.label || '').split('+').filter(Boolean)
71
+ return []
72
+ }
73
+ export function keysLabel(cfg, mac = isMac()) {
74
+ const caps = keyCaps(cfg, mac)
75
+ if (!caps.length) return ''
76
+ return cfg.trigger.startsWith('hold') ? `hold ${caps[0]}` : cfg.trigger === 'double-ctrl' ? caps.join(' ') : caps.join('+')
77
+ }
78
+ const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c])
79
+ // keycaps as markup, one <kbd> each (shared look: entry cards, the pill, Point's rail)
80
+ export const capsHtml = (caps, cls = 'kc') => caps.map((k) => `<kbd class="${cls}">${esc(k)}</kbd>`).join('')
81
+ // how a person is told to use the shortcut, in a sentence
82
+ export function keysSentence(cfg) {
83
+ const caps = keyCaps(cfg)
84
+ if (!caps.length) return ''
85
+ if (cfg.trigger === 'double-ctrl') return `Tap ${caps[0] === '⌘' ? '⌘' : 'Ctrl'} twice`
86
+ if (cfg.trigger.startsWith('hold')) return `Hold ${caps[0]}`
87
+ return `Press ${caps.join('+')}`
88
+ }
89
+
90
+ // the launcher the code asks for (data-launcher*, startRecording({ launcher }),
91
+ // Specto.launcher()) over the one Settings → Point gives: false hides it on
92
+ // this page; anything else is merged in, checked like the server checks it
93
+ const POSITIONS = ['bottom-right', 'bottom-left', 'edge']
94
+ export function launcherFrom(remote, local) {
95
+ if (local === false) return null
96
+ if (!local || typeof local !== 'object') return remote
97
+ const base = remote || { label: 'Report a problem', position: 'bottom-right', color: '#0E1320', pages: [] }
98
+ const off = Array.isArray(local.offset) ? local.offset.slice(0, 2).map((n) => Math.max(0, Math.min(600, Math.round(Number(n) || 0)))) : null
99
+ return {
100
+ ...base,
101
+ ...(POSITIONS.includes(local.position) ? { position: local.position } : {}),
102
+ ...(typeof local.label === 'string' && local.label.trim() ? { label: local.label.trim().slice(0, 40) } : {}),
103
+ ...(/^#[0-9a-f]{6}$/i.test(local.color || '') ? { color: local.color } : {}),
104
+ ...(off && off.length === 2 ? { offset: off } : {}),
105
+ }
106
+ }
107
+
108
+ // is a reminder due? (pure: the caller passes what the browser remembers)
109
+ export function hintDue(hint, { used, visits, last, release, now = Date.now() }) {
110
+ if (!hint || used) return false
111
+ if (hint.when === 'monthly') return !last || now - last.at >= MONTH
112
+ if (hint.when === 'release') return Boolean(release) && last?.release !== release
113
+ return visits >= 3 && !last // third-visit: once
114
+ }
115
+
116
+ // the newest failure in the recorder's memory after `since` that the
117
+ // project wants a nudge for → its time, or 0
118
+ export function failureSince(recent, kinds, since) {
119
+ let at = 0
120
+ if (kinds.includes('network')) for (const n of recent.network || []) if (n.at > since && (n.error || n.status >= 500)) at = Math.max(at, n.at)
121
+ for (const e of recent.event || []) {
122
+ if (e.at <= since) continue
123
+ if ((e.type === 'error' && kinds.includes('error')) || (e.type === 'rage' && kinds.includes('rage')) || (e.type === 'dead' && kinds.includes('dead'))) at = Math.max(at, e.at)
124
+ }
125
+ return at
126
+ }
127
+
128
+ export function mountEntry(rec, cfg, { open, may, local }) {
129
+ const p = rec._point
130
+ // a phone or a tablet has no keyboard shortcut to teach
131
+ const touch = typeof matchMedia === 'function' && matchMedia('(pointer: coarse)').matches
132
+ const caps = touch ? [] : keyCaps(cfg)
133
+ // count this visit once per tab session (the reminder's "3rd visit")
134
+ if (!store.get(sessionStorage, VISIT_FLAG)) {
135
+ store.set(sessionStorage, VISIT_FLAG, '1')
136
+ store.set(localStorage, VISITS_KEY, String((Number(store.get(localStorage, VISITS_KEY)) || 0) + 1))
137
+ }
138
+ const host = document.createElement('div')
139
+ host.id = 'specto-point-entry'
140
+ host.className = 'specto-block'
141
+ // the page can move it with CSS: #specto-point-entry { --specto-launcher-x: 24px;
142
+ // --specto-launcher-y: 96px; --specto-launcher-z: 900 } (custom properties
143
+ // cross the shadow root; \`all: initial\` leaves them alone)
144
+ host.setAttribute('style', 'all:initial;position:fixed;top:0;left:0;width:0;height:0;overflow:visible;z-index:var(--specto-launcher-z,2147483645)')
145
+ const root = host.attachShadow({ mode: 'open' })
146
+ let L = launcherFrom(cfg.launcher, local)
147
+ let me = {}
148
+ try { me = JSON.parse(store.get(localStorage, ME_KEY) || '{}') || {} } catch { /* corrupt */ }
149
+ const saveMe = (patch) => { me = { ...me, ...patch }; store.set(localStorage, ME_KEY, JSON.stringify(me)); drawLauncher(); tick() }
150
+ // where it sits: the visitor's side over the project's; an edge tab stays one
151
+ const sideOf = () => (L?.position === 'edge' ? 'edge' : me.side || (L?.position === 'bottom-left' ? 'left' : 'right'))
152
+ const nudgeSide = () => (sideOf() === 'left' ? 'left' : 'right')
153
+ root.innerHTML = `<style>${CSS}</style>
154
+ <button class="pill" type="button" hidden>
155
+ <svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="5.5"/><circle class="d" cx="8" cy="8" r="1.6"/></svg>
156
+ <span class="lbl"></span>${caps.length ? `<span class="keys" aria-hidden="true">${capsHtml(caps)}</span>` : ''}
157
+ </button>
158
+ <div class="menu lmenu" role="menu" aria-label="Report a problem button" hidden>
159
+ <button class="m-open" type="button" role="menuitem">${esc(L?.label || 'Report a problem')}</button>
160
+ <hr>
161
+ <button class="m-size" type="button" role="menuitem"></button>
162
+ <button class="m-side" type="button" role="menuitem"></button>
163
+ <button class="m-hide" type="button" role="menuitem">Hide for this visit</button>
164
+ <p class="tip">Or drag it out of the way</p>
165
+ </div>
166
+ <div class="menu cmenu" role="menu" aria-label="Report a problem here" hidden>
167
+ <button class="c-go" type="button" role="menuitem"><svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="5.5"/><circle class="d" cx="8" cy="8" r="1.6"/></svg>Report a problem here</button>
168
+ <p class="tip">Shift + right-click for the browser’s menu</p>
169
+ </div>
170
+ <div class="card nudge" role="dialog" aria-label="Something didn't work?" hidden>
171
+ <div class="hd"><span class="red" aria-hidden="true"></span><b>That didn’t work?</b></div>
172
+ <p>Show us what happened: point at it and say what you expected. Takes 20 seconds.</p>
173
+ <div class="row"><button class="go" type="button">Show us</button><button class="no" type="button">Not now</button>${caps.length ? `<span class="or">or ${capsHtml(caps)}</span>` : ''}</div>
174
+ </div>
175
+ <div class="card hint" role="dialog" aria-label="Report a problem" hidden>
176
+ <div class="hd">${caps.length ? `<span class="big" aria-hidden="true">${capsHtml(caps, 'kc lg')}</span>` : ''}<b>Spot something broken?</b></div>
177
+ <p>${caps.length ? `${keysSentence(cfg)}, click` : `${touch ? 'Tap' : 'Click'} “${esc(launcherFrom(cfg.launcher, local)?.label || 'Report a problem')}”, then ${touch ? 'tap' : 'click'}`} what’s wrong and tell us. We see exactly what you saw.</p>
178
+ <div class="row"><button class="go" type="button">Try it now</button><button class="no" type="button">Got it</button></div>
179
+ </div>`
180
+ const $ = (s) => root.querySelector(s)
181
+ document.documentElement.appendChild(host)
182
+ const pill = $('.pill')
183
+ const nudge = $('.nudge')
184
+ const hint = $('.hint')
185
+ const lmenu = $('.lmenu')
186
+ const cmenu = $('.cmenu')
187
+ // the launcher as it is now (Settings → Point, then the code's overrides)
188
+ function drawLauncher() {
189
+ pill.querySelector('.lbl').textContent = L?.label || ''
190
+ pill.className = `pill ${sideOf()}${me.compact && sideOf() !== 'edge' ? ' compact' : ''}`
191
+ pill.setAttribute('aria-label', L?.label || 'Report a problem')
192
+ pill.title = `${L?.label || 'Report a problem'}${caps.length ? ` (${keysLabel(cfg)})` : ''}`
193
+ pill.style.setProperty('--bg', L?.color || '#0E1320')
194
+ pill.style.setProperty('--ink', inkOn(L?.color || '#0E1320'))
195
+ for (const [i, v] of ['x', 'y'].entries()) {
196
+ const px = v === 'y' && Number.isFinite(me.y) ? me.y : L?.offset?.[i]
197
+ if (px != null) host.style.setProperty(`--specto-launcher-${v}`, `${px}px`)
198
+ else host.style.removeProperty(`--specto-launcher-${v}`)
199
+ }
200
+ lmenu.querySelector('.m-size').textContent = me.compact ? 'Show the label' : 'Make it smaller'
201
+ lmenu.querySelector('.m-side').textContent = sideOf() === 'left' ? 'Move it to the right' : 'Move it to the left'
202
+ lmenu.querySelector('.m-side').hidden = sideOf() === 'edge'
203
+ lmenu.querySelector('.m-size').hidden = sideOf() === 'edge'
204
+ nudge.classList.toggle('left', nudgeSide() === 'left')
205
+ nudge.classList.toggle('right', nudgeSide() === 'right')
206
+ // above the launcher when asked, or when they share a corner
207
+ const hintSide = cfg.hint?.where === 'launcher' ? nudgeSide() : cfg.hint?.where === 'bottom-left' ? 'left' : 'right'
208
+ hint.classList.toggle('left', hintSide === 'left')
209
+ hint.classList.toggle('right', hintSide === 'right')
210
+ hint.classList.toggle('by', Boolean(L) && L.position !== 'edge' && hintSide === nudgeSide())
211
+ }
212
+ drawLauncher()
213
+
214
+ // ---- the launcher: a click opens Point, a drag moves it, a right-click or
215
+ // a long press opens its menu ------------------------------------------------------
216
+ let drag = null // { x, y, moved }
217
+ let pressTimer = 0
218
+ let menuOpen = false
219
+ const closeMenus = () => { lmenu.hidden = true; cmenu.hidden = true; menuOpen = false }
220
+ function showLauncherMenu() {
221
+ closeMenus()
222
+ const r = pill.getBoundingClientRect()
223
+ lmenu.style.bottom = `${Math.max(8, innerHeight - r.top + 8)}px`
224
+ lmenu.style.left = sideOf() === 'left' ? `${Math.max(8, r.left)}px` : ''
225
+ lmenu.style.right = sideOf() === 'left' ? '' : `${Math.max(8, innerWidth - r.right)}px`
226
+ lmenu.hidden = false
227
+ menuOpen = true
228
+ lmenu.querySelector('button').focus()
229
+ }
230
+ pill.addEventListener('click', (e) => {
231
+ if (drag?.moved) { e.preventDefault(); return }
232
+ pill.hidden = true
233
+ open('launcher')
234
+ })
235
+ pill.addEventListener('contextmenu', (e) => { e.preventDefault(); e.stopPropagation(); showLauncherMenu() })
236
+ pill.addEventListener('pointerdown', (e) => {
237
+ if (e.button !== 0) return
238
+ drag = { x: e.clientX, y: e.clientY, moved: false }
239
+ // on a touch screen, a long press is the right-click
240
+ if (e.pointerType !== 'mouse') pressTimer = setTimeout(() => { if (drag && !drag.moved) { drag = null; showLauncherMenu() } }, 550)
241
+ })
242
+ const onDragMove = (e) => {
243
+ if (!drag) return
244
+ if (!drag.moved && Math.hypot(e.clientX - drag.x, e.clientY - drag.y) < 6) return
245
+ clearTimeout(pressTimer)
246
+ drag.moved = true
247
+ pill.classList.add('dragging')
248
+ const r = pill.getBoundingClientRect()
249
+ const edge = sideOf() === 'edge'
250
+ pill.style.left = `${edge ? innerWidth - r.width : Math.min(innerWidth - r.width - 8, Math.max(8, e.clientX - r.width / 2))}px`
251
+ pill.style.right = 'auto'
252
+ pill.style.top = `${Math.min(innerHeight - r.height - 8, Math.max(8, e.clientY - r.height / 2))}px`
253
+ pill.style.bottom = 'auto'
254
+ pill.style.transform = edge ? 'rotate(180deg)' : 'none'
255
+ }
256
+ const onDragEnd = (e) => {
257
+ clearTimeout(pressTimer)
258
+ if (!drag?.moved) { drag = null; return }
259
+ // it lands on the nearer side, as high as it was dropped
260
+ const r = pill.getBoundingClientRect()
261
+ pill.classList.remove('dragging')
262
+ for (const k of ['left', 'right', 'top', 'bottom', 'transform']) pill.style[k] = ''
263
+ const y = Math.round(Math.min(innerHeight - r.height - 8, Math.max(8, innerHeight - r.bottom)))
264
+ saveMe({ y, ...(sideOf() === 'edge' ? {} : { side: e.clientX < innerWidth / 2 ? 'left' : 'right' }) })
265
+ setTimeout(() => { drag = null }, 0) // the click that ends a drag opens nothing
266
+ }
267
+ window.addEventListener('pointermove', onDragMove, true)
268
+ window.addEventListener('pointerup', onDragEnd, true)
269
+ lmenu.querySelector('.m-open').addEventListener('click', () => { closeMenus(); pill.hidden = true; open('launcher') })
270
+ lmenu.querySelector('.m-size').addEventListener('click', () => { closeMenus(); saveMe({ compact: !me.compact }) })
271
+ lmenu.querySelector('.m-side').addEventListener('click', () => { closeMenus(); saveMe({ side: sideOf() === 'left' ? 'right' : 'left' }) })
272
+ lmenu.querySelector('.m-hide').addEventListener('click', () => { closeMenus(); store.set(sessionStorage, HIDDEN_KEY, '1'); tick() })
273
+
274
+ // ---- right-click on the page --------------------------------------------------------
275
+ let ctxTarget = null
276
+ // where the browser's own menu matters more: links, fields, media, selected text
277
+ const native = (t) => Boolean(t.closest('a[href],input,textarea,select,img,video,[contenteditable=""],[contenteditable="true"]')) || Boolean(String(getSelection?.() || '').trim())
278
+ const onContext = (e) => {
279
+ if (!cfg.context || cfg.context === 'off' || e.composedPath?.().includes(host) || document.getElementById('specto-point') || !may()) return
280
+ const t = e.target instanceof Element ? e.target : null
281
+ if (!t) return
282
+ if (e.shiftKey || e.altKey) {
283
+ // straight into Point with this element marked — except Shift on a
284
+ // 'menu' project, which the menu promises to the browser
285
+ if (cfg.context === 'menu' && e.shiftKey) return
286
+ e.preventDefault()
287
+ closeMenus()
288
+ open('context', t)
289
+ return
290
+ }
291
+ if (cfg.context !== 'menu' || native(t)) return
292
+ e.preventDefault()
293
+ closeMenus()
294
+ ctxTarget = t
295
+ cmenu.style.left = `${Math.min(e.clientX, innerWidth - 250)}px`
296
+ cmenu.style.top = `${Math.min(e.clientY, innerHeight - 90)}px`
297
+ cmenu.hidden = false
298
+ menuOpen = true
299
+ cmenu.querySelector('button').focus()
300
+ }
301
+ cmenu.querySelector('.c-go').addEventListener('click', () => { const t = ctxTarget; closeMenus(); if (t?.isConnected) open('context', t) })
302
+ window.addEventListener('contextmenu', onContext, true)
303
+ const onAway = (e) => { if (menuOpen && !e.composedPath?.().includes(host)) closeMenus() }
304
+ const onEsc = (e) => { if (menuOpen && e.key === 'Escape') { closeMenus(); pill.focus?.() } }
305
+ window.addEventListener('pointerdown', onAway, true)
306
+ window.addEventListener('keydown', onEsc, true)
307
+ window.addEventListener('scroll', closeMenus, { passive: true, capture: true })
308
+
309
+
310
+ // ---- the nudge --------------------------------------------------------------
311
+ let lastKey = 0
312
+ let nudgedAt = 0
313
+ let seen = Date.now()
314
+ const onKey = () => { lastKey = Date.now() }
315
+ window.addEventListener('keydown', onKey, true)
316
+ const hideNudge = () => { nudge.hidden = true }
317
+ nudge.querySelector('.go').addEventListener('click', () => { hideNudge(); open('nudge') })
318
+ nudge.querySelector('.no').addEventListener('click', hideNudge)
319
+
320
+ // ---- the reminder ---------------------------------------------------------------
321
+ let last = null
322
+ try { last = JSON.parse(store.get(localStorage, HINT_KEY) || 'null') } catch { /* corrupt */ }
323
+ const used = () => store.get(localStorage, USED_KEY) === '1'
324
+ const hideHint = () => { hint.hidden = true }
325
+ hint.querySelector('.go').addEventListener('click', () => { hideHint(); open('hint') })
326
+ hint.querySelector('.no').addEventListener('click', hideHint)
327
+ let hintChecked = false
328
+
329
+ // one tick for everything that can change under us: the page (SPAs), who
330
+ // the visitor is, Point opening and closing, new failures
331
+ const tick = () => {
332
+ const pointOpen = Boolean(document.getElementById('specto-point'))
333
+ const here = may() && !pointOpen
334
+ // a page that still uses the legacy feedback button (data-feedback) keeps
335
+ // its corner: Point replaces that button, it doesn't stack on it
336
+ const legacy = Boolean(document.getElementById('specto-feedback-host'))
337
+ const hiddenNow = store.get(sessionStorage, HIDDEN_KEY) === '1'
338
+ pill.hidden = !(L && here && !legacy && !hiddenNow && pageMatches(L.pages))
339
+ if (pill.hidden && !lmenu.hidden) closeMenus()
340
+ if (pointOpen) { hideNudge(); hideHint() }
341
+ if (cfg.nudge && here && !nudgedAt && !store.get(sessionStorage, NUDGED)) {
342
+ const at = failureSince(p.recent(), cfg.nudge, seen)
343
+ const typing = Date.now() - lastKey < TYPING_MS || /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement?.tagName || '') || document.activeElement?.isContentEditable
344
+ if (at && !typing) {
345
+ nudgedAt = Date.now()
346
+ store.set(sessionStorage, NUDGED, '1')
347
+ hideHint()
348
+ nudge.hidden = false
349
+ setTimeout(hideNudge, NUDGE_MS)
350
+ }
351
+ if (at) seen = at
352
+ }
353
+ if (cfg.hint && here && !hintChecked) {
354
+ hintChecked = true
355
+ const visits = Number(store.get(localStorage, VISITS_KEY)) || 0
356
+ if (hintDue(cfg.hint, { used: used(), visits, last, release: p.release })) {
357
+ store.set(localStorage, HINT_KEY, JSON.stringify({ at: Date.now(), release: p.release || null }))
358
+ setTimeout(() => { if (nudge.hidden && !document.getElementById('specto-point')) hint.hidden = false }, 1500)
359
+ }
360
+ }
361
+ }
362
+ tick()
363
+ const timer = setInterval(tick, 1000)
364
+ // Point opening or closing (by any route) shows at once, not on the next tick
365
+ const watch = new MutationObserver(tick)
366
+ watch.observe(document.documentElement, { childList: true })
367
+ return {
368
+ // Specto.launcher({ position, offset, label, color }) / launcher(false):
369
+ // the code changes the launcher on this page, e.g. per route
370
+ launcher(o) { L = launcherFrom(cfg.launcher, o); drawLauncher(); tick() },
371
+ stop() {
372
+ clearInterval(timer)
373
+ watch.disconnect()
374
+ window.removeEventListener('keydown', onKey, true)
375
+ window.removeEventListener('pointermove', onDragMove, true)
376
+ window.removeEventListener('pointerup', onDragEnd, true)
377
+ window.removeEventListener('contextmenu', onContext, true)
378
+ window.removeEventListener('pointerdown', onAway, true)
379
+ window.removeEventListener('keydown', onEsc, true)
380
+ window.removeEventListener('scroll', closeMenus, true)
381
+ host.remove()
382
+ },
383
+ }
384
+ }
385
+
386
+ // N2 on the design board: on a later visit, "Fixed: …" — once, on any page.
387
+ // items: [{ receipt, number, title, message }] from /api/point-status.
388
+ // "Still happening?" opens Point about that bug (a report reopens it).
389
+ export function showFixed(items, { open } = {}) {
390
+ const list = (items || []).filter((x) => x && x.title).slice(0, 3)
391
+ if (!list.length || document.getElementById('specto-point-fixed')) return null
392
+ const host = document.createElement('div')
393
+ host.id = 'specto-point-fixed'
394
+ host.className = 'specto-block'
395
+ host.setAttribute('style', 'all:initial;position:fixed;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483646')
396
+ const root = host.attachShadow({ mode: 'open' })
397
+ const it = list[0]
398
+ const more = list.length > 1 ? `<p class="more">And ${list.length - 1} more you reported ${list.length > 2 ? 'are' : 'is'} fixed too.</p>` : ''
399
+ root.innerHTML = `<style>${CSS}${FIXED_CSS}</style>
400
+ <div class="card fixed" role="status" aria-live="polite">
401
+ <button class="x" type="button" aria-label="Dismiss"><svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 3l6 6M9 3l-6 6"/></svg></button>
402
+ <div class="hd"><span class="okc" aria-hidden="true"><svg viewBox="0 0 12 12"><path d="M2.5 6.2 5 8.5 9.5 3.5"/></svg></span><b></b></div>
403
+ <p class="msg"></p>${more}
404
+ <div class="row"><button class="go" type="button">Got it</button><button class="no still" type="button">Still happening?</button></div>
405
+ </div>`
406
+ root.querySelector('b').textContent = `Fixed: ${it.title}`
407
+ root.querySelector('.msg').textContent = it.message || 'The fix is live. Thank you, it helped.'
408
+ const remove = () => host.remove()
409
+ root.querySelector('.x').addEventListener('click', remove)
410
+ root.querySelector('.go').addEventListener('click', remove)
411
+ root.querySelector('.still').addEventListener('click', () => { remove(); open?.('fixed', null, it.receipt) })
412
+ document.documentElement.appendChild(host)
413
+ return { close: remove }
414
+ }
415
+ const FIXED_CSS = `
416
+ .card.fixed{top:20px;right:20px;bottom:auto;width:340px;padding:16px 16px 14px}
417
+ .fixed .hd{align-items:flex-start;padding-right:22px}
418
+ .fixed .hd b{line-height:1.4}
419
+ .okc{width:22px;height:22px;flex:none;border-radius:50%;background:#14C8A6;display:flex;align-items:center;justify-content:center}
420
+ .okc svg{width:12px;height:12px;fill:none;stroke:#0E1320;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
421
+ .fixed .more{font-size:12px;color:#8A93A6}
422
+ .fixed .row{margin-top:2px}
423
+ .x{position:absolute;top:8px;right:8px;width:28px;height:28px;border:0;border-radius:6px;background:none;color:#8A93A6;display:flex;align-items:center;justify-content:center;cursor:pointer}
424
+ .x svg{width:12px;height:12px;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round}
425
+ .x:hover{color:#F4F5F8}
426
+ @media (max-width:480px){.card.fixed{left:12px;right:12px;width:auto}}
427
+ `
428
+
429
+ const CSS = `
430
+ :host{all:initial}
431
+ *{-webkit-user-select:none;user-select:none}
432
+ input,textarea{-webkit-user-select:text;user-select:text}
433
+ *{box-sizing:border-box;font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}
434
+ [hidden]{display:none!important}
435
+ .kc{display:inline-flex;align-items:center;justify-content:center;min-width:20px;height:20px;padding:0 5px;border:1px solid rgba(255,255,255,.22);border-bottom-width:2px;border-radius:5px;background:rgba(255,255,255,.06);color:inherit;font:600 10.5px/1 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:nowrap}
436
+ .kc.lg{min-width:34px;height:26px;padding:0 8px;font-size:12.5px;border-bottom-width:3px;border-radius:6px}
437
+ .keys,.or,.big{display:inline-flex;align-items:center;gap:3px}
438
+ .pill{position:fixed;bottom:var(--specto-launcher-y,20px);display:inline-flex;align-items:center;gap:10px;height:40px;padding:0 12px 0 11px;border:0;border-radius:999px;background:var(--bg,#0E1320);color:var(--ink,#fff);font:600 13px/1 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;cursor:pointer;box-shadow:0 8px 22px rgba(7,10,16,.28);white-space:nowrap}
439
+ .pill.right{right:var(--specto-launcher-x,20px)}.pill.left{left:var(--specto-launcher-x,20px)}
440
+ .pill .ic{width:16px;height:16px;flex:none;fill:none;stroke:#A9A0FF;stroke-width:1.6}
441
+ .pill .ic .d{fill:#A9A0FF;stroke:none}
442
+ .pill .keys{opacity:.7}
443
+ .pill .kc{height:18px;min-width:18px;border-color:currentColor;background:transparent;opacity:.85}
444
+ .pill.edge{right:0;bottom:auto;top:calc(50% + var(--specto-launcher-y,0px) - 20px);height:auto;padding:14px 9px;gap:8px;border-radius:10px 0 0 10px;writing-mode:vertical-rl;transform:translateY(-50%) rotate(180deg)}
445
+ .pill.edge .keys{display:none}
446
+ .pill:hover{filter:brightness(1.12)}
447
+ .pill:focus-visible,.card button:focus-visible{outline:2px solid #5B4BF0;outline-offset:2px}
448
+ .card{position:fixed;bottom:calc(var(--specto-launcher-y,20px) + 52px);width:330px;background:#0E1320;color:#F4F5F8;border-radius:12px;padding:14px 16px;box-shadow:0 12px 32px rgba(7,10,16,.35);font-size:13px;display:flex;flex-direction:column;gap:10px}
449
+ .card.right{right:var(--specto-launcher-x,20px)}.card.left{left:var(--specto-launcher-x,20px)}
450
+ .card.hint:not(.by){bottom:24px}
451
+ .hd{display:flex;align-items:center;gap:10px}
452
+ .hd b{font-size:14px;font-weight:600}
453
+ .red{width:8px;height:8px;border-radius:50%;background:#F87171;flex:none}
454
+ .card p{margin:0;line-height:1.5;color:#C3C8D4}
455
+ .row{display:flex;align-items:center;gap:10px}
456
+ .go{height:34px;padding:0 14px;background:#5B4BF0;border:0;color:#fff;border-radius:8px;font-weight:600;font-size:13px;cursor:pointer}
457
+ .no{height:34px;padding:0 10px;background:none;border:0;color:#8A93A6;font-size:13px;cursor:pointer}
458
+ .or{margin-left:auto;gap:4px;font-size:11px;color:#8A93A6}
459
+ .pill.compact{width:44px;height:44px;padding:0;justify-content:center;gap:0}
460
+ .pill.compact .lbl,.pill.compact .keys{display:none}
461
+ .pill.compact .ic{width:20px;height:20px}
462
+ .pill.compact::after{content:"";position:absolute;inset:-4px;border-radius:50%;border:2px solid rgba(169,160,255,.55);animation:sp-pulse 2.4s ease-out 2;pointer-events:none}
463
+ @keyframes sp-pulse{0%{transform:scale(.85);opacity:1}100%{transform:scale(1.35);opacity:0}}
464
+ .pill.dragging{cursor:grabbing;transition:none;box-shadow:0 14px 34px rgba(7,10,16,.4)}
465
+ .menu{position:fixed;min-width:210px;background:#0E1320;color:#F4F5F8;border:1px solid #2a3346;border-radius:10px;padding:5px;box-shadow:0 12px 32px rgba(7,10,16,.4);font-size:13px;display:flex;flex-direction:column}
466
+ .menu button{display:flex;align-items:center;gap:8px;text-align:left;background:none;border:0;color:inherit;font:inherit;padding:8px 10px;border-radius:7px;cursor:pointer}
467
+ .menu button:hover,.menu button:focus-visible{background:rgba(91,75,240,.22);outline:none}
468
+ .menu .m-open,.menu .c-go{font-weight:600}
469
+ .menu .ic{width:16px;height:16px;fill:none;stroke:#A9A0FF;stroke-width:1.6}
470
+ .menu .ic .d{fill:#A9A0FF;stroke:none}
471
+ .menu hr{border:0;border-top:1px solid #232c40;margin:4px 2px}
472
+ .menu .tip{margin:4px 10px 6px;font-size:11px;color:#8A93A6}
473
+ @media (prefers-reduced-motion:reduce){.pill.compact::after{animation:none;opacity:0}}
474
+ @media (max-width:480px){.card{width:calc(100vw - 40px)}}
475
+ `