@eva/plugin-renderer-lottie 2.0.1-beta.3 → 2.0.1-beta.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.
@@ -62,6 +62,7 @@ export declare class LottieSystem extends Renderer {
62
62
  init(): void;
63
63
  componentChanged(changed: ComponentChanged): Promise<void>;
64
64
  add(changed: ComponentChanged): Promise<void>;
65
+ getDir(url: string): string;
65
66
  remove(changed: ComponentChanged): void;
66
67
  }
67
68
 
@@ -1,6 +1,6 @@
1
1
  import { decorators, OBSERVER_TYPE, resource, Component } from '@eva/eva.js';
2
2
  import { Renderer } from '@eva/plugin-renderer';
3
- import { UPDATE_PRIORITY, Ticker, Container, Texture as Texture$1, Graphics, Matrix as Matrix$1, Sprite, Rectangle, EventEmitter, Text, TextStyle } from 'pixi.js';
3
+ import { UPDATE_PRIORITY, Ticker, Container, Texture, Graphics, Matrix as Matrix$1, Sprite, Assets, Text, TextStyle } from 'pixi.js';
4
4
  import iOSVersion from 'ios-version';
5
5
 
6
6
  /*! *****************************************************************************
@@ -10557,8 +10557,6 @@ function createSizedArray(len) {
10557
10557
  return Array.apply(null, { length: len });
10558
10558
  }
10559
10559
 
10560
- window.$commands = [];
10561
-
10562
10560
  class MatrixHelper extends Matrix$1 {
10563
10561
  reset() {
10564
10562
  // 重置为单位矩阵
@@ -11089,18 +11087,17 @@ class SpriteElement extends Sprite {
11089
11087
  * @param {object} config layer data information
11090
11088
  */
