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

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.3
6
+ * Version: v2.10.0-alpha.5
7
7
  */
8
8
 
9
9
  'use strict';
@@ -2958,6 +2958,11 @@ var PluginSystem = /*#__PURE__*/ function() {
2958
2958
  PluginSystem.getPlugins = function getPlugins() {
2959
2959
  return plugins;
2960
2960
  };
2961
+ PluginSystem.notifyCompositionCreating = function notifyCompositionCreating(composition, scene) {
2962
+ plugins.forEach(function(plugin) {
2963
+ return plugin.onCompositionCreating(composition, scene);
2964
+ });
2965
+ };
2961
2966
  PluginSystem.notifyCompositionCreated = function notifyCompositionCreated(composition, scene) {
2962
2967
  plugins.forEach(function(plugin) {
2963
2968
  return plugin.onCompositionCreated(composition, scene);
@@ -3050,6 +3055,12 @@ function getPluginUsageInfo(name) {
3050
3055
  * @param engine - 引擎实例
3051
3056
  */ _proto.onAssetsLoadFinish = function onAssetsLoadFinish(scene, options, engine) {};
3052
3057
  /**
3058
+ * 合成内容开始创建前触发。
3059
+ * 此时 root、pluginRoot 和 sceneRoot 已创建,但场景内容尚未实例化。
3060
+ * @param composition - 正在创建的合成对象
3061
+ * @param scene - 场景对象
3062
+ */ _proto.onCompositionCreating = function onCompositionCreating(composition, scene) {};
3063
+ /**
3053
3064
  * 合成创建完成后触发。
3054
3065
  * @param composition - 合成对象
3055
3066
  * @param scene - 场景对象
@@ -15658,35 +15669,35 @@ function vecMulCombine(out, a, b) {
15658
15669
  }
15659
15670
  return out;
15660
15671
  }
15661
- var _obj$7;
15662
- var particleOriginTranslateMap$1 = (_obj$7 = {}, _obj$7[ParticleOrigin.PARTICLE_ORIGIN_CENTER] = [
15672
+ var _obj$6;
15673
+ var particleOriginTranslateMap$1 = (_obj$6 = {}, _obj$6[ParticleOrigin.PARTICLE_ORIGIN_CENTER] = [
15663
15674
  0,
15664
15675
  0
15665
- ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_CENTER_BOTTOM] = [
15676
+ ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_CENTER_BOTTOM] = [
15666
15677
  0,
15667
15678
  -0.5
15668
- ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_CENTER_TOP] = [
15679
+ ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_CENTER_TOP] = [
15669
15680
  0,
15670
15681
  0.5
15671
- ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_LEFT_TOP] = [
15682
+ ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_LEFT_TOP] = [
15672
15683
  -0.5,
15673
15684
  0.5
15674
- ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_LEFT_CENTER] = [
15685
+ ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_LEFT_CENTER] = [
15675
15686
  -0.5,
15676
15687
  0
15677
- ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_LEFT_BOTTOM] = [
15688
+ ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_LEFT_BOTTOM] = [
15678
15689
  -0.5,
15679
15690
  -0.5
15680
- ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_CENTER] = [
15691
+ ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_CENTER] = [
15681
15692
  0.5,
15682
15693
  0
15683
- ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_BOTTOM] = [
15694
+ ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_BOTTOM] = [
15684
15695
  0.5,
15685
15696
  -0.5
15686
- ], _obj$7[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_TOP] = [
15697
+ ], _obj$6[ParticleOrigin.PARTICLE_ORIGIN_RIGHT_TOP] = [
15687
15698
  0.5,
15688
15699
  0.5
15689
- ], _obj$7);
15700
+ ], _obj$6);
15690
15701
  function nearestPowerOfTwo(value) {
15691
15702
  return Math.pow(2, Math.round(Math.log(value) / Math.LN2));
15692
15703
  }
@@ -17424,27 +17435,27 @@ function oldBezierKeyFramesToNew(props) {
17424
17435
  * 对象引用阶梯曲线(spec ValueType.REFERENCE_CURVE)。
17425
17436
  * props 为 [[time, value], ...],value 为已解析的对象引用实例。
17426
17437
  */ var REFERENCE_CURVE = 28;
17427
- var _obj$6;
17428
- var map$1 = (_obj$6 = {}, _obj$6[ValueType.RANDOM] = function(props) {
17438
+ var _obj$5;
17439
+ var map$1 = (_obj$5 = {}, _obj$5[ValueType.RANDOM] = function(props) {
17429
17440
  if (_instanceof1(props[0], Array)) {
17430
17441
  return new RandomVectorValue(props);
17431
17442
  }
17432
17443
  return new RandomValue(props);
17433
- }, _obj$6[ValueType.CONSTANT] = function(props) {
17444
+ }, _obj$5[ValueType.CONSTANT] = function(props) {
17434
17445
  return new StaticValue(props);
17435
- }, _obj$6[ValueType.CONSTANT_VEC2] = function(props) {
17446
+ }, _obj$5[ValueType.CONSTANT_VEC2] = function(props) {
17436
17447
  return new StaticValue(props);
17437
- }, _obj$6[ValueType.CONSTANT_VEC3] = function(props) {
17448
+ }, _obj$5[ValueType.CONSTANT_VEC3] = function(props) {
17438
17449
  return new StaticValue(props);
17439
- }, _obj$6[ValueType.CONSTANT_VEC4] = function(props) {
17450
+ }, _obj$5[ValueType.CONSTANT_VEC4] = function(props) {
17440
17451
  return new StaticValue(props);
17441
- }, _obj$6[ValueType.RGBA_COLOR] = function(props) {
17452
+ }, _obj$5[ValueType.RGBA_COLOR] = function(props) {
17442
17453
  return new StaticValue(props);
17443
- }, _obj$6[ValueType.COLORS] = function(props) {
17454
+ }, _obj$5[ValueType.COLORS] = function(props) {
17444
17455
  return new RandomSetValue(props.map(function(c) {
17445
17456
  return colorToArr$1(c, false);
17446
17457
  }));
17447
- }, _obj$6[ValueType.LINE] = function(props) {
17458
+ }, _obj$5[ValueType.LINE] = function(props) {
17448
17459
  if (props.length === 2 && props[0][0] === 0 && props[1][0] === 1) {
17449
17460
  return new LinearValue([
17450
17461
  props[0][1],
@@ -17452,38 +17463,38 @@ var map$1 = (_obj$6 = {}, _obj$6[ValueType.RANDOM] = function(props) {
17452
17463
  ]);
17453
17464
  }
17454
17465
  return new LineSegments(props);
17455
- }, _obj$6[ValueType.GRADIENT_COLOR] = function(props) {
17466
+ }, _obj$5[ValueType.GRADIENT_COLOR] = function(props) {
17456
17467
  return new GradientValue(props);
17457
- }, _obj$6[ValueType.LINEAR_PATH] = function(pros) {
17468
+ }, _obj$5[ValueType.LINEAR_PATH] = function(pros) {
17458
17469
  return new PathSegments(pros);
17459
- }, _obj$6[ValueType.BEZIER_CURVE] = function(props) {
17470
+ }, _obj$5[ValueType.BEZIER_CURVE] = function(props) {
17460
17471
  if (props.length === 1) {
17461
17472
  return new StaticValue(props[0][1][1]);
17462
17473
  }
17463
17474
  return new BezierCurve(props);
17464
- }, _obj$6[ValueType.BEZIER_CURVE_PATH] = function(props) {
17475
+ }, _obj$5[ValueType.BEZIER_CURVE_PATH] = function(props) {
17465
17476
  if (props[0].length === 1) {
17466
17477
  return new StaticValue(_construct(Vector3, [].concat(props[1][0])));
17467
17478
  }
17468
17479
  return new BezierCurvePath(props);
17469
- }, _obj$6[ValueType.BEZIER_CURVE_QUAT] = function(props) {
17480
+ }, _obj$5[ValueType.BEZIER_CURVE_QUAT] = function(props) {
17470
17481
  if (props[0].length === 1) {
17471
17482
  return new StaticValue(_construct(Quaternion, [].concat(props[1][0])));
17472
17483
  }
17473
17484
  return new BezierCurveQuat(props);
17474
- }, _obj$6[ValueType.COLOR_CURVE] = function(props) {
17485
+ }, _obj$5[ValueType.COLOR_CURVE] = function(props) {
17475
17486
  return new ColorCurve(props);
17476
- }, _obj$6[ValueType.VECTOR4_CURVE] = function(props) {
17487
+ }, _obj$5[ValueType.VECTOR4_CURVE] = function(props) {
17477
17488
  return new Vector4Curve(props);
17478
- }, _obj$6[ValueType.VECTOR2_CURVE] = function(props) {
17489
+ }, _obj$5[ValueType.VECTOR2_CURVE] = function(props) {
17479
17490
  return new Vector2Curve(props);
17480
17491
  }, // TODO: add spec
17481
- _obj$6[VECTOR3_CURVE] = function(props) {
17492
+ _obj$5[VECTOR3_CURVE] = function(props) {
17482
17493
  return new Vector3Curve(props);
17483
17494
  }, // 对象引用阶梯曲线(不插值):props.data 为 [time, value][],value 已解析为 EffectsObject
17484
- _obj$6[REFERENCE_CURVE] = function(props) {
17495
+ _obj$5[REFERENCE_CURVE] = function(props) {
17485
17496
  return new ReferenceCurve(props);
17486
- }, _obj$6);
17497
+ }, _obj$5);
17487
17498
  function createValueGetter(args) {
17488
17499
  if (!args || !isNaN(+args)) {
17489
17500
  return new StaticValue(args || 0);
@@ -21424,8 +21435,8 @@ var vertexBufferSemanticMap = {
21424
21435
  TANGENT_BS2: "aTargetTangent2",
21425
21436
  TANGENT_BS3: "aTargetTangent3"
21426
21437
  };
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);
21438
+ var _obj$4;
21439
+ 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);
21429
21440
  function generateEmptyTypedArray(type) {
21430
21441
  return createTypedArray(type, 0);
21431
21442
  }
@@ -22942,7 +22953,7 @@ var canvasPool = new CanvasPool();
22942
22953
  * `ATLAS_SIZE × ATLAS_SIZE` 的离屏 canvas atlas,字符按需逐个绘制并打包,
22943
22954
  * `Graphics.drawText` 通过逐字 quad 引用 atlas 子矩形渲染。
22944
22955
  *
22945
- * - 同一段文本不同颜色不会重复 upload(颜色由顶点 `vColor` 乘上字形 alpha)
22956
+ * - 同一段文本不同颜色不会重复 upload(颜色由顶点 `vColor` 与字形 RGBA 相乘)
22946
22957
  * - 同一字体/字号下重复字符只渲染一次,显著减少 canvas → texture 上传次数
22947
22958
  *
22948
22959
  * 入参全部展开(避免调用方每帧创建临时 style 对象触发 GC)
@@ -22956,7 +22967,7 @@ var canvasPool = new CanvasPool();
22956
22967
  /**
22957
22968
  * 取(必要时新建)对应字体的字符 atlas
22958
22969
  */ _proto.getAtlas = function getAtlas(fontSize, fontFamily, fontWeight, fontStyle) {
22959
- // Pixi CanvasText 默认跟随 renderer.resolution;这里对应 Engine.pixelRatio。
22970
+ // 字形 atlas 跟随 Engine.pixelRatio。
22960
22971
  var resolution = this.engine.pixelRatio;
22961
22972
  if (resolution !== this.resolution) {
22962
22973
  this.clear();
@@ -22977,14 +22988,11 @@ var canvasPool = new CanvasPool();
22977
22988
  var probeCtx = probeCanvasAndContext.context;
22978
22989
  var ascentPx = fontSize * 0.8 * resolution;
22979
22990
  var descentPx = fontSize * 0.2 * resolution;
22980
- try {
22981
- probeCtx.font = scaledFontString;
22982
- var m = probeCtx.measureText(METRICS_STRING + BASELINE_SYMBOL);
22983
- ascentPx = m.actualBoundingBoxAscent || ascentPx;
22984
- descentPx = m.actualBoundingBoxDescent || descentPx;
22985
- } finally{
22986
- canvasPool.releaseCanvasAndContext(probeCanvasAndContext);
22987
- }
22991
+ probeCtx.font = scaledFontString;
22992
+ var m = probeCtx.measureText(METRICS_STRING + BASELINE_SYMBOL);
22993
+ ascentPx = m.actualBoundingBoxAscent || ascentPx;
22994
+ descentPx = m.actualBoundingBoxDescent || descentPx;
22995
+ canvasPool.releaseCanvasAndContext(probeCanvasAndContext);
22988
22996
  var atlas = new GlyphAtlas(this.engine, scaledFontString, ascentPx, descentPx, fontStyle, resolution);
22989
22997
  this.atlases.set(fontKey, atlas);
22990
22998
  return atlas;
@@ -23020,6 +23028,10 @@ var FULL_REGION = {
23020
23028
  u1: 1,
23021
23029
  v1: 1
23022
23030
  };
23031
+ var NINE_PATCH_DRAW_SOURCE_SIZE = "aDrawSourceSize";
23032
+ var NINE_PATCH_SOURCE_RECT = "aSourceRect";
23033
+ var NINE_PATCH_MARGINS = "aMargins";
23034
+ var NINE_PATCH_OPTIONS = "aOptions";
23023
23035
  var Graphics = /*#__PURE__*/ function() {
23024
23036
  function Graphics(engine) {
23025
23037
  this.engine = engine;
@@ -23033,6 +23045,10 @@ var Graphics = /*#__PURE__*/ function() {
23033
23045
  this.colors = [];
23034
23046
  this.uvs = [];
23035
23047
  this.indices = [];
23048
+ this.ninePatchDrawSourceSizes = [];
23049
+ this.ninePatchSourceRects = [];
23050
+ this.ninePatchMargins = [];
23051
+ this.ninePatchOptions = [];
23036
23052
  this.lineStyle = {
23037
23053
  width: 1,
23038
23054
  alignment: 0.5,
@@ -23044,6 +23060,9 @@ var Graphics = /*#__PURE__*/ function() {
23044
23060
  this.currentBatchTexture = null;
23045
23061
  this.transformStack = [];
23046
23062
  this.currentTransform = Matrix3.fromIdentity();
23063
+ this.clipStack = [];
23064
+ this.logicalWidth = 1;
23065
+ this.logicalHeight = 1;
23047
23066
  var _obj;
23048
23067
  this.geometry = Geometry.create(this.engine, {
23049
23068
  attributes: (_obj = {}, _obj[VertexBuffer.PositionKind] = {
@@ -23109,6 +23128,51 @@ var Graphics = /*#__PURE__*/ function() {
23109
23128
  drawCount: 6,
23110
23129
  bufferUsage: glContext.DYNAMIC_DRAW
23111
23130
  });
23131
+ var _obj1;
23132
+ this.ninePatchGeometry = Geometry.create(this.engine, {
23133
+ attributes: (_obj1 = {}, _obj1[VertexBuffer.PositionKind] = {
23134
+ type: glContext.FLOAT,
23135
+ size: 2,
23136
+ data: new Float32Array(8)
23137
+ }, _obj1[VertexBuffer.ColorKind] = {
23138
+ type: glContext.FLOAT,
23139
+ size: 4,
23140
+ data: new Float32Array(16)
23141
+ }, _obj1[VertexBuffer.UVKind] = {
23142
+ type: glContext.FLOAT,
23143
+ size: 2,
23144
+ data: new Float32Array(8)
23145
+ }, _obj1[NINE_PATCH_DRAW_SOURCE_SIZE] = {
23146
+ type: glContext.FLOAT,
23147
+ size: 4,
23148
+ data: new Float32Array(16)
23149
+ }, _obj1[NINE_PATCH_SOURCE_RECT] = {
23150
+ type: glContext.FLOAT,
23151
+ size: 4,
23152
+ data: new Float32Array(16)
23153
+ }, _obj1[NINE_PATCH_MARGINS] = {
23154
+ type: glContext.FLOAT,
23155
+ size: 4,
23156
+ data: new Float32Array(16)
23157
+ }, _obj1[NINE_PATCH_OPTIONS] = {
23158
+ type: glContext.FLOAT,
23159
+ size: 4,
23160
+ data: new Float32Array(16)
23161
+ }, _obj1),
23162
+ indices: {
23163
+ data: new Uint16Array([
23164
+ 0,
23165
+ 1,
23166
+ 2,
23167
+ 2,
23168
+ 1,
23169
+ 3
23170
+ ])
23171
+ },
23172
+ mode: glContext.TRIANGLES,
23173
+ drawCount: 6,
23174
+ bufferUsage: glContext.DYNAMIC_DRAW
23175
+ });
23112
23176
  this.coloredMaterial = Material.create(this.engine, {
23113
23177
  shader: {
23114
23178
  vertex: "precision highp float;\n attribute vec2 aPos;\n attribute vec4 aColor;\n varying vec4 vColor;\n\n uniform mat4 effects_MatrixVP;\n void main() {\n vColor = aColor;\n gl_Position = effects_MatrixVP * vec4(aPos, 0.0, 1.0);\n }",
@@ -23127,12 +23191,21 @@ var Graphics = /*#__PURE__*/ function() {
23127
23191
  this.texturedMaterial.depthTest = false;
23128
23192
  this.texturedMaterial.depthMask = false;
23129
23193
  this.texturedMaterial.blending = true;
23130
- // 文本 atlas 按 Pixi 的方式在上传时预乘 alpha,因此采样后只需应用顶点色和顶点 alpha。
23194
+ this.ninePatchMaterial = Material.create(this.engine, {
23195
+ shader: {
23196
+ vertex: "precision highp float;\n attribute vec2 aPos;\n attribute vec4 aColor;\n attribute vec2 aUV;\n attribute vec4 aDrawSourceSize;\n attribute vec4 aSourceRect;\n attribute vec4 aMargins;\n attribute vec4 aOptions;\n varying vec4 vColor;\n varying vec2 vUV;\n varying vec4 vDrawSourceSize;\n varying vec4 vSourceRect;\n varying vec4 vMargins;\n varying vec4 vOptions;\n\n uniform mat4 effects_MatrixVP;\n void main() {\n vColor = aColor;\n vUV = aUV;\n vDrawSourceSize = aDrawSourceSize;\n vSourceRect = aSourceRect;\n vMargins = aMargins;\n vOptions = aOptions;\n gl_Position = effects_MatrixVP * vec4(aPos, 0.0, 1.0);\n }",
23197
+ fragment: "precision highp float;\n varying vec4 vColor;\n varying vec2 vUV;\n varying vec4 vDrawSourceSize;\n varying vec4 vSourceRect;\n varying vec4 vMargins;\n varying vec4 vOptions;\n uniform sampler2D uMainTexture;\n\n float mapNinePatchAxis(\n float pixel,\n float drawSize,\n float sourceSize,\n float marginBegin,\n float marginEnd,\n float repeatMode,\n inout float drawCenter\n ) {\n if (pixel < marginBegin) {\n return pixel / sourceSize;\n } else if (pixel >= drawSize - marginEnd) {\n return (sourceSize - (drawSize - pixel)) / sourceSize;\n } else {\n if (vOptions.z < 0.5) {\n drawCenter -= 1.0;\n }\n\n if (repeatMode < 0.5) {\n float ratio = (pixel - marginBegin) / (drawSize - marginBegin - marginEnd);\n return (marginBegin + ratio * (sourceSize - marginBegin - marginEnd)) / sourceSize;\n } else if (repeatMode < 1.5) {\n float offset = mod(pixel - marginBegin, sourceSize - marginBegin - marginEnd);\n return (marginBegin + offset) / sourceSize;\n } else {\n float drawArea = drawSize - marginBegin - marginEnd;\n float sourceArea = sourceSize - marginBegin - marginEnd;\n float scale = max(1.0, floor(drawArea / max(sourceArea, 0.0000001) + 0.5));\n float ratio = mod((pixel - marginBegin) / drawArea * scale, 1.0);\n return (marginBegin + ratio * sourceArea) / sourceSize;\n }\n }\n }\n\n void main() {\n vec2 pixel = vec2(vUV.x, 1.0 - vUV.y) * vDrawSourceSize.xy;\n float drawCenter = 2.0;\n vec2 sourceUV = vec2(\n mapNinePatchAxis(\n pixel.x, vDrawSourceSize.x, vDrawSourceSize.z,\n vMargins.x, vMargins.z, vOptions.x, drawCenter\n ),\n mapNinePatchAxis(\n pixel.y, vDrawSourceSize.y, vDrawSourceSize.w,\n vMargins.y, vMargins.w, vOptions.y, drawCenter\n )\n );\n\n if (drawCenter < 0.5) {\n discard;\n }\n\n vec2 uv = vec2(\n vSourceRect.x + sourceUV.x * vSourceRect.z,\n vSourceRect.y - sourceUV.y * vSourceRect.w\n );\n vec4 color = texture2D(uMainTexture, uv) * vColor;\n color.rgb *= color.a;\n gl_FragColor = color;\n }"
23198
+ }
23199
+ });
23200
+ this.ninePatchMaterial.depthTest = false;
23201
+ this.ninePatchMaterial.depthMask = false;
23202
+ this.ninePatchMaterial.blending = true;
23203
+ // 文本 atlas 在上传时预乘 alpha,因此纹理 RGB 只需乘顶点色和顶点 alpha。
23131
23204
  // 单独使用 material,避免改变 drawTexture 对普通非预乘纹理的处理。
23132
23205
  this.textMaterial = Material.create(this.engine, {
23133
23206
  shader: {
23134
23207
  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 }"
23208
+ fragment: "precision highp float;\n varying vec4 vColor;\n varying vec2 vUV;\n uniform sampler2D uMainTexture;\n void main() {\n vec4 textureColor = texture2D(uMainTexture, vUV);\n float alpha = textureColor.a * vColor.a;\n vec3 rgb = textureColor.rgb * vColor.rgb * vColor.a;\n gl_FragColor = vec4(rgb, alpha);\n }"
23136
23209
  }
23137
23210
  });
23138
23211
  this.textMaterial.depthTest = false;
@@ -23148,25 +23221,36 @@ var Graphics = /*#__PURE__*/ function() {
23148
23221
  this.vertices.length = 0;
23149
23222
  this.colors.length = 0;
23150
23223
  this.uvs.length = 0;
23224
+ this.ninePatchDrawSourceSizes.length = 0;
23225
+ this.ninePatchSourceRects.length = 0;
23226
+ this.ninePatchMargins.length = 0;
23227
+ this.ninePatchOptions.length = 0;
23151
23228
  this.transformStack = [];
23152
23229
  this.currentTransform = Matrix3.fromIdentity();
23230
+ this.clipStack = [];
23153
23231
  this.currentBatchType = "colored";
23154
23232
  this.currentBatchTexture = null;
23155
- // 创建从屏幕坐标到 NDC 的投影矩阵,屏幕坐标: (0, 0) 在左下角,(width, height) 在右上角
23156
- var _this_engine_canvas_getBoundingClientRect = this.engine.canvas.getBoundingClientRect(), width = _this_engine_canvas_getBoundingClientRect.width, height = _this_engine_canvas_getBoundingClientRect.height;
23233
+ this.engine.setScissorTest(false);
23234
+ // 创建从屏幕坐标到 NDC 的投影矩阵,屏幕坐标:(0, 0) 在左上角,(width, height) 在右下角,+Y 向下。
23235
+ var bounds = this.engine.canvas.getBoundingClientRect();
23236
+ var width = bounds.width || this.engine.canvas.width / this.engine.pixelRatio || 1;
23237
+ var height = bounds.height || this.engine.canvas.height / this.engine.pixelRatio || 1;
23238
+ this.logicalWidth = width;
23239
+ this.logicalHeight = height;
23157
23240
  // 正交投影矩阵:将屏幕坐标 [0, width] x [0, height] 映射到 NDC [-1, 1] x [-1, 1]
23158
- var projectionMatrix = new Matrix4(2 / width, 0, 0, 0, 0, 2 / height, 0, 0, 0, 0, -1, 0, -1, -1, 0, 1 // 第四列
23241
+ var projectionMatrix = new Matrix4(2 / width, 0, 0, 0, 0, -2 / height, 0, 0, 0, 0, -1, 0, -1, 1, 0, 1 // 第四列
23159
23242
  );
23160
23243
  this.coloredMaterial.setMatrix("effects_MatrixVP", projectionMatrix);
23161
23244
  this.texturedMaterial.setMatrix("effects_MatrixVP", projectionMatrix);
23162
23245
  this.textMaterial.setMatrix("effects_MatrixVP", projectionMatrix);
23246
+ this.ninePatchMaterial.setMatrix("effects_MatrixVP", projectionMatrix);
23163
23247
  };
23164
23248
  /**
23165
23249
  * 将当前变换压入栈,并设置新的变换
23166
23250
  * @param transform - 新的变换矩阵(会与当前变换相乘)
23167
23251
  */ _proto.pushTransform = function pushTransform(transform) {
23168
23252
  this.transformStack.push(this.currentTransform.clone());
23169
- this.currentTransform = this.currentTransform.premultiply(transform);
23253
+ this.currentTransform = this.currentTransform.multiply(transform);
23170
23254
  };
23171
23255
  /**
23172
23256
  * 恢复上一个变换
@@ -23178,10 +23262,81 @@ var Graphics = /*#__PURE__*/ function() {
23178
23262
  }
23179
23263
  this.currentTransform = transform;
23180
23264
  };
23265
+ /** Pushes a local rectangular child clip using a screen-space AABB scissor. */ _proto.pushClipRect = function pushClipRect(x, y, width, height) {
23266
+ var elements = this.currentTransform.elements;
23267
+ var corners = [
23268
+ [
23269
+ x,
23270
+ y
23271
+ ],
23272
+ [
23273
+ x + width,
23274
+ y
23275
+ ],
23276
+ [
23277
+ x,
23278
+ y + height
23279
+ ],
23280
+ [
23281
+ x + width,
23282
+ y + height
23283
+ ]
23284
+ ];
23285
+ var left = Infinity;
23286
+ var top = Infinity;
23287
+ var right = -Infinity;
23288
+ var bottom = -Infinity;
23289
+ for(var _iterator = _create_for_of_iterator_helper_loose(corners), _step; !(_step = _iterator()).done;){
23290
+ var corner = _step.value;
23291
+ var transformedX = elements[0] * corner[0] + elements[3] * corner[1] + elements[6];
23292
+ var transformedY = elements[1] * corner[0] + elements[4] * corner[1] + elements[7];
23293
+ left = Math.min(left, transformedX);
23294
+ top = Math.min(top, transformedY);
23295
+ right = Math.max(right, transformedX);
23296
+ bottom = Math.max(bottom, transformedY);
23297
+ }
23298
+ var parent = this.clipStack[this.clipStack.length - 1];
23299
+ if (parent) {
23300
+ left = Math.max(left, parent.x);
23301
+ top = Math.max(top, parent.y);
23302
+ right = Math.min(right, parent.x + parent.width);
23303
+ bottom = Math.min(bottom, parent.y + parent.height);
23304
+ }
23305
+ var clip = {
23306
+ x: left,
23307
+ y: top,
23308
+ width: Math.max(0, right - left),
23309
+ height: Math.max(0, bottom - top)
23310
+ };
23311
+ var previous = parent;
23312
+ this.clipStack.push(clip);
23313
+ if (!this.clipRectsEqual(previous, clip)) {
23314
+ this.flushBatch();
23315
+ this.applyClipRect(clip);
23316
+ }
23317
+ };
23318
+ /** Restores the parent rectangular clip. */ _proto.popClipRect = function popClipRect() {
23319
+ var previous = this.clipStack.pop();
23320
+ if (!previous) {
23321
+ console.warn("Graphics: clip stack is empty.");
23322
+ return;
23323
+ }
23324
+ var clip = this.clipStack[this.clipStack.length - 1];
23325
+ if (!this.clipRectsEqual(previous, clip)) {
23326
+ this.flushBatch();
23327
+ if (clip) {
23328
+ this.applyClipRect(clip);
23329
+ } else {
23330
+ this.engine.setScissorTest(false);
23331
+ }
23332
+ }
23333
+ };
23181
23334
  /**
23182
23335
  * 刷新并渲染所有累积的绘制命令
23183
23336
  */ _proto.end = function end() {
23184
23337
  this.flushBatch();
23338
+ this.clipStack = [];
23339
+ this.engine.setScissorTest(false);
23185
23340
  };
23186
23341
  /**
23187
23342
  * 切换到指定批次类型/纹理。若与当前批次不一致,先 flush 已累积顶点
@@ -23194,6 +23349,24 @@ var Graphics = /*#__PURE__*/ function() {
23194
23349
  this.currentBatchType = type;
23195
23350
  this.currentBatchTexture = texture;
23196
23351
  };
23352
+ _proto.applyClipRect = function applyClipRect(clip) {
23353
+ var framebufferWidth = this.engine.canvas.width;
23354
+ var framebufferHeight = this.engine.canvas.height;
23355
+ var scaleX = framebufferWidth / this.logicalWidth;
23356
+ var scaleY = framebufferHeight / this.logicalHeight;
23357
+ var left = Math.max(0, Math.min(framebufferWidth, Math.floor(clip.x * scaleX)));
23358
+ var top = Math.max(0, Math.min(framebufferHeight, Math.floor(clip.y * scaleY)));
23359
+ var right = Math.max(left, Math.min(framebufferWidth, Math.ceil((clip.x + clip.width) * scaleX)));
23360
+ var bottom = Math.max(top, Math.min(framebufferHeight, Math.ceil((clip.y + clip.height) * scaleY)));
23361
+ this.engine.setScissorTest(true);
23362
+ this.engine.setScissor(left, framebufferHeight - bottom, right - left, bottom - top);
23363
+ };
23364
+ _proto.clipRectsEqual = function clipRectsEqual(left, right) {
23365
+ if (!left || !right) {
23366
+ return left === right;
23367
+ }
23368
+ return left.x === right.x && left.y === right.y && left.width === right.width && left.height === right.height;
23369
+ };
23197
23370
  /**
23198
23371
  * 提交当前累积的顶点到 renderer,清空缓冲(批次内部 flush 不重置 batchType)
23199
23372
  */ _proto.flushBatch = function flushBatch() {
@@ -23207,37 +23380,48 @@ var Graphics = /*#__PURE__*/ function() {
23207
23380
  var colorsArray = new Float32Array(this.colors);
23208
23381
  var uvsArray = new Float32Array(this.uvs);
23209
23382
  var indicesArray = new Uint16Array(this.indices);
23210
- this.updateAttributeData(VertexBuffer.PositionKind, verticesArray, 2);
23211
- this.updateAttributeData(VertexBuffer.ColorKind, colorsArray, 4);
23212
- this.updateAttributeData(VertexBuffer.UVKind, uvsArray, 2);
23213
- this.geometry.setIndexData(indicesArray);
23214
- this.geometry.setDrawCount(this.currentIndexCount);
23383
+ var geometry = this.currentBatchType === "ninePatch" ? this.ninePatchGeometry : this.geometry;
23384
+ this.updateAttributeData(geometry, VertexBuffer.PositionKind, verticesArray, 2);
23385
+ this.updateAttributeData(geometry, VertexBuffer.ColorKind, colorsArray, 4);
23386
+ this.updateAttributeData(geometry, VertexBuffer.UVKind, uvsArray, 2);
23387
+ if (this.currentBatchType === "ninePatch") {
23388
+ this.updateAttributeData(geometry, NINE_PATCH_DRAW_SOURCE_SIZE, new Float32Array(this.ninePatchDrawSourceSizes), 4);
23389
+ this.updateAttributeData(geometry, NINE_PATCH_SOURCE_RECT, new Float32Array(this.ninePatchSourceRects), 4);
23390
+ this.updateAttributeData(geometry, NINE_PATCH_MARGINS, new Float32Array(this.ninePatchMargins), 4);
23391
+ this.updateAttributeData(geometry, NINE_PATCH_OPTIONS, new Float32Array(this.ninePatchOptions), 4);
23392
+ }
23393
+ geometry.setIndexData(indicesArray);
23394
+ geometry.setDrawCount(this.currentIndexCount);
23215
23395
  var material;
23216
- if (this.currentBatchType === "textured" || this.currentBatchType === "text") {
23217
- material = this.currentBatchType === "text" ? this.textMaterial : this.texturedMaterial;
23396
+ if (this.currentBatchType === "textured" || this.currentBatchType === "text" || this.currentBatchType === "ninePatch") {
23397
+ material = this.currentBatchType === "text" ? this.textMaterial : this.currentBatchType === "ninePatch" ? this.ninePatchMaterial : this.texturedMaterial;
23218
23398
  var _this_currentBatchTexture;
23219
23399
  var tex = (_this_currentBatchTexture = this.currentBatchTexture) != null ? _this_currentBatchTexture : this.engine.whiteTexture;
23220
23400
  material.setTexture("uMainTexture", tex);
23221
23401
  } else {
23222
23402
  material = this.coloredMaterial;
23223
23403
  }
23224
- this.engine.renderer.drawGeometry(this.geometry, Matrix4.IDENTITY, material);
23404
+ this.engine.renderer.drawGeometry(geometry, Matrix4.IDENTITY, material);
23225
23405
  this.indices.length = 0;
23226
23406
  this.vertices.length = 0;
23227
23407
  this.colors.length = 0;
23228
23408
  this.uvs.length = 0;
23229
- };
23230
- _proto.updateAttributeData = function updateAttributeData(name, data, size) {
23231
- var _this_geometry_getVertexBuffer;
23232
- var dataBuffer = (_this_geometry_getVertexBuffer = this.geometry.getVertexBuffer(name)) == null ? void 0 : _this_geometry_getVertexBuffer.getBuffer();
23409
+ this.ninePatchDrawSourceSizes.length = 0;
23410
+ this.ninePatchSourceRects.length = 0;
23411
+ this.ninePatchMargins.length = 0;
23412
+ this.ninePatchOptions.length = 0;
23413
+ };
23414
+ _proto.updateAttributeData = function updateAttributeData(geometry, name, data, size) {
23415
+ var _geometry_getVertexBuffer;
23416
+ var dataBuffer = (_geometry_getVertexBuffer = geometry.getVertexBuffer(name)) == null ? void 0 : _geometry_getVertexBuffer.getBuffer();
23233
23417
  if (dataBuffer && data.byteLength > dataBuffer.capacity) {
23234
- this.geometry.setVerticesBuffer(new VertexBuffer(this.engine, data, name, {
23418
+ geometry.setVerticesBuffer(new VertexBuffer(this.engine, data, name, {
23235
23419
  updatable: true,
23236
23420
  size: size
23237
23421
  }));
23238
23422
  return;
23239
23423
  }
23240
- this.geometry.setAttributeData(name, data);
23424
+ geometry.setAttributeData(name, data);
23241
23425
  };
23242
23426
  /**
23243
23427
  * 线段顶点按顺序连接 (p0-p1, p1-p2, p2-p3, ...)
@@ -23320,8 +23504,8 @@ var Graphics = /*#__PURE__*/ function() {
23320
23504
  };
23321
23505
  /**
23322
23506
  * 绘制矩形边框
23323
- * @param x - 矩形左下角 X 坐标
23324
- * @param y - 矩形左下角 Y 坐标
23507
+ * @param x - 矩形左上角 X 坐标
23508
+ * @param y - 矩形左上角 Y 坐标
23325
23509
  * @param width - 矩形宽度
23326
23510
  * @param height - 矩形高度
23327
23511
  * @param color - 边框颜色,默认白色,范围 0-1
@@ -23364,8 +23548,8 @@ var Graphics = /*#__PURE__*/ function() {
23364
23548
  };
23365
23549
  /**
23366
23550
  * 绘制填充矩形
23367
- * @param x - 矩形左下角 X 坐标
23368
- * @param y - 矩形左下角 Y 坐标
23551
+ * @param x - 矩形左上角 X 坐标
23552
+ * @param y - 矩形左上角 Y 坐标
23369
23553
  * @param width - 矩形宽度
23370
23554
  * @param height - 矩形高度
23371
23555
  * @param color - 填充颜色,默认白色,范围 0-1
@@ -23391,9 +23575,9 @@ var Graphics = /*#__PURE__*/ function() {
23391
23575
  this.buildShape(this.circleShape, color);
23392
23576
  };
23393
23577
  /**
23394
- * 绘制纹理矩形(本地坐标,Y 向上,(x, y) 为左下角)
23395
- * @param x - 矩形左下角 X 坐标
23396
- * @param y - 矩形左下角 Y 坐标
23578
+ * 绘制纹理矩形(本地坐标,Y 向下,(x, y) 为左上角)
23579
+ * @param x - 矩形左上角 X 坐标
23580
+ * @param y - 矩形左上角 Y 坐标
23397
23581
  * @param width - 矩形宽度
23398
23582
  * @param height - 矩形高度
23399
23583
  * @param texture - 要采样的纹理。同纹理连续绘制会合批,纹理切换会自动 flush 当前批次
@@ -23406,14 +23590,41 @@ var Graphics = /*#__PURE__*/ function() {
23406
23590
  this.pushQuad(x, y, width, height, color, region);
23407
23591
  };
23408
23592
  /**
23409
- * 绘制文本(本地坐标,Y 向上,(x, y) 为文本左下角)。
23593
+ * Draws a nine-patch as one quad. Stretching and repetition are resolved in the fragment shader,
23594
+ * so Tile and TileFit do not expand into CPU-side geometry.
23595
+ */ _proto.drawNinePatch = function drawNinePatch(x, y, width, height, texture, options, color) {
23596
+ if (color === void 0) color = Color.WHITE;
23597
+ if (width <= 0 || height <= 0 || options.sourceWidth <= 0 || options.sourceHeight <= 0) {
23598
+ return;
23599
+ }
23600
+ this.ensureBatch("ninePatch", texture);
23601
+ var sourceU = options.sourceX / texture.width;
23602
+ var sourceV = 1 - options.sourceY / texture.height;
23603
+ var sourceUSize = options.sourceWidth / texture.width;
23604
+ var sourceVSize = options.sourceHeight / texture.height;
23605
+ var _options_horizontalMode;
23606
+ var horizontalMode = (_options_horizontalMode = options.horizontalMode) != null ? _options_horizontalMode : 0;
23607
+ var _options_verticalMode;
23608
+ var verticalMode = (_options_verticalMode = options.verticalMode) != null ? _options_verticalMode : 0;
23609
+ var _options_drawCenter;
23610
+ var drawCenter = Number((_options_drawCenter = options.drawCenter) != null ? _options_drawCenter : true);
23611
+ this.pushQuad(x, y, width, height, color, FULL_REGION);
23612
+ for(var i = 0; i < 4; i++){
23613
+ this.ninePatchDrawSourceSizes.push(width, height, options.sourceWidth, options.sourceHeight);
23614
+ this.ninePatchSourceRects.push(sourceU, sourceV, sourceUSize, sourceVSize);
23615
+ this.ninePatchMargins.push(options.marginLeft, options.marginTop, options.marginRight, options.marginBottom);
23616
+ this.ninePatchOptions.push(horizontalMode, verticalMode, drawCenter, 0);
23617
+ }
23618
+ };
23619
+ /**
23620
+ * 绘制文本(本地坐标,Y 向下,(x, y) 为文本 cell 左上角)。
23410
23621
  *
23411
23622
  * 文本走字符级 bitmap atlas(同一字体下每个字只渲染一次,任意文本组合复用 atlas);
23412
- * `color` 作为乘色与白色字形 alpha 相乘,任意颜色都不会污染 atlas。
23623
+ * `color` atlas 字形 RGBA 相乘,任意颜色都不会污染 atlas。
23413
23624
  *
23414
23625
  * 字体参数全部展开,避免调用方每帧创建临时 style 对象触发 GC
23415
- * @param x - 文本左下角 X 坐标(首字 ink 起始处,含 padding 的 quad 会向左延伸)
23416
- * @param y - 文本左下角 Y 坐标(cell 底,含底部 padding;字形 ink 在其上方 padding+ascent 处)
23626
+ * @param x - 文本左上角 X 坐标(首字 ink 起始处,含 padding 的 quad 会向左延伸)
23627
+ * @param y - 文本 cell 顶部 Y 坐标
23417
23628
  * @param text - 要绘制的文本内容,空串直接 return
23418
23629
  * @param fontSize - 字号(逻辑像素)
23419
23630
  * @param color - 乘色,默认白色,范围 0-1
@@ -23432,10 +23643,11 @@ var Graphics = /*#__PURE__*/ function() {
23432
23643
  this.ensureBatch("text", atlas.texture);
23433
23644
  var lineHeight = atlas.lineHeight;
23434
23645
  var cursorX = x;
23646
+ var characters = Array.from(text);
23435
23647
  // ensureChar 可能往 atlas canvas 写新字并打 dirty 标;实际 upload 推迟到
23436
23648
  // flushBatch 统一处理,这样一帧多次 drawText 共写同一 atlas 只 upload 一次
23437
- for(var i = 0; i < text.length; i++){
23438
- var info = atlas.ensureChar(text[i]);
23649
+ for(var i = 0; i < characters.length; i++){
23650
+ var info = atlas.ensureChar(characters[i]);
23439
23651
  if (!info) {
23440
23652
  continue;
23441
23653
  }
@@ -23457,11 +23669,35 @@ var Graphics = /*#__PURE__*/ function() {
23457
23669
  cursorX += info.advance;
23458
23670
  }
23459
23671
  };
23672
+ /** Measures text with the same glyph metrics used by {@link drawText}. */ _proto.measureText = function measureText(text, fontSize, fontFamily, fontWeight, fontStyle) {
23673
+ if (fontFamily === void 0) fontFamily = "sans-serif";
23674
+ if (fontWeight === void 0) fontWeight = "normal";
23675
+ if (fontStyle === void 0) fontStyle = "normal";
23676
+ var atlas = this.textCache.getAtlas(fontSize, fontFamily, fontWeight, fontStyle);
23677
+ var characters = Array.from(text);
23678
+ var advances = [];
23679
+ var width = 0;
23680
+ for(var _iterator = _create_for_of_iterator_helper_loose(characters), _step; !(_step = _iterator()).done;){
23681
+ var character = _step.value;
23682
+ var _atlas_ensureChar;
23683
+ var _atlas_ensureChar_advance;
23684
+ var advance = (_atlas_ensureChar_advance = (_atlas_ensureChar = atlas.ensureChar(character)) == null ? void 0 : _atlas_ensureChar.advance) != null ? _atlas_ensureChar_advance : 0;
23685
+ advances.push(advance);
23686
+ width += advance;
23687
+ }
23688
+ return {
23689
+ width: width,
23690
+ lineHeight: atlas.lineHeight,
23691
+ advances: advances
23692
+ };
23693
+ };
23460
23694
  _proto.dispose = function dispose() {
23461
23695
  this.geometry.dispose();
23696
+ this.ninePatchGeometry.dispose();
23462
23697
  this.coloredMaterial.dispose();
23463
23698
  this.texturedMaterial.dispose();
23464
23699
  this.textMaterial.dispose();
23700
+ this.ninePatchMaterial.dispose();
23465
23701
  this.textCache.dispose();
23466
23702
  };
23467
23703
  _proto.buildShape = function buildShape(shape, color) {
@@ -23469,7 +23705,7 @@ var Graphics = /*#__PURE__*/ function() {
23469
23705
  var indexOffset = this.indices.length;
23470
23706
  var vertexOffset = this.vertices.length / 2;
23471
23707
  buildPoints.length = 0;
23472
- shape.build(buildPoints);
23708
+ shape.build(buildPoints, this.getScreenScale());
23473
23709
  shape.triangulate(buildPoints, this.vertices, vertexOffset, this.indices, indexOffset);
23474
23710
  this.applyTransformAndColor(vertexOffset, this.vertices.length / 2 - vertexOffset, color);
23475
23711
  };
@@ -23479,11 +23715,19 @@ var Graphics = /*#__PURE__*/ function() {
23479
23715
  this.indices.length;
23480
23716
  var vertexOffset = this.vertices.length / 2;
23481
23717
  buildPoints.length = 0;
23482
- shape.build(buildPoints);
23718
+ shape.build(buildPoints, this.getScreenScale());
23483
23719
  this.lineStyle.width = thickness;
23484
23720
  buildLine(buildPoints, this.lineStyle, false, closed, this.vertices, 2, vertexOffset, this.indices);
23485
23721
  this.applyTransformAndColor(vertexOffset, this.vertices.length / 2 - vertexOffset, color);
23486
23722
  };
23723
+ _proto.getScreenScale = function getScreenScale() {
23724
+ var transform = this.currentTransform.elements;
23725
+ var transformScaleX = Math.hypot(transform[0], transform[1]);
23726
+ var transformScaleY = Math.hypot(transform[3], transform[4]);
23727
+ var framebufferScaleX = this.engine.canvas.width / this.logicalWidth;
23728
+ var framebufferScaleY = this.engine.canvas.height / this.logicalHeight;
23729
+ return Math.max(transformScaleX * framebufferScaleX, transformScaleY * framebufferScaleY, 1);
23730
+ };
23487
23731
  _proto.setTriangleShape = function setTriangleShape(x1, y1, x2, y2, x3, y3) {
23488
23732
  this.triangleShape.x = x1;
23489
23733
  this.triangleShape.y = y1;
@@ -23528,7 +23772,7 @@ var Graphics = /*#__PURE__*/ function() {
23528
23772
  * 在像素级亚像素精度下会暴露 1-2 像素缝隙,叠层时底层颜色透出形成可见的对角痕迹
23529
23773
  */ _proto.pushQuad = function pushQuad(x, y, width, height, color, region) {
23530
23774
  var vertexOffset = this.vertices.length / 2;
23531
- // 4 顶点(本地坐标,左下/右下/左上/右上),应用当前变换写入 vertices
23775
+ // 4 顶点(本地坐标,左上/右上/左下/右下),应用当前变换写入 vertices
23532
23776
  var corners = [
23533
23777
  [
23534
23778
  x,
@@ -23554,19 +23798,19 @@ var Graphics = /*#__PURE__*/ function() {
23554
23798
  var cornerUVs = [
23555
23799
  [
23556
23800
  u0,
23557
- v0
23801
+ v1
23558
23802
  ],
23559
23803
  [
23560
23804
  u1,
23561
- v0
23805
+ v1
23562
23806
  ],
23563
23807
  [
23564
23808
  u0,
23565
- v1
23809
+ v0
23566
23810
  ],
23567
23811
  [
23568
23812
  u1,
23569
- v1
23813
+ v0
23570
23814
  ]
23571
23815
  ];
23572
23816
  for(var i = 0; i < 4; i++){
@@ -24532,2086 +24776,6 @@ exports.FrameComponent = __decorate([
24532
24776
  // 第四列 (位移) 乘 1,无需修改
24533
24777
  }
24534
24778
 
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);
24617
- };
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);
24633
- }
24634
- function Wrapper() {
24635
- return _construct(Class, arguments, _get_prototype_of(this).constructor);
24636
- }
24637
- Wrapper.prototype = Object.create(Class.prototype, {
24638
- constructor: {
24639
- value: Wrapper,
24640
- enumerable: false,
24641
- writable: true,
24642
- configurable: true
24643
- }
24644
- });
24645
- return _set_prototype_of(Wrapper, Class);
24646
- };
24647
- return _wrap_native_super(Class);
24648
- }
24649
-
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;
24663
- }
24664
- var _proto = InputEvent.prototype;
24665
- _proto.isPressed = function isPressed() {
24666
- return this.pressed && !this.canceled;
24667
- };
24668
- _proto.isReleased = function isReleased() {
24669
- return !this.pressed && !this.canceled;
24670
- };
24671
- _proto.isCanceled = function isCanceled() {
24672
- return this.canceled;
24673
- };
24674
- _proto.isEcho = function isEcho() {
24675
- return false;
24676
- };
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;
24683
- };
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;
24701
- }
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;
24732
- }
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 = {
24887
- topLeft: [
24888
- 0,
24889
- 1,
24890
- 0,
24891
- 1
24892
- ],
24893
- topRight: [
24894
- 1,
24895
- 1,
24896
- 1,
24897
- 1
24898
- ],
24899
- bottomLeft: [
24900
- 0,
24901
- 0,
24902
- 0,
24903
- 0
24904
- ],
24905
- bottomRight: [
24906
- 1,
24907
- 0,
24908
- 1,
24909
- 0
24910
- ],
24911
- centerLeft: [
24912
- 0,
24913
- 0.5,
24914
- 0,
24915
- 0.5
24916
- ],
24917
- centerTop: [
24918
- 0.5,
24919
- 1,
24920
- 0.5,
24921
- 1
24922
- ],
24923
- centerRight: [
24924
- 1,
24925
- 0.5,
24926
- 1,
24927
- 0.5
24928
- ],
24929
- centerBottom: [
24930
- 0.5,
24931
- 0,
24932
- 0.5,
24933
- 0
24934
- ],
24935
- center: [
24936
- 0.5,
24937
- 0.5,
24938
- 0.5,
24939
- 0.5
24940
- ],
24941
- leftWide: [
24942
- 0,
24943
- 0,
24944
- 0,
24945
- 1
24946
- ],
24947
- topWide: [
24948
- 0,
24949
- 1,
24950
- 1,
24951
- 1
24952
- ],
24953
- rightWide: [
24954
- 1,
24955
- 0,
24956
- 1,
24957
- 1
24958
- ],
24959
- bottomWide: [
24960
- 0,
24961
- 0,
24962
- 1,
24963
- 0
24964
- ],
24965
- vcenterWide: [
24966
- 0.5,
24967
- 0,
24968
- 0.5,
24969
- 1
24970
- ],
24971
- hcenterWide: [
24972
- 0,
24973
- 0.5,
24974
- 1,
24975
- 0.5
24976
- ],
24977
- fullRect: [
24978
- 0,
24979
- 0,
24980
- 1,
24981
- 1
24982
- ]
24983
- };
24984
- /**
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;
25015
- }
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;
25027
- }
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());
25036
- }
25037
- this.updateLayout();
25038
- };
25039
- _proto.setSize = function setSize(width, height) {
25040
- if (this.size.x === width && this.size.y === height) {
25041
- return;
25042
- }
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();
25054
- }
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();
25072
- }
25073
- };
25074
- _proto.setAnchorMin = function setAnchorMin(x, y) {
25075
- if (this.anchorMin.x !== x || this.anchorMin.y !== y) {
25076
- this.anchorMin.set(x, y);
25077
- this.updateLayout();
25078
- }
25079
- };
25080
- _proto.setAnchorMax = function setAnchorMax(x, y) {
25081
- if (this.anchorMax.x !== x || this.anchorMax.y !== y) {
25082
- this.anchorMax.set(x, y);
25083
- this.updateLayout();
25084
- }
25085
- };
25086
- _proto.setOffsetMin = function setOffsetMin(x, y) {
25087
- if (this.offsetMin.x !== x || this.offsetMin.y !== y) {
25088
- this.offsetMin.set(x, y);
25089
- this.updateLayout();
25090
- }
25091
- };
25092
- _proto.setOffsetMax = function setOffsetMax(x, y) {
25093
- if (this.offsetMax.x !== x || this.offsetMax.y !== y) {
25094
- this.offsetMax.set(x, y);
25095
- this.updateLayout();
25096
- }
25097
- };
25098
- _proto.getRect = function getRect() {
25099
- return {
25100
- position: this.position.clone(),
25101
- size: this.size.clone()
25102
- };
25103
- };
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) {
25125
- if (keepOffsets === void 0) keepOffsets = true;
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];
25127
- if (keepOffsets) {
25128
- this.anchorMin.set(minX, minY);
25129
- this.anchorMax.set(maxX, maxY);
25130
- } else {
25131
- var rect = this.getRect();
25132
- this.anchorMin.set(minX, minY);
25133
- this.anchorMax.set(maxX, maxY);
25134
- this.computeOffsets(rect, this.getParentRect());
25135
- }
25136
- this.updateLayout();
25137
- };
25138
- _proto.setOffsetsPreset = function setOffsetsPreset(preset, margin) {
25139
- if (margin === void 0) margin = 0;
25140
- if (!this.parent) {
25141
- return;
25142
- }
25143
- var parentSize = this.parent.size;
25144
- var width = this.size.x;
25145
- var height = this.size.y;
25146
- var a = this.anchorMin;
25147
- var b = this.anchorMax;
25148
- var minX = 0, maxX = 0, minY = 0, maxY = 0;
25149
- switch(preset){
25150
- case "topLeft":
25151
- case "bottomLeft":
25152
- case "centerLeft":
25153
- case "topWide":
25154
- case "bottomWide":
25155
- case "leftWide":
25156
- case "hcenterWide":
25157
- case "fullRect":
25158
- minX = margin - a.x * parentSize.x;
25159
- maxX = margin + width - b.x * parentSize.x;
25160
- break;
25161
- case "centerTop":
25162
- case "centerBottom":
25163
- case "center":
25164
- case "vcenterWide":
25165
- minX = 0.5 * parentSize.x - width / 2 - a.x * parentSize.x;
25166
- maxX = 0.5 * parentSize.x + width / 2 - b.x * parentSize.x;
25167
- break;
25168
- default:
25169
- minX = parentSize.x - margin - width - a.x * parentSize.x;
25170
- maxX = parentSize.x - margin - b.x * parentSize.x;
25171
- break;
25172
- }
25173
- switch(preset){
25174
- case "bottomLeft":
25175
- case "bottomRight":
25176
- case "centerBottom":
25177
- case "leftWide":
25178
- case "rightWide":
25179
- case "bottomWide":
25180
- case "vcenterWide":
25181
- case "fullRect":
25182
- minY = margin - a.y * parentSize.y;
25183
- maxY = margin + height - b.y * parentSize.y;
25184
- break;
25185
- case "centerLeft":
25186
- case "centerRight":
25187
- case "center":
25188
- case "hcenterWide":
25189
- minY = 0.5 * parentSize.y - height / 2 - a.y * parentSize.y;
25190
- maxY = 0.5 * parentSize.y + height / 2 - b.y * parentSize.y;
25191
- break;
25192
- default:
25193
- minY = parentSize.y - margin - height - a.y * parentSize.y;
25194
- maxY = parentSize.y - margin - b.y * parentSize.y;
25195
- break;
25196
- }
25197
- this.offsetMin.set(minX, minY);
25198
- this.offsetMax.set(maxX, maxY);
25199
- this.updateLayout();
25200
- };
25201
- _proto.setAnchorsAndOffsetsPreset = function setAnchorsAndOffsetsPreset(preset, margin) {
25202
- if (margin === void 0) margin = 0;
25203
- this.setAnchorsPreset(preset, false);
25204
- this.setOffsetsPreset(preset, margin);
25205
- };
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;
26391
- }
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();
26403
- }
26404
- };
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);
26428
-
26429
- /**
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;
26448
- }
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;
26457
- }
26458
- };
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);
26614
-
26615
24779
  exports.CameraController = /*#__PURE__*/ function(Component) {
26616
24780
  _inherits(CameraController, Component);
26617
24781
  function CameraController(engine, props) {
@@ -26646,6 +24810,42 @@ exports.CameraController = __decorate([
26646
24810
  effectsClass(DataType.CameraController)
26647
24811
  ], exports.CameraController);
26648
24812
 
24813
+ function _get_prototype_of(o) {
24814
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
24815
+ return o.__proto__ || Object.getPrototypeOf(o);
24816
+ };
24817
+ return _get_prototype_of(o);
24818
+ }
24819
+
24820
+ function _is_native_function(fn) {
24821
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
24822
+ }
24823
+
24824
+ function _wrap_native_super(Class) {
24825
+ var _cache = typeof Map === "function" ? new Map() : undefined;
24826
+ _wrap_native_super = function _wrap_native_super(Class) {
24827
+ if (Class === null || !_is_native_function(Class)) return Class;
24828
+ if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
24829
+ if (typeof _cache !== "undefined") {
24830
+ if (_cache.has(Class)) return _cache.get(Class);
24831
+ _cache.set(Class, Wrapper);
24832
+ }
24833
+ function Wrapper() {
24834
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
24835
+ }
24836
+ Wrapper.prototype = Object.create(Class.prototype, {
24837
+ constructor: {
24838
+ value: Wrapper,
24839
+ enumerable: false,
24840
+ writable: true,
24841
+ configurable: true
24842
+ }
24843
+ });
24844
+ return _set_prototype_of(Wrapper, Class);
24845
+ };
24846
+ return _wrap_native_super(Class);
24847
+ }
24848
+
26649
24849
  var CameraVFXItemLoader = /*#__PURE__*/ function(Plugin) {
26650
24850
  _inherits(CameraVFXItemLoader, Plugin);
26651
24851
  function CameraVFXItemLoader() {
@@ -26654,6 +24854,255 @@ var CameraVFXItemLoader = /*#__PURE__*/ function(Plugin) {
26654
24854
  return CameraVFXItemLoader;
26655
24855
  }(_wrap_native_super(Plugin));
26656
24856
 
24857
+ exports.MouseButton = void 0;
24858
+ (function(MouseButton) {
24859
+ MouseButton[MouseButton["None"] = 0] = "None";
24860
+ MouseButton[MouseButton["Left"] = 1] = "Left";
24861
+ MouseButton[MouseButton["Right"] = 2] = "Right";
24862
+ MouseButton[MouseButton["Middle"] = 3] = "Middle";
24863
+ MouseButton[MouseButton["WheelUp"] = 4] = "WheelUp";
24864
+ MouseButton[MouseButton["WheelDown"] = 5] = "WheelDown";
24865
+ MouseButton[MouseButton["WheelLeft"] = 6] = "WheelLeft";
24866
+ MouseButton[MouseButton["WheelRight"] = 7] = "WheelRight";
24867
+ MouseButton[MouseButton["Xbutton1"] = 8] = "Xbutton1";
24868
+ MouseButton[MouseButton["Xbutton2"] = 9] = "Xbutton2";
24869
+ })(exports.MouseButton || (exports.MouseButton = {}));
24870
+ exports.MouseButtonMask = void 0;
24871
+ (function(MouseButtonMask) {
24872
+ MouseButtonMask[MouseButtonMask["None"] = 0] = "None";
24873
+ MouseButtonMask[MouseButtonMask["Left"] = 1] = "Left";
24874
+ MouseButtonMask[MouseButtonMask["Right"] = 2] = "Right";
24875
+ MouseButtonMask[MouseButtonMask["Middle"] = 4] = "Middle";
24876
+ MouseButtonMask[MouseButtonMask["Xbutton1"] = 128] = "Xbutton1";
24877
+ MouseButtonMask[MouseButtonMask["Xbutton2"] = 256] = "Xbutton2";
24878
+ })(exports.MouseButtonMask || (exports.MouseButtonMask = {}));
24879
+ exports.KeyLocation = void 0;
24880
+ (function(KeyLocation) {
24881
+ KeyLocation[KeyLocation["Unspecified"] = 0] = "Unspecified";
24882
+ KeyLocation[KeyLocation["Left"] = 1] = "Left";
24883
+ KeyLocation[KeyLocation["Right"] = 2] = "Right";
24884
+ })(exports.KeyLocation || (exports.KeyLocation = {}));
24885
+
24886
+ function transformPoint(transform, value) {
24887
+ var elements = transform.elements;
24888
+ return new Vector2(elements[0] * value.x + elements[3] * value.y + elements[6], elements[1] * value.x + elements[4] * value.y + elements[7]);
24889
+ }
24890
+ function transformVector(transform, value) {
24891
+ var elements = transform.elements;
24892
+ return new Vector2(elements[0] * value.x + elements[3] * value.y, elements[1] * value.x + elements[4] * value.y);
24893
+ }
24894
+ var InputEvent = /*#__PURE__*/ function() {
24895
+ function InputEvent() {
24896
+ this.device = 0;
24897
+ this.pressed = false;
24898
+ this.canceled = false;
24899
+ this._accepted = false;
24900
+ }
24901
+ var _proto = InputEvent.prototype;
24902
+ _proto.accept = function accept() {
24903
+ this._accepted = true;
24904
+ };
24905
+ _proto.clearAccepted = function clearAccepted() {
24906
+ this._accepted = false;
24907
+ };
24908
+ _proto.isAccepted = function isAccepted() {
24909
+ return this._accepted;
24910
+ };
24911
+ _proto.isPressed = function isPressed() {
24912
+ return this.pressed && !this.canceled;
24913
+ };
24914
+ _proto.isReleased = function isReleased() {
24915
+ return !this.pressed && !this.canceled;
24916
+ };
24917
+ _proto.isCanceled = function isCanceled() {
24918
+ return this.canceled;
24919
+ };
24920
+ _proto.isEcho = function isEcho() {
24921
+ return false;
24922
+ };
24923
+ _proto.xformedBy = function xformedBy(transform) {
24924
+ return this;
24925
+ };
24926
+ return InputEvent;
24927
+ }();
24928
+ InputEvent.deviceIdEmulation = -1;
24929
+ InputEvent.deviceIdInternal = -2;
24930
+ InputEvent.deviceIdKeyboard = 16;
24931
+ InputEvent.deviceIdMouse = 32;
24932
+ var InputEventWithModifiers = /*#__PURE__*/ function(InputEvent) {
24933
+ _inherits(InputEventWithModifiers, InputEvent);
24934
+ function InputEventWithModifiers() {
24935
+ var _this;
24936
+ _this = InputEvent.apply(this, arguments) || this;
24937
+ _this.commandOrControlAutoremap = false;
24938
+ _this.shiftPressed = false;
24939
+ _this.altPressed = false;
24940
+ _this.metaPressed = false;
24941
+ _this.ctrlPressed = false;
24942
+ return _this;
24943
+ }
24944
+ var _proto = InputEventWithModifiers.prototype;
24945
+ _proto.copyModifiersTo = function copyModifiersTo(event) {
24946
+ event.device = this.device;
24947
+ event.pressed = this.pressed;
24948
+ event.canceled = this.canceled;
24949
+ event.commandOrControlAutoremap = this.commandOrControlAutoremap;
24950
+ event.shiftPressed = this.shiftPressed;
24951
+ event.altPressed = this.altPressed;
24952
+ event.metaPressed = this.metaPressed;
24953
+ event.ctrlPressed = this.ctrlPressed;
24954
+ };
24955
+ return InputEventWithModifiers;
24956
+ }(_wrap_native_super(InputEvent));
24957
+ var InputEventKey = /*#__PURE__*/ function(InputEventWithModifiers) {
24958
+ _inherits(InputEventKey, InputEventWithModifiers);
24959
+ function InputEventKey() {
24960
+ var _this;
24961
+ _this = InputEventWithModifiers.apply(this, arguments) || this;
24962
+ _this.keycode = "";
24963
+ _this.physicalKeycode = "";
24964
+ _this.keyLabel = "";
24965
+ _this.unicode = 0;
24966
+ _this.location = exports.KeyLocation.Unspecified;
24967
+ _this.echo = false;
24968
+ return _this;
24969
+ }
24970
+ var _proto = InputEventKey.prototype;
24971
+ _proto.isEcho = function isEcho() {
24972
+ return this.echo;
24973
+ };
24974
+ return InputEventKey;
24975
+ }(InputEventWithModifiers);
24976
+ var InputEventMouse = /*#__PURE__*/ function(InputEventWithModifiers) {
24977
+ _inherits(InputEventMouse, InputEventWithModifiers);
24978
+ function InputEventMouse() {
24979
+ var _this;
24980
+ _this = InputEventWithModifiers.apply(this, arguments) || this;
24981
+ _this.buttonMask = exports.MouseButtonMask.None;
24982
+ _this.position = new Vector2();
24983
+ _this.globalPosition = new Vector2();
24984
+ return _this;
24985
+ }
24986
+ var _proto = InputEventMouse.prototype;
24987
+ _proto.copyMouseTo = function copyMouseTo(event) {
24988
+ this.copyModifiersTo(event);
24989
+ event.buttonMask = this.buttonMask;
24990
+ event.position.copyFrom(this.position);
24991
+ event.globalPosition.copyFrom(this.globalPosition);
24992
+ };
24993
+ return InputEventMouse;
24994
+ }(InputEventWithModifiers);
24995
+ var InputEventMouseButton = /*#__PURE__*/ function(InputEventMouse) {
24996
+ _inherits(InputEventMouseButton, InputEventMouse);
24997
+ function InputEventMouseButton() {
24998
+ var _this;
24999
+ _this = InputEventMouse.apply(this, arguments) || this;
25000
+ _this.factor = 1;
25001
+ _this.buttonIndex = exports.MouseButton.None;
25002
+ _this.doubleClick = false;
25003
+ return _this;
25004
+ }
25005
+ var _proto = InputEventMouseButton.prototype;
25006
+ _proto.xformedBy = function xformedBy(transform) {
25007
+ var event = new InputEventMouseButton();
25008
+ this.copyMouseTo(event);
25009
+ event.position.copyFrom(transformPoint(transform, this.position));
25010
+ event.factor = this.factor;
25011
+ event.buttonIndex = this.buttonIndex;
25012
+ event.doubleClick = this.doubleClick;
25013
+ return event;
25014
+ };
25015
+ return InputEventMouseButton;
25016
+ }(InputEventMouse);
25017
+ var InputEventMouseMotion = /*#__PURE__*/ function(InputEventMouse) {
25018
+ _inherits(InputEventMouseMotion, InputEventMouse);
25019
+ function InputEventMouseMotion() {
25020
+ var _this;
25021
+ _this = InputEventMouse.apply(this, arguments) || this;
25022
+ _this.tilt = new Vector2();
25023
+ _this.pressure = 0;
25024
+ _this.relative = new Vector2();
25025
+ _this.screenRelative = new Vector2();
25026
+ _this.velocity = new Vector2();
25027
+ _this.screenVelocity = new Vector2();
25028
+ _this.penInverted = false;
25029
+ return _this;
25030
+ }
25031
+ var _proto = InputEventMouseMotion.prototype;
25032
+ _proto.xformedBy = function xformedBy(transform) {
25033
+ var event = new InputEventMouseMotion();
25034
+ this.copyMouseTo(event);
25035
+ event.position.copyFrom(transformPoint(transform, this.position));
25036
+ event.tilt.copyFrom(this.tilt);
25037
+ event.pressure = this.pressure;
25038
+ event.relative.copyFrom(transformVector(transform, this.relative));
25039
+ event.screenRelative.copyFrom(this.screenRelative);
25040
+ event.velocity.copyFrom(transformVector(transform, this.velocity));
25041
+ event.screenVelocity.copyFrom(this.screenVelocity);
25042
+ event.penInverted = this.penInverted;
25043
+ return event;
25044
+ };
25045
+ return InputEventMouseMotion;
25046
+ }(InputEventMouse);
25047
+ var InputEventScreenTouch = /*#__PURE__*/ function(InputEvent) {
25048
+ _inherits(InputEventScreenTouch, InputEvent);
25049
+ function InputEventScreenTouch() {
25050
+ var _this;
25051
+ _this = InputEvent.apply(this, arguments) || this;
25052
+ _this.index = 0;
25053
+ _this.position = new Vector2();
25054
+ _this.doubleTap = false;
25055
+ return _this;
25056
+ }
25057
+ var _proto = InputEventScreenTouch.prototype;
25058
+ _proto.xformedBy = function xformedBy(transform) {
25059
+ var event = new InputEventScreenTouch();
25060
+ event.device = this.device;
25061
+ event.pressed = this.pressed;
25062
+ event.canceled = this.canceled;
25063
+ event.index = this.index;
25064
+ event.position.copyFrom(transformPoint(transform, this.position));
25065
+ event.doubleTap = this.doubleTap;
25066
+ return event;
25067
+ };
25068
+ return InputEventScreenTouch;
25069
+ }(_wrap_native_super(InputEvent));
25070
+ var InputEventScreenDrag = /*#__PURE__*/ function(InputEvent) {
25071
+ _inherits(InputEventScreenDrag, InputEvent);
25072
+ function InputEventScreenDrag() {
25073
+ var _this;
25074
+ _this = InputEvent.apply(this, arguments) || this;
25075
+ _this.index = 0;
25076
+ _this.position = new Vector2();
25077
+ _this.relative = new Vector2();
25078
+ _this.screenRelative = new Vector2();
25079
+ _this.velocity = new Vector2();
25080
+ _this.screenVelocity = new Vector2();
25081
+ _this.pressure = 0;
25082
+ _this.tilt = new Vector2();
25083
+ _this.penInverted = false;
25084
+ return _this;
25085
+ }
25086
+ var _proto = InputEventScreenDrag.prototype;
25087
+ _proto.xformedBy = function xformedBy(transform) {
25088
+ var event = new InputEventScreenDrag();
25089
+ event.device = this.device;
25090
+ event.pressed = this.pressed;
25091
+ event.canceled = this.canceled;
25092
+ event.index = this.index;
25093
+ event.position.copyFrom(transformPoint(transform, this.position));
25094
+ event.relative.copyFrom(transformVector(transform, this.relative));
25095
+ event.screenRelative.copyFrom(this.screenRelative);
25096
+ event.velocity.copyFrom(transformVector(transform, this.velocity));
25097
+ event.screenVelocity.copyFrom(this.screenVelocity);
25098
+ event.pressure = this.pressure;
25099
+ event.tilt.copyFrom(this.tilt);
25100
+ event.penInverted = this.penInverted;
25101
+ return event;
25102
+ };
25103
+ return InputEventScreenDrag;
25104
+ }(_wrap_native_super(InputEvent));
25105
+
26657
25106
  var EVENT_TYPE_CLICK = "click";
26658
25107
  var EVENT_TYPE_TOUCH_START = "touchstart";
26659
25108
  var EVENT_TYPE_TOUCH_MOVE = "touchmove";
@@ -26664,49 +25113,52 @@ exports.PointerEventType = void 0;
26664
25113
  PointerEventType[PointerEventType["PointerUp"] = 1] = "PointerUp";
26665
25114
  PointerEventType[PointerEventType["PointerMove"] = 2] = "PointerMove";
26666
25115
  })(exports.PointerEventType || (exports.PointerEventType = {}));
26667
- var EventSystem = /*#__PURE__*/ function() {
25116
+ var EventSystem = /*#__PURE__*/ function(EventEmitter) {
25117
+ _inherits(EventSystem, EventEmitter);
26668
25118
  function EventSystem(engine, allowPropagation) {
26669
- var _this = this;
26670
25119
  if (allowPropagation === void 0) allowPropagation = false;
26671
- this.engine = engine;
26672
- this.allowPropagation = allowPropagation;
26673
- this.skipPointerMovePicking = true;
26674
- this.emulateMouseFromTouch = true;
26675
- this.emulateTouchFromMouse = false;
26676
- this._enabled = true;
26677
- this.handlers = {};
26678
- this.nativeHandlers = [];
26679
- this.target = null;
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) {
25120
+ var _this;
25121
+ _this = EventEmitter.call(this) || this;
25122
+ _this.engine = engine;
25123
+ _this.allowPropagation = allowPropagation;
25124
+ _this.skipPointerMovePicking = true;
25125
+ _this.emulateMouseFromTouch = true;
25126
+ _this.emulateTouchFromMouse = false;
25127
+ _this._enabled = true;
25128
+ _this.handlers = {};
25129
+ _this.nativeHandlers = [];
25130
+ _this.target = null;
25131
+ _this.mouseState = null;
25132
+ _this.mouseButtonMask = exports.MouseButtonMask.None;
25133
+ _this.touchStates = new Map();
25134
+ _this.mouseFromTouchIndex = null;
25135
+ _this.touchFromMousePressed = false;
25136
+ _this.addedTabIndex = false;
25137
+ _this.addedOutlineStyle = false;
25138
+ _this.onNativeWheel = function(event) {
26687
25139
  if (!_this.enabled || !_this.target) {
26688
25140
  return;
26689
25141
  }
26690
25142
  var position = _this.getCanvasPosition(event.clientX, event.clientY);
26691
25143
  var handled = false;
26692
25144
  if (event.deltaY !== 0) {
26693
- handled = _this.pushWheelButton(event.deltaY < 0 ? exports.MouseButton.WheelUp : exports.MouseButton.WheelDown, Math.abs(event.deltaY), position, event) || handled;
25145
+ handled = _this.pushWheelButton(event.deltaY < 0 ? exports.MouseButton.WheelUp : exports.MouseButton.WheelDown, normalizeWheelFactor(event.deltaY, event.deltaMode), position, event) || handled;
26694
25146
  }
26695
25147
  if (event.deltaX !== 0) {
26696
- handled = _this.pushWheelButton(event.deltaX < 0 ? exports.MouseButton.WheelLeft : exports.MouseButton.WheelRight, Math.abs(event.deltaX), position, event) || handled;
25148
+ handled = _this.pushWheelButton(event.deltaX < 0 ? exports.MouseButton.WheelLeft : exports.MouseButton.WheelRight, normalizeWheelFactor(event.deltaX, event.deltaMode), position, event) || handled;
26697
25149
  }
26698
25150
  _this.consumeNativeEvent(event, handled);
26699
25151
  };
26700
- this.onNativeKeyDown = function(event) {
25152
+ _this.onNativeKeyDown = function(event) {
26701
25153
  _this.handleNativeKey(event, true);
26702
25154
  };
26703
- this.onNativeKeyUp = function(event) {
25155
+ _this.onNativeKeyUp = function(event) {
26704
25156
  _this.handleNativeKey(event, false);
26705
25157
  };
26706
- this.onNativeMouseDown = function(event) {
25158
+ _this.onNativeMouseDown = function(event) {
26707
25159
  _this.handleNativeMouseDown(event);
26708
25160
  };
26709
- this.onNativeMouseMove = function(event) {
25161
+ _this.onNativeMouseMove = function(event) {
26710
25162
  var _state;
26711
25163
  if (!_this.enabled || !_this.target) {
26712
25164
  return;
@@ -26718,18 +25170,22 @@ var EventSystem = /*#__PURE__*/ function() {
26718
25170
  var relative = new Vector2(position.x - state.last.x, position.y - state.last.y);
26719
25171
  var velocity = _this.getVelocity(state, position);
26720
25172
  var handled = _this.pushNativeMouseMotion(event, position, relative, velocity);
26721
- (_state = state).controlHandled || (_state.controlHandled = handled);
26722
- if (!handled && (!state.pressed || !state.controlHandled)) {
25173
+ (_state = state).inputHandled || (_state.inputHandled = handled);
25174
+ if (!handled && (!state.pressed || !state.inputHandled)) {
26723
25175
  var pointerEvent = _this.createPointerEvent(event, position, state, velocity);
26724
25176
  _this.dispatchEvent(EVENT_TYPE_TOUCH_MOVE, pointerEvent);
26725
25177
  }
26726
25178
  _this.updatePointerState(state, position);
26727
25179
  _this.consumeNativeEvent(event, handled);
26728
25180
  };
26729
- this.onNativeMouseUp = function(event) {
25181
+ _this.onNativeMouseUp = function(event) {
26730
25182
  if (!_this.enabled || !_this.target) {
26731
25183
  return;
26732
25184
  }
25185
+ // Keep the canonical mask in sync even when mouseState already ended on a
25186
+ // previous button release. The target and Window listeners may see the
25187
+ // same mouseup, but clearing a bit twice is intentionally idempotent.
25188
+ _this.setMouseButtonPressed(event.button, false);
26733
25189
  var position = _this.getCanvasPosition(event.clientX, event.clientY);
26734
25190
  var existingState = _this.mouseState;
26735
25191
  if (!(existingState == null ? void 0 : existingState.pressed)) {
@@ -26738,16 +25194,16 @@ var EventSystem = /*#__PURE__*/ function() {
26738
25194
  var state = existingState;
26739
25195
  var handled = _this.pushNativeMouseButton(event, position, false);
26740
25196
  var pointerEvent = _this.createPointerEvent(event, position, state);
26741
- if (!state.controlHandled && !handled && _this.isClick(state, position)) {
25197
+ if (!state.inputHandled && !handled && _this.isClick(state, position)) {
26742
25198
  _this.dispatchEvent(EVENT_TYPE_CLICK, pointerEvent);
26743
25199
  }
26744
- if (!handled && !state.controlHandled) {
25200
+ if (!handled && !state.inputHandled) {
26745
25201
  _this.dispatchEvent(EVENT_TYPE_TOUCH_END, pointerEvent);
26746
25202
  }
26747
25203
  _this.mouseState = null;
26748
- _this.consumeNativeEvent(event, handled || state.controlHandled || !_this.allowPropagation);
25204
+ _this.consumeNativeEvent(event, handled || state.inputHandled || !_this.allowPropagation);
26749
25205
  };
26750
- this.onNativeTouchStart = function(event) {
25206
+ _this.onNativeTouchStart = function(event) {
26751
25207
  if (!_this.enabled) {
26752
25208
  return;
26753
25209
  }
@@ -26759,7 +25215,7 @@ var EventSystem = /*#__PURE__*/ function() {
26759
25215
  _this.touchStates.set(touch.identifier, state);
26760
25216
  state.pressed = true;
26761
25217
  var handled = _this.pushNativeScreenTouch(touch.identifier, position, true, false, false);
26762
- state.controlHandled = handled;
25218
+ state.inputHandled = handled;
26763
25219
  if (!handled) {
26764
25220
  var pointerEvent = _this.createPointerEvent(event, position, state);
26765
25221
  _this.dispatchEvent(EVENT_TYPE_TOUCH_START, pointerEvent);
@@ -26768,7 +25224,7 @@ var EventSystem = /*#__PURE__*/ function() {
26768
25224
  }
26769
25225
  _this.preventTouchDefaults(event);
26770
25226
  };
26771
- this.onNativeTouchMove = function(event) {
25227
+ _this.onNativeTouchMove = function(event) {
26772
25228
  if (!_this.enabled) {
26773
25229
  return;
26774
25230
  }
@@ -26782,8 +25238,8 @@ var EventSystem = /*#__PURE__*/ function() {
26782
25238
  var relative = new Vector2(position.x - state.last.x, position.y - state.last.y);
26783
25239
  var velocity = _this.getVelocity(state, position);
26784
25240
  var handled = _this.pushNativeScreenDrag(touch.identifier, position, relative, velocity);
26785
- (_state = state).controlHandled || (_state.controlHandled = handled);
26786
- if (!handled && !state.controlHandled) {
25241
+ (_state = state).inputHandled || (_state.inputHandled = handled);
25242
+ if (!handled && !state.inputHandled) {
26787
25243
  var pointerEvent = _this.createPointerEvent(event, position, state, velocity);
26788
25244
  _this.dispatchEvent(EVENT_TYPE_TOUCH_MOVE, pointerEvent);
26789
25245
  }
@@ -26792,24 +25248,26 @@ var EventSystem = /*#__PURE__*/ function() {
26792
25248
  }
26793
25249
  _this.preventTouchDefaults(event);
26794
25250
  };
26795
- this.onNativeTouchEnd = function(event) {
25251
+ _this.onNativeTouchEnd = function(event) {
26796
25252
  _this.handleNativeTouchEnd(event, false);
26797
25253
  };
26798
- this.onNativeTouchCancel = function(event) {
25254
+ _this.onNativeTouchCancel = function(event) {
26799
25255
  _this.handleNativeTouchEnd(event, true);
26800
25256
  };
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
- }
25257
+ _this.onCanvasFocus = function() {
25258
+ _this.emit("canvasFocus");
25259
+ };
25260
+ _this.onCanvasBlur = function() {
25261
+ _this.emit("canvasBlur");
26809
25262
  };
25263
+ return _this;
26810
25264
  }
26811
25265
  var _proto = EventSystem.prototype;
26812
- _proto.bindListeners = function bindListeners(target) {
25266
+ /**
25267
+ * Rebinds native input listeners to a canvas.
25268
+ *
25269
+ * Rebind or unbind only while there are no active key, mouse, touch, or drag sessions.
25270
+ */ _proto.bindListeners = function bindListeners(target) {
26813
25271
  this.unbindListeners();
26814
25272
  this.target = target;
26815
25273
  if (!target || typeof window === "undefined") {
@@ -26846,7 +25304,8 @@ var EventSystem = /*#__PURE__*/ function() {
26846
25304
  });
26847
25305
  this.addNativeHandler(target, "keydown", this.onNativeKeyDown);
26848
25306
  this.addNativeHandler(target, "keyup", this.onNativeKeyUp);
26849
- this.addNativeHandler(window, "blur", this.onWindowBlur);
25307
+ this.addNativeHandler(target, "focus", this.onCanvasFocus);
25308
+ this.addNativeHandler(target, "blur", this.onCanvasBlur);
26850
25309
  };
26851
25310
  _proto.dispatchEvent = function dispatchEvent(type, event) {
26852
25311
  var handlers = this.handlers[type];
@@ -26880,11 +25339,7 @@ var EventSystem = /*#__PURE__*/ function() {
26880
25339
  }
26881
25340
  };
26882
25341
  _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;
25342
+ this.resetInputState();
26888
25343
  this.handlers = {};
26889
25344
  this.unbindListeners();
26890
25345
  this.target = null;
@@ -26893,13 +25348,14 @@ var EventSystem = /*#__PURE__*/ function() {
26893
25348
  if (!this.enabled || !this.target) {
26894
25349
  return;
26895
25350
  }
26896
- this.focusTarget();
25351
+ this.setMouseButtonPressed(event.button, true);
26897
25352
  var position = this.getCanvasPosition(event.clientX, event.clientY);
25353
+ this.focusTarget();
26898
25354
  var state = this.createPointerState(position);
26899
25355
  this.mouseState = state;
26900
25356
  state.pressed = true;
26901
25357
  var handled = this.pushNativeMouseButton(event, position, true);
26902
- state.controlHandled = handled;
25358
+ state.inputHandled = handled;
26903
25359
  if (!handled) {
26904
25360
  var pointerEvent = this.createPointerEvent(event, position, state);
26905
25361
  this.dispatchEvent(EVENT_TYPE_TOUCH_START, pointerEvent);
@@ -26923,8 +25379,7 @@ var EventSystem = /*#__PURE__*/ function() {
26923
25379
  input.altPressed = event.altKey;
26924
25380
  input.metaPressed = event.metaKey;
26925
25381
  input.ctrlPressed = event.ctrlKey;
26926
- this.engine.windowRoot.pushInput(input);
26927
- this.consumeNativeEvent(event, this.engine.windowRoot.isInputHandled());
25382
+ this.consumeNativeEvent(event, this.pushInput(input));
26928
25383
  };
26929
25384
  _proto.handleNativeTouchEnd = function handleNativeTouchEnd(event, canceled) {
26930
25385
  if (!this.enabled) {
@@ -26939,14 +25394,14 @@ var EventSystem = /*#__PURE__*/ function() {
26939
25394
  }
26940
25395
  var handled = this.pushNativeScreenTouch(touch.identifier, position, false, canceled, false);
26941
25396
  var pointerEvent = this.createPointerEvent(event, position, state);
26942
- if (!canceled && !state.controlHandled && !handled && this.isClick(state, position)) {
25397
+ if (!canceled && !state.inputHandled && !handled && this.isClick(state, position)) {
26943
25398
  this.dispatchEvent(EVENT_TYPE_CLICK, pointerEvent);
26944
25399
  }
26945
- if (!handled && !canceled && !state.controlHandled) {
25400
+ if (!handled && !canceled && !state.inputHandled) {
26946
25401
  this.dispatchEvent(EVENT_TYPE_TOUCH_END, pointerEvent);
26947
25402
  }
26948
25403
  this.touchStates.delete(touch.identifier);
26949
- this.consumeNativeEvent(event, handled || state.controlHandled || !this.allowPropagation);
25404
+ this.consumeNativeEvent(event, handled || state.inputHandled || !this.allowPropagation);
26950
25405
  }
26951
25406
  this.preventTouchDefaults(event);
26952
25407
  };
@@ -26966,7 +25421,7 @@ var EventSystem = /*#__PURE__*/ function() {
26966
25421
  };
26967
25422
  _proto.pushNativeMouseMotion = function pushNativeMouseMotion(event, position, relative, velocity) {
26968
25423
  var handled = false;
26969
- if (this.touchFromMousePressed && (event.buttons & 1) !== 0) {
25424
+ if (this.touchFromMousePressed && (this.mouseButtonMask & exports.MouseButtonMask.Left) !== 0) {
26970
25425
  handled = this.pushScreenDrag(0, position, relative, velocity, InputEvent.deviceIdEmulation);
26971
25426
  }
26972
25427
  return this.pushMouseMotion(event, position, relative, velocity) || handled;
@@ -27003,8 +25458,7 @@ var EventSystem = /*#__PURE__*/ function() {
27003
25458
  input.pressed = pressed;
27004
25459
  input.canceled = canceled;
27005
25460
  input.doubleClick = doubleClick;
27006
- this.engine.windowRoot.pushInput(input);
27007
- return this.engine.windowRoot.isInputHandled();
25461
+ return this.pushInput(input);
27008
25462
  };
27009
25463
  _proto.pushEmulatedMouseMotion = function pushEmulatedMouseMotion(position, relative, velocity) {
27010
25464
  var input = new InputEventMouseMotion();
@@ -27017,42 +25471,42 @@ var EventSystem = /*#__PURE__*/ function() {
27017
25471
  input.screenRelative.copyFrom(relative);
27018
25472
  input.velocity.copyFrom(velocity);
27019
25473
  input.screenVelocity.copyFrom(velocity);
27020
- this.engine.windowRoot.pushInput(input);
27021
- return this.engine.windowRoot.isInputHandled();
25474
+ return this.pushInput(input);
27022
25475
  };
27023
25476
  _proto.pushMouseButton = function pushMouseButton(event, position, pressed) {
27024
25477
  var input = new InputEventMouseButton();
27025
25478
  this.copyMouseFields(input, event, position);
27026
25479
  input.device = InputEvent.deviceIdMouse;
27027
25480
  input.buttonIndex = getMouseButton(event.button);
27028
- input.buttonMask = getMouseButtonMask(event.buttons);
25481
+ input.buttonMask = this.mouseButtonMask;
25482
+ input.pressed = pressed;
25483
+ input.doubleClick = event.detail > 1;
25484
+ return this.pushInput(input);
25485
+ };
25486
+ _proto.setMouseButtonPressed = function setMouseButtonPressed(button, pressed) {
25487
+ var buttonBit = getMouseButtonBit(getMouseButton(button));
27029
25488
  if (pressed) {
27030
- input.buttonMask |= getMouseButtonBit(input.buttonIndex);
25489
+ this.mouseButtonMask |= buttonBit;
27031
25490
  } else {
27032
- input.buttonMask &= ~getMouseButtonBit(input.buttonIndex);
25491
+ this.mouseButtonMask &= ~buttonBit;
27033
25492
  }
27034
- input.pressed = pressed;
27035
- input.doubleClick = event.detail > 1;
27036
- this.engine.windowRoot.pushInput(input);
27037
- return this.engine.windowRoot.isInputHandled();
27038
25493
  };
27039
25494
  _proto.pushWheelButton = function pushWheelButton(button, factor, position, event) {
27040
25495
  var input = new InputEventMouseButton();
27041
25496
  this.copyMouseFields(input, event, position);
27042
25497
  input.device = InputEvent.deviceIdMouse;
27043
25498
  input.buttonIndex = button;
27044
- input.buttonMask = getMouseButtonMask(event.buttons);
25499
+ input.buttonMask = this.mouseButtonMask;
27045
25500
  input.factor = factor;
27046
25501
  input.pressed = true;
27047
- this.engine.windowRoot.pushInput(input);
27048
- return this.engine.windowRoot.isInputHandled();
25502
+ return this.pushInput(input);
27049
25503
  };
27050
25504
  _proto.pushMouseMotion = function pushMouseMotion(event, position, relative, velocity) {
27051
25505
  var input = new InputEventMouseMotion();
27052
25506
  this.copyMouseFields(input, event, position);
27053
25507
  input.device = InputEvent.deviceIdMouse;
27054
- input.buttonMask = getMouseButtonMask(event.buttons);
27055
- input.pressed = event.buttons !== 0;
25508
+ input.buttonMask = this.mouseButtonMask;
25509
+ input.pressed = this.mouseButtonMask !== exports.MouseButtonMask.None;
27056
25510
  input.relative.copyFrom(relative);
27057
25511
  input.screenRelative.copyFrom(relative);
27058
25512
  input.velocity.copyFrom(velocity);
@@ -27061,8 +25515,7 @@ var EventSystem = /*#__PURE__*/ function() {
27061
25515
  input.pressure = event.pressure;
27062
25516
  input.tilt.set(event.tiltX, event.tiltY);
27063
25517
  }
27064
- this.engine.windowRoot.pushInput(input);
27065
- return this.engine.windowRoot.isInputHandled();
25518
+ return this.pushInput(input);
27066
25519
  };
27067
25520
  _proto.pushScreenTouch = function pushScreenTouch(index, position, pressed, canceled, doubleTap, device) {
27068
25521
  var input = new InputEventScreenTouch();
@@ -27072,8 +25525,7 @@ var EventSystem = /*#__PURE__*/ function() {
27072
25525
  input.pressed = pressed;
27073
25526
  input.canceled = canceled;
27074
25527
  input.doubleTap = doubleTap;
27075
- this.engine.windowRoot.pushInput(input);
27076
- return this.engine.windowRoot.isInputHandled();
25528
+ return this.pushInput(input);
27077
25529
  };
27078
25530
  _proto.pushScreenDrag = function pushScreenDrag(index, position, relative, velocity, device) {
27079
25531
  var input = new InputEventScreenDrag();
@@ -27085,8 +25537,7 @@ var EventSystem = /*#__PURE__*/ function() {
27085
25537
  input.velocity.copyFrom(velocity);
27086
25538
  input.screenVelocity.copyFrom(velocity);
27087
25539
  input.pressed = true;
27088
- this.engine.windowRoot.pushInput(input);
27089
- return this.engine.windowRoot.isInputHandled();
25540
+ return this.pushInput(input);
27090
25541
  };
27091
25542
  _proto.copyMouseFields = function copyMouseFields(input, event, position) {
27092
25543
  input.position.copyFrom(position);
@@ -27161,7 +25612,7 @@ var EventSystem = /*#__PURE__*/ function() {
27161
25612
  start: position.clone(),
27162
25613
  last: position.clone(),
27163
25614
  lastTime: performance.now(),
27164
- controlHandled: false,
25615
+ inputHandled: false,
27165
25616
  pressed: false
27166
25617
  };
27167
25618
  return state;
@@ -27186,12 +25637,14 @@ var EventSystem = /*#__PURE__*/ function() {
27186
25637
  var _target_width, _target_height;
27187
25638
  return {
27188
25639
  x: position.x / cssWidth * 2 - 1,
27189
- y: position.y / cssHeight * 2 - 1,
25640
+ // Legacy composition picking uses bottom-left, Y-up NDC even though
25641
+ // standardized input follows the DOM convention of top-left, Y-down pixels.
25642
+ y: 1 - position.y / cssHeight * 2,
27190
25643
  vx: velocity.x / cssWidth * 2,
27191
- vy: velocity.y / cssHeight * 2,
25644
+ vy: -velocity.y / cssHeight * 2,
27192
25645
  ts: performance.now(),
27193
25646
  dx: (position.x - state.start.x) / cssWidth * 2,
27194
- dy: (position.y - state.start.y) / cssHeight * 2,
25647
+ dy: -(position.y - state.start.y) / cssHeight * 2,
27195
25648
  width: (_target_width = target == null ? void 0 : target.width) != null ? _target_width : 0,
27196
25649
  height: (_target_height = target == null ? void 0 : target.height) != null ? _target_height : 0,
27197
25650
  origin: origin
@@ -27203,7 +25656,7 @@ var EventSystem = /*#__PURE__*/ function() {
27203
25656
  if (!rect) {
27204
25657
  return new Vector2();
27205
25658
  }
27206
- return new Vector2(clientX - rect.left, rect.bottom - clientY);
25659
+ return new Vector2(clientX - rect.left, clientY - rect.top);
27207
25660
  };
27208
25661
  _proto.consumeNativeEvent = function consumeNativeEvent(event, handled) {
27209
25662
  if (handled && !this.allowPropagation) {
@@ -27213,15 +25666,26 @@ var EventSystem = /*#__PURE__*/ function() {
27213
25666
  event.stopPropagation();
27214
25667
  }
27215
25668
  };
25669
+ _proto.pushInput = function pushInput(input) {
25670
+ input.clearAccepted();
25671
+ this.emit("input", input);
25672
+ return input.isAccepted();
25673
+ };
27216
25674
  _proto.preventTouchDefaults = function preventTouchDefaults(event) {
27217
25675
  if (event.cancelable) {
27218
25676
  event.preventDefault();
27219
25677
  }
27220
25678
  };
27221
25679
  _proto.focusTarget = function focusTarget() {
27222
- if (this.target && document.activeElement !== this.target) {
27223
- this.target.focus();
27224
- }
25680
+ var _this_target;
25681
+ (_this_target = this.target) == null ? void 0 : _this_target.focus();
25682
+ };
25683
+ _proto.resetInputState = function resetInputState() {
25684
+ this.mouseState = null;
25685
+ this.mouseButtonMask = exports.MouseButtonMask.None;
25686
+ this.touchStates.clear();
25687
+ this.mouseFromTouchIndex = null;
25688
+ this.touchFromMousePressed = false;
27225
25689
  };
27226
25690
  _proto.addNativeHandler = function addNativeHandler(target, name, handler, options) {
27227
25691
  target.addEventListener(name, handler, options);
@@ -27253,23 +25717,20 @@ var EventSystem = /*#__PURE__*/ function() {
27253
25717
  get: function get() {
27254
25718
  return this._enabled;
27255
25719
  },
27256
- set: function set(value) {
25720
+ set: /**
25721
+ * Enables native input processing.
25722
+ *
25723
+ * Change this only while there are no active key, mouse, touch, or drag sessions.
25724
+ */ function set(value) {
27257
25725
  if (this._enabled === value) {
27258
25726
  return;
27259
25727
  }
27260
25728
  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
25729
  }
27269
25730
  }
27270
25731
  ]);
27271
25732
  return EventSystem;
27272
- }();
25733
+ }(EventEmitter);
27273
25734
  function getKeyLocation(location) {
27274
25735
  if (location === 1) {
27275
25736
  return exports.KeyLocation.Left;
@@ -27300,25 +25761,6 @@ function getMouseButton(button) {
27300
25761
  return exports.MouseButton.None;
27301
25762
  }
27302
25763
  }
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
25764
  function getMouseButtonBit(button) {
27323
25765
  switch(button){
27324
25766
  case exports.MouseButton.Left:
@@ -27335,6 +25777,16 @@ function getMouseButtonBit(button) {
27335
25777
  return exports.MouseButtonMask.None;
27336
25778
  }
27337
25779
  }
25780
+ function normalizeWheelFactor(delta, mode) {
25781
+ var magnitude = Math.abs(delta);
25782
+ if (mode === 1) {
25783
+ return magnitude / 3;
25784
+ }
25785
+ if (mode === 2) {
25786
+ return magnitude;
25787
+ }
25788
+ return magnitude / 100;
25789
+ }
27338
25790
 
27339
25791
  var InteractLoader = /*#__PURE__*/ function(Plugin) {
27340
25792
  _inherits(InteractLoader, Plugin);
@@ -29354,6 +27806,11 @@ exports.SpritePropertyTrack = __decorate([
29354
27806
  effectsClass("SpritePropertyTrack")
29355
27807
  ], exports.SpritePropertyTrack);
29356
27808
 
27809
+ function _assert_this_initialized(self) {
27810
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
27811
+ return self;
27812
+ }
27813
+
29357
27814
  var Cone = /*#__PURE__*/ function() {
29358
27815
  function Cone(props) {
29359
27816
  var _this = this;
@@ -39358,7 +37815,7 @@ function getStandardSpriteContent(sprite, transform) {
39358
37815
  return ret;
39359
37816
  }
39360
37817
 
39361
- var version$2 = "2.10.0-alpha.3";
37818
+ var version$2 = "2.10.0-alpha.5";
39362
37819
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
39363
37820
  var standardVersion = /^(\d+)\.(\d+)$/;
39364
37821
  var reverseParticle = false;
@@ -41354,9 +39811,11 @@ var PreRenderTickData = /*#__PURE__*/ function(TickData) {
41354
39811
  // Instantiate composition rootItem
41355
39812
  _this.sceneRoot = new exports.VFXItem(_this.engine);
41356
39813
  _this.sceneRoot.setParent(_this.root);
41357
- _this.uiCanvas = _this.sceneRoot.addComponent(UICanvas);
41358
39814
  if (sourceContent) {
41359
39815
  _this.sceneRoot.setInstanceId(sourceContent.id);
39816
+ }
39817
+ PluginSystem.notifyCompositionCreating(_assert_this_initialized(_this), scene);
39818
+ if (sourceContent) {
41360
39819
  _this.sceneRoot.instantiatePreComposition(sourceContent, false);
41361
39820
  }
41362
39821
  // 在 instantiatePreComposition 后设置 rootItem 的 name,避免 name 被覆盖
@@ -41925,9 +40384,6 @@ var PreRenderTickData = /*#__PURE__*/ function(TickData) {
41925
40384
  },
41926
40385
  set: function set(value) {
41927
40386
  this._renderOrder = value;
41928
- if (this.uiCanvas) {
41929
- this.uiCanvas.order = value;
41930
- }
41931
40387
  }
41932
40388
  },
41933
40389
  {
@@ -41940,9 +40396,6 @@ var PreRenderTickData = /*#__PURE__*/ function(TickData) {
41940
40396
  },
41941
40397
  set: function set(value) {
41942
40398
  this._interactive = !!value;
41943
- if (this.uiCanvas) {
41944
- this.uiCanvas.receivesEvents = this._interactive;
41945
- }
41946
40399
  }
41947
40400
  },
41948
40401
  {
@@ -43770,7 +42223,6 @@ var DEFAULT_FPS = 60;
43770
42223
  _this.objectInstance = {};
43771
42224
  _this.root = new exports.VFXItem(_assert_this_initialized(_this));
43772
42225
  _this.root.name = "root";
43773
- _this.windowRoot = new WindowRootControl(_assert_this_initialized(_this));
43774
42226
  _this.whiteTexture = generateWhiteTexture(_assert_this_initialized(_this));
43775
42227
  _this.transparentTexture = generateEmptyTexture(_assert_this_initialized(_this));
43776
42228
  if (!(options == null ? void 0 : options.manualRender)) {
@@ -43923,7 +42375,7 @@ var DEFAULT_FPS = 60;
43923
42375
  (_this_ticker1 = this.ticker) == null ? void 0 : _this_ticker1.pause();
43924
42376
  return;
43925
42377
  }
43926
- this.windowRoot.update(dt);
42378
+ this.emit("update", dt);
43927
42379
  // Tick compositions onPreRender
43928
42380
  //-------------------------------------------------------------------------
43929
42381
  for(var _iterator1 = _create_for_of_iterator_helper_loose(compositions), _step1; !(_step1 = _iterator1()).done;){
@@ -43938,7 +42390,7 @@ var DEFAULT_FPS = 60;
43938
42390
  var composition2 = _step2.value;
43939
42391
  composition2.renderContent();
43940
42392
  }
43941
- this.windowRoot.render();
42393
+ this.emit("postrender");
43942
42394
  this.renderTargetPool.flush();
43943
42395
  };
43944
42396
  /**
@@ -43980,7 +42432,6 @@ var DEFAULT_FPS = 60;
43980
42432
  this.canvas.style.height = containerHeight + "px";
43981
42433
  logger.info("Resize engine " + this.name + " [" + canvasWidth + "," + canvasHeight + "," + containerWidth + "," + containerHeight + "].");
43982
42434
  this.setSize(canvasWidth, canvasHeight);
43983
- this.windowRoot.resize(canvasWidth, canvasHeight);
43984
42435
  }
43985
42436
  };
43986
42437
  _proto.setSize = function setSize(width, height) {
@@ -44186,6 +42637,12 @@ var DEFAULT_FPS = 60;
44186
42637
  _proto.setStencilTest = function setStencilTest(enable) {
44187
42638
  // OVERRIDE
44188
42639
  };
42640
+ _proto.setScissorTest = function setScissorTest(enable) {
42641
+ // OVERRIDE
42642
+ };
42643
+ _proto.setScissor = function setScissor(x, y, width, height) {
42644
+ // OVERRIDE
42645
+ };
44189
42646
  _proto.setCulling = function setCulling(enable) {
44190
42647
  // OVERRIDE
44191
42648
  };
@@ -44263,7 +42720,6 @@ var DEFAULT_FPS = 60;
44263
42720
  composition.dispose();
44264
42721
  }
44265
42722
  this.root.dispose();
44266
- this.windowRoot.dispose();
44267
42723
  (_this_assetService = this.assetService) == null ? void 0 : _this_assetService.dispose();
44268
42724
  (_this__graphics = this._graphics) == null ? void 0 : _this__graphics.dispose();
44269
42725
  this.renderPasses.forEach(function(pass) {
@@ -44588,7 +43044,7 @@ registerPlugin("text", TextLoader);
44588
43044
  registerPlugin("sprite", SpriteLoader);
44589
43045
  registerPlugin("particle", ParticleLoader);
44590
43046
  registerPlugin("interact", InteractLoader);
44591
- var version$1 = "2.10.0-alpha.3";
43047
+ var version$1 = "2.10.0-alpha.5";
44592
43048
  logger.info("Core version: " + version$1 + ".");
44593
43049
 
44594
43050
  var _obj;
@@ -46081,7 +44537,7 @@ applyMixins(exports.ThreeTextComponent, [
46081
44537
  */ Mesh.create = function(engine, props) {
46082
44538
  return new ThreeMesh(engine, props);
46083
44539
  };
46084
- var version = "2.10.0-alpha.3";
44540
+ var version = "2.10.0-alpha.5";
46085
44541
  logger.info("THREEJS plugin version: " + version + ".");
46086
44542
 
46087
44543
  exports.ATLAS_SIZE = ATLAS_SIZE;
@@ -46120,8 +44576,6 @@ exports.COPY_MESH_SHADER_ID = COPY_MESH_SHADER_ID;
46120
44576
  exports.COPY_VERTEX_SHADER = COPY_VERTEX_SHADER;
46121
44577
  exports.Camera = Camera;
46122
44578
  exports.CameraVFXItemLoader = CameraVFXItemLoader;
46123
- exports.CanvasContainer = CanvasContainer;
46124
- exports.CanvasRootControl = CanvasRootControl;
46125
44579
  exports.Circle = Circle$1;
46126
44580
  exports.ColorCurve = ColorCurve;
46127
44581
  exports.ColorPlayable = ColorPlayable;
@@ -46134,8 +44588,6 @@ exports.Composition = Composition;
46134
44588
  exports.ConstBoolNode = ConstBoolNode;
46135
44589
  exports.ConstFloatNode = ConstFloatNode;
46136
44590
  exports.ConstraintTarget = ConstraintTarget;
46137
- exports.ContainerControl = ContainerControl;
46138
- exports.Control = Control;
46139
44591
  exports.ControlParameterBoolNode = ControlParameterBoolNode;
46140
44592
  exports.ControlParameterFloatNode = ControlParameterFloatNode;
46141
44593
  exports.ControlParameterTriggerNode = ControlParameterTriggerNode;
@@ -46242,7 +44694,6 @@ exports.RenderTargetPool = RenderTargetPool;
46242
44694
  exports.Renderbuffer = Renderbuffer;
46243
44695
  exports.Renderer = Renderer;
46244
44696
  exports.RendererComponent = RendererComponent;
46245
- exports.RootControl = RootControl;
46246
44697
  exports.RuntimeClip = RuntimeClip;
46247
44698
  exports.SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0 = SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0;
46248
44699
  exports.SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0 = SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0;
@@ -46286,8 +44737,6 @@ exports.TransformPlayable = TransformPlayable;
46286
44737
  exports.TransitionNode = TransitionNode;
46287
44738
  exports.Triangle = Triangle;
46288
44739
  exports.TrimPath = TrimPath;
46289
- exports.UICanvas = UICanvas;
46290
- exports.UIControl = UIControl;
46291
44740
  exports.ValueGetter = ValueGetter;
46292
44741
  exports.ValueNode = ValueNode;
46293
44742
  exports.Vector2Curve = Vector2Curve;
@@ -46297,7 +44746,6 @@ exports.Vector3PropertyMixerPlayable = Vector3PropertyMixerPlayable;
46297
44746
  exports.Vector4Curve = Vector4Curve;
46298
44747
  exports.Vector4PropertyMixerPlayable = Vector4PropertyMixerPlayable;
46299
44748
  exports.VertexBuffer = VertexBuffer;
46300
- exports.WindowRootControl = WindowRootControl;
46301
44749
  exports.addByOrder = addByOrder;
46302
44750
  exports.addItem = addItem;
46303
44751
  exports.addItemWithOrder = addItemWithOrder;