@galacean/engine-ui 0.0.0-experimental-2.0-spine.1 → 0.0.0-experimental-2.0-migrate.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -4,24 +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 _defineProperties(target, props) {
8
- for (var i = 0; i < props.length; i++) {
9
- var descriptor = props[i];
10
- descriptor.enumerable = descriptor.enumerable || false;
11
- descriptor.configurable = true;
12
-
13
- if ("value" in descriptor) descriptor.writable = true;
14
-
15
- Object.defineProperty(target, descriptor.key, descriptor);
16
- }
17
- }
18
- function _create_class(Constructor, protoProps, staticProps) {
19
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
20
- if (staticProps) _defineProperties(Constructor, staticProps);
21
-
22
- return Constructor;
23
- }
24
-
25
7
  function _set_prototype_of(o, p) {
26
8
  _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
27
9
  o.__proto__ = p;
@@ -42,10 +24,22 @@
42
24
  if (superClass) _set_prototype_of(subClass, superClass);
43
25
  }
44
26
 
45
- function _instanceof(left, right) {
46
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
47
- return !!right[Symbol.hasInstance](left);
48
- } else return left instanceof right;
27
+ function _defineProperties(target, props) {
28
+ for (var i = 0; i < props.length; i++) {
29
+ var descriptor = props[i];
30
+ descriptor.enumerable = descriptor.enumerable || false;
31
+ descriptor.configurable = true;
32
+
33
+ if ("value" in descriptor) descriptor.writable = true;
34
+
35
+ Object.defineProperty(target, descriptor.key, descriptor);
36
+ }
37
+ }
38
+ function _create_class(Constructor, protoProps, staticProps) {
39
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
40
+ if (staticProps) _defineProperties(Constructor, staticProps);
41
+
42
+ return Constructor;
49
43
  }
50
44
 
51
45
  /******************************************************************************
@@ -75,957 +69,944 @@
75
69
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
76
70
  };
77
71
 
78
- var UIGroup = /*#__PURE__*/ function(Component) {
79
- _inherits(UIGroup, Component);
80
- function UIGroup(entity) {
81
- var _this;
82
- _this = Component.call(this, entity) || this, /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._disorderedElements = new engine.DisorderedArray(), /** @internal */ _this._globalAlpha = 1, /** @internal */ _this._globalInteractive = true, _this._alpha = 1, _this._interactive = true, _this._ignoreParentGroup = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupDirtyFlags = 0;
83
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
84
- _this._groupListener = _this._groupListener.bind(_this);
85
- return _this;
86
- }
87
- var _proto = UIGroup.prototype;
72
+ function _instanceof(left, right) {
73
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
74
+ return !!right[Symbol.hasInstance](left);
75
+ } else return left instanceof right;
76
+ }
77
+
78
+ /**
79
+ * @internal
80
+ * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
81
+ *
82
+ * Think of it as stacking elements onto numbered shelves (depths):
83
+ * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
84
+ * - Overlapping + batch-compatible — share the same shelf, still cluster.
85
+ * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
86
+ *
87
+ * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
88
+ * share the same depth and get clustered together. Once depth is assigned, sort by
89
+ * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
90
+ * by-product of materials clustering within each depth band.
91
+ *
92
+ * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
93
+ * are derived from the union AABB of input elements (the bounds transform itself is the
94
+ * work the loop must do anyway, so the union accumulation just piggybacks). This stays
95
+ * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
96
+ * on canvas configuration.
97
+ */ var UIBatchSorter = /*#__PURE__*/ function() {
98
+ function UIBatchSorter() {}
88
99
  /**
89
- * @internal
90
- */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
91
- if (this._isContainDirtyFlag(1)) {
92
- if (this._ignoreParentGroup) {
93
- this._globalAlpha = this._alpha;
94
- } else {
95
- var parentGroup = this._getGroup();
96
- this._globalAlpha = this._alpha * (parentGroup ? parentGroup._getGlobalAlpha() : 1);
100
+ * Reorders `elements` in place for optimal batching.
101
+ * @param elements - in hierarchy order (depth-first traversal); mutated in place
102
+ * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
103
+ */ UIBatchSorter.sort = function sort(elements, canvasWorldMatrix) {
104
+ var count = elements.length;
105
+ if (count <= 1) return;
106
+ var gridDim = this._gridDim;
107
+ var entries = this._entries;
108
+ var grid = this._grid;
109
+ var dirtyCells = this._dirtyCells;
110
+ var localBoundsPool = this._localBoundsPool;
111
+ var worldToLocal = this._worldToLocal;
112
+ engine.Matrix.invert(canvasWorldMatrix, worldToLocal);
113
+ while(entries.length < count)entries.push(new SortEntry());
114
+ // Allocate grid once, reuse forever (each cell must be a real [], not a sparse hole)
115
+ if (grid.length < gridDim) {
116
+ while(grid.length < gridDim)grid.push([]);
117
+ for(var i = 0; i < gridDim; i++){
118
+ var row = grid[i];
119
+ while(row.length < gridDim)row.push([]);
97
120
  }
98
- this._setDirtyFlagFalse(1);
99
121
  }
100
- return this._globalAlpha;
101
- };
102
- /**
103
- * @internal
104
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
105
- if (this._isContainDirtyFlag(2)) {
106
- if (this._ignoreParentGroup) {
107
- this._globalInteractive = this._interactive;
108
- } else {
109
- var parentGroup = this._getGroup();
110
- this._globalInteractive = this._interactive && (!parentGroup || parentGroup._getGlobalInteractive());
122
+ // Clear only previously-used cells (no full sweep)
123
+ for(var k = 0, n = dirtyCells.length; k < n; k += 2){
124
+ grid[dirtyCells[k]][dirtyCells[k + 1]].length = 0;
125
+ }
126
+ dirtyCells.length = 0;
127
+ // Pass 1: transform world bounds to canvas-local + accumulate the union AABB.
128
+ // Transform is already required to do precise overlap, so the union accumulation
129
+ // is essentially free — just a few minmax compares riding on the existing pass
130
+ var unionMinX = Infinity;
131
+ var unionMinY = Infinity;
132
+ var unionMaxX = -Infinity;
133
+ var unionMaxY = -Infinity;
134
+ for(var i1 = 0; i1 < count; i1++){
135
+ var _localBoundsPool, _i;
136
+ var localBounds = (_localBoundsPool = localBoundsPool)[_i = i1] || (_localBoundsPool[_i] = new engine.BoundingBox());
137
+ engine.BoundingBox.transform(elements[i1].component.bounds, worldToLocal, localBounds);
138
+ var min = localBounds.min, max = localBounds.max;
139
+ if (min.x < unionMinX) unionMinX = min.x;
140
+ if (min.y < unionMinY) unionMinY = min.y;
141
+ if (max.x > unionMaxX) unionMaxX = max.x;
142
+ if (max.y > unionMaxY) unionMaxY = max.y;
143
+ }
144
+ // Guard against a degenerate union (all elements collapsed onto a single point /
145
+ // axis); the grid then collapses to cell 0 which is semantically correct
146
+ var cellSizeX = Math.max(1e-6, unionMaxX - unionMinX) / gridDim;
147
+ var cellSizeY = Math.max(1e-6, unionMaxY - unionMinY) / gridDim;
148
+ var maxCell = gridDim - 1;
149
+ // Pass 2: register each element into grid cells and compute its depth
150
+ for(var i2 = 0; i2 < count; i2++){
151
+ var element = elements[i2];
152
+ var localBounds1 = localBoundsPool[i2];
153
+ var materialId = element.material.instanceId;
154
+ var textureId = element.texture ? element.texture.instanceId : 0;
155
+ // Floor + clamp guards floating-point edge cases (a `max` exactly on the union
156
+ // boundary would otherwise produce `gridDim`)
157
+ var minCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.x - unionMinX) / cellSizeX)));
158
+ var maxCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.x - unionMinX) / cellSizeX)));
159
+ var minCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.y - unionMinY) / cellSizeY)));
160
+ var maxCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.y - unionMinY) / cellSizeY)));
161
+ // Find the deepest overlapping prior, and whether that shelf has any incompatible occupant
162
+ var maxDepth = -1;
163
+ var maxDepthIncompatible = false;
164
+ for(var cellY = minCellY; cellY <= maxCellY; cellY++){
165
+ for(var cellX = minCellX; cellX <= maxCellX; cellX++){
166
+ var cell = grid[cellX][cellY];
167
+ for(var j = 0, m = cell.length; j < m; j++){
168
+ var other = cell[j];
169
+ if (!UIBatchSorter._rectOverlap(localBounds1, other.bounds)) continue;
170
+ var otherDepth = other.depth;
171
+ var otherIncompatible = other.materialId !== materialId || other.textureId !== textureId;
172
+ if (otherDepth > maxDepth) {
173
+ maxDepth = otherDepth;
174
+ maxDepthIncompatible = otherIncompatible;
175
+ } else if (otherDepth === maxDepth && otherIncompatible) {
176
+ maxDepthIncompatible = true;
177
+ }
178
+ }
179
+ }
180
+ }
181
+ var entry = entries[i2];
182
+ entry.element = element;
183
+ entry.hierarchyIndex = i2;
184
+ // Share the deepest shelf if compatible; bump up one if blocked by an incompatible occupant
185
+ entry.depth = maxDepth < 0 ? 0 : maxDepth + (maxDepthIncompatible ? 1 : 0);
186
+ entry.materialId = materialId;
187
+ entry.textureId = textureId;
188
+ entry.bounds = localBounds1;
189
+ for(var cellY1 = minCellY; cellY1 <= maxCellY; cellY1++){
190
+ for(var cellX1 = minCellX; cellX1 <= maxCellX; cellX1++){
191
+ var cell1 = grid[cellX1][cellY1];
192
+ if (cell1.length === 0) dirtyCells.push(cellX1, cellY1);
193
+ cell1.push(entry);
194
+ }
111
195
  }
112
- this._setDirtyFlagFalse(2);
113
196
  }
114
- return this._globalInteractive;
197
+ // @ts-ignore — Utils._quickSort is @internal
198
+ engine.Utils._quickSort(entries, 0, count, UIBatchSorter._compareEntries);
199
+ for(var i3 = 0; i3 < count; i3++)elements[i3] = entries[i3].element;
115
200
  };
116
- // @ts-ignore
117
- _proto._onEnableInScene = function _onEnableInScene() {
118
- Utils.setRootCanvasDirty(this);
119
- Utils.setGroupDirty(this);
120
- // @ts-ignore
121
- this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
201
+ UIBatchSorter._rectOverlap = function _rectOverlap(a, b) {
202
+ 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;
122
203
  };
123
- // @ts-ignore
124
- _proto._onDisableInScene = function _onDisableInScene() {
125
- Utils.cleanRootCanvas(this);
126
- Utils.cleanGroup(this);
127
- var disorderedElements = this._disorderedElements;
128
- disorderedElements.forEach(function(element) {
129
- Utils.setGroupDirty(element);
130
- });
131
- disorderedElements.length = 0;
132
- disorderedElements.garbageCollection();
133
- this._isRootCanvasDirty = this._isGroupDirty = false;
204
+ UIBatchSorter._compareEntries = function _compareEntries(a, b) {
205
+ return a.depth - b.depth || a.materialId - b.materialId || a.textureId - b.textureId || a.hierarchyIndex - b.hierarchyIndex;
134
206
  };
207
+ return UIBatchSorter;
208
+ }();
209
+ // Spatial-hash is fastest when cell size ≈ typical element size (one element per cell).
210
+ // UI elements typically span ~10% of the canvas → 10×10 grid.
211
+ UIBatchSorter._gridDim = 10;
212
+ UIBatchSorter._entries = new Array();
213
+ UIBatchSorter._grid = [];
214
+ // Interleaved (x, y) cell coords touched in the previous frame
215
+ UIBatchSorter._dirtyCells = new Array();
216
+ UIBatchSorter._localBoundsPool = new Array();
217
+ UIBatchSorter._worldToLocal = new engine.Matrix();
218
+ // materialId/textureId/bounds are flattened from RenderElement to avoid
219
+ // multi-hop property access in the hot inner loop and the sort comparator.
220
+ var SortEntry = function SortEntry() {
221
+ this.hierarchyIndex = 0;
222
+ this.depth = 0;
223
+ this.materialId = 0;
224
+ this.textureId = 0;
225
+ };
226
+
227
+ /**
228
+ * Render mode for ui canvas.
229
+ */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
135
230
  /**
136
- * @internal
137
- */ _proto._getRootCanvas = function _getRootCanvas() {
138
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
139
- return this._rootCanvas;
140
- };
231
+ * The UI canvas will be rendered directly onto the screen and adapted to screen space,
232
+ * overlaying other rendering elements in the same scene.
233
+ * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
234
+ */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
141
235
  /**
142
- * @internal
143
- */ _proto._getGroup = function _getGroup() {
144
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
145
- return this._group;
146
- };
236
+ * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
237
+ * with all objects rendered by the camera.
238
+ * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
239
+ * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
240
+ */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
241
+ /**
242
+ * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
243
+ */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
244
+ return CanvasRenderMode;
245
+ }({});
246
+
247
+ /**
248
+ * Resolution adaptation mode.
249
+ * @remarks Only effective in screen space.
250
+ */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
251
+ /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
252
+ /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
253
+ /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
254
+ /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
255
+ /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
256
+ return ResolutionAdaptationMode;
257
+ }({});
258
+
259
+ /** Horizontal alignment mode. */ var HorizontalAlignmentMode = /*#__PURE__*/ function(HorizontalAlignmentMode) {
260
+ /** No horizontal alignment. */ HorizontalAlignmentMode[HorizontalAlignmentMode["None"] = 0] = "None";
261
+ /** Left-aligned, `alignLeft` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Left"] = 1] = "Left";
262
+ /** Right-aligned, `alignRight` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Right"] = 2] = "Right";
263
+ /** Horizontal stretch, `alignLeft` and `alignRight` drive `position.x` and `size.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["LeftAndRight"] = 3] = "LeftAndRight";
264
+ /** Center-aligned, `alignCenter` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Center"] = 4] = "Center";
265
+ return HorizontalAlignmentMode;
266
+ }({});
267
+
268
+ /** Vertical alignment mode. */ var VerticalAlignmentMode = /*#__PURE__*/ function(VerticalAlignmentMode) {
269
+ /** No vertical alignment. */ VerticalAlignmentMode[VerticalAlignmentMode["None"] = 0] = "None";
270
+ /** Top-aligned, `alignTop` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Top"] = 1] = "Top";
271
+ /** Bottom-aligned, `alignBottom` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Bottom"] = 2] = "Bottom";
272
+ /** Vertical stretch, `alignTop` and `alignBottom` drive `position.y` and `size.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["TopAndBottom"] = 3] = "TopAndBottom";
273
+ /** Middle-aligned, `alignMiddle` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Middle"] = 4] = "Middle";
274
+ return VerticalAlignmentMode;
275
+ }({});
276
+
277
+ /**
278
+ * The Transform component exclusive to the UI element.
279
+ */ var UITransform = /*#__PURE__*/ function(Transform) {
280
+ _inherits(UITransform, Transform);
281
+ function UITransform(entity) {
282
+ var _this;
283
+ _this = Transform.call(this, entity) || this, _this._size = new engine.Vector2(100, 100), _this._pivot = new engine.Vector2(0.5, 0.5), _this._rect = new engine.Rect(-50, -50, 100, 100), _this._alignLeft = 0, _this._alignRight = 0, _this._alignCenter = 0, _this._alignTop = 0, _this._alignBottom = 0, _this._alignMiddle = 0, _this._horizontalAlignment = HorizontalAlignmentMode.None, _this._verticalAlignment = VerticalAlignmentMode.None;
284
+ _this._onSizeChanged = _this._onSizeChanged.bind(_this);
285
+ _this._onPivotChanged = _this._onPivotChanged.bind(_this);
286
+ // @ts-ignore
287
+ _this._size._onValueChanged = _this._onSizeChanged;
288
+ // @ts-ignore
289
+ _this._pivot._onValueChanged = _this._onPivotChanged;
290
+ return _this;
291
+ }
292
+ var _proto = UITransform.prototype;
147
293
  /**
148
294
  * @internal
149
- */ _proto._groupListener = function _groupListener(flag) {
150
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
151
- Utils.setGroupDirty(this);
295
+ */ _proto._parentChange = function _parentChange() {
296
+ this._isParentDirty = true;
297
+ this._updateWorldFlagWithParentRectChange(engine.TransformModifyFlags.WmWpWeWqWsWus);
298
+ };
299
+ // @ts-ignore
300
+ _proto._cloneTo = function _cloneTo(target) {
301
+ // @ts-ignore
302
+ Transform.prototype._cloneTo.call(this, target);
303
+ var size = target._size, pivot = target._pivot;
304
+ // @ts-ignore
305
+ size._onValueChanged = pivot._onValueChanged = null;
306
+ size.copyFrom(this._size);
307
+ pivot.copyFrom(this._pivot);
308
+ // @ts-ignore
309
+ size._onValueChanged = target._onSizeChanged;
310
+ // @ts-ignore
311
+ pivot._onValueChanged = target._onPivotChanged;
312
+ };
313
+ _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
314
+ // `super._onLocalMatrixChanging()` will set `LocalMatrix` dirty flag `false`
315
+ // If there is an alignment, `position` and `localMatrix` will be reset again
316
+ if (this._horizontalAlignment || this._verticalAlignment) {
317
+ this._updatePositionByAlignment();
318
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
319
+ } else {
320
+ Transform.prototype._onLocalMatrixChanging.call(this);
152
321
  }
153
322
  };
154
- /**
155
- * @internal
156
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
157
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
158
- Utils.setRootCanvasDirty(this);
159
- Utils.setGroupDirty(this);
323
+ _proto._onWorldMatrixChanging = function _onWorldMatrixChanging() {
324
+ // `super._onWorldMatrixChanging()` will set `WorldMatrix` dirty flag `false`
325
+ // If there is an alignment, `position` and `worldMatrix` will be reset again(`worldMatrix` dirty flag is already `true`)
326
+ !this._horizontalAlignment && !this._verticalAlignment && Transform.prototype._onWorldMatrixChanging.call(this);
327
+ };
328
+ _proto._onPositionChanged = function _onPositionChanged() {
329
+ (this._horizontalAlignment || this._verticalAlignment) && this._updatePositionByAlignment();
330
+ Transform.prototype._onPositionChanged.call(this);
331
+ };
332
+ _proto._onWorldPositionChanged = function _onWorldPositionChanged() {
333
+ Transform.prototype._onWorldPositionChanged.call(this);
334
+ if (this._horizontalAlignment || this._verticalAlignment) {
335
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.WorldPosition);
160
336
  }
161
337
  };
162
- /**
163
- * @internal
164
- */ _proto._onGroupModify = function _onGroupModify(flags, isPass) {
165
- if (isPass === void 0) isPass = false;
166
- if (isPass && this._ignoreParentGroup) return;
167
- if (this._isContainDirtyFlags(flags)) return;
168
- this._setDirtyFlagTrue(flags);
169
- this._disorderedElements.forEach(function(element) {
170
- element._onGroupModify(flags, true);
171
- });
338
+ _proto._updatePositionByAlignment = function _updatePositionByAlignment() {
339
+ var _this__getParentTransform;
340
+ var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
341
+ if (parentRect) {
342
+ var position = this.position;
343
+ // @ts-ignore
344
+ position._onValueChanged = null;
345
+ var rect = this._rect;
346
+ switch(this._horizontalAlignment){
347
+ case HorizontalAlignmentMode.Left:
348
+ case HorizontalAlignmentMode.LeftAndRight:
349
+ position.x = parentRect.x - rect.x + this._alignLeft;
350
+ break;
351
+ case HorizontalAlignmentMode.Center:
352
+ position.x = parentRect.x + parentRect.width * 0.5 - rect.x - rect.width * 0.5 + this._alignCenter;
353
+ break;
354
+ case HorizontalAlignmentMode.Right:
355
+ position.x = parentRect.x + parentRect.width - rect.x - rect.width - this._alignRight;
356
+ break;
357
+ }
358
+ switch(this._verticalAlignment){
359
+ case VerticalAlignmentMode.Top:
360
+ position.y = parentRect.y + parentRect.height - rect.y - rect.height - this._alignTop;
361
+ break;
362
+ case VerticalAlignmentMode.Middle:
363
+ position.y = parentRect.y + parentRect.height * 0.5 - rect.y - rect.height * 0.5 + this._alignMiddle;
364
+ break;
365
+ case VerticalAlignmentMode.Bottom:
366
+ case VerticalAlignmentMode.TopAndBottom:
367
+ position.y = parentRect.y - rect.y + this._alignBottom;
368
+ break;
369
+ }
370
+ // @ts-ignore
371
+ position._onValueChanged = this._onPositionChanged;
372
+ }
172
373
  };
173
- _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
174
- return (this._groupDirtyFlags & targetDirtyFlags) === targetDirtyFlags;
374
+ _proto._updateSizeByAlignment = function _updateSizeByAlignment() {
375
+ var _this__getParentTransform;
376
+ var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
377
+ if (parentRect) {
378
+ var size = this._size;
379
+ // @ts-ignore
380
+ size._onValueChanged = null;
381
+ // The values of size must be greater than 0
382
+ if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight) {
383
+ size.x = Math.max(parentRect.width - this._alignLeft - this._alignRight, 0);
384
+ }
385
+ if (this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
386
+ size.y = Math.max(parentRect.height - this._alignTop - this._alignBottom, 0);
387
+ }
388
+ // @ts-ignore
389
+ size._onValueChanged = this._onSizeChanged;
390
+ }
175
391
  };
176
- _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
177
- return (this._groupDirtyFlags & type) != 0;
392
+ _proto._updateRectBySizeAndPivot = function _updateRectBySizeAndPivot() {
393
+ var _this = this, size = _this.size, pivot = _this._pivot;
394
+ var x = -pivot.x * size.x;
395
+ var y = -pivot.y * size.y;
396
+ this._rect.set(x, y, size.x, size.y);
178
397
  };
179
- _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
180
- this._groupDirtyFlags |= type;
398
+ _proto._onSizeChanged = function _onSizeChanged() {
399
+ if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
400
+ this._updateSizeByAlignment();
401
+ }
402
+ this._updateRectBySizeAndPivot();
403
+ this._updateWorldFlagWithSelfRectChange();
404
+ // @ts-ignore
405
+ this._entity._updateFlagManager.dispatch(512);
181
406
  };
182
- _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
183
- this._groupDirtyFlags &= ~type;
407
+ _proto._onPivotChanged = function _onPivotChanged() {
408
+ this._updateRectBySizeAndPivot();
409
+ this._updateWorldFlagWithSelfRectChange();
410
+ // @ts-ignore
411
+ this._entity._updateFlagManager.dispatch(1024);
184
412
  };
185
- _create_class(UIGroup, [
413
+ _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
414
+ var worldFlags = 0;
415
+ if (this._horizontalAlignment || this._verticalAlignment) {
416
+ this._updatePositionByAlignment();
417
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
418
+ worldFlags = engine.TransformModifyFlags.WmWp;
419
+ !this._isContainDirtyFlags(worldFlags) && this._worldAssociatedChange(worldFlags);
420
+ }
421
+ var children = this.entity.children;
422
+ for(var i = 0, n = children.length; i < n; i++){
423
+ var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
424
+ (_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, worldFlags);
425
+ }
426
+ };
427
+ _proto._updateWorldFlagWithParentRectChange = function _updateWorldFlagWithParentRectChange(flags, parentChange) {
428
+ if (parentChange === void 0) parentChange = true;
429
+ var selfChange = false;
430
+ if (parentChange) {
431
+ var _this = this, horizontalAlignment = _this._horizontalAlignment, verticalAlignment = _this._verticalAlignment;
432
+ if (horizontalAlignment || verticalAlignment) {
433
+ if (horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
434
+ this._updateSizeByAlignment();
435
+ this._updateRectBySizeAndPivot();
436
+ selfChange = true;
437
+ }
438
+ this._updatePositionByAlignment();
439
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
440
+ flags |= engine.TransformModifyFlags.WmWp;
441
+ }
442
+ }
443
+ var containDirtyFlags = this._isContainDirtyFlags(flags);
444
+ !containDirtyFlags && this._worldAssociatedChange(flags);
445
+ if (selfChange || !containDirtyFlags) {
446
+ var children = this.entity.children;
447
+ for(var i = 0, n = children.length; i < n; i++){
448
+ var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
449
+ (_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);
450
+ }
451
+ }
452
+ // @ts-ignore
453
+ selfChange && this._entity._updateFlagManager.dispatch(512);
454
+ };
455
+ _create_class(UITransform, [
186
456
  {
187
- key: "ignoreParentGroup",
457
+ key: "size",
188
458
  get: /**
189
- * Whether to ignore the parent group.
190
- * @remarks If this parameter set to `true`,
191
- * all settings of the parent group will be ignored.
459
+ * Width and height of UI element.
192
460
  */ function get() {
193
- return this._ignoreParentGroup;
461
+ return this._size;
194
462
  },
195
463
  set: function set(value) {
196
- if (this._ignoreParentGroup !== value) {
197
- this._ignoreParentGroup = value;
198
- this._onGroupModify(3);
199
- }
464
+ var _this = this, size = _this._size;
465
+ if (size === value) return;
466
+ (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
200
467
  }
201
468
  },
202
469
  {
203
- key: "interactive",
470
+ key: "pivot",
204
471
  get: /**
205
- * Whether the group is interactive.
472
+ * Pivot of UI element.
206
473
  */ function get() {
207
- return this._interactive;
474
+ return this._pivot;
208
475
  },
209
476
  set: function set(value) {
210
- if (this._interactive !== value) {
211
- this._interactive = value;
212
- this._onGroupModify(2);
477
+ var _this = this, pivot = _this._pivot;
478
+ if (pivot === value) return;
479
+ (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
480
+ }
481
+ },
482
+ {
483
+ key: "horizontalAlignment",
484
+ get: /**
485
+ * Horizontal alignment mode.
486
+ *
487
+ * @remarks
488
+ * Controls how the element aligns horizontally within its parent:
489
+ * - `Left` - Align to parent's left edge
490
+ * - `Center` - Align to parent's horizontal center
491
+ * - `Right` - Align to parent's right edge
492
+ * - `LeftAndRight` - Align to both left and right edges (stretch to fill width)
493
+ */ function get() {
494
+ return this._horizontalAlignment;
495
+ },
496
+ set: function set(value) {
497
+ if (this._horizontalAlignment === value) return;
498
+ this._horizontalAlignment = value;
499
+ switch(value){
500
+ case HorizontalAlignmentMode.Left:
501
+ case HorizontalAlignmentMode.Right:
502
+ case HorizontalAlignmentMode.Center:
503
+ this._onPositionChanged();
504
+ break;
505
+ case HorizontalAlignmentMode.LeftAndRight:
506
+ this._onPositionChanged();
507
+ this._onSizeChanged();
508
+ break;
213
509
  }
214
510
  }
215
511
  },
216
512
  {
217
- key: "alpha",
513
+ key: "alignLeft",
218
514
  get: /**
219
- * The alpha value of the group.
515
+ * Left margin when horizontalAlignment is Left or LeftAndRight.
516
+ *
517
+ * @remarks
518
+ * Only effective when horizontalAlignment includes Left mode.
519
+ * Distance from the parent's left edge to the element's left edge.
220
520
  */ function get() {
221
- return this._alpha;
521
+ return this._alignLeft;
222
522
  },
223
523
  set: function set(value) {
224
- value = Math.max(0, Math.min(value, 1));
225
- if (this._alpha !== value) {
226
- this._alpha = value;
227
- this._onGroupModify(1);
524
+ if (!Number.isFinite(value)) return;
525
+ if (engine.MathUtil.equals(value, this._alignLeft)) return;
526
+ this._alignLeft = value;
527
+ if (this._horizontalAlignment & HorizontalAlignmentMode.Left) {
528
+ this._onPositionChanged();
529
+ this._horizontalAlignment & HorizontalAlignmentMode.Right && this._onSizeChanged();
530
+ }
531
+ }
532
+ },
533
+ {
534
+ key: "alignRight",
535
+ get: /**
536
+ * Right margin when horizontalAlignment is Right or LeftAndRight.
537
+ *
538
+ * @remarks
539
+ * Only effective when horizontalAlignment includes Right mode.
540
+ * Distance from the parent's right edge to the element's right edge.
541
+ */ function get() {
542
+ return this._alignRight;
543
+ },
544
+ set: function set(value) {
545
+ if (!Number.isFinite(value)) return;
546
+ if (engine.MathUtil.equals(value, this._alignRight)) return;
547
+ this._alignRight = value;
548
+ if (this._horizontalAlignment & HorizontalAlignmentMode.Right) {
549
+ this._onPositionChanged();
550
+ this._horizontalAlignment & HorizontalAlignmentMode.Left && this._onSizeChanged();
551
+ }
552
+ }
553
+ },
554
+ {
555
+ key: "alignCenter",
556
+ get: /**
557
+ * Horizontal center offset when horizontalAlignment is Center.
558
+ *
559
+ * @remarks
560
+ * Only effective when horizontalAlignment is Center mode.
561
+ * Positive values move the element to the right, negative values to the left.
562
+ */ function get() {
563
+ return this._alignCenter;
564
+ },
565
+ set: function set(value) {
566
+ if (!Number.isFinite(value)) return;
567
+ if (engine.MathUtil.equals(value, this._alignCenter)) return;
568
+ this._alignCenter = value;
569
+ this._horizontalAlignment & HorizontalAlignmentMode.Center && this._onPositionChanged();
570
+ }
571
+ },
572
+ {
573
+ key: "verticalAlignment",
574
+ get: /**
575
+ * Vertical alignment mode.
576
+ *
577
+ * @remarks
578
+ * Controls how the element aligns vertically within its parent:
579
+ * - `Top` - Align to parent's top edge
580
+ * - `Middle` - Align to parent's vertical center
581
+ * - `Bottom` - Align to parent's bottom edge
582
+ * - `TopAndBottom` - Align to both top and bottom edges (stretch to fill height)
583
+ */ function get() {
584
+ return this._verticalAlignment;
585
+ },
586
+ set: function set(value) {
587
+ if (this._verticalAlignment === value) return;
588
+ this._verticalAlignment = value;
589
+ switch(value){
590
+ case VerticalAlignmentMode.Top:
591
+ case VerticalAlignmentMode.Bottom:
592
+ case VerticalAlignmentMode.Middle:
593
+ this._onPositionChanged();
594
+ break;
595
+ case VerticalAlignmentMode.TopAndBottom:
596
+ this._onPositionChanged();
597
+ this._onSizeChanged();
598
+ break;
599
+ }
600
+ }
601
+ },
602
+ {
603
+ key: "alignTop",
604
+ get: /**
605
+ * Top margin when verticalAlignment is Top or TopAndBottom.
606
+ *
607
+ * @remarks
608
+ * Only effective when verticalAlignment includes Top mode.
609
+ * Used to offset the element from the parent's top edge.
610
+ */ function get() {
611
+ return this._alignTop;
612
+ },
613
+ set: function set(value) {
614
+ if (!Number.isFinite(value)) return;
615
+ if (engine.MathUtil.equals(value, this._alignTop)) return;
616
+ this._alignTop = value;
617
+ if (this._verticalAlignment & VerticalAlignmentMode.Top) {
618
+ this._onPositionChanged();
619
+ this._verticalAlignment & VerticalAlignmentMode.Bottom && this._onSizeChanged();
620
+ }
621
+ }
622
+ },
623
+ {
624
+ key: "alignBottom",
625
+ get: /**
626
+ * Bottom inset used in vertical alignment formulas.
627
+ */ function get() {
628
+ return this._alignBottom;
629
+ },
630
+ set: function set(value) {
631
+ if (!Number.isFinite(value)) return;
632
+ if (engine.MathUtil.equals(value, this._alignBottom)) return;
633
+ this._alignBottom = value;
634
+ if (this._verticalAlignment & VerticalAlignmentMode.Bottom) {
635
+ this._onPositionChanged();
636
+ this._verticalAlignment & VerticalAlignmentMode.Top && this._onSizeChanged();
228
637
  }
229
638
  }
639
+ },
640
+ {
641
+ key: "alignMiddle",
642
+ get: /**
643
+ * Vertical middle offset relative to parent's middle.
644
+ */ function get() {
645
+ return this._alignMiddle;
646
+ },
647
+ set: function set(value) {
648
+ if (!Number.isFinite(value)) return;
649
+ if (engine.MathUtil.equals(value, this._alignMiddle)) return;
650
+ this._alignMiddle = value;
651
+ this._verticalAlignment & VerticalAlignmentMode.Middle && this._onPositionChanged();
652
+ }
230
653
  }
231
654
  ]);
232
- return UIGroup;
233
- }(engine.Component);
234
- __decorate([
235
- engine.ignoreClone
236
- ], UIGroup.prototype, "_indexInGroup", void 0);
237
- __decorate([
238
- engine.ignoreClone
239
- ], UIGroup.prototype, "_indexInRootCanvas", void 0);
240
- __decorate([
241
- engine.ignoreClone
242
- ], UIGroup.prototype, "_disorderedElements", void 0);
243
- __decorate([
244
- engine.ignoreClone
245
- ], UIGroup.prototype, "_globalAlpha", void 0);
246
- __decorate([
247
- engine.ignoreClone
248
- ], UIGroup.prototype, "_globalInteractive", void 0);
249
- __decorate([
250
- engine.assignmentClone
251
- ], UIGroup.prototype, "_alpha", void 0);
252
- __decorate([
253
- engine.assignmentClone
254
- ], UIGroup.prototype, "_interactive", void 0);
255
- __decorate([
256
- engine.assignmentClone
257
- ], UIGroup.prototype, "_ignoreParentGroup", void 0);
258
- __decorate([
259
- engine.ignoreClone
260
- ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
655
+ return UITransform;
656
+ }(engine.Transform);
261
657
  __decorate([
262
658
  engine.ignoreClone
263
- ], UIGroup.prototype, "_groupListeningEntities", void 0);
659
+ ], UITransform.prototype, "_size", void 0);
264
660
  __decorate([
265
661
  engine.ignoreClone
266
- ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
662
+ ], UITransform.prototype, "_pivot", void 0);
267
663
  __decorate([
268
664
  engine.ignoreClone
269
- ], UIGroup.prototype, "_isGroupDirty", void 0);
665
+ ], UITransform.prototype, "_onPositionChanged", null);
270
666
  __decorate([
271
667
  engine.ignoreClone
272
- ], UIGroup.prototype, "_groupDirtyFlags", void 0);
668
+ ], UITransform.prototype, "_onWorldPositionChanged", null);
273
669
  __decorate([
274
670
  engine.ignoreClone
275
- ], UIGroup.prototype, "_groupListener", null);
671
+ ], UITransform.prototype, "_onSizeChanged", null);
276
672
  __decorate([
277
673
  engine.ignoreClone
278
- ], UIGroup.prototype, "_rootCanvasListener", null);
279
- var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
280
- GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
281
- GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
282
- GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
283
- GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
284
- return GroupModifyFlags;
674
+ ], UITransform.prototype, "_onPivotChanged", null);
675
+ /**
676
+ * @internal
677
+ * extends TransformModifyFlags
678
+ */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
679
+ UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
680
+ UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
681
+ return UITransformModifyFlags;
285
682
  }({});
