@babylonjs/lottie-player 8.25.1 → 8.25.2
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/blobWorkerWrapper.d.ts +21 -0
- package/blobWorkerWrapper.d.ts.map +1 -0
- package/blobWorkerWrapper.js +35 -0
- package/blobWorkerWrapper.js.map +1 -0
- package/package.json +1 -1
- package/player.d.ts.map +1 -1
- package/player.js +3 -1
- package/player.js.map +1 -1
- package/readme.md +9 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This class wraps a regular URL worker into a blob.
|
|
3
|
+
* It is a common scenario to have the website served from one domain, and scripts from another one.
|
|
4
|
+
* This can cause CSP issues if worker-src does not include the domain that serves the scripts. By
|
|
5
|
+
* wrapping the worker into a blob, the only CSP required for worker-src is blob and the worker will
|
|
6
|
+
* load correctly. script-src must still include the domain that serves the worker script and dependencies.
|
|
7
|
+
*/
|
|
8
|
+
export declare class BlobWorkerWrapper {
|
|
9
|
+
private readonly _worker;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new instance of the BlobWorkerWrapper class.
|
|
12
|
+
* @param url The URL of the worker script that needs to be wrapper into a blob.
|
|
13
|
+
*/
|
|
14
|
+
constructor(url: URL);
|
|
15
|
+
/**
|
|
16
|
+
* Gets the underlying Worker instance created by this CorsWorker.
|
|
17
|
+
* @returns The underlying Worker instance created by this CorsWorker.
|
|
18
|
+
*/
|
|
19
|
+
getWorker(): Worker;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=blobWorkerWrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blobWorkerWrapper.d.ts","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/blobWorkerWrapper.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC;;;OAGG;gBACgB,GAAG,EAAE,GAAG;IAgB3B;;;OAGG;IACI,SAAS,IAAI,MAAM;CAG7B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// From https://github.com/webpack/webpack/discussions/14648#discussioncomment-1589272
|
|
2
|
+
/**
|
|
3
|
+
* This class wraps a regular URL worker into a blob.
|
|
4
|
+
* It is a common scenario to have the website served from one domain, and scripts from another one.
|
|
5
|
+
* This can cause CSP issues if worker-src does not include the domain that serves the scripts. By
|
|
6
|
+
* wrapping the worker into a blob, the only CSP required for worker-src is blob and the worker will
|
|
7
|
+
* load correctly. script-src must still include the domain that serves the worker script and dependencies.
|
|
8
|
+
*/
|
|
9
|
+
export class BlobWorkerWrapper {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new instance of the BlobWorkerWrapper class.
|
|
12
|
+
* @param url The URL of the worker script that needs to be wrapper into a blob.
|
|
13
|
+
*/
|
|
14
|
+
constructor(url) {
|
|
15
|
+
const workerScript = `
|
|
16
|
+
const scriptUrl = new URL("${url.toString()}");
|
|
17
|
+
const originalImportScripts = self.importScripts;
|
|
18
|
+
self.importScripts = (url) => originalImportScripts.call(self, new URL(url, scriptUrl).toString());
|
|
19
|
+
importScripts(scriptUrl.toString());
|
|
20
|
+
`;
|
|
21
|
+
const objectURL = URL.createObjectURL(new Blob([workerScript], {
|
|
22
|
+
type: "application/javascript",
|
|
23
|
+
}));
|
|
24
|
+
this._worker = new Worker(objectURL);
|
|
25
|
+
URL.revokeObjectURL(objectURL);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Gets the underlying Worker instance created by this CorsWorker.
|
|
29
|
+
* @returns The underlying Worker instance created by this CorsWorker.
|
|
30
|
+
*/
|
|
31
|
+
getWorker() {
|
|
32
|
+
return this._worker;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=blobWorkerWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blobWorkerWrapper.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/blobWorkerWrapper.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAE1B;;;OAGG;IACH,YAAmB,GAAQ;QACvB,MAAM,YAAY,GAAG;yCACY,GAAG,CAAC,QAAQ,EAAE;;;;SAI9C,CAAC;QACF,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,CACjC,IAAI,IAAI,CAAC,CAAC,YAAY,CAAC,EAAE;YACrB,IAAI,EAAE,wBAAwB;SACjC,CAAC,CACL,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;QACrC,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,SAAS;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ"}
|
package/package.json
CHANGED
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;AAEvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,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;AAI7D;;;;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,CAAqC;IACpD,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;IAwE/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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CalculateScaleFactor } from "./rendering/animationController.js";
|
|
2
|
+
import { BlobWorkerWrapper as Worker } from "./blobWorkerWrapper.js";
|
|
2
3
|
/**
|
|
3
4
|
* Allows you to play Lottie animations using Babylon.js.
|
|
4
5
|
* It plays the animations in a worker thread using OffscreenCanvas.
|
|
@@ -48,7 +49,8 @@ export class Player {
|
|
|
48
49
|
return false;
|
|
49
50
|
}
|
|
50
51
|
if ("OffscreenCanvas" in window) {
|
|
51
|
-
|
|
52
|
+
const wrapperWorker = new Worker(new URL("./worker", import.meta.url));
|
|
53
|
+
this._worker = wrapperWorker.getWorker();
|
|
52
54
|
this._worker.onmessage = (evt) => {
|
|
53
55
|
const message = evt.data;
|
|
54
56
|
if (message === undefined) {
|
package/player.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/player.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"player.js","sourceRoot":"","sources":["../../../dev/lottiePlayer/src/player.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,iBAAiB,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElE;;;;GAIG;AACH,MAAM,OAAO,MAAM;IAef;;;;;;OAMG;IACH,YACI,SAAyB,EACzB,eAA4C,EAC5C,YAA2C,IAAI,EAC/C,gBAA2D,IAAI;QApB3D,aAAQ,GAAY,KAAK,CAAC;QAC1B,cAAS,GAAY,KAAK,CAAC;QAC3B,YAAO,GAAgC,IAAI,CAAC;QAC5C,YAAO,GAAgC,IAAI,CAAC;QAC5C,oBAAe,GAAW,CAAC,CAAC;QAC5B,qBAAgB,GAAW,CAAC,CAAC;QAC7B,iBAAY,GAAW,CAAC,CAAC;QACzB,oBAAe,GAA6B,IAAI,CAAC;QAsKjD,oBAAe,GAAG,GAAG,EAAE;YAC3B,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACnD,OAAO;YACX,CAAC;YAED,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;YACnC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;YAEpC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;QACtD,CAAC,CAAC;QAEM,oBAA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C,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;aACjF;SACJ,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,qBAAqB,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IACjE,CAAC;CAiBJ;AAED,SAAS,oBAAoB,CAAC,CAAU;IACpC,MAAM,CAAC,GAAG,CAAQ,CAAC;IACnB,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACzH,CAAC"}
|
package/readme.md
CHANGED
|
@@ -29,6 +29,15 @@ You can pass a variables map in the constructor of Player. These variables will
|
|
|
29
29
|
|
|
30
30
|
You can use the AnimationConfiguration to change certain parameters of the parser/player. For example, loopAnimation to loop the animation, or ignoreOpacityAnimation for performance if you know your animation doesn't modify opacity.
|
|
31
31
|
|
|
32
|
+
## Security
|
|
33
|
+
|
|
34
|
+
For this player to work, if you are applying CSP to your website, you need the following headers:
|
|
35
|
+
_worker-src blob:_
|
|
36
|
+
_script-src thedomainservingyourjs_
|
|
37
|
+
|
|
38
|
+
worker-src is used to load the worker. To simplify configuration, we have a small wrapper over the real worker that loads it as a blob.
|
|
39
|
+
script-src is used by the scripts the worker references, like the classes it needs from babylon.js to render. If your CSP is blocking the domain of those scripts, then the worker will fail. You can use 'self' if you are serving your .js from the same domain you are serving your site, or your domain if your .js is served from a separate domain like a CDN.
|
|
40
|
+
|
|
32
41
|
## Remarks
|
|
33
42
|
|
|
34
43
|
- Prefer to use the class Player that uses an Offscreen canvas and the worker thread. If for some reason that is not available to you, you can use LocalPlayer and call playAnimationAsync which renders in the main JS thread.
|