MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / PagePinching

Class PagePinching

apps/client/src/code/pages/page/camera/pinching.ts:13–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13export class PagePinching {
14 readonly page: Page;
15
16 readonly react: UnwrapNestedRefs<IPinchingReact>;
17
18 displayCenterPos!: Vec2;
19 displayDistance!: number;
20
21 unwatchActive?: WatchStopHandle;
22
23 constructor(input: { page: Page }) {
24 this.page = input.page;
25
26 this.react = reactive({
27 pointers: {},
28
29 active: computed(() => {
30 return Object.keys(this.react.pointers).length >= 2;
31 }),
32 });
33
34 this.unwatchActive = watch(
35 () => this.react.active,
36 () => {
37 if (this.react.active) {
38 this.page.panning.cancel();
39 this.page.dragging.cancel();
40 this.page.boxSelection.cancel();
41
42 this.page.selection.clear();
43
44 const { displayCenterPos, displayDistance } =
45 this._getCenterAndDistance();
46
47 this.displayCenterPos = displayCenterPos;
48 this.displayDistance = displayDistance;
49
50 document.addEventListener('pointermove', this._update);
51 } else {
52 document.removeEventListener('pointermove', this._update);
53 }
54 },
55 );
56 }
57
58 destroy() {
59 this.unwatchActive?.();
60 }
61
62 private _getCenterAndDistance() {
63 const pointers = Object.values(this.react.pointers);
64
65 const displayCenterPos = pointers[0].lerp(pointers[1], 0.5);
66 const displayDistance = pointers[0].sub(pointers[1]).length();
67
68 return { displayCenterPos, displayDistance };
69 }
70

Callers

nothing calls this directly

Calls 5

_getCenterAndDistanceMethod · 0.95
screenToWorld2DMethod · 0.80
subMethod · 0.80
fixDisplayMethod · 0.80
displayToWorldMethod · 0.45

Tested by

no test coverage detected