@galacean/engine-ui 2.0.0-alpha.5 → 2.0.0-alpha.51

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/module.js CHANGED
@@ -1,90 +1,4 @@
1
- import { EntityModifyFlags, ignoreClone, assignmentClone, DisorderedArray, Component, TransformModifyFlags, Transform, deepClone, Vector2, Rect, MathUtil, Vector3, Matrix, Plane, ShaderProperty, dependentComponents, DependentMode, BatchUtils, ShaderMacroCollection, Renderer, Vector4, Color, RendererUpdateFlags, Entity, Script, Camera, CameraModifyFlags, Logger, SafeLoopArray, SpriteDrawMode, RenderQueueFlags, SpriteModifyFlags, SpriteTileMode, TiledSpriteAssembler, SlicedSpriteAssembler, SimpleSpriteAssembler, BoundingBox, ShaderData, ShaderDataGroup, TextUtils, Engine, TextVerticalAlignment, TextHorizontalAlignment, OverflowMode, CharRenderInfo, FontStyle, ReferResource, registerPointerEventEmitter, PointerEventEmitter, CameraClearFlags, ReflectionParser, Material, BlendFactor, BlendOperation, CullMode, RenderQueueType, Loader, Shader, ShaderPass, PipelineStage, Font } from '@galacean/engine';
2
-
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
4
- try {
5
- var info = gen[key](arg);
6
- var value = info.value;
7
- } catch (error) {
8
- reject(error);
9
- return;
10
- }
11
- if (info.done) resolve(value);
12
- else Promise.resolve(value).then(_next, _throw);
13
- }
14
- function _async_to_generator(fn) {
15
- return function() {
16
- var self = this, args = arguments;
17
-
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
-
21
- function _next(value) {
22
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
- }
24
-
25
- function _throw(err) {
26
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
27
- }
28
-
29
- _next(undefined);
30
- });
31
- };
32
- }
33
-
34
- /******************************************************************************
35
- Copyright (c) Microsoft Corporation.
36
-
37
- Permission to use, copy, modify, and/or distribute this software for any
38
- purpose with or without fee is hereby granted.
39
-
40
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
41
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
42
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
43
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
44
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
45
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
46
- PERFORMANCE OF THIS SOFTWARE.
47
- ***************************************************************************** */
48
-
49
- function __decorate(decorators, target, key, desc) {
50
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
51
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
52
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
53
- return c > 3 && r && Object.defineProperty(target, key, r), r;
54
- }
55
-
56
- function __generator(thisArg, body) {
57
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
58
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
59
- function verb(n) { return function (v) { return step([n, v]); }; }
60
- function step(op) {
61
- if (f) throw new TypeError("Generator is already executing.");
62
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
63
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
- if (y = 0, t) op = [op[0] & 2, t.value];
65
- switch (op[0]) {
66
- case 0: case 1: t = op; break;
67
- case 4: _.label++; return { value: op[1], done: false };
68
- case 5: _.label++; y = op[1]; op = [0]; continue;
69
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
70
- default:
71
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
72
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
73
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
74
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
75
- if (t[2]) _.ops.pop();
76
- _.trys.pop(); continue;
77
- }
78
- op = body.call(thisArg, _);
79
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
80
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
81
- }
82
- }
83
-
84
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
85
- var e = new Error(message);
86
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
87
- };
1
+ import { EntityModifyFlags, ignoreClone, DisorderedArray, Component, Matrix, BoundingBox, Utils as Utils$1, TransformModifyFlags, Transform, Vector2, Rect, MathUtil, Vector3, Plane, ShaderProperty, dependentComponents, DependentMode, VertexMergeBatcher, ShaderMacroCollection, Renderer, Vector4, Color, RendererUpdateFlags, Script, CameraModifyFlags, Logger, Signal, SpriteDrawMode, SpriteModifyFlags, SpriteTileMode, TiledSpriteAssembler, SlicedSpriteAssembler, SimpleSpriteAssembler, ShaderData, ShaderDataGroup, TextUtils, Engine, TextVerticalAlignment, TextHorizontalAlignment, OverflowMode, CharRenderInfo, FontStyle, ReferResource, DataObject, registerPointerEventEmitter, PointerEventEmitter, Layer, CameraClearFlags, Material, Entity, Loader, Shader } from '@galacean/engine';
88
2
 
