@galacean/engine-ui 2.0.0-alpha.6 → 2.0.0-alpha.60

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/browser.js CHANGED
@@ -4,92 +4,6 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Galacean = global.Galacean || {}, global.Galacean.UI = {}), global.Galacean));
5
5
  })(this, (function (exports, engine) { 'use strict';
6
6
 
7
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
8
- try {
9
- var info = gen[key](arg);
10
- var value = info.value;
11
- } catch (error) {
12
- reject(error);
13
- return;
14
- }
15
- if (info.done) resolve(value);
16
- else Promise.resolve(value).then(_next, _throw);
17
- }
18
- function _async_to_generator(fn) {
19
- return function() {
20
- var self = this, args = arguments;
21
-
22
- return new Promise(function(resolve, reject) {
23
- var gen = fn.apply(self, args);
24
-
25
- function _next(value) {
26
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
27
- }
28
-
29
- function _throw(err) {
30
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
31
- }
32
-
33
- _next(undefined);
34
- });
35
- };
36
- }
37
-
38
- /******************************************************************************
39
- Copyright (c) Microsoft Corporation.
40
-
41
- Permission to use, copy, modify, and/or distribute this software for any
42
- purpose with or without fee is hereby granted.
43
-
44
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
45
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
46
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
47
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
48
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
49
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
50
- PERFORMANCE OF THIS SOFTWARE.
51
- ***************************************************************************** */
52
-
53
- function __decorate(decorators, target, key, desc) {
54
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
55
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
56
- 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;
57
- return c > 3 && r && Object.defineProperty(target, key, r), r;
58
- }
59
-
60
- function __generator(thisArg, body) {
61
- 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);
62
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
- function verb(n) { return function (v) { return step([n, v]); }; }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
- 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;
68
- if (y = 0, t) op = [op[0] & 2, t.value];
69
- switch (op[0]) {
70
- case 0: case 1: t = op; break;
71
- case 4: _.label++; return { value: op[1], done: false };
72
- case 5: _.label++; y = op[1]; op = [0]; continue;
73
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
- default:
75
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
- if (t[2]) _.ops.pop();
80
- _.trys.pop(); continue;
81
- }
82
- op = body.call(thisArg, _);
83
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
- }
86
- }
87
-
88
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
89
- var e = new Error(message);
90
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
91
- };
92
-
93
7
  function _defineProperties(target, props) {
94
8
  for (var i = 0; i < props.length; i++) {
95
9
  var descriptor = props[i];
@@ -134,6 +48,33 @@
134
48
  } else return left instanceof right;
135
49
  }
136
50
 
51
+ /******************************************************************************
52
+ Copyright (c) Microsoft Corporation.
53
+
54
+ Permission to use, copy, modify, and/or distribute this software for any
55
+ purpose with or without fee is hereby granted.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
58
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
59
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
60
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
61
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
62
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
63
+ PERFORMANCE OF THIS SOFTWARE.
64
+ ***************************************************************************** */
65
+
66
+ function __decorate(decorators, target, key, desc) {
67
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
68
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
69
+ 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;
70
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
71
+ }
72
+
73
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
74
+ var e = new Error(message);
75
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
76
+ };
77
+
137
78
  var UIGroup = /*#__PURE__*/ function(Component) {
138
79
  _inherits(UIGroup, Component);
139
80
  function UIGroup(entity) {
@@ -172,15 +113,17 @@
172
113
  }
173
114
  return this._globalInteractive;
174
115
  };
