mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
Added types for svg-intersections (#39899)
* 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
This commit is contained in:
parent
13e6949a02
commit
eb680b04ff
85
types/svg-intersections/index.d.ts
vendored
Normal file
85
types/svg-intersections/index.d.ts
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
// 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;
|
||||
11
types/svg-intersections/svg-intersections-tests.ts
Normal file
11
types/svg-intersections/svg-intersections-tests.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { intersect, shape } from 'svg-intersections';
|
||||
|
||||
const line = shape('line', {x1: 0, y1: 0, x2: 2, y2: 3});
|
||||
const rect = shape('rect', {x: 0, y: 0, width: 200, height: 100});
|
||||
const rectWithOptional = shape('rect', {x: 0, y: 0, width: 200, height: 100, rx: 4, ry: 4});
|
||||
const circle = shape('circle', {cx: 0, cy: 0, r: 100});
|
||||
const ellipse = shape('ellipse', {rx: 100, ry: 150, cx: 0, cy: 0});
|
||||
const polygon = shape('polygon', {points: '-5,0 0,10 5,0 0,-10'});
|
||||
const path = shape('path', {d: 'M 10 10 h 80 v 80 h -80 Z'});
|
||||
|
||||
const intersections = intersect(line, rect);
|
||||
23
types/svg-intersections/tsconfig.json
Normal file
23
types/svg-intersections/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"svg-intersections-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/svg-intersections/tslint.json
Normal file
1
types/svg-intersections/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user