@celljs/ta-web 4.9.0 → 4.10.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.en.md +4 -3
- package/README.md +4 -3
- package/esm/browser/assistant/assistant-chat-list.js +8 -2
- package/esm/browser/assistant/assistant-extension.d.ts +8 -1
- package/esm/browser/assistant/assistant-extension.js +33 -5
- package/esm/browser/assistant/assistant-protocol.d.ts +3 -1
- package/esm/browser/assistant/assistant-task-source.d.ts +2 -0
- package/esm/browser/assistant/assistant-task-source.js +2 -0
- package/esm/browser/assistant/assistant-task-util.d.ts +8 -0
- package/esm/browser/assistant/assistant-task-util.js +13 -3
- package/esm/browser/assistant/assistant-tasks.js +3 -2
- package/esm/browser/assistant/assistant-view.js +81 -56
- package/esm/browser/assistant/assistant.d.ts +30 -1
- package/esm/browser/assistant/assistant.js +89 -6
- package/esm/browser/assistant/task-views.d.ts +40 -6
- package/esm/browser/assistant/task-views.js +73 -21
- package/esm/browser/avatar/dino-avatar.d.ts +3 -4
- package/esm/browser/avatar/dino-avatar.js +4 -178
- package/esm/browser/avatar/dino-face.d.ts +19 -0
- package/esm/browser/avatar/dino-face.js +142 -0
- package/esm/browser/avatar/dino-geometry.d.ts +11 -0
- package/esm/browser/avatar/dino-geometry.js +38 -0
- package/esm/browser/avatar/dino-kinds.d.ts +15 -0
- package/esm/browser/avatar/dino-kinds.js +544 -0
- package/esm/browser/avatar/dino-motion.js +1 -1
- package/esm/browser/avatar/dino-shape.d.ts +80 -0
- package/esm/browser/avatar/dino-shape.js +113 -0
- package/esm/browser/avatar/dino-species.d.ts +1 -61
- package/esm/browser/avatar/dino-species.js +2 -653
- package/esm/browser/chat/chat-packages.d.ts +39 -0
- package/esm/browser/chat/chat-packages.js +70 -0
- package/esm/browser/chat/chat-protocol.d.ts +23 -1
- package/esm/browser/chat/chat-stores.d.ts +59 -0
- package/esm/browser/chat/chat-stores.js +121 -0
- package/esm/browser/chat/chat-util.d.ts +17 -0
- package/esm/browser/chat/chat-util.js +61 -0
- package/esm/browser/chat/chat-view.js +33 -12
- package/esm/browser/chat/chat.d.ts +31 -39
- package/esm/browser/chat/chat.js +226 -175
- package/esm/browser/components/access-view.js +1 -1
- package/esm/browser/components/account-menu.js +1 -1
- package/esm/browser/components/app-nav.d.ts +6 -3
- package/esm/browser/components/app-nav.js +19 -10
- package/esm/browser/components/app-shell-hooks.d.ts +47 -0
- package/esm/browser/components/app-shell-hooks.js +169 -0
- package/esm/browser/components/app-view.js +81 -172
- package/esm/browser/components/auth-view.js +1 -1
- package/esm/browser/components/chat-list.d.ts +20 -2
- package/esm/browser/components/chat-list.js +138 -22
- package/esm/browser/components/composer-box.d.ts +5 -5
- package/esm/browser/components/composer-box.js +111 -4
- package/esm/browser/components/composer.d.ts +7 -0
- package/esm/browser/components/composer.js +22 -14
- package/esm/browser/components/connection-bar.js +50 -17
- package/esm/browser/components/context-menu.d.ts +30 -4
- package/esm/browser/components/context-menu.js +199 -37
- package/esm/browser/components/conversation-scroll.d.ts +129 -6
- package/esm/browser/components/conversation-scroll.js +429 -109
- package/esm/browser/components/dino.js +1 -1
- package/esm/browser/components/earlier-messages.d.ts +2 -1
- package/esm/browser/components/earlier-messages.js +2 -17
- package/esm/browser/components/editor-area.d.ts +3 -1
- package/esm/browser/components/editor-area.js +6 -5
- package/esm/browser/components/empty-pictures.d.ts +0 -2
- package/esm/browser/components/empty-pictures.js +0 -16
- package/esm/browser/components/folder-picker.d.ts +5 -2
- package/esm/browser/components/folder-picker.js +30 -9
- package/esm/browser/components/held-talk.d.ts +28 -0
- package/esm/browser/components/held-talk.js +76 -0
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/host-view.js +1 -1
- package/esm/browser/components/icon.d.ts +2 -2
- package/esm/browser/components/icon.js +5 -6
- package/esm/browser/components/image-viewer.d.ts +124 -0
- package/esm/browser/components/image-viewer.js +397 -0
- package/esm/browser/components/lightbox.d.ts +11 -0
- package/esm/browser/components/lightbox.js +24 -0
- package/esm/browser/components/markdown.d.ts +6 -2
- package/esm/browser/components/markdown.js +24 -10
- package/esm/browser/components/media.js +1 -10
- package/esm/browser/components/message-footer.d.ts +16 -2
- package/esm/browser/components/message-footer.js +29 -12
- package/esm/browser/components/message-list.d.ts +24 -3
- package/esm/browser/components/message-list.js +149 -20
- package/esm/browser/components/message-menu.d.ts +3 -1
- package/esm/browser/components/message-menu.js +18 -3
- package/esm/browser/components/nav-places.d.ts +16 -1
- package/esm/browser/components/nav-places.js +12 -3
- package/esm/browser/components/phone-shell.d.ts +4 -1
- package/esm/browser/components/phone-shell.js +3 -1
- package/esm/browser/components/run-status.js +3 -3
- package/esm/browser/components/select-bar.d.ts +9 -0
- package/esm/browser/components/select-bar.js +24 -0
- package/esm/browser/components/session-settings.d.ts +6 -0
- package/esm/browser/components/session-settings.js +14 -1
- package/esm/browser/components/session-view.js +8 -4
- package/esm/browser/components/settings-choices.d.ts +35 -0
- package/esm/browser/components/settings-choices.js +117 -0
- package/esm/browser/components/settings-parts.d.ts +21 -0
- package/esm/browser/components/settings-parts.js +323 -0
- package/esm/browser/components/settings-view.d.ts +0 -6
- package/esm/browser/components/settings-view.js +4 -406
- package/esm/browser/components/swipe-row.d.ts +2 -2
- package/esm/browser/components/swipe-row.js +7 -3
- package/esm/browser/components/tool-view.js +14 -12
- package/esm/browser/components/voice-button.d.ts +1 -1
- package/esm/browser/components/voice-button.js +1 -1
- package/esm/browser/components/voice-talk.d.ts +43 -0
- package/esm/browser/components/voice-talk.js +222 -0
- package/esm/browser/components/workbench-view.js +1 -1
- package/esm/browser/device/device.d.ts +3 -0
- package/esm/browser/device/device.js +11 -1
- package/esm/browser/device/hold.d.ts +42 -0
- package/esm/browser/device/hold.js +136 -0
- package/esm/browser/device/launch-screen.d.ts +1 -1
- package/esm/browser/device/launch-screen.js +1 -1
- package/esm/browser/device/long-press.d.ts +2 -0
- package/esm/browser/device/long-press.js +16 -1
- package/esm/browser/device/pull-down.d.ts +4 -2
- package/esm/browser/device/pull-down.js +64 -76
- package/esm/browser/device/row-swipe.d.ts +35 -10
- package/esm/browser/device/row-swipe.js +149 -71
- package/esm/browser/device/shake-undo.d.ts +16 -0
- package/esm/browser/device/shake-undo.js +59 -0
- package/esm/browser/device/sheet-swipe.d.ts +118 -18
- package/esm/browser/device/sheet-swipe.js +406 -107
- package/esm/browser/extension/icons.js +2 -1
- package/esm/browser/extension/web-extension-api.d.ts +135 -2
- package/esm/browser/extension/web-extension-code.d.ts +6 -0
- package/esm/browser/extension/web-extension-code.js +24 -0
- package/esm/browser/extension/web-extension-protocol.d.ts +23 -1
- package/esm/browser/extension/web-extension-protocol.js +8 -0
- package/esm/browser/extension/web-extensions.d.ts +14 -1
- package/esm/browser/extension/web-extensions.js +128 -24
- package/esm/browser/extension/web-tasks.d.ts +9 -1
- package/esm/browser/extension/web-tasks.js +24 -0
- package/esm/browser/files/files-protocol.d.ts +25 -0
- package/esm/browser/files/files-protocol.js +2 -0
- package/esm/browser/files/files.d.ts +35 -0
- package/esm/browser/files/files.js +119 -0
- package/esm/browser/hooks.d.ts +3 -1
- package/esm/browser/hooks.js +8 -0
- package/esm/browser/i18n/locales.d.ts +29 -2
- package/esm/browser/i18n/messages.d.ts +28 -1
- package/esm/browser/i18n/messages.js +58 -4
- package/esm/browser/index.d.ts +6 -0
- package/esm/browser/index.js +6 -0
- package/esm/browser/notices/notices-protocol.d.ts +9 -1
- package/esm/browser/notices/notices.d.ts +2 -0
- package/esm/browser/notices/notices.js +20 -10
- package/esm/browser/offline/device-values.d.ts +55 -0
- package/esm/browser/offline/device-values.js +142 -0
- package/esm/browser/offline/kept-chats-protocol.d.ts +17 -0
- package/esm/browser/offline/kept-chats-protocol.js +2 -0
- package/esm/browser/offline/kept-chats.d.ts +47 -0
- package/esm/browser/offline/kept-chats.js +146 -0
- package/esm/browser/offline/offline-reads.d.ts +44 -0
- package/esm/browser/offline/offline-reads.js +107 -0
- package/esm/browser/settings/settings-protocol.d.ts +2 -0
- package/esm/browser/settings/settings-protocol.js +2 -0
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +57 -17
- package/esm/browser/style/device.js +43 -4
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +67 -15
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +2 -1
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +47 -3
- package/esm/browser/style/tasks.d.ts +1 -1
- package/esm/browser/style/tasks.js +2 -0
- package/esm/browser/util/frame.d.ts +5 -4
- package/esm/browser/util/frame.js +5 -4
- package/esm/browser/util/markdown.d.ts +18 -1
- package/esm/browser/util/markdown.js +119 -5
- package/esm/browser/util/process.d.ts +21 -0
- package/esm/browser/util/process.js +45 -1
- package/esm/browser/util/voice.d.ts +5 -2
- package/esm/browser/util/voice.js +6 -3
- package/esm/browser/util/zoom.d.ts +46 -0
- package/esm/browser/util/zoom.js +96 -0
- package/esm/browser/workbench-calls.d.ts +59 -0
- package/esm/browser/workbench-calls.js +141 -0
- package/esm/browser/workbench-protocol.d.ts +5 -1
- package/esm/browser/workbench-util.d.ts +68 -0
- package/esm/browser/workbench-util.js +145 -0
- package/esm/browser/workbench.d.ts +15 -42
- package/esm/browser/workbench.js +53 -167
- package/lib/browser/assistant/assistant-chat-list.js +8 -2
- package/lib/browser/assistant/assistant-extension.d.ts +8 -1
- package/lib/browser/assistant/assistant-extension.js +33 -5
- package/lib/browser/assistant/assistant-protocol.d.ts +3 -1
- package/lib/browser/assistant/assistant-task-source.d.ts +2 -0
- package/lib/browser/assistant/assistant-task-source.js +2 -0
- package/lib/browser/assistant/assistant-task-util.d.ts +8 -0
- package/lib/browser/assistant/assistant-task-util.js +13 -3
- package/lib/browser/assistant/assistant-tasks.js +2 -1
- package/lib/browser/assistant/assistant-view.js +78 -53
- package/lib/browser/assistant/assistant.d.ts +30 -1
- package/lib/browser/assistant/assistant.js +89 -6
- package/lib/browser/assistant/task-views.d.ts +40 -6
- package/lib/browser/assistant/task-views.js +74 -21
- package/lib/browser/avatar/dino-avatar.d.ts +3 -4
- package/lib/browser/avatar/dino-avatar.js +27 -202
- package/lib/browser/avatar/dino-face.d.ts +20 -0
- package/lib/browser/avatar/dino-face.js +148 -0
- package/lib/browser/avatar/dino-geometry.d.ts +12 -0
- package/lib/browser/avatar/dino-geometry.js +47 -0
- package/lib/browser/avatar/dino-kinds.d.ts +16 -0
- package/lib/browser/avatar/dino-kinds.js +547 -0
- package/lib/browser/avatar/dino-motion.js +2 -2
- package/lib/browser/avatar/dino-shape.d.ts +81 -0
- package/lib/browser/avatar/dino-shape.js +126 -0
- package/lib/browser/avatar/dino-species.d.ts +1 -61
- package/lib/browser/avatar/dino-species.js +34 -687
- package/lib/browser/chat/chat-packages.d.ts +40 -0
- package/lib/browser/chat/chat-packages.js +74 -0
- package/lib/browser/chat/chat-protocol.d.ts +23 -1
- package/lib/browser/chat/chat-stores.d.ts +60 -0
- package/lib/browser/chat/chat-stores.js +125 -0
- package/lib/browser/chat/chat-util.d.ts +18 -0
- package/lib/browser/chat/chat-util.js +64 -0
- package/lib/browser/chat/chat-view.js +33 -12
- package/lib/browser/chat/chat.d.ts +31 -39
- package/lib/browser/chat/chat.js +227 -176
- package/lib/browser/components/access-view.js +2 -2
- package/lib/browser/components/account-menu.js +2 -2
- package/lib/browser/components/app-nav.d.ts +6 -3
- package/lib/browser/components/app-nav.js +17 -8
- package/lib/browser/components/app-shell-hooks.d.ts +48 -0
- package/lib/browser/components/app-shell-hooks.js +211 -0
- package/lib/browser/components/app-view.js +89 -180
- package/lib/browser/components/auth-view.js +3 -3
- package/lib/browser/components/chat-list.d.ts +20 -2
- package/lib/browser/components/chat-list.js +137 -21
- package/lib/browser/components/composer-box.d.ts +5 -5
- package/lib/browser/components/composer-box.js +111 -4
- package/lib/browser/components/composer.d.ts +7 -0
- package/lib/browser/components/composer.js +22 -14
- package/lib/browser/components/connection-bar.js +48 -15
- package/lib/browser/components/context-menu.d.ts +30 -4
- package/lib/browser/components/context-menu.js +198 -36
- package/lib/browser/components/conversation-scroll.d.ts +129 -6
- package/lib/browser/components/conversation-scroll.js +431 -110
- package/lib/browser/components/dino.js +3 -3
- package/lib/browser/components/earlier-messages.d.ts +2 -1
- package/lib/browser/components/earlier-messages.js +2 -17
- package/lib/browser/components/editor-area.d.ts +3 -1
- package/lib/browser/components/editor-area.js +5 -4
- package/lib/browser/components/empty-pictures.d.ts +0 -2
- package/lib/browser/components/empty-pictures.js +0 -17
- package/lib/browser/components/folder-picker.d.ts +5 -2
- package/lib/browser/components/folder-picker.js +30 -9
- package/lib/browser/components/held-talk.d.ts +29 -0
- package/lib/browser/components/held-talk.js +79 -0
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/host-view.js +5 -5
- package/lib/browser/components/icon.d.ts +2 -2
- package/lib/browser/components/icon.js +7 -6
- package/lib/browser/components/image-viewer.d.ts +125 -0
- package/lib/browser/components/image-viewer.js +435 -0
- package/lib/browser/components/lightbox.d.ts +12 -0
- package/lib/browser/components/lightbox.js +60 -0
- package/lib/browser/components/markdown.d.ts +6 -2
- package/lib/browser/components/markdown.js +24 -10
- package/lib/browser/components/media.js +2 -11
- package/lib/browser/components/message-footer.d.ts +16 -2
- package/lib/browser/components/message-footer.js +31 -12
- package/lib/browser/components/message-list.d.ts +24 -3
- package/lib/browser/components/message-list.js +146 -16
- package/lib/browser/components/message-menu.d.ts +3 -1
- package/lib/browser/components/message-menu.js +17 -2
- package/lib/browser/components/nav-places.d.ts +16 -1
- package/lib/browser/components/nav-places.js +13 -3
- package/lib/browser/components/phone-shell.d.ts +4 -1
- package/lib/browser/components/phone-shell.js +3 -1
- package/lib/browser/components/run-status.js +3 -3
- package/lib/browser/components/select-bar.d.ts +10 -0
- package/lib/browser/components/select-bar.js +61 -0
- package/lib/browser/components/session-settings.d.ts +6 -0
- package/lib/browser/components/session-settings.js +14 -1
- package/lib/browser/components/session-view.js +7 -3
- package/lib/browser/components/settings-choices.d.ts +36 -0
- package/lib/browser/components/settings-choices.js +156 -0
- package/lib/browser/components/settings-parts.d.ts +22 -0
- package/lib/browser/components/settings-parts.js +359 -0
- package/lib/browser/components/settings-view.d.ts +0 -6
- package/lib/browser/components/settings-view.js +2 -405
- package/lib/browser/components/swipe-row.d.ts +2 -2
- package/lib/browser/components/swipe-row.js +7 -3
- package/lib/browser/components/tool-view.js +14 -12
- package/lib/browser/components/voice-button.d.ts +1 -1
- package/lib/browser/components/voice-button.js +1 -1
- package/lib/browser/components/voice-talk.d.ts +44 -0
- package/lib/browser/components/voice-talk.js +260 -0
- package/lib/browser/components/workbench-view.js +3 -3
- package/lib/browser/device/device.d.ts +3 -0
- package/lib/browser/device/device.js +11 -1
- package/lib/browser/device/hold.d.ts +43 -0
- package/lib/browser/device/hold.js +173 -0
- package/lib/browser/device/launch-screen.d.ts +1 -1
- package/lib/browser/device/launch-screen.js +1 -1
- package/lib/browser/device/long-press.d.ts +2 -0
- package/lib/browser/device/long-press.js +16 -1
- package/lib/browser/device/pull-down.d.ts +4 -2
- package/lib/browser/device/pull-down.js +63 -75
- package/lib/browser/device/row-swipe.d.ts +35 -10
- package/lib/browser/device/row-swipe.js +148 -70
- package/lib/browser/device/shake-undo.d.ts +17 -0
- package/lib/browser/device/shake-undo.js +63 -0
- package/lib/browser/device/sheet-swipe.d.ts +118 -18
- package/lib/browser/device/sheet-swipe.js +410 -108
- package/lib/browser/extension/icons.js +1 -0
- package/lib/browser/extension/web-extension-api.d.ts +135 -2
- package/lib/browser/extension/web-extension-code.d.ts +6 -0
- package/lib/browser/extension/web-extension-code.js +24 -0
- package/lib/browser/extension/web-extension-protocol.d.ts +23 -1
- package/lib/browser/extension/web-extension-protocol.js +9 -1
- package/lib/browser/extension/web-extensions.d.ts +14 -1
- package/lib/browser/extension/web-extensions.js +125 -21
- package/lib/browser/extension/web-tasks.d.ts +9 -1
- package/lib/browser/extension/web-tasks.js +24 -0
- package/lib/browser/files/files-protocol.d.ts +26 -0
- package/lib/browser/files/files-protocol.js +5 -0
- package/lib/browser/files/files.d.ts +36 -0
- package/lib/browser/files/files.js +122 -0
- package/lib/browser/hooks.d.ts +3 -1
- package/lib/browser/hooks.js +9 -0
- package/lib/browser/i18n/locales.d.ts +29 -2
- package/lib/browser/i18n/messages.d.ts +28 -1
- package/lib/browser/i18n/messages.js +58 -4
- package/lib/browser/index.d.ts +6 -0
- package/lib/browser/index.js +6 -0
- package/lib/browser/notices/notices-protocol.d.ts +9 -1
- package/lib/browser/notices/notices.d.ts +2 -0
- package/lib/browser/notices/notices.js +20 -10
- package/lib/browser/offline/device-values.d.ts +56 -0
- package/lib/browser/offline/device-values.js +148 -0
- package/lib/browser/offline/kept-chats-protocol.d.ts +18 -0
- package/lib/browser/offline/kept-chats-protocol.js +5 -0
- package/lib/browser/offline/kept-chats.d.ts +48 -0
- package/lib/browser/offline/kept-chats.js +149 -0
- package/lib/browser/offline/offline-reads.d.ts +45 -0
- package/lib/browser/offline/offline-reads.js +111 -0
- package/lib/browser/settings/settings-protocol.d.ts +2 -0
- package/lib/browser/settings/settings-protocol.js +2 -0
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +57 -17
- package/lib/browser/style/device.js +43 -4
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +67 -15
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +2 -1
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +47 -3
- package/lib/browser/style/tasks.d.ts +1 -1
- package/lib/browser/style/tasks.js +2 -0
- package/lib/browser/util/frame.d.ts +5 -4
- package/lib/browser/util/frame.js +5 -4
- package/lib/browser/util/markdown.d.ts +18 -1
- package/lib/browser/util/markdown.js +119 -5
- package/lib/browser/util/process.d.ts +21 -0
- package/lib/browser/util/process.js +46 -2
- package/lib/browser/util/voice.d.ts +5 -2
- package/lib/browser/util/voice.js +6 -3
- package/lib/browser/util/zoom.d.ts +47 -0
- package/lib/browser/util/zoom.js +99 -0
- package/lib/browser/workbench-calls.d.ts +60 -0
- package/lib/browser/workbench-calls.js +145 -0
- package/lib/browser/workbench-protocol.d.ts +5 -1
- package/lib/browser/workbench-util.d.ts +69 -0
- package/lib/browser/workbench-util.js +151 -0
- package/lib/browser/workbench.d.ts +15 -42
- package/lib/browser/workbench.js +74 -189
- package/package.json +10 -10
- package/public/launch.svg +46 -42
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { Minus, Plus } from 'lucide-react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useT } from '../i18n/use-t.js';
|
|
4
|
+
import { ZoomUtil } from '../util/zoom.js';
|
|
5
|
+
import { Icon } from './icon.js';
|
|
6
|
+
/** How long a step of the buttons, a double tap, or a pinch let go past the limits takes to get there. */
|
|
7
|
+
const ANIMATE_MS = 200;
|
|
8
|
+
/** Two taps this close in time and place are a double tap. */
|
|
9
|
+
const DOUBLE_TAP_MS = 300;
|
|
10
|
+
const DOUBLE_TAP_PX = 30;
|
|
11
|
+
/** A finger or the mouse that moved less than this taps or clicks. */
|
|
12
|
+
const TAP_PX = 8;
|
|
13
|
+
/**
|
|
14
|
+
* Zooms a picture in a box that scrolls, as the viewers of pictures do: all of it at first, never larger than
|
|
15
|
+
* its own pixels; two fingers pinch it, a trackpad pinches it (a wheel with Ctrl, or Safari's gestures), a
|
|
16
|
+
* wheel with Ctrl or ⌘ zooms it at the pointer, a double tap or click zooms in there and back out; zoomed,
|
|
17
|
+
* a finger or the wheel scrolls it and the mouse drags it. A pinch past the limits goes on a little and comes
|
|
18
|
+
* back. What scrolls is the box itself: a finger scrolls it on the compositor, and the sheets of the phone
|
|
19
|
+
* leave a picture that scrolls sideways alone (sheet-swipe.ts).
|
|
20
|
+
*/
|
|
21
|
+
export class ImageZoom {
|
|
22
|
+
constructor(viewport, stage, image, on) {
|
|
23
|
+
this.viewport = viewport;
|
|
24
|
+
this.stage = stage;
|
|
25
|
+
this.image = image;
|
|
26
|
+
this.on = on;
|
|
27
|
+
this.scale = 1;
|
|
28
|
+
this.limits = { base: 1, min: 1, max: 1 };
|
|
29
|
+
/** Whether it shows as at first: then it fits again when the box changes size. */
|
|
30
|
+
this.fitted = true;
|
|
31
|
+
this.lastTouch = 0;
|
|
32
|
+
this.dragged = false;
|
|
33
|
+
this.frame = 0;
|
|
34
|
+
this.announced = 0;
|
|
35
|
+
this.onLoad = () => {
|
|
36
|
+
const { image } = this;
|
|
37
|
+
// A picture of no size of its own (an SVG with only a viewBox) fills the box.
|
|
38
|
+
const box = this.box();
|
|
39
|
+
this.natural = { width: image.naturalWidth || box.width, height: image.naturalHeight || box.height };
|
|
40
|
+
this.fitted = true;
|
|
41
|
+
this.layout();
|
|
42
|
+
image.dataset.ready = '';
|
|
43
|
+
this.on.loaded(this.natural);
|
|
44
|
+
};
|
|
45
|
+
this.onWheel = (event) => {
|
|
46
|
+
// A pinch of a trackpad comes as a wheel with Ctrl; Ctrl or ⌘ with a wheel zooms too. A wheel alone scrolls.
|
|
47
|
+
if (!event.ctrlKey && !event.metaKey) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
cancelAnimationFrame(this.frame);
|
|
52
|
+
const point = this.local(event.clientX, event.clientY);
|
|
53
|
+
const last = this.wheelAnchor;
|
|
54
|
+
const same = last && event.timeStamp - last.t < 250 && Math.hypot(point.x - last.point.x, point.y - last.point.y) < 2;
|
|
55
|
+
const spot = same ? last.spot : this.spotAt(point);
|
|
56
|
+
this.wheelAnchor = { point, spot, t: event.timeStamp };
|
|
57
|
+
this.place(ZoomUtil.clamp(this.scale * ZoomUtil.wheel(event.deltaY, event.deltaMode), this.limits), spot, point);
|
|
58
|
+
};
|
|
59
|
+
/** Safari's pinch of a trackpad (and of a finger, which the touches have already). */
|
|
60
|
+
this.onGesture = (event) => {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
const gesture = event;
|
|
63
|
+
if (this.pinch || Date.now() - this.lastTouch < 500) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const point = this.local(gesture.clientX, gesture.clientY);
|
|
67
|
+
if (event.type === 'gesturestart') {
|
|
68
|
+
cancelAnimationFrame(this.frame);
|
|
69
|
+
this.gesture = { scale: this.scale };
|
|
70
|
+
}
|
|
71
|
+
else if (this.gesture && event.type === 'gesturechange') {
|
|
72
|
+
this.place(ZoomUtil.clamp(this.gesture.scale * gesture.scale, this.limits), this.spotAt(point), point);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.gesture = undefined;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
this.onTouchStart = (event) => {
|
|
79
|
+
this.lastTouch = Date.now();
|
|
80
|
+
cancelAnimationFrame(this.frame);
|
|
81
|
+
if (event.touches.length >= 2) {
|
|
82
|
+
const { point, distance } = this.pinchOf(event.touches);
|
|
83
|
+
this.pinch = { scale: this.scale, distance, spot: this.spotAt(point) };
|
|
84
|
+
this.tap = undefined;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const touch = event.touches[0];
|
|
88
|
+
this.tap = touch && { x: touch.clientX, y: touch.clientY, t: event.timeStamp, moved: false };
|
|
89
|
+
};
|
|
90
|
+
this.onTouchMove = (event) => {
|
|
91
|
+
this.lastTouch = Date.now();
|
|
92
|
+
if (this.pinch && event.touches.length >= 2) {
|
|
93
|
+
// Neither the page nor a sheet moves under a pinch.
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
const { point, distance } = this.pinchOf(event.touches);
|
|
96
|
+
this.place(ZoomUtil.rubber((this.pinch.scale * distance) / this.pinch.distance, this.limits), this.pinch.spot, point);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const touch = event.touches[0];
|
|
100
|
+
if (this.tap && touch && Math.hypot(touch.clientX - this.tap.x, touch.clientY - this.tap.y) > TAP_PX) {
|
|
101
|
+
this.tap.moved = true;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
this.onTouchEnd = (event) => {
|
|
105
|
+
this.lastTouch = Date.now();
|
|
106
|
+
if (this.pinch) {
|
|
107
|
+
if (event.touches.length >= 2) {
|
|
108
|
+
const { point, distance } = this.pinchOf(event.touches);
|
|
109
|
+
this.pinch = { scale: this.scale, distance, spot: this.spotAt(point) };
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.pinch = undefined;
|
|
113
|
+
// Past the limits, it comes back, about the middle of the box.
|
|
114
|
+
const settled = ZoomUtil.clamp(this.scale, this.limits);
|
|
115
|
+
if (settled !== this.scale) {
|
|
116
|
+
this.zoomTo(settled);
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const tap = this.tap;
|
|
121
|
+
this.tap = undefined;
|
|
122
|
+
if (!tap || tap.moved || event.touches.length > 0 || event.timeStamp - tap.t > DOUBLE_TAP_MS) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const last = this.lastTap;
|
|
126
|
+
if (last && tap.t - last.t < DOUBLE_TAP_MS * 1.5 && Math.hypot(tap.x - last.x, tap.y - last.y) < DOUBLE_TAP_PX) {
|
|
127
|
+
this.lastTap = undefined;
|
|
128
|
+
clearTimeout(this.backgroundTimer);
|
|
129
|
+
// No click, nor a zoom of the page, follows.
|
|
130
|
+
if (event.cancelable) {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
}
|
|
133
|
+
this.zoomTo(ZoomUtil.toggle(this.scale, this.limits), this.local(tap.x, tap.y));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.lastTap = { x: tap.x, y: tap.y, t: tap.t };
|
|
137
|
+
};
|
|
138
|
+
this.onPointerDown = (event) => {
|
|
139
|
+
var _a;
|
|
140
|
+
this.dragged = false;
|
|
141
|
+
if (event.pointerType !== 'mouse' || event.button !== 0 || this.viewport.dataset.zoomed !== 'true') {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
cancelAnimationFrame(this.frame);
|
|
145
|
+
const { viewport } = this;
|
|
146
|
+
this.drag = { id: event.pointerId, x: event.clientX, y: event.clientY, left: viewport.scrollLeft, top: viewport.scrollTop, moved: false };
|
|
147
|
+
(_a = viewport.setPointerCapture) === null || _a === void 0 ? void 0 : _a.call(viewport, event.pointerId);
|
|
148
|
+
};
|
|
149
|
+
this.onPointerMove = (event) => {
|
|
150
|
+
const drag = this.drag;
|
|
151
|
+
if (!drag || drag.id !== event.pointerId) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const dx = event.clientX - drag.x;
|
|
155
|
+
const dy = event.clientY - drag.y;
|
|
156
|
+
if (!drag.moved && Math.hypot(dx, dy) > TAP_PX / 2) {
|
|
157
|
+
drag.moved = true;
|
|
158
|
+
this.viewport.dataset.dragging = '';
|
|
159
|
+
}
|
|
160
|
+
if (drag.moved) {
|
|
161
|
+
this.viewport.scrollLeft = drag.left - dx;
|
|
162
|
+
this.viewport.scrollTop = drag.top - dy;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
this.onPointerUp = (event) => {
|
|
166
|
+
var _a;
|
|
167
|
+
if (((_a = this.drag) === null || _a === void 0 ? void 0 : _a.id) === event.pointerId) {
|
|
168
|
+
this.dragged = this.drag.moved;
|
|
169
|
+
this.drag = undefined;
|
|
170
|
+
delete this.viewport.dataset.dragging;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
/** A click beside the picture; after a touch, once it is clear that no second tap follows. */
|
|
174
|
+
this.onClick = (event) => {
|
|
175
|
+
if (this.dragged || event.target === this.image) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
clearTimeout(this.backgroundTimer);
|
|
179
|
+
if (Date.now() - this.lastTouch < 800) {
|
|
180
|
+
this.backgroundTimer = setTimeout(() => this.on.background(), DOUBLE_TAP_MS * 1.5);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
this.on.background();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
this.onDoubleClick = (event) => {
|
|
187
|
+
// A double tap is the touches'.
|
|
188
|
+
if (Date.now() - this.lastTouch < 800) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
this.zoomTo(ZoomUtil.toggle(this.scale, this.limits), this.local(event.clientX, event.clientY));
|
|
193
|
+
};
|
|
194
|
+
this.onKey = (event) => {
|
|
195
|
+
if (event.altKey) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const keys = {
|
|
199
|
+
'+': () => this.step(1),
|
|
200
|
+
'=': () => this.step(1),
|
|
201
|
+
'-': () => this.step(-1),
|
|
202
|
+
'0': () => this.fit(),
|
|
203
|
+
'1': () => this.actual(),
|
|
204
|
+
};
|
|
205
|
+
const action = keys[event.key];
|
|
206
|
+
if (action) {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
action();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
attach() {
|
|
213
|
+
const { viewport, image } = this;
|
|
214
|
+
const listeners = [
|
|
215
|
+
[image, 'load', this.onLoad],
|
|
216
|
+
[viewport, 'wheel', this.onWheel, { passive: false }],
|
|
217
|
+
[viewport, 'touchstart', this.onTouchStart, { passive: true }],
|
|
218
|
+
[viewport, 'touchmove', this.onTouchMove, { passive: false }],
|
|
219
|
+
[viewport, 'touchend', this.onTouchEnd],
|
|
220
|
+
[viewport, 'touchcancel', this.onTouchEnd],
|
|
221
|
+
[viewport, 'gesturestart', this.onGesture],
|
|
222
|
+
[viewport, 'gesturechange', this.onGesture],
|
|
223
|
+
[viewport, 'gestureend', this.onGesture],
|
|
224
|
+
[viewport, 'pointerdown', this.onPointerDown],
|
|
225
|
+
[viewport, 'pointermove', this.onPointerMove],
|
|
226
|
+
[viewport, 'pointerup', this.onPointerUp],
|
|
227
|
+
[viewport, 'pointercancel', this.onPointerUp],
|
|
228
|
+
[viewport, 'click', this.onClick],
|
|
229
|
+
[viewport, 'dblclick', this.onDoubleClick],
|
|
230
|
+
[viewport, 'keydown', this.onKey],
|
|
231
|
+
];
|
|
232
|
+
for (const [target, type, listener, options] of listeners) {
|
|
233
|
+
target.addEventListener(type, listener, options);
|
|
234
|
+
}
|
|
235
|
+
const resize = new ResizeObserver(() => this.layout());
|
|
236
|
+
resize.observe(viewport);
|
|
237
|
+
if (image.complete && image.naturalWidth) {
|
|
238
|
+
this.onLoad();
|
|
239
|
+
}
|
|
240
|
+
return () => {
|
|
241
|
+
for (const [target, type, listener] of listeners) {
|
|
242
|
+
target.removeEventListener(type, listener);
|
|
243
|
+
}
|
|
244
|
+
resize.disconnect();
|
|
245
|
+
cancelAnimationFrame(this.frame);
|
|
246
|
+
clearTimeout(this.backgroundTimer);
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/** Zooms to `scale` at `point` of the box (its middle by default), sliding there. */
|
|
250
|
+
zoomTo(scale, point = this.middle(), animate = true) {
|
|
251
|
+
const to = ZoomUtil.clamp(scale, this.limits);
|
|
252
|
+
if (!animate) {
|
|
253
|
+
this.place(to, this.spotAt(point), point);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const from = this.scale;
|
|
257
|
+
const spot = this.spotAt(point);
|
|
258
|
+
const start = performance.now();
|
|
259
|
+
cancelAnimationFrame(this.frame);
|
|
260
|
+
const tick = (now) => {
|
|
261
|
+
const progress = Math.min(1, (now - start) / ANIMATE_MS);
|
|
262
|
+
const eased = 1 - (1 - progress) ** 3;
|
|
263
|
+
this.place(from + (to - from) * eased, spot, point);
|
|
264
|
+
if (progress < 1) {
|
|
265
|
+
this.frame = requestAnimationFrame(tick);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
this.frame = requestAnimationFrame(tick);
|
|
269
|
+
}
|
|
270
|
+
step(way) {
|
|
271
|
+
this.zoomTo(ZoomUtil.step(this.scale, way, this.limits));
|
|
272
|
+
}
|
|
273
|
+
fit() {
|
|
274
|
+
this.zoomTo(this.limits.base);
|
|
275
|
+
}
|
|
276
|
+
actual() {
|
|
277
|
+
this.zoomTo(1);
|
|
278
|
+
}
|
|
279
|
+
box() {
|
|
280
|
+
return { width: this.viewport.clientWidth, height: this.viewport.clientHeight };
|
|
281
|
+
}
|
|
282
|
+
middle() {
|
|
283
|
+
const box = this.box();
|
|
284
|
+
return { x: box.width / 2, y: box.height / 2 };
|
|
285
|
+
}
|
|
286
|
+
/** A point of the page in the box. */
|
|
287
|
+
local(clientX, clientY) {
|
|
288
|
+
const rect = this.viewport.getBoundingClientRect();
|
|
289
|
+
return { x: clientX - rect.left, y: clientY - rect.top };
|
|
290
|
+
}
|
|
291
|
+
/** The spot of the picture (its own pixels) under `point` of the box. */
|
|
292
|
+
spotAt(point) {
|
|
293
|
+
var _a;
|
|
294
|
+
const natural = (_a = this.natural) !== null && _a !== void 0 ? _a : { width: 1, height: 1 };
|
|
295
|
+
const box = this.box();
|
|
296
|
+
return {
|
|
297
|
+
x: ZoomUtil.at(point.x, this.viewport.scrollLeft, natural.width, this.scale, box.width),
|
|
298
|
+
y: ZoomUtil.at(point.y, this.viewport.scrollTop, natural.height, this.scale, box.height),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/** Draws it at `scale` with `spot` of the picture under `point` of the box. */
|
|
302
|
+
place(scale, spot, point) {
|
|
303
|
+
const natural = this.natural;
|
|
304
|
+
if (!natural) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const box = this.box();
|
|
308
|
+
const width = natural.width * scale;
|
|
309
|
+
const height = natural.height * scale;
|
|
310
|
+
this.scale = scale;
|
|
311
|
+
this.fitted = ZoomUtil.fitted(scale, this.limits);
|
|
312
|
+
const { stage, image, viewport } = this;
|
|
313
|
+
stage.style.width = `${ZoomUtil.extent(width, box.width)}px`;
|
|
314
|
+
stage.style.height = `${ZoomUtil.extent(height, box.height)}px`;
|
|
315
|
+
image.style.width = `${width}px`;
|
|
316
|
+
image.style.height = `${height}px`;
|
|
317
|
+
image.style.transform = `translate(${ZoomUtil.offset(width, box.width)}px, ${ZoomUtil.offset(height, box.height)}px)`;
|
|
318
|
+
image.classList.toggle('ta-zoom-pixelated', scale >= ZoomUtil.PIXELATED);
|
|
319
|
+
viewport.scrollLeft = ZoomUtil.scrollTo(spot.x, point.x, natural.width, scale, box.width);
|
|
320
|
+
viewport.scrollTop = ZoomUtil.scrollTo(spot.y, point.y, natural.height, scale, box.height);
|
|
321
|
+
viewport.dataset.zoomed = String(width + 2 * ZoomUtil.PAD > box.width + 1 || height + 2 * ZoomUtil.PAD > box.height + 1);
|
|
322
|
+
this.announce();
|
|
323
|
+
}
|
|
324
|
+
/** Tells what shows the scale, once a frame. */
|
|
325
|
+
announce() {
|
|
326
|
+
if (this.announced) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
this.announced = requestAnimationFrame(() => {
|
|
330
|
+
this.announced = 0;
|
|
331
|
+
this.on.changed({ scale: this.scale, ...this.limits });
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/** Fits it again in a box of another size, or keeps the middle where it is when zoomed. */
|
|
335
|
+
layout() {
|
|
336
|
+
if (!this.natural) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const middle = this.middle();
|
|
340
|
+
const spot = this.spotAt(middle);
|
|
341
|
+
const fitted = this.fitted;
|
|
342
|
+
this.limits = ZoomUtil.limits(this.natural, this.box());
|
|
343
|
+
if (fitted) {
|
|
344
|
+
this.place(this.limits.base, { x: this.natural.width / 2, y: this.natural.height / 2 }, middle);
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
this.place(ZoomUtil.clamp(this.scale, this.limits), spot, middle);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
pinchOf(touches) {
|
|
351
|
+
const a = touches[0];
|
|
352
|
+
const b = touches[1];
|
|
353
|
+
return {
|
|
354
|
+
point: this.local((a.clientX + b.clientX) / 2, (a.clientY + b.clientY) / 2),
|
|
355
|
+
distance: Math.max(1, Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY)),
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/** A picture that zooms and scrolls (ImageZoom), with its buttons: −, the scale (back to fit), + and 1:1. */
|
|
360
|
+
export function ImageViewer({ src, alt = '', className = '', onLoad, onBackground }) {
|
|
361
|
+
const t = useT();
|
|
362
|
+
const viewport = React.useRef(null);
|
|
363
|
+
const stage = React.useRef(null);
|
|
364
|
+
const image = React.useRef(null);
|
|
365
|
+
const zoom = React.useRef(undefined);
|
|
366
|
+
const latest = React.useRef({ onLoad, onBackground });
|
|
367
|
+
latest.current = { onLoad, onBackground };
|
|
368
|
+
const [state, setState] = React.useState();
|
|
369
|
+
React.useEffect(() => {
|
|
370
|
+
if (!viewport.current || !stage.current || !image.current) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const controller = new ImageZoom(viewport.current, stage.current, image.current, {
|
|
374
|
+
changed: setState,
|
|
375
|
+
loaded: size => { var _a, _b; return (_b = (_a = latest.current).onLoad) === null || _b === void 0 ? void 0 : _b.call(_a, size); },
|
|
376
|
+
background: () => { var _a, _b; return (_b = (_a = latest.current).onBackground) === null || _b === void 0 ? void 0 : _b.call(_a); },
|
|
377
|
+
});
|
|
378
|
+
zoom.current = controller;
|
|
379
|
+
// Another src loads in the same picture: its load measures it again.
|
|
380
|
+
return controller.attach();
|
|
381
|
+
}, []);
|
|
382
|
+
const fitted = !state || ZoomUtil.fitted(state.scale, state);
|
|
383
|
+
return (React.createElement("div", { className: `ta-zoom ${className}` },
|
|
384
|
+
React.createElement("div", { ref: viewport, className: "ta-zoom-viewport", tabIndex: 0 },
|
|
385
|
+
React.createElement("div", { ref: stage, className: "ta-zoom-stage" },
|
|
386
|
+
React.createElement("img", { ref: image, src: src, alt: alt, draggable: false }))),
|
|
387
|
+
state && (React.createElement("div", { className: "ta-zoom-bar" },
|
|
388
|
+
React.createElement("button", { type: "button", title: t('ta.zoom.out'), disabled: state.scale <= state.min * 1.001, onClick: () => { var _a; return (_a = zoom.current) === null || _a === void 0 ? void 0 : _a.step(-1); } },
|
|
389
|
+
React.createElement(Icon, { icon: Minus, size: 15 })),
|
|
390
|
+
React.createElement("button", { type: "button", className: "ta-zoom-scale", title: t('ta.zoom.fit'), disabled: fitted, onClick: () => { var _a; return (_a = zoom.current) === null || _a === void 0 ? void 0 : _a.fit(); } },
|
|
391
|
+
Math.round(state.scale * 100),
|
|
392
|
+
"%"),
|
|
393
|
+
React.createElement("button", { type: "button", title: t('ta.zoom.in'), disabled: state.scale >= state.max * 0.999, onClick: () => { var _a; return (_a = zoom.current) === null || _a === void 0 ? void 0 : _a.step(1); } },
|
|
394
|
+
React.createElement(Icon, { icon: Plus, size: 15 })),
|
|
395
|
+
React.createElement("button", { type: "button", className: "ta-zoom-actual", title: t('ta.zoom.actual'), disabled: Math.abs(state.scale - 1) < 0.001, onClick: () => { var _a; return (_a = zoom.current) === null || _a === void 0 ? void 0 : _a.actual(); } }, "1:1")))));
|
|
396
|
+
}
|
|
397
|
+
//# sourceMappingURL=image-viewer.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* An image over the page, to look at closely (ImageViewer): pinched, zoomed, dragged. A click or tap beside it,
|
|
4
|
+
* its close button or Escape closes it. In the top layer, so no container clips it; the touches in it are its
|
|
5
|
+
* own, never a swipe of a sheet under it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function Lightbox({ src, alt, onClose }: {
|
|
8
|
+
src: string;
|
|
9
|
+
alt: string;
|
|
10
|
+
onClose(): void;
|
|
11
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { X } from 'lucide-react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useT } from '../i18n/use-t.js';
|
|
4
|
+
import { Icon } from './icon.js';
|
|
5
|
+
import { ImageViewer } from './image-viewer.js';
|
|
6
|
+
/**
|
|
7
|
+
* An image over the page, to look at closely (ImageViewer): pinched, zoomed, dragged. A click or tap beside it,
|
|
8
|
+
* its close button or Escape closes it. In the top layer, so no container clips it; the touches in it are its
|
|
9
|
+
* own, never a swipe of a sheet under it.
|
|
10
|
+
*/
|
|
11
|
+
export function Lightbox({ src, alt, onClose }) {
|
|
12
|
+
const t = useT();
|
|
13
|
+
const dialog = React.useRef(null);
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
(_b = (_a = dialog.current) === null || _a === void 0 ? void 0 : _a.showModal) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
17
|
+
}, []);
|
|
18
|
+
const close = () => { var _a; return (_a = dialog.current) === null || _a === void 0 ? void 0 : _a.close(); };
|
|
19
|
+
return (React.createElement("dialog", { ref: dialog, className: "ta-lightbox", onClose: onClose, onTouchStart: event => event.stopPropagation() },
|
|
20
|
+
React.createElement(ImageViewer, { src: src, alt: alt, onBackground: close }),
|
|
21
|
+
React.createElement("button", { type: "button", className: "ta-lightbox-close", title: t('ta.close'), "aria-label": t('ta.close'), onClick: close },
|
|
22
|
+
React.createElement(Icon, { icon: X, size: 18 }))));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=lightbox.js.map
|
|
@@ -3,7 +3,11 @@ export declare function CodeBlock({ code }: {
|
|
|
3
3
|
code: string;
|
|
4
4
|
language?: string;
|
|
5
5
|
}): React.JSX.Element;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Markdown as React elements; drawn again only when its text changes, and then only the blocks that did.
|
|
8
|
+
* `streaming`: the text is a reply still coming, which shows nothing that is about to turn into something else.
|
|
9
|
+
*/
|
|
10
|
+
export declare function Markdown({ text, streaming }: {
|
|
8
11
|
text: string;
|
|
12
|
+
streaming?: boolean;
|
|
9
13
|
}): React.JSX.Element;
|
|
@@ -70,12 +70,13 @@ const Block = React.memo(function Block({ block }) {
|
|
|
70
70
|
return block.ordered ? React.createElement("ol", null, items) : React.createElement("ul", null, items);
|
|
71
71
|
}
|
|
72
72
|
case 'table':
|
|
73
|
+
// Short cells keep to one line and long ones wrap: a table wider than the page scrolls in its frame.
|
|
73
74
|
return (React.createElement("div", { className: "ta-table" },
|
|
74
75
|
React.createElement("table", null,
|
|
75
76
|
React.createElement("thead", null,
|
|
76
|
-
React.createElement("tr", null, block.header.map((cell, index) => (React.createElement("th", { key: index },
|
|
77
|
+
React.createElement("tr", null, block.header.map((cell, index) => (React.createElement("th", { key: index, "data-align": block.align[index] || undefined },
|
|
77
78
|
React.createElement(Text, { text: cell })))))),
|
|
78
|
-
React.createElement("tbody", null, block.rows.map((row, index) => (React.createElement("tr", { key: index }, row.map((cell, column) => (React.createElement("td", { key: column },
|
|
79
|
+
React.createElement("tbody", null, block.rows.map((row, index) => (React.createElement("tr", { key: index }, row.map((cell, column) => (React.createElement("td", { key: column, className: MarkdownUtil.longCell(cell) ? 'ta-cell-long' : undefined, "data-align": block.align[column] || undefined },
|
|
79
80
|
React.createElement(Text, { text: cell })))))))))));
|
|
80
81
|
case 'rule':
|
|
81
82
|
return React.createElement("hr", null);
|
|
@@ -83,16 +84,29 @@ const Block = React.memo(function Block({ block }) {
|
|
|
83
84
|
return (React.createElement("p", null,
|
|
84
85
|
React.createElement(Text, { text: block.text })));
|
|
85
86
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* The blocks of `text`, those that did not change the same objects as before: a block draws again only when it
|
|
90
|
+
* changed, and the blocks are not compared again as they draw.
|
|
91
|
+
*/
|
|
92
|
+
function useBlocks(text, streaming) {
|
|
93
|
+
const previous = React.useRef([]);
|
|
94
|
+
return React.useMemo(() => {
|
|
95
|
+
const blocks = streaming ? MarkdownUtil.streaming(text) : MarkdownUtil.blocks(text);
|
|
96
|
+
const kept = blocks.map((block, index) => (MarkdownUtil.same(previous.current[index], block) ? previous.current[index] : block));
|
|
97
|
+
previous.current = kept;
|
|
98
|
+
return kept;
|
|
99
|
+
}, [text, streaming]);
|
|
89
100
|
}
|
|
90
|
-
const MarkdownBody = React.memo(function MarkdownBody({ text }) {
|
|
91
|
-
const blocks =
|
|
101
|
+
const MarkdownBody = React.memo(function MarkdownBody({ text, streaming }) {
|
|
102
|
+
const blocks = useBlocks(text, streaming);
|
|
92
103
|
return (React.createElement("div", { className: "ta-markdown" }, blocks.map((block, index) => (React.createElement(Block, { key: index, block: block })))));
|
|
93
104
|
});
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Markdown as React elements; drawn again only when its text changes, and then only the blocks that did.
|
|
107
|
+
* `streaming`: the text is a reply still coming, which shows nothing that is about to turn into something else.
|
|
108
|
+
*/
|
|
109
|
+
export function Markdown({ text, streaming = false }) {
|
|
110
|
+
return React.createElement(MarkdownBody, { text: text, streaming: streaming });
|
|
97
111
|
}
|
|
98
112
|
//# sourceMappingURL=markdown.js.map
|
|
@@ -3,6 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import { useT } from '../i18n/use-t.js';
|
|
4
4
|
import { MarkdownUtil } from '../util/markdown.js';
|
|
5
5
|
import { Icon } from './icon.js';
|
|
6
|
+
import { Lightbox } from './lightbox.js';
|
|
6
7
|
/**
|
|
7
8
|
* Where the page loads a file of the workspace from (TaWorkspaceServer.fileUrl), in the directory of the
|
|
8
9
|
* conversation that shows it; without it, files of the workspace do not show.
|
|
@@ -30,16 +31,6 @@ function useUrl(src) {
|
|
|
30
31
|
}, [fileUrl, path, src]);
|
|
31
32
|
return url;
|
|
32
33
|
}
|
|
33
|
-
/** An image at its full size over the page; a click or Escape closes it. In the top layer, so no container clips it. */
|
|
34
|
-
function Lightbox({ src, alt, onClose }) {
|
|
35
|
-
const dialog = React.useRef(null);
|
|
36
|
-
React.useEffect(() => {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
(_b = (_a = dialog.current) === null || _a === void 0 ? void 0 : _a.showModal) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
39
|
-
}, []);
|
|
40
|
-
return (React.createElement("dialog", { ref: dialog, className: "ta-lightbox", onClose: onClose, onClick: () => { var _a; return (_a = dialog.current) === null || _a === void 0 ? void 0 : _a.close(); } },
|
|
41
|
-
React.createElement("img", { src: src, alt: alt })));
|
|
42
|
-
}
|
|
43
34
|
/** An image, a video or a sound a reply shows: from the web, a data URL, or a file of the workspace. */
|
|
44
35
|
export function MediaView({ src, alt }) {
|
|
45
36
|
var _a;
|
|
@@ -17,15 +17,29 @@ export declare namespace MessageFooterUtil {
|
|
|
17
17
|
/** What to paste into an issue: where the message is, and what the model said of it. */
|
|
18
18
|
function debugInfo(message: SessionMessage, session: TaSessionInfo | undefined): string;
|
|
19
19
|
}
|
|
20
|
+
/** When, as a person says it: the time today, "Yesterday" and the time, else the date and the time. */
|
|
21
|
+
export declare function useTimeLabel(): (timestamp: number) => string;
|
|
22
|
+
/**
|
|
23
|
+
* The time between two messages far apart (ProcessUtil.timeBreaks), as WeChat shows it: on a touch screen,
|
|
24
|
+
* where the footers of the messages, which carry their times, are not shown.
|
|
25
|
+
*/
|
|
26
|
+
export declare function TimeBreak({ timestamp }: {
|
|
27
|
+
timestamp?: number;
|
|
28
|
+
}): React.JSX.Element;
|
|
20
29
|
/** Under a message of the user: when, copy, a new conversation from here, back to here. */
|
|
21
30
|
export declare function UserFooter({ message, text }: {
|
|
22
31
|
message: SessionMessage;
|
|
23
32
|
text: string;
|
|
24
33
|
}): React.JSX.Element;
|
|
25
|
-
/**
|
|
26
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Under a turn that ended: copy the reply, a new conversation from it, what to report, when, what it took.
|
|
36
|
+
* `latest`: the last turn of the conversation, whose footer a touch screen keeps (only its copy and fork;
|
|
37
|
+
* the rest, and the footers of the others, are in the menu of a held message).
|
|
38
|
+
*/
|
|
39
|
+
export declare function TurnFooter({ messages, last, reply, session, latest, }: {
|
|
27
40
|
messages: SessionMessage[];
|
|
28
41
|
last?: SessionMessage;
|
|
29
42
|
reply: string;
|
|
30
43
|
session?: TaSessionInfo;
|
|
44
|
+
latest?: boolean;
|
|
31
45
|
}): React.JSX.Element;
|
|
@@ -25,12 +25,12 @@ export var MessageFooterUtil;
|
|
|
25
25
|
}
|
|
26
26
|
MessageFooterUtil.debugInfo = debugInfo;
|
|
27
27
|
})(MessageFooterUtil || (MessageFooterUtil = {}));
|
|
28
|
-
function FooterButton({ icon, label, onClick }) {
|
|
29
|
-
return (React.createElement("button", { type: "button", className:
|
|
28
|
+
function FooterButton({ icon, label, onClick, className }) {
|
|
29
|
+
return (React.createElement("button", { type: "button", className: className ? `ta-footer-button ${className}` : 'ta-footer-button', title: label, "aria-label": label, onClick: onClick },
|
|
30
30
|
React.createElement(Icon, { icon: icon, size: 14 })));
|
|
31
31
|
}
|
|
32
32
|
/** Copies, and says so on the button for a moment. */
|
|
33
|
-
function CopyButton({ text, icon, label, done }) {
|
|
33
|
+
function CopyButton({ text, icon, label, done, className }) {
|
|
34
34
|
const t = useT();
|
|
35
35
|
const [copied, setCopied] = React.useState(false);
|
|
36
36
|
React.useEffect(() => {
|
|
@@ -40,16 +40,29 @@ function CopyButton({ text, icon, label, done }) {
|
|
|
40
40
|
}
|
|
41
41
|
}, [copied]);
|
|
42
42
|
const copy = () => { var _a; return void ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(text()).then(() => setCopied(true))); };
|
|
43
|
-
return React.createElement(FooterButton, { icon: copied ? Check : icon, label: t(copied ? done : label), onClick: copy });
|
|
43
|
+
return React.createElement(FooterButton, { icon: copied ? Check : icon, label: t(copied ? done : label), onClick: copy, className: className });
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
/** When, as a person says it: the time today, "Yesterday" and the time, else the date and the time. */
|
|
46
|
+
export function useTimeLabel() {
|
|
46
47
|
const t = useT();
|
|
48
|
+
return timestamp => {
|
|
49
|
+
const { day, time, date } = MessageUtil.when(timestamp);
|
|
50
|
+
return day === 'today' ? time : day === 'date' ? `${date} ${time}` : `${t(day === 'yesterday' ? 'ta.time.yesterday' : 'ta.time.dayBefore')} ${time}`;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function Time({ timestamp, className = 'ta-footer-time' }) {
|
|
54
|
+
const label = useTimeLabel();
|
|
47
55
|
if (timestamp === undefined) {
|
|
48
56
|
return null;
|
|
49
57
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
return (React.createElement("time", { className: className, dateTime: new Date(timestamp).toISOString(), title: new Date(timestamp).toLocaleString() }, label(timestamp)));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The time between two messages far apart (ProcessUtil.timeBreaks), as WeChat shows it: on a touch screen,
|
|
62
|
+
* where the footers of the messages, which carry their times, are not shown.
|
|
63
|
+
*/
|
|
64
|
+
export function TimeBreak({ timestamp }) {
|
|
65
|
+
return React.createElement(Time, { timestamp: timestamp, className: "ta-time-break" });
|
|
53
66
|
}
|
|
54
67
|
/** Under a message of the user: when, copy, a new conversation from here, back to here. */
|
|
55
68
|
export function UserFooter({ message, text }) {
|
|
@@ -62,16 +75,20 @@ export function UserFooter({ message, text }) {
|
|
|
62
75
|
branches && React.createElement(FooterButton, { icon: GitFork, label: t('ta.message.forkBefore'), onClick: () => actions.fork(message, 'before') }),
|
|
63
76
|
branches && React.createElement(FooterButton, { icon: Undo2, label: t('ta.message.rewind'), onClick: () => actions.rewind(message) })));
|
|
64
77
|
}
|
|
65
|
-
/**
|
|
66
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Under a turn that ended: copy the reply, a new conversation from it, what to report, when, what it took.
|
|
80
|
+
* `latest`: the last turn of the conversation, whose footer a touch screen keeps (only its copy and fork;
|
|
81
|
+
* the rest, and the footers of the others, are in the menu of a held message).
|
|
82
|
+
*/
|
|
83
|
+
export function TurnFooter({ messages, last, reply, session, latest, }) {
|
|
67
84
|
const t = useT();
|
|
68
85
|
const actions = React.useContext(MessageActions);
|
|
69
86
|
const usage = React.useMemo(() => MessageUtil.usage(messages), [messages]);
|
|
70
87
|
const used = usage.input > 0 || usage.output > 0;
|
|
71
|
-
return (React.createElement("div", { className:
|
|
88
|
+
return (React.createElement("div", { className: latest ? 'ta-footer ta-footer-latest' : 'ta-footer' },
|
|
72
89
|
reply && React.createElement(CopyButton, { text: () => reply, icon: Copy, label: "ta.copy", done: "ta.copied" }),
|
|
73
90
|
last && actions && !actions.working && React.createElement(FooterButton, { icon: GitFork, label: t('ta.message.forkAt'), onClick: () => actions.fork(last, 'at') }),
|
|
74
|
-
last && React.createElement(CopyButton, { text: () => MessageFooterUtil.debugInfo(last, session), icon: Bug, label: "ta.message.debug", done: "ta.message.debugCopied" }),
|
|
91
|
+
last && (React.createElement(CopyButton, { text: () => MessageFooterUtil.debugInfo(last, session), icon: Bug, label: "ta.message.debug", done: "ta.message.debugCopied", className: "ta-footer-debug" })),
|
|
75
92
|
React.createElement(Time, { timestamp: last === null || last === void 0 ? void 0 : last.timestamp }),
|
|
76
93
|
used && (React.createElement("span", { className: "ta-footer-usage", title: t('ta.message.usageTitle', { input: usage.input, output: usage.output }) },
|
|
77
94
|
React.createElement("span", null, t('ta.message.used')),
|