@flowgram.ai/utils 0.1.1

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.
@@ -0,0 +1,2493 @@
1
+ // src/math/const.ts
2
+ var { PI } = Math;
3
+ var PI_2 = PI * 2;
4
+ var RAD_TO_DEG = 180 / PI;
5
+ var DEG_TO_RAD = PI / 180;
6
+ var SHAPES = /* @__PURE__ */ ((SHAPES2) => {
7
+ SHAPES2[SHAPES2["POLY"] = 0] = "POLY";
8
+ SHAPES2[SHAPES2["RECT"] = 1] = "RECT";
9
+ SHAPES2[SHAPES2["CIRC"] = 2] = "CIRC";
10
+ SHAPES2[SHAPES2["ELIP"] = 3] = "ELIP";
11
+ SHAPES2[SHAPES2["RREC"] = 4] = "RREC";
12
+ return SHAPES2;
13
+ })(SHAPES || {});
14
+
15
+ // src/math/Vector2.ts
16
+ var Vector2 = class _Vector2 {
17
+ constructor(x = 0, y = 0) {
18
+ this.x = x;
19
+ this.y = y;
20
+ }
21
+ /**
22
+ * 向量减法
23
+ */
24
+ sub(v) {
25
+ return new _Vector2(this.x - v.x, this.y - v.y);
26
+ }
27
+ /**
28
+ * 向量点乘
29
+ */
30
+ dot(v) {
31
+ return this.x * v.x + this.y * v.y;
32
+ }
33
+ /**
34
+ * 向量叉乘
35
+ */
36
+ // cross(v: Vector2): number {
37
+ // }
38
+ };
39
+
40
+ // src/math/Point.ts
41
+ var Point = class _Point {
42
+ constructor(x = 0, y = 0) {
43
+ this.x = x;
44
+ this.y = y;
45
+ }
46
+ /**
47
+ * Creates a clone of this point
48
+ *
49
+ * @return {Point} a copy of the point
50
+ */
51
+ clone() {
52
+ return new _Point(this.x, this.y);
53
+ }
54
+ /**
55
+ * Copies x and y from the given point
56
+ *
57
+ * @param {IPoint} p - The point to copy from
58
+ * @returns {this} Returns itself.
59
+ */
60
+ copyFrom(p) {
61
+ this.set(p.x, p.y);
62
+ return this;
63
+ }
64
+ /**
65
+ * Copies x and y into the given point
66
+ *
67
+ * @param {IPoint} p - The point to copy.
68
+ * @returns {IPoint} Given point with values updated
69
+ */
70
+ copyTo(p) {
71
+ p.x = this.x;
72
+ p.y = this.y;
73
+ return p;
74
+ }
75
+ /**
76
+ * Returns true if the given point is equal to this point
77
+ *
78
+ * @param {IPoint} p - The point to check
79
+ * @returns {boolean} Whether the given point equal to this point
80
+ */
81
+ equals(p) {
82
+ return p.x === this.x && p.y === this.y;
83
+ }
84
+ /**
85
+ * Sets the point to a new x and y position.
86
+ * If y is omitted, both x and y will be set to x.
87
+ *
88
+ * @param {number} [x=0] - position of the point on the x axis
89
+ * @param {number} [y=x] - position of the point on the y axis
90
+ * @returns {this} Returns itself.
91
+ */
92
+ set(x = 0, y = x) {
93
+ this.x = x;
94
+ this.y = y;
95
+ return this;
96
+ }
97
+ };
98
+ ((Point2) => {
99
+ Point2.EMPTY = { x: 0, y: 0 };
100
+ function getDistance(p1, p2) {
101
+ return Math.sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2);
102
+ }
103
+ Point2.getDistance = getDistance;
104
+ function getMiddlePoint(p1, p2) {
105
+ return getRatioPoint(p1, p2, 0.5);
106
+ }
107
+ Point2.getMiddlePoint = getMiddlePoint;
108
+ function getRatioPoint(p1, p2, ratio) {
109
+ return {
110
+ x: p1.x + ratio * (p2.x - p1.x),
111
+ y: p1.y + ratio * (p2.y - p1.y)
112
+ };
113
+ }
114
+ Point2.getRatioPoint = getRatioPoint;
115
+ function fixZero(output) {
116
+ if (output.x === 0) output.x = 0;
117
+ if (output.y === 0) output.y = 0;
118
+ return output;
119
+ }
120
+ Point2.fixZero = fixZero;
121
+ function move(current, m) {
122
+ return {
123
+ x: current.x + (m.x || 0),
124
+ y: current.y + (m.y || 0)
125
+ };
126
+ }
127
+ Point2.move = move;
128
+ function moveDistanceToDirection(current, direction, distance) {
129
+ const deltaX = direction.x - current.x;
130
+ const deltaY = direction.y - current.y;
131
+ const distanceX = deltaX === 0 ? 0 : Math.sqrt(distance ** 2 / (1 + deltaY ** 2 / deltaX ** 2));
132
+ const moveX = deltaX > 0 ? distanceX : -distanceX;
133
+ const distanceY = deltaX === 0 ? distance : Math.abs(distanceX * deltaY / deltaX);
134
+ const moveY = deltaY > 0 ? distanceY : -distanceY;
135
+ return {
136
+ x: current.x + moveX,
137
+ y: current.y + moveY
138
+ };
139
+ }
140
+ Point2.moveDistanceToDirection = moveDistanceToDirection;
141
+ })(Point || (Point = {}));
142
+
143
+ // src/math/shapes/Rectangle.ts
144
+ var Rectangle = class _Rectangle {
145
+ /**
146
+ * @param [x] - The X coordinate of the upper-left corner of the rectangle
147
+ * @param [y] - The Y coordinate of the upper-left corner of the rectangle
148
+ * @param [width] - The overall width of this rectangle
149
+ * @param [height] - The overall height of this rectangle
150
+ */
151
+ constructor(x = 0, y = 0, width = 0, height = 0) {
152
+ this.x = x;
153
+ this.y = y;
154
+ this.width = width;
155
+ this.height = height;
156
+ /**
157
+ * The type of the object, mainly used to avoid `instanceof` checks
158
+ */
159
+ this.type = 1 /* RECT */;
160
+ }
161
+ // static _empty: Rectangle = Object.freeze(new Rectangle(0, 0, 0, 0))
162
+ /**
163
+ * A constant empty rectangle. MUST NOT modify properties!
164
+ */
165
+ static get EMPTY() {
166
+ return new _Rectangle(0, 0, 0, 0);
167
+ }
168
+ get left() {
169
+ return this.x;
170
+ }
171
+ get right() {
172
+ return this.x + this.width;
173
+ }
174
+ get top() {
175
+ return this.y;
176
+ }
177
+ get bottom() {
178
+ return this.y + this.height;
179
+ }
180
+ /**
181
+ * Creates a clone of this Rectangle.
182
+ *
183
+ * @return a copy of the rectangle
184
+ */
185
+ clone() {
186
+ return new _Rectangle(this.x, this.y, this.width, this.height);
187
+ }
188
+ /**
189
+ * Copies another rectangle to this one.
190
+ *
191
+ * @return Returns itself.
192
+ */
193
+ copyFrom(rectangle) {
194
+ this.x = rectangle.x;
195
+ this.y = rectangle.y;
196
+ this.width = rectangle.width;
197
+ this.height = rectangle.height;
198
+ return this;
199
+ }
200
+ /**
201
+ * Copies this rectangle to another one.
202
+ *
203
+ * @return Returns given rectangle.
204
+ */
205
+ copyTo(rectangle) {
206
+ rectangle.x = this.x;
207
+ rectangle.y = this.y;
208
+ rectangle.width = this.width;
209
+ rectangle.height = this.height;
210
+ return rectangle;
211
+ }
212
+ /**
213
+ * Checks whether the x and y coordinates given are contained within this Rectangle
214
+ *
215
+ * @param x - The X coordinate of the point to test
216
+ * @param y - The Y coordinate of the point to test
217
+ * @return Whether the x/y coordinates are within this Rectangle
218
+ */
219
+ contains(x, y) {
220
+ if (this.width <= 0 || this.height <= 0) {
221
+ return false;
222
+ }
223
+ if (x >= this.x && x <= this.right) {
224
+ if (y >= this.y && y <= this.bottom) {
225
+ return true;
226
+ }
227
+ }
228
+ return false;
229
+ }
230
+ isEqual(rect) {
231
+ return this.x === rect.x && this.y === rect.y && this.width === rect.width && this.height === rect.height;
232
+ }
233
+ containsRectangle(rect) {
234
+ return rect.left >= this.left && rect.right <= this.right && rect.top >= this.top && rect.bottom <= this.bottom;
235
+ }
236
+ /**
237
+ * Pads the rectangle making it grow in all directions.
238
+ * If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
239
+ *
240
+ * @param [paddingX] - The horizontal padding amount.
241
+ * @param [paddingY] - The vertical padding amount.
242
+ */
243
+ pad(paddingX = 0, paddingY = paddingX) {
244
+ this.x -= paddingX;
245
+ this.y -= paddingY;
246
+ this.width += paddingX * 2;
247
+ this.height += paddingY * 2;
248
+ return this;
249
+ }
250
+ /**
251
+ * Fits this rectangle around the passed one.
252
+ * Intersection 交集
253
+ */
254
+ fit(rectangle) {
255
+ const x1 = Math.max(this.x, rectangle.x);
256
+ const x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
257
+ const y1 = Math.max(this.y, rectangle.y);
258
+ const y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
259
+ this.x = x1;
260
+ this.width = Math.max(x2 - x1, 0);
261
+ this.y = y1;
262
+ this.height = Math.max(y2 - y1, 0);
263
+ return this;
264
+ }
265
+ /**
266
+ * Enlarges rectangle that way its corners lie on grid
267
+ */
268
+ ceil(resolution = 1, precision = 1e-3) {
269
+ const x2 = Math.ceil((this.x + this.width - precision) * resolution) / resolution;
270
+ const y2 = Math.ceil((this.y + this.height - precision) * resolution) / resolution;
271
+ this.x = Math.floor((this.x + precision) * resolution) / resolution;
272
+ this.y = Math.floor((this.y + precision) * resolution) / resolution;
273
+ this.width = x2 - this.x;
274
+ this.height = y2 - this.y;
275
+ return this;
276
+ }
277
+ /**
278
+ * Enlarges this rectangle to include the passed rectangle.
279
+ */
280
+ enlarge(rectangle) {
281
+ const x1 = Math.min(this.x, rectangle.x);
282
+ const x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
283
+ const y1 = Math.min(this.y, rectangle.y);
284
+ const y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
285
+ this.x = x1;
286
+ this.width = x2 - x1;
287
+ this.y = y1;
288
+ this.height = y2 - y1;
289
+ return this;
290
+ }
291
+ get center() {
292
+ return {
293
+ x: this.x + this.width / 2,
294
+ y: this.y + this.height / 2
295
+ };
296
+ }
297
+ get rightBottom() {
298
+ return {
299
+ x: this.right,
300
+ y: this.bottom
301
+ };
302
+ }
303
+ get leftBottom() {
304
+ return {
305
+ x: this.left,
306
+ y: this.bottom
307
+ };
308
+ }
309
+ get rightTop() {
310
+ return {
311
+ x: this.right,
312
+ y: this.top
313
+ };
314
+ }
315
+ get leftTop() {
316
+ return {
317
+ x: this.left,
318
+ y: this.top
319
+ };
320
+ }
321
+ get bottomCenter() {
322
+ return {
323
+ x: this.x + this.width / 2,
324
+ y: this.bottom
325
+ };
326
+ }
327
+ get topCenter() {
328
+ return {
329
+ x: this.x + this.width / 2,
330
+ y: this.top
331
+ };
332
+ }
333
+ get rightCenter() {
334
+ return {
335
+ x: this.right,
336
+ y: this.y + this.height / 2
337
+ };
338
+ }
339
+ get leftCenter() {
340
+ return {
341
+ x: this.left,
342
+ y: this.y + this.height / 2
343
+ };
344
+ }
345
+ update(fn) {
346
+ return fn(this);
347
+ }
348
+ get crossDistance() {
349
+ return Point.getDistance(this.leftTop, this.rightBottom);
350
+ }
351
+ toStyleStr() {
352
+ return `left: ${this.x}px; top: ${this.y}px; width: ${this.width}px; height: ${this.height}px;`;
353
+ }
354
+ withPadding(padding) {
355
+ this.x -= padding.left;
356
+ this.y -= padding.top;
357
+ this.width += padding.left + padding.right;
358
+ this.height += padding.top + padding.bottom;
359
+ return this;
360
+ }
361
+ withoutPadding(padding) {
362
+ this.x += padding.left;
363
+ this.y += padding.top;
364
+ this.width = this.width - padding.left - padding.right;
365
+ this.height = this.height - padding.top - padding.bottom;
366
+ return this;
367
+ }
368
+ withHeight(height) {
369
+ this.height = height;
370
+ return this;
371
+ }
372
+ clearSpace() {
373
+ this.width = 0;
374
+ this.height = 0;
375
+ return this;
376
+ }
377
+ };
378
+ var RectangleAlignType = /* @__PURE__ */ ((RectangleAlignType2) => {
379
+ RectangleAlignType2["ALIGN_LEFT"] = "align-left";
380
+ RectangleAlignType2["ALIGN_CENTER"] = "align-center";
381
+ RectangleAlignType2["ALIGN_RIGHT"] = "align-right";
382
+ RectangleAlignType2["ALIGN_TOP"] = "align-top";
383
+ RectangleAlignType2["ALIGN_MIDDLE"] = "align-middle";
384
+ RectangleAlignType2["ALIGN_BOTTOM"] = "align-bottom";
385
+ RectangleAlignType2["DISTRIBUTE_HORIZONTAL"] = "distribute-horizontal";
386
+ RectangleAlignType2["DISTRIBUTE_VERTICAL"] = "distribute-vertical";
387
+ return RectangleAlignType2;
388
+ })(RectangleAlignType || {});
389
+ var RectangleAlignTitle = /* @__PURE__ */ ((RectangleAlignTitle2) => {
390
+ RectangleAlignTitle2["ALIGN_LEFT"] = "\u5DE6\u5BF9\u9F50";
391
+ RectangleAlignTitle2["ALIGN_CENTER"] = "\u5DE6\u53F3\u5C45\u4E2D\u5BF9\u9F50";
392
+ RectangleAlignTitle2["ALIGN_RIGHT"] = "\u53F3\u5BF9\u9F50";
393
+ RectangleAlignTitle2["ALIGN_TOP"] = "\u4E0A\u5BF9\u9F50";
394
+ RectangleAlignTitle2["ALIGN_MIDDLE"] = "\u4E0A\u4E0B\u5C45\u4E2D\u5BF9\u9F50";
395
+ RectangleAlignTitle2["ALIGN_BOTTOM"] = "\u4E0B\u5BF9\u9F50";
396
+ RectangleAlignTitle2["DISTRIBUTE_HORIZONTAL"] = "\u6C34\u5E73\u5E73\u5747\u5206\u5E03";
397
+ RectangleAlignTitle2["DISTRIBUTE_VERTICAL"] = "\u5782\u76F4\u5E73\u5747\u5206\u5E03";
398
+ return RectangleAlignTitle2;
399
+ })(RectangleAlignTitle || {});
400
+ ((Rectangle2) => {
401
+ function align(rectangles, type) {
402
+ if (rectangles.length <= 1) return rectangles;
403
+ switch (type) {
404
+ /**
405
+ * 下对齐
406
+ */
407
+ case "align-bottom" /* ALIGN_BOTTOM */:
408
+ const maxBottom = Math.max(...rectangles.map((r) => r.bottom));
409
+ rectangles.forEach((rect) => {
410
+ rect.y = maxBottom - rect.height;
411
+ });
412
+ break;
413
+ /**
414
+ * 左右居中对齐
415
+ */
416
+ case "align-center" /* ALIGN_CENTER */:
417
+ const centerX = enlarge(rectangles).center.x;
418
+ rectangles.forEach((rect) => {
419
+ rect.x = centerX - rect.width / 2;
420
+ });
421
+ break;
422
+ /**
423
+ * 左对齐
424
+ */
425
+ case "align-left" /* ALIGN_LEFT */:
426
+ const minLeft = Math.min(...rectangles.map((r) => r.left));
427
+ rectangles.forEach((rect) => {
428
+ rect.x = minLeft;
429
+ });
430
+ break;
431
+ /**
432
+ * 上下居中对齐
433
+ */
434
+ case "align-middle" /* ALIGN_MIDDLE */:
435
+ const centerY = enlarge(rectangles).center.y;
436
+ rectangles.forEach((rect) => {
437
+ rect.y = centerY - rect.height / 2;
438
+ });
439
+ break;
440
+ /**
441
+ * 右对齐
442
+ */
443
+ case "align-right" /* ALIGN_RIGHT */:
444
+ const maxRight = Math.max(...rectangles.map((r) => r.right));
445
+ rectangles.forEach((rect) => {
446
+ rect.x = maxRight - rect.width;
447
+ });
448
+ break;
449
+ /**
450
+ * 上对齐
451
+ */
452
+ case "align-top" /* ALIGN_TOP */:
453
+ const minTop = Math.min(...rectangles.map((r) => r.top));
454
+ rectangles.forEach((rect) => {
455
+ rect.y = minTop;
456
+ });
457
+ break;
458
+ /**
459
+ * 水平平均分布
460
+ */
461
+ case "distribute-horizontal" /* DISTRIBUTE_HORIZONTAL */:
462
+ if (rectangles.length <= 2) break;
463
+ const sort = rectangles.slice().sort((r1, r2) => r1.left - r2.left);
464
+ const bounds = enlarge(rectangles);
465
+ const space = rectangles.reduce((s, rect) => s - rect.width, bounds.width) / (rectangles.length - 1);
466
+ sort.reduce((left, rect) => {
467
+ rect.x = left;
468
+ return left + rect.width + space;
469
+ }, bounds.x);
470
+ break;
471
+ /**
472
+ * 垂直平均分布
473
+ */
474
+ case "distribute-vertical" /* DISTRIBUTE_VERTICAL */:
475
+ if (rectangles.length <= 2) break;
476
+ const sort2 = rectangles.slice().sort((r1, r2) => r1.top - r2.top);
477
+ const bounds2 = enlarge(rectangles);
478
+ const space2 = rectangles.reduce((s, rect) => s - rect.height, bounds2.height) / (rectangles.length - 1);
479
+ sort2.reduce((top, rect) => {
480
+ rect.y = top;
481
+ return top + rect.height + space2;
482
+ }, bounds2.y);
483
+ break;
484
+ default:
485
+ break;
486
+ }
487
+ return rectangles;
488
+ }
489
+ Rectangle2.align = align;
490
+ function enlarge(rectangles) {
491
+ const result = Rectangle2.EMPTY.clone();
492
+ if (!rectangles.length) return result;
493
+ const lefts = [];
494
+ const tops = [];
495
+ const rights = [];
496
+ const bottoms = [];
497
+ rectangles.forEach((r) => {
498
+ lefts.push(r.left);
499
+ rights.push(r.right);
500
+ bottoms.push(r.bottom);
501
+ tops.push(r.top);
502
+ });
503
+ const left = Math.min.apply(Math, lefts);
504
+ const right = Math.max.apply(Math, rights);
505
+ const top = Math.min.apply(Math, tops);
506
+ const bottom = Math.max.apply(Math, bottoms);
507
+ result.x = left;
508
+ result.width = right - left;
509
+ result.y = top;
510
+ result.height = bottom - top;
511
+ return result;
512
+ }
513
+ Rectangle2.enlarge = enlarge;
514
+ function intersects(target1, target2, direction) {
515
+ const left1 = target1.left;
516
+ const top1 = target1.top;
517
+ const right1 = target1.right;
518
+ const bottom1 = target1.bottom;
519
+ const left2 = target2.left;
520
+ const top2 = target2.top;
521
+ const right2 = target2.right;
522
+ const bottom2 = target2.bottom;
523
+ if (direction === "horizontal") return right1 > left2 && left1 < right2;
524
+ if (direction === "vertical") return bottom1 > top2 && top1 < bottom2;
525
+ if (right1 > left2 && left1 < right2) {
526
+ if (bottom1 > top2 && top1 < bottom2) {
527
+ return true;
528
+ }
529
+ }
530
+ return false;
531
+ }
532
+ Rectangle2.intersects = intersects;
533
+ function intersectsWithRotation(rect1, rotate1, rect2, rotate2) {
534
+ const obb1 = new OBBRect(rect1.center, rect1.width, rect1.height, rotate1);
535
+ const obb2 = new OBBRect(rect2.center, rect2.width, rect2.height, rotate2);
536
+ const nv = obb1.centerPoint.sub(obb2.centerPoint);
537
+ const axisA1 = obb1.axesX;
538
+ if (obb1.getProjectionRadius(axisA1) + obb2.getProjectionRadius(axisA1) <= Math.abs(nv.dot(axisA1)))
539
+ return false;
540
+ const axisA2 = obb1.axesY;
541
+ if (obb1.getProjectionRadius(axisA2) + obb2.getProjectionRadius(axisA2) <= Math.abs(nv.dot(axisA2)))
542
+ return false;
543
+ const axisB1 = obb2.axesX;
544
+ if (obb1.getProjectionRadius(axisB1) + obb2.getProjectionRadius(axisB1) <= Math.abs(nv.dot(axisB1)))
545
+ return false;
546
+ const axisB2 = obb2.axesY;
547
+ if (obb1.getProjectionRadius(axisB2) + obb2.getProjectionRadius(axisB2) <= Math.abs(nv.dot(axisB2)))
548
+ return false;
549
+ return true;
550
+ }
551
+ Rectangle2.intersectsWithRotation = intersectsWithRotation;
552
+ function isViewportVisible(rect, viewport, rotation = 0, isContains = false) {
553
+ if (isContains) {
554
+ return viewport.containsRectangle(rect);
555
+ }
556
+ if (rotation === 0) return Rectangle2.intersects(rect, viewport);
557
+ return Rectangle2.intersectsWithRotation(rect, rotation, viewport, 0);
558
+ }
559
+ Rectangle2.isViewportVisible = isViewportVisible;
560
+ function setViewportVisible(bounds, viewport, padding = 0) {
561
+ const { left: tLeft, right: tRight, top: tTop, bottom: tBottom, width, height } = bounds;
562
+ const { left: vLeft, right: vRight, top: vTop, bottom: vBottom } = viewport;
563
+ if (tLeft <= vLeft) {
564
+ bounds.x = vLeft + padding;
565
+ } else if (tRight >= vRight) {
566
+ bounds.x = vRight - padding - width;
567
+ }
568
+ if (tTop <= vTop) {
569
+ bounds.y = vTop + padding;
570
+ } else if (tBottom >= vBottom) {
571
+ bounds.y = vBottom - padding - height;
572
+ }
573
+ return bounds;
574
+ }
575
+ Rectangle2.setViewportVisible = setViewportVisible;
576
+ function createRectangleWithTwoPoints(point1, point2) {
577
+ const x = point1.x < point2.x ? point1.x : point2.x;
578
+ const y = point1.y < point2.y ? point1.y : point2.y;
579
+ const width = Math.abs(point1.x - point2.x);
580
+ const height = Math.abs(point1.y - point2.y);
581
+ return new Rectangle2(x, y, width, height);
582
+ }
583
+ Rectangle2.createRectangleWithTwoPoints = createRectangleWithTwoPoints;
584
+ })(Rectangle || (Rectangle = {}));
585
+ var OBBRect = class {
586
+ /**
587
+ * @param rotation in radian
588
+ */
589
+ constructor(centerPoint, width, height, rotation) {
590
+ this.width = width;
591
+ this.height = height;
592
+ this.centerPoint = new Vector2(centerPoint.x, centerPoint.y);
593
+ this.axesX = new Vector2(Math.cos(rotation), Math.sin(rotation));
594
+ this.axesY = new Vector2(-1 * this.axesX.y, this.axesX.x);
595
+ }
596
+ /**
597
+ * 计算投影半径
598
+ */
599
+ getProjectionRadius(axis) {
600
+ return this.width / 2 * Math.abs(axis.dot(this.axesX)) + this.height / 2 * Math.abs(axis.dot(this.axesY));
601
+ }
602
+ };
603
+
604
+ // src/math/shapes/Circle.ts
605
+ var Circle = class _Circle {
606
+ /**
607
+ * @param x Circle center x
608
+ * @param y Circle center y
609
+ */
610
+ constructor(x = 0, y = 0, radius = 0) {
611
+ this.x = x;
612
+ this.y = y;
613
+ this.radius = radius;
614
+ /**
615
+ * The type of the object, mainly used to avoid `instanceof` checks
616
+ */
617
+ this.type = 2 /* CIRC */;
618
+ }
619
+ /**
620
+ * Creates a clone of this Circle instance
621
+ *
622
+ * @return a copy of the Circle
623
+ */
624
+ clone() {
625
+ return new _Circle(this.x, this.y, this.radius);
626
+ }
627
+ /**
628
+ * Checks whether the x and y coordinates given are contained within this circle
629
+ *
630
+ * @return Whether the (x, y) coordinates are within this Circle
631
+ */
632
+ contains(x, y) {
633
+ if (this.radius <= 0) {
634
+ return false;
635
+ }
636
+ const r2 = this.radius * this.radius;
637
+ let dx = this.x - x;
638
+ let dy = this.y - y;
639
+ dx *= dx;
640
+ dy *= dy;
641
+ return dx + dy <= r2;
642
+ }
643
+ /**
644
+ * Returns the framing rectangle of the circle as a Rectangle object
645
+ *
646
+ * @return the framing rectangle
647
+ */
648
+ getBounds() {
649
+ return new Rectangle(
650
+ this.x - this.radius,
651
+ this.y - this.radius,
652
+ this.radius * 2,
653
+ this.radius * 2
654
+ );
655
+ }
656
+ };
657
+
658
+ // src/math/Matrix.ts
659
+ var Matrix = class _Matrix {
660
+ /**
661
+ * @param [a] x scale
662
+ * @param [b] x skew
663
+ * @param [c] y skew
664
+ * @param [d] y scale
665
+ * @param [tx] x translation
666
+ * @param [ty] y translation
667
+ */
668
+ constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {
669
+ this.a = a;
670
+ this.b = b;
671
+ this.c = c;
672
+ this.d = d;
673
+ this.tx = tx;
674
+ this.ty = ty;
675
+ this.array = null;
676
+ }
677
+ /**
678
+ * A default (identity) matrix
679
+ */
680
+ static get IDENTITY() {
681
+ return new _Matrix();
682
+ }
683
+ /**
684
+ * A temp matrix
685
+ */
686
+ static get TEMP_MATRIX() {
687
+ return new _Matrix();
688
+ }
689
+ /**
690
+ * Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:
691
+ *
692
+ * @param array The array that the matrix will be populated from.
693
+ */
694
+ fromArray(array) {
695
+ if (array.length < 6) return this;
696
+ this.a = array[0];
697
+ this.b = array[1];
698
+ this.c = array[3];
699
+ this.d = array[4];
700
+ this.tx = array[2];
701
+ this.ty = array[5];
702
+ return this;
703
+ }
704
+ /**
705
+ * sets the matrix properties
706
+ *
707
+ * @param a Matrix component
708
+ * @param b Matrix component
709
+ * @param c Matrix component
710
+ * @param d Matrix component
711
+ * @param tx Matrix component
712
+ * @param ty Matrix component
713
+ */
714
+ set(a, b, c, d, tx, ty) {
715
+ this.a = a;
716
+ this.b = b;
717
+ this.c = c;
718
+ this.d = d;
719
+ this.tx = tx;
720
+ this.ty = ty;
721
+ return this;
722
+ }
723
+ /**
724
+ * Creates an array from the current Matrix object.
725
+ *
726
+ * @param transpose Whether we need to transpose the matrix or not
727
+ * @param [out=new Float32Array(9)] If provided the array will be assigned to out
728
+ * @return the newly created array which contains the matrix
729
+ */
730
+ toArray(transpose, out) {
731
+ if (!this.array) {
732
+ this.array = new Float32Array(9);
733
+ }
734
+ const array = out || this.array;
735
+ if (transpose) {
736
+ array[0] = this.a;
737
+ array[1] = this.b;
738
+ array[2] = 0;
739
+ array[3] = this.c;
740
+ array[4] = this.d;
741
+ array[5] = 0;
742
+ array[6] = this.tx;
743
+ array[7] = this.ty;
744
+ array[8] = 1;
745
+ } else {
746
+ array[0] = this.a;
747
+ array[1] = this.c;
748
+ array[2] = this.tx;
749
+ array[3] = this.b;
750
+ array[4] = this.d;
751
+ array[5] = this.ty;
752
+ array[6] = 0;
753
+ array[7] = 0;
754
+ array[8] = 1;
755
+ }
756
+ return array;
757
+ }
758
+ /**
759
+ * Get a new position with the current transformation applied.
760
+ * Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
761
+ *
762
+ * @param pos The origin
763
+ * @param [newPos] The point that the new position is assigned to (allowed to be same as input)
764
+ * @return The new point, transformed through this matrix
765
+ */
766
+ apply(pos, newPos) {
767
+ newPos = newPos || { x: 0, y: 0 };
768
+ const { x, y } = pos;
769
+ newPos.x = this.a * x + this.c * y + this.tx;
770
+ newPos.y = this.b * x + this.d * y + this.ty;
771
+ return newPos;
772
+ }
773
+ /**
774
+ * Get a new position with the inverse of the current transformation applied.
775
+ * Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
776
+ *
777
+ * @param pos The origin
778
+ * @param [newPos] The point that the new position is assigned to (allowed to be same as input)
779
+ * @return The new point, inverse-transformed through this matrix
780
+ */
781
+ applyInverse(pos, newPos) {
782
+ newPos = newPos || { x: 0, y: 0 };
783
+ const id = 1 / (this.a * this.d + this.c * -this.b);
784
+ const { x } = pos;
785
+ const { y } = pos;
786
+ newPos.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id;
787
+ newPos.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id;
788
+ return newPos;
789
+ }
790
+ /**
791
+ * Translates the matrix on the x and y.
792
+ *
793
+ * @param x How much to translate x by
794
+ * @param y How much to translate y by
795
+ */
796
+ translate(x, y) {
797
+ this.tx += x;
798
+ this.ty += y;
799
+ return this;
800
+ }
801
+ /**
802
+ * Applies a scale transformation to the matrix.
803
+ *
804
+ * @param x The amount to scale horizontally
805
+ * @param y The amount to scale vertically
806
+ */
807
+ scale(x, y) {
808
+ this.a *= x;
809
+ this.d *= y;
810
+ this.c *= x;
811
+ this.b *= y;
812
+ this.tx *= x;
813
+ this.ty *= y;
814
+ return this;
815
+ }
816
+ /**
817
+ * Applies a rotation transformation to the matrix.
818
+ *
819
+ * @param angle The angle in radians.
820
+ */
821
+ rotate(angle) {
822
+ const cos = Math.cos(angle);
823
+ const sin = Math.sin(angle);
824
+ const a1 = this.a;
825
+ const c1 = this.c;
826
+ const tx1 = this.tx;
827
+ this.a = a1 * cos - this.b * sin;
828
+ this.b = a1 * sin + this.b * cos;
829
+ this.c = c1 * cos - this.d * sin;
830
+ this.d = c1 * sin + this.d * cos;
831
+ this.tx = tx1 * cos - this.ty * sin;
832
+ this.ty = tx1 * sin + this.ty * cos;
833
+ return this;
834
+ }
835
+ /**
836
+ * 矩阵乘法,当前矩阵 * matrix
837
+ * Appends the given Matrix to this Matrix.
838
+ */
839
+ append(matrix) {
840
+ const a1 = this.a;
841
+ const b1 = this.b;
842
+ const c1 = this.c;
843
+ const d1 = this.d;
844
+ this.a = matrix.a * a1 + matrix.b * c1;
845
+ this.b = matrix.a * b1 + matrix.b * d1;
846
+ this.c = matrix.c * a1 + matrix.d * c1;
847
+ this.d = matrix.c * b1 + matrix.d * d1;
848
+ this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx;
849
+ this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty;
850
+ return this;
851
+ }
852
+ /**
853
+ * Sets the matrix based on all the available properties
854
+ *
855
+ * @param x Position on the x axis
856
+ * @param y Position on the y axis
857
+ * @param pivotX Pivot on the x axis
858
+ * @param pivotY Pivot on the y axis
859
+ * @param scaleX Scale on the x axis
860
+ * @param scaleY Scale on the y axis
861
+ * @param rotation Rotation in radians
862
+ * @param skewX Skew on the x axis
863
+ * @param skewY Skew on the y axis
864
+ */
865
+ setTransform(x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) {
866
+ this.a = Math.cos(rotation + skewY) * scaleX;
867
+ this.b = Math.sin(rotation + skewY) * scaleX;
868
+ this.c = -Math.sin(rotation - skewX) * scaleY;
869
+ this.d = Math.cos(rotation - skewX) * scaleY;
870
+ this.tx = x - (pivotX * this.a + pivotY * this.c);
871
+ this.ty = y - (pivotX * this.b + pivotY * this.d);
872
+ return this;
873
+ }
874
+ /**
875
+ * 矩阵乘法,matrix * 当前矩阵
876
+ * Prepends the given Matrix to this Matrix.
877
+ */
878
+ prepend(matrix) {
879
+ const tx1 = this.tx;
880
+ if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) {
881
+ const a1 = this.a;
882
+ const c1 = this.c;
883
+ this.a = a1 * matrix.a + this.b * matrix.c;
884
+ this.b = a1 * matrix.b + this.b * matrix.d;
885
+ this.c = c1 * matrix.a + this.d * matrix.c;
886
+ this.d = c1 * matrix.b + this.d * matrix.d;
887
+ }
888
+ this.tx = tx1 * matrix.a + this.ty * matrix.c + matrix.tx;
889
+ this.ty = tx1 * matrix.b + this.ty * matrix.d + matrix.ty;
890
+ return this;
891
+ }
892
+ /**
893
+ * Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform.
894
+ *
895
+ * @param transform The transform to apply the properties to.
896
+ * @return The transform with the newly applied properties
897
+ */
898
+ decompose(transform) {
899
+ const { a } = this;
900
+ const { b } = this;
901
+ const { c } = this;
902
+ const { d } = this;
903
+ const skewX = -Math.atan2(-c, d);
904
+ const skewY = Math.atan2(b, a);
905
+ const delta = Math.abs(skewX + skewY);
906
+ if (delta < 1e-5 || Math.abs(PI_2 - delta) < 1e-5) {
907
+ transform.rotation = skewY;
908
+ transform.skew.x = 0;
909
+ transform.skew.y = 0;
910
+ } else {
911
+ transform.rotation = 0;
912
+ transform.skew.x = skewX;
913
+ transform.skew.y = skewY;
914
+ }
915
+ transform.scale.x = Math.sqrt(a * a + b * b);
916
+ transform.scale.y = Math.sqrt(c * c + d * d);
917
+ transform.position.x = this.tx;
918
+ transform.position.y = this.ty;
919
+ return transform;
920
+ }
921
+ /**
922
+ * Inverts this matrix
923
+ */
924
+ invert() {
925
+ const a1 = this.a;
926
+ const b1 = this.b;
927
+ const c1 = this.c;
928
+ const d1 = this.d;
929
+ const tx1 = this.tx;
930
+ const n = a1 * d1 - b1 * c1;
931
+ this.a = d1 / n;
932
+ this.b = -b1 / n;
933
+ this.c = -c1 / n;
934
+ this.d = a1 / n;
935
+ this.tx = (c1 * this.ty - d1 * tx1) / n;
936
+ this.ty = -(a1 * this.ty - b1 * tx1) / n;
937
+ return this;
938
+ }
939
+ /**
940
+ * Resets this Matrix to an identity (default) matrix.
941
+ */
942
+ identity() {
943
+ this.a = 1;
944
+ this.b = 0;
945
+ this.c = 0;
946
+ this.d = 1;
947
+ this.tx = 0;
948
+ this.ty = 0;
949
+ return this;
950
+ }
951
+ /**
952
+ * 未做旋转的矩阵
953
+ */
954
+ isSimple() {
955
+ return this.a === 1 && this.b === 0 && this.c === 0 && this.d === 1;
956
+ }
957
+ /**
958
+ * Creates a new Matrix object with the same values as this one.
959
+ *
960
+ * @return A copy of this matrix.
961
+ */
962
+ clone() {
963
+ const matrix = new _Matrix();
964
+ matrix.a = this.a;
965
+ matrix.b = this.b;
966
+ matrix.c = this.c;
967
+ matrix.d = this.d;
968
+ matrix.tx = this.tx;
969
+ matrix.ty = this.ty;
970
+ return matrix;
971
+ }
972
+ /**
973
+ * Changes the values of the given matrix to be the same as the ones in this matrix
974
+ *
975
+ * @return The matrix given in parameter with its values updated.
976
+ */
977
+ copyTo(matrix) {
978
+ matrix.a = this.a;
979
+ matrix.b = this.b;
980
+ matrix.c = this.c;
981
+ matrix.d = this.d;
982
+ matrix.tx = this.tx;
983
+ matrix.ty = this.ty;
984
+ return matrix;
985
+ }
986
+ /**
987
+ * Changes the values of the matrix to be the same as the ones in given matrix
988
+ */
989
+ copyFrom(matrix) {
990
+ this.a = matrix.a;
991
+ this.b = matrix.b;
992
+ this.c = matrix.c;
993
+ this.d = matrix.d;
994
+ this.tx = matrix.tx;
995
+ this.ty = matrix.ty;
996
+ return this;
997
+ }
998
+ };
999
+
1000
+ // src/math/ObservablePoint.ts
1001
+ var ObservablePoint = class _ObservablePoint {
1002
+ /**
1003
+ * @param {Function} cb - callback when changed
1004
+ * @param {object} scope - owner of callback
1005
+ * @param {number} [x=0] - position of the point on the x axis
1006
+ * @param {number} [y=0] - position of the point on the y axis
1007
+ */
1008
+ constructor(cb, scope, x = 0, y = 0) {
1009
+ this._x = x;
1010
+ this._y = y;
1011
+ this.cb = cb;
1012
+ this.scope = scope;
1013
+ }
1014
+ /**
1015
+ * The position of the displayObject on the x axis relative to the local coordinates of the parent.
1016
+ */
1017
+ get x() {
1018
+ return this._x;
1019
+ }
1020
+ set x(value) {
1021
+ if (this._x !== value) {
1022
+ this._x = value;
1023
+ this.cb.call(this.scope);
1024
+ }
1025
+ }
1026
+ /**
1027
+ * The position of the displayObject on the x axis relative to the local coordinates of the parent.
1028
+ */
1029
+ get y() {
1030
+ return this._y;
1031
+ }
1032
+ set y(value) {
1033
+ if (this._y !== value) {
1034
+ this._y = value;
1035
+ this.cb.call(this.scope);
1036
+ }
1037
+ }
1038
+ /**
1039
+ * Creates a clone of this point.
1040
+ * The callback and scope params can be overidden otherwise they will default
1041
+ * to the clone object's values.
1042
+ *
1043
+ * @override
1044
+ * @param {Function} [cb=null] - callback when changed
1045
+ * @param {object} [scope=null] - owner of callback
1046
+ * @return {ObservablePoint} a copy of the point
1047
+ */
1048
+ clone(cb = this.cb, scope = this.scope) {
1049
+ return new _ObservablePoint(cb, scope, this._x, this._y);
1050
+ }
1051
+ /**
1052
+ * Sets the point to a new x and y position.
1053
+ * If y is omitted, both x and y will be set to x.
1054
+ *
1055
+ * @param {number} [x=0] - position of the point on the x axis
1056
+ * @param {number} [y=x] - position of the point on the y axis
1057
+ * @returns {this} Returns itself.
1058
+ */
1059
+ set(x = 0, y = x) {
1060
+ if (this._x !== x || this._y !== y) {
1061
+ this._x = x;
1062
+ this._y = y;
1063
+ this.cb.call(this.scope);
1064
+ }
1065
+ return this;
1066
+ }
1067
+ /**
1068
+ * Copies x and y from the given point
1069
+ *
1070
+ * @param {IPoint} p - The point to copy from.
1071
+ * @returns {this} Returns itself.
1072
+ */
1073
+ copyFrom(p) {
1074
+ if (this._x !== p.x || this._y !== p.y) {
1075
+ this._x = p.x;
1076
+ this._y = p.y;
1077
+ this.cb.call(this.scope);
1078
+ }
1079
+ return this;
1080
+ }
1081
+ /**
1082
+ * Copies x and y into the given point
1083
+ *
1084
+ * @param {IPoint} p - The point to copy.
1085
+ * @returns {IPoint} Given point with values updated
1086
+ */
1087
+ copyTo(p) {
1088
+ p.x = this._x;
1089
+ p.y = this._y;
1090
+ return p;
1091
+ }
1092
+ /**
1093
+ * Returns true if the given point is equal to this point
1094
+ *
1095
+ * @param {IPoint} p - The point to check
1096
+ * @returns {boolean} Whether the given point equal to this point
1097
+ */
1098
+ equals(p) {
1099
+ return p.x === this._x && p.y === this._y;
1100
+ }
1101
+ };
1102
+
1103
+ // src/math/Transform.ts
1104
+ var _Transform = class _Transform {
1105
+ constructor() {
1106
+ this.worldTransform = new Matrix();
1107
+ this.localTransform = new Matrix();
1108
+ this.position = new ObservablePoint(this.onChange, this, 0, 0);
1109
+ this.scale = new ObservablePoint(this.onChange, this, 1, 1);
1110
+ this.pivot = new ObservablePoint(this.onChange, this, 0, 0);
1111
+ this.skew = new ObservablePoint(this.updateSkew, this, 0, 0);
1112
+ this._rotation = 0;
1113
+ this._cx = 1;
1114
+ this._sx = 0;
1115
+ this._cy = 0;
1116
+ this._sy = 1;
1117
+ this._localID = 0;
1118
+ this._currentLocalID = 0;
1119
+ this._worldID = 0;
1120
+ this._parentID = 0;
1121
+ }
1122
+ /**
1123
+ * Called when a value changes.
1124
+ *
1125
+ * @protected
1126
+ */
1127
+ onChange() {
1128
+ this._localID++;
1129
+ }
1130
+ /**
1131
+ * Called when the skew or the rotation changes.
1132
+ *
1133
+ * @protected
1134
+ */
1135
+ updateSkew() {
1136
+ this._cx = Math.cos(this._rotation + this.skew.y);
1137
+ this._sx = Math.sin(this._rotation + this.skew.y);
1138
+ this._cy = -Math.sin(this._rotation - this.skew.x);
1139
+ this._sy = Math.cos(this._rotation - this.skew.x);
1140
+ this._localID++;
1141
+ }
1142
+ /**
1143
+ * Updates the local transformation matrix.
1144
+ */
1145
+ updateLocalTransform() {
1146
+ const lt = this.localTransform;
1147
+ if (this._localID !== this._currentLocalID) {
1148
+ lt.a = this._cx * this.scale.x;
1149
+ lt.b = this._sx * this.scale.x;
1150
+ lt.c = this._cy * this.scale.y;
1151
+ lt.d = this._sy * this.scale.y;
1152
+ lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c);
1153
+ lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d);
1154
+ this._currentLocalID = this._localID;
1155
+ this._parentID = -1;
1156
+ }
1157
+ }
1158
+ /**
1159
+ * Updates the local and the world transformation matrices.
1160
+ *
1161
+ * @param {PIXI.Transform} parentTransform - The parent transform
1162
+ */
1163
+ updateTransform(parentTransform) {
1164
+ const lt = this.localTransform;
1165
+ if (this._localID !== this._currentLocalID) {
1166
+ lt.a = this._cx * this.scale.x;
1167
+ lt.b = this._sx * this.scale.x;
1168
+ lt.c = this._cy * this.scale.y;
1169
+ lt.d = this._sy * this.scale.y;
1170
+ lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c);
1171
+ lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d);
1172
+ this._currentLocalID = this._localID;
1173
+ this._parentID = -1;
1174
+ }
1175
+ if (this._parentID !== parentTransform._worldID) {
1176
+ const pt = parentTransform.worldTransform;
1177
+ const wt = this.worldTransform;
1178
+ wt.a = lt.a * pt.a + lt.b * pt.c;
1179
+ wt.b = lt.a * pt.b + lt.b * pt.d;
1180
+ wt.c = lt.c * pt.a + lt.d * pt.c;
1181
+ wt.d = lt.c * pt.b + lt.d * pt.d;
1182
+ wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx;
1183
+ wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty;
1184
+ this._parentID = parentTransform._worldID;
1185
+ this._worldID++;
1186
+ }
1187
+ }
1188
+ /**
1189
+ * Decomposes a matrix and sets the transforms properties based on it.
1190
+ *
1191
+ * @param {PIXI.Matrix} matrix - The matrix to decompose
1192
+ */
1193
+ setFromMatrix(matrix) {
1194
+ matrix.decompose(this);
1195
+ this._localID++;
1196
+ }
1197
+ /**
1198
+ * The rotation of the object in radians.
1199
+ *
1200
+ * @member {number}
1201
+ */
1202
+ get rotation() {
1203
+ return this._rotation;
1204
+ }
1205
+ set rotation(value) {
1206
+ if (this._rotation !== value) {
1207
+ this._rotation = value;
1208
+ this.updateSkew();
1209
+ }
1210
+ }
1211
+ };
1212
+ /**
1213
+ * A default (identity) transform
1214
+ *
1215
+ * @static
1216
+ * @constant
1217
+ * @member {PIXI.Transform}
1218
+ */
1219
+ _Transform.IDENTITY = new _Transform();
1220
+ var Transform = _Transform;
1221
+
1222
+ // src/math/wrap.ts
1223
+ function wrap(value, min, max) {
1224
+ const range = max - min;
1225
+ return min + ((value - min) % range + range) % range;
1226
+ }
1227
+
1228
+ // src/math/angle.ts
1229
+ var Angle;
1230
+ ((Angle2) => {
1231
+ function wrap2(angle) {
1232
+ return wrap(angle, -Math.PI, Math.PI);
1233
+ }
1234
+ Angle2.wrap = wrap2;
1235
+ function wrapDegrees(angle) {
1236
+ return wrap(angle, -180, 180);
1237
+ }
1238
+ Angle2.wrapDegrees = wrapDegrees;
1239
+ function betweenPoints(point1, point2, originPoint = { x: 0, y: 0 }) {
1240
+ const p1 = {
1241
+ x: point1.x - originPoint.x,
1242
+ y: point1.y - originPoint.y
1243
+ };
1244
+ const p2 = {
1245
+ x: point2.x - originPoint.x,
1246
+ y: point2.y - originPoint.y
1247
+ };
1248
+ return Math.atan2(p1.x * p2.y - p1.y * p2.x, p1.x * p2.x + p1.y * p2.y);
1249
+ }
1250
+ Angle2.betweenPoints = betweenPoints;
1251
+ })(Angle || (Angle = {}));
1252
+
1253
+ // src/objects.ts
1254
+ var { keys } = Object;
1255
+ function deepFreeze(obj) {
1256
+ if (!obj || typeof obj !== "object") {
1257
+ return obj;
1258
+ }
1259
+ const stack = [obj];
1260
+ while (stack.length > 0) {
1261
+ const objectToFreeze = stack.shift();
1262
+ Object.freeze(objectToFreeze);
1263
+ for (const key in objectToFreeze) {
1264
+ if (_hasOwnProperty.call(objectToFreeze, key)) {
1265
+ const prop = objectToFreeze[key];
1266
+ if (typeof prop === "object" && !Object.isFrozen(prop)) {
1267
+ stack.push(prop);
1268
+ }
1269
+ }
1270
+ }
1271
+ }
1272
+ return obj;
1273
+ }
1274
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
1275
+ function notEmpty(arg) {
1276
+ return arg !== void 0 && arg !== null;
1277
+ }
1278
+ function isEmpty(arg) {
1279
+ return keys(arg).length === 0 && arg.constructor === Object;
1280
+ }
1281
+ var each = (obj, fn) => keys(obj).forEach((key) => fn(obj[key], key));
1282
+ var values = (obj) => Object.values ? Object.values(obj) : keys(obj).map((k) => obj[k]);
1283
+ var filter = (obj, fn, dest) => keys(obj).reduce(
1284
+ (output, key) => fn(obj[key], key) ? Object.assign(output, { [key]: obj[key] }) : output,
1285
+ dest || {}
1286
+ );
1287
+ var pick = (obj, fields, dest) => filter(obj, (n, k) => fields.indexOf(k) !== -1, dest);
1288
+ var omit = (obj, fields, dest) => filter(obj, (n, k) => fields.indexOf(k) === -1, dest);
1289
+ var reduce = (obj, fn, res = {}) => keys(obj).reduce((r, k) => fn(r, obj[k], k), res);
1290
+ var mapValues = (obj, fn) => reduce(obj, (res, value, key) => Object.assign(res, { [key]: fn(value, key) }));
1291
+ var mapKeys = (obj, fn) => reduce(obj, (res, value, key) => Object.assign(res, { [fn(value, key)]: value }));
1292
+ function getByKey(target, key) {
1293
+ if (typeof target !== "object" || !key) return void 0;
1294
+ return key.split(".").reduce((v, k) => {
1295
+ if (typeof v !== "object") return void 0;
1296
+ return v[k];
1297
+ }, target);
1298
+ }
1299
+ function setByKey(target, key, newValue, autoCreateObject = true, clone = false) {
1300
+ if (typeof target !== "object" || !key) return target;
1301
+ if (clone) {
1302
+ target = { ...target };
1303
+ }
1304
+ const originTarget = target;
1305
+ const targetKeys = key.split(".");
1306
+ while (targetKeys.length > 0) {
1307
+ key = targetKeys.shift();
1308
+ if (targetKeys.length === 0) {
1309
+ target[key] = newValue;
1310
+ return originTarget;
1311
+ }
1312
+ if (typeof target[key] !== "object") {
1313
+ if (!autoCreateObject) return originTarget;
1314
+ target[key] = {};
1315
+ }
1316
+ if (clone) {
1317
+ if (Array.isArray(target[key])) {
1318
+ target[key] = target[key].slice();
1319
+ } else {
1320
+ target[key] = { ...target[key] };
1321
+ }
1322
+ }
1323
+ target = target[key];
1324
+ }
1325
+ return originTarget;
1326
+ }
1327
+ var NOOP = () => {
1328
+ };
1329
+ function isPlainObject(obj) {
1330
+ if (typeof obj !== "object" || obj === null) return false;
1331
+ let proto = obj;
1332
+ while (Object.getPrototypeOf(proto) !== null) {
1333
+ proto = Object.getPrototypeOf(proto);
1334
+ }
1335
+ return Object.getPrototypeOf(obj) === proto;
1336
+ }
1337
+
1338
+ // src/types.ts
1339
+ function isObject(v) {
1340
+ return typeof v === "object" && v !== null;
1341
+ }
1342
+ function isString(v) {
1343
+ return typeof v === "string" || v instanceof String;
1344
+ }
1345
+ function isFunction(v) {
1346
+ return typeof v === "function";
1347
+ }
1348
+ var toString = Object.prototype.toString;
1349
+ function getTag(v) {
1350
+ if (v == null) {
1351
+ return v === void 0 ? "[object Undefined]" : "[object Null]";
1352
+ }
1353
+ return toString.call(v);
1354
+ }
1355
+ function isNumber(v) {
1356
+ return typeof v === "number" || isObject(v) && getTag(v) === "[object Number]";
1357
+ }
1358
+
1359
+ // src/event.ts
1360
+ var DisposableNULL = Object.freeze({ dispose: NOOP });
1361
+ var Event;
1362
+ ((Event2) => {
1363
+ Event2.None = () => DisposableNULL;
1364
+ })(Event || (Event = {}));
1365
+ var _Emitter = class _Emitter {
1366
+ constructor() {
1367
+ this._disposed = false;
1368
+ }
1369
+ get event() {
1370
+ if (!this._event) {
1371
+ this._event = (listener, thisArgs) => {
1372
+ if (this._disposed) {
1373
+ return DisposableNULL;
1374
+ }
1375
+ if (!this._listeners) {
1376
+ this._listeners = [];
1377
+ }
1378
+ const finalListener = thisArgs ? listener.bind(thisArgs) : listener;
1379
+ if (this._listeners.length >= _Emitter.LEAK_WARNING_THRESHHOLD) {
1380
+ console.warn(`[Emitter] Listeners length >= ${_Emitter.LEAK_WARNING_THRESHHOLD}`);
1381
+ }
1382
+ this._listeners.push(finalListener);
1383
+ const eventDisposable = {
1384
+ dispose: () => {
1385
+ eventDisposable.dispose = NOOP;
1386
+ if (!this._disposed) {
1387
+ const index = this._listeners.indexOf(finalListener);
1388
+ if (index !== -1) {
1389
+ this._listeners.splice(index, 1);
1390
+ }
1391
+ }
1392
+ }
1393
+ };
1394
+ return eventDisposable;
1395
+ };
1396
+ }
1397
+ return this._event;
1398
+ }
1399
+ fire(event) {
1400
+ if (this._listeners) {
1401
+ this._listeners.forEach((listener) => listener(event));
1402
+ }
1403
+ }
1404
+ get disposed() {
1405
+ return this._disposed;
1406
+ }
1407
+ dispose() {
1408
+ if (this._listeners) {
1409
+ this._listeners = void 0;
1410
+ }
1411
+ this._disposed = true;
1412
+ }
1413
+ };
1414
+ _Emitter.LEAK_WARNING_THRESHHOLD = 175;
1415
+ var Emitter = _Emitter;
1416
+
1417
+ // src/disposable.ts
1418
+ var Disposable;
1419
+ ((Disposable2) => {
1420
+ function is(thing) {
1421
+ return typeof thing === "object" && thing !== null && typeof thing.dispose === "function";
1422
+ }
1423
+ Disposable2.is = is;
1424
+ function create(func) {
1425
+ return {
1426
+ dispose: func
1427
+ };
1428
+ }
1429
+ Disposable2.create = create;
1430
+ Disposable2.NULL = Object.freeze(create(() => {
1431
+ }));
1432
+ })(Disposable || (Disposable = {}));
1433
+ var DisposableImpl = class {
1434
+ constructor() {
1435
+ this.toDispose = new DisposableCollection();
1436
+ }
1437
+ dispose() {
1438
+ this.toDispose.dispose();
1439
+ }
1440
+ get disposed() {
1441
+ return this.toDispose.disposed;
1442
+ }
1443
+ get onDispose() {
1444
+ return this.toDispose.onDispose;
1445
+ }
1446
+ };
1447
+ var DisposableCollection = class {
1448
+ constructor(...toDispose) {
1449
+ this.disposables = [];
1450
+ this.onDisposeEmitter = new Emitter();
1451
+ this._disposed = false;
1452
+ toDispose.forEach((d) => this.push(d));
1453
+ }
1454
+ get onDispose() {
1455
+ return this.onDisposeEmitter.event;
1456
+ }
1457
+ get disposed() {
1458
+ return this._disposed;
1459
+ }
1460
+ dispose() {
1461
+ if (this.disposed) {
1462
+ return;
1463
+ }
1464
+ this._disposed = true;
1465
+ this.disposables.slice().reverse().forEach((disposable) => {
1466
+ try {
1467
+ disposable.dispose();
1468
+ } catch (e) {
1469
+ console.error(e);
1470
+ }
1471
+ });
1472
+ this.onDisposeEmitter.fire(void 0);
1473
+ this.onDisposeEmitter.dispose();
1474
+ }
1475
+ push(disposable) {
1476
+ if (this.disposed) return Disposable.NULL;
1477
+ const { disposables } = this;
1478
+ if (disposables.find((d) => d._origin === disposable)) {
1479
+ return Disposable.NULL;
1480
+ }
1481
+ let disposableWrap;
1482
+ const toRemove = Disposable.create(() => {
1483
+ const index = disposables.indexOf(disposableWrap);
1484
+ if (index !== -1) {
1485
+ disposables.splice(index, 1);
1486
+ }
1487
+ });
1488
+ disposableWrap = {
1489
+ dispose: () => {
1490
+ toRemove.dispose();
1491
+ disposable.dispose();
1492
+ },
1493
+ _origin: disposable
1494
+ };
1495
+ disposables.push(disposableWrap);
1496
+ return toRemove;
1497
+ }
1498
+ pushAll(disposables) {
1499
+ return disposables.map((disposable) => this.push(disposable));
1500
+ }
1501
+ };
1502
+
1503
+ // src/cancellation.ts
1504
+ var shortcutEvent = Object.freeze(function(callback, context) {
1505
+ const handle = setTimeout(callback.bind(context), 0);
1506
+ return {
1507
+ dispose() {
1508
+ clearTimeout(handle);
1509
+ }
1510
+ };
1511
+ });
1512
+ var CancellationToken;
1513
+ ((CancellationToken2) => {
1514
+ function isCancellationToken(thing) {
1515
+ if (thing === CancellationToken2.None || thing === CancellationToken2.Cancelled) {
1516
+ return true;
1517
+ }
1518
+ if (thing instanceof MutableToken) {
1519
+ return true;
1520
+ }
1521
+ if (!thing || typeof thing !== "object") {
1522
+ return false;
1523
+ }
1524
+ return typeof thing.isCancellationRequested === "boolean" && typeof thing.onCancellationRequested === "function";
1525
+ }
1526
+ CancellationToken2.isCancellationToken = isCancellationToken;
1527
+ CancellationToken2.None = Object.freeze({
1528
+ isCancellationRequested: false,
1529
+ onCancellationRequested: Event.None
1530
+ });
1531
+ CancellationToken2.Cancelled = Object.freeze({
1532
+ isCancellationRequested: true,
1533
+ onCancellationRequested: shortcutEvent
1534
+ });
1535
+ })(CancellationToken || (CancellationToken = {}));
1536
+ var MutableToken = class {
1537
+ constructor() {
1538
+ this._isCancelled = false;
1539
+ }
1540
+ cancel() {
1541
+ if (!this._isCancelled) {
1542
+ this._isCancelled = true;
1543
+ if (this._emitter) {
1544
+ this._emitter.fire(void 0);
1545
+ this.dispose();
1546
+ }
1547
+ }
1548
+ }
1549
+ get isCancellationRequested() {
1550
+ return this._isCancelled;
1551
+ }
1552
+ get onCancellationRequested() {
1553
+ if (this._isCancelled) {
1554
+ return shortcutEvent;
1555
+ }
1556
+ if (!this._emitter) {
1557
+ this._emitter = new Emitter();
1558
+ }
1559
+ return this._emitter.event;
1560
+ }
1561
+ dispose() {
1562
+ if (this._emitter) {
1563
+ this._emitter.dispose();
1564
+ this._emitter = void 0;
1565
+ }
1566
+ }
1567
+ };
1568
+ var CancellationTokenSource = class {
1569
+ get token() {
1570
+ if (!this._token) {
1571
+ this._token = new MutableToken();
1572
+ }
1573
+ return this._token;
1574
+ }
1575
+ cancel() {
1576
+ if (!this._token) {
1577
+ this._token = CancellationToken.Cancelled;
1578
+ } else if (this._token !== CancellationToken.Cancelled) {
1579
+ this._token.cancel();
1580
+ }
1581
+ }
1582
+ dispose() {
1583
+ this.cancel();
1584
+ }
1585
+ };
1586
+ var cancelledMessage = "Cancelled";
1587
+ function cancelled() {
1588
+ return new Error(cancelledMessage);
1589
+ }
1590
+ function isCancelled(err) {
1591
+ return !!err && err.message === cancelledMessage;
1592
+ }
1593
+ function checkCancelled(token) {
1594
+ if (!!token && token.isCancellationRequested) {
1595
+ throw cancelled();
1596
+ }
1597
+ }
1598
+
1599
+ // src/promise-util.ts
1600
+ var PromiseDeferred = class {
1601
+ constructor() {
1602
+ this.promise = new Promise((resolve, reject) => {
1603
+ this.resolve = resolve;
1604
+ this.reject = reject;
1605
+ });
1606
+ }
1607
+ };
1608
+ var Deferred = PromiseDeferred;
1609
+ function delay(ms, token = CancellationToken.None) {
1610
+ const deferred = new PromiseDeferred();
1611
+ const handle = setTimeout(() => deferred.resolve(), ms);
1612
+ token.onCancellationRequested(() => {
1613
+ clearTimeout(handle);
1614
+ deferred.reject(cancelled());
1615
+ });
1616
+ return deferred.promise;
1617
+ }
1618
+ async function retry(task, delayTime, retries, shouldRetry) {
1619
+ let lastError;
1620
+ let result;
1621
+ for (let i = 0; i < retries; i++) {
1622
+ try {
1623
+ result = await task();
1624
+ if (shouldRetry && shouldRetry(result)) {
1625
+ await delay(delayTime);
1626
+ continue;
1627
+ }
1628
+ return result;
1629
+ } catch (error) {
1630
+ lastError = error;
1631
+ await delay(delayTime);
1632
+ }
1633
+ }
1634
+ if (lastError) {
1635
+ throw lastError;
1636
+ }
1637
+ return result;
1638
+ }
1639
+ var PromisePoolOptsDefault = {
1640
+ intervalCount: 10,
1641
+ // 每批数目
1642
+ intervalTime: 0,
1643
+ retries: 0,
1644
+ retryDelay: 10
1645
+ };
1646
+ var PromisePool = class {
1647
+ constructor(opts = PromisePoolOptsDefault) {
1648
+ this.opts = { ...PromisePoolOptsDefault, ...opts };
1649
+ }
1650
+ async tryToExec(task, checkIfRetry) {
1651
+ if (this.opts.retries === 0) return task();
1652
+ return retry(task, this.opts.retryDelay, this.opts.retries, checkIfRetry);
1653
+ }
1654
+ /**
1655
+ * @param tasks 执行任务
1656
+ * @param checkIfRetry 判断结果是否需要重试
1657
+ */
1658
+ async run(tasks, checkIfRetry) {
1659
+ if (tasks.length === 0) return [];
1660
+ const curTasks = tasks.slice(0, this.opts.intervalCount);
1661
+ const promises = curTasks.map((task) => this.tryToExec(task, checkIfRetry));
1662
+ const result = await Promise.all(promises);
1663
+ const nextTasks = tasks.slice(this.opts.intervalCount);
1664
+ if (nextTasks.length === 0) return result;
1665
+ if (this.opts.intervalTime !== 0) await delay(this.opts.intervalTime);
1666
+ return result.concat(await this.run(nextTasks, checkIfRetry));
1667
+ }
1668
+ };
1669
+
1670
+ // src/compare.ts
1671
+ var Compare;
1672
+ ((Compare2) => {
1673
+ function isChanged(oldProps, newProps, depth = 1, partial = true) {
1674
+ if (oldProps === newProps) return false;
1675
+ if (depth === 0 || typeof oldProps !== "object" || typeof newProps !== "object") {
1676
+ return oldProps !== newProps;
1677
+ }
1678
+ const keys2 = Object.keys(newProps);
1679
+ if (!partial) {
1680
+ const oldKeys = Object.keys(oldProps);
1681
+ if (keys2.length !== oldKeys.length) return true;
1682
+ }
1683
+ for (let i = 0, len = keys2.length; i < len; i++) {
1684
+ const key = keys2[i];
1685
+ if (isChanged(oldProps[key], newProps[key], depth - 1, partial)) return true;
1686
+ }
1687
+ return false;
1688
+ }
1689
+ Compare2.isChanged = isChanged;
1690
+ function isDeepChanged(oldProps, newProps, partial) {
1691
+ return isChanged(oldProps, newProps, Infinity, partial);
1692
+ }
1693
+ Compare2.isDeepChanged = isDeepChanged;
1694
+ function isArrayShallowChanged(arr1, arr2) {
1695
+ if (arr1.length !== arr2.length) return true;
1696
+ for (let i = 0, len = arr1.length; i < len; i++) {
1697
+ if (arr1[i] !== arr2[i]) {
1698
+ return true;
1699
+ }
1700
+ }
1701
+ return false;
1702
+ }
1703
+ Compare2.isArrayShallowChanged = isArrayShallowChanged;
1704
+ })(Compare || (Compare = {}));
1705
+
1706
+ // src/cache.ts
1707
+ var Cache;
1708
+ ((Cache2) => {
1709
+ function create(cacheFactory, opts = {}) {
1710
+ let cache = [];
1711
+ return {
1712
+ getFromCache() {
1713
+ return cache;
1714
+ },
1715
+ getMore(count, autoDelete = true) {
1716
+ if (count === cache.length) {
1717
+ } else if (count > cache.length) {
1718
+ let added = count - cache.length;
1719
+ while (added > 0) {
1720
+ cache.push(cacheFactory());
1721
+ added--;
1722
+ }
1723
+ } else if (autoDelete) {
1724
+ const deleteLimit = opts.deleteLimit ?? 0;
1725
+ if (cache.length - count > deleteLimit) {
1726
+ const deleted = cache.splice(count);
1727
+ deleted.forEach((el) => el.dispose && el.dispose());
1728
+ }
1729
+ }
1730
+ return cache.slice(0, count);
1731
+ },
1732
+ /**
1733
+ * 通过 key 去创建缓存
1734
+ * @param items
1735
+ */
1736
+ getMoreByItemKeys(items) {
1737
+ const newCache = [];
1738
+ const findedMap = /* @__PURE__ */ new Map();
1739
+ cache.forEach((item) => {
1740
+ const finded = items.find((i) => i.key === item.key);
1741
+ if (finded) {
1742
+ findedMap.set(item.key, item);
1743
+ } else {
1744
+ item.dispose?.();
1745
+ }
1746
+ });
1747
+ items.forEach((item) => {
1748
+ if (!item.key) throw new Error("getMoreByItemKeys need a key");
1749
+ const finded = findedMap.get(item.key);
1750
+ if (finded) {
1751
+ newCache.push(finded);
1752
+ } else {
1753
+ newCache.push(cacheFactory(item));
1754
+ }
1755
+ });
1756
+ cache = newCache;
1757
+ return cache;
1758
+ },
1759
+ /**
1760
+ * 通过 item 引用取拿缓存数据
1761
+ */
1762
+ getMoreByItems(items) {
1763
+ const newCache = [];
1764
+ const findedMap = /* @__PURE__ */ new Map();
1765
+ cache.forEach((cacheItem) => {
1766
+ const finded = items.find((ref) => ref === cacheItem.key);
1767
+ if (finded) {
1768
+ findedMap.set(cacheItem.key, cacheItem);
1769
+ } else {
1770
+ cacheItem.dispose?.();
1771
+ }
1772
+ });
1773
+ items.forEach((item) => {
1774
+ const finded = findedMap.get(item);
1775
+ if (finded) {
1776
+ newCache.push(finded);
1777
+ } else {
1778
+ newCache.push({
1779
+ ...cacheFactory(item),
1780
+ key: item
1781
+ });
1782
+ }
1783
+ });
1784
+ cache = newCache;
1785
+ return cache;
1786
+ },
1787
+ get() {
1788
+ if (cache.length > 0) return cache[0];
1789
+ cache.push(cacheFactory());
1790
+ return cache[0];
1791
+ },
1792
+ getFromCacheByKey(key) {
1793
+ return cache.find((item) => item.key === key);
1794
+ },
1795
+ dispose() {
1796
+ cache.forEach((item) => item.dispose && item.dispose());
1797
+ cache.length = 0;
1798
+ },
1799
+ clear() {
1800
+ this.dispose();
1801
+ }
1802
+ };
1803
+ }
1804
+ Cache2.create = create;
1805
+ function assign(target, fn) {
1806
+ return Object.assign(target, fn);
1807
+ }
1808
+ Cache2.assign = assign;
1809
+ function createShortCache(timeout = 1e3) {
1810
+ let cache;
1811
+ let timeoutId;
1812
+ function updateTimeout() {
1813
+ if (timeoutId) clearTimeout(timeoutId);
1814
+ timeoutId = setTimeout(() => {
1815
+ timeoutId = void 0;
1816
+ cache = void 0;
1817
+ }, timeout);
1818
+ }
1819
+ return {
1820
+ get(getValue) {
1821
+ if (cache) {
1822
+ updateTimeout();
1823
+ return cache;
1824
+ }
1825
+ cache = getValue();
1826
+ updateTimeout();
1827
+ return cache;
1828
+ }
1829
+ };
1830
+ }
1831
+ Cache2.createShortCache = createShortCache;
1832
+ function createWeakCache() {
1833
+ const weakCache = /* @__PURE__ */ new WeakMap();
1834
+ return {
1835
+ get: (key) => weakCache.get(key),
1836
+ save: (key, value) => weakCache.set(key, value),
1837
+ isChanged: (key, value) => Compare.isChanged(weakCache.get(key), value)
1838
+ };
1839
+ }
1840
+ Cache2.createWeakCache = createWeakCache;
1841
+ })(Cache || (Cache = {}));
1842
+
1843
+ // src/schema/schema.ts
1844
+ var SchemaDecoration;
1845
+ ((SchemaDecoration2) => {
1846
+ function create(properties, baseDecoration, mixinDefaults) {
1847
+ return {
1848
+ type: "object",
1849
+ properties: {
1850
+ ...baseDecoration?.properties,
1851
+ ...properties
1852
+ },
1853
+ mixinDefaults: {
1854
+ ...baseDecoration?.mixinDefaults,
1855
+ ...mixinDefaults
1856
+ }
1857
+ };
1858
+ }
1859
+ SchemaDecoration2.create = create;
1860
+ })(SchemaDecoration || (SchemaDecoration = {}));
1861
+ var Schema;
1862
+ ((Schema2) => {
1863
+ function createDefault(decoration, mixinDefaults, _key) {
1864
+ mixinDefaults = { ...decoration.mixinDefaults, ...mixinDefaults };
1865
+ const prefixKey = _key ? `${_key}.` : "";
1866
+ if (decoration.properties) {
1867
+ return mapValues(decoration.properties, (v, k) => {
1868
+ const childKey = prefixKey + k;
1869
+ if (mixinDefaults && mixinDefaults[childKey] !== void 0) {
1870
+ return mixinDefaults[childKey];
1871
+ }
1872
+ return createDefault(v, mixinDefaults, childKey);
1873
+ });
1874
+ }
1875
+ return typeof decoration.default === "function" ? decoration.default() : decoration.default;
1876
+ }
1877
+ Schema2.createDefault = createDefault;
1878
+ function isBaseType(decoration) {
1879
+ return decoration.type === "string" || decoration.type === "float" || decoration.type === "integer" || decoration.type === "boolean" || decoration.type === "enum" || decoration.type === "color" || decoration.type === "range";
1880
+ }
1881
+ Schema2.isBaseType = isBaseType;
1882
+ })(Schema || (Schema = {}));
1883
+
1884
+ // src/schema/schema-transform.ts
1885
+ var SizeSchemaDecoration = {
1886
+ label: "\u5927\u5C0F",
1887
+ properties: {
1888
+ width: { label: "\u5BBD", default: 0, type: "float" },
1889
+ height: { label: "\u9AD8", default: 0, type: "float" },
1890
+ locked: { label: "\u7B49\u6BD4\u9501", default: false, type: "boolean" }
1891
+ },
1892
+ type: "object"
1893
+ };
1894
+ var OriginSchemaDecoration = {
1895
+ label: "\u539F\u70B9",
1896
+ description: "\u7528\u4E8E\u8BBE\u7F6E\u65CB\u8F6C\u7684\u4E2D\u5FC3\u4F4D\u7F6E",
1897
+ properties: {
1898
+ x: { label: "x", default: 0.5, type: "float" },
1899
+ y: { label: "y", default: 0.5, type: "float" }
1900
+ },
1901
+ type: "object"
1902
+ };
1903
+ var PositionSchemaDecoration = {
1904
+ label: "\u4F4D\u7F6E",
1905
+ properties: {
1906
+ x: { label: "x", default: 0, type: "float" },
1907
+ y: { label: "y", default: 0, type: "float" }
1908
+ },
1909
+ type: "object"
1910
+ };
1911
+ var RotationSchemaDecoration = {
1912
+ label: "\u65CB\u8F6C",
1913
+ type: "float",
1914
+ default: 0
1915
+ };
1916
+ var ScaleSchemaDecoration = {
1917
+ label: "\u7F29\u653E",
1918
+ properties: {
1919
+ x: { label: "x", default: 1, type: "float" },
1920
+ y: { label: "y", default: 1, type: "float" }
1921
+ },
1922
+ type: "object"
1923
+ };
1924
+ var SkewSchemaDecoration = {
1925
+ label: "\u503E\u659C",
1926
+ properties: {
1927
+ x: { label: "x", default: 0, type: "float" },
1928
+ y: { label: "y", default: 0, type: "float" }
1929
+ },
1930
+ type: "object"
1931
+ };
1932
+ var TransformSchemaDecoration = {
1933
+ properties: {
1934
+ position: PositionSchemaDecoration,
1935
+ size: SizeSchemaDecoration,
1936
+ origin: OriginSchemaDecoration,
1937
+ scale: ScaleSchemaDecoration,
1938
+ skew: SkewSchemaDecoration,
1939
+ rotation: RotationSchemaDecoration
1940
+ },
1941
+ type: "object"
1942
+ };
1943
+ var TransformSchema;
1944
+ ((TransformSchema2) => {
1945
+ function createDefault() {
1946
+ return Schema.createDefault(TransformSchemaDecoration);
1947
+ }
1948
+ TransformSchema2.createDefault = createDefault;
1949
+ function toJSON(obj) {
1950
+ return {
1951
+ position: { x: obj.position.x, y: obj.position.y },
1952
+ size: {
1953
+ width: obj.size.width,
1954
+ height: obj.size.height,
1955
+ locked: obj.size.locked
1956
+ },
1957
+ origin: { x: obj.origin.x, y: obj.origin.y },
1958
+ scale: { x: obj.scale.x, y: obj.scale.y },
1959
+ skew: { x: obj.skew.x, y: obj.skew.y },
1960
+ rotation: obj.rotation
1961
+ };
1962
+ }
1963
+ TransformSchema2.toJSON = toJSON;
1964
+ function getDelta(oldTransform, newTransform) {
1965
+ return {
1966
+ position: {
1967
+ x: newTransform.position.x - oldTransform.position.x,
1968
+ y: newTransform.position.y - oldTransform.position.y
1969
+ },
1970
+ size: {
1971
+ width: newTransform.size.width - oldTransform.size.width,
1972
+ height: newTransform.size.height - oldTransform.size.height
1973
+ },
1974
+ origin: {
1975
+ x: newTransform.origin.x - oldTransform.origin.x,
1976
+ y: newTransform.origin.y - oldTransform.origin.y
1977
+ },
1978
+ scale: {
1979
+ x: newTransform.scale.x - oldTransform.scale.x,
1980
+ y: newTransform.scale.y - oldTransform.scale.y
1981
+ },
1982
+ skew: {
1983
+ x: newTransform.skew.x - oldTransform.skew.x,
1984
+ y: newTransform.skew.y - oldTransform.skew.y
1985
+ },
1986
+ rotation: newTransform.rotation - oldTransform.rotation
1987
+ };
1988
+ }
1989
+ TransformSchema2.getDelta = getDelta;
1990
+ function mergeDelta(oldTransform, newTransformDelta, toFixedNum) {
1991
+ const toFixed = toFixedNum !== void 0 ? (v) => Math.round(v * 100) / 100 : (v) => v;
1992
+ return {
1993
+ position: {
1994
+ x: toFixed(newTransformDelta.position.x + oldTransform.position.x),
1995
+ y: toFixed(newTransformDelta.position.y + oldTransform.position.y)
1996
+ },
1997
+ size: {
1998
+ width: toFixed(newTransformDelta.size.width + oldTransform.size.width),
1999
+ height: toFixed(newTransformDelta.size.height + oldTransform.size.height),
2000
+ locked: oldTransform.size.locked
2001
+ },
2002
+ origin: {
2003
+ x: toFixed(newTransformDelta.origin.x + oldTransform.origin.x),
2004
+ y: toFixed(newTransformDelta.origin.y + oldTransform.origin.y)
2005
+ },
2006
+ scale: {
2007
+ x: toFixed(newTransformDelta.scale.x + oldTransform.scale.x),
2008
+ y: toFixed(newTransformDelta.scale.y + oldTransform.scale.y)
2009
+ },
2010
+ skew: {
2011
+ x: toFixed(newTransformDelta.skew.x + oldTransform.skew.x),
2012
+ y: toFixed(newTransformDelta.skew.y + oldTransform.skew.y)
2013
+ },
2014
+ rotation: newTransformDelta.rotation + oldTransform.rotation
2015
+ };
2016
+ }
2017
+ TransformSchema2.mergeDelta = mergeDelta;
2018
+ function is(obj) {
2019
+ return obj && obj.position && obj.size && typeof obj.position.x === "number" && typeof obj.size.width === "number";
2020
+ }
2021
+ TransformSchema2.is = is;
2022
+ })(TransformSchema || (TransformSchema = {}));
2023
+ var SizeSchema;
2024
+ ((SizeSchema2) => {
2025
+ function fixSize(currentSize, parentSize) {
2026
+ if (currentSize.width <= parentSize.width && currentSize.height <= parentSize.height) return 1;
2027
+ const wScale = currentSize.width / parentSize.width;
2028
+ const hScale = currentSize.height / parentSize.height;
2029
+ const scale = wScale > hScale ? wScale : hScale;
2030
+ return 1 / scale;
2031
+ }
2032
+ SizeSchema2.fixSize = fixSize;
2033
+ function coverSize(currentSize, parentSize) {
2034
+ const wScale = currentSize.width / parentSize.width;
2035
+ const hScale = currentSize.height / parentSize.height;
2036
+ const scale = wScale < hScale ? wScale : hScale;
2037
+ return 1 / scale;
2038
+ }
2039
+ SizeSchema2.coverSize = coverSize;
2040
+ function empty() {
2041
+ return { width: 0, height: 0 };
2042
+ }
2043
+ SizeSchema2.empty = empty;
2044
+ })(SizeSchema || (SizeSchema = {}));
2045
+
2046
+ // src/schema/schema-base.ts
2047
+ var PaddingSchema;
2048
+ ((PaddingSchema2) => {
2049
+ PaddingSchema2.empty = () => ({ left: 0, right: 0, top: 0, bottom: 0 });
2050
+ })(PaddingSchema || (PaddingSchema = {}));
2051
+ var TintSchema;
2052
+ ((TintSchema2) => {
2053
+ function isEmpty2(tint) {
2054
+ if (!tint) return true;
2055
+ return tint.topLeft === void 0 && tint.topRight === void 0 && tint.bottomLeft === void 0 && tint.bottomRight === void 0;
2056
+ }
2057
+ TintSchema2.isEmpty = isEmpty2;
2058
+ })(TintSchema || (TintSchema = {}));
2059
+ var CropSchemaDecoration = {
2060
+ label: "\u88C1\u526A",
2061
+ properties: {
2062
+ width: { label: "\u5BBD", type: "integer" },
2063
+ height: { label: "\u9AD8", type: "integer" },
2064
+ x: { label: "x", type: "integer" },
2065
+ y: { label: "y", type: "integer" }
2066
+ },
2067
+ type: "object"
2068
+ };
2069
+ var FlipSchemaDecoration = {
2070
+ label: "\u955C\u50CF\u66FF\u6362",
2071
+ properties: {
2072
+ x: { label: "\u6C34\u5E73\u955C\u50CF\u66FF\u6362", default: false, type: "boolean" },
2073
+ y: { label: "\u5782\u76F4\u955C\u50CF\u66FF\u6362", default: false, type: "boolean" }
2074
+ },
2075
+ type: "object"
2076
+ };
2077
+ var PaddingSchemaDecoration = {
2078
+ label: "\u7559\u767D",
2079
+ properties: {
2080
+ left: { label: "\u5DE6", default: 0, type: "integer" },
2081
+ top: { label: "\u4E0A", default: 0, type: "integer" },
2082
+ right: { label: "\u53F3", default: 0, type: "integer" },
2083
+ bottom: { label: "\u4E0B", default: 0, type: "integer" }
2084
+ },
2085
+ type: "object"
2086
+ };
2087
+ var ShadowSchemaDecoration = {
2088
+ label: "\u9634\u5F71",
2089
+ properties: {
2090
+ offsetX: { label: "X", type: "integer" },
2091
+ offsetY: { label: "Y", type: "integer" },
2092
+ blur: { label: "\u6A21\u7CCA", type: "integer" },
2093
+ color: { label: "\u989C\u8272", type: "color" }
2094
+ },
2095
+ type: "object"
2096
+ };
2097
+ var TintSchemaDecoration = {
2098
+ label: "\u989C\u8272",
2099
+ properties: {
2100
+ topLeft: { label: "\u5DE6\u4E0A", type: "color" },
2101
+ topRight: { label: "\u53F3\u4E0A", type: "color" },
2102
+ bottomLeft: { label: "\u5DE6\u4E0B", type: "color" },
2103
+ bottomRight: { label: "\u53F3\u4E0B", type: "color" }
2104
+ },
2105
+ type: "object"
2106
+ };
2107
+ var OpacitySchemaDecoration = {
2108
+ label: "\u900F\u660E\u5EA6",
2109
+ type: "float",
2110
+ min: 0,
2111
+ max: 1,
2112
+ default: 1
2113
+ };
2114
+
2115
+ // src/dom-utils.ts
2116
+ import clx from "clsx";
2117
+ var toStyleKey = (key) => key.replace(/([A-Z])/, (k) => `-${k.toLowerCase()}`);
2118
+ var domUtils;
2119
+ ((domUtils2) => {
2120
+ function toPixel(num) {
2121
+ return `${num}px`;
2122
+ }
2123
+ domUtils2.toPixel = toPixel;
2124
+ function fromPercent(percent) {
2125
+ return parseFloat(percent.substring(0, percent.length - 1));
2126
+ }
2127
+ domUtils2.fromPercent = fromPercent;
2128
+ function toPercent(percent) {
2129
+ return `${percent}%`;
2130
+ }
2131
+ domUtils2.toPercent = toPercent;
2132
+ function enableEvent(element) {
2133
+ element.style.pointerEvents = "all";
2134
+ }
2135
+ domUtils2.enableEvent = enableEvent;
2136
+ function disableEvent(element) {
2137
+ element.style.pointerEvents = "none";
2138
+ }
2139
+ domUtils2.disableEvent = disableEvent;
2140
+ function createElement(ele, ...classNames) {
2141
+ const element = document.createElement(ele);
2142
+ if (classNames.length > 0) {
2143
+ element.className = clx(classNames);
2144
+ }
2145
+ return element;
2146
+ }
2147
+ domUtils2.createElement = createElement;
2148
+ function createDivWithClass(...classNames) {
2149
+ return createElement("div", ...classNames);
2150
+ }
2151
+ domUtils2.createDivWithClass = createDivWithClass;
2152
+ function addClass(element, ...classNames) {
2153
+ element.className = clx(classNames.concat(element.className.split(" ")));
2154
+ }
2155
+ domUtils2.addClass = addClass;
2156
+ function delClass(element, ...classNames) {
2157
+ classNames.forEach((name) => {
2158
+ element.classList.remove(name);
2159
+ });
2160
+ element.className = element.classList.toString();
2161
+ }
2162
+ domUtils2.delClass = delClass;
2163
+ function coverClass(element, ...classNames) {
2164
+ element.className = clx(classNames);
2165
+ }
2166
+ domUtils2.coverClass = coverClass;
2167
+ function clearChildren(container) {
2168
+ container.innerHTML = "";
2169
+ }
2170
+ domUtils2.clearChildren = clearChildren;
2171
+ function translatePercent(node, x, y) {
2172
+ node.style.transform = `translate(${x}%, ${y}%)`;
2173
+ }
2174
+ domUtils2.translatePercent = translatePercent;
2175
+ function translateXPercent(node, x) {
2176
+ node.style.transform = `translateX(${x}%)`;
2177
+ }
2178
+ domUtils2.translateXPercent = translateXPercent;
2179
+ function translateYPercent(node, y) {
2180
+ node.style.transform = `translateY(${y}%)`;
2181
+ }
2182
+ domUtils2.translateYPercent = translateYPercent;
2183
+ function setStyle(node, styles) {
2184
+ const styleStrs = [];
2185
+ each(styles, (value, key) => {
2186
+ if (value === void 0) return;
2187
+ if (typeof value === "number" && key !== "opacity" && key !== "zIndex" && key !== "scale") {
2188
+ value = toPixel(value);
2189
+ }
2190
+ styleStrs.push(`${toStyleKey(key)}:${value}`);
2191
+ });
2192
+ const oldStyle = node.getAttribute("style");
2193
+ const newStyle = styleStrs.join(";");
2194
+ if (oldStyle !== newStyle) {
2195
+ node.setAttribute("style", newStyle);
2196
+ }
2197
+ }
2198
+ domUtils2.setStyle = setStyle;
2199
+ function classNameWithPrefix(prefix) {
2200
+ return (key, opts) => clx(
2201
+ key.split(/\s+/).map((s) => `${prefix}-${s}`).join(" "),
2202
+ opts
2203
+ );
2204
+ }
2205
+ domUtils2.classNameWithPrefix = classNameWithPrefix;
2206
+ function addStandardDisposableListener(dom, type, listener, options) {
2207
+ dom.addEventListener(type, listener, options);
2208
+ return Disposable.create(() => {
2209
+ dom.removeEventListener(type, listener);
2210
+ });
2211
+ }
2212
+ domUtils2.addStandardDisposableListener = addStandardDisposableListener;
2213
+ function createDOMCache(parent, className, children) {
2214
+ return Cache.create(() => {
2215
+ const dom = typeof className === "string" ? domUtils2.createDivWithClass(className) : className();
2216
+ if (children) {
2217
+ dom.innerHTML = children;
2218
+ }
2219
+ parent.appendChild(dom);
2220
+ return Object.assign(dom, {
2221
+ // key: item ? item.key : undefined,
2222
+ dispose: () => {
2223
+ const { parentNode } = dom;
2224
+ if (parentNode) {
2225
+ parentNode.removeChild(dom);
2226
+ }
2227
+ },
2228
+ setStyle: (style) => {
2229
+ domUtils2.setStyle(dom, style);
2230
+ }
2231
+ });
2232
+ });
2233
+ }
2234
+ domUtils2.createDOMCache = createDOMCache;
2235
+ })(domUtils || (domUtils = {}));
2236
+
2237
+ // src/id.ts
2238
+ var _idx = 0;
2239
+ function generateLocalId() {
2240
+ if (_idx === Number.MAX_SAFE_INTEGER) {
2241
+ _idx = 0;
2242
+ }
2243
+ return _idx++;
2244
+ }
2245
+ function _setIdx(idx) {
2246
+ _idx = idx;
2247
+ }
2248
+
2249
+ // src/array.ts
2250
+ function iterToArray(iter) {
2251
+ const result = [];
2252
+ for (const v of iter) {
2253
+ result.push(v);
2254
+ }
2255
+ return result;
2256
+ }
2257
+ function arrayToSet(arr) {
2258
+ const set = /* @__PURE__ */ new Set();
2259
+ for (let i = 0, len = arr.length; i < len; i++) {
2260
+ set.add(arr[i]);
2261
+ }
2262
+ return set;
2263
+ }
2264
+ function arrayUnion(arr) {
2265
+ const result = [];
2266
+ for (let i = 0, len = arr.length; i < len; i++) {
2267
+ if (!result.includes(arr[i])) result.push(arr[i]);
2268
+ }
2269
+ return result;
2270
+ }
2271
+
2272
+ // src/inversify-utils.ts
2273
+ function bindContributions(bind, target, contribs) {
2274
+ bind(target).toSelf().inSingletonScope();
2275
+ contribs.forEach((contrib) => bind(contrib).toService(target));
2276
+ }
2277
+
2278
+ // src/request-with-memo.ts
2279
+ var RequestCache = /* @__PURE__ */ new Map();
2280
+ var CACHE_TIME = 1e4;
2281
+ function clearRequestCache() {
2282
+ RequestCache.clear();
2283
+ }
2284
+ function requestWithMemo(req, cacheTime = CACHE_TIME, createCacheKey) {
2285
+ return (...args) => {
2286
+ const cacheKey = createCacheKey ? createCacheKey(...args) : req;
2287
+ if (RequestCache.has(cacheKey)) {
2288
+ return Promise.resolve(RequestCache.get(cacheKey));
2289
+ }
2290
+ const result = req(...args);
2291
+ const time = setTimeout(() => RequestCache.delete(cacheKey), cacheTime);
2292
+ const withErrorResult = result.catch((e) => {
2293
+ RequestCache.delete(cacheKey);
2294
+ clearTimeout(time);
2295
+ throw e;
2296
+ });
2297
+ RequestCache.set(cacheKey, withErrorResult);
2298
+ return withErrorResult;
2299
+ };
2300
+ }
2301
+
2302
+ // src/compose.ts
2303
+ function composeAsync(...fns) {
2304
+ return async (data, ...others) => {
2305
+ let index = 0;
2306
+ while (fns[index]) {
2307
+ data = await fns[index](data, ...others);
2308
+ index += 1;
2309
+ }
2310
+ return data;
2311
+ };
2312
+ }
2313
+ function compose(...fns) {
2314
+ return (data, ...others) => {
2315
+ let index = 0;
2316
+ while (fns[index]) {
2317
+ data = fns[index](data, ...others);
2318
+ index += 1;
2319
+ }
2320
+ return data;
2321
+ };
2322
+ }
2323
+
2324
+ // src/contribution-provider.ts
2325
+ var ContributionProvider = Symbol("ContributionProvider");
2326
+ var ContainerContributionProviderImpl = class {
2327
+ constructor(container, identifier) {
2328
+ this.container = container;
2329
+ this.identifier = identifier;
2330
+ }
2331
+ forEach(fn) {
2332
+ this.getContributions().forEach(fn);
2333
+ }
2334
+ getContributions() {
2335
+ if (!this.services) {
2336
+ const currentServices = [];
2337
+ let { container } = this;
2338
+ if (container.isBound(this.identifier)) {
2339
+ try {
2340
+ currentServices.push(...container.getAll(this.identifier));
2341
+ } catch (error) {
2342
+ console.error(error);
2343
+ }
2344
+ }
2345
+ this.services = currentServices;
2346
+ }
2347
+ return this.services;
2348
+ }
2349
+ };
2350
+ function bindContributionProvider(bind, id) {
2351
+ bind(ContributionProvider).toDynamicValue((ctx) => new ContainerContributionProviderImpl(ctx.container, id)).inSingletonScope().whenTargetNamed(id);
2352
+ }
2353
+
2354
+ // src/add-event-listener.ts
2355
+ function addEventListener(element, type, listener, useCapture) {
2356
+ element.addEventListener(type, listener, useCapture);
2357
+ return Disposable.create(() => element.removeEventListener(type, listener, useCapture));
2358
+ }
2359
+
2360
+ // src/logger.ts
2361
+ var Logger = class {
2362
+ isDevEnv() {
2363
+ return process.env.NODE_ENV === "development";
2364
+ }
2365
+ info(...props) {
2366
+ if (!this.isDevEnv()) return;
2367
+ return console.info(props);
2368
+ }
2369
+ log(...props) {
2370
+ if (!this.isDevEnv()) return;
2371
+ return console.log(...props);
2372
+ }
2373
+ error(...props) {
2374
+ return console.error(...props);
2375
+ }
2376
+ warn(...props) {
2377
+ return console.warn(...props);
2378
+ }
2379
+ };
2380
+ var logger = new Logger();
2381
+
2382
+ // src/decoration-style.ts
2383
+ function createStyleElement(styleId, container = document.head) {
2384
+ const style = document.createElement("style");
2385
+ style.id = styleId;
2386
+ style.type = "text/css";
2387
+ style.media = "screen";
2388
+ style.appendChild(document.createTextNode(""));
2389
+ container.appendChild(style);
2390
+ return style;
2391
+ }
2392
+ var DecorationStyle = {
2393
+ createStyleElement
2394
+ };
2395
+
2396
+ // src/hooks/use-refresh.ts
2397
+ import { useCallback, useState } from "react";
2398
+ function useRefresh(defaultValue) {
2399
+ const [, update] = useState(defaultValue);
2400
+ return useCallback((v) => update(v !== void 0 ? v : {}), []);
2401
+ }
2402
+ export {
2403
+ Angle,
2404
+ Cache,
2405
+ CancellationToken,
2406
+ CancellationTokenSource,
2407
+ Circle,
2408
+ Compare,
2409
+ ContributionProvider,
2410
+ CropSchemaDecoration,
2411
+ DEG_TO_RAD,
2412
+ DecorationStyle,
2413
+ Deferred,
2414
+ Disposable,
2415
+ DisposableCollection,
2416
+ DisposableImpl,
2417
+ Emitter,
2418
+ Event,
2419
+ FlipSchemaDecoration,
2420
+ Matrix,
2421
+ MutableToken,
2422
+ NOOP,
2423
+ OBBRect,
2424
+ OpacitySchemaDecoration,
2425
+ OriginSchemaDecoration,
2426
+ PI,
2427
+ PI_2,
2428
+ PaddingSchema,
2429
+ PaddingSchemaDecoration,
2430
+ Point,
2431
+ PositionSchemaDecoration,
2432
+ PromiseDeferred,
2433
+ PromisePool,
2434
+ RAD_TO_DEG,
2435
+ Rectangle,
2436
+ RectangleAlignTitle,
2437
+ RectangleAlignType,
2438
+ RequestCache,
2439
+ RotationSchemaDecoration,
2440
+ SHAPES,
2441
+ ScaleSchemaDecoration,
2442
+ Schema,
2443
+ SchemaDecoration,
2444
+ ShadowSchemaDecoration,
2445
+ SizeSchema,
2446
+ SizeSchemaDecoration,
2447
+ SkewSchemaDecoration,
2448
+ TintSchema,
2449
+ TintSchemaDecoration,
2450
+ Transform,
2451
+ TransformSchema,
2452
+ TransformSchemaDecoration,
2453
+ _setIdx,
2454
+ addEventListener,
2455
+ arrayToSet,
2456
+ arrayUnion,
2457
+ bindContributionProvider,
2458
+ bindContributions,
2459
+ cancelled,
2460
+ checkCancelled,
2461
+ clearRequestCache,
2462
+ compose,
2463
+ composeAsync,
2464
+ deepFreeze,
2465
+ delay,
2466
+ domUtils,
2467
+ each,
2468
+ filter,
2469
+ generateLocalId,
2470
+ getByKey,
2471
+ getTag,
2472
+ isCancelled,
2473
+ isEmpty,
2474
+ isFunction,
2475
+ isNumber,
2476
+ isObject,
2477
+ isPlainObject,
2478
+ isString,
2479
+ iterToArray,
2480
+ logger,
2481
+ mapKeys,
2482
+ mapValues,
2483
+ notEmpty,
2484
+ omit,
2485
+ pick,
2486
+ reduce,
2487
+ requestWithMemo,
2488
+ retry,
2489
+ setByKey,
2490
+ useRefresh,
2491
+ values
2492
+ };
2493
+ //# sourceMappingURL=index.js.map