175
- // @ts-ignore
176
- _proto._onEnableInScene = function _onEnableInScene() {
116
+ /**
117
+ * @internal
118
+ */ _proto._onEnableInScene = function _onEnableInScene() {
177
119
  Utils.setRootCanvasDirty(this);
178
120
  Utils.setGroupDirty(this);
179
121
  // @ts-ignore
180
122
  this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
181
123
  };
182
- // @ts-ignore
183
- _proto._onDisableInScene = function _onDisableInScene() {
124
+ /**
125
+ * @internal
126
+ */ _proto._onDisableInScene = function _onDisableInScene() {
184
127
  Utils.cleanRootCanvas(this);
185
128
  Utils.cleanGroup(this);
186
129
  var disorderedElements = this._disorderedElements;
@@ -296,30 +239,12 @@
296
239
  __decorate([
297
240
  engine.ignoreClone
298
241
  ], UIGroup.prototype, "_indexInRootCanvas", void 0);
299
- __decorate([
300
- engine.ignoreClone
301
- ], UIGroup.prototype, "_group", void 0);
302
- __decorate([
303
- engine.ignoreClone
304
- ], UIGroup.prototype, "_rootCanvas", void 0);
305
- __decorate([
306
- engine.ignoreClone
307
- ], UIGroup.prototype, "_disorderedElements", void 0);
308
242
  __decorate([
309
243
  engine.ignoreClone
310
244
  ], UIGroup.prototype, "_globalAlpha", void 0);
311
245
  __decorate([
312
246
  engine.ignoreClone
313
247
  ], UIGroup.prototype, "_globalInteractive", void 0);
314
- __decorate([
315
- engine.assignmentClone
316
- ], UIGroup.prototype, "_alpha", void 0);
317
- __decorate([
318
- engine.assignmentClone
319
- ], UIGroup.prototype, "_interactive", void 0);
320
- __decorate([
321
- engine.assignmentClone
322
- ], UIGroup.prototype, "_ignoreParentGroup", void 0);
323
248
  __decorate([
324
249
  engine.ignoreClone
325
250
  ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
@@ -372,7 +297,6 @@
372
297
  Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
373
298
  var entity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
374
299
  while(entity){
375
- // @ts-ignore
376
300
  var components = entity._components;
377
301
  for(var i = 0, n = components.length; i < n; i++){
378
302
  var component = components[i];
@@ -413,7 +337,6 @@
413
337
  var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
414
338
  var rootCanvasParent = rootCanvas.entity.parent;
415
339
  while(entity && entity !== rootCanvasParent){
416
- // @ts-ignore
417
340
  var components = entity._components;
418
341
  for(var i = 0, n = components.length; i < n; i++){
419
342
  var component = components[i];
@@ -463,10 +386,8 @@
463
386
  while(entity && entity !== root){
464
387
  var preEntity = listeningEntities[count];
465
388
  if (preEntity !== entity) {
466
- // @ts-ignore
467
389
  preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
468
390
  listeningEntities[count] = entity;
469
- // @ts-ignore
470
391
  entity._registerModifyListener(listener);
471
392
  }
472
393
  entity = entity.parent;
@@ -476,7 +397,6 @@
476
397
  };
477
398
  Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
478
399
  for(var i = 0, n = listeningEntities.length; i < n; i++){
479
- // @ts-ignore
480
400
  listeningEntities[i]._unRegisterModifyListener(listener);
481
401
  }
482
402
  listeningEntities.length = 0;
@@ -484,6 +404,154 @@
484
404
  return Utils;
485
405
  }();
486
406
 
407
+ /**
408
+ * @internal
409
+ * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
410
+ *
411
+ * Think of it as stacking elements onto numbered shelves (depths):
412
+ * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
413
+ * - Overlapping + batch-compatible — share the same shelf, still cluster.
414
+ * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
415
+ *
416
+ * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
417
+ * share the same depth and get clustered together. Once depth is assigned, sort by
418
+ * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
419
+ * by-product of materials clustering within each depth band.
420
+ *
421
+ * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
422
+ * are derived from the union AABB of input elements (the bounds transform itself is the
423
+ * work the loop must do anyway, so the union accumulation just piggybacks). This stays
424
+ * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
425
+ * on canvas configuration.
426
+ */ var UIBatchSorter = /*#__PURE__*/ function() {
427
+ function UIBatchSorter() {}
428
+ /**
429
+ * Reorders `elements` in place for optimal batching.
430
+ * @param elements - in hierarchy order (depth-first traversal); mutated in place
431
+ * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
432
+ */ UIBatchSorter.sort = function sort(elements, canvasWorldMatrix) {
433
+ var count = elements.length;
434
+ if (count <= 1) return;
435
+ var gridDim = this._gridDim;
436
+ var entries = this._entries;
437
+ var grid = this._grid;
438
+ var dirtyCells = this._dirtyCells;
439
+ var localBoundsPool = this._localBoundsPool;
440
+ var worldToLocal = this._worldToLocal;
441
+ engine.Matrix.invert(canvasWorldMatrix, worldToLocal);
442
+ while(entries.length < count)entries.push(new SortEntry());
443
+ // Allocate grid once, reuse forever (each cell must be a real [], not a sparse hole)
444
+ if (grid.length < gridDim) {
445
+ while(grid.length < gridDim)grid.push([]);
446
+ for(var i = 0; i < gridDim; i++){
447
+ var row = grid[i];
448
+ while(row.length < gridDim)row.push([]);
449
+ }
450
+ }
451
+ // Clear only previously-used cells (no full sweep)
452
+ for(var k = 0, n = dirtyCells.length; k < n; k += 2){
453
+ grid[dirtyCells[k]][dirtyCells[k + 1]].length = 0;
454
+ }
455
+ dirtyCells.length = 0;
456
+ // Pass 1: transform world bounds to canvas-local + accumulate the union AABB.
457
+ // Transform is already required to do precise overlap, so the union accumulation
458
+ // is essentially free — just a few minmax compares riding on the existing pass
459
+ var unionMinX = Infinity;
460
+ var unionMinY = Infinity;
461
+ var unionMaxX = -Infinity;
462
+ var unionMaxY = -Infinity;
463
+ for(var i1 = 0; i1 < count; i1++){
464
+ var _localBoundsPool, _i;
465
+ var localBounds = (_localBoundsPool = localBoundsPool)[_i = i1] || (_localBoundsPool[_i] = new engine.BoundingBox());
466
+ engine.BoundingBox.transform(elements[i1].component.bounds, worldToLocal, localBounds);
467
+ var min = localBounds.min, max = localBounds.max;
468
+ if (min.x < unionMinX) unionMinX = min.x;
469
+ if (min.y < unionMinY) unionMinY = min.y;
470
+ if (max.x > unionMaxX) unionMaxX = max.x;
471
+ if (max.y > unionMaxY) unionMaxY = max.y;
472
+ }
473
+ // Guard against a degenerate union (all elements collapsed onto a single point /
474
+ // axis); the grid then collapses to cell 0 which is semantically correct
475
+ var cellSizeX = Math.max(1e-6, unionMaxX - unionMinX) / gridDim;
476
+ var cellSizeY = Math.max(1e-6, unionMaxY - unionMinY) / gridDim;
477
+ var maxCell = gridDim - 1;
478
+ // Pass 2: register each element into grid cells and compute its depth
479
+ for(var i2 = 0; i2 < count; i2++){
480
+ var element = elements[i2];
481
+ var localBounds1 = localBoundsPool[i2];
482
+ var materialId = element.material.instanceId;
483
+ var textureId = element.texture ? element.texture.instanceId : 0;
484
+ // Floor + clamp guards floating-point edge cases (a `max` exactly on the union
485
+ // boundary would otherwise produce `gridDim`)
486
+ var minCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.x - unionMinX) / cellSizeX)));
487
+ var maxCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.x - unionMinX) / cellSizeX)));
488
+ var minCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.y - unionMinY) / cellSizeY)));
489
+ var maxCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.y - unionMinY) / cellSizeY)));
490
+ // Find the deepest overlapping prior, and whether that shelf has any incompatible occupant
491
+ var maxDepth = -1;
492
+ var maxDepthIncompatible = false;
493
+ for(var cellY = minCellY; cellY <= maxCellY; cellY++){
494
+ for(var cellX = minCellX; cellX <= maxCellX; cellX++){
495
+ var cell = grid[cellX][cellY];
496
+ for(var j = 0, m = cell.length; j < m; j++){
497
+ var other = cell[j];
498
+ if (!UIBatchSorter._rectOverlap(localBounds1, other.bounds)) continue;
499
+ var otherDepth = other.depth;
500
+ var otherIncompatible = other.materialId !== materialId || other.textureId !== textureId;
501
+ if (otherDepth > maxDepth) {
502
+ maxDepth = otherDepth;
503
+ maxDepthIncompatible = otherIncompatible;
504
+ } else if (otherDepth === maxDepth && otherIncompatible) {
505
+ maxDepthIncompatible = true;
506
+ }
507
+ }
508
+ }
509
+ }
510
+ var entry = entries[i2];
511
+ entry.element = element;
512
+ entry.hierarchyIndex = i2;
513
+ // Share the deepest shelf if compatible; bump up one if blocked by an incompatible occupant
514
+ entry.depth = maxDepth < 0 ? 0 : maxDepth + (maxDepthIncompatible ? 1 : 0);
515
+ entry.materialId = materialId;
516
+ entry.textureId = textureId;
517
+ entry.bounds = localBounds1;
518
+ for(var cellY1 = minCellY; cellY1 <= maxCellY; cellY1++){
519
+ for(var cellX1 = minCellX; cellX1 <= maxCellX; cellX1++){
520
+ var cell1 = grid[cellX1][cellY1];
521
+ if (cell1.length === 0) dirtyCells.push(cellX1, cellY1);
522
+ cell1.push(entry);
523
+ }
524
+ }
525
+ }
526
+ engine.Utils._quickSort(entries, 0, count, UIBatchSorter._compareEntries);
527
+ for(var i3 = 0; i3 < count; i3++)elements[i3] = entries[i3].element;
528
+ };
529
+ UIBatchSorter._rectOverlap = function _rectOverlap(a, b) {
530
+ 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;
531
+ };
532
+ UIBatchSorter._compareEntries = function _compareEntries(a, b) {
533
+ return a.depth - b.depth || a.materialId - b.materialId || a.textureId - b.textureId || a.hierarchyIndex - b.hierarchyIndex;
534
+ };
535
+ return UIBatchSorter;
536
+ }();
537
+ // Spatial-hash is fastest when cell size ≈ typical element size (one element per cell).
538
+ // UI elements typically span ~10% of the canvas → 10×10 grid.
539
+ UIBatchSorter._gridDim = 10;
540
+ UIBatchSorter._entries = new Array();
541
+ UIBatchSorter._grid = [];
542
+ // Interleaved (x, y) cell coords touched in the previous frame
543
+ UIBatchSorter._dirtyCells = new Array();
544
+ UIBatchSorter._localBoundsPool = new Array();
545
+ UIBatchSorter._worldToLocal = new engine.Matrix();
546
+ // materialId/textureId/bounds are flattened from RenderElement to avoid
547
+ // multi-hop property access in the hot inner loop and the sort comparator.
548
+ var SortEntry = function SortEntry() {
549
+ this.hierarchyIndex = 0;
550
+ this.depth = 0;
551
+ this.materialId = 0;
552
+ this.textureId = 0;
553
+ };
554
+
487
555
  /**
488
556
  * Render mode for ui canvas.
489
557
  */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
@@ -505,14 +573,16 @@
505
573
  }({});
506
574
 
507
575
  /**
508
- * Resolution adaptation mode.
509
- * @remarks Only effective in screen space.
576
+ * Resolution adaptation in screen space.
577
+ * Scale ratios are available size / `referenceResolution` per axis.
578
+ * Available size comes from the canvas in Overlay mode or the camera's standard projection at `distance`
579
+ * in Camera mode; a custom `Camera.projectionMatrix` is not reflected.
510
580
  */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
511
581
  /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
512
582
  /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
513
583
  /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
514
- /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
515
- /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
584
+ /** Use the smaller scale ratio to fit the reference rectangle; the UICanvas expands on the other axis. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
585
+ /** Use the larger scale ratio to cover the available area; the reference rectangle may overflow. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
516
586
  return ResolutionAdaptationMode;
517
587
  }({});
518
588
 
@@ -556,10 +626,11 @@
556
626
  this._isParentDirty = true;
557
627
  this._updateWorldFlagWithParentRectChange(engine.TransformModifyFlags.WmWpWeWqWsWus);
558
628
  };
559
- // @ts-ignore
560
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
561
- // @ts-ignore
562
- Transform.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
629
+ /**
630
+ * @internal
631
+ * @inheritdoc
632
+ */ _proto._onClone = function _onClone(target) {
633
+ Transform.prototype._onClone.call(this, target);
563
634
  var size = target._size, pivot = target._pivot;
564
635
  // @ts-ignore
565
636
  size._onValueChanged = pivot._onValueChanged = null;
@@ -661,13 +732,11 @@
661
732
  }
662
733
  this._updateRectBySizeAndPivot();
663
734
  this._updateWorldFlagWithSelfRectChange();
664
- // @ts-ignore
665
735
  this._entity._updateFlagManager.dispatch(512);
666
736
  };
667
737
  _proto._onPivotChanged = function _onPivotChanged() {
668
738
  this._updateRectBySizeAndPivot();
669
739
  this._updateWorldFlagWithSelfRectChange();
670
- // @ts-ignore
671
740
  this._entity._updateFlagManager.dispatch(1024);
672
741
  };
673
742
  _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
@@ -709,14 +778,14 @@
709
778
  (_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);
710
779
  }
711
780
  }
712
- // @ts-ignore
713
781
  selfChange && this._entity._updateFlagManager.dispatch(512);
714
782
  };
