@galacean/engine-core 1.5.2 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -691,6 +691,186 @@ var Logger = {
691
691
  return GLCapabilityType;
692
692
  }({});
693
693
 
694
+ var AssetPromise = /*#__PURE__*/ function() {
695
+ function AssetPromise(executor) {
696
+ var _this = this;
697
+ this._state = "pending";
698
+ this._onTaskCompleteCallbacks = [];
699
+ this._onTaskDetailCallbacks = [];
700
+ this._promise = new Promise(function(resolve, reject) {
701
+ _this._reject = reject;
702
+ var onResolve = function(value) {
703
+ if (_this._state === "pending") {
704
+ resolve(value);
705
+ _this._state = "fulfilled";
706
+ _this._onTaskCompleteCallbacks = undefined;
707
+ _this._onTaskDetailCallbacks = undefined;
708
+ }
709
+ };
710
+ var onReject = function(reason) {
711
+ if (_this._state === "pending") {
712
+ reject(reason);
713
+ _this._state = "rejected";
714
+ _this._onTaskCompleteCallbacks = undefined;
715
+ _this._onTaskDetailCallbacks = undefined;
716
+ }
717
+ };
718
+ var onCancel = function(callback) {
719
+ if (_this._state === "pending") {
720
+ _this._onCancelHandler = callback;
721
+ }
722
+ };
723
+ var setTaskCompleteProgress = function(loaded, total) {
724
+ if (_this._state === "pending") {
725
+ var progress = _this._taskCompleteProgress || (_this._taskCompleteProgress = {
726
+ loaded: loaded,
727
+ total: total
728
+ });
729
+ progress.loaded = loaded;
730
+ progress.total = total;
731
+ _this._onTaskCompleteCallbacks.forEach(function(callback) {
732
+ return callback(loaded, total);
733
+ });
734
+ }
735
+ };
736
+ var setTaskDetailProgress = function(url, loaded, total) {
737
+ if (_this._state === "pending") {
738
+ var _this__taskDetailProgress, _url;
739
+ _this._taskDetailProgress || (_this._taskDetailProgress = {});
740
+ var progress = (_this__taskDetailProgress = _this._taskDetailProgress)[_url = url] || (_this__taskDetailProgress[_url] = {
741
+ loaded: loaded,
742
+ total: total
743
+ });
744
+ progress.loaded = loaded;
745
+ progress.total = total;
746
+ _this._onTaskDetailCallbacks.forEach(function(callback) {
747
+ return callback(url, loaded, total);
748
+ });
749
+ }
750
+ };
751
+ executor(onResolve, onReject, setTaskCompleteProgress, setTaskDetailProgress, onCancel);
752
+ });
753
+ }
754
+ var _proto = AssetPromise.prototype;
755
+ /**
756
+ * Progress callback.
757
+ * @param onTaskComplete - This callback function provides information about the overall progress of the task. For example, in batch processing tasks, you can use the loaded and total parameters to calculate the percentage of task completion or display a progress bar
758
+ * @param onTaskDetail - This callback function provides detailed progress information about the task. For instance, in file downloading scenarios, you can use the loaded and total parameters to calculate the download progress percentage and utilize the url parameter to provide additional details such as download speed and estimated remaining time
759
+ * @returns AssetPromise
760
+ */ _proto.onProgress = function onProgress(onTaskComplete, onTaskDetail) {
761
+ var completeProgress = this._taskCompleteProgress;
762
+ var detailProgress = this._taskDetailProgress;
763
+ if (completeProgress) {
764
+ onTaskComplete(completeProgress.loaded, completeProgress.total);
765
+ }
766
+ if (detailProgress) {
767
+ for(var url in detailProgress){
768
+ var _detailProgress_url = detailProgress[url], loaded = _detailProgress_url.loaded, total = _detailProgress_url.total;
769
+ onTaskDetail(url, loaded, total);
770
+ }
771
+ }
772
+ if (this._state === "pending") {
773
+ onTaskComplete && this._onTaskCompleteCallbacks.push(onTaskComplete);
774
+ onTaskDetail && this._onTaskDetailCallbacks.push(onTaskDetail);
775
+ }
776
+ return this;
777
+ };
778
+ _proto.then = function then(onfulfilled, onrejected) {
779
+ var _this = this;
780
+ return new AssetPromise(function(resolve, reject) {
781
+ _this._promise.then(onfulfilled, onrejected).then(resolve).catch(reject);
782
+ });
783
+ };
784
+ /**
785
+ * Attaches a callback for only the rejection of the Promise.
786
+ * @param onRejected - The callback to execute when the Promise is rejected.
787
+ * @returns A Promise for the completion of the callback.
788
+ */ _proto.catch = function _catch(onRejected) {
789
+ var _this = this;
790
+ return new AssetPromise(function(resolve, reject) {
791
+ _this._promise.catch(onRejected).then(resolve).catch(reject);
792
+ });
793
+ };
794
+ /**
795
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
796
+ * resolved value cannot be modified from the callback.
797
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
798
+ * @returns A Promise for the completion of the callback.
799
+ */ _proto.finally = function _finally(onFinally) {
800
+ return this._promise.finally(onFinally);
801
+ };
802
+ /**
803
+ * Cancel promise request.
804
+ * @returns Asset promise
805
+ */ _proto.cancel = function cancel() {
806
+ if (this._state !== "pending") {
807
+ return;
808
+ }
809
+ this._state = "canceled";
810
+ this._reject("canceled");
811
+ this._onCancelHandler && this._onCancelHandler();
812
+ return this;
813
+ };
814
+ AssetPromise.resolve = function resolve(value) {
815
+ if (value === undefined) {
816
+ return new AssetPromise(function(resolve) {
817
+ return resolve();
818
+ });
819
+ } else if (_instanceof(value, AssetPromise) || _instanceof(value, Promise)) {
820
+ return new AssetPromise(function(resolve, reject) {
821
+ value.then(function(resolved) {
822
+ return resolve(resolved);
823
+ }, reject);
824
+ });
825
+ } else {
826
+ return new AssetPromise(function(resolve) {
827
+ return resolve(value);
828
+ });
829
+ }
830
+ };
831
+ AssetPromise.all = function all(values) {
832
+ return new AssetPromise(function(resolve, reject, setTaskCompleteProgress) {
833
+ var onComplete = function onComplete(index, resultValue) {
834
+ completed++;
835
+ results[index] = resultValue;
836
+ setTaskCompleteProgress(completed, count);
837
+ if (completed === count) {
838
+ resolve(results);
839
+ }
840
+ };
841
+ var onProgress = function onProgress(promise, index) {
842
+ if (_instanceof(promise, AssetPromise) || _instanceof(promise, Promise)) {
843
+ promise.then(function(value) {
844
+ onComplete(index, value);
845
+ }, reject);
846
+ } else {
847
+ Promise.resolve().then(function() {
848
+ onComplete(index, promise);
849
+ });
850
+ }
851
+ };
852
+ var count = Array.from(values).length;
853
+ var results = new Array(count);
854
+ var completed = 0;
855
+ if (count === 0) {
856
+ return resolve(results);
857
+ }
858
+ for(var i = 0; i < count; i++){
859
+ onProgress(values[i], i);
860
+ }
861
+ });
862
+ };
863
+ _create_class(AssetPromise, [
864
+ {
865
+ key: Symbol.toStringTag,
866
+ get: /** compatible with Promise */ function get() {
867
+ return "AssetPromise";
868
+ }
869
+ }
870
+ ]);
871
+ return AssetPromise;
872
+ }();
873
+
694
874
  /**
695
875
  * Access operating system, platform and hardware information.
696
876
  */ var SystemInfo = /*#__PURE__*/ function() {
@@ -794,6 +974,27 @@ var Logger = {
794
974
  }
795
975
  return this._simdSupported;
796
976
  };
