-
Notifications
You must be signed in to change notification settings - Fork 1
/
addBackgroundInteraction.js
48 lines (39 loc) · 1.06 KB
/
addBackgroundInteraction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { createListener } from "./utils.js";
import { html, render } from "lit-html";
function contextView(x, y) {
return html`<input
id="context-box"
type="text"
placeholder="search..."
style="
--x:${x}px;
--y:${y}px;" />`;
}
export async function addBackgroundInteraction(svgBackground, state) {
const listen = createListener(svgBackground);
let down, dy, dx;
let ctxContainer = document.getElementById("context-box-container");
listen("pointerdown", "#svg-layer", (e) => {
down = true;
dy = 0;
dx = 0;
});
listen("pointermove", "#svg-layer", (e) => {
if (!down) return;
dx += e.movementX;
dy += e.movementY;
});
listen("pointerup", "#svg-layer", (e) => {
down = false;
if (Math.abs(dy) < 5 && Math.abs(dx) < 5) {
state.selection.clear();
}
});
listen("contextmenu", "#svg-layer", (e) => {
e.preventDefault();
if (state.toolchain.pipes["loose"]) {
delete state.toolchain.pipes["loose"];
}
// render(contextView(e.offsetX, e.offsetY), ctxContainer);
});
}