715
783
  _create_class(UITransform, [
716
784
  {
717
785
  key: "size",
718
786
  get: /**
719
- * Width and height of UI element.
787
+ * Width and height in local units, before transform scaling.
788
+ * Screen-space units are pixels at the root canvas's {@link UICanvas.referenceResolution}; world-space units are scene units.
720
789
  */ function get() {
721
790
  return this._size;
722
791
  },
@@ -920,9 +989,6 @@
920
989
  __decorate([
921
990
  engine.ignoreClone
922
991
  ], UITransform.prototype, "_pivot", void 0);
923
- __decorate([
924
- engine.deepClone
925
- ], UITransform.prototype, "_rect", void 0);
926
992
  __decorate([
927
993
  engine.ignoreClone
928
994
  ], UITransform.prototype, "_onPositionChanged", null);
@@ -961,42 +1027,44 @@
961
1027
  return _this;
962
1028
  }
963
1029
  var _proto = UIRenderer.prototype;
964
- // @ts-ignore
965
- _proto._canBatch = function _canBatch(elementA, elementB) {
966
- return engine.BatchUtils.canBatchSprite(elementA, elementB);
1030
+ /**
1031
+ * @internal
1032
+ */ _proto._canBatch = function _canBatch(preElement, curElement) {
1033
+ return engine.VertexMergeBatcher.canBatchSprite(preElement, curElement);
967
1034
  };
968
- // @ts-ignore
969
- _proto._batch = function _batch(elementA, elementB) {
970
- engine.BatchUtils.batchFor2D(elementA, elementB);
1035
+ /**
1036
+ * @internal
1037
+ */ _proto._batch = function _batch(preElement, curElement) {
1038
+ engine.VertexMergeBatcher.batch(preElement, curElement);
971
1039
  };
972
- // @ts-ignore
973
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
1040
+ /**
1041
+ * @internal
1042
+ */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP) {
974
1043
  // @ts-ignore
975
- Renderer.prototype._updateTransformShaderData.call(this, context, onlyMVP, true);
1044
+ this._updateWorldSpaceTransformShaderData(context, onlyMVP);
976
1045
  };
977
- // @ts-ignore
978
- _proto._prepareRender = function _prepareRender(context) {
1046
+ /**
1047
+ * @internal
1048
+ */ _proto._prepareRender = function _prepareRender(context) {
979
1049
  // Update once per frame per renderer, not influenced by batched
980
1050
  if (this._renderFrameCount !== this.engine.time.frameCount) {
981
1051
  this._update(context);
982
1052
  }
983
1053
  this._render(context);
984
1054
  // union camera global macro and renderer macro.
985
- engine.ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
986
- this.shaderData._macroCollection, //@ts-ignore
987
- this._globalShaderMacro);
1055
+ engine.ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, this.shaderData._macroCollection, this._globalShaderMacro);
988
1056
  };
989
- // @ts-ignore
990
- _proto._onEnableInScene = function _onEnableInScene() {
991
- // @ts-ignore
1057
+ /**
1058
+ * @internal
1059
+ */ _proto._onEnableInScene = function _onEnableInScene() {
992
1060
  this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
993
1061
  this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
994
1062
  Utils.setRootCanvasDirty(this);
995
1063
  Utils.setGroupDirty(this);
996
1064
  };
997
- // @ts-ignore
998
- _proto._onDisableInScene = function _onDisableInScene() {
999
- // @ts-ignore
1065
+ /**
1066
+ * @internal
1067
+ */ _proto._onDisableInScene = function _onDisableInScene() {
1000
1068
  this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
1001
1069
  this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
1002
1070
  Utils.cleanRootCanvas(this);
@@ -1053,13 +1121,11 @@
1053
1121
  /**
1054
1122
  * @internal
1055
1123
  */ _proto._getChunkManager = function _getChunkManager() {
1056
- // @ts-ignore
1057
1124
  return this.engine._batcherManager.primitiveChunkManagerUI;
1058
1125
  };
1059
1126
  /**
1060
1127
  * @internal
1061
1128
  */ _proto._raycast = function _raycast(ray, out, distance) {
1062
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1063
1129
  var plane = UIRenderer._tempPlane;
1064
1130
  var transform = this._transformEntity.transform;
1065
1131
  var normal = plane.normal.copyFrom(transform.worldForward);
@@ -1133,12 +1199,6 @@
1133
1199
  /** @internal */ exports.UIRenderer._tempMat = new engine.Matrix();
1134
1200
  /** @internal */ exports.UIRenderer._tempPlane = new engine.Plane();
1135
1201
  /** @internal */ exports.UIRenderer._textureProperty = engine.ShaderProperty.getByName("renderer_UITexture");
1136
- __decorate([
1137
- engine.deepClone
1138
- ], exports.UIRenderer.prototype, "raycastPadding", void 0);
1139
- __decorate([
1140
- engine.ignoreClone
1141
- ], exports.UIRenderer.prototype, "_rootCanvas", void 0);
1142
1202
  __decorate([
1143
1203
  engine.ignoreClone
1144
1204
  ], exports.UIRenderer.prototype, "_indexInRootCanvas", void 0);
@@ -1148,9 +1208,6 @@
1148
1208
  __decorate([
1149
1209
  engine.ignoreClone
1150
1210
  ], exports.UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
1151
- __decorate([
1152
- engine.ignoreClone
1153
- ], exports.UIRenderer.prototype, "_group", void 0);
1154
1211
  __decorate([
1155
1212
  engine.ignoreClone
1156
1213
  ], exports.UIRenderer.prototype, "_indexInGroup", void 0);
@@ -1163,12 +1220,6 @@
1163
1220
  __decorate([
1164
1221
  engine.ignoreClone
1165
1222
  ], exports.UIRenderer.prototype, "_subChunk", void 0);
1166
- __decorate([
1167
- engine.assignmentClone
1168
- ], exports.UIRenderer.prototype, "_raycastEnabled", void 0);
1169
- __decorate([
1170
- engine.deepClone
1171
- ], exports.UIRenderer.prototype, "_color", void 0);
1172
1223
  __decorate([
1173
1224
  engine.ignoreClone
1174
1225
  ], exports.UIRenderer.prototype, "_groupListener", null);
@@ -1267,26 +1318,6 @@
1267
1318
  transitions[i].destroy();
1268
1319
  }
1269
1320
  };
1270
- // @ts-ignore
1271
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1272
- var transitions = this._transitions;
1273
- for(var i = 0, n = transitions.length; i < n; i++){
1274
- var srcTransition = transitions[i];
1275
- var dstTransition = new transitions[i].constructor();
1276
- dstTransition.normal = srcTransition.normal;
1277
- dstTransition.pressed = srcTransition.pressed;
1278
- dstTransition.hover = srcTransition.hover;
1279
- dstTransition.disabled = srcTransition.disabled;
1280
- var transitionTarget = srcTransition.target;
1281
- if (transitionTarget) {
1282
- var paths = UIInteractive._targetTempPath;
1283
- // @ts-ignore
1284
- var success = engine.Entity._getEntityHierarchyPath(srcRoot, transitionTarget.entity, paths);
1285
- dstTransition.target = success ? engine.Entity._getEntityByHierarchyPath(targetRoot, paths).getComponent(transitionTarget.constructor) : transitionTarget;
1286
- }
1287
- target.addTransition(dstTransition);
1288
- }
1289
- };
1290
1321
  /**
1291
1322
  * @internal
1292
1323
  */ _proto._getRootCanvas = function _getRootCanvas() {
@@ -1299,17 +1330,17 @@
1299
1330
  this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1300
1331
  return this._group;
1301
1332
  };
1302
- // @ts-ignore
1303
- _proto._onEnableInScene = function _onEnableInScene() {
1304
- // @ts-ignore
1333
+ /**
1334
+ * @internal
1335
+ */ _proto._onEnableInScene = function _onEnableInScene() {
1305
1336
  Script.prototype._onEnableInScene.call(this);
1306
1337
  Utils.setRootCanvasDirty(this);
1307
1338
  Utils.setGroupDirty(this);
1308
1339
  this._updateState(true);
1309
1340
  };
1310
- // @ts-ignore
1311
- _proto._onDisableInScene = function _onDisableInScene() {
1312
- // @ts-ignore
1341
+ /**
1342
+ * @internal
1343
+ */ _proto._onDisableInScene = function _onDisableInScene() {
1313
1344
  Script.prototype._onDisableInScene.call(this);
1314
1345
  Utils.cleanRootCanvas(this);
1315
1346
  Utils.cleanGroup(this);
@@ -1397,10 +1428,6 @@
1397
1428
  ]);
1398
1429
  return UIInteractive;
1399
1430
  }(engine.Script);
1400
- UIInteractive._targetTempPath = new Array();
1401
- __decorate([
1402
- engine.ignoreClone
1403
- ], UIInteractive.prototype, "_rootCanvas", void 0);
1404
1431
  __decorate([
1405
1432
  engine.ignoreClone
1406
1433
  ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
@@ -1410,9 +1437,6 @@
1410
1437
  __decorate([
1411
1438
  engine.ignoreClone
1412
1439
  ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
1413
- __decorate([
1414
- engine.ignoreClone
1415
- ], UIInteractive.prototype, "_group", void 0);
1416
1440
  __decorate([
1417
1441
  engine.ignoreClone
1418
1442
  ], UIInteractive.prototype, "_indexInGroup", void 0);
@@ -1428,12 +1452,6 @@
1428
1452
  __decorate([
1429
1453
  engine.ignoreClone
1430
1454
  ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
1431
- __decorate([
1432
- engine.ignoreClone
1433
- ], UIInteractive.prototype, "_transitions", void 0);
1434
- __decorate([
1435
- engine.assignmentClone
1436
- ], UIInteractive.prototype, "_interactive", void 0);
1437
1455
  __decorate([
1438
1456
  engine.ignoreClone
1439
1457
  ], UIInteractive.prototype, "_state", void 0);
@@ -1464,7 +1482,7 @@
1464
1482
  _inherits(UICanvas, Component);
1465
1483
  function UICanvas(entity) {
1466
1484
  var _this;
1467
- _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 engine.DisorderedArray(), _this._renderMode = CanvasRenderMode.WorldSpace, _this._resolutionAdaptationMode = ResolutionAdaptationMode.HeightAdaptation, _this._sortOrder = 0, _this._distance = 10, _this._referenceResolution = new engine.Vector2(800, 600), _this._referenceResolutionPerUnit = 100, _this._hierarchyVersion = -1, _this._center = new engine.Vector3();
1485
+ _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 engine.DisorderedArray(), _this._renderMode = CanvasRenderMode.WorldSpace, _this._resolutionAdaptationMode = ResolutionAdaptationMode.HeightAdaptation, _this._sortOrder = 0, _this._distance = 10, _this._referenceResolution = new engine.Vector2(800, 600), _this._referenceResolutionPerUnit = 100, _this._hierarchyVersion = -1, _this._center = new engine.Vector3();
1468
1486
  _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1469
1487
  _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1470
1488
  _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
@@ -1478,12 +1496,11 @@
1478
1496
  var _proto = UICanvas.prototype;
1479
1497
  /**
1480
1498
  * @internal
1481
- */ _proto._raycast = function _raycast(ray, out, distance) {
1482
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1499
+ */ _proto._raycast = function _raycast(ray, out, distance, cullingMask) {
1483
1500
  var renderers = this._getRenderers();
1484
1501
  for(var i = renderers.length - 1; i >= 0; i--){
1485
1502
  var element = renderers[i];
1486
- if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1503
+ if ((cullingMask & element.entity.layer) !== 0 && element.raycastEnabled && element._raycast(ray, out, distance)) {
1487
1504
  return true;
1488
1505
  }
1489
1506
  }
@@ -1507,10 +1524,12 @@
1507
1524
  /**
1508
1525
  * @internal
1509
1526
  */ _proto._canDispatchEvent = function _canDispatchEvent(camera) {
1510
- var realMode = this._realRenderMode;
1511
- if (realMode === CanvasRenderMode.ScreenSpaceOverlay) {
1527
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1512
1528
  return true;
1513
1529
  }
1530
+ if (!(camera.cullingMask & this.entity.layer)) {
1531
+ return false;
1532
+ }
1514
1533
  var assignedCamera = this._camera;
1515
1534
  // @ts-ignore
1516
1535
  return !assignedCamera || !assignedCamera._phasedActiveInScene || assignedCamera === camera;
@@ -1521,20 +1540,17 @@
1521
1540
  var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1522
1541
  var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1523
1542
  var frameCount = engine.time.frameCount;
1524
- // @ts-ignore
1525
- var renderElement = this._renderElement = engine._renderElementPool.get();
1543
+ var renderElements = this._renderElements;
1544
+ renderElements.length = 0;
1526
1545
  var virtualCamera = context.virtualCamera;
1527
1546
  this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1528
- renderElement.set(this.sortOrder, this._sortDistance);
1529
1547
  var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1530
1548
  var renderers = this._getRenderers();
1531
1549
  for(var i = 0, n = renderers.length; i < n; i++){
1532
1550
  var renderer = renderers[i];
1533
- // Filter by camera culling mask
1534
1551
  if (!(cullingMask & renderer.entity.layer)) {
1535
1552
  continue;
1536
1553
  }
1537
- // Filter by camera frustum
1538
1554
  if (enableFrustumCulling) {
1539
1555
  switch(mode){
1540
1556
  case CanvasRenderMode.ScreenSpaceOverlay:
@@ -1554,6 +1570,13 @@
1554
1570
  renderer._prepareRender(context);
1555
1571
  renderer._renderFrameCount = frameCount;
1556
1572
  }
1573
+ var batchedRenderElements = this._batchedRenderElements;
1574
+ batchedRenderElements.length = 0;
1575
+ UIBatchSorter.sort(renderElements, this.entity.transform.worldMatrix);
1576
+ engine._batcherManager.batch(renderElements, batchedRenderElements);
1577
+ for(var i1 = 0, n1 = batchedRenderElements.length; i1 < n1; i1++){
1578
+ batchedRenderElements[i1].subDistancePriority = i1;
1579
+ }
1557
1580
  };
1558
1581
  /**
1559
1582
  * @internal
@@ -1577,8 +1600,9 @@
1577
1600
  break;
1578
1601
  }
1579
1602
  };
1580
- // @ts-ignore
1581
- _proto._onEnableInScene = function _onEnableInScene() {
1603
+ /**
1604
+ * @internal
1605
+ */ _proto._onEnableInScene = function _onEnableInScene() {
1582
1606
  var entity = this.entity;
1583
1607
  // @ts-ignore
1584
1608
  entity._dispatchModify(4, this);
@@ -1586,13 +1610,20 @@
1586
1610
  this._setIsRootCanvas(!rootCanvas);
1587
1611
  Utils.setRootCanvas(this, rootCanvas);
1588
1612
  };
1589
- // @ts-ignore
1590
- _proto._onDisableInScene = function _onDisableInScene() {
1613
+ /**
1614
+ * @internal
1615
+ */ _proto._onDisableInScene = function _onDisableInScene() {
1591
1616
  this._setIsRootCanvas(false);
1592
1617
  Utils.cleanRootCanvas(this);
1593
1618
  };
1594
1619
  /**
1595
1620
  * @internal
1621
+ */ _proto._onDisable = function _onDisable() {
1622
+ this._renderElements.length = 0;
1623
+ this._batchedRenderElements.length = 0;
1624
+ };
1625
+ /**
1626
+ * @internal
1596
1627
  */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1597
1628
  if (this._isRootCanvas) {
1598
1629
  if (flag === engine.EntityModifyFlags.Parent) {
@@ -1613,16 +1644,9 @@
1613
1644
  };
1614
1645
  /**
1615
1646
  * @internal
1616
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1647
+ * @inheritdoc
1648
+ */ _proto._onClone = function _onClone(target) {
1617
1649
  target.renderMode = this._renderMode;
1618
- var camera = this._camera;
1619
- if (camera) {
1620
- var paths = UICanvas._targetTempPath;
1621
- // @ts-ignore
1622
- var success = engine.Entity._getEntityHierarchyPath(srcRoot, camera.entity, paths);
1623
- // @ts-ignore
1624
- target.camera = success ? engine.Entity._getEntityByHierarchyPath(targetRoot, paths).getComponent(engine.Camera) : camera;
1625
- }
1626
1650
  };
1627
1651
  _proto._getRenderers = function _getRenderers() {
1628
1652
  var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
@@ -1696,7 +1720,6 @@
1696
1720
  _proto._walk = function _walk(entity, renderers, depth, group) {
1697
1721
  if (depth === void 0) depth = 0;
1698
1722
  if (group === void 0) group = null;
1699
- // @ts-ignore
1700
1723
  var components = entity._components;
1701
1724
  var tempGroupAbleList = UICanvas._tempGroupAbleList;
1702
1725
  var groupAbleCount = 0;
@@ -1737,15 +1760,11 @@
1737
1760
  if (preCamera !== camera) {
1738
1761
  this._cameraObserver = camera;
1739
1762
  if (preCamera) {
1740
- // @ts-ignore
1741
1763
  preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1742
- // @ts-ignore
1743
1764
  preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1744
1765
  }
1745
1766
  if (camera) {
1746
- // @ts-ignore
1747
1767
  camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1748
- // @ts-ignore
1749
1768
  camera._registerModifyListener(this._onCameraModifyListener);
1750
1769
  }
1751
1770
  }
@@ -1775,11 +1794,9 @@
1775
1794
  this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1776
1795
  };
1777
1796
  _proto._addCanvasListener = function _addCanvasListener() {
1778
- // @ts-ignore
1779
1797
  this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1780
1798
  };
1781
1799
  _proto._removeCanvasListener = function _removeCanvasListener() {
1782
- // @ts-ignore
1783
1800
  this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1784
1801
  };
1785
1802
  _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
@@ -1848,7 +1865,6 @@
1848
1865
  var preRealMode = this._realRenderMode;
1849
1866
  if (preRealMode !== curRealMode) {
1850
1867
  this._realRenderMode = curRealMode;
1851
- // @ts-ignore
1852
1868
  var componentsManager = this.scene._componentsManager;
1853
1869
  switch(preRealMode){
1854
1870
  case CanvasRenderMode.ScreenSpaceOverlay:
@@ -1882,7 +1898,8 @@
1882
1898
  {
1883
1899
  key: "referenceResolutionPerUnit",
1884
1900
  get: /**
1885
- * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1901
+ * Local UI units per sprite world unit for sliced borders and tile sizing.
1902
+ * One glyph pixel maps to `referenceResolutionPerUnit / 100` local UI units.
1886
1903
  */ function get() {
1887
1904
  return this._referenceResolutionPerUnit;
1888
1905
  },
@@ -1898,7 +1915,8 @@
1898
1915
  {
1899
1916
  key: "referenceResolution",
1900
1917
  get: /**
1901
- * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1918
+ * Design resolution in pixels for {@link CanvasRenderMode.ScreenSpaceCamera} and {@link CanvasRenderMode.ScreenSpaceOverlay}.
1919
+ * The root canvas adapts it to the camera viewport or engine canvas using {@link UICanvas.resolutionAdaptationMode}.
1902
1920
  */ function get() {
1903
1921
  return this._referenceResolution;
1904
1922
  },
@@ -1986,15 +2004,14 @@
1986
2004
  {
1987
2005
  key: "sortOrder",
1988
2006
  get: /**
1989
- * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
2007
+ * The rendering priority of the canvas.
1990
2008
  */ function get() {
1991
2009
  return this._sortOrder;
1992
2010
  },
1993
2011
  set: function set(value) {
1994
2012
  if (this._sortOrder !== value) {
1995
2013
  this._sortOrder = value;
1996
- this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
1997
- (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
2014
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && (this.scene._componentsManager._overlayCanvasesSortingDirty = true);
1998
2015
  }
1999
2016
  }
2000
2017
  },
@@ -2019,16 +2036,12 @@
2019
2036
  return UICanvas;
2020
2037
  }(engine.Component);
2021
2038
  /** @internal */ exports.UICanvas._hierarchyCounter = 1;
2022
- exports.UICanvas._targetTempPath = [];
2023
2039
  exports.UICanvas._tempGroupAbleList = [];
2024
2040
  exports.UICanvas._tempVec3 = new engine.Vector3();
2025
2041
  exports.UICanvas._tempMat = new engine.Matrix();
2026
2042
  __decorate([
2027
2043
  engine.ignoreClone
2028
2044
  ], exports.UICanvas.prototype, "_canvasIndex", void 0);
2029
- __decorate([
2030
- engine.ignoreClone
2031
- ], exports.UICanvas.prototype, "_rootCanvas", void 0);
2032
2045
  __decorate([
2033
2046
  engine.ignoreClone
2034
2047
  ], exports.UICanvas.prototype, "_indexInRootCanvas", void 0);
@@ -2043,7 +2056,10 @@
2043
2056
  ], exports.UICanvas.prototype, "_isRootCanvas", void 0);
2044
2057
  __decorate([
2045
2058
  engine.ignoreClone
2046
- ], exports.UICanvas.prototype, "_renderElement", void 0);
2059
+ ], exports.UICanvas.prototype, "_renderElements", void 0);
2060
+ __decorate([
2061
+ engine.ignoreClone
2062
+ ], exports.UICanvas.prototype, "_batchedRenderElements", void 0);
2047
2063
  __decorate([
2048
2064
  engine.ignoreClone
2049
2065
  ], exports.UICanvas.prototype, "_sortDistance", void 0);
@@ -2053,42 +2069,15 @@
2053
2069
  __decorate([
2054
2070
  engine.ignoreClone
2055
2071
  ], exports.UICanvas.prototype, "_realRenderMode", void 0);
2056
- __decorate([
2057
- engine.ignoreClone
2058
- ], exports.UICanvas.prototype, "_disorderedElements", void 0);
2059
2072
  __decorate([
2060
2073
  engine.ignoreClone
2061
2074
  ], exports.UICanvas.prototype, "_renderMode", void 0);
2062
- __decorate([
2063
- engine.ignoreClone
2064
- ], exports.UICanvas.prototype, "_camera", void 0);
2065
- __decorate([
2066
- engine.ignoreClone
2067
- ], exports.UICanvas.prototype, "_cameraObserver", void 0);
2068
- __decorate([
2069
- engine.assignmentClone
2070
- ], exports.UICanvas.prototype, "_resolutionAdaptationMode", void 0);
2071
- __decorate([
2072
- engine.assignmentClone
2073
- ], exports.UICanvas.prototype, "_sortOrder", void 0);
2074
- __decorate([
2075
- engine.assignmentClone
2076
- ], exports.UICanvas.prototype, "_distance", void 0);
2077
- __decorate([
2078
- engine.deepClone
2079
- ], exports.UICanvas.prototype, "_referenceResolution", void 0);
2080
- __decorate([
2081
- engine.assignmentClone
2082
- ], exports.UICanvas.prototype, "_referenceResolutionPerUnit", void 0);
2083
2075
  __decorate([
2084
2076
  engine.ignoreClone
2085
2077
  ], exports.UICanvas.prototype, "_hierarchyVersion", void 0);
2086
2078
  __decorate([
2087
2079
  engine.ignoreClone
2088
2080
  ], exports.UICanvas.prototype, "_center", void 0);
2089
- __decorate([
2090
- engine.ignoreClone
2091
- ], exports.UICanvas.prototype, "_centerDirtyFlag", void 0);
2092
2081
  __decorate([
2093
2082
  engine.ignoreClone
2094
2083
  ], exports.UICanvas.prototype, "_rootCanvasListener", null);
@@ -2125,45 +2114,32 @@
2125
2114
  _inherits(Button, UIInteractive);
2126
2115
  function Button() {
2127
2116
  var _this;
2128
- _this = UIInteractive.apply(this, arguments) || this, _this._listeners = new engine.SafeLoopArray();
2117
+ _this = UIInteractive.apply(this, arguments) || this, /** Signal emitted when the button is clicked. */ _this.onClick = new engine.Signal();
2129
2118
  return _this;
2130
2119
  }
2131
2120
  var _proto = Button.prototype;
2121
+ _proto.onPointerClick = function onPointerClick(event) {
2122
+ if (!this._getGlobalInteractive()) return;
2123
+ this.onClick.invoke(event);
2124
+ };
2125
+ _proto.onDestroy = function onDestroy() {
2126
+ UIInteractive.prototype.onDestroy.call(this);
2127
+ this.onClick.removeAll();
2128
+ };
2132
2129
  /**
2133
2130
  * Add a listening function for click.
2134
- * @param listener - The listening function
2131
+ * @deprecated Use `onClick.on(listener, context)` instead.
2135
2132
  */ _proto.addClicked = function addClicked(listener) {
2136
- this._listeners.push({
2137
- fn: listener
2138
- });
2133
+ this.onClick.on(listener);
2139
2134
  };
2140
2135
  /**
2141
2136
  * Remove a listening function of click.
2142
- * @param listener - The listening function
2137
+ * @deprecated Use `onClick.off(listener, context)` instead.
2143
2138
  */ _proto.removeClicked = function removeClicked(listener) {
2144
- this._listeners.findAndRemove(function(value) {
2145
- return value.fn === listener ? value.destroyed = true : false;
2146
- });
2147
- };
2148
- _proto.onPointerClick = function onPointerClick(event) {
2149
- if (!this._getGlobalInteractive()) return;
2150
- var listeners = this._listeners.getLoopArray();
2151
- for(var i = 0, n = listeners.length; i < n; i++){
2152
- var listener = listeners[i];
2153
- !listener.destroyed && listener.fn(event);
2154
- }
2155
- };
2156
- _proto.onDestroy = function onDestroy() {
2157
- UIInteractive.prototype.onDestroy.call(this);
2158
- this._listeners.findAndRemove(function(value) {
2159
- return value.destroyed = true;
2160
- });
2139
+ this.onClick.off(listener);
2161
2140
  };
2162
2141
  return Button;
2163
2142
  }(UIInteractive);
2164
- __decorate([
2165
- engine.ignoreClone
2166
- ], Button.prototype, "_listeners", void 0);
2167
2143
 
2168
2144
  /**
2169
2145
  * UI element that renders an image.
@@ -2173,7 +2149,6 @@
2173
2149
  var _this;
2174
2150
  _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = engine.SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5;
2175
2151
  _this.drawMode = engine.SpriteDrawMode.Simple;
2176
- // @ts-ignore
2177
2152
  _this.setMaterial(_this._engine._getUIDefaultMaterial());
2178
2153
  _this._onSpriteChange = _this._onSpriteChange.bind(_this);
2179
2154
  return _this;
@@ -2193,9 +2168,9 @@
2193
2168
  };
2194
2169
  /**
2195
2170
  * @internal
2196
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
2197
- // @ts-ignore
2198
- UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
2171
+ * @inheritdoc
2172
+ */ _proto._onClone = function _onClone(target) {
2173
+ UIRenderer1.prototype._onClone.call(this, target);
2199
2174
  target.sprite = this._sprite;
2200
2175
  target.drawMode = this._drawMode;
2201
2176
  };
@@ -2225,7 +2200,6 @@
2225
2200
  }
2226
2201
  // @todo: This question needs to be raised rather than hidden.
2227
2202
  if (material.destroyed) {
2228
- // @ts-ignore
2229
2203
  material = this._engine._getUIDefaultMaterial();
2230
2204
  }
2231
2205
  var alpha = this._getGlobalAlpha();
@@ -2250,16 +2224,14 @@
2250
2224
  dirtyUpdateFlag &= ~UIRendererUpdateFlags.Color;
2251
2225
  }
2252
2226
  this._dirtyUpdateFlag = dirtyUpdateFlag;
2253
- // Init sub render element.
2254
2227
  var engine$1 = context.camera.engine;
2255
- var subRenderElement = engine$1._subRenderElementPool.get();
2228
+ var renderElement = engine$1._renderElementPool.get();
2256
2229
  var subChunk = this._subChunk;
2257
- subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
2258
- if (canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
2259
- subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
2260
- subRenderElement.renderQueueFlags = engine.RenderQueueFlags.All;
2261
- }
2262
- canvas._renderElement.addSubRenderElement(subRenderElement);
2230
+ renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
2231
+ renderElement.subShader = material.shader.subShaders[0];
2232
+ renderElement.priority = canvas.sortOrder;
2233
+ renderElement.distanceForSort = canvas._sortDistance;
2234
+ canvas._renderElements.push(renderElement);
2263
2235
  };
2264
2236
  _proto._onTransformChanged = function _onTransformChanged(type) {
2265
2237
  if (type & UITransformModifyFlags.Size && this._drawMode === engine.SpriteDrawMode.Tiled) {
@@ -2271,7 +2243,6 @@
2271
2243
  var sprite = this._sprite;
2272
2244
  if (sprite) {
2273
2245
  this._addResourceReferCount(sprite, -1);
2274
- // @ts-ignore
2275
2246
  sprite._updateFlagManager.removeListener(this._onSpriteChange);
2276
2247
  this._sprite = null;
2277
2248
  }
@@ -2386,13 +2357,11 @@
2386
2357
  if (lastSprite !== value) {
2387
2358
  if (lastSprite) {
2388
2359
  this._addResourceReferCount(lastSprite, -1);
2389
- // @ts-ignore
2390
2360
  lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
2391
2361
  }
2392
2362
  this._dirtyUpdateFlag |= 7;
2393
2363
  if (value) {
2394
2364
  this._addResourceReferCount(value, 1);
2395
- // @ts-ignore
2396
2365
  value._updateFlagManager.addListener(this._onSpriteChange);
2397
2366
  this.shaderData.setTexture(exports.UIRenderer._textureProperty, value.texture);
2398
2367
  } else {
@@ -2414,12 +2383,6 @@
2414
2383
  __decorate([
2415
2384
  engine.ignoreClone
2416
2385
  ], Image.prototype, "_assembler", void 0);
2417
- __decorate([
2418
- engine.assignmentClone
2419
- ], Image.prototype, "_tileMode", void 0);
2420
- __decorate([
2421
- engine.assignmentClone
2422
- ], Image.prototype, "_tiledAdaptiveThreshold", void 0);
2423
2386
  __decorate([
2424
2387
  engine.ignoreClone
2425
2388
  ], Image.prototype, "_onTransformChanged", null);
@@ -2435,10 +2398,8 @@
2435
2398
  var _this;
2436
2399
  _this = UIRenderer1.call(this, entity) || this, _this._textChunks = Array(), _this._subFont = null, _this._text = "", _this._localBounds = new engine.BoundingBox(), _this._font = null, _this._fontSize = 24, _this._fontStyle = engine.FontStyle.None, _this._lineSpacing = 0, _this._characterSpacing = 0, _this._horizontalAlignment = engine.TextHorizontalAlignment.Center, _this._verticalAlignment = engine.TextVerticalAlignment.Center, _this._enableWrapping = false, _this._overflowMode = engine.OverflowMode.Overflow;
2437
2400
  var engine$1 = _this.engine;
2438
- // @ts-ignore
2439
2401
  _this.font = engine$1._textDefaultFont;
2440
2402
  _this.raycastEnabled = false;
2441
- // @ts-ignore
2442
2403
  _this.setMaterial(engine$1._basicResources.textDefaultMaterial);
2443
2404
  return _this;
2444
2405
  }
@@ -2455,13 +2416,6 @@
2455
2416
  this._textChunks = null;
2456
2417
  this._subFont && (this._subFont = null);
2457
2418
  };
2458
- // @ts-ignore
2459
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
2460
- // @ts-ignore
2461
- UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
2462
- target.font = this._font;
2463
- target._subFont = this._subFont;
2464
- };
2465
2419
  /**
2466
2420
  * @internal
2467
2421
  */ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
@@ -2489,7 +2443,7 @@
2489
2443
  * @internal
2490
2444
  */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2491
2445
  if (flag === RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2492
- this._setDirtyFlagTrue(8);
2446
+ this._setDirtyFlagTrue(25);
2493
2447
  }
2494
2448
  };
2495
2449
  _proto._updateBounds = function _updateBounds(worldBounds) {
@@ -2511,7 +2465,7 @@
2511
2465
  var canvas = this._getRootCanvas();
2512
2466
  if (this._isContainDirtyFlag(8)) {
2513
2467
  this._updateLocalData();
2514
- this._setDirtyFlagTrue(8);
2468
+ this._setDirtyFlagFalse(8);
2515
2469
  }
2516
2470
  if (this._isContainDirtyFlag(16)) {
2517
2471
  this._updatePosition();
@@ -2522,29 +2476,28 @@
2522
2476
  this._setDirtyFlagFalse(UIRendererUpdateFlags.Color);
2523
2477
  }
2524
2478
  var engine$1 = context.camera.engine;
2525
- var textSubRenderElementPool = engine$1._textSubRenderElementPool;
2479
+ var textRenderElementPool = engine$1._textRenderElementPool;
2526
2480
  var material = this.getMaterial();
2527
- var renderElement = canvas._renderElement;
2481
+ var renderElements = canvas._renderElements;
2482
+ var priority = canvas.sortOrder;
2483
+ var distanceForSort = canvas._sortDistance;
2528
2484
  var textChunks = this._textChunks;
2529
- var isOverlay = canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay;
2485
+ var subShader = material.shader.subShaders[0];
2530
2486
  for(var i = 0, n = textChunks.length; i < n; ++i){
2531
- var // @ts-ignore
2532
- _subRenderElement;
2533
2487
  var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, texture = _textChunks_i.texture;
2534
- var subRenderElement = textSubRenderElementPool.get();
2535
- subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
2536
- (_subRenderElement = subRenderElement).shaderData || (_subRenderElement.shaderData = new engine.ShaderData(engine.ShaderDataGroup.RenderElement));
2537
- subRenderElement.shaderData.setTexture(Text._textTextureProperty, texture);
2538
- if (isOverlay) {
2539
- subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
2540
- subRenderElement.renderQueueFlags = engine.RenderQueueFlags.All;
2541
- }
2542
- renderElement.addSubRenderElement(subRenderElement);
2488
+ var renderElement = textRenderElementPool.get();
2489
+ var _renderElement_shaderData;
2490
+ var shaderData = (_renderElement_shaderData = renderElement.shaderData) != null ? _renderElement_shaderData : new engine.ShaderData(engine.ShaderDataGroup.RenderElement);
2491
+ renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk, shaderData);
2492
+ shaderData.setTexture(Text._textTextureProperty, texture);
2493
+ renderElement.subShader = subShader;
2494
+ renderElement.priority = priority;
2495
+ renderElement.distanceForSort = distanceForSort;
2496
+ renderElements.push(renderElement);
2543
2497
  }
2544
2498
  };
2545
2499
  _proto._resetSubFont = function _resetSubFont() {
2546
2500
  var font = this._font;
2547
- // @ts-ignore
2548
2501
  this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
2549
2502
  this._subFont.nativeFontString = engine.TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
2550
2503
  };
@@ -2600,7 +2553,6 @@
2600
2553
  }
2601
2554
  };
2602
2555
  _proto._updateLocalData = function _updateLocalData() {
2603
- // @ts-ignore
2604
2556
  var pixelsPerResolution = engine.Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
2605
2557
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
2606
2558
  var charRenderInfos = Text._charRenderInfos;
@@ -2613,7 +2565,6 @@
2613
2565
  var characterSpacing = this._characterSpacing * this._fontSize;
2614
2566
  var textMetrics = this.enableWrapping ? engine.TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing) : engine.TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing);
2615
2567
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
2616
- // @ts-ignore
2617
2568
  var charRenderInfoPool = this.engine._charRenderInfoPool;
2618
2569
  var linesLen = lines.length;
2619
2570
  var renderElementCount = 0;
@@ -2743,7 +2694,7 @@
2743
2694
  };
2744
2695
  _proto._isTextNoVisible = function _isTextNoVisible() {
2745
2696
  var size = this._transformEntity.transform.size;
2746
- return this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === engine.OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
2697
+ return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === engine.OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
2747
2698
  };
2748
2699
  _proto._buildChunk = function _buildChunk(textChunk, count) {
2749
2700
  var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
@@ -2775,7 +2726,6 @@
2775
2726
  };
2776
2727
  _proto._freeTextChunks = function _freeTextChunks() {
2777
2728
  var textChunks = this._textChunks;
2778
- // @ts-ignore
2779
2729
  var charRenderInfoPool = this.engine._charRenderInfoPool;
2780
2730
  var manager = this._getChunkManager();
2781
2731
  for(var i = 0, n = textChunks.length; i < n; ++i){
@@ -2827,7 +2777,9 @@
2827
2777
  {
2828
2778
  key: "fontSize",
2829
2779
  get: /**
2830
- * The font size of the Text.
2780
+ * Font size in pixels, used for glyph rasterization.
2781
+ * Glyph pixel dimensions are converted to local UI units using the root canvas's
2782
+ * {@link UICanvas.referenceResolutionPerUnit}.
2831
2783
  */ function get() {
2832
2784
  return this._fontSize;
2833
2785
  },
@@ -2987,39 +2939,9 @@
2987
2939
  __decorate([
2988
2940
  engine.ignoreClone
2989
2941
  ], Text.prototype, "_subFont", void 0);
2990
- __decorate([
2991
- engine.assignmentClone
2992
- ], Text.prototype, "_text", void 0);
2993
2942
  __decorate([
2994
2943
  engine.ignoreClone
2995
2944
  ], Text.prototype, "_localBounds", void 0);
2996
- __decorate([
2997
- engine.assignmentClone
2998
- ], Text.prototype, "_font", void 0);
2999
- __decorate([
3000
- engine.assignmentClone
3001
- ], Text.prototype, "_fontSize", void 0);
3002
- __decorate([
3003
- engine.assignmentClone
3004
- ], Text.prototype, "_fontStyle", void 0);
3005
- __decorate([
3006
- engine.assignmentClone
3007
- ], Text.prototype, "_lineSpacing", void 0);
3008
- __decorate([
3009
- engine.assignmentClone
3010
- ], Text.prototype, "_characterSpacing", void 0);
3011
- __decorate([
3012
- engine.assignmentClone
3013
- ], Text.prototype, "_horizontalAlignment", void 0);
3014
- __decorate([
3015
- engine.assignmentClone
3016
- ], Text.prototype, "_verticalAlignment", void 0);
3017
- __decorate([
3018
- engine.assignmentClone
3019
- ], Text.prototype, "_enableWrapping", void 0);
3020
- __decorate([
3021
- engine.assignmentClone
3022
- ], Text.prototype, "_overflowMode", void 0);
3023
2945
  __decorate([
3024
2946
  engine.ignoreClone
3025
2947
  ], Text.prototype, "_onTransformChanged", null);
@@ -3029,20 +2951,30 @@
3029
2951
 
3030
2952
  /**
3031
2953
  * The transition behavior of UIInteractive.
3032
- */ var Transition = /*#__PURE__*/ function() {
2954
+ */ var Transition = /*#__PURE__*/ function(DataObject) {
2955
+ _inherits(Transition, DataObject);
3033
2956
  function Transition() {
3034
- this._duration = 0;
3035
- this._countDown = 0;
3036
- this._finalState = InteractiveState.Normal;
2957
+ var _this;
2958
+ _this = DataObject.apply(this, arguments) || this, _this._duration = 0, _this._countDown = 0, _this._finalState = InteractiveState.Normal;
2959
+ return _this;
3037
2960
  }
3038
2961
  var _proto = Transition.prototype;
3039
2962
  _proto.destroy = function destroy() {
3040
2963
  var _this__interactive;
3041
2964
  (_this__interactive = this._interactive) == null ? void 0 : _this__interactive.removeTransition(this);
2965
+ this._addStateValuesReferCount(-1);
2966
+ this._normal = this._pressed = this._hover = this._disabled = null;
2967
+ this._initialValue = this._currentValue = this._finalValue = null;
3042
2968
  this._target = null;
3043
2969
  };
3044
2970
  /**
3045
2971
  * @internal
2972
+ * @inheritdoc
2973
+ */ _proto._onClone = function _onClone(target) {
2974
+ target._addStateValuesReferCount(1);
2975
+ };
2976
+ /**
2977
+ * @internal
3046
2978
  */ _proto._setState = function _setState(state, instant) {
3047
2979
  this._finalState = state;
3048
2980
  var value = this._getValueByState(state);
@@ -3065,9 +2997,7 @@
3065
2997
  }
3066
2998
  };
3067
2999
  _proto._onStateValueDirty = function _onStateValueDirty(state, preValue, curValue) {
3068
- // @ts-ignore
3069
3000
  _instanceof(preValue, engine.ReferResource) && preValue._addReferCount(-1);
3070
- // @ts-ignore
3071
3001
  _instanceof(curValue, engine.ReferResource) && curValue._addReferCount(1);
3072
3002
  if (this._finalState === state) {
3073
3003
  this._finalValue = curValue;
@@ -3080,6 +3010,13 @@
3080
3010
  this._updateCurrentValue(this._initialValue, this._finalValue, weight);
3081
3011
  ((_this__target = this._target) == null ? void 0 : _this__target.enabled) && this._applyValue(this._currentValue);
3082
3012
  };
3013
+ _proto._addStateValuesReferCount = function _addStateValuesReferCount(count) {
3014
+ var _this = this, _normal = _this._normal, _pressed = _this._pressed, _hover = _this._hover, _disabled = _this._disabled;
3015
+ _instanceof(_normal, engine.ReferResource) && _normal._addReferCount(count);
3016
+ _instanceof(_pressed, engine.ReferResource) && _pressed._addReferCount(count);
3017
+ _instanceof(_hover, engine.ReferResource) && _hover._addReferCount(count);
3018
+ _instanceof(_disabled, engine.ReferResource) && _disabled._addReferCount(count);
3019
+ };
3083
3020
  _proto._getValueByState = function _getValueByState(state) {
3084
3021
  switch(state){
3085
3022
  case InteractiveState.Normal:
@@ -3188,7 +3125,22 @@
3188
3125
  }
3189
3126
  ]);
3190
3127
  return Transition;
3191
- }();
3128
+ }(engine.DataObject);
3129
+ __decorate([
3130
+ engine.ignoreClone
3131
+ ], Transition.prototype, "_countDown", void 0);
3132
+ __decorate([
3133
+ engine.ignoreClone
3134
+ ], Transition.prototype, "_initialValue", void 0);
3135
+ __decorate([
3136
+ engine.ignoreClone
3137
+ ], Transition.prototype, "_finalValue", void 0);
3138
+ __decorate([
3139
+ engine.ignoreClone
3140
+ ], Transition.prototype, "_currentValue", void 0);
3141
+ __decorate([
3142
+ engine.ignoreClone
3143
+ ], Transition.prototype, "_finalState", void 0);
3192
3144
 
3193
3145
  /**
3194
3146
  * Color transition.
@@ -3297,33 +3249,6 @@
3297
3249
  return Transition.apply(this, arguments) || this;
3298
3250
  }
3299
3251
  var _proto = SpriteTransition.prototype;
3300
- /**
3301
- * @internal
3302
- */ _proto.destroy = function destroy() {
3303
- Transition.prototype.destroy.call(this);
3304
- if (this._normal) {
3305
- // @ts-ignore
3306
- this._normal._addReferCount(-1);
3307
- this._normal = null;
3308
- }
3309
- if (this._hover) {
3310
- // @ts-ignore
3311
- this._hover._addReferCount(-1);
3312
- this._hover = null;
3313
- }
3314
- if (this._pressed) {
3315
- // @ts-ignore
3316
- this._pressed._addReferCount(-1);
3317
- this._pressed = null;
3318
- }
3319
- if (this._disabled) {
3320
- // @ts-ignore
3321
- this._disabled._addReferCount(-1);
3322
- this._disabled = null;
3323
- }
3324
- this._initialValue = this._currentValue = this._finalValue = null;
3325
- this._target = null;
3326
- };
3327
3252
  _proto._getTargetValueCopy = function _getTargetValueCopy() {
3328
3253
  var _this__target;
3329
3254
  return (_this__target = this._target) == null ? void 0 : _this__target.sprite;
@@ -3352,10 +3277,6 @@
3352
3277
  Transition: Transition
3353
3278
  });
3354
3279
 
3355
- 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
3356
-
3357
- 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
3358
-
3359
3280
  /**
3360
3281
  * @internal
3361
3282
  */ var UIHitResult = function UIHitResult() {
@@ -3385,15 +3306,13 @@
3385
3306
  for(var i = scenes.length - 1; i >= 0; i--){
3386
3307
  var scene = scenes[i];
3387
3308
  if (!scene.isActive || scene.destroyed) continue;
3388
- // @ts-ignore
3389
3309
  var componentsManager = scene._componentsManager;
3390
- // Overlay Canvas
3391
3310
  var canvasElements = componentsManager._overlayCanvases;
3392
- // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
3311
+ // Convert screen coordinates to overlay coordinates.
3393
3312
  ray.origin.set(position.x, scene.engine.canvas.height - position.y, 1);
3394
3313
  ray.direction.set(0, 0, -1);
3395
3314
  for(var j = canvasElements.length - 1; j >= 0; j--){
3396
- if (canvasElements.get(j)._raycast(ray, hitResult)) {
3315
+ if (canvasElements.get(j)._raycast(ray, hitResult, Number.MAX_SAFE_INTEGER, engine.Layer.Everything)) {
3397
3316
  this._updateRaycast(hitResult.component, pointer);
3398
3317
  return;
3399
3318
  }
@@ -3407,26 +3326,22 @@
3407
3326
  continue;
3408
3327
  }
3409
3328
  camera.screenPointToRay(pointer.position, ray);
3410
- // Other canvases
3411
- var isOrthographic = camera.isOrthographic;
3412
- var _camera_entity_transform = camera.entity.transform, cameraPosition = _camera_entity_transform.worldPosition, cameraForward = _camera_entity_transform.worldForward;
3413
- // Sort by rendering order
3414
3329
  canvasElements = componentsManager._canvases;
3330
+ var isOrthographic = camera.isOrthographic, farClipPlane = camera.farClipPlane, cullingMask = camera.cullingMask;
3331
+ var _camera_entity_transform = camera.entity.transform, worldPosition = _camera_entity_transform.worldPosition, worldForward = _camera_entity_transform.worldForward;
3415
3332
  for(var k = 0, n = canvasElements.length; k < n; k++){
3416
- canvasElements.get(k)._updateSortDistance(isOrthographic, cameraPosition, cameraForward);
3333
+ canvasElements.get(k)._updateSortDistance(isOrthographic, worldPosition, worldForward);
3417
3334
  }
3418
- canvasElements.sort(function(a, b) {
3419
- return a.sortOrder - b.sortOrder || a._sortDistance - b._sortDistance;
3420
- });
3335
+ canvasElements.sort(UIPointerEventEmitter._compareRaycastOrder);
3336
+ // Update registry indices after sorting.
3421
3337
  for(var k1 = 0, n1 = canvasElements.length; k1 < n1; k1++){
3422
3338
  canvasElements.get(k1)._canvasIndex = k1;
3423
3339
  }
3424
- var farClipPlane = camera.farClipPlane;
3425
- // Post-rendering first detection
3340
+ // Fully tied canvases may differ in hit and draw order.
3426
3341
  for(var k2 = 0, n2 = canvasElements.length; k2 < n2; k2++){
3427
3342
  var canvas = canvasElements.get(k2);
3428
3343
  if (!canvas._canDispatchEvent(camera)) continue;
3429
- if (canvas._raycast(ray, hitResult, farClipPlane)) {
3344
+ if (canvas._raycast(ray, hitResult, farClipPlane, cullingMask)) {
3430
3345
  this._updateRaycast(hitResult.component, pointer);
3431
3346
  return;
3432
3347
  }
@@ -3587,6 +3502,9 @@
3587
3502
  fireEvent(path[i], eventData);
3588
3503
  }
3589
3504
  };
3505
+ UIPointerEventEmitter._compareRaycastOrder = function _compareRaycastOrder(a, b) {
3506
+ return b.sortOrder - a.sortOrder || a._sortDistance - b._sortDistance;
3507
+ };
3590
3508
  return UIPointerEventEmitter;
3591
3509
  }(engine.PointerEventEmitter);
3592
3510
  exports.UIPointerEventEmitter._MAX_PATH_DEPTH = 2048;
@@ -3598,25 +3516,14 @@
3598
3516
  engine.registerPointerEventEmitter()
3599
3517
  ], exports.UIPointerEventEmitter);
3600
3518
 
3601
- var EngineExtension = /*#__PURE__*/ function() {
3519
+ /**
3520
+ * @internal
3521
+ */ var EngineExtension = /*#__PURE__*/ function() {
3602
3522
  function EngineExtension() {}
3603
3523
  var _proto = EngineExtension.prototype;
3604
3524
  _proto._getUIDefaultMaterial = function _getUIDefaultMaterial() {
3605
3525
  if (!this._uiDefaultMaterial) {
3606
- var shader = _getOrCreateUIShader();
3607
- // @ts-ignore
3608
- var material = new engine.Material(this, shader);
3609
- var renderState = material.renderState;
3610
- var target = renderState.blendState.targetBlendState;
3611
- target.enabled = true;
3612
- target.sourceColorBlendFactor = engine.BlendFactor.SourceAlpha;
3613
- target.destinationColorBlendFactor = engine.BlendFactor.OneMinusSourceAlpha;
3614
- target.sourceAlphaBlendFactor = engine.BlendFactor.One;
3615
- target.destinationAlphaBlendFactor = engine.BlendFactor.OneMinusSourceAlpha;
3616
- target.colorBlendOperation = target.alphaBlendOperation = engine.BlendOperation.Add;
3617
- renderState.depthState.writeEnabled = false;
3618
- renderState.rasterState.cullMode = engine.CullMode.Off;
3619
- renderState.renderQueueType = engine.RenderQueueType.Transparent;
3526
+ var material = new engine.Material(this, engine.Engine._builtinShaders.ui);
3620
3527
  material.isGCIgnored = true;
3621
3528
  this._uiDefaultMaterial = material;
3622
3529
  }
@@ -3624,7 +3531,9 @@
3624
3531
  };
3625
3532
  return EngineExtension;
3626
3533
  }();
3627
- var EntityExtension = /*#__PURE__*/ function() {
3534
+ /**
3535
+ * @internal
3536
+ */ var EntityExtension = /*#__PURE__*/ function() {
3628
3537
  function EntityExtension() {
3629
3538
  this._uiHierarchyVersion = 0;
3630
3539
  }
@@ -3652,38 +3561,12 @@
3652
3561
  ApplyMixins(engine.Entity, [
3653
3562
  EntityExtension
3654
3563
  ]);
3655
- engine.ReflectionParser.registerCustomParseComponent("Text", /*#__PURE__*/ _async_to_generator(function(instance, item) {
3656
- var props;
3657
- return __generator(this, function(_state) {
3658
- props = item.props;
3659
- if (!props.font) {
3660
- // @ts-ignore
3661
- instance.font = engine.Font.createFromOS(instance.engine, props.fontFamily || "Arial");
3662
- }
3663
- return [
3664
- 2,
3665
- instance
3666
- ];
3667
- });
3668
- }));
3669
3564
  /**
3670
3565
  * Register GUI components for the editor.
3671
3566
  */ function registerGUI() {
3672
3567
  for(var key in GUIComponent){
3673
3568
  engine.Loader.registerClass(key, GUIComponent[key]);
3674
3569
  }
3675
- _getOrCreateUIShader();
3676
- }
3677
- function _getOrCreateUIShader() {
3678
- var shader = engine.Shader.find("ui");
3679
- if (!shader) {
3680
- shader = engine.Shader.create("ui", [
3681
- new engine.ShaderPass("Forward", uiDefaultVs, uiDefaultFs, {
3682
- pipelineStage: engine.PipelineStage.Forward
3683
- })
3684
- ]);
3685
- }
3686
- return shader;
3687
3570
  }
3688
3571
 
3689
3572
  exports.Button = Button;