@songsid/agend 2.4.0-beta.2 → 2.4.0-beta.4
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/dist/agent-cli.js +1 -1
- package/dist/agent-endpoint.d.ts +1 -1
- package/dist/agent-endpoint.js +8 -2
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/agent-token-header.d.ts +1 -1
- package/dist/agent-token-header.js +1 -1
- package/dist/auth-api.d.ts +3 -0
- package/dist/auth-api.js +15 -1
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/agy-model-switch.d.ts +22 -0
- package/dist/backend/agy-model-switch.js +62 -0
- package/dist/backend/agy-model-switch.js.map +1 -0
- package/dist/backend/antigravity.js +60 -3
- package/dist/backend/antigravity.js.map +1 -1
- package/dist/backend/cli-runtime-switch.d.ts +71 -0
- package/dist/backend/cli-runtime-switch.js +176 -0
- package/dist/backend/cli-runtime-switch.js.map +1 -0
- package/dist/backend/codex-model-switch.d.ts +41 -0
- package/dist/backend/codex-model-switch.js +170 -0
- package/dist/backend/codex-model-switch.js.map +1 -0
- package/dist/backend/credential-profile.js +1 -1
- package/dist/backend/credential-profile.js.map +1 -1
- package/dist/backend/grok-model-switch.d.ts +16 -0
- package/dist/backend/grok-model-switch.js +45 -0
- package/dist/backend/grok-model-switch.js.map +1 -0
- package/dist/backend/grok.js +1 -1
- package/dist/backend/grok.js.map +1 -1
- package/dist/backend/muse.d.ts +2 -0
- package/dist/backend/muse.js +7 -3
- package/dist/backend/muse.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/channel/mcp-server.js +10 -1
- package/dist/channel/mcp-server.js.map +1 -1
- package/dist/channel/mcp-tools.js +8 -0
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/classic-channel-manager.d.ts +1 -1
- package/dist/classic-channel-manager.js +1 -1
- package/dist/cli-audited.js +12 -12
- package/dist/cli-audited.js.map +1 -1
- package/dist/daemon.d.ts +48 -2
- package/dist/daemon.js +302 -21
- package/dist/daemon.js.map +1 -1
- package/dist/delivery-consumed-watch.js +3 -0
- package/dist/delivery-consumed-watch.js.map +1 -1
- package/dist/event-log.d.ts +1 -1
- package/dist/event-log.js +1 -1
- package/dist/fleet-manager.d.ts +104 -2
- package/dist/fleet-manager.js +665 -27
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +10 -0
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +2 -0
- package/dist/general-knowledge/skills/fleet-health/SKILL.md +18 -0
- package/dist/general-knowledge/skills/hub/SKILL.md +154 -0
- package/dist/general-knowledge/skills/model-discovery/SKILL.md +4 -0
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +17 -3
- package/dist/hub/admin-dashboard.d.ts +85 -0
- package/dist/hub/admin-dashboard.js +161 -0
- package/dist/hub/admin-dashboard.js.map +1 -0
- package/dist/hub/attachments/store.d.ts +2 -0
- package/dist/hub/attachments/store.js +6 -0
- package/dist/hub/attachments/store.js.map +1 -1
- package/dist/hub/client.d.ts +10 -0
- package/dist/hub/client.js +72 -10
- package/dist/hub/client.js.map +1 -1
- package/dist/hub/compose/member.d.ts +20 -0
- package/dist/hub/compose/member.js +212 -17
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/compose/server.d.ts +8 -0
- package/dist/hub/compose/server.js +13 -2
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/display-name.d.ts +10 -0
- package/dist/hub/display-name.js +35 -0
- package/dist/hub/display-name.js.map +1 -0
- package/dist/hub/execution/service.d.ts +1 -0
- package/dist/hub/execution/service.js +1 -1
- package/dist/hub/execution/service.js.map +1 -1
- package/dist/hub/fleet-info.d.ts +12 -0
- package/dist/hub/fleet-info.js +14 -0
- package/dist/hub/fleet-info.js.map +1 -0
- package/dist/hub/fleet-update-model.d.ts +100 -0
- package/dist/hub/fleet-update-model.js +15 -0
- package/dist/hub/fleet-update-model.js.map +1 -0
- package/dist/hub/fleet-updates.d.ts +46 -0
- package/dist/hub/fleet-updates.js +282 -0
- package/dist/hub/fleet-updates.js.map +1 -0
- package/dist/hub/fleet-versions.d.ts +28 -0
- package/dist/hub/fleet-versions.js +80 -0
- package/dist/hub/fleet-versions.js.map +1 -0
- package/dist/hub/http/compose.d.ts +2 -0
- package/dist/hub/http/compose.js +192 -16
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/http/deps.d.ts +1 -0
- package/dist/hub/http/schema.js +13 -1
- package/dist/hub/http/schema.js.map +1 -1
- package/dist/hub/member/display-name.d.ts +9 -0
- package/dist/hub/member/display-name.js +71 -0
- package/dist/hub/member/display-name.js.map +1 -0
- package/dist/hub/member/exposure-api.d.ts +4 -0
- package/dist/hub/member/exposure-api.js +8 -3
- 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 +20 -0
- package/dist/hub/member/exposures.js.map +1 -1
- package/dist/hub/member/pairing-api.js +3 -2
- package/dist/hub/member/pairing-api.js.map +1 -1
- package/dist/hub/member/recommendations.d.ts +37 -0
- package/dist/hub/member/recommendations.js +129 -0
- package/dist/hub/member/recommendations.js.map +1 -0
- package/dist/hub/member/room-ask.d.ts +60 -1
- package/dist/hub/member/room-ask.js +254 -24
- package/dist/hub/member/room-ask.js.map +1 -1
- package/dist/hub/member/room-post-answers.d.ts +52 -0
- package/dist/hub/member/room-post-answers.js +152 -0
- package/dist/hub/member/room-post-answers.js.map +1 -0
- package/dist/hub/member/room-post-receipt.d.ts +21 -0
- package/dist/hub/member/room-post-receipt.js +49 -0
- package/dist/hub/member/room-post-receipt.js.map +1 -0
- package/dist/hub/member/room-post.d.ts +100 -0
- package/dist/hub/member/room-post.js +223 -0
- package/dist/hub/member/room-post.js.map +1 -0
- package/dist/hub/member/updates.d.ts +92 -0
- package/dist/hub/member/updates.js +316 -0
- package/dist/hub/member/updates.js.map +1 -0
- package/dist/hub/protocol.d.ts +658 -1
- package/dist/hub/protocol.js +90 -13
- package/dist/hub/protocol.js.map +1 -1
- package/dist/hub/published-version.d.ts +3 -0
- package/dist/hub/published-version.js +35 -0
- package/dist/hub/published-version.js.map +1 -0
- package/dist/hub/recommendation-model.d.ts +36 -0
- package/dist/hub/recommendation-model.js +9 -0
- package/dist/hub/recommendation-model.js.map +1 -0
- package/dist/hub/recommendations.d.ts +58 -0
- package/dist/hub/recommendations.js +211 -0
- package/dist/hub/recommendations.js.map +1 -0
- package/dist/hub/representative.d.ts +3 -0
- package/dist/hub/representative.js +2 -1
- package/dist/hub/representative.js.map +1 -1
- package/dist/hub/room-context-model.d.ts +43 -0
- package/dist/hub/room-context-model.js +12 -0
- package/dist/hub/room-context-model.js.map +1 -0
- package/dist/hub/rooms/agents.d.ts +41 -9
- package/dist/hub/rooms/agents.js +183 -21
- package/dist/hub/rooms/agents.js.map +1 -1
- package/dist/hub/rooms/assistant.d.ts +1 -6
- package/dist/hub/rooms/assistant.js +7 -2
- package/dist/hub/rooms/assistant.js.map +1 -1
- package/dist/hub/rooms/automation.d.ts +24 -0
- package/dist/hub/rooms/automation.js +66 -0
- package/dist/hub/rooms/automation.js.map +1 -0
- package/dist/hub/rooms/buttons.d.ts +85 -0
- package/dist/hub/rooms/buttons.js +62 -0
- package/dist/hub/rooms/buttons.js.map +1 -0
- package/dist/hub/rooms/context-cursor.d.ts +18 -0
- package/dist/hub/rooms/context-cursor.js +61 -0
- package/dist/hub/rooms/context-cursor.js.map +1 -0
- package/dist/hub/rooms/context.d.ts +1 -1
- package/dist/hub/rooms/context.js +4 -4
- package/dist/hub/rooms/context.js.map +1 -1
- package/dist/hub/rooms/mentions.d.ts +15 -0
- package/dist/hub/rooms/mentions.js +43 -0
- package/dist/hub/rooms/mentions.js.map +1 -0
- package/dist/hub/rooms/post-replies.d.ts +23 -0
- package/dist/hub/rooms/post-replies.js +114 -0
- package/dist/hub/rooms/post-replies.js.map +1 -0
- package/dist/hub/rooms/schema.d.ts +9 -0
- package/dist/hub/rooms/schema.js +43 -0
- package/dist/hub/rooms/schema.js.map +1 -1
- package/dist/hub/rooms/service.d.ts +136 -1
- package/dist/hub/rooms/service.js +727 -18
- package/dist/hub/rooms/service.js.map +1 -1
- package/dist/hub/rooms/types.d.ts +27 -3
- package/dist/hub/rooms.js +1 -1
- package/dist/hub/rooms.js.map +1 -1
- package/dist/hub/runtime.d.ts +1 -1
- package/dist/hub/runtime.js +12 -0
- package/dist/hub/runtime.js.map +1 -1
- package/dist/hub/server.d.ts +6 -1
- package/dist/hub/server.js +75 -5
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/settings-directory-proof.js +22 -1
- package/dist/hub/settings-directory-proof.js.map +1 -1
- package/dist/hub/types.d.ts +133 -2
- package/dist/hub-contact-windows.d.ts +11 -0
- package/dist/hub-contact-windows.js +56 -0
- package/dist/hub-contact-windows.js.map +1 -0
- package/dist/hub-pairing-summary.d.ts +1 -1
- package/dist/hub-room-conversation.d.ts +14 -0
- package/dist/hub-room-conversation.js +60 -0
- package/dist/hub-room-conversation.js.map +1 -0
- package/dist/hub-update-notice.d.ts +12 -0
- package/dist/hub-update-notice.js +35 -0
- package/dist/hub-update-notice.js.map +1 -0
- package/dist/locale.js +58 -2
- package/dist/locale.js.map +1 -1
- package/dist/native-mcp.js +9 -6
- package/dist/native-mcp.js.map +1 -1
- package/dist/outbound-handlers.d.ts +14 -4
- package/dist/outbound-handlers.js +54 -1
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +12 -0
- package/dist/outbound-schemas.js +12 -0
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/pane-port.d.ts +2 -0
- package/dist/queued-handoffs.d.ts +16 -4
- package/dist/queued-handoffs.js +18 -1
- package/dist/queued-handoffs.js.map +1 -1
- package/dist/runtime-cli-install.js +13 -10
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/settings-api.d.ts +1 -0
- package/dist/settings-api.js +87 -0
- package/dist/settings-api.js.map +1 -1
- package/dist/tmux-manager.d.ts +2 -0
- package/dist/tmux-manager.js +2 -0
- package/dist/tmux-manager.js.map +1 -1
- package/dist/tool-permissions.js +3 -0
- package/dist/tool-permissions.js.map +1 -1
- package/dist/ui/chat-msg-actions.js +3 -222
- package/dist/ui/hub-admin-overview.js +189 -0
- package/dist/ui/hub-client.js +36 -4
- package/dist/ui/hub-fleet-versions.js +393 -0
- package/dist/ui/hub-room-agent-strings.js +28 -0
- package/dist/ui/hub-room-composer.js +16 -8
- package/dist/ui/hub-room-members-strings.js +2 -2
- package/dist/ui/hub-room-members.js +3 -2
- package/dist/ui/hub-room-notify.js +161 -0
- package/dist/ui/hub-room-search.js +126 -0
- package/dist/ui/hub-room-strings.js +47 -1
- package/dist/ui/hub-room-thread.js +243 -35
- package/dist/ui/hub-room-unread.js +2 -1
- package/dist/ui/hub-strings.js +8 -0
- package/dist/ui/image-annotate.js +2 -283
- package/dist/ui/image-lightbox.js +2 -176
- package/dist/ui/image-zoom.js +2 -242
- package/dist/ui/notice-hub-update.js +94 -0
- package/dist/ui/panel-chat.js +121 -12
- package/dist/ui/panel-hub.js +133 -19
- package/dist/ui/panel-notices.js +3 -1
- package/dist/ui/panel-settings.js +1 -1
- package/dist/ui/settings-hub-updates.js +67 -0
- package/dist/ui/settings-hub.js +28 -3
- package/dist/ui/settings-registry.js +1 -0
- package/dist/ui/settings-update.js +11 -5
- package/dist/ui/settings-web-authority.js +1 -1
- package/dist/ui/shared/app-i18n.js +2 -0
- package/dist/ui/shared/app-nav.js +6 -2
- package/dist/ui/shared/app-prefs.js +2 -1
- package/dist/ui/shared/app-shell.js +29 -4
- package/dist/ui/shared/app-update.js +90 -8
- package/dist/ui/shared/app.css +33 -0
- package/dist/ui/shared/chat-composer.js +6 -3
- package/dist/ui/shared/chat-msg-actions.js +225 -0
- package/dist/ui/shared/chat-thread.js +70 -5
- package/dist/ui/shared/chat-work-bar.css +48 -0
- package/dist/ui/shared/hub-chat.css +16 -2
- package/dist/ui/shared/hub-owner.css +104 -0
- package/dist/ui/shared/hub-rooms-u2.css +16 -0
- package/dist/ui/shared/hub.css +5 -0
- package/dist/ui/shared/image-annotate.js +306 -0
- package/dist/ui/shared/image-lightbox.js +183 -0
- package/dist/ui/shared/image-zoom.js +242 -0
- package/dist/ui/shared/instance-nav.js +36 -7
- package/dist/ui/shared/model-picker.css +4 -3
- package/dist/ui/shared/view-strings.js +8 -0
- package/dist/ui/shared/web-authorize.js +2 -2
- package/dist/update-dispatch.d.ts +8 -1
- package/dist/update-dispatch.js +16 -1
- package/dist/update-dispatch.js.map +1 -1
- package/dist/update-idle.d.ts +65 -0
- package/dist/update-idle.js +190 -0
- package/dist/update-idle.js.map +1 -0
- package/dist/update-launch.d.ts +1 -1
- package/dist/update-launch.js +9 -2
- package/dist/update-launch.js.map +1 -1
- package/dist/usage/i18n-keys.d.ts +1 -1
- package/dist/usage/i18n-keys.js +1 -1
- package/dist/usage/i18n-keys.js.map +1 -1
- package/dist/usage/profile-timeline.d.ts +2 -0
- package/dist/usage/profile-timeline.js +4 -0
- package/dist/usage/profile-timeline.js.map +1 -1
- package/dist/usage/providers.js +4 -4
- package/dist/usage/providers.js.map +1 -1
- package/dist/usage/quota-history.d.ts +1 -1
- package/dist/view-api.js +1 -1
- package/dist/view-api.js.map +1 -1
- package/dist/web-api.js +19 -2
- package/dist/web-api.js.map +1 -1
- package/dist/web-notices.d.ts +3 -0
- package/dist/web-notices.js +17 -2
- package/dist/web-notices.js.map +1 -1
- package/dist/web-prefs.js +1 -0
- package/dist/web-prefs.js.map +1 -1
- package/dist/web-update.d.ts +15 -1
- package/package.json +1 -1
|
@@ -1,283 +1,2 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
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
|
-
}
|
|
1
|
+
// M-3125 PR3: moved to /assets/ (shared with the Hub's rooms); this old path re-exports it for tabs opened before.
|
|
2
|
+
export * from "/assets/image-annotate.js";
|
|
@@ -1,176 +1,2 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
// new tab (the thumbnail's link, unchanged: a ctrl-, meta-, shift- or middle-click on it still does what the browser
|
|
4
|
-
// does). Several images in one message: previous / next, and the arrow keys.
|
|
5
|
-
//
|
|
6
|
-
// The native <dialog> opened with showModal(): the browser traps focus and makes the rest inert. No style attribute
|
|
7
|
-
// (#1300): classes only. Only a file URL the chat itself rendered (/ui/file/<32 hex>) is ever shown.
|
|
8
|
-
//
|
|
9
|
-
// #2333: zoom and pan (image-zoom.js). The toolbar has −, the level (it toggles fit ↔ 100%), + and Fit width; the keys
|
|
10
|
-
// + / − / 0 (fit) / 1 (100%) / W (fit width). Each image opens fitted; stepping to another fits it again.
|
|
11
|
-
import { html, useEffect, useLayoutEffect, useRef, useState } from "/assets/app-html.js";
|
|
12
|
-
import { register, t } from "/assets/app-i18n.js";
|
|
13
|
-
import { createStore, useStore } from "/assets/app-store.js";
|
|
14
|
-
import { Icon } from "/assets/ui-icons.js";
|
|
15
|
-
import { createZoom, STEP } from "./image-zoom.js";
|
|
16
|
-
|
|
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");
|
|
23
|
-
/** What is shown: { items: [{ src, name }], index, opener } or null. One per page; the chat that shows it owns it. */
|
|
24
|
-
export const lightboxStore = createStore({ open: null });
|
|
25
|
-
let seq = 0;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The images of a message, from its thumbnails' links; `index` the one clicked. Anything that is not a chat file URL
|
|
29
|
-
* is left out (and nothing opens if the clicked one is not).
|
|
30
|
-
*/
|
|
31
|
-
export function openLightbox(links, clicked, annotate = null) {
|
|
32
|
-
const items = [];
|
|
33
|
-
let index = -1;
|
|
34
|
-
for (const a of links) {
|
|
35
|
-
const src = a.getAttribute("href") || "";
|
|
36
|
-
if (!FILE_URL.test(src)) continue;
|
|
37
|
-
if (a === clicked) index = items.length;
|
|
38
|
-
const img = a.querySelector("img");
|
|
39
|
-
items.push({ src, name: (img && img.getAttribute("alt")) || "" });
|
|
40
|
-
}
|
|
41
|
-
if (index < 0) return false;
|
|
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 } });
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Close it — the one way every close goes: ✕, the dark area, Esc, the dialog's own close (the browser's, a form with
|
|
48
|
-
* method=dialog), the chat leaving. The store is the truth; unmounting the dialog is the one cleanup (scroll unlocked,
|
|
49
|
-
* focus back on the thumbnail). `seq`: only that lightbox — a late close of one already replaced closes nothing.
|
|
50
|
-
*/
|
|
51
|
-
export function closeLightbox(seq) {
|
|
52
|
-
const open = lightboxStore.get().open;
|
|
53
|
-
if (open && (seq === undefined || open.seq === seq)) lightboxStore.set({ open: null });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Rendered by the chat; gone with it (another instance, another panel). */
|
|
57
|
-
export function LightboxHost({ owner } = {}) {
|
|
58
|
-
const { open } = useStore(lightboxStore);
|
|
59
|
-
const owned = useRef(null);
|
|
60
|
-
const mine = !owner || owner.current?.contains(open?.opener);
|
|
61
|
-
if (open && mine) owned.current = open.seq;
|
|
62
|
-
useEffect(() => () => {
|
|
63
|
-
if (!owner) closeLightbox();
|
|
64
|
-
else if (owned.current !== null) closeLightbox(owned.current);
|
|
65
|
-
}, []);
|
|
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;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function ImageLightbox({ items, index, opener, annotate = null, onClose }) {
|
|
70
|
-
const [at, setAt] = useState(index);
|
|
71
|
-
const ref = useRef(null);
|
|
72
|
-
const close = useRef(null);
|
|
73
|
-
const stage = useRef(null);
|
|
74
|
-
const img = useRef(null);
|
|
75
|
-
const zoom = useRef(null);
|
|
76
|
-
const [level, setLevel] = useState(null); // { scale, fit, mode } once the picture has loaded
|
|
77
|
-
const item = items[at] || items[0];
|
|
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
|
-
};
|
|
86
|
-
const step = (d) => setAt((n) => (n + d + items.length) % items.length);
|
|
87
|
-
useLayoutEffect(() => {
|
|
88
|
-
const d = ref.current;
|
|
89
|
-
const root = typeof document !== "undefined" ? document.documentElement : null;
|
|
90
|
-
if (root) root.classList.add("lb-open"); // the chat behind it does not scroll
|
|
91
|
-
if (d && typeof d.showModal === "function" && !d.open) d.showModal();
|
|
92
|
-
if (close.current && typeof close.current.focus === "function") close.current.focus();
|
|
93
|
-
return () => {
|
|
94
|
-
if (root) root.classList.remove("lb-open");
|
|
95
|
-
if (d && d.open && typeof d.close === "function") d.close();
|
|
96
|
-
if (opener && typeof opener.focus === "function" && document.contains?.(opener)) opener.focus();
|
|
97
|
-
};
|
|
98
|
-
}, []);
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
if (!stage.current || !img.current) return undefined;
|
|
101
|
-
const z = createZoom({ stage: stage.current, img: img.current, onChange: setLevel });
|
|
102
|
-
zoom.current = z;
|
|
103
|
-
return () => { z.destroy(); zoom.current = null; };
|
|
104
|
-
}, []);
|
|
105
|
-
// Another image: hidden until it has loaded and been fitted (its load resets the zoom). A layout effect — in the same
|
|
106
|
-
// commit that set the new src, before any load can arrive: a picture already in the cache (every thumbnail above it
|
|
107
|
-
// has loaded) fires its load before a passive effect would run, and such an effect then hid it for good with the
|
|
108
|
-
// level at "…" (the report on beta.24: Next "flashes once, then the next image is not visible"). A picture that is
|
|
109
|
-
// already complete here (the same file again: no load comes) is fitted at once.
|
|
110
|
-
const first = useRef(true);
|
|
111
|
-
useLayoutEffect(() => {
|
|
112
|
-
if (first.current) { first.current = false; return; }
|
|
113
|
-
const el = img.current;
|
|
114
|
-
if (el) el.classList.remove("lb-ready");
|
|
115
|
-
setLevel(null);
|
|
116
|
-
if (el && el.complete && el.naturalWidth > 0 && zoom.current) zoom.current.reset();
|
|
117
|
-
}, [at]);
|
|
118
|
-
useEffect(() => {
|
|
119
|
-
const d = ref.current;
|
|
120
|
-
if (!d) return undefined;
|
|
121
|
-
// Esc: the browser fires "cancel"; closing goes through the store so its state stays the truth.
|
|
122
|
-
const onCancel = (e) => { e.preventDefault(); onClose(); };
|
|
123
|
-
// The dialog closed by itself — the browser (a close request it did not ask about) or a form with method=dialog:
|
|
124
|
-
// the same close as every other, so the store and the cleanup follow (#1558 review).
|
|
125
|
-
const onNativeClose = () => onClose();
|
|
126
|
-
// The dark area (the dialog itself, or the stage around the image) closes it; the image and the controls do not.
|
|
127
|
-
const onClick = (e) => { if (e.target === d || (e.target && e.target.classList && e.target.classList.contains("lb-stage"))) onClose(); };
|
|
128
|
-
const onKey = (e) => {
|
|
129
|
-
if (editing) return; // the editor's keys (tools, colours, undo) are its own
|
|
130
|
-
const z = zoom.current;
|
|
131
|
-
if (z && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
132
|
-
const act = { "+": () => z.zoomBy(STEP), "=": () => z.zoomBy(STEP), "-": () => z.zoomBy(1 / STEP), "_": () => z.zoomBy(1 / STEP),
|
|
133
|
-
"0": () => z.fit(), "1": () => z.actual(), w: () => z.fitWidth(), W: () => z.fitWidth() }[e.key];
|
|
134
|
-
if (act) { e.preventDefault(); act(); return; }
|
|
135
|
-
}
|
|
136
|
-
if (!many) return;
|
|
137
|
-
if (e.key === "ArrowRight") { e.preventDefault(); step(1); } else if (e.key === "ArrowLeft") { e.preventDefault(); step(-1); }
|
|
138
|
-
};
|
|
139
|
-
d.addEventListener("cancel", onCancel);
|
|
140
|
-
d.addEventListener("close", onNativeClose);
|
|
141
|
-
d.addEventListener("click", onClick);
|
|
142
|
-
d.addEventListener("keydown", onKey);
|
|
143
|
-
return () => { d.removeEventListener("cancel", onCancel); d.removeEventListener("close", onNativeClose); d.removeEventListener("click", onClick); d.removeEventListener("keydown", onKey); };
|
|
144
|
-
}, [onClose, many, items.length, editing]);
|
|
145
|
-
const label = item.name ? t("chat.lbLabel", item.name) : t("chat.lbLabelNoName");
|
|
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
|
-
}
|
|
152
|
-
return html`<dialog data-trust="lightbox" ref=${ref} class="lb" role="dialog" aria-modal="true" aria-label=${label}>
|
|
153
|
-
<div class="lb-bar">
|
|
154
|
-
<span class="lb-name" title=${item.name}>${item.name}</span>
|
|
155
|
-
${many ? html`<span class="lb-count">${t("chat.lbCount", at + 1, items.length)}</span>` : null}
|
|
156
|
-
<span class="lb-zoom" role="group">
|
|
157
|
-
<button type="button" class="icon-btn lb-zoom-out" disabled=${!level} aria-label=${t("chat.lbZoomOut")} title=${t("chat.lbZoomOut")}
|
|
158
|
-
onClick=${() => zoom.current && zoom.current.zoomBy(1 / STEP)}><${Icon} name="minus" /></button>
|
|
159
|
-
<button type="button" class="btn btn-sm lb-level" disabled=${!level} aria-label=${t("chat.lbZoomLevel", pct ?? "")} title=${t("chat.lbZoomLevel", pct ?? "")}
|
|
160
|
-
onClick=${() => zoom.current && zoom.current.toggle()}>${pct === null ? "…" : `${pct}%`}</button>
|
|
161
|
-
<button type="button" class="icon-btn lb-zoom-in" disabled=${!level} aria-label=${t("chat.lbZoomIn")} title=${t("chat.lbZoomIn")}
|
|
162
|
-
onClick=${() => zoom.current && zoom.current.zoomBy(STEP)}><${Icon} name="plus" /></button>
|
|
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"}
|
|
164
|
-
aria-label=${t("chat.lbFitWidth")} title=${t("chat.lbFitWidth")} onClick=${() => zoom.current && zoom.current.fitWidth()}><${Icon} name="fitwidth" /></button>
|
|
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}
|
|
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>
|
|
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>
|
|
169
|
-
</div>
|
|
170
|
-
<div class="lb-stage" ref=${stage}><img class="lb-img" ref=${img} src=${item.src} alt=${item.name} draggable=${false} /></div>
|
|
171
|
-
${many ? html`<button type="button" class="icon-btn lb-nav lb-prev" aria-label=${t("chat.lbPrev")} title=${t("chat.lbPrev")} onClick=${() => step(-1)}><${Icon} name="back" /></button>
|
|
172
|
-
<button type="button" class="icon-btn lb-nav lb-next" aria-label=${t("chat.lbNext")} title=${t("chat.lbNext")} onClick=${() => step(1)}><${Icon} name="forward" /></button>` : null}
|
|
173
|
-
</dialog>`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
LightboxHost.paneOwner = true;
|
|
1
|
+
// M-3125 PR3: moved to /assets/ (shared with the Hub's rooms); this old path re-exports it for tabs opened before.
|
|
2
|
+
export * from "/assets/image-lightbox.js";
|