89
3
  function _defineProperties(target, props) {
90
4
  for (var i = 0; i < props.length; i++) {
@@ -130,6 +44,33 @@ function _instanceof(left, right) {
130
44
  } else return left instanceof right;
131
45
  }
132
46
 
47
+ /******************************************************************************
48
+ Copyright (c) Microsoft Corporation.
49
+
50
+ Permission to use, copy, modify, and/or distribute this software for any
51
+ purpose with or without fee is hereby granted.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
54
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
55
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
56
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
57
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
58
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
59
+ PERFORMANCE OF THIS SOFTWARE.
60
+ ***************************************************************************** */
61
+
62
+ function __decorate(decorators, target, key, desc) {
63
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
64
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
65
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
66
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
67
+ }
68
+
69
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
70
+ var e = new Error(message);
71
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
72
+ };
73
+
133
74
  var UIGroup = /*#__PURE__*/ function(Component) {
134
75
  _inherits(UIGroup, Component);
135
76
  function UIGroup(entity) {
@@ -168,15 +109,17 @@ var UIGroup = /*#__PURE__*/ function(Component) {
168
109
  }
169
110
  return this._globalInteractive;
170
111
  };
171
- // @ts-ignore
172
- _proto._onEnableInScene = function _onEnableInScene() {
112
+ /**
113
+ * @internal
114
+ */ _proto._onEnableInScene = function _onEnableInScene() {
173
115
  Utils.setRootCanvasDirty(this);
174
116
  Utils.setGroupDirty(this);
175
117
  // @ts-ignore
176
118
  this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
177
119
  };
178
- // @ts-ignore
179
- _proto._onDisableInScene = function _onDisableInScene() {
120
+ /**
121
+ * @internal
122
+ */ _proto._onDisableInScene = function _onDisableInScene() {
180
123
  Utils.cleanRootCanvas(this);
181
124
  Utils.cleanGroup(this);
182
125
  var disorderedElements = this._disorderedElements;
@@ -292,30 +235,12 @@ __decorate([
292
235
  __decorate([
293
236
  ignoreClone
294
237
  ], UIGroup.prototype, "_indexInRootCanvas", void 0);
295
- __decorate([
296
- ignoreClone
297
- ], UIGroup.prototype, "_group", void 0);
298
- __decorate([
299
- ignoreClone
300
- ], UIGroup.prototype, "_rootCanvas", void 0);
301
- __decorate([
302
- ignoreClone
303
- ], UIGroup.prototype, "_disorderedElements", void 0);
304
238
  __decorate([
305
239
  ignoreClone
306
240
  ], UIGroup.prototype, "_globalAlpha", void 0);
307
241
  __decorate([
308
242
  ignoreClone
309
243
  ], UIGroup.prototype, "_globalInteractive", void 0);
310
- __decorate([
311
- assignmentClone
312
- ], UIGroup.prototype, "_alpha", void 0);
313
- __decorate([
314
- assignmentClone
315
- ], UIGroup.prototype, "_interactive", void 0);
316
- __decorate([
317
- assignmentClone
318
- ], UIGroup.prototype, "_ignoreParentGroup", void 0);
319
244
  __decorate([
320
245
  ignoreClone
321
246
  ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
@@ -368,7 +293,6 @@ var Utils = /*#__PURE__*/ function() {
368
293
  Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
369
294
  var entity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
370
295
  while(entity){
371
- // @ts-ignore
372
296
  var components = entity._components;
373
297
  for(var i = 0, n = components.length; i < n; i++){
374
298
  var component = components[i];
@@ -409,7 +333,6 @@ var Utils = /*#__PURE__*/ function() {
409
333
  var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
410
334
  var rootCanvasParent = rootCanvas.entity.parent;
411
335
  while(entity && entity !== rootCanvasParent){
412
- // @ts-ignore
413
336
  var components = entity._components;
414
337
  for(var i = 0, n = components.length; i < n; i++){
415
338
  var component = components[i];
@@ -459,10 +382,8 @@ var Utils = /*#__PURE__*/ function() {
459
382
  while(entity && entity !== root){
460
383
  var preEntity = listeningEntities[count];
461
384
  if (preEntity !== entity) {
462
- // @ts-ignore
463
385
  preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
464
386
  listeningEntities[count] = entity;
465
- // @ts-ignore
466
387
  entity._registerModifyListener(listener);
467
388
  }
468
389
  entity = entity.parent;
@@ -472,7 +393,6 @@ var Utils = /*#__PURE__*/ function() {
472
393
  };
473
394
  Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
474
395
  for(var i = 0, n = listeningEntities.length; i < n; i++){
475
- // @ts-ignore
476
396
  listeningEntities[i]._unRegisterModifyListener(listener);
477
397
  }
478
398
  listeningEntities.length = 0;
@@ -480,6 +400,154 @@ var Utils = /*#__PURE__*/ function() {
480
400
  return Utils;
481
401
  }();
482
402
 
403
+ /**
404
+ * @internal
405
+ * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
406
+ *
407
+ * Think of it as stacking elements onto numbered shelves (depths):
408
+ * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
409
+ * - Overlapping + batch-compatible — share the same shelf, still cluster.
410
+ * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
411
+ *
412
+ * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
413
+ * share the same depth and get clustered together. Once depth is assigned, sort by
414
+ * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
415
+ * by-product of materials clustering within each depth band.
416
+ *
417
+ * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
418
+ * are derived from the union AABB of input elements (the bounds transform itself is the
419
+ * work the loop must do anyway, so the union accumulation just piggybacks). This stays
420
+ * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
421
+ * on canvas configuration.
422
+ */ var UIBatchSorter = /*#__PURE__*/ function() {
423
+ function UIBatchSorter() {}
424
+ /**
425
+ * Reorders `elements` in place for optimal batching.
426
+ * @param elements - in hierarchy order (depth-first traversal); mutated in place
427
+ * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
428
+ */ UIBatchSorter.sort = function sort(elements, canvasWorldMatrix) {
429
+ var count = elements.length;
430
+ if (count <= 1) return;
431
+ var gridDim = this._gridDim;
432
+ var entries = this._entries;
433
+ var grid = this._grid;
434
+ var dirtyCells = this._dirtyCells;
435
+ var localBoundsPool = this._localBoundsPool;
436
+ var worldToLocal = this._worldToLocal;
437
+ Matrix.invert(canvasWorldMatrix, worldToLocal);
438
+ while(entries.length < count)entries.push(new SortEntry());
439
+ // Allocate grid once, reuse forever (each cell must be a real [], not a sparse hole)
440
+ if (grid.length < gridDim) {
441
+ while(grid.length < gridDim)grid.push([]);
442
+ for(var i = 0; i < gridDim; i++){
443
+ var row = grid[i];
444
+ while(row.length < gridDim)row.push([]);
445
+ }
446
+ }
447
+ // Clear only previously-used cells (no full sweep)
448
+ for(var k = 0, n = dirtyCells.length; k < n; k += 2){
449
+ grid[dirtyCells[k]][dirtyCells[k + 1]].length = 0;
450
+ }
451
+ dirtyCells.length = 0;
452
+ // Pass 1: transform world bounds to canvas-local + accumulate the union AABB.
453
+ // Transform is already required to do precise overlap, so the union accumulation
454
+ // is essentially free — just a few minmax compares riding on the existing pass
455
+ var unionMinX = Infinity;
456
+ var unionMinY = Infinity;
457
+ var unionMaxX = -Infinity;
458
+ var unionMaxY = -Infinity;
459
+ for(var i1 = 0; i1 < count; i1++){
460
+ var _localBoundsPool, _i;
461
+ var localBounds = (_localBoundsPool = localBoundsPool)[_i = i1] || (_localBoundsPool[_i] = new BoundingBox());
462
+ BoundingBox.transform(elements[i1].component.bounds, worldToLocal, localBounds);
463
+ var min = localBounds.min, max = localBounds.max;
464
+ if (min.x < unionMinX) unionMinX = min.x;
465
+ if (min.y < unionMinY) unionMinY = min.y;
466
+ if (max.x > unionMaxX) unionMaxX = max.x;
467
+ if (max.y > unionMaxY) unionMaxY = max.y;
468
+ }
469
+ // Guard against a degenerate union (all elements collapsed onto a single point /
470
+ // axis); the grid then collapses to cell 0 which is semantically correct
471
+ var cellSizeX = Math.max(1e-6, unionMaxX - unionMinX) / gridDim;
472
+ var cellSizeY = Math.max(1e-6, unionMaxY - unionMinY) / gridDim;
473
+ var maxCell = gridDim - 1;
474
+ // Pass 2: register each element into grid cells and compute its depth
475
+ for(var i2 = 0; i2 < count; i2++){
476
+ var element = elements[i2];
477
+ var localBounds1 = localBoundsPool[i2];
478
+ var materialId = element.material.instanceId;
479
+ var textureId = element.texture ? element.texture.instanceId : 0;
480
+ // Floor + clamp guards floating-point edge cases (a `max` exactly on the union
481
+ // boundary would otherwise produce `gridDim`)
482
+ var minCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.x - unionMinX) / cellSizeX)));
483
+ var maxCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.x - unionMinX) / cellSizeX)));
484
+ var minCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.y - unionMinY) / cellSizeY)));
485
+ var maxCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.y - unionMinY) / cellSizeY)));
486
+ // Find the deepest overlapping prior, and whether that shelf has any incompatible occupant
487
+ var maxDepth = -1;
488
+ var maxDepthIncompatible = false;
489
+ for(var cellY = minCellY; cellY <= maxCellY; cellY++){
490
+ for(var cellX = minCellX; cellX <= maxCellX; cellX++){
491
+ var cell = grid[cellX][cellY];
492
+ for(var j = 0, m = cell.length; j < m; j++){
493
+ var other = cell[j];
494
+ if (!UIBatchSorter._rectOverlap(localBounds1, other.bounds)) continue;
495
+ var otherDepth = other.depth;
496
+ var otherIncompatible = other.materialId !== materialId || other.textureId !== textureId;
497
+ if (otherDepth > maxDepth) {
498
+ maxDepth = otherDepth;
499
+ maxDepthIncompatible = otherIncompatible;
500
+ } else if (otherDepth === maxDepth && otherIncompatible) {
501
+ maxDepthIncompatible = true;
502
+ }
503
+ }
504
+ }
505
+ }
506
+ var entry = entries[i2];
507
+ entry.element = element;
508
+ entry.hierarchyIndex = i2;
509
+ // Share the deepest shelf if compatible; bump up one if blocked by an incompatible occupant
510
+ entry.depth = maxDepth < 0 ? 0 : maxDepth + (maxDepthIncompatible ? 1 : 0);
511
+ entry.materialId = materialId;
512
+ entry.textureId = textureId;
513
+ entry.bounds = localBounds1;
514
+ for(var cellY1 = minCellY; cellY1 <= maxCellY; cellY1++){
515
+ for(var cellX1 = minCellX; cellX1 <= maxCellX; cellX1++){
516
+ var cell1 = grid[cellX1][cellY1];
517
+ if (cell1.length === 0) dirtyCells.push(cellX1, cellY1);
518
+ cell1.push(entry);
519
+ }
520
+ }
521
+ }
522
+ Utils$1._quickSort(entries, 0, count, UIBatchSorter._compareEntries);
523
+ for(var i3 = 0; i3 < count; i3++)elements[i3] = entries[i3].element;
524
+ };
525
+ UIBatchSorter._rectOverlap = function _rectOverlap(a, b) {
526
+ return a.min.x < b.max.x && a.max.x > b.min.x && a.min.y < b.max.y && a.max.y > b.min.y;
527
+ };
528
+ UIBatchSorter._compareEntries = function _compareEntries(a, b) {
529
+ return a.depth - b.depth || a.materialId - b.materialId || a.textureId - b.textureId || a.hierarchyIndex - b.hierarchyIndex;
530
+ };
531
+ return UIBatchSorter;
532
+ }();
533
+ // Spatial-hash is fastest when cell size ≈ typical element size (one element per cell).
534
+ // UI elements typically span ~10% of the canvas → 10×10 grid.
535
+ UIBatchSorter._gridDim = 10;
536
+ UIBatchSorter._entries = new Array();
537
+ UIBatchSorter._grid = [];
538
+ // Interleaved (x, y) cell coords touched in the previous frame
539
+ UIBatchSorter._dirtyCells = new Array();
540
+ UIBatchSorter._localBoundsPool = new Array();
541
+ UIBatchSorter._worldToLocal = new Matrix();
542
+ // materialId/textureId/bounds are flattened from RenderElement to avoid
543
+ // multi-hop property access in the hot inner loop and the sort comparator.
544
+ var SortEntry = function SortEntry() {
545
+ this.hierarchyIndex = 0;
546
+ this.depth = 0;
547
+ this.materialId = 0;
548
+ this.textureId = 0;
549
+ };
550
+
483
551
  /**
484
552
  * Render mode for ui canvas.
485
553
  */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
@@ -501,14 +569,16 @@ var Utils = /*#__PURE__*/ function() {
501
569
  }({});
502
570
 
503
571
  /**
504
- * Resolution adaptation mode.
505
- * @remarks Only effective in screen space.
572
+ * Resolution adaptation in screen space.
573
+ * Scale ratios are available size / `referenceResolution` per axis.
574
+ * Available size comes from the canvas in Overlay mode or the camera's standard projection at `distance`
575
+ * in Camera mode; a custom `Camera.projectionMatrix` is not reflected.
506
576
  */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
507
577
  /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
508
578
  /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
509
579
  /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
510
- /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
511
- /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
580
+ /** Use the smaller scale ratio to fit the reference rectangle; the UICanvas expands on the other axis. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
581
+ /** Use the larger scale ratio to cover the available area; the reference rectangle may overflow. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
512
582
  return ResolutionAdaptationMode;
513
583
  }({});
514
584
 
@@ -552,10 +622,11 @@ var Utils = /*#__PURE__*/ function() {
552
622
  this._isParentDirty = true;
553
623
  this._updateWorldFlagWithParentRectChange(TransformModifyFlags.WmWpWeWqWsWus);
554
624
  };
