@galacean/engine-ui 0.0.0-experimental-2.0-migrate.5 → 0.0.0-experimental-2.0-skill.0

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