jassub 1.2.0 → 1.2.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/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._canvasParent = null;
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,15 +71,10 @@ 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
- this._bufferCtx = this._bufferCanvas.getContext("2d");
75
+ this._bufferCtx = this._bufferCanvas.getContext("2d", { desynchronized: true, willReadFrequently: true });
76
76
  this._canvasctrl = offscreenRender ? this._canvas.transferControlToOffscreen() : this._canvas;
77
- this._ctx = !offscreenRender && this._canvasctrl.getContext("2d");
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;
@@ -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.setVideo(options.video);
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
- window.ImageData = function(data, width, height) {
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);
@@ -137,9 +138,8 @@ const _JASSUB = class extends EventTarget {
137
138
  try {
138
139
  if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") {
139
140
  const module = new WebAssembly.Module(Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0));
140
- if (module instanceof WebAssembly.Module) {
141
+ if (module instanceof WebAssembly.Module)
141
142
  _JASSUB._supportsWebAssembly = new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
142
- }
143
143
  }
144
144
  } catch (e) {
145
145
  _JASSUB._supportsWebAssembly = false;
@@ -157,17 +157,20 @@ const _JASSUB = class extends EventTarget {
157
157
  _JASSUB._hasAlphaBug = prePut[1] !== postPut[1];
158
158
  if (_JASSUB._hasAlphaBug)
159
159
  console.log("Detected a browser having issue with transparent pixels, applying workaround");
160
+ canvas1.remove();
160
161
  canvas2.remove();
161
162
  }
162
163
  resize(width = 0, height = 0, top = 0, left = 0) {
163
164
  let videoSize = null;
164
165
  if ((!width || !height) && this._video) {
165
166
  videoSize = this._getVideoPosition();
166
- const newsize = this._computeCanvasSize((videoSize.width || 0) * (window.devicePixelRatio || 1), (videoSize.height || 0) * (window.devicePixelRatio || 1));
167
+ const newsize = this._computeCanvasSize((videoSize.width || 0) * (self.devicePixelRatio || 1), (videoSize.height || 0) * (self.devicePixelRatio || 1));
167
168
  width = newsize.width;
168
169
  height = newsize.height;
169
- top = videoSize.y - (this._canvasParent.getBoundingClientRect().top - this._video.getBoundingClientRect().top);
170
- left = videoSize.x;
170
+ if (this._canvasParent) {
171
+ top = videoSize.y - (this._canvasParent.getBoundingClientRect().top - this._video.getBoundingClientRect().top);
172
+ left = videoSize.x;
173
+ }
171
174
  }
172
175
  if (videoSize != null) {
173
176
  this._canvas.style.top = top + "px";
@@ -323,12 +326,12 @@ const _JASSUB = class extends EventTarget {
323
326
  addFont(font) {
324
327
  this.sendMessage("addFont", { font });
325
328
  }
326
- _sendLocalFont(font) {
329
+ _sendLocalFont(name) {
327
330
  try {
328
331
  queryLocalFonts().then((fontData) => {
329
- const filtered = fontData && fontData.filter((obj) => obj.fullName.toLowerCase() === font);
330
- if (filtered && filtered.length) {
331
- filtered[0].blob().then((blob) => {
332
+ const font = fontData == null ? void 0 : fontData.find((obj) => obj.fullName.toLowerCase() === name);
333
+ if (font) {
334
+ font.blob().then((blob) => {
332
335
  blob.arrayBuffer().then((buffer) => {
333
336
  this.addFont(new Uint8Array(buffer));
334
337
  });
@@ -481,7 +484,7 @@ const _JASSUB = class extends EventTarget {
481
484
  destroy(err) {
482
485
  if (err)
483
486
  this._error(err);
484
- if (this._video)
487
+ if (this._video && this._canvasParent)
485
488
  this._video.parentNode.removeChild(this._canvasParent);
486
489
  this._destroyed = true;
487
490
  this._removeListeners();