@galacean/effects-threejs 2.10.0-alpha.2 → 2.10.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime threejs plugin for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.10.0-alpha.2
6
+ * Version: v2.10.0-alpha.3
7
7
  */
8
8
 
9
9
  'use strict';
@@ -7083,6 +7083,11 @@ function _create_class(Constructor, protoProps, staticProps) {
7083
7083
  // OVERRIDE
7084
7084
  };
7085
7085
  /**
7086
+ * Called when the owning item's sibling order changes.
7087
+ */ _proto.onOrderInParentChanged = function onOrderInParentChanged() {
7088
+ // OVERRIDE
7089
+ };
7090
+ /**
7086
7091
  * @internal
7087
7092
  */ _proto.enable = function enable() {
7088
7093
  if (this.item.composition) {
@@ -14040,6 +14045,7 @@ var seed$7 = 1;
14040
14045
  quat: new Quaternion(0, 0, 0, 1),
14041
14046
  scale: new Vector3(1, 1, 1)
14042
14047
  };
14048
+ this.eventEmitter = new EventEmitter();
14043
14049
  this.name = "transform_" + seed$7++;
14044
14050
  if (props) {
14045
14051
  this.setTransform(props);
@@ -14052,6 +14058,12 @@ var seed$7 = 1;
14052
14058
  }
14053
14059
  }
14054
14060
  var _proto = Transform.prototype;
14061
+ _proto.on = function on(eventName, listener, options) {
14062
+ this.eventEmitter.on(eventName, listener, options);
14063
+ };
14064
+ _proto.off = function off(eventName, listener) {
14065
+ this.eventEmitter.off(eventName, listener);
14066
+ };
14055
14067
  /**
14056
14068
  * 父 transform 切换时的 hook。子类可重写以接管订阅 / 解算等逻辑
14057
14069
  * @param oldParent - 切换前的父 transform(若没有则为 null)
@@ -14470,6 +14482,7 @@ var seed$7 = 1;
14470
14482
  this.children.forEach(function(c) {
14471
14483
  c.worldMatrixDirty = true;
14472
14484
  });
14485
+ this.eventEmitter.emit("changed", this);
14473
14486
  };
14474
14487
  /**
14475
14488
  * 转换右手坐标系左手螺旋对应的四元数到对应的旋转角
@@ -14488,14 +14501,16 @@ var seed$7 = 1;
14488
14501
  return this.parent;
14489
14502
  },
14490
14503
  set: function set(transform) {
14491
- if (!transform || this.parent === transform || this === transform) {
14504
+ if (this.parent === transform || this === transform) {
14492
14505
  return;
14493
14506
  }
14494
14507
  var oldParent = this.parent;
14495
14508
  if (this.parent) {
14496
14509
  this.parent.removeChild(this);
14497
14510
  }
14498
- transform.addChild(this);
14511
+ if (transform) {
14512
+ transform.addChild(this);
14513
+ }
14499
14514
  this.parent = transform;
14500
14515
  this.worldMatrixDirty = true;
14501
14516
  this.onParentTransformChanged(oldParent, transform);
@@ -14678,7 +14693,7 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
14678
14693
  return results;
14679
14694
  };
14680
14695
  _proto.setParent = function setParent(vfxItem) {
14681
- if (vfxItem === this && !vfxItem) {
14696
+ if (vfxItem === this || this.parent === vfxItem) {
14682
14697
  return;
14683
14698
  }
14684
14699
  if (this.parent) {
@@ -15065,6 +15080,12 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
15065
15080
  child.onParentChanged();
15066
15081
  }
15067
15082
  };
15083
+ _proto.onOrderInParentChanged = function onOrderInParentChanged() {
15084
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
15085
+ var component = _step.value;
15086
+ component.onOrderInParentChanged();
15087
+ }
15088
+ };
15068
15089
  /**
15069
15090
  * @internal
15070
15091
  */ _proto.setRendererComponentOrder = function setRendererComponentOrder(renderOrder) {
@@ -15149,15 +15170,16 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
15149
15170
  */ _proto.dispose = function dispose() {
15150
15171
  if (this.composition) {
15151
15172
  this.composition.destroyItem(this);
15152
- // component 调用 dispose() 会将自身从 this.components 数组删除,slice() 避免迭代错误
15153
- for(var _iterator = _create_for_of_iterator_helper_loose(this.components.slice()), _step; !(_step = _iterator()).done;){
15154
- var component = _step.value;
15155
- component.dispose();
15156
- }
15157
- this.components = [];
15158
- this._composition = null;
15159
- this.transform.setValid(false);
15160
15173
  }
15174
+ // component.dispose() removes itself from this.components. Use a snapshot
15175
+ // so Engine.root components are also disposed even without a Composition.
15176
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.components.slice()), _step; !(_step = _iterator()).done;){
15177
+ var component = _step.value;
15178
+ component.dispose();
15179
+ }
15180
+ this.components = [];
15181
+ this._composition = null;
15182
+ this.transform.setValid(false);
15161
15183
  this.resetChildrenParent();
15162
15184
  EffectsObject.prototype.dispose.call(this);
15163
15185
  };
@@ -15353,6 +15375,33 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
15353
15375
  this.setRendererComponentOrder(value);
15354
15376
  }
15355
15377
  },