286
683
 
287
- var Utils = /*#__PURE__*/ function() {
288
- function Utils() {}
289
- Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
290
- if (element._isRootCanvasDirty) return;
291
- element._isRootCanvasDirty = true;
292
- this._registerRootCanvas(element, null);
293
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
684
+ exports.RectMask2D = /*#__PURE__*/ function(Component) {
685
+ _inherits(RectMask2D, Component);
686
+ function RectMask2D(entity) {
687
+ var _this;
688
+ _this = Component.call(this, entity) || this, _this._softness = new engine.Vector2(0, 0), _this._alphaClip = false;
689
+ _this._onSoftnessChanged = _this._onSoftnessChanged.bind(_this);
690
+ // @ts-ignore
691
+ _this._softness._onValueChanged = _this._onSoftnessChanged;
692
+ return _this;
693
+ }
694
+ var _proto = RectMask2D.prototype;
695
+ /**
696
+ * @internal
697
+ */ _proto._getWorldRect = function _getWorldRect(out) {
698
+ var transform = this.entity.transform;
699
+ var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
700
+ if (!width || !height) {
701
+ return false;
702
+ }
703
+ var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
704
+ var left = -width * pivotX;
705
+ var right = width * (1 - pivotX);
706
+ var bottom = -height * pivotY;
707
+ var top = height * (1 - pivotY);
708
+ var worldMatrix = transform.worldMatrix;
709
+ var corner0 = RectMask2D._tempCorner0;
710
+ var corner1 = RectMask2D._tempCorner1;
711
+ var corner2 = RectMask2D._tempCorner2;
712
+ var corner3 = RectMask2D._tempCorner3;
713
+ engine.Vector3.transformCoordinate(corner0.set(left, bottom, 0), worldMatrix, corner0);
714
+ engine.Vector3.transformCoordinate(corner1.set(left, top, 0), worldMatrix, corner1);
715
+ engine.Vector3.transformCoordinate(corner2.set(right, bottom, 0), worldMatrix, corner2);
716
+ engine.Vector3.transformCoordinate(corner3.set(right, top, 0), worldMatrix, corner3);
717
+ var minX = Math.min(corner0.x, corner1.x, corner2.x, corner3.x);
718
+ var minY = Math.min(corner0.y, corner1.y, corner2.y, corner3.y);
719
+ var maxX = Math.max(corner0.x, corner1.x, corner2.x, corner3.x);
720
+ var maxY = Math.max(corner0.y, corner1.y, corner2.y, corner3.y);
721
+ out.set(minX, minY, maxX, maxY);
722
+ return true;
294
723
  };
295
- Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
296
- element._isRootCanvasDirty = false;
297
- this._registerRootCanvas(element, rootCanvas);
298
- var fromEntity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
299
- var _rootCanvas_entity_parent;
300
- var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
301
- this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
724
+ /**
725
+ * @internal
726
+ */ _proto._containsWorldPoint = function _containsWorldPoint(worldPoint) {
727
+ var worldRect = RectMask2D._tempRect;
728
+ if (!this._getWorldRect(worldRect)) {
729
+ return false;
730
+ }
731
+ var x = worldPoint.x, y = worldPoint.y;
732
+ return x >= worldRect.x && x <= worldRect.z && y >= worldRect.y && y <= worldRect.w;
302
733
  };
303
- Utils.cleanRootCanvas = function cleanRootCanvas(element) {
304
- this._registerRootCanvas(element, null);
305
- this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
734
+ // @ts-ignore
735
+ _proto._onEnableInScene = function _onEnableInScene() {
736
+ this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
306
737
  };
307
- Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
308
- var entity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
309
- while(entity){
310
- // @ts-ignore
311
- var components = entity._components;
312
- for(var i = 0, n = components.length; i < n; i++){
313
- var component = components[i];
314
- if (component.enabled && _instanceof(component, exports.UICanvas) && component._isRootCanvas) {
315
- return component;
316
- }
317
- }
318
- entity = entity.parent;
319
- }
320
- return null;
321
- };
322
- Utils.setGroupDirty = function setGroupDirty(element) {
323
- if (element._isGroupDirty) return;
324
- element._isGroupDirty = true;
325
- this._registerGroup(element, null);
326
- element._onGroupModify(GroupModifyFlags.All);
327
- };
328
- Utils.setGroup = function setGroup(element, group) {
329
- element._isGroupDirty = false;
330
- this._registerGroup(element, group);
331
- var rootCanvas = element._getRootCanvas();
332
- if (rootCanvas) {
333
- var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
334
- var _group_entity;
335
- var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
336
- this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
337
- } else {
338
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
339
- }
340
- };
341
- Utils.cleanGroup = function cleanGroup(element) {
342
- this._registerGroup(element, null);
343
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
344
- };
345
- Utils.searchGroupInParents = function searchGroupInParents(element) {
346
- var rootCanvas = element._getRootCanvas();
347
- if (!rootCanvas) return null;
348
- var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
349
- var rootCanvasParent = rootCanvas.entity.parent;
350
- while(entity && entity !== rootCanvasParent){
351
- // @ts-ignore
352
- var components = entity._components;
353
- for(var i = 0, n = components.length; i < n; i++){
354
- var component = components[i];
355
- if (component.enabled && _instanceof(component, UIGroup)) {
356
- return component;
357
- }
358
- }
359
- entity = entity.parent;
360
- }
361
- return null;
362
- };
363
- Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
364
- var preCanvas = element._rootCanvas;
365
- if (preCanvas !== canvas) {
366
- if (preCanvas) {
367
- var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
368
- replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
369
- element._indexInRootCanvas = -1;
370
- }
371
- if (canvas) {
372
- var disorderedElements = canvas._disorderedElements;
373
- element._indexInRootCanvas = disorderedElements.length;
374
- disorderedElements.add(element);
375
- }
376
- element._rootCanvas = canvas;
377
- }
378
- };
379
- Utils._registerGroup = function _registerGroup(element, group) {
380
- var preGroup = element._group;
381
- if (preGroup !== group) {
382
- if (preGroup) {
383
- var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
384
- replaced && (replaced._indexInGroup = element._indexInGroup);
385
- element._indexInGroup = -1;
386
- }
387
- if (group) {
388
- var disorderedElements = group._disorderedElements;
389
- element._indexInGroup = disorderedElements.length;
390
- disorderedElements.add(element);
391
- }
392
- element._group = group;
393
- element._onGroupModify(GroupModifyFlags.All);
394
- }
395
- };
396
- Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
397
- var count = 0;
398
- while(entity && entity !== root){
399
- var preEntity = listeningEntities[count];
400
- if (preEntity !== entity) {
401
- // @ts-ignore
402
- preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
403
- listeningEntities[count] = entity;
404
- // @ts-ignore
405
- entity._registerModifyListener(listener);
406
- }
407
- entity = entity.parent;
408
- count++;
409
- }
410
- listeningEntities.length = count;
411
- };
412
- Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
413
- for(var i = 0, n = listeningEntities.length; i < n; i++){
414
- // @ts-ignore
415
- listeningEntities[i]._unRegisterModifyListener(listener);
416
- }
417
- listeningEntities.length = 0;
418
- };
419
- return Utils;
420
- }();
421
-
422
- /**
423
- * @internal
424
- * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
425
- *
426
- * Think of it as stacking elements onto numbered shelves (depths):
427
- * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
428
- * - Overlapping + batch-compatible — share the same shelf, still cluster.
429
- * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
430
- *
431
- * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
432
- * share the same depth and get clustered together. Once depth is assigned, sort by
433
- * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
434
- * by-product of materials clustering within each depth band.
435
- *
436
- * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
437
- * are derived from the union AABB of input elements (the bounds transform itself is the
438
- * work the loop must do anyway, so the union accumulation just piggybacks). This stays
439
- * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
440
- * on canvas configuration.
441
- */ var UIBatchSorter = /*#__PURE__*/ function() {
442
- function UIBatchSorter() {}
443
- /**
444
- * Reorders `elements` in place for optimal batching.
445
- * @param elements - in hierarchy order (depth-first traversal); mutated in place
446
- * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
447
- */ UIBatchSorter.sort = function sort(elements, canvasWorldMatrix) {
448
- var count = elements.length;
449
- if (count <= 1) return;
450
- var gridDim = this._gridDim;
451
- var entries = this._entries;
452
- var grid = this._grid;
453
- var dirtyCells = this._dirtyCells;
454
- var localBoundsPool = this._localBoundsPool;
455
- var worldToLocal = this._worldToLocal;
456
- engine.Matrix.invert(canvasWorldMatrix, worldToLocal);
457
- while(entries.length < count)entries.push(new SortEntry());
458
- // Allocate grid once, reuse forever (each cell must be a real [], not a sparse hole)
459
- if (grid.length < gridDim) {
460
- while(grid.length < gridDim)grid.push([]);
461
- for(var i = 0; i < gridDim; i++){
462
- var row = grid[i];
463
- while(row.length < gridDim)row.push([]);
464
- }
465
- }
466
- // Clear only previously-used cells (no full sweep)
467
- for(var k = 0, n = dirtyCells.length; k < n; k += 2){
468
- grid[dirtyCells[k]][dirtyCells[k + 1]].length = 0;
469
- }
470
- dirtyCells.length = 0;
471
- // Pass 1: transform world bounds to canvas-local + accumulate the union AABB.
472
- // Transform is already required to do precise overlap, so the union accumulation
473
- // is essentially free — just a few minmax compares riding on the existing pass
474
- var unionMinX = Infinity;
475
- var unionMinY = Infinity;
476
- var unionMaxX = -Infinity;
477
- var unionMaxY = -Infinity;
478
- for(var i1 = 0; i1 < count; i1++){
479
- var _localBoundsPool, _i;
480
- var localBounds = (_localBoundsPool = localBoundsPool)[_i = i1] || (_localBoundsPool[_i] = new engine.BoundingBox());
481
- engine.BoundingBox.transform(elements[i1].component.bounds, worldToLocal, localBounds);
482
- var min = localBounds.min, max = localBounds.max;
483
- if (min.x < unionMinX) unionMinX = min.x;
484
- if (min.y < unionMinY) unionMinY = min.y;
485
- if (max.x > unionMaxX) unionMaxX = max.x;
486
- if (max.y > unionMaxY) unionMaxY = max.y;
487
- }
488
- // Guard against a degenerate union (all elements collapsed onto a single point /
489
- // axis); the grid then collapses to cell 0 which is semantically correct
490
- var cellSizeX = Math.max(1e-6, unionMaxX - unionMinX) / gridDim;
491
- var cellSizeY = Math.max(1e-6, unionMaxY - unionMinY) / gridDim;
492
- var maxCell = gridDim - 1;
493
- // Pass 2: register each element into grid cells and compute its depth
494
- for(var i2 = 0; i2 < count; i2++){
495
- var element = elements[i2];
496
- var localBounds1 = localBoundsPool[i2];
497
- var materialId = element.material.instanceId;
498
- var textureId = element.texture ? element.texture.instanceId : 0;
499
- // Floor + clamp guards floating-point edge cases (a `max` exactly on the union
500
- // boundary would otherwise produce `gridDim`)
501
- var minCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.x - unionMinX) / cellSizeX)));
502
- var maxCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.x - unionMinX) / cellSizeX)));
503
- var minCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.y - unionMinY) / cellSizeY)));
504
- var maxCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.y - unionMinY) / cellSizeY)));
505
- // Find the deepest overlapping prior, and whether that shelf has any incompatible occupant
506
- var maxDepth = -1;
507
- var maxDepthIncompatible = false;
508
- for(var cellY = minCellY; cellY <= maxCellY; cellY++){
509
- for(var cellX = minCellX; cellX <= maxCellX; cellX++){
510
- var cell = grid[cellX][cellY];
511
- for(var j = 0, m = cell.length; j < m; j++){
512
- var other = cell[j];
513
- if (!UIBatchSorter._rectOverlap(localBounds1, other.bounds)) continue;
514
- var otherDepth = other.depth;
515
- var otherIncompatible = other.materialId !== materialId || other.textureId !== textureId;
516
- if (otherDepth > maxDepth) {
517
- maxDepth = otherDepth;
518
- maxDepthIncompatible = otherIncompatible;
519
- } else if (otherDepth === maxDepth && otherIncompatible) {
520
- maxDepthIncompatible = true;
521
- }
522
- }
523
- }
524
- }
525
- var entry = entries[i2];
526
- entry.element = element;
527
- entry.hierarchyIndex = i2;
528
- // Share the deepest shelf if compatible; bump up one if blocked by an incompatible occupant
529
- entry.depth = maxDepth < 0 ? 0 : maxDepth + (maxDepthIncompatible ? 1 : 0);
530
- entry.materialId = materialId;
531
- entry.textureId = textureId;
532
- entry.bounds = localBounds1;
533
- for(var cellY1 = minCellY; cellY1 <= maxCellY; cellY1++){
534
- for(var cellX1 = minCellX; cellX1 <= maxCellX; cellX1++){
535
- var cell1 = grid[cellX1][cellY1];
536
- if (cell1.length === 0) dirtyCells.push(cellX1, cellY1);
537
- cell1.push(entry);
538
- }
539
- }
540
- }
541
- // @ts-ignore — Utils._quickSort is @internal
542
- engine.Utils._quickSort(entries, 0, count, UIBatchSorter._compareEntries);
543
- for(var i3 = 0; i3 < count; i3++)elements[i3] = entries[i3].element;
544
- };
545
- UIBatchSorter._rectOverlap = function _rectOverlap(a, b) {
546
- 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;
547
- };
548
- UIBatchSorter._compareEntries = function _compareEntries(a, b) {
549
- return a.depth - b.depth || a.materialId - b.materialId || a.textureId - b.textureId || a.hierarchyIndex - b.hierarchyIndex;
550
- };
551
- return UIBatchSorter;
552
- }();
553
- // Spatial-hash is fastest when cell size ≈ typical element size (one element per cell).
554
- // UI elements typically span ~10% of the canvas → 10×10 grid.
555
- UIBatchSorter._gridDim = 10;
556
- UIBatchSorter._entries = new Array();
557
- UIBatchSorter._grid = [];
558
- // Interleaved (x, y) cell coords touched in the previous frame
559
- UIBatchSorter._dirtyCells = new Array();
560
- UIBatchSorter._localBoundsPool = new Array();
561
- UIBatchSorter._worldToLocal = new engine.Matrix();
562
- // materialId/textureId/bounds are flattened from RenderElement to avoid
563
- // multi-hop property access in the hot inner loop and the sort comparator.
564
- var SortEntry = function SortEntry() {
565
- this.hierarchyIndex = 0;
566
- this.depth = 0;
567
- this.materialId = 0;
568
- this.textureId = 0;
569
- };
570
-
571
- /**
572
- * Render mode for ui canvas.
573
- */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
574
- /**
575
- * The UI canvas will be rendered directly onto the screen and adapted to screen space,
576
- * overlaying other rendering elements in the same scene.
577
- * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
578
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
579
- /**
580
- * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
581
- * with all objects rendered by the camera.
582
- * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
583
- * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
584
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
585
- /**
586
- * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
587
- */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
588
- return CanvasRenderMode;
589
- }({});
590
-
591
- /**
592
- * Resolution adaptation mode.
593
- * @remarks Only effective in screen space.
594
- */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
595
- /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
596
- /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
597
- /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
598
- /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
599
- /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
600
- return ResolutionAdaptationMode;
601
- }({});
602
-
603
- /** Horizontal alignment mode. */ var HorizontalAlignmentMode = /*#__PURE__*/ function(HorizontalAlignmentMode) {
604
- /** No horizontal alignment. */ HorizontalAlignmentMode[HorizontalAlignmentMode["None"] = 0] = "None";
605
- /** Left-aligned, `alignLeft` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Left"] = 1] = "Left";
606
- /** Right-aligned, `alignRight` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Right"] = 2] = "Right";
607
- /** Horizontal stretch, `alignLeft` and `alignRight` drive `position.x` and `size.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["LeftAndRight"] = 3] = "LeftAndRight";
608
- /** Center-aligned, `alignCenter` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Center"] = 4] = "Center";
609
- return HorizontalAlignmentMode;
610
- }({});
611
-
612
- /** Vertical alignment mode. */ var VerticalAlignmentMode = /*#__PURE__*/ function(VerticalAlignmentMode) {
613
- /** No vertical alignment. */ VerticalAlignmentMode[VerticalAlignmentMode["None"] = 0] = "None";
614
- /** Top-aligned, `alignTop` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Top"] = 1] = "Top";
615
- /** Bottom-aligned, `alignBottom` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Bottom"] = 2] = "Bottom";
616
- /** Vertical stretch, `alignTop` and `alignBottom` drive `position.y` and `size.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["TopAndBottom"] = 3] = "TopAndBottom";
617
- /** Middle-aligned, `alignMiddle` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Middle"] = 4] = "Middle";
618
- return VerticalAlignmentMode;
619
- }({});
620
-
621
- /**
622
- * The Transform component exclusive to the UI element.
623
- */ var UITransform = /*#__PURE__*/ function(Transform) {
624
- _inherits(UITransform, Transform);
625
- function UITransform(entity) {
626
- var _this;
627
- _this = Transform.call(this, entity) || this, _this._size = new engine.Vector2(100, 100), _this._pivot = new engine.Vector2(0.5, 0.5), _this._rect = new engine.Rect(-50, -50, 100, 100), _this._alignLeft = 0, _this._alignRight = 0, _this._alignCenter = 0, _this._alignTop = 0, _this._alignBottom = 0, _this._alignMiddle = 0, _this._horizontalAlignment = HorizontalAlignmentMode.None, _this._verticalAlignment = VerticalAlignmentMode.None;
628
- _this._onSizeChanged = _this._onSizeChanged.bind(_this);
629
- _this._onPivotChanged = _this._onPivotChanged.bind(_this);
630
- // @ts-ignore
631
- _this._size._onValueChanged = _this._onSizeChanged;
632
- // @ts-ignore
633
- _this._pivot._onValueChanged = _this._onPivotChanged;
634
- return _this;
635
- }
636
- var _proto = UITransform.prototype;
637
- /**
638
- * @internal
639
- */ _proto._parentChange = function _parentChange() {
640
- this._isParentDirty = true;
641
- this._updateWorldFlagWithParentRectChange(engine.TransformModifyFlags.WmWpWeWqWsWus);
738
+ // @ts-ignore
739
+ _proto._onDisableInScene = function _onDisableInScene() {
740
+ this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
642
741
  };
643
742
  // @ts-ignore
644
743
  _proto._cloneTo = function _cloneTo(target) {
744
+ // RectMask2D extends Component directly; Component.prototype 上没有 _cloneTo,
745
+ // 不能 super._cloneTo(target) — 会拿到 undefined 报 "Cannot read properties of undefined (reading 'call')"。
746
+ // (Image/Mask 走 Renderer 链路所以能 super;RectMask2D 不在 Renderer 链路里。)
747
+ var targetSoftness = target._softness;
645
748
  // @ts-ignore
646
- Transform.prototype._cloneTo.call(this, target);
647
- var size = target._size, pivot = target._pivot;
648
- // @ts-ignore
649
- size._onValueChanged = pivot._onValueChanged = null;
650
- size.copyFrom(this._size);
651
- pivot.copyFrom(this._pivot);
652
- // @ts-ignore
653
- size._onValueChanged = target._onSizeChanged;
654
- // @ts-ignore
655
- pivot._onValueChanged = target._onPivotChanged;
656
- };
657
- _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
658
- // `super._onLocalMatrixChanging()` will set `LocalMatrix` dirty flag `false`
659
- // If there is an alignment, `position` and `localMatrix` will be reset again
660
- if (this._horizontalAlignment || this._verticalAlignment) {
661
- this._updatePositionByAlignment();
662
- this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
663
- } else {
664
- Transform.prototype._onLocalMatrixChanging.call(this);
665
- }
666
- };
667
- _proto._onWorldMatrixChanging = function _onWorldMatrixChanging() {
668
- // `super._onWorldMatrixChanging()` will set `WorldMatrix` dirty flag `false`
669
- // If there is an alignment, `position` and `worldMatrix` will be reset again(`worldMatrix` dirty flag is already `true`)
670
- !this._horizontalAlignment && !this._verticalAlignment && Transform.prototype._onWorldMatrixChanging.call(this);
671
- };
672
- _proto._onPositionChanged = function _onPositionChanged() {
673
- (this._horizontalAlignment || this._verticalAlignment) && this._updatePositionByAlignment();
674
- Transform.prototype._onPositionChanged.call(this);
675
- };
676
- _proto._onWorldPositionChanged = function _onWorldPositionChanged() {
677
- Transform.prototype._onWorldPositionChanged.call(this);
678
- if (this._horizontalAlignment || this._verticalAlignment) {
679
- this._setDirtyFlagTrue(engine.TransformModifyFlags.WorldPosition);
680
- }
681
- };
682
- _proto._updatePositionByAlignment = function _updatePositionByAlignment() {
683
- var _this__getParentTransform;
684
- var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
685
- if (parentRect) {
686
- var position = this.position;
687
- // @ts-ignore
688
- position._onValueChanged = null;
689
- var rect = this._rect;
690
- switch(this._horizontalAlignment){
691
- case HorizontalAlignmentMode.Left:
692
- case HorizontalAlignmentMode.LeftAndRight:
693
- position.x = parentRect.x - rect.x + this._alignLeft;
694
- break;
695
- case HorizontalAlignmentMode.Center:
696
- position.x = parentRect.x + parentRect.width * 0.5 - rect.x - rect.width * 0.5 + this._alignCenter;
697
- break;
698
- case HorizontalAlignmentMode.Right:
699
- position.x = parentRect.x + parentRect.width - rect.x - rect.width - this._alignRight;
700
- break;
701
- }
702
- switch(this._verticalAlignment){
703
- case VerticalAlignmentMode.Top:
704
- position.y = parentRect.y + parentRect.height - rect.y - rect.height - this._alignTop;
705
- break;
706
- case VerticalAlignmentMode.Middle:
707
- position.y = parentRect.y + parentRect.height * 0.5 - rect.y - rect.height * 0.5 + this._alignMiddle;
708
- break;
709
- case VerticalAlignmentMode.Bottom:
710
- case VerticalAlignmentMode.TopAndBottom:
711
- position.y = parentRect.y - rect.y + this._alignBottom;
712
- break;
713
- }
714
- // @ts-ignore
715
- position._onValueChanged = this._onPositionChanged;
716
- }
717
- };
718
- _proto._updateSizeByAlignment = function _updateSizeByAlignment() {
719
- var _this__getParentTransform;
720
- var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
721
- if (parentRect) {
722
- var size = this._size;
723
- // @ts-ignore
724
- size._onValueChanged = null;
725
- // The values of size must be greater than 0
726
- if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight) {
727
- size.x = Math.max(parentRect.width - this._alignLeft - this._alignRight, 0);
728
- }
729
- if (this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
730
- size.y = Math.max(parentRect.height - this._alignTop - this._alignBottom, 0);
731
- }
732
- // @ts-ignore
733
- size._onValueChanged = this._onSizeChanged;
734
- }
735
- };
736
- _proto._updateRectBySizeAndPivot = function _updateRectBySizeAndPivot() {
737
- var _this = this, size = _this.size, pivot = _this._pivot;
738
- var x = -pivot.x * size.x;
739
- var y = -pivot.y * size.y;
740
- this._rect.set(x, y, size.x, size.y);
741
- };
742
- _proto._onSizeChanged = function _onSizeChanged() {
743
- if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
744
- this._updateSizeByAlignment();
745
- }
746
- this._updateRectBySizeAndPivot();
747
- this._updateWorldFlagWithSelfRectChange();
748
- // @ts-ignore
749
- this._entity._updateFlagManager.dispatch(512);
750
- };
751
- _proto._onPivotChanged = function _onPivotChanged() {
752
- this._updateRectBySizeAndPivot();
753
- this._updateWorldFlagWithSelfRectChange();
754
- // @ts-ignore
755
- this._entity._updateFlagManager.dispatch(1024);
756
- };
757
- _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
758
- var worldFlags = 0;
759
- if (this._horizontalAlignment || this._verticalAlignment) {
760
- this._updatePositionByAlignment();
761
- this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
762
- worldFlags = engine.TransformModifyFlags.WmWp;
763
- !this._isContainDirtyFlags(worldFlags) && this._worldAssociatedChange(worldFlags);
764
- }
765
- var children = this.entity.children;
766
- for(var i = 0, n = children.length; i < n; i++){
767
- var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
768
- (_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, worldFlags);
769
- }
770
- };
771
- _proto._updateWorldFlagWithParentRectChange = function _updateWorldFlagWithParentRectChange(flags, parentChange) {
772
- if (parentChange === void 0) parentChange = true;
773
- var selfChange = false;
774
- if (parentChange) {
775
- var _this = this, horizontalAlignment = _this._horizontalAlignment, verticalAlignment = _this._verticalAlignment;
776
- if (horizontalAlignment || verticalAlignment) {
777
- if (horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
778
- this._updateSizeByAlignment();
779
- this._updateRectBySizeAndPivot();
780
- selfChange = true;
781
- }
782
- this._updatePositionByAlignment();
783
- this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
784
- flags |= engine.TransformModifyFlags.WmWp;
785
- }
786
- }
787
- var containDirtyFlags = this._isContainDirtyFlags(flags);
788
- !containDirtyFlags && this._worldAssociatedChange(flags);
789
- if (selfChange || !containDirtyFlags) {
790
- var children = this.entity.children;
791
- for(var i = 0, n = children.length; i < n; i++){
792
- var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
793
- (_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);
794
- }
795
- }
796
- // @ts-ignore
797
- selfChange && this._entity._updateFlagManager.dispatch(512);
798
- };
799
- _create_class(UITransform, [
800
- {
801
- key: "size",
802
- get: /**
803
- * Width and height of UI element.
804
- */ function get() {
805
- return this._size;
806
- },
807
- set: function set(value) {
808
- var _this = this, size = _this._size;
809
- if (size === value) return;
810
- (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
811
- }
812
- },
813
- {
814
- key: "pivot",
815
- get: /**
816
- * Pivot of UI element.
817
- */ function get() {
818
- return this._pivot;
819
- },
820
- set: function set(value) {
821
- var _this = this, pivot = _this._pivot;
822
- if (pivot === value) return;
823
- (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
824
- }
825
- },
826
- {
827
- key: "horizontalAlignment",
828
- get: /**
829
- * Horizontal alignment mode.
830
- *
831
- * @remarks
832
- * Controls how the element aligns horizontally within its parent:
833
- * - `Left` - Align to parent's left edge
834
- * - `Center` - Align to parent's horizontal center
835
- * - `Right` - Align to parent's right edge
836
- * - `LeftAndRight` - Align to both left and right edges (stretch to fill width)
837
- */ function get() {
838
- return this._horizontalAlignment;
839
- },
840
- set: function set(value) {
841
- if (this._horizontalAlignment === value) return;
842
- this._horizontalAlignment = value;
843
- switch(value){
844
- case HorizontalAlignmentMode.Left:
845
- case HorizontalAlignmentMode.Right:
846
- case HorizontalAlignmentMode.Center:
847
- this._onPositionChanged();
848
- break;
849
- case HorizontalAlignmentMode.LeftAndRight:
850
- this._onPositionChanged();
851
- this._onSizeChanged();
852
- break;
853
- }
854
- }
855
- },
856
- {
857
- key: "alignLeft",
858
- get: /**
859
- * Left margin when horizontalAlignment is Left or LeftAndRight.
860
- *
861
- * @remarks
862
- * Only effective when horizontalAlignment includes Left mode.
863
- * Distance from the parent's left edge to the element's left edge.
864
- */ function get() {
865
- return this._alignLeft;
866
- },
867
- set: function set(value) {
868
- if (!Number.isFinite(value)) return;
869
- if (engine.MathUtil.equals(value, this._alignLeft)) return;
870
- this._alignLeft = value;
871
- if (this._horizontalAlignment & HorizontalAlignmentMode.Left) {
872
- this._onPositionChanged();
873
- this._horizontalAlignment & HorizontalAlignmentMode.Right && this._onSizeChanged();
874
- }
875
- }
876
- },
877
- {
878
- key: "alignRight",
879
- get: /**
880
- * Right margin when horizontalAlignment is Right or LeftAndRight.
881
- *
882
- * @remarks
883
- * Only effective when horizontalAlignment includes Right mode.
884
- * Distance from the parent's right edge to the element's right edge.
885
- */ function get() {
886
- return this._alignRight;
887
- },
888
- set: function set(value) {
889
- if (!Number.isFinite(value)) return;
890
- if (engine.MathUtil.equals(value, this._alignRight)) return;
891
- this._alignRight = value;
892
- if (this._horizontalAlignment & HorizontalAlignmentMode.Right) {
893
- this._onPositionChanged();
894
- this._horizontalAlignment & HorizontalAlignmentMode.Left && this._onSizeChanged();
895
- }
896
- }
897
- },
749
+ targetSoftness._onValueChanged = null;
750
+ targetSoftness.copyFrom(this._softness);
751
+ target._clampSoftness();
752
+ // @ts-ignore
753
+ targetSoftness._onValueChanged = target._onSoftnessChanged;
754
+ };
755
+ _proto._onDestroy = function _onDestroy() {
756
+ // @ts-ignore
757
+ this._softness._onValueChanged = null;
758
+ this._softness = null;
759
+ Component.prototype._onDestroy.call(this);
760
+ };
761
+ _proto._onSoftnessChanged = function _onSoftnessChanged() {
762
+ this._clampSoftness();
763
+ };
764
+ _proto._clampSoftness = function _clampSoftness() {
765
+ var softness = this._softness;
766
+ if (softness.x < 0) {
767
+ softness.x = 0;
768
+ }
769
+ if (softness.y < 0) {
770
+ softness.y = 0;
771
+ }
772
+ };
773
+ _create_class(RectMask2D, [
898
774
  {
899
- key: "alignCenter",
775
+ key: "softness",
900
776
  get: /**
901
- * Horizontal center offset when horizontalAlignment is Center.
902
- *
903
- * @remarks
904
- * Only effective when horizontalAlignment is Center mode.
905
- * Positive values move the element to the right, negative values to the left.
777
+ * Soft clipping width on X/Y axis in world space.
906
778
  */ function get() {
907
- return this._alignCenter;
779
+ return this._softness;
908
780
  },
909
781
  set: function set(value) {
910
- if (!Number.isFinite(value)) return;
911
- if (engine.MathUtil.equals(value, this._alignCenter)) return;
912
- this._alignCenter = value;
913
- this._horizontalAlignment & HorizontalAlignmentMode.Center && this._onPositionChanged();
782
+ var softness = this._softness;
783
+ if (softness === value) {
784
+ return;
785
+ }
786
+ if (softness.x !== value.x || softness.y !== value.y) {
787
+ softness.copyFrom(value);
788
+ this._clampSoftness();
789
+ }
914
790
  }
915
791
  },
916
792
  {
917
- key: "verticalAlignment",
793
+ key: "alphaClip",
918
794
  get: /**
919
- * Vertical alignment mode.
920
- *
921
- * @remarks
922
- * Controls how the element aligns vertically within its parent:
923
- * - `Top` - Align to parent's top edge
924
- * - `Middle` - Align to parent's vertical center
925
- * - `Bottom` - Align to parent's bottom edge
926
- * - `TopAndBottom` - Align to both top and bottom edges (stretch to fill height)
795
+ * Whether to enable hard clip (discard) when outside the rect.
927
796
  */ function get() {
928
- return this._verticalAlignment;
797
+ return this._alphaClip;
929
798
  },
930
799
  set: function set(value) {
931
- if (this._verticalAlignment === value) return;
932
- this._verticalAlignment = value;
933
- switch(value){
934
- case VerticalAlignmentMode.Top:
935
- case VerticalAlignmentMode.Bottom:
936
- case VerticalAlignmentMode.Middle:
937
- this._onPositionChanged();
938
- break;
939
- case VerticalAlignmentMode.TopAndBottom:
940
- this._onPositionChanged();
941
- this._onSizeChanged();
942
- break;
943
- }
800
+ this._alphaClip = value;
944
801
  }
945
- },
802
+ }
803
+ ]);
804
+ return RectMask2D;
805
+ }(engine.Component);
806
+ exports.RectMask2D._tempRect = new engine.Vector4();
807
+ exports.RectMask2D._tempCorner0 = new engine.Vector3();
808
+ exports.RectMask2D._tempCorner1 = new engine.Vector3();
809
+ exports.RectMask2D._tempCorner2 = new engine.Vector3();
810
+ exports.RectMask2D._tempCorner3 = new engine.Vector3();
811
+ exports.RectMask2D = __decorate([
812
+ engine.dependentComponents(UITransform, engine.DependentMode.AutoAdd)
813
+ ], exports.RectMask2D);
814
+
815
+ var UIGroup = /*#__PURE__*/ function(Component) {
816
+ _inherits(UIGroup, Component);
817
+ function UIGroup(entity) {
818
+ var _this;
819
+ _this = Component.call(this, entity) || this, /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._disorderedElements = new engine.DisorderedArray(), /** @internal */ _this._globalAlpha = 1, /** @internal */ _this._globalInteractive = true, _this._alpha = 1, _this._interactive = true, _this._ignoreParentGroup = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupDirtyFlags = 0;
820
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
821
+ _this._groupListener = _this._groupListener.bind(_this);
822
+ return _this;
823
+ }
824
+ var _proto = UIGroup.prototype;
825
+ /**
826
+ * @internal
827
+ */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
828
+ if (this._isContainDirtyFlag(1)) {
829
+ if (this._ignoreParentGroup) {
830
+ this._globalAlpha = this._alpha;
831
+ } else {
832
+ var parentGroup = this._getGroup();
833
+ this._globalAlpha = this._alpha * (parentGroup ? parentGroup._getGlobalAlpha() : 1);
834
+ }
835
+ this._setDirtyFlagFalse(1);
836
+ }
837
+ return this._globalAlpha;
838
+ };
839
+ /**
840
+ * @internal
841
+ */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
842
+ if (this._isContainDirtyFlag(2)) {
843
+ if (this._ignoreParentGroup) {
844
+ this._globalInteractive = this._interactive;
845
+ } else {
846
+ var parentGroup = this._getGroup();
847
+ this._globalInteractive = this._interactive && (!parentGroup || parentGroup._getGlobalInteractive());
848
+ }
849
+ this._setDirtyFlagFalse(2);
850
+ }
851
+ return this._globalInteractive;
852
+ };
853
+ // @ts-ignore
854
+ _proto._onEnableInScene = function _onEnableInScene() {
855
+ Utils.setRootCanvasDirty(this);
856
+ Utils.setGroupDirty(this);
857
+ // @ts-ignore
858
+ this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
859
+ };
860
+ // @ts-ignore
861
+ _proto._onDisableInScene = function _onDisableInScene() {
862
+ Utils.cleanRootCanvas(this);
863
+ Utils.cleanGroup(this);
864
+ var disorderedElements = this._disorderedElements;
865
+ disorderedElements.forEach(function(element) {
866
+ Utils.setGroupDirty(element);
867
+ });
868
+ disorderedElements.length = 0;
869
+ disorderedElements.garbageCollection();
870
+ this._isRootCanvasDirty = this._isGroupDirty = false;
871
+ };
872
+ /**
873
+ * @internal
874
+ */ _proto._getRootCanvas = function _getRootCanvas() {
875
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
876
+ return this._rootCanvas;
877
+ };
878
+ /**
879
+ * @internal
880
+ */ _proto._getGroup = function _getGroup() {
881
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
882
+ return this._group;
883
+ };
884
+ /**
885
+ * @internal
886
+ */ _proto._groupListener = function _groupListener(flag) {
887
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
888
+ Utils.setGroupDirty(this);
889
+ }
890
+ };
891
+ /**
892
+ * @internal
893
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
894
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
895
+ Utils.setRootCanvasDirty(this);
896
+ Utils.setGroupDirty(this);
897
+ }
898
+ };
899
+ /**
900
+ * @internal
901
+ */ _proto._onGroupModify = function _onGroupModify(flags, isPass) {
902
+ if (isPass === void 0) isPass = false;
903
+ if (isPass && this._ignoreParentGroup) return;
904
+ if (this._isContainDirtyFlags(flags)) return;
905
+ this._setDirtyFlagTrue(flags);
906
+ this._disorderedElements.forEach(function(element) {
907
+ element._onGroupModify(flags, true);
908
+ });
909
+ };
910
+ _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
911
+ return (this._groupDirtyFlags & targetDirtyFlags) === targetDirtyFlags;
912
+ };
913
+ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
914
+ return (this._groupDirtyFlags & type) != 0;
915
+ };
916
+ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
917
+ this._groupDirtyFlags |= type;
918
+ };
919
+ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
920
+ this._groupDirtyFlags &= ~type;
921
+ };
922
+ _create_class(UIGroup, [
946
923
  {
947
- key: "alignTop",
924
+ key: "ignoreParentGroup",
948
925
  get: /**
949
- * Top margin when verticalAlignment is Top or TopAndBottom.
950
- *
951
- * @remarks
952
- * Only effective when verticalAlignment includes Top mode.
953
- * Used to offset the element from the parent's top edge.
926
+ * Whether to ignore the parent group.
927
+ * @remarks If this parameter set to `true`,
928
+ * all settings of the parent group will be ignored.
954
929
  */ function get() {
955
- return this._alignTop;
930
+ return this._ignoreParentGroup;
956
931
  },
957
932
  set: function set(value) {
958
- if (!Number.isFinite(value)) return;
959
- if (engine.MathUtil.equals(value, this._alignTop)) return;
960
- this._alignTop = value;
961
- if (this._verticalAlignment & VerticalAlignmentMode.Top) {
962
- this._onPositionChanged();
963
- this._verticalAlignment & VerticalAlignmentMode.Bottom && this._onSizeChanged();
933
+ if (this._ignoreParentGroup !== value) {
934
+ this._ignoreParentGroup = value;
935
+ this._onGroupModify(3);
964
936
  }
965
937
  }
966
938
  },
967
939
  {
968
- key: "alignBottom",
940
+ key: "interactive",
969
941
  get: /**
970
- * Bottom inset used in vertical alignment formulas.
942
+ * Whether the group is interactive.
971
943
  */ function get() {
972
- return this._alignBottom;
944
+ return this._interactive;
973
945
  },
974
946
  set: function set(value) {
975
- if (!Number.isFinite(value)) return;
976
- if (engine.MathUtil.equals(value, this._alignBottom)) return;
977
- this._alignBottom = value;
978
- if (this._verticalAlignment & VerticalAlignmentMode.Bottom) {
979
- this._onPositionChanged();
980
- this._verticalAlignment & VerticalAlignmentMode.Top && this._onSizeChanged();
947
+ if (this._interactive !== value) {
948
+ this._interactive = value;
949
+ this._onGroupModify(2);
981
950
  }
982
951
  }
983
952
  },
984
953
  {
985
- key: "alignMiddle",
954
+ key: "alpha",
986
955
  get: /**
987
- * Vertical middle offset relative to parent's middle.
956
+ * The alpha value of the group.
988
957
  */ function get() {
989
- return this._alignMiddle;
958
+ return this._alpha;
990
959
  },
991
960
  set: function set(value) {
992
- if (!Number.isFinite(value)) return;
993
- if (engine.MathUtil.equals(value, this._alignMiddle)) return;
994
- this._alignMiddle = value;
995
- this._verticalAlignment & VerticalAlignmentMode.Middle && this._onPositionChanged();
961
+ value = Math.max(0, Math.min(value, 1));
962
+ if (this._alpha !== value) {
963
+ this._alpha = value;
964
+ this._onGroupModify(1);
965
+ }
996
966
  }
997
967
  }
998
968
  ]);
999
- return UITransform;
1000
- }(engine.Transform);
969
+ return UIGroup;
970
+ }(engine.Component);
1001
971
  __decorate([
1002
972
  engine.ignoreClone
1003
- ], UITransform.prototype, "_size", void 0);
973
+ ], UIGroup.prototype, "_indexInGroup", void 0);
1004
974
  __decorate([
1005
975
  engine.ignoreClone
1006
- ], UITransform.prototype, "_pivot", void 0);
976
+ ], UIGroup.prototype, "_indexInRootCanvas", void 0);
1007
977
  __decorate([
1008
- engine.deepClone
1009
- ], UITransform.prototype, "_rect", void 0);
978
+ engine.ignoreClone
979
+ ], UIGroup.prototype, "_globalAlpha", void 0);
1010
980
  __decorate([
1011
981
  engine.ignoreClone
1012
- ], UITransform.prototype, "_onPositionChanged", null);
982
+ ], UIGroup.prototype, "_globalInteractive", void 0);
1013
983
  __decorate([
1014
984
  engine.ignoreClone
1015
- ], UITransform.prototype, "_onWorldPositionChanged", null);
985
+ ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
1016
986
  __decorate([
1017
987
  engine.ignoreClone
1018
- ], UITransform.prototype, "_onSizeChanged", null);
988
+ ], UIGroup.prototype, "_groupListeningEntities", void 0);
1019
989
  __decorate([
1020
990
  engine.ignoreClone
1021
- ], UITransform.prototype, "_onPivotChanged", null);
1022
- /**
1023
- * @internal
1024
- * extends TransformModifyFlags
1025
- */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
1026
- UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
1027
- UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
1028
- return UITransformModifyFlags;
991
+ ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
992
+ __decorate([
993
+ engine.ignoreClone
994
+ ], UIGroup.prototype, "_isGroupDirty", void 0);
995
+ __decorate([
996
+ engine.ignoreClone
997
+ ], UIGroup.prototype, "_groupDirtyFlags", void 0);
998
+ __decorate([
999
+ engine.ignoreClone
1000
+ ], UIGroup.prototype, "_groupListener", null);
1001
+ __decorate([
1002
+ engine.ignoreClone
1003
+ ], UIGroup.prototype, "_rootCanvasListener", null);
1004
+ var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
1005
+ GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
1006
+ GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
1007
+ GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
1008
+ GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
1009
+ return GroupModifyFlags;
1029
1010
  }({});
