@daybook/feedback 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -2
- package/dist/clearance.d.ts +73 -0
- package/dist/clearance.js +154 -0
- package/dist/feedback.js +12 -5
- package/dist/screenshot.d.ts +15 -0
- package/dist/screenshot.js +63 -7
- package/dist/types.d.ts +20 -0
- package/dist/widget.d.ts +45 -6
- package/dist/widget.js +183 -74
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -240,10 +240,47 @@ three days later when the reporter has moved on.
|
|
|
240
240
|
There is no setting that shows the control and then ignores it. A tick box that does nothing is
|
|
241
241
|
worse than no tick box.
|
|
242
242
|
|
|
243
|
+
## Where it sits
|
|
244
|
+
|
|
245
|
+
`placement` puts the widget in a corner: `bottom-right` (the default), `bottom-left`, `top-right`
|
|
246
|
+
or `top-left`. Set here it overrides the corner chosen in the workspace's own settings, which is
|
|
247
|
+
the right way round — the workspace owner is choosing a default for every install, and whoever
|
|
248
|
+
writes this line is looking at the page.
|
|
249
|
+
|
|
250
|
+
```js
|
|
251
|
+
init({ ingestKey: '...', placement: 'bottom-left' })
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### It moves out of your other buttons' way
|
|
255
|
+
|
|
256
|
+
Most pages already have something in the bottom-right corner: a chat bubble, a back-to-top arrow,
|
|
257
|
+
a cookie notice. The widget looks at what is painted in the corner it is about to occupy and stacks
|
|
258
|
+
above it rather than on it — including things that are not there yet, like a back-to-top button that
|
|
259
|
+
appears once the reporter scrolls, which is re-checked on scroll and whenever the page changes.
|
|
260
|
+
|
|
261
|
+
There is no list of selectors involved and there will not be one: what a chat bubble and a
|
|
262
|
+
back-to-top button have in common is not a class name, it is being fixed, painted and small in the
|
|
263
|
+
corner. Anything larger than a quarter of the viewport is treated as scenery — a modal backdrop is
|
|
264
|
+
not something to politely stack above — and if getting clear would mean moving more than a third of
|
|
265
|
+
the way up the page, it stays put and overlaps instead.
|
|
266
|
+
|
|
267
|
+
Turn it off with `avoidOverlap: false` if your page positions things by measuring ours, or if the
|
|
268
|
+
movement bothers you more than the overlap would.
|
|
269
|
+
|
|
243
270
|
## Moving the panel
|
|
244
271
|
|
|
245
|
-
The composer is dragged by its header and
|
|
246
|
-
|
|
272
|
+
The composer is dragged by its header, and lands against whichever side of the window it is let go
|
|
273
|
+
nearest — only that axis pins, so dragging it to the left edge halfway down leaves it halfway down.
|
|
274
|
+
A double-click on the header puts it back.
|
|
275
|
+
|
|
276
|
+
**A drag lasts for one report.** Sending resets it, so does closing, and the next report opens where
|
|
277
|
+
`placement` says. It used to be remembered across visits, which sounds helpful and is not: the
|
|
278
|
+
widget then turns up somewhere different on every page, and the somewhere is wherever it was last
|
|
279
|
+
shoved aside — a position chosen to be temporary.
|
|
280
|
+
|
|
281
|
+
The confirmation always appears at home, never where the panel was dragged to. The reporter moved
|
|
282
|
+
the panel to see what was under it; putting the receipt back over that same spot answers a question
|
|
283
|
+
nobody asked and covers the thing they moved it for.
|
|
247
284
|
|
|
248
285
|
It closes on the cross or on Cancel, and on nothing else — not Escape, not a click on the page
|
|
249
286
|
behind it. Every one of those gestures gets pressed while a report is being written, and each of
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Getting out of the way of the host page's own floating furniture.
|
|
3
|
+
*
|
|
4
|
+
* A launcher pinned to the bottom-right corner is pinned to the same corner every other widget on
|
|
5
|
+
* the web chose: a chat bubble, a cookie bar's dismiss, a back-to-top arrow. On a page that already
|
|
6
|
+
* has one, ours lands on top of it, and the reporter is left with two controls sharing one square of
|
|
7
|
+
* screen — usually with theirs underneath, since we deliberately sit high in the stacking order.
|
|
8
|
+
*
|
|
9
|
+
* So before rendering, we look at what is already there and stack above it.
|
|
10
|
+
*
|
|
11
|
+
* <h3>Looking, not guessing</h3>
|
|
12
|
+
*
|
|
13
|
+
* There is no list of selectors here and there should not be one. `.intercom-launcher`,
|
|
14
|
+
* `#hubspot-messages-iframe-container`, `.crisp-client` — a list like that is a promise to keep
|
|
15
|
+
* chasing other people's class names, and it answers nothing about the bespoke button somebody's
|
|
16
|
+
* designer added last week. What every one of them has in common is not a name: it is being
|
|
17
|
+
* painted, fixed, and small, in the corner we want. That is a question the browser can answer
|
|
18
|
+
* directly, so we ask it — elementsFromPoint over the corner we are about to occupy.
|
|
19
|
+
*
|
|
20
|
+
* <h3>The one that is not there yet</h3>
|
|
21
|
+
*
|
|
22
|
+
* Back-to-top buttons are the hard case, and the common one: they do not exist, or are hidden, until
|
|
23
|
+
* the reporter scrolls. A measurement taken once at startup sees nothing and is wrong for the rest
|
|
24
|
+
* of the visit — which is precisely when somebody is deep in a page and wants to report something.
|
|
25
|
+
*
|
|
26
|
+
* The answer is to keep asking: on scroll, on resize, and when the DOM changes. All three are cheap
|
|
27
|
+
* because the probe is a fixed handful of hit tests rather than a walk of the document, and the
|
|
28
|
+
* caller throttles them into one measurement per frame at most.
|
|
29
|
+
*
|
|
30
|
+
* <h3>Measured from home, always</h3>
|
|
31
|
+
*
|
|
32
|
+
* The probe reads the corner the widget was CONFIGURED into, never the corner it has been pushed to.
|
|
33
|
+
* Reading its own current position would make the measurement depend on its own last answer: shift
|
|
34
|
+
* up to clear a chat bubble, and the next probe finds the space below newly empty and shifts back
|
|
35
|
+
* down onto it, for ever. Measuring the fixed home makes the answer a property of the page.
|
|
36
|
+
*/
|
|
37
|
+
export interface Slot {
|
|
38
|
+
/** The home corner's box, in viewport coordinates. */
|
|
39
|
+
left: number;
|
|
40
|
+
right: number;
|
|
41
|
+
top: number;
|
|
42
|
+
bottom: number;
|
|
43
|
+
/** Which edge the offset is measured from — the side we would grow away from. */
|
|
44
|
+
v: 'top' | 'bottom';
|
|
45
|
+
}
|
|
46
|
+
export interface Box {
|
|
47
|
+
top: number;
|
|
48
|
+
bottom: number;
|
|
49
|
+
left: number;
|
|
50
|
+
right: number;
|
|
51
|
+
}
|
|
52
|
+
export interface Viewport {
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* How far to shift, given what is in the way.
|
|
58
|
+
*
|
|
59
|
+
* Pure, and exported for that reason: the arithmetic is the part with the off-by-one in it, and it
|
|
60
|
+
* is the part that can be tested without a browser.
|
|
61
|
+
*/
|
|
62
|
+
export declare function shiftFor(slot: Slot, boxes: Box[], viewport: Viewport): number;
|
|
63
|
+
/**
|
|
64
|
+
* What is painted in the corner we want, right now.
|
|
65
|
+
*
|
|
66
|
+
* elementsFromPoint rather than a query: it answers with what the browser would actually hit,
|
|
67
|
+
* through shadow roots and whatever the host's stacking order turned out to be, and it costs a hit
|
|
68
|
+
* test rather than a walk. It skips `pointer-events: none`, which is the correct bias — something
|
|
69
|
+
* the reporter cannot click is something we are not stealing a click from.
|
|
70
|
+
*/
|
|
71
|
+
export declare function obstructions(slot: Slot, ours: Element, viewport: Viewport): Box[];
|
|
72
|
+
/** The whole question in one call: how far out of the way to move, in pixels. */
|
|
73
|
+
export declare function measureClearance(slot: Slot, ours: Element): number;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Getting out of the way of the host page's own floating furniture.
|
|
3
|
+
*
|
|
4
|
+
* A launcher pinned to the bottom-right corner is pinned to the same corner every other widget on
|
|
5
|
+
* the web chose: a chat bubble, a cookie bar's dismiss, a back-to-top arrow. On a page that already
|
|
6
|
+
* has one, ours lands on top of it, and the reporter is left with two controls sharing one square of
|
|
7
|
+
* screen — usually with theirs underneath, since we deliberately sit high in the stacking order.
|
|
8
|
+
*
|
|
9
|
+
* So before rendering, we look at what is already there and stack above it.
|
|
10
|
+
*
|
|
11
|
+
* <h3>Looking, not guessing</h3>
|
|
12
|
+
*
|
|
13
|
+
* There is no list of selectors here and there should not be one. `.intercom-launcher`,
|
|
14
|
+
* `#hubspot-messages-iframe-container`, `.crisp-client` — a list like that is a promise to keep
|
|
15
|
+
* chasing other people's class names, and it answers nothing about the bespoke button somebody's
|
|
16
|
+
* designer added last week. What every one of them has in common is not a name: it is being
|
|
17
|
+
* painted, fixed, and small, in the corner we want. That is a question the browser can answer
|
|
18
|
+
* directly, so we ask it — elementsFromPoint over the corner we are about to occupy.
|
|
19
|
+
*
|
|
20
|
+
* <h3>The one that is not there yet</h3>
|
|
21
|
+
*
|
|
22
|
+
* Back-to-top buttons are the hard case, and the common one: they do not exist, or are hidden, until
|
|
23
|
+
* the reporter scrolls. A measurement taken once at startup sees nothing and is wrong for the rest
|
|
24
|
+
* of the visit — which is precisely when somebody is deep in a page and wants to report something.
|
|
25
|
+
*
|
|
26
|
+
* The answer is to keep asking: on scroll, on resize, and when the DOM changes. All three are cheap
|
|
27
|
+
* because the probe is a fixed handful of hit tests rather than a walk of the document, and the
|
|
28
|
+
* caller throttles them into one measurement per frame at most.
|
|
29
|
+
*
|
|
30
|
+
* <h3>Measured from home, always</h3>
|
|
31
|
+
*
|
|
32
|
+
* The probe reads the corner the widget was CONFIGURED into, never the corner it has been pushed to.
|
|
33
|
+
* Reading its own current position would make the measurement depend on its own last answer: shift
|
|
34
|
+
* up to clear a chat bubble, and the next probe finds the space below newly empty and shifts back
|
|
35
|
+
* down onto it, for ever. Measuring the fixed home makes the answer a property of the page.
|
|
36
|
+
*/
|
|
37
|
+
/** Space left between us and whatever we are stacking above. */
|
|
38
|
+
const GAP = 12;
|
|
39
|
+
/**
|
|
40
|
+
* The most we will move.
|
|
41
|
+
*
|
|
42
|
+
* Past this the cure is worse than the overlap: a widget a third of the way up someone's page reads
|
|
43
|
+
* as broken, and a chat panel somebody has OPENED is full height, which would otherwise push us off
|
|
44
|
+
* the top of the screen. Beyond the cap we stay home and overlap, which at least looks deliberate.
|
|
45
|
+
*/
|
|
46
|
+
const MAX_SHIFT = 0.35;
|
|
47
|
+
/**
|
|
48
|
+
* How far apart the hit tests are, across and up. Smaller finds smaller furniture; larger costs less.
|
|
49
|
+
*
|
|
50
|
+
* The first version sampled three columns — both edges and the middle — and missed a 60px chat
|
|
51
|
+
* bubble sitting between two of them, which is the single most common thing this exists to avoid.
|
|
52
|
+
* A grid only has to TOUCH a candidate once, since the element's own rect is what gets measured
|
|
53
|
+
* afterwards, but it does have to touch it: the spacing has to be smaller than the smallest thing
|
|
54
|
+
* worth dodging, not smaller than the area being searched.
|
|
55
|
+
*/
|
|
56
|
+
const STEP = 32;
|
|
57
|
+
/**
|
|
58
|
+
* Anything bigger than this share of the viewport is scenery, not furniture.
|
|
59
|
+
*
|
|
60
|
+
* A modal backdrop, a cookie wall, a sticky header spanning the page — none of them are things to
|
|
61
|
+
* politely stack above, and treating one as furniture would launch us into the middle of the page.
|
|
62
|
+
*/
|
|
63
|
+
const MAX_AREA = 0.25;
|
|
64
|
+
/**
|
|
65
|
+
* How far to shift, given what is in the way.
|
|
66
|
+
*
|
|
67
|
+
* Pure, and exported for that reason: the arithmetic is the part with the off-by-one in it, and it
|
|
68
|
+
* is the part that can be tested without a browser.
|
|
69
|
+
*/
|
|
70
|
+
export function shiftFor(slot, boxes, viewport) {
|
|
71
|
+
let taken = 0;
|
|
72
|
+
for (const box of boxes) {
|
|
73
|
+
// Only what actually sits in our column. A button in the opposite corner is not our problem.
|
|
74
|
+
if (box.right <= slot.left || box.left >= slot.right)
|
|
75
|
+
continue;
|
|
76
|
+
// How far the obstruction reaches from our edge towards the middle of the screen.
|
|
77
|
+
const reach = slot.v === 'bottom' ? viewport.height - box.top : box.bottom;
|
|
78
|
+
if (reach > taken)
|
|
79
|
+
taken = reach;
|
|
80
|
+
}
|
|
81
|
+
if (taken === 0)
|
|
82
|
+
return 0;
|
|
83
|
+
// Our own edge already clears part of it: the shift is only what is left over.
|
|
84
|
+
const occupied = slot.v === 'bottom' ? viewport.height - slot.bottom : slot.top;
|
|
85
|
+
const shift = Math.round(taken + GAP - occupied);
|
|
86
|
+
if (shift <= 0)
|
|
87
|
+
return 0;
|
|
88
|
+
return shift > viewport.height * MAX_SHIFT ? 0 : shift;
|
|
89
|
+
}
|
|
90
|
+
/** Whether an element is furniture we should stack above, rather than scenery or ourselves. */
|
|
91
|
+
function isFurniture(element, ours, viewport) {
|
|
92
|
+
if (element === ours || ours.contains(element) || element.contains(ours))
|
|
93
|
+
return false;
|
|
94
|
+
if (element === document.body || element === document.documentElement)
|
|
95
|
+
return false;
|
|
96
|
+
const style = getComputedStyle(element);
|
|
97
|
+
// Only what floats. Anything in the normal flow scrolls away on its own and is not competing for
|
|
98
|
+
// this corner — it merely happens to be under the point we sampled.
|
|
99
|
+
if (style.position !== 'fixed' && style.position !== 'sticky')
|
|
100
|
+
return false;
|
|
101
|
+
if (style.visibility === 'hidden' || style.display === 'none')
|
|
102
|
+
return false;
|
|
103
|
+
if (Number(style.opacity) === 0)
|
|
104
|
+
return false;
|
|
105
|
+
const rect = element.getBoundingClientRect();
|
|
106
|
+
if (rect.width < 8 || rect.height < 8)
|
|
107
|
+
return false;
|
|
108
|
+
if ((rect.width * rect.height) > viewport.width * viewport.height * MAX_AREA)
|
|
109
|
+
return false;
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* What is painted in the corner we want, right now.
|
|
114
|
+
*
|
|
115
|
+
* elementsFromPoint rather than a query: it answers with what the browser would actually hit,
|
|
116
|
+
* through shadow roots and whatever the host's stacking order turned out to be, and it costs a hit
|
|
117
|
+
* test rather than a walk. It skips `pointer-events: none`, which is the correct bias — something
|
|
118
|
+
* the reporter cannot click is something we are not stealing a click from.
|
|
119
|
+
*/
|
|
120
|
+
export function obstructions(slot, ours, viewport) {
|
|
121
|
+
if (typeof document.elementsFromPoint !== 'function')
|
|
122
|
+
return [];
|
|
123
|
+
const found = new Map();
|
|
124
|
+
const xs = [];
|
|
125
|
+
for (let x = slot.left + 4; x < slot.right; x += STEP)
|
|
126
|
+
xs.push(x);
|
|
127
|
+
xs.push(slot.right - 4);
|
|
128
|
+
const limit = viewport.height * MAX_SHIFT;
|
|
129
|
+
for (let away = 0; away <= limit; away += STEP) {
|
|
130
|
+
const y = slot.v === 'bottom' ? slot.bottom - away : slot.top + away;
|
|
131
|
+
if (y < 0 || y > viewport.height)
|
|
132
|
+
break;
|
|
133
|
+
for (const x of xs) {
|
|
134
|
+
if (x < 0 || x > viewport.width)
|
|
135
|
+
continue;
|
|
136
|
+
for (const element of document.elementsFromPoint(x, y)) {
|
|
137
|
+
if (found.has(element))
|
|
138
|
+
continue;
|
|
139
|
+
if (!isFurniture(element, ours, viewport))
|
|
140
|
+
continue;
|
|
141
|
+
const rect = element.getBoundingClientRect();
|
|
142
|
+
found.set(element, {
|
|
143
|
+
top: rect.top, bottom: rect.bottom, left: rect.left, right: rect.right,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return [...found.values()];
|
|
149
|
+
}
|
|
150
|
+
/** The whole question in one call: how far out of the way to move, in pixels. */
|
|
151
|
+
export function measureClearance(slot, ours) {
|
|
152
|
+
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
153
|
+
return shiftFor(slot, obstructions(slot, ours, viewport), viewport);
|
|
154
|
+
}
|
package/dist/feedback.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
"use strict";var DaybookFeedback=(()=>{var C=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var ge=Object.prototype.hasOwnProperty;var be=(n,e)=>{for(var t in e)C(n,t,{get:e[t],enumerable:!0})},ye=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of me(e))!ge.call(n,r)&&r!==t&&C(n,r,{get:()=>e[r],enumerable:!(o=fe(e,r))||o.enumerable});return n};var we=n=>ye(C({},"__esModule",{value:!0}),n);var qe={};be(qe,{DEFAULT_API_URL:()=>ue,DaybookFeedback:()=>A,captureAnchor:()=>_,init:()=>Oe,resolveAnchor:()=>se});function v(n){var e;try{let t=new URL(n,location.href);return t.origin===location.origin?t.pathname:`${t.origin}${t.pathname}`}catch{return(e=n.split("?")[0])!=null?e:n}}function P(n){var o,r,i,s,a,c;let e=n.tagName.toLowerCase();if(!n.getAttribute("aria-label")&&!n.getAttribute("data-testid")&&!((o=n.textContent)!=null?o:"").trim()){let d=n.closest("button, a, [role=button], [data-testid], label");if(d&&d!==n)return P(d)}if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement){let d=(i=(r=n.getAttribute("name"))!=null?r:n.id)!=null?i:"",u=n instanceof HTMLInputElement?n.type:e;return`${e}[${u}]${d?` name=${d}`:""}`}let t=(c=(s=n.getAttribute("aria-label"))!=null?s:n.getAttribute("data-testid"))!=null?c:((a=n.textContent)!=null?a:"").replace(/\s+/g," ").trim().slice(0,40);return t?`${e} "${t}"`:e}function Q(n){return n.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"[email]").replace(/\b[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,"[jwt]").replace(/\bBearer\s+[\w.-]+/gi,"Bearer [redacted]").replace(/\b\d{12,19}\b/g,"[number]").slice(0,500)}var Z="data-daybook-private";var k=class{constructor(e=40,t=!0){this.limit=e;this.redact=t;this.entries=[];this.detach=[]}list(){return[...this.entries]}add(e,t){for(this.entries.push({at:new Date().toISOString(),type:e,message:this.redact?Q(t):t.slice(0,500)});this.entries.length>this.limit;)this.entries.shift()}start(){let e=a=>{let c=a.target;c instanceof Element&&(c.closest("[data-daybook-feedback]")||this.add("click",P(c)))};document.addEventListener("click",e,{capture:!0,passive:!0}),this.detach.push(()=>document.removeEventListener("click",e,{capture:!0}));let t=history.pushState,o=history.replaceState,r=()=>this.add("nav",v(location.href));history.pushState=(...a)=>{t.apply(history,a),r()},history.replaceState=(...a)=>{o.apply(history,a),r()},window.addEventListener("popstate",r),this.detach.push(()=>{history.pushState=t,history.replaceState=o,window.removeEventListener("popstate",r)});for(let a of["error","warn"]){let c=console[a];console[a]=(...d)=>{this.add("console",`${a}: ${d.map(F).join(" ")}`),c.apply(console,d)},this.detach.push(()=>{console[a]=c})}let i=a=>this.add("console",`uncaught: ${a.message}`),s=a=>this.add("console",`unhandled rejection: ${F(a.reason)}`);window.addEventListener("error",i),window.addEventListener("unhandledrejection",s),this.detach.push(()=>{window.removeEventListener("error",i),window.removeEventListener("unhandledrejection",s)}),this.watchFetch()}stop(){for(let e of this.detach.splice(0))e()}watchFetch(){if(typeof window.fetch!="function")return;let e=window.fetch;window.fetch=async(...t)=>{let o=performance.now();try{let r=await e.apply(window,t),i=Math.round(performance.now()-o);return(!r.ok||i>3e3)&&this.add("network",`${r.status} ${v(G(t[0]))} ${i}ms`),r}catch(r){throw this.add("network",`failed ${v(G(t[0]))}: ${F(r)}`),r}},this.detach.push(()=>{window.fetch=e})}};function G(n){return typeof n=="string"?n:n instanceof URL?n.href:n.url}function F(n){var e,t;if(typeof n=="string")return n;if(n instanceof Error)return`${n.name}: ${n.message}`;try{return(t=(e=JSON.stringify(n))==null?void 0:e.slice(0,200))!=null?t:String(n)}catch{return String(n)}}var j="pm.feedback.queue";var T=class{constructor(e,t){this.apiUrl=e;this.ingestKey=t;this.session=null;this.identityToken=null}setSession(e){this.session=e}async send(e,t=[],o){var c,d,u;let r={idempotencyKey:(c=e.idempotencyKey)!=null?c:ee(),...e,attachments:[...(d=e.attachments)!=null?d:[],...t.map(p=>({filename:p.filename,contentType:p.contentType,size:p.blob.size}))]},i=await this.post("/ingest/v1",r);if(!i.ok)throw await E(i);let s=await i.json(),a=((u=e.attachments)!=null?u:[]).length;return await Promise.all(t.map(async(p,m)=>{let g=ve(s,a+m);if(!g){o==null||o(p,new Error("The server would not accept that file."));return}try{await this.upload(g,p)}catch(y){o==null||o(p,y)}})),s}async flush(){let e=ne();if(e.length!==0){oe([]);for(let t of e)try{let o=await this.post("/ingest/v1",t);!o.ok&&(o.status===429||o.status>=500)&&O(t)}catch{O(t)}}}queue(e){var t;O({...e,idempotencyKey:(t=e.idempotencyKey)!=null?t:ee(),attachments:void 0})}async signIn(){let e=te(64),t=await xe(e),o=te(16),r=`${this.base()}/ingest/v1/authorize?key=${encodeURIComponent(this.ingestKey)}&origin=${encodeURIComponent(location.origin)}&code_challenge=${encodeURIComponent(t)}&state=${encodeURIComponent(o)}`,i=window.open(r,"daybook-feedback","width=460,height=640");if(!i)throw Object.assign(new Error("Popup blocked"),{code:"popup_blocked"});let s=await new Promise((d,u)=>{let p=setInterval(()=>{i.closed&&(g(),u(Object.assign(new Error("Sign-in cancelled"),{code:"cancelled"})))},400),m=y=>{if(y.origin!==new URL(this.base()).origin)return;let f=y.data;if((f==null?void 0:f.source)==="daybook-feedback"&&f.state===o){if(g(),f.error||!f.code){u(Object.assign(new Error("Sign-in was refused"),{code:f.error||"refused"}));return}d(f.code)}},g=()=>{clearInterval(p),window.removeEventListener("message",m)};window.addEventListener("message",m)}),a=await this.post("/ingest/v1/token",{code:s,codeVerifier:e});if(!a.ok)throw await E(a);let{identityToken:c}=await a.json();return this.identityToken=c,c}base(){return this.apiUrl.replace(/\/$/,"")}resolve(e){try{let t=new URL(this.base()),o=new URL(e,t);return o.hostname===t.hostname?new URL(o.pathname+o.search,t).toString():o.toString()}catch{return e}}async handshake(e){var r,i;let t=await this.post("/ingest/v1/session",{...e,identityToken:(r=this.identityToken)!=null?r:void 0});if(!t.ok)throw await E(t);let o=await t.json();return this.session=(i=o.sessionToken)!=null?i:null,o}post(e,t){let o={"Content-Type":"application/json","X-Ingest-Key":this.ingestKey};return this.session&&(o["X-Feedback-Session"]=this.session),fetch(`${this.base()}${e}`,{method:"POST",headers:o,body:JSON.stringify(t),credentials:"omit"})}async upload(e,t){let o=await fetch(this.resolve(e.uploadUrl),{method:e.method,headers:{"Content-Type":e.contentType,"X-Ingest-Key":this.ingestKey},body:t.blob,credentials:"omit"});if(!o.ok)throw await E(o);await this.post(`/ingest/v1/attachments/${e.id}/confirm`,{})}};function ve(n,e){let t=n.attachments.find(o=>o.index===e);return t!=null?t:n.attachments.some(o=>typeof o.index=="number")?void 0:n.attachments[e]}function O(n){let e=ne();e.push(n),oe(e.slice(-20))}function ne(){try{let n=localStorage.getItem(j);return n?JSON.parse(n):[]}catch{return[]}}function oe(n){try{n.length===0?localStorage.removeItem(j):localStorage.setItem(j,JSON.stringify(n))}catch{}}async function E(n){let e=`http_${n.status}`;try{let t=await n.json();if(t.code&&(e=t.code),t.message)return Object.assign(new Error(t.message),{code:e})}catch{}return Object.assign(new Error(`Ingest failed (${n.status})`),{code:e})}function ee(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function te(n){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=new Uint8Array(n);return crypto.getRandomValues(t),Array.from(t,o=>e[o%e.length]).join("")}async function xe(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function q(n){var t;let e={platform:"web",route:location.pathname,title:document.title.slice(0,200),locale:navigator.language,timezone:Ee(),viewport:{width:window.innerWidth,height:window.innerHeight,dpr:(t=window.devicePixelRatio)!=null?t:1},device:ke()};return document.referrer&&(e.referrer=v(document.referrer)),n.app&&(e.app=n.app),n.anchor&&(e.anchor=n.anchor),n.breadcrumbs&&n.breadcrumbs.length>0&&(e.breadcrumbs=n.breadcrumbs),e}function ke(){var r;let n=navigator.userAgent,e=/Edg\//.test(n)?"Edge":/OPR\//.test(n)?"Opera":/Firefox\//.test(n)?"Firefox":/Chrome\//.test(n)?"Chrome":/Safari\//.test(n)?"Safari":"Unknown",t=/Windows NT/.test(n)?"Windows":/iPhone|iPad|iPod/.test(n)?"iOS":/Mac OS X/.test(n)?"macOS":/Android/.test(n)?"Android":/Linux/.test(n)?"Linux":"Unknown",o=(r=n.match(/(?:Edg|OPR|Firefox|Chrome|Version)\/(\d+)/))==null?void 0:r[1];return{browser:o?`${e} ${o}`:e,os:t,touch:navigator.maxTouchPoints>0,userAgent:n.slice(0,300)}}function Ee(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return`UTC${-new Date().getTimezoneOffset()/60}`}}async function re(n,e=()=>()=>{}){var i;if(typeof((i=navigator.mediaDevices)==null?void 0:i.getDisplayMedia)!="function")return null;let t=n?Le():()=>{},o=e(),r=null;try{if(r=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include",surfaceSwitching:"exclude",monitorTypeSurfaces:"exclude"}),!r.getVideoTracks()[0])return null;await new Promise(c=>setTimeout(c,250));let a=await Te(r);return a?{blob:a,filename:"screenshot.png",contentType:"image/png"}:null}catch{return null}finally{r==null||r.getTracks().forEach(s=>s.stop()),o(),t()}}async function Te(n){let e=document.createElement("video");e.srcObject=n,e.muted=!0,await e.play().catch(()=>{});let t=document.createElement("canvas");t.width=e.videoWidth||window.innerWidth,t.height=e.videoHeight||window.innerHeight;let o=t.getContext("2d");return o?(o.drawImage(e,0,0,t.width,t.height),e.pause(),e.srcObject=null,new Promise(r=>t.toBlob(i=>r(i),"image/png"))):null}function Le(){let n=[...document.querySelectorAll(`[${Z}]`),...document.querySelectorAll('input[type="password"]')],e=n.map(t=>t.style.filter);return n.forEach(t=>{t.style.filter="blur(12px)"}),()=>{n.forEach((t,o)=>{var r;t.style.filter=(r=e[o])!=null?r:""})}}function _(n,e){let t=document.elementFromPoint(n,e);if(!(t instanceof HTMLElement))return{selector:null,offsetX:S(n/window.innerWidth),offsetY:S(e/window.innerHeight),elementText:null};let o=t.getBoundingClientRect();return{selector:Se(t),offsetX:o.width>0?S((n-o.left)/o.width):0,offsetY:o.height>0?S((e-o.top)/o.height):0,elementText:_e(t)}}function se(n){if(!n.selector)return{x:n.offsetX*window.innerWidth,y:n.offsetY*window.innerHeight};let e=null;try{e=document.querySelector(n.selector)}catch{return null}if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+n.offsetX*t.width,y:t.top+n.offsetY*t.height}}function Se(n){if(n===document.body)return"body";for(let r of["data-testid","data-test","data-daybook-id","data-cy"]){let i=n.getAttribute(r);if(i){let s=`[${r}="${U(i)}"]`;if(L(s))return s}}if(n.id&&!ie(n.id)){let r=`#${U(n.id)}`;if(L(r))return r}let e=[],t=n;for(;t&&t!==document.body&&e.length<8;){let r=t.tagName.toLowerCase(),i=Array.from(t.classList).filter(c=>!ie(c)).slice(0,2);i.length>0&&(r+=i.map(c=>`.${U(c)}`).join(""));let s=t.parentElement;if(s){let c=Array.from(s.children).filter(d=>d.tagName===t.tagName);c.length>1&&(r+=`:nth-of-type(${c.indexOf(t)+1})`)}e.unshift(r);let a=e.join(" > ");if(L(a))return a;t=s}let o=e.length>0?`body > ${e.join(" > ")}`:null;return o&&L(o)?o:null}function L(n){try{return document.querySelectorAll(n).length===1}catch{return!1}}function ie(n){return/^[a-z]{1,3}[0-9a-f]{5,}$/i.test(n)||/--[0-9a-f]{5,}$/i.test(n)||/^_[0-9a-z]{5,}/i.test(n)||/^v-[0-9a-f]{6,}$/i.test(n)||/^ng-/.test(n)||/[0-9a-f]{8,}/i.test(n)}function _e(n){var o,r,i;let t=((r=(o=n.innerText)!=null?o:n.textContent)!=null?r:"").replace(/\s+/g," ").trim();if(!t){let s=(i=n.getAttribute("aria-label"))!=null?i:n.getAttribute("title");return(s==null?void 0:s.trim())||null}return t.length>80?`${t.slice(0,77)}\u2026`:t}function S(n){return Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}function U(n){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/([^\w-])/g,"\\$1")}var Re=/^(image\/(png|jpeg|gif|webp)|video\/(mp4|quicktime|webm))$/;function ae(n,e){let t=[];for(let o of n){if(e+t.length>=5)break;let r=Re.test(o.type)?o.size>26214400?`Too large (${(o.size/1048576).toFixed(1)} MB, max 25).`:null:"Only images and short videos.";t.push({blob:o,filename:o.name||`pasted-${t.length+1}.${$e(o.type)}`,contentType:o.type,preview:r?null:URL.createObjectURL(o),error:r})}return t}function ce(n){var o;let e=(o=n.clipboardData)==null?void 0:o.items;if(!e)return[];let t=[];for(let r of e){if(r.kind!=="file")continue;let i=r.getAsFile();i&&t.push(i)}return t}function R(n){for(let e of n)e.preview&&URL.revokeObjectURL(e.preview)}function $e(n){var e,t;return(t=(e=n.split("/")[1])==null?void 0:e.replace("quicktime","mov"))!=null?t:"bin"}function le(n){var o;let t=(o=(typeof n.composedPath=="function"?n.composedPath():[])[0])!=null?o:n.target;return!t||t.nodeType!==1?!1:/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)?!0:typeof t.closest=="function"&&t.closest('[contenteditable=""], [contenteditable="true"]')!==null}var M=class{constructor(e,t){this.options=e;this.onSubmit=t;this.mode="idle";this.anchor=null;this.detach=[];this.state="ready";this.policy=null;this.placement=Ie();this.reference=null;this.uploadsFailed=0;this.host=document.createElement("div"),this.host.setAttribute("data-daybook-feedback",""),this.host.style.cssText="position:fixed;inset:0;z-index:2147483000;pointer-events:none",this.root=this.host.attachShadow({mode:"open"}),this.root.innerHTML=`<style>${Fe}</style><style id="theme"></style><div id="layer"></div>`}setTheme(e){var s,a;let t=this.root.getElementById("theme");if(!t)return;if(!e){t.textContent="";return}let o=[];Pe(e.accent)&&o.push(`--pm-accent: ${e.accent}`);let r={none:"0",sm:"6px",md:"12px",lg:"18px"}[(s=e.cornerRadius)!=null?s:"md"];r&&o.push(`--pm-radius: ${r}`);let i=Ce[(a=e.position)!=null?a:"bottom-right"];i&&o.push(i),t.textContent=o.length>0?`:host { ${o.join("; ")} }`:"",this.launcherLabel=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):void 0}setState(e){this.state=e,this.host.isConnected&&this.render()}mount(){var e;if(document.body.appendChild(this.host),this.render(),this.options.hotkey!==null){let t=((e=this.options.hotkey)!=null?e:"f").toLowerCase(),o=r=>{if(r.key==="Escape"){this.mode==="picking"&&(this.mode="idle",this.anchor=null,this.render());return}r.metaKey||r.ctrlKey||r.altKey||le(r)||this.mode!=="composing"&&r.key.toLowerCase()===t&&(this.mode=this.mode==="picking"?"idle":"picking",this.render())};window.addEventListener("keydown",o),this.detach.push(()=>window.removeEventListener("keydown",o))}}unmount(){for(let e of this.detach.splice(0))e();this.host.remove()}open(){this.mode="picking",this.render()}setReporter(e){this.reporter=e}setPolicy(e){this.policy=e}capture(){var t,o;let e=(t=this.options.screenshots)!=null?t:!0;return e===!1||((o=this.policy)==null?void 0:o.screenshots)===!1?{offered:!1,checked:!1}:{offered:!0,checked:e!=="optional"}}conceal(){let e=this.host.style.visibility;return this.host.style.visibility="hidden",()=>{this.host.style.visibility=e}}movable(e,t){this.place(e),t.classList.add("drag"),t.title="Drag to move \xB7 double-click to reset",t.addEventListener("dblclick",()=>{this.placement=null,pe(null),this.place(e)}),t.addEventListener("pointerdown",o=>{if(o.target.closest("button")||o.button!==0)return;o.preventDefault();let r=e.getBoundingClientRect(),i=o.clientX-r.left,s=o.clientY-r.top;t.setPointerCapture(o.pointerId),e.classList.add("panel--dragging");let a=d=>{let u=$(d.clientX-i,w-r.width+z,window.innerWidth-z),p=$(d.clientY-s,0,window.innerHeight-z);e.style.left=`${u}px`,e.style.top=`${p}px`,e.style.right="auto",e.style.bottom="auto"},c=()=>{t.releasePointerCapture(o.pointerId),t.removeEventListener("pointermove",a),t.removeEventListener("pointerup",c),t.removeEventListener("pointercancel",c),e.classList.remove("panel--dragging"),this.placement=He(e.getBoundingClientRect()),pe(this.placement),this.place(e)};t.addEventListener("pointermove",a),t.addEventListener("pointerup",c),t.addEventListener("pointercancel",c)})}place(e){let t=this.placement;if(!t){e.style.left=e.style.right=e.style.top=e.style.bottom="";return}let o=e.offsetWidth||380,r=e.offsetHeight||240,i=$(t.dx,w,Math.max(w,window.innerWidth-o-w)),s=$(t.dy,w,Math.max(w,window.innerHeight-r-w));e.style.left=t.h==="left"?`${i}px`:"auto",e.style.right=t.h==="right"?`${i}px`:"auto",e.style.top=t.v==="top"?`${s}px`:"auto",e.style.bottom=t.v==="bottom"?`${s}px`:"auto"}render(){let e=this.root.getElementById("layer");if(e.innerHTML="",this.mode==="idle"){e.appendChild(this.state==="pending"?this.pending():this.launcher());return}if(this.mode==="sent"){let o=this.sent();e.appendChild(o),this.place(o);return}if(this.mode==="picking"){e.appendChild(this.picker());return}let t=this.composer();e.appendChild(t),this.place(t)}pending(){let e=document.createElement("div");return e.className="launcher launcher--pending",e.setAttribute("role","status"),e.textContent="Feedback access pending approval",e}sent(){var c;let e=document.createElement("div");e.className="panel panel--sent",e.setAttribute("role","status");let t=this.reference,o=this.uploadsFailed;e.innerHTML=`
|
|
1
|
+
"use strict";var DaybookFeedback=(()=>{var P=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var ge=Object.prototype.hasOwnProperty;var be=(n,e)=>{for(var t in e)P(n,t,{get:e[t],enumerable:!0})},ye=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of me(e))!ge.call(n,i)&&i!==t&&P(n,i,{get:()=>e[i],enumerable:!(o=fe(e,i))||o.enumerable});return n};var we=n=>ye(P({},"__esModule",{value:!0}),n);var ze={};be(ze,{DEFAULT_API_URL:()=>ue,DaybookFeedback:()=>R,captureAnchor:()=>_,init:()=>Be,resolveAnchor:()=>ae});function v(n){var e;try{let t=new URL(n,location.href);return t.origin===location.origin?t.pathname:`${t.origin}${t.pathname}`}catch{return(e=n.split("?")[0])!=null?e:n}}function F(n){var o,i,r,s,a,c;let e=n.tagName.toLowerCase();if(!n.getAttribute("aria-label")&&!n.getAttribute("data-testid")&&!((o=n.textContent)!=null?o:"").trim()){let l=n.closest("button, a, [role=button], [data-testid], label");if(l&&l!==n)return F(l)}if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement){let l=(r=(i=n.getAttribute("name"))!=null?i:n.id)!=null?r:"",h=n instanceof HTMLInputElement?n.type:e;return`${e}[${h}]${l?` name=${l}`:""}`}let t=(c=(s=n.getAttribute("aria-label"))!=null?s:n.getAttribute("data-testid"))!=null?c:((a=n.textContent)!=null?a:"").replace(/\s+/g," ").trim().slice(0,40);return t?`${e} "${t}"`:e}function Q(n){return n.replace(/[\w.+-]+@[\w-]+\.[\w.]+/g,"[email]").replace(/\b[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g,"[jwt]").replace(/\bBearer\s+[\w.-]+/gi,"Bearer [redacted]").replace(/\b\d{12,19}\b/g,"[number]").slice(0,500)}var J="data-daybook-private";var k=class{constructor(e=40,t=!0){this.limit=e;this.redact=t;this.entries=[];this.detach=[]}list(){return[...this.entries]}add(e,t){for(this.entries.push({at:new Date().toISOString(),type:e,message:this.redact?Q(t):t.slice(0,500)});this.entries.length>this.limit;)this.entries.shift()}start(){let e=a=>{let c=a.target;c instanceof Element&&(c.closest("[data-daybook-feedback]")||this.add("click",F(c)))};document.addEventListener("click",e,{capture:!0,passive:!0}),this.detach.push(()=>document.removeEventListener("click",e,{capture:!0}));let t=history.pushState,o=history.replaceState,i=()=>this.add("nav",v(location.href));history.pushState=(...a)=>{t.apply(history,a),i()},history.replaceState=(...a)=>{o.apply(history,a),i()},window.addEventListener("popstate",i),this.detach.push(()=>{history.pushState=t,history.replaceState=o,window.removeEventListener("popstate",i)});for(let a of["error","warn"]){let c=console[a];console[a]=(...l)=>{this.add("console",`${a}: ${l.map(I).join(" ")}`),c.apply(console,l)},this.detach.push(()=>{console[a]=c})}let r=a=>this.add("console",`uncaught: ${a.message}`),s=a=>this.add("console",`unhandled rejection: ${I(a.reason)}`);window.addEventListener("error",r),window.addEventListener("unhandledrejection",s),this.detach.push(()=>{window.removeEventListener("error",r),window.removeEventListener("unhandledrejection",s)}),this.watchFetch()}stop(){for(let e of this.detach.splice(0))e()}watchFetch(){if(typeof window.fetch!="function")return;let e=window.fetch;window.fetch=async(...t)=>{let o=performance.now();try{let i=await e.apply(window,t),r=Math.round(performance.now()-o);return(!i.ok||r>3e3)&&this.add("network",`${i.status} ${v(G(t[0]))} ${r}ms`),i}catch(i){throw this.add("network",`failed ${v(G(t[0]))}: ${I(i)}`),i}},this.detach.push(()=>{window.fetch=e})}};function G(n){return typeof n=="string"?n:n instanceof URL?n.href:n.url}function I(n){var e,t;if(typeof n=="string")return n;if(n instanceof Error)return`${n.name}: ${n.message}`;try{return(t=(e=JSON.stringify(n))==null?void 0:e.slice(0,200))!=null?t:String(n)}catch{return String(n)}}var O="pm.feedback.queue";var T=class{constructor(e,t){this.apiUrl=e;this.ingestKey=t;this.session=null;this.identityToken=null}setSession(e){this.session=e}async send(e,t=[],o){var c,l,h;let i={idempotencyKey:(c=e.idempotencyKey)!=null?c:Z(),...e,attachments:[...(l=e.attachments)!=null?l:[],...t.map(p=>({filename:p.filename,contentType:p.contentType,size:p.blob.size}))]},r=await this.post("/ingest/v1",i);if(!r.ok)throw await E(r);let s=await r.json(),a=((h=e.attachments)!=null?h:[]).length;return await Promise.all(t.map(async(p,g)=>{let b=ve(s,a+g);if(!b){o==null||o(p,new Error("The server would not accept that file."));return}try{await this.upload(b,p)}catch(w){o==null||o(p,w)}})),s}async flush(){let e=te();if(e.length!==0){ne([]);for(let t of e)try{let o=await this.post("/ingest/v1",t);!o.ok&&(o.status===429||o.status>=500)&&j(t)}catch{j(t)}}}queue(e){var t;j({...e,idempotencyKey:(t=e.idempotencyKey)!=null?t:Z(),attachments:void 0})}async signIn(){let e=ee(64),t=await xe(e),o=ee(16),i=`${this.base()}/ingest/v1/authorize?key=${encodeURIComponent(this.ingestKey)}&origin=${encodeURIComponent(location.origin)}&code_challenge=${encodeURIComponent(t)}&state=${encodeURIComponent(o)}`,r=window.open(i,"daybook-feedback","width=460,height=640");if(!r)throw Object.assign(new Error("Popup blocked"),{code:"popup_blocked"});let s=await new Promise((l,h)=>{let p=setInterval(()=>{r.closed&&(b(),h(Object.assign(new Error("Sign-in cancelled"),{code:"cancelled"})))},400),g=w=>{if(w.origin!==new URL(this.base()).origin)return;let m=w.data;if((m==null?void 0:m.source)==="daybook-feedback"&&m.state===o){if(b(),m.error||!m.code){h(Object.assign(new Error("Sign-in was refused"),{code:m.error||"refused"}));return}l(m.code)}},b=()=>{clearInterval(p),window.removeEventListener("message",g)};window.addEventListener("message",g)}),a=await this.post("/ingest/v1/token",{code:s,codeVerifier:e});if(!a.ok)throw await E(a);let{identityToken:c}=await a.json();return this.identityToken=c,c}base(){return this.apiUrl.replace(/\/$/,"")}resolve(e){try{let t=new URL(this.base()),o=new URL(e,t);return o.hostname===t.hostname?new URL(o.pathname+o.search,t).toString():o.toString()}catch{return e}}async handshake(e){var i,r;let t=await this.post("/ingest/v1/session",{...e,identityToken:(i=this.identityToken)!=null?i:void 0});if(!t.ok)throw await E(t);let o=await t.json();return this.session=(r=o.sessionToken)!=null?r:null,o}post(e,t){let o={"Content-Type":"application/json","X-Ingest-Key":this.ingestKey};return this.session&&(o["X-Feedback-Session"]=this.session),fetch(`${this.base()}${e}`,{method:"POST",headers:o,body:JSON.stringify(t),credentials:"omit"})}async upload(e,t){let o=await fetch(this.resolve(e.uploadUrl),{method:e.method,headers:{"Content-Type":e.contentType,"X-Ingest-Key":this.ingestKey},body:t.blob,credentials:"omit"});if(!o.ok)throw await E(o);await this.post(`/ingest/v1/attachments/${e.id}/confirm`,{})}};function ve(n,e){let t=n.attachments.find(o=>o.index===e);return t!=null?t:n.attachments.some(o=>typeof o.index=="number")?void 0:n.attachments[e]}function j(n){let e=te();e.push(n),ne(e.slice(-20))}function te(){try{let n=localStorage.getItem(O);return n?JSON.parse(n):[]}catch{return[]}}function ne(n){try{n.length===0?localStorage.removeItem(O):localStorage.setItem(O,JSON.stringify(n))}catch{}}async function E(n){let e=`http_${n.status}`;try{let t=await n.json();if(t.code&&(e=t.code),t.message)return Object.assign(new Error(t.message),{code:e})}catch{}return Object.assign(new Error(`Ingest failed (${n.status})`),{code:e})}function Z(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ee(n){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=new Uint8Array(n);return crypto.getRandomValues(t),Array.from(t,o=>e[o%e.length]).join("")}async function xe(n){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n));return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function q(n){var t;let e={platform:"web",route:location.pathname,title:document.title.slice(0,200),locale:navigator.language,timezone:Ee(),viewport:{width:window.innerWidth,height:window.innerHeight,dpr:(t=window.devicePixelRatio)!=null?t:1},device:ke()};return document.referrer&&(e.referrer=v(document.referrer)),n.app&&(e.app=n.app),n.anchor&&(e.anchor=n.anchor),n.breadcrumbs&&n.breadcrumbs.length>0&&(e.breadcrumbs=n.breadcrumbs),e}function ke(){var i;let n=navigator.userAgent,e=/Edg\//.test(n)?"Edge":/OPR\//.test(n)?"Opera":/Firefox\//.test(n)?"Firefox":/Chrome\//.test(n)?"Chrome":/Safari\//.test(n)?"Safari":"Unknown",t=/Windows NT/.test(n)?"Windows":/iPhone|iPad|iPod/.test(n)?"iOS":/Mac OS X/.test(n)?"macOS":/Android/.test(n)?"Android":/Linux/.test(n)?"Linux":"Unknown",o=(i=n.match(/(?:Edg|OPR|Firefox|Chrome|Version)\/(\d+)/))==null?void 0:i[1];return{browser:o?`${e} ${o}`:e,os:t,touch:navigator.maxTouchPoints>0,userAgent:n.slice(0,300)}}function Ee(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return`UTC${-new Date().getTimezoneOffset()/60}`}}async function re(n,e=()=>()=>{}){var r;if(typeof((r=navigator.mediaDevices)==null?void 0:r.getDisplayMedia)!="function")return null;let t=n?_e():()=>{},o=e(),i=null;try{return i=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include",surfaceSwitching:"exclude",monitorTypeSurfaces:"exclude"}),i.getVideoTracks()[0]?(await new Promise(a=>setTimeout(a,250)),await Le(i)):null}catch{return null}finally{i==null||i.getTracks().forEach(s=>s.stop()),o(),t()}}var oe=1920,Te=.82;async function Le(n){let e=document.createElement("video");e.srcObject=n,e.muted=!0,await e.play().catch(()=>{});let t=e.videoWidth||window.innerWidth,o=e.videoHeight||window.innerHeight,i=t>oe?oe/t:1,r=document.createElement("canvas");r.width=Math.round(t*i),r.height=Math.round(o*i);let s=r.getContext("2d");if(!s)return null;s.imageSmoothingQuality="high",s.drawImage(e,0,0,r.width,r.height),e.pause(),e.srcObject=null;let a=await Se(r);if(!a)return null;let c=a.type||"image/png";return{blob:a,filename:`screenshot.${c==="image/webp"?"webp":c==="image/jpeg"?"jpg":"png"}`,contentType:c}}async function Se(n){for(let e of["image/webp","image/jpeg"]){let t=await ie(n,e,Te);if((t==null?void 0:t.type)===e)return t}return ie(n,"image/png")}function ie(n,e,t){return new Promise(o=>n.toBlob(i=>o(i),e,t))}function _e(){let n=[...document.querySelectorAll(`[${J}]`),...document.querySelectorAll('input[type="password"]')],e=n.map(t=>t.style.filter);return n.forEach(t=>{t.style.filter="blur(12px)"}),()=>{n.forEach((t,o)=>{var i;t.style.filter=(i=e[o])!=null?i:""})}}function _(n,e){let t=document.elementFromPoint(n,e);if(!(t instanceof HTMLElement))return{selector:null,offsetX:S(n/window.innerWidth),offsetY:S(e/window.innerHeight),elementText:null};let o=t.getBoundingClientRect();return{selector:Me(t),offsetX:o.width>0?S((n-o.left)/o.width):0,offsetY:o.height>0?S((e-o.top)/o.height):0,elementText:$e(t)}}function ae(n){if(!n.selector)return{x:n.offsetX*window.innerWidth,y:n.offsetY*window.innerHeight};let e=null;try{e=document.querySelector(n.selector)}catch{return null}if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+n.offsetX*t.width,y:t.top+n.offsetY*t.height}}function Me(n){if(n===document.body)return"body";for(let i of["data-testid","data-test","data-daybook-id","data-cy"]){let r=n.getAttribute(i);if(r){let s=`[${i}="${B(r)}"]`;if(L(s))return s}}if(n.id&&!se(n.id)){let i=`#${B(n.id)}`;if(L(i))return i}let e=[],t=n;for(;t&&t!==document.body&&e.length<8;){let i=t.tagName.toLowerCase(),r=Array.from(t.classList).filter(c=>!se(c)).slice(0,2);r.length>0&&(i+=r.map(c=>`.${B(c)}`).join(""));let s=t.parentElement;if(s){let c=Array.from(s.children).filter(l=>l.tagName===t.tagName);c.length>1&&(i+=`:nth-of-type(${c.indexOf(t)+1})`)}e.unshift(i);let a=e.join(" > ");if(L(a))return a;t=s}let o=e.length>0?`body > ${e.join(" > ")}`:null;return o&&L(o)?o:null}function L(n){try{return document.querySelectorAll(n).length===1}catch{return!1}}function se(n){return/^[a-z]{1,3}[0-9a-f]{5,}$/i.test(n)||/--[0-9a-f]{5,}$/i.test(n)||/^_[0-9a-z]{5,}/i.test(n)||/^v-[0-9a-f]{6,}$/i.test(n)||/^ng-/.test(n)||/[0-9a-f]{8,}/i.test(n)}function $e(n){var o,i,r;let t=((i=(o=n.innerText)!=null?o:n.textContent)!=null?i:"").replace(/\s+/g," ").trim();if(!t){let s=(r=n.getAttribute("aria-label"))!=null?r:n.getAttribute("title");return(s==null?void 0:s.trim())||null}return t.length>80?`${t.slice(0,77)}\u2026`:t}function S(n){return Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}function B(n){return typeof CSS!="undefined"&&typeof CSS.escape=="function"?CSS.escape(n):n.replace(/([^\w-])/g,"\\$1")}var Ae=/^(image\/(png|jpeg|gif|webp)|video\/(mp4|quicktime|webm))$/;function ce(n,e){let t=[];for(let o of n){if(e+t.length>=5)break;let i=Ae.test(o.type)?o.size>26214400?`Too large (${(o.size/1048576).toFixed(1)} MB, max 25).`:null:"Only images and short videos.";t.push({blob:o,filename:o.name||`pasted-${t.length+1}.${Re(o.type)}`,contentType:o.type,preview:i?null:URL.createObjectURL(o),error:i})}return t}function le(n){var o;let e=(o=n.clipboardData)==null?void 0:o.items;if(!e)return[];let t=[];for(let i of e){if(i.kind!=="file")continue;let r=i.getAsFile();r&&t.push(r)}return t}function M(n){for(let e of n)e.preview&&URL.revokeObjectURL(e.preview)}function Re(n){var e,t;return(t=(e=n.split("/")[1])==null?void 0:e.replace("quicktime","mov"))!=null?t:"bin"}function de(n){var o;let t=(o=(typeof n.composedPath=="function"?n.composedPath():[])[0])!=null?o:n.target;return!t||t.nodeType!==1?!1:/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)?!0:typeof t.closest=="function"&&t.closest('[contenteditable=""], [contenteditable="true"]')!==null}function He(n,e,t){let o=0;for(let s of e){if(s.right<=n.left||s.left>=n.right)continue;let a=n.v==="bottom"?t.height-s.top:s.bottom;a>o&&(o=a)}if(o===0)return 0;let i=n.v==="bottom"?t.height-n.bottom:n.top,r=Math.round(o+12-i);return r<=0||r>t.height*.35?0:r}function Ce(n,e,t){if(n===e||e.contains(n)||n.contains(e)||n===document.body||n===document.documentElement)return!1;let o=getComputedStyle(n);if(o.position!=="fixed"&&o.position!=="sticky"||o.visibility==="hidden"||o.display==="none"||Number(o.opacity)===0)return!1;let i=n.getBoundingClientRect();return!(i.width<8||i.height<8||i.width*i.height>t.width*t.height*.25)}function Pe(n,e,t){if(typeof document.elementsFromPoint!="function")return[];let o=new Map,i=[];for(let s=n.left+4;s<n.right;s+=32)i.push(s);i.push(n.right-4);let r=t.height*.35;for(let s=0;s<=r;s+=32){let a=n.v==="bottom"?n.bottom-s:n.top+s;if(a<0||a>t.height)break;for(let c of i)if(!(c<0||c>t.width))for(let l of document.elementsFromPoint(c,a)){if(o.has(l)||!Ce(l,e,t))continue;let h=l.getBoundingClientRect();o.set(l,{top:h.top,bottom:h.bottom,left:h.left,right:h.right})}}return[...o.values()]}function pe(n,e){let t={width:window.innerWidth,height:window.innerHeight};return He(n,Pe(n,e,t),t)}var A=class{constructor(e,t){this.options=e;this.onSubmit=t;this.mode="idle";this.anchor=null;this.detach=[];this.clearance=0;this.state="ready";this.policy=null;this.dragged=null;this.reference=null;this.uploadsFailed=0;this.host=document.createElement("div"),this.host.setAttribute("data-daybook-feedback",""),this.host.style.cssText="position:fixed;inset:0;z-index:2147483000;pointer-events:none",this.root=this.host.attachShadow({mode:"open"}),this.root.innerHTML=`<style>${qe}</style><style id="theme"></style><style id="place"></style><div id="layer"></div>`}setTheme(e){var r;let t=this.root.getElementById("theme");if(!t)return;if(!e){t.textContent="";return}let o=[];Oe(e.accent)&&o.push(`--pm-accent: ${e.accent}`);let i={none:"0",sm:"6px",md:"12px",lg:"18px"}[(r=e.cornerRadius)!=null?r:"md"];i&&o.push(`--pm-radius: ${i}`),t.textContent=o.length>0?`:host { ${o.join("; ")} }`:"",this.themePlacement=e.position,this.applyPlacement(),this.launcherLabel=typeof e.launcherLabel=="string"&&e.launcherLabel.length>0?e.launcherLabel.slice(0,24):void 0}get placement(){var e,t;return(t=(e=this.options.placement)!=null?e:this.themePlacement)!=null?t:"bottom-right"}applyPlacement(){let e=this.root.getElementById("place");if(!e)return;let t=this.placement,o=t.startsWith("bottom")?"bottom":"top",i=t.endsWith("right")?"right":"left",r=f+this.clearance;e.textContent=`:host {
|
|
2
|
+
--pm-${i}: ${f}px; --pm-${i==="right"?"left":"right"}: auto;
|
|
3
|
+
--pm-${o}: ${r}px; --pm-${o==="bottom"?"top":"bottom"}: auto;
|
|
4
|
+
}`}homeSlot(){let e=this.placement,t=220,o=48,i=e.endsWith("right")?window.innerWidth-f:f+t,r=e.startsWith("bottom")?window.innerHeight-f:f+o;return{left:i-t,right:i,top:r-o,bottom:r,v:e.startsWith("bottom")?"bottom":"top"}}watchClearance(){if(this.options.avoidOverlap===!1)return;let e=!1,t=()=>{if(e=!1,this.mode==="idle")try{let r=pe(this.homeSlot(),this.host);if(Math.abs(r-this.clearance)<4)return;this.clearance=r,this.applyPlacement()}catch{}},o=typeof requestAnimationFrame=="function"?r=>requestAnimationFrame(r):r=>setTimeout(r,16),i=()=>{e||(e=!0,o(t))};if(window.addEventListener("scroll",i,{passive:!0,capture:!0}),window.addEventListener("resize",i),this.detach.push(()=>{window.removeEventListener("scroll",i,{capture:!0}),window.removeEventListener("resize",i)}),typeof MutationObserver=="function"){let r=new MutationObserver(i);r.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","hidden"]}),this.detach.push(()=>r.disconnect())}i()}setState(e){this.state=e,this.host.isConnected&&this.render()}mount(){var e;if(document.body.appendChild(this.host),this.applyPlacement(),this.render(),this.watchClearance(),this.options.hotkey!==null){let t=((e=this.options.hotkey)!=null?e:"f").toLowerCase(),o=i=>{if(i.key==="Escape"){this.mode==="picking"&&(this.mode="idle",this.anchor=null,this.dragged=null,this.render());return}i.metaKey||i.ctrlKey||i.altKey||de(i)||this.mode!=="composing"&&i.key.toLowerCase()===t&&(this.mode=this.mode==="picking"?"idle":"picking",this.render())};window.addEventListener("keydown",o),this.detach.push(()=>window.removeEventListener("keydown",o))}}unmount(){for(let e of this.detach.splice(0))e();this.host.remove()}open(){this.mode="picking",this.render()}setReporter(e){this.reporter=e}setPolicy(e){this.policy=e}capture(){var t,o;let e=(t=this.options.screenshots)!=null?t:!0;return e===!1||((o=this.policy)==null?void 0:o.screenshots)===!1?{offered:!1,checked:!1}:{offered:!0,checked:e!=="optional"}}conceal(){let e=this.host.style.visibility;return this.host.style.visibility="hidden",()=>{this.host.style.visibility=e}}movable(e,t){this.place(e),t.classList.add("drag"),t.title="Drag to move \xB7 double-click to reset",t.addEventListener("dblclick",()=>{this.dragged=null,this.place(e)}),t.addEventListener("pointerdown",o=>{if(o.target.closest("button")||o.button!==0)return;o.preventDefault();let i=e.getBoundingClientRect(),r=o.clientX-i.left,s=o.clientY-i.top;t.setPointerCapture(o.pointerId),e.classList.add("panel--dragging");let a=l=>{let h=$(l.clientX-r,f-i.width+U,window.innerWidth-U),p=$(l.clientY-s,0,window.innerHeight-U);e.style.left=`${h}px`,e.style.top=`${p}px`,e.style.right="auto",e.style.bottom="auto"},c=()=>{t.releasePointerCapture(o.pointerId),t.removeEventListener("pointermove",a),t.removeEventListener("pointerup",c),t.removeEventListener("pointercancel",c),e.classList.remove("panel--dragging"),this.dragged=je(e.getBoundingClientRect()),this.place(e)};t.addEventListener("pointermove",a),t.addEventListener("pointerup",c),t.addEventListener("pointercancel",c)})}place(e){let t=this.dragged;if(!t){e.style.left=e.style.right=e.style.top=e.style.bottom="";return}let o=e.offsetWidth||380,i=e.offsetHeight||240,r=$(t.dx,f,Math.max(f,window.innerWidth-o-f)),s=$(t.dy,f,Math.max(f,window.innerHeight-i-f));e.style.left=t.h==="left"?`${r}px`:"auto",e.style.right=t.h==="right"?`${r}px`:"auto",e.style.top=t.v==="top"?`${s}px`:"auto",e.style.bottom=t.v==="bottom"?`${s}px`:"auto"}render(){let e=this.root.getElementById("layer");if(e.innerHTML="",this.mode==="idle"){e.appendChild(this.state==="pending"?this.pending():this.launcher());return}if(this.mode==="sent"){this.dragged=null,e.appendChild(this.sent());return}if(this.mode==="picking"){e.appendChild(this.picker());return}let t=this.composer();e.appendChild(t),this.place(t)}pending(){let e=document.createElement("div");return e.className="launcher launcher--pending",e.setAttribute("role","status"),e.textContent="Feedback access pending approval",e}sent(){var c;let e=document.createElement("div");e.className="panel panel--sent",e.setAttribute("role","status");let t=this.reference,o=this.uploadsFailed;e.innerHTML=`
|
|
2
5
|
<div class="sent__tick" aria-hidden="true">✓</div>
|
|
3
6
|
<div class="sent__body">
|
|
4
7
|
<div class="panel__title">Thank you \u2014 that is on its way.</div>
|
|
@@ -9,7 +12,7 @@
|
|
|
9
12
|
<div class="panel__anchor">Quote it if you follow it up.</div>`:""}
|
|
10
13
|
${o>0?`<div class="sent__warn">${o===1?"One attachment could not be uploaded.":`${o} attachments could not be uploaded.`} The report was filed without it.</div>`:""}
|
|
11
14
|
</div>
|
|
12
|
-
${t?'<button type="button" class="panel__close" data-dismiss aria-label="Dismiss">×</button>':""}`;let
|
|
15
|
+
${t?'<button type="button" class="panel__close" data-dismiss aria-label="Dismiss">×</button>':""}`;let i=()=>{this.mode==="sent"&&(this.mode="idle",this.render())},r=window.setTimeout(i,o>0?2e4:t?12e3:6e3),s=()=>window.clearTimeout(r);if(this.detach.push(()=>window.clearTimeout(r)),this.contain(e),this.place(e),!t)return e;e.addEventListener("pointerenter",s),e.addEventListener("focusin",s),(c=e.querySelector("[data-dismiss]"))==null||c.addEventListener("click",i);let a=e.querySelector("[data-copy]");return a&&(a.onclick=async()=>{s();let l=await Ie(t);a.textContent=l?"Copied":"Copy failed",a.classList.toggle("sent__copy--done",l)}),e}launcher(){var t,o;let e=document.createElement("button");return e.className="launcher",e.textContent=(t=this.launcherLabel)!=null?t:"Feedback",e.title=this.options.hotkey===null?"Report a problem":`Report a problem (${((o=this.options.hotkey)!=null?o:"f").toUpperCase()})`,e.onclick=()=>{this.mode="picking",this.render()},e}picker(){let e=document.createElement("div");return e.className="mask",e.innerHTML='<div class="hint">Click the thing that is wrong \xB7 <kbd>Esc</kbd> to cancel</div>',e.onclick=t=>{e.style.pointerEvents="none",this.anchor=_(t.clientX,t.clientY),e.style.pointerEvents="",this.mode="composing",this.render()},e}composer(){var N,K,X,W,V;let e=document.createElement("div");e.className="panel";let t=(N=this.anchor)!=null&&N.elementText?`on \u201C${this.anchor.elementText}\u201D`:(K=this.anchor)!=null&&K.selector?`on ${this.anchor.selector}`:"on this page",o=this.capture();e.innerHTML=`
|
|
13
16
|
<div class="panel__head" id="head">
|
|
14
17
|
<span class="panel__grip" aria-hidden="true">\u283F</span>
|
|
15
18
|
<div class="panel__heading">
|
|
@@ -27,7 +30,7 @@
|
|
|
27
30
|
what somebody came here to do is type.
|
|
28
31
|
-->
|
|
29
32
|
<div class="panel__kinds">
|
|
30
|
-
${["bug","idea","praise","question"].map((
|
|
33
|
+
${["bug","idea","praise","question"].map((d,u)=>`<button class="kind${u===0?" kind--on":""}" data-kind="${d}">${d}</button>`).join("")}
|
|
31
34
|
</div>
|
|
32
35
|
|
|
33
36
|
<input id="email" type="email" placeholder="Email (optional, so we can reply)" autocomplete="email" />
|
|
@@ -53,7 +56,7 @@
|
|
|
53
56
|
<span class="panel__note">Sends the page, your browser, and recent errors.</span>
|
|
54
57
|
<button id="cancel" class="ghost">Cancel</button>
|
|
55
58
|
<button id="send" class="primary">Send</button>
|
|
56
|
-
</div>`;let
|
|
59
|
+
</div>`;let i=[],r=e.querySelector("#files"),s=e.querySelector("#drop"),a=e.querySelector("#file"),c=()=>{r.innerHTML="",i.forEach((d,u)=>{var Y;let y=document.createElement("div");y.className=d.error?"file file--bad":"file",y.innerHTML=d.preview?`<img src="${d.preview}" alt="" />`:'<span class="file__icon">\u25A6</span>';let C=document.createElement("span");C.className="file__name",C.textContent=(Y=d.error)!=null?Y:d.filename,y.appendChild(C);let x=document.createElement("button");x.className="link",x.textContent="\xD7",x.onclick=()=>{M([d]),i.splice(u,1),c()},y.appendChild(x),r.appendChild(y)}),s.style.display=i.length>=5?"none":""},l=d=>{i.push(...ce(d,i.length)),c()};a.onchange=()=>{a.files&&l(a.files)},e.querySelector("#browse").onclick=()=>a.click(),e.addEventListener("paste",d=>{let u=le(d);u.length>0&&(d.preventDefault(),l(u))}),s.addEventListener("dragover",d=>{d.preventDefault(),s.classList.add("drop--over")}),s.addEventListener("dragleave",()=>s.classList.remove("drop--over")),s.addEventListener("drop",d=>{var u,y;d.preventDefault(),s.classList.remove("drop--over"),l(Array.from((y=(u=d.dataTransfer)==null?void 0:u.files)!=null?y:[]))});let h="bug";e.querySelectorAll(".kind").forEach(d=>{d.onclick=()=>{var u;h=(u=d.dataset.kind)!=null?u:"bug",e.querySelectorAll(".kind").forEach(y=>y.classList.remove("kind--on")),d.classList.add("kind--on")}});let p=e.querySelector("#message"),g=e.querySelector("#email"),b=(V=(X=this.reporter)==null?void 0:X.email)!=null?V:(W=this.options.reporter)==null?void 0:W.email;b&&!g.value&&(g.value=b);let w=e.querySelector("#shot"),m=e.querySelector("#status"),H=e.querySelector("#send"),z=()=>{M(i),this.mode="idle",this.anchor=null,this.dragged=null,this.render()};e.querySelector("#cancel").onclick=z,e.querySelector("#close").onclick=z;let D=async()=>{var d;if(!p.value.trim()){m.textContent="Say what happened first.";return}H.disabled=!0,m.textContent="Sending\u2026";try{let u=await this.onSubmit({message:p.value.trim(),kind:h,email:g.value.trim()||void 0,anchor:this.anchor,withScreenshot:(d=w==null?void 0:w.checked)!=null?d:!1,files:i.filter(y=>!y.error)});this.reference=u.reference,this.uploadsFailed=u.uploadsFailed,M(i),this.mode="sent",this.anchor=null,this.render()}catch(u){H.disabled=!1,m.textContent=u instanceof Error?`${u.message} \u2014 saved, will retry.`:"Failed, saved and will retry."}};return H.onclick=D,p.onkeydown=d=>{(d.metaKey||d.ctrlKey)&&d.key==="Enter"&&D()},setTimeout(()=>p.focus(),0),this.contain(e),this.movable(e,e.querySelector("#head")),e}contain(e){for(let t of["pointerdown","mousedown","click"])e.addEventListener(t,o=>o.stopPropagation())}};async function Ie(n){var t;try{if((t=navigator.clipboard)!=null&&t.writeText)return await navigator.clipboard.writeText(n),!0}catch{}let e=document.createElement("textarea");e.value=n,e.setAttribute("readonly",""),e.style.cssText="position:fixed;top:0;left:0;width:1px;height:1px;opacity:0",document.body.appendChild(e);try{return e.select(),document.execCommand("copy")}catch{return!1}finally{e.remove()}}var f=16,U=56;function je(n){let e={left:n.left,right:window.innerWidth-n.right,top:n.top,bottom:window.innerHeight-n.bottom},t=Object.keys(e).reduce((r,s)=>e[s]<e[r]?s:r),o=t==="left"||t==="right"?t:e.left<=e.right?"left":"right",i=t==="top"||t==="bottom"?t:e.top<=e.bottom?"top":"bottom";return{h:o,v:i,dx:t===o?f:Math.max(f,Math.round(e[o])),dy:t===i?f:Math.max(f,Math.round(e[i]))}}function $(n,e,t){return Math.min(Math.max(n,e),t)}function he(n){return n.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}function Oe(n){return typeof n=="string"&&/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%/]+\)|hsla?\([\d\s.,%/deg]+\)|[a-z]{3,20})$/i.test(n.trim())}var qe=`
|
|
57
60
|
:host {
|
|
58
61
|
all: initial;
|
|
59
62
|
|
|
@@ -68,11 +71,15 @@
|
|
|
68
71
|
--pm-bottom: 16px;
|
|
69
72
|
}
|
|
70
73
|
* { box-sizing: border-box; font-family: system-ui, -apple-system, sans-serif }
|
|
74
|
+
@media (prefers-reduced-motion: reduce) { .launcher { transition: none } }
|
|
71
75
|
#layer { position: fixed; inset: 0; pointer-events: none }
|
|
72
76
|
.launcher {
|
|
73
77
|
position: fixed; pointer-events: auto;
|
|
74
78
|
left: var(--pm-left); right: var(--pm-right);
|
|
75
79
|
top: var(--pm-top); bottom: var(--pm-bottom);
|
|
80
|
+
/* A back-to-top button appearing on scroll moves us; gliding reads as making room, and jumping
|
|
81
|
+
reads as a bug. Honoured only where motion is welcome. */
|
|
82
|
+
transition: bottom .18s ease, top .18s ease;
|
|
76
83
|
padding: 9px 14px; border: 0; border-radius: 999px; cursor: pointer;
|
|
77
84
|
background: var(--pm-accent); color: #fafafa; font-size: 13px; font-weight: 500;
|
|
78
85
|
box-shadow: 0 2px 12px rgba(0,0,0,.3);
|
|
@@ -211,4 +218,4 @@ textarea:focus, input:focus { outline: 2px solid #171717; outline-offset: -1px }
|
|
|
211
218
|
.file__icon { width: 28px; text-align: center }
|
|
212
219
|
.file__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
|
|
213
220
|
.link { border: 0; background: transparent; color: #525252; cursor: pointer; font-size: 11px; text-decoration: underline }
|
|
214
|
-
`;var ue="https://api.daybook.team",
|
|
221
|
+
`;var ue="https://api.daybook.team",R=class{constructor(e){this.options=e;this.widget=null;this.started=!1;this.inFlight=null;this.epoch=0;this.ready=null;this.stopped=!1;var t;if(!e.ingestKey)throw new Error("ingestKey is required");this.client=new T((t=e.apiUrl)!=null?t:ue,e.ingestKey),this.trail=e.breadcrumbs===!1?null:new k(40,e.redact!==!1)}start(){var e;return this.stopped=!1,(e=this.trail)==null||e.start(),this.mount(),this.started||(this.started=!0,this.client.flush()),this.handshake(),this}mount(){this.widget||this.stopped||(this.widget=new A(this.options,e=>this.submit(e)),this.widget.setReporter(this.options.reporter),this.widget.mount())}handshake(){var o,i,r;let e=JSON.stringify([(o=this.options.reporter)!=null?o:null,(i=this.options.signature)!=null?i:null,this.epoch]);if(((r=this.inFlight)==null?void 0:r.key)===e)return this.inFlight.promise;let t=this.runHandshake().finally(()=>{var s;((s=this.inFlight)==null?void 0:s.promise)===t&&(this.inFlight=null)});return this.inFlight={key:e,promise:t},t}async runHandshake(){var e,t,o,i,r,s,a;try{let c=await this.client.handshake({identity:this.options.reporter,signature:this.options.signature,locale:typeof navigator!="undefined"?navigator.language:void 0});if(this.ready=c,(t=(e=this.options).onReady)==null||t.call(e,c),c.reporterStatus==="Blocked"){(o=this.widget)==null||o.unmount(),this.widget=null;return}this.mount(),this.widget.setTheme(Ue(c.theme)),this.widget.setPolicy((i=c.policy)!=null?i:null),this.widget.setState(c.reporterStatus==="Pending"?"pending":"ready")}catch(c){(s=(r=this.options).onError)==null||s.call(r,c),console.warn("[feedback] handshake failed; the widget will not appear",c),(a=this.widget)==null||a.unmount(),this.widget=null}}identify(e){var t;this.options={...this.options,reporter:e?{...this.options.reporter,...e}:void 0},(t=this.widget)==null||t.setReporter(this.options.reporter),this.widget&&this.handshake()}async signIn(){await this.client.signIn(),this.epoch++,await this.handshake()}authenticate(e){this.options={...this.options,signature:e!=null?e:void 0},this.widget&&this.handshake()}stop(){var e,t;this.started=!1,this.stopped=!0,(e=this.trail)==null||e.stop(),(t=this.widget)==null||t.unmount(),this.widget=null}open(){var e;(e=this.widget)==null||e.open()}async report(e,t={}){var o,i,r;return this.client.send({message:e,surface:this.options.surface,...t,context:{...q({breadcrumbs:(o=this.trail)==null?void 0:o.list(),app:this.options.app}),...(i=t.context)!=null?i:{}},reporter:(r=t.reporter)!=null?r:this.options.reporter})}async submit(e){var s,a,c,l,h;let t=e.withScreenshot?await re(this.options.redact!==!1,()=>{var p,g;return(g=(p=this.widget)==null?void 0:p.conceal())!=null?g:(()=>{})}):null,o=[...e.files,...t?[t]:[]],i={message:e.message,kind:e.kind,app:this.options.app,surface:this.options.surface,reporter:e.email?{...this.options.reporter,email:e.email}:this.options.reporter,context:q({anchor:e.anchor,breadcrumbs:(s=this.trail)==null?void 0:s.list(),app:this.options.app})},r=[];try{let p=await this.client.send(i,o,(g,b)=>{var w,m;r.push(b),console.warn(`[feedback] "${g.filename}" did not upload`,b),(m=(w=this.options).onError)==null||m.call(w,b)});return p.uploadsFailed=r.length,(c=(a=this.options).onSent)==null||c.call(a,p),{reference:p.reference,uploadsFailed:r.length}}catch(p){throw this.client.queue(i),(h=(l=this.options).onError)==null||h.call(l,p),p}}};function Be(n){return new R(n).start()}function Ue(n){if(!n)return null;try{let e=JSON.parse(n);return e&&typeof e=="object"?e:null}catch{return null}}return we(ze);})();
|
package/dist/screenshot.d.ts
CHANGED
|
@@ -23,3 +23,18 @@ export interface Screenshot {
|
|
|
23
23
|
* the form they just filled in, covering the thing they were reporting.
|
|
24
24
|
*/
|
|
25
25
|
export declare function captureScreenshot(redact: boolean, conceal?: () => () => void): Promise<Screenshot | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Encodes the frame as small as the browser can manage.
|
|
28
|
+
*
|
|
29
|
+
* WebP first, JPEG second, and whatever comes back last. The order is by size on this kind of
|
|
30
|
+
* image: a 2880-wide screenshot is several megabytes as PNG and a couple of hundred kilobytes as
|
|
31
|
+
* WebP, and that difference is a report that uploads in a second rather than in a minute.
|
|
32
|
+
*
|
|
33
|
+
* Each step checks what came back rather than trusting the request. toBlob falls back to PNG
|
|
34
|
+
* silently for a format it does not support, so asking for WebP and believing the answer is how a
|
|
35
|
+
* fix like this quietly does nothing on Safari.
|
|
36
|
+
*
|
|
37
|
+
* Exported so that behaviour can be tested — it is the only part of the capture path that does not
|
|
38
|
+
* need a browser, and it is the part with the trap in it.
|
|
39
|
+
*/
|
|
40
|
+
export declare function encode(canvas: HTMLCanvasElement): Promise<Blob | null>;
|
package/dist/screenshot.js
CHANGED
|
@@ -38,10 +38,7 @@ export async function captureScreenshot(redact, conceal = () => () => { }) {
|
|
|
38
38
|
return null;
|
|
39
39
|
// A frame arrives a moment after the track opens; without this the capture is often blank.
|
|
40
40
|
await new Promise(resolve => setTimeout(resolve, 250));
|
|
41
|
-
|
|
42
|
-
return blob
|
|
43
|
-
? { blob, filename: 'screenshot.png', contentType: 'image/png' }
|
|
44
|
-
: null;
|
|
41
|
+
return await grabFrame(stream);
|
|
45
42
|
}
|
|
46
43
|
catch {
|
|
47
44
|
// Declining the share prompt is a normal outcome, not an error worth surfacing — the report
|
|
@@ -54,21 +51,80 @@ export async function captureScreenshot(redact, conceal = () => () => { }) {
|
|
|
54
51
|
restore();
|
|
55
52
|
}
|
|
56
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* The widest a screenshot is allowed to be, in pixels.
|
|
56
|
+
*
|
|
57
|
+
* A screen capture arrives at the display's PHYSICAL resolution — 2880 or 3840 across on the
|
|
58
|
+
* laptops this is reported from — and none of that detail survives being read by a person triaging
|
|
59
|
+
* a bug. Halving the width quarters the pixels, and 1920 is still wider than most people's browser
|
|
60
|
+
* window.
|
|
61
|
+
*/
|
|
62
|
+
const MAX_WIDTH = 1920;
|
|
63
|
+
/**
|
|
64
|
+
* WebP quality. Lossy, deliberately.
|
|
65
|
+
*
|
|
66
|
+
* A screenshot is a photograph of text, which is the worst case for PNG: lossless compression finds
|
|
67
|
+
* almost nothing to remove and the file comes out in megabytes. At 0.82 the text is still crisp and
|
|
68
|
+
* the file is a fraction of the size.
|
|
69
|
+
*/
|
|
70
|
+
const QUALITY = 0.82;
|
|
57
71
|
async function grabFrame(stream) {
|
|
58
72
|
const video = document.createElement('video');
|
|
59
73
|
video.srcObject = stream;
|
|
60
74
|
video.muted = true;
|
|
61
75
|
await video.play().catch(() => { });
|
|
76
|
+
const width = video.videoWidth || window.innerWidth;
|
|
77
|
+
const height = video.videoHeight || window.innerHeight;
|
|
78
|
+
// Scaled on the way into the canvas rather than afterwards, so the full-resolution bitmap is
|
|
79
|
+
// never held at all.
|
|
80
|
+
const scale = width > MAX_WIDTH ? MAX_WIDTH / width : 1;
|
|
62
81
|
const canvas = document.createElement('canvas');
|
|
63
|
-
canvas.width =
|
|
64
|
-
canvas.height =
|
|
82
|
+
canvas.width = Math.round(width * scale);
|
|
83
|
+
canvas.height = Math.round(height * scale);
|
|
65
84
|
const context = canvas.getContext('2d');
|
|
66
85
|
if (!context)
|
|
67
86
|
return null;
|
|
87
|
+
// Text is what a screenshot is mostly made of, and the default resampler smears it when
|
|
88
|
+
// downscaling. This is the one place the quality hint earns its cost.
|
|
89
|
+
context.imageSmoothingQuality = 'high';
|
|
68
90
|
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
69
91
|
video.pause();
|
|
70
92
|
video.srcObject = null;
|
|
71
|
-
|
|
93
|
+
const blob = await encode(canvas);
|
|
94
|
+
if (!blob)
|
|
95
|
+
return null;
|
|
96
|
+
// Named from what the browser ACTUALLY produced, not from what was asked for. A browser that
|
|
97
|
+
// cannot encode WebP does not fail — it silently returns a PNG — and a PNG called .webp is
|
|
98
|
+
// rejected by the server's magic-number check, which would turn a slow screenshot into a missing
|
|
99
|
+
// one.
|
|
100
|
+
const type = blob.type || 'image/png';
|
|
101
|
+
const extension = type === 'image/webp' ? 'webp' : type === 'image/jpeg' ? 'jpg' : 'png';
|
|
102
|
+
return { blob, filename: `screenshot.${extension}`, contentType: type };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Encodes the frame as small as the browser can manage.
|
|
106
|
+
*
|
|
107
|
+
* WebP first, JPEG second, and whatever comes back last. The order is by size on this kind of
|
|
108
|
+
* image: a 2880-wide screenshot is several megabytes as PNG and a couple of hundred kilobytes as
|
|
109
|
+
* WebP, and that difference is a report that uploads in a second rather than in a minute.
|
|
110
|
+
*
|
|
111
|
+
* Each step checks what came back rather than trusting the request. toBlob falls back to PNG
|
|
112
|
+
* silently for a format it does not support, so asking for WebP and believing the answer is how a
|
|
113
|
+
* fix like this quietly does nothing on Safari.
|
|
114
|
+
*
|
|
115
|
+
* Exported so that behaviour can be tested — it is the only part of the capture path that does not
|
|
116
|
+
* need a browser, and it is the part with the trap in it.
|
|
117
|
+
*/
|
|
118
|
+
export async function encode(canvas) {
|
|
119
|
+
for (const type of ['image/webp', 'image/jpeg']) {
|
|
120
|
+
const blob = await toBlob(canvas, type, QUALITY);
|
|
121
|
+
if (blob?.type === type)
|
|
122
|
+
return blob;
|
|
123
|
+
}
|
|
124
|
+
return toBlob(canvas, 'image/png');
|
|
125
|
+
}
|
|
126
|
+
function toBlob(canvas, type, quality) {
|
|
127
|
+
return new Promise(resolve => canvas.toBlob(blob => resolve(blob), type, quality));
|
|
72
128
|
}
|
|
73
129
|
/**
|
|
74
130
|
* Blurs anything the host app marked private, and every password field whether it was marked or not.
|
package/dist/types.d.ts
CHANGED
|
@@ -175,6 +175,26 @@ export interface FeedbackOptions {
|
|
|
175
175
|
breadcrumbs?: boolean;
|
|
176
176
|
/** Keyboard shortcut to enter pick mode. Defaults to "f". Set null to disable. */
|
|
177
177
|
hotkey?: string | null;
|
|
178
|
+
/**
|
|
179
|
+
* Which corner the widget lives in. Defaults to the workspace's own setting, then bottom-right.
|
|
180
|
+
*
|
|
181
|
+
* Set here it wins over the workspace setting, and that is the right way round: the workspace
|
|
182
|
+
* owner is choosing a default for every install, while whoever writes this line is looking at the
|
|
183
|
+
* page and knows what else is in that corner.
|
|
184
|
+
*
|
|
185
|
+
* It is a home rather than a fixed position. The reporter can drag the composer off whatever they
|
|
186
|
+
* are documenting, and it comes back here for the next report — see the widget's own notes on why
|
|
187
|
+
* that is not remembered.
|
|
188
|
+
*/
|
|
189
|
+
placement?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
190
|
+
/**
|
|
191
|
+
* Whether to stack above the host page's own floating buttons — a chat bubble, a back-to-top
|
|
192
|
+
* arrow — instead of landing on them. On by default.
|
|
193
|
+
*
|
|
194
|
+
* Turn it off if the page positions things by measuring OUR corner, or if the movement is more
|
|
195
|
+
* distracting than the overlap it avoids.
|
|
196
|
+
*/
|
|
197
|
+
avoidOverlap?: boolean;
|
|
178
198
|
/** Called after a successful report, e.g. to show your own confirmation. */
|
|
179
199
|
onSent?: (response: IngestResponse) => void;
|
|
180
200
|
/**
|
package/dist/widget.d.ts
CHANGED
|
@@ -37,6 +37,39 @@ export declare class FeedbackWidget {
|
|
|
37
37
|
*/
|
|
38
38
|
setTheme(theme: FeedbackTheme | null): void;
|
|
39
39
|
private launcherLabel;
|
|
40
|
+
/** The corner the workspace chose, if it chose one. The init option outranks it. */
|
|
41
|
+
private themePlacement;
|
|
42
|
+
/** How far the host page's own floating buttons push us out of that corner. */
|
|
43
|
+
private clearance;
|
|
44
|
+
/** Where the widget lives: the caller's choice, then the workspace's, then the bottom right. */
|
|
45
|
+
private get placement();
|
|
46
|
+
/**
|
|
47
|
+
* Writes the corner, plus whatever room the page's own furniture needs, as four numbers.
|
|
48
|
+
*
|
|
49
|
+
* Numbers rather than a keyword because a custom property holds a value, not a property name —
|
|
50
|
+
* "put it bottom left" has to be four offsets. They are computed together because the clearance
|
|
51
|
+
* is an addition to one of them, and `calc(auto + 12px)` is not a length.
|
|
52
|
+
*
|
|
53
|
+
* This used to be a lookup table, which is what kept a server-sent position out of the stylesheet:
|
|
54
|
+
* an unrecognised key found nothing. Nothing is looked up now, and the same property holds for a
|
|
55
|
+
* better reason — the value itself never reaches the CSS. Only the words `left`, `right`, `top`
|
|
56
|
+
* and `bottom`, chosen here, and two numbers.
|
|
57
|
+
*/
|
|
58
|
+
private applyPlacement;
|
|
59
|
+
/** The box the widget would occupy if nothing were in its way. What the probe measures. */
|
|
60
|
+
private homeSlot;
|
|
61
|
+
/**
|
|
62
|
+
* Keeps out of the way of whatever else is in the corner, as that changes.
|
|
63
|
+
*
|
|
64
|
+
* Re-measured rather than measured once, because the button most likely to collide with ours is
|
|
65
|
+
* the one that is not there yet: a back-to-top arrow appears on scroll, a chat bubble loads a
|
|
66
|
+
* second after the page. Scroll, resize and DOM changes all trigger a re-read, coalesced into at
|
|
67
|
+
* most one per frame.
|
|
68
|
+
*
|
|
69
|
+
* Never while the composer is open. Moving a form out from under somebody's cursor mid-sentence
|
|
70
|
+
* is a worse thing to do to them than overlapping a button they are not currently using.
|
|
71
|
+
*/
|
|
72
|
+
private watchClearance;
|
|
40
73
|
/**
|
|
41
74
|
* What the widget is allowed to do, from the handshake.
|
|
42
75
|
*
|
|
@@ -77,13 +110,19 @@ export declare class FeedbackWidget {
|
|
|
77
110
|
*/
|
|
78
111
|
conceal(): () => void;
|
|
79
112
|
/**
|
|
80
|
-
* Where the reporter dragged the panel to, if they did.
|
|
113
|
+
* Where the reporter dragged the panel to, if they did — for this report only.
|
|
114
|
+
*
|
|
115
|
+
* It used to be remembered in localStorage, across reports and across visits, on the reasoning
|
|
116
|
+
* that somebody who moved it once would want it moved next time. In use that is not what it feels
|
|
117
|
+
* like: the widget turns up in a different place on every page of the app with no explanation of
|
|
118
|
+
* why, and the place it turns up is wherever it was last shoved out of the way — a position
|
|
119
|
+
* chosen to be temporary. A home you can move things away from is easier to live with than a
|
|
120
|
+
* position that drifts.
|
|
81
121
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* is the friction that stops the second report being written.
|
|
122
|
+
* So a drag lasts as long as the report. Sending resets it, closing resets it, and the next
|
|
123
|
+
* report opens where the install said it would.
|
|
85
124
|
*/
|
|
86
|
-
private
|
|
125
|
+
private dragged;
|
|
87
126
|
/**
|
|
88
127
|
* Makes the panel draggable by its header, and snaps it to a side when it is let go near one.
|
|
89
128
|
*
|
|
@@ -92,7 +131,7 @@ export declare class FeedbackWidget {
|
|
|
92
131
|
* one corner, the only way to do that was to close the widget, which loses what they had written.
|
|
93
132
|
*/
|
|
94
133
|
private movable;
|
|
95
|
-
/** Applies the
|
|
134
|
+
/** Applies the drag, if there is one, or hands the panel back to its home corner. */
|
|
96
135
|
private place;
|
|
97
136
|
private render;
|
|
98
137
|
/**
|
package/dist/widget.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { captureAnchor } from './anchor.js';
|
|
2
2
|
import { fromPaste, MAX_FILES, revoke, stage } from './files.js';
|
|
3
3
|
import { isTyping } from './hotkey.js';
|
|
4
|
+
import { measureClearance } from './clearance.js';
|
|
4
5
|
/**
|
|
5
6
|
* The reporter-facing UI, rendered inside a shadow root.
|
|
6
7
|
*
|
|
@@ -17,6 +18,8 @@ export class FeedbackWidget {
|
|
|
17
18
|
this.mode = 'idle';
|
|
18
19
|
this.anchor = null;
|
|
19
20
|
this.detach = [];
|
|
21
|
+
/** How far the host page's own floating buttons push us out of that corner. */
|
|
22
|
+
this.clearance = 0;
|
|
20
23
|
/**
|
|
21
24
|
* What the widget is allowed to do, from the handshake.
|
|
22
25
|
*
|
|
@@ -32,13 +35,19 @@ export class FeedbackWidget {
|
|
|
32
35
|
*/
|
|
33
36
|
this.policy = null;
|
|
34
37
|
/**
|
|
35
|
-
* Where the reporter dragged the panel to, if they did.
|
|
38
|
+
* Where the reporter dragged the panel to, if they did — for this report only.
|
|
36
39
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
+
* It used to be remembered in localStorage, across reports and across visits, on the reasoning
|
|
41
|
+
* that somebody who moved it once would want it moved next time. In use that is not what it feels
|
|
42
|
+
* like: the widget turns up in a different place on every page of the app with no explanation of
|
|
43
|
+
* why, and the place it turns up is wherever it was last shoved out of the way — a position
|
|
44
|
+
* chosen to be temporary. A home you can move things away from is easier to live with than a
|
|
45
|
+
* position that drifts.
|
|
46
|
+
*
|
|
47
|
+
* So a drag lasts as long as the report. Sending resets it, closing resets it, and the next
|
|
48
|
+
* report opens where the install said it would.
|
|
40
49
|
*/
|
|
41
|
-
this.
|
|
50
|
+
this.dragged = null;
|
|
42
51
|
/** The reference of the last report, so the confirmation can quote it. */
|
|
43
52
|
this.reference = null;
|
|
44
53
|
/** How many attachments did not land, so the confirmation can be honest about it. */
|
|
@@ -50,7 +59,8 @@ export class FeedbackWidget {
|
|
|
50
59
|
this.host.style.cssText = 'position:fixed;inset:0;z-index:2147483000;pointer-events:none';
|
|
51
60
|
this.root = this.host.attachShadow({ mode: 'open' });
|
|
52
61
|
this.root.innerHTML =
|
|
53
|
-
`<style>${STYLES}</style><style id="theme"></style><
|
|
62
|
+
`<style>${STYLES}</style><style id="theme"></style><style id="place"></style>`
|
|
63
|
+
+ `<div id="layer"></div>`;
|
|
54
64
|
}
|
|
55
65
|
/**
|
|
56
66
|
* Applies the tokens the handshake served.
|
|
@@ -75,14 +85,124 @@ export class FeedbackWidget {
|
|
|
75
85
|
const radius = { none: '0', sm: '6px', md: '12px', lg: '18px' }[theme.cornerRadius ?? 'md'];
|
|
76
86
|
if (radius)
|
|
77
87
|
declarations.push(`--pm-radius: ${radius}`);
|
|
78
|
-
const corner = POSITIONS[theme.position ?? 'bottom-right'];
|
|
79
|
-
if (corner)
|
|
80
|
-
declarations.push(corner);
|
|
81
88
|
style.textContent = declarations.length > 0 ? `:host { ${declarations.join('; ')} }` : '';
|
|
89
|
+
// The corner is deliberately NOT written here. Where the widget sits is decided by one method
|
|
90
|
+
// that also has to account for the host page's furniture, and two style blocks both claiming
|
|
91
|
+
// --pm-bottom is how the second one silently wins.
|
|
92
|
+
this.themePlacement = theme.position;
|
|
93
|
+
this.applyPlacement();
|
|
82
94
|
this.launcherLabel = typeof theme.launcherLabel === 'string' && theme.launcherLabel.length > 0
|
|
83
95
|
? theme.launcherLabel.slice(0, 24)
|
|
84
96
|
: undefined;
|
|
85
97
|
}
|
|
98
|
+
/** Where the widget lives: the caller's choice, then the workspace's, then the bottom right. */
|
|
99
|
+
get placement() {
|
|
100
|
+
return this.options.placement ?? this.themePlacement ?? 'bottom-right';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Writes the corner, plus whatever room the page's own furniture needs, as four numbers.
|
|
104
|
+
*
|
|
105
|
+
* Numbers rather than a keyword because a custom property holds a value, not a property name —
|
|
106
|
+
* "put it bottom left" has to be four offsets. They are computed together because the clearance
|
|
107
|
+
* is an addition to one of them, and `calc(auto + 12px)` is not a length.
|
|
108
|
+
*
|
|
109
|
+
* This used to be a lookup table, which is what kept a server-sent position out of the stylesheet:
|
|
110
|
+
* an unrecognised key found nothing. Nothing is looked up now, and the same property holds for a
|
|
111
|
+
* better reason — the value itself never reaches the CSS. Only the words `left`, `right`, `top`
|
|
112
|
+
* and `bottom`, chosen here, and two numbers.
|
|
113
|
+
*/
|
|
114
|
+
applyPlacement() {
|
|
115
|
+
const style = this.root.getElementById('place');
|
|
116
|
+
if (!style)
|
|
117
|
+
return;
|
|
118
|
+
const at = this.placement;
|
|
119
|
+
const near = at.startsWith('bottom') ? 'bottom' : 'top';
|
|
120
|
+
const side = at.endsWith('right') ? 'right' : 'left';
|
|
121
|
+
const offset = EDGE + this.clearance;
|
|
122
|
+
style.textContent = `:host {
|
|
123
|
+
--pm-${side}: ${EDGE}px; --pm-${side === 'right' ? 'left' : 'right'}: auto;
|
|
124
|
+
--pm-${near}: ${offset}px; --pm-${near === 'bottom' ? 'top' : 'bottom'}: auto;
|
|
125
|
+
}`;
|
|
126
|
+
}
|
|
127
|
+
/** The box the widget would occupy if nothing were in its way. What the probe measures. */
|
|
128
|
+
homeSlot() {
|
|
129
|
+
const at = this.placement;
|
|
130
|
+
const width = 220;
|
|
131
|
+
const height = 48;
|
|
132
|
+
const right = at.endsWith('right') ? window.innerWidth - EDGE : EDGE + width;
|
|
133
|
+
const bottom = at.startsWith('bottom') ? window.innerHeight - EDGE : EDGE + height;
|
|
134
|
+
return {
|
|
135
|
+
left: right - width,
|
|
136
|
+
right,
|
|
137
|
+
top: bottom - height,
|
|
138
|
+
bottom,
|
|
139
|
+
v: at.startsWith('bottom') ? 'bottom' : 'top',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Keeps out of the way of whatever else is in the corner, as that changes.
|
|
144
|
+
*
|
|
145
|
+
* Re-measured rather than measured once, because the button most likely to collide with ours is
|
|
146
|
+
* the one that is not there yet: a back-to-top arrow appears on scroll, a chat bubble loads a
|
|
147
|
+
* second after the page. Scroll, resize and DOM changes all trigger a re-read, coalesced into at
|
|
148
|
+
* most one per frame.
|
|
149
|
+
*
|
|
150
|
+
* Never while the composer is open. Moving a form out from under somebody's cursor mid-sentence
|
|
151
|
+
* is a worse thing to do to them than overlapping a button they are not currently using.
|
|
152
|
+
*/
|
|
153
|
+
watchClearance() {
|
|
154
|
+
if (this.options.avoidOverlap === false)
|
|
155
|
+
return;
|
|
156
|
+
let queued = false;
|
|
157
|
+
const measure = () => {
|
|
158
|
+
queued = false;
|
|
159
|
+
if (this.mode !== 'idle')
|
|
160
|
+
return;
|
|
161
|
+
try {
|
|
162
|
+
const next = measureClearance(this.homeSlot(), this.host);
|
|
163
|
+
// A pixel or two of churn is measurement noise, and acting on it makes the launcher shiver.
|
|
164
|
+
if (Math.abs(next - this.clearance) < 4)
|
|
165
|
+
return;
|
|
166
|
+
this.clearance = next;
|
|
167
|
+
this.applyPlacement();
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
// Whatever the page did to make this throw, the widget staying where it is beats the widget
|
|
171
|
+
// not being there. Politeness is not worth an exception on somebody else's page.
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
// Every capability here is checked rather than assumed. This runs inside mount, so an
|
|
175
|
+
// environment without one of them would otherwise mean no widget at all rather than a widget
|
|
176
|
+
// that does not dodge — which is how a courtesy becomes an outage.
|
|
177
|
+
const soon = typeof requestAnimationFrame === 'function'
|
|
178
|
+
? (fn) => requestAnimationFrame(fn)
|
|
179
|
+
: (fn) => setTimeout(fn, 16);
|
|
180
|
+
const schedule = () => {
|
|
181
|
+
if (queued)
|
|
182
|
+
return;
|
|
183
|
+
queued = true;
|
|
184
|
+
soon(measure);
|
|
185
|
+
};
|
|
186
|
+
window.addEventListener('scroll', schedule, { passive: true, capture: true });
|
|
187
|
+
window.addEventListener('resize', schedule);
|
|
188
|
+
this.detach.push(() => {
|
|
189
|
+
window.removeEventListener('scroll', schedule, { capture: true });
|
|
190
|
+
window.removeEventListener('resize', schedule);
|
|
191
|
+
});
|
|
192
|
+
// Attributes as well as children: the back-to-top button usually exists all along and is being
|
|
193
|
+
// shown by a class or a style, which is not a childList change.
|
|
194
|
+
if (typeof MutationObserver === 'function') {
|
|
195
|
+
const observer = new MutationObserver(schedule);
|
|
196
|
+
observer.observe(document.documentElement, {
|
|
197
|
+
childList: true,
|
|
198
|
+
subtree: true,
|
|
199
|
+
attributes: true,
|
|
200
|
+
attributeFilter: ['style', 'class', 'hidden'],
|
|
201
|
+
});
|
|
202
|
+
this.detach.push(() => observer.disconnect());
|
|
203
|
+
}
|
|
204
|
+
schedule();
|
|
205
|
+
}
|
|
86
206
|
setState(state) {
|
|
87
207
|
this.state = state;
|
|
88
208
|
if (this.host.isConnected)
|
|
@@ -90,7 +210,9 @@ export class FeedbackWidget {
|
|
|
90
210
|
}
|
|
91
211
|
mount() {
|
|
92
212
|
document.body.appendChild(this.host);
|
|
213
|
+
this.applyPlacement();
|
|
93
214
|
this.render();
|
|
215
|
+
this.watchClearance();
|
|
94
216
|
if (this.options.hotkey !== null) {
|
|
95
217
|
const hotkey = (this.options.hotkey ?? 'f').toLowerCase();
|
|
96
218
|
const onKey = (event) => {
|
|
@@ -104,6 +226,7 @@ export class FeedbackWidget {
|
|
|
104
226
|
if (this.mode === 'picking') {
|
|
105
227
|
this.mode = 'idle';
|
|
106
228
|
this.anchor = null;
|
|
229
|
+
this.dragged = null;
|
|
107
230
|
this.render();
|
|
108
231
|
}
|
|
109
232
|
return;
|
|
@@ -174,8 +297,7 @@ export class FeedbackWidget {
|
|
|
174
297
|
handle.classList.add('drag');
|
|
175
298
|
handle.title = 'Drag to move · double-click to reset';
|
|
176
299
|
handle.addEventListener('dblclick', () => {
|
|
177
|
-
this.
|
|
178
|
-
writePlacement(null);
|
|
300
|
+
this.dragged = null;
|
|
179
301
|
this.place(panel);
|
|
180
302
|
});
|
|
181
303
|
handle.addEventListener('pointerdown', (event) => {
|
|
@@ -206,8 +328,7 @@ export class FeedbackWidget {
|
|
|
206
328
|
handle.removeEventListener('pointerup', drop);
|
|
207
329
|
handle.removeEventListener('pointercancel', drop);
|
|
208
330
|
panel.classList.remove('panel--dragging');
|
|
209
|
-
this.
|
|
210
|
-
writePlacement(this.placement);
|
|
331
|
+
this.dragged = stickToFrame(panel.getBoundingClientRect());
|
|
211
332
|
this.place(panel);
|
|
212
333
|
};
|
|
213
334
|
handle.addEventListener('pointermove', move);
|
|
@@ -215,9 +336,9 @@ export class FeedbackWidget {
|
|
|
215
336
|
handle.addEventListener('pointercancel', drop);
|
|
216
337
|
});
|
|
217
338
|
}
|
|
218
|
-
/** Applies the
|
|
339
|
+
/** Applies the drag, if there is one, or hands the panel back to its home corner. */
|
|
219
340
|
place(panel) {
|
|
220
|
-
const at = this.
|
|
341
|
+
const at = this.dragged;
|
|
221
342
|
if (!at) {
|
|
222
343
|
panel.style.left = panel.style.right = panel.style.top = panel.style.bottom = '';
|
|
223
344
|
return;
|
|
@@ -241,11 +362,14 @@ export class FeedbackWidget {
|
|
|
241
362
|
return;
|
|
242
363
|
}
|
|
243
364
|
if (this.mode === 'sent') {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
|
|
365
|
+
// Home, deliberately, and the drag is dropped on the way.
|
|
366
|
+
//
|
|
367
|
+
// The confirmation used to appear wherever the composer had been dragged to, which is the one
|
|
368
|
+
// place it should not: the reporter moved the panel to see something underneath it, the panel
|
|
369
|
+
// is gone, and a tick they were not looking for lands over that same spot. The reference in it
|
|
370
|
+
// is the only copy they will ever be shown, so it goes where the widget lives.
|
|
371
|
+
this.dragged = null;
|
|
372
|
+
layer.appendChild(this.sent());
|
|
249
373
|
return;
|
|
250
374
|
}
|
|
251
375
|
if (this.mode === 'picking') {
|
|
@@ -512,6 +636,7 @@ export class FeedbackWidget {
|
|
|
512
636
|
revoke(files);
|
|
513
637
|
this.mode = 'idle';
|
|
514
638
|
this.anchor = null;
|
|
639
|
+
this.dragged = null;
|
|
515
640
|
this.render();
|
|
516
641
|
};
|
|
517
642
|
panel.querySelector('#cancel').onclick = dismiss;
|
|
@@ -619,56 +744,48 @@ export async function copyText(text) {
|
|
|
619
744
|
scratch.remove();
|
|
620
745
|
}
|
|
621
746
|
}
|
|
622
|
-
/**
|
|
623
|
-
const SNAP = 72;
|
|
747
|
+
/** The margin every edge of the widget keeps from the frame. */
|
|
624
748
|
const EDGE = 16;
|
|
625
749
|
/** Enough of the header must stay reachable to drag it back. */
|
|
626
750
|
const HANDLE = 56;
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
751
|
+
/**
|
|
752
|
+
* Where a dropped panel lands: against the nearest edge of the frame, always.
|
|
753
|
+
*
|
|
754
|
+
* It used to stay wherever it was let go unless that happened to be within 72px of a side, so the
|
|
755
|
+
* usual outcome of a drag was a panel floating in the middle of somebody's page at whatever angle
|
|
756
|
+
* the reporter's hand left it. Against a side it reads as a tool that has been put somewhere; in
|
|
757
|
+
* the middle it reads as something dropped.
|
|
758
|
+
*
|
|
759
|
+
* Only the nearest axis pins. Drag it to the left edge halfway down the page and it goes flush
|
|
760
|
+
* left, still halfway down — moving it to a side should not also move it to a corner it was not
|
|
761
|
+
* taken to.
|
|
762
|
+
*
|
|
763
|
+
* Offsets from a corner rather than absolute coordinates, because absolute coordinates do not
|
|
764
|
+
* survive a resize: a panel dropped at x=1600 is off-screen the moment the window narrows, and the
|
|
765
|
+
* reporter cannot reach the header to drag it back.
|
|
766
|
+
*/
|
|
767
|
+
function stickToFrame(rect) {
|
|
768
|
+
const gaps = {
|
|
769
|
+
left: rect.left,
|
|
770
|
+
right: window.innerWidth - rect.right,
|
|
771
|
+
top: rect.top,
|
|
772
|
+
bottom: window.innerHeight - rect.bottom,
|
|
773
|
+
};
|
|
774
|
+
const nearest = Object.keys(gaps)
|
|
775
|
+
.reduce((closest, side) => (gaps[side] < gaps[closest] ? side : closest));
|
|
776
|
+
const h = nearest === 'left' || nearest === 'right'
|
|
777
|
+
? nearest
|
|
778
|
+
: gaps.left <= gaps.right ? 'left' : 'right';
|
|
779
|
+
const v = nearest === 'top' || nearest === 'bottom'
|
|
780
|
+
? nearest
|
|
781
|
+
: gaps.top <= gaps.bottom ? 'top' : 'bottom';
|
|
635
782
|
return {
|
|
636
783
|
h,
|
|
637
784
|
v,
|
|
638
|
-
dx:
|
|
639
|
-
dy:
|
|
785
|
+
dx: nearest === h ? EDGE : Math.max(EDGE, Math.round(gaps[h])),
|
|
786
|
+
dy: nearest === v ? EDGE : Math.max(EDGE, Math.round(gaps[v])),
|
|
640
787
|
};
|
|
641
788
|
}
|
|
642
|
-
function readPlacement() {
|
|
643
|
-
try {
|
|
644
|
-
const raw = localStorage.getItem(PLACEMENT_KEY);
|
|
645
|
-
if (!raw)
|
|
646
|
-
return null;
|
|
647
|
-
const parsed = JSON.parse(raw);
|
|
648
|
-
// Validated rather than trusted: this is storage the host page can also write to, and the
|
|
649
|
-
// values go straight into a style property.
|
|
650
|
-
return (parsed.h === 'left' || parsed.h === 'right')
|
|
651
|
-
&& (parsed.v === 'top' || parsed.v === 'bottom')
|
|
652
|
-
&& Number.isFinite(parsed.dx) && Number.isFinite(parsed.dy)
|
|
653
|
-
? parsed
|
|
654
|
-
: null;
|
|
655
|
-
}
|
|
656
|
-
catch {
|
|
657
|
-
return null;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
function writePlacement(placement) {
|
|
661
|
-
try {
|
|
662
|
-
if (placement)
|
|
663
|
-
localStorage.setItem(PLACEMENT_KEY, JSON.stringify(placement));
|
|
664
|
-
else
|
|
665
|
-
localStorage.removeItem(PLACEMENT_KEY);
|
|
666
|
-
}
|
|
667
|
-
catch {
|
|
668
|
-
// Private mode, or a full quota. Losing where the panel was put is not worth an exception on
|
|
669
|
-
// somebody else's page.
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
789
|
function clamp(value, min, max) {
|
|
673
790
|
return Math.min(Math.max(value, min), max);
|
|
674
791
|
}
|
|
@@ -680,18 +797,6 @@ function escapeHtml(value) {
|
|
|
680
797
|
* hard-coded rather than inherited for the same reason — a host app's dark mode should not make our
|
|
681
798
|
* text invisible.
|
|
682
799
|
*/
|
|
683
|
-
/**
|
|
684
|
-
* Where the launcher and the panel sit, as a pair of custom properties.
|
|
685
|
-
*
|
|
686
|
-
* A fixed map rather than free text: the value goes into a stylesheet, and a position that is not
|
|
687
|
-
* one of these four is a string somebody chose.
|
|
688
|
-
*/
|
|
689
|
-
const POSITIONS = {
|
|
690
|
-
'bottom-right': '--pm-left: auto; --pm-right: 16px; --pm-top: auto; --pm-bottom: 16px',
|
|
691
|
-
'bottom-left': '--pm-left: 16px; --pm-right: auto; --pm-top: auto; --pm-bottom: 16px',
|
|
692
|
-
'top-right': '--pm-left: auto; --pm-right: 16px; --pm-top: 16px; --pm-bottom: auto',
|
|
693
|
-
'top-left': '--pm-left: 16px; --pm-right: auto; --pm-top: 16px; --pm-bottom: auto',
|
|
694
|
-
};
|
|
695
800
|
/**
|
|
696
801
|
* A hex colour, an rgb()/hsl() call, or a plain CSS colour word.
|
|
697
802
|
*
|
|
@@ -718,11 +823,15 @@ const STYLES = `
|
|
|
718
823
|
--pm-bottom: 16px;
|
|
719
824
|
}
|
|
720
825
|
* { box-sizing: border-box; font-family: system-ui, -apple-system, sans-serif }
|
|
826
|
+
@media (prefers-reduced-motion: reduce) { .launcher { transition: none } }
|
|
721
827
|
#layer { position: fixed; inset: 0; pointer-events: none }
|
|
722
828
|
.launcher {
|
|
723
829
|
position: fixed; pointer-events: auto;
|
|
724
830
|
left: var(--pm-left); right: var(--pm-right);
|
|
725
831
|
top: var(--pm-top); bottom: var(--pm-bottom);
|
|
832
|
+
/* A back-to-top button appearing on scroll moves us; gliding reads as making room, and jumping
|
|
833
|
+
reads as a bug. Honoured only where motion is welcome. */
|
|
834
|
+
transition: bottom .18s ease, top .18s ease;
|
|
726
835
|
padding: 9px 14px; border: 0; border-radius: 999px; cursor: pointer;
|
|
727
836
|
background: var(--pm-accent); color: #fafafa; font-size: 13px; font-weight: 500;
|
|
728
837
|
box-shadow: 0 2px 12px rgba(0,0,0,.3);
|
package/package.json
CHANGED