@babylonjs/lottie-player 8.24.1 → 8.25.0
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/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/localPlayer.d.ts +4 -3
- package/localPlayer.d.ts.map +1 -1
- package/localPlayer.js +10 -4
- package/localPlayer.js.map +1 -1
- package/messageTypes.d.ts +3 -0
- package/messageTypes.d.ts.map +1 -1
- package/package.json +1 -1
- package/player.d.ts +5 -3
- package/player.d.ts.map +1 -1
- package/player.js +61 -38
- package/player.js.map +1 -1
- package/worker.js +12 -8
- package/worker.js.map +1 -1
package/index.d.ts
CHANGED
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/localPlayer.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AnimationConfiguration } from "./animationConfiguration.js";
|
|
2
|
+
import type { RawLottieAnimation } from "./parsing/rawTypes.js";
|
|
2
3
|
/**
|
|
3
4
|
* Allows you to play Lottie animations using Babylon.js.
|
|
4
5
|
* It plays the animations in the main JS thread. Prefer to use Player instead if Offscreen canvas and worker threads are supported.
|
|
@@ -6,7 +7,7 @@ import type { AnimationConfiguration } from "./animationConfiguration.js";
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class LocalPlayer {
|
|
8
9
|
private readonly _container;
|
|
9
|
-
private readonly
|
|
10
|
+
private readonly _animationSource;
|
|
10
11
|
private readonly _variables;
|
|
11
12
|
private readonly _configuration;
|
|
12
13
|
private _rawAnimation;
|
|
@@ -19,11 +20,11 @@ export declare class LocalPlayer {
|
|
|
19
20
|
/**
|
|
20
21
|
* Creates a new instance of the LottiePlayer.
|
|
21
22
|
* @param container The HTMLDivElement to create the canvas in and render the animation on.
|
|
22
|
-
* @param
|
|
23
|
+
* @param animationSource The URL of the Lottie animation file to be played, or a parsed Lottie JSON object.
|
|
23
24
|
* @param variables Optional map of variables to replace in the animation file.
|
|
24
25
|
* @param configuration Optional configuration object to customize the animation playback.
|
|
25
26
|
*/
|
|
26
|
-
constructor(container: HTMLDivElement,
|
|
27
|
+
constructor(container: HTMLDivElement, animationSource: string | RawLottieAnimation, variables?: Map<string, string>, configuration?: Partial<AnimationConfiguration>);
|
|
27
28
|
/**
|
|
28
29
|
* Loads and plays a lottie animation.
|
|
29
30
|
* @returns True if the animation is successfully set up to play, false if the animation couldn't play.
|
package/localPlayer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localPlayer.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/localPlayer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"localPlayer.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/localPlayer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAK7D;;;;GAIG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8B;IAC/D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IACjD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAkC;IAEjE,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,eAAe,CAA+B;IACtD,OAAO,CAAC,oBAAoB,CAAoC;IAEhE;;;;;;OAMG;gBACgB,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,GAAG,kBAAkB,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC;IAO5K;;;OAGG;IACU,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IA4DnD;;OAEG;IACI,OAAO,IAAI,IAAI;IAgBtB,OAAO,CAAC,eAAe,CAUrB;CACL"}
|
package/localPlayer.js
CHANGED
|
@@ -10,11 +10,11 @@ export class LocalPlayer {
|
|
|
10
10
|
/**
|
|
11
11
|
* Creates a new instance of the LottiePlayer.
|
|
12
12
|
* @param container The HTMLDivElement to create the canvas in and render the animation on.
|
|
13
|
-
* @param
|
|
13
|
+
* @param animationSource The URL of the Lottie animation file to be played, or a parsed Lottie JSON object.
|
|
14
14
|
* @param variables Optional map of variables to replace in the animation file.
|
|
15
15
|
* @param configuration Optional configuration object to customize the animation playback.
|
|
16
16
|
*/
|
|
17
|
-
constructor(container,
|
|
17
|
+
constructor(container, animationSource, variables, configuration) {
|
|
18
18
|
this._rawAnimation = undefined;
|
|
19
19
|
this._scaleFactor = 1;
|
|
20
20
|
this._playing = false;
|
|
@@ -32,7 +32,7 @@ export class LocalPlayer {
|
|
|
32
32
|
this._animationController.setScale(this._scaleFactor);
|
|
33
33
|
};
|
|
34
34
|
this._container = container;
|
|
35
|
-
this.
|
|
35
|
+
this._animationSource = animationSource;
|
|
36
36
|
this._variables = variables ?? new Map();
|
|
37
37
|
this._configuration = configuration ?? {};
|
|
38
38
|
}
|
|
@@ -44,7 +44,13 @@ export class LocalPlayer {
|
|
|
44
44
|
if (this._playing || this._disposed) {
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
// Load the animation from URL or use the provided parsed JSON
|
|
48
|
+
if (typeof this._animationSource === "string") {
|
|
49
|
+
this._rawAnimation = await GetRawAnimationDataAsync(this._animationSource);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this._rawAnimation = this._animationSource;
|
|
53
|
+
}
|
|
48
54
|
// Create the canvas element
|
|
49
55
|
this._canvas = document.createElement("canvas");
|
|
50
56
|
// Center the canvas in the container
|
package/localPlayer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localPlayer.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/localPlayer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"localPlayer.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/localPlayer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAE5F;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAcpB;;;;;;OAMG;IACH,YAAmB,SAAyB,EAAE,eAA4C,EAAE,SAA+B,EAAE,aAA+C;QAfpK,kBAAa,GAAmC,SAAS,CAAC;QAC1D,iBAAY,GAAW,CAAC,CAAC;QACzB,aAAQ,GAAG,KAAK,CAAC;QACjB,cAAS,GAAG,K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,CAAC;IAED;;OAEG;IACI,OAAO;QACV,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAE3D,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACvB,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC;YAClC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAChC,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACxB,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1B,CAAC;CAaJ"}
|
package/messageTypes.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Nullable } from "@babylonjs/core/types.js";
|
|
2
2
|
import type { AnimationConfiguration } from "./animationConfiguration.js";
|
|
3
|
+
import type { RawLottieAnimation } from "./parsing/rawTypes.js";
|
|
3
4
|
/**
|
|
4
5
|
* Generic type representing a message sent between the main thread and the worker.
|
|
5
6
|
*/
|
|
@@ -71,6 +72,8 @@ export type StartAnimationMessagePayload = {
|
|
|
71
72
|
variables: Nullable<Map<string, string>>;
|
|
72
73
|
/** Optional configuration object to customize the animation playback. */
|
|
73
74
|
configuration: Nullable<Partial<AnimationConfiguration>>;
|
|
75
|
+
/** The parsed lottie animation if it is available */
|
|
76
|
+
animationData?: RawLottieAnimation;
|
|
74
77
|
};
|
|
75
78
|
/** Payload for the "containerResize" message type */
|
|
76
79
|
export type ContainerResizeMessagePayload = {
|
package/messageTypes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageTypes.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/messageTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,iCAAmB;AAC3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kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,qDAAqD;AACrD,MAAM,MAAM,4BAA4B,GAAG;IACvC,qDAAqD;IACrD,MAAM,EAAE,eAAe,CAAC;IACxB,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACzC,yEAAyE;IACzE,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC;IACzD,qDAAqD;IACrD,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACtC,CAAC;AAEF,qDAAqD;AACrD,MAAM,MAAM,6BAA6B,GAAG;IACxC,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AAElG;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,0BAA0B,GAAG,2BAA2B,GAAG,4BAA4B,GAAG,6BAA6B,CAAC"}
|
package/package.json
CHANGED
package/player.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Nullable } from "@babylonjs/core/types.js";
|
|
2
2
|
import type { AnimationConfiguration } from "./animationConfiguration.js";
|
|
3
|
+
import type { RawLottieAnimation } from "./parsing/rawTypes.js";
|
|
3
4
|
/**
|
|
4
5
|
* Allows you to play Lottie animations using Babylon.js.
|
|
5
6
|
* It plays the animations in a worker thread using OffscreenCanvas.
|
|
@@ -7,7 +8,7 @@ import type { AnimationConfiguration } from "./animationConfiguration.js";
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class Player {
|
|
9
10
|
private readonly _container;
|
|
10
|
-
private readonly
|
|
11
|
+
private readonly _animationSource;
|
|
11
12
|
private readonly _variables;
|
|
12
13
|
private readonly _configuration;
|
|
13
14
|
private _playing;
|
|
@@ -21,11 +22,11 @@ export declare class Player {
|
|
|
21
22
|
/**
|
|
22
23
|
* Creates a new instance of the LottiePlayer.
|
|
23
24
|
* @param container The HTMLDivElement to create the canvas in and render the animation on.
|
|
24
|
-
* @param
|
|
25
|
+
* @param animationSource The URL of the Lottie animation file to be played, or a parsed Lottie JSON object.
|
|
25
26
|
* @param variables Optional map of variables to replace in the animation file.
|
|
26
27
|
* @param configuration Optional configuration object to customize the animation playback.
|
|
27
28
|
*/
|
|
28
|
-
constructor(container: HTMLDivElement,
|
|
29
|
+
constructor(container: HTMLDivElement, animationSource: string | RawLottieAnimation, variables?: Nullable<Map<string, string>>, configuration?: Nullable<Partial<AnimationConfiguration>>);
|
|
29
30
|
/**
|
|
30
31
|
* Loads and plays a lottie animation using a webworker and offscreen canvas.
|
|
31
32
|
* If OffscreenCanvas is not supported by the browser, the animation will not play. Try using LocalLottiePlayer instead.
|
|
@@ -36,6 +37,7 @@ export declare class Player {
|
|
|
36
37
|
* Disposes the LottiePlayer instance, cleaning up resources and event listeners.
|
|
37
38
|
*/
|
|
38
39
|
dispose(): void;
|
|
40
|
+
private _createPlayerAndStartAnimation;
|
|
39
41
|
private _onWindowResize;
|
|
40
42
|
private _onBeforeUnload;
|
|
41
43
|
}
|
package/player.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/player.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,iCAAmB;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/player.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,iCAAmB;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG7D;;;;GAIG;AACH,qBAAa,MAAM;IACf,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8B;IAC/D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgC;IAC3D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4C;IAE3E,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,gBAAgB,CAAa;IACrC,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,eAAe,CAAkC;IAEzD;;;;;;OAMG;gBAEC,SAAS,EAAE,cAAc,EACzB,eAAe,EAAE,MAAM,GAAG,kBAAkB,EAC5C,SAAS,GAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAQ,EAC/C,aAAa,GAAE,QAAQ,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAQ;IAQnE;;;;OAIG;IACI,aAAa,IAAI,OAAO;IAuE/B;;OAEG;IACI,OAAO,IAAI,IAAI;IAmBtB,OAAO,CAAC,8BAA8B;IA8CtC,OAAO,CAAC,eAAe,CASrB;IAEF,OAAO,CAAC,eAAe,CAGrB;CACL"}
|
package/player.js
CHANGED
|
@@ -8,11 +8,11 @@ export class Player {
|
|
|
8
8
|
/**
|
|
9
9
|
* Creates a new instance of the LottiePlayer.
|
|
10
10
|
* @param container The HTMLDivElement to create the canvas in and render the animation on.
|
|
11
|
-
* @param
|
|
11
|
+
* @param animationSource The URL of the Lottie animation file to be played, or a parsed Lottie JSON object.
|
|
12
12
|
* @param variables Optional map of variables to replace in the animation file.
|
|
13
13
|
* @param configuration Optional configuration object to customize the animation playback.
|
|
14
14
|
*/
|
|
15
|
-
constructor(container,
|
|
15
|
+
constructor(container, animationSource, variables = null, configuration = null) {
|
|
16
16
|
this._playing = false;
|
|
17
17
|
this._disposed = false;
|
|
18
18
|
this._worker = null;
|
|
@@ -34,7 +34,7 @@ export class Player {
|
|
|
34
34
|
this._worker = null;
|
|
35
35
|
};
|
|
36
36
|
this._container = container;
|
|
37
|
-
this.
|
|
37
|
+
this._animationSource = animationSource;
|
|
38
38
|
this._variables = variables;
|
|
39
39
|
this._configuration = configuration;
|
|
40
40
|
}
|
|
@@ -59,45 +59,25 @@ export class Player {
|
|
|
59
59
|
if (this._worker === null) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
this._animationWidth = payload.width;
|
|
64
|
-
this._animationHeight = payload.height;
|
|
65
|
-
// Create the canvas element
|
|
66
|
-
this._canvas = document.createElement("canvas");
|
|
67
|
-
// Center the canvas in the container
|
|
68
|
-
this._canvas.style.position = "absolute";
|
|
69
|
-
this._canvas.style.left = "50%";
|
|
70
|
-
this._canvas.style.top = "50%";
|
|
71
|
-
this._canvas.style.transform = "translate(-50%, -50%)";
|
|
72
|
-
this._canvas.style.display = "block";
|
|
73
|
-
// The size of the canvas is the relation between the size of the container div and the size of the animation
|
|
74
|
-
this._scaleFactor = CalculateScaleFactor(this._animationWidth, this._animationHeight, this._container);
|
|
75
|
-
this._canvas.style.width = `${this._animationWidth * this._scaleFactor}px`;
|
|
76
|
-
this._canvas.style.height = `${this._animationHeight * this._scaleFactor}px`;
|
|
77
|
-
// Append the canvas to the container
|
|
78
|
-
this._container.appendChild(this._canvas);
|
|
79
|
-
const offscreen = this._canvas.transferControlToOffscreen();
|
|
80
|
-
const startAnimationMessage = {
|
|
81
|
-
type: "startAnimation",
|
|
82
|
-
payload: {
|
|
83
|
-
canvas: offscreen,
|
|
84
|
-
scaleFactor: this._scaleFactor,
|
|
85
|
-
variables: this._variables,
|
|
86
|
-
configuration: this._configuration,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
this._worker.postMessage(startAnimationMessage, [offscreen]);
|
|
62
|
+
this._createPlayerAndStartAnimation(message.payload);
|
|
90
63
|
break;
|
|
91
64
|
}
|
|
92
65
|
}
|
|
93
66
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
67
|
+
if (typeof this._animationSource === "string") {
|
|
68
|
+
// We need to load the animation from a URL in the worker
|
|
69
|
+
const animationUrlMessage = {
|
|
70
|
+
type: "animationUrl",
|
|
71
|
+
payload: {
|
|
72
|
+
url: this._animationSource,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
this._worker.postMessage(animationUrlMessage);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// We have the raw animation data already on this thread
|
|
79
|
+
this._createPlayerAndStartAnimation(this._animationSource);
|
|
80
|
+
}
|
|
101
81
|
window.addEventListener("resize", this._onWindowResize);
|
|
102
82
|
window.addEventListener("beforeunload", this._onBeforeUnload);
|
|
103
83
|
if ("ResizeObserver" in window) {
|
|
@@ -142,5 +122,48 @@ export class Player {
|
|
|
142
122
|
}
|
|
143
123
|
this._disposed = true;
|
|
144
124
|
}
|
|
125
|
+
_createPlayerAndStartAnimation(animationData) {
|
|
126
|
+
if (this._worker === null) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (IsRawLottieAnimation(animationData)) {
|
|
130
|
+
this._animationWidth = animationData.w;
|
|
131
|
+
this._animationHeight = animationData.h;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this._animationWidth = animationData.width;
|
|
135
|
+
this._animationHeight = animationData.height;
|
|
136
|
+
}
|
|
137
|
+
// Create the canvas element
|
|
138
|
+
this._canvas = document.createElement("canvas");
|
|
139
|
+
// Center the canvas in the container
|
|
140
|
+
this._canvas.style.position = "absolute";
|
|
141
|
+
this._canvas.style.left = "50%";
|
|
142
|
+
this._canvas.style.top = "50%";
|
|
143
|
+
this._canvas.style.transform = "translate(-50%, -50%)";
|
|
144
|
+
this._canvas.style.display = "block";
|
|
145
|
+
// The size of the canvas is the relation between the size of the container div and the size of the animation
|
|
146
|
+
this._scaleFactor = CalculateScaleFactor(this._animationWidth, this._animationHeight, this._container);
|
|
147
|
+
this._canvas.style.width = `${this._animationWidth * this._scaleFactor}px`;
|
|
148
|
+
this._canvas.style.height = `${this._animationHeight * this._scaleFactor}px`;
|
|
149
|
+
// Append the canvas to the container
|
|
150
|
+
this._container.appendChild(this._canvas);
|
|
151
|
+
const offscreen = this._canvas.transferControlToOffscreen();
|
|
152
|
+
const startAnimationMessage = {
|
|
153
|
+
type: "startAnimation",
|
|
154
|
+
payload: {
|
|
155
|
+
canvas: offscreen,
|
|
156
|
+
scaleFactor: this._scaleFactor,
|
|
157
|
+
variables: this._variables,
|
|
158
|
+
configuration: this._configuration,
|
|
159
|
+
animationData: IsRawLottieAnimation(animationData) ? animationData : undefined,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
this._worker.postMessage(startAnimationMessage, [offscreen]);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function IsRawLottieAnimation(x) {
|
|
166
|
+
const o = x;
|
|
167
|
+
return !!o && typeof o === "object" && typeof o.w === "number" && typeof o.h === "number" && Array.isArray(o.layers);
|
|
145
168
|
}
|
|
146
169
|
//# sourceMappingURL=player.js.map
|
package/player.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/player.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"player.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/player.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,OAAO,MAAM;IAef;;;;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@@
|
|
|
1
1
|
let RawAnimation = null;
|
|
2
|
-
// Use any type to avoid importing the class at module scope
|
|
3
|
-
// eslint-disable @typescript-eslint/no-explicit-any
|
|
4
2
|
let Controller = null;
|
|
5
3
|
let AnimationPromises = null;
|
|
6
|
-
// eslint-enable @typescript-eslint/no-explicit-any
|
|
7
4
|
onmessage = async function (evt) {
|
|
8
5
|
const message = evt.data;
|
|
9
6
|
if (message === undefined) {
|
|
@@ -28,11 +25,11 @@ onmessage = async function (evt) {
|
|
|
28
25
|
break;
|
|
29
26
|
}
|
|
30
27
|
case "startAnimation": {
|
|
31
|
-
if (
|
|
32
|
-
|
|
28
|
+
if (AnimationPromises === null) {
|
|
29
|
+
AnimationPromises = Promise.all([import("./animationConfiguration.js"), import("./rendering/animationController.js")]);
|
|
33
30
|
}
|
|
34
|
-
const payload = message.payload;
|
|
35
31
|
const [{ DefaultConfiguration }, { AnimationController }] = await AnimationPromises;
|
|
32
|
+
const payload = message.payload;
|
|
36
33
|
const canvas = payload.canvas;
|
|
37
34
|
const scaleFactor = payload.scaleFactor;
|
|
38
35
|
const variables = payload.variables ?? new Map();
|
|
@@ -41,8 +38,15 @@ onmessage = async function (evt) {
|
|
|
41
38
|
...DefaultConfiguration,
|
|
42
39
|
...originalConfig,
|
|
43
40
|
};
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
if (RawAnimation === null && payload.animationData) {
|
|
42
|
+
RawAnimation = payload.animationData;
|
|
43
|
+
}
|
|
44
|
+
if (RawAnimation === null) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const controller = new AnimationController(canvas, RawAnimation, scaleFactor, variables, finalConfig);
|
|
48
|
+
controller.playAnimation();
|
|
49
|
+
Controller = controller;
|
|
46
50
|
break;
|
|
47
51
|
}
|
|
48
52
|
case "containerResize": {
|
package/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/worker.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