@obliczeniowo/elementary
Version:
Library made in Angular version 20
330 lines (315 loc) • 11.5 kB
TypeScript
/** means string that can be represented as any html css style color */
type HtmlColor = string;
/** only #ffffff like colors as string representation */
type HexColor = string;
interface Color {
hex: HexColor;
html: HtmlColor;
}
type ColorType = string | Color;
declare class ColorRGB {
private r;
private g;
private b;
protected a: number;
/**
* Calculate color with linear interpolation using factor parameter
*/
static proportionalColor(firstColor: ColorRGB, secondColor: ColorRGB, factor: number): ColorRGB;
static fromHex(hexColor: string): ColorRGB;
static fromHtmlColor(htmlColor: string): ColorRGB;
constructor(red: number | string, green: number | string, blue: number | string, alpha?: number | string);
private getHex;
/** set red value of color with handling min/max */
set red(red: number);
get red(): number;
/** set green value of color with handling min/max */
set green(green: number);
get green(): number;
/** set blue value of color with handling min/max */
set blue(blue: number);
get blue(): number;
get alpha(): number;
/** set alpha value of color with handling min/max */
set alpha(alpha: number);
/**
* Return color in hex format including transparency
* @return - format #ffccbbaa (last one is alpha)
*/
get getHexColor(): string;
/**
* Return hex format of color without alpha
* @return color in format: #ff00bb
*/
get getHexColorBase(): string;
/**
* Return rgba(100, 200, 255, 0.5) color format as string
*/
getRGBAColor(): string;
toString(): string;
/**
* create object copy
*/
copy(): ColorRGB;
/**
* Multiply every single value of colors by factor parameter with handling min/max cases
*/
multiply(factor: number): ColorRGB;
negative(): ColorRGB;
}
declare class ColorHSV {
h: number;
s: number;
v: number;
protected constructor(h: number, s: number, v: number);
/**
* Calculate color with linear interpolation using factor parameter
*/
static proportionalColor(firstColor: ColorHSV, secondColor: ColorHSV, factor: number): ColorHSV;
/**
* Static constructor for creating ColorHSV object
* @param h hue - value from 0 - 360 degrees
* @param s saturation - value from 0 - 1
* @param v value 0 - 255
* @returns ColorHSV object
*/
static createColorHSV(h: number, s: number, v: number): ColorHSV;
static fmod(a: number, b: number): number;
/**
* Static constructor for creating ColorHSV object
* @param colorRGB object of RGB color
* @returns brand, brand new object of ColorHSV
*/
static createColorHSVfromRGB(colorRGB: ColorRGB): ColorHSV;
convertToRGB(): ColorRGB;
addHue(hue: number): ColorHSV;
toString(): string;
}
type CompareOperators = '<' | '=' | '>' | '!=' | '<=' | '>=';
declare class Dates {
static countDays(start: Date, end: Date): number;
static countWeeks(start: Date, end: Date): number;
static getWeekDate(date: Date, type?: 'last' | 'first', offset?: number): Date;
static equalToDayLevel(first: Date, last: Date): boolean;
static equalToTimeLevel(first: Date, last: Date): boolean;
protected static compare(first: number, last: number, operator: CompareOperators, error: Error): boolean;
static compareToTimeLevel(first: Date, last: Date, operator: CompareOperators): boolean;
/**
* Compare two dates on time level that consider only hours, minutes and seconds (no milliseconds)
*/
static compareToDateLevel(first: Date, last: Date, operator: CompareOperators): boolean;
/**
* set date
*/
static setTimeToZero(date: Date): Date;
/**
* clear date part and milliseconds part
*/
static setDateToZero(date: Date): Date;
static timeFromArray(time: [number, number, number]): Date;
}
interface IPoint2D {
x: number;
y: number;
}
interface IDrawText {
drawText: (text: string, handlePosition: Point2D, color: ColorType, angle: number, options?: any) => void;
setFontSize: (size: number) => void;
}
declare class Point2D implements IPoint2D {
x: number;
y: number;
static isCorrectPoint(point: IPoint2D): boolean;
static fromInterface(iPoint: IPoint2D): Point2D;
/**
* Check if two lines described by pairs of points intersects with each other
* @param pt1 first line start point
* @param pt2 first line end point
* @param pt3 second line start point
* @param pt4 second line end point
* @returns true if intersection exist
*/
static linesIntersect(pt1: Point2D, pt2: Point2D, pt3: Point2D, pt4: Point2D): boolean;
constructor(x?: number, y?: number);
get isZeroLength(): boolean;
isPtInCircle(centralPoint: Point2D, ray: number): boolean;
isPtInRect(x: number, y: number, width: number, height: number): boolean;
isEqual(point2D: Point2D): boolean;
multiply(value: number): Point2D;
scalarMultiple(other: Point2D): number;
determinant(other: Point2D): number;
scale(xs: number, ys: number): Point2D;
add(point: Point2D): Point2D;
subtract(point: Point2D): Point2D;
length(): number;
/**
* Set vector length
* @param length new length to set
* @returns new instance of Point2D with new length if current length of vector is !== 0 in this case
* return degenerated { x: 0, y: 0 } vector
*/
setLength(length: number): Point2D;
/**
* Calculate x * x + y * y = scalarMultiple(this)
* @returns return sick length that can be useful to compare distance between points without calculate sqrt.
* for example if you have two points P1, P2 then P1.sickLength() < P2.sickLength() means P1 is closer to beginning of
* x = 0, y = 0 point then P2 (not require calculate sqrt)
*/
sickLength(): number;
angle(reverseX?: boolean): number;
/**
* rotate point by angle
* @param angle - in radians
* @returns new Instance of Point2D
*/
rotate(angle: number): Point2D;
/**
* Calculate Point2D containing coordinates of point thrown perpendicularly on line
* @param startLinePoint first point of line
* @param endLinePoint last point of line
* @returns if points are equal then null, if not then new instance of Point2D containing coordinates of point thrown
* perpendicularly on line
*/
getPointOnLine(startLinePoint: Point2D, endLinePoint: Point2D): Point2D | null;
/**
* Method to draw point position using IDrawingInterface (require only DrawText method)
* @param ctx can be any IDrawingInterface or your own class containing drawing method
* @param options options to control drawing:
* x, y - position coordinates to display (can be different then coordinates)
* precision - 2 for value 2.3333 display 2.33
* color - of text
* angle - of text
*/
drawPointPos(ctx: IDrawText, options: {
x?: number;
y?: number;
precision?: number;
color?: string;
angle?: number;
fontSize?: number;
}): void;
/**
* Make brand brand new copy of object
* @returns new instance
*/
copy(): Point2D;
/**
* Simplify to interface
*
* @returns IPoint2D interface
*/
toInterface(): IPoint2D;
/**
* Convert to string
* @param separator separator to use for coordinates
* @returns string in format: ' 10, 23.5'
*/
toString(separator?: string): string;
toCssTranslate(unit?: '' | 'px' | 'rem'): string;
}
interface IPoint2DData<T = any> extends IPoint2D {
extData: T;
}
declare class Point2DData<T = any> extends Point2D {
extData?: T;
constructor(x?: number, y?: number, extData?: T);
}
declare class Point3D {
x: number;
y: number;
z: number;
constructor(x?: number, y?: number, z?: number);
add(point: Point3D): Point3D;
subtract(point: Point3D): Point3D;
sickLength(): number;
length(): number;
copy(p3d: Point3D): Point3D;
}
declare class TextTransform {
/**
* Split text only on space sign and if length of more then 1 word in one line is greater then maxLength
* @param text - text to split
* @param maxLength - max length of line
* @returns table of splitted text
*/
static splitByLengthAndWords(text: string, maxLength: number): string[];
/**
* Transform text `some text {to-replace-1}, by using other object {to-replace-2}` using object properties keys
* to replace in text by given properties object
* @param text - text with hidden {key} value
* @param properties - object properties
* {
* 'to-replace-1': 'replace',
* 'to-replace-2': 'replace 2'
* }
* @returns text with replaced by keys part, if key not exist in properties object then matching text is put there
*/
static prepare(text: string, properties: {
[key: string]: string;
}, prepareProps?: (key: string, properties: {
[key: string]: string;
}) => string | undefined): string;
static splitByMathOperator(text: string): string[];
}
declare class LinearFunction2D {
a: number;
b: number;
static fromTwoPoints(p1: Point2D, p2: Point2D): LinearFunction2D | undefined;
constructor(a: number, b: number);
zeroPoint(): number;
xPoint(y: number): number;
yPoint(x: number): number;
}
declare abstract class AbstractSearchDomain<T> {
items: T[];
regExpOn: boolean;
filtered: T[];
abstract search(filter: string): void;
}
declare class DefaultSearchDomain<T extends {
id: string | number;
text: string;
}> extends AbstractSearchDomain<T> {
constructor(items: T[]);
search(filter: string): void;
}
interface IDrawRectangle {
drawRect: (x: number, y: number, width: number, height: number, stroke: number, strokeColor: ColorType, fillColor: ColorType, options?: any) => void;
}
declare class Rectangle {
width: number;
height: number;
start: Point2D;
end: Point2D;
constructor(start?: Point2D, width?: number, height?: number);
get left(): number;
get bottom(): number;
get top(): number;
get right(): number;
isPointIn(point?: Point2D): boolean;
isRectanglesOverlapping(rectangle?: Rectangle): boolean;
drawRectangle(ctx: IDrawRectangle, stroke: number, strokeColor: ColorType, fillColor: ColorType): void;
}
interface IDrawPolyline {
drawPolyline: (points: Point2D[], stroke: number, color: ColorType, options?: {
close?: boolean;
[key: string]: any;
}) => {};
}
declare class Polygon {
static random: (spaceWidth: number, spaceHeight: number, size?: number) => Polygon;
points: Point2D[];
constructor(points?: Point2D[]);
getBondingRect(): Rectangle;
isPointIn(point: Point2D): boolean;
isIntersect(polygon?: Polygon): boolean;
subtract(point: Point2D): Polygon;
multiply(scalar: number): Polygon;
drawPolygon(ctx: IDrawPolyline, stroke: number, color: ColorType): void;
}
interface ClickDataEvent<T = any> {
event: MouseEvent;
data: T;
}
export { AbstractSearchDomain, ColorHSV, ColorRGB, Dates, DefaultSearchDomain, LinearFunction2D, Point2D, Point2DData, Point3D, Polygon, Rectangle, TextTransform };
export type { ClickDataEvent, Color, ColorType, CompareOperators, HexColor, HtmlColor, IDrawText, IPoint2D, IPoint2DData };