@antv/g-lite 2.0.9 → 2.0.10-alpha.1

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.esm.js CHANGED
@@ -1,10 +1,12 @@
1
+ import { glMatrix, mat4, vec4, vec3, mat3, quat as quat$1, vec2 } from 'gl-matrix';
1
2
  import { __assign, __read, __extends, __spreadArray, __awaiter, __generator, __values, __rest } from 'tslib';
2
3
  import EventEmitter from 'eventemitter3';
3
- import { mat4, vec4, vec3, mat3, quat as quat$1, vec2 } from 'gl-matrix';
4
4
  import { isNumber, distanceSquareRoot, isString, isNil, clamp, getTotalLength, min, max, isNumberEqual, mod, normalizePath, path2Curve, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, isUndefined, isArray, isBoolean, isObject, getPointAtLength } from '@antv/util';
5
5
  import * as d3 from 'd3-color';
6
6
  import { polylineLength, arcBox, cubicBox, quadBox, linePointAt, lineLength } from '@antv/g-math';
7
7
 
8
+ glMatrix.setMatrixArrayType(Array);
9
+
8
10
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
9
11
 
10
12
  var rbush = {exports: {}};
@@ -641,7 +643,7 @@ var AbstractRenderer = /** @class */ (function () {
641
643
  /**
642
644
  * enable dirty rectangle rendering by default
643
645
  */
644
- enableDirtyRectangleRendering: true, enableDirtyRectangleRenderingDebug: false, enableSizeAttenuation: true }, config);
646
+ enableDirtyRectangleRendering: true, enableDirtyRectangleRenderingDebug: false, enableSizeAttenuation: true, imageSmoothingEnabled: true, imageSmoothingQuality: 'high' }, config);
645
647
  }