1030
1011
 
1031
1012
  exports.UIRenderer = /*#__PURE__*/ function(Renderer) {
@@ -1035,13 +1016,16 @@
1035
1016
  _this = Renderer.call(this, entity) || this, /**
1036
1017
  * Custom boundary for raycast detection.
1037
1018
  * @remarks this is based on `this.entity.transform`.
1038
- */ _this.raycastPadding = new engine.Vector4(0, 0, 0, 0), /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], _this._raycastEnabled = true, _this._color = new engine.Color(1, 1, 1, 1);
1019
+ */ _this.raycastPadding = new engine.Vector4(0, 0, 0, 0), /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._rectMasks = [], /** @internal */ _this._rectMaskRect = new engine.Vector4(), /** @internal */ _this._rectMaskEnabled = false, /** @internal */ _this._rectMaskSoftness = new engine.Vector4(), /** @internal */ _this._rectMaskHardClip = false, _this._raycastEnabled = false, _this._color = new engine.Color(1, 1, 1, 1);
1039
1020
  _this._dirtyUpdateFlag = engine.RendererUpdateFlags.WorldVolume | 2;
1040
1021
  _this._onColorChanged = _this._onColorChanged.bind(_this);
1041
1022
  //@ts-ignore
1042
1023
  _this._color._onValueChanged = _this._onColorChanged;