977
+ SystemInfo._checkWebpSupported = function _checkWebpSupported() {
978
+ var _this = this;
979
+ if (!this._webpSupported) {
980
+ this._webpSupported = new AssetPromise(function(resolve) {
981
+ if (_this._isBrowser) {
982
+ var img = new Image();
983
+ img.onload = function() {
984
+ var result = img.width > 0 && img.height > 0;
985
+ resolve(result);
986
+ };
987
+ img.onerror = function() {
988
+ resolve(false);
989
+ };
990
+ img.src = "data:image/webp;base64,UklGRhACAABXRUJQVlA4WAoAAAAwAAAAAAAAAAAASUNDUMgBAAAAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADZBTFBIAgAAAAAAVlA4IBgAAAAwAQCdASoBAAEAAUAmJaQAA3AA/v02aAA=";
991
+ } else {
992
+ resolve(false);
993
+ }
994
+ });
995
+ }
996
+ return this._webpSupported;
997
+ };
797
998
  /**
798
999
  * Checks whether the system supports the given texture format.
799
1000
  * @param format - The texture format
@@ -847,6 +1048,7 @@ var Logger = {
847
1048
  /** The operating system is running on. */ SystemInfo.operatingSystem = "";
848
1049
  /** @internal */ SystemInfo._isBrowser = true;
