jassub 1.1.13 → 1.2.1
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 +951 -951
- package/dist/jassub-worker-legacy.js +20 -20
- package/dist/jassub-worker.js +1 -1
- package/dist/jassub.es.js +39 -27
- package/dist/jassub.js +1627 -1607
- package/dist/jassub.umd.js +1 -1
- package/package.json +1 -1
- package/src/jassub.js +41 -26
package/dist/jassub.es.js
CHANGED
|
@@ -41,15 +41,15 @@ if (!("requestVideoFrameCallback" in HTMLVideoElement.prototype) && "getVideoPla
|
|
|
41
41
|
}
|
|
42
42
|
const _JASSUB = class extends EventTarget {
|
|
43
43
|
constructor(options = {}) {
|
|
44
|
-
var _a, _b, _c;
|
|
44
|
+
var _a, _b, _c, _d, _e;
|
|
45
45
|
super();
|
|
46
46
|
if (!globalThis.Worker) {
|
|
47
47
|
this.destroy("Worker not supported");
|
|
48
48
|
}
|
|
49
49
|
_JASSUB._test();
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
50
|
+
const blendMode = options.blendMode || "js";
|
|
51
|
+
const asyncRender = typeof createImageBitmap !== "undefined" && ((_a = options.asyncRender) != null ? _a : true);
|
|
52
|
+
const offscreenRender = typeof OffscreenCanvas !== "undefined" && ((_b = options.offscreenRender) != null ? _b : true);
|
|
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;
|
|
@@ -72,9 +72,9 @@ const _JASSUB = class extends EventTarget {
|
|
|
72
72
|
this._canvas.style.pointerEvents = "none";
|
|
73
73
|
this._canvasParent.appendChild(this._canvas);
|
|
74
74
|
this._bufferCanvas = document.createElement("canvas");
|
|
75
|
-
this._bufferCtx = this._bufferCanvas.getContext("2d");
|
|
76
|
-
this._canvasctrl =
|
|
77
|
-
this._ctx = !
|
|
75
|
+
this._bufferCtx = this._bufferCanvas.getContext("2d", { desynchronized: true, willReadFrequently: true });
|
|
76
|
+
this._canvasctrl = offscreenRender ? this._canvas.transferControlToOffscreen() : this._canvas;
|
|
77
|
+
this._ctx = !offscreenRender && this._canvasctrl.getContext("2d", { desynchronized: true });
|
|
78
78
|
this._lastRenderTime = 0;
|
|
79
79
|
this.debug = !!options.debug;
|
|
80
80
|
this.prescaleFactor = options.prescaleFactor || 1;
|
|
@@ -85,11 +85,12 @@ const _JASSUB = class extends EventTarget {
|
|
|
85
85
|
this._worker.onerror = (e) => this._error(e);
|
|
86
86
|
this._worker.postMessage({
|
|
87
87
|
target: "init",
|
|
88
|
-
asyncRender
|
|
88
|
+
asyncRender,
|
|
89
|
+
onDemandRender: this._onDemandRender,
|
|
89
90
|
width: this._canvas.width,
|
|
90
91
|
height: this._canvas.height,
|
|
91
92
|
preMain: true,
|
|
92
|
-
blendMode
|
|
93
|
+
blendMode,
|
|
93
94
|
subUrl: options.subUrl,
|
|
94
95
|
subContent: options.subContent || null,
|
|
95
96
|
fonts: options.fonts || [],
|
|
@@ -101,9 +102,9 @@ const _JASSUB = class extends EventTarget {
|
|
|
101
102
|
libassMemoryLimit: options.libassMemoryLimit || 0,
|
|
102
103
|
libassGlyphLimit: options.libassGlyphLimit || 0,
|
|
103
104
|
hasAlphaBug: _JASSUB._hasAlphaBug,
|
|
104
|
-
useLocalFonts: "queryLocalFonts" in self &&
|
|
105
|
+
useLocalFonts: "queryLocalFonts" in self && ((_d = options.useLocalFonts) != null ? _d : true)
|
|
105
106
|
});
|
|
106
|
-
if (
|
|
107
|
+
if (offscreenRender === true)
|
|
107
108
|
this.sendMessage("offscreenCanvas", null, [this._canvasctrl]);
|
|
108
109
|
this._boundResize = this.resize.bind(this);
|
|
109
110
|
this._boundTimeUpdate = this._timeupdate.bind(this);
|
|
@@ -111,14 +112,15 @@ const _JASSUB = class extends EventTarget {
|
|
|
111
112
|
this.setVideo(options.video);
|
|
112
113
|
if (this._onDemandRender) {
|
|
113
114
|
this.busy = false;
|
|
114
|
-
this.
|
|
115
|
+
this._lastDemandTime = null;
|
|
116
|
+
(_e = this._video) == null ? void 0 : _e.requestVideoFrameCallback(this._handleRVFC.bind(this));
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
static _test() {
|
|
118
120
|
if (_JASSUB._supportsWebAssembly !== null)
|
|
119
121
|
return null;
|
|
120
122
|
const canvas1 = document.createElement("canvas");
|
|
121
|
-
const ctx1 = canvas1.getContext("2d");
|
|
123
|
+
const ctx1 = canvas1.getContext("2d", { willReadFrequently: true });
|
|
122
124
|
if (typeof ImageData.prototype.constructor === "function") {
|
|
123
125
|
try {
|
|
124
126
|
new ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1);
|
|
@@ -135,15 +137,14 @@ const _JASSUB = class extends EventTarget {
|
|
|
135
137
|
try {
|
|
136
138
|
if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") {
|
|
137
139
|
const module = new WebAssembly.Module(Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0));
|
|
138
|
-
if (module instanceof WebAssembly.Module)
|
|
140
|
+
if (module instanceof WebAssembly.Module)
|
|
139
141
|
_JASSUB._supportsWebAssembly = new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
|
|
140
|
-
}
|
|
141
142
|
}
|
|
142
143
|
} catch (e) {
|
|
143
144
|
_JASSUB._supportsWebAssembly = false;
|
|
144
145
|
}
|
|
145
146
|
const canvas2 = document.createElement("canvas");
|
|
146
|
-
const ctx2 = canvas2.getContext("2d");
|
|
147
|
+
const ctx2 = canvas2.getContext("2d", { willReadFrequently: true });
|
|
147
148
|
canvas1.width = canvas2.width = 1;
|
|
148
149
|
canvas1.height = canvas2.height = 1;
|
|
149
150
|
ctx1.clearRect(0, 0, 1, 1);
|
|
@@ -242,7 +243,9 @@ const _JASSUB = class extends EventTarget {
|
|
|
242
243
|
if (video instanceof HTMLVideoElement) {
|
|
243
244
|
this._removeListeners();
|
|
244
245
|
this._video = video;
|
|
245
|
-
if (this._onDemandRender
|
|
246
|
+
if (this._onDemandRender) {
|
|
247
|
+
this._video.requestVideoFrameCallback(this._handleRVFC.bind(this));
|
|
248
|
+
} else {
|
|
246
249
|
this._playstate = video.paused;
|
|
247
250
|
video.addEventListener("timeupdate", this._boundTimeUpdate, false);
|
|
248
251
|
video.addEventListener("progress", this._boundTimeUpdate, false);
|
|
@@ -336,16 +339,15 @@ const _JASSUB = class extends EventTarget {
|
|
|
336
339
|
}
|
|
337
340
|
}
|
|
338
341
|
_getLocalFont({ font }) {
|
|
339
|
-
var _a
|
|
342
|
+
var _a;
|
|
340
343
|
try {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
query({ name: "local-fonts" }).then((permission) => {
|
|
344
|
+
if ((_a = navigator == null ? void 0 : navigator.permissions) == null ? void 0 : _a.query) {
|
|
345
|
+
navigator.permissions.query({ name: "local-fonts" }).then((permission) => {
|
|
344
346
|
if (permission.state === "granted") {
|
|
345
347
|
this._sendLocalFont(font);
|
|
346
348
|
}
|
|
347
349
|
});
|
|
348
|
-
} else
|
|
350
|
+
} else {
|
|
349
351
|
this._sendLocalFont(font);
|
|
350
352
|
}
|
|
351
353
|
} catch (e) {
|
|
@@ -353,16 +355,26 @@ const _JASSUB = class extends EventTarget {
|
|
|
353
355
|
}
|
|
354
356
|
}
|
|
355
357
|
_unbusy() {
|
|
356
|
-
this.
|
|
358
|
+
if (this._lastDemandTime) {
|
|
359
|
+
this._demandRender(this._lastDemandTime);
|
|
360
|
+
} else {
|
|
361
|
+
this.busy = false;
|
|
362
|
+
}
|
|
357
363
|
}
|
|
358
|
-
|
|
364
|
+
_handleRVFC(now, { mediaTime }) {
|
|
359
365
|
if (this._destroyed)
|
|
360
366
|
return null;
|
|
361
|
-
if (
|
|
367
|
+
if (this.busy) {
|
|
368
|
+
this._lastDemandTime = mediaTime;
|
|
369
|
+
} else {
|
|
362
370
|
this.busy = true;
|
|
363
|
-
this.
|
|
371
|
+
this._demandRender(mediaTime);
|
|
364
372
|
}
|
|
365
|
-
this._video.requestVideoFrameCallback(this.
|
|
373
|
+
this._video.requestVideoFrameCallback(this._handleRVFC.bind(this));
|
|
374
|
+
}
|
|
375
|
+
_demandRender(time) {
|
|
376
|
+
this._lastDemandTime = null;
|
|
377
|
+
this.sendMessage("demand", { time: time + this.timeOffset });
|
|
366
378
|
}
|
|
367
379
|
_render({ images, async, times }) {
|
|
368
380
|
const drawStartTime = Date.now();
|