@vitrinka/web 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/README.md +59 -5
- package/build/hud.d.ts +1 -1
- package/build/hud.iife.js +46 -9
- package/build/protocol/index.d.ts +55 -4
- package/build/protocol/index.js +4 -2
- package/build/recorder/api.d.ts +25 -5
- package/build/recorder/api.js +21 -9
- package/build/recorder/attachments.d.ts +19 -0
- package/build/recorder/attachments.js +31 -0
- package/build/recorder/hud/Hud.d.ts +1 -1
- package/build/recorder/hud/Hud.js +43 -10
- package/build/recorder/hud/Sheet.d.ts +40 -5
- package/build/recorder/hud/Sheet.js +134 -8
- package/build/recorder/hud/attach.d.ts +26 -0
- package/build/recorder/hud/attach.js +136 -0
- package/build/recorder/hud/controller.d.ts +31 -3
- package/build/recorder/hud/controller.js +1 -1
- package/build/recorder/hud/host.js +2 -0
- package/build/recorder/hud/icons.d.ts +3 -0
- package/build/recorder/hud/icons.js +7 -0
- package/build/recorder/hud/layer.d.ts +4 -1
- package/build/recorder/hud/layer.js +11 -3
- package/build/recorder/hud/resize.d.ts +83 -0
- package/build/recorder/hud/resize.js +236 -0
- package/build/recorder/hud/styles.d.ts +1 -1
- package/build/recorder/hud/styles.js +38 -1
- package/build/recorder/link.d.ts +4 -1
- package/build/recorder/link.js +6 -2
- package/build/recorder/me.d.ts +7 -0
- package/build/recorder/me.js +62 -12
- package/build/recorder/page-controller.js +4 -3
- package/build/recorder/queue.d.ts +33 -3
- package/build/recorder/queue.js +404 -24
- package/build/recorder/report.d.ts +9 -0
- package/build/recorder/report.js +46 -4
- package/build/recorder/session.d.ts +13 -5
- package/build/recorder/session.js +42 -12
- package/build/recorder/storage/blobs.d.ts +32 -0
- package/build/recorder/storage/blobs.js +83 -0
- package/build/recorder/storage/index.js +3 -2
- package/package.json +1 -1
|
@@ -1,20 +1,61 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
3
|
-
* The composer sheet — the extension's hud.html, as a component:
|
|
4
|
-
* anchored to the dock (a bottom sheet on phones), a 14px textarea
|
|
5
|
-
* touch, so iOS never zooms)
|
|
3
|
+
* The composer sheet — the extension's hud.html, as a component: 440px wide
|
|
4
|
+
* by default, anchored to the dock (a bottom sheet on phones), a 14px textarea
|
|
5
|
+
* (16px on touch, so iOS never zooms) that grows with the draft up to a cap
|
|
6
|
+
* and then scrolls, a resize grip on the corner away from the dock (width
|
|
7
|
+
* and cap are HUD prefs — resize.ts), ✕ in the title row, a three-column footer
|
|
6
8
|
* (board|task · context · ↑ Send) and the hint line (hidden on touch). Enter sends, ⇧Enter newlines, Esc
|
|
7
9
|
* cancels. The DRAFT is owned by the caller so a cancel keeps it until the
|
|
8
10
|
* next send (recorder-hud-polish D3); the board|task choice resets on every
|
|
9
11
|
* open — a destination is per observation, not a mode. The bug report is the
|
|
10
12
|
* same sheet: a required description and "Mark on screen" in the board|task
|
|
11
13
|
* slot.
|
|
14
|
+
*
|
|
15
|
+
* Images (recorder attachments), only when the caller passes `images`: the
|
|
16
|
+
* paperclip beside Send picks them, an image paste on the textarea and a
|
|
17
|
+
* drop onto the sheet add them (attach.ts normalizes each), a strip of
|
|
18
|
+
* thumbnails above the footer removes them, at most `MAX_ATTACHMENTS`. Like
|
|
19
|
+
* the text, the caller owns them — and the count still preparing — so a
|
|
20
|
+
* cancel keeps them and a reopened sheet still waits. A refusal (not an
|
|
21
|
+
* image, the cap) shows in the footer's context slot — one line, so the
|
|
22
|
+
* footer never moves.
|
|
12
23
|
*/
|
|
13
|
-
import { useEffect, useRef, useState } from 'react';
|
|
14
|
-
import {
|
|
15
|
-
|
|
24
|
+
import { useEffect, useRef, useState, } from 'react';
|
|
25
|
+
import { MAX_ATTACHMENTS, normalizeAttachment, pastedName } from './attach';
|
|
26
|
+
import { ArrowUpIcon, CloseIcon, GripIcon, PaperclipIcon, SpinnerIcon } from './icons';
|
|
27
|
+
import { useSheetSize } from './resize';
|
|
28
|
+
/** How long a refusal holds the context slot. */
|
|
29
|
+
const REFUSAL_MS = 5000;
|
|
30
|
+
const errorText = (e) => (e instanceof Error ? e.message : String(e));
|
|
31
|
+
/** A stable React key per image (a name can repeat, an index shifts on remove). */
|
|
32
|
+
const keys = new WeakMap();
|
|
33
|
+
let lastKey = 0;
|
|
34
|
+
function keyOf(image) {
|
|
35
|
+
let k = keys.get(image);
|
|
36
|
+
if (k === undefined)
|
|
37
|
+
keys.set(image, (k = ++lastKey));
|
|
38
|
+
return k;
|
|
39
|
+
}
|
|
40
|
+
/** A drag that carries files (not a text selection or a link). */
|
|
41
|
+
const carriesFiles = (e) => Array.from(e.dataTransfer.types).includes('Files');
|
|
42
|
+
function Thumb({ image, onRemove }) {
|
|
43
|
+
const [src, setSrc] = useState('');
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const url = URL.createObjectURL(image.blob);
|
|
46
|
+
setSrc(url);
|
|
47
|
+
return () => URL.revokeObjectURL(url);
|
|
48
|
+
}, [image.blob]);
|
|
49
|
+
return (_jsxs("li", { className: "att", children: [src ? _jsx("img", { src: src, alt: image.name }) : null, _jsx("button", { type: "button", className: "attx", "aria-label": `Remove ${image.name}`, onClick: onRemove, children: _jsx(CloseIcon, {}) })] }));
|
|
50
|
+
}
|
|
51
|
+
export function Sheet({ className, origin, title, ctx, pick, draft, onDraft, onSend, onClose, placeholder = "what's wrong / what to refine…", required = false, onMark, marked = false, images, onImages, preparing: busy = 0, onPreparing, kind = 'note', sheetW = 0, sheetH = 0, room = 0, grip = null, onResize, onLayout, }) {
|
|
52
|
+
const pop = useRef(null);
|
|
16
53
|
const ta = useRef(null);
|
|
54
|
+
const file = useRef(null);
|
|
55
|
+
const size = useSheetSize({ sheet: pop, text: ta, width: sheetW, cap: sheetH, room, grip, onResize, onLayout });
|
|
17
56
|
const [task, setTask] = useState(false);
|
|
57
|
+
const [refusal, setRefusal] = useState('');
|
|
58
|
+
const [dropping, setDropping] = useState(false);
|
|
18
59
|
useEffect(() => {
|
|
19
60
|
const el = ta.current;
|
|
20
61
|
if (!el)
|
|
@@ -22,14 +63,95 @@ export function Sheet({ className, origin, title, ctx, pick, draft, onDraft, onS
|
|
|
22
63
|
el.focus();
|
|
23
64
|
el.setSelectionRange(el.value.length, el.value.length);
|
|
24
65
|
}, []);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!refusal)
|
|
68
|
+
return;
|
|
69
|
+
const t = setTimeout(() => setRefusal(''), REFUSAL_MS);
|
|
70
|
+
return () => clearTimeout(t);
|
|
71
|
+
}, [refusal]);
|
|
25
72
|
const empty = required && draft.trim() === '';
|
|
73
|
+
const held = images?.length ?? 0;
|
|
74
|
+
const full = held + busy >= MAX_ATTACHMENTS;
|
|
26
75
|
const send = () => {
|
|
27
|
-
if (empty) {
|
|
76
|
+
if (empty || busy > 0) {
|
|
28
77
|
ta.current?.focus();
|
|
29
78
|
return;
|
|
30
79
|
}
|
|
31
80
|
onSend(draft.trim(), task);
|
|
32
81
|
};
|
|
82
|
+
// Normalize in order (the strip keeps the order they came in); the cap is
|
|
83
|
+
// re-checked as each lands, so two quick adds never pass it. The work can
|
|
84
|
+
// outlive this sheet (a cancel mid-way): its count and its result go to
|
|
85
|
+
// the caller's draft, never to this sheet's state.
|
|
86
|
+
const attach = (files, pasted = false) => {
|
|
87
|
+
if (!onImages || !onPreparing || !files.length)
|
|
88
|
+
return;
|
|
89
|
+
const take = files.slice(0, Math.max(0, MAX_ATTACHMENTS - held - busy));
|
|
90
|
+
setRefusal(take.length < files.length ? `${MAX_ATTACHMENTS} images at most` : '');
|
|
91
|
+
if (!take.length)
|
|
92
|
+
return;
|
|
93
|
+
onPreparing((n) => n + take.length);
|
|
94
|
+
void (async () => {
|
|
95
|
+
for (const f of take) {
|
|
96
|
+
try {
|
|
97
|
+
const image = await normalizeAttachment(f, pasted ? pastedName(f) : f.name || 'image');
|
|
98
|
+
onImages((prev) => (prev.length >= MAX_ATTACHMENTS ? prev : [...prev, image]));
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
setRefusal(errorText(e));
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
onPreparing((n) => n - 1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
108
|
+
};
|
|
109
|
+
const remove = (image) => {
|
|
110
|
+
onImages?.((prev) => prev.filter((x) => x !== image));
|
|
111
|
+
setRefusal('');
|
|
112
|
+
ta.current?.focus();
|
|
113
|
+
};
|
|
114
|
+
const browse = () => {
|
|
115
|
+
if (full) {
|
|
116
|
+
setRefusal(`${MAX_ATTACHMENTS} images at most`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
file.current?.click();
|
|
120
|
+
};
|
|
121
|
+
// An image paste attaches; a text paste stays a text paste (an office app
|
|
122
|
+
// puts a picture of the copied cells beside their text), unless the text
|
|
123
|
+
// is only a copied file's name.
|
|
124
|
+
const onPaste = (e) => {
|
|
125
|
+
if (!onImages)
|
|
126
|
+
return;
|
|
127
|
+
const files = Array.from(e.clipboardData.files);
|
|
128
|
+
if (!files.length)
|
|
129
|
+
return;
|
|
130
|
+
const text = e.clipboardData.getData('text/plain').trim();
|
|
131
|
+
if (text && !files.some((f) => f.name && text.includes(f.name)))
|
|
132
|
+
return;
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
attach(files, true);
|
|
135
|
+
};
|
|
136
|
+
const onDragOver = (e) => {
|
|
137
|
+
if (!onImages || !carriesFiles(e))
|
|
138
|
+
return;
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
e.dataTransfer.dropEffect = 'copy';
|
|
141
|
+
setDropping(true);
|
|
142
|
+
};
|
|
143
|
+
const onDragLeave = (e) => {
|
|
144
|
+
if (!e.currentTarget.contains(e.relatedTarget))
|
|
145
|
+
setDropping(false);
|
|
146
|
+
};
|
|
147
|
+
const onDrop = (e) => {
|
|
148
|
+
if (!onImages || !carriesFiles(e))
|
|
149
|
+
return;
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
setDropping(false);
|
|
152
|
+
attach(Array.from(e.dataTransfer.files));
|
|
153
|
+
};
|
|
154
|
+
const sendb = (_jsxs("button", { type: "button", className: "sendb", "aria-disabled": empty || busy > 0 || undefined, onClick: send, children: [_jsx(ArrowUpIcon, {}), _jsx("span", { children: "Send" })] }));
|
|
33
155
|
const onKey = (e) => {
|
|
34
156
|
if (e.key === 'Escape') {
|
|
35
157
|
e.preventDefault();
|
|
@@ -42,5 +164,9 @@ export function Sheet({ className, origin, title, ctx, pick, draft, onDraft, onS
|
|
|
42
164
|
send();
|
|
43
165
|
}
|
|
44
166
|
};
|
|
45
|
-
return (_jsxs("div", { className: `pop ${className}`, style: { transformOrigin: origin }, role: "dialog", "aria-labelledby": "vt-pop-title", onKeyDown: onKey, children: [_jsxs("div", { className: "pop-head", children: [_jsxs("span", { className: "title", children: [_jsx("i", {}), _jsx("span", { id: "vt-pop-title", children: title })] }), _jsx("button", { type: "button", className: "closeb", "aria-label": "Close", onClick: onClose, children: _jsx(CloseIcon, {}) })] }), _jsx("textarea", { ref: ta, placeholder: placeholder, "aria-required": required || undefined, value: draft, onChange: (e) => onDraft(e.target.value), onKeyDown: onTaKey }), _jsxs("div", { className: pick || onMark ? 'row' : 'row nodest', children: [onMark ? (_jsx("span", { className: "dest", children: _jsx("button", { type: "button", "aria-pressed": marked, onClick: onMark, children: "Mark on screen" }) })) : pick ? (_jsxs("span", { className: "dest", role: "group", "aria-label": "Where this snap lands", children: [_jsx("button", { type: "button", "aria-pressed": !task, onClick: () => setTask(false), children: "board" }), _jsx("button", { type: "button", "aria-pressed": task, onClick: () => setTask(true), children: "task" })] })) : null, _jsx("span", { className: "ctx", children: ctx }), _jsxs("button", { type: "button", className: "
|
|
167
|
+
return (_jsxs("div", { ref: pop, className: `pop compose ${className}${dropping ? ' dropping' : ''}`, style: { transformOrigin: origin, ...size.style }, role: "dialog", "aria-labelledby": "vt-pop-title", onKeyDown: onKey, ...(onImages ? { onDragEnter: onDragOver, onDragOver, onDragLeave, onDrop } : {}), children: [_jsxs("div", { className: "pop-head", children: [_jsxs("span", { className: "title", children: [_jsx("i", {}), _jsx("span", { id: "vt-pop-title", children: title })] }), _jsx("button", { type: "button", className: "closeb", "aria-label": "Close", onClick: onClose, children: _jsx(CloseIcon, {}) })] }), _jsx("textarea", { ref: ta, placeholder: placeholder, "aria-required": required || undefined, value: draft, onChange: (e) => onDraft(e.target.value), onKeyDown: onTaKey, ...(onImages ? { onPaste } : {}) }), images && (images.length > 0 || busy > 0) ? (_jsxs("ul", { className: "atts", "aria-label": "Attached images", children: [images.map((image) => (_jsx(Thumb, { image: image, onRemove: () => remove(image) }, keyOf(image)))), Array.from({ length: busy }, (_, i) => (_jsx("li", { className: "att busy", "aria-label": "Preparing image", children: _jsx(SpinnerIcon, {}) }, `busy${i}`)))] })) : null, _jsxs("div", { className: pick || onMark ? 'row' : 'row nodest', children: [onMark ? (_jsx("span", { className: "dest", children: _jsx("button", { type: "button", "aria-pressed": marked, onClick: onMark, children: "Mark on screen" }) })) : pick ? (_jsxs("span", { className: "dest", role: "group", "aria-label": "Where this snap lands", children: [_jsx("button", { type: "button", "aria-pressed": !task, onClick: () => setTask(false), children: "board" }), _jsx("button", { type: "button", "aria-pressed": task, onClick: () => setTask(true), children: "task" })] })) : null, refusal ? (_jsx("span", { className: "ctx bad", title: refusal, children: refusal })) : (_jsx("span", { className: "ctx", children: ctx })), onImages ? (_jsxs("span", { className: "acts", children: [_jsx("button", { type: "button", className: "clipb", "aria-label": "Attach image", "aria-disabled": full || undefined, onClick: browse, children: _jsx(PaperclipIcon, {}) }), _jsx("input", { ref: file, type: "file", accept: "image/*", multiple: true, hidden: true, onChange: (e) => {
|
|
168
|
+
attach(Array.from(e.currentTarget.files ?? []));
|
|
169
|
+
// The same file picked again is a change too.
|
|
170
|
+
e.currentTarget.value = '';
|
|
171
|
+
} }), sendb] })) : (sendb)] }), onImages ? (_jsx("span", { className: "sr", role: "status", children: refusal })) : null, _jsx("div", { className: "hints", children: "\u21A9 send \u00B7 \u21E7\u21A9 newline \u00B7 esc cancel" }), size.grip ? (_jsx("button", { type: "button", className: "grip", "data-corner": size.grip.corner, "aria-label": `Resize ${kind}`, ...size.grip.handlers, children: _jsx(GripIcon, {}) })) : null] }));
|
|
46
172
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One picked, pasted or dropped file → a `HudAttachment` a controller ships
|
|
3
|
+
* as-is (recorder attachments). The image is decoded (an animated input keeps
|
|
4
|
+
* its first frame), drawn at a long edge ≤ 2560 px and re-encoded, so its
|
|
5
|
+
* EXIF/GPS never leave the device: WebP at 0.85; where the browser cannot
|
|
6
|
+
* encode WebP (it hands back another type) JPEG at 0.85, or PNG when the
|
|
7
|
+
* image has transparency JPEG would lose. Over 12 MiB (the `/shot` cap) it
|
|
8
|
+
* steps down until it fits. A file that is not an image is refused with a
|
|
9
|
+
* reason the sheet shows verbatim.
|
|
10
|
+
*/
|
|
11
|
+
import type { HudAttachment } from './controller';
|
|
12
|
+
/** Images one note carries from the HUD (the server takes at most 10). */
|
|
13
|
+
export declare const MAX_ATTACHMENTS = 4;
|
|
14
|
+
export declare const MAX_EDGE = 2560;
|
|
15
|
+
/** The `/shot` upload cap. */
|
|
16
|
+
export declare const MAX_ATTACHMENT_BYTES: number;
|
|
17
|
+
/** Test-only: forget what the first encode learned about WebP. */
|
|
18
|
+
export declare function __resetEncoderForTests(): void;
|
|
19
|
+
/** The name a pasted image carries: the clipboard's generic one becomes "pasted image.<ext>". */
|
|
20
|
+
export declare function pastedName(file: File): string;
|
|
21
|
+
/**
|
|
22
|
+
* Normalize one file for a note. Rejects with an `Error` whose message leads
|
|
23
|
+
* with the reason (not an image, unreadable, too large), then the file — the
|
|
24
|
+
* sheet ellipsizes a long name, never the reason.
|
|
25
|
+
*/
|
|
26
|
+
export declare function normalizeAttachment(file: Blob, name: string): Promise<HudAttachment>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/** Images one note carries from the HUD (the server takes at most 10). */
|
|
2
|
+
export const MAX_ATTACHMENTS = 4;
|
|
3
|
+
export const MAX_EDGE = 2560;
|
|
4
|
+
/** The `/shot` upload cap. */
|
|
5
|
+
export const MAX_ATTACHMENT_BYTES = 12 * 1024 * 1024;
|
|
6
|
+
const QUALITY = 0.85;
|
|
7
|
+
/** Step-downs before an image counts as too large. */
|
|
8
|
+
const MAX_TRIES = 8;
|
|
9
|
+
/** null until the first encode says whether this browser writes WebP. */
|
|
10
|
+
let webp = null;
|
|
11
|
+
/** Test-only: forget what the first encode learned about WebP. */
|
|
12
|
+
export function __resetEncoderForTests() {
|
|
13
|
+
webp = null;
|
|
14
|
+
}
|
|
15
|
+
/** The name a pasted image carries: the clipboard's generic one becomes "pasted image.<ext>". */
|
|
16
|
+
export function pastedName(file) {
|
|
17
|
+
if (file.name && !/^(image|untitled)\.\w+$/i.test(file.name))
|
|
18
|
+
return file.name;
|
|
19
|
+
const ext = file.type.startsWith('image/') ? file.type.slice(6).replace('jpeg', 'jpg').replace(/\+.*$/, '') : 'png';
|
|
20
|
+
return `pasted image.${ext || 'png'}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Normalize one file for a note. Rejects with an `Error` whose message leads
|
|
24
|
+
* with the reason (not an image, unreadable, too large), then the file — the
|
|
25
|
+
* sheet ellipsizes a long name, never the reason.
|
|
26
|
+
*/
|
|
27
|
+
export async function normalizeAttachment(file, name) {
|
|
28
|
+
if (file.type && !file.type.startsWith('image/'))
|
|
29
|
+
throw new Error(`Not an image: ${name}`);
|
|
30
|
+
let img;
|
|
31
|
+
try {
|
|
32
|
+
img = await decode(file);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
console.warn('vitrinka: attachment decode failed —', e);
|
|
36
|
+
throw new Error(`Unreadable image: ${name}`);
|
|
37
|
+
}
|
|
38
|
+
let out;
|
|
39
|
+
try {
|
|
40
|
+
out = await encode(img, name, mayHaveAlpha(file.type));
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
// A canvas the browser refuses to read back (a tainted SVG) or encode.
|
|
44
|
+
console.warn('vitrinka: attachment encode failed —', e);
|
|
45
|
+
throw new Error(`Could not convert: ${name}`);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
img.close();
|
|
49
|
+
}
|
|
50
|
+
if (!out)
|
|
51
|
+
throw new Error(`Too large to attach: ${name}`);
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/** JPEG never carries transparency; anything else may. */
|
|
55
|
+
function mayHaveAlpha(type) {
|
|
56
|
+
return type !== 'image/jpeg' && type !== 'image/jpg';
|
|
57
|
+
}
|
|
58
|
+
/** The re-encoded image, or null when even the last step-down is over the cap. */
|
|
59
|
+
async function encode(img, name, alphaInput) {
|
|
60
|
+
let scale = Math.min(1, MAX_EDGE / Math.max(img.w, img.h));
|
|
61
|
+
let alpha = null;
|
|
62
|
+
for (let tries = 0; tries < MAX_TRIES; tries++) {
|
|
63
|
+
const w = Math.max(1, Math.round(img.w * scale));
|
|
64
|
+
const h = Math.max(1, Math.round(img.h * scale));
|
|
65
|
+
const s = surface(w, h);
|
|
66
|
+
s.paint.drawImage(img.source, 0, 0, w, h);
|
|
67
|
+
let blob = webp === false ? null : await s.encode('image/webp', QUALITY);
|
|
68
|
+
if (blob && webp === null)
|
|
69
|
+
webp = blob.type === 'image/webp';
|
|
70
|
+
if (!blob || blob.type !== 'image/webp') {
|
|
71
|
+
alpha ??= alphaInput && hasAlpha(s.paint, w, h);
|
|
72
|
+
blob = alpha ? await s.encode('image/png') : await s.encode('image/jpeg', QUALITY);
|
|
73
|
+
}
|
|
74
|
+
if (!blob)
|
|
75
|
+
throw new Error('the canvas encoded nothing');
|
|
76
|
+
if (blob.size <= MAX_ATTACHMENT_BYTES)
|
|
77
|
+
return { name, blob, w, h };
|
|
78
|
+
// Bytes scale with the area: aim just under the cap, never less than half the edge a step.
|
|
79
|
+
scale *= Math.min(0.9, Math.max(0.5, Math.sqrt(MAX_ATTACHMENT_BYTES / blob.size) * 0.95));
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
/** Any pixel not fully opaque. */
|
|
84
|
+
function hasAlpha(paint, w, h) {
|
|
85
|
+
const data = paint.getImageData(0, 0, w, h).data;
|
|
86
|
+
for (let i = 3; i < data.length; i += 4)
|
|
87
|
+
if ((data[i] ?? 255) < 255)
|
|
88
|
+
return true;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
/** An OffscreenCanvas where there is one, else a detached `<canvas>`. */
|
|
92
|
+
function surface(w, h) {
|
|
93
|
+
if (typeof OffscreenCanvas === 'function') {
|
|
94
|
+
const c = new OffscreenCanvas(w, h);
|
|
95
|
+
const paint = c.getContext('2d');
|
|
96
|
+
if (!paint)
|
|
97
|
+
throw new Error('no 2d canvas');
|
|
98
|
+
return { paint, encode: (type, quality) => c.convertToBlob({ type, ...(quality === undefined ? {} : { quality }) }) };
|
|
99
|
+
}
|
|
100
|
+
const c = document.createElement('canvas');
|
|
101
|
+
c.width = w;
|
|
102
|
+
c.height = h;
|
|
103
|
+
const paint = c.getContext('2d');
|
|
104
|
+
if (!paint)
|
|
105
|
+
throw new Error('no 2d canvas');
|
|
106
|
+
return { paint, encode: (type, quality) => new Promise((resolve) => c.toBlob(resolve, type, quality)) };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Decode upright (EXIF orientation applied, so the re-encode that drops the
|
|
110
|
+
* tag keeps the picture the right way up). `createImageBitmap` takes most
|
|
111
|
+
* types; an SVG decodes only through an `<img>`.
|
|
112
|
+
*/
|
|
113
|
+
async function decode(file) {
|
|
114
|
+
if (typeof createImageBitmap === 'function') {
|
|
115
|
+
try {
|
|
116
|
+
const bmp = await createImageBitmap(file, { imageOrientation: 'from-image' });
|
|
117
|
+
return { source: bmp, w: bmp.width, h: bmp.height, close: () => bmp.close() };
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// fall through to <img>
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const url = URL.createObjectURL(file);
|
|
124
|
+
try {
|
|
125
|
+
const el = new Image();
|
|
126
|
+
el.src = url;
|
|
127
|
+
await el.decode();
|
|
128
|
+
if (!el.naturalWidth || !el.naturalHeight)
|
|
129
|
+
throw new Error('no intrinsic size');
|
|
130
|
+
return { source: el, w: el.naturalWidth, h: el.naturalHeight, close: () => URL.revokeObjectURL(url) };
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
URL.revokeObjectURL(url);
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -19,6 +19,10 @@ export interface HudPrefs {
|
|
|
19
19
|
size: HudSize;
|
|
20
20
|
/** Technical details (events, queue, last sync, session id, version). */
|
|
21
21
|
verbose: boolean;
|
|
22
|
+
/** The note / annotate / report sheet's width, CSS px; 0 = the HUD's default. */
|
|
23
|
+
sheetW: number;
|
|
24
|
+
/** The cap its text box grows to before it scrolls, CSS px; 0 = the HUD's default (20 rows). */
|
|
25
|
+
sheetH: number;
|
|
22
26
|
}
|
|
23
27
|
/** Who the recorder token belongs to (`GET /api/v1/recorder/me`). */
|
|
24
28
|
export interface HudAccount {
|
|
@@ -40,7 +44,7 @@ export type HudSyncState = 'ok' | 'backlog' | 'offline' | 'dead';
|
|
|
40
44
|
export interface HudSync {
|
|
41
45
|
state: HudSyncState;
|
|
42
46
|
synced: boolean;
|
|
43
|
-
/** Items (events + rrweb chunks) not yet delivered. */
|
|
47
|
+
/** Items (events + rrweb chunks + attached images) not yet delivered. */
|
|
44
48
|
queued: number;
|
|
45
49
|
/** Of those, rrweb chunks. */
|
|
46
50
|
chunks: number;
|
|
@@ -99,6 +103,22 @@ export interface HudSnapshot {
|
|
|
99
103
|
* session, or, idle, with the last minute the host keeps. Absent = never.
|
|
100
104
|
*/
|
|
101
105
|
canReport?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The sheets take images (paperclip, paste, drop) — the server answered
|
|
108
|
+
* `attachments: true` to the policy read. Absent or false = text only.
|
|
109
|
+
*/
|
|
110
|
+
canAttach?: boolean;
|
|
111
|
+
}
|
|
112
|
+
/** One image a tester attached, already normalized by the HUD:
|
|
113
|
+
* re-encoded (EXIF/GPS gone), long edge ≤ 2560 px, ≤ 12 MiB. */
|
|
114
|
+
export interface HudAttachment {
|
|
115
|
+
/** The original file name ("pasted image.png" for a paste). */
|
|
116
|
+
name: string;
|
|
117
|
+
/** image/webp, image/jpeg or image/png — what /shot accepts. */
|
|
118
|
+
blob: Blob;
|
|
119
|
+
/** Pixel size after normalizing. */
|
|
120
|
+
w: number;
|
|
121
|
+
h: number;
|
|
102
122
|
}
|
|
103
123
|
/** The code half of a device link, as the link sheet paints it. */
|
|
104
124
|
export interface HudLinkCode {
|
|
@@ -126,6 +146,7 @@ export interface HudAnnotation {
|
|
|
126
146
|
selector: string;
|
|
127
147
|
/** Also file it as an intake task. */
|
|
128
148
|
task: boolean;
|
|
149
|
+
attachments?: readonly HudAttachment[];
|
|
129
150
|
}
|
|
130
151
|
/** What "Report a bug" sends from the sheet. */
|
|
131
152
|
export interface HudReport {
|
|
@@ -135,6 +156,7 @@ export interface HudReport {
|
|
|
135
156
|
rect: HudRect | null;
|
|
136
157
|
/** The marked element's selector; '' for a region or no mark. */
|
|
137
158
|
selector: string;
|
|
159
|
+
attachments?: readonly HudAttachment[];
|
|
138
160
|
}
|
|
139
161
|
/**
|
|
140
162
|
* What a stop or an idle report saved. `boardUrl` when the board already
|
|
@@ -154,14 +176,20 @@ export interface HudController {
|
|
|
154
176
|
togglePause(): Promise<void>;
|
|
155
177
|
/** Drains, then closes the session; rejects (session kept) while unreachable. */
|
|
156
178
|
stop(): Promise<HudSaved>;
|
|
157
|
-
|
|
179
|
+
/** `attachments` only when `canAttach`; with them, `text` may be empty. */
|
|
180
|
+
note(text: string, attachments?: readonly HudAttachment[]): void;
|
|
158
181
|
annotate(a: HudAnnotation): void;
|
|
159
182
|
setAnnotating(active: boolean): void;
|
|
160
183
|
link(): Promise<HudLinkFlow>;
|
|
161
184
|
unlink(): void;
|
|
162
185
|
/** Refresh `account` (and server prefs); null when unknown. Never rejects. */
|
|
163
186
|
getMe(): Promise<HudAccount | null>;
|
|
164
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Apply locally at once, then persist where the server keeps prefs. Never
|
|
189
|
+
* rejects. The sheet size (`sheetW`/`sheetH`, one call per resize) goes in
|
|
190
|
+
* its own PATCH: a server that predates it answers 422, and the size then
|
|
191
|
+
* stays on the device without costing size/verbose their server copy.
|
|
192
|
+
*/
|
|
165
193
|
setPrefs(patch: Partial<HudPrefs>): Promise<void>;
|
|
166
194
|
/** Fill missing board links of recents from the server. Never rejects. */
|
|
167
195
|
refreshRecents(): Promise<void>;
|
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
* server is unreachable, a failed start). A link flow's `linked` rejects
|
|
15
15
|
* with an error NAMED `LinkExpired` or `AbortError` for those two outcomes.
|
|
16
16
|
*/
|
|
17
|
-
export const DEFAULT_PREFS = { size: 'md', verbose: false };
|
|
17
|
+
export const DEFAULT_PREFS = { size: 'md', verbose: false, sheetW: 0, sheetH: 0 };
|
|
@@ -18,6 +18,8 @@ const SHIELDED = [
|
|
|
18
18
|
'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'click', 'dblclick', 'auxclick',
|
|
19
19
|
'contextmenu', 'touchstart', 'touchend', 'touchmove', 'touchcancel', 'wheel',
|
|
20
20
|
'focusin', 'focusout', 'keydown', 'keyup', 'keypress',
|
|
21
|
+
// An image pasted or dropped onto a sheet is the HUD's, never the page's upload.
|
|
22
|
+
'paste', 'dragenter', 'dragover', 'dragleave', 'drop',
|
|
21
23
|
];
|
|
22
24
|
export function shield(el) {
|
|
23
25
|
for (const t of SHIELDED)
|
|
@@ -10,6 +10,9 @@ export declare function PencilIcon(): ReactElement;
|
|
|
10
10
|
export declare function AnnotateIcon(): ReactElement;
|
|
11
11
|
export declare function CloseIcon(): ReactElement;
|
|
12
12
|
export declare function ArrowUpIcon(): ReactElement;
|
|
13
|
+
export declare function PaperclipIcon(): ReactElement;
|
|
14
|
+
/** The sheet's resize grip, drawn for the bottom-right corner (CSS turns it to the others). */
|
|
15
|
+
export declare function GripIcon(): ReactElement;
|
|
13
16
|
export declare function MoreIcon(): ReactElement;
|
|
14
17
|
export declare function NewTabIcon(): ReactElement;
|
|
15
18
|
export declare function StopIcon(): ReactElement;
|
|
@@ -29,6 +29,13 @@ export function CloseIcon() {
|
|
|
29
29
|
export function ArrowUpIcon() {
|
|
30
30
|
return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "M12 19V5" }), _jsx("path", { d: "m5 12 7-7 7 7" })] }));
|
|
31
31
|
}
|
|
32
|
+
export function PaperclipIcon() {
|
|
33
|
+
return (_jsx("svg", { ...base, children: _jsx("path", { d: "m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48" }) }));
|
|
34
|
+
}
|
|
35
|
+
/** The sheet's resize grip, drawn for the bottom-right corner (CSS turns it to the others). */
|
|
36
|
+
export function GripIcon() {
|
|
37
|
+
return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "M20 9 9 20" }), _jsx("path", { d: "M20 15l-5 5" })] }));
|
|
38
|
+
}
|
|
32
39
|
export function MoreIcon() {
|
|
33
40
|
return (_jsxs("svg", { ...base, children: [_jsx("circle", { cx: "12", cy: "12", r: "1" }), _jsx("circle", { cx: "19", cy: "12", r: "1" }), _jsx("circle", { cx: "5", cy: "12", r: "1" })] }));
|
|
34
41
|
}
|
|
@@ -46,7 +46,8 @@ export declare function hostOrigin(mount: HTMLElement): {
|
|
|
46
46
|
* A popover anchored to the dock: toward the page centre (sideways from a
|
|
47
47
|
* vertical or tucked dock), flush with the dock's outer edge, flipped and
|
|
48
48
|
* shifted so the measured `size` never leaves the viewport; it grows from
|
|
49
|
-
* the point nearest the dock.
|
|
49
|
+
* the point nearest the dock. `side` is where it opened, `room` the tallest
|
|
50
|
+
* it may stand there without covering the dock or leaving the viewport.
|
|
50
51
|
*/
|
|
51
52
|
export declare function anchoredLayer(dock: Box, size: {
|
|
52
53
|
w: number;
|
|
@@ -57,6 +58,8 @@ export declare function anchoredLayer(dock: Box, size: {
|
|
|
57
58
|
}): {
|
|
58
59
|
style: CSSProperties;
|
|
59
60
|
origin: string;
|
|
61
|
+
side: FloatSide;
|
|
62
|
+
room: number;
|
|
60
63
|
};
|
|
61
64
|
/** A phone bottom sheet: the full visual viewport, content pinned to its bottom edge. */
|
|
62
65
|
export declare function phoneLayer(origin: {
|
|
@@ -97,11 +97,19 @@ export function hostOrigin(mount) {
|
|
|
97
97
|
* A popover anchored to the dock: toward the page centre (sideways from a
|
|
98
98
|
* vertical or tucked dock), flush with the dock's outer edge, flipped and
|
|
99
99
|
* shifted so the measured `size` never leaves the viewport; it grows from
|
|
100
|
-
* the point nearest the dock.
|
|
100
|
+
* the point nearest the dock. `side` is where it opened, `room` the tallest
|
|
101
|
+
* it may stand there without covering the dock or leaving the viewport.
|
|
101
102
|
*/
|
|
102
103
|
export function anchoredLayer(dock, size, place, origin) {
|
|
103
|
-
const
|
|
104
|
-
|
|
104
|
+
const gap = 8;
|
|
105
|
+
const margin = 8;
|
|
106
|
+
const p = placeFloating({ x: dock.left, y: dock.top, w: dock.right - dock.left, h: dock.bottom - dock.top }, size, { w: innerWidth, h: innerHeight }, towardCentre(place), { align: alignFor(place), gap, margin });
|
|
107
|
+
const room = p.side === 'top'
|
|
108
|
+
? dock.top - gap - margin
|
|
109
|
+
: p.side === 'bottom'
|
|
110
|
+
? innerHeight - dock.bottom - gap - margin
|
|
111
|
+
: innerHeight - 2 * margin;
|
|
112
|
+
return { style: { left: p.x - origin.x, top: p.y - origin.y }, origin: p.origin, side: p.side, room };
|
|
105
113
|
}
|
|
106
114
|
/** A phone bottom sheet: the full visual viewport, content pinned to its bottom edge. */
|
|
107
115
|
export function phoneLayer(origin) {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The composer sheet's size — HUD prefs `sheetW` (its width) and `sheetH`
|
|
3
|
+
* (the cap its text box grows to with the draft before it scrolls), CSS px,
|
|
4
|
+
* 0 = the HUD's default: `SHEET_W` at every HUD size, `SHEET_ROWS` rows.
|
|
5
|
+
*
|
|
6
|
+
* A grip on the corner facing away from the dock (`gripFor`) resizes both: a
|
|
7
|
+
* pointer drag (captured) live, reporting ONCE on release; arrow keys move
|
|
8
|
+
* that corner 16 px (⇧ 64) and report on key-up; Enter or a double-click
|
|
9
|
+
* resets both to the default. While a vertical resize is in progress the text
|
|
10
|
+
* box stands at the cap it sets, so the hand sees it; once it ends the text box
|
|
11
|
+
* fits its draft again, up to that cap. An axis a drag barely moved keeps its
|
|
12
|
+
* pref, so widening never pins the cap to today's draft. A phone's bottom
|
|
13
|
+
* sheet spans the viewport, so its grip sizes the cap alone. The sheet never
|
|
14
|
+
* outgrows the `room` it has beside the dock: past the cap, or past that
|
|
15
|
+
* room, the text box scrolls.
|
|
16
|
+
*/
|
|
17
|
+
import { type CSSProperties, type KeyboardEvent, type MouseEvent, type PointerEvent, type RefObject } from 'react';
|
|
18
|
+
import type { FloatAlign, FloatSide } from './place';
|
|
19
|
+
/** The default width, CSS px, at every HUD size (styles.ts `.pop.compose`). */
|
|
20
|
+
export declare const SHEET_W = 440;
|
|
21
|
+
export declare const SHEET_MIN_W = 320;
|
|
22
|
+
export declare const SHEET_MAX_W = 960;
|
|
23
|
+
/** The default cap: this many text rows. */
|
|
24
|
+
export declare const SHEET_ROWS = 20;
|
|
25
|
+
export type GripCorner = 'tl' | 'tr' | 'bl' | 'br';
|
|
26
|
+
export interface Grip {
|
|
27
|
+
corner: GripCorner;
|
|
28
|
+
/** 2 where the sheet is centred on the dock along that axis: it grows both ways, the corner travels half. */
|
|
29
|
+
spanX: 1 | 2;
|
|
30
|
+
spanY: 1 | 2;
|
|
31
|
+
/** What it sizes: the width and the cap, or the cap alone (a phone's full-width bottom sheet). */
|
|
32
|
+
axes: 'xy' | 'y';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The free corner of a sheet opened on `side` of the dock, aligned `align`
|
|
36
|
+
* (place.ts): away from the dock on both axes. Beside a vertical dock it is
|
|
37
|
+
* the bottom one; above or below a centred dock, the one clear of the ✕. A
|
|
38
|
+
* phone's bottom sheet opens on `top` with `axes` 'y': a top corner, away
|
|
39
|
+
* from the pill's column.
|
|
40
|
+
*/
|
|
41
|
+
export declare function gripFor(side: FloatSide, align: FloatAlign, axes?: Grip['axes']): Grip;
|
|
42
|
+
/** A width in [SHEET_MIN_W, SHEET_MAX_W] that leaves the viewport its sides (a narrow viewport wins). */
|
|
43
|
+
export declare function clampSheetW(w: number, viewW: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* Size the text box to its draft: from its CSS min-height (at least `floor`)
|
|
46
|
+
* up to `cap` (0 = `SHEET_ROWS` rows) within the sheet's `room`; past that it
|
|
47
|
+
* scrolls. Its scroll position survives the measuring.
|
|
48
|
+
*/
|
|
49
|
+
export declare function fitText(el: HTMLTextAreaElement, sheet: HTMLElement, cap: number, floor: number, room: number): void;
|
|
50
|
+
export interface SheetSizeOptions {
|
|
51
|
+
sheet: RefObject<HTMLElement | null>;
|
|
52
|
+
text: RefObject<HTMLTextAreaElement | null>;
|
|
53
|
+
/** The prefs, CSS px; 0 = the default. */
|
|
54
|
+
width: number;
|
|
55
|
+
cap: number;
|
|
56
|
+
/** The tallest the sheet may stand where it opens (viewport px); 0 = the viewport. */
|
|
57
|
+
room: number;
|
|
58
|
+
/** Where the grip sits and what it sizes; null = none. */
|
|
59
|
+
grip: Grip | null;
|
|
60
|
+
/** A resize ended: the new prefs (0, 0 = the default). */
|
|
61
|
+
onResize?: ((sheetW: number, sheetH: number) => void) | undefined;
|
|
62
|
+
/** The sheet's box changed size — place it again before it paints. */
|
|
63
|
+
onLayout?: (() => void) | undefined;
|
|
64
|
+
}
|
|
65
|
+
/** The sheet's width style, its text box fitted on every commit, and the grip's handlers. */
|
|
66
|
+
export declare function useSheetSize(o: SheetSizeOptions): {
|
|
67
|
+
style: CSSProperties | undefined;
|
|
68
|
+
grip: {
|
|
69
|
+
corner: GripCorner;
|
|
70
|
+
handlers: {
|
|
71
|
+
onPointerDown: (e: PointerEvent<HTMLButtonElement>) => void;
|
|
72
|
+
onPointerMove: (e: PointerEvent<HTMLButtonElement>) => void;
|
|
73
|
+
onPointerUp: (e: PointerEvent<HTMLButtonElement>) => void;
|
|
74
|
+
onPointerCancel: (e: PointerEvent<HTMLButtonElement>) => void;
|
|
75
|
+
onLostPointerCapture: (e: PointerEvent<HTMLButtonElement>) => void;
|
|
76
|
+
onMouseDown: (e: MouseEvent<HTMLButtonElement>) => void;
|
|
77
|
+
onDoubleClick: () => void;
|
|
78
|
+
onKeyDown: (e: KeyboardEvent<HTMLButtonElement>) => void;
|
|
79
|
+
onKeyUp: (e: KeyboardEvent<HTMLButtonElement>) => void;
|
|
80
|
+
onBlur: () => void;
|
|
81
|
+
};
|
|
82
|
+
} | null;
|
|
83
|
+
};
|