jassub 1.1.11 → 1.1.12

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.js CHANGED
@@ -19,8 +19,8 @@
19
19
  // License: Expat
20
20
  // Copyright: 2019 Zhongyuan Zhou <zhouzhongyuan@huawei.com>
21
21
  // 2020 Joe Orton <jorton@redhat.com>
22
- // 2016-2019 Sebastian Pipping <sebastian@pipping.org>
23
22
  // 2021 Dong-hee Na <donghee.na@python.org>
23
+ // 2016-2019 Sebastian Pipping <sebastian@pipping.org>
24
24
  // 2017 Joe Orton <jorton@redhat.com>
25
25
  // 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
26
26
  // 2004-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
@@ -53,21 +53,21 @@
53
53
  // 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
54
54
  // 2017-2018 Rhodri James <rhodri@wildebeest.org.uk>
55
55
  // 2005-2012 Karl Waclawek <karl@waclawek.net>
56
- // 2022 Thijs Schreijer <thijs@thijsschreijer.nl>
57
56
  // 2020 Boris Kolpackov <boris@codesynthesis.com>
57
+ // 2022 Thijs Schreijer <thijs@thijsschreijer.nl>
58
58
  // 2016 Cristian Rodr\x{00c3}\x{00ad}guez <crrodriguez@opensuse.org>
59
59
  // 2017-2019 Sebastian Pipping <sebastian@pipping.org>
60
60
  // 2005 Karl Waclawek <karl@waclawek.net>
61
61
  // 1999-2000 Thai Open Source Software Center Ltd
62
62
  // 2000-2017 Expat development team / 1997-2000 Thai Open Source Software Center Ltd
63
+ // 2016-2021 Sebastian Pipping <sebastian@pipping.org>
63
64
  // 2005-2007 Steven Solie <steven@solie.ca>
64
65
  // 2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
65
- // 2016-2021 Sebastian Pipping <sebastian@pipping.org>
66
66
  // 2018 Anton Maklakov <antmak.pub@gmail.com>
67
67
  // 2017 Alexander Bluhm <alexander.bluhm@gmx.net>
68
68
  // 1997-2000 Thai Open Source Software Center Ltd
69
- // 2016-2022 Sebastian Pipping <sebastian@pipping.org>
70
69
  // 2017-2021 Sebastian Pipping <sebastian@pipping.org>
70
+ // 2016-2022 Sebastian Pipping <sebastian@pipping.org>
71
71
  // 2002-2009 Karl Waclawek <karl@waclawek.net>
72
72
  // 2002 Karl Waclawek <karl@waclawek.net>
73
73
  // 2020 Tim Gates <tim.gates@iress.com>
@@ -75,8 +75,8 @@
75
75
  // 2016 Pascal Cuoq <cuoq@trust-in-soft.com>
76
76
  // 2017 Jos\x{00c3}\x{00a9} Guti\x{00c3}\x{00a9}rrez de la Concha <jose@zeroc.com>
77
77
  // 2001-2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
78
- // 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
79
78
  // 2002-2006 Karl Waclawek <karl@waclawek.net>
79
+ // 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
80
80
  // 2018 Yury Gribov <tetra2005@gmail.com>
81
81
  // 2005-2009 Steven Solie <steven@solie.ca>
82
82
  // 2003 Greg Stein <gstein@users.sourceforge.net>
@@ -103,12 +103,12 @@
103
103
  // 2010-2021 Joel Klinghed.
104
104
  // 2007-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
105
105
  // 1996-2021 David Turner, Robert Wilhelm, and Werner Lemberg
106
- // 2005-2021 Werner Lemberg and Detlef W\x{00fc}rkner.
107
106
  // \x{00c5}\x{009d}\x{00c5}\x{00a5} \x{00c5}\x{009d}\x{00c5}\x{00a5}\x{00d1}\x{008f}\x{00c3}\x{00af}\x{00ef}\x{00ac}\x{00af}\x{00c4}\x{009f}"));
107
+ // 2005-2021 Werner Lemberg and Detlef W\x{00fc}rkner.
108
108
  // 2002-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
109
+ // 2013-2014 Adobe Systems Incorporated.
109
110
  // 2003 Huw D M Davies for Codeweavers
110
111
  // 2004-2021 David Turner, Robert Wilhelm, Werner Lemberg, and George Williams.
111
- // 2013-2014 Adobe Systems Incorporated.
112
112
  // 1996-2021 David Turner, Robert Wilhelm, Werner Lemberg, and Detlef Wuerkner.
113
113
  // 2000-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
114
114
  // 2007-2021 David Turner.
@@ -123,35 +123,35 @@
123
123
  // 1996-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
124
124
  // 2003-2021 Masatake YAMATO, Redhat K.K.,
125
125
  // 2008-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
126
- // 2009-2021 Oran Agra and Mickey Gabel.
127
126
  // 2006-2013 Adobe Systems Incorporated.
127
+ // 2009-2021 Oran Agra and Mickey Gabel.
128
128
  // 2013-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
129
129
  // 2004-2021 Masatake YAMATO, Red Hat K.K.,
130
130
  // 2016-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
131
- // 2007-2021 Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>.
132
131
  // 2020-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
133
132
  // 2002-2021 Roberto Alameda.
133
+ // 2007-2021 Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>.
134
134
  // 1995-2002 Jean-loup Gailly.
135
135
  // 2004-2021 suzuki toshiya, Masatake YAMATO, Red Hat K.K.,
136
- // 2004-2021 Albert Chin-A-Young.
137
136
  // 2018-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
