@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.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/src/components/HkRemoteInputDock.barrel.test.ts +29 -0
  3. package/src/components/HkRemoteInputDock.scss +125 -0
  4. package/src/components/HkRemoteInputDock.test.tsx +271 -0
  5. package/src/components/HkRemoteInputDock.tsx +252 -0
  6. package/src/components/HkVirtualCursor.scss +93 -0
  7. package/src/components/HkVirtualCursor.test.tsx +146 -0
  8. package/src/components/HkVirtualCursor.tsx +133 -0
  9. package/src/components/remoteInputTypes.test.ts +47 -0
  10. package/src/components/remoteInputTypes.ts +95 -0
  11. package/src/composables/useOrientationLock.test.ts +39 -0
  12. package/src/composables/useOrientationLock.ts +39 -0
  13. package/src/composables/useRemoteTouchGestures.test.ts +180 -0
  14. package/src/composables/useRemoteTouchGestures.ts +251 -0
  15. package/src/composables/useVirtualPointer.test.ts +128 -0
  16. package/src/composables/useVirtualPointer.ts +151 -0
  17. package/src/i18n/locales/ar/components.json +58 -47
  18. package/src/i18n/locales/de/components.json +58 -47
  19. package/src/i18n/locales/en/components.json +58 -47
  20. package/src/i18n/locales/es/components.json +58 -47
  21. package/src/i18n/locales/fr/components.json +58 -47
  22. package/src/i18n/locales/ja/components.json +58 -47
  23. package/src/i18n/locales/ko/components.json +58 -47
  24. package/src/i18n/locales/pt/components.json +58 -47
  25. package/src/i18n/locales/ru/components.json +58 -47
  26. package/src/i18n/locales/zh-Hans/components.json +62 -51
  27. package/src/i18n/locales/zh-Hant/components.json +62 -51
  28. package/src/i18n/usageSurface.test.ts +4 -0
  29. package/src/index.ts +25 -0
