@galacean/effects 1.2.6 → 1.3.0-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.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime player for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v1.2.6
6
+ * Version: v1.3.0-alpha.1
7
7
  */
8
8
 
9
9
  'use strict';
@@ -686,7 +686,7 @@ function asserts(condition, msg) {
686
686
  * Name: @galacean/effects-specification
687
687
  * Description: Galacean Effects JSON Specification
688
688
  * Author: Ant Group CO., Ltd.
689
- * Version: v1.0.1
689
+ * Version: v1.1.0-alpha.1
690
690
  */
691
691
 
692
692
  /*********************************************/
@@ -1067,6 +1067,16 @@ var CompositionEndBehavior$1;
1067
1067
  CompositionEndBehavior[CompositionEndBehavior["pause_destroy"] = END_BEHAVIOR_PAUSE_AND_DESTROY$1] = "pause_destroy";
1068
1068
  })(CompositionEndBehavior$1 || (CompositionEndBehavior$1 = {}));
1069
1069
 
1070
+ /**
1071
+ * 动态换图类型
1072
+ * @since 1.3.0
1073
+ */
1074
+ var BackgroundType$1;
1075
+ (function (BackgroundType) {
1076
+ BackgroundType["video"] = "video";
1077
+ BackgroundType["image"] = "image";
1078
+ })(BackgroundType$1 || (BackgroundType$1 = {}));
1079
+
1070
1080
  /*********************************************/
1071
1081
  /* 基本数值属性参数 */
1072
1082
  /*********************************************/
@@ -1356,6 +1366,7 @@ var FontStyle$1;
1356
1366
 
