1/* 2 * Copyright (C) 2025 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 unknown 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 { SpSystemTrace } from './SpSystemTrace'; 18import { SpSnapShotViewHtml } from './SpSnapShotView.html'; 19import { SnapShotStruct } from '../database/ui-worker/ProcedureWorkerSnaps'; 20 21@element('sp-snapshot-view') 22export class SpSnapShotView extends BaseElement { 23 private chatBox: HTMLElement | undefined | null; 24 private snapShotView: HTMLElement | undefined | null; 25 26 initElements(): void { 27 this.chatBox = document.querySelector("body > sp-application")?.shadowRoot?.querySelector("#sp-snapshot-view")?.shadowRoot?.querySelector(".chatBox"); 28 this.snapShotView = document.querySelector("body > sp-application")?.shadowRoot?.querySelector("#sp-snapshot-view"); 29 let sp = document.querySelector("body > sp-application")?.shadowRoot?.querySelector("#sp-system-trace") as SpSystemTrace; 30 let closeBtn = document.querySelector("body > sp-application")?.shadowRoot?.querySelector("#sp-snapshot-view")?.shadowRoot?.querySelector("div > lit-icon")?.shadowRoot?.querySelector('#icon'); 31 closeBtn?.addEventListener('click', () => { 32 this.snapShotView!.style.visibility = 'hidden'; 33 this.snapShotView!.style.display = 'none'; 34 SnapShotStruct.hoverSnapShotStruct = undefined; 35 SnapShotStruct.selectSnapShotStruct = undefined; 36 SnapShotStruct.isClear = true; 37 setTimeout(() => { 38 SnapShotStruct.isClear = false; 39 }, 0); 40 sp.refreshCanvas(true); 41 }) 42 } 43 44 init(data: SnapShotStruct): void { 45 this.drawImage(data.img); 46 } 47 48 drawImage(base64Image: string): void { 49 const imageContainer = this.chatBox!.querySelector('.image-container') as HTMLElement; 50 imageContainer.innerHTML = ''; 51 const proportion = 350 * 2720 / 1260; 52 const img = document.createElement('img'); 53 img.src = base64Image; 54 img.style.width = '350px'; 55 img.style.maxHeight = `${proportion}px`; 56 57 imageContainer.appendChild(img); 58 } 59 60 initHtml(): string { 61 return SpSnapShotViewHtml; 62 } 63}