1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { BaseElement, element } from '../../../base-ui/BaseElement'; 17import { HdcDeviceManager } from '../../../hdc/HdcDeviceManager'; 18import { SpRecordTrace } from '../SpRecordTrace'; 19import { DataMessage } from '../../../hdc/message/DataMessage'; 20 21@element('sp-web-hdc-shell') 22export class SpWebHdcShell extends BaseElement { 23 private static MAX_DISPLAY_ROWS = 1000; 24 private static MAX_SAVE_SIZE = 2097152; 25 shellDiv: HTMLDivElement | null | undefined; 26 currentScreenRemain: number = 0; 27 private shellCanvas: HTMLCanvasElement | null | undefined; 28 private shellCanvasCtx: CanvasRenderingContext2D | null | undefined; 29 private resultStr = ''; 30 private sendCallBack: ((keyboardEvent: KeyboardEvent | string) => void | undefined) | undefined; 31 private startShellDevice = ''; 32 private intervalId: number | undefined; 33 private skipFlag: number[] = [7]; 34 private clearFlag: number[] = [27, 91, 50, 74, 27, 91, 72]; 35 private CRLFFlag: number[] = [13, 13, 10]; 36 private startRealTimeFlag: number[] = [27, 91, 115]; 37 private endRealTimeFlag: number[] = [27, 91, 117]; 38 private clearRealTimeFlag: number[] = [27, 91, 72, 27, 91, 74]; 39 private ctrlCFlag: number[] = [13, 10, 35, 32]; 40 private points: Point | undefined; 41 private forwardFlag: boolean = false; 42 private cursorIndex: number = 3; 43 private shellStrLength: number = 0; 44 private textY: number = 0; 45 private cursorRow: string = ''; 46 private textDecoder: TextDecoder = new TextDecoder(); 47 private isDragging: boolean = false; 48 private static TOP_OFFSET = 48; 49 private static FIRST_ROW_OFFSET = 32; 50 private static LAST_ROW_OFFSET = 40; 51 private static MULTI_LINE_FLAG = '<\b'; 52 private static LINE_BREAK_LENGTH = 2; 53 private static LEFT_OFFSET = 48; 54 private realTimeResult: string | null | undefined = ''; 55 private startRealTime: boolean = false; 56 private prevTextY: number = 0; 57 58 public initElements(): void { 59 this.shellCanvas = this.shadowRoot!.querySelector<HTMLCanvasElement>('#shell_cmd'); 60 this.shellCanvasCtx = this.shellCanvas!.getContext('2d'); 61 this.shellCanvasCtx!.fillStyle = '#000'; 62 63 this.shellCanvasCtx!.fillRect(0, 0, this.shellCanvas!.width, this.shellCanvas!.height); 64 this.shellDiv = this.shadowRoot!.querySelector<HTMLDivElement>('.shell_cmd_div'); 65 this.shellCanvasAddMouseListener(); 66 this.shellCanvas!.addEventListener('contextmenu', (event) => { 67 event.preventDefault(); 68 event.stopPropagation(); 69 }); 70 this.shellCanvas!.addEventListener('keydown', async (keyboardEvent) => { 71 keyboardEvent.preventDefault(); 72 if (keyboardEvent.ctrlKey && keyboardEvent.code === 'KeyC' && this.points) { 73 let rowText: string = this.getSelectedText(); 74 this.points = undefined; 75 await navigator.clipboard.writeText(rowText); 76 } else { 77 if (this.sendCallBack) { 78 this.sendCallBack(keyboardEvent); 79 } 80 } 81 }); //@ts-ignore 82 window.subscribe(window.SmartEvent.UI.DeviceConnect, (deviceName: string) => { 83 if (deviceName) { 84 this.hdcShellFocus(); 85 } 86 }); 87 window.subscribe(window.SmartEvent.UI.DeviceDisConnect, () => { 88 this.clear(); 89 }); 90 this.shellCanvas!.addEventListener('blur', () => { 91 if (this.intervalId) { 92 window.clearInterval(this.intervalId); 93 } 94 this.shellCanvasCtx!.clearRect(this.shellStrLength, this.textY, 12, 3); 95 }); 96 new ResizeObserver(() => { 97 this.resizeCanvas(); 98 this.refreshShellPage(true); 99 }).observe(this); 100 } 101 102 resizeCanvas(): void { 103 if (this.shellCanvas !== null && this.shellCanvas !== undefined) { 104 this.shellCanvas.width = this.shellCanvas.clientWidth; 105 this.shellCanvas.height = this.shellCanvas.clientHeight; 106 } 107 } 108 109 clear(): void { 110 this.sendCallBack = undefined; 111 this.resultStr = ''; 112 this.cursorRow = ''; 113 this.shellCanvasCtx!.clearRect(0, 0, this.shellCanvas!.width, this.shellCanvas!.height); 114 this.shellCanvasCtx!.fillStyle = '#000'; 115 this.shellCanvasCtx!.fillRect(0, 0, this.shellCanvas!.width, this.shellCanvas!.height); 116 window.clearInterval(this.intervalId); 117 } 118 119 public hdcShellFocus(): void { 120 HdcDeviceManager.connect(SpRecordTrace.serialNumber).then((connected) => { 121 if (connected) { 122 if (this.sendCallBack && this.startShellDevice === SpRecordTrace.serialNumber) { 123 this.shellCanvas!.focus(); 124 this.refreshShellPage(true); 125 } else { 126 this.clear(); 127 this.sendCallBack = HdcDeviceManager.startShell((result: DataMessage) => { 128 if (result.channelClose) { 129 this.clear(); 130 return; 131 } 132 this.startShellDevice = SpRecordTrace.serialNumber; 133 this.handleHdcRecvData(result); 134 }); 135 this.shellCanvas!.focus(); 136 this.refreshShellPage(true); 137 } 138 } else { 139 this.clear(); 140 } 141 }); 142 } 143 144 arrayBufferCompare(compareA: ArrayBuffer, compareB: number[]): boolean { 145 const arrayA = new Uint8Array(compareA); 146 if (arrayA.length === compareB.length) { 147 for (let i = 0; i < arrayA.length; i++) { 148 const dd = arrayA[i]; 149 if (dd !== compareB[i]) { 150 return false; 151 } 152 } 153 return true; 154 } 155 return false; 156 } 157 158 getSelectedText(): string { 159 let selectedText = ''; 160 let textLines = [...this.finalArr]; 161 let startX = this.points!.startX < SpWebHdcShell.LEFT_OFFSET ? SpWebHdcShell.LEFT_OFFSET : this.points!.startX; 162 let startY = this.points!.startY; 163 let endX = this.points!.endX < SpWebHdcShell.LEFT_OFFSET ? SpWebHdcShell.LEFT_OFFSET : this.points!.endX; 164 let endY = this.points!.endY; 165 let endTop = Math.ceil((endY - SpWebHdcShell.TOP_OFFSET) / 16); 166 let startTop = Math.floor((startY - SpWebHdcShell.TOP_OFFSET - 2) / 16); 167 let selectRangeList = textLines.slice(startTop + 1, endTop); 168 let charWidth = this.shellCanvasCtx!.measureText(selectRangeList[0].split('')[0]).width; 169 for (let index = 0; index < selectRangeList.length; index++) { 170 let currentIndexLine = selectRangeList[index]; 171 if (index === 0) { 172 let startNum = Math.floor((startX - SpWebHdcShell.LEFT_OFFSET) / charWidth); 173 selectedText = currentIndexLine.slice(startNum); 174 } else if (index === selectRangeList.length - 1) { 175 let endNum = Math.ceil((endX - SpWebHdcShell.LEFT_OFFSET) / charWidth); 176 selectedText += currentIndexLine.slice(0, endNum); 177 } else { 178 selectedText += `${currentIndexLine}\n`; 179 } 180 } 181 return selectedText.trim(); 182 } 183 184 forwardSelected(startX: number, startY: number, endX: number, endY: number): void { 185 //左边界x为SpWebHdcShell.LEFT_OFFSET,右边界为this.shellCanvas!.width 186 let depth = Math.ceil((endY - startY) / 16); 187 let startPointX = 0; 188 let startPointY = 0; 189 let endPointX = 0; 190 let endPointY = 0; 191 if (depth <= 1) { 192 this.shellCanvasCtx!.fillRect(startX, startY, endX - startX, endY - startY); 193 startPointX = startX; 194 startPointY = startY; 195 endPointX = endX; 196 endPointY = endY; 197 } else { 198 //绘制多行 199 for (let index = 1; index <= depth; index++) { 200 //第一行,绘起始点到canvas右边界矩形 201 if (index === 1) { 202 this.shellCanvasCtx!.fillRect(startX, startY, this.shellCanvas!.width - startX, index * 16); 203 startPointX = startX; 204 startPointY = startY; 205 } else if (index === depth) { 206 //最后一行,canvas左边界到结束点矩形 207 this.shellCanvasCtx!.fillRect( 208 SpWebHdcShell.LEFT_OFFSET, 209 startY + (index - 1) * 16, 210 endX - SpWebHdcShell.LEFT_OFFSET, 211 endY - (startY + (index - 1) * 16) 212 ); 213 endPointX = endX; 214 endPointY = endY; 215 } else { 216 //中间行,canvas的左边界到右边界的矩形 217 this.shellCanvasCtx!.fillRect( 218 SpWebHdcShell.LEFT_OFFSET, 219 startY + (index - 1) * 16, 220 this.shellCanvas!.width, 221 16 222 ); 223 } 224 } 225 } 226 this.points = { startX: startPointX, startY: startPointY, endX: endPointX, endY: endPointY }; 227 } 228 229 getCurrentLineBackSize(currentLine: string, maxBackSize: number, isStart: boolean): number { 230 let fillText = ''; 231 let strings = currentLine.split(''); 232 for (let index = 0; index < strings.length; index++) { 233 let text = strings[index]; 234 if ( 235 this.shellCanvasCtx!.measureText(fillText).width < maxBackSize && 236 this.shellCanvasCtx!.measureText(fillText + text).width >= maxBackSize 237 ) { 238 if (!isStart) { 239 fillText += text; 240 } 241 break; 242 } 243 fillText += text; 244 } 245 return fillText.length; 246 } 247 248 reverseSelected(startX: number, startY: number, endX: number, endY: number): void { 249 //左边界x为SpWebHdcShell.LEFT_OFFSET,右边界为this.shellCanvas!.width 250 let depth = Math.ceil((startY - endY) / 16); 251 let startPointX = 0; 252 let startPointY = 0; 253 let endPointX = 0; 254 let endPointY = 0; 255 if (depth <= 1) { 256 this.shellCanvasCtx!.fillRect(endX, endY, startX - endX, startY - endY); 257 startPointX = endX; 258 startPointY = endY; 259 endPointX = startX; 260 endPointY = startY; 261 } else { 262 //绘制多行 263 for (let index = 1; index <= depth; index++) { 264 //第一行,绘起始点到canvas左边界矩形 265 if (index === 1) { 266 this.shellCanvasCtx!.fillRect(SpWebHdcShell.LEFT_OFFSET, startY - 16, startX - SpWebHdcShell.LEFT_OFFSET, 16); 267 endPointX = startX; 268 endPointY = startY; 269 } else if (index === depth) { 270 //最后一行,canvas右边界到结束点矩形 271 this.shellCanvasCtx!.fillRect(endX, endY, this.shellCanvas!.width - endX, startY - (index - 1) * 16 - endY); 272 startPointX = endX; 273 startPointY = endY; 274 } else { 275 this.shellCanvasCtx!.fillRect(SpWebHdcShell.LEFT_OFFSET, startY - index * 16, this.shellCanvas!.width, 16); 276 this.shellCanvasCtx!.textBaseline = 'middle'; 277 } 278 } 279 } 280 this.points = { startX: startPointX, startY: startPointY, endX: endPointX, endY: endPointY }; 281 } 282 283 private singleLineToMultiLine(shellStr: string, foundationWidth: number, maxWidth: number): string[] { 284 let result = []; 285 while (shellStr.length * foundationWidth > maxWidth) { 286 let bfb = maxWidth / (shellStr.length * foundationWidth); 287 let cutIndex = Math.floor(shellStr.length * bfb); 288 let ss = shellStr.substring(0, cutIndex); 289 result.push(ss); 290 shellStr = shellStr.substring(cutIndex); 291 } 292 if (shellStr.length > 0) { 293 result.push(shellStr); 294 } 295 return result; 296 } 297 298 private finalArr: Array<string> = []; 299 300 private drawShellPage(resultStrArr: string[]): void { 301 let maxWidth = this.shellCanvas!.width; 302 let foundationWidth = Math.ceil(this.shellCanvasCtx!.measureText(' ').width); 303 for (let index = 0; index < resultStrArr.length - 1; index++) { 304 let shellStr = resultStrArr[index]; 305 let strWidth = this.shellCanvasCtx!.measureText(shellStr).width; 306 if (strWidth > maxWidth) { 307 let lines = this.singleLineToMultiLine(shellStr, foundationWidth, maxWidth - SpWebHdcShell.LEFT_OFFSET); 308 this.finalArr.push(...lines); 309 } else { 310 this.finalArr.push(shellStr); 311 } 312 } 313 if (this.finalArr.length > SpWebHdcShell.MAX_DISPLAY_ROWS) { 314 this.finalArr.splice(0, this.finalArr.length - SpWebHdcShell.MAX_DISPLAY_ROWS + 1); 315 } 316 this.shellCanvasCtx!.fillStyle = '#fff'; 317 this.shellCanvasCtx!.font = '16px serif'; 318 this.textY = SpWebHdcShell.TOP_OFFSET; 319 this.finalArr.push(this.cursorRow); 320 for (let index: number = 0; index < this.finalArr.length; index++) { 321 let shellStr: string = this.finalArr[index]; 322 this.textY = SpWebHdcShell.TOP_OFFSET + index * 16; 323 this.shellCanvasCtx!.fillText(shellStr, SpWebHdcShell.LEFT_OFFSET, this.textY); 324 } 325 } 326 327 private drawCursorStyle(): void { 328 if (this.intervalId) { 329 window.clearInterval(this.intervalId); 330 } 331 let needClear = false; 332 this.intervalId = window.setInterval(() => { 333 if (needClear) { 334 needClear = false; 335 this.shellCanvasCtx!.fillStyle = '#000'; 336 this.shellCanvasCtx!.fillRect(this.shellStrLength, this.textY, 12, 3); 337 } else { 338 needClear = true; 339 this.shellCanvasCtx!.fillStyle = '#fff'; 340 this.shellCanvasCtx!.fillRect(this.shellStrLength, this.textY, 12, 3); 341 } 342 }, 500); 343 } 344 345 refreshShellPage(scroller: boolean): void { 346 try { 347 if (this.resultStr.length === 0 && this.cursorRow.length === 0) { 348 return; 349 } 350 this.shellCanvasCtx!.clearRect(0, 0, this.shellCanvas!.width, this.shellCanvas!.height); 351 this.shellCanvasCtx!.fillStyle = '#000'; 352 this.shellCanvasCtx!.fillRect(0, 0, this.shellCanvas!.width, this.shellCanvas!.height); 353 let resultStrArr = this.resultStr.split('\r\n'); 354 if (this.realTimeResult !== '') { 355 resultStrArr = (this.resultStr + this.realTimeResult).split('\r\n'); 356 } 357 this.finalArr = []; 358 if (this.shellCanvas!.width > 0) { 359 this.drawShellPage(resultStrArr); 360 this.shellStrLength = 361 this.shellCanvasCtx!.measureText(this.cursorRow.slice(0, this.cursorIndex)).width + SpWebHdcShell.LEFT_OFFSET; 362 // 记录前一次滚动条的位置 363 this.prevTextY = this.shellDiv!.scrollTop + this.shellDiv!.clientHeight - 3; 364 if (scroller && this.textY > this.shellDiv!.clientHeight && this.textY > this.prevTextY) { 365 this.shellDiv!.scrollTop = this.textY - this.shellDiv!.clientHeight + 3; 366 this.currentScreenRemain = this.shellDiv!.scrollTop; 367 } 368 this.drawCursorStyle(); 369 } 370 } catch (e) { } 371 } 372 373 public initHtml(): string { 374 return ` 375 <style> 376 :host{ 377 display: block; 378 border-radius: 0 16px 16px 0; 379 width: 100%; 380 position: relative; 381 } 382 .shell_cmd_div { 383 width: 90%; 384 margin-left: 5%; 385 margin-top: 3%; 386 overflow-y: scroll; 387 height: 40rem; 388 background: #000; 389 border: 1px solid var(--dark-color1,#4D4D4D); 390 border-radius: 16px; 391 } 392 ::-webkit-scrollbar{ 393 width: 13px; 394 height: 10px; 395 background-color: #FFFFFF; 396 } 397 ::-webkit-scrollbar-track{ 398 border-top-right-radius: 16px; 399 border-bottom-right-radius: 16px; 400 background-color: #000000; 401 } 402 ::-webkit-scrollbar-thumb{ 403 background: #5A5A5A; 404 border-radius: 6px; 405 } 406 canvas { 407 display: inline-block; 408 outline: none; 409 } 410 411 </style> 412 <div class="shell_cmd_div"> 413 <canvas id="shell_cmd" style="width: 100%;height:${16000 + SpWebHdcShell.TOP_OFFSET}px;" tabindex="0"></canvas> 414 </div> 415 `; 416 } 417 418 private refreshCurrentRow(): void { 419 let lastRow: string = this.resultStr; 420 if (this.resultStr.lastIndexOf('\r\n') !== -1) { 421 lastRow = this.resultStr.substring(this.resultStr.lastIndexOf('\r\n') + 2); 422 } 423 let currentRow: string[] = [...lastRow]; 424 let result: string[] = []; 425 this.cursorIndex = 0; 426 for (let index: number = 0; index < currentRow.length; index++) { 427 let currentResult: string = currentRow[index]; 428 if (currentResult === '\b') { 429 this.cursorIndex--; 430 } else { 431 result[this.cursorIndex] = currentResult; 432 this.cursorIndex++; 433 } 434 } 435 this.cursorRow = result.join(''); 436 } 437 438 private handleHdcRecvData(result: DataMessage): void { 439 const resData = result.getData(); 440 if (resData) { 441 if (this.arrayBufferCompare(resData, this.skipFlag)) { 442 return; 443 } else if (this.arrayBufferCompare(resData, this.clearFlag)) { 444 this.resultStr = ''; 445 this.shellDiv!.scrollTop = 0; 446 this.cursorIndex = 3; 447 } else if (this.arrayBufferCompare(resData, this.CRLFFlag)) { 448 if (this.resultStr.lastIndexOf('\r\n') !== -1) { 449 this.resultStr = this.resultStr.substring(0, this.resultStr.lastIndexOf('\r\n') + 2) + this.cursorRow; 450 } else { 451 this.resultStr = this.cursorRow; 452 } 453 this.resultStr += result.getDataToString(); 454 this.cursorIndex = 3; 455 } else { 456 if (this.resultStr.length > SpWebHdcShell.MAX_SAVE_SIZE) { 457 this.resultStr = this.resultStr.substring(this.resultStr.length / 2); 458 } 459 const arrayA = new Uint8Array(resData); 460 if (arrayA[0] === 13 && arrayA[1] !== 10 && arrayA[1] !== 13) { 461 this.hdcRecvEnterAndBracket(arrayA, result); 462 } else if (this.isStartWidthArrayBuffer(arrayA, this.startRealTimeFlag)) { 463 let lastIndex = this.getLastRestorationIndex(arrayA, this.endRealTimeFlag); 464 this.realTimeResult = this.removeTextAndColorSequenceStr( 465 this.textDecoder.decode(arrayA.slice(lastIndex, arrayA.length)) 466 ); 467 this.startRealTime = true; 468 } else if (this.isStartWidthArrayBuffer(arrayA, this.clearRealTimeFlag)) { 469 this.realTimeResult = this.removeTextAndColorSequenceStr( 470 this.textDecoder.decode(arrayA.slice(6, arrayA.length)) 471 ); 472 this.startRealTime = true; 473 } else { 474 if (this.isStartWidthArrayBuffer(arrayA, this.ctrlCFlag)) { 475 this.resultStr += this.realTimeResult; 476 this.startRealTime = false; 477 } 478 this.hdcRecvRealMessage(result); 479 } 480 } 481 this.resultStr = this.removeTextAndColorSequenceStr(this.resultStr); 482 this.refreshCurrentRow(); 483 this.refreshShellPage(true); 484 } 485 } 486 487 private hdcRecvEnterAndBracket(arrayA: Uint8Array, result: DataMessage): void { 488 const index = this.resultStr.lastIndexOf('\n'); 489 const resultStrLength = this.resultStr.length; 490 if (index > -1 && resultStrLength > index) { 491 this.resultStr = this.resultStr.substring(0, index + 1) + this.textDecoder.decode(arrayA.slice(1, arrayA.length)); 492 } else { 493 if (this.resultStr.split('\n').length === 1) { 494 const index = this.cursorRow.lastIndexOf('\n'); 495 this.cursorRow = 496 this.cursorRow.substring(0, index + 1) + this.textDecoder.decode(arrayA.slice(1, arrayA.length)); 497 this.resultStr = this.cursorRow; 498 } else { 499 this.resultStr += result.getDataToString(); 500 } 501 } 502 this.realTimeResult = ''; 503 } 504 505 private hdcRecvRealMessage(result: DataMessage): void { 506 if (this.startRealTime) { 507 if (result.getDataToString().includes(SpWebHdcShell.MULTI_LINE_FLAG)) { 508 this.realTimeResult += result.getDataToString().substring(result.getDataToString().indexOf('\r')); 509 } else { 510 this.realTimeResult += result.getDataToString(); 511 } 512 this.realTimeResult = this.removeTextAndColorSequenceStr(this.realTimeResult!); 513 } else { 514 this.realTimeResult = ''; 515 if (result.getDataToString().includes(SpWebHdcShell.MULTI_LINE_FLAG)) { 516 // 获取所有内容,不包括最后一行数据 517 this.resultStr = this.resultStr.substring( 518 0, 519 this.resultStr.lastIndexOf('\r\n') + SpWebHdcShell.LINE_BREAK_LENGTH 520 ); 521 // 多行情况不能直接拼接返回数据 522 this.resultStr += result.getDataToString().substring(result.getDataToString().indexOf('\r')); 523 } else { 524 this.resultStr += result.getDataToString(); 525 } 526 } 527 } 528 529 private removeTextAndColorSequenceStr(currentStr: string): string { 530 return currentStr.replace(new RegExp(/\x1B\[[0-9;]*[a-zA-Z]/g), ''); 531 } 532 533 private isStartWidthArrayBuffer(sourceArray: Uint8Array, compareArray: number[]): boolean { 534 for (let index = 0; index < compareArray.length; index++) { 535 if (sourceArray[index] !== compareArray[index]) { 536 return false; 537 } 538 } 539 return true; 540 } 541 542 private getLastRestorationIndex(sourceArray: Uint8Array, compareArray: number[]): number { 543 let lastIndex = -1; 544 for (let index = sourceArray.length - 1; index >= 0; index--) { 545 if (sourceArray[index] === compareArray[0]) { 546 let isLast = true; 547 for (let j = 1; j < compareArray.length; j++) { 548 if (sourceArray[index + j] !== compareArray[j]) { 549 isLast = false; 550 break; 551 } 552 } 553 if (isLast) { 554 lastIndex = index; 555 break; 556 } 557 } 558 } 559 return lastIndex + compareArray.length; 560 } 561 562 private shellCanvasAddMouseListener(): void { 563 let startX: number; 564 let startY: number; 565 let endX: number; 566 let endY: number; 567 this.shellCanvas!.addEventListener('mousedown', (event) => { 568 if (this.resultStr.length === 0 && this.cursorRow.length === 0) { 569 return; 570 } 571 this.isDragging = true; 572 startX = event.offsetX; 573 startY = event.offsetY; 574 this.refreshShellPage(false); 575 }); 576 this.shellCanvas!.addEventListener('mousemove', (event) => { 577 if (!this.isDragging) { 578 return; 579 } 580 if (this.resultStr.length === 0 && this.cursorRow.length === 0) { 581 return; 582 } 583 endX = event.offsetX; 584 endY = event.offsetY; 585 this.refreshShellPage(false); 586 this.points = undefined; 587 this.shellCanvasCtx!.fillStyle = 'rgba(128, 128, 128, 0.5)'; 588 if (endY > startY) { 589 this.forwardFlag = true; 590 this.forwardSelected(startX, startY, endX, endY); 591 } else { 592 this.forwardFlag = false; 593 this.reverseSelected(startX, startY, endX, endY); 594 } 595 }); 596 this.shellCanvasAddMouseUpListener(); 597 } 598 599 private shellCanvasAddMouseUpListener(): void { 600 this.shellCanvas!.addEventListener('mouseup', async (event)=> { 601 if (!this.isDragging) { 602 return; 603 } 604 if (this.resultStr.length === 0 && this.cursorRow.length === 0) { 605 return; 606 } 607 this.isDragging = false; 608 //右键 609 if (event.button === 2) { 610 let text: string = await navigator.clipboard.readText(); 611 if (text) { 612 if (this.sendCallBack) { 613 this.sendCallBack(text); 614 } 615 return; 616 } 617 } 618 }); 619 } 620} 621 622export class Point { 623 startX: number = 0; 624 startY: number = 0; 625 endX: number = 0; 626 endY: number = 0; 627} 628