15378
+ {
15379
+ key: "orderInParent",
15380
+ get: /** Zero-based sibling order within the parent item. */ function get() {
15381
+ var _this_parent;
15382
+ var _this_parent_children_indexOf;
15383
+ return (_this_parent_children_indexOf = (_this_parent = this.parent) == null ? void 0 : _this_parent.children.indexOf(this)) != null ? _this_parent_children_indexOf : -1;
15384
+ },
15385
+ set: function set(value) {
15386
+ var _this_parent;
15387
+ var siblings = (_this_parent = this.parent) == null ? void 0 : _this_parent.children;
15388
+ var _siblings_indexOf;
15389
+ var oldIndex = (_siblings_indexOf = siblings == null ? void 0 : siblings.indexOf(this)) != null ? _siblings_indexOf : -1;
15390
+ if (!siblings || oldIndex === -1) {
15391
+ return;
15392
+ }
15393
+ var newIndex = Math.max(0, Math.min(Math.trunc(value), siblings.length - 1));
15394
+ if (oldIndex === newIndex) {
15395
+ return;
15396
+ }
15397
+ siblings.splice(oldIndex, 1);
15398
+ siblings.splice(newIndex, 0, this);
15399
+ for(var _iterator = _create_for_of_iterator_helper_loose(siblings), _step; !(_step = _iterator()).done;){
15400
+ var sibling = _step.value;
15401
+ sibling.onOrderInParentChanged();
15402
+ }
15403
+ }
15404
+ },
15356
15405
  {
15357
15406
  key: "isActive",
15358
15407
  get: /**
@@ -15609,35 +15658,35 @@ function vecMulCombine(out, a, b) {
15609
15658
  }
15610
15659
  return out;
15611
15660
  }
15612
- var _obj$6;
15613
- var particleOriginTranslateMap$1 = (_obj$6 = {}, _obj$6[ParticleOrigin.PARTICLE_ORIGIN_CENTER] = [
15661
+ var _obj$7;
15662
+ var particleOriginTranslateMap$1 = (_obj$7 = {}, _obj$7[ParticleOrigin.PARTICLE_ORIGIN_CENTER] = [
15614
15663
  0,
15615
15664
  0
15616
- ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_CENTER_BOTTOM] = [
15665
+ ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_CENTER_BOTTOM] = [
15617
15666
  0,
15618
15667
  -0.5
15619
- ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_CENTER_TOP] = [
15668
+ ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_CENTER_TOP] = [
15620
15669
  0,
15621
15670
  0.5
15622
- ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_LEFT_TOP] = [
15671
+ ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_LEFT_TOP] = [
15623
15672
  -0.5,
15624
15673
  0.5
15625
- ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_LEFT_CENTER] = [
15674
+ ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_LEFT_CENTER] = [
15626
15675
  -0.5,
15627
15676
  0
15628
- ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_LEFT_BOTTOM] = [
15677
+ ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_LEFT_BOTTOM] = [
15629
15678
  -0.5,
15630
15679
  -0.5
15631
- ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_CENTER] = [
15680
+ ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_CENTER] = [
15632
15681
  0.5,
15633
15682
  0
15634
- ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_BOTTOM] = [
15683
+ ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_BOTTOM] = [
15635
15684
  0.5,
15636
15685
  -0.5
15637
- ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_TOP] = [
15686
+ ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_TOP] = [
15638
15687
  0.5,
15639
15688
  0.5
15640
- ], _obj$6);
15689
+ ], _obj$7);
15641
15690
  function nearestPowerOfTwo(value) {
15642
15691
  return Math.pow(2, Math.round(Math.log(value) / Math.LN2));
15643
15692
  }
@@ -17375,27 +17424,27 @@ function oldBezierKeyFramesToNew(props) {
17375
17424
  * 对象引用阶梯曲线(spec ValueType.REFERENCE_CURVE)。
17376
17425
  * props 为 [[time, value], ...],value 为已解析的对象引用实例。
17377
17426
  */ var REFERENCE_CURVE = 28;
17378
- var _obj$5;
17379
- var map$1 = (_obj$5 = {}, _obj$5[ValueType.RANDOM] = function(props) {
17427
+ var _obj$6;
17428
+ var map$1 = (_obj$6 = {}, _obj$6[ValueType.RANDOM] = function(props) {
17380
17429
  if (_instanceof1(props[0], Array)) {
17381
17430
  return new RandomVectorValue(props);
17382
17431
  }
17383
17432
  return new RandomValue(props);
17384
- }, _obj$5[ValueType.CONSTANT] = function(props) {
17433
+ }, _obj$6[ValueType.CONSTANT] = function(props) {
17385
17434
  return new StaticValue(props);
17386
- }, _obj$5[ValueType.CONSTANT_VEC2] = function(props) {
17435
+ }, _obj$6[ValueType.CONSTANT_VEC2] = function(props) {
17387
17436
  return new StaticValue(props);
17388
- }, _obj$5[ValueType.CONSTANT_VEC3] = function(props) {
17437
+ }, _obj$6[ValueType.CONSTANT_VEC3] = function(props) {
17389
17438
  return new StaticValue(props);
17390
- }, _obj$5[ValueType.CONSTANT_VEC4] = function(props) {
17439
+ }, _obj$6[ValueType.CONSTANT_VEC4] = function(props) {
17391
17440
  return new StaticValue(props);
17392
- }, _obj$5[ValueType.RGBA_COLOR] = function(props) {
17441
+ }, _obj$6[ValueType.RGBA_COLOR] = function(props) {
17393
17442
  return new StaticValue(props);
17394
- }, _obj$5[ValueType.COLORS] = function(props) {
17443
+ }, _obj$6[ValueType.COLORS] = function(props) {
17395
17444
  return new RandomSetValue(props.map(function(c) {
17396
17445
  return colorToArr$1(c, false);
17397
17446
  }));
17398
- }, _obj$5[ValueType.LINE] = function(props) {
17447
+ }, _obj$6[ValueType.LINE] = function(props) {
17399
17448
  if (props.length === 2 && props[0][0] === 0 && props[1][0] === 1) {
17400
17449
  return new LinearValue([
17401
17450
  props[0][1],
@@ -17403,38 +17452,38 @@ var map$1 = (_obj$5 = {}, _obj$5[ValueType.RANDOM] = function(props) {
17403
17452
  ]);
17404
17453
  }
17405
17454
  return new LineSegments(props);
17406
- }, _obj$5[ValueType.GRADIENT_COLOR] = function(props) {
17455
+ }, _obj$6[ValueType.GRADIENT_COLOR] = function(props) {
17407
17456
  return new GradientValue(props);
17408
- }, _obj$5[ValueType.LINEAR_PATH] = function(pros) {
17457
+ }, _obj$6[ValueType.LINEAR_PATH] = function(pros) {
17409
17458
  return new PathSegments(pros);
17410
- }, _obj$5[ValueType.BEZIER_CURVE] = function(props) {
17459
+ }, _obj$6[ValueType.BEZIER_CURVE] = function(props) {
17411
17460
  if (props.length === 1) {
17412
17461
  return new StaticValue(props[0][1][1]);
17413
17462
  }
17414
17463
  return new BezierCurve(props);
17415
- }, _obj$5[ValueType.BEZIER_CURVE_PATH] = function(props) {
17464
+ }, _obj$6[ValueType.BEZIER_CURVE_PATH] = function(props) {
17416
17465
  if (props[0].length === 1) {
17417
17466
  return new StaticValue(_construct(Vector3, [].concat(props[1][0])));
17418
17467
  }
17419
17468
  return new BezierCurvePath(props);
17420
- }, _obj$5[ValueType.BEZIER_CURVE_QUAT] = function(props) {
17469
+ }, _obj$6[ValueType.BEZIER_CURVE_QUAT] = function(props) {
17421
17470
  if (props[0].length === 1) {
17422
17471
  return new StaticValue(_construct(Quaternion, [].concat(props[1][0])));
17423
17472
  }
17424
17473
  return new BezierCurveQuat(props);
17425
- }, _obj$5[ValueType.COLOR_CURVE] = function(props) {
17474
+ }, _obj$6[ValueType.COLOR_CURVE] = function(props) {
17426
17475
  return new ColorCurve(props);
17427
- }, _obj$5[ValueType.VECTOR4_CURVE] = function(props) {
17476
+ }, _obj$6[ValueType.VECTOR4_CURVE] = function(props) {
17428
17477
  return new Vector4Curve(props);
17429
- }, _obj$5[ValueType.VECTOR2_CURVE] = function(props) {
17478
+ }, _obj$6[ValueType.VECTOR2_CURVE] = function(props) {
17430
17479
  return new Vector2Curve(props);
17431
17480
  }, // TODO: add spec
17432
- _obj$5[VECTOR3_CURVE] = function(props) {
17481
+ _obj$6[VECTOR3_CURVE] = function(props) {
17433
17482
  return new Vector3Curve(props);
17434
17483
  }, // 对象引用阶梯曲线(不插值):props.data 为 [time, value][],value 已解析为 EffectsObject
17435
- _obj$5[REFERENCE_CURVE] = function(props) {
17484
+ _obj$6[REFERENCE_CURVE] = function(props) {
17436
17485
  return new ReferenceCurve(props);
17437
- }, _obj$5);
17486
+ }, _obj$6);
17438
17487
  function createValueGetter(args) {
17439
17488
  if (!args || !isNaN(+args)) {
17440
17489
  return new StaticValue(args || 0);
@@ -20951,20 +21000,24 @@ var geometryId = 1;
20951
21000
  var vertexArrayObjects = this.vertexArrayObjects;
20952
21001
  var engine = this.engine;
20953
21002
  if (!vertexArrayObjects || !supportsVertexArrayObjects(engine)) {
20954
- engine.bindBuffers(this.vertexBuffers, this.indexBuffer, shader);
21003
+ var _this_indexBuffer;
21004
+ engine.bindBuffers(this.vertexBuffers, (_this_indexBuffer = this.indexBuffer) != null ? _this_indexBuffer : null, shader);
20955
21005
  return;
20956
21006
  }
20957
21007
  var vertexArrayObject = vertexArrayObjects[shader.key];
20958
21008
  if (!vertexArrayObject) {
20959
- vertexArrayObject = engine.recordVertexArrayObject(this.vertexBuffers, this.indexBuffer, shader);
21009
+ var _this_indexBuffer1;
21010
+ vertexArrayObject = engine.recordVertexArrayObject(this.vertexBuffers, (_this_indexBuffer1 = this.indexBuffer) != null ? _this_indexBuffer1 : null, shader);
20960
21011
  if (vertexArrayObject) {
20961
21012
  vertexArrayObjects[shader.key] = vertexArrayObject;
20962
21013
  }
20963
21014
  }
20964
21015
  if (vertexArrayObject) {
20965
- engine.bindVertexArrayObject(vertexArrayObject, this.indexBuffer);
21016
+ var _this_indexBuffer2;
21017
+ engine.bindVertexArrayObject(vertexArrayObject, (_this_indexBuffer2 = this.indexBuffer) != null ? _this_indexBuffer2 : null);
20966
21018
  } else {
20967
- engine.bindBuffers(this.vertexBuffers, this.indexBuffer, shader);
21019
+ var _this_indexBuffer3;
21020
+ engine.bindBuffers(this.vertexBuffers, (_this_indexBuffer3 = this.indexBuffer) != null ? _this_indexBuffer3 : null, shader);
20968
21021
  }
20969
21022
  };
20970
21023
  _proto.releaseVertexArrayObject = function releaseVertexArrayObject(key) {
@@ -21371,8 +21424,8 @@ var vertexBufferSemanticMap = {
21371
21424
  TANGENT_BS2: "aTargetTangent2",
21372
21425
  TANGENT_BS3: "aTargetTangent3"
21373
21426
  };
21374
- var _obj$4;
21375
- var BYTES_TYPE_MAP = (_obj$4 = {}, _obj$4[exports.BufferDataType.Float] = 4, _obj$4[exports.BufferDataType.Int] = 4, _obj$4[exports.BufferDataType.UnsignedInt] = 4, _obj$4[exports.BufferDataType.Short] = 2, _obj$4[exports.BufferDataType.UnsignedShort] = 2, _obj$4[exports.BufferDataType.Byte] = 1, _obj$4[exports.BufferDataType.UnsignedByte] = 1, _obj$4);
21427
+ var _obj$5;
21428
+ var BYTES_TYPE_MAP = (_obj$5 = {}, _obj$5[exports.BufferDataType.Float] = 4, _obj$5[exports.BufferDataType.Int] = 4, _obj$5[exports.BufferDataType.UnsignedInt] = 4, _obj$5[exports.BufferDataType.Short] = 2, _obj$5[exports.BufferDataType.UnsignedShort] = 2, _obj$5[exports.BufferDataType.Byte] = 1, _obj$5[exports.BufferDataType.UnsignedByte] = 1, _obj$5);
21376
21429
  function generateEmptyTypedArray(type) {
21377
21430
  return createTypedArray(type, 0);
21378
21431
  }
@@ -22382,7 +22435,7 @@ var Renderer = /*#__PURE__*/ function() {
22382
22435
  }
22383
22436
  };
22384
22437
  _proto.setViewport = function setViewport(x, y, width, height) {
22385
- this.engine.viewport(x, y, width, height);
22438
+ this.engine.setViewport(x, y, width, height);
22386
22439
  };
22387
22440
  _proto.clear = function clear(action) {
22388
22441
  this.engine.clear(action);
@@ -22445,7 +22498,40 @@ var Renderer = /*#__PURE__*/ function() {
22445
22498
  };
22446
22499
  _proto.drawGeometry = function drawGeometry(geometry, matrix, material, subMeshIndex) {
22447
22500
  if (subMeshIndex === void 0) subMeshIndex = 0;
22448
- this.engine.drawGeometry(geometry, matrix, material, subMeshIndex);
22501
+ if (!geometry || !material) {
22502
+ return;
22503
+ }
22504
+ material.initialize();
22505
+ geometry.initialize();
22506
+ geometry.flush();
22507
+ material.setMatrix("effects_ObjectToWorld", matrix);
22508
+ try {
22509
+ material.use(this, this.renderingData.currentFrame.globalUniforms);
22510
+ } catch (e) {
22511
+ console.error(e);
22512
+ this.engine.renderErrors.add(e);
22513
+ return;
22514
+ }
22515
+ var indexBuffer = geometry.getIndexBuffer();
22516
+ var offset = geometry.getDrawStart();
22517
+ var count = geometry.getDrawCount();
22518
+ var subMeshes = geometry.subMeshes;
22519
+ if (subMeshes.length > 0) {
22520
+ var subMesh = subMeshes[subMeshIndex];
22521
+ offset = subMesh.offset;
22522
+ var _subMesh_indexCount;
22523
+ count = indexBuffer ? (_subMesh_indexCount = subMesh.indexCount) != null ? _subMesh_indexCount : 0 : subMesh.vertexCount;
22524
+ }
22525
+ if (count <= 0) {
22526
+ return;
22527
+ }
22528
+ geometry.bind(material.shaderVariant);
22529
+ var instanceCount = geometry.instanceCount || undefined;
22530
+ if (indexBuffer) {
22531
+ this.engine.drawElementsType(geometry.mode, offset, count, instanceCount);
22532
+ } else {
22533
+ this.engine.drawArraysType(geometry.mode, offset, count, instanceCount);
22534
+ }
22449
22535
  };
22450
22536
  _proto.getTemporaryRT = function getTemporaryRT(name, width, height, depthBuffer, filter, format) {
22451
22537
  return this.engine.renderTargetPool.get(name, width, height, depthBuffer, filter, format);
@@ -22713,11 +22799,7 @@ var CanvasPool = /*#__PURE__*/ function() {
22713
22799
  var canvasPool = new CanvasPool();
22714
22800
 
22715
22801
  /**
22716
- * 字形纹理超采样倍数。canvas `fontSize * FONT_SCALE` 渲染,纹理像素也是 scale 倍,
22717
- * 但 quad 仍按 1x 逻辑尺寸绘制 — 双线性 downsample 后比原 1x 渲染清晰得多
22718
- */ var FONT_SCALE = 2;
22719
- /**
22720
- * 单张字符 atlas 的边长(像素,scale 后的实际像素,非逻辑尺寸)。
22802
+ * 单张字符 atlas 的逻辑边长。实际 canvas 像素尺寸会乘以渲染 resolution。
22721
22803
  * 512×512 在 24px 字号下约可容纳 250+ 字形,常见 demo 文本足够
22722
22804
  */ var ATLAS_SIZE = 512;
22723
22805
  /**
@@ -22739,7 +22821,7 @@ var canvasPool = new CanvasPool();
22739
22821
  * canvas 内容变更后需要 `uploadIfDirty` 重新上传到纹理 — 由调用方在使用纹理前主动触发,
22740
22822
  * 避免每加一字都 upload 一次造成的 GL 开销
22741
22823
  */ var GlyphAtlas = /*#__PURE__*/ function() {
22742
- function GlyphAtlas(engine, scaledFontString, /** baseline 距 cell 顶距离(像素,scale 后,仅 ascent 部分,不含 padding) */ ascentPx, /** baseline 距 cell 底距离(像素,scale 后,仅 descent 部分) */ descentPx, fontStyle) {
22824
+ function GlyphAtlas(engine, scaledFontString, /** baseline 距 cell 顶距离(像素,scale 后,仅 ascent 部分,不含 padding) */ ascentPx, /** baseline 距 cell 底距离(像素,scale 后,仅 descent 部分) */ descentPx, fontStyle, resolution) {
22743
22825
  this.engine = engine;
22744
22826
  this.scaledFontString = scaledFontString;
22745
22827
  this.glyphs = new Map();
@@ -22747,9 +22829,10 @@ var canvasPool = new CanvasPool();
22747
22829
  this.currentY = 0;
22748
22830
  this.full = false;
22749
22831
  this.dirty = true;
22832
+ this.resolution = resolution;
22750
22833
  this.canvas = document.createElement("canvas");
22751
- this.canvas.width = ATLAS_SIZE;
22752
- this.canvas.height = ATLAS_SIZE;
22834
+ this.canvas.width = Math.ceil(ATLAS_SIZE * resolution);
22835
+ this.canvas.height = Math.ceil(ATLAS_SIZE * resolution);
22753
22836
  var ctx = this.canvas.getContext("2d", {
22754
22837
  willReadFrequently: false
22755
22838
  });
@@ -22760,14 +22843,14 @@ var canvasPool = new CanvasPool();
22760
22843
  ctx.font = scaledFontString;
22761
22844
  ctx.textBaseline = "alphabetic";
22762
22845
  ctx.fillStyle = "#ffffff";
22763
- this.paddingPx = GLYPH_PADDING * FONT_SCALE;
22846
+ this.paddingPx = GLYPH_PADDING * resolution;
22764
22847
  this.italicScale = fontStyle === "italic" ? 2 : 1;
22765
22848
  // ascent/descent 由探针 '|ÉqÅM' 测得 actualBoundingBox(重音字已抬高 ink 顶),
22766
22849
  // 两者内部保持浮点,仅 cell 高做一次外层 ceil — 与 padding 共同保证 cell 内不裁切
22767
22850
  var fontHeightPx = ascentPx + descentPx;
22768
22851
  this.baselinePx = this.paddingPx + ascentPx;
22769
22852
  this.cellHPx = Math.ceil(fontHeightPx + this.paddingPx * 2);
22770
- this.lineHeight = this.cellHPx / FONT_SCALE;
22853
+ this.lineHeight = this.cellHPx / resolution;
22771
22854
  this.texture = Texture.create(engine, {
22772
22855
  sourceType: exports.TextureSourceType.image,
22773
22856
  image: this.canvas,
@@ -22776,7 +22859,8 @@ var canvasPool = new CanvasPool();
22776
22859
  magFilter: glContext.LINEAR,
22777
22860
  minFilter: glContext.LINEAR,
22778
22861
  wrapS: glContext.CLAMP_TO_EDGE,
22779
- wrapT: glContext.CLAMP_TO_EDGE
22862
+ wrapT: glContext.CLAMP_TO_EDGE,
22863
+ premultiplyAlpha: true
22780
22864
  });
22781
22865
  this.texture.initialize();
22782
22866
  }
@@ -22794,19 +22878,19 @@ var canvasPool = new CanvasPool();
22794
22878
  var ctx = this.ctx;
22795
22879
  // 每次重设字体,防御外部潜在污染(虽然 ctx 私有)
22796
22880
  ctx.font = this.scaledFontString;
22797
- // measureText 用的是 scaledFontString,advance 已经是 scale 后的像素,不能再乘 FONT_SCALE
22881
+ // measureText 用的是 scaledFontString,advance 已经是 resolution 后的像素
22798
22882
  var advancePx = ctx.measureText(char).width;
22799
22883
  // italic 放大 cell 宽防斜体越界;ceil 对齐像素网格避免相邻字采样重叠
22800
22884
  var widthPx = Math.max(1, Math.ceil(advancePx * this.italicScale));
22801
22885
  var paddedWidthPx = widthPx + this.paddingPx * 2;
22802
22886
  var cellH = this.cellHPx;
22803
22887
  // 行尾换行
22804
- if (this.currentX + paddedWidthPx > ATLAS_SIZE) {
22888
+ if (this.currentX + paddedWidthPx > this.canvas.width) {
22805
22889
  this.currentX = 0;
22806
22890
  this.currentY += cellH;
22807
22891
  }
22808
22892
  // atlas 满,后续不再尝试
22809
- if (this.currentY + cellH > ATLAS_SIZE) {
22893
+ if (this.currentY + cellH > this.canvas.height) {
22810
22894
  this.full = true;
22811
22895
  console.warn('GlyphAtlas full, dropping char "' + char + '"');
22812
22896
  return null;
@@ -22822,8 +22906,8 @@ var canvasPool = new CanvasPool();
22822
22906
  py: py,
22823
22907
  pw: paddedWidthPx,
22824
22908
  ph: cellH,
22825
- advance: advancePx / FONT_SCALE,
22826
- paddingLeft: this.paddingPx / FONT_SCALE
22909
+ advance: advancePx / this.resolution,
22910
+ paddingLeft: this.paddingPx / this.resolution
22827
22911
  };
22828
22912
  this.glyphs.set(char, info);
22829
22913
  return info;
@@ -22842,7 +22926,8 @@ var canvasPool = new CanvasPool();
22842
22926
  magFilter: glContext.LINEAR,
22843
22927
  minFilter: glContext.LINEAR,
22844
22928
  wrapS: glContext.CLAMP_TO_EDGE,
22845
- wrapT: glContext.CLAMP_TO_EDGE
22929
+ wrapT: glContext.CLAMP_TO_EDGE,
22930
+ premultiplyAlpha: true
22846
22931
  });
22847
22932
  this.dirty = false;
22848
22933
  };
@@ -22865,26 +22950,33 @@ var canvasPool = new CanvasPool();
22865
22950
  function TextCache(engine) {
22866
22951
  this.engine = engine;
22867
22952
  this.atlases = new Map();
22953
+ this.resolution = engine.pixelRatio;
22868
22954
  }
22869
22955
  var _proto = TextCache.prototype;
22870
22956
  /**
22871
22957
  * 取(必要时新建)对应字体的字符 atlas
22872
22958
  */ _proto.getAtlas = function getAtlas(fontSize, fontFamily, fontWeight, fontStyle) {
22873
- var fontKey = fontStyle + "|" + fontWeight + "|" + fontSize + "|" + fontFamily;
22959
+ // Pixi CanvasText 默认跟随 renderer.resolution;这里对应 Engine.pixelRatio。
22960
+ var resolution = this.engine.pixelRatio;
22961
+ if (resolution !== this.resolution) {
22962
+ this.clear();
22963
+ this.resolution = resolution;
22964
+ }
22965
+ var fontKey = fontStyle + "|" + fontWeight + "|" + fontSize + "|" + fontFamily + "|" + resolution;
22874
22966
  var cached = this.atlases.get(fontKey);
22875
22967
  if (cached) {
22876
22968
  return cached;
22877
22969
  }
22878
- var scaledFontString = fontStyle + " " + fontWeight + " " + fontSize * FONT_SCALE + "px " + fontFamily;
22970
+ var scaledFontString = fontStyle + " " + fontWeight + " " + fontSize * resolution + "px " + fontFamily;
22879
22971
  // 探一次得到字体级 ascent/descent(整张 atlas 共享 cell 高与 baseline,各字对齐)。
22880
- // 直接在 scaledFontString 下测,得到的就是 scale 后像素,无需再乘 FONT_SCALE。
22972
+ // 直接在 scaledFontString 下测,得到的就是 resolution 后像素。
22881
22973
  // 探针用 '|ÉqÅ' + 'M':带重音符的 ÉÅ 把 ink 顶推到接近字体真实 ascent,
22882
22974
  // 单字 'M' 只有 cap height(~0.7em) 太矮,CJK / 带重音字顶部会越过 cell 上界被裁。
22883
22975
  // 取 actualBoundingBoxAscent/Descent 度量 ink 边界,跨平台语义稳定
22884
22976
  var probeCanvasAndContext = canvasPool.getCanvasAndContext(1, 1);
22885
22977
  var probeCtx = probeCanvasAndContext.context;
22886
- var ascentPx = fontSize * 0.8 * FONT_SCALE;
22887
- var descentPx = fontSize * 0.2 * FONT_SCALE;
22978
+ var ascentPx = fontSize * 0.8 * resolution;
22979
+ var descentPx = fontSize * 0.2 * resolution;
22888
22980
  try {
22889
22981
  probeCtx.font = scaledFontString;
22890
22982
  var m = probeCtx.measureText(METRICS_STRING + BASELINE_SYMBOL);
@@ -22893,7 +22985,7 @@ var canvasPool = new CanvasPool();
22893
22985
  } finally{
22894
22986
  canvasPool.releaseCanvasAndContext(probeCanvasAndContext);
22895
22987
  }
22896
- var atlas = new GlyphAtlas(this.engine, scaledFontString, ascentPx, descentPx, fontStyle);
22988
+ var atlas = new GlyphAtlas(this.engine, scaledFontString, ascentPx, descentPx, fontStyle, resolution);
22897
22989
  this.atlases.set(fontKey, atlas);
22898
22990
  return atlas;
22899
22991
  };
@@ -22910,6 +23002,9 @@ var canvasPool = new CanvasPool();
22910
23002
  /**
22911
23003
  * 清空所有 atlas 并 dispose 对应纹理。Engine dispose 时调用
22912
23004
  */ _proto.dispose = function dispose() {
23005
+ this.clear();
23006
+ };
23007
+ _proto.clear = function clear() {
22913
23008
  for(var _iterator = _create_for_of_iterator_helper_loose(this.atlases.values()), _step; !(_step = _iterator()).done;){
22914
23009
  var atlas = _step.value;
22915
23010
  atlas.dispose();
@@ -23032,6 +23127,17 @@ var Graphics = /*#__PURE__*/ function() {
23032
23127
  this.texturedMaterial.depthTest = false;
23033
23128
  this.texturedMaterial.depthMask = false;
23034
23129
  this.texturedMaterial.blending = true;
23130
+ // 文本 atlas 按 Pixi 的方式在上传时预乘 alpha,因此采样后只需应用顶点色和顶点 alpha。
23131
+ // 单独使用 material,避免改变 drawTexture 对普通非预乘纹理的处理。
23132
+ this.textMaterial = Material.create(this.engine, {
23133
+ shader: {
23134
+ vertex: "precision highp float;\n attribute vec2 aPos;\n attribute vec4 aColor;\n attribute vec2 aUV;\n varying vec4 vColor;\n varying vec2 vUV;\n\n uniform mat4 effects_MatrixVP;\n void main() {\n vColor = aColor;\n vUV = aUV;\n gl_Position = effects_MatrixVP * vec4(aPos, 0.0, 1.0);\n }",
23135
+ fragment: "precision highp float;\n varying vec4 vColor;\n varying vec2 vUV;\n uniform sampler2D uMainTexture;\n void main() {\n float alpha = texture2D(uMainTexture, vUV).a * vColor.a;\n gl_FragColor = vec4(vColor.rgb * alpha, alpha);\n }"
23136
+ }
23137
+ });
23138
+ this.textMaterial.depthTest = false;
23139
+ this.textMaterial.depthMask = false;
23140
+ this.textMaterial.blending = true;
23035
23141
  this.textCache = new TextCache(engine);
23036
23142
  }
23037
23143
  var _proto = Graphics.prototype;
@@ -23053,6 +23159,7 @@ var Graphics = /*#__PURE__*/ function() {
23053
23159
  );
23054
23160
  this.coloredMaterial.setMatrix("effects_MatrixVP", projectionMatrix);
23055
23161
  this.texturedMaterial.setMatrix("effects_MatrixVP", projectionMatrix);
23162
+ this.textMaterial.setMatrix("effects_MatrixVP", projectionMatrix);
23056
23163
  };
23057
23164
  /**
23058
23165
  * 将当前变换压入栈,并设置新的变换
@@ -23080,7 +23187,7 @@ var Graphics = /*#__PURE__*/ function() {
23080
23187
  * 切换到指定批次类型/纹理。若与当前批次不一致,先 flush 已累积顶点
23081
23188
  */ _proto.ensureBatch = function ensureBatch(type, texture) {
23082
23189
  if (texture === void 0) texture = null;
23083
- var sameBatch = this.currentBatchType === type && (type !== "textured" || this.currentBatchTexture === texture);
23190
+ var sameBatch = this.currentBatchType === type && (type === "colored" || this.currentBatchTexture === texture);
23084
23191
  if (!sameBatch && this.currentVertexCount > 0) {
23085
23192
  this.flushBatch();
23086
23193
  }
@@ -23106,8 +23213,8 @@ var Graphics = /*#__PURE__*/ function() {
23106
23213
  this.geometry.setIndexData(indicesArray);
23107
23214
  this.geometry.setDrawCount(this.currentIndexCount);
23108
23215
  var material;
23109
- if (this.currentBatchType === "textured") {
23110
- material = this.texturedMaterial;
23216
+ if (this.currentBatchType === "textured" || this.currentBatchType === "text") {
23217
+ material = this.currentBatchType === "text" ? this.textMaterial : this.texturedMaterial;
23111
23218
  var _this_currentBatchTexture;
23112
23219
  var tex = (_this_currentBatchTexture = this.currentBatchTexture) != null ? _this_currentBatchTexture : this.engine.whiteTexture;
23113
23220
  material.setTexture("uMainTexture", tex);
@@ -23322,7 +23429,7 @@ var Graphics = /*#__PURE__*/ function() {
23322
23429
  return;
23323
23430
  }
23324
23431
  var atlas = this.textCache.getAtlas(fontSize, fontFamily, fontWeight, fontStyle);
23325
- this.ensureBatch("textured", atlas.texture);
23432
+ this.ensureBatch("text", atlas.texture);
23326
23433
  var lineHeight = atlas.lineHeight;
23327
23434
  var cursorX = x;
23328
23435
  // ensureChar 可能往 atlas canvas 写新字并打 dirty 标;实际 upload 推迟到
@@ -23333,13 +23440,15 @@ var Graphics = /*#__PURE__*/ function() {
23333
23440
  continue;
23334
23441
  }
23335
23442
  // atlas 像素坐标 → UV(纹理 flipY 后,canvas 顶 → v=1,canvas 底 → v=0)
23336
- var u0 = info.px / ATLAS_SIZE;
23337
- var u1 = (info.px + info.pw) / ATLAS_SIZE;
23338
- var v0 = 1 - (info.py + info.ph) / ATLAS_SIZE;
23339
- var v1 = 1 - info.py / ATLAS_SIZE;
23443
+ var atlasWidth = atlas.canvas.width;
23444
+ var atlasHeight = atlas.canvas.height;
23445
+ var u0 = info.px / atlasWidth;
23446
+ var u1 = (info.px + info.pw) / atlasWidth;
23447
+ var v0 = 1 - (info.py + info.ph) / atlasHeight;
23448
+ var v1 = 1 - info.py / atlasHeight;
23340
23449
  // quad 宽与采样区都含四周 padding(cell 留白透明);但光标只按 advance 前进,
23341
23450
  // quad 起点左偏 paddingLeft 使字形 ink 落在 cursorX — padding 区重叠无妨
23342
- this.pushQuad(cursorX - info.paddingLeft, y, info.pw / FONT_SCALE, lineHeight, color, {
23451
+ this.pushQuad(cursorX - info.paddingLeft, y, info.pw / atlas.resolution, lineHeight, color, {
23343
23452
  u0: u0,
23344
23453
  v0: v0,
23345
23454
  u1: u1,
@@ -23352,6 +23461,7 @@ var Graphics = /*#__PURE__*/ function() {
23352
23461
  this.geometry.dispose();
23353
23462
  this.coloredMaterial.dispose();
23354
23463
  this.texturedMaterial.dispose();
23464
+ this.textMaterial.dispose();
23355
23465
  this.textCache.dispose();
23356
23466
  };
23357
23467
  _proto.buildShape = function buildShape(shape, color) {
@@ -24422,410 +24532,358 @@ exports.FrameComponent = __decorate([
24422
24532
  // 第四列 (位移) 乘 1,无需修改
24423
24533
  }
24424
24534
 
24425
- /**
24426
- * 画布层组件
24427
- *
24428
- * 作为一组顶层 CanvasItem 的容器:本层内所有 parent 为 null 的 CanvasItem 都登记在 canvasItems 中。
24429
- * 嵌套关系下的子 CanvasItem 通过其父 CanvasItem 的 children 数组管理,由父节点在 draw 时递归绘制。
24430
- */ var CanvasLayer = /*#__PURE__*/ function(Component) {
24431
- _inherits(CanvasLayer, Component);
24432
- function CanvasLayer() {
24433
- var _this;
24434
- _this = Component.apply(this, arguments) || this;
24435
- /**
24436
- * 当前层中的顶层 CanvasItem 列表(按注册顺序)。
24437
- * 仅包含 parent 为 null 的 CanvasItem;嵌套的子 CanvasItem 不会出现在此列表
24438
- */ _this.canvasItems = [];
24439
- /**
24440
- * 绘制层级,数值越小越先绘制
24441
- */ _this.layer = 0;
24442
- return _this;
24443
- }
24444
- var _proto = CanvasLayer.prototype;
24445
- /**
24446
- * 注册一个顶层 CanvasItem 到当前层
24447
- * @internal
24448
- */ _proto.addCanvasItem = function addCanvasItem(canvasItem) {
24449
- if (this.canvasItems.includes(canvasItem)) {
24450
- return;
24451
- }
24452
- this.canvasItems.push(canvasItem);
24453
- };
24454
- /**
24455
- * 从当前层注销一个顶层 CanvasItem
24456
- * @internal
24457
- */ _proto.removeCanvasItem = function removeCanvasItem(canvasItem) {
24458
- removeItem(this.canvasItems, canvasItem);
24459
- };
24460
- _proto.onEnable = function onEnable() {
24461
- var _this_item_composition;
24462
- var canvasLayers = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.canvasLayers;
24463
- if (canvasLayers && !canvasLayers.includes(this)) {
24464
- canvasLayers.push(this);
24465
- }
24466
- };
24467
- _proto.onDisable = function onDisable() {
24468
- this.removeFromComposition();
24469
- this.refreshCanvasItemsLayer();
24535
+ function _assert_this_initialized(self) {
24536
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
24537
+ return self;
24538
+ }
24539
+
24540
+ exports.MouseFilter = void 0;
24541
+ (function(MouseFilter) {
24542
+ MouseFilter[MouseFilter["Stop"] = 0] = "Stop";
24543
+ MouseFilter[MouseFilter["Pass"] = 1] = "Pass";
24544
+ MouseFilter[MouseFilter["Ignore"] = 2] = "Ignore";
24545
+ })(exports.MouseFilter || (exports.MouseFilter = {}));
24546
+ exports.MouseBehaviorRecursive = void 0;
24547
+ (function(MouseBehaviorRecursive) {
24548
+ MouseBehaviorRecursive[MouseBehaviorRecursive["Inherited"] = 0] = "Inherited";
24549
+ MouseBehaviorRecursive[MouseBehaviorRecursive["Disabled"] = 1] = "Disabled";
24550
+ MouseBehaviorRecursive[MouseBehaviorRecursive["Enabled"] = 2] = "Enabled";
24551
+ })(exports.MouseBehaviorRecursive || (exports.MouseBehaviorRecursive = {}));
24552
+ exports.MouseButton = void 0;
24553
+ (function(MouseButton) {
24554
+ MouseButton[MouseButton["None"] = 0] = "None";
24555
+ MouseButton[MouseButton["Left"] = 1] = "Left";
24556
+ MouseButton[MouseButton["Right"] = 2] = "Right";
24557
+ MouseButton[MouseButton["Middle"] = 3] = "Middle";
24558
+ MouseButton[MouseButton["WheelUp"] = 4] = "WheelUp";
24559
+ MouseButton[MouseButton["WheelDown"] = 5] = "WheelDown";
24560
+ MouseButton[MouseButton["WheelLeft"] = 6] = "WheelLeft";
24561
+ MouseButton[MouseButton["WheelRight"] = 7] = "WheelRight";
24562
+ MouseButton[MouseButton["Xbutton1"] = 8] = "Xbutton1";
24563
+ MouseButton[MouseButton["Xbutton2"] = 9] = "Xbutton2";
24564
+ })(exports.MouseButton || (exports.MouseButton = {}));
24565
+ exports.MouseButtonMask = void 0;
24566
+ (function(MouseButtonMask) {
24567
+ MouseButtonMask[MouseButtonMask["None"] = 0] = "None";
24568
+ MouseButtonMask[MouseButtonMask["Left"] = 1] = "Left";
24569
+ MouseButtonMask[MouseButtonMask["Right"] = 2] = "Right";
24570
+ MouseButtonMask[MouseButtonMask["Middle"] = 4] = "Middle";
24571
+ MouseButtonMask[MouseButtonMask["Xbutton1"] = 128] = "Xbutton1";
24572
+ MouseButtonMask[MouseButtonMask["Xbutton2"] = 256] = "Xbutton2";
24573
+ })(exports.MouseButtonMask || (exports.MouseButtonMask = {}));
24574
+ exports.FocusMode = void 0;
24575
+ (function(FocusMode) {
24576
+ FocusMode[FocusMode["None"] = 0] = "None";
24577
+ FocusMode[FocusMode["Click"] = 1] = "Click";
24578
+ FocusMode[FocusMode["All"] = 2] = "All";
24579
+ FocusMode[FocusMode["Accessibility"] = 3] = "Accessibility";
24580
+ })(exports.FocusMode || (exports.FocusMode = {}));
24581
+ exports.FocusBehaviorRecursive = void 0;
24582
+ (function(FocusBehaviorRecursive) {
24583
+ FocusBehaviorRecursive[FocusBehaviorRecursive["Inherited"] = 0] = "Inherited";
24584
+ FocusBehaviorRecursive[FocusBehaviorRecursive["Disabled"] = 1] = "Disabled";
24585
+ FocusBehaviorRecursive[FocusBehaviorRecursive["Enabled"] = 2] = "Enabled";
24586
+ })(exports.FocusBehaviorRecursive || (exports.FocusBehaviorRecursive = {}));
24587
+ exports.KeyLocation = void 0;
24588
+ (function(KeyLocation) {
24589
+ KeyLocation[KeyLocation["Unspecified"] = 0] = "Unspecified";
24590
+ KeyLocation[KeyLocation["Left"] = 1] = "Left";
24591
+ KeyLocation[KeyLocation["Right"] = 2] = "Right";
24592
+ })(exports.KeyLocation || (exports.KeyLocation = {}));
24593
+ exports.CursorShape = void 0;
24594
+ (function(CursorShape) {
24595
+ CursorShape[CursorShape["Arrow"] = 0] = "Arrow";
24596
+ CursorShape[CursorShape["Ibeam"] = 1] = "Ibeam";
24597
+ CursorShape[CursorShape["PointingHand"] = 2] = "PointingHand";
24598
+ CursorShape[CursorShape["Cross"] = 3] = "Cross";
24599
+ CursorShape[CursorShape["Wait"] = 4] = "Wait";
24600
+ CursorShape[CursorShape["Busy"] = 5] = "Busy";
24601
+ CursorShape[CursorShape["Drag"] = 6] = "Drag";
24602
+ CursorShape[CursorShape["CanDrop"] = 7] = "CanDrop";
24603
+ CursorShape[CursorShape["Forbidden"] = 8] = "Forbidden";
24604
+ CursorShape[CursorShape["Vsize"] = 9] = "Vsize";
24605
+ CursorShape[CursorShape["Hsize"] = 10] = "Hsize";
24606
+ CursorShape[CursorShape["Bdiagsize"] = 11] = "Bdiagsize";
24607
+ CursorShape[CursorShape["Fdiagsize"] = 12] = "Fdiagsize";
24608
+ CursorShape[CursorShape["Move"] = 13] = "Move";
24609
+ CursorShape[CursorShape["Vsplit"] = 14] = "Vsplit";
24610
+ CursorShape[CursorShape["Hsplit"] = 15] = "Hsplit";
24611
+ CursorShape[CursorShape["Help"] = 16] = "Help";
24612
+ })(exports.CursorShape || (exports.CursorShape = {}));
24613
+
24614
+ function _get_prototype_of(o) {
24615
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
24616
+ return o.__proto__ || Object.getPrototypeOf(o);
24470
24617
  };
24471
- _proto.removeFromComposition = function removeFromComposition() {
24472
- var _this_item_composition;
24473
- var canvasLayers = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.canvasLayers;
24474
- if (canvasLayers) {
24475
- removeItem(canvasLayers, this);
24618
+ return _get_prototype_of(o);
24619
+ }
24620
+
24621
+ function _is_native_function(fn) {
24622
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
24623
+ }
24624
+
24625
+ function _wrap_native_super(Class) {
24626
+ var _cache = typeof Map === "function" ? new Map() : undefined;
24627
+ _wrap_native_super = function _wrap_native_super(Class) {
24628
+ if (Class === null || !_is_native_function(Class)) return Class;
24629
+ if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
24630
+ if (typeof _cache !== "undefined") {
24631
+ if (_cache.has(Class)) return _cache.get(Class);
24632
+ _cache.set(Class, Wrapper);
24476
24633
  }
24477
- };
24478
- _proto.refreshCanvasItemsLayer = function refreshCanvasItemsLayer() {
24479
- // CanvasLayer 失效时,让其下挂的 CanvasItem 重新查找归属层
24480
- // 拷贝一份避免迭代过程中数组被修改
24481
- var items = this.canvasItems.slice();
24482
- this.canvasItems.length = 0;
24483
- for(var _iterator = _create_for_of_iterator_helper_loose(items), _step; !(_step = _iterator()).done;){
24484
- var canvasItem = _step.value;
24485
- canvasItem.updateCanvasLayer();
24634
+ function Wrapper() {
24635
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
24486
24636
  }
24487
- };
24488
- /**
24489
- * 绘制当前层
24490
- *
24491
- * 遍历顶层 CanvasItem 进行绘制,由 CanvasItem.drawInternal 内部递归子节点。
24492
- * 整棵跳过看 `vfxItem.isActive`(item 级开关);self 自身是否画由 drawInternal 内的 `component.enabled` 决定。
24493
- *
24494
- * 注:画布尺寸到 RectTransform.size 的同步目前未在此处处理(由 RectTransform 自身按需 resolve);
24495
- * 后续若需要在每帧强制刷新顶层 size,可在此处补回写入与 sizeChanged 传播
24496
- *
24497
- * @internal
24498
- */ _proto.draw = function draw() {
24499
- for(var _iterator = _create_for_of_iterator_helper_loose(this.canvasItems), _step; !(_step = _iterator()).done;){
24500
- var canvasItem = _step.value;
24501
- if (!canvasItem.item.isActive) {
24502
- continue;
24637
+ Wrapper.prototype = Object.create(Class.prototype, {
24638
+ constructor: {
24639
+ value: Wrapper,
24640
+ enumerable: false,
24641
+ writable: true,
24642
+ configurable: true
24503
24643
  }
24504
- canvasItem.drawInternal();
24505
- }
24644
+ });
24645
+ return _set_prototype_of(Wrapper, Class);
24506
24646
  };
24507
- return CanvasLayer;
24508
- }(Component);
24647
+ return _wrap_native_super(Class);
24648
+ }
24509
24649
 
24510
- /**
24511
- * 画布元素组件
24512
- *
24513
- * 进入场景树时沿父链向上查找最近的 CanvasLayer 祖先并注册自己;
24514
- * 父级改变或自身销毁时,刷新 / 注销在所属 CanvasLayer 的登记。
24515
- *
24516
- * 注:拓扑(parent / children / 所属 layer)与 enabled/active 解耦
24517
- * `component.enabled=false` 仅让自身 draw 被跳过,**不**改父子关系,也**不**从 layer 注销;
24518
- * 整棵子树的隐藏由 `vfxItem.setActive(false)` 配合 drawInternal 中的 `isActive` 检查处理
24519
- */ var CanvasItem = /*#__PURE__*/ function(Component) {
24520
- _inherits(CanvasItem, Component);
24521
- function CanvasItem() {
24522
- var _this;
24523
- _this = Component.apply(this, arguments) || this;
24524
- /**
24525
- * 父 CanvasItem
24526
- * 沿 VFXItem 父链向上查找到的最近的 CanvasItem(只看类型,不看 active/enabled — 拓扑跟激活状态解耦)。
24527
- * 若不存在 CanvasItem 祖先(即直属于 CanvasLayer 或处于游离状态),该值为 null。
24528
- */ _this.parent = null;
24529
- /**
24530
- * 子 CanvasItem 列表(按注册顺序)
24531
- * 由子节点在维护自身 parent 时反向写入,draw 时按数组顺序递归绘制
24532
- */ _this.children = [];
24533
- /**
24534
- * 当前所属的 CanvasLayer,未注册到任何 CanvasLayer 时为 null
24535
- */ _this.canvasLayerNode = null;
24536
- return _this;
24650
+ function transformPoint(transform, value) {
24651
+ var elements = transform.elements;
24652
+ return new Vector2(elements[0] * value.x + elements[3] * value.y + elements[6], elements[1] * value.x + elements[4] * value.y + elements[7]);
24653
+ }
24654
+ function transformVector(transform, value) {
24655
+ var elements = transform.elements;
24656
+ return new Vector2(elements[0] * value.x + elements[3] * value.y, elements[1] * value.x + elements[4] * value.y);
24657
+ }
24658
+ var InputEvent = /*#__PURE__*/ function() {
24659
+ function InputEvent() {
24660
+ this.device = 0;
24661
+ this.pressed = false;
24662
+ this.canceled = false;
24537
24663
  }
24538
- var _proto = CanvasItem.prototype;
24539
- _proto.onEnable = function onEnable() {
24540
- // 首次接入 / 重新接入场景树时把自己挂上(若拓扑还没建立)。
24541
- // 注意 enable/disable 不再改变 CanvasItem 父子拓扑 — 拓扑由 VFXItem 父链(setParent / onParentChanged)维护,
24542
- // enable 在这里只是兜底首次入树
24543
- this.updateCanvasLayer();
24544
- this.updateParentItem();
24545
- };
24546
- _proto.onDisable = function onDisable() {
24547
- // 组件禁用 = 仅 self.draw 跳过,不应改父子拓扑(否则 enable 回来位置就乱了)。
24548
- // 整棵子树的隐藏由 `vfxItem.setActive(false)` 配合 drawInternal 中的 `item.isActive` 检查处理
24664
+ var _proto = InputEvent.prototype;
24665
+ _proto.isPressed = function isPressed() {
24666
+ return this.pressed && !this.canceled;
24549
24667
  };
24550
- _proto.onParentChanged = function onParentChanged() {
24551
- // VFXItem 的父级(或间接父级)发生变化时,CanvasLayer 与父 CanvasItem 都可能改变,需要联动刷新
24552
- this.updateCanvasLayer();
24553
- this.updateParentItem();
24668
+ _proto.isReleased = function isReleased() {
24669
+ return !this.pressed && !this.canceled;
24554
24670
  };
24555
- _proto.onDestroy = function onDestroy() {
24556
- this.removeFromParent();
24557
- this.removeFromCanvasLayer();
24558
- // 防止子 canvasItem updateParentItem 的时候继续找到当前已销毁的 canvasItem
24559
- this.enabled = false;
24560
- this.updateChildrenParentItems();
24671
+ _proto.isCanceled = function isCanceled() {
24672
+ return this.canceled;
24561
24673
  };
24562
- /**
24563
- * 重新计算并更新当前 CanvasItem 应归属的 CanvasLayer
24564
- * 在父级变化、所在 CanvasLayer 失效等场景中调用
24565
- *
24566
- * 仅当自身是顶层 CanvasItem(parent 为 null)时才会登记到 CanvasLayer.canvasItems;
24567
- * 嵌套的子 CanvasItem 仅记录 canvasLayerNode 引用,不进入 layer 的顶层列表。
24568
- * @internal
24569
- */ _proto.updateCanvasLayer = function updateCanvasLayer() {
24570
- // 拓扑跟 enabled/active 解耦,只看 item 是否还在
24571
- if (!this.item) {
24572
- this.removeFromCanvasLayer();
24573
- return;
24574
- }
24575
- var newLayer = this.getCanvasLayerNode();
24576
- if (newLayer === this.canvasLayerNode) {
24577
- return;
24578
- }
24579
- // 仅当自身是顶层 CanvasItem 时,才需要在 layer 的 canvasItems 中迁移
24580
- if (this.parent === null && this.canvasLayerNode) {
24581
- this.canvasLayerNode.removeCanvasItem(this);
24582
- }
24583
- this.canvasLayerNode = newLayer;
24584
- if (this.parent === null && newLayer) {
24585
- newLayer.addCanvasItem(this);
24586
- }
24587
- };
24588
- /**
24589
- * 重新计算并更新当前 CanvasItem 的父 CanvasItem
24590
- * 在 VFXItem 父级变化、自身启用/禁用、父 CanvasItem 失效等场景中调用
24591
- *
24592
- * parent 的变化会同步影响在 CanvasLayer.canvasItems 中的归属:
24593
- * - 由有 parent 变成无 parent 且仍归属某 layer:加入 layer.canvasItems
24594
- * - 由无 parent 变成有 parent:从 layer.canvasItems 中移除
24595
- * @internal
24596
- */ _proto.updateParentItem = function updateParentItem() {
24597
- // 拓扑跟 enabled/active 解耦,只看 item 是否还在
24598
- if (!this.item) {
24599
- this.removeFromParent();
24600
- return;
24601
- }
24602
- var newParent = this.getParentItem();
24603
- if (newParent === this.parent) {
24604
- return;
24605
- }
24606
- var wasTopLevel = this.parent === null;
24607
- this.removeFromParent();
24608
- if (newParent) {
24609
- this.parent = newParent;
24610
- newParent.children.push(this);
24611
- // 由顶层变成嵌套:从 layer 的顶层列表中移除
24612
- if (wasTopLevel && this.canvasLayerNode) {
24613
- this.canvasLayerNode.removeCanvasItem(this);
24614
- }
24615
- } else if (!wasTopLevel && this.canvasLayerNode) {
24616
- // 由嵌套变成顶层:加入 layer 的顶层列表
24617
- this.canvasLayerNode.addCanvasItem(this);
24618
- }
24619
- };
24620
- /**
24621
- * 绘制函数
24622
- * 子类重写此方法以输出实际的绘制内容;调用时 graphics 的变换栈顶已经累积了从根到当前节点的所有父变换,
24623
- * 子类直接使用 this.drawXxx / this.fillXxx 系列封装方法绘制即可,绘制坐标视为本地坐标。
24624
- */ _proto.draw = function draw() {
24625
- // OVERRIDE
24626
- };
24627
- /**
24628
- * 绘制单条线段
24629
- * @param x1 - 起点 x
24630
- * @param y1 - 起点 y
24631
- * @param x2 - 终点 x
24632
- * @param y2 - 终点 y
24633
- * @param color - 线条颜色
24634
- * @param thickness - 线宽
24635
- */ _proto.drawLine = function drawLine(x1, y1, x2, y2, color, thickness) {
24636
- this.engine.graphics.drawLine(x1, y1, x2, y2, color, thickness);
24637
- };
24638
- /**
24639
- * 按顺序连接所有点绘制折线(首尾相同则视为闭合)
24640
- * @param points - 点数组,格式 [x1,y1,x2,y2,...]
24641
- * @param color - 线条颜色
24642
- * @param thickness - 线宽
24643
- */ _proto.drawPolyline = function drawPolyline(points, color, thickness) {
24644
- this.engine.graphics.drawLines(points, color, thickness);
24645
- };
24646
- /**
24647
- * 绘制三次贝塞尔曲线
24648
- */ _proto.drawBezier = function drawBezier(x1, y1, x2, y2, x3, y3, x4, y4, color, thickness) {
24649
- this.engine.graphics.drawBezier(x1, y1, x2, y2, x3, y3, x4, y4, color, thickness);
24650
- };
24651
- /**
24652
- * 绘制三角形边框
24653
- */ _proto.drawTriangle = function drawTriangle(x1, y1, x2, y2, x3, y3, color, thickness) {
24654
- this.engine.graphics.drawTriangle(x1, y1, x2, y2, x3, y3, color, thickness);
24655
- };
24656
- /**
24657
- * 绘制矩形边框
24658
- * @param x - 矩形左下角 x 坐标
24659
- * @param y - 矩形左下角 y 坐标
24660
- */ _proto.drawRect = function drawRect(x, y, width, height, color, thickness) {
24661
- this.engine.graphics.drawRectangle(x, y, width, height, color, thickness);
24662
- };
24663
- /**
24664
- * 绘制圆形边框
24665
- */ _proto.drawCircle = function drawCircle(cx, cy, radius, color, thickness) {
24666
- this.engine.graphics.drawCircle(cx, cy, radius, color, thickness);
24667
- };
24668
- /**
24669
- * 绘制填充三角形
24670
- */ _proto.fillTriangle = function fillTriangle(x1, y1, x2, y2, x3, y3, color) {
24671
- this.engine.graphics.fillTriangle(x1, y1, x2, y2, x3, y3, color);
24672
- };
24673
- /**
24674
- * 绘制填充矩形
24675
- * @param x - 矩形左下角 x 坐标
24676
- * @param y - 矩形左下角 y 坐标
24677
- */ _proto.fillRect = function fillRect(x, y, width, height, color) {
24678
- this.engine.graphics.fillRectangle(x, y, width, height, color);
24679
- };
24680
- /**
24681
- * 绘制填充圆形
24682
- */ _proto.fillCircle = function fillCircle(cx, cy, radius, color) {
24683
- this.engine.graphics.fillCircle(cx, cy, radius, color);
24684
- };
24685
- /**
24686
- * 绘制纹理矩形(本地坐标,Y 向上,(x, y) 为左下角)
24687
- * @param region - 纹理 UV 子矩形,默认全图。Y 向上,(u0, v0) 为左下角 UV
24688
- * @param color - 乘色,默认白色
24689
- */ _proto.drawTexture = function drawTexture(x, y, width, height, texture, region, color) {
24690
- this.engine.graphics.drawTexture(x, y, width, height, texture, region, color);
24691
- };
24692
- /**
24693
- * 绘制文本(本地坐标,Y 向上,(x, y) 为文本左下角)。
24694
- *
24695
- * 同一段文本不同颜色不会重复 upload — 颜色由 `color` 参数透传作为乘色,纹理只缓存白色字形。
24696
- * 字体参数全部展开,避免调用方每帧创建临时 style 对象触发 GC
24697
- */ _proto.drawText = function drawText(x, y, text, fontSize, color, fontFamily, fontWeight, fontStyle) {
24698
- this.engine.graphics.drawText(x, y, text, fontSize, color, fontFamily, fontWeight, fontStyle);
24699
- };
24700
- /**
24701
- * 绘制自身并按 children 数组顺序递归绘制所有子 CanvasItem。
24702
- * @internal
24703
- */ _proto.drawInternal = function drawInternal() {
24704
- var graphics = this.engine.graphics;
24705
- var localMatrix2D = this.transform.getMatrix2D();
24706
- graphics.pushTransform(localMatrix2D);
24707
- // self 是否绘制只看 component.enabled — 其它都不影响。
24708
- // transform 始终被 push,children 始终被遍历,这样 component.enabled=false 时 self 隐藏
24709
- // 但 children 的位置不受影响
24710
- if (this.enabled) {
24711
- this.draw();
24712
- }
24713
- // 子是否参与绘制看 VFXItem.isActive(整棵跳过的语义)。
24714
- // 子自身的 component.enabled 在它自己的 drawInternal 里再判断
24715
- for(var _iterator = _create_for_of_iterator_helper_loose(this.children), _step; !(_step = _iterator()).done;){
24716
- var child = _step.value;
24717
- if (!child.item.isActive) {
24718
- continue;
24719
- }
24720
- child.drawInternal();
24721
- }
24722
- graphics.popTransform();
24723
- };
24724
- /**
24725
- * 从当前所属的 CanvasLayer 注销自身(如果有)
24726
- * 仅当自身是顶层 CanvasItem 时,才会触发 layer 顶层列表的移除
24727
- */ _proto.removeFromCanvasLayer = function removeFromCanvasLayer() {
24728
- if (!this.canvasLayerNode) {
24729
- return;
24730
- }
24731
- if (this.parent === null) {
24732
- this.canvasLayerNode.removeCanvasItem(this);
24733
- }
24734
- this.canvasLayerNode = null;
24735
- };
24736
- /**
24737
- * 从当前父 CanvasItem 的 children 中移除自身(如果有)
24738
- */ _proto.removeFromParent = function removeFromParent() {
24739
- if (!this.parent) {
24740
- return;
24741
- }
24742
- removeItem(this.parent.children, this);
24743
- this.parent = null;
24744
- };
24745
- /**
24746
- * 更新所有子 CanvasItem 的层级归属。
24747
- * 自身失效时调用,子节点会跳过自己向上找到新的父 CanvasItem(可能为 null)。
24748
- */ _proto.updateChildrenParentItems = function updateChildrenParentItems() {
24749
- if (this.children.length === 0) {
24750
- return;
24751
- }
24752
- // 拷贝避免迭代过程中数组被 removeFromParent 修改
24753
- var snapshot = this.children.slice();
24754
- for(var _iterator = _create_for_of_iterator_helper_loose(snapshot), _step; !(_step = _iterator()).done;){
24755
- var child = _step.value;
24756
- child.updateParentItem();
24757
- }
24758
- };
24759
- /**
24760
- * 沿父链向上查找最近的 CanvasLayer 祖先
24761
- * 注意:自身所在 VFXItem 上的 CanvasLayer 也参与查找(同节点上可能并存 CanvasLayer 与 CanvasItem)
24762
- */ _proto.getCanvasLayerNode = function getCanvasLayerNode() {
24763
- var current = this.item;
24764
- while(current){
24765
- var layer = getCanvasLayerFromItem(current);
24766
- if (layer) {
24767
- return layer;
24768
- }
24769
- var _current_parent;
24770
- current = (_current_parent = current.parent) != null ? _current_parent : null;
24771
- }
24772
- return null;
24674
+ _proto.isEcho = function isEcho() {
24675
+ return false;
24773
24676
  };
24774
- /**
24775
- * 沿 VFXItem 父链向上查找最近的 CanvasItem 祖先(不包含自身,只看类型不看 active/enabled)
24776
- */ _proto.getParentItem = function getParentItem() {
24777
- var _this_item;
24778
- var _this_item_parent;
24779
- var current = (_this_item_parent = (_this_item = this.item) == null ? void 0 : _this_item.parent) != null ? _this_item_parent : null;
24780
- while(current){
24781
- var canvasItem = getCanvasItemFromItem(current);
24782
- if (canvasItem) {
24783
- return canvasItem;
24784
- }
24785
- var _current_parent;
24786
- current = (_current_parent = current.parent) != null ? _current_parent : null;
24787
- }
24788
- return null;
24677
+ _proto.xformedBy = function xformedBy(transform) {
24678
+ var event = new InputEvent();
24679
+ event.device = this.device;
24680
+ event.pressed = this.pressed;
24681
+ event.canceled = this.canceled;
24682
+ return event;
24789
24683
  };
24790
- _create_class(CanvasItem, [
24791
- {
24792
- key: "canvasLayer",
24793
- get: /**
24794
- * 获取当前所属的 CanvasLayer
24795
- */ function get() {
24796
- return this.canvasLayerNode;
24797
- }
24798
- }
24799
- ]);
24800
- return CanvasItem;
24801
- }(Component);
24802
- /**
24803
- * 在指定 VFXItem 上查找一个激活的 CanvasLayer 组件
24804
- */ function getCanvasLayerFromItem(item) {
24805
- for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
24806
- var component = _step.value;
24807
- if (_instanceof1(component, CanvasLayer) && component.isActiveAndEnabled) {
24808
- return component;
24809
- }
24684
+ return InputEvent;
24685
+ }();
24686
+ InputEvent.deviceIdEmulation = -1;
24687
+ InputEvent.deviceIdInternal = -2;
24688
+ InputEvent.deviceIdKeyboard = 16;
24689
+ InputEvent.deviceIdMouse = 32;
24690
+ var InputEventWithModifiers = /*#__PURE__*/ function(InputEvent) {
24691
+ _inherits(InputEventWithModifiers, InputEvent);
24692
+ function InputEventWithModifiers() {
24693
+ var _this;
24694
+ _this = InputEvent.apply(this, arguments) || this;
24695
+ _this.commandOrControlAutoremap = false;
24696
+ _this.shiftPressed = false;
24697
+ _this.altPressed = false;
24698
+ _this.metaPressed = false;
24699
+ _this.ctrlPressed = false;
24700
+ return _this;
24810
24701
  }
24811
- return null;
24812
- }
24813
- /**
24814
- * 在指定 VFXItem 上查找 CanvasItem 组件(只看类型,不看 active/enabled — 拓扑跟激活状态解耦)
24815
- */ function getCanvasItemFromItem(item) {
24816
- for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
24817
- var component = _step.value;
24818
- if (_instanceof1(component, CanvasItem)) {
24819
- return component;
24820
- }
24702
+ var _proto = InputEventWithModifiers.prototype;
24703
+ _proto.copyModifiersTo = function copyModifiersTo(event) {
24704
+ event.device = this.device;
24705
+ event.pressed = this.pressed;
24706
+ event.canceled = this.canceled;
24707
+ event.commandOrControlAutoremap = this.commandOrControlAutoremap;
24708
+ event.shiftPressed = this.shiftPressed;
24709
+ event.altPressed = this.altPressed;
24710
+ event.metaPressed = this.metaPressed;
24711
+ event.ctrlPressed = this.ctrlPressed;
24712
+ };
24713
+ _proto.xformedBy = function xformedBy(transform) {
24714
+ var event = new InputEventWithModifiers();
24715
+ this.copyModifiersTo(event);
24716
+ return event;
24717
+ };
24718
+ return InputEventWithModifiers;
24719
+ }(_wrap_native_super(InputEvent));
24720
+ var InputEventKey = /*#__PURE__*/ function(InputEventWithModifiers) {
24721
+ _inherits(InputEventKey, InputEventWithModifiers);
24722
+ function InputEventKey() {
24723
+ var _this;
24724
+ _this = InputEventWithModifiers.apply(this, arguments) || this;
24725
+ _this.keycode = "";
24726
+ _this.physicalKeycode = "";
24727
+ _this.keyLabel = "";
24728
+ _this.unicode = 0;
24729
+ _this.location = exports.KeyLocation.Unspecified;
24730
+ _this.echo = false;
24731
+ return _this;
24821
24732
  }
24822
- return null;
24823
- }
24824
-
24825
- /**
24826
- * 16 preset 对应的 anchorMin / anchorMax(Y 向上)
24827
- */ var ANCHOR_PRESET_TABLE = {
24828
- // [anchorMin.x, anchorMin.y, anchorMax.x, anchorMax.y]
24733
+ var _proto = InputEventKey.prototype;
24734
+ _proto.isEcho = function isEcho() {
24735
+ return this.echo;
24736
+ };
24737
+ _proto.xformedBy = function xformedBy(transform) {
24738
+ var event = new InputEventKey();
24739
+ this.copyModifiersTo(event);
24740
+ event.keycode = this.keycode;
24741
+ event.physicalKeycode = this.physicalKeycode;
24742
+ event.keyLabel = this.keyLabel;
24743
+ event.unicode = this.unicode;
24744
+ event.location = this.location;
24745
+ event.echo = this.echo;
24746
+ return event;
24747
+ };
24748
+ return InputEventKey;
24749
+ }(InputEventWithModifiers);
24750
+ var InputEventMouse = /*#__PURE__*/ function(InputEventWithModifiers) {
24751
+ _inherits(InputEventMouse, InputEventWithModifiers);
24752
+ function InputEventMouse() {
24753
+ var _this;
24754
+ _this = InputEventWithModifiers.apply(this, arguments) || this;
24755
+ _this.buttonMask = exports.MouseButtonMask.None;
24756
+ _this.position = new Vector2();
24757
+ _this.globalPosition = new Vector2();
24758
+ return _this;
24759
+ }
24760
+ var _proto = InputEventMouse.prototype;
24761
+ _proto.copyMouseTo = function copyMouseTo(event) {
24762
+ this.copyModifiersTo(event);
24763
+ event.buttonMask = this.buttonMask;
24764
+ event.position.copyFrom(this.position);
24765
+ event.globalPosition.copyFrom(this.globalPosition);
24766
+ };
24767
+ _proto.xformedBy = function xformedBy(transform) {
24768
+ var event = new InputEventMouse();
24769
+ this.copyMouseTo(event);
24770
+ event.position.copyFrom(transformPoint(transform, this.position));
24771
+ return event;
24772
+ };
24773
+ return InputEventMouse;
24774
+ }(InputEventWithModifiers);
24775
+ var InputEventMouseButton = /*#__PURE__*/ function(InputEventMouse) {
24776
+ _inherits(InputEventMouseButton, InputEventMouse);
24777
+ function InputEventMouseButton() {
24778
+ var _this;
24779
+ _this = InputEventMouse.apply(this, arguments) || this;
24780
+ _this.factor = 1;
24781
+ _this.buttonIndex = exports.MouseButton.None;
24782
+ _this.doubleClick = false;
24783
+ return _this;
24784
+ }
24785
+ var _proto = InputEventMouseButton.prototype;
24786
+ _proto.xformedBy = function xformedBy(transform) {
24787
+ var event = new InputEventMouseButton();
24788
+ this.copyMouseTo(event);
24789
+ event.position.copyFrom(transformPoint(transform, this.position));
24790
+ event.factor = this.factor;
24791
+ event.buttonIndex = this.buttonIndex;
24792
+ event.doubleClick = this.doubleClick;
24793
+ return event;
24794
+ };
24795
+ return InputEventMouseButton;
24796
+ }(InputEventMouse);
24797
+ var InputEventMouseMotion = /*#__PURE__*/ function(InputEventMouse) {
24798
+ _inherits(InputEventMouseMotion, InputEventMouse);
24799
+ function InputEventMouseMotion() {
24800
+ var _this;
24801
+ _this = InputEventMouse.apply(this, arguments) || this;
24802
+ _this.tilt = new Vector2();
24803
+ _this.pressure = 0;
24804
+ _this.relative = new Vector2();
24805
+ _this.screenRelative = new Vector2();
24806
+ _this.velocity = new Vector2();
24807
+ _this.screenVelocity = new Vector2();
24808
+ _this.penInverted = false;
24809
+ return _this;
24810
+ }
24811
+ var _proto = InputEventMouseMotion.prototype;
24812
+ _proto.xformedBy = function xformedBy(transform) {
24813
+ var event = new InputEventMouseMotion();
24814
+ this.copyMouseTo(event);
24815
+ event.position.copyFrom(transformPoint(transform, this.position));
24816
+ event.tilt.copyFrom(this.tilt);
24817
+ event.pressure = this.pressure;
24818
+ event.relative.copyFrom(transformVector(transform, this.relative));
24819
+ event.screenRelative.copyFrom(this.screenRelative);
24820
+ event.velocity.copyFrom(transformVector(transform, this.velocity));
24821
+ event.screenVelocity.copyFrom(this.screenVelocity);
24822
+ event.penInverted = this.penInverted;
24823
+ return event;
24824
+ };
24825
+ return InputEventMouseMotion;
24826
+ }(InputEventMouse);
24827
+ var InputEventScreenTouch = /*#__PURE__*/ function(InputEvent) {
24828
+ _inherits(InputEventScreenTouch, InputEvent);
24829
+ function InputEventScreenTouch() {
24830
+ var _this;
24831
+ _this = InputEvent.apply(this, arguments) || this;
24832
+ _this.index = 0;
24833
+ _this.position = new Vector2();
24834
+ _this.doubleTap = false;
24835
+ return _this;
24836
+ }
24837
+ var _proto = InputEventScreenTouch.prototype;
24838
+ _proto.xformedBy = function xformedBy(transform) {
24839
+ var event = new InputEventScreenTouch();
24840
+ event.device = this.device;
24841
+ event.pressed = this.pressed;
24842
+ event.canceled = this.canceled;
24843
+ event.index = this.index;
24844
+ event.position.copyFrom(transformPoint(transform, this.position));
24845
+ event.doubleTap = this.doubleTap;
24846
+ return event;
24847
+ };
24848
+ return InputEventScreenTouch;
24849
+ }(_wrap_native_super(InputEvent));
24850
+ var InputEventScreenDrag = /*#__PURE__*/ function(InputEvent) {
24851
+ _inherits(InputEventScreenDrag, InputEvent);
24852
+ function InputEventScreenDrag() {
24853
+ var _this;
24854
+ _this = InputEvent.apply(this, arguments) || this;
24855
+ _this.index = 0;
24856
+ _this.position = new Vector2();
24857
+ _this.relative = new Vector2();
24858
+ _this.screenRelative = new Vector2();
24859
+ _this.velocity = new Vector2();
24860
+ _this.screenVelocity = new Vector2();
24861
+ _this.pressure = 0;
24862
+ _this.tilt = new Vector2();
24863
+ _this.penInverted = false;
24864
+ return _this;
24865
+ }
24866
+ var _proto = InputEventScreenDrag.prototype;
24867
+ _proto.xformedBy = function xformedBy(transform) {
24868
+ var event = new InputEventScreenDrag();
24869
+ event.device = this.device;
24870
+ event.pressed = this.pressed;
24871
+ event.canceled = this.canceled;
24872
+ event.index = this.index;
24873
+ event.position.copyFrom(transformPoint(transform, this.position));
24874
+ event.relative.copyFrom(transformVector(transform, this.relative));
24875
+ event.screenRelative.copyFrom(this.screenRelative);
24876
+ event.velocity.copyFrom(transformVector(transform, this.velocity));
24877
+ event.screenVelocity.copyFrom(this.screenVelocity);
24878
+ event.pressure = this.pressure;
24879
+ event.tilt.copyFrom(this.tilt);
24880
+ event.penInverted = this.penInverted;
24881
+ return event;
24882
+ };
24883
+ return InputEventScreenDrag;
24884
+ }(_wrap_native_super(InputEvent));
24885
+
24886
+ var ANCHOR_PRESET_TABLE = {
24829
24887
  topLeft: [
24830
24888
  0,
24831
24889
  1,
@@ -24924,306 +24982,170 @@ exports.FrameComponent = __decorate([
24924
24982
  ]
24925
24983
  };
24926
24984
  /**
24927
- * 锚点布局变换。`RectTransform extends Transform`,在 Transform position/rotation/scale/size/anchor(=pivot 偏移)
24928
- * 之上额外维护 4 边锚点 + 4 边像素偏移,提供 rect 解算与编辑 API。
24929
- *
24930
- * 解算公式(Y 向上,父 vertex 坐标原点 = 父 rect 左下角):
24931
- * ```
24932
- * left = offsetMin.x + anchorMin.x * parentSize.x
24933
- * bottom = offsetMin.y + anchorMin.y * parentSize.y
24934
- * right = offsetMax.x + anchorMax.x * parentSize.x
24935
- * top = offsetMax.y + anchorMax.y * parentSize.y
24936
- * ```
24937
- *
24938
- * 写回 Transform:
24939
- * - `position` ← `(left, bottom)`(rect 左下角,父 vertex 坐标)
24940
- * - `size` ← rect 尺寸
24941
- * - `anchor`(Vector3 像素 pivot 偏移)由用户独立设置,仅作旋转/缩放中心
24942
- *
24943
- * **解算入口** 是 `sizeChanged()` 方法:
24944
- * - 父是 RectTransform → 用 `parent.size` parentSize 解算自身,写回 `position` / `size`
24945
- * - 否则(顶层 / 没父):自身 size 视为权威值(由外部 通常是 CanvasLayer 直接写),不再自解算
24946
- * - 末尾遍历 `children` 中的 RectTransform,直接调它们的 `sizeChanged()`,链式向下传播
24947
- *
24948
- * **重写 `setPosition` / `setSize`** 让其语义变为"用户输入 rect 位置 / 尺寸":
24949
- * - 顶层(无 RectTransform 父):直接写 `super.setPosition / super.setSize`,然后 `sizeChanged` 传播给子节点
24950
- * - 否则:反推 offset 维持当前 anchor,然后 `sizeChanged` 重算并向下传
24951
- */ var RectTransform = /*#__PURE__*/ function(Transform) {
24952
- _inherits(RectTransform, Transform);
24953
- function RectTransform() {
24954
- var _this;
24955
- _this = Transform.apply(this, arguments) || this;
24956
- /**
24957
- * 父 rect 上的归一化最小角 `(anchorLeft, anchorBottom)`
24958
- */ _this.anchorMin = new Vector2(0, 0);
24959
- /**
24960
- * 父 rect 上的归一化最大角 `(anchorRight, anchorTop)`
24961
- */ _this.anchorMax = new Vector2(0, 0);
24962
- /**
24963
- * rect 左/下边相对 anchorMin 锚点的像素偏移 `(offsetLeft, offsetBottom)`
24964
- */ _this.offsetMin = new Vector2(0, 0);
24965
- /**
24966
- * rect 右/上边相对 anchorMax 锚点的像素偏移 `(offsetRight, offsetTop)`
24967
- */ _this.offsetMax = new Vector2(0, 0);
24968
- /**
24969
- * 自身 rect 上的归一化轴心 `(0..1)`,默认 `(0.5, 0.5)`(中心)。两层效果:
24970
- * 1. **Layout**:`setSize` 时 rect 围绕此点对称缩放(pivot=(0.5, 0.5) → 居中扩展;pivot=(0, 0) → 从左下扩展;pivot=(1, 1) → 向左下缩)
24971
- * 2. **矩阵**:`pivot` 自动同步到 `transform.anchor = pivot * size`(像素值,矩阵旋转/缩放中心),
24972
- * 所以旋转/缩放也围绕同一点。`setPivot` 和每次 `sizeChanged`(size 重算后)都会刷新 `transform.anchor`
24973
- */ _this.pivot = new Vector2(0.5, 0.5);
24974
- return _this;
24985
+ * A drawable GUI object. Controls form a tree independent from the VFXItem
24986
+ * scene tree. UIControl is the bridge between both trees.
24987
+ */ var Control = /*#__PURE__*/ function() {
24988
+ function Control(engine) {
24989
+ this.engine = engine;
24990
+ this._parent = null;
24991
+ this._visible = true;
24992
+ this._enabled = true;
24993
+ this._mouseFilter = exports.MouseFilter.Stop;
24994
+ this._mouseBehaviorRecursive = exports.MouseBehaviorRecursive.Inherited;
24995
+ this._focusMode = exports.FocusMode.None;
24996
+ this._focusBehaviorRecursive = exports.FocusBehaviorRecursive.Inherited;
24997
+ this._defaultCursorShape = exports.CursorShape.Arrow;
24998
+ this._rotation = 0;
24999
+ this.transformDirty = true;
25000
+ this.cachedTransform = new Matrix3();
25001
+ this.eventEmitter = new EventEmitter();
25002
+ this.disposed = false;
25003
+ this./** Scene-tree bridge that owns this GUI object, if any. */ owner = null;
25004
+ this.position = new Vector2();
25005
+ this.size = new Vector2(1, 1);
25006
+ this.anchorMin = new Vector2();
25007
+ this.anchorMax = new Vector2();
25008
+ this.offsetMin = new Vector2();
25009
+ this.offsetMax = new Vector2(1, 1);
25010
+ this.pivot = new Vector2(0.5, 0.5);
25011
+ this.scale = new Vector2(1, 1);
25012
+ this.shear = new Vector2();
25013
+ this.mouseForcePassScrollEvents = true;
25014
+ this.clipContents = false;
24975
25015
  }
24976
- var _proto = RectTransform.prototype;
24977
- /**
24978
- * 反序列化:在 `Transform.fromData` 基础上还原 RectTransform 特有的 `pivot` /
24979
- * `anchorMin` / `anchorMax` / `offsetMin` / `offsetMax`。
24980
- *
24981
- * 顺序:
24982
- * 1. `super.fromData` 还原 `position` / `rotation` / `scale` / `size` / `anchor`
24983
- * 2. 若数据有 size,从 `anchor / size` 反推 `pivot`,保持 `anchor = pivot * size` 一致
24984
- * 3. 应用 `anchorMin/Max` / `offsetMin/Max`,每个 setter 末尾会触发 `sizeChanged`
24985
- * 重新解算 rect 与同步 `transform.anchor`
24986
- */ _proto.fromData = function fromData(data) {
24987
- Transform.prototype.fromData.call(this, data);
24988
- if (this.size.x !== 0 && this.size.y !== 0) {
24989
- this.pivot.set(this.anchor.x / this.size.x, this.anchor.y / this.size.y);
25016
+ var _proto = Control.prototype;
25017
+ _proto.on = function on(eventName, listener, options) {
25018
+ this.eventEmitter.on(eventName, listener, options);
25019
+ };
25020
+ _proto.off = function off(eventName, listener) {
25021
+ this.eventEmitter.off(eventName, listener);
25022
+ };
25023
+ _proto.setPosition = function setPosition(x, y, keepOffsets) {
25024
+ if (keepOffsets === void 0) keepOffsets = false;
25025
+ if (this.position.x === x && this.position.y === y) {
25026
+ return;
24990
25027
  }
24991
- // @ts-expect-error spec.TransformData 暂未声明 RectTransform 字段
24992
- if (data.anchorMin) {
24993
- // @ts-expect-error
24994
- this.setAnchorMin(data.anchorMin.x, data.anchorMin.y);
25028
+ var rect = {
25029
+ position: new Vector2(x, y),
25030
+ size: this.size.clone()
25031
+ };
25032
+ if (keepOffsets && this.parent) {
25033
+ this.computeAnchors(rect, this.getParentRect());
25034
+ } else {
25035
+ this.computeOffsets(rect, this.getParentRect());
24995
25036
  }
24996
- // @ts-expect-error
24997
- if (data.anchorMax) {
24998
- // @ts-expect-error
24999
- this.setAnchorMax(data.anchorMax.x, data.anchorMax.y);
25037
+ this.updateLayout();
25038
+ };
25039
+ _proto.setSize = function setSize(width, height) {
25040
+ if (this.size.x === width && this.size.y === height) {
25041
+ return;
25000
25042
  }
25001
- // @ts-expect-error
25002
- if (data.offsetMin) {
25003
- // @ts-expect-error
25004
- this.setOffsetMin(data.offsetMin.x, data.offsetMin.y);
25043
+ var rect = {
25044
+ position: this.position.clone(),
25045
+ size: new Vector2(width, height)
25046
+ };
25047
+ this.computeOffsets(rect, this.getParentRect());
25048
+ this.updateLayout();
25049
+ };
25050
+ _proto.setScale = function setScale(x, y) {
25051
+ if (this.scale.x !== x || this.scale.y !== y) {
25052
+ this.scale.set(x, y);
25053
+ this.markTransformDirty();
25005
25054
  }
25006
- // @ts-expect-error
25007
- if (data.offsetMax) {
25008
- // @ts-expect-error
25009
- this.setOffsetMax(data.offsetMax.x, data.offsetMax.y);
25055
+ };
25056
+ _proto.setRotation = function setRotation(degrees) {
25057
+ if (this._rotation !== degrees) {
25058
+ this._rotation = degrees;
25059
+ this.markTransformDirty();
25060
+ }
25061
+ };
25062
+ _proto.setShear = function setShear(x, y) {
25063
+ if (this.shear.x !== x || this.shear.y !== y) {
25064
+ this.shear.set(x, y);
25065
+ this.markTransformDirty();
25066
+ }
25067
+ };
25068
+ _proto.setPivot = function setPivot(x, y) {
25069
+ if (this.pivot.x !== x || this.pivot.y !== y) {
25070
+ this.pivot.set(x, y);
25071
+ this.markTransformDirty();
25010
25072
  }
25011
25073
  };
25012
- // ── layout-input setters(改完 → sizeChanged 重算)──────
25013
25074
  _proto.setAnchorMin = function setAnchorMin(x, y) {
25014
25075
  if (this.anchorMin.x !== x || this.anchorMin.y !== y) {
25015
- this.anchorMin.x = x;
25016
- this.anchorMin.y = y;
25017
- this.sizeChanged();
25076
+ this.anchorMin.set(x, y);
25077
+ this.updateLayout();
25018
25078
  }
25019
25079
  };
25020
25080
  _proto.setAnchorMax = function setAnchorMax(x, y) {
25021
25081
  if (this.anchorMax.x !== x || this.anchorMax.y !== y) {
25022
- this.anchorMax.x = x;
25023
- this.anchorMax.y = y;
25024
- this.sizeChanged();
25082
+ this.anchorMax.set(x, y);
25083
+ this.updateLayout();
25025
25084
  }
25026
25085
  };
25027
25086
  _proto.setOffsetMin = function setOffsetMin(x, y) {
25028
25087
  if (this.offsetMin.x !== x || this.offsetMin.y !== y) {
25029
- this.offsetMin.x = x;
25030
- this.offsetMin.y = y;
25031
- this.sizeChanged();
25088
+ this.offsetMin.set(x, y);
25089
+ this.updateLayout();
25032
25090
  }
25033
25091
  };
25034
25092
  _proto.setOffsetMax = function setOffsetMax(x, y) {
25035
25093
  if (this.offsetMax.x !== x || this.offsetMax.y !== y) {
25036
- this.offsetMax.x = x;
25037
- this.offsetMax.y = y;
25038
- this.sizeChanged();
25039
- }
25040
- };
25041
- /**
25042
- * 设置 rect 内的归一化轴心 `(0..1)`,同时把 `transform.anchor`(矩阵旋转/缩放中心)同步到 `pivot * size`。
25043
- * 不重算 rect(pivot 只决定 setSize 行为,不直接影响当前 rect 位置 / 尺寸)
25044
- */ _proto.setPivot = function setPivot(x, y) {
25045
- if (this.pivot.x !== x || this.pivot.y !== y) {
25046
- this.pivot.x = x;
25047
- this.pivot.y = y;
25048
- // 同步 transform.anchor(像素 pivot)= pivot * size,让旋转/缩放绕同一点
25049
- this.anchor.set(this.pivot.x * this.size.x, this.pivot.y * this.size.y, this.anchor.z);
25094
+ this.offsetMax.set(x, y);
25095
+ this.updateLayout();
25050
25096
  }
25051
25097
  };
25052
- /**
25053
- * 重写父类 `setPosition`:
25054
- * - 顶层(无 RectTransform 父):直接 `super.setPosition` 写位置,触发 `sizeChanged` 传播
25055
- * - 非顶层:语义为"设置 rect 左下角到 (x, y)",反推 offset 维持当前 anchor,然后 `sizeChanged` 重算
25056
- *
25057
- * @param keepOffsets - 默认 false。true 时反推 anchor 而非 offset(rect 在屏幕上不动,但 anchor 比例改变)
25058
- */ _proto.setPosition = function setPosition(x, y, z, keepOffsets) {
25059
- if (keepOffsets === void 0) keepOffsets = false;
25060
- if (!_instanceof1(this.parentTransform, RectTransform)) {
25061
- // 顶层:直接写,然后传播给子节点
25062
- Transform.prototype.setPosition.call(this, x, y, z);
25063
- this.sizeChanged();
25064
- return;
25065
- }
25066
- var parentRect = {
25067
- position: new Vector2(0, 0),
25068
- size: this.parentTransform.size.clone()
25069
- };
25070
- var newRect = {
25071
- position: new Vector2(x, y),
25072
- size: this.size.clone()
25073
- };
25074
- if (keepOffsets) {
25075
- this.computeAnchors(newRect, parentRect);
25076
- } else {
25077
- this.computeOffsets(newRect, parentRect);
25078
- }
25079
- this.sizeChanged();
25080
- if (this.position.z !== z) {
25081
- Transform.prototype.setPosition.call(this, this.position.x, this.position.y, z);
25082
- }
25083
- };
25084
- /**
25085
- * 重写父类 `setSize`:
25086
- * - 顶层:直接 `super.setSize`,触发 `sizeChanged` 传播
25087
- * - 非顶层:反推 offset 维持当前 anchor,然后 `sizeChanged` 重算
25088
- */ _proto.setSize = function setSize(x, y) {
25089
- if (this.size.x === x && this.size.y === y) {
25090
- return;
25091
- }
25092
- if (!_instanceof1(this.parentTransform, RectTransform)) {
25093
- Transform.prototype.setSize.call(this, x, y);
25094
- this.sizeChanged();
25095
- return;
25096
- }
25097
- // 围绕 pivot 对称缩放:Δsize 在 offsetMin / offsetMax 上按 pivot / (1-pivot) 比例分配。
25098
- // 例如 pivot=(0.5, 0.5) → 两边各 ±Δ/2,rect 居中扩展;pivot=(0, 0) → offsetMin 不动、offsetMax 全吃,rect 从左下扩展
25099
- var dw = x - this.size.x;
25100
- var dh = y - this.size.y;
25101
- this.offsetMin.set(this.offsetMin.x - this.pivot.x * dw, this.offsetMin.y - this.pivot.y * dh);
25102
- this.offsetMax.set(this.offsetMax.x + (1 - this.pivot.x) * dw, this.offsetMax.y + (1 - this.pivot.y) * dh);
25103
- this.sizeChanged();
25104
- };
25105
- // ── rect query ───────────────────────────────────────
25106
- /**
25107
- * 当前自身 rect(在父 vertex 坐标下,Y 向上)。`sizeChanged` 之后才有意义
25108
- */ _proto.getRect = function getRect() {
25098
+ _proto.getRect = function getRect() {
25109
25099
  return {
25110
- position: new Vector2(this.position.x, this.position.y),
25100
+ position: this.position.clone(),
25111
25101
  size: this.size.clone()
25112
25102
  };
25113
25103
  };
25114
- // ── parent linkage ───────────────────────────────────
25115
- /**
25116
- * transform 切换时重算自身布局。子节点链路通过 `Transform.children` 直接访问,无需事件订阅
25117
- * @internal
25118
- */ _proto.onParentTransformChanged = function onParentTransformChanged(_oldParent, _newParent) {
25119
- if (_instanceof1(_oldParent, RectTransform)) {
25120
- this.engine.off("resize", this.onCanvasResize.bind(this));
25121
- }
25122
- if (!_instanceof1(_newParent, RectTransform)) {
25123
- this.onCanvasResize();
25124
- this.engine.on("resize", this.onCanvasResize.bind(this));
25125
- }
25126
- this.sizeChanged();
25127
- };
25128
- _proto.onCanvasResize = function onCanvasResize() {
25129
- var rect = this.engine.canvas.getBoundingClientRect();
25130
- this.setSize(rect.width, rect.height);
25131
- };
25132
- // ── layout solver──────────────
25133
- /**
25134
- * 解算入口:
25135
- *
25136
- * 1. 父是 RectTransform → 从 `parent.size` 求自身 rect,通过 `super.setPosition / super.setSize` 写回
25137
- * (避免触发本类 setPosition / setSize 重写)
25138
- * 2. 顶层(无 RectTransform 父):自身 size 视为权威值(由 CanvasLayer 等外部直接写),不自解算
25139
- * 3. 遍历 `children` 中所有 RectTransform 子节点,直接调它们的 `sizeChanged()` 链式传播
25140
- */ _proto.sizeChanged = function sizeChanged() {
25141
- if (_instanceof1(this.parentTransform, RectTransform)) {
25142
- var parentSize = this.parentTransform.size;
25143
- var left = this.offsetMin.x + this.anchorMin.x * parentSize.x;
25144
- var bottom = this.offsetMin.y + this.anchorMin.y * parentSize.y;
25145
- var right = this.offsetMax.x + this.anchorMax.x * parentSize.x;
25146
- var top = this.offsetMax.y + this.anchorMax.y * parentSize.y;
25147
- Transform.prototype.setPosition.call(this, left, bottom, this.position.z);
25148
- Transform.prototype.setSize.call(this, right - left, top - bottom);
25149
- }
25150
- // size 更新后同步 transform.anchor(矩阵旋转/缩放中心)= pivot * size,跟 setPivot 保持统一
25151
- this.anchor.set(this.pivot.x * this.size.x, this.pivot.y * this.size.y, this.anchor.z);
25152
- for(var _iterator = _create_for_of_iterator_helper_loose(this.children), _step; !(_step = _iterator()).done;){
25153
- var child = _step.value;
25154
- if (_instanceof1(child, RectTransform)) {
25155
- child.sizeChanged();
25156
- }
25157
- }
25158
- };
25159
- /**
25160
- * 给定目标 rect 反推 offsetMin/Max,保持当前 anchor 不变
25161
- */ _proto.computeOffsets = function computeOffsets(rect, parentRect) {
25162
- this.offsetMin.set(rect.position.x - parentRect.position.x - this.anchorMin.x * parentRect.size.x, rect.position.y - parentRect.position.y - this.anchorMin.y * parentRect.size.y);
25163
- this.offsetMax.set(rect.position.x + rect.size.x - parentRect.position.x - this.anchorMax.x * parentRect.size.x, rect.position.y + rect.size.y - parentRect.position.y - this.anchorMax.y * parentRect.size.y);
25164
- };
25165
- /**
25166
- * 给定目标 rect 反推 anchorMin/Max,保持当前 offset 不变。父 size 为 0 的方向不修改
25167
- */ _proto.computeAnchors = function computeAnchors(rect, parentRect) {
25168
- if (parentRect.size.x !== 0) {
25169
- var aMinX = (rect.position.x - parentRect.position.x - this.offsetMin.x) / parentRect.size.x;
25170
- var aMaxX = (rect.position.x + rect.size.x - parentRect.position.x - this.offsetMax.x) / parentRect.size.x;
25171
- this.anchorMin.x = aMinX;
25172
- this.anchorMax.x = aMaxX;
25173
- }
25174
- if (parentRect.size.y !== 0) {
25175
- var aMinY = (rect.position.y - parentRect.position.y - this.offsetMin.y) / parentRect.size.y;
25176
- var aMaxY = (rect.position.y + rect.size.y - parentRect.position.y - this.offsetMax.y) / parentRect.size.y;
25177
- this.anchorMin.y = aMinY;
25178
- this.anchorMax.y = aMaxY;
25179
- }
25180
- };
25181
- // ── preset API ───────────────────────────────────────
25182
- /**
25183
- * 把 anchorMin/Max 设为内建预设。
25184
- * @param keepOffsets - 默认 true:offset 不动,rect 实际位置会跳到新 anchor 计算的位置(要求保留视觉位置请用 setAnchorsAndOffsetsPreset)
25185
- */ _proto.setAnchorsPreset = function setAnchorsPreset(preset, keepOffsets) {
25104
+ _proto.getTransform2D = function getTransform2D() {
25105
+ if (this.transformDirty) {
25106
+ var radians = this._rotation * Math.PI / 180;
25107
+ var sin = Math.sin(radians);
25108
+ var cos = Math.cos(radians);
25109
+ var shearX = Math.tan(Math.max(-89, Math.min(89, this.shear.x)) * Math.PI / 180);
25110
+ var shearY = Math.tan(Math.max(-89, Math.min(89, this.shear.y)) * Math.PI / 180);
25111
+ var a = this.scale.x * (cos - sin * shearY);
25112
+ var b = this.scale.x * (sin + cos * shearY);
25113
+ var c = this.scale.y * (cos * shearX - sin);
25114
+ var d = this.scale.y * (sin * shearX + cos);
25115
+ var pivotX = this.pivot.x * this.size.x;
25116
+ var pivotY = this.pivot.y * this.size.y;
25117
+ var tx = this.position.x + pivotX - a * pivotX - c * pivotY;
25118
+ var ty = this.position.y + pivotY - b * pivotX - d * pivotY;
25119
+ this.cachedTransform.set(a, b, 0, c, d, 0, tx, ty, 1);
25120
+ this.transformDirty = false;
25121
+ }
25122
+ return this.cachedTransform;
25123
+ };
25124
+ _proto.setAnchorsPreset = function setAnchorsPreset(preset, keepOffsets) {
25186
25125
  if (keepOffsets === void 0) keepOffsets = true;
25187
- var _ANCHOR_PRESET_TABLE_preset = ANCHOR_PRESET_TABLE[preset], aMinX = _ANCHOR_PRESET_TABLE_preset[0], aMinY = _ANCHOR_PRESET_TABLE_preset[1], aMaxX = _ANCHOR_PRESET_TABLE_preset[2], aMaxY = _ANCHOR_PRESET_TABLE_preset[3];
25126
+ var _ANCHOR_PRESET_TABLE_preset = ANCHOR_PRESET_TABLE[preset], minX = _ANCHOR_PRESET_TABLE_preset[0], minY = _ANCHOR_PRESET_TABLE_preset[1], maxX = _ANCHOR_PRESET_TABLE_preset[2], maxY = _ANCHOR_PRESET_TABLE_preset[3];
25188
25127
  if (keepOffsets) {
25189
- this.anchorMin.set(aMinX, aMinY);
25190
- this.anchorMax.set(aMaxX, aMaxY);
25191
- } else if (_instanceof1(this.parentTransform, RectTransform)) {
25192
- var parentRect = {
25193
- position: new Vector2(0, 0),
25194
- size: this.parentTransform.size.clone()
25195
- };
25196
- var rect = this.getRect();
25197
- this.anchorMin.set(aMinX, aMinY);
25198
- this.anchorMax.set(aMaxX, aMaxY);
25199
- this.computeOffsets(rect, parentRect);
25128
+ this.anchorMin.set(minX, minY);
25129
+ this.anchorMax.set(maxX, maxY);
25200
25130
  } else {
25201
- // 顶层无父 rect 可参考,降级为 keepOffsets
25202
- this.anchorMin.set(aMinX, aMinY);
25203
- this.anchorMax.set(aMaxX, aMaxY);
25131
+ var rect = this.getRect();
25132
+ this.anchorMin.set(minX, minY);
25133
+ this.anchorMax.set(maxX, maxY);
25134
+ this.computeOffsets(rect, this.getParentRect());
25204
25135
  }
25205
- this.sizeChanged();
25136
+ this.updateLayout();
25206
25137
  };
25207
- /**
25208
- * 把 offsetMin/Max 设为预设值,使 rect 在父 rect 内落在视觉上对应的位置(留 margin 像素边距)。
25209
- * 当 anchor 已经按相同 preset 设定时,等价于“贴边放置带 margin 的 rect”。
25210
- * 使用当前 size 作为 rect 尺寸。
25211
- */ _proto.setOffsetsPreset = function setOffsetsPreset(preset, margin) {
25138
+ _proto.setOffsetsPreset = function setOffsetsPreset(preset, margin) {
25212
25139
  if (margin === void 0) margin = 0;
25213
- if (!_instanceof1(this.parentTransform, RectTransform)) {
25140
+ if (!this.parent) {
25214
25141
  return;
25215
25142
  }
25216
- var newSizeX = this.size.x;
25217
- var newSizeY = this.size.y;
25143
+ var parentSize = this.parent.size;
25144
+ var width = this.size.x;
25145
+ var height = this.size.y;
25218
25146
  var a = this.anchorMin;
25219
25147
  var b = this.anchorMax;
25220
- var pw = this.parentTransform.size.x;
25221
- var ph = this.parentTransform.size.y;
25222
- var offMinX = 0;
25223
- var offMaxX = 0;
25224
- var offMinY = 0;
25225
- var offMaxY = 0;
25226
- // X 方向(left / right)
25148
+ var minX = 0, maxX = 0, minY = 0, maxY = 0;
25227
25149
  switch(preset){
25228
25150
  case "topLeft":
25229
25151
  case "bottomLeft":
@@ -25233,25 +25155,21 @@ exports.FrameComponent = __decorate([
25233
25155
  case "leftWide":
25234
25156
  case "hcenterWide":
25235
25157
  case "fullRect":
25236
- offMinX = margin - a.x * pw;
25237
- offMaxX = margin + newSizeX - b.x * pw;
25158
+ minX = margin - a.x * parentSize.x;
25159
+ maxX = margin + width - b.x * parentSize.x;
25238
25160
  break;
25239
25161
  case "centerTop":
25240
25162
  case "centerBottom":
25241
25163
  case "center":
25242
25164
  case "vcenterWide":
25243
- offMinX = 0.5 * pw - newSizeX / 2 - a.x * pw;
25244
- offMaxX = 0.5 * pw + newSizeX / 2 - b.x * pw;
25165
+ minX = 0.5 * parentSize.x - width / 2 - a.x * parentSize.x;
25166
+ maxX = 0.5 * parentSize.x + width / 2 - b.x * parentSize.x;
25245
25167
  break;
25246
- case "topRight":
25247
- case "bottomRight":
25248
- case "centerRight":
25249
- case "rightWide":
25250
- offMinX = pw - margin - newSizeX - a.x * pw;
25251
- offMaxX = pw - margin - b.x * pw;
25168
+ default:
25169
+ minX = parentSize.x - margin - width - a.x * parentSize.x;
25170
+ maxX = parentSize.x - margin - b.x * parentSize.x;
25252
25171
  break;
25253
25172
  }
25254
- // Y 方向(bottom / top)— Y 向上
25255
25173
  switch(preset){
25256
25174
  case "bottomLeft":
25257
25175
  case "bottomRight":
@@ -25261,91 +25179,1438 @@ exports.FrameComponent = __decorate([
25261
25179
  case "bottomWide":
25262
25180
  case "vcenterWide":
25263
25181
  case "fullRect":
25264
- offMinY = margin - a.y * ph;
25265
- offMaxY = margin + newSizeY - b.y * ph;
25182
+ minY = margin - a.y * parentSize.y;
25183
+ maxY = margin + height - b.y * parentSize.y;
25266
25184
  break;
25267
25185
  case "centerLeft":
25268
25186
  case "centerRight":
25269
25187
  case "center":
25270
25188
  case "hcenterWide":
25271
- offMinY = 0.5 * ph - newSizeY / 2 - a.y * ph;
25272
- offMaxY = 0.5 * ph + newSizeY / 2 - b.y * ph;
25189
+ minY = 0.5 * parentSize.y - height / 2 - a.y * parentSize.y;
25190
+ maxY = 0.5 * parentSize.y + height / 2 - b.y * parentSize.y;
25273
25191
  break;
25274
- case "topLeft":
25275
- case "topRight":
25276
- case "centerTop":
25277
- case "topWide":
25278
- offMinY = ph - margin - newSizeY - a.y * ph;
25279
- offMaxY = ph - margin - b.y * ph;
25192
+ default:
25193
+ minY = parentSize.y - margin - height - a.y * parentSize.y;
25194
+ maxY = parentSize.y - margin - b.y * parentSize.y;
25280
25195
  break;
25281
25196
  }
25282
- this.offsetMin.set(offMinX, offMinY);
25283
- this.offsetMax.set(offMaxX, offMaxY);
25284
- this.sizeChanged();
25197
+ this.offsetMin.set(minX, minY);
25198
+ this.offsetMax.set(maxX, maxY);
25199
+ this.updateLayout();
25285
25200
  };
25286
- /**
25287
- * 同时设置 anchor 和 offset,达到“按 preset 摆放并贴边带 margin”的效果。
25288
- *
25289
- * 注意第一步用 `keepOffsets=false`(反推 offset 维持 rect 视觉位置),不能用默认 `true`:
25290
- * 后者会让 rect 的 size 在中间步先跳到错值(因为 anchor 改了 offset 没改),
25291
- * 第二步 `setOffsetsPreset` 又用这个错 size 算 offset,最终 rect size 不对
25292
- */ _proto.setAnchorsAndOffsetsPreset = function setAnchorsAndOffsetsPreset(preset, margin) {
25201
+ _proto.setAnchorsAndOffsetsPreset = function setAnchorsAndOffsetsPreset(preset, margin) {
25293
25202
  if (margin === void 0) margin = 0;
25294
25203
  this.setAnchorsPreset(preset, false);
25295
25204
  this.setOffsetsPreset(preset, margin);
25296
25205
  };
25297
- /**
25298
- * 用既有 Transform 的状态创建 RectTransform。
25299
- * 用于 Control / CanvasLayer 接管 VFXItem 时,把 VFXItem 自带的 Transform 升级为 RectTransform 而不丢失 position/rotation/scale 等已设置好的状态。
25300
- */ RectTransform.fromTransform = function fromTransform(t) {
25301
- if (_instanceof1(t, RectTransform)) {
25302
- return t;
25206
+ _proto.getGlobalTransform2D = function getGlobalTransform2D() {
25207
+ var local = this.getTransform2D();
25208
+ return this.parent ? new Matrix3().multiplyMatrices(this.parent.getGlobalTransform2D(), local) : local.clone();
25209
+ };
25210
+ _proto.hasPoint = function hasPoint(point) {
25211
+ return point.x >= 0 && point.y >= 0 && point.x <= this.size.x && point.y <= this.size.y;
25212
+ };
25213
+ _proto.getEffectiveMouseFilter = function getEffectiveMouseFilter() {
25214
+ return this.enabledInHierarchy && this.isMouseRecursiveEnabled() ? this.mouseFilter : exports.MouseFilter.Ignore;
25215
+ };
25216
+ _proto.getFocusModeWithOverride = function getFocusModeWithOverride() {
25217
+ return this.enabledInHierarchy && this.isFocusRecursiveEnabled() ? this.focusMode : exports.FocusMode.None;
25218
+ };
25219
+ _proto.getCursorShape = function getCursorShape(position) {
25220
+ return this.defaultCursorShape;
25221
+ };
25222
+ _proto.acceptEvent = function acceptEvent() {
25223
+ var _this_root;
25224
+ (_this_root = this.root) == null ? void 0 : _this_root.acceptControlEvent(this);
25225
+ };
25226
+ _proto.focus = function focus() {
25227
+ var _this_root;
25228
+ (_this_root = this.root) == null ? void 0 : _this_root.grabControlFocus(this);
25229
+ };
25230
+ _proto.grabFocus = function grabFocus() {
25231
+ this.focus();
25232
+ };
25233
+ _proto.grabClickFocus = function grabClickFocus() {
25234
+ var _this_root;
25235
+ (_this_root = this.root) == null ? void 0 : _this_root.grabControlClickFocus(this);
25236
+ };
25237
+ _proto.releaseFocus = function releaseFocus() {
25238
+ var _this_root;
25239
+ (_this_root = this.root) == null ? void 0 : _this_root.releaseControlFocus(this);
25240
+ };
25241
+ _proto.warpMouse = function warpMouse(position) {
25242
+ var _this_root;
25243
+ var matrix = this.getGlobalTransform2D().elements;
25244
+ (_this_root = this.root) == null ? void 0 : _this_root.warpControlMouse(new Vector2(matrix[0] * position.x + matrix[3] * position.y + matrix[6], matrix[1] * position.x + matrix[4] * position.y + matrix[7]));
25245
+ };
25246
+ /** Converts a window-space position into this control's local coordinates. */ _proto.makePositionLocal = function makePositionLocal(position) {
25247
+ var transform = this.getGlobalTransform2D().clone();
25248
+ if (Math.abs(transform.determinant()) < 1e-12) {
25249
+ return new Vector2();
25250
+ }
25251
+ var elements = transform.invert().elements;
25252
+ return new Vector2(elements[0] * position.x + elements[3] * position.y + elements[6], elements[1] * position.x + elements[4] * position.y + elements[7]);
25253
+ };
25254
+ /** Gets the current mouse position transformed into this control's coordinates. */ _proto.getLocalMousePosition = function getLocalMousePosition() {
25255
+ var root = this.root;
25256
+ return root ? this.makePositionLocal(root.getMousePosition()) : new Vector2();
25257
+ };
25258
+ _proto.update = function update(deltaTime) {};
25259
+ _proto.draw = function draw() {
25260
+ // OVERRIDE
25261
+ };
25262
+ _proto.onDestroy = function onDestroy() {};
25263
+ /** @internal */ _proto.drawInternal = function drawInternal() {
25264
+ if (!this.visibleInHierarchy || this.disposed) {
25265
+ return;
25266
+ }
25267
+ var graphics = this.engine.graphics;
25268
+ graphics.pushTransform(this.getTransform2D());
25269
+ this.draw();
25270
+ graphics.popTransform();
25271
+ };
25272
+ _proto.drawLine = function drawLine(x1, y1, x2, y2, color, thickness) {
25273
+ this.engine.graphics.drawLine(x1, y1, x2, y2, color, thickness);
25274
+ };
25275
+ _proto.drawPolyline = function drawPolyline(points, color, thickness) {
25276
+ this.engine.graphics.drawLines(points, color, thickness);
25277
+ };
25278
+ _proto.drawBezier = function drawBezier(x1, y1, x2, y2, x3, y3, x4, y4, color, thickness) {
25279
+ this.engine.graphics.drawBezier(x1, y1, x2, y2, x3, y3, x4, y4, color, thickness);
25280
+ };
25281
+ _proto.drawTriangle = function drawTriangle(x1, y1, x2, y2, x3, y3, color, thickness) {
25282
+ this.engine.graphics.drawTriangle(x1, y1, x2, y2, x3, y3, color, thickness);
25283
+ };
25284
+ _proto.drawRect = function drawRect(x, y, width, height, color, thickness) {
25285
+ this.engine.graphics.drawRectangle(x, y, width, height, color, thickness);
25286
+ };
25287
+ _proto.drawCircle = function drawCircle(cx, cy, radius, color, thickness) {
25288
+ this.engine.graphics.drawCircle(cx, cy, radius, color, thickness);
25289
+ };
25290
+ _proto.fillTriangle = function fillTriangle(x1, y1, x2, y2, x3, y3, color) {
25291
+ this.engine.graphics.fillTriangle(x1, y1, x2, y2, x3, y3, color);
25292
+ };
25293
+ _proto.fillRect = function fillRect(x, y, width, height, color) {
25294
+ this.engine.graphics.fillRectangle(x, y, width, height, color);
25295
+ };
25296
+ _proto.fillCircle = function fillCircle(cx, cy, radius, color) {
25297
+ this.engine.graphics.fillCircle(cx, cy, radius, color);
25298
+ };
25299
+ _proto.drawTexture = function drawTexture(x, y, width, height, texture, region, color) {
25300
+ this.engine.graphics.drawTexture(x, y, width, height, texture, region, color);
25301
+ };
25302
+ _proto.drawText = function drawText(x, y, text, fontSize, color, fontFamily, fontWeight, fontStyle) {
25303
+ this.engine.graphics.drawText(x, y, text, fontSize, color, fontFamily, fontWeight, fontStyle);
25304
+ };
25305
+ _proto.onMouseEnter = function onMouseEnter(location) {};
25306
+ _proto.onMouseMove = function onMouseMove(location, event) {};
25307
+ _proto.onMouseLeave = function onMouseLeave() {};
25308
+ _proto.onMouseWheel = function onMouseWheel(location, delta, event) {};
25309
+ _proto.onMouseDown = function onMouseDown(location, button, event) {};
25310
+ _proto.onMouseUp = function onMouseUp(location, button, event) {};
25311
+ _proto.onTouchDown = function onTouchDown(location, pointerId, event) {};
25312
+ _proto.onTouchMove = function onTouchMove(location, pointerId, event) {};
25313
+ _proto.onTouchUp = function onTouchUp(location, pointerId, event) {};
25314
+ _proto.onKeyDown = function onKeyDown(event) {};
25315
+ _proto.onKeyUp = function onKeyUp(event) {};
25316
+ _proto.onGotFocus = function onGotFocus() {};
25317
+ _proto.onLostFocus = function onLostFocus() {};
25318
+ /** @internal */ _proto.invokeGetDragData = function invokeGetDragData(position) {
25319
+ return this.getDragData(position);
25320
+ };
25321
+ /** @internal */ _proto.invokeCanDropData = function invokeCanDropData(position, data) {
25322
+ return this.canDropData(position, data);
25323
+ };
25324
+ /** @internal */ _proto.invokeDropData = function invokeDropData(position, data) {
25325
+ this.dropData(position, data);
25326
+ };
25327
+ _proto.getDragData = function getDragData(position) {
25328
+ return null;
25329
+ };
25330
+ _proto.canDropData = function canDropData(position, data) {
25331
+ return false;
25332
+ };
25333
+ _proto.dropData = function dropData(position, data) {};
25334
+ _proto.dispose = function dispose() {
25335
+ if (this.disposed) {
25336
+ return;
25337
+ }
25338
+ this.disposed = true;
25339
+ this.onDestroy();
25340
+ this.parent = null;
25341
+ this.owner = null;
25342
+ };
25343
+ /** @internal */ _proto.updateLayout = function updateLayout() {
25344
+ var _this_parent;
25345
+ var _this_parent_size;
25346
+ var parentSize = (_this_parent_size = (_this_parent = this.parent) == null ? void 0 : _this_parent.size) != null ? _this_parent_size : new Vector2();
25347
+ var left = this.offsetMin.x + this.anchorMin.x * parentSize.x;
25348
+ var bottom = this.offsetMin.y + this.anchorMin.y * parentSize.y;
25349
+ var right = this.offsetMax.x + this.anchorMax.x * parentSize.x;
25350
+ var top = this.offsetMax.y + this.anchorMax.y * parentSize.y;
25351
+ this.applyBounds(left, bottom, right - left, top - bottom);
25352
+ };
25353
+ _proto.applyBounds = function applyBounds(x, y, width, height) {
25354
+ var locationChanged = this.position.x !== x || this.position.y !== y;
25355
+ var sizeChanged = this.size.x !== width || this.size.y !== height;
25356
+ if (!locationChanged && !sizeChanged) {
25357
+ return;
25358
+ }
25359
+ this.position.set(x, y);
25360
+ this.size.set(width, height);
25361
+ this.markTransformDirty();
25362
+ if (locationChanged) {
25363
+ this.eventEmitter.emit("locationChanged", this);
25364
+ }
25365
+ if (sizeChanged) {
25366
+ this.eventEmitter.emit("sizeChanged", this);
25367
+ if (_instanceof1(this, ContainerControl)) {
25368
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.children.slice()), _step; !(_step = _iterator()).done;){
25369
+ var child = _step.value;
25370
+ child.updateLayout();
25371
+ }
25372
+ }
25373
+ }
25374
+ };
25375
+ _proto.markTransformDirty = function markTransformDirty() {
25376
+ var _this_root;
25377
+ this.transformDirty = true;
25378
+ (_this_root = this.root) == null ? void 0 : _this_root.controlTreeChanged();
25379
+ };
25380
+ _proto.getParentRect = function getParentRect() {
25381
+ var _this_parent;
25382
+ var _this_parent_size_clone;
25383
+ return {
25384
+ position: new Vector2(),
25385
+ size: (_this_parent_size_clone = (_this_parent = this.parent) == null ? void 0 : _this_parent.size.clone()) != null ? _this_parent_size_clone : new Vector2()
25386
+ };
25387
+ };
25388
+ _proto.computeOffsets = function computeOffsets(rect, parentRect) {
25389
+ this.offsetMin.set(rect.position.x - parentRect.position.x - this.anchorMin.x * parentRect.size.x, rect.position.y - parentRect.position.y - this.anchorMin.y * parentRect.size.y);
25390
+ this.offsetMax.set(rect.position.x + rect.size.x - parentRect.position.x - this.anchorMax.x * parentRect.size.x, rect.position.y + rect.size.y - parentRect.position.y - this.anchorMax.y * parentRect.size.y);
25391
+ };
25392
+ _proto.computeAnchors = function computeAnchors(rect, parentRect) {
25393
+ if (parentRect.size.x !== 0) {
25394
+ this.anchorMin.x = (rect.position.x - parentRect.position.x - this.offsetMin.x) / parentRect.size.x;
25395
+ this.anchorMax.x = (rect.position.x + rect.size.x - parentRect.position.x - this.offsetMax.x) / parentRect.size.x;
25396
+ }
25397
+ if (parentRect.size.y !== 0) {
25398
+ this.anchorMin.y = (rect.position.y - parentRect.position.y - this.offsetMin.y) / parentRect.size.y;
25399
+ this.anchorMax.y = (rect.position.y + rect.size.y - parentRect.position.y - this.offsetMax.y) / parentRect.size.y;
25400
+ }
25401
+ };
25402
+ _proto.isMouseRecursiveEnabled = function isMouseRecursiveEnabled() {
25403
+ if (this.mouseBehaviorRecursive === exports.MouseBehaviorRecursive.Inherited) {
25404
+ var _this_parent;
25405
+ var _this_parent_isMouseRecursiveEnabled;
25406
+ return (_this_parent_isMouseRecursiveEnabled = (_this_parent = this.parent) == null ? void 0 : _this_parent.isMouseRecursiveEnabled()) != null ? _this_parent_isMouseRecursiveEnabled : true;
25407
+ }
25408
+ return this.mouseBehaviorRecursive === exports.MouseBehaviorRecursive.Enabled;
25409
+ };
25410
+ _proto.isFocusRecursiveEnabled = function isFocusRecursiveEnabled() {
25411
+ if (this.focusBehaviorRecursive === exports.FocusBehaviorRecursive.Inherited) {
25412
+ var _this_parent;
25413
+ var _this_parent_isFocusRecursiveEnabled;
25414
+ return (_this_parent_isFocusRecursiveEnabled = (_this_parent = this.parent) == null ? void 0 : _this_parent.isFocusRecursiveEnabled()) != null ? _this_parent_isFocusRecursiveEnabled : true;
25415
+ }
25416
+ return this.focusBehaviorRecursive === exports.FocusBehaviorRecursive.Enabled;
25417
+ };
25418
+ _create_class(Control, [
25419
+ {
25420
+ key: "parent",
25421
+ get: function get() {
25422
+ return this._parent;
25423
+ },
25424
+ set: function set(value) {
25425
+ var _this__parent;
25426
+ if (value === this._parent) {
25427
+ return;
25428
+ }
25429
+ var previousRoot = this.root;
25430
+ (_this__parent = this._parent) == null ? void 0 : _this__parent.removeChildInternal(this);
25431
+ this._parent = value;
25432
+ value == null ? void 0 : value.addChildInternal(this);
25433
+ this.updateLayout();
25434
+ var nextRoot = this.root;
25435
+ if (previousRoot && previousRoot !== nextRoot) {
25436
+ previousRoot.controlRemoved(this);
25437
+ }
25438
+ nextRoot == null ? void 0 : nextRoot.controlTreeChanged();
25439
+ this.eventEmitter.emit("parentChanged", this);
25440
+ }
25441
+ },
25442
+ {
25443
+ key: "item",
25444
+ get: /** Scene item exposed through the optional UIControl bridge. */ function get() {
25445
+ var _this_owner;
25446
+ var _this_owner_item;
25447
+ return (_this_owner_item = (_this_owner = this.owner) == null ? void 0 : _this_owner.item) != null ? _this_owner_item : null;
25448
+ }
25449
+ },
25450
+ {
25451
+ key: "indexInParent",
25452
+ get: function get() {
25453
+ var _this_parent;
25454
+ var _this_parent_getChildIndex;
25455
+ return (_this_parent_getChildIndex = (_this_parent = this.parent) == null ? void 0 : _this_parent.getChildIndex(this)) != null ? _this_parent_getChildIndex : -1;
25456
+ },
25457
+ set: function set(value) {
25458
+ var _this_parent;
25459
+ (_this_parent = this.parent) == null ? void 0 : _this_parent.changeChildIndex(this, value);
25460
+ }
25461
+ },
25462
+ {
25463
+ key: "visible",
25464
+ get: function get() {
25465
+ return this._visible;
25466
+ },
25467
+ set: function set(value) {
25468
+ if (this._visible !== value) {
25469
+ var _this_root;
25470
+ this._visible = value;
25471
+ (_this_root = this.root) == null ? void 0 : _this_root.controlStateChanged(this);
25472
+ }
25473
+ }
25474
+ },
25475
+ {
25476
+ key: "visibleInHierarchy",
25477
+ get: function get() {
25478
+ var _this_parent;
25479
+ var _this_parent_visibleInHierarchy;
25480
+ return this.visible && ((_this_parent_visibleInHierarchy = (_this_parent = this.parent) == null ? void 0 : _this_parent.visibleInHierarchy) != null ? _this_parent_visibleInHierarchy : true);
25481
+ }
25482
+ },
25483
+ {
25484
+ key: "enabled",
25485
+ get: function get() {
25486
+ return this._enabled;
25487
+ },
25488
+ set: function set(value) {
25489
+ if (this._enabled !== value) {
25490
+ var _this_root;
25491
+ this._enabled = value;
25492
+ (_this_root = this.root) == null ? void 0 : _this_root.controlStateChanged(this);
25493
+ }
25494
+ }
25495
+ },
25496
+ {
25497
+ key: "enabledInHierarchy",
25498
+ get: function get() {
25499
+ var _this_parent;
25500
+ var _this_parent_enabledInHierarchy;
25501
+ return this.enabled && ((_this_parent_enabledInHierarchy = (_this_parent = this.parent) == null ? void 0 : _this_parent.enabledInHierarchy) != null ? _this_parent_enabledInHierarchy : true);
25502
+ }
25503
+ },
25504
+ {
25505
+ key: "mouseFilter",
25506
+ get: function get() {
25507
+ return this._mouseFilter;
25508
+ },
25509
+ set: function set(value) {
25510
+ if (this._mouseFilter !== value) {
25511
+ var _this_root;
25512
+ this._mouseFilter = value;
25513
+ (_this_root = this.root) == null ? void 0 : _this_root.controlStateChanged(this);
25514
+ }
25515
+ }
25516
+ },
25517
+ {
25518
+ key: "mouseBehaviorRecursive",
25519
+ get: function get() {
25520
+ return this._mouseBehaviorRecursive;
25521
+ },
25522
+ set: function set(value) {
25523
+ if (this._mouseBehaviorRecursive !== value) {
25524
+ var _this_root;
25525
+ this._mouseBehaviorRecursive = value;
25526
+ (_this_root = this.root) == null ? void 0 : _this_root.controlStateChanged(this);
25527
+ }
25528
+ }
25529
+ },
25530
+ {
25531
+ key: "focusMode",
25532
+ get: function get() {
25533
+ return this._focusMode;
25534
+ },
25535
+ set: function set(value) {
25536
+ if (this._focusMode !== value) {
25537
+ var _this_root;
25538
+ this._focusMode = value;
25539
+ (_this_root = this.root) == null ? void 0 : _this_root.controlStateChanged(this);
25540
+ }
25541
+ }
25542
+ },
25543
+ {
25544
+ key: "focusBehaviorRecursive",
25545
+ get: function get() {
25546
+ return this._focusBehaviorRecursive;
25547
+ },
25548
+ set: function set(value) {
25549
+ if (this._focusBehaviorRecursive !== value) {
25550
+ var _this_root;
25551
+ this._focusBehaviorRecursive = value;
25552
+ (_this_root = this.root) == null ? void 0 : _this_root.controlStateChanged(this);
25553
+ }
25554
+ }
25555
+ },
25556
+ {
25557
+ key: "defaultCursorShape",
25558
+ get: function get() {
25559
+ return this._defaultCursorShape;
25560
+ },
25561
+ set: function set(value) {
25562
+ this._defaultCursorShape = value;
25563
+ }
25564
+ },
25565
+ {
25566
+ key: "location",
25567
+ get: function get() {
25568
+ return this.position;
25569
+ },
25570
+ set: function set(value) {
25571
+ this.setPosition(value.x, value.y);
25572
+ }
25573
+ },
25574
+ {
25575
+ key: "rotation",
25576
+ get: function get() {
25577
+ return this._rotation;
25578
+ }
25579
+ },
25580
+ {
25581
+ key: "x",
25582
+ get: function get() {
25583
+ return this.position.x;
25584
+ },
25585
+ set: function set(value) {
25586
+ this.setPosition(value, this.position.y);
25587
+ }
25588
+ },
25589
+ {
25590
+ key: "y",
25591
+ get: function get() {
25592
+ return this.position.y;
25593
+ },
25594
+ set: function set(value) {
25595
+ this.setPosition(this.position.x, value);
25596
+ }
25597
+ },
25598
+ {
25599
+ key: "width",
25600
+ get: function get() {
25601
+ return this.size.x;
25602
+ },
25603
+ set: function set(value) {
25604
+ this.setSize(value, this.size.y);
25605
+ }
25606
+ },
25607
+ {
25608
+ key: "height",
25609
+ get: function get() {
25610
+ return this.size.y;
25611
+ },
25612
+ set: function set(value) {
25613
+ this.setSize(this.size.x, value);
25614
+ }
25615
+ },
25616
+ {
25617
+ key: "root",
25618
+ get: function get() {
25619
+ var _this_parent;
25620
+ var _this_parent_root;
25621
+ return _instanceof1(this, RootControl) ? this : (_this_parent_root = (_this_parent = this.parent) == null ? void 0 : _this_parent.root) != null ? _this_parent_root : null;
25622
+ }
25623
+ },
25624
+ {
25625
+ key: "isDisposed",
25626
+ get: function get() {
25627
+ return this.disposed;
25628
+ }
25629
+ }
25630
+ ]);
25631
+ return Control;
25632
+ }();
25633
+ /** A Control that owns child Controls. */ var ContainerControl = /*#__PURE__*/ function(Control) {
25634
+ _inherits(ContainerControl, Control);
25635
+ function ContainerControl() {
25636
+ var _this;
25637
+ _this = Control.apply(this, arguments) || this;
25638
+ _this.children = [];
25639
+ return _this;
25640
+ }
25641
+ var _proto = ContainerControl.prototype;
25642
+ _proto.addChild = function addChild(child) {
25643
+ child.parent = this;
25644
+ return child;
25645
+ };
25646
+ _proto.removeChild = function removeChild(child) {
25647
+ if (child.parent === this) {
25648
+ child.parent = null;
25649
+ }
25650
+ };
25651
+ _proto.getChildIndex = function getChildIndex(child) {
25652
+ return this.children.indexOf(child);
25653
+ };
25654
+ /** @internal */ _proto.changeChildIndex = function changeChildIndex(child, newIndex) {
25655
+ var _this_root;
25656
+ var oldIndex = this.children.indexOf(child);
25657
+ if (oldIndex === newIndex || oldIndex === -1) {
25658
+ return;
25659
+ }
25660
+ this.children.splice(oldIndex, 1);
25661
+ if (newIndex < 0 || newIndex >= this.children.length) {
25662
+ this.children.push(child);
25663
+ } else {
25664
+ this.children.splice(newIndex, 0, child);
25665
+ }
25666
+ (_this_root = this.root) == null ? void 0 : _this_root.controlTreeChanged();
25667
+ };
25668
+ /** @internal */ _proto.addChildInternal = function addChildInternal(child) {
25669
+ if (!this.children.includes(child)) {
25670
+ this.children.push(child);
25671
+ }
25672
+ };
25673
+ /** @internal */ _proto.removeChildInternal = function removeChildInternal(child) {
25674
+ var index = this.children.indexOf(child);
25675
+ if (index !== -1) {
25676
+ this.children.splice(index, 1);
25677
+ }
25678
+ };
25679
+ _proto.drawSelf = function drawSelf() {
25680
+ Control.prototype.draw.call(this);
25681
+ };
25682
+ _proto.draw = function draw() {
25683
+ this.drawSelf();
25684
+ this.drawChildren();
25685
+ };
25686
+ _proto.drawChildren = function drawChildren() {
25687
+ var graphics = this.engine.graphics;
25688
+ if (this.clipContents) ;
25689
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.children), _step; !(_step = _iterator()).done;){
25690
+ var child = _step.value;
25691
+ if (!child.visible || child.isDisposed) {
25692
+ continue;
25693
+ }
25694
+ graphics.pushTransform(child.getTransform2D());
25695
+ child.draw();
25696
+ graphics.popTransform();
25697
+ }
25698
+ };
25699
+ _proto.update = function update(deltaTime) {
25700
+ Control.prototype.update.call(this, deltaTime);
25701
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.children.slice()), _step; !(_step = _iterator()).done;){
25702
+ var child = _step.value;
25703
+ if (child.enabled && !child.isDisposed) {
25704
+ child.update(deltaTime);
25705
+ }
25706
+ }
25707
+ };
25708
+ _proto.dispose = function dispose() {
25709
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.children.slice()), _step; !(_step = _iterator()).done;){
25710
+ var child = _step.value;
25711
+ child.dispose();
25712
+ }
25713
+ Control.prototype.dispose.call(this);
25714
+ };
25715
+ return ContainerControl;
25716
+ }(Control);
25717
+ /** Base class for GUI tree roots and input dispatchers. */ var RootControl = /*#__PURE__*/ function(ContainerControl) {
25718
+ _inherits(RootControl, ContainerControl);
25719
+ function RootControl() {
25720
+ return ContainerControl.apply(this, arguments);
25721
+ }
25722
+ return RootControl;
25723
+ }(ContainerControl);
25724
+
25725
+ var _obj$4;
25726
+ var cursorNames = (_obj$4 = {}, _obj$4[exports.CursorShape.Arrow] = "default", _obj$4[exports.CursorShape.Ibeam] = "text", _obj$4[exports.CursorShape.PointingHand] = "pointer", _obj$4[exports.CursorShape.Cross] = "crosshair", _obj$4[exports.CursorShape.Wait] = "wait", _obj$4[exports.CursorShape.Busy] = "progress", _obj$4[exports.CursorShape.Drag] = "grab", _obj$4[exports.CursorShape.CanDrop] = "copy", _obj$4[exports.CursorShape.Forbidden] = "not-allowed", _obj$4[exports.CursorShape.Vsize] = "ns-resize", _obj$4[exports.CursorShape.Hsize] = "ew-resize", _obj$4[exports.CursorShape.Bdiagsize] = "nesw-resize", _obj$4[exports.CursorShape.Fdiagsize] = "nwse-resize", _obj$4[exports.CursorShape.Move] = "move", _obj$4[exports.CursorShape.Vsplit] = "row-resize", _obj$4[exports.CursorShape.Hsplit] = "col-resize", _obj$4[exports.CursorShape.Help] = "help", _obj$4);
25727
+ function getButtonMask(button) {
25728
+ switch(button){
25729
+ case exports.MouseButton.Left:
25730
+ return exports.MouseButtonMask.Left;
25731
+ case exports.MouseButton.Right:
25732
+ return exports.MouseButtonMask.Right;
25733
+ case exports.MouseButton.Middle:
25734
+ return exports.MouseButtonMask.Middle;
25735
+ case exports.MouseButton.Xbutton1:
25736
+ return exports.MouseButtonMask.Xbutton1;
25737
+ case exports.MouseButton.Xbutton2:
25738
+ return exports.MouseButtonMask.Xbutton2;
25739
+ default:
25740
+ return exports.MouseButtonMask.None;
25741
+ }
25742
+ }
25743
+ function isWheelButton(button) {
25744
+ return button >= exports.MouseButton.WheelUp && button <= exports.MouseButton.WheelRight;
25745
+ }
25746
+ function getWheelDelta(event) {
25747
+ return event.buttonIndex === exports.MouseButton.WheelUp || event.buttonIndex === exports.MouseButton.WheelLeft ? event.factor : -event.factor;
25748
+ }
25749
+ /** CanvasLayer-like boundary for a single UICanvas GUI tree. */ var CanvasRootControl = /*#__PURE__*/ function(ContainerControl) {
25750
+ _inherits(CanvasRootControl, ContainerControl);
25751
+ function CanvasRootControl(engine, canvas) {
25752
+ var _this;
25753
+ _this = ContainerControl.call(this, engine) || this;
25754
+ _this.canvas = canvas;
25755
+ _this.mouseFilter = exports.MouseFilter.Ignore;
25756
+ _this.setSize(engine.canvas.width, engine.canvas.height);
25757
+ return _this;
25758
+ }
25759
+ _create_class(CanvasRootControl, [
25760
+ {
25761
+ key: "inputDisabled",
25762
+ get: function get() {
25763
+ var _this_canvas_item;
25764
+ return !this.canvas.receivesEvents || !this.canvas.enabled || !((_this_canvas_item = this.canvas.item) == null ? void 0 : _this_canvas_item.isActive);
25765
+ }
25766
+ }
25767
+ ]);
25768
+ return CanvasRootControl;
25769
+ }(ContainerControl);
25770
+ /** Global ordered collection of UICanvas roots. */ var CanvasContainer = /*#__PURE__*/ function(ContainerControl) {
25771
+ _inherits(CanvasContainer, ContainerControl);
25772
+ function CanvasContainer(engine) {
25773
+ var _this;
25774
+ _this = ContainerControl.call(this, engine) || this;
25775
+ _this.mouseFilter = exports.MouseFilter.Ignore;
25776
+ _this.setSize(engine.canvas.width, engine.canvas.height);
25777
+ return _this;
25778
+ }
25779
+ var _proto = CanvasContainer.prototype;
25780
+ _proto.sortCanvases = function sortCanvases() {
25781
+ this.children.sort(function(left, right) {
25782
+ return left.canvas.order - right.canvas.order;
25783
+ });
25784
+ };
25785
+ _proto.addChildInternal = function addChildInternal(child) {
25786
+ ContainerControl.prototype.addChildInternal.call(this, child);
25787
+ this.sortCanvases();
25788
+ };
25789
+ _proto.draw = function draw() {
25790
+ this.sortCanvases();
25791
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.children), _step; !(_step = _iterator()).done;){
25792
+ var child = _step.value;
25793
+ var root = child;
25794
+ if (root.canvas.isVisible) {
25795
+ root.draw();
25796
+ }
25797
+ }
25798
+ };
25799
+ return CanvasContainer;
25800
+ }(ContainerControl);
25801
+ /** Engine window GUI root. Routes events across all UICanvas roots. */ var WindowRootControl = /*#__PURE__*/ function(RootControl) {
25802
+ _inherits(WindowRootControl, RootControl);
25803
+ function WindowRootControl(engine) {
25804
+ var _this;
25805
+ _this = RootControl.call(this, engine) || this;
25806
+ _this.dragThreshold = 10;
25807
+ _this.inputHandled = false;
25808
+ _this.gui = {
25809
+ mouseFocus: null,
25810
+ mouseClickGrabber: null,
25811
+ mouseFocusMask: exports.MouseButtonMask.None,
25812
+ mouseOver: null,
25813
+ mouseOverHierarchy: [],
25814
+ touchFocus: new Map(),
25815
+ keyFocus: null,
25816
+ dragAccum: new Vector2(),
25817
+ dragAttempted: false,
25818
+ dragging: false,
25819
+ dragData: null,
25820
+ dragMouseOver: null,
25821
+ dragSuccessful: false,
25822
+ lastMousePosition: new Vector2(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY),
25823
+ sendingMouseEnterExit: false,
25824
+ mouseOverUpdatePending: false
25825
+ };
25826
+ _this.mouseFilter = exports.MouseFilter.Ignore;
25827
+ _this.setSize(engine.canvas.width, engine.canvas.height);
25828
+ _this.canvases = new CanvasContainer(engine);
25829
+ _this.canvases.parent = _assert_this_initialized(_this);
25830
+ return _this;
25831
+ }
25832
+ var _proto = WindowRootControl.prototype;
25833
+ _proto.pushInput = function pushInput(event) {
25834
+ this.inputHandled = false;
25835
+ this.cleanupInternalState();
25836
+ this.processGUIInput(event);
25837
+ this.postGrabClickFocus();
25838
+ };
25839
+ _proto.isInputHandled = function isInputHandled() {
25840
+ return this.inputHandled;
25841
+ };
25842
+ _proto.getMousePosition = function getMousePosition() {
25843
+ return this.gui.lastMousePosition.clone();
25844
+ };
25845
+ _proto.guiGetFocusOwner = function guiGetFocusOwner() {
25846
+ return this.isFocusTargetUsable(this.gui.keyFocus) ? this.gui.keyFocus : null;
25847
+ };
25848
+ _proto.guiReleaseFocus = function guiReleaseFocus() {
25849
+ this.releaseControlFocus();
25850
+ };
25851
+ _proto.guiIsDragging = function guiIsDragging() {
25852
+ return this.gui.dragging;
25853
+ };
25854
+ _proto.guiGetDragData = function guiGetDragData() {
25855
+ return this.gui.dragData;
25856
+ };
25857
+ _proto.guiIsDragSuccessful = function guiIsDragSuccessful() {
25858
+ return this.gui.dragSuccessful;
25859
+ };
25860
+ _proto.guiCancelDrag = function guiCancelDrag() {
25861
+ this.endDragging(false);
25862
+ };
25863
+ _proto.acceptControlEvent = function acceptControlEvent(control) {
25864
+ if (this.isControlUsable(control)) {
25865
+ this.inputHandled = true;
25866
+ }
25867
+ };
25868
+ _proto.grabControlFocus = function grabControlFocus(control) {
25869
+ if (!this.isFocusTargetUsable(control) || this.gui.keyFocus === control) {
25870
+ return;
25871
+ }
25872
+ var previous = this.gui.keyFocus;
25873
+ this.gui.keyFocus = control;
25874
+ if (previous && !previous.isDisposed) {
25875
+ previous.onLostFocus();
25876
+ }
25877
+ control.onGotFocus();
25878
+ };
25879
+ _proto.grabControlClickFocus = function grabControlClickFocus(control) {
25880
+ var _this = this;
25881
+ if (this.isControlValid(control)) {
25882
+ this.gui.mouseClickGrabber = control;
25883
+ queueMicrotask(function() {
25884
+ return _this.postGrabClickFocus();
25885
+ });
25886
+ }
25887
+ };
25888
+ _proto.releaseControlFocus = function releaseControlFocus(control) {
25889
+ var previous = this.gui.keyFocus;
25890
+ if (!previous || control && previous !== control) {
25891
+ return;
25892
+ }
25893
+ this.gui.keyFocus = null;
25894
+ if (!previous.isDisposed) {
25895
+ previous.onLostFocus();
25896
+ }
25897
+ };
25898
+ _proto.warpControlMouse = function warpControlMouse(position) {
25899
+ this.gui.lastMousePosition.copyFrom(position);
25900
+ this.updateMouseOver(position);
25901
+ };
25902
+ _proto.controlStateChanged = function controlStateChanged(control) {
25903
+ if (!this.isControlUsable(control)) {
25904
+ this.dropControlState(control);
25905
+ }
25906
+ this.requestMouseOverUpdate();
25907
+ };
25908
+ _proto.controlRemoved = function controlRemoved(control) {
25909
+ this.dropControlState(control);
25910
+ this.cleanupInternalState();
25911
+ this.requestMouseOverUpdate();
25912
+ };
25913
+ _proto.controlTreeChanged = function controlTreeChanged() {
25914
+ this.requestMouseOverUpdate();
25915
+ };
25916
+ _proto.cancelPointerInput = function cancelPointerInput() {
25917
+ this.dropMouseFocus();
25918
+ this.dropMouseOver();
25919
+ this.gui.touchFocus.clear();
25920
+ this.endDragging(false);
25921
+ this.releaseControlFocus();
25922
+ };
25923
+ _proto.resize = function resize(width, height) {
25924
+ this.setSize(width, height);
25925
+ this.canvases.setSize(width, height);
25926
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.canvases.children), _step; !(_step = _iterator()).done;){
25927
+ var root = _step.value;
25928
+ root.setSize(width, height);
25929
+ }
25930
+ };
25931
+ _proto.render = function render() {
25932
+ if (this.canvases.children.length === 0) {
25933
+ return;
25934
+ }
25935
+ this.engine.graphics.begin();
25936
+ this.draw();
25937
+ this.engine.graphics.end();
25938
+ };
25939
+ _proto.update = function update(deltaTime) {
25940
+ if (this.gui.mouseOverUpdatePending) {
25941
+ this.gui.mouseOverUpdatePending = false;
25942
+ this.updateMouseOver(this.gui.lastMousePosition);
25943
+ }
25944
+ RootControl.prototype.update.call(this, deltaTime);
25945
+ };
25946
+ _proto.dispose = function dispose() {
25947
+ this.cancelPointerInput();
25948
+ RootControl.prototype.dispose.call(this);
25949
+ };
25950
+ _proto.processGUIInput = function processGUIInput(event) {
25951
+ if (_instanceof1(event, InputEventKey)) {
25952
+ var target = this.guiGetFocusOwner();
25953
+ if (target) {
25954
+ this.callControlInput(target, event);
25955
+ }
25956
+ } else if (_instanceof1(event, InputEventMouse)) {
25957
+ this.gui.lastMousePosition.copyFrom(event.globalPosition);
25958
+ this.updateMouseOver(event.globalPosition);
25959
+ if (_instanceof1(event, InputEventMouseButton)) {
25960
+ this.processMouseButton(event);
25961
+ } else if (_instanceof1(event, InputEventMouseMotion)) {
25962
+ this.processMouseMotion(event);
25963
+ }
25964
+ } else if (_instanceof1(event, InputEventScreenTouch)) {
25965
+ this.processScreenTouch(event);
25966
+ } else if (_instanceof1(event, InputEventScreenDrag)) {
25967
+ this.processScreenDrag(event);
25968
+ }
25969
+ };
25970
+ _proto.processMouseButton = function processMouseButton(event) {
25971
+ if (isWheelButton(event.buttonIndex)) {
25972
+ var target = this.findInputControl(event.globalPosition);
25973
+ if (target) {
25974
+ this.callGUIInput(target, event);
25975
+ }
25976
+ return;
25977
+ }
25978
+ var mask = getButtonMask(event.buttonIndex);
25979
+ if (event.isPressed()) {
25980
+ var target1 = this.gui.mouseFocusMask !== 0 ? this.gui.mouseFocus : this.findInputControl(event.globalPosition);
25981
+ this.gui.mouseFocus = target1;
25982
+ if (!target1) {
25983
+ return;
25984
+ }
25985
+ this.gui.mouseFocusMask |= mask;
25986
+ if (event.buttonIndex === exports.MouseButton.Left) {
25987
+ this.gui.dragAccum.setZero();
25988
+ this.gui.dragAttempted = false;
25989
+ this.findClickFocus(target1);
25990
+ }
25991
+ this.callGUIInput(target1, event);
25992
+ } else {
25993
+ if (event.buttonIndex === exports.MouseButton.Left && this.gui.dragging) {
25994
+ this.finishDrop(event.globalPosition);
25995
+ }
25996
+ this.gui.mouseFocusMask &= ~mask;
25997
+ var target2 = this.gui.mouseFocus;
25998
+ if (this.gui.mouseFocusMask === 0) {
25999
+ this.gui.mouseFocus = null;
26000
+ }
26001
+ if (this.isControlUsable(target2)) {
26002
+ this.callGUIInput(target2, event);
26003
+ }
26004
+ }
26005
+ };
26006
+ _proto.processMouseMotion = function processMouseMotion(event) {
26007
+ if (!this.gui.dragging && !this.gui.dragAttempted && this.gui.mouseFocus && (this.gui.mouseFocusMask & exports.MouseButtonMask.Left) !== 0) {
26008
+ this.gui.dragAccum.add(event.relative);
26009
+ if (this.gui.dragAccum.length() > this.dragThreshold) {
26010
+ var origin = event.globalPosition.clone().subtract(this.gui.dragAccum);
26011
+ this.beginDragging(this.gui.mouseFocus, origin);
26012
+ this.gui.dragAttempted = true;
26013
+ }
26014
+ }
26015
+ var target = this.isControlUsable(this.gui.mouseFocus) ? this.gui.mouseFocus : this.findInputControl(event.globalPosition);
26016
+ if (target) {
26017
+ this.callGUIInput(target, event);
26018
+ }
26019
+ if (this.gui.dragging) {
26020
+ this.gui.dragMouseOver = this.findDropTarget(this.findInputControl(event.globalPosition), event.globalPosition);
26021
+ }
26022
+ this.updateCursor(target, event.globalPosition);
26023
+ };
26024
+ _proto.processScreenTouch = function processScreenTouch(event) {
26025
+ var target;
26026
+ if (event.isPressed()) {
26027
+ target = this.findInputControl(event.position);
26028
+ if (target) {
26029
+ this.gui.touchFocus.set(event.index, target);
26030
+ }
26031
+ } else {
26032
+ var _this_gui_touchFocus_get;
26033
+ target = (_this_gui_touchFocus_get = this.gui.touchFocus.get(event.index)) != null ? _this_gui_touchFocus_get : null;
26034
+ this.gui.touchFocus.delete(event.index);
26035
+ }
26036
+ if (this.isControlUsable(target)) {
26037
+ this.callGUIInput(target, event);
26038
+ }
26039
+ };
26040
+ _proto.processScreenDrag = function processScreenDrag(event) {
26041
+ var _this_gui_touchFocus_get;
26042
+ var target = (_this_gui_touchFocus_get = this.gui.touchFocus.get(event.index)) != null ? _this_gui_touchFocus_get : this.findInputControl(event.position);
26043
+ if (this.isControlUsable(target)) {
26044
+ this.callGUIInput(target, event);
26045
+ }
26046
+ };
26047
+ _proto.callGUIInput = function callGUIInput(target, event) {
26048
+ var current = target;
26049
+ var pointerEvent = _instanceof1(event, InputEventMouse) || _instanceof1(event, InputEventScreenTouch) || _instanceof1(event, InputEventScreenDrag);
26050
+ while(current && current !== this && this.isControlUsable(current)){
26051
+ var filter = current.getEffectiveMouseFilter();
26052
+ if (filter !== exports.MouseFilter.Ignore) {
26053
+ this.callControlInput(current, event.xformedBy(this.getGlobalInverse(current)));
26054
+ }
26055
+ var forcePassWheel = _instanceof1(event, InputEventMouseButton) && isWheelButton(event.buttonIndex) && current.mouseForcePassScrollEvents;
26056
+ if (this.inputHandled || filter === exports.MouseFilter.Stop && pointerEvent && !forcePassWheel) {
26057
+ this.inputHandled = true;
26058
+ return;
26059
+ }
26060
+ current = current.parent;
26061
+ }
26062
+ };
26063
+ _proto.callControlInput = function callControlInput(control, event) {
26064
+ if (_instanceof1(event, InputEventMouseButton)) {
26065
+ if (isWheelButton(event.buttonIndex)) {
26066
+ control.onMouseWheel(event.position, getWheelDelta(event), event);
26067
+ } else if (event.isPressed()) {
26068
+ control.onMouseDown(event.position, event.buttonIndex, event);
26069
+ } else {
26070
+ control.onMouseUp(event.position, event.buttonIndex, event);
26071
+ }
26072
+ } else if (_instanceof1(event, InputEventMouseMotion)) {
26073
+ control.onMouseMove(event.position, event);
26074
+ } else if (_instanceof1(event, InputEventScreenTouch)) {
26075
+ if (event.isPressed()) {
26076
+ control.onTouchDown(event.position, event.index, event);
26077
+ } else {
26078
+ control.onTouchUp(event.position, event.index, event);
26079
+ }
26080
+ } else if (_instanceof1(event, InputEventScreenDrag)) {
26081
+ control.onTouchMove(event.position, event.index, event);
26082
+ } else if (_instanceof1(event, InputEventKey)) {
26083
+ if (event.isPressed()) {
26084
+ control.onKeyDown(event);
26085
+ } else if (event.isReleased()) {
26086
+ control.onKeyUp(event);
26087
+ }
26088
+ }
26089
+ };
26090
+ _proto.findInputControl = function findInputControl(position) {
26091
+ this.canvases.sortCanvases();
26092
+ for(var index = this.canvases.children.length - 1; index >= 0; index--){
26093
+ var root = this.canvases.children[index];
26094
+ if (!root.canvas.isVisible || root.inputDisabled) {
26095
+ continue;
26096
+ }
26097
+ var target = this.findControlAtPosition(root, position, true);
26098
+ if (target) {
26099
+ return target;
26100
+ }
26101
+ }
26102
+ return null;
26103
+ };
26104
+ _proto.findControlAtPosition = function findControlAtPosition(container, position, skipSelf) {
26105
+ if (skipSelf === void 0) skipSelf = false;
26106
+ if (!container.visibleInHierarchy || container.isDisposed) {
26107
+ return null;
26108
+ }
26109
+ var localPosition = this.toLocal(container, position);
26110
+ if (container.clipContents && !container.hasPoint(localPosition)) {
26111
+ return null;
26112
+ }
26113
+ for(var index = container.children.length - 1; index >= 0; index--){
26114
+ var child = container.children[index];
26115
+ if (!child.visibleInHierarchy || child.isDisposed) {
26116
+ continue;
26117
+ }
26118
+ if (_instanceof1(child, ContainerControl)) {
26119
+ var found = this.findControlAtPosition(child, position);
26120
+ if (found) {
26121
+ return found;
26122
+ }
26123
+ } else if (child.getEffectiveMouseFilter() !== exports.MouseFilter.Ignore && child.hasPoint(this.toLocal(child, position))) {
26124
+ return child;
26125
+ }
26126
+ }
26127
+ if (!skipSelf && container.getEffectiveMouseFilter() !== exports.MouseFilter.Ignore && container.hasPoint(localPosition)) {
26128
+ return container;
26129
+ }
26130
+ return null;
26131
+ };
26132
+ _proto.updateMouseOver = function updateMouseOver(position) {
26133
+ if (this.gui.sendingMouseEnterExit) {
26134
+ this.gui.mouseOverUpdatePending = true;
26135
+ return;
26136
+ }
26137
+ this.gui.mouseOverUpdatePending = false;
26138
+ var target = this.findInputControl(position);
26139
+ var next = this.buildHoverHierarchy(target);
26140
+ var previous = this.gui.mouseOverHierarchy;
26141
+ var common = 0;
26142
+ while(common < previous.length && common < next.length && previous[common] === next[common]){
26143
+ common++;
26144
+ }
26145
+ this.gui.sendingMouseEnterExit = true;
26146
+ for(var index = previous.length - 1; index >= common; index--){
26147
+ if (!previous[index].isDisposed) {
26148
+ previous[index].onMouseLeave();
26149
+ }
26150
+ }
26151
+ for(var index1 = common; index1 < next.length; index1++){
26152
+ next[index1].onMouseEnter(this.toLocal(next[index1], position));
26153
+ }
26154
+ this.gui.sendingMouseEnterExit = false;
26155
+ this.gui.mouseOver = target;
26156
+ this.gui.mouseOverHierarchy = next;
26157
+ };
26158
+ _proto.buildHoverHierarchy = function buildHoverHierarchy(target) {
26159
+ var hierarchy = [];
26160
+ var current = target;
26161
+ while(current && current !== this){
26162
+ if (current.getEffectiveMouseFilter() !== exports.MouseFilter.Ignore) {
26163
+ hierarchy.push(current);
26164
+ }
26165
+ if (current.getEffectiveMouseFilter() === exports.MouseFilter.Stop) {
26166
+ break;
26167
+ }
26168
+ current = current.parent;
26169
+ }
26170
+ hierarchy.reverse();
26171
+ return hierarchy;
26172
+ };
26173
+ _proto.findClickFocus = function findClickFocus(target) {
26174
+ var current = target;
26175
+ while(current && current !== this){
26176
+ var mode = current.getFocusModeWithOverride();
26177
+ if (mode === exports.FocusMode.Click || mode === exports.FocusMode.All) {
26178
+ this.grabControlFocus(current);
26179
+ return;
26180
+ }
26181
+ if (current.getEffectiveMouseFilter() === exports.MouseFilter.Stop) {
26182
+ return;
26183
+ }
26184
+ current = current.parent;
26185
+ }
26186
+ };
26187
+ _proto.beginDragging = function beginDragging(source, position) {
26188
+ var current = source;
26189
+ while(current && current !== this){
26190
+ var data = current.invokeGetDragData(this.toLocal(current, position));
26191
+ if (data !== null && data !== undefined) {
26192
+ this.gui.dragging = true;
26193
+ this.gui.dragData = data;
26194
+ this.gui.mouseFocus = null;
26195
+ this.gui.mouseFocusMask = exports.MouseButtonMask.None;
26196
+ return;
26197
+ }
26198
+ if (current.getEffectiveMouseFilter() === exports.MouseFilter.Stop) {
26199
+ return;
26200
+ }
26201
+ current = current.parent;
26202
+ }
26203
+ };
26204
+ _proto.finishDrop = function finishDrop(position) {
26205
+ var target = this.findDropTarget(this.findInputControl(position), position);
26206
+ if (target) {
26207
+ target.invokeDropData(this.toLocal(target, position), this.gui.dragData);
26208
+ }
26209
+ this.endDragging(!!target);
26210
+ };
26211
+ _proto.findDropTarget = function findDropTarget(target, position) {
26212
+ var current = target;
26213
+ while(current && current !== this){
26214
+ if (current.invokeCanDropData(this.toLocal(current, position), this.gui.dragData)) {
26215
+ return current;
26216
+ }
26217
+ if (current.getEffectiveMouseFilter() === exports.MouseFilter.Stop) {
26218
+ return null;
26219
+ }
26220
+ current = current.parent;
26221
+ }
26222
+ return null;
26223
+ };
26224
+ _proto.endDragging = function endDragging(successful) {
26225
+ this.gui.dragSuccessful = successful;
26226
+ this.gui.dragging = false;
26227
+ this.gui.dragData = null;
26228
+ this.gui.dragMouseOver = null;
26229
+ };
26230
+ _proto.updateCursor = function updateCursor(target, position) {
26231
+ var current = target;
26232
+ var shape = exports.CursorShape.Arrow;
26233
+ while(current && current !== this){
26234
+ var candidate = current.getCursorShape(this.toLocal(current, position));
26235
+ if (candidate !== exports.CursorShape.Arrow) {
26236
+ shape = candidate;
26237
+ break;
26238
+ }
26239
+ if (current.getEffectiveMouseFilter() === exports.MouseFilter.Stop) {
26240
+ break;
26241
+ }
26242
+ current = current.parent;
26243
+ }
26244
+ this.engine.canvas.style.cursor = cursorNames[shape];
26245
+ };
26246
+ _proto.postGrabClickFocus = function postGrabClickFocus() {
26247
+ var target = this.gui.mouseClickGrabber;
26248
+ this.gui.mouseClickGrabber = null;
26249
+ if (this.isControlUsable(target)) {
26250
+ this.gui.mouseFocus = target;
26251
+ }
26252
+ };
26253
+ _proto.cleanupInternalState = function cleanupInternalState() {
26254
+ if (!this.isControlUsable(this.gui.mouseFocus)) {
26255
+ this.dropMouseFocus();
26256
+ }
26257
+ if (this.gui.keyFocus && !this.isFocusTargetUsable(this.gui.keyFocus)) {
26258
+ this.releaseControlFocus(this.gui.keyFocus);
26259
+ }
26260
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.gui.touchFocus), _step; !(_step = _iterator()).done;){
26261
+ var _step_value = _step.value, index = _step_value[0], control = _step_value[1];
26262
+ if (!this.isControlUsable(control)) {
26263
+ this.gui.touchFocus.delete(index);
26264
+ }
26265
+ }
26266
+ };
26267
+ _proto.dropMouseFocus = function dropMouseFocus() {
26268
+ this.gui.mouseFocus = null;
26269
+ this.gui.mouseFocusMask = exports.MouseButtonMask.None;
26270
+ };
26271
+ _proto.dropMouseOver = function dropMouseOver() {
26272
+ for(var index = this.gui.mouseOverHierarchy.length - 1; index >= 0; index--){
26273
+ var control = this.gui.mouseOverHierarchy[index];
26274
+ if (!control.isDisposed) {
26275
+ control.onMouseLeave();
26276
+ }
26277
+ }
26278
+ this.gui.mouseOver = null;
26279
+ this.gui.mouseOverHierarchy = [];
26280
+ };
26281
+ _proto.dropControlState = function dropControlState(control) {
26282
+ if (this.controlBelongsToSubtree(this.gui.mouseFocus, control)) {
26283
+ this.dropMouseFocus();
26284
+ }
26285
+ if (this.controlBelongsToSubtree(this.gui.mouseClickGrabber, control)) {
26286
+ this.gui.mouseClickGrabber = null;
26287
+ }
26288
+ if (this.controlBelongsToSubtree(this.gui.keyFocus, control)) {
26289
+ var _this_gui_keyFocus;
26290
+ this.releaseControlFocus((_this_gui_keyFocus = this.gui.keyFocus) != null ? _this_gui_keyFocus : undefined);
26291
+ }
26292
+ if (this.controlBelongsToSubtree(this.gui.mouseOver, control)) {
26293
+ this.dropMouseOver();
26294
+ }
26295
+ if (this.controlBelongsToSubtree(this.gui.dragMouseOver, control)) {
26296
+ this.gui.dragMouseOver = null;
26297
+ }
26298
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.gui.touchFocus), _step; !(_step = _iterator()).done;){
26299
+ var _step_value = _step.value, index = _step_value[0], target = _step_value[1];
26300
+ if (this.controlBelongsToSubtree(target, control)) {
26301
+ this.gui.touchFocus.delete(index);
26302
+ }
26303
+ }
26304
+ };
26305
+ _proto.requestMouseOverUpdate = function requestMouseOverUpdate() {
26306
+ if (Number.isFinite(this.gui.lastMousePosition.x)) {
26307
+ this.updateMouseOver(this.gui.lastMousePosition);
26308
+ }
26309
+ };
26310
+ _proto.getGlobalInverse = function getGlobalInverse(control) {
26311
+ var transform = control.getGlobalTransform2D().clone();
26312
+ return Math.abs(transform.determinant()) < 1e-12 ? new Matrix3() : transform.invert();
26313
+ };
26314
+ _proto.toLocal = function toLocal(control, position) {
26315
+ var elements = this.getGlobalInverse(control).elements;
26316
+ return new Vector2(elements[0] * position.x + elements[3] * position.y + elements[6], elements[1] * position.x + elements[4] * position.y + elements[7]);
26317
+ };
26318
+ _proto.controlBelongsToSubtree = function controlBelongsToSubtree(control, subtree) {
26319
+ var current = control;
26320
+ while(current){
26321
+ if (current === subtree) {
26322
+ return true;
26323
+ }
26324
+ current = current.parent;
26325
+ }
26326
+ return false;
26327
+ };
26328
+ _proto.isControlValid = function isControlValid(control) {
26329
+ return !!control && !control.isDisposed && control.root === this;
26330
+ };
26331
+ _proto.isControlUsable = function isControlUsable(control) {
26332
+ if (!this.isControlValid(control) || !control.visibleInHierarchy || !control.enabledInHierarchy) {
26333
+ return false;
26334
+ }
26335
+ var root = this.findCanvasRoot(control);
26336
+ return !root || !root.inputDisabled;
26337
+ };
26338
+ _proto.findCanvasRoot = function findCanvasRoot(control) {
26339
+ var current = control;
26340
+ while(current && current !== this){
26341
+ if (_instanceof1(current, CanvasRootControl)) {
26342
+ return current;
26343
+ }
26344
+ current = current.parent;
26345
+ }
26346
+ return null;
26347
+ };
26348
+ _proto.isFocusTargetUsable = function isFocusTargetUsable(control) {
26349
+ return this.isControlUsable(control) && control.getFocusModeWithOverride() !== exports.FocusMode.None;
26350
+ };
26351
+ return WindowRootControl;
26352
+ }(RootControl);
26353
+
26354
+ exports.CanvasRenderMode = void 0;
26355
+ (function(CanvasRenderMode) {
26356
+ CanvasRenderMode[CanvasRenderMode["ScreenSpace"] = 0] = "ScreenSpace";
26357
+ CanvasRenderMode[CanvasRenderMode["CameraSpace"] = 1] = "CameraSpace";
26358
+ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
26359
+ CanvasRenderMode[CanvasRenderMode["WorldSpaceFaceCamera"] = 3] = "WorldSpaceFaceCamera";
26360
+ })(exports.CanvasRenderMode || (exports.CanvasRenderMode = {}));
26361
+ /** Canvas-layer boundary attached to a VFXItem. Input state remains owned by the window root. */ var UICanvas = /*#__PURE__*/ function(Component) {
26362
+ _inherits(UICanvas, Component);
26363
+ function UICanvas(engine) {
26364
+ var _this;
26365
+ _this = Component.call(this, engine) || this;
26366
+ _this.renderMode = 0;
26367
+ _this.receivesEvents = true;
26368
+ _this._order = 0;
26369
+ _this.registered = false;
26370
+ _this.rootControl = new CanvasRootControl(engine, _assert_this_initialized(_this));
26371
+ return _this;
26372
+ }
26373
+ var _proto = UICanvas.prototype;
26374
+ _proto.onEnable = function onEnable() {
26375
+ this.register();
26376
+ };
26377
+ _proto.onDisable = function onDisable() {
26378
+ this.unregister();
26379
+ };
26380
+ _proto.onDestroy = function onDestroy() {
26381
+ this.destroyCanvas();
26382
+ };
26383
+ _proto.dispose = function dispose() {
26384
+ this.destroyCanvas();
26385
+ Component.prototype.dispose.call(this);
26386
+ };
26387
+ _proto.register = function register() {
26388
+ if (!this.registered) {
26389
+ this.rootControl.parent = this.engine.windowRoot.canvases;
26390
+ this.registered = true;
25303
26391
  }
25304
- var rt = new RectTransform();
25305
- rt.engine = t.engine;
25306
- rt.name = t.name;
25307
- rt.position.copyFrom(t.position);
25308
- rt.quat.copyFrom(t.quat);
25309
- rt.rotation.copyFrom(t.rotation);
25310
- rt.scale.copyFrom(t.scale);
25311
- rt.size.copyFrom(t.size);
25312
- // 不拷贝源 anchor — 升级为 RectTransform 时使用默认 pivot=(0.5, 0.5)
25313
- // anchor 同步成 pivot * size,获得“中心轴心”默认行为
25314
- rt.anchor.set(rt.pivot.x * rt.size.x, rt.pivot.y * rt.size.y, t.anchor.z);
25315
- if (t.parentTransform) {
25316
- rt.parentTransform = t.parentTransform;
26392
+ };
26393
+ _proto.unregister = function unregister() {
26394
+ if (this.registered) {
26395
+ this.rootControl.parent = null;
26396
+ this.registered = false;
26397
+ }
26398
+ };
26399
+ _proto.destroyCanvas = function destroyCanvas() {
26400
+ this.unregister();
26401
+ if (!this.rootControl.isDisposed) {
26402
+ this.rootControl.dispose();
25317
26403
  }
25318
- return rt;
25319
26404
  };
25320
- return RectTransform;
25321
- }(Transform);
26405
+ _create_class(UICanvas, [
26406
+ {
26407
+ key: "order",
26408
+ get: function get() {
26409
+ return this._order;
26410
+ },
26411
+ set: function set(value) {
26412
+ if (this._order !== value) {
26413
+ this._order = value;
26414
+ this.engine.windowRoot.canvases.sortCanvases();
26415
+ }
26416
+ }
26417
+ },
26418
+ {
26419
+ key: "isVisible",
26420
+ get: function get() {
26421
+ var _this_item;
26422
+ return this.renderMode === 0 && this.enabled && !!((_this_item = this.item) == null ? void 0 : _this_item.isActive);
26423
+ }
26424
+ }
26425
+ ]);
26426
+ return UICanvas;
26427
+ }(Component);
25322
26428
 
25323
26429
  /**
25324
- * 锚点布局组件
25325
- *
25326
- * `Control extends CanvasItem`。CanvasItem 仅承担绘制与节点层级,Control 在挂到 VFXItem 时把
25327
- * `item.transform` 升级为 {@link RectTransform}。
25328
- *
25329
- * 布局完全由 RectTransform 自治:父子节点关系沿 `Transform.parentTransform / children` 走,
25330
- * 父节点 size 变化时通过 `RectTransform.sizeChanged()` 直接调用子节点 sizeChanged 链式传播。
25331
- * Control 本身不持有任何与布局相关的状态
25332
- */ var Control = /*#__PURE__*/ function(CanvasItem) {
25333
- _inherits(Control, CanvasItem);
25334
- function Control() {
25335
- return CanvasItem.apply(this, arguments);
26430
+ * Scene-tree bridge for a GUI Control. The VFXItem tree owns lifecycle and
26431
+ * serialization while the Control tree owns layout, drawing and input.
26432
+ */ var UIControl = /*#__PURE__*/ function(Component) {
26433
+ _inherits(UIControl, Component);
26434
+ function UIControl(engine) {
26435
+ var _this;
26436
+ _this = Component.call(this, engine) || this;
26437
+ _this.controlNode = null;
26438
+ _this.linkedItemTransform = null;
26439
+ _this.linkedControl = null;
26440
+ _this.syncingLocation = false;
26441
+ _this.itemTransformChanged = function() {
26442
+ return _this.syncItemLocationToControl();
26443
+ };
26444
+ _this.controlLocationChanged = function() {
26445
+ return _this.syncControlLocationToItem();
26446
+ };
26447
+ return _this;
25336
26448
  }
25337
- var _proto = Control.prototype;
25338
- /**
25339
- * 在挂到 VFXItem 时确保 `item.transform` 是 `RectTransform`。
25340
- * 既有 Transform 状态(position / rotation / scale / size / anchor 等)通过 `RectTransform.fromTransform` 复制
25341
- */ _proto.onAwake = function onAwake() {
25342
- var item = this.item;
25343
- if (!_instanceof1(item.transform, RectTransform)) {
25344
- item.transform = RectTransform.fromTransform(item.transform);
26449
+ var _proto = UIControl.prototype;
26450
+ _proto.onAwake = function onAwake() {
26451
+ this.syncControl();
26452
+ };
26453
+ _proto.onEnable = function onEnable() {
26454
+ if (this.controlNode) {
26455
+ this.controlNode.visible = this.item.isActive;
26456
+ this.controlNode.enabled = true;
25345
26457
  }
25346
26458
  };
25347
- return Control;
25348
- }(CanvasItem);
26459
+ _proto.onDisable = function onDisable() {
26460
+ if (this.controlNode) {
26461
+ this.controlNode.visible = this.item.isActive;
26462
+ this.controlNode.enabled = false;
26463
+ }
26464
+ };
26465
+ _proto.onParentChanged = function onParentChanged() {
26466
+ this.syncControl();
26467
+ };
26468
+ _proto.onOrderInParentChanged = function onOrderInParentChanged() {
26469
+ this.syncControlOrder();
26470
+ };
26471
+ _proto.onDestroy = function onDestroy() {
26472
+ this.disposeControl();
26473
+ };
26474
+ _proto.dispose = function dispose() {
26475
+ this.disposeControl();
26476
+ Component.prototype.dispose.call(this);
26477
+ };
26478
+ /** Unlinks the GUI object without disposing or modifying it. */ _proto.unlinkControl = function unlinkControl() {
26479
+ if (this.controlNode) {
26480
+ this.unbindLocationSync();
26481
+ this.controlNode = null;
26482
+ }
26483
+ };
26484
+ _proto.disposeControl = function disposeControl() {
26485
+ var control = this.controlNode;
26486
+ if (control) {
26487
+ this.unbindLocationSync();
26488
+ this.controlNode = null;
26489
+ control.dispose();
26490
+ }
26491
+ };
26492
+ _proto.syncControl = function syncControl() {
26493
+ var control = this.controlNode;
26494
+ if (!control || !this.item) {
26495
+ return;
26496
+ }
26497
+ this.syncingLocation = true;
26498
+ try {
26499
+ control.visible = this.item.isActive;
26500
+ control.enabled = this.enabled;
26501
+ control.parent = this.resolveParent();
26502
+ this.syncControlOrder();
26503
+ this.copyItemLocationToControl();
26504
+ } finally{
26505
+ this.syncingLocation = false;
26506
+ }
26507
+ this.bindLocationSync();
26508
+ };
26509
+ _proto.syncControlOrder = function syncControlOrder() {
26510
+ if (this.controlNode && this.item) {
26511
+ this.controlNode.indexInParent = this.item.orderInParent;
26512
+ }
26513
+ };
26514
+ _proto.resolveParent = function resolveParent() {
26515
+ var parentItem = this.item.parent;
26516
+ if (!parentItem) {
26517
+ var _UIControl_fallbackParentGetDelegate;
26518
+ return (_UIControl_fallbackParentGetDelegate = UIControl.fallbackParentGetDelegate == null ? void 0 : UIControl.fallbackParentGetDelegate.call(UIControl, this)) != null ? _UIControl_fallbackParentGetDelegate : null;
26519
+ }
26520
+ var uiControl = parentItem.getComponent(UIControl);
26521
+ if ((uiControl == null ? void 0 : uiControl.control) && "children" in uiControl.control) {
26522
+ return uiControl.control;
26523
+ }
26524
+ var canvas = parentItem.getComponent(UICanvas);
26525
+ var _canvas_rootControl, _ref;
26526
+ return (_ref = (_canvas_rootControl = canvas == null ? void 0 : canvas.rootControl) != null ? _canvas_rootControl : UIControl.fallbackParentGetDelegate == null ? void 0 : UIControl.fallbackParentGetDelegate.call(UIControl, this)) != null ? _ref : null;
26527
+ };
26528
+ _proto.bindLocationSync = function bindLocationSync() {
26529
+ var itemTransform = this.item.transform;
26530
+ var control = this.controlNode;
26531
+ if (this.linkedItemTransform === itemTransform && this.linkedControl === control) {
26532
+ return;
26533
+ }
26534
+ this.unbindLocationSync();
26535
+ if (control) {
26536
+ this.linkedItemTransform = itemTransform;
26537
+ this.linkedControl = control;
26538
+ itemTransform.on("changed", this.itemTransformChanged);
26539
+ control.on("locationChanged", this.controlLocationChanged);
26540
+ }
26541
+ };
26542
+ _proto.unbindLocationSync = function unbindLocationSync() {
26543
+ var _this_linkedItemTransform, _this_linkedControl;
26544
+ (_this_linkedItemTransform = this.linkedItemTransform) == null ? void 0 : _this_linkedItemTransform.off("changed", this.itemTransformChanged);
26545
+ (_this_linkedControl = this.linkedControl) == null ? void 0 : _this_linkedControl.off("locationChanged", this.controlLocationChanged);
26546
+ this.linkedItemTransform = null;
26547
+ this.linkedControl = null;
26548
+ };
26549
+ _proto.syncItemLocationToControl = function syncItemLocationToControl() {
26550
+ if (!this.syncingLocation && this.controlNode) {
26551
+ this.syncingLocation = true;
26552
+ try {
26553
+ this.copyItemLocationToControl();
26554
+ } finally{
26555
+ this.syncingLocation = false;
26556
+ }
26557
+ }
26558
+ };
26559
+ _proto.syncControlLocationToItem = function syncControlLocationToItem() {
26560
+ var control = this.controlNode;
26561
+ if (!this.syncingLocation && control) {
26562
+ var source = control.location;
26563
+ var target = this.item.transform.position;
26564
+ if (source.x !== target.x || source.y !== target.y) {
26565
+ this.syncingLocation = true;
26566
+ try {
26567
+ this.item.transform.setPosition(source.x, source.y, target.z);
26568
+ } finally{
26569
+ this.syncingLocation = false;
26570
+ }
26571
+ }
26572
+ }
26573
+ };
26574
+ _proto.copyItemLocationToControl = function copyItemLocationToControl() {
26575
+ var control = this.controlNode;
26576
+ if (control) {
26577
+ var source = this.item.transform.position;
26578
+ var target = control.location;
26579
+ if (source.x !== target.x || source.y !== target.y) {
26580
+ control.setPosition(source.x, source.y);
26581
+ }
26582
+ }
26583
+ };
26584
+ _create_class(UIControl, [
26585
+ {
26586
+ key: "control",
26587
+ get: function get() {
26588
+ return this.controlNode;
26589
+ },
26590
+ set: function set(value) {
26591
+ if (value === this.controlNode) {
26592
+ return;
26593
+ }
26594
+ this.disposeControl();
26595
+ if (value) {
26596
+ if (value.owner && value.owner !== this && value.owner.control === value) {
26597
+ throw new Error("A Control can only be owned by one UIControl.");
26598
+ }
26599
+ this.controlNode = value;
26600
+ value.owner = this;
26601
+ this.syncControl();
26602
+ }
26603
+ }
26604
+ },
26605
+ {
26606
+ key: "hasControl",
26607
+ get: function get() {
26608
+ return this.controlNode !== null;
26609
+ }
26610
+ }
26611
+ ]);
26612
+ return UIControl;
26613
+ }(Component);
25349
26614
 
25350
26615
  exports.CameraController = /*#__PURE__*/ function(Component) {
25351
26616
  _inherits(CameraController, Component);
@@ -25381,42 +26646,6 @@ exports.CameraController = __decorate([
25381
26646
  effectsClass(DataType.CameraController)
25382
26647
  ], exports.CameraController);
25383
26648
 
25384
- function _get_prototype_of(o) {
25385
- _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
25386
- return o.__proto__ || Object.getPrototypeOf(o);
25387
- };
25388
- return _get_prototype_of(o);
25389
- }
25390
-
25391
- function _is_native_function(fn) {
25392
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
25393
- }
25394
-
25395
- function _wrap_native_super(Class) {
25396
- var _cache = typeof Map === "function" ? new Map() : undefined;
25397
- _wrap_native_super = function _wrap_native_super(Class) {
25398
- if (Class === null || !_is_native_function(Class)) return Class;
25399
- if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
25400
- if (typeof _cache !== "undefined") {
25401
- if (_cache.has(Class)) return _cache.get(Class);
25402
- _cache.set(Class, Wrapper);
25403
- }
25404
- function Wrapper() {
25405
- return _construct(Class, arguments, _get_prototype_of(this).constructor);
25406
- }
25407
- Wrapper.prototype = Object.create(Class.prototype, {
25408
- constructor: {
25409
- value: Wrapper,
25410
- enumerable: false,
25411
- writable: true,
25412
- configurable: true
25413
- }
25414
- });
25415
- return _set_prototype_of(Wrapper, Class);
25416
- };
25417
- return _wrap_native_super(Class);
25418
- }
25419
-
25420
26649
  var CameraVFXItemLoader = /*#__PURE__*/ function(Plugin) {
25421
26650
  _inherits(CameraVFXItemLoader, Plugin);
25422
26651
  function CameraVFXItemLoader() {
@@ -25437,142 +26666,202 @@ exports.PointerEventType = void 0;
25437
26666
  })(exports.PointerEventType || (exports.PointerEventType = {}));
25438
26667
  var EventSystem = /*#__PURE__*/ function() {
25439
26668
  function EventSystem(engine, allowPropagation) {
26669
+ var _this = this;
25440
26670
  if (allowPropagation === void 0) allowPropagation = false;
25441
26671
  this.engine = engine;
25442
26672
  this.allowPropagation = allowPropagation;
25443
- this.enabled = true;
25444
26673
  this.skipPointerMovePicking = true;
26674
+ this.emulateMouseFromTouch = true;
26675
+ this.emulateTouchFromMouse = false;
26676
+ this._enabled = true;
25445
26677
  this.handlers = {};
25446
- this.nativeHandlers = {};
26678
+ this.nativeHandlers = [];
25447
26679
  this.target = null;
25448
- }
25449
- var _proto = EventSystem.prototype;
25450
- _proto.bindListeners = function bindListeners(target) {
25451
- var _this = this;
25452
- this.target = target;
25453
- var x;
25454
- var y;
25455
- var currentTouch;
25456
- var lastTouch;
25457
- var getTouch;
25458
- getTouch = function(event) {
25459
- return event;
26680
+ this.mouseState = null;
26681
+ this.touchStates = new Map();
26682
+ this.mouseFromTouchIndex = null;
26683
+ this.touchFromMousePressed = false;
26684
+ this.addedTabIndex = false;
26685
+ this.addedOutlineStyle = false;
26686
+ this.onNativeWheel = function(event) {
26687
+ if (!_this.enabled || !_this.target) {
26688
+ return;
26689
+ }
26690
+ var position = _this.getCanvasPosition(event.clientX, event.clientY);
26691
+ var handled = false;
26692
+ if (event.deltaY !== 0) {
26693
+ handled = _this.pushWheelButton(event.deltaY < 0 ? exports.MouseButton.WheelUp : exports.MouseButton.WheelDown, Math.abs(event.deltaY), position, event) || handled;
26694
+ }
26695
+ if (event.deltaX !== 0) {
26696
+ handled = _this.pushWheelButton(event.deltaX < 0 ? exports.MouseButton.WheelLeft : exports.MouseButton.WheelRight, Math.abs(event.deltaX), position, event) || handled;
26697
+ }
26698
+ _this.consumeNativeEvent(event, handled);
25460
26699
  };
25461
- var touchstart = "mousedown";
25462
- var touchmove = "mousemove";
25463
- var touchend = "mouseup";
25464
- var touchcancel = "mouseleave";
25465
- var getTouchEventValue = function(event, x, y, dx, dy) {
25466
- if (dx === void 0) dx = 0;
25467
- if (dy === void 0) dy = 0;
25468
- var vx = 0;
25469
- var vy = 0;
25470
- var ts = performance.now();
25471
- if (!_this.target) {
25472
- logger.warn("Trigger TouchEvent after EventSystem is disposed.");
25473
- return {
25474
- x: x,
25475
- y: y,
25476
- vx: 0,
25477
- vy: vy,
25478
- dx: dx,
25479
- dy: dy,
25480
- ts: ts,
25481
- width: 0,
25482
- height: 0,
25483
- origin: event
25484
- };
26700
+ this.onNativeKeyDown = function(event) {
26701
+ _this.handleNativeKey(event, true);
26702
+ };
26703
+ this.onNativeKeyUp = function(event) {
26704
+ _this.handleNativeKey(event, false);
26705
+ };
26706
+ this.onNativeMouseDown = function(event) {
26707
+ _this.handleNativeMouseDown(event);
26708
+ };
26709
+ this.onNativeMouseMove = function(event) {
26710
+ var _state;
26711
+ if (!_this.enabled || !_this.target) {
26712
+ return;
25485
26713
  }
25486
- var _this_target = _this.target, width = _this_target.width, height = _this_target.height;
25487
- if (lastTouch) {
25488
- var dt = ts - lastTouch.ts;
25489
- vx = (dx - lastTouch.dx) / dt || 0;
25490
- vy = (dy - lastTouch.dy) / dt || 0;
25491
- lastTouch = {
25492
- dx: dx,
25493
- dy: dy,
25494
- ts: ts
25495
- };
26714
+ var position = _this.getCanvasPosition(event.clientX, event.clientY);
26715
+ var _this_mouseState;
26716
+ var state = (_this_mouseState = _this.mouseState) != null ? _this_mouseState : _this.createPointerState(position);
26717
+ _this.mouseState = state;
26718
+ var relative = new Vector2(position.x - state.last.x, position.y - state.last.y);
26719
+ var velocity = _this.getVelocity(state, position);
26720
+ var handled = _this.pushNativeMouseMotion(event, position, relative, velocity);
26721
+ (_state = state).controlHandled || (_state.controlHandled = handled);
26722
+ if (!handled && (!state.pressed || !state.controlHandled)) {
26723
+ var pointerEvent = _this.createPointerEvent(event, position, state, velocity);
26724
+ _this.dispatchEvent(EVENT_TYPE_TOUCH_MOVE, pointerEvent);
26725
+ }
26726
+ _this.updatePointerState(state, position);
26727
+ _this.consumeNativeEvent(event, handled);
26728
+ };
26729
+ this.onNativeMouseUp = function(event) {
26730
+ if (!_this.enabled || !_this.target) {
26731
+ return;
25496
26732
  }
25497
- return {
25498
- x: x,
25499
- y: y,
25500
- vx: vx,
25501
- vy: vy,
25502
- dx: dx,
25503
- dy: dy,
25504
- ts: ts,
25505
- width: width,
25506
- height: height,
25507
- origin: event
25508
- };
26733
+ var position = _this.getCanvasPosition(event.clientX, event.clientY);
26734
+ var existingState = _this.mouseState;
26735
+ if (!(existingState == null ? void 0 : existingState.pressed)) {
26736
+ return;
26737
+ }
26738
+ var state = existingState;
26739
+ var handled = _this.pushNativeMouseButton(event, position, false);
26740
+ var pointerEvent = _this.createPointerEvent(event, position, state);
26741
+ if (!state.controlHandled && !handled && _this.isClick(state, position)) {
26742
+ _this.dispatchEvent(EVENT_TYPE_CLICK, pointerEvent);
26743
+ }
26744
+ if (!handled && !state.controlHandled) {
26745
+ _this.dispatchEvent(EVENT_TYPE_TOUCH_END, pointerEvent);
26746
+ }
26747
+ _this.mouseState = null;
26748
+ _this.consumeNativeEvent(event, handled || state.controlHandled || !_this.allowPropagation);
25509
26749
  };
25510
- if (isSimulatorCellPhone()) {
25511
- getTouch = function(event) {
25512
- var touches = event.touches, changedTouches = event.changedTouches;
25513
- return touches[0] || changedTouches[0];
25514
- };
25515
- touchstart = "touchstart";
25516
- touchmove = "touchmove";
25517
- touchend = "touchend";
25518
- touchcancel = "touchcancel";
25519
- }
25520
- var _obj;
25521
- this.nativeHandlers = (_obj = {}, _obj[touchstart] = function(event) {
25522
- if (_this.enabled) {
25523
- var touch = getTouch(event);
25524
- var cood = getCoord(touch);
25525
- x = cood.x;
25526
- y = cood.y;
25527
- lastTouch = currentTouch = {
25528
- clientX: touch.clientX,
25529
- clientY: touch.clientY,
25530
- ts: performance.now(),
25531
- x: x,
25532
- y: y
25533
- };
25534
- _this.dispatchEvent(EVENT_TYPE_TOUCH_START, getTouchEventValue(event, x, y));
25535
- }
25536
- }, _obj[touchmove] = function(event) {
25537
- if (currentTouch && _this.enabled) {
25538
- var cood = getCoord(getTouch(event));
25539
- x = cood.x;
25540
- y = cood.y;
25541
- _this.dispatchEvent(EVENT_TYPE_TOUCH_MOVE, getTouchEventValue(event, x, y, x - currentTouch.x, y - currentTouch.y));
25542
- }
25543
- }, _obj[touchend] = function(event) {
25544
- if (currentTouch && _this.enabled) {
25545
- if (!_this.allowPropagation && event.cancelable) {
25546
- event.preventDefault();
25547
- event.stopPropagation();
26750
+ this.onNativeTouchStart = function(event) {
26751
+ if (!_this.enabled) {
26752
+ return;
26753
+ }
26754
+ _this.focusTarget();
26755
+ for(var _iterator = _create_for_of_iterator_helper_loose(Array.from(event.changedTouches)), _step; !(_step = _iterator()).done;){
26756
+ var touch = _step.value;
26757
+ var position = _this.getCanvasPosition(touch.clientX, touch.clientY);
26758
+ var state = _this.createPointerState(position);
26759
+ _this.touchStates.set(touch.identifier, state);
26760
+ state.pressed = true;
26761
+ var handled = _this.pushNativeScreenTouch(touch.identifier, position, true, false, false);
26762
+ state.controlHandled = handled;
26763
+ if (!handled) {
26764
+ var pointerEvent = _this.createPointerEvent(event, position, state);
26765
+ _this.dispatchEvent(EVENT_TYPE_TOUCH_START, pointerEvent);
25548
26766
  }
25549
- var touch = getTouch(event);
25550
- var cood = getCoord(touch);
25551
- var dt = Math.abs(currentTouch.clientX - touch.clientX) + Math.abs(currentTouch.clientY - touch.clientY);
25552
- x = cood.x;
25553
- y = cood.y;
25554
- if (dt < 4) {
25555
- _this.dispatchEvent(EVENT_TYPE_CLICK, getTouchEventValue(event, x, y));
26767
+ _this.consumeNativeEvent(event, handled);
26768
+ }
26769
+ _this.preventTouchDefaults(event);
26770
+ };
26771
+ this.onNativeTouchMove = function(event) {
26772
+ if (!_this.enabled) {
26773
+ return;
26774
+ }
26775
+ for(var _iterator = _create_for_of_iterator_helper_loose(Array.from(event.changedTouches)), _step; !(_step = _iterator()).done;){
26776
+ var touch = _step.value;
26777
+ var _state;
26778
+ var position = _this.getCanvasPosition(touch.clientX, touch.clientY);
26779
+ var _this_touchStates_get;
26780
+ var state = (_this_touchStates_get = _this.touchStates.get(touch.identifier)) != null ? _this_touchStates_get : _this.createPointerState(position);
26781
+ _this.touchStates.set(touch.identifier, state);
26782
+ var relative = new Vector2(position.x - state.last.x, position.y - state.last.y);
26783
+ var velocity = _this.getVelocity(state, position);
26784
+ var handled = _this.pushNativeScreenDrag(touch.identifier, position, relative, velocity);
26785
+ (_state = state).controlHandled || (_state.controlHandled = handled);
26786
+ if (!handled && !state.controlHandled) {
26787
+ var pointerEvent = _this.createPointerEvent(event, position, state, velocity);
26788
+ _this.dispatchEvent(EVENT_TYPE_TOUCH_MOVE, pointerEvent);
25556
26789
  }
25557
- _this.dispatchEvent(EVENT_TYPE_TOUCH_END, getTouchEventValue(event, x, y, x - currentTouch.x, y - currentTouch.y));
25558
- }
25559
- currentTouch = 0;
25560
- }, _obj);
25561
- this.nativeHandlers[touchcancel] = this.nativeHandlers[touchend];
25562
- Object.keys(this.nativeHandlers).forEach(function(name) {
25563
- var _this_target;
25564
- (_this_target = _this.target) == null ? void 0 : _this_target.addEventListener(String(name), _this.nativeHandlers[name]);
26790
+ _this.updatePointerState(state, position);
26791
+ _this.consumeNativeEvent(event, handled);
26792
+ }
26793
+ _this.preventTouchDefaults(event);
26794
+ };
26795
+ this.onNativeTouchEnd = function(event) {
26796
+ _this.handleNativeTouchEnd(event, false);
26797
+ };
26798
+ this.onNativeTouchCancel = function(event) {
26799
+ _this.handleNativeTouchEnd(event, true);
26800
+ };
26801
+ this.onWindowBlur = function() {
26802
+ if (_this.enabled) {
26803
+ _this.mouseState = null;
26804
+ _this.touchStates.clear();
26805
+ _this.mouseFromTouchIndex = null;
26806
+ _this.touchFromMousePressed = false;
26807
+ _this.engine.windowRoot.cancelPointerInput();
26808
+ }
26809
+ };
26810
+ }
26811
+ var _proto = EventSystem.prototype;
26812
+ _proto.bindListeners = function bindListeners(target) {
26813
+ this.unbindListeners();
26814
+ this.target = target;
26815
+ if (!target || typeof window === "undefined") {
26816
+ return;
26817
+ }
26818
+ if (!target.hasAttribute("tabindex")) {
26819
+ target.tabIndex = 0;
26820
+ this.addedTabIndex = true;
26821
+ }
26822
+ if (!target.style.outline) {
26823
+ target.style.outline = "none";
26824
+ this.addedOutlineStyle = true;
26825
+ }
26826
+ this.addNativeHandler(target, "mousedown", this.onNativeMouseDown);
26827
+ // The Window listener runs after the event reaches the host container, so keep a
26828
+ // target listener to preserve notifyTouch/allowPropagation for in-canvas releases.
26829
+ this.addNativeHandler(target, "mouseup", this.onNativeMouseUp);
26830
+ this.addNativeHandler(window, "mouseup", this.onNativeMouseUp);
26831
+ this.addNativeHandler(window, "pointermove", this.onNativeMouseMove);
26832
+ this.addNativeHandler(target, "touchstart", this.onNativeTouchStart, {
26833
+ passive: false
26834
+ });
26835
+ this.addNativeHandler(target, "touchmove", this.onNativeTouchMove, {
26836
+ passive: false
26837
+ });
26838
+ this.addNativeHandler(target, "touchend", this.onNativeTouchEnd, {
26839
+ passive: false
26840
+ });
26841
+ this.addNativeHandler(target, "touchcancel", this.onNativeTouchCancel, {
26842
+ passive: false
26843
+ });
26844
+ this.addNativeHandler(target, "wheel", this.onNativeWheel, {
26845
+ passive: false
25565
26846
  });
25566
- this.addEventListener(EVENT_TYPE_CLICK, this.onClick.bind(this));
25567
- this.addEventListener(EVENT_TYPE_TOUCH_START, this.onPointerDown.bind(this));
25568
- this.addEventListener(EVENT_TYPE_TOUCH_END, this.onPointerUp.bind(this));
25569
- this.addEventListener(EVENT_TYPE_TOUCH_MOVE, this.onPointerMove.bind(this));
26847
+ this.addNativeHandler(target, "keydown", this.onNativeKeyDown);
26848
+ this.addNativeHandler(target, "keyup", this.onNativeKeyUp);
26849
+ this.addNativeHandler(window, "blur", this.onWindowBlur);
25570
26850
  };
25571
26851
  _proto.dispatchEvent = function dispatchEvent(type, event) {
25572
26852
  var handlers = this.handlers[type];
25573
- handlers == null ? void 0 : handlers.forEach(function(fn) {
26853
+ handlers == null ? void 0 : handlers.slice().forEach(function(fn) {
25574
26854
  return fn(event);
25575
26855
  });
26856
+ if (type === EVENT_TYPE_CLICK) {
26857
+ this.onClick(event);
26858
+ } else if (type === EVENT_TYPE_TOUCH_START) {
26859
+ this.onPointerDown(event);
26860
+ } else if (type === EVENT_TYPE_TOUCH_END) {
26861
+ this.onPointerUp(event);
26862
+ } else if (type === EVENT_TYPE_TOUCH_MOVE) {
26863
+ this.onPointerMove(event);
26864
+ }
25576
26865
  };
25577
26866
  _proto.addEventListener = function addEventListener(type, callback) {
25578
26867
  var handlers = this.handlers[type];
@@ -25590,14 +26879,229 @@ var EventSystem = /*#__PURE__*/ function() {
25590
26879
  removeItem(handlers, callback);
25591
26880
  }
25592
26881
  };
25593
- _proto.onClick = function onClick(e) {
25594
- var x = e.x, y = e.y;
26882
+ _proto.dispose = function dispose() {
26883
+ this.engine.windowRoot.cancelPointerInput();
26884
+ this.mouseState = null;
26885
+ this.touchStates.clear();
26886
+ this.mouseFromTouchIndex = null;
26887
+ this.touchFromMousePressed = false;
26888
+ this.handlers = {};
26889
+ this.unbindListeners();
26890
+ this.target = null;
26891
+ };
26892
+ _proto.handleNativeMouseDown = function handleNativeMouseDown(event) {
26893
+ if (!this.enabled || !this.target) {
26894
+ return;
26895
+ }
26896
+ this.focusTarget();
26897
+ var position = this.getCanvasPosition(event.clientX, event.clientY);
26898
+ var state = this.createPointerState(position);
26899
+ this.mouseState = state;
26900
+ state.pressed = true;
26901
+ var handled = this.pushNativeMouseButton(event, position, true);
26902
+ state.controlHandled = handled;
26903
+ if (!handled) {
26904
+ var pointerEvent = this.createPointerEvent(event, position, state);
26905
+ this.dispatchEvent(EVENT_TYPE_TOUCH_START, pointerEvent);
26906
+ }
26907
+ this.consumeNativeEvent(event, handled);
26908
+ };
26909
+ _proto.handleNativeKey = function handleNativeKey(event, pressed) {
26910
+ if (!this.enabled) {
26911
+ return;
26912
+ }
26913
+ var input = new InputEventKey();
26914
+ input.device = InputEvent.deviceIdKeyboard;
26915
+ input.pressed = pressed;
26916
+ input.echo = pressed && event.repeat;
26917
+ input.keycode = event.key;
26918
+ input.physicalKeycode = event.code;
26919
+ input.keyLabel = event.key;
26920
+ input.unicode = getUnicode(event.key);
26921
+ input.location = getKeyLocation(event.location);
26922
+ input.shiftPressed = event.shiftKey;
26923
+ input.altPressed = event.altKey;
26924
+ input.metaPressed = event.metaKey;
26925
+ input.ctrlPressed = event.ctrlKey;
26926
+ this.engine.windowRoot.pushInput(input);
26927
+ this.consumeNativeEvent(event, this.engine.windowRoot.isInputHandled());
26928
+ };
26929
+ _proto.handleNativeTouchEnd = function handleNativeTouchEnd(event, canceled) {
26930
+ if (!this.enabled) {
26931
+ return;
26932
+ }
26933
+ for(var _iterator = _create_for_of_iterator_helper_loose(Array.from(event.changedTouches)), _step; !(_step = _iterator()).done;){
26934
+ var touch = _step.value;
26935
+ var position = this.getCanvasPosition(touch.clientX, touch.clientY);
26936
+ var state = this.touchStates.get(touch.identifier);
26937
+ if (!(state == null ? void 0 : state.pressed)) {
26938
+ continue;
26939
+ }
26940
+ var handled = this.pushNativeScreenTouch(touch.identifier, position, false, canceled, false);
26941
+ var pointerEvent = this.createPointerEvent(event, position, state);
26942
+ if (!canceled && !state.controlHandled && !handled && this.isClick(state, position)) {
26943
+ this.dispatchEvent(EVENT_TYPE_CLICK, pointerEvent);
26944
+ }
26945
+ if (!handled && !canceled && !state.controlHandled) {
26946
+ this.dispatchEvent(EVENT_TYPE_TOUCH_END, pointerEvent);
26947
+ }
26948
+ this.touchStates.delete(touch.identifier);
26949
+ this.consumeNativeEvent(event, handled || state.controlHandled || !this.allowPropagation);
26950
+ }
26951
+ this.preventTouchDefaults(event);
26952
+ };
26953
+ _proto.pushNativeMouseButton = function pushNativeMouseButton(event, position, pressed) {
26954
+ var handled = false;
26955
+ var button = getMouseButton(event.button);
26956
+ if (pressed && this.emulateTouchFromMouse && button === exports.MouseButton.Left) {
26957
+ this.touchFromMousePressed = true;
26958
+ }
26959
+ if (this.touchFromMousePressed && button === exports.MouseButton.Left) {
26960
+ handled = this.pushScreenTouch(0, position, pressed, false, event.detail > 1, InputEvent.deviceIdEmulation);
26961
+ if (!pressed) {
26962
+ this.touchFromMousePressed = false;
26963
+ }
26964
+ }
26965
+ return this.pushMouseButton(event, position, pressed) || handled;
26966
+ };
26967
+ _proto.pushNativeMouseMotion = function pushNativeMouseMotion(event, position, relative, velocity) {
26968
+ var handled = false;
26969
+ if (this.touchFromMousePressed && (event.buttons & 1) !== 0) {
26970
+ handled = this.pushScreenDrag(0, position, relative, velocity, InputEvent.deviceIdEmulation);
26971
+ }
26972
+ return this.pushMouseMotion(event, position, relative, velocity) || handled;
26973
+ };
26974
+ _proto.pushNativeScreenTouch = function pushNativeScreenTouch(index, position, pressed, canceled, doubleTap) {
26975
+ var handled = false;
26976
+ var emulateMouse = false;
26977
+ if (pressed && this.emulateMouseFromTouch && this.mouseFromTouchIndex === null) {
26978
+ this.mouseFromTouchIndex = index;
26979
+ emulateMouse = true;
26980
+ } else if (!pressed && this.mouseFromTouchIndex === index) {
26981
+ emulateMouse = true;
26982
+ this.mouseFromTouchIndex = null;
26983
+ }
26984
+ if (emulateMouse) {
26985
+ handled = this.pushEmulatedMouseButton(position, pressed, canceled, doubleTap);
26986
+ }
26987
+ return this.pushScreenTouch(index, position, pressed, canceled, doubleTap, 0) || handled;
26988
+ };
26989
+ _proto.pushNativeScreenDrag = function pushNativeScreenDrag(index, position, relative, velocity) {
26990
+ var handled = false;
26991
+ if (this.emulateMouseFromTouch && this.mouseFromTouchIndex === index) {
26992
+ handled = this.pushEmulatedMouseMotion(position, relative, velocity);
26993
+ }
26994
+ return this.pushScreenDrag(index, position, relative, velocity, 0) || handled;
26995
+ };
26996
+ _proto.pushEmulatedMouseButton = function pushEmulatedMouseButton(position, pressed, canceled, doubleClick) {
26997
+ var input = new InputEventMouseButton();
26998
+ input.device = InputEvent.deviceIdEmulation;
26999
+ input.position.copyFrom(position);
27000
+ input.globalPosition.copyFrom(position);
27001
+ input.buttonIndex = exports.MouseButton.Left;
27002
+ input.buttonMask = pressed ? exports.MouseButtonMask.Left : exports.MouseButtonMask.None;
27003
+ input.pressed = pressed;
27004
+ input.canceled = canceled;
27005
+ input.doubleClick = doubleClick;
27006
+ this.engine.windowRoot.pushInput(input);
27007
+ return this.engine.windowRoot.isInputHandled();
27008
+ };
27009
+ _proto.pushEmulatedMouseMotion = function pushEmulatedMouseMotion(position, relative, velocity) {
27010
+ var input = new InputEventMouseMotion();
27011
+ input.device = InputEvent.deviceIdEmulation;
27012
+ input.position.copyFrom(position);
27013
+ input.globalPosition.copyFrom(position);
27014
+ input.buttonMask = exports.MouseButtonMask.Left;
27015
+ input.pressed = true;
27016
+ input.relative.copyFrom(relative);
27017
+ input.screenRelative.copyFrom(relative);
27018
+ input.velocity.copyFrom(velocity);
27019
+ input.screenVelocity.copyFrom(velocity);
27020
+ this.engine.windowRoot.pushInput(input);
27021
+ return this.engine.windowRoot.isInputHandled();
27022
+ };
27023
+ _proto.pushMouseButton = function pushMouseButton(event, position, pressed) {
27024
+ var input = new InputEventMouseButton();
27025
+ this.copyMouseFields(input, event, position);
27026
+ input.device = InputEvent.deviceIdMouse;
27027
+ input.buttonIndex = getMouseButton(event.button);
27028
+ input.buttonMask = getMouseButtonMask(event.buttons);
27029
+ if (pressed) {
27030
+ input.buttonMask |= getMouseButtonBit(input.buttonIndex);
27031
+ } else {
27032
+ input.buttonMask &= ~getMouseButtonBit(input.buttonIndex);
27033
+ }
27034
+ input.pressed = pressed;
27035
+ input.doubleClick = event.detail > 1;
27036
+ this.engine.windowRoot.pushInput(input);
27037
+ return this.engine.windowRoot.isInputHandled();
27038
+ };
27039
+ _proto.pushWheelButton = function pushWheelButton(button, factor, position, event) {
27040
+ var input = new InputEventMouseButton();
27041
+ this.copyMouseFields(input, event, position);
27042
+ input.device = InputEvent.deviceIdMouse;
27043
+ input.buttonIndex = button;
27044
+ input.buttonMask = getMouseButtonMask(event.buttons);
27045
+ input.factor = factor;
27046
+ input.pressed = true;
27047
+ this.engine.windowRoot.pushInput(input);
27048
+ return this.engine.windowRoot.isInputHandled();
27049
+ };
27050
+ _proto.pushMouseMotion = function pushMouseMotion(event, position, relative, velocity) {
27051
+ var input = new InputEventMouseMotion();
27052
+ this.copyMouseFields(input, event, position);
27053
+ input.device = InputEvent.deviceIdMouse;
27054
+ input.buttonMask = getMouseButtonMask(event.buttons);
27055
+ input.pressed = event.buttons !== 0;
27056
+ input.relative.copyFrom(relative);
27057
+ input.screenRelative.copyFrom(relative);
27058
+ input.velocity.copyFrom(velocity);
27059
+ input.screenVelocity.copyFrom(velocity);
27060
+ if ("pressure" in event) {
27061
+ input.pressure = event.pressure;
27062
+ input.tilt.set(event.tiltX, event.tiltY);
27063
+ }
27064
+ this.engine.windowRoot.pushInput(input);
27065
+ return this.engine.windowRoot.isInputHandled();
27066
+ };
27067
+ _proto.pushScreenTouch = function pushScreenTouch(index, position, pressed, canceled, doubleTap, device) {
27068
+ var input = new InputEventScreenTouch();
27069
+ input.index = index;
27070
+ input.device = device;
27071
+ input.position.copyFrom(position);
27072
+ input.pressed = pressed;
27073
+ input.canceled = canceled;
27074
+ input.doubleTap = doubleTap;
27075
+ this.engine.windowRoot.pushInput(input);
27076
+ return this.engine.windowRoot.isInputHandled();
27077
+ };
27078
+ _proto.pushScreenDrag = function pushScreenDrag(index, position, relative, velocity, device) {
27079
+ var input = new InputEventScreenDrag();
27080
+ input.index = index;
27081
+ input.device = device;
27082
+ input.position.copyFrom(position);
27083
+ input.relative.copyFrom(relative);
27084
+ input.screenRelative.copyFrom(relative);
27085
+ input.velocity.copyFrom(velocity);
27086
+ input.screenVelocity.copyFrom(velocity);
27087
+ input.pressed = true;
27088
+ this.engine.windowRoot.pushInput(input);
27089
+ return this.engine.windowRoot.isInputHandled();
27090
+ };
27091
+ _proto.copyMouseFields = function copyMouseFields(input, event, position) {
27092
+ input.position.copyFrom(position);
27093
+ input.globalPosition.copyFrom(position);
27094
+ input.shiftPressed = event.shiftKey;
27095
+ input.altPressed = event.altKey;
27096
+ input.metaPressed = event.metaKey;
27097
+ input.ctrlPressed = event.ctrlKey;
27098
+ };
27099
+ _proto.onClick = function onClick(event) {
25595
27100
  var hitResults = [];
25596
- // 收集所有的点击测试结果,click 回调执行可能会对 composition 点击结果有影响,放在点击测试执行完后再统一触发。
25597
27101
  for(var _iterator = _create_for_of_iterator_helper_loose(this.engine.compositions), _step; !(_step = _iterator()).done;){
25598
27102
  var composition = _step.value;
25599
27103
  var _hitResults;
25600
- (_hitResults = hitResults).push.apply(_hitResults, [].concat(composition.hitTest(x, y)));
27104
+ (_hitResults = hitResults).push.apply(_hitResults, [].concat(composition.hitTest(event.x, event.y)));
25601
27105
  }
25602
27106
  for(var _iterator1 = _create_for_of_iterator_helper_loose(hitResults), _step1; !(_step1 = _iterator1()).done;){
25603
27107
  var hitResult = _step1.value;
@@ -25614,49 +27118,36 @@ var EventSystem = /*#__PURE__*/ function() {
25614
27118
  this.engine.emit("click", clickInfo);
25615
27119
  }
25616
27120
  };
25617
- _proto.onPointerDown = function onPointerDown(e) {
25618
- this.handlePointerEvent(e, 0);
27121
+ _proto.onPointerDown = function onPointerDown(event) {
27122
+ this.handlePointerEvent(event, 0);
25619
27123
  };
25620
- _proto.onPointerUp = function onPointerUp(e) {
25621
- this.handlePointerEvent(e, 1);
27124
+ _proto.onPointerUp = function onPointerUp(event) {
27125
+ this.handlePointerEvent(event, 1);
25622
27126
  };
25623
- _proto.onPointerMove = function onPointerMove(e) {
25624
- this.handlePointerEvent(e, 2);
27127
+ _proto.onPointerMove = function onPointerMove(event) {
27128
+ this.handlePointerEvent(event, 2);
25625
27129
  };
25626
- _proto.handlePointerEvent = function handlePointerEvent(e, type) {
27130
+ _proto.handlePointerEvent = function handlePointerEvent(event, type) {
25627
27131
  var hitRegion = null;
25628
- var x = e.x, y = e.y, width = e.width, height = e.height;
25629
27132
  if (!(type === 2 && this.skipPointerMovePicking)) {
25630
27133
  for(var _iterator = _create_for_of_iterator_helper_loose(this.engine.compositions), _step; !(_step = _iterator()).done;){
25631
27134
  var composition = _step.value;
25632
- var regions = composition.hitTest(x, y);
27135
+ var regions = composition.hitTest(event.x, event.y);
25633
27136
  if (regions.length > 0) {
25634
27137
  hitRegion = regions[regions.length - 1];
25635
27138
  }
25636
27139
  }
25637
27140
  }
25638
27141
  var eventData = new PointerEventData();
25639
- eventData.position.x = (x + 1) / 2 * width;
25640
- eventData.position.y = (y + 1) / 2 * height;
25641
- eventData.delta.x = e.vx * width;
25642
- eventData.delta.y = e.vy * height;
25643
- var raycast = eventData.pointerCurrentRaycast;
27142
+ eventData.position.x = (event.x + 1) / 2 * event.width;
27143
+ eventData.position.y = (event.y + 1) / 2 * event.height;
27144
+ eventData.delta.x = event.vx * event.width;
27145
+ eventData.delta.y = event.vy * event.height;
25644
27146
  if (hitRegion) {
25645
- raycast.point = hitRegion.position;
25646
- raycast.item = hitRegion.item;
25647
- }
25648
- var eventName = "pointerdown";
25649
- switch(type){
25650
- case 0:
25651
- eventName = "pointerdown";
25652
- break;
25653
- case 1:
25654
- eventName = "pointerup";
25655
- break;
25656
- case 2:
25657
- eventName = "pointermove";
25658
- break;
27147
+ eventData.pointerCurrentRaycast.point = hitRegion.position;
27148
+ eventData.pointerCurrentRaycast.item = hitRegion.item;
25659
27149
  }
27150
+ var eventName = type === 0 ? "pointerdown" : type === 1 ? "pointerup" : "pointermove";
25660
27151
  if (hitRegion) {
25661
27152
  var hitItem = hitRegion.item;
25662
27153
  var hitComposition = hitItem.composition;
@@ -25665,29 +27156,184 @@ var EventSystem = /*#__PURE__*/ function() {
25665
27156
  this.engine.emit(eventName, eventData);
25666
27157
  }
25667
27158
  };
25668
- _proto.dispose = function dispose() {
25669
- var _this = this;
25670
- if (this.target) {
25671
- this.handlers = {};
25672
- Object.keys(this.nativeHandlers).forEach(function(name) {
25673
- var _this_target;
25674
- (_this_target = _this.target) == null ? void 0 : _this_target.removeEventListener(String(name), _this.nativeHandlers[name]);
25675
- });
25676
- this.nativeHandlers = {};
27159
+ _proto.createPointerState = function createPointerState(position) {
27160
+ var state = {
27161
+ start: position.clone(),
27162
+ last: position.clone(),
27163
+ lastTime: performance.now(),
27164
+ controlHandled: false,
27165
+ pressed: false
27166
+ };
27167
+ return state;
27168
+ };
27169
+ _proto.updatePointerState = function updatePointerState(state, position) {
27170
+ state.last.copyFrom(position);
27171
+ state.lastTime = performance.now();
27172
+ };
27173
+ _proto.getVelocity = function getVelocity(state, position) {
27174
+ var elapsed = Math.max(performance.now() - state.lastTime, 1);
27175
+ return new Vector2((position.x - state.last.x) / elapsed, (position.y - state.last.y) / elapsed);
27176
+ };
27177
+ _proto.isClick = function isClick(state, position) {
27178
+ return Math.abs(position.x - state.start.x) + Math.abs(position.y - state.start.y) < 4;
27179
+ };
27180
+ _proto.createPointerEvent = function createPointerEvent(origin, position, state, velocity) {
27181
+ if (velocity === void 0) velocity = new Vector2();
27182
+ var target = this.target;
27183
+ var rect = target == null ? void 0 : target.getBoundingClientRect();
27184
+ var cssWidth = (rect == null ? void 0 : rect.width) || 1;
27185
+ var cssHeight = (rect == null ? void 0 : rect.height) || 1;
27186
+ var _target_width, _target_height;
27187
+ return {
27188
+ x: position.x / cssWidth * 2 - 1,
27189
+ y: position.y / cssHeight * 2 - 1,
27190
+ vx: velocity.x / cssWidth * 2,
27191
+ vy: velocity.y / cssHeight * 2,
27192
+ ts: performance.now(),
27193
+ dx: (position.x - state.start.x) / cssWidth * 2,
27194
+ dy: (position.y - state.start.y) / cssHeight * 2,
27195
+ width: (_target_width = target == null ? void 0 : target.width) != null ? _target_width : 0,
27196
+ height: (_target_height = target == null ? void 0 : target.height) != null ? _target_height : 0,
27197
+ origin: origin
27198
+ };
27199
+ };
27200
+ _proto.getCanvasPosition = function getCanvasPosition(clientX, clientY) {
27201
+ var _this_target;
27202
+ var rect = (_this_target = this.target) == null ? void 0 : _this_target.getBoundingClientRect();
27203
+ if (!rect) {
27204
+ return new Vector2();
27205
+ }
27206
+ return new Vector2(clientX - rect.left, rect.bottom - clientY);
27207
+ };
27208
+ _proto.consumeNativeEvent = function consumeNativeEvent(event, handled) {
27209
+ if (handled && !this.allowPropagation) {
27210
+ if (event.cancelable) {
27211
+ event.preventDefault();
27212
+ }
27213
+ event.stopPropagation();
27214
+ }
27215
+ };
27216
+ _proto.preventTouchDefaults = function preventTouchDefaults(event) {
27217
+ if (event.cancelable) {
27218
+ event.preventDefault();
25677
27219
  }
25678
27220
  };
27221
+ _proto.focusTarget = function focusTarget() {
27222
+ if (this.target && document.activeElement !== this.target) {
27223
+ this.target.focus();
27224
+ }
27225
+ };
27226
+ _proto.addNativeHandler = function addNativeHandler(target, name, handler, options) {
27227
+ target.addEventListener(name, handler, options);
27228
+ this.nativeHandlers.push({
27229
+ target: target,
27230
+ name: name,
27231
+ handler: handler,
27232
+ options: options
27233
+ });
27234
+ };
27235
+ _proto.unbindListeners = function unbindListeners() {
27236
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.nativeHandlers), _step; !(_step = _iterator()).done;){
27237
+ var nativeHandler = _step.value;
27238
+ nativeHandler.target.removeEventListener(nativeHandler.name, nativeHandler.handler, nativeHandler.options);
27239
+ }
27240
+ this.nativeHandlers = [];
27241
+ if (this.addedTabIndex && this.target) {
27242
+ this.target.removeAttribute("tabindex");
27243
+ }
27244
+ if (this.addedOutlineStyle && this.target) {
27245
+ this.target.style.removeProperty("outline");
27246
+ }
27247
+ this.addedTabIndex = false;
27248
+ this.addedOutlineStyle = false;
27249
+ };
27250
+ _create_class(EventSystem, [
27251
+ {
27252
+ key: "enabled",
27253
+ get: function get() {
27254
+ return this._enabled;
27255
+ },
27256
+ set: function set(value) {
27257
+ if (this._enabled === value) {
27258
+ return;
27259
+ }
27260
+ this._enabled = value;
27261
+ if (!value) {
27262
+ this.mouseState = null;
27263
+ this.touchStates.clear();
27264
+ this.mouseFromTouchIndex = null;
27265
+ this.touchFromMousePressed = false;
27266
+ this.engine.windowRoot.cancelPointerInput();
27267
+ }
27268
+ }
27269
+ }
27270
+ ]);
25679
27271
  return EventSystem;
25680
27272
  }();
25681
- function getCoord(event) {
25682
- var ele = event.target;
25683
- var clientX = event.clientX, clientY = event.clientY;
25684
- var _ele_getBoundingClientRect = ele.getBoundingClientRect(), left = _ele_getBoundingClientRect.left, top = _ele_getBoundingClientRect.top, width = _ele_getBoundingClientRect.width, height = _ele_getBoundingClientRect.height;
25685
- var x = (clientX - left) / width * 2 - 1;
25686
- var y = 1 - (clientY - top) / height * 2;
25687
- return {
25688
- x: x,
25689
- y: y
25690
- };
27273
+ function getKeyLocation(location) {
27274
+ if (location === 1) {
27275
+ return exports.KeyLocation.Left;
27276
+ }
27277
+ if (location === 2) {
27278
+ return exports.KeyLocation.Right;
27279
+ }
27280
+ return exports.KeyLocation.Unspecified;
27281
+ }
27282
+ function getUnicode(key) {
27283
+ var characters = Array.from(key);
27284
+ var _characters__codePointAt;
27285
+ return characters.length === 1 ? (_characters__codePointAt = characters[0].codePointAt(0)) != null ? _characters__codePointAt : 0 : 0;
27286
+ }
27287
+ function getMouseButton(button) {
27288
+ switch(button){
27289
+ case 0:
27290
+ return exports.MouseButton.Left;
27291
+ case 1:
27292
+ return exports.MouseButton.Middle;
27293
+ case 2:
27294
+ return exports.MouseButton.Right;
27295
+ case 3:
27296
+ return exports.MouseButton.Xbutton1;
27297
+ case 4:
27298
+ return exports.MouseButton.Xbutton2;
27299
+ default:
27300
+ return exports.MouseButton.None;
27301
+ }
27302
+ }
27303
+ function getMouseButtonMask(buttons) {
27304
+ var mask = exports.MouseButtonMask.None;
27305
+ if ((buttons & 1) !== 0) {
27306
+ mask |= exports.MouseButtonMask.Left;
27307
+ }
27308
+ if ((buttons & 2) !== 0) {
27309
+ mask |= exports.MouseButtonMask.Right;
27310
+ }
27311
+ if ((buttons & 4) !== 0) {
27312
+ mask |= exports.MouseButtonMask.Middle;
27313
+ }
27314
+ if ((buttons & 8) !== 0) {
27315
+ mask |= exports.MouseButtonMask.Xbutton1;
27316
+ }
27317
+ if ((buttons & 16) !== 0) {
27318
+ mask |= exports.MouseButtonMask.Xbutton2;
27319
+ }
27320
+ return mask;
27321
+ }
27322
+ function getMouseButtonBit(button) {
27323
+ switch(button){
27324
+ case exports.MouseButton.Left:
27325
+ return exports.MouseButtonMask.Left;
27326
+ case exports.MouseButton.Right:
27327
+ return exports.MouseButtonMask.Right;
27328
+ case exports.MouseButton.Middle:
27329
+ return exports.MouseButtonMask.Middle;
27330
+ case exports.MouseButton.Xbutton1:
27331
+ return exports.MouseButtonMask.Xbutton1;
27332
+ case exports.MouseButton.Xbutton2:
27333
+ return exports.MouseButtonMask.Xbutton2;
27334
+ default:
27335
+ return exports.MouseButtonMask.None;
27336
+ }
25691
27337
  }
25692
27338
 
25693
27339
  var InteractLoader = /*#__PURE__*/ function(Plugin) {
@@ -27708,11 +29354,6 @@ exports.SpritePropertyTrack = __decorate([
27708
29354
  effectsClass("SpritePropertyTrack")
27709
29355
  ], exports.SpritePropertyTrack);
27710
29356
 
27711
- function _assert_this_initialized(self) {
27712
- if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
27713
- return self;
27714
- }
27715
-
27716
29357
  var Cone = /*#__PURE__*/ function() {
27717
29358
  function Cone(props) {
27718
29359
  var _this = this;
@@ -37717,7 +39358,7 @@ function getStandardSpriteContent(sprite, transform) {
37717
39358
  return ret;
37718
39359
  }
37719
39360
 
37720
- var version$2 = "2.10.0-alpha.2";
39361
+ var version$2 = "2.10.0-alpha.3";
37721
39362
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
37722
39363
  var standardVersion = /^(\d+)\.(\d+)$/;
37723
39364
  var reverseParticle = false;
@@ -39669,10 +41310,11 @@ var PreRenderTickData = /*#__PURE__*/ function(TickData) {
39669
41310
  _this./**
39670
41311
  * 是否开启后处理
39671
41312
  */ postProcessingEnabled = false;
39672
- _this.canvasLayers = [];
39673
41313
  _this.destroyed = false;
39674
41314
  _this.paused = true;
39675
41315
  _this.isEndCalled = false;
41316
+ _this._renderOrder = 0;
41317
+ _this._interactive = true;
39676
41318
  _this._textures = [];
39677
41319
  var _ref = props != null ? props : {}, _ref_reusable = _ref.reusable, reusable = _ref_reusable === void 0 ? false : _ref_reusable, _ref_speed = _ref.speed, speed = _ref_speed === void 0 ? 1 : _ref_speed, _ref_baseRenderOrder = _ref.baseRenderOrder, baseRenderOrder = _ref_baseRenderOrder === void 0 ? 0 : _ref_baseRenderOrder, onItemMessage = _ref.onItemMessage;
39678
41320
  _this.engine.addComposition(_assert_this_initialized(_this));
@@ -39705,13 +41347,14 @@ var PreRenderTickData = /*#__PURE__*/ function(TickData) {
39705
41347
  _this.root = new exports.VFXItem(_this.engine);
39706
41348
  _this.root.name = "root";
39707
41349
  _this.root.composition = _assert_this_initialized(_this);
41350
+ _this.root.setParent(_this.engine.root);
39708
41351
  _this.pluginRoot = new exports.VFXItem(_this.engine);
39709
41352
  _this.pluginRoot.name = "pluginRoot";
39710
41353
  _this.pluginRoot.setParent(_this.root);
39711
- _this.pluginRoot.addComponent(CanvasLayer);
39712
41354
  // Instantiate composition rootItem
39713
41355
  _this.sceneRoot = new exports.VFXItem(_this.engine);
39714
41356
  _this.sceneRoot.setParent(_this.root);
41357
+ _this.uiCanvas = _this.sceneRoot.addComponent(UICanvas);
39715
41358
  if (sourceContent) {
39716
41359
  _this.sceneRoot.setInstanceId(sourceContent.id);
39717
41360
  _this.sceneRoot.instantiatePreComposition(sourceContent, false);
@@ -39910,9 +41553,13 @@ var PreRenderTickData = /*#__PURE__*/ function(TickData) {
39910
41553
  this.isEndCalled = false;
39911
41554
  this.rootComposition.setTime(0);
39912
41555
  };
39913
- _proto.render = function render() {
41556
+ /** Renders this Composition content. Screen-space UI is rendered by Engine. */ _proto.render = function render() {
41557
+ this.renderContent();
41558
+ };
41559
+ /**
41560
+ * Renders only the Composition scene content.
41561
+ */ _proto.renderContent = function renderContent() {
39914
41562
  this.renderer.renderRenderFrame(this.renderFrame);
39915
- this.renderCanvasLayers();
39916
41563
  };
39917
41564
  /**
39918
41565
  * 合成更新,针对所有 item 的更新
@@ -40001,17 +41648,6 @@ var PreRenderTickData = /*#__PURE__*/ function(TickData) {
40001
41648
  }
40002
41649
  }
40003
41650
  };
40004
- _proto.renderCanvasLayers = function renderCanvasLayers() {
40005
- this.engine.graphics.begin();
40006
- this.canvasLayers.sort(function(leftLayer, rightLayer) {
40007
- return leftLayer.layer - rightLayer.layer;
40008
- });
40009
- for(var _iterator = _create_for_of_iterator_helper_loose(this.canvasLayers), _step; !(_step = _iterator()).done;){
40010
- var canvasLayer = _step.value;
40011
- canvasLayer.draw();
40012
- }
40013
- this.engine.graphics.end();
40014
- };
40015
41651
  /**
40016
41652
  * @internal
40017
41653
  */ _proto.createTexturesFromData = function createTexturesFromData(textureDataList) {
@@ -40280,6 +41916,35 @@ var PreRenderTickData = /*#__PURE__*/ function(TickData) {
40280
41916
  })();
40281
41917
  };
40282
41918
  _create_class(Composition, [
41919
+ {
41920
+ key: "renderOrder",
41921
+ get: /**
41922
+ * 合成渲染顺序,默认按升序渲染
41923
+ */ function get() {
41924
+ return this._renderOrder;
41925
+ },
41926
+ set: function set(value) {
41927
+ this._renderOrder = value;
41928
+ if (this.uiCanvas) {
41929
+ this.uiCanvas.order = value;
41930
+ }
41931
+ }
41932
+ },
41933
+ {
41934
+ key: "interactive",
41935
+ get: /**
41936
+ * 合成内的元素否允许点击、拖拽交互
41937
+ * @since 1.6.0
41938
+ */ function get() {
41939
+ return this._interactive;
41940
+ },
41941
+ set: function set(value) {
41942
+ this._interactive = !!value;
41943
+ if (this.uiCanvas) {
41944
+ this.uiCanvas.receivesEvents = this._interactive;
41945
+ }
41946
+ }
41947
+ },
40283
41948
  {
40284
41949
  key: "width",
40285
41950
  get: /**
@@ -42057,7 +43722,6 @@ var DEFAULT_FPS = 60;
42057
43722
  /**
42058
43723
  * 渲染过程中错误队列
42059
43724
  */ _this.renderErrors = new Set();
42060
- _this.compositions = [];
42061
43725
  _this.assetManagers = [];
42062
43726
  _this.env = "";
42063
43727
  /**
@@ -42079,6 +43743,7 @@ var DEFAULT_FPS = 60;
42079
43743
  _this.framebuffers = [];
42080
43744
  _this.renderbuffers = [];
42081
43745
  _this.particleSystems = [];
43746
+ _this._compositions = [];
42082
43747
  _this.clearAction = {
42083
43748
  stencilAction: exports.TextureLoadAction.clear,
42084
43749
  clearStencil: 0,
@@ -42103,6 +43768,9 @@ var DEFAULT_FPS = 60;
42103
43768
  _this.pixelRatio = (_options_pixelRatio = options == null ? void 0 : options.pixelRatio) != null ? _options_pixelRatio : getPixelRatio();
42104
43769
  _this.jsonSceneData = {};
42105
43770
  _this.objectInstance = {};
43771
+ _this.root = new exports.VFXItem(_assert_this_initialized(_this));
43772
+ _this.root.name = "root";
43773
+ _this.windowRoot = new WindowRootControl(_assert_this_initialized(_this));
42106
43774
  _this.whiteTexture = generateWhiteTexture(_assert_this_initialized(_this));
42107
43775
  _this.transparentTexture = generateEmptyTexture(_assert_this_initialized(_this));
42108
43776
  if (!(options == null ? void 0 : options.manualRender)) {
@@ -42237,9 +43905,6 @@ var DEFAULT_FPS = 60;
42237
43905
  // Sort compositions by index
42238
43906
  //-------------------------------------------------------------------------
42239
43907
  var compositions = this.compositions;
42240
- compositions.sort(function(a, b) {
42241
- return a.getIndex() - b.getIndex();
42242
- });
42243
43908
  var skipRender = false;
42244
43909
  // Update Compositions
42245
43910
  //-------------------------------------------------------------------------
@@ -42258,6 +43923,7 @@ var DEFAULT_FPS = 60;
42258
43923
  (_this_ticker1 = this.ticker) == null ? void 0 : _this_ticker1.pause();
42259
43924
  return;
42260
43925
  }
43926
+ this.windowRoot.update(dt);
42261
43927
  // Tick compositions onPreRender
42262
43928
  //-------------------------------------------------------------------------
42263
43929
  for(var _iterator1 = _create_for_of_iterator_helper_loose(compositions), _step1; !(_step1 = _iterator1()).done;){
@@ -42270,8 +43936,9 @@ var DEFAULT_FPS = 60;
42270
43936
  this.renderer.clear(this.clearAction);
42271
43937
  for(var _iterator2 = _create_for_of_iterator_helper_loose(compositions), _step2; !(_step2 = _iterator2()).done;){
42272
43938
  var composition2 = _step2.value;
42273
- composition2.render();
43939
+ composition2.renderContent();
42274
43940
  }
43941
+ this.windowRoot.render();
42275
43942
  this.renderTargetPool.flush();
42276
43943
  };
42277
43944
  /**
@@ -42313,6 +43980,7 @@ var DEFAULT_FPS = 60;
42313
43980
  this.canvas.style.height = containerHeight + "px";
42314
43981
  logger.info("Resize engine " + this.name + " [" + canvasWidth + "," + canvasHeight + "," + containerWidth + "," + containerHeight + "].");
42315
43982
  this.setSize(canvasWidth, canvasHeight);
43983
+ this.windowRoot.resize(canvasWidth, canvasHeight);
42316
43984
  }
42317
43985
  };
42318
43986
  _proto.setSize = function setSize(width, height) {
@@ -42320,7 +43988,7 @@ var DEFAULT_FPS = 60;
42320
43988
  if (this.getWidth() !== width || this.getHeight() !== height) {
42321
43989
  this.canvas.width = width;
42322
43990
  this.canvas.height = height;
42323
- this.viewport(0, 0, width, height);
43991
+ this.setViewport(0, 0, width, height);
42324
43992
  }
42325
43993
  (_this_compositions = this.compositions) == null ? void 0 : _this_compositions.forEach(function(comp) {
42326
43994
  comp.camera.aspect = width / height;
@@ -42349,6 +44017,26 @@ var DEFAULT_FPS = 60;
42349
44017
  /** @hide */ _proto.bindBuffers = function bindBuffers(vertexBuffers, indexBuffer, effect) {
42350
44018
  throw new Error("The active rendering backend cannot bind geometry buffers.");
42351
44019
  };
44020
+ /**
44021
+ * 使用当前绑定的顶点和索引缓冲区绘制图元。
44022
+ * @param mode - 图元类型
44023
+ * @param indexOffset - 索引缓冲区中的字节偏移
44024
+ * @param indexCount - 索引数量
44025
+ * @param instanceCount - 实例数量
44026
+ * @hide
44027
+ */ _proto.drawElementsType = function drawElementsType(mode, indexOffset, indexCount, instanceCount) {
44028
+ throw new Error("The active rendering backend cannot draw indexed primitives.");
44029
+ };
44030
+ /**
44031
+ * 使用当前绑定的顶点缓冲区绘制图元。
44032
+ * @param mode - 图元类型
44033
+ * @param vertexStart - 起始顶点
44034
+ * @param vertexCount - 顶点数量
44035
+ * @param instanceCount - 实例数量
44036
+ * @hide
44037
+ */ _proto.drawArraysType = function drawArraysType(mode, vertexStart, vertexCount, instanceCount) {
44038
+ throw new Error("The active rendering backend cannot draw primitives.");
44039
+ };
42352
44040
  _proto.addTexture = function addTexture(tex) {
42353
44041
  if (this.disposed) {
42354
44042
  return;
@@ -42480,15 +44168,12 @@ var DEFAULT_FPS = 60;
42480
44168
  * @param height
42481
44169
  * example:
42482
44170
  * gl.viewport(0, 0, width, height);
42483
- */ _proto.viewport = function viewport(x, y, width, height) {
44171
+ */ _proto.setViewport = function setViewport(x, y, width, height) {
42484
44172
  // OVERRIDE
42485
44173
  };
42486
44174
  _proto.clear = function clear(action) {
42487
44175
  // OVERRIDE
42488
44176
  };
42489
- _proto.drawGeometry = function drawGeometry(geometry, matrix, material, subMeshIndex) {
42490
- // OVERRIDE
42491
- };
42492
44177
  /*** 渲染状态控制 ***/ _proto.setSampleAlphaToCoverage = function setSampleAlphaToCoverage(enable) {
42493
44178
  // OVERRIDE
42494
44179
  };
@@ -42573,6 +44258,12 @@ var DEFAULT_FPS = 60;
42573
44258
  }
42574
44259
  (_this_ticker = this.ticker) == null ? void 0 : _this_ticker.stop();
42575
44260
  (_this_eventSystem = this.eventSystem) == null ? void 0 : _this_eventSystem.dispose();
44261
+ for(var _iterator = _create_for_of_iterator_helper_loose(this._compositions.slice()), _step; !(_step = _iterator()).done;){
44262
+ var composition = _step.value;
44263
+ composition.dispose();
44264
+ }
44265
+ this.root.dispose();
44266
+ this.windowRoot.dispose();
42576
44267
  (_this_assetService = this.assetService) == null ? void 0 : _this_assetService.dispose();
42577
44268
  (_this__graphics = this._graphics) == null ? void 0 : _this__graphics.dispose();
42578
44269
  this.renderPasses.forEach(function(pass) {
@@ -42593,16 +44284,13 @@ var DEFAULT_FPS = 60;
42593
44284
  this.assetManagers.forEach(function(assetManager) {
42594
44285
  return assetManager.dispose();
42595
44286
  });
42596
- this.compositions.forEach(function(comp) {
42597
- return comp.dispose();
42598
- });
42599
44287
  this.textures = [];
42600
44288
  this.materials = [];
42601
44289
  this.geometries = [];
42602
44290
  this.meshes = [];
42603
44291
  this.renderPasses = [];
42604
- this.compositions = [];
42605
44292
  this.particleSystems = [];
44293
+ this._compositions = [];
42606
44294
  };
42607
44295
  _proto.getTargetSize = function getTargetSize(parentEle) {
42608
44296
  if (parentEle === undefined || parentEle === null) {
@@ -42655,6 +44343,14 @@ var DEFAULT_FPS = 60;
42655
44343
  ];
42656
44344
  };
42657
44345
  _create_class(Engine, [
44346
+ {
44347
+ key: "compositions",
44348
+ get: function get() {
44349
+ return this._compositions.sort(function(a, b) {
44350
+ return a.getIndex() - b.getIndex();
44351
+ });
44352
+ }
44353
+ },
42658
44354
  {
42659
44355
  key: "graphics",
42660
44356
  get: function get() {
@@ -42892,7 +44588,7 @@ registerPlugin("text", TextLoader);
42892
44588
  registerPlugin("sprite", SpriteLoader);
42893
44589
  registerPlugin("particle", ParticleLoader);
42894
44590
  registerPlugin("interact", InteractLoader);
42895
- var version$1 = "2.10.0-alpha.2";
44591
+ var version$1 = "2.10.0-alpha.3";
42896
44592
  logger.info("Core version: " + version$1 + ".");
42897
44593
 
42898
44594
  var _obj;
@@ -43839,7 +45535,7 @@ function disposeThreeGeometry(source) {
43839
45535
  return Composition.call(this, engine, props, scene);
43840
45536
  }
43841
45537
  var _proto = ThreeComposition.prototype;
43842
- _proto.render = function render() {
45538
+ _proto.renderContent = function renderContent() {
43843
45539
  var render = this.renderer;
43844
45540
  var frame = this.renderFrame;
43845
45541
  frame.renderPasses[0].meshes.length = 0;
@@ -43874,6 +45570,8 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
43874
45570
  _proto.getHeight = function getHeight() {
43875
45571
  return this.engine.canvas.height;
43876
45572
  };
45573
+ _proto.drawGeometry = function drawGeometry(geometry, matrix, material, subMeshIndex) {
45574
+ };
43877
45575
  return ThreeRenderer;
43878
45576
  }(Renderer);
43879
45577
 
@@ -44383,7 +46081,7 @@ applyMixins(exports.ThreeTextComponent, [
44383
46081
  */ Mesh.create = function(engine, props) {
44384
46082
  return new ThreeMesh(engine, props);
44385
46083
  };
44386
- var version = "2.10.0-alpha.2";
46084
+ var version = "2.10.0-alpha.3";
44387
46085
  logger.info("THREEJS plugin version: " + version + ".");
44388
46086
 
44389
46087
  exports.ATLAS_SIZE = ATLAS_SIZE;
@@ -44422,8 +46120,8 @@ exports.COPY_MESH_SHADER_ID = COPY_MESH_SHADER_ID;
44422
46120
  exports.COPY_VERTEX_SHADER = COPY_VERTEX_SHADER;
44423
46121
  exports.Camera = Camera;
44424
46122
  exports.CameraVFXItemLoader = CameraVFXItemLoader;
44425
- exports.CanvasItem = CanvasItem;
44426
- exports.CanvasLayer = CanvasLayer;
46123
+ exports.CanvasContainer = CanvasContainer;
46124
+ exports.CanvasRootControl = CanvasRootControl;
44427
46125
  exports.Circle = Circle$1;
44428
46126
  exports.ColorCurve = ColorCurve;
44429
46127
  exports.ColorPlayable = ColorPlayable;
@@ -44436,6 +46134,7 @@ exports.Composition = Composition;
44436
46134
  exports.ConstBoolNode = ConstBoolNode;
44437
46135
  exports.ConstFloatNode = ConstFloatNode;
44438
46136
  exports.ConstraintTarget = ConstraintTarget;
46137
+ exports.ContainerControl = ContainerControl;
44439
46138
  exports.Control = Control;
44440
46139
  exports.ControlParameterBoolNode = ControlParameterBoolNode;
44441
46140
  exports.ControlParameterFloatNode = ControlParameterFloatNode;
@@ -44459,7 +46158,6 @@ exports.Ellipse = Ellipse;
44459
46158
  exports.Engine = Engine;
44460
46159
  exports.EventEmitter = EventEmitter;
44461
46160
  exports.EventSystem = EventSystem;
44462
- exports.FONT_SCALE = FONT_SCALE;
44463
46161
  exports.Float16ArrayWrapper = Float16ArrayWrapper;
44464
46162
  exports.FloatComparisonNode = FloatComparisonNode;
44465
46163
  exports.FloatComparisonNodeData = FloatComparisonNodeData;
@@ -44476,6 +46174,14 @@ exports.GraphNode = GraphNode;
44476
46174
  exports.GraphNodeData = GraphNodeData;
44477
46175
  exports.Graphics = Graphics;
44478
46176
  exports.HELP_LINK = HELP_LINK;
46177
+ exports.InputEvent = InputEvent;
46178
+ exports.InputEventKey = InputEventKey;
46179
+ exports.InputEventMouse = InputEventMouse;
46180
+ exports.InputEventMouseButton = InputEventMouseButton;
46181
+ exports.InputEventMouseMotion = InputEventMouseMotion;
46182
+ exports.InputEventScreenDrag = InputEventScreenDrag;
46183
+ exports.InputEventScreenTouch = InputEventScreenTouch;
46184
+ exports.InputEventWithModifiers = InputEventWithModifiers;
44479
46185
  exports.InteractLoader = InteractLoader;
44480
46186
  exports.InteractMesh = InteractMesh;
44481
46187
  exports.InvalidIndex = InvalidIndex;
@@ -44524,7 +46230,6 @@ exports.RandomSetValue = RandomSetValue;
44524
46230
  exports.RandomValue = RandomValue;
44525
46231
  exports.RandomVectorValue = RandomVectorValue;
44526
46232
  exports.RaycastResult = RaycastResult;
44527
- exports.RectTransform = RectTransform;
44528
46233
  exports.Rectangle = Rectangle$1;
44529
46234
  exports.ReferenceCurve = ReferenceCurve;
44530
46235
  exports.RenderFrame = RenderFrame;
@@ -44537,6 +46242,7 @@ exports.RenderTargetPool = RenderTargetPool;
44537
46242
  exports.Renderbuffer = Renderbuffer;
44538
46243
  exports.Renderer = Renderer;
44539
46244
  exports.RendererComponent = RendererComponent;
46245
+ exports.RootControl = RootControl;
44540
46246
  exports.RuntimeClip = RuntimeClip;
44541
46247
  exports.SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0 = SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0;
44542
46248
  exports.SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0 = SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0;
@@ -44580,6 +46286,8 @@ exports.TransformPlayable = TransformPlayable;
44580
46286
  exports.TransitionNode = TransitionNode;
44581
46287
  exports.Triangle = Triangle;
44582
46288
  exports.TrimPath = TrimPath;
46289
+ exports.UICanvas = UICanvas;
46290
+ exports.UIControl = UIControl;
44583
46291
  exports.ValueGetter = ValueGetter;
44584
46292
  exports.ValueNode = ValueNode;
44585
46293
  exports.Vector2Curve = Vector2Curve;
@@ -44589,6 +46297,7 @@ exports.Vector3PropertyMixerPlayable = Vector3PropertyMixerPlayable;
44589
46297
  exports.Vector4Curve = Vector4Curve;
44590
46298
  exports.Vector4PropertyMixerPlayable = Vector4PropertyMixerPlayable;
44591
46299
  exports.VertexBuffer = VertexBuffer;
46300
+ exports.WindowRootControl = WindowRootControl;
44592
46301
  exports.addByOrder = addByOrder;
44593
46302
  exports.addItem = addItem;
44594
46303
  exports.addItemWithOrder = addItemWithOrder;