1043
1024
  _this._groupListener = _this._groupListener.bind(_this);
1044
1025
  _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1026
+ _this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 0);
1027
+ _this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, _this._rectMaskSoftness);
1028
+ _this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, 0);
1045
1029
  return _this;
1046
1030
  }
1047
1031
  var _proto = UIRenderer.prototype;
@@ -1064,6 +1048,7 @@
1064
1048
  if (this._renderFrameCount !== this.engine.time.frameCount) {
1065
1049
  this._update(context);
1066
1050
  }
1051
+ this._updateRectMaskClipState();
1067
1052
  this._render(context);
1068
1053
  // union camera global macro and renderer macro.
1069
1054
  engine.ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
@@ -1142,6 +1127,15 @@
1142
1127
  };
1143
1128
  /**
1144
1129
  * @internal
1130
+ */ _proto._setRectMasks = function _setRectMasks(rectMasks, count) {
1131
+ var targetMasks = this._rectMasks;
1132
+ targetMasks.length = count;
1133
+ for(var i = 0; i < count; i++){
1134
+ targetMasks[i] = rectMasks[i];
1135
+ }
1136
+ };
1137
+ /**
1138
+ * @internal
1145
1139
  */ _proto._raycast = function _raycast(ray, out, distance) {
1146
1140
  if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1147
1141
  var plane = UIRenderer._tempPlane;
@@ -1155,7 +1149,7 @@
1155
1149
  engine.Matrix.invert(transform.worldMatrix, worldMatrixInv);
1156
1150
  var localPosition = UIRenderer._tempVec31;
1157
1151
  engine.Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, localPosition);
1158
- if (this._hitTest(localPosition)) {
1152
+ if (this._hitTest(localPosition) && this._isRaycastVisibleByRectMask(hitPointWorld) && this._isRaycastVisibleByMask(hitPointWorld)) {
1159
1153
  out.component = this;
1160
1154
  out.distance = curDistance;
1161
1155
  out.entity = this.entity;
@@ -1174,6 +1168,127 @@
1174
1168
  var _this_raycastPadding = this.raycastPadding, paddingLeft = _this_raycastPadding.x, paddingBottom = _this_raycastPadding.y, paddingRight = _this_raycastPadding.z, paddingTop = _this_raycastPadding.w;
1175
1169
  return x >= -width * pivotX + paddingLeft && x <= width * (1 - pivotX) - paddingRight && y >= -height * pivotY + paddingTop && y <= height * (1 - pivotY) - paddingBottom;
1176
1170
  };
1171
+ _proto._isRaycastVisibleByMask = function _isRaycastVisibleByMask(hitPointWorld) {
1172
+ var maskInteraction = this._maskInteraction;
1173
+ if (maskInteraction === engine.SpriteMaskInteraction.None) {
1174
+ return true;
1175
+ }
1176
+ // @ts-ignore
1177
+ return this.scene._maskManager.isVisibleByMask(maskInteraction, this._maskLayer, hitPointWorld);
1178
+ };
1179
+ _proto._isRaycastVisibleByRectMask = function _isRaycastVisibleByRectMask(hitPointWorld) {
1180
+ var rectMasks = this._rectMasks;
1181
+ for(var i = 0, n = rectMasks.length; i < n; i++){
1182
+ var rectMask = rectMasks[i];
1183
+ if (!rectMask.enabled || !rectMask.entity.isActiveInHierarchy) {
1184
+ continue;
1185
+ }
1186
+ if (!rectMask._containsWorldPoint(hitPointWorld)) {
1187
+ return false;
1188
+ }
1189
+ }
1190
+ return true;
1191
+ };
1192
+ _proto._updateRectMaskClipState = function _updateRectMaskClipState() {
1193
+ var rectMasks = this._rectMasks;
1194
+ var count = rectMasks.length;
1195
+ if (count <= 0) {
1196
+ this._resetRectMaskClipState();
1197
+ return;
1198
+ }
1199
+ var minX = Number.NEGATIVE_INFINITY;
1200
+ var minY = Number.NEGATIVE_INFINITY;
1201
+ var maxX = Number.POSITIVE_INFINITY;
1202
+ var maxY = Number.POSITIVE_INFINITY;
1203
+ var clipSoftnessLeft = 0;
1204
+ var clipSoftnessBottom = 0;
1205
+ var clipSoftnessRight = 0;
1206
+ var clipSoftnessTop = 0;
1207
+ var clipHardClip = false;
1208
+ var hasActiveMask = false;
1209
+ var tempRect = UIRenderer._tempRect;
1210
+ for(var i = 0; i < count; i++){
1211
+ var rectMask = rectMasks[i];
1212
+ if (!rectMask.enabled || !rectMask.entity.isActiveInHierarchy) {
1213
+ continue;
1214
+ }
1215
+ hasActiveMask = true;
1216
+ var softness = rectMask.softness;
1217
+ if (!clipHardClip && rectMask.alphaClip) {
1218
+ clipHardClip = true;
1219
+ }
1220
+ if (!rectMask._getWorldRect(tempRect)) {
1221
+ minX = 1;
1222
+ minY = 1;
1223
+ maxX = 0;
1224
+ maxY = 0;
1225
+ break;
1226
+ }
1227
+ if (tempRect.x > minX) {
1228
+ minX = tempRect.x;
1229
+ clipSoftnessLeft = softness.x;
1230
+ }
1231
+ if (tempRect.y > minY) {
1232
+ minY = tempRect.y;
1233
+ clipSoftnessBottom = softness.y;
1234
+ }
1235
+ if (tempRect.z < maxX) {
1236
+ maxX = tempRect.z;
1237
+ clipSoftnessRight = softness.x;
1238
+ }
1239
+ if (tempRect.w < maxY) {
1240
+ maxY = tempRect.w;
1241
+ clipSoftnessTop = softness.y;
1242
+ }
1243
+ }
1244
+ if (!hasActiveMask) {
1245
+ this._resetRectMaskClipState();
1246
+ return;
1247
+ }
1248
+ if (minX >= maxX || minY >= maxY) {
1249
+ minX = 1;
1250
+ minY = 1;
1251
+ maxX = 0;
1252
+ maxY = 0;
1253
+ clipSoftnessLeft = 0;
1254
+ clipSoftnessBottom = 0;
1255
+ clipSoftnessRight = 0;
1256
+ clipSoftnessTop = 0;
1257
+ }
1258
+ var rectMaskRect = this._rectMaskRect;
1259
+ if (rectMaskRect.x !== minX || rectMaskRect.y !== minY || rectMaskRect.z !== maxX || rectMaskRect.w !== maxY) {
1260
+ rectMaskRect.set(minX, minY, maxX, maxY);
1261
+ this.shaderData.setVector4(UIRenderer._rectClipRectProperty, rectMaskRect);
1262
+ }
1263
+ var rectMaskSoftness = this._rectMaskSoftness;
1264
+ if (rectMaskSoftness.x !== clipSoftnessLeft || rectMaskSoftness.y !== clipSoftnessBottom || rectMaskSoftness.z !== clipSoftnessRight || rectMaskSoftness.w !== clipSoftnessTop) {
1265
+ rectMaskSoftness.set(clipSoftnessLeft, clipSoftnessBottom, clipSoftnessRight, clipSoftnessTop);
1266
+ this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, rectMaskSoftness);
1267
+ }
1268
+ if (this._rectMaskHardClip !== clipHardClip) {
1269
+ this._rectMaskHardClip = clipHardClip;
1270
+ this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, clipHardClip ? 1 : 0);
1271
+ }
1272
+ if (!this._rectMaskEnabled) {
1273
+ this._rectMaskEnabled = true;
1274
+ this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 1);
1275
+ }
1276
+ };
1277
+ _proto._resetRectMaskClipState = function _resetRectMaskClipState() {
1278
+ if (this._rectMaskEnabled) {
1279
+ this._rectMaskEnabled = false;
1280
+ this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 0);
1281
+ }
1282
+ var rectMaskSoftness = this._rectMaskSoftness;
1283
+ if (rectMaskSoftness.x !== 0 || rectMaskSoftness.y !== 0 || rectMaskSoftness.z !== 0 || rectMaskSoftness.w !== 0) {
1284
+ rectMaskSoftness.set(0, 0, 0, 0);
1285
+ this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, rectMaskSoftness);
1286
+ }
1287
+ if (this._rectMaskHardClip) {
1288
+ this._rectMaskHardClip = false;
1289
+ this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, 0);
1290
+ }
1291
+ };
1177
1292
  _proto._onDestroy = function _onDestroy() {
1178
1293
  if (this._subChunk) {
1179
1294
  this._getChunkManager().freeSubChunk(this._subChunk);
@@ -1183,6 +1298,8 @@
1183
1298
  //@ts-ignore
1184
1299
  this._color._onValueChanged = null;
1185
1300
  this._color = null;
1301
+ this._rectMasks = null;
1302
+ this._rectMaskSoftness = null;
1186
1303
  };
1187
1304
  _create_class(UIRenderer, [
1188
1305
  {
@@ -1198,6 +1315,30 @@
1198
1315
  }
1199
1316
  }
1200
1317
  },
1318
+ {
1319
+ key: "maskLayer",
1320
+ get: /**
1321
+ * The mask layer the ui renderer belongs to.
1322
+ */ function get() {
1323
+ return this._maskLayer;
1324
+ },
1325
+ set: function set(value) {
1326
+ this._maskLayer = value;
1327
+ }
1328
+ },
1329
+ {
1330
+ key: "maskInteraction",
1331
+ get: /**
1332
+ * Interacts with the masks.
1333
+ */ function get() {
1334
+ return this._maskInteraction;
1335
+ },
1336
+ set: function set(value) {
1337
+ if (this._maskInteraction !== value) {
1338
+ this._maskInteraction = value;
1339
+ }
1340
+ }
1341
+ },
1201
1342
  {
1202
1343
  key: "raycastEnabled",
1203
1344
  get: /**
@@ -1212,14 +1353,17 @@
1212
1353
  ]);
1213
1354
  return UIRenderer;
1214
1355
  }(engine.Renderer);
1356
+ /** @internal */ exports.UIRenderer._tempVec20 = new engine.Vector2();
1215
1357
  /** @internal */ exports.UIRenderer._tempVec30 = new engine.Vector3();
1216
1358
  /** @internal */ exports.UIRenderer._tempVec31 = new engine.Vector3();
1217
1359
  /** @internal */ exports.UIRenderer._tempMat = new engine.Matrix();
1218
1360
  /** @internal */ exports.UIRenderer._tempPlane = new engine.Plane();
1219
1361
  /** @internal */ exports.UIRenderer._textureProperty = engine.ShaderProperty.getByName("renderer_UITexture");
1220
- __decorate([
1221
- engine.deepClone
1222
- ], exports.UIRenderer.prototype, "raycastPadding", void 0);
1362
+ /** @internal */ exports.UIRenderer._rectClipRectProperty = engine.ShaderProperty.getByName("renderer_UIRectClipRect");
1363
+ /** @internal */ exports.UIRenderer._rectClipEnabledProperty = engine.ShaderProperty.getByName("renderer_UIRectClipEnabled");
1364
+ /** @internal */ exports.UIRenderer._rectClipSoftnessProperty = engine.ShaderProperty.getByName("renderer_UIRectClipSoftness");
1365
+ /** @internal */ exports.UIRenderer._rectClipHardClipProperty = engine.ShaderProperty.getByName("renderer_UIRectClipHardClip");
1366
+ /** @internal */ exports.UIRenderer._tempRect = new engine.Vector4();
1223
1367
  __decorate([
1224
1368
  engine.ignoreClone
1225
1369
  ], exports.UIRenderer.prototype, "_indexInRootCanvas", void 0);
@@ -1242,11 +1386,20 @@
1242
1386
  engine.ignoreClone
1243
1387
  ], exports.UIRenderer.prototype, "_subChunk", void 0);
1244
1388
  __decorate([
1245
- engine.assignmentClone
1246
- ], exports.UIRenderer.prototype, "_raycastEnabled", void 0);
1389
+ engine.ignoreClone
1390
+ ], exports.UIRenderer.prototype, "_rectMasks", void 0);
1391
+ __decorate([
1392
+ engine.ignoreClone
1393
+ ], exports.UIRenderer.prototype, "_rectMaskRect", void 0);
1394
+ __decorate([
1395
+ engine.ignoreClone
1396
+ ], exports.UIRenderer.prototype, "_rectMaskEnabled", void 0);
1397
+ __decorate([
1398
+ engine.ignoreClone
1399
+ ], exports.UIRenderer.prototype, "_rectMaskSoftness", void 0);
1247
1400
  __decorate([
1248
- engine.deepClone
1249
- ], exports.UIRenderer.prototype, "_color", void 0);
1401
+ engine.ignoreClone
1402
+ ], exports.UIRenderer.prototype, "_rectMaskHardClip", void 0);
1250
1403
  __decorate([
1251
1404
  engine.ignoreClone
1252
1405
  ], exports.UIRenderer.prototype, "_groupListener", null);
@@ -1266,906 +1419,1077 @@
1266
1419
  return UIRendererUpdateFlags;
1267
1420
  }({});
1268
1421
 