1357
1367
  var index$1 = /*#__PURE__*/Object.freeze({
1358
1368
  __proto__: null,
1369
+ get BackgroundType () { return BackgroundType$1; },
1359
1370
  get BezierKeyframeType () { return BezierKeyframeType$1; },
1360
1371
  get BlendingMode () { return BlendingMode$1; },
1361
1372
  BloomFilterThresholdAvgColor: BloomFilterThresholdAvgColor,
@@ -10153,10 +10164,8 @@ function loadBlob(url) {
10153
10164
  /**
10154
10165
  * 异步加载一个视频文件
10155
10166
  * @param url - 视频文件的 URL 或 MediaProvider 对象
10156
- * @param options - 加载参数
10157
10167
  */
10158
- function loadVideo(url, options) {
10159
- if (options === void 0) { options = {}; }
10168
+ function loadVideo(url) {
10160
10169
  return __awaiter(this, void 0, void 0, function () {
10161
10170
  var video;
10162
10171
  return __generator(this, function (_a) {
@@ -10169,9 +10178,6 @@ function loadVideo(url, options) {
10169
10178
  }
10170
10179
  video.crossOrigin = 'anonymous';
10171
10180
  video.muted = true;
10172
- if (options.loop) {
10173
- video.addEventListener('ended', function () { return video.play(); });
10174
- }
10175
10181
  if (isAndroid()) {
10176
10182
  video.setAttribute('renderer', 'standard');
10177
10183
  }
@@ -19660,6 +19666,26 @@ function getBackgroundImage(template, variables) {
19660
19666
  }
19661
19667
  return templateBackground;
19662
19668
  }
19669
+ function loadMedia(url, loadFn) {
19670
+ return __awaiter(this, void 0, void 0, function () {
19671
+ return __generator(this, function (_a) {
19672
+ switch (_a.label) {
19673
+ case 0:
19674
+ if (!Array.isArray(url)) return [3 /*break*/, 5];
19675
+ _a.label = 1;
19676
+ case 1:
19677
+ _a.trys.push([1, 3, , 5]);
19678
+ return [4 /*yield*/, loadFn(url[0])];
19679
+ case 2: return [2 /*return*/, _a.sent()];
19680
+ case 3:
19681
+ _a.sent();
19682
+ return [4 /*yield*/, loadFn(url[1])];
19683
+ case 4: return [2 /*return*/, _a.sent()];
19684
+ case 5: return [2 /*return*/, loadFn(url)];
19685
+ }
19686
+ });
19687
+ });
19688
+ }
19663
19689
  function drawImageAndTemplate(viewer, image, template, variables, opt) {
19664
19690
  var _a;
19665
19691
  return __awaiter(this, void 0, void 0, function () {
@@ -21551,7 +21577,7 @@ var filters = {
21551
21577
  * Name: @galacean/effects-specification
21552
21578
  * Description: Galacean Effects JSON Specification
21553
21579
  * Author: Ant Group CO., Ltd.
21554
- * Version: v1.0.1
21580
+ * Version: v1.1.0-alpha.1
21555
21581
  */
21556
21582
 
21557
21583
  /*********************************************/
@@ -21930,6 +21956,16 @@ var CompositionEndBehavior;
21930
21956
  CompositionEndBehavior[CompositionEndBehavior["pause_destroy"] = END_BEHAVIOR_PAUSE_AND_DESTROY] = "pause_destroy";
21931
21957
  })(CompositionEndBehavior || (CompositionEndBehavior = {}));
21932
21958
 
21959
+ /**
21960
+ * 动态换图类型
21961
+ * @since 1.3.0
21962
+ */
21963
+ var BackgroundType;
21964
+ (function (BackgroundType) {
21965
+ BackgroundType["video"] = "video";
21966
+ BackgroundType["image"] = "image";
21967
+ })(BackgroundType || (BackgroundType = {}));
21968
+
21933
21969
  /*********************************************/
21934
21970
  /* 基本数值属性参数 */
21935
21971
  /*********************************************/
@@ -23014,11 +23050,9 @@ function getStandardImage(image, index, imageTags) {
23014
23050
  else if (image.url) {
23015
23051
  return {
23016
23052
  url: image.url,
23017
- type: image.type,
23018
23053
  webp: image.webp,
23019
23054
  renderLevel: renderLevel,
23020
23055
  oriY: oriY,
23021
- loop: image.loop,
23022
23056
  };
23023
23057
  }
23024
23058
  else if (image && image.sourceType) {
@@ -23772,79 +23806,61 @@ var AssetManager = /** @class */ (function () {
23772
23806
  _a = this.options, useCompressedTexture = _a.useCompressedTexture, variables = _a.variables;
23773
23807
  baseUrl = this.baseUrl;
23774
23808
  jobs = images.map(function (img, idx) { return __awaiter(_this, void 0, void 0, function () {
23775
- var png, webp, imageURL, webpURL, template, result, url_1, name_1, templateImage, loop, compressed, src, bufferURL, _a, url, image;
23776
- var _b, _c, _d;
23777
- return __generator(this, function (_e) {
23778
- switch (_e.label) {
23809
+ var png, webp, imageURL, webpURL, template, isTemplateV2, background, url_1, isVideo, loadFn, resultImage, resultImage, compressed, src, bufferURL, _a, url, image;
23810
+ return __generator(this, function (_b) {
23811
+ switch (_b.label) {
23779
23812
  case 0:
23780
- if (!usage[idx]) return [3 /*break*/, 19];
23813
+ if (!usage[idx]) {
23814
+ return [2 /*return*/, undefined];
23815
+ }
23781
23816
  png = img.url, webp = img.webp;
23782
23817
  imageURL = new URL(png, baseUrl).href;
23783
23818
  webpURL = webp && new URL(webp, baseUrl).href;
23784
- if (!('template' in img)) return [3 /*break*/, 16];
23819
+ if (!('template' in img)) return [3 /*break*/, 13];
23785
23820
  template = img.template;
23786
- result = void 0;
23787
- if (!('v' in template && template.v === 2 && template.background)) return [3 /*break*/, 9];
23821
+ isTemplateV2 = 'v' in template && template.v === 2 && template.background;
23822
+ background = isTemplateV2 ? template.background : undefined;
23823
+ if (!(isTemplateV2 && background)) return [3 /*break*/, 8];
23788
23824
  url_1 = getBackgroundImage(template, variables);
23789
- if (!(url_1 instanceof Array)) return [3 /*break*/, 6];
23790
- name_1 = template.background.name;
23791
- _e.label = 1;
23825
+ isVideo = background.type === BackgroundType$1.video;
23826
+ loadFn = background && isVideo ? loadVideo : loadImage;
23827
+ _b.label = 1;
23792
23828
  case 1:
23793
- _e.trys.push([1, 3, , 5]);
23794
- _b = {};
23795
- return [4 /*yield*/, loadImage(url_1[0])];
23829
+ _b.trys.push([1, 6, , 7]);
23830
+ return [4 /*yield*/, loadMedia(url_1, loadFn)];
23796
23831
  case 2:
23797
- result = (_b.image = _e.sent(),
23798
- _b.url = url_1[0],
23799
- _b);
23800
- return [3 /*break*/, 5];
23832
+ resultImage = _b.sent();
23833
+ if (!(resultImage instanceof HTMLVideoElement)) return [3 /*break*/, 3];
23834
+ return [2 /*return*/, resultImage];
23801
23835
  case 3:
23802
- _e.sent();
23803
- _c = {};
23804
- return [4 /*yield*/, loadImage(url_1[1])];
23805
- case 4:
23806
- result = (_c.image = _e.sent(),
23807
- _c.url = url_1[1],
23808
- _c);
23809
- return [3 /*break*/, 5];
23810
- case 5:
23811
- if (variables) {
23812
- variables[name_1] = result.url;
23836
+ // 如果是加载图片且是数组,设置变量,视频情况下不需要
23837
+ if (background && !Array.isArray(url_1) && variables) {
23838
+ variables[background.name] = url_1;
23813
23839
  }
23814
- return [3 /*break*/, 8];
23840
+ return [4 /*yield*/, combineImageTemplate(resultImage, template, variables, this.options, img.oriY === -1)];
23841
+ case 4: return [2 /*return*/, _b.sent()];
23842
+ case 5: return [3 /*break*/, 7];
23815
23843
  case 6:
23816
- if (!(typeof url_1 === 'string')) return [3 /*break*/, 8];
23817
- _d = {};
23818
- return [4 /*yield*/, loadImage(url_1)];
23819
- case 7:
23820
- result = (_d.image = _e.sent(),
23821
- _d.url = url_1,
23822
- _d);
23823
- _e.label = 8;
23824
- case 8: return [3 /*break*/, 11];
23825
- case 9: return [4 /*yield*/, loadWebPOptional(imageURL, webpURL)];
23826
- case 10:
23827
- // 测试场景:'年兽大爆炸——8个彩蛋t1'
23828
- result = _e.sent();
23829
- _e.label = 11;
23844
+ _b.sent();
23845
+ throw new Error("Failed to load. Check the template or if the URL is ".concat(isVideo ? 'video' : 'image', " type, URL: ").concat(url_1, "."));
23846
+ case 7: return [3 /*break*/, 12];
23847
+ case 8:
23848
+ _b.trys.push([8, 11, , 12]);
23849
+ return [4 /*yield*/, loadWebPOptional(imageURL, webpURL)];
23850
+ case 9:
23851
+ resultImage = _b.sent();
23852
+ return [4 /*yield*/, combineImageTemplate(resultImage.image, template, variables, this.options, img.oriY === -1)];
23853
+ case 10: return [2 /*return*/, _b.sent()];
23830
23854
  case 11:
23831
- templateImage = void 0;
23832
- _e.label = 12;
23833
- case 12:
23834
- _e.trys.push([12, 14, , 15]);
23835
- return [4 /*yield*/, combineImageTemplate(result.image, template, variables, this.options, img.oriY === -1)];
23855
+ _b.sent();
23856
+ throw new Error("Failed to load. Check the template, URL: ".concat(imageURL, "."));
23857
+ case 12: return [3 /*break*/, 14];
23836
23858
  case 13:
23837
- templateImage = _e.sent();
23838
- return [3 /*break*/, 15];
23839
- case 14:
23840
- _e.sent();
23841
- throw new Error("image template fail: ".concat(imageURL));
23842
- case 15: return [2 /*return*/, templateImage];
23843
- case 16:
23844
23859
  if ('type' in img && img.type === 'video') {
23845
- loop = img.loop;
23846
23860
  // 视频
23847
- return [2 /*return*/, loadVideo(img.url, { loop: loop })];
23861
+ // TODO: 2024.03.28 后面考虑下掉非推荐的视频元素使用方式
23862
+ console.warn('The video element is deprecated. Use template BackgroundType.video instead.');
23863
+ return [2 /*return*/, loadVideo(img.url)];
23848
23864
  }
23849
23865
  else if ('compressed' in img && useCompressedTexture && compressedTexture) {
23850
23866
  compressed = img.compressed;
@@ -23870,13 +23886,12 @@ var AssetManager = /** @class */ (function () {
23870
23886
  img instanceof Texture) {
23871
23887
  return [2 /*return*/, img];
23872
23888
  }
23873
- _e.label = 17;
23874
- case 17: return [4 /*yield*/, loadWebPOptional(imageURL, webpURL)];
23875
- case 18:
23876
- _a = _e.sent(), url = _a.url, image = _a.image;
23889
+ _b.label = 14;
23890
+ case 14: return [4 /*yield*/, loadWebPOptional(imageURL, webpURL)];
23891
+ case 15:
23892
+ _a = _b.sent(), url = _a.url, image = _a.image;
23877
23893
  this.assets[idx] = { url: url, type: exports.TextureSourceType.image };
23878
23894
  return [2 /*return*/, image];
23879
- case 19: return [2 /*return*/, undefined];
23880
23895
  }
23881
23896
  });
23882
23897
  }); });
@@ -24023,10 +24038,10 @@ function createTextureOptionsBySource(image, sourceFrom) {
24023
24038
  }
24024
24039
  throw new Error('Invalid texture options');
24025
24040
  }
24026
- function isCanvas(cavnas) {
24041
+ function isCanvas(canvas) {
24027
24042
  var _a;
24028
24043
  // 小程序 Canvas 无法使用 instanceof HTMLCanvasElement 判断
24029
- return typeof cavnas === 'object' && cavnas !== null && ((_a = cavnas.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'CANVAS';
24044
+ return typeof canvas === 'object' && canvas !== null && ((_a = canvas.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'CANVAS';
24030
24045
  }
24031
24046
 
24032
24047
  var CompVFXItem = /** @class */ (function (_super) {
@@ -30455,7 +30470,7 @@ Renderer.create = function (canvas, framework, renderOptions) {
30455
30470
  Engine.create = function (gl) {
30456
30471
  return new GLEngine(gl);
30457
30472
  };
30458
- var version = "1.2.6";
30473
+ var version = "1.3.0-alpha.1";
30459
30474
  logger.info('player version: ' + version);
30460
30475
 
30461
30476
  exports.AbstractPlugin = AbstractPlugin;
@@ -30661,6 +30676,7 @@ exports.itemVert = itemVert;
30661
30676
  exports.loadBinary = loadBinary;
30662
30677
  exports.loadBlob = loadBlob;
30663
30678
  exports.loadImage = loadImage;
30679
+ exports.loadMedia = loadMedia;
30664
30680
  exports.loadVideo = loadVideo;
30665
30681
  exports.loadWebPOptional = loadWebPOptional;
30666
30682
  exports.logger = logger;