jassub 1.2.1 → 1.2.4
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/COPYRIGHT +21 -21
- package/dist/jassub-worker-legacy.js +10 -10
- package/dist/jassub-worker-legacy.js.mem +0 -0
- package/dist/jassub-worker.js +1 -1
- package/dist/jassub-worker.wasm +0 -0
- package/dist/jassub.es.js +30 -20
- package/dist/jassub.js +32 -971
- package/dist/jassub.umd.js +1 -1
- package/package.json +1 -1
- package/src/jassub.js +30 -20
package/dist/jassub.es.js
CHANGED
|
@@ -53,11 +53,16 @@ const _JASSUB = class extends EventTarget {
|
|
|
53
53
|
this._onDemandRender = "requestVideoFrameCallback" in HTMLVideoElement.prototype && ((_c = options.onDemandRender) != null ? _c : true);
|
|
54
54
|
this.timeOffset = options.timeOffset || 0;
|
|
55
55
|
this._video = options.video;
|
|
56
|
-
this.
|
|
57
|
-
if (this._video) {
|
|
56
|
+
this._canvas = options.canvas;
|
|
57
|
+
if (this._video && !this._canvas) {
|
|
58
58
|
this._canvasParent = document.createElement("div");
|
|
59
59
|
this._canvasParent.className = "JASSUB";
|
|
60
60
|
this._canvasParent.style.position = "relative";
|
|
61
|
+
this._canvas = document.createElement("canvas");
|
|
62
|
+
this._canvas.style.display = "block";
|
|
63
|
+
this._canvas.style.position = "absolute";
|
|
64
|
+
this._canvas.style.pointerEvents = "none";
|
|
65
|
+
this._canvasParent.appendChild(this._canvas);
|
|
61
66
|
if (this._video.nextSibling) {
|
|
62
67
|
this._video.parentNode.insertBefore(this._canvasParent, this._video.nextSibling);
|
|
63
68
|
} else {
|
|
@@ -66,11 +71,6 @@ const _JASSUB = class extends EventTarget {
|
|
|
66
71
|
} else if (!this._canvas) {
|
|
67
72
|
this.destroy("Don't know where to render: you should give video or canvas in options.");
|
|
68
73
|
}
|
|
69
|
-
this._canvas = options.canvas || document.createElement("canvas");
|
|
70
|
-
this._canvas.style.display = "block";
|
|
71
|
-
this._canvas.style.position = "absolute";
|
|
72
|
-
this._canvas.style.pointerEvents = "none";
|
|
73
|
-
this._canvasParent.appendChild(this._canvas);
|
|
74
74
|
this._bufferCanvas = document.createElement("canvas");
|
|
75
75
|
this._bufferCtx = this._bufferCanvas.getContext("2d", { desynchronized: true, willReadFrequently: true });
|
|
76
76
|
this._canvasctrl = offscreenRender ? this._canvas.transferControlToOffscreen() : this._canvas;
|
|
@@ -109,7 +109,8 @@ const _JASSUB = class extends EventTarget {
|
|
|
109
109
|
this._boundResize = this.resize.bind(this);
|
|
110
110
|
this._boundTimeUpdate = this._timeupdate.bind(this);
|
|
111
111
|
this._boundSetRate = this.setRate.bind(this);
|
|
112
|
-
this.
|
|
112
|
+
if (this._video)
|
|
113
|
+
this.setVideo(options.video);
|
|
113
114
|
if (this._onDemandRender) {
|
|
114
115
|
this.busy = false;
|
|
115
116
|
this._lastDemandTime = null;
|
|
@@ -126,7 +127,7 @@ const _JASSUB = class extends EventTarget {
|
|
|
126
127
|
new ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1);
|
|
127
128
|
} catch (e) {
|
|
128
129
|
console.log("detected that ImageData is not constructable despite browser saying so");
|
|
129
|
-
|
|
130
|
+
self.ImageData = function(data, width, height) {
|
|
130
131
|
const imageData = ctx1.createImageData(width, height);
|
|
131
132
|
if (data)
|
|
132
133
|
imageData.data.set(data);
|
|
@@ -156,17 +157,20 @@ const _JASSUB = class extends EventTarget {
|
|
|
156
157
|
_JASSUB._hasAlphaBug = prePut[1] !== postPut[1];
|
|
157
158
|
if (_JASSUB._hasAlphaBug)
|
|
158
159
|
console.log("Detected a browser having issue with transparent pixels, applying workaround");
|
|
160
|
+
canvas1.remove();
|
|
159
161
|
canvas2.remove();
|
|
160
162
|
}
|
|
161
163
|
resize(width = 0, height = 0, top = 0, left = 0) {
|
|
162
164
|
let videoSize = null;
|
|
163
165
|
if ((!width || !height) && this._video) {
|
|
164
166
|
videoSize = this._getVideoPosition();
|
|
165
|
-
const newsize = this._computeCanvasSize((videoSize.width || 0) * (
|
|
167
|
+
const newsize = this._computeCanvasSize((videoSize.width || 0) * (self.devicePixelRatio || 1), (videoSize.height || 0) * (self.devicePixelRatio || 1));
|
|
166
168
|
width = newsize.width;
|
|
167
169
|
height = newsize.height;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
if (this._canvasParent) {
|
|
171
|
+
top = videoSize.y - (this._canvasParent.getBoundingClientRect().top - this._video.getBoundingClientRect().top);
|
|
172
|
+
left = videoSize.x;
|
|
173
|
+
}
|
|
170
174
|
}
|
|
171
175
|
if (videoSize != null) {
|
|
172
176
|
this._canvas.style.top = top + "px";
|
|
@@ -322,12 +326,12 @@ const _JASSUB = class extends EventTarget {
|
|
|
322
326
|
addFont(font) {
|
|
323
327
|
this.sendMessage("addFont", { font });
|
|
324
328
|
}
|
|
325
|
-
_sendLocalFont(
|
|
329
|
+
_sendLocalFont(name) {
|
|
326
330
|
try {
|
|
327
331
|
queryLocalFonts().then((fontData) => {
|
|
328
|
-
const
|
|
329
|
-
if (
|
|
330
|
-
|
|
332
|
+
const font = fontData == null ? void 0 : fontData.find((obj) => obj.fullName.toLowerCase() === name);
|
|
333
|
+
if (font) {
|
|
334
|
+
font.blob().then((blob) => {
|
|
331
335
|
blob.arrayBuffer().then((buffer) => {
|
|
332
336
|
this.addFont(new Uint8Array(buffer));
|
|
333
337
|
});
|
|
@@ -460,9 +464,15 @@ const _JASSUB = class extends EventTarget {
|
|
|
460
464
|
this["_" + data.target](data);
|
|
461
465
|
}
|
|
462
466
|
_error(err) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
467
|
+
this.dispatchEvent(err instanceof ErrorEvent ? err : new ErrorEvent("error", { cause: err instanceof Error ? err.cause : err }));
|
|
468
|
+
if (!(err instanceof Error)) {
|
|
469
|
+
if (err instanceof ErrorEvent) {
|
|
470
|
+
err = err.error;
|
|
471
|
+
} else {
|
|
472
|
+
err = new Error("error", { cause: err });
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
console.error(err);
|
|
466
476
|
}
|
|
467
477
|
_removeListeners() {
|
|
468
478
|
if (this._video) {
|
|
@@ -480,7 +490,7 @@ const _JASSUB = class extends EventTarget {
|
|
|
480
490
|
destroy(err) {
|
|
481
491
|
if (err)
|
|
482
492
|
this._error(err);
|
|
483
|
-
if (this._video)
|
|
493
|
+
if (this._video && this._canvasParent)
|
|
484
494
|
this._video.parentNode.removeChild(this._canvasParent);
|
|
485
495
|
this._destroyed = true;
|
|
486
496
|
this._removeListeners();
|