@galacean/engine-ui 0.0.0-experimental-2.0-migrate.6 → 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.
@@ -0,0 +1,3618 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@galacean/engine')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@galacean/engine'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Galacean = global.Galacean || {}, global.Galacean.UI = {}), global.Galacean));
5
+ })(this, (function (exports, engine) { 'use strict';
6
+
7
+ function _defineProperties(target, props) {
8
+ for (var i = 0; i < props.length; i++) {
9
+ var descriptor = props[i];
10
+ descriptor.enumerable = descriptor.enumerable || false;
11
+ descriptor.configurable = true;
12
+
13
+ if ("value" in descriptor) descriptor.writable = true;
14
+
15
+ Object.defineProperty(target, descriptor.key, descriptor);
16
+ }
17
+ }
18
+ function _create_class(Constructor, protoProps, staticProps) {
19
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
20
+ if (staticProps) _defineProperties(Constructor, staticProps);
21
+
22
+ return Constructor;
23
+ }
24
+
25
+ function _set_prototype_of(o, p) {
26
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
27
+ o.__proto__ = p;
28
+
29
+ return o;
30
+ };
31
+
32
+ return _set_prototype_of(o, p);
33
+ }
34
+
35
+ function _inherits(subClass, superClass) {
36
+ if (typeof superClass !== "function" && superClass !== null) {
37
+ throw new TypeError("Super expression must either be null or a function");
38
+ }
39
+
40
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
41
+
42
+ if (superClass) _set_prototype_of(subClass, superClass);
43
+ }
44
+
45
+ function _instanceof(left, right) {
46
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
47
+ return !!right[Symbol.hasInstance](left);
48
+ } else return left instanceof right;
49
+ }
50
+
51
+ /******************************************************************************
52
+ Copyright (c) Microsoft Corporation.
53
+
54
+ Permission to use, copy, modify, and/or distribute this software for any
55
+ purpose with or without fee is hereby granted.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
58
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
59
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
60
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
61
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
62
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
63
+ PERFORMANCE OF THIS SOFTWARE.
64
+ ***************************************************************************** */
65
+
66
+ function __decorate(decorators, target, key, desc) {
67
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
68
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
69
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
70
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
71
+ }
72
+
73
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
74
+ var e = new Error(message);
75
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
76
+ };
77
+
78
+ var UIGroup = /*#__PURE__*/ function(Component) {
79
+ _inherits(UIGroup, Component);
80
+ function UIGroup(entity) {
81
+ var _this;
82
+ _this = Component.call(this, entity) || this, /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._disorderedElements = new engine.DisorderedArray(), /** @internal */ _this._globalAlpha = 1, /** @internal */ _this._globalInteractive = true, _this._alpha = 1, _this._interactive = true, _this._ignoreParentGroup = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupDirtyFlags = 0;
83
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
84
+ _this._groupListener = _this._groupListener.bind(_this);
85
+ return _this;
86
+ }
87
+ var _proto = UIGroup.prototype;
88
+ /**
89
+ * @internal
90
+ */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
91
+ if (this._isContainDirtyFlag(1)) {
92
+ if (this._ignoreParentGroup) {
93
+ this._globalAlpha = this._alpha;
94
+ } else {
95
+ var parentGroup = this._getGroup();
96
+ this._globalAlpha = this._alpha * (parentGroup ? parentGroup._getGlobalAlpha() : 1);
97
+ }
98
+ this._setDirtyFlagFalse(1);
99
+ }
100
+ return this._globalAlpha;
101
+ };
102
+ /**
103
+ * @internal
104
+ */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
105
+ if (this._isContainDirtyFlag(2)) {
106
+ if (this._ignoreParentGroup) {
107
+ this._globalInteractive = this._interactive;
108
+ } else {
109
+ var parentGroup = this._getGroup();
110
+ this._globalInteractive = this._interactive && (!parentGroup || parentGroup._getGlobalInteractive());
111
+ }
112
+ this._setDirtyFlagFalse(2);
113
+ }
114
+ return this._globalInteractive;
115
+ };
116
+ // @ts-ignore
117
+ _proto._onEnableInScene = function _onEnableInScene() {
118
+ Utils.setRootCanvasDirty(this);
119
+ Utils.setGroupDirty(this);
120
+ // @ts-ignore
121
+ this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
122
+ };
123
+ // @ts-ignore
124
+ _proto._onDisableInScene = function _onDisableInScene() {
125
+ Utils.cleanRootCanvas(this);
126
+ Utils.cleanGroup(this);
127
+ var disorderedElements = this._disorderedElements;
128
+ disorderedElements.forEach(function(element) {
129
+ Utils.setGroupDirty(element);
130
+ });
131
+ disorderedElements.length = 0;
132
+ disorderedElements.garbageCollection();
133
+ this._isRootCanvasDirty = this._isGroupDirty = false;
134
+ };
135
+ /**
136
+ * @internal
137
+ */ _proto._getRootCanvas = function _getRootCanvas() {
138
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
139
+ return this._rootCanvas;
140
+ };
141
+ /**
142
+ * @internal
143
+ */ _proto._getGroup = function _getGroup() {
144
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
145
+ return this._group;
146
+ };
147
+ /**
148
+ * @internal
149
+ */ _proto._groupListener = function _groupListener(flag) {
150
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
151
+ Utils.setGroupDirty(this);
152
+ }
153
+ };
154
+ /**
155
+ * @internal
156
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
157
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
158
+ Utils.setRootCanvasDirty(this);
159
+ Utils.setGroupDirty(this);
160
+ }
161
+ };
162
+ /**
163
+ * @internal
164
+ */ _proto._onGroupModify = function _onGroupModify(flags, isPass) {
165
+ if (isPass === void 0) isPass = false;
166
+ if (isPass && this._ignoreParentGroup) return;
167
+ if (this._isContainDirtyFlags(flags)) return;
168
+ this._setDirtyFlagTrue(flags);
169
+ this._disorderedElements.forEach(function(element) {
170
+ element._onGroupModify(flags, true);
171
+ });
172
+ };
173
+ _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
174
+ return (this._groupDirtyFlags & targetDirtyFlags) === targetDirtyFlags;
175
+ };
176
+ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
177
+ return (this._groupDirtyFlags & type) != 0;
178
+ };
179
+ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
180
+ this._groupDirtyFlags |= type;
181
+ };
182
+ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
183
+ this._groupDirtyFlags &= ~type;
184
+ };
185
+ _create_class(UIGroup, [
186
+ {
187
+ key: "ignoreParentGroup",
188
+ get: /**
189
+ * Whether to ignore the parent group.
190
+ * @remarks If this parameter set to `true`,
191
+ * all settings of the parent group will be ignored.
192
+ */ function get() {
193
+ return this._ignoreParentGroup;
194
+ },
195
+ set: function set(value) {
196
+ if (this._ignoreParentGroup !== value) {
197
+ this._ignoreParentGroup = value;
198
+ this._onGroupModify(3);
199
+ }
200
+ }
201
+ },
202
+ {
203
+ key: "interactive",
204
+ get: /**
205
+ * Whether the group is interactive.
206
+ */ function get() {
207
+ return this._interactive;
208
+ },
209
+ set: function set(value) {
210
+ if (this._interactive !== value) {
211
+ this._interactive = value;
212
+ this._onGroupModify(2);
213
+ }
214
+ }
215
+ },
216
+ {
217
+ key: "alpha",
218
+ get: /**
219
+ * The alpha value of the group.
220
+ */ function get() {
221
+ return this._alpha;
222
+ },
223
+ set: function set(value) {
224
+ value = Math.max(0, Math.min(value, 1));
225
+ if (this._alpha !== value) {
226
+ this._alpha = value;
227
+ this._onGroupModify(1);
228
+ }
229
+ }
230
+ }
231
+ ]);
232
+ return UIGroup;
233
+ }(engine.Component);
234
+ __decorate([
235
+ engine.ignoreClone
236
+ ], UIGroup.prototype, "_indexInGroup", void 0);
237
+ __decorate([
238
+ engine.ignoreClone
239
+ ], UIGroup.prototype, "_indexInRootCanvas", void 0);
240
+ __decorate([
241
+ engine.ignoreClone
242
+ ], UIGroup.prototype, "_globalAlpha", void 0);
243
+ __decorate([
244
+ engine.ignoreClone
245
+ ], UIGroup.prototype, "_globalInteractive", void 0);
246
+ __decorate([
247
+ engine.ignoreClone
248
+ ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
249
+ __decorate([
250
+ engine.ignoreClone
251
+ ], UIGroup.prototype, "_groupListeningEntities", void 0);
252
+ __decorate([
253
+ engine.ignoreClone
254
+ ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
255
+ __decorate([
256
+ engine.ignoreClone
257
+ ], UIGroup.prototype, "_isGroupDirty", void 0);
258
+ __decorate([
259
+ engine.ignoreClone
260
+ ], UIGroup.prototype, "_groupDirtyFlags", void 0);
261
+ __decorate([
262
+ engine.ignoreClone
263
+ ], UIGroup.prototype, "_groupListener", null);
264
+ __decorate([
265
+ engine.ignoreClone
266
+ ], UIGroup.prototype, "_rootCanvasListener", null);
267
+ var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
268
+ GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
269
+ GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
270
+ GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
271
+ GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
272
+ return GroupModifyFlags;
273
+ }({});
274
+
275
+ var Utils = /*#__PURE__*/ function() {
276
+ function Utils() {}
277
+ Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
278
+ if (element._isRootCanvasDirty) return;
279
+ element._isRootCanvasDirty = true;
280
+ this._registerRootCanvas(element, null);
281
+ element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
282
+ };
283
+ Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
284
+ element._isRootCanvasDirty = false;
285
+ this._registerRootCanvas(element, rootCanvas);
286
+ var fromEntity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
287
+ var _rootCanvas_entity_parent;
288
+ var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
289
+ this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
290
+ };
291
+ Utils.cleanRootCanvas = function cleanRootCanvas(element) {
292
+ this._registerRootCanvas(element, null);
293
+ this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
294
+ };
295
+ Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
296
+ var entity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
297
+ while(entity){
298
+ // @ts-ignore
299
+ var components = entity._components;
300
+ for(var i = 0, n = components.length; i < n; i++){
301
+ var component = components[i];
302
+ if (component.enabled && _instanceof(component, exports.UICanvas) && component._isRootCanvas) {
303
+ return component;
304
+ }
305
+ }
306
+ entity = entity.parent;
307
+ }
308
+ return null;
309
+ };
310
+ Utils.setGroupDirty = function setGroupDirty(element) {
311
+ if (element._isGroupDirty) return;
312
+ element._isGroupDirty = true;
313
+ this._registerGroup(element, null);
314
+ element._onGroupModify(GroupModifyFlags.All);
315
+ };
316
+ Utils.setGroup = function setGroup(element, group) {
317
+ element._isGroupDirty = false;
318
+ this._registerGroup(element, group);
319
+ var rootCanvas = element._getRootCanvas();
320
+ if (rootCanvas) {
321
+ var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
322
+ var _group_entity;
323
+ var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
324
+ this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
325
+ } else {
326
+ this._unRegisterListener(element._groupListener, element._groupListeningEntities);
327
+ }
328
+ };
329
+ Utils.cleanGroup = function cleanGroup(element) {
330
+ this._registerGroup(element, null);
331
+ this._unRegisterListener(element._groupListener, element._groupListeningEntities);
332
+ };
333
+ Utils.searchGroupInParents = function searchGroupInParents(element) {
334
+ var rootCanvas = element._getRootCanvas();
335
+ if (!rootCanvas) return null;
336
+ var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
337
+ var rootCanvasParent = rootCanvas.entity.parent;
338
+ while(entity && entity !== rootCanvasParent){
339
+ // @ts-ignore
340
+ var components = entity._components;
341
+ for(var i = 0, n = components.length; i < n; i++){
342
+ var component = components[i];
343
+ if (component.enabled && _instanceof(component, UIGroup)) {
344
+ return component;
345
+ }
346
+ }
347
+ entity = entity.parent;
348
+ }
349
+ return null;
350
+ };
351
+ Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
352
+ var preCanvas = element._rootCanvas;
353
+ if (preCanvas !== canvas) {
354
+ if (preCanvas) {
355
+ var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
356
+ replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
357
+ element._indexInRootCanvas = -1;
358
+ }
359
+ if (canvas) {
360
+ var disorderedElements = canvas._disorderedElements;
361
+ element._indexInRootCanvas = disorderedElements.length;
362
+ disorderedElements.add(element);
363
+ }
364
+ element._rootCanvas = canvas;
365
+ }
366
+ };
367
+ Utils._registerGroup = function _registerGroup(element, group) {
368
+ var preGroup = element._group;
369
+ if (preGroup !== group) {
370
+ if (preGroup) {
371
+ var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
372
+ replaced && (replaced._indexInGroup = element._indexInGroup);
373
+ element._indexInGroup = -1;
374
+ }
375
+ if (group) {
376
+ var disorderedElements = group._disorderedElements;
377
+ element._indexInGroup = disorderedElements.length;
378
+ disorderedElements.add(element);
379
+ }
380
+ element._group = group;
381
+ element._onGroupModify(GroupModifyFlags.All);
382
+ }
383
+ };
384
+ Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
385
+ var count = 0;
386
+ while(entity && entity !== root){
387
+ var preEntity = listeningEntities[count];
388
+ if (preEntity !== entity) {
389
+ // @ts-ignore
390
+ preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
391
+ listeningEntities[count] = entity;
392
+ // @ts-ignore
393
+ entity._registerModifyListener(listener);
394
+ }
395
+ entity = entity.parent;
396
+ count++;
397
+ }
398
+ listeningEntities.length = count;
399
+ };
400
+ Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
401
+ for(var i = 0, n = listeningEntities.length; i < n; i++){
402
+ // @ts-ignore
403
+ listeningEntities[i]._unRegisterModifyListener(listener);
404
+ }
405
+ listeningEntities.length = 0;
406
+ };
407
+ return Utils;
408
+ }();
409
+
410
+ /**
411
+ * @internal
412
+ * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
413
+ *
414
+ * Think of it as stacking elements onto numbered shelves (depths):
415
+ * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
416
+ * - Overlapping + batch-compatible — share the same shelf, still cluster.
417
+ * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
418
+ *
419
+ * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
420
+ * share the same depth and get clustered together. Once depth is assigned, sort by
421
+ * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
422
+ * by-product of materials clustering within each depth band.
423
+ *
424
+ * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
425
+ * are derived from the union AABB of input elements (the bounds transform itself is the
426
+ * work the loop must do anyway, so the union accumulation just piggybacks). This stays
427
+ * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
428
+ * on canvas configuration.
429
+ */ var UIBatchSorter = /*#__PURE__*/ function() {
430
+ function UIBatchSorter() {}
431
+ /**
432
+ * Reorders `elements` in place for optimal batching.
433
+ * @param elements - in hierarchy order (depth-first traversal); mutated in place
434
+ * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
435
+ */ UIBatchSorter.sort = function sort(elements, canvasWorldMatrix) {
436
+ var count = elements.length;
437
+ if (count <= 1) return;
438
+ var gridDim = this._gridDim;
439
+ var entries = this._entries;
440
+ var grid = this._grid;
441
+ var dirtyCells = this._dirtyCells;
442
+ var localBoundsPool = this._localBoundsPool;
443
+ var worldToLocal = this._worldToLocal;
444
+ engine.Matrix.invert(canvasWorldMatrix, worldToLocal);
445
+ while(entries.length < count)entries.push(new SortEntry());
446
+ // Allocate grid once, reuse forever (each cell must be a real [], not a sparse hole)
447
+ if (grid.length < gridDim) {
448
+ while(grid.length < gridDim)grid.push([]);
449
+ for(var i = 0; i < gridDim; i++){
450
+ var row = grid[i];
451
+ while(row.length < gridDim)row.push([]);
452
+ }
453
+ }
454
+ // Clear only previously-used cells (no full sweep)
455
+ for(var k = 0, n = dirtyCells.length; k < n; k += 2){
456
+ grid[dirtyCells[k]][dirtyCells[k + 1]].length = 0;
457
+ }
458
+ dirtyCells.length = 0;
459
+ // Pass 1: transform world bounds to canvas-local + accumulate the union AABB.
460
+ // Transform is already required to do precise overlap, so the union accumulation
461
+ // is essentially free — just a few minmax compares riding on the existing pass
462
+ var unionMinX = Infinity;
463
+ var unionMinY = Infinity;
464
+ var unionMaxX = -Infinity;
465
+ var unionMaxY = -Infinity;
466
+ for(var i1 = 0; i1 < count; i1++){
467
+ var _localBoundsPool, _i;
468
+ var localBounds = (_localBoundsPool = localBoundsPool)[_i = i1] || (_localBoundsPool[_i] = new engine.BoundingBox());
469
+ engine.BoundingBox.transform(elements[i1].component.bounds, worldToLocal, localBounds);
470
+ var min = localBounds.min, max = localBounds.max;
471
+ if (min.x < unionMinX) unionMinX = min.x;
472
+ if (min.y < unionMinY) unionMinY = min.y;
473
+ if (max.x > unionMaxX) unionMaxX = max.x;
474
+ if (max.y > unionMaxY) unionMaxY = max.y;
475
+ }
476
+ // Guard against a degenerate union (all elements collapsed onto a single point /
477
+ // axis); the grid then collapses to cell 0 which is semantically correct
478
+ var cellSizeX = Math.max(1e-6, unionMaxX - unionMinX) / gridDim;
479
+ var cellSizeY = Math.max(1e-6, unionMaxY - unionMinY) / gridDim;
480
+ var maxCell = gridDim - 1;
481
+ // Pass 2: register each element into grid cells and compute its depth
482
+ for(var i2 = 0; i2 < count; i2++){
483
+ var element = elements[i2];
484
+ var localBounds1 = localBoundsPool[i2];
485
+ var materialId = element.material.instanceId;
486
+ var textureId = element.texture ? element.texture.instanceId : 0;
487
+ // Floor + clamp guards floating-point edge cases (a `max` exactly on the union
488
+ // boundary would otherwise produce `gridDim`)
489
+ var minCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.x - unionMinX) / cellSizeX)));
490
+ var maxCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.x - unionMinX) / cellSizeX)));
491
+ var minCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.y - unionMinY) / cellSizeY)));
492
+ var maxCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.y - unionMinY) / cellSizeY)));
493
+ // Find the deepest overlapping prior, and whether that shelf has any incompatible occupant
494
+ var maxDepth = -1;
495
+ var maxDepthIncompatible = false;
496
+ for(var cellY = minCellY; cellY <= maxCellY; cellY++){
497
+ for(var cellX = minCellX; cellX <= maxCellX; cellX++){
498
+ var cell = grid[cellX][cellY];
499
+ for(var j = 0, m = cell.length; j < m; j++){
500
+ var other = cell[j];
501
+ if (!UIBatchSorter._rectOverlap(localBounds1, other.bounds)) continue;
502
+ var otherDepth = other.depth;
503
+ var otherIncompatible = other.materialId !== materialId || other.textureId !== textureId;
504
+ if (otherDepth > maxDepth) {
505
+ maxDepth = otherDepth;
506
+ maxDepthIncompatible = otherIncompatible;
507
+ } else if (otherDepth === maxDepth && otherIncompatible) {
508
+ maxDepthIncompatible = true;
509
+ }
510
+ }
511
+ }
512
+ }
513
+ var entry = entries[i2];
514
+ entry.element = element;
515
+ entry.hierarchyIndex = i2;
516
+ // Share the deepest shelf if compatible; bump up one if blocked by an incompatible occupant
517
+ entry.depth = maxDepth < 0 ? 0 : maxDepth + (maxDepthIncompatible ? 1 : 0);
518
+ entry.materialId = materialId;
519
+ entry.textureId = textureId;
520
+ entry.bounds = localBounds1;
521
+ for(var cellY1 = minCellY; cellY1 <= maxCellY; cellY1++){
522
+ for(var cellX1 = minCellX; cellX1 <= maxCellX; cellX1++){
523
+ var cell1 = grid[cellX1][cellY1];
524
+ if (cell1.length === 0) dirtyCells.push(cellX1, cellY1);
525
+ cell1.push(entry);
526
+ }
527
+ }
528
+ }
529
+ // @ts-ignore — Utils._quickSort is @internal
530
+ engine.Utils._quickSort(entries, 0, count, UIBatchSorter._compareEntries);
531
+ for(var i3 = 0; i3 < count; i3++)elements[i3] = entries[i3].element;
532
+ };
533
+ UIBatchSorter._rectOverlap = function _rectOverlap(a, b) {
534
+ 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;
535
+ };
536
+ UIBatchSorter._compareEntries = function _compareEntries(a, b) {
537
+ return a.depth - b.depth || a.materialId - b.materialId || a.textureId - b.textureId || a.hierarchyIndex - b.hierarchyIndex;
538
+ };
539
+ return UIBatchSorter;
540
+ }();
541
+ // Spatial-hash is fastest when cell size ≈ typical element size (one element per cell).
542
+ // UI elements typically span ~10% of the canvas → 10×10 grid.
543
+ UIBatchSorter._gridDim = 10;
544
+ UIBatchSorter._entries = new Array();
545
+ UIBatchSorter._grid = [];
546
+ // Interleaved (x, y) cell coords touched in the previous frame
547
+ UIBatchSorter._dirtyCells = new Array();
548
+ UIBatchSorter._localBoundsPool = new Array();
549
+ UIBatchSorter._worldToLocal = new engine.Matrix();
550
+ // materialId/textureId/bounds are flattened from RenderElement to avoid
551
+ // multi-hop property access in the hot inner loop and the sort comparator.
552
+ var SortEntry = function SortEntry() {
553
+ this.hierarchyIndex = 0;
554
+ this.depth = 0;
555
+ this.materialId = 0;
556
+ this.textureId = 0;
557
+ };
558
+
559
+ /**
560
+ * Render mode for ui canvas.
561
+ */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
562
+ /**
563
+ * The UI canvas will be rendered directly onto the screen and adapted to screen space,
564
+ * overlaying other rendering elements in the same scene.
565
+ * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
566
+ */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
567
+ /**
568
+ * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
569
+ * with all objects rendered by the camera.
570
+ * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
571
+ * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
572
+ */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
573
+ /**
574
+ * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
575
+ */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
576
+ return CanvasRenderMode;
577
+ }({});
578
+
579
+ /**
580
+ * Resolution adaptation mode.
581
+ * @remarks Only effective in screen space.
582
+ */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
583
+ /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
584
+ /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
585
+ /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
586
+ /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
587
+ /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
588
+ return ResolutionAdaptationMode;
589
+ }({});
590
+
591
+ /** Horizontal alignment mode. */ var HorizontalAlignmentMode = /*#__PURE__*/ function(HorizontalAlignmentMode) {
592
+ /** No horizontal alignment. */ HorizontalAlignmentMode[HorizontalAlignmentMode["None"] = 0] = "None";
593
+ /** Left-aligned, `alignLeft` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Left"] = 1] = "Left";
594
+ /** Right-aligned, `alignRight` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Right"] = 2] = "Right";
595
+ /** Horizontal stretch, `alignLeft` and `alignRight` drive `position.x` and `size.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["LeftAndRight"] = 3] = "LeftAndRight";
596
+ /** Center-aligned, `alignCenter` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Center"] = 4] = "Center";
597
+ return HorizontalAlignmentMode;
598
+ }({});
599
+
600
+ /** Vertical alignment mode. */ var VerticalAlignmentMode = /*#__PURE__*/ function(VerticalAlignmentMode) {
601
+ /** No vertical alignment. */ VerticalAlignmentMode[VerticalAlignmentMode["None"] = 0] = "None";
602
+ /** Top-aligned, `alignTop` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Top"] = 1] = "Top";
603
+ /** Bottom-aligned, `alignBottom` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Bottom"] = 2] = "Bottom";
604
+ /** Vertical stretch, `alignTop` and `alignBottom` drive `position.y` and `size.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["TopAndBottom"] = 3] = "TopAndBottom";
605
+ /** Middle-aligned, `alignMiddle` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Middle"] = 4] = "Middle";
606
+ return VerticalAlignmentMode;
607
+ }({});
608
+
609
+ /**
610
+ * The Transform component exclusive to the UI element.
611
+ */ var UITransform = /*#__PURE__*/ function(Transform) {
612
+ _inherits(UITransform, Transform);
613
+ function UITransform(entity) {
614
+ var _this;
615
+ _this = Transform.call(this, entity) || this, _this._size = new engine.Vector2(100, 100), _this._pivot = new engine.Vector2(0.5, 0.5), _this._rect = new engine.Rect(-50, -50, 100, 100), _this._alignLeft = 0, _this._alignRight = 0, _this._alignCenter = 0, _this._alignTop = 0, _this._alignBottom = 0, _this._alignMiddle = 0, _this._horizontalAlignment = HorizontalAlignmentMode.None, _this._verticalAlignment = VerticalAlignmentMode.None;
616
+ _this._onSizeChanged = _this._onSizeChanged.bind(_this);
617
+ _this._onPivotChanged = _this._onPivotChanged.bind(_this);
618
+ // @ts-ignore
619
+ _this._size._onValueChanged = _this._onSizeChanged;
620
+ // @ts-ignore
621
+ _this._pivot._onValueChanged = _this._onPivotChanged;
622
+ return _this;
623
+ }
624
+ var _proto = UITransform.prototype;
625
+ /**
626
+ * @internal
627
+ */ _proto._parentChange = function _parentChange() {
628
+ this._isParentDirty = true;
629
+ this._updateWorldFlagWithParentRectChange(engine.TransformModifyFlags.WmWpWeWqWsWus);
630
+ };
631
+ /**
632
+ * @inheritdoc
633
+ */ _proto._onClone = function _onClone(target) {
634
+ Transform.prototype._onClone.call(this, target);
635
+ var size = target._size, pivot = target._pivot;
636
+ // @ts-ignore
637
+ size._onValueChanged = pivot._onValueChanged = null;
638
+ size.copyFrom(this._size);
639
+ pivot.copyFrom(this._pivot);
640
+ // @ts-ignore
641
+ size._onValueChanged = target._onSizeChanged;
642
+ // @ts-ignore
643
+ pivot._onValueChanged = target._onPivotChanged;
644
+ };
645
+ _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
646
+ // `super._onLocalMatrixChanging()` will set `LocalMatrix` dirty flag `false`
647
+ // If there is an alignment, `position` and `localMatrix` will be reset again
648
+ if (this._horizontalAlignment || this._verticalAlignment) {
649
+ this._updatePositionByAlignment();
650
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
651
+ } else {
652
+ Transform.prototype._onLocalMatrixChanging.call(this);
653
+ }
654
+ };
655
+ _proto._onWorldMatrixChanging = function _onWorldMatrixChanging() {
656
+ // `super._onWorldMatrixChanging()` will set `WorldMatrix` dirty flag `false`
657
+ // If there is an alignment, `position` and `worldMatrix` will be reset again(`worldMatrix` dirty flag is already `true`)
658
+ !this._horizontalAlignment && !this._verticalAlignment && Transform.prototype._onWorldMatrixChanging.call(this);
659
+ };
660
+ _proto._onPositionChanged = function _onPositionChanged() {
661
+ (this._horizontalAlignment || this._verticalAlignment) && this._updatePositionByAlignment();
662
+ Transform.prototype._onPositionChanged.call(this);
663
+ };
664
+ _proto._onWorldPositionChanged = function _onWorldPositionChanged() {
665
+ Transform.prototype._onWorldPositionChanged.call(this);
666
+ if (this._horizontalAlignment || this._verticalAlignment) {
667
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.WorldPosition);
668
+ }
669
+ };
670
+ _proto._updatePositionByAlignment = function _updatePositionByAlignment() {
671
+ var _this__getParentTransform;
672
+ var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
673
+ if (parentRect) {
674
+ var position = this.position;
675
+ // @ts-ignore
676
+ position._onValueChanged = null;
677
+ var rect = this._rect;
678
+ switch(this._horizontalAlignment){
679
+ case HorizontalAlignmentMode.Left:
680
+ case HorizontalAlignmentMode.LeftAndRight:
681
+ position.x = parentRect.x - rect.x + this._alignLeft;
682
+ break;
683
+ case HorizontalAlignmentMode.Center:
684
+ position.x = parentRect.x + parentRect.width * 0.5 - rect.x - rect.width * 0.5 + this._alignCenter;
685
+ break;
686
+ case HorizontalAlignmentMode.Right:
687
+ position.x = parentRect.x + parentRect.width - rect.x - rect.width - this._alignRight;
688
+ break;
689
+ }
690
+ switch(this._verticalAlignment){
691
+ case VerticalAlignmentMode.Top:
692
+ position.y = parentRect.y + parentRect.height - rect.y - rect.height - this._alignTop;
693
+ break;
694
+ case VerticalAlignmentMode.Middle:
695
+ position.y = parentRect.y + parentRect.height * 0.5 - rect.y - rect.height * 0.5 + this._alignMiddle;
696
+ break;
697
+ case VerticalAlignmentMode.Bottom:
698
+ case VerticalAlignmentMode.TopAndBottom:
699
+ position.y = parentRect.y - rect.y + this._alignBottom;
700
+ break;
701
+ }
702
+ // @ts-ignore
703
+ position._onValueChanged = this._onPositionChanged;
704
+ }
705
+ };
706
+ _proto._updateSizeByAlignment = function _updateSizeByAlignment() {
707
+ var _this__getParentTransform;
708
+ var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
709
+ if (parentRect) {
710
+ var size = this._size;
711
+ // @ts-ignore
712
+ size._onValueChanged = null;
713
+ // The values of size must be greater than 0
714
+ if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight) {
715
+ size.x = Math.max(parentRect.width - this._alignLeft - this._alignRight, 0);
716
+ }
717
+ if (this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
718
+ size.y = Math.max(parentRect.height - this._alignTop - this._alignBottom, 0);
719
+ }
720
+ // @ts-ignore
721
+ size._onValueChanged = this._onSizeChanged;
722
+ }
723
+ };
724
+ _proto._updateRectBySizeAndPivot = function _updateRectBySizeAndPivot() {
725
+ var _this = this, size = _this.size, pivot = _this._pivot;
726
+ var x = -pivot.x * size.x;
727
+ var y = -pivot.y * size.y;
728
+ this._rect.set(x, y, size.x, size.y);
729
+ };
730
+ _proto._onSizeChanged = function _onSizeChanged() {
731
+ if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
732
+ this._updateSizeByAlignment();
733
+ }
734
+ this._updateRectBySizeAndPivot();
735
+ this._updateWorldFlagWithSelfRectChange();
736
+ // @ts-ignore
737
+ this._entity._updateFlagManager.dispatch(512);
738
+ };
739
+ _proto._onPivotChanged = function _onPivotChanged() {
740
+ this._updateRectBySizeAndPivot();
741
+ this._updateWorldFlagWithSelfRectChange();
742
+ // @ts-ignore
743
+ this._entity._updateFlagManager.dispatch(1024);
744
+ };
745
+ _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
746
+ var worldFlags = 0;
747
+ if (this._horizontalAlignment || this._verticalAlignment) {
748
+ this._updatePositionByAlignment();
749
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
750
+ worldFlags = engine.TransformModifyFlags.WmWp;
751
+ !this._isContainDirtyFlags(worldFlags) && this._worldAssociatedChange(worldFlags);
752
+ }
753
+ var children = this.entity.children;
754
+ for(var i = 0, n = children.length; i < n; i++){
755
+ var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
756
+ (_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);
757
+ }
758
+ };
759
+ _proto._updateWorldFlagWithParentRectChange = function _updateWorldFlagWithParentRectChange(flags, parentChange) {
760
+ if (parentChange === void 0) parentChange = true;
761
+ var selfChange = false;
762
+ if (parentChange) {
763
+ var _this = this, horizontalAlignment = _this._horizontalAlignment, verticalAlignment = _this._verticalAlignment;
764
+ if (horizontalAlignment || verticalAlignment) {
765
+ if (horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
766
+ this._updateSizeByAlignment();
767
+ this._updateRectBySizeAndPivot();
768
+ selfChange = true;
769
+ }
770
+ this._updatePositionByAlignment();
771
+ this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
772
+ flags |= engine.TransformModifyFlags.WmWp;
773
+ }
774
+ }
775
+ var containDirtyFlags = this._isContainDirtyFlags(flags);
776
+ !containDirtyFlags && this._worldAssociatedChange(flags);
777
+ if (selfChange || !containDirtyFlags) {
778
+ var children = this.entity.children;
779
+ for(var i = 0, n = children.length; i < n; i++){
780
+ var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
781
+ (_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);
782
+ }
783
+ }
784
+ // @ts-ignore
785
+ selfChange && this._entity._updateFlagManager.dispatch(512);
786
+ };
787
+ _create_class(UITransform, [
788
+ {
789
+ key: "size",
790
+ get: /**
791
+ * Width and height of UI element.
792
+ */ function get() {
793
+ return this._size;
794
+ },
795
+ set: function set(value) {
796
+ var _this = this, size = _this._size;
797
+ if (size === value) return;
798
+ (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
799
+ }
800
+ },
801
+ {
802
+ key: "pivot",
803
+ get: /**
804
+ * Pivot of UI element.
805
+ */ function get() {
806
+ return this._pivot;
807
+ },
808
+ set: function set(value) {
809
+ var _this = this, pivot = _this._pivot;
810
+ if (pivot === value) return;
811
+ (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
812
+ }
813
+ },
814
+ {
815
+ key: "horizontalAlignment",
816
+ get: /**
817
+ * Horizontal alignment mode.
818
+ *
819
+ * @remarks
820
+ * Controls how the element aligns horizontally within its parent:
821
+ * - `Left` - Align to parent's left edge
822
+ * - `Center` - Align to parent's horizontal center
823
+ * - `Right` - Align to parent's right edge
824
+ * - `LeftAndRight` - Align to both left and right edges (stretch to fill width)
825
+ */ function get() {
826
+ return this._horizontalAlignment;
827
+ },
828
+ set: function set(value) {
829
+ if (this._horizontalAlignment === value) return;
830
+ this._horizontalAlignment = value;
831
+ switch(value){
832
+ case HorizontalAlignmentMode.Left:
833
+ case HorizontalAlignmentMode.Right:
834
+ case HorizontalAlignmentMode.Center:
835
+ this._onPositionChanged();
836
+ break;
837
+ case HorizontalAlignmentMode.LeftAndRight:
838
+ this._onPositionChanged();
839
+ this._onSizeChanged();
840
+ break;
841
+ }
842
+ }
843
+ },
844
+ {
845
+ key: "alignLeft",
846
+ get: /**
847
+ * Left margin when horizontalAlignment is Left or LeftAndRight.
848
+ *
849
+ * @remarks
850
+ * Only effective when horizontalAlignment includes Left mode.
851
+ * Distance from the parent's left edge to the element's left edge.
852
+ */ function get() {
853
+ return this._alignLeft;
854
+ },
855
+ set: function set(value) {
856
+ if (!Number.isFinite(value)) return;
857
+ if (engine.MathUtil.equals(value, this._alignLeft)) return;
858
+ this._alignLeft = value;
859
+ if (this._horizontalAlignment & HorizontalAlignmentMode.Left) {
860
+ this._onPositionChanged();
861
+ this._horizontalAlignment & HorizontalAlignmentMode.Right && this._onSizeChanged();
862
+ }
863
+ }
864
+ },
865
+ {
866
+ key: "alignRight",
867
+ get: /**
868
+ * Right margin when horizontalAlignment is Right or LeftAndRight.
869
+ *
870
+ * @remarks
871
+ * Only effective when horizontalAlignment includes Right mode.
872
+ * Distance from the parent's right edge to the element's right edge.
873
+ */ function get() {
874
+ return this._alignRight;
875
+ },
876
+ set: function set(value) {
877
+ if (!Number.isFinite(value)) return;
878
+ if (engine.MathUtil.equals(value, this._alignRight)) return;
879
+ this._alignRight = value;
880
+ if (this._horizontalAlignment & HorizontalAlignmentMode.Right) {
881
+ this._onPositionChanged();
882
+ this._horizontalAlignment & HorizontalAlignmentMode.Left && this._onSizeChanged();
883
+ }
884
+ }
885
+ },
886
+ {
887
+ key: "alignCenter",
888
+ get: /**
889
+ * Horizontal center offset when horizontalAlignment is Center.
890
+ *
891
+ * @remarks
892
+ * Only effective when horizontalAlignment is Center mode.
893
+ * Positive values move the element to the right, negative values to the left.
894
+ */ function get() {
895
+ return this._alignCenter;
896
+ },
897
+ set: function set(value) {
898
+ if (!Number.isFinite(value)) return;
899
+ if (engine.MathUtil.equals(value, this._alignCenter)) return;
900
+ this._alignCenter = value;
901
+ this._horizontalAlignment & HorizontalAlignmentMode.Center && this._onPositionChanged();
902
+ }
903
+ },
904
+ {
905
+ key: "verticalAlignment",
906
+ get: /**
907
+ * Vertical alignment mode.
908
+ *
909
+ * @remarks
910
+ * Controls how the element aligns vertically within its parent:
911
+ * - `Top` - Align to parent's top edge
912
+ * - `Middle` - Align to parent's vertical center
913
+ * - `Bottom` - Align to parent's bottom edge
914
+ * - `TopAndBottom` - Align to both top and bottom edges (stretch to fill height)
915
+ */ function get() {
916
+ return this._verticalAlignment;
917
+ },
918
+ set: function set(value) {
919
+ if (this._verticalAlignment === value) return;
920
+ this._verticalAlignment = value;
921
+ switch(value){
922
+ case VerticalAlignmentMode.Top:
923
+ case VerticalAlignmentMode.Bottom:
924
+ case VerticalAlignmentMode.Middle:
925
+ this._onPositionChanged();
926
+ break;
927
+ case VerticalAlignmentMode.TopAndBottom:
928
+ this._onPositionChanged();
929
+ this._onSizeChanged();
930
+ break;
931
+ }
932
+ }
933
+ },
934
+ {
935
+ key: "alignTop",
936
+ get: /**
937
+ * Top margin when verticalAlignment is Top or TopAndBottom.
938
+ *
939
+ * @remarks
940
+ * Only effective when verticalAlignment includes Top mode.
941
+ * Used to offset the element from the parent's top edge.
942
+ */ function get() {
943
+ return this._alignTop;
944
+ },
945
+ set: function set(value) {
946
+ if (!Number.isFinite(value)) return;
947
+ if (engine.MathUtil.equals(value, this._alignTop)) return;
948
+ this._alignTop = value;
949
+ if (this._verticalAlignment & VerticalAlignmentMode.Top) {
950
+ this._onPositionChanged();
951
+ this._verticalAlignment & VerticalAlignmentMode.Bottom && this._onSizeChanged();
952
+ }
953
+ }
954
+ },
955
+ {
956
+ key: "alignBottom",
957
+ get: /**
958
+ * Bottom inset used in vertical alignment formulas.
959
+ */ function get() {
960
+ return this._alignBottom;
961
+ },
962
+ set: function set(value) {
963
+ if (!Number.isFinite(value)) return;
964
+ if (engine.MathUtil.equals(value, this._alignBottom)) return;
965
+ this._alignBottom = value;
966
+ if (this._verticalAlignment & VerticalAlignmentMode.Bottom) {
967
+ this._onPositionChanged();
968
+ this._verticalAlignment & VerticalAlignmentMode.Top && this._onSizeChanged();
969
+ }
970
+ }
971
+ },
972
+ {
973
+ key: "alignMiddle",
974
+ get: /**
975
+ * Vertical middle offset relative to parent's middle.
976
+ */ function get() {
977
+ return this._alignMiddle;
978
+ },
979
+ set: function set(value) {
980
+ if (!Number.isFinite(value)) return;
981
+ if (engine.MathUtil.equals(value, this._alignMiddle)) return;
982
+ this._alignMiddle = value;
983
+ this._verticalAlignment & VerticalAlignmentMode.Middle && this._onPositionChanged();
984
+ }
985
+ }
986
+ ]);
987
+ return UITransform;
988
+ }(engine.Transform);
989
+ __decorate([
990
+ engine.ignoreClone
991
+ ], UITransform.prototype, "_size", void 0);
992
+ __decorate([
993
+ engine.ignoreClone
994
+ ], UITransform.prototype, "_pivot", void 0);
995
+ __decorate([
996
+ engine.ignoreClone
997
+ ], UITransform.prototype, "_onPositionChanged", null);
998
+ __decorate([
999
+ engine.ignoreClone
1000
+ ], UITransform.prototype, "_onWorldPositionChanged", null);
1001
+ __decorate([
1002
+ engine.ignoreClone
1003
+ ], UITransform.prototype, "_onSizeChanged", null);
1004
+ __decorate([
1005
+ engine.ignoreClone
1006
+ ], UITransform.prototype, "_onPivotChanged", null);
1007
+ /**
1008
+ * @internal
1009
+ * extends TransformModifyFlags
1010
+ */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
1011
+ UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
1012
+ UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
1013
+ return UITransformModifyFlags;
1014
+ }({});
1015
+
1016
+ exports.UIRenderer = /*#__PURE__*/ function(Renderer) {
1017
+ _inherits(UIRenderer, Renderer);
1018
+ function UIRenderer(entity) {
1019
+ var _this;
1020
+ _this = Renderer.call(this, entity) || this, /**
1021
+ * Custom boundary for raycast detection.
1022
+ * @remarks this is based on `this.entity.transform`.
1023
+ */ _this.raycastPadding = new engine.Vector4(0, 0, 0, 0), /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], _this._raycastEnabled = true, _this._color = new engine.Color(1, 1, 1, 1);
1024
+ _this._dirtyUpdateFlag = engine.RendererUpdateFlags.WorldVolume | 2;
1025
+ _this._onColorChanged = _this._onColorChanged.bind(_this);
1026
+ //@ts-ignore
1027
+ _this._color._onValueChanged = _this._onColorChanged;
1028
+ _this._groupListener = _this._groupListener.bind(_this);
1029
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1030
+ return _this;
1031
+ }
1032
+ var _proto = UIRenderer.prototype;
1033
+ // @ts-ignore
1034
+ _proto._canBatch = function _canBatch(preElement, curElement) {
1035
+ return engine.VertexMergeBatcher.canBatchSprite(preElement, curElement);
1036
+ };
1037
+ // @ts-ignore
1038
+ _proto._batch = function _batch(preElement, curElement) {
1039
+ engine.VertexMergeBatcher.batch(preElement, curElement);
1040
+ };
1041
+ // @ts-ignore
1042
+ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP) {
1043
+ // @ts-ignore
1044
+ this._updateWorldSpaceTransformShaderData(context, onlyMVP);
1045
+ };
1046
+ // @ts-ignore
1047
+ _proto._prepareRender = function _prepareRender(context) {
1048
+ // Update once per frame per renderer, not influenced by batched
1049
+ if (this._renderFrameCount !== this.engine.time.frameCount) {
1050
+ this._update(context);
1051
+ }
1052
+ this._render(context);
1053
+ // union camera global macro and renderer macro.
1054
+ engine.ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
1055
+ this.shaderData._macroCollection, //@ts-ignore
1056
+ this._globalShaderMacro);
1057
+ };
1058
+ // @ts-ignore
1059
+ _proto._onEnableInScene = function _onEnableInScene() {
1060
+ // @ts-ignore
1061
+ this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
1062
+ this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
1063
+ Utils.setRootCanvasDirty(this);
1064
+ Utils.setGroupDirty(this);
1065
+ };
1066
+ // @ts-ignore
1067
+ _proto._onDisableInScene = function _onDisableInScene() {
1068
+ // @ts-ignore
1069
+ this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
1070
+ this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
1071
+ Utils.cleanRootCanvas(this);
1072
+ Utils.cleanGroup(this);
1073
+ };
1074
+ /**
1075
+ * @internal
1076
+ */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
1077
+ var _this__getGroup;
1078
+ var _this__getGroup__getGlobalAlpha;
1079
+ return (_this__getGroup__getGlobalAlpha = (_this__getGroup = this._getGroup()) == null ? void 0 : _this__getGroup._getGlobalAlpha()) != null ? _this__getGroup__getGlobalAlpha : 1;
1080
+ };
1081
+ /**
1082
+ * @internal
1083
+ */ _proto._getRootCanvas = function _getRootCanvas() {
1084
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1085
+ return this._rootCanvas;
1086
+ };
1087
+ /**
1088
+ * @internal
1089
+ */ _proto._getGroup = function _getGroup() {
1090
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1091
+ return this._group;
1092
+ };
1093
+ /**
1094
+ * @internal
1095
+ */ _proto._groupListener = function _groupListener(flag) {
1096
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1097
+ Utils.setGroupDirty(this);
1098
+ }
1099
+ };
1100
+ /**
1101
+ * @internal
1102
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag, entity) {
1103
+ switch(flag){
1104
+ case engine.EntityModifyFlags.Parent:
1105
+ Utils.setRootCanvasDirty(this);
1106
+ Utils.setGroupDirty(this);
1107
+ case engine.EntityModifyFlags.Child:
1108
+ entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
1109
+ break;
1110
+ }
1111
+ };
1112
+ /**
1113
+ * @internal
1114
+ */ _proto._onGroupModify = function _onGroupModify(flags) {
1115
+ if (flags & GroupModifyFlags.GlobalAlpha) {
1116
+ this._dirtyUpdateFlag |= 2;
1117
+ }
1118
+ };
1119
+ _proto._onColorChanged = function _onColorChanged() {
1120
+ this._dirtyUpdateFlag |= 2;
1121
+ };
1122
+ /**
1123
+ * @internal
1124
+ */ _proto._getChunkManager = function _getChunkManager() {
1125
+ // @ts-ignore
1126
+ return this.engine._batcherManager.primitiveChunkManagerUI;
1127
+ };
1128
+ /**
1129
+ * @internal
1130
+ */ _proto._raycast = function _raycast(ray, out, distance) {
1131
+ if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1132
+ var plane = UIRenderer._tempPlane;
1133
+ var transform = this._transformEntity.transform;
1134
+ var normal = plane.normal.copyFrom(transform.worldForward);
1135
+ plane.distance = -engine.Vector3.dot(normal, transform.worldPosition);
1136
+ var curDistance = ray.intersectPlane(plane);
1137
+ if (curDistance >= 0 && curDistance < distance) {
1138
+ var hitPointWorld = ray.getPoint(curDistance, UIRenderer._tempVec30);
1139
+ var worldMatrixInv = UIRenderer._tempMat;
1140
+ engine.Matrix.invert(transform.worldMatrix, worldMatrixInv);
1141
+ var localPosition = UIRenderer._tempVec31;
1142
+ engine.Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, localPosition);
1143
+ if (this._hitTest(localPosition)) {
1144
+ out.component = this;
1145
+ out.distance = curDistance;
1146
+ out.entity = this.entity;
1147
+ out.normal.copyFrom(normal);
1148
+ out.point.copyFrom(hitPointWorld);
1149
+ return true;
1150
+ }
1151
+ }
1152
+ return false;
1153
+ };
1154
+ _proto._hitTest = function _hitTest(localPosition) {
1155
+ var x = localPosition.x, y = localPosition.y;
1156
+ var uiTransform = this._transformEntity.transform;
1157
+ var _uiTransform_size = uiTransform.size, width = _uiTransform_size.x, height = _uiTransform_size.y;
1158
+ var _uiTransform_pivot = uiTransform.pivot, pivotX = _uiTransform_pivot.x, pivotY = _uiTransform_pivot.y;
1159
+ var _this_raycastPadding = this.raycastPadding, paddingLeft = _this_raycastPadding.x, paddingBottom = _this_raycastPadding.y, paddingRight = _this_raycastPadding.z, paddingTop = _this_raycastPadding.w;
1160
+ return x >= -width * pivotX + paddingLeft && x <= width * (1 - pivotX) - paddingRight && y >= -height * pivotY + paddingTop && y <= height * (1 - pivotY) - paddingBottom;
1161
+ };
1162
+ _proto._onDestroy = function _onDestroy() {
1163
+ if (this._subChunk) {
1164
+ this._getChunkManager().freeSubChunk(this._subChunk);
1165
+ this._subChunk = null;
1166
+ }
1167
+ Renderer.prototype._onDestroy.call(this);
1168
+ //@ts-ignore
1169
+ this._color._onValueChanged = null;
1170
+ this._color = null;
1171
+ };
1172
+ _create_class(UIRenderer, [
1173
+ {
1174
+ key: "color",
1175
+ get: /**
1176
+ * Rendering color for the ui renderer.
1177
+ */ function get() {
1178
+ return this._color;
1179
+ },
1180
+ set: function set(value) {
1181
+ if (this._color !== value) {
1182
+ this._color.copyFrom(value);
1183
+ }
1184
+ }
1185
+ },
1186
+ {
1187
+ key: "raycastEnabled",
1188
+ get: /**
1189
+ * Whether this renderer be picked up by raycast.
1190
+ */ function get() {
1191
+ return this._raycastEnabled;
1192
+ },
1193
+ set: function set(value) {
1194
+ this._raycastEnabled = value;
1195
+ }
1196
+ }
1197
+ ]);
1198
+ return UIRenderer;
1199
+ }(engine.Renderer);
1200
+ /** @internal */ exports.UIRenderer._tempVec30 = new engine.Vector3();
1201
+ /** @internal */ exports.UIRenderer._tempVec31 = new engine.Vector3();
1202
+ /** @internal */ exports.UIRenderer._tempMat = new engine.Matrix();
1203
+ /** @internal */ exports.UIRenderer._tempPlane = new engine.Plane();
1204
+ /** @internal */ exports.UIRenderer._textureProperty = engine.ShaderProperty.getByName("renderer_UITexture");
1205
+ __decorate([
1206
+ engine.ignoreClone
1207
+ ], exports.UIRenderer.prototype, "_indexInRootCanvas", void 0);
1208
+ __decorate([
1209
+ engine.ignoreClone
1210
+ ], exports.UIRenderer.prototype, "_isRootCanvasDirty", void 0);
1211
+ __decorate([
1212
+ engine.ignoreClone
1213
+ ], exports.UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
1214
+ __decorate([
1215
+ engine.ignoreClone
1216
+ ], exports.UIRenderer.prototype, "_indexInGroup", void 0);
1217
+ __decorate([
1218
+ engine.ignoreClone
1219
+ ], exports.UIRenderer.prototype, "_isGroupDirty", void 0);
1220
+ __decorate([
1221
+ engine.ignoreClone
1222
+ ], exports.UIRenderer.prototype, "_groupListeningEntities", void 0);
1223
+ __decorate([
1224
+ engine.ignoreClone
1225
+ ], exports.UIRenderer.prototype, "_subChunk", void 0);
1226
+ __decorate([
1227
+ engine.ignoreClone
1228
+ ], exports.UIRenderer.prototype, "_groupListener", null);
1229
+ __decorate([
1230
+ engine.ignoreClone
1231
+ ], exports.UIRenderer.prototype, "_rootCanvasListener", null);
1232
+ __decorate([
1233
+ engine.ignoreClone
1234
+ ], exports.UIRenderer.prototype, "_onColorChanged", null);
1235
+ exports.UIRenderer = __decorate([
1236
+ engine.dependentComponents(UITransform, engine.DependentMode.AutoAdd)
1237
+ ], exports.UIRenderer);
1238
+ /**
1239
+ * @remarks Extends `RendererUpdateFlags`.
1240
+ */ var UIRendererUpdateFlags = /*#__PURE__*/ function(UIRendererUpdateFlags) {
1241
+ UIRendererUpdateFlags[UIRendererUpdateFlags["Color"] = 2] = "Color";
1242
+ return UIRendererUpdateFlags;
1243
+ }({});
1244
+
1245
+ /**
1246
+ * Interactive component.
1247
+ */ var UIInteractive = /*#__PURE__*/ function(Script) {
1248
+ _inherits(UIInteractive, Script);
1249
+ function UIInteractive(entity) {
1250
+ var _this;
1251
+ _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;
1252
+ _this._groupListener = _this._groupListener.bind(_this);
1253
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1254
+ return _this;
1255
+ }
1256
+ var _proto = UIInteractive.prototype;
1257
+ /**
1258
+ * Add transition on this interactive.
1259
+ * @param transition - The transition
1260
+ */ _proto.addTransition = function addTransition(transition) {
1261
+ var interactive = transition._interactive;
1262
+ if (interactive !== this) {
1263
+ interactive == null ? void 0 : interactive.removeTransition(transition);
1264
+ this._transitions.push(transition);
1265
+ transition._interactive = this;
1266
+ transition._setState(this._state, true);
1267
+ }
1268
+ };
1269
+ /**
1270
+ * Remove a transition.
1271
+ * @param shape - The transition.
1272
+ */ _proto.removeTransition = function removeTransition(transition) {
1273
+ var transitions = this._transitions;
1274
+ var lastOneIndex = transitions.length - 1;
1275
+ for(var i = lastOneIndex; i >= 0; i--){
1276
+ if (transitions[i] === transition) {
1277
+ i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
1278
+ transitions.length = lastOneIndex;
1279
+ transition._interactive = null;
1280
+ break;
1281
+ }
1282
+ }
1283
+ };
1284
+ /**
1285
+ * Remove all transitions.
1286
+ */ _proto.clearTransitions = function clearTransitions() {
1287
+ var transitions = this._transitions;
1288
+ for(var i = 0, n = transitions.length; i < n; i++){
1289
+ transitions[i]._interactive = null;
1290
+ }
1291
+ transitions.length = 0;
1292
+ };
1293
+ _proto.onUpdate = function onUpdate(deltaTime) {
1294
+ if (this._getGlobalInteractive()) {
1295
+ var transitions = this._transitions;
1296
+ for(var i = 0, n = transitions.length; i < n; i++){
1297
+ transitions[i]._onUpdate(deltaTime);
1298
+ }
1299
+ }
1300
+ };
1301
+ _proto.onPointerBeginDrag = function onPointerBeginDrag() {
1302
+ this._isPointerDragging = true;
1303
+ this._updateState(false);
1304
+ };
1305
+ _proto.onPointerEndDrag = function onPointerEndDrag() {
1306
+ this._isPointerDragging = false;
1307
+ this._updateState(false);
1308
+ };
1309
+ _proto.onPointerEnter = function onPointerEnter() {
1310
+ this._isPointerInside = true;
1311
+ this._updateState(false);
1312
+ };
1313
+ _proto.onPointerExit = function onPointerExit() {
1314
+ this._isPointerInside = false;
1315
+ this._updateState(false);
1316
+ };
1317
+ _proto.onDestroy = function onDestroy() {
1318
+ Script.prototype.onDestroy.call(this);
1319
+ var transitions = this._transitions;
1320
+ for(var i = transitions.length - 1; i >= 0; i--){
1321
+ transitions[i].destroy();
1322
+ }
1323
+ };
1324
+ /**
1325
+ * @internal
1326
+ */ _proto._getRootCanvas = function _getRootCanvas() {
1327
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1328
+ return this._rootCanvas;
1329
+ };
1330
+ /**
1331
+ * @internal
1332
+ */ _proto._getGroup = function _getGroup() {
1333
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1334
+ return this._group;
1335
+ };
1336
+ // @ts-ignore
1337
+ _proto._onEnableInScene = function _onEnableInScene() {
1338
+ // @ts-ignore
1339
+ Script.prototype._onEnableInScene.call(this);
1340
+ Utils.setRootCanvasDirty(this);
1341
+ Utils.setGroupDirty(this);
1342
+ this._updateState(true);
1343
+ };
1344
+ // @ts-ignore
1345
+ _proto._onDisableInScene = function _onDisableInScene() {
1346
+ // @ts-ignore
1347
+ Script.prototype._onDisableInScene.call(this);
1348
+ Utils.cleanRootCanvas(this);
1349
+ Utils.cleanGroup(this);
1350
+ this._isPointerInside = this._isPointerDragging = false;
1351
+ };
1352
+ /**
1353
+ * @internal
1354
+ */ _proto._groupListener = function _groupListener(flag) {
1355
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1356
+ Utils.setGroupDirty(this);
1357
+ }
1358
+ };
1359
+ /**
1360
+ * @internal
1361
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
1362
+ if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
1363
+ Utils.setRootCanvasDirty(this);
1364
+ Utils.setGroupDirty(this);
1365
+ }
1366
+ };
1367
+ /**
1368
+ * @internal
1369
+ */ _proto._onGroupModify = function _onGroupModify(flags) {
1370
+ if (flags & GroupModifyFlags.GlobalInteractive) {
1371
+ this._globalInteractiveDirty = true;
1372
+ }
1373
+ };
1374
+ /**
1375
+ * @internal
1376
+ */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
1377
+ if (this._globalInteractiveDirty) {
1378
+ var group = this._getGroup();
1379
+ var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
1380
+ if (this._globalInteractive !== globalInteractive) {
1381
+ this._globalInteractive = globalInteractive;
1382
+ this._updateState(true);
1383
+ }
1384
+ this._globalInteractiveDirty = false;
1385
+ }
1386
+ return this._globalInteractive;
1387
+ };
1388
+ _proto._updateState = function _updateState(instant) {
1389
+ var state = this._getInteractiveState();
1390
+ if (this._state !== state) {
1391
+ this._state = state;
1392
+ var transitions = this._transitions;
1393
+ for(var i = 0, n = transitions.length; i < n; i++){
1394
+ transitions[i]._setState(state, instant);
1395
+ }
1396
+ }
1397
+ };
1398
+ _proto._getInteractiveState = function _getInteractiveState() {
1399
+ if (!this._getGlobalInteractive()) {
1400
+ return 3;
1401
+ }
1402
+ if (this._isPointerDragging) {
1403
+ return 1;
1404
+ } else {
1405
+ return this._isPointerInside ? 2 : 0;
1406
+ }
1407
+ };
1408
+ _create_class(UIInteractive, [
1409
+ {
1410
+ key: "transitions",
1411
+ get: /**
1412
+ * The transitions of this interactive.
1413
+ */ function get() {
1414
+ return this._transitions;
1415
+ }
1416
+ },
1417
+ {
1418
+ key: "interactive",
1419
+ get: /**
1420
+ * Whether the interactive is enabled.
1421
+ */ function get() {
1422
+ return this._interactive;
1423
+ },
1424
+ set: function set(value) {
1425
+ if (this._interactive !== value) {
1426
+ this._interactive = value;
1427
+ this._globalInteractiveDirty = true;
1428
+ }
1429
+ }
1430
+ }
1431
+ ]);
1432
+ return UIInteractive;
1433
+ }(engine.Script);
1434
+ __decorate([
1435
+ engine.ignoreClone
1436
+ ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
1437
+ __decorate([
1438
+ engine.ignoreClone
1439
+ ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
1440
+ __decorate([
1441
+ engine.ignoreClone
1442
+ ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
1443
+ __decorate([
1444
+ engine.ignoreClone
1445
+ ], UIInteractive.prototype, "_indexInGroup", void 0);
1446
+ __decorate([
1447
+ engine.ignoreClone
1448
+ ], UIInteractive.prototype, "_isGroupDirty", void 0);
1449
+ __decorate([
1450
+ engine.ignoreClone
1451
+ ], UIInteractive.prototype, "_groupListeningEntities", void 0);
1452
+ __decorate([
1453
+ engine.ignoreClone
1454
+ ], UIInteractive.prototype, "_globalInteractive", void 0);
1455
+ __decorate([
1456
+ engine.ignoreClone
1457
+ ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
1458
+ __decorate([
1459
+ engine.ignoreClone
1460
+ ], UIInteractive.prototype, "_state", void 0);
1461
+ __decorate([
1462
+ engine.ignoreClone
1463
+ ], UIInteractive.prototype, "_isPointerInside", void 0);
1464
+ __decorate([
1465
+ engine.ignoreClone
1466
+ ], UIInteractive.prototype, "_isPointerDragging", void 0);
1467
+ __decorate([
1468
+ engine.ignoreClone
1469
+ ], UIInteractive.prototype, "_groupListener", null);
1470
+ __decorate([
1471
+ engine.ignoreClone
1472
+ ], UIInteractive.prototype, "_rootCanvasListener", null);
1473
+ __decorate([
1474
+ engine.ignoreClone
1475
+ ], UIInteractive.prototype, "_onGroupModify", null);
1476
+ var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
1477
+ InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
1478
+ InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
1479
+ InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
1480
+ InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
1481
+ return InteractiveState;
1482
+ }({});
1483
+
1484
+ exports.UICanvas = /*#__PURE__*/ function(Component) {
1485
+ _inherits(UICanvas, Component);
1486
+ function UICanvas(entity) {
1487
+ var _this;
1488
+ _this = Component.call(this, entity) || this, /** @internal */ _this._canvasIndex = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._isRootCanvas = false, /** @internal */ _this._renderElements = [], /** @internal */ _this._batchedRenderElements = [], /** @internal */ _this._sortDistance = 0, /** @internal */ _this._orderedRenderers = [], /** @internal */ _this._realRenderMode = 4, /** @internal */ _this._disorderedElements = new engine.DisorderedArray(), _this._renderMode = CanvasRenderMode.WorldSpace, _this._resolutionAdaptationMode = ResolutionAdaptationMode.HeightAdaptation, _this._sortOrder = 0, _this._distance = 10, _this._referenceResolution = new engine.Vector2(800, 600), _this._referenceResolutionPerUnit = 100, _this._hierarchyVersion = -1, _this._center = new engine.Vector3();
1489
+ _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1490
+ _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1491
+ _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1492
+ _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1493
+ // @ts-ignore
1494
+ _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1495
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1496
+ _this._centerDirtyFlag = entity.registerWorldChangeFlag();
1497
+ return _this;
1498
+ }
1499
+ var _proto = UICanvas.prototype;
1500
+ /**
1501
+ * @internal
1502
+ */ _proto._raycast = function _raycast(ray, out, distance) {
1503
+ if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1504
+ var renderers = this._getRenderers();
1505
+ for(var i = renderers.length - 1; i >= 0; i--){
1506
+ var element = renderers[i];
1507
+ if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1508
+ return true;
1509
+ }
1510
+ }
1511
+ out.component = null;
1512
+ out.entity = null;
1513
+ out.distance = 0;
1514
+ out.point.set(0, 0, 0);
1515
+ out.normal.set(0, 0, 0);
1516
+ return false;
1517
+ };
1518
+ /**
1519
+ * @internal
1520
+ */ _proto._getRootCanvas = function _getRootCanvas() {
1521
+ return this._rootCanvas;
1522
+ };
1523
+ /**
1524
+ * @internal
1525
+ */ _proto._canRender = function _canRender(camera) {
1526
+ return this._realRenderMode !== CanvasRenderMode.ScreenSpaceCamera || this._camera === camera;
1527
+ };
1528
+ /**
1529
+ * @internal
1530
+ */ _proto._canDispatchEvent = function _canDispatchEvent(camera) {
1531
+ var realMode = this._realRenderMode;
1532
+ if (realMode === CanvasRenderMode.ScreenSpaceOverlay) {
1533
+ return true;
1534
+ }
1535
+ var assignedCamera = this._camera;
1536
+ // @ts-ignore
1537
+ return !assignedCamera || !assignedCamera._phasedActiveInScene || assignedCamera === camera;
1538
+ };
1539
+ /**
1540
+ * @internal
1541
+ */ _proto._prepareRender = function _prepareRender(context) {
1542
+ var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1543
+ var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1544
+ var frameCount = engine.time.frameCount;
1545
+ var renderElements = this._renderElements;
1546
+ renderElements.length = 0;
1547
+ var virtualCamera = context.virtualCamera;
1548
+ this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1549
+ var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1550
+ var renderers = this._getRenderers();
1551
+ for(var i = 0, n = renderers.length; i < n; i++){
1552
+ var renderer = renderers[i];
1553
+ // Filter by camera culling mask
1554
+ if (!(cullingMask & renderer.entity.layer)) {
1555
+ continue;
1556
+ }
1557
+ // Filter by camera frustum
1558
+ if (enableFrustumCulling) {
1559
+ switch(mode){
1560
+ case CanvasRenderMode.ScreenSpaceOverlay:
1561
+ var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1562
+ if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1563
+ continue;
1564
+ }
1565
+ break;
1566
+ case CanvasRenderMode.ScreenSpaceCamera:
1567
+ case CanvasRenderMode.WorldSpace:
1568
+ if (!frustum.intersectsBox(renderer.bounds)) {
1569
+ continue;
1570
+ }
1571
+ break;
1572
+ }
1573
+ }
1574
+ renderer._prepareRender(context);
1575
+ renderer._renderFrameCount = frameCount;
1576
+ }
1577
+ var batchedRenderElements = this._batchedRenderElements;
1578
+ batchedRenderElements.length = 0;
1579
+ UIBatchSorter.sort(renderElements, this.entity.transform.worldMatrix);
1580
+ engine._batcherManager.batch(renderElements, batchedRenderElements);
1581
+ for(var i1 = 0, n1 = batchedRenderElements.length; i1 < n1; i1++){
1582
+ batchedRenderElements[i1].subDistancePriority = i1;
1583
+ }
1584
+ };
1585
+ /**
1586
+ * @internal
1587
+ */ _proto._updateSortDistance = function _updateSortDistance(isOrthographic, cameraPosition, cameraForward) {
1588
+ switch(this._realRenderMode){
1589
+ case CanvasRenderMode.ScreenSpaceOverlay:
1590
+ this._sortDistance = 0;
1591
+ break;
1592
+ case CanvasRenderMode.ScreenSpaceCamera:
1593
+ this._sortDistance = this._distance;
1594
+ break;
1595
+ case CanvasRenderMode.WorldSpace:
1596
+ var boundsCenter = this._getCenter();
1597
+ if (isOrthographic) {
1598
+ var distance = UICanvas._tempVec3;
1599
+ engine.Vector3.subtract(boundsCenter, cameraPosition, distance);
1600
+ this._sortDistance = engine.Vector3.dot(distance, cameraForward);
1601
+ } else {
1602
+ this._sortDistance = engine.Vector3.distanceSquared(boundsCenter, cameraPosition);
1603
+ }
1604
+ break;
1605
+ }
1606
+ };
1607
+ // @ts-ignore
1608
+ _proto._onEnableInScene = function _onEnableInScene() {
1609
+ var entity = this.entity;
1610
+ // @ts-ignore
1611
+ entity._dispatchModify(4, this);
1612
+ var rootCanvas = Utils.searchRootCanvasInParents(this);
1613
+ this._setIsRootCanvas(!rootCanvas);
1614
+ Utils.setRootCanvas(this, rootCanvas);
1615
+ };
1616
+ // @ts-ignore
1617
+ _proto._onDisableInScene = function _onDisableInScene() {
1618
+ this._setIsRootCanvas(false);
1619
+ Utils.cleanRootCanvas(this);
1620
+ };
1621
+ // @ts-ignore
1622
+ _proto._onDisable = function _onDisable() {
1623
+ this._renderElements.length = 0;
1624
+ this._batchedRenderElements.length = 0;
1625
+ };
1626
+ /**
1627
+ * @internal
1628
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1629
+ if (this._isRootCanvas) {
1630
+ if (flag === engine.EntityModifyFlags.Parent) {
1631
+ var rootCanvas = Utils.searchRootCanvasInParents(this);
1632
+ this._setIsRootCanvas(!rootCanvas);
1633
+ Utils.setRootCanvas(this, rootCanvas);
1634
+ } else if (flag === 4) {
1635
+ this._setIsRootCanvas(false);
1636
+ Utils.setRootCanvas(this, param);
1637
+ }
1638
+ } else {
1639
+ if (flag === engine.EntityModifyFlags.Parent) {
1640
+ var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1641
+ this._setIsRootCanvas(!rootCanvas1);
1642
+ Utils.setRootCanvas(this, rootCanvas1);
1643
+ }
1644
+ }
1645
+ };
1646
+ /**
1647
+ * @inheritdoc
1648
+ */ _proto._onClone = function _onClone(target) {
1649
+ target.renderMode = this._renderMode;
1650
+ };
1651
+ _proto._getRenderers = function _getRenderers() {
1652
+ var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1653
+ var uiHierarchyVersion = entity._uiHierarchyVersion;
1654
+ if (this._hierarchyVersion !== uiHierarchyVersion) {
1655
+ renderers.length = this._walk(this.entity, renderers);
1656
+ UICanvas._tempGroupAbleList.length = 0;
1657
+ this._hierarchyVersion = uiHierarchyVersion;
1658
+ ++UICanvas._hierarchyCounter;
1659
+ }
1660
+ return renderers;
1661
+ };
1662
+ _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1663
+ var transform = this.entity.transform;
1664
+ var realRenderMode = this._realRenderMode;
1665
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1666
+ var cameraEntity = this._camera.entity;
1667
+ if (!this._isSameOrChildEntity(cameraEntity)) {
1668
+ var cameraTransform = cameraEntity.transform;
1669
+ var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1670
+ var distance = this._distance;
1671
+ transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1672
+ transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
1673
+ }
1674
+ } else {
1675
+ var canvas = this.engine.canvas;
1676
+ transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1677
+ transform.worldRotationQuaternion.set(0, 0, 0, 1);
1678
+ }
1679
+ };
1680
+ _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1681
+ var transform = this.entity.transform;
1682
+ var realRenderMode = this._realRenderMode;
1683
+ var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1684
+ var curWidth;
1685
+ var curHeight;
1686
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1687
+ var camera = this._camera;
1688
+ curHeight = camera.isOrthographic ? camera.orthographicSize * 2 : 2 * (Math.tan(engine.MathUtil.degreeToRadian(camera.fieldOfView * 0.5)) * this._distance);
1689
+ curWidth = camera.aspectRatio * curHeight;
1690
+ } else {
1691
+ var canvas = this.engine.canvas;
1692
+ curHeight = canvas.height;
1693
+ curWidth = canvas.width;
1694
+ }
1695
+ var expectX, expectY, expectZ;
1696
+ switch(this._resolutionAdaptationMode){
1697
+ case ResolutionAdaptationMode.WidthAdaptation:
1698
+ expectX = expectY = expectZ = curWidth / width;
1699
+ break;
1700
+ case ResolutionAdaptationMode.HeightAdaptation:
1701
+ expectX = expectY = expectZ = curHeight / height;
1702
+ break;
1703
+ case ResolutionAdaptationMode.BothAdaptation:
1704
+ expectX = curWidth / width;
1705
+ expectY = curHeight / height;
1706
+ expectZ = (expectX + expectY) * 0.5;
1707
+ break;
1708
+ case ResolutionAdaptationMode.ExpandAdaptation:
1709
+ expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1710
+ break;
1711
+ case ResolutionAdaptationMode.ShrinkAdaptation:
1712
+ expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1713
+ break;
1714
+ }
1715
+ var worldMatrix = UICanvas._tempMat;
1716
+ engine.Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1717
+ transform.worldMatrix = worldMatrix;
1718
+ transform.size.set(curWidth / expectX, curHeight / expectY);
1719
+ };
1720
+ _proto._walk = function _walk(entity, renderers, depth, group) {
1721
+ if (depth === void 0) depth = 0;
1722
+ if (group === void 0) group = null;
1723
+ // @ts-ignore
1724
+ var components = entity._components;
1725
+ var tempGroupAbleList = UICanvas._tempGroupAbleList;
1726
+ var groupAbleCount = 0;
1727
+ for(var i = 0, n = components.length; i < n; i++){
1728
+ var component = components[i];
1729
+ if (!component.enabled) continue;
1730
+ if (_instanceof(component, exports.UIRenderer)) {
1731
+ renderers[depth] = component;
1732
+ ++depth;
1733
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1734
+ if (component._isGroupDirty) {
1735
+ tempGroupAbleList[groupAbleCount++] = component;
1736
+ }
1737
+ } else if (_instanceof(component, UIInteractive)) {
1738
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1739
+ if (component._isGroupDirty) {
1740
+ tempGroupAbleList[groupAbleCount++] = component;
1741
+ }
1742
+ } else if (_instanceof(component, UIGroup)) {
1743
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1744
+ component._isGroupDirty && Utils.setGroup(component, group);
1745
+ group = component;
1746
+ }
1747
+ }
1748
+ for(var i1 = 0; i1 < groupAbleCount; i1++){
1749
+ Utils.setGroup(tempGroupAbleList[i1], group);
1750
+ }
1751
+ var children = entity.children;
1752
+ for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1753
+ var child = children[i2];
1754
+ child.isActive && (depth = this._walk(child, renderers, depth, group));
1755
+ }
1756
+ return depth;
1757
+ };
1758
+ _proto._updateCameraObserver = function _updateCameraObserver() {
1759
+ var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._camera : null;
1760
+ var preCamera = this._cameraObserver;
1761
+ if (preCamera !== camera) {
1762
+ this._cameraObserver = camera;
1763
+ if (preCamera) {
1764
+ // @ts-ignore
1765
+ preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1766
+ // @ts-ignore
1767
+ preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1768
+ }
1769
+ if (camera) {
1770
+ // @ts-ignore
1771
+ camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1772
+ // @ts-ignore
1773
+ camera._registerModifyListener(this._onCameraModifyListener);
1774
+ }
1775
+ }
1776
+ };
1777
+ _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1778
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1779
+ switch(flag){
1780
+ case engine.CameraModifyFlags.ProjectionType:
1781
+ case engine.CameraModifyFlags.AspectRatio:
1782
+ this._adapterSizeInScreenSpace();
1783
+ break;
1784
+ case engine.CameraModifyFlags.FieldOfView:
1785
+ !this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1786
+ break;
1787
+ case engine.CameraModifyFlags.OrthographicSize:
1788
+ this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1789
+ break;
1790
+ case engine.CameraModifyFlags.DisableInScene:
1791
+ this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
1792
+ break;
1793
+ }
1794
+ } else {
1795
+ flag === engine.CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
1796
+ }
1797
+ };
1798
+ _proto._onCameraTransformListener = function _onCameraTransformListener() {
1799
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1800
+ };
1801
+ _proto._addCanvasListener = function _addCanvasListener() {
1802
+ // @ts-ignore
1803
+ this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1804
+ };
1805
+ _proto._removeCanvasListener = function _removeCanvasListener() {
1806
+ // @ts-ignore
1807
+ this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1808
+ };
1809
+ _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1810
+ var canvas = this.engine.canvas;
1811
+ this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1812
+ this._adapterSizeInScreenSpace();
1813
+ };
1814
+ _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1815
+ var realRenderMode = this._realRenderMode;
1816
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1817
+ this._adapterSizeInScreenSpace();
1818
+ }
1819
+ };
1820
+ _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1821
+ var _this = this;
1822
+ if (this._isRootCanvas !== isRootCanvas) {
1823
+ this._isRootCanvas = isRootCanvas;
1824
+ this._updateCameraObserver();
1825
+ this._setRealRenderMode(this._getRealRenderMode());
1826
+ if (isRootCanvas) {
1827
+ this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1828
+ } else {
1829
+ var _this1 = this, disorderedElements = _this1._disorderedElements;
1830
+ disorderedElements.forEach(function(element) {
1831
+ if (_instanceof(element, UICanvas)) {
1832
+ var rootCanvas = Utils.searchRootCanvasInParents(element);
1833
+ element._setIsRootCanvas(!rootCanvas);
1834
+ Utils.setRootCanvas(element, rootCanvas);
1835
+ } else {
1836
+ Utils.setRootCanvasDirty(_this);
1837
+ Utils.setGroupDirty(element);
1838
+ }
1839
+ });
1840
+ disorderedElements.length = 0;
1841
+ disorderedElements.garbageCollection();
1842
+ this._orderedRenderers.length = 0;
1843
+ }
1844
+ }
1845
+ };
1846
+ _proto._getCenter = function _getCenter() {
1847
+ if (this._centerDirtyFlag.flag) {
1848
+ var center = this._center;
1849
+ var uiTransform = this.entity.transform;
1850
+ var pivot = uiTransform.pivot, size = uiTransform.size;
1851
+ center.set((0.5 - pivot.x) * size.x, (0.5 - pivot.y) * size.y, 0);
1852
+ engine.Vector3.transformCoordinate(center, uiTransform.worldMatrix, center);
1853
+ this._centerDirtyFlag.flag = false;
1854
+ }
1855
+ return this._center;
1856
+ };
1857
+ _proto._getRealRenderMode = function _getRealRenderMode() {
1858
+ if (this._isRootCanvas) {
1859
+ var _this__camera;
1860
+ var mode = this._renderMode;
1861
+ // @ts-ignore
1862
+ if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__camera = this._camera) == null ? void 0 : _this__camera._phasedActiveInScene)) {
1863
+ return CanvasRenderMode.ScreenSpaceOverlay;
1864
+ } else {
1865
+ return mode;
1866
+ }
1867
+ } else {
1868
+ return 4;
1869
+ }
1870
+ };
1871
+ _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1872
+ var preRealMode = this._realRenderMode;
1873
+ if (preRealMode !== curRealMode) {
1874
+ this._realRenderMode = curRealMode;
1875
+ // @ts-ignore
1876
+ var componentsManager = this.scene._componentsManager;
1877
+ switch(preRealMode){
1878
+ case CanvasRenderMode.ScreenSpaceOverlay:
1879
+ this._removeCanvasListener();
1880
+ case CanvasRenderMode.ScreenSpaceCamera:
1881
+ case CanvasRenderMode.WorldSpace:
1882
+ componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1883
+ break;
1884
+ }
1885
+ switch(curRealMode){
1886
+ case CanvasRenderMode.ScreenSpaceOverlay:
1887
+ this._addCanvasListener();
1888
+ case CanvasRenderMode.ScreenSpaceCamera:
1889
+ this._adapterPoseInScreenSpace();
1890
+ this._adapterSizeInScreenSpace();
1891
+ case CanvasRenderMode.WorldSpace:
1892
+ componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1893
+ break;
1894
+ }
1895
+ }
1896
+ };
1897
+ _proto._isSameOrChildEntity = function _isSameOrChildEntity(cameraEntity) {
1898
+ var canvasEntity = this.entity;
1899
+ while(cameraEntity){
1900
+ if (cameraEntity === canvasEntity) return true;
1901
+ cameraEntity = cameraEntity.parent;
1902
+ }
1903
+ return false;
1904
+ };
1905
+ _create_class(UICanvas, [
1906
+ {
1907
+ key: "referenceResolutionPerUnit",
1908
+ get: /**
1909
+ * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1910
+ */ function get() {
1911
+ return this._referenceResolutionPerUnit;
1912
+ },
1913
+ set: function set(value) {
1914
+ if (this._referenceResolutionPerUnit !== value) {
1915
+ this._referenceResolutionPerUnit = value;
1916
+ this._disorderedElements.forEach(function(element) {
1917
+ element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1918
+ });
1919
+ }
1920
+ }
1921
+ },
1922
+ {
1923
+ key: "referenceResolution",
1924
+ get: /**
1925
+ * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1926
+ */ function get() {
1927
+ return this._referenceResolution;
1928
+ },
1929
+ set: function set(value) {
1930
+ var referenceResolution = this._referenceResolution;
1931
+ if (referenceResolution === value) return;
1932
+ (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
1933
+ }
1934
+ },
1935
+ {
1936
+ key: "renderMode",
1937
+ get: /**
1938
+ * The rendering mode of the UI canvas.
1939
+ */ function get() {
1940
+ return this._renderMode;
1941
+ },
1942
+ set: function set(mode) {
1943
+ var preMode = this._renderMode;
1944
+ if (preMode !== mode) {
1945
+ this._renderMode = mode;
1946
+ this._updateCameraObserver();
1947
+ this._setRealRenderMode(this._getRealRenderMode());
1948
+ }
1949
+ }
1950
+ },
1951
+ {
1952
+ key: "camera",
1953
+ get: /**
1954
+ * The camera associated with this canvas.
1955
+ * @remarks
1956
+ * - `ScreenSpaceCamera` mode: Used for rendering adaptation. Defaults to `ScreenSpaceOverlay` if not assigned.
1957
+ * - `WorldSpace` mode: Used for event detection. If not assigned, events are handled by the highest-priority camera.
1958
+ */ function get() {
1959
+ return this._camera;
1960
+ },
1961
+ set: function set(value) {
1962
+ var preCamera = this._camera;
1963
+ if (preCamera !== value) {
1964
+ if (value && this._isSameOrChildEntity(value.entity)) {
1965
+ engine.Logger.warn("Camera entity matching or nested within the canvas entity disables canvas auto-adaptation in ScreenSpaceCamera mode.");
1966
+ }
1967
+ this._camera = value;
1968
+ this._updateCameraObserver();
1969
+ var preRenderMode = this._realRenderMode;
1970
+ var curRenderMode = this._getRealRenderMode();
1971
+ if (preRenderMode === curRenderMode) {
1972
+ if (curRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1973
+ this._adapterPoseInScreenSpace();
1974
+ this._adapterSizeInScreenSpace();
1975
+ }
1976
+ } else {
1977
+ this._setRealRenderMode(curRenderMode);
1978
+ }
1979
+ }
1980
+ }
1981
+ },
1982
+ {
1983
+ key: "renderCamera",
1984
+ get: /**
1985
+ * @deprecated Use {@link camera} instead.
1986
+ */ function get() {
1987
+ return this.camera;
1988
+ },
1989
+ set: function set(value) {
1990
+ this.camera = value;
1991
+ }
1992
+ },
1993
+ {
1994
+ key: "resolutionAdaptationMode",
1995
+ get: /**
1996
+ * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1997
+ */ function get() {
1998
+ return this._resolutionAdaptationMode;
1999
+ },
2000
+ set: function set(value) {
2001
+ if (this._resolutionAdaptationMode !== value) {
2002
+ this._resolutionAdaptationMode = value;
2003
+ var realRenderMode = this._realRenderMode;
2004
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
2005
+ this._adapterSizeInScreenSpace();
2006
+ }
2007
+ }
2008
+ }
2009
+ },
2010
+ {
2011
+ key: "sortOrder",
2012
+ get: /**
2013
+ * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
2014
+ */ function get() {
2015
+ return this._sortOrder;
2016
+ },
2017
+ set: function set(value) {
2018
+ if (this._sortOrder !== value) {
2019
+ this._sortOrder = value;
2020
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
2021
+ (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
2022
+ }
2023
+ }
2024
+ },
2025
+ {
2026
+ key: "distance",
2027
+ get: /**
2028
+ * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
2029
+ */ function get() {
2030
+ return this._distance;
2031
+ },
2032
+ set: function set(value) {
2033
+ if (this._distance !== value) {
2034
+ this._distance = value;
2035
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
2036
+ this._adapterPoseInScreenSpace();
2037
+ this._adapterSizeInScreenSpace();
2038
+ }
2039
+ }
2040
+ }
2041
+ }
2042
+ ]);
2043
+ return UICanvas;
2044
+ }(engine.Component);
2045
+ /** @internal */ exports.UICanvas._hierarchyCounter = 1;
2046
+ exports.UICanvas._tempGroupAbleList = [];
2047
+ exports.UICanvas._tempVec3 = new engine.Vector3();
2048
+ exports.UICanvas._tempMat = new engine.Matrix();
2049
+ __decorate([
2050
+ engine.ignoreClone
2051
+ ], exports.UICanvas.prototype, "_canvasIndex", void 0);
2052
+ __decorate([
2053
+ engine.ignoreClone
2054
+ ], exports.UICanvas.prototype, "_indexInRootCanvas", void 0);
2055
+ __decorate([
2056
+ engine.ignoreClone
2057
+ ], exports.UICanvas.prototype, "_isRootCanvasDirty", void 0);
2058
+ __decorate([
2059
+ engine.ignoreClone
2060
+ ], exports.UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
2061
+ __decorate([
2062
+ engine.ignoreClone
2063
+ ], exports.UICanvas.prototype, "_isRootCanvas", void 0);
2064
+ __decorate([
2065
+ engine.ignoreClone
2066
+ ], exports.UICanvas.prototype, "_renderElements", void 0);
2067
+ __decorate([
2068
+ engine.ignoreClone
2069
+ ], exports.UICanvas.prototype, "_batchedRenderElements", void 0);
2070
+ __decorate([
2071
+ engine.ignoreClone
2072
+ ], exports.UICanvas.prototype, "_sortDistance", void 0);
2073
+ __decorate([
2074
+ engine.ignoreClone
2075
+ ], exports.UICanvas.prototype, "_orderedRenderers", void 0);
2076
+ __decorate([
2077
+ engine.ignoreClone
2078
+ ], exports.UICanvas.prototype, "_realRenderMode", void 0);
2079
+ __decorate([
2080
+ engine.ignoreClone
2081
+ ], exports.UICanvas.prototype, "_renderMode", void 0);
2082
+ __decorate([
2083
+ engine.ignoreClone
2084
+ ], exports.UICanvas.prototype, "_hierarchyVersion", void 0);
2085
+ __decorate([
2086
+ engine.ignoreClone
2087
+ ], exports.UICanvas.prototype, "_center", void 0);
2088
+ __decorate([
2089
+ engine.ignoreClone
2090
+ ], exports.UICanvas.prototype, "_rootCanvasListener", null);
2091
+ __decorate([
2092
+ engine.ignoreClone
2093
+ ], exports.UICanvas.prototype, "_onCameraModifyListener", null);
2094
+ __decorate([
2095
+ engine.ignoreClone
2096
+ ], exports.UICanvas.prototype, "_onCameraTransformListener", null);
2097
+ __decorate([
2098
+ engine.ignoreClone
2099
+ ], exports.UICanvas.prototype, "_onCanvasSizeListener", null);
2100
+ __decorate([
2101
+ engine.ignoreClone
2102
+ ], exports.UICanvas.prototype, "_onReferenceResolutionChanged", null);
2103
+ exports.UICanvas = __decorate([
2104
+ engine.dependentComponents(UITransform, engine.DependentMode.AutoAdd)
2105
+ ], exports.UICanvas);
2106
+ /**
2107
+ * @remarks Extends `EntityModifyFlags`.
2108
+ */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
2109
+ EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
2110
+ EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
2111
+ return EntityUIModifyFlags;
2112
+ }({});
2113
+ var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
2114
+ RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
2115
+ RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
2116
+ RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
2117
+ return RootCanvasModifyFlags;
2118
+ }({});
2119
+
2120
+ var Button = /*#__PURE__*/ function(UIInteractive) {
2121
+ _inherits(Button, UIInteractive);
2122
+ function Button() {
2123
+ var _this;
2124
+ _this = UIInteractive.apply(this, arguments) || this, /** Signal emitted when the button is clicked. */ _this.onClick = new engine.Signal();
2125
+ return _this;
2126
+ }
2127
+ var _proto = Button.prototype;
2128
+ _proto.onPointerClick = function onPointerClick(event) {
2129
+ if (!this._getGlobalInteractive()) return;
2130
+ this.onClick.invoke(event);
2131
+ };
2132
+ _proto.onDestroy = function onDestroy() {
2133
+ UIInteractive.prototype.onDestroy.call(this);
2134
+ this.onClick.removeAll();
2135
+ };
2136
+ /**
2137
+ * Add a listening function for click.
2138
+ * @deprecated Use `onClick.on(listener, context)` instead.
2139
+ */ _proto.addClicked = function addClicked(listener) {
2140
+ this.onClick.on(listener);
2141
+ };
2142
+ /**
2143
+ * Remove a listening function of click.
2144
+ * @deprecated Use `onClick.off(listener, context)` instead.
2145
+ */ _proto.removeClicked = function removeClicked(listener) {
2146
+ this.onClick.off(listener);
2147
+ };
2148
+ return Button;
2149
+ }(UIInteractive);
2150
+
2151
+ /**
2152
+ * UI element that renders an image.
2153
+ */ var Image = /*#__PURE__*/ function(UIRenderer1) {
2154
+ _inherits(Image, UIRenderer1);
2155
+ function Image(entity) {
2156
+ var _this;
2157
+ _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = engine.SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5;
2158
+ _this.drawMode = engine.SpriteDrawMode.Simple;
2159
+ // @ts-ignore
2160
+ _this.setMaterial(_this._engine._getUIDefaultMaterial());
2161
+ _this._onSpriteChange = _this._onSpriteChange.bind(_this);
2162
+ return _this;
2163
+ }
2164
+ var _proto = Image.prototype;
2165
+ /**
2166
+ * @internal
2167
+ */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2168
+ if (flag & RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2169
+ var drawMode = this._drawMode;
2170
+ if (drawMode === engine.SpriteDrawMode.Tiled) {
2171
+ this._dirtyUpdateFlag |= 15;
2172
+ } else if (drawMode === engine.SpriteDrawMode.Sliced) {
2173
+ this._dirtyUpdateFlag |= engine.RendererUpdateFlags.WorldVolume;
2174
+ }
2175
+ }
2176
+ };
2177
+ /**
2178
+ * @inheritdoc
2179
+ */ _proto._onClone = function _onClone(target) {
2180
+ UIRenderer1.prototype._onClone.call(this, target);
2181
+ target.sprite = this._sprite;
2182
+ target.drawMode = this._drawMode;
2183
+ };
2184
+ _proto._updateBounds = function _updateBounds(worldBounds) {
2185
+ var sprite = this._sprite;
2186
+ var rootCanvas = this._getRootCanvas();
2187
+ if (sprite && rootCanvas) {
2188
+ var transform = this._transformEntity.transform;
2189
+ var size = transform.size;
2190
+ this._assembler.updatePositions(this, transform.worldMatrix, size.x, size.y, transform.pivot, false, false, rootCanvas.referenceResolutionPerUnit);
2191
+ } else {
2192
+ var worldPosition = this._transformEntity.transform.worldPosition;
2193
+ worldBounds.min.copyFrom(worldPosition);
2194
+ worldBounds.max.copyFrom(worldPosition);
2195
+ }
2196
+ };
2197
+ _proto._render = function _render(context) {
2198
+ var _this = this, sprite = _this._sprite;
2199
+ var transform = this._transformEntity.transform;
2200
+ var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2201
+ if (!(sprite == null ? void 0 : sprite.texture) || !width || !height) {
2202
+ return;
2203
+ }
2204
+ var material = this.getMaterial();
2205
+ if (!material) {
2206
+ return;
2207
+ }
2208
+ // @todo: This question needs to be raised rather than hidden.
2209
+ if (material.destroyed) {
2210
+ // @ts-ignore
2211
+ material = this._engine._getUIDefaultMaterial();
2212
+ }
2213
+ var alpha = this._getGlobalAlpha();
2214
+ if (this._color.a * alpha <= 0) {
2215
+ return;
2216
+ }
2217
+ var _this1 = this, dirtyUpdateFlag = _this1._dirtyUpdateFlag;
2218
+ var canvas = this._getRootCanvas();
2219
+ // Update position
2220
+ if (dirtyUpdateFlag & engine.RendererUpdateFlags.WorldVolume) {
2221
+ this._assembler.updatePositions(this, transform.worldMatrix, width, height, transform.pivot, false, false, canvas.referenceResolutionPerUnit);
2222
+ dirtyUpdateFlag &= ~engine.RendererUpdateFlags.WorldVolume;
2223
+ }
2224
+ // Update uv
2225
+ if (dirtyUpdateFlag & 4) {
2226
+ this._assembler.updateUVs(this);
2227
+ dirtyUpdateFlag &= ~4;
2228
+ }
2229
+ // Update color
2230
+ if (dirtyUpdateFlag & UIRendererUpdateFlags.Color) {
2231
+ this._assembler.updateColor(this, alpha);
2232
+ dirtyUpdateFlag &= ~UIRendererUpdateFlags.Color;
2233
+ }
2234
+ this._dirtyUpdateFlag = dirtyUpdateFlag;
2235
+ var engine$1 = context.camera.engine;
2236
+ var renderElement = engine$1._renderElementPool.get();
2237
+ var subChunk = this._subChunk;
2238
+ renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
2239
+ renderElement.subShader = material.shader.subShaders[0];
2240
+ renderElement.priority = canvas.sortOrder;
2241
+ renderElement.distanceForSort = canvas._sortDistance;
2242
+ canvas._renderElements.push(renderElement);
2243
+ };
2244
+ _proto._onTransformChanged = function _onTransformChanged(type) {
2245
+ if (type & UITransformModifyFlags.Size && this._drawMode === engine.SpriteDrawMode.Tiled) {
2246
+ this._dirtyUpdateFlag |= 15;
2247
+ }
2248
+ this._dirtyUpdateFlag |= engine.RendererUpdateFlags.WorldVolume;
2249
+ };
2250
+ _proto._onDestroy = function _onDestroy() {
2251
+ var sprite = this._sprite;
2252
+ if (sprite) {
2253
+ this._addResourceReferCount(sprite, -1);
2254
+ // @ts-ignore
2255
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
2256
+ this._sprite = null;
2257
+ }
2258
+ UIRenderer1.prototype._onDestroy.call(this);
2259
+ };
2260
+ _proto._onSpriteChange = function _onSpriteChange(type) {
2261
+ switch(type){
2262
+ case engine.SpriteModifyFlags.texture:
2263
+ this.shaderData.setTexture(exports.UIRenderer._textureProperty, this.sprite.texture);
2264
+ break;
2265
+ case engine.SpriteModifyFlags.size:
2266
+ switch(this._drawMode){
2267
+ case engine.SpriteDrawMode.Sliced:
2268
+ this._dirtyUpdateFlag |= engine.RendererUpdateFlags.WorldVolume;
2269
+ break;
2270
+ case engine.SpriteDrawMode.Tiled:
2271
+ this._dirtyUpdateFlag |= 7;
2272
+ break;
2273
+ }
2274
+ break;
2275
+ case engine.SpriteModifyFlags.border:
2276
+ switch(this._drawMode){
2277
+ case engine.SpriteDrawMode.Sliced:
2278
+ this._dirtyUpdateFlag |= 5;
2279
+ break;
2280
+ case engine.SpriteDrawMode.Tiled:
2281
+ this._dirtyUpdateFlag |= 7;
2282
+ break;
2283
+ }
2284
+ break;
2285
+ case engine.SpriteModifyFlags.region:
2286
+ case engine.SpriteModifyFlags.atlasRegionOffset:
2287
+ this._dirtyUpdateFlag |= 5;
2288
+ break;
2289
+ case engine.SpriteModifyFlags.atlasRegion:
2290
+ this._dirtyUpdateFlag |= 4;
2291
+ break;
2292
+ case engine.SpriteModifyFlags.destroy:
2293
+ this.sprite = null;
2294
+ break;
2295
+ }
2296
+ };
2297
+ _create_class(Image, [
2298
+ {
2299
+ key: "drawMode",
2300
+ get: /**
2301
+ * The draw mode of the image.
2302
+ */ function get() {
2303
+ return this._drawMode;
2304
+ },
2305
+ set: function set(value) {
2306
+ if (this._drawMode !== value) {
2307
+ this._drawMode = value;
2308
+ switch(value){
2309
+ case engine.SpriteDrawMode.Simple:
2310
+ this._assembler = engine.SimpleSpriteAssembler;
2311
+ break;
2312
+ case engine.SpriteDrawMode.Sliced:
2313
+ this._assembler = engine.SlicedSpriteAssembler;
2314
+ break;
2315
+ case engine.SpriteDrawMode.Tiled:
2316
+ this._assembler = engine.TiledSpriteAssembler;
2317
+ break;
2318
+ }
2319
+ this._assembler.resetData(this);
2320
+ this._dirtyUpdateFlag |= 7;
2321
+ }
2322
+ }
2323
+ },
2324
+ {
2325
+ key: "tileMode",
2326
+ get: /**
2327
+ * The tiling mode of the image. (Only works in tiled mode.)
2328
+ */ function get() {
2329
+ return this._tileMode;
2330
+ },
2331
+ set: function set(value) {
2332
+ if (this._tileMode !== value) {
2333
+ this._tileMode = value;
2334
+ if (this.drawMode === engine.SpriteDrawMode.Tiled) {
2335
+ this._dirtyUpdateFlag |= 7;
2336
+ }
2337
+ }
2338
+ }
2339
+ },
2340
+ {
2341
+ key: "tiledAdaptiveThreshold",
2342
+ get: /**
2343
+ * Stretch Threshold in Tile Adaptive Mode, specified in normalized. (Only works in tiled adaptive mode.)
2344
+ */ function get() {
2345
+ return this._tiledAdaptiveThreshold;
2346
+ },
2347
+ set: function set(value) {
2348
+ if (value !== this._tiledAdaptiveThreshold) {
2349
+ value = engine.MathUtil.clamp(value, 0, 1);
2350
+ this._tiledAdaptiveThreshold = value;
2351
+ if (this.drawMode === engine.SpriteDrawMode.Tiled) {
2352
+ this._dirtyUpdateFlag |= 7;
2353
+ }
2354
+ }
2355
+ }
2356
+ },
2357
+ {
2358
+ key: "sprite",
2359
+ get: /**
2360
+ * The Sprite to render.
2361
+ */ function get() {
2362
+ return this._sprite;
2363
+ },
2364
+ set: function set(value) {
2365
+ var lastSprite = this._sprite;
2366
+ if (lastSprite !== value) {
2367
+ if (lastSprite) {
2368
+ this._addResourceReferCount(lastSprite, -1);
2369
+ // @ts-ignore
2370
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
2371
+ }
2372
+ this._dirtyUpdateFlag |= 7;
2373
+ if (value) {
2374
+ this._addResourceReferCount(value, 1);
2375
+ // @ts-ignore
2376
+ value._updateFlagManager.addListener(this._onSpriteChange);
2377
+ this.shaderData.setTexture(exports.UIRenderer._textureProperty, value.texture);
2378
+ } else {
2379
+ this.shaderData.setTexture(exports.UIRenderer._textureProperty, null);
2380
+ }
2381
+ this._sprite = value;
2382
+ }
2383
+ }
2384
+ }
2385
+ ]);
2386
+ return Image;
2387
+ }(exports.UIRenderer);
2388
+ __decorate([
2389
+ engine.ignoreClone
2390
+ ], Image.prototype, "_sprite", void 0);
2391
+ __decorate([
2392
+ engine.ignoreClone
2393
+ ], Image.prototype, "_drawMode", void 0);
2394
+ __decorate([
2395
+ engine.ignoreClone
2396
+ ], Image.prototype, "_assembler", void 0);
2397
+ __decorate([
2398
+ engine.ignoreClone
2399
+ ], Image.prototype, "_onTransformChanged", null);
2400
+ __decorate([
2401
+ engine.ignoreClone
2402
+ ], Image.prototype, "_onSpriteChange", null);
2403
+
2404
+ /**
2405
+ * UI component used to render text.
2406
+ */ var Text = /*#__PURE__*/ function(UIRenderer1) {
2407
+ _inherits(Text, UIRenderer1);
2408
+ function Text(entity) {
2409
+ var _this;
2410
+ _this = UIRenderer1.call(this, entity) || this, _this._textChunks = Array(), _this._subFont = null, _this._text = "", _this._localBounds = new engine.BoundingBox(), _this._font = null, _this._fontSize = 24, _this._fontStyle = engine.FontStyle.None, _this._lineSpacing = 0, _this._characterSpacing = 0, _this._horizontalAlignment = engine.TextHorizontalAlignment.Center, _this._verticalAlignment = engine.TextVerticalAlignment.Center, _this._enableWrapping = false, _this._overflowMode = engine.OverflowMode.Overflow;
2411
+ var engine$1 = _this.engine;
2412
+ // @ts-ignore
2413
+ _this.font = engine$1._textDefaultFont;
2414
+ _this.raycastEnabled = false;
2415
+ // @ts-ignore
2416
+ _this.setMaterial(engine$1._basicResources.textDefaultMaterial);
2417
+ return _this;
2418
+ }
2419
+ var _proto = Text.prototype;
2420
+ /**
2421
+ * @internal
2422
+ */ _proto._onDestroy = function _onDestroy() {
2423
+ if (this._font) {
2424
+ this._addResourceReferCount(this._font, -1);
2425
+ this._font = null;
2426
+ }
2427
+ UIRenderer1.prototype._onDestroy.call(this);
2428
+ this._freeTextChunks();
2429
+ this._textChunks = null;
2430
+ this._subFont && (this._subFont = null);
2431
+ };
2432
+ /**
2433
+ * @internal
2434
+ */ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
2435
+ return (this._dirtyUpdateFlag & type) != 0;
2436
+ };
2437
+ /**
2438
+ * @internal
2439
+ */ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
2440
+ this._dirtyUpdateFlag |= type;
2441
+ };
2442
+ /**
2443
+ * @internal
2444
+ */ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
2445
+ this._dirtyUpdateFlag &= ~type;
2446
+ };
2447
+ /**
2448
+ * @internal
2449
+ */ _proto._getSubFont = function _getSubFont() {
2450
+ if (!this._subFont) {
2451
+ this._resetSubFont();
2452
+ }
2453
+ return this._subFont;
2454
+ };
2455
+ /**
2456
+ * @internal
2457
+ */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2458
+ if (flag === RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2459
+ this._setDirtyFlagTrue(25);
2460
+ }
2461
+ };
2462
+ _proto._updateBounds = function _updateBounds(worldBounds) {
2463
+ var transform = this._transformEntity.transform;
2464
+ var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2465
+ var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
2466
+ worldBounds.min.set(-width * pivotX, -height * pivotY, 0);
2467
+ worldBounds.max.set(width * (1 - pivotX), height * (1 - pivotY), 0);
2468
+ engine.BoundingBox.transform(worldBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2469
+ };
2470
+ _proto._render = function _render(context) {
2471
+ if (this._isTextNoVisible()) {
2472
+ return;
2473
+ }
2474
+ if (this._isContainDirtyFlag(4)) {
2475
+ this._resetSubFont();
2476
+ this._setDirtyFlagFalse(4);
2477
+ }
2478
+ var canvas = this._getRootCanvas();
2479
+ if (this._isContainDirtyFlag(8)) {
2480
+ this._updateLocalData();
2481
+ this._setDirtyFlagFalse(8);
2482
+ }
2483
+ if (this._isContainDirtyFlag(16)) {
2484
+ this._updatePosition();
2485
+ this._setDirtyFlagFalse(16);
2486
+ }
2487
+ if (this._isContainDirtyFlag(UIRendererUpdateFlags.Color)) {
2488
+ this._updateColor();
2489
+ this._setDirtyFlagFalse(UIRendererUpdateFlags.Color);
2490
+ }
2491
+ var engine$1 = context.camera.engine;
2492
+ var textRenderElementPool = engine$1._textRenderElementPool;
2493
+ var material = this.getMaterial();
2494
+ var renderElements = canvas._renderElements;
2495
+ var priority = canvas.sortOrder;
2496
+ var distanceForSort = canvas._sortDistance;
2497
+ var textChunks = this._textChunks;
2498
+ var subShader = material.shader.subShaders[0];
2499
+ for(var i = 0, n = textChunks.length; i < n; ++i){
2500
+ var // @ts-ignore
2501
+ _renderElement;
2502
+ var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, texture = _textChunks_i.texture;
2503
+ var renderElement = textRenderElementPool.get();
2504
+ renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
2505
+ (_renderElement = renderElement).shaderData || (_renderElement.shaderData = new engine.ShaderData(engine.ShaderDataGroup.RenderElement));
2506
+ renderElement.shaderData.setTexture(Text._textTextureProperty, texture);
2507
+ renderElement.subShader = subShader;
2508
+ renderElement.priority = priority;
2509
+ renderElement.distanceForSort = distanceForSort;
2510
+ renderElements.push(renderElement);
2511
+ }
2512
+ };
2513
+ _proto._resetSubFont = function _resetSubFont() {
2514
+ var font = this._font;
2515
+ // @ts-ignore
2516
+ this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
2517
+ this._subFont.nativeFontString = engine.TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
2518
+ };
2519
+ _proto._updatePosition = function _updatePosition() {
2520
+ var e = this._transformEntity.transform.worldMatrix.elements;
2521
+ // prettier-ignore
2522
+ var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e12 = e[12], e13 = e[13], e14 = e[14];
2523
+ var up = exports.UIRenderer._tempVec31.set(e4, e5, e6);
2524
+ var right = exports.UIRenderer._tempVec30.set(e0, e1, e2);
2525
+ var worldPositions = Text._worldPositions;
2526
+ var worldPosition0 = worldPositions[0], worldPosition1 = worldPositions[1], worldPosition2 = worldPositions[2], worldPosition3 = worldPositions[3];
2527
+ var textChunks = this._textChunks;
2528
+ for(var i = 0, n = textChunks.length; i < n; ++i){
2529
+ var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, charRenderInfos = _textChunks_i.charRenderInfos;
2530
+ for(var j = 0, m = charRenderInfos.length; j < m; ++j){
2531
+ var charRenderInfo = charRenderInfos[j];
2532
+ var localPositions = charRenderInfo.localPositions;
2533
+ var topLeftX = localPositions.x, topLeftY = localPositions.y;
2534
+ // Top-Left
2535
+ worldPosition0.set(topLeftX * e0 + topLeftY * e4 + e12, topLeftX * e1 + topLeftY * e5 + e13, topLeftX * e2 + topLeftY * e6 + e14);
2536
+ // Right offset
2537
+ engine.Vector3.scale(right, localPositions.z - topLeftX, worldPosition1);
2538
+ // Top-Right
2539
+ engine.Vector3.add(worldPosition0, worldPosition1, worldPosition1);
2540
+ // Up offset
2541
+ engine.Vector3.scale(up, localPositions.w - topLeftY, worldPosition2);
2542
+ // Bottom-Left
2543
+ engine.Vector3.add(worldPosition0, worldPosition2, worldPosition3);
2544
+ // Bottom-Right
2545
+ engine.Vector3.add(worldPosition1, worldPosition2, worldPosition2);
2546
+ var vertices = subChunk.chunk.vertices;
2547
+ for(var k = 0, o = subChunk.vertexArea.start + charRenderInfo.indexInChunk * 36; k < 4; ++k, o += 9){
2548
+ worldPositions[k].copyToArray(vertices, o);
2549
+ }
2550
+ }
2551
+ }
2552
+ };
2553
+ _proto._updateColor = function _updateColor() {
2554
+ var _this__color = this._color, r = _this__color.r, g = _this__color.g, b = _this__color.b, a = _this__color.a;
2555
+ var finalAlpha = a * this._getGlobalAlpha();
2556
+ var textChunks = this._textChunks;
2557
+ for(var i = 0, n = textChunks.length; i < n; ++i){
2558
+ var subChunk = textChunks[i].subChunk;
2559
+ var vertexArea = subChunk.vertexArea;
2560
+ var vertexCount = vertexArea.size / 9;
2561
+ var vertices = subChunk.chunk.vertices;
2562
+ for(var j = 0, o = vertexArea.start + 5; j < vertexCount; ++j, o += 9){
2563
+ vertices[o] = r;
2564
+ vertices[o + 1] = g;
2565
+ vertices[o + 2] = b;
2566
+ vertices[o + 3] = finalAlpha;
2567
+ }
2568
+ }
2569
+ };
2570
+ _proto._updateLocalData = function _updateLocalData() {
2571
+ // @ts-ignore
2572
+ var pixelsPerResolution = engine.Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
2573
+ var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
2574
+ var charRenderInfos = Text._charRenderInfos;
2575
+ var charFont = this._getSubFont();
2576
+ var _this__transformEntity_transform = this._transformEntity.transform, size = _this__transformEntity_transform.size, pivot = _this__transformEntity_transform.pivot;
2577
+ var rendererWidth = size.x;
2578
+ var rendererHeight = size.y;
2579
+ var offsetWidth = rendererWidth * (0.5 - pivot.x);
2580
+ var offsetHeight = rendererHeight * (0.5 - pivot.y);
2581
+ var characterSpacing = this._characterSpacing * this._fontSize;
2582
+ var textMetrics = this.enableWrapping ? engine.TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing) : engine.TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing);
2583
+ var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
2584
+ // @ts-ignore
2585
+ var charRenderInfoPool = this.engine._charRenderInfoPool;
2586
+ var linesLen = lines.length;
2587
+ var renderElementCount = 0;
2588
+ if (linesLen > 0) {
2589
+ var horizontalAlignment = this.horizontalAlignment;
2590
+ var pixelsPerUnitReciprocal = 1.0 / pixelsPerResolution;
2591
+ rendererWidth *= pixelsPerResolution;
2592
+ rendererHeight *= pixelsPerResolution;
2593
+ var halfRendererWidth = rendererWidth * 0.5;
2594
+ var halfLineHeight = lineHeight * 0.5;
2595
+ var startY = 0;
2596
+ var topDiff = lineHeight * 0.5 - lineMaxSizes[0].ascent;
2597
+ var bottomDiff = lineHeight * 0.5 - lineMaxSizes[linesLen - 1].descent - 1;
2598
+ switch(this.verticalAlignment){
2599
+ case engine.TextVerticalAlignment.Top:
2600
+ startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
2601
+ break;
2602
+ case engine.TextVerticalAlignment.Center:
2603
+ startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
2604
+ break;
2605
+ case engine.TextVerticalAlignment.Bottom:
2606
+ startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
2607
+ break;
2608
+ }
2609
+ var firstLine = -1;
2610
+ var minX = Number.MAX_SAFE_INTEGER;
2611
+ var minY = Number.MAX_SAFE_INTEGER;
2612
+ var maxX = Number.MIN_SAFE_INTEGER;
2613
+ var maxY = Number.MIN_SAFE_INTEGER;
2614
+ for(var i = 0; i < linesLen; ++i){
2615
+ var lineWidth = lineWidths[i];
2616
+ if (lineWidth > 0) {
2617
+ var line = lines[i];
2618
+ var startX = 0;
2619
+ var firstRow = -1;
2620
+ if (firstLine < 0) {
2621
+ firstLine = i;
2622
+ }
2623
+ switch(horizontalAlignment){
2624
+ case engine.TextHorizontalAlignment.Left:
2625
+ startX = -halfRendererWidth;
2626
+ break;
2627
+ case engine.TextHorizontalAlignment.Center:
2628
+ startX = -lineWidth * 0.5;
2629
+ break;
2630
+ case engine.TextHorizontalAlignment.Right:
2631
+ startX = halfRendererWidth - lineWidth;
2632
+ break;
2633
+ }
2634
+ for(var j = 0, n = line.length; j < n; ++j){
2635
+ var char = line[j];
2636
+ var charInfo = charFont._getCharInfo(char);
2637
+ if (charInfo.h > 0) {
2638
+ firstRow < 0 && (firstRow = j);
2639
+ var charRenderInfo = charRenderInfos[renderElementCount++] = charRenderInfoPool.get();
2640
+ var localPositions = charRenderInfo.localPositions;
2641
+ charRenderInfo.texture = charFont._getTextureByIndex(charInfo.index);
2642
+ charRenderInfo.uvs = charInfo.uvs;
2643
+ var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
2644
+ var left = (startX + offsetWidth) * pixelsPerUnitReciprocal;
2645
+ var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal;
2646
+ var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal;
2647
+ var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal;
2648
+ localPositions.set(left, top, right, bottom);
2649
+ i === firstLine && (maxY = Math.max(maxY, top));
2650
+ minY = Math.min(minY, bottom);
2651
+ j === firstRow && (minX = Math.min(minX, left));
2652
+ maxX = Math.max(maxX, right);
2653
+ }
2654
+ startX += charInfo.xAdvance + characterSpacing;
2655
+ }
2656
+ }
2657
+ startY -= lineHeight;
2658
+ }
2659
+ if (firstLine < 0) {
2660
+ min.set(0, 0, 0);
2661
+ max.set(0, 0, 0);
2662
+ } else {
2663
+ min.set(minX, minY, 0);
2664
+ max.set(maxX, maxY, 0);
2665
+ }
2666
+ } else {
2667
+ min.set(0, 0, 0);
2668
+ max.set(0, 0, 0);
2669
+ }
2670
+ charFont._getLastIndex() > 0 && charRenderInfos.sort(function(a, b) {
2671
+ return a.texture.instanceId - b.texture.instanceId;
2672
+ });
2673
+ this._freeTextChunks();
2674
+ if (renderElementCount === 0) {
2675
+ return;
2676
+ }
2677
+ var textChunks = this._textChunks;
2678
+ var curTextChunk = new TextChunk();
2679
+ textChunks.push(curTextChunk);
2680
+ var chunkMaxVertexCount = this._getChunkManager().maxVertexCount;
2681
+ var curCharRenderInfo = charRenderInfos[0];
2682
+ var curTexture = curCharRenderInfo.texture;
2683
+ curTextChunk.texture = curTexture;
2684
+ var curCharInfos = curTextChunk.charRenderInfos;
2685
+ curCharInfos.push(curCharRenderInfo);
2686
+ for(var i1 = 1; i1 < renderElementCount; ++i1){
2687
+ var charRenderInfo1 = charRenderInfos[i1];
2688
+ var texture = charRenderInfo1.texture;
2689
+ if (curTexture !== texture || curCharInfos.length * 4 + 4 > chunkMaxVertexCount) {
2690
+ this._buildChunk(curTextChunk, curCharInfos.length);
2691
+ curTextChunk = new TextChunk();
2692
+ textChunks.push(curTextChunk);
2693
+ curTexture = texture;
2694
+ curTextChunk.texture = texture;
2695
+ curCharInfos = curTextChunk.charRenderInfos;
2696
+ }
2697
+ curCharInfos.push(charRenderInfo1);
2698
+ }
2699
+ var charLength = curCharInfos.length;
2700
+ if (charLength > 0) {
2701
+ this._buildChunk(curTextChunk, charLength);
2702
+ }
2703
+ charRenderInfos.length = 0;
2704
+ };
2705
+ _proto._onTransformChanged = function _onTransformChanged(type) {
2706
+ if (type & UITransformModifyFlags.Size || type & UITransformModifyFlags.Pivot) {
2707
+ this._dirtyUpdateFlag |= 8;
2708
+ }
2709
+ UIRenderer1.prototype._onTransformChanged.call(this, type);
2710
+ this._setDirtyFlagTrue(16);
2711
+ };
2712
+ _proto._isTextNoVisible = function _isTextNoVisible() {
2713
+ var size = this._transformEntity.transform.size;
2714
+ return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === engine.OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
2715
+ };
2716
+ _proto._buildChunk = function _buildChunk(textChunk, count) {
2717
+ var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
2718
+ var finalAlpha = a * this._getGlobalAlpha();
2719
+ var tempIndices = engine.CharRenderInfo.triangles;
2720
+ var tempIndicesLength = tempIndices.length;
2721
+ var subChunk = textChunk.subChunk = this._getChunkManager().allocateSubChunk(count * 4);
2722
+ var vertices = subChunk.chunk.vertices;
2723
+ var indices = subChunk.indices = [];
2724
+ var charRenderInfos = textChunk.charRenderInfos;
2725
+ for(var i = 0, ii = 0, io = 0, vo = subChunk.vertexArea.start + 3; i < count; ++i, io += 4){
2726
+ var charRenderInfo = charRenderInfos[i];
2727
+ charRenderInfo.indexInChunk = i;
2728
+ // Set indices
2729
+ for(var j = 0; j < tempIndicesLength; ++j){
2730
+ indices[ii++] = tempIndices[j] + io;
2731
+ }
2732
+ // Set uv and color for vertices
2733
+ for(var j1 = 0; j1 < 4; ++j1, vo += 9){
2734
+ var uv = charRenderInfo.uvs[j1];
2735
+ uv.copyToArray(vertices, vo);
2736
+ vertices[vo + 2] = r;
2737
+ vertices[vo + 3] = g;
2738
+ vertices[vo + 4] = b;
2739
+ vertices[vo + 5] = finalAlpha;
2740
+ }
2741
+ }
2742
+ return subChunk;
2743
+ };
2744
+ _proto._freeTextChunks = function _freeTextChunks() {
2745
+ var textChunks = this._textChunks;
2746
+ // @ts-ignore
2747
+ var charRenderInfoPool = this.engine._charRenderInfoPool;
2748
+ var manager = this._getChunkManager();
2749
+ for(var i = 0, n = textChunks.length; i < n; ++i){
2750
+ var textChunk = textChunks[i];
2751
+ var charRenderInfos = textChunk.charRenderInfos;
2752
+ for(var j = 0, m = charRenderInfos.length; j < m; ++j){
2753
+ charRenderInfoPool.return(charRenderInfos[j]);
2754
+ }
2755
+ charRenderInfos.length = 0;
2756
+ manager.freeSubChunk(textChunk.subChunk);
2757
+ textChunk.subChunk = null;
2758
+ textChunk.texture = null;
2759
+ }
2760
+ textChunks.length = 0;
2761
+ };
2762
+ _create_class(Text, [
2763
+ {
2764
+ key: "text",
2765
+ get: /**
2766
+ * Rendering string for the Text.
2767
+ */ function get() {
2768
+ return this._text;
2769
+ },
2770
+ set: function set(value) {
2771
+ value = value || "";
2772
+ if (this._text !== value) {
2773
+ this._text = value;
2774
+ this._setDirtyFlagTrue(25);
2775
+ }
2776
+ }
2777
+ },
2778
+ {
2779
+ key: "font",
2780
+ get: /**
2781
+ * The font of the Text.
2782
+ */ function get() {
2783
+ return this._font;
2784
+ },
2785
+ set: function set(value) {
2786
+ var lastFont = this._font;
2787
+ if (lastFont !== value) {
2788
+ lastFont && this._addResourceReferCount(lastFont, -1);
2789
+ value && this._addResourceReferCount(value, 1);
2790
+ this._font = value;
2791
+ this._setDirtyFlagTrue(29);
2792
+ }
2793
+ }
2794
+ },
2795
+ {
2796
+ key: "fontSize",
2797
+ get: /**
2798
+ * The font size of the Text.
2799
+ */ function get() {
2800
+ return this._fontSize;
2801
+ },
2802
+ set: function set(value) {
2803
+ if (this._fontSize !== value) {
2804
+ this._fontSize = value;
2805
+ this._setDirtyFlagTrue(29);
2806
+ }
2807
+ }
2808
+ },
2809
+ {
2810
+ key: "fontStyle",
2811
+ get: /**
2812
+ * The style of the font.
2813
+ */ function get() {
2814
+ return this._fontStyle;
2815
+ },
2816
+ set: function set(value) {
2817
+ if (this.fontStyle !== value) {
2818
+ this._fontStyle = value;
2819
+ this._setDirtyFlagTrue(29);
2820
+ }
2821
+ }
2822
+ },
2823
+ {
2824
+ key: "lineSpacing",
2825
+ get: /**
2826
+ * The space between two lines, in em (ratio of fontSize).
2827
+ */ function get() {
2828
+ return this._lineSpacing;
2829
+ },
2830
+ set: function set(value) {
2831
+ if (this._lineSpacing !== value) {
2832
+ this._lineSpacing = value;
2833
+ this._setDirtyFlagTrue(25);
2834
+ }
2835
+ }
2836
+ },
2837
+ {
2838
+ key: "characterSpacing",
2839
+ get: /**
2840
+ * The space between two characters, in em (ratio of fontSize).
2841
+ */ function get() {
2842
+ return this._characterSpacing;
2843
+ },
2844
+ set: function set(value) {
2845
+ if (this._characterSpacing !== value) {
2846
+ this._characterSpacing = value;
2847
+ this._setDirtyFlagTrue(25);
2848
+ }
2849
+ }
2850
+ },
2851
+ {
2852
+ key: "horizontalAlignment",
2853
+ get: /**
2854
+ * The horizontal alignment.
2855
+ */ function get() {
2856
+ return this._horizontalAlignment;
2857
+ },
2858
+ set: function set(value) {
2859
+ if (this._horizontalAlignment !== value) {
2860
+ this._horizontalAlignment = value;
2861
+ this._setDirtyFlagTrue(25);
2862
+ }
2863
+ }
2864
+ },
2865
+ {
2866
+ key: "verticalAlignment",
2867
+ get: /**
2868
+ * The vertical alignment.
2869
+ */ function get() {
2870
+ return this._verticalAlignment;
2871
+ },
2872
+ set: function set(value) {
2873
+ if (this._verticalAlignment !== value) {
2874
+ this._verticalAlignment = value;
2875
+ this._setDirtyFlagTrue(25);
2876
+ }
2877
+ }
2878
+ },
2879
+ {
2880
+ key: "enableWrapping",
2881
+ get: /**
2882
+ * Whether wrap text to next line when exceeds the width of the container.
2883
+ */ function get() {
2884
+ return this._enableWrapping;
2885
+ },
2886
+ set: function set(value) {
2887
+ if (this._enableWrapping !== value) {
2888
+ this._enableWrapping = value;
2889
+ this._setDirtyFlagTrue(25);
2890
+ }
2891
+ }
2892
+ },
2893
+ {
2894
+ key: "overflowMode",
2895
+ get: /**
2896
+ * The overflow mode.
2897
+ */ function get() {
2898
+ return this._overflowMode;
2899
+ },
2900
+ set: function set(value) {
2901
+ if (this._overflowMode !== value) {
2902
+ this._overflowMode = value;
2903
+ this._setDirtyFlagTrue(25);
2904
+ }
2905
+ }
2906
+ },
2907
+ {
2908
+ key: "maskLayer",
2909
+ get: /**
2910
+ * The mask layer the sprite renderer belongs to.
2911
+ */ function get() {
2912
+ return this._maskLayer;
2913
+ },
2914
+ set: function set(value) {
2915
+ this._maskLayer = value;
2916
+ }
2917
+ },
2918
+ {
2919
+ key: "bounds",
2920
+ get: /**
2921
+ * The bounding volume of the TextRenderer.
2922
+ */ function get() {
2923
+ if (this._isTextNoVisible()) {
2924
+ if (this._isContainDirtyFlag(engine.RendererUpdateFlags.WorldVolume)) {
2925
+ var localBounds = this._localBounds;
2926
+ localBounds.min.set(0, 0, 0);
2927
+ localBounds.max.set(0, 0, 0);
2928
+ this._updateBounds(this._bounds);
2929
+ this._setDirtyFlagFalse(engine.RendererUpdateFlags.WorldVolume);
2930
+ }
2931
+ return this._bounds;
2932
+ }
2933
+ this._isContainDirtyFlag(4) && this._resetSubFont();
2934
+ this._isContainDirtyFlag(8) && this._updateLocalData();
2935
+ this._isContainDirtyFlag(16) && this._updatePosition();
2936
+ this._isContainDirtyFlag(engine.RendererUpdateFlags.WorldVolume) && this._updateBounds(this._bounds);
2937
+ this._setDirtyFlagFalse(29);
2938
+ return this._bounds;
2939
+ }
2940
+ }
2941
+ ]);
2942
+ return Text;
2943
+ }(exports.UIRenderer);
2944
+ Text._textTextureProperty = engine.ShaderProperty.getByName("renderElement_TextTexture");
2945
+ Text._worldPositions = [
2946
+ new engine.Vector3(),
2947
+ new engine.Vector3(),
2948
+ new engine.Vector3(),
2949
+ new engine.Vector3()
2950
+ ];
2951
+ Text._charRenderInfos = [];
2952
+ __decorate([
2953
+ engine.ignoreClone
2954
+ ], Text.prototype, "_textChunks", void 0);
2955
+ __decorate([
2956
+ engine.ignoreClone
2957
+ ], Text.prototype, "_subFont", void 0);
2958
+ __decorate([
2959
+ engine.ignoreClone
2960
+ ], Text.prototype, "_localBounds", void 0);
2961
+ __decorate([
2962
+ engine.ignoreClone
2963
+ ], Text.prototype, "_onTransformChanged", null);
2964
+ var TextChunk = function TextChunk() {
2965
+ this.charRenderInfos = new Array();
2966
+ };
2967
+
2968
+ /**
2969
+ * The transition behavior of UIInteractive.
2970
+ */ var Transition = /*#__PURE__*/ function(DataObject) {
2971
+ _inherits(Transition, DataObject);
2972
+ function Transition() {
2973
+ var _this;
2974
+ _this = DataObject.apply(this, arguments) || this, _this._duration = 0, _this._countDown = 0, _this._finalState = InteractiveState.Normal;
2975
+ return _this;
2976
+ }
2977
+ var _proto = Transition.prototype;
2978
+ _proto.destroy = function destroy() {
2979
+ var _this__interactive;
2980
+ (_this__interactive = this._interactive) == null ? void 0 : _this__interactive.removeTransition(this);
2981
+ this._addStateValuesReferCount(-1);
2982
+ this._normal = this._pressed = this._hover = this._disabled = null;
2983
+ this._initialValue = this._currentValue = this._finalValue = null;
2984
+ this._target = null;
2985
+ };
2986
+ /**
2987
+ * @inheritdoc
2988
+ */ _proto._onClone = function _onClone(target) {
2989
+ target._addStateValuesReferCount(1);
2990
+ };
2991
+ /**
2992
+ * @internal
2993
+ */ _proto._setState = function _setState(state, instant) {
2994
+ this._finalState = state;
2995
+ var value = this._getValueByState(state);
2996
+ if (instant) {
2997
+ this._countDown = 0;
2998
+ this._initialValue = this._finalValue = value;
2999
+ } else {
3000
+ this._countDown = this._duration;
3001
+ this._initialValue = this._getTargetValueCopy();
3002
+ this._finalValue = value;
3003
+ }
3004
+ this._updateValue();
3005
+ };
3006
+ /**
3007
+ * @internal
3008
+ */ _proto._onUpdate = function _onUpdate(delta) {
3009
+ if (this._countDown > 0) {
3010
+ this._countDown -= delta;
3011
+ this._updateValue();
3012
+ }
3013
+ };
3014
+ _proto._onStateValueDirty = function _onStateValueDirty(state, preValue, curValue) {
3015
+ // @ts-ignore
3016
+ _instanceof(preValue, engine.ReferResource) && preValue._addReferCount(-1);
3017
+ // @ts-ignore
3018
+ _instanceof(curValue, engine.ReferResource) && curValue._addReferCount(1);
3019
+ if (this._finalState === state) {
3020
+ this._finalValue = curValue;
3021
+ this._updateValue();
3022
+ }
3023
+ };
3024
+ _proto._updateValue = function _updateValue() {
3025
+ var _this__target;
3026
+ var weight = this._duration ? 1 - this._countDown / this._duration : 1;
3027
+ this._updateCurrentValue(this._initialValue, this._finalValue, weight);
3028
+ ((_this__target = this._target) == null ? void 0 : _this__target.enabled) && this._applyValue(this._currentValue);
3029
+ };
3030
+ _proto._addStateValuesReferCount = function _addStateValuesReferCount(count) {
3031
+ var _this = this, _normal = _this._normal, _pressed = _this._pressed, _hover = _this._hover, _disabled = _this._disabled;
3032
+ // @ts-ignore
3033
+ _instanceof(_normal, engine.ReferResource) && _normal._addReferCount(count);
3034
+ // @ts-ignore
3035
+ _instanceof(_pressed, engine.ReferResource) && _pressed._addReferCount(count);
3036
+ // @ts-ignore
3037
+ _instanceof(_hover, engine.ReferResource) && _hover._addReferCount(count);
3038
+ // @ts-ignore
3039
+ _instanceof(_disabled, engine.ReferResource) && _disabled._addReferCount(count);
3040
+ };
3041
+ _proto._getValueByState = function _getValueByState(state) {
3042
+ switch(state){
3043
+ case InteractiveState.Normal:
3044
+ return this.normal;
3045
+ case InteractiveState.Pressed:
3046
+ return this.pressed;
3047
+ case InteractiveState.Hover:
3048
+ return this.hover;
3049
+ case InteractiveState.Disable:
3050
+ return this.disabled;
3051
+ }
3052
+ };
3053
+ _create_class(Transition, [
3054
+ {
3055
+ key: "normal",
3056
+ get: /**
3057
+ * The normal state of the transition.
3058
+ */ function get() {
3059
+ return this._normal;
3060
+ },
3061
+ set: function set(value) {
3062
+ var preNormal = this._normal;
3063
+ if (preNormal !== value) {
3064
+ this._normal = value;
3065
+ this._onStateValueDirty(InteractiveState.Normal, preNormal, value);
3066
+ }
3067
+ }
3068
+ },
3069
+ {
3070
+ key: "pressed",
3071
+ get: /**
3072
+ * The pressed state of the transition.
3073
+ */ function get() {
3074
+ return this._pressed;
3075
+ },
3076
+ set: function set(value) {
3077
+ var prePressed = this._pressed;
3078
+ if (prePressed !== value) {
3079
+ this._pressed = value;
3080
+ this._onStateValueDirty(InteractiveState.Pressed, prePressed, value);
3081
+ }
3082
+ }
3083
+ },
3084
+ {
3085
+ key: "hover",
3086
+ get: /**
3087
+ * The hover state of the transition.
3088
+ */ function get() {
3089
+ return this._hover;
3090
+ },
3091
+ set: function set(value) {
3092
+ var preHover = this._hover;
3093
+ if (preHover !== value) {
3094
+ this._hover = value;
3095
+ this._onStateValueDirty(InteractiveState.Hover, preHover, value);
3096
+ }
3097
+ }
3098
+ },
3099
+ {
3100
+ key: "disabled",
3101
+ get: /**
3102
+ * The disabled state of the transition.
3103
+ */ function get() {
3104
+ return this._disabled;
3105
+ },
3106
+ set: function set(value) {
3107
+ var preDisabled = this._disabled;
3108
+ if (preDisabled !== value) {
3109
+ this._disabled = value;
3110
+ this._onStateValueDirty(InteractiveState.Disable, preDisabled, value);
3111
+ }
3112
+ }
3113
+ },
3114
+ {
3115
+ key: "target",
3116
+ get: /**
3117
+ * The target of the transition.
3118
+ */ function get() {
3119
+ return this._target;
3120
+ },
3121
+ set: function set(value) {
3122
+ if (this._target !== value) {
3123
+ this._target = value;
3124
+ (value == null ? void 0 : value.enabled) && this._applyValue(this._currentValue);
3125
+ }
3126
+ }
3127
+ },
3128
+ {
3129
+ key: "duration",
3130
+ get: /**
3131
+ * The duration of the transition.
3132
+ */ function get() {
3133
+ return this._duration;
3134
+ },
3135
+ set: function set(value) {
3136
+ if (value < 0) value = 0;
3137
+ var preDuration = this._duration;
3138
+ if (preDuration !== value) {
3139
+ this._duration = value;
3140
+ if (this._countDown > 0) {
3141
+ this._countDown = value * (1 - this._countDown / preDuration);
3142
+ this._updateValue();
3143
+ }
3144
+ }
3145
+ }
3146
+ }
3147
+ ]);
3148
+ return Transition;
3149
+ }(engine.DataObject);
3150
+ __decorate([
3151
+ engine.ignoreClone
3152
+ ], Transition.prototype, "_countDown", void 0);
3153
+ __decorate([
3154
+ engine.ignoreClone
3155
+ ], Transition.prototype, "_initialValue", void 0);
3156
+ __decorate([
3157
+ engine.ignoreClone
3158
+ ], Transition.prototype, "_finalValue", void 0);
3159
+ __decorate([
3160
+ engine.ignoreClone
3161
+ ], Transition.prototype, "_currentValue", void 0);
3162
+ __decorate([
3163
+ engine.ignoreClone
3164
+ ], Transition.prototype, "_finalState", void 0);
3165
+
3166
+ /**
3167
+ * Color transition.
3168
+ */ var ColorTransition = /*#__PURE__*/ function(Transition) {
3169
+ _inherits(ColorTransition, Transition);
3170
+ function ColorTransition() {
3171
+ var _this;
3172
+ _this = Transition.call(this) || this, _this._color = new engine.Color();
3173
+ _this._normal = new engine.Color(1, 1, 1, 1);
3174
+ _this._hover = new engine.Color(0.9130986517934192, 0.9130986517934192, 0.9130986517934192, 1);
3175
+ _this._pressed = new engine.Color(0.5775804404296506, 0.5775804404296506, 0.5775804404296506, 1);
3176
+ _this._disabled = new engine.Color(0.5775804404296506, 0.5775804404296506, 0.5775804404296506, 1);
3177
+ _this._duration = 0.1;
3178
+ _this._currentValue = new engine.Color();
3179
+ _this._onNormalValueChanged = _this._onNormalValueChanged.bind(_this);
3180
+ _this._onHoverValueChanged = _this._onHoverValueChanged.bind(_this);
3181
+ _this._onPressedValueChanged = _this._onPressedValueChanged.bind(_this);
3182
+ _this._onDisabledValueChanged = _this._onDisabledValueChanged.bind(_this);
3183
+ // @ts-ignore
3184
+ _this._normal._onValueChanged = _this._onNormalValueChanged;
3185
+ // @ts-ignore
3186
+ _this._hover._onValueChanged = _this._onHoverValueChanged;
3187
+ // @ts-ignore
3188
+ _this._pressed._onValueChanged = _this._onPressedValueChanged;
3189
+ // @ts-ignore
3190
+ _this._disabled._onValueChanged = _this._onDisabledValueChanged;
3191
+ return _this;
3192
+ }
3193
+ var _proto = ColorTransition.prototype;
3194
+ _proto._onNormalValueChanged = function _onNormalValueChanged() {
3195
+ if (this._finalState === InteractiveState.Normal) {
3196
+ this._finalValue = this._normal;
3197
+ this._updateValue();
3198
+ }
3199
+ };
3200
+ _proto._onHoverValueChanged = function _onHoverValueChanged() {
3201
+ if (this._finalState === InteractiveState.Hover) {
3202
+ this._finalValue = this._hover;
3203
+ this._updateValue();
3204
+ }
3205
+ };
3206
+ _proto._onPressedValueChanged = function _onPressedValueChanged() {
3207
+ if (this._finalState === InteractiveState.Pressed) {
3208
+ this._finalValue = this._pressed;
3209
+ this._updateValue();
3210
+ }
3211
+ };
3212
+ _proto._onDisabledValueChanged = function _onDisabledValueChanged() {
3213
+ if (this._finalState === InteractiveState.Disable) {
3214
+ this._finalValue = this._disabled;
3215
+ this._updateValue();
3216
+ }
3217
+ };
3218
+ _proto._getTargetValueCopy = function _getTargetValueCopy() {
3219
+ var _this__target;
3220
+ var color = this._color;
3221
+ color.copyFrom(((_this__target = this._target) == null ? void 0 : _this__target.color) || this._normal);
3222
+ return color;
3223
+ };
3224
+ _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3225
+ if (weight >= 1) {
3226
+ this._currentValue.copyFrom(destValue);
3227
+ } else {
3228
+ engine.Color.lerp(srcValue, destValue, weight, this._currentValue);
3229
+ }
3230
+ };
3231
+ _proto._applyValue = function _applyValue(value) {
3232
+ this._target.color = value;
3233
+ };
3234
+ return ColorTransition;
3235
+ }(Transition);
3236
+
3237
+ /**
3238
+ * Scale transition.
3239
+ */ var ScaleTransition = /*#__PURE__*/ function(Transition) {
3240
+ _inherits(ScaleTransition, Transition);
3241
+ function ScaleTransition() {
3242
+ var _this;
3243
+ _this = Transition.call(this) || this;
3244
+ _this._normal = 1;
3245
+ _this._hover = 1;
3246
+ _this._pressed = 1.2;
3247
+ _this._disabled = 1;
3248
+ _this._duration = 0.1;
3249
+ return _this;
3250
+ }
3251
+ var _proto = ScaleTransition.prototype;
3252
+ _proto._getTargetValueCopy = function _getTargetValueCopy() {
3253
+ var _this__target;
3254
+ return ((_this__target = this._target) == null ? void 0 : _this__target.entity.transform.scale.x) || this._normal;
3255
+ };
3256
+ _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3257
+ this._currentValue = weight >= 1 ? destValue : (destValue - srcValue) * weight + srcValue;
3258
+ };
3259
+ _proto._applyValue = function _applyValue(value) {
3260
+ this._target.entity.transform.setScale(value, value, value);
3261
+ };
3262
+ return ScaleTransition;
3263
+ }(Transition);
3264
+
3265
+ /**
3266
+ * Sprite transition.
3267
+ */ var SpriteTransition = /*#__PURE__*/ function(Transition) {
3268
+ _inherits(SpriteTransition, Transition);
3269
+ function SpriteTransition() {
3270
+ return Transition.apply(this, arguments) || this;
3271
+ }
3272
+ var _proto = SpriteTransition.prototype;
3273
+ _proto._getTargetValueCopy = function _getTargetValueCopy() {
3274
+ var _this__target;
3275
+ return (_this__target = this._target) == null ? void 0 : _this__target.sprite;
3276
+ };
3277
+ _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3278
+ this._currentValue = weight >= 1 ? destValue : srcValue;
3279
+ };
3280
+ _proto._applyValue = function _applyValue(value) {
3281
+ this._target.sprite = value;
3282
+ };
3283
+ return SpriteTransition;
3284
+ }(Transition);
3285
+
3286
+ var GUIComponent = /*#__PURE__*/Object.freeze({
3287
+ __proto__: null,
3288
+ get UICanvas () { return exports.UICanvas; },
3289
+ UIGroup: UIGroup,
3290
+ get UIRenderer () { return exports.UIRenderer; },
3291
+ UITransform: UITransform,
3292
+ Button: Button,
3293
+ Image: Image,
3294
+ Text: Text,
3295
+ ColorTransition: ColorTransition,
3296
+ ScaleTransition: ScaleTransition,
3297
+ SpriteTransition: SpriteTransition,
3298
+ Transition: Transition
3299
+ });
3300
+
3301
+ /**
3302
+ * @internal
3303
+ */ var UIHitResult = function UIHitResult() {
3304
+ this.entity = null;
3305
+ this.distance = 0;
3306
+ this.point = new engine.Vector3();
3307
+ this.normal = new engine.Vector3();
3308
+ this.component = null;
3309
+ };
3310
+
3311
+ exports.UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
3312
+ _inherits(UIPointerEventEmitter, PointerEventEmitter1);
3313
+ function UIPointerEventEmitter() {
3314
+ var _this;
3315
+ _this = PointerEventEmitter1.apply(this, arguments) || this, _this._enteredPath = [], _this._pressedPath = [], _this._draggedPath = [];
3316
+ return _this;
3317
+ }
3318
+ var _proto = UIPointerEventEmitter.prototype;
3319
+ _proto._init = function _init() {
3320
+ this._hitResult = new UIHitResult();
3321
+ };
3322
+ _proto.processRaycast = function processRaycast(scenes, pointer) {
3323
+ var ray = engine.PointerEventEmitter._tempRay;
3324
+ var hitResult = this._hitResult;
3325
+ var position = pointer.position;
3326
+ var x = position.x, y = position.y;
3327
+ for(var i = scenes.length - 1; i >= 0; i--){
3328
+ var scene = scenes[i];
3329
+ if (!scene.isActive || scene.destroyed) continue;
3330
+ // @ts-ignore
3331
+ var componentsManager = scene._componentsManager;
3332
+ // Overlay Canvas
3333
+ var canvasElements = componentsManager._overlayCanvases;
3334
+ // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
3335
+ ray.origin.set(position.x, scene.engine.canvas.height - position.y, 1);
3336
+ ray.direction.set(0, 0, -1);
3337
+ for(var j = canvasElements.length - 1; j >= 0; j--){
3338
+ if (canvasElements.get(j)._raycast(ray, hitResult)) {
3339
+ this._updateRaycast(hitResult.component, pointer);
3340
+ return;
3341
+ }
3342
+ }
3343
+ var cameras = componentsManager._activeCameras;
3344
+ for(var j1 = cameras.length - 1; j1 >= 0; j1--){
3345
+ var camera = cameras.get(j1);
3346
+ if (camera.renderTarget) continue;
3347
+ var pixelViewport = camera.pixelViewport;
3348
+ if (x < pixelViewport.x || y < pixelViewport.y || x > pixelViewport.x + pixelViewport.width || y > pixelViewport.y + pixelViewport.height) {
3349
+ continue;
3350
+ }
3351
+ camera.screenPointToRay(pointer.position, ray);
3352
+ // Other canvases
3353
+ var isOrthographic = camera.isOrthographic;
3354
+ var _camera_entity_transform = camera.entity.transform, cameraPosition = _camera_entity_transform.worldPosition, cameraForward = _camera_entity_transform.worldForward;
3355
+ // Sort by rendering order
3356
+ canvasElements = componentsManager._canvases;
3357
+ for(var k = 0, n = canvasElements.length; k < n; k++){
3358
+ canvasElements.get(k)._updateSortDistance(isOrthographic, cameraPosition, cameraForward);
3359
+ }
3360
+ canvasElements.sort(function(a, b) {
3361
+ return a.sortOrder - b.sortOrder || a._sortDistance - b._sortDistance;
3362
+ });
3363
+ for(var k1 = 0, n1 = canvasElements.length; k1 < n1; k1++){
3364
+ canvasElements.get(k1)._canvasIndex = k1;
3365
+ }
3366
+ var farClipPlane = camera.farClipPlane;
3367
+ // Post-rendering first detection
3368
+ for(var k2 = 0, n2 = canvasElements.length; k2 < n2; k2++){
3369
+ var canvas = canvasElements.get(k2);
3370
+ if (!canvas._canDispatchEvent(camera)) continue;
3371
+ if (canvas._raycast(ray, hitResult, farClipPlane)) {
3372
+ this._updateRaycast(hitResult.component, pointer);
3373
+ return;
3374
+ }
3375
+ }
3376
+ if (camera.clearFlags & engine.CameraClearFlags.Color) {
3377
+ this._updateRaycast(null);
3378
+ return;
3379
+ }
3380
+ }
3381
+ this._updateRaycast(null);
3382
+ }
3383
+ };
3384
+ _proto.processDrag = function processDrag(pointer) {
3385
+ var draggedPath = this._draggedPath;
3386
+ if (draggedPath.length > 0) {
3387
+ this._bubble(draggedPath, pointer, this._fireDrag);
3388
+ }
3389
+ };
3390
+ _proto.processDown = function processDown(pointer) {
3391
+ var enteredPath = this._enteredPath;
3392
+ var pressedPath = this._pressedPath;
3393
+ var draggedPath = this._draggedPath;
3394
+ var length = draggedPath.length = pressedPath.length = enteredPath.length;
3395
+ if (length > 0) {
3396
+ for(var i = 0; i < length; i++){
3397
+ pressedPath[i] = draggedPath[i] = enteredPath[i];
3398
+ }
3399
+ this._bubble(pressedPath, pointer, this._fireDown);
3400
+ this._bubble(draggedPath, pointer, this._fireBeginDrag);
3401
+ }
3402
+ };
3403
+ _proto.processUp = function processUp(pointer) {
3404
+ var enteredPath = this._enteredPath;
3405
+ var pressedPath = this._pressedPath;
3406
+ if (enteredPath.length > 0) {
3407
+ this._bubble(enteredPath, pointer, this._fireUp);
3408
+ if (pressedPath.length > 0) {
3409
+ var common = UIPointerEventEmitter._tempArray0;
3410
+ if (this._findCommonInPath(enteredPath, pressedPath, common)) {
3411
+ var eventData = this._createEventData(pointer);
3412
+ for(var i = 0, n = common.length; i < n; i++){
3413
+ this._fireClick(common[i], eventData);
3414
+ }
3415
+ common.length = 0;
3416
+ }
3417
+ }
3418
+ }
3419
+ pressedPath.length = 0;
3420
+ var draggedPath = this._draggedPath;
3421
+ if (draggedPath.length > 0) {
3422
+ this._bubble(draggedPath, pointer, this._fireEndDrag);
3423
+ draggedPath.length = 0;
3424
+ }
3425
+ if (enteredPath.length > 0) {
3426
+ this._bubble(enteredPath, pointer, this._fireDrop);
3427
+ }
3428
+ };
3429
+ _proto.processLeave = function processLeave(pointer) {
3430
+ var enteredPath = this._enteredPath;
3431
+ if (enteredPath.length > 0) {
3432
+ this._bubble(enteredPath, pointer, this._fireExit);
3433
+ enteredPath.length = 0;
3434
+ }
3435
+ var draggedPath = this._draggedPath;
3436
+ if (draggedPath.length > 0) {
3437
+ this._bubble(draggedPath, pointer, this._fireEndDrag);
3438
+ draggedPath.length = 0;
3439
+ }
3440
+ this._pressedPath.length = 0;
3441
+ };
3442
+ _proto.dispose = function dispose() {
3443
+ this._enteredPath.length = this._pressedPath.length = this._draggedPath.length = 0;
3444
+ };
3445
+ _proto._updateRaycast = function _updateRaycast(element, pointer) {
3446
+ if (pointer === void 0) pointer = null;
3447
+ var enteredPath = this._enteredPath;
3448
+ var curPath = this._composedPath(element, UIPointerEventEmitter._path);
3449
+ var add = UIPointerEventEmitter._tempArray0;
3450
+ var del = UIPointerEventEmitter._tempArray1;
3451
+ if (this._findDiffInPath(enteredPath, curPath, add, del)) {
3452
+ var eventData = this._createEventData(pointer);
3453
+ for(var i = 0, n = add.length; i < n; i++){
3454
+ this._fireEnter(add[i], eventData);
3455
+ }
3456
+ for(var i1 = 0, n1 = del.length; i1 < n1; i1++){
3457
+ this._fireExit(del[i1], eventData);
3458
+ }
3459
+ var length = enteredPath.length = curPath.length;
3460
+ for(var i2 = 0; i2 < length; i2++){
3461
+ enteredPath[i2] = curPath[i2];
3462
+ }
3463
+ add.length = del.length = 0;
3464
+ }
3465
+ curPath.length = 0;
3466
+ };
3467
+ _proto._composedPath = function _composedPath(element, path) {
3468
+ if (!element) {
3469
+ path.length = 0;
3470
+ return path;
3471
+ }
3472
+ var entity = path[0] = element.entity;
3473
+ var i = 1;
3474
+ var rootEntity = element._getRootCanvas().entity;
3475
+ for(; i < UIPointerEventEmitter._MAX_PATH_DEPTH && !!entity && entity !== rootEntity; i++){
3476
+ entity = path[i] = entity.parent;
3477
+ }
3478
+ path.length = i;
3479
+ return path;
3480
+ };
3481
+ _proto._findCommonInPath = function _findCommonInPath(prePath, curPath, common) {
3482
+ var idSet = UIPointerEventEmitter._tempSet;
3483
+ idSet.clear();
3484
+ for(var i = 0, n = prePath.length; i < n; i++){
3485
+ idSet.add(prePath[i].instanceId);
3486
+ }
3487
+ var hasCommon = false;
3488
+ for(var i1 = 0, n1 = curPath.length; i1 < n1; i1++){
3489
+ var entity = curPath[i1];
3490
+ if (idSet.has(entity.instanceId)) {
3491
+ common.push(entity);
3492
+ hasCommon = true;
3493
+ }
3494
+ }
3495
+ return hasCommon;
3496
+ };
3497
+ _proto._findDiffInPath = function _findDiffInPath(prePath, curPath, add, del) {
3498
+ var idSet = UIPointerEventEmitter._tempSet;
3499
+ idSet.clear();
3500
+ var changed = false;
3501
+ for(var i = 0, n = prePath.length; i < n; i++){
3502
+ idSet.add(prePath[i].instanceId);
3503
+ }
3504
+ for(var i1 = 0, n1 = curPath.length; i1 < n1; i1++){
3505
+ var entity = curPath[i1];
3506
+ if (!idSet.has(entity.instanceId)) {
3507
+ add.push(entity);
3508
+ changed = true;
3509
+ }
3510
+ }
3511
+ idSet.clear();
3512
+ for(var i2 = 0, n2 = curPath.length; i2 < n2; i2++){
3513
+ idSet.add(curPath[i2].instanceId);
3514
+ }
3515
+ for(var i3 = 0, n3 = prePath.length; i3 < n3; i3++){
3516
+ var entity1 = prePath[i3];
3517
+ if (!idSet.has(entity1.instanceId)) {
3518
+ del.push(entity1);
3519
+ changed = true;
3520
+ }
3521
+ }
3522
+ return changed;
3523
+ };
3524
+ _proto._bubble = function _bubble(path, pointer, fireEvent) {
3525
+ var length = path.length;
3526
+ if (length <= 0) return;
3527
+ var eventData = this._createEventData(pointer);
3528
+ for(var i = 0; i < length; i++){
3529
+ fireEvent(path[i], eventData);
3530
+ }
3531
+ };
3532
+ return UIPointerEventEmitter;
3533
+ }(engine.PointerEventEmitter);
3534
+ exports.UIPointerEventEmitter._MAX_PATH_DEPTH = 2048;
3535
+ exports.UIPointerEventEmitter._tempSet = new Set();
3536
+ exports.UIPointerEventEmitter._path = [];
3537
+ exports.UIPointerEventEmitter._tempArray0 = [];
3538
+ exports.UIPointerEventEmitter._tempArray1 = [];
3539
+ exports.UIPointerEventEmitter = __decorate([
3540
+ engine.registerPointerEventEmitter()
3541
+ ], exports.UIPointerEventEmitter);
3542
+
3543
+ var EngineExtension = /*#__PURE__*/ function() {
3544
+ function EngineExtension() {}
3545
+ var _proto = EngineExtension.prototype;
3546
+ _proto._getUIDefaultMaterial = function _getUIDefaultMaterial() {
3547
+ if (!this._uiDefaultMaterial) {
3548
+ var shader = _getOrCreateUIShader();
3549
+ // @ts-ignore
3550
+ var material = new engine.Material(this, shader);
3551
+ material.isGCIgnored = true;
3552
+ this._uiDefaultMaterial = material;
3553
+ }
3554
+ return this._uiDefaultMaterial;
3555
+ };
3556
+ return EngineExtension;
3557
+ }();
3558
+ var EntityExtension = /*#__PURE__*/ function() {
3559
+ function EntityExtension() {
3560
+ this._uiHierarchyVersion = 0;
3561
+ }
3562
+ var _proto = EntityExtension.prototype;
3563
+ _proto._updateUIHierarchyVersion = function _updateUIHierarchyVersion(version) {
3564
+ if (this._uiHierarchyVersion !== version) {
3565
+ var // @ts-ignore
3566
+ _this_parent;
3567
+ this._uiHierarchyVersion = version;
3568
+ (_this_parent = this.parent) == null ? void 0 : _this_parent._updateUIHierarchyVersion(version);
3569
+ }
3570
+ };
3571
+ return EntityExtension;
3572
+ }();
3573
+ function ApplyMixins(derivedCtor, baseCtors) {
3574
+ baseCtors.forEach(function(baseCtor) {
3575
+ Object.getOwnPropertyNames(baseCtor.prototype).forEach(function(name) {
3576
+ Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
3577
+ });
3578
+ });
3579
+ }
3580
+ ApplyMixins(engine.Engine, [
3581
+ EngineExtension
3582
+ ]);
3583
+ ApplyMixins(engine.Entity, [
3584
+ EntityExtension
3585
+ ]);
3586
+ /**
3587
+ * Register GUI components for the editor.
3588
+ */ function registerGUI() {
3589
+ for(var key in GUIComponent){
3590
+ engine.Loader.registerClass(key, GUIComponent[key]);
3591
+ }
3592
+ _getOrCreateUIShader();
3593
+ }
3594
+ function _getOrCreateUIShader() {
3595
+ return engine.Shader.find("2D/UIDefault");
3596
+ }
3597
+
3598
+ exports.Button = Button;
3599
+ exports.CanvasRenderMode = CanvasRenderMode;
3600
+ exports.ColorTransition = ColorTransition;
3601
+ exports.EngineExtension = EngineExtension;
3602
+ exports.EntityExtension = EntityExtension;
3603
+ exports.HorizontalAlignmentMode = HorizontalAlignmentMode;
3604
+ exports.Image = Image;
3605
+ exports.ResolutionAdaptationMode = ResolutionAdaptationMode;
3606
+ exports.ScaleTransition = ScaleTransition;
3607
+ exports.SpriteTransition = SpriteTransition;
3608
+ exports.Text = Text;
3609
+ exports.Transition = Transition;
3610
+ exports.UIGroup = UIGroup;
3611
+ exports.UITransform = UITransform;
3612
+ exports.VerticalAlignmentMode = VerticalAlignmentMode;
3613
+ exports.registerGUI = registerGUI;
3614
+
3615
+ Object.defineProperty(exports, '__esModule', { value: true });
3616
+
3617
+ }));
3618
+ //# sourceMappingURL=browser.js.map