@flowgram.ai/utils 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +2493 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +1214 -0
- package/dist/index.d.ts +1214 -0
- package/dist/index.js +2618 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,1214 @@
|
|
|
1
|
+
import { interfaces } from 'inversify';
|
|
2
|
+
|
|
3
|
+
declare const PI: number;
|
|
4
|
+
/** Two Pi. */
|
|
5
|
+
declare const PI_2: number;
|
|
6
|
+
/** Conversion factor for converting radians to degrees. */
|
|
7
|
+
declare const RAD_TO_DEG: number;
|
|
8
|
+
/** Conversion factor for converting degrees to radians. */
|
|
9
|
+
declare const DEG_TO_RAD: number;
|
|
10
|
+
/** Constants that identify shapes. */
|
|
11
|
+
declare enum SHAPES {
|
|
12
|
+
/** Polygon */
|
|
13
|
+
POLY = 0,
|
|
14
|
+
/** Rectangle */
|
|
15
|
+
RECT = 1,
|
|
16
|
+
/** Circle */
|
|
17
|
+
CIRC = 2,
|
|
18
|
+
/** Ellipse */
|
|
19
|
+
ELIP = 3,
|
|
20
|
+
/** Rounded Rectangle */
|
|
21
|
+
RREC = 4
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class Vector2 {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
constructor(x?: number, y?: number);
|
|
28
|
+
/**
|
|
29
|
+
* 向量减法
|
|
30
|
+
*/
|
|
31
|
+
sub(v: Vector2): Vector2;
|
|
32
|
+
/**
|
|
33
|
+
* 向量点乘
|
|
34
|
+
*/
|
|
35
|
+
dot(v: Vector2): number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Common interface for points. Both Point and ObservablePoint implement it
|
|
40
|
+
*/
|
|
41
|
+
interface IPoint {
|
|
42
|
+
/**
|
|
43
|
+
* X coord
|
|
44
|
+
*/
|
|
45
|
+
x: number;
|
|
46
|
+
/**
|
|
47
|
+
* Y coord
|
|
48
|
+
*/
|
|
49
|
+
y: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type SchemaType = 'string' | 'integer' | 'float' | 'boolean' | 'enum' | 'object' | 'range' | 'color' | 'array';
|
|
53
|
+
interface SchemaMixinDefaults {
|
|
54
|
+
[defaultKey: string]: any;
|
|
55
|
+
}
|
|
56
|
+
interface SchemaDecoration<SCHEMA = any> {
|
|
57
|
+
type: SchemaType;
|
|
58
|
+
label?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
properties?: {
|
|
61
|
+
[K in keyof SCHEMA]: SchemaDecoration<SCHEMA[K]> & {
|
|
62
|
+
priority?: number;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
enumValues?: (string | number)[];
|
|
66
|
+
enumType?: string | number;
|
|
67
|
+
enumLabels?: string[];
|
|
68
|
+
rangeStep?: number;
|
|
69
|
+
max?: number;
|
|
70
|
+
min?: number;
|
|
71
|
+
disabled?: boolean;
|
|
72
|
+
default?: SCHEMA;
|
|
73
|
+
mixinDefaults?: SchemaMixinDefaults;
|
|
74
|
+
}
|
|
75
|
+
declare namespace SchemaDecoration {
|
|
76
|
+
/**
|
|
77
|
+
* 扩展 SchemaDecoration
|
|
78
|
+
*
|
|
79
|
+
* @param properties - 定义新的属性
|
|
80
|
+
* @param baseDecoration - 基类
|
|
81
|
+
* @param mixinDefaults - 修改默认值
|
|
82
|
+
* @example
|
|
83
|
+
* const MySchemaDecoration = SchemaDecoration.create({
|
|
84
|
+
* myProp: { label: '', default: 1, type: 'number' }
|
|
85
|
+
* },
|
|
86
|
+
* TransformSchemaDecoration, // 继承 Transform
|
|
87
|
+
* {
|
|
88
|
+
* 'size.width': 100, // 修改 size 的默认值
|
|
89
|
+
* 'size.height': 100,
|
|
90
|
+
* })
|
|
91
|
+
*/
|
|
92
|
+
function create<T>(properties: {
|
|
93
|
+
[key: string]: SchemaDecoration;
|
|
94
|
+
}, baseDecoration?: SchemaDecoration, mixinDefaults?: SchemaMixinDefaults): SchemaDecoration<T>;
|
|
95
|
+
}
|
|
96
|
+
declare namespace Schema {
|
|
97
|
+
function createDefault<T>(decoration: SchemaDecoration, mixinDefaults?: SchemaMixinDefaults, _key?: string): T;
|
|
98
|
+
/**
|
|
99
|
+
* 非 object 类
|
|
100
|
+
*/
|
|
101
|
+
function isBaseType(decoration: SchemaDecoration): boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface PositionSchema {
|
|
105
|
+
x: number;
|
|
106
|
+
y: number;
|
|
107
|
+
}
|
|
108
|
+
type RotationSchema = number;
|
|
109
|
+
interface OriginSchema {
|
|
110
|
+
x: number;
|
|
111
|
+
y: number;
|
|
112
|
+
}
|
|
113
|
+
interface ScaleSchema {
|
|
114
|
+
x: number;
|
|
115
|
+
y: number;
|
|
116
|
+
}
|
|
117
|
+
interface ScrollSchema {
|
|
118
|
+
scrollX: number;
|
|
119
|
+
scrollY: number;
|
|
120
|
+
}
|
|
121
|
+
interface SkewSchema {
|
|
122
|
+
x: number;
|
|
123
|
+
y: number;
|
|
124
|
+
}
|
|
125
|
+
declare const SizeSchemaDecoration: SchemaDecoration<SizeSchema>;
|
|
126
|
+
declare const OriginSchemaDecoration: SchemaDecoration<OriginSchema>;
|
|
127
|
+
declare const PositionSchemaDecoration: SchemaDecoration<PositionSchema>;
|
|
128
|
+
declare const RotationSchemaDecoration: SchemaDecoration<RotationSchema>;
|
|
129
|
+
declare const ScaleSchemaDecoration: SchemaDecoration<ScaleSchema>;
|
|
130
|
+
declare const SkewSchemaDecoration: SchemaDecoration<SkewSchema>;
|
|
131
|
+
declare const TransformSchemaDecoration: SchemaDecoration<TransformSchema>;
|
|
132
|
+
interface TransformSchema {
|
|
133
|
+
position: PositionSchema;
|
|
134
|
+
size: SizeSchema;
|
|
135
|
+
origin: OriginSchema;
|
|
136
|
+
scale: ScaleSchema;
|
|
137
|
+
skew: SkewSchema;
|
|
138
|
+
rotation: RotationSchema;
|
|
139
|
+
}
|
|
140
|
+
declare namespace TransformSchema {
|
|
141
|
+
function createDefault(): TransformSchema;
|
|
142
|
+
function toJSON(obj: TransformSchema): TransformSchema;
|
|
143
|
+
function getDelta(oldTransform: TransformSchema, newTransform: TransformSchema): TransformSchema;
|
|
144
|
+
function mergeDelta(oldTransform: TransformSchema, newTransformDelta: TransformSchema, toFixedNum?: number): TransformSchema;
|
|
145
|
+
function is(obj: object): obj is TransformSchema;
|
|
146
|
+
}
|
|
147
|
+
interface SizeSchema {
|
|
148
|
+
width: number;
|
|
149
|
+
height: number;
|
|
150
|
+
locked?: boolean;
|
|
151
|
+
}
|
|
152
|
+
declare namespace SizeSchema {
|
|
153
|
+
/**
|
|
154
|
+
* 适配父节点宽高
|
|
155
|
+
*
|
|
156
|
+
* @return 返回需要缩放的比例,为 1 则不缩放
|
|
157
|
+
*/
|
|
158
|
+
function fixSize(currentSize: SizeSchema, parentSize: SizeSchema): number;
|
|
159
|
+
/**
|
|
160
|
+
* 填充父节点的宽高
|
|
161
|
+
*
|
|
162
|
+
* @return 返回放大的比例
|
|
163
|
+
*/
|
|
164
|
+
function coverSize(currentSize: SizeSchema, parentSize: SizeSchema): number;
|
|
165
|
+
function empty(): SizeSchema;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
type OpacitySchema = number;
|
|
169
|
+
interface FlipSchema {
|
|
170
|
+
x: boolean;
|
|
171
|
+
y: boolean;
|
|
172
|
+
}
|
|
173
|
+
interface ShadowSchema {
|
|
174
|
+
color: string;
|
|
175
|
+
offsetX: number;
|
|
176
|
+
offsetY: number;
|
|
177
|
+
blur: number;
|
|
178
|
+
}
|
|
179
|
+
interface PaddingSchema {
|
|
180
|
+
left: number;
|
|
181
|
+
right: number;
|
|
182
|
+
top: number;
|
|
183
|
+
bottom: number;
|
|
184
|
+
}
|
|
185
|
+
declare namespace PaddingSchema {
|
|
186
|
+
const empty: () => {
|
|
187
|
+
left: number;
|
|
188
|
+
right: number;
|
|
189
|
+
top: number;
|
|
190
|
+
bottom: number;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
type MarginSchema = PaddingSchema;
|
|
194
|
+
interface TintSchema {
|
|
195
|
+
topLeft: string;
|
|
196
|
+
topRight: string;
|
|
197
|
+
bottomLeft: string;
|
|
198
|
+
bottomRight: string;
|
|
199
|
+
}
|
|
200
|
+
declare namespace TintSchema {
|
|
201
|
+
function isEmpty(tint: Partial<TintSchema> | undefined): boolean;
|
|
202
|
+
}
|
|
203
|
+
declare const CropSchemaDecoration: SchemaDecoration<PositionSchema & SizeSchema>;
|
|
204
|
+
declare const FlipSchemaDecoration: SchemaDecoration<FlipSchema>;
|
|
205
|
+
declare const PaddingSchemaDecoration: SchemaDecoration<PaddingSchema>;
|
|
206
|
+
declare const ShadowSchemaDecoration: SchemaDecoration<ShadowSchema>;
|
|
207
|
+
declare const TintSchemaDecoration: SchemaDecoration<TintSchema>;
|
|
208
|
+
declare const OpacitySchemaDecoration: SchemaDecoration<OpacitySchema>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Size object, contains width and height
|
|
212
|
+
*/
|
|
213
|
+
type ISize = {
|
|
214
|
+
width: number;
|
|
215
|
+
height: number;
|
|
216
|
+
};
|
|
217
|
+
declare enum RectangleAlignType {
|
|
218
|
+
ALIGN_LEFT = "align-left",
|
|
219
|
+
ALIGN_CENTER = "align-center",
|
|
220
|
+
ALIGN_RIGHT = "align-right",
|
|
221
|
+
ALIGN_TOP = "align-top",
|
|
222
|
+
ALIGN_MIDDLE = "align-middle",
|
|
223
|
+
ALIGN_BOTTOM = "align-bottom",
|
|
224
|
+
DISTRIBUTE_HORIZONTAL = "distribute-horizontal",
|
|
225
|
+
DISTRIBUTE_VERTICAL = "distribute-vertical"
|
|
226
|
+
}
|
|
227
|
+
declare enum RectangleAlignTitle {
|
|
228
|
+
ALIGN_LEFT = "\u5DE6\u5BF9\u9F50",
|
|
229
|
+
ALIGN_CENTER = "\u5DE6\u53F3\u5C45\u4E2D\u5BF9\u9F50",
|
|
230
|
+
ALIGN_RIGHT = "\u53F3\u5BF9\u9F50",
|
|
231
|
+
ALIGN_TOP = "\u4E0A\u5BF9\u9F50",
|
|
232
|
+
ALIGN_MIDDLE = "\u4E0A\u4E0B\u5C45\u4E2D\u5BF9\u9F50",
|
|
233
|
+
ALIGN_BOTTOM = "\u4E0B\u5BF9\u9F50",
|
|
234
|
+
DISTRIBUTE_HORIZONTAL = "\u6C34\u5E73\u5E73\u5747\u5206\u5E03",
|
|
235
|
+
DISTRIBUTE_VERTICAL = "\u5782\u76F4\u5E73\u5747\u5206\u5E03"
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Rectangle object is an area defined by its position, as indicated by its top-left corner
|
|
239
|
+
* point (x, y) and by its width and its height.
|
|
240
|
+
*/
|
|
241
|
+
declare class Rectangle {
|
|
242
|
+
x: number;
|
|
243
|
+
y: number;
|
|
244
|
+
width: number;
|
|
245
|
+
height: number;
|
|
246
|
+
/**
|
|
247
|
+
* The type of the object, mainly used to avoid `instanceof` checks
|
|
248
|
+
*/
|
|
249
|
+
readonly type = SHAPES.RECT;
|
|
250
|
+
/**
|
|
251
|
+
* @param [x] - The X coordinate of the upper-left corner of the rectangle
|
|
252
|
+
* @param [y] - The Y coordinate of the upper-left corner of the rectangle
|
|
253
|
+
* @param [width] - The overall width of this rectangle
|
|
254
|
+
* @param [height] - The overall height of this rectangle
|
|
255
|
+
*/
|
|
256
|
+
constructor(x?: number, y?: number, width?: number, height?: number);
|
|
257
|
+
/**
|
|
258
|
+
* A constant empty rectangle. MUST NOT modify properties!
|
|
259
|
+
*/
|
|
260
|
+
static get EMPTY(): Rectangle;
|
|
261
|
+
get left(): number;
|
|
262
|
+
get right(): number;
|
|
263
|
+
get top(): number;
|
|
264
|
+
get bottom(): number;
|
|
265
|
+
/**
|
|
266
|
+
* Creates a clone of this Rectangle.
|
|
267
|
+
*
|
|
268
|
+
* @return a copy of the rectangle
|
|
269
|
+
*/
|
|
270
|
+
clone(): Rectangle;
|
|
271
|
+
/**
|
|
272
|
+
* Copies another rectangle to this one.
|
|
273
|
+
*
|
|
274
|
+
* @return Returns itself.
|
|
275
|
+
*/
|
|
276
|
+
copyFrom(rectangle: Rectangle): Rectangle;
|
|
277
|
+
/**
|
|
278
|
+
* Copies this rectangle to another one.
|
|
279
|
+
*
|
|
280
|
+
* @return Returns given rectangle.
|
|
281
|
+
*/
|
|
282
|
+
copyTo(rectangle: Rectangle): Rectangle;
|
|
283
|
+
/**
|
|
284
|
+
* Checks whether the x and y coordinates given are contained within this Rectangle
|
|
285
|
+
*
|
|
286
|
+
* @param x - The X coordinate of the point to test
|
|
287
|
+
* @param y - The Y coordinate of the point to test
|
|
288
|
+
* @return Whether the x/y coordinates are within this Rectangle
|
|
289
|
+
*/
|
|
290
|
+
contains(x: number, y: number): boolean;
|
|
291
|
+
isEqual(rect: Rectangle): boolean;
|
|
292
|
+
containsRectangle(rect: Rectangle): boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Pads the rectangle making it grow in all directions.
|
|
295
|
+
* If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
|
|
296
|
+
*
|
|
297
|
+
* @param [paddingX] - The horizontal padding amount.
|
|
298
|
+
* @param [paddingY] - The vertical padding amount.
|
|
299
|
+
*/
|
|
300
|
+
pad(paddingX?: number, paddingY?: number): this;
|
|
301
|
+
/**
|
|
302
|
+
* Fits this rectangle around the passed one.
|
|
303
|
+
* Intersection 交集
|
|
304
|
+
*/
|
|
305
|
+
fit(rectangle: Rectangle): this;
|
|
306
|
+
/**
|
|
307
|
+
* Enlarges rectangle that way its corners lie on grid
|
|
308
|
+
*/
|
|
309
|
+
ceil(resolution?: number, precision?: number): this;
|
|
310
|
+
/**
|
|
311
|
+
* Enlarges this rectangle to include the passed rectangle.
|
|
312
|
+
*/
|
|
313
|
+
enlarge(rectangle: Rectangle): this;
|
|
314
|
+
get center(): IPoint;
|
|
315
|
+
get rightBottom(): IPoint;
|
|
316
|
+
get leftBottom(): IPoint;
|
|
317
|
+
get rightTop(): IPoint;
|
|
318
|
+
get leftTop(): IPoint;
|
|
319
|
+
get bottomCenter(): IPoint;
|
|
320
|
+
get topCenter(): IPoint;
|
|
321
|
+
get rightCenter(): IPoint;
|
|
322
|
+
get leftCenter(): IPoint;
|
|
323
|
+
update(fn: (rect: Rectangle) => Rectangle): Rectangle;
|
|
324
|
+
get crossDistance(): number;
|
|
325
|
+
toStyleStr(): string;
|
|
326
|
+
withPadding(padding: PaddingSchema): this;
|
|
327
|
+
withoutPadding(padding: PaddingSchema): this;
|
|
328
|
+
withHeight(height: number): this;
|
|
329
|
+
clearSpace(): this;
|
|
330
|
+
}
|
|
331
|
+
declare namespace Rectangle {
|
|
332
|
+
/**
|
|
333
|
+
* 矩形对齐
|
|
334
|
+
*/
|
|
335
|
+
function align(rectangles: Rectangle[], type: RectangleAlignType): Rectangle[];
|
|
336
|
+
/**
|
|
337
|
+
* 获取所有矩形的外围最大边框
|
|
338
|
+
*/
|
|
339
|
+
function enlarge(rectangles: Rectangle[]): Rectangle;
|
|
340
|
+
/**
|
|
341
|
+
* 判断矩形相交
|
|
342
|
+
*
|
|
343
|
+
* @param [direction] 判断单一方向
|
|
344
|
+
*/
|
|
345
|
+
function intersects(target1: Rectangle, target2: Rectangle, direction?: 'horizontal' | 'vertical'): boolean;
|
|
346
|
+
/**
|
|
347
|
+
* 使用 OBB 算法判断两个旋转矩形是否相交
|
|
348
|
+
* @param rotate1 单位 radian
|
|
349
|
+
* @param rotate2 单位 radian
|
|
350
|
+
*/
|
|
351
|
+
function intersectsWithRotation(rect1: Rectangle, rotate1: number, rect2: Rectangle, rotate2: number): boolean;
|
|
352
|
+
/**
|
|
353
|
+
* 判断指定 rect 是否在 viewport 可见
|
|
354
|
+
*
|
|
355
|
+
* @param rotation rect 旋转,单位 radian
|
|
356
|
+
* @param isContains 整个 bounds 是否全部可见
|
|
357
|
+
*/
|
|
358
|
+
function isViewportVisible(rect: Rectangle, viewport: Rectangle, rotation?: number, isContains?: boolean): boolean;
|
|
359
|
+
/**
|
|
360
|
+
* 保证bounds 永远在 viewport 里边
|
|
361
|
+
*
|
|
362
|
+
* @param bounds
|
|
363
|
+
* @param viewport
|
|
364
|
+
* @param padding 距离 viewport 的安全边界
|
|
365
|
+
*/
|
|
366
|
+
function setViewportVisible(bounds: Rectangle, viewport: Rectangle, padding?: number): Rectangle;
|
|
367
|
+
/**
|
|
368
|
+
* 根据两点创建矩形
|
|
369
|
+
*/
|
|
370
|
+
function createRectangleWithTwoPoints(point1: IPoint, point2: IPoint): Rectangle;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Oriented Bounding Box (OBB)
|
|
374
|
+
* @see https://en.wikipedia.org/wiki/Bounding_volume
|
|
375
|
+
*/
|
|
376
|
+
declare class OBBRect {
|
|
377
|
+
protected width: number;
|
|
378
|
+
protected height: number;
|
|
379
|
+
readonly axesX: Vector2;
|
|
380
|
+
readonly axesY: Vector2;
|
|
381
|
+
readonly centerPoint: Vector2;
|
|
382
|
+
/**
|
|
383
|
+
* @param rotation in radian
|
|
384
|
+
*/
|
|
385
|
+
constructor(centerPoint: IPoint, width: number, height: number, rotation: number);
|
|
386
|
+
/**
|
|
387
|
+
* 计算投影半径
|
|
388
|
+
*/
|
|
389
|
+
getProjectionRadius(axis: Vector2): number;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* The Circle object is used to help draw graphics and can also be used to specify a hit area for displayObjects.
|
|
394
|
+
*/
|
|
395
|
+
declare class Circle {
|
|
396
|
+
x: number;
|
|
397
|
+
y: number;
|
|
398
|
+
radius: number;
|
|
399
|
+
/**
|
|
400
|
+
* The type of the object, mainly used to avoid `instanceof` checks
|
|
401
|
+
*/
|
|
402
|
+
readonly type = SHAPES.CIRC;
|
|
403
|
+
/**
|
|
404
|
+
* @param x Circle center x
|
|
405
|
+
* @param y Circle center y
|
|
406
|
+
*/
|
|
407
|
+
constructor(x?: number, y?: number, radius?: number);
|
|
408
|
+
/**
|
|
409
|
+
* Creates a clone of this Circle instance
|
|
410
|
+
*
|
|
411
|
+
* @return a copy of the Circle
|
|
412
|
+
*/
|
|
413
|
+
clone(): Circle;
|
|
414
|
+
/**
|
|
415
|
+
* Checks whether the x and y coordinates given are contained within this circle
|
|
416
|
+
*
|
|
417
|
+
* @return Whether the (x, y) coordinates are within this Circle
|
|
418
|
+
*/
|
|
419
|
+
contains(x: number, y: number): boolean;
|
|
420
|
+
/**
|
|
421
|
+
* Returns the framing rectangle of the circle as a Rectangle object
|
|
422
|
+
*
|
|
423
|
+
* @return the framing rectangle
|
|
424
|
+
*/
|
|
425
|
+
getBounds(): Rectangle;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* The Point object represents a location in a two-dimensional coordinate system, where x represents
|
|
430
|
+
* the horizontal axis and y represents the vertical axis.
|
|
431
|
+
*
|
|
432
|
+
* An ObservablePoint is a point that triggers a callback when the point's position is changed.
|
|
433
|
+
*/
|
|
434
|
+
declare class ObservablePoint<T = any> implements IPoint {
|
|
435
|
+
cb: (this: T) => any;
|
|
436
|
+
scope: any;
|
|
437
|
+
/**
|
|
438
|
+
* @param {Function} cb - callback when changed
|
|
439
|
+
* @param {object} scope - owner of callback
|
|
440
|
+
* @param {number} [x=0] - position of the point on the x axis
|
|
441
|
+
* @param {number} [y=0] - position of the point on the y axis
|
|
442
|
+
*/
|
|
443
|
+
constructor(cb: (this: T) => any, scope: T, x?: number, y?: number);
|
|
444
|
+
_x: number;
|
|
445
|
+
/**
|
|
446
|
+
* The position of the displayObject on the x axis relative to the local coordinates of the parent.
|
|
447
|
+
*/
|
|
448
|
+
get x(): number;
|
|
449
|
+
set x(value: number);
|
|
450
|
+
_y: number;
|
|
451
|
+
/**
|
|
452
|
+
* The position of the displayObject on the x axis relative to the local coordinates of the parent.
|
|
453
|
+
*/
|
|
454
|
+
get y(): number;
|
|
455
|
+
set y(value: number);
|
|
456
|
+
/**
|
|
457
|
+
* Creates a clone of this point.
|
|
458
|
+
* The callback and scope params can be overidden otherwise they will default
|
|
459
|
+
* to the clone object's values.
|
|
460
|
+
*
|
|
461
|
+
* @override
|
|
462
|
+
* @param {Function} [cb=null] - callback when changed
|
|
463
|
+
* @param {object} [scope=null] - owner of callback
|
|
464
|
+
* @return {ObservablePoint} a copy of the point
|
|
465
|
+
*/
|
|
466
|
+
clone(cb?: (this: T) => any, scope?: any): ObservablePoint;
|
|
467
|
+
/**
|
|
468
|
+
* Sets the point to a new x and y position.
|
|
469
|
+
* If y is omitted, both x and y will be set to x.
|
|
470
|
+
*
|
|
471
|
+
* @param {number} [x=0] - position of the point on the x axis
|
|
472
|
+
* @param {number} [y=x] - position of the point on the y axis
|
|
473
|
+
* @returns {this} Returns itself.
|
|
474
|
+
*/
|
|
475
|
+
set(x?: number, y?: number): this;
|
|
476
|
+
/**
|
|
477
|
+
* Copies x and y from the given point
|
|
478
|
+
*
|
|
479
|
+
* @param {IPoint} p - The point to copy from.
|
|
480
|
+
* @returns {this} Returns itself.
|
|
481
|
+
*/
|
|
482
|
+
copyFrom(p: IPoint): this;
|
|
483
|
+
/**
|
|
484
|
+
* Copies x and y into the given point
|
|
485
|
+
*
|
|
486
|
+
* @param {IPoint} p - The point to copy.
|
|
487
|
+
* @returns {IPoint} Given point with values updated
|
|
488
|
+
*/
|
|
489
|
+
copyTo<T2 extends IPoint>(p: T2): T2;
|
|
490
|
+
/**
|
|
491
|
+
* Returns true if the given point is equal to this point
|
|
492
|
+
*
|
|
493
|
+
* @param {IPoint} p - The point to check
|
|
494
|
+
* @returns {boolean} Whether the given point equal to this point
|
|
495
|
+
*/
|
|
496
|
+
equals(p: IPoint): boolean;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Transform that takes care about its versions
|
|
501
|
+
*
|
|
502
|
+
* @class
|
|
503
|
+
* @memberof PIXI
|
|
504
|
+
*/
|
|
505
|
+
declare class Transform {
|
|
506
|
+
/**
|
|
507
|
+
* A default (identity) transform
|
|
508
|
+
*
|
|
509
|
+
* @static
|
|
510
|
+
* @constant
|
|
511
|
+
* @member {PIXI.Transform}
|
|
512
|
+
*/
|
|
513
|
+
static readonly IDENTITY: Transform;
|
|
514
|
+
worldTransform: Matrix;
|
|
515
|
+
localTransform: Matrix;
|
|
516
|
+
position: ObservablePoint;
|
|
517
|
+
scale: ObservablePoint;
|
|
518
|
+
pivot: ObservablePoint;
|
|
519
|
+
skew: ObservablePoint;
|
|
520
|
+
_parentID: number;
|
|
521
|
+
_worldID: number;
|
|
522
|
+
protected _rotation: number;
|
|
523
|
+
protected _cx: number;
|
|
524
|
+
protected _sx: number;
|
|
525
|
+
protected _cy: number;
|
|
526
|
+
protected _sy: number;
|
|
527
|
+
protected _localID: number;
|
|
528
|
+
protected _currentLocalID: number;
|
|
529
|
+
constructor();
|
|
530
|
+
/**
|
|
531
|
+
* Called when a value changes.
|
|
532
|
+
*
|
|
533
|
+
* @protected
|
|
534
|
+
*/
|
|
535
|
+
protected onChange(): void;
|
|
536
|
+
/**
|
|
537
|
+
* Called when the skew or the rotation changes.
|
|
538
|
+
*
|
|
539
|
+
* @protected
|
|
540
|
+
*/
|
|
541
|
+
protected updateSkew(): void;
|
|
542
|
+
/**
|
|
543
|
+
* Updates the local transformation matrix.
|
|
544
|
+
*/
|
|
545
|
+
updateLocalTransform(): void;
|
|
546
|
+
/**
|
|
547
|
+
* Updates the local and the world transformation matrices.
|
|
548
|
+
*
|
|
549
|
+
* @param {PIXI.Transform} parentTransform - The parent transform
|
|
550
|
+
*/
|
|
551
|
+
updateTransform(parentTransform: Transform): void;
|
|
552
|
+
/**
|
|
553
|
+
* Decomposes a matrix and sets the transforms properties based on it.
|
|
554
|
+
*
|
|
555
|
+
* @param {PIXI.Matrix} matrix - The matrix to decompose
|
|
556
|
+
*/
|
|
557
|
+
setFromMatrix(matrix: Matrix): void;
|
|
558
|
+
/**
|
|
559
|
+
* The rotation of the object in radians.
|
|
560
|
+
*
|
|
561
|
+
* @member {number}
|
|
562
|
+
*/
|
|
563
|
+
get rotation(): number;
|
|
564
|
+
set rotation(value: number);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* The PIXIJS Matrix as a class makes it a lot faster.
|
|
569
|
+
*
|
|
570
|
+
* Here is a representation of it:
|
|
571
|
+
* ```js
|
|
572
|
+
* | a | c | tx|
|
|
573
|
+
* | b | d | ty|
|
|
574
|
+
* | 0 | 0 | 1 |
|
|
575
|
+
* // default:
|
|
576
|
+
* | 1 | 0 | 0 |
|
|
577
|
+
* | 0 | 1 | 0 |
|
|
578
|
+
* | 0 | 0 | 1 |
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
declare class Matrix {
|
|
582
|
+
a: number;
|
|
583
|
+
b: number;
|
|
584
|
+
c: number;
|
|
585
|
+
d: number;
|
|
586
|
+
tx: number;
|
|
587
|
+
ty: number;
|
|
588
|
+
array: Float32Array | null;
|
|
589
|
+
/**
|
|
590
|
+
* @param [a] x scale
|
|
591
|
+
* @param [b] x skew
|
|
592
|
+
* @param [c] y skew
|
|
593
|
+
* @param [d] y scale
|
|
594
|
+
* @param [tx] x translation
|
|
595
|
+
* @param [ty] y translation
|
|
596
|
+
*/
|
|
597
|
+
constructor(a?: number, b?: number, c?: number, d?: number, tx?: number, ty?: number);
|
|
598
|
+
/**
|
|
599
|
+
* A default (identity) matrix
|
|
600
|
+
*/
|
|
601
|
+
static get IDENTITY(): Matrix;
|
|
602
|
+
/**
|
|
603
|
+
* A temp matrix
|
|
604
|
+
*/
|
|
605
|
+
static get TEMP_MATRIX(): Matrix;
|
|
606
|
+
/**
|
|
607
|
+
* Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:
|
|
608
|
+
*
|
|
609
|
+
* @param array The array that the matrix will be populated from.
|
|
610
|
+
*/
|
|
611
|
+
fromArray(array: number[]): this;
|
|
612
|
+
/**
|
|
613
|
+
* sets the matrix properties
|
|
614
|
+
*
|
|
615
|
+
* @param a Matrix component
|
|
616
|
+
* @param b Matrix component
|
|
617
|
+
* @param c Matrix component
|
|
618
|
+
* @param d Matrix component
|
|
619
|
+
* @param tx Matrix component
|
|
620
|
+
* @param ty Matrix component
|
|
621
|
+
*/
|
|
622
|
+
set(a: number, b: number, c: number, d: number, tx: number, ty: number): this;
|
|
623
|
+
/**
|
|
624
|
+
* Creates an array from the current Matrix object.
|
|
625
|
+
*
|
|
626
|
+
* @param transpose Whether we need to transpose the matrix or not
|
|
627
|
+
* @param [out=new Float32Array(9)] If provided the array will be assigned to out
|
|
628
|
+
* @return the newly created array which contains the matrix
|
|
629
|
+
*/
|
|
630
|
+
toArray(transpose: boolean, out?: Float32Array): Float32Array;
|
|
631
|
+
/**
|
|
632
|
+
* Get a new position with the current transformation applied.
|
|
633
|
+
* Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
|
|
634
|
+
*
|
|
635
|
+
* @param pos The origin
|
|
636
|
+
* @param [newPos] The point that the new position is assigned to (allowed to be same as input)
|
|
637
|
+
* @return The new point, transformed through this matrix
|
|
638
|
+
*/
|
|
639
|
+
apply(pos: IPoint, newPos?: IPoint): IPoint;
|
|
640
|
+
/**
|
|
641
|
+
* Get a new position with the inverse of the current transformation applied.
|
|
642
|
+
* Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
|
|
643
|
+
*
|
|
644
|
+
* @param pos The origin
|
|
645
|
+
* @param [newPos] The point that the new position is assigned to (allowed to be same as input)
|
|
646
|
+
* @return The new point, inverse-transformed through this matrix
|
|
647
|
+
*/
|
|
648
|
+
applyInverse(pos: IPoint, newPos?: IPoint): IPoint;
|
|
649
|
+
/**
|
|
650
|
+
* Translates the matrix on the x and y.
|
|
651
|
+
*
|
|
652
|
+
* @param x How much to translate x by
|
|
653
|
+
* @param y How much to translate y by
|
|
654
|
+
*/
|
|
655
|
+
translate(x: number, y: number): this;
|
|
656
|
+
/**
|
|
657
|
+
* Applies a scale transformation to the matrix.
|
|
658
|
+
*
|
|
659
|
+
* @param x The amount to scale horizontally
|
|
660
|
+
* @param y The amount to scale vertically
|
|
661
|
+
*/
|
|
662
|
+
scale(x: number, y: number): this;
|
|
663
|
+
/**
|
|
664
|
+
* Applies a rotation transformation to the matrix.
|
|
665
|
+
*
|
|
666
|
+
* @param angle The angle in radians.
|
|
667
|
+
*/
|
|
668
|
+
rotate(angle: number): this;
|
|
669
|
+
/**
|
|
670
|
+
* 矩阵乘法,当前矩阵 * matrix
|
|
671
|
+
* Appends the given Matrix to this Matrix.
|
|
672
|
+
*/
|
|
673
|
+
append(matrix: Matrix): this;
|
|
674
|
+
/**
|
|
675
|
+
* Sets the matrix based on all the available properties
|
|
676
|
+
*
|
|
677
|
+
* @param x Position on the x axis
|
|
678
|
+
* @param y Position on the y axis
|
|
679
|
+
* @param pivotX Pivot on the x axis
|
|
680
|
+
* @param pivotY Pivot on the y axis
|
|
681
|
+
* @param scaleX Scale on the x axis
|
|
682
|
+
* @param scaleY Scale on the y axis
|
|
683
|
+
* @param rotation Rotation in radians
|
|
684
|
+
* @param skewX Skew on the x axis
|
|
685
|
+
* @param skewY Skew on the y axis
|
|
686
|
+
*/
|
|
687
|
+
setTransform(x: number, y: number, pivotX: number, pivotY: number, scaleX: number, scaleY: number, rotation: number, skewX: number, skewY: number): this;
|
|
688
|
+
/**
|
|
689
|
+
* 矩阵乘法,matrix * 当前矩阵
|
|
690
|
+
* Prepends the given Matrix to this Matrix.
|
|
691
|
+
*/
|
|
692
|
+
prepend(matrix: Matrix): this;
|
|
693
|
+
/**
|
|
694
|
+
* Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform.
|
|
695
|
+
*
|
|
696
|
+
* @param transform The transform to apply the properties to.
|
|
697
|
+
* @return The transform with the newly applied properties
|
|
698
|
+
*/
|
|
699
|
+
decompose(transform: Transform): Transform;
|
|
700
|
+
/**
|
|
701
|
+
* Inverts this matrix
|
|
702
|
+
*/
|
|
703
|
+
invert(): this;
|
|
704
|
+
/**
|
|
705
|
+
* Resets this Matrix to an identity (default) matrix.
|
|
706
|
+
*/
|
|
707
|
+
identity(): this;
|
|
708
|
+
/**
|
|
709
|
+
* 未做旋转的矩阵
|
|
710
|
+
*/
|
|
711
|
+
isSimple(): boolean;
|
|
712
|
+
/**
|
|
713
|
+
* Creates a new Matrix object with the same values as this one.
|
|
714
|
+
*
|
|
715
|
+
* @return A copy of this matrix.
|
|
716
|
+
*/
|
|
717
|
+
clone(): Matrix;
|
|
718
|
+
/**
|
|
719
|
+
* Changes the values of the given matrix to be the same as the ones in this matrix
|
|
720
|
+
*
|
|
721
|
+
* @return The matrix given in parameter with its values updated.
|
|
722
|
+
*/
|
|
723
|
+
copyTo(matrix: Matrix): Matrix;
|
|
724
|
+
/**
|
|
725
|
+
* Changes the values of the matrix to be the same as the ones in given matrix
|
|
726
|
+
*/
|
|
727
|
+
copyFrom(matrix: Matrix): this;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* The Point object represents a location in a two-dimensional coordinate system, where x represents
|
|
732
|
+
* the horizontal axis and y represents the vertical axis.
|
|
733
|
+
*
|
|
734
|
+
* @class
|
|
735
|
+
* @memberof PIXI
|
|
736
|
+
* @implements IPoint
|
|
737
|
+
*/
|
|
738
|
+
declare class Point implements IPoint {
|
|
739
|
+
x: number;
|
|
740
|
+
y: number;
|
|
741
|
+
constructor(x?: number, y?: number);
|
|
742
|
+
/**
|
|
743
|
+
* Creates a clone of this point
|
|
744
|
+
*
|
|
745
|
+
* @return {Point} a copy of the point
|
|
746
|
+
*/
|
|
747
|
+
clone(): Point;
|
|
748
|
+
/**
|
|
749
|
+
* Copies x and y from the given point
|
|
750
|
+
*
|
|
751
|
+
* @param {IPoint} p - The point to copy from
|
|
752
|
+
* @returns {this} Returns itself.
|
|
753
|
+
*/
|
|
754
|
+
copyFrom(p: IPoint): this;
|
|
755
|
+
/**
|
|
756
|
+
* Copies x and y into the given point
|
|
757
|
+
*
|
|
758
|
+
* @param {IPoint} p - The point to copy.
|
|
759
|
+
* @returns {IPoint} Given point with values updated
|
|
760
|
+
*/
|
|
761
|
+
copyTo<T extends IPoint>(p: T): T;
|
|
762
|
+
/**
|
|
763
|
+
* Returns true if the given point is equal to this point
|
|
764
|
+
*
|
|
765
|
+
* @param {IPoint} p - The point to check
|
|
766
|
+
* @returns {boolean} Whether the given point equal to this point
|
|
767
|
+
*/
|
|
768
|
+
equals(p: IPoint): boolean;
|
|
769
|
+
/**
|
|
770
|
+
* Sets the point to a new x and y position.
|
|
771
|
+
* If y is omitted, both x and y will be set to x.
|
|
772
|
+
*
|
|
773
|
+
* @param {number} [x=0] - position of the point on the x axis
|
|
774
|
+
* @param {number} [y=x] - position of the point on the y axis
|
|
775
|
+
* @returns {this} Returns itself.
|
|
776
|
+
*/
|
|
777
|
+
set(x?: number, y?: number): this;
|
|
778
|
+
}
|
|
779
|
+
declare namespace Point {
|
|
780
|
+
const EMPTY: IPoint;
|
|
781
|
+
/**
|
|
782
|
+
* 获取两点间的距离
|
|
783
|
+
* @param p1
|
|
784
|
+
* @param p2
|
|
785
|
+
*/
|
|
786
|
+
function getDistance(p1: IPoint, p2: IPoint): number;
|
|
787
|
+
/**
|
|
788
|
+
* 获取两点间的中间点
|
|
789
|
+
* @param p1
|
|
790
|
+
* @param p2
|
|
791
|
+
*/
|
|
792
|
+
function getMiddlePoint(p1: IPoint, p2: IPoint): IPoint;
|
|
793
|
+
/**
|
|
794
|
+
* 按一定比例,获取两点间的中间点
|
|
795
|
+
* @param p1
|
|
796
|
+
* @param p2
|
|
797
|
+
*/
|
|
798
|
+
function getRatioPoint(p1: IPoint, p2: IPoint, ratio: number): IPoint;
|
|
799
|
+
function fixZero(output: IPoint): IPoint;
|
|
800
|
+
/**
|
|
801
|
+
* 往目标点移动 distance 距离
|
|
802
|
+
* @param current
|
|
803
|
+
* @param direction
|
|
804
|
+
*/
|
|
805
|
+
function move(current: IPoint, m: Partial<IPoint>): IPoint;
|
|
806
|
+
/**
|
|
807
|
+
* 往目标点移动 distance 距离
|
|
808
|
+
* @param current
|
|
809
|
+
* @param direction
|
|
810
|
+
*/
|
|
811
|
+
function moveDistanceToDirection(current: IPoint, direction: IPoint, distance: number): IPoint;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
declare namespace Angle {
|
|
815
|
+
/**
|
|
816
|
+
* Wrap an angle.
|
|
817
|
+
*
|
|
818
|
+
* Wraps the angle to a value in the range of -PI to PI.
|
|
819
|
+
*
|
|
820
|
+
* @param angle - The angle to wrap, in radians.
|
|
821
|
+
* @return The wrapped angle, in radians.
|
|
822
|
+
*/
|
|
823
|
+
function wrap(angle: number): number;
|
|
824
|
+
/**
|
|
825
|
+
* Wrap an angle in degrees.
|
|
826
|
+
*
|
|
827
|
+
* Wraps the angle to a value in the range of -180 to 180.
|
|
828
|
+
*
|
|
829
|
+
* @param angle - The angle to wrap, in degrees.
|
|
830
|
+
* @return The wrapped angle, in degrees.
|
|
831
|
+
*/
|
|
832
|
+
function wrapDegrees(angle: number): number;
|
|
833
|
+
/**
|
|
834
|
+
* 计算两个点的夹角
|
|
835
|
+
*
|
|
836
|
+
* @return The angle in radians.
|
|
837
|
+
*/
|
|
838
|
+
function betweenPoints(point1: IPoint, point2: IPoint, originPoint?: IPoint): number;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
declare function deepFreeze<T>(obj: T): T;
|
|
842
|
+
declare function notEmpty<T>(arg: T | undefined | null): arg is T;
|
|
843
|
+
/**
|
|
844
|
+
* `true` if the argument is an empty object. Otherwise, `false`.
|
|
845
|
+
*/
|
|
846
|
+
declare function isEmpty(arg: Object): boolean;
|
|
847
|
+
declare const each: <T = any, K = string>(obj: any, fn: (value: T, key: K) => void) => void;
|
|
848
|
+
declare const values: (obj: any) => any[];
|
|
849
|
+
declare const filter: (obj: any, fn: (value: any, key: string) => boolean, dest?: any) => any;
|
|
850
|
+
declare const pick: (obj: any, fields: string[], dest?: any) => any;
|
|
851
|
+
declare const omit: (obj: any, fields: string[], dest?: any) => any;
|
|
852
|
+
declare const reduce: <V = any, R = any>(obj: any, fn: (res: R, value: V, key: string) => any, res?: R) => R;
|
|
853
|
+
declare const mapValues: <V = any>(obj: any, fn: (value: V, key: string) => any) => any;
|
|
854
|
+
declare const mapKeys: <V = any>(obj: any, fn: (value: V, key: string) => any) => any;
|
|
855
|
+
/**
|
|
856
|
+
* @param target
|
|
857
|
+
* @param key
|
|
858
|
+
* @example
|
|
859
|
+
* const obj = {
|
|
860
|
+
* position: {
|
|
861
|
+
* x: 0
|
|
862
|
+
* y: 0
|
|
863
|
+
* }
|
|
864
|
+
* }
|
|
865
|
+
* getByKey(ob, 'position.x') // 0
|
|
866
|
+
*/
|
|
867
|
+
declare function getByKey(target: any, key: string): any | undefined;
|
|
868
|
+
/**
|
|
869
|
+
* @param target
|
|
870
|
+
* @param key
|
|
871
|
+
* @param newValue
|
|
872
|
+
* @param autoCreateObject
|
|
873
|
+
* @example
|
|
874
|
+
* const obj = {
|
|
875
|
+
* position: {
|
|
876
|
+
* x: 0
|
|
877
|
+
* y: 0
|
|
878
|
+
* }
|
|
879
|
+
* }
|
|
880
|
+
* setByKey(ob, 'position.x', 100) // true
|
|
881
|
+
* setByKey(obj, 'size.width', 100) // false
|
|
882
|
+
* setBeyKey(obj, 'size.width', 100, true) // true
|
|
883
|
+
*/
|
|
884
|
+
declare function setByKey(target: any, key: string, newValue: any, autoCreateObject?: boolean, clone?: boolean): any;
|
|
885
|
+
declare const NOOP: () => void;
|
|
886
|
+
/**
|
|
887
|
+
* @param obj The object to inspect.
|
|
888
|
+
* @returns True if the argument appears to be a plain object.
|
|
889
|
+
*/
|
|
890
|
+
declare function isPlainObject(obj: any): boolean;
|
|
891
|
+
|
|
892
|
+
interface AsClass<T> {
|
|
893
|
+
new (...args: any[]): T;
|
|
894
|
+
}
|
|
895
|
+
type UnknownObject<T extends object> = Record<string | number | symbol, unknown> & {
|
|
896
|
+
[K in keyof T]: unknown;
|
|
897
|
+
};
|
|
898
|
+
declare function isObject<T extends object>(v: unknown): v is UnknownObject<T>;
|
|
899
|
+
declare function isString(v: unknown): v is string;
|
|
900
|
+
declare function isFunction<T extends (...args: unknown[]) => unknown>(v: unknown): v is T;
|
|
901
|
+
declare function getTag(v: unknown): string;
|
|
902
|
+
declare function isNumber(v: unknown): v is number;
|
|
903
|
+
type MaybeArray<T> = T | T[];
|
|
904
|
+
type MaybePromise<T> = T | PromiseLike<T>;
|
|
905
|
+
type RecursivePartial<T> = {
|
|
906
|
+
[P in keyof T]?: T[P] extends Array<infer I> ? Array<RecursivePartial<I>> : RecursivePartial<T[P]>;
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* An object that performs a cleanup operation when `.dispose()` is called.
|
|
911
|
+
*
|
|
912
|
+
* Some examples of how disposables are used:
|
|
913
|
+
*
|
|
914
|
+
* - An event listener that removes itself when `.dispose()` is called.
|
|
915
|
+
* - The return value from registering a provider. When `.dispose()` is called, the provider is unregistered.
|
|
916
|
+
*/
|
|
917
|
+
interface Disposable {
|
|
918
|
+
dispose(): void;
|
|
919
|
+
}
|
|
920
|
+
declare namespace Disposable {
|
|
921
|
+
function is(thing: any): thing is Disposable;
|
|
922
|
+
function create(func: () => void): Disposable;
|
|
923
|
+
const NULL: Readonly<Disposable>;
|
|
924
|
+
}
|
|
925
|
+
declare class DisposableImpl implements Disposable {
|
|
926
|
+
readonly toDispose: DisposableCollection;
|
|
927
|
+
dispose(): void;
|
|
928
|
+
get disposed(): boolean;
|
|
929
|
+
get onDispose(): Event<void>;
|
|
930
|
+
}
|
|
931
|
+
declare class DisposableCollection implements Disposable {
|
|
932
|
+
protected readonly disposables: (Disposable & {
|
|
933
|
+
_origin: Disposable;
|
|
934
|
+
})[];
|
|
935
|
+
protected readonly onDisposeEmitter: Emitter<void>;
|
|
936
|
+
private _disposed;
|
|
937
|
+
constructor(...toDispose: Disposable[]);
|
|
938
|
+
get onDispose(): Event<void>;
|
|
939
|
+
get disposed(): boolean;
|
|
940
|
+
dispose(): void;
|
|
941
|
+
push(disposable: Disposable): Disposable;
|
|
942
|
+
pushAll(disposables: Disposable[]): Disposable[];
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
interface EventListener$1<T> {
|
|
946
|
+
(args: T): void;
|
|
947
|
+
}
|
|
948
|
+
interface Event<T> {
|
|
949
|
+
(listener: EventListener$1<T>, thisArgs?: any): Disposable;
|
|
950
|
+
}
|
|
951
|
+
declare namespace Event {
|
|
952
|
+
const None: Event<any>;
|
|
953
|
+
}
|
|
954
|
+
declare class Emitter<T = any> {
|
|
955
|
+
static LEAK_WARNING_THRESHHOLD: number;
|
|
956
|
+
private _event?;
|
|
957
|
+
private _listeners?;
|
|
958
|
+
private _disposed;
|
|
959
|
+
get event(): Event<T>;
|
|
960
|
+
fire(event: T): void;
|
|
961
|
+
get disposed(): boolean;
|
|
962
|
+
dispose(): void;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
interface CancellationToken {
|
|
966
|
+
/**
|
|
967
|
+
* A flag signalling is cancellation has been requested.
|
|
968
|
+
*/
|
|
969
|
+
readonly isCancellationRequested: boolean;
|
|
970
|
+
/**
|
|
971
|
+
* An event which fires when cancellation is requested. This event
|
|
972
|
+
* only ever fires `once` as cancellation can only happen once. Listeners
|
|
973
|
+
* that are registered after cancellation will be called (next event loop run),
|
|
974
|
+
* but also only once.
|
|
975
|
+
* @event
|
|
976
|
+
*/
|
|
977
|
+
readonly onCancellationRequested: Event<void>;
|
|
978
|
+
}
|
|
979
|
+
declare namespace CancellationToken {
|
|
980
|
+
function isCancellationToken(thing: unknown): thing is CancellationToken;
|
|
981
|
+
const None: Readonly<CancellationToken>;
|
|
982
|
+
const Cancelled: Readonly<CancellationToken>;
|
|
983
|
+
}
|
|
984
|
+
declare class MutableToken implements CancellationToken {
|
|
985
|
+
private _isCancelled;
|
|
986
|
+
private _emitter?;
|
|
987
|
+
cancel(): void;
|
|
988
|
+
get isCancellationRequested(): boolean;
|
|
989
|
+
get onCancellationRequested(): Event<void>;
|
|
990
|
+
dispose(): void;
|
|
991
|
+
}
|
|
992
|
+
declare class CancellationTokenSource {
|
|
993
|
+
private _token;
|
|
994
|
+
get token(): CancellationToken;
|
|
995
|
+
cancel(): void;
|
|
996
|
+
dispose(): void;
|
|
997
|
+
}
|
|
998
|
+
declare function cancelled(): Error;
|
|
999
|
+
declare function isCancelled(err: Error | undefined): boolean;
|
|
1000
|
+
declare function checkCancelled(token?: CancellationToken): void;
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Simple implementation of the deferred pattern.
|
|
1004
|
+
* An object that exposes a promise and functions to resolve and reject it.
|
|
1005
|
+
*/
|
|
1006
|
+
declare class PromiseDeferred<T> {
|
|
1007
|
+
resolve: (value?: T | PromiseLike<T>) => void;
|
|
1008
|
+
reject: (err?: any) => void;
|
|
1009
|
+
promise: Promise<T>;
|
|
1010
|
+
}
|
|
1011
|
+
declare const Deferred: typeof PromiseDeferred;
|
|
1012
|
+
/**
|
|
1013
|
+
* @returns resolves after a specified number of milliseconds
|
|
1014
|
+
* @throws cancelled if a given token is cancelled before a specified number of milliseconds
|
|
1015
|
+
*/
|
|
1016
|
+
declare function delay(ms: number, token?: Readonly<CancellationToken>): Promise<void>;
|
|
1017
|
+
declare function retry<T>(task: () => Promise<T>, delayTime: number, retries: number, shouldRetry?: (res: T) => boolean): Promise<T>;
|
|
1018
|
+
interface PromiseTask<T> {
|
|
1019
|
+
(): Promise<T>;
|
|
1020
|
+
}
|
|
1021
|
+
interface PromisePoolOpts {
|
|
1022
|
+
intervalCount?: number;
|
|
1023
|
+
intervalTime?: number;
|
|
1024
|
+
retries?: number;
|
|
1025
|
+
retryDelay?: number;
|
|
1026
|
+
}
|
|
1027
|
+
declare class PromisePool {
|
|
1028
|
+
protected opts: Required<PromisePoolOpts>;
|
|
1029
|
+
constructor(opts?: PromisePoolOpts);
|
|
1030
|
+
protected tryToExec<T>(task: PromiseTask<T>, checkIfRetry?: (res: T) => boolean): Promise<T>;
|
|
1031
|
+
/**
|
|
1032
|
+
* @param tasks 执行任务
|
|
1033
|
+
* @param checkIfRetry 判断结果是否需要重试
|
|
1034
|
+
*/
|
|
1035
|
+
run<T>(tasks: PromiseTask<T>[], checkIfRetry?: (res: T) => boolean): Promise<T[]>;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
interface CacheManager<T, ITEM extends CacheOriginItem = CacheOriginItem> extends Disposable {
|
|
1039
|
+
get(): T;
|
|
1040
|
+
getMore(count: number, autoDelete?: boolean): T[];
|
|
1041
|
+
getMoreByItemKeys(item: ITEM[]): T[];
|
|
1042
|
+
getMoreByItems(item: ITEM[]): T[];
|
|
1043
|
+
/**
|
|
1044
|
+
* 从缓存中获取
|
|
1045
|
+
* @param key
|
|
1046
|
+
*/
|
|
1047
|
+
getFromCacheByKey(key: string): T | undefined;
|
|
1048
|
+
/**
|
|
1049
|
+
* 获取所有缓存
|
|
1050
|
+
*/
|
|
1051
|
+
getFromCache(): Cache<T>[];
|
|
1052
|
+
/**
|
|
1053
|
+
* 清空缓存数据
|
|
1054
|
+
*/
|
|
1055
|
+
clear(): void;
|
|
1056
|
+
}
|
|
1057
|
+
interface ShortCache<T> {
|
|
1058
|
+
get(fn: () => T): T;
|
|
1059
|
+
}
|
|
1060
|
+
interface WeakCache {
|
|
1061
|
+
get(key: any): any;
|
|
1062
|
+
save(key: any, value: any): void;
|
|
1063
|
+
isChanged(key: any, value: any): boolean;
|
|
1064
|
+
}
|
|
1065
|
+
interface CacheOpts {
|
|
1066
|
+
deleteLimit?: number;
|
|
1067
|
+
}
|
|
1068
|
+
interface CacheOriginItem {
|
|
1069
|
+
key?: any;
|
|
1070
|
+
}
|
|
1071
|
+
type Cache<T> = {
|
|
1072
|
+
[P in keyof T]: T[P];
|
|
1073
|
+
} & {
|
|
1074
|
+
dispose?: () => void;
|
|
1075
|
+
key?: any;
|
|
1076
|
+
};
|
|
1077
|
+
/**
|
|
1078
|
+
* 缓存工具:
|
|
1079
|
+
* 1. 可延迟按需创建,提升性能
|
|
1080
|
+
* 2. 可支持多个或单个,有些动态创建多个的场景可以共享已有的实例,提升性能
|
|
1081
|
+
* 3. 自动删除,超过一定的数目会自动做清空回收
|
|
1082
|
+
*
|
|
1083
|
+
* @example
|
|
1084
|
+
* function htmlFactory<HTMLElement>(): Cache<HTMLElement> {
|
|
1085
|
+
* const el = document.createElement('div')
|
|
1086
|
+
* return Cache.assign(el, { dispose: () => el.remove() })
|
|
1087
|
+
* }
|
|
1088
|
+
* const htmlCache = Cache.create<HTMLElement>(htmlFactory)
|
|
1089
|
+
* console.log(htmlCache.get() === htmlCache.get()) // true
|
|
1090
|
+
* console.log(htmlCache.getMore(3)) // [HTMLElement, HTMLElement, HTMLElement]
|
|
1091
|
+
* console.log(htmlCache.getMore(2)) // [HTMLElement, HTMLElement] 自动删除第三个
|
|
1092
|
+
*/
|
|
1093
|
+
declare namespace Cache {
|
|
1094
|
+
function create<T, ITEM extends CacheOriginItem = CacheOriginItem>(cacheFactory: (item?: ITEM) => Cache<T>, opts?: CacheOpts): CacheManager<T, ITEM>;
|
|
1095
|
+
function assign<T = any>(target: T, fn: Disposable): Cache<T>;
|
|
1096
|
+
/**
|
|
1097
|
+
* 短存储
|
|
1098
|
+
* @param timeout
|
|
1099
|
+
*/
|
|
1100
|
+
function createShortCache<T>(timeout?: number): ShortCache<T>;
|
|
1101
|
+
function createWeakCache(): WeakCache;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
declare namespace Compare {
|
|
1105
|
+
/**
|
|
1106
|
+
* 比较,默认浅比较
|
|
1107
|
+
* @param oldProps
|
|
1108
|
+
* @param newProps
|
|
1109
|
+
* @param depth - 比较的深度,默认是 1
|
|
1110
|
+
* @param partial - 比较对象的局部,默认 true
|
|
1111
|
+
*/
|
|
1112
|
+
function isChanged(oldProps: any, newProps: any, depth?: number, partial?: boolean): boolean;
|
|
1113
|
+
/**
|
|
1114
|
+
* 深度比较
|
|
1115
|
+
* @param oldProps
|
|
1116
|
+
* @param newProps
|
|
1117
|
+
* @param partial - 比较对象的局部,默认 true
|
|
1118
|
+
*/
|
|
1119
|
+
function isDeepChanged(oldProps: any, newProps: any, partial?: boolean): boolean;
|
|
1120
|
+
function isArrayShallowChanged(arr1: any[], arr2: any[]): boolean;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
type CSSStyle = {
|
|
1124
|
+
[P in keyof CSSStyleDeclaration]?: string | number | undefined;
|
|
1125
|
+
};
|
|
1126
|
+
interface DOMCache extends HTMLElement, Disposable {
|
|
1127
|
+
setStyle(style: CSSStyle): void;
|
|
1128
|
+
key?: string | number;
|
|
1129
|
+
}
|
|
1130
|
+
declare namespace domUtils {
|
|
1131
|
+
function toPixel(num: number): string;
|
|
1132
|
+
function fromPercent(percent: string): number;
|
|
1133
|
+
function toPercent(percent: number): string;
|
|
1134
|
+
function enableEvent(element: HTMLDivElement): void;
|
|
1135
|
+
function disableEvent(element: HTMLDivElement): void;
|
|
1136
|
+
function createElement<T extends HTMLElement>(ele: string, ...classNames: string[]): T;
|
|
1137
|
+
function createDivWithClass(...classNames: string[]): HTMLDivElement;
|
|
1138
|
+
function addClass(element: Element, ...classNames: string[]): void;
|
|
1139
|
+
function delClass(element: Element, ...classNames: string[]): void;
|
|
1140
|
+
function coverClass(element: Element, ...classNames: string[]): void;
|
|
1141
|
+
function clearChildren(container: HTMLDivElement): void;
|
|
1142
|
+
function translatePercent(node: HTMLDivElement, x: number, y: number): void;
|
|
1143
|
+
function translateXPercent(node: HTMLDivElement, x: number): void;
|
|
1144
|
+
function translateYPercent(node: HTMLDivElement, y: number): void;
|
|
1145
|
+
function setStyle(node: HTMLElement, styles: CSSStyle): void;
|
|
1146
|
+
function classNameWithPrefix(prefix: string): (key: string, opts?: any) => string;
|
|
1147
|
+
function addStandardDisposableListener(dom: HTMLElement | HTMLDocument, type: string, listener: EventListenerOrEventListenerObject | any, options?: boolean | any): Disposable;
|
|
1148
|
+
/**
|
|
1149
|
+
* dom 缓存
|
|
1150
|
+
* @param parent
|
|
1151
|
+
* @param className
|
|
1152
|
+
*/
|
|
1153
|
+
function createDOMCache<T extends DOMCache = DOMCache>(parent: HTMLElement, className: string | (() => HTMLElement), children?: string): CacheManager<T>;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
type LocalId = number;
|
|
1157
|
+
declare function generateLocalId(): LocalId;
|
|
1158
|
+
declare function _setIdx(idx: number): void;
|
|
1159
|
+
|
|
1160
|
+
declare function iterToArray<T = any>(iter: IterableIterator<T>): T[];
|
|
1161
|
+
declare function arrayToSet(arr: any[]): Set<any>;
|
|
1162
|
+
/**
|
|
1163
|
+
* @see https://stackoverflow.com/a/9229821
|
|
1164
|
+
* export function arrayUnion(arr: any[]): any[] {
|
|
1165
|
+
* return [...new Set(arr)]
|
|
1166
|
+
* }
|
|
1167
|
+
*/
|
|
1168
|
+
declare function arrayUnion(arr: any[]): any[];
|
|
1169
|
+
|
|
1170
|
+
declare function bindContributions(bind: interfaces.Bind, target: any, contribs: any[]): void;
|
|
1171
|
+
|
|
1172
|
+
type RequestFn = (...args: any[]) => Promise<any>;
|
|
1173
|
+
/**
|
|
1174
|
+
* 请求缓存
|
|
1175
|
+
* @param req
|
|
1176
|
+
*/
|
|
1177
|
+
declare const RequestCache: Map<any, Promise<any>>;
|
|
1178
|
+
declare function clearRequestCache(): void;
|
|
1179
|
+
declare function requestWithMemo(req: RequestFn, cacheTime?: number, createCacheKey?: (...args: any[]) => any): RequestFn;
|
|
1180
|
+
|
|
1181
|
+
type FuncMaybePromise<D> = (d: D, ...others: any[]) => MaybePromise<D>;
|
|
1182
|
+
type FuncPromise<D> = (d: D, ...others: any[]) => Promise<D>;
|
|
1183
|
+
type Func<D> = (d: D, ...others: any[]) => D;
|
|
1184
|
+
declare function composeAsync<D>(...fns: FuncMaybePromise<D>[]): FuncPromise<D>;
|
|
1185
|
+
declare function compose<D>(...fns: Func<D>[]): Func<D>;
|
|
1186
|
+
|
|
1187
|
+
declare const ContributionProvider: unique symbol;
|
|
1188
|
+
interface ContributionProvider<T extends object> {
|
|
1189
|
+
getContributions(): T[];
|
|
1190
|
+
forEach(fn: (v: T) => void): void;
|
|
1191
|
+
}
|
|
1192
|
+
declare function bindContributionProvider(bind: interfaces.Bind, id: symbol): void;
|
|
1193
|
+
|
|
1194
|
+
type EventListener<K extends keyof HTMLElementEventMap> = (this: HTMLElement, event: HTMLElementEventMap[K]) => any;
|
|
1195
|
+
type EventListenerOrEventListenerObject$1<K extends keyof HTMLElementEventMap> = EventListener<K>;
|
|
1196
|
+
declare function addEventListener<K extends keyof HTMLElementEventMap>(element: HTMLElement, type: K, listener: EventListenerOrEventListenerObject$1<K>, useCapture?: boolean): Disposable;
|
|
1197
|
+
|
|
1198
|
+
declare class Logger {
|
|
1199
|
+
isDevEnv(): boolean;
|
|
1200
|
+
info(...props: any): void;
|
|
1201
|
+
log(...props: any): void;
|
|
1202
|
+
error(...props: any): void;
|
|
1203
|
+
warn(...props: any): void;
|
|
1204
|
+
}
|
|
1205
|
+
declare const logger: Logger;
|
|
1206
|
+
|
|
1207
|
+
declare function createStyleElement(styleId: string, container?: HTMLElement): HTMLStyleElement;
|
|
1208
|
+
declare const DecorationStyle: {
|
|
1209
|
+
createStyleElement: typeof createStyleElement;
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
declare function useRefresh(defaultValue?: any): (v?: any) => void;
|
|
1213
|
+
|
|
1214
|
+
export { Angle, type AsClass, type CSSStyle, Cache, type CacheManager, type CacheOpts, type CacheOriginItem, CancellationToken, CancellationTokenSource, Circle, Compare, ContributionProvider, CropSchemaDecoration, DEG_TO_RAD, type DOMCache, DecorationStyle, Deferred, Disposable, DisposableCollection, DisposableImpl, Emitter, Event, type EventListener$1 as EventListener, type FlipSchema, FlipSchemaDecoration, type IPoint, type ISize, type LocalId, type MarginSchema, Matrix, type MaybeArray, type MaybePromise, MutableToken, NOOP, OBBRect, type OpacitySchema, OpacitySchemaDecoration, type OriginSchema, OriginSchemaDecoration, PI, PI_2, PaddingSchema, PaddingSchemaDecoration, Point, type PositionSchema, PositionSchemaDecoration, PromiseDeferred, PromisePool, type PromisePoolOpts, type PromiseTask, RAD_TO_DEG, Rectangle, RectangleAlignTitle, RectangleAlignType, type RecursivePartial, RequestCache, type RotationSchema, RotationSchemaDecoration, SHAPES, type ScaleSchema, ScaleSchemaDecoration, Schema, SchemaDecoration, type SchemaType, type ScrollSchema, type ShadowSchema, ShadowSchemaDecoration, type ShortCache, SizeSchema, SizeSchemaDecoration, type SkewSchema, SkewSchemaDecoration, TintSchema, TintSchemaDecoration, Transform, TransformSchema, TransformSchemaDecoration, type WeakCache, _setIdx, addEventListener, arrayToSet, arrayUnion, bindContributionProvider, bindContributions, cancelled, checkCancelled, clearRequestCache, compose, composeAsync, deepFreeze, delay, domUtils, each, filter, generateLocalId, getByKey, getTag, isCancelled, isEmpty, isFunction, isNumber, isObject, isPlainObject, isString, iterToArray, logger, mapKeys, mapValues, notEmpty, omit, pick, reduce, requestWithMemo, retry, setByKey, useRefresh, values };
|