-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
typedefs.ts
118 lines (92 loc) · 2.75 KB
/
typedefs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// https://www.typescriptlang.org/docs/handbook/utility-types.html
import type { Gradient } from './gradient/gradient.class';
import type { Pattern } from './pattern.class';
import type { Point } from './point.class';
import type { FabricObject } from './shapes/Object/FabricObject';
interface NominalTag<T> {
nominalTag?: T;
}
type Nominal<Type, Tag> = NominalTag<Tag> & Type;
// eslint-disable-next-line @typescript-eslint/ban-types
type TNonFunctionPropertyNames<T> = {
[K in keyof T]: T[K] extends Function ? never : K;
}[keyof T];
export type TClassProperties<T> = Pick<T, TNonFunctionPropertyNames<T>>;
// https://github.com/microsoft/TypeScript/issues/32080
export type Constructor<T = object> = new (...args: any[]) => T;
const enum Degree {}
const enum Radian {}
export type TDegree = Nominal<number, Degree>;
export type TRadian = Nominal<number, Radian>;
export type TAxis = 'x' | 'y';
export type TAxisKey<T extends string> = `${T}${Capitalize<TAxis>}`;
export type TFiller = Gradient<'linear'> | Gradient<'radial'> | Pattern;
export type TSize = {
width: number;
height: number;
};
export type TBBox = {
left: number;
top: number;
} & TSize;
export type Percent = `${number}%`;
export const enum ImageFormat {
jpeg = 'jpeg',
jpg = 'jpeg',
png = 'png',
}
export const enum SVGElementName {
linearGradient = 'linearGradient',
radialGradient = 'radialGradient',
stop = 'stop',
}
export const enum SupportedSVGUnit {
mm = 'mm',
cm = 'cm',
in = 'in',
pt = 'pt',
pc = 'pc',
em = 'em',
}
export type TMat2D = [number, number, number, number, number, number];
/**
* SVG path commands
*/
export type PathData = (string | number)[][];
/**
* An invalid keyword and an empty string will be handled as the `anonymous` keyword.
* @see https://developer.mozilla.org/en-US/docs/HTML/CORS_settings_attributes
*/
export type TCrossOrigin = '' | 'anonymous' | 'use-credentials' | null;
export type TOriginX = 'center' | 'left' | 'right' | number;
export type TOriginY = 'center' | 'top' | 'bottom' | number;
export type TCornerPoint = {
tl: Point;
tr: Point;
bl: Point;
br: Point;
};
export type TSVGReviver = (markup: string) => string;
export type TValidToObjectMethod = 'toDatalessObject' | 'toObject';
export type TCacheCanvasDimensions = {
width: number;
height: number;
zoomX: number;
zoomY: number;
x: number;
y: number;
};
export type TToCanvasElementOptions = {
left?: number;
top?: number;
width?: number;
height?: number;
filter?: (object: FabricObject) => boolean;
};
export type TDataUrlOptions = TToCanvasElementOptions & {
multiplier: number;
format?: ImageFormat;
quality?: number;
enableRetinaScaling?: boolean;
};
export type AssertKeys<T, K extends keyof T> = T & Record<K, NonNullable<T[K]>>;