mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Generated svg-intersections files using npx * Added base typings for shape method with conditional second argument type * Added missing types in SvgProperties * Added basic Shape interface * Added types for intersect function * Refactored intersection to interface and added typings to Matrix2D * Linted index.d.ts * Added line test * Added tests for rect, circle, ellipse & polygon * Added test for path * Rectangle rx&ry should be optional * Added intersections test * Replaced unnecessary typeof with generic type
86 lines
1.8 KiB
TypeScript
86 lines
1.8 KiB
TypeScript
// Type definitions for svg-intersections 0.4
|
|
// Project: https://github.com/effektif/svg-intersections#readme
|
|
// Definitions by: xWiiLLz <https://github.com/xWiiLLz>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
// TypeScript Version: 2.8
|
|
|
|
export type SvgElements = 'line' | 'rect' | 'circle' | 'ellipse' | 'polygon' | 'polyline' | 'path';
|
|
|
|
// Svg element properties
|
|
export interface LineProps {
|
|
x1: number;
|
|
y1: number;
|
|
x2: number;
|
|
y2: number;
|
|
}
|
|
|
|
export interface RectProps {
|
|
rx?: number;
|
|
ry?: number;
|
|
x: number;
|
|
y: number;
|
|
width: number;
|
|
height: number;
|
|
}
|
|
|
|
export interface CircleProps {
|
|
cx: number;
|
|
cy: number;
|
|
r: number;
|
|
}
|
|
|
|
export interface EllipseProps {
|
|
cx: number;
|
|
cy: number;
|
|
rx: number;
|
|
ry: number;
|
|
}
|
|
|
|
export interface PolygonProps {
|
|
points: string;
|
|
}
|
|
|
|
export type PolylineProps = PolygonProps;
|
|
|
|
export interface PathProps {
|
|
d: string;
|
|
}
|
|
|
|
export type SvgProperties<T extends SvgElements> =
|
|
T extends 'line' ? LineProps :
|
|
T extends 'rect' ? RectProps :
|
|
T extends 'circle' ? CircleProps :
|
|
T extends 'ellipse' ? EllipseProps :
|
|
T extends 'polygon' ? PolygonProps :
|
|
T extends 'polyline' ? PolylineProps :
|
|
T extends 'path' ? PathProps :
|
|
never;
|
|
|
|
export interface Shape {
|
|
type: string;
|
|
meta: object;
|
|
params: object;
|
|
}
|
|
|
|
export interface Matrix2D {
|
|
a: number;
|
|
b: number;
|
|
c: number;
|
|
d: number;
|
|
e: number;
|
|
f: number;
|
|
}
|
|
|
|
export interface Point2D {
|
|
x: number;
|
|
y: number;
|
|
}
|
|
|
|
export interface Intersection {
|
|
status: string;
|
|
points: Point2D[];
|
|
}
|
|
|
|
export function shape<T extends SvgElements>(svgElementName: T, svgProps: SvgProperties<T>): Shape;
|
|
export function intersect(shape1: Shape, shape2: Shape, m1?: Matrix2D, m2?: Matrix2D): Intersection;
|