@galacean/engine-ui 1.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js ADDED
@@ -0,0 +1,3077 @@
1
+ import { EntityModifyFlags, ignoreClone, assignmentClone, DisorderedArray, Component, deepClone, Vector2, Transform, Vector3, Matrix, Plane, ShaderProperty, dependentComponents, DependentMode, BatchUtils, ShaderMacroCollection, Renderer, Vector4, Color, RendererUpdateFlags, Script, MathUtil, CameraModifyFlags, SafeLoopArray, SpriteDrawMode, RenderQueueFlags, SpriteModifyFlags, SpriteTileMode, TiledSpriteAssembler, SlicedSpriteAssembler, SimpleSpriteAssembler, BoundingBox, ShaderData, ShaderDataGroup, TextUtils, Engine, TextVerticalAlignment, TextHorizontalAlignment, OverflowMode, CharRenderInfo, FontStyle, ReferResource, registerPointerEventEmitter, PointerEventEmitter, CameraClearFlags, ReflectionParser, Shader, ShaderPass, PipelineStage, Material, BlendFactor, BlendOperation, CullMode, RenderQueueType, Entity } from '@galacean/engine';
2
+
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
4
+ try {
5
+ var info = gen[key](arg);
6
+ var value = info.value;
7
+ } catch (error) {
8
+ reject(error);
9
+ return;
10
+ }
11
+ if (info.done) resolve(value);
12
+ else Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ function _async_to_generator(fn) {
15
+ return function() {
16
+ var self = this, args = arguments;
17
+
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+
21
+ function _next(value) {
22
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
+ }
24
+
25
+ function _throw(err) {
26
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
27
+ }
28
+
29
+ _next(undefined);
30
+ });
31
+ };
32
+ }
33
+
34
+ /******************************************************************************
35
+ Copyright (c) Microsoft Corporation.
36
+
37
+ Permission to use, copy, modify, and/or distribute this software for any
38
+ purpose with or without fee is hereby granted.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
41
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
42
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
43
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
44
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
45
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
46
+ PERFORMANCE OF THIS SOFTWARE.
47
+ ***************************************************************************** */
48
+
49
+ function __decorate(decorators, target, key, desc) {
50
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
51
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
52
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
53
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
54
+ }
55
+
56
+ function __generator(thisArg, body) {
57
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
58
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
59
+ function verb(n) { return function (v) { return step([n, v]); }; }
60
+ function step(op) {
61
+ if (f) throw new TypeError("Generator is already executing.");
62
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
63
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
+ if (y = 0, t) op = [op[0] & 2, t.value];
65
+ switch (op[0]) {
66
+ case 0: case 1: t = op; break;
67
+ case 4: _.label++; return { value: op[1], done: false };
68
+ case 5: _.label++; y = op[1]; op = [0]; continue;
69
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
70
+ default:
71
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
72
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
73
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
74
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
75
+ if (t[2]) _.ops.pop();
76
+ _.trys.pop(); continue;
77
+ }
78
+ op = body.call(thisArg, _);
79
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
80
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
81
+ }
82
+ }
83
+
84
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
85
+ var e = new Error(message);
86
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
87
+ };
88
+
89
+ var uiDefaultFs = "#define GLSLIFY 1\nuniform sampler2D renderer_UITexture;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main() {\n vec4 baseColor = texture2D(renderer_UITexture, v_uv);\n gl_FragColor = baseColor * v_color;\n}\n"; // eslint-disable-line
90
+
91
+ var uiDefaultVs = "#define GLSLIFY 1\nuniform mat4 renderer_MVPMat;\n\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\nattribute vec4 COLOR_0;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main() {\n gl_Position = renderer_MVPMat * vec4(POSITION, 1.0);\n\n v_uv = TEXCOORD_0;\n v_color = COLOR_0;\n}\n"; // eslint-disable-line
92
+
93
+ function _defineProperties(target, props) {
94
+ for (var i = 0; i < props.length; i++) {
95
+ var descriptor = props[i];
96
+ descriptor.enumerable = descriptor.enumerable || false;
97
+ descriptor.configurable = true;
98
+
99
+ if ("value" in descriptor) descriptor.writable = true;
100
+
101
+ Object.defineProperty(target, descriptor.key, descriptor);
102
+ }
103
+ }
104
+ function _create_class(Constructor, protoProps, staticProps) {
105
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
106
+ if (staticProps) _defineProperties(Constructor, staticProps);
107
+
108
+ return Constructor;
109
+ }
110
+
111
+ function _set_prototype_of(o, p) {
112
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
113
+ o.__proto__ = p;
114
+
115
+ return o;
116
+ };
117
+
118
+ return _set_prototype_of(o, p);
119
+ }
120
+
121
+ function _inherits(subClass, superClass) {
122
+ if (typeof superClass !== "function" && superClass !== null) {
123
+ throw new TypeError("Super expression must either be null or a function");
124
+ }
125
+
126
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
127
+
128
+ if (superClass) _set_prototype_of(subClass, superClass);
129
+ }
130
+
131
+ function _instanceof(left, right) {
132
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
133
+ return !!right[Symbol.hasInstance](left);
134
+ } else return left instanceof right;
135
+ }
136
+
137
+ var UIGroup = /*#__PURE__*/ function(Component) {
138
+ _inherits(UIGroup, Component);
139
+ function UIGroup(entity) {
140
+ var _this;
141
+ _this = Component.call(this, entity) || this, /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._disorderedElements = new DisorderedArray(), /** @internal */ _this._globalAlpha = 1, /** @internal */ _this._globalInteractive = true, _this._alpha = 1, _this._interactive = true, _this._ignoreParentGroup = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._isRootCanvasDirty = true, /** @internal */ _this._isGroupDirty = true, /** @internal */ _this._groupDirtyFlags = 0;
142
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
143
+ _this._groupListener = _this._groupListener.bind(_this);
144
+ return _this;
145
+ }
146
+ var _proto = UIGroup.prototype;
147
+ /**
148
+ * @internal
149
+ */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
150
+ if (this._isContainDirtyFlag(1)) {
151
+ if (this._ignoreParentGroup) {
152
+ this._globalAlpha = this._alpha;
153
+ } else {
154
+ var parentGroup = this._getGroup();
155
+ this._globalAlpha = this._alpha * (parentGroup ? parentGroup._getGlobalAlpha() : 1);
156
+ }
157
+ this._setDirtyFlagFalse(1);
158
+ }
159
+ return this._globalAlpha;
160
+ };
161
+ /**
162
+ * @internal
163
+ */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
164
+ if (this._isContainDirtyFlag(2)) {
165
+ if (this._ignoreParentGroup) {
166
+ this._globalInteractive = this._interactive;
167
+ } else {
168
+ var parentGroup = this._getGroup();
169
+ this._globalInteractive = this._interactive && (!parentGroup || parentGroup._getGlobalInteractive());
170
+ }
171
+ this._setDirtyFlagFalse(2);
172
+ }
173
+ return this._globalInteractive;
174
+ };
175
+ // @ts-ignore
176
+ _proto._onEnableInScene = function _onEnableInScene() {
177
+ Utils.setRootCanvasDirty(this);
178
+ Utils.setGroupDirty(this);
179
+ // @ts-ignore
180
+ this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
181
+ };
182
+ // @ts-ignore
183
+ _proto._onDisableInScene = function _onDisableInScene() {
184
+ Utils.cleanRootCanvas(this);
185
+ Utils.cleanGroup(this);
186
+ var disorderedElements = this._disorderedElements;
187
+ disorderedElements.forEach(function(element) {
188
+ Utils.setGroupDirty(element);
189
+ });
190
+ disorderedElements.length = 0;
191
+ disorderedElements.garbageCollection();
192
+ this._isRootCanvasDirty = this._isGroupDirty = false;
193
+ };
194
+ /**
195
+ * @internal
196
+ */ _proto._getRootCanvas = function _getRootCanvas() {
197
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
198
+ return this._rootCanvas;
199
+ };
200
+ /**
201
+ * @internal
202
+ */ _proto._getGroup = function _getGroup() {
203
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
204
+ return this._group;
205
+ };
206
+ /**
207
+ * @internal
208
+ */ _proto._groupListener = function _groupListener(flag) {
209
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
210
+ Utils.setGroupDirty(this);
211
+ }
212
+ };
213
+ /**
214
+ * @internal
215
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
216
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
217
+ Utils.setRootCanvasDirty(this);
218
+ Utils.setGroupDirty(this);
219
+ }
220
+ };
221
+ /**
222
+ * @internal
223
+ */ _proto._onGroupModify = function _onGroupModify(flags, isPass) {
224
+ if (isPass === void 0) isPass = false;
225
+ if (isPass && this._ignoreParentGroup) return;
226
+ if (this._isContainDirtyFlags(flags)) return;
227
+ this._setDirtyFlagTrue(flags);
228
+ this._disorderedElements.forEach(function(element) {
229
+ element._onGroupModify(flags, true);
230
+ });
231
+ };
232
+ _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
233
+ return (this._groupDirtyFlags & targetDirtyFlags) === targetDirtyFlags;
234
+ };
235
+ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
236
+ return (this._groupDirtyFlags & type) != 0;
237
+ };
238
+ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
239
+ this._groupDirtyFlags |= type;
240
+ };
241
+ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
242
+ this._groupDirtyFlags &= ~type;
243
+ };
244
+ _create_class(UIGroup, [
245
+ {
246
+ key: "ignoreParentGroup",
247
+ get: /**
248
+ * Whether to ignore the parent group.
249
+ * @remarks If this parameter set to `true`,
250
+ * all settings of the parent group will be ignored.
251
+ */ function get() {
252
+ return this._ignoreParentGroup;
253
+ },
254
+ set: function set(value) {
255
+ if (this._ignoreParentGroup !== value) {
256
+ this._ignoreParentGroup = value;
257
+ this._onGroupModify(3);
258
+ }
259
+ }
260
+ },
261
+ {
262
+ key: "interactive",
263
+ get: /**
264
+ * Whether the group is interactive.
265
+ */ function get() {
266
+ return this._interactive;
267
+ },
268
+ set: function set(value) {
269
+ if (this._interactive !== value) {
270
+ this._interactive = value;
271
+ this._onGroupModify(2);
272
+ }
273
+ }
274
+ },
275
+ {
276
+ key: "alpha",
277
+ get: /**
278
+ * The alpha value of the group.
279
+ */ function get() {
280
+ return this._alpha;
281
+ },
282
+ set: function set(value) {
283
+ value = Math.max(0, Math.min(value, 1));
284
+ if (this._alpha !== value) {
285
+ this._alpha = value;
286
+ this._onGroupModify(1);
287
+ }
288
+ }
289
+ }
290
+ ]);
291
+ return UIGroup;
292
+ }(Component);
293
+ __decorate([
294
+ ignoreClone
295
+ ], UIGroup.prototype, "_indexInGroup", void 0);
296
+ __decorate([
297
+ ignoreClone
298
+ ], UIGroup.prototype, "_indexInRootCanvas", void 0);
299
+ __decorate([
300
+ ignoreClone
301
+ ], UIGroup.prototype, "_group", void 0);
302
+ __decorate([
303
+ ignoreClone
304
+ ], UIGroup.prototype, "_rootCanvas", void 0);
305
+ __decorate([
306
+ ignoreClone
307
+ ], UIGroup.prototype, "_disorderedElements", void 0);
308
+ __decorate([
309
+ ignoreClone
310
+ ], UIGroup.prototype, "_globalAlpha", void 0);
311
+ __decorate([
312
+ assignmentClone
313
+ ], UIGroup.prototype, "_alpha", void 0);
314
+ __decorate([
315
+ assignmentClone
316
+ ], UIGroup.prototype, "_interactive", void 0);
317
+ __decorate([
318
+ assignmentClone
319
+ ], UIGroup.prototype, "_ignoreParentGroup", void 0);
320
+ __decorate([
321
+ ignoreClone
322
+ ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
323
+ __decorate([
324
+ ignoreClone
325
+ ], UIGroup.prototype, "_groupListeningEntities", void 0);
326
+ __decorate([
327
+ ignoreClone
328
+ ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
329
+ __decorate([
330
+ ignoreClone
331
+ ], UIGroup.prototype, "_isGroupDirty", void 0);
332
+ __decorate([
333
+ ignoreClone
334
+ ], UIGroup.prototype, "_groupDirtyFlags", void 0);
335
+ __decorate([
336
+ ignoreClone
337
+ ], UIGroup.prototype, "_groupListener", null);
338
+ __decorate([
339
+ ignoreClone
340
+ ], UIGroup.prototype, "_rootCanvasListener", null);
341
+ var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
342
+ GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
343
+ GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
344
+ GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
345
+ GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
346
+ return GroupModifyFlags;
347
+ }({});
348
+
349
+ var Utils = /*#__PURE__*/ function() {
350
+ function Utils() {}
351
+ Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
352
+ if (element._isRootCanvasDirty) return;
353
+ element._isRootCanvasDirty = true;
354
+ this._registerRootCanvas(element, null);
355
+ element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
356
+ };
357
+ Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
358
+ element._isRootCanvasDirty = false;
359
+ this._registerRootCanvas(element, rootCanvas);
360
+ var fromEntity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
361
+ var _rootCanvas_entity_parent;
362
+ var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
363
+ this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
364
+ };
365
+ Utils.cleanRootCanvas = function cleanRootCanvas(element) {
366
+ this._registerRootCanvas(element, null);
367
+ this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
368
+ };
369
+ Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
370
+ var entity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
371
+ while(entity){
372
+ // @ts-ignore
373
+ var components = entity._components;
374
+ for(var i = 0, n = components.length; i < n; i++){
375
+ var component = components[i];
376
+ if (component.enabled && _instanceof(component, UICanvas) && component._isRootCanvas) {
377
+ return component;
378
+ }
379
+ }
380
+ entity = entity.parent;
381
+ }
382
+ return null;
383
+ };
384
+ Utils.setGroupDirty = function setGroupDirty(element) {
385
+ if (element._isGroupDirty) return;
386
+ element._isGroupDirty = true;
387
+ this._registerGroup(element, null);
388
+ element._onGroupModify(GroupModifyFlags.All);
389
+ };
390
+ Utils.setGroup = function setGroup(element, group) {
391
+ element._isGroupDirty = false;
392
+ this._registerGroup(element, group);
393
+ var rootCanvas = element._getRootCanvas();
394
+ if (rootCanvas) {
395
+ var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
396
+ var _group_entity;
397
+ var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
398
+ this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
399
+ } else {
400
+ this._unRegisterListener(element._groupListener, element._groupListeningEntities);
401
+ }
402
+ };
403
+ Utils.cleanGroup = function cleanGroup(element) {
404
+ this._registerGroup(element, null);
405
+ this._unRegisterListener(element._groupListener, element._groupListeningEntities);
406
+ };
407
+ Utils.searchGroupInParents = function searchGroupInParents(element) {
408
+ var rootCanvas = element._getRootCanvas();
409
+ if (!rootCanvas) return null;
410
+ var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
411
+ var rootCanvasParent = rootCanvas.entity.parent;
412
+ while(entity && entity !== rootCanvasParent){
413
+ // @ts-ignore
414
+ var components = entity._components;
415
+ for(var i = 0, n = components.length; i < n; i++){
416
+ var component = components[i];
417
+ if (component.enabled && _instanceof(component, UIGroup)) {
418
+ return component;
419
+ }
420
+ }
421
+ entity = entity.parent;
422
+ }
423
+ return null;
424
+ };
425
+ Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
426
+ var preCanvas = element._rootCanvas;
427
+ if (preCanvas !== canvas) {
428
+ if (preCanvas) {
429
+ var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
430
+ replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
431
+ element._indexInRootCanvas = -1;
432
+ }
433
+ if (canvas) {
434
+ var disorderedElements = canvas._disorderedElements;
435
+ element._indexInRootCanvas = disorderedElements.length;
436
+ disorderedElements.add(element);
437
+ }
438
+ element._rootCanvas = canvas;
439
+ }
440
+ };
441
+ Utils._registerGroup = function _registerGroup(element, group) {
442
+ var preGroup = element._group;
443
+ if (preGroup !== group) {
444
+ if (preGroup) {
445
+ var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
446
+ replaced && (replaced._indexInGroup = element._indexInGroup);
447
+ element._indexInGroup = -1;
448
+ }
449
+ if (group) {
450
+ var disorderedElements = group._disorderedElements;
451
+ element._indexInGroup = disorderedElements.length;
452
+ disorderedElements.add(element);
453
+ }
454
+ element._group = group;
455
+ element._onGroupModify(GroupModifyFlags.All);
456
+ }
457
+ };
458
+ Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
459
+ var count = 0;
460
+ while(entity && entity !== root){
461
+ var preEntity = listeningEntities[count];
462
+ if (preEntity !== entity) {
463
+ // @ts-ignore
464
+ preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
465
+ listeningEntities[count] = entity;
466
+ // @ts-ignore
467
+ entity._registerModifyListener(listener);
468
+ }
469
+ entity = entity.parent;
470
+ count++;
471
+ }
472
+ listeningEntities.length = count;
473
+ };
474
+ Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
475
+ for(var i = 0, n = listeningEntities.length; i < n; i++){
476
+ // @ts-ignore
477
+ listeningEntities[i]._unRegisterModifyListener(listener);
478
+ }
479
+ listeningEntities.length = 0;
480
+ };
481
+ return Utils;
482
+ }();
483
+
484
+ /**
485
+ * Render mode for ui canvas.
486
+ */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
487
+ /**
488
+ * The UI canvas will be rendered directly onto the screen and adapted to screen space,
489
+ * overlaying other rendering elements in the same scene.
490
+ * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
491
+ */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
492
+ /**
493
+ * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
494
+ * with all objects rendered by the camera.
495
+ * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
496
+ * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
497
+ */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
498
+ /**
499
+ * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
500
+ */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
501
+ return CanvasRenderMode;
502
+ }({});
503
+
504
+ /**
505
+ * Resolution adaptation mode.
506
+ * @remarks Only effective in screen space.
507
+ */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
508
+ /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
509
+ /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
510
+ /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
511
+ /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
512
+ /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
513
+ return ResolutionAdaptationMode;
514
+ }({});
515
+
516
+ /**
517
+ * The Transform component exclusive to the UI element.
518
+ */ var UITransform = /*#__PURE__*/ function(Transform) {
519
+ _inherits(UITransform, Transform);
520
+ function UITransform(entity) {
521
+ var _this;
522
+ _this = Transform.call(this, entity) || this, _this._size = new Vector2(100, 100), _this._pivot = new Vector2(0.5, 0.5);
523
+ // @ts-ignore
524
+ _this._size._onValueChanged = _this._onSizeChange.bind(_this);
525
+ // @ts-ignore
526
+ _this._pivot._onValueChanged = _this._onPivotChange.bind(_this);
527
+ return _this;
528
+ }
529
+ var _proto = UITransform.prototype;
530
+ _proto._onSizeChange = function _onSizeChange() {
531
+ // @ts-ignore
532
+ this._entity._updateFlagManager.dispatch(512);
533
+ };
534
+ _proto._onPivotChange = function _onPivotChange() {
535
+ // @ts-ignore
536
+ this._entity._updateFlagManager.dispatch(1024);
537
+ };
538
+ _create_class(UITransform, [
539
+ {
540
+ key: "size",
541
+ get: /**
542
+ * Width and height of UI element.
543
+ */ function get() {
544
+ return this._size;
545
+ },
546
+ set: function set(value) {
547
+ var _this = this, size = _this._size;
548
+ if (size === value) return;
549
+ (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
550
+ }
551
+ },
552
+ {
553
+ key: "pivot",
554
+ get: /**
555
+ * Pivot of UI element.
556
+ */ function get() {
557
+ return this._pivot;
558
+ },
559
+ set: function set(value) {
560
+ var _this = this, pivot = _this._pivot;
561
+ if (pivot === value) return;
562
+ (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
563
+ }
564
+ }
565
+ ]);
566
+ return UITransform;
567
+ }(Transform);
568
+ __decorate([
569
+ deepClone
570
+ ], UITransform.prototype, "_size", void 0);
571
+ __decorate([
572
+ deepClone
573
+ ], UITransform.prototype, "_pivot", void 0);
574
+ __decorate([
575
+ ignoreClone
576
+ ], UITransform.prototype, "_onSizeChange", null);
577
+ __decorate([
578
+ ignoreClone
579
+ ], UITransform.prototype, "_onPivotChange", null);
580
+ /**
581
+ * @internal
582
+ * extends TransformModifyFlags
583
+ */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
584
+ /** Size. */ UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
585
+ /** Pivot. */ UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
586
+ return UITransformModifyFlags;
587
+ }({});
588
+
589
+ var UIRenderer = /*#__PURE__*/ function(Renderer) {
590
+ _inherits(UIRenderer, Renderer);
591
+ function UIRenderer(entity) {
592
+ var _this;
593
+ _this = Renderer.call(this, entity) || this, /**
594
+ * Custom boundary for raycast detection.
595
+ * @remarks this is based on `this.entity.transform`.
596
+ */ _this.raycastPadding = new Vector4(0, 0, 0, 0), /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], _this._raycastEnabled = true, _this._color = new Color(1, 1, 1, 1);
597
+ _this._dirtyUpdateFlag = RendererUpdateFlags.WorldVolume | 2;
598
+ _this._onColorChanged = _this._onColorChanged.bind(_this);
599
+ //@ts-ignore
600
+ _this._color._onValueChanged = _this._onColorChanged;
601
+ _this._groupListener = _this._groupListener.bind(_this);
602
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
603
+ return _this;
604
+ }
605
+ var _proto = UIRenderer.prototype;
606
+ // @ts-ignore
607
+ _proto._canBatch = function _canBatch(elementA, elementB) {
608
+ return BatchUtils.canBatchSprite(elementA, elementB);
609
+ };
610
+ // @ts-ignore
611
+ _proto._batch = function _batch(elementA, elementB) {
612
+ BatchUtils.batchFor2D(elementA, elementB);
613
+ };
614
+ // @ts-ignore
615
+ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
616
+ // @ts-ignore
617
+ Renderer.prototype._updateTransformShaderData.call(this, context, onlyMVP, true);
618
+ };
619
+ // @ts-ignore
620
+ _proto._prepareRender = function _prepareRender(context) {
621
+ // Update once per frame per renderer, not influenced by batched
622
+ if (this._renderFrameCount !== this.engine.time.frameCount) {
623
+ this._update(context);
624
+ }
625
+ this._render(context);
626
+ // union camera global macro and renderer macro.
627
+ ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
628
+ this.shaderData._macroCollection, //@ts-ignore
629
+ this._globalShaderMacro);
630
+ };
631
+ // @ts-ignore
632
+ _proto._onEnableInScene = function _onEnableInScene() {
633
+ // @ts-ignore
634
+ this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
635
+ this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
636
+ Utils.setRootCanvasDirty(this);
637
+ Utils.setGroupDirty(this);
638
+ };
639
+ // @ts-ignore
640
+ _proto._onDisableInScene = function _onDisableInScene() {
641
+ // @ts-ignore
642
+ this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
643
+ this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
644
+ Utils.cleanRootCanvas(this);
645
+ Utils.cleanGroup(this);
646
+ };
647
+ /**
648
+ * @internal
649
+ */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
650
+ var _this__getGroup;
651
+ var _this__getGroup__getGlobalAlpha;
652
+ return (_this__getGroup__getGlobalAlpha = (_this__getGroup = this._getGroup()) == null ? void 0 : _this__getGroup._getGlobalAlpha()) != null ? _this__getGroup__getGlobalAlpha : 1;
653
+ };
654
+ /**
655
+ * @internal
656
+ */ _proto._getRootCanvas = function _getRootCanvas() {
657
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
658
+ return this._rootCanvas;
659
+ };
660
+ /**
661
+ * @internal
662
+ */ _proto._getGroup = function _getGroup() {
663
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
664
+ return this._group;
665
+ };
666
+ /**
667
+ * @internal
668
+ */ _proto._groupListener = function _groupListener(flag) {
669
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
670
+ Utils.setGroupDirty(this);
671
+ }
672
+ };
673
+ /**
674
+ * @internal
675
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag, entity) {
676
+ switch(flag){
677
+ case EntityModifyFlags.Parent:
678
+ Utils.setRootCanvasDirty(this);
679
+ Utils.setGroupDirty(this);
680
+ case EntityModifyFlags.Child:
681
+ entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
682
+ break;
683
+ }
684
+ };
685
+ /**
686
+ * @internal
687
+ */ _proto._onGroupModify = function _onGroupModify(flags) {
688
+ if (flags & GroupModifyFlags.GlobalAlpha) {
689
+ this._dirtyUpdateFlag |= 2;
690
+ }
691
+ };
692
+ _proto._onColorChanged = function _onColorChanged() {
693
+ this._dirtyUpdateFlag |= 2;
694
+ };
695
+ /**
696
+ * @internal
697
+ */ _proto._getChunkManager = function _getChunkManager() {
698
+ // @ts-ignore
699
+ return this.engine._batcherManager.primitiveChunkManagerUI;
700
+ };
701
+ /**
702
+ * @internal
703
+ */ _proto._raycast = function _raycast(ray, out, distance) {
704
+ if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
705
+ var plane = UIRenderer._tempPlane;
706
+ var transform = this._transformEntity.transform;
707
+ var normal = plane.normal.copyFrom(transform.worldForward);
708
+ plane.distance = -Vector3.dot(normal, transform.worldPosition);
709
+ var curDistance = ray.intersectPlane(plane);
710
+ if (curDistance >= 0 && curDistance < distance) {
711
+ var hitPointWorld = ray.getPoint(curDistance, UIRenderer._tempVec30);
712
+ var worldMatrixInv = UIRenderer._tempMat;
713
+ Matrix.invert(transform.worldMatrix, worldMatrixInv);
714
+ var localPosition = UIRenderer._tempVec31;
715
+ Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, localPosition);
716
+ if (this._hitTest(localPosition)) {
717
+ out.component = this;
718
+ out.distance = curDistance;
719
+ out.entity = this.entity;
720
+ out.normal.copyFrom(normal);
721
+ out.point.copyFrom(hitPointWorld);
722
+ return true;
723
+ }
724
+ }
725
+ return false;
726
+ };
727
+ _proto._hitTest = function _hitTest(localPosition) {
728
+ var x = localPosition.x, y = localPosition.y;
729
+ var uiTransform = this._transformEntity.transform;
730
+ var _uiTransform_size = uiTransform.size, width = _uiTransform_size.x, height = _uiTransform_size.y;
731
+ var _uiTransform_pivot = uiTransform.pivot, pivotX = _uiTransform_pivot.x, pivotY = _uiTransform_pivot.y;
732
+ var _this_raycastPadding = this.raycastPadding, paddingLeft = _this_raycastPadding.x, paddingBottom = _this_raycastPadding.y, paddingRight = _this_raycastPadding.z, paddingTop = _this_raycastPadding.w;
733
+ return x >= -width * pivotX + paddingLeft && x <= width * (1 - pivotX) - paddingRight && y >= -height * pivotY + paddingTop && y <= height * (1 - pivotY) - paddingBottom;
734
+ };
735
+ _proto._onDestroy = function _onDestroy() {
736
+ if (this._subChunk) {
737
+ this._getChunkManager().freeSubChunk(this._subChunk);
738
+ this._subChunk = null;
739
+ }
740
+ Renderer.prototype._onDestroy.call(this);
741
+ //@ts-ignore
742
+ this._color._onValueChanged = null;
743
+ this._color = null;
744
+ };
745
+ _create_class(UIRenderer, [
746
+ {
747
+ key: "color",
748
+ get: /**
749
+ * Rendering color for the ui renderer.
750
+ */ function get() {
751
+ return this._color;
752
+ },
753
+ set: function set(value) {
754
+ if (this._color !== value) {
755
+ this._color.copyFrom(value);
756
+ }
757
+ }
758
+ },
759
+ {
760
+ key: "raycastEnabled",
761
+ get: /**
762
+ * Whether this renderer be picked up by raycast.
763
+ */ function get() {
764
+ return this._raycastEnabled;
765
+ },
766
+ set: function set(value) {
767
+ this._raycastEnabled = value;
768
+ }
769
+ }
770
+ ]);
771
+ return UIRenderer;
772
+ }(Renderer);
773
+ /** @internal */ UIRenderer._tempVec30 = new Vector3();
774
+ /** @internal */ UIRenderer._tempVec31 = new Vector3();
775
+ /** @internal */ UIRenderer._tempMat = new Matrix();
776
+ /** @internal */ UIRenderer._tempPlane = new Plane();
777
+ /** @internal */ UIRenderer._textureProperty = ShaderProperty.getByName("renderer_UITexture");
778
+ __decorate([
779
+ deepClone
780
+ ], UIRenderer.prototype, "raycastPadding", void 0);
781
+ __decorate([
782
+ ignoreClone
783
+ ], UIRenderer.prototype, "_rootCanvas", void 0);
784
+ __decorate([
785
+ ignoreClone
786
+ ], UIRenderer.prototype, "_indexInRootCanvas", void 0);
787
+ __decorate([
788
+ ignoreClone
789
+ ], UIRenderer.prototype, "_isRootCanvasDirty", void 0);
790
+ __decorate([
791
+ ignoreClone
792
+ ], UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
793
+ __decorate([
794
+ ignoreClone
795
+ ], UIRenderer.prototype, "_group", void 0);
796
+ __decorate([
797
+ ignoreClone
798
+ ], UIRenderer.prototype, "_indexInGroup", void 0);
799
+ __decorate([
800
+ ignoreClone
801
+ ], UIRenderer.prototype, "_isGroupDirty", void 0);
802
+ __decorate([
803
+ ignoreClone
804
+ ], UIRenderer.prototype, "_groupListeningEntities", void 0);
805
+ __decorate([
806
+ ignoreClone
807
+ ], UIRenderer.prototype, "_subChunk", void 0);
808
+ __decorate([
809
+ ignoreClone
810
+ ], UIRenderer.prototype, "_raycastEnabled", void 0);
811
+ __decorate([
812
+ deepClone
813
+ ], UIRenderer.prototype, "_color", void 0);
814
+ __decorate([
815
+ ignoreClone
816
+ ], UIRenderer.prototype, "_groupListener", null);
817
+ __decorate([
818
+ ignoreClone
819
+ ], UIRenderer.prototype, "_rootCanvasListener", null);
820
+ __decorate([
821
+ ignoreClone
822
+ ], UIRenderer.prototype, "_onColorChanged", null);
823
+ UIRenderer = __decorate([
824
+ dependentComponents(UITransform, DependentMode.AutoAdd)
825
+ ], UIRenderer);
826
+ /**
827
+ * @remarks Extends `RendererUpdateFlags`.
828
+ */ var UIRendererUpdateFlags = /*#__PURE__*/ function(UIRendererUpdateFlags) {
829
+ UIRendererUpdateFlags[UIRendererUpdateFlags["Color"] = 2] = "Color";
830
+ return UIRendererUpdateFlags;
831
+ }({});
832
+
833
+ /**
834
+ * Interactive component.
835
+ */ var UIInteractive = /*#__PURE__*/ function(Script) {
836
+ _inherits(UIInteractive, Script);
837
+ function UIInteractive(entity) {
838
+ var _this;
839
+ _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._interactive = true, _this._state = 0, _this._transitions = [], /** @todo Multi-touch points are not considered yet. */ _this._isPointerInside = false, _this._isPointerDragging = false;
840
+ _this._groupListener = _this._groupListener.bind(_this);
841
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
842
+ return _this;
843
+ }
844
+ var _proto = UIInteractive.prototype;
845
+ /**
846
+ * Add transition on this interactive.
847
+ * @param transition - The transition
848
+ */ _proto.addTransition = function addTransition(transition) {
849
+ var interactive = transition._interactive;
850
+ if (interactive !== this) {
851
+ interactive == null ? void 0 : interactive.removeTransition(transition);
852
+ this._transitions.push(transition);
853
+ transition._interactive = this;
854
+ transition._setState(this._state, true);
855
+ }
856
+ };
857
+ /**
858
+ * Remove a transition.
859
+ * @param shape - The transition.
860
+ */ _proto.removeTransition = function removeTransition(transition) {
861
+ var transitions = this._transitions;
862
+ var lastOneIndex = transitions.length - 1;
863
+ for(var i = lastOneIndex; i >= 0; i--){
864
+ if (transitions[i] === transition) {
865
+ i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
866
+ transitions.length = lastOneIndex;
867
+ transition._interactive = null;
868
+ break;
869
+ }
870
+ }
871
+ };
872
+ /**
873
+ * Remove all transitions.
874
+ */ _proto.clearShapes = function clearShapes() {
875
+ var transitions = this._transitions;
876
+ for(var i = 0, n = transitions.length; i < n; i++){
877
+ transitions[i]._interactive = null;
878
+ }
879
+ transitions.length = 0;
880
+ };
881
+ _proto.onUpdate = function onUpdate(deltaTime) {
882
+ if (this._getGlobalInteractive()) {
883
+ var transitions = this._transitions;
884
+ for(var i = 0, n = transitions.length; i < n; i++){
885
+ transitions[i]._onUpdate(deltaTime);
886
+ }
887
+ }
888
+ };
889
+ _proto.onPointerBeginDrag = function onPointerBeginDrag() {
890
+ this._isPointerDragging = true;
891
+ this._updateState(false);
892
+ };
893
+ _proto.onPointerEndDrag = function onPointerEndDrag() {
894
+ this._isPointerDragging = false;
895
+ this._updateState(false);
896
+ };
897
+ _proto.onPointerEnter = function onPointerEnter() {
898
+ this._isPointerInside = true;
899
+ this._updateState(false);
900
+ };
901
+ _proto.onPointerExit = function onPointerExit() {
902
+ this._isPointerInside = false;
903
+ this._updateState(false);
904
+ };
905
+ _proto.onDestroy = function onDestroy() {
906
+ Script.prototype.onDestroy.call(this);
907
+ var transitions = this._transitions;
908
+ for(var i = 0, n = transitions.length; i < n; i++){
909
+ transitions[i].destroy();
910
+ }
911
+ };
912
+ /**
913
+ * @internal
914
+ */ _proto._getRootCanvas = function _getRootCanvas() {
915
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
916
+ return this._rootCanvas;
917
+ };
918
+ /**
919
+ * @internal
920
+ */ _proto._getGroup = function _getGroup() {
921
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
922
+ return this._group;
923
+ };
924
+ // @ts-ignore
925
+ _proto._onEnableInScene = function _onEnableInScene() {
926
+ // @ts-ignore
927
+ Script.prototype._onEnableInScene.call(this);
928
+ Utils.setRootCanvasDirty(this);
929
+ Utils.setGroupDirty(this);
930
+ this._updateState(true);
931
+ };
932
+ // @ts-ignore
933
+ _proto._onDisableInScene = function _onDisableInScene() {
934
+ // @ts-ignore
935
+ Script.prototype._onDisableInScene.call(this);
936
+ Utils.cleanRootCanvas(this);
937
+ Utils.cleanGroup(this);
938
+ this._isPointerInside = this._isPointerDragging = false;
939
+ };
940
+ /**
941
+ * @internal
942
+ */ _proto._groupListener = function _groupListener(flag) {
943
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
944
+ Utils.setGroupDirty(this);
945
+ }
946
+ };
947
+ /**
948
+ * @internal
949
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
950
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
951
+ Utils.setRootCanvasDirty(this);
952
+ Utils.setGroupDirty(this);
953
+ }
954
+ };
955
+ /**
956
+ * @internal
957
+ */ _proto._onGroupModify = function _onGroupModify(flags) {
958
+ if (flags & GroupModifyFlags.GlobalInteractive) {
959
+ this._globalInteractiveDirty = true;
960
+ }
961
+ };
962
+ /**
963
+ * @internal
964
+ */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
965
+ if (this._globalInteractiveDirty) {
966
+ var group = this._getGroup();
967
+ var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
968
+ if (this._globalInteractive !== globalInteractive) {
969
+ this._globalInteractive = globalInteractive;
970
+ this._updateState(true);
971
+ }
972
+ this._globalInteractiveDirty = false;
973
+ }
974
+ return this._globalInteractive;
975
+ };
976
+ _proto._updateState = function _updateState(instant) {
977
+ var state = this._getInteractiveState();
978
+ if (this._state !== state) {
979
+ this._state = state;
980
+ var transitions = this._transitions;
981
+ for(var i = 0, n = transitions.length; i < n; i++){
982
+ transitions[i]._setState(state, instant);
983
+ }
984
+ }
985
+ };
986
+ _proto._getInteractiveState = function _getInteractiveState() {
987
+ if (!this._getGlobalInteractive()) {
988
+ return 3;
989
+ }
990
+ if (this._isPointerDragging) {
991
+ return 1;
992
+ } else {
993
+ return this._isPointerInside ? 2 : 0;
994
+ }
995
+ };
996
+ _create_class(UIInteractive, [
997
+ {
998
+ key: "transitions",
999
+ get: /**
1000
+ * The transitions of this interactive.
1001
+ */ function get() {
1002
+ return this._transitions;
1003
+ }
1004
+ },
1005
+ {
1006
+ key: "interactive",
1007
+ get: /**
1008
+ * Whether the interactive is enabled.
1009
+ */ function get() {
1010
+ return this._interactive;
1011
+ },
1012
+ set: function set(value) {
1013
+ if (this._interactive !== value) {
1014
+ this._interactive = value;
1015
+ this._globalInteractiveDirty = true;
1016
+ }
1017
+ }
1018
+ }
1019
+ ]);
1020
+ return UIInteractive;
1021
+ }(Script);
1022
+ __decorate([
1023
+ ignoreClone
1024
+ ], UIInteractive.prototype, "_rootCanvas", void 0);
1025
+ __decorate([
1026
+ ignoreClone
1027
+ ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
1028
+ __decorate([
1029
+ ignoreClone
1030
+ ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
1031
+ __decorate([
1032
+ ignoreClone
1033
+ ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
1034
+ __decorate([
1035
+ ignoreClone
1036
+ ], UIInteractive.prototype, "_group", void 0);
1037
+ __decorate([
1038
+ ignoreClone
1039
+ ], UIInteractive.prototype, "_indexInGroup", void 0);
1040
+ __decorate([
1041
+ ignoreClone
1042
+ ], UIInteractive.prototype, "_isGroupDirty", void 0);
1043
+ __decorate([
1044
+ ignoreClone
1045
+ ], UIInteractive.prototype, "_groupListeningEntities", void 0);
1046
+ __decorate([
1047
+ ignoreClone
1048
+ ], UIInteractive.prototype, "_globalInteractive", void 0);
1049
+ __decorate([
1050
+ ignoreClone
1051
+ ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
1052
+ __decorate([
1053
+ ignoreClone
1054
+ ], UIInteractive.prototype, "_groupListener", null);
1055
+ __decorate([
1056
+ ignoreClone
1057
+ ], UIInteractive.prototype, "_rootCanvasListener", null);
1058
+ __decorate([
1059
+ ignoreClone
1060
+ ], UIInteractive.prototype, "_onGroupModify", null);
1061
+ var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
1062
+ InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
1063
+ InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
1064
+ InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
1065
+ InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
1066
+ return InteractiveState;
1067
+ }({});
1068
+
1069
+ var UICanvas = /*#__PURE__*/ function(Component) {
1070
+ _inherits(UICanvas, Component);
1071
+ function UICanvas(entity) {
1072
+ var _this;
1073
+ _this = Component.call(this, entity) || this, /** @internal */ _this._canvasIndex = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._isRootCanvas = false, /** @internal */ _this._sortDistance = 0, /** @internal */ _this._orderedRenderers = [], /** @internal */ _this._realRenderMode = 4, /** @internal */ _this._disorderedElements = new DisorderedArray(), _this._renderMode = CanvasRenderMode.WorldSpace, _this._resolutionAdaptationMode = ResolutionAdaptationMode.HeightAdaptation, _this._sortOrder = 0, _this._distance = 10, _this._referenceResolution = new Vector2(800, 600), _this._referenceResolutionPerUnit = 100, _this._hierarchyVersion = -1;
1074
+ _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1075
+ _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1076
+ _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1077
+ _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1078
+ // @ts-ignore
1079
+ _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1080
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1081
+ return _this;
1082
+ }
1083
+ var _proto = UICanvas.prototype;
1084
+ _proto.raycast = function raycast(ray, out, distance) {
1085
+ if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1086
+ var renderers = this._getRenderers();
1087
+ for(var i = renderers.length - 1; i >= 0; i--){
1088
+ var element = renderers[i];
1089
+ if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1090
+ return true;
1091
+ }
1092
+ }
1093
+ out.component = null;
1094
+ out.entity = null;
1095
+ out.distance = 0;
1096
+ out.point.set(0, 0, 0);
1097
+ out.normal.set(0, 0, 0);
1098
+ return false;
1099
+ };
1100
+ /**
1101
+ * @internal
1102
+ */ _proto._getRootCanvas = function _getRootCanvas() {
1103
+ return this._rootCanvas;
1104
+ };
1105
+ /**
1106
+ * @internal
1107
+ */ _proto._canRender = function _canRender(camera) {
1108
+ return this._renderMode !== CanvasRenderMode.ScreenSpaceCamera || this._renderCamera === camera;
1109
+ };
1110
+ /**
1111
+ * @internal
1112
+ */ _proto._prepareRender = function _prepareRender(context) {
1113
+ var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1114
+ var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1115
+ var frameCount = engine.time.frameCount;
1116
+ // @ts-ignore
1117
+ var renderElement = this._renderElement = engine._renderElementPool.get();
1118
+ this._updateSortDistance(context.virtualCamera.position);
1119
+ renderElement.set(this.sortOrder, this._sortDistance);
1120
+ var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1121
+ var renderers = this._getRenderers();
1122
+ for(var i = 0, n = renderers.length; i < n; i++){
1123
+ var renderer = renderers[i];
1124
+ // Filter by camera culling mask
1125
+ if (!(cullingMask & renderer.entity.layer)) {
1126
+ continue;
1127
+ }
1128
+ // Filter by camera frustum
1129
+ if (enableFrustumCulling) {
1130
+ switch(mode){
1131
+ case CanvasRenderMode.ScreenSpaceOverlay:
1132
+ var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1133
+ if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1134
+ continue;
1135
+ }
1136
+ break;
1137
+ case CanvasRenderMode.ScreenSpaceCamera:
1138
+ case CanvasRenderMode.WorldSpace:
1139
+ if (!frustum.intersectsBox(renderer.bounds)) {
1140
+ continue;
1141
+ }
1142
+ break;
1143
+ }
1144
+ }
1145
+ renderer._prepareRender(context);
1146
+ renderer._renderFrameCount = frameCount;
1147
+ }
1148
+ };
1149
+ /**
1150
+ * @internal
1151
+ */ _proto._updateSortDistance = function _updateSortDistance(cameraPosition) {
1152
+ switch(this._realRenderMode){
1153
+ case CanvasRenderMode.ScreenSpaceOverlay:
1154
+ this._sortDistance = 0;
1155
+ break;
1156
+ case CanvasRenderMode.ScreenSpaceCamera:
1157
+ this._sortDistance = this._distance;
1158
+ break;
1159
+ case CanvasRenderMode.WorldSpace:
1160
+ this._sortDistance = Vector3.distance(cameraPosition, this.entity.transform.worldPosition);
1161
+ break;
1162
+ }
1163
+ };
1164
+ // @ts-ignore
1165
+ _proto._onEnableInScene = function _onEnableInScene() {
1166
+ var entity = this.entity;
1167
+ // @ts-ignore
1168
+ entity._dispatchModify(4, this);
1169
+ var rootCanvas = Utils.searchRootCanvasInParents(this);
1170
+ this._setIsRootCanvas(!rootCanvas);
1171
+ Utils.setRootCanvas(this, rootCanvas);
1172
+ };
1173
+ // @ts-ignore
1174
+ _proto._onDisableInScene = function _onDisableInScene() {
1175
+ this._setIsRootCanvas(false);
1176
+ Utils.cleanRootCanvas(this);
1177
+ };
1178
+ /**
1179
+ * @internal
1180
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1181
+ if (this._isRootCanvas) {
1182
+ if (flag === EntityModifyFlags.Parent) {
1183
+ var rootCanvas = Utils.searchRootCanvasInParents(this);
1184
+ this._setIsRootCanvas(!rootCanvas);
1185
+ Utils.setRootCanvas(this, rootCanvas);
1186
+ } else if (flag === 4) {
1187
+ this._setIsRootCanvas(false);
1188
+ Utils.setRootCanvas(this, param);
1189
+ }
1190
+ } else {
1191
+ if (flag === EntityModifyFlags.Parent) {
1192
+ var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1193
+ this._setIsRootCanvas(!rootCanvas1);
1194
+ Utils.setRootCanvas(this, rootCanvas1);
1195
+ }
1196
+ }
1197
+ };
1198
+ _proto._getRenderers = function _getRenderers() {
1199
+ var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1200
+ var uiHierarchyVersion = entity._uiHierarchyVersion;
1201
+ if (this._hierarchyVersion !== uiHierarchyVersion) {
1202
+ renderers.length = this._walk(this.entity, renderers);
1203
+ UICanvas._tempGroupAbleList.length = 0;
1204
+ this._hierarchyVersion = uiHierarchyVersion;
1205
+ ++UICanvas._hierarchyCounter;
1206
+ }
1207
+ return renderers;
1208
+ };
1209
+ _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1210
+ var transform = this.entity.transform;
1211
+ var realRenderMode = this._realRenderMode;
1212
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1213
+ var _this__renderCamera_entity = this._renderCamera.entity, cameraTransform = _this__renderCamera_entity.transform;
1214
+ var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1215
+ var distance = this._distance;
1216
+ transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1217
+ transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
1218
+ } else {
1219
+ var canvas = this.engine.canvas;
1220
+ transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1221
+ transform.worldRotationQuaternion.set(0, 0, 0, 1);
1222
+ }
1223
+ };
1224
+ _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1225
+ var transform = this.entity.transform;
1226
+ var realRenderMode = this._realRenderMode;
1227
+ var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1228
+ var curWidth;
1229
+ var curHeight;
1230
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1231
+ var renderCamera = this._renderCamera;
1232
+ curHeight = renderCamera.isOrthographic ? renderCamera.orthographicSize * 2 : 2 * (Math.tan(MathUtil.degreeToRadian(renderCamera.fieldOfView * 0.5)) * this._distance);
1233
+ curWidth = renderCamera.aspectRatio * curHeight;
1234
+ } else {
1235
+ var canvas = this.engine.canvas;
1236
+ curHeight = canvas.height;
1237
+ curWidth = canvas.width;
1238
+ }
1239
+ var expectX, expectY, expectZ;
1240
+ switch(this._resolutionAdaptationMode){
1241
+ case ResolutionAdaptationMode.WidthAdaptation:
1242
+ expectX = expectY = expectZ = curWidth / width;
1243
+ break;
1244
+ case ResolutionAdaptationMode.HeightAdaptation:
1245
+ expectX = expectY = expectZ = curHeight / height;
1246
+ break;
1247
+ case ResolutionAdaptationMode.BothAdaptation:
1248
+ expectX = curWidth / width;
1249
+ expectY = curHeight / height;
1250
+ expectZ = (expectX + expectY) * 0.5;
1251
+ break;
1252
+ case ResolutionAdaptationMode.ExpandAdaptation:
1253
+ expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1254
+ break;
1255
+ case ResolutionAdaptationMode.ShrinkAdaptation:
1256
+ expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1257
+ break;
1258
+ }
1259
+ var worldMatrix = UICanvas._tempMat;
1260
+ Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1261
+ transform.worldMatrix = worldMatrix;
1262
+ transform.size.set(curWidth / expectX, curHeight / expectY);
1263
+ };
1264
+ _proto._walk = function _walk(entity, renderers, depth, group) {
1265
+ if (depth === void 0) depth = 0;
1266
+ if (group === void 0) group = null;
1267
+ // @ts-ignore
1268
+ var components = entity._components;
1269
+ var tempGroupAbleList = UICanvas._tempGroupAbleList;
1270
+ var groupAbleCount = 0;
1271
+ for(var i = 0, n = components.length; i < n; i++){
1272
+ var component = components[i];
1273
+ if (!component.enabled) continue;
1274
+ if (_instanceof(component, UIRenderer)) {
1275
+ renderers[depth] = component;
1276
+ ++depth;
1277
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1278
+ if (component._isGroupDirty) {
1279
+ tempGroupAbleList[groupAbleCount++] = component;
1280
+ }
1281
+ } else if (_instanceof(component, UIInteractive)) {
1282
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1283
+ if (component._isGroupDirty) {
1284
+ tempGroupAbleList[groupAbleCount++] = component;
1285
+ }
1286
+ } else if (_instanceof(component, UIGroup)) {
1287
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1288
+ component._isGroupDirty && Utils.setGroup(component, group);
1289
+ group = component;
1290
+ }
1291
+ }
1292
+ for(var i1 = 0; i1 < groupAbleCount; i1++){
1293
+ Utils.setGroup(tempGroupAbleList[i1], group);
1294
+ }
1295
+ var children = entity.children;
1296
+ for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1297
+ var child = children[i2];
1298
+ child.isActive && (depth = this._walk(child, renderers, depth, group));
1299
+ }
1300
+ return depth;
1301
+ };
1302
+ _proto._updateCameraObserver = function _updateCameraObserver() {
1303
+ var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._renderCamera : null;
1304
+ var preCamera = this._cameraObserver;
1305
+ if (preCamera !== camera) {
1306
+ this._cameraObserver = camera;
1307
+ if (preCamera) {
1308
+ // @ts-ignore
1309
+ preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1310
+ // @ts-ignore
1311
+ preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1312
+ }
1313
+ if (camera) {
1314
+ // @ts-ignore
1315
+ camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1316
+ // @ts-ignore
1317
+ camera._registerModifyListener(this._onCameraModifyListener);
1318
+ }
1319
+ }
1320
+ };
1321
+ _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1322
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1323
+ switch(flag){
1324
+ case CameraModifyFlags.ProjectionType:
1325
+ case CameraModifyFlags.AspectRatio:
1326
+ this._adapterSizeInScreenSpace();
1327
+ break;
1328
+ case CameraModifyFlags.FieldOfView:
1329
+ !this._renderCamera.isOrthographic && this._adapterSizeInScreenSpace();
1330
+ break;
1331
+ case CameraModifyFlags.OrthographicSize:
1332
+ this._renderCamera.isOrthographic && this._adapterSizeInScreenSpace();
1333
+ break;
1334
+ case CameraModifyFlags.DisableInScene:
1335
+ this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
1336
+ break;
1337
+ }
1338
+ } else {
1339
+ flag === CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
1340
+ }
1341
+ };
1342
+ _proto._onCameraTransformListener = function _onCameraTransformListener() {
1343
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1344
+ };
1345
+ _proto._addCanvasListener = function _addCanvasListener() {
1346
+ // @ts-ignore
1347
+ this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1348
+ };
1349
+ _proto._removeCanvasListener = function _removeCanvasListener() {
1350
+ // @ts-ignore
1351
+ this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1352
+ };
1353
+ _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1354
+ var canvas = this.engine.canvas;
1355
+ this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1356
+ this._adapterSizeInScreenSpace();
1357
+ };
1358
+ _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1359
+ var realRenderMode = this._realRenderMode;
1360
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1361
+ this._adapterSizeInScreenSpace();
1362
+ }
1363
+ };
1364
+ _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1365
+ var _this = this;
1366
+ if (this._isRootCanvas !== isRootCanvas) {
1367
+ this._isRootCanvas = isRootCanvas;
1368
+ this._updateCameraObserver();
1369
+ this._setRealRenderMode(this._getRealRenderMode());
1370
+ if (isRootCanvas) {
1371
+ this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1372
+ } else {
1373
+ var _this1 = this, disorderedElements = _this1._disorderedElements;
1374
+ disorderedElements.forEach(function(element) {
1375
+ if (_instanceof(element, UICanvas)) {
1376
+ var rootCanvas = Utils.searchRootCanvasInParents(element);
1377
+ element._setIsRootCanvas(!rootCanvas);
1378
+ Utils.setRootCanvas(element, rootCanvas);
1379
+ } else {
1380
+ Utils.setRootCanvasDirty(_this);
1381
+ Utils.setGroupDirty(element);
1382
+ }
1383
+ });
1384
+ disorderedElements.length = 0;
1385
+ disorderedElements.garbageCollection();
1386
+ this._orderedRenderers.length = 0;
1387
+ }
1388
+ }
1389
+ };
1390
+ _proto._getRealRenderMode = function _getRealRenderMode() {
1391
+ if (this._isRootCanvas) {
1392
+ var _this__renderCamera;
1393
+ var mode = this._renderMode;
1394
+ if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__renderCamera = this._renderCamera) == null ? void 0 : _this__renderCamera.enabled)) {
1395
+ return CanvasRenderMode.ScreenSpaceOverlay;
1396
+ } else {
1397
+ return mode;
1398
+ }
1399
+ } else {
1400
+ return 4;
1401
+ }
1402
+ };
1403
+ _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1404
+ var preRealMode = this._realRenderMode;
1405
+ if (preRealMode !== curRealMode) {
1406
+ this._realRenderMode = curRealMode;
1407
+ // @ts-ignore
1408
+ var componentsManager = this.scene._componentsManager;
1409
+ switch(preRealMode){
1410
+ case CanvasRenderMode.ScreenSpaceOverlay:
1411
+ this._removeCanvasListener();
1412
+ case CanvasRenderMode.ScreenSpaceCamera:
1413
+ case CanvasRenderMode.WorldSpace:
1414
+ componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1415
+ break;
1416
+ }
1417
+ switch(curRealMode){
1418
+ case CanvasRenderMode.ScreenSpaceOverlay:
1419
+ this._addCanvasListener();
1420
+ case CanvasRenderMode.ScreenSpaceCamera:
1421
+ this._adapterPoseInScreenSpace();
1422
+ this._adapterSizeInScreenSpace();
1423
+ case CanvasRenderMode.WorldSpace:
1424
+ componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1425
+ break;
1426
+ }
1427
+ }
1428
+ };
1429
+ _create_class(UICanvas, [
1430
+ {
1431
+ key: "referenceResolutionPerUnit",
1432
+ get: /**
1433
+ * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1434
+ */ function get() {
1435
+ return this._referenceResolutionPerUnit;
1436
+ },
1437
+ set: function set(value) {
1438
+ if (this._referenceResolutionPerUnit !== value) {
1439
+ this._referenceResolutionPerUnit = value;
1440
+ this._disorderedElements.forEach(function(element) {
1441
+ element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1442
+ });
1443
+ }
1444
+ }
1445
+ },
1446
+ {
1447
+ key: "referenceResolution",
1448
+ get: /**
1449
+ * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1450
+ */ function get() {
1451
+ return this._referenceResolution;
1452
+ },
1453
+ set: function set(value) {
1454
+ var referenceResolution = this._referenceResolution;
1455
+ if (referenceResolution === value) return;
1456
+ (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
1457
+ }
1458
+ },
1459
+ {
1460
+ key: "renderMode",
1461
+ get: /**
1462
+ * The rendering mode of the UI canvas.
1463
+ */ function get() {
1464
+ return this._renderMode;
1465
+ },
1466
+ set: function set(mode) {
1467
+ var preMode = this._renderMode;
1468
+ if (preMode !== mode) {
1469
+ this._renderMode = mode;
1470
+ this._updateCameraObserver();
1471
+ this._setRealRenderMode(this._getRealRenderMode());
1472
+ }
1473
+ }
1474
+ },
1475
+ {
1476
+ key: "renderCamera",
1477
+ get: /**
1478
+ * The camera used to render the UI canvas in `ScreenSpaceCamera` mode.
1479
+ * @remarks If set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
1480
+ */ function get() {
1481
+ return this._renderCamera;
1482
+ },
1483
+ set: function set(value) {
1484
+ var preCamera = this._renderCamera;
1485
+ if (preCamera !== value) {
1486
+ this._renderCamera = value;
1487
+ this._updateCameraObserver();
1488
+ this._setRealRenderMode(this._getRealRenderMode());
1489
+ }
1490
+ }
1491
+ },
1492
+ {
1493
+ key: "resolutionAdaptationMode",
1494
+ get: /**
1495
+ * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1496
+ */ function get() {
1497
+ return this._resolutionAdaptationMode;
1498
+ },
1499
+ set: function set(value) {
1500
+ if (this._resolutionAdaptationMode !== value) {
1501
+ this._resolutionAdaptationMode = value;
1502
+ var realRenderMode = this._realRenderMode;
1503
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1504
+ this._adapterSizeInScreenSpace();
1505
+ }
1506
+ }
1507
+ }
1508
+ },
1509
+ {
1510
+ key: "sortOrder",
1511
+ get: /**
1512
+ * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
1513
+ */ function get() {
1514
+ return this._sortOrder;
1515
+ },
1516
+ set: function set(value) {
1517
+ if (this._sortOrder !== value) {
1518
+ this._sortOrder = value;
1519
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
1520
+ (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
1521
+ }
1522
+ }
1523
+ },
1524
+ {
1525
+ key: "distance",
1526
+ get: /**
1527
+ * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
1528
+ */ function get() {
1529
+ return this._distance;
1530
+ },
1531
+ set: function set(value) {
1532
+ if (this._distance !== value) {
1533
+ this._distance = value;
1534
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1535
+ this._adapterPoseInScreenSpace();
1536
+ this._adapterSizeInScreenSpace();
1537
+ }
1538
+ }
1539
+ }
1540
+ }
1541
+ ]);
1542
+ return UICanvas;
1543
+ }(Component);
1544
+ /** @internal */ UICanvas._hierarchyCounter = 1;
1545
+ UICanvas._tempGroupAbleList = [];
1546
+ UICanvas._tempVec3 = new Vector3();
1547
+ UICanvas._tempMat = new Matrix();
1548
+ __decorate([
1549
+ ignoreClone
1550
+ ], UICanvas.prototype, "_canvasIndex", void 0);
1551
+ __decorate([
1552
+ ignoreClone
1553
+ ], UICanvas.prototype, "_rootCanvas", void 0);
1554
+ __decorate([
1555
+ ignoreClone
1556
+ ], UICanvas.prototype, "_indexInRootCanvas", void 0);
1557
+ __decorate([
1558
+ ignoreClone
1559
+ ], UICanvas.prototype, "_isRootCanvasDirty", void 0);
1560
+ __decorate([
1561
+ ignoreClone
1562
+ ], UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
1563
+ __decorate([
1564
+ ignoreClone
1565
+ ], UICanvas.prototype, "_isRootCanvas", void 0);
1566
+ __decorate([
1567
+ ignoreClone
1568
+ ], UICanvas.prototype, "_renderElement", void 0);
1569
+ __decorate([
1570
+ ignoreClone
1571
+ ], UICanvas.prototype, "_sortDistance", void 0);
1572
+ __decorate([
1573
+ ignoreClone
1574
+ ], UICanvas.prototype, "_orderedRenderers", void 0);
1575
+ __decorate([
1576
+ ignoreClone
1577
+ ], UICanvas.prototype, "_realRenderMode", void 0);
1578
+ __decorate([
1579
+ ignoreClone
1580
+ ], UICanvas.prototype, "_disorderedElements", void 0);
1581
+ __decorate([
1582
+ ignoreClone
1583
+ ], UICanvas.prototype, "_renderMode", void 0);
1584
+ __decorate([
1585
+ ignoreClone
1586
+ ], UICanvas.prototype, "_renderCamera", void 0);
1587
+ __decorate([
1588
+ ignoreClone
1589
+ ], UICanvas.prototype, "_cameraObserver", void 0);
1590
+ __decorate([
1591
+ ignoreClone
1592
+ ], UICanvas.prototype, "_resolutionAdaptationMode", void 0);
1593
+ __decorate([
1594
+ ignoreClone
1595
+ ], UICanvas.prototype, "_sortOrder", void 0);
1596
+ __decorate([
1597
+ ignoreClone
1598
+ ], UICanvas.prototype, "_distance", void 0);
1599
+ __decorate([
1600
+ deepClone
1601
+ ], UICanvas.prototype, "_referenceResolution", void 0);
1602
+ __decorate([
1603
+ deepClone
1604
+ ], UICanvas.prototype, "_referenceResolutionPerUnit", void 0);
1605
+ __decorate([
1606
+ ignoreClone
1607
+ ], UICanvas.prototype, "_hierarchyVersion", void 0);
1608
+ __decorate([
1609
+ ignoreClone
1610
+ ], UICanvas.prototype, "_rootCanvasListener", null);
1611
+ __decorate([
1612
+ ignoreClone
1613
+ ], UICanvas.prototype, "_onCameraModifyListener", null);
1614
+ __decorate([
1615
+ ignoreClone
1616
+ ], UICanvas.prototype, "_onCameraTransformListener", null);
1617
+ __decorate([
1618
+ ignoreClone
1619
+ ], UICanvas.prototype, "_onCanvasSizeListener", null);
1620
+ __decorate([
1621
+ ignoreClone
1622
+ ], UICanvas.prototype, "_onReferenceResolutionChanged", null);
1623
+ UICanvas = __decorate([
1624
+ dependentComponents(UITransform, DependentMode.AutoAdd)
1625
+ ], UICanvas);
1626
+ /**
1627
+ * @remarks Extends `EntityModifyFlags`.
1628
+ */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
1629
+ EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
1630
+ EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
1631
+ return EntityUIModifyFlags;
1632
+ }({});
1633
+ var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
1634
+ RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
1635
+ RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
1636
+ RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
1637
+ return RootCanvasModifyFlags;
1638
+ }({});
1639
+
1640
+ var Button = /*#__PURE__*/ function(UIInteractive) {
1641
+ _inherits(Button, UIInteractive);
1642
+ function Button() {
1643
+ var _this;
1644
+ _this = UIInteractive.apply(this, arguments) || this, _this._listeners = new SafeLoopArray();
1645
+ return _this;
1646
+ }
1647
+ var _proto = Button.prototype;
1648
+ /**
1649
+ * Add a listening function for click.
1650
+ * @param listener - The listening function
1651
+ */ _proto.addClicked = function addClicked(listener) {
1652
+ this._listeners.push({
1653
+ fn: listener
1654
+ });
1655
+ };
1656
+ /**
1657
+ * Remove a listening function of click.
1658
+ * @param listener - The listening function
1659
+ */ _proto.removeClicked = function removeClicked(listener) {
1660
+ this._listeners.findAndRemove(function(value) {
1661
+ return value.fn === listener ? value.destroyed = true : false;
1662
+ });
1663
+ };
1664
+ _proto.onPointerClick = function onPointerClick(event) {
1665
+ if (!this._getGlobalInteractive()) return;
1666
+ var listeners = this._listeners.getLoopArray();
1667
+ for(var i = 0, n = listeners.length; i < n; i++){
1668
+ var listener = listeners[i];
1669
+ !listener.destroyed && listener.fn(event);
1670
+ }
1671
+ };
1672
+ _proto.onDestroy = function onDestroy() {
1673
+ UIInteractive.prototype.onDestroy.call(this);
1674
+ this._listeners.findAndRemove(function(value) {
1675
+ return value.destroyed = true;
1676
+ });
1677
+ };
1678
+ return Button;
1679
+ }(UIInteractive);
1680
+
1681
+ /**
1682
+ * UI element that renders an image.
1683
+ */ var Image = /*#__PURE__*/ function(UIRenderer1) {
1684
+ _inherits(Image, UIRenderer1);
1685
+ function Image(entity) {
1686
+ var _this;
1687
+ _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5;
1688
+ _this.drawMode = SpriteDrawMode.Simple;
1689
+ _this.setMaterial(_this._engine._getUIDefaultMaterial());
1690
+ _this._onSpriteChange = _this._onSpriteChange.bind(_this);
1691
+ return _this;
1692
+ }
1693
+ var _proto = Image.prototype;
1694
+ /**
1695
+ * @internal
1696
+ */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
1697
+ if (flag & RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
1698
+ var drawMode = this._drawMode;
1699
+ if (drawMode === SpriteDrawMode.Tiled) {
1700
+ this._dirtyUpdateFlag |= 15;
1701
+ } else if (drawMode === SpriteDrawMode.Sliced) {
1702
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
1703
+ }
1704
+ }
1705
+ };
1706
+ _proto._updateBounds = function _updateBounds(worldBounds) {
1707
+ var sprite = this._sprite;
1708
+ var rootCanvas = this._getRootCanvas();
1709
+ if (sprite && rootCanvas) {
1710
+ var transform = this._transformEntity.transform;
1711
+ var size = transform.size;
1712
+ this._assembler.updatePositions(this, transform.worldMatrix, size.x, size.y, transform.pivot, false, false, rootCanvas.referenceResolutionPerUnit);
1713
+ } else {
1714
+ var worldPosition = this._transformEntity.transform.worldPosition;
1715
+ worldBounds.min.copyFrom(worldPosition);
1716
+ worldBounds.max.copyFrom(worldPosition);
1717
+ }
1718
+ };
1719
+ _proto._render = function _render(context) {
1720
+ var _this = this, sprite = _this._sprite;
1721
+ var transform = this._transformEntity.transform;
1722
+ var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
1723
+ if (!(sprite == null ? void 0 : sprite.texture) || !width || !height) {
1724
+ return;
1725
+ }
1726
+ var material = this.getMaterial();
1727
+ if (!material) {
1728
+ return;
1729
+ }
1730
+ // @todo: This question needs to be raised rather than hidden.
1731
+ if (material.destroyed) {
1732
+ material = this._engine._getUIDefaultMaterial();
1733
+ }
1734
+ var alpha = this._getGlobalAlpha();
1735
+ if (this._color.a * alpha <= 0) {
1736
+ return;
1737
+ }
1738
+ var _this1 = this, dirtyUpdateFlag = _this1._dirtyUpdateFlag;
1739
+ var canvas = this._getRootCanvas();
1740
+ // Update position
1741
+ if (dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
1742
+ this._assembler.updatePositions(this, transform.worldMatrix, width, height, transform.pivot, false, false, canvas.referenceResolutionPerUnit);
1743
+ dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
1744
+ }
1745
+ // Update uv
1746
+ if (dirtyUpdateFlag & 4) {
1747
+ this._assembler.updateUVs(this);
1748
+ dirtyUpdateFlag &= ~4;
1749
+ }
1750
+ // Update color
1751
+ if (dirtyUpdateFlag & UIRendererUpdateFlags.Color) {
1752
+ this._assembler.updateColor(this, alpha);
1753
+ dirtyUpdateFlag &= ~UIRendererUpdateFlags.Color;
1754
+ }
1755
+ this._dirtyUpdateFlag = dirtyUpdateFlag;
1756
+ // Init sub render element.
1757
+ var engine = context.camera.engine;
1758
+ var subRenderElement = engine._subRenderElementPool.get();
1759
+ var subChunk = this._subChunk;
1760
+ subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
1761
+ if (canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1762
+ subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
1763
+ subRenderElement.renderQueueFlags = RenderQueueFlags.All;
1764
+ }
1765
+ canvas._renderElement.addSubRenderElement(subRenderElement);
1766
+ };
1767
+ _proto._onTransformChanged = function _onTransformChanged(type) {
1768
+ if (type & UITransformModifyFlags.Size && this._drawMode === SpriteDrawMode.Tiled) {
1769
+ this._dirtyUpdateFlag |= 15;
1770
+ }
1771
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
1772
+ };
1773
+ _proto._onDestroy = function _onDestroy() {
1774
+ var sprite = this._sprite;
1775
+ if (sprite) {
1776
+ this._addResourceReferCount(sprite, -1);
1777
+ // @ts-ignore
1778
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
1779
+ this._sprite = null;
1780
+ }
1781
+ UIRenderer1.prototype._onDestroy.call(this);
1782
+ };
1783
+ _proto._onSpriteChange = function _onSpriteChange(type) {
1784
+ switch(type){
1785
+ case SpriteModifyFlags.texture:
1786
+ this.shaderData.setTexture(UIRenderer._textureProperty, this.sprite.texture);
1787
+ break;
1788
+ case SpriteModifyFlags.size:
1789
+ switch(this._drawMode){
1790
+ case SpriteDrawMode.Sliced:
1791
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
1792
+ break;
1793
+ case SpriteDrawMode.Tiled:
1794
+ this._dirtyUpdateFlag |= 7;
1795
+ break;
1796
+ }
1797
+ break;
1798
+ case SpriteModifyFlags.border:
1799
+ switch(this._drawMode){
1800
+ case SpriteDrawMode.Sliced:
1801
+ this._dirtyUpdateFlag |= 5;
1802
+ break;
1803
+ case SpriteDrawMode.Tiled:
1804
+ this._dirtyUpdateFlag |= 7;
1805
+ break;
1806
+ }
1807
+ break;
1808
+ case SpriteModifyFlags.region:
1809
+ case SpriteModifyFlags.atlasRegionOffset:
1810
+ this._dirtyUpdateFlag |= 5;
1811
+ break;
1812
+ case SpriteModifyFlags.atlasRegion:
1813
+ this._dirtyUpdateFlag |= 4;
1814
+ break;
1815
+ case SpriteModifyFlags.destroy:
1816
+ this.sprite = null;
1817
+ break;
1818
+ }
1819
+ };
1820
+ _create_class(Image, [
1821
+ {
1822
+ key: "drawMode",
1823
+ get: /**
1824
+ * The draw mode of the image.
1825
+ */ function get() {
1826
+ return this._drawMode;
1827
+ },
1828
+ set: function set(value) {
1829
+ if (this._drawMode !== value) {
1830
+ this._drawMode = value;
1831
+ switch(value){
1832
+ case SpriteDrawMode.Simple:
1833
+ this._assembler = SimpleSpriteAssembler;
1834
+ break;
1835
+ case SpriteDrawMode.Sliced:
1836
+ this._assembler = SlicedSpriteAssembler;
1837
+ break;
1838
+ case SpriteDrawMode.Tiled:
1839
+ this._assembler = TiledSpriteAssembler;
1840
+ break;
1841
+ }
1842
+ this._assembler.resetData(this);
1843
+ this._dirtyUpdateFlag |= 7;
1844
+ }
1845
+ }
1846
+ },
1847
+ {
1848
+ key: "tileMode",
1849
+ get: /**
1850
+ * The tiling mode of the image. (Only works in tiled mode.)
1851
+ */ function get() {
1852
+ return this._tileMode;
1853
+ },
1854
+ set: function set(value) {
1855
+ if (this._tileMode !== value) {
1856
+ this._tileMode = value;
1857
+ if (this.drawMode === SpriteDrawMode.Tiled) {
1858
+ this._dirtyUpdateFlag |= 7;
1859
+ }
1860
+ }
1861
+ }
1862
+ },
1863
+ {
1864
+ key: "tiledAdaptiveThreshold",
1865
+ get: /**
1866
+ * Stretch Threshold in Tile Adaptive Mode, specified in normalized. (Only works in tiled adaptive mode.)
1867
+ */ function get() {
1868
+ return this._tiledAdaptiveThreshold;
1869
+ },
1870
+ set: function set(value) {
1871
+ if (value !== this._tiledAdaptiveThreshold) {
1872
+ value = MathUtil.clamp(value, 0, 1);
1873
+ this._tiledAdaptiveThreshold = value;
1874
+ if (this.drawMode === SpriteDrawMode.Tiled) {
1875
+ this._dirtyUpdateFlag |= 7;
1876
+ }
1877
+ }
1878
+ }
1879
+ },
1880
+ {
1881
+ key: "sprite",
1882
+ get: /**
1883
+ * The Sprite to render.
1884
+ */ function get() {
1885
+ return this._sprite;
1886
+ },
1887
+ set: function set(value) {
1888
+ var lastSprite = this._sprite;
1889
+ if (lastSprite !== value) {
1890
+ if (lastSprite) {
1891
+ this._addResourceReferCount(lastSprite, -1);
1892
+ // @ts-ignore
1893
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
1894
+ }
1895
+ this._dirtyUpdateFlag |= 7;
1896
+ if (value) {
1897
+ this._addResourceReferCount(value, 1);
1898
+ // @ts-ignore
1899
+ value._updateFlagManager.addListener(this._onSpriteChange);
1900
+ this.shaderData.setTexture(UIRenderer._textureProperty, value.texture);
1901
+ } else {
1902
+ this.shaderData.setTexture(UIRenderer._textureProperty, null);
1903
+ }
1904
+ this._sprite = value;
1905
+ }
1906
+ }
1907
+ }
1908
+ ]);
1909
+ return Image;
1910
+ }(UIRenderer);
1911
+ __decorate([
1912
+ ignoreClone
1913
+ ], Image.prototype, "_sprite", void 0);
1914
+ __decorate([
1915
+ ignoreClone
1916
+ ], Image.prototype, "_drawMode", void 0);
1917
+ __decorate([
1918
+ assignmentClone
1919
+ ], Image.prototype, "_assembler", void 0);
1920
+ __decorate([
1921
+ assignmentClone
1922
+ ], Image.prototype, "_tileMode", void 0);
1923
+ __decorate([
1924
+ assignmentClone
1925
+ ], Image.prototype, "_tiledAdaptiveThreshold", void 0);
1926
+ __decorate([
1927
+ ignoreClone
1928
+ ], Image.prototype, "_onTransformChanged", null);
1929
+ __decorate([
1930
+ ignoreClone
1931
+ ], Image.prototype, "_onSpriteChange", null);
1932
+
1933
+ /**
1934
+ * UI component used to render text.
1935
+ */ var Text = /*#__PURE__*/ function(UIRenderer1) {
1936
+ _inherits(Text, UIRenderer1);
1937
+ function Text(entity) {
1938
+ var _this;
1939
+ _this = UIRenderer1.call(this, entity) || this, _this._textChunks = Array(), _this._subFont = null, _this._text = "", _this._localBounds = new BoundingBox(), _this._font = null, _this._fontSize = 24, _this._fontStyle = FontStyle.None, _this._lineSpacing = 0, _this._horizontalAlignment = TextHorizontalAlignment.Center, _this._verticalAlignment = TextVerticalAlignment.Center, _this._enableWrapping = false, _this._overflowMode = OverflowMode.Overflow;
1940
+ var engine = _this.engine;
1941
+ // @ts-ignore
1942
+ _this.font = engine._textDefaultFont;
1943
+ // @ts-ignore
1944
+ _this.setMaterial(engine._basicResources.textDefaultMaterial);
1945
+ return _this;
1946
+ }
1947
+ var _proto = Text.prototype;
1948
+ /**
1949
+ * @internal
1950
+ */ _proto._onDestroy = function _onDestroy() {
1951
+ if (this._font) {
1952
+ this._addResourceReferCount(this._font, -1);
1953
+ this._font = null;
1954
+ }
1955
+ UIRenderer1.prototype._onDestroy.call(this);
1956
+ this._freeTextChunks();
1957
+ this._textChunks = null;
1958
+ this._subFont && (this._subFont = null);
1959
+ };
1960
+ // @ts-ignore
1961
+ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1962
+ // @ts-ignore
1963
+ UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
1964
+ target.font = this._font;
1965
+ target._subFont = this._subFont;
1966
+ };
1967
+ /**
1968
+ * @internal
1969
+ */ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
1970
+ return (this._dirtyUpdateFlag & type) != 0;
1971
+ };
1972
+ /**
1973
+ * @internal
1974
+ */ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
1975
+ this._dirtyUpdateFlag |= type;
1976
+ };
1977
+ /**
1978
+ * @internal
1979
+ */ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
1980
+ this._dirtyUpdateFlag &= ~type;
1981
+ };
1982
+ /**
1983
+ * @internal
1984
+ */ _proto._getSubFont = function _getSubFont() {
1985
+ if (!this._subFont) {
1986
+ this._resetSubFont();
1987
+ }
1988
+ return this._subFont;
1989
+ };
1990
+ /**
1991
+ * @internal
1992
+ */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
1993
+ if (flag === RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
1994
+ this._setDirtyFlagTrue(8);
1995
+ }
1996
+ };
1997
+ _proto._updateBounds = function _updateBounds(worldBounds) {
1998
+ var transform = this._transformEntity.transform;
1999
+ var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2000
+ var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
2001
+ worldBounds.min.set(-width * pivotX, -height * pivotY, 0);
2002
+ worldBounds.max.set(width * (1 - pivotX), height * (1 - pivotY), 0);
2003
+ BoundingBox.transform(worldBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2004
+ };
2005
+ _proto._render = function _render(context) {
2006
+ if (this._isTextNoVisible()) {
2007
+ return;
2008
+ }
2009
+ if (this._isContainDirtyFlag(4)) {
2010
+ this._resetSubFont();
2011
+ this._setDirtyFlagFalse(4);
2012
+ }
2013
+ var canvas = this._getRootCanvas();
2014
+ if (this._isContainDirtyFlag(8)) {
2015
+ this._updateLocalData();
2016
+ this._setDirtyFlagTrue(8);
2017
+ }
2018
+ if (this._isContainDirtyFlag(16)) {
2019
+ this._updatePosition();
2020
+ this._setDirtyFlagFalse(16);
2021
+ }
2022
+ if (this._isContainDirtyFlag(UIRendererUpdateFlags.Color)) {
2023
+ this._updateColor();
2024
+ this._setDirtyFlagFalse(UIRendererUpdateFlags.Color);
2025
+ }
2026
+ var engine = context.camera.engine;
2027
+ var textSubRenderElementPool = engine._textSubRenderElementPool;
2028
+ var material = this.getMaterial();
2029
+ var renderElement = canvas._renderElement;
2030
+ var textChunks = this._textChunks;
2031
+ var isOverlay = canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay;
2032
+ for(var i = 0, n = textChunks.length; i < n; ++i){
2033
+ var // @ts-ignore
2034
+ _subRenderElement;
2035
+ var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, texture = _textChunks_i.texture;
2036
+ var subRenderElement = textSubRenderElementPool.get();
2037
+ subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
2038
+ (_subRenderElement = subRenderElement).shaderData || (_subRenderElement.shaderData = new ShaderData(ShaderDataGroup.RenderElement));
2039
+ subRenderElement.shaderData.setTexture(Text._textTextureProperty, texture);
2040
+ if (isOverlay) {
2041
+ subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
2042
+ subRenderElement.renderQueueFlags = RenderQueueFlags.All;
2043
+ }
2044
+ renderElement.addSubRenderElement(subRenderElement);
2045
+ }
2046
+ };
2047
+ _proto._resetSubFont = function _resetSubFont() {
2048
+ var font = this._font;
2049
+ // @ts-ignore
2050
+ this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
2051
+ this._subFont.nativeFontString = TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
2052
+ };
2053
+ _proto._updatePosition = function _updatePosition() {
2054
+ var e = this._transformEntity.transform.worldMatrix.elements;
2055
+ // prettier-ignore
2056
+ 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];
2057
+ var up = UIRenderer._tempVec31.set(e4, e5, e6);
2058
+ var right = UIRenderer._tempVec30.set(e0, e1, e2);
2059
+ var worldPositions = Text._worldPositions;
2060
+ var worldPosition0 = worldPositions[0], worldPosition1 = worldPositions[1], worldPosition2 = worldPositions[2], worldPosition3 = worldPositions[3];
2061
+ var textChunks = this._textChunks;
2062
+ for(var i = 0, n = textChunks.length; i < n; ++i){
2063
+ var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, charRenderInfos = _textChunks_i.charRenderInfos;
2064
+ for(var j = 0, m = charRenderInfos.length; j < m; ++j){
2065
+ var charRenderInfo = charRenderInfos[j];
2066
+ var localPositions = charRenderInfo.localPositions;
2067
+ var topLeftX = localPositions.x, topLeftY = localPositions.y;
2068
+ // Top-Left
2069
+ worldPosition0.set(topLeftX * e0 + topLeftY * e4 + e12, topLeftX * e1 + topLeftY * e5 + e13, topLeftX * e2 + topLeftY * e6 + e14);
2070
+ // Right offset
2071
+ Vector3.scale(right, localPositions.z - topLeftX, worldPosition1);
2072
+ // Top-Right
2073
+ Vector3.add(worldPosition0, worldPosition1, worldPosition1);
2074
+ // Up offset
2075
+ Vector3.scale(up, localPositions.w - topLeftY, worldPosition2);
2076
+ // Bottom-Left
2077
+ Vector3.add(worldPosition0, worldPosition2, worldPosition3);
2078
+ // Bottom-Right
2079
+ Vector3.add(worldPosition1, worldPosition2, worldPosition2);
2080
+ var vertices = subChunk.chunk.vertices;
2081
+ for(var k = 0, o = subChunk.vertexArea.start + charRenderInfo.indexInChunk * 36; k < 4; ++k, o += 9){
2082
+ worldPositions[k].copyToArray(vertices, o);
2083
+ }
2084
+ }
2085
+ }
2086
+ };
2087
+ _proto._updateColor = function _updateColor() {
2088
+ var _this__color = this._color, r = _this__color.r, g = _this__color.g, b = _this__color.b, a = _this__color.a;
2089
+ var finalAlpha = a * this._getGlobalAlpha();
2090
+ var textChunks = this._textChunks;
2091
+ for(var i = 0, n = textChunks.length; i < n; ++i){
2092
+ var subChunk = textChunks[i].subChunk;
2093
+ var vertexArea = subChunk.vertexArea;
2094
+ var vertexCount = vertexArea.size / 9;
2095
+ var vertices = subChunk.chunk.vertices;
2096
+ for(var j = 0, o = vertexArea.start + 5; j < vertexCount; ++j, o += 9){
2097
+ vertices[o] = r;
2098
+ vertices[o + 1] = g;
2099
+ vertices[o + 2] = b;
2100
+ vertices[o + 3] = finalAlpha;
2101
+ }
2102
+ }
2103
+ };
2104
+ _proto._updateLocalData = function _updateLocalData() {
2105
+ // @ts-ignore
2106
+ var pixelsPerResolution = Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
2107
+ var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
2108
+ var charRenderInfos = Text._charRenderInfos;
2109
+ var charFont = this._getSubFont();
2110
+ var _this__transformEntity_transform = this._transformEntity.transform, size = _this__transformEntity_transform.size, pivot = _this__transformEntity_transform.pivot;
2111
+ var rendererWidth = size.x;
2112
+ var rendererHeight = size.y;
2113
+ var offsetWidth = rendererWidth * (0.5 - pivot.x);
2114
+ var offsetHeight = rendererHeight * (0.5 - pivot.y);
2115
+ var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * pixelsPerResolution) : TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * pixelsPerResolution);
2116
+ var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
2117
+ // @ts-ignore
2118
+ var charRenderInfoPool = this.engine._charRenderInfoPool;
2119
+ var linesLen = lines.length;
2120
+ var renderElementCount = 0;
2121
+ if (linesLen > 0) {
2122
+ var horizontalAlignment = this.horizontalAlignment;
2123
+ var pixelsPerUnitReciprocal = 1.0 / pixelsPerResolution;
2124
+ rendererWidth *= pixelsPerResolution;
2125
+ rendererHeight *= pixelsPerResolution;
2126
+ var halfRendererWidth = rendererWidth * 0.5;
2127
+ var halfLineHeight = lineHeight * 0.5;
2128
+ var startY = 0;
2129
+ var topDiff = lineHeight * 0.5 - lineMaxSizes[0].ascent;
2130
+ var bottomDiff = lineHeight * 0.5 - lineMaxSizes[linesLen - 1].descent - 1;
2131
+ switch(this.verticalAlignment){
2132
+ case TextVerticalAlignment.Top:
2133
+ startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
2134
+ break;
2135
+ case TextVerticalAlignment.Center:
2136
+ startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
2137
+ break;
2138
+ case TextVerticalAlignment.Bottom:
2139
+ startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
2140
+ break;
2141
+ }
2142
+ var firstLine = -1;
2143
+ var minX = Number.MAX_SAFE_INTEGER;
2144
+ var minY = Number.MAX_SAFE_INTEGER;
2145
+ var maxX = Number.MIN_SAFE_INTEGER;
2146
+ var maxY = Number.MIN_SAFE_INTEGER;
2147
+ for(var i = 0; i < linesLen; ++i){
2148
+ var lineWidth = lineWidths[i];
2149
+ if (lineWidth > 0) {
2150
+ var line = lines[i];
2151
+ var startX = 0;
2152
+ var firstRow = -1;
2153
+ if (firstLine < 0) {
2154
+ firstLine = i;
2155
+ }
2156
+ switch(horizontalAlignment){
2157
+ case TextHorizontalAlignment.Left:
2158
+ startX = -halfRendererWidth;
2159
+ break;
2160
+ case TextHorizontalAlignment.Center:
2161
+ startX = -lineWidth * 0.5;
2162
+ break;
2163
+ case TextHorizontalAlignment.Right:
2164
+ startX = halfRendererWidth - lineWidth;
2165
+ break;
2166
+ }
2167
+ for(var j = 0, n = line.length; j < n; ++j){
2168
+ var char = line[j];
2169
+ var charInfo = charFont._getCharInfo(char);
2170
+ if (charInfo.h > 0) {
2171
+ firstRow < 0 && (firstRow = j);
2172
+ var charRenderInfo = charRenderInfos[renderElementCount++] = charRenderInfoPool.get();
2173
+ var localPositions = charRenderInfo.localPositions;
2174
+ charRenderInfo.texture = charFont._getTextureByIndex(charInfo.index);
2175
+ charRenderInfo.uvs = charInfo.uvs;
2176
+ var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
2177
+ var left = (startX + offsetWidth) * pixelsPerUnitReciprocal;
2178
+ var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal;
2179
+ var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal;
2180
+ var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal;
2181
+ localPositions.set(left, top, right, bottom);
2182
+ i === firstLine && (maxY = Math.max(maxY, top));
2183
+ minY = Math.min(minY, bottom);
2184
+ j === firstRow && (minX = Math.min(minX, left));
2185
+ maxX = Math.max(maxX, right);
2186
+ }
2187
+ startX += charInfo.xAdvance + charInfo.offsetX;
2188
+ }
2189
+ }
2190
+ startY -= lineHeight;
2191
+ }
2192
+ if (firstLine < 0) {
2193
+ min.set(0, 0, 0);
2194
+ max.set(0, 0, 0);
2195
+ } else {
2196
+ min.set(minX, minY, 0);
2197
+ max.set(maxX, maxY, 0);
2198
+ }
2199
+ } else {
2200
+ min.set(0, 0, 0);
2201
+ max.set(0, 0, 0);
2202
+ }
2203
+ charFont._getLastIndex() > 0 && charRenderInfos.sort(function(a, b) {
2204
+ return a.texture.instanceId - b.texture.instanceId;
2205
+ });
2206
+ this._freeTextChunks();
2207
+ if (renderElementCount === 0) {
2208
+ return;
2209
+ }
2210
+ var textChunks = this._textChunks;
2211
+ var curTextChunk = new TextChunk();
2212
+ textChunks.push(curTextChunk);
2213
+ var chunkMaxVertexCount = this._getChunkManager().maxVertexCount;
2214
+ var curCharRenderInfo = charRenderInfos[0];
2215
+ var curTexture = curCharRenderInfo.texture;
2216
+ curTextChunk.texture = curTexture;
2217
+ var curCharInfos = curTextChunk.charRenderInfos;
2218
+ curCharInfos.push(curCharRenderInfo);
2219
+ for(var i1 = 1; i1 < renderElementCount; ++i1){
2220
+ var charRenderInfo1 = charRenderInfos[i1];
2221
+ var texture = charRenderInfo1.texture;
2222
+ if (curTexture !== texture || curCharInfos.length * 4 + 4 > chunkMaxVertexCount) {
2223
+ this._buildChunk(curTextChunk, curCharInfos.length);
2224
+ curTextChunk = new TextChunk();
2225
+ textChunks.push(curTextChunk);
2226
+ curTexture = texture;
2227
+ curTextChunk.texture = texture;
2228
+ curCharInfos = curTextChunk.charRenderInfos;
2229
+ }
2230
+ curCharInfos.push(charRenderInfo1);
2231
+ }
2232
+ var charLength = curCharInfos.length;
2233
+ if (charLength > 0) {
2234
+ this._buildChunk(curTextChunk, charLength);
2235
+ }
2236
+ charRenderInfos.length = 0;
2237
+ };
2238
+ _proto._onTransformChanged = function _onTransformChanged(type) {
2239
+ if (type & UITransformModifyFlags.Size || type & UITransformModifyFlags.Pivot) {
2240
+ this._dirtyUpdateFlag |= 8;
2241
+ }
2242
+ UIRenderer1.prototype._onTransformChanged.call(this, type);
2243
+ this._setDirtyFlagTrue(16);
2244
+ };
2245
+ _proto._isTextNoVisible = function _isTextNoVisible() {
2246
+ var size = this._transformEntity.transform.size;
2247
+ return this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === OverflowMode.Truncate && size.y <= 0;
2248
+ };
2249
+ _proto._buildChunk = function _buildChunk(textChunk, count) {
2250
+ var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
2251
+ var tempIndices = CharRenderInfo.triangles;
2252
+ var tempIndicesLength = tempIndices.length;
2253
+ var subChunk = textChunk.subChunk = this._getChunkManager().allocateSubChunk(count * 4);
2254
+ var vertices = subChunk.chunk.vertices;
2255
+ var indices = subChunk.indices = [];
2256
+ var charRenderInfos = textChunk.charRenderInfos;
2257
+ for(var i = 0, ii = 0, io = 0, vo = subChunk.vertexArea.start + 3; i < count; ++i, io += 4){
2258
+ var charRenderInfo = charRenderInfos[i];
2259
+ charRenderInfo.indexInChunk = i;
2260
+ // Set indices
2261
+ for(var j = 0; j < tempIndicesLength; ++j){
2262
+ indices[ii++] = tempIndices[j] + io;
2263
+ }
2264
+ // Set uv and color for vertices
2265
+ for(var j1 = 0; j1 < 4; ++j1, vo += 9){
2266
+ var uv = charRenderInfo.uvs[j1];
2267
+ uv.copyToArray(vertices, vo);
2268
+ vertices[vo + 2] = r;
2269
+ vertices[vo + 3] = g;
2270
+ vertices[vo + 4] = b;
2271
+ vertices[vo + 5] = a;
2272
+ }
2273
+ }
2274
+ return subChunk;
2275
+ };
2276
+ _proto._freeTextChunks = function _freeTextChunks() {
2277
+ var textChunks = this._textChunks;
2278
+ // @ts-ignore
2279
+ var charRenderInfoPool = this.engine._charRenderInfoPool;
2280
+ var manager = this._getChunkManager();
2281
+ for(var i = 0, n = textChunks.length; i < n; ++i){
2282
+ var textChunk = textChunks[i];
2283
+ var charRenderInfos = textChunk.charRenderInfos;
2284
+ for(var j = 0, m = charRenderInfos.length; j < m; ++j){
2285
+ charRenderInfoPool.return(charRenderInfos[j]);
2286
+ }
2287
+ charRenderInfos.length = 0;
2288
+ manager.freeSubChunk(textChunk.subChunk);
2289
+ textChunk.subChunk = null;
2290
+ textChunk.texture = null;
2291
+ }
2292
+ textChunks.length = 0;
2293
+ };
2294
+ _create_class(Text, [
2295
+ {
2296
+ key: "text",
2297
+ get: /**
2298
+ * Rendering string for the Text.
2299
+ */ function get() {
2300
+ return this._text;
2301
+ },
2302
+ set: function set(value) {
2303
+ value = value || "";
2304
+ if (this._text !== value) {
2305
+ this._text = value;
2306
+ this._setDirtyFlagTrue(25);
2307
+ }
2308
+ }
2309
+ },
2310
+ {
2311
+ key: "font",
2312
+ get: /**
2313
+ * The font of the Text.
2314
+ */ function get() {
2315
+ return this._font;
2316
+ },
2317
+ set: function set(value) {
2318
+ var lastFont = this._font;
2319
+ if (lastFont !== value) {
2320
+ lastFont && this._addResourceReferCount(lastFont, -1);
2321
+ value && this._addResourceReferCount(value, 1);
2322
+ this._font = value;
2323
+ this._setDirtyFlagTrue(29);
2324
+ }
2325
+ }
2326
+ },
2327
+ {
2328
+ key: "fontSize",
2329
+ get: /**
2330
+ * The font size of the Text.
2331
+ */ function get() {
2332
+ return this._fontSize;
2333
+ },
2334
+ set: function set(value) {
2335
+ if (this._fontSize !== value) {
2336
+ this._fontSize = value;
2337
+ this._setDirtyFlagTrue(29);
2338
+ }
2339
+ }
2340
+ },
2341
+ {
2342
+ key: "fontStyle",
2343
+ get: /**
2344
+ * The style of the font.
2345
+ */ function get() {
2346
+ return this._fontStyle;
2347
+ },
2348
+ set: function set(value) {
2349
+ if (this.fontStyle !== value) {
2350
+ this._fontStyle = value;
2351
+ this._setDirtyFlagTrue(29);
2352
+ }
2353
+ }
2354
+ },
2355
+ {
2356
+ key: "lineSpacing",
2357
+ get: /**
2358
+ * The space between two lines (in pixels).
2359
+ */ function get() {
2360
+ return this._lineSpacing;
2361
+ },
2362
+ set: function set(value) {
2363
+ if (this._lineSpacing !== value) {
2364
+ this._lineSpacing = value;
2365
+ this._setDirtyFlagTrue(25);
2366
+ }
2367
+ }
2368
+ },
2369
+ {
2370
+ key: "horizontalAlignment",
2371
+ get: /**
2372
+ * The horizontal alignment.
2373
+ */ function get() {
2374
+ return this._horizontalAlignment;
2375
+ },
2376
+ set: function set(value) {
2377
+ if (this._horizontalAlignment !== value) {
2378
+ this._horizontalAlignment = value;
2379
+ this._setDirtyFlagTrue(25);
2380
+ }
2381
+ }
2382
+ },
2383
+ {
2384
+ key: "verticalAlignment",
2385
+ get: /**
2386
+ * The vertical alignment.
2387
+ */ function get() {
2388
+ return this._verticalAlignment;
2389
+ },
2390
+ set: function set(value) {
2391
+ if (this._verticalAlignment !== value) {
2392
+ this._verticalAlignment = value;
2393
+ this._setDirtyFlagTrue(25);
2394
+ }
2395
+ }
2396
+ },
2397
+ {
2398
+ key: "enableWrapping",
2399
+ get: /**
2400
+ * Whether wrap text to next line when exceeds the width of the container.
2401
+ */ function get() {
2402
+ return this._enableWrapping;
2403
+ },
2404
+ set: function set(value) {
2405
+ if (this._enableWrapping !== value) {
2406
+ this._enableWrapping = value;
2407
+ this._setDirtyFlagTrue(25);
2408
+ }
2409
+ }
2410
+ },
2411
+ {
2412
+ key: "overflowMode",
2413
+ get: /**
2414
+ * The overflow mode.
2415
+ */ function get() {
2416
+ return this._overflowMode;
2417
+ },
2418
+ set: function set(value) {
2419
+ if (this._overflowMode !== value) {
2420
+ this._overflowMode = value;
2421
+ this._setDirtyFlagTrue(25);
2422
+ }
2423
+ }
2424
+ },
2425
+ {
2426
+ key: "maskLayer",
2427
+ get: /**
2428
+ * The mask layer the sprite renderer belongs to.
2429
+ */ function get() {
2430
+ return this._maskLayer;
2431
+ },
2432
+ set: function set(value) {
2433
+ this._maskLayer = value;
2434
+ }
2435
+ },
2436
+ {
2437
+ key: "bounds",
2438
+ get: /**
2439
+ * The bounding volume of the TextRenderer.
2440
+ */ function get() {
2441
+ if (this._isTextNoVisible()) {
2442
+ if (this._isContainDirtyFlag(RendererUpdateFlags.WorldVolume)) {
2443
+ var localBounds = this._localBounds;
2444
+ localBounds.min.set(0, 0, 0);
2445
+ localBounds.max.set(0, 0, 0);
2446
+ this._updateBounds(this._bounds);
2447
+ this._setDirtyFlagFalse(RendererUpdateFlags.WorldVolume);
2448
+ }
2449
+ return this._bounds;
2450
+ }
2451
+ this._isContainDirtyFlag(4) && this._resetSubFont();
2452
+ this._isContainDirtyFlag(8) && this._updateLocalData();
2453
+ this._isContainDirtyFlag(16) && this._updatePosition();
2454
+ this._isContainDirtyFlag(RendererUpdateFlags.WorldVolume) && this._updateBounds(this._bounds);
2455
+ this._setDirtyFlagFalse(29);
2456
+ return this._bounds;
2457
+ }
2458
+ }
2459
+ ]);
2460
+ return Text;
2461
+ }(UIRenderer);
2462
+ Text._textTextureProperty = ShaderProperty.getByName("renderElement_TextTexture");
2463
+ Text._worldPositions = [
2464
+ new Vector3(),
2465
+ new Vector3(),
2466
+ new Vector3(),
2467
+ new Vector3()
2468
+ ];
2469
+ Text._charRenderInfos = [];
2470
+ __decorate([
2471
+ ignoreClone
2472
+ ], Text.prototype, "_textChunks", void 0);
2473
+ __decorate([
2474
+ ignoreClone
2475
+ ], Text.prototype, "_subFont", void 0);
2476
+ __decorate([
2477
+ assignmentClone
2478
+ ], Text.prototype, "_text", void 0);
2479
+ __decorate([
2480
+ ignoreClone
2481
+ ], Text.prototype, "_localBounds", void 0);
2482
+ __decorate([
2483
+ assignmentClone
2484
+ ], Text.prototype, "_font", void 0);
2485
+ __decorate([
2486
+ assignmentClone
2487
+ ], Text.prototype, "_fontSize", void 0);
2488
+ __decorate([
2489
+ assignmentClone
2490
+ ], Text.prototype, "_fontStyle", void 0);
2491
+ __decorate([
2492
+ assignmentClone
2493
+ ], Text.prototype, "_lineSpacing", void 0);
2494
+ __decorate([
2495
+ assignmentClone
2496
+ ], Text.prototype, "_horizontalAlignment", void 0);
2497
+ __decorate([
2498
+ assignmentClone
2499
+ ], Text.prototype, "_verticalAlignment", void 0);
2500
+ __decorate([
2501
+ assignmentClone
2502
+ ], Text.prototype, "_enableWrapping", void 0);
2503
+ __decorate([
2504
+ assignmentClone
2505
+ ], Text.prototype, "_overflowMode", void 0);
2506
+ __decorate([
2507
+ ignoreClone
2508
+ ], Text.prototype, "_onTransformChanged", null);
2509
+ var TextChunk = function TextChunk() {
2510
+ this.charRenderInfos = new Array();
2511
+ };
2512
+
2513
+ /**
2514
+ * The transition behavior of UIInteractive.
2515
+ */ var Transition = /*#__PURE__*/ function() {
2516
+ function Transition() {
2517
+ this._duration = 0;
2518
+ this._countDown = 0;
2519
+ this._finalState = InteractiveState.Normal;
2520
+ }
2521
+ var _proto = Transition.prototype;
2522
+ _proto.destroy = function destroy() {
2523
+ var _this__interactive;
2524
+ (_this__interactive = this._interactive) == null ? void 0 : _this__interactive.removeTransition(this);
2525
+ this._target = null;
2526
+ };
2527
+ /**
2528
+ * @internal
2529
+ */ _proto._setState = function _setState(state, instant) {
2530
+ this._finalState = state;
2531
+ var value = this._getValueByState(state);
2532
+ if (instant) {
2533
+ this._countDown = 0;
2534
+ this._initialValue = this._finalValue = value;
2535
+ } else {
2536
+ this._countDown = this._duration;
2537
+ this._initialValue = this._getTargetValueCopy();
2538
+ this._finalValue = value;
2539
+ }
2540
+ this._updateValue();
2541
+ };
2542
+ /**
2543
+ * @internal
2544
+ */ _proto._onUpdate = function _onUpdate(delta) {
2545
+ if (this._countDown > 0) {
2546
+ this._countDown -= delta;
2547
+ this._updateValue();
2548
+ }
2549
+ };
2550
+ _proto._onStateValueDirty = function _onStateValueDirty(state, preValue, curValue) {
2551
+ // @ts-ignore
2552
+ _instanceof(preValue, ReferResource) && preValue._addReferCount(-1);
2553
+ // @ts-ignore
2554
+ _instanceof(curValue, ReferResource) && curValue._addReferCount(1);
2555
+ if (this._finalState === state) {
2556
+ this._finalValue = curValue;
2557
+ this._updateValue();
2558
+ }
2559
+ };
2560
+ _proto._updateValue = function _updateValue() {
2561
+ var _this__target;
2562
+ var weight = this._duration ? 1 - this._countDown / this._duration : 1;
2563
+ this._updateCurrentValue(this._initialValue, this._finalValue, weight);
2564
+ ((_this__target = this._target) == null ? void 0 : _this__target.enabled) && this._applyValue(this._currentValue);
2565
+ };
2566
+ _proto._getValueByState = function _getValueByState(state) {
2567
+ switch(state){
2568
+ case InteractiveState.Normal:
2569
+ return this.normal;
2570
+ case InteractiveState.Pressed:
2571
+ return this.pressed;
2572
+ case InteractiveState.Hover:
2573
+ return this.hover;
2574
+ case InteractiveState.Disable:
2575
+ return this.disabled;
2576
+ }
2577
+ };
2578
+ _create_class(Transition, [
2579
+ {
2580
+ key: "normal",
2581
+ get: /**
2582
+ * The normal state of the transition.
2583
+ */ function get() {
2584
+ return this._normal;
2585
+ },
2586
+ set: function set(value) {
2587
+ var preNormal = this._normal;
2588
+ if (preNormal !== value) {
2589
+ this._normal = value;
2590
+ this._onStateValueDirty(InteractiveState.Normal, preNormal, value);
2591
+ }
2592
+ }
2593
+ },
2594
+ {
2595
+ key: "pressed",
2596
+ get: /**
2597
+ * The pressed state of the transition.
2598
+ */ function get() {
2599
+ return this._pressed;
2600
+ },
2601
+ set: function set(value) {
2602
+ var prePressed = this._pressed;
2603
+ if (prePressed !== value) {
2604
+ this._pressed = value;
2605
+ this._onStateValueDirty(InteractiveState.Pressed, prePressed, value);
2606
+ }
2607
+ }
2608
+ },
2609
+ {
2610
+ key: "hover",
2611
+ get: /**
2612
+ * The hover state of the transition.
2613
+ */ function get() {
2614
+ return this._hover;
2615
+ },
2616
+ set: function set(value) {
2617
+ var preHover = this._hover;
2618
+ if (preHover !== value) {
2619
+ this._hover = value;
2620
+ this._onStateValueDirty(InteractiveState.Hover, preHover, value);
2621
+ }
2622
+ }
2623
+ },
2624
+ {
2625
+ key: "disabled",
2626
+ get: /**
2627
+ * The disabled state of the transition.
2628
+ */ function get() {
2629
+ return this._disabled;
2630
+ },
2631
+ set: function set(value) {
2632
+ var preDisabled = this._disabled;
2633
+ if (preDisabled !== value) {
2634
+ this._disabled = value;
2635
+ this._onStateValueDirty(InteractiveState.Disable, preDisabled, value);
2636
+ }
2637
+ }
2638
+ },
2639
+ {
2640
+ key: "target",
2641
+ get: /**
2642
+ * The target of the transition.
2643
+ */ function get() {
2644
+ return this._target;
2645
+ },
2646
+ set: function set(value) {
2647
+ if (this._target !== value) {
2648
+ this._target = value;
2649
+ (value == null ? void 0 : value.enabled) && this._applyValue(this._currentValue);
2650
+ }
2651
+ }
2652
+ },
2653
+ {
2654
+ key: "duration",
2655
+ get: /**
2656
+ * The duration of the transition.
2657
+ */ function get() {
2658
+ return this._duration;
2659
+ },
2660
+ set: function set(value) {
2661
+ if (value < 0) value = 0;
2662
+ var preDuration = this._duration;
2663
+ if (preDuration !== value) {
2664
+ this._duration = value;
2665
+ if (this._countDown > 0) {
2666
+ this._countDown = value * (1 - this._countDown / preDuration);
2667
+ this._updateValue();
2668
+ }
2669
+ }
2670
+ }
2671
+ }
2672
+ ]);
2673
+ return Transition;
2674
+ }();
2675
+
2676
+ /**
2677
+ * Color transition.
2678
+ */ var ColorTransition = /*#__PURE__*/ function(Transition) {
2679
+ _inherits(ColorTransition, Transition);
2680
+ function ColorTransition() {
2681
+ var _this;
2682
+ _this = Transition.call(this) || this, _this._color = new Color();
2683
+ _this._normal = new Color(1, 1, 1, 1);
2684
+ _this._hover = new Color(245 / 255, 245 / 255, 245 / 255, 1);
2685
+ _this._pressed = new Color(200 / 255, 200 / 255, 200 / 255, 1);
2686
+ _this._disabled = new Color(200 / 255, 200 / 255, 200 / 255, 1);
2687
+ _this._duration = 0.1;
2688
+ _this._currentValue = new Color();
2689
+ _this._onNormalValueChanged = _this._onNormalValueChanged.bind(_this);
2690
+ _this._onHoverValueChanged = _this._onHoverValueChanged.bind(_this);
2691
+ _this._onPressedValueChanged = _this._onPressedValueChanged.bind(_this);
2692
+ _this._onDisabledValueChanged = _this._onDisabledValueChanged.bind(_this);
2693
+ // @ts-ignore
2694
+ _this._normal._onValueChanged = _this._onNormalValueChanged;
2695
+ // @ts-ignore
2696
+ _this._hover._onValueChanged = _this._onHoverValueChanged;
2697
+ // @ts-ignore
2698
+ _this._pressed._onValueChanged = _this._onPressedValueChanged;
2699
+ // @ts-ignore
2700
+ _this._disabled._onValueChanged = _this._onDisabledValueChanged;
2701
+ return _this;
2702
+ }
2703
+ var _proto = ColorTransition.prototype;
2704
+ _proto._onNormalValueChanged = function _onNormalValueChanged() {
2705
+ this._finalState === InteractiveState.Normal && this._updateValue();
2706
+ };
2707
+ _proto._onHoverValueChanged = function _onHoverValueChanged() {
2708
+ this._finalState === InteractiveState.Hover && this._updateValue();
2709
+ };
2710
+ _proto._onPressedValueChanged = function _onPressedValueChanged() {
2711
+ this._finalState === InteractiveState.Pressed && this._updateValue();
2712
+ };
2713
+ _proto._onDisabledValueChanged = function _onDisabledValueChanged() {
2714
+ this._finalState === InteractiveState.Disable && this._updateValue();
2715
+ };
2716
+ _proto._getTargetValueCopy = function _getTargetValueCopy() {
2717
+ var _this__target;
2718
+ var color = this._color;
2719
+ color.copyFrom(((_this__target = this._target) == null ? void 0 : _this__target.color) || this._normal);
2720
+ return color;
2721
+ };
2722
+ _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
2723
+ if (weight >= 1) {
2724
+ this._currentValue.copyFrom(destValue);
2725
+ } else {
2726
+ Color.lerp(srcValue, destValue, weight, this._currentValue);
2727
+ }
2728
+ };
2729
+ _proto._applyValue = function _applyValue(value) {
2730
+ this._target.color = value;
2731
+ };
2732
+ return ColorTransition;
2733
+ }(Transition);
2734
+
2735
+ /**
2736
+ * Scale transition.
2737
+ */ var ScaleTransition = /*#__PURE__*/ function(Transition) {
2738
+ _inherits(ScaleTransition, Transition);
2739
+ function ScaleTransition() {
2740
+ var _this;
2741
+ _this = Transition.call(this) || this;
2742
+ _this._normal = 1;
2743
+ _this._hover = 1;
2744
+ _this._pressed = 1.2;
2745
+ _this._disabled = 1;
2746
+ _this._duration = 0.1;
2747
+ return _this;
2748
+ }
2749
+ var _proto = ScaleTransition.prototype;
2750
+ _proto._getTargetValueCopy = function _getTargetValueCopy() {
2751
+ var _this__target;
2752
+ return ((_this__target = this._target) == null ? void 0 : _this__target.entity.transform.scale.x) || this._normal;
2753
+ };
2754
+ _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
2755
+ this._currentValue = weight >= 1 ? destValue : (destValue - srcValue) * weight + srcValue;
2756
+ };
2757
+ _proto._applyValue = function _applyValue(value) {
2758
+ this._target.entity.transform.setScale(value, value, value);
2759
+ };
2760
+ return ScaleTransition;
2761
+ }(Transition);
2762
+
2763
+ /**
2764
+ * Sprite transition.
2765
+ */ var SpriteTransition = /*#__PURE__*/ function(Transition) {
2766
+ _inherits(SpriteTransition, Transition);
2767
+ function SpriteTransition() {
2768
+ return Transition.apply(this, arguments) || this;
2769
+ }
2770
+ var _proto = SpriteTransition.prototype;
2771
+ /**
2772
+ * @internal
2773
+ */ _proto.destroy = function destroy() {
2774
+ Transition.prototype.destroy.call(this);
2775
+ if (this._normal) {
2776
+ // @ts-ignore
2777
+ this._normal._addReferCount(-1);
2778
+ this._normal = null;
2779
+ }
2780
+ if (this._hover) {
2781
+ // @ts-ignore
2782
+ this._hover._addReferCount(-1);
2783
+ this._hover = null;
2784
+ }
2785
+ if (this._pressed) {
2786
+ // @ts-ignore
2787
+ this._pressed._addReferCount(-1);
2788
+ this._pressed = null;
2789
+ }
2790
+ if (this._disabled) {
2791
+ // @ts-ignore
2792
+ this._disabled._addReferCount(-1);
2793
+ this._disabled = null;
2794
+ }
2795
+ this._initialValue = this._currentValue = this._finalValue = null;
2796
+ this._target = null;
2797
+ };
2798
+ _proto._getTargetValueCopy = function _getTargetValueCopy() {
2799
+ var _this__target;
2800
+ return (_this__target = this._target) == null ? void 0 : _this__target.sprite;
2801
+ };
2802
+ _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
2803
+ this._currentValue = weight >= 1 ? destValue : srcValue;
2804
+ };
2805
+ _proto._applyValue = function _applyValue(value) {
2806
+ this._target.sprite = value || this._normal;
2807
+ };
2808
+ return SpriteTransition;
2809
+ }(Transition);
2810
+
2811
+ /**
2812
+ * @internal
2813
+ */ var UIHitResult = function UIHitResult() {
2814
+ this.entity = null;
2815
+ this.distance = 0;
2816
+ this.point = new Vector3();
2817
+ this.normal = new Vector3();
2818
+ this.component = null;
2819
+ };
2820
+
2821
+ var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
2822
+ _inherits(UIPointerEventEmitter, PointerEventEmitter1);
2823
+ function UIPointerEventEmitter() {
2824
+ return PointerEventEmitter1.apply(this, arguments) || this;
2825
+ }
2826
+ var _proto = UIPointerEventEmitter.prototype;
2827
+ _proto._init = function _init() {
2828
+ this._hitResult = new UIHitResult();
2829
+ };
2830
+ _proto.processRaycast = function processRaycast(scenes, pointer) {
2831
+ var ray = PointerEventEmitter._tempRay;
2832
+ var hitResult = this._hitResult;
2833
+ var position = pointer.position;
2834
+ var x = position.x, y = position.y;
2835
+ for(var i = scenes.length - 1; i >= 0; i--){
2836
+ var scene = scenes[i];
2837
+ if (!scene.isActive || scene.destroyed) continue;
2838
+ // @ts-ignore
2839
+ var componentsManager = scene._componentsManager;
2840
+ /** Overlay Canvas */ var canvasElements = componentsManager._overlayCanvases;
2841
+ ray.origin.set(position.x, position.y, 1);
2842
+ ray.direction.set(0, 0, -1);
2843
+ for(var j = canvasElements.length - 1; j >= 0; j--){
2844
+ if (canvasElements.get(j).raycast(ray, hitResult)) {
2845
+ this._updateRaycast(hitResult.component, pointer);
2846
+ return;
2847
+ }
2848
+ }
2849
+ var cameras = componentsManager._activeCameras;
2850
+ for(var j1 = cameras.length - 1; j1 >= 0; j1--){
2851
+ var camera = cameras.get(j1);
2852
+ if (camera.renderTarget) continue;
2853
+ var pixelViewport = camera.pixelViewport;
2854
+ if (x < pixelViewport.x || y < pixelViewport.y || x > pixelViewport.x + pixelViewport.width || y > pixelViewport.y + pixelViewport.height) {
2855
+ continue;
2856
+ }
2857
+ camera.screenPointToRay(pointer.position, ray);
2858
+ /** Other canvases */ var cameraPosition = camera.entity.transform.position;
2859
+ /** Sort by rendering order */ canvasElements = componentsManager._canvases;
2860
+ for(var k = 0, n = canvasElements.length; k < n; k++){
2861
+ canvasElements.get(k)._updateSortDistance(cameraPosition);
2862
+ }
2863
+ canvasElements.sort(function(a, b) {
2864
+ return a.sortOrder - b.sortOrder || a._sortDistance - b._sortDistance;
2865
+ });
2866
+ for(var k1 = 0, n1 = canvasElements.length; k1 < n1; k1++){
2867
+ canvasElements.get(k1)._canvasIndex = k1;
2868
+ }
2869
+ var farClipPlane = camera.farClipPlane;
2870
+ /** Post-rendering first detection */ for(var k2 = 0, n2 = canvasElements.length; k2 < n2; k2++){
2871
+ var canvas = canvasElements.get(k2);
2872
+ if (canvas.renderCamera !== camera) continue;
2873
+ if (canvas.raycast(ray, hitResult, farClipPlane)) {
2874
+ this._updateRaycast(hitResult.component, pointer);
2875
+ return;
2876
+ }
2877
+ }
2878
+ if (camera.clearFlags & CameraClearFlags.Color) {
2879
+ this._updateRaycast(null);
2880
+ return;
2881
+ }
2882
+ }
2883
+ }
2884
+ };
2885
+ _proto.processDrag = function processDrag(pointer) {
2886
+ if (this._draggedElement) {
2887
+ this._bubble(this._composedPath(this._draggedElement, UIPointerEventEmitter._path0), pointer, this._fireDrag);
2888
+ }
2889
+ };
2890
+ _proto.processDown = function processDown(pointer) {
2891
+ var element = this._pressedElement = this._draggedElement = this._enteredElement;
2892
+ if (element) {
2893
+ var path = this._composedPath(element, UIPointerEventEmitter._path0);
2894
+ this._bubble(path, pointer, this._fireDown);
2895
+ this._bubble(path, pointer, this._fireBeginDrag);
2896
+ }
2897
+ };
2898
+ _proto.processUp = function processUp(pointer) {
2899
+ var liftedPath = UIPointerEventEmitter._path0;
2900
+ var enteredElement = this._enteredElement;
2901
+ if (enteredElement) {
2902
+ this._composedPath(enteredElement, liftedPath);
2903
+ this._bubble(liftedPath, pointer, this._fireUp);
2904
+ if (this._pressedElement) {
2905
+ var pressedPath = this._composedPath(this._pressedElement, UIPointerEventEmitter._path1);
2906
+ var enterLength = liftedPath.length;
2907
+ var pressLength = pressedPath.length;
2908
+ var minLength = Math.min(enterLength, pressLength);
2909
+ var i = 0;
2910
+ for(; i < minLength; i++){
2911
+ if (liftedPath[enterLength - 1 - i] !== pressedPath[pressLength - 1 - i]) {
2912
+ break;
2913
+ }
2914
+ }
2915
+ var targetIndex = enterLength - i;
2916
+ var eventData = this._createEventData(pointer);
2917
+ for(var j = targetIndex; j < enterLength; j++){
2918
+ this._fireClick(liftedPath[j], eventData);
2919
+ }
2920
+ this._pressedElement = null;
2921
+ }
2922
+ }
2923
+ if (this._draggedElement) {
2924
+ this._bubble(this._composedPath(this._draggedElement, UIPointerEventEmitter._path1), pointer, this._fireEndDrag);
2925
+ this._draggedElement = null;
2926
+ }
2927
+ if (enteredElement) {
2928
+ this._bubble(liftedPath, pointer, this._fireDrop);
2929
+ }
2930
+ };
2931
+ _proto.processLeave = function processLeave(pointer) {
2932
+ var path = UIPointerEventEmitter._path0;
2933
+ if (this._enteredElement) {
2934
+ this._bubble(this._composedPath(this._enteredElement, path), pointer, this._fireExit);
2935
+ this._enteredElement = null;
2936
+ }
2937
+ if (this._draggedElement) {
2938
+ this._bubble(this._composedPath(this._draggedElement, path), pointer, this._fireEndDrag);
2939
+ this._draggedElement = null;
2940
+ }
2941
+ this._pressedElement = null;
2942
+ };
2943
+ _proto.dispose = function dispose() {
2944
+ this._enteredElement = this._pressedElement = this._draggedElement = null;
2945
+ };
2946
+ _proto._updateRaycast = function _updateRaycast(element, pointer) {
2947
+ if (pointer === void 0) pointer = null;
2948
+ var enteredElement = this._enteredElement;
2949
+ if (element !== enteredElement) {
2950
+ var prePath = this._composedPath(enteredElement, UIPointerEventEmitter._path0);
2951
+ var curPath = this._composedPath(element, UIPointerEventEmitter._path1);
2952
+ var preLength = prePath.length;
2953
+ var curLength = curPath.length;
2954
+ var minLength = Math.min(preLength, curLength);
2955
+ var i = 0;
2956
+ for(; i < minLength; i++){
2957
+ if (prePath[preLength - i - 1] !== curPath[curLength - i - 1]) {
2958
+ break;
2959
+ }
2960
+ }
2961
+ var eventData = this._createEventData(pointer);
2962
+ for(var j = 0, n = preLength - i; j < n; j++){
2963
+ this._fireExit(prePath[j], eventData);
2964
+ }
2965
+ for(var j1 = 0, n1 = curLength - i; j1 < n1; j1++){
2966
+ this._fireEnter(curPath[j1], eventData);
2967
+ }
2968
+ this._enteredElement = element;
2969
+ }
2970
+ };
2971
+ _proto._composedPath = function _composedPath(element, path) {
2972
+ if (!element) {
2973
+ path.length = 0;
2974
+ return path;
2975
+ }
2976
+ var entity = path[0] = element.entity;
2977
+ var i = 1;
2978
+ var rootEntity = element._getRootCanvas().entity;
2979
+ for(; i < UIPointerEventEmitter._MAX_PATH_DEPTH && !!entity && entity !== rootEntity; i++){
2980
+ entity = path[i] = entity.parent;
2981
+ }
2982
+ path.length = i;
2983
+ return path;
2984
+ };
2985
+ _proto._bubble = function _bubble(path, pointer, fireEvent) {
2986
+ var length = path.length;
2987
+ if (length <= 0) return;
2988
+ var eventData = this._createEventData(pointer);
2989
+ for(var i = 0; i < length; i++){
2990
+ fireEvent(path[i], eventData);
2991
+ }
2992
+ };
2993
+ return UIPointerEventEmitter;
2994
+ }(PointerEventEmitter);
2995
+ UIPointerEventEmitter._MAX_PATH_DEPTH = 2048;
2996
+ UIPointerEventEmitter._path0 = [];
2997
+ UIPointerEventEmitter._path1 = [];
2998
+ UIPointerEventEmitter = __decorate([
2999
+ registerPointerEventEmitter()
3000
+ ], UIPointerEventEmitter);
3001
+
3002
+ var EngineExtension = /*#__PURE__*/ function() {
3003
+ function EngineExtension() {}
3004
+ var _proto = EngineExtension.prototype;
3005
+ _proto._getUIDefaultMaterial = function _getUIDefaultMaterial() {
3006
+ if (!this._uiDefaultMaterial) {
3007
+ var _Shader_find;
3008
+ var shader = (_Shader_find = Shader.find("ui")) != null ? _Shader_find : Shader.create("ui", [
3009
+ new ShaderPass("Forward", uiDefaultVs, uiDefaultFs, {
3010
+ pipelineStage: PipelineStage.Forward
3011
+ })
3012
+ ]);
3013
+ // @ts-ignore
3014
+ var material = new Material(this, shader);
3015
+ var renderState = material.renderState;
3016
+ var target = renderState.blendState.targetBlendState;
3017
+ target.enabled = true;
3018
+ target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
3019
+ target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
3020
+ target.sourceAlphaBlendFactor = BlendFactor.One;
3021
+ target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
3022
+ target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
3023
+ renderState.depthState.writeEnabled = false;
3024
+ renderState.rasterState.cullMode = CullMode.Off;
3025
+ renderState.renderQueueType = RenderQueueType.Transparent;
3026
+ material.isGCIgnored = true;
3027
+ this._uiDefaultMaterial = material;
3028
+ }
3029
+ return this._uiDefaultMaterial;
3030
+ };
3031
+ return EngineExtension;
3032
+ }();
3033
+ var EntityExtension = /*#__PURE__*/ function() {
3034
+ function EntityExtension() {
3035
+ this._uiHierarchyVersion = 0;
3036
+ }
3037
+ var _proto = EntityExtension.prototype;
3038
+ _proto._updateUIHierarchyVersion = function _updateUIHierarchyVersion(version) {
3039
+ if (this._uiHierarchyVersion !== version) {
3040
+ var // @ts-ignore
3041
+ _this_parent;
3042
+ this._uiHierarchyVersion = version;
3043
+ (_this_parent = this.parent) == null ? void 0 : _this_parent._updateUIHierarchyVersion(version);
3044
+ }
3045
+ };
3046
+ return EntityExtension;
3047
+ }();
3048
+ function ApplyMixins(derivedCtor, baseCtors) {
3049
+ baseCtors.forEach(function(baseCtor) {
3050
+ Object.getOwnPropertyNames(baseCtor.prototype).forEach(function(name) {
3051
+ Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
3052
+ });
3053
+ });
3054
+ }
3055
+ ApplyMixins(Engine, [
3056
+ EngineExtension
3057
+ ]);
3058
+ ApplyMixins(Entity, [
3059
+ EntityExtension
3060
+ ]);
3061
+ ReflectionParser.registerCustomParseComponent("Text", /*#__PURE__*/ _async_to_generator(function(instance, item) {
3062
+ var props;
3063
+ return __generator(this, function(_state) {
3064
+ props = item.props;
3065
+ if (!props.font) {
3066
+ // @ts-ignore
3067
+ instance.font = Font.createFromOS(instance.engine, props.fontFamily || "Arial");
3068
+ }
3069
+ return [
3070
+ 2,
3071
+ instance
3072
+ ];
3073
+ });
3074
+ }));
3075
+
3076
+ export { Button, CanvasRenderMode, ColorTransition, EngineExtension, EntityExtension, Image, ResolutionAdaptationMode, ScaleTransition, SpriteTransition, Text, Transition, UICanvas, UIGroup, UIPointerEventEmitter, UIRenderer, UITransform };
3077
+ //# sourceMappingURL=module.js.map