subtitles-octopus

111

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/507157/1442600/subtitles-octopus.js

  1. // # The following lists all copyright notices and licenses for the
  2. // # work contained in JavascriptSubtitlesOctopus per project.
  3. //
  4. // # Project: subtitlesoctopus
  5. // License: Expat
  6. // Copyright: 2017-2021 JavascriptSubtitlesOctopus contributors
  7. //
  8. // # Project: brotli
  9. // License: Expat
  10. // Copyright: 2014 Google Inc.
  11. // 2015 The Chromium Authors.
  12. // 2016 Google Inc.
  13. // 2017 Google Inc.
  14. // 2018 Google Inc.
  15. // 2015 Google Inc.
  16. // 2013 Google Inc.
  17. // 2009, 2010, 2013-2016 by the Brotli Authors
  18. // 2010 Google Inc.
  19. //
  20. // # Project: expat
  21. // License: Expat
  22. // Copyright: 2019 Zhongyuan Zhou <zhouzhongyuan@huawei.com>
  23. // 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
  24. // 2022 Jeffrey Walton <noloader@gmail.com>
  25. // 2017 Václav Slavík <vaclav@slavik.io>
  26. // 2020 Kleber Tarcísio <klebertarcisio@yahoo.com.br>
  27. // 2022 Samanta Navarro <ferivoz@riseup.net>
  28. // 2020 Joe Orton <jorton@redhat.com>
  29. // 2021 Dong-hee Na <donghee.na@python.org>
  30. // 2016-2019 Sebastian Pipping <sebastian@pipping.org>
  31. // 2017 Joe Orton <jorton@redhat.com>
  32. // 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  33. // 2004-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  34. // 2017 Sebastian Pipping <sebastian@pipping.org>
  35. // 2004-2006 Karl Waclawek <karl@waclawek.net>
  36. // 2016 Cristian Rodríguez <crrodriguez@opensuse.org>
  37. // 2003-2006 Karl Waclawek <karl@waclawek.net>
  38. // 2006 Karl Waclawek <karl@waclawek.net>
  39. // 2001-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  40. // 2000-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  41. // 2017 Franek Korta <fkorta@gmail.com>
  42. // 2001-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  43. // 2006-2012 Karl Waclawek <karl@waclawek.net>
  44. // 2017 Benbuck Nason <bnason@netflix.com>
  45. // 2019 David Loffredo <loffredo@steptools.com>
  46. // 2021 Tim Bray <tbray@textuality.com>
  47. // 2018 Benjamin Peterson <benjamin@python.org>
  48. // 2017 Rhodri James <rhodri@wildebeest.org.uk>
  49. // 2017 Chanho Park <chanho61.park@samsung.com>
  50. // 2002-2005 Karl Waclawek <karl@waclawek.net>
  51. // 2016-2020 Sebastian Pipping <sebastian@pipping.org>
  52. // 2016 Gilles Espinasse <g.esp@free.fr>
  53. // 2016-2018 Sebastian Pipping <sebastian@pipping.org>
  54. // 2016 Gustavo Grieco <gustavo.grieco@imag.fr>
  55. // 2007 Karl Waclawek <karl@waclawek.net>
  56. // 2016 Ed Schouten <ed@nuxi.nl>
  57. // 2002-2016 Karl Waclawek <karl@waclawek.net>
  58. // 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  59. // 2016 Don Lewis <truckman@apache.org>
  60. // 2000-2017 Expat development team
  61. // 2002-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  62. // 2017 José Gutiérrez de la Concha <jose@zeroc.com>
  63. // 2000 Clark Cooper <coopercc@users.sourceforge.net>
  64. // 2017 Viktor Szakats <commit@vsz.me>
  65. // 2016 Gaurav <g.gupta@samsung.com>
  66. // 2002 Greg Stein <gstein@users.sourceforge.net>
  67. // 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
  68. // 2022 Jann Horn <jannh@google.com>
  69. // 2016 Eric Rahm <erahm@mozilla.com>
  70. // 2005-2012 Karl Waclawek <karl@waclawek.net>
  71. // 2022 Thijs Schreijer <thijs@thijsschreijer.nl>
  72. // 2020 Boris Kolpackov <boris@codesynthesis.com>
  73. // 2017-2019 Sebastian Pipping <sebastian@pipping.org>
  74. // 2005 Karl Waclawek <karl@waclawek.net>
  75. // 1999-2000 Thai Open Source Software Center Ltd
  76. // 2000-2017 Expat development team / 1997-2000 Thai Open Source Software Center Ltd
  77. // 2005-2007 Steven Solie <steven@solie.ca>
  78. // 2016-2021 Sebastian Pipping <sebastian@pipping.org>
  79. // 2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  80. // 2017 Alexander Bluhm <alexander.bluhm@gmx.net>
  81. // 2018 Anton Maklakov <antmak.pub@gmail.com>
  82. // 2017 Rolf Eike Beer <eike@sf-mail.de>
  83. // 2017-2021 Sebastian Pipping <sebastian@pipping.org>
  84. // 2016-2022 Sebastian Pipping <sebastian@pipping.org>
  85. // 1997-2000 Thai Open Source Software Center Ltd
  86. // 2002-2009 Karl Waclawek <karl@waclawek.net>
  87. // 2002 Karl Waclawek <karl@waclawek.net>
  88. // 2020 Tim Gates <tim.gates@iress.com>
  89. // 2004-2009 Karl Waclawek <karl@waclawek.net>
  90. // 2016 Pascal Cuoq <cuoq@trust-in-soft.com>
  91. // 2019-2020 Ben Wagner <bungeman@chromium.org>
  92. // 2001-2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  93. // 2002-2006 Karl Waclawek <karl@waclawek.net>
  94. // 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  95. // 2018 Yury Gribov <tetra2005@gmail.com>
  96. // 2005-2009 Steven Solie <steven@solie.ca>
  97. // 2003 Greg Stein <gstein@users.sourceforge.net>
  98. // 2022 Martin Ettl <ettl.martin78@googlemail.com>
  99. // 2018 Mariusz Zaborski <oshogbo@vexillium.org>
  100. // 2016-2017 Sebastian Pipping <sebastian@pipping.org>
  101. // 2001-2002 Greg Stein <gstein@users.sourceforge.net>
  102. // 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  103. // 2005-2006 Karl Waclawek <karl@waclawek.net>
  104. // 2017 Hans Wennborg <hans@chromium.org>
  105. // 2016 Thomas Beutlich <tc@tbeu.de>
  106. // 2000-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
  107. // 2019 Vadim Zeitlin <vadim@zeitlins.org>
  108. //
  109. // # Project: freetype
  110. // License: FTL
  111. // Copyright: 2009-2013 Adobe Systems Incorporated.
  112. // 2016-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  113. // 2013 Adobe Systems Incorporated.
  114. // 2004-2022 David Turner, Robert Wilhelm, Werner Lemberg, and George Williams.
  115. // 2018-2022 Armin Hasitzka, David Turner, Robert Wilhelm, and Werner Lemberg.
  116. // 2013-2022 Google, Inc.
  117. // 1996-2022 David Turner, Robert Wilhelm, Werner Lemberg and Detlef Würkner.
  118. // 2007-2014 Adobe Systems Incorporated.
  119. // 2008-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  120. // 2006-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  121. // 2007-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  122. // 2004-2022 Masatake YAMATO, Redhat K.K,
  123. // 1996-2022 David Turner, Robert Wilhelm, Werner Lemberg, and Detlef Wuerkner.
  124. // 1996-2022 David Turner, Robert Wilhelm, and Werner Lemberg
  125. // 1995-2016 Jean-loup Gailly, Mark Adler
  126. // 2021-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  127. // 2004-2022 David Turner, Robert Wilhelm, Werner Lemberg and George Williams.
  128. // 2018-2022 David Turner, Robert Wilhelm, Dominik Röttsches, and Werner Lemberg.
  129. // 2009-2022 Oran Agra and Mickey Gabel.
  130. // 1995-2017 Jean-loup Gailly
  131. // 2010-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  132. // 2003 Huw D M Davies for Codeweavers
  133. // 2013-2014 Adobe Systems Incorporated.
  134. // 2005-2022 David Turner.
  135. // 1995-2011, 2016 Mark Adler
  136. // 2010-2022 Joel Klinghed.
  137. // 2002-2022 Roberto Alameda.
  138. // 1996-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  139. // 2011-2013 Adobe Systems Incorporated.
  140. // 2005-2022 Werner Lemberg and Detlef Würkner.
  141. // 2013-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  142. // 2007 Dmitry Timoshkov for Codeweavers
  143. // 2002-2022 David Turner, Robert Wilhelm, and Werner Lemberg
  144. // 1996-2022 Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg.
  145. // 1995-2017 Mark Adler
  146. // 2000-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  147. // 2022 David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti.
  148. // 2006-2013 Adobe Systems Incorporated.
  149. // 1995-2003, 2010 Mark Adler
  150. // 2012-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  151. // 2007-2022 Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>.
  152. // 2007-2022 David Turner.
  153. // 2017-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  154. // 2008-2022 David Turner, Robert Wilhelm, Werner Lemberg, and suzuki toshiya.
  155. // 1995-2005, 2010 Mark Adler
  156. // 2018-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  157. // 2005-2022 suzuki toshiya, Masatake YAMATO, Red Hat K.K.,
  158. // 2020-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  159. // 2007-2022 Derek Clegg and Michael Toftdal.
  160. // 2004-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  161. // 2013 Google, Inc.
  162. // 2019-2022 Nikhil Ramakrishnan, David Turner, Robert Wilhelm, and Werner Lemberg.
  163. // 2004-2022 Albert Chin-A-Young.
  164. // 2009-2014 Adobe Systems Incorporated.
  165. // 2003-2022 Masatake YAMATO, Redhat K.K.,
  166. // 2002-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  167. // 2007-2013 Adobe Systems Incorporated.
  168. // 2007-2022 Dereg Clegg and Michael Toftdal.
  169. // 2003-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  170. // 2004-2022 Masatake YAMATO and Redhat K.K.
  171. // 2004-2022 Masatake YAMATO, Red Hat K.K.,
  172. // 2001, 2012 David Turner, Robert Wilhelm, and Werner Lemberg.
  173. // 2001-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  174. // 1995-2022 Jean-loup Gailly, Mark Adler
  175. // 1995-2022 Mark Adler
  176. // 2004-2019 Mark Adler
  177. // 1990, 1994, 1998 The Open Group
  178. // 1995-2019 Mark Adler
  179. // 2005-2022 David Turner, Robert Wilhelm, and Werner Lemberg.
  180. // 2004-2022 suzuki toshiya, Masatake YAMATO, Red Hat K.K.,
  181. //
  182. // License: public-domain
  183. // Copyright: 2001 Alexander Peslyak and it is hereby released to the
  184. //
  185. // License: Zlib
  186. // Copyright: 1995-2022 Jean-loup Gailly and Mark Adler
  187. //
  188. // License: Expat
  189. // Copyright: 2000-2001, 2004 Francesco Zappa Nardelli
  190. // 2001-2004 Francesco Zappa Nardelli
  191. // 2003 Francesco Zappa Nardelli
  192. // 2001-2015 Francesco Zappa Nardelli
  193. // 2001-2004, 2011 Francesco Zappa Nardelli
  194. // 2000-2002 Francesco Zappa Nardelli
  195. // 2000 Computing Research Labs, New Mexico State University
  196. // 2001-2014 Francesco Zappa Nardelli
  197. // 2001-2002, 2012 Francesco Zappa Nardelli
  198. // 2001-2002 Francesco Zappa Nardelli
  199. // 2001-2008, 2011, 2013-2014 Francesco Zappa Nardelli
  200. // 2000-2003, 2006, 2010 Francesco Zappa Nardelli
  201. // 2000-2001, 2003 Francesco Zappa Nardelli
  202. // 2000-2004, 2006-2011, 2013-2014 Francesco Zappa Nardelli
  203. // 2000-2010, 2012-2014 Francesco Zappa Nardelli
  204. //
  205. // License: BSL-1.0
  206. // Copyright: 2019 nyorain
  207. //
  208. // # Project: fribidi
  209. // License: LGPL-2.1+
  210. // Copyright: 1999-2000, 2017 Dov Grobgeld
  211. // 1999-2000 Dov Grobgeld
  212. // 2004 Behdad Esfahbod
  213. // 2001-2002, 2004 Behdad Esfahbod
  214. // 2009 Behdad Esfahbod
  215. // 2017 Dov Grobgeld
  216. // 2004-2005 Behdad Esfahbod
  217. // 2004 Sharif FarsiWeb, Inc.
  218. // 2015, 2017 Dov Grobgeld
  219. // 2005 Behdad Esfahbod
  220. // 2001 Behdad Esfahbod.
  221. // 2001-2002 Behdad Esfahbod
  222. // 2004 Sharif FarsiWeb, Inc
  223. //
  224. // # Project: fontconfig
  225. // License: NTP~disclaimer
  226. // Copyright: 2002 Keith Packard
  227. // 2009 Roozbeh Pournader
  228. // 2000 Tuomas J. Lukka
  229. // 2006 Keith Packard
  230. // 2008 Red Hat, Inc.
  231. // 2000-2007 Keith Packard / 2005 Patrick Lam / 2009 Roozbeh Pournader / 2008,2009 Red Hat, Inc. / 2008 Danilo Šegan / 2012 Google, Inc.
  232. // 2001 Keith Packard
  233. // 2012 Google, Inc.
  234. // 2012 Red Hat, Inc.
  235. // 2013 Raimund Steger
  236. // 2008,2009 Red Hat, Inc.
  237. // 2000-2007 Keith Packard
  238. // 2005 Patrick Lam
  239. // 2003 Keith Packard
  240. // 息 2006 Keith Packard
  241. // 2020 Zoltan Vandrus
  242. // 2014 Red Hat, Inc.
  243. // 2007 Keith Packard
  244. // 2018 Akira TAGOH
  245. // 2008 Danilo Šegan
  246. // 息 2010 Behdad Esfahbod
  247. // 2015 Akira TAGOH
  248. // 2008-2009 Red Hat, Inc.
  249. // 2016 Akira TAGOH
  250. // 2000 Keith Packard
  251. // 2010 Behdad Esfahbod
  252. // 2013 Google, Inc.
  253. // 2013 Akira TAGOH
  254. //
  255. // License: MIT~old
  256. // Copyright: 2009-2010 Red Hat, Inc.
  257. // 2011-2013 Google, Inc.
  258. // 2007 Chris Wilson
  259. //
  260. // License: public-domain
  261. // Copyright: 2008,2009 Red Hat, Inc.
  262. // 2009 Roozbeh Pournader
  263. // 2012 Google, Inc.
  264. // 2008 Danilo Šegan
  265. // 2005 Patrick Lam
  266. // 2000-2007 Keith Packard
  267. //
  268. // License: Expat
  269. // Copyright: 2002-2003 Juliusz Chroboczek
  270. //
  271. // # Project: harfbuzz
  272. // License: NTP~disclaimer
  273. // Copyright: 2002 Keith Packard
  274. // 2014 Google, Inc.
  275. //
  276. // License: MIT~old
  277. // Copyright: 2012 Mozilla Foundation.
  278. // 2004, 2007, 2009 Red Hat, Inc.
  279. // 2009 Red Hat, Inc.
  280. // 2015 Google, Inc.
  281. // 2014 Google, Inc.
  282. // 2018 Ebrahim Byagowi
  283. // 2016 Igalia S.L.
  284. // 2018 Ebrahim Byagowi.
  285. // 2011 Martin Hosken
  286. // 2019 Ebrahim Byagowi
  287. // 2020 Ebrahim Byagowi
  288. // 1998-2004 David Turner and Werner Lemberg
  289. // 2013 Red Hat, Inc.
  290. // 2011-2012 Google, Inc.
  291. // 2011 SIL International
  292. // 2018 Khaled Hosny
  293. // 2018 Google, Inc.
  294. // 2019-2020 Ebrahim Byagowi
  295. // 2022 Google, Inc.
  296. // 2012 Google, Inc.
  297. // 2017 Google, Inc.
  298. // 2007-2009 Red Hat, Inc.
  299. // 2011 Codethink Limited
  300. // 2013 Google, Inc.
  301. // 2015-2019 Ebrahim Byagowi
  302. // 2016 Google, Inc.
  303. // 2011 Google, Inc.
  304. //
  305. // # Project: libass
  306. // License: public-domain
  307. // Copyright: 2006-2016 libass contributors
  308. //
  309. // License: NTP
  310. // Copyright: 1994 Sun Microsystems, Inc.
  311. // 2016 Oleg Oshmyan <chortos@inbox.lv>
  312. // 1988-1993 The Regents of the University of California.
  313. //
  314. // License: ISC
  315. // Copyright: 2015 Oleg Oshmyan <chortos@inbox.lv>
  316. // 2011-2014 Yu Zhuohuang <yuzhuohuang@qq.com>
  317. // 2013 rcombs <rcombs@rcombs.me>
  318. // 2016 Vabishchevich Nikolay <vabnick@gmail.com>
  319. // 2022 libass contributors
  320. // 2015 Stephan Vedder <stephan.vedder@gmail.com>
  321. // 2015 Vabishchevich Nikolay <vabnick@gmail.com>
  322. // interest in the
  323. // 2006-2016 libass contributors
  324. // 2021 libass contributors
  325. // 2017 Vabishchevich Nikolay <vabnick@gmail.com>
  326. // 2011 Grigori Goronzy <greg@chown.ath.cx>
  327. // 2010 Grigori Goronzy <greg@geekmind.org>
  328. // 2014 Vabishchevich Nikolay <vabnick@gmail.com>
  329. // 2013 Stefano Pigozzi <stefano.pigozzi@gmail.com>
  330. // 2015 Grigori Goronzy <greg@kinoho.net>
  331. // 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
  332. // 2009 Grigori Goronzy <greg@geekmind.org>
  333. //
  334. // # The following section contains the full license text or
  335. // # where permitted a shorter notice for all works contained
  336. // # in JavascriptSubtitlesOctopus listed above
  337. // #
  338. // # Note that the shortnames used here are identical to those used by Debian
  339. // # and will in some cases differ from SPDX identifiers. See below.
  340. // #
  341. // # Debian-name | SPDX-name
  342. // # ---------------+-------------------
  343. // # MIT~old | MIT-Modern-Variant
  344. // # Expat | MIT
  345. // # NTP~disclaimer | (None; it is NTP with a more verbose warranty disclaimer)
  346. //
  347. // License: Expat
  348. // Permission is hereby granted, free of charge, to any person obtaining
  349. // a copy of this software and associated documentation files (the
  350. // "Software"), to deal in the Software without restriction, including
  351. // without limitation the rights to use, copy, modify, merge, publish,
  352. // distribute, sublicense, and/or sell copies of the Software, and to permit
  353. // persons to whom the Software is furnished to do so, subject to the
  354. // following conditions:
  355. // .
  356. // The above copyright notice and this permission notice shall be included
  357. // in all copies or substantial portions of the Software.
  358. // .
  359. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  360. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  361. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  362. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  363. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  364. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  365. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  366. //
  367. // License: FTL
  368. // Portions of this software are copyright © 2021 The FreeType
  369. // Project (www.freetype.org). All rights reserved.
  370. // A copy of the FreeType License can be obtained at
  371. // https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT
  372. //
  373. // License: ISC
  374. // Permission to use, copy, modify, and/or distribute this software for any
  375. // purpose with or without fee is hereby granted, provided that the above
  376. // copyright notice and this permission notice appear in all copies.
  377. // .
  378. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  379. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  380. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  381. // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  382. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  383. // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  384. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  385. //
  386. // License: MIT~old
  387. // Permission is hereby granted, without written agreement and without
  388. // license or royalty fees, to use, copy, modify, and distribute this
  389. // software and its documentation for any purpose, provided that the
  390. // above copyright notice and the following two paragraphs appear in
  391. // all copies of this software.
  392. // .
  393. // IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
  394. // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  395. // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  396. // IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  397. // DAMAGE.
  398. // .
  399. // THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
  400. // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  401. // FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
  402. // ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
  403. // PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS
  404. //
  405. // License: NTP
  406. // Permission to use, copy, modify, and distribute this
  407. // software and its documentation for any purpose and without
  408. // fee is hereby granted, provided that the above copyright
  409. // notice appear in all copies. The University of California
  410. // makes no representations about the suitability of this
  411. // software for any purpose. It is provided "as is" without
  412. // express or implied warranty.
  413. //
  414. // License: NTP~disclaimer
  415. // Permission to use, copy, modify, distribute, and sell this software and its
  416. // documentation for any purpose is hereby granted without fee, provided that
  417. // the above copyright notice appear in all copies and that both that
  418. // copyright notice and this permission notice appear in supporting
  419. // documentation, and that the name of the author(s) not be used in
  420. // advertising or publicity pertaining to distribution of the software without
  421. // specific, written prior permission. The authors make no
  422. // representations about the suitability of this software for any purpose. It
  423. // is provided "as is" without express or implied warranty.
  424. // .
  425. // THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  426. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  427. // EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  428. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  429. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  430. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  431. // PERFORMANCE OF THIS SOFTWARE.
  432. //
  433. // License: Zlib
  434. // This software is provided 'as-is', without any express or implied
  435. // warranty. In no event will the authors be held liable for any damages
  436. // arising from the use of this software.
  437. // .
  438. // Permission is granted to anyone to use this software for any purpose,
  439. // including commercial applications, and to alter it and redistribute it
  440. // freely, subject to the following restrictions:
  441. // .
  442. // 1. The origin of this software must not be misrepresented; you must not
  443. // claim that you wrote the original software. If you use this software
  444. // in a product, an acknowledgment in the product documentation would be
  445. // appreciated but is not required.
  446. // 2. Altered source versions must be plainly marked as such, and must not be
  447. // misrepresented as being the original software.
  448. // 3. This notice may not be removed or altered from any source distribution.
  449. //
  450. // License: BSL-1
  451. // Boost Software License - Version 1.0 - August 17th, 2003
  452. // .
  453. // Permission is hereby granted, free of charge, to any person or organization
  454. // obtaining a copy of the software and accompanying documentation covered by
  455. // this license (the "Software") to use, reproduce, display, distribute,
  456. // execute, and transmit the Software, and to prepare derivative works of the
  457. // Software, and to permit third-parties to whom the Software is furnished to
  458. // do so, all subject to the following:
  459. // .
  460. // The copyright notices in the Software and this entire statement, including
  461. // the above license grant, this restriction and the following disclaimer,
  462. // must be included in all copies of the Software, in whole or in part, and
  463. // all derivative works of the Software, unless such copies or derivative
  464. // works are solely in the form of machine-executable object code generated by
  465. // a source language processor.
  466. // .
  467. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  468. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  469. // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  470. // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  471. // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  472. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  473. // DEALINGS IN THE SOFTWARE.
  474. //
  475. // License: LGPL-2.1
  476. // GNU LESSER GENERAL PUBLIC LICENSE
  477. // Version 2.1, February 1999
  478. // .
  479. // Copyright (C) 1991, 1999 Free Software Foundation, Inc.
  480. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  481. // Everyone is permitted to copy and distribute verbatim copies
  482. // of this license document, but changing it is not allowed.
  483. // .
  484. // [This is the first released version of the Lesser GPL. It also counts
  485. // as the successor of the GNU Library Public License, version 2, hence
  486. // the version number 2.1.]
  487. // .
  488. // Preamble
  489. // .
  490. // The licenses for most software are designed to take away your
  491. // freedom to share and change it. By contrast, the GNU General Public
  492. // Licenses are intended to guarantee your freedom to share and change
  493. // free software--to make sure the software is free for all its users.
  494. // .
  495. // This license, the Lesser General Public License, applies to some
  496. // specially designated software packages--typically libraries--of the
  497. // Free Software Foundation and other authors who decide to use it. You
  498. // can use it too, but we suggest you first think carefully about whether
  499. // this license or the ordinary General Public License is the better
  500. // strategy to use in any particular case, based on the explanations below.
  501. // .
  502. // When we speak of free software, we are referring to freedom of use,
  503. // not price. Our General Public Licenses are designed to make sure that
  504. // you have the freedom to distribute copies of free software (and charge
  505. // for this service if you wish); that you receive source code or can get
  506. // it if you want it; that you can change the software and use pieces of
  507. // it in new free programs; and that you are informed that you can do
  508. // these things.
  509. // .
  510. // To protect your rights, we need to make restrictions that forbid
  511. // distributors to deny you these rights or to ask you to surrender these
  512. // rights. These restrictions translate to certain responsibilities for
  513. // you if you distribute copies of the library or if you modify it.
  514. // .
  515. // For example, if you distribute copies of the library, whether gratis
  516. // or for a fee, you must give the recipients all the rights that we gave
  517. // you. You must make sure that they, too, receive or can get the source
  518. // code. If you link other code with the library, you must provide
  519. // complete object files to the recipients, so that they can relink them
  520. // with the library after making changes to the library and recompiling
  521. // it. And you must show them these terms so they know their rights.
  522. // .
  523. // We protect your rights with a two-step method: (1) we copyright the
  524. // library, and (2) we offer you this license, which gives you legal
  525. // permission to copy, distribute and/or modify the library.
  526. // .
  527. // To protect each distributor, we want to make it very clear that
  528. // there is no warranty for the free library. Also, if the library is
  529. // modified by someone else and passed on, the recipients should know
  530. // that what they have is not the original version, so that the original
  531. // author's reputation will not be affected by problems that might be
  532. // introduced by others.
  533. // .
  534. // Finally, software patents pose a constant threat to the existence of
  535. // any free program. We wish to make sure that a company cannot
  536. // effectively restrict the users of a free program by obtaining a
  537. // restrictive license from a patent holder. Therefore, we insist that
  538. // any patent license obtained for a version of the library must be
  539. // consistent with the full freedom of use specified in this license.
  540. // .
  541. // Most GNU software, including some libraries, is covered by the
  542. // ordinary GNU General Public License. This license, the GNU Lesser
  543. // General Public License, applies to certain designated libraries, and
  544. // is quite different from the ordinary General Public License. We use
  545. // this license for certain libraries in order to permit linking those
  546. // libraries into non-free programs.
  547. // .
  548. // When a program is linked with a library, whether statically or using
  549. // a shared library, the combination of the two is legally speaking a
  550. // combined work, a derivative of the original library. The ordinary
  551. // General Public License therefore permits such linking only if the
  552. // entire combination fits its criteria of freedom. The Lesser General
  553. // Public License permits more lax criteria for linking other code with
  554. // the library.
  555. // .
  556. // We call this license the "Lesser" General Public License because it
  557. // does Less to protect the user's freedom than the ordinary General
  558. // Public License. It also provides other free software developers Less
  559. // of an advantage over competing non-free programs. These disadvantages
  560. // are the reason we use the ordinary General Public License for many
  561. // libraries. However, the Lesser license provides advantages in certain
  562. // special circumstances.
  563. // .
  564. // For example, on rare occasions, there may be a special need to
  565. // encourage the widest possible use of a certain library, so that it becomes
  566. // a de-facto standard. To achieve this, non-free programs must be
  567. // allowed to use the library. A more frequent case is that a free
  568. // library does the same job as widely used non-free libraries. In this
  569. // case, there is little to gain by limiting the free library to free
  570. // software only, so we use the Lesser General Public License.
  571. // .
  572. // In other cases, permission to use a particular library in non-free
  573. // programs enables a greater number of people to use a large body of
  574. // free software. For example, permission to use the GNU C Library in
  575. // non-free programs enables many more people to use the whole GNU
  576. // operating system, as well as its variant, the GNU/Linux operating
  577. // system.
  578. // .
  579. // Although the Lesser General Public License is Less protective of the
  580. // users' freedom, it does ensure that the user of a program that is
  581. // linked with the Library has the freedom and the wherewithal to run
  582. // that program using a modified version of the Library.
  583. // .
  584. // The precise terms and conditions for copying, distribution and
  585. // modification follow. Pay close attention to the difference between a
  586. // "work based on the library" and a "work that uses the library". The
  587. // former contains code derived from the library, whereas the latter must
  588. // be combined with the library in order to run.
  589. // .
  590. // GNU LESSER GENERAL PUBLIC LICENSE
  591. // TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  592. // .
  593. // 0. This License Agreement applies to any software library or other
  594. // program which contains a notice placed by the copyright holder or
  595. // other authorized party saying it may be distributed under the terms of
  596. // this Lesser General Public License (also called "this License").
  597. // Each licensee is addressed as "you".
  598. // .
  599. // A "library" means a collection of software functions and/or data
  600. // prepared so as to be conveniently linked with application programs
  601. // (which use some of those functions and data) to form executables.
  602. // .
  603. // The "Library", below, refers to any such software library or work
  604. // which has been distributed under these terms. A "work based on the
  605. // Library" means either the Library or any derivative work under
  606. // copyright law: that is to say, a work containing the Library or a
  607. // portion of it, either verbatim or with modifications and/or translated
  608. // straightforwardly into another language. (Hereinafter, translation is
  609. // included without limitation in the term "modification".)
  610. // .
  611. // "Source code" for a work means the preferred form of the work for
  612. // making modifications to it. For a library, complete source code means
  613. // all the source code for all modules it contains, plus any associated
  614. // interface definition files, plus the scripts used to control compilation
  615. // and installation of the library.
  616. // .
  617. // Activities other than copying, distribution and modification are not
  618. // covered by this License; they are outside its scope. The act of
  619. // running a program using the Library is not restricted, and output from
  620. // such a program is covered only if its contents constitute a work based
  621. // on the Library (independent of the use of the Library in a tool for
  622. // writing it). Whether that is true depends on what the Library does
  623. // and what the program that uses the Library does.
  624. //
  625. // 1. You may copy and distribute verbatim copies of the Library's
  626. // complete source code as you receive it, in any medium, provided that
  627. // you conspicuously and appropriately publish on each copy an
  628. // appropriate copyright notice and disclaimer of warranty; keep intact
  629. // all the notices that refer to this License and to the absence of any
  630. // warranty; and distribute a copy of this License along with the
  631. // Library.
  632. // .
  633. // You may charge a fee for the physical act of transferring a copy,
  634. // and you may at your option offer warranty protection in exchange for a
  635. // fee.
  636. // .
  637. // 2. You may modify your copy or copies of the Library or any portion
  638. // of it, thus forming a work based on the Library, and copy and
  639. // distribute such modifications or work under the terms of Section 1
  640. // above, provided that you also meet all of these conditions:
  641. // .
  642. // a) The modified work must itself be a software library.
  643. // .
  644. // b) You must cause the files modified to carry prominent notices
  645. // stating that you changed the files and the date of any change.
  646. // .
  647. // c) You must cause the whole of the work to be licensed at no
  648. // charge to all third parties under the terms of this License.
  649. // .
  650. // d) If a facility in the modified Library refers to a function or a
  651. // table of data to be supplied by an application program that uses
  652. // the facility, other than as an argument passed when the facility
  653. // is invoked, then you must make a good faith effort to ensure that,
  654. // in the event an application does not supply such function or
  655. // table, the facility still operates, and performs whatever part of
  656. // its purpose remains meaningful.
  657. // .
  658. // (For example, a function in a library to compute square roots has
  659. // a purpose that is entirely well-defined independent of the
  660. // application. Therefore, Subsection 2d requires that any
  661. // application-supplied function or table used by this function must
  662. // be optional: if the application does not supply it, the square
  663. // root function must still compute square roots.)
  664. // .
  665. // These requirements apply to the modified work as a whole. If
  666. // identifiable sections of that work are not derived from the Library,
  667. // and can be reasonably considered independent and separate works in
  668. // themselves, then this License, and its terms, do not apply to those
  669. // sections when you distribute them as separate works. But when you
  670. // distribute the same sections as part of a whole which is a work based
  671. // on the Library, the distribution of the whole must be on the terms of
  672. // this License, whose permissions for other licensees extend to the
  673. // entire whole, and thus to each and every part regardless of who wrote
  674. // it.
  675. // .
  676. // Thus, it is not the intent of this section to claim rights or contest
  677. // your rights to work written entirely by you; rather, the intent is to
  678. // exercise the right to control the distribution of derivative or
  679. // collective works based on the Library.
  680. // .
  681. // In addition, mere aggregation of another work not based on the Library
  682. // with the Library (or with a work based on the Library) on a volume of
  683. // a storage or distribution medium does not bring the other work under
  684. // the scope of this License.
  685. // .
  686. // 3. You may opt to apply the terms of the ordinary GNU General Public
  687. // License instead of this License to a given copy of the Library. To do
  688. // this, you must alter all the notices that refer to this License, so
  689. // that they refer to the ordinary GNU General Public License, version 2,
  690. // instead of to this License. (If a newer version than version 2 of the
  691. // ordinary GNU General Public License has appeared, then you can specify
  692. // that version instead if you wish.) Do not make any other change in
  693. // these notices.
  694. // .
  695. // Once this change is made in a given copy, it is irreversible for
  696. // that copy, so the ordinary GNU General Public License applies to all
  697. // subsequent copies and derivative works made from that copy.
  698. // .
  699. // This option is useful when you wish to copy part of the code of
  700. // the Library into a program that is not a library.
  701. // .
  702. // 4. You may copy and distribute the Library (or a portion or
  703. // derivative of it, under Section 2) in object code or executable form
  704. // under the terms of Sections 1 and 2 above provided that you accompany
  705. // it with the complete corresponding machine-readable source code, which
  706. // must be distributed under the terms of Sections 1 and 2 above on a
  707. // medium customarily used for software interchange.
  708. // .
  709. // If distribution of object code is made by offering access to copy
  710. // from a designated place, then offering equivalent access to copy the
  711. // source code from the same place satisfies the requirement to
  712. // distribute the source code, even though third parties are not
  713. // compelled to copy the source along with the object code.
  714. // .
  715. // 5. A program that contains no derivative of any portion of the
  716. // Library, but is designed to work with the Library by being compiled or
  717. // linked with it, is called a "work that uses the Library". Such a
  718. // work, in isolation, is not a derivative work of the Library, and
  719. // therefore falls outside the scope of this License.
  720. // .
  721. // However, linking a "work that uses the Library" with the Library
  722. // creates an executable that is a derivative of the Library (because it
  723. // contains portions of the Library), rather than a "work that uses the
  724. // library". The executable is therefore covered by this License.
  725. // Section 6 states terms for distribution of such executables.
  726. // .
  727. // When a "work that uses the Library" uses material from a header file
  728. // that is part of the Library, the object code for the work may be a
  729. // derivative work of the Library even though the source code is not.
  730. // Whether this is true is especially significant if the work can be
  731. // linked without the Library, or if the work is itself a library. The
  732. // threshold for this to be true is not precisely defined by law.
  733. // .
  734. // If such an object file uses only numerical parameters, data
  735. // structure layouts and accessors, and small macros and small inline
  736. // functions (ten lines or less in length), then the use of the object
  737. // file is unrestricted, regardless of whether it is legally a derivative
  738. // work. (Executables containing this object code plus portions of the
  739. // Library will still fall under Section 6.)
  740. // .
  741. // Otherwise, if the work is a derivative of the Library, you may
  742. // distribute the object code for the work under the terms of Section 6.
  743. // Any executables containing that work also fall under Section 6,
  744. // whether or not they are linked directly with the Library itself.
  745. // .
  746. // 6. As an exception to the Sections above, you may also combine or
  747. // link a "work that uses the Library" with the Library to produce a
  748. // work containing portions of the Library, and distribute that work
  749. // under terms of your choice, provided that the terms permit
  750. // modification of the work for the customer's own use and reverse
  751. // engineering for debugging such modifications.
  752. // .
  753. // You must give prominent notice with each copy of the work that the
  754. // Library is used in it and that the Library and its use are covered by
  755. // this License. You must supply a copy of this License. If the work
  756. // during execution displays copyright notices, you must include the
  757. // copyright notice for the Library among them, as well as a reference
  758. // directing the user to the copy of this License. Also, you must do one
  759. // of these things:
  760. // .
  761. // a) Accompany the work with the complete corresponding
  762. // machine-readable source code for the Library including whatever
  763. // changes were used in the work (which must be distributed under
  764. // Sections 1 and 2 above); and, if the work is an executable linked
  765. // with the Library, with the complete machine-readable "work that
  766. // uses the Library", as object code and/or source code, so that the
  767. // user can modify the Library and then relink to produce a modified
  768. // executable containing the modified Library. (It is understood
  769. // that the user who changes the contents of definitions files in the
  770. // Library will not necessarily be able to recompile the application
  771. // to use the modified definitions.)
  772. // .
  773. // b) Use a suitable shared library mechanism for linking with the
  774. // Library. A suitable mechanism is one that (1) uses at run time a
  775. // copy of the library already present on the user's computer system,
  776. // rather than copying library functions into the executable, and (2)
  777. // will operate properly with a modified version of the library, if
  778. // the user installs one, as long as the modified version is
  779. // interface-compatible with the version that the work was made with.
  780. // .
  781. // c) Accompany the work with a written offer, valid for at
  782. // least three years, to give the same user the materials
  783. // specified in Subsection 6a, above, for a charge no more
  784. // than the cost of performing this distribution.
  785. // .
  786. // d) If distribution of the work is made by offering access to copy
  787. // from a designated place, offer equivalent access to copy the above
  788. // specified materials from the same place.
  789. // .
  790. // e) Verify that the user has already received a copy of these
  791. // materials or that you have already sent this user a copy.
  792. // .
  793. // For an executable, the required form of the "work that uses the
  794. // Library" must include any data and utility programs needed for
  795. // reproducing the executable from it. However, as a special exception,
  796. // the materials to be distributed need not include anything that is
  797. // normally distributed (in either source or binary form) with the major
  798. // components (compiler, kernel, and so on) of the operating system on
  799. // which the executable runs, unless that component itself accompanies
  800. // the executable.
  801. // .
  802. // It may happen that this requirement contradicts the license
  803. // restrictions of other proprietary libraries that do not normally
  804. // accompany the operating system. Such a contradiction means you cannot
  805. // use both them and the Library together in an executable that you
  806. // distribute.
  807. // .
  808. // 7. You may place library facilities that are a work based on the
  809. // Library side-by-side in a single library together with other library
  810. // facilities not covered by this License, and distribute such a combined
  811. // library, provided that the separate distribution of the work based on
  812. // the Library and of the other library facilities is otherwise
  813. // permitted, and provided that you do these two things:
  814. // .
  815. // a) Accompany the combined library with a copy of the same work
  816. // based on the Library, uncombined with any other library
  817. // facilities. This must be distributed under the terms of the
  818. // Sections above.
  819. // .
  820. // b) Give prominent notice with the combined library of the fact
  821. // that part of it is a work based on the Library, and explaining
  822. // where to find the accompanying uncombined form of the same work.
  823. // .
  824. // 8. You may not copy, modify, sublicense, link with, or distribute
  825. // the Library except as expressly provided under this License. Any
  826. // attempt otherwise to copy, modify, sublicense, link with, or
  827. // distribute the Library is void, and will automatically terminate your
  828. // rights under this License. However, parties who have received copies,
  829. // or rights, from you under this License will not have their licenses
  830. // terminated so long as such parties remain in full compliance.
  831. // .
  832. // 9. You are not required to accept this License, since you have not
  833. // signed it. However, nothing else grants you permission to modify or
  834. // distribute the Library or its derivative works. These actions are
  835. // prohibited by law if you do not accept this License. Therefore, by
  836. // modifying or distributing the Library (or any work based on the
  837. // Library), you indicate your acceptance of this License to do so, and
  838. // all its terms and conditions for copying, distributing or modifying
  839. // the Library or works based on it.
  840. // .
  841. // 10. Each time you redistribute the Library (or any work based on the
  842. // Library), the recipient automatically receives a license from the
  843. // original licensor to copy, distribute, link with or modify the Library
  844. // subject to these terms and conditions. You may not impose any further
  845. // restrictions on the recipients' exercise of the rights granted herein.
  846. // You are not responsible for enforcing compliance by third parties with
  847. // this License.
  848. // .
  849. // 11. If, as a consequence of a court judgment or allegation of patent
  850. // infringement or for any other reason (not limited to patent issues),
  851. // conditions are imposed on you (whether by court order, agreement or
  852. // otherwise) that contradict the conditions of this License, they do not
  853. // excuse you from the conditions of this License. If you cannot
  854. // distribute so as to satisfy simultaneously your obligations under this
  855. // License and any other pertinent obligations, then as a consequence you
  856. // may not distribute the Library at all. For example, if a patent
  857. // license would not permit royalty-free redistribution of the Library by
  858. // all those who receive copies directly or indirectly through you, then
  859. // the only way you could satisfy both it and this License would be to
  860. // refrain entirely from distribution of the Library.
  861. // .
  862. // If any portion of this section is held invalid or unenforceable under any
  863. // particular circumstance, the balance of the section is intended to apply,
  864. // and the section as a whole is intended to apply in other circumstances.
  865. // .
  866. // It is not the purpose of this section to induce you to infringe any
  867. // patents or other property right claims or to contest validity of any
  868. // such claims; this section has the sole purpose of protecting the
  869. // integrity of the free software distribution system which is
  870. // implemented by public license practices. Many people have made
  871. // generous contributions to the wide range of software distributed
  872. // through that system in reliance on consistent application of that
  873. // system; it is up to the author/donor to decide if he or she is willing
  874. // to distribute software through any other system and a licensee cannot
  875. // impose that choice.
  876. // .
  877. // This section is intended to make thoroughly clear what is believed to
  878. // be a consequence of the rest of this License.
  879. // .
  880. // 12. If the distribution and/or use of the Library is restricted in
  881. // certain countries either by patents or by copyrighted interfaces, the
  882. // original copyright holder who places the Library under this License may add
  883. // an explicit geographical distribution limitation excluding those countries,
  884. // so that distribution is permitted only in or among countries not thus
  885. // excluded. In such case, this License incorporates the limitation as if
  886. // written in the body of this License.
  887. // .
  888. // 13. The Free Software Foundation may publish revised and/or new
  889. // versions of the Lesser General Public License from time to time.
  890. // Such new versions will be similar in spirit to the present version,
  891. // but may differ in detail to address new problems or concerns.
  892. // .
  893. // Each version is given a distinguishing version number. If the Library
  894. // specifies a version number of this License which applies to it and
  895. // "any later version", you have the option of following the terms and
  896. // conditions either of that version or of any later version published by
  897. // the Free Software Foundation. If the Library does not specify a
  898. // license version number, you may choose any version ever published by
  899. // the Free Software Foundation.
  900. // .
  901. // 14. If you wish to incorporate parts of the Library into other free
  902. // programs whose distribution conditions are incompatible with these,
  903. // write to the author to ask for permission. For software which is
  904. // copyrighted by the Free Software Foundation, write to the Free
  905. // Software Foundation; we sometimes make exceptions for this. Our
  906. // decision will be guided by the two goals of preserving the free status
  907. // of all derivatives of our free software and of promoting the sharing
  908. // and reuse of software generally.
  909. // .
  910. // NO WARRANTY
  911. // .
  912. // 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
  913. // WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
  914. // EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
  915. // OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
  916. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
  917. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  918. // PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
  919. // LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
  920. // THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  921. // .
  922. // 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  923. // WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
  924. // AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
  925. // FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
  926. // CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
  927. // LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
  928. // RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
  929. // FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
  930. // SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  931. // DAMAGES.
  932. // .
  933. // END OF TERMS AND CONDITIONS
  934. // .
  935. // How to Apply These Terms to Your New Libraries
  936. // .
  937. // If you develop a new library, and you want it to be of the greatest
  938. // possible use to the public, we recommend making it free software that
  939. // everyone can redistribute and change. You can do so by permitting
  940. // redistribution under these terms (or, alternatively, under the terms of the
  941. // ordinary General Public License).
  942. // .
  943. // To apply these terms, attach the following notices to the library. It is
  944. // safest to attach them to the start of each source file to most effectively
  945. // convey the exclusion of warranty; and each file should have at least the
  946. // "copyright" line and a pointer to where the full notice is found.
  947. // .
  948. // <one line to give the library's name and a brief idea of what it does.>
  949. // Copyright (C) <year> <name of author>
  950. // .
  951. // This library is free software; you can redistribute it and/or
  952. // modify it under the terms of the GNU Lesser General Public
  953. // License as published by the Free Software Foundation; either
  954. // version 2.1 of the License, or (at your option) any later version.
  955. // .
  956. // This library is distributed in the hope that it will be useful,
  957. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  958. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  959. // Lesser General Public License for more details.
  960. // .
  961. // You should have received a copy of the GNU Lesser General Public
  962. // License along with this library; if not, write to the Free Software
  963. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  964. // .
  965. // Also add information on how to contact you by electronic and paper mail.
  966. // .
  967. // You should also get your employer (if you work as a programmer) or your
  968. // school, if any, to sign a "copyright disclaimer" for the library, if
  969. // necessary. Here is a sample; alter the names:
  970. // .
  971. // Yoyodyne, Inc., hereby disclaims all copyright interest in the
  972. // library `Frob' (a library for tweaking knobs) written by James Random Hacker.
  973. // .
  974. // <signature of Ty Coon>, 1 April 1990
  975. // Ty Coon, President of Vice
  976. // .
  977. // That's all there is to it!
  978. "use strict";
  979. var SubtitlesOctopus = function (options) {
  980. var supportsWebAssembly = false;
  981. try {
  982. if (typeof WebAssembly === "object"
  983. && typeof WebAssembly.instantiate === "function") {
  984. const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
  985. if (module instanceof WebAssembly.Module)
  986. supportsWebAssembly = (new WebAssembly.Instance(module) instanceof WebAssembly.Instance);
  987. }
  988. } catch (e) {
  989. }
  990. console.log("WebAssembly support detected: " + (supportsWebAssembly ? "yes" : "no"));
  991.  
  992. var self = this;
  993. self.canvas = options.canvas; // HTML canvas element (optional if video specified)
  994. self.renderMode = options.renderMode || (options.lossyRender ? 'lossy' : 'wasm-blend');
  995. self.libassMemoryLimit = options.libassMemoryLimit || 0;
  996. self.libassGlyphLimit = options.libassGlyphLimit || 0;
  997. self.targetFps = options.targetFps || 24;
  998. self.prescaleFactor = options.prescaleFactor || 1.0;
  999. self.prescaleHeightLimit = options.prescaleHeightLimit || 1080;
  1000. self.maxRenderHeight = options.maxRenderHeight || 0; // 0 - no limit
  1001. self.dropAllAnimations = options.dropAllAnimations || false; // attempt to remove all animations as a last ditch effort for displaying on weak hardware; may severly mangle subtitles if enabled
  1002. self.isOurCanvas = false; // (internal) we created canvas and manage it
  1003. self.video = options.video; // HTML video element (optional if canvas specified)
  1004. self.canvasParent = null; // (internal) HTML canvas parent element
  1005. self.fonts = options.fonts || []; // Array with links to fonts used in sub (optional)
  1006. self.availableFonts = options.availableFonts || []; // Object with all available fonts (optional). Key is font name in lower case, value is link: {"arial": "/font1.ttf"}
  1007. self.fallbackFont = options.fallbackFont || 'default.woff2'; // URL to override fallback font, for example, with a CJK one. Default fallback font is Liberation Sans (Optional)
  1008. self.lazyFileLoading = options.lazyFileLoading || false; // Load fonts in a lazy way. Requires Access-Control-Expose-Headers for Accept-Ranges, Content-Length, and Content-Encoding. If Content-Encoding is compressed, file will be fully fetched instead of just a HEAD request.
  1009. self.onReadyEvent = options.onReady; // Function called when SubtitlesOctopus is ready (optional)
  1010. if (supportsWebAssembly) {
  1011. self.workerUrl = options.workerUrl || 'subtitles-octopus-worker.js'; // Link to WebAssembly worker
  1012. } else {
  1013. self.workerUrl = options.legacyWorkerUrl || 'subtitles-octopus-worker-legacy.js'; // Link to legacy worker
  1014. }
  1015. self.subUrl = options.subUrl; // Link to sub file (optional if subContent specified)
  1016. self.subContent = options.subContent || null; // Sub content (optional if subUrl specified)
  1017. self.onErrorEvent = options.onError; // Function called in case of critical error meaning sub wouldn't be shown and you should use alternative method (for instance it occurs if browser doesn't support web workers).
  1018. self.debug = options.debug || false; // When debug enabled, some performance info printed in console.
  1019. self.lastRenderTime = 0; // (internal) Last time we got some frame from worker
  1020. self.pixelRatio = window.devicePixelRatio || 1; // (internal) Device pixel ratio (for high dpi devices)
  1021.  
  1022. self.timeOffset = options.timeOffset || 0; // Time offset would be applied to currentTime from video (option)
  1023.  
  1024. self.hasAlphaBug = false;
  1025.  
  1026. (function() {
  1027. if (typeof ImageData.prototype.constructor === 'function') {
  1028. try {
  1029. // try actually calling ImageData, as on some browsers it's reported
  1030. // as existing but calling it errors out as "TypeError: Illegal constructor"
  1031. new window.ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1);
  1032. return;
  1033. } catch (e) {
  1034. console.log("detected that ImageData is not constructable despite browser saying so");
  1035. }
  1036. }
  1037.  
  1038. var canvas = document.createElement('canvas');
  1039. var ctx = canvas.getContext('2d');
  1040.  
  1041. window.ImageData = function () {
  1042. var i = 0;
  1043. if (arguments[0] instanceof Uint8ClampedArray) {
  1044. var data = arguments[i++];
  1045. }
  1046. var width = arguments[i++];
  1047. var height = arguments[i];
  1048.  
  1049. var imageData = ctx.createImageData(width, height);
  1050. if (data) imageData.data.set(data);
  1051. return imageData;
  1052. }
  1053. })();
  1054.  
  1055. self.workerError = function (error) {
  1056. console.error('Worker error: ', error);
  1057. if (self.onErrorEvent) {
  1058. self.onErrorEvent(error);
  1059. }
  1060. if (!self.debug) {
  1061. self.dispose();
  1062. throw new Error('Worker error: ' + error);
  1063. }
  1064. };
  1065.  
  1066. // Not tested for repeated usage yet
  1067. self.init = function () {
  1068. if (!window.Worker) {
  1069. self.workerError('worker not supported');
  1070. return;
  1071. }
  1072. // Worker
  1073. if (!self.worker) {
  1074. self.worker = new Worker(self.workerUrl);
  1075. self.worker.addEventListener('message', self.onWorkerMessage);
  1076. self.worker.addEventListener('error', self.workerError);
  1077. }
  1078. self.workerActive = false;
  1079. self.createCanvas();
  1080. self.setVideo(options.video);
  1081. self.setSubUrl(options.subUrl);
  1082. self.worker.postMessage({
  1083. target: 'worker-init',
  1084. width: self.canvas.width,
  1085. height: self.canvas.height,
  1086. URL: document.URL,
  1087. currentScript: self.workerUrl,
  1088. preMain: true,
  1089. renderMode: self.renderMode,
  1090. subUrl: self.subUrl,
  1091. subContent: self.subContent,
  1092. fonts: self.fonts,
  1093. availableFonts: self.availableFonts,
  1094. fallbackFont: self.fallbackFont,
  1095. lazyFileLoading: self.lazyFileLoading,
  1096. debug: self.debug,
  1097. targetFps: self.targetFps,
  1098. libassMemoryLimit: self.libassMemoryLimit,
  1099. libassGlyphLimit: self.libassGlyphLimit,
  1100. dropAllAnimations: self.dropAllAnimations
  1101. });
  1102. };
  1103.  
  1104. self.createCanvas = function () {
  1105. if (!self.canvas) {
  1106. if (self.video) {
  1107. self.isOurCanvas = true;
  1108. self.canvas = document.createElement('canvas');
  1109. self.canvas.className = 'libassjs-canvas';
  1110. self.canvas.style.display = 'none';
  1111.  
  1112. self.canvasParent = document.createElement('div');
  1113. self.canvasParent.className = 'libassjs-canvas-parent';
  1114. self.canvasParent.appendChild(self.canvas);
  1115.  
  1116. if (self.video.nextSibling) {
  1117. self.video.parentNode.insertBefore(self.canvasParent, self.video.nextSibling);
  1118. }
  1119. else {
  1120. self.video.parentNode.appendChild(self.canvasParent);
  1121. }
  1122. }
  1123. else {
  1124. if (!self.canvas) {
  1125. self.workerError('Don\'t know where to render: you should give video or canvas in options.');
  1126. }
  1127. }
  1128. }
  1129. self.ctx = self.canvas.getContext('2d');
  1130. self.bufferCanvas = document.createElement('canvas');
  1131. self.bufferCanvasCtx = self.bufferCanvas.getContext('2d');
  1132.  
  1133. // test for alpha bug, where e.g. WebKit can render a transparent pixel
  1134. // (with alpha == 0) as non-black which then leads to visual artifacts
  1135. self.bufferCanvas.width = 1;
  1136. self.bufferCanvas.height = 1;
  1137. var testBuf = new Uint8ClampedArray([0, 255, 0, 0]);
  1138. var testImage = new ImageData(testBuf, 1, 1);
  1139. self.bufferCanvasCtx.clearRect(0, 0, 1, 1);
  1140. self.ctx.clearRect(0, 0, 1, 1);
  1141. var prePut = self.ctx.getImageData(0, 0, 1, 1).data;
  1142. self.bufferCanvasCtx.putImageData(testImage, 0, 0);
  1143. self.ctx.drawImage(self.bufferCanvas, 0, 0);
  1144. var postPut = self.ctx.getImageData(0, 0, 1, 1).data;
  1145. self.hasAlphaBug = prePut[1] != postPut[1];
  1146. if (self.hasAlphaBug) {
  1147. console.log("Detected a browser having issue with transparent pixels, applying workaround");
  1148. }
  1149. };
  1150.  
  1151. function onTimeUpdate() {
  1152. self.setCurrentTime(self.video.currentTime + self.timeOffset);
  1153. };
  1154.  
  1155. function onPlaying() {
  1156. self.setIsPaused(false, self.video.currentTime + self.timeOffset);
  1157. }
  1158.  
  1159. function onPause() {
  1160. self.setIsPaused(true, self.video.currentTime + self.timeOffset);
  1161. }
  1162.  
  1163. function onSeeking() {
  1164. self.video.removeEventListener('timeupdate', onTimeUpdate, false);
  1165. }
  1166.  
  1167. function onSeeked() {
  1168. self.video.addEventListener('timeupdate', onTimeUpdate, false);
  1169.  
  1170. var currentTime = self.video.currentTime + self.timeOffset;
  1171.  
  1172. self.setCurrentTime(currentTime);
  1173. }
  1174.  
  1175. function onRateChange() {
  1176. self.setRate(self.video.playbackRate);
  1177. }
  1178.  
  1179. function onWaiting() {
  1180. self.setIsPaused(true, self.video.currentTime + self.timeOffset);
  1181. }
  1182.  
  1183. function onLoadedMetadata(e) {
  1184. e.target.removeEventListener(e.type, onLoadedMetadata, false);
  1185. self.resize();
  1186. }
  1187.  
  1188. self.setVideo = function (video) {
  1189. self.video = video;
  1190. if (self.video) {
  1191. self.video.addEventListener('timeupdate', onTimeUpdate, false);
  1192. self.video.addEventListener('playing', onPlaying, false);
  1193. self.video.addEventListener('pause', onPause, false);
  1194. self.video.addEventListener('seeking', onSeeking, false);
  1195. self.video.addEventListener('seeked', onSeeked, false);
  1196. self.video.addEventListener('ratechange', onRateChange, false);
  1197. self.video.addEventListener('waiting', onWaiting, false);
  1198.  
  1199. document.addEventListener("fullscreenchange", self.resizeWithTimeout, false);
  1200. document.addEventListener("mozfullscreenchange", self.resizeWithTimeout, false);
  1201. document.addEventListener("webkitfullscreenchange", self.resizeWithTimeout, false);
  1202. document.addEventListener("msfullscreenchange", self.resizeWithTimeout, false);
  1203. window.addEventListener("resize", self.resizeWithTimeout, false);
  1204.  
  1205. // Support Element Resize Observer
  1206. if (typeof ResizeObserver !== "undefined") {
  1207. self.ro = new ResizeObserver(self.resizeWithTimeout);
  1208. self.ro.observe(self.video);
  1209. }
  1210.  
  1211. if (self.video.videoWidth > 0) {
  1212. self.resize();
  1213. }
  1214. else {
  1215. self.video.addEventListener('loadedmetadata', onLoadedMetadata, false);
  1216. }
  1217. }
  1218. };
  1219.  
  1220. self.getVideoPosition = function () {
  1221. var videoRatio = self.video.videoWidth / self.video.videoHeight;
  1222. var width = self.video.offsetWidth, height = self.video.offsetHeight;
  1223. var elementRatio = width / height;
  1224. var realWidth = width, realHeight = height;
  1225. if (elementRatio > videoRatio) realWidth = Math.floor(height * videoRatio);
  1226. else realHeight = Math.floor(width / videoRatio);
  1227.  
  1228. var x = (width - realWidth) / 2;
  1229. var y = (height - realHeight) / 2;
  1230.  
  1231. return {
  1232. width: realWidth,
  1233. height: realHeight,
  1234. x: x,
  1235. y: y
  1236. };
  1237. };
  1238.  
  1239. self.setSubUrl = function (subUrl) {
  1240. self.subUrl = subUrl;
  1241. };
  1242.  
  1243. self.renderFrameData = null;
  1244. function renderFrames() {
  1245. var data = self.renderFramesData;
  1246. var beforeDrawTime = performance.now();
  1247. self.ctx.clearRect(0, 0, self.canvas.width, self.canvas.height);
  1248. for (var i = 0; i < data.canvases.length; i++) {
  1249. var image = data.canvases[i];
  1250. self.bufferCanvas.width = image.w;
  1251. self.bufferCanvas.height = image.h;
  1252. var imageBuffer = new Uint8ClampedArray(image.buffer);
  1253. if (self.hasAlphaBug) {
  1254. for (var j = 3; j < imageBuffer.length; j = j + 4) {
  1255. imageBuffer[j] = (imageBuffer[j] >= 1) ? imageBuffer[j] : 1;
  1256. }
  1257. }
  1258. var imageData = new ImageData(imageBuffer, image.w, image.h);
  1259. self.bufferCanvasCtx.putImageData(imageData, 0, 0);
  1260. self.ctx.drawImage(self.bufferCanvas, image.x, image.y);
  1261. }
  1262. if (self.debug) {
  1263. var drawTime = Math.round(performance.now() - beforeDrawTime);
  1264. var blendTime = data.blendTime;
  1265. if (typeof blendTime !== 'undefined') {
  1266. console.log('render: ' + Math.round(data.spentTime - blendTime) + ' ms, blend: ' + Math.round(blendTime) + ' ms, draw: ' + drawTime + ' ms; TOTAL=' + Math.round(data.spentTime + drawTime) + ' ms');
  1267. } else {
  1268. console.log(Math.round(data.spentTime) + ' ms (+ ' + drawTime + ' ms draw)');
  1269. }
  1270. self.renderStart = performance.now();
  1271. }
  1272. }
  1273.  
  1274. /**
  1275. * Lossy Render Mode
  1276. *
  1277. */
  1278. function renderFastFrames() {
  1279. var data = self.renderFramesData;
  1280. var beforeDrawTime = performance.now();
  1281. self.ctx.clearRect(0, 0, self.canvas.width, self.canvas.height);
  1282. for (var i = 0; i < data.bitmaps.length; i++) {
  1283. var image = data.bitmaps[i];
  1284. self.ctx.drawImage(image.bitmap, image.x, image.y);
  1285. }
  1286. if (self.debug) {
  1287. var drawTime = Math.round(performance.now() - beforeDrawTime);
  1288. console.log(data.bitmaps.length + ' bitmaps, libass: ' + Math.round(data.libassTime) + 'ms, decode: ' + Math.round(data.decodeTime) + 'ms, draw: ' + drawTime + 'ms');
  1289. self.renderStart = performance.now();
  1290. }
  1291. }
  1292.  
  1293. self.workerActive = false;
  1294. self.frameId = 0;
  1295. self.onWorkerMessage = function (event) {
  1296. //dump('\nclient got ' + JSON.stringify(event.data).substr(0, 150) + '\n');
  1297. if (!self.workerActive) {
  1298. self.workerActive = true;
  1299. if (self.onReadyEvent) {
  1300. self.onReadyEvent();
  1301. }
  1302. }
  1303. var data = event.data;
  1304. switch (data.target) {
  1305. case 'stdout': {
  1306. console.log(data.content);
  1307. break;
  1308. }
  1309. case 'console-log': {
  1310. console.log.apply(console, JSON.parse(data.content));
  1311. break;
  1312. }
  1313. case 'console-debug': {
  1314. console.debug.apply(console, JSON.parse(data.content));
  1315. break;
  1316. }
  1317. case 'console-info': {
  1318. console.info.apply(console, JSON.parse(data.content));
  1319. break;
  1320. }
  1321. case 'console-warn': {
  1322. console.warn.apply(console, JSON.parse(data.content));
  1323. break;
  1324. }
  1325. case 'console-error': {
  1326. console.error.apply(console, JSON.parse(data.content));
  1327. break;
  1328. }
  1329. case 'stderr': {
  1330. console.error(data.content);
  1331. break;
  1332. }
  1333. case 'window': {
  1334. window[data.method]();
  1335. break;
  1336. }
  1337. case 'canvas': {
  1338. switch (data.op) {
  1339. case 'getContext': {
  1340. self.ctx = self.canvas.getContext(data.type, data.attributes);
  1341. break;
  1342. }
  1343. case 'resize': {
  1344. self.resize(data.width, data.height);
  1345. break;
  1346. }
  1347. case 'renderCanvas': {
  1348. if (self.lastRenderTime < data.time) {
  1349. self.lastRenderTime = data.time;
  1350. self.renderFramesData = data;
  1351. window.requestAnimationFrame(renderFrames);
  1352. }
  1353. break;
  1354. }
  1355. case 'renderFastCanvas': {
  1356. if (self.lastRenderTime < data.time) {
  1357. self.lastRenderTime = data.time;
  1358. self.renderFramesData = data;
  1359. window.requestAnimationFrame(renderFastFrames);
  1360. }
  1361. break;
  1362. }
  1363. case 'setObjectProperty': {
  1364. self.canvas[data.object][data.property] = data.value;
  1365. break;
  1366. }
  1367. default:
  1368. throw 'eh?';
  1369. }
  1370. break;
  1371. }
  1372. case 'tick': {
  1373. self.frameId = data.id;
  1374. self.worker.postMessage({
  1375. target: 'tock',
  1376. id: self.frameId
  1377. });
  1378. break;
  1379. }
  1380. case 'custom': {
  1381. if (self['onCustomMessage']) {
  1382. self['onCustomMessage'](event);
  1383. } else {
  1384. throw 'Custom message received but client onCustomMessage not implemented.';
  1385. }
  1386. break;
  1387. }
  1388. case 'setimmediate': {
  1389. self.worker.postMessage({
  1390. target: 'setimmediate'
  1391. });
  1392. break;
  1393. }
  1394. case 'get-events': {
  1395. break;
  1396. }
  1397. case 'get-styles': {
  1398. break;
  1399. }
  1400. case 'ready': {
  1401. break;
  1402. }
  1403. default:
  1404. throw 'what? ' + data.target;
  1405. }
  1406. };
  1407.  
  1408. function _computeCanvasSize(width, height) {
  1409. var scalefactor = self.prescaleFactor <= 0 ? 1.0 : self.prescaleFactor;
  1410.  
  1411. if (height <= 0 || width <= 0) {
  1412. width = 0;
  1413. height = 0;
  1414. } else {
  1415. var sgn = scalefactor < 1 ? -1 : 1;
  1416. var newH = height;
  1417. if (sgn * newH * scalefactor <= sgn * self.prescaleHeightLimit)
  1418. newH *= scalefactor;
  1419. else if (sgn * newH < sgn * self.prescaleHeightLimit)
  1420. newH = self.prescaleHeightLimit;
  1421.  
  1422. if (self.maxRenderHeight > 0 && newH > self.maxRenderHeight)
  1423. newH = self.maxRenderHeight;
  1424.  
  1425. width *= newH / height;
  1426. height = newH;
  1427. }
  1428.  
  1429. return {'width': width, 'height': height};
  1430. }
  1431.  
  1432. self.resize = function (width, height, top, left) {
  1433. var videoSize = null;
  1434. top = top || 0;
  1435. left = left || 0;
  1436. if ((!width || !height) && self.video) {
  1437. videoSize = self.getVideoPosition();
  1438. var newSize = _computeCanvasSize(videoSize.width * self.pixelRatio, videoSize.height * self.pixelRatio);
  1439. width = newSize.width;
  1440. height = newSize.height;
  1441. var offset = self.canvasParent.getBoundingClientRect().top - self.video.getBoundingClientRect().top;
  1442. top = videoSize.y - offset;
  1443. left = videoSize.x;
  1444. }
  1445. if (!width || !height) {
  1446. if (!self.video) {
  1447. console.error('width or height is 0. You should specify width & height for resize.');
  1448. }
  1449. return;
  1450. }
  1451.  
  1452.  
  1453. if (
  1454. self.canvas.width != width ||
  1455. self.canvas.height != height ||
  1456. self.canvas.style.top != top ||
  1457. self.canvas.style.left != left
  1458. ) {
  1459. self.canvas.width = width;
  1460. self.canvas.height = height;
  1461.  
  1462. if (videoSize != null) {
  1463. self.canvasParent.style.position = 'relative';
  1464. self.canvas.style.display = 'block';
  1465. self.canvas.style.position = 'absolute';
  1466. self.canvas.style.width = videoSize.width + 'px';
  1467. self.canvas.style.height = videoSize.height + 'px';
  1468. self.canvas.style.top = top + 'px';
  1469. self.canvas.style.left = left + 'px';
  1470. self.canvas.style.pointerEvents = 'none';
  1471. }
  1472.  
  1473. self.worker.postMessage({
  1474. target: 'canvas',
  1475. width: self.canvas.width,
  1476. height: self.canvas.height
  1477. });
  1478. }
  1479. };
  1480.  
  1481. self.resizeWithTimeout = function () {
  1482. self.resize();
  1483. setTimeout(self.resize, 100);
  1484. };
  1485.  
  1486. self.runBenchmark = function () {
  1487. self.worker.postMessage({
  1488. target: 'runBenchmark'
  1489. });
  1490. };
  1491.  
  1492. self.customMessage = function (data, options) {
  1493. options = options || {};
  1494. self.worker.postMessage({
  1495. target: 'custom',
  1496. userData: data,
  1497. preMain: options.preMain
  1498. });
  1499. };
  1500.  
  1501. self.setCurrentTime = function (currentTime) {
  1502. self.worker.postMessage({
  1503. target: 'video',
  1504. currentTime: currentTime
  1505. });
  1506. };
  1507.  
  1508. self.setTrackByUrl = function (url) {
  1509. self.worker.postMessage({
  1510. target: 'set-track-by-url',
  1511. url: url
  1512. });
  1513. };
  1514.  
  1515. self.setTrack = function (content) {
  1516. self.worker.postMessage({
  1517. target: 'set-track',
  1518. content: content
  1519. });
  1520. };
  1521.  
  1522. self.freeTrack = function (content) {
  1523. self.worker.postMessage({
  1524. target: 'free-track'
  1525. });
  1526. };
  1527.  
  1528.  
  1529. self.render = self.setCurrentTime;
  1530.  
  1531. self.setIsPaused = function (isPaused, currentTime) {
  1532. self.worker.postMessage({
  1533. target: 'video',
  1534. isPaused: isPaused,
  1535. currentTime: currentTime
  1536. });
  1537. };
  1538.  
  1539. self.setRate = function (rate) {
  1540. self.worker.postMessage({
  1541. target: 'video',
  1542. rate: rate
  1543. });
  1544. };
  1545.  
  1546. self.dispose = function () {
  1547. self.worker.postMessage({
  1548. target: 'destroy'
  1549. });
  1550.  
  1551. self.worker.terminate();
  1552. self.worker.removeEventListener('message', self.onWorkerMessage);
  1553. self.worker.removeEventListener('error', self.workerError);
  1554. self.workerActive = false;
  1555. self.worker = null;
  1556.  
  1557. // Remove the canvas element to remove residual subtitles rendered on player
  1558. if (self.video) {
  1559. self.video.removeEventListener('timeupdate', onTimeUpdate, false);
  1560. self.video.removeEventListener('playing', onPlaying, false);
  1561. self.video.removeEventListener('pause', onPause, false);
  1562. self.video.removeEventListener('seeking', onSeeking, false);
  1563. self.video.removeEventListener('seeked', onSeeked, false);
  1564. self.video.removeEventListener('ratechange', onRateChange, false);
  1565. self.video.removeEventListener('waiting', onWaiting, false);
  1566. self.video.removeEventListener('loadedmetadata', onLoadedMetadata, false);
  1567.  
  1568. document.removeEventListener('fullscreenchange', self.resizeWithTimeout, false);
  1569. document.removeEventListener('mozfullscreenchange', self.resizeWithTimeout, false);
  1570. document.removeEventListener('webkitfullscreenchange', self.resizeWithTimeout, false);
  1571. document.removeEventListener('msfullscreenchange', self.resizeWithTimeout, false);
  1572. window.removeEventListener('resize', self.resizeWithTimeout, false);
  1573.  
  1574. self.video.parentNode.removeChild(self.canvasParent);
  1575.  
  1576. self.video = null;
  1577. }
  1578.  
  1579. if (self.ro) {
  1580. self.ro.disconnect();
  1581. self.ro = null;
  1582. }
  1583.  
  1584. self.onCustomMessage = null;
  1585. self.onErrorEvent = null;
  1586. self.onReadyEvent = null;
  1587. };
  1588.  
  1589. self.fetchFromWorker = function (workerOptions, onSuccess, onError) {
  1590. try {
  1591. var target = workerOptions['target']
  1592.  
  1593. var timeout = setTimeout(function() {
  1594. reject(Error('Error: Timeout while try to fetch ' + target))
  1595. }, 5000)
  1596.  
  1597. var resolve = function (event) {
  1598. if (event.data.target == target) {
  1599. onSuccess(event.data)
  1600. self.worker.removeEventListener('message', resolve)
  1601. self.worker.removeEventListener('error', reject)
  1602. clearTimeout(timeout)
  1603. }
  1604. }
  1605.  
  1606. var reject = function (event) {
  1607. onError(event)
  1608. self.worker.removeEventListener('message', resolve)
  1609. self.worker.removeEventListener('error', reject)
  1610. clearTimeout(timeout)
  1611. }
  1612.  
  1613. self.worker.addEventListener('message', resolve)
  1614. self.worker.addEventListener('error', reject)
  1615.  
  1616. self.worker.postMessage(workerOptions)
  1617. } catch (error) {
  1618. onError(error)
  1619. }
  1620. }
  1621.  
  1622. self.createEvent = function (event) {
  1623. self.worker.postMessage({
  1624. target: 'create-event',
  1625. event: event
  1626. });
  1627. };
  1628.  
  1629. self.getEvents = function (onSuccess, onError) {
  1630. self.fetchFromWorker({
  1631. target: 'get-events'
  1632. }, function(data) {
  1633. onSuccess(data.events)
  1634. }, onError);
  1635. };
  1636.  
  1637. self.setEvent = function (event, index) {
  1638. self.worker.postMessage({
  1639. target: 'set-event',
  1640. event: event,
  1641. index: index
  1642. });
  1643. };
  1644.  
  1645. self.removeEvent = function (index) {
  1646. self.worker.postMessage({
  1647. target: 'remove-event',
  1648. index: index
  1649. });
  1650. };
  1651.  
  1652. self.createStyle = function (style) {
  1653. self.worker.postMessage({
  1654. target: 'create-style',
  1655. style: style
  1656. });
  1657. };
  1658. self.getStyles = function (onSuccess, onError) {
  1659. self.fetchFromWorker({
  1660. target: 'get-styles'
  1661. }, function(data) {
  1662. onSuccess(data.styles)
  1663. }, onError);
  1664. };
  1665.  
  1666. self.setStyle = function (style, index) {
  1667. self.worker.postMessage({
  1668. target: 'set-style',
  1669. style: style,
  1670. index: index
  1671. });
  1672. };
  1673.  
  1674. self.removeStyle = function (index) {
  1675. self.worker.postMessage({
  1676. target: 'remove-style',
  1677. index: index
  1678. });
  1679. };
  1680.  
  1681. self.init();
  1682. };
  1683.  
  1684. if (typeof SubtitlesOctopusOnLoad == 'function') {
  1685. SubtitlesOctopusOnLoad();
  1686. }
  1687.  
  1688. if (typeof exports !== 'undefined') {
  1689. if (typeof module !== 'undefined' && module.exports) {
  1690. exports = module.exports = SubtitlesOctopus
  1691. }
  1692. }