137
+ // 2004-2021 Albert Chin-A-Young.
138
138
  // 2018-2021 David Turner, Robert Wilhelm, Dominik R\x{00c3}\x{00b6}ttsches, and Werner Lemberg.
139
139
  // 2002-2021 David Turner, Robert Wilhelm, and Werner Lemberg
140
140
  // \x{00e1}\x{00bb}\x{008b}...): %dn", "\x{00e1}\x{00ba}\x{0083}\x{00ce}\x{00ad}\x{00c5}\x{0082}\x{00c4}\x{00ba}", "all", 42);
141
- // 2005-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
142
141
  // 2013 Google, Inc.
142
+ // 2005-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
143
143
  // 2009-2014 Adobe Systems Incorporated.
144
- // 2010-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
145
- // 2013-2021 Google, Inc.
146
144
  // 2007-2013 Adobe Systems Incorporated.
147
- // 2001, 2012 David Turner, Robert Wilhelm, and Werner Lemberg.
145
+ // 2013-2021 Google, Inc.
146
+ // 2010-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
148
147
  // 2007-2021 Derek Clegg and Michael Toftdal.
148
+ // 2001, 2012 David Turner, Robert Wilhelm, and Werner Lemberg.
149
149
  // 2003-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
150
150
  // 2008-2021 David Turner, Robert Wilhelm, Werner Lemberg, and suzuki toshiya.
151
151
  // 1990, 1994, 1998 The Open Group
152
152
  // 2004-2021 David Turner, Robert Wilhelm, and Werner Lemberg.
153
- // 1996-2021 David Turner, Robert Wilhelm, Werner Lemberg and Detlef W\x{00fc}rkner.
154
153
  // 2005-2021 suzuki toshiya, Masatake YAMATO, Red Hat K.K.,
154
+ // 1996-2021 David Turner, Robert Wilhelm, Werner Lemberg and Detlef W\x{00fc}rkner.
155
155
  // 2004-2021 Masatake YAMATO, Redhat K.K,
156
156
  //
157
157
  // License: public-domain
@@ -161,8 +161,8 @@
161
161
  // Copyright: 1995-2002 Jean-loup Gailly and Mark Adler
162
162
  //
163
163
  // License: Expat
164
- // Copyright: 2000-2001, 2004 Francesco Zappa Nardelli
165
- // 2001-2004 Francesco Zappa Nardelli
164
+ // Copyright: 2001-2004 Francesco Zappa Nardelli
165
+ // 2000-2001, 2004 Francesco Zappa Nardelli
166
166
  // 2003 Francesco Zappa Nardelli
167
167
  // 2001-2015 Francesco Zappa Nardelli
168
168
  // 2001-2004, 2011 Francesco Zappa Nardelli
@@ -216,15 +216,15 @@
216
216
  // \x{00e6}\x{0081}\x{00af} 2010 Behdad Esfahbod
217
217
  // 2014 Red Hat, Inc.
218
218
  // 2007 Keith Packard
219
- // \x{00e6}\x{0081}\x{00af} 2006 Keith Packard
220
219
  // 2018 Akira TAGOH
220
+ // \x{00e6}\x{0081}\x{00af} 2006 Keith Packard
221
221
  // 2008 Danilo Šegan
222
222
  // 2015 Akira TAGOH
223
223
  // 2008-2009 Red Hat, Inc.
224
224
  // 2016 Akira TAGOH
225
225
  // 2000 Keith Packard
226
- // 2010 Behdad Esfahbod
227
226
  // 2013 Google, Inc.
227
+ // 2010 Behdad Esfahbod
228
228
  // 2013 Akira TAGOH
229
229
  //
230
230
  // License: MIT~old
@@ -256,11 +256,11 @@
256
256
  // 2014 Google, Inc.
257
257
  // 2018 Ebrahim Byagowi
258
258
  // 2016 Igalia S.L.
259
- // 2018 Ebrahim Byagowi.
260
259
  // 2011 Martin Hosken
261
- // 2020 Ebrahim Byagowi
262
- // 1998-2004 David Turner and Werner Lemberg
260
+ // 2018 Ebrahim Byagowi.
263
261
  // 2019 Ebrahim Byagowi
262
+ // 1998-2004 David Turner and Werner Lemberg
263
+ // 2020 Ebrahim Byagowi
264
264
  // 2013 Red Hat, Inc.
265
265
  // 2011-2012 Google, Inc.
266
266
  // 2011 SIL International
@@ -268,8 +268,8 @@
268
268
  // 2018 Google, Inc.
269
269
  // 2019-2020 Ebrahim Byagowi
270
270
  // 2012 Google, Inc.
271
- // 2007-2009 Red Hat, Inc.
272
271
  // 2017 Google, Inc.
272
+ // 2007-2009 Red Hat, Inc.
273
273
  // 2011 Codethink Limited
274
274
  // 2013 Google, Inc.
275
275
  // 2015-2019 Ebrahim Byagowi
@@ -288,8 +288,9 @@
288
288
  // License: ISC
289
289
  // Copyright: 2015 Oleg Oshmyan <chortos@inbox.lv>
290
290
  // 2011-2014 Yu Zhuohuang <yuzhuohuang@qq.com>
291
- // 2016 Vabishchevich Nikolay <vabnick@gmail.com>
292
291
  // 2013 rcombs <rcombs@rcombs.me>
292
+ // 2016 Vabishchevich Nikolay <vabnick@gmail.com>
293
+ // 2022 libass contributors
293
294
  // 2015 Stephan Vedder <stephan.vedder@gmail.com>
294
295
  // 2015 Vabishchevich Nikolay <vabnick@gmail.com>
