clavarium-parley 0.12.0 → 0.13.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/README.md +4 -0
- package/docs/protocol.md +5 -2
- package/host/parley-host.mjs +5 -3
- package/package.json +1 -1
- package/server/parley-mcp.mjs +2 -2
- package/ui/parley-icons.js +5 -1
- package/ui/parley-ui.css +26 -0
- package/ui/parley-ui.js +161 -7
- package/ui/texts/en.json +9 -0
- package/ui/texts/fr.json +9 -0
package/README.md
CHANGED
|
@@ -36,6 +36,10 @@ posted and nothing printed; the screen says "Working…" while it beats, and
|
|
|
36
36
|
Claude Code's `Stop` hook asks it once, when it stops while its chat still says
|
|
37
37
|
it works, to say where it is.
|
|
38
38
|
|
|
39
|
+
A picture the person attaches can be drawn on before it is sent (a tap on it,
|
|
40
|
+
then a finger or the mouse), with a note about it alone: the agent receives
|
|
41
|
+
the picture as drawn (`photo-annotated.png`) and the note under its path.
|
|
42
|
+
|
|
39
43
|
Nothing waits: the agent posts, and is told in one line when a message
|
|
40
44
|
arrived. See [docs/protocol.md](docs/protocol.md).
|
|
41
45
|
|
package/docs/protocol.md
CHANGED
|
@@ -96,8 +96,11 @@ message proposes; several proposals: ask which), `disagree` (ask what is
|
|
|
96
96
|
wrong), `unclear` (explain more simply, without acting), `stop` (stop now,
|
|
97
97
|
do nothing more), `redo` (another way), `later` (nothing for now), `love`
|
|
98
98
|
(noted). An application may offer another set: an unknown one is given by
|
|
99
|
-
its name. When the person attached files: `files`, `[{path, name, size}]`, ten at most,
|
|
100
|
-
`path` as the agent sees it; the text may then be empty.
|
|
99
|
+
its name. When the person attached files: `files`, `[{path, name, size, note?}]`, ten at most,
|
|
100
|
+
`path` as the agent sees it; the text may then be empty. `note`: what the
|
|
101
|
+
person wrote about that file alone (500 characters, one line); a picture
|
|
102
|
+
they drew on before sending comes as they drew it, and its name says so
|
|
103
|
+
(`photo-annotated.png`). Where the files are
|
|
101
104
|
put is the application's business: it puts them where the agent can open
|
|
102
105
|
them, and gives Parley their paths. `parley read` gives each path.
|
|
103
106
|
|
package/host/parley-host.mjs
CHANGED
|
@@ -49,6 +49,8 @@ export const FILE_MAX = 2 * 1024 * 1024;
|
|
|
49
49
|
export const STATES = ['working', 'waiting', 'done'];
|
|
50
50
|
/* Files the person attaches to one message, at most. */
|
|
51
51
|
export const FILES_MAX = 10;
|
|
52
|
+
/* What the person wrote about one file they attached. */
|
|
53
|
+
export const NOTE_MAX = 500;
|
|
52
54
|
/* Files the agent shows at once, as one gallery. */
|
|
53
55
|
export const SHOW_MAX = 12;
|
|
54
56
|
/* THE REACTIONS a person may put on a message of the agent, by default: an
|
|
@@ -222,7 +224,7 @@ export class Parley {
|
|
|
222
224
|
return list.slice(0, FILES_MAX).filter((f) => f && typeof f === 'object').map((f) => {
|
|
223
225
|
const path = oneLine(f.path, 1000);
|
|
224
226
|
const open = this.#open(path);
|
|
225
|
-
return { path, name: oneLine(f.name, 200) || path.split('/').pop(), size: Number.isInteger(f.size) && f.size >= 0 ? f.size : null, open };
|
|
227
|
+
return { path, name: oneLine(f.name, 200) || path.split('/').pop(), size: Number.isInteger(f.size) && f.size >= 0 ? f.size : null, open, ...(oneLine(f.note, NOTE_MAX) ? { note: oneLine(f.note, NOTE_MAX) } : {}) };
|
|
226
228
|
});
|
|
227
229
|
}
|
|
228
230
|
|
|
@@ -290,12 +292,12 @@ export class Parley {
|
|
|
290
292
|
const said = clean(text).trim();
|
|
291
293
|
const given = Array.isArray(files) ? files : [];
|
|
292
294
|
if (given.length > FILES_MAX) throw new RangeError(`${FILES_MAX} files at most in one message.`);
|
|
293
|
-
const attached = given.map((f) => ({ path: oneLine(f?.path, 1000), name: oneLine(f?.name, 200), size: Number.isInteger(f?.size) && f.size >= 0 ? f.size : undefined }));
|
|
295
|
+
const attached = given.map((f) => ({ path: oneLine(f?.path, 1000), name: oneLine(f?.name, 200), size: Number.isInteger(f?.size) && f.size >= 0 ? f.size : undefined, note: oneLine(f?.note, NOTE_MAX) }));
|
|
294
296
|
if (attached.some((f) => !f.path.startsWith('/'))) throw new RangeError('A file is given by its whole path.');
|
|
295
297
|
if (!said && attached.length === 0) throw new RangeError('Write something.');
|
|
296
298
|
const entry = { id: randomUUID(), at: this.#now().toISOString(), text: said };
|
|
297
299
|
if (via === 'voice') entry.via = 'voice';
|
|
298
|
-
if (attached.length) entry.files = attached.map((f) => ({ path: f.path, name: f.name || f.path.split('/').pop(), ...(f.size === undefined ? {} : { size: f.size }) }));
|
|
300
|
+
if (attached.length) entry.files = attached.map((f) => ({ path: f.path, name: f.name || f.path.split('/').pop(), ...(f.size === undefined ? {} : { size: f.size }), ...(f.note ? { note: f.note } : {}) }));
|
|
299
301
|
if (typeof answers === 'string' && answers) {
|
|
300
302
|
const asked = this.read().messages.find((m) => m.from === 'agent' && ['say', 'ask', 'show'].includes(m.kind) && m.id === answers);
|
|
301
303
|
/* A question is answered; any other message of the agent is replied to, quoted. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium-parley",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A bridge between a command-line agent and a screen of its own: a command and an MCP server of five verbs, and a small library that shows the exchange.",
|
package/server/parley-mcp.mjs
CHANGED
|
@@ -33,7 +33,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
33
33
|
import { randomUUID } from 'node:crypto';
|
|
34
34
|
import { createInterface } from 'node:readline';
|
|
35
35
|
|
|
36
|
-
export const VERSION = '0.
|
|
36
|
+
export const VERSION = '0.13.0';
|
|
37
37
|
/* A message may be long: the screen folds it, and shows its short version first. */
|
|
38
38
|
export const TEXT_MAX = 16000;
|
|
39
39
|
/* Its short version: a title of one or two lines. */
|
|
@@ -61,7 +61,7 @@ export const ALL_CHARS = 100_000;
|
|
|
61
61
|
const lines = (file) => { try { return readFileSync(file, 'utf8').split('\n').filter(Boolean).map((l) => { try { const j = JSON.parse(l); return j && typeof j === 'object' && !Array.isArray(j) ? j : null; } catch { return null; } }); } catch { return []; } };
|
|
62
62
|
const size = (n) => (n >= 1048576 ? `${(n / 1048576).toFixed(1)} MB` : n >= 1024 ? `${Math.round(n / 1024)} KB` : `${n} bytes`);
|
|
63
63
|
/* The files the person attached to a message, one line each: where they are, for the agent to open. */
|
|
64
|
-
const attached = (m) => (Array.isArray(m.files) ? m.files.slice(0, 10).map((f) => `\n Attached file: ${plain(f?.path, 1000)}${Number.isInteger(f?.size) ? ` (${size(f.size)})` : ''}`).join('') : '');
|
|
64
|
+
const attached = (m) => (Array.isArray(m.files) ? m.files.slice(0, 10).map((f) => `\n Attached file: ${plain(f?.path, 1000)}${Number.isInteger(f?.size) ? ` (${size(f.size)})` : ''}${f?.note ? `\n Their note on this file: ${plain(f.note, 500).replace(/\s+/g, ' ')}` : ''}`).join('') : '');
|
|
65
65
|
/* The short version of a message, when given: one or two lines. */
|
|
66
66
|
/* A message the person dictated: said so, for the words a recognizer got wrong. */
|
|
67
67
|
export const DICTATED = 'dictated: may hold recognition mistakes; ask when a key word seems wrong';
|
package/ui/parley-icons.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* where it had none ("3.676.56" is "3.676 .56"): the same drawing.
|
|
12
12
|
*
|
|
13
13
|
* Lucide's licence (ISC), and the MIT licence of the Feather icons some of
|
|
14
|
-
* them derive from (arrow-up, arrow-down, chevron-left, chevron-right, plus,
|
|
14
|
+
* them derive from (arrow-up, arrow-down, check, chevron-left, chevron-right, plus,
|
|
15
15
|
* smartphone, x), as the package gives them:
|
|
16
16
|
*
|
|
17
17
|
* ISC License. Copyright (c) 2026 Lucide Icons and Contributors.
|
|
@@ -82,6 +82,10 @@ export const ICONS = Object.freeze({
|
|
|
82
82
|
'arrow-up': [['path',{d:'m5 12 7-7 7 7'}],['path',{d:'M12 19V5'}]],
|
|
83
83
|
'arrow-down': [['path',{d:'M12 5v14'}],['path',{d:'m19 12-7 7-7-7'}]],
|
|
84
84
|
'plus': [['path',{d:'M5 12h14'}],['path',{d:'M12 5v14'}]],
|
|
85
|
+
'pencil': [['path',{d:'M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5 .83l-1.321 4.352a.5 .5 0 0 0 .623 .622l4.353-1.32a2 2 0 0 0 .83-.497z'}],['path',{d:'m15 5 4 4'}]],
|
|
86
|
+
'undo-2': [['path',{d:'M9 14 4 9l5-5'}],['path',{d:'M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11'}]],
|
|
87
|
+
'eraser': [['path',{d:'M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21'}],['path',{d:'m5.082 11.09 8.828 8.828'}]],
|
|
88
|
+
'check': [['path',{d:'M20 6 9 17l-5-5'}]],
|
|
85
89
|
});
|
|
86
90
|
|
|
87
91
|
/* The kinds of files, by extension, and the icon of each. */
|
package/ui/parley-ui.css
CHANGED
|
@@ -390,6 +390,32 @@ mark.parley-found[data-now="true"] { outline: 2px solid var(--parley-ask); }
|
|
|
390
390
|
.parley-zoom-word { display: inline; }
|
|
391
391
|
.parley .parley-zoom-bar .parley-zoom-close { margin-left: .9em; }
|
|
392
392
|
}
|
|
393
|
+
/* ---- drawing on a picture before it is sent ---- */
|
|
394
|
+
.parley-noted { margin: 0; display: flex; flex-direction: column; gap: .2em; max-width: 16em; }
|
|
395
|
+
.parley-file-note { font-size: .85em; color: var(--parley-dim); font-style: italic; overflow-wrap: anywhere; }
|
|
396
|
+
|
|
397
|
+
.parley-draw { background: #0d0f13; }
|
|
398
|
+
.parley-draw .parley-zoom-name { flex: 1 1 100%; text-align: center; }
|
|
399
|
+
.parley .parley-draw .parley-zoom-bar .parley-zoom-close { order: 0; }
|
|
400
|
+
.parley-draw-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: .4em; overflow: hidden; }
|
|
401
|
+
.parley-draw-canvas { display: block; touch-action: none; cursor: crosshair; background: #fff; box-shadow: 0 0 0 1px rgba(255, 255, 255, .2); }
|
|
402
|
+
.parley-draw-colours { display: inline-flex; gap: .3em; align-items: center; padding-inline: .3em; }
|
|
403
|
+
.parley .parley-zoom-bar .parley-draw-colour { min-width: 2em; min-height: 2em; width: 2em; height: 2em; padding: 0; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .5); }
|
|
404
|
+
.parley .parley-zoom-bar .parley-draw-colour[aria-checked="true"] { outline: 3px solid #f2f3f5; outline-offset: 2px; }
|
|
405
|
+
.parley-draw .parley-zoom-undo .parley-zoom-word, .parley-draw .parley-zoom-clear .parley-zoom-word { display: none; }
|
|
406
|
+
.parley-draw .parley-zoom-close .parley-zoom-word, .parley-draw .parley-zoom-done .parley-zoom-word { display: inline; }
|
|
407
|
+
.parley .parley-zoom-bar .parley-zoom-done { border-color: transparent; background: var(--parley-action); color: var(--parley-on-action); font-weight: 650; padding: 0 .9em 0 .6em; }
|
|
408
|
+
.parley .parley-zoom-bar button:disabled { opacity: .4; }
|
|
409
|
+
.parley-draw-foot { display: flex; flex-direction: column; gap: .3em; padding: .4em .6em calc(.5em + env(safe-area-inset-bottom)); background: rgba(0, 0, 0, .4); }
|
|
410
|
+
.parley-draw-hint { margin: 0; font-size: .8em; opacity: .75; text-align: center; }
|
|
411
|
+
.parley .parley-draw-note { width: 100%; max-width: 48rem; margin-inline: auto; box-sizing: border-box; resize: none; font: inherit; font-size: 16px; padding: .45em .6em; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .3); background: rgba(255, 255, 255, .08); color: #f2f3f5; }
|
|
412
|
+
@container parley (min-width: 46rem) {
|
|
413
|
+
.parley-draw .parley-zoom-name { flex: 0 1 auto; }
|
|
414
|
+
.parley-draw .parley-zoom-undo .parley-zoom-word, .parley-draw .parley-zoom-clear .parley-zoom-word { display: inline; }
|
|
415
|
+
}
|
|
416
|
+
.parley .parley-pending-open { display: block; position: relative; padding: 0; border: 0; background: none; cursor: zoom-in; min-height: 0; }
|
|
417
|
+
.parley-pending-marked { position: absolute; left: .2em; bottom: .2em; display: inline-flex; padding: .15em; border-radius: 6px; background: var(--parley-action); color: var(--parley-on-action); }
|
|
418
|
+
.parley-pending-marked .parley-sign { width: .9em; height: .9em; }
|
|
393
419
|
/* ---- the composer, in the same column ---- */
|
|
394
420
|
.parley-top, .parley-quick, .parley-attached, .parley-form, .parley-problem, .parley-replying { width: 100%; max-width: var(--parley-column); margin-inline: auto; box-sizing: border-box; }
|
|
395
421
|
.parley-replying { width: auto; margin-inline: 0; }
|
package/ui/parley-ui.js
CHANGED
|
@@ -173,7 +173,7 @@ export const VIEWS = Object.freeze(['simple', 'detailed']);
|
|
|
173
173
|
export const KEYS = Object.freeze(['send', 'placeholder', 'empty', 'view', 'simple', 'detailed', 'working', 'waiting', 'done', 'no-status', 'asks', 'open', 'outside',
|
|
174
174
|
'not-read', 'read', 'remind', 'reminded', 'steps', 'no-steps', 'files', 'no-files', 'terminal', 'not-sent', 'step-one', 'steps-many', 'today', 'yesterday', 'quiet', 'stopped',
|
|
175
175
|
'mic', 'mic-stop', 'auto-send', 'auto-on', 'settings', 'voice-placeholder', 'voice-calibrating', 'voice-listening', 'voice-hearing', 'voice-transcribing', 'voice-wait', 'voice-off', 'replies', 'replies-more', 'replies-less',
|
|
176
|
-
'attach', 'remove-file', 'sending-files', 'attach-where',
|
|
176
|
+
'attach', 'remove-file', 'sending-files', 'attach-where', 'draw-open', 'draw-marked', 'draw-colour', 'draw-undo', 'draw-clear', 'draw-cancel', 'draw-done', 'draw-note', 'draw-hint',
|
|
177
177
|
'copy', 'copied', 'see-details', 'see-more', 'see-less', 'note', 'tip', 'important', 'warning', 'caution', 'badge-ok', 'badge-todo', 'badge-blocked', 'badge-warn',
|
|
178
178
|
'waits-you', 'waits-you-note', 'busy', 'pulse', 'state-sent', 'state-read', 'state-working', 'state-done', 'sent-at', 'read-at', 'done-at',
|
|
179
179
|
'reply', 'replying', 'not-a-reply', 'in-reply', 'closed', 'you', 'agent', 'drop', 'picture', 'diagram', 'not-shown', 'grouped',
|
|
@@ -523,7 +523,7 @@ export function view(data, { words = {}, view: as = 'simple', now = Date.now(),
|
|
|
523
523
|
dictated: person && m.via === 'voice',
|
|
524
524
|
tool: detailed && !person && agentTool ? String(agentTool) : '',
|
|
525
525
|
/* What the person attached: by name, opened the application's way; its whole path in the detailed view. */
|
|
526
|
-
files: (person && Array.isArray(m.files) ? m.files : []).slice(0, FILES_MAX).filter((f) => f && typeof f === 'object').map((f) => ({ path: String(f.path ?? ''), name: String(f.name || nameOf(f.path)), open: typeof f.open === 'string' ? f.open : null, shown: detailed ? String(f.path ?? '') : '', size: sizeText(f.size), picture: PICTURE.test(String(f.name || f.path || '')) })),
|
|
526
|
+
files: (person && Array.isArray(m.files) ? m.files : []).slice(0, FILES_MAX).filter((f) => f && typeof f === 'object').map((f) => ({ path: String(f.path ?? ''), name: String(f.name || nameOf(f.path)), open: typeof f.open === 'string' ? f.open : null, shown: detailed ? String(f.path ?? '') : '', size: sizeText(f.size), picture: PICTURE.test(String(f.name || f.path || '')), ...(String(f.note ?? '').trim() ? { note: cut(String(f.note).replace(/\s+/g, ' ').trim(), 500) } : {}) })),
|
|
527
527
|
actions: [],
|
|
528
528
|
outside: show && !(Array.isArray(m.files) && m.files.length) && reach === null ? said(words, 'outside', { path: String(m.path ?? '') }) : show && Array.isArray(m.files) && m.files.some((f) => f && typeof f.open !== 'string') && detailed ? said(words, 'outside', { path: m.files.filter((f) => f && typeof f.open !== 'string').map((f) => f.path).join(', ') }) : '',
|
|
529
529
|
choices: m.kind === 'ask' && !answered.has(m.id) ? (m.choices ?? []).map(String) : [],
|
|
@@ -1186,6 +1186,135 @@ function zoomer(root, words, steps) {
|
|
|
1186
1186
|
};
|
|
1187
1187
|
}
|
|
1188
1188
|
|
|
1189
|
+
/* DRAWING ON A PICTURE before it is sent, and a note about it alone: what the person
|
|
1190
|
+
means ("this button", "here") is where they point. Lines are kept in the picture's own
|
|
1191
|
+
pixels, so they stay where they were drawn whatever the screen; sent as one picture. */
|
|
1192
|
+
/* The colours of the pen: seen on light and dark pictures alike. */
|
|
1193
|
+
export const PEN_COLOURS = Object.freeze(['#e53935', '#fdd835', '#1e88e5', '#43a047', '#ffffff', '#111111']);
|
|
1194
|
+
/* A picture drawn on is sent no larger than this on its longest side. */
|
|
1195
|
+
export const DRAWN_MAX_PX = 2048;
|
|
1196
|
+
/* How thick a line is, in the picture's pixels: seen on a large picture, not a blot on a small one. */
|
|
1197
|
+
export const penWidth = (w, h) => Math.max(3, Math.round(Math.max(w, h) / 150));
|
|
1198
|
+
/* The name it is sent under: what it was, and that it was drawn on. */
|
|
1199
|
+
export const drawnName = (name, type) => `${String(name ?? '').replace(/\.[A-Za-z0-9]{1,5}$/, '') || 'picture'}-annotated.${type === 'image/jpeg' ? 'jpg' : 'png'}`;
|
|
1200
|
+
/* The size it is drawn at: its own, made smaller only past the most. */
|
|
1201
|
+
export const drawnSize = (w, h, most = DRAWN_MAX_PX) => { const k = Math.min(1, most / Math.max(w, h, 1)); return { w: Math.max(1, Math.round(w * k)), h: Math.max(1, Math.round(h * k)) }; };
|
|
1202
|
+
function annotator(words, steps) {
|
|
1203
|
+
const box = el('div', 'parley-zoom parley-draw'); box.hidden = true; box.setAttribute('role', 'dialog'); box.setAttribute('aria-modal', 'true'); box.tabIndex = -1;
|
|
1204
|
+
const bar = el('div', 'parley-zoom-bar');
|
|
1205
|
+
const title = el('span', 'parley-zoom-name');
|
|
1206
|
+
const tool = (kind, key, name, act) => {
|
|
1207
|
+
const b = el('button', `parley-zoom-${kind}`); b.type = 'button'; b.title = said(words, key); b.setAttribute('aria-label', b.title);
|
|
1208
|
+
b.append(icon(name, 'parley-sign'), el('span', 'parley-zoom-word', said(words, key)));
|
|
1209
|
+
b.addEventListener('click', act); return b;
|
|
1210
|
+
};
|
|
1211
|
+
const stage = el('div', 'parley-draw-stage');
|
|
1212
|
+
const canvas = el('canvas', 'parley-draw-canvas');
|
|
1213
|
+
stage.append(canvas);
|
|
1214
|
+
const colours = el('div', 'parley-draw-colours'); colours.setAttribute('role', 'radiogroup'); colours.setAttribute('aria-label', said(words, 'draw-colour'));
|
|
1215
|
+
let colour = PEN_COLOURS[0];
|
|
1216
|
+
const swatches = PEN_COLOURS.map((c) => {
|
|
1217
|
+
const b = el('button', 'parley-draw-colour'); b.type = 'button'; b.style.backgroundColor = c; b.dataset.colour = c;
|
|
1218
|
+
b.setAttribute('role', 'radio'); b.setAttribute('aria-label', `${said(words, 'draw-colour')} ${c}`);
|
|
1219
|
+
b.addEventListener('click', () => { colour = c; paintSwatches(); });
|
|
1220
|
+
return b;
|
|
1221
|
+
});
|
|
1222
|
+
const paintSwatches = () => { for (const b of swatches) b.setAttribute('aria-checked', String(b.dataset.colour === colour)); };
|
|
1223
|
+
colours.append(...swatches); paintSwatches();
|
|
1224
|
+
const undo = tool('undo', 'draw-undo', 'undo-2', () => { strokes.pop(); paint(); });
|
|
1225
|
+
const clear = tool('clear', 'draw-clear', 'eraser', () => { strokes = []; paint(); });
|
|
1226
|
+
const cancel = tool('close', 'draw-cancel', 'x', () => close(null));
|
|
1227
|
+
const done = tool('done', 'draw-done', 'check', () => { void finish(); });
|
|
1228
|
+
bar.append(title, colours, undo, clear, cancel, done);
|
|
1229
|
+
const foot = el('div', 'parley-draw-foot');
|
|
1230
|
+
const note = el('textarea', 'parley-draw-note'); note.rows = 2; note.maxLength = 500; note.placeholder = said(words, 'draw-note'); note.setAttribute('aria-label', said(words, 'draw-note'));
|
|
1231
|
+
const hint = el('p', 'parley-draw-hint', said(words, 'draw-hint'));
|
|
1232
|
+
foot.append(hint, note);
|
|
1233
|
+
box.append(bar, stage, foot);
|
|
1234
|
+
const img = el('img');
|
|
1235
|
+
let strokes = []; let drawing = null; let file = null; let done2 = null; let back = null;
|
|
1236
|
+
const pen = () => penWidth(canvas.width, canvas.height);
|
|
1237
|
+
const line = (ctx, st) => {
|
|
1238
|
+
ctx.strokeStyle = st.colour; ctx.lineWidth = st.width; ctx.lineCap = 'round'; ctx.lineJoin = 'round';
|
|
1239
|
+
ctx.beginPath(); const [x0, y0] = st.points[0]; ctx.moveTo(x0, y0);
|
|
1240
|
+
if (st.points.length === 1) ctx.lineTo(x0 + 0.01, y0); else for (const [x, y] of st.points.slice(1)) ctx.lineTo(x, y);
|
|
1241
|
+
ctx.stroke();
|
|
1242
|
+
};
|
|
1243
|
+
function paint() {
|
|
1244
|
+
const ctx = canvas.getContext('2d'); if (!ctx) return;
|
|
1245
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
1246
|
+
for (const st of strokes) line(ctx, st);
|
|
1247
|
+
undo.disabled = clear.disabled = strokes.length === 0;
|
|
1248
|
+
}
|
|
1249
|
+
/* The canvas fills what room there is, keeping the picture's shape. */
|
|
1250
|
+
const fit = () => {
|
|
1251
|
+
const w = stage.clientWidth || 1; const h = stage.clientHeight || 1;
|
|
1252
|
+
const k = Math.min(w / canvas.width, h / canvas.height);
|
|
1253
|
+
canvas.style.width = `${Math.floor(canvas.width * k)}px`; canvas.style.height = `${Math.floor(canvas.height * k)}px`;
|
|
1254
|
+
};
|
|
1255
|
+
const at = (event) => { const r = canvas.getBoundingClientRect(); return [(event.clientX - r.left) * (canvas.width / (r.width || 1)), (event.clientY - r.top) * (canvas.height / (r.height || 1))]; };
|
|
1256
|
+
canvas.addEventListener('pointerdown', (event) => {
|
|
1257
|
+
if (event.button !== undefined && event.button !== 0) return;
|
|
1258
|
+
event.preventDefault();
|
|
1259
|
+
try { canvas.setPointerCapture(event.pointerId); } catch { /* not given */ }
|
|
1260
|
+
drawing = { id: event.pointerId, colour, width: pen(), points: [at(event)] };
|
|
1261
|
+
strokes.push(drawing); paint();
|
|
1262
|
+
});
|
|
1263
|
+
canvas.addEventListener('pointermove', (event) => {
|
|
1264
|
+
if (!drawing || event.pointerId !== drawing.id) return;
|
|
1265
|
+
drawing.points.push(at(event));
|
|
1266
|
+
const ctx = canvas.getContext('2d'); if (ctx) line(ctx, { ...drawing, points: drawing.points.slice(-2) });
|
|
1267
|
+
});
|
|
1268
|
+
const lift = (event) => { if (drawing && event.pointerId === drawing.id) { drawing = null; paint(); } };
|
|
1269
|
+
canvas.addEventListener('pointerup', lift); canvas.addEventListener('pointercancel', lift);
|
|
1270
|
+
box.addEventListener('keydown', (event) => {
|
|
1271
|
+
if (event.key === 'Escape') { event.preventDefault(); close(null); }
|
|
1272
|
+
else if ((event.ctrlKey || event.metaKey) && event.key === 'z' && event.target !== note) { event.preventDefault(); strokes.pop(); paint(); }
|
|
1273
|
+
});
|
|
1274
|
+
const onResize = () => { if (!box.hidden) fit(); };
|
|
1275
|
+
function close(result) {
|
|
1276
|
+
if (box.hidden) return;
|
|
1277
|
+
box.hidden = true; removeEventListener('resize', onResize);
|
|
1278
|
+
steps?.closed('draw');
|
|
1279
|
+
try { back?.focus?.({ preventScroll: true }); } catch { /* gone */ }
|
|
1280
|
+
const r = done2; done2 = null; r?.(result);
|
|
1281
|
+
}
|
|
1282
|
+
async function finish() {
|
|
1283
|
+
const kept = { strokes: strokes.map((st) => ({ ...st, points: [...st.points] })), note: note.value.replace(/\s+/g, ' ').trim().slice(0, 500), drawn: null };
|
|
1284
|
+
if (strokes.length) {
|
|
1285
|
+
const type = file.type === 'image/jpeg' ? 'image/jpeg' : 'image/png';
|
|
1286
|
+
const blob = await new Promise((resolve) => { try { canvas.toBlob(resolve, type, 0.9); } catch { resolve(null); } });
|
|
1287
|
+
if (blob) kept.drawn = new File([blob], drawnName(file.name, type), { type });
|
|
1288
|
+
}
|
|
1289
|
+
close(kept);
|
|
1290
|
+
}
|
|
1291
|
+
return {
|
|
1292
|
+
box,
|
|
1293
|
+
get open() { return !box.hidden; },
|
|
1294
|
+
/* Opens `picture` (a File) at `url`, with what was drawn and noted on it before. Resolves with
|
|
1295
|
+
{ strokes, note, drawn } (drawn: the picture to send, or null when nothing is drawn), or null when given up. */
|
|
1296
|
+
edit(picture, url, before = {}) {
|
|
1297
|
+
close(null);
|
|
1298
|
+
return new Promise((resolve) => {
|
|
1299
|
+
file = picture; done2 = resolve; back = document.activeElement;
|
|
1300
|
+
title.textContent = picture.name;
|
|
1301
|
+
strokes = (before.strokes ?? []).map((st) => ({ ...st, points: [...st.points] }));
|
|
1302
|
+
note.value = before.note ?? '';
|
|
1303
|
+
img.onload = () => {
|
|
1304
|
+
const { w, h } = drawnSize(img.naturalWidth, img.naturalHeight);
|
|
1305
|
+
canvas.width = w; canvas.height = h; paint(); fit();
|
|
1306
|
+
};
|
|
1307
|
+
img.onerror = () => close(null);
|
|
1308
|
+
img.src = url;
|
|
1309
|
+
box.hidden = false; addEventListener('resize', onResize);
|
|
1310
|
+
box.focus?.({ preventScroll: true });
|
|
1311
|
+
steps?.opened('draw', () => close(null));
|
|
1312
|
+
});
|
|
1313
|
+
},
|
|
1314
|
+
close: () => close(null),
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1189
1318
|
/* The kind of a file, as a short tag on its card. */
|
|
1190
1319
|
const extOf = (name) => { const m = /\.([a-z0-9]{1,5})$/i.exec(String(name ?? '')); return m ? m[1].toUpperCase() : ''; };
|
|
1191
1320
|
/* The icon of a file's kind, and its kind and size in a word under its name. */
|
|
@@ -1309,13 +1438,14 @@ export function mount(root, { load, send, words = {}, open, terminal, remind, vi
|
|
|
1309
1438
|
form.append(field, clip, mic, go, picker);
|
|
1310
1439
|
const dropZone = el('div', 'parley-drop', said(words, 'drop')); dropZone.hidden = true;
|
|
1311
1440
|
const zoom = zoomer(root, words, steps);
|
|
1441
|
+
const drawer = annotator(words, steps);
|
|
1312
1442
|
/* What floats over the chat first; then the chat, top to bottom. */
|
|
1313
1443
|
/* The box and what goes with it: apart from the thread, by a line and some room. */
|
|
1314
1444
|
const composer = el('div', 'parley-composer');
|
|
1315
1445
|
composer.append(quickRow, replyRow, pendingRow, form, problem);
|
|
1316
1446
|
const reacting = reactionPicker();
|
|
1317
1447
|
const shelf = mediaShelf();
|
|
1318
|
-
root.replaceChildren(zoom.box, shelf.box, reacting.box, dropZone, top, finder, main, composer);
|
|
1448
|
+
root.replaceChildren(zoom.box, drawer.box, shelf.box, reacting.box, dropZone, top, finder, main, composer);
|
|
1319
1449
|
root.dataset.view = as;
|
|
1320
1450
|
const narrow = () => root.clientWidth > 0 && root.clientWidth < NARROW_PX;
|
|
1321
1451
|
let wasNarrow = narrow();
|
|
@@ -1509,10 +1639,12 @@ export function mount(root, { load, send, words = {}, open, terminal, remind, vi
|
|
|
1509
1639
|
const pictures = el('div', 'parley-pictures');
|
|
1510
1640
|
for (const f of item.files) {
|
|
1511
1641
|
const url = f.picture && f.open !== null ? pictureUrl(f) : null;
|
|
1512
|
-
|
|
1642
|
+
/* What they wrote about this file alone, under it. */
|
|
1643
|
+
if (url) { const v = fileView(f); if (f.note) { const fig = el('figure', 'parley-noted'); fig.append(v, el('figcaption', 'parley-file-note', f.note)); pictures.append(fig); } else pictures.append(v); continue; }
|
|
1513
1644
|
const row2 = el('div', 'parley-file'); row2.dataset.attached = 'true';
|
|
1514
1645
|
row2.append(card(f, words, open, f.size));
|
|
1515
1646
|
if (f.shown) row2.append(el('span', 'parley-path', f.shown));
|
|
1647
|
+
if (f.note) row2.append(el('span', 'parley-file-note', f.note));
|
|
1516
1648
|
bubble.append(row2);
|
|
1517
1649
|
}
|
|
1518
1650
|
if (pictures.childNodes.length) bubble.append(pictures);
|
|
@@ -1935,7 +2067,13 @@ export function mount(root, { load, send, words = {}, open, terminal, remind, vi
|
|
|
1935
2067
|
if (!previews.has(file)) { let url = null; try { if (/^image\/(png|jpeg|gif|webp)$/.test(file.type) && typeof URL?.createObjectURL === 'function') url = URL.createObjectURL(file); } catch { url = null; } previews.set(file, url); }
|
|
1936
2068
|
return previews.get(file);
|
|
1937
2069
|
};
|
|
1938
|
-
|
|
2070
|
+
/* What was drawn on a picture about to go, and noted about it: { strokes, note, drawn }. */
|
|
2071
|
+
const marks = new Map();
|
|
2072
|
+
const letGo = (keep2) => {
|
|
2073
|
+
const kept = new Set([...keep2, ...keep2.map((f) => marks.get(f)?.drawn).filter(Boolean)]);
|
|
2074
|
+
for (const [file, url] of previews) if (!kept.has(file)) { if (url) try { URL.revokeObjectURL(url); } catch { /* gone */ } previews.delete(file); }
|
|
2075
|
+
for (const file of [...marks.keys()]) if (!keep2.includes(file)) marks.delete(file);
|
|
2076
|
+
};
|
|
1939
2077
|
const paintPending = () => {
|
|
1940
2078
|
letGo(pending);
|
|
1941
2079
|
pendingRow.hidden = pending.length === 0;
|
|
@@ -1943,8 +2081,20 @@ export function mount(root, { load, send, words = {}, open, terminal, remind, vi
|
|
|
1943
2081
|
const where = el('p', 'parley-where', said(words, 'attach-where'));
|
|
1944
2082
|
pendingRow.replaceChildren(where, ...pending.map((file, i) => {
|
|
1945
2083
|
const url = previewOf(file);
|
|
2084
|
+
const mark = marks.get(file);
|
|
1946
2085
|
const chip = el('span', url ? 'parley-pending parley-pending-picture' : 'parley-pending');
|
|
1947
|
-
if (url) {
|
|
2086
|
+
if (url) {
|
|
2087
|
+
/* A tap opens it large, to draw on it and say something about it alone. */
|
|
2088
|
+
const open2 = el('button', 'parley-pending-open'); open2.type = 'button';
|
|
2089
|
+
open2.title = said(words, 'draw-open', { name: file.name }); open2.setAttribute('aria-label', open2.title);
|
|
2090
|
+
const img = el('img'); img.src = (mark?.drawn && previewOf(mark.drawn)) || url; img.alt = file.name; open2.append(img);
|
|
2091
|
+
if (mark && (mark.drawn || mark.note)) { const badge = el('span', 'parley-pending-marked'); badge.append(icon('pencil', 'parley-sign')); badge.title = mark.note || said(words, 'draw-marked'); open2.append(badge); chip.dataset.marked = 'true'; }
|
|
2092
|
+
open2.addEventListener('click', async () => {
|
|
2093
|
+
const got = await drawer.edit(file, url, mark ?? {});
|
|
2094
|
+
if (got && pending.includes(file)) { if (got.drawn || got.note) marks.set(file, got); else marks.delete(file); paintPending(); }
|
|
2095
|
+
});
|
|
2096
|
+
chip.append(open2);
|
|
2097
|
+
}
|
|
1948
2098
|
else { const about = el('span', 'parley-card-about'); about.append(el('span', 'parley-name', file.name), kindLine(file.name, sizeText(file.size))); chip.append(fileGlyph(file.name), about); }
|
|
1949
2099
|
const x = button('\u00d7', 'parley-unattach', () => { pending = pending.filter((_, j) => j !== i); paintPending(); stayIn(); });
|
|
1950
2100
|
x.title = said(words, 'remove-file', { name: file.name }); x.setAttribute('aria-label', x.title);
|
|
@@ -1984,7 +2134,11 @@ export function mount(root, { load, send, words = {}, open, terminal, remind, vi
|
|
|
1984
2134
|
problem.hidden = false; problem.dataset.kind = 'sending'; problem.textContent = said(words, 'sending-files');
|
|
1985
2135
|
const files = [];
|
|
1986
2136
|
try {
|
|
1987
|
-
for (const file of pending)
|
|
2137
|
+
for (const file of pending) {
|
|
2138
|
+
const mark = marks.get(file); const sent2 = mark?.drawn ?? file;
|
|
2139
|
+
const up = await attach.upload(sent2, sent2.name);
|
|
2140
|
+
files.push(mark?.note ? { ...up, note: mark.note } : up);
|
|
2141
|
+
}
|
|
1988
2142
|
} catch (error) {
|
|
1989
2143
|
problem.dataset.kind = ''; problem.textContent = said(words, 'not-sent', { error: String(error?.message ?? error) });
|
|
1990
2144
|
uploading = false; go.disabled = clip.disabled = false;
|
package/ui/texts/en.json
CHANGED
|
@@ -49,6 +49,15 @@
|
|
|
49
49
|
"remove-file": "Remove {name}",
|
|
50
50
|
"sending-files": "Sending the files...",
|
|
51
51
|
"attach-where": "They go to its work folder: it opens them there, and so can whoever has this chat.",
|
|
52
|
+
"draw-open": "Open {name}: draw on it, add a note",
|
|
53
|
+
"draw-marked": "Drawn on",
|
|
54
|
+
"draw-colour": "Colour",
|
|
55
|
+
"draw-undo": "Undo",
|
|
56
|
+
"draw-clear": "Clear",
|
|
57
|
+
"draw-cancel": "Cancel",
|
|
58
|
+
"draw-done": "Done",
|
|
59
|
+
"draw-note": "A note about this picture (optional)",
|
|
60
|
+
"draw-hint": "Draw with a finger or the mouse to point at something.",
|
|
52
61
|
"copy": "Copy",
|
|
53
62
|
"copied": "Copied",
|
|
54
63
|
"see-details": "See the details",
|
package/ui/texts/fr.json
CHANGED
|
@@ -49,6 +49,15 @@
|
|
|
49
49
|
"remove-file": "Retirer {name}",
|
|
50
50
|
"sending-files": "Envoi des fichiers...",
|
|
51
51
|
"attach-where": "Ils vont dans son dossier de travail : il les ouvre là, comme quiconque a ce chat.",
|
|
52
|
+
"draw-open": "Ouvrir {name} : dessiner dessus, ajouter une note",
|
|
53
|
+
"draw-marked": "Annotée",
|
|
54
|
+
"draw-colour": "Couleur",
|
|
55
|
+
"draw-undo": "Défaire",
|
|
56
|
+
"draw-clear": "Effacer",
|
|
57
|
+
"draw-cancel": "Abandonner",
|
|
58
|
+
"draw-done": "Terminé",
|
|
59
|
+
"draw-note": "Une note sur cette image (facultatif)",
|
|
60
|
+
"draw-hint": "Dessinez au doigt ou à la souris pour montrer quelque chose.",
|
|
52
61
|
"copy": "Copier",
|
|
53
62
|
"copied": "Copié",
|
|
54
63
|
"see-details": "Voir le détail",
|