@zag-js/rect-utils
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -1,16 +0,186 @@ | ||
export * from "./align"; | ||
export * from "./closest"; | ||
export * from "./contains"; | ||
export * from "./distance"; | ||
export * from "./from-element"; | ||
export * from "./from-points"; | ||
export * from "./from-range"; | ||
export * from "./from-rotation"; | ||
export * from "./from-window"; | ||
export * from "./get-polygon"; | ||
export * from "./intersection"; | ||
export * from "./operations"; | ||
export * from "./polygon"; | ||
export * from "./rect"; | ||
export * from "./types"; | ||
export * from "./union"; | ||
declare type Point = { | ||
x: number; | ||
y: number; | ||
}; | ||
declare type RectValue = { | ||
x: number; | ||
y: number; | ||
width: number; | ||
height: number; | ||
}; | ||
declare type RectSide = "top" | "right" | "bottom" | "left"; | ||
declare type RectPoint = "top-left" | "top-center" | "top-right" | "right-center" | "left-center" | "bottom-left" | "bottom-right" | "bottom-center" | "center"; | ||
declare type RectEdge = [Point, Point]; | ||
declare type RectPoints = [Point, Point, Point, Point]; | ||
declare type RectEdges = Record<RectSide, RectEdge> & { | ||
value: RectEdge[]; | ||
}; | ||
declare type RectCorner = "topLeft" | "topRight" | "bottomLeft" | "bottomRight"; | ||
declare type RectCorners = Record<RectCorner, Point> & { | ||
value: RectPoints; | ||
}; | ||
declare type RectCenter = "topCenter" | "rightCenter" | "leftCenter" | "bottomCenter"; | ||
declare type RectCenters = Record<RectCenter, Point> & { | ||
value: RectPoints; | ||
}; | ||
declare type RectInset = Partial<Record<RectSide, number>>; | ||
declare type SymmetricRectInset = { | ||
dx?: number; | ||
dy?: number; | ||
}; | ||
declare function createRect(r: RectValue): { | ||
x: number; | ||
y: number; | ||
width: number; | ||
height: number; | ||
minX: number; | ||
minY: number; | ||
maxX: number; | ||
maxY: number; | ||
midX: number; | ||
midY: number; | ||
center: { | ||
x: number; | ||
y: number; | ||
}; | ||
}; | ||
declare type Rect = ReturnType<typeof createRect>; | ||
declare function isRect(v: any): v is Rect; | ||
declare function getRectCenters(v: Rect): { | ||
top: { | ||
x: number; | ||
y: number; | ||
}; | ||
right: { | ||
x: number; | ||
y: number; | ||
}; | ||
bottom: { | ||
x: number; | ||
y: number; | ||
}; | ||
left: { | ||
x: number; | ||
y: number; | ||
}; | ||
}; | ||
declare function getRectCorners(v: Rect): { | ||
top: { | ||
x: number; | ||
y: number; | ||
}; | ||
right: { | ||
x: number; | ||
y: number; | ||
}; | ||
bottom: { | ||
x: number; | ||
y: number; | ||
}; | ||
left: { | ||
x: number; | ||
y: number; | ||
}; | ||
}; | ||
declare function getRectEdges(v: Rect): { | ||
top: RectEdge; | ||
right: RectEdge; | ||
bottom: RectEdge; | ||
left: RectEdge; | ||
}; | ||
declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect; | ||
declare type AlignOptions = { | ||
h: HAlign; | ||
v: VAlign; | ||
}; | ||
declare type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside"; | ||
declare type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside"; | ||
declare function closest(...pts: Point[]): (a: Point) => Point; | ||
declare function closestSideToRect(ref: Rect, r: Rect): RectSide; | ||
declare function closestSideToPoint(ref: Rect, p: Point): RectSide; | ||
declare function containsPoint(r: Rect, p: Point): boolean; | ||
declare function containsRect(a: Rect, b: Rect): boolean; | ||
declare function contains(r: Rect, v: Rect | Point): boolean; | ||
declare type DistanceValue = Point & { | ||
value: number; | ||
}; | ||
declare function distance(a: Point, b?: Point): number; | ||
declare function distanceFromPoint(r: Rect, p: Point): DistanceValue; | ||
declare function distanceFromRect(a: Rect, b: Rect): DistanceValue; | ||
declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>; | ||
declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect; | ||
declare type ElementRectOptions = { | ||
/** | ||
* Whether to exclude the element's scrollbar size from the calculation. | ||
*/ | ||
excludeScrollbar?: boolean; | ||
/** | ||
* Whether to exclude the element's borders from the calculation. | ||
*/ | ||
excludeBorders?: boolean; | ||
}; | ||
declare function getRectFromPoints(...pts: Point[]): Rect; | ||
declare function fromRange(range: Range): Rect; | ||
declare function toRad(d: number): number; | ||
declare function rotate(a: Point, d: number, c: Point): Point; | ||
declare function getRotationRect(r: Rect, deg: number): Rect; | ||
declare type WindowRectOptions = { | ||
/** | ||
* Whether to exclude the element's scrollbar size from the calculation. | ||
*/ | ||
excludeScrollbar?: boolean; | ||
}; | ||
/** | ||
* Creates a rectange from window object | ||
*/ | ||
declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect; | ||
/** | ||
* Get the rect of the window with the option to exclude the scrollbar | ||
*/ | ||
declare function getViewportRect(win: Window, opts: WindowRectOptions): { | ||
x: number; | ||
y: number; | ||
width: number; | ||
height: number; | ||
}; | ||
declare function getElementPolygon(rectValue: RectValue, placement: string): { | ||
x: number; | ||
y: number; | ||
}[] | undefined; | ||
/** | ||
* Checks if a Rect intersects another Rect | ||
*/ | ||
declare function intersects(a: Rect, b: Rect): boolean; | ||
/** | ||
* Returns a new Rect that represents the intersection between two Rects | ||
*/ | ||
declare function intersection(a: Rect, b: Rect): Rect; | ||
/** | ||
* Returns whether two rects collide along each edge | ||
*/ | ||
declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>; | ||
declare const isSymmetric: (v: any) => v is SymmetricRectInset; | ||
declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect; | ||
declare function expand(r: Rect, v: number | SymmetricRectInset): Rect; | ||
declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect; | ||
declare function shift(r: Rect, o: Partial<Point>): Rect; | ||
declare function isPointInPolygon(polygon: Point[], point: Point): boolean; | ||
declare function debugPolygon(polygon: Point[]): () => void; | ||
declare function union(...rs: Rect[]): Rect; | ||
export { AlignOptions, DistanceValue, ElementRectOptions, HAlign, Point, Rect, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInset, RectPoint, RectPoints, RectSide, RectValue, SymmetricRectInset, VAlign, WindowRectOptions, alignRect, closest, closestSideToPoint, closestSideToRect, collisions, contains, containsPoint, containsRect, createRect, debugPolygon, distance, distanceBtwEdges, distanceFromPoint, distanceFromRect, expand, fromRange, getElementPolygon, getElementRect, getRectCenters, getRectCorners, getRectEdges, getRectFromPoints, getRotationRect, getViewportRect, getWindowRect, inset, intersection, intersects, isPointInPolygon, isRect, isSymmetric, rotate, shift, shrink, toRad, union }; |
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
var __export = (target, all) => { | ||
@@ -97,3 +80,3 @@ for (var name in all) | ||
} | ||
return __spreadProps(__spreadValues({}, a), { x }); | ||
return { ...a, x }; | ||
} | ||
@@ -117,3 +100,3 @@ function vAlign(a, ref, v) { | ||
} | ||
return __spreadProps(__spreadValues({}, a), { y }); | ||
return { ...a, y }; | ||
} | ||
@@ -296,3 +279,2 @@ function alignRect(a, ref, options) { | ||
function getComputedStyle(el) { | ||
var _a; | ||
if (!el) | ||
@@ -303,3 +285,3 @@ return {}; | ||
if (!style) { | ||
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
const win = (el == null ? void 0 : el.ownerDocument.defaultView) ?? window; | ||
style = win.getComputedStyle(el); | ||
@@ -379,3 +361,3 @@ cache.set(el, style); | ||
const r = getElementRect(start); | ||
rs.push(__spreadProps(__spreadValues({}, r), { x: r.maxX, width: 0 })); | ||
rs.push({ ...r, x: r.maxX, width: 0 }); | ||
} | ||
@@ -525,1 +507,40 @@ return union.apply(void 0, rs); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
alignRect, | ||
closest, | ||
closestSideToPoint, | ||
closestSideToRect, | ||
collisions, | ||
contains, | ||
containsPoint, | ||
containsRect, | ||
createRect, | ||
debugPolygon, | ||
distance, | ||
distanceBtwEdges, | ||
distanceFromPoint, | ||
distanceFromRect, | ||
expand, | ||
fromRange, | ||
getElementPolygon, | ||
getElementRect, | ||
getRectCenters, | ||
getRectCorners, | ||
getRectEdges, | ||
getRectFromPoints, | ||
getRotationRect, | ||
getViewportRect, | ||
getWindowRect, | ||
inset, | ||
intersection, | ||
intersects, | ||
isPointInPolygon, | ||
isRect, | ||
isSymmetric, | ||
rotate, | ||
shift, | ||
shrink, | ||
toRad, | ||
union | ||
}); |
{ | ||
"name": "@zag-js/rect-utils", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "", | ||
@@ -27,15 +27,16 @@ "keywords": [ | ||
}, | ||
"dependencies": { | ||
"@zag-js/dom-utils": "0.1.7", | ||
"@zag-js/utils": "0.1.2" | ||
"devDependencies": { | ||
"@zag-js/dom-utils": "0.1.8", | ||
"@zag-js/utils": "0.1.3" | ||
}, | ||
"scripts": { | ||
"build:fast": "zag build", | ||
"start": "zag build --watch", | ||
"build": "zag build --prod", | ||
"build-fast": "tsup src/index.ts --format=esm,cjs", | ||
"start": "pnpm build --watch", | ||
"build": "tsup src/index.ts --format=esm,cjs --dts", | ||
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests", | ||
"lint": "eslint src --ext .ts,.tsx", | ||
"test:ci": "yarn test --ci --runInBand", | ||
"test:watch": "yarn test --watch --updateSnapshot" | ||
"test-ci": "pnpm test --ci --runInBand", | ||
"test-watch": "pnpm test --watch -u", | ||
"typecheck": "tsc --noEmit" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
0
34940
2
6
1156
- Removed@zag-js/dom-utils@0.1.7
- Removed@zag-js/utils@0.1.2
- Removed@zag-js/dom-utils@0.1.7(transitive)
- Removed@zag-js/types@0.2.2(transitive)
- Removed@zag-js/utils@0.1.2(transitive)
- Removedcsstype@3.1.0(transitive)