dsh-ide-window 0.3.2 → 0.3.3
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/AGENTS.md +31 -12
- package/CHANGELOG.md +14 -0
- package/README.md +13 -5
- package/client.js +840 -126
- package/index.js +40 -8
- package/locale/en.json +9 -5
- package/locale/zh.json +9 -5
- package/package.json +1 -1
- package/platform/contract.js +3 -2
- package/platform/macos.js +2 -2
- package/platform/windows.js +5 -4
package/client.js
CHANGED
|
@@ -236,11 +236,7 @@ window.__ModuleLoader__.load({
|
|
|
236
236
|
"theme_solarized_light": "Solarized Light",
|
|
237
237
|
"theme_intellij_light": "IntelliJ Light",
|
|
238
238
|
"shortcutScreenshot": "Screenshot (can jump to chat)",
|
|
239
|
-
"shotTitle": "Screenshot taken",
|
|
240
239
|
"shotBusy": "Capturing…",
|
|
241
|
-
"shotPreview": "Screenshot preview",
|
|
242
|
-
"shotJump": "Screenshot and jump to chat",
|
|
243
|
-
"shotKeep": "Screenshot only (copy to clipboard)",
|
|
244
240
|
"shotRetry": "Retry",
|
|
245
241
|
"shotFailed": "Screenshot failed",
|
|
246
242
|
"shotNoPermissionTitle": "Cannot capture: Screen Recording permission is missing",
|
|
@@ -252,6 +248,14 @@ window.__ModuleLoader__.load({
|
|
|
252
248
|
"shotNoEditor": "Composer not found: the screenshot is on the clipboard, press ⌘V",
|
|
253
249
|
"shotOpenFailed": "Could not open System Settings. Open it manually: Privacy & Security → Screen Recording",
|
|
254
250
|
"paletteActionScreenshot": "Take a screenshot",
|
|
251
|
+
"shotSelectHint": "Press the left button and drag to frame the area; release to finish, Esc cancels.",
|
|
252
|
+
"shotMarkHint": "Drag inside the frame to draw a box, or pick Text and click to type. ⌘Z undoes, Esc closes.",
|
|
253
|
+
"shotTool_rect": "Box",
|
|
254
|
+
"shotTool_text": "Text",
|
|
255
|
+
"shotUndo": "Undo",
|
|
256
|
+
"shotTextPlaceholder": "Type, then press Enter",
|
|
257
|
+
"shotCopy": "Capture",
|
|
258
|
+
"shotJump": "Capture and open chat",
|
|
255
259
|
}
|
|
256
260
|
const IDE_TEXT_ZH = {
|
|
257
261
|
"title": "代码工作区",
|
|
@@ -481,11 +485,7 @@ window.__ModuleLoader__.load({
|
|
|
481
485
|
"theme_solarized_light": "Solarized 浅色",
|
|
482
486
|
"theme_intellij_light": "IntelliJ 浅色",
|
|
483
487
|
"shortcutScreenshot": "截图(可跳转会话)",
|
|
484
|
-
"shotTitle": "截图完成",
|
|
485
488
|
"shotBusy": "正在截图…",
|
|
486
|
-
"shotPreview": "截图预览",
|
|
487
|
-
"shotJump": "截图并跳转会话",
|
|
488
|
-
"shotKeep": "只截图(复制到剪贴板)",
|
|
489
489
|
"shotRetry": "重试",
|
|
490
490
|
"shotFailed": "截图失败",
|
|
491
491
|
"shotNoPermissionTitle": "无法截图:缺少屏幕录制权限",
|
|
@@ -497,6 +497,14 @@ window.__ModuleLoader__.load({
|
|
|
497
497
|
"shotNoEditor": "没找到对话框:截图已复制到剪贴板,按 ⌘V 粘贴",
|
|
498
498
|
"shotOpenFailed": "打不开系统设置,请手动打开:系统设置 → 隐私与安全性 → 屏幕录制",
|
|
499
499
|
"paletteActionScreenshot": "截图",
|
|
500
|
+
"shotSelectHint": "按住鼠标左键拖动,框出要截的范围;松开后完成选框,Esc 取消",
|
|
501
|
+
"shotMarkHint": "在选框内拖动可画矩形,选「文字」后点一下输入;⌘Z 撤销,Esc 关闭",
|
|
502
|
+
"shotTool_rect": "矩形",
|
|
503
|
+
"shotTool_text": "文字",
|
|
504
|
+
"shotUndo": "撤销",
|
|
505
|
+
"shotTextPlaceholder": "输入文字后回车",
|
|
506
|
+
"shotCopy": "截图",
|
|
507
|
+
"shotJump": "截图并跳转会话",
|
|
500
508
|
}
|
|
501
509
|
|
|
502
510
|
// ---- 00-css.js -----------------------------------------------------------
|
|
@@ -1982,11 +1990,25 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
1982
1990
|
.iw-theme-dot--solarized-light { background: #fdf6e3; }
|
|
1983
1991
|
.iw-theme-dot--intellij-light { background: #f7f8fa; }
|
|
1984
1992
|
|
|
1985
|
-
/* ---- screenshot
|
|
1993
|
+
/* ---- screenshot: veil, permission card, editor ---- */
|
|
1994
|
+
.iw-shot-veil {
|
|
1995
|
+
position: fixed;
|
|
1996
|
+
inset: 0;
|
|
1997
|
+
display: flex;
|
|
1998
|
+
align-items: center;
|
|
1999
|
+
justify-content: center;
|
|
2000
|
+
background: rgba(0, 0, 0, 0.45);
|
|
2001
|
+
z-index: 60;
|
|
2002
|
+
}
|
|
2003
|
+
.iw-shot-veil--editor {
|
|
2004
|
+
flex-direction: column;
|
|
2005
|
+
gap: 10px;
|
|
2006
|
+
padding: 16px;
|
|
2007
|
+
box-sizing: border-box;
|
|
2008
|
+
background: rgba(8, 10, 14, 0.92);
|
|
2009
|
+
outline: none;
|
|
2010
|
+
}
|
|
1986
2011
|
.iw-shot {
|
|
1987
|
-
position: absolute;
|
|
1988
|
-
right: 16px;
|
|
1989
|
-
bottom: 40px;
|
|
1990
2012
|
width: 420px;
|
|
1991
2013
|
max-width: calc(100% - 32px);
|
|
1992
2014
|
padding: 14px;
|
|
@@ -1995,7 +2017,6 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
1995
2017
|
border-radius: var(--dsw-radius-lg, 10px);
|
|
1996
2018
|
background: var(--dsw-alias-bg-layer-2, #23262c);
|
|
1997
2019
|
box-shadow: var(--dsw-elevation-prominent, 0 12px 32px rgba(0, 0, 0, 0.4));
|
|
1998
|
-
z-index: 45;
|
|
1999
2020
|
}
|
|
2000
2021
|
.iw-shot-title {
|
|
2001
2022
|
font-size: 13px;
|
|
@@ -2008,16 +2029,6 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2008
2029
|
font-size: 12px;
|
|
2009
2030
|
line-height: 1.6;
|
|
2010
2031
|
}
|
|
2011
|
-
.iw-shot-preview {
|
|
2012
|
-
display: block;
|
|
2013
|
-
width: 100%;
|
|
2014
|
-
max-height: 240px;
|
|
2015
|
-
margin-top: 10px;
|
|
2016
|
-
object-fit: contain;
|
|
2017
|
-
border: 1px solid var(--dsw-alias-border-l1, #2c3038);
|
|
2018
|
-
border-radius: var(--dsw-radius-sm, 4px);
|
|
2019
|
-
background: var(--dsw-alias-bg-base, #16181c);
|
|
2020
|
-
}
|
|
2021
2032
|
.iw-shot-actions {
|
|
2022
2033
|
display: flex;
|
|
2023
2034
|
align-items: center;
|
|
@@ -2025,9 +2036,8 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2025
2036
|
gap: 8px;
|
|
2026
2037
|
margin-top: 12px;
|
|
2027
2038
|
}
|
|
2028
|
-
.iw-shot-
|
|
2029
|
-
|
|
2030
|
-
font-size: 12px;
|
|
2039
|
+
.iw-shot-actions--bar {
|
|
2040
|
+
margin-top: 0;
|
|
2031
2041
|
}
|
|
2032
2042
|
.iw-shot-button,
|
|
2033
2043
|
.iw-shot-primary {
|
|
@@ -2041,14 +2051,89 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2041
2051
|
font-size: 12px;
|
|
2042
2052
|
cursor: pointer;
|
|
2043
2053
|
}
|
|
2054
|
+
.iw-shot-button:disabled {
|
|
2055
|
+
opacity: 0.45;
|
|
2056
|
+
cursor: default;
|
|
2057
|
+
}
|
|
2044
2058
|
.iw-shot-primary {
|
|
2045
2059
|
border-color: transparent;
|
|
2046
2060
|
background: var(--dsw-alias-brand-primary, #4f8cff);
|
|
2047
2061
|
color: #fff;
|
|
2048
2062
|
}
|
|
2049
|
-
.iw-shot-button:hover {
|
|
2063
|
+
.iw-shot-button:hover:not(:disabled) {
|
|
2050
2064
|
background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, 0.16));
|
|
2051
2065
|
}
|
|
2066
|
+
.iw-shot-card {
|
|
2067
|
+
position: fixed;
|
|
2068
|
+
display: flex;
|
|
2069
|
+
align-items: center;
|
|
2070
|
+
flex-wrap: nowrap;
|
|
2071
|
+
gap: 4px;
|
|
2072
|
+
padding: 5px 6px;
|
|
2073
|
+
box-sizing: border-box;
|
|
2074
|
+
border-radius: var(--dsw-radius-md, 8px);
|
|
2075
|
+
background: var(--dsw-alias-bg-layer-2, #23262c);
|
|
2076
|
+
border: 1px solid var(--dsw-alias-border-l1, #2c3038);
|
|
2077
|
+
box-shadow: var(--dsw-elevation-prominent, 0 10px 28px rgba(0, 0, 0, 0.45));
|
|
2078
|
+
color: var(--dsw-alias-label-primary, #e6e8ec);
|
|
2079
|
+
z-index: 62;
|
|
2080
|
+
}
|
|
2081
|
+
.iw-shot-tool,
|
|
2082
|
+
.iw-shot-card .iw-shot-button,
|
|
2083
|
+
.iw-shot-card .iw-shot-primary {
|
|
2084
|
+
flex: 0 0 auto;
|
|
2085
|
+
white-space: nowrap;
|
|
2086
|
+
}
|
|
2087
|
+
.iw-shot-card .iw-btn {
|
|
2088
|
+
flex: 0 0 auto;
|
|
2089
|
+
white-space: nowrap;
|
|
2090
|
+
font-size: inherit;
|
|
2091
|
+
}
|
|
2092
|
+
.iw-shot-card .iw-sep {
|
|
2093
|
+
width: 1px;
|
|
2094
|
+
height: 16px;
|
|
2095
|
+
margin: 0 2px;
|
|
2096
|
+
flex: 0 0 auto;
|
|
2097
|
+
background: var(--dsw-alias-border-l1, #2c3038);
|
|
2098
|
+
}
|
|
2099
|
+
.iw-shot-grow {
|
|
2100
|
+
flex: 1;
|
|
2101
|
+
}
|
|
2102
|
+
.iw-shot-hint {
|
|
2103
|
+
color: var(--dsw-alias-label-secondary, #98a0ad);
|
|
2104
|
+
}
|
|
2105
|
+
.iw-shot-hint--top {
|
|
2106
|
+
padding: 0 4px 2px;
|
|
2107
|
+
text-align: center;
|
|
2108
|
+
}
|
|
2109
|
+
.iw-shot-stage {
|
|
2110
|
+
position: relative;
|
|
2111
|
+
display: flex;
|
|
2112
|
+
align-items: center;
|
|
2113
|
+
justify-content: center;
|
|
2114
|
+
flex: 1;
|
|
2115
|
+
min-height: 0;
|
|
2116
|
+
width: 100%;
|
|
2117
|
+
touch-action: none;
|
|
2118
|
+
cursor: crosshair;
|
|
2119
|
+
}
|
|
2120
|
+
.iw-shot-canvas {
|
|
2121
|
+
display: block;
|
|
2122
|
+
border-radius: 4px;
|
|
2123
|
+
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
|
|
2124
|
+
}
|
|
2125
|
+
.iw-shot-text {
|
|
2126
|
+
position: absolute;
|
|
2127
|
+
min-width: 160px;
|
|
2128
|
+
padding: 4px 6px;
|
|
2129
|
+
border: 1px solid var(--dsw-alias-brand-primary, #4f8cff);
|
|
2130
|
+
border-radius: 4px;
|
|
2131
|
+
background: var(--dsw-alias-bg-layer-2, #23262c);
|
|
2132
|
+
color: var(--dsw-alias-label-primary, #e6e8ec);
|
|
2133
|
+
font: inherit;
|
|
2134
|
+
font-size: 13px;
|
|
2135
|
+
outline: none;
|
|
2136
|
+
}
|
|
2052
2137
|
|
|
2053
2138
|
`
|
|
2054
2139
|
|
|
@@ -3238,7 +3323,7 @@ function ideCreateStore(refs) {
|
|
|
3238
3323
|
themeMenu: false,
|
|
3239
3324
|
/**
|
|
3240
3325
|
* Screenshot dialog: `null` when closed, otherwise
|
|
3241
|
-
* `{ phase: '
|
|
3326
|
+
* `{ phase: 'editing' | 'error', dataUrl?, path?, code?, message? }`.
|
|
3242
3327
|
*/
|
|
3243
3328
|
screenshot: null,
|
|
3244
3329
|
/** Editor and tree font sizes, in px, shared by the whole workspace. */
|
|
@@ -6983,7 +7068,7 @@ function IdeSetupDialog({ tr, open, busy, still, onCheck, onClose, store }) {
|
|
|
6983
7068
|
/** How many times the panel body has rendered; a probe can read it. */
|
|
6984
7069
|
let idePanelRenders = 0
|
|
6985
7070
|
|
|
6986
|
-
function IdePanel({ store, translate, onBackToChat, onToggleSidebar, onEnter, useSessions, useWorkspaces, navigate, paletteActions, onReferenceToChat
|
|
7071
|
+
function IdePanel({ store, translate, onBackToChat, onToggleSidebar, onEnter, useSessions, useWorkspaces, navigate, paletteActions, onReferenceToChat }) {
|
|
6987
7072
|
const tr = typeof translate === 'function' ? translate : (key) => key
|
|
6988
7073
|
const actions = paletteActions ?? []
|
|
6989
7074
|
|
|
@@ -7243,18 +7328,7 @@ function IdePanel({ store, translate, onBackToChat, onToggleSidebar, onEnter, us
|
|
|
7243
7328
|
state.themeMenu === true
|
|
7244
7329
|
? h(IdeThemePopup, { key: 'themepopup', store, themeId: ideIsThemeId(state.theme) ? state.theme : '', tr })
|
|
7245
7330
|
: null,
|
|
7246
|
-
|
|
7247
|
-
? null
|
|
7248
|
-
: h(IdeScreenshotPopup, {
|
|
7249
|
-
key: 'shotpopup',
|
|
7250
|
-
state,
|
|
7251
|
-
tr,
|
|
7252
|
-
onJump: onScreenshotJump,
|
|
7253
|
-
onKeep: onScreenshotKeep,
|
|
7254
|
-
onRetry: onScreenshotRetry,
|
|
7255
|
-
onOpenSettings: onScreenshotOpenSettings,
|
|
7256
|
-
onClose: onScreenshotClose,
|
|
7257
|
-
}),
|
|
7331
|
+
|
|
7258
7332
|
h(IdeTreeMenu, {
|
|
7259
7333
|
key: 'treemenu',
|
|
7260
7334
|
store,
|
|
@@ -10356,27 +10430,50 @@ function IdePalette({ store, tr, actions, onClose }) {
|
|
|
10356
10430
|
|
|
10357
10431
|
// ---- 72-screenshot.js ----------------------------------------------------
|
|
10358
10432
|
/**
|
|
10359
|
-
*
|
|
10433
|
+
* Screenshot editor: the Host captures, the panel decides and annotates.
|
|
10360
10434
|
*
|
|
10361
10435
|
* The Web page cannot read the screen (the shell answers `getDisplayMedia` with
|
|
10362
|
-
* a refusal), so the
|
|
10363
|
-
*
|
|
10364
|
-
*
|
|
10365
|
-
*
|
|
10366
|
-
*
|
|
10367
|
-
*
|
|
10368
|
-
*
|
|
10369
|
-
*
|
|
10370
|
-
*
|
|
10371
|
-
*
|
|
10372
|
-
*
|
|
10373
|
-
*
|
|
10374
|
-
*
|
|
10436
|
+
* a refusal), so the Host captures a full screen with an OS built-in tool and
|
|
10437
|
+
* hands it back as a data URL. Everything after that is ordinary Canvas work,
|
|
10438
|
+
* which is why macOS and Windows share this whole file:
|
|
10439
|
+
*
|
|
10440
|
+
* - **range**: the user drags a rectangle on the capture (move it, pull its
|
|
10441
|
+
* handles), and only that rectangle is exported;
|
|
10442
|
+
* - **marks**: rectangle, ellipse, arrow, pen, text and mosaic, each stored as
|
|
10443
|
+
* an operation instead of pixels, so undo is a `pop()` and the export redraws
|
|
10444
|
+
* from the untouched base image;
|
|
10445
|
+
* - **budget**: the export is cropped, scaled to a 1920 long edge and encoded as
|
|
10446
|
+
* JPEG with a quality ladder, so a screenshot stays well under 1 MB.
|
|
10447
|
+
*
|
|
10448
|
+
* Two exits: paste it into the conversation (only an image is added — the draft's
|
|
10449
|
+
* text and attachments are untouched) or copy it to the system clipboard.
|
|
10375
10450
|
*/
|
|
10376
10451
|
|
|
10377
10452
|
const IDE_SHOT_ROUTE = '/dsh-ide/screenshot'
|
|
10378
10453
|
const IDE_SHOT_PERMISSION_ROUTE = '/dsh-ide/screen-permission'
|
|
10379
10454
|
|
|
10455
|
+
/** Long edge of the export; 1920 keeps a 16:9 crop at 1080p. */
|
|
10456
|
+
const IDE_SHOT_EXPORT_EDGE = 1920
|
|
10457
|
+
/** The export must not exceed this when it becomes a chat attachment. */
|
|
10458
|
+
const IDE_SHOT_BUDGET = 1024 * 1024
|
|
10459
|
+
/** JPEG qualities tried in order until the budget is met. */
|
|
10460
|
+
const IDE_SHOT_QUALITIES = [0.8, 0.7, 0.6, 0.5, 0.4]
|
|
10461
|
+
|
|
10462
|
+
/**
|
|
10463
|
+
* Tools the popup card offers.
|
|
10464
|
+
*
|
|
10465
|
+
* `select` is the range tool, not a mark. Ellipse, arrow, pen and mosaic still
|
|
10466
|
+
* have their drawing code (`ideShotDrawOp`) but are not surfaced: the card stays
|
|
10467
|
+
* small, and the two that cover callouts are enough.
|
|
10468
|
+
*/
|
|
10469
|
+
const IDE_SHOT_TOOLS = ['select', 'rect', 'text']
|
|
10470
|
+
/** Stroke colours offered; red first because a screenshot mark is usually red. */
|
|
10471
|
+
const IDE_SHOT_COLORS = ['#ff4d4f', '#ffd666', '#52c41a', '#4f8cff', '#ffffff']
|
|
10472
|
+
/** Stroke widths offered, in image pixels. */
|
|
10473
|
+
const IDE_SHOT_WIDTHS = [2, 4, 8]
|
|
10474
|
+
/** Smallest selection a drag may produce, in image pixels. */
|
|
10475
|
+
const IDE_SHOT_MIN_SELECTION = 24
|
|
10476
|
+
|
|
10380
10477
|
/** POST one screenshot request; never throws, returns `{ ok }` shapes. */
|
|
10381
10478
|
async function ideShotRequest(body) {
|
|
10382
10479
|
let response
|
|
@@ -10417,11 +10514,11 @@ async function ideOpenScreenPermission() {
|
|
|
10417
10514
|
return parsed?.ok === true ? parsed.value : { opened: false }
|
|
10418
10515
|
}
|
|
10419
10516
|
|
|
10420
|
-
/** The image inside a `data:image
|
|
10421
|
-
function ideShotFile(dataUrl, name = 'screenshot.
|
|
10517
|
+
/** The image inside a `data:image/…;base64,…` URL as a `File`. */
|
|
10518
|
+
function ideShotFile(dataUrl, name = 'screenshot.jpg') {
|
|
10422
10519
|
const comma = dataUrl.indexOf(',')
|
|
10423
10520
|
const head = dataUrl.slice(0, comma)
|
|
10424
|
-
const type = /^data:(image\/[a-z+]+)/.exec(head)?.[1] ?? 'image/
|
|
10521
|
+
const type = /^data:(image\/[a-z+]+)/.exec(head)?.[1] ?? 'image/jpeg'
|
|
10425
10522
|
const binary = atob(dataUrl.slice(comma + 1))
|
|
10426
10523
|
const bytes = new Uint8Array(binary.length)
|
|
10427
10524
|
for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index)
|
|
@@ -10433,8 +10530,7 @@ function ideShotFile(dataUrl, name = 'screenshot.png') {
|
|
|
10433
10530
|
*
|
|
10434
10531
|
* Only a paste is dispatched — no editor mutation, no `@` mention flow — so the
|
|
10435
10532
|
* draft keeps whatever the user already typed or attached. Returns `false` when
|
|
10436
|
-
* no composer is on screen, which the caller degrades to "copy it and paste
|
|
10437
|
-
* yourself".
|
|
10533
|
+
* no composer is on screen, which the caller degrades to "copy it and paste".
|
|
10438
10534
|
*/
|
|
10439
10535
|
async function idePasteScreenshot(dataUrl) {
|
|
10440
10536
|
const findEditor = () => (typeof document === 'undefined' ? null : document.querySelector('[data-lexical-editor="true"]'))
|
|
@@ -10449,56 +10545,652 @@ async function idePasteScreenshot(dataUrl) {
|
|
|
10449
10545
|
const transfer = new DataTransfer()
|
|
10450
10546
|
transfer.items.add(file)
|
|
10451
10547
|
editor.focus()
|
|
10452
|
-
|
|
10453
|
-
editor.dispatchEvent(event)
|
|
10548
|
+
editor.dispatchEvent(new ClipboardEvent('paste', { clipboardData: transfer, bubbles: true, cancelable: true }))
|
|
10454
10549
|
return true
|
|
10455
10550
|
}
|
|
10456
10551
|
|
|
10552
|
+
// ------------------------------------------------------------------ geometry
|
|
10553
|
+
// Pure helpers: the editor converts pointer positions into image pixels, keeps
|
|
10554
|
+
// a selection inside the capture and resizes it from one of eight handles.
|
|
10555
|
+
|
|
10556
|
+
/** Scale that fits `width × height` into the given box, never upscaling. */
|
|
10557
|
+
function ideShotFitScale(width, height, boxWidth, boxHeight) {
|
|
10558
|
+
if (!(width > 0) || !(height > 0) || !(boxWidth > 0) || !(boxHeight > 0)) return 1
|
|
10559
|
+
return Math.min(boxWidth / width, boxHeight / height, 1)
|
|
10560
|
+
}
|
|
10561
|
+
|
|
10562
|
+
/** Keep a rectangle inside `bounds` without changing its size (unless it must shrink). */
|
|
10563
|
+
function ideShotClampSelection(rect, bounds) {
|
|
10564
|
+
const width = Math.min(rect.width, bounds.width)
|
|
10565
|
+
const height = Math.min(rect.height, bounds.height)
|
|
10566
|
+
const x = Math.min(Math.max(rect.x, 0), Math.max(bounds.width - width, 0))
|
|
10567
|
+
const y = Math.min(Math.max(rect.y, 0), Math.max(bounds.height - height, 0))
|
|
10568
|
+
return { x, y, width, height }
|
|
10569
|
+
}
|
|
10570
|
+
|
|
10571
|
+
/** A rectangle from two dragged corners, normalized and clamped to the image. */
|
|
10572
|
+
function ideShotRectFromPoints(start, end, bounds) {
|
|
10573
|
+
const x = Math.min(start.x, end.x)
|
|
10574
|
+
const y = Math.min(start.y, end.y)
|
|
10575
|
+
const width = Math.abs(end.x - start.x)
|
|
10576
|
+
const height = Math.abs(end.y - start.y)
|
|
10577
|
+
return ideShotClampSelection({ x, y, width, height }, bounds)
|
|
10578
|
+
}
|
|
10579
|
+
|
|
10580
|
+
/** The eight resize handles of a rectangle, as `{ id, x, y }` in image pixels. */
|
|
10581
|
+
function ideShotHandles(rect) {
|
|
10582
|
+
const midX = rect.x + rect.width / 2
|
|
10583
|
+
const midY = rect.y + rect.height / 2
|
|
10584
|
+
const right = rect.x + rect.width
|
|
10585
|
+
const bottom = rect.y + rect.height
|
|
10586
|
+
return [
|
|
10587
|
+
{ id: 'nw', x: rect.x, y: rect.y },
|
|
10588
|
+
{ id: 'n', x: midX, y: rect.y },
|
|
10589
|
+
{ id: 'ne', x: right, y: rect.y },
|
|
10590
|
+
{ id: 'e', x: right, y: midY },
|
|
10591
|
+
{ id: 'se', x: right, y: bottom },
|
|
10592
|
+
{ id: 's', x: midX, y: bottom },
|
|
10593
|
+
{ id: 'sw', x: rect.x, y: bottom },
|
|
10594
|
+
{ id: 'w', x: rect.x, y: midY },
|
|
10595
|
+
]
|
|
10596
|
+
}
|
|
10597
|
+
|
|
10598
|
+
/** Whether a point is inside `rect`, expanded by `slack` on every side. */
|
|
10599
|
+
function ideShotHitsRect(point, rect, slack) {
|
|
10600
|
+
const pad = Number.isFinite(slack) ? slack : 0
|
|
10601
|
+
return point.x >= rect.x - pad && point.x <= rect.x + rect.width + pad
|
|
10602
|
+
&& point.y >= rect.y - pad && point.y <= rect.y + rect.height + pad
|
|
10603
|
+
}
|
|
10604
|
+
|
|
10605
|
+
/** Resize `rect` by dragging one handle to `point`, keeping it valid and in bounds. */
|
|
10606
|
+
function ideShotResize(rect, handle, point, bounds) {
|
|
10607
|
+
let left = rect.x
|
|
10608
|
+
let top = rect.y
|
|
10609
|
+
let right = rect.x + rect.width
|
|
10610
|
+
let bottom = rect.y + rect.height
|
|
10611
|
+
if (handle.includes('w')) left = point.x
|
|
10612
|
+
if (handle.includes('e')) right = point.x
|
|
10613
|
+
if (handle.includes('n')) top = point.y
|
|
10614
|
+
if (handle.includes('s')) bottom = point.y
|
|
10615
|
+
const x = Math.min(left, right)
|
|
10616
|
+
const y = Math.min(top, bottom)
|
|
10617
|
+
const width = Math.max(Math.abs(right - left), IDE_SHOT_MIN_SELECTION / 4)
|
|
10618
|
+
const height = Math.max(Math.abs(bottom - top), IDE_SHOT_MIN_SELECTION / 4)
|
|
10619
|
+
return ideShotClampSelection({ x, y, width, height }, bounds)
|
|
10620
|
+
}
|
|
10621
|
+
|
|
10622
|
+
/**
|
|
10623
|
+
* Pointer position in image pixels.
|
|
10624
|
+
*
|
|
10625
|
+
* The capture is centred inside the stage, so the offset of the drawn canvas
|
|
10626
|
+
* within the stage is half of the leftover space; `bounds` is the image size
|
|
10627
|
+
* (the stage element itself has no width/height of its own).
|
|
10628
|
+
*/
|
|
10629
|
+
function ideShotPoint(event, stage, scale, bounds) {
|
|
10630
|
+
const box = stage.getBoundingClientRect()
|
|
10631
|
+
const drawnWidth = bounds.width * scale
|
|
10632
|
+
const drawnHeight = bounds.height * scale
|
|
10633
|
+
const x = (event.clientX - box.left - (box.width - drawnWidth) / 2) / scale
|
|
10634
|
+
const y = (event.clientY - box.top - (box.height - drawnHeight) / 2) / scale
|
|
10635
|
+
return {
|
|
10636
|
+
x: Math.max(0, Math.min(Number.isFinite(x) ? x : 0, bounds.width)),
|
|
10637
|
+
y: Math.max(0, Math.min(Number.isFinite(y) ? y : 0, bounds.height)),
|
|
10638
|
+
}
|
|
10639
|
+
}
|
|
10640
|
+
|
|
10641
|
+
// -------------------------------------------------------------------- drawing
|
|
10642
|
+
|
|
10643
|
+
/** Draw one stored operation onto a context that already shows the capture. */
|
|
10644
|
+
function ideShotDrawOp(ctx, op, image) {
|
|
10645
|
+
const color = op.color ?? '#ff4d4f'
|
|
10646
|
+
// `stroke` is the pen width; `width`/`height` are the rectangle being drawn.
|
|
10647
|
+
const stroke = op.stroke ?? 4
|
|
10648
|
+
ctx.save()
|
|
10649
|
+
ctx.strokeStyle = color
|
|
10650
|
+
ctx.fillStyle = color
|
|
10651
|
+
ctx.lineWidth = stroke
|
|
10652
|
+
ctx.lineCap = 'round'
|
|
10653
|
+
ctx.lineJoin = 'round'
|
|
10654
|
+
if (op.tool === 'rect') {
|
|
10655
|
+
ctx.strokeRect(op.x, op.y, op.width, op.height)
|
|
10656
|
+
} else if (op.tool === 'ellipse') {
|
|
10657
|
+
ctx.beginPath()
|
|
10658
|
+
ctx.ellipse(op.x + op.width / 2, op.y + op.height / 2, Math.abs(op.width / 2), Math.abs(op.height / 2), 0, 0, Math.PI * 2)
|
|
10659
|
+
ctx.stroke()
|
|
10660
|
+
} else if (op.tool === 'arrow') {
|
|
10661
|
+
const x1 = op.x
|
|
10662
|
+
const y1 = op.y
|
|
10663
|
+
const x2 = op.x + op.width
|
|
10664
|
+
const y2 = op.y + op.height
|
|
10665
|
+
const angle = Math.atan2(y2 - y1, x2 - x1)
|
|
10666
|
+
const head = Math.max(10, stroke * 4)
|
|
10667
|
+
ctx.beginPath()
|
|
10668
|
+
ctx.moveTo(x1, y1)
|
|
10669
|
+
ctx.lineTo(x2, y2)
|
|
10670
|
+
ctx.stroke()
|
|
10671
|
+
ctx.beginPath()
|
|
10672
|
+
ctx.moveTo(x2, y2)
|
|
10673
|
+
ctx.lineTo(x2 - head * Math.cos(angle - Math.PI / 7), y2 - head * Math.sin(angle - Math.PI / 7))
|
|
10674
|
+
ctx.lineTo(x2 - head * Math.cos(angle + Math.PI / 7), y2 - head * Math.sin(angle + Math.PI / 7))
|
|
10675
|
+
ctx.closePath()
|
|
10676
|
+
ctx.fill()
|
|
10677
|
+
} else if (op.tool === 'pen') {
|
|
10678
|
+
const points = op.points ?? []
|
|
10679
|
+
if (points.length > 1) {
|
|
10680
|
+
ctx.beginPath()
|
|
10681
|
+
ctx.moveTo(points[0].x, points[0].y)
|
|
10682
|
+
for (const point of points.slice(1)) ctx.lineTo(point.x, point.y)
|
|
10683
|
+
ctx.stroke()
|
|
10684
|
+
}
|
|
10685
|
+
} else if (op.tool === 'text') {
|
|
10686
|
+
ctx.font = `${Math.max(12, stroke * 5)}px -apple-system, "Segoe UI", "PingFang SC", sans-serif`
|
|
10687
|
+
ctx.textBaseline = 'top'
|
|
10688
|
+
// A dark halo keeps the label readable on light and dark captures alike.
|
|
10689
|
+
ctx.lineWidth = Math.max(2, stroke / 2)
|
|
10690
|
+
ctx.strokeStyle = 'rgba(0, 0, 0, 0.55)'
|
|
10691
|
+
ctx.strokeText(op.text ?? '', op.x, op.y)
|
|
10692
|
+
ctx.fillStyle = color
|
|
10693
|
+
ctx.fillText(op.text ?? '', op.x, op.y)
|
|
10694
|
+
} else if (op.tool === 'mosaic') {
|
|
10695
|
+
const x = Math.min(op.x, op.x + op.width)
|
|
10696
|
+
const y = Math.min(op.y, op.y + op.height)
|
|
10697
|
+
const w = Math.abs(op.width)
|
|
10698
|
+
const h = Math.abs(op.height)
|
|
10699
|
+
if (w > 2 && h > 2 && image !== undefined) {
|
|
10700
|
+
const block = Math.max(6, Math.round(Math.min(w, h) / 12))
|
|
10701
|
+
const small = document.createElement('canvas')
|
|
10702
|
+
small.width = Math.max(1, Math.round(w / block))
|
|
10703
|
+
small.height = Math.max(1, Math.round(h / block))
|
|
10704
|
+
const smallCtx = small.getContext('2d')
|
|
10705
|
+
smallCtx.imageSmoothingEnabled = true
|
|
10706
|
+
smallCtx.drawImage(image, x, y, w, h, 0, 0, small.width, small.height)
|
|
10707
|
+
ctx.imageSmoothingEnabled = false
|
|
10708
|
+
ctx.drawImage(small, 0, 0, small.width, small.height, x, y, w, h)
|
|
10709
|
+
}
|
|
10710
|
+
}
|
|
10711
|
+
ctx.restore()
|
|
10712
|
+
}
|
|
10713
|
+
|
|
10714
|
+
/** Redraw the whole editor frame: capture, dimmed outside, marks, selection. */
|
|
10715
|
+
function ideShotPaint(canvas, image, ops, draft, selection, showSelection) {
|
|
10716
|
+
const ctx = canvas.getContext('2d')
|
|
10717
|
+
if (ctx === null || image === null) return
|
|
10718
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
|
10719
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
10720
|
+
ctx.drawImage(image, 0, 0, canvas.width, canvas.height)
|
|
10721
|
+
for (const op of ops) ideShotDrawOp(ctx, op, image)
|
|
10722
|
+
if (draft !== null) ideShotDrawOp(ctx, draft, image)
|
|
10723
|
+
if (selection === null) {
|
|
10724
|
+
// Nothing framed yet: dim the whole capture so the hint reads as a mode.
|
|
10725
|
+
ctx.save()
|
|
10726
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.35)'
|
|
10727
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
|
10728
|
+
ctx.restore()
|
|
10729
|
+
} else if (showSelection) {
|
|
10730
|
+
const { x, y, width, height } = selection
|
|
10731
|
+
ctx.save()
|
|
10732
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.45)'
|
|
10733
|
+
ctx.beginPath()
|
|
10734
|
+
ctx.rect(0, 0, canvas.width, canvas.height)
|
|
10735
|
+
ctx.rect(x, y, width, height)
|
|
10736
|
+
ctx.fill('evenodd')
|
|
10737
|
+
ctx.strokeStyle = '#4f8cff'
|
|
10738
|
+
ctx.lineWidth = Math.max(1, canvas.width / 900)
|
|
10739
|
+
ctx.strokeRect(x, y, width, height)
|
|
10740
|
+
for (const handle of ideShotHandles(selection)) {
|
|
10741
|
+
const size = Math.max(6, canvas.width / 160)
|
|
10742
|
+
ctx.fillStyle = '#ffffff'
|
|
10743
|
+
ctx.strokeStyle = '#4f8cff'
|
|
10744
|
+
ctx.lineWidth = Math.max(1, canvas.width / 900)
|
|
10745
|
+
ctx.beginPath()
|
|
10746
|
+
ctx.rect(handle.x - size / 2, handle.y - size / 2, size, size)
|
|
10747
|
+
ctx.fill()
|
|
10748
|
+
ctx.stroke()
|
|
10749
|
+
}
|
|
10750
|
+
ctx.restore()
|
|
10751
|
+
}
|
|
10752
|
+
}
|
|
10753
|
+
|
|
10754
|
+
/**
|
|
10755
|
+
* Crop the selection, redraw the marks and encode within the budget.
|
|
10756
|
+
*
|
|
10757
|
+
* The ladder stops at the first size that fits, so a flat capture keeps its
|
|
10758
|
+
* quality while a text-heavy one steps down instead of blowing the budget.
|
|
10759
|
+
*/
|
|
10760
|
+
function ideShotExport(image, ops, selection) {
|
|
10761
|
+
const sourceX = Math.max(0, Math.round(selection.x))
|
|
10762
|
+
const sourceY = Math.max(0, Math.round(selection.y))
|
|
10763
|
+
const sourceWidth = Math.max(1, Math.round(Math.min(selection.width, image.width - sourceX)))
|
|
10764
|
+
const sourceHeight = Math.max(1, Math.round(Math.min(selection.height, image.height - sourceY)))
|
|
10765
|
+
const scale = Math.min(1, IDE_SHOT_EXPORT_EDGE / Math.max(sourceWidth, sourceHeight))
|
|
10766
|
+
const canvas = document.createElement('canvas')
|
|
10767
|
+
canvas.width = Math.max(1, Math.round(sourceWidth * scale))
|
|
10768
|
+
canvas.height = Math.max(1, Math.round(sourceHeight * scale))
|
|
10769
|
+
const ctx = canvas.getContext('2d')
|
|
10770
|
+
if (ctx === null) return ''
|
|
10771
|
+
ctx.drawImage(image, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, canvas.width, canvas.height)
|
|
10772
|
+
ctx.save()
|
|
10773
|
+
ctx.scale(scale, scale)
|
|
10774
|
+
ctx.translate(-sourceX, -sourceY)
|
|
10775
|
+
for (const op of ops) ideShotDrawOp(ctx, op, image)
|
|
10776
|
+
ctx.restore()
|
|
10777
|
+
let smallest = canvas.toDataURL('image/jpeg', IDE_SHOT_QUALITIES[IDE_SHOT_QUALITIES.length - 1])
|
|
10778
|
+
for (const quality of IDE_SHOT_QUALITIES) {
|
|
10779
|
+
const url = canvas.toDataURL('image/jpeg', quality)
|
|
10780
|
+
if (url.length * 0.75 <= IDE_SHOT_BUDGET) return url
|
|
10781
|
+
if (url.length < smallest.length) smallest = url
|
|
10782
|
+
}
|
|
10783
|
+
return smallest
|
|
10784
|
+
}
|
|
10785
|
+
|
|
10786
|
+
// ------------------------------------------------------------------ component
|
|
10787
|
+
|
|
10788
|
+
/** One toolbar button. */
|
|
10789
|
+
function IdeShotToolButton({ active, label, title, onClick }) {
|
|
10790
|
+
return h('button', {
|
|
10791
|
+
type: 'button',
|
|
10792
|
+
className: `iw-shot-tool${active ? ' on' : ''}`,
|
|
10793
|
+
title,
|
|
10794
|
+
onClick,
|
|
10795
|
+
}, label)
|
|
10796
|
+
}
|
|
10797
|
+
|
|
10457
10798
|
/**
|
|
10458
|
-
* The
|
|
10459
|
-
*
|
|
10799
|
+
* The editor overlay.
|
|
10800
|
+
*
|
|
10801
|
+
* Rendered through `shell.overlay`, so it covers the window regardless of which
|
|
10802
|
+
* column is showing and is never clipped by the panel's overflow.
|
|
10460
10803
|
*/
|
|
10461
|
-
function
|
|
10804
|
+
function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onClose }) {
|
|
10805
|
+
const state = useSyncExternalStore(store.subscribe, store.getState, store.getState)
|
|
10462
10806
|
const shot = state.screenshot ?? null
|
|
10807
|
+
const editing = shot?.phase === 'editing'
|
|
10808
|
+
const [image, setImage] = useState(null)
|
|
10809
|
+
const [tool, setTool] = useState('select')
|
|
10810
|
+
const [color, setColor] = useState(IDE_SHOT_COLORS[0])
|
|
10811
|
+
const [width, setWidth] = useState(IDE_SHOT_WIDTHS[1])
|
|
10812
|
+
const [ops, setOps] = useState([])
|
|
10813
|
+
const [selection, setSelection] = useState(null)
|
|
10814
|
+
/** True while the frame is being dragged: the card only shows once released. */
|
|
10815
|
+
const [dragging, setDragging] = useState(false)
|
|
10816
|
+
const [draft, setDraft] = useState(null)
|
|
10817
|
+
const [textAt, setTextAt] = useState(null)
|
|
10818
|
+
const [textValue, setTextValue] = useState('')
|
|
10819
|
+
const [scale, setScale] = useState(1)
|
|
10820
|
+
const [stageRect, setStageRect] = useState(null)
|
|
10821
|
+
const canvasRef = useRef(null)
|
|
10822
|
+
const frameRef = useRef(null)
|
|
10823
|
+
const dragRef = useRef(null)
|
|
10824
|
+
|
|
10825
|
+
// Load the capture into an <img>: the canvas needs natural pixels, and the
|
|
10826
|
+
// selection is expressed in those pixels.
|
|
10827
|
+
useEffect(() => {
|
|
10828
|
+
if (!editing) {
|
|
10829
|
+
setImage(null)
|
|
10830
|
+
return
|
|
10831
|
+
}
|
|
10832
|
+
setOps([])
|
|
10833
|
+
setDraft(null)
|
|
10834
|
+
setTool('select')
|
|
10835
|
+
setTextAt(null)
|
|
10836
|
+
setSelection(null)
|
|
10837
|
+
const element = new Image()
|
|
10838
|
+
element.onload = () => setImage(element)
|
|
10839
|
+
element.src = shot.dataUrl
|
|
10840
|
+
}, [editing, shot?.dataUrl])
|
|
10841
|
+
|
|
10842
|
+
// Fit the capture into the window and keep it fitted across resizes.
|
|
10843
|
+
useEffect(() => {
|
|
10844
|
+
if (image === null) return
|
|
10845
|
+
const fit = () => {
|
|
10846
|
+
const box = { width: Math.max(320, globalThis.innerWidth - 96), height: Math.max(240, globalThis.innerHeight - 180) }
|
|
10847
|
+
setScale(ideShotFitScale(image.naturalWidth, image.naturalHeight, box.width, box.height))
|
|
10848
|
+
}
|
|
10849
|
+
fit()
|
|
10850
|
+
globalThis.addEventListener?.('resize', fit)
|
|
10851
|
+
return () => globalThis.removeEventListener?.('resize', fit)
|
|
10852
|
+
}, [image])
|
|
10853
|
+
|
|
10854
|
+
// Repaint whenever anything visible changed.
|
|
10855
|
+
useEffect(() => {
|
|
10856
|
+
const canvas = canvasRef.current
|
|
10857
|
+
if (canvas === null || image === null) return
|
|
10858
|
+
canvas.width = image.naturalWidth
|
|
10859
|
+
canvas.height = image.naturalHeight
|
|
10860
|
+
ideShotPaint(canvas, image, ops, draft, selection, selection !== null)
|
|
10861
|
+
}, [image, ops, draft, selection, tool])
|
|
10862
|
+
|
|
10863
|
+
// Undo from anywhere: the overlay never holds focus, so the key is read at
|
|
10864
|
+
// the window instead of relying on a focused element.
|
|
10865
|
+
useEffect(() => {
|
|
10866
|
+
if (!editing) return undefined
|
|
10867
|
+
const onKey = (event) => {
|
|
10868
|
+
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 'z') return
|
|
10869
|
+
event.preventDefault()
|
|
10870
|
+
setOps((list) => list.slice(0, -1))
|
|
10871
|
+
}
|
|
10872
|
+
globalThis.addEventListener?.('keydown', onKey, true)
|
|
10873
|
+
return () => globalThis.removeEventListener?.('keydown', onKey, true)
|
|
10874
|
+
}, [editing])
|
|
10875
|
+
|
|
10876
|
+
// Where the canvas sits on screen: the popup card is anchored to the frame.
|
|
10877
|
+
const layoutKey = selection === null ? '' : `${selection.x},${selection.y},${selection.width},${selection.height}`
|
|
10878
|
+
useEffect(() => {
|
|
10879
|
+
const canvas = canvasRef.current
|
|
10880
|
+
if (canvas === null || image === null) {
|
|
10881
|
+
setStageRect(null)
|
|
10882
|
+
return
|
|
10883
|
+
}
|
|
10884
|
+
const rect = canvas.getBoundingClientRect()
|
|
10885
|
+
setStageRect({ left: rect.left, top: rect.top, width: rect.width, height: rect.height })
|
|
10886
|
+
}, [image, scale, layoutKey])
|
|
10887
|
+
|
|
10888
|
+
const bounds = image === null
|
|
10889
|
+
? { width: 1, height: 1 }
|
|
10890
|
+
: { width: image.naturalWidth, height: image.naturalHeight }
|
|
10891
|
+
|
|
10892
|
+
/** Whether a point may carry a mark (a mark needs a framed area). */
|
|
10893
|
+
const canMark = selection !== null && ideShotHitsRect
|
|
10894
|
+
|
|
10895
|
+
const beginSelection = (point) => {
|
|
10896
|
+
dragRef.current = { mode: 'create', origin: point }
|
|
10897
|
+
setDragging(true)
|
|
10898
|
+
setSelection({ x: point.x, y: point.y, width: 0, height: 0 })
|
|
10899
|
+
}
|
|
10900
|
+
|
|
10901
|
+
/**
|
|
10902
|
+
* Pointer down: dragging on empty space always draws a new frame — that is
|
|
10903
|
+
* the first thing the user does after the shortcut. Inside an existing frame
|
|
10904
|
+
* the active tool decides (range adjust, rectangle, or text).
|
|
10905
|
+
*/
|
|
10906
|
+
const onPointerDown = (event) => {
|
|
10907
|
+
if (image === null) return
|
|
10908
|
+
const frame = frameRef.current
|
|
10909
|
+
if (frame === null) return
|
|
10910
|
+
const point = ideShotPoint(event, frame, scale, bounds)
|
|
10911
|
+
try {
|
|
10912
|
+
frame.setPointerCapture?.(event.pointerId)
|
|
10913
|
+
} catch {
|
|
10914
|
+
/* a synthetic or already-captured pointer: dragging still works */
|
|
10915
|
+
}
|
|
10916
|
+
const inside = selection !== null && selection.width > 0 && ideShotHitsRect(point, selection, 0)
|
|
10917
|
+
if (!inside) {
|
|
10918
|
+
beginSelection(point)
|
|
10919
|
+
return
|
|
10920
|
+
}
|
|
10921
|
+
if (tool === 'text') {
|
|
10922
|
+
setTextAt(point)
|
|
10923
|
+
setTextValue('')
|
|
10924
|
+
return
|
|
10925
|
+
}
|
|
10926
|
+
if (tool === 'rect') {
|
|
10927
|
+
setDraft({ tool, color, stroke: width, x: point.x, y: point.y, width: 0, height: 0, points: [point] })
|
|
10928
|
+
return
|
|
10929
|
+
}
|
|
10930
|
+
// Range tool: handles first, then the body.
|
|
10931
|
+
const handle = ideShotHandles(selection).find((entry) => (
|
|
10932
|
+
Math.abs(entry.x - point.x) <= 12 / scale && Math.abs(entry.y - point.y) <= 12 / scale
|
|
10933
|
+
))
|
|
10934
|
+
if (handle !== undefined) {
|
|
10935
|
+
dragRef.current = { mode: 'resize', handle: handle.id }
|
|
10936
|
+
return
|
|
10937
|
+
}
|
|
10938
|
+
dragRef.current = { mode: 'move', origin: point, start: selection }
|
|
10939
|
+
}
|
|
10940
|
+
|
|
10941
|
+
const onPointerMove = (event) => {
|
|
10942
|
+
const drag = dragRef.current
|
|
10943
|
+
const frame = frameRef.current
|
|
10944
|
+
if (frame === null) return
|
|
10945
|
+
const point = ideShotPoint(event, frame, scale, bounds)
|
|
10946
|
+
if (drag !== null) {
|
|
10947
|
+
if (drag.mode === 'move') {
|
|
10948
|
+
const dx = point.x - drag.origin.x
|
|
10949
|
+
const dy = point.y - drag.origin.y
|
|
10950
|
+
setSelection(ideShotClampSelection({
|
|
10951
|
+
x: drag.start.x + dx,
|
|
10952
|
+
y: drag.start.y + dy,
|
|
10953
|
+
width: drag.start.width,
|
|
10954
|
+
height: drag.start.height,
|
|
10955
|
+
}, bounds))
|
|
10956
|
+
return
|
|
10957
|
+
}
|
|
10958
|
+
if (drag.mode === 'resize') {
|
|
10959
|
+
setSelection(ideShotResize(selection, drag.handle, point, bounds))
|
|
10960
|
+
return
|
|
10961
|
+
}
|
|
10962
|
+
setSelection(ideShotRectFromPoints(drag.origin, point, bounds))
|
|
10963
|
+
return
|
|
10964
|
+
}
|
|
10965
|
+
if (draft !== null) {
|
|
10966
|
+
const next = { ...draft }
|
|
10967
|
+
if (draft.tool === 'pen') next.points = [...draft.points, point]
|
|
10968
|
+
else {
|
|
10969
|
+
next.width = point.x - draft.x
|
|
10970
|
+
next.height = point.y - draft.y
|
|
10971
|
+
}
|
|
10972
|
+
setDraft(next)
|
|
10973
|
+
}
|
|
10974
|
+
}
|
|
10975
|
+
|
|
10976
|
+
const onPointerUp = () => {
|
|
10977
|
+
const drag = dragRef.current
|
|
10978
|
+
dragRef.current = null
|
|
10979
|
+
setDragging(false)
|
|
10980
|
+
if (draft !== null) {
|
|
10981
|
+
const op = draft.tool === 'pen'
|
|
10982
|
+
? { ...draft }
|
|
10983
|
+
: {
|
|
10984
|
+
...draft,
|
|
10985
|
+
x: Math.min(draft.x, draft.x + draft.width),
|
|
10986
|
+
y: Math.min(draft.y, draft.y + draft.height),
|
|
10987
|
+
width: Math.abs(draft.width),
|
|
10988
|
+
height: Math.abs(draft.height),
|
|
10989
|
+
}
|
|
10990
|
+
setDraft(null)
|
|
10991
|
+
if (op.tool === 'pen' ? (op.points?.length ?? 0) > 1 : (op.width > 2 || op.height > 2)) {
|
|
10992
|
+
setOps((list) => [...list, op])
|
|
10993
|
+
}
|
|
10994
|
+
return
|
|
10995
|
+
}
|
|
10996
|
+
if (drag?.mode === 'create' && selection !== null) {
|
|
10997
|
+
// A click (or a stray twitch) is not a frame: drop it and stay unframed.
|
|
10998
|
+
if (selection.width < IDE_SHOT_MIN_SELECTION || selection.height < IDE_SHOT_MIN_SELECTION) {
|
|
10999
|
+
setSelection(null)
|
|
11000
|
+
}
|
|
11001
|
+
}
|
|
11002
|
+
}
|
|
11003
|
+
|
|
11004
|
+
const commitText = () => {
|
|
11005
|
+
if (textAt === null || textValue.trim() === '') {
|
|
11006
|
+
setTextAt(null)
|
|
11007
|
+
return
|
|
11008
|
+
}
|
|
11009
|
+
setOps((list) => [...list, { tool: 'text', x: textAt.x, y: textAt.y, text: textValue.trim(), color, stroke: width }])
|
|
11010
|
+
setTextAt(null)
|
|
11011
|
+
setTextValue('')
|
|
11012
|
+
}
|
|
11013
|
+
|
|
11014
|
+
const undo = () => setOps((list) => list.slice(0, -1))
|
|
11015
|
+
const exportImage = () => (selection === null || image === null ? '' : ideShotExport(image, ops, selection))
|
|
11016
|
+
|
|
11017
|
+
/**
|
|
11018
|
+
* Esc leaves the whole operation — before the first press, and also in the
|
|
11019
|
+
* middle of dragging a frame (the pointer capture is dropped so the "up"
|
|
11020
|
+
* that follows cannot revive it). A text box open eats the first Esc.
|
|
11021
|
+
*
|
|
11022
|
+
* The listener is on `window` in the capture phase: the overlay never takes
|
|
11023
|
+
* focus, and the shell handles Esc for its own panels.
|
|
11024
|
+
*/
|
|
11025
|
+
useEffect(() => {
|
|
11026
|
+
if (!editing) return undefined
|
|
11027
|
+
const onKey = (event) => {
|
|
11028
|
+
if (event.key !== 'Escape') return
|
|
11029
|
+
if (textAt !== null) return
|
|
11030
|
+
event.preventDefault()
|
|
11031
|
+
event.stopPropagation()
|
|
11032
|
+
dragRef.current = null
|
|
11033
|
+
setDragging(false)
|
|
11034
|
+
setDraft(null)
|
|
11035
|
+
onClose()
|
|
11036
|
+
}
|
|
11037
|
+
globalThis.addEventListener?.('keydown', onKey, true)
|
|
11038
|
+
return () => globalThis.removeEventListener?.('keydown', onKey, true)
|
|
11039
|
+
}, [editing, textAt, onClose])
|
|
11040
|
+
|
|
10463
11041
|
if (shot === null) return null
|
|
10464
|
-
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
//
|
|
10468
|
-
|
|
10469
|
-
const
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
} else if (failed) {
|
|
10479
|
-
actions.push(h('button', { key: 'retry', type: 'button', className: 'iw-shot-primary', onClick: onRetry }, tr('shotRetry')))
|
|
10480
|
-
actions.push(h('button', { key: 'close', type: 'button', className: 'iw-shot-button', onClick: onClose }, tr('setupClose')))
|
|
10481
|
-
} else {
|
|
10482
|
-
actions.push(h('button', { key: 'jump', type: 'button', className: 'iw-shot-primary', onClick: onJump }, tr('shotJump')))
|
|
10483
|
-
actions.push(h('button', { key: 'keep', type: 'button', className: 'iw-shot-button', onClick: onKeep }, tr('shotKeep')))
|
|
10484
|
-
actions.push(h('button', { key: 'close', type: 'button', className: 'iw-shot-button', onClick: onClose }, tr('setupClose')))
|
|
11042
|
+
|
|
11043
|
+
// The editor renders through `shell.overlay`, i.e. outside the panel: the
|
|
11044
|
+
// workspace stylesheet is only mounted by the panel components, so without
|
|
11045
|
+
// this the card falls back to browser-default buttons (white) and fonts.
|
|
11046
|
+
const styled = (node) => h(React.Fragment, null, [h(IdeStyles, { key: 'style' }), node])
|
|
11047
|
+
const palette = ideIsThemeId(state.theme) ? { 'data-dsh-theme': state.theme } : {}
|
|
11048
|
+
|
|
11049
|
+
// Typography follows the user's own settings; the variables are set here
|
|
11050
|
+
// because `.iw-root` (which normally sets them) is not an ancestor.
|
|
11051
|
+
const skin = {
|
|
11052
|
+
fontFamily: 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
|
|
11053
|
+
fontSize: `${Number.isFinite(state.treeFontSize) ? state.treeFontSize : 14.5}px`,
|
|
11054
|
+
'--iw-code-font-size': `${Number.isFinite(state.codeFontSize) ? state.codeFontSize : 12.5}px`,
|
|
11055
|
+
'--iw-tree-font-size': `${Number.isFinite(state.treeFontSize) ? state.treeFontSize : 14.5}px`,
|
|
10485
11056
|
}
|
|
10486
11057
|
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
11058
|
+
if (shot.phase === 'error') {
|
|
11059
|
+
const needsPermission = shot.code === 'no-screen-permission'
|
|
11060
|
+
const isMac = ideHostIsMacos()
|
|
11061
|
+
const actions = []
|
|
11062
|
+
if (needsPermission && isMac) {
|
|
11063
|
+
actions.push(h('button', { key: 'settings', type: 'button', className: 'iw-shot-primary', onClick: onOpenSettings }, tr('shotOpenSettings')))
|
|
11064
|
+
}
|
|
11065
|
+
actions.push(h('button', { key: 'close', type: 'button', className: 'iw-shot-button', onClick: onClose }, tr('setupClose')))
|
|
11066
|
+
return styled(h('div', { className: 'iw-shot-veil', style: skin, ...palette }, [
|
|
11067
|
+
h('div', { key: 'card', className: 'iw-shot' }, [
|
|
11068
|
+
h('div', { key: 'title', className: 'iw-shot-title' }, needsPermission ? tr('shotNoPermissionTitle') : tr('shotFailed')),
|
|
11069
|
+
h('div', { key: 'guide', className: 'iw-shot-guide' }, needsPermission
|
|
11070
|
+
? (isMac ? tr('shotNoPermissionMac') : tr('shotNoPermissionWindows'))
|
|
11071
|
+
: (shot.message === '' ? tr('shotFailed') : `${tr('shotFailed')}:${shot.message}`)),
|
|
11072
|
+
h('div', { key: 'actions', className: 'iw-shot-actions' }, actions),
|
|
11073
|
+
]),
|
|
11074
|
+
]))
|
|
11075
|
+
}
|
|
11076
|
+
|
|
11077
|
+
if (image === null) {
|
|
11078
|
+
return styled(h('div', { className: 'iw-shot-veil', style: skin, ...palette }, [
|
|
11079
|
+
h('div', { key: 'card', className: 'iw-shot' }, [h('div', { key: 'title', className: 'iw-shot-title' }, tr('shotBusy'))]),
|
|
11080
|
+
]))
|
|
11081
|
+
}
|
|
11082
|
+
|
|
11083
|
+
// The popup card: below the frame, or above it when the bottom is crowded.
|
|
11084
|
+
const card = (() => {
|
|
11085
|
+
if (selection === null || dragging || stageRect === null) return null
|
|
11086
|
+
const cardWidth = 392
|
|
11087
|
+
const frameLeft = stageRect.left + selection.x * scale
|
|
11088
|
+
const frameTop = stageRect.top + selection.y * scale
|
|
11089
|
+
const frameWidth = selection.width * scale
|
|
11090
|
+
const frameHeight = selection.height * scale
|
|
11091
|
+
const left = Math.max(8, Math.min(globalThis.innerWidth - cardWidth - 8, frameLeft + frameWidth / 2 - cardWidth / 2))
|
|
11092
|
+
const below = frameTop + frameHeight + 10
|
|
11093
|
+
const top = below + 44 <= globalThis.innerHeight ? below : Math.max(8, frameTop - 44)
|
|
11094
|
+
const pick = (id) => {
|
|
11095
|
+
setTool(tool === id ? 'select' : id)
|
|
11096
|
+
setTextAt(null)
|
|
11097
|
+
}
|
|
11098
|
+
return h('div', {
|
|
11099
|
+
className: 'iw-shot-card',
|
|
11100
|
+
style: { left: `${left}px`, top: `${top}px`, width: `${cardWidth}px` },
|
|
11101
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
11102
|
+
}, [
|
|
11103
|
+
h('button', {
|
|
11104
|
+
key: 'rect',
|
|
11105
|
+
type: 'button',
|
|
11106
|
+
className: `iw-btn${tool === 'rect' ? ' on' : ''}`,
|
|
11107
|
+
title: tr('shotTool_rect'),
|
|
11108
|
+
onClick: () => pick('rect'),
|
|
11109
|
+
}, tr('shotTool_rect')),
|
|
11110
|
+
h('button', {
|
|
11111
|
+
key: 'text',
|
|
11112
|
+
type: 'button',
|
|
11113
|
+
className: `iw-btn${tool === 'text' ? ' on' : ''}`,
|
|
11114
|
+
title: tr('shotTool_text'),
|
|
11115
|
+
onClick: () => pick('text'),
|
|
11116
|
+
}, tr('shotTool_text')),
|
|
11117
|
+
h('button', {
|
|
11118
|
+
key: 'undo',
|
|
11119
|
+
type: 'button',
|
|
11120
|
+
className: 'iw-btn',
|
|
11121
|
+
disabled: ops.length === 0,
|
|
11122
|
+
onClick: undo,
|
|
11123
|
+
}, tr('shotUndo')),
|
|
11124
|
+
h('span', { key: 'grow', className: 'iw-shot-grow' }),
|
|
11125
|
+
h('button', {
|
|
11126
|
+
key: 'copy',
|
|
11127
|
+
type: 'button',
|
|
11128
|
+
className: 'iw-btn',
|
|
11129
|
+
onClick: () => { const url = exportImage(); if (url !== '') onCopy(url) },
|
|
11130
|
+
}, tr('shotCopy')),
|
|
11131
|
+
h('button', {
|
|
11132
|
+
key: 'insert',
|
|
11133
|
+
type: 'button',
|
|
11134
|
+
className: 'iw-btn primary',
|
|
11135
|
+
onClick: () => { const url = exportImage(); if (url !== '') onInsert(url) },
|
|
11136
|
+
}, tr('shotJump')),
|
|
11137
|
+
])
|
|
11138
|
+
})()
|
|
10490
11139
|
|
|
10491
|
-
return h('div', {
|
|
10492
|
-
className: 'iw-shot',
|
|
10493
|
-
|
|
11140
|
+
return styled(h('div', {
|
|
11141
|
+
className: 'iw-shot-veil iw-shot-veil--editor',
|
|
11142
|
+
style: skin,
|
|
11143
|
+
...palette,
|
|
11144
|
+
tabIndex: -1,
|
|
11145
|
+
onKeyDown: (event) => {
|
|
11146
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'z') {
|
|
11147
|
+
event.preventDefault()
|
|
11148
|
+
undo()
|
|
11149
|
+
}
|
|
11150
|
+
},
|
|
10494
11151
|
}, [
|
|
10495
|
-
h('div', { key: '
|
|
10496
|
-
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10501
|
-
|
|
11152
|
+
h('div', { key: 'hint', className: 'iw-shot-hint iw-shot-hint--top' }, selection === null || dragging ? tr('shotSelectHint') : tr('shotMarkHint')),
|
|
11153
|
+
h('div', {
|
|
11154
|
+
key: 'stage',
|
|
11155
|
+
ref: frameRef,
|
|
11156
|
+
className: 'iw-shot-stage',
|
|
11157
|
+
onPointerDown: onPointerDown,
|
|
11158
|
+
onPointerMove: onPointerMove,
|
|
11159
|
+
onPointerUp: onPointerUp,
|
|
11160
|
+
onPointerCancel: onPointerUp,
|
|
11161
|
+
}, [
|
|
11162
|
+
h('canvas', {
|
|
11163
|
+
key: 'canvas',
|
|
11164
|
+
ref: canvasRef,
|
|
11165
|
+
className: 'iw-shot-canvas',
|
|
11166
|
+
style: {
|
|
11167
|
+
width: `${Math.round(image.naturalWidth * scale)}px`,
|
|
11168
|
+
height: `${Math.round(image.naturalHeight * scale)}px`,
|
|
11169
|
+
},
|
|
11170
|
+
}),
|
|
11171
|
+
textAt === null ? null : h('input', {
|
|
11172
|
+
key: 'text',
|
|
11173
|
+
className: 'iw-shot-text',
|
|
11174
|
+
autoFocus: true,
|
|
11175
|
+
value: textValue,
|
|
11176
|
+
placeholder: tr('shotTextPlaceholder'),
|
|
11177
|
+
style: {
|
|
11178
|
+
left: `${textAt.x * scale}px`,
|
|
11179
|
+
top: `${textAt.y * scale}px`,
|
|
11180
|
+
},
|
|
11181
|
+
onChange: (event) => setTextValue(event.target.value),
|
|
11182
|
+
onKeyDown: (event) => {
|
|
11183
|
+
event.stopPropagation()
|
|
11184
|
+
if (event.key === 'Enter') commitText()
|
|
11185
|
+
if (event.key === 'Escape') {
|
|
11186
|
+
setTextAt(null)
|
|
11187
|
+
setTextValue('')
|
|
11188
|
+
}
|
|
11189
|
+
},
|
|
11190
|
+
}),
|
|
11191
|
+
]),
|
|
11192
|
+
card,
|
|
11193
|
+
]))
|
|
10502
11194
|
}
|
|
10503
11195
|
|
|
10504
11196
|
// ---- 90-apply.js ---------------------------------------------------------
|
|
@@ -10808,32 +11500,47 @@ function apply(ctx) {
|
|
|
10808
11500
|
* draft's text and attachments are untouched; "只截图" puts it on the system
|
|
10809
11501
|
* clipboard and keeps the file.
|
|
10810
11502
|
*/
|
|
11503
|
+
/**
|
|
11504
|
+
* Capture first, render after.
|
|
11505
|
+
*
|
|
11506
|
+
* Anything drawn before the Host grabs the screen ends up *inside* the
|
|
11507
|
+
* screenshot — an overlay that says "capturing…" would be printed onto the
|
|
11508
|
+
* picture. So the panel stays untouched until the image arrives, and a short
|
|
11509
|
+
* guard keeps a double press from firing two captures.
|
|
11510
|
+
*/
|
|
11511
|
+
let screenshotBusy = false
|
|
10811
11512
|
async function startScreenshot() {
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
11513
|
+
if (screenshotBusy) return
|
|
11514
|
+
if (store.getState().screenshot !== null) return
|
|
11515
|
+
screenshotBusy = true
|
|
11516
|
+
try {
|
|
11517
|
+
const result = await ideShotRequest({})
|
|
11518
|
+
if (!result.ok) {
|
|
11519
|
+
store.setScreenshot({ phase: 'error', code: result.code, message: result.message })
|
|
11520
|
+
return
|
|
11521
|
+
}
|
|
11522
|
+
// The editor owns the capture from here: range, marks, export.
|
|
11523
|
+
store.setScreenshot({ phase: 'editing', ...result.value })
|
|
11524
|
+
} finally {
|
|
11525
|
+
screenshotBusy = false
|
|
10818
11526
|
}
|
|
10819
|
-
store.setScreenshot({ phase: 'ready', ...result.value })
|
|
10820
11527
|
}
|
|
10821
11528
|
|
|
10822
|
-
|
|
10823
|
-
|
|
11529
|
+
/** The editor's "insert" exit: back to the chat, paste only that image. */
|
|
11530
|
+
async function screenshotInsert(dataUrl) {
|
|
10824
11531
|
store.setScreenshot(null)
|
|
10825
11532
|
backToChat()
|
|
10826
|
-
if (
|
|
10827
|
-
const pasted = await idePasteScreenshot(
|
|
11533
|
+
if (typeof dataUrl !== 'string' || dataUrl === '') return
|
|
11534
|
+
const pasted = await idePasteScreenshot(dataUrl)
|
|
10828
11535
|
store.setNotice(pasted ? translate('shotAttached') : translate('shotNoEditor'))
|
|
10829
11536
|
}
|
|
10830
11537
|
|
|
10831
|
-
|
|
10832
|
-
|
|
11538
|
+
/** The editor's "copy" exit: the annotated result goes to the clipboard. */
|
|
11539
|
+
async function screenshotCopy(dataUrl) {
|
|
11540
|
+
if (typeof dataUrl !== 'string' || dataUrl === '') return
|
|
11541
|
+
const copied = await ideShotRequest({ copyDataUrl: dataUrl })
|
|
10833
11542
|
store.setScreenshot(null)
|
|
10834
|
-
|
|
10835
|
-
const copied = await ideShotRequest({ copyOf: shot.path })
|
|
10836
|
-
store.setNotice(copied.ok ? `${translate('shotCopied')}: ${shot.path}` : translate('shotFailed'))
|
|
11543
|
+
store.setNotice(copied.ok ? translate('shotCopied') : translate('shotFailed'))
|
|
10837
11544
|
}
|
|
10838
11545
|
|
|
10839
11546
|
async function screenshotOpenSettings() {
|
|
@@ -10842,7 +11549,6 @@ function apply(ctx) {
|
|
|
10842
11549
|
}
|
|
10843
11550
|
|
|
10844
11551
|
const screenshotClose = () => store.setScreenshot(null)
|
|
10845
|
-
const screenshotRetry = () => { void startScreenshot() }
|
|
10846
11552
|
|
|
10847
11553
|
/**
|
|
10848
11554
|
* Back to the conversation with the reference appended to the draft.
|
|
@@ -11243,11 +11949,6 @@ function apply(ctx) {
|
|
|
11243
11949
|
navigate,
|
|
11244
11950
|
paletteActions,
|
|
11245
11951
|
onReferenceToChat: referenceToChat,
|
|
11246
|
-
onScreenshotJump: screenshotJump,
|
|
11247
|
-
onScreenshotKeep: screenshotKeep,
|
|
11248
|
-
onScreenshotRetry: screenshotRetry,
|
|
11249
|
-
onScreenshotOpenSettings: screenshotOpenSettings,
|
|
11250
|
-
onScreenshotClose: screenshotClose,
|
|
11251
11952
|
}),
|
|
11252
11953
|
}, IdePanel))
|
|
11253
11954
|
ctx.effect(() => {
|
|
@@ -11265,11 +11966,6 @@ function apply(ctx) {
|
|
|
11265
11966
|
navigate,
|
|
11266
11967
|
paletteActions,
|
|
11267
11968
|
onReferenceToChat: referenceToChat,
|
|
11268
|
-
onScreenshotJump: screenshotJump,
|
|
11269
|
-
onScreenshotKeep: screenshotKeep,
|
|
11270
|
-
onScreenshotRetry: screenshotRetry,
|
|
11271
|
-
onScreenshotOpenSettings: screenshotOpenSettings,
|
|
11272
|
-
onScreenshotClose: screenshotClose,
|
|
11273
11969
|
}),
|
|
11274
11970
|
}, IdePanel))
|
|
11275
11971
|
mainRegistered = true
|
|
@@ -11488,6 +12184,24 @@ function apply(ctx) {
|
|
|
11488
12184
|
inject: () => ({ store }),
|
|
11489
12185
|
}, IdeSessionTracker)), 'dsh-ide-window: session tracker')
|
|
11490
12186
|
|
|
12187
|
+
// The screenshot editor lives at shell level: it must cover the window (not
|
|
12188
|
+
// the centre panel) and must not be clipped by the panel's overflow.
|
|
12189
|
+
ctx.effect(() => ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
12190
|
+
name: 'shell.overlay',
|
|
12191
|
+
id: `${IDE_NS}:screenshot`,
|
|
12192
|
+
order: 41,
|
|
12193
|
+
registrant: IDE_NS,
|
|
12194
|
+
locale: IDE_NS,
|
|
12195
|
+
inject: () => ({
|
|
12196
|
+
store,
|
|
12197
|
+
tr: translate,
|
|
12198
|
+
onInsert: screenshotInsert,
|
|
12199
|
+
onCopy: screenshotCopy,
|
|
12200
|
+
onOpenSettings: screenshotOpenSettings,
|
|
12201
|
+
onClose: screenshotClose,
|
|
12202
|
+
}),
|
|
12203
|
+
}, IdeScreenshotEditor)), 'dsh-ide-window: screenshot editor')
|
|
12204
|
+
|
|
11491
12205
|
|
|
11492
12206
|
/**
|
|
11493
12207
|
* The right-Sidebar page type and its body.
|