@zag-js/dom-utils
Advanced tools
Comparing version 0.0.0-dev-20221229205502 to 0.0.0-dev-20230101161254
@@ -9,3 +9,11 @@ type Point = { | ||
}; | ||
declare function getPointPercentRelativeToNode(point: Point, element: HTMLElement): { | ||
x: number; | ||
y: number; | ||
}; | ||
declare function normalizePointValue(point: Point, options: { | ||
dir?: "ltr" | "rtl"; | ||
orientation?: "vertical" | "horizontal"; | ||
}): number; | ||
export { getPointRelativeToNode }; | ||
export { getPointPercentRelativeToNode, getPointRelativeToNode, normalizePointValue }; |
@@ -23,3 +23,5 @@ "use strict"; | ||
__export(get_point_relative_to_element_exports, { | ||
getPointRelativeToNode: () => getPointRelativeToNode | ||
getPointPercentRelativeToNode: () => getPointPercentRelativeToNode, | ||
getPointRelativeToNode: () => getPointRelativeToNode, | ||
normalizePointValue: () => normalizePointValue | ||
}); | ||
@@ -59,5 +61,23 @@ module.exports = __toCommonJS(get_point_relative_to_element_exports); | ||
} | ||
var clampPercent = (value) => Math.max(0, Math.min(100, value)); | ||
function getPointPercentRelativeToNode(point, element) { | ||
const pt = getPointRelativeToNode(point, element); | ||
const x = pt.x / element.offsetWidth * 100; | ||
const y = pt.y / element.offsetHeight * 100; | ||
return { x: clampPercent(x), y: clampPercent(y) }; | ||
} | ||
function normalizePointValue(point, options) { | ||
const { dir = "ltr", orientation = "horizontal" } = options; | ||
const { x, y } = point; | ||
let result = { x, y }; | ||
if (orientation === "horizontal" && dir === "rtl") { | ||
result = { x: 100 - x, y }; | ||
} | ||
return orientation === "horizontal" ? result.x : result.y; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
getPointRelativeToNode | ||
getPointPercentRelativeToNode, | ||
getPointRelativeToNode, | ||
normalizePointValue | ||
}); |
@@ -10,3 +10,3 @@ export { ariaAttr, dataAttr, matchAttr } from './attrs.js'; | ||
export { getEventPoint } from './get-event-point.js'; | ||
export { getPointRelativeToNode } from './get-point-relative-to-element.js'; | ||
export { getPointPercentRelativeToNode, getPointRelativeToNode, normalizePointValue } from './get-point-relative-to-element.js'; | ||
export { EventKeyMap, getEventKey, getEventStep } from './keyboard-event.js'; | ||
@@ -13,0 +13,0 @@ export { addDomEvent, addPointerEvent, extractClientInfo, extractInfo, getEventName } from './listener.js'; |
@@ -66,2 +66,3 @@ "use strict"; | ||
getPlatform: () => getPlatform, | ||
getPointPercentRelativeToNode: () => getPointPercentRelativeToNode, | ||
getPointRelativeToNode: () => getPointRelativeToNode, | ||
@@ -111,2 +112,3 @@ getRootNode: () => getRootNode, | ||
nextTick: () => nextTick, | ||
normalizePointValue: () => normalizePointValue, | ||
observeAttributes: () => observeAttributes, | ||
@@ -532,2 +534,18 @@ observeChildren: () => observeChildren, | ||
} | ||
var clampPercent = (value) => Math.max(0, Math.min(100, value)); | ||
function getPointPercentRelativeToNode(point, element) { | ||
const pt2 = getPointRelativeToNode(point, element); | ||
const x = pt2.x / element.offsetWidth * 100; | ||
const y = pt2.y / element.offsetHeight * 100; | ||
return { x: clampPercent(x), y: clampPercent(y) }; | ||
} | ||
function normalizePointValue(point, options) { | ||
const { dir = "ltr", orientation = "horizontal" } = options; | ||
const { x, y } = point; | ||
let result = { x, y }; | ||
if (orientation === "horizontal" && dir === "rtl") { | ||
result = { x: 100 - x, y }; | ||
} | ||
return orientation === "horizontal" ? result.x : result.y; | ||
} | ||
@@ -1140,2 +1158,3 @@ // src/keyboard-event.ts | ||
getPlatform, | ||
getPointPercentRelativeToNode, | ||
getPointRelativeToNode, | ||
@@ -1185,2 +1204,3 @@ getRootNode, | ||
nextTick, | ||
normalizePointValue, | ||
observeAttributes, | ||
@@ -1187,0 +1207,0 @@ observeChildren, |
{ | ||
"name": "@zag-js/dom-utils", | ||
"version": "0.0.0-dev-20221229205502", | ||
"version": "0.0.0-dev-20230101161254", | ||
"description": "", | ||
@@ -25,7 +25,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/types": "0.0.0-dev-20221229205502" | ||
"@zag-js/types": "0.3.2" | ||
}, | ||
"devDependencies": { | ||
"clean-package": "2.2.0", | ||
"@zag-js/utils": "0.0.0-dev-20221229205502" | ||
"@zag-js/utils": "0.3.2" | ||
}, | ||
@@ -32,0 +32,0 @@ "clean-package": "../../../clean-package.config.json", |
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
186276
5727
+ Added@zag-js/types@0.3.2(transitive)
- Removed@zag-js/types@0.0.0-dev-20221229205502(transitive)
Updated@zag-js/types@0.3.2