Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

figma like infinite canvas cursor

Sultan06df7d234792
diff --git a/app/shared/design-system/components/primitives/numericGestureControl.js b/app/shared/design-system/components/primitives/numericGestureControl.js
index a397ddc9ee..c2ac0c1b7c 100644
--- a/app/shared/design-system/components/primitives/numericGestureControl.js
+++ b/app/shared/design-system/components/primitives/numericGestureControl.js
@@ -19,40 +19,63 @@ export const numericGestureControl = (
) => {
const eventNames = ["pointerup", "pointerdown", "pointermove"];
const state = {
- type: "",
value: initialValue,
- cursor: direction === "horizontal" ? "ew-resize" : "ns-resize",
+ offset: 0,
+ direction: direction === "horizontal" ? "ew-resize" : "ns-resize",
+ cursor: cursorNode.cloneNode(true),
};
const handleEvent = ({
type,
target,
+ offsetX,
+ offsetY,
movementY,
movementX,
pointerId,
pressure,
+ x,
+ y,
}) => {
+ const offset = direction === "horizontal" ? offsetX : offsetY;
const movement = direction === "horizontal" ? movementX : -movementY;
+ const position = direction === "horizontal" ? "left" : "top";
switch (type) {
case "pointerup": {
- targetNode.releasePointerCapture(pointerId);
+ state.offset = 0;
+ targetNode.ownerDocument.exitPointerLock(pointerId);
+ state.cursor.remove();
break;
}
case "pointerdown": {
- targetNode.setPointerCapture(pointerId);
+ state.offset = offset;
+ state.cursor.style.position = "absolute";
+ state.cursor.style.top = `${offsetY}px`;
+ state.cursor.style.left = `${offsetX}px`;
+ targetNode.requestPointerLock();
+ targetNode.ownerDocument.documentElement.append(state.cursor);
break;
}
case "pointermove": {
- if (pressure)
+ if (pressure) {
+ if (state.offset < 0) {
+ state.offset = globalThis.innerWidth + 1;
+ } else if (state.offset > globalThis.innerWidth) {
+ state.offset = 1;
+ }
+ state.value += movement;
+ state.offset += movement;
+ state.cursor.style[position] = `${state.offset}px`;
onValueChange({
target,
- value: (state.value += movement),
+ value: state.value,
preventDefault: () => event.preventDefault(),
});
+ }
break;
}
}
};
- targetNode.style.setProperty("cursor", state.cursor);
+ targetNode.style.setProperty("cursor", state.direction);
eventNames.forEach((eventName) =>
targetNode.addEventListener(eventName, handleEvent)
);
@@ -65,3 +88,12 @@ export const numericGestureControl = (
},
};
};
+
+const cursorNode = new Range().createContextualFragment(`
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="46" height="15">
+ <g transform="translate(2 3)">
+ <path fill-rule="evenodd" d="M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z"></path>
+ <path fill-rule="evenodd" d="M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z"></path>
+ </g>
+ </svg>
+`).firstElementChild;