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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
numeric gesture fix for light pressure touches, improvements and cursor offset
Sultan37d5d43f82a9
diff --git a/packages/design-system/src/components/primitives/numeric-gesture-control.ts b/packages/design-system/src/components/primitives/numeric-gesture-control.tsindex befb8ddcd4..c7433069ab 100644--- a/packages/design-system/src/components/primitives/numeric-gesture-control.ts+++ b/packages/design-system/src/components/primitives/numeric-gesture-control.ts@@ -18,16 +18,19 @@ export type NumericScrubDirection = "horizontal" | "vertical";export type NumericScrubValue = number;+export type NumericScrubCallback = (event: {+ target: HTMLElement;+ value: NumericScrubValue;+ preventDefault: () => void;+}) => void;+export type NumericScrubOptions = {minValue?: NumericScrubValue;maxValue?: NumericScrubValue;initialValue?: NumericScrubValue;direction?: NumericScrubDirection;- onValueChange?: (event: {- target: HTMLElement;- value: NumericScrubValue;- preventDefault: () => void;- }) => void;+ onValueInput?: NumericScrubCallback;+ onValueChange?: NumericScrubCallback;};type NumericScrubState = {@@ -45,6 +48,7 @@ export const numericScrubControl = (maxValue = Number.MAX_SAFE_INTEGER,initialValue = 0,direction = "horizontal",+ onValueInput = () => null,onValueChange = () => null,}: NumericScrubOptions) => {@@ -78,9 +82,16 @@ export const numericScrubControl = (state.offset = 0;handleCursor(targetNode.ownerDocument.documentElement, false);exitPointerLock(state, event, targetNode);+ onValueChange({+ target: targetNode,+ value: state.value,+ preventDefault: () => event.preventDefault(),+ });break;}case "pointerdown": {+ // light touches don't register corresponding pointerup+ if (event.pressure === 0) break;state.offset = offset;handleCursor(targetNode.ownerDocument.documentElement, true);requestPointerLock(state, event, targetNode);@@ -94,7 +105,7 @@ export const numericScrubControl = (if (state.value < minValue) state.value = minValue;else if (state.value > maxValue) state.value = maxValue;state.offset += movement * state.velocity;- onValueChange({+ onValueInput({target: targetNode,value: state.value,preventDefault: () => event.preventDefault(),@@ -143,9 +154,11 @@ const requestPointerLock = (cursorNode.style.filter = `drop-shadow(${state.direction === "horizontal" ? "0 1px" : "1px 0"} 1.1px rgba(0,0,0,.4))`;+ // avoid obscuring anything that could be behind the cursor by offseting it after the target+ const { top, height } = targetNode.getBoundingClientRect();cursorNode.style.position = "absolute";cursorNode.style.left = `${event.clientX}px`;- cursorNode.style.top = `${event.clientY}px`;+ cursorNode.style.top = `${top + height}px`;cursorNode.style.transform = `translate(-50%, -50%) ${state.direction === "horizontal" ? "rotate(0deg)" : "rotate(90deg)"}`;