11091
11089
  constructor(lottieLayer, imageInfo) {
11092
- const { asset, texture } = imageInfo;
11093
- super(texture.baseTexture.texture);
11090
+ const { texture: texturePromise } = imageInfo;
11091
+ super();
11094
11092
  this.label = lottieLayer.fullname;
11095
11093
 
11096
- if (texture.baseTexture.texture.valid) {
11097
- texture.baseTexture.texture.orig = new Rectangle(0, 0, asset.w, asset.h);
11098
- } else {
11099
- texture.baseTexture.on('loaded', () => {
11100
- this.texture = texture.baseTexture.texture;
11101
- texture.baseTexture.texture.orig = new Rectangle(0, 0, asset.w, asset.h);
11094
+ texturePromise
11095
+ .then(texture => {
11096
+ this.texture = texture;
11097
+ })
11098
+ .catch(e => {
11099
+ console.error(e);
11102
11100
  });
11103
- }
11104
11101
 
11105
11102
  this.lottieLayer = lottieLayer;
11106
11103
 
@@ -11173,32 +11170,6 @@ class SpriteElement extends Sprite {
11173
11170
  }
11174
11171
  }
11175
11172
 
11176
- class BaseTexture extends EventEmitter {
11177
- constructor(url) {
11178
- super();
11179
- this.texture = Texture$1.EMPTY;
11180
- this.img = new Image();
11181
- this.img.src = url;
11182
- this.img.onload = () => {
11183
- this.texture = Texture$1.from(this.img);
11184
- this.emit('loaded');
11185
- };
11186
- this.img.onerror = () => {
11187
- this.emit('error');
11188
- };
11189
- }
11190
- }
11191
-
11192
- class Texture {
11193
- constructor(url) {
11194
- this.baseTexture = new BaseTexture(url);
11195
- }
11196
-
11197
- static from(url) {
11198
- return new Texture(url);
11199
- }
11200
- }
11201
-
11202
11173
  const regHttp = /^(https?:)?\/\//;
11203
11174
 
11204
11175
  /**
@@ -11254,25 +11225,20 @@ class LoadTexture extends Eventer {
11254
11225
  this.assets.forEach(asset => {
11255
11226
  const id = asset.id;
11256
11227
  const url = createUrl(asset, this.prefix);
11257
- const texture = url ? Texture.from(url, this.textureOptions) : Texture.EMPTY;
11258
- this.textures[id] = texture;
11228
+ const texturePromise = Assets.load(url);
11229
+ this.textures[id] = texturePromise;
11259
11230
  this._total++;
11260
- if (texture.baseTexture.valid || texture === Texture.EMPTY) {
11261
- this._received++;
11262
- this.emit('update');
11263
- if (this._received + this._failed >= this._total) this._onComplete();
11264
- } else {
11265
- texture.baseTexture.once('loaded', () => {
11231
+ texturePromise
11232
+ .then(() => {
11266
11233
  this._received++;
11267
11234
  this.emit('update');
11268
11235
  if (this._received + this._failed >= this._total) this._onComplete();
11269
- });
11270
- texture.baseTexture.once('error', () => {
11236
+ })
11237
+ .catch(e => {
11271
11238
  this._failed++;
11272
11239
  this.emit('update');
11273
11240
  if (this._received + this._failed >= this._total) this._onComplete();
11274
11241
  });
11275
- }
11276
11242
  });
11277
11243
  }
11278
11244
 
@@ -11820,7 +11786,8 @@ class AnimationGroup extends Eventer {
11820
11786
  },
11821
11787
  };
11822
11788
  session.fontManager.addChars(data.chars);
11823
- session.fontManager.addFonts(data.fonts, document.body);
11789
+ // @TODO
11790
+ // session.fontManager.addFonts(data.fonts, document.body);
11824
11791
 
11825
11792
  this._buildElements(session);
11826
11793
 
@@ -12284,11 +12251,11 @@ class AnimationGroup extends Eventer {
12284
12251
  * @param {*} image url | texture
12285
12252
  * @return {this}
12286
12253
  */
12287
- replaceImageByQuerySelector(selector, image = Texture$1.EMPTY) {
12254
+ replaceImageByQuerySelector(selector, image = Texture.EMPTY) {
12288
12255
  const layerDisplay = this.getDisplayByQuerySelector(selector);
12289
12256
  if (layerDisplay && layerDisplay.isSprite) {
12290
12257
  const texture =
12291
- typeof image === 'string' ? Texture$1.from(image, { resourceOptions: { crossorigin: '*' } }) : image;
12258
+ typeof image === 'string' ? Texture.from(image, { resourceOptions: { crossorigin: '*' } }) : image;
12292
12259
  layerDisplay.texture = texture;
12293
12260
  }
12294
12261
  return this;
@@ -12301,7 +12268,7 @@ class AnimationGroup extends Eventer {
12301
12268
  * @param {*} image url | texture or array[url | texture]
12302
12269
  * @return {this}
12303
12270
  */
12304
- replaceImageByQuerySelectorAll(selector, image = [Texture$1.EMPTY]) {
12271
+ replaceImageByQuerySelectorAll(selector, image = [Texture.EMPTY]) {
12305
12272
  const layers = this.querySelectorAll(selector);
12306
12273
  const isArrImage = Tools.isArray(image);
12307
12274
  layers.forEach((layer, idx) => {
@@ -12310,7 +12277,7 @@ class AnimationGroup extends Eventer {
12310
12277
  const imageItem = isArrImage ? image[idx] : image;
12311
12278
  const texture =
12312
12279
  typeof imageItem === 'string'
12313
- ? Texture$1.from(imageItem, { resourceOptions: { crossorigin: '*' } })
12280
+ ? Texture.from(imageItem, { resourceOptions: { crossorigin: '*' } })
12314
12281
  : imageItem;
12315
12282
  layerDisplay.texture = texture;
12316
12283
  }
@@ -12876,7 +12843,7 @@ class AnimationManager extends Eventer {
12876
12843
  }
12877
12844
  }
12878
12845
 
12879
- const { major } = iOSVersion(window.navigator.userAgent) || {};
12846
+ const { major } = iOSVersion(globalThis.navigator.userAgent) || {};
12880
12847
 
12881
12848
  /**
12882
12849
  * dataURL 转成 blob
@@ -12962,14 +12929,16 @@ let LottieSystem = class LottieSystem extends Renderer {
12962
12929
  if (!container)
12963
12930
  return;
12964
12931
  const _a = component.options, { resource: rn } = _a, otherOpts = __rest(_a, ["resource"]);
12965
- const { data } = yield resource.getResource(rn);
12932
+ const res = yield resource.getResource(rn);
12933
+ const data = res.data;
12934
+ const url = res.src.json.url;
12966
12935
  const json = Object.assign({}, (data.json || {}));
12967
12936
  const assets = json.assets || [];
12968
12937
  assets.forEach(item => {
12969
12938
  if (item.p)
12970
12939
  item.p = imageHandle(item.p);
12971
12940
  });
12972
- const anim = this.manager.parseAnimation(Object.assign({ keyframes: json }, otherOpts));
12941
+ const anim = this.manager.parseAnimation(Object.assign({ keyframes: json, prefix: this.getDir(url) }, otherOpts));
12973
12942
  component.anim = anim;
12974
12943
  container.addChildAt(anim.group, 0);
12975
12944
  this.managerLife.forEach(eventName => {
@@ -12979,6 +12948,9 @@ let LottieSystem = class LottieSystem extends Renderer {
12979
12948
  component.emit('success', {});
12980
12949
  });
12981
12950
  }
12951
+ getDir(url) {
12952
+ return new URL('./', url).href;
12953
+ }
12982
12954
  remove(changed) {
12983
12955
  const component = changed.component;
12984
12956
  const container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
@@ -13031,7 +13003,10 @@ class Lottie extends Component {
13031
13003
  this.currentSlot[name] = Sprite.from(value);
13032
13004
  }
13033
13005
  else if (type === 'TEXT') {
13034
- this.currentSlot[name] = new Text(value, new TextStyle(style));
13006
+ this.currentSlot[name] = new Text({
13007
+ text: value,
13008
+ style: new TextStyle(style),
13009
+ });
13035
13010
  }
13036
13011
  if (x)
13037
13012
  this.currentSlot[name].x = x;
@@ -13066,9 +13041,7 @@ class Lottie extends Component {
13066
13041
  this.on('success', () => {
13067
13042
  const ele = this.anim.querySelector(name);
13068
13043
  const display = ele.display;
13069
- g.beginFill(0xffffff);
13070
- g.drawRect(0, 0, 100, 100);
13071
- g.endFill();
13044
+ g.rect(0, 0, 100, 100).fill(0xffffff);
13072
13045
  g.alpha = 0;
13073
13046
  display.addChild(g);
13074
13047
  ele.display.interactive = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-lottie",
3
- "version": "2.0.1-beta.3",
3
+ "version": "2.0.1-beta.5",
4
4
  "description": "@eva/plugin-renderer-lottie",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-lottie.esm.js",
@@ -18,8 +18,8 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/eva.js": "2.0.1-beta.3",
22
- "@eva/plugin-renderer": "2.0.1-beta.3",
21
+ "@eva/eva.js": "2.0.1-beta.5",
22
+ "@eva/plugin-renderer": "2.0.1-beta.5",
23
23
  "ios-version": "^1.0.1",
24
24
  "pixi.js": "^8.8.1"
25
25
  }