@celestia-island/hikari 0.55.401 → 0.55.402
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.
- package/package.json +1 -1
- package/src/components/HkRemoteInputDock.barrel.test.ts +29 -0
- package/src/components/HkRemoteInputDock.scss +125 -0
- package/src/components/HkRemoteInputDock.test.tsx +271 -0
- package/src/components/HkRemoteInputDock.tsx +252 -0
- package/src/components/HkVirtualCursor.scss +93 -0
- package/src/components/HkVirtualCursor.test.tsx +146 -0
- package/src/components/HkVirtualCursor.tsx +133 -0
- package/src/components/remoteInputTypes.test.ts +47 -0
- package/src/components/remoteInputTypes.ts +95 -0
- package/src/composables/useOrientationLock.test.ts +39 -0
- package/src/composables/useOrientationLock.ts +39 -0
- package/src/composables/useRemoteTouchGestures.test.ts +180 -0
- package/src/composables/useRemoteTouchGestures.ts +251 -0
- package/src/composables/useVirtualPointer.test.ts +128 -0
- package/src/composables/useVirtualPointer.ts +151 -0
- package/src/i18n/locales/ar/components.json +58 -47
- package/src/i18n/locales/de/components.json +58 -47
- package/src/i18n/locales/en/components.json +58 -47
- package/src/i18n/locales/es/components.json +58 -47
- package/src/i18n/locales/fr/components.json +58 -47
- package/src/i18n/locales/ja/components.json +58 -47
- package/src/i18n/locales/ko/components.json +58 -47
- package/src/i18n/locales/pt/components.json +58 -47
- package/src/i18n/locales/ru/components.json +58 -47
- package/src/i18n/locales/zh-Hans/components.json +62 -51
- package/src/i18n/locales/zh-Hant/components.json +62 -51
- package/src/i18n/usageSurface.test.ts +4 -0
- package/src/index.ts +25 -0
package/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as barrel from "../index";
|
|
3
|
+
import { asIndexable } from "../utils/typing";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The public barrel guard (HkAdaptiveTabs.barrel.test.ts shape): the
|
|
7
|
+
* component's own tests reach it through "./HkRemoteInputDock" — only
|
|
8
|
+
* an external consumer would notice a dropped export line.
|
|
9
|
+
*/
|
|
10
|
+
describe("the public barrel", () => {
|
|
11
|
+
it("exports the remote-input components under both family names", () => {
|
|
12
|
+
const dock = asIndexable(barrel.HkRemoteInputDock);
|
|
13
|
+
expect(dock, "HkRemoteInputDock must be re-exported").toBeTruthy();
|
|
14
|
+
expect(dock.name).toBe("HkRemoteInputDock");
|
|
15
|
+
expect(barrel.HRemoteInputDock).toBe(barrel.HkRemoteInputDock);
|
|
16
|
+
|
|
17
|
+
const cursor = asIndexable(barrel.HkVirtualCursor);
|
|
18
|
+
expect(cursor, "HkVirtualCursor must be re-exported").toBeTruthy();
|
|
19
|
+
expect(cursor.name).toBe("HkVirtualCursor");
|
|
20
|
+
expect(barrel.HVirtualCursor).toBe(barrel.HkVirtualCursor);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("exports the composables and the mask vocabulary", () => {
|
|
24
|
+
expect(typeof barrel.useVirtualPointer).toBe("function");
|
|
25
|
+
expect(typeof barrel.useRemoteTouchGestures).toBe("function");
|
|
26
|
+
expect(typeof barrel.useOrientationLock).toBe("function");
|
|
27
|
+
expect([barrel.MASK_LEFT, barrel.MASK_MIDDLE, barrel.MASK_RIGHT]).toEqual([1, 2, 4]);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/* HkRemoteInputDock — the remote-control dial.
|
|
2
|
+
*
|
|
3
|
+
* A fixed-corner dial button that expands into the control card. The
|
|
4
|
+
* card speaks the panel grammar (sheet surface, fine radius) so it
|
|
5
|
+
* reads as a floating panel, not a popup menu. */
|
|
6
|
+
|
|
7
|
+
@use "../styles/polyfill" as *;
|
|
8
|
+
|
|
9
|
+
.hk-remote-input-dock {
|
|
10
|
+
position: absolute;
|
|
11
|
+
/* The dock-gap law (#1340): every dock's edge gap reads the shared
|
|
12
|
+
* override chain, never a private constant. */
|
|
13
|
+
right: var(--hk-dock-gap-right, var(--hk-dock-inset, var(--hk-dock-gap, var(--space-16, 1rem))));
|
|
14
|
+
bottom: var(--hk-dock-gap-bottom, var(--hk-dock-inset, var(--hk-dock-gap, var(--space-16, 1rem))));
|
|
15
|
+
z-index: 3; /* above the session surface + virtual cursor */
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
align-items: flex-end;
|
|
19
|
+
gap: 0.5rem;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.hk-remote-input-dock__dial {
|
|
23
|
+
width: 44px;
|
|
24
|
+
height: 44px;
|
|
25
|
+
border-radius: 999px;
|
|
26
|
+
border: 1px solid rgb(var(--color-border));
|
|
27
|
+
background: rgb(var(--color-background) / 92%);
|
|
28
|
+
color: rgb(var(--color-text));
|
|
29
|
+
display: grid;
|
|
30
|
+
place-items: center;
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
box-shadow: 0 4px 14px rgb(0 0 0 / 30%);
|
|
33
|
+
@include backdrop-filter(blur(6px));
|
|
34
|
+
|
|
35
|
+
&[data-open] {
|
|
36
|
+
background: rgb(var(--color-primary) / 90%);
|
|
37
|
+
color: rgb(var(--color-on-primary, 255 255 255));
|
|
38
|
+
border-color: rgb(var(--color-primary));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&:focus-visible {
|
|
42
|
+
outline: 2px solid rgb(var(--color-primary) / 70%);
|
|
43
|
+
outline-offset: 2px;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.hk-remote-input-dock__card {
|
|
48
|
+
width: 13rem;
|
|
49
|
+
padding: 0.6rem;
|
|
50
|
+
border-radius: var(--radius-md, 10px);
|
|
51
|
+
border: 1px solid rgb(var(--color-border));
|
|
52
|
+
background: rgb(var(--color-background) / 96%);
|
|
53
|
+
box-shadow: 0 8px 24px rgb(0 0 0 / 35%);
|
|
54
|
+
@include backdrop-filter(blur(8px));
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-direction: column;
|
|
57
|
+
gap: 0.5rem;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.hk-remote-input-dock__modes {
|
|
61
|
+
display: grid;
|
|
62
|
+
grid-template-columns: 1fr 1fr;
|
|
63
|
+
gap: 0.35rem;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.hk-remote-input-dock__mode {
|
|
67
|
+
padding: 0.35rem 0.4rem;
|
|
68
|
+
border-radius: var(--radius-sm, 6px);
|
|
69
|
+
border: 1px solid rgb(var(--color-border));
|
|
70
|
+
background: transparent;
|
|
71
|
+
color: rgb(var(--color-text));
|
|
72
|
+
font-size: 0.78rem;
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
|
|
75
|
+
&[data-active] {
|
|
76
|
+
background: rgb(var(--color-primary) / 14%);
|
|
77
|
+
border-color: rgb(var(--color-primary) / 60%);
|
|
78
|
+
color: rgb(var(--color-primary));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&:focus-visible {
|
|
82
|
+
outline: 2px solid rgb(var(--color-primary) / 70%);
|
|
83
|
+
outline-offset: 1px;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.hk-remote-input-dock__pad {
|
|
88
|
+
display: grid;
|
|
89
|
+
grid-template-columns: repeat(5, 1fr);
|
|
90
|
+
gap: 0.3rem;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.hk-remote-input-dock__btn {
|
|
94
|
+
height: 2rem;
|
|
95
|
+
border-radius: var(--radius-sm, 6px);
|
|
96
|
+
border: 1px solid rgb(var(--color-border));
|
|
97
|
+
background: rgb(var(--color-surface, var(--color-background)));
|
|
98
|
+
color: rgb(var(--color-text));
|
|
99
|
+
font-size: 0.8rem;
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
touch-action: none;
|
|
102
|
+
@include user-select(none);
|
|
103
|
+
|
|
104
|
+
&:active:not(:disabled) {
|
|
105
|
+
background: rgb(var(--color-primary) / 22%);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&:disabled {
|
|
109
|
+
opacity: 0.45;
|
|
110
|
+
cursor: default;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
&:focus-visible {
|
|
114
|
+
outline: 2px solid rgb(var(--color-primary) / 70%);
|
|
115
|
+
outline-offset: 1px;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.hk-remote-input-dock__host {
|
|
120
|
+
display: flex;
|
|
121
|
+
flex-wrap: wrap;
|
|
122
|
+
gap: 0.35rem;
|
|
123
|
+
padding-top: 0.35rem;
|
|
124
|
+
border-top: 1px solid rgb(var(--color-border) / 60%);
|
|
125
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vitest } from "vitest";
|
|
2
|
+
import { createApp, defineComponent, h, nextTick, ref } from "vue";
|
|
3
|
+
|
|
4
|
+
import HkRemoteInputDock from "./HkRemoteInputDock";
|
|
5
|
+
|
|
6
|
+
const mounts: ReturnType<typeof createApp>[] = [];
|
|
7
|
+
const containers: HTMLElement[] = [];
|
|
8
|
+
|
|
9
|
+
interface Mounted {
|
|
10
|
+
container: HTMLElement;
|
|
11
|
+
dial: HTMLButtonElement;
|
|
12
|
+
modes: () => HTMLButtonElement[];
|
|
13
|
+
btns: () => HTMLButtonElement[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Mount a dock through a wrapper app (the HkFab.test.tsx pattern). */
|
|
17
|
+
function mountDock(props: Record<string, unknown> = {}, slot?: () => ReturnType<typeof h>): Mounted {
|
|
18
|
+
const container = document.createElement("div");
|
|
19
|
+
document.body.appendChild(container);
|
|
20
|
+
containers.push(container);
|
|
21
|
+
|
|
22
|
+
const Wrapper = defineComponent({
|
|
23
|
+
setup() {
|
|
24
|
+
return () =>
|
|
25
|
+
h(HkRemoteInputDock, props, slot ? { default: slot } : undefined);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const app = createApp(Wrapper);
|
|
29
|
+
mounts.push(app);
|
|
30
|
+
app.mount(container);
|
|
31
|
+
|
|
32
|
+
const dial = container.querySelector<HTMLButtonElement>(".hk-remote-input-dock__dial");
|
|
33
|
+
if (!dial) throw new Error("dock did not render its dial");
|
|
34
|
+
return {
|
|
35
|
+
container,
|
|
36
|
+
dial,
|
|
37
|
+
modes: () => [...container.querySelectorAll<HTMLButtonElement>(".hk-remote-input-dock__mode")],
|
|
38
|
+
btns: () => [...container.querySelectorAll<HTMLButtonElement>(".hk-remote-input-dock__btn")],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
while (mounts.length) mounts.pop()?.unmount();
|
|
44
|
+
while (containers.length) containers.pop()?.remove();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("HkRemoteInputDock", () => {
|
|
48
|
+
it("hidden prop renders nothing", () => {
|
|
49
|
+
const container = document.createElement("div");
|
|
50
|
+
document.body.appendChild(container);
|
|
51
|
+
containers.push(container);
|
|
52
|
+
const app = createApp({ render: () => h(HkRemoteInputDock, { hidden: true }) });
|
|
53
|
+
mounts.push(app);
|
|
54
|
+
app.mount(container);
|
|
55
|
+
expect(container.querySelector(".hk-remote-input-dock")).toBeNull();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("the dial expands the card; the mode radios drive update:mode", async () => {
|
|
59
|
+
const seen: string[] = [];
|
|
60
|
+
const m = mountDock({ mode: "direct", "onUpdate:mode": (v: string) => seen.push(v) });
|
|
61
|
+
expect(m.container.querySelector(".hk-remote-input-dock__card")).toBeNull();
|
|
62
|
+
m.dial.click();
|
|
63
|
+
await nextTick();
|
|
64
|
+
expect(m.container.querySelector(".hk-remote-input-dock__card")).not.toBeNull();
|
|
65
|
+
const radios = m.modes();
|
|
66
|
+
expect(radios[0]!.getAttribute("aria-checked")).toBe("true");
|
|
67
|
+
expect(radios[1]!.getAttribute("aria-checked")).toBe("false");
|
|
68
|
+
radios[1]!.click();
|
|
69
|
+
await nextTick();
|
|
70
|
+
expect(seen).toEqual(["virtual"]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("pad hold-buttons drive the actions with an absolute held mask", async () => {
|
|
74
|
+
const actions = { setButtons: vitest.fn(), wheel: vitest.fn() };
|
|
75
|
+
const m = mountDock({ mode: "virtual", actions });
|
|
76
|
+
m.dial.click();
|
|
77
|
+
await nextTick();
|
|
78
|
+
const btns = m.btns();
|
|
79
|
+
// [left, middle, right, wheelUp, wheelDown]
|
|
80
|
+
btns[0]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
81
|
+
expect(actions.setButtons).toHaveBeenLastCalledWith(0b001);
|
|
82
|
+
btns[2]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
83
|
+
expect(actions.setButtons).toHaveBeenLastCalledWith(0b101);
|
|
84
|
+
btns[0]!.dispatchEvent(new Event("pointerup", { bubbles: true }));
|
|
85
|
+
expect(actions.setButtons).toHaveBeenLastCalledWith(0b100);
|
|
86
|
+
// An unheld pad's pointerleave must not fire a phantom release.
|
|
87
|
+
actions.setButtons.mockClear();
|
|
88
|
+
btns[1]!.dispatchEvent(new Event("pointerleave", { bubbles: true }));
|
|
89
|
+
expect(actions.setButtons).not.toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("wheel taps ride the actions; without actions the pad disables", async () => {
|
|
93
|
+
const actions = { setButtons: vitest.fn(), wheel: vitest.fn() };
|
|
94
|
+
const m = mountDock({ actions });
|
|
95
|
+
m.dial.click();
|
|
96
|
+
await nextTick();
|
|
97
|
+
const btns = m.btns();
|
|
98
|
+
btns[3]!.click();
|
|
99
|
+
btns[4]!.click();
|
|
100
|
+
expect(actions.wheel.mock.calls).toEqual([[1], [-1]]);
|
|
101
|
+
|
|
102
|
+
while (mounts.length) mounts.pop()?.unmount();
|
|
103
|
+
while (containers.length) containers.pop()?.remove();
|
|
104
|
+
const bare = mountDock();
|
|
105
|
+
bare.dial.click();
|
|
106
|
+
await nextTick();
|
|
107
|
+
expect(bare.btns()[0]!.disabled).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("outside pointerdown and Escape close the card", async () => {
|
|
111
|
+
const m = mountDock();
|
|
112
|
+
m.dial.click();
|
|
113
|
+
await nextTick();
|
|
114
|
+
expect(m.container.querySelector(".hk-remote-input-dock__card")).not.toBeNull();
|
|
115
|
+
document.dispatchEvent(
|
|
116
|
+
new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }),
|
|
117
|
+
);
|
|
118
|
+
await nextTick();
|
|
119
|
+
expect(m.container.querySelector(".hk-remote-input-dock__card")).toBeNull();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("a HELD pad keeps the card open across outside touches", async () => {
|
|
123
|
+
const actions = { setButtons: vitest.fn(), wheel: vitest.fn() };
|
|
124
|
+
const m = mountDock({ actions });
|
|
125
|
+
m.dial.click();
|
|
126
|
+
await nextTick();
|
|
127
|
+
const btns = m.btns();
|
|
128
|
+
btns[0]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
129
|
+
// A touch on the canvas (outside the dock) while the pad is held:
|
|
130
|
+
// the card must stay open — the held button is still in use.
|
|
131
|
+
document.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
132
|
+
await nextTick();
|
|
133
|
+
expect(m.container.querySelector(".hk-remote-input-dock__card")).not.toBeNull();
|
|
134
|
+
// Releasing the pad: an outside touch now closes.
|
|
135
|
+
btns[0]!.dispatchEvent(new Event("pointerup", { bubbles: true }));
|
|
136
|
+
document.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
137
|
+
await nextTick();
|
|
138
|
+
expect(m.container.querySelector(".hk-remote-input-dock__card")).toBeNull();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("every card-unmount path force-releases held bits", async () => {
|
|
142
|
+
// (a) Escape closes → release
|
|
143
|
+
const a = { setButtons: vitest.fn(), wheel: vitest.fn() };
|
|
144
|
+
const ma = mountDock({ actions: a });
|
|
145
|
+
ma.dial.click();
|
|
146
|
+
await nextTick();
|
|
147
|
+
ma.btns()[2]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
148
|
+
document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }));
|
|
149
|
+
await nextTick();
|
|
150
|
+
expect(a.setButtons).toHaveBeenLastCalledWith(0);
|
|
151
|
+
|
|
152
|
+
// (b) hidden while open → release
|
|
153
|
+
const b = { setButtons: vitest.fn(), wheel: vitest.fn() };
|
|
154
|
+
const container = document.createElement("div");
|
|
155
|
+
document.body.appendChild(container);
|
|
156
|
+
containers.push(container);
|
|
157
|
+
const app = createApp({
|
|
158
|
+
setup() {
|
|
159
|
+
const hidden = ref(false);
|
|
160
|
+
return () => [
|
|
161
|
+
h(HkRemoteInputDock, { actions: b, hidden: hidden.value }),
|
|
162
|
+
h("button", { class: "flip", onClick: () => { hidden.value = true; } }, "flip"),
|
|
163
|
+
];
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
mounts.push(app);
|
|
167
|
+
app.mount(container);
|
|
168
|
+
(container.querySelector<HTMLButtonElement>(".hk-remote-input-dock__dial"))!.click();
|
|
169
|
+
await nextTick();
|
|
170
|
+
const padBtns = [...container.querySelectorAll<HTMLButtonElement>(".hk-remote-input-dock__btn")];
|
|
171
|
+
padBtns[0]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
172
|
+
expect(b.setButtons).toHaveBeenLastCalledWith(0b001);
|
|
173
|
+
(container.querySelector<HTMLButtonElement>(".flip"))!.click();
|
|
174
|
+
await nextTick();
|
|
175
|
+
expect(container.querySelector(".hk-remote-input-dock")).toBeNull();
|
|
176
|
+
expect(b.setButtons).toHaveBeenLastCalledWith(0); // hidden force-releases
|
|
177
|
+
// A hidden dock swallows no Escape: the listener stood down.
|
|
178
|
+
const esc = new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true });
|
|
179
|
+
document.dispatchEvent(esc);
|
|
180
|
+
expect(esc.defaultPrevented).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("component UNMOUNT releases a held pad (the third teardown path)", async () => {
|
|
184
|
+
const actions = { setButtons: vitest.fn(), wheel: vitest.fn() };
|
|
185
|
+
const m = mountDock({ actions });
|
|
186
|
+
m.dial.click();
|
|
187
|
+
await nextTick();
|
|
188
|
+
m.btns()[1]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
189
|
+
expect(actions.setButtons).toHaveBeenLastCalledWith(0b010);
|
|
190
|
+
while (mounts.length) mounts.pop()?.unmount();
|
|
191
|
+
expect(actions.setButtons).toHaveBeenLastCalledWith(0);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("actions vanishing mid-hold clears the strand locally", async () => {
|
|
195
|
+
const actions = { setButtons: vitest.fn(), wheel: vitest.fn() };
|
|
196
|
+
const container = document.createElement("div");
|
|
197
|
+
document.body.appendChild(container);
|
|
198
|
+
containers.push(container);
|
|
199
|
+
const app = createApp({
|
|
200
|
+
setup() {
|
|
201
|
+
const live = ref<typeof actions | null>(actions);
|
|
202
|
+
return () => [
|
|
203
|
+
h(HkRemoteInputDock, { actions: live.value }),
|
|
204
|
+
h("button", { class: "drop", onClick: () => { live.value = null; } }, "drop"),
|
|
205
|
+
h("button", { class: "revive", onClick: () => { live.value = actions; } }, "revive"),
|
|
206
|
+
];
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
mounts.push(app);
|
|
210
|
+
app.mount(container);
|
|
211
|
+
(container.querySelector<HTMLButtonElement>(".hk-remote-input-dock__dial"))!.click();
|
|
212
|
+
await nextTick();
|
|
213
|
+
const pad = () => [...container.querySelectorAll<HTMLButtonElement>(".hk-remote-input-dock__btn")];
|
|
214
|
+
pad()[0]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
215
|
+
expect(actions.setButtons).toHaveBeenLastCalledWith(0b001);
|
|
216
|
+
// The wire vanishes mid-hold: no release frame can ride it (it is
|
|
217
|
+
// GONE), but the local bit must not linger into the next session.
|
|
218
|
+
(container.querySelector<HTMLButtonElement>(".drop"))!.click();
|
|
219
|
+
await nextTick();
|
|
220
|
+
(container.querySelector<HTMLButtonElement>(".revive"))!.click();
|
|
221
|
+
await nextTick();
|
|
222
|
+
actions.setButtons.mockClear();
|
|
223
|
+
// Press a DIFFERENT mask: a stranded 0b001 would ride along as
|
|
224
|
+
// 0b011 — the collinear same-mask form cannot distinguish.
|
|
225
|
+
pad()[1]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
|
|
226
|
+
expect(actions.setButtons).toHaveBeenLastCalledWith(0b010); // the strand died with the old wire
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("the radiogroup roves tabindex and switches on arrows", async () => {
|
|
230
|
+
const container = document.createElement("div");
|
|
231
|
+
document.body.appendChild(container);
|
|
232
|
+
containers.push(container);
|
|
233
|
+
const mode = ref<"direct" | "virtual">("direct");
|
|
234
|
+
const app = createApp({
|
|
235
|
+
setup: () => () =>
|
|
236
|
+
h(HkRemoteInputDock, {
|
|
237
|
+
mode: mode.value,
|
|
238
|
+
"onUpdate:mode": (v: "direct" | "virtual") => { mode.value = v; },
|
|
239
|
+
}),
|
|
240
|
+
});
|
|
241
|
+
mounts.push(app);
|
|
242
|
+
app.mount(container);
|
|
243
|
+
(container.querySelector<HTMLButtonElement>(".hk-remote-input-dock__dial"))!.click();
|
|
244
|
+
await nextTick();
|
|
245
|
+
const radios = () => [...container.querySelectorAll<HTMLButtonElement>(".hk-remote-input-dock__mode")];
|
|
246
|
+
expect(radios()[0]!.tabIndex).toBe(0);
|
|
247
|
+
expect(radios()[1]!.tabIndex).toBe(-1);
|
|
248
|
+
radios()[0]!.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true }));
|
|
249
|
+
await nextTick();
|
|
250
|
+
expect(mode.value, "the arrow flipped the mode").toBe("virtual");
|
|
251
|
+
expect(radios()[1]!.tabIndex, "focus roved to the now-checked radio").toBe(0);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("the pad carries its accessible group role and labels", async () => {
|
|
255
|
+
const m = mountDock({ actions: { setButtons: () => {}, wheel: () => {} } });
|
|
256
|
+
m.dial.click();
|
|
257
|
+
await nextTick();
|
|
258
|
+
const pad = m.container.querySelector('[class="hk-remote-input-dock__pad"]');
|
|
259
|
+
expect(pad!.getAttribute("role")).toBe("group");
|
|
260
|
+
expect(pad!.getAttribute("aria-label")).toBeTruthy();
|
|
261
|
+
const labelled = [...m.btns()].every((b) => b.getAttribute("aria-label"));
|
|
262
|
+
expect(labelled, "every pad button is labelled").toBe(true);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("renders host view controls through the default slot", async () => {
|
|
266
|
+
const m = mountDock({}, () => h("button", { class: "host-ctl" }, "FIT"));
|
|
267
|
+
m.dial.click();
|
|
268
|
+
await nextTick();
|
|
269
|
+
expect(m.container.querySelector(".hk-remote-input-dock__host .host-ctl")).not.toBeNull();
|
|
270
|
+
});
|
|
271
|
+
});
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// AI-generated: developed with the DeepSeek Harness agent (model GLM-5.3 Flash); human-directed.
|
|
2
|
+
|
|
3
|
+
import { MousePointerClick } from "lucide-vue-next";
|
|
4
|
+
|
|
5
|
+
import { computed, defineComponent, onBeforeUnmount, ref, watch, type PropType } from "vue";
|
|
6
|
+
|
|
7
|
+
import { useI18n } from "../i18n/context";
|
|
8
|
+
import { MASK_LEFT, MASK_MIDDLE, MASK_RIGHT, type RemoteButtonActions } from "./remoteInputTypes";
|
|
9
|
+
import "./HkRemoteInputDock.scss";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* HkRemoteInputDock — the remote-control dial (2026-11-15 user
|
|
13
|
+
* direction: 不论电脑版、手机版,都需要在合适的位置悬浮拨号盘类似的工具栏).
|
|
14
|
+
*
|
|
15
|
+
* A floating dial button (fixed to a corner, above the session
|
|
16
|
+
* surface) that expands into the remote-input control card:
|
|
17
|
+
*
|
|
18
|
+
* - the MODE switch — direct touch (the finger is the pointer) vs the
|
|
19
|
+
* virtual mouse (a pointer that moves relatively; v-model);
|
|
20
|
+
* - the BUTTON pad — left / middle / right hold-buttons plus wheel
|
|
21
|
+
* up/down taps, wired straight into the `actions` prop (the host's
|
|
22
|
+
* transport closure; the dock never owns pointer state);
|
|
23
|
+
* - the HOST slot — view controls the owning surface adds beside them
|
|
24
|
+
* (fit/fill, the landscape-lock toggle, …).
|
|
25
|
+
*
|
|
26
|
+
* Hold semantics (the flagship phone flow: one thumb HOLDS a pad
|
|
27
|
+
* button while the other works the canvas): a held pad KEEPS the card
|
|
28
|
+
* open — the outside-pointerdown dismissal stands down while any pad
|
|
29
|
+
* bit is held — and any path that unmounts the card anyway (Escape,
|
|
30
|
+
* `hidden`, component teardown) force-releases every held bit, so a
|
|
31
|
+
* removed button can never leave the remote button latched.
|
|
32
|
+
*
|
|
33
|
+
* The mask the pad reports is the PAD'S OWN held bits — the host
|
|
34
|
+
* unions it with every other holder before wiring (see
|
|
35
|
+
* RemoteButtonActions.setButtons); one holder per bit.
|
|
36
|
+
*
|
|
37
|
+
* Dismissal follows the HkFab grammar: outside pointerdown or Escape
|
|
38
|
+
* closes the card (Escape is swallowed so an ancestor modal survives;
|
|
39
|
+
* a hidden dock swallows nothing).
|
|
40
|
+
*/
|
|
41
|
+
export default defineComponent({
|
|
42
|
+
name: "HkRemoteInputDock",
|
|
43
|
+
props: {
|
|
44
|
+
/** 'direct' — the finger/cursor is the pointer; 'virtual' — a
|
|
45
|
+
* pointer moves relatively (touchpad semantics). v-model:mode. */
|
|
46
|
+
mode: { type: String as PropType<"direct" | "virtual">, default: "direct" },
|
|
47
|
+
/** Button/wire actions; when absent the pad renders disabled. */
|
|
48
|
+
actions: { type: Object as PropType<RemoteButtonActions | null>, default: null },
|
|
49
|
+
/** Hide the whole dial (e.g. no live session). */
|
|
50
|
+
hidden: { type: Boolean, default: false },
|
|
51
|
+
},
|
|
52
|
+
emits: {
|
|
53
|
+
"update:mode": (_mode: "direct" | "virtual") => true,
|
|
54
|
+
},
|
|
55
|
+
setup(props, { emit, slots }) {
|
|
56
|
+
const { t } = useI18n();
|
|
57
|
+
const open = ref(false);
|
|
58
|
+
const rootRef = ref<HTMLElement>();
|
|
59
|
+
|
|
60
|
+
/** Hold-buttons: pointerdown presses, pointerup/leave/cancel
|
|
61
|
+
* releases — the pad speaks the absolute-mask action, so the
|
|
62
|
+
* mask of CURRENTLY HELD pads is sent on every transition. */
|
|
63
|
+
const held = ref(0);
|
|
64
|
+
|
|
65
|
+
/** Release every held bit. Unconditional on `held` itself; the
|
|
66
|
+
* wire call is best-effort (actions may have vanished with the
|
|
67
|
+
* session) — called from every teardown path so a removed button
|
|
68
|
+
* can never stay latched on the remote. */
|
|
69
|
+
function releaseAll() {
|
|
70
|
+
if (held.value === 0) return;
|
|
71
|
+
held.value = 0;
|
|
72
|
+
props.actions?.setButtons(0);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function padDown(mask: number) {
|
|
76
|
+
if (!props.actions) return;
|
|
77
|
+
held.value |= mask;
|
|
78
|
+
props.actions.setButtons(held.value);
|
|
79
|
+
}
|
|
80
|
+
function padUp(mask: number) {
|
|
81
|
+
// Clear the bit FIRST: `actions` may vanish mid-gesture (the
|
|
82
|
+
// session dropped) and the local bookkeeping must not strand it.
|
|
83
|
+
if ((held.value & mask) === 0) return;
|
|
84
|
+
held.value &= ~mask;
|
|
85
|
+
props.actions?.setButtons(held.value);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function setOpen(next: boolean) {
|
|
89
|
+
open.value = next;
|
|
90
|
+
if (next) {
|
|
91
|
+
document.addEventListener("keydown", onDocKeydown, true);
|
|
92
|
+
document.addEventListener("pointerdown", onDocPointerdown, true);
|
|
93
|
+
} else {
|
|
94
|
+
unbind();
|
|
95
|
+
releaseAll();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function unbind() {
|
|
100
|
+
document.removeEventListener("keydown", onDocKeydown, true);
|
|
101
|
+
document.removeEventListener("pointerdown", onDocPointerdown, true);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function onDocKeydown(e: KeyboardEvent) {
|
|
105
|
+
if (e.key !== "Escape" || props.hidden) return;
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
e.stopPropagation();
|
|
108
|
+
setOpen(false);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function onDocPointerdown(e: PointerEvent) {
|
|
112
|
+
const root = rootRef.value;
|
|
113
|
+
if (root && e.target instanceof Node && root.contains(e.target)) return;
|
|
114
|
+
// A HELD pad keeps the card open (the hold-and-work flow): the
|
|
115
|
+
// dismissal stands down while any bit is held.
|
|
116
|
+
if (held.value !== 0) return;
|
|
117
|
+
setOpen(false);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// hidden while open: the card vanishes with the session — release
|
|
121
|
+
// everything and stand the listeners down (an invisible dock must
|
|
122
|
+
// not swallow Escape for the whole app).
|
|
123
|
+
watch(
|
|
124
|
+
() => props.hidden,
|
|
125
|
+
(h) => {
|
|
126
|
+
if (h && open.value) setOpen(false);
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
// actions vanishing mid-hold (the session dropped): the disabled
|
|
130
|
+
// pad would swallow the pointerup — release what it held.
|
|
131
|
+
watch(
|
|
132
|
+
() => props.actions,
|
|
133
|
+
(a) => {
|
|
134
|
+
if (!a) releaseAll();
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
onBeforeUnmount(() => {
|
|
138
|
+
unbind();
|
|
139
|
+
releaseAll();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
function setMode(mode: "direct" | "virtual") {
|
|
143
|
+
emit("update:mode", mode);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const padItems = computed(() => [
|
|
147
|
+
{ key: "left", mask: MASK_LEFT },
|
|
148
|
+
{ key: "middle", mask: MASK_MIDDLE },
|
|
149
|
+
{ key: "right", mask: MASK_RIGHT },
|
|
150
|
+
] as const);
|
|
151
|
+
|
|
152
|
+
/** Roving-tab tabindex: only the checked radio is a tab stop. */
|
|
153
|
+
function radioTabindex(mode: "direct" | "virtual") {
|
|
154
|
+
return props.mode === mode ? 0 : -1;
|
|
155
|
+
}
|
|
156
|
+
function onRadiogroupKeydown(e: KeyboardEvent) {
|
|
157
|
+
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
setMode(props.mode === "direct" ? "virtual" : "direct");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return () =>
|
|
163
|
+
props.hidden
|
|
164
|
+
? null
|
|
165
|
+
: (
|
|
166
|
+
<div class="hk-remote-input-dock" ref={rootRef}>
|
|
167
|
+
<button
|
|
168
|
+
type="button"
|
|
169
|
+
class="hk-remote-input-dock__dial"
|
|
170
|
+
data-open={open.value || undefined}
|
|
171
|
+
aria-expanded={open.value}
|
|
172
|
+
aria-label={t("hikari::remoteInput.dial", "Remote input")}
|
|
173
|
+
onClick={() => setOpen(!open.value)}
|
|
174
|
+
>
|
|
175
|
+
<MousePointerClick size={20} aria-hidden="true" />
|
|
176
|
+
</button>
|
|
177
|
+
{open.value ? (
|
|
178
|
+
<div class="hk-remote-input-dock__card" role="group" aria-label={t("hikari::remoteInput.card", "Remote input controls")}>
|
|
179
|
+
<div
|
|
180
|
+
class="hk-remote-input-dock__modes"
|
|
181
|
+
role="radiogroup"
|
|
182
|
+
aria-label={t("hikari::remoteInput.mode", "Pointer mode")}
|
|
183
|
+
onKeydown={onRadiogroupKeydown}
|
|
184
|
+
>
|
|
185
|
+
<button
|
|
186
|
+
type="button"
|
|
187
|
+
role="radio"
|
|
188
|
+
tabindex={radioTabindex("direct")}
|
|
189
|
+
aria-checked={props.mode === "direct"}
|
|
190
|
+
class="hk-remote-input-dock__mode"
|
|
191
|
+
data-active={props.mode === "direct" || undefined}
|
|
192
|
+
onClick={() => setMode("direct")}
|
|
193
|
+
>
|
|
194
|
+
{t("hikari::remoteInput.mode.direct", "Direct touch")}
|
|
195
|
+
</button>
|
|
196
|
+
<button
|
|
197
|
+
type="button"
|
|
198
|
+
role="radio"
|
|
199
|
+
tabindex={radioTabindex("virtual")}
|
|
200
|
+
aria-checked={props.mode === "virtual"}
|
|
201
|
+
class="hk-remote-input-dock__mode"
|
|
202
|
+
data-active={props.mode === "virtual" || undefined}
|
|
203
|
+
onClick={() => setMode("virtual")}
|
|
204
|
+
>
|
|
205
|
+
{t("hikari::remoteInput.mode.virtual", "Virtual mouse")}
|
|
206
|
+
</button>
|
|
207
|
+
</div>
|
|
208
|
+
<div class="hk-remote-input-dock__pad" role="group" aria-label={t("hikari::remoteInput.pad", "Buttons and wheel")}>
|
|
209
|
+
{padItems.value.map(({ key, mask }) => (
|
|
210
|
+
<button
|
|
211
|
+
key={key}
|
|
212
|
+
type="button"
|
|
213
|
+
class="hk-remote-input-dock__btn"
|
|
214
|
+
disabled={!props.actions}
|
|
215
|
+
aria-label={t(`hikari::remoteInput.btn.${key}`, key)}
|
|
216
|
+
onPointerdown={(e) => { e.preventDefault(); padDown(mask); }}
|
|
217
|
+
onPointerup={() => padUp(mask)}
|
|
218
|
+
onPointerleave={() => padUp(mask)}
|
|
219
|
+
onPointercancel={() => padUp(mask)}
|
|
220
|
+
>
|
|
221
|
+
{t(`hikari::remoteInput.btn.${key}`, key).slice(0, 1).toUpperCase()}
|
|
222
|
+
</button>
|
|
223
|
+
))}
|
|
224
|
+
<button
|
|
225
|
+
type="button"
|
|
226
|
+
class="hk-remote-input-dock__btn"
|
|
227
|
+
disabled={!props.actions}
|
|
228
|
+
aria-label={t("hikari::remoteInput.wheelUp", "Wheel up")}
|
|
229
|
+
onClick={() => props.actions?.wheel(1)}
|
|
230
|
+
>
|
|
231
|
+
↑
|
|
232
|
+
</button>
|
|
233
|
+
<button
|
|
234
|
+
type="button"
|
|
235
|
+
class="hk-remote-input-dock__btn"
|
|
236
|
+
disabled={!props.actions}
|
|
237
|
+
aria-label={t("hikari::remoteInput.wheelDown", "Wheel down")}
|
|
238
|
+
onClick={() => props.actions?.wheel(-1)}
|
|
239
|
+
>
|
|
240
|
+
↓
|
|
241
|
+
</button>
|
|
242
|
+
</div>
|
|
243
|
+
{/* Host view controls (fit/fill, landscape lock, …). */}
|
|
244
|
+
{slots.default ? (
|
|
245
|
+
<div class="hk-remote-input-dock__host">{slots.default()}</div>
|
|
246
|
+
) : null}
|
|
247
|
+
</div>
|
|
248
|
+
) : null}
|
|
249
|
+
</div>
|
|
250
|
+
);
|
|
251
|
+
},
|
|
252
|
+
});
|