295
296
  // interest in the
@@ -299,8 +300,8 @@
299
300
  // 2011 Grigori Goronzy <greg@chown.ath.cx>
300
301
  // 2010 Grigori Goronzy <greg@geekmind.org>
301
302
  // 2014 Vabishchevich Nikolay <vabnick@gmail.com>
302
- // 2013 Stefano Pigozzi <stefano.pigozzi@gmail.com>
303
303
  // 2015 Grigori Goronzy <greg@kinoho.net>
304
+ // 2013 Stefano Pigozzi <stefano.pigozzi@gmail.com>
304
305
  // 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
305
306
  // 2009 Grigori Goronzy <greg@geekmind.org>
306
307
  //
@@ -1126,7 +1127,7 @@ export default class JASSUB extends EventTarget {
1126
1127
  let videoSize = null
1127
1128
  if ((!width || !height) && this._video) {
1128
1129
  videoSize = this._getVideoPosition()
1129
- const newsize = this._computeCanvasSize(videoSize.width || 0 * (window.devicePixelRatio || 1), videoSize.height || 0 * (window.devicePixelRatio || 1))
1130
+ const newsize = this._computeCanvasSize((videoSize.width || 0) * (window.devicePixelRatio || 1), (videoSize.height || 0) * (window.devicePixelRatio || 1))
1130
1131
  width = newsize.width
1131
1132
  height = newsize.height
1132
1133
  top = videoSize.y - (this._canvasParent.getBoundingClientRect().top - this._video.getBoundingClientRect().top)
@@ -1446,8 +1447,9 @@ export default class JASSUB extends EventTarget {
1446
1447
  try {
1447
1448
  // electron by default has all permissions enabled, and it doesn't have requesting
1448
1449
  // if this happens, make sure you can query fonts
1449
- if ('request' in navigator.permissions) {
1450
- navigator.permissions.request({ name: 'local-fonts' }).then(permission => {
1450
+ const query = navigator?.permissions?.request || navigator?.permissions?.query
1451
+ if (query) {
1452
+ query({ name: 'local-fonts' }).then(permission => {
1451
1453
  if (permission.state === 'granted') {
1452
1454
  this._sendLocalFont(font)
1453
1455
  }
@@ -1 +1 @@
1
- (function(h,n){typeof exports=="object"&&typeof module!="undefined"?module.exports=n():typeof define=="function"&&define.amd?define(n):(h=typeof globalThis!="undefined"?globalThis:h||self,h.JASSUB=n())})(this,function(){"use strict";var p=Object.defineProperty;var g=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var u=(h,n,l)=>n in h?p(h,n,{enumerable:!0,configurable:!0,writable:!0,value:l}):h[n]=l,v=(h,n)=>{for(var l in n||(n={}))y.call(n,l)&&u(h,l,n[l]);if(g)for(var l of g(n))b.call(n,l)&&u(h,l,n[l]);return h};var _=(h,n,l)=>(u(h,typeof n!="symbol"?n+"":n,l),l);!("requestVideoFrameCallback"in HTMLVideoElement.prototype)&&"getVideoPlaybackQuality"in HTMLVideoElement.prototype&&(HTMLVideoElement.prototype._rvfcpolyfillmap={},HTMLVideoElement.prototype.requestVideoFrameCallback=function(l){const e=this.getVideoPlaybackQuality(),t=this.mozPresentedFrames||e.totalVideoFrames-e.droppedVideoFrames,i=(r,o)=>{const d=this.getVideoPlaybackQuality(),f=this.mozPresentedFrames||d.totalVideoFrames-d.droppedVideoFrames;if(f>t){const c=this.mozFrameDelay||d.totalFrameDelay-e.totalFrameDelay||0,m=o-r;l(o,{presentationTime:o+c*1e3,expectedDisplayTime:o+m,width:this.videoWidth,height:this.videoHeight,mediaTime:Math.max(0,this.currentTime||0)+m/1e3,presentedFrames:f,processingDuration:c}),delete this._rvfcpolyfillmap[a]}else this._rvfcpolyfillmap[a]=requestAnimationFrame(c=>i(o,c))},a=Date.now(),s=performance.now();return this._rvfcpolyfillmap[a]=requestAnimationFrame(r=>i(s,r)),a},HTMLVideoElement.prototype.cancelVideoFrameCallback=function(l){cancelAnimationFrame(this._rvfcpolyfillmap[l]),delete this._rvfcpolyfillmap[l]});const n=class extends EventTarget{constructor(e={}){var s,r,o;super(),globalThis.Worker||this.destroy("Worker not supported"),n._test();const t=e.blendMode||"js",i=typeof createImageBitmap!="undefined"&&((s=e.asyncRender)!=null?s:!0),a=typeof OffscreenCanvas!="undefined"&&((r=e.offscreenRender)!=null?r:!0);this._onDemandRender="requestVideoFrameCallback"in HTMLVideoElement.prototype&&((o=e.onDemandRender)!=null?o:!0),this.timeOffset=e.timeOffset||0,this._video=e.video,this._canvasParent=null,this._video?(this._canvasParent=document.createElement("div"),this._canvasParent.className="JASSUB",this._canvasParent.style.position="relative",this._video.nextSibling?this._video.parentNode.insertBefore(this._canvasParent,this._video.nextSibling):this._video.parentNode.appendChild(this._canvasParent)):this._canvas||this.destroy("Don't know where to render: you should give video or canvas in options."),this._canvas=e.canvas||document.createElement("canvas"),this._canvas.style.display="block",this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvasParent.appendChild(this._canvas),this._bufferCanvas=document.createElement("canvas"),this._bufferCtx=this._bufferCanvas.getContext("2d"),this._canvasctrl=a?this._canvas.transferControlToOffscreen():this._canvas,this._ctx=!a&&this._canvasctrl.getContext("2d"),this._lastRenderTime=0,this.debug=!!e.debug,this.prescaleFactor=e.prescaleFactor||1,this.prescaleHeightLimit=e.prescaleHeightLimit||1080,this.maxRenderHeight=e.maxRenderHeight||0,this._worker=new Worker(n._supportsWebAssembly?e.workerUrl||"jassub-worker.js":e.legacyWorkerUrl||"jassub-worker-legacy.js"),this._worker.onmessage=d=>this._onmessage(d),this._worker.onerror=d=>this._error(d),this._worker.postMessage({target:"init",asyncRender:i,width:this._canvas.width,height:this._canvas.height,preMain:!0,blendMode:t,subUrl:e.subUrl,subContent:e.subContent||null,fonts:e.fonts||[],availableFonts:e.availableFonts||{"liberation sans":"./default.woff2"},fallbackFont:e.fallbackFont||"liberation sans",debug:this.debug,targetFps:e.targetFps||24,dropAllAnimations:e.dropAllAnimations,libassMemoryLimit:e.libassMemoryLimit||0,libassGlyphLimit:e.libassGlyphLimit||0,hasAlphaBug:n._hasAlphaBug,useLocalFonts:"queryLocalFonts"in self&&!!e.useLocalFonts}),a===!0&&this.sendMessage("offscreenCanvas",null,[this._canvasctrl]),this.setVideo(e.video),this._onDemandRender&&(this.busy=!1,this._video.requestVideoFrameCallback(this._demandRender.bind(this)))}static _test(){if(n._supportsWebAssembly!==null)return null;const e=document.createElement("canvas"),t=e.getContext("2d");if(typeof ImageData.prototype.constructor=="function")try{new ImageData(new Uint8ClampedArray([0,0,0,0]),1,1)}catch{console.log("detected that ImageData is not constructable despite browser saying so"),window.ImageData=function(d,f,c){const m=t.createImageData(f,c);return d&&m.data.set(d),m}}try{if(typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function"){const o=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));o instanceof WebAssembly.Module&&(n._supportsWebAssembly=new WebAssembly.Instance(o)instanceof WebAssembly.Instance)}}catch{n._supportsWebAssembly=!1}const i=document.createElement("canvas"),a=i.getContext("2d");e.width=i.width=1,e.height=i.height=1,t.clearRect(0,0,1,1),a.clearRect(0,0,1,1);const s=a.getImageData(0,0,1,1).data;t.putImageData(new ImageData(new Uint8ClampedArray([0,255,0,0]),1,1),0,0),a.drawImage(e,0,0);const r=a.getImageData(0,0,1,1).data;n._hasAlphaBug=s[1]!==r[1],n._hasAlphaBug&&console.log("Detected a browser having issue with transparent pixels, applying workaround"),i.remove()}resize(e=0,t=0,i=0,a=0){let s=null;if((!e||!t)&&this._video){s=this._getVideoPosition();const r=this._computeCanvasSize(s.width||0*(window.devicePixelRatio||1),s.height||0*(window.devicePixelRatio||1));e=r.width,t=r.height,i=s.y-(this._canvasParent.getBoundingClientRect().top-this._video.getBoundingClientRect().top),a=s.x}s!=null&&(this._canvas.style.top=i+"px",this._canvas.style.left=a+"px",this._canvas.style.width=s.width+"px",this._canvas.style.height=s.height+"px"),this._canvasctrl.width===e&&this._canvasctrl.height===t||(this._resizeTimeoutBuffer?(clearTimeout(this._resizeTimeoutBuffer),this._resizeTimeoutBuffer=setTimeout(()=>{this._resizeTimeoutBuffer=void 0,this._canvasctrl.width=e,this._canvasctrl.height=t,this.sendMessage("canvas",{width:e,height:t})},100)):(this._canvasctrl.width=e,this._canvasctrl.height=t,this.sendMessage("canvas",{width:e,height:t}),this._resizeTimeoutBuffer=setTimeout(()=>{this._resizeTimeoutBuffer=void 0},100)))}_getVideoPosition(){const e=this._video.videoWidth/this._video.videoHeight,{offsetWidth:t,offsetHeight:i}=this._video,a=t/i;let s=t,r=i;a>e?s=Math.floor(i*e):r=Math.floor(t/e);const o=(t-s)/2,d=(i-r)/2;return{width:s,height:r,x:o,y:d}}_computeCanvasSize(e=0,t=0){const i=this.prescaleFactor<=0?1:this.prescaleFactor;if(t<=0||e<=0)e=0,t=0;else{const a=i<1?-1:1;let s=t;a*s*i<=a*this.prescaleHeightLimit?s*=i:a*s<a*this.prescaleHeightLimit&&(s=this.prescaleHeightLimit),this.maxRenderHeight>0&&s>this.maxRenderHeight&&(s=this.maxRenderHeight),e*=s/t,t=s}return{width:e,height:t}}_timeupdate({type:e}){const i={seeking:!0,waiting:!0,playing:!1}[e];i!=null&&(this._playstate=i),this.setCurrentTime(this._video.paused||this._playstate,this._video.currentTime+this.timeOffset)}setVideo(e){e instanceof HTMLVideoElement?(this._removeListeners(),this._video=e,this._onDemandRender!==!0&&(this._playstate=e.paused,e.addEventListener("timeupdate",this._timeupdate.bind(this),!1),e.addEventListener("progress",this._timeupdate.bind(this),!1),e.addEventListener("waiting",this._timeupdate.bind(this),!1),e.addEventListener("seeking",this._timeupdate.bind(this),!1),e.addEventListener("playing",this._timeupdate.bind(this),!1),e.addEventListener("ratechange",this.setRate.bind(this),!1)),e.videoWidth>0&&this.resize(),e.addEventListener("resize",this.resize.bind(this)),typeof ResizeObserver!="undefined"&&(this._ro||(this._ro=new ResizeObserver(()=>this.resize())),this._ro.observe(e))):this._error("Video element invalid!")}runBenchmark(){this.sendMessage("runBenchmark")}setTrackByUrl(e){this.sendMessage("setTrackByUrl",{url:e})}setTrack(e){this.sendMessage("setTrack",{content:e})}freeTrack(){this.sendMessage("freeTrack")}setIsPaused(e){this.sendMessage("video",{isPaused:e})}setRate(e){this.sendMessage("video",{rate:e})}setCurrentTime(e,t,i){this.sendMessage("video",{isPaused:e,currentTime:t,rate:i})}createEvent(e){this.sendMessage("createEvent",{event:e})}setEvent(e,t){this.sendMessage("setEvent",{event:e,index:t})}removeEvent(e){this.sendMessage("removeEvent",{index:e})}getEvents(e){this._fetchFromWorker({target:"getEvents"},(t,{events:i})=>{e(t,i)})}createStyle(e){this.sendMessage("createStyle",{style:e})}setStyle(e,t){this.sendMessage("setStyle",{event:e,index:t})}removeStyle(e){this.sendMessage("removeStyle",{index:e})}getStyles(e){this._fetchFromWorker({target:"getStyles"},(t,{styles:i})=>{e(t,i)})}addFont(e){this.sendMessage("addFont",{font:e})}_sendLocalFont(e){try{queryLocalFonts().then(t=>{const i=t&&t.filter(a=>a.fullName.toLowerCase()===e);i&&i.length&&i[0].blob().then(a=>{a.arrayBuffer().then(s=>{this.addFont(new Uint8Array(s))})})})}catch(t){console.warn("Local fonts API:",t)}}_getLocalFont({font:e}){try{"request"in navigator.permissions?navigator.permissions.request({name:"local-fonts"}).then(t=>{t.state==="granted"&&this._sendLocalFont(e)}):"queryLocalFonts"in self&&this._sendLocalFont(e)}catch(t){console.warn("Local fonts API:",t)}}_unbusy(){this.busy=!1}_demandRender(e,t){if(this._destroyed)return null;this.busy||(this.busy=!0,this.sendMessage("demand",{time:t.mediaTime+this.timeOffset})),this._video.requestVideoFrameCallback(this._demandRender.bind(this))}_render({images:e,async:t,times:i}){const a=Date.now();this._ctx.clearRect(0,0,this._canvasctrl.width,this._canvasctrl.height);for(const s of e)s.image&&(t?(this._ctx.drawImage(s.image,s.x,s.y),s.image.close()):(this._bufferCanvas.width=s.w,this._bufferCanvas.height=s.h,this._bufferCtx.putImageData(new ImageData(this._fixAlpha(new Uint8ClampedArray(s.image)),s.w,s.h),0,0),this._ctx.drawImage(this._bufferCanvas,s.x,s.y)));if(this.debug){i.drawTime=Date.now()-a;let s=0;for(const r in i)s+=i[r];console.log("Bitmaps: "+e.length+" Total: "+Math.round(s)+"ms",i)}}_fixAlpha(e){if(n._hasAlphaBug)for(let t=3;t<e.length;t+=4)e[t]=e[t]>1?e[t]:1;return e}_ready(){this.dispatchEvent(new CustomEvent("ready"))}sendMessage(e,t={},i){i?this._worker.postMessage(v({target:e,transferable:i},t),[...i]):this._worker.postMessage(v({target:e},t))}_fetchFromWorker(e,t){try{const i=e.target,a=setTimeout(()=>{r(new Error("Error: Timeout while try to fetch "+i))},5e3),s=({data:o})=>{o.target===i&&(t(null,o),this._worker.removeEventListener("message",s),this._worker.removeEventListener("error",r),clearTimeout(a))},r=o=>{t(o),this._worker.removeEventListener("message",s),this._worker.removeEventListener("error",r),clearTimeout(a)};this._worker.addEventListener("message",s),this._worker.addEventListener("error",r),this._worker.postMessage(e)}catch(i){this._error(i)}}_console({content:e,command:t}){console[t].apply(console,JSON.parse(e))}_onmessage({data:e}){this["_"+e.target]&&this["_"+e.target](e)}_error(e){throw e instanceof ErrorEvent||this.dispatchEvent(new ErrorEvent("error",{message:e instanceof Error?e.cause:e})),e instanceof Error?e:new Error(e instanceof ErrorEvent?e.message:"error",{cause:e})}_removeListeners(){this._video&&(this._ro&&this._ro.unobserve(this._video),this._video.removeEventListener("timeupdate",this._timeupdate),this._video.removeEventListener("progress",this._timeupdate),this._video.removeEventListener("waiting",this._timeupdate),this._video.removeEventListener("seeking",this._timeupdate),this._video.removeEventListener("playing",this._timeupdate),this._video.removeEventListener("ratechange",this.setRate),this._video.removeEventListener("resize",this.resize))}destroy(e){e&&this._error(e),this._video&&this._video.parentNode.removeChild(this._canvasParent),this._destroyed=!0,this._removeListeners(),this.sendMessage("destroy"),this._worker.terminate()}};let h=n;return _(h,"_supportsWebAssembly",null),_(h,"_hasAlphaBug",null),h});
1
+ (function(h,n){typeof exports=="object"&&typeof module!="undefined"?module.exports=n():typeof define=="function"&&define.amd?define(n):(h=typeof globalThis!="undefined"?globalThis:h||self,h.JASSUB=n())})(this,function(){"use strict";var p=Object.defineProperty;var g=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var u=(h,n,l)=>n in h?p(h,n,{enumerable:!0,configurable:!0,writable:!0,value:l}):h[n]=l,v=(h,n)=>{for(var l in n||(n={}))y.call(n,l)&&u(h,l,n[l]);if(g)for(var l of g(n))b.call(n,l)&&u(h,l,n[l]);return h};var _=(h,n,l)=>(u(h,typeof n!="symbol"?n+"":n,l),l);!("requestVideoFrameCallback"in HTMLVideoElement.prototype)&&"getVideoPlaybackQuality"in HTMLVideoElement.prototype&&(HTMLVideoElement.prototype._rvfcpolyfillmap={},HTMLVideoElement.prototype.requestVideoFrameCallback=function(l){const e=this.getVideoPlaybackQuality(),t=this.mozPresentedFrames||e.totalVideoFrames-e.droppedVideoFrames,i=(r,o)=>{const d=this.getVideoPlaybackQuality(),f=this.mozPresentedFrames||d.totalVideoFrames-d.droppedVideoFrames;if(f>t){const c=this.mozFrameDelay||d.totalFrameDelay-e.totalFrameDelay||0,m=o-r;l(o,{presentationTime:o+c*1e3,expectedDisplayTime:o+m,width:this.videoWidth,height:this.videoHeight,mediaTime:Math.max(0,this.currentTime||0)+m/1e3,presentedFrames:f,processingDuration:c}),delete this._rvfcpolyfillmap[a]}else this._rvfcpolyfillmap[a]=requestAnimationFrame(c=>i(o,c))},a=Date.now(),s=performance.now();return this._rvfcpolyfillmap[a]=requestAnimationFrame(r=>i(s,r)),a},HTMLVideoElement.prototype.cancelVideoFrameCallback=function(l){cancelAnimationFrame(this._rvfcpolyfillmap[l]),delete this._rvfcpolyfillmap[l]});const n=class extends EventTarget{constructor(e={}){var s,r,o;super(),globalThis.Worker||this.destroy("Worker not supported"),n._test();const t=e.blendMode||"js",i=typeof createImageBitmap!="undefined"&&((s=e.asyncRender)!=null?s:!0),a=typeof OffscreenCanvas!="undefined"&&((r=e.offscreenRender)!=null?r:!0);this._onDemandRender="requestVideoFrameCallback"in HTMLVideoElement.prototype&&((o=e.onDemandRender)!=null?o:!0),this.timeOffset=e.timeOffset||0,this._video=e.video,this._canvasParent=null,this._video?(this._canvasParent=document.createElement("div"),this._canvasParent.className="JASSUB",this._canvasParent.style.position="relative",this._video.nextSibling?this._video.parentNode.insertBefore(this._canvasParent,this._video.nextSibling):this._video.parentNode.appendChild(this._canvasParent)):this._canvas||this.destroy("Don't know where to render: you should give video or canvas in options."),this._canvas=e.canvas||document.createElement("canvas"),this._canvas.style.display="block",this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none",this._canvasParent.appendChild(this._canvas),this._bufferCanvas=document.createElement("canvas"),this._bufferCtx=this._bufferCanvas.getContext("2d"),this._canvasctrl=a?this._canvas.transferControlToOffscreen():this._canvas,this._ctx=!a&&this._canvasctrl.getContext("2d"),this._lastRenderTime=0,this.debug=!!e.debug,this.prescaleFactor=e.prescaleFactor||1,this.prescaleHeightLimit=e.prescaleHeightLimit||1080,this.maxRenderHeight=e.maxRenderHeight||0,this._worker=new Worker(n._supportsWebAssembly?e.workerUrl||"jassub-worker.js":e.legacyWorkerUrl||"jassub-worker-legacy.js"),this._worker.onmessage=d=>this._onmessage(d),this._worker.onerror=d=>this._error(d),this._worker.postMessage({target:"init",asyncRender:i,width:this._canvas.width,height:this._canvas.height,preMain:!0,blendMode:t,subUrl:e.subUrl,subContent:e.subContent||null,fonts:e.fonts||[],availableFonts:e.availableFonts||{"liberation sans":"./default.woff2"},fallbackFont:e.fallbackFont||"liberation sans",debug:this.debug,targetFps:e.targetFps||24,dropAllAnimations:e.dropAllAnimations,libassMemoryLimit:e.libassMemoryLimit||0,libassGlyphLimit:e.libassGlyphLimit||0,hasAlphaBug:n._hasAlphaBug,useLocalFonts:"queryLocalFonts"in self&&!!e.useLocalFonts}),a===!0&&this.sendMessage("offscreenCanvas",null,[this._canvasctrl]),this.setVideo(e.video),this._onDemandRender&&(this.busy=!1,this._video.requestVideoFrameCallback(this._demandRender.bind(this)))}static _test(){if(n._supportsWebAssembly!==null)return null;const e=document.createElement("canvas"),t=e.getContext("2d");if(typeof ImageData.prototype.constructor=="function")try{new ImageData(new Uint8ClampedArray([0,0,0,0]),1,1)}catch{console.log("detected that ImageData is not constructable despite browser saying so"),window.ImageData=function(d,f,c){const m=t.createImageData(f,c);return d&&m.data.set(d),m}}try{if(typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function"){const o=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));o instanceof WebAssembly.Module&&(n._supportsWebAssembly=new WebAssembly.Instance(o)instanceof WebAssembly.Instance)}}catch{n._supportsWebAssembly=!1}const i=document.createElement("canvas"),a=i.getContext("2d");e.width=i.width=1,e.height=i.height=1,t.clearRect(0,0,1,1),a.clearRect(0,0,1,1);const s=a.getImageData(0,0,1,1).data;t.putImageData(new ImageData(new Uint8ClampedArray([0,255,0,0]),1,1),0,0),a.drawImage(e,0,0);const r=a.getImageData(0,0,1,1).data;n._hasAlphaBug=s[1]!==r[1],n._hasAlphaBug&&console.log("Detected a browser having issue with transparent pixels, applying workaround"),i.remove()}resize(e=0,t=0,i=0,a=0){let s=null;if((!e||!t)&&this._video){s=this._getVideoPosition();const r=this._computeCanvasSize((s.width||0)*(window.devicePixelRatio||1),(s.height||0)*(window.devicePixelRatio||1));e=r.width,t=r.height,i=s.y-(this._canvasParent.getBoundingClientRect().top-this._video.getBoundingClientRect().top),a=s.x}s!=null&&(this._canvas.style.top=i+"px",this._canvas.style.left=a+"px",this._canvas.style.width=s.width+"px",this._canvas.style.height=s.height+"px"),this._canvasctrl.width===e&&this._canvasctrl.height===t||(this._resizeTimeoutBuffer?(clearTimeout(this._resizeTimeoutBuffer),this._resizeTimeoutBuffer=setTimeout(()=>{this._resizeTimeoutBuffer=void 0,this._canvasctrl.width=e,this._canvasctrl.height=t,this.sendMessage("canvas",{width:e,height:t})},100)):(this._canvasctrl.width=e,this._canvasctrl.height=t,this.sendMessage("canvas",{width:e,height:t}),this._resizeTimeoutBuffer=setTimeout(()=>{this._resizeTimeoutBuffer=void 0},100)))}_getVideoPosition(){const e=this._video.videoWidth/this._video.videoHeight,{offsetWidth:t,offsetHeight:i}=this._video,a=t/i;let s=t,r=i;a>e?s=Math.floor(i*e):r=Math.floor(t/e);const o=(t-s)/2,d=(i-r)/2;return{width:s,height:r,x:o,y:d}}_computeCanvasSize(e=0,t=0){const i=this.prescaleFactor<=0?1:this.prescaleFactor;if(t<=0||e<=0)e=0,t=0;else{const a=i<1?-1:1;let s=t;a*s*i<=a*this.prescaleHeightLimit?s*=i:a*s<a*this.prescaleHeightLimit&&(s=this.prescaleHeightLimit),this.maxRenderHeight>0&&s>this.maxRenderHeight&&(s=this.maxRenderHeight),e*=s/t,t=s}return{width:e,height:t}}_timeupdate({type:e}){const i={seeking:!0,waiting:!0,playing:!1}[e];i!=null&&(this._playstate=i),this.setCurrentTime(this._video.paused||this._playstate,this._video.currentTime+this.timeOffset)}setVideo(e){e instanceof HTMLVideoElement?(this._removeListeners(),this._video=e,this._onDemandRender!==!0&&(this._playstate=e.paused,e.addEventListener("timeupdate",this._timeupdate.bind(this),!1),e.addEventListener("progress",this._timeupdate.bind(this),!1),e.addEventListener("waiting",this._timeupdate.bind(this),!1),e.addEventListener("seeking",this._timeupdate.bind(this),!1),e.addEventListener("playing",this._timeupdate.bind(this),!1),e.addEventListener("ratechange",this.setRate.bind(this),!1)),e.videoWidth>0&&this.resize(),e.addEventListener("resize",this.resize.bind(this)),typeof ResizeObserver!="undefined"&&(this._ro||(this._ro=new ResizeObserver(()=>this.resize())),this._ro.observe(e))):this._error("Video element invalid!")}runBenchmark(){this.sendMessage("runBenchmark")}setTrackByUrl(e){this.sendMessage("setTrackByUrl",{url:e})}setTrack(e){this.sendMessage("setTrack",{content:e})}freeTrack(){this.sendMessage("freeTrack")}setIsPaused(e){this.sendMessage("video",{isPaused:e})}setRate(e){this.sendMessage("video",{rate:e})}setCurrentTime(e,t,i){this.sendMessage("video",{isPaused:e,currentTime:t,rate:i})}createEvent(e){this.sendMessage("createEvent",{event:e})}setEvent(e,t){this.sendMessage("setEvent",{event:e,index:t})}removeEvent(e){this.sendMessage("removeEvent",{index:e})}getEvents(e){this._fetchFromWorker({target:"getEvents"},(t,{events:i})=>{e(t,i)})}createStyle(e){this.sendMessage("createStyle",{style:e})}setStyle(e,t){this.sendMessage("setStyle",{event:e,index:t})}removeStyle(e){this.sendMessage("removeStyle",{index:e})}getStyles(e){this._fetchFromWorker({target:"getStyles"},(t,{styles:i})=>{e(t,i)})}addFont(e){this.sendMessage("addFont",{font:e})}_sendLocalFont(e){try{queryLocalFonts().then(t=>{const i=t&&t.filter(a=>a.fullName.toLowerCase()===e);i&&i.length&&i[0].blob().then(a=>{a.arrayBuffer().then(s=>{this.addFont(new Uint8Array(s))})})})}catch(t){console.warn("Local fonts API:",t)}}_getLocalFont({font:e}){var t,i;try{const a=((t=navigator==null?void 0:navigator.permissions)==null?void 0:t.request)||((i=navigator==null?void 0:navigator.permissions)==null?void 0:i.query);a?a({name:"local-fonts"}).then(s=>{s.state==="granted"&&this._sendLocalFont(e)}):"queryLocalFonts"in self&&this._sendLocalFont(e)}catch(a){console.warn("Local fonts API:",a)}}_unbusy(){this.busy=!1}_demandRender(e,t){if(this._destroyed)return null;this.busy||(this.busy=!0,this.sendMessage("demand",{time:t.mediaTime+this.timeOffset})),this._video.requestVideoFrameCallback(this._demandRender.bind(this))}_render({images:e,async:t,times:i}){const a=Date.now();this._ctx.clearRect(0,0,this._canvasctrl.width,this._canvasctrl.height);for(const s of e)s.image&&(t?(this._ctx.drawImage(s.image,s.x,s.y),s.image.close()):(this._bufferCanvas.width=s.w,this._bufferCanvas.height=s.h,this._bufferCtx.putImageData(new ImageData(this._fixAlpha(new Uint8ClampedArray(s.image)),s.w,s.h),0,0),this._ctx.drawImage(this._bufferCanvas,s.x,s.y)));if(this.debug){i.drawTime=Date.now()-a;let s=0;for(const r in i)s+=i[r];console.log("Bitmaps: "+e.length+" Total: "+Math.round(s)+"ms",i)}}_fixAlpha(e){if(n._hasAlphaBug)for(let t=3;t<e.length;t+=4)e[t]=e[t]>1?e[t]:1;return e}_ready(){this.dispatchEvent(new CustomEvent("ready"))}sendMessage(e,t={},i){i?this._worker.postMessage(v({target:e,transferable:i},t),[...i]):this._worker.postMessage(v({target:e},t))}_fetchFromWorker(e,t){try{const i=e.target,a=setTimeout(()=>{r(new Error("Error: Timeout while try to fetch "+i))},5e3),s=({data:o})=>{o.target===i&&(t(null,o),this._worker.removeEventListener("message",s),this._worker.removeEventListener("error",r),clearTimeout(a))},r=o=>{t(o),this._worker.removeEventListener("message",s),this._worker.removeEventListener("error",r),clearTimeout(a)};this._worker.addEventListener("message",s),this._worker.addEventListener("error",r),this._worker.postMessage(e)}catch(i){this._error(i)}}_console({content:e,command:t}){console[t].apply(console,JSON.parse(e))}_onmessage({data:e}){this["_"+e.target]&&this["_"+e.target](e)}_error(e){throw e instanceof ErrorEvent||this.dispatchEvent(new ErrorEvent("error",{message:e instanceof Error?e.cause:e})),e instanceof Error?e:new Error(e instanceof ErrorEvent?e.message:"error",{cause:e})}_removeListeners(){this._video&&(this._ro&&this._ro.unobserve(this._video),this._video.removeEventListener("timeupdate",this._timeupdate),this._video.removeEventListener("progress",this._timeupdate),this._video.removeEventListener("waiting",this._timeupdate),this._video.removeEventListener("seeking",this._timeupdate),this._video.removeEventListener("playing",this._timeupdate),this._video.removeEventListener("ratechange",this.setRate),this._video.removeEventListener("resize",this.resize))}destroy(e){e&&this._error(e),this._video&&this._video.parentNode.removeChild(this._canvasParent),this._destroyed=!0,this._removeListeners(),this.sendMessage("destroy"),this._worker.terminate()}};let h=n;return _(h,"_supportsWebAssembly",null),_(h,"_hasAlphaBug",null),h});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jassub",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "libass Subtitle Renderer and Parser library for browsers",
5
5
  "main": "src/jassub.js",
6
6
  "files": [
package/src/jassub.js CHANGED
@@ -176,7 +176,7 @@ export default class JASSUB extends EventTarget {
176
176
  let videoSize = null
177
177
  if ((!width || !height) && this._video) {
178
178
  videoSize = this._getVideoPosition()
179
- const newsize = this._computeCanvasSize(videoSize.width || 0 * (window.devicePixelRatio || 1), videoSize.height || 0 * (window.devicePixelRatio || 1))
179
+ const newsize = this._computeCanvasSize((videoSize.width || 0) * (window.devicePixelRatio || 1), (videoSize.height || 0) * (window.devicePixelRatio || 1))
180
180
  width = newsize.width
181
181
  height = newsize.height
182
182
  top = videoSize.y - (this._canvasParent.getBoundingClientRect().top - this._video.getBoundingClientRect().top)
@@ -496,8 +496,9 @@ export default class JASSUB extends EventTarget {
496
496
  try {
497
497
  // electron by default has all permissions enabled, and it doesn't have requesting
498
498
  // if this happens, make sure you can query fonts
499
- if ('request' in navigator.permissions) {
500
- navigator.permissions.request({ name: 'local-fonts' }).then(permission => {
499
+ const query = navigator?.permissions?.request || navigator?.permissions?.query
500
+ if (query) {
501
+ query({ name: 'local-fonts' }).then(permission => {
501
502
  if (permission.state === 'granted') {
502
503
  this._sendLocalFont(font)
503
504
  }