@celestia-island/hikari 0.55.401 → 0.55.403

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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/src/components/HkDateTag.test.tsx +46 -3
  3. package/src/components/HkDateTag.tsx +18 -4
  4. package/src/components/HkRemoteInputDock.barrel.test.ts +29 -0
  5. package/src/components/HkRemoteInputDock.scss +125 -0
  6. package/src/components/HkRemoteInputDock.test.tsx +271 -0
  7. package/src/components/HkRemoteInputDock.tsx +252 -0
  8. package/src/components/HkVirtualCursor.scss +93 -0
  9. package/src/components/HkVirtualCursor.test.tsx +146 -0
  10. package/src/components/HkVirtualCursor.tsx +133 -0
  11. package/src/components/remoteInputTypes.test.ts +47 -0
  12. package/src/components/remoteInputTypes.ts +95 -0
  13. package/src/composables/useOrientationLock.test.ts +39 -0
  14. package/src/composables/useOrientationLock.ts +39 -0
  15. package/src/composables/useRemoteTouchGestures.test.ts +180 -0
  16. package/src/composables/useRemoteTouchGestures.ts +251 -0
  17. package/src/composables/useVirtualPointer.test.ts +128 -0
  18. package/src/composables/useVirtualPointer.ts +151 -0
  19. package/src/i18n/locales/ar/components.json +58 -47
  20. package/src/i18n/locales/de/components.json +58 -47
  21. package/src/i18n/locales/en/components.json +58 -47
  22. package/src/i18n/locales/es/components.json +58 -47
  23. package/src/i18n/locales/fr/components.json +58 -47
  24. package/src/i18n/locales/ja/components.json +58 -47
  25. package/src/i18n/locales/ko/components.json +58 -47
  26. package/src/i18n/locales/pt/components.json +58 -47
  27. package/src/i18n/locales/ru/components.json +58 -47
  28. package/src/i18n/locales/zh-Hans/components.json +62 -51
  29. package/src/i18n/locales/zh-Hant/components.json +62 -51
  30. package/src/i18n/usageSurface.test.ts +4 -0
  31. package/src/index.ts +25 -0