@@ -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
+ });
@@ -0,0 +1,95 @@
1
+ // AI-generated: developed with the DeepSeek Harness agent (model GLM-5.3 Flash); human-directed.
2
+
3
+ /**
4
+ * Remote-input shared vocabulary — the types and pure helpers the
5
+ * remote-control components (HkRemoteInputDock, HkVirtualCursor, the
6
+ * touch-gesture and virtual-pointer composables) speak, and the
7
+ * contract a HOST (e.g. shittim-chest's RemoteDesktopCanvas) wires to
8
+ * its transport.
9
+ *
10
+ * The button-mask convention is the UI mask the node-console canvas
11
+ * already speaks on its wire: bit0 left, bit1 MIDDLE, bit2 right. It
12
+ * is deliberately NOT the VNC mask (bit1 right) — hosts that ride a
13
+ * VNC-shaped transport remap at their boundary, exactly like
14
+ * useDesktopSession.sendPointer does; keeping the UI mask here means
15
+ * the components compose with the existing canvas handlers verbatim.
16
+ */
17
+
18
+ /** UI button mask: bit0 left, bit1 middle, bit2 right. */
19
+ export const MASK_LEFT = 0b001 as const;
20
+ export const MASK_MIDDLE = 0b010 as const;
21
+ export const MASK_RIGHT = 0b100 as const;
22
+ /**
23
+ * The minimal action surface a dock needs from the host. The host
24
+ * closes over its own pointer state (the virtual pointer's current
25
+ * position, or its own equivalent) — the components never own
26
+ * coordinates, only button bits and wheel notches.
27
+ */
28
+ export interface RemoteButtonActions {
29
+ /**
30
+ * The PAD's OWN held bits (its absolute mask), called on every pad
31
+ * transition. This is NOT the global pressed set: the host MUST
32
+ * union it with every other holder (a virtual pointer's held state,
33
+ * another surface's hold) before sending the wire frame —
34
+ * forwarding it verbatim would release a co-resident hold's bit
35
+ * (one holder per bit, the same law the cursor's lobes enforce
36
+ * structurally).
37
+ */
38
+ setButtons(padHeldMask: number): void;
39
+ /**
40
+ * Vertical wheel notches at the host's current pointer position;
41
+ * positive scrolls up/away from the operator.
42
+ */
43
+ wheel(units: number): void;
44
+ }
45
+
46
+ /** The remote screen's pixel coordinate space the pointer lives in. */
47
+ export interface RemoteViewport {
48
+ width: number;
49
+ height: number;
50
+ }
51
+
52
+ /** Live virtual-pointer state (remote pixels + UI button mask). */
53
+ export interface VirtualPointerState {
54
+ x: number;
55
+ y: number;
56
+ buttons: number;
57
+ }
58
+
59
+ /** Remote pixels per display pixel along ONE axis (degenerate boxes
60
+ * stay 1:1 instead of exploding). Callers scale each axis with its
61
+ * own pair — a fill/cover transform stretches them differently. */
62
+ export function displayScale(remotePx: number, displayPx: number): number {
63
+ if (displayPx <= 0 || remotePx <= 0) return 1;
64
+ return remotePx / displayPx;
65
+ }
66
+
67
+ /** Clamp a point into the remote viewport (inclusive pixel edges). */
68
+ export function clampToViewport(
69
+ x: number,
70
+ y: number,
71
+ viewport: RemoteViewport,
72
+ ): { x: number; y: number } {
73
+ const maxX = Math.max(0, Math.floor(viewport.width) - 1);
74
+ const maxY = Math.max(0, Math.floor(viewport.height) - 1);
75
+ return {
76
+ x: Math.min(Math.max(0, Math.round(x)), maxX),
77
+ y: Math.min(Math.max(0, Math.round(y)), maxY),
78
+ };
79
+ }
80
+
81
+ /** Wheel notches from a display-pixel vertical scroll (the canvas
82
+ * coefficient: 53 display px per notch, positive scrolls up). */
83
+ export function wheelNotches(displayDy: number): number {
84
+ return Math.round(-displayDy / 53);
85
+ }
86
+
87
+ /** A tap: quick (≤ 250 ms) and still (< 8 display px travelled). */
88
+ export const TAP_MAX_MS = 250;
89
+ export const TAP_MAX_TRAVEL_PX = 8;
90
+
91
+ /** A long-press: held ≥ 500 ms and still (< 8 display px travelled). */
92
+ export const LONG_PRESS_MIN_MS = 500;
93
+
94
+ /** Two-finger scroll: 53 display px of averaged travel per notch. */
95
+ export const TWO_FINGER_PX_PER_NOTCH = 53;
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+
3
+ import { useOrientationLock } from "./useOrientationLock";
4
+
5
+ describe("useOrientationLock", () => {
6
+ it("reports unsupported without the API and resolves lock to false", async () => {
7
+ const orig = (screen as { orientation?: ScreenOrientation }).orientation;
8
+ Object.defineProperty(screen, "orientation", { configurable: true, value: undefined });
9
+ try {
10
+ const { supported, lockLandscape } = useOrientationLock();
11
+ expect(supported).toBe(false);
12
+ expect(await lockLandscape()).toBe(false);
13
+ } finally {
14
+ Object.defineProperty(screen, "orientation", { configurable: true, value: orig });
15
+ }
16
+ });
17
+
18
+ it("locks landscape through the API; a refusal resolves false", async () => {
19
+ const orig = (screen as { orientation?: ScreenOrientation }).orientation;
20
+ const lock = vi.fn(async () => {});
21
+ const unlock = vi.fn(async () => {});
22
+ Object.defineProperty(screen, "orientation", {
23
+ configurable: true,
24
+ value: { lock, unlock },
25
+ });
26
+ try {
27
+ const api = useOrientationLock();
28
+ expect(api.supported).toBe(true);
29
+ expect(await api.lockLandscape()).toBe(true);
30
+ expect(lock).toHaveBeenCalledWith("landscape");
31
+ await api.unlock();
32
+ expect(unlock).toHaveBeenCalled();
33
+ lock.mockRejectedValue(new DOMException("denied"));
34
+ expect(await api.lockLandscape(), "a refusal is a false, never a throw").toBe(false);
35
+ } finally {
36
+ Object.defineProperty(screen, "orientation", { configurable: true, value: orig });
37
+ }
38
+ });
39
+ });
@@ -0,0 +1,39 @@
1
+ // AI-generated: developed with the DeepSeek Harness agent (model GLM-5.3 Flash); human-directed.
2
+
3
+ /**
4
+ * useOrientationLock — request landscape for the remote-control
5
+ * fullscreen posture (2026-11-15 user direction: 自动触发横屏).
6
+ *
7
+ * The Screen Orientation API only honours `lock()` while the document
8
+ * holds a fullscreen element — callers therefore lock on entering the
9
+ * session-pane fullscreen and unlock on exit. Engines without the API
10
+ * (iOS Safari) resolve `lock()` to false: the host shows its
11
+ * "rotate the phone" hint instead, never a silent dead control.
12
+ */
13
+ export function useOrientationLock() {
14
+ const orientation = typeof screen !== "undefined" && "orientation" in screen
15
+ ? (screen as Screen & { orientation?: ScreenOrientation }).orientation
16
+ : undefined;
17
+ const supported = typeof orientation?.lock === "function";
18
+
19
+ async function lockLandscape(): Promise<boolean> {
20
+ if (!supported || !orientation) return false;
21
+ try {
22
+ await orientation.lock("landscape");
23
+ return true;
24
+ } catch {
25
+ // Not in fullscreen, engine refused, or the platform ignores it.
26
+ return false;
27
+ }
28
+ }
29
+
30
+ async function unlock(): Promise<void> {
31
+ try {
32
+ await orientation?.unlock?.();
33
+ } catch {
34
+ /* unlocking an unlocked orientation is a no-op at worst */
35
+ }
36
+ }
37
+
38
+ return { supported, lockLandscape, unlock };
39
+ }