dsh-ide-window 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +50 -13
- package/CHANGELOG.md +29 -0
- package/README.md +15 -5
- package/client.js +934 -126
- package/index.js +53 -25
- package/locale/en.json +7 -5
- package/locale/zh.json +7 -5
- package/package.json +1 -1
- package/platform/contract.js +4 -2
- package/platform/macos.js +4 -2
- package/platform/windows.js +6 -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,12 @@ 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
|
+
"shotTool_rect": "Box",
|
|
252
|
+
"shotTool_text": "Text",
|
|
253
|
+
"shotUndo": "Undo",
|
|
254
|
+
"shotTextPlaceholder": "Type, then press Enter",
|
|
255
|
+
"shotCopy": "Capture",
|
|
256
|
+
"shotJump": "Capture and open chat",
|
|
255
257
|
}
|
|
256
258
|
const IDE_TEXT_ZH = {
|
|
257
259
|
"title": "代码工作区",
|
|
@@ -481,11 +483,7 @@ window.__ModuleLoader__.load({
|
|
|
481
483
|
"theme_solarized_light": "Solarized 浅色",
|
|
482
484
|
"theme_intellij_light": "IntelliJ 浅色",
|
|
483
485
|
"shortcutScreenshot": "截图(可跳转会话)",
|
|
484
|
-
"shotTitle": "截图完成",
|
|
485
486
|
"shotBusy": "正在截图…",
|
|
486
|
-
"shotPreview": "截图预览",
|
|
487
|
-
"shotJump": "截图并跳转会话",
|
|
488
|
-
"shotKeep": "只截图(复制到剪贴板)",
|
|
489
487
|
"shotRetry": "重试",
|
|
490
488
|
"shotFailed": "截图失败",
|
|
491
489
|
"shotNoPermissionTitle": "无法截图:缺少屏幕录制权限",
|
|
@@ -497,6 +495,12 @@ window.__ModuleLoader__.load({
|
|
|
497
495
|
"shotNoEditor": "没找到对话框:截图已复制到剪贴板,按 ⌘V 粘贴",
|
|
498
496
|
"shotOpenFailed": "打不开系统设置,请手动打开:系统设置 → 隐私与安全性 → 屏幕录制",
|
|
499
497
|
"paletteActionScreenshot": "截图",
|
|
498
|
+
"shotTool_rect": "矩形",
|
|
499
|
+
"shotTool_text": "文字",
|
|
500
|
+
"shotUndo": "撤销",
|
|
501
|
+
"shotTextPlaceholder": "输入文字后回车",
|
|
502
|
+
"shotCopy": "截图",
|
|
503
|
+
"shotJump": "截图并跳转会话",
|
|
500
504
|
}
|
|
501
505
|
|
|
502
506
|
// ---- 00-css.js -----------------------------------------------------------
|
|
@@ -1982,11 +1986,26 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
1982
1986
|
.iw-theme-dot--solarized-light { background: #fdf6e3; }
|
|
1983
1987
|
.iw-theme-dot--intellij-light { background: #f7f8fa; }
|
|
1984
1988
|
|
|
1985
|
-
/* ---- screenshot
|
|
1989
|
+
/* ---- screenshot: veil, permission card, editor ---- */
|
|
1990
|
+
.iw-shot-veil {
|
|
1991
|
+
position: fixed;
|
|
1992
|
+
inset: 0;
|
|
1993
|
+
display: flex;
|
|
1994
|
+
align-items: center;
|
|
1995
|
+
justify-content: center;
|
|
1996
|
+
background: rgba(0, 0, 0, 0.45);
|
|
1997
|
+
z-index: 60;
|
|
1998
|
+
}
|
|
1999
|
+
.iw-shot-veil--editor {
|
|
2000
|
+
flex-direction: column;
|
|
2001
|
+
gap: 0;
|
|
2002
|
+
padding: 0;
|
|
2003
|
+
box-sizing: border-box;
|
|
2004
|
+
background: #000;
|
|
2005
|
+
outline: none;
|
|
2006
|
+
overflow: hidden;
|
|
2007
|
+
}
|
|
1986
2008
|
.iw-shot {
|
|
1987
|
-
position: absolute;
|
|
1988
|
-
right: 16px;
|
|
1989
|
-
bottom: 40px;
|
|
1990
2009
|
width: 420px;
|
|
1991
2010
|
max-width: calc(100% - 32px);
|
|
1992
2011
|
padding: 14px;
|
|
@@ -1995,7 +2014,6 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
1995
2014
|
border-radius: var(--dsw-radius-lg, 10px);
|
|
1996
2015
|
background: var(--dsw-alias-bg-layer-2, #23262c);
|
|
1997
2016
|
box-shadow: var(--dsw-elevation-prominent, 0 12px 32px rgba(0, 0, 0, 0.4));
|
|
1998
|
-
z-index: 45;
|
|
1999
2017
|
}
|
|
2000
2018
|
.iw-shot-title {
|
|
2001
2019
|
font-size: 13px;
|
|
@@ -2008,16 +2026,6 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2008
2026
|
font-size: 12px;
|
|
2009
2027
|
line-height: 1.6;
|
|
2010
2028
|
}
|
|
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
2029
|
.iw-shot-actions {
|
|
2022
2030
|
display: flex;
|
|
2023
2031
|
align-items: center;
|
|
@@ -2025,9 +2033,8 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2025
2033
|
gap: 8px;
|
|
2026
2034
|
margin-top: 12px;
|
|
2027
2035
|
}
|
|
2028
|
-
.iw-shot-
|
|
2029
|
-
|
|
2030
|
-
font-size: 12px;
|
|
2036
|
+
.iw-shot-actions--bar {
|
|
2037
|
+
margin-top: 0;
|
|
2031
2038
|
}
|
|
2032
2039
|
.iw-shot-button,
|
|
2033
2040
|
.iw-shot-primary {
|
|
@@ -2041,14 +2048,108 @@ html.iw-select-code .iw-code .iw-vision {
|
|
|
2041
2048
|
font-size: 12px;
|
|
2042
2049
|
cursor: pointer;
|
|
2043
2050
|
}
|
|
2051
|
+
.iw-shot-button:disabled {
|
|
2052
|
+
opacity: 0.45;
|
|
2053
|
+
cursor: default;
|
|
2054
|
+
}
|
|
2044
2055
|
.iw-shot-primary {
|
|
2045
2056
|
border-color: transparent;
|
|
2046
2057
|
background: var(--dsw-alias-brand-primary, #4f8cff);
|
|
2047
2058
|
color: #fff;
|
|
2048
2059
|
}
|
|
2049
|
-
.iw-shot-button:hover {
|
|
2060
|
+
.iw-shot-button:hover:not(:disabled) {
|
|
2050
2061
|
background: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, 0.16));
|
|
2051
2062
|
}
|
|
2063
|
+
.iw-shot-card {
|
|
2064
|
+
position: fixed;
|
|
2065
|
+
display: flex;
|
|
2066
|
+
align-items: center;
|
|
2067
|
+
flex-wrap: nowrap;
|
|
2068
|
+
gap: 4px;
|
|
2069
|
+
padding: 5px 6px;
|
|
2070
|
+
box-sizing: border-box;
|
|
2071
|
+
border-radius: var(--dsw-radius-md, 8px);
|
|
2072
|
+
background: var(--dsw-alias-bg-layer-2, #23262c);
|
|
2073
|
+
border: 1px solid var(--dsw-alias-border-l1, #2c3038);
|
|
2074
|
+
box-shadow: var(--dsw-elevation-prominent, 0 10px 28px rgba(0, 0, 0, 0.45));
|
|
2075
|
+
color: var(--dsw-alias-label-primary, #e6e8ec);
|
|
2076
|
+
z-index: 62;
|
|
2077
|
+
}
|
|
2078
|
+
.iw-shot-tool,
|
|
2079
|
+
.iw-shot-card .iw-shot-button,
|
|
2080
|
+
.iw-shot-card .iw-shot-primary {
|
|
2081
|
+
flex: 0 0 auto;
|
|
2082
|
+
white-space: nowrap;
|
|
2083
|
+
}
|
|
2084
|
+
.iw-shot-card .iw-btn {
|
|
2085
|
+
flex: 0 0 auto;
|
|
2086
|
+
white-space: nowrap;
|
|
2087
|
+
font-size: inherit;
|
|
2088
|
+
}
|
|
2089
|
+
.iw-shot-card .iw-sep {
|
|
2090
|
+
width: 1px;
|
|
2091
|
+
height: 16px;
|
|
2092
|
+
margin: 0 2px;
|
|
2093
|
+
flex: 0 0 auto;
|
|
2094
|
+
background: var(--dsw-alias-border-l1, #2c3038);
|
|
2095
|
+
}
|
|
2096
|
+
.iw-shot-grow {
|
|
2097
|
+
flex: 1;
|
|
2098
|
+
}
|
|
2099
|
+
.iw-shot-hint {
|
|
2100
|
+
color: var(--dsw-alias-label-secondary, #98a0ad);
|
|
2101
|
+
}
|
|
2102
|
+
.iw-shot-hint--top {
|
|
2103
|
+
padding: 0 4px 2px;
|
|
2104
|
+
text-align: center;
|
|
2105
|
+
}
|
|
2106
|
+
.iw-shot-stage {
|
|
2107
|
+
position: relative;
|
|
2108
|
+
display: flex;
|
|
2109
|
+
align-items: center;
|
|
2110
|
+
justify-content: center;
|
|
2111
|
+
flex: 1;
|
|
2112
|
+
min-height: 0;
|
|
2113
|
+
width: 100%;
|
|
2114
|
+
touch-action: none;
|
|
2115
|
+
cursor: crosshair;
|
|
2116
|
+
}
|
|
2117
|
+
.iw-shot-frame {
|
|
2118
|
+
position: relative;
|
|
2119
|
+
display: block;
|
|
2120
|
+
flex: 0 0 auto;
|
|
2121
|
+
}
|
|
2122
|
+
.iw-shot-canvas {
|
|
2123
|
+
display: block;
|
|
2124
|
+
width: 100%;
|
|
2125
|
+
height: 100%;
|
|
2126
|
+
border-radius: 4px;
|
|
2127
|
+
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
|
|
2128
|
+
}
|
|
2129
|
+
/* The text box has to sit *on* the picture without covering it: no fill, no
|
|
2130
|
+
chrome, just a hairline so the caret has somewhere to live. Its colour is the
|
|
2131
|
+
annotation colour, so what you type looks like the mark you will get. */
|
|
2132
|
+
.iw-shot-text {
|
|
2133
|
+
position: absolute;
|
|
2134
|
+
min-width: 0;
|
|
2135
|
+
margin: 0;
|
|
2136
|
+
padding: 1px 2px;
|
|
2137
|
+
border: 1px dashed color-mix(in srgb, currentColor 55%, transparent);
|
|
2138
|
+
border-radius: 3px;
|
|
2139
|
+
background: transparent;
|
|
2140
|
+
color: currentColor;
|
|
2141
|
+
font-family: -apple-system, "Segoe UI", "PingFang SC", sans-serif;
|
|
2142
|
+
font-weight: 600;
|
|
2143
|
+
line-height: 1.25;
|
|
2144
|
+
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
|
|
2145
|
+
caret-color: currentColor;
|
|
2146
|
+
outline: none;
|
|
2147
|
+
}
|
|
2148
|
+
.iw-shot-text::placeholder {
|
|
2149
|
+
color: currentColor;
|
|
2150
|
+
opacity: 0.45;
|
|
2151
|
+
font-weight: 400;
|
|
2152
|
+
}
|
|
2052
2153
|
|
|
2053
2154
|
`
|
|
2054
2155
|
|
|
@@ -3238,7 +3339,7 @@ function ideCreateStore(refs) {
|
|
|
3238
3339
|
themeMenu: false,
|
|
3239
3340
|
/**
|
|
3240
3341
|
* Screenshot dialog: `null` when closed, otherwise
|
|
3241
|
-
* `{ phase: '
|
|
3342
|
+
* `{ phase: 'editing' | 'error', dataUrl?, path?, code?, message? }`.
|
|
3242
3343
|
*/
|
|
3243
3344
|
screenshot: null,
|
|
3244
3345
|
/** Editor and tree font sizes, in px, shared by the whole workspace. */
|
|
@@ -6983,7 +7084,7 @@ function IdeSetupDialog({ tr, open, busy, still, onCheck, onClose, store }) {
|
|
|
6983
7084
|
/** How many times the panel body has rendered; a probe can read it. */
|
|
6984
7085
|
let idePanelRenders = 0
|
|
6985
7086
|
|
|
6986
|
-
function IdePanel({ store, translate, onBackToChat, onToggleSidebar, onEnter, useSessions, useWorkspaces, navigate, paletteActions, onReferenceToChat
|
|
7087
|
+
function IdePanel({ store, translate, onBackToChat, onToggleSidebar, onEnter, useSessions, useWorkspaces, navigate, paletteActions, onReferenceToChat }) {
|
|
6987
7088
|
const tr = typeof translate === 'function' ? translate : (key) => key
|
|
6988
7089
|
const actions = paletteActions ?? []
|
|
6989
7090
|
|
|
@@ -7243,18 +7344,7 @@ function IdePanel({ store, translate, onBackToChat, onToggleSidebar, onEnter, us
|
|
|
7243
7344
|
state.themeMenu === true
|
|
7244
7345
|
? h(IdeThemePopup, { key: 'themepopup', store, themeId: ideIsThemeId(state.theme) ? state.theme : '', tr })
|
|
7245
7346
|
: 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
|
-
}),
|
|
7347
|
+
|
|
7258
7348
|
h(IdeTreeMenu, {
|
|
7259
7349
|
key: 'treemenu',
|
|
7260
7350
|
store,
|
|
@@ -10356,27 +10446,51 @@ function IdePalette({ store, tr, actions, onClose }) {
|
|
|
10356
10446
|
|
|
10357
10447
|
// ---- 72-screenshot.js ----------------------------------------------------
|
|
10358
10448
|
/**
|
|
10359
|
-
*
|
|
10449
|
+
* Screenshot editor: the Host captures, the panel decides and annotates.
|
|
10360
10450
|
*
|
|
10361
10451
|
* 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
|
-
*
|
|
10452
|
+
* a refusal), so the Host captures a full screen with an OS built-in tool and
|
|
10453
|
+
* hands it back as a data URL. Everything after that is ordinary Canvas work,
|
|
10454
|
+
* which is why macOS and Windows share this whole file:
|
|
10455
|
+
*
|
|
10456
|
+
* - **range**: the user drags a rectangle on the capture (move it, pull its
|
|
10457
|
+
* handles), and only that rectangle is exported;
|
|
10458
|
+
* - **marks**: rectangle, ellipse, arrow, pen, text and mosaic, each stored as
|
|
10459
|
+
* an operation instead of pixels, so undo is a `pop()` and the export redraws
|
|
10460
|
+
* from the untouched base image;
|
|
10461
|
+
* - **budget**: the export is cropped, scaled to a 1920 long edge and encoded as
|
|
10462
|
+
* JPEG with a quality ladder, so a screenshot stays well under 1 MB.
|
|
10463
|
+
*
|
|
10464
|
+
* Two exits: paste it into the conversation (only an image is added — the draft's
|
|
10465
|
+
* text and attachments are untouched) or copy it to the system clipboard.
|
|
10375
10466
|
*/
|
|
10376
10467
|
|
|
10377
10468
|
const IDE_SHOT_ROUTE = '/dsh-ide/screenshot'
|
|
10378
10469
|
const IDE_SHOT_PERMISSION_ROUTE = '/dsh-ide/screen-permission'
|
|
10379
10470
|
|
|
10471
|
+
/** Long edge of the export; 1920 keeps a 16:9 crop at 1080p. */
|
|
10472
|
+
/** The export must not exceed this when it becomes a chat attachment. */
|
|
10473
|
+
const IDE_SHOT_BUDGET = 1024 * 1024
|
|
10474
|
+
/** JPEG qualities tried in order until the budget is met. */
|
|
10475
|
+
const IDE_SHOT_QUALITIES = [0.8, 0.7, 0.6, 0.5, 0.4]
|
|
10476
|
+
/** Extra passes that only run when the JPEG still exceeds the budget. */
|
|
10477
|
+
const IDE_SHOT_SHRINK_STEPS = [1, 1.25, 1.5, 2]
|
|
10478
|
+
|
|
10479
|
+
/**
|
|
10480
|
+
* Tools the popup card offers.
|
|
10481
|
+
*
|
|
10482
|
+
* `select` is the range tool, not a mark. Ellipse, arrow, pen and mosaic still
|
|
10483
|
+
* have their drawing code (`ideShotDrawOp`) but are not surfaced: the card stays
|
|
10484
|
+
* small, and the two that cover callouts are enough.
|
|
10485
|
+
*/
|
|
10486
|
+
const IDE_SHOT_TOOLS = ['select', 'rect', 'text']
|
|
10487
|
+
/** Stroke colours offered; red first because a screenshot mark is usually red. */
|
|
10488
|
+
const IDE_SHOT_COLORS = ['#ff4d4f', '#ffd666', '#52c41a', '#4f8cff', '#ffffff']
|
|
10489
|
+
/** Stroke widths offered, in image pixels. */
|
|
10490
|
+
const IDE_SHOT_WIDTHS = [2, 4, 8]
|
|
10491
|
+
/** Smallest selection a drag may produce, in image pixels. */
|
|
10492
|
+
const IDE_SHOT_MIN_SELECTION = 24
|
|
10493
|
+
|
|
10380
10494
|
/** POST one screenshot request; never throws, returns `{ ok }` shapes. */
|
|
10381
10495
|
async function ideShotRequest(body) {
|
|
10382
10496
|
let response
|
|
@@ -10417,11 +10531,11 @@ async function ideOpenScreenPermission() {
|
|
|
10417
10531
|
return parsed?.ok === true ? parsed.value : { opened: false }
|
|
10418
10532
|
}
|
|
10419
10533
|
|
|
10420
|
-
/** The image inside a `data:image
|
|
10421
|
-
function ideShotFile(dataUrl, name = 'screenshot.
|
|
10534
|
+
/** The image inside a `data:image/…;base64,…` URL as a `File`. */
|
|
10535
|
+
function ideShotFile(dataUrl, name = 'screenshot.jpg') {
|
|
10422
10536
|
const comma = dataUrl.indexOf(',')
|
|
10423
10537
|
const head = dataUrl.slice(0, comma)
|
|
10424
|
-
const type = /^data:(image\/[a-z+]+)/.exec(head)?.[1] ?? 'image/
|
|
10538
|
+
const type = /^data:(image\/[a-z+]+)/.exec(head)?.[1] ?? 'image/jpeg'
|
|
10425
10539
|
const binary = atob(dataUrl.slice(comma + 1))
|
|
10426
10540
|
const bytes = new Uint8Array(binary.length)
|
|
10427
10541
|
for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index)
|
|
@@ -10433,8 +10547,7 @@ function ideShotFile(dataUrl, name = 'screenshot.png') {
|
|
|
10433
10547
|
*
|
|
10434
10548
|
* Only a paste is dispatched — no editor mutation, no `@` mention flow — so the
|
|
10435
10549
|
* 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".
|
|
10550
|
+
* no composer is on screen, which the caller degrades to "copy it and paste".
|
|
10438
10551
|
*/
|
|
10439
10552
|
async function idePasteScreenshot(dataUrl) {
|
|
10440
10553
|
const findEditor = () => (typeof document === 'undefined' ? null : document.querySelector('[data-lexical-editor="true"]'))
|
|
@@ -10449,56 +10562,723 @@ async function idePasteScreenshot(dataUrl) {
|
|
|
10449
10562
|
const transfer = new DataTransfer()
|
|
10450
10563
|
transfer.items.add(file)
|
|
10451
10564
|
editor.focus()
|
|
10452
|
-
|
|
10453
|
-
editor.dispatchEvent(event)
|
|
10565
|
+
editor.dispatchEvent(new ClipboardEvent('paste', { clipboardData: transfer, bubbles: true, cancelable: true }))
|
|
10454
10566
|
return true
|
|
10455
10567
|
}
|
|
10456
10568
|
|
|
10569
|
+
// ------------------------------------------------------------------ geometry
|
|
10570
|
+
// Pure helpers: the editor converts pointer positions into image pixels, keeps
|
|
10571
|
+
// a selection inside the capture and resizes it from one of eight handles.
|
|
10572
|
+
|
|
10573
|
+
/** Scale that fits `width × height` into the given box, never upscaling. */
|
|
10574
|
+
function ideShotFitScale(width, height, boxWidth, boxHeight) {
|
|
10575
|
+
if (!(width > 0) || !(height > 0) || !(boxWidth > 0) || !(boxHeight > 0)) return 1
|
|
10576
|
+
return Math.min(boxWidth / width, boxHeight / height, 1)
|
|
10577
|
+
}
|
|
10578
|
+
|
|
10457
10579
|
/**
|
|
10458
|
-
*
|
|
10459
|
-
*
|
|
10580
|
+
* How big to draw the capture.
|
|
10581
|
+
*
|
|
10582
|
+
* The whole picture has to stay visible — cropping it would put the screen's
|
|
10583
|
+
* edges out of reach, and a selection there would silently lose content. So it
|
|
10584
|
+
* is drawn at life size (a Retina capture is 2× the CSS pixels, hence `1/ratio`)
|
|
10585
|
+
* and only scaled down when the window cannot hold it. On a window that is
|
|
10586
|
+
* nearly the screen this fills it edge to edge.
|
|
10460
10587
|
*/
|
|
10461
|
-
function
|
|
10588
|
+
function ideShotDisplayScale(imageWidth, imageHeight, boxWidth, boxHeight, ratio) {
|
|
10589
|
+
if (!(imageWidth > 0) || !(imageHeight > 0) || !(boxWidth > 0) || !(boxHeight > 0)) return 1
|
|
10590
|
+
const life = 1 / (ratio > 0 ? ratio : 1)
|
|
10591
|
+
return Math.min(life, boxWidth / imageWidth, boxHeight / imageHeight)
|
|
10592
|
+
}
|
|
10593
|
+
|
|
10594
|
+
/** Keep a rectangle inside `bounds` without changing its size (unless it must shrink). */
|
|
10595
|
+
function ideShotClampSelection(rect, bounds) {
|
|
10596
|
+
const width = Math.min(rect.width, bounds.width)
|
|
10597
|
+
const height = Math.min(rect.height, bounds.height)
|
|
10598
|
+
const x = Math.min(Math.max(rect.x, 0), Math.max(bounds.width - width, 0))
|
|
10599
|
+
const y = Math.min(Math.max(rect.y, 0), Math.max(bounds.height - height, 0))
|
|
10600
|
+
return { x, y, width, height }
|
|
10601
|
+
}
|
|
10602
|
+
|
|
10603
|
+
/** A rectangle from two dragged corners, normalized and clamped to the image. */
|
|
10604
|
+
function ideShotRectFromPoints(start, end, bounds) {
|
|
10605
|
+
const x = Math.min(start.x, end.x)
|
|
10606
|
+
const y = Math.min(start.y, end.y)
|
|
10607
|
+
const width = Math.abs(end.x - start.x)
|
|
10608
|
+
const height = Math.abs(end.y - start.y)
|
|
10609
|
+
return ideShotClampSelection({ x, y, width, height }, bounds)
|
|
10610
|
+
}
|
|
10611
|
+
|
|
10612
|
+
/** The eight resize handles of a rectangle, as `{ id, x, y }` in image pixels. */
|
|
10613
|
+
function ideShotHandles(rect) {
|
|
10614
|
+
const midX = rect.x + rect.width / 2
|
|
10615
|
+
const midY = rect.y + rect.height / 2
|
|
10616
|
+
const right = rect.x + rect.width
|
|
10617
|
+
const bottom = rect.y + rect.height
|
|
10618
|
+
return [
|
|
10619
|
+
{ id: 'nw', x: rect.x, y: rect.y },
|
|
10620
|
+
{ id: 'n', x: midX, y: rect.y },
|
|
10621
|
+
{ id: 'ne', x: right, y: rect.y },
|
|
10622
|
+
{ id: 'e', x: right, y: midY },
|
|
10623
|
+
{ id: 'se', x: right, y: bottom },
|
|
10624
|
+
{ id: 's', x: midX, y: bottom },
|
|
10625
|
+
{ id: 'sw', x: rect.x, y: bottom },
|
|
10626
|
+
{ id: 'w', x: rect.x, y: midY },
|
|
10627
|
+
]
|
|
10628
|
+
}
|
|
10629
|
+
|
|
10630
|
+
/** Whether a point is inside `rect`, expanded by `slack` on every side. */
|
|
10631
|
+
function ideShotHitsRect(point, rect, slack) {
|
|
10632
|
+
const pad = Number.isFinite(slack) ? slack : 0
|
|
10633
|
+
return point.x >= rect.x - pad && point.x <= rect.x + rect.width + pad
|
|
10634
|
+
&& point.y >= rect.y - pad && point.y <= rect.y + rect.height + pad
|
|
10635
|
+
}
|
|
10636
|
+
|
|
10637
|
+
/** Resize `rect` by dragging one handle to `point`, keeping it valid and in bounds. */
|
|
10638
|
+
function ideShotResize(rect, handle, point, bounds) {
|
|
10639
|
+
let left = rect.x
|
|
10640
|
+
let top = rect.y
|
|
10641
|
+
let right = rect.x + rect.width
|
|
10642
|
+
let bottom = rect.y + rect.height
|
|
10643
|
+
if (handle.includes('w')) left = point.x
|
|
10644
|
+
if (handle.includes('e')) right = point.x
|
|
10645
|
+
if (handle.includes('n')) top = point.y
|
|
10646
|
+
if (handle.includes('s')) bottom = point.y
|
|
10647
|
+
const x = Math.min(left, right)
|
|
10648
|
+
const y = Math.min(top, bottom)
|
|
10649
|
+
const width = Math.max(Math.abs(right - left), IDE_SHOT_MIN_SELECTION / 4)
|
|
10650
|
+
const height = Math.max(Math.abs(bottom - top), IDE_SHOT_MIN_SELECTION / 4)
|
|
10651
|
+
return ideShotClampSelection({ x, y, width, height }, bounds)
|
|
10652
|
+
}
|
|
10653
|
+
|
|
10654
|
+
/**
|
|
10655
|
+
* Pointer position in image pixels.
|
|
10656
|
+
*
|
|
10657
|
+
* The capture is centred inside the stage, so the offset of the drawn canvas
|
|
10658
|
+
* within the stage is half of the leftover space; `bounds` is the image size
|
|
10659
|
+
* (the stage element itself has no width/height of its own).
|
|
10660
|
+
*/
|
|
10661
|
+
function ideShotPoint(event, canvas, scale, bounds) {
|
|
10662
|
+
const box = canvas.getBoundingClientRect()
|
|
10663
|
+
const x = (event.clientX - box.left) / scale
|
|
10664
|
+
const y = (event.clientY - box.top) / scale
|
|
10665
|
+
return {
|
|
10666
|
+
x: Math.max(0, Math.min(Number.isFinite(x) ? x : 0, bounds.width)),
|
|
10667
|
+
y: Math.max(0, Math.min(Number.isFinite(y) ? y : 0, bounds.height)),
|
|
10668
|
+
}
|
|
10669
|
+
}
|
|
10670
|
+
|
|
10671
|
+
// -------------------------------------------------------------------- drawing
|
|
10672
|
+
|
|
10673
|
+
/** Draw one stored operation onto a context that already shows the capture. */
|
|
10674
|
+
function ideShotDrawOp(ctx, op, image) {
|
|
10675
|
+
const color = op.color ?? '#ff4d4f'
|
|
10676
|
+
// `stroke` is the pen width; `width`/`height` are the rectangle being drawn.
|
|
10677
|
+
const stroke = op.stroke ?? 4
|
|
10678
|
+
ctx.save()
|
|
10679
|
+
ctx.strokeStyle = color
|
|
10680
|
+
ctx.fillStyle = color
|
|
10681
|
+
ctx.lineWidth = stroke
|
|
10682
|
+
ctx.lineCap = 'round'
|
|
10683
|
+
ctx.lineJoin = 'round'
|
|
10684
|
+
if (op.tool === 'rect') {
|
|
10685
|
+
ctx.strokeRect(op.x, op.y, op.width, op.height)
|
|
10686
|
+
} else if (op.tool === 'ellipse') {
|
|
10687
|
+
ctx.beginPath()
|
|
10688
|
+
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)
|
|
10689
|
+
ctx.stroke()
|
|
10690
|
+
} else if (op.tool === 'arrow') {
|
|
10691
|
+
const x1 = op.x
|
|
10692
|
+
const y1 = op.y
|
|
10693
|
+
const x2 = op.x + op.width
|
|
10694
|
+
const y2 = op.y + op.height
|
|
10695
|
+
const angle = Math.atan2(y2 - y1, x2 - x1)
|
|
10696
|
+
const head = Math.max(10, stroke * 4)
|
|
10697
|
+
ctx.beginPath()
|
|
10698
|
+
ctx.moveTo(x1, y1)
|
|
10699
|
+
ctx.lineTo(x2, y2)
|
|
10700
|
+
ctx.stroke()
|
|
10701
|
+
ctx.beginPath()
|
|
10702
|
+
ctx.moveTo(x2, y2)
|
|
10703
|
+
ctx.lineTo(x2 - head * Math.cos(angle - Math.PI / 7), y2 - head * Math.sin(angle - Math.PI / 7))
|
|
10704
|
+
ctx.lineTo(x2 - head * Math.cos(angle + Math.PI / 7), y2 - head * Math.sin(angle + Math.PI / 7))
|
|
10705
|
+
ctx.closePath()
|
|
10706
|
+
ctx.fill()
|
|
10707
|
+
} else if (op.tool === 'pen') {
|
|
10708
|
+
const points = op.points ?? []
|
|
10709
|
+
if (points.length > 1) {
|
|
10710
|
+
ctx.beginPath()
|
|
10711
|
+
ctx.moveTo(points[0].x, points[0].y)
|
|
10712
|
+
for (const point of points.slice(1)) ctx.lineTo(point.x, point.y)
|
|
10713
|
+
ctx.stroke()
|
|
10714
|
+
}
|
|
10715
|
+
} else if (op.tool === 'text') {
|
|
10716
|
+
ctx.font = `${Math.max(12, Math.round(stroke))}px -apple-system, "Segoe UI", "PingFang SC", sans-serif`
|
|
10717
|
+
ctx.textBaseline = 'top'
|
|
10718
|
+
// A dark halo keeps the label readable on light and dark captures alike.
|
|
10719
|
+
ctx.lineWidth = Math.max(2, stroke / 2)
|
|
10720
|
+
ctx.strokeStyle = 'rgba(0, 0, 0, 0.55)'
|
|
10721
|
+
ctx.strokeText(op.text ?? '', op.x, op.y)
|
|
10722
|
+
ctx.fillStyle = color
|
|
10723
|
+
ctx.fillText(op.text ?? '', op.x, op.y)
|
|
10724
|
+
} else if (op.tool === 'mosaic') {
|
|
10725
|
+
const x = Math.min(op.x, op.x + op.width)
|
|
10726
|
+
const y = Math.min(op.y, op.y + op.height)
|
|
10727
|
+
const w = Math.abs(op.width)
|
|
10728
|
+
const h = Math.abs(op.height)
|
|
10729
|
+
if (w > 2 && h > 2 && image !== undefined) {
|
|
10730
|
+
const block = Math.max(6, Math.round(Math.min(w, h) / 12))
|
|
10731
|
+
const small = document.createElement('canvas')
|
|
10732
|
+
small.width = Math.max(1, Math.round(w / block))
|
|
10733
|
+
small.height = Math.max(1, Math.round(h / block))
|
|
10734
|
+
const smallCtx = small.getContext('2d')
|
|
10735
|
+
smallCtx.imageSmoothingEnabled = true
|
|
10736
|
+
smallCtx.drawImage(image, x, y, w, h, 0, 0, small.width, small.height)
|
|
10737
|
+
ctx.imageSmoothingEnabled = false
|
|
10738
|
+
ctx.drawImage(small, 0, 0, small.width, small.height, x, y, w, h)
|
|
10739
|
+
}
|
|
10740
|
+
}
|
|
10741
|
+
ctx.restore()
|
|
10742
|
+
}
|
|
10743
|
+
|
|
10744
|
+
/** Redraw the whole editor frame: capture, dimmed outside, marks, selection. */
|
|
10745
|
+
function ideShotPaint(canvas, image, ops, draft, selection, showSelection) {
|
|
10746
|
+
const ctx = canvas.getContext('2d')
|
|
10747
|
+
if (ctx === null || image === null) return
|
|
10748
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
|
10749
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
|
10750
|
+
ctx.drawImage(image, 0, 0, canvas.width, canvas.height)
|
|
10751
|
+
for (const op of ops) ideShotDrawOp(ctx, op, image)
|
|
10752
|
+
if (draft !== null) ideShotDrawOp(ctx, draft, image)
|
|
10753
|
+
if (selection === null) {
|
|
10754
|
+
// Nothing framed yet: dim the whole capture so the hint reads as a mode.
|
|
10755
|
+
ctx.save()
|
|
10756
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.35)'
|
|
10757
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
|
10758
|
+
ctx.restore()
|
|
10759
|
+
} else if (showSelection) {
|
|
10760
|
+
const { x, y, width, height } = selection
|
|
10761
|
+
ctx.save()
|
|
10762
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.45)'
|
|
10763
|
+
ctx.beginPath()
|
|
10764
|
+
ctx.rect(0, 0, canvas.width, canvas.height)
|
|
10765
|
+
ctx.rect(x, y, width, height)
|
|
10766
|
+
ctx.fill('evenodd')
|
|
10767
|
+
ctx.strokeStyle = '#4f8cff'
|
|
10768
|
+
ctx.lineWidth = Math.max(1, canvas.width / 900)
|
|
10769
|
+
ctx.strokeRect(x, y, width, height)
|
|
10770
|
+
for (const handle of ideShotHandles(selection)) {
|
|
10771
|
+
const size = Math.max(6, canvas.width / 160)
|
|
10772
|
+
ctx.fillStyle = '#ffffff'
|
|
10773
|
+
ctx.strokeStyle = '#4f8cff'
|
|
10774
|
+
ctx.lineWidth = Math.max(1, canvas.width / 900)
|
|
10775
|
+
ctx.beginPath()
|
|
10776
|
+
ctx.rect(handle.x - size / 2, handle.y - size / 2, size, size)
|
|
10777
|
+
ctx.fill()
|
|
10778
|
+
ctx.stroke()
|
|
10779
|
+
}
|
|
10780
|
+
ctx.restore()
|
|
10781
|
+
}
|
|
10782
|
+
}
|
|
10783
|
+
|
|
10784
|
+
/**
|
|
10785
|
+
* Crop the selection, redraw the marks and encode within the budget.
|
|
10786
|
+
*
|
|
10787
|
+
* The ladder stops at the first size that fits, so a flat capture keeps its
|
|
10788
|
+
* quality while a text-heavy one steps down instead of blowing the budget.
|
|
10789
|
+
*/
|
|
10790
|
+
function ideShotExport(image, ops, selection) {
|
|
10791
|
+
const sourceX = Math.max(0, Math.round(selection.x))
|
|
10792
|
+
const sourceY = Math.max(0, Math.round(selection.y))
|
|
10793
|
+
const sourceWidth = Math.max(1, Math.round(Math.min(selection.width, image.width - sourceX)))
|
|
10794
|
+
const sourceHeight = Math.max(1, Math.round(Math.min(selection.height, image.height - sourceY)))
|
|
10795
|
+
const render = (scale) => {
|
|
10796
|
+
const canvas = document.createElement('canvas')
|
|
10797
|
+
canvas.width = Math.max(1, Math.round(sourceWidth * scale))
|
|
10798
|
+
canvas.height = Math.max(1, Math.round(sourceHeight * scale))
|
|
10799
|
+
const ctx = canvas.getContext('2d')
|
|
10800
|
+
if (ctx === null) return null
|
|
10801
|
+
ctx.drawImage(image, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, canvas.width, canvas.height)
|
|
10802
|
+
ctx.save()
|
|
10803
|
+
ctx.scale(scale, scale)
|
|
10804
|
+
ctx.translate(-sourceX, -sourceY)
|
|
10805
|
+
for (const op of ops) ideShotDrawOp(ctx, op, image)
|
|
10806
|
+
ctx.restore()
|
|
10807
|
+
return canvas
|
|
10808
|
+
}
|
|
10809
|
+
// The crop keeps the screen's own pixels (no forced 1920 edge). Quality is
|
|
10810
|
+
// spent first; the picture is only ever shrunk if it still cannot fit the
|
|
10811
|
+
// attachment budget.
|
|
10812
|
+
let smallest = ''
|
|
10813
|
+
for (const step of IDE_SHOT_SHRINK_STEPS) {
|
|
10814
|
+
const canvas = render(Math.min(1, 1 / step))
|
|
10815
|
+
if (canvas === null) return ''
|
|
10816
|
+
for (const quality of IDE_SHOT_QUALITIES) {
|
|
10817
|
+
const url = canvas.toDataURL('image/jpeg', quality)
|
|
10818
|
+
if (url.length * 0.75 <= IDE_SHOT_BUDGET) return url
|
|
10819
|
+
if (smallest === '' || url.length < smallest.length) smallest = url
|
|
10820
|
+
}
|
|
10821
|
+
}
|
|
10822
|
+
return smallest
|
|
10823
|
+
}
|
|
10824
|
+
|
|
10825
|
+
// ------------------------------------------------------------------ component
|
|
10826
|
+
|
|
10827
|
+
/** One toolbar button. */
|
|
10828
|
+
function IdeShotToolButton({ active, label, title, onClick }) {
|
|
10829
|
+
return h('button', {
|
|
10830
|
+
type: 'button',
|
|
10831
|
+
className: `iw-shot-tool${active ? ' on' : ''}`,
|
|
10832
|
+
title,
|
|
10833
|
+
onClick,
|
|
10834
|
+
}, label)
|
|
10835
|
+
}
|
|
10836
|
+
|
|
10837
|
+
/**
|
|
10838
|
+
* The editor overlay.
|
|
10839
|
+
*
|
|
10840
|
+
* Rendered through `shell.overlay`, so it covers the window regardless of which
|
|
10841
|
+
* column is showing and is never clipped by the panel's overflow.
|
|
10842
|
+
*/
|
|
10843
|
+
function IdeScreenshotEditor({ store, tr, onInsert, onCopy, onOpenSettings, onClose }) {
|
|
10844
|
+
const state = useSyncExternalStore(store.subscribe, store.getState, store.getState)
|
|
10462
10845
|
const shot = state.screenshot ?? null
|
|
10846
|
+
const editing = shot?.phase === 'editing'
|
|
10847
|
+
const [image, setImage] = useState(null)
|
|
10848
|
+
const [tool, setTool] = useState('select')
|
|
10849
|
+
const [color, setColor] = useState(IDE_SHOT_COLORS[0])
|
|
10850
|
+
const [width, setWidth] = useState(IDE_SHOT_WIDTHS[1])
|
|
10851
|
+
const [ops, setOps] = useState([])
|
|
10852
|
+
const [selection, setSelection] = useState(null)
|
|
10853
|
+
/** True while the frame is being dragged: the card only shows once released. */
|
|
10854
|
+
const [dragging, setDragging] = useState(false)
|
|
10855
|
+
const [draft, setDraft] = useState(null)
|
|
10856
|
+
const [textAt, setTextAt] = useState(null)
|
|
10857
|
+
const [textValue, setTextValue] = useState('')
|
|
10858
|
+
const [scale, setScale] = useState(1)
|
|
10859
|
+
/**
|
|
10860
|
+
* On-screen size of a text mark. The operation stores the same size in image
|
|
10861
|
+
* pixels (divided by the zoom), so what you type is exactly what gets drawn.
|
|
10862
|
+
*/
|
|
10863
|
+
const textFont = Math.max(12, Math.round(width * 2.4 * scale))
|
|
10864
|
+
const [stageRect, setStageRect] = useState(null)
|
|
10865
|
+
/** Where image pixel (0,0) goes, in viewport coordinates. */
|
|
10866
|
+
const [origin, setOrigin] = useState({ left: 0, top: 0 })
|
|
10867
|
+
const canvasRef = useRef(null)
|
|
10868
|
+
const frameRef = useRef(null)
|
|
10869
|
+
const dragRef = useRef(null)
|
|
10870
|
+
|
|
10871
|
+
// Load the capture into an <img>: the canvas needs natural pixels, and the
|
|
10872
|
+
// selection is expressed in those pixels.
|
|
10873
|
+
useEffect(() => {
|
|
10874
|
+
if (!editing) {
|
|
10875
|
+
setImage(null)
|
|
10876
|
+
return
|
|
10877
|
+
}
|
|
10878
|
+
setOps([])
|
|
10879
|
+
setDraft(null)
|
|
10880
|
+
setTool('select')
|
|
10881
|
+
setTextAt(null)
|
|
10882
|
+
setSelection(null)
|
|
10883
|
+
const element = new Image()
|
|
10884
|
+
element.onload = () => setImage(element)
|
|
10885
|
+
element.src = shot.dataUrl
|
|
10886
|
+
}, [editing, shot?.dataUrl])
|
|
10887
|
+
|
|
10888
|
+
/**
|
|
10889
|
+
* Put the frozen picture exactly where the screen was.
|
|
10890
|
+
*
|
|
10891
|
+
* The capture is the whole screen in device pixels, and the overlay only
|
|
10892
|
+
* covers this window — so it is drawn 1:1 (`1 / devicePixelRatio`) and moved
|
|
10893
|
+
* up/left by the window's own screen offset. Without that offset the picture
|
|
10894
|
+
* is centred inside the window: its menu bar and title bar land *inside* the
|
|
10895
|
+
* window too, and you see everything doubled.
|
|
10896
|
+
*/
|
|
10897
|
+
useEffect(() => {
|
|
10898
|
+
if (image === null) return
|
|
10899
|
+
setScale(1 / (globalThis.devicePixelRatio || 1))
|
|
10900
|
+
setOrigin({
|
|
10901
|
+
left: -(globalThis.screenX ?? globalThis.screenLeft ?? 0),
|
|
10902
|
+
top: -(globalThis.screenY ?? globalThis.screenTop ?? 0),
|
|
10903
|
+
})
|
|
10904
|
+
}, [image])
|
|
10905
|
+
|
|
10906
|
+
// Repaint whenever anything visible changed.
|
|
10907
|
+
useEffect(() => {
|
|
10908
|
+
const canvas = canvasRef.current
|
|
10909
|
+
if (canvas === null || image === null) return
|
|
10910
|
+
canvas.width = image.naturalWidth
|
|
10911
|
+
canvas.height = image.naturalHeight
|
|
10912
|
+
ideShotPaint(canvas, image, ops, draft, selection, selection !== null)
|
|
10913
|
+
}, [image, ops, draft, selection, tool])
|
|
10914
|
+
|
|
10915
|
+
// Undo from anywhere: the overlay never holds focus, so the key is read at
|
|
10916
|
+
// the window instead of relying on a focused element.
|
|
10917
|
+
useEffect(() => {
|
|
10918
|
+
if (!editing) return undefined
|
|
10919
|
+
const onKey = (event) => {
|
|
10920
|
+
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 'z') return
|
|
10921
|
+
event.preventDefault()
|
|
10922
|
+
setOps((list) => list.slice(0, -1))
|
|
10923
|
+
}
|
|
10924
|
+
globalThis.addEventListener?.('keydown', onKey, true)
|
|
10925
|
+
return () => globalThis.removeEventListener?.('keydown', onKey, true)
|
|
10926
|
+
}, [editing])
|
|
10927
|
+
|
|
10928
|
+
// Where the canvas sits on screen: the popup card is anchored to the frame.
|
|
10929
|
+
const layoutKey = selection === null ? '' : `${selection.x},${selection.y},${selection.width},${selection.height}`
|
|
10930
|
+
useEffect(() => {
|
|
10931
|
+
const canvas = canvasRef.current
|
|
10932
|
+
if (canvas === null || image === null) {
|
|
10933
|
+
setStageRect(null)
|
|
10934
|
+
return
|
|
10935
|
+
}
|
|
10936
|
+
const rect = canvas.getBoundingClientRect()
|
|
10937
|
+
setStageRect({ left: rect.left, top: rect.top, width: rect.width, height: rect.height })
|
|
10938
|
+
}, [image, scale, layoutKey])
|
|
10939
|
+
|
|
10940
|
+
const bounds = image === null
|
|
10941
|
+
? { width: 1, height: 1 }
|
|
10942
|
+
: { width: image.naturalWidth, height: image.naturalHeight }
|
|
10943
|
+
|
|
10944
|
+
/** Whether a point may carry a mark (a mark needs a framed area). */
|
|
10945
|
+
const canMark = selection !== null && ideShotHitsRect
|
|
10946
|
+
|
|
10947
|
+
const beginSelection = (point) => {
|
|
10948
|
+
dragRef.current = { mode: 'create', origin: point }
|
|
10949
|
+
setDragging(true)
|
|
10950
|
+
setSelection({ x: point.x, y: point.y, width: 0, height: 0 })
|
|
10951
|
+
}
|
|
10952
|
+
|
|
10953
|
+
/**
|
|
10954
|
+
* Pointer down: dragging on empty space always draws a new frame — that is
|
|
10955
|
+
* the first thing the user does after the shortcut. Inside an existing frame
|
|
10956
|
+
* the active tool decides (range adjust, rectangle, or text).
|
|
10957
|
+
*/
|
|
10958
|
+
const onPointerDown = (event) => {
|
|
10959
|
+
// Pressing the box itself has to place the caret, not cancel it: the event
|
|
10960
|
+
// bubbles from the <input> up to this stage handler.
|
|
10961
|
+
if (event.target?.closest?.('.iw-shot-text')) return
|
|
10962
|
+
if (textAt !== null) {
|
|
10963
|
+
setTextAt(null)
|
|
10964
|
+
setTextValue('')
|
|
10965
|
+
return
|
|
10966
|
+
}
|
|
10967
|
+
if (image === null) return
|
|
10968
|
+
const frame = frameRef.current
|
|
10969
|
+
if (frame === null) return
|
|
10970
|
+
const point = ideShotPoint(event, canvasRef.current ?? frame, scale, bounds)
|
|
10971
|
+
try {
|
|
10972
|
+
frame.setPointerCapture?.(event.pointerId)
|
|
10973
|
+
} catch {
|
|
10974
|
+
/* a synthetic or already-captured pointer: dragging still works */
|
|
10975
|
+
}
|
|
10976
|
+
const inside = selection !== null && selection.width > 0 && ideShotHitsRect(point, selection, 0)
|
|
10977
|
+
if (!inside) {
|
|
10978
|
+
beginSelection(point)
|
|
10979
|
+
return
|
|
10980
|
+
}
|
|
10981
|
+
if (tool === 'text') {
|
|
10982
|
+
setTextAt(point)
|
|
10983
|
+
setTextValue('')
|
|
10984
|
+
return
|
|
10985
|
+
}
|
|
10986
|
+
if (tool === 'rect') {
|
|
10987
|
+
setDraft({ tool, color, stroke: width, x: point.x, y: point.y, width: 0, height: 0, points: [point] })
|
|
10988
|
+
return
|
|
10989
|
+
}
|
|
10990
|
+
// Range tool: handles first, then the body.
|
|
10991
|
+
const handle = ideShotHandles(selection).find((entry) => (
|
|
10992
|
+
Math.abs(entry.x - point.x) <= 12 / scale && Math.abs(entry.y - point.y) <= 12 / scale
|
|
10993
|
+
))
|
|
10994
|
+
if (handle !== undefined) {
|
|
10995
|
+
dragRef.current = { mode: 'resize', handle: handle.id }
|
|
10996
|
+
return
|
|
10997
|
+
}
|
|
10998
|
+
dragRef.current = { mode: 'move', origin: point, start: selection }
|
|
10999
|
+
}
|
|
11000
|
+
|
|
11001
|
+
const onPointerMove = (event) => {
|
|
11002
|
+
const drag = dragRef.current
|
|
11003
|
+
const frame = frameRef.current
|
|
11004
|
+
if (frame === null) return
|
|
11005
|
+
const point = ideShotPoint(event, canvasRef.current ?? frame, scale, bounds)
|
|
11006
|
+
if (drag !== null) {
|
|
11007
|
+
if (drag.mode === 'move') {
|
|
11008
|
+
const dx = point.x - drag.origin.x
|
|
11009
|
+
const dy = point.y - drag.origin.y
|
|
11010
|
+
setSelection(ideShotClampSelection({
|
|
11011
|
+
x: drag.start.x + dx,
|
|
11012
|
+
y: drag.start.y + dy,
|
|
11013
|
+
width: drag.start.width,
|
|
11014
|
+
height: drag.start.height,
|
|
11015
|
+
}, bounds))
|
|
11016
|
+
return
|
|
11017
|
+
}
|
|
11018
|
+
if (drag.mode === 'resize') {
|
|
11019
|
+
setSelection(ideShotResize(selection, drag.handle, point, bounds))
|
|
11020
|
+
return
|
|
11021
|
+
}
|
|
11022
|
+
setSelection(ideShotRectFromPoints(drag.origin, point, bounds))
|
|
11023
|
+
return
|
|
11024
|
+
}
|
|
11025
|
+
if (draft !== null) {
|
|
11026
|
+
const next = { ...draft }
|
|
11027
|
+
if (draft.tool === 'pen') next.points = [...draft.points, point]
|
|
11028
|
+
else {
|
|
11029
|
+
next.width = point.x - draft.x
|
|
11030
|
+
next.height = point.y - draft.y
|
|
11031
|
+
}
|
|
11032
|
+
setDraft(next)
|
|
11033
|
+
}
|
|
11034
|
+
}
|
|
11035
|
+
|
|
11036
|
+
const onPointerUp = () => {
|
|
11037
|
+
const drag = dragRef.current
|
|
11038
|
+
dragRef.current = null
|
|
11039
|
+
setDragging(false)
|
|
11040
|
+
if (draft !== null) {
|
|
11041
|
+
const op = draft.tool === 'pen'
|
|
11042
|
+
? { ...draft }
|
|
11043
|
+
: {
|
|
11044
|
+
...draft,
|
|
11045
|
+
x: Math.min(draft.x, draft.x + draft.width),
|
|
11046
|
+
y: Math.min(draft.y, draft.y + draft.height),
|
|
11047
|
+
width: Math.abs(draft.width),
|
|
11048
|
+
height: Math.abs(draft.height),
|
|
11049
|
+
}
|
|
11050
|
+
setDraft(null)
|
|
11051
|
+
if (op.tool === 'pen' ? (op.points?.length ?? 0) > 1 : (op.width > 2 || op.height > 2)) {
|
|
11052
|
+
setOps((list) => [...list, op])
|
|
11053
|
+
}
|
|
11054
|
+
return
|
|
11055
|
+
}
|
|
11056
|
+
if (drag?.mode === 'create' && selection !== null) {
|
|
11057
|
+
// A click (or a stray twitch) is not a frame: drop it and stay unframed.
|
|
11058
|
+
if (selection.width < IDE_SHOT_MIN_SELECTION || selection.height < IDE_SHOT_MIN_SELECTION) {
|
|
11059
|
+
setSelection(null)
|
|
11060
|
+
}
|
|
11061
|
+
}
|
|
11062
|
+
}
|
|
11063
|
+
|
|
11064
|
+
const commitText = () => {
|
|
11065
|
+
if (textAt === null || textValue.trim() === '') {
|
|
11066
|
+
setTextAt(null)
|
|
11067
|
+
return
|
|
11068
|
+
}
|
|
11069
|
+
// `stroke` doubles as the font size for text marks, in image pixels; the
|
|
11070
|
+
// preview is that number times the zoom, so the two agree.
|
|
11071
|
+
setOps((list) => [...list, { tool: 'text', x: textAt.x, y: textAt.y, text: textValue.trim(), color, stroke: Math.max(12, Math.round(textFont / scale)) }])
|
|
11072
|
+
setTextAt(null)
|
|
11073
|
+
setTextValue('')
|
|
11074
|
+
}
|
|
11075
|
+
|
|
11076
|
+
const undo = () => setOps((list) => list.slice(0, -1))
|
|
11077
|
+
const exportImage = () => (selection === null || image === null ? '' : ideShotExport(image, ops, selection))
|
|
11078
|
+
|
|
11079
|
+
/**
|
|
11080
|
+
* Esc leaves the whole operation — before the first press, and also in the
|
|
11081
|
+
* middle of dragging a frame (the pointer capture is dropped so the "up"
|
|
11082
|
+
* that follows cannot revive it). A text box open eats the first Esc.
|
|
11083
|
+
*
|
|
11084
|
+
* The listener is on `window` in the capture phase: the overlay never takes
|
|
11085
|
+
* focus, and the shell handles Esc for its own panels.
|
|
11086
|
+
*/
|
|
11087
|
+
useEffect(() => {
|
|
11088
|
+
if (!editing) return undefined
|
|
11089
|
+
/**
|
|
11090
|
+
* Esc leaves the editor — except while a text box is open: then the box
|
|
11091
|
+
* owns the key and closes itself (its own `onKeyDown`), so one press never
|
|
11092
|
+
* does two things. Nothing here stops propagation for that case.
|
|
11093
|
+
*/
|
|
11094
|
+
const onKey = (event) => {
|
|
11095
|
+
if (event.key !== 'Escape' || event.defaultPrevented === true) return
|
|
11096
|
+
if (textAt !== null) return
|
|
11097
|
+
event.preventDefault()
|
|
11098
|
+
event.stopPropagation()
|
|
11099
|
+
dragRef.current = null
|
|
11100
|
+
setDragging(false)
|
|
11101
|
+
setDraft(null)
|
|
11102
|
+
onClose()
|
|
11103
|
+
}
|
|
11104
|
+
globalThis.addEventListener?.('keydown', onKey, true)
|
|
11105
|
+
return () => globalThis.removeEventListener?.('keydown', onKey, true)
|
|
11106
|
+
}, [editing, textAt, onClose])
|
|
11107
|
+
|
|
10463
11108
|
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')))
|
|
11109
|
+
|
|
11110
|
+
// The editor renders through `shell.overlay`, i.e. outside the panel: the
|
|
11111
|
+
// workspace stylesheet is only mounted by the panel components, so without
|
|
11112
|
+
// this the card falls back to browser-default buttons (white) and fonts.
|
|
11113
|
+
const styled = (node) => h(React.Fragment, null, [h(IdeStyles, { key: 'style' }), node])
|
|
11114
|
+
const palette = ideIsThemeId(state.theme) ? { 'data-dsh-theme': state.theme } : {}
|
|
11115
|
+
|
|
11116
|
+
// Typography follows the user's own settings; the variables are set here
|
|
11117
|
+
// because `.iw-root` (which normally sets them) is not an ancestor.
|
|
11118
|
+
const skin = {
|
|
11119
|
+
fontFamily: 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
|
|
11120
|
+
fontSize: `${Number.isFinite(state.treeFontSize) ? state.treeFontSize : 14.5}px`,
|
|
11121
|
+
'--iw-code-font-size': `${Number.isFinite(state.codeFontSize) ? state.codeFontSize : 12.5}px`,
|
|
11122
|
+
'--iw-tree-font-size': `${Number.isFinite(state.treeFontSize) ? state.treeFontSize : 14.5}px`,
|
|
10485
11123
|
}
|
|
10486
11124
|
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
11125
|
+
if (shot.phase === 'error') {
|
|
11126
|
+
const needsPermission = shot.code === 'no-screen-permission'
|
|
11127
|
+
const isMac = ideHostIsMacos()
|
|
11128
|
+
const actions = []
|
|
11129
|
+
if (needsPermission && isMac) {
|
|
11130
|
+
actions.push(h('button', { key: 'settings', type: 'button', className: 'iw-shot-primary', onClick: onOpenSettings }, tr('shotOpenSettings')))
|
|
11131
|
+
}
|
|
11132
|
+
actions.push(h('button', { key: 'close', type: 'button', className: 'iw-shot-button', onClick: onClose }, tr('setupClose')))
|
|
11133
|
+
return styled(h('div', { className: 'iw-shot-veil', style: skin, ...palette }, [
|
|
11134
|
+
h('div', { key: 'card', className: 'iw-shot' }, [
|
|
11135
|
+
h('div', { key: 'title', className: 'iw-shot-title' }, needsPermission ? tr('shotNoPermissionTitle') : tr('shotFailed')),
|
|
11136
|
+
h('div', { key: 'guide', className: 'iw-shot-guide' }, needsPermission
|
|
11137
|
+
? (isMac ? tr('shotNoPermissionMac') : tr('shotNoPermissionWindows'))
|
|
11138
|
+
: (shot.message === '' ? tr('shotFailed') : `${tr('shotFailed')}:${shot.message}`)),
|
|
11139
|
+
h('div', { key: 'actions', className: 'iw-shot-actions' }, actions),
|
|
11140
|
+
]),
|
|
11141
|
+
]))
|
|
11142
|
+
}
|
|
11143
|
+
|
|
11144
|
+
if (image === null) {
|
|
11145
|
+
return styled(h('div', { className: 'iw-shot-veil', style: skin, ...palette }, [
|
|
11146
|
+
h('div', { key: 'card', className: 'iw-shot' }, [h('div', { key: 'title', className: 'iw-shot-title' }, tr('shotBusy'))]),
|
|
11147
|
+
]))
|
|
11148
|
+
}
|
|
11149
|
+
|
|
11150
|
+
// The popup card: below the frame, or above it when the bottom is crowded.
|
|
11151
|
+
const card = (() => {
|
|
11152
|
+
if (selection === null || dragging || stageRect === null) return null
|
|
11153
|
+
const cardWidth = 392
|
|
11154
|
+
const frameLeft = stageRect.left + selection.x * scale
|
|
11155
|
+
const frameTop = stageRect.top + selection.y * scale
|
|
11156
|
+
const frameWidth = selection.width * scale
|
|
11157
|
+
const frameHeight = selection.height * scale
|
|
11158
|
+
const left = Math.max(8, Math.min(globalThis.innerWidth - cardWidth - 8, frameLeft + frameWidth / 2 - cardWidth / 2))
|
|
11159
|
+
const below = frameTop + frameHeight + 10
|
|
11160
|
+
const top = below + 44 <= globalThis.innerHeight ? below : Math.max(8, frameTop - 44)
|
|
11161
|
+
const pick = (id) => {
|
|
11162
|
+
setTool(tool === id ? 'select' : id)
|
|
11163
|
+
setTextAt(null)
|
|
11164
|
+
}
|
|
11165
|
+
return h('div', {
|
|
11166
|
+
className: 'iw-shot-card',
|
|
11167
|
+
style: { left: `${left}px`, top: `${top}px`, width: `${cardWidth}px` },
|
|
11168
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
11169
|
+
}, [
|
|
11170
|
+
h('button', {
|
|
11171
|
+
key: 'rect',
|
|
11172
|
+
type: 'button',
|
|
11173
|
+
className: `iw-btn${tool === 'rect' ? ' on' : ''}`,
|
|
11174
|
+
title: tr('shotTool_rect'),
|
|
11175
|
+
onClick: () => pick('rect'),
|
|
11176
|
+
}, tr('shotTool_rect')),
|
|
11177
|
+
h('button', {
|
|
11178
|
+
key: 'text',
|
|
11179
|
+
type: 'button',
|
|
11180
|
+
className: `iw-btn${tool === 'text' ? ' on' : ''}`,
|
|
11181
|
+
title: tr('shotTool_text'),
|
|
11182
|
+
onClick: () => pick('text'),
|
|
11183
|
+
}, tr('shotTool_text')),
|
|
11184
|
+
h('button', {
|
|
11185
|
+
key: 'undo',
|
|
11186
|
+
type: 'button',
|
|
11187
|
+
className: 'iw-btn',
|
|
11188
|
+
disabled: ops.length === 0,
|
|
11189
|
+
onClick: undo,
|
|
11190
|
+
}, tr('shotUndo')),
|
|
11191
|
+
h('span', { key: 'grow', className: 'iw-shot-grow' }),
|
|
11192
|
+
h('button', {
|
|
11193
|
+
key: 'copy',
|
|
11194
|
+
type: 'button',
|
|
11195
|
+
className: 'iw-btn',
|
|
11196
|
+
onClick: () => { const url = exportImage(); if (url !== '') onCopy(url) },
|
|
11197
|
+
}, tr('shotCopy')),
|
|
11198
|
+
h('button', {
|
|
11199
|
+
key: 'insert',
|
|
11200
|
+
type: 'button',
|
|
11201
|
+
className: 'iw-btn primary',
|
|
11202
|
+
onClick: () => { const url = exportImage(); if (url !== '') onInsert(url) },
|
|
11203
|
+
}, tr('shotJump')),
|
|
11204
|
+
])
|
|
11205
|
+
})()
|
|
10490
11206
|
|
|
10491
|
-
return h('div', {
|
|
10492
|
-
className: 'iw-shot',
|
|
10493
|
-
|
|
11207
|
+
return styled(h('div', {
|
|
11208
|
+
className: 'iw-shot-veil iw-shot-veil--editor',
|
|
11209
|
+
style: skin,
|
|
11210
|
+
...palette,
|
|
11211
|
+
tabIndex: -1,
|
|
11212
|
+
onKeyDown: (event) => {
|
|
11213
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'z') {
|
|
11214
|
+
event.preventDefault()
|
|
11215
|
+
undo()
|
|
11216
|
+
}
|
|
11217
|
+
},
|
|
10494
11218
|
}, [
|
|
10495
|
-
h('div', {
|
|
10496
|
-
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
:
|
|
10500
|
-
|
|
10501
|
-
|
|
11219
|
+
h('div', {
|
|
11220
|
+
key: 'stage',
|
|
11221
|
+
ref: frameRef,
|
|
11222
|
+
className: 'iw-shot-stage',
|
|
11223
|
+
onPointerDown: onPointerDown,
|
|
11224
|
+
onPointerMove: onPointerMove,
|
|
11225
|
+
onPointerUp: onPointerUp,
|
|
11226
|
+
onPointerCancel: onPointerUp,
|
|
11227
|
+
}, [
|
|
11228
|
+
h('div', {
|
|
11229
|
+
key: 'frame',
|
|
11230
|
+
className: 'iw-shot-frame',
|
|
11231
|
+
style: {
|
|
11232
|
+
position: 'absolute',
|
|
11233
|
+
left: `${origin.left}px`,
|
|
11234
|
+
top: `${origin.top}px`,
|
|
11235
|
+
width: `${Math.round(image.naturalWidth * scale)}px`,
|
|
11236
|
+
height: `${Math.round(image.naturalHeight * scale)}px`,
|
|
11237
|
+
},
|
|
11238
|
+
}, [
|
|
11239
|
+
h('canvas', {
|
|
11240
|
+
key: 'canvas',
|
|
11241
|
+
ref: canvasRef,
|
|
11242
|
+
className: 'iw-shot-canvas',
|
|
11243
|
+
}),
|
|
11244
|
+
textAt === null ? null : h('input', {
|
|
11245
|
+
key: 'text',
|
|
11246
|
+
className: 'iw-shot-text',
|
|
11247
|
+
autoFocus: true,
|
|
11248
|
+
// The stage cancels an open box on pointerdown; a click in the box
|
|
11249
|
+
// itself must not bubble up to it.
|
|
11250
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
11251
|
+
value: textValue,
|
|
11252
|
+
placeholder: tr('shotTextPlaceholder'),
|
|
11253
|
+
style: {
|
|
11254
|
+
left: `${Math.round(textAt.x * scale)}px`,
|
|
11255
|
+
top: `${Math.round(textAt.y * scale) - textFont}px`,
|
|
11256
|
+
color,
|
|
11257
|
+
fontSize: `${textFont}px`,
|
|
11258
|
+
width: `${Math.max(96, Math.round((textValue.length + 1) * textFont * 0.62))}px`,
|
|
11259
|
+
},
|
|
11260
|
+
onChange: (event) => setTextValue(event.target.value),
|
|
11261
|
+
onKeyDown: (event) => {
|
|
11262
|
+
if (event.key === 'Enter') {
|
|
11263
|
+
event.preventDefault()
|
|
11264
|
+
event.stopPropagation()
|
|
11265
|
+
commitText()
|
|
11266
|
+
return
|
|
11267
|
+
}
|
|
11268
|
+
if (event.key === 'Escape') {
|
|
11269
|
+
event.preventDefault()
|
|
11270
|
+
event.stopPropagation()
|
|
11271
|
+
setTextAt(null)
|
|
11272
|
+
setTextValue('')
|
|
11273
|
+
return
|
|
11274
|
+
}
|
|
11275
|
+
event.stopPropagation()
|
|
11276
|
+
},
|
|
11277
|
+
}),
|
|
11278
|
+
]),
|
|
11279
|
+
]),
|
|
11280
|
+
card,
|
|
11281
|
+
]))
|
|
10502
11282
|
}
|
|
10503
11283
|
|
|
10504
11284
|
// ---- 90-apply.js ---------------------------------------------------------
|
|
@@ -10808,32 +11588,51 @@ function apply(ctx) {
|
|
|
10808
11588
|
* draft's text and attachments are untouched; "只截图" puts it on the system
|
|
10809
11589
|
* clipboard and keeps the file.
|
|
10810
11590
|
*/
|
|
11591
|
+
/**
|
|
11592
|
+
* Capture first, render after.
|
|
11593
|
+
*
|
|
11594
|
+
* Anything drawn before the Host grabs the screen ends up *inside* the
|
|
11595
|
+
* screenshot — an overlay that says "capturing…" would be printed onto the
|
|
11596
|
+
* picture. So the panel stays untouched until the image arrives, and a short
|
|
11597
|
+
* guard keeps a double press from firing two captures.
|
|
11598
|
+
*/
|
|
11599
|
+
let screenshotBusy = false
|
|
11600
|
+
/**
|
|
11601
|
+
* Same flow on the desktop window and in a browser tab: the Host (which runs
|
|
11602
|
+
* on the machine that owns the screen) grabs the picture, the editor frames
|
|
11603
|
+
* it. Nothing here depends on the shell's own screen-capture permission.
|
|
11604
|
+
*/
|
|
10811
11605
|
async function startScreenshot() {
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
11606
|
+
if (screenshotBusy) return
|
|
11607
|
+
screenshotBusy = true
|
|
11608
|
+
try {
|
|
11609
|
+
const result = await ideShotRequest({})
|
|
11610
|
+
if (!result.ok) {
|
|
11611
|
+
store.setScreenshot({ phase: 'error', code: result.code, message: result.message })
|
|
11612
|
+
return
|
|
11613
|
+
}
|
|
11614
|
+
// The editor owns the capture from here: frame, marks, export.
|
|
11615
|
+
store.setScreenshot({ phase: 'editing', ...result.value })
|
|
11616
|
+
} finally {
|
|
11617
|
+
screenshotBusy = false
|
|
10818
11618
|
}
|
|
10819
|
-
store.setScreenshot({ phase: 'ready', ...result.value })
|
|
10820
11619
|
}
|
|
10821
11620
|
|
|
10822
|
-
|
|
10823
|
-
|
|
11621
|
+
/** The editor's "insert" exit: back to the chat, paste only that image. */
|
|
11622
|
+
async function screenshotInsert(dataUrl) {
|
|
10824
11623
|
store.setScreenshot(null)
|
|
10825
11624
|
backToChat()
|
|
10826
|
-
if (
|
|
10827
|
-
const pasted = await idePasteScreenshot(
|
|
11625
|
+
if (typeof dataUrl !== 'string' || dataUrl === '') return
|
|
11626
|
+
const pasted = await idePasteScreenshot(dataUrl)
|
|
10828
11627
|
store.setNotice(pasted ? translate('shotAttached') : translate('shotNoEditor'))
|
|
10829
11628
|
}
|
|
10830
11629
|
|
|
10831
|
-
|
|
10832
|
-
|
|
11630
|
+
/** The editor's "copy" exit: the annotated result goes to the clipboard. */
|
|
11631
|
+
async function screenshotCopy(dataUrl) {
|
|
11632
|
+
if (typeof dataUrl !== 'string' || dataUrl === '') return
|
|
11633
|
+
const copied = await ideShotRequest({ copyDataUrl: dataUrl })
|
|
10833
11634
|
store.setScreenshot(null)
|
|
10834
|
-
|
|
10835
|
-
const copied = await ideShotRequest({ copyOf: shot.path })
|
|
10836
|
-
store.setNotice(copied.ok ? `${translate('shotCopied')}: ${shot.path}` : translate('shotFailed'))
|
|
11635
|
+
store.setNotice(copied.ok ? translate('shotCopied') : translate('shotFailed'))
|
|
10837
11636
|
}
|
|
10838
11637
|
|
|
10839
11638
|
async function screenshotOpenSettings() {
|
|
@@ -10842,7 +11641,6 @@ function apply(ctx) {
|
|
|
10842
11641
|
}
|
|
10843
11642
|
|
|
10844
11643
|
const screenshotClose = () => store.setScreenshot(null)
|
|
10845
|
-
const screenshotRetry = () => { void startScreenshot() }
|
|
10846
11644
|
|
|
10847
11645
|
/**
|
|
10848
11646
|
* Back to the conversation with the reference appended to the draft.
|
|
@@ -10916,6 +11714,8 @@ function apply(ctx) {
|
|
|
10916
11714
|
{ id: 'jump', labelKey: 'paletteActionJump', run: () => store.setJumpEnabled(!store.getState().jumpEnabled) },
|
|
10917
11715
|
{ id: 'closeTabs', labelKey: 'paletteActionCloseTabs', run: () => store.closeAllTabs() },
|
|
10918
11716
|
{ id: 'back', labelKey: 'paletteActionBack', run: () => backToChat() },
|
|
11717
|
+
// Kept in the list on every runtime: in a browser the entry explains why the
|
|
11718
|
+
// feature needs the desktop app instead of silently doing nothing.
|
|
10919
11719
|
{ id: 'screenshot', labelKey: 'paletteActionScreenshot', run: () => { void startScreenshot() } },
|
|
10920
11720
|
{ id: 'licenseRelogin', labelKey: 'paletteActionLicenseRelogin', run: () => { void reloginLicense() } },
|
|
10921
11721
|
{ id: 'diagnostics', labelKey: 'paletteActionDiagnostics', run: () => { void exportDiagnostics() } },
|
|
@@ -11243,11 +12043,6 @@ function apply(ctx) {
|
|
|
11243
12043
|
navigate,
|
|
11244
12044
|
paletteActions,
|
|
11245
12045
|
onReferenceToChat: referenceToChat,
|
|
11246
|
-
onScreenshotJump: screenshotJump,
|
|
11247
|
-
onScreenshotKeep: screenshotKeep,
|
|
11248
|
-
onScreenshotRetry: screenshotRetry,
|
|
11249
|
-
onScreenshotOpenSettings: screenshotOpenSettings,
|
|
11250
|
-
onScreenshotClose: screenshotClose,
|
|
11251
12046
|
}),
|
|
11252
12047
|
}, IdePanel))
|
|
11253
12048
|
ctx.effect(() => {
|
|
@@ -11265,11 +12060,6 @@ function apply(ctx) {
|
|
|
11265
12060
|
navigate,
|
|
11266
12061
|
paletteActions,
|
|
11267
12062
|
onReferenceToChat: referenceToChat,
|
|
11268
|
-
onScreenshotJump: screenshotJump,
|
|
11269
|
-
onScreenshotKeep: screenshotKeep,
|
|
11270
|
-
onScreenshotRetry: screenshotRetry,
|
|
11271
|
-
onScreenshotOpenSettings: screenshotOpenSettings,
|
|
11272
|
-
onScreenshotClose: screenshotClose,
|
|
11273
12063
|
}),
|
|
11274
12064
|
}, IdePanel))
|
|
11275
12065
|
mainRegistered = true
|
|
@@ -11488,6 +12278,24 @@ function apply(ctx) {
|
|
|
11488
12278
|
inject: () => ({ store }),
|
|
11489
12279
|
}, IdeSessionTracker)), 'dsh-ide-window: session tracker')
|
|
11490
12280
|
|
|
12281
|
+
// The screenshot editor lives at shell level: it must cover the window (not
|
|
12282
|
+
// the centre panel) and must not be clipped by the panel's overflow.
|
|
12283
|
+
ctx.effect(() => ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
12284
|
+
name: 'shell.overlay',
|
|
12285
|
+
id: `${IDE_NS}:screenshot`,
|
|
12286
|
+
order: 41,
|
|
12287
|
+
registrant: IDE_NS,
|
|
12288
|
+
locale: IDE_NS,
|
|
12289
|
+
inject: () => ({
|
|
12290
|
+
store,
|
|
12291
|
+
tr: translate,
|
|
12292
|
+
onInsert: screenshotInsert,
|
|
12293
|
+
onCopy: screenshotCopy,
|
|
12294
|
+
onOpenSettings: screenshotOpenSettings,
|
|
12295
|
+
onClose: screenshotClose,
|
|
12296
|
+
}),
|
|
12297
|
+
}, IdeScreenshotEditor)), 'dsh-ide-window: screenshot editor')
|
|
12298
|
+
|
|
11491
12299
|
|
|
11492
12300
|
/**
|
|
11493
12301
|
* The right-Sidebar page type and its body.
|