@celestia-island/hikari 0.55.21 → 0.55.23

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.
@@ -0,0 +1,158 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { createApp, defineComponent, h, nextTick, ref } from "vue";
3
+
4
+ import HkNodeCanvas from "./HkNodeCanvas";
5
+
6
+ /** Mount a component into a detached div and return the root element. */
7
+ function mountToDom(component: ReturnType<typeof defineComponent>): HTMLElement {
8
+ const el = document.createElement("div");
9
+ document.body.appendChild(el);
10
+ const app = createApp(component);
11
+ app.mount(el);
12
+ return el;
13
+ }
14
+
15
+ function pointerEvent(type: string, opts: Record<string, number | boolean> = {}): PointerEvent {
16
+ return new PointerEvent(type, {
17
+ pointerId: (opts.pointerId as number) ?? 1,
18
+ clientX: (opts.clientX as number) ?? 0,
19
+ clientY: (opts.clientY as number) ?? 0,
20
+ button: (opts.button as number) ?? 0,
21
+ bubbles: true,
22
+ cancelable: true,
23
+ ...opts,
24
+ });
25
+ }
26
+
27
+ describe("HkNodeCanvas gesture & animation upgrades", () => {
28
+ describe("tweenCamera", () => {
29
+ it("exposes tweenCamera as a function", () => {
30
+ const exposed: Record<string, unknown> = {};
31
+ const Host = defineComponent({
32
+ setup() {
33
+ const canvasRef = ref<unknown>(null);
34
+ const check = () => {
35
+ const vm = canvasRef.value as Record<string, unknown> | null;
36
+ if (vm) Object.assign(exposed, { tweenCamera: vm.tweenCamera });
37
+ };
38
+ return () =>
39
+ h(HkNodeCanvas, { ref: canvasRef, minimap: false, onVnodeMounted: check }, { default: () => h("div") });
40
+ },
41
+ });
42
+ const el = mountToDom(Host);
43
+ expect(typeof exposed.tweenCamera).toBe("function");
44
+ el.remove();
45
+ });
46
+
47
+ it("tweenMs=0 (default) does not start an animation frame", () => {
48
+ let tweenFn: ((...a: unknown[]) => void) | null = null;
49
+ const Host = defineComponent({
50
+ setup() {
51
+ const canvasRef = ref<unknown>(null);
52
+ const check = () => {
53
+ const vm = canvasRef.value as Record<string, unknown> | null;
54
+ if (vm) tweenFn = vm.tweenCamera as (...a: unknown[]) => void;
55
+ };
56
+ return () =>
57
+ h(HkNodeCanvas, {
58
+ ref: canvasRef,
59
+ minimap: false,
60
+ fitOnLoad: false,
61
+ onVnodeMounted: check,
62
+ }, { default: () => h("div") });
63
+ },
64
+ });
65
+ const el = mountToDom(Host);
66
+ expect(tweenFn).toBeTruthy();
67
+ // Calling with default tweenMs=0 should snap (no rAF started).
68
+ tweenFn!({ k: 2, x: 100, y: 50 });
69
+ el.remove();
70
+ });
71
+ });
72
+
73
+ describe("pinchable prop", () => {
74
+ it("defaults to true", () => {
75
+ const el = mountToDom(defineComponent({
76
+ setup() {
77
+ return () => h(HkNodeCanvas, { minimap: false }, { default: () => h("div") });
78
+ },
79
+ }));
80
+ expect(el.querySelector(".hk-node-canvas")).toBeTruthy();
81
+ el.remove();
82
+ });
83
+
84
+ it("can be disabled", () => {
85
+ const el = mountToDom(defineComponent({
86
+ setup() {
87
+ return () => h(HkNodeCanvas, { minimap: false, pinchable: false }, { default: () => h("div") });
88
+ },
89
+ }));
90
+ expect(el.querySelector(".hk-node-canvas")).toBeTruthy();
91
+ el.remove();
92
+ });
93
+ });
94
+
95
+ describe("reduced motion", () => {
96
+ it("respectReducedMotion defaults to true", () => {
97
+ const el = mountToDom(defineComponent({
98
+ setup() {
99
+ return () => h(HkNodeCanvas, { minimap: false }, { default: () => h("div") });
100
+ },
101
+ }));
102
+ expect(el.querySelector(".hk-node-canvas")).toBeTruthy();
103
+ el.remove();
104
+ });
105
+ });
106
+
107
+ describe("pointerScale prop", () => {
108
+ it("accepts a pointerScale function", () => {
109
+ const el = mountToDom(defineComponent({
110
+ setup() {
111
+ return () =>
112
+ h(HkNodeCanvas, {
113
+ minimap: false,
114
+ pointerScale: () => ({ x: 2, y: 2 }),
115
+ }, { default: () => h("div") });
116
+ },
117
+ }));
118
+ expect(el.querySelector(".hk-node-canvas")).toBeTruthy();
119
+ el.remove();
120
+ });
121
+ });
122
+
123
+ describe("pinch gesture (integration)", () => {
124
+ it("two simultaneous pointers do not crash", async () => {
125
+ const Host = defineComponent({
126
+ setup() {
127
+ return () =>
128
+ h(HkNodeCanvas, {
129
+ minimap: false,
130
+ pannable: true,
131
+ pinchable: true,
132
+ }, { default: () => h("div") });
133
+ },
134
+ });
135
+ const el = mountToDom(Host);
136
+ const root = el.querySelector(".hk-node-canvas")!;
137
+ expect(root).toBeTruthy();
138
+
139
+ // Simulate two fingers down.
140
+ root.dispatchEvent(pointerEvent("pointerdown", { pointerId: 10, clientX: 100, clientY: 100 }));
141
+ root.dispatchEvent(pointerEvent("pointerdown", { pointerId: 20, clientX: 200, clientY: 100 }));
142
+ await nextTick();
143
+
144
+ // Simulate one finger moving (pinch in progress).
145
+ root.dispatchEvent(pointerEvent("pointermove", { pointerId: 20, clientX: 150, clientY: 100 }));
146
+ await nextTick();
147
+
148
+ // Release both fingers.
149
+ root.dispatchEvent(pointerEvent("pointerup", { pointerId: 10 }));
150
+ root.dispatchEvent(pointerEvent("pointerup", { pointerId: 20 }));
151
+ await nextTick();
152
+
153
+ // No crash — the component is still mounted.
154
+ expect(el.querySelector(".hk-node-canvas")).toBeTruthy();
155
+ el.remove();
156
+ });
157
+ });
158
+ });