1/*
2 * Copyright (c) 2023 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
16class CanvasInput {
17  static FOCUS = false;
18  static SAFE_AREA = [];
19  static SetSafeArea(x, y, w, h) {
20    CanvasInput.SAFE_AREA = [x, y, w, h];
21  }
22  static Reset(x, y, w, h, value, cb, cb2, cb3) {
23    CanvasInput.SAFE_AREA = [x, y, w, h];
24    let ci = document.getElementById('canvas_textarea');
25    ci.style.left = x + 'px';
26    ci.style.top = y + 'px';
27    ci.style.width = w + 'px';
28    ci.style.height = h + 'px';
29    ci.style.display = 'block';
30    ci.value = value;
31    ci.onchange = (e) => {
32      if (cb) {
33        cb(e.target.value);
34      }
35    };
36    ci.oninput = (e) => {
37      if (cb2) {
38        cb2(e.target.value);
39      }
40    };
41    ci.focus();
42
43    ci.addEventListener('keydown', (e) => {
44      if (e.key === 'Enter') {
45        console.log(e);
46        e.preventDefault();
47        if (cb3) {
48          cb3();
49        }
50      }
51    });
52    CanvasInput.FOCUS = true;
53  }
54  static HideEx() {
55    let ci = document.getElementById('canvas_textarea');
56    ci.style.display = 'none';
57    CanvasInput.FOCUS = false;
58  }
59}
60
61module.exports = {
62  CanvasInput,
63};
64