1269
- /**
1270
- * Interactive component.
1271
- */ var UIInteractive = /*#__PURE__*/ function(Script) {
1272
- _inherits(UIInteractive, Script);
1273
- function UIInteractive(entity) {
1422
+ exports.UICanvas = /*#__PURE__*/ function(Component) {
1423
+ _inherits(UICanvas, Component);
1424
+ function UICanvas(entity) {
1274
1425
  var _this;
1275
- _this = Script.call(this, entity) || this, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._globalInteractive = false, /** @internal */ _this._globalInteractiveDirty = false, _this._transitions = [], _this._interactive = true, _this._state = 0, /** @todo Multi-touch points are not considered yet. */ _this._isPointerInside = false, _this._isPointerDragging = false;
1276
- _this._groupListener = _this._groupListener.bind(_this);
1426
+ _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();
1427
+ _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1428
+ _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1429
+ _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1430
+ _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1431
+ // @ts-ignore
1432
+ _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1277
1433
  _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1434
+ _this._centerDirtyFlag = entity.registerWorldChangeFlag();
1278
1435
  return _this;
1279
1436
  }
1280
- var _proto = UIInteractive.prototype;
1437
+ var _proto = UICanvas.prototype;
1281
1438
  /**
1282
- * Add transition on this interactive.
1283
- * @param transition - The transition
1284
- */ _proto.addTransition = function addTransition(transition) {
1285
- var interactive = transition._interactive;
1286
- if (interactive !== this) {
1287
- interactive == null ? void 0 : interactive.removeTransition(transition);
1288
- this._transitions.push(transition);
1289
- transition._interactive = this;
1290
- transition._setState(this._state, true);
1439
+ * @internal
1440
+ */ _proto._raycast = function _raycast(ray, out, distance) {
1441
+ if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1442
+ var renderers = this._getRenderers();
1443
+ for(var i = renderers.length - 1; i >= 0; i--){
1444
+ var element = renderers[i];
1445
+ if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1446
+ return true;
1447
+ }
1448
+ }
1449
+ out.component = null;
1450
+ out.entity = null;
1451
+ out.distance = 0;
1452
+ out.point.set(0, 0, 0);
1453
+ out.normal.set(0, 0, 0);
1454
+ return false;
1455
+ };
1456
+ /**
1457
+ * @internal
1458
+ */ _proto._getRootCanvas = function _getRootCanvas() {
1459
+ return this._rootCanvas;
1460
+ };
1461
+ /**
1462
+ * @internal
1463
+ */ _proto._canRender = function _canRender(camera) {
1464
+ return this._realRenderMode !== CanvasRenderMode.ScreenSpaceCamera || this._camera === camera;
1465
+ };
1466
+ /**
1467
+ * @internal
1468
+ */ _proto._canDispatchEvent = function _canDispatchEvent(camera) {
1469
+ var realMode = this._realRenderMode;
1470
+ if (realMode === CanvasRenderMode.ScreenSpaceOverlay) {
1471
+ return true;
1472
+ }
1473
+ var assignedCamera = this._camera;
1474
+ // @ts-ignore
1475
+ return !assignedCamera || !assignedCamera._phasedActiveInScene || assignedCamera === camera;
1476
+ };
1477
+ /**
1478
+ * @internal
1479
+ */ _proto._prepareRender = function _prepareRender(context) {
1480
+ var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1481
+ var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1482
+ var frameCount = engine.time.frameCount;
1483
+ var renderElements = this._renderElements;
1484
+ renderElements.length = 0;
1485
+ var virtualCamera = context.virtualCamera;
1486
+ this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1487
+ var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1488
+ var renderers = this._getRenderers();
1489
+ for(var i = 0, n = renderers.length; i < n; i++){
1490
+ var renderer = renderers[i];
1491
+ // Filter by camera culling mask
1492
+ if (!(cullingMask & renderer.entity.layer)) {
1493
+ continue;
1494
+ }
1495
+ // Filter by camera frustum
1496
+ if (enableFrustumCulling) {
1497
+ switch(mode){
1498
+ case CanvasRenderMode.ScreenSpaceOverlay:
1499
+ var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1500
+ if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1501
+ continue;
1502
+ }
1503
+ break;
1504
+ case CanvasRenderMode.ScreenSpaceCamera:
1505
+ case CanvasRenderMode.WorldSpace:
1506
+ if (!frustum.intersectsBox(renderer.bounds)) {
1507
+ continue;
1508
+ }
1509
+ break;
1510
+ }
1511
+ }
1512
+ renderer._prepareRender(context);
1513
+ renderer._renderFrameCount = frameCount;
1514
+ }
1515
+ var batchedRenderElements = this._batchedRenderElements;
1516
+ batchedRenderElements.length = 0;
1517
+ UIBatchSorter.sort(renderElements, this.entity.transform.worldMatrix);
1518
+ engine._batcherManager.batch(renderElements, batchedRenderElements);
1519
+ for(var i1 = 0, n1 = batchedRenderElements.length; i1 < n1; i1++){
1520
+ batchedRenderElements[i1].subDistancePriority = i1;
1521
+ }
1522
+ };
1523
+ /**
1524
+ * @internal
1525
+ */ _proto._updateSortDistance = function _updateSortDistance(isOrthographic, cameraPosition, cameraForward) {
1526
+ switch(this._realRenderMode){
1527
+ case CanvasRenderMode.ScreenSpaceOverlay:
1528
+ this._sortDistance = 0;
1529
+ break;
1530
+ case CanvasRenderMode.ScreenSpaceCamera:
1531
+ this._sortDistance = this._distance;
1532
+ break;
1533
+ case CanvasRenderMode.WorldSpace:
1534
+ var boundsCenter = this._getCenter();
1535
+ if (isOrthographic) {
1536
+ var distance = UICanvas._tempVec3;
1537
+ engine.Vector3.subtract(boundsCenter, cameraPosition, distance);
1538
+ this._sortDistance = engine.Vector3.dot(distance, cameraForward);
1539
+ } else {
1540
+ this._sortDistance = engine.Vector3.distanceSquared(boundsCenter, cameraPosition);
1541
+ }
1542
+ break;
1543
+ }
1544
+ };
1545
+ // @ts-ignore
1546
+ _proto._onEnableInScene = function _onEnableInScene() {
1547
+ var entity = this.entity;
1548
+ // @ts-ignore
1549
+ entity._dispatchModify(4, this);
1550
+ var rootCanvas = Utils.searchRootCanvasInParents(this);
1551
+ this._setIsRootCanvas(!rootCanvas);
1552
+ Utils.setRootCanvas(this, rootCanvas);
1553
+ };
1554
+ // @ts-ignore
1555
+ _proto._onDisableInScene = function _onDisableInScene() {
1556
+ this._setIsRootCanvas(false);
1557
+ Utils.cleanRootCanvas(this);
1558
+ };
1559
+ // @ts-ignore
1560
+ _proto._onDisable = function _onDisable() {
1561
+ this._renderElements.length = 0;
1562
+ this._batchedRenderElements.length = 0;
1563
+ };
1564
+ /**
1565
+ * @internal
1566
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1567
+ if (this._isRootCanvas) {
1568
+ if (flag === engine.EntityModifyFlags.Parent) {
1569
+ var rootCanvas = Utils.searchRootCanvasInParents(this);
1570
+ this._setIsRootCanvas(!rootCanvas);
1571
+ Utils.setRootCanvas(this, rootCanvas);
1572
+ } else if (flag === 4) {
1573
+ this._setIsRootCanvas(false);
1574
+ Utils.setRootCanvas(this, param);
1575
+ }
1576
+ } else {
1577
+ if (flag === engine.EntityModifyFlags.Parent) {
1578
+ var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1579
+ this._setIsRootCanvas(!rootCanvas1);
1580
+ Utils.setRootCanvas(this, rootCanvas1);
1581
+ }
1582
+ }
1583
+ };
1584
+ /**
1585
+ * @internal
1586
+ */ _proto._cloneTo = function _cloneTo(target) {
1587
+ target.renderMode = this._renderMode;
1588
+ };
1589
+ _proto._getRenderers = function _getRenderers() {
1590
+ var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1591
+ var uiHierarchyVersion = entity._uiHierarchyVersion;
1592
+ if (this._hierarchyVersion !== uiHierarchyVersion) {
1593
+ UICanvas._tempRectMaskList.length = 0;
1594
+ renderers.length = this._walk(this.entity, renderers, 0, null, 0);
1595
+ UICanvas._tempGroupAbleList.length = 0;
1596
+ this._hierarchyVersion = uiHierarchyVersion;
1597
+ ++UICanvas._hierarchyCounter;
1598
+ }
1599
+ return renderers;
1600
+ };
1601
+ _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1602
+ var transform = this.entity.transform;
1603
+ var realRenderMode = this._realRenderMode;
1604
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1605
+ var cameraEntity = this._camera.entity;
1606
+ if (!this._isSameOrChildEntity(cameraEntity)) {
1607
+ var cameraTransform = cameraEntity.transform;
1608
+ var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1609
+ var distance = this._distance;
1610
+ transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1611
+ transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
1612
+ }
1613
+ } else {
1614
+ var canvas = this.engine.canvas;
1615
+ transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1616
+ transform.worldRotationQuaternion.set(0, 0, 0, 1);
1291
1617
  }
1292
1618
  };
1293
- /**
1294
- * Remove a transition.
1295
- * @param shape - The transition.
1296
- */ _proto.removeTransition = function removeTransition(transition) {
1297
- var transitions = this._transitions;
1298
- var lastOneIndex = transitions.length - 1;
1299
- for(var i = lastOneIndex; i >= 0; i--){
1300
- if (transitions[i] === transition) {
1301
- i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
1302
- transitions.length = lastOneIndex;
1303
- transition._interactive = null;
1619
+ _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1620
+ var transform = this.entity.transform;
1621
+ var realRenderMode = this._realRenderMode;
1622
+ var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1623
+ var curWidth;
1624
+ var curHeight;
1625
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1626
+ var camera = this._camera;
1627
+ curHeight = camera.isOrthographic ? camera.orthographicSize * 2 : 2 * (Math.tan(engine.MathUtil.degreeToRadian(camera.fieldOfView * 0.5)) * this._distance);
1628
+ curWidth = camera.aspectRatio * curHeight;
1629
+ } else {
1630
+ var canvas = this.engine.canvas;
1631
+ curHeight = canvas.height;
1632
+ curWidth = canvas.width;
1633
+ }
1634
+ var expectX, expectY, expectZ;
1635
+ switch(this._resolutionAdaptationMode){
1636
+ case ResolutionAdaptationMode.WidthAdaptation:
1637
+ expectX = expectY = expectZ = curWidth / width;
1638
+ break;
1639
+ case ResolutionAdaptationMode.HeightAdaptation:
1640
+ expectX = expectY = expectZ = curHeight / height;
1641
+ break;
1642
+ case ResolutionAdaptationMode.BothAdaptation:
1643
+ expectX = curWidth / width;
1644
+ expectY = curHeight / height;
1645
+ expectZ = (expectX + expectY) * 0.5;
1646
+ break;
1647
+ case ResolutionAdaptationMode.ExpandAdaptation:
1648
+ expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1649
+ break;
1650
+ case ResolutionAdaptationMode.ShrinkAdaptation:
1651
+ expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1304
1652
  break;
1305
- }
1306
1653
  }
1654
+ var worldMatrix = UICanvas._tempMat;
1655
+ engine.Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1656
+ transform.worldMatrix = worldMatrix;
1657
+ transform.size.set(curWidth / expectX, curHeight / expectY);
1307
1658
  };
1308
- /**
1309
- * Remove all transitions.
1310
- */ _proto.clearTransitions = function clearTransitions() {
1311
- var transitions = this._transitions;
1312
- for(var i = 0, n = transitions.length; i < n; i++){
1313
- transitions[i]._interactive = null;
1659
+ _proto._walk = function _walk(entity, renderers, depth, group, rectMaskCount) {
1660
+ if (depth === void 0) depth = 0;
1661
+ if (group === void 0) group = null;
1662
+ if (rectMaskCount === void 0) rectMaskCount = 0;
1663
+ // @ts-ignore
1664
+ var components = entity._components;
1665
+ var tempGroupAbleList = UICanvas._tempGroupAbleList;
1666
+ var tempRectMaskList = UICanvas._tempRectMaskList;
1667
+ var rectMask = null;
1668
+ var groupAbleCount = 0;
1669
+ for(var i = 0, n = components.length; i < n; i++){
1670
+ var component = components[i];
1671
+ if (!component.enabled) continue;
1672
+ if (_instanceof(component, exports.UIRenderer)) {
1673
+ renderers[depth] = component;
1674
+ ++depth;
1675
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1676
+ if (component._isGroupDirty) {
1677
+ tempGroupAbleList[groupAbleCount++] = component;
1678
+ }
1679
+ component._setRectMasks(tempRectMaskList, rectMaskCount);
1680
+ } else if (_instanceof(component, UIInteractive)) {
1681
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1682
+ if (component._isGroupDirty) {
1683
+ tempGroupAbleList[groupAbleCount++] = component;
1684
+ }
1685
+ } else if (_instanceof(component, exports.RectMask2D)) {
1686
+ rectMask = component;
1687
+ } else if (_instanceof(component, UIGroup)) {
1688
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1689
+ component._isGroupDirty && Utils.setGroup(component, group);
1690
+ group = component;
1691
+ }
1314
1692
  }
1315
- transitions.length = 0;
1693
+ for(var i1 = 0; i1 < groupAbleCount; i1++){
1694
+ Utils.setGroup(tempGroupAbleList[i1], group);
1695
+ }
1696
+ if (rectMask) {
1697
+ tempRectMaskList[rectMaskCount++] = rectMask;
1698
+ }
1699
+ var children = entity.children;
1700
+ for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1701
+ var child = children[i2];
1702
+ child.isActive && (depth = this._walk(child, renderers, depth, group, rectMaskCount));
1703
+ }
1704
+ return depth;
1316
1705
  };
1317
- _proto.onUpdate = function onUpdate(deltaTime) {
1318
- if (this._getGlobalInteractive()) {
1319
- var transitions = this._transitions;
1320
- for(var i = 0, n = transitions.length; i < n; i++){
1321
- transitions[i]._onUpdate(deltaTime);
1706
+ _proto._updateCameraObserver = function _updateCameraObserver() {
1707
+ var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._camera : null;
1708
+ var preCamera = this._cameraObserver;
1709
+ if (preCamera !== camera) {
1710
+ this._cameraObserver = camera;
1711
+ if (preCamera) {
1712
+ // @ts-ignore
1713
+ preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1714
+ // @ts-ignore
1715
+ preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1716
+ }
1717
+ if (camera) {
1718
+ // @ts-ignore
1719
+ camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1720
+ // @ts-ignore
1721
+ camera._registerModifyListener(this._onCameraModifyListener);
1322
1722
  }
1323
1723
  }
1324
1724
  };
1325
- _proto.onPointerBeginDrag = function onPointerBeginDrag() {
1326
- this._isPointerDragging = true;
1327
- this._updateState(false);
1328
- };
1329
- _proto.onPointerEndDrag = function onPointerEndDrag() {
1330
- this._isPointerDragging = false;
1331
- this._updateState(false);
1332
- };
1333
- _proto.onPointerEnter = function onPointerEnter() {
1334
- this._isPointerInside = true;
1335
- this._updateState(false);
1336
- };
1337
- _proto.onPointerExit = function onPointerExit() {
1338
- this._isPointerInside = false;
1339
- this._updateState(false);
1340
- };
1341
- _proto.onDestroy = function onDestroy() {
1342
- Script.prototype.onDestroy.call(this);
1343
- var transitions = this._transitions;
1344
- for(var i = transitions.length - 1; i >= 0; i--){
1345
- transitions[i].destroy();
1725
+ _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1726
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1727
+ switch(flag){
1728
+ case engine.CameraModifyFlags.ProjectionType:
1729
+ case engine.CameraModifyFlags.AspectRatio:
1730
+ this._adapterSizeInScreenSpace();
1731
+ break;
1732
+ case engine.CameraModifyFlags.FieldOfView:
1733
+ !this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1734
+ break;
1735
+ case engine.CameraModifyFlags.OrthographicSize:
1736
+ this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1737
+ break;
1738
+ case engine.CameraModifyFlags.DisableInScene:
1739
+ this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
1740
+ break;
1741
+ }
1742
+ } else {
1743
+ flag === engine.CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
1346
1744
  }
1347
1745
  };
1348
- /**
1349
- * @internal
1350
- */ _proto._getRootCanvas = function _getRootCanvas() {
1351
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1352
- return this._rootCanvas;
1353
- };
1354
- /**
1355
- * @internal
1356
- */ _proto._getGroup = function _getGroup() {
1357
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1358
- return this._group;
1746
+ _proto._onCameraTransformListener = function _onCameraTransformListener() {
1747
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1359
1748
  };
1360
- // @ts-ignore
1361
- _proto._onEnableInScene = function _onEnableInScene() {
1749
+ _proto._addCanvasListener = function _addCanvasListener() {
1362
1750
  // @ts-ignore
1363
- Script.prototype._onEnableInScene.call(this);
1364
- Utils.setRootCanvasDirty(this);
1365
- Utils.setGroupDirty(this);
1366
- this._updateState(true);
1751
+ this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1367
1752
  };
1368
- // @ts-ignore
1369
- _proto._onDisableInScene = function _onDisableInScene() {
1753
+ _proto._removeCanvasListener = function _removeCanvasListener() {
1370
1754
  // @ts-ignore
1371
- Script.prototype._onDisableInScene.call(this);
1372
- Utils.cleanRootCanvas(this);
1373
- Utils.cleanGroup(this);
1374
- this._isPointerInside = this._isPointerDragging = false;
1755
+ this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1375
1756
  };
1376
- /**
1377
- * @internal
1378
- */ _proto._groupListener = function _groupListener(flag) {
1379
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1380
- Utils.setGroupDirty(this);
1381
- }
1757
+ _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1758
+ var canvas = this.engine.canvas;
1759
+ this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1760
+ this._adapterSizeInScreenSpace();
1382
1761
  };
1383
- /**
1384
- * @internal
1385
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
1386
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
1387
- Utils.setRootCanvasDirty(this);
1388
- Utils.setGroupDirty(this);
1762
+ _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1763
+ var realRenderMode = this._realRenderMode;
1764
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1765
+ this._adapterSizeInScreenSpace();
1389
1766
  }
1390
1767
  };
1391
- /**
1392
- * @internal
1393
- */ _proto._onGroupModify = function _onGroupModify(flags) {
1394
- if (flags & GroupModifyFlags.GlobalInteractive) {
1395
- this._globalInteractiveDirty = true;
1768
+ _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1769
+ var _this = this;
1770
+ if (this._isRootCanvas !== isRootCanvas) {
1771
+ this._isRootCanvas = isRootCanvas;
1772
+ this._updateCameraObserver();
1773
+ this._setRealRenderMode(this._getRealRenderMode());
1774
+ if (isRootCanvas) {
1775
+ this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1776
+ } else {
1777
+ var _this1 = this, disorderedElements = _this1._disorderedElements;
1778
+ disorderedElements.forEach(function(element) {
1779
+ if (_instanceof(element, UICanvas)) {
1780
+ var rootCanvas = Utils.searchRootCanvasInParents(element);
1781
+ element._setIsRootCanvas(!rootCanvas);
1782
+ Utils.setRootCanvas(element, rootCanvas);
1783
+ } else {
1784
+ Utils.setRootCanvasDirty(_this);
1785
+ Utils.setGroupDirty(element);
1786
+ }
1787
+ });
1788
+ disorderedElements.length = 0;
1789
+ disorderedElements.garbageCollection();
1790
+ this._orderedRenderers.length = 0;
1791
+ }
1396
1792
  }
1397
1793
  };
1398
- /**
1399
- * @internal
1400
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
1401
- if (this._globalInteractiveDirty) {
1402
- var group = this._getGroup();
1403
- var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
1404
- if (this._globalInteractive !== globalInteractive) {
1405
- this._globalInteractive = globalInteractive;
1406
- this._updateState(true);
1407
- }
1408
- this._globalInteractiveDirty = false;
1794
+ _proto._getCenter = function _getCenter() {
1795
+ if (this._centerDirtyFlag.flag) {
1796
+ var center = this._center;
1797
+ var uiTransform = this.entity.transform;
1798
+ var pivot = uiTransform.pivot, size = uiTransform.size;
1799
+ center.set((0.5 - pivot.x) * size.x, (0.5 - pivot.y) * size.y, 0);
1800
+ engine.Vector3.transformCoordinate(center, uiTransform.worldMatrix, center);
1801
+ this._centerDirtyFlag.flag = false;
1409
1802
  }
1410
- return this._globalInteractive;
1803
+ return this._center;
1411
1804
  };
1412
- _proto._updateState = function _updateState(instant) {
1413
- var state = this._getInteractiveState();
1414
- if (this._state !== state) {
1415
- this._state = state;
1416
- var transitions = this._transitions;
1417
- for(var i = 0, n = transitions.length; i < n; i++){
1418
- transitions[i]._setState(state, instant);
1805
+ _proto._getRealRenderMode = function _getRealRenderMode() {
1806
+ if (this._isRootCanvas) {
1807
+ var _this__camera;
1808
+ var mode = this._renderMode;
1809
+ // @ts-ignore
1810
+ if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__camera = this._camera) == null ? void 0 : _this__camera._phasedActiveInScene)) {
1811
+ return CanvasRenderMode.ScreenSpaceOverlay;
1812
+ } else {
1813
+ return mode;
1419
1814
  }
1815
+ } else {
1816
+ return 4;
1420
1817
  }
1421
1818
  };
1422
- _proto._getInteractiveState = function _getInteractiveState() {
1423
- if (!this._getGlobalInteractive()) {
1424
- return 3;
1819
+ _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1820
+ var preRealMode = this._realRenderMode;
1821
+ if (preRealMode !== curRealMode) {
1822
+ this._realRenderMode = curRealMode;
1823
+ // @ts-ignore
1824
+ var componentsManager = this.scene._componentsManager;
1825
+ switch(preRealMode){
1826
+ case CanvasRenderMode.ScreenSpaceOverlay:
1827
+ this._removeCanvasListener();
1828
+ case CanvasRenderMode.ScreenSpaceCamera:
1829
+ case CanvasRenderMode.WorldSpace:
1830
+ componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1831
+ break;
1832
+ }
1833
+ switch(curRealMode){
1834
+ case CanvasRenderMode.ScreenSpaceOverlay:
1835
+ this._addCanvasListener();
1836
+ case CanvasRenderMode.ScreenSpaceCamera:
1837
+ this._adapterPoseInScreenSpace();
1838
+ this._adapterSizeInScreenSpace();
1839
+ case CanvasRenderMode.WorldSpace:
1840
+ componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1841
+ break;
1842
+ }
1425
1843
  }
1426
- if (this._isPointerDragging) {
1427
- return 1;
1428
- } else {
1429
- return this._isPointerInside ? 2 : 0;
1844
+ };
1845
+ _proto._isSameOrChildEntity = function _isSameOrChildEntity(cameraEntity) {
1846
+ var canvasEntity = this.entity;
1847
+ while(cameraEntity){
1848
+ if (cameraEntity === canvasEntity) return true;
1849
+ cameraEntity = cameraEntity.parent;
1430
1850
  }
1851
+ return false;
1431
1852
  };
1432
- _create_class(UIInteractive, [
1853
+ _create_class(UICanvas, [
1433
1854
  {
1434
- key: "transitions",
1855
+ key: "referenceResolutionPerUnit",
1435
1856
  get: /**
1436
- * The transitions of this interactive.
1857
+ * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1437
1858
  */ function get() {
1438
- return this._transitions;
1859
+ return this._referenceResolutionPerUnit;
1860
+ },
1861
+ set: function set(value) {
1862
+ if (this._referenceResolutionPerUnit !== value) {
1863
+ this._referenceResolutionPerUnit = value;
1864
+ this._disorderedElements.forEach(function(element) {
1865
+ element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1866
+ });
1867
+ }
1439
1868
  }
1440
1869
  },
1441
1870
  {
1442
- key: "interactive",
1871
+ key: "referenceResolution",
1443
1872
  get: /**
1444
- * Whether the interactive is enabled.
1873
+ * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1445
1874
  */ function get() {
1446
- return this._interactive;
1875
+ return this._referenceResolution;
1447
1876
  },
1448
1877
  set: function set(value) {
1449
- if (this._interactive !== value) {
1450
- this._interactive = value;
1451
- this._globalInteractiveDirty = true;
1878
+ var referenceResolution = this._referenceResolution;
1879
+ if (referenceResolution === value) return;
1880
+ (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
1881
+ }
1882
+ },
1883
+ {
1884
+ key: "renderMode",
1885
+ get: /**
1886
+ * The rendering mode of the UI canvas.
1887
+ */ function get() {
1888
+ return this._renderMode;
1889
+ },
1890
+ set: function set(mode) {
1891
+ var preMode = this._renderMode;
1892
+ if (preMode !== mode) {
1893
+ this._renderMode = mode;
1894
+ this._updateCameraObserver();
1895
+ this._setRealRenderMode(this._getRealRenderMode());
1896
+ }
1897
+ }
1898
+ },
1899
+ {
1900
+ key: "camera",
1901
+ get: /**
1902
+ * The camera associated with this canvas.
1903
+ * @remarks
1904
+ * - `ScreenSpaceCamera` mode: Used for rendering adaptation. Defaults to `ScreenSpaceOverlay` if not assigned.
1905
+ * - `WorldSpace` mode: Used for event detection. If not assigned, events are handled by the highest-priority camera.
1906
+ */ function get() {
1907
+ return this._camera;
1908
+ },
1909
+ set: function set(value) {
1910
+ var preCamera = this._camera;
1911
+ if (preCamera !== value) {
1912
+ if (value && this._isSameOrChildEntity(value.entity)) {
1913
+ engine.Logger.warn("Camera entity matching or nested within the canvas entity disables canvas auto-adaptation in ScreenSpaceCamera mode.");
1914
+ }
1915
+ this._camera = value;
1916
+ this._updateCameraObserver();
1917
+ var preRenderMode = this._realRenderMode;
1918
+ var curRenderMode = this._getRealRenderMode();
1919
+ if (preRenderMode === curRenderMode) {
1920
+ if (curRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1921
+ this._adapterPoseInScreenSpace();
1922
+ this._adapterSizeInScreenSpace();
1923
+ }
1924
+ } else {
1925
+ this._setRealRenderMode(curRenderMode);
1926
+ }
1927
+ }
1928
+ }
1929
+ },
1930
+ {
1931
+ key: "renderCamera",
1932
+ get: /**
1933
+ * @deprecated Use {@link camera} instead.
1934
+ */ function get() {
1935
+ return this.camera;
1936
+ },
1937
+ set: function set(value) {
1938
+ this.camera = value;
1939
+ }
1940
+ },
1941
+ {
1942
+ key: "resolutionAdaptationMode",
1943
+ get: /**
1944
+ * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1945
+ */ function get() {
1946
+ return this._resolutionAdaptationMode;
1947
+ },
1948
+ set: function set(value) {
1949
+ if (this._resolutionAdaptationMode !== value) {
1950
+ this._resolutionAdaptationMode = value;
1951
+ var realRenderMode = this._realRenderMode;
1952
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1953
+ this._adapterSizeInScreenSpace();
1954
+ }
1955
+ }
1956
+ }
1957
+ },
1958
+ {
1959
+ key: "sortOrder",
1960
+ get: /**
1961
+ * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
1962
+ */ function get() {
1963
+ return this._sortOrder;
1964
+ },
1965
+ set: function set(value) {
1966
+ if (this._sortOrder !== value) {
1967
+ this._sortOrder = value;
1968
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
1969
+ (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
1970
+ }
1971
+ }
1972
+ },
1973
+ {
1974
+ key: "distance",
1975
+ get: /**
1976
+ * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
1977
+ */ function get() {
1978
+ return this._distance;
1979
+ },
1980
+ set: function set(value) {
1981
+ if (this._distance !== value) {
1982
+ this._distance = value;
1983
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1984
+ this._adapterPoseInScreenSpace();
1985
+ this._adapterSizeInScreenSpace();
1986
+ }
1452
1987
  }
1453
1988
  }
1454
1989
  }
1455
1990
  ]);
1456
- return UIInteractive;
1457
- }(engine.Script);
1991
+ return UICanvas;
1992
+ }(engine.Component);
1993
+ /** @internal */ exports.UICanvas._hierarchyCounter = 1;
1994
+ exports.UICanvas._tempGroupAbleList = [];
1995
+ exports.UICanvas._tempRectMaskList = [];
1996
+ exports.UICanvas._tempVec3 = new engine.Vector3();
1997
+ exports.UICanvas._tempMat = new engine.Matrix();
1458
1998
  __decorate([
1459
1999
  engine.ignoreClone
1460
- ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
2000
+ ], exports.UICanvas.prototype, "_canvasIndex", void 0);
1461
2001
  __decorate([
1462
2002
  engine.ignoreClone
1463
- ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
2003
+ ], exports.UICanvas.prototype, "_indexInRootCanvas", void 0);
1464
2004
  __decorate([
1465
2005
  engine.ignoreClone
1466
- ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
2006
+ ], exports.UICanvas.prototype, "_isRootCanvasDirty", void 0);
1467
2007
  __decorate([
1468
2008
  engine.ignoreClone
1469
- ], UIInteractive.prototype, "_indexInGroup", void 0);
2009
+ ], exports.UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
1470
2010
  __decorate([
1471
2011
  engine.ignoreClone
1472
- ], UIInteractive.prototype, "_isGroupDirty", void 0);
2012
+ ], exports.UICanvas.prototype, "_isRootCanvas", void 0);
1473
2013
  __decorate([
1474
2014
  engine.ignoreClone
1475
- ], UIInteractive.prototype, "_groupListeningEntities", void 0);
2015
+ ], exports.UICanvas.prototype, "_renderElements", void 0);
1476
2016
  __decorate([
1477
2017
  engine.ignoreClone
1478
- ], UIInteractive.prototype, "_globalInteractive", void 0);
2018
+ ], exports.UICanvas.prototype, "_batchedRenderElements", void 0);
1479
2019
  __decorate([
1480
2020
  engine.ignoreClone
1481
- ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
2021
+ ], exports.UICanvas.prototype, "_sortDistance", void 0);
2022
+ __decorate([
2023
+ engine.ignoreClone
2024
+ ], exports.UICanvas.prototype, "_orderedRenderers", void 0);
2025
+ __decorate([
2026
+ engine.ignoreClone
2027
+ ], exports.UICanvas.prototype, "_realRenderMode", void 0);
1482
2028
  __decorate([
1483
- engine.deepClone
1484
- ], UIInteractive.prototype, "_transitions", void 0);
2029
+ engine.ignoreClone
2030
+ ], exports.UICanvas.prototype, "_renderMode", void 0);
1485
2031
  __decorate([
1486
- engine.assignmentClone
1487
- ], UIInteractive.prototype, "_interactive", void 0);
2032
+ engine.ignoreClone
2033
+ ], exports.UICanvas.prototype, "_hierarchyVersion", void 0);
1488
2034
  __decorate([
1489
2035
  engine.ignoreClone
1490
- ], UIInteractive.prototype, "_state", void 0);
2036
+ ], exports.UICanvas.prototype, "_center", void 0);
1491
2037
  __decorate([
1492
2038
  engine.ignoreClone
1493
- ], UIInteractive.prototype, "_isPointerInside", void 0);
2039
+ ], exports.UICanvas.prototype, "_rootCanvasListener", null);
1494
2040
  __decorate([
1495
2041
  engine.ignoreClone
1496
- ], UIInteractive.prototype, "_isPointerDragging", void 0);
2042
+ ], exports.UICanvas.prototype, "_onCameraModifyListener", null);
1497
2043
  __decorate([
1498
2044
  engine.ignoreClone
1499
- ], UIInteractive.prototype, "_groupListener", null);
2045
+ ], exports.UICanvas.prototype, "_onCameraTransformListener", null);
1500
2046
  __decorate([
1501
2047
  engine.ignoreClone
1502
- ], UIInteractive.prototype, "_rootCanvasListener", null);
2048
+ ], exports.UICanvas.prototype, "_onCanvasSizeListener", null);
1503
2049
  __decorate([
1504
2050
  engine.ignoreClone
1505
- ], UIInteractive.prototype, "_onGroupModify", null);
1506
- var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
1507
- InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
1508
- InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
1509
- InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
1510
- InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
1511
- return InteractiveState;
2051
+ ], exports.UICanvas.prototype, "_onReferenceResolutionChanged", null);
2052
+ exports.UICanvas = __decorate([
2053
+ engine.dependentComponents(UITransform, engine.DependentMode.AutoAdd)
2054
+ ], exports.UICanvas);
2055
+ /**
2056
+ * @remarks Extends `EntityModifyFlags`.
2057
+ */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
2058
+ EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
2059
+ EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
2060
+ return EntityUIModifyFlags;
2061
+ }({});
2062
+ var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
2063
+ RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
2064
+ RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
2065
+ RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
2066
+ return RootCanvasModifyFlags;
1512
2067
  }({});
1513
2068
 