849
1050
  /** Whether the system support SIMD. */ SystemInfo._simdSupported = null;
1051
+ SystemInfo._webpSupported = null;
850
1052
  SystemInfo._initialize();
851
1053
 
852
1054
  /**
@@ -23327,186 +23529,6 @@ var SafeLoopArray = /*#__PURE__*/ function() {
23327
23529
  return SceneManager;
23328
23530
  }();
23329
23531
 
23330
- var AssetPromise = /*#__PURE__*/ function() {
23331
- function AssetPromise(executor) {
23332
- var _this = this;
23333
- this._state = "pending";
23334
- this._onTaskCompleteCallbacks = [];
23335
- this._onTaskDetailCallbacks = [];
23336
- this._promise = new Promise(function(resolve, reject) {
23337
- _this._reject = reject;
23338
- var onResolve = function(value) {
23339
- if (_this._state === "pending") {
23340
- resolve(value);
23341
- _this._state = "fulfilled";
23342
- _this._onTaskCompleteCallbacks = undefined;
23343
- _this._onTaskDetailCallbacks = undefined;
23344
- }
23345
- };
23346
- var onReject = function(reason) {
23347
- if (_this._state === "pending") {
23348
- reject(reason);
23349
- _this._state = "rejected";
23350
- _this._onTaskCompleteCallbacks = undefined;
23351
- _this._onTaskDetailCallbacks = undefined;
23352
- }
23353
- };
23354
- var onCancel = function(callback) {
23355
- if (_this._state === "pending") {
23356
- _this._onCancelHandler = callback;
23357
- }
23358
- };
23359
- var setTaskCompleteProgress = function(loaded, total) {
23360
- if (_this._state === "pending") {
23361
- var progress = _this._taskCompleteProgress || (_this._taskCompleteProgress = {
23362
- loaded: loaded,
23363
- total: total
23364
- });
23365
- progress.loaded = loaded;
23366
- progress.total = total;
23367
- _this._onTaskCompleteCallbacks.forEach(function(callback) {
23368
- return callback(loaded, total);
23369
- });
23370
- }
23371
- };
23372
- var setTaskDetailProgress = function(url, loaded, total) {
23373
- if (_this._state === "pending") {
23374
- var _this__taskDetailProgress, _url;
23375
- _this._taskDetailProgress || (_this._taskDetailProgress = {});
23376
- var progress = (_this__taskDetailProgress = _this._taskDetailProgress)[_url = url] || (_this__taskDetailProgress[_url] = {
23377
- loaded: loaded,
23378
- total: total
23379
- });
23380
- progress.loaded = loaded;
23381
- progress.total = total;
23382
- _this._onTaskDetailCallbacks.forEach(function(callback) {
23383
- return callback(url, loaded, total);
23384
- });
23385
- }
23386
- };
23387
- executor(onResolve, onReject, setTaskCompleteProgress, setTaskDetailProgress, onCancel);
23388
- });
23389
- }
23390
- var _proto = AssetPromise.prototype;
23391
- /**
23392
- * Progress callback.
23393
- * @param onTaskComplete - This callback function provides information about the overall progress of the task. For example, in batch processing tasks, you can use the loaded and total parameters to calculate the percentage of task completion or display a progress bar
23394
- * @param onTaskDetail - This callback function provides detailed progress information about the task. For instance, in file downloading scenarios, you can use the loaded and total parameters to calculate the download progress percentage and utilize the url parameter to provide additional details such as download speed and estimated remaining time
23395
- * @returns AssetPromise
23396
- */ _proto.onProgress = function onProgress(onTaskComplete, onTaskDetail) {
23397
- var completeProgress = this._taskCompleteProgress;
23398
- var detailProgress = this._taskDetailProgress;
23399
- if (completeProgress) {
23400
- onTaskComplete(completeProgress.loaded, completeProgress.total);
23401
- }
23402
- if (detailProgress) {
23403
- for(var url in detailProgress){
23404
- var _detailProgress_url = detailProgress[url], loaded = _detailProgress_url.loaded, total = _detailProgress_url.total;
23405
- onTaskDetail(url, loaded, total);
23406
- }
23407
- }
23408
- if (this._state === "pending") {
23409
- onTaskComplete && this._onTaskCompleteCallbacks.push(onTaskComplete);
23410
- onTaskDetail && this._onTaskDetailCallbacks.push(onTaskDetail);
23411
- }
23412
- return this;
23413
- };
23414
- _proto.then = function then(onfulfilled, onrejected) {
23415
- var _this = this;
23416
- return new AssetPromise(function(resolve, reject) {
23417
- _this._promise.then(onfulfilled, onrejected).then(resolve).catch(reject);
23418
- });
23419
- };
23420
- /**
23421
- * Attaches a callback for only the rejection of the Promise.
23422
- * @param onRejected - The callback to execute when the Promise is rejected.
23423
- * @returns A Promise for the completion of the callback.
23424
- */ _proto.catch = function _catch(onRejected) {
23425
- var _this = this;
23426
- return new AssetPromise(function(resolve, reject) {
23427
- _this._promise.catch(onRejected).then(resolve).catch(reject);
23428
- });
23429
- };
23430
- /**
23431
- * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
23432
- * resolved value cannot be modified from the callback.
23433
- * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
23434
- * @returns A Promise for the completion of the callback.
23435
- */ _proto.finally = function _finally(onFinally) {
23436
- return this._promise.finally(onFinally);
23437
- };
23438
- /**
23439
- * Cancel promise request.
23440
- * @returns Asset promise
23441
- */ _proto.cancel = function cancel() {
23442
- if (this._state !== "pending") {
23443
- return;
23444
- }
23445
- this._state = "canceled";
23446
- this._reject("canceled");
23447
- this._onCancelHandler && this._onCancelHandler();
23448
- return this;
23449
- };
23450
- AssetPromise.resolve = function resolve(value) {
23451
- if (value === undefined) {
23452
- return new AssetPromise(function(resolve) {
23453
- return resolve();
23454
- });
23455
- } else if (_instanceof(value, AssetPromise) || _instanceof(value, Promise)) {
23456
- return new AssetPromise(function(resolve, reject) {
23457
- value.then(function(resolved) {
23458
- return resolve(resolved);
23459
- }, reject);
23460
- });
23461
- } else {
23462
- return new AssetPromise(function(resolve) {
23463
- return resolve(value);
23464
- });
23465
- }
23466
- };
23467
- AssetPromise.all = function all(values) {
23468
- return new AssetPromise(function(resolve, reject, setTaskCompleteProgress) {
23469
- var onComplete = function onComplete(index, resultValue) {
23470
- completed++;
23471
- results[index] = resultValue;
23472
- setTaskCompleteProgress(completed, count);
23473
- if (completed === count) {
23474
- resolve(results);
23475
- }
23476
- };
23477
- var onProgress = function onProgress(promise, index) {
23478
- if (_instanceof(promise, AssetPromise) || _instanceof(promise, Promise)) {
23479
- promise.then(function(value) {
23480
- onComplete(index, value);
23481
- }, reject);
23482
- } else {
23483
- Promise.resolve().then(function() {
23484
- onComplete(index, promise);
23485
- });
23486
- }
23487
- };
23488
- var count = Array.from(values).length;
23489
- var results = new Array(count);
23490
- var completed = 0;
23491
- if (count === 0) {
23492
- return resolve(results);
23493
- }
23494
- for(var i = 0; i < count; i++){
23495
- onProgress(values[i], i);
23496
- }
23497
- });
23498
- };
23499
- _create_class(AssetPromise, [
23500
- {
23501
- key: Symbol.toStringTag,
23502
- get: /** compatible with Promise */ function get() {
23503
- return "AssetPromise";
23504
- }
23505
- }
23506
- ]);
23507
- return AssetPromise;
23508
- }();
23509
-
23510
23532
  var mimeType = {
23511
23533
  json: "json",
23512
23534
  gltf: "json",
@@ -36638,7 +36660,8 @@ __decorate([
36638
36660
  // Based on the specific version of the engine implementation, when actualBoundingBoxLeft is not supported, width is used to represent the rendering width, and `textAlign` uses the default value `start` and direction is left to right.
36639
36661
  // Some devices do not support actualBoundingBoxLeft and actualBoundingBoxRight in TextMetrics.
36640
36662
  // Examples: Google Pixel 2 XL (Android 11), Honor 6X (Android 8).
36641
- if (!("actualBoundingBoxLeft" in TextMetrics.prototype)) {
36663
+ // In WeChat Mini Games, TextMetrics may be reported as not defined, so a check for window.TextMetrics is added.
36664
+ if (window.TextMetrics && !("actualBoundingBoxLeft" in TextMetrics.prototype)) {
36642
36665
  Object.defineProperties(TextMetrics.prototype, {
36643
36666
  actualBoundingBoxLeft: {
36644
36667
  get: function get() {