@@ -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
+ });
@@ -0,0 +1,93 @@
1
+ /* HkVirtualCursor — the virtual mouse's rendered half.
2
+ *
3
+ * The overlay is inset-0 over the remote screen's display box and
4
+ * click-transparent except for the glyph: position rides percentages
5
+ * of the overlay, so letterbox/fill transforms of the underlying
6
+ * canvas carry the pointer along with the pixels. The glyph's lobes
7
+ * are the only hit area (the phone's missing mouse buttons). */
8
+
9
+ .hk-virtual-cursor {
10
+ position: absolute;
11
+ inset: 0;
12
+ pointer-events: none;
13
+ z-index: 2; /* above the canvas + grab hint, below floating chrome */
14
+ }
15
+
16
+ .hk-virtual-cursor__glyph {
17
+ position: absolute;
18
+ /* The arrow's hotspot (top-left of the glyph) rides the exact
19
+ percentage; the box itself hangs down-right from it. */
20
+ transform: translate(-1px, -1px);
21
+ display: block;
22
+ pointer-events: none;
23
+ }
24
+
25
+ .hk-virtual-cursor__arrow {
26
+ width: 18px;
27
+ height: 27px;
28
+ filter: drop-shadow(0 1px 2px rgb(0 0 0 / 55%));
29
+ pointer-events: none;
30
+
31
+ path {
32
+ fill: rgb(var(--color-text));
33
+ stroke: rgb(0 0 0 / 65%);
34
+ stroke-width: 1;
35
+ }
36
+ }
37
+
38
+ /* The lobes: a horizontal two-button pill tucked under the arrow's
39
+ * tail — the two buttons sit on one inline row (inline-grid keeps the
40
+ * glyph block layout). Real buttons (focusable, pressable,
41
+ * cancellable); held renders lit. */
42
+ .hk-virtual-cursor__lobe {
43
+ pointer-events: auto;
44
+ display: inline-grid;
45
+ place-items: center;
46
+ width: 30px;
47
+ height: 24px;
48
+ border: 1px solid rgb(var(--color-border));
49
+ background: rgb(var(--color-background) / 92%);
50
+ color: rgb(var(--color-text));
51
+ border-radius: 8px;
52
+ vertical-align: top;
53
+ cursor: pointer;
54
+ touch-action: none;
55
+
56
+ /* TinyMouseButton glyphs: the lobe IS the button — draw its own
57
+ profile so no icon dependency is needed. */
58
+ &[data-lobe="left"] {
59
+ border-bottom-right-radius: 2px;
60
+ }
61
+ &[data-lobe="right"] {
62
+ border-bottom-left-radius: 2px;
63
+ }
64
+ &[data-lobe="left"]::after,
65
+ &[data-lobe="right"]::after {
66
+ content: "";
67
+ width: 10px;
68
+ height: 10px;
69
+ border-radius: 3px;
70
+ background: currentColor;
71
+ opacity: 0.55;
72
+ }
73
+
74
+ &[data-held] {
75
+ background: rgb(var(--color-primary) / 80%);
76
+ border-color: rgb(var(--color-primary));
77
+ color: rgb(var(--color-on-primary, 255 255 255));
78
+
79
+ &::after {
80
+ opacity: 1;
81
+ }
82
+ }
83
+
84
+ &:focus-visible {
85
+ outline: 2px solid rgb(var(--color-primary) / 70%);
86
+ outline-offset: 1px;
87
+ }
88
+ }
89
+
90
+ /* The two lobes sit side by side under the arrow (inline row). */
91
+ .hk-virtual-cursor__lobe + .hk-virtual-cursor__lobe {
92
+ margin-left: -1px; /* share the border, one pill */
93
+ }
@@ -0,0 +1,146 @@
1
+ import { afterEach, describe, expect, it, vitest } from "vitest";
2
+ import { createApp, defineComponent, h, nextTick } from "vue";
3
+
4
+ import HkVirtualCursor from "./HkVirtualCursor";
5
+
6
+ const mounts: ReturnType<typeof createApp>[] = [];
7
+ const containers: HTMLElement[] = [];
8
+
9
+ interface Harness {
10
+ root: HTMLElement;
11
+ glyph: HTMLElement;
12
+ lobes: HTMLButtonElement[];
13
+ presses: [number, boolean][];
14
+ }
15
+
16
+ interface CursorProps {
17
+ x: number;
18
+ y: number;
19
+ viewport: { width: number; height: number };
20
+ buttons?: number;
21
+ label?: string;
22
+ }
23
+
24
+ /** Mount an HkVirtualCursor through a wrapper app and collect press
25
+ * events (the HkFab.test.tsx mount pattern). */
26
+ function mountCursor(props: CursorProps): Harness {
27
+ const container = document.createElement("div");
28
+ document.body.appendChild(container);
29
+ containers.push(container);
30
+
31
+ const harness: Harness = {
32
+ root: document.createElement("div"),
33
+ glyph: document.createElement("div"),
34
+ lobes: [],
35
+ presses: [],
36
+ };
37
+
38
+ const Wrapper = defineComponent({
39
+ setup() {
40
+ return () =>
41
+ h(HkVirtualCursor, {
42
+ "onPress": (mask: number, down: boolean) => { harness.presses.push([mask, down]); },
43
+ ...props,
44
+ });
45
+ },
46
+ });
47
+ const app = createApp(Wrapper);
48
+ mounts.push(app);
49
+ app.mount(container);
50
+
51
+ const root = container.querySelector<HTMLElement>(".hk-virtual-cursor");
52
+ const glyph = container.querySelector<HTMLElement>(".hk-virtual-cursor__glyph");
53
+ const lobes = [...container.querySelectorAll<HTMLButtonElement>(".hk-virtual-cursor__lobe")];
54
+ if (!root || !glyph || lobes.length !== 2) throw new Error("HkVirtualCursor did not render its shell");
55
+ harness.root = root;
56
+ harness.glyph = glyph;
57
+ harness.lobes = lobes;
58
+ return harness;
59
+ }
60
+
61
+ afterEach(() => {
62
+ while (mounts.length) mounts.pop()?.unmount();
63
+ while (containers.length) containers.pop()?.remove();
64
+ });
65
+
66
+ /** Percentage mapping: x/width*100 positions the glyph inside the
67
+ * inset-0 overlay, so the letterbox/fill transform of the underlying
68
+ * canvas carries the pointer with the pixels. */
69
+ describe("HkVirtualCursor", () => {
70
+ it("maps remote coordinates to percentage positions", () => {
71
+ const { glyph } = mountCursor({ x: 960, y: 270, viewport: { width: 1920, height: 1080 } });
72
+ const style = glyph.getAttribute("style") ?? "";
73
+ expect(style).toContain("left: 50%");
74
+ expect(style).toContain("top: 25%");
75
+ });
76
+
77
+ it("survives a degenerate viewport without NaN", () => {
78
+ const { glyph } = mountCursor({ x: 5, y: 5, viewport: { width: 0, height: 0 } });
79
+ const style = glyph.getAttribute("style") ?? "";
80
+ expect(style).not.toContain("NaN");
81
+ });
82
+
83
+ it("lobes emit press down/up with their masks", async () => {
84
+ const { lobes, presses } = mountCursor({ x: 10, y: 10, viewport: { width: 100, height: 100 } });
85
+ const [left, right] = lobes;
86
+ left!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
87
+ left!.dispatchEvent(new Event("pointerup", { bubbles: true }));
88
+ right!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
89
+ right!.dispatchEvent(new Event("pointerup", { bubbles: true }));
90
+ await nextTick();
91
+ expect(presses).toEqual([
92
+ [0b001, true],
93
+ [0b001, false],
94
+ [0b100, true],
95
+ [0b100, false],
96
+ ]);
97
+ });
98
+
99
+ it("unmount releases a lobe still held (teardown honesty)", async () => {
100
+ const { lobes, presses } = mountCursor({ x: 10, y: 10, viewport: { width: 100, height: 100 } });
101
+ lobes[0]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
102
+ lobes[1]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
103
+ expect(presses).toEqual([[0b001, true], [0b100, true]]);
104
+ // Unmount mid-hold (a mode flip / session drop): BOTH held bits
105
+ // must release — a removed button can never stay latched.
106
+ while (mounts.length) mounts.pop()?.unmount();
107
+ expect(presses).toEqual([
108
+ [0b001, true], [0b100, true],
109
+ [0b001, false], [0b100, false],
110
+ ]);
111
+ });
112
+
113
+ it("one holder per bit: a lobe refuses to take over a foreign hold", async () => {
114
+ // LEFT is held by the dock pad (flows in through props.buttons):
115
+ // pressing the left lobe must be refused — its release could not
116
+ // know the dock still holds the bit, and an early release would
117
+ // drop an in-flight drag.
118
+ const { lobes, presses } = mountCursor({
119
+ x: 10, y: 10, viewport: { width: 100, height: 100 }, buttons: 0b001,
120
+ });
121
+ lobes[0]!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
122
+ lobes[0]!.dispatchEvent(new Event("pointerup", { bubbles: true }));
123
+ await nextTick();
124
+ expect(presses).toEqual([]);
125
+ });
126
+
127
+ it("ownership: a leave releases only what THIS lobe pressed", async () => {
128
+ // The left bit is held by ANOTHER surface (the dock pad — it flows
129
+ // in through props.buttons): this surface's leave must NOT release
130
+ // it, and this surface never re-releases what it never pressed.
131
+ const { lobes, presses } = mountCursor({
132
+ x: 10, y: 10, viewport: { width: 100, height: 100 }, buttons: 0b001,
133
+ });
134
+ const [left, right] = lobes;
135
+ expect(left!.hasAttribute("data-held")).toBe(true); // rendered held…
136
+ left!.dispatchEvent(new Event("pointerleave", { bubbles: true })); // …but not pressed here
137
+ right!.dispatchEvent(new Event("pointerleave", { bubbles: true }));
138
+ await nextTick();
139
+ expect(presses, "neither leave releases the foreign hold").toEqual([]);
140
+ // A lobe pressed HERE still releases on leave.
141
+ right!.dispatchEvent(new Event("pointerdown", { bubbles: true }));
142
+ right!.dispatchEvent(new Event("pointerleave", { bubbles: true }));
143
+ await nextTick();
144
+ expect(presses).toEqual([[0b100, true], [0b100, false]]);
145
+ });
146
+ });
@@ -0,0 +1,133 @@
1
+ // AI-generated: developed with the DeepSeek Harness agent (model GLM-5.3 Flash); human-directed.
2
+
3
+ import { computed, defineComponent, onBeforeUnmount, ref, type PropType } from "vue";
4
+
5
+ import { useI18n } from "../i18n/context";
6
+ import {
7
+ MASK_LEFT,
8
+ MASK_RIGHT,
9
+ type RemoteViewport,
10
+ } from "./remoteInputTypes";
11
+ import "./HkVirtualCursor.scss";
12
+
13
+ /**
14
+ * HkVirtualCursor — the rendered half of the virtual mouse (2026-11-15
15
+ * remote-control direction: a pointer that MOVES with the finger
16
+ * instead of BEING the finger).
17
+ *
18
+ * An absolute-position overlay pinned over the remote screen's display
19
+ * box: the pointer glyph sits at the pointer's REMOTE coordinates
20
+ * (percentage-mapped, so any letterbox/fill transform of the underlying
21
+ * canvas carries it along), and its two button lobes are REAL touch
22
+ * targets — hold the left/right lobe to press that button (press and
23
+ * release pair, emitted through `press`), which is how a phone without
24
+ * mouse buttons clicks.
25
+ *
26
+ * Ownership rule (R2): a lobe releases ONLY a button IT pressed — the
27
+ * local `pressedHere` set tracks which bits this surface put down, so
28
+ * a bit held by another surface (the dock pad, a host-side hold)
29
+ * survives an unrelated pointerleave here, and this surface never
30
+ * re-releases what it never pressed.
31
+ *
32
+ * The component is presentation + lobes only: position and pressed
33
+ * state come in as props (a `useVirtualPointer` state), and every
34
+ * interaction reports upward — it owns no pointer state beyond the
35
+ * ownership set and never talks to a transport.
36
+ */
37
+ export default defineComponent({
38
+ name: "HkVirtualCursor",
39
+ props: {
40
+ /** Pointer x in REMOTE pixels. */
41
+ x: { type: Number, required: true },
42
+ /** Pointer y in REMOTE pixels. */
43
+ y: { type: Number, required: true },
44
+ /** The remote screen's pixel size (the coordinate space of x/y). */
45
+ viewport: { type: Object as PropType<RemoteViewport>, required: true },
46
+ /** Live UI button mask — a pressed lobe renders held. */
47
+ buttons: { type: Number, default: 0 },
48
+ /** Accessible label for the cursor surface. */
49
+ label: { type: String, default: "" },
50
+ },
51
+ emits: {
52
+ /** A lobe press (mask bit) went down (true) or up (false). */
53
+ press: (_mask: number, _down: boolean) => true,
54
+ },
55
+ setup(props, { emit }) {
56
+ const { t } = useI18n();
57
+
58
+ /** Bits THIS surface pressed and has not yet released. */
59
+ const pressedHere = ref(0);
60
+
61
+ const leftPct = computed(() =>
62
+ props.viewport.width > 0 ? (props.x / props.viewport.width) * 100 : 0,
63
+ );
64
+ const topPct = computed(() =>
65
+ props.viewport.height > 0 ? (props.y / props.viewport.height) * 100 : 0,
66
+ );
67
+ const leftHeld = computed(() => (props.buttons & MASK_LEFT) !== 0);
68
+ const rightHeld = computed(() => (props.buttons & MASK_RIGHT) !== 0);
69
+
70
+ /** One holder per bit: a lobe never TAKES OVER a bit another
71
+ * surface (the dock pad, a host-side hold) already holds — its
72
+ * release could not know the other holder remains, and an early
73
+ * release would drop an in-flight drag. Release the other surface
74
+ * first; the lobe renders held either way. */
75
+ function lobeDown(mask: number) {
76
+ if ((props.buttons & mask) !== 0 && (pressedHere.value & mask) === 0) return;
77
+ pressedHere.value |= mask;
78
+ emit("press", mask, true);
79
+ }
80
+ /** Release ONLY what this surface pressed (the ownership rule). */
81
+ function lobeUp(mask: number) {
82
+ if ((pressedHere.value & mask) === 0) return;
83
+ pressedHere.value &= ~mask;
84
+ emit("press", mask, false);
85
+ }
86
+
87
+ // Teardown honesty (the dock's own invariant, applied here too): a
88
+ // lobe held when the cursor unmounts (mode flip, session drop)
89
+ // must release — a removed button can never leave the remote
90
+ // button latched.
91
+ onBeforeUnmount(() => {
92
+ for (const mask of [MASK_LEFT, MASK_RIGHT]) lobeUp(mask);
93
+ });
94
+
95
+ return () => (
96
+ <div class="hk-virtual-cursor" aria-label={props.label} role="presentation">
97
+ <div
98
+ class="hk-virtual-cursor__glyph"
99
+ style={{ left: `${leftPct.value}%`, top: `${topPct.value}%` }}
100
+ >
101
+ {/* The pointer arrow: hotspot at the glyph's top-left. */}
102
+ <svg class="hk-virtual-cursor__arrow" viewBox="0 0 12 18" aria-hidden="true">
103
+ <path d="M1 1 L1 14 L4.6 10.8 L7 16 L9.2 15 L6.8 9.9 L11 9.4 Z" />
104
+ </svg>
105
+ {/* The lobes: real touch targets under the arrow's tail —
106
+ left and right mouse buttons a phone does not have. */}
107
+ <button
108
+ type="button"
109
+ class="hk-virtual-cursor__lobe"
110
+ data-lobe="left"
111
+ data-held={leftHeld.value || undefined}
112
+ aria-label={t("hikari::remoteInput.btn.left", "left button")}
113
+ onPointerdown={(e) => { e.preventDefault(); lobeDown(MASK_LEFT); }}
114
+ onPointerup={() => lobeUp(MASK_LEFT)}
115
+ onPointerleave={() => lobeUp(MASK_LEFT)}
116
+ onPointercancel={() => lobeUp(MASK_LEFT)}
117
+ />
118
+ <button
119
+ type="button"
120
+ class="hk-virtual-cursor__lobe"
121
+ data-lobe="right"
122
+ data-held={rightHeld.value || undefined}
123
+ aria-label={t("hikari::remoteInput.btn.right", "right button")}
124
+ onPointerdown={(e) => { e.preventDefault(); lobeDown(MASK_RIGHT); }}
125
+ onPointerup={() => lobeUp(MASK_RIGHT)}
126
+ onPointerleave={() => lobeUp(MASK_RIGHT)}
127
+ onPointercancel={() => lobeUp(MASK_RIGHT)}
128
+ />
129
+ </div>
130
+ </div>
131
+ );
132
+ },
133
+ });
@@ -0,0 +1,47 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import {
4
+ TAP_MAX_MS,
5
+ TAP_MAX_TRAVEL_PX,
6
+ clampToViewport,
7
+ displayScale,
8
+ wheelNotches,
9
+ } from "./remoteInputTypes";
10
+
11
+ describe("remoteInputTypes pure helpers", () => {
12
+ it("clamps into the inclusive pixel edges", () => {
13
+ const vp = { width: 1920, height: 1080 };
14
+ expect(clampToViewport(-20, -20, vp)).toEqual({ x: 0, y: 0 });
15
+ expect(clampToViewport(5000, 5000, vp)).toEqual({ x: 1919, y: 1079 });
16
+ expect(clampToViewport(960.4, 540.6, vp)).toEqual({ x: 960, y: 541 });
17
+ });
18
+
19
+ it("survives a degenerate viewport (never NaN, always 0..0)", () => {
20
+ expect(clampToViewport(100, 100, { width: 0, height: 0 })).toEqual({ x: 0, y: 0 });
21
+ });
22
+
23
+ it("scales remote pixels per display pixel along one axis", () => {
24
+ // A 1920px remote axis shown in 960 display px: one display px
25
+ // covers two remote px.
26
+ expect(displayScale(1920, 960)).toBe(2);
27
+ // The vertical axis scales independently (fill/cover transforms).
28
+ expect(displayScale(1080, 540)).toBe(2);
29
+ // Degenerate boxes keep 1:1 instead of exploding.
30
+ expect(displayScale(1920, 0)).toBe(1);
31
+ expect(displayScale(0, 960)).toBe(1);
32
+ });
33
+
34
+ it("converts display scroll to notches with the canvas coefficient", () => {
35
+ expect(wheelNotches(-53)).toBe(1); // finger up = scroll up
36
+ expect(wheelNotches(53)).toBe(-1);
37
+ expect(wheelNotches(-26)).toBe(0); // sub-notch rounds away
38
+ expect(wheelNotches(-212)).toBe(4);
39
+ });
40
+
41
+ it("pins the gesture constants the recognisers branch on", () => {
42
+ // The recognisers import these; pin the values so a silent edit
43
+ // cannot desynchronise the docs from the behaviour.
44
+ expect(TAP_MAX_MS).toBe(250);
45
+ expect(TAP_MAX_TRAVEL_PX).toBe(8);
46
+ });
47
+ });