646
648
  AbstractRenderer.prototype.registerPlugin = function (plugin) {
647
649
  var index = this.plugins.findIndex(function (p) { return p === plugin; });
@@ -3106,25 +3108,25 @@ var CSSUnitValue = /** @class */ (function (_super) {
3106
3108
  case UnitType.kSeconds:
3107
3109
  // case UnitType.kHertz:
3108
3110
  // case UnitType.kKilohertz:
3109
- case UnitType.kTurns: // case UnitType.kContainerMax: { // case UnitType.kContainerMin: // case UnitType.kContainerBlockSize: // case UnitType.kContainerInlineSize: // case UnitType.kContainerHeight: // case UnitType.kContainerWidth: // case UnitType.kDynamicViewportMax: // case UnitType.kDynamicViewportMin: // case UnitType.kDynamicViewportBlockSize: // case UnitType.kDynamicViewportInlineSize: // case UnitType.kDynamicViewportHeight: // case UnitType.kDynamicViewportWidth: // case UnitType.kLargeViewportMax: // case UnitType.kLargeViewportMin: // case UnitType.kLargeViewportBlockSize: // case UnitType.kLargeViewportInlineSize: // case UnitType.kLargeViewportHeight: // case UnitType.kLargeViewportWidth: // case UnitType.kSmallViewportMax: // case UnitType.kSmallViewportMin: // case UnitType.kSmallViewportBlockSize: // case UnitType.kSmallViewportInlineSize: // case UnitType.kSmallViewportHeight: // case UnitType.kSmallViewportWidth: // case UnitType.kViewportMax: // case UnitType.kViewportMin: // case UnitType.kViewportBlockSize: // case UnitType.kViewportInlineSize: // case UnitType.kViewportHeight: // case UnitType.kViewportWidth: // case UnitType.kFraction:
3110
- {
3111
- var kMinInteger = -999999;
3112
- var kMaxInteger = 999999;
3113
- var value = this.value;
3114
- var unit = unitTypeToString(this.unit);
3115
- if (value < kMinInteger || value > kMaxInteger) {
3116
- var unit_1 = unitTypeToString(this.unit);
3117
- if (!Number.isFinite(value) || Number.isNaN(value)) {
3118
- text = formatInfinityOrNaN(value, unit_1);
3119
- }
3120
- else {
3121
- text = value + (unit_1 || '');
3122
- }
3111
+ // case UnitType.kContainerMax: { // case UnitType.kContainerMin: // case UnitType.kContainerBlockSize: // case UnitType.kContainerInlineSize: // case UnitType.kContainerHeight: // case UnitType.kContainerWidth: // case UnitType.kDynamicViewportMax: // case UnitType.kDynamicViewportMin: // case UnitType.kDynamicViewportBlockSize: // case UnitType.kDynamicViewportInlineSize: // case UnitType.kDynamicViewportHeight: // case UnitType.kDynamicViewportWidth: // case UnitType.kLargeViewportMax: // case UnitType.kLargeViewportMin: // case UnitType.kLargeViewportBlockSize: // case UnitType.kLargeViewportInlineSize: // case UnitType.kLargeViewportHeight: // case UnitType.kLargeViewportWidth: // case UnitType.kSmallViewportMax: // case UnitType.kSmallViewportMin: // case UnitType.kSmallViewportBlockSize: // case UnitType.kSmallViewportInlineSize: // case UnitType.kSmallViewportHeight: // case UnitType.kSmallViewportWidth: // case UnitType.kViewportMax: // case UnitType.kViewportMin: // case UnitType.kViewportBlockSize: // case UnitType.kViewportInlineSize: // case UnitType.kViewportHeight: // case UnitType.kViewportWidth: // case UnitType.kFraction:
3112
+ case UnitType.kTurns: {
3113
+ var kMinInteger = -999999;
3114
+ var kMaxInteger = 999999;
3115
+ var value = this.value;
3116
+ var unit = unitTypeToString(this.unit);
3117
+ if (value < kMinInteger || value > kMaxInteger) {
3118
+ var unit_1 = unitTypeToString(this.unit);
3119
+ if (!Number.isFinite(value) || Number.isNaN(value)) {
3120
+ text = formatInfinityOrNaN(value, unit_1);
3123
3121
  }
3124
3122
  else {
3125
- text = "".concat(value).concat(unit);
3123
+ text = value + (unit_1 || '');
3126
3124
  }
3127
3125
  }
3126
+ else {
3127
+ text = "".concat(value).concat(unit);
3128
+ }
3129
+ }
3128
3130
  }
3129
3131
  result += text;
3130
3132
  return result;
@@ -3132,7 +3134,6 @@ var CSSUnitValue = /** @class */ (function (_super) {
3132
3134
  return CSSUnitValue;
3133
3135
  }(CSSStyleValue));
3134
3136
  var Opx = new CSSUnitValue(0, 'px');
3135
- new CSSUnitValue(1, 'px');
3136
3137
  var Odeg = new CSSUnitValue(0, 'deg');
3137
3138
 
3138
3139
  /**
@@ -5162,6 +5163,7 @@ function mergePoints(left, right) {
5162
5163
  }
5163
5164
 
5164
5165
  var _ = null;
5166
+ var TRANSFORM_REGEXP = /\s*(\w+)\(([^)]*)\)/g;
5165
5167
  function cast(pattern) {
5166
5168
  return function (contents) {
5167
5169
  var i = 0;
@@ -5180,48 +5182,75 @@ var transformFunctions = {
5180
5182
  matrix: ['NNNNNN', [_, _, 0, 0, _, _, 0, 0, 0, 0, 1, 0, _, _, 0, 1], id],
5181
5183
  matrix3d: ['NNNNNNNNNNNNNNNN', id],
5182
5184
  rotate: ['A'],
5183
- rotatex: ['A'],
5184
- rotatey: ['A'],
5185
- rotatez: ['A'],
5185
+ rotateX: ['A'],
5186
+ rotateY: ['A'],
5187
+ rotateZ: ['A'],
5186
5188
  rotate3d: ['NNNA'],
5187
5189
  perspective: ['L'],
5188
5190
  scale: ['Nn', cast([_, _, new CSSUnitValue(1)]), id],
5189
- scalex: [
5191
+ scaleX: [
5190
5192
  'N',
5191
5193
  cast([_, new CSSUnitValue(1), new CSSUnitValue(1)]),
5192
5194
  cast([_, new CSSUnitValue(1)]),
5193
5195
  ],
5194
- scaley: [
5196
+ scaleY: [
5195
5197
  'N',
5196
5198
  cast([new CSSUnitValue(1), _, new CSSUnitValue(1)]),
5197
5199
  cast([new CSSUnitValue(1), _]),
5198
5200
  ],
5199
- scalez: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
5201
+ scaleZ: ['N', cast([new CSSUnitValue(1), new CSSUnitValue(1), _])],
5200
5202
  scale3d: ['NNN', id],
5201
5203
  skew: ['Aa', null, id],
5202
- skewx: ['A', null, cast([_, Odeg])],
5203
- skewy: ['A', null, cast([Odeg, _])],
5204
+ skewX: ['A', null, cast([_, Odeg])],
5205
+ skewY: ['A', null, cast([Odeg, _])],
5204
5206
  translate: ['Tt', cast([_, _, Opx]), id],
5205
- translatex: ['T', cast([_, Opx, Opx]), cast([_, Opx])],
5206
- translatey: ['T', cast([Opx, _, Opx]), cast([Opx, _])],
5207
- translatez: ['L', cast([Opx, Opx, _])],
5207
+ translateX: ['T', cast([_, Opx, Opx]), cast([_, Opx])],
5208
+ translateY: ['T', cast([Opx, _, Opx]), cast([Opx, _])],
5209
+ translateZ: ['L', cast([Opx, Opx, _])],
5208
5210
  translate3d: ['TTL', id],
5209
5211
  };
5212
+ function parseArrayTransform(transform) {
5213
+ var result = [];
5214
+ var length = transform.length;
5215
+ for (var i = 0; i < length; i++) {
5216
+ var item = transform[i];
5217
+ var name_1 = item[0];
5218
+ var args = item.slice(1);
5219
+ // infer default value
5220
+ if (name_1 === 'translate' || name_1 === 'skew') {
5221
+ if (args.length === 1)
5222
+ args.push(0);
5223
+ }
5224
+ else if (name_1 === 'scale') {
5225
+ if (args.length === 1)
5226
+ args.push(args[0]);
5227
+ }
5228
+ var functionData = transformFunctions[name_1];
5229
+ if (!functionData)
5230
+ return [];
5231
+ var parsedArgs = args.map(function (value) { return getOrCreateUnitValue(value); });
5232
+ result.push({ t: name_1, d: parsedArgs });
5233
+ }
5234
+ return result;
5235
+ }
5210
5236
  /**
5211
5237
  * none
5212
5238
  * scale(1) scale(1, 2)
5213
5239
  * scaleX(1)
5214
5240
  */
5215
- function parseTransform(string) {
5216
- string = (string || 'none').toLowerCase().trim();
5217
- if (string === 'none') {
5241
+ function parseTransform(transform) {
5242
+ if (Array.isArray(transform)) {
5243
+ return parseArrayTransform(transform);
5244
+ }
5245
+ transform = (transform || 'none').trim();
5246
+ if (transform === 'none') {
5218
5247
  return [];
5219
5248
  }
5220
- var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5221
5249
  var result = [];
5222
5250
  var match;
5223
5251
  var prevLastIndex = 0;
5224
- while ((match = transformRegExp.exec(string))) {
5252
+ TRANSFORM_REGEXP.lastIndex = 0;
5253
+ while ((match = TRANSFORM_REGEXP.exec(transform))) {
5225
5254
  if (match.index !== prevLastIndex) {
5226
5255
  return [];
5227
5256
  }
@@ -5268,22 +5297,24 @@ function parseTransform(string) {
5268
5297
  parsedArgs.push(parsedArg);
5269
5298
  }
5270
5299
  result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5271
- if (transformRegExp.lastIndex === string.length) {
5300
+ if (TRANSFORM_REGEXP.lastIndex === transform.length) {
5272
5301
  return result;
5273
5302
  }
5274
5303
  }
5275
5304
  return [];
5276
5305
  }
5277
- function parseTransformUnmemoize(string) {
5278
- string = (string || 'none').toLowerCase().trim();
5279
- if (string === 'none') {
5306
+ function parseTransformUnmemoize(transform) {
5307
+ if (Array.isArray(transform)) {
5308
+ return parseArrayTransform(transform);
5309
+ }
5310
+ transform = (transform || 'none').trim();
5311
+ if (transform === 'none') {
5280
5312
  return [];
5281
5313
  }
5282
- var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5283
5314
  var result = [];
5284
5315
  var match;
5285
5316
  var prevLastIndex = 0;
5286
- while ((match = transformRegExp.exec(string))) {
5317
+ while ((match = TRANSFORM_REGEXP.exec(transform))) {
5287
5318
  if (match.index !== prevLastIndex) {
5288
5319
  return [];
5289
5320
  }
@@ -5330,7 +5361,7 @@ function parseTransformUnmemoize(string) {
5330
5361
  parsedArgs.push(parsedArg);
5331
5362
  }
5332
5363
  result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5333
- if (transformRegExp.lastIndex === string.length) {
5364
+ if (TRANSFORM_REGEXP.lastIndex === transform.length) {
5334
5365
  return result;
5335
5366
  }
5336
5367
  }
@@ -5342,7 +5373,7 @@ function convertItemToMatrix(item) {
5342
5373
  var z;
5343
5374
  var angle;
5344
5375
  switch (item.t) {
5345
- case 'rotatex':
5376
+ case 'rotateX':
5346
5377
  angle = deg2rad(convertAngleUnit(item.d[0]));
5347
5378
  return [
5348
5379
  1,
@@ -5362,7 +5393,7 @@ function convertItemToMatrix(item) {
5362
5393
  0,
5363
5394
  1,
5364
5395
  ];
5365
- case 'rotatey':
5396
+ case 'rotateY':
5366
5397
  angle = deg2rad(convertAngleUnit(item.d[0]));
5367
5398
  return [
5368
5399
  Math.cos(angle),
@@ -5383,7 +5414,7 @@ function convertItemToMatrix(item) {
5383
5414
  1,
5384
5415
  ];
5385
5416
  case 'rotate':
5386
- case 'rotatez':
5417
+ case 'rotateZ':
5387
5418
  angle = deg2rad(convertAngleUnit(item.d[0]));
5388
5419
  return [
5389
5420
  Math.cos(angle),
@@ -5460,11 +5491,11 @@ function convertItemToMatrix(item) {
5460
5491
  0,
5461
5492
  1,
5462
5493
  ];
5463
- case 'scalex':
5494
+ case 'scaleX':
5464
5495
  return [item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5465
- case 'scaley':
5496
+ case 'scaleY':
5466
5497
  return [1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5467
- case 'scalez':
5498
+ case 'scaleZ':
5468
5499
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, item.d[0].value, 0, 0, 0, 0, 1];
5469
5500
  case 'scale3d':
5470
5501
  return [
@@ -5506,10 +5537,10 @@ function convertItemToMatrix(item) {
5506
5537
  0,
5507
5538
  1,
5508
5539
  ];
5509
- case 'skewx':
5540
+ case 'skewX':
5510
5541
  angle = deg2rad(convertAngleUnit(item.d[0]));
5511
5542
  return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5512
- case 'skewy':
5543
+ case 'skewY':
5513
5544
  angle = deg2rad(convertAngleUnit(item.d[0]));
5514
5545
  return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5515
5546
  case 'translate':
@@ -5517,13 +5548,13 @@ function convertItemToMatrix(item) {
5517
5548
  x = convertPercentUnit(item.d[0], 0, null) || 0;
5518
5549
  y = convertPercentUnit(item.d[1], 0, null) || 0;
5519
5550
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, 0, 1];
5520
- case 'translatex':
5551
+ case 'translateX':
5521
5552
  x = convertPercentUnit(item.d[0], 0, null) || 0;
5522
5553
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, 0, 0, 1];
5523
- case 'translatey':
5554
+ case 'translateY':
5524
5555
  y = convertPercentUnit(item.d[0], 0, null) || 0;
5525
5556
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, y, 0, 1];
5526
- case 'translatez':
5557
+ case 'translateZ':
5527
5558
  z = convertPercentUnit(item.d[0], 0, null) || 0;
5528
5559
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, z, 1];
5529
5560
  case 'translate3d':
@@ -5764,13 +5795,13 @@ function quat(fromQ, toQ, f) {
5764
5795
  }
5765
5796
  return quat;
5766
5797
  }
5767
- // scalex/y/z -> scale
5798
+ // scaleX/Y/Z -> scale
5768
5799
  function typeTo2D(type) {
5769
- return type.replace(/[xy]/, '');
5800
+ return type.replace(/[XY]/, '');
5770
5801
  }
5771
- // scalex/y/z -> scale3d
5802
+ // scaleX/Y/Z -> scale3d
5772
5803
  function typeTo3D(type) {
5773
- return type.replace(/(x|y|z|3d)?$/, '3d');
5804
+ return type.replace(/(X|Y|Z|3d)?$/, '3d');
5774
5805
  }
5775
5806
  var isMatrixOrPerspective = function (lt, rt) {
5776
5807
  return ((lt === 'perspective' && rt === 'perspective') ||
@@ -7904,15 +7935,15 @@ function parsedTransformToMat4(transform, object) {
7904
7935
  ];
7905
7936
  mat4.fromScaling(tmpMat2, [newScale[0], newScale[1], 1]);
7906
7937
  }
7907
- else if (t === 'scalex') {
7938
+ else if (t === 'scaleX') {
7908
7939
  var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7909
7940
  mat4.fromScaling(tmpMat2, [newScale[0], 1, 1]);
7910
7941
  }
7911
- else if (t === 'scaley') {
7942
+ else if (t === 'scaleY') {
7912
7943
  var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7913
7944
  mat4.fromScaling(tmpMat2, [1, newScale[0], 1]);
7914
7945
  }
7915
- else if (t === 'scalez') {
7946
+ else if (t === 'scaleZ') {
7916
7947
  var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7917
7948
  mat4.fromScaling(tmpMat2, [1, 1, newScale[0]]);
7918
7949
  }
@@ -7930,15 +7961,15 @@ function parsedTransformToMat4(transform, object) {
7930
7961
  0,
7931
7962
  ]);
7932
7963
  }
7933
- else if (t === 'translatex') {
7964
+ else if (t === 'translateX') {
7934
7965
  var newTranslation = d || [Opx];
7935
7966
  mat4.fromTranslation(tmpMat2, [newTranslation[0].value, 0, 0]);
7936
7967
  }
7937
- else if (t === 'translatey') {
7968
+ else if (t === 'translateY') {
7938
7969
  var newTranslation = d || [Opx];
7939
7970
  mat4.fromTranslation(tmpMat2, [0, newTranslation[0].value, 0]);
7940
7971
  }
7941
- else if (t === 'translatez') {
7972
+ else if (t === 'translateZ') {
7942
7973
  var newTranslation = d || [Opx];
7943
7974
  mat4.fromTranslation(tmpMat2, [0, 0, newTranslation[0].value]);
7944
7975
  }
@@ -7954,15 +7985,15 @@ function parsedTransformToMat4(transform, object) {
7954
7985
  var newAngles = d || [Odeg];
7955
7986
  mat4.fromZRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7956
7987
  }
7957
- else if (t === 'rotatex') {
7988
+ else if (t === 'rotateX') {
7958
7989
  var newAngles = d || [Odeg];
7959
7990
  mat4.fromXRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7960
7991
  }
7961
- else if (t === 'rotatey') {
7992
+ else if (t === 'rotateY') {
7962
7993
  var newAngles = d || [Odeg];
7963
7994
  mat4.fromYRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7964
7995
  }
7965
- else if (t === 'rotatez') {
7996
+ else if (t === 'rotateZ') {
7966
7997
  var newAngles = d || [Odeg];
7967
7998
  mat4.fromZRotation(tmpMat2, deg2rad(convertAngleUnit(newAngles[0])));
7968
7999
  }
@@ -7978,11 +8009,11 @@ function parsedTransformToMat4(transform, object) {
7978
8009
  var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0, 0];
7979
8010
  createSkewMatrix(tmpMat2, deg2rad(newSkew[0]), deg2rad(newSkew[1]));
7980
8011
  }
7981
- else if (t === 'skewx') {
8012
+ else if (t === 'skewX') {
7982
8013
  var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
7983
8014
  createSkewMatrix(tmpMat2, deg2rad(newSkew[0]), 0);
7984
8015
  }
7985
- else if (t === 'skewy') {
8016
+ else if (t === 'skewY') {
7986
8017
  var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
7987
8018
  createSkewMatrix(tmpMat2, 0, deg2rad(newSkew[0]));
7988
8019
  }
@@ -10072,6 +10103,12 @@ var RenderingService = /** @class */ (function () {
10072
10103
  */
10073
10104
  rendered: 0,
10074
10105
  };
10106
+ /**
10107
+ * frame counter
10108
+ * - 1 - init root container
10109
+ * - 2 - user first frame
10110
+ */
10111
+ this.frame = 0;
10075
10112
  this.zIndexCounter = 0;
10076
10113
  this.hooks = {
10077
10114
  /**
@@ -10164,9 +10201,12 @@ var RenderingService = /** @class */ (function () {
10164
10201
  this.stats.total = 0;
10165
10202
  this.stats.rendered = 0;
10166
10203
  this.zIndexCounter = 0;
10204
+ this.frame++;
10167
10205
  var renderingContext = this.context.renderingContext;
10168
10206
  this.globalRuntime.sceneGraphService.syncHierarchy(renderingContext.root);
10169
- this.globalRuntime.sceneGraphService.triggerPendingEvents();
10207
+ if (this.frame > 2) {
10208
+ this.globalRuntime.sceneGraphService.triggerPendingEvents(this.frame === 3 ? renderingContext.root : undefined);
10209
+ }
10170
10210
  if (renderingContext.renderReasons.size && this.inited) {
10171
10211
  // @ts-ignore
10172
10212
  renderingContext.dirtyRectangleRenderingDisabled =
@@ -10471,6 +10511,19 @@ function markRenderableDirty(e) {
10471
10511
  }
10472
10512
  }
10473
10513
  var reparentEvent = new MutationEvent(ElementEvent.REPARENT, null, '', '', '', 0, '', '');
10514
+ var EPSILON = 0.000001;
10515
+ /**
10516
+ * an optimized version of gl-matrix's equals
10517
+ */
10518
+ function equals(a, b) {
10519
+ var a0 = a[0], a1 = a[1], a2 = a[2];
10520
+ var b0 = b[0], b1 = b[1], b2 = b[2];
10521
+ if (a0 === b0 && a1 === b1 && a2 === b2)
10522
+ return true;
10523
+ return (Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
10524
+ Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
10525
+ Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)));
10526
+ }
10474
10527
  /**
10475
10528
  * update transform in scene graph
10476
10529
  *
@@ -10582,7 +10635,7 @@ var DefaultSceneGraphService = /** @class */ (function () {
10582
10635
  translation = vec3.fromValues(translation, y, z);
10583
10636
  }
10584
10637
  var transform = element.transformable;
10585
- if (vec3.equals(translation, vec3.create())) {
10638
+ if (equals(translation, vec3.create())) {
10586
10639
  return;
10587
10640
  }
10588
10641
  vec3.transformQuat(translation, translation, transform.localRotation);
@@ -10607,7 +10660,7 @@ var DefaultSceneGraphService = /** @class */ (function () {
10607
10660
  tmpPosition[0] = position[0];
10608
10661
  tmpPosition[1] = position[1];
10609
10662
  tmpPosition[2] = position[2] || 0;
10610
- if (vec3.equals(_this.getPosition(element), tmpPosition)) {
10663
+ if (equals(_this.getPosition(element), tmpPosition)) {
10611
10664
  return;
10612
10665
  }
10613
10666
  vec3.copy(transform.position, tmpPosition);
@@ -10637,7 +10690,7 @@ var DefaultSceneGraphService = /** @class */ (function () {
10637
10690
  tmpPosition[0] = position[0];
10638
10691
  tmpPosition[1] = position[1];
10639
10692
  tmpPosition[2] = position[2] || 0;
10640
- if (vec3.equals(transform.localPosition, tmpPosition)) {
10693
+ if (equals(transform.localPosition, tmpPosition)) {
10641
10694
  return;
10642
10695
  }
10643
10696
  vec3.copy(transform.localPosition, tmpPosition);
@@ -10669,7 +10722,7 @@ var DefaultSceneGraphService = /** @class */ (function () {
10669
10722
  if (typeof translation === 'number') {
10670
10723
  translation = vec3.set(tmpVec3, translation, y, z);
10671
10724
  }
10672
- if (vec3.equals(translation, zeroVec3)) {
10725
+ if (equals(translation, zeroVec3)) {
10673
10726
  return;
10674
10727
  }
10675
10728
  vec3.add(tr, _this.getPosition(element), translation);
@@ -10700,6 +10753,7 @@ var DefaultSceneGraphService = /** @class */ (function () {
10700
10753
  }
10701
10754
  };
10702
10755
  };
10756
+ this.eventEntitySet = new Set();
10703
10757
  this.displayObjectDependencyMap = new WeakMap();
10704
10758
  this.calcLocalTransform = (function () {
10705
10759
  var tmpMat = mat4.create();
@@ -10867,7 +10921,7 @@ var DefaultSceneGraphService = /** @class */ (function () {
10867
10921
  if (dirtify === void 0) { dirtify = true; }
10868
10922
  var transform = element.transformable;
10869
10923
  var updatedScaling = vec3.fromValues(scaling[0], scaling[1], scaling[2] || transform.localScale[2]);
10870
- if (vec3.equals(updatedScaling, transform.localScale)) {
10924
+ if (equals(updatedScaling, transform.localScale)) {
10871
10925
  return;
10872
10926
  }
10873
10927
  vec3.copy(transform.localScale, updatedScaling);
@@ -10909,35 +10963,47 @@ var DefaultSceneGraphService = /** @class */ (function () {
10909
10963
  this.dirtifyWorldInternal(element, transform);
10910
10964
  this.dirtifyToRoot(element, true);
10911
10965
  };
10912
- DefaultSceneGraphService.prototype.triggerPendingEvents = function () {
10966
+ DefaultSceneGraphService.prototype.triggerEvent = function (element, detail) {
10967
+ if (element.isConnected && !this.eventEntitySet.has(element.entity)) {
10968
+ this.boundsChangedEvent.detail = detail;
10969
+ this.boundsChangedEvent.target = element;
10970
+ if (element.isMutationObserved) {
10971
+ element.dispatchEvent(this.boundsChangedEvent);
10972
+ }
10973
+ else {
10974
+ element.ownerDocument.defaultView.dispatchEvent(this.boundsChangedEvent, true);
10975
+ }
10976
+ this.eventEntitySet.add(element.entity);
10977
+ }
10978
+ };
10979
+ DefaultSceneGraphService.prototype.triggerPendingEvents = function (root) {
10913
10980
  var _this = this;
10914
- var set = new Set();
10915
- var trigger = function (element, detail) {
10916
- if (element.isConnected && !set.has(element.entity)) {
10917
- _this.boundsChangedEvent.detail = detail;
10918
- _this.boundsChangedEvent.target = element;
10919
- if (element.isMutationObserved) {
10920
- element.dispatchEvent(_this.boundsChangedEvent);
10981
+ if (root) {
10982
+ root.forEach(function (e) {
10983
+ _this.triggerEvent(e, { affectChildren: true });
10984
+ });
10985
+ }
10986
+ else {
10987
+ var events = this.pendingEvents;
10988
+ var length_1 = events.length;
10989
+ var _loop_1 = function (i) {
10990
+ var _a = __read(events[i], 2), element = _a[0], detail = _a[1];
10991
+ if (detail.affectChildren) {
10992
+ element.forEach(function (e) {
10993
+ _this.triggerEvent(e, detail);
10994
+ });
10921
10995
  }
10922
10996
  else {
10923
- element.ownerDocument.defaultView.dispatchEvent(_this.boundsChangedEvent, true);
10997
+ this_1.triggerEvent(element, detail);
10924
10998
  }
10925
- set.add(element.entity);
10926
- }
10927
- };
10928
- this.pendingEvents.forEach(function (_a) {
10929
- var _b = __read(_a, 2), element = _b[0], detail = _b[1];
10930
- if (detail.affectChildren) {
10931
- element.forEach(function (e) {
10932
- trigger(e, detail);
10933
- });
10934
- }
10935
- else {
10936
- trigger(element, detail);
10999
+ };
11000
+ var this_1 = this;
11001
+ for (var i = 0; i < length_1; i++) {
11002
+ _loop_1(i);
10937
11003
  }
10938
- });
11004
+ }
11005
+ this.eventEntitySet.clear();
10939
11006
  this.clearPendingEvents();
10940
- set.clear();
10941
11007
  };
10942
11008
  DefaultSceneGraphService.prototype.clearPendingEvents = function () {
10943
11009
  this.pendingEvents = [];
@@ -11045,9 +11111,9 @@ var DefaultSceneGraphService = /** @class */ (function () {
11045
11111
  return transform.localTransform;
11046
11112
  };
11047
11113
  DefaultSceneGraphService.prototype.setLocalTransform = function (element, transform) {
11048
- var t = mat4.getTranslation(vec3.create(), transform);
11049
- var r = mat4.getRotation(quat$1.create(), transform);
11050
- var s = mat4.getScaling(vec3.create(), transform);
11114
+ var t = mat4.getTranslation([0, 0, 0], transform);
11115
+ var r = mat4.getRotation([0, 0, 0, 1], transform);
11116
+ var s = mat4.getScaling([0, 0, 0], transform);
11051
11117
  this.setLocalScale(element, s, false);
11052
11118
  this.setLocalPosition(element, t, false);
11053
11119
  this.setLocalRotation(element, r, undefined, undefined, undefined, false);
@@ -14799,7 +14865,6 @@ var PrepareRendererPlugin = /** @class */ (function () {
14799
14865
  * sync to RBush later
14800
14866
  */
14801
14867
  this.toSync = new Set();
14802
- this.isFirstTimeRendering = true;
14803
14868
  this.syncing = false;
14804
14869
  this.isFirstTimeRenderingFinished = false;
14805
14870
  }
@@ -14869,8 +14934,9 @@ var PrepareRendererPlugin = /** @class */ (function () {
14869
14934
  });
14870
14935
  var ric = (_a = runtime.globalThis.requestIdleCallback) !== null && _a !== void 0 ? _a : raf.bind(runtime.globalThis);
14871
14936
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
14872
- if (_this.isFirstTimeRendering) {
14873
- _this.isFirstTimeRendering = false;
14937
+ var frame = context.renderingService.frame;
14938
+ if (frame === 1) ;
14939
+ else if (frame === 2) {
14874
14940
  _this.syncing = true;
14875
14941
  ric(function () {
14876
14942
  _this.syncRTree(true);
@@ -14891,13 +14957,12 @@ var PrepareRendererPlugin = /** @class */ (function () {
14891
14957
  this.syncing = true;
14892
14958
  // bounds changed, need re-inserting its children
14893
14959
  var bulk = [];
14894
- Array.from(this.toSync)
14895
- // some objects may be removed since last frame
14896
- .filter(function (object) { return object.isConnected; })
14897
- .forEach(function (node) {
14960
+ this.toSync.forEach(function (node) {
14961
+ if (node.isConnected)
14962
+ return;
14898
14963
  var rBushNode = node.rBushNode;
14899
14964
  // clear dirty node
14900
- if (rBushNode && rBushNode.aabb) {
14965
+ if (rBushNode === null || rBushNode === void 0 ? void 0 : rBushNode.aabb) {
14901
14966
  _this.rBush.remove(rBushNode.aabb);
14902
14967
  }
14903
14968
  var renderBounds = node.getRenderBounds();
@@ -15304,13 +15369,13 @@ var Canvas = /** @class */ (function (_super) {
15304
15369
  });
15305
15370
  }
15306
15371
  };
15307
- Canvas.prototype.initRenderingService = function (renderer, firstContentfullPaint, async) {
15372
+ Canvas.prototype.initRenderingService = function (renderer, firstContentfulPaint, async) {
15308
15373
  var _this = this;
15309
- if (firstContentfullPaint === void 0) { firstContentfullPaint = false; }
15374
+ if (firstContentfulPaint === void 0) { firstContentfulPaint = false; }
15310
15375
  if (async === void 0) { async = false; }
15311
15376
  this.context.renderingService.init(function () {
15312
15377
  _this.inited = true;
15313
- if (firstContentfullPaint) {
15378
+ if (firstContentfulPaint) {
15314
15379
  if (async) {
15315
15380
  _this.requestAnimationFrame(function () {
15316
15381
  _this.dispatchEvent(new CustomEvent(CanvasEvent.READY));
@@ -15326,7 +15391,7 @@ var Canvas = /** @class */ (function (_super) {
15326
15391
  if (_this.readyPromise) {
15327
15392
  _this.resolveReadyPromise();
15328
15393
  }
15329
- if (!firstContentfullPaint) {
15394
+ if (!firstContentfulPaint) {
15330
15395
  _this.getRoot().forEach(function (node) {
15331
15396
  var renderable = node.renderable;
15332
15397
  if (renderable) {