1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_ciimport { BaseElement, element } from '../../../base-ui/BaseElement'; 17fb726d48Sopenharmony_ciimport '../../../base-ui/select/LitSelectV'; 18fb726d48Sopenharmony_ciimport '../../../base-ui/select/LitSelect'; 19fb726d48Sopenharmony_ci 20fb726d48Sopenharmony_ciimport '../../../base-ui/switch/lit-switch'; 21fb726d48Sopenharmony_ciimport LitSwitch, { LitSwitchChangeEvent } from '../../../base-ui/switch/lit-switch'; 22fb726d48Sopenharmony_ciimport { LitSelectV } from '../../../base-ui/select/LitSelectV'; 23fb726d48Sopenharmony_ciimport { LitAllocationSelect } from '../../../base-ui/select/LitAllocationSelect'; 24fb726d48Sopenharmony_ciimport { SpSdkConfigHtml } from './SpSdkConfig.html'; 25fb726d48Sopenharmony_ci 26fb726d48Sopenharmony_ci@element('sp-sdk-config') 27fb726d48Sopenharmony_ciexport class SpSdkConfig extends BaseElement { 28fb726d48Sopenharmony_ci private worker: Worker | undefined; 29fb726d48Sopenharmony_ci private sdkConfigList: unknown; 30fb726d48Sopenharmony_ci private customConfig: HTMLDivElement | undefined | null; 31fb726d48Sopenharmony_ci private selectConfig: LitSelectV | undefined | null; 32fb726d48Sopenharmony_ci private list: Array<HTMLElement> | undefined; 33fb726d48Sopenharmony_ci private pluginName: string = ''; 34fb726d48Sopenharmony_ci private sampleInterval: number = 5000; 35fb726d48Sopenharmony_ci 36fb726d48Sopenharmony_ci static get observedAttributes(): string[] { 37fb726d48Sopenharmony_ci return ['configName', 'value', 'type']; 38fb726d48Sopenharmony_ci } 39fb726d48Sopenharmony_ci 40fb726d48Sopenharmony_ci get show(): boolean { 41fb726d48Sopenharmony_ci return this.hasAttribute('show'); 42fb726d48Sopenharmony_ci } 43fb726d48Sopenharmony_ci 44fb726d48Sopenharmony_ci set show(sdkConfigShow: boolean) { 45fb726d48Sopenharmony_ci if (sdkConfigShow) { 46fb726d48Sopenharmony_ci this.setAttribute('show', ''); 47fb726d48Sopenharmony_ci } else { 48fb726d48Sopenharmony_ci this.removeAttribute('show'); 49fb726d48Sopenharmony_ci } 50fb726d48Sopenharmony_ci } 51fb726d48Sopenharmony_ci 52fb726d48Sopenharmony_ci set startSamp(sdkConfigStart: boolean) { 53fb726d48Sopenharmony_ci if (sdkConfigStart) { 54fb726d48Sopenharmony_ci this.setAttribute('startSamp', ''); 55fb726d48Sopenharmony_ci } else { 56fb726d48Sopenharmony_ci this.removeAttribute('startSamp'); 57fb726d48Sopenharmony_ci } 58fb726d48Sopenharmony_ci } 59fb726d48Sopenharmony_ci 60fb726d48Sopenharmony_ci get startSamp(): boolean { 61fb726d48Sopenharmony_ci return this.hasAttribute('startSamp'); 62fb726d48Sopenharmony_ci } 63fb726d48Sopenharmony_ci 64fb726d48Sopenharmony_ci set configName(configName: string) { 65fb726d48Sopenharmony_ci if (configName !== '') { 66fb726d48Sopenharmony_ci this.setAttribute('configName', configName); 67fb726d48Sopenharmony_ci } else { 68fb726d48Sopenharmony_ci this.removeAttribute('configName'); 69fb726d48Sopenharmony_ci } 70fb726d48Sopenharmony_ci } 71fb726d48Sopenharmony_ci 72fb726d48Sopenharmony_ci get configName(): string { 73fb726d48Sopenharmony_ci return this.getAttribute('configName') || ''; 74fb726d48Sopenharmony_ci } 75fb726d48Sopenharmony_ci 76fb726d48Sopenharmony_ci get type(): string { 77fb726d48Sopenharmony_ci return this.getAttribute('type') || ''; 78fb726d48Sopenharmony_ci } 79fb726d48Sopenharmony_ci 80fb726d48Sopenharmony_ci set type(type: string) { 81fb726d48Sopenharmony_ci if (type !== '') { 82fb726d48Sopenharmony_ci this.setAttribute('type', type); 83fb726d48Sopenharmony_ci } else { 84fb726d48Sopenharmony_ci this.removeAttribute('type'); 85fb726d48Sopenharmony_ci } 86fb726d48Sopenharmony_ci } 87fb726d48Sopenharmony_ci 88fb726d48Sopenharmony_ci private wasmMap: Map<string, unknown> = new Map<string, unknown>(); 89fb726d48Sopenharmony_ci private wasmList: Array<string> = []; 90fb726d48Sopenharmony_ci 91fb726d48Sopenharmony_ci private changGpu(gpuName: string): void { 92fb726d48Sopenharmony_ci let config = this.wasmMap.get(gpuName); 93fb726d48Sopenharmony_ci //@ts-ignore 94fb726d48Sopenharmony_ci this.pluginName = config?.pluginName; 95fb726d48Sopenharmony_ci //@ts-ignore 96fb726d48Sopenharmony_ci this.sampleInterval = config?.sampleInterval; 97fb726d48Sopenharmony_ci let pam = { 98fb726d48Sopenharmony_ci action: 'open', 99fb726d48Sopenharmony_ci //@ts-ignore 100fb726d48Sopenharmony_ci componentId: config.componentId, 101fb726d48Sopenharmony_ci //@ts-ignore 102fb726d48Sopenharmony_ci wasmJsName: config.wasmJsName, 103fb726d48Sopenharmony_ci //@ts-ignore 104fb726d48Sopenharmony_ci WasmName: config.wasmName, 105fb726d48Sopenharmony_ci }; 106fb726d48Sopenharmony_ci this.worker!.postMessage(pam); 107fb726d48Sopenharmony_ci this.worker!.onmessage = (event: MessageEvent): void => { 108fb726d48Sopenharmony_ci let results = event.data.results; 109fb726d48Sopenharmony_ci this.sdkConfigList = results.settingConfig; 110fb726d48Sopenharmony_ci this.initConfig(); 111fb726d48Sopenharmony_ci }; 112fb726d48Sopenharmony_ci } 113fb726d48Sopenharmony_ci 114fb726d48Sopenharmony_ci getPlugName(): string { 115fb726d48Sopenharmony_ci return this.pluginName; 116fb726d48Sopenharmony_ci } 117fb726d48Sopenharmony_ci 118fb726d48Sopenharmony_ci getSampleInterval(): number { 119fb726d48Sopenharmony_ci return this.sampleInterval; 120fb726d48Sopenharmony_ci } 121fb726d48Sopenharmony_ci 122fb726d48Sopenharmony_ci getGpuConfig(): {} { 123fb726d48Sopenharmony_ci let configVal = this.shadowRoot?.querySelectorAll<HTMLElement>('.config'); 124fb726d48Sopenharmony_ci let gpuConfig = {}; 125fb726d48Sopenharmony_ci for (let i = 0; i < configVal!.length; i++) { 126fb726d48Sopenharmony_ci let configName = configVal![i].getAttribute('configName'); 127fb726d48Sopenharmony_ci let type = configVal![i].getAttribute('type'); 128fb726d48Sopenharmony_ci if (type === 'enum') { 129fb726d48Sopenharmony_ci let enumValue = configVal![i].getAttribute('value'); 130fb726d48Sopenharmony_ci if (enumValue !== undefined && enumValue !== 'undefined') { 131fb726d48Sopenharmony_ci // @ts-ignore 132fb726d48Sopenharmony_ci gpuConfig[configName!] = enumValue; 133fb726d48Sopenharmony_ci } 134fb726d48Sopenharmony_ci } else if (type === 'number' || type === 'integer' || type === 'num') { 135fb726d48Sopenharmony_ci // @ts-ignore 136fb726d48Sopenharmony_ci gpuConfig[configName!] = Number(configVal![i].value); 137fb726d48Sopenharmony_ci } else if (type === 'boolean') { 138fb726d48Sopenharmony_ci let attribute = configVal![i].getAttribute('value'); 139fb726d48Sopenharmony_ci // @ts-ignore 140fb726d48Sopenharmony_ci gpuConfig[configName!] = attribute === 'true'; 141fb726d48Sopenharmony_ci } else { 142fb726d48Sopenharmony_ci // @ts-ignore 143fb726d48Sopenharmony_ci gpuConfig[configName!] = configVal![i].value; 144fb726d48Sopenharmony_ci } 145fb726d48Sopenharmony_ci } 146fb726d48Sopenharmony_ci return gpuConfig; 147fb726d48Sopenharmony_ci } 148fb726d48Sopenharmony_ci 149fb726d48Sopenharmony_ci private initSdkWasm(): void { 150fb726d48Sopenharmony_ci try { 151fb726d48Sopenharmony_ci let spApplication = document.querySelector<HTMLElement>('sp-application'); 152fb726d48Sopenharmony_ci let wasmJsonUrl = `https://${window.location.host.split(':')[0]}:${window.location.port}/application/wasm.json`; 153fb726d48Sopenharmony_ci if (spApplication!.hasAttribute('vs')) { 154fb726d48Sopenharmony_ci wasmJsonUrl = `http://${window.location.host.split(':')[0]}:${window.location.port}/wasm.json`; 155fb726d48Sopenharmony_ci } 156fb726d48Sopenharmony_ci fetch(wasmJsonUrl) 157fb726d48Sopenharmony_ci .then((res): void => { 158fb726d48Sopenharmony_ci if (res.ok) { 159fb726d48Sopenharmony_ci res.text().then((text) => { 160fb726d48Sopenharmony_ci this.wasmMap = new Map(); 161fb726d48Sopenharmony_ci this.wasmList = []; 162fb726d48Sopenharmony_ci let wasmJson = JSON.parse(text); 163fb726d48Sopenharmony_ci let wasmFiles = wasmJson.WasmFiles; 164fb726d48Sopenharmony_ci wasmFiles.forEach((wasmFile: unknown) => { 165fb726d48Sopenharmony_ci //@ts-ignore 166fb726d48Sopenharmony_ci this.wasmMap.set(wasmFile.disPlayName, wasmFile); 167fb726d48Sopenharmony_ci //@ts-ignore 168fb726d48Sopenharmony_ci this.wasmList.push(wasmFile.disPlayName); 169fb726d48Sopenharmony_ci }); 170fb726d48Sopenharmony_ci }); 171fb726d48Sopenharmony_ci } 172fb726d48Sopenharmony_ci }) 173fb726d48Sopenharmony_ci .catch(() => { }); 174fb726d48Sopenharmony_ci if (this.worker === null) { 175fb726d48Sopenharmony_ci // @ts-ignore 176fb726d48Sopenharmony_ci if (window.useWb) { 177fb726d48Sopenharmony_ci return; 178fb726d48Sopenharmony_ci } 179fb726d48Sopenharmony_ci this.worker = new Worker(new URL('../../database/ConfigWorker', import.meta.url)); 180fb726d48Sopenharmony_ci } 181fb726d48Sopenharmony_ci } catch (e) { } 182fb726d48Sopenharmony_ci } 183fb726d48Sopenharmony_ci 184fb726d48Sopenharmony_ci initElements(): void { 185fb726d48Sopenharmony_ci this.initSdkWasm(); 186fb726d48Sopenharmony_ci this.customConfig = this.shadowRoot?.querySelector<HTMLDivElement>('.configList'); 187fb726d48Sopenharmony_ci let switchButton = this.shadowRoot?.querySelector('.config_switch') as LitSwitch; 188fb726d48Sopenharmony_ci switchButton.addEventListener('change', (event: CustomEventInit<LitSwitchChangeEvent>) => { 189fb726d48Sopenharmony_ci let detail = event.detail; 190fb726d48Sopenharmony_ci if (detail!.checked) { 191fb726d48Sopenharmony_ci this.startSamp = true; 192fb726d48Sopenharmony_ci this.isAbleShowConfig(false); 193fb726d48Sopenharmony_ci } else { 194fb726d48Sopenharmony_ci this.startSamp = false; 195fb726d48Sopenharmony_ci this.isAbleShowConfig(true); 196fb726d48Sopenharmony_ci } 197fb726d48Sopenharmony_ci }); 198fb726d48Sopenharmony_ci this.selectConfig = this.shadowRoot?.querySelector<LitSelectV>('lit-select-v'); 199fb726d48Sopenharmony_ci let inputDiv = this.selectConfig?.shadowRoot?.querySelector('input') as HTMLDivElement; 200fb726d48Sopenharmony_ci inputDiv.addEventListener('mousedown', () => { 201fb726d48Sopenharmony_ci if (this.startSamp) { 202fb726d48Sopenharmony_ci inputDiv!.removeAttribute('readonly'); 203fb726d48Sopenharmony_ci this.selectConfig!.dataSource(this.wasmList, '', true); 204fb726d48Sopenharmony_ci } else { 205fb726d48Sopenharmony_ci inputDiv!.setAttribute('readonly', 'readonly'); 206fb726d48Sopenharmony_ci return; 207fb726d48Sopenharmony_ci } 208fb726d48Sopenharmony_ci }); 209fb726d48Sopenharmony_ci this.list = []; 210fb726d48Sopenharmony_ci this.list.push(this.selectConfig!); 211fb726d48Sopenharmony_ci this.isAbleShowConfig(true); 212fb726d48Sopenharmony_ci } 213fb726d48Sopenharmony_ci 214fb726d48Sopenharmony_ci private sdkConfigByBooleanType(key: string, sdkConfigSwitch: LitSwitch, sdkConfigHeadDiv: HTMLDivElement): void { 215fb726d48Sopenharmony_ci sdkConfigSwitch.className = 'switch1 config'; 216fb726d48Sopenharmony_ci sdkConfigSwitch.setAttribute('configName', key); 217fb726d48Sopenharmony_ci //@ts-ignore 218fb726d48Sopenharmony_ci sdkConfigSwitch.setAttribute('type', this.sdkConfigList.configuration[key].type); 219fb726d48Sopenharmony_ci //@ts-ignore 220fb726d48Sopenharmony_ci if (this.sdkConfigList.configuration[key].default === 'true') { 221fb726d48Sopenharmony_ci sdkConfigSwitch.setAttribute('checked', ''); 222fb726d48Sopenharmony_ci sdkConfigSwitch.setAttribute('value', 'true'); 223fb726d48Sopenharmony_ci } else { 224fb726d48Sopenharmony_ci sdkConfigSwitch.removeAttribute('checked'); 225fb726d48Sopenharmony_ci sdkConfigSwitch.setAttribute('value', 'false'); 226fb726d48Sopenharmony_ci } 227fb726d48Sopenharmony_ci sdkConfigHeadDiv.appendChild(sdkConfigSwitch); 228fb726d48Sopenharmony_ci this.list!.push(sdkConfigSwitch); 229fb726d48Sopenharmony_ci } 230fb726d48Sopenharmony_ci 231fb726d48Sopenharmony_ci private sdkConfigByIntegerType(key: string, sdkConfigDiv: HTMLDivElement, sdkConfigTitle: HTMLSpanElement): void { 232fb726d48Sopenharmony_ci let input = document.createElement('input'); 233fb726d48Sopenharmony_ci input.className = 'sdk-config-input config'; 234fb726d48Sopenharmony_ci //@ts-ignore 235fb726d48Sopenharmony_ci if (this.sdkConfigList.configuration[key].default) { 236fb726d48Sopenharmony_ci //@ts-ignore 237fb726d48Sopenharmony_ci input.value = this.sdkConfigList.configuration[key].default; 238fb726d48Sopenharmony_ci } 239fb726d48Sopenharmony_ci input.setAttribute('configName', key); 240fb726d48Sopenharmony_ci //@ts-ignore 241fb726d48Sopenharmony_ci input.setAttribute('type', this.sdkConfigList.configuration[key].type); 242fb726d48Sopenharmony_ci input.oninput = (): void => { 243fb726d48Sopenharmony_ci input.value = this.checkIntegerInput(input.value); 244fb726d48Sopenharmony_ci sdkConfigTitle.setAttribute('value', input.value); 245fb726d48Sopenharmony_ci }; 246fb726d48Sopenharmony_ci sdkConfigDiv.appendChild(input); 247fb726d48Sopenharmony_ci this.list!.push(input); 248fb726d48Sopenharmony_ci } 249fb726d48Sopenharmony_ci 250fb726d48Sopenharmony_ci private sdkConfigByNumberType(key: string, sdkConfigDiv: HTMLDivElement): void { 251fb726d48Sopenharmony_ci let numberInput = document.createElement('input'); 252fb726d48Sopenharmony_ci numberInput.className = 'sdk-config-input config'; 253fb726d48Sopenharmony_ci //@ts-ignore 254fb726d48Sopenharmony_ci if (this.sdkConfigList.configuration[key].default) { 255fb726d48Sopenharmony_ci //@ts-ignore 256fb726d48Sopenharmony_ci numberInput.value = this.sdkConfigList.configuration[key].default; 257fb726d48Sopenharmony_ci } 258fb726d48Sopenharmony_ci numberInput.setAttribute('configName', key); 259fb726d48Sopenharmony_ci numberInput.setAttribute('type', 'num'); 260fb726d48Sopenharmony_ci numberInput.oninput = (): void => { 261fb726d48Sopenharmony_ci numberInput.value = this.checkFloatInput(numberInput.value); 262fb726d48Sopenharmony_ci }; 263fb726d48Sopenharmony_ci sdkConfigDiv.appendChild(numberInput); 264fb726d48Sopenharmony_ci this.list!.push(numberInput); 265fb726d48Sopenharmony_ci } 266fb726d48Sopenharmony_ci 267fb726d48Sopenharmony_ci private sdkConfigByStringType(key: string, sdkConfigDiv: HTMLDivElement): void { 268fb726d48Sopenharmony_ci let html = ''; 269fb726d48Sopenharmony_ci //@ts-ignore 270fb726d48Sopenharmony_ci if (this.sdkConfigList.configuration[key].enum) { 271fb726d48Sopenharmony_ci let placeholder = ''; 272fb726d48Sopenharmony_ci //@ts-ignore 273fb726d48Sopenharmony_ci if (this.sdkConfigList.configuration[key].default) { 274fb726d48Sopenharmony_ci //@ts-ignore 275fb726d48Sopenharmony_ci placeholder = this.sdkConfigList.configuration[key].default; 276fb726d48Sopenharmony_ci } 277fb726d48Sopenharmony_ci //@ts-ignore 278fb726d48Sopenharmony_ci html += `<lit-select-v id="${key}" type="${this.sdkConfigList.configuration[key].type}" 279fb726d48Sopenharmony_cidefault-value="" rounded="" class="sdk-config-select config" mode="multiple" canInsert="" 280fb726d48Sopenharmony_cirounded placement = "bottom" configName ="${key}" placeholder="${placeholder}"></lit-select-v>`; 281fb726d48Sopenharmony_ci sdkConfigDiv.innerHTML = sdkConfigDiv.innerHTML + html; 282fb726d48Sopenharmony_ci } else { 283fb726d48Sopenharmony_ci let inputElement = document.createElement('input'); 284fb726d48Sopenharmony_ci inputElement.className = 'sdk-config-input config'; 285fb726d48Sopenharmony_ci //@ts-ignore 286fb726d48Sopenharmony_ci if (this.sdkConfigList.configuration[key].default) { 287fb726d48Sopenharmony_ci //@ts-ignore 288fb726d48Sopenharmony_ci inputElement.value = this.sdkConfigList.configuration[key].default; 289fb726d48Sopenharmony_ci } 290fb726d48Sopenharmony_ci inputElement.setAttribute('configName', key); 291fb726d48Sopenharmony_ci //@ts-ignore 292fb726d48Sopenharmony_ci inputElement.setAttribute('type', this.sdkConfigList.configuration[key].type); 293fb726d48Sopenharmony_ci sdkConfigDiv.appendChild(inputElement); 294fb726d48Sopenharmony_ci this.list!.push(inputElement); 295fb726d48Sopenharmony_ci } 296fb726d48Sopenharmony_ci } 297fb726d48Sopenharmony_ci 298fb726d48Sopenharmony_ci initConfig(): void { 299fb726d48Sopenharmony_ci this.customConfig!.innerHTML = ''; 300fb726d48Sopenharmony_ci this.list = []; 301fb726d48Sopenharmony_ci this.list.push(this.selectConfig!); 302fb726d48Sopenharmony_ci let sdkConfigSwitch = document.createElement('lit-switch') as LitSwitch; 303fb726d48Sopenharmony_ci //@ts-ignore 304fb726d48Sopenharmony_ci for (let key in this.sdkConfigList.configuration) { 305fb726d48Sopenharmony_ci let sdkConfigDiv = document.createElement('div'); 306fb726d48Sopenharmony_ci sdkConfigDiv.className = 'sdk-config-div'; 307fb726d48Sopenharmony_ci let sdkConfigHeadDiv = document.createElement('div'); 308fb726d48Sopenharmony_ci sdkConfigDiv.appendChild(sdkConfigHeadDiv); 309fb726d48Sopenharmony_ci let sdkConfigTitle = document.createElement('span'); 310fb726d48Sopenharmony_ci sdkConfigTitle.className = 'sdk-config-title'; 311fb726d48Sopenharmony_ci sdkConfigTitle.textContent = key; 312fb726d48Sopenharmony_ci sdkConfigHeadDiv.appendChild(sdkConfigTitle); 313fb726d48Sopenharmony_ci let sdkConfigDes = document.createElement('span'); 314fb726d48Sopenharmony_ci //@ts-ignore 315fb726d48Sopenharmony_ci sdkConfigDes.textContent = this.sdkConfigList.configuration[key].description; 316fb726d48Sopenharmony_ci sdkConfigDes.className = 'sdk-config-des'; 317fb726d48Sopenharmony_ci sdkConfigHeadDiv.appendChild(sdkConfigDes); 318fb726d48Sopenharmony_ci //@ts-ignore 319fb726d48Sopenharmony_ci switch (this.sdkConfigList.configuration[key].type) { 320fb726d48Sopenharmony_ci case 'string': 321fb726d48Sopenharmony_ci this.sdkConfigByStringType(key, sdkConfigDiv); 322fb726d48Sopenharmony_ci break; 323fb726d48Sopenharmony_ci case 'number': 324fb726d48Sopenharmony_ci this.sdkConfigByNumberType(key, sdkConfigDiv); 325fb726d48Sopenharmony_ci break; 326fb726d48Sopenharmony_ci case 'integer': 327fb726d48Sopenharmony_ci this.sdkConfigByIntegerType(key, sdkConfigDiv, sdkConfigTitle); 328fb726d48Sopenharmony_ci break; 329fb726d48Sopenharmony_ci case 'boolean': 330fb726d48Sopenharmony_ci this.sdkConfigByBooleanType(key, sdkConfigSwitch, sdkConfigHeadDiv); 331fb726d48Sopenharmony_ci break; 332fb726d48Sopenharmony_ci } 333fb726d48Sopenharmony_ci this.customConfig!.appendChild(sdkConfigDiv); 334fb726d48Sopenharmony_ci //@ts-ignore 335fb726d48Sopenharmony_ci if (this.sdkConfigList.configuration[key].enum) { 336fb726d48Sopenharmony_ci let select = this.shadowRoot!.querySelector<LitSelectV>(`#${key}`); 337fb726d48Sopenharmony_ci select!.setAttribute('type', 'enum'); 338fb726d48Sopenharmony_ci //@ts-ignore 339fb726d48Sopenharmony_ci select!.setAttribute('value', this.sdkConfigList.configuration.key.default); 340fb726d48Sopenharmony_ci //@ts-ignore 341fb726d48Sopenharmony_ci select!.dataSource(this.sdkConfigList.configuration.key.enum, ''); 342fb726d48Sopenharmony_ci this.list.push(select!); 343fb726d48Sopenharmony_ci select!.addEventListener('click', () => { 344fb726d48Sopenharmony_ci select!.setAttribute('value', select!.value); 345fb726d48Sopenharmony_ci }); 346fb726d48Sopenharmony_ci } 347fb726d48Sopenharmony_ci } 348fb726d48Sopenharmony_ci sdkConfigSwitch.addEventListener('change', () => { 349fb726d48Sopenharmony_ci sdkConfigSwitch.setAttribute('value', `${sdkConfigSwitch.hasAttribute('checked')}`); 350fb726d48Sopenharmony_ci }); 351fb726d48Sopenharmony_ci } 352fb726d48Sopenharmony_ci 353fb726d48Sopenharmony_ci checkIntegerInput(value: string): string { 354fb726d48Sopenharmony_ci let inputValue = value 355fb726d48Sopenharmony_ci .replace(/[^\-\d]|\-{2,}/g, '') 356fb726d48Sopenharmony_ci .replace(/(\d)\-|-(0+)|^0+(\d)/g, '$1') 357fb726d48Sopenharmony_ci .replace(/(-?\d{15})\d*/, '$1'); 358fb726d48Sopenharmony_ci return inputValue; 359fb726d48Sopenharmony_ci } 360fb726d48Sopenharmony_ci 361fb726d48Sopenharmony_ci checkFloatInput(value: string): string { 362fb726d48Sopenharmony_ci let inputValue = value 363fb726d48Sopenharmony_ci .replace(/[^\d.]/g, '') 364fb726d48Sopenharmony_ci .replace(/^\.|^0+(\d)/g, '') 365fb726d48Sopenharmony_ci .replace(/(\.\d+)\.|(-)\.|(\d+|\.)-/g, '$1') 366fb726d48Sopenharmony_ci .replace(/(-?\d{9})\d*/, '$1'); 367fb726d48Sopenharmony_ci return inputValue.replace(/\.{2,}|-(0){2,}|(-)0+(\d+)/g, '.'); 368fb726d48Sopenharmony_ci } 369fb726d48Sopenharmony_ci 370fb726d48Sopenharmony_ci isAbleShowConfig(isAbleShow: boolean): void { 371fb726d48Sopenharmony_ci if (this.list!) { 372fb726d48Sopenharmony_ci if (isAbleShow) { 373fb726d48Sopenharmony_ci this.list!.forEach((item) => { 374fb726d48Sopenharmony_ci item.setAttribute('disabled', ''); 375fb726d48Sopenharmony_ci }); 376fb726d48Sopenharmony_ci } else { 377fb726d48Sopenharmony_ci this.list!.forEach((item) => { 378fb726d48Sopenharmony_ci item.removeAttribute('disabled'); 379fb726d48Sopenharmony_ci }); 380fb726d48Sopenharmony_ci } 381fb726d48Sopenharmony_ci } 382fb726d48Sopenharmony_ci } 383fb726d48Sopenharmony_ci 384fb726d48Sopenharmony_ci initHtml(): string { 385fb726d48Sopenharmony_ci return SpSdkConfigHtml; 386fb726d48Sopenharmony_ci } 387fb726d48Sopenharmony_ci} 388