@openbone/player 0.4.1 → 0.4.3
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/player.d.ts +2 -0
- package/dist/player.js +16 -11
- package/package.json +6 -6
package/dist/player.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface PlayerOptions {
|
|
|
34
34
|
audioContext?: AudioContext;
|
|
35
35
|
/** Map an audio asset to the URL to load (overrides baseUrl), e.g. for files read from disk. */
|
|
36
36
|
resolveAudioUrl?: (asset: AudioAsset) => string;
|
|
37
|
+
/** Map a font src to the URL to load (overrides baseUrl). */
|
|
38
|
+
resolveFontUrl?: (src: string) => string;
|
|
37
39
|
/** Map an image src to the URL to load (overrides baseUrl). */
|
|
38
40
|
resolveImageUrl?: (src: string) => string;
|
|
39
41
|
onEvent?: (e: FiredEvent) => void;
|
package/dist/player.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseDocument, textureAssets } from "@openbone/core";
|
|
2
2
|
import { CanvasRenderer } from "@openbone/render-canvas";
|
|
3
3
|
import { WebGLRenderer } from "@openbone/render-webgl";
|
|
4
|
-
import { OpenBoneInstance } from "@openbone/runtime";
|
|
4
|
+
import { OpenBoneInstance, loadDocumentFonts } from "@openbone/runtime";
|
|
5
5
|
import { WebAudioBackend } from "./audio.js";
|
|
6
6
|
/** The most of the artboard's width or height `auto` will crop to fill the canvas. */
|
|
7
7
|
export const AUTO_CROP = 0.15;
|
|
@@ -94,16 +94,21 @@ export class Player {
|
|
|
94
94
|
}
|
|
95
95
|
else
|
|
96
96
|
this.doc = o.src;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
97
|
+
const abs = (src) => (/^(data:|https?:|blob:|\/)/.test(src) ? src : base + src);
|
|
98
|
+
await Promise.all([
|
|
99
|
+
// The document's own fonts, so the first frame already draws text with them.
|
|
100
|
+
loadDocumentFonts(this.doc, (f) => (o.resolveFontUrl ? o.resolveFontUrl(f.src) : abs(f.src))),
|
|
101
|
+
...textureAssets(this.doc).map((img) => new Promise((resolve) => {
|
|
102
|
+
const el = new Image();
|
|
103
|
+
el.crossOrigin = "anonymous";
|
|
104
|
+
el.onload = () => {
|
|
105
|
+
this.images.set(img.id, el);
|
|
106
|
+
resolve();
|
|
107
|
+
};
|
|
108
|
+
el.onerror = () => resolve();
|
|
109
|
+
el.src = o.resolveImageUrl ? o.resolveImageUrl(img.src) : abs(img.src);
|
|
110
|
+
})),
|
|
111
|
+
]);
|
|
107
112
|
// null: scripts off on purpose ("none", no scripts, or no sandbox in this build, which warns above).
|
|
108
113
|
let scriptHost = null;
|
|
109
114
|
if (typeof o.scripts === "object")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openbone/player",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Drop-in <openbone-player> web component and JS API for OpenBone animations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openbone",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"quickjs-emscripten": "^0.32.0",
|
|
51
|
-
"@openbone/
|
|
52
|
-
"@openbone/render-webgl": "0.4.
|
|
53
|
-
"@openbone/
|
|
54
|
-
"@openbone/runtime": "0.4.
|
|
55
|
-
"@openbone/scripting": "0.4.
|
|
51
|
+
"@openbone/core": "0.4.3",
|
|
52
|
+
"@openbone/render-webgl": "0.4.3",
|
|
53
|
+
"@openbone/render-canvas": "0.4.3",
|
|
54
|
+
"@openbone/runtime": "0.4.3",
|
|
55
|
+
"@openbone/scripting": "0.4.3"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"esbuild": ">=0.25.0"
|