@zag-js/dom-event
Advanced tools
Comparing version 0.0.0-dev-20230516112932 to 0.0.0-dev-20230517120057
@@ -30,2 +30,3 @@ "use strict"; | ||
let el = element; | ||
const win = element.ownerDocument.defaultView || window; | ||
if (el.parentNode) { | ||
@@ -44,4 +45,4 @@ do { | ||
top, | ||
right: innerWidth - left - element.offsetWidth, | ||
bottom: innerHeight - top - element.offsetHeight, | ||
right: win.innerWidth - left - element.offsetWidth, | ||
bottom: win.innerHeight - top - element.offsetHeight, | ||
left | ||
@@ -48,0 +49,0 @@ }; |
@@ -5,5 +5,6 @@ export { addDomEvent } from './add-dom-event.js'; | ||
export { getEventKey } from './get-event-key.js'; | ||
export { getEventPoint } from './get-event-point.js'; | ||
export { getEventStep } from './get-event-step.js'; | ||
export { getNativeEvent } from './get-native-event.js'; | ||
export { getRelativePointPercent, getRelativePointValue } from './point-value.js'; | ||
export { getRelativePointPercent, getRelativePointValue } from './get-point-value.js'; | ||
export { requestPointerLock } from './request-pointer-lock.js'; | ||
@@ -10,0 +11,0 @@ export { trackPointerMove } from './track-pointer-move.js'; |
@@ -27,2 +27,3 @@ "use strict"; | ||
getEventKey: () => getEventKey, | ||
getEventPoint: () => getEventPoint, | ||
getEventStep: () => getEventStep, | ||
@@ -120,2 +121,15 @@ getNativeEvent: () => getNativeEvent, | ||
// src/get-event-point.ts | ||
function pointFromTouch(e, type = "page") { | ||
const point = e.touches[0] || e.changedTouches[0]; | ||
return { x: point[`${type}X`], y: point[`${type}Y`] }; | ||
} | ||
function pointFromMouse(point, type = "page") { | ||
return { x: point[`${type}X`], y: point[`${type}Y`] }; | ||
} | ||
var isTouchEvent = (event) => "touches" in event && event.touches.length > 0; | ||
function getEventPoint(event, type = "page") { | ||
return isTouchEvent(event) ? pointFromTouch(event, type) : pointFromMouse(event, type); | ||
} | ||
// src/get-event-step.ts | ||
@@ -144,2 +158,3 @@ var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]); | ||
let el = element; | ||
const win = element.ownerDocument.defaultView || window; | ||
if (el.parentNode) { | ||
@@ -158,4 +173,4 @@ do { | ||
top, | ||
right: innerWidth - left - element.offsetWidth, | ||
bottom: innerHeight - top - element.offsetHeight, | ||
right: win.innerWidth - left - element.offsetWidth, | ||
bottom: win.innerHeight - top - element.offsetHeight, | ||
left | ||
@@ -165,3 +180,3 @@ }; | ||
// src/point-value.ts | ||
// src/get-point-value.ts | ||
var clamp = (value) => Math.max(0, Math.min(1, value)); | ||
@@ -232,5 +247,4 @@ function getRelativePointValue(absolutePoint, element) { | ||
const handleMove = (event) => { | ||
const x = event.clientX; | ||
const y = event.clientY; | ||
const distance = Math.sqrt(x ** 2 + y ** 2); | ||
const point = getEventPoint(event); | ||
const distance = Math.sqrt(point.x ** 2 + point.y ** 2); | ||
const moveBuffer = event.pointerType === "touch" ? 10 : 5; | ||
@@ -243,3 +257,3 @@ if (distance < moveBuffer) | ||
} | ||
onPointerMove({ point: { x, y }, event }); | ||
onPointerMove({ point, event }); | ||
}; | ||
@@ -279,2 +293,3 @@ const cleanups = [ | ||
getEventKey, | ||
getEventPoint, | ||
getEventStep, | ||
@@ -281,0 +296,0 @@ getNativeEvent, |
@@ -37,2 +37,15 @@ "use strict"; | ||
// src/get-event-point.ts | ||
function pointFromTouch(e, type = "page") { | ||
const point = e.touches[0] || e.changedTouches[0]; | ||
return { x: point[`${type}X`], y: point[`${type}Y`] }; | ||
} | ||
function pointFromMouse(point, type = "page") { | ||
return { x: point[`${type}X`], y: point[`${type}Y`] }; | ||
} | ||
var isTouchEvent = (event) => "touches" in event && event.touches.length > 0; | ||
function getEventPoint(event, type = "page") { | ||
return isTouchEvent(event) ? pointFromTouch(event, type) : pointFromMouse(event, type); | ||
} | ||
// src/track-pointer-move.ts | ||
@@ -42,5 +55,4 @@ function trackPointerMove(doc, handlers) { | ||
const handleMove = (event) => { | ||
const x = event.clientX; | ||
const y = event.clientY; | ||
const distance = Math.sqrt(x ** 2 + y ** 2); | ||
const point = getEventPoint(event); | ||
const distance = Math.sqrt(point.x ** 2 + point.y ** 2); | ||
const moveBuffer = event.pointerType === "touch" ? 10 : 5; | ||
@@ -53,3 +65,3 @@ if (distance < moveBuffer) | ||
} | ||
onPointerMove({ point: { x, y }, event }); | ||
onPointerMove({ point, event }); | ||
}; | ||
@@ -56,0 +68,0 @@ const cleanups = [ |
{ | ||
"name": "@zag-js/dom-event", | ||
"version": "0.0.0-dev-20230516112932", | ||
"version": "0.0.0-dev-20230517120057", | ||
"description": "", | ||
@@ -27,4 +27,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/types": "0.0.0-dev-20230516112932", | ||
"@zag-js/text-selection": "0.0.0-dev-20230516112932" | ||
"@zag-js/types": "0.0.0-dev-20230517120057", | ||
"@zag-js/text-selection": "0.0.0-dev-20230517120057" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51333
57
1492
+ Added@zag-js/dom-query@0.0.0-dev-20230517120057(transitive)
+ Added@zag-js/text-selection@0.0.0-dev-20230517120057(transitive)
+ Added@zag-js/types@0.0.0-dev-20230517120057(transitive)
- Removed@zag-js/dom-query@0.0.0-dev-20230516112932(transitive)
- Removed@zag-js/text-selection@0.0.0-dev-20230516112932(transitive)
- Removed@zag-js/types@0.0.0-dev-20230516112932(transitive)