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