555
- // @ts-ignore
556
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
557
- // @ts-ignore
558
- Transform.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
625
+ /**
626
+ * @internal
627
+ * @inheritdoc
628
+ */ _proto._onClone = function _onClone(target) {
629
+ Transform.prototype._onClone.call(this, target);
559
630
  var size = target._size, pivot = target._pivot;
560
631
  // @ts-ignore
561
632
  size._onValueChanged = pivot._onValueChanged = null;
@@ -657,13 +728,11 @@ var Utils = /*#__PURE__*/ function() {
657
728
  }
658
729
  this._updateRectBySizeAndPivot();
659
730
  this._updateWorldFlagWithSelfRectChange();
660
- // @ts-ignore
661
731
  this._entity._updateFlagManager.dispatch(512);
662
732
  };
663
733
  _proto._onPivotChanged = function _onPivotChanged() {
664
734
  this._updateRectBySizeAndPivot();
665
735
  this._updateWorldFlagWithSelfRectChange();
666
- // @ts-ignore
667
736
  this._entity._updateFlagManager.dispatch(1024);
668
737
  };
669
738
  _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
@@ -705,14 +774,14 @@ var Utils = /*#__PURE__*/ function() {
705
774
  (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, flags, selfChange);
706
775
  }
707
776
  }
708
- // @ts-ignore
709
777
  selfChange && this._entity._updateFlagManager.dispatch(512);
710
778
  };