1514
- exports.UICanvas = /*#__PURE__*/ function(Component) {
1515
- _inherits(UICanvas, Component);
1516
- function UICanvas(entity) {
1517
- var _this;
1518
- _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();
1519
- _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1520
- _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1521
- _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1522
- _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1523
- // @ts-ignore
1524
- _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1525
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1526
- _this._centerDirtyFlag = entity.registerWorldChangeFlag();
1527
- return _this;
1528
- }
1529
- var _proto = UICanvas.prototype;
2069
+ var Utils = /*#__PURE__*/ function() {
2070
+ function Utils() {}
1530
2071
  /**
1531
- * @internal
1532
- */ _proto._raycast = function _raycast(ray, out, distance) {
1533
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1534
- var renderers = this._getRenderers();
1535
- for(var i = renderers.length - 1; i >= 0; i--){
1536
- var element = renderers[i];
1537
- if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1538
- return true;
2072
+ * Local position of a screen point in the component
2073
+ */ Utils.screenToLocalPoint = function screenToLocalPoint(position, transform, out) {
2074
+ var engine$1 = transform.engine;
2075
+ // Get root canvas
2076
+ var entity = transform.entity;
2077
+ var rootCanvas;
2078
+ while(entity){
2079
+ // @ts-ignore
2080
+ var components = entity._components;
2081
+ for(var i = 0, n = components.length; i < n; i++){
2082
+ var component = components[i];
2083
+ if (component.enabled && _instanceof(component, exports.UICanvas) && component._isRootCanvas) {
2084
+ rootCanvas = component;
2085
+ }
1539
2086
  }
2087
+ entity = entity.parent;
2088
+ }
2089
+ if (!rootCanvas) return false;
2090
+ // Calculate ray
2091
+ var ray = this._tempRay;
2092
+ switch(rootCanvas._realRenderMode){
2093
+ case CanvasRenderMode.ScreenSpaceOverlay:
2094
+ // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
2095
+ ray.origin.set(position.x, engine$1.canvas.height - position.y, 1);
2096
+ ray.direction.set(0, 0, -1);
2097
+ break;
2098
+ case CanvasRenderMode.ScreenSpaceCamera:
2099
+ rootCanvas.renderCamera.screenPointToRay(position, ray);
2100
+ break;
2101
+ default:
2102
+ // World space not yet supported, see issue #2793
2103
+ return false;
2104
+ }
2105
+ // Intersect ray with UI plane to get local coordinates
2106
+ var plane = this._tempPlane;
2107
+ var normal = plane.normal.copyFrom(transform.worldForward);
2108
+ plane.distance = -engine.Vector3.dot(normal, transform.worldPosition);
2109
+ var curDistance = ray.intersectPlane(plane);
2110
+ if (curDistance >= 0 && curDistance < Number.MAX_SAFE_INTEGER) {
2111
+ var hitPointWorld = ray.getPoint(curDistance, this._tempVec3);
2112
+ var worldMatrixInv = this._tempMat;
2113
+ engine.Matrix.invert(transform.worldMatrix, worldMatrixInv);
2114
+ engine.Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, out);
2115
+ return true;
1540
2116
  }
1541
- out.component = null;
1542
- out.entity = null;
1543
- out.distance = 0;
1544
- out.point.set(0, 0, 0);
1545
- out.normal.set(0, 0, 0);
1546
2117
  return false;
1547
2118
  };
1548
- /**
1549
- * @internal
1550
- */ _proto._getRootCanvas = function _getRootCanvas() {
1551
- return this._rootCanvas;
2119
+ Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
2120
+ if (element._isRootCanvasDirty) return;
2121
+ element._isRootCanvasDirty = true;
2122
+ this._registerRootCanvas(element, null);
2123
+ element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
1552
2124
  };
1553
- /**
1554
- * @internal
1555
- */ _proto._canRender = function _canRender(camera) {
1556
- return this._realRenderMode !== CanvasRenderMode.ScreenSpaceCamera || this._camera === camera;
2125
+ Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
2126
+ element._isRootCanvasDirty = false;
2127
+ this._registerRootCanvas(element, rootCanvas);
2128
+ var fromEntity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
2129
+ var _rootCanvas_entity_parent;
2130
+ var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
2131
+ this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
1557
2132
  };
1558
- /**
1559
- * @internal
1560
- */ _proto._canDispatchEvent = function _canDispatchEvent(camera) {
1561
- var realMode = this._realRenderMode;
1562
- if (realMode === CanvasRenderMode.ScreenSpaceOverlay) {
1563
- return true;
1564
- }
1565
- var assignedCamera = this._camera;
1566
- // @ts-ignore
1567
- return !assignedCamera || !assignedCamera._phasedActiveInScene || assignedCamera === camera;
2133
+ Utils.cleanRootCanvas = function cleanRootCanvas(element) {
2134
+ this._registerRootCanvas(element, null);
2135
+ this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
1568
2136
  };
1569
- /**
1570
- * @internal
1571
- */ _proto._prepareRender = function _prepareRender(context) {
1572
- var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1573
- var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1574
- var frameCount = engine.time.frameCount;
1575
- var renderElements = this._renderElements;
1576
- renderElements.length = 0;
1577
- var virtualCamera = context.virtualCamera;
1578
- this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1579
- var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1580
- var renderers = this._getRenderers();
1581
- for(var i = 0, n = renderers.length; i < n; i++){
1582
- var renderer = renderers[i];
1583
- // Filter by camera culling mask
1584
- if (!(cullingMask & renderer.entity.layer)) {
1585
- continue;
1586
- }
1587
- // Filter by camera frustum
1588
- if (enableFrustumCulling) {
1589
- switch(mode){
1590
- case CanvasRenderMode.ScreenSpaceOverlay:
1591
- var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1592
- if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1593
- continue;
1594
- }
1595
- break;
1596
- case CanvasRenderMode.ScreenSpaceCamera:
1597
- case CanvasRenderMode.WorldSpace:
1598
- if (!frustum.intersectsBox(renderer.bounds)) {
1599
- continue;
1600
- }
1601
- break;
2137
+ Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
2138
+ var entity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
2139
+ while(entity){
2140
+ // @ts-ignore
2141
+ var components = entity._components;
2142
+ for(var i = 0, n = components.length; i < n; i++){
2143
+ var component = components[i];
2144
+ if (component.enabled && _instanceof(component, exports.UICanvas) && component._isRootCanvas) {
2145
+ return component;
1602
2146
  }
1603
2147
  }
1604
- renderer._prepareRender(context);
1605
- renderer._renderFrameCount = frameCount;
1606
- }
1607
- var batchedRenderElements = this._batchedRenderElements;
1608
- batchedRenderElements.length = 0;
1609
- UIBatchSorter.sort(renderElements, this.entity.transform.worldMatrix);
1610
- engine._batcherManager.batch(renderElements, batchedRenderElements);
1611
- for(var i1 = 0, n1 = batchedRenderElements.length; i1 < n1; i1++){
1612
- batchedRenderElements[i1].subDistancePriority = i1;
2148
+ entity = entity.parent;
1613
2149
  }
2150
+ return null;
1614
2151
  };
1615
- /**
1616
- * @internal
1617
- */ _proto._updateSortDistance = function _updateSortDistance(isOrthographic, cameraPosition, cameraForward) {
1618
- switch(this._realRenderMode){
1619
- case CanvasRenderMode.ScreenSpaceOverlay:
1620
- this._sortDistance = 0;
1621
- break;
1622
- case CanvasRenderMode.ScreenSpaceCamera:
1623
- this._sortDistance = this._distance;
1624
- break;
1625
- case CanvasRenderMode.WorldSpace:
1626
- var boundsCenter = this._getCenter();
1627
- if (isOrthographic) {
1628
- var distance = UICanvas._tempVec3;
1629
- engine.Vector3.subtract(boundsCenter, cameraPosition, distance);
1630
- this._sortDistance = engine.Vector3.dot(distance, cameraForward);
1631
- } else {
1632
- this._sortDistance = engine.Vector3.distanceSquared(boundsCenter, cameraPosition);
1633
- }
1634
- break;
2152
+ Utils.setGroupDirty = function setGroupDirty(element) {
2153
+ if (element._isGroupDirty) return;
2154
+ element._isGroupDirty = true;
2155
+ this._registerGroup(element, null);
2156
+ element._onGroupModify(GroupModifyFlags.All);
2157
+ };
2158
+ Utils.setGroup = function setGroup(element, group) {
2159
+ element._isGroupDirty = false;
2160
+ this._registerGroup(element, group);
2161
+ var rootCanvas = element._getRootCanvas();
2162
+ if (rootCanvas) {
2163
+ var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
2164
+ var _group_entity;
2165
+ var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
2166
+ this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
2167
+ } else {
2168
+ this._unRegisterListener(element._groupListener, element._groupListeningEntities);
1635
2169
  }
1636
2170
  };
1637
- // @ts-ignore
1638
- _proto._onEnableInScene = function _onEnableInScene() {
1639
- var entity = this.entity;
1640
- // @ts-ignore
1641
- entity._dispatchModify(4, this);
1642
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1643
- this._setIsRootCanvas(!rootCanvas);
1644
- Utils.setRootCanvas(this, rootCanvas);
2171
+ Utils.cleanGroup = function cleanGroup(element) {
2172
+ this._registerGroup(element, null);
2173
+ this._unRegisterListener(element._groupListener, element._groupListeningEntities);
1645
2174
  };
1646
- // @ts-ignore
1647
- _proto._onDisableInScene = function _onDisableInScene() {
1648
- this._setIsRootCanvas(false);
1649
- Utils.cleanRootCanvas(this);
2175
+ Utils.searchGroupInParents = function searchGroupInParents(element) {
2176
+ var rootCanvas = element._getRootCanvas();
2177
+ if (!rootCanvas) return null;
2178
+ var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
2179
+ var rootCanvasParent = rootCanvas.entity.parent;
2180
+ while(entity && entity !== rootCanvasParent){
2181
+ // @ts-ignore
2182
+ var components = entity._components;
2183
+ for(var i = 0, n = components.length; i < n; i++){
2184
+ var component = components[i];
2185
+ if (component.enabled && _instanceof(component, UIGroup)) {
2186
+ return component;
2187
+ }
2188
+ }
2189
+ entity = entity.parent;
2190
+ }
2191
+ return null;
1650
2192
  };
1651
- // @ts-ignore
1652
- _proto._onDisable = function _onDisable() {
1653
- this._renderElements.length = 0;
1654
- this._batchedRenderElements.length = 0;
2193
+ Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
2194
+ var preCanvas = element._rootCanvas;
2195
+ if (preCanvas !== canvas) {
2196
+ if (preCanvas) {
2197
+ var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
2198
+ replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
2199
+ element._indexInRootCanvas = -1;
2200
+ }
2201
+ if (canvas) {
2202
+ var disorderedElements = canvas._disorderedElements;
2203
+ element._indexInRootCanvas = disorderedElements.length;
2204
+ disorderedElements.add(element);
2205
+ }
2206
+ element._rootCanvas = canvas;
2207
+ }
1655
2208
  };
1656
- /**
1657
- * @internal
1658
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1659
- if (this._isRootCanvas) {
1660
- if (flag === engine.EntityModifyFlags.Parent) {
1661
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1662
- this._setIsRootCanvas(!rootCanvas);
1663
- Utils.setRootCanvas(this, rootCanvas);
1664
- } else if (flag === 4) {
1665
- this._setIsRootCanvas(false);
1666
- Utils.setRootCanvas(this, param);
2209
+ Utils._registerGroup = function _registerGroup(element, group) {
2210
+ var preGroup = element._group;
2211
+ if (preGroup !== group) {
2212
+ if (preGroup) {
2213
+ var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
2214
+ replaced && (replaced._indexInGroup = element._indexInGroup);
2215
+ element._indexInGroup = -1;
1667
2216
  }
1668
- } else {
1669
- if (flag === engine.EntityModifyFlags.Parent) {
1670
- var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1671
- this._setIsRootCanvas(!rootCanvas1);
1672
- Utils.setRootCanvas(this, rootCanvas1);
2217
+ if (group) {
2218
+ var disorderedElements = group._disorderedElements;
2219
+ element._indexInGroup = disorderedElements.length;
2220
+ disorderedElements.add(element);
1673
2221
  }
2222
+ element._group = group;
2223
+ element._onGroupModify(GroupModifyFlags.All);
1674
2224
  }
1675
2225
  };
1676
- /**
1677
- * @internal
1678
- */ _proto._cloneTo = function _cloneTo(target) {
1679
- target.renderMode = this._renderMode;
1680
- };
1681
- _proto._getRenderers = function _getRenderers() {
1682
- var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1683
- var uiHierarchyVersion = entity._uiHierarchyVersion;
1684
- if (this._hierarchyVersion !== uiHierarchyVersion) {
1685
- renderers.length = this._walk(this.entity, renderers);
1686
- UICanvas._tempGroupAbleList.length = 0;
1687
- this._hierarchyVersion = uiHierarchyVersion;
1688
- ++UICanvas._hierarchyCounter;
1689
- }
1690
- return renderers;
1691
- };
1692
- _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1693
- var transform = this.entity.transform;
1694
- var realRenderMode = this._realRenderMode;
1695
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1696
- var cameraEntity = this._camera.entity;
1697
- if (!this._isSameOrChildEntity(cameraEntity)) {
1698
- var cameraTransform = cameraEntity.transform;
1699
- var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1700
- var distance = this._distance;
1701
- transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1702
- transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
2226
+ Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
2227
+ var count = 0;
2228
+ while(entity && entity !== root){
2229
+ var preEntity = listeningEntities[count];
2230
+ if (preEntity !== entity) {
2231
+ // @ts-ignore
2232
+ preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
2233
+ listeningEntities[count] = entity;
2234
+ // @ts-ignore
2235
+ entity._registerModifyListener(listener);
1703
2236
  }
1704
- } else {
1705
- var canvas = this.engine.canvas;
1706
- transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1707
- transform.worldRotationQuaternion.set(0, 0, 0, 1);
2237
+ entity = entity.parent;
2238
+ count++;
1708
2239
  }
2240
+ listeningEntities.length = count;
1709
2241
  };
1710
- _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1711
- var transform = this.entity.transform;
1712
- var realRenderMode = this._realRenderMode;
1713
- var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1714
- var curWidth;
1715
- var curHeight;
1716
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1717
- var camera = this._camera;
1718
- curHeight = camera.isOrthographic ? camera.orthographicSize * 2 : 2 * (Math.tan(engine.MathUtil.degreeToRadian(camera.fieldOfView * 0.5)) * this._distance);
1719
- curWidth = camera.aspectRatio * curHeight;
1720
- } else {
1721
- var canvas = this.engine.canvas;
1722
- curHeight = canvas.height;
1723
- curWidth = canvas.width;
2242
+ Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
2243
+ for(var i = 0, n = listeningEntities.length; i < n; i++){
2244
+ // @ts-ignore
2245
+ listeningEntities[i]._unRegisterModifyListener(listener);
1724
2246
  }
1725
- var expectX, expectY, expectZ;
1726
- switch(this._resolutionAdaptationMode){
1727
- case ResolutionAdaptationMode.WidthAdaptation:
1728
- expectX = expectY = expectZ = curWidth / width;
1729
- break;
1730
- case ResolutionAdaptationMode.HeightAdaptation:
1731
- expectX = expectY = expectZ = curHeight / height;
1732
- break;
1733
- case ResolutionAdaptationMode.BothAdaptation:
1734
- expectX = curWidth / width;
1735
- expectY = curHeight / height;
1736
- expectZ = (expectX + expectY) * 0.5;
1737
- break;
1738
- case ResolutionAdaptationMode.ExpandAdaptation:
1739
- expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1740
- break;
1741
- case ResolutionAdaptationMode.ShrinkAdaptation:
1742
- expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1743
- break;
2247
+ listeningEntities.length = 0;
2248
+ };
2249
+ return Utils;
2250
+ }();
2251
+ Utils._tempRay = new engine.Ray();
2252
+ Utils._tempPlane = new engine.Plane();
2253
+ Utils._tempVec3 = new engine.Vector3();
2254
+ Utils._tempMat = new engine.Matrix();
2255
+
2256
+ /**
2257
+ * Interactive component.
2258
+ */ var UIInteractive = /*#__PURE__*/ function(Script) {
2259
+ _inherits(UIInteractive, Script);
2260
+ function UIInteractive(entity) {
2261
+ var _this;
2262
+ _this = Script.call(this, entity) || this, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._globalInteractive = false, /** @internal */ _this._globalInteractiveDirty = false, _this._transitions = [], _this._interactive = true, _this._state = 0, /** @todo Multi-touch points are not considered yet. */ _this._isPointerInside = false, _this._isPointerDragging = false;
2263
+ _this._groupListener = _this._groupListener.bind(_this);
2264
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
2265
+ return _this;
2266
+ }
2267
+ var _proto = UIInteractive.prototype;
2268
+ /**
2269
+ * Add transition on this interactive.
2270
+ * @param transition - The transition
2271
+ */ _proto.addTransition = function addTransition(transition) {
2272
+ var interactive = transition._interactive;
2273
+ if (interactive !== this) {
2274
+ interactive == null ? void 0 : interactive.removeTransition(transition);
2275
+ this._transitions.push(transition);
2276
+ transition._interactive = this;
2277
+ transition._setState(this._state, true);
1744
2278
  }
1745
- var worldMatrix = UICanvas._tempMat;
1746
- engine.Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1747
- transform.worldMatrix = worldMatrix;
1748
- transform.size.set(curWidth / expectX, curHeight / expectY);
1749
2279
  };
1750
- _proto._walk = function _walk(entity, renderers, depth, group) {
1751
- if (depth === void 0) depth = 0;
1752
- if (group === void 0) group = null;
1753
- // @ts-ignore
1754
- var components = entity._components;
1755
- var tempGroupAbleList = UICanvas._tempGroupAbleList;
1756
- var groupAbleCount = 0;
1757
- for(var i = 0, n = components.length; i < n; i++){
1758
- var component = components[i];
1759
- if (!component.enabled) continue;
1760
- if (_instanceof(component, exports.UIRenderer)) {
1761
- renderers[depth] = component;
1762
- ++depth;
1763
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1764
- if (component._isGroupDirty) {
1765
- tempGroupAbleList[groupAbleCount++] = component;
1766
- }
1767
- } else if (_instanceof(component, UIInteractive)) {
1768
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1769
- if (component._isGroupDirty) {
1770
- tempGroupAbleList[groupAbleCount++] = component;
1771
- }
1772
- } else if (_instanceof(component, UIGroup)) {
1773
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1774
- component._isGroupDirty && Utils.setGroup(component, group);
1775
- group = component;
2280
+ /**
2281
+ * Remove a transition.
2282
+ * @param shape - The transition.
2283
+ */ _proto.removeTransition = function removeTransition(transition) {
2284
+ var transitions = this._transitions;
2285
+ var lastOneIndex = transitions.length - 1;
2286
+ for(var i = lastOneIndex; i >= 0; i--){
2287
+ if (transitions[i] === transition) {
2288
+ i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
2289
+ transitions.length = lastOneIndex;
2290
+ transition._interactive = null;
2291
+ break;
1776
2292
  }
1777
2293
  }
1778
- for(var i1 = 0; i1 < groupAbleCount; i1++){
1779
- Utils.setGroup(tempGroupAbleList[i1], group);
1780
- }
1781
- var children = entity.children;
1782
- for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1783
- var child = children[i2];
1784
- child.isActive && (depth = this._walk(child, renderers, depth, group));
2294
+ };
2295
+ /**
2296
+ * Remove all transitions.
2297
+ */ _proto.clearTransitions = function clearTransitions() {
2298
+ var transitions = this._transitions;
2299
+ for(var i = 0, n = transitions.length; i < n; i++){
2300
+ transitions[i]._interactive = null;
1785
2301
  }
1786
- return depth;
2302
+ transitions.length = 0;
1787
2303
  };
1788
- _proto._updateCameraObserver = function _updateCameraObserver() {
1789
- var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._camera : null;
1790
- var preCamera = this._cameraObserver;
1791
- if (preCamera !== camera) {
1792
- this._cameraObserver = camera;
1793
- if (preCamera) {
1794
- // @ts-ignore
1795
- preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1796
- // @ts-ignore
1797
- preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1798
- }
1799
- if (camera) {
1800
- // @ts-ignore
1801
- camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1802
- // @ts-ignore
1803
- camera._registerModifyListener(this._onCameraModifyListener);
2304
+ _proto.onUpdate = function onUpdate(deltaTime) {
2305
+ if (this._getGlobalInteractive()) {
2306
+ var transitions = this._transitions;
2307
+ for(var i = 0, n = transitions.length; i < n; i++){
2308
+ transitions[i]._onUpdate(deltaTime);
1804
2309
  }
1805
2310
  }
1806
2311
  };
1807
- _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1808
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1809
- switch(flag){
1810
- case engine.CameraModifyFlags.ProjectionType:
1811
- case engine.CameraModifyFlags.AspectRatio:
1812
- this._adapterSizeInScreenSpace();
1813
- break;
1814
- case engine.CameraModifyFlags.FieldOfView:
1815
- !this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1816
- break;
1817
- case engine.CameraModifyFlags.OrthographicSize:
1818
- this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1819
- break;
1820
- case engine.CameraModifyFlags.DisableInScene:
1821
- this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
1822
- break;
1823
- }
1824
- } else {
1825
- flag === engine.CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
2312
+ _proto.onPointerBeginDrag = function onPointerBeginDrag() {
2313
+ this._isPointerDragging = true;
2314
+ this._updateState(false);
2315
+ };
2316
+ _proto.onPointerEndDrag = function onPointerEndDrag() {
2317
+ this._isPointerDragging = false;
2318
+ this._updateState(false);
2319
+ };
2320
+ _proto.onPointerEnter = function onPointerEnter() {
2321
+ this._isPointerInside = true;
2322
+ this._updateState(false);
2323
+ };
2324
+ _proto.onPointerExit = function onPointerExit() {
2325
+ this._isPointerInside = false;
2326
+ this._updateState(false);
2327
+ };
2328
+ _proto.onDestroy = function onDestroy() {
2329
+ Script.prototype.onDestroy.call(this);
2330
+ var transitions = this._transitions;
2331
+ for(var i = transitions.length - 1; i >= 0; i--){
2332
+ transitions[i].destroy();
1826
2333
  }
1827
2334
  };
1828
- _proto._onCameraTransformListener = function _onCameraTransformListener() {
1829
- this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
2335
+ /**
2336
+ * @internal
2337
+ */ _proto._getRootCanvas = function _getRootCanvas() {
2338
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
2339
+ return this._rootCanvas;
1830
2340
  };
1831
- _proto._addCanvasListener = function _addCanvasListener() {
1832
- // @ts-ignore
1833
- this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
2341
+ /**
2342
+ * @internal
2343
+ */ _proto._getGroup = function _getGroup() {
2344
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
2345
+ return this._group;
1834
2346
  };
1835
- _proto._removeCanvasListener = function _removeCanvasListener() {
2347
+ // @ts-ignore
2348
+ _proto._onEnableInScene = function _onEnableInScene() {
1836
2349
  // @ts-ignore
1837
- this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
2350
+ Script.prototype._onEnableInScene.call(this);
2351
+ Utils.setRootCanvasDirty(this);
2352
+ Utils.setGroupDirty(this);
2353
+ this._updateState(true);
1838
2354
  };
1839
- _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1840
- var canvas = this.engine.canvas;
1841
- this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1842
- this._adapterSizeInScreenSpace();
2355
+ // @ts-ignore
2356
+ _proto._onDisableInScene = function _onDisableInScene() {
2357
+ // @ts-ignore
2358
+ Script.prototype._onDisableInScene.call(this);
2359
+ Utils.cleanRootCanvas(this);
2360
+ Utils.cleanGroup(this);
2361
+ this._isPointerInside = this._isPointerDragging = false;
1843
2362
  };
1844
- _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1845
- var realRenderMode = this._realRenderMode;
1846
- if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1847
- this._adapterSizeInScreenSpace();
2363
+ /**
2364
+ * @internal
2365
+ */ _proto._groupListener = function _groupListener(flag) {
2366
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
2367
+ Utils.setGroupDirty(this);
1848
2368
  }
1849
2369
  };
1850
- _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1851
- var _this = this;
1852
- if (this._isRootCanvas !== isRootCanvas) {
1853
- this._isRootCanvas = isRootCanvas;
1854
- this._updateCameraObserver();
1855
- this._setRealRenderMode(this._getRealRenderMode());
1856
- if (isRootCanvas) {
1857
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1858
- } else {
1859
- var _this1 = this, disorderedElements = _this1._disorderedElements;
1860
- disorderedElements.forEach(function(element) {
1861
- if (_instanceof(element, UICanvas)) {
1862
- var rootCanvas = Utils.searchRootCanvasInParents(element);
1863
- element._setIsRootCanvas(!rootCanvas);
1864
- Utils.setRootCanvas(element, rootCanvas);
1865
- } else {
1866
- Utils.setRootCanvasDirty(_this);
1867
- Utils.setGroupDirty(element);
1868
- }
1869
- });
1870
- disorderedElements.length = 0;
1871
- disorderedElements.garbageCollection();
1872
- this._orderedRenderers.length = 0;
1873
- }
2370
+ /**
2371
+ * @internal
2372
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
2373
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
2374
+ Utils.setRootCanvasDirty(this);
2375
+ Utils.setGroupDirty(this);
1874
2376
  }
1875
2377
  };
1876
- _proto._getCenter = function _getCenter() {
1877
- if (this._centerDirtyFlag.flag) {
1878
- var center = this._center;
1879
- var uiTransform = this.entity.transform;
1880
- var pivot = uiTransform.pivot, size = uiTransform.size;
1881
- center.set((0.5 - pivot.x) * size.x, (0.5 - pivot.y) * size.y, 0);
1882
- engine.Vector3.transformCoordinate(center, uiTransform.worldMatrix, center);
1883
- this._centerDirtyFlag.flag = false;
2378
+ /**
2379
+ * @internal
2380
+ */ _proto._onGroupModify = function _onGroupModify(flags) {
2381
+ if (flags & GroupModifyFlags.GlobalInteractive) {
2382
+ this._globalInteractiveDirty = true;
1884
2383
  }
1885
- return this._center;
1886
2384
  };
1887
- _proto._getRealRenderMode = function _getRealRenderMode() {
1888
- if (this._isRootCanvas) {
1889
- var _this__camera;
1890
- var mode = this._renderMode;
1891
- // @ts-ignore
1892
- if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__camera = this._camera) == null ? void 0 : _this__camera._phasedActiveInScene)) {
1893
- return CanvasRenderMode.ScreenSpaceOverlay;
1894
- } else {
1895
- return mode;
2385
+ /**
2386
+ * @internal
2387
+ */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
2388
+ if (this._globalInteractiveDirty) {
2389
+ var group = this._getGroup();
2390
+ var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
2391
+ if (this._globalInteractive !== globalInteractive) {
2392
+ this._globalInteractive = globalInteractive;
2393
+ this._updateState(true);
1896
2394
  }
1897
- } else {
1898
- return 4;
2395
+ this._globalInteractiveDirty = false;
1899
2396
  }
2397
+ return this._globalInteractive;
1900
2398
  };
1901
- _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1902
- var preRealMode = this._realRenderMode;
1903
- if (preRealMode !== curRealMode) {
1904
- this._realRenderMode = curRealMode;
1905
- // @ts-ignore
1906
- var componentsManager = this.scene._componentsManager;
1907
- switch(preRealMode){
1908
- case CanvasRenderMode.ScreenSpaceOverlay:
1909
- this._removeCanvasListener();
1910
- case CanvasRenderMode.ScreenSpaceCamera:
1911
- case CanvasRenderMode.WorldSpace:
1912
- componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1913
- break;
1914
- }
1915
- switch(curRealMode){
1916
- case CanvasRenderMode.ScreenSpaceOverlay:
1917
- this._addCanvasListener();
1918
- case CanvasRenderMode.ScreenSpaceCamera:
1919
- this._adapterPoseInScreenSpace();
1920
- this._adapterSizeInScreenSpace();
1921
- case CanvasRenderMode.WorldSpace:
1922
- componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1923
- break;
2399
+ _proto._updateState = function _updateState(instant) {
2400
+ var state = this._getInteractiveState();
2401
+ if (this._state !== state) {
2402
+ this._state = state;
2403
+ var transitions = this._transitions;
2404
+ for(var i = 0, n = transitions.length; i < n; i++){
2405
+ transitions[i]._setState(state, instant);
1924
2406
  }
1925
2407
  }
1926
2408
  };
1927
- _proto._isSameOrChildEntity = function _isSameOrChildEntity(cameraEntity) {
1928
- var canvasEntity = this.entity;
1929
- while(cameraEntity){
1930
- if (cameraEntity === canvasEntity) return true;
1931
- cameraEntity = cameraEntity.parent;
2409
+ _proto._getInteractiveState = function _getInteractiveState() {
2410
+ if (!this._getGlobalInteractive()) {
2411
+ return 3;
2412
+ }
2413
+ if (this._isPointerDragging) {
2414
+ return 1;
2415
+ } else {
2416
+ return this._isPointerInside ? 2 : 0;
1932
2417
  }
1933
- return false;
1934
2418
  };
1935
- _create_class(UICanvas, [
1936
- {
1937
- key: "referenceResolutionPerUnit",
1938
- get: /**
1939
- * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1940
- */ function get() {
1941
- return this._referenceResolutionPerUnit;
1942
- },
1943
- set: function set(value) {
1944
- if (this._referenceResolutionPerUnit !== value) {
1945
- this._referenceResolutionPerUnit = value;
1946
- this._disorderedElements.forEach(function(element) {
1947
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1948
- });
1949
- }
1950
- }
1951
- },
1952
- {
1953
- key: "referenceResolution",
1954
- get: /**
1955
- * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1956
- */ function get() {
1957
- return this._referenceResolution;
1958
- },
1959
- set: function set(value) {
1960
- var referenceResolution = this._referenceResolution;
1961
- if (referenceResolution === value) return;
1962
- (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
1963
- }
1964
- },
1965
- {
1966
- key: "renderMode",
1967
- get: /**
1968
- * The rendering mode of the UI canvas.
1969
- */ function get() {
1970
- return this._renderMode;
1971
- },
1972
- set: function set(mode) {
1973
- var preMode = this._renderMode;
1974
- if (preMode !== mode) {
1975
- this._renderMode = mode;
1976
- this._updateCameraObserver();
1977
- this._setRealRenderMode(this._getRealRenderMode());
1978
- }
1979
- }
1980
- },
1981
- {
1982
- key: "camera",
1983
- get: /**
1984
- * The camera associated with this canvas.
1985
- * @remarks
1986
- * - `ScreenSpaceCamera` mode: Used for rendering adaptation. Defaults to `ScreenSpaceOverlay` if not assigned.
1987
- * - `WorldSpace` mode: Used for event detection. If not assigned, events are handled by the highest-priority camera.
1988
- */ function get() {
1989
- return this._camera;
1990
- },
1991
- set: function set(value) {
1992
- var preCamera = this._camera;
1993
- if (preCamera !== value) {
1994
- if (value && this._isSameOrChildEntity(value.entity)) {
1995
- engine.Logger.warn("Camera entity matching or nested within the canvas entity disables canvas auto-adaptation in ScreenSpaceCamera mode.");
1996
- }
1997
- this._camera = value;
1998
- this._updateCameraObserver();
1999
- var preRenderMode = this._realRenderMode;
2000
- var curRenderMode = this._getRealRenderMode();
2001
- if (preRenderMode === curRenderMode) {
2002
- if (curRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
2003
- this._adapterPoseInScreenSpace();
2004
- this._adapterSizeInScreenSpace();
2005
- }
2006
- } else {
2007
- this._setRealRenderMode(curRenderMode);
2008
- }
2009
- }
2010
- }
2011
- },
2012
- {
2013
- key: "renderCamera",
2014
- get: /**
2015
- * @deprecated Use {@link camera} instead.
2016
- */ function get() {
2017
- return this.camera;
2018
- },
2019
- set: function set(value) {
2020
- this.camera = value;
2021
- }
2022
- },
2023
- {
2024
- key: "resolutionAdaptationMode",
2025
- get: /**
2026
- * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
2027
- */ function get() {
2028
- return this._resolutionAdaptationMode;
2029
- },
2030
- set: function set(value) {
2031
- if (this._resolutionAdaptationMode !== value) {
2032
- this._resolutionAdaptationMode = value;
2033
- var realRenderMode = this._realRenderMode;
2034
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
2035
- this._adapterSizeInScreenSpace();
2036
- }
2037
- }
2038
- }
2039
- },
2419
+ _create_class(UIInteractive, [
2040
2420
  {
2041
- key: "sortOrder",
2421
+ key: "transitions",
2042
2422
  get: /**
2043
- * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
2423
+ * The transitions of this interactive.
2044
2424
  */ function get() {
2045
- return this._sortOrder;
2046
- },
2047
- set: function set(value) {
2048
- if (this._sortOrder !== value) {
2049
- this._sortOrder = value;
2050
- this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
2051
- (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
2052
- }
2425
+ return this._transitions;
2053
2426
  }
2054
2427
  },
2055
2428
  {
2056
- key: "distance",
2429
+ key: "interactive",
2057
2430
  get: /**
2058
- * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
2431
+ * Whether the interactive is enabled.
2059
2432
  */ function get() {
2060
- return this._distance;
2433
+ return this._interactive;
2061
2434
  },
2062
2435
  set: function set(value) {
2063
- if (this._distance !== value) {
2064
- this._distance = value;
2065
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
2066
- this._adapterPoseInScreenSpace();
2067
- this._adapterSizeInScreenSpace();
2068
- }
2436
+ if (this._interactive !== value) {
2437
+ this._interactive = value;
2438
+ this._globalInteractiveDirty = true;
2069
2439
  }
2070
2440
  }
2071
2441
  }
2072
2442
  ]);
2073
- return UICanvas;
2074
- }(engine.Component);
2075
- /** @internal */ exports.UICanvas._hierarchyCounter = 1;
2076
- exports.UICanvas._tempGroupAbleList = [];
2077
- exports.UICanvas._tempVec3 = new engine.Vector3();
2078
- exports.UICanvas._tempMat = new engine.Matrix();
2079
- __decorate([
2080
- engine.ignoreClone
2081
- ], exports.UICanvas.prototype, "_canvasIndex", void 0);
2082
- __decorate([
2083
- engine.ignoreClone
2084
- ], exports.UICanvas.prototype, "_indexInRootCanvas", void 0);
2085
- __decorate([
2086
- engine.ignoreClone
2087
- ], exports.UICanvas.prototype, "_isRootCanvasDirty", void 0);
2088
- __decorate([
2089
- engine.ignoreClone
2090
- ], exports.UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
2091
- __decorate([
2092
- engine.ignoreClone
2093
- ], exports.UICanvas.prototype, "_isRootCanvas", void 0);
2094
- __decorate([
2095
- engine.ignoreClone
2096
- ], exports.UICanvas.prototype, "_renderElements", void 0);
2443
+ return UIInteractive;
2444
+ }(engine.Script);
2097
2445
  __decorate([
2098
2446
  engine.ignoreClone
2099
- ], exports.UICanvas.prototype, "_batchedRenderElements", void 0);
2447
+ ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
2100
2448
  __decorate([
2101
2449
  engine.ignoreClone
2102
- ], exports.UICanvas.prototype, "_sortDistance", void 0);
2450
+ ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
2103
2451
  __decorate([
2104
2452
  engine.ignoreClone
2105
- ], exports.UICanvas.prototype, "_orderedRenderers", void 0);
2453
+ ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
2106
2454
  __decorate([
2107
2455
  engine.ignoreClone
2108
- ], exports.UICanvas.prototype, "_realRenderMode", void 0);
2456
+ ], UIInteractive.prototype, "_indexInGroup", void 0);
2109
2457
  __decorate([
2110
2458
  engine.ignoreClone
2111
- ], exports.UICanvas.prototype, "_disorderedElements", void 0);
2459
+ ], UIInteractive.prototype, "_isGroupDirty", void 0);
2112
2460
  __decorate([
2113
2461
  engine.ignoreClone
2114
- ], exports.UICanvas.prototype, "_renderMode", void 0);
2115
- __decorate([
2116
- engine.assignmentClone
2117
- ], exports.UICanvas.prototype, "_resolutionAdaptationMode", void 0);
2118
- __decorate([
2119
- engine.assignmentClone
2120
- ], exports.UICanvas.prototype, "_sortOrder", void 0);
2121
- __decorate([
2122
- engine.assignmentClone
2123
- ], exports.UICanvas.prototype, "_distance", void 0);
2124
- __decorate([
2125
- engine.deepClone
2126
- ], exports.UICanvas.prototype, "_referenceResolution", void 0);
2127
- __decorate([
2128
- engine.assignmentClone
2129
- ], exports.UICanvas.prototype, "_referenceResolutionPerUnit", void 0);
2462
+ ], UIInteractive.prototype, "_groupListeningEntities", void 0);
2130
2463
  __decorate([
2131
2464
  engine.ignoreClone
2132
- ], exports.UICanvas.prototype, "_hierarchyVersion", void 0);
2465
+ ], UIInteractive.prototype, "_globalInteractive", void 0);
2133
2466
  __decorate([
2134
2467
  engine.ignoreClone
2135
- ], exports.UICanvas.prototype, "_center", void 0);
2468
+ ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
2136
2469
  __decorate([
2137
2470
  engine.ignoreClone
2138
- ], exports.UICanvas.prototype, "_centerDirtyFlag", void 0);
2471
+ ], UIInteractive.prototype, "_state", void 0);
2139
2472
  __decorate([
2140
2473
  engine.ignoreClone
2141
- ], exports.UICanvas.prototype, "_rootCanvasListener", null);
2474
+ ], UIInteractive.prototype, "_isPointerInside", void 0);
2142
2475
  __decorate([
2143
2476
  engine.ignoreClone
2144
- ], exports.UICanvas.prototype, "_onCameraModifyListener", null);
2477
+ ], UIInteractive.prototype, "_isPointerDragging", void 0);
2145
2478
  __decorate([
2146
2479
  engine.ignoreClone
2147
- ], exports.UICanvas.prototype, "_onCameraTransformListener", null);
2480
+ ], UIInteractive.prototype, "_groupListener", null);
2148
2481
  __decorate([
2149
2482
  engine.ignoreClone
2150
- ], exports.UICanvas.prototype, "_onCanvasSizeListener", null);
2483
+ ], UIInteractive.prototype, "_rootCanvasListener", null);
2151
2484
  __decorate([
2152
2485
  engine.ignoreClone
2153
- ], exports.UICanvas.prototype, "_onReferenceResolutionChanged", null);
2154
- exports.UICanvas = __decorate([
2155
- engine.dependentComponents(UITransform, engine.DependentMode.AutoAdd)
2156
- ], exports.UICanvas);
2157
- /**
2158
- * @remarks Extends `EntityModifyFlags`.
2159
- */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
2160
- EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
2161
- EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
2162
- return EntityUIModifyFlags;
2163
- }({});
2164
- var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
2165
- RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
2166
- RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
2167
- RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
2168
- return RootCanvasModifyFlags;
2486
+ ], UIInteractive.prototype, "_onGroupModify", null);
2487
+ var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
2488
+ InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
2489
+ InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
2490
+ InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
2491
+ InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
2492
+ return InteractiveState;
2169
2493
  }({});
2170
2494
 
2171
2495
  var Button = /*#__PURE__*/ function(UIInteractive) {
@@ -2198,9 +2522,6 @@
2198
2522
  };
2199
2523
  return Button;
2200
2524
  }(UIInteractive);
2201
- __decorate([
2202
- engine.deepClone
2203
- ], Button.prototype, "onClick", void 0);
2204
2525
 
2205
2526
  /**
2206
2527
  * UI element that renders an image.
@@ -2208,7 +2529,7 @@
2208
2529
  _inherits(Image, UIRenderer1);
2209
2530
  function Image(entity) {
2210
2531
  var _this;
2211
- _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = engine.SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5;
2532
+ _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = engine.SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5, _this._filledMode = engine.SpriteFilledMode.Radial360, _this._filledAmount = 1, _this._filledOrigin = engine.SpriteFilledOrigin.Bottom, _this._filledClockWise = true;
2212
2533
  _this.drawMode = engine.SpriteDrawMode.Simple;
2213
2534
  // @ts-ignore
2214
2535
  _this.setMaterial(_this._engine._getUIDefaultMaterial());
@@ -2297,7 +2618,7 @@
2297
2618
  canvas._renderElements.push(renderElement);
2298
2619
  };
2299
2620
  _proto._onTransformChanged = function _onTransformChanged(type) {
2300
- if (type & UITransformModifyFlags.Size && this._drawMode === engine.SpriteDrawMode.Tiled) {
2621
+ if (type & UITransformModifyFlags.Size && (this._drawMode === engine.SpriteDrawMode.Tiled || this._drawMode === engine.SpriteDrawMode.Filled)) {
2301
2622
  this._dirtyUpdateFlag |= 15;
2302
2623
  }
2303
2624
  this._dirtyUpdateFlag |= engine.RendererUpdateFlags.WorldVolume;
@@ -2325,6 +2646,9 @@
2325
2646
  case engine.SpriteDrawMode.Tiled:
2326
2647
  this._dirtyUpdateFlag |= 7;
2327
2648
  break;
2649
+ case engine.SpriteDrawMode.Filled:
2650
+ this._dirtyUpdateFlag |= 7;
2651
+ break;
2328
2652
  }
2329
2653
  break;
2330
2654
  case engine.SpriteModifyFlags.border:
@@ -2342,13 +2666,25 @@
2342
2666
  this._dirtyUpdateFlag |= 5;
2343
2667
  break;
2344
2668
  case engine.SpriteModifyFlags.atlasRegion:
2345
- this._dirtyUpdateFlag |= 4;
2669
+ this._dirtyUpdateFlag |= this._drawMode === engine.SpriteDrawMode.Filled ? 5 : 4;
2346
2670
  break;
2347
2671
  case engine.SpriteModifyFlags.destroy:
2348
2672
  this.sprite = null;
2349
2673
  break;
2350
2674
  }
2351
2675
  };
2676
+ Image._correctOrigin = function _correctOrigin(mode, origin) {
2677
+ switch(mode){
2678
+ case engine.SpriteFilledMode.Horizontal:
2679
+ return origin === engine.SpriteFilledOrigin.Left || origin === engine.SpriteFilledOrigin.Right ? origin : engine.SpriteFilledOrigin.Left;
2680
+ case engine.SpriteFilledMode.Vertical:
2681
+ return origin === engine.SpriteFilledOrigin.Top || origin === engine.SpriteFilledOrigin.Bottom ? origin : engine.SpriteFilledOrigin.Bottom;
2682
+ case engine.SpriteFilledMode.Radial90:
2683
+ return origin === engine.SpriteFilledOrigin.TopLeft || origin === engine.SpriteFilledOrigin.TopRight || origin === engine.SpriteFilledOrigin.BottomLeft || origin === engine.SpriteFilledOrigin.BottomRight ? origin : engine.SpriteFilledOrigin.BottomLeft;
2684
+ default:
2685
+ return origin === engine.SpriteFilledOrigin.Top || origin === engine.SpriteFilledOrigin.Bottom || origin === engine.SpriteFilledOrigin.Left || origin === engine.SpriteFilledOrigin.Right ? origin : engine.SpriteFilledOrigin.Bottom;
2686
+ }
2687
+ };
2352
2688
  _create_class(Image, [
2353
2689
  {
2354
2690
  key: "drawMode",
@@ -2370,6 +2706,9 @@
2370
2706
  case engine.SpriteDrawMode.Tiled:
2371
2707
  this._assembler = engine.TiledSpriteAssembler;
2372
2708
  break;
2709
+ case engine.SpriteDrawMode.Filled:
2710
+ this._assembler = engine.FilledSpriteAssembler;
2711
+ break;
2373
2712
  }
2374
2713
  this._assembler.resetData(this);
2375
2714
  this._dirtyUpdateFlag |= 7;
@@ -2409,6 +2748,73 @@
2409
2748
  }
2410
2749
  }
2411
2750
  },
2751
+ {
2752
+ key: "filledAmount",
2753
+ get: /**
2754
+ * The fill amount of the image, range from 0 to 1. (Only works in filled mode.)
2755
+ */ function get() {
2756
+ return this._filledAmount;
2757
+ },
2758
+ set: function set(value) {
2759
+ value = engine.MathUtil.clamp(value, 0, 1);
2760
+ if (this._filledAmount !== value) {
2761
+ this._filledAmount = value;
2762
+ if (this._drawMode === engine.SpriteDrawMode.Filled) {
2763
+ this._dirtyUpdateFlag |= 5;
2764
+ }
2765
+ }
2766
+ }
2767
+ },
2768
+ {
2769
+ key: "filledMode",
2770
+ get: /**
2771
+ * The fill mode of the image. (Only works in filled mode.)
2772
+ */ function get() {
2773
+ return this._filledMode;
2774
+ },
2775
+ set: function set(value) {
2776
+ if (this._filledMode !== value) {
2777
+ this._filledMode = value;
2778
+ this._filledOrigin = Image._correctOrigin(value, this._filledOrigin);
2779
+ if (this._drawMode === engine.SpriteDrawMode.Filled) {
2780
+ this._dirtyUpdateFlag |= 5;
2781
+ }
2782
+ }
2783
+ }
2784
+ },
2785
+ {
2786
+ key: "filledOrigin",
2787
+ get: /**
2788
+ * The fill origin of the image. (Only works in filled mode.)
2789
+ */ function get() {
2790
+ return this._filledOrigin;
2791
+ },
2792
+ set: function set(value) {
2793
+ value = Image._correctOrigin(this._filledMode, value);
2794
+ if (this._filledOrigin !== value) {
2795
+ this._filledOrigin = value;
2796
+ if (this._drawMode === engine.SpriteDrawMode.Filled) {
2797
+ this._dirtyUpdateFlag |= 5;
2798
+ }
2799
+ }
2800
+ }
2801
+ },
2802
+ {
2803
+ key: "filledClockWise",
2804
+ get: /**
2805
+ * Whether the fill is clockwise. (Only works in filled radial mode.)
2806
+ */ function get() {
2807
+ return this._filledClockWise;
2808
+ },
2809
+ set: function set(value) {
2810
+ if (this._filledClockWise !== value) {
2811
+ this._filledClockWise = value;
2812
+ if (this._drawMode === engine.SpriteDrawMode.Filled) {
2813
+ this._dirtyUpdateFlag |= 5;
2814
+ }
2815
+ }
2816
+ }
2817
+ },
2412
2818
  {
2413
2819
  key: "sprite",
2414
2820
  get: /**
@@ -2449,12 +2855,6 @@
2449
2855
  __decorate([
2450
2856
  engine.ignoreClone
2451
2857
  ], Image.prototype, "_assembler", void 0);
2452
- __decorate([
2453
- engine.assignmentClone
2454
- ], Image.prototype, "_tileMode", void 0);
2455
- __decorate([
2456
- engine.assignmentClone
2457
- ], Image.prototype, "_tiledAdaptiveThreshold", void 0);
2458
2858
  __decorate([
2459
2859
  engine.ignoreClone
2460
2860
  ], Image.prototype, "_onTransformChanged", null);
@@ -2462,19 +2862,87 @@
2462
2862
  engine.ignoreClone
2463
2863
  ], Image.prototype, "_onSpriteChange", null);
2464
2864
 
2865
+ /**
2866
+ * UI component that uses a sprite to mask child UI renderers via stencil.
2867
+ */ var Mask = /*#__PURE__*/ function(_MaskRenderable) {
2868
+ _inherits(Mask, _MaskRenderable);
2869
+ function Mask(entity) {
2870
+ var _this;
2871
+ _this = _MaskRenderable.call(this, entity) || this;
2872
+ _this._initMask();
2873
+ _this.raycastEnabled = false;
2874
+ return _this;
2875
+ }
2876
+ var _proto = Mask.prototype;
2877
+ /**
2878
+ * @internal
2879
+ */ _proto._getChunkManager = function _getChunkManager() {
2880
+ // @ts-ignore
2881
+ return this.engine._batcherManager.primitiveChunkManagerMask;
2882
+ };
2883
+ /**
2884
+ * @internal
2885
+ */ // @ts-ignore
2886
+ _proto._cloneTo = function _cloneTo(target) {
2887
+ // @ts-ignore
2888
+ _MaskRenderable.prototype._cloneTo.call(this, target);
2889
+ this._cloneMaskData(target);
2890
+ };
2891
+ _proto._updateBounds = function _updateBounds(worldBounds) {
2892
+ var rootCanvas = this._getRootCanvas();
2893
+ if (this.sprite && rootCanvas) {
2894
+ this._updateMaskBounds(worldBounds);
2895
+ } else {
2896
+ var worldPosition = this._transformEntity.transform.worldPosition;
2897
+ worldBounds.min.copyFrom(worldPosition);
2898
+ worldBounds.max.copyFrom(worldPosition);
2899
+ }
2900
+ };
2901
+ /**
2902
+ * @inheritdoc
2903
+ */ _proto._render = function _render(context) {
2904
+ this._renderMask(0);
2905
+ };
2906
+ /**
2907
+ * @inheritdoc
2908
+ */ _proto._onDestroy = function _onDestroy() {
2909
+ this._destroyMaskResources();
2910
+ _MaskRenderable.prototype._onDestroy.call(this);
2911
+ if (this._subChunk) {
2912
+ this._getChunkManager().freeSubChunk(this._subChunk);
2913
+ this._subChunk = null;
2914
+ }
2915
+ };
2916
+ _proto._getSpriteWidth = function _getSpriteWidth() {
2917
+ return this._transformEntity.transform.size.x;
2918
+ };
2919
+ _proto._getSpriteHeight = function _getSpriteHeight() {
2920
+ return this._transformEntity.transform.size.y;
2921
+ };
2922
+ _proto._getSpritePivot = function _getSpritePivot() {
2923
+ return this._transformEntity.transform.pivot;
2924
+ };
2925
+ return Mask;
2926
+ }(engine.MaskRenderable(exports.UIRenderer));
2927
+
2465
2928
  /**
2466
2929
  * UI component used to render text.
2467
2930
  */ var Text = /*#__PURE__*/ function(UIRenderer1) {
2468
2931
  _inherits(Text, UIRenderer1);
2469
2932
  function Text(entity) {
2470
2933
  var _this;
2471
- _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;
2934
+ _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, _this._outlineColor = new engine.Color(0, 0, 0, 1), _this._outlineWidth = 0;
2472
2935
  var engine$1 = _this.engine;
2473
2936
  // @ts-ignore
2474
2937
  _this.font = engine$1._textDefaultFont;
2475
2938
  _this.raycastEnabled = false;
2476
2939
  // @ts-ignore
2477
2940
  _this.setMaterial(engine$1._basicResources.textDefaultMaterial);
2941
+ var shaderData = _this.shaderData;
2942
+ shaderData.setFloat(Text._outlineWidthProperty, _this._outlineWidth);
2943
+ shaderData.setColor(Text._outlineColorProperty, _this._outlineColor);
2944
+ // @ts-ignore
2945
+ _this._outlineColor._onValueChanged = _this._onOutlineColorChanged.bind(_this);
2478
2946
  return _this;
2479
2947
  }
2480
2948
  var _proto = Text.prototype;
@@ -2490,13 +2958,6 @@
2490
2958
  this._textChunks = null;
2491
2959
  this._subFont && (this._subFont = null);
2492
2960
  };
2493
- // @ts-ignore
2494
- _proto._cloneTo = function _cloneTo(target) {
2495
- // @ts-ignore
2496
- UIRenderer1.prototype._cloneTo.call(this, target);
2497
- target.font = this._font;
2498
- target._subFont = this._subFont;
2499
- };
2500
2961
  /**
2501
2962
  * @internal
2502
2963
  */ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
@@ -2527,13 +2988,13 @@
2527
2988
  this._setDirtyFlagTrue(25);
2528
2989
  }
