testplane
Version:
Tests framework based on mocha and wdio
86 lines (85 loc) • 5.42 kB
TypeScript
declare const brand: unique symbol;
type Brand<T, B extends string> = T & {
readonly [brand]: B;
};
export type Space = "page" | "viewport" | "image" | "capture";
/** css are logical pixels, device are physical pixels, usually equal to <logical pixels> * <device pixel ratio> */
export type Unit = "css" | "device";
type MainAxis = "x" | "y";
type InverseAxis = "x-inverse" | "y-inverse";
type Axis = MainAxis | InverseAxis;
export type Coord<S extends Space, U extends Unit, A extends Axis> = Brand<number, `${S}:${U}:${A}`>;
export type Length<U extends Unit, A extends MainAxis> = Brand<number, `${U}:${A}:len`>;
export type Point<S extends Space, U extends Unit> = Readonly<{
top: Coord<S, U, "y">;
left: Coord<S, U, "x">;
}>;
export type Size<U extends Unit> = Readonly<{
width: Length<U, "x">;
height: Length<U, "y">;
}>;
export type Rect<S extends Space, U extends Unit> = Point<S, U> & Size<U>;
export type YBand<S extends Space, U extends Unit> = {
top: Coord<S, U, "y">;
height: Length<U, "y">;
};
export type XBand<S extends Space, U extends Unit> = {
left: Coord<S, U, "x">;
width: Length<U, "x">;
};
export declare const getSize: <U extends Unit>(rect: Rect<Space, U>) => Readonly<{
width: Length<U, "x">;
height: Length<U, "y">;
}>;
export declare const addCoords: <T extends Coord<Space, Unit, Axis>>(a: T, b: T) => T;
export declare const subtractCoords: <T extends Coord<Space, Unit, Axis>>(a: T, b: T) => T;
export declare const equalsSize: <T extends Readonly<{
width: Length<Unit, "x">;
height: Length<Unit, "y">;
}>>(a: T, b: T) => boolean;
export declare const prettyPoint: <T extends Readonly<{
top: Coord<Space, Unit, "y">;
left: Coord<Space, Unit, "x">;
}>>(point: T) => string;
export declare const prettySize: <T extends Readonly<{
width: Length<Unit, "x">;
height: Length<Unit, "y">;
}>>(size: T) => string;
export declare const prettyRect: <T extends Rect<Space, Unit>>(rect: T) => string;
export declare const intersectYBands: <T extends YBand<Space, Unit>>(a: T | null, b: T | null) => T | null;
export declare const intersectXBands: <T extends XBand<Space, Unit>>(a: T | null, b: T | null) => T | null;
export declare const getIntersection: <S extends Space, U extends Unit, A extends Rect<S, U> | YBand<S, U> | XBand<S, U>, B extends Rect<S, U> | YBand<S, U> | XBand<S, U>>(a: A | null, b: B | null) => (A & B) | null;
type GetUnit<T> = T extends Coord<Space, infer Unit, Axis> ? Unit : never;
type GetAxis<T> = T extends Coord<Space, Unit, infer Axis> ? Axis : never;
export declare const getHeight: <T extends Coord<Space, Unit, "y">>(a: T, b: T) => Length<GetUnit<T>, GetAxis<T>>;
export declare const getWidth: <T extends Coord<Space, Unit, "x">>(a: T, b: T) => Length<GetUnit<T>, GetAxis<T>>;
export declare const getBottom: <S extends Space, U extends Unit>(bandOrRect: YBand<S, U>) => Coord<S, U, "y">;
export declare const getRight: <S extends Space, U extends Unit>(bandOrRect: XBand<S, U>) => Coord<S, U, "x">;
export declare const getMaxLength: <U extends Unit, A extends MainAxis>(...lengths: Length<U, A>[]) => Length<U, A>;
export declare const getMaxCoord: <T extends Coord<Space, Unit, Axis>>(...coords: T[]) => T;
export declare const getMinCoord: <T extends Coord<Space, Unit, Axis>>(...coords: T[]) => T;
export declare const fromCaptureAreaToViewport: <U extends Unit>(coordRelativeToCaptureArea: Coord<"capture", U, "y">, captureAreaTopRelativeToViewport: Coord<"viewport", U, "y">) => Coord<"viewport", U, "y">;
export declare const fromViewportToCaptureArea: <U extends Unit>(coordRelativeToViewport: Coord<"viewport", U, "y">, captureAreaTopRelativeToViewport: Coord<"viewport", U, "y">) => Coord<"capture", U, "y">;
export declare const getCoveringRect: <T extends Rect<Space, Unit>>(rects: T[]) => T;
type NumericShape = Rect<Space, Unit> | YBand<Space, Unit> | XBand<Space, Unit> | Size<Unit> | Point<Space, Unit>;
export declare const roundCoords: <T extends NumericShape>(value: T) => T;
export declare const floorCoords: <T extends NumericShape>(value: T) => T;
export declare const ceilCoords: <T extends NumericShape>(value: T) => T;
type CssToDevice<T> = T extends Rect<infer S, "css"> ? Rect<S, "device"> : T extends YBand<infer S, "css"> ? YBand<S, "device"> : T extends XBand<infer S, "css"> ? XBand<S, "device"> : T extends Size<"css"> ? Size<"device"> : T extends Point<infer S, "css"> ? Point<S, "device"> : never;
export declare const fromCssToDevice: <T extends Readonly<{
width: Length<"css", "x">;
height: Length<"css", "y">;
}> | Readonly<{
top: Coord<Space, "css", "y">;
left: Coord<Space, "css", "x">;
}> | Rect<Space, "css"> | YBand<Space, "css"> | XBand<Space, "css">>(value: T, pixelRatio: number) => CssToDevice<T>;
export declare const fromCssToDeviceNumber: {
<S extends Space, U extends Unit, A extends Axis>(value: Coord<S, U, A>, pixelRatio: number): Coord<S, "device", A>;
<U extends Unit, A extends MainAxis>(value: Length<U, A>, pixelRatio: number): Length<"device", A>;
};
export declare const fromDeviceToCssNumber: {
<S extends Space, U extends Unit, A extends Axis>(value: Coord<S, U, A>, pixelRatio: number): Coord<S, "css", A>;
<U extends Unit, A extends MainAxis>(value: Length<U, A>, pixelRatio: number): Length<"css", A>;
};
export declare const fromBcrToRect: (bcr: DOMRect) => Rect<"viewport", "css">;
export {};