-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathtypedefs.ts
130 lines (104 loc) · 2.93 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
119
120
121
122
123
124
125
126
127
128
129
130
// https://www.typescriptlang.org/docs/handbook/utility-types.html
import { BaseFabricObject } from './EventTypeDefs';
import type { Gradient } from './gradient/Gradient';
import type { Pattern } from './Pattern';
import type { XY, Point } from './Point';
interface NominalTag<T> {
nominalTag?: T;
}
type Nominal<Type, Tag> = NominalTag<Tag> & Type;
type TNonFunctionPropertyNames<T> = {
// eslint-disable-next-line @typescript-eslint/ban-types
[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',
}
/**
* A transform matrix.
* Basically a matrix in the form
* [ a c e ]
* [ b d f ]
* [ 0 0 1 ]
* For more details, see @link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform#matrix
*/
export type TMat2D = [
a: number,
b: number,
c: number,
d: number,
e: number,
f: 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 TRectBounds = [min: XY, max: XY];
export type TToCanvasElementOptions = {
left?: number;
top?: number;
width?: number;
height?: number;
filter?: (object: BaseFabricObject) => 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]>>;