2529
2990
  };
2991
+ /**
2992
+ * @internal
2993
+ */ _proto._canBatch = function _canBatch(preElement, curElement) {
2994
+ return engine.VertexMergeBatcher.canBatchText(preElement, curElement);
2995
+ };
2530
2996
  _proto._updateBounds = function _updateBounds(worldBounds) {
2531
- var transform = this._transformEntity.transform;
2532
- var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2533
- var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
2534
- worldBounds.min.set(-width * pivotX, -height * pivotY, 0);
2535
- worldBounds.max.set(width * (1 - pivotX), height * (1 - pivotY), 0);
2536
- engine.BoundingBox.transform(worldBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2997
+ engine.BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2537
2998
  };
2538
2999
  _proto._render = function _render(context) {
2539
3000
  if (this._isTextNoVisible()) {
@@ -2564,6 +3025,7 @@
2564
3025
  var distanceForSort = canvas._sortDistance;
2565
3026
  var textChunks = this._textChunks;
2566
3027
  var subShader = material.shader.subShaders[0];
3028
+ var textTextureSize = Text._tempVec20;
2567
3029
  for(var i = 0, n = textChunks.length; i < n; ++i){
2568
3030
  var // @ts-ignore
2569
3031
  _renderElement;
@@ -2572,6 +3034,7 @@
2572
3034
  renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
2573
3035
  (_renderElement = renderElement).shaderData || (_renderElement.shaderData = new engine.ShaderData(engine.ShaderDataGroup.RenderElement));
2574
3036
  renderElement.shaderData.setTexture(Text._textTextureProperty, texture);
3037
+ renderElement.shaderData.setVector2(Text._textTextureSizeProperty, textTextureSize.set(texture.width, texture.height));
2575
3038
  renderElement.subShader = subShader;
2576
3039
  renderElement.priority = priority;
2577
3040
  renderElement.distanceForSort = distanceForSort;
@@ -2584,6 +3047,15 @@
2584
3047
  this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
2585
3048
  this._subFont.nativeFontString = engine.TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
2586
3049
  };
3050
+ /**
3051
+ * Switch the sub font to a specific font size, used by the SHRINK overflow measurement.
3052
+ */ _proto._applyFontSizeForShrink = function _applyFontSizeForShrink(fontSize) {
3053
+ var font = this._font;
3054
+ // @ts-ignore
3055
+ var subFont = font._getSubFont(fontSize, this._fontStyle);
3056
+ subFont.nativeFontString = engine.TextUtils.getNativeFontString(font.name, fontSize, this._fontStyle);
3057
+ this._subFont = subFont;
3058
+ };
2587
3059
  _proto._updatePosition = function _updatePosition() {
2588
3060
  var e = this._transformEntity.transform.worldMatrix.elements;
2589
3061
  // prettier-ignore
@@ -2636,18 +3108,30 @@
2636
3108
  }
2637
3109
  };
2638
3110
  _proto._updateLocalData = function _updateLocalData() {
3111
+ var _this = this;
2639
3112
  // @ts-ignore
2640
3113
  var pixelsPerResolution = engine.Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
2641
3114
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
2642
3115
  var charRenderInfos = Text._charRenderInfos;
2643
- var charFont = this._getSubFont();
2644
3116
  var _this__transformEntity_transform = this._transformEntity.transform, size = _this__transformEntity_transform.size, pivot = _this__transformEntity_transform.pivot;
2645
3117
  var rendererWidth = size.x;
2646
3118
  var rendererHeight = size.y;
2647
3119
  var offsetWidth = rendererWidth * (0.5 - pivot.x);
2648
3120
  var offsetHeight = rendererHeight * (0.5 - pivot.y);
2649
- var characterSpacing = this._characterSpacing * this._fontSize;
2650
- 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);
3121
+ var fontSize = this._fontSize;
3122
+ var textMetrics;
3123
+ if (this._overflowMode === engine.OverflowMode.Shrink) {
3124
+ var result = engine.TextUtils.measureTextWithShrink(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._fontSize, this._lineSpacing, this._characterSpacing, this.enableWrapping, function(sizeValue) {
3125
+ return _this._applyFontSizeForShrink(sizeValue);
3126
+ });
3127
+ fontSize = result.fontSize;
3128
+ textMetrics = result.metrics;
3129
+ } else {
3130
+ var characterSpacing = this._characterSpacing * fontSize;
3131
+ textMetrics = this.enableWrapping ? engine.TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * fontSize, characterSpacing) : engine.TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * fontSize, characterSpacing);
3132
+ }
3133
+ var charFont = this._getSubFont();
3134
+ var characterSpacing1 = this._characterSpacing * fontSize;
2651
3135
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
2652
3136
  // @ts-ignore
