-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
typedefs.ts
126 lines (99 loc) · 3.08 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
// https://www.typescriptlang.org/docs/handbook/utility-types.html
import type { Gradient } from './gradient/Gradient';
import type { Pattern } from './Pattern';
import type { XY, Point } from './Point';
import type { FabricObject as BaseFabricObject } from './shapes/Object/Object';
interface NominalTag<T> {
nominalTag?: T;
}
type Nominal<Type, Tag> = NominalTag<Tag> & Type;
type TNonFunctionPropertyNames<T> = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
[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 type ImageFormat = 'jpeg' | 'png';
export type SVGElementName = 'linearGradient' | 'radialGradient' | 'stop';
export type SupportedSVGUnit = 'mm' | 'cm' | 'in' | 'pt' | 'pc' | '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<
T extends BaseFabricObject = BaseFabricObject,
> = {
left?: number;
top?: number;
width?: number;
height?: number;
filter?: (object: T) => boolean;
};
export type TDataUrlOptions<T extends BaseFabricObject = BaseFabricObject> =
TToCanvasElementOptions<T> & {
multiplier: number;
format?: ImageFormat;
quality?: number;
enableRetinaScaling?: boolean;
};
export type Abortable = {
/**
* handle aborting
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
*/
signal?: AbortSignal;
};
export type TOptions<T> = Partial<T> & Record<string, any>;