711
779
  _create_class(UITransform, [
712
780
  {
713
781
  key: "size",
714
782
  get: /**
715
- * Width and height of UI element.
783
+ * Width and height in local units, before transform scaling.
784
+ * Screen-space units are pixels at the root canvas's {@link UICanvas.referenceResolution}; world-space units are scene units.
716
785
  */ function get() {
717
786
  return this._size;
718
787
  },
@@ -916,9 +985,6 @@ __decorate([
916
985
  __decorate([
917
986
  ignoreClone
918
987
  ], UITransform.prototype, "_pivot", void 0);
919
- __decorate([
920
- deepClone
921
- ], UITransform.prototype, "_rect", void 0);
922
988
  __decorate([
923
989
  ignoreClone
924
990
  ], UITransform.prototype, "_onPositionChanged", null);
@@ -957,42 +1023,44 @@ var UIRenderer = /*#__PURE__*/ function(Renderer) {
957
1023
  return _this;
958
1024
  }
959
1025
  var _proto = UIRenderer.prototype;
960
- // @ts-ignore
961
- _proto._canBatch = function _canBatch(elementA, elementB) {
962
- return BatchUtils.canBatchSprite(elementA, elementB);
1026
+ /**
1027
+ * @internal
1028
+ */ _proto._canBatch = function _canBatch(preElement, curElement) {
1029
+ return VertexMergeBatcher.canBatchSprite(preElement, curElement);
963
1030
  };
964
- // @ts-ignore
965
- _proto._batch = function _batch(elementA, elementB) {
966
- BatchUtils.batchFor2D(elementA, elementB);
1031
+ /**
1032
+ * @internal
1033
+ */ _proto._batch = function _batch(preElement, curElement) {
1034
+ VertexMergeBatcher.batch(preElement, curElement);
967
1035
  };
968
- // @ts-ignore
969
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
1036
+ /**
1037
+ * @internal
1038
+ */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP) {
970
1039
  // @ts-ignore
971
- Renderer.prototype._updateTransformShaderData.call(this, context, onlyMVP, true);
1040
+ this._updateWorldSpaceTransformShaderData(context, onlyMVP);
972
1041
  };
973
- // @ts-ignore
974
- _proto._prepareRender = function _prepareRender(context) {
1042
+ /**
1043
+ * @internal
1044
+ */ _proto._prepareRender = function _prepareRender(context) {
975
1045
  // Update once per frame per renderer, not influenced by batched
976
1046
  if (this._renderFrameCount !== this.engine.time.frameCount) {
977
1047
  this._update(context);
978
1048
  }
979
1049
  this._render(context);
980
1050
  // union camera global macro and renderer macro.
981
- ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
982
- this.shaderData._macroCollection, //@ts-ignore
983
- this._globalShaderMacro);
1051
+ ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, this.shaderData._macroCollection, this._globalShaderMacro);
984
1052
  };
985
- // @ts-ignore
986
- _proto._onEnableInScene = function _onEnableInScene() {
987
- // @ts-ignore
1053
+ /**
1054
+ * @internal
1055
+ */ _proto._onEnableInScene = function _onEnableInScene() {
988
1056
  this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
989
1057
  this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
990
1058
  Utils.setRootCanvasDirty(this);
991
1059
  Utils.setGroupDirty(this);
992
1060
  };
993
- // @ts-ignore
994
- _proto._onDisableInScene = function _onDisableInScene() {
995
- // @ts-ignore
1061
+ /**
1062
+ * @internal
1063
+ */ _proto._onDisableInScene = function _onDisableInScene() {
996
1064
  this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
997
1065
  this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
998
1066
  Utils.cleanRootCanvas(this);
@@ -1049,13 +1117,11 @@ var UIRenderer = /*#__PURE__*/ function(Renderer) {
1049
1117
  /**
1050
1118
  * @internal
1051
1119
  */ _proto._getChunkManager = function _getChunkManager() {
1052
- // @ts-ignore
1053
1120
  return this.engine._batcherManager.primitiveChunkManagerUI;
1054
1121
  };
1055
1122
  /**
1056
1123
  * @internal
1057
1124
  */ _proto._raycast = function _raycast(ray, out, distance) {
1058
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1059
1125
  var plane = UIRenderer._tempPlane;
1060
1126
  var transform = this._transformEntity.transform;
1061
1127
  var normal = plane.normal.copyFrom(transform.worldForward);
@@ -1129,12 +1195,6 @@ var UIRenderer = /*#__PURE__*/ function(Renderer) {
1129
1195
  /** @internal */ UIRenderer._tempMat = new Matrix();
1130
1196
  /** @internal */ UIRenderer._tempPlane = new Plane();
1131
1197
  /** @internal */ UIRenderer._textureProperty = ShaderProperty.getByName("renderer_UITexture");
1132
- __decorate([
1133
- deepClone
1134
- ], UIRenderer.prototype, "raycastPadding", void 0);
1135
- __decorate([
1136
- ignoreClone
1137
- ], UIRenderer.prototype, "_rootCanvas", void 0);
1138
1198
  __decorate([
1139
1199
  ignoreClone
1140
1200
  ], UIRenderer.prototype, "_indexInRootCanvas", void 0);
@@ -1144,9 +1204,6 @@ __decorate([
1144
1204
  __decorate([
1145
1205
  ignoreClone
1146
1206
  ], UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
1147
- __decorate([
1148
- ignoreClone
1149
- ], UIRenderer.prototype, "_group", void 0);
1150
1207
  __decorate([
1151
1208
  ignoreClone
1152
1209
  ], UIRenderer.prototype, "_indexInGroup", void 0);
@@ -1159,12 +1216,6 @@ __decorate([
1159
1216
  __decorate([
1160
1217
  ignoreClone
1161
1218
  ], UIRenderer.prototype, "_subChunk", void 0);
1162
- __decorate([
1163
- assignmentClone
1164
- ], UIRenderer.prototype, "_raycastEnabled", void 0);
1165
- __decorate([
1166
- deepClone
1167
- ], UIRenderer.prototype, "_color", void 0);
1168
1219
  __decorate([
1169
1220
  ignoreClone
1170
1221
  ], UIRenderer.prototype, "_groupListener", null);
@@ -1263,26 +1314,6 @@ UIRenderer = __decorate([
1263
1314
  transitions[i].destroy();
1264
1315
  }
1265
1316
  };
1266
- // @ts-ignore
1267
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1268
- var transitions = this._transitions;
1269
- for(var i = 0, n = transitions.length; i < n; i++){
1270
- var srcTransition = transitions[i];
1271
- var dstTransition = new transitions[i].constructor();
1272
- dstTransition.normal = srcTransition.normal;
1273
- dstTransition.pressed = srcTransition.pressed;
1274
- dstTransition.hover = srcTransition.hover;
1275
- dstTransition.disabled = srcTransition.disabled;
1276
- var transitionTarget = srcTransition.target;
1277
- if (transitionTarget) {
1278
- var paths = UIInteractive._targetTempPath;
1279
- // @ts-ignore
1280
- var success = Entity._getEntityHierarchyPath(srcRoot, transitionTarget.entity, paths);
1281
- dstTransition.target = success ? Entity._getEntityByHierarchyPath(targetRoot, paths).getComponent(transitionTarget.constructor) : transitionTarget;
1282
- }
1283
- target.addTransition(dstTransition);
1284
- }
1285
- };
1286
1317
  /**
1287
1318
  * @internal
1288
1319
  */ _proto._getRootCanvas = function _getRootCanvas() {
@@ -1295,17 +1326,17 @@ UIRenderer = __decorate([
1295
1326
  this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1296
1327
  return this._group;
1297
1328
  };
1298
- // @ts-ignore
1299
- _proto._onEnableInScene = function _onEnableInScene() {
1300
- // @ts-ignore
1329
+ /**
1330
+ * @internal
1331
+ */ _proto._onEnableInScene = function _onEnableInScene() {
1301
1332
  Script.prototype._onEnableInScene.call(this);
1302
1333
  Utils.setRootCanvasDirty(this);
1303
1334
  Utils.setGroupDirty(this);
1304
1335
  this._updateState(true);
1305
1336
  };
1306
- // @ts-ignore
1307
- _proto._onDisableInScene = function _onDisableInScene() {
1308
- // @ts-ignore
1337
+ /**
1338
+ * @internal
1339
+ */ _proto._onDisableInScene = function _onDisableInScene() {
1309
1340
  Script.prototype._onDisableInScene.call(this);
1310
1341
  Utils.cleanRootCanvas(this);
1311
1342
  Utils.cleanGroup(this);
@@ -1393,10 +1424,6 @@ UIRenderer = __decorate([
1393
1424
  ]);
1394
1425
  return UIInteractive;
1395
1426
  }(Script);
1396
- UIInteractive._targetTempPath = new Array();
1397
- __decorate([
1398
- ignoreClone
1399
- ], UIInteractive.prototype, "_rootCanvas", void 0);
1400
1427
  __decorate([
1401
1428
  ignoreClone
1402
1429
  ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
@@ -1406,9 +1433,6 @@ __decorate([
1406
1433
  __decorate([
1407
1434
  ignoreClone
1408
1435
  ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
1409
- __decorate([
1410
- ignoreClone
1411
- ], UIInteractive.prototype, "_group", void 0);
1412
1436
  __decorate([
1413
1437
  ignoreClone
1414
1438
  ], UIInteractive.prototype, "_indexInGroup", void 0);
@@ -1424,12 +1448,6 @@ __decorate([
1424
1448
  __decorate([
1425
1449
  ignoreClone
1426
1450
  ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
1427
- __decorate([
1428
- ignoreClone
1429
- ], UIInteractive.prototype, "_transitions", void 0);
1430
- __decorate([
1431
- assignmentClone
1432
- ], UIInteractive.prototype, "_interactive", void 0);
1433
1451
  __decorate([
1434
1452
  ignoreClone
1435
1453
  ], UIInteractive.prototype, "_state", void 0);
@@ -1460,7 +1478,7 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1460
1478
  _inherits(UICanvas, Component);
1461
1479
  function UICanvas(entity) {
1462
1480
  var _this;
1463
- _this = Component.call(this, entity) || this, /** @internal */ _this._canvasIndex = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._isRootCanvas = false, /** @internal */ _this._sortDistance = 0, /** @internal */ _this._orderedRenderers = [], /** @internal */ _this._realRenderMode = 4, /** @internal */ _this._disorderedElements = new DisorderedArray(), _this._renderMode = CanvasRenderMode.WorldSpace, _this._resolutionAdaptationMode = ResolutionAdaptationMode.HeightAdaptation, _this._sortOrder = 0, _this._distance = 10, _this._referenceResolution = new Vector2(800, 600), _this._referenceResolutionPerUnit = 100, _this._hierarchyVersion = -1, _this._center = new Vector3();
1481
+ _this = Component.call(this, entity) || this, /** @internal */ _this._canvasIndex = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._isRootCanvas = false, /** @internal */ _this._renderElements = [], /** @internal */ _this._batchedRenderElements = [], /** @internal */ _this._sortDistance = 0, /** @internal */ _this._orderedRenderers = [], /** @internal */ _this._realRenderMode = 4, /** @internal */ _this._disorderedElements = new DisorderedArray(), _this._renderMode = CanvasRenderMode.WorldSpace, _this._resolutionAdaptationMode = ResolutionAdaptationMode.HeightAdaptation, _this._sortOrder = 0, _this._distance = 10, _this._referenceResolution = new Vector2(800, 600), _this._referenceResolutionPerUnit = 100, _this._hierarchyVersion = -1, _this._center = new Vector3();
1464
1482
  _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1465
1483
  _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1466
1484
  _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
@@ -1474,12 +1492,11 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1474
1492
  var _proto = UICanvas.prototype;
1475
1493
  /**
1476
1494
  * @internal
1477
- */ _proto._raycast = function _raycast(ray, out, distance) {
1478
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1495
+ */ _proto._raycast = function _raycast(ray, out, distance, cullingMask) {
1479
1496
  var renderers = this._getRenderers();
1480
1497
  for(var i = renderers.length - 1; i >= 0; i--){
1481
1498
  var element = renderers[i];
1482
- if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1499
+ if ((cullingMask & element.entity.layer) !== 0 && element.raycastEnabled && element._raycast(ray, out, distance)) {
1483
1500
  return true;
1484
1501
  }
1485
1502
  }
@@ -1503,10 +1520,12 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1503
1520
  /**
1504
1521
  * @internal
1505
1522
  */ _proto._canDispatchEvent = function _canDispatchEvent(camera) {
1506
- var realMode = this._realRenderMode;
1507
- if (realMode === CanvasRenderMode.ScreenSpaceOverlay) {
1523
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1508
1524
  return true;
1509
1525
  }
1526
+ if (!(camera.cullingMask & this.entity.layer)) {
1527
+ return false;
1528
+ }
1510
1529
  var assignedCamera = this._camera;
1511
1530
  // @ts-ignore
1512
1531
  return !assignedCamera || !assignedCamera._phasedActiveInScene || assignedCamera === camera;
@@ -1517,20 +1536,17 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1517
1536
  var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1518
1537
  var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1519
1538
  var frameCount = engine.time.frameCount;
1520
- // @ts-ignore
1521
- var renderElement = this._renderElement = engine._renderElementPool.get();
1539
+ var renderElements = this._renderElements;
1540
+ renderElements.length = 0;
1522
1541
  var virtualCamera = context.virtualCamera;
1523
1542
  this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1524
- renderElement.set(this.sortOrder, this._sortDistance);
1525
1543
  var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1526
1544
  var renderers = this._getRenderers();
1527
1545
  for(var i = 0, n = renderers.length; i < n; i++){
1528
1546
  var renderer = renderers[i];
1529
- // Filter by camera culling mask
1530
1547
  if (!(cullingMask & renderer.entity.layer)) {
1531
1548
  continue;
1532
1549
  }
1533
- // Filter by camera frustum
1534
1550
  if (enableFrustumCulling) {
1535
1551
  switch(mode){
1536
1552
  case CanvasRenderMode.ScreenSpaceOverlay:
@@ -1550,6 +1566,13 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1550
1566
  renderer._prepareRender(context);
1551
1567
  renderer._renderFrameCount = frameCount;
1552
1568
  }
1569
+ var batchedRenderElements = this._batchedRenderElements;
1570
+ batchedRenderElements.length = 0;
1571
+ UIBatchSorter.sort(renderElements, this.entity.transform.worldMatrix);
1572
+ engine._batcherManager.batch(renderElements, batchedRenderElements);
1573
+ for(var i1 = 0, n1 = batchedRenderElements.length; i1 < n1; i1++){
1574
+ batchedRenderElements[i1].subDistancePriority = i1;
1575
+ }
1553
1576
  };
1554
1577
  /**
1555
1578
  * @internal
@@ -1573,8 +1596,9 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1573
1596
  break;
1574
1597
  }
1575
1598
  };
1576
- // @ts-ignore
1577
- _proto._onEnableInScene = function _onEnableInScene() {
1599
+ /**
1600
+ * @internal
1601
+ */ _proto._onEnableInScene = function _onEnableInScene() {
1578
1602
  var entity = this.entity;
1579
1603
  // @ts-ignore
1580
1604
  entity._dispatchModify(4, this);
@@ -1582,13 +1606,20 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1582
1606
  this._setIsRootCanvas(!rootCanvas);
1583
1607
  Utils.setRootCanvas(this, rootCanvas);
1584
1608
  };
1585
- // @ts-ignore
1586
- _proto._onDisableInScene = function _onDisableInScene() {
1609
+ /**
1610
+ * @internal
1611
+ */ _proto._onDisableInScene = function _onDisableInScene() {
1587
1612
  this._setIsRootCanvas(false);
1588
1613
  Utils.cleanRootCanvas(this);
1589
1614
  };
1590
1615
  /**
1591
1616
  * @internal
1617
+ */ _proto._onDisable = function _onDisable() {
1618
+ this._renderElements.length = 0;
1619
+ this._batchedRenderElements.length = 0;
1620
+ };
1621
+ /**
1622
+ * @internal
1592
1623
  */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1593
1624
  if (this._isRootCanvas) {
1594
1625
  if (flag === EntityModifyFlags.Parent) {
@@ -1609,16 +1640,9 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1609
1640
  };
1610
1641
  /**
1611
1642
  * @internal
1612
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1643
+ * @inheritdoc
1644
+ */ _proto._onClone = function _onClone(target) {
1613
1645
  target.renderMode = this._renderMode;
1614
- var camera = this._camera;
1615
- if (camera) {
1616
- var paths = UICanvas._targetTempPath;
1617
- // @ts-ignore
1618
- var success = Entity._getEntityHierarchyPath(srcRoot, camera.entity, paths);
1619
- // @ts-ignore
1620
- target.camera = success ? Entity._getEntityByHierarchyPath(targetRoot, paths).getComponent(Camera) : camera;
1621
- }
1622
1646
  };
1623
1647
  _proto._getRenderers = function _getRenderers() {
1624
1648
  var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
@@ -1692,7 +1716,6 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1692
1716
  _proto._walk = function _walk(entity, renderers, depth, group) {
1693
1717
  if (depth === void 0) depth = 0;
1694
1718
  if (group === void 0) group = null;
1695
- // @ts-ignore
1696
1719
  var components = entity._components;
1697
1720
  var tempGroupAbleList = UICanvas._tempGroupAbleList;
1698
1721
  var groupAbleCount = 0;
@@ -1733,15 +1756,11 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1733
1756
  if (preCamera !== camera) {
1734
1757
  this._cameraObserver = camera;
1735
1758
  if (preCamera) {
1736
- // @ts-ignore
1737
1759
  preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1738
- // @ts-ignore
1739
1760
  preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1740
1761
  }
1741
1762
  if (camera) {
1742
- // @ts-ignore
1743
1763
  camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1744
- // @ts-ignore
1745
1764
  camera._registerModifyListener(this._onCameraModifyListener);
1746
1765
  }
1747
1766
  }
@@ -1771,11 +1790,9 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1771
1790
  this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1772
1791
  };
1773
1792
  _proto._addCanvasListener = function _addCanvasListener() {
1774
- // @ts-ignore
1775
1793
  this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1776
1794
  };
1777
1795
  _proto._removeCanvasListener = function _removeCanvasListener() {
1778
- // @ts-ignore
1779
1796
  this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1780
1797
  };
1781
1798
  _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
@@ -1844,7 +1861,6 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1844
1861
  var preRealMode = this._realRenderMode;
1845
1862
  if (preRealMode !== curRealMode) {
1846
1863
  this._realRenderMode = curRealMode;
1847
- // @ts-ignore
1848
1864
  var componentsManager = this.scene._componentsManager;
1849
1865
  switch(preRealMode){
1850
1866
  case CanvasRenderMode.ScreenSpaceOverlay:
@@ -1878,7 +1894,8 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1878
1894
  {
1879
1895
  key: "referenceResolutionPerUnit",
1880
1896
  get: /**
1881
- * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1897
+ * Local UI units per sprite world unit for sliced borders and tile sizing.
1898
+ * One glyph pixel maps to `referenceResolutionPerUnit / 100` local UI units.
1882
1899
  */ function get() {
1883
1900
  return this._referenceResolutionPerUnit;
1884
1901
  },
@@ -1894,7 +1911,8 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1894
1911
  {
1895
1912
  key: "referenceResolution",
1896
1913
  get: /**
1897
- * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1914
+ * Design resolution in pixels for {@link CanvasRenderMode.ScreenSpaceCamera} and {@link CanvasRenderMode.ScreenSpaceOverlay}.
1915
+ * The root canvas adapts it to the camera viewport or engine canvas using {@link UICanvas.resolutionAdaptationMode}.
1898
1916
  */ function get() {
1899
1917
  return this._referenceResolution;
1900
1918
  },
@@ -1982,15 +2000,14 @@ var UICanvas = /*#__PURE__*/ function(Component) {
1982
2000
  {
1983
2001
  key: "sortOrder",
1984
2002
  get: /**
1985
- * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
2003
+ * The rendering priority of the canvas.
1986
2004
  */ function get() {
1987
2005
  return this._sortOrder;
1988
2006
  },
1989
2007
  set: function set(value) {
1990
2008
  if (this._sortOrder !== value) {
1991
2009
  this._sortOrder = value;
1992
- this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
1993
- (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
2010
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && (this.scene._componentsManager._overlayCanvasesSortingDirty = true);
1994
2011
  }
1995
2012
  }
1996
2013
  },
@@ -2015,16 +2032,12 @@ var UICanvas = /*#__PURE__*/ function(Component) {
2015
2032
  return UICanvas;
2016
2033
  }(Component);
2017
2034
  /** @internal */ UICanvas._hierarchyCounter = 1;
2018
- UICanvas._targetTempPath = [];
2019
2035
  UICanvas._tempGroupAbleList = [];
2020
2036
  UICanvas._tempVec3 = new Vector3();
2021
2037
  UICanvas._tempMat = new Matrix();
2022
2038
  __decorate([
2023
2039
  ignoreClone
2024
2040
  ], UICanvas.prototype, "_canvasIndex", void 0);
2025
- __decorate([
2026
- ignoreClone
2027
- ], UICanvas.prototype, "_rootCanvas", void 0);
2028
2041
  __decorate([
2029
2042
  ignoreClone
2030
2043
  ], UICanvas.prototype, "_indexInRootCanvas", void 0);
@@ -2039,7 +2052,10 @@ __decorate([
2039
2052
  ], UICanvas.prototype, "_isRootCanvas", void 0);
2040
2053
  __decorate([
2041
2054
  ignoreClone
2042
- ], UICanvas.prototype, "_renderElement", void 0);
2055
+ ], UICanvas.prototype, "_renderElements", void 0);
2056
+ __decorate([
2057
+ ignoreClone
2058
+ ], UICanvas.prototype, "_batchedRenderElements", void 0);
2043
2059
  __decorate([
2044
2060
  ignoreClone
2045
2061
  ], UICanvas.prototype, "_sortDistance", void 0);
@@ -2049,42 +2065,15 @@ __decorate([
2049
2065
  __decorate([
2050
2066
  ignoreClone
2051
2067
  ], UICanvas.prototype, "_realRenderMode", void 0);
2052
- __decorate([
2053
- ignoreClone
2054
- ], UICanvas.prototype, "_disorderedElements", void 0);
2055
2068
  __decorate([
2056
2069
  ignoreClone
2057
2070
  ], UICanvas.prototype, "_renderMode", void 0);
2058
- __decorate([
2059
- ignoreClone
2060
- ], UICanvas.prototype, "_camera", void 0);
2061
- __decorate([
2062
- ignoreClone
2063
- ], UICanvas.prototype, "_cameraObserver", void 0);
2064
- __decorate([
2065
- assignmentClone
2066
- ], UICanvas.prototype, "_resolutionAdaptationMode", void 0);
2067
- __decorate([
2068
- assignmentClone
2069
- ], UICanvas.prototype, "_sortOrder", void 0);
2070
- __decorate([
2071
- assignmentClone
2072
- ], UICanvas.prototype, "_distance", void 0);
2073
- __decorate([
2074
- deepClone
2075
- ], UICanvas.prototype, "_referenceResolution", void 0);
2076
- __decorate([
2077
- assignmentClone
2078
- ], UICanvas.prototype, "_referenceResolutionPerUnit", void 0);
2079
2071
  __decorate([
2080
2072
  ignoreClone
2081
2073
  ], UICanvas.prototype, "_hierarchyVersion", void 0);
2082
2074
  __decorate([
2083
2075
  ignoreClone
2084
2076
  ], UICanvas.prototype, "_center", void 0);
2085
- __decorate([
2086
- ignoreClone
2087
- ], UICanvas.prototype, "_centerDirtyFlag", void 0);
2088
2077
  __decorate([
2089
2078
  ignoreClone
2090
2079
  ], UICanvas.prototype, "_rootCanvasListener", null);
@@ -2121,45 +2110,32 @@ var Button = /*#__PURE__*/ function(UIInteractive) {
2121
2110
  _inherits(Button, UIInteractive);
2122
2111
  function Button() {
2123
2112
  var _this;
2124
- _this = UIInteractive.apply(this, arguments) || this, _this._listeners = new SafeLoopArray();
2113
+ _this = UIInteractive.apply(this, arguments) || this, /** Signal emitted when the button is clicked. */ _this.onClick = new Signal();
2125
2114
  return _this;
2126
2115
  }
2127
2116
  var _proto = Button.prototype;
2117
+ _proto.onPointerClick = function onPointerClick(event) {
2118
+ if (!this._getGlobalInteractive()) return;
2119
+ this.onClick.invoke(event);
2120
+ };
2121
+ _proto.onDestroy = function onDestroy() {
2122
+ UIInteractive.prototype.onDestroy.call(this);
2123
+ this.onClick.removeAll();
2124
+ };
2128
2125
  /**
2129
2126
  * Add a listening function for click.
2130
- * @param listener - The listening function
2127
+ * @deprecated Use `onClick.on(listener, context)` instead.
2131
2128
  */ _proto.addClicked = function addClicked(listener) {
2132
- this._listeners.push({
2133
- fn: listener
2134
- });
2129
+ this.onClick.on(listener);
2135
2130
  };
2136
2131
  /**
2137
2132
  * Remove a listening function of click.
2138
- * @param listener - The listening function
2133
+ * @deprecated Use `onClick.off(listener, context)` instead.
2139
2134
  */ _proto.removeClicked = function removeClicked(listener) {
2140
- this._listeners.findAndRemove(function(value) {
2141
- return value.fn === listener ? value.destroyed = true : false;
2142
- });
2143
- };
2144
- _proto.onPointerClick = function onPointerClick(event) {
2145
- if (!this._getGlobalInteractive()) return;
2146
- var listeners = this._listeners.getLoopArray();
2147
- for(var i = 0, n = listeners.length; i < n; i++){
2148
- var listener = listeners[i];
2149
- !listener.destroyed && listener.fn(event);
2150
- }
2151
- };
2152
- _proto.onDestroy = function onDestroy() {
2153
- UIInteractive.prototype.onDestroy.call(this);
2154
- this._listeners.findAndRemove(function(value) {
2155
- return value.destroyed = true;
2156
- });
2135
+ this.onClick.off(listener);
2157
2136
  };
2158
2137
  return Button;
2159
2138
  }(UIInteractive);
2160
- __decorate([
2161
- ignoreClone
2162
- ], Button.prototype, "_listeners", void 0);
2163
2139
 
2164
2140
  /**
2165
2141
  * UI element that renders an image.
@@ -2169,7 +2145,6 @@ __decorate([
2169
2145
  var _this;
2170
2146
  _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5;
2171
2147
  _this.drawMode = SpriteDrawMode.Simple;
2172
- // @ts-ignore
2173
2148
  _this.setMaterial(_this._engine._getUIDefaultMaterial());
2174
2149
  _this._onSpriteChange = _this._onSpriteChange.bind(_this);
2175
2150
  return _this;
@@ -2189,9 +2164,9 @@ __decorate([
2189
2164
  };
2190
2165
  /**
2191
2166
  * @internal
2192
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
2193
- // @ts-ignore
2194
- UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
2167
+ * @inheritdoc
2168
+ */ _proto._onClone = function _onClone(target) {
2169
+ UIRenderer1.prototype._onClone.call(this, target);
2195
2170
  target.sprite = this._sprite;
2196
2171
  target.drawMode = this._drawMode;
2197
2172
  };
@@ -2221,7 +2196,6 @@ __decorate([
2221
2196
  }
2222
2197
  // @todo: This question needs to be raised rather than hidden.
2223
2198
  if (material.destroyed) {
2224
- // @ts-ignore
2225
2199
  material = this._engine._getUIDefaultMaterial();
2226
2200
  }
2227
2201
  var alpha = this._getGlobalAlpha();
@@ -2246,16 +2220,14 @@ __decorate([
2246
2220
  dirtyUpdateFlag &= ~UIRendererUpdateFlags.Color;
2247
2221
  }
2248
2222
  this._dirtyUpdateFlag = dirtyUpdateFlag;
2249
- // Init sub render element.
2250
2223
  var engine = context.camera.engine;
2251
- var subRenderElement = engine._subRenderElementPool.get();
2224
+ var renderElement = engine._renderElementPool.get();
2252
2225
  var subChunk = this._subChunk;
2253
- subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
2254
- if (canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
2255
- subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
2256
- subRenderElement.renderQueueFlags = RenderQueueFlags.All;
2257
- }
2258
- canvas._renderElement.addSubRenderElement(subRenderElement);
2226
+ renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
2227
+ renderElement.subShader = material.shader.subShaders[0];
2228
+ renderElement.priority = canvas.sortOrder;
2229
+ renderElement.distanceForSort = canvas._sortDistance;
2230
+ canvas._renderElements.push(renderElement);
2259
2231
  };
2260
2232
  _proto._onTransformChanged = function _onTransformChanged(type) {
2261
2233
  if (type & UITransformModifyFlags.Size && this._drawMode === SpriteDrawMode.Tiled) {
@@ -2267,7 +2239,6 @@ __decorate([
2267
2239
  var sprite = this._sprite;
2268
2240
  if (sprite) {
2269
2241
  this._addResourceReferCount(sprite, -1);
2270
- // @ts-ignore
2271
2242
  sprite._updateFlagManager.removeListener(this._onSpriteChange);
2272
2243
  this._sprite = null;
2273
2244
  }
@@ -2382,13 +2353,11 @@ __decorate([
2382
2353
  if (lastSprite !== value) {
2383
2354
  if (lastSprite) {
2384
2355
  this._addResourceReferCount(lastSprite, -1);
2385
- // @ts-ignore
2386
2356
  lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
2387
2357
  }
2388
2358
  this._dirtyUpdateFlag |= 7;
2389
2359
  if (value) {
2390
2360
  this._addResourceReferCount(value, 1);
2391
- // @ts-ignore
2392
2361
  value._updateFlagManager.addListener(this._onSpriteChange);
2393
2362
  this.shaderData.setTexture(UIRenderer._textureProperty, value.texture);
2394
2363
  } else {
@@ -2410,12 +2379,6 @@ __decorate([
2410
2379
  __decorate([
2411
2380
  ignoreClone
2412
2381
  ], Image.prototype, "_assembler", void 0);
2413
- __decorate([
2414
- assignmentClone
2415
- ], Image.prototype, "_tileMode", void 0);
2416
- __decorate([
2417
- assignmentClone
2418
- ], Image.prototype, "_tiledAdaptiveThreshold", void 0);
2419
2382
  __decorate([
2420
2383
  ignoreClone
2421
2384
  ], Image.prototype, "_onTransformChanged", null);
@@ -2431,10 +2394,8 @@ __decorate([
2431
2394
  var _this;
2432
2395
  _this = UIRenderer1.call(this, entity) || this, _this._textChunks = Array(), _this._subFont = null, _this._text = "", _this._localBounds = new BoundingBox(), _this._font = null, _this._fontSize = 24, _this._fontStyle = FontStyle.None, _this._lineSpacing = 0, _this._characterSpacing = 0, _this._horizontalAlignment = TextHorizontalAlignment.Center, _this._verticalAlignment = TextVerticalAlignment.Center, _this._enableWrapping = false, _this._overflowMode = OverflowMode.Overflow;
2433
2396
  var engine = _this.engine;
2434
- // @ts-ignore
2435
2397
  _this.font = engine._textDefaultFont;
2436
2398
  _this.raycastEnabled = false;
2437
- // @ts-ignore
2438
2399
  _this.setMaterial(engine._basicResources.textDefaultMaterial);
2439
2400
  return _this;
2440
2401
  }
@@ -2451,13 +2412,6 @@ __decorate([
2451
2412
  this._textChunks = null;
2452
2413
  this._subFont && (this._subFont = null);
2453
2414
  };
2454
- // @ts-ignore
2455
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
2456
- // @ts-ignore
2457
- UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
2458
- target.font = this._font;
2459
- target._subFont = this._subFont;
2460
- };
2461
2415
  /**
2462
2416
  * @internal
2463
2417
  */ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
@@ -2485,7 +2439,7 @@ __decorate([
2485
2439
  * @internal
2486
2440
  */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2487
2441
  if (flag === RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2488
- this._setDirtyFlagTrue(8);
2442
+ this._setDirtyFlagTrue(25);
2489
2443
  }
2490
2444
  };
2491
2445
  _proto._updateBounds = function _updateBounds(worldBounds) {
@@ -2507,7 +2461,7 @@ __decorate([
2507
2461
  var canvas = this._getRootCanvas();
2508
2462
  if (this._isContainDirtyFlag(8)) {
2509
2463
  this._updateLocalData();
2510
- this._setDirtyFlagTrue(8);
2464
+ this._setDirtyFlagFalse(8);
2511
2465
  }
2512
2466
  if (this._isContainDirtyFlag(16)) {
2513
2467
  this._updatePosition();
@@ -2518,29 +2472,28 @@ __decorate([
2518
2472
  this._setDirtyFlagFalse(UIRendererUpdateFlags.Color);
2519
2473
  }
2520
2474
  var engine = context.camera.engine;
2521
- var textSubRenderElementPool = engine._textSubRenderElementPool;
2475
+ var textRenderElementPool = engine._textRenderElementPool;
2522
2476
  var material = this.getMaterial();
2523
- var renderElement = canvas._renderElement;
2477
+ var renderElements = canvas._renderElements;
2478
+ var priority = canvas.sortOrder;
2479
+ var distanceForSort = canvas._sortDistance;
2524
2480
  var textChunks = this._textChunks;
2525
- var isOverlay = canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay;
2481
+ var subShader = material.shader.subShaders[0];
2526
2482
  for(var i = 0, n = textChunks.length; i < n; ++i){
2527
- var // @ts-ignore
2528
- _subRenderElement;
2483
+ var _renderElement;
2529
2484
  var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, texture = _textChunks_i.texture;
2530
- var subRenderElement = textSubRenderElementPool.get();
2531
- subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
2532
- (_subRenderElement = subRenderElement).shaderData || (_subRenderElement.shaderData = new ShaderData(ShaderDataGroup.RenderElement));
2533
- subRenderElement.shaderData.setTexture(Text._textTextureProperty, texture);
2534
- if (isOverlay) {
2535
- subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
2536
- subRenderElement.renderQueueFlags = RenderQueueFlags.All;
2537
- }
2538
- renderElement.addSubRenderElement(subRenderElement);
2485
+ var renderElement = textRenderElementPool.get();
2486
+ renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
2487
+ (_renderElement = renderElement).shaderData || (_renderElement.shaderData = new ShaderData(ShaderDataGroup.RenderElement));
2488
+ renderElement.shaderData.setTexture(Text._textTextureProperty, texture);
2489
+ renderElement.subShader = subShader;
2490
+ renderElement.priority = priority;
2491
+ renderElement.distanceForSort = distanceForSort;
2492
+ renderElements.push(renderElement);
2539
2493
  }
2540
2494
  };
2541
2495
  _proto._resetSubFont = function _resetSubFont() {
2542
2496
  var font = this._font;
2543
- // @ts-ignore
2544
2497
  this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
2545
2498
  this._subFont.nativeFontString = TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
2546
2499
  };
@@ -2596,7 +2549,6 @@ __decorate([
2596
2549
  }
2597
2550
  };
2598
2551
  _proto._updateLocalData = function _updateLocalData() {
2599
- // @ts-ignore
2600
2552
  var pixelsPerResolution = Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
2601
2553
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
2602
2554
  var charRenderInfos = Text._charRenderInfos;
@@ -2609,7 +2561,6 @@ __decorate([
2609
2561
  var characterSpacing = this._characterSpacing * this._fontSize;
2610
2562
  var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing) : TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing);
2611
2563
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
2612
- // @ts-ignore
2613
2564
  var charRenderInfoPool = this.engine._charRenderInfoPool;
2614
2565
  var linesLen = lines.length;
2615
2566
  var renderElementCount = 0;
@@ -2739,7 +2690,7 @@ __decorate([
2739
2690
  };
2740
2691
  _proto._isTextNoVisible = function _isTextNoVisible() {
2741
2692
  var size = this._transformEntity.transform.size;
2742
- return this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
2693
+ return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
2743
2694
  };
2744
2695
  _proto._buildChunk = function _buildChunk(textChunk, count) {
2745
2696
  var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
@@ -2771,7 +2722,6 @@ __decorate([
2771
2722
  };
2772
2723
  _proto._freeTextChunks = function _freeTextChunks() {
2773
2724
  var textChunks = this._textChunks;
2774
- // @ts-ignore
2775
2725
  var charRenderInfoPool = this.engine._charRenderInfoPool;
2776
2726
  var manager = this._getChunkManager();
2777
2727
  for(var i = 0, n = textChunks.length; i < n; ++i){
@@ -2823,7 +2773,9 @@ __decorate([
2823
2773
  {
2824
2774
  key: "fontSize",
2825
2775
  get: /**
2826
- * The font size of the Text.
2776
+ * Font size in pixels, used for glyph rasterization.
2777
+ * Glyph pixel dimensions are converted to local UI units using the root canvas's
2778
+ * {@link UICanvas.referenceResolutionPerUnit}.
2827
2779
  */ function get() {
2828
2780
  return this._fontSize;
2829
2781
  },
@@ -2983,39 +2935,9 @@ __decorate([
2983
2935
  __decorate([
2984
2936
  ignoreClone
2985
2937
  ], Text.prototype, "_subFont", void 0);
2986
- __decorate([
2987
- assignmentClone
2988
- ], Text.prototype, "_text", void 0);
2989
2938
  __decorate([
2990
2939
  ignoreClone
2991
2940
  ], Text.prototype, "_localBounds", void 0);
2992
- __decorate([
2993
- assignmentClone
2994
- ], Text.prototype, "_font", void 0);
2995
- __decorate([
2996
- assignmentClone
2997
- ], Text.prototype, "_fontSize", void 0);
2998
- __decorate([
2999
- assignmentClone
3000
- ], Text.prototype, "_fontStyle", void 0);
3001
- __decorate([
3002
- assignmentClone
3003
- ], Text.prototype, "_lineSpacing", void 0);
3004
- __decorate([
3005
- assignmentClone
3006
- ], Text.prototype, "_characterSpacing", void 0);
3007
- __decorate([
3008
- assignmentClone
3009
- ], Text.prototype, "_horizontalAlignment", void 0);
3010
- __decorate([
3011
- assignmentClone
3012
- ], Text.prototype, "_verticalAlignment", void 0);
3013
- __decorate([
3014
- assignmentClone
3015
- ], Text.prototype, "_enableWrapping", void 0);
3016
- __decorate([
3017
- assignmentClone
3018
- ], Text.prototype, "_overflowMode", void 0);
3019
2941
  __decorate([
3020
2942
  ignoreClone
3021
2943
  ], Text.prototype, "_onTransformChanged", null);
@@ -3025,20 +2947,30 @@ var TextChunk = function TextChunk() {
3025
2947
 
3026
2948
  /**
3027
2949
  * The transition behavior of UIInteractive.
3028
- */ var Transition = /*#__PURE__*/ function() {
2950
+ */ var Transition = /*#__PURE__*/ function(DataObject) {
2951
+ _inherits(Transition, DataObject);
3029
2952
  function Transition() {
3030
- this._duration = 0;
3031
- this._countDown = 0;
3032
- this._finalState = InteractiveState.Normal;
2953
+ var _this;
2954
+ _this = DataObject.apply(this, arguments) || this, _this._duration = 0, _this._countDown = 0, _this._finalState = InteractiveState.Normal;
2955
+ return _this;
3033
2956
  }
3034
2957
  var _proto = Transition.prototype;
3035
2958
  _proto.destroy = function destroy() {
3036
2959
  var _this__interactive;
3037
2960
  (_this__interactive = this._interactive) == null ? void 0 : _this__interactive.removeTransition(this);
2961
+ this._addStateValuesReferCount(-1);
2962
+ this._normal = this._pressed = this._hover = this._disabled = null;
2963
+ this._initialValue = this._currentValue = this._finalValue = null;
3038
2964
  this._target = null;
3039
2965
  };
3040
2966
  /**
3041
2967
  * @internal
2968
+ * @inheritdoc
2969
+ */ _proto._onClone = function _onClone(target) {
2970
+ target._addStateValuesReferCount(1);
2971
+ };
2972
+ /**
2973
+ * @internal
3042
2974
  */ _proto._setState = function _setState(state, instant) {
3043
2975
  this._finalState = state;
3044
2976
  var value = this._getValueByState(state);
@@ -3061,9 +2993,7 @@ var TextChunk = function TextChunk() {
3061
2993
  }
3062
2994
  };
3063
2995
  _proto._onStateValueDirty = function _onStateValueDirty(state, preValue, curValue) {
3064
- // @ts-ignore
3065
2996
  _instanceof(preValue, ReferResource) && preValue._addReferCount(-1);
3066
- // @ts-ignore
3067
2997
  _instanceof(curValue, ReferResource) && curValue._addReferCount(1);
3068
2998
  if (this._finalState === state) {
3069
2999
  this._finalValue = curValue;
@@ -3076,6 +3006,13 @@ var TextChunk = function TextChunk() {
3076
3006
  this._updateCurrentValue(this._initialValue, this._finalValue, weight);
3077
3007
  ((_this__target = this._target) == null ? void 0 : _this__target.enabled) && this._applyValue(this._currentValue);
3078
3008
  };
3009
+ _proto._addStateValuesReferCount = function _addStateValuesReferCount(count) {
3010
+ var _this = this, _normal = _this._normal, _pressed = _this._pressed, _hover = _this._hover, _disabled = _this._disabled;
3011
+ _instanceof(_normal, ReferResource) && _normal._addReferCount(count);
3012
+ _instanceof(_pressed, ReferResource) && _pressed._addReferCount(count);
3013
+ _instanceof(_hover, ReferResource) && _hover._addReferCount(count);
3014
+ _instanceof(_disabled, ReferResource) && _disabled._addReferCount(count);
3015
+ };
3079
3016
  _proto._getValueByState = function _getValueByState(state) {
3080
3017
  switch(state){
3081
3018
  case InteractiveState.Normal:
@@ -3184,7 +3121,22 @@ var TextChunk = function TextChunk() {
3184
3121
  }
3185
3122
  ]);
3186
3123
  return Transition;
3187
- }();
3124
+ }(DataObject);
3125
+ __decorate([
3126
+ ignoreClone
3127
+ ], Transition.prototype, "_countDown", void 0);
3128
+ __decorate([
3129
+ ignoreClone
3130
+ ], Transition.prototype, "_initialValue", void 0);
3131
+ __decorate([
3132
+ ignoreClone
3133
+ ], Transition.prototype, "_finalValue", void 0);
3134
+ __decorate([
3135
+ ignoreClone
3136
+ ], Transition.prototype, "_currentValue", void 0);
3137
+ __decorate([
3138
+ ignoreClone
3139
+ ], Transition.prototype, "_finalState", void 0);
3188
3140
 
3189
3141
  /**
3190
3142
  * Color transition.
@@ -3293,33 +3245,6 @@ var TextChunk = function TextChunk() {
3293
3245
  return Transition.apply(this, arguments) || this;
3294
3246
  }
3295
3247
  var _proto = SpriteTransition.prototype;
3296
- /**
3297
- * @internal
3298
- */ _proto.destroy = function destroy() {
3299
- Transition.prototype.destroy.call(this);
3300
- if (this._normal) {
3301
- // @ts-ignore
3302
- this._normal._addReferCount(-1);
3303
- this._normal = null;
3304
- }
3305
- if (this._hover) {
3306
- // @ts-ignore
3307
- this._hover._addReferCount(-1);
3308
- this._hover = null;
3309
- }
3310
- if (this._pressed) {
3311
- // @ts-ignore
3312
- this._pressed._addReferCount(-1);
3313
- this._pressed = null;
3314
- }
3315
- if (this._disabled) {
3316
- // @ts-ignore
3317
- this._disabled._addReferCount(-1);
3318
- this._disabled = null;
3319
- }
3320
- this._initialValue = this._currentValue = this._finalValue = null;
3321
- this._target = null;
3322
- };
3323
3248
  _proto._getTargetValueCopy = function _getTargetValueCopy() {
3324
3249
  var _this__target;
3325
3250
  return (_this__target = this._target) == null ? void 0 : _this__target.sprite;
@@ -3348,10 +3273,6 @@ var GUIComponent = /*#__PURE__*/Object.freeze({
3348
3273
  Transition: Transition
3349
3274
  });
3350
3275
 
3351
- var uiDefaultFs = "#include <common>\nuniform sampler2D renderer_UITexture;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main() {\n vec4 baseColor = texture2DSRGB(renderer_UITexture, v_uv);\n vec4 finalColor = baseColor * v_color;\n #ifdef ENGINE_SHOULD_SRGB_CORRECT\n finalColor = outputSRGBCorrection(finalColor);\n #endif\n gl_FragColor = finalColor;\n}"; // eslint-disable-line
3352
-
3353
- var uiDefaultVs = "uniform mat4 renderer_MVPMat;\n\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\nattribute vec4 COLOR_0;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main() {\n gl_Position = renderer_MVPMat * vec4(POSITION, 1.0);\n\n v_uv = TEXCOORD_0;\n v_color = COLOR_0;\n}\n"; // eslint-disable-line
3354
-
3355
3276
  /**
3356
3277
  * @internal
3357
3278
  */ var UIHitResult = function UIHitResult() {
@@ -3381,15 +3302,13 @@ var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
3381
3302
  for(var i = scenes.length - 1; i >= 0; i--){
3382
3303
  var scene = scenes[i];
3383
3304
  if (!scene.isActive || scene.destroyed) continue;
3384
- // @ts-ignore
3385
3305
  var componentsManager = scene._componentsManager;
3386
- // Overlay Canvas
3387
3306
  var canvasElements = componentsManager._overlayCanvases;
3388
- // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
3307
+ // Convert screen coordinates to overlay coordinates.
3389
3308
  ray.origin.set(position.x, scene.engine.canvas.height - position.y, 1);
3390
3309
  ray.direction.set(0, 0, -1);
3391
3310
  for(var j = canvasElements.length - 1; j >= 0; j--){
3392
- if (canvasElements.get(j)._raycast(ray, hitResult)) {
3311
+ if (canvasElements.get(j)._raycast(ray, hitResult, Number.MAX_SAFE_INTEGER, Layer.Everything)) {
3393
3312
  this._updateRaycast(hitResult.component, pointer);
3394
3313
  return;
3395
3314
  }
@@ -3403,26 +3322,22 @@ var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
3403
3322
  continue;
3404
3323
  }
3405
3324
  camera.screenPointToRay(pointer.position, ray);
3406
- // Other canvases
3407
- var isOrthographic = camera.isOrthographic;
3408
- var _camera_entity_transform = camera.entity.transform, cameraPosition = _camera_entity_transform.worldPosition, cameraForward = _camera_entity_transform.worldForward;
3409
- // Sort by rendering order
3410
3325
  canvasElements = componentsManager._canvases;
3326
+ var isOrthographic = camera.isOrthographic, farClipPlane = camera.farClipPlane, cullingMask = camera.cullingMask;
3327
+ var _camera_entity_transform = camera.entity.transform, worldPosition = _camera_entity_transform.worldPosition, worldForward = _camera_entity_transform.worldForward;
3411
3328
  for(var k = 0, n = canvasElements.length; k < n; k++){
3412
- canvasElements.get(k)._updateSortDistance(isOrthographic, cameraPosition, cameraForward);
3329
+ canvasElements.get(k)._updateSortDistance(isOrthographic, worldPosition, worldForward);
3413
3330
  }
3414
- canvasElements.sort(function(a, b) {
3415
- return a.sortOrder - b.sortOrder || a._sortDistance - b._sortDistance;
3416
- });
3331
+ canvasElements.sort(UIPointerEventEmitter._compareRaycastOrder);
3332
+ // Update registry indices after sorting.
3417
3333
  for(var k1 = 0, n1 = canvasElements.length; k1 < n1; k1++){
3418
3334
  canvasElements.get(k1)._canvasIndex = k1;
3419
3335
  }
3420
- var farClipPlane = camera.farClipPlane;
3421
- // Post-rendering first detection
3336
+ // Fully tied canvases may differ in hit and draw order.
3422
3337
  for(var k2 = 0, n2 = canvasElements.length; k2 < n2; k2++){
3423
3338
  var canvas = canvasElements.get(k2);
3424
3339
  if (!canvas._canDispatchEvent(camera)) continue;
3425
- if (canvas._raycast(ray, hitResult, farClipPlane)) {
3340
+ if (canvas._raycast(ray, hitResult, farClipPlane, cullingMask)) {
3426
3341
  this._updateRaycast(hitResult.component, pointer);
3427
3342
  return;
3428
3343
  }
@@ -3583,6 +3498,9 @@ var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
3583
3498
  fireEvent(path[i], eventData);
3584
3499
  }
3585
3500
  };
3501
+ UIPointerEventEmitter._compareRaycastOrder = function _compareRaycastOrder(a, b) {
3502
+ return b.sortOrder - a.sortOrder || a._sortDistance - b._sortDistance;
3503
+ };
3586
3504
  return UIPointerEventEmitter;
3587
3505
  }(PointerEventEmitter);
3588
3506
  UIPointerEventEmitter._MAX_PATH_DEPTH = 2048;
@@ -3594,7 +3512,9 @@ UIPointerEventEmitter = __decorate([
3594
3512
  registerPointerEventEmitter()
3595
3513
  ], UIPointerEventEmitter);
3596
3514
 
3597
- var EngineExtension = /*#__PURE__*/ function() {
3515
+ /**
3516
+ * @internal
3517
+ */ var EngineExtension = /*#__PURE__*/ function() {
3598
3518
  function EngineExtension() {}
3599
3519
  var _proto = EngineExtension.prototype;
3600
3520
  _proto._getUIDefaultMaterial = function _getUIDefaultMaterial() {
@@ -3602,17 +3522,6 @@ var EngineExtension = /*#__PURE__*/ function() {
3602
3522
  var shader = _getOrCreateUIShader();
3603
3523
  // @ts-ignore
3604
3524
  var material = new Material(this, shader);
3605
- var renderState = material.renderState;
3606
- var target = renderState.blendState.targetBlendState;
3607
- target.enabled = true;
3608
- target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
3609
- target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
3610
- target.sourceAlphaBlendFactor = BlendFactor.One;
3611
- target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
3612
- target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
3613
- renderState.depthState.writeEnabled = false;
3614
- renderState.rasterState.cullMode = CullMode.Off;
3615
- renderState.renderQueueType = RenderQueueType.Transparent;
3616
3525
  material.isGCIgnored = true;
3617
3526
  this._uiDefaultMaterial = material;
3618
3527
  }
@@ -3620,7 +3529,9 @@ var EngineExtension = /*#__PURE__*/ function() {
3620
3529
  };
3621
3530
  return EngineExtension;
3622
3531
  }();
3623
- var EntityExtension = /*#__PURE__*/ function() {
3532
+ /**
3533
+ * @internal
3534
+ */ var EntityExtension = /*#__PURE__*/ function() {
3624
3535
  function EntityExtension() {
3625
3536
  this._uiHierarchyVersion = 0;
3626
3537
  }
@@ -3648,20 +3559,6 @@ ApplyMixins(Engine, [
3648
3559
  ApplyMixins(Entity, [
3649
3560
  EntityExtension
3650
3561
  ]);
3651
- ReflectionParser.registerCustomParseComponent("Text", /*#__PURE__*/ _async_to_generator(function(instance, item) {
3652
- var props;
3653
- return __generator(this, function(_state) {
3654
- props = item.props;
3655
- if (!props.font) {
3656
- // @ts-ignore
3657
- instance.font = Font.createFromOS(instance.engine, props.fontFamily || "Arial");
3658
- }
3659
- return [
3660
- 2,
3661
- instance
3662
- ];
3663
- });
3664
- }));
3665
3562
  /**
3666
3563
  * Register GUI components for the editor.
3667
3564
  */ function registerGUI() {
@@ -3671,15 +3568,7 @@ ReflectionParser.registerCustomParseComponent("Text", /*#__PURE__*/ _async_to_ge
3671
3568
  _getOrCreateUIShader();
3672
3569
  }
3673
3570
  function _getOrCreateUIShader() {
3674
- var shader = Shader.find("ui");
3675
- if (!shader) {
3676
- shader = Shader.create("ui", [
3677
- new ShaderPass("Forward", uiDefaultVs, uiDefaultFs, {
3678
- pipelineStage: PipelineStage.Forward
3679
- })
3680
- ]);
3681
- }
3682
- return shader;
3571
+ return Shader.find("2D/UIDefault");
3683
3572
  }
3684
3573
 
3685
3574
  export { Button, CanvasRenderMode, ColorTransition, EngineExtension, EntityExtension, HorizontalAlignmentMode, Image, ResolutionAdaptationMode, ScaleTransition, SpriteTransition, Text, Transition, UICanvas, UIGroup, UIPointerEventEmitter, UIRenderer, UITransform, VerticalAlignmentMode, registerGUI };