1 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6 | };
|
7 | var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11 | };
|
12 | var _DuoyunInputCaptureElement_onClear, _DuoyunInputCaptureElement_onKeydown, _DuoyunInputCaptureElement_onPointerdown, _DuoyunInputCaptureElement_onPointermove, _DuoyunInputCaptureElement_onPointerup;
|
13 | var DuoyunInputCaptureElement_1;
|
14 | import { adoptedStyle, customElement, part } from '@mantou/gem/lib/decorators';
|
15 | import { GemElement, html } from '@mantou/gem/lib/element';
|
16 | import { createCSSSheet, css } from '@mantou/gem/lib/utils';
|
17 | import { theme } from '../lib/theme';
|
18 | import { getDisplayKey } from '../lib/hotkeys';
|
19 | import { throttle } from '../lib/utils';
|
20 | import './paragraph';
|
21 | const style = createCSSSheet(css `
|
22 | :host(:where(:not([hidden]))) {
|
23 | display: contents;
|
24 | }
|
25 | .container,
|
26 | .circle {
|
27 | position: fixed;
|
28 | z-index: calc(${theme.popupZIndex} + 3);
|
29 | pointer-events: none;
|
30 | }
|
31 | .container {
|
32 | font-size: 4em;
|
33 | left: 0;
|
34 | right: 0;
|
35 | bottom: 2em;
|
36 | text-align: center;
|
37 | white-space: nowrap;
|
38 | background: rgba(0, 0, 0, calc(${theme.maskAlpha} + 0.4));
|
39 | }
|
40 | .kbd {
|
41 | background: transparent;
|
42 | color: white;
|
43 | }
|
44 | .circle {
|
45 | border: 2px solid red;
|
46 | border-radius: 10em;
|
47 | width: 2.5em;
|
48 | aspect-ratio: 1;
|
49 | transform: translate(-50%, -50%);
|
50 | }
|
51 | `);
|
52 |
|
53 |
|
54 |
|
55 | let DuoyunInputCaptureElement = DuoyunInputCaptureElement_1 = class DuoyunInputCaptureElement extends GemElement {
|
56 | constructor() {
|
57 | super(...arguments);
|
58 | this.state = {
|
59 | keys: [],
|
60 | mousePosition: null,
|
61 | };
|
62 | _DuoyunInputCaptureElement_onClear.set(this, throttle(() => {
|
63 | this.setState({ keys: [] });
|
64 | }, 1000));
|
65 | _DuoyunInputCaptureElement_onKeydown.set(this, (evt) => {
|
66 | this.setState({ keys: [...this.state.keys.slice(-5), getDisplayKey(evt.code)] });
|
67 | __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onClear, "f").call(this);
|
68 | });
|
69 | _DuoyunInputCaptureElement_onPointerdown.set(this, (evt) => this.setState({ mousePosition: [evt.clientX, evt.clientY] }));
|
70 | _DuoyunInputCaptureElement_onPointermove.set(this, (evt) => this.state.mousePosition && __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointerdown, "f").call(this, evt));
|
71 | _DuoyunInputCaptureElement_onPointerup.set(this, () => this.setState({ mousePosition: null }));
|
72 | this.mounted = () => {
|
73 | addEventListener('keydown', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onKeydown, "f"), { capture: true });
|
74 | addEventListener('pointerdown', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointerdown, "f"), { capture: true });
|
75 | addEventListener('pointermove', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointermove, "f"), { capture: true });
|
76 | addEventListener('pointerup', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointerup, "f"), { capture: true });
|
77 | addEventListener('pointercancel', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointerup, "f"), { capture: true });
|
78 | () => {
|
79 | removeEventListener('keydown', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onKeydown, "f"), { capture: true });
|
80 | removeEventListener('pointerdown', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointerdown, "f"), { capture: true });
|
81 | removeEventListener('pointermove', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointermove, "f"), { capture: true });
|
82 | removeEventListener('pointerup', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointerup, "f"), { capture: true });
|
83 | removeEventListener('pointercancel', __classPrivateFieldGet(this, _DuoyunInputCaptureElement_onPointerup, "f"), { capture: true });
|
84 | };
|
85 | };
|
86 | this.render = () => {
|
87 | const { keys, mousePosition } = this.state;
|
88 | return html `
|
89 | ${keys.length
|
90 | ? html `
|
91 | <dy-paragraph part=${DuoyunInputCaptureElement_1.container} class="container">
|
92 | ${keys.map((key) => html `<kbd part=${DuoyunInputCaptureElement_1.kbd} class="kbd">${key}</kbd>`)}
|
93 | </dy-paragraph>
|
94 | `
|
95 | : ''}
|
96 | ${mousePosition
|
97 | ? html `
|
98 | <div class="circle">
|
99 | <style>
|
100 | .circle {
|
101 | left: ${mousePosition[0]}px;
|
102 | top: ${mousePosition[1]}px;
|
103 | }
|
104 | </style>
|
105 | </div>
|
106 | `
|
107 | : ''}
|
108 | `;
|
109 | };
|
110 | }
|
111 | };
|
112 | _DuoyunInputCaptureElement_onClear = new WeakMap(), _DuoyunInputCaptureElement_onKeydown = new WeakMap(), _DuoyunInputCaptureElement_onPointerdown = new WeakMap(), _DuoyunInputCaptureElement_onPointermove = new WeakMap(), _DuoyunInputCaptureElement_onPointerup = new WeakMap();
|
113 | __decorate([
|
114 | part
|
115 | ], DuoyunInputCaptureElement, "container", void 0);
|
116 | __decorate([
|
117 | part
|
118 | ], DuoyunInputCaptureElement, "kbd", void 0);
|
119 | DuoyunInputCaptureElement = DuoyunInputCaptureElement_1 = __decorate([
|
120 | customElement('dy-input-capture'),
|
121 | adoptedStyle(style)
|
122 | ], DuoyunInputCaptureElement);
|
123 | export { DuoyunInputCaptureElement };
|
124 |
|
\ | No newline at end of file |