copy_tuner_client 2.0.0 → 2.1.1

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.
data/src/specimen.ts DELETED
@@ -1,94 +0,0 @@
1
- import { computeBoundingBox } from './util'
2
-
3
- const ZINDEX = 2_000_000_000
4
-
5
- export default class Specimen {
6
- // @ts-expect-error TS7006
7
- constructor(element, keys, callback) {
8
- // @ts-expect-error TS2339
9
- this.element = element
10
- // @ts-expect-error TS2339
11
- this.keys = keys
12
- // @ts-expect-error TS2339
13
- this.callback = callback
14
- }
15
-
16
- show() {
17
- // @ts-expect-error TS2339
18
- this.box = this.makeBox()
19
- // @ts-expect-error TS2339
20
- if (this.box === null) return
21
-
22
- // box 全体のクリックは先頭キーを開く(広いクリック領域を維持)。複数キー時は各ラベルから個別に開ける
23
- // @ts-expect-error TS2339
24
- this.box.addEventListener('click', () => {
25
- // @ts-expect-error TS2339
26
- this.callback(this.keys[0])
27
- })
28
-
29
- // @ts-expect-error TS2339
30
- document.body.append(this.box)
31
- }
32
-
33
- remove() {
34
- // @ts-expect-error TS2339
35
- if (!this.box) {
36
- return
37
- }
38
- // @ts-expect-error TS2339
39
- this.box.remove()
40
- // @ts-expect-error TS2339
41
- this.box = null
42
- }
43
-
44
- makeBox() {
45
- const box = document.createElement('div')
46
- box.classList.add('copyray-specimen')
47
- box.classList.add('Specimen')
48
-
49
- // @ts-expect-error TS2339
50
- const bounds = computeBoundingBox(this.element)
51
- if (bounds === null) return null
52
-
53
- for (const key of Object.keys(bounds)) {
54
- // @ts-expect-error TS7053
55
- const value = bounds[key]
56
- // @ts-expect-error TS7015
57
- box.style[key] = `${value}px`
58
- }
59
- // @ts-expect-error TS2322
60
- box.style.zIndex = ZINDEX
61
-
62
- // @ts-expect-error TS2339
63
- const { position, top, left } = getComputedStyle(this.element)
64
- if (position === 'fixed') {
65
- // @ts-expect-error TS2339
66
- this.box.style.position = 'fixed'
67
- // @ts-expect-error TS2339
68
- this.box.style.top = `${top}px`
69
- // @ts-expect-error TS2339
70
- this.box.style.left = `${left}px`
71
- }
72
-
73
- // @ts-expect-error TS2339
74
- for (const key of this.keys) {
75
- box.append(this.makeLabel(key))
76
- }
77
- return box
78
- }
79
-
80
- // @ts-expect-error TS7006
81
- makeLabel(key) {
82
- const div = document.createElement('div')
83
- div.classList.add('copyray-specimen-handle')
84
- div.classList.add('Specimen')
85
- div.textContent = key
86
- // ラベルのクリックはそのキーを開く。box への伝播を止めて先頭キーとの二重発火を防ぐ
87
- div.addEventListener('click', (event) => {
88
- event.stopPropagation()
89
- // @ts-expect-error TS2339
90
- this.callback(key)
91
- })
92
- return div
93
- }
94
- }