@songsid/agend 2.4.0-alpha.1 → 2.4.0-alpha.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 +1 -1
- package/README.zh-TW.md +1 -1
- package/dist/agent-whats-new.js +2 -0
- package/dist/agent-whats-new.js.map +1 -1
- package/dist/auth-api.js +3 -1
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/claude-code.js +4 -0
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/types.d.ts +6 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-availability.d.ts +1 -1
- package/dist/backend-availability.js +28 -1
- package/dist/backend-availability.js.map +1 -1
- package/dist/browser-backend-signins.d.ts +7 -1
- package/dist/browser-backend-signins.js +8 -4
- package/dist/browser-backend-signins.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/channel/mcp-tools.js +1 -1
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/config-validator.js +47 -7
- package/dist/config-validator.js.map +1 -1
- package/dist/daemon.d.ts +3 -0
- package/dist/daemon.js +4 -0
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-manager.d.ts +33 -4
- package/dist/fleet-manager.js +143 -61
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +19 -0
- package/dist/hub/audit/index.js +12 -5
- package/dist/hub/audit/index.js.map +1 -1
- package/dist/hub/catalog.d.ts +6 -0
- package/dist/hub/catalog.js +14 -4
- package/dist/hub/catalog.js.map +1 -1
- package/dist/hub/client.js +2 -0
- package/dist/hub/client.js.map +1 -1
- package/dist/hub/compose/member.d.ts +2 -0
- package/dist/hub/compose/member.js +11 -2
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/compose/server.js +2 -1
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/enrolment-code.d.ts +126 -0
- package/dist/hub/enrolment-code.js +266 -0
- package/dist/hub/enrolment-code.js.map +1 -0
- package/dist/hub/group-policy/admin-impact.js +4 -2
- package/dist/hub/group-policy/admin-impact.js.map +1 -1
- package/dist/hub/group-policy/admin-inventory.js +6 -6
- package/dist/hub/group-policy/admin-inventory.js.map +1 -1
- package/dist/hub/group-policy/authorization.d.ts +16 -2
- package/dist/hub/group-policy/authorization.js +69 -5
- package/dist/hub/group-policy/authorization.js.map +1 -1
- package/dist/hub/group-policy/impact-inventory.js +3 -3
- package/dist/hub/group-policy/impact-inventory.js.map +1 -1
- package/dist/hub/group-policy/resources.d.ts +40 -1
- package/dist/hub/group-policy/resources.js +51 -13
- package/dist/hub/group-policy/resources.js.map +1 -1
- package/dist/hub/group-policy/store.d.ts +6 -0
- package/dist/hub/group-policy/store.js +49 -4
- package/dist/hub/group-policy/store.js.map +1 -1
- package/dist/hub/http/compose.js +30 -6
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/init/text.js +2 -2
- package/dist/hub/init/text.js.map +1 -1
- package/dist/hub/init/web.d.ts +7 -0
- package/dist/hub/init/web.js +6 -1
- package/dist/hub/init/web.js.map +1 -1
- package/dist/hub/join/local.d.ts +27 -0
- package/dist/hub/join/local.js +70 -5
- package/dist/hub/join/local.js.map +1 -1
- package/dist/hub/join/receipt.d.ts +1 -0
- package/dist/hub/join/receipt.js +1 -1
- package/dist/hub/join/receipt.js.map +1 -1
- package/dist/hub/join/service.d.ts +92 -6
- package/dist/hub/join/service.js +199 -28
- package/dist/hub/join/service.js.map +1 -1
- package/dist/hub/join/store.d.ts +2 -1
- package/dist/hub/join/store.js +7 -7
- package/dist/hub/join/store.js.map +1 -1
- package/dist/hub/member/exposure-api.d.ts +2 -0
- package/dist/hub/member/exposure-api.js +3 -2
- package/dist/hub/member/exposure-api.js.map +1 -1
- package/dist/hub/member/exposures.d.ts +4 -0
- package/dist/hub/member/exposures.js +12 -2
- package/dist/hub/member/exposures.js.map +1 -1
- package/dist/hub/member/pairing-notices.js +8 -6
- package/dist/hub/member/pairing-notices.js.map +1 -1
- package/dist/hub/pairing-notices.d.ts +5 -2
- package/dist/hub/pairing-notices.js +38 -13
- package/dist/hub/pairing-notices.js.map +1 -1
- package/dist/hub/pairing.d.ts +7 -2
- package/dist/hub/protocol.d.ts +47 -0
- package/dist/hub/protocol.js +3 -1
- package/dist/hub/protocol.js.map +1 -1
- package/dist/hub/server.js +15 -1
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/types.d.ts +12 -4
- package/dist/hub-pairing-summary.js +1 -1
- package/dist/hub-pairing-summary.js.map +1 -1
- package/dist/instance-config-impact.js +4 -0
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instance-lifecycle.js +4 -0
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/locale.js +6 -2
- package/dist/locale.js.map +1 -1
- package/dist/log-service.d.ts +62 -6
- package/dist/log-service.js +135 -28
- package/dist/log-service.js.map +1 -1
- package/dist/log-steps-agy-grok.d.ts +74 -0
- package/dist/log-steps-agy-grok.js +440 -0
- package/dist/log-steps-agy-grok.js.map +1 -0
- package/dist/log-steps.d.ts +62 -3
- package/dist/log-steps.js +188 -22
- package/dist/log-steps.js.map +1 -1
- package/dist/log-transcript-paths.d.ts +29 -0
- package/dist/log-transcript-paths.js +109 -0
- package/dist/log-transcript-paths.js.map +1 -0
- package/dist/login-controller.d.ts +17 -3
- package/dist/login-controller.js +57 -5
- package/dist/login-controller.js.map +1 -1
- package/dist/login-window-lock.d.ts +20 -8
- package/dist/login-window-lock.js +35 -16
- package/dist/login-window-lock.js.map +1 -1
- package/dist/outbound-handlers.d.ts +14 -0
- package/dist/outbound-handlers.js +49 -1
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/profile-signins.d.ts +2 -0
- package/dist/profile-signins.js +1 -1
- package/dist/profile-signins.js.map +1 -1
- package/dist/settings-api.d.ts +34 -0
- package/dist/settings-api.js +184 -6
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +38 -1
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.js +14 -0
- package/dist/settings-effect.js.map +1 -1
- package/dist/tool-progress.d.ts +7 -0
- package/dist/tool-progress.js +21 -9
- package/dist/tool-progress.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/ui/accounts-view.js +14 -4
- package/dist/ui/agent-details-settings.js +2 -2
- package/dist/ui/agent-page-strings.js +2 -2
- package/dist/ui/backend-signin.js +47 -14
- package/dist/ui/chat-activity-groups.js +225 -0
- package/dist/ui/chat-activity.js +355 -0
- package/dist/ui/chat-popout-header.js +35 -0
- package/dist/ui/chat-popout-transport.js +80 -0
- package/dist/ui/chat-popout.js +63 -0
- package/dist/ui/chat-quote.js +3 -1
- package/dist/ui/chat-store.js +45 -4
- package/dist/ui/chat-workspace-gestures.js +177 -0
- package/dist/ui/chat-workspace-navigation.js +34 -10
- package/dist/ui/chat-workspace.js +96 -32
- package/dist/ui/host-install.js +2 -2
- package/dist/ui/hub-agent-copy.js +7 -7
- package/dist/ui/hub-chat-strings.js +3 -3
- package/dist/ui/hub-client.js +77 -17
- package/dist/ui/hub-company-join-strings.js +12 -10
- package/dist/ui/hub-company-join.js +52 -39
- package/dist/ui/hub-confirm-place.js +44 -0
- package/dist/ui/hub-directory-editor-strings.js +3 -3
- package/dist/ui/hub-directory-notice-strings.js +1 -1
- package/dist/ui/hub-enrolment-code-strings.js +44 -0
- package/dist/ui/hub-enrolment-code.js +159 -0
- package/dist/ui/hub-group-search.js +82 -0
- package/dist/ui/hub-group-strings.js +8 -8
- package/dist/ui/hub-join-approval.js +31 -0
- package/dist/ui/hub-join-code-input.js +66 -0
- package/dist/ui/hub-join-queue.js +62 -0
- package/dist/ui/hub-join-steps.js +231 -0
- package/dist/ui/hub-joincode-flow-strings.js +22 -0
- package/dist/ui/hub-owner-strings.js +9 -9
- package/dist/ui/hub-pairing-progress-strings.js +1 -1
- package/dist/ui/hub-quick-pairing.js +8 -4
- package/dist/ui/hub-quick-strings.js +11 -11
- package/dist/ui/hub-share-refused.js +17 -0
- package/dist/ui/hub-strings.js +61 -61
- package/dist/ui/hub-this-hub.js +2 -2
- package/dist/ui/hub-welcome.js +26 -5
- package/dist/ui/image-annotate.js +283 -0
- package/dist/ui/image-lightbox.js +26 -6
- package/dist/ui/log-row.js +327 -0
- package/dist/ui/panel-chat.js +151 -12
- package/dist/ui/panel-details.js +14 -6
- package/dist/ui/panel-hub.js +42 -13
- package/dist/ui/panel-log.js +9 -154
- package/dist/ui/panel-settings.js +48 -11
- package/dist/ui/search-dialog.js +1 -0
- package/dist/ui/settings-access-overview.js +1 -1
- package/dist/ui/settings-hub-browser-certificate.js +3 -3
- package/dist/ui/settings-hub-company-join.js +41 -30
- package/dist/ui/settings-hub-connection.js +8 -5
- package/dist/ui/settings-hub-membership.js +3 -3
- package/dist/ui/settings-hub-section.js +1 -1
- package/dist/ui/settings-hub-setup-strings.js +6 -6
- package/dist/ui/settings-hub-setup.js +44 -6
- package/dist/ui/settings-hub.js +35 -10
- package/dist/ui/settings-layout.js +6 -4
- package/dist/ui/settings-public-session-strings.js +37 -0
- package/dist/ui/settings-registry.js +4 -0
- package/dist/ui/settings-strings.js +2 -2
- package/dist/ui/shared/app-shell.js +16 -10
- package/dist/ui/shared/app.css +195 -30
- package/dist/ui/shared/app.js +8 -1
- package/dist/ui/shared/chat-render.js +11 -2
- package/dist/ui/shared/chat-thread.js +20 -3
- package/dist/ui/shared/chat-work-bar.css +7 -0
- package/dist/ui/shared/chat-workspace-model.js +39 -9
- package/dist/ui/shared/hub-owner.css +8 -0
- package/dist/ui/shared/identity-color.js +9 -3
- package/dist/ui/shared/image-annotate.css +45 -0
- package/dist/ui/shared/instance-nav.js +59 -22
- package/dist/ui/shared/pane-geometry.js +29 -0
- package/dist/ui/shared/signin.js +2 -2
- package/dist/ui/shared/tokens.css +14 -0
- package/dist/ui/shared/ui-menu.js +22 -7
- package/dist/ui/signin.html +1 -1
- package/dist/ui/structured-signin.js +11 -4
- package/dist/web-api.d.ts +1 -0
- package/dist/web-api.js +34 -4
- package/dist/web-api.js.map +1 -1
- package/dist/web-backend-login.d.ts +9 -3
- package/dist/web-backend-login.js +7 -4
- package/dist/web-backend-login.js.map +1 -1
- package/dist/web-chat-history.d.ts +11 -0
- package/dist/web-chat-history.js +9 -1
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-guest-access.js +2 -2
- package/dist/web-guest-access.js.map +1 -1
- package/dist/web-session.d.ts +31 -3
- package/dist/web-session.js +25 -4
- package/dist/web-session.js.map +1 -1
- package/dist/web-settings-patch.d.ts +8 -2
- package/dist/web-settings-patch.js +22 -10
- package/dist/web-settings-patch.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
// #3727 (M-2973): mark up a chat image and quote it to the agent. The image viewer's 「標註」 opens this editor in the
|
|
2
|
+
// viewer's own dialog: the picture on a canvas, and on top of it pen strokes, boxes, arrows and text in a few colours,
|
|
3
|
+
// with undo, redo and clear. 「引用給 Agent」 hands back the marked-up picture as a NEW PNG file (the original file is
|
|
4
|
+
// only read, never changed); the chat puts it in a composer as an attachment with a reply to the original message.
|
|
5
|
+
//
|
|
6
|
+
// Browser-only: the picture is the chat's own same-origin file (/ui/file/<hex>), drawn and encoded here — no server
|
|
7
|
+
// call, no other origin. No style attribute (#1300): classes only; the stylesheet is linked by this module (an older
|
|
8
|
+
// app.css lacks it). Pointer events, so a mouse, a pen and a finger draw the same way.
|
|
9
|
+
import { html, useEffect, useRef, useState } from "/assets/app-html.js";
|
|
10
|
+
import { register, t } from "/assets/app-i18n.js";
|
|
11
|
+
import { Icon } from "/assets/ui-icons.js";
|
|
12
|
+
|
|
13
|
+
export const annotateV1 = true;
|
|
14
|
+
register("annotate", {
|
|
15
|
+
en: {
|
|
16
|
+
title: "Annotate: {0}", titleNoName: "Annotate image", tools: "Tools", colours: "Colour",
|
|
17
|
+
pen: "Pen (P)", box: "Box (B)", arrow: "Arrow (A)", text: "Text (T)", undo: "Undo (Ctrl+Z)", redo: "Redo (Ctrl+Shift+Z)", clear: "Clear",
|
|
18
|
+
red: "Red", yellow: "Yellow", blue: "Blue", white: "White",
|
|
19
|
+
textField: "Text", textShort: "Type, then Enter", textHint: "Click the picture where the text goes, type it here, then press Enter.", textAdd: "Add",
|
|
20
|
+
close: "Close without sending", loading: "Loading the picture…",
|
|
21
|
+
failedLoad: "The picture could not be loaded for annotating.", failedSave: "The annotated picture could not be made.",
|
|
22
|
+
canvas: "Picture to annotate. Choose a tool, then draw on it.",
|
|
23
|
+
},
|
|
24
|
+
"zh-TW": {
|
|
25
|
+
title: "標註:{0}", titleNoName: "標註圖片", tools: "工具", colours: "顏色",
|
|
26
|
+
pen: "畫筆(P)", box: "方框(B)", arrow: "箭頭(A)", text: "文字(T)", undo: "復原(Ctrl+Z)", redo: "重做(Ctrl+Shift+Z)", clear: "清除",
|
|
27
|
+
red: "紅", yellow: "黃", blue: "藍", white: "白",
|
|
28
|
+
textField: "文字", textShort: "輸入後按 Enter", textHint: "先點圖片上要放文字的地方,在這裡輸入,再按 Enter。", textAdd: "加入",
|
|
29
|
+
close: "關閉,不送出", loading: "正在載入圖片…",
|
|
30
|
+
failedLoad: "無法載入這張圖片來標註。", failedSave: "無法產生標註後的圖片。",
|
|
31
|
+
canvas: "要標註的圖片。選一個工具,然後在上面畫。",
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const COLOURS = [["red", "#e5484d"], ["yellow", "#ffc53d"], ["blue", "#3e8eff"], ["white", "#ffffff"]];
|
|
36
|
+
export const TOOLS = ["pen", "box", "arrow", "text"];
|
|
37
|
+
const KEYS = { p: "pen", b: "box", a: "arrow", t: "text" };
|
|
38
|
+
/** The longest side a marked-up picture is drawn at (a larger original is scaled down; a smaller one is kept). */
|
|
39
|
+
export const MAX_SIDE = 2560;
|
|
40
|
+
|
|
41
|
+
/** Canvas size for a picture of w × h: its own size, scaled down to MAX_SIDE on its longest side. */
|
|
42
|
+
export function canvasSize(w, h) {
|
|
43
|
+
const k = Math.min(1, MAX_SIDE / Math.max(1, w, h));
|
|
44
|
+
return { w: Math.max(1, Math.round(w * k)), h: Math.max(1, Math.round(h * k)) };
|
|
45
|
+
}
|
|
46
|
+
/** Stroke width for a canvas of w × h: readable on a phone screenshot and on a wide one. */
|
|
47
|
+
export const strokeWidth = (w, h) => Math.max(3, Math.round(Math.max(w, h) / 320));
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The marks as a history: `shapes` in drawing order (a "clear" is one too, so it can be undone) and `redo`, what undo
|
|
51
|
+
* took back. Pure, so the order of undo / redo / clear is tested without a canvas.
|
|
52
|
+
*/
|
|
53
|
+
export function history() {
|
|
54
|
+
let shapes = [], redo = [];
|
|
55
|
+
return {
|
|
56
|
+
get shapes() { return shapes; },
|
|
57
|
+
/** What is drawn: everything after the last clear. */
|
|
58
|
+
visible() { const at = shapes.map(s => s.tool).lastIndexOf("clear"); return shapes.slice(at + 1); },
|
|
59
|
+
add(shape) { shapes = [...shapes, shape]; redo = []; },
|
|
60
|
+
clear() { if (this.visible().length) this.add({ tool: "clear" }); },
|
|
61
|
+
undo() { if (!shapes.length) return false; redo = [...redo, shapes[shapes.length - 1]]; shapes = shapes.slice(0, -1); return true; },
|
|
62
|
+
redo() { if (!redo.length) return false; shapes = [...shapes, redo[redo.length - 1]]; redo = redo.slice(0, -1); return true; },
|
|
63
|
+
get canUndo() { return shapes.length > 0; },
|
|
64
|
+
get canRedo() { return redo.length > 0; },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Draw one mark. `lw`: the stroke width for this canvas. */
|
|
69
|
+
export function drawShape(ctx, s, base) {
|
|
70
|
+
const lw = s.lw ?? base; // a mark keeps the width it was drawn with
|
|
71
|
+
ctx.save();
|
|
72
|
+
ctx.lineCap = "round"; ctx.lineJoin = "round"; ctx.lineWidth = lw; ctx.strokeStyle = s.colour; ctx.fillStyle = s.colour;
|
|
73
|
+
if (s.tool === "pen" && s.points.length) {
|
|
74
|
+
ctx.beginPath(); ctx.moveTo(s.points[0][0], s.points[0][1]);
|
|
75
|
+
for (const [x, y] of s.points.slice(1)) ctx.lineTo(x, y);
|
|
76
|
+
if (s.points.length === 1) ctx.lineTo(s.points[0][0] + 0.01, s.points[0][1]); // a dot
|
|
77
|
+
ctx.stroke();
|
|
78
|
+
} else if (s.tool === "box") {
|
|
79
|
+
ctx.strokeRect(Math.min(s.x0, s.x1), Math.min(s.y0, s.y1), Math.abs(s.x1 - s.x0), Math.abs(s.y1 - s.y0));
|
|
80
|
+
} else if (s.tool === "arrow") {
|
|
81
|
+
const angle = Math.atan2(s.y1 - s.y0, s.x1 - s.x0), head = lw * 4;
|
|
82
|
+
ctx.beginPath(); ctx.moveTo(s.x0, s.y0); ctx.lineTo(s.x1, s.y1); ctx.stroke();
|
|
83
|
+
ctx.beginPath(); ctx.moveTo(s.x1, s.y1);
|
|
84
|
+
ctx.lineTo(s.x1 - head * Math.cos(angle - Math.PI / 6), s.y1 - head * Math.sin(angle - Math.PI / 6));
|
|
85
|
+
ctx.lineTo(s.x1 - head * Math.cos(angle + Math.PI / 6), s.y1 - head * Math.sin(angle + Math.PI / 6));
|
|
86
|
+
ctx.closePath(); ctx.fill();
|
|
87
|
+
} else if (s.tool === "text" && s.text) {
|
|
88
|
+
ctx.font = `bold ${s.size ?? lw * 6}px system-ui, sans-serif`; ctx.textBaseline = "top";
|
|
89
|
+
// A dark outline, so a light colour reads on a light picture and the reverse.
|
|
90
|
+
ctx.lineWidth = Math.max(2, lw * 0.8); ctx.strokeStyle = s.colour === "#ffffff" ? "#000000" : "rgba(0,0,0,0.65)";
|
|
91
|
+
ctx.strokeText(s.text, s.x, s.y); ctx.fillText(s.text, s.x, s.y);
|
|
92
|
+
}
|
|
93
|
+
ctx.restore();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The marked-up picture's file name: the original's, before its extension, plus "-annotated.png". */
|
|
97
|
+
export function annotatedName(name) {
|
|
98
|
+
const base = String(name || "image").replace(/\.[A-Za-z0-9]{1,5}$/, "").replace(/[\\/:*?"<>|\x00-\x1f]/g, "_").slice(0, 80) || "image";
|
|
99
|
+
return `${base}-annotated.png`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Prism on #3735: the editor's colours are tokens (tokens.css). A tab whose cached tokens.css predates them would draw
|
|
104
|
+
* transparent swatches and lose the selected tool, so the editor's root sets any of them that resolve to nothing —
|
|
105
|
+
* CSSOM on its own element (#1300), the same values as tokens.css; a current tokens.css wins (nothing is set).
|
|
106
|
+
*/
|
|
107
|
+
export const MEDIA_TOKENS = [["--media-ink", "#ffffff"], ["--media-bar", "rgba(0, 0, 0, 0.75)"], ["--media-panel", "rgba(0, 0, 0, 0.6)"],
|
|
108
|
+
["--media-btn", "rgba(255, 255, 255, 0.12)"], ["--media-btn-on", "rgba(255, 255, 255, 0.32)"], ["--media-line", "rgba(255, 255, 255, 0.35)"],
|
|
109
|
+
...COLOURS.map(([k, v]) => [`--mark-${k}`, v])];
|
|
110
|
+
export function fillMissingTokens(el) {
|
|
111
|
+
if (!el || typeof getComputedStyle !== "function") return;
|
|
112
|
+
const computed = getComputedStyle(el);
|
|
113
|
+
for (const [name, value] of MEDIA_TOKENS) if (!computed.getPropertyValue(name).trim()) el.style.setProperty(name, value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The stylesheet, once per document. */
|
|
117
|
+
export function linkAnnotateCss(doc = typeof document !== "undefined" ? document : null) {
|
|
118
|
+
if (!doc || !doc.head || doc.querySelector('link[data-annotate-css="1"]')) return;
|
|
119
|
+
const link = doc.createElement("link");
|
|
120
|
+
link.setAttribute("rel", "stylesheet"); link.setAttribute("href", "/assets/image-annotate.css"); link.setAttribute("data-annotate-css", "1");
|
|
121
|
+
doc.head.appendChild(link);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The editor, inside the viewer's dialog. `src`, `name`: the picture. `targets`: [{ key, label, quote(file) }] — the first
|
|
126
|
+
* is this chat's composer, a second the other pane's; quote() answers true when the file went in. `onClose`: ✕ / Esc
|
|
127
|
+
* (the dialog's own cancel), and after a quote.
|
|
128
|
+
*/
|
|
129
|
+
export function AnnotateEditor({ src, name, targets = [], onClose, onError }) {
|
|
130
|
+
const canvas = useRef(null), base = useRef(null), hist = useRef(history()), drag = useRef(null), textField = useRef(null);
|
|
131
|
+
const [size, setSize] = useState(null); // { w, h, lw } once the picture has loaded
|
|
132
|
+
const [failed, setFailed] = useState(false);
|
|
133
|
+
const [tool, setTool] = useState("pen");
|
|
134
|
+
const [colour, setColour] = useState(COLOURS[0][1]);
|
|
135
|
+
const [textAt, setTextAt] = useState(null); // where a text mark goes: [x, y] on the canvas
|
|
136
|
+
const [text, setText] = useState("");
|
|
137
|
+
const [, setTick] = useState(0);
|
|
138
|
+
const [busy, setBusy] = useState(false);
|
|
139
|
+
const refresh = () => setTick(n => n + 1);
|
|
140
|
+
// Prism on #3735: an export (toBlob is asynchronous) belongs to the live editor. Closing it, or the editor going
|
|
141
|
+
// away, retires one in flight: its file is never handed to a composer afterwards.
|
|
142
|
+
const live = useRef({ alive: true, op: 0 });
|
|
143
|
+
const close = () => { live.current.op++; onClose?.(); };
|
|
144
|
+
useEffect(() => () => { live.current.alive = false; live.current.op++; }, []);
|
|
145
|
+
useEffect(() => { linkAnnotateCss(); }, []);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
const img = new Image();
|
|
148
|
+
img.decoding = "async";
|
|
149
|
+
img.onload = () => {
|
|
150
|
+
const { w, h } = canvasSize(img.naturalWidth, img.naturalHeight);
|
|
151
|
+
base.current = img; setSize({ w, h, lw: strokeWidth(w, h) });
|
|
152
|
+
};
|
|
153
|
+
img.onerror = () => setFailed(true);
|
|
154
|
+
img.src = src; // the chat's own file: same origin, so the canvas can be read back
|
|
155
|
+
return () => { img.onload = null; img.onerror = null; };
|
|
156
|
+
}, [src]);
|
|
157
|
+
const paint = (extra, forExport = false) => {
|
|
158
|
+
const c = canvas.current, s = size;
|
|
159
|
+
if (!c || !s || !base.current) return;
|
|
160
|
+
const ctx = c.getContext("2d");
|
|
161
|
+
ctx.clearRect(0, 0, s.w, s.h);
|
|
162
|
+
ctx.drawImage(base.current, 0, 0, s.w, s.h);
|
|
163
|
+
for (const shape of hist.current.visible()) drawShape(ctx, shape, s.lw);
|
|
164
|
+
if (extra) drawShape(ctx, extra, s.lw);
|
|
165
|
+
if (textAt && !forExport) { // where the text will go: a small cross (never in the file)
|
|
166
|
+
ctx.save(); ctx.strokeStyle = colour; ctx.lineWidth = Math.max(2, s.lw / 2);
|
|
167
|
+
ctx.beginPath(); ctx.moveTo(textAt[0] - s.lw * 2, textAt[1]); ctx.lineTo(textAt[0] + s.lw * 2, textAt[1]);
|
|
168
|
+
ctx.moveTo(textAt[0], textAt[1] - s.lw * 2); ctx.lineTo(textAt[0], textAt[1] + s.lw * 2); ctx.stroke(); ctx.restore();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
useEffect(() => { paint(); });
|
|
172
|
+
/** Canvas pixels per screen pixel now (a phone shows a big picture small): a mark is at least 3 screen px wide, and
|
|
173
|
+
* text at least 20 screen px tall, whatever the picture's own size. */
|
|
174
|
+
const perScreenPx = () => { const c = canvas.current, r = c?.getBoundingClientRect(); return c && r && r.width > 0 ? c.width / r.width : 1; };
|
|
175
|
+
const markWidth = () => Math.max(size.lw, Math.round(3 * perScreenPx()));
|
|
176
|
+
const textSize = () => Math.max(size.lw * 6, Math.round(20 * perScreenPx()));
|
|
177
|
+
const point = (e) => {
|
|
178
|
+
const c = canvas.current, r = c.getBoundingClientRect();
|
|
179
|
+
return [((e.clientX - r.left) / Math.max(1, r.width)) * c.width, ((e.clientY - r.top) / Math.max(1, r.height)) * c.height];
|
|
180
|
+
};
|
|
181
|
+
const onDown = (e) => {
|
|
182
|
+
if (!size || (e.button ?? 0) !== 0) return;
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
const [x, y] = point(e);
|
|
185
|
+
if (tool === "text") { setTextAt([x, y]); textField.current?.focus(); return; }
|
|
186
|
+
canvas.current.setPointerCapture?.(e.pointerId);
|
|
187
|
+
const lw = markWidth();
|
|
188
|
+
drag.current = tool === "pen" ? { tool, colour, lw, points: [[x, y]] } : { tool, colour, lw, x0: x, y0: y, x1: x, y1: y };
|
|
189
|
+
paint(drag.current);
|
|
190
|
+
};
|
|
191
|
+
const onMove = (e) => {
|
|
192
|
+
const d = drag.current;
|
|
193
|
+
if (!d) return;
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
const [x, y] = point(e);
|
|
196
|
+
if (d.tool === "pen") d.points.push([x, y]); else { d.x1 = x; d.y1 = y; }
|
|
197
|
+
paint(d);
|
|
198
|
+
};
|
|
199
|
+
const onUp = () => {
|
|
200
|
+
const d = drag.current;
|
|
201
|
+
drag.current = null;
|
|
202
|
+
if (!d) return;
|
|
203
|
+
const tiny = d.tool !== "pen" && Math.hypot(d.x1 - d.x0, d.y1 - d.y0) < 3;
|
|
204
|
+
if (!tiny) hist.current.add(d);
|
|
205
|
+
refresh();
|
|
206
|
+
};
|
|
207
|
+
const addText = () => {
|
|
208
|
+
const value = text.trim();
|
|
209
|
+
if (!value || !textAt) return;
|
|
210
|
+
hist.current.add({ tool: "text", colour, lw: markWidth(), size: textSize(), x: textAt[0], y: textAt[1], text: value.slice(0, 200) });
|
|
211
|
+
setText(""); setTextAt(null);
|
|
212
|
+
};
|
|
213
|
+
const undo = () => { if (hist.current.undo()) refresh(); };
|
|
214
|
+
const redo = () => { if (hist.current.redo()) refresh(); };
|
|
215
|
+
const clear = () => { hist.current.clear(); setTextAt(null); refresh(); };
|
|
216
|
+
const quote = async (target) => {
|
|
217
|
+
const c = canvas.current;
|
|
218
|
+
if (!c || busy) return;
|
|
219
|
+
const op = ++live.current.op, current = () => live.current.alive && live.current.op === op;
|
|
220
|
+
setBusy(true);
|
|
221
|
+
try {
|
|
222
|
+
paint(null, true); // without the text cross
|
|
223
|
+
const blob = await new Promise((resolve) => c.toBlob(resolve, "image/png"));
|
|
224
|
+
if (!current()) return; // closed or gone while encoding: nothing is added anywhere
|
|
225
|
+
if (!blob) throw new Error("no image");
|
|
226
|
+
const file = new File([blob], annotatedName(name), { type: "image/png" });
|
|
227
|
+
// The editor's own liveness travels with the file: a target that waits (the other pane's Chat mounting) checks it
|
|
228
|
+
// at its commit, so closing the editor meanwhile cancels the quote and the attachment there (Prism on #3735 r2).
|
|
229
|
+
if (await target.quote(file, current) && current()) onClose?.();
|
|
230
|
+
} catch { if (current()) onError?.(t("annotate.failedSave")); }
|
|
231
|
+
finally { if (live.current.alive) setBusy(false); }
|
|
232
|
+
};
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const onKey = (e) => {
|
|
235
|
+
const typing = e.target && (e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA");
|
|
236
|
+
const mod = e.ctrlKey || e.metaKey;
|
|
237
|
+
if (mod && !e.altKey && (e.key === "z" || e.key === "Z")) { if (typing && !e.shiftKey && text) return; e.preventDefault(); if (e.shiftKey) redo(); else undo(); return; }
|
|
238
|
+
if (mod && !e.altKey && (e.key === "y" || e.key === "Y")) { e.preventDefault(); redo(); return; }
|
|
239
|
+
if (typing || mod || e.altKey) return;
|
|
240
|
+
const k = KEYS[e.key.toLowerCase()];
|
|
241
|
+
if (k) { e.preventDefault(); setTool(k); if (k !== "text") setTextAt(null); return; }
|
|
242
|
+
const n = Number(e.key);
|
|
243
|
+
if (n >= 1 && n <= COLOURS.length) { e.preventDefault(); setColour(COLOURS[n - 1][1]); }
|
|
244
|
+
};
|
|
245
|
+
document.addEventListener("keydown", onKey);
|
|
246
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
247
|
+
});
|
|
248
|
+
const label = name ? t("annotate.title", name) : t("annotate.titleNoName");
|
|
249
|
+
return html`<div class="an" data-trust="annotate" role="group" aria-label=${label} ref=${fillMissingTokens}>
|
|
250
|
+
<div class="an-bar">
|
|
251
|
+
<span class="an-name" title=${name}>${label}</span>
|
|
252
|
+
<span class="an-tools" role="radiogroup" aria-label=${t("annotate.tools")}>
|
|
253
|
+
${TOOLS.map((k) => html`<button type="button" role="radio" aria-checked=${tool === k ? "true" : "false"} class=${`btn btn-sm an-tool an-tool-${k}${tool === k ? " on" : ""}`}
|
|
254
|
+
title=${t(`annotate.${k}`)} aria-label=${t(`annotate.${k}`)} onClick=${() => { setTool(k); if (k !== "text") setTextAt(null); }}><span class="an-glyph" aria-hidden="true">${{ pen: "✎", box: "▭", arrow: "↗", text: "T" }[k]}</span></button>`)}
|
|
255
|
+
</span>
|
|
256
|
+
<span class="an-colours" role="radiogroup" aria-label=${t("annotate.colours")}>
|
|
257
|
+
${COLOURS.map(([k, v], i) => html`<button type="button" role="radio" aria-checked=${colour === v ? "true" : "false"} class=${`an-colour${colour === v ? " on" : ""}`}
|
|
258
|
+
title=${`${t(`annotate.${k}`)} (${i + 1})`} aria-label=${t(`annotate.${k}`)} onClick=${() => setColour(v)}><span class=${`an-dot an-colour-${k}`} aria-hidden="true"></span></button>`)}
|
|
259
|
+
</span>
|
|
260
|
+
<span class="an-history">
|
|
261
|
+
<button type="button" class="btn btn-sm an-undo" disabled=${!hist.current.canUndo} title=${t("annotate.undo")} aria-label=${t("annotate.undo")} onClick=${undo}>↶</button>
|
|
262
|
+
<button type="button" class="btn btn-sm an-redo" disabled=${!hist.current.canRedo} title=${t("annotate.redo")} aria-label=${t("annotate.redo")} onClick=${redo}>↷</button>
|
|
263
|
+
<button type="button" class="btn btn-sm an-clear" disabled=${!hist.current.visible().length} onClick=${clear}>${t("annotate.clear")}</button>
|
|
264
|
+
</span>
|
|
265
|
+
<button type="button" class="icon-btn an-close" title=${t("annotate.close")} aria-label=${t("annotate.close")} onClick=${close}><${Icon} name="close" /></button>
|
|
266
|
+
</div>
|
|
267
|
+
${tool === "text" ? html`<form class="an-text" onSubmit=${(e) => { e.preventDefault(); addText(); }}>
|
|
268
|
+
<label class="an-text-label"><span>${t("annotate.textField")}</span>
|
|
269
|
+
<input ref=${textField} type="text" maxlength="200" value=${text} placeholder=${t("annotate.textShort")} title=${t("annotate.textHint")} onInput=${(e) => setText(e.target.value)} /></label>
|
|
270
|
+
<button type="submit" class="btn btn-sm" disabled=${!text.trim() || !textAt}>${t("annotate.textAdd")}</button>
|
|
271
|
+
</form>` : null}
|
|
272
|
+
<div class="an-stage">
|
|
273
|
+
${failed ? html`<p class="an-note" role="alert">${t("annotate.failedLoad")}</p>`
|
|
274
|
+
: size ? html`<canvas ref=${canvas} class=${`an-canvas an-cursor-${tool}`} width=${size.w} height=${size.h} role="img" aria-label=${t("annotate.canvas")}
|
|
275
|
+
onPointerDown=${onDown} onPointerMove=${onMove} onPointerUp=${onUp} onPointerCancel=${onUp} />`
|
|
276
|
+
: html`<p class="an-note" role="status">${t("annotate.loading")}</p>`}
|
|
277
|
+
</div>
|
|
278
|
+
<div class="an-actions">
|
|
279
|
+
${targets.map((target, i) => html`<button type="button" class=${`btn ${i === 0 ? "btn-primary" : ""} an-quote`} disabled=${!size || busy}
|
|
280
|
+
data-target=${target.key} onClick=${() => quote(target)}>${target.label}</button>`)}
|
|
281
|
+
</div>
|
|
282
|
+
</div>`;
|
|
283
|
+
}
|
|
@@ -9,12 +9,17 @@
|
|
|
9
9
|
// #2333: zoom and pan (image-zoom.js). The toolbar has −, the level (it toggles fit ↔ 100%), + and Fit width; the keys
|
|
10
10
|
// + / − / 0 (fit) / 1 (100%) / W (fit width). Each image opens fitted; stepping to another fits it again.
|
|
11
11
|
import { html, useEffect, useLayoutEffect, useRef, useState } from "/assets/app-html.js";
|
|
12
|
-
import { t } from "/assets/app-i18n.js";
|
|
12
|
+
import { register, t } from "/assets/app-i18n.js";
|
|
13
13
|
import { createStore, useStore } from "/assets/app-store.js";
|
|
14
14
|
import { Icon } from "/assets/ui-icons.js";
|
|
15
15
|
import { createZoom, STEP } from "./image-zoom.js";
|
|
16
16
|
|
|
17
17
|
const FILE_URL = /^\/ui\/file\/[0-9a-f]{32}$/;
|
|
18
|
+
// #3727: the viewer's own word for the annotate button (here, so an older cached chat dictionary is never shown a raw key).
|
|
19
|
+
register("lbAnnotate", { en: { open: "Annotate", failed: "The annotation tools could not be loaded. Reload this page to try again." },
|
|
20
|
+
"zh-TW": { open: "標註", failed: "無法載入標註工具。請重新整理頁面再試。" } });
|
|
21
|
+
/** The annotation editor, loaded on the first 「標註」 (its module and stylesheet stay out of every other page load). */
|
|
22
|
+
const loadAnnotate = () => import("./image-annotate.js");
|
|
18
23
|
/** What is shown: { items: [{ src, name }], index, opener } or null. One per page; the chat that shows it owns it. */
|
|
19
24
|
export const lightboxStore = createStore({ open: null });
|
|
20
25
|
let seq = 0;
|
|
@@ -23,7 +28,7 @@ let seq = 0;
|
|
|
23
28
|
* The images of a message, from its thumbnails' links; `index` the one clicked. Anything that is not a chat file URL
|
|
24
29
|
* is left out (and nothing opens if the clicked one is not).
|
|
25
30
|
*/
|
|
26
|
-
export function openLightbox(links, clicked) {
|
|
31
|
+
export function openLightbox(links, clicked, annotate = null) {
|
|
27
32
|
const items = [];
|
|
28
33
|
let index = -1;
|
|
29
34
|
for (const a of links) {
|
|
@@ -34,7 +39,8 @@ export function openLightbox(links, clicked) {
|
|
|
34
39
|
items.push({ src, name: (img && img.getAttribute("alt")) || "" });
|
|
35
40
|
}
|
|
36
41
|
if (index < 0) return false;
|
|
37
|
-
|
|
42
|
+
// #3727: `annotate` — { targets: [{ key, label, quote(file) }], notice(text) } — only from a chat that can quote.
|
|
43
|
+
lightboxStore.set({ open: { items, index, opener: clicked, seq: ++seq, annotate: annotate && annotate.targets?.length ? annotate : null } });
|
|
38
44
|
return true;
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
@@ -57,10 +63,10 @@ export function LightboxHost({ owner } = {}) {
|
|
|
57
63
|
if (!owner) closeLightbox();
|
|
58
64
|
else if (owned.current !== null) closeLightbox(owned.current);
|
|
59
65
|
}, []);
|
|
60
|
-
return open && mine ? html`<${ImageLightbox} key=${open.seq} items=${open.items} index=${open.index} opener=${open.opener} onClose=${() => closeLightbox(open.seq)} />` : null;
|
|
66
|
+
return open && mine ? html`<${ImageLightbox} key=${open.seq} items=${open.items} index=${open.index} opener=${open.opener} annotate=${open.annotate} onClose=${() => closeLightbox(open.seq)} />` : null;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
function ImageLightbox({ items, index, opener, onClose }) {
|
|
69
|
+
function ImageLightbox({ items, index, opener, annotate = null, onClose }) {
|
|
64
70
|
const [at, setAt] = useState(index);
|
|
65
71
|
const ref = useRef(null);
|
|
66
72
|
const close = useRef(null);
|
|
@@ -70,6 +76,13 @@ function ImageLightbox({ items, index, opener, onClose }) {
|
|
|
70
76
|
const [level, setLevel] = useState(null); // { scale, fit, mode } once the picture has loaded
|
|
71
77
|
const item = items[at] || items[0];
|
|
72
78
|
const many = items.length > 1;
|
|
79
|
+
// #3727: the editor's component once 「標註」 has loaded it; while it shows, the viewer's own keys stand aside.
|
|
80
|
+
const [Editor, setEditor] = useState(null);
|
|
81
|
+
const editing = !!Editor;
|
|
82
|
+
const startAnnotate = () => {
|
|
83
|
+
loadAnnotate().then((m) => { if (m && m.annotateV1 === true && typeof m.AnnotateEditor === "function") setEditor(() => m.AnnotateEditor); else throw new Error("old module"); })
|
|
84
|
+
.catch(() => annotate?.notice?.(t("lbAnnotate.failed")));
|
|
85
|
+
};
|
|
73
86
|
const step = (d) => setAt((n) => (n + d + items.length) % items.length);
|
|
74
87
|
useLayoutEffect(() => {
|
|
75
88
|
const d = ref.current;
|
|
@@ -113,6 +126,7 @@ function ImageLightbox({ items, index, opener, onClose }) {
|
|
|
113
126
|
// The dark area (the dialog itself, or the stage around the image) closes it; the image and the controls do not.
|
|
114
127
|
const onClick = (e) => { if (e.target === d || (e.target && e.target.classList && e.target.classList.contains("lb-stage"))) onClose(); };
|
|
115
128
|
const onKey = (e) => {
|
|
129
|
+
if (editing) return; // the editor's keys (tools, colours, undo) are its own
|
|
116
130
|
const z = zoom.current;
|
|
117
131
|
if (z && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
118
132
|
const act = { "+": () => z.zoomBy(STEP), "=": () => z.zoomBy(STEP), "-": () => z.zoomBy(1 / STEP), "_": () => z.zoomBy(1 / STEP),
|
|
@@ -127,9 +141,14 @@ function ImageLightbox({ items, index, opener, onClose }) {
|
|
|
127
141
|
d.addEventListener("click", onClick);
|
|
128
142
|
d.addEventListener("keydown", onKey);
|
|
129
143
|
return () => { d.removeEventListener("cancel", onCancel); d.removeEventListener("close", onNativeClose); d.removeEventListener("click", onClick); d.removeEventListener("keydown", onKey); };
|
|
130
|
-
}, [onClose, many, items.length]);
|
|
144
|
+
}, [onClose, many, items.length, editing]);
|
|
131
145
|
const label = item.name ? t("chat.lbLabel", item.name) : t("chat.lbLabelNoName");
|
|
132
146
|
const pct = level ? Math.round(level.scale * 100) : null;
|
|
147
|
+
if (editing) {
|
|
148
|
+
return html`<dialog data-trust="lightbox" ref=${ref} class="lb lb-annotating" role="dialog" aria-modal="true" aria-label=${label}>
|
|
149
|
+
<${Editor} src=${item.src} name=${item.name} targets=${annotate.targets} onClose=${onClose} onError=${(text) => annotate.notice?.(text)} />
|
|
150
|
+
</dialog>`;
|
|
151
|
+
}
|
|
133
152
|
return html`<dialog data-trust="lightbox" ref=${ref} class="lb" role="dialog" aria-modal="true" aria-label=${label}>
|
|
134
153
|
<div class="lb-bar">
|
|
135
154
|
<span class="lb-name" title=${item.name}>${item.name}</span>
|
|
@@ -144,6 +163,7 @@ function ImageLightbox({ items, index, opener, onClose }) {
|
|
|
144
163
|
<button type="button" class=${`icon-btn lb-fit-width${level && level.mode === "width" ? " on" : ""}`} disabled=${!level} aria-pressed=${level && level.mode === "width" ? "true" : "false"}
|
|
145
164
|
aria-label=${t("chat.lbFitWidth")} title=${t("chat.lbFitWidth")} onClick=${() => zoom.current && zoom.current.fitWidth()}><${Icon} name="fitwidth" /></button>
|
|
146
165
|
</span>
|
|
166
|
+
${annotate ? html`<button type="button" class="btn btn-sm lb-annotate" aria-label=${t("lbAnnotate.open")} title=${t("lbAnnotate.open")} onClick=${startAnnotate}><${Icon} name="edit" size=${14} /><span class="lbl">${t("lbAnnotate.open")}</span></button>` : null}
|
|
147
167
|
<a class="btn btn-sm lb-orig" href=${item.src} target="_blank" rel="noopener noreferrer"><${Icon} name="external" size=${14} /><span class="lbl">${t("chat.lbOpenOriginal")}</span></a>
|
|
148
168
|
<button type="button" class="icon-btn lb-close" ref=${close} aria-label=${t("chat.lbClose")} title=${t("chat.lbClose")} onClick=${onClose}><${Icon} name="close" /></button>
|
|
149
169
|
</div>
|