2653
3137
  var charRenderInfoPool = this.engine._charRenderInfoPool;
@@ -2668,7 +3152,10 @@
2668
3152
  startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
2669
3153
  break;
2670
3154
  case engine.TextVerticalAlignment.Center:
2671
- startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
3155
+ // Center the text block (lineHeight * lineCount) within the renderer, independent of
3156
+ // `height` — which equals the renderer height for Truncate/Shrink and would otherwise
3157
+ // push the text upward by (rendererHeight - blockHeight) / 2 when the box is taller.
3158
+ startY = lineHeight * linesLen * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
2672
3159
  break;
2673
3160
  case engine.TextVerticalAlignment.Bottom:
2674
3161
  startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
@@ -2709,17 +3196,18 @@
2709
3196
  charRenderInfo.texture = charFont._getTextureByIndex(charInfo.index);
2710
3197
  charRenderInfo.uvs = charInfo.uvs;
2711
3198
  var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
2712
- var left = (startX + offsetWidth) * pixelsPerUnitReciprocal;
2713
- var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal;
2714
- var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal;
2715
- var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal;
3199
+ var ow = this._outlineWidth * pixelsPerUnitReciprocal;
3200
+ var left = (startX + offsetWidth) * pixelsPerUnitReciprocal - ow;
3201
+ var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal + ow;
3202
+ var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal + ow;
3203
+ var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal - ow;
2716
3204
  localPositions.set(left, top, right, bottom);
2717
3205
  i === firstLine && (maxY = Math.max(maxY, top));
2718
3206
  minY = Math.min(minY, bottom);
2719
3207
  j === firstRow && (minX = Math.min(minX, left));
2720
3208
  maxX = Math.max(maxX, right);
2721
3209
  }
2722
- startX += charInfo.xAdvance + characterSpacing;
3210
+ startX += charInfo.xAdvance + characterSpacing1;
2723
3211
  }
2724
3212
  }
2725
3213
  startY -= lineHeight;
@@ -2779,7 +3267,7 @@
2779
3267
  };
2780
3268
  _proto._isTextNoVisible = function _isTextNoVisible() {
2781
3269
  var size = this._transformEntity.transform.size;
2782
- return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === engine.OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
3270
+ return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || (this.overflowMode === engine.OverflowMode.Truncate || this.overflowMode === engine.OverflowMode.Shrink) && size.y <= 0 || !this._getRootCanvas();
2783
3271
  };
2784
3272
  _proto._buildChunk = function _buildChunk(textChunk, count) {
2785
3273
  var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
@@ -2790,6 +3278,10 @@
2790
3278
  var vertices = subChunk.chunk.vertices;
2791
3279
  var indices = subChunk.indices = [];
2792
3280
  var charRenderInfos = textChunk.charRenderInfos;
3281
+ var ow = this._outlineWidth;
3282
+ var texture = textChunk.texture;
3283
+ var owU = ow > 0 ? ow / texture.width : 0;
3284
+ var owV = ow > 0 ? ow / texture.height : 0;
2793
3285
  for(var i = 0, ii = 0, io = 0, vo = subChunk.vertexArea.start + 3; i < count; ++i, io += 4){
2794
3286
  var charRenderInfo = charRenderInfos[i];
2795
3287
  charRenderInfo.indexInChunk = i;
@@ -2797,10 +3289,13 @@
2797
3289
  for(var j = 0; j < tempIndicesLength; ++j){
2798
3290
  indices[ii++] = tempIndices[j] + io;
2799
3291
  }
2800
- // Set uv and color for vertices
3292
+ // Set uv and color for vertices, expand uv outward by outline width
2801
3293
  for(var j1 = 0; j1 < 4; ++j1, vo += 9){
2802
3294
  var uv = charRenderInfo.uvs[j1];
2803
- uv.copyToArray(vertices, vo);
3295
+ var su = j1 === 1 || j1 === 2 ? 1 : -1;
3296
+ var sv = j1 >= 2 ? 1 : -1;
3297
+ vertices[vo] = uv.x + owU * su;
3298
+ vertices[vo + 1] = uv.y + owV * sv;
2804
3299
  vertices[vo + 2] = r;
2805
3300
  vertices[vo + 3] = g;
2806
3301
  vertices[vo + 4] = b;
@@ -2827,6 +3322,9 @@
2827
3322
  }
2828
3323
  textChunks.length = 0;
2829
3324
  };
3325
+ _proto._onOutlineColorChanged = function _onOutlineColorChanged() {
3326
+ this.shaderData.setColor(Text._outlineColorProperty, this._outlineColor);
3327
+ };
2830
3328
  _create_class(Text, [
2831
3329
  {
2832
3330
  key: "text",
@@ -2973,14 +3471,32 @@
2973
3471
  }
2974
3472
  },
2975
3473
  {
2976
- key: "maskLayer",
3474
+ key: "outlineWidth",
2977
3475
  get: /**
2978
- * The mask layer the sprite renderer belongs to.
3476
+ * The outline width in pixels. 0 means outline is disabled. Clamped to [0, 8].
2979
3477
  */ function get() {
2980
- return this._maskLayer;
3478
+ return this._outlineWidth;
2981
3479
  },
2982
3480
  set: function set(value) {
2983
- this._maskLayer = value;
3481
+ value = Math.max(0, Math.min(value, 3));
3482
+ if (this._outlineWidth !== value) {
3483
+ this._outlineWidth = value;
3484
+ this.shaderData.setFloat(Text._outlineWidthProperty, value);
3485
+ this._setDirtyFlagTrue(25);
3486
+ }
3487
+ }
3488
+ },
3489
+ {
3490
+ key: "outlineColor",
3491
+ get: /**
3492
+ * The outline color. Only effective when outlineWidth > 0.
3493
+ */ function get() {
3494
+ return this._outlineColor;
3495
+ },
3496
+ set: function set(value) {
3497
+ if (this._outlineColor !== value) {
3498
+ this._outlineColor.copyFrom(value);
3499
+ }
2984
3500
  }
2985
3501
  },
2986
3502
  {
@@ -2991,8 +3507,14 @@
2991
3507
  if (this._isTextNoVisible()) {
2992
3508
  if (this._isContainDirtyFlag(engine.RendererUpdateFlags.WorldVolume)) {
2993
3509
  var localBounds = this._localBounds;
2994
- localBounds.min.set(0, 0, 0);
2995
- localBounds.max.set(0, 0, 0);
3510
+ if (this._getRootCanvas()) {
3511
+ localBounds.min.set(0, 0, 0);
3512
+ localBounds.max.set(0, 0, 0);
3513
+ } else {
3514
+ var _this_entity_transform = this.entity.transform, size = _this_entity_transform.size, pivot = _this_entity_transform.pivot;
3515
+ localBounds.min.set(-size.x * pivot.x, -size.y * pivot.y, 0);
3516
+ localBounds.max.set(size.x * (1 - pivot.x), size.y * (1 - pivot.y), 0);
3517
+ }
2996
3518
  this._updateBounds(this._bounds);
2997
3519
  this._setDirtyFlagFalse(engine.RendererUpdateFlags.WorldVolume);
2998
3520
  }
@@ -3010,6 +3532,9 @@
3010
3532
  return Text;
3011
3533
  }(exports.UIRenderer);
3012
3534
  Text._textTextureProperty = engine.ShaderProperty.getByName("renderElement_TextTexture");
3535
+ Text._textTextureSizeProperty = engine.ShaderProperty.getByName("renderElement_TextTextureSize");
3536
+ Text._outlineColorProperty = engine.ShaderProperty.getByName("renderer_OutlineColor");
3537
+ Text._outlineWidthProperty = engine.ShaderProperty.getByName("renderer_OutlineWidth");
3013
3538
  Text._worldPositions = [
3014
3539
  new engine.Vector3(),
3015
3540
  new engine.Vector3(),
@@ -3023,62 +3548,44 @@
3023
3548
  __decorate([
3024
3549
  engine.ignoreClone
3025
3550
  ], Text.prototype, "_subFont", void 0);
3026
- __decorate([
3027
- engine.assignmentClone
3028
- ], Text.prototype, "_text", void 0);
3029
3551
  __decorate([
3030
3552
  engine.ignoreClone
3031
3553
  ], Text.prototype, "_localBounds", void 0);
3032
- __decorate([
3033
- engine.assignmentClone
3034
- ], Text.prototype, "_font", void 0);
3035
- __decorate([
3036
- engine.assignmentClone
3037
- ], Text.prototype, "_fontSize", void 0);
3038
- __decorate([
3039
- engine.assignmentClone
3040
- ], Text.prototype, "_fontStyle", void 0);
3041
- __decorate([
3042
- engine.assignmentClone
3043
- ], Text.prototype, "_lineSpacing", void 0);
3044
- __decorate([
3045
- engine.assignmentClone
3046
- ], Text.prototype, "_characterSpacing", void 0);
3047
- __decorate([
3048
- engine.assignmentClone
3049
- ], Text.prototype, "_horizontalAlignment", void 0);
3050
- __decorate([
3051
- engine.assignmentClone
3052
- ], Text.prototype, "_verticalAlignment", void 0);
3053
- __decorate([
3054
- engine.assignmentClone
3055
- ], Text.prototype, "_enableWrapping", void 0);
3056
- __decorate([
3057
- engine.assignmentClone
3058
- ], Text.prototype, "_overflowMode", void 0);
3059
3554
  __decorate([
3060
3555
  engine.ignoreClone
3061
3556
  ], Text.prototype, "_onTransformChanged", null);
3557
+ __decorate([
3558
+ engine.ignoreClone
3559
+ ], Text.prototype, "_onOutlineColorChanged", null);
3062
3560
  var TextChunk = function TextChunk() {
3063
3561
  this.charRenderInfos = new Array();
3064
3562
  };
3065
3563
 
3066
3564
  /**
3067
3565
  * The transition behavior of UIInteractive.
3068
- */ var Transition = /*#__PURE__*/ function() {
3566
+ */ var Transition = /*#__PURE__*/ function(DataObject) {
3567
+ _inherits(Transition, DataObject);
3069
3568
  function Transition() {
3070
- this._duration = 0;
3071
- this._countDown = 0;
3072
- this._finalState = InteractiveState.Normal;
3569
+ var _this;
3570
+ _this = DataObject.apply(this, arguments) || this, _this._duration = 0, _this._countDown = 0, _this._finalState = InteractiveState.Normal;
3571
+ return _this;
3073
3572
  }
3074
3573
  var _proto = Transition.prototype;
3075
3574
  _proto.destroy = function destroy() {
3076
3575
  var _this__interactive;
3077
3576
  (_this__interactive = this._interactive) == null ? void 0 : _this__interactive.removeTransition(this);
3577
+ this._addStateValuesReferCount(-1);
3578
+ this._normal = this._pressed = this._hover = this._disabled = null;
3579
+ this._initialValue = this._currentValue = this._finalValue = null;
3078
3580
  this._target = null;
3079
3581
  };
3080
3582
  /**
3081
3583
  * @internal
3584
+ */ _proto._cloneTo = function _cloneTo(target) {
3585
+ target._addStateValuesReferCount(1);
3586
+ };
3587
+ /**
3588
+ * @internal
3082
3589
  */ _proto._setState = function _setState(state, instant) {
3083
3590
  this._finalState = state;
3084
3591
  var value = this._getValueByState(state);
@@ -3116,6 +3623,17 @@
3116
3623
  this._updateCurrentValue(this._initialValue, this._finalValue, weight);
3117
3624
  ((_this__target = this._target) == null ? void 0 : _this__target.enabled) && this._applyValue(this._currentValue);
3118
3625
  };
3626
+ _proto._addStateValuesReferCount = function _addStateValuesReferCount(count) {
3627
+ var _this = this, _normal = _this._normal, _pressed = _this._pressed, _hover = _this._hover, _disabled = _this._disabled;
3628
+ // @ts-ignore
3629
+ _instanceof(_normal, engine.ReferResource) && _normal._addReferCount(count);
3630
+ // @ts-ignore
3631
+ _instanceof(_pressed, engine.ReferResource) && _pressed._addReferCount(count);
3632
+ // @ts-ignore
3633
+ _instanceof(_hover, engine.ReferResource) && _hover._addReferCount(count);
3634
+ // @ts-ignore
3635
+ _instanceof(_disabled, engine.ReferResource) && _disabled._addReferCount(count);
3636
+ };
3119
3637
  _proto._getValueByState = function _getValueByState(state) {
3120
3638
  switch(state){
3121
3639
  case InteractiveState.Normal:
@@ -3224,7 +3742,22 @@
3224
3742
  }
3225
3743
  ]);
3226
3744
  return Transition;
3227
- }();
3745
+ }(engine.DataObject);
3746
+ __decorate([
3747
+ engine.ignoreClone
3748
+ ], Transition.prototype, "_countDown", void 0);
3749
+ __decorate([
3750
+ engine.ignoreClone
3751
+ ], Transition.prototype, "_initialValue", void 0);
3752
+ __decorate([
3753
+ engine.ignoreClone
3754
+ ], Transition.prototype, "_finalValue", void 0);
3755
+ __decorate([
3756
+ engine.ignoreClone
3757
+ ], Transition.prototype, "_currentValue", void 0);
3758
+ __decorate([
3759
+ engine.ignoreClone
3760
+ ], Transition.prototype, "_finalState", void 0);
3228
3761
 
3229
3762
  /**
3230
3763
  * Color transition.
@@ -3333,33 +3866,6 @@
3333
3866
  return Transition.apply(this, arguments) || this;
3334
3867
  }
3335
3868
  var _proto = SpriteTransition.prototype;
3336
- /**
3337
- * @internal
3338
- */ _proto.destroy = function destroy() {
3339
- Transition.prototype.destroy.call(this);
3340
- if (this._normal) {
3341
- // @ts-ignore
3342
- this._normal._addReferCount(-1);
3343
- this._normal = null;
3344
- }
3345
- if (this._hover) {
3346
- // @ts-ignore
3347
- this._hover._addReferCount(-1);
3348
- this._hover = null;
3349
- }
3350
- if (this._pressed) {
3351
- // @ts-ignore
3352
- this._pressed._addReferCount(-1);
3353
- this._pressed = null;
3354
- }
3355
- if (this._disabled) {
3356
- // @ts-ignore
3357
- this._disabled._addReferCount(-1);
3358
- this._disabled = null;
3359
- }
3360
- this._initialValue = this._currentValue = this._finalValue = null;
3361
- this._target = null;
3362
- };
3363
3869
  _proto._getTargetValueCopy = function _getTargetValueCopy() {
3364
3870
  var _this__target;
3365
3871
  return (_this__target = this._target) == null ? void 0 : _this__target.sprite;
@@ -3375,17 +3881,19 @@
3375
3881
 
3376
3882
  var GUIComponent = /*#__PURE__*/Object.freeze({
3377
3883
  __proto__: null,
3378
- get UICanvas () { return exports.UICanvas; },
3379
- UIGroup: UIGroup,
3380
- get UIRenderer () { return exports.UIRenderer; },
3381
- UITransform: UITransform,
3382
3884
  Button: Button,
3383
3885
  Image: Image,
3886
+ Mask: Mask,
3887
+ get RectMask2D () { return exports.RectMask2D; },
3384
3888
  Text: Text,
3385
3889
  ColorTransition: ColorTransition,
3386
3890
  ScaleTransition: ScaleTransition,
3387
3891
  SpriteTransition: SpriteTransition,
3388
- Transition: Transition
3892
+ Transition: Transition,
3893
+ get UICanvas () { return exports.UICanvas; },
3894
+ UIGroup: UIGroup,
3895
+ get UIRenderer () { return exports.UIRenderer; },
3896
+ UITransform: UITransform
3389
3897
  });
3390
3898
 
3391
3899
  /**
@@ -3464,11 +3972,11 @@
3464
3972
  }
3465
3973
  }
3466
3974
  if (camera.clearFlags & engine.CameraClearFlags.Color) {
3467
- this._updateRaycast(null);
3975
+ this._updateRaycast(null, pointer);
3468
3976
  return;
3469
3977
  }
3470
3978
  }
3471
- this._updateRaycast(null);
3979
+ this._updateRaycast(null, pointer);
3472
3980
  }
3473
3981
  };
3474
3982
  _proto.processDrag = function processDrag(pointer) {
@@ -3498,10 +4006,7 @@
3498
4006
  if (pressedPath.length > 0) {
3499
4007
  var common = UIPointerEventEmitter._tempArray0;
3500
4008
  if (this._findCommonInPath(enteredPath, pressedPath, common)) {
3501
- var eventData = this._createEventData(pointer);
3502
- for(var i = 0, n = common.length; i < n; i++){
3503
- this._fireClick(common[i], eventData);
3504
- }
4009
+ this._bubble(common, pointer, this._fireClick);
3505
4010
  common.length = 0;
3506
4011
  }
3507
4012
  }
@@ -3533,18 +4038,16 @@
3533
4038
  this._enteredPath.length = this._pressedPath.length = this._draggedPath.length = 0;
3534
4039
  };
3535
4040
  _proto._updateRaycast = function _updateRaycast(element, pointer) {
3536
- if (pointer === void 0) pointer = null;
3537
4041
  var enteredPath = this._enteredPath;
3538
4042
  var curPath = this._composedPath(element, UIPointerEventEmitter._path);
3539
4043
  var add = UIPointerEventEmitter._tempArray0;
3540
4044
  var del = UIPointerEventEmitter._tempArray1;
3541
4045
  if (this._findDiffInPath(enteredPath, curPath, add, del)) {
3542
- var eventData = this._createEventData(pointer);
3543
4046
  for(var i = 0, n = add.length; i < n; i++){
3544
- this._fireEnter(add[i], eventData);
4047
+ this._fireEnter(add[i], this._createEventData(pointer, add[i]));
3545
4048
  }
3546
4049
  for(var i1 = 0, n1 = del.length; i1 < n1; i1++){
3547
- this._fireExit(del[i1], eventData);
4050
+ this._fireExit(del[i1], this._createEventData(pointer, del[i1]));
3548
4051
  }
3549
4052
  var length = enteredPath.length = curPath.length;
3550
4053
  for(var i2 = 0; i2 < length; i2++){
@@ -3614,8 +4117,9 @@
3614
4117
  _proto._bubble = function _bubble(path, pointer, fireEvent) {
3615
4118
  var length = path.length;
3616
4119
  if (length <= 0) return;
3617
- var eventData = this._createEventData(pointer);
4120
+ var eventData = this._createEventData(pointer, path[0]);
3618
4121
  for(var i = 0; i < length; i++){
4122
+ eventData.currentTarget = path[i];
3619
4123
  fireEvent(path[i], eventData);
3620
4124
  }
3621
4125
  };
@@ -3692,6 +4196,7 @@
3692
4196
  exports.EntityExtension = EntityExtension;
3693
4197
  exports.HorizontalAlignmentMode = HorizontalAlignmentMode;
3694
4198
  exports.Image = Image;
4199
+ exports.Mask = Mask;
3695
4200
  exports.ResolutionAdaptationMode = ResolutionAdaptationMode;
3696
4201
  exports.ScaleTransition = ScaleTransition;
3697
4202
  exports.SpriteTransition = SpriteTransition;