@tarojs/components 4.0.0-beta.0 → 4.0.0-beta.2

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.
Files changed (588) hide show
  1. package/LICENSE +14 -0
  2. package/dist/cjs/{index-e751dfe3.js → index-dbbe9dde.js} +3 -0
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/taro-ad-core.cjs.entry.js +1 -1
  5. package/dist/cjs/taro-ad-custom-core.cjs.entry.js +1 -1
  6. package/dist/cjs/taro-animation-video-core.cjs.entry.js +1 -1
  7. package/dist/cjs/taro-animation-view-core.cjs.entry.js +1 -1
  8. package/dist/cjs/taro-ar-camera-core.cjs.entry.js +1 -1
  9. package/dist/cjs/taro-audio-core.cjs.entry.js +2 -2
  10. package/dist/cjs/taro-aweme-data-core.cjs.entry.js +1 -1
  11. package/dist/cjs/taro-block-core.cjs.entry.js +1 -1
  12. package/dist/cjs/taro-button-core.cjs.entry.js +2 -2
  13. package/dist/cjs/taro-camera-core.cjs.entry.js +1 -1
  14. package/dist/cjs/taro-canvas-core.cjs.entry.js +2 -2
  15. package/dist/cjs/taro-channel-live-core.cjs.entry.js +1 -1
  16. package/dist/cjs/taro-channel-video-core.cjs.entry.js +1 -1
  17. package/dist/cjs/taro-checkbox-core_2.cjs.entry.js +2 -2
  18. package/dist/cjs/taro-comment-detail-core.cjs.entry.js +1 -1
  19. package/dist/cjs/taro-comment-list-core.cjs.entry.js +1 -1
  20. package/dist/cjs/taro-components.cjs.js +2 -2
  21. package/dist/cjs/taro-contact-button-core.cjs.entry.js +1 -1
  22. package/dist/cjs/taro-cover-image-core.cjs.entry.js +2 -2
  23. package/dist/cjs/taro-cover-view-core.cjs.entry.js +1 -1
  24. package/dist/cjs/taro-custom-wrapper-core.cjs.entry.js +1 -1
  25. package/dist/cjs/taro-editor-core.cjs.entry.js +1 -1
  26. package/dist/cjs/taro-follow-swan-core.cjs.entry.js +1 -1
  27. package/dist/cjs/taro-form-core.cjs.entry.js +1 -1
  28. package/dist/cjs/taro-functional-page-navigator-core.cjs.entry.js +1 -1
  29. package/dist/cjs/taro-grid-view-core.cjs.entry.js +1 -1
  30. package/dist/cjs/taro-icon-core.cjs.entry.js +4 -1
  31. package/dist/cjs/taro-image-core.cjs.entry.js +6 -5
  32. package/dist/cjs/taro-inline-payment-panel-core.cjs.entry.js +1 -1
  33. package/dist/cjs/taro-input-core.cjs.entry.js +2 -2
  34. package/dist/cjs/taro-keyboard-accessory-core.cjs.entry.js +1 -1
  35. package/dist/cjs/taro-label-core.cjs.entry.js +1 -1
  36. package/dist/cjs/taro-lifestyle-core.cjs.entry.js +1 -1
  37. package/dist/cjs/taro-like-core.cjs.entry.js +1 -1
  38. package/dist/cjs/taro-list-view-core.cjs.entry.js +1 -1
  39. package/dist/cjs/taro-live-player-core.cjs.entry.js +1 -1
  40. package/dist/cjs/taro-live-pusher-core.cjs.entry.js +1 -1
  41. package/dist/cjs/taro-login-core.cjs.entry.js +1 -1
  42. package/dist/cjs/taro-lottie-core.cjs.entry.js +1 -1
  43. package/dist/cjs/taro-map-core.cjs.entry.js +1 -1
  44. package/dist/cjs/taro-match-media-core.cjs.entry.js +1 -1
  45. package/dist/cjs/taro-movable-area-core_2.cjs.entry.js +4 -4
  46. package/dist/cjs/taro-native-slot-core.cjs.entry.js +1 -1
  47. package/dist/cjs/taro-navigation-bar-core.cjs.entry.js +1 -1
  48. package/dist/cjs/taro-navigator-core.cjs.entry.js +1 -1
  49. package/dist/cjs/taro-official-account-core.cjs.entry.js +1 -1
  50. package/dist/cjs/taro-open-data-core.cjs.entry.js +1 -1
  51. package/dist/cjs/taro-page-container-core.cjs.entry.js +1 -1
  52. package/dist/cjs/taro-page-meta-core.cjs.entry.js +1 -1
  53. package/dist/cjs/taro-picker-core_2.cjs.entry.js +2 -2
  54. package/dist/cjs/taro-picker-view-column-core_2.cjs.entry.js +3 -3
  55. package/dist/cjs/taro-progress-core.cjs.entry.js +4 -1
  56. package/dist/cjs/taro-pull-to-refresh-core.cjs.entry.js +2 -2
  57. package/dist/cjs/taro-radio-core_2.cjs.entry.js +1 -1
  58. package/dist/cjs/taro-rich-text-core.cjs.entry.js +2 -2
  59. package/dist/cjs/taro-root-portal-core.cjs.entry.js +1 -1
  60. package/dist/cjs/taro-rtc-room-core.cjs.entry.js +1 -1
  61. package/dist/cjs/taro-rtc-room-item-core.cjs.entry.js +1 -1
  62. package/dist/cjs/taro-scroll-view-core.cjs.entry.js +2 -2
  63. package/dist/cjs/taro-share-element-core.cjs.entry.js +1 -1
  64. package/dist/cjs/taro-slider-core.cjs.entry.js +4 -1
  65. package/dist/cjs/taro-slot-core.cjs.entry.js +1 -1
  66. package/dist/cjs/taro-snapshot-core.cjs.entry.js +1 -1
  67. package/dist/cjs/taro-sticky-header-core.cjs.entry.js +1 -1
  68. package/dist/cjs/taro-sticky-section-core.cjs.entry.js +1 -1
  69. package/dist/cjs/taro-swiper-core_2.cjs.entry.js +19 -9863
  70. package/dist/cjs/taro-switch-core.cjs.entry.js +13 -12
  71. package/dist/cjs/taro-tab-item-core.cjs.entry.js +1 -1
  72. package/dist/cjs/taro-tabbar.cjs.entry.js +13 -85
  73. package/dist/cjs/taro-tabs-core.cjs.entry.js +1 -1
  74. package/dist/cjs/taro-text-core.cjs.entry.js +2 -2
  75. package/dist/cjs/taro-textarea-core.cjs.entry.js +12 -3
  76. package/dist/cjs/taro-video-control_3.cjs.entry.js +24 -4
  77. package/dist/cjs/taro-view-core.cjs.entry.js +2 -2
  78. package/dist/cjs/taro-voip-room-core.cjs.entry.js +1 -1
  79. package/dist/cjs/taro-web-view-core.cjs.entry.js +2 -2
  80. package/dist/collection/components/audio/style/index.css +1 -4
  81. package/dist/collection/components/button/style/index.css +1 -160
  82. package/dist/collection/components/canvas/style/index.css +1 -6
  83. package/dist/collection/components/checkbox/style/index.css +1 -39
  84. package/dist/collection/components/cover-image/style/index.css +1 -5
  85. package/dist/collection/components/cover-view/style/cover-view.css +1 -3
  86. package/dist/collection/components/icon/icon.js +10 -0
  87. package/dist/collection/components/icon/style/index.css +1 -0
  88. package/dist/collection/components/image/image.js +4 -3
  89. package/dist/collection/components/image/style/index.css +1 -73
  90. package/dist/collection/components/input/input.js +2 -2
  91. package/dist/collection/components/input/style/index.css +1 -0
  92. package/dist/collection/components/movable-area/area.css +1 -6
  93. package/dist/collection/components/movable-area/view.css +1 -8
  94. package/dist/collection/components/navigator/style/index.css +1 -3
  95. package/dist/collection/components/picker/style/index.css +1 -4
  96. package/dist/collection/components/picker-view/style/column.css +1 -12
  97. package/dist/collection/components/picker-view/style/index.css +1 -28
  98. package/dist/collection/components/progress/progress.js +10 -0
  99. package/dist/collection/components/progress/style/index.css +1 -0
  100. package/dist/collection/components/pull-to-refresh/style/index.css +1 -52
  101. package/dist/collection/components/rich-text/style/index.css +1 -16
  102. package/dist/collection/components/scroll-view/style/index.css +1 -17
  103. package/dist/collection/components/slider/slider.js +10 -0
  104. package/dist/collection/components/slider/style/index.css +1 -0
  105. package/dist/collection/components/swiper/style/index.css +2 -19
  106. package/dist/collection/components/switch/style/index.css +1 -10
  107. package/dist/collection/components/switch/switch.js +12 -12
  108. package/dist/collection/components/tabbar/style/index.css +1 -53
  109. package/dist/collection/components/tabbar/tabbar.js +1 -1
  110. package/dist/collection/components/text/style/index.css +1 -26
  111. package/dist/collection/components/textarea/style/index.css +1 -22
  112. package/dist/collection/components/textarea/textarea.js +11 -0
  113. package/dist/collection/components/video/style/index.css +1 -327
  114. package/dist/collection/components/view/style/index.css +1 -9
  115. package/dist/collection/components/web-view/style/index.css +1 -12
  116. package/dist/components/taro-audio-core.js +1 -1
  117. package/dist/components/taro-button-core.js +1 -1
  118. package/dist/components/taro-canvas-core.js +1 -1
  119. package/dist/components/taro-checkbox-core.js +1 -1
  120. package/dist/components/taro-cover-image-core.js +1 -1
  121. package/dist/components/taro-icon-core.js +3 -0
  122. package/dist/components/taro-image-core.js +5 -4
  123. package/dist/components/taro-input-core.js +1 -1
  124. package/dist/components/taro-movable-area-core.js +1 -1
  125. package/dist/components/taro-movable-view-core.js +1 -1
  126. package/dist/components/taro-picker-core.js +1 -1
  127. package/dist/components/taro-picker-view-column-core.js +1 -1
  128. package/dist/components/taro-picker-view-core.js +1 -1
  129. package/dist/components/taro-progress-core.js +3 -0
  130. package/dist/components/taro-pull-to-refresh-core.js +1 -1
  131. package/dist/components/taro-rich-text-core.js +1 -1
  132. package/dist/components/taro-scroll-view-core.js +1 -1
  133. package/dist/components/taro-slider-core.js +3 -0
  134. package/dist/components/taro-swiper-core.js +5 -9853
  135. package/dist/components/taro-switch-core.js +13 -13
  136. package/dist/components/taro-tabbar.js +3 -76
  137. package/dist/components/taro-text-core.js +1 -1
  138. package/dist/components/taro-textarea-core.js +11 -2
  139. package/dist/components/taro-video-core.js +2 -2
  140. package/dist/components/taro-view-core.js +1 -1
  141. package/dist/components/taro-web-view-core.js +1 -1
  142. package/dist/esm/{index-980f930f.js → index-486e187e.js} +3 -1
  143. package/dist/esm/loader.js +3 -3
  144. package/dist/esm/taro-ad-core.entry.js +1 -1
  145. package/dist/esm/taro-ad-custom-core.entry.js +1 -1
  146. package/dist/esm/taro-animation-video-core.entry.js +1 -1
  147. package/dist/esm/taro-animation-view-core.entry.js +1 -1
  148. package/dist/esm/taro-ar-camera-core.entry.js +1 -1
  149. package/dist/esm/taro-audio-core.entry.js +2 -2
  150. package/dist/esm/taro-aweme-data-core.entry.js +1 -1
  151. package/dist/esm/taro-block-core.entry.js +1 -1
  152. package/dist/esm/taro-button-core.entry.js +2 -2
  153. package/dist/esm/taro-camera-core.entry.js +1 -1
  154. package/dist/esm/taro-canvas-core.entry.js +2 -2
  155. package/dist/esm/taro-channel-live-core.entry.js +1 -1
  156. package/dist/esm/taro-channel-video-core.entry.js +1 -1
  157. package/dist/esm/taro-checkbox-core_2.entry.js +2 -2
  158. package/dist/esm/taro-comment-detail-core.entry.js +1 -1
  159. package/dist/esm/taro-comment-list-core.entry.js +1 -1
  160. package/dist/esm/taro-components.js +3 -3
  161. package/dist/esm/taro-contact-button-core.entry.js +1 -1
  162. package/dist/esm/taro-cover-image-core.entry.js +2 -2
  163. package/dist/esm/taro-cover-view-core.entry.js +1 -1
  164. package/dist/esm/taro-custom-wrapper-core.entry.js +1 -1
  165. package/dist/esm/taro-editor-core.entry.js +1 -1
  166. package/dist/esm/taro-follow-swan-core.entry.js +1 -1
  167. package/dist/esm/taro-form-core.entry.js +1 -1
  168. package/dist/esm/taro-functional-page-navigator-core.entry.js +1 -1
  169. package/dist/esm/taro-grid-view-core.entry.js +1 -1
  170. package/dist/esm/taro-icon-core.entry.js +4 -1
  171. package/dist/esm/taro-image-core.entry.js +6 -5
  172. package/dist/esm/taro-inline-payment-panel-core.entry.js +1 -1
  173. package/dist/esm/taro-input-core.entry.js +2 -2
  174. package/dist/esm/taro-keyboard-accessory-core.entry.js +1 -1
  175. package/dist/esm/taro-label-core.entry.js +1 -1
  176. package/dist/esm/taro-lifestyle-core.entry.js +1 -1
  177. package/dist/esm/taro-like-core.entry.js +1 -1
  178. package/dist/esm/taro-list-view-core.entry.js +1 -1
  179. package/dist/esm/taro-live-player-core.entry.js +1 -1
  180. package/dist/esm/taro-live-pusher-core.entry.js +1 -1
  181. package/dist/esm/taro-login-core.entry.js +1 -1
  182. package/dist/esm/taro-lottie-core.entry.js +1 -1
  183. package/dist/esm/taro-map-core.entry.js +1 -1
  184. package/dist/esm/taro-match-media-core.entry.js +1 -1
  185. package/dist/esm/taro-movable-area-core_2.entry.js +4 -4
  186. package/dist/esm/taro-native-slot-core.entry.js +1 -1
  187. package/dist/esm/taro-navigation-bar-core.entry.js +1 -1
  188. package/dist/esm/taro-navigator-core.entry.js +1 -1
  189. package/dist/esm/taro-official-account-core.entry.js +1 -1
  190. package/dist/esm/taro-open-data-core.entry.js +1 -1
  191. package/dist/esm/taro-page-container-core.entry.js +1 -1
  192. package/dist/esm/taro-page-meta-core.entry.js +1 -1
  193. package/dist/esm/taro-picker-core_2.entry.js +2 -2
  194. package/dist/esm/taro-picker-view-column-core_2.entry.js +3 -3
  195. package/dist/esm/taro-progress-core.entry.js +4 -1
  196. package/dist/esm/taro-pull-to-refresh-core.entry.js +2 -2
  197. package/dist/esm/taro-radio-core_2.entry.js +1 -1
  198. package/dist/esm/taro-rich-text-core.entry.js +2 -2
  199. package/dist/esm/taro-root-portal-core.entry.js +1 -1
  200. package/dist/esm/taro-rtc-room-core.entry.js +1 -1
  201. package/dist/esm/taro-rtc-room-item-core.entry.js +1 -1
  202. package/dist/esm/taro-scroll-view-core.entry.js +2 -2
  203. package/dist/esm/taro-share-element-core.entry.js +1 -1
  204. package/dist/esm/taro-slider-core.entry.js +4 -1
  205. package/dist/esm/taro-slot-core.entry.js +1 -1
  206. package/dist/esm/taro-snapshot-core.entry.js +1 -1
  207. package/dist/esm/taro-sticky-header-core.entry.js +1 -1
  208. package/dist/esm/taro-sticky-section-core.entry.js +1 -1
  209. package/dist/esm/taro-swiper-core_2.entry.js +4 -9852
  210. package/dist/esm/taro-switch-core.entry.js +13 -12
  211. package/dist/esm/taro-tab-item-core.entry.js +1 -1
  212. package/dist/esm/taro-tabbar.entry.js +4 -77
  213. package/dist/esm/taro-tabs-core.entry.js +1 -1
  214. package/dist/esm/taro-text-core.entry.js +2 -2
  215. package/dist/esm/taro-textarea-core.entry.js +12 -3
  216. package/dist/esm/taro-video-control_3.entry.js +3 -3
  217. package/dist/esm/taro-view-core.entry.js +2 -2
  218. package/dist/esm/taro-voip-room-core.entry.js +1 -1
  219. package/dist/esm/taro-web-view-core.entry.js +2 -2
  220. package/dist/esm-es5/index-486e187e.js +2 -0
  221. package/dist/esm-es5/loader.js +1 -1
  222. package/dist/esm-es5/taro-ad-core.entry.js +1 -1
  223. package/dist/esm-es5/taro-ad-custom-core.entry.js +1 -1
  224. package/dist/esm-es5/taro-animation-video-core.entry.js +1 -1
  225. package/dist/esm-es5/taro-animation-view-core.entry.js +1 -1
  226. package/dist/esm-es5/taro-ar-camera-core.entry.js +1 -1
  227. package/dist/esm-es5/taro-audio-core.entry.js +1 -1
  228. package/dist/esm-es5/taro-aweme-data-core.entry.js +1 -1
  229. package/dist/esm-es5/taro-block-core.entry.js +1 -1
  230. package/dist/esm-es5/taro-button-core.entry.js +1 -1
  231. package/dist/esm-es5/taro-camera-core.entry.js +1 -1
  232. package/dist/esm-es5/taro-canvas-core.entry.js +1 -1
  233. package/dist/esm-es5/taro-channel-live-core.entry.js +1 -1
  234. package/dist/esm-es5/taro-channel-video-core.entry.js +1 -1
  235. package/dist/esm-es5/taro-checkbox-core_2.entry.js +1 -1
  236. package/dist/esm-es5/taro-comment-detail-core.entry.js +1 -1
  237. package/dist/esm-es5/taro-comment-list-core.entry.js +1 -1
  238. package/dist/esm-es5/taro-components.js +1 -1
  239. package/dist/esm-es5/taro-contact-button-core.entry.js +1 -1
  240. package/dist/esm-es5/taro-cover-image-core.entry.js +1 -1
  241. package/dist/esm-es5/taro-cover-view-core.entry.js +1 -1
  242. package/dist/esm-es5/taro-custom-wrapper-core.entry.js +1 -1
  243. package/dist/esm-es5/taro-editor-core.entry.js +1 -1
  244. package/dist/esm-es5/taro-follow-swan-core.entry.js +1 -1
  245. package/dist/esm-es5/taro-form-core.entry.js +1 -1
  246. package/dist/esm-es5/taro-functional-page-navigator-core.entry.js +1 -1
  247. package/dist/esm-es5/taro-grid-view-core.entry.js +1 -1
  248. package/dist/esm-es5/taro-icon-core.entry.js +1 -1
  249. package/dist/esm-es5/taro-image-core.entry.js +1 -1
  250. package/dist/esm-es5/taro-inline-payment-panel-core.entry.js +1 -1
  251. package/dist/esm-es5/taro-input-core.entry.js +1 -1
  252. package/dist/esm-es5/taro-keyboard-accessory-core.entry.js +1 -1
  253. package/dist/esm-es5/taro-label-core.entry.js +1 -1
  254. package/dist/esm-es5/taro-lifestyle-core.entry.js +1 -1
  255. package/dist/esm-es5/taro-like-core.entry.js +1 -1
  256. package/dist/esm-es5/taro-list-view-core.entry.js +1 -1
  257. package/dist/esm-es5/taro-live-player-core.entry.js +1 -1
  258. package/dist/esm-es5/taro-live-pusher-core.entry.js +1 -1
  259. package/dist/esm-es5/taro-login-core.entry.js +1 -1
  260. package/dist/esm-es5/taro-lottie-core.entry.js +1 -1
  261. package/dist/esm-es5/taro-map-core.entry.js +1 -1
  262. package/dist/esm-es5/taro-match-media-core.entry.js +1 -1
  263. package/dist/esm-es5/taro-movable-area-core_2.entry.js +1 -1
  264. package/dist/esm-es5/taro-native-slot-core.entry.js +1 -1
  265. package/dist/esm-es5/taro-navigation-bar-core.entry.js +1 -1
  266. package/dist/esm-es5/taro-navigator-core.entry.js +1 -1
  267. package/dist/esm-es5/taro-official-account-core.entry.js +1 -1
  268. package/dist/esm-es5/taro-open-data-core.entry.js +1 -1
  269. package/dist/esm-es5/taro-page-container-core.entry.js +1 -1
  270. package/dist/esm-es5/taro-page-meta-core.entry.js +1 -1
  271. package/dist/esm-es5/taro-picker-core_2.entry.js +1 -1
  272. package/dist/esm-es5/taro-picker-view-column-core_2.entry.js +1 -1
  273. package/dist/esm-es5/taro-progress-core.entry.js +1 -1
  274. package/dist/esm-es5/taro-pull-to-refresh-core.entry.js +1 -1
  275. package/dist/esm-es5/taro-radio-core_2.entry.js +1 -1
  276. package/dist/esm-es5/taro-rich-text-core.entry.js +1 -1
  277. package/dist/esm-es5/taro-root-portal-core.entry.js +1 -1
  278. package/dist/esm-es5/taro-rtc-room-core.entry.js +1 -1
  279. package/dist/esm-es5/taro-rtc-room-item-core.entry.js +1 -1
  280. package/dist/esm-es5/taro-scroll-view-core.entry.js +1 -1
  281. package/dist/esm-es5/taro-share-element-core.entry.js +1 -1
  282. package/dist/esm-es5/taro-slider-core.entry.js +1 -1
  283. package/dist/esm-es5/taro-slot-core.entry.js +1 -1
  284. package/dist/esm-es5/taro-snapshot-core.entry.js +1 -1
  285. package/dist/esm-es5/taro-sticky-header-core.entry.js +1 -1
  286. package/dist/esm-es5/taro-sticky-section-core.entry.js +1 -1
  287. package/dist/esm-es5/taro-swiper-core_2.entry.js +1 -1
  288. package/dist/esm-es5/taro-switch-core.entry.js +1 -1
  289. package/dist/esm-es5/taro-tab-item-core.entry.js +1 -1
  290. package/dist/esm-es5/taro-tabbar.entry.js +1 -1
  291. package/dist/esm-es5/taro-tabs-core.entry.js +1 -1
  292. package/dist/esm-es5/taro-text-core.entry.js +1 -1
  293. package/dist/esm-es5/taro-textarea-core.entry.js +1 -1
  294. package/dist/esm-es5/taro-video-control_3.entry.js +1 -1
  295. package/dist/esm-es5/taro-view-core.entry.js +1 -1
  296. package/dist/esm-es5/taro-voip-room-core.entry.js +1 -1
  297. package/dist/esm-es5/taro-web-view-core.entry.js +1 -1
  298. package/dist/taro-components/{p-ebc7b6fc.entry.js → p-00d05751.entry.js} +1 -1
  299. package/dist/taro-components/p-014534ca.system.entry.js +1 -0
  300. package/dist/taro-components/p-015b3025.system.entry.js +1 -0
  301. package/dist/taro-components/{p-0d7a705b.system.entry.js → p-02dd30fa.system.entry.js} +1 -1
  302. package/dist/taro-components/{p-9e03bc7a.system.entry.js → p-040f15f2.system.entry.js} +1 -1
  303. package/dist/taro-components/p-06cf6b18.system.entry.js +1 -0
  304. package/dist/taro-components/{p-a74c970c.system.entry.js → p-07e94301.system.entry.js} +1 -1
  305. package/dist/taro-components/{p-5e91398a.system.entry.js → p-0cf04b3d.system.entry.js} +1 -1
  306. package/dist/taro-components/p-0e3d8ada.entry.js +1 -0
  307. package/dist/taro-components/p-101f49dd.entry.js +1 -0
  308. package/dist/taro-components/p-10d3c795.system.entry.js +1 -0
  309. package/dist/taro-components/{p-7e8e355b.system.entry.js → p-114f89d6.system.entry.js} +1 -1
  310. package/dist/taro-components/p-1182efdd.system.entry.js +1 -0
  311. package/dist/taro-components/{p-2da9c8fd.entry.js → p-128f9eb0.entry.js} +1 -1
  312. package/dist/taro-components/p-16954dd6.entry.js +1 -0
  313. package/dist/taro-components/p-170ce205.system.entry.js +1 -0
  314. package/dist/taro-components/{p-208e438c.system.entry.js → p-1b42ba7e.system.entry.js} +1 -1
  315. package/dist/taro-components/{p-e598f47b.entry.js → p-1ced140d.entry.js} +1 -1
  316. package/dist/taro-components/{p-fbb2446e.entry.js → p-1d25f4e3.entry.js} +1 -1
  317. package/dist/taro-components/{p-fd7ff0f3.system.entry.js → p-1e3d7899.system.entry.js} +1 -1
  318. package/dist/taro-components/{p-de96861c.system.entry.js → p-1ee83d63.system.entry.js} +1 -1
  319. package/dist/taro-components/p-2059cbc0.system.entry.js +1 -0
  320. package/dist/taro-components/{p-15624788.system.entry.js → p-205a0692.system.entry.js} +1 -1
  321. package/dist/taro-components/p-25bbf4aa.system.entry.js +1 -0
  322. package/dist/taro-components/{p-b07cd197.system.entry.js → p-26545e4e.system.entry.js} +1 -1
  323. package/dist/taro-components/p-28bf8423.system.entry.js +1 -0
  324. package/dist/taro-components/{p-3004e71a.system.entry.js → p-290fd78b.system.entry.js} +1 -1
  325. package/dist/taro-components/p-2bbdbe9c.system.entry.js +1 -0
  326. package/dist/taro-components/{p-a4951dd6.entry.js → p-2d6d4850.entry.js} +1 -1
  327. package/dist/taro-components/{p-9fe49bab.entry.js → p-2dea35fd.entry.js} +1 -1
  328. package/dist/taro-components/p-2f403f7f.entry.js +1 -0
  329. package/dist/taro-components/{p-a2d590ad.entry.js → p-2f683899.entry.js} +1 -1
  330. package/dist/taro-components/p-30623371.entry.js +1 -0
  331. package/dist/taro-components/{p-a2141e85.system.entry.js → p-34933f34.system.entry.js} +1 -1
  332. package/dist/taro-components/{p-92d04741.system.entry.js → p-352b6b6b.system.entry.js} +1 -1
  333. package/dist/taro-components/p-35e96af8.system.entry.js +1 -0
  334. package/dist/taro-components/{p-f78823a1.entry.js → p-37593ce7.entry.js} +1 -1
  335. package/dist/taro-components/p-387f300a.entry.js +1 -0
  336. package/dist/taro-components/p-3afbae36.entry.js +1 -0
  337. package/dist/taro-components/p-3bd04d38.entry.js +1 -0
  338. package/dist/taro-components/{p-21c07cb3.system.entry.js → p-3ca9aa19.system.entry.js} +1 -1
  339. package/dist/taro-components/{p-ce303d12.system.entry.js → p-3d76b46e.system.entry.js} +1 -1
  340. package/dist/taro-components/p-3dadbe4c.system.entry.js +1 -0
  341. package/dist/taro-components/{p-ef322936.entry.js → p-3e9bf572.entry.js} +1 -1
  342. package/dist/taro-components/p-4408d796.entry.js +1 -0
  343. package/dist/taro-components/{p-8ccaf5e8.entry.js → p-445810cb.entry.js} +1 -1
  344. package/dist/taro-components/p-449f60fa.entry.js +1 -0
  345. package/dist/taro-components/p-46661961.entry.js +1 -0
  346. package/dist/taro-components/{p-124ac21f.entry.js → p-48e5ddaa.entry.js} +1 -1
  347. package/dist/taro-components/{p-43720011.entry.js → p-4928ee37.entry.js} +1 -1
  348. package/dist/taro-components/{p-84958ace.entry.js → p-4cbd26dd.entry.js} +1 -1
  349. package/dist/taro-components/p-4e4ac1fe.system.entry.js +1 -0
  350. package/dist/taro-components/{p-d2e0b15c.entry.js → p-4e4cc6ab.entry.js} +1 -1
  351. package/dist/taro-components/{p-fac4ce6f.system.entry.js → p-50e1ba06.system.entry.js} +1 -1
  352. package/dist/taro-components/{p-a6e2dd48.entry.js → p-510a69b3.entry.js} +1 -1
  353. package/dist/taro-components/p-5307637c.system.entry.js +1 -0
  354. package/dist/taro-components/{p-5870248f.system.entry.js → p-54941baf.system.entry.js} +1 -1
  355. package/dist/taro-components/{p-0e3b37e9.entry.js → p-55be4215.entry.js} +1 -1
  356. package/dist/taro-components/{p-c913b635.system.entry.js → p-578f19ea.system.entry.js} +1 -1
  357. package/dist/taro-components/{p-a90221ab.system.entry.js → p-581e844d.system.entry.js} +1 -1
  358. package/dist/taro-components/p-5a1bb2d3.system.entry.js +1 -0
  359. package/dist/taro-components/{p-1cf16dfa.entry.js → p-5bb60b5e.entry.js} +1 -1
  360. package/dist/taro-components/p-600d9210.entry.js +1 -0
  361. package/dist/taro-components/p-6066e633.entry.js +1 -0
  362. package/dist/taro-components/p-61cb688a.entry.js +1 -0
  363. package/dist/taro-components/{p-5994d9f2.system.entry.js → p-6229bb7d.system.entry.js} +1 -1
  364. package/dist/taro-components/p-64f5abce.entry.js +1 -0
  365. package/dist/taro-components/p-67ff5a50.system.entry.js +1 -0
  366. package/dist/taro-components/p-69e747dc.entry.js +1 -0
  367. package/dist/taro-components/{p-7e6b54cb.system.js → p-6bbb639a.system.js} +2 -2
  368. package/dist/taro-components/p-6cf765b7.system.entry.js +1 -0
  369. package/dist/taro-components/{p-f2c86846.entry.js → p-6e9d509a.entry.js} +1 -1
  370. package/dist/taro-components/p-6f027b85.entry.js +1 -0
  371. package/dist/taro-components/p-72b954ce.system.entry.js +1 -0
  372. package/dist/taro-components/p-74129eac.entry.js +1 -0
  373. package/dist/taro-components/{p-473afc8e.system.entry.js → p-74b1be20.system.entry.js} +1 -1
  374. package/dist/taro-components/{p-58cc2e6d.system.entry.js → p-758e3319.system.entry.js} +1 -1
  375. package/dist/taro-components/{p-b5b30493.system.entry.js → p-75b927b4.system.entry.js} +1 -1
  376. package/dist/taro-components/p-764cd497.entry.js +1 -0
  377. package/dist/taro-components/p-7b6f6526.system.entry.js +1 -0
  378. package/dist/taro-components/p-7bd1345f.entry.js +1 -0
  379. package/dist/taro-components/{p-be96eb59.system.entry.js → p-7cecf08e.system.entry.js} +1 -1
  380. package/dist/taro-components/{p-6cde54e5.system.entry.js → p-7f084a29.system.entry.js} +1 -1
  381. package/dist/taro-components/{p-600e89cc.system.entry.js → p-80106cc2.system.entry.js} +1 -1
  382. package/dist/taro-components/{p-76996fcb.entry.js → p-80278124.entry.js} +1 -1
  383. package/dist/taro-components/p-83699a53.entry.js +1 -0
  384. package/dist/taro-components/{p-38ee526a.entry.js → p-846aa5ec.entry.js} +1 -1
  385. package/dist/taro-components/{p-e740320c.entry.js → p-861834ce.entry.js} +1 -1
  386. package/dist/taro-components/{p-d1756770.entry.js → p-870e0d9d.entry.js} +1 -1
  387. package/dist/taro-components/{p-69c43a81.entry.js → p-87422c88.entry.js} +1 -1
  388. package/dist/taro-components/p-88c5f0eb.system.entry.js +1 -0
  389. package/dist/taro-components/{p-22bf7daf.entry.js → p-8b70fd1d.entry.js} +1 -1
  390. package/dist/taro-components/{p-0e8199b7.entry.js → p-8d437a7f.entry.js} +1 -1
  391. package/dist/taro-components/{p-519fbe84.system.entry.js → p-8df92f90.system.entry.js} +1 -1
  392. package/dist/taro-components/p-8e45a207.system.entry.js +1 -0
  393. package/dist/taro-components/p-92daad3f.system.entry.js +1 -0
  394. package/dist/taro-components/{p-7726b789.system.entry.js → p-940d41e9.system.entry.js} +1 -1
  395. package/dist/taro-components/{p-78e4805e.entry.js → p-95058ee1.entry.js} +1 -1
  396. package/dist/taro-components/p-95e88e0f.entry.js +1 -0
  397. package/dist/taro-components/{p-b1d2b575.system.entry.js → p-9623f19c.system.entry.js} +1 -1
  398. package/dist/taro-components/{p-0ec2e88a.entry.js → p-970623a1.entry.js} +1 -1
  399. package/dist/taro-components/{p-24d9836e.entry.js → p-9890bb7b.entry.js} +1 -1
  400. package/dist/taro-components/{p-9137dcab.js → p-98b1fc13.js} +2 -2
  401. package/dist/taro-components/{p-8d990f1c.system.entry.js → p-9937cf08.system.entry.js} +1 -1
  402. package/dist/taro-components/p-9a5bfa2a.system.entry.js +1 -0
  403. package/dist/taro-components/{p-bc541cd8.entry.js → p-9b4e5578.entry.js} +1 -1
  404. package/dist/taro-components/{p-065a10d7.entry.js → p-9e138188.entry.js} +1 -1
  405. package/dist/taro-components/p-a17b1a7e.entry.js +1 -0
  406. package/dist/taro-components/p-a197cbae.system.entry.js +1 -0
  407. package/dist/taro-components/p-a2a70581.system.entry.js +1 -0
  408. package/dist/taro-components/p-a61e195b.entry.js +1 -0
  409. package/dist/taro-components/p-a972aa1d.system.js +1 -0
  410. package/dist/taro-components/p-ae128150.entry.js +1 -0
  411. package/dist/taro-components/p-b04cdd9a.system.entry.js +1 -0
  412. package/dist/taro-components/{p-f2235cbb.entry.js → p-b317674b.entry.js} +1 -1
  413. package/dist/taro-components/p-b6694eb3.system.entry.js +1 -0
  414. package/dist/taro-components/p-b8858af9.system.entry.js +1 -0
  415. package/dist/taro-components/{p-da3db323.entry.js → p-b8e2465a.entry.js} +1 -1
  416. package/dist/taro-components/{p-c99e14b5.entry.js → p-b9f19e77.entry.js} +1 -1
  417. package/dist/taro-components/{p-bf0e0394.entry.js → p-ba195b39.entry.js} +1 -1
  418. package/dist/taro-components/{p-1b789738.system.entry.js → p-ba50342b.system.entry.js} +1 -1
  419. package/dist/taro-components/{p-0fa96970.entry.js → p-bb712e32.entry.js} +1 -1
  420. package/dist/taro-components/p-bb87373d.entry.js +1 -0
  421. package/dist/taro-components/{p-9ea4f297.entry.js → p-bba220a9.entry.js} +1 -1
  422. package/dist/taro-components/{p-f420680c.system.entry.js → p-bcf5d78a.system.entry.js} +1 -1
  423. package/dist/taro-components/p-bdd7b5a9.entry.js +1 -0
  424. package/dist/taro-components/p-bdee068b.system.entry.js +1 -0
  425. package/dist/taro-components/p-bf0d2c21.system.entry.js +1 -0
  426. package/dist/taro-components/{p-aa04f605.entry.js → p-c0f710ae.entry.js} +1 -1
  427. package/dist/taro-components/p-c11fcb25.system.entry.js +1 -0
  428. package/dist/taro-components/p-caba17c6.system.entry.js +1 -0
  429. package/dist/taro-components/p-cbc19d63.entry.js +1 -0
  430. package/dist/taro-components/p-d03136d7.system.entry.js +1 -0
  431. package/dist/taro-components/p-d36f8c4f.entry.js +1 -0
  432. package/dist/taro-components/p-d60b66c2.entry.js +1 -0
  433. package/dist/taro-components/p-d78ab2de.system.entry.js +1 -0
  434. package/dist/taro-components/{p-36d4407e.system.entry.js → p-dbb47d14.system.entry.js} +1 -1
  435. package/dist/taro-components/p-dc6db06e.system.entry.js +1 -0
  436. package/dist/taro-components/{p-f1304456.entry.js → p-dc98486d.entry.js} +1 -1
  437. package/dist/taro-components/p-dca5e9ee.entry.js +1 -0
  438. package/dist/taro-components/{p-c1a3fecf.system.entry.js → p-de3e1cee.system.entry.js} +1 -1
  439. package/dist/taro-components/p-e09e8b51.system.entry.js +1 -0
  440. package/dist/taro-components/{p-8ca82a56.entry.js → p-e1c2e636.entry.js} +1 -1
  441. package/dist/taro-components/{p-30805bdf.entry.js → p-e25c2a22.entry.js} +1 -1
  442. package/dist/taro-components/{p-b641e598.entry.js → p-e26c787b.entry.js} +1 -1
  443. package/dist/taro-components/p-e457a83a.system.entry.js +1 -0
  444. package/dist/taro-components/{p-29638de3.entry.js → p-e7d82e00.entry.js} +1 -1
  445. package/dist/taro-components/{p-9d76d7a9.system.entry.js → p-ebf38559.system.entry.js} +1 -1
  446. package/dist/taro-components/p-eeb6aeb5.system.entry.js +1 -0
  447. package/dist/taro-components/p-ef0aff29.entry.js +1 -0
  448. package/dist/taro-components/p-f554428f.system.entry.js +1 -0
  449. package/dist/taro-components/p-fd1d75db.entry.js +1 -0
  450. package/dist/taro-components/{p-ccc64042.system.entry.js → p-ff7dfc5c.system.entry.js} +1 -1
  451. package/dist/taro-components/taro-components.css +1 -5
  452. package/dist/taro-components/taro-components.esm.js +1 -1
  453. package/dist/taro-components/taro-components.js +1 -1
  454. package/dist/types/components/switch/switch.d.ts +3 -3
  455. package/dist/types/components/textarea/textarea.d.ts +1 -0
  456. package/lib/react/react-component-lib/createComponent.js +3 -2
  457. package/lib/react/react-component-lib/createComponent.js.map +1 -1
  458. package/lib/react/react-component-lib/createOverlayComponent.js +1 -1
  459. package/lib/react/react-component-lib/utils/attachProps.d.ts +16 -7
  460. package/lib/react/react-component-lib/utils/attachProps.js +85 -9
  461. package/lib/react/react-component-lib/utils/attachProps.js.map +1 -1
  462. package/lib/react/react-component-lib/utils/index.js +1 -1
  463. package/package.json +12 -13
  464. package/types/Audio.d.ts +11 -11
  465. package/types/Button.d.ts +9 -9
  466. package/types/Canvas.d.ts +11 -11
  467. package/types/Checkbox.d.ts +8 -8
  468. package/types/CheckboxGroup.d.ts +3 -3
  469. package/types/CoverImage.d.ts +4 -4
  470. package/types/CoverView.d.ts +1 -1
  471. package/types/CustomWrapper.d.ts +1 -1
  472. package/types/Form.d.ts +4 -4
  473. package/types/Icon.d.ts +4 -4
  474. package/types/Image.d.ts +8 -8
  475. package/types/Input.d.ts +21 -17
  476. package/types/Label.d.ts +2 -2
  477. package/types/MovableArea.d.ts +2 -2
  478. package/types/MovableView.d.ts +18 -18
  479. package/types/NativeSlot.d.ts +1 -1
  480. package/types/Navigator.d.ts +8 -8
  481. package/types/Picker.d.ts +44 -28
  482. package/types/PickerView.d.ts +5 -1
  483. package/types/PickerViewColumn.d.ts +1 -1
  484. package/types/Progress.d.ts +13 -13
  485. package/types/Radio.d.ts +7 -7
  486. package/types/RadioGroup.d.ts +2 -2
  487. package/types/RichText.d.ts +5 -5
  488. package/types/ScrollView.d.ts +13 -13
  489. package/types/Slider.d.ts +18 -14
  490. package/types/Slot.d.ts +1 -1
  491. package/types/Swiper.d.ts +17 -17
  492. package/types/SwiperItem.d.ts +2 -2
  493. package/types/Switch.d.ts +11 -7
  494. package/types/Text.d.ts +4 -4
  495. package/types/Textarea.d.ts +17 -13
  496. package/types/Video.d.ts +30 -30
  497. package/types/View.d.ts +4 -4
  498. package/types/WebView.d.ts +4 -4
  499. package/types/common.d.ts +6 -1
  500. package/dist/cjs/hls-00fec546.js +0 -25673
  501. package/dist/cjs/intersection-observer-dc4cfcef.js +0 -728
  502. package/dist/collection/components/input/index.css +0 -12
  503. package/dist/components/hls.js +0 -25671
  504. package/dist/components/intersection-observer.js +0 -726
  505. package/dist/esm/hls-4018c7ea.js +0 -25671
  506. package/dist/esm/intersection-observer-8e4c7135.js +0 -726
  507. package/dist/esm-es5/hls-4018c7ea.js +0 -1
  508. package/dist/esm-es5/index-980f930f.js +0 -2
  509. package/dist/esm-es5/intersection-observer-8e4c7135.js +0 -1
  510. package/dist/taro-components/p-00ed4bbb.entry.js +0 -1
  511. package/dist/taro-components/p-01e163f8.system.entry.js +0 -1
  512. package/dist/taro-components/p-06671eee.entry.js +0 -1
  513. package/dist/taro-components/p-085076c5.system.entry.js +0 -1
  514. package/dist/taro-components/p-08b7ecd7.system.entry.js +0 -1
  515. package/dist/taro-components/p-0a250d71.system.entry.js +0 -1
  516. package/dist/taro-components/p-0cedad18.system.entry.js +0 -1
  517. package/dist/taro-components/p-0fe855c6.entry.js +0 -1
  518. package/dist/taro-components/p-117633e9.system.entry.js +0 -1
  519. package/dist/taro-components/p-1e739fcb.system.entry.js +0 -1
  520. package/dist/taro-components/p-1f118969.system.entry.js +0 -1
  521. package/dist/taro-components/p-2a071adf.system.entry.js +0 -1
  522. package/dist/taro-components/p-32e9981a.system.entry.js +0 -1
  523. package/dist/taro-components/p-357ba712.system.entry.js +0 -1
  524. package/dist/taro-components/p-3b1d2d37.system.js +0 -1
  525. package/dist/taro-components/p-3f3abe55.system.entry.js +0 -1
  526. package/dist/taro-components/p-425c209a.entry.js +0 -1
  527. package/dist/taro-components/p-43efbf30.js +0 -1
  528. package/dist/taro-components/p-4cedbe5e.system.entry.js +0 -1
  529. package/dist/taro-components/p-4fc40739.entry.js +0 -1
  530. package/dist/taro-components/p-5756cf00.system.entry.js +0 -1
  531. package/dist/taro-components/p-5ebc7010.system.entry.js +0 -1
  532. package/dist/taro-components/p-64eb91f7.entry.js +0 -1
  533. package/dist/taro-components/p-657cb6e4.system.entry.js +0 -1
  534. package/dist/taro-components/p-6aa2ac6a.system.entry.js +0 -1
  535. package/dist/taro-components/p-6b454506.entry.js +0 -1
  536. package/dist/taro-components/p-72b118b0.entry.js +0 -1
  537. package/dist/taro-components/p-72f327e1.js +0 -1
  538. package/dist/taro-components/p-7b68dee8.entry.js +0 -1
  539. package/dist/taro-components/p-7bfc5f3d.entry.js +0 -1
  540. package/dist/taro-components/p-862b38b9.entry.js +0 -1
  541. package/dist/taro-components/p-962f28cb.entry.js +0 -1
  542. package/dist/taro-components/p-99e16df8.entry.js +0 -1
  543. package/dist/taro-components/p-9a5fbb2e.entry.js +0 -1
  544. package/dist/taro-components/p-9b0298bf.entry.js +0 -1
  545. package/dist/taro-components/p-9dcba4a7.system.entry.js +0 -1
  546. package/dist/taro-components/p-9edea30f.system.entry.js +0 -1
  547. package/dist/taro-components/p-9eeba192.entry.js +0 -1
  548. package/dist/taro-components/p-9feff958.system.entry.js +0 -1
  549. package/dist/taro-components/p-a1763153.entry.js +0 -1
  550. package/dist/taro-components/p-a20fed0a.entry.js +0 -1
  551. package/dist/taro-components/p-a5a51112.entry.js +0 -1
  552. package/dist/taro-components/p-a7d31b01.system.entry.js +0 -1
  553. package/dist/taro-components/p-a940a65b.entry.js +0 -1
  554. package/dist/taro-components/p-a94e3347.system.entry.js +0 -1
  555. package/dist/taro-components/p-ad9b04e0.entry.js +0 -1
  556. package/dist/taro-components/p-b0fc8752.entry.js +0 -1
  557. package/dist/taro-components/p-b201ff38.entry.js +0 -1
  558. package/dist/taro-components/p-bd4ed8b1.entry.js +0 -1
  559. package/dist/taro-components/p-bf0c8449.system.entry.js +0 -1
  560. package/dist/taro-components/p-c0080d83.entry.js +0 -1
  561. package/dist/taro-components/p-cb406f85.system.entry.js +0 -1
  562. package/dist/taro-components/p-cbcaad0e.system.entry.js +0 -1
  563. package/dist/taro-components/p-d025a415.system.entry.js +0 -1
  564. package/dist/taro-components/p-d550aea9.system.entry.js +0 -1
  565. package/dist/taro-components/p-d5c8380d.system.entry.js +0 -1
  566. package/dist/taro-components/p-d867e333.system.entry.js +0 -1
  567. package/dist/taro-components/p-d9dcc6c6.entry.js +0 -1
  568. package/dist/taro-components/p-dab28e1f.system.entry.js +0 -1
  569. package/dist/taro-components/p-dadd02ca.entry.js +0 -1
  570. package/dist/taro-components/p-dc5d65a0.system.entry.js +0 -1
  571. package/dist/taro-components/p-e09451c5.system.entry.js +0 -1
  572. package/dist/taro-components/p-e2cd5dd3.system.entry.js +0 -1
  573. package/dist/taro-components/p-e6481671.system.entry.js +0 -1
  574. package/dist/taro-components/p-e67755f0.system.entry.js +0 -1
  575. package/dist/taro-components/p-e78775ce.system.js +0 -1
  576. package/dist/taro-components/p-e976c6c9.system.entry.js +0 -1
  577. package/dist/taro-components/p-ea0d5d4f.system.entry.js +0 -1
  578. package/dist/taro-components/p-ed331c06.system.js +0 -1
  579. package/dist/taro-components/p-eee6e075.system.entry.js +0 -1
  580. package/dist/taro-components/p-f02b6f70.entry.js +0 -1
  581. package/dist/taro-components/p-f0340edf.entry.js +0 -1
  582. package/dist/taro-components/p-f23cfdc8.entry.js +0 -1
  583. package/dist/taro-components/p-f4d86882.entry.js +0 -1
  584. package/dist/taro-components/p-f533bc2f.entry.js +0 -1
  585. package/dist/taro-components/p-f658de2e.entry.js +0 -1
  586. package/dist/taro-components/p-f6f6a996.system.entry.js +0 -1
  587. package/lib/react/node_modules/.pnpm/registry.npmjs.org_tslib@2.5.0/node_modules/tslib/tslib.es6.js +0 -296
  588. package/lib/react/node_modules/.pnpm/registry.npmjs.org_tslib@2.5.0/node_modules/tslib/tslib.es6.js.map +0 -1
@@ -1 +0,0 @@
1
- function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var s,i,e,n,r;s=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,i=/^(?=([^\/?#]*))\1([^]*)$/,e=/(?:\/|^)\.(?=\/)/g,n=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g;var h={exports:{}}.exports=r={buildAbsoluteURL:function(t,s,e){if(e=e||{},t=t.trim(),!(s=s.trim())){if(!e.alwaysNormalize)return t;var n=r.parseURL(t);if(!n)throw new Error("Error trying to parse base URL.");return n.path=r.normalizePath(n.path),r.buildURLFromParts(n)}var h=r.parseURL(s);if(!h)throw new Error("Error trying to parse relative URL.");if(h.scheme)return e.alwaysNormalize?(h.path=r.normalizePath(h.path),r.buildURLFromParts(h)):s;var o=r.parseURL(t);if(!o)throw new Error("Error trying to parse base URL.");if(!o.netLoc&&o.path&&"/"!==o.path[0]){var a=i.exec(o.path);o.netLoc=a[1],o.path=a[2]}o.netLoc&&!o.path&&(o.path="/");var l={scheme:o.scheme,netLoc:h.netLoc,path:null,params:h.params,query:h.query,fragment:h.fragment};if(!h.netLoc&&(l.netLoc=o.netLoc,"/"!==h.path[0]))if(h.path){var c=o.path,u=c.substring(0,c.lastIndexOf("/")+1)+h.path;l.path=r.normalizePath(u)}else l.path=o.path,h.params||(l.params=o.params,h.query||(l.query=o.query));return null===l.path&&(l.path=e.alwaysNormalize?r.normalizePath(h.path):h.path),r.buildURLFromParts(l)},parseURL:function(t){var i=s.exec(t);return i?{scheme:i[1]||"",netLoc:i[2]||"",path:i[3]||"",params:i[4]||"",query:i[5]||"",fragment:i[6]||""}:null},normalizePath:function(t){for(t=t.split("").reverse().join("").replace(e,"");t.length!==(t=t.replace(n,"")).length;);return t.split("").reverse().join("")},buildURLFromParts:function(t){return t.scheme+t.netLoc+t.path+t.params+t.query+t.fragment}};function o(t,s){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);s&&(e=e.filter((function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable}))),i.push.apply(i,e)}return i}function a(t){for(var s=1;s<arguments.length;s++){var i=null!=arguments[s]?arguments[s]:{};s%2?o(Object(i),!0).forEach((function(s){l(t,s,i[s])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):o(Object(i)).forEach((function(s){Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(i,s))}))}return t}function l(t,s,i){return(s=function(t){var s=function(t){if("object"!=typeof t||null===t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var i=s.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof s?s:String(s)}(s))in t?Object.defineProperty(t,s,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[s]=i,t}function c(){return c=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var i=arguments[s];for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])}return t},c.apply(this,arguments)}const u=Number.isFinite||function(t){return"number"==typeof t&&isFinite(t)};let d=function(t){return t.MEDIA_ATTACHING="hlsMediaAttaching",t.MEDIA_ATTACHED="hlsMediaAttached",t.MEDIA_DETACHING="hlsMediaDetaching",t.MEDIA_DETACHED="hlsMediaDetached",t.BUFFER_RESET="hlsBufferReset",t.BUFFER_CODECS="hlsBufferCodecs",t.BUFFER_CREATED="hlsBufferCreated",t.BUFFER_APPENDING="hlsBufferAppending",t.BUFFER_APPENDED="hlsBufferAppended",t.BUFFER_EOS="hlsBufferEos",t.BUFFER_FLUSHING="hlsBufferFlushing",t.BUFFER_FLUSHED="hlsBufferFlushed",t.MANIFEST_LOADING="hlsManifestLoading",t.MANIFEST_LOADED="hlsManifestLoaded",t.MANIFEST_PARSED="hlsManifestParsed",t.LEVEL_SWITCHING="hlsLevelSwitching",t.LEVEL_SWITCHED="hlsLevelSwitched",t.LEVEL_LOADING="hlsLevelLoading",t.LEVEL_LOADED="hlsLevelLoaded",t.LEVEL_UPDATED="hlsLevelUpdated",t.LEVEL_PTS_UPDATED="hlsLevelPtsUpdated",t.LEVELS_UPDATED="hlsLevelsUpdated",t.AUDIO_TRACKS_UPDATED="hlsAudioTracksUpdated",t.AUDIO_TRACK_SWITCHING="hlsAudioTrackSwitching",t.AUDIO_TRACK_SWITCHED="hlsAudioTrackSwitched",t.AUDIO_TRACK_LOADING="hlsAudioTrackLoading",t.AUDIO_TRACK_LOADED="hlsAudioTrackLoaded",t.SUBTITLE_TRACKS_UPDATED="hlsSubtitleTracksUpdated",t.SUBTITLE_TRACKS_CLEARED="hlsSubtitleTracksCleared",t.SUBTITLE_TRACK_SWITCH="hlsSubtitleTrackSwitch",t.SUBTITLE_TRACK_LOADING="hlsSubtitleTrackLoading",t.SUBTITLE_TRACK_LOADED="hlsSubtitleTrackLoaded",t.SUBTITLE_FRAG_PROCESSED="hlsSubtitleFragProcessed",t.CUES_PARSED="hlsCuesParsed",t.NON_NATIVE_TEXT_TRACKS_FOUND="hlsNonNativeTextTracksFound",t.INIT_PTS_FOUND="hlsInitPtsFound",t.FRAG_LOADING="hlsFragLoading",t.FRAG_LOAD_EMERGENCY_ABORTED="hlsFragLoadEmergencyAborted",t.FRAG_LOADED="hlsFragLoaded",t.FRAG_DECRYPTED="hlsFragDecrypted",t.FRAG_PARSING_INIT_SEGMENT="hlsFragParsingInitSegment",t.FRAG_PARSING_USERDATA="hlsFragParsingUserdata",t.FRAG_PARSING_METADATA="hlsFragParsingMetadata",t.FRAG_PARSED="hlsFragParsed",t.FRAG_BUFFERED="hlsFragBuffered",t.FRAG_CHANGED="hlsFragChanged",t.FPS_DROP="hlsFpsDrop",t.FPS_DROP_LEVEL_CAPPING="hlsFpsDropLevelCapping",t.ERROR="hlsError",t.DESTROYING="hlsDestroying",t.KEY_LOADING="hlsKeyLoading",t.KEY_LOADED="hlsKeyLoaded",t.LIVE_BACK_BUFFER_REACHED="hlsLiveBackBufferReached",t.BACK_BUFFER_REACHED="hlsBackBufferReached",t}({}),f=function(t){return t.NETWORK_ERROR="networkError",t.MEDIA_ERROR="mediaError",t.KEY_SYSTEM_ERROR="keySystemError",t.MUX_ERROR="muxError",t.OTHER_ERROR="otherError",t}({}),m=function(t){return t.KEY_SYSTEM_NO_KEYS="keySystemNoKeys",t.KEY_SYSTEM_NO_ACCESS="keySystemNoAccess",t.KEY_SYSTEM_NO_SESSION="keySystemNoSession",t.KEY_SYSTEM_NO_CONFIGURED_LICENSE="keySystemNoConfiguredLicense",t.KEY_SYSTEM_LICENSE_REQUEST_FAILED="keySystemLicenseRequestFailed",t.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED="keySystemServerCertificateRequestFailed",t.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED="keySystemServerCertificateUpdateFailed",t.KEY_SYSTEM_SESSION_UPDATE_FAILED="keySystemSessionUpdateFailed",t.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED="keySystemStatusOutputRestricted",t.KEY_SYSTEM_STATUS_INTERNAL_ERROR="keySystemStatusInternalError",t.MANIFEST_LOAD_ERROR="manifestLoadError",t.MANIFEST_LOAD_TIMEOUT="manifestLoadTimeOut",t.MANIFEST_PARSING_ERROR="manifestParsingError",t.MANIFEST_INCOMPATIBLE_CODECS_ERROR="manifestIncompatibleCodecsError",t.LEVEL_EMPTY_ERROR="levelEmptyError",t.LEVEL_LOAD_ERROR="levelLoadError",t.LEVEL_LOAD_TIMEOUT="levelLoadTimeOut",t.LEVEL_PARSING_ERROR="levelParsingError",t.LEVEL_SWITCH_ERROR="levelSwitchError",t.AUDIO_TRACK_LOAD_ERROR="audioTrackLoadError",t.AUDIO_TRACK_LOAD_TIMEOUT="audioTrackLoadTimeOut",t.SUBTITLE_LOAD_ERROR="subtitleTrackLoadError",t.SUBTITLE_TRACK_LOAD_TIMEOUT="subtitleTrackLoadTimeOut",t.FRAG_LOAD_ERROR="fragLoadError",t.FRAG_LOAD_TIMEOUT="fragLoadTimeOut",t.FRAG_DECRYPT_ERROR="fragDecryptError",t.FRAG_PARSING_ERROR="fragParsingError",t.FRAG_GAP="fragGap",t.REMUX_ALLOC_ERROR="remuxAllocError",t.KEY_LOAD_ERROR="keyLoadError",t.KEY_LOAD_TIMEOUT="keyLoadTimeOut",t.BUFFER_ADD_CODEC_ERROR="bufferAddCodecError",t.BUFFER_INCOMPATIBLE_CODECS_ERROR="bufferIncompatibleCodecsError",t.BUFFER_APPEND_ERROR="bufferAppendError",t.BUFFER_APPENDING_ERROR="bufferAppendingError",t.BUFFER_STALLED_ERROR="bufferStalledError",t.BUFFER_FULL_ERROR="bufferFullError",t.BUFFER_SEEK_OVER_HOLE="bufferSeekOverHole",t.BUFFER_NUDGE_ON_STALL="bufferNudgeOnStall",t.INTERNAL_EXCEPTION="internalException",t.INTERNAL_ABORTED="aborted",t.UNKNOWN="unknown",t}({});const g=function(){},v={trace:g,debug:g,log:g,warn:g,info:g,error:g};let p=v;const y=p,w=/^(\d+)x(\d+)$/,b=/(.+?)=(".*?"|.*?)(?:,|$)/g;class T{constructor(t){"string"==typeof t&&(t=T.parseAttrList(t));for(const s in t)t.hasOwnProperty(s)&&("X-"===s.substring(0,2)&&(this.clientAttrs=this.clientAttrs||[],this.clientAttrs.push(s)),this[s]=t[s])}decimalInteger(t){const s=parseInt(this[t],10);return s>Number.MAX_SAFE_INTEGER?1/0:s}hexadecimalInteger(t){if(this[t]){let s=(this[t]||"0x").slice(2);s=(1&s.length?"0":"")+s;const i=new Uint8Array(s.length/2);for(let t=0;t<s.length/2;t++)i[t]=parseInt(s.slice(2*t,2*t+2),16);return i}return null}hexadecimalIntegerAsNumber(t){const s=parseInt(this[t],16);return s>Number.MAX_SAFE_INTEGER?1/0:s}decimalFloatingPoint(t){return parseFloat(this[t])}optionalFloat(t,s){const i=this[t];return i?parseFloat(i):s}enumeratedString(t){return this[t]}bool(t){return"YES"===this[t]}decimalResolution(t){const s=w.exec(this[t]);if(null!==s)return{width:parseInt(s[1],10),height:parseInt(s[2],10)}}static parseAttrList(t){let s;const i={};for(b.lastIndex=0;null!==(s=b.exec(t));){let t=s[2];0===t.indexOf('"')&&t.lastIndexOf('"')===t.length-1&&(t=t.slice(1,-1)),i[s[1].trim()]=t}return i}}function S(t){return"SCTE35-OUT"===t||"SCTE35-IN"===t}class E{constructor(t,s){if(this.attr=void 0,this._startDate=void 0,this._endDate=void 0,this._badValueForSameId=void 0,s){const i=s.attr;for(const s in i)if(Object.prototype.hasOwnProperty.call(t,s)&&t[s]!==i[s]){y.warn(`DATERANGE tag attribute: "${s}" does not match for tags with ID: "${t.ID}"`),this._badValueForSameId=s;break}t=c(new T({}),i,t)}if(this.attr=t,this._startDate=new Date(t["START-DATE"]),"END-DATE"in this.attr){const t=new Date(this.attr["END-DATE"]);u(t.getTime())&&(this._endDate=t)}}get id(){return this.attr.ID}get class(){return this.attr.CLASS}get startDate(){return this._startDate}get endDate(){if(this._endDate)return this._endDate;const t=this.duration;return null!==t?new Date(this._startDate.getTime()+1e3*t):null}get duration(){if("DURATION"in this.attr){const t=this.attr.decimalFloatingPoint("DURATION");if(u(t))return t}else if(this._endDate)return(this._endDate.getTime()-this._startDate.getTime())/1e3;return null}get plannedDuration(){return"PLANNED-DURATION"in this.attr?this.attr.decimalFloatingPoint("PLANNED-DURATION"):null}get endOnNext(){return this.attr.bool("END-ON-NEXT")}get isValid(){return!!this.id&&!this._badValueForSameId&&u(this.startDate.getTime())&&(null===this.duration||this.duration>=0)&&(!this.endOnNext||!!this.class)}}class k{constructor(){this.aborted=!1,this.loaded=0,this.retry=0,this.total=0,this.chunkCount=0,this.bwEstimate=0,this.loading={start:0,first:0,end:0},this.parsing={start:0,end:0},this.buffering={start:0,first:0,end:0}}}var $="audio",A="video",L="audiovideo";class M{constructor(t){this._byteRange=null,this._url=null,this.baseurl=void 0,this.relurl=void 0,this.elementaryStreams={[$]:null,[A]:null,[L]:null},this.baseurl=t}setByteRange(t,s){const i=t.split("@",2),e=[];e[0]=1===i.length?s?s.byteRangeEndOffset:0:parseInt(i[1]),e[1]=parseInt(i[0])+e[0],this._byteRange=e}get byteRange(){return this._byteRange?this._byteRange:[]}get byteRangeStartOffset(){return this.byteRange[0]}get byteRangeEndOffset(){return this.byteRange[1]}get url(){return!this._url&&this.baseurl&&this.relurl&&(this._url=h.buildAbsoluteURL(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url||""}set url(t){this._url=t}}class D extends M{constructor(t,s){super(s),this._decryptdata=null,this.rawProgramDateTime=null,this.programDateTime=null,this.tagList=[],this.duration=0,this.sn=0,this.levelkeys=void 0,this.type=void 0,this.loader=null,this.keyLoader=null,this.level=-1,this.cc=0,this.startPTS=void 0,this.endPTS=void 0,this.startDTS=void 0,this.endDTS=void 0,this.start=0,this.deltaPTS=void 0,this.maxStartPTS=void 0,this.minEndPTS=void 0,this.stats=new k,this.urlId=0,this.data=void 0,this.bitrateTest=!1,this.title=null,this.initSegment=null,this.endList=void 0,this.gap=void 0,this.type=t}get decryptdata(){const{levelkeys:t}=this;if(!t&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkeys&&!this.levelkeys.NONE){const t=this.levelkeys.identity;if(t)this._decryptdata=t.getDecryptData(this.sn);else{const t=Object.keys(this.levelkeys);if(1===t.length)return this._decryptdata=this.levelkeys[t[0]].getDecryptData(this.sn)}}return this._decryptdata}get end(){return this.start+this.duration}get endProgramDateTime(){if(null===this.programDateTime)return null;if(!u(this.programDateTime))return null;const t=u(this.duration)?this.duration:0;return this.programDateTime+1e3*t}get encrypted(){var t;if(null!=(t=this._decryptdata)&&t.encrypted)return!0;if(this.levelkeys){const t=Object.keys(this.levelkeys),s=t.length;if(s>1||1===s&&this.levelkeys[t[0]].encrypted)return!0}return!1}setKeyFormat(t){if(this.levelkeys){const s=this.levelkeys[t];s&&!this._decryptdata&&(this._decryptdata=s.getDecryptData(this.sn))}}abortRequests(){var t,s;null==(t=this.loader)||t.abort(),null==(s=this.keyLoader)||s.abort()}setElementaryStreamInfo(t,s,i,e,n,r=!1){const{elementaryStreams:h}=this,o=h[t];o?(o.startPTS=Math.min(o.startPTS,s),o.endPTS=Math.max(o.endPTS,i),o.startDTS=Math.min(o.startDTS,e),o.endDTS=Math.max(o.endDTS,n)):h[t]={startPTS:s,endPTS:i,startDTS:e,endDTS:n,partial:r}}clearElementaryStreamInfo(){const{elementaryStreams:t}=this;t[$]=null,t[A]=null,t[L]=null}}class x extends M{constructor(t,s,i,e,n){super(i),this.fragOffset=0,this.duration=0,this.gap=!1,this.independent=!1,this.relurl=void 0,this.fragment=void 0,this.index=void 0,this.stats=new k,this.duration=t.decimalFloatingPoint("DURATION"),this.gap=t.bool("GAP"),this.independent=t.bool("INDEPENDENT"),this.relurl=t.enumeratedString("URI"),this.fragment=s,this.index=e;const r=t.enumeratedString("BYTERANGE");r&&this.setByteRange(r,n),n&&(this.fragOffset=n.fragOffset+n.duration)}get start(){return this.fragment.start+this.fragOffset}get end(){return this.start+this.duration}get loaded(){const{elementaryStreams:t}=this;return!!(t.audio||t.video||t.audiovideo)}}class I{constructor(t){this.PTSKnown=!1,this.alignedSliding=!1,this.averagetargetduration=void 0,this.endCC=0,this.endSN=0,this.fragments=void 0,this.fragmentHint=void 0,this.partList=null,this.dateRanges=void 0,this.live=!0,this.ageHeader=0,this.advancedDateTime=void 0,this.updated=!0,this.advanced=!0,this.availabilityDelay=void 0,this.misses=0,this.startCC=0,this.startSN=0,this.startTimeOffset=null,this.targetduration=0,this.totalduration=0,this.type=null,this.url=void 0,this.m3u8="",this.version=null,this.canBlockReload=!1,this.canSkipUntil=0,this.canSkipDateRanges=!1,this.skippedSegments=0,this.recentlyRemovedDateranges=void 0,this.partHoldBack=0,this.holdBack=0,this.partTarget=0,this.preloadHint=void 0,this.renditionReports=void 0,this.tuneInGoal=0,this.deltaUpdateFailed=void 0,this.driftStartTime=0,this.driftEndTime=0,this.driftStart=0,this.driftEnd=0,this.encryptedFragments=void 0,this.playlistParsingError=null,this.variableList=null,this.hasVariableRefs=!1,this.fragments=[],this.encryptedFragments=[],this.dateRanges={},this.url=t}reloaded(t){if(!t)return this.advanced=!0,void(this.updated=!0);const s=this.lastPartSn-t.lastPartSn,i=this.lastPartIndex-t.lastPartIndex;this.updated=this.endSN!==t.endSN||!!i||!!s,this.advanced=this.endSN>t.endSN||s>0||0===s&&i>0,this.misses=this.updated||this.advanced?Math.floor(.6*t.misses):t.misses+1,this.availabilityDelay=t.availabilityDelay}get hasProgramDateTime(){return!!this.fragments.length&&u(this.fragments[this.fragments.length-1].programDateTime)}get levelTargetDuration(){return this.averagetargetduration||this.targetduration||10}get drift(){const t=this.driftEndTime-this.driftStartTime;return t>0?1e3*(this.driftEnd-this.driftStart)/t:1}get edge(){return this.partEnd||this.fragmentEnd}get partEnd(){var t;return null!=(t=this.partList)&&t.length?this.partList[this.partList.length-1].end:this.fragmentEnd}get fragmentEnd(){var t;return null!=(t=this.fragments)&&t.length?this.fragments[this.fragments.length-1].end:0}get age(){return this.advancedDateTime?Math.max(Date.now()-this.advancedDateTime,0)/1e3:0}get lastPartIndex(){var t;return null!=(t=this.partList)&&t.length?this.partList[this.partList.length-1].index:-1}get lastPartSn(){var t;return null!=(t=this.partList)&&t.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}}function C(t){return Uint8Array.from(atob(t),(t=>t.charCodeAt(0)))}function P(t){return Uint8Array.from(unescape(encodeURIComponent(t)),(t=>t.charCodeAt(0)))}var R={CLEARKEY:"org.w3.clearkey",FAIRPLAY:"com.apple.fps",PLAYREADY:"com.microsoft.playready",WIDEVINE:"com.widevine.alpha"},O="org.w3.clearkey",N="com.apple.streamingkeydelivery",U="com.microsoft.playready",F="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed";function B(t){switch(t){case N:return R.FAIRPLAY;case U:return R.PLAYREADY;case F:return R.WIDEVINE;case O:return R.CLEARKEY}}var _="edef8ba979d64acea3c827dcd51d21ed";function j(t){switch(t){case R.FAIRPLAY:return N;case R.PLAYREADY:return U;case R.WIDEVINE:return F;case R.CLEARKEY:return O}}function K(t){const{drmSystems:s,widevineLicenseUrl:i}=t,e=s?[R.FAIRPLAY,R.WIDEVINE,R.PLAYREADY,R.CLEARKEY].filter((t=>!!s[t])):[];return!e[R.WIDEVINE]&&i&&e.push(R.WIDEVINE),e}const H="undefined"!=typeof self&&self.navigator&&self.navigator.requestMediaKeySystemAccess?self.navigator.requestMediaKeySystemAccess.bind(self.navigator):null;function G(t,s,i){return Uint8Array.prototype.slice?t.slice(s,i):new Uint8Array(Array.prototype.slice.call(t,s,i))}const V=(t,s)=>s+10<=t.length&&73===t[s]&&68===t[s+1]&&51===t[s+2]&&t[s+3]<255&&t[s+4]<255&&t[s+6]<128&&t[s+7]<128&&t[s+8]<128&&t[s+9]<128,W=(t,s)=>s+10<=t.length&&51===t[s]&&68===t[s+1]&&73===t[s+2]&&t[s+3]<255&&t[s+4]<255&&t[s+6]<128&&t[s+7]<128&&t[s+8]<128&&t[s+9]<128,X=(t,s)=>{const i=s;let e=0;for(;V(t,s);)e+=10,e+=q(t,s+6),W(t,s+10)&&(e+=10),s+=e;if(e>0)return t.subarray(i,i+e)},q=(t,s)=>{let i=0;return i=(127&t[s])<<21,i|=(127&t[s+1])<<14,i|=(127&t[s+2])<<7,i|=127&t[s+3],i},Y=(t,s)=>V(t,s)&&q(t,s+6)+10<=t.length-s,z=t=>t&&"PRIV"===t.key&&"com.apple.streaming.transportStreamTimestamp"===t.info,Q=t=>{const s=String.fromCharCode(t[0],t[1],t[2],t[3]),i=q(t,4);return{type:s,size:i,data:t.subarray(10,10+i)}},J=t=>{let s=0;const i=[];for(;V(t,s);){const e=q(t,s+6);s+=10;const n=s+e;for(;s+8<n;){const e=Q(t.subarray(s)),n=Z(e);n&&i.push(n),s+=e.size+10}W(t,s)&&(s+=10)}return i},Z=t=>"PRIV"===t.type?tt(t):"W"===t.type[0]?it(t):st(t),tt=t=>{if(t.size<2)return;const s=nt(t.data,!0),i=new Uint8Array(t.data.subarray(s.length+1));return{key:t.type,info:s,data:i.buffer}},st=t=>{if(t.size<2)return;if("TXXX"===t.type){let s=1;const i=nt(t.data.subarray(s),!0);s+=i.length+1;const e=nt(t.data.subarray(s));return{key:t.type,info:i,data:e}}const s=nt(t.data.subarray(1));return{key:t.type,data:s}},it=t=>{if("WXXX"===t.type){if(t.size<2)return;let s=1;const i=nt(t.data.subarray(s),!0);s+=i.length+1;const e=nt(t.data.subarray(s));return{key:t.type,info:i,data:e}}const s=nt(t.data);return{key:t.type,data:s}},et=t=>{if(8===t.data.byteLength){const s=new Uint8Array(t.data);let i=(s[4]<<23)+(s[5]<<15)+(s[6]<<7)+s[7];return i/=45,1&s[3]&&(i+=47721858.84),Math.round(i)}},nt=(t,s=!1)=>{const i=ht();if(i){const e=i.decode(t);if(s){const t=e.indexOf("\0");return-1!==t?e.substring(0,t):e}return e.replace(/\0/g,"")}const e=t.length;let n,r,h,o="",a=0;for(;a<e;){if(n=t[a++],0===n&&s)return o;if(0!==n&&3!==n)switch(n>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:o+=String.fromCharCode(n);break;case 12:case 13:r=t[a++],o+=String.fromCharCode((31&n)<<6|63&r);break;case 14:r=t[a++],h=t[a++],o+=String.fromCharCode((15&n)<<12|(63&r)<<6|(63&h)<<0)}}return o};let rt;function ht(){return rt||void 0===self.TextDecoder||(rt=new self.TextDecoder("utf-8")),rt}const ot=function(t){let s="";for(let i=0;i<t.length;i++){let e=t[i].toString(16);e.length<2&&(e="0"+e),s+=e}return s},at=Math.pow(2,32)-1,lt=[].push,ct={video:1,audio:2,id3:3,text:4};function ut(t){return String.fromCharCode.apply(null,t)}function dt(t,s){const i=t[s]<<8|t[s+1];return i<0?65536+i:i}function ft(t,s){const i=mt(t,s);return i<0?4294967296+i:i}function mt(t,s){return t[s]<<24|t[s+1]<<16|t[s+2]<<8|t[s+3]}function gt(t,s,i){t[s]=i>>24,t[s+1]=i>>16&255,t[s+2]=i>>8&255,t[s+3]=255&i}function vt(t,s){const i=[];if(!s.length)return i;const e=t.byteLength;for(let n=0;n<e;){const r=ft(t,n),h=r>1?n+r:e;if(ut(t.subarray(n+4,n+8))===s[0])if(1===s.length)i.push(t.subarray(n+8,h));else{const e=vt(t.subarray(n+8,h),s.slice(1));e.length&&lt.apply(i,e)}n=h}return i}function pt(t){const s=[],i=t[0];let e=8;const n=ft(t,e);e+=4,e+=0===i?8:16,e+=2;let r=t.length+0;const h=dt(t,e);e+=2;for(let i=0;i<h;i++){let i=e;const h=ft(t,i);i+=4;const o=2147483647&h;if(1==(2147483648&h)>>>31)return y.warn("SIDX has hierarchical references (not supported)"),null;const a=ft(t,i);i+=4,s.push({referenceSize:o,subsegmentDuration:a,info:{duration:a/n,start:r,end:r+o-1}}),r+=o,i+=4,e=i}return{earliestPresentationTime:0,timescale:n,version:i,referencesCount:h,references:s}}function yt(t){const s=[],i=vt(t,["moov","trak"]);for(let t=0;t<i.length;t++){const e=i[t],n=vt(e,["tkhd"])[0];if(n){let t=n[0],i=0===t?12:20;const r=ft(n,i),h=vt(e,["mdia","mdhd"])[0];if(h){t=h[0],i=0===t?12:20;const n=ft(h,i),o=vt(e,["mdia","hdlr"])[0];if(o){const t=ut(o.subarray(8,12)),i={soun:$,vide:A}[t];if(i){const t=vt(e,["mdia","minf","stbl","stsd"])[0];let h;t&&(h=ut(t.subarray(12,16))),s[r]={timescale:n,type:i},s[i]={timescale:n,id:r,codec:h}}}}}}return vt(t,["moov","mvex","trex"]).forEach((t=>{const i=ft(t,4),e=s[i];e&&(e.default={duration:ft(t,12),flags:ft(t,20)})})),s}function wt(t){const s=vt(t,["schm"])[0];if(s){const i=ut(s.subarray(4,8));if("cbcs"===i||"cenc"===i)return vt(t,["schi","tenc"])[0]}return y.error("[eme] missing 'schm' box"),null}function bt(t){const s=ft(t,0);let i=8;1&s&&(i+=4),4&s&&(i+=4);let e=0;const n=ft(t,4);for(let r=0;r<n;r++)256&s&&(e+=ft(t,i),i+=4),512&s&&(i+=4),1024&s&&(i+=4),2048&s&&(i+=4);return e}function Tt(t,s){const i=new Uint8Array(t.length+s.length);return i.set(t),i.set(s,t.length),i}function St(t,s){const i=[],e=s.samples,n=s.timescale,r=s.id;let h=!1;return vt(e,["moof"]).map((o=>{const a=o.byteOffset-8;vt(o,["traf"]).map((o=>{const l=vt(o,["tfdt"]).map((t=>{const s=t[0];let i=ft(t,4);return 1===s&&(i*=Math.pow(2,32),i+=ft(t,8)),i/n}))[0];return void 0!==l&&(t=l),vt(o,["tfhd"]).map((l=>{const c=ft(l,4),u=16777215&ft(l,0);let d=0;const f=0!=(16&u);let m=0;const g=0!=(32&u);let v=8;c===r&&(0!=(1&u)&&(v+=8),0!=(2&u)&&(v+=4),0!=(8&u)&&(d=ft(l,v),v+=4),f&&(m=ft(l,v),v+=4),g&&(v+=4),"video"===s.type&&(h=function(t){if(!t)return!1;const s=t.indexOf("."),i=s<0?t:t.substring(0,s);return"hvc1"===i||"hev1"===i||"dvh1"===i||"dvhe"===i}(s.codec)),vt(o,["trun"]).map((r=>{const o=r[0],l=16777215&ft(r,0),c=0!=(1&l);let u=0;const f=0!=(4&l),g=0!=(256&l);let v=0;const p=0!=(512&l);let y=0;const w=0!=(1024&l),b=0!=(2048&l);let T=0;const S=ft(r,4);let E=8;c&&(u=ft(r,E),E+=4),f&&(E+=4);let k=u+a;for(let a=0;a<S;a++){if(g?(v=ft(r,E),E+=4):v=d,p?(y=ft(r,E),E+=4):y=m,w&&(E+=4),b&&(T=0===o?ft(r,E):mt(r,E),E+=4),s.type===A){let s=0;for(;s<y;){const r=ft(e,k);k+=4,Et(h,e[k])&&kt(e.subarray(k,k+r),h?2:1,t+T/n,i),k+=r,s+=r+4}}t+=v/n}})))}))}))})),i}function Et(t,s){if(t){const t=s>>1&63;return 39===t||40===t}return 6==(31&s)}function kt(t,s,i,e){const n=$t(t);let r=0;r+=s;let h=0,o=0,a=!1,l=0;for(;r<n.length;){h=0;do{if(r>=n.length)break;l=n[r++],h+=l}while(255===l);o=0;do{if(r>=n.length)break;l=n[r++],o+=l}while(255===l);const t=n.length-r;if(!a&&4===h&&r<n.length){if(a=!0,181===n[r++]){const t=dt(n,r);if(r+=2,49===t){const t=ft(n,r);if(r+=4,1195456820===t){const t=n[r++];if(3===t){const s=n[r++],o=64&s,a=o?2+3*(31&s):0,l=new Uint8Array(a);if(o){l[0]=s;for(let t=1;t<a;t++)l[t]=n[r++]}e.push({type:t,payloadType:h,pts:i,bytes:l})}}}}}else if(5===h&&o<t){if(a=!0,o>16){const t=[];for(let s=0;s<16;s++){const i=n[r++].toString(16);t.push(1==i.length?"0"+i:i),3!==s&&5!==s&&7!==s&&9!==s||t.push("-")}const s=o-16,a=new Uint8Array(s);for(let t=0;t<s;t++)a[t]=n[r++];e.push({payloadType:h,pts:i,uuid:t.join(""),userData:nt(a),userDataBytes:a})}}else if(o<t)r+=o;else if(o>t)break}}function $t(t){const s=t.byteLength,i=[];let e=1;for(;e<s-2;)0===t[e]&&0===t[e+1]&&3===t[e+2]?(i.push(e+2),e+=2):e++;if(0===i.length)return t;const n=s-i.length,r=new Uint8Array(n);let h=0;for(e=0;e<n;h++,e++)h===i[0]&&(h++,i.shift()),r[e]=t[h];return r}let At={};class Lt{static clearKeyUriToKeyIdMap(){At={}}constructor(t,s,i,e=[1],n=null){this.uri=void 0,this.method=void 0,this.keyFormat=void 0,this.keyFormatVersions=void 0,this.encrypted=void 0,this.isCommonEncryption=void 0,this.iv=null,this.key=null,this.keyId=null,this.pssh=null,this.method=t,this.uri=s,this.keyFormat=i,this.keyFormatVersions=e,this.iv=n,this.encrypted=!!t&&"NONE"!==t,this.isCommonEncryption=this.encrypted&&"AES-128"!==t}isSupported(){if(this.method){if("AES-128"===this.method||"NONE"===this.method)return!0;if("identity"===this.keyFormat)return"SAMPLE-AES"===this.method;switch(this.keyFormat){case N:case F:case U:case O:return-1!==["ISO-23001-7","SAMPLE-AES","SAMPLE-AES-CENC","SAMPLE-AES-CTR"].indexOf(this.method)}}return!1}getDecryptData(t){if(!this.encrypted||!this.uri)return null;if("AES-128"===this.method&&this.uri&&!this.iv){"number"!=typeof t&&("AES-128"!==this.method||this.iv||y.warn(`missing IV for initialization segment with method="${this.method}" - compliance issue`),t=0);const s=function(t){const s=new Uint8Array(16);for(let i=12;i<16;i++)s[i]=t>>8*(15-i)&255;return s}(t);return new Lt(this.method,this.uri,"identity",this.keyFormatVersions,s)}const s=function(t){const s=t.split(":");let i=null;if("data"===s[0]&&2===s.length){const t=s[1].split(";"),e=t[t.length-1].split(",");if(2===e.length){const s=e[1];"base64"===e[0]?(t.splice(-1,1),i=C(s)):i=function(t){const s=P(t).subarray(0,16),i=new Uint8Array(16);return i.set(s,16-s.length),i}(s)}}return i}(this.uri);if(s)switch(this.keyFormat){case F:this.pssh=s,s.length>=22&&(this.keyId=s.subarray(s.length-22,s.length-6));break;case U:{const t=new Uint8Array([154,4,240,121,152,64,66,134,171,146,230,91,224,136,95,149]);this.pssh=function(t,s,i){if(16!==t.byteLength)throw new RangeError("Invalid system id");let e,n,r;if(s){e=1,n=new Uint8Array(16*s.length);for(let t=0;t<s.length;t++){const i=s[t];if(16!==i.byteLength)throw new RangeError("Invalid key");n.set(i,16*t)}}else e=0,n=new Uint8Array;e>0?(r=new Uint8Array(4),s.length>0&&new DataView(r.buffer).setUint32(0,s.length,!1)):r=new Uint8Array;const h=new Uint8Array(4);return i&&i.byteLength>0&&new DataView(h.buffer).setUint32(0,i.byteLength,!1),function(t,...s){const i=s.length;let e=8,n=i;for(;n--;)e+=s[n].byteLength;const r=new Uint8Array(e);for(r[0]=e>>24&255,r[1]=e>>16&255,r[2]=e>>8&255,r[3]=255&e,r.set(t,4),n=0,e=8;n<i;n++)r.set(s[n],e),e+=s[n].byteLength;return r}([112,115,115,104],new Uint8Array([e,0,0,0]),t,r,n,h,i||new Uint8Array)}(t,null,s);const i=new Uint16Array(s.buffer,s.byteOffset,s.byteLength/2),e=String.fromCharCode.apply(null,Array.from(i)),n=e.substring(e.indexOf("<"),e.length),r=(new DOMParser).parseFromString(n,"text/xml").getElementsByTagName("KID")[0];if(r){const t=r.childNodes[0]?r.childNodes[0].nodeValue:r.getAttribute("VALUE");if(t){const s=C(t).subarray(0,16);!function(t){const s=function(t,s,i){const e=t[s];t[s]=t[i],t[i]=e};s(t,0,3),s(t,1,2),s(t,4,5),s(t,6,7)}(s),this.keyId=s}}break}default:{let t=s.subarray(0,16);if(16!==t.length){const s=new Uint8Array(16);s.set(t,16-t.length),t=s}this.keyId=t;break}}if(!this.keyId||16!==this.keyId.byteLength){let t=At[this.uri];if(!t){const s=Object.keys(At).length%Number.MAX_SAFE_INTEGER;t=new Uint8Array(16),new DataView(t.buffer,12,4).setUint32(0,s),At[this.uri]=t}this.keyId=t}return this}}const Mt=/\{\$([a-zA-Z0-9-_]+)\}/g;function Dt(t){return Mt.test(t)}function xt(t,s,i){if(null!==t.variableList||t.hasVariableRefs)for(let e=i.length;e--;){const n=i[e],r=s[n];r&&(s[n]=It(t,r))}}function It(t,s){if(null!==t.variableList||t.hasVariableRefs){const i=t.variableList;return s.replace(Mt,(s=>{const e=s.substring(2,s.length-1),n=null==i?void 0:i[e];return void 0===n?(t.playlistParsingError||(t.playlistParsingError=new Error(`Missing preceding EXT-X-DEFINE tag for Variable Reference: "${e}"`)),s):n}))}return s}function Ct(t,s,i){let e,n,r=t.variableList;if(r||(t.variableList=r={}),"QUERYPARAM"in s){e=s.QUERYPARAM;try{const t=new self.URL(i).searchParams;if(!t.has(e))throw new Error(`"${e}" does not match any query parameter in URI: "${i}"`);n=t.get(e)}catch(s){t.playlistParsingError||(t.playlistParsingError=new Error(`EXT-X-DEFINE QUERYPARAM: ${s.message}`))}}else e=s.NAME,n=s.VALUE;e in r?t.playlistParsingError||(t.playlistParsingError=new Error(`EXT-X-DEFINE duplicate Variable Name declarations: "${e}"`)):r[e]=n||""}function Pt(t,s,i){const e=s.IMPORT;if(i&&e in i){let s=t.variableList;s||(t.variableList=s={}),s[e]=i[e]}else t.playlistParsingError||(t.playlistParsingError=new Error(`EXT-X-DEFINE IMPORT attribute not found in Multivariant Playlist: "${e}"`))}function Rt(){if("undefined"!=typeof self)return self.MediaSource||self.WebKitMediaSource}const Ot={audio:{a3ds:!0,"ac-3":!0,"ac-4":!0,alac:!0,alaw:!0,dra1:!0,"dts+":!0,"dts-":!0,dtsc:!0,dtse:!0,dtsh:!0,"ec-3":!0,enca:!0,g719:!0,g726:!0,m4ae:!0,mha1:!0,mha2:!0,mhm1:!0,mhm2:!0,mlpa:!0,mp4a:!0,"raw ":!0,Opus:!0,opus:!0,samr:!0,sawb:!0,sawp:!0,sevc:!0,sqcp:!0,ssmv:!0,twos:!0,ulaw:!0},video:{avc1:!0,avc2:!0,avc3:!0,avc4:!0,avcp:!0,av01:!0,drac:!0,dva1:!0,dvav:!0,dvh1:!0,dvhe:!0,encv:!0,hev1:!0,hvc1:!0,mjp2:!0,mp4v:!0,mvc1:!0,mvc2:!0,mvc3:!0,mvc4:!0,resv:!0,rv60:!0,s263:!0,svc1:!0,svc2:!0,"vc-1":!0,vp08:!0,vp09:!0},text:{stpp:!0,wvtt:!0}},Nt=Rt();function Ut(t,s){var i;return null!=(i=null==Nt?void 0:Nt.isTypeSupported(`${s||"video"}/mp4;codecs="${t}"`))&&i}const Ft=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-(SESSION-DATA|SESSION-KEY|DEFINE|CONTENT-STEERING|START):([^\r\n]*)[\r\n]+/g,Bt=/#EXT-X-MEDIA:(.*)/g,_t=/^#EXT(?:INF|-X-TARGETDURATION):/m,jt=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[\S ]*)/.source,/#EXT-X-BYTERANGE:*(.+)/.source,/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/#.*/.source].join("|"),"g"),Kt=new RegExp([/#(EXTM3U)/.source,/#EXT-X-(DATERANGE|DEFINE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|"));class Ht{static findGroup(t,s){for(let i=0;i<t.length;i++){const e=t[i];if(e.id===s)return e}}static convertAVC1ToAVCOTI(t){const s=t.split(".");if(s.length>2){let t=s.shift()+".";return t+=parseInt(s.shift()).toString(16),t+=("000"+parseInt(s.shift()).toString(16)).slice(-4),t}return t}static resolve(t,s){return h.buildAbsoluteURL(s,t,{alwaysNormalize:!0})}static isMediaPlaylist(t){return _t.test(t)}static parseMasterPlaylist(t,s){const i={contentSteering:null,levels:[],playlistParsingError:null,sessionData:null,sessionKeys:null,startTimeOffset:null,variableList:null,hasVariableRefs:Dt(t)},e=[];let n;for(Ft.lastIndex=0;null!=(n=Ft.exec(t));)if(n[1]){var r;const t=new T(n[1]);xt(i,t,["CODECS","SUPPLEMENTAL-CODECS","ALLOWED-CPC","PATHWAY-ID","STABLE-VARIANT-ID","AUDIO","VIDEO","SUBTITLES","CLOSED-CAPTIONS","NAME"]);const h=It(i,n[2]),o={attrs:t,bitrate:t.decimalInteger("AVERAGE-BANDWIDTH")||t.decimalInteger("BANDWIDTH"),name:t.NAME,url:Ht.resolve(h,s)},a=t.decimalResolution("RESOLUTION");a&&(o.width=a.width,o.height=a.height),Wt((t.CODECS||"").split(/[ ,]+/).filter((t=>t)),o),o.videoCodec&&-1!==o.videoCodec.indexOf("avc1")&&(o.videoCodec=Ht.convertAVC1ToAVCOTI(o.videoCodec)),null!=(r=o.unknownCodecs)&&r.length||e.push(o),i.levels.push(o)}else if(n[3]){const t=n[4];switch(n[3]){case"SESSION-DATA":{const s=new T(t);xt(i,s,["DATA-ID","LANGUAGE","VALUE","URI"]);const e=s["DATA-ID"];e&&(null===i.sessionData&&(i.sessionData={}),i.sessionData[e]=s);break}case"SESSION-KEY":{const e=Gt(t,s,i);e.encrypted&&e.isSupported()?(null===i.sessionKeys&&(i.sessionKeys=[]),i.sessionKeys.push(e)):y.warn(`[Keys] Ignoring invalid EXT-X-SESSION-KEY tag: "${t}"`);break}case"DEFINE":{const e=new T(t);xt(i,e,["NAME","VALUE","QUERYPARAM"]),Ct(i,e,s)}break;case"CONTENT-STEERING":{const e=new T(t);xt(i,e,["SERVER-URI","PATHWAY-ID"]),i.contentSteering={uri:Ht.resolve(e["SERVER-URI"],s),pathwayId:e["PATHWAY-ID"]||"."};break}case"START":i.startTimeOffset=Vt(t)}}return i.levels=e.length>0&&e.length<i.levels.length?e:i.levels,0===i.levels.length&&(i.playlistParsingError=new Error("no levels found in manifest")),i}static parseMasterPlaylistMedia(t,s,i){let e;const n={},r=i.levels,h={AUDIO:r.map((t=>({id:t.attrs.AUDIO,audioCodec:t.audioCodec}))),SUBTITLES:r.map((t=>({id:t.attrs.SUBTITLES,textCodec:t.textCodec}))),"CLOSED-CAPTIONS":[]};let o=0;for(Bt.lastIndex=0;null!==(e=Bt.exec(t));){const t=new T(e[1]),r=t.TYPE;if(r){const e=h[r],a=n[r]||[];n[r]=a,xt(i,t,["URI","GROUP-ID","LANGUAGE","ASSOC-LANGUAGE","STABLE-RENDITION-ID","NAME","INSTREAM-ID","CHARACTERISTICS","CHANNELS"]);const l={attrs:t,bitrate:0,id:o++,groupId:t["GROUP-ID"]||"",instreamId:t["INSTREAM-ID"],name:t.NAME||t.LANGUAGE||"",type:r,default:t.bool("DEFAULT"),autoselect:t.bool("AUTOSELECT"),forced:t.bool("FORCED"),lang:t.LANGUAGE,url:t.URI?Ht.resolve(t.URI,s):""};if(null!=e&&e.length){const t=Ht.findGroup(e,l.groupId)||e[0];Xt(l,t,"audioCodec"),Xt(l,t,"textCodec")}a.push(l)}}return n}static parseLevelPlaylist(t,s,i,e,n,r){const h=new I(s),o=h.fragments;let a,l,d,f=null,m=0,g=0,v=0,p=0,w=null,b=new D(e,s),S=-1,k=!1;for(jt.lastIndex=0,h.m3u8=t,h.hasVariableRefs=Dt(t);null!==(a=jt.exec(t));){k&&(k=!1,b=new D(e,s),b.start=v,b.sn=m,b.cc=p,b.level=i,f&&(b.initSegment=f,b.rawProgramDateTime=f.rawProgramDateTime,f.rawProgramDateTime=null));const t=a[1];if(t){b.duration=parseFloat(t);const s=(" "+a[2]).slice(1);b.title=s||null,b.tagList.push(s?["INF",t,s]:["INF",t])}else if(a[3]){if(u(b.duration)){b.start=v,d&&zt(b,d,h),b.sn=m,b.level=i,b.cc=p,b.urlId=n,o.push(b);const t=(" "+a[3]).slice(1);b.relurl=It(h,t),qt(b,w),w=b,v+=b.duration,m++,g=0,k=!0}}else if(a[4]){const t=(" "+a[4]).slice(1);w?b.setByteRange(t,w):b.setByteRange(t)}else if(a[5])b.rawProgramDateTime=(" "+a[5]).slice(1),b.tagList.push(["PROGRAM-DATE-TIME",b.rawProgramDateTime]),-1===S&&(S=o.length);else{if(a=a[0].match(Kt),!a){y.warn("No matches on slow regex match for level playlist!");continue}for(l=1;l<a.length&&void 0===a[l];l++);const t=(" "+a[l]).slice(1),n=(" "+a[l+1]).slice(1),v=a[l+2]?(" "+a[l+2]).slice(1):"";switch(t){case"PLAYLIST-TYPE":h.type=n.toUpperCase();break;case"MEDIA-SEQUENCE":m=h.startSN=parseInt(n);break;case"SKIP":{const t=new T(n);xt(h,t,["RECENTLY-REMOVED-DATERANGES"]);const s=t.decimalInteger("SKIPPED-SEGMENTS");if(u(s)){h.skippedSegments=s;for(let t=s;t--;)o.unshift(null);m+=s}const i=t.enumeratedString("RECENTLY-REMOVED-DATERANGES");i&&(h.recentlyRemovedDateranges=i.split("\t"));break}case"TARGETDURATION":h.targetduration=Math.max(parseInt(n),1);break;case"VERSION":h.version=parseInt(n);break;case"EXTM3U":break;case"ENDLIST":h.live=!1;break;case"#":(n||v)&&b.tagList.push(v?[n,v]:[n]);break;case"DISCONTINUITY":p++,b.tagList.push(["DIS"]);break;case"GAP":b.gap=!0,b.tagList.push([t]);break;case"BITRATE":b.tagList.push([t,n]);break;case"DATERANGE":{const t=new T(n);xt(h,t,["ID","CLASS","START-DATE","END-DATE","SCTE35-CMD","SCTE35-OUT","SCTE35-IN"]),xt(h,t,t.clientAttrs);const s=new E(t,h.dateRanges[t.ID]);s.isValid||h.skippedSegments?h.dateRanges[s.id]=s:y.warn(`Ignoring invalid DATERANGE tag: "${n}"`),b.tagList.push(["EXT-X-DATERANGE",n]);break}case"DEFINE":{const t=new T(n);xt(h,t,["NAME","VALUE","IMPORT","QUERYPARAM"]),"IMPORT"in t?Pt(h,t,r):Ct(h,t,s)}break;case"DISCONTINUITY-SEQUENCE":p=parseInt(n);break;case"KEY":{const t=Gt(n,s,h);if(t.isSupported()){if("NONE"===t.method){d=void 0;break}d||(d={}),d[t.keyFormat]&&(d=c({},d)),d[t.keyFormat]=t}else y.warn(`[Keys] Ignoring invalid EXT-X-KEY tag: "${n}"`);break}case"START":h.startTimeOffset=Vt(n);break;case"MAP":{const t=new T(n);if(xt(h,t,["BYTERANGE","URI"]),b.duration){const n=new D(e,s);Yt(n,t,i,d),f=n,b.initSegment=f,f.rawProgramDateTime&&!b.rawProgramDateTime&&(b.rawProgramDateTime=f.rawProgramDateTime)}else Yt(b,t,i,d),f=b,k=!0;break}case"SERVER-CONTROL":{const t=new T(n);h.canBlockReload=t.bool("CAN-BLOCK-RELOAD"),h.canSkipUntil=t.optionalFloat("CAN-SKIP-UNTIL",0),h.canSkipDateRanges=h.canSkipUntil>0&&t.bool("CAN-SKIP-DATERANGES"),h.partHoldBack=t.optionalFloat("PART-HOLD-BACK",0),h.holdBack=t.optionalFloat("HOLD-BACK",0);break}case"PART-INF":{const t=new T(n);h.partTarget=t.decimalFloatingPoint("PART-TARGET");break}case"PART":{let t=h.partList;t||(t=h.partList=[]);const i=g>0?t[t.length-1]:void 0,e=g++,r=new T(n);xt(h,r,["BYTERANGE","URI"]);const o=new x(r,b,s,e,i);t.push(o),b.duration+=o.duration;break}case"PRELOAD-HINT":{const t=new T(n);xt(h,t,["URI"]),h.preloadHint=t;break}case"RENDITION-REPORT":{const t=new T(n);xt(h,t,["URI"]),h.renditionReports=h.renditionReports||[],h.renditionReports.push(t);break}default:y.warn(`line parsed but not handled: ${a}`)}}}w&&!w.relurl?(o.pop(),v-=w.duration,h.partList&&(h.fragmentHint=w)):h.partList&&(qt(b,w),b.cc=p,h.fragmentHint=b,d&&zt(b,d,h));const $=o.length,A=o[0],L=o[$-1];if(v+=h.skippedSegments*h.targetduration,v>0&&$&&L){h.averagetargetduration=v/$;const t=L.sn;h.endSN="initSegment"!==t?t:0,h.live||(L.endList=!0),A&&(h.startCC=A.cc)}else h.endSN=0,h.startCC=0;return h.fragmentHint&&(v+=h.fragmentHint.duration),h.totalduration=v,h.endCC=p,S>0&&function(t,s){let i=t[s];for(let e=s;e--;){const s=t[e];if(!s)return;s.programDateTime=i.programDateTime-1e3*s.duration,i=s}}(o,S),h}}function Gt(t,s,i){var e,n;const r=new T(t);xt(i,r,["KEYFORMAT","KEYFORMATVERSIONS","URI","IV","URI"]);const h=null!=(e=r.METHOD)?e:"",o=r.URI,a=r.hexadecimalInteger("IV"),l=r.KEYFORMATVERSIONS,c=null!=(n=r.KEYFORMAT)?n:"identity";o&&r.IV&&!a&&y.error(`Invalid IV: ${r.IV}`);const u=o?Ht.resolve(o,s):"",d=(l||"1").split("/").map(Number).filter(Number.isFinite);return new Lt(h,u,c,d,a)}function Vt(t){const s=new T(t).decimalFloatingPoint("TIME-OFFSET");return u(s)?s:null}function Wt(t,s){["video","audio","text"].forEach((i=>{const e=t.filter((t=>function(t,s){const i=Ot[s];return!!i&&!0===i[t.slice(0,4)]}(t,i)));if(e.length){const n=e.filter((t=>0===t.lastIndexOf("avc1",0)||0===t.lastIndexOf("mp4a",0)));s[`${i}Codec`]=n.length>0?n[0]:e[0],t=t.filter((t=>-1===e.indexOf(t)))}})),s.unknownCodecs=t}function Xt(t,s,i){const e=s[i];e&&(t[i]=e)}function qt(t,s){t.rawProgramDateTime?t.programDateTime=Date.parse(t.rawProgramDateTime):null!=s&&s.programDateTime&&(t.programDateTime=s.endProgramDateTime),u(t.programDateTime)||(t.programDateTime=null,t.rawProgramDateTime=null)}function Yt(t,s,i,e){t.relurl=s.URI,s.BYTERANGE&&t.setByteRange(s.BYTERANGE),t.level=i,t.sn="initSegment",e&&(t.levelkeys=e),t.initSegment=null}function zt(t,s,i){t.levelkeys=s;const{encryptedFragments:e}=i;e.length&&e[e.length-1].levelkeys===s||!Object.keys(s).some((t=>s[t].isCommonEncryption))||e.push(t)}var Qt="manifest",Jt="level",Zt="audioTrack",ts="subtitleTrack",ss="main",is="audio",es="subtitle";function ns(t){const{type:s}=t;switch(s){case Zt:return is;case ts:return es;default:return ss}}function rs(t,s){let i=t.url;return void 0!==i&&0!==i.indexOf("data:")||(i=s.url),i}class hs{constructor(t){this.hls=void 0,this.loaders=Object.create(null),this.variableList=null,this.hls=t,this.registerListeners()}startLoad(t){}stopLoad(){this.destroyInternalLoaders()}registerListeners(){const{hls:t}=this;t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.LEVEL_LOADING,this.onLevelLoading,this),t.on(d.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),t.on(d.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)}unregisterListeners(){const{hls:t}=this;t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.LEVEL_LOADING,this.onLevelLoading,this),t.off(d.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),t.off(d.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)}createInternalLoader(t){const s=this.hls.config,i=new(s.pLoader||s.loader)(s);return this.loaders[t.type]=i,i}getInternalLoader(t){return this.loaders[t.type]}resetInternalLoader(t){this.loaders[t]&&delete this.loaders[t]}destroyInternalLoaders(){for(const t in this.loaders){const s=this.loaders[t];s&&s.destroy(),this.resetInternalLoader(t)}}destroy(){this.variableList=null,this.unregisterListeners(),this.destroyInternalLoaders()}onManifestLoading(t,s){const{url:i}=s;this.variableList=null,this.load({id:null,level:0,responseType:"text",type:Qt,url:i,deliveryDirectives:null})}onLevelLoading(t,s){const{id:i,level:e,url:n,deliveryDirectives:r}=s;this.load({id:i,level:e,responseType:"text",type:Jt,url:n,deliveryDirectives:r})}onAudioTrackLoading(t,s){const{id:i,groupId:e,url:n,deliveryDirectives:r}=s;this.load({id:i,groupId:e,level:null,responseType:"text",type:Zt,url:n,deliveryDirectives:r})}onSubtitleTrackLoading(t,s){const{id:i,groupId:e,url:n,deliveryDirectives:r}=s;this.load({id:i,groupId:e,level:null,responseType:"text",type:ts,url:n,deliveryDirectives:r})}load(t){var s;const i=this.hls.config;let e,n=this.getInternalLoader(t);if(n){const s=n.context;if(s&&s.url===t.url)return void y.trace("[playlist-loader]: playlist request ongoing");y.log(`[playlist-loader]: aborting previous loader for type: ${t.type}`),n.abort()}if(e=t.type===Qt?i.manifestLoadPolicy.default:c({},i.playlistLoadPolicy.default,{timeoutRetry:null,errorRetry:null}),n=this.createInternalLoader(t),null!=(s=t.deliveryDirectives)&&s.part){let s;if(t.type===Jt&&null!==t.level?s=this.hls.levels[t.level].details:t.type===Zt&&null!==t.id?s=this.hls.audioTracks[t.id].details:t.type===ts&&null!==t.id&&(s=this.hls.subtitleTracks[t.id].details),s){const t=s.partTarget,i=s.targetduration;if(t&&i){const s=1e3*Math.max(3*t,.8*i);e=c({},e,{maxTimeToFirstByteMs:Math.min(s,e.maxTimeToFirstByteMs),maxLoadTimeMs:Math.min(s,e.maxTimeToFirstByteMs)})}}}const r=e.errorRetry||e.timeoutRetry||{},h={onSuccess:(t,s,i,e)=>{const n=this.getInternalLoader(i);this.resetInternalLoader(i.type);const r=t.data;0===r.indexOf("#EXTM3U")?(s.parsing.start=performance.now(),Ht.isMediaPlaylist(r)?this.handleTrackOrLevelPlaylist(t,s,i,e||null,n):this.handleMasterPlaylist(t,s,i,e)):this.handleManifestParsingError(t,i,new Error("no EXTM3U delimiter"),e||null,s)},onError:(t,s,i,e)=>{this.handleNetworkError(s,i,!1,t,e)},onTimeout:(t,s,i)=>{this.handleNetworkError(s,i,!0,void 0,t)}};n.load(t,{loadPolicy:e,timeout:e.maxLoadTimeMs,maxRetry:r.maxNumRetry||0,retryDelay:r.retryDelayMs||0,maxRetryDelay:r.maxRetryDelayMs||0},h)}handleMasterPlaylist(t,s,i,e){const n=this.hls,r=t.data,h=rs(t,i),o=Ht.parseMasterPlaylist(r,h);if(o.playlistParsingError)return void this.handleManifestParsingError(t,i,o.playlistParsingError,e,s);const{contentSteering:a,levels:l,sessionData:c,sessionKeys:u,startTimeOffset:f,variableList:m}=o;this.variableList=m;const{AUDIO:g=[],SUBTITLES:v,"CLOSED-CAPTIONS":p}=Ht.parseMasterPlaylistMedia(r,h,o);g.length&&(g.some((t=>!t.url))||!l[0].audioCodec||l[0].attrs.AUDIO||(y.log("[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one"),g.unshift({type:"main",name:"main",groupId:"main",default:!1,autoselect:!1,forced:!1,id:-1,attrs:new T({}),bitrate:0,url:""}))),n.trigger(d.MANIFEST_LOADED,{levels:l,audioTracks:g,subtitles:v,captions:p,contentSteering:a,url:h,stats:s,networkDetails:e,sessionData:c,sessionKeys:u,startTimeOffset:f,variableList:m})}handleTrackOrLevelPlaylist(t,s,i,e,n){const r=this.hls,{id:h,level:o,type:a}=i,l=rs(t,i),c=u(h)?h:0,f=u(o)?o:c,m=ns(i),g=Ht.parseLevelPlaylist(t.data,l,f,m,c,this.variableList);if(a===Qt){const t={attrs:new T({}),bitrate:0,details:g,name:"",url:l};r.trigger(d.MANIFEST_LOADED,{levels:[t],audioTracks:[],url:l,stats:s,networkDetails:e,sessionData:null,sessionKeys:null,contentSteering:null,startTimeOffset:null,variableList:null})}s.parsing.end=performance.now(),i.levelDetails=g,this.handlePlaylistLoaded(g,t,s,i,e,n)}handleManifestParsingError(t,s,i,e,n){this.hls.trigger(d.ERROR,{type:f.NETWORK_ERROR,details:m.MANIFEST_PARSING_ERROR,fatal:s.type===Qt,url:t.url,err:i,error:i,reason:i.message,response:t,context:s,networkDetails:e,stats:n})}handleNetworkError(t,s,i=!1,e,n){let r=`A network ${i?"timeout":"error"+(e?" (status "+e.code+")":"")} occurred while loading ${t.type}`;t.type===Jt?r+=`: ${t.level} id: ${t.id}`:t.type!==Zt&&t.type!==ts||(r+=` id: ${t.id} group-id: "${t.groupId}"`);const h=new Error(r);y.warn(`[playlist-loader]: ${r}`);let o=m.UNKNOWN,l=!1;const c=this.getInternalLoader(t);switch(t.type){case Qt:o=i?m.MANIFEST_LOAD_TIMEOUT:m.MANIFEST_LOAD_ERROR,l=!0;break;case Jt:o=i?m.LEVEL_LOAD_TIMEOUT:m.LEVEL_LOAD_ERROR,l=!1;break;case Zt:o=i?m.AUDIO_TRACK_LOAD_TIMEOUT:m.AUDIO_TRACK_LOAD_ERROR,l=!1;break;case ts:o=i?m.SUBTITLE_TRACK_LOAD_TIMEOUT:m.SUBTITLE_LOAD_ERROR,l=!1}c&&this.resetInternalLoader(t.type);const u={type:f.NETWORK_ERROR,details:o,fatal:l,url:t.url,loader:c,context:t,error:h,networkDetails:s,stats:n};e&&(u.response=a({url:(null==s?void 0:s.url)||t.url,data:void 0},e)),this.hls.trigger(d.ERROR,u)}handlePlaylistLoaded(t,s,i,e,n,r){const h=this.hls,{type:o,level:a,id:l,groupId:c,deliveryDirectives:u}=e,g=rs(s,e),v=ns(e),p="number"==typeof e.level&&v===ss?a:void 0;if(!t.fragments.length){const t=new Error("No Segments found in Playlist");return void h.trigger(d.ERROR,{type:f.NETWORK_ERROR,details:m.LEVEL_EMPTY_ERROR,fatal:!1,url:g,error:t,reason:t.message,response:s,context:e,level:p,parent:v,networkDetails:n,stats:i})}t.targetduration||(t.playlistParsingError=new Error("Missing Target Duration"));const y=t.playlistParsingError;if(y)h.trigger(d.ERROR,{type:f.NETWORK_ERROR,details:m.LEVEL_PARSING_ERROR,fatal:!1,url:g,error:y,reason:y.message,response:s,context:e,level:p,parent:v,networkDetails:n,stats:i});else switch(t.live&&r&&(r.getCacheAge&&(t.ageHeader=r.getCacheAge()||0),r.getCacheAge&&!isNaN(t.ageHeader)||(t.ageHeader=0)),o){case Qt:case Jt:h.trigger(d.LEVEL_LOADED,{details:t,level:p||0,id:l||0,stats:i,networkDetails:n,deliveryDirectives:u});break;case Zt:h.trigger(d.AUDIO_TRACK_LOADED,{details:t,id:l||0,groupId:c||"",stats:i,networkDetails:n,deliveryDirectives:u});break;case ts:h.trigger(d.SUBTITLE_TRACK_LOADED,{details:t,id:l||0,groupId:c||"",stats:i,networkDetails:n,deliveryDirectives:u})}}}function os(t,s){let i;try{i=new Event("addtrack")}catch(t){i=document.createEvent("Event"),i.initEvent("addtrack",!1,!1)}i.track=t,s.dispatchEvent(i)}function as(t,s){const i=t.mode;if("disabled"===i&&(t.mode="hidden"),t.cues&&!t.cues.getCueById(s.id))try{if(t.addCue(s),!t.cues.getCueById(s.id))throw new Error(`addCue is failed for: ${s}`)}catch(i){y.debug(`[texttrack-utils]: ${i}`);const e=new self.TextTrackCue(s.startTime,s.endTime,s.text);e.id=s.id,t.addCue(e)}"disabled"===i&&(t.mode=i)}function ls(t){const s=t.mode;if("disabled"===s&&(t.mode="hidden"),t.cues)for(let s=t.cues.length;s--;)t.removeCue(t.cues[s]);"disabled"===s&&(t.mode=s)}function cs(t,s,i,e){const n=t.mode;if("disabled"===n&&(t.mode="hidden"),t.cues&&t.cues.length>0){const n=function(t,s,i){const e=[],n=function(t,s){if(s<t[0].startTime)return 0;const i=t.length-1;if(s>t[i].endTime)return-1;let e=0,n=i;for(;e<=n;){const r=Math.floor((n+e)/2);if(s<t[r].startTime)n=r-1;else{if(!(s>t[r].startTime&&e<i))return r;e=r+1}}return t[e].startTime-s<s-t[n].startTime?e:n}(t,s);if(n>-1)for(let r=n,h=t.length;r<h;r++){const n=t[r];if(n.startTime>=s&&n.endTime<=i)e.push(n);else if(n.startTime>i)return e}return e}(t.cues,s,i);for(let s=0;s<n.length;s++)e&&!e(n[s])||t.removeCue(n[s])}"disabled"===n&&(t.mode=n)}var us="org.id3",ds="https://aomedia.org/emsg/ID3";function fs(){if("undefined"!=typeof self)return self.WebKitDataCue||self.VTTCue||self.TextTrackCue}const ms=(()=>{const t=fs();try{new t(0,Number.POSITIVE_INFINITY,"")}catch(t){return Number.MAX_VALUE}return Number.POSITIVE_INFINITY})();function gs(t,s){return t.getTime()/1e3-s}class vs{constructor(t){this.hls=void 0,this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=t,this._registerListeners()}destroy(){this._unregisterListeners(),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=null}_registerListeners(){const{hls:t}=this;t.on(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),t.on(d.BUFFER_FLUSHING,this.onBufferFlushing,this),t.on(d.LEVEL_UPDATED,this.onLevelUpdated,this)}_unregisterListeners(){const{hls:t}=this;t.off(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),t.off(d.BUFFER_FLUSHING,this.onBufferFlushing,this),t.off(d.LEVEL_UPDATED,this.onLevelUpdated,this)}onMediaAttached(t,s){this.media=s.media}onMediaDetaching(){this.id3Track&&(ls(this.id3Track),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={})}onManifestLoading(){this.dateRangeCuesAppended={}}createTrack(t){const s=this.getID3Track(t.textTracks);return s.mode="hidden",s}getID3Track(t){if(this.media){for(let s=0;s<t.length;s++){const i=t[s];if("metadata"===i.kind&&"id3"===i.label)return os(i,this.media),i}return this.media.addTextTrack("metadata","id3")}}onFragParsingMetadata(t,s){if(!this.media)return;const{hls:{config:{enableEmsgMetadataCues:i,enableID3MetadataCues:e}}}=this;if(!i&&!e)return;const{samples:n}=s;this.id3Track||(this.id3Track=this.createTrack(this.media));const r=fs();for(let t=0;t<n.length;t++){const s=n[t].type;if(s===ds&&!i||!e)continue;const h=J(n[t].data);if(h){const i=n[t].pts;let e=i+n[t].duration;e>ms&&(e=ms),e-i<=0&&(e=i+.25);for(let t=0;t<h.length;t++){const n=h[t];if(!z(n)){this.updateId3CueEnds(i);const t=new r(i,e,"");t.value=n,s&&(t.type=s),this.id3Track.addCue(t)}}}}}updateId3CueEnds(t){var s;const i=null==(s=this.id3Track)?void 0:s.cues;if(i)for(let s=i.length;s--;){const e=i[s];e.startTime<t&&e.endTime===ms&&(e.endTime=t)}}onBufferFlushing(t,{startOffset:s,endOffset:i,type:e}){const{id3Track:n,hls:r}=this;if(!r)return;const{config:{enableEmsgMetadataCues:h,enableID3MetadataCues:o}}=r;if(n&&(h||o)){let t;t="audio"===e?t=>t.type===us&&o:"video"===e?t=>t.type===ds&&h:t=>t.type===us&&o||t.type===ds&&h,cs(n,s,i,t)}}onLevelUpdated(t,{details:s}){if(!this.media||!s.hasProgramDateTime||!this.hls.config.enableDateRangeMetadataCues)return;const{dateRangeCuesAppended:i,id3Track:e}=this,{dateRanges:n}=s,r=Object.keys(n);if(e){const t=Object.keys(i).filter((t=>!r.includes(t)));for(let s=t.length;s--;){const n=t[s];Object.keys(i[n].cues).forEach((t=>{e.removeCue(i[n].cues[t])})),delete i[n]}}const h=s.fragments[s.fragments.length-1];if(0===r.length||!u(null==h?void 0:h.programDateTime))return;this.id3Track||(this.id3Track=this.createTrack(this.media));const o=h.programDateTime/1e3-h.start,a=fs();for(let t=0;t<r.length;t++){const s=r[t],e=n[s],h=i[s],c=(null==h?void 0:h.cues)||{};let u=(null==h?void 0:h.durationKnown)||!1;const d=gs(e.startDate,o);let f=ms;const m=e.endDate;if(m)f=gs(m,o),u=!0;else if(e.endOnNext&&!u){const t=r.reduce(((t,s)=>{const i=n[s];return i.class===e.class&&i.id!==s&&i.startDate>e.startDate&&t.push(i),t}),[]).sort(((t,s)=>t.startDate.getTime()-s.startDate.getTime()))[0];t&&(f=gs(t.startDate,o),u=!0)}const g=Object.keys(e.attr);for(let t=0;t<g.length;t++){const i=g[t];if("ID"===(l=i)||"CLASS"===l||"START-DATE"===l||"DURATION"===l||"END-DATE"===l||"END-ON-NEXT"===l)continue;let n=c[i];if(n)u&&!h.durationKnown&&(n.endTime=f);else{let t=e.attr[i];n=new a(d,f,""),S(i)&&(t=Uint8Array.from(t.replace(/^0x/,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" ")).buffer),n.value={key:i,data:t},n.type="com.apple.quicktime.HLS",n.id=s,this.id3Track.addCue(n),c[i]=n}}i[s]={cues:c,dateRange:e,durationKnown:u}}var l}}class ps{constructor(t){this.hls=void 0,this.config=void 0,this.media=null,this.levelDetails=null,this.currentTime=0,this.stallCount=0,this._latency=null,this.timeupdateHandler=()=>this.timeupdate(),this.hls=t,this.config=t.config,this.registerListeners()}get latency(){return this._latency||0}get maxLatency(){const{config:t,levelDetails:s}=this;return void 0!==t.liveMaxLatencyDuration?t.liveMaxLatencyDuration:s?t.liveMaxLatencyDurationCount*s.targetduration:0}get targetLatency(){const{levelDetails:t}=this;if(null===t)return null;const{holdBack:s,partHoldBack:i,targetduration:e}=t,{liveSyncDuration:n,liveSyncDurationCount:r,lowLatencyMode:h}=this.config,o=this.hls.userConfig;let a=h&&i||s;return(o.liveSyncDuration||o.liveSyncDurationCount||0===a)&&(a=void 0!==n?n:r*e),a+Math.min(1*this.stallCount,e)}get liveSyncPosition(){const t=this.estimateLiveEdge(),s=this.targetLatency,i=this.levelDetails;if(null===t||null===s||null===i)return null;const e=i.edge,n=e-(this.config.lowLatencyMode&&i.partTarget||i.targetduration);return Math.min(Math.max(e-i.totalduration,t-s-this.edgeStalled),n)}get drift(){const{levelDetails:t}=this;return null===t?1:t.drift}get edgeStalled(){const{levelDetails:t}=this;return null===t?0:Math.max(t.age-3*(this.config.lowLatencyMode&&t.partTarget||t.targetduration),0)}get forwardBufferLength(){const{media:t,levelDetails:s}=this;if(!t||!s)return 0;const i=t.buffered.length;return(i?t.buffered.end(i-1):s.edge)-this.currentTime}destroy(){this.unregisterListeners(),this.onMediaDetaching(),this.levelDetails=null,this.hls=this.timeupdateHandler=null}registerListeners(){this.hls.on(d.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(d.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.on(d.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(d.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.on(d.ERROR,this.onError,this)}unregisterListeners(){this.hls.off(d.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(d.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.off(d.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.off(d.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.off(d.ERROR,this.onError,this)}onMediaAttached(t,s){this.media=s.media,this.media.addEventListener("timeupdate",this.timeupdateHandler)}onMediaDetaching(){this.media&&(this.media.removeEventListener("timeupdate",this.timeupdateHandler),this.media=null)}onManifestLoading(){this.levelDetails=null,this._latency=null,this.stallCount=0}onLevelUpdated(t,{details:s}){this.levelDetails=s,s.advanced&&this.timeupdate(),!s.live&&this.media&&this.media.removeEventListener("timeupdate",this.timeupdateHandler)}onError(t,s){var i;s.details===m.BUFFER_STALLED_ERROR&&(this.stallCount++,null!=(i=this.levelDetails)&&i.live&&y.warn("[playback-rate-controller]: Stall detected, adjusting target latency"))}timeupdate(){const{media:t,levelDetails:s}=this;if(!t||!s)return;this.currentTime=t.currentTime;const i=this.computeLatency();if(null===i)return;this._latency=i;const{lowLatencyMode:e,maxLiveSyncPlaybackRate:n}=this.config;if(!e||1===n)return;const r=this.targetLatency;if(null===r)return;const h=i-r,o=Math.min(this.maxLatency,r+s.targetduration);if(s.live&&h<o&&h>.05&&this.forwardBufferLength>1){const s=Math.min(2,Math.max(1,n)),i=Math.round(2/(1+Math.exp(-.75*h-this.edgeStalled))*20)/20;t.playbackRate=Math.min(s,Math.max(1,i))}else 1!==t.playbackRate&&0!==t.playbackRate&&(t.playbackRate=1)}estimateLiveEdge(){const{levelDetails:t}=this;return null===t?null:t.edge+t.age}computeLatency(){const t=this.estimateLiveEdge();return null===t?null:t-this.currentTime}}const ys=["NONE","TYPE-0","TYPE-1",null];class ws{constructor(t,s,i){this.msn=void 0,this.part=void 0,this.skip=void 0,this.msn=t,this.part=s,this.skip=i}addDirectives(t){const s=new self.URL(t);return void 0!==this.msn&&s.searchParams.set("_HLS_msn",this.msn.toString()),void 0!==this.part&&s.searchParams.set("_HLS_part",this.part.toString()),this.skip&&s.searchParams.set("_HLS_skip",this.skip),s.href}}class bs{constructor(t){this._attrs=void 0,this.audioCodec=void 0,this.bitrate=void 0,this.codecSet=void 0,this.height=void 0,this.id=void 0,this.name=void 0,this.videoCodec=void 0,this.width=void 0,this.unknownCodecs=void 0,this.audioGroupIds=void 0,this.details=void 0,this.fragmentError=0,this.loadError=0,this.loaded=void 0,this.realBitrate=0,this.textGroupIds=void 0,this.url=void 0,this._urlId=0,this.url=[t.url],this._attrs=[t.attrs],this.bitrate=t.bitrate,t.details&&(this.details=t.details),this.id=t.id||0,this.name=t.name,this.width=t.width||0,this.height=t.height||0,this.audioCodec=t.audioCodec,this.videoCodec=t.videoCodec,this.unknownCodecs=t.unknownCodecs,this.codecSet=[t.videoCodec,t.audioCodec].filter((t=>t)).join(",").replace(/\.[^.,]+/g,"")}get maxBitrate(){return Math.max(this.realBitrate,this.bitrate)}get attrs(){return this._attrs[this._urlId]}get pathwayId(){return this.attrs["PATHWAY-ID"]||"."}get uri(){return this.url[this._urlId]||""}get urlId(){return this._urlId}set urlId(t){const s=t%this.url.length;this._urlId!==s&&(this.fragmentError=0,this.loadError=0,this.details=void 0,this._urlId=s)}get audioGroupId(){var t;return null==(t=this.audioGroupIds)?void 0:t[this.urlId]}get textGroupId(){var t;return null==(t=this.textGroupIds)?void 0:t[this.urlId]}addFallback(t){this.url.push(t.url),this._attrs.push(t.attrs)}}function Ts(t,s){const i=s.startPTS;if(u(i)){let e,n=0;s.sn>t.sn?(n=i-t.start,e=t):(n=t.start-i,e=s),e.duration!==n&&(e.duration=n)}else s.start=s.sn>t.sn?t.cc===s.cc&&t.minEndPTS?t.start+(t.minEndPTS-t.start):t.start+t.duration:Math.max(t.start-s.duration,0)}function Ss(t,s,i,e,n,r){e-i<=0&&(y.warn("Fragment should have a positive duration",s),e=i+s.duration,r=n+s.duration);let h=i,o=e;const a=s.startPTS,l=s.endPTS;if(u(a)){const t=Math.abs(a-i);s.deltaPTS=u(s.deltaPTS)?Math.max(t,s.deltaPTS):t,h=Math.max(i,a),i=Math.min(i,a),n=Math.min(n,s.startDTS),o=Math.min(e,l),e=Math.max(e,l),r=Math.max(r,s.endDTS)}const c=i-s.start;0!==s.start&&(s.start=i),s.duration=e-s.start,s.startPTS=i,s.maxStartPTS=h,s.startDTS=n,s.endPTS=e,s.minEndPTS=o,s.endDTS=r;const d=s.sn;if(!t||d<t.startSN||d>t.endSN)return 0;let f;const m=d-t.startSN,g=t.fragments;for(g[m]=s,f=m;f>0;f--)Ts(g[f],g[f-1]);for(f=m;f<g.length-1;f++)Ts(g[f],g[f+1]);return t.fragmentHint&&Ts(g[g.length-1],t.fragmentHint),t.PTSKnown=t.alignedSliding=!0,c}function Es(t,s){const i=s.startSN+s.skippedSegments-t.startSN,e=t.fragments;i<0||i>=e.length||ks(s,e[i].start)}function ks(t,s){if(s){const i=t.fragments;for(let e=t.skippedSegments;e<i.length;e++)i[e].start+=s;t.fragmentHint&&(t.fragmentHint.start+=s)}}function $s(t,s,i){var e;return null!=t&&t.details?As(null==(e=t.details)?void 0:e.partList,s,i):null}function As(t,s,i){if(t)for(let e=t.length;e--;){const n=t[e];if(n.index===i&&n.fragment.sn===s)return n}return null}function Ls(t){switch(t.details){case m.FRAG_LOAD_TIMEOUT:case m.KEY_LOAD_TIMEOUT:case m.LEVEL_LOAD_TIMEOUT:case m.MANIFEST_LOAD_TIMEOUT:return!0}return!1}function Ms(t,s){const i=Ls(s);return t.default[(i?"timeout":"error")+"Retry"]}function Ds(t,s){const i="linear"===t.backoff?1:Math.pow(2,s);return Math.min(i*t.retryDelayMs,t.maxRetryDelayMs)}function xs(t){return a(a({},t),{errorRetry:null,timeoutRetry:null})}function Is(t,s,i,e){return!!t&&s<t.maxNumRetry&&(function(t){return 0===t&&!1===navigator.onLine||!!t&&(t<400||t>499)}(e)||!!i)}const Cs=function(t,s){let i=0,e=t.length-1,n=null,r=null;for(;i<=e;){n=(i+e)/2|0,r=t[n];const h=s(r);if(h>0)i=n+1;else{if(!(h<0))return r;e=n-1}}return null};function Ps(t,s,i=0,e=0){let n=null;if(t?n=s[t.sn-s[0].sn+1]||null:0===i&&0===s[0].start&&(n=s[0]),n&&0===Rs(i,e,n))return n;const r=Cs(s,Rs.bind(null,i,e));return!r||r===t&&n?n:r}function Rs(t=0,s=0,i){if(i.start<=t&&i.start+i.duration>t)return 0;const e=Math.min(s,i.duration+(i.deltaPTS?i.deltaPTS:0));return i.start+i.duration-e<=t?1:i.start-e>t&&i.start?-1:0}function Os(t,s,i){const e=1e3*Math.min(s,i.duration+(i.deltaPTS?i.deltaPTS:0));return(i.endProgramDateTime||0)-e>t}function Ns(t,s,i){if(performance.now()-t.lastErrorPerfMs>3e5)return!0;const e=t.details;if(s.details===m.FRAG_GAP&&e&&s.frag){const t=Ps(null,e.fragments,s.frag.start);if(t&&!t.gap)return!0}if(i&&t.errors.length<i.errors.length){const i=t.errors[t.errors.length-1];if(e&&i.frag&&s.frag&&Math.abs(i.frag.start-s.frag.start)>3*e.targetduration)return!0}return!1}class Us{constructor(t,s){this.hls=void 0,this.timer=-1,this.requestScheduled=-1,this.canLoad=!1,this.log=void 0,this.warn=void 0,this.log=y.log.bind(y,`${s}:`),this.warn=y.warn.bind(y,`${s}:`),this.hls=t}destroy(){this.clearTimer(),this.hls=this.log=this.warn=null}clearTimer(){clearTimeout(this.timer),this.timer=-1}startLoad(){this.canLoad=!0,this.requestScheduled=-1,this.loadPlaylist()}stopLoad(){this.canLoad=!1,this.clearTimer()}switchParams(t,s){const i=null==s?void 0:s.renditionReports;if(i){let e=-1;for(let n=0;n<i.length;n++){const r=i[n];let h;try{h=new self.URL(r.URI,s.url).href}catch(t){y.warn(`Could not construct new URL for Rendition Report: ${t}`),h=r.URI||""}if(h===t){e=n;break}h===t.substring(0,h.length)&&(e=n)}if(-1!==e){const t=i[e],n=parseInt(t["LAST-MSN"])||(null==s?void 0:s.lastPartSn);let r=parseInt(t["LAST-PART"])||(null==s?void 0:s.lastPartIndex);if(this.hls.config.lowLatencyMode){const t=Math.min(s.age-s.partTarget,s.targetduration);r>=0&&t>s.partTarget&&(r+=1)}return new ws(n,r>=0?r:void 0,"")}}}loadPlaylist(t){-1===this.requestScheduled&&(this.requestScheduled=self.performance.now())}shouldLoadPlaylist(t){return this.canLoad&&!!t&&!!t.url&&(!t.details||t.details.live)}shouldReloadPlaylist(t){return-1===this.timer&&-1===this.requestScheduled&&this.shouldLoadPlaylist(t)}playlistLoaded(t,s,i){const{details:e,stats:n}=s,r=self.performance.now(),h=n.loading.first?Math.max(0,r-n.loading.first):0;if(e.advancedDateTime=Date.now()-h,e.live||null!=i&&i.live){if(e.reloaded(i),i&&this.log(`live playlist ${t} ${e.advanced?"REFRESHED "+e.lastPartSn+"-"+e.lastPartIndex:"MISSED"}`),i&&e.fragments.length>0&&function(t,s){let i=null;const e=t.fragments;for(let t=e.length-1;t>=0;t--){const s=e[t].initSegment;if(s){i=s;break}}t.fragmentHint&&delete t.fragmentHint.endPTS;let n,r=0;if(function(t,s,i){const e=s.skippedSegments,n=Math.max(t.startSN,s.startSN)-s.startSN,r=(t.fragmentHint?1:0)+(e?s.endSN:Math.min(t.endSN,s.endSN))-s.startSN,h=s.startSN-t.startSN,o=s.fragmentHint?s.fragments.concat(s.fragmentHint):s.fragments,a=t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments;for(let t=n;t<=r;t++){const n=a[h+t];let r=o[t];e&&!r&&t<e&&(r=s.fragments[t]=n),n&&r&&i(n,r)}}(t,s,((t,e)=>{t.relurl&&(r=t.cc-e.cc),u(t.startPTS)&&u(t.endPTS)&&(e.start=e.startPTS=t.startPTS,e.startDTS=t.startDTS,e.maxStartPTS=t.maxStartPTS,e.endPTS=t.endPTS,e.endDTS=t.endDTS,e.minEndPTS=t.minEndPTS,e.duration=t.endPTS-t.startPTS,e.duration&&(n=e),s.PTSKnown=s.alignedSliding=!0),e.elementaryStreams=t.elementaryStreams,e.loader=t.loader,e.stats=t.stats,e.urlId=t.urlId,t.initSegment&&(e.initSegment=t.initSegment,i=t.initSegment)})),i&&(s.fragmentHint?s.fragments.concat(s.fragmentHint):s.fragments).forEach((t=>{var s;t.initSegment&&t.initSegment.relurl!==(null==(s=i)?void 0:s.relurl)||(t.initSegment=i)})),s.skippedSegments)if(s.deltaUpdateFailed=s.fragments.some((t=>!t)),s.deltaUpdateFailed){y.warn("[level-helper] Previous playlist missing segments skipped in delta playlist");for(let t=s.skippedSegments;t--;)s.fragments.shift();s.startSN=s.fragments[0].sn,s.startCC=s.fragments[0].cc}else s.canSkipDateRanges&&(s.dateRanges=function(t,s,i){const e=c({},t);return i&&i.forEach((t=>{delete e[t]})),Object.keys(s).forEach((t=>{const i=new E(s[t].attr,e[t]);i.isValid?e[t]=i:y.warn(`Ignoring invalid Playlist Delta Update DATERANGE tag: "${JSON.stringify(s[t].attr)}"`)})),e}(t.dateRanges,s.dateRanges,s.recentlyRemovedDateranges));const h=s.fragments;if(r){y.warn("discontinuity sliding from playlist, take drift into account");for(let t=0;t<h.length;t++)h[t].cc+=r}s.skippedSegments&&(s.startCC=s.fragments[0].cc),function(t,s,i){if(t&&s){let e=0;for(let n=0,r=t.length;n<=r;n++){const r=t[n],h=s[n+e];r&&h&&r.index===h.index&&r.fragment.sn===h.fragment.sn?i(r,h):e--}}}(t.partList,s.partList,((t,s)=>{s.elementaryStreams=t.elementaryStreams,s.stats=t.stats})),n?Ss(s,n,n.startPTS,n.endPTS,n.startDTS,n.endDTS):Es(t,s),h.length&&(s.totalduration=s.edge-h[0].start),s.driftStartTime=t.driftStartTime,s.driftStart=t.driftStart;const o=s.advancedDateTime;if(s.advanced&&o){const t=s.edge;s.driftStart||(s.driftStartTime=o,s.driftStart=t),s.driftEndTime=o,s.driftEnd=t}else s.driftEndTime=t.driftEndTime,s.driftEnd=t.driftEnd,s.advancedDateTime=t.advancedDateTime}(i,e),!this.canLoad||!e.live)return;let h,o,a;if(e.canBlockReload&&e.endSN&&e.advanced){const t=this.hls.config.lowLatencyMode,n=e.lastPartSn,r=e.endSN,l=e.lastPartIndex,c=n===r;-1!==l?(o=c?r+1:n,a=c?t?0:l:l+1):o=r+1;const u=e.age;let d=Math.min(u+e.ageHeader-e.partTarget,1.5*e.targetduration);if(d>0){if(i&&d>i.tuneInGoal)this.warn(`CDN Tune-in goal increased from: ${i.tuneInGoal} to: ${d} with playlist age: ${e.age}`),d=0;else{const t=Math.floor(d/e.targetduration);o+=t,void 0!==a&&(a+=Math.round(d%e.targetduration/e.partTarget)),this.log(`CDN Tune-in age: ${e.ageHeader}s last advanced ${u.toFixed(2)}s goal: ${d} skip sn ${t} to part ${a}`)}e.tuneInGoal=d}if(h=this.getDeliveryDirectives(e,s.deliveryDirectives,o,a),t||!c)return void this.loadPlaylist(h)}else e.canBlockReload&&(h=this.getDeliveryDirectives(e,s.deliveryDirectives,o,a));const l=this.hls.mainForwardBufferInfo,d=function(t,s=1/0){let i=1e3*t.targetduration;if(t.updated){const e=t.fragments;if(e.length&&4*i>s){const t=1e3*e[e.length-1].duration;t<i&&(i=t)}}else i/=2;return Math.round(i)}(e,1e3*(e.edge-(l?l.end-l.len:0)));e.updated&&r>this.requestScheduled+d&&(this.requestScheduled=n.loading.start),void 0!==o&&e.canBlockReload?this.requestScheduled=n.loading.first+d-(1e3*e.partTarget||1e3):-1===this.requestScheduled||this.requestScheduled+d<r?this.requestScheduled=r:this.requestScheduled-r<=0&&(this.requestScheduled+=d);let f=this.requestScheduled-r;f=Math.max(0,f),this.log(`reload live playlist ${t} in ${Math.round(f)} ms`),this.timer=self.setTimeout((()=>this.loadPlaylist(h)),f)}else this.clearTimer()}getDeliveryDirectives(t,s,i,e){let n=function(t,s){const{canSkipUntil:i,canSkipDateRanges:e,endSN:n}=t;return i&&(void 0!==s?s-n:0)<i?e?"v2":"YES":""}(t,i);return null!=s&&s.skip&&t.deltaUpdateFailed&&(i=s.msn,e=s.part,n=""),new ws(i,e,n)}checkRetry(t){const s=t.details,i=Ls(t),e=t.errorAction,{action:n,retryCount:r=0,retryConfig:h}=e||{},o=!!e&&!!h&&(5===n||!e.resolved&&2===n);if(o){var a;if(this.requestScheduled=-1,i&&null!=(a=t.context)&&a.deliveryDirectives)this.warn(`Retrying playlist loading ${r+1}/${h.maxNumRetry} after "${s}" without delivery-directives`),this.loadPlaylist();else{const t=Ds(h,r);this.timer=self.setTimeout((()=>this.loadPlaylist()),t),this.warn(`Retrying playlist loading ${r+1}/${h.maxNumRetry} after "${s}" in ${t}ms`)}t.levelRetry=!0,e.resolved=!0}return o}}let Fs;class Bs extends Us{constructor(t,s){super(t,"[level-controller]"),this._levels=[],this._firstLevel=-1,this._startLevel=void 0,this.currentLevel=null,this.currentLevelIndex=-1,this.manualLevelIndex=-1,this.steering=void 0,this.onParsedComplete=void 0,this.steering=s,this._registerListeners()}_registerListeners(){const{hls:t}=this;t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(d.LEVEL_LOADED,this.onLevelLoaded,this),t.on(d.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(d.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.on(d.FRAG_LOADED,this.onFragLoaded,this),t.on(d.ERROR,this.onError,this)}_unregisterListeners(){const{hls:t}=this;t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(d.LEVEL_LOADED,this.onLevelLoaded,this),t.off(d.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(d.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.off(d.FRAG_LOADED,this.onFragLoaded,this),t.off(d.ERROR,this.onError,this)}destroy(){this._unregisterListeners(),this.steering=null,this.resetLevels(),super.destroy()}startLoad(){this._levels.forEach((t=>{t.loadError=0,t.fragmentError=0})),super.startLoad()}resetLevels(){this._startLevel=void 0,this.manualLevelIndex=-1,this.currentLevelIndex=-1,this.currentLevel=null,this._levels=[]}onManifestLoading(t,s){this.resetLevels()}onManifestLoaded(t,s){const i=[],e={};let n;s.levels.forEach((t=>{var s;const r=t.attrs;-1!==(null==(s=t.audioCodec)?void 0:s.indexOf("mp4a.40.34"))&&(Fs||(Fs=/chrome|firefox/i.test(navigator.userAgent)),Fs&&(t.audioCodec=void 0));const{AUDIO:h,CODECS:o,"FRAME-RATE":a,"PATHWAY-ID":l,RESOLUTION:c,SUBTITLES:u}=r,d=`${l||"."}-${t.bitrate}-${c}-${a}-${o}`;n=e[d],n?n.addFallback(t):(n=new bs(t),e[d]=n,i.push(n)),_s(n,"audio",h),_s(n,"text",u)})),this.filterAndSortMediaOptions(i,s)}filterAndSortMediaOptions(t,s){let i=[],e=[],n=!1,r=!1,h=!1,o=t.filter((({audioCodec:t,videoCodec:s,width:i,height:e,unknownCodecs:o})=>(n||(n=!(!i||!e)),r||(r=!!s),h||(h=!!t),!(null!=o&&o.length)&&(!t||Ut(t,"audio"))&&(!s||Ut(s,"video")))));if((n||r)&&h&&(o=o.filter((({videoCodec:t,width:s,height:i})=>!!t||!(!s||!i)))),0===o.length)return void Promise.resolve().then((()=>{if(this.hls){const t=new Error("no level with compatible codecs found in manifest");this.hls.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:s.url,error:t,reason:t.message})}}));s.audioTracks&&(i=s.audioTracks.filter((t=>!t.audioCodec||Ut(t.audioCodec,"audio"))),js(i)),s.subtitles&&(e=s.subtitles,js(e));const a=o.slice(0);o.sort(((t,s)=>t.attrs["HDCP-LEVEL"]!==s.attrs["HDCP-LEVEL"]?(t.attrs["HDCP-LEVEL"]||"")>(s.attrs["HDCP-LEVEL"]||"")?1:-1:t.bitrate!==s.bitrate?t.bitrate-s.bitrate:t.attrs["FRAME-RATE"]!==s.attrs["FRAME-RATE"]?t.attrs.decimalFloatingPoint("FRAME-RATE")-s.attrs.decimalFloatingPoint("FRAME-RATE"):t.attrs.SCORE!==s.attrs.SCORE?t.attrs.decimalFloatingPoint("SCORE")-s.attrs.decimalFloatingPoint("SCORE"):n&&t.height!==s.height?t.height-s.height:0));let l=a[0];if(this.steering&&(o=this.steering.filterParsedLevels(o),o.length!==a.length))for(let t=0;t<a.length;t++)if(a[t].pathwayId===o[0].pathwayId){l=a[t];break}this._levels=o;for(let t=0;t<o.length;t++)if(o[t]===l){this._firstLevel=t,this.log(`manifest loaded, ${o.length} level(s) found, first bitrate: ${l.bitrate}`);break}const c={levels:o,audioTracks:i,subtitleTracks:e,sessionData:s.sessionData,sessionKeys:s.sessionKeys,firstLevel:this._firstLevel,stats:s.stats,audio:h,video:r,altAudio:!(h&&!r)&&i.some((t=>!!t.url))};this.hls.trigger(d.MANIFEST_PARSED,c),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}get levels(){return 0===this._levels.length?null:this._levels}get level(){return this.currentLevelIndex}set level(t){const s=this._levels;if(0===s.length)return;if(t<0||t>=s.length){const i=new Error("invalid level idx"),e=t<0;if(this.hls.trigger(d.ERROR,{type:f.OTHER_ERROR,details:m.LEVEL_SWITCH_ERROR,level:t,fatal:e,error:i,reason:i.message}),e)return;t=Math.min(t,s.length-1)}const i=this.currentLevelIndex,e=this.currentLevel,n=e?e.attrs["PATHWAY-ID"]:void 0,r=s[t],h=r.attrs["PATHWAY-ID"];if(this.currentLevelIndex=t,this.currentLevel=r,i===t&&r.details&&e&&n===h)return;this.log(`Switching to level ${t}${h?" with Pathway "+h:""} from level ${i}${n?" with Pathway "+n:""}`);const o=c({},r,{level:t,maxBitrate:r.maxBitrate,attrs:r.attrs,uri:r.uri,urlId:r.urlId});delete o._attrs,delete o._urlId,this.hls.trigger(d.LEVEL_SWITCHING,o);const a=r.details;if(!a||a.live){const t=this.switchParams(r.uri,null==e?void 0:e.details);this.loadPlaylist(t)}}get manualLevel(){return this.manualLevelIndex}set manualLevel(t){this.manualLevelIndex=t,void 0===this._startLevel&&(this._startLevel=t),-1!==t&&(this.level=t)}get firstLevel(){return this._firstLevel}set firstLevel(t){this._firstLevel=t}get startLevel(){if(void 0===this._startLevel){const t=this.hls.config.startLevel;return void 0!==t?t:this._firstLevel}return this._startLevel}set startLevel(t){this._startLevel=t}onError(t,s){!s.fatal&&s.context&&s.context.type===Jt&&s.context.level===this.level&&this.checkRetry(s)}onFragLoaded(t,{frag:s}){if(void 0!==s&&s.type===ss){const t=this._levels[s.level];void 0!==t&&(t.loadError=0)}}onLevelLoaded(t,s){var i;const{level:e,details:n}=s,r=this._levels[e];var h;if(!r)return this.warn(`Invalid level index ${e}`),void(null!=(h=s.deliveryDirectives)&&h.skip&&(n.deltaUpdateFailed=!0));e===this.currentLevelIndex?(0===r.fragmentError&&(r.loadError=0),this.playlistLoaded(e,s,r.details)):null!=(i=s.deliveryDirectives)&&i.skip&&(n.deltaUpdateFailed=!0)}onAudioTrackSwitched(t,s){const i=this.currentLevel;if(!i)return;const e=this.hls.audioTracks[s.id].groupId;if(i.audioGroupIds&&i.audioGroupId!==e){let t=-1;for(let s=0;s<i.audioGroupIds.length;s++)if(i.audioGroupIds[s]===e){t=s;break}-1!==t&&t!==i.urlId&&(i.urlId=t,this.canLoad&&this.startLoad())}}loadPlaylist(t){super.loadPlaylist();const s=this.currentLevelIndex,i=this.currentLevel;if(i&&this.shouldLoadPlaylist(i)){const e=i.urlId;let n=i.uri;if(t)try{n=t.addDirectives(n)}catch(t){this.warn(`Could not construct new URL with HLS Delivery Directives: ${t}`)}const r=i.attrs["PATHWAY-ID"];this.log(`Loading level index ${s}${void 0!==(null==t?void 0:t.msn)?" at sn "+t.msn+" part "+t.part:""} with${r?" Pathway "+r:""} URI ${e+1}/${i.url.length} ${n}`),this.clearTimer(),this.hls.trigger(d.LEVEL_LOADING,{url:n,level:s,id:e,deliveryDirectives:t||null})}}get nextLoadLevel(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel}set nextLoadLevel(t){this.level=t,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=t)}removeLevel(t,s){const i=(t,i)=>i!==s,e=this._levels.filter(((e,n)=>n!==t||(e.url.length>1&&void 0!==s?(e.url=e.url.filter(i),e.audioGroupIds&&(e.audioGroupIds=e.audioGroupIds.filter(i)),e.textGroupIds&&(e.textGroupIds=e.textGroupIds.filter(i)),e.urlId=0,!0):(this.steering&&this.steering.removeLevel(e),!1))));this.hls.trigger(d.LEVELS_UPDATED,{levels:e})}onLevelsUpdated(t,{levels:s}){s.forEach(((t,s)=>{const{details:i}=t;null!=i&&i.fragments&&i.fragments.forEach((t=>{t.level=s}))})),this._levels=s}}function _s(t,s,i){i&&("audio"===s?(t.audioGroupIds||(t.audioGroupIds=[]),t.audioGroupIds[t.url.length-1]=i):"text"===s&&(t.textGroupIds||(t.textGroupIds=[]),t.textGroupIds[t.url.length-1]=i))}function js(t){const s={};t.forEach((t=>{const i=t.groupId||"";t.id=s[i]=s[i]||0,s[i]++}))}var Ks="NOT_LOADED",Hs="APPENDING",Gs="PARTIAL",Vs="OK";class Ws{constructor(t){this.activePartLists=Object.create(null),this.endListFragments=Object.create(null),this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.bufferPadding=.2,this.hls=void 0,this.hasGaps=!1,this.hls=t,this._registerListeners()}_registerListeners(){const{hls:t}=this;t.on(d.BUFFER_APPENDED,this.onBufferAppended,this),t.on(d.FRAG_BUFFERED,this.onFragBuffered,this),t.on(d.FRAG_LOADED,this.onFragLoaded,this)}_unregisterListeners(){const{hls:t}=this;t.off(d.BUFFER_APPENDED,this.onBufferAppended,this),t.off(d.FRAG_BUFFERED,this.onFragBuffered,this),t.off(d.FRAG_LOADED,this.onFragLoaded,this)}destroy(){this._unregisterListeners(),this.fragments=this.activePartLists=this.endListFragments=this.timeRanges=null}getAppendedFrag(t,s){const i=this.activePartLists[s];if(i)for(let s=i.length;s--;){const e=i[s];if(!e)break;const n=e.end;if(e.start<=t&&null!==n&&t<=n)return e}return this.getBufferedFrag(t,s)}getBufferedFrag(t,s){const{fragments:i}=this,e=Object.keys(i);for(let n=e.length;n--;){const r=i[e[n]];if((null==r?void 0:r.body.type)===s&&r.buffered){const s=r.body;if(s.start<=t&&t<=s.end)return s}}return null}detectEvictedFragments(t,s,i,e){this.timeRanges&&(this.timeRanges[t]=s);const n=(null==e?void 0:e.fragment.sn)||0;Object.keys(this.fragments).forEach((e=>{const r=this.fragments[e];if(!r)return;if(n>=r.body.sn)return;if(!r.buffered&&!r.loaded)return void(r.body.type===i&&this.removeFragment(r.body));const h=r.range[t];h&&h.time.some((t=>{const i=!this.isTimeBuffered(t.startPTS,t.endPTS,s);return i&&this.removeFragment(r.body),i}))}))}detectPartialFragments(t){const s=this.timeRanges,{frag:i,part:e}=t;if(!s||"initSegment"===i.sn)return;const n=qs(i),r=this.fragments[n];if(!r)return;const h=!i.relurl;Object.keys(s).forEach((t=>{const n=i.elementaryStreams[t];n&&(r.range[t]=this.getBufferedTimes(i,e,h||!0===n.partial,s[t]))})),r.loaded=null,Object.keys(r.range).length?(r.buffered=!0,r.body.endList&&(this.endListFragments[r.body.type]=r),Xs(r)||this.removeParts(i.sn-1,i.type)):this.removeFragment(r.body)}removeParts(t,s){const i=this.activePartLists[s];i&&(this.activePartLists[s]=i.filter((s=>s.fragment.sn>=t)))}fragBuffered(t,s){const i=qs(t);let e=this.fragments[i];!e&&s&&(e=this.fragments[i]={body:t,appendedPTS:null,loaded:null,buffered:!1,range:Object.create(null)},t.gap&&(this.hasGaps=!0)),e&&(e.loaded=null,e.buffered=!0)}getBufferedTimes(t,s,i,e){const n={time:[],partial:i},r=t.start,h=t.end,o=t.minEndPTS||h,a=t.maxStartPTS||r;for(let t=0;t<e.length;t++){const s=e.start(t)-this.bufferPadding,i=e.end(t)+this.bufferPadding;if(a>=s&&o<=i){n.time.push({startPTS:Math.max(r,e.start(t)),endPTS:Math.min(h,e.end(t))});break}if(r<i&&h>s)n.partial=!0,n.time.push({startPTS:Math.max(r,e.start(t)),endPTS:Math.min(h,e.end(t))});else if(h<=s)break}return n}getPartialFragment(t){let s,i,e,n=null,r=0;const{bufferPadding:h,fragments:o}=this;return Object.keys(o).forEach((a=>{const l=o[a];l&&Xs(l)&&(i=l.body.start-h,e=l.body.end+h,t>=i&&t<=e&&(s=Math.min(t-i,e-t),r<=s&&(n=l.body,r=s)))})),n}isEndListAppended(t){const s=this.endListFragments[t];return void 0!==s&&(s.buffered||Xs(s))}getState(t){const s=qs(t),i=this.fragments[s];return i?i.buffered?Xs(i)?Gs:Vs:Hs:Ks}isTimeBuffered(t,s,i){let e,n;for(let r=0;r<i.length;r++){if(e=i.start(r)-this.bufferPadding,n=i.end(r)+this.bufferPadding,t>=e&&s<=n)return!0;if(s<=e)return!1}return!1}onFragLoaded(t,s){const{frag:i,part:e}=s;if("initSegment"===i.sn||i.bitrateTest)return;const n=e?null:s,r=qs(i);this.fragments[r]={body:i,appendedPTS:null,loaded:n,buffered:!1,range:Object.create(null)}}onBufferAppended(t,s){const{frag:i,part:e,timeRanges:n}=s;if("initSegment"===i.sn)return;const r=i.type;if(e){let t=this.activePartLists[r];t||(this.activePartLists[r]=t=[]),t.push(e)}this.timeRanges=n,Object.keys(n).forEach((t=>{this.detectEvictedFragments(t,n[t],r,e)}))}onFragBuffered(t,s){this.detectPartialFragments(s)}hasFragment(t){const s=qs(t);return!!this.fragments[s]}hasParts(t){var s;return!(null==(s=this.activePartLists[t])||!s.length)}removeFragmentsInRange(t,s,i,e,n){e&&!this.hasGaps||Object.keys(this.fragments).forEach((r=>{const h=this.fragments[r];if(!h)return;const o=h.body;o.type!==i||e&&!o.gap||o.start<s&&o.end>t&&(h.buffered||n)&&this.removeFragment(o)}))}removeFragment(t){const s=qs(t);t.stats.loaded=0,t.clearElementaryStreamInfo();const i=this.activePartLists[t.type];if(i){const s=t.sn;this.activePartLists[t.type]=i.filter((t=>t.fragment.sn!==s))}delete this.fragments[s],t.endList&&delete this.endListFragments[t.type]}removeAllFragments(){this.fragments=Object.create(null),this.endListFragments=Object.create(null),this.activePartLists=Object.create(null),this.hasGaps=!1}}function Xs(t){var s,i;return t.buffered&&(t.body.gap||(null==(s=t.range.video)?void 0:s.partial)||(null==(i=t.range.audio)?void 0:i.partial))}function qs(t){return`${t.type}_${t.level}_${t.urlId}_${t.sn}`}const Ys=Math.pow(2,17);class zs{constructor(t){this.config=void 0,this.loader=null,this.partLoadTimeout=-1,this.config=t}destroy(){this.loader&&(this.loader.destroy(),this.loader=null)}abort(){this.loader&&this.loader.abort()}load(t,s){const i=t.url;if(!i)return Promise.reject(new Zs({type:f.NETWORK_ERROR,details:m.FRAG_LOAD_ERROR,fatal:!1,frag:t,error:new Error("Fragment does not have a "+(i?"part list":"url")),networkDetails:null}));this.abort();const e=this.config,n=e.fLoader,r=e.loader;return new Promise(((h,o)=>{if(this.loader&&this.loader.destroy(),t.gap)return void o(Js(t));const l=this.loader=t.loader=n?new n(e):new r(e),c=Qs(t),u=xs(e.fragLoadPolicy.default),d={loadPolicy:u,timeout:u.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:"initSegment"===t.sn?1/0:Ys};t.stats=l.stats,l.load(c,d,{onSuccess:(s,i,e,n)=>{this.resetLoader(t,l);let r=s.data;e.resetIV&&t.decryptdata&&(t.decryptdata.iv=new Uint8Array(r.slice(0,16)),r=r.slice(16)),h({frag:t,part:null,payload:r,networkDetails:n})},onError:(s,e,n,r)=>{this.resetLoader(t,l),o(new Zs({type:f.NETWORK_ERROR,details:m.FRAG_LOAD_ERROR,fatal:!1,frag:t,response:a({url:i,data:void 0},s),error:new Error(`HTTP Error ${s.code} ${s.text}`),networkDetails:n,stats:r}))},onAbort:(s,i,e)=>{this.resetLoader(t,l),o(new Zs({type:f.NETWORK_ERROR,details:m.INTERNAL_ABORTED,fatal:!1,frag:t,error:new Error("Aborted"),networkDetails:e,stats:s}))},onTimeout:(s,i,e)=>{this.resetLoader(t,l),o(new Zs({type:f.NETWORK_ERROR,details:m.FRAG_LOAD_TIMEOUT,fatal:!1,frag:t,error:new Error(`Timeout after ${d.timeout}ms`),networkDetails:e,stats:s}))},onProgress:(i,e,n,r)=>{s&&s({frag:t,part:null,payload:n,networkDetails:r})}})}))}loadPart(t,s,i){this.abort();const e=this.config,n=e.fLoader,r=e.loader;return new Promise(((h,o)=>{if(this.loader&&this.loader.destroy(),t.gap||s.gap)return void o(Js(t,s));const l=this.loader=t.loader=n?new n(e):new r(e),c=Qs(t,s),u=xs(e.fragLoadPolicy.default),d={loadPolicy:u,timeout:u.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:Ys};s.stats=l.stats,l.load(c,d,{onSuccess:(e,n,r,o)=>{this.resetLoader(t,l),this.updateStatsFromPart(t,s);const a={frag:t,part:s,payload:e.data,networkDetails:o};i(a),h(a)},onError:(i,e,n,r)=>{this.resetLoader(t,l),o(new Zs({type:f.NETWORK_ERROR,details:m.FRAG_LOAD_ERROR,fatal:!1,frag:t,part:s,response:a({url:c.url,data:void 0},i),error:new Error(`HTTP Error ${i.code} ${i.text}`),networkDetails:n,stats:r}))},onAbort:(i,e,n)=>{t.stats.aborted=s.stats.aborted,this.resetLoader(t,l),o(new Zs({type:f.NETWORK_ERROR,details:m.INTERNAL_ABORTED,fatal:!1,frag:t,part:s,error:new Error("Aborted"),networkDetails:n,stats:i}))},onTimeout:(i,e,n)=>{this.resetLoader(t,l),o(new Zs({type:f.NETWORK_ERROR,details:m.FRAG_LOAD_TIMEOUT,fatal:!1,frag:t,part:s,error:new Error(`Timeout after ${d.timeout}ms`),networkDetails:n,stats:i}))}})}))}updateStatsFromPart(t,s){const i=t.stats,e=s.stats,n=e.total;if(i.loaded+=e.loaded,n){const e=Math.round(t.duration/s.duration),r=Math.min(Math.round(i.loaded/n),e),h=(e-r)*Math.round(i.loaded/r);i.total=i.loaded+h}else i.total=Math.max(i.loaded,i.total);const r=i.loading,h=e.loading;r.start?r.first+=h.first-h.start:(r.start=h.start,r.first=h.first),r.end=h.end}resetLoader(t,s){t.loader=null,this.loader===s&&(self.clearTimeout(this.partLoadTimeout),this.loader=null),s.destroy()}}function Qs(t,s=null){const i=s||t,e={frag:t,part:s,responseType:"arraybuffer",url:i.url,headers:{},rangeStart:0,rangeEnd:0},n=i.byteRangeStartOffset,r=i.byteRangeEndOffset;if(u(n)&&u(r)){var h;let s=n,i=r;if("initSegment"===t.sn&&"AES-128"===(null==(h=t.decryptdata)?void 0:h.method)){const t=r-n;t%16&&(i=r+(16-t%16)),0!==n&&(e.resetIV=!0,s=n-16)}e.rangeStart=s,e.rangeEnd=i}return e}function Js(t,s){const i=new Error(`GAP ${t.gap?"tag":"attribute"} found`),e={type:f.MEDIA_ERROR,details:m.FRAG_GAP,fatal:!1,frag:t,error:i,networkDetails:null};return s&&(e.part=s),(s||t).stats.aborted=!0,new Zs(e)}class Zs extends Error{constructor(t){super(t.error.message),this.data=void 0,this.data=t}}class ti{constructor(t){this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=t}abort(t){for(const s in this.keyUriToKeyInfo){const i=this.keyUriToKeyInfo[s].loader;if(i){if(t&&t!==i.context.frag.type)return;i.abort()}}}detach(){for(const t in this.keyUriToKeyInfo){const s=this.keyUriToKeyInfo[t];(s.mediaKeySessionContext||s.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[t]}}destroy(){this.detach();for(const t in this.keyUriToKeyInfo){const s=this.keyUriToKeyInfo[t].loader;s&&s.destroy()}this.keyUriToKeyInfo={}}createKeyLoadError(t,s=m.KEY_LOAD_ERROR,i,e,n){return new Zs({type:f.NETWORK_ERROR,details:s,fatal:!1,frag:t,response:n,error:i,networkDetails:e})}loadClear(t,s){if(this.emeController&&this.config.emeEnabled){const{sn:i,cc:e}=t;for(let t=0;t<s.length;t++){const n=s[t];if(e<=n.cc&&("initSegment"===i||"initSegment"===n.sn||i<n.sn)){this.emeController.selectKeySystemFormat(n).then((t=>{n.setKeyFormat(t)}));break}}}}load(t){return!t.decryptdata&&t.encrypted&&this.emeController?this.emeController.selectKeySystemFormat(t).then((s=>this.loadInternal(t,s))):this.loadInternal(t)}loadInternal(t,s){var i,e;s&&t.setKeyFormat(s);const n=t.decryptdata;if(!n){const i=new Error(s?`Expected frag.decryptdata to be defined after setting format ${s}`:"Missing decryption data on fragment in onKeyLoading");return Promise.reject(this.createKeyLoadError(t,m.KEY_LOAD_ERROR,i))}const r=n.uri;if(!r)return Promise.reject(this.createKeyLoadError(t,m.KEY_LOAD_ERROR,new Error(`Invalid key URI: "${r}"`)));let h=this.keyUriToKeyInfo[r];if(null!=(i=h)&&i.decryptdata.key)return n.key=h.decryptdata.key,Promise.resolve({frag:t,keyInfo:h});var o;if(null!=(e=h)&&e.keyLoadPromise)switch(null==(o=h.mediaKeySessionContext)?void 0:o.keyStatus){case void 0:case"status-pending":case"usable":case"usable-in-future":return h.keyLoadPromise.then((s=>(n.key=s.keyInfo.decryptdata.key,{frag:t,keyInfo:h})))}switch(h=this.keyUriToKeyInfo[r]={decryptdata:n,keyLoadPromise:null,loader:null,mediaKeySessionContext:null},n.method){case"ISO-23001-7":case"SAMPLE-AES":case"SAMPLE-AES-CENC":case"SAMPLE-AES-CTR":return"identity"===n.keyFormat?this.loadKeyHTTP(h,t):this.loadKeyEME(h,t);case"AES-128":return this.loadKeyHTTP(h,t);default:return Promise.reject(this.createKeyLoadError(t,m.KEY_LOAD_ERROR,new Error(`Key supplied with unsupported METHOD: "${n.method}"`)))}}loadKeyEME(t,s){const i={frag:s,keyInfo:t};if(this.emeController&&this.config.emeEnabled){const s=this.emeController.loadKey(i);if(s)return(t.keyLoadPromise=s.then((s=>(t.mediaKeySessionContext=s,i)))).catch((s=>{throw t.keyLoadPromise=null,s}))}return Promise.resolve(i)}loadKeyHTTP(t,s){const i=this.config,e=new(0,i.loader)(i);return s.keyLoader=t.loader=e,t.keyLoadPromise=new Promise(((n,r)=>{const h={keyInfo:t,frag:s,responseType:"arraybuffer",url:t.decryptdata.uri},o=i.keyLoadPolicy.default,l={onSuccess:(t,s,i,e)=>{const{frag:h,keyInfo:o,url:a}=i;if(!h.decryptdata||o!==this.keyUriToKeyInfo[a])return r(this.createKeyLoadError(h,m.KEY_LOAD_ERROR,new Error("after key load, decryptdata unset or changed"),e));o.decryptdata.key=h.decryptdata.key=new Uint8Array(t.data),h.keyLoader=null,o.loader=null,n({frag:h,keyInfo:o})},onError:(t,i,e)=>{this.resetLoader(i),r(this.createKeyLoadError(s,m.KEY_LOAD_ERROR,new Error(`HTTP Error ${t.code} loading key ${t.text}`),e,a({url:h.url,data:void 0},t)))},onTimeout:(t,i,e)=>{this.resetLoader(i),r(this.createKeyLoadError(s,m.KEY_LOAD_TIMEOUT,new Error("key loading timed out"),e))},onAbort:(t,i,e)=>{this.resetLoader(i),r(this.createKeyLoadError(s,m.INTERNAL_ABORTED,new Error("key loading aborted"),e))}};e.load(h,{loadPolicy:o,timeout:o.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0},l)}))}resetLoader(t){const{frag:s,keyInfo:i,url:e}=t,n=i.loader;s.keyLoader===n&&(s.keyLoader=null,i.loader=null),delete this.keyUriToKeyInfo[e],n&&n.destroy()}}class si{constructor(){this._boundTick=void 0,this._tickTimer=null,this._tickInterval=null,this._tickCallCount=0,this._boundTick=this.tick.bind(this)}destroy(){this.onHandlerDestroying(),this.onHandlerDestroyed()}onHandlerDestroying(){this.clearNextTick(),this.clearInterval()}onHandlerDestroyed(){}hasInterval(){return!!this._tickInterval}hasNextTick(){return!!this._tickTimer}setInterval(t){return!this._tickInterval&&(this._tickCallCount=0,this._tickInterval=self.setInterval(this._boundTick,t),!0)}clearInterval(){return!!this._tickInterval&&(self.clearInterval(this._tickInterval),this._tickInterval=null,!0)}clearNextTick(){return!!this._tickTimer&&(self.clearTimeout(this._tickTimer),this._tickTimer=null,!0)}tick(){this._tickCallCount++,1===this._tickCallCount&&(this.doTick(),this._tickCallCount>1&&this.tickImmediate(),this._tickCallCount=0)}tickImmediate(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)}doTick(){}}const ii={length:0,start:()=>0,end:()=>0};class ei{static isBuffered(t,s){try{if(t){const i=ei.getBuffered(t);for(let t=0;t<i.length;t++)if(s>=i.start(t)&&s<=i.end(t))return!0}}catch(t){}return!1}static bufferInfo(t,s,i){try{if(t){const e=ei.getBuffered(t),n=[];let r;for(r=0;r<e.length;r++)n.push({start:e.start(r),end:e.end(r)});return this.bufferedInfo(n,s,i)}}catch(t){}return{len:0,start:s,end:s,nextStart:void 0}}static bufferedInfo(t,s,i){s=Math.max(0,s),t.sort((function(t,s){return t.start-s.start||s.end-t.end}));let e=[];if(i)for(let s=0;s<t.length;s++){const n=e.length;if(n){const r=e[n-1].end;t[s].start-r<i?t[s].end>r&&(e[n-1].end=t[s].end):e.push(t[s])}else e.push(t[s])}else e=t;let n,r=0,h=s,o=s;for(let t=0;t<e.length;t++){const a=e[t].start,l=e[t].end;if(s+i>=a&&s<l)h=a,o=l,r=o-s;else if(s+i<a){n=a;break}}return{len:r,start:h||0,end:o||0,nextStart:n}}static getBuffered(t){try{return t.buffered}catch(t){return y.log("failed to get media.buffered",t),ii}}}class ni{constructor(t,s,i,e=0,n=-1,r=!1){this.level=void 0,this.sn=void 0,this.part=void 0,this.id=void 0,this.size=void 0,this.partial=void 0,this.transmuxing={start:0,executeStart:0,executeEnd:0,end:0},this.buffering={audio:{start:0,executeStart:0,executeEnd:0,end:0},video:{start:0,executeStart:0,executeEnd:0,end:0},audiovideo:{start:0,executeStart:0,executeEnd:0,end:0}},this.level=t,this.sn=s,this.id=i,this.size=e,this.part=n,this.partial=r}}function ri(t,s){let i=null;for(let e=0,n=t.length;e<n;e++){const n=t[e];if(n&&n.cc===s){i=n;break}}return i}function hi(t,s){if(t){const i=t.start+s;t.start=t.startPTS=i,t.endPTS=i+t.duration}}function oi(t,s){const i=s.fragments;for(let s=0,e=i.length;s<e;s++)hi(i[s],t);s.fragmentHint&&hi(s.fragmentHint,t),s.alignedSliding=!0}function ai(t,s){if(!t.hasProgramDateTime||!s.hasProgramDateTime)return;const i=t.fragments,e=s.fragments;if(!i.length||!e.length)return;const n=e[Math.round(e.length/2)-1],r=ri(i,n.cc)||i[Math.round(i.length/2)-1],h=n.programDateTime,o=r.programDateTime;null!==h&&null!==o&&oi((o-h)/1e3-(r.start-n.start),t)}class li{constructor(t,s){this.subtle=void 0,this.aesIV=void 0,this.subtle=t,this.aesIV=s}decrypt(t,s){return this.subtle.decrypt({name:"AES-CBC",iv:this.aesIV},s,t)}}class ci{constructor(t,s){this.subtle=void 0,this.key=void 0,this.subtle=t,this.key=s}expandKey(){return this.subtle.importKey("raw",this.key,{name:"AES-CBC"},!1,["encrypt","decrypt"])}}class ui{constructor(){this.rcon=[0,1,2,4,8,16,32,64,128,27,54],this.subMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.invSubMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.sBox=new Uint32Array(256),this.invSBox=new Uint32Array(256),this.key=new Uint32Array(0),this.ksRows=0,this.keySize=0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.initTable()}uint8ArrayToUint32Array_(t){const s=new DataView(t),i=new Uint32Array(4);for(let t=0;t<4;t++)i[t]=s.getUint32(4*t);return i}initTable(){const t=this.sBox,s=this.invSBox,i=this.subMix,e=i[0],n=i[1],r=i[2],h=i[3],o=this.invSubMix,a=o[0],l=o[1],c=o[2],u=o[3],d=new Uint32Array(256);let f=0,m=0,g=0;for(g=0;g<256;g++)d[g]=g<128?g<<1:g<<1^283;for(g=0;g<256;g++){let i=m^m<<1^m<<2^m<<3^m<<4;i=i>>>8^255&i^99,t[f]=i,s[i]=f;const o=d[f],g=d[o],v=d[g];let p=257*d[i]^16843008*i;e[f]=p<<24|p>>>8,n[f]=p<<16|p>>>16,r[f]=p<<8|p>>>24,h[f]=p,p=16843009*v^65537*g^257*o^16843008*f,a[i]=p<<24|p>>>8,l[i]=p<<16|p>>>16,c[i]=p<<8|p>>>24,u[i]=p,f?(f=o^d[d[d[v^o]]],m^=d[d[m]]):f=m=1}}expandKey(t){const s=this.uint8ArrayToUint32Array_(t);let i=!0,e=0;for(;e<s.length&&i;)i=s[e]===this.key[e],e++;if(i)return;this.key=s;const n=this.keySize=s.length;if(4!==n&&6!==n&&8!==n)throw new Error("Invalid aes key size="+n);const r=this.ksRows=4*(n+6+1);let h,o;const a=this.keySchedule=new Uint32Array(r),l=this.invKeySchedule=new Uint32Array(r),c=this.sBox,u=this.rcon,d=this.invSubMix,f=d[0],m=d[1],g=d[2],v=d[3];let p,y;for(h=0;h<r;h++)h<n?p=a[h]=s[h]:(y=p,h%n==0?(y=y<<8|y>>>24,y=c[y>>>24]<<24|c[y>>>16&255]<<16|c[y>>>8&255]<<8|c[255&y],y^=u[h/n|0]<<24):n>6&&h%n==4&&(y=c[y>>>24]<<24|c[y>>>16&255]<<16|c[y>>>8&255]<<8|c[255&y]),a[h]=p=(a[h-n]^y)>>>0);for(o=0;o<r;o++)h=r-o,y=3&o?a[h]:a[h-4],l[o]=o<4||h<=4?y:f[c[y>>>24]]^m[c[y>>>16&255]]^g[c[y>>>8&255]]^v[c[255&y]],l[o]=l[o]>>>0}networkToHostOrderSwap(t){return t<<24|(65280&t)<<8|(16711680&t)>>8|t>>>24}decrypt(t,s,i){const e=this.keySize+6,n=this.invKeySchedule,r=this.invSBox,h=this.invSubMix,o=h[0],a=h[1],l=h[2],c=h[3],u=this.uint8ArrayToUint32Array_(i);let d=u[0],f=u[1],m=u[2],g=u[3];const v=new Int32Array(t),p=new Int32Array(v.length);let y,w,b,T,S,E,k,$,A,L,M,D,x,I;const C=this.networkToHostOrderSwap;for(;s<v.length;){for(A=C(v[s]),L=C(v[s+1]),M=C(v[s+2]),D=C(v[s+3]),S=A^n[0],E=D^n[1],k=M^n[2],$=L^n[3],x=4,I=1;I<e;I++)y=o[S>>>24]^a[E>>16&255]^l[k>>8&255]^c[255&$]^n[x],w=o[E>>>24]^a[k>>16&255]^l[$>>8&255]^c[255&S]^n[x+1],b=o[k>>>24]^a[$>>16&255]^l[S>>8&255]^c[255&E]^n[x+2],T=o[$>>>24]^a[S>>16&255]^l[E>>8&255]^c[255&k]^n[x+3],S=y,E=w,k=b,$=T,x+=4;y=r[S>>>24]<<24^r[E>>16&255]<<16^r[k>>8&255]<<8^r[255&$]^n[x],w=r[E>>>24]<<24^r[k>>16&255]<<16^r[$>>8&255]<<8^r[255&S]^n[x+1],b=r[k>>>24]<<24^r[$>>16&255]<<16^r[S>>8&255]<<8^r[255&E]^n[x+2],T=r[$>>>24]<<24^r[S>>16&255]<<16^r[E>>8&255]<<8^r[255&k]^n[x+3],p[s]=C(y^d),p[s+1]=C(T^f),p[s+2]=C(b^m),p[s+3]=C(w^g),d=A,f=L,m=M,g=D,s+=4}return p.buffer}}class di{constructor(t,{removePKCS7Padding:s=!0}={}){if(this.logEnabled=!0,this.removePKCS7Padding=void 0,this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null,this.useSoftware=void 0,this.useSoftware=t.enableSoftwareAES,this.removePKCS7Padding=s,s)try{const t=self.crypto;t&&(this.subtle=t.subtle||t.webkitSubtle)}catch(t){}null===this.subtle&&(this.useSoftware=!0)}destroy(){this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null}isSync(){return this.useSoftware}flush(){const{currentResult:t,remainderData:s}=this;if(!t||s)return this.reset(),null;const i=new Uint8Array(t);return this.reset(),this.removePKCS7Padding?function(t){const s=t.byteLength,i=s&&new DataView(t.buffer).getUint8(s-1);return i?G(t,0,s-i):t}(i):i}reset(){this.currentResult=null,this.currentIV=null,this.remainderData=null,this.softwareDecrypter&&(this.softwareDecrypter=null)}decrypt(t,s,i){return this.useSoftware?new Promise(((e,n)=>{this.softwareDecrypt(new Uint8Array(t),s,i);const r=this.flush();r?e(r.buffer):n(new Error("[softwareDecrypt] Failed to decrypt data"))})):this.webCryptoDecrypt(new Uint8Array(t),s,i)}softwareDecrypt(t,s,i){const{currentIV:e,currentResult:n,remainderData:r}=this;this.logOnce("JS AES decrypt"),r&&(t=Tt(r,t),this.remainderData=null);const h=this.getValidChunk(t);if(!h.length)return null;e&&(i=e);let o=this.softwareDecrypter;o||(o=this.softwareDecrypter=new ui),o.expandKey(s);const a=n;return this.currentResult=o.decrypt(h.buffer,0,i),this.currentIV=G(h,-16).buffer,a||null}webCryptoDecrypt(t,s,i){const e=this.subtle;return this.key===s&&this.fastAesKey||(this.key=s,this.fastAesKey=new ci(e,s)),this.fastAesKey.expandKey().then((s=>e?(this.logOnce("WebCrypto AES decrypt"),new li(e,new Uint8Array(i)).decrypt(t.buffer,s)):Promise.reject(new Error("web crypto not initialized")))).catch((e=>(y.warn(`[decrypter]: WebCrypto Error, disable WebCrypto API, ${e.name}: ${e.message}`),this.onWebCryptoError(t,s,i))))}onWebCryptoError(t,s,i){this.useSoftware=!0,this.logEnabled=!0,this.softwareDecrypt(t,s,i);const e=this.flush();if(e)return e.buffer;throw new Error("WebCrypto and softwareDecrypt: failed to decrypt data")}getValidChunk(t){let s=t;const i=t.length-t.length%16;return i!==t.length&&(s=G(t,0,i),this.remainderData=G(t,i)),s}logOnce(t){this.logEnabled&&(y.log(`[decrypter]: ${t}`),this.logEnabled=!1)}}const fi="STOPPED",mi="IDLE",gi="KEY_LOADING",vi="FRAG_LOADING",pi="FRAG_LOADING_WAITING_RETRY",yi="WAITING_TRACK",wi="PARSING",bi="PARSED",Ti="ENDED",Si="ERROR",Ei="WAITING_INIT_PTS",ki="WAITING_LEVEL";class $i extends si{constructor(t,s,i,e,n){super(),this.hls=void 0,this.fragPrevious=null,this.fragCurrent=null,this.fragmentTracker=void 0,this.transmuxer=null,this._state=fi,this.playlistType=void 0,this.media=null,this.mediaBuffer=null,this.config=void 0,this.bitrateTest=!1,this.lastCurrentTime=0,this.nextLoadPosition=0,this.startPosition=0,this.startTimeOffset=null,this.loadedmetadata=!1,this.retryDate=0,this.levels=null,this.fragmentLoader=void 0,this.keyLoader=void 0,this.levelLastLoaded=null,this.startFragRequested=!1,this.decrypter=void 0,this.initPTS=[],this.onvseeking=null,this.onvended=null,this.logPrefix="",this.log=void 0,this.warn=void 0,this.playlistType=n,this.logPrefix=e,this.log=y.log.bind(y,`${e}:`),this.warn=y.warn.bind(y,`${e}:`),this.hls=t,this.fragmentLoader=new zs(t.config),this.keyLoader=i,this.fragmentTracker=s,this.config=t.config,this.decrypter=new di(t.config),t.on(d.MANIFEST_LOADED,this.onManifestLoaded,this)}doTick(){this.onTickEnd()}onTickEnd(){}startLoad(t){}stopLoad(){this.fragmentLoader.abort(),this.keyLoader.abort(this.playlistType);const t=this.fragCurrent;null!=t&&t.loader&&(t.abortRequests(),this.fragmentTracker.removeFragment(t)),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=fi}_streamEnded(t,s){if(s.live||t.nextStart||!t.end||!this.media)return!1;const i=s.partList;if(null!=i&&i.length){const t=i[i.length-1];return ei.isBuffered(this.media,t.start+t.duration/2)}return this.fragmentTracker.isEndListAppended(s.fragments[s.fragments.length-1].type)}getLevelDetails(){var t;if(this.levels&&null!==this.levelLastLoaded)return null==(t=this.levels[this.levelLastLoaded])?void 0:t.details}onMediaAttached(t,s){const i=this.media=this.mediaBuffer=s.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),i.addEventListener("seeking",this.onvseeking),i.addEventListener("ended",this.onvended);const e=this.config;this.levels&&e.autoStartLoad&&this.state===fi&&this.startLoad(e.startPosition)}onMediaDetaching(){const t=this.media;null!=t&&t.ended&&(this.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),t&&this.onvseeking&&this.onvended&&(t.removeEventListener("seeking",this.onvseeking),t.removeEventListener("ended",this.onvended),this.onvseeking=this.onvended=null),this.keyLoader&&this.keyLoader.detach(),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()}onMediaSeeking(){const{config:t,fragCurrent:s,media:i,mediaBuffer:e,state:n}=this,r=i?i.currentTime:0,h=ei.bufferInfo(e||i,r,t.maxBufferHole);if(this.log(`media seeking to ${u(r)?r.toFixed(3):r}, state: ${n}`),this.state===Ti)this.resetLoadingState();else if(s){const i=t.maxFragLookUpTolerance,e=s.start-i,n=s.start+s.duration+i;if(!h.len||n<h.start||e>h.end){const t=r>n;(r<e||t)&&(t&&s.loader&&(this.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),s.abortRequests(),this.resetLoadingState()),this.fragPrevious=null)}}i&&(this.fragmentTracker.removeFragmentsInRange(r,1/0,this.playlistType,!0),this.lastCurrentTime=r),this.loadedmetadata||h.len||(this.nextLoadPosition=this.startPosition=r),this.tickImmediate()}onMediaEnded(){this.startPosition=this.lastCurrentTime=0}onManifestLoaded(t,s){this.startTimeOffset=s.startTimeOffset,this.initPTS=[]}onHandlerDestroying(){this.stopLoad(),super.onHandlerDestroying()}onHandlerDestroyed(){this.state=fi,this.fragmentLoader&&this.fragmentLoader.destroy(),this.keyLoader&&this.keyLoader.destroy(),this.decrypter&&this.decrypter.destroy(),this.hls=this.log=this.warn=this.decrypter=this.keyLoader=this.fragmentLoader=this.fragmentTracker=null,super.onHandlerDestroyed()}loadFragment(t,s,i){this._loadFragForPlayback(t,s,i)}_loadFragForPlayback(t,s,i){this._doFragLoad(t,s,i,(s=>{if(this.fragContextChanged(t))return this.warn(`Fragment ${t.sn}${s.part?" p: "+s.part.index:""} of level ${t.level} was dropped during download.`),void this.fragmentTracker.removeFragment(t);t.stats.chunkCount++,this._handleFragmentLoadProgress(s)})).then((s=>{if(!s)return;const i=this.state;this.fragContextChanged(t)?(i===vi||!this.fragCurrent&&i===wi)&&(this.fragmentTracker.removeFragment(t),this.state=mi):("payload"in s&&(this.log(`Loaded fragment ${t.sn} of level ${t.level}`),this.hls.trigger(d.FRAG_LOADED,s)),this._handleFragmentLoadComplete(s))})).catch((s=>{this.state!==fi&&this.state!==Si&&(this.warn(s),this.resetFragmentLoading(t))}))}clearTrackerIfNeeded(t){var s;const{fragmentTracker:i}=this;if(i.getState(t)===Hs){const s=this.getFwdBufferInfo(this.mediaBuffer,t.type),e=Math.max(t.duration,s?s.len:this.config.maxBufferLength);this.reduceMaxBufferLength(e)&&i.removeFragment(t)}else 0===(null==(s=this.mediaBuffer)?void 0:s.buffered.length)?i.removeAllFragments():i.hasParts(t.type)&&(i.detectPartialFragments({frag:t,part:null,stats:t.stats,id:t.type}),i.getState(t)===Gs&&i.removeFragment(t))}flushMainBuffer(t,s,i=null){t-s&&this.hls.trigger(d.BUFFER_FLUSHING,{startOffset:t,endOffset:s,type:i})}_loadInitSegment(t,s){this._doFragLoad(t,s).then((s=>{if(!s||this.fragContextChanged(t)||!this.levels)throw new Error("init load aborted");return s})).then((s=>{const{hls:i}=this,{payload:e}=s,n=t.decryptdata;if(e&&e.byteLength>0&&n&&n.key&&n.iv&&"AES-128"===n.method){const r=self.performance.now();return this.decrypter.decrypt(new Uint8Array(e),n.key.buffer,n.iv.buffer).catch((s=>{throw i.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.FRAG_DECRYPT_ERROR,fatal:!1,error:s,reason:s.message,frag:t}),s})).then((e=>{const n=self.performance.now();return i.trigger(d.FRAG_DECRYPTED,{frag:t,payload:e,stats:{tstart:r,tdecrypt:n}}),s.payload=e,s}))}return s})).then((i=>{const{fragCurrent:e,hls:n,levels:r}=this;if(!r)throw new Error("init load aborted, missing levels");const h=t.stats;this.state=mi,s.fragmentError=0,t.data=new Uint8Array(i.payload),h.parsing.start=h.buffering.start=self.performance.now(),h.parsing.end=h.buffering.end=self.performance.now(),i.frag===e&&n.trigger(d.FRAG_BUFFERED,{stats:h,frag:e,part:null,id:t.type}),this.tick()})).catch((s=>{this.state!==fi&&this.state!==Si&&(this.warn(s),this.resetFragmentLoading(t))}))}fragContextChanged(t){const{fragCurrent:s}=this;return!t||!s||t.level!==s.level||t.sn!==s.sn||t.urlId!==s.urlId}fragBufferedComplete(t,s){var i,e,n,r;const h=this.mediaBuffer?this.mediaBuffer:this.media;this.log(`Buffered ${t.type} sn: ${t.sn}${s?" part: "+s.index:""} of ${this.playlistType===ss?"level":"track"} ${t.level} (frag:[${(null!=(i=t.startPTS)?i:NaN).toFixed(3)}-${(null!=(e=t.endPTS)?e:NaN).toFixed(3)}] > buffer:${h?function(t){let s="";const i=t.length;for(let e=0;e<i;e++)s+=`[${t.start(e).toFixed(3)}-${t.end(e).toFixed(3)}]`;return s}(ei.getBuffered(h)):"(detached)"})`),this.state=mi,h&&(!this.loadedmetadata&&t.type==ss&&h.buffered.length&&(null==(n=this.fragCurrent)?void 0:n.sn)===(null==(r=this.fragPrevious)?void 0:r.sn)&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())}seekToStartPos(){}_handleFragmentLoadComplete(t){const{transmuxer:s}=this;if(!s)return;const{frag:i,part:e,partsLoaded:n}=t,r=!n||0===n.length||n.some((t=>!t)),h=new ni(i.level,i.sn,i.stats.chunkCount+1,0,e?e.index:-1,!r);s.flush(h)}_handleFragmentLoadProgress(t){}_doFragLoad(t,s,i=null,e){var n;const r=null==s?void 0:s.details;if(!this.levels||!r)throw new Error(`frag load aborted, missing level${r?"":" detail"}s`);let h=null;if(!t.encrypted||null!=(n=t.decryptdata)&&n.key?!t.encrypted&&r.encryptedFragments.length&&this.keyLoader.loadClear(t,r.encryptedFragments):(this.log(`Loading key for ${t.sn} of [${r.startSN}-${r.endSN}], ${"[stream-controller]"===this.logPrefix?"level":"track"} ${t.level}`),this.state=gi,this.fragCurrent=t,h=this.keyLoader.load(t).then((t=>{if(!this.fragContextChanged(t.frag))return this.hls.trigger(d.KEY_LOADED,t),this.state===gi&&(this.state=mi),t})),this.hls.trigger(d.KEY_LOADING,{frag:t}),null===this.fragCurrent&&(h=Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING")))),i=Math.max(t.start,i||0),this.config.lowLatencyMode&&"initSegment"!==t.sn){const n=r.partList;if(n&&e){i>t.end&&r.fragmentHint&&(t=r.fragmentHint);const o=this.getNextPart(n,t,i);if(o>-1){const a=n[o];let l;return this.log(`Loading part sn: ${t.sn} p: ${a.index} cc: ${t.cc} of playlist [${r.startSN}-${r.endSN}] parts [0-${o}-${n.length-1}] ${"[stream-controller]"===this.logPrefix?"level":"track"}: ${t.level}, target: ${parseFloat(i.toFixed(3))}`),this.nextLoadPosition=a.start+a.duration,this.state=vi,l=h?h.then((i=>!i||this.fragContextChanged(i.frag)?null:this.doFragPartsLoad(t,a,s,e))).catch((t=>this.handleFragLoadError(t))):this.doFragPartsLoad(t,a,s,e).catch((t=>this.handleFragLoadError(t))),this.hls.trigger(d.FRAG_LOADING,{frag:t,part:a,targetBufferTime:i}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING parts")):l}if(!t.url||this.loadedEndOfParts(n,i))return Promise.resolve(null)}}this.log(`Loading fragment ${t.sn} cc: ${t.cc} ${r?"of ["+r.startSN+"-"+r.endSN+"] ":""}${"[stream-controller]"===this.logPrefix?"level":"track"}: ${t.level}, target: ${parseFloat(i.toFixed(3))}`),u(t.sn)&&!this.bitrateTest&&(this.nextLoadPosition=t.start+t.duration),this.state=vi;const o=this.config.progressive;let a;return a=o&&h?h.then((s=>!s||this.fragContextChanged(null==s?void 0:s.frag)?null:this.fragmentLoader.load(t,e))).catch((t=>this.handleFragLoadError(t))):Promise.all([this.fragmentLoader.load(t,o?e:void 0),h]).then((([t])=>(!o&&t&&e&&e(t),t))).catch((t=>this.handleFragLoadError(t))),this.hls.trigger(d.FRAG_LOADING,{frag:t,targetBufferTime:i}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING")):a}doFragPartsLoad(t,s,i,e){return new Promise(((n,r)=>{var h;const o=[],a=null==(h=i.details)?void 0:h.partList,l=s=>{this.fragmentLoader.loadPart(t,s,e).then((e=>{o[s.index]=e;const r=e.part;this.hls.trigger(d.FRAG_LOADED,e);const h=$s(i,t.sn,s.index+1)||As(a,t.sn,s.index+1);if(!h)return n({frag:t,part:r,partsLoaded:o});l(h)})).catch(r)};l(s)}))}handleFragLoadError(t){if("data"in t){const s=t.data;t.data&&s.details===m.INTERNAL_ABORTED?this.handleFragLoadAborted(s.frag,s.part):this.hls.trigger(d.ERROR,s)}else this.hls.trigger(d.ERROR,{type:f.OTHER_ERROR,details:m.INTERNAL_EXCEPTION,err:t,error:t,fatal:!0});return null}_handleTransmuxerFlush(t){const s=this.getCurrentContext(t);if(!s||this.state!==wi)return void(this.fragCurrent||this.state===fi||this.state===Si||(this.state=mi));const{frag:i,part:e,level:n}=s,r=self.performance.now();i.stats.parsing.end=r,e&&(e.stats.parsing.end=r),this.updateLevelTiming(i,e,n,t.partial)}getCurrentContext(t){const{levels:s,fragCurrent:i}=this,{level:e,sn:n,part:r}=t;if(null==s||!s[e])return this.warn(`Levels object was unset while buffering fragment ${n} of level ${e}. The current chunk will not be buffered.`),null;const h=s[e],o=r>-1?$s(h,n,r):null,a=o?o.fragment:function(t,s,i){if(null==t||!t.details)return null;const e=t.details;let n=e.fragments[s-e.startSN];return n||(n=e.fragmentHint,n&&n.sn===s?n:s<e.startSN&&i&&i.sn===s?i:null)}(h,n,i);return a?(i&&i!==a&&(a.stats=i.stats),{frag:a,part:o,level:h}):null}bufferFragmentData(t,s,i,e){var n;if(!t||this.state!==wi)return;const{data1:r,data2:h}=t;let o=r;r&&h&&(o=Tt(r,h)),null!=(n=o)&&n.length&&(this.hls.trigger(d.BUFFER_APPENDING,{type:t.type,frag:s,part:i,chunkMeta:e,parent:s.type,data:o}),t.dropped&&t.independent&&!i&&this.flushBufferGap(s))}flushBufferGap(t){const s=this.media;if(!s)return;if(!ei.isBuffered(s,s.currentTime))return void this.flushMainBuffer(0,t.start);const i=s.currentTime,e=ei.bufferInfo(s,i,0),n=Math.min(2*this.config.maxFragLookUpTolerance,.25*t.duration),r=Math.max(Math.min(t.start-n,e.end-n),i+n);t.start-r>n&&this.flushMainBuffer(r,t.start)}getFwdBufferInfo(t,s){const i=this.getLoadPosition();return u(i)?this.getFwdBufferInfoAtPos(t,i,s):null}getFwdBufferInfoAtPos(t,s,i){const{config:{maxBufferHole:e}}=this,n=ei.bufferInfo(t,s,e);if(0===n.len&&void 0!==n.nextStart){const r=this.fragmentTracker.getBufferedFrag(s,i);if(r&&n.nextStart<r.end)return ei.bufferInfo(t,s,Math.max(n.nextStart,e))}return n}getMaxBufferLength(t){const{config:s}=this;let i;return i=t?Math.max(8*s.maxBufferSize/t,s.maxBufferLength):s.maxBufferLength,Math.min(i,s.maxMaxBufferLength)}reduceMaxBufferLength(t){const s=this.config;return s.maxMaxBufferLength>=(t||s.maxBufferLength)&&(s.maxMaxBufferLength/=2,this.warn(`Reduce max buffer length to ${s.maxMaxBufferLength}s`),!0)}getAppendedFrag(t,s=ss){const i=this.fragmentTracker.getAppendedFrag(t,ss);return i&&"fragment"in i?i.fragment:i}getNextFragment(t,s){const i=s.fragments,e=i.length;if(!e)return null;const{config:n}=this,r=i[0].start;let h;if(s.live){const r=n.initialLiveManifestSize;if(e<r)return this.warn(`Not enough fragments to start playback (have: ${e}, need: ${r})`),null;s.PTSKnown||this.startFragRequested||-1!==this.startPosition||(h=this.getInitialLiveFragment(s,i),this.startPosition=h?this.hls.liveSyncPosition||h.start:t)}else t<=r&&(h=i[0]);return h||(h=this.getFragmentAtPosition(t,n.lowLatencyMode?s.partEnd:s.fragmentEnd,s)),this.mapToInitFragWhenRequired(h)}isLoopLoading(t,s){const i=this.fragmentTracker.getState(t);return(i===Vs||i===Gs&&!!t.gap)&&this.nextLoadPosition>s}getNextFragmentLoopLoading(t,s,i,e,n){const r=t.gap,h=this.getNextFragment(this.nextLoadPosition,s);if(null===h)return h;if(t=h,r&&t&&!t.gap&&i.nextStart){const s=this.getFwdBufferInfoAtPos(this.mediaBuffer?this.mediaBuffer:this.media,i.nextStart,e);if(null!==s&&i.len+s.len>=n)return this.log(`buffer full after gaps in "${e}" playlist starting at sn: ${t.sn}`),null}return t}mapToInitFragWhenRequired(t){return null==t||!t.initSegment||null!=t&&t.initSegment.data||this.bitrateTest?t:t.initSegment}getNextPart(t,s,i){let e=-1,n=!1,r=!0;for(let h=0,o=t.length;h<o;h++){const o=t[h];if(r=r&&!o.independent,e>-1&&i<o.start)break;const a=o.loaded;a?e=-1:(n||o.independent||r)&&o.fragment===s&&(e=h),n=a}return e}loadedEndOfParts(t,s){const i=t[t.length-1];return i&&s>i.start&&i.loaded}getInitialLiveFragment(t,s){const i=this.fragPrevious;let e=null;if(i){if(t.hasProgramDateTime&&(this.log(`Live playlist, switching playlist, load frag with same PDT: ${i.programDateTime}`),e=function(t,s,i){if(null===s||!Array.isArray(t)||!t.length||!u(s))return null;if(s<(t[0].programDateTime||0))return null;if(s>=(t[t.length-1].endProgramDateTime||0))return null;i=i||0;for(let e=0;e<t.length;++e){const n=t[e];if(Os(s,i,n))return n}return null}(s,i.endProgramDateTime,this.config.maxFragLookUpTolerance)),!e){const n=i.sn+1;if(n>=t.startSN&&n<=t.endSN){const r=s[n-t.startSN];i.cc===r.cc&&(e=r,this.log(`Live playlist, switching playlist, load frag with next SN: ${e.sn}`))}e||(e=function(t,s){return Cs(t,(t=>t.cc<s?1:t.cc>s?-1:0))}(s,i.cc),e&&this.log(`Live playlist, switching playlist, load frag with same CC: ${e.sn}`))}}else{const s=this.hls.liveSyncPosition;null!==s&&(e=this.getFragmentAtPosition(s,this.bitrateTest?t.fragmentEnd:t.edge,t))}return e}getFragmentAtPosition(t,s,i){const{config:e}=this;let{fragPrevious:n}=this,{fragments:r,endSN:h}=i;const{fragmentHint:o}=i,a=e.maxFragLookUpTolerance,l=i.partList,c=!!(e.lowLatencyMode&&null!=l&&l.length&&o);let u;if(c&&o&&!this.bitrateTest&&(r=r.concat(o),h=o.sn),u=t<s?Ps(n,r,t,t>s-a?0:a):r[r.length-1],u){const t=u.sn-i.startSN,s=this.fragmentTracker.getState(u);if((s===Vs||s===Gs&&u.gap)&&(n=u),n&&u.sn===n.sn&&(!c||l[0].fragment.sn>u.sn)&&n&&u.level===n.level){const s=r[t+1];u=u.sn<h&&this.fragmentTracker.getState(s)!==Vs?s:null}}return u}synchronizeToLiveEdge(t){const{config:s,media:i}=this;if(!i)return;const e=this.hls.liveSyncPosition,n=i.currentTime,r=t.edge,h=n>=t.fragments[0].start-s.maxFragLookUpTolerance&&n<=r;null!==e&&i.duration>e&&(n<e||!h)&&(!h&&i.readyState<4||n<r-(void 0!==s.liveMaxLatencyDuration?s.liveMaxLatencyDuration:s.liveMaxLatencyDurationCount*t.targetduration))&&(this.loadedmetadata||(this.nextLoadPosition=e),i.readyState&&(this.warn(`Playback: ${n.toFixed(3)} is located too far from the end of live sliding playlist: ${r}, reset currentTime to : ${e.toFixed(3)}`),i.currentTime=e))}alignPlaylists(t,s){const{levels:i,levelLastLoaded:e,fragPrevious:n}=this,r=null!==e?i[e]:null,h=t.fragments.length;if(!h)return this.warn("No fragments in live playlist"),0;const o=t.fragments[0].start,a=!s,l=t.alignedSliding&&u(o);if(a||!l&&!o){!function(t,s,i){s&&(function(t,s,i){if(function(t,s,i){return!(!s.details||!(i.endCC>i.startCC||t&&t.cc<i.startCC))}(t,i,s)){const t=function(t,s){const i=t.fragments,e=s.fragments;if(!e.length||!i.length)return void y.log("No fragments to align");const n=ri(i,e[0].cc);if(n&&(!n||n.startPTS))return n;y.log("No frag in previous level to align on")}(i.details,s);t&&u(t.start)&&(y.log(`Adjusting PTS using last level due to CC increase within current level ${s.url}`),oi(t.start,s))}}(t,i,s),!i.alignedSliding&&s.details&&function(t,s){if(!s.fragments.length||!t.hasProgramDateTime||!s.hasProgramDateTime)return;const i=s.fragments[0].programDateTime,e=t.fragments[0].programDateTime,n=(e-i)/1e3+s.fragments[0].start;n&&u(n)&&(y.log(`Adjusting PTS using programDateTime delta ${e-i}ms, sliding:${n.toFixed(3)} ${t.url} `),oi(n,t))}(i,s.details),i.alignedSliding||!s.details||i.skippedSegments||Es(s.details,i))}(n,r,t);const i=t.fragments[0].start;return this.log(`Live playlist sliding: ${i.toFixed(2)} start-sn: ${s?s.startSN:"na"}->${t.startSN} prev-sn: ${n?n.sn:"na"} fragments: ${h}`),i}return o}waitForCdnTuneIn(t){return t.live&&t.canBlockReload&&t.partTarget&&t.tuneInGoal>Math.max(t.partHoldBack,3*t.partTarget)}setStartPosition(t,s){let i=this.startPosition;if(i<s&&(i=-1),-1===i||-1===this.lastCurrentTime){const e=null!==this.startTimeOffset,n=e?this.startTimeOffset:t.startTimeOffset;null!==n&&u(n)?(i=s+n,n<0&&(i+=t.totalduration),i=Math.min(Math.max(s,i),s+t.totalduration),this.log(`Start time offset ${n} found in ${e?"multivariant":"media"} playlist, adjust startPosition to ${i}`),this.startPosition=i):t.live?i=this.hls.liveSyncPosition||s:this.startPosition=i=0,this.lastCurrentTime=i}this.nextLoadPosition=i}getLoadPosition(){const{media:t}=this;let s=0;return this.loadedmetadata&&t?s=t.currentTime:this.nextLoadPosition&&(s=this.nextLoadPosition),s}handleFragLoadAborted(t,s){this.transmuxer&&"initSegment"!==t.sn&&t.stats.aborted&&(this.warn(`Fragment ${t.sn}${s?" part "+s.index:""} of level ${t.level} was aborted`),this.resetFragmentLoading(t))}resetFragmentLoading(t){this.fragCurrent&&(this.fragContextChanged(t)||this.state===pi)||(this.state=mi)}onFragmentOrKeyLoadError(t,s){if(s.chunkMeta&&!s.frag){const t=this.getCurrentContext(s.chunkMeta);t&&(s.frag=t.frag)}const i=s.frag;if(!i||i.type!==t||!this.levels)return;var e;if(this.fragContextChanged(i))return void this.warn(`Frag load error must match current frag to retry ${i.url} > ${null==(e=this.fragCurrent)?void 0:e.url}`);const n=s.details===m.FRAG_GAP;n&&this.fragmentTracker.fragBuffered(i,!0);const r=s.errorAction,{action:h,retryCount:o=0,retryConfig:a}=r||{};if(r&&5===h&&a){this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition);const e=Ds(a,o);this.warn(`Fragment ${i.sn} of ${t} ${i.level} errored with ${s.details}, retrying loading ${o+1}/${a.maxNumRetry} in ${e}ms`),r.resolved=!0,this.retryDate=self.performance.now()+e,this.state=pi}else a&&r?(this.resetFragmentErrors(t),o<a.maxNumRetry?n||(r.resolved=!0):y.warn(`${s.details} reached or exceeded max retry (${o})`)):this.state=Si;this.tickImmediate()}reduceLengthAndFlushBuffer(t){if(this.state===wi||this.state===bi){const s=t.parent,i=this.getFwdBufferInfo(this.mediaBuffer,s),e=i&&i.len>.5;e&&this.reduceMaxBufferLength(i.len);const n=!e;return n&&this.warn(`Buffer full error while media.currentTime is not buffered, flush ${s} buffer`),t.frag&&(this.fragmentTracker.removeFragment(t.frag),this.nextLoadPosition=t.frag.start),this.resetLoadingState(),n}return!1}resetFragmentErrors(t){t===is&&(this.fragCurrent=null),this.loadedmetadata||(this.startFragRequested=!1),this.state!==fi&&(this.state=mi)}afterBufferFlushed(t,s,i){if(!t)return;const e=ei.getBuffered(t);this.fragmentTracker.detectEvictedFragments(s,e,i),this.state===Ti&&this.resetLoadingState()}resetLoadingState(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state=mi}resetStartWhenNotLoaded(t){if(!this.loadedmetadata){this.startFragRequested=!1;const s=this.levels?this.levels[t].details:null;null!=s&&s.live?(this.startPosition=-1,this.setStartPosition(s,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}}resetWhenMissingContext(t){this.warn(`The loading context changed while buffering fragment ${t.sn} of level ${t.level}. This chunk will not be buffered.`),this.removeUnbufferedFrags(),this.resetStartWhenNotLoaded(t.level),this.resetLoadingState()}removeUnbufferedFrags(t=0){this.fragmentTracker.removeFragmentsInRange(t,1/0,this.playlistType,!1,!0)}updateLevelTiming(t,s,i,e){var n;const r=i.details;if(r){if(Object.keys(t.elementaryStreams).reduce(((s,n)=>{const h=t.elementaryStreams[n];if(h){const o=h.endPTS-h.startPTS;if(o<=0)return this.warn(`Could not parse fragment ${t.sn} ${n} duration reliably (${o})`),s||!1;const a=e?0:Ss(r,t,h.startPTS,h.endPTS,h.startDTS,h.endDTS);return this.hls.trigger(d.LEVEL_PTS_UPDATED,{details:r,level:i,drift:a,type:n,frag:t,start:h.startPTS,end:h.endPTS}),!0}return s}),!1))i.fragmentError=0;else if(null===(null==(n=this.transmuxer)?void 0:n.error)){const s=new Error(`Found no media in fragment ${t.sn} of level ${i.id} resetting transmuxer to fallback to playlist timing`);if(this.warn(s.message),this.hls.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.FRAG_PARSING_ERROR,fatal:!1,error:s,frag:t,reason:`Found no media in msn ${t.sn} of level "${i.url}"`}),!this.hls)return;this.resetTransmuxer()}this.state=bi,this.hls.trigger(d.FRAG_PARSED,{frag:t,part:s})}else this.warn("level.details undefined")}resetTransmuxer(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)}recoverWorkerError(t){"demuxerWorker"===t.event&&(this.resetTransmuxer(),this.resetLoadingState())}set state(t){const s=this._state;s!==t&&(this._state=t,this.log(`${s}->${t}`))}get state(){return this._state}}function Ai(){return self.SourceBuffer||self.WebKitSourceBuffer}function Li(t="",s=9e4){return{type:t,id:-1,pid:-1,inputTimeScale:s,sequenceNumber:-1,samples:[],dropped:0}}class Mi{constructor(){this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.basePTS=null,this.initPTS=null,this.lastPTS=null}resetInitSegment(t,s,i,e){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}}resetTimeStamp(t){this.initPTS=t,this.resetContiguity()}resetContiguity(){this.basePTS=null,this.lastPTS=null,this.frameIndex=0}canParse(t,s){return!1}appendFrame(t,s,i){}demux(t,s){this.cachedData&&(t=Tt(this.cachedData,t),this.cachedData=null);let i,e=X(t,0),n=e?e.length:0;const r=this._audioTrack,h=this._id3Track,o=e?(t=>{const s=J(t);for(let t=0;t<s.length;t++){const i=s[t];if(z(i))return et(i)}})(e):void 0,a=t.length;for((null===this.basePTS||0===this.frameIndex&&u(o))&&(this.basePTS=Di(o,s,this.initPTS),this.lastPTS=this.basePTS),null===this.lastPTS&&(this.lastPTS=this.basePTS),e&&e.length>0&&h.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:e,type:us,duration:Number.POSITIVE_INFINITY});n<a;){if(this.canParse(t,n)){const s=this.appendFrame(r,t,n);s?(this.frameIndex++,this.lastPTS=s.sample.pts,n+=s.length,i=n):n=a}else Y(t,n)?(e=X(t,n),h.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:e,type:us,duration:Number.POSITIVE_INFINITY}),n+=e.length,i=n):n++;if(n===a&&i!==a){const s=G(t,i);this.cachedData=this.cachedData?Tt(this.cachedData,s):s}}return{audioTrack:r,videoTrack:Li(),id3Track:h,textTrack:Li()}}demuxSampleAes(t,s,i){return Promise.reject(new Error(`[${this}] This demuxer does not support Sample-AES decryption`))}flush(t){const s=this.cachedData;return s&&(this.cachedData=null,this.demux(s,0)),{audioTrack:this._audioTrack,videoTrack:Li(),id3Track:this._id3Track,textTrack:Li()}}destroy(){}}const Di=(t,s,i)=>u(t)?90*t:9e4*s+(i?9e4*i.baseTime/i.timescale:0);function xi(t,s){return 255===t[s]&&240==(246&t[s+1])}function Ii(t,s){return 1&t[s+1]?7:9}function Ci(t,s){return(3&t[s+3])<<11|t[s+4]<<3|(224&t[s+5])>>>5}function Pi(t,s){return s+1<t.length&&xi(t,s)}function Ri(t,s){if(Pi(t,s)){const i=Ii(t,s);if(s+i>=t.length)return!1;const e=Ci(t,s);if(e<=i)return!1;const n=s+e;return n===t.length||Pi(t,n)}return!1}function Oi(t,s,i,e,n){if(!t.samplerate){const r=function(t,s,i,e){let n,r,h,o;const a=navigator.userAgent.toLowerCase(),l=e,c=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];n=1+((192&s[i+2])>>>6);const u=(60&s[i+2])>>>2;if(!(u>c.length-1))return h=(1&s[i+2])<<2,h|=(192&s[i+3])>>>6,y.log(`manifest codec:${e}, ADTS type:${n}, samplingIndex:${u}`),/firefox/i.test(a)?u>=6?(n=5,o=new Array(4),r=u-3):(n=2,o=new Array(2),r=u):-1!==a.indexOf("android")?(n=2,o=new Array(2),r=u):(n=5,o=new Array(4),e&&(-1!==e.indexOf("mp4a.40.29")||-1!==e.indexOf("mp4a.40.5"))||!e&&u>=6?r=u-3:((e&&-1!==e.indexOf("mp4a.40.2")&&(u>=6&&1===h||/vivaldi/i.test(a))||!e&&1===h)&&(n=2,o=new Array(2)),r=u)),o[0]=n<<3,o[0]|=(14&u)>>1,o[1]|=(1&u)<<7,o[1]|=h<<3,5===n&&(o[1]|=(14&r)>>1,o[2]=(1&r)<<7,o[2]|=8,o[3]=0),{config:o,samplerate:c[u],channelCount:h,codec:"mp4a.40."+n,manifestCodec:l};t.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.FRAG_PARSING_ERROR,fatal:!0,reason:`invalid ADTS sampling index:${u}`})}(s,i,e,n);if(!r)return;t.config=r.config,t.samplerate=r.samplerate,t.channelCount=r.channelCount,t.codec=r.codec,t.manifestCodec=r.manifestCodec,y.log(`parsed codec:${t.codec}, rate:${r.samplerate}, channels:${r.channelCount}`)}}function Ni(t){return 9216e4/t}function Ui(t,s,i,e,n){const r=e+n*Ni(t.samplerate),h=function(t,s){const i=Ii(t,s);if(s+i<=t.length){const e=Ci(t,s)-i;if(e>0)return{headerLength:i,frameLength:e}}}(s,i);let o;if(h){const{frameLength:e,headerLength:n}=h,a=n+e,l=Math.max(0,i+a-s.length);l?(o=new Uint8Array(a-n),o.set(s.subarray(i+n,s.length),0)):o=s.subarray(i+n,i+a);const c={unit:o,pts:r};return l||t.samples.push(c),{sample:c,length:a,missing:l}}const a=s.length-i;return o=new Uint8Array(a),o.set(s.subarray(i,s.length),0),{sample:{unit:o,pts:r},length:a,missing:-1}}const Fi=/\/emsg[-/]ID3/i;let Bi=null;const _i=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],ji=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],Ki=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],Hi=[0,1,1,4];function Gi(t,s,i,e,n){if(i+24>s.length)return;const r=Vi(s,i);if(r&&i+r.frameLength<=s.length){const h=e+n*(9e4*r.samplesPerFrame/r.sampleRate),o={unit:s.subarray(i,i+r.frameLength),pts:h,dts:h};return t.config=[],t.channelCount=r.channelCount,t.samplerate=r.sampleRate,t.samples.push(o),{sample:o,length:r.frameLength,missing:0}}}function Vi(t,s){const i=t[s+1]>>3&3,e=t[s+1]>>1&3,n=t[s+2]>>4&15,r=t[s+2]>>2&3;if(1!==i&&0!==n&&15!==n&&3!==r){const h=t[s+3]>>6,o=1e3*_i[14*(3===i?3-e:3===e?3:4)+n-1],a=ji[3*(3===i?0:2===i?1:2)+r],l=3===h?1:2,c=Ki[i][e],u=Hi[e],d=8*c*u,f=Math.floor(c*o/a+(t[s+2]>>1&1))*u;if(null===Bi){const t=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Bi=t?parseInt(t[1]):0}return!!Bi&&Bi<=87&&2===e&&o>=224e3&&0===h&&(t[s+3]=128|t[s+3]),{sampleRate:a,channelCount:l,frameLength:f,samplesPerFrame:d}}}function Wi(t,s){return 255===t[s]&&224==(224&t[s+1])&&0!=(6&t[s+1])}function Xi(t,s){return s+1<t.length&&Wi(t,s)}function qi(t,s){if(s+1<t.length&&Wi(t,s)){const i=4,e=Vi(t,s);let n=i;null!=e&&e.frameLength&&(n=e.frameLength);const r=s+n;return r===t.length||Xi(t,r)}return!1}class Yi{constructor(t){this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=t,this.bytesAvailable=t.byteLength,this.word=0,this.bitsAvailable=0}loadWord(){const t=this.data,s=this.bytesAvailable,i=t.byteLength-s,e=new Uint8Array(4),n=Math.min(4,s);if(0===n)throw new Error("no bytes available");e.set(t.subarray(i,i+n)),this.word=new DataView(e.buffer).getUint32(0),this.bitsAvailable=8*n,this.bytesAvailable-=n}skipBits(t){let s;t=Math.min(t,8*this.bytesAvailable+this.bitsAvailable),this.bitsAvailable>t?(this.word<<=t,this.bitsAvailable-=t):(s=(t-=this.bitsAvailable)>>3,t-=s<<3,this.bytesAvailable-=s,this.loadWord(),this.word<<=t,this.bitsAvailable-=t)}readBits(t){let s=Math.min(this.bitsAvailable,t);const i=this.word>>>32-s;if(t>32&&y.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=s,this.bitsAvailable>0)this.word<<=s;else{if(!(this.bytesAvailable>0))throw new Error("no bits available");this.loadWord()}return s=t-s,s>0&&this.bitsAvailable?i<<s|this.readBits(s):i}skipLZ(){let t;for(t=0;t<this.bitsAvailable;++t)if(0!=(this.word&2147483648>>>t))return this.word<<=t,this.bitsAvailable-=t,t;return this.loadWord(),t+this.skipLZ()}skipUEG(){this.skipBits(1+this.skipLZ())}skipEG(){this.skipBits(1+this.skipLZ())}readUEG(){const t=this.skipLZ();return this.readBits(t+1)-1}readEG(){const t=this.readUEG();return 1&t?1+t>>>1:-1*(t>>>1)}readBoolean(){return 1===this.readBits(1)}readUByte(){return this.readBits(8)}readUShort(){return this.readBits(16)}readUInt(){return this.readBits(32)}skipScalingList(t){let s,i=8,e=8;for(let n=0;n<t;n++)0!==e&&(s=this.readEG(),e=(i+s+256)%256),i=0===e?i:e}readSPS(){let t,s,i,e=0,n=0,r=0,h=0;const o=this.readUByte.bind(this),a=this.readBits.bind(this),l=this.readUEG.bind(this),c=this.readBoolean.bind(this),u=this.skipBits.bind(this),d=this.skipEG.bind(this),f=this.skipUEG.bind(this),m=this.skipScalingList.bind(this);o();const g=o();if(a(5),u(3),o(),f(),100===g||110===g||122===g||244===g||44===g||83===g||86===g||118===g||128===g){const t=l();if(3===t&&u(1),f(),f(),u(1),c())for(s=3!==t?8:12,i=0;i<s;i++)c()&&m(i<6?16:64)}f();const v=l();if(0===v)l();else if(1===v)for(u(1),d(),d(),t=l(),i=0;i<t;i++)d();f(),u(1);const p=l(),y=l(),w=a(1);0===w&&u(1),u(1),c()&&(e=l(),n=l(),r=l(),h=l());let b=[1,1];if(c()&&c())switch(o()){case 1:b=[1,1];break;case 2:b=[12,11];break;case 3:b=[10,11];break;case 4:b=[16,11];break;case 5:b=[40,33];break;case 6:b=[24,11];break;case 7:b=[20,11];break;case 8:b=[32,11];break;case 9:b=[80,33];break;case 10:b=[18,11];break;case 11:b=[15,11];break;case 12:b=[64,33];break;case 13:b=[160,99];break;case 14:b=[4,3];break;case 15:b=[3,2];break;case 16:b=[2,1];break;case 255:b=[o()<<8|o(),o()<<8|o()]}return{width:Math.ceil(16*(p+1)-2*e-2*n),height:(2-w)*(y+1)*16-(w?2:4)*(r+h),pixelRatio:b}}readSliceType(){return this.readUByte(),this.readUEG(),this.readUEG()}}class zi{constructor(t,s,i){this.keyData=void 0,this.decrypter=void 0,this.keyData=i,this.decrypter=new di(s,{removePKCS7Padding:!1})}decryptBuffer(t){return this.decrypter.decrypt(t,this.keyData.key.buffer,this.keyData.iv.buffer)}decryptAacSample(t,s,i){const e=t[s].unit;if(e.length<=16)return;const n=e.subarray(16,e.length-e.length%16),r=n.buffer.slice(n.byteOffset,n.byteOffset+n.length);this.decryptBuffer(r).then((n=>{const r=new Uint8Array(n);e.set(r,16),this.decrypter.isSync()||this.decryptAacSamples(t,s+1,i)}))}decryptAacSamples(t,s,i){for(;;s++){if(s>=t.length)return void i();if(!(t[s].unit.length<32||(this.decryptAacSample(t,s,i),this.decrypter.isSync())))return}}getAvcEncryptedData(t){const s=16*Math.floor((t.length-48)/160)+16,i=new Int8Array(s);let e=0;for(let s=32;s<t.length-16;s+=160,e+=16)i.set(t.subarray(s,s+16),e);return i}getAvcDecryptedUnit(t,s){const i=new Uint8Array(s);let e=0;for(let s=32;s<t.length-16;s+=160,e+=16)t.set(i.subarray(e,e+16),s);return t}decryptAvcSample(t,s,i,e,n){const r=$t(n.data),h=this.getAvcEncryptedData(r);this.decryptBuffer(h.buffer).then((h=>{n.data=this.getAvcDecryptedUnit(r,h),this.decrypter.isSync()||this.decryptAvcSamples(t,s,i+1,e)}))}decryptAvcSamples(t,s,i,e){if(t instanceof Uint8Array)throw new Error("Cannot decrypt samples of type Uint8Array");for(;;s++,i=0){if(s>=t.length)return void e();const n=t[s].units;for(;!(i>=n.length);i++){const r=n[i];if(!(r.data.length<=48||1!==r.type&&5!==r.type||(this.decryptAvcSample(t,s,i,e,r),this.decrypter.isSync())))return}}}}const Qi=188;class Ji{constructor(t,s,i){this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._pmtId=-1,this._avcTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.observer=t,this.config=s,this.typeSupported=i}static probe(t){const s=Ji.syncOffset(t);return s>0&&y.warn(`MPEG2-TS detected but first sync word found @ offset ${s}`),-1!==s}static syncOffset(t){const s=t.length,i=Math.min(940,t.length-Qi)+1;let e=0;for(;e<i;){let n=!1;for(let r=e;r<s&&71===t[r];r+=Qi)if(n||0!==te(t,r)||(n=!0),n&&r+Qi>i)return e;e++}return-1}static createTrack(t,s){return{container:"video"===t||"audio"===t?"video/mp2t":void 0,type:t,id:ct[t],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===t?s:void 0}}resetInitSegment(t,s,i,e){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack=Ji.createTrack("video"),this._audioTrack=Ji.createTrack("audio",e),this._id3Track=Ji.createTrack("id3"),this._txtTrack=Ji.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.audioCodec=s,this.videoCodec=i,this._duration=e}resetTimeStamp(){}resetContiguity(){const{_audioTrack:t,_avcTrack:s,_id3Track:i}=this;t&&(t.pesData=null),s&&(s.pesData=null),i&&(i.pesData=null),this.aacOverFlow=null,this.avcSample=null,this.remainderData=null}demux(t,s,i=!1,e=!1){let n;i||(this.sampleAes=null);const r=this._avcTrack,h=this._audioTrack,o=this._id3Track,a=this._txtTrack;let l=r.pid,c=r.pesData,u=h.pid,g=o.pid,v=h.pesData,p=o.pesData,w=null,b=this.pmtParsed,T=this._pmtId,S=t.length;if(this.remainderData&&(S=(t=Tt(this.remainderData,t)).length,this.remainderData=null),S<Qi&&!e)return this.remainderData=t,{audioTrack:h,videoTrack:r,id3Track:o,textTrack:a};const E=Math.max(0,Ji.syncOffset(t));S-=(S-E)%Qi,S<t.byteLength&&!e&&(this.remainderData=new Uint8Array(t.buffer,S,t.buffer.byteLength-S));let k=0;for(let s=E;s<S;s+=Qi)if(71===t[s]){const e=!!(64&t[s+1]),d=te(t,s);let f;if((48&t[s+3])>>4>1){if(f=s+5+t[s+4],f===s+Qi)continue}else f=s+4;switch(d){case l:e&&(c&&(n=ee(c))&&this.parseAVCPES(r,a,n,!1),c={data:[],size:0}),c&&(c.data.push(t.subarray(f,s+Qi)),c.size+=s+Qi-f);break;case u:if(e){if(v&&(n=ee(v)))switch(h.segmentCodec){case"aac":this.parseAACPES(h,n);break;case"mp3":this.parseMPEGPES(h,n)}v={data:[],size:0}}v&&(v.data.push(t.subarray(f,s+Qi)),v.size+=s+Qi-f);break;case g:e&&(p&&(n=ee(p))&&this.parseID3PES(o,n),p={data:[],size:0}),p&&(p.data.push(t.subarray(f,s+Qi)),p.size+=s+Qi-f);break;case 0:e&&(f+=t[f]+1),T=this._pmtId=se(t,f);break;case T:{e&&(f+=t[f]+1);const n=ie(t,f,this.typeSupported,i);l=n.avc,l>0&&(r.pid=l),u=n.audio,u>0&&(h.pid=u,h.segmentCodec=n.segmentCodec),g=n.id3,g>0&&(o.pid=g),null===w||b||(y.warn(`MPEG-TS PMT found at ${s} after unknown PID '${w}'. Backtracking to sync byte @${E} to parse all TS packets.`),w=null,s=E-188),b=this.pmtParsed=!0;break}case 17:case 8191:break;default:w=d}}else k++;if(k>0){const t=new Error(`Found ${k} TS packet/s that do not start with 0x47`);this.observer.emit(d.ERROR,d.ERROR,{type:f.MEDIA_ERROR,details:m.FRAG_PARSING_ERROR,fatal:!1,error:t,reason:t.message})}r.pesData=c,h.pesData=v,o.pesData=p;const $={audioTrack:h,videoTrack:r,id3Track:o,textTrack:a};return e&&this.extractRemainingSamples($),$}flush(){const{remainderData:t}=this;let s;return this.remainderData=null,s=t?this.demux(t,-1,!1,!0):{videoTrack:this._avcTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(s),this.sampleAes?this.decrypt(s,this.sampleAes):s}extractRemainingSamples(t){const{audioTrack:s,videoTrack:i,id3Track:e,textTrack:n}=t,r=i.pesData,h=s.pesData,o=e.pesData;let a;if(r&&(a=ee(r))?(this.parseAVCPES(i,n,a,!0),i.pesData=null):i.pesData=r,h&&(a=ee(h))){switch(s.segmentCodec){case"aac":this.parseAACPES(s,a);break;case"mp3":this.parseMPEGPES(s,a)}s.pesData=null}else null!=h&&h.size&&y.log("last AAC PES packet truncated,might overlap between fragments"),s.pesData=h;o&&(a=ee(o))?(this.parseID3PES(e,a),e.pesData=null):e.pesData=o}demuxSampleAes(t,s,i){const e=this.demux(t,i,!0,!this.config.progressive),n=this.sampleAes=new zi(this.observer,this.config,s);return this.decrypt(e,n)}decrypt(t,s){return new Promise((i=>{const{audioTrack:e,videoTrack:n}=t;e.samples&&"aac"===e.segmentCodec?s.decryptAacSamples(e.samples,0,(()=>{n.samples?s.decryptAvcSamples(n.samples,0,0,(()=>{i(t)})):i(t)})):n.samples&&s.decryptAvcSamples(n.samples,0,0,(()=>{i(t)}))}))}destroy(){this._duration=0}parseAVCPES(t,s,i,e){const n=this.parseAVCNALu(t,i.data);let r,h=this.avcSample,o=!1;i.data=null,h&&n.length&&!t.audFound&&(ne(h,t),h=this.avcSample=Zi(!1,i.pts,i.dts,"")),n.forEach((e=>{switch(e.type){case 1:{r=!0,h||(h=this.avcSample=Zi(!0,i.pts,i.dts,"")),h.frame=!0;const t=e.data;if(o&&t.length>4){const s=new Yi(t).readSliceType();2!==s&&4!==s&&7!==s&&9!==s||(h.key=!0)}break}case 5:r=!0,h||(h=this.avcSample=Zi(!0,i.pts,i.dts,"")),h.key=!0,h.frame=!0;break;case 6:r=!0,kt(e.data,1,i.pts,s.samples);break;case 7:if(r=!0,o=!0,!t.sps){const s=e.data,i=new Yi(s).readSPS();t.width=i.width,t.height=i.height,t.pixelRatio=i.pixelRatio,t.sps=[s],t.duration=this._duration;const n=s.subarray(1,4);let r="avc1.";for(let t=0;t<3;t++){let s=n[t].toString(16);s.length<2&&(s="0"+s),r+=s}t.codec=r}break;case 8:r=!0,t.pps||(t.pps=[e.data]);break;case 9:r=!1,t.audFound=!0,h&&ne(h,t),h=this.avcSample=Zi(!1,i.pts,i.dts,"");break;case 12:r=!0;break;default:r=!1,h&&(h.debug+="unknown NAL "+e.type+" ")}h&&r&&h.units.push(e)})),e&&h&&(ne(h,t),this.avcSample=null)}getLastNalUnit(t){var s;let i,e=this.avcSample;if(e&&0!==e.units.length||(e=t[t.length-1]),null!=(s=e)&&s.units){const t=e.units;i=t[t.length-1]}return i}parseAVCNALu(t,s){const i=s.byteLength;let e=t.naluState||0;const n=e,r=[];let h,o,a,l=0,c=-1,u=0;for(-1===e&&(c=0,u=31&s[0],e=0,l=1);l<i;)if(h=s[l++],e)if(1!==e)if(h)if(1===h){if(c>=0){const t={data:s.subarray(c,l-e-1),type:u};r.push(t)}else{const i=this.getLastNalUnit(t.samples);if(i&&(n&&l<=4-n&&i.state&&(i.data=i.data.subarray(0,i.data.byteLength-n)),o=l-e-1,o>0)){const t=new Uint8Array(i.data.byteLength+o);t.set(i.data,0),t.set(s.subarray(0,o),i.data.byteLength),i.data=t,i.state=0}}l<i?(a=31&s[l],c=l,u=a,e=0):e=-1}else e=0;else e=3;else e=h?0:2;else e=h?0:1;if(c>=0&&e>=0){const t={data:s.subarray(c,i),type:u,state:e};r.push(t)}if(0===r.length){const i=this.getLastNalUnit(t.samples);if(i){const t=new Uint8Array(i.data.byteLength+s.byteLength);t.set(i.data,0),t.set(s,i.data.byteLength),i.data=t}}return t.naluState=e,r}parseAACPES(t,s){let i=0;const e=this.aacOverFlow;let n,r,h,o=s.data;if(e){this.aacOverFlow=null;const s=e.missing,n=e.sample.unit.byteLength;if(-1===s){const t=new Uint8Array(n+o.byteLength);t.set(e.sample.unit,0),t.set(o,n),o=t}else{const r=n-s;e.sample.unit.set(o.subarray(0,s),r),t.samples.push(e.sample),i=e.missing}}for(n=i,r=o.length;n<r-1&&!Pi(o,n);n++);if(n!==i){let t;const s=n<r-1;t=s?`AAC PES did not start with ADTS header,offset:${n}`:"No ADTS header found in AAC PES";const i=new Error(t);if(y.warn(`parsing error: ${t}`),this.observer.emit(d.ERROR,d.ERROR,{type:f.MEDIA_ERROR,details:m.FRAG_PARSING_ERROR,fatal:!1,levelRetry:s,error:i,reason:t}),!s)return}if(Oi(t,this.observer,o,n,this.audioCodec),void 0!==s.pts)h=s.pts;else{if(!e)return void y.warn("[tsdemuxer]: AAC PES unknown PTS");{const s=Ni(t.samplerate);h=e.sample.pts+s}}let a,l=0;for(;n<r;){if(a=Ui(t,o,n,h,l),n+=a.length,a.missing){this.aacOverFlow=a;break}for(l++;n<r-1&&!Pi(o,n);n++);}}parseMPEGPES(t,s){const i=s.data,e=i.length;let n=0,r=0;const h=s.pts;if(void 0!==h)for(;r<e;)if(Xi(i,r)){const s=Gi(t,i,r,h,n);if(!s)break;r+=s.length,n++}else r++;else y.warn("[tsdemuxer]: MPEG PES unknown PTS")}parseID3PES(t,s){if(void 0===s.pts)return void y.warn("[tsdemuxer]: ID3 PES unknown PTS");const i=c({},s,{type:this._avcTrack?ds:us,duration:Number.POSITIVE_INFINITY});t.samples.push(i)}}function Zi(t,s,i,e){return{key:t,frame:!1,pts:s,dts:i,units:[],debug:e,length:0}}function te(t,s){return((31&t[s+1])<<8)+t[s+2]}function se(t,s){return(31&t[s+10])<<8|t[s+11]}function ie(t,s,i,e){const n={audio:-1,avc:-1,id3:-1,segmentCodec:"aac"},r=s+3+((15&t[s+1])<<8|t[s+2])-4;for(s+=12+((15&t[s+10])<<8|t[s+11]);s<r;){const r=te(t,s);switch(t[s]){case 207:if(!e){y.log("ADTS AAC with AES-128-CBC frame encryption found in unencrypted stream");break}case 15:-1===n.audio&&(n.audio=r);break;case 21:-1===n.id3&&(n.id3=r);break;case 219:if(!e){y.log("H.264 with AES-128-CBC slice encryption found in unencrypted stream");break}case 27:-1===n.avc&&(n.avc=r);break;case 3:case 4:!0!==i.mpeg&&!0!==i.mp3?y.log("MPEG audio found, not supported in this browser"):-1===n.audio&&(n.audio=r,n.segmentCodec="mp3");break;case 36:y.warn("Unsupported HEVC stream type found")}s+=5+((15&t[s+3])<<8|t[s+4])}return n}function ee(t){let s,i,e,n,r,h=0;const o=t.data;if(!t||0===t.size)return null;for(;o[0].length<19&&o.length>1;){const t=new Uint8Array(o[0].length+o[1].length);t.set(o[0]),t.set(o[1],o[0].length),o[0]=t,o.splice(1,1)}if(s=o[0],1===(s[0]<<16)+(s[1]<<8)+s[2]){if(i=(s[4]<<8)+s[5],i&&i>t.size-6)return null;const a=s[7];192&a&&(n=536870912*(14&s[9])+4194304*(255&s[10])+16384*(254&s[11])+128*(255&s[12])+(254&s[13])/2,64&a?(r=536870912*(14&s[14])+4194304*(255&s[15])+16384*(254&s[16])+128*(255&s[17])+(254&s[18])/2,n-r>54e5&&(y.warn(`${Math.round((n-r)/9e4)}s delta between PTS and DTS, align them`),n=r)):r=n),e=s[8];let l=e+9;if(t.size<=l)return null;t.size-=l;const c=new Uint8Array(t.size);for(let t=0,i=o.length;t<i;t++){s=o[t];let i=s.byteLength;if(l){if(l>i){l-=i;continue}s=s.subarray(l),i-=l,l=0}c.set(s,h),h+=i}return i&&(i-=e+3),{data:c,pts:n,dts:r,len:i}}return null}function ne(t,s){if(t.units.length&&t.frame){if(void 0===t.pts){const i=s.samples,e=i.length;if(!e)return void s.dropped++;{const s=i[e-1];t.pts=s.pts,t.dts=s.dts}}s.samples.push(t)}t.debug.length&&y.log(t.pts+"/"+t.dts+":"+t.debug)}class re{static getSilentFrame(t,s){if("mp4a.40.2"===t){if(1===s)return new Uint8Array([0,200,0,128,35,128]);if(2===s)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===s)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===s)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===s)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(6===s)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224])}else{if(1===s)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(2===s)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(3===s)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94])}}}const he=Math.pow(2,32)-1;class oe{static init(){let t;for(t in oe.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],mvex:[],mvhd:[],pasp:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]},oe.types)oe.types.hasOwnProperty(t)&&(oe.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);const s=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),i=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]);oe.HDLR_TYPES={video:s,audio:i};const e=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),n=new Uint8Array([0,0,0,0,0,0,0,0]);oe.STTS=oe.STSC=oe.STCO=n,oe.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),oe.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),oe.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),oe.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);const r=new Uint8Array([105,115,111,109]),h=new Uint8Array([97,118,99,49]),o=new Uint8Array([0,0,0,1]);oe.FTYP=oe.box(oe.types.ftyp,r,o,r,h),oe.DINF=oe.box(oe.types.dinf,oe.box(oe.types.dref,e))}static box(t,...s){let i=8,e=s.length;const n=e;for(;e--;)i+=s[e].byteLength;const r=new Uint8Array(i);for(r[0]=i>>24&255,r[1]=i>>16&255,r[2]=i>>8&255,r[3]=255&i,r.set(t,4),e=0,i=8;e<n;e++)r.set(s[e],i),i+=s[e].byteLength;return r}static hdlr(t){return oe.box(oe.types.hdlr,oe.HDLR_TYPES[t])}static mdat(t){return oe.box(oe.types.mdat,t)}static mdhd(t,s){s*=t;const i=Math.floor(s/(he+1)),e=Math.floor(s%(he+1));return oe.box(oe.types.mdhd,new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,e>>24,e>>16&255,e>>8&255,255&e,85,196,0,0]))}static mdia(t){return oe.box(oe.types.mdia,oe.mdhd(t.timescale,t.duration),oe.hdlr(t.type),oe.minf(t))}static mfhd(t){return oe.box(oe.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}static minf(t){return oe.box(oe.types.minf,"audio"===t.type?oe.box(oe.types.smhd,oe.SMHD):oe.box(oe.types.vmhd,oe.VMHD),oe.DINF,oe.stbl(t))}static moof(t,s,i){return oe.box(oe.types.moof,oe.mfhd(t),oe.traf(i,s))}static moov(t){let s=t.length;const i=[];for(;s--;)i[s]=oe.trak(t[s]);return oe.box.apply(null,[oe.types.moov,oe.mvhd(t[0].timescale,t[0].duration)].concat(i).concat(oe.mvex(t)))}static mvex(t){let s=t.length;const i=[];for(;s--;)i[s]=oe.trex(t[s]);return oe.box.apply(null,[oe.types.mvex,...i])}static mvhd(t,s){s*=t;const i=Math.floor(s/(he+1)),e=Math.floor(s%(he+1)),n=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,e>>24,e>>16&255,e>>8&255,255&e,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return oe.box(oe.types.mvhd,n)}static sdtp(t){const s=t.samples||[],i=new Uint8Array(4+s.length);let e,n;for(e=0;e<s.length;e++)n=s[e].flags,i[e+4]=n.dependsOn<<4|n.isDependedOn<<2|n.hasRedundancy;return oe.box(oe.types.sdtp,i)}static stbl(t){return oe.box(oe.types.stbl,oe.stsd(t),oe.box(oe.types.stts,oe.STTS),oe.box(oe.types.stsc,oe.STSC),oe.box(oe.types.stsz,oe.STSZ),oe.box(oe.types.stco,oe.STCO))}static avc1(t){let s,i,e,n=[],r=[];for(s=0;s<t.sps.length;s++)i=t.sps[s],e=i.byteLength,n.push(e>>>8&255),n.push(255&e),n=n.concat(Array.prototype.slice.call(i));for(s=0;s<t.pps.length;s++)i=t.pps[s],e=i.byteLength,r.push(e>>>8&255),r.push(255&e),r=r.concat(Array.prototype.slice.call(i));const h=oe.box(oe.types.avcC,new Uint8Array([1,n[3],n[4],n[5],255,224|t.sps.length].concat(n).concat([t.pps.length]).concat(r))),o=t.width,a=t.height,l=t.pixelRatio[0],c=t.pixelRatio[1];return oe.box(oe.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,o>>8&255,255&o,a>>8&255,255&a,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),h,oe.box(oe.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),oe.box(oe.types.pasp,new Uint8Array([l>>24,l>>16&255,l>>8&255,255&l,c>>24,c>>16&255,c>>8&255,255&c])))}static esds(t){const s=t.config.length;return new Uint8Array([0,0,0,0,3,23+s,0,1,0,4,15+s,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([s]).concat(t.config).concat([6,1,2]))}static mp4a(t){const s=t.samplerate;return oe.box(oe.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,s>>8&255,255&s,0,0]),oe.box(oe.types.esds,oe.esds(t)))}static mp3(t){const s=t.samplerate;return oe.box(oe.types[".mp3"],new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,s>>8&255,255&s,0,0]))}static stsd(t){return oe.box(oe.types.stsd,oe.STSD,"audio"===t.type?"mp3"===t.segmentCodec&&"mp3"===t.codec?oe.mp3(t):oe.mp4a(t):oe.avc1(t))}static tkhd(t){const s=t.id,i=t.duration*t.timescale,e=t.width,n=t.height,r=Math.floor(i/(he+1)),h=Math.floor(i%(he+1));return oe.box(oe.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,s>>24&255,s>>16&255,s>>8&255,255&s,0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,h>>24,h>>16&255,h>>8&255,255&h,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,e>>8&255,255&e,0,0,n>>8&255,255&n,0,0]))}static traf(t,s){const i=oe.sdtp(t),e=t.id,n=Math.floor(s/(he+1)),r=Math.floor(s%(he+1));return oe.box(oe.types.traf,oe.box(oe.types.tfhd,new Uint8Array([0,0,0,0,e>>24,e>>16&255,e>>8&255,255&e])),oe.box(oe.types.tfdt,new Uint8Array([1,0,0,0,n>>24,n>>16&255,n>>8&255,255&n,r>>24,r>>16&255,r>>8&255,255&r])),oe.trun(t,i.length+16+20+8+16+8+8),i)}static trak(t){return t.duration=t.duration||4294967295,oe.box(oe.types.trak,oe.tkhd(t),oe.mdia(t))}static trex(t){const s=t.id;return oe.box(oe.types.trex,new Uint8Array([0,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}static trun(t,s){const i=t.samples||[],e=i.length,n=12+16*e,r=new Uint8Array(n);let h,o,a,l,c,u;for(r.set(["video"===t.type?1:0,0,15,1,e>>>24&255,e>>>16&255,e>>>8&255,255&e,(s+=8+n)>>>24&255,s>>>16&255,s>>>8&255,255&s],0),h=0;h<e;h++)o=i[h],a=o.duration,l=o.size,c=o.flags,u=o.cts,r.set([a>>>24&255,a>>>16&255,a>>>8&255,255&a,l>>>24&255,l>>>16&255,l>>>8&255,255&l,c.isLeading<<2|c.dependsOn,c.isDependedOn<<6|c.hasRedundancy<<4|c.paddingValue<<1|c.isNonSync,61440&c.degradPrio,15&c.degradPrio,u>>>24&255,u>>>16&255,u>>>8&255,255&u],12+16*h);return oe.box(oe.types.trun,r)}static initSegment(t){oe.types||oe.init();const s=oe.moov(t),i=new Uint8Array(oe.FTYP.byteLength+s.byteLength);return i.set(oe.FTYP),i.set(s,oe.FTYP.byteLength),i}}function ae(t,s,i=1,e=!1){const n=t*s*i;return e?Math.round(n):n}function le(t,s=!1){return ae(t,1e3,1/9e4,s)}oe.types=void 0,oe.HDLR_TYPES=void 0,oe.STTS=void 0,oe.STSC=void 0,oe.STCO=void 0,oe.STSZ=void 0,oe.VMHD=void 0,oe.SMHD=void 0,oe.STSD=void 0,oe.FTYP=void 0,oe.DINF=void 0;let ce,ue=null,de=null;class fe{constructor(t,s,i,e=""){if(this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=null,this._initDTS=null,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.observer=t,this.config=s,this.typeSupported=i,this.ISGenerated=!1,null===ue){const t=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);ue=t?parseInt(t[1]):0}if(null===de){const t=navigator.userAgent.match(/Safari\/(\d+)/i);de=t?parseInt(t[1]):0}}destroy(){}resetTimeStamp(t){y.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=t}resetNextTimestamp(){y.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1}resetInitSegment(){y.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1}getVideoStartPts(t){let s=!1;const i=t.reduce(((t,i)=>{const e=i.pts-t;return e<-4294967296?(s=!0,me(t,i.pts)):e>0?t:i.pts}),t[0].pts);return s&&y.debug("PTS rollover detected"),i}remux(t,s,i,e,n,r,h,o){let a,l,c,u,d,f,m=n,g=n;const v=s.pid>-1,p=s.samples.length,w=t.samples.length>0,b=h&&p>0||p>1;if((!(t.pid>-1)||w)&&(!v||b)||this.ISGenerated||h){this.ISGenerated||(c=this.generateIS(t,s,n,r));const i=this.isVideoContiguous;let e,h=-1;if(b&&(h=function(t){for(let s=0;s<t.length;s++)if(t[s].key)return s;return-1}(s.samples),!i&&this.config.forceKeyFrameOnDiscontinuity))if(f=!0,h>0){y.warn(`[mp4-remuxer]: Dropped ${h} out of ${p} video samples due to a missing keyframe`);const t=this.getVideoStartPts(s.samples);s.samples=s.samples.slice(h),s.dropped+=h,g+=(s.samples[0].pts-t)/s.inputTimeScale,e=g}else-1===h&&(y.warn(`[mp4-remuxer]: No keyframe found out of ${p} video samples`),f=!1);if(this.ISGenerated){if(w&&b){const i=this.getVideoStartPts(s.samples),e=(me(t.samples[0].pts,i)-i)/s.inputTimeScale;m+=Math.max(0,e),g+=Math.max(0,-e)}if(w){if(t.samplerate||(y.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),c=this.generateIS(t,s,n,r)),l=this.remuxAudio(t,m,this.isAudioContiguous,r,v||b||o===is?g:void 0),b){const e=l?l.endPTS-l.startPTS:0;s.inputTimeScale||(y.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),c=this.generateIS(t,s,n,r)),a=this.remuxVideo(s,g,i,e)}}else b&&(a=this.remuxVideo(s,g,i,0));a&&(a.firstKeyFrame=h,a.independent=-1!==h,a.firstKeyFramePTS=e)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(i.samples.length&&(d=ge(i,n,this._initPTS,this._initDTS)),e.samples.length&&(u=ve(e,n,this._initPTS))),{audio:l,video:a,initSegment:c,independent:f,text:u,id3:d}}generateIS(t,s,i,e){const n=t.samples,r=s.samples,h=this.typeSupported,o={},a=this._initPTS;let l,c,u,d=!a||e,f="audio/mp4";if(d&&(l=c=1/0),t.config&&n.length&&(t.timescale=t.samplerate,"mp3"===t.segmentCodec&&(h.mpeg?(f="audio/mpeg",t.codec=""):h.mp3&&(t.codec="mp3")),o.audio={id:"audio",container:f,codec:t.codec,initSegment:"mp3"===t.segmentCodec&&h.mpeg?new Uint8Array(0):oe.initSegment([t]),metadata:{channelCount:t.channelCount}},d&&(u=t.inputTimeScale,a&&u===a.timescale?d=!1:l=c=n[0].pts-Math.round(u*i))),s.sps&&s.pps&&r.length&&(s.timescale=s.inputTimeScale,o.video={id:"main",container:"video/mp4",codec:s.codec,initSegment:oe.initSegment([s]),metadata:{width:s.width,height:s.height}},d))if(u=s.inputTimeScale,a&&u===a.timescale)d=!1;else{const t=this.getVideoStartPts(r),s=Math.round(u*i);c=Math.min(c,me(r[0].dts,t)-s),l=Math.min(l,t-s)}if(Object.keys(o).length)return this.ISGenerated=!0,d?(this._initPTS={baseTime:l,timescale:u},this._initDTS={baseTime:c,timescale:u}):l=u=void 0,{tracks:o,initPTS:l,timescale:u}}remuxVideo(t,s,i,e){const n=t.inputTimeScale,r=t.samples,h=[],o=r.length,a=this._initPTS;let l,u,g=this.nextAvcDts,v=8,p=this.videoSampleDuration,w=Number.POSITIVE_INFINITY,b=Number.NEGATIVE_INFINITY,T=!1;i&&null!==g||(g=s*n-(r[0].pts-me(r[0].dts,r[0].pts)));const S=a.baseTime*n/a.timescale;for(let t=0;t<o;t++){const s=r[t];s.pts=me(s.pts-S,g),s.dts=me(s.dts-S,g),s.dts<r[t>0?t-1:t].dts&&(T=!0)}T&&r.sort((function(t,s){return t.dts-s.dts||t.pts-s.pts})),l=r[0].dts,u=r[r.length-1].dts;const E=u-l,k=E?Math.round(E/(o-1)):p||t.inputTimeScale/30;if(i){const t=l-g,s=t>k,i=t<-1;if((s||i)&&(y.warn(s?`AVC: ${le(t,!0)} ms (${t}dts) hole between fragments detected, filling it`:`AVC: ${le(-t,!0)} ms (${t}dts) overlapping between fragments detected`),!i||g>r[0].pts)){l=g;const s=r[0].pts-t;r[0].dts=l,r[0].pts=s,y.log(`Video: First PTS/DTS adjusted: ${le(s,!0)}/${le(l,!0)}, delta: ${le(t,!0)} ms`)}}l=Math.max(0,l);let $=0,A=0;for(let t=0;t<o;t++){const s=r[t],i=s.units,e=i.length;let n=0;for(let t=0;t<e;t++)n+=i[t].data.length;A+=n,$+=e,s.length=n,s.dts=Math.max(s.dts,l),w=Math.min(s.pts,w),b=Math.max(s.pts,b)}u=r[o-1].dts;const L=A+4*$+8;let M;try{M=new Uint8Array(L)}catch(t){return void this.observer.emit(d.ERROR,d.ERROR,{type:f.MUX_ERROR,details:m.REMUX_ALLOC_ERROR,fatal:!1,error:t,bytes:L,reason:`fail allocating video mdat ${L}`})}const D=new DataView(M.buffer);D.setUint32(0,L),M.set(oe.types.mdat,4);let x=!1,I=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,P=Number.NEGATIVE_INFINITY,R=Number.NEGATIVE_INFINITY;for(let t=0;t<o;t++){const s=r[t],i=s.units;let a,l=0;for(let t=0,s=i.length;t<s;t++){const s=i[t],e=s.data,n=s.data.byteLength;D.setUint32(v,n),v+=4,M.set(e,v),v+=n,l+=4+n}if(t<o-1)p=r[t+1].dts-s.dts,a=r[t+1].pts-s.pts;else{const i=this.config,h=t>0?s.dts-r[t-1].dts:k;if(a=t>0?s.pts-r[t-1].pts:k,i.stretchShortVideoTrack&&null!==this.nextAudioPts){const t=Math.floor(i.maxBufferHole*n),r=(e?w+e*n:this.nextAudioPts)-s.pts;r>t?(p=r-h,p<0?p=h:x=!0,y.log(`[mp4-remuxer]: It is approximately ${r/90} ms to the next segment; using duration ${p/90} ms for the last video frame.`)):p=h}else p=h}const c=Math.round(s.pts-s.dts);I=Math.min(I,p),P=Math.max(P,p),C=Math.min(C,a),R=Math.max(R,a),h.push(new pe(s.key,p,l,c))}if(h.length)if(ue){if(ue<70){const t=h[0].flags;t.dependsOn=2,t.isNonSync=0}}else if(de&&R-C<P-I&&k/P<.025&&0===h[0].cts){y.warn("Found irregular gaps in sample duration. Using PTS instead of DTS to determine MP4 sample duration.");let t=l;for(let s=0,i=h.length;s<i;s++){const e=t+h[s].duration;h[s].duration=s<i-1?e+h[s+1].cts-(t+h[s].cts):s?h[s-1].duration:k,h[s].cts=0,t=e}}p=x||!p?k:p,this.nextAvcDts=g=u+p,this.videoSampleDuration=p,this.isVideoContiguous=!0;const O={data1:oe.moof(t.sequenceNumber++,l,c({},t,{samples:h})),data2:M,startPTS:w/n,endPTS:(b+p)/n,startDTS:l/n,endDTS:g/n,type:"video",hasAudio:!1,hasVideo:!0,nb:h.length,dropped:t.dropped};return t.samples=[],t.dropped=0,O}remuxAudio(t,s,i,e,n){const r=t.inputTimeScale,h=r/(t.samplerate?t.samplerate:r),o="aac"===t.segmentCodec?1024:1152,a=o*h,l=this._initPTS,u="mp3"===t.segmentCodec&&this.typeSupported.mpeg,g=[],v=void 0!==n;let p=t.samples,w=u?0:8,b=this.nextAudioPts||-1;const T=s*r,S=l.baseTime*r/l.timescale;if(this.isAudioContiguous=i=i||p.length&&b>0&&(e&&Math.abs(T-b)<9e3||Math.abs(me(p[0].pts-S,T)-b)<20*a),p.forEach((function(t){t.pts=me(t.pts-S,T)})),!i||b<0){if(p=p.filter((t=>t.pts>=0)),!p.length)return;b=0===n?0:e&&!v?Math.max(0,T):p[0].pts}if("aac"===t.segmentCodec){const s=this.config.maxAudioFramesDrift;for(let i=0,e=b;i<p.length;i++){const n=p[i],h=n.pts,o=h-e,l=Math.abs(1e3*o/r);if(o<=-s*a&&v)0===i&&(y.warn(`Audio frame @ ${(h/r).toFixed(3)}s overlaps nextAudioPts by ${Math.round(1e3*o/r)} ms.`),this.nextAudioPts=b=e=h);else if(o>=s*a&&l<1e4&&v){let s=Math.round(o/a);e=h-s*a,e<0&&(s--,e+=a),0===i&&(this.nextAudioPts=b=e),y.warn(`[mp4-remuxer]: Injecting ${s} audio frame @ ${(e/r).toFixed(3)}s due to ${Math.round(1e3*o/r)} ms gap.`);for(let r=0;r<s;r++){const s=Math.max(e,0);let r=re.getSilentFrame(t.manifestCodec||t.codec,t.channelCount);r||(y.log("[mp4-remuxer]: Unable to get silent frame for given audio codec; duplicating last frame instead."),r=n.unit.subarray()),p.splice(i,0,{unit:r,pts:s}),e+=a,i++}}n.pts=e,e+=a}}let E,k=null,$=null,A=0,L=p.length;for(;L--;)A+=p[L].unit.byteLength;for(let s=0,e=p.length;s<e;s++){const e=p[s],n=e.unit;let r=e.pts;if(null!==$)g[s-1].duration=Math.round((r-$)/h);else{if(i&&"aac"===t.segmentCodec&&(r=b),k=r,!(A>0))return;A+=w;try{E=new Uint8Array(A)}catch(t){return void this.observer.emit(d.ERROR,d.ERROR,{type:f.MUX_ERROR,details:m.REMUX_ALLOC_ERROR,fatal:!1,error:t,bytes:A,reason:`fail allocating audio mdat ${A}`})}u||(new DataView(E.buffer).setUint32(0,A),E.set(oe.types.mdat,4))}E.set(n,w);const a=n.byteLength;w+=a,g.push(new pe(!0,o,a,0)),$=r}const M=g.length;if(!M)return;this.nextAudioPts=b=$+h*g[g.length-1].duration;const D=u?new Uint8Array(0):oe.moof(t.sequenceNumber++,k/h,c({},t,{samples:g}));t.samples=[];const x=k/r,I=b/r,C={data1:D,data2:E,startPTS:x,endPTS:I,startDTS:x,endDTS:I,type:"audio",hasAudio:!0,hasVideo:!1,nb:M};return this.isAudioContiguous=!0,C}remuxEmptyAudio(t,s,i,e){const n=t.inputTimeScale,r=this.nextAudioPts,h=this._initDTS,o=9e4*h.baseTime/h.timescale,a=(null!==r?r:e.startDTS*n)+o,l=n/(t.samplerate?t.samplerate:n)*1024,c=Math.ceil((e.endDTS*n+o-a)/l),u=re.getSilentFrame(t.manifestCodec||t.codec,t.channelCount);if(y.warn("[mp4-remuxer]: remux empty Audio"),!u)return void y.trace("[mp4-remuxer]: Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec");const d=[];for(let t=0;t<c;t++){const s=a+t*l;d.push({unit:u,pts:s,dts:s})}return t.samples=d,this.remuxAudio(t,s,i,!1)}}function me(t,s){let i;if(null===s)return t;for(i=s<t?-8589934592:8589934592;Math.abs(t-s)>4294967296;)t+=i;return t}function ge(t,s,i,e){const n=t.samples.length;if(!n)return;const r=t.inputTimeScale;for(let h=0;h<n;h++){const n=t.samples[h];n.pts=me(n.pts-9e4*i.baseTime/i.timescale,s*r)/r,n.dts=me(n.dts-9e4*e.baseTime/e.timescale,s*r)/r}const h=t.samples;return t.samples=[],{samples:h}}function ve(t,s,i){const e=t.samples.length;if(!e)return;const n=t.inputTimeScale;for(let r=0;r<e;r++){const e=t.samples[r];e.pts=me(e.pts-9e4*i.baseTime/i.timescale,s*n)/n}t.samples.sort(((t,s)=>t.pts-s.pts));const r=t.samples;return t.samples=[],{samples:r}}class pe{constructor(t,s,i,e){this.size=void 0,this.duration=void 0,this.cts=void 0,this.flags=void 0,this.duration=s,this.size=i,this.cts=e,this.flags=new ye(t)}}class ye{constructor(t){this.isLeading=0,this.isDependedOn=0,this.hasRedundancy=0,this.degradPrio=0,this.dependsOn=1,this.isNonSync=1,this.dependsOn=t?2:1,this.isNonSync=t?0:1}}function we(t,s){const i=null==t?void 0:t.codec;return i&&i.length>4?i:"hvc1"===i||"hev1"===i?"hvc1.1.6.L120.90":"av01"===i?"av01.0.04M.08":"avc1"===i||s===A?"avc1.42e01e":"mp4a.40.5"}try{ce=self.performance.now.bind(self.performance)}catch(t){y.debug("Unable to use Performance API on this environment"),ce="undefined"!=typeof self&&self.Date.now}const be=[{demux:class{constructor(t,s){this.remainderData=null,this.timeOffset=0,this.config=void 0,this.videoTrack=void 0,this.audioTrack=void 0,this.id3Track=void 0,this.txtTrack=void 0,this.config=s}resetTimeStamp(){}resetInitSegment(t,s,i,e){const n=this.videoTrack=Li("video",1),r=this.audioTrack=Li("audio",1),h=this.txtTrack=Li("text",1);if(this.id3Track=Li("id3",1),this.timeOffset=0,null==t||!t.byteLength)return;const o=yt(t);if(o.video){const{id:t,timescale:s,codec:i}=o.video;n.id=t,n.timescale=h.timescale=s,n.codec=i}if(o.audio){const{id:t,timescale:s,codec:i}=o.audio;r.id=t,r.timescale=s,r.codec=i}h.id=ct.text,n.sampleDuration=0,n.duration=r.duration=e}resetContiguity(){this.remainderData=null}static probe(t){return vt(t=t.length>16384?t.subarray(0,16384):t,["moof"]).length>0}demux(t,s){this.timeOffset=s;let i=t;const e=this.videoTrack,n=this.txtTrack;if(this.config.progressive){this.remainderData&&(i=Tt(this.remainderData,t));const s=function(t){const s={valid:null,remainder:null},i=vt(t,["moof"]);if(!i)return s;if(i.length<2)return s.remainder=t,s;const e=i[i.length-1];return s.valid=G(t,0,e.byteOffset-8),s.remainder=G(t,e.byteOffset-8),s}(i);this.remainderData=s.remainder,e.samples=s.valid||new Uint8Array}else e.samples=i;const r=this.extractID3Track(e,s);return n.samples=St(s,e),{videoTrack:e,audioTrack:this.audioTrack,id3Track:r,textTrack:this.txtTrack}}flush(){const t=this.timeOffset,s=this.videoTrack,i=this.txtTrack;s.samples=this.remainderData||new Uint8Array,this.remainderData=null;const e=this.extractID3Track(s,this.timeOffset);return i.samples=St(t,s),{videoTrack:s,audioTrack:Li(),id3Track:e,textTrack:Li()}}extractID3Track(t,s){const i=this.id3Track;if(t.samples.length){const e=vt(t.samples,["emsg"]);e&&e.forEach((t=>{const e=function(t){const s=t[0];let i="",e="",n=0,r=0,h=0,o=0,a=0,l=0;if(0===s){for(;"\0"!==ut(t.subarray(l,l+1));)i+=ut(t.subarray(l,l+1)),l+=1;for(i+=ut(t.subarray(l,l+1)),l+=1;"\0"!==ut(t.subarray(l,l+1));)e+=ut(t.subarray(l,l+1)),l+=1;e+=ut(t.subarray(l,l+1)),l+=1,n=ft(t,12),r=ft(t,16),o=ft(t,20),a=ft(t,24),l=28}else if(1===s){l+=4,n=ft(t,l),l+=4;const s=ft(t,l);l+=4;const r=ft(t,l);for(l+=4,h=2**32*s+r,Number.isSafeInteger(h)||(h=Number.MAX_SAFE_INTEGER,y.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=ft(t,l),l+=4,a=ft(t,l),l+=4;"\0"!==ut(t.subarray(l,l+1));)i+=ut(t.subarray(l,l+1)),l+=1;for(i+=ut(t.subarray(l,l+1)),l+=1;"\0"!==ut(t.subarray(l,l+1));)e+=ut(t.subarray(l,l+1)),l+=1;e+=ut(t.subarray(l,l+1)),l+=1}return{schemeIdUri:i,value:e,timeScale:n,presentationTime:h,presentationTimeDelta:r,eventDuration:o,id:a,payload:t.subarray(l,t.byteLength)}}(t);if(Fi.test(e.schemeIdUri)){const t=u(e.presentationTime)?e.presentationTime/e.timeScale:s+e.presentationTimeDelta/e.timeScale;let n=4294967295===e.eventDuration?Number.POSITIVE_INFINITY:e.eventDuration/e.timeScale;n<=.001&&(n=Number.POSITIVE_INFINITY);const r=e.payload;i.samples.push({data:r,len:r.byteLength,dts:t,pts:t,type:ds,duration:n})}}))}return i}demuxSampleAes(t,s,i){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))}destroy(){}},remux:class{constructor(){this.emitInitSegment=!1,this.audioCodec=void 0,this.videoCodec=void 0,this.initData=void 0,this.initPTS=null,this.initTracks=void 0,this.lastEndTime=null}destroy(){}resetTimeStamp(t){this.initPTS=t,this.lastEndTime=null}resetNextTimestamp(){this.lastEndTime=null}resetInitSegment(t,s,i,e){this.audioCodec=s,this.videoCodec=i,this.generateInitSegment(function(t,s){if(!t||!s)return t;const i=s.keyId;return i&&s.isCommonEncryption&&vt(t,["moov","trak"]).forEach((t=>{const s=vt(t,["mdia","minf","stbl","stsd"])[0].subarray(8);let e=vt(s,["enca"]);const n=e.length>0;n||(e=vt(s,["encv"])),e.forEach((t=>{vt(t.subarray(n?28:78),["sinf"]).forEach((t=>{const s=wt(t);if(s){const t=s.subarray(8,24);t.some((t=>0!==t))||(y.log(`[eme] Patching keyId in 'enc${n?"a":"v"}>sinf>>tenc' box: ${ot(t)} -> ${ot(i)}`),s.set(i,8))}}))}))})),t}(t,e)),this.emitInitSegment=!0}generateInitSegment(t){let{audioCodec:s,videoCodec:i}=this;if(null==t||!t.byteLength)return this.initTracks=void 0,void(this.initData=void 0);const e=this.initData=yt(t);s||(s=we(e.audio,$)),i||(i=we(e.video,A));const n={};e.audio&&e.video?n.audiovideo={container:"video/mp4",codec:s+","+i,initSegment:t,id:"main"}:e.audio?n.audio={container:"audio/mp4",codec:s,initSegment:t,id:"audio"}:e.video?n.video={container:"video/mp4",codec:i,initSegment:t,id:"main"}:y.warn("[passthrough-remuxer.ts]: initSegment does not contain moov or trak boxes."),this.initTracks=n}remux(t,s,i,e,n,r){var h,o;let{initPTS:a,lastEndTime:l}=this;const c={audio:void 0,video:void 0,text:e,id3:i,initSegment:void 0};u(l)||(l=this.lastEndTime=n||0);const d=s.samples;if(null==d||!d.length)return c;const f={initPTS:void 0,timescale:1};let m=this.initData;if(null!=(h=m)&&h.length||(this.generateInitSegment(d),m=this.initData),null==(o=m)||!o.length)return y.warn("[passthrough-remuxer.ts]: Failed to generate initSegment."),c;this.emitInitSegment&&(f.tracks=this.initTracks,this.emitInitSegment=!1);const g=function(t,s){return vt(s,["moof","traf"]).reduce(((s,i)=>{const e=vt(i,["tfdt"])[0],n=e[0],r=vt(i,["tfhd"]).reduce(((s,i)=>{const r=ft(i,4),h=t[r];if(h){let t=ft(e,4);if(1===n){if(t===at)return y.warn("[mp4-demuxer]: Ignoring assumed invalid signed 64-bit track fragment decode time"),s;t*=at+1,t+=ft(e,8)}const i=t/(h.timescale||9e4);if(isFinite(i)&&(null===s||i<s))return i}return s}),null);return null!==r&&isFinite(r)&&(null===s||r<s)?r:s}),null)}(m,d),v=null===g?n:g;(function(t,s,i){if(null===t)return!0;const e=s-t.baseTime/t.timescale;return e<0&&Math.abs(e-i)>1}(a,v,n)||f.timescale!==a.timescale&&r)&&(f.initPTS=v-n,this.initPTS=a={baseTime:f.initPTS,timescale:1});const p=function(t,s){let i=0,e=0,n=0;const r=vt(t,["moof","traf"]);for(let t=0;t<r.length;t++){const h=r[t],o=vt(h,["tfhd"])[0],a=s[ft(o,4)];if(!a)continue;const l=a.default,c=ft(o,0)|(null==l?void 0:l.flags);let u=null==l?void 0:l.duration;8&c&&(u=ft(o,2&c?12:8));const d=a.timescale||9e4,f=vt(h,["trun"]);for(let t=0;t<f.length;t++)i=bt(f[t]),!i&&u&&(i=u*ft(f[t],4)),a.type===A?e+=i/d:a.type===$&&(n+=i/d)}if(0===e&&0===n){let s=0;const i=vt(t,["sidx"]);for(let t=0;t<i.length;t++){const e=pt(i[t]);null!=e&&e.references&&(s+=e.references.reduce(((t,s)=>t+s.info.duration||0),0))}return s}return e||n}(d,m),w=t?v-a.baseTime/a.timescale:l,b=w+p;!function(t,s,i){vt(s,["moof","traf"]).forEach((s=>{vt(s,["tfhd"]).forEach((e=>{const n=ft(e,4),r=t[n];if(!r)return;const h=r.timescale||9e4;vt(s,["tfdt"]).forEach((t=>{const s=t[0];let e=ft(t,4);if(0===s)e-=i*h,e=Math.max(e,0),gt(t,4,e);else{e*=Math.pow(2,32),e+=ft(t,8),e-=i*h,e=Math.max(e,0);const s=Math.floor(e/(at+1)),n=Math.floor(e%(at+1));gt(t,4,s),gt(t,8,n)}}))}))}))}(m,d,a.baseTime/a.timescale),p>0?this.lastEndTime=b:(y.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());const T=!!m.audio,S=!!m.video;let E="";T&&(E+="audio"),S&&(E+="video");const k={data1:d,startPTS:w,startDTS:w,endPTS:b,endDTS:b,type:E,hasAudio:T,hasVideo:S,nb:1,dropped:0};return c.audio="audio"===k.type?k:void 0,c.video="audio"!==k.type?k:void 0,c.initSegment=f,c.id3=ge(i,n,a,a),e.samples.length&&(c.text=ve(e,n,a)),c}}},{demux:Ji,remux:fe},{demux:class extends Mi{constructor(t,s){super(),this.observer=void 0,this.config=void 0,this.observer=t,this.config=s}resetInitSegment(t,s,i,e){super.resetInitSegment(t,s,i,e),this._audioTrack={container:"audio/adts",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"aac",samples:[],manifestCodec:s,duration:e,inputTimeScale:9e4,dropped:0}}static probe(t){if(!t)return!1;let s=(X(t,0)||[]).length;for(let i=t.length;s<i;s++)if(Ri(t,s))return y.log("ADTS sync word found !"),!0;return!1}canParse(t,s){return function(t,s){return function(t,s){return s+5<t.length}(t,s)&&xi(t,s)&&Ci(t,s)<=t.length-s}(t,s)}appendFrame(t,s,i){Oi(t,this.observer,s,i,t.manifestCodec);const e=Ui(t,s,i,this.basePTS,this.frameIndex);if(e&&0===e.missing)return e}},remux:fe},{demux:class extends Mi{resetInitSegment(t,s,i,e){super.resetInitSegment(t,s,i,e),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:s,duration:e,inputTimeScale:9e4,dropped:0}}static probe(t){if(!t)return!1;let s=(X(t,0)||[]).length;for(let i=t.length;s<i;s++)if(qi(t,s))return y.log("MPEG Audio sync word found !"),!0;return!1}canParse(t,s){return function(t,s){return Wi(t,s)&&4<=t.length-s}(t,s)}appendFrame(t,s,i){if(null!==this.basePTS)return Gi(t,s,i,this.basePTS,this.frameIndex)}},remux:fe}];class Te{constructor(t,s,i,e,n){this.async=!1,this.observer=void 0,this.typeSupported=void 0,this.config=void 0,this.vendor=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionPromise=null,this.transmuxConfig=void 0,this.currentTransmuxState=void 0,this.observer=t,this.typeSupported=s,this.config=i,this.vendor=e,this.id=n}configure(t){this.transmuxConfig=t,this.decrypter&&this.decrypter.reset()}push(t,s,i,e){const n=i.transmuxing;n.executeStart=ce();let r=new Uint8Array(t);const{currentTransmuxState:h,transmuxConfig:o}=this;e&&(this.currentTransmuxState=e);const{contiguous:a,discontinuity:l,trackSwitch:c,accurateTimeOffset:u,timeOffset:g,initSegmentChange:v}=e||h,{audioCodec:p,videoCodec:w,defaultInitPts:b,duration:T,initSegmentData:S}=o,E=function(t,s){let i=null;return t.byteLength>0&&null!=s&&null!=s.key&&null!==s.iv&&null!=s.method&&(i=s),i}(r,s);if(E&&"AES-128"===E.method){const t=this.getDecrypter();if(!t.isSync())return this.decryptionPromise=t.webCryptoDecrypt(r,E.key.buffer,E.iv.buffer).then((t=>{const s=this.push(t,null,i);return this.decryptionPromise=null,s})),this.decryptionPromise;{let s=t.softwareDecrypt(r,E.key.buffer,E.iv.buffer);if(i.part>-1&&(s=t.flush()),!s)return n.executeEnd=ce(),Se(i);r=new Uint8Array(s)}}const k=this.needsProbing(l,c);if(k){const t=this.configureTransmuxer(r);if(t)return y.warn(`[transmuxer] ${t.message}`),this.observer.emit(d.ERROR,d.ERROR,{type:f.MEDIA_ERROR,details:m.FRAG_PARSING_ERROR,fatal:!1,error:t,reason:t.message}),n.executeEnd=ce(),Se(i)}(l||c||v||k)&&this.resetInitSegment(S,p,w,T,s),(l||v||k)&&this.resetInitialTimestamp(b),a||this.resetContiguity();const $=this.transmux(r,E,g,u,i),A=this.currentTransmuxState;return A.contiguous=!0,A.discontinuity=!1,A.trackSwitch=!1,n.executeEnd=ce(),$}flush(t){const s=t.transmuxing;s.executeStart=ce();const{decrypter:i,currentTransmuxState:e,decryptionPromise:n}=this;if(n)return n.then((()=>this.flush(t)));const r=[],{timeOffset:h}=e;if(i){const s=i.flush();s&&r.push(this.push(s,null,t))}const{demuxer:o,remuxer:a}=this;if(!o||!a)return s.executeEnd=ce(),[Se(t)];const l=o.flush(h);return Ee(l)?l.then((s=>(this.flushRemux(r,s,t),r))):(this.flushRemux(r,l,t),r)}flushRemux(t,s,i){const{audioTrack:e,videoTrack:n,id3Track:r,textTrack:h}=s,{accurateTimeOffset:o,timeOffset:a}=this.currentTransmuxState;y.log(`[transmuxer.ts]: Flushed fragment ${i.sn}${i.part>-1?" p: "+i.part:""} of level ${i.level}`);const l=this.remuxer.remux(e,n,r,h,a,o,!0,this.id);t.push({remuxResult:l,chunkMeta:i}),i.transmuxing.executeEnd=ce()}resetInitialTimestamp(t){const{demuxer:s,remuxer:i}=this;s&&i&&(s.resetTimeStamp(t),i.resetTimeStamp(t))}resetContiguity(){const{demuxer:t,remuxer:s}=this;t&&s&&(t.resetContiguity(),s.resetNextTimestamp())}resetInitSegment(t,s,i,e,n){const{demuxer:r,remuxer:h}=this;r&&h&&(r.resetInitSegment(t,s,i,e),h.resetInitSegment(t,s,i,n))}destroy(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)}transmux(t,s,i,e,n){let r;return r=s&&"SAMPLE-AES"===s.method?this.transmuxSampleAes(t,s,i,e,n):this.transmuxUnencrypted(t,i,e,n),r}transmuxUnencrypted(t,s,i,e){const{audioTrack:n,videoTrack:r,id3Track:h,textTrack:o}=this.demuxer.demux(t,s,!1,!this.config.progressive);return{remuxResult:this.remuxer.remux(n,r,h,o,s,i,!1,this.id),chunkMeta:e}}transmuxSampleAes(t,s,i,e,n){return this.demuxer.demuxSampleAes(t,s,i).then((t=>({remuxResult:this.remuxer.remux(t.audioTrack,t.videoTrack,t.id3Track,t.textTrack,i,e,!1,this.id),chunkMeta:n})))}configureTransmuxer(t){const{config:s,observer:i,typeSupported:e,vendor:n}=this;let r;for(let s=0,i=be.length;s<i;s++)if(be[s].demux.probe(t)){r=be[s];break}if(!r)return new Error("Failed to find demuxer by probing fragment data");const h=this.demuxer,o=this.remuxer,a=r.remux,l=r.demux;o&&o instanceof a||(this.remuxer=new a(i,s,e,n)),h&&h instanceof l||(this.demuxer=new l(i,s,e),this.probe=l.probe)}needsProbing(t,s){return!this.demuxer||!this.remuxer||t||s}getDecrypter(){let t=this.decrypter;return t||(t=this.decrypter=new di(this.config)),t}}const Se=t=>({remuxResult:{},chunkMeta:t});function Ee(t){return"then"in t&&t.then instanceof Function}class ke{constructor(t,s,i,e,n){this.audioCodec=void 0,this.videoCodec=void 0,this.initSegmentData=void 0,this.duration=void 0,this.defaultInitPts=void 0,this.audioCodec=t,this.videoCodec=s,this.initSegmentData=i,this.duration=e,this.defaultInitPts=n||null}}class $e{constructor(t,s,i,e,n,r){this.discontinuity=void 0,this.contiguous=void 0,this.accurateTimeOffset=void 0,this.trackSwitch=void 0,this.timeOffset=void 0,this.initSegmentChange=void 0,this.discontinuity=t,this.contiguous=s,this.accurateTimeOffset=i,this.trackSwitch=e,this.timeOffset=n,this.initSegmentChange=r}}var Ae={exports:{}};!function(t){var s=Object.prototype.hasOwnProperty,i="~";function e(){}function n(t,s,i){this.fn=t,this.context=s,this.once=i||!1}function r(t,s,e,r,h){if("function"!=typeof e)throw new TypeError("The listener must be a function");var o=new n(e,r||t,h),a=i?i+s:s;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],o]:t._events[a].push(o):(t._events[a]=o,t._eventsCount++),t}function h(t,s){0==--t._eventsCount?t._events=new e:delete t._events[s]}function o(){this._events=new e,this._eventsCount=0}Object.create&&(e.prototype=Object.create(null),(new e).__proto__||(i=!1)),o.prototype.eventNames=function(){var t,e,n=[];if(0===this._eventsCount)return n;for(e in t=this._events)s.call(t,e)&&n.push(i?e.slice(1):e);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(t)):n},o.prototype.listeners=function(t){var s=this._events[i?i+t:t];if(!s)return[];if(s.fn)return[s.fn];for(var e=0,n=s.length,r=new Array(n);e<n;e++)r[e]=s[e].fn;return r},o.prototype.listenerCount=function(t){var s=this._events[i?i+t:t];return s?s.fn?1:s.length:0},o.prototype.emit=function(t,s,e,n,r,h){var o=i?i+t:t;if(!this._events[o])return!1;var a,l,c=this._events[o],u=arguments.length;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,s),!0;case 3:return c.fn.call(c.context,s,e),!0;case 4:return c.fn.call(c.context,s,e,n),!0;case 5:return c.fn.call(c.context,s,e,n,r),!0;case 6:return c.fn.call(c.context,s,e,n,r,h),!0}for(l=1,a=new Array(u-1);l<u;l++)a[l-1]=arguments[l];c.fn.apply(c.context,a)}else{var d,f=c.length;for(l=0;l<f;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,s);break;case 3:c[l].fn.call(c[l].context,s,e);break;case 4:c[l].fn.call(c[l].context,s,e,n);break;default:if(!a)for(d=1,a=new Array(u-1);d<u;d++)a[d-1]=arguments[d];c[l].fn.apply(c[l].context,a)}}return!0},o.prototype.on=function(t,s,i){return r(this,t,s,i,!1)},o.prototype.once=function(t,s,i){return r(this,t,s,i,!0)},o.prototype.removeListener=function(t,s,e,n){var r=i?i+t:t;if(!this._events[r])return this;if(!s)return h(this,r),this;var o=this._events[r];if(o.fn)o.fn!==s||n&&!o.once||e&&o.context!==e||h(this,r);else{for(var a=0,l=[],c=o.length;a<c;a++)(o[a].fn!==s||n&&!o[a].once||e&&o[a].context!==e)&&l.push(o[a]);l.length?this._events[r]=1===l.length?l[0]:l:h(this,r)}return this},o.prototype.removeAllListeners=function(t){var s;return t?this._events[s=i?i+t:t]&&h(this,s):(this._events=new e,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=i,o.EventEmitter=o,t.exports=o}(Ae);var Le=t(Ae.exports);const Me=Rt()||{isTypeSupported:()=>!1};class De{constructor(t,s,i,e){this.error=null,this.hls=void 0,this.id=void 0,this.observer=void 0,this.frag=null,this.part=null,this.useWorker=void 0,this.workerContext=null,this.onwmsg=void 0,this.transmuxer=null,this.onTransmuxComplete=void 0,this.onFlush=void 0;const n=t.config;this.hls=t,this.id=s,this.useWorker=!!n.enableWorker,this.onTransmuxComplete=i,this.onFlush=e;const r=(t,s)=>{(s=s||{}).frag=this.frag,s.id=this.id,t===d.ERROR&&(this.error=s.error),this.hls.trigger(t,s)};this.observer=new Le,this.observer.on(d.FRAG_DECRYPTED,r),this.observer.on(d.ERROR,r);const h={mp4:Me.isTypeSupported("video/mp4"),mpeg:Me.isTypeSupported("audio/mpeg"),mp3:Me.isTypeSupported('audio/mp4; codecs="mp3"')},o=navigator.vendor;if(!this.useWorker||"undefined"==typeof Worker||!n.workerPath&&"function"!=typeof __HLS_WORKER_BUNDLE__)this.transmuxer=new Te(this.observer,h,n,o,s);else try{n.workerPath?(y.log(`loading Web Worker ${n.workerPath} for "${s}"`),this.workerContext=function(t){const s=new self.URL(t,self.location.href).href;return{worker:new self.Worker(s),scriptURL:s}}(n.workerPath)):(y.log(`injecting Web Worker for "${s}"`),this.workerContext=function(){const t=new self.Blob([`var exports={};var module={exports:exports};function define(f){f()};define.amd=true;(${__HLS_WORKER_BUNDLE__.toString()})(true);`],{type:"text/javascript"}),s=self.URL.createObjectURL(t);return{worker:new self.Worker(s),objectURL:s}}()),this.onwmsg=t=>this.onWorkerMessage(t);const{worker:t}=this.workerContext;t.addEventListener("message",this.onwmsg),t.onerror=t=>{const i=new Error(`${t.message} (${t.filename}:${t.lineno})`);n.enableWorker=!1,y.warn(`Error in "${s}" Web Worker, fallback to inline`),this.hls.trigger(d.ERROR,{type:f.OTHER_ERROR,details:m.INTERNAL_EXCEPTION,fatal:!1,event:"demuxerWorker",error:i})},t.postMessage({cmd:"init",typeSupported:h,vendor:o,id:s,config:JSON.stringify(n)})}catch(t){y.warn(`Error setting up "${s}" Web Worker, fallback to inline`,t),this.resetWorker(),this.error=null,this.transmuxer=new Te(this.observer,h,n,o,s)}}resetWorker(){if(this.workerContext){const{worker:t,objectURL:s}=this.workerContext;s&&self.URL.revokeObjectURL(s),t.removeEventListener("message",this.onwmsg),t.onerror=null,t.terminate(),this.workerContext=null}}destroy(){if(this.workerContext)this.resetWorker(),this.onwmsg=void 0;else{const t=this.transmuxer;t&&(t.destroy(),this.transmuxer=null)}const t=this.observer;t&&t.removeAllListeners(),this.frag=null,this.observer=null,this.hls=null}push(t,s,i,e,n,r,h,o,a,l){var c,u;a.transmuxing.start=self.performance.now();const{transmuxer:d}=this,f=r?r.start:n.start,m=n.decryptdata,g=this.frag,v=!(g&&n.cc===g.cc),p=!(g&&a.level===g.level),w=g?a.sn-g.sn:-1,b=this.part?a.part-this.part.index:-1,T=!p&&(1===w||0===w&&(1===b||0===w&&a.id>1&&a.id===(null==g?void 0:g.stats.chunkCount)&&b<=0)),S=self.performance.now();(p||w||0===n.stats.parsing.start)&&(n.stats.parsing.start=S),!r||!b&&T||(r.stats.parsing.start=S);const E=!(g&&(null==(c=n.initSegment)?void 0:c.url)===(null==(u=g.initSegment)?void 0:u.url)),k=new $e(v,T,o,p,f,E);if(!T||v||E){y.log(`[transmuxer-interface, ${n.type}]: Starting new transmux session for sn: ${a.sn} p: ${a.part} level: ${a.level} id: ${a.id}\n discontinuity: ${v}\n trackSwitch: ${p}\n contiguous: ${T}\n accurateTimeOffset: ${o}\n timeOffset: ${f}\n initSegmentChange: ${E}`);const t=new ke(i,e,s,h,l);this.configureTransmuxer(t)}if(this.frag=n,this.part=r,this.workerContext)this.workerContext.worker.postMessage({cmd:"demux",data:t,decryptdata:m,chunkMeta:a,state:k},t instanceof ArrayBuffer?[t]:[]);else if(d){const s=d.push(t,m,a,k);Ee(s)?(d.async=!0,s.then((t=>{this.handleTransmuxComplete(t)})).catch((t=>{this.transmuxerError(t,a,"transmuxer-interface push error")}))):(d.async=!1,this.handleTransmuxComplete(s))}}flush(t){t.transmuxing.start=self.performance.now();const{transmuxer:s}=this;if(this.workerContext)this.workerContext.worker.postMessage({cmd:"flush",chunkMeta:t});else if(s){let i=s.flush(t);Ee(i)||s.async?(Ee(i)||(i=Promise.resolve(i)),i.then((s=>{this.handleFlushResult(s,t)})).catch((s=>{this.transmuxerError(s,t,"transmuxer-interface flush error")}))):this.handleFlushResult(i,t)}}transmuxerError(t,s,i){this.hls&&(this.error=t,this.hls.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.FRAG_PARSING_ERROR,chunkMeta:s,fatal:!1,error:t,err:t,reason:i}))}handleFlushResult(t,s){t.forEach((t=>{this.handleTransmuxComplete(t)})),this.onFlush(s)}onWorkerMessage(t){const s=t.data,i=this.hls;switch(s.event){case"init":{var e;const t=null==(e=this.workerContext)?void 0:e.objectURL;t&&self.URL.revokeObjectURL(t);break}case"transmuxComplete":this.handleTransmuxComplete(s.data);break;case"flush":this.onFlush(s.data);break;case"workerLog":y[s.data.logType]&&y[s.data.logType](s.data.message);break;default:s.data=s.data||{},s.data.frag=this.frag,s.data.id=this.id,i.trigger(s.event,s.data)}}configureTransmuxer(t){const{transmuxer:s}=this;this.workerContext?this.workerContext.worker.postMessage({cmd:"configure",config:t}):s&&s.configure(t)}handleTransmuxComplete(t){t.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(t)}}class xe{constructor(t,s,i,e){this.config=void 0,this.media=null,this.fragmentTracker=void 0,this.hls=void 0,this.nudgeRetry=0,this.stallReported=!1,this.stalled=null,this.moved=!1,this.seeking=!1,this.config=t,this.media=s,this.fragmentTracker=i,this.hls=e}destroy(){this.media=null,this.hls=this.fragmentTracker=null}poll(t,s){const{config:i,media:e,stalled:n}=this;if(null===e)return;const{currentTime:r,seeking:h}=e,o=this.seeking&&!h,a=!this.seeking&&h;if(this.seeking=h,r!==t){if(this.moved=!0,null!==n){if(this.stallReported){const t=self.performance.now()-n;y.warn(`playback not stuck anymore @${r}, after ${Math.round(t)}ms`),this.stallReported=!1}this.stalled=null,this.nudgeRetry=0}return}if(a||o)return void(this.stalled=null);if(e.paused&&!h||e.ended||0===e.playbackRate||!ei.getBuffered(e).length)return;const l=ei.bufferInfo(e,r,0),c=l.nextStart||0;if(!(l.len>0||c))return;if(h){const t=l.len>2,i=!c||s&&s.start<=r||c-r>2&&!this.fragmentTracker.getPartialFragment(r);if(t||i)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var u;const t=Math.max(c,l.start||0)-r,s=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,i=(null==s||null==(u=s.details)?void 0:u.live)?2*s.details.targetduration:2,e=this.fragmentTracker.getPartialFragment(r);if(t>0&&(t<=i||e))return void this._trySkipBufferHole(e)}const d=self.performance.now();if(null===n)return void(this.stalled=d);const f=d-n;if(!h&&f>=250&&(this._reportStall(l),!this.media))return;const m=ei.bufferInfo(e,r,i.maxBufferHole);this._tryFixBufferStall(m,f)}_tryFixBufferStall(t,s){const{config:i,fragmentTracker:e,media:n}=this;if(null===n)return;const r=n.currentTime,h=e.getPartialFragment(r);(!h||!this._trySkipBufferHole(h)&&this.media)&&(t.len>i.maxBufferHole||t.nextStart&&t.nextStart-r<i.maxBufferHole)&&s>1e3*i.highBufferWatchdogPeriod&&(y.warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())}_reportStall(t){const{hls:s,media:i,stallReported:e}=this;if(!e&&i){this.stallReported=!0;const e=new Error(`Playback stalling at @${i.currentTime} due to low buffer (${JSON.stringify(t)})`);y.warn(e.message),s.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.BUFFER_STALLED_ERROR,fatal:!1,error:e,buffer:t.len})}}_trySkipBufferHole(t){const{config:s,hls:i,media:e}=this;if(null===e)return 0;const n=e.currentTime,r=ei.bufferInfo(e,n,0),h=n<r.start?r.start:r.nextStart;if(h){const o=h-n;if(o>0&&(r.len<=s.maxBufferHole||r.len>0&&r.len<1&&e.readyState<3)){if(o>s.maxBufferHole){const{fragmentTracker:s}=this;let i=!1;if(0===n){const t=s.getAppendedFrag(0,ss);t&&h<t.end&&(i=!0)}if(!i){const i=t||s.getAppendedFrag(n,ss);if(i){let t=!1,e=i.end;for(;e<h;){const i=s.getPartialFragment(e);if(!i){t=!0;break}e+=i.duration}if(t)return 0}}}const r=Math.max(h+.05,n+.1);if(y.warn(`skipping hole, adjusting currentTime from ${n} to ${r}`),this.moved=!0,this.stalled=null,e.currentTime=r,t&&!t.gap){const s=new Error(`fragment loaded with buffer holes, seeking from ${n} to ${r}`);i.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.BUFFER_SEEK_OVER_HOLE,fatal:!1,error:s,reason:s.message,frag:t})}return r}}return 0}_tryNudgeBuffer(){const{config:t,hls:s,media:i,nudgeRetry:e}=this;if(null===i)return;const n=i.currentTime;if(this.nudgeRetry++,e<t.nudgeMaxRetry){const r=n+(e+1)*t.nudgeOffset,h=new Error(`Nudging 'currentTime' from ${n} to ${r}`);y.warn(h.message),i.currentTime=r,s.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.BUFFER_NUDGE_ON_STALL,error:h,fatal:!1})}else{const i=new Error(`Playhead still not moving while enough data buffered @${n} after ${t.nudgeMaxRetry} nudges`);y.error(i.message),s.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.BUFFER_STALLED_ERROR,error:i,fatal:!0})}}}class Ie extends $i{constructor(t,s,i){super(t,s,i,"[stream-controller]",ss),this.audioCodecSwap=!1,this.gapController=null,this.level=-1,this._forceStartLoad=!1,this.altAudio=!1,this.audioOnly=!1,this.fragPlaying=null,this.onvplaying=null,this.onvseeked=null,this.fragLastKbps=0,this.couldBacktrack=!1,this.backtrackFragment=null,this.audioCodecSwitch=!1,this.videoBuffer=null,this._registerListeners()}_registerListeners(){const{hls:t}=this;t.on(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.MANIFEST_PARSED,this.onManifestParsed,this),t.on(d.LEVEL_LOADING,this.onLevelLoading,this),t.on(d.LEVEL_LOADED,this.onLevelLoaded,this),t.on(d.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),t.on(d.ERROR,this.onError,this),t.on(d.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.on(d.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.on(d.BUFFER_CREATED,this.onBufferCreated,this),t.on(d.BUFFER_FLUSHED,this.onBufferFlushed,this),t.on(d.LEVELS_UPDATED,this.onLevelsUpdated,this),t.on(d.FRAG_BUFFERED,this.onFragBuffered,this)}_unregisterListeners(){const{hls:t}=this;t.off(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.MANIFEST_PARSED,this.onManifestParsed,this),t.off(d.LEVEL_LOADED,this.onLevelLoaded,this),t.off(d.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),t.off(d.ERROR,this.onError,this),t.off(d.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.off(d.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),t.off(d.BUFFER_CREATED,this.onBufferCreated,this),t.off(d.BUFFER_FLUSHED,this.onBufferFlushed,this),t.off(d.LEVELS_UPDATED,this.onLevelsUpdated,this),t.off(d.FRAG_BUFFERED,this.onFragBuffered,this)}onHandlerDestroying(){this._unregisterListeners(),this.onMediaDetaching()}startLoad(t){if(this.levels){const{lastCurrentTime:s,hls:i}=this;if(this.stopLoad(),this.setInterval(100),this.level=-1,!this.startFragRequested){let t=i.startLevel;-1===t&&(i.config.testBandwidth&&this.levels.length>1?(t=0,this.bitrateTest=!0):t=i.nextAutoLevel),this.level=i.nextLoadLevel=t,this.loadedmetadata=!1}s>0&&-1===t&&(this.log(`Override startPosition with lastCurrentTime @${s.toFixed(3)}`),t=s),this.state=mi,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}else this._forceStartLoad=!0,this.state=fi}stopLoad(){this._forceStartLoad=!1,super.stopLoad()}doTick(){switch(this.state){case ki:{var t;const{levels:s,level:i}=this,e=null==s||null==(t=s[i])?void 0:t.details;if(e&&(!e.live||this.levelLastLoaded===this.level)){if(this.waitForCdnTuneIn(e))break;this.state=mi;break}break}case pi:{var s;const t=self.performance.now(),i=this.retryDate;(!i||t>=i||null!=(s=this.media)&&s.seeking)&&(this.resetStartWhenNotLoaded(this.level),this.state=mi)}}this.state===mi&&this.doTickIdle(),this.onTickEnd()}onTickEnd(){super.onTickEnd(),this.checkBuffer(),this.checkFragmentChanged()}doTickIdle(){const{hls:t,levelLastLoaded:s,levels:i,media:e}=this,{config:n,nextLoadLevel:r}=t;if(null===s||!e&&(this.startFragRequested||!n.startFragPrefetch))return;if(this.altAudio&&this.audioOnly)return;if(null==i||!i[r])return;const h=i[r],o=this.getMainFwdBufferInfo();if(null===o)return;const a=this.getLevelDetails();if(a&&this._streamEnded(o,a)){const t={};return this.altAudio&&(t.type="video"),this.hls.trigger(d.BUFFER_EOS,t),void(this.state=Ti)}t.loadLevel!==r&&-1===t.manualLevel&&this.log(`Adapting to level ${r} from level ${this.level}`),this.level=t.nextLoadLevel=r;const l=h.details;if(!l||this.state===ki||l.live&&this.levelLastLoaded!==r)return this.level=r,void(this.state=ki);const c=o.len,u=this.getMaxBufferLength(h.maxBitrate);if(c>=u)return;this.backtrackFragment&&this.backtrackFragment.start>o.end&&(this.backtrackFragment=null);const f=this.backtrackFragment?this.backtrackFragment.start:o.end;let m=this.getNextFragment(f,l);if(this.couldBacktrack&&!this.fragPrevious&&m&&"initSegment"!==m.sn&&this.fragmentTracker.getState(m)!==Vs){var g;const t=(null!=(g=this.backtrackFragment)?g:m).sn,s=l.fragments[t-l.startSN-1];s&&m.cc===s.cc&&(m=s,this.fragmentTracker.removeFragment(s))}else this.backtrackFragment&&o.len&&(this.backtrackFragment=null);if(m&&this.isLoopLoading(m,f)){if(!m.gap){const t=this.audioOnly&&!this.altAudio?$:A,s=(t===A?this.videoBuffer:this.mediaBuffer)||this.media;s&&this.afterBufferFlushed(s,t,ss)}m=this.getNextFragmentLoopLoading(m,l,o,ss,u)}m&&(!m.initSegment||m.initSegment.data||this.bitrateTest||(m=m.initSegment),this.loadFragment(m,h,f))}loadFragment(t,s,i){const e=this.fragmentTracker.getState(t);this.fragCurrent=t,e===Ks||e===Gs?"initSegment"===t.sn?this._loadInitSegment(t,s):this.bitrateTest?(this.log(`Fragment ${t.sn} of level ${t.level} is being downloaded to test bitrate and will not be buffered`),this._loadBitrateTestFrag(t,s)):(this.startFragRequested=!0,super.loadFragment(t,s,i)):this.clearTrackerIfNeeded(t)}getBufferedFrag(t){return this.fragmentTracker.getBufferedFrag(t,ss)}followingBufferedFrag(t){return t?this.getBufferedFrag(t.end+.5):null}immediateLevelSwitch(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)}nextLevelSwitch(){const{levels:t,media:s}=this;if(null!=s&&s.readyState){let i;const e=this.getAppendedFrag(s.currentTime);e&&e.start>1&&this.flushMainBuffer(0,e.start-1);const n=this.getLevelDetails();if(null!=n&&n.live){const t=this.getMainFwdBufferInfo();if(!t||t.len<2*n.targetduration)return}if(!s.paused&&t){const s=this.fragLastKbps;i=s&&this.fragCurrent?this.fragCurrent.duration*t[this.hls.nextLoadLevel].maxBitrate/(1e3*s)+1:0}else i=0;const r=this.getBufferedFrag(s.currentTime+i);if(r){const t=this.followingBufferedFrag(r);if(t){this.abortCurrentFrag();const s=t.duration,i=Math.max(r.end,(t.maxStartPTS?t.maxStartPTS:t.start)+Math.min(Math.max(s-this.config.maxFragLookUpTolerance,.5*s),.75*s));this.flushMainBuffer(i,Number.POSITIVE_INFINITY)}}}}abortCurrentFrag(){const t=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,t&&(t.abortRequests(),this.fragmentTracker.removeFragment(t)),this.state){case gi:case vi:case pi:case wi:case bi:this.state=mi}this.nextLoadPosition=this.getLoadPosition()}flushMainBuffer(t,s){super.flushMainBuffer(t,s,this.altAudio?"video":null)}onMediaAttached(t,s){super.onMediaAttached(t,s);const i=s.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),i.addEventListener("playing",this.onvplaying),i.addEventListener("seeked",this.onvseeked),this.gapController=new xe(this.config,i,this.fragmentTracker,this.hls)}onMediaDetaching(){const{media:t}=this;t&&this.onvplaying&&this.onvseeked&&(t.removeEventListener("playing",this.onvplaying),t.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),super.onMediaDetaching()}onMediaPlaying(){this.tick()}onMediaSeeked(){const t=this.media,s=t?t.currentTime:null;u(s)&&this.log(`Media seeked to ${s.toFixed(3)}`);const i=this.getMainFwdBufferInfo();null!==i&&0!==i.len?this.tick():this.warn(`Main forward buffer length on "seeked" event ${i?i.len:"empty"})`)}onManifestLoading(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(d.BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=!1,this.startPosition=this.lastCurrentTime=0,this.levels=this.fragPlaying=this.backtrackFragment=null,this.altAudio=this.audioOnly=!1}onManifestParsed(t,s){let i,e=!1,n=!1;s.levels.forEach((t=>{i=t.audioCodec,i&&(-1!==i.indexOf("mp4a.40.2")&&(e=!0),-1!==i.indexOf("mp4a.40.5")&&(n=!0))})),this.audioCodecSwitch=e&&n&&!function(){var t;const s=Ai();return"function"==typeof(null==s||null==(t=s.prototype)?void 0:t.changeType)}(),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=s.levels,this.startFragRequested=!1}onLevelLoading(t,s){const{levels:i}=this;if(!i||this.state!==mi)return;const e=i[s.level];(!e.details||e.details.live&&this.levelLastLoaded!==s.level||this.waitForCdnTuneIn(e.details))&&(this.state=ki)}onLevelLoaded(t,s){var i;const{levels:e}=this,n=s.level,r=s.details,h=r.totalduration;if(!e)return void this.warn(`Levels were reset while loading level ${n}`);this.log(`Level ${n} loaded [${r.startSN},${r.endSN}]${r.lastPartSn?`[part-${r.lastPartSn}-${r.lastPartIndex}]`:""}, cc [${r.startCC}, ${r.endCC}] duration:${h}`);const o=e[n],a=this.fragCurrent;!a||this.state!==vi&&this.state!==pi||a.level===s.level&&a.urlId===o.urlId||!a.loader||this.abortCurrentFrag();let l=0;if(r.live||null!=(i=o.details)&&i.live){if(r.fragments[0]||(r.deltaUpdateFailed=!0),r.deltaUpdateFailed)return;l=this.alignPlaylists(r,o.details)}if(o.details=r,this.levelLastLoaded=n,this.hls.trigger(d.LEVEL_UPDATED,{details:r,level:n}),this.state===ki){if(this.waitForCdnTuneIn(r))return;this.state=mi}this.startFragRequested?r.live&&this.synchronizeToLiveEdge(r):this.setStartPosition(r,l),this.tick()}_handleFragmentLoadProgress(t){var s;const{frag:i,part:e,payload:n}=t,{levels:r}=this;if(!r)return void this.warn(`Levels were reset while fragment load was in progress. Fragment ${i.sn} of level ${i.level} will not be buffered`);const h=r[i.level],o=h.details;if(!o)return this.warn(`Dropping fragment ${i.sn} of level ${i.level} after level details were reset`),void this.fragmentTracker.removeFragment(i);const a=h.videoCodec,l=o.PTSKnown||!o.live,c=null==(s=i.initSegment)?void 0:s.data,u=this._getAudioCodec(h),d=this.transmuxer=this.transmuxer||new De(this.hls,ss,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),f=e?e.index:-1,m=new ni(i.level,i.sn,i.stats.chunkCount,n.byteLength,f,-1!==f);d.push(n,c,u,a,i,e,o.totalduration,l,m,this.initPTS[i.cc])}onAudioTrackSwitching(t,s){const i=this.altAudio;if(!s.url){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;const t=this.fragCurrent;t&&(this.log("Switching to main audio track, cancel main fragment load"),t.abortRequests(),this.fragmentTracker.removeFragment(t)),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();const t=this.hls;i&&(t.trigger(d.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:null}),this.fragmentTracker.removeAllFragments()),t.trigger(d.AUDIO_TRACK_SWITCHED,s)}}onAudioTrackSwitched(t,s){const i=!!this.hls.audioTracks[s.id].url;if(i){const t=this.videoBuffer;t&&this.mediaBuffer!==t&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=t)}this.altAudio=i,this.tick()}onBufferCreated(t,s){const i=s.tracks;let e,n,r=!1;for(const t in i){const s=i[t];if("main"===s.id){if(n=t,e=s,"video"===t){const s=i[t];s&&(this.videoBuffer=s.buffer)}}else r=!0}r&&e?(this.log(`Alternate track found, use ${n}.buffered to schedule main fragment loading`),this.mediaBuffer=e.buffer):this.mediaBuffer=this.media}onFragBuffered(t,s){const{frag:i,part:e}=s;if(i&&i.type!==ss)return;if(this.fragContextChanged(i))return this.warn(`Fragment ${i.sn}${e?" p: "+e.index:""} of level ${i.level} finished buffering, but was aborted. state: ${this.state}`),void(this.state===bi&&(this.state=mi));const n=e?e.stats:i.stats;this.fragLastKbps=Math.round(8*n.total/(n.buffering.end-n.loading.first)),"initSegment"!==i.sn&&(this.fragPrevious=i),this.fragBufferedComplete(i,e)}onError(t,s){var i;if(s.fatal)this.state=Si;else switch(s.details){case m.FRAG_GAP:case m.FRAG_PARSING_ERROR:case m.FRAG_DECRYPT_ERROR:case m.FRAG_LOAD_ERROR:case m.FRAG_LOAD_TIMEOUT:case m.KEY_LOAD_ERROR:case m.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(ss,s);break;case m.LEVEL_LOAD_ERROR:case m.LEVEL_LOAD_TIMEOUT:case m.LEVEL_PARSING_ERROR:s.levelRetry||this.state!==ki||(null==(i=s.context)?void 0:i.type)!==Jt||(this.state=mi);break;case m.BUFFER_FULL_ERROR:if(!s.parent||"main"!==s.parent)return;this.reduceLengthAndFlushBuffer(s)&&this.flushMainBuffer(0,Number.POSITIVE_INFINITY);break;case m.INTERNAL_EXCEPTION:this.recoverWorkerError(s)}}checkBuffer(){const{media:t,gapController:s}=this;t&&s&&t.readyState&&(!this.loadedmetadata&&ei.getBuffered(t).length||s.poll(this.lastCurrentTime,this.state!==mi?this.fragCurrent:null),this.lastCurrentTime=t.currentTime)}onFragLoadEmergencyAborted(){this.state=mi,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()}onBufferFlushed(t,{type:s}){(s!==$||this.audioOnly&&!this.altAudio)&&this.afterBufferFlushed((s===A?this.videoBuffer:this.mediaBuffer)||this.media,s,ss)}onLevelsUpdated(t,s){this.levels=s.levels}swapAudioCodec(){this.audioCodecSwap=!this.audioCodecSwap}seekToStartPos(){const{media:t}=this;if(!t)return;const s=t.currentTime;let i=this.startPosition;if(i>=0&&s<i){if(t.seeking)return void this.log(`could not seek to ${i}, already seeking at ${s}`);const e=ei.getBuffered(t),n=(e.length?e.start(0):0)-i;n>0&&(n<this.config.maxBufferHole||n<this.config.maxFragLookUpTolerance)&&(this.log(`adjusting start position by ${n} to match buffer start`),i+=n,this.startPosition=i),this.log(`seek to target start position ${i} from current time ${s}`),t.currentTime=i}}_getAudioCodec(t){let s=this.config.defaultAudioCodec||t.audioCodec;return this.audioCodecSwap&&s&&(this.log("Swapping audio codec"),s=-1!==s.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),s}_loadBitrateTestFrag(t,s){t.bitrateTest=!0,this._doFragLoad(t,s).then((i=>{const{hls:e}=this;if(!i||this.fragContextChanged(t))return;s.fragmentError=0,this.state=mi,this.startFragRequested=!1,this.bitrateTest=!1;const n=t.stats;n.parsing.start=n.parsing.end=n.buffering.start=n.buffering.end=self.performance.now(),e.trigger(d.FRAG_LOADED,i),t.bitrateTest=!1}))}_handleTransmuxComplete(t){var s;const i="main",{hls:e}=this,{remuxResult:n,chunkMeta:r}=t,h=this.getCurrentContext(r);if(!h)return void this.resetWhenMissingContext(r);const{frag:o,part:a,level:l}=h,{video:c,text:f,id3:m,initSegment:g}=n,{details:v}=l,p=this.altAudio?void 0:n.audio;if(this.fragContextChanged(o))this.fragmentTracker.removeFragment(o);else{if(this.state=wi,g){if(null!=g&&g.tracks){const t=o.initSegment||o;this._bufferInitSegment(l,g.tracks,t,r),e.trigger(d.FRAG_PARSING_INIT_SEGMENT,{frag:t,id:i,tracks:g.tracks})}const t=g.initPTS,s=g.timescale;u(t)&&(this.initPTS[o.cc]={baseTime:t,timescale:s},e.trigger(d.INIT_PTS_FOUND,{frag:o,id:i,initPTS:t,timescale:s}))}if(c&&!1!==n.independent){if(v){const{startPTS:t,endPTS:s,startDTS:i,endDTS:e}=c;if(a)a.elementaryStreams[c.type]={startPTS:t,endPTS:s,startDTS:i,endDTS:e};else if(c.firstKeyFrame&&c.independent&&1===r.id&&(this.couldBacktrack=!0),c.dropped&&c.independent){const i=this.getMainFwdBufferInfo();if((i?i.end:this.getLoadPosition())+this.config.maxBufferHole<(c.firstKeyFramePTS?c.firstKeyFramePTS:t)-this.config.maxBufferHole)return void this.backtrack(o);o.setElementaryStreamInfo(c.type,o.start,s,o.start,e,!0)}o.setElementaryStreamInfo(c.type,t,s,i,e),this.backtrackFragment&&(this.backtrackFragment=o),this.bufferFragmentData(c,o,a,r)}}else if(!1===n.independent)return void this.backtrack(o);if(p){const{startPTS:t,endPTS:s,startDTS:i,endDTS:e}=p;a&&(a.elementaryStreams[$]={startPTS:t,endPTS:s,startDTS:i,endDTS:e}),o.setElementaryStreamInfo($,t,s,i,e),this.bufferFragmentData(p,o,a,r)}v&&null!=m&&null!=(s=m.samples)&&s.length&&e.trigger(d.FRAG_PARSING_METADATA,{id:i,frag:o,details:v,samples:m.samples}),v&&f&&e.trigger(d.FRAG_PARSING_USERDATA,{id:i,frag:o,details:v,samples:f.samples})}}_bufferInitSegment(t,s,i,e){if(this.state!==wi)return;this.audioOnly=!!s.audio&&!s.video,this.altAudio&&!this.audioOnly&&delete s.audio;const{audio:n,video:r,audiovideo:h}=s;if(n){let s=t.audioCodec;const i=navigator.userAgent.toLowerCase();this.audioCodecSwitch&&(s&&(s=-1!==s.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),1!==n.metadata.channelCount&&-1===i.indexOf("firefox")&&(s="mp4a.40.5")),-1!==i.indexOf("android")&&"audio/mpeg"!==n.container&&(s="mp4a.40.2",this.log(`Android: force audio codec to ${s}`)),t.audioCodec&&t.audioCodec!==s&&this.log(`Swapping manifest audio codec "${t.audioCodec}" for "${s}"`),n.levelCodec=s,n.id="main",this.log(`Init audio buffer, container:${n.container}, codecs[selected/level/parsed]=[${s||""}/${t.audioCodec||""}/${n.codec}]`)}r&&(r.levelCodec=t.videoCodec,r.id="main",this.log(`Init video buffer, container:${r.container}, codecs[level/parsed]=[${t.videoCodec||""}/${r.codec}]`)),h&&this.log(`Init audiovideo buffer, container:${h.container}, codecs[level/parsed]=[${t.attrs.CODECS||""}/${h.codec}]`),this.hls.trigger(d.BUFFER_CODECS,s),Object.keys(s).forEach((t=>{const n=s[t].initSegment;null!=n&&n.byteLength&&this.hls.trigger(d.BUFFER_APPENDING,{type:t,data:n,frag:i,part:null,chunkMeta:e,parent:i.type})})),this.tick()}getMainFwdBufferInfo(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,ss)}backtrack(t){this.couldBacktrack=!0,this.backtrackFragment=t,this.resetTransmuxer(),this.flushBufferGap(t),this.fragmentTracker.removeFragment(t),this.fragPrevious=null,this.nextLoadPosition=t.start,this.state=mi}checkFragmentChanged(){const t=this.media;let s=null;if(t&&t.readyState>1&&!1===t.seeking){const i=t.currentTime;if(ei.isBuffered(t,i)?s=this.getAppendedFrag(i):ei.isBuffered(t,i+.1)&&(s=this.getAppendedFrag(i+.1)),s){this.backtrackFragment=null;const t=this.fragPlaying,i=s.level;t&&s.sn===t.sn&&t.level===i&&s.urlId===t.urlId||(this.fragPlaying=s,this.hls.trigger(d.FRAG_CHANGED,{frag:s}),t&&t.level===i||this.hls.trigger(d.LEVEL_SWITCHED,{level:i}))}}}get nextLevel(){const t=this.nextBufferedFrag;return t?t.level:-1}get currentFrag(){const t=this.media;return t?this.fragPlaying||this.getAppendedFrag(t.currentTime):null}get currentProgramDateTime(){const t=this.media;if(t){const s=t.currentTime,i=this.currentFrag;if(i&&u(s)&&u(i.programDateTime))return new Date(i.programDateTime+1e3*(s-i.start))}return null}get currentLevel(){const t=this.currentFrag;return t?t.level:-1}get nextBufferedFrag(){const t=this.currentFrag;return t?this.followingBufferedFrag(t):null}get forceStartLoad(){return this._forceStartLoad}}class Ce{constructor(t,s=0,i=0){this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=t,this.alpha_=t?Math.exp(Math.log(.5)/t):0,this.estimate_=s,this.totalWeight_=i}sample(t,s){const i=Math.pow(this.alpha_,t);this.estimate_=s*(1-i)+i*this.estimate_,this.totalWeight_+=t}getTotalWeight(){return this.totalWeight_}getEstimate(){if(this.alpha_){const t=1-Math.pow(this.alpha_,this.totalWeight_);if(t)return this.estimate_/t}return this.estimate_}}class Pe{constructor(t,s,i,e=100){this.defaultEstimate_=void 0,this.minWeight_=void 0,this.minDelayMs_=void 0,this.slow_=void 0,this.fast_=void 0,this.defaultTTFB_=void 0,this.ttfb_=void 0,this.defaultEstimate_=i,this.minWeight_=.001,this.minDelayMs_=50,this.slow_=new Ce(t),this.fast_=new Ce(s),this.defaultTTFB_=e,this.ttfb_=new Ce(t)}update(t,s){const{slow_:i,fast_:e,ttfb_:n}=this;i.halfLife!==t&&(this.slow_=new Ce(t,i.getEstimate(),i.getTotalWeight())),e.halfLife!==s&&(this.fast_=new Ce(s,e.getEstimate(),e.getTotalWeight())),n.halfLife!==t&&(this.ttfb_=new Ce(t,n.getEstimate(),n.getTotalWeight()))}sample(t,s){const i=(t=Math.max(t,this.minDelayMs_))/1e3,e=8*s/i;this.fast_.sample(i,e),this.slow_.sample(i,e)}sampleTTFB(t){const s=t/1e3,i=Math.sqrt(2)*Math.exp(-Math.pow(s,2)/2);this.ttfb_.sample(i,Math.max(t,5))}canEstimate(){return this.fast_.getTotalWeight()>=this.minWeight_}getEstimate(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_}getEstimateTTFB(){return this.ttfb_.getTotalWeight()>=this.minWeight_?this.ttfb_.getEstimate():this.defaultTTFB_}destroy(){}}class Re{constructor(){this.chunks=[],this.dataLength=0}push(t){this.chunks.push(t),this.dataLength+=t.length}flush(){const{chunks:t,dataLength:s}=this;let i;return t.length?(i=1===t.length?t[0]:function(t,s){const i=new Uint8Array(s);let e=0;for(let s=0;s<t.length;s++){const n=t[s];i.set(n,e),e+=n.length}return i}(t,s),this.reset(),i):new Uint8Array(0)}reset(){this.chunks.length=0,this.dataLength=0}}function Oe(t,s){if(t.length!==s.length)return!1;for(let i=0;i<t.length;i++)if(!Ne(t[i].attrs,s[i].attrs))return!1;return!0}function Ne(t,s){const i=t["STABLE-RENDITION-ID"];return i?i===s["STABLE-RENDITION-ID"]:!["LANGUAGE","NAME","CHARACTERISTICS","AUTOSELECT","DEFAULT","FORCED"].some((i=>t[i]!==s[i]))}class Ue{constructor(t){this.buffered=void 0;const s=(s,i,e)=>{if((i>>>=0)>e-1)throw new DOMException(`Failed to execute '${s}' on 'TimeRanges': The index provided (${i}) is greater than the maximum bound (${e})`);return t[i][s]};this.buffered={get length(){return t.length},end:i=>s("end",i,t.length),start:i=>s("start",i,t.length)}}}function Fe(t){const s=[];for(let i=0;i<t.length;i++){const e=t[i];"subtitles"!==e.kind&&"captions"!==e.kind||!e.label||s.push(t[i])}return s}class Be{constructor(t){this.buffers=void 0,this.queues={video:[],audio:[],audiovideo:[]},this.buffers=t}append(t,s){const i=this.queues[s];i.push(t),1===i.length&&this.buffers[s]&&this.executeNext(s)}insertAbort(t,s){this.queues[s].unshift(t),this.executeNext(s)}appendBlocker(t){let s;const i=new Promise((t=>{s=t}));return this.append({execute:s,onStart:()=>{},onComplete:()=>{},onError:()=>{}},t),i}executeNext(t){const{buffers:s,queues:i}=this,e=s[t],n=i[t];if(n.length){const s=n[0];try{s.execute()}catch(i){y.warn("[buffer-operation-queue]: Unhandled exception executing the current operation"),s.onError(i),null!=e&&e.updating||(n.shift(),this.executeNext(t))}}}shiftAndExecuteNext(t){this.queues[t].shift(),this.executeNext(t)}current(t){return this.queues[t][0]}}const _e=Rt(),je=/([ha]vc.)(?:\.[^.,]+)+/,Ke={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608,128:174,129:176,130:189,131:191,132:8482,133:162,134:163,135:9834,136:224,137:32,138:232,139:226,140:234,141:238,142:244,143:251,144:193,145:201,146:211,147:218,148:220,149:252,150:8216,151:161,152:42,153:8217,154:9473,155:169,156:8480,157:8226,158:8220,159:8221,160:192,161:194,162:199,163:200,164:202,165:203,166:235,167:206,168:207,169:239,170:212,171:217,172:249,173:219,174:171,175:187,176:195,177:227,178:205,179:204,180:236,181:210,182:242,183:213,184:245,185:123,186:125,187:92,188:94,189:95,190:124,191:8764,192:196,193:228,194:214,195:246,196:223,197:165,198:164,199:9475,200:197,201:229,202:216,203:248,204:9487,205:9491,206:9495,207:9499},He=function(t){let s=t;return Ke.hasOwnProperty(t)&&(s=Ke[t]),String.fromCharCode(s)},Ge=15,Ve=100,We={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},Xe={17:2,18:4,21:6,22:8,23:10,19:13,20:15},qe={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14},Ye={25:2,26:4,29:6,30:8,31:10,27:13,28:15},ze=["white","green","blue","cyan","red","yellow","magenta","black","transparent"];class Qe{constructor(){this.time=null,this.verboseLevel=0}log(t,s){if(this.verboseLevel>=t){const i="function"==typeof s?s():s;y.log(`${this.time} [${t}] ${i}`)}}}const Je=function(t){const s=[];for(let i=0;i<t.length;i++)s.push(t[i].toString(16));return s};class Ze{constructor(t,s,i,e,n){this.foreground=void 0,this.underline=void 0,this.italics=void 0,this.background=void 0,this.flash=void 0,this.foreground=t||"white",this.underline=s||!1,this.italics=i||!1,this.background=e||"black",this.flash=n||!1}reset(){this.foreground="white",this.underline=!1,this.italics=!1,this.background="black",this.flash=!1}setStyles(t){const s=["foreground","underline","italics","background","flash"];for(let i=0;i<s.length;i++){const e=s[i];t.hasOwnProperty(e)&&(this[e]=t[e])}}isDefault(){return"white"===this.foreground&&!this.underline&&!this.italics&&"black"===this.background&&!this.flash}equals(t){return this.foreground===t.foreground&&this.underline===t.underline&&this.italics===t.italics&&this.background===t.background&&this.flash===t.flash}copy(t){this.foreground=t.foreground,this.underline=t.underline,this.italics=t.italics,this.background=t.background,this.flash=t.flash}toString(){return"color="+this.foreground+", underline="+this.underline+", italics="+this.italics+", background="+this.background+", flash="+this.flash}}class tn{constructor(t,s,i,e,n,r){this.uchar=void 0,this.penState=void 0,this.uchar=t||" ",this.penState=new Ze(s,i,e,n,r)}reset(){this.uchar=" ",this.penState.reset()}setChar(t,s){this.uchar=t,this.penState.copy(s)}setPenState(t){this.penState.copy(t)}equals(t){return this.uchar===t.uchar&&this.penState.equals(t.penState)}copy(t){this.uchar=t.uchar,this.penState.copy(t.penState)}isEmpty(){return" "===this.uchar&&this.penState.isDefault()}}class sn{constructor(t){this.chars=void 0,this.pos=void 0,this.currPenState=void 0,this.cueStartTime=void 0,this.logger=void 0,this.chars=[];for(let t=0;t<Ve;t++)this.chars.push(new tn);this.logger=t,this.pos=0,this.currPenState=new Ze}equals(t){let s=!0;for(let i=0;i<Ve;i++)if(!this.chars[i].equals(t.chars[i])){s=!1;break}return s}copy(t){for(let s=0;s<Ve;s++)this.chars[s].copy(t.chars[s])}isEmpty(){let t=!0;for(let s=0;s<Ve;s++)if(!this.chars[s].isEmpty()){t=!1;break}return t}setCursor(t){this.pos!==t&&(this.pos=t),this.pos<0?(this.logger.log(3,"Negative cursor position "+this.pos),this.pos=0):this.pos>Ve&&(this.logger.log(3,"Too large cursor position "+this.pos),this.pos=Ve)}moveCursor(t){const s=this.pos+t;if(t>1)for(let t=this.pos+1;t<s+1;t++)this.chars[t].setPenState(this.currPenState);this.setCursor(s)}backSpace(){this.moveCursor(-1),this.chars[this.pos].setChar(" ",this.currPenState)}insertChar(t){t>=144&&this.backSpace();const s=He(t);this.pos>=Ve?this.logger.log(0,(()=>"Cannot insert "+t.toString(16)+" ("+s+") at position "+this.pos+". Skipping it!")):(this.chars[this.pos].setChar(s,this.currPenState),this.moveCursor(1))}clearFromPos(t){let s;for(s=t;s<Ve;s++)this.chars[s].reset()}clear(){this.clearFromPos(0),this.pos=0,this.currPenState.reset()}clearToEndOfRow(){this.clearFromPos(this.pos)}getTextString(){const t=[];let s=!0;for(let i=0;i<Ve;i++){const e=this.chars[i].uchar;" "!==e&&(s=!1),t.push(e)}return s?"":t.join("")}setPenStyles(t){this.currPenState.setStyles(t),this.chars[this.pos].setPenState(this.currPenState)}}class en{constructor(t){this.rows=void 0,this.currRow=void 0,this.nrRollUpRows=void 0,this.lastOutputScreen=void 0,this.logger=void 0,this.rows=[];for(let s=0;s<Ge;s++)this.rows.push(new sn(t));this.logger=t,this.currRow=14,this.nrRollUpRows=null,this.lastOutputScreen=null,this.reset()}reset(){for(let t=0;t<Ge;t++)this.rows[t].clear();this.currRow=14}equals(t){let s=!0;for(let i=0;i<Ge;i++)if(!this.rows[i].equals(t.rows[i])){s=!1;break}return s}copy(t){for(let s=0;s<Ge;s++)this.rows[s].copy(t.rows[s])}isEmpty(){let t=!0;for(let s=0;s<Ge;s++)if(!this.rows[s].isEmpty()){t=!1;break}return t}backSpace(){this.rows[this.currRow].backSpace()}clearToEndOfRow(){this.rows[this.currRow].clearToEndOfRow()}insertChar(t){this.rows[this.currRow].insertChar(t)}setPen(t){this.rows[this.currRow].setPenStyles(t)}moveCursor(t){this.rows[this.currRow].moveCursor(t)}setCursor(t){this.logger.log(2,"setCursor: "+t),this.rows[this.currRow].setCursor(t)}setPAC(t){this.logger.log(2,(()=>"pacData = "+JSON.stringify(t)));let s=t.row-1;if(this.nrRollUpRows&&s<this.nrRollUpRows-1&&(s=this.nrRollUpRows-1),this.nrRollUpRows&&this.currRow!==s){for(let t=0;t<Ge;t++)this.rows[t].clear();const t=this.currRow+1-this.nrRollUpRows,i=this.lastOutputScreen;if(i){const e=i.rows[t].cueStartTime,n=this.logger.time;if(e&&null!==n&&e<n)for(let e=0;e<this.nrRollUpRows;e++)this.rows[s-this.nrRollUpRows+e+1].copy(i.rows[t+e])}}this.currRow=s;const i=this.rows[this.currRow];if(null!==t.indent){const s=Math.max(t.indent-1,0);i.setCursor(t.indent),t.color=i.chars[s].penState.foreground}this.setPen({foreground:t.color,underline:t.underline,italics:t.italics,background:"black",flash:!1})}setBkgData(t){this.logger.log(2,(()=>"bkgData = "+JSON.stringify(t))),this.backSpace(),this.setPen(t),this.insertChar(32)}setRollUpRows(t){this.nrRollUpRows=t}rollUp(){if(null===this.nrRollUpRows)return void this.logger.log(3,"roll_up but nrRollUpRows not set yet");this.logger.log(1,(()=>this.getDisplayText()));const t=this.rows.splice(this.currRow+1-this.nrRollUpRows,1)[0];t.clear(),this.rows.splice(this.currRow,0,t),this.logger.log(2,"Rolling up")}getDisplayText(t){t=t||!1;const s=[];let i="",e=-1;for(let i=0;i<Ge;i++){const n=this.rows[i].getTextString();n&&(e=i+1,s.push(t?"Row "+e+": '"+n+"'":n.trim()))}return s.length>0&&(i=t?"["+s.join(" | ")+"]":s.join("\n")),i}getTextAndFormat(){return this.rows}}class nn{constructor(t,s,i){this.chNr=void 0,this.outputFilter=void 0,this.mode=void 0,this.verbose=void 0,this.displayedMemory=void 0,this.nonDisplayedMemory=void 0,this.lastOutputScreen=void 0,this.currRollUpRow=void 0,this.writeScreen=void 0,this.cueStartTime=void 0,this.logger=void 0,this.chNr=t,this.outputFilter=s,this.mode=null,this.verbose=0,this.displayedMemory=new en(i),this.nonDisplayedMemory=new en(i),this.lastOutputScreen=new en(i),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null,this.logger=i}reset(){this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),this.outputFilter.reset(),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null}getHandler(){return this.outputFilter}setHandler(t){this.outputFilter=t}setPAC(t){this.writeScreen.setPAC(t)}setBkgData(t){this.writeScreen.setBkgData(t)}setMode(t){t!==this.mode&&(this.mode=t,this.logger.log(2,(()=>"MODE="+t)),"MODE_POP-ON"===this.mode?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),"MODE_ROLL-UP"!==this.mode&&(this.displayedMemory.nrRollUpRows=null,this.nonDisplayedMemory.nrRollUpRows=null),this.mode=t)}insertChars(t){for(let s=0;s<t.length;s++)this.writeScreen.insertChar(t[s]);const s=this.writeScreen===this.displayedMemory?"DISP":"NON_DISP";this.logger.log(2,(()=>s+": "+this.writeScreen.getDisplayText(!0))),"MODE_PAINT-ON"!==this.mode&&"MODE_ROLL-UP"!==this.mode||(this.logger.log(1,(()=>"DISPLAYED: "+this.displayedMemory.getDisplayText(!0))),this.outputDataUpdate())}ccRCL(){this.logger.log(2,"RCL - Resume Caption Loading"),this.setMode("MODE_POP-ON")}ccBS(){this.logger.log(2,"BS - BackSpace"),"MODE_TEXT"!==this.mode&&(this.writeScreen.backSpace(),this.writeScreen===this.displayedMemory&&this.outputDataUpdate())}ccAOF(){}ccAON(){}ccDER(){this.logger.log(2,"DER- Delete to End of Row"),this.writeScreen.clearToEndOfRow(),this.outputDataUpdate()}ccRU(t){this.logger.log(2,"RU("+t+") - Roll Up"),this.writeScreen=this.displayedMemory,this.setMode("MODE_ROLL-UP"),this.writeScreen.setRollUpRows(t)}ccFON(){this.logger.log(2,"FON - Flash On"),this.writeScreen.setPen({flash:!0})}ccRDC(){this.logger.log(2,"RDC - Resume Direct Captioning"),this.setMode("MODE_PAINT-ON")}ccTR(){this.logger.log(2,"TR"),this.setMode("MODE_TEXT")}ccRTD(){this.logger.log(2,"RTD"),this.setMode("MODE_TEXT")}ccEDM(){this.logger.log(2,"EDM - Erase Displayed Memory"),this.displayedMemory.reset(),this.outputDataUpdate(!0)}ccCR(){this.logger.log(2,"CR - Carriage Return"),this.writeScreen.rollUp(),this.outputDataUpdate(!0)}ccENM(){this.logger.log(2,"ENM - Erase Non-displayed Memory"),this.nonDisplayedMemory.reset()}ccEOC(){if(this.logger.log(2,"EOC - End Of Caption"),"MODE_POP-ON"===this.mode){const t=this.displayedMemory;this.displayedMemory=this.nonDisplayedMemory,this.nonDisplayedMemory=t,this.writeScreen=this.nonDisplayedMemory,this.logger.log(1,(()=>"DISP: "+this.displayedMemory.getDisplayText()))}this.outputDataUpdate(!0)}ccTO(t){this.logger.log(2,"TO("+t+") - Tab Offset"),this.writeScreen.moveCursor(t)}ccMIDROW(t){const s={flash:!1};if(s.underline=t%2==1,s.italics=t>=46,s.italics)s.foreground="white";else{const i=Math.floor(t/2)-16;s.foreground=["white","green","blue","cyan","red","yellow","magenta"][i]}this.logger.log(2,"MIDROW: "+JSON.stringify(s)),this.writeScreen.setPen(s)}outputDataUpdate(t=!1){const s=this.logger.time;null!==s&&this.outputFilter&&(null!==this.cueStartTime||this.displayedMemory.isEmpty()?this.displayedMemory.equals(this.lastOutputScreen)||(this.outputFilter.newCue(this.cueStartTime,s,this.lastOutputScreen),t&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue(),this.cueStartTime=this.displayedMemory.isEmpty()?null:s):this.cueStartTime=s,this.lastOutputScreen.copy(this.displayedMemory))}cueSplitAtTime(t){this.outputFilter&&(this.displayedMemory.isEmpty()||(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,t,this.displayedMemory),this.cueStartTime=t))}}class rn{constructor(t,s,i){this.channels=void 0,this.currentChannel=0,this.cmdHistory=void 0,this.logger=void 0;const e=new Qe;this.channels=[null,new nn(t,s,e),new nn(t+1,i,e)],this.cmdHistory={a:null,b:null},this.logger=e}getHandler(t){return this.channels[t].getHandler()}setHandler(t,s){this.channels[t].setHandler(s)}addData(t,s){let i,e,n,r=!1;this.logger.time=t;for(let t=0;t<s.length;t+=2)if(e=127&s[t],n=127&s[t+1],0!==e||0!==n){if(this.logger.log(3,"["+Je([s[t],s[t+1]])+"] -> ("+Je([e,n])+")"),i=this.parseCmd(e,n),i||(i=this.parseMidrow(e,n)),i||(i=this.parsePAC(e,n)),i||(i=this.parseBackgroundAttributes(e,n)),!i&&(r=this.parseChars(e,n),r)){const t=this.currentChannel;t&&t>0?this.channels[t].insertChars(r):this.logger.log(2,"No channel found yet. TEXT-MODE?")}i||r||this.logger.log(2,"Couldn't parse cleaned data "+Je([e,n])+" orig: "+Je([s[t],s[t+1]]))}}parseCmd(t,s){const{cmdHistory:i}=this;if(!((20===t||28===t||21===t||29===t)&&s>=32&&s<=47||(23===t||31===t)&&s>=33&&s<=35))return!1;if(on(t,s,i))return hn(null,null,i),this.logger.log(3,"Repeated command ("+Je([t,s])+") is dropped"),!0;const e=20===t||21===t||23===t?1:2,n=this.channels[e];return 20===t||21===t||28===t||29===t?32===s?n.ccRCL():33===s?n.ccBS():34===s?n.ccAOF():35===s?n.ccAON():36===s?n.ccDER():37===s?n.ccRU(2):38===s?n.ccRU(3):39===s?n.ccRU(4):40===s?n.ccFON():41===s?n.ccRDC():42===s?n.ccTR():43===s?n.ccRTD():44===s?n.ccEDM():45===s?n.ccCR():46===s?n.ccENM():47===s&&n.ccEOC():n.ccTO(s-32),hn(t,s,i),this.currentChannel=e,!0}parseMidrow(t,s){let i=0;if((17===t||25===t)&&s>=32&&s<=47){if(i=17===t?1:2,i!==this.currentChannel)return this.logger.log(0,"Mismatch channel in midrow parsing"),!1;const e=this.channels[i];return!!e&&(e.ccMIDROW(s),this.logger.log(3,"MIDROW ("+Je([t,s])+")"),!0)}return!1}parsePAC(t,s){let i;const e=this.cmdHistory;if(!((t>=17&&t<=23||t>=25&&t<=31)&&s>=64&&s<=127||(16===t||24===t)&&s>=64&&s<=95))return!1;if(on(t,s,e))return hn(null,null,e),!0;const n=t<=23?1:2;i=s>=64&&s<=95?1===n?We[t]:qe[t]:1===n?Xe[t]:Ye[t];const r=this.channels[n];return!!r&&(r.setPAC(this.interpretPAC(i,s)),hn(t,s,e),this.currentChannel=n,!0)}interpretPAC(t,s){let i;const e={color:null,italics:!1,indent:null,underline:!1,row:t};return i=s>95?s-96:s-64,e.underline=1==(1&i),i<=13?e.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(i/2)]:i<=15?(e.italics=!0,e.color="white"):e.indent=4*Math.floor((i-16)/2),e}parseChars(t,s){let i,e=null,n=null;if(t>=25?(i=2,n=t-8):(i=1,n=t),n>=17&&n<=19){let t;t=17===n?s+80:18===n?s+112:s+144,this.logger.log(2,"Special char '"+He(t)+"' in channel "+i),e=[t]}else t>=32&&t<=127&&(e=0===s?[t]:[t,s]);if(e){const i=Je(e);this.logger.log(3,"Char codes = "+i.join(",")),hn(t,s,this.cmdHistory)}return e}parseBackgroundAttributes(t,s){if(!((16===t||24===t)&&s>=32&&s<=47||(23===t||31===t)&&s>=45&&s<=47))return!1;let i;const e={};return 16===t||24===t?(i=Math.floor((s-32)/2),e.background=ze[i],s%2==1&&(e.background=e.background+"_semi")):45===s?e.background="transparent":(e.foreground="black",47===s&&(e.underline=!0)),this.channels[t<=23?1:2].setBkgData(e),hn(t,s,this.cmdHistory),!0}reset(){for(let t=0;t<Object.keys(this.channels).length;t++){const s=this.channels[t];s&&s.reset()}this.cmdHistory={a:null,b:null}}cueSplitAtTime(t){for(let s=0;s<this.channels.length;s++){const i=this.channels[s];i&&i.cueSplitAtTime(t)}}}function hn(t,s,i){i.a=t,i.b=s}function on(t,s,i){return i.a===t&&i.b===s}class an{constructor(t,s){this.timelineController=void 0,this.cueRanges=[],this.trackName=void 0,this.startTime=null,this.endTime=null,this.screen=null,this.timelineController=t,this.trackName=s}dispatchCue(){null!==this.startTime&&(this.timelineController.addCues(this.trackName,this.startTime,this.endTime,this.screen,this.cueRanges),this.startTime=null)}newCue(t,s,i){(null===this.startTime||this.startTime>t)&&(this.startTime=t),this.endTime=s,this.screen=i,this.timelineController.createCaptionsTrack(this.trackName)}reset(){this.cueRanges=[],this.startTime=null}}var ln=function(){if("undefined"!=typeof self&&self.VTTCue)return self.VTTCue;const t=["","lr","rl"],s=["start","middle","end","left","right"];function i(t,s){if("string"!=typeof s)return!1;if(!Array.isArray(t))return!1;const i=s.toLowerCase();return!!~t.indexOf(i)&&i}function e(t){return i(s,t)}function n(t){let s=1;for(;s<arguments.length;s++){const i=arguments[s];for(const s in i)t[s]=i[s]}return t}function r(s,r,h){const o=this,a={enumerable:!0};o.hasBeenReset=!1;let l="",c=!1,u=s,d=r,f=h,m=null,g="",v=!0,p="auto",y="start",w=50,b="middle",T=50,S="middle";Object.defineProperty(o,"id",n({},a,{get:function(){return l},set:function(t){l=""+t}})),Object.defineProperty(o,"pauseOnExit",n({},a,{get:function(){return c},set:function(t){c=!!t}})),Object.defineProperty(o,"startTime",n({},a,{get:function(){return u},set:function(t){if("number"!=typeof t)throw new TypeError("Start time must be set to a number.");u=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"endTime",n({},a,{get:function(){return d},set:function(t){if("number"!=typeof t)throw new TypeError("End time must be set to a number.");d=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"text",n({},a,{get:function(){return f},set:function(t){f=""+t,this.hasBeenReset=!0}})),Object.defineProperty(o,"region",n({},a,{get:function(){return m},set:function(t){m=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"vertical",n({},a,{get:function(){return g},set:function(s){const e=function(s){return i(t,s)}(s);if(!1===e)throw new SyntaxError("An invalid or illegal string was specified.");g=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"snapToLines",n({},a,{get:function(){return v},set:function(t){v=!!t,this.hasBeenReset=!0}})),Object.defineProperty(o,"line",n({},a,{get:function(){return p},set:function(t){if("number"!=typeof t&&"auto"!==t)throw new SyntaxError("An invalid number or illegal string was specified.");p=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"lineAlign",n({},a,{get:function(){return y},set:function(t){const s=e(t);if(!s)throw new SyntaxError("An invalid or illegal string was specified.");y=s,this.hasBeenReset=!0}})),Object.defineProperty(o,"position",n({},a,{get:function(){return w},set:function(t){if(t<0||t>100)throw new Error("Position must be between 0 and 100.");w=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"positionAlign",n({},a,{get:function(){return b},set:function(t){const s=e(t);if(!s)throw new SyntaxError("An invalid or illegal string was specified.");b=s,this.hasBeenReset=!0}})),Object.defineProperty(o,"size",n({},a,{get:function(){return T},set:function(t){if(t<0||t>100)throw new Error("Size must be between 0 and 100.");T=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"align",n({},a,{get:function(){return S},set:function(t){const s=e(t);if(!s)throw new SyntaxError("An invalid or illegal string was specified.");S=s,this.hasBeenReset=!0}})),o.displayState=void 0}return r.prototype.getCueAsHTML=function(){return self.WebVTT.convertCueToDOMTree(self,this.text)},r}();class cn{decode(t,s){if(!t)return"";if("string"!=typeof t)throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(t))}}function un(t){function s(t,s,i,e){return 3600*(0|t)+60*(0|s)+(0|i)+parseFloat(e||0)}const i=t.match(/^(?:(\d+):)?(\d{2}):(\d{2})(\.\d+)?/);return i?parseFloat(i[2])>59?s(i[2],i[3],0,i[4]):s(i[1],i[2],i[3],i[4]):null}class dn{constructor(){this.values=Object.create(null)}set(t,s){this.get(t)||""===s||(this.values[t]=s)}get(t,s,i){return i?this.has(t)?this.values[t]:s[i]:this.has(t)?this.values[t]:s}has(t){return t in this.values}alt(t,s,i){for(let e=0;e<i.length;++e)if(s===i[e]){this.set(t,s);break}}integer(t,s){/^-?\d+$/.test(s)&&this.set(t,parseInt(s,10))}percent(t,s){if(/^([\d]{1,3})(\.[\d]*)?%$/.test(s)){const i=parseFloat(s);if(i>=0&&i<=100)return this.set(t,i),!0}return!1}}function fn(t,s,i,e){const n=e?t.split(e):[t];for(const t in n){if("string"!=typeof n[t])continue;const e=n[t].split(i);2===e.length&&s(e[0],e[1])}}const mn=new ln(0,0,""),gn="middle"===mn.align?"middle":"center";function vn(t,s,i){const e=t;function n(){const s=un(t);if(null===s)throw new Error("Malformed timestamp: "+e);return t=t.replace(/^[^\sa-zA-Z-]+/,""),s}function r(){t=t.replace(/^\s+/,"")}if(r(),s.startTime=n(),r(),"--\x3e"!==t.slice(0,3))throw new Error("Malformed time stamp (time stamps must be separated by '--\x3e'): "+e);t=t.slice(3),r(),s.endTime=n(),r(),function(t,s){const e=new dn;fn(t,(function(t,s){let n;switch(t){case"region":for(let n=i.length-1;n>=0;n--)if(i[n].id===s){e.set(t,i[n].region);break}break;case"vertical":e.alt(t,s,["rl","lr"]);break;case"line":n=s.split(","),e.integer(t,n[0]),e.percent(t,n[0])&&e.set("snapToLines",!1),e.alt(t,n[0],["auto"]),2===n.length&&e.alt("lineAlign",n[1],["start",gn,"end"]);break;case"position":n=s.split(","),e.percent(t,n[0]),2===n.length&&e.alt("positionAlign",n[1],["start",gn,"end","line-left","line-right","auto"]);break;case"size":e.percent(t,s);break;case"align":e.alt(t,s,["start",gn,"end","left","right"])}}),/:/,/\s/),s.region=e.get("region",null),s.vertical=e.get("vertical","");let n=e.get("line","auto");"auto"===n&&-1===mn.line&&(n=-1),s.line=n,s.lineAlign=e.get("lineAlign","start"),s.snapToLines=e.get("snapToLines",!0),s.size=e.get("size",100),s.align=e.get("align",gn);let r=e.get("position","auto");"auto"===r&&50===mn.position&&(r="start"===s.align||"left"===s.align?0:"end"===s.align||"right"===s.align?100:50),s.position=r}(t,s)}function pn(t){return t.replace(/<br(?: \/)?>/gi,"\n")}class yn{constructor(){this.state="INITIAL",this.buffer="",this.decoder=new cn,this.regionList=[],this.cue=null,this.oncue=void 0,this.onparsingerror=void 0,this.onflush=void 0}parse(t){const s=this;function i(){let t=s.buffer,i=0;for(t=pn(t);i<t.length&&"\r"!==t[i]&&"\n"!==t[i];)++i;const e=t.slice(0,i);return"\r"===t[i]&&++i,"\n"===t[i]&&++i,s.buffer=t.slice(i),e}t&&(s.buffer+=s.decoder.decode(t,{stream:!0}));try{let t="";if("INITIAL"===s.state){if(!/\r\n|\n/.test(s.buffer))return this;t=i();const e=t.match(/^()?WEBVTT([ \t].*)?$/);if(null==e||!e[0])throw new Error("Malformed WebVTT signature.");s.state="HEADER"}let e=!1;for(;s.buffer;){if(!/\r\n|\n/.test(s.buffer))return this;switch(e?e=!1:t=i(),s.state){case"HEADER":/:/.test(t)?fn(t,(function(){}),/:/):t||(s.state="ID");continue;case"NOTE":t||(s.state="ID");continue;case"ID":if(/^NOTE($|[ \t])/.test(t)){s.state="NOTE";break}if(!t)continue;if(s.cue=new ln(0,0,""),s.state="CUE",-1===t.indexOf("--\x3e")){s.cue.id=t;continue}case"CUE":if(!s.cue){s.state="BADCUE";continue}try{vn(t,s.cue,s.regionList)}catch(t){s.cue=null,s.state="BADCUE";continue}s.state="CUETEXT";continue;case"CUETEXT":{const i=-1!==t.indexOf("--\x3e");if(!t||i&&(e=!0)){s.oncue&&s.cue&&s.oncue(s.cue),s.cue=null,s.state="ID";continue}if(null===s.cue)continue;s.cue.text&&(s.cue.text+="\n"),s.cue.text+=t}continue;case"BADCUE":t||(s.state="ID")}}}catch(t){"CUETEXT"===s.state&&s.cue&&s.oncue&&s.oncue(s.cue),s.cue=null,s.state="INITIAL"===s.state?"BADWEBVTT":"BADCUE"}return this}flush(){const t=this;try{if((t.cue||"HEADER"===t.state)&&(t.buffer+="\n\n",t.parse()),"INITIAL"===t.state||"BADWEBVTT"===t.state)throw new Error("Malformed WebVTT signature.")}catch(s){t.onparsingerror&&t.onparsingerror(s)}return t.onflush&&t.onflush(),this}}const wn=/\r\n|\n\r|\n|\r/g,bn=function(t,s,i=0){return t.slice(i,i+s.length)===s},Tn=function(t){let s=5381,i=t.length;for(;i;)s=33*s^t.charCodeAt(--i);return(s>>>0).toString()};function Sn(t,s,i){return Tn(t.toString())+Tn(s.toString())+Tn(i)}const En="stpp.ttml.im1t",kn=/^(\d{2,}):(\d{2}):(\d{2}):(\d{2})\.?(\d+)?$/,$n=/^(\d*(?:\.\d*)?)(h|m|s|ms|f|t)$/,An={left:"start",center:"center",right:"end",start:"start",end:"end"};function Ln(t,s,i,e){const n=vt(new Uint8Array(t),["mdat"]);if(0===n.length)return void e(new Error("Could not parse IMSC1 mdat"));const r=n.map((t=>nt(t))),h=function(t,s,i=1,e=!1){return ae(t,1,1/i,e)}(s.baseTime,0,s.timescale);try{r.forEach((t=>i(function(t,s){const i=(new DOMParser).parseFromString(t,"text/xml").getElementsByTagName("tt")[0];if(!i)throw new Error("Invalid ttml");const e={frameRate:30,subFrameRate:1,frameRateMultiplier:0,tickRate:0},n=Object.keys(e).reduce(((t,s)=>(t[s]=i.getAttribute(`ttp:${s}`)||e[s],t)),{}),r="preserve"!==i.getAttribute("xml:space"),h=Dn(Mn(i,"styling","style")),o=Dn(Mn(i,"layout","region")),a=Mn(i,"body","[begin]");return[].map.call(a,(t=>{const i=xn(t,r);if(!i||!t.hasAttribute("begin"))return null;const e=Pn(t.getAttribute("begin"),n),a=Pn(t.getAttribute("dur"),n);let l=Pn(t.getAttribute("end"),n);if(null===e)throw Cn(t);if(null===l){if(null===a)throw Cn(t);l=e+a}const u=new ln(e-s,l-s,i);u.id=Sn(u.startTime,u.endTime,u.text);const d=function(t,s,i){const e="http://www.w3.org/ns/ttml#styling";let n=null;const r=null!=t&&t.hasAttribute("style")?t.getAttribute("style"):null;return r&&i.hasOwnProperty(r)&&(n=i[r]),["displayAlign","textAlign","color","backgroundColor","fontSize","fontFamily"].reduce(((i,r)=>{const h=In(s,e,r)||In(t,e,r)||In(n,e,r);return h&&(i[r]=h),i}),{})}(o[t.getAttribute("region")],h[t.getAttribute("style")],h),{textAlign:f}=d;if(f){const t=An[f];t&&(u.lineAlign=t),u.align=f}return c(u,d),u})).filter((t=>null!==t))}(t,h))))}catch(t){e(t)}}function Mn(t,s,i){const e=t.getElementsByTagName(s)[0];return e?[].slice.call(e.querySelectorAll(i)):[]}function Dn(t){return t.reduce(((t,s)=>{const i=s.getAttribute("xml:id");return i&&(t[i]=s),t}),{})}function xn(t,s){return[].slice.call(t.childNodes).reduce(((t,i,e)=>{var n;return"br"===i.nodeName&&e?t+"\n":null!=(n=i.childNodes)&&n.length?xn(i,s):s?t+i.textContent.trim().replace(/\s+/g," "):t+i.textContent}),"")}function In(t,s,i){return t&&t.hasAttributeNS(s,i)?t.getAttributeNS(s,i):null}function Cn(t){return new Error(`Could not parse ttml timestamp ${t}`)}function Pn(t,s){if(!t)return null;let i=un(t);return null===i&&(kn.test(t)?i=function(t,s){const i=kn.exec(t);return 3600*(0|i[1])+60*(0|i[2])+(0|i[3])+((0|i[4])+(0|i[5])/s.subFrameRate)/s.frameRate}(t,s):$n.test(t)&&(i=function(t,s){const i=$n.exec(t),e=Number(i[1]);switch(i[2]){case"h":return 3600*e;case"m":return 60*e;case"ms":return 1e3*e;case"f":return e/s.frameRate;case"t":return e/s.tickRate}return e}(t,s))),i}function Rn(t,s){return!!t&&t.label===s.name&&!(t.textTrack1||t.textTrack2)}class On{constructor(t){this.hls=void 0,this.autoLevelCapping=void 0,this.firstLevel=void 0,this.media=void 0,this.restrictedLevels=void 0,this.timer=void 0,this.clientRect=void 0,this.streamController=void 0,this.hls=t,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.firstLevel=-1,this.media=null,this.restrictedLevels=[],this.timer=void 0,this.clientRect=null,this.registerListeners()}setStreamController(t){this.streamController=t}destroy(){this.unregisterListener(),this.hls.config.capLevelToPlayerSize&&this.stopCapping(),this.media=null,this.clientRect=null,this.hls=this.streamController=null}registerListeners(){const{hls:t}=this;t.on(d.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),t.on(d.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(d.MANIFEST_PARSED,this.onManifestParsed,this),t.on(d.BUFFER_CODECS,this.onBufferCodecs,this),t.on(d.MEDIA_DETACHING,this.onMediaDetaching,this)}unregisterListener(){const{hls:t}=this;t.off(d.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),t.off(d.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(d.MANIFEST_PARSED,this.onManifestParsed,this),t.off(d.BUFFER_CODECS,this.onBufferCodecs,this),t.off(d.MEDIA_DETACHING,this.onMediaDetaching,this)}onFpsDropLevelCapping(t,s){const i=this.hls.levels[s.droppedLevel];this.isLevelAllowed(i)&&this.restrictedLevels.push({bitrate:i.bitrate,height:i.height,width:i.width})}onMediaAttaching(t,s){this.media=s.media instanceof HTMLVideoElement?s.media:null,this.clientRect=null}onManifestParsed(t,s){const i=this.hls;this.restrictedLevels=[],this.firstLevel=s.firstLevel,i.config.capLevelToPlayerSize&&s.video&&this.startCapping()}onBufferCodecs(t,s){this.hls.config.capLevelToPlayerSize&&s.video&&this.startCapping()}onMediaDetaching(){this.stopCapping()}detectPlayerSize(){if(this.media&&this.mediaHeight>0&&this.mediaWidth>0){const t=this.hls.levels;if(t.length){const s=this.hls;s.autoLevelCapping=this.getMaxLevel(t.length-1),s.autoLevelCapping>this.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=s.autoLevelCapping}}}getMaxLevel(t){const s=this.hls.levels;if(!s.length)return-1;const i=s.filter(((s,i)=>this.isLevelAllowed(s)&&i<=t));return this.clientRect=null,On.getMaxLevelByMediaSize(i,this.mediaWidth,this.mediaHeight)}startCapping(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,this.hls.firstLevel=this.getMaxLevel(this.firstLevel),self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())}stopCapping(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)}getDimensions(){if(this.clientRect)return this.clientRect;const t=this.media,s={width:0,height:0};if(t){const i=t.getBoundingClientRect();s.width=i.width,s.height=i.height,s.width||s.height||(s.width=i.right-i.left||t.width||0,s.height=i.bottom-i.top||t.height||0)}return this.clientRect=s,s}get mediaWidth(){return this.getDimensions().width*this.contentScaleFactor}get mediaHeight(){return this.getDimensions().height*this.contentScaleFactor}get contentScaleFactor(){let t=1;if(!this.hls.config.ignoreDevicePixelRatio)try{t=self.devicePixelRatio}catch(t){}return t}isLevelAllowed(t){return!this.restrictedLevels.some((s=>t.bitrate===s.bitrate&&t.width===s.width&&t.height===s.height))}static getMaxLevelByMediaSize(t,s,i){if(null==t||!t.length)return-1;let e=t.length-1;for(let h=0;h<t.length;h+=1){const o=t[h];if((o.width>=s||o.height>=i)&&(n=o,!(r=t[h+1])||n.width!==r.width||n.height!==r.height)){e=h;break}}var n,r;return e}}const Nn="[eme]";class Un{constructor(t){this.hls=void 0,this.config=void 0,this.media=null,this.keyFormatPromise=null,this.keySystemAccessPromises={},this._requestLicenseFailureCount=0,this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},this.setMediaKeysQueue=Un.CDMCleanupPromise?[Un.CDMCleanupPromise]:[],this.onMediaEncrypted=this._onMediaEncrypted.bind(this),this.onWaitingForKey=this._onWaitingForKey.bind(this),this.debug=y.debug.bind(y,Nn),this.log=y.log.bind(y,Nn),this.warn=y.warn.bind(y,Nn),this.error=y.error.bind(y,Nn),this.hls=t,this.config=t.config,this.registerListeners()}destroy(){this.unregisterListeners(),this.onMediaDetached();const t=this.config;t.requestMediaKeySystemAccessFunc=null,t.licenseXhrSetup=t.licenseResponseCallback=void 0,t.drmSystems=t.drmSystemOptions={},this.hls=this.onMediaEncrypted=this.onWaitingForKey=this.keyIdToKeySessionPromise=null,this.config=null}registerListeners(){this.hls.on(d.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(d.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.on(d.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(d.MANIFEST_LOADED,this.onManifestLoaded,this)}unregisterListeners(){this.hls.off(d.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(d.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.off(d.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.off(d.MANIFEST_LOADED,this.onManifestLoaded,this)}getLicenseServerUrl(t){const{drmSystems:s,widevineLicenseUrl:i}=this.config,e=s[t];if(e)return e.licenseUrl;if(t===R.WIDEVINE&&i)return i;throw new Error(`no license server URL configured for key-system "${t}"`)}getServerCertificateUrl(t){const{drmSystems:s}=this.config,i=s[t];if(i)return i.serverCertificateUrl;this.log(`No Server Certificate in config.drmSystems["${t}"]`)}attemptKeySystemAccess(t){const s=this.hls.levels,i=(t,s,i)=>!!t&&i.indexOf(t)===s,e=s.map((t=>t.audioCodec)).filter(i),n=s.map((t=>t.videoCodec)).filter(i);return e.length+n.length===0&&n.push("avc1.42e01e"),new Promise(((s,i)=>{const r=t=>{const h=t.shift();this.getMediaKeysPromise(h,e,n).then((t=>s({keySystem:h,mediaKeys:t}))).catch((s=>{t.length?r(t):i(s instanceof Fn?s:new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_NO_ACCESS,error:s,fatal:!0},s.message))}))};r(t)}))}requestMediaKeySystemAccess(t,s){const{requestMediaKeySystemAccessFunc:i}=this.config;if("function"!=typeof i){let t=`Configured requestMediaKeySystemAccess is not a function ${i}`;return null===H&&"http:"===self.location.protocol&&(t=`navigator.requestMediaKeySystemAccess is not available over insecure protocol ${location.protocol}`),Promise.reject(new Error(t))}return i(t,s)}getMediaKeysPromise(t,s,i){const e=function(t,s,i,e){let n;switch(t){case R.FAIRPLAY:n=["cenc","sinf"];break;case R.WIDEVINE:case R.PLAYREADY:n=["cenc"];break;case R.CLEARKEY:n=["cenc","keyids"];break;default:throw new Error(`Unknown key-system: ${t}`)}return function(t,s,i,e){return[{initDataTypes:t,persistentState:e.persistentState||"not-allowed",distinctiveIdentifier:e.distinctiveIdentifier||"not-allowed",sessionTypes:e.sessionTypes||[e.sessionType||"temporary"],audioCapabilities:s.map((t=>({contentType:`audio/mp4; codecs="${t}"`,robustness:e.audioRobustness||"",encryptionScheme:e.audioEncryptionScheme||null}))),videoCapabilities:i.map((t=>({contentType:`video/mp4; codecs="${t}"`,robustness:e.videoRobustness||"",encryptionScheme:e.videoEncryptionScheme||null})))}]}(n,s,i,e)}(t,s,i,this.config.drmSystemOptions),n=this.keySystemAccessPromises[t];let r=null==n?void 0:n.keySystemAccess;if(!r){this.log(`Requesting encrypted media "${t}" key-system access with config: ${JSON.stringify(e)}`),r=this.requestMediaKeySystemAccess(t,e);const s=this.keySystemAccessPromises[t]={keySystemAccess:r};return r.catch((s=>{this.log(`Failed to obtain access to key-system "${t}": ${s}`)})),r.then((i=>{this.log(`Access for key-system "${i.keySystem}" obtained`);const e=this.fetchServerCertificate(t);return this.log(`Create media-keys for "${t}"`),s.mediaKeys=i.createMediaKeys().then((s=>(this.log(`Media-keys created for "${t}"`),e.then((i=>i?this.setMediaKeysServerCertificate(s,t,i):s))))),s.mediaKeys.catch((s=>{this.error(`Failed to create media-keys for "${t}"}: ${s}`)})),s.mediaKeys}))}return r.then((()=>n.mediaKeys))}createMediaKeySessionContext({decryptdata:t,keySystem:s,mediaKeys:i}){this.log(`Creating key-system session "${s}" keyId: ${ot(t.keyId||[])}`);const e=i.createSession(),n={decryptdata:t,keySystem:s,mediaKeys:i,mediaKeysSession:e,keyStatus:"status-pending"};return this.mediaKeySessions.push(n),n}renewKeySession(t){const s=t.decryptdata;if(s.pssh){const i=this.createMediaKeySessionContext(t),e=this.getKeyIdString(s);this.keyIdToKeySessionPromise[e]=this.generateRequestWithPreferredKeySession(i,"cenc",s.pssh,"expired")}else this.warn("Could not renew expired session. Missing pssh initData.");this.removeSession(t)}getKeyIdString(t){if(!t)throw new Error("Could not read keyId of undefined decryptdata");if(null===t.keyId)throw new Error("keyId is null");return ot(t.keyId)}updateKeySession(t,s){var i;const e=t.mediaKeysSession;return this.log(`Updating key-session "${e.sessionId}" for keyID ${ot((null==(i=t.decryptdata)?void 0:i.keyId)||[])}\n } (data length: ${s?s.byteLength:s})`),e.update(s)}selectKeySystemFormat(t){const s=Object.keys(t.levelkeys||{});return this.keyFormatPromise||(this.log(`Selecting key-system from fragment (sn: ${t.sn} ${t.type}: ${t.level}) key formats ${s.join(", ")}`),this.keyFormatPromise=this.getKeyFormatPromise(s)),this.keyFormatPromise}getKeyFormatPromise(t){return new Promise(((s,i)=>{const e=K(this.config),n=t.map(B).filter((t=>!!t&&-1!==e.indexOf(t)));return this.getKeySystemSelectionPromise(n).then((({keySystem:t})=>{const e=j(t);e?s(e):i(new Error(`Unable to find format for key-system "${t}"`))})).catch(i)}))}loadKey(t){const s=t.keyInfo.decryptdata,i=this.getKeyIdString(s),e=`(keyId: ${i} format: "${s.keyFormat}" method: ${s.method} uri: ${s.uri})`;this.log(`Starting session for key ${e}`);let n=this.keyIdToKeySessionPromise[i];return n||(n=this.keyIdToKeySessionPromise[i]=this.getKeySystemForKeyPromise(s).then((({keySystem:i,mediaKeys:n})=>(this.throwIfDestroyed(),this.log(`Handle encrypted media sn: ${t.frag.sn} ${t.frag.type}: ${t.frag.level} using key ${e}`),this.attemptSetMediaKeys(i,n).then((()=>{this.throwIfDestroyed();const t=this.createMediaKeySessionContext({keySystem:i,mediaKeys:n,decryptdata:s});return this.generateRequestWithPreferredKeySession(t,"cenc",s.pssh,"playlist-key")}))))),n.catch((t=>this.handleError(t)))),n}throwIfDestroyed(t="Invalid state"){if(!this.hls)throw new Error("invalid state")}handleError(t){this.hls&&(this.error(t.message),this.hls.trigger(d.ERROR,t instanceof Fn?t.data:{type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_NO_KEYS,error:t,fatal:!0}))}getKeySystemForKeyPromise(t){const s=this.getKeyIdString(t),i=this.keyIdToKeySessionPromise[s];if(!i){const s=B(t.keyFormat),i=s?[s]:K(this.config);return this.attemptKeySystemAccess(i)}return i}getKeySystemSelectionPromise(t){if(t.length||(t=K(this.config)),0===t.length)throw new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_NO_CONFIGURED_LICENSE,fatal:!0},`Missing key-system license configuration options ${JSON.stringify({drmSystems:this.config.drmSystems})}`);return this.attemptKeySystemAccess(t)}_onMediaEncrypted(t){const{initDataType:s,initData:i}=t;if(this.debug(`"${t.type}" event: init data type: "${s}"`),null===i)return;let e,n;if("sinf"===s&&this.config.drmSystems[R.FAIRPLAY]){const t=ut(new Uint8Array(i));try{const s=C(JSON.parse(t).sinf),i=wt(new Uint8Array(s));if(!i)return;e=i.subarray(8,24),n=R.FAIRPLAY}catch(t){return void this.warn('Failed to parse sinf "encrypted" event message initData')}}else{const t=function(t){if(!(t instanceof ArrayBuffer)||t.byteLength<32)return null;const s={version:0,systemId:"",kids:null,data:null},i=new DataView(t),e=i.getUint32(0);if(t.byteLength!==e&&e>44)return null;if(1886614376!==i.getUint32(4))return null;if(s.version=i.getUint32(8)>>>24,s.version>1)return null;s.systemId=ot(new Uint8Array(t,12,16));const n=i.getUint32(28);if(0===s.version){if(e-32<n)return null;s.data=new Uint8Array(t,32,n)}else if(1===s.version){s.kids=[];for(let i=0;i<n;i++)s.kids.push(new Uint8Array(t,32+16*i,16))}return s}(i);if(null===t)return;0===t.version&&t.systemId===_&&t.data&&(e=t.data.subarray(8,24)),n=function(t){if(t===_)return R.WIDEVINE}(t.systemId)}if(!n||!e)return;const r=ot(e),{keyIdToKeySessionPromise:h,mediaKeySessions:o}=this;let a=h[r];for(let t=0;t<o.length;t++){const n=o[t],l=n.decryptdata;if(l.pssh||!l.keyId)continue;const c=ot(l.keyId);if(r===c||-1!==l.uri.replace(/-/g,"").indexOf(r)){a=h[c],delete h[c],l.pssh=new Uint8Array(i),l.keyId=e,a=h[r]=a.then((()=>this.generateRequestWithPreferredKeySession(n,s,i,"encrypted-event-key-match")));break}}a||(a=h[r]=this.getKeySystemSelectionPromise([n]).then((({keySystem:t,mediaKeys:n})=>{var h;this.throwIfDestroyed();const o=new Lt("ISO-23001-7",r,null!=(h=j(t))?h:"");return o.pssh=new Uint8Array(i),o.keyId=e,this.attemptSetMediaKeys(t,n).then((()=>{this.throwIfDestroyed();const e=this.createMediaKeySessionContext({decryptdata:o,keySystem:t,mediaKeys:n});return this.generateRequestWithPreferredKeySession(e,s,i,"encrypted-event-no-match")}))}))),a.catch((t=>this.handleError(t)))}_onWaitingForKey(t){this.log(`"${t.type}" event`)}attemptSetMediaKeys(t,s){const i=this.setMediaKeysQueue.slice();this.log(`Setting media-keys for "${t}"`);const e=Promise.all(i).then((()=>{if(!this.media)throw new Error("Attempted to set mediaKeys without media element attached");return this.media.setMediaKeys(s)}));return this.setMediaKeysQueue.push(e),e.then((()=>{this.log(`Media-keys set for "${t}"`),i.push(e),this.setMediaKeysQueue=this.setMediaKeysQueue.filter((t=>-1===i.indexOf(t)))}))}generateRequestWithPreferredKeySession(t,s,i,e){var n,r;const h=null==(n=this.config.drmSystems)||null==(r=n[t.keySystem])?void 0:r.generateRequest;if(h)try{const e=h.call(this.hls,s,i,t);if(!e)throw new Error("Invalid response from configured generateRequest filter");s=e.initDataType,i=t.decryptdata.pssh=e.initData?new Uint8Array(e.initData):null}catch(t){var o;if(this.warn(t.message),null!=(o=this.hls)&&o.config.debug)throw t}if(null===i)return this.log(`Skipping key-session request for "${e}" (no initData)`),Promise.resolve(t);const a=this.getKeyIdString(t.decryptdata);this.log(`Generating key-session request for "${e}": ${a} (init data type: ${s} length: ${i?i.byteLength:null})`);const l=new Le;t.mediaKeysSession.onmessage=s=>{const i=t.mediaKeysSession;if(!i)return void l.emit("error",new Error("invalid state"));const{messageType:e,message:n}=s;this.log(`"${e}" message event for session "${i.sessionId}" message size: ${n.byteLength}`),"license-request"===e||"license-renewal"===e?this.renewLicense(t,n).catch((t=>{this.handleError(t),l.emit("error",t)})):"license-release"===e?t.keySystem===R.FAIRPLAY&&(this.updateKeySession(t,P("acknowledged")),this.removeSession(t)):this.warn(`unhandled media key message type "${e}"`)},t.mediaKeysSession.onkeystatuseschange=()=>{if(!t.mediaKeysSession)return void l.emit("error",new Error("invalid state"));this.onKeyStatusChange(t);const s=t.keyStatus;l.emit("keyStatus",s),"expired"===s&&(this.warn(`${t.keySystem} expired for key ${a}`),this.renewKeySession(t))};const c=new Promise(((t,s)=>{l.on("error",s),l.on("keyStatus",(i=>{i.startsWith("usable")?t():"output-restricted"===i?s(new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED,fatal:!1},"HDCP level output restricted")):"internal-error"===i?s(new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_STATUS_INTERNAL_ERROR,fatal:!0},`key status changed to "${i}"`)):"expired"===i?s(new Error("key expired while generating request")):this.warn(`unhandled key status change "${i}"`)}))}));return t.mediaKeysSession.generateRequest(s,i).then((()=>{var s;this.log(`Request generated for key-session "${null==(s=t.mediaKeysSession)?void 0:s.sessionId}" keyId: ${a}`)})).catch((t=>{throw new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_NO_SESSION,error:t,fatal:!1},`Error generating key-session request: ${t}`)})).then((()=>c)).catch((s=>{throw l.removeAllListeners(),this.removeSession(t),s})).then((()=>(l.removeAllListeners(),t)))}onKeyStatusChange(t){t.mediaKeysSession.keyStatuses.forEach(((s,i)=>{this.log(`key status change "${s}" for keyStatuses keyId: ${ot("buffer"in i?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):new Uint8Array(i))} session keyId: ${ot(new Uint8Array(t.decryptdata.keyId||[]))} uri: ${t.decryptdata.uri}`),t.keyStatus=s}))}fetchServerCertificate(t){const s=this.config,i=new(0,s.loader)(s),e=this.getServerCertificateUrl(t);return e?(this.log(`Fetching serverCertificate for "${t}"`),new Promise(((n,r)=>{const h={responseType:"arraybuffer",url:e},o=s.certLoadPolicy.default;i.load(h,{loadPolicy:o,timeout:o.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0},{onSuccess:t=>{n(t.data)},onError:(s,i,n)=>{r(new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED,fatal:!0,networkDetails:n,response:a({url:h.url,data:void 0},s)},`"${t}" certificate request failed (${e}). Status: ${s.code} (${s.text})`))},onTimeout:(s,i,n)=>{r(new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED,fatal:!0,networkDetails:n,response:{url:h.url,data:void 0}},`"${t}" certificate request timed out (${e})`))},onAbort:()=>{r(new Error("aborted"))}})}))):Promise.resolve()}setMediaKeysServerCertificate(t,s,i){return new Promise(((e,n)=>{t.setServerCertificate(i).then((n=>{this.log(`setServerCertificate ${n?"success":"not supported by CDM"} (${null==i?void 0:i.byteLength}) on "${s}"`),e(t)})).catch((t=>{n(new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED,error:t,fatal:!0},t.message))}))}))}renewLicense(t,s){return this.requestLicense(t,new Uint8Array(s)).then((s=>this.updateKeySession(t,new Uint8Array(s)).catch((t=>{throw new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_SESSION_UPDATE_FAILED,error:t,fatal:!0},t.message)}))))}setupLicenseXHR(t,s,i,e){const n=this.config.licenseXhrSetup;return n?Promise.resolve().then((()=>{if(!i.decryptdata)throw new Error("Key removed");return n.call(this.hls,t,s,i,e)})).catch((r=>{if(!i.decryptdata)throw r;return t.open("POST",s,!0),n.call(this.hls,t,s,i,e)})).then((i=>(t.readyState||t.open("POST",s,!0),{xhr:t,licenseChallenge:i||e}))):(t.open("POST",s,!0),Promise.resolve({xhr:t,licenseChallenge:e}))}requestLicense(t,s){const i=this.config.keyLoadPolicy.default;return new Promise(((e,n)=>{const r=this.getLicenseServerUrl(t.keySystem);this.log(`Sending license request to URL: ${r}`);const h=new XMLHttpRequest;h.responseType="arraybuffer",h.onreadystatechange=()=>{if(!this.hls||!t.mediaKeysSession)return n(new Error("invalid state"));if(4===h.readyState)if(200===h.status){this._requestLicenseFailureCount=0;let s=h.response;this.log(`License received ${s instanceof ArrayBuffer?s.byteLength:s}`);const i=this.config.licenseResponseCallback;if(i)try{s=i.call(this.hls,h,r,t)}catch(t){this.error(t)}e(s)}else{const o=i.errorRetry,a=o?o.maxNumRetry:0;this._requestLicenseFailureCount++,this._requestLicenseFailureCount>a||h.status>=400&&h.status<500?n(new Fn({type:f.KEY_SYSTEM_ERROR,details:m.KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0,networkDetails:h,response:{url:r,data:void 0,code:h.status,text:h.statusText}},`License Request XHR failed (${r}). Status: ${h.status} (${h.statusText})`)):(this.warn(`Retrying license request, ${a-this._requestLicenseFailureCount+1} attempts left`),this.requestLicense(t,s).then(e,n))}},t.licenseXhr&&t.licenseXhr.readyState!==XMLHttpRequest.DONE&&t.licenseXhr.abort(),t.licenseXhr=h,this.setupLicenseXHR(h,r,t,s).then((({xhr:t,licenseChallenge:s})=>{t.send(s)}))}))}onMediaAttached(t,s){if(!this.config.emeEnabled)return;const i=s.media;this.media=i,i.addEventListener("encrypted",this.onMediaEncrypted),i.addEventListener("waitingforkey",this.onWaitingForKey)}onMediaDetached(){const t=this.media,s=this.mediaKeySessions;t&&(t.removeEventListener("encrypted",this.onMediaEncrypted),t.removeEventListener("waitingforkey",this.onWaitingForKey),this.media=null),this._requestLicenseFailureCount=0,this.setMediaKeysQueue=[],this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},Lt.clearKeyUriToKeyIdMap();const i=s.length;Un.CDMCleanupPromise=Promise.all(s.map((t=>this.removeSession(t))).concat(null==t?void 0:t.setMediaKeys(null).catch((s=>{this.log(`Could not clear media keys: ${s}. media.src: ${null==t?void 0:t.src}`)})))).then((()=>{i&&(this.log("finished closing key sessions and clearing media keys"),s.length=0)})).catch((s=>{this.log(`Could not close sessions and clear media keys: ${s}. media.src: ${null==t?void 0:t.src}`)}))}onManifestLoading(){this.keyFormatPromise=null}onManifestLoaded(t,{sessionKeys:s}){if(s&&this.config.emeEnabled&&!this.keyFormatPromise){const t=s.reduce(((t,s)=>(-1===t.indexOf(s.keyFormat)&&t.push(s.keyFormat),t)),[]);this.log(`Selecting key-system from session-keys ${t.join(", ")}`),this.keyFormatPromise=this.getKeyFormatPromise(t)}}removeSession(t){const{mediaKeysSession:s,licenseXhr:i}=t;if(s){this.log(`Remove licenses and keys and close session ${s.sessionId}`),s.onmessage=null,s.onkeystatuseschange=null,i&&i.readyState!==XMLHttpRequest.DONE&&i.abort(),t.mediaKeysSession=t.decryptdata=t.licenseXhr=void 0;const e=this.mediaKeySessions.indexOf(t);return e>-1&&this.mediaKeySessions.splice(e,1),s.remove().catch((t=>{this.log(`Could not remove session: ${t}`)})).then((()=>s.close())).catch((t=>{this.log(`Could not close session: ${t}`)}))}}}Un.CDMCleanupPromise=void 0;class Fn extends Error{constructor(t,s){super(s),this.data=void 0,t.error||(t.error=new Error(s)),this.data=t,t.err=t.error}}var Bn="a",_n="av";class jn{constructor(t){this.hls=void 0,this.config=void 0,this.media=void 0,this.sid=void 0,this.cid=void 0,this.useHeaders=!1,this.initialized=!1,this.starved=!1,this.buffering=!0,this.audioBuffer=void 0,this.videoBuffer=void 0,this.onWaiting=()=>{this.initialized&&(this.starved=!0),this.buffering=!0},this.onPlaying=()=>{this.initialized||(this.initialized=!0),this.buffering=!1},this.applyPlaylistData=t=>{try{this.apply(t,{ot:"m",su:!this.initialized})}catch(t){y.warn("Could not generate manifest CMCD data.",t)}},this.applyFragmentData=t=>{try{const s=t.frag,i=this.hls.levels[s.level],e=this.getObjectType(s),n={d:1e3*s.duration,ot:e};"v"!==e&&e!==Bn&&e!=_n||(n.br=i.bitrate/1e3,n.tb=this.getTopBandwidth(e)/1e3,n.bl=this.getBufferLength(e)),this.apply(t,n)}catch(t){y.warn("Could not generate segment CMCD data.",t)}},this.hls=t;const s=this.config=t.config,{cmcd:i}=s;null!=i&&(s.pLoader=this.createPlaylistLoader(),s.fLoader=this.createFragmentLoader(),this.sid=i.sessionId||jn.uuid(),this.cid=i.contentId,this.useHeaders=!0===i.useHeaders,this.registerListeners())}registerListeners(){const t=this.hls;t.on(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(d.MEDIA_DETACHED,this.onMediaDetached,this),t.on(d.BUFFER_CREATED,this.onBufferCreated,this)}unregisterListeners(){const t=this.hls;t.off(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(d.MEDIA_DETACHED,this.onMediaDetached,this),t.off(d.BUFFER_CREATED,this.onBufferCreated,this)}destroy(){this.unregisterListeners(),this.onMediaDetached(),this.hls=this.config=this.audioBuffer=this.videoBuffer=null}onMediaAttached(t,s){this.media=s.media,this.media.addEventListener("waiting",this.onWaiting),this.media.addEventListener("playing",this.onPlaying)}onMediaDetached(){this.media&&(this.media.removeEventListener("waiting",this.onWaiting),this.media.removeEventListener("playing",this.onPlaying),this.media=null)}onBufferCreated(t,s){var i,e;this.audioBuffer=null==(i=s.tracks.audio)?void 0:i.buffer,this.videoBuffer=null==(e=s.tracks.video)?void 0:e.buffer}createData(){var t;return{v:1,sf:"h",sid:this.sid,cid:this.cid,pr:null==(t=this.media)?void 0:t.playbackRate,mtp:this.hls.bandwidthEstimate/1e3}}apply(t,s={}){if(c(s,this.createData()),this.starved&&("i"===s.ot||"v"===s.ot||s.ot===_n)&&(s.bs=!0,s.su=!0,this.starved=!1),null==s.su&&(s.su=this.buffering),this.useHeaders){const i=jn.toHeaders(s);if(!Object.keys(i).length)return;t.headers||(t.headers={}),c(t.headers,i)}else{const i=jn.toQuery(s);if(!i)return;t.url=jn.appendQueryToUri(t.url,i)}}getObjectType(t){const{type:s}=t;return"subtitle"===s?"tt":"initSegment"===t.sn?"i":"audio"===s?Bn:"main"===s?this.hls.audioTracks.length?"v":_n:void 0}getTopBandwidth(t){let s,i=0;const e=this.hls;if(t===Bn)s=e.audioTracks;else{const t=e.maxAutoLevel;s=e.levels.slice(0,t>-1?t+1:e.levels.length)}for(const t of s)t.bitrate>i&&(i=t.bitrate);return i>0?i:NaN}getBufferLength(t){const s=this.hls.media,i=t===Bn?this.audioBuffer:this.videoBuffer;return i&&s?1e3*ei.bufferInfo(i,s.currentTime,this.config.maxBufferHole).len:NaN}createPlaylistLoader(){const{pLoader:t}=this.config,s=this.applyPlaylistData,i=t||this.config.loader;return class{constructor(t){this.loader=void 0,this.loader=new i(t)}get stats(){return this.loader.stats}get context(){return this.loader.context}destroy(){this.loader.destroy()}abort(){this.loader.abort()}load(t,i,e){s(t),this.loader.load(t,i,e)}}}createFragmentLoader(){const{fLoader:t}=this.config,s=this.applyFragmentData,i=t||this.config.loader;return class{constructor(t){this.loader=void 0,this.loader=new i(t)}get stats(){return this.loader.stats}get context(){return this.loader.context}destroy(){this.loader.destroy()}abort(){this.loader.abort()}load(t,i,e){s(t),this.loader.load(t,i,e)}}}static uuid(){const t=URL.createObjectURL(new Blob),s=t.toString();return URL.revokeObjectURL(t),s.slice(s.lastIndexOf("/")+1)}static serialize(t){const s=[],i=t=>!Number.isNaN(t)&&null!=t&&""!==t&&!1!==t,e=t=>Math.round(t),n=t=>100*e(t/100),r={br:e,d:e,bl:n,dl:n,mtp:n,nor:t=>encodeURIComponent(t),rtp:n,tb:e},h=Object.keys(t||{}).sort();for(const e of h){let n=t[e];if(!i(n))continue;if("v"===e&&1===n)continue;if("pr"==e&&1===n)continue;const h=r[e];h&&(n=h(n));const o=typeof n;let a;a="ot"===e||"sf"===e||"st"===e?`${e}=${n}`:"boolean"===o?e:"number"===o?`${e}=${n}`:`${e}=${JSON.stringify(n)}`,s.push(a)}return s.join(",")}static toHeaders(t){const s=Object.keys(t),i={},e=["Object","Request","Session","Status"],n=[{},{},{},{}],r={br:0,d:0,ot:0,tb:0,bl:1,dl:1,mtp:1,nor:1,nrr:1,su:1,cid:2,pr:2,sf:2,sid:2,st:2,v:2,bs:3,rtp:3};for(const i of s)n[null!=r[i]?r[i]:1][i]=t[i];for(let t=0;t<n.length;t++){const s=jn.serialize(n[t]);s&&(i[`CMCD-${e[t]}`]=s)}return i}static toQuery(t){return`CMCD=${encodeURIComponent(jn.serialize(t))}`}static appendQueryToUri(t,s){if(!s)return t;const i=t.includes("?")?"&":"?";return`${t}${i}${s}`}}function Kn(t,s,i,e){t&&Object.keys(s).forEach((n=>{const r=t.filter((t=>t.groupId===n)).map((t=>{const r=c({},t);return r.details=void 0,r.attrs=new T(r.attrs),r.url=r.attrs.URI=Hn(t.url,t.attrs["STABLE-RENDITION-ID"],"PER-RENDITION-URIS",i),r.groupId=r.attrs["GROUP-ID"]=s[n],r.attrs["PATHWAY-ID"]=e,r}));t.push(...r)}))}function Hn(t,s,i,e){const{HOST:n,PARAMS:r,[i]:h}=e;let o;s&&(o=null==h?void 0:h[s],o&&(t=o));const a=new self.URL(t);return n&&!o&&(a.host=n),r&&Object.keys(r).sort().forEach((t=>{t&&a.searchParams.set(t,r[t])})),a.href}const Gn=/^age:\s*[\d.]+\s*$/im;class Vn{constructor(t){this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=void 0,this.loader=null,this.stats=void 0,this.xhrSetup=t&&t.xhrSetup||null,this.stats=new k,this.retryDelay=0}destroy(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null}abortInternal(){const t=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),t&&(t.onreadystatechange=null,t.onprogress=null,4!==t.readyState&&(this.stats.aborted=!0,t.abort()))}abort(){var t;this.abortInternal(),null!=(t=this.callbacks)&&t.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)}load(t,s,i){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=t,this.config=s,this.callbacks=i,this.loadInternal()}loadInternal(){const{config:t,context:s}=this;if(!t)return;const i=this.loader=new self.XMLHttpRequest,e=this.stats;e.loading.first=0,e.loaded=0;const n=this.xhrSetup;n?Promise.resolve().then((()=>{if(!this.stats.aborted)return n(i,s.url)})).catch((()=>(i.open("GET",s.url,!0),n(i,s.url)))).then((()=>{this.stats.aborted||this.openAndSendXhr(i,s,t)})).catch((t=>{this.callbacks.onError({code:i.status,text:t.message},s,i,e)})):this.openAndSendXhr(i,s,t)}openAndSendXhr(t,s,i){t.readyState||t.open("GET",s.url,!0);const e=this.context.headers,{maxTimeToFirstByteMs:n,maxLoadTimeMs:r}=i.loadPolicy;if(e)for(const s in e)t.setRequestHeader(s,e[s]);s.rangeEnd&&t.setRequestHeader("Range","bytes="+s.rangeStart+"-"+(s.rangeEnd-1)),t.onreadystatechange=this.readystatechange.bind(this),t.onprogress=this.loadprogress.bind(this),t.responseType=s.responseType,self.clearTimeout(this.requestTimeout),i.timeout=n&&u(n)?n:r,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),i.timeout),t.send()}readystatechange(){const{context:t,loader:s,stats:i}=this;if(!t||!s)return;const e=s.readyState,n=this.config;if(!i.aborted&&e>=2&&(0===i.loading.first&&(i.loading.first=Math.max(self.performance.now(),i.loading.start),n.timeout!==n.loadPolicy.maxLoadTimeMs&&(self.clearTimeout(this.requestTimeout),n.timeout=n.loadPolicy.maxLoadTimeMs,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),n.loadPolicy.maxLoadTimeMs-(i.loading.first-i.loading.start)))),4===e)){self.clearTimeout(this.requestTimeout),s.onreadystatechange=null,s.onprogress=null;const e=s.status,r="text"!==s.responseType;if(e>=200&&e<300&&(r&&s.response||null!==s.responseText)){i.loading.end=Math.max(self.performance.now(),i.loading.first);const n=r?s.response:s.responseText;if(i.loaded=i.total="arraybuffer"===s.responseType?n.byteLength:n.length,i.bwEstimate=8e3*i.total/(i.loading.end-i.loading.first),!this.callbacks)return;const h=this.callbacks.onProgress;if(h&&h(i,t,n,s),!this.callbacks)return;this.callbacks.onSuccess({url:s.responseURL,data:n,code:e},i,t,s)}else{const r=n.loadPolicy.errorRetry;Is(r,i.retry,!1,e)?this.retry(r):(y.error(`${e} while loading ${t.url}`),this.callbacks.onError({code:e,text:s.statusText},t,s,i))}}}loadtimeout(){var t;const s=null==(t=this.config)?void 0:t.loadPolicy.timeoutRetry;if(Is(s,this.stats.retry,!0))this.retry(s);else{y.warn(`timeout while loading ${this.context.url}`);const t=this.callbacks;t&&(this.abortInternal(),t.onTimeout(this.stats,this.context,this.loader))}}retry(t){const{context:s,stats:i}=this;this.retryDelay=Ds(t,i.retry),i.retry++,y.warn(`${status?"HTTP Status "+status:"Timeout"} while loading ${s.url}, retrying ${i.retry}/${t.maxNumRetry} in ${this.retryDelay}ms`),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay)}loadprogress(t){const s=this.stats;s.loaded=t.loaded,t.lengthComputable&&(s.total=t.total)}getCacheAge(){let t=null;if(this.loader&&Gn.test(this.loader.getAllResponseHeaders())){const s=this.loader.getResponseHeader("age");t=s?parseFloat(s):null}return t}getResponseHeader(t){return this.loader&&new RegExp(`^${t}:\\s*[\\d.]+\\s*$`,"im").test(this.loader.getAllResponseHeaders())?this.loader.getResponseHeader(t):null}}const Wn=/(\d+)-(\d+)\/(\d+)/;class Xn{constructor(t){this.fetchSetup=void 0,this.requestTimeout=void 0,this.request=void 0,this.response=void 0,this.controller=void 0,this.context=void 0,this.config=null,this.callbacks=null,this.stats=void 0,this.loader=null,this.fetchSetup=t.fetchSetup||qn,this.controller=new self.AbortController,this.stats=new k}destroy(){this.loader=this.callbacks=null,this.abortInternal()}abortInternal(){const t=this.response;null!=t&&t.ok||(this.stats.aborted=!0,this.controller.abort())}abort(){var t;this.abortInternal(),null!=(t=this.callbacks)&&t.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.response)}load(t,s,i){const e=this.stats;if(e.loading.start)throw new Error("Loader can only be used once.");e.loading.start=self.performance.now();const n=function(t,s){const i={method:"GET",mode:"cors",credentials:"same-origin",signal:s,headers:new self.Headers(c({},t.headers))};return t.rangeEnd&&i.headers.set("Range","bytes="+t.rangeStart+"-"+String(t.rangeEnd-1)),i}(t,this.controller.signal),r=i.onProgress,h="arraybuffer"===t.responseType,o=h?"byteLength":"length",{maxTimeToFirstByteMs:a,maxLoadTimeMs:l}=s.loadPolicy;this.context=t,this.config=s,this.callbacks=i,this.request=this.fetchSetup(t,n),self.clearTimeout(this.requestTimeout),s.timeout=a&&u(a)?a:l,this.requestTimeout=self.setTimeout((()=>{this.abortInternal(),i.onTimeout(e,t,this.response)}),s.timeout),self.fetch(this.request).then((n=>{this.response=this.loader=n;const o=Math.max(self.performance.now(),e.loading.start);if(self.clearTimeout(this.requestTimeout),s.timeout=l,this.requestTimeout=self.setTimeout((()=>{this.abortInternal(),i.onTimeout(e,t,this.response)}),l-(o-e.loading.start)),!n.ok){const{status:t,statusText:s}=n;throw new Yn(s||"fetch, bad network response",t,n)}return e.loading.first=o,e.total=function(t){const s=t.get("Content-Range");if(s){const t=function(t){const s=Wn.exec(t);if(s)return parseInt(s[2])-parseInt(s[1])+1}(s);if(u(t))return t}const i=t.get("Content-Length");if(i)return parseInt(i)}(n.headers)||e.total,r&&u(s.highWaterMark)?this.loadProgressively(n,e,t,s.highWaterMark,r):h?n.arrayBuffer():"json"===t.responseType?n.json():n.text()})).then((n=>{const{response:h}=this;self.clearTimeout(this.requestTimeout),e.loading.end=Math.max(self.performance.now(),e.loading.first);const a=n[o];a&&(e.loaded=e.total=a);const l={url:h.url,data:n,code:h.status};r&&!u(s.highWaterMark)&&r(e,t,n,h),i.onSuccess(l,e,t,h)})).catch((s=>{self.clearTimeout(this.requestTimeout),e.aborted||i.onError({code:s&&s.code||0,text:s?s.message:null},t,s?s.details:null,e)}))}getCacheAge(){let t=null;if(this.response){const s=this.response.headers.get("age");t=s?parseFloat(s):null}return t}getResponseHeader(t){return this.response?this.response.headers.get(t):null}loadProgressively(t,s,i,e=0,n){const r=new Re,h=t.body.getReader(),o=()=>h.read().then((h=>{if(h.done)return r.dataLength&&n(s,i,r.flush(),t),Promise.resolve(new ArrayBuffer(0));const a=h.value,l=a.length;return s.loaded+=l,l<e||r.dataLength?(r.push(a),r.dataLength>=e&&n(s,i,r.flush(),t)):n(s,i,a,t),o()})).catch((()=>Promise.reject()));return o()}}function qn(t,s){return new self.Request(t.url,s)}class Yn extends Error{constructor(t,s,i){super(t),this.code=void 0,this.details=void 0,this.code=s,this.details=i}}const zn=/\s/,Qn={newCue(t,s,i,e){const n=[];let r,h,o,a,l;const c=self.VTTCue||self.TextTrackCue;for(let d=0;d<e.rows.length;d++)if(r=e.rows[d],o=!0,a=0,l="",!r.isEmpty()){var u;for(let t=0;t<r.chars.length;t++)zn.test(r.chars[t].uchar)&&o?a++:(l+=r.chars[t].uchar,o=!1);r.cueStartTime=s,s===i&&(i+=1e-4),a>=16?a--:a++;const e=pn(l.trim()),f=Sn(s,i,e);null!=t&&null!=(u=t.cues)&&u.getCueById(f)||(h=new c(s,i,e),h.id=f,h.line=d+1,h.align="left",h.position=10+Math.min(80,10*Math.floor(8*a/32)),n.push(h))}return t&&n.length&&(n.sort(((t,s)=>"auto"===t.line||"auto"===s.line?0:t.line>8&&s.line>8?s.line-t.line:t.line-s.line)),n.forEach((s=>as(t,s)))),n}},Jn=a(a({autoStartLoad:!0,startPosition:-1,defaultAudioCodec:void 0,debug:!1,capLevelOnFPSDrop:!1,capLevelToPlayerSize:!1,ignoreDevicePixelRatio:!1,initialLiveManifestSize:1,maxBufferLength:30,backBufferLength:1/0,maxBufferSize:6e7,maxBufferHole:.1,highBufferWatchdogPeriod:2,nudgeOffset:.1,nudgeMaxRetry:3,maxFragLookUpTolerance:.25,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,liveSyncDuration:void 0,liveMaxLatencyDuration:void 0,maxLiveSyncPlaybackRate:1,liveDurationInfinity:!1,liveBackBufferLength:null,maxMaxBufferLength:600,enableWorker:!0,workerPath:null,enableSoftwareAES:!0,startLevel:void 0,startFragPrefetch:!1,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:3,loader:Vn,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:class{constructor(t){this.hls=void 0,this.lastLevelLoadSec=0,this.lastLoadedFragLevel=0,this._nextAutoLevel=-1,this.timer=-1,this.onCheck=this._abandonRulesCheck.bind(this),this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.bwEstimator=void 0,this.hls=t;const s=t.config;this.bwEstimator=new Pe(s.abrEwmaSlowVoD,s.abrEwmaFastVoD,s.abrEwmaDefaultEstimate),this.registerListeners()}registerListeners(){const{hls:t}=this;t.on(d.FRAG_LOADING,this.onFragLoading,this),t.on(d.FRAG_LOADED,this.onFragLoaded,this),t.on(d.FRAG_BUFFERED,this.onFragBuffered,this),t.on(d.LEVEL_SWITCHING,this.onLevelSwitching,this),t.on(d.LEVEL_LOADED,this.onLevelLoaded,this)}unregisterListeners(){const{hls:t}=this;t.off(d.FRAG_LOADING,this.onFragLoading,this),t.off(d.FRAG_LOADED,this.onFragLoaded,this),t.off(d.FRAG_BUFFERED,this.onFragBuffered,this),t.off(d.LEVEL_SWITCHING,this.onLevelSwitching,this),t.off(d.LEVEL_LOADED,this.onLevelLoaded,this)}destroy(){this.unregisterListeners(),this.clearTimer(),this.hls=this.onCheck=null,this.fragCurrent=this.partCurrent=null}onFragLoading(t,s){var i;const e=s.frag;this.ignoreFragment(e)||(this.fragCurrent=e,this.partCurrent=null!=(i=s.part)?i:null,this.clearTimer(),this.timer=self.setInterval(this.onCheck,100))}onLevelSwitching(t,s){this.clearTimer()}getTimeToLoadFrag(t,s,i,e){return t+i/s+(e?this.lastLevelLoadSec:0)}onLevelLoaded(t,s){const i=this.hls.config,{total:e,bwEstimate:n}=s.stats;u(e)&&u(n)&&(this.lastLevelLoadSec=8*e/n),s.details.live?this.bwEstimator.update(i.abrEwmaSlowLive,i.abrEwmaFastLive):this.bwEstimator.update(i.abrEwmaSlowVoD,i.abrEwmaFastVoD)}_abandonRulesCheck(){const{fragCurrent:t,partCurrent:s,hls:i}=this,{autoLevelEnabled:e,media:n}=i;if(!t||!n)return;const r=performance.now(),h=s?s.stats:t.stats,o=s?s.duration:t.duration,a=r-h.loading.start;if(h.aborted||h.loaded&&h.loaded===h.total||0===t.level)return this.clearTimer(),void(this._nextAutoLevel=-1);if(!e||n.paused||!n.playbackRate||!n.readyState)return;const l=i.mainForwardBufferInfo;if(null===l)return;const c=this.bwEstimator.getEstimateTTFB(),f=Math.abs(n.playbackRate);if(a<=Math.max(c,o/(2*f)*1e3))return;const m=l.len/f;if(m>=2*o/f)return;const g=h.loading.first?h.loading.first-h.loading.start:-1,v=h.loaded&&g>-1,p=this.bwEstimator.getEstimate(),{levels:w,minAutoLevel:b}=i,T=h.total||Math.max(h.loaded,Math.round(o*w[t.level].maxBitrate/8));let S=a-g;S<1&&v&&(S=Math.min(a,8*h.loaded/p));const E=v?1e3*h.loaded/S:0,k=E?(T-h.loaded)/E:8*T/p+c/1e3;if(k<=m)return;const $=E?8*E:p;let A,L=Number.POSITIVE_INFINITY;for(A=t.level-1;A>b&&(L=this.getTimeToLoadFrag(c/1e3,$,o*w[A].maxBitrate,!w[A].details),!(L<m));A--);L>=k||L>10*o||(i.nextLoadLevel=A,v?this.bwEstimator.sample(a-Math.min(c,g),h.loaded):this.bwEstimator.sampleTTFB(a),this.clearTimer(),y.warn(`[abr] Fragment ${t.sn}${s?" part "+s.index:""} of level ${t.level} is loading too slowly;\n Time to underbuffer: ${m.toFixed(3)} s\n Estimated load time for current fragment: ${k.toFixed(3)} s\n Estimated load time for down switch fragment: ${L.toFixed(3)} s\n TTFB estimate: ${g}\n Current BW estimate: ${u(p)?(p/1024).toFixed(3):"Unknown"} Kb/s\n New BW estimate: ${(this.bwEstimator.getEstimate()/1024).toFixed(3)} Kb/s\n Aborting and switching to level ${A}`),t.loader&&(this.fragCurrent=this.partCurrent=null,t.abortRequests()),i.trigger(d.FRAG_LOAD_EMERGENCY_ABORTED,{frag:t,part:s,stats:h}))}onFragLoaded(t,{frag:s,part:i}){const e=i?i.stats:s.stats;if(s.type===ss&&this.bwEstimator.sampleTTFB(e.loading.first-e.loading.start),!this.ignoreFragment(s)){if(this.clearTimer(),this.lastLoadedFragLevel=s.level,this._nextAutoLevel=-1,this.hls.config.abrMaxWithRealBitrate){const t=this.hls.levels[s.level],n=(t.loaded?t.loaded.bytes:0)+e.loaded,r=(t.loaded?t.loaded.duration:0)+(i?i.duration:s.duration);t.loaded={bytes:n,duration:r},t.realBitrate=Math.round(8*n/r)}s.bitrateTest&&(this.onFragBuffered(d.FRAG_BUFFERED,{stats:e,frag:s,part:i,id:s.type}),s.bitrateTest=!1)}}onFragBuffered(t,s){const{frag:i,part:e}=s,n=null!=e&&e.stats.loaded?e.stats:i.stats;if(n.aborted)return;if(this.ignoreFragment(i))return;const r=n.parsing.end-n.loading.start-Math.min(n.loading.first-n.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(r,n.loaded),n.bwEstimate=this.bwEstimator.getEstimate(),this.bitrateTestDelay=i.bitrateTest?r/1e3:0}ignoreFragment(t){return t.type!==ss||"initSegment"===t.sn}clearTimer(){self.clearInterval(this.timer)}get nextAutoLevel(){const t=this._nextAutoLevel;if(-1!==t&&!this.bwEstimator.canEstimate())return t;let s=this.getNextABRAutoLevel();if(-1!==t){const i=this.hls.levels;if(i.length>Math.max(t,s)&&i[t].loadError<=i[s].loadError)return t}return-1!==t&&(s=Math.min(t,s)),s}getNextABRAutoLevel(){const{fragCurrent:t,partCurrent:s,hls:i}=this,{maxAutoLevel:e,config:n,minAutoLevel:r,media:h}=i,o=s?s.duration:t?t.duration:0,a=h&&0!==h.playbackRate?Math.abs(h.playbackRate):1,l=this.bwEstimator?this.bwEstimator.getEstimate():n.abrEwmaDefaultEstimate,c=i.mainForwardBufferInfo,u=(c?c.len:0)/a;let d=this.findBestLevel(l,r,e,u,n.abrBandWidthFactor,n.abrBandWidthUpFactor);if(d>=0)return d;y.trace(`[abr] ${u?"rebuffering expected":"buffer is empty"}, finding optimal quality level`);let f=o?Math.min(o,n.maxStarvationDelay):n.maxStarvationDelay,m=n.abrBandWidthFactor,g=n.abrBandWidthUpFactor;if(!u){const t=this.bitrateTestDelay;t&&(f=(o?Math.min(o,n.maxLoadingDelay):n.maxLoadingDelay)-t,y.trace(`[abr] bitrate test took ${Math.round(1e3*t)}ms, set first fragment max fetchDuration to ${Math.round(1e3*f)} ms`),m=g=1)}return d=this.findBestLevel(l,r,e,u+f,m,g),Math.max(d,0)}findBestLevel(t,s,i,e,n,r){var h;const{fragCurrent:o,partCurrent:a,lastLoadedFragLevel:l}=this,{levels:c}=this.hls,d=c[l],f=!(null==d||null==(h=d.details)||!h.live),m=null==d?void 0:d.codecSet,g=a?a.duration:o?o.duration:0,v=this.bwEstimator.getEstimateTTFB()/1e3;let p=s,w=-1;for(let h=i;h>=s;h--){const s=c[h];if(!s||m&&s.codecSet!==m){s&&(p=Math.min(h,p),w=Math.max(h,w));continue}-1!==w&&y.trace(`[abr] Skipped level(s) ${p}-${w} with CODECS:"${c[w].attrs.CODECS}"; not compatible with "${d.attrs.CODECS}"`);const i=s.details,o=(a?null==i?void 0:i.partTarget:null==i?void 0:i.averagetargetduration)||g;let b;b=h<=l?n*t:r*t;const T=c[h].maxBitrate,S=this.getTimeToLoadFrag(v,b,T*o,void 0===i);if(y.trace(`[abr] level:${h} adjustedbw-bitrate:${Math.round(b-T)} avgDuration:${o.toFixed(1)} maxFetchDuration:${e.toFixed(1)} fetchDuration:${S.toFixed(1)}`),b>T&&(0===S||!u(S)||f&&!this.bitrateTestDelay||S<e))return h}return-1}set nextAutoLevel(t){this._nextAutoLevel=t}},bufferController:class{constructor(t){this.details=null,this._objectUrl=null,this.operationQueue=void 0,this.listeners=void 0,this.hls=void 0,this.bufferCodecEventsExpected=0,this._bufferCodecEventsTotal=0,this.media=null,this.mediaSource=null,this.lastMpegAudioChunk=null,this.appendError=0,this.tracks={},this.pendingTracks={},this.sourceBuffer=void 0,this._onMediaSourceOpen=()=>{const{media:t,mediaSource:s}=this;y.log("[buffer-controller]: Media source opened"),t&&(t.removeEventListener("emptied",this._onMediaEmptied),this.updateMediaElementDuration(),this.hls.trigger(d.MEDIA_ATTACHED,{media:t})),s&&s.removeEventListener("sourceopen",this._onMediaSourceOpen),this.checkPendingTracks()},this._onMediaSourceClose=()=>{y.log("[buffer-controller]: Media source closed")},this._onMediaSourceEnded=()=>{y.log("[buffer-controller]: Media source ended")},this._onMediaEmptied=()=>{const{media:t,_objectUrl:s}=this;t&&t.src!==s&&y.error(`Media element src was set while attaching MediaSource (${s} > ${t.src})`)},this.hls=t,this._initSourceBuffer(),this.registerListeners()}hasSourceTypes(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0}destroy(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=null}registerListeners(){const{hls:t}=this;t.on(d.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.MANIFEST_PARSED,this.onManifestParsed,this),t.on(d.BUFFER_RESET,this.onBufferReset,this),t.on(d.BUFFER_APPENDING,this.onBufferAppending,this),t.on(d.BUFFER_CODECS,this.onBufferCodecs,this),t.on(d.BUFFER_EOS,this.onBufferEos,this),t.on(d.BUFFER_FLUSHING,this.onBufferFlushing,this),t.on(d.LEVEL_UPDATED,this.onLevelUpdated,this),t.on(d.FRAG_PARSED,this.onFragParsed,this),t.on(d.FRAG_CHANGED,this.onFragChanged,this)}unregisterListeners(){const{hls:t}=this;t.off(d.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.MANIFEST_PARSED,this.onManifestParsed,this),t.off(d.BUFFER_RESET,this.onBufferReset,this),t.off(d.BUFFER_APPENDING,this.onBufferAppending,this),t.off(d.BUFFER_CODECS,this.onBufferCodecs,this),t.off(d.BUFFER_EOS,this.onBufferEos,this),t.off(d.BUFFER_FLUSHING,this.onBufferFlushing,this),t.off(d.LEVEL_UPDATED,this.onLevelUpdated,this),t.off(d.FRAG_PARSED,this.onFragParsed,this),t.off(d.FRAG_CHANGED,this.onFragChanged,this)}_initSourceBuffer(){this.sourceBuffer={},this.operationQueue=new Be(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]},this.lastMpegAudioChunk=null}onManifestLoading(){this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=0,this.details=null}onManifestParsed(t,s){let i=2;(s.audio&&!s.video||!s.altAudio)&&(i=1),this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=i,y.log(`${this.bufferCodecEventsExpected} bufferCodec event(s) expected`)}onMediaAttaching(t,s){const i=this.media=s.media;if(i&&_e){const t=this.mediaSource=new _e;t.addEventListener("sourceopen",this._onMediaSourceOpen),t.addEventListener("sourceended",this._onMediaSourceEnded),t.addEventListener("sourceclose",this._onMediaSourceClose),i.src=self.URL.createObjectURL(t),this._objectUrl=i.src,i.addEventListener("emptied",this._onMediaEmptied)}}onMediaDetaching(){const{media:t,mediaSource:s,_objectUrl:i}=this;if(s){if(y.log("[buffer-controller]: media source detaching"),"open"===s.readyState)try{s.endOfStream()}catch(t){y.warn(`[buffer-controller]: onMediaDetaching: ${t.message} while calling endOfStream`)}this.onBufferReset(),s.removeEventListener("sourceopen",this._onMediaSourceOpen),s.removeEventListener("sourceended",this._onMediaSourceEnded),s.removeEventListener("sourceclose",this._onMediaSourceClose),t&&(t.removeEventListener("emptied",this._onMediaEmptied),i&&self.URL.revokeObjectURL(i),t.src===i?(t.removeAttribute("src"),t.load()):y.warn("[buffer-controller]: media.src was changed by a third party - skip cleanup")),this.mediaSource=null,this.media=null,this._objectUrl=null,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal,this.pendingTracks={},this.tracks={}}this.hls.trigger(d.MEDIA_DETACHED,void 0)}onBufferReset(){this.getSourceBufferTypes().forEach((t=>{const s=this.sourceBuffer[t];try{s&&(this.removeBufferListeners(t),this.mediaSource&&this.mediaSource.removeSourceBuffer(s),this.sourceBuffer[t]=void 0)}catch(s){y.warn(`[buffer-controller]: Failed to reset the ${t} buffer`,s)}})),this._initSourceBuffer()}onBufferCodecs(t,s){const i=this.getSourceBufferTypes().length;Object.keys(s).forEach((t=>{if(i){const i=this.tracks[t];if(i&&"function"==typeof i.buffer.changeType){const{id:e,codec:n,levelCodec:r,container:h,metadata:o}=s[t],a=(i.levelCodec||i.codec).replace(je,"$1"),l=(r||n).replace(je,"$1");a!==l&&(this.appendChangeType(t,`${h};codecs=${r||n}`),y.log(`[buffer-controller]: switching codec ${a} to ${l}`),this.tracks[t]={buffer:i.buffer,codec:n,container:h,levelCodec:r,metadata:o,id:e})}}else this.pendingTracks[t]=s[t]})),i||(this.bufferCodecEventsExpected=Math.max(this.bufferCodecEventsExpected-1,0),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks())}appendChangeType(t,s){const{operationQueue:i}=this,e={execute:()=>{const e=this.sourceBuffer[t];e&&(y.log(`[buffer-controller]: changing ${t} sourceBuffer type to ${s}`),e.changeType(s)),i.shiftAndExecuteNext(t)},onStart:()=>{},onComplete:()=>{},onError:s=>{y.warn(`[buffer-controller]: Failed to change ${t} SourceBuffer type`,s)}};i.append(e,t)}onBufferAppending(t,s){const{hls:i,operationQueue:e,tracks:n}=this,{data:r,type:h,frag:o,part:a,chunkMeta:l}=s,c=l.buffering[h],u=self.performance.now();c.start=u;const g=o.stats.buffering,v=a?a.stats.buffering:null;0===g.start&&(g.start=u),v&&0===v.start&&(v.start=u);const p=n.audio;let w=!1;"audio"===h&&"audio/mpeg"===(null==p?void 0:p.container)&&(w=!this.lastMpegAudioChunk||1===l.id||this.lastMpegAudioChunk.sn!==l.sn,this.lastMpegAudioChunk=l);const b=o.start,T={execute:()=>{if(c.executeStart=self.performance.now(),w){const t=this.sourceBuffer[h];if(t){const s=b-t.timestampOffset;Math.abs(s)>=.1&&(y.log(`[buffer-controller]: Updating audio SourceBuffer timestampOffset to ${b} (delta: ${s}) sn: ${o.sn})`),t.timestampOffset=b)}}this.appendExecutor(r,h)},onStart:()=>{},onComplete:()=>{const t=self.performance.now();c.executeEnd=c.end=t,0===g.first&&(g.first=t),v&&0===v.first&&(v.first=t);const{sourceBuffer:s}=this,i={};for(const t in s)i[t]=ei.getBuffered(s[t]);this.appendError=0,this.hls.trigger(d.BUFFER_APPENDED,{type:h,frag:o,part:a,chunkMeta:l,parent:o.type,timeRanges:i})},onError:t=>{y.error(`[buffer-controller]: Error encountered while trying to append to the ${h} SourceBuffer`,t);const s={type:f.MEDIA_ERROR,parent:o.type,details:m.BUFFER_APPEND_ERROR,frag:o,part:a,chunkMeta:l,error:t,err:t,fatal:!1};t.code===DOMException.QUOTA_EXCEEDED_ERR?s.details=m.BUFFER_FULL_ERROR:(this.appendError++,s.details=m.BUFFER_APPEND_ERROR,this.appendError>i.config.appendErrorMaxRetry&&(y.error(`[buffer-controller]: Failed ${i.config.appendErrorMaxRetry} times to append segment in sourceBuffer`),s.fatal=!0)),i.trigger(d.ERROR,s)}};e.append(T,h)}onBufferFlushing(t,s){const{operationQueue:i}=this,e=t=>({execute:this.removeExecutor.bind(this,t,s.startOffset,s.endOffset),onStart:()=>{},onComplete:()=>{this.hls.trigger(d.BUFFER_FLUSHED,{type:t})},onError:s=>{y.warn(`[buffer-controller]: Failed to remove from ${t} SourceBuffer`,s)}});s.type?i.append(e(s.type),s.type):this.getSourceBufferTypes().forEach((t=>{i.append(e(t),t)}))}onFragParsed(t,s){const{frag:i,part:e}=s,n=[],r=e?e.elementaryStreams:i.elementaryStreams;r[L]?n.push("audiovideo"):(r[$]&&n.push("audio"),r[A]&&n.push("video")),0===n.length&&y.warn(`Fragments must have at least one ElementaryStreamType set. type: ${i.type} level: ${i.level} sn: ${i.sn}`),this.blockBuffers((()=>{const t=self.performance.now();i.stats.buffering.end=t,e&&(e.stats.buffering.end=t),this.hls.trigger(d.FRAG_BUFFERED,{frag:i,part:e,stats:e?e.stats:i.stats,id:i.type})}),n)}onFragChanged(t,s){this.flushBackBuffer()}onBufferEos(t,s){this.getSourceBufferTypes().reduce(((t,i)=>{const e=this.sourceBuffer[i];return!e||s.type&&s.type!==i||(e.ending=!0,e.ended||(e.ended=!0,y.log(`[buffer-controller]: ${i} sourceBuffer now EOS`))),t&&!(e&&!e.ended)}),!0)&&(y.log("[buffer-controller]: Queueing mediaSource.endOfStream()"),this.blockBuffers((()=>{this.getSourceBufferTypes().forEach((t=>{const s=this.sourceBuffer[t];s&&(s.ending=!1)}));const{mediaSource:t}=this;t&&"open"===t.readyState?(y.log("[buffer-controller]: Calling mediaSource.endOfStream()"),t.endOfStream()):t&&y.info(`[buffer-controller]: Could not call mediaSource.endOfStream(). mediaSource.readyState: ${t.readyState}`)})))}onLevelUpdated(t,{details:s}){s.fragments.length&&(this.details=s,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())}flushBackBuffer(){const{hls:t,details:s,media:i,sourceBuffer:e}=this;if(!i||null===s)return;const n=this.getSourceBufferTypes();if(!n.length)return;const r=s.live&&null!==t.config.liveBackBufferLength?t.config.liveBackBufferLength:t.config.backBufferLength;if(!u(r)||r<0)return;const h=i.currentTime,o=s.levelTargetDuration,a=Math.max(r,o),l=Math.floor(h/o)*o-a;n.forEach((i=>{const n=e[i];if(n){const e=ei.getBuffered(n);if(e.length>0&&l>e.start(0)){if(t.trigger(d.BACK_BUFFER_REACHED,{bufferEnd:l}),s.live)t.trigger(d.LIVE_BACK_BUFFER_REACHED,{bufferEnd:l});else if(n.ended&&e.end(e.length-1)-h<2*o)return void y.info(`[buffer-controller]: Cannot flush ${i} back buffer while SourceBuffer is in ended state`);t.trigger(d.BUFFER_FLUSHING,{startOffset:0,endOffset:l,type:i})}}}))}updateMediaElementDuration(){if(!this.details||!this.media||!this.mediaSource||"open"!==this.mediaSource.readyState)return;const{details:t,hls:s,media:i,mediaSource:e}=this,n=t.fragments[0].start+t.totalduration,r=i.duration,h=u(e.duration)?e.duration:0;t.live&&s.config.liveDurationInfinity?(y.log("[buffer-controller]: Media Source duration is set to Infinity"),e.duration=1/0,this.updateSeekableRange(t)):(n>h&&n>r||!u(r))&&(y.log(`[buffer-controller]: Updating Media Source duration to ${n.toFixed(3)}`),e.duration=n)}updateSeekableRange(t){const s=this.mediaSource,i=t.fragments;if(i.length&&t.live&&null!=s&&s.setLiveSeekableRange){const e=Math.max(0,i[0].start),n=Math.max(e,e+t.totalduration);s.setLiveSeekableRange(e,n)}}checkPendingTracks(){const{bufferCodecEventsExpected:t,operationQueue:s,pendingTracks:i}=this,e=Object.keys(i).length;if(e&&!t||2===e){this.createSourceBuffers(i),this.pendingTracks={};const t=this.getSourceBufferTypes();if(t.length)this.hls.trigger(d.BUFFER_CREATED,{tracks:this.tracks}),t.forEach((t=>{s.executeNext(t)}));else{const t=new Error("could not create source buffer for media codec(s)");this.hls.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,error:t,reason:t.message})}}}createSourceBuffers(t){const{sourceBuffer:s,mediaSource:i}=this;if(!i)throw Error("createSourceBuffers called when mediaSource was null");for(const e in t)if(!s[e]){const n=t[e];if(!n)throw Error(`source buffer exists for track ${e}, however track does not`);const r=n.levelCodec||n.codec,h=`${n.container};codecs=${r}`;y.log(`[buffer-controller]: creating sourceBuffer(${h})`);try{const t=s[e]=i.addSourceBuffer(h),o=e;this.addBufferListener(o,"updatestart",this._onSBUpdateStart),this.addBufferListener(o,"updateend",this._onSBUpdateEnd),this.addBufferListener(o,"error",this._onSBUpdateError),this.tracks[e]={buffer:t,codec:r,container:n.container,levelCodec:n.levelCodec,metadata:n.metadata,id:n.id}}catch(t){y.error(`[buffer-controller]: error while trying to add sourceBuffer: ${t.message}`),this.hls.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:t,mimeType:h})}}}_onSBUpdateStart(t){const{operationQueue:s}=this;s.current(t).onStart()}_onSBUpdateEnd(t){const{operationQueue:s}=this;s.current(t).onComplete(),s.shiftAndExecuteNext(t)}_onSBUpdateError(t,s){const i=new Error(`${t} SourceBuffer error`);y.error(`[buffer-controller]: ${i}`,s),this.hls.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.BUFFER_APPENDING_ERROR,error:i,fatal:!1});const e=this.operationQueue.current(t);e&&e.onError(s)}removeExecutor(t,s,i){const{media:e,mediaSource:n,operationQueue:r,sourceBuffer:h}=this,o=h[t];if(!e||!n||!o)return y.warn(`[buffer-controller]: Attempting to remove from the ${t} SourceBuffer, but it does not exist`),void r.shiftAndExecuteNext(t);const a=u(e.duration)?e.duration:1/0,l=u(n.duration)?n.duration:1/0,c=Math.max(0,s),d=Math.min(i,a,l);d>c&&!o.ending?(o.ended=!1,y.log(`[buffer-controller]: Removing [${c},${d}] from the ${t} SourceBuffer`),o.remove(c,d)):r.shiftAndExecuteNext(t)}appendExecutor(t,s){const{operationQueue:i,sourceBuffer:e}=this,n=e[s];if(!n)return y.warn(`[buffer-controller]: Attempting to append to the ${s} SourceBuffer, but it does not exist`),void i.shiftAndExecuteNext(s);n.ended=!1,n.appendBuffer(t)}blockBuffers(t,s=this.getSourceBufferTypes()){if(!s.length)return y.log("[buffer-controller]: Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(t);const{operationQueue:i}=this,e=s.map((t=>i.appendBlocker(t)));Promise.all(e).then((()=>{t(),s.forEach((t=>{const s=this.sourceBuffer[t];null!=s&&s.updating||i.shiftAndExecuteNext(t)}))}))}getSourceBufferTypes(){return Object.keys(this.sourceBuffer)}addBufferListener(t,s,i){const e=this.sourceBuffer[t];if(!e)return;const n=i.bind(this,t);this.listeners[t].push({event:s,listener:n}),e.addEventListener(s,n)}removeBufferListeners(t){const s=this.sourceBuffer[t];s&&this.listeners[t].forEach((t=>{s.removeEventListener(t.event,t.listener)}))}},capLevelController:On,errorController:class{constructor(t){this.hls=void 0,this.playlistError=0,this.penalizedRenditions={},this.log=void 0,this.warn=void 0,this.error=void 0,this.hls=t,this.log=y.log.bind(y,"[info]:"),this.warn=y.warn.bind(y,"[warning]:"),this.error=y.error.bind(y,"[error]:"),this.registerListeners()}registerListeners(){const t=this.hls;t.on(d.ERROR,this.onError,this),t.on(d.MANIFEST_LOADING,this.onManifestLoading,this)}unregisterListeners(){const t=this.hls;t&&(t.off(d.ERROR,this.onError,this),t.off(d.ERROR,this.onErrorOut,this),t.off(d.MANIFEST_LOADING,this.onManifestLoading,this))}destroy(){this.unregisterListeners(),this.hls=null,this.penalizedRenditions={}}startLoad(t){this.playlistError=0}stopLoad(){}getVariantLevelIndex(t){return(null==t?void 0:t.type)===ss?t.level:this.hls.loadLevel}onManifestLoading(){this.playlistError=0,this.penalizedRenditions={}}onError(t,s){var i;if(s.fatal)return;const e=this.hls,n=s.context;switch(s.details){case m.FRAG_LOAD_ERROR:case m.FRAG_LOAD_TIMEOUT:case m.KEY_LOAD_ERROR:case m.KEY_LOAD_TIMEOUT:return void(s.errorAction=this.getFragRetryOrSwitchAction(s));case m.FRAG_GAP:case m.FRAG_PARSING_ERROR:case m.FRAG_DECRYPT_ERROR:return s.errorAction=this.getFragRetryOrSwitchAction(s),void(s.errorAction.action=2);case m.LEVEL_EMPTY_ERROR:case m.LEVEL_PARSING_ERROR:{var r,h;const t=s.parent===ss?s.level:e.loadLevel;s.details===m.LEVEL_EMPTY_ERROR&&null!=(r=s.context)&&null!=(h=r.levelDetails)&&h.live?s.errorAction=this.getPlaylistRetryOrSwitchAction(s,t):(s.levelRetry=!1,s.errorAction=this.getLevelSwitchAction(s,t))}return;case m.LEVEL_LOAD_ERROR:case m.LEVEL_LOAD_TIMEOUT:return void("number"==typeof(null==n?void 0:n.level)&&(s.errorAction=this.getPlaylistRetryOrSwitchAction(s,n.level)));case m.AUDIO_TRACK_LOAD_ERROR:case m.AUDIO_TRACK_LOAD_TIMEOUT:case m.SUBTITLE_LOAD_ERROR:case m.SUBTITLE_TRACK_LOAD_TIMEOUT:if(n){const t=e.levels[e.loadLevel];if(t&&(n.type===Zt&&n.groupId===t.audioGroupId||n.type===ts&&n.groupId===t.textGroupId))return s.errorAction=this.getPlaylistRetryOrSwitchAction(s,e.loadLevel),s.errorAction.action=2,void(s.errorAction.flags=1)}return;case m.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:{const t=e.levels[e.loadLevel],i=null==t?void 0:t.attrs["HDCP-LEVEL"];i&&(s.errorAction={action:2,flags:2,hdcpLevel:i})}return;case m.BUFFER_ADD_CODEC_ERROR:case m.REMUX_ALLOC_ERROR:return void(s.errorAction=this.getLevelSwitchAction(s,null!=(i=s.level)?i:e.loadLevel));case m.INTERNAL_EXCEPTION:case m.BUFFER_APPENDING_ERROR:case m.BUFFER_APPEND_ERROR:case m.BUFFER_FULL_ERROR:case m.LEVEL_SWITCH_ERROR:case m.BUFFER_STALLED_ERROR:case m.BUFFER_SEEK_OVER_HOLE:case m.BUFFER_NUDGE_ON_STALL:return void(s.errorAction={action:0,flags:0})}if(s.type===f.KEY_SYSTEM_ERROR){const t=this.getVariantLevelIndex(s.frag);return s.levelRetry=!1,void(s.errorAction=this.getLevelSwitchAction(s,t))}}getPlaylistRetryOrSwitchAction(t,s){var i,e;const n=Ms(this.hls.config.playlistLoadPolicy,t),r=this.playlistError++,h=null==(i=t.response)?void 0:i.code;return Is(n,r,Ls(t),h)?{action:5,flags:0,retryConfig:n,retryCount:r}:null!=(e=t.context)&&e.deliveryDirectives?{action:0,flags:0,retryConfig:n||{maxNumRetry:0,retryDelayMs:0,maxRetryDelayMs:0},retryCount:r}:this.getLevelSwitchAction(t,s)}getFragRetryOrSwitchAction(t){const s=this.hls,i=this.getVariantLevelIndex(t.frag),e=s.levels[i],{fragLoadPolicy:n,keyLoadPolicy:r}=s.config,h=Ms(t.details.startsWith("key")?r:n,t),o=s.levels.reduce(((t,s)=>t+s.fragmentError),0);if(e){var a;t.details!==m.FRAG_GAP&&e.fragmentError++;const s=null==(a=t.response)?void 0:a.code;if(Is(h,o,Ls(t),s))return{action:5,flags:0,retryConfig:h,retryCount:o}}const l=this.getLevelSwitchAction(t,i);return h&&(l.retryConfig=h,l.retryCount=o),l}getLevelSwitchAction(t,s){const i=this.hls;null==s&&(s=i.loadLevel);const e=this.hls.levels[s];if(e&&(e.loadError++,i.autoLevelEnabled)){var n,r;let s=-1;const h=i.levels,o=null==(n=t.frag)?void 0:n.type,{type:a,groupId:l}=null!=(r=t.context)?r:{};for(let n=h.length;n--;){const r=(n+i.loadLevel)%h.length;if(r!==i.loadLevel&&0===h[r].loadError){const i=h[r];if(t.details===m.FRAG_GAP&&t.frag){const s=h[r].details;if(s){const i=Ps(t.frag,s.fragments,t.frag.start);if(null!=i&&i.gap)continue}}else{if(a===Zt&&l===i.audioGroupId||a===ts&&l===i.textGroupId)continue;if(o===is&&e.audioGroupId===i.audioGroupId||o===es&&e.textGroupId===i.textGroupId)continue}s=r;break}}if(s>-1&&i.loadLevel!==s)return t.levelRetry=!0,{action:2,flags:0,nextAutoLevel:s}}return{action:2,flags:1}}onErrorOut(t,s){var i;switch(null==(i=s.errorAction)?void 0:i.action){case 0:break;case 2:this.sendAlternateToPenaltyBox(s),s.errorAction.resolved||s.details===m.FRAG_GAP||(s.fatal=!0)}s.fatal&&this.hls.stopLoad()}sendAlternateToPenaltyBox(t){const s=this.hls,i=t.errorAction;if(!i)return;const{flags:e,hdcpLevel:n,nextAutoLevel:r}=i;switch(e){case 0:this.switchLevel(t,r);break;case 1:i.resolved||(i.resolved=this.redundantFailover(t));break;case 2:n&&(s.maxHdcpLevel=ys[ys.indexOf(n)-1],i.resolved=!0),this.warn(`Restricting playback to HDCP-LEVEL of "${s.maxHdcpLevel}" or lower`)}i.resolved||this.switchLevel(t,r)}switchLevel(t,s){void 0!==s&&t.errorAction&&(this.warn(`switching to level ${s} after ${t.details}`),this.hls.nextAutoLevel=s,t.errorAction.resolved=!0,this.hls.nextLoadLevel=this.hls.nextAutoLevel)}redundantFailover(t){const{hls:s,penalizedRenditions:i}=this,e=t.parent===ss?t.level:s.loadLevel,n=s.levels[e],r=n.url.length,h=t.frag?t.frag.urlId:n.urlId;n.urlId!==h||t.frag&&!n.details||this.penalizeRendition(n,t);for(let o=1;o<r;o++){const a=(h+o)%r,l=i[a];if(!l||Ns(l,t,i[h]))return this.warn(`Switching to Redundant Stream ${a+1}/${r}: "${n.url[a]}" after ${t.details}`),this.playlistError=0,s.levels.forEach((t=>{t.urlId=a})),s.nextLoadLevel=e,!0}return!1}penalizeRendition(t,s){const{penalizedRenditions:i}=this,e=i[t.urlId]||{lastErrorPerfMs:0,errors:[],details:void 0};e.lastErrorPerfMs=performance.now(),e.errors.push(s),e.details=t.details,i[t.urlId]=e}},fpsController:class{constructor(t){this.hls=void 0,this.isVideoPlaybackQualityAvailable=!1,this.timer=void 0,this.media=null,this.lastTime=void 0,this.lastDroppedFrames=0,this.lastDecodedFrames=0,this.streamController=void 0,this.hls=t,this.registerListeners()}setStreamController(t){this.streamController=t}registerListeners(){this.hls.on(d.MEDIA_ATTACHING,this.onMediaAttaching,this)}unregisterListeners(){this.hls.off(d.MEDIA_ATTACHING,this.onMediaAttaching,this)}destroy(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null}onMediaAttaching(t,s){const i=this.hls.config;if(i.capLevelOnFPSDrop){const t=s.media instanceof self.HTMLVideoElement?s.media:null;this.media=t,t&&"function"==typeof t.getVideoPlaybackQuality&&(this.isVideoPlaybackQualityAvailable=!0),self.clearInterval(this.timer),this.timer=self.setInterval(this.checkFPSInterval.bind(this),i.fpsDroppedMonitoringPeriod)}}checkFPS(t,s,i){const e=performance.now();if(s){if(this.lastTime){const t=i-this.lastDroppedFrames,n=s-this.lastDecodedFrames,r=1e3*t/(e-this.lastTime),h=this.hls;if(h.trigger(d.FPS_DROP,{currentDropped:t,currentDecoded:n,totalDroppedFrames:i}),r>0&&t>h.config.fpsDroppedMonitoringThreshold*n){let t=h.currentLevel;y.warn("drop FPS ratio greater than max allowed value for currentLevel: "+t),t>0&&(-1===h.autoLevelCapping||h.autoLevelCapping>=t)&&(t-=1,h.trigger(d.FPS_DROP_LEVEL_CAPPING,{level:t,droppedLevel:h.currentLevel}),h.autoLevelCapping=t,this.streamController.nextLevelSwitch())}}this.lastTime=e,this.lastDroppedFrames=i,this.lastDecodedFrames=s}}checkFPSInterval(){const t=this.media;if(t)if(this.isVideoPlaybackQualityAvailable){const s=t.getVideoPlaybackQuality();this.checkFPS(t,s.totalVideoFrames,s.droppedVideoFrames)}else this.checkFPS(t,t.webkitDecodedFrameCount,t.webkitDroppedFrameCount)}},stretchShortVideoTrack:!1,maxAudioFramesDrift:1,forceKeyFrameOnDiscontinuity:!0,abrEwmaFastLive:3,abrEwmaSlowLive:9,abrEwmaFastVoD:3,abrEwmaSlowVoD:9,abrEwmaDefaultEstimate:5e5,abrBandWidthFactor:.95,abrBandWidthUpFactor:.7,abrMaxWithRealBitrate:!1,maxStarvationDelay:4,maxLoadingDelay:4,minAutoBitrate:0,emeEnabled:!1,widevineLicenseUrl:void 0,drmSystems:{},drmSystemOptions:{},requestMediaKeySystemAccessFunc:H,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0,certLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:null,errorRetry:null}},keyLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"},errorRetry:{maxNumRetry:8,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"}}},manifestLoadPolicy:{default:{maxTimeToFirstByteMs:1/0,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},playlistLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:2,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},fragLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:12e4,timeoutRetry:{maxNumRetry:4,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:6,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},steeringManifestLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,manifestLoadingMaxRetryTimeout:64e3,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,levelLoadingMaxRetryTimeout:64e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingMaxRetryTimeout:64e3},{cueHandler:Qn,enableWebVTT:!0,enableIMSC1:!0,enableCEA708Captions:!0,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}),{},{subtitleStreamController:class extends $i{constructor(t,s,i){super(t,s,i,"[subtitle-stream-controller]",es),this.levels=[],this.currentTrackId=-1,this.tracksBuffered=[],this.mainDetails=null,this._registerListeners()}onHandlerDestroying(){this._unregisterListeners(),this.mainDetails=null}_registerListeners(){const{hls:t}=this;t.on(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.LEVEL_LOADED,this.onLevelLoaded,this),t.on(d.ERROR,this.onError,this),t.on(d.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(d.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),t.on(d.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.on(d.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),t.on(d.BUFFER_FLUSHING,this.onBufferFlushing,this),t.on(d.FRAG_BUFFERED,this.onFragBuffered,this)}_unregisterListeners(){const{hls:t}=this;t.off(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.LEVEL_LOADED,this.onLevelLoaded,this),t.off(d.ERROR,this.onError,this),t.off(d.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(d.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),t.off(d.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.off(d.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),t.off(d.BUFFER_FLUSHING,this.onBufferFlushing,this),t.off(d.FRAG_BUFFERED,this.onFragBuffered,this)}startLoad(t){this.stopLoad(),this.state=mi,this.setInterval(500),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}onManifestLoading(){this.mainDetails=null,this.fragmentTracker.removeAllFragments()}onMediaDetaching(){this.tracksBuffered=[],super.onMediaDetaching()}onLevelLoaded(t,s){this.mainDetails=s.details}onSubtitleFragProcessed(t,s){const{frag:i,success:e}=s;if(this.fragPrevious=i,this.state=mi,!e)return;const n=this.tracksBuffered[this.currentTrackId];if(!n)return;let r;const h=i.start;for(let t=0;t<n.length;t++)if(h>=n[t].start&&h<=n[t].end){r=n[t];break}const o=i.start+i.duration;r?r.end=o:(r={start:h,end:o},n.push(r)),this.fragmentTracker.fragBuffered(i)}onBufferFlushing(t,s){const{startOffset:i,endOffset:e}=s;if(0===i&&e!==Number.POSITIVE_INFINITY){const{currentTrackId:t,levels:n}=this;if(!n.length||!n[t]||!n[t].details)return;const r=e-n[t].details.targetduration;if(r<=0)return;s.endOffsetSubtitles=Math.max(0,r),this.tracksBuffered.forEach((t=>{for(let s=0;s<t.length;)if(t[s].end<=r)t.shift();else{if(!(t[s].start<r))break;t[s].start=r,s++}})),this.fragmentTracker.removeFragmentsInRange(i,r,es)}}onFragBuffered(t,s){var i;this.loadedmetadata||s.frag.type!==ss||null!=(i=this.media)&&i.buffered.length&&(this.loadedmetadata=!0)}onError(t,s){const i=s.frag;(null==i?void 0:i.type)===es&&(this.fragCurrent&&this.fragCurrent.abortRequests(),this.state!==fi&&(this.state=mi))}onSubtitleTracksUpdated(t,{subtitleTracks:s}){Oe(this.levels,s)?this.levels=s.map((t=>new bs(t))):(this.tracksBuffered=[],this.levels=s.map((t=>{const s=new bs(t);return this.tracksBuffered[s.id]=[],s})),this.fragmentTracker.removeFragmentsInRange(0,Number.POSITIVE_INFINITY,es),this.fragPrevious=null,this.mediaBuffer=null)}onSubtitleTrackSwitch(t,s){if(this.currentTrackId=s.id,!this.levels.length||-1===this.currentTrackId)return void this.clearInterval();const i=this.levels[this.currentTrackId];this.mediaBuffer=null!=i&&i.details?this.mediaBufferTimeRanges:null,i&&this.setInterval(500)}onSubtitleTrackLoaded(t,s){var i;const{details:e,id:n}=s,{currentTrackId:r,levels:h}=this;if(!h.length)return;const o=h[r];if(n>=h.length||n!==r||!o)return;this.mediaBuffer=this.mediaBufferTimeRanges;let a=0;if(e.live||null!=(i=o.details)&&i.live){const t=this.mainDetails;if(e.deltaUpdateFailed||!t)return;const s=t.fragments[0];o.details?(a=this.alignPlaylists(e,o.details),0===a&&s&&(a=s.start,ks(e,a))):e.hasProgramDateTime&&t.hasProgramDateTime?(ai(e,t),a=e.fragments[0].start):s&&(a=s.start,ks(e,a))}o.details=e,this.levelLastLoaded=n,this.startFragRequested||!this.mainDetails&&e.live||this.setStartPosition(o.details,a),this.tick(),e.live&&!this.fragCurrent&&this.media&&this.state===mi&&(Ps(null,e.fragments,this.media.currentTime,0)||(this.warn("Subtitle playlist not aligned with playback"),o.details=void 0))}_handleFragmentLoadComplete(t){const{frag:s,payload:i}=t,e=s.decryptdata,n=this.hls;if(!this.fragContextChanged(s)&&i&&i.byteLength>0&&e&&e.key&&e.iv&&"AES-128"===e.method){const t=performance.now();this.decrypter.decrypt(new Uint8Array(i),e.key.buffer,e.iv.buffer).catch((t=>{throw n.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.FRAG_DECRYPT_ERROR,fatal:!1,error:t,reason:t.message,frag:s}),t})).then((i=>{const e=performance.now();n.trigger(d.FRAG_DECRYPTED,{frag:s,payload:i,stats:{tstart:t,tdecrypt:e}})})).catch((t=>{this.warn(`${t.name}: ${t.message}`),this.state=mi}))}}doTick(){if(this.media){if(this.state===mi){const{currentTrackId:t,levels:s}=this,i=s[t];if(!s.length||!i||!i.details)return;const e=i.details,n=e.targetduration,{config:r}=this,h=this.getLoadPosition(),o=ei.bufferedInfo(this.tracksBuffered[this.currentTrackId]||[],h-n,r.maxBufferHole),{end:a,len:l}=o,c=this.getFwdBufferInfo(this.media,ss);if(l>this.getMaxBufferLength(null==c?void 0:c.len)+n)return;const u=e.fragments,d=u.length;let f=null;const m=this.fragPrevious;if(a<e.edge){const{maxFragLookUpTolerance:t}=r;f=Ps(m,u,Math.max(u[0].start,a),t),!f&&m&&m.start<u[0].start&&(f=u[0])}else f=u[d-1];if(!f)return;f=this.mapToInitFragWhenRequired(f),this.fragmentTracker.getState(f)===Ks&&this.loadFragment(f,i,a)}}else this.state=mi}getMaxBufferLength(t){const s=super.getMaxBufferLength();return t?Math.max(s,t):s}loadFragment(t,s,i){this.fragCurrent=t,"initSegment"===t.sn?this._loadInitSegment(t,s):(this.startFragRequested=!0,super.loadFragment(t,s,i))}get mediaBufferTimeRanges(){return new Ue(this.tracksBuffered[this.currentTrackId]||[])}},subtitleTrackController:class extends Us{constructor(t){super(t,"[subtitle-track-controller]"),this.media=null,this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.selectDefaultTrack=!0,this.queuedDefaultTrack=-1,this.trackChangeListener=()=>this.onTextTracksChanged(),this.asyncPollTrackChange=()=>this.pollTrackChange(0),this.useTextTrackPolling=!1,this.subtitlePollingInterval=-1,this._subtitleDisplay=!0,this.registerListeners()}destroy(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,this.trackChangeListener=this.asyncPollTrackChange=null,super.destroy()}get subtitleDisplay(){return this._subtitleDisplay}set subtitleDisplay(t){this._subtitleDisplay=t,this.trackId>-1&&this.toggleTrackModes(this.trackId)}registerListeners(){const{hls:t}=this;t.on(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.MANIFEST_PARSED,this.onManifestParsed,this),t.on(d.LEVEL_LOADING,this.onLevelLoading,this),t.on(d.LEVEL_SWITCHING,this.onLevelSwitching,this),t.on(d.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.on(d.ERROR,this.onError,this)}unregisterListeners(){const{hls:t}=this;t.off(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.MANIFEST_PARSED,this.onManifestParsed,this),t.off(d.LEVEL_LOADING,this.onLevelLoading,this),t.off(d.LEVEL_SWITCHING,this.onLevelSwitching,this),t.off(d.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),t.off(d.ERROR,this.onError,this)}onMediaAttached(t,s){this.media=s.media,this.media&&(this.queuedDefaultTrack>-1&&(this.subtitleTrack=this.queuedDefaultTrack,this.queuedDefaultTrack=-1),this.useTextTrackPolling=!(this.media.textTracks&&"onchange"in this.media.textTracks),this.useTextTrackPolling?this.pollTrackChange(500):this.media.textTracks.addEventListener("change",this.asyncPollTrackChange))}pollTrackChange(t){self.clearInterval(this.subtitlePollingInterval),this.subtitlePollingInterval=self.setInterval(this.trackChangeListener,t)}onMediaDetaching(){this.media&&(self.clearInterval(this.subtitlePollingInterval),this.useTextTrackPolling||this.media.textTracks.removeEventListener("change",this.asyncPollTrackChange),this.trackId>-1&&(this.queuedDefaultTrack=this.trackId),Fe(this.media.textTracks).forEach((t=>{ls(t)})),this.subtitleTrack=-1,this.media=null)}onManifestLoading(){this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.selectDefaultTrack=!0}onManifestParsed(t,s){this.tracks=s.subtitleTracks}onSubtitleTrackLoaded(t,s){const{id:i,details:e}=s,{trackId:n}=this,r=this.tracksInGroup[n];if(!r)return void this.warn(`Invalid subtitle track id ${i}`);const h=r.details;r.details=s.details,this.log(`subtitle track ${i} loaded [${e.startSN}-${e.endSN}]`),i===this.trackId&&this.playlistLoaded(i,s,h)}onLevelLoading(t,s){this.switchLevel(s.level)}onLevelSwitching(t,s){this.switchLevel(s.level)}switchLevel(t){const s=this.hls.levels[t];if(null==s||!s.textGroupIds)return;const i=s.textGroupIds[s.urlId],e=this.tracksInGroup?this.tracksInGroup[this.trackId]:void 0;if(this.groupId!==i){const t=this.tracks.filter((t=>!i||t.groupId===i));this.tracksInGroup=t;const s=this.findTrackId(null==e?void 0:e.name)||this.findTrackId();this.groupId=i||null;const n={subtitleTracks:t};this.log(`Updating subtitle tracks, ${t.length} track(s) found in "${i}" group-id`),this.hls.trigger(d.SUBTITLE_TRACKS_UPDATED,n),-1!==s&&this.setSubtitleTrack(s,e)}else this.shouldReloadPlaylist(e)&&this.setSubtitleTrack(this.trackId,e)}findTrackId(t){const s=this.tracksInGroup;for(let i=0;i<s.length;i++){const e=s[i];if((!this.selectDefaultTrack||e.default)&&(!t||t===e.name))return e.id}return-1}onError(t,s){!s.fatal&&s.context&&s.context.type===ts&&s.context.id===this.trackId&&s.context.groupId===this.groupId&&this.checkRetry(s)}get subtitleTracks(){return this.tracksInGroup}get subtitleTrack(){return this.trackId}set subtitleTrack(t){this.selectDefaultTrack=!1,this.setSubtitleTrack(t,this.tracksInGroup?this.tracksInGroup[this.trackId]:void 0)}loadPlaylist(t){super.loadPlaylist();const s=this.tracksInGroup[this.trackId];if(this.shouldLoadPlaylist(s)){const i=s.id,e=s.groupId;let n=s.url;if(t)try{n=t.addDirectives(n)}catch(t){this.warn(`Could not construct new URL with HLS Delivery Directives: ${t}`)}this.log(`Loading subtitle playlist for id ${i}`),this.hls.trigger(d.SUBTITLE_TRACK_LOADING,{url:n,id:i,groupId:e,deliveryDirectives:t||null})}}toggleTrackModes(t){const{media:s,trackId:i}=this;if(!s)return;const e=Fe(s.textTracks),n=e.filter((t=>t.groupId===this.groupId));if(-1===t)[].slice.call(e).forEach((t=>{t.mode="disabled"}));else{const t=n[i];t&&(t.mode="disabled")}const r=n[t];r&&(r.mode=this.subtitleDisplay?"showing":"hidden")}setSubtitleTrack(t,s){var i;const e=this.tracksInGroup;if(!this.media)return void(this.queuedDefaultTrack=t);if(this.trackId!==t&&this.toggleTrackModes(t),this.trackId===t&&(-1===t||null!=(i=e[t])&&i.details)||t<-1||t>=e.length)return;this.clearTimer();const n=e[t];if(this.log(`Switching to subtitle-track ${t}`+(n?` "${n.name}" lang:${n.lang} group:${n.groupId}`:"")),this.trackId=t,n){const{id:t,groupId:i="",name:e,type:r,url:h}=n;this.hls.trigger(d.SUBTITLE_TRACK_SWITCH,{id:t,groupId:i,name:e,type:r,url:h});const o=this.switchParams(n.url,null==s?void 0:s.details);this.loadPlaylist(o)}else this.hls.trigger(d.SUBTITLE_TRACK_SWITCH,{id:t})}onTextTracksChanged(){if(this.useTextTrackPolling||self.clearInterval(this.subtitlePollingInterval),!this.media||!this.hls.config.renderTextTracksNatively)return;let t=-1;const s=Fe(this.media.textTracks);for(let i=0;i<s.length;i++)if("hidden"===s[i].mode)t=i;else if("showing"===s[i].mode){t=i;break}this.subtitleTrack!==t&&(this.subtitleTrack=t)}},timelineController:class{constructor(t){if(this.hls=void 0,this.media=null,this.config=void 0,this.enabled=!0,this.Cues=void 0,this.textTracks=[],this.tracks=[],this.initPTS=[],this.unparsedVttFrags=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.cea608Parser1=void 0,this.cea608Parser2=void 0,this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}},this.captionsProperties=void 0,this.hls=t,this.config=t.config,this.Cues=t.config.cueHandler,this.captionsProperties={textTrack1:{label:this.config.captionsTextTrack1Label,languageCode:this.config.captionsTextTrack1LanguageCode},textTrack2:{label:this.config.captionsTextTrack2Label,languageCode:this.config.captionsTextTrack2LanguageCode},textTrack3:{label:this.config.captionsTextTrack3Label,languageCode:this.config.captionsTextTrack3LanguageCode},textTrack4:{label:this.config.captionsTextTrack4Label,languageCode:this.config.captionsTextTrack4LanguageCode}},this.config.enableCEA708Captions){const t=new an(this,"textTrack1"),s=new an(this,"textTrack2"),i=new an(this,"textTrack3"),e=new an(this,"textTrack4");this.cea608Parser1=new rn(1,t,s),this.cea608Parser2=new rn(3,i,e)}t.on(d.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(d.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(d.FRAG_LOADING,this.onFragLoading,this),t.on(d.FRAG_LOADED,this.onFragLoaded,this),t.on(d.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.on(d.FRAG_DECRYPTED,this.onFragDecrypted,this),t.on(d.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(d.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.on(d.BUFFER_FLUSHING,this.onBufferFlushing,this)}destroy(){const{hls:t}=this;t.off(d.MEDIA_ATTACHING,this.onMediaAttaching,this),t.off(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(d.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.off(d.FRAG_LOADING,this.onFragLoading,this),t.off(d.FRAG_LOADED,this.onFragLoaded,this),t.off(d.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.off(d.FRAG_DECRYPTED,this.onFragDecrypted,this),t.off(d.INIT_PTS_FOUND,this.onInitPtsFound,this),t.off(d.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.off(d.BUFFER_FLUSHING,this.onBufferFlushing,this),this.hls=this.config=this.cea608Parser1=this.cea608Parser2=null}addCues(t,s,i,e,n){let r=!1;for(let t=n.length;t--;){const e=n[t],a=(h=e[0],o=s,Math.min(e[1],i)-Math.max(h,o));if(a>=0&&(e[0]=Math.min(e[0],s),e[1]=Math.max(e[1],i),r=!0,a/(i-s)>.5))return}var h,o;if(r||n.push([s,i]),this.config.renderTextTracksNatively)this.Cues.newCue(this.captionsTracks[t],s,i,e);else{const n=this.Cues.newCue(null,s,i,e);this.hls.trigger(d.CUES_PARSED,{type:"captions",cues:n,track:t})}}onInitPtsFound(t,{frag:s,id:i,initPTS:e,timescale:n}){const{unparsedVttFrags:r}=this;"main"===i&&(this.initPTS[s.cc]={baseTime:e,timescale:n}),r.length&&(this.unparsedVttFrags=[],r.forEach((t=>{this.onFragLoaded(d.FRAG_LOADED,t)})))}getExistingTrack(t){const{media:s}=this;if(s)for(let i=0;i<s.textTracks.length;i++){const e=s.textTracks[i];if(e[t])return e}return null}createCaptionsTrack(t){this.config.renderTextTracksNatively?this.createNativeTrack(t):this.createNonNativeTrack(t)}createNativeTrack(t){if(this.captionsTracks[t])return;const{captionsProperties:s,captionsTracks:i,media:e}=this,{label:n,languageCode:r}=s[t],h=this.getExistingTrack(t);if(h)i[t]=h,ls(i[t]),os(i[t],e);else{const s=this.createTextTrack("captions",n,r);s&&(s[t]=!0,i[t]=s)}}createNonNativeTrack(t){if(this.nonNativeCaptionsTracks[t])return;const s=this.captionsProperties[t];if(!s)return;const i={_id:t,label:s.label,kind:"captions",default:!!s.media&&!!s.media.default,closedCaptions:s.media};this.nonNativeCaptionsTracks[t]=i,this.hls.trigger(d.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:[i]})}createTextTrack(t,s,i){const e=this.media;if(e)return e.addTextTrack(t,s,i)}onMediaAttaching(t,s){this.media=s.media,this._cleanTracks()}onMediaDetaching(){const{captionsTracks:t}=this;Object.keys(t).forEach((s=>{ls(t[s]),delete t[s]})),this.nonNativeCaptionsTracks={}}onManifestLoading(){this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}},this._cleanTracks(),this.tracks=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.textTracks=[],this.unparsedVttFrags=this.unparsedVttFrags||[],this.initPTS=[],this.cea608Parser1&&this.cea608Parser2&&(this.cea608Parser1.reset(),this.cea608Parser2.reset())}_cleanTracks(){const{media:t}=this;if(!t)return;const s=t.textTracks;if(s)for(let t=0;t<s.length;t++)ls(s[t])}onSubtitleTracksUpdated(t,s){const i=s.subtitleTracks||[],e=i.some((t=>t.textCodec===En));if(this.config.enableWebVTT||e&&this.config.enableIMSC1){if(Oe(this.tracks,i))return void(this.tracks=i);if(this.textTracks=[],this.tracks=i,this.config.renderTextTracksNatively){const t=this.media?this.media.textTracks:null;this.tracks.forEach(((s,i)=>{let e;if(t&&i<t.length){let i=null;for(let e=0;e<t.length;e++)if(Rn(t[e],s)){i=t[e];break}i&&(e=i)}if(e)ls(e);else{const t=this._captionsOrSubtitlesFromCharacteristics(s);e=this.createTextTrack(t,s.name,s.lang),e&&(e.mode="disabled")}e&&(e.groupId=s.groupId,this.textTracks.push(e))}))}else if(this.tracks.length){const t=this.tracks.map((t=>({label:t.name,kind:t.type.toLowerCase(),default:t.default,subtitleTrack:t})));this.hls.trigger(d.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:t})}}}_captionsOrSubtitlesFromCharacteristics(t){if(t.attrs.CHARACTERISTICS){const s=/transcribes-spoken-dialog/gi.test(t.attrs.CHARACTERISTICS),i=/describes-music-and-sound/gi.test(t.attrs.CHARACTERISTICS);if(s&&i)return"captions"}return"subtitles"}onManifestLoaded(t,s){this.config.enableCEA708Captions&&s.captions&&s.captions.forEach((t=>{const s=/(?:CC|SERVICE)([1-4])/.exec(t.instreamId);if(!s)return;const i=this.captionsProperties[`textTrack${s[1]}`];i&&(i.label=t.name,t.lang&&(i.languageCode=t.lang),i.media=t)}))}closedCaptionsForLevel(t){const s=this.hls.levels[t.level];return null==s?void 0:s.attrs["CLOSED-CAPTIONS"]}onFragLoading(t,s){const{cea608Parser1:i,cea608Parser2:e,lastSn:n,lastPartIndex:r}=this;if(this.enabled&&i&&e&&s.frag.type===ss){var h,o;const t=s.frag.sn,a=null!=(h=null==s||null==(o=s.part)?void 0:o.index)?h:-1;t===n+1||t===n&&a===r+1||(i.reset(),e.reset()),this.lastSn=t,this.lastPartIndex=a}}onFragLoaded(t,s){const{frag:i,payload:e}=s,{initPTS:n,unparsedVttFrags:r}=this;if(i.type===es)if(e.byteLength){if(!n[i.cc])return r.push(s),void(n.length&&this.hls.trigger(d.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:i,error:new Error("Missing initial subtitle PTS")}));const t=i.decryptdata;if(null==t||!t.encrypted||"stats"in s){const t=this.tracks[i.level],s=this.vttCCs;s[i.cc]||(s[i.cc]={start:i.start,prevCC:this.prevCC,new:!0},this.prevCC=i.cc),t&&t.textCodec===En?this._parseIMSC1(i,e):this._parseVTTs(i,e,s)}}else this.hls.trigger(d.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:i,error:new Error("Empty subtitle payload")})}_parseIMSC1(t,s){const i=this.hls;Ln(s,this.initPTS[t.cc],(s=>{this._appendCues(s,t.level),i.trigger(d.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:t})}),(s=>{y.log(`Failed to parse IMSC1: ${s}`),i.trigger(d.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:t,error:s})}))}_parseVTTs(t,s,i){var e;const n=this.hls;!function(t,s,i,e,n,r,h){const o=new yn,a=nt(new Uint8Array(t)).trim().replace(wn,"\n").split("\n"),l=[],c=function(t,s=1){return ae(t,9e4,1/s)}(s.baseTime,s.timescale);let d,f="00:00.000",m=0,g=0,v=!0;o.oncue=function(t){const s=i[e];let r=i.ccOffset;const h=(m-c)/9e4;null!=s&&s.new&&(void 0!==g?r=i.ccOffset=s.start:function(t,s,i){let e=t[s],n=t[e.prevCC];if(!n||!n.new&&e.new)return t.ccOffset=t.presentationOffset=e.start,void(e.new=!1);for(;null!=(r=n)&&r.new;){var r;t.ccOffset+=e.start-n.start,e.new=!1,e=n,n=t[e.prevCC]}t.presentationOffset=i}(i,e,h)),h&&(r=h-i.presentationOffset);const o=t.endTime-t.startTime,a=me(9e4*(t.startTime+r-g),9e4*n)/9e4;t.startTime=Math.max(a,0),t.endTime=Math.max(a+o,0);const u=t.text.trim();t.text=decodeURIComponent(encodeURIComponent(u)),t.id||(t.id=Sn(t.startTime,t.endTime,u)),t.endTime>0&&l.push(t)},o.onparsingerror=function(t){d=t},o.onflush=function(){d?h(d):r(l)},a.forEach((t=>{if(v){if(bn(t,"X-TIMESTAMP-MAP=")){v=!1,t.slice(16).split(",").forEach((t=>{bn(t,"LOCAL:")?f=t.slice(6):bn(t,"MPEGTS:")&&(m=parseInt(t.slice(7)))}));try{g=function(t){let s=parseInt(t.slice(-3));const i=parseInt(t.slice(-6,-4)),e=parseInt(t.slice(-9,-7)),n=t.length>9?parseInt(t.substring(0,t.indexOf(":"))):0;if(!(u(s)&&u(i)&&u(e)&&u(n)))throw Error(`Malformed X-TIMESTAMP-MAP: Local:${t}`);return s+=1e3*i,s+=6e4*e,s+=36e5*n,s}(f)/1e3}catch(t){d=t}return}""===t&&(v=!1)}o.parse(t+"\n")})),o.flush()}(null!=(e=t.initSegment)&&e.data?Tt(t.initSegment.data,new Uint8Array(s)):s,this.initPTS[t.cc],i,t.cc,t.start,(s=>{this._appendCues(s,t.level),n.trigger(d.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:t})}),(i=>{this._fallbackToIMSC1(t,s),y.log(`Failed to parse VTT cue: ${i}`),n.trigger(d.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:t,error:i})}))}_fallbackToIMSC1(t,s){const i=this.tracks[t.level];i.textCodec||Ln(s,this.initPTS[t.cc],(()=>{i.textCodec=En,this._parseIMSC1(t,s)}),(()=>{i.textCodec="wvtt"}))}_appendCues(t,s){const i=this.hls;if(this.config.renderTextTracksNatively){const i=this.textTracks[s];if(!i||"disabled"===i.mode)return;t.forEach((t=>as(i,t)))}else{const e=this.tracks[s];if(!e)return;i.trigger(d.CUES_PARSED,{type:"subtitles",cues:t,track:e.default?"default":"subtitles"+s})}}onFragDecrypted(t,s){const{frag:i}=s;if(i.type===es){if(!this.initPTS[i.cc])return void this.unparsedVttFrags.push(s);this.onFragLoaded(d.FRAG_LOADED,s)}}onSubtitleTracksCleared(){this.tracks=[],this.captionsTracks={}}onFragParsingUserdata(t,s){const{cea608Parser1:i,cea608Parser2:e}=this;if(!this.enabled||!i||!e)return;const{frag:n,samples:r}=s;if(n.type!==ss||"NONE"!==this.closedCaptionsForLevel(n))for(let t=0;t<r.length;t++){const s=r[t].bytes;if(s){const n=this.extractCea608Data(s);i.addData(r[t].pts,n[0]),e.addData(r[t].pts,n[1])}}}onBufferFlushing(t,{startOffset:s,endOffset:i,endOffsetSubtitles:e,type:n}){const{media:r}=this;if(r&&!(r.currentTime<i)){if(!n||"video"===n){const{captionsTracks:t}=this;Object.keys(t).forEach((e=>cs(t[e],s,i)))}if(this.config.renderTextTracksNatively&&0===s&&void 0!==e){const{textTracks:t}=this;Object.keys(t).forEach((i=>cs(t[i],s,e)))}}}extractCea608Data(t){const s=[[],[]],i=31&t[0];let e=2;for(let n=0;n<i;n++){const i=t[e++],n=127&t[e++],r=127&t[e++];if((0!==n||0!==r)&&0!=(4&i)){const t=3&i;0!==t&&1!==t||(s[t].push(n),s[t].push(r))}}return s}},audioStreamController:class extends $i{constructor(t,s,i){super(t,s,i,"[audio-stream-controller]",is),this.videoBuffer=null,this.videoTrackCC=-1,this.waitingVideoCC=-1,this.bufferedTrack=null,this.switchingTrack=null,this.trackId=-1,this.waitingData=null,this.mainDetails=null,this.bufferFlushed=!1,this.cachedTrackLoadedData=null,this._registerListeners()}onHandlerDestroying(){this._unregisterListeners(),this.mainDetails=null,this.bufferedTrack=null,this.switchingTrack=null}_registerListeners(){const{hls:t}=this;t.on(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.on(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.LEVEL_LOADED,this.onLevelLoaded,this),t.on(d.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),t.on(d.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.on(d.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.on(d.ERROR,this.onError,this),t.on(d.BUFFER_RESET,this.onBufferReset,this),t.on(d.BUFFER_CREATED,this.onBufferCreated,this),t.on(d.BUFFER_FLUSHED,this.onBufferFlushed,this),t.on(d.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(d.FRAG_BUFFERED,this.onFragBuffered,this)}_unregisterListeners(){const{hls:t}=this;t.off(d.MEDIA_ATTACHED,this.onMediaAttached,this),t.off(d.MEDIA_DETACHING,this.onMediaDetaching,this),t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.LEVEL_LOADED,this.onLevelLoaded,this),t.off(d.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),t.off(d.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),t.off(d.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.off(d.ERROR,this.onError,this),t.off(d.BUFFER_RESET,this.onBufferReset,this),t.off(d.BUFFER_CREATED,this.onBufferCreated,this),t.off(d.BUFFER_FLUSHED,this.onBufferFlushed,this),t.off(d.INIT_PTS_FOUND,this.onInitPtsFound,this),t.off(d.FRAG_BUFFERED,this.onFragBuffered,this)}onInitPtsFound(t,{frag:s,id:i,initPTS:e,timescale:n}){if("main"===i){const t=s.cc;this.initPTS[s.cc]={baseTime:e,timescale:n},this.log(`InitPTS for cc: ${t} found from main: ${e}`),this.videoTrackCC=t,this.state===Ei&&this.tick()}}startLoad(t){if(!this.levels)return this.startPosition=t,void(this.state=fi);const s=this.lastCurrentTime;this.stopLoad(),this.setInterval(100),s>0&&-1===t?(this.log(`Override startPosition with lastCurrentTime @${s.toFixed(3)}`),t=s,this.state=mi):(this.loadedmetadata=!1,this.state=yi),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=t,this.tick()}doTick(){switch(this.state){case mi:this.doTickIdle();break;case yi:{var t;const{levels:s,trackId:i}=this,e=null==s||null==(t=s[i])?void 0:t.details;if(e){if(this.waitForCdnTuneIn(e))break;this.state=Ei}break}case pi:{var s;const t=performance.now(),i=this.retryDate;(!i||t>=i||null!=(s=this.media)&&s.seeking)&&(this.log("RetryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded(this.trackId),this.state=mi);break}case Ei:{const t=this.waitingData;if(t){const{frag:s,part:i,cache:e,complete:n}=t;if(void 0!==this.initPTS[s.cc]){this.waitingData=null,this.waitingVideoCC=-1,this.state=vi;const t={frag:s,part:i,payload:e.flush(),networkDetails:null};this._handleFragmentLoadProgress(t),n&&super._handleFragmentLoadComplete(t)}else if(this.videoTrackCC!==this.waitingVideoCC)this.log(`Waiting fragment cc (${s.cc}) cancelled because video is at cc ${this.videoTrackCC}`),this.clearWaitingFragment();else{const t=this.getLoadPosition(),i=ei.bufferInfo(this.mediaBuffer,t,this.config.maxBufferHole);Rs(i.end,this.config.maxFragLookUpTolerance,s)<0&&(this.log(`Waiting fragment cc (${s.cc}) @ ${s.start} cancelled because another fragment at ${i.end} is needed`),this.clearWaitingFragment())}}else this.state=mi}}this.onTickEnd()}clearWaitingFragment(){const t=this.waitingData;t&&(this.fragmentTracker.removeFragment(t.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=mi)}resetLoadingState(){this.clearWaitingFragment(),super.resetLoadingState()}onTickEnd(){const{media:t}=this;null!=t&&t.readyState&&(this.lastCurrentTime=t.currentTime)}doTickIdle(){const{hls:t,levels:s,media:i,trackId:e}=this;if(null==s||!s[e])return;if(!i&&(this.startFragRequested||!t.config.startFragPrefetch))return;const n=s[e],r=n.details;if(!r||r.live&&this.levelLastLoaded!==e||this.waitForCdnTuneIn(r))return void(this.state=yi);const h=this.mediaBuffer?this.mediaBuffer:this.media;this.bufferFlushed&&h&&(this.bufferFlushed=!1,this.afterBufferFlushed(h,$,is));const o=this.getFwdBufferInfo(h,is);if(null===o)return;const{bufferedTrack:a,switchingTrack:l}=this;if(!l&&this._streamEnded(o,r))return t.trigger(d.BUFFER_EOS,{type:"audio"}),void(this.state=Ti);const c=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,ss),u=o.len,f=this.getMaxBufferLength(null==c?void 0:c.len);if(u>=f&&!l)return;const m=r.fragments[0].start;let g=o.end;if(l&&i){const t=this.getLoadPosition();a&&l.attrs!==a.attrs&&(g=t),r.PTSKnown&&t<m&&(o.end>m||o.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),i.currentTime=m+.05)}let v=this.getNextFragment(g,r),p=!1;if(v&&this.isLoopLoading(v,g)&&(p=!!v.gap,v=this.getNextFragmentLoopLoading(v,r,o,ss,f)),!v)return void(this.bufferFlushed=!0);const y=c&&v.start>c.end+r.targetduration;if(y||(null==c||!c.len)&&o.len){const t=this.getAppendedFrag(v.start,ss);if(null===t)return;if(p||(p=!!t.gap||!!y&&0===c.len),y&&!p||p&&o.nextStart&&o.nextStart<t.end)return}this.loadFragment(v,n,g)}getMaxBufferLength(t){const s=super.getMaxBufferLength();return t?Math.min(Math.max(s,t),this.config.maxMaxBufferLength):s}onMediaDetaching(){this.videoBuffer=null,super.onMediaDetaching()}onAudioTracksUpdated(t,{audioTracks:s}){this.resetTransmuxer(),this.levels=s.map((t=>new bs(t)))}onAudioTrackSwitching(t,s){const i=!!s.url;this.trackId=s.id;const{fragCurrent:e}=this;e&&(e.abortRequests(),this.removeUnbufferedFrags(e.start)),this.resetLoadingState(),i?this.setInterval(100):this.resetTransmuxer(),i?(this.switchingTrack=s,this.state=mi):(this.switchingTrack=null,this.bufferedTrack=s,this.state=fi),this.tick()}onManifestLoading(){this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=!1,this.levels=this.mainDetails=this.waitingData=this.bufferedTrack=this.cachedTrackLoadedData=this.switchingTrack=null,this.startFragRequested=!1,this.trackId=this.videoTrackCC=this.waitingVideoCC=-1}onLevelLoaded(t,s){this.mainDetails=s.details,null!==this.cachedTrackLoadedData&&(this.hls.trigger(d.AUDIO_TRACK_LOADED,this.cachedTrackLoadedData),this.cachedTrackLoadedData=null)}onAudioTrackLoaded(t,s){var i;if(null==this.mainDetails)return void(this.cachedTrackLoadedData=s);const{levels:e}=this,{details:n,id:r}=s;if(!e)return void this.warn(`Audio tracks were reset while loading level ${r}`);this.log(`Track ${r} loaded [${n.startSN},${n.endSN}]${n.lastPartSn?`[part-${n.lastPartSn}-${n.lastPartIndex}]`:""},duration:${n.totalduration}`);const h=e[r];let o=0;if(n.live||null!=(i=h.details)&&i.live){const t=this.mainDetails;if(n.fragments[0]||(n.deltaUpdateFailed=!0),n.deltaUpdateFailed||!t)return;!h.details&&n.hasProgramDateTime&&t.hasProgramDateTime?(ai(n,t),o=n.fragments[0].start):o=this.alignPlaylists(n,h.details)}h.details=n,this.levelLastLoaded=r,this.startFragRequested||!this.mainDetails&&n.live||this.setStartPosition(h.details,o),this.state!==yi||this.waitForCdnTuneIn(n)||(this.state=mi),this.tick()}_handleFragmentLoadProgress(t){var s;const{frag:i,part:e,payload:n}=t,{config:r,trackId:h,levels:o}=this;if(!o)return void this.warn(`Audio tracks were reset while fragment load was in progress. Fragment ${i.sn} of level ${i.level} will not be buffered`);const a=o[h];if(!a)return void this.warn("Audio track is undefined on fragment load progress");const l=a.details;if(!l)return this.warn("Audio track details undefined on fragment load progress"),void this.removeUnbufferedFrags(i.start);const c=r.defaultAudioCodec||a.audioCodec||"mp4a.40.2";let u=this.transmuxer;u||(u=this.transmuxer=new De(this.hls,is,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)));const d=this.initPTS[i.cc],f=null==(s=i.initSegment)?void 0:s.data;if(void 0!==d){const t=!1,s=e?e.index:-1,r=new ni(i.level,i.sn,i.stats.chunkCount,n.byteLength,s,-1!==s);u.push(n,f,c,"",i,e,l.totalduration,t,r,d)}else{this.log(`Unknown video PTS for cc ${i.cc}, waiting for video PTS before demuxing audio frag ${i.sn} of [${l.startSN} ,${l.endSN}],track ${h}`);const{cache:t}=this.waitingData=this.waitingData||{frag:i,part:e,cache:new Re,complete:!1};t.push(new Uint8Array(n)),this.waitingVideoCC=this.videoTrackCC,this.state=Ei}}_handleFragmentLoadComplete(t){this.waitingData?this.waitingData.complete=!0:super._handleFragmentLoadComplete(t)}onBufferReset(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1}onBufferCreated(t,s){const i=s.tracks.audio;i&&(this.mediaBuffer=i.buffer||null),s.tracks.video&&(this.videoBuffer=s.tracks.video.buffer||null)}onFragBuffered(t,s){const{frag:i,part:e}=s;var n;if(i.type===is)if(this.fragContextChanged(i))this.warn(`Fragment ${i.sn}${e?" p: "+e.index:""} of level ${i.level} finished buffering, but was aborted. state: ${this.state}, audioSwitch: ${this.switchingTrack?this.switchingTrack.name:"false"}`);else{if("initSegment"!==i.sn){this.fragPrevious=i;const t=this.switchingTrack;t&&(this.bufferedTrack=t,this.switchingTrack=null,this.hls.trigger(d.AUDIO_TRACK_SWITCHED,a({},t)))}this.fragBufferedComplete(i,e)}else this.loadedmetadata||i.type!==ss||null!=(n=this.videoBuffer||this.media)&&n.buffered.length&&(this.loadedmetadata=!0)}onError(t,s){var i;if(s.fatal)this.state=Si;else switch(s.details){case m.FRAG_GAP:case m.FRAG_PARSING_ERROR:case m.FRAG_DECRYPT_ERROR:case m.FRAG_LOAD_ERROR:case m.FRAG_LOAD_TIMEOUT:case m.KEY_LOAD_ERROR:case m.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(is,s);break;case m.AUDIO_TRACK_LOAD_ERROR:case m.AUDIO_TRACK_LOAD_TIMEOUT:case m.LEVEL_PARSING_ERROR:s.levelRetry||this.state!==yi||(null==(i=s.context)?void 0:i.type)!==Zt||(this.state=mi);break;case m.BUFFER_FULL_ERROR:if(!s.parent||"audio"!==s.parent)return;this.reduceLengthAndFlushBuffer(s)&&(this.bufferedTrack=null,super.flushMainBuffer(0,Number.POSITIVE_INFINITY,"audio"));break;case m.INTERNAL_EXCEPTION:this.recoverWorkerError(s)}}onBufferFlushed(t,{type:s}){s===$&&(this.bufferFlushed=!0,this.state===Ti&&(this.state=mi))}_handleTransmuxComplete(t){var s;const i="audio",{hls:e}=this,{remuxResult:n,chunkMeta:r}=t,h=this.getCurrentContext(r);if(!h)return void this.resetWhenMissingContext(r);const{frag:o,part:a,level:l}=h,{details:u}=l,{audio:f,text:m,id3:g,initSegment:v}=n;if(!this.fragContextChanged(o)&&u){if(this.state=wi,this.switchingTrack&&f&&this.completeAudioSwitch(this.switchingTrack),null!=v&&v.tracks){const t=o.initSegment||o;this._bufferInitSegment(v.tracks,t,r),e.trigger(d.FRAG_PARSING_INIT_SEGMENT,{frag:t,id:i,tracks:v.tracks})}if(f){const{startPTS:t,endPTS:s,startDTS:i,endDTS:e}=f;a&&(a.elementaryStreams[$]={startPTS:t,endPTS:s,startDTS:i,endDTS:e}),o.setElementaryStreamInfo($,t,s,i,e),this.bufferFragmentData(f,o,a,r)}if(null!=g&&null!=(s=g.samples)&&s.length){const t=c({id:i,frag:o,details:u},g);e.trigger(d.FRAG_PARSING_METADATA,t)}if(m){const t=c({id:i,frag:o,details:u},m);e.trigger(d.FRAG_PARSING_USERDATA,t)}}else this.fragmentTracker.removeFragment(o)}_bufferInitSegment(t,s,i){if(this.state!==wi)return;t.video&&delete t.video;const e=t.audio;if(!e)return;e.levelCodec=e.codec,e.id="audio",this.log(`Init audio buffer, container:${e.container}, codecs[parsed]=[${e.codec}]`),this.hls.trigger(d.BUFFER_CODECS,t);const n=e.initSegment;null!=n&&n.byteLength&&this.hls.trigger(d.BUFFER_APPENDING,{type:"audio",frag:s,part:null,chunkMeta:i,parent:s.type,data:n}),this.tick()}loadFragment(t,s,i){const e=this.fragmentTracker.getState(t);var n;this.fragCurrent=t,this.switchingTrack||e===Ks||e===Gs?"initSegment"===t.sn?this._loadInitSegment(t,s):null!=(n=s.details)&&n.live&&!this.initPTS[t.cc]?(this.log(`Waiting for video PTS in continuity counter ${t.cc} of live stream before loading audio fragment ${t.sn} of level ${this.trackId}`),this.state=Ei):(this.startFragRequested=!0,super.loadFragment(t,s,i)):this.clearTrackerIfNeeded(t)}completeAudioSwitch(t){const{hls:s,media:i,bufferedTrack:e}=this,n=null==e?void 0:e.attrs,r=t.attrs;i&&n&&(n.CHANNELS!==r.CHANNELS||n.NAME!==r.NAME||n.LANGUAGE!==r.LANGUAGE)&&(this.log("Switching audio track : flushing all audio"),super.flushMainBuffer(0,Number.POSITIVE_INFINITY,"audio")),this.bufferedTrack=t,this.switchingTrack=null,s.trigger(d.AUDIO_TRACK_SWITCHED,a({},t))}},audioTrackController:class extends Us{constructor(t){super(t,"[audio-track-controller]"),this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0,this.registerListeners()}registerListeners(){const{hls:t}=this;t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.MANIFEST_PARSED,this.onManifestParsed,this),t.on(d.LEVEL_LOADING,this.onLevelLoading,this),t.on(d.LEVEL_SWITCHING,this.onLevelSwitching,this),t.on(d.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.on(d.ERROR,this.onError,this)}unregisterListeners(){const{hls:t}=this;t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.MANIFEST_PARSED,this.onManifestParsed,this),t.off(d.LEVEL_LOADING,this.onLevelLoading,this),t.off(d.LEVEL_SWITCHING,this.onLevelSwitching,this),t.off(d.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),t.off(d.ERROR,this.onError,this)}destroy(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,this.currentTrack=null,super.destroy()}onManifestLoading(){this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0}onManifestParsed(t,s){this.tracks=s.audioTracks||[]}onAudioTrackLoaded(t,s){const{id:i,groupId:e,details:n}=s,r=this.tracksInGroup[i];if(!r||r.groupId!==e)return void this.warn(`Track with id:${i} and group:${e} not found in active group ${r.groupId}`);const h=r.details;r.details=s.details,this.log(`audio-track ${i} "${r.name}" lang:${r.lang} group:${e} loaded [${n.startSN}-${n.endSN}]`),i===this.trackId&&this.playlistLoaded(i,s,h)}onLevelLoading(t,s){this.switchLevel(s.level)}onLevelSwitching(t,s){this.switchLevel(s.level)}switchLevel(t){const s=this.hls.levels[t];if(null==s||!s.audioGroupIds)return;const i=s.audioGroupIds[s.urlId];if(this.groupId!==i){this.groupId=i||null;const t=this.tracks.filter((t=>!i||t.groupId===i));this.selectDefaultTrack&&!t.some((t=>t.default))&&(this.selectDefaultTrack=!1),this.tracksInGroup=t;const s={audioTracks:t};this.log(`Updating audio tracks, ${t.length} track(s) found in group:${i}`),this.hls.trigger(d.AUDIO_TRACKS_UPDATED,s),this.selectInitialTrack()}else this.shouldReloadPlaylist(this.currentTrack)&&this.setAudioTrack(this.trackId)}onError(t,s){!s.fatal&&s.context&&s.context.type===Zt&&s.context.id===this.trackId&&s.context.groupId===this.groupId&&(this.requestScheduled=-1,this.checkRetry(s))}get audioTracks(){return this.tracksInGroup}get audioTrack(){return this.trackId}set audioTrack(t){this.selectDefaultTrack=!1,this.setAudioTrack(t)}setAudioTrack(t){const s=this.tracksInGroup;if(t<0||t>=s.length)return void this.warn("Invalid id passed to audio-track controller");this.clearTimer();const i=this.currentTrack,e=s[t],{groupId:n,name:r}=e;if(this.log(`Switching to audio-track ${t} "${r}" lang:${e.lang} group:${n}`),this.trackId=t,this.currentTrack=e,this.selectDefaultTrack=!1,this.hls.trigger(d.AUDIO_TRACK_SWITCHING,a({},e)),e.details&&!e.details.live)return;const h=this.switchParams(e.url,null==i?void 0:i.details);this.loadPlaylist(h)}selectInitialTrack(){const t=this.tracksInGroup,s=this.findTrackId(this.currentTrack)|this.findTrackId(null);if(-1!==s)this.setAudioTrack(s);else{const s=new Error(`No track found for running audio group-ID: ${this.groupId} track count: ${t.length}`);this.warn(s.message),this.hls.trigger(d.ERROR,{type:f.MEDIA_ERROR,details:m.AUDIO_TRACK_LOAD_ERROR,fatal:!0,error:s})}}findTrackId(t){const s=this.tracksInGroup;for(let i=0;i<s.length;i++){const e=s[i];if(!this.selectDefaultTrack||e.default){if(!t||void 0!==t.attrs["STABLE-RENDITION-ID"]&&t.attrs["STABLE-RENDITION-ID"]===e.attrs["STABLE-RENDITION-ID"])return e.id;if(t.name===e.name&&t.lang===e.lang)return e.id}}return-1}loadPlaylist(t){super.loadPlaylist();const s=this.tracksInGroup[this.trackId];if(this.shouldLoadPlaylist(s)){const i=s.id,e=s.groupId;let n=s.url;if(t)try{n=t.addDirectives(n)}catch(t){this.warn(`Could not construct new URL with HLS Delivery Directives: ${t}`)}this.log(`loading audio-track playlist ${i} "${s.name}" lang:${s.lang} group:${e}`),this.clearTimer(),this.hls.trigger(d.AUDIO_TRACK_LOADING,{url:n,id:i,groupId:e,deliveryDirectives:t||null})}}},emeController:Un,cmcdController:jn,contentSteeringController:class{constructor(t){this.hls=void 0,this.log=void 0,this.loader=null,this.uri=null,this.pathwayId=".",this.pathwayPriority=null,this.timeToLoad=300,this.reloadTimer=-1,this.updated=0,this.started=!1,this.enabled=!0,this.levels=null,this.audioTracks=null,this.subtitleTracks=null,this.penalizedPathways={},this.hls=t,this.log=y.log.bind(y,"[content-steering]:"),this.registerListeners()}registerListeners(){const t=this.hls;t.on(d.MANIFEST_LOADING,this.onManifestLoading,this),t.on(d.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(d.MANIFEST_PARSED,this.onManifestParsed,this),t.on(d.ERROR,this.onError,this)}unregisterListeners(){const t=this.hls;t&&(t.off(d.MANIFEST_LOADING,this.onManifestLoading,this),t.off(d.MANIFEST_LOADED,this.onManifestLoaded,this),t.off(d.MANIFEST_PARSED,this.onManifestParsed,this),t.off(d.ERROR,this.onError,this))}startLoad(){if(this.started=!0,self.clearTimeout(this.reloadTimer),this.enabled&&this.uri)if(this.updated){const t=Math.max(1e3*this.timeToLoad-(performance.now()-this.updated),0);this.scheduleRefresh(this.uri,t)}else this.loadSteeringManifest(this.uri)}stopLoad(){this.started=!1,this.loader&&(this.loader.destroy(),this.loader=null),self.clearTimeout(this.reloadTimer)}destroy(){this.unregisterListeners(),this.stopLoad(),this.hls=null,this.levels=this.audioTracks=this.subtitleTracks=null}removeLevel(t){const s=this.levels;s&&(this.levels=s.filter((s=>s!==t)))}onManifestLoading(){this.stopLoad(),this.enabled=!0,this.timeToLoad=300,this.updated=0,this.uri=null,this.pathwayId=".",this.levels=this.audioTracks=this.subtitleTracks=null}onManifestLoaded(t,s){const{contentSteering:i}=s;null!==i&&(this.pathwayId=i.pathwayId,this.uri=i.uri,this.started&&this.startLoad())}onManifestParsed(t,s){this.audioTracks=s.audioTracks,this.subtitleTracks=s.subtitleTracks}onError(t,s){const{errorAction:i}=s;if(2===(null==i?void 0:i.action)&&1===i.flags){let t=this.pathwayPriority;const s=this.pathwayId;this.penalizedPathways[s]||(this.penalizedPathways[s]=performance.now()),!t&&this.levels&&(t=this.levels.reduce(((t,s)=>(-1===t.indexOf(s.pathwayId)&&t.push(s.pathwayId),t)),[])),t&&t.length>1&&(this.updatePathwayPriority(t),i.resolved=this.pathwayId!==s)}}filterParsedLevels(t){this.levels=t;let s=this.getLevelsForPathway(this.pathwayId);if(0===s.length){const i=t[0].pathwayId;this.log(`No levels found in Pathway ${this.pathwayId}. Setting initial Pathway to "${i}"`),s=this.getLevelsForPathway(i),this.pathwayId=i}return s.length!==t.length?(this.log(`Found ${s.length}/${t.length} levels in Pathway "${this.pathwayId}"`),s):t}getLevelsForPathway(t){return null===this.levels?[]:this.levels.filter((s=>t===s.pathwayId))}updatePathwayPriority(t){let s;this.pathwayPriority=t;const i=this.penalizedPathways,e=performance.now();Object.keys(i).forEach((t=>{e-i[t]>3e5&&delete i[t]}));for(let e=0;e<t.length;e++){const n=t[e];if(i[n])continue;if(n===this.pathwayId)return;const r=this.hls.nextLoadLevel,h=this.hls.levels[r];if(s=this.getLevelsForPathway(n),s.length>0){this.log(`Setting Pathway to "${n}"`),this.pathwayId=n,this.hls.trigger(d.LEVELS_UPDATED,{levels:s});const t=this.hls.levels[r];h&&t&&this.levels&&(t.attrs["STABLE-VARIANT-ID"]!==h.attrs["STABLE-VARIANT-ID"]&&t.bitrate!==h.bitrate&&this.log(`Unstable Pathways change from bitrate ${h.bitrate} to ${t.bitrate}`),this.hls.nextLoadLevel=r);break}}}clonePathways(t){const s=this.levels;if(!s)return;const i={},e={};t.forEach((t=>{const{ID:n,"BASE-ID":r,"URI-REPLACEMENT":h}=t;if(s.some((t=>t.pathwayId===n)))return;const o=this.getLevelsForPathway(r).map((t=>{const s=c({},t);s.details=void 0,s.url=Hn(t.uri,t.attrs["STABLE-VARIANT-ID"],"PER-VARIANT-URIS",h);const r=new T(t.attrs);r["PATHWAY-ID"]=n;const o=r.AUDIO&&`${r.AUDIO}_clone_${n}`,a=r.SUBTITLES&&`${r.SUBTITLES}_clone_${n}`;o&&(i[r.AUDIO]=o,r.AUDIO=o),a&&(e[r.SUBTITLES]=a,r.SUBTITLES=a),s.attrs=r;const l=new bs(s);return _s(l,"audio",o),_s(l,"text",a),l}));s.push(...o),Kn(this.audioTracks,i,h,n),Kn(this.subtitleTracks,e,h,n)}))}loadSteeringManifest(t){const s=this.hls.config,i=s.loader;let e;this.loader&&this.loader.destroy(),this.loader=new i(s);try{e=new self.URL(t)}catch(s){return this.enabled=!1,void this.log(`Failed to parse Steering Manifest URI: ${t}`)}if("data:"!==e.protocol){const t=0|(this.hls.bandwidthEstimate||s.abrEwmaDefaultEstimate);e.searchParams.set("_HLS_pathway",this.pathwayId),e.searchParams.set("_HLS_throughput",""+t)}const n={responseType:"json",url:e.href},r=s.steeringManifestLoadPolicy.default,h=r.errorRetry||r.timeoutRetry||{},o={loadPolicy:r,timeout:r.maxLoadTimeMs,maxRetry:h.maxNumRetry||0,retryDelay:h.retryDelayMs||0,maxRetryDelay:h.maxRetryDelayMs||0},a={onSuccess:(t,s,i)=>{this.log(`Loaded steering manifest: "${e}"`);const n=t.data;if(1!==n.VERSION)return void this.log(`Steering VERSION ${n.VERSION} not supported!`);this.updated=performance.now(),this.timeToLoad=n.TTL;const{"RELOAD-URI":r,"PATHWAY-CLONES":h,"PATHWAY-PRIORITY":o}=n;if(r)try{this.uri=new self.URL(r,e).href}catch(t){return this.enabled=!1,void this.log(`Failed to parse Steering Manifest RELOAD-URI: ${r}`)}this.scheduleRefresh(this.uri||i.url),h&&this.clonePathways(h),o&&this.updatePathwayPriority(o)},onError:(t,s)=>{if(this.log(`Error loading steering manifest: ${t.code} ${t.text} (${s.url})`),this.stopLoad(),410===t.code)return this.enabled=!1,void this.log(`Steering manifest ${s.url} no longer available`);let i=1e3*this.timeToLoad;if(429!==t.code)this.scheduleRefresh(this.uri||s.url,i);else{const t=this.loader;if("function"==typeof(null==t?void 0:t.getResponseHeader)){const s=t.getResponseHeader("Retry-After");s&&(i=1e3*parseFloat(s))}this.log(`Steering manifest ${s.url} rate limited`)}},onTimeout:(t,s)=>{this.log(`Timeout loading steering manifest (${s.url})`),this.scheduleRefresh(this.uri||s.url)}};this.log(`Requesting steering manifest: ${e}`),this.loader.load(n,o,a)}scheduleRefresh(t,s=1e3*this.timeToLoad){self.clearTimeout(this.reloadTimer),this.reloadTimer=self.setTimeout((()=>{this.loadSteeringManifest(t)}),s)}}});function Zn(t){return t&&"object"==typeof t?Array.isArray(t)?t.map(Zn):Object.keys(t).reduce(((s,i)=>(s[i]=Zn(t[i]),s)),{}):t}class tr{static get version(){return"1.4.1"}static isSupported(){return function(){const t=Rt();if(!t)return!1;const s=Ai();return!(!t||"function"!=typeof t.isTypeSupported||!t.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')||s&&(!s.prototype||"function"!=typeof s.prototype.appendBuffer||"function"!=typeof s.prototype.remove))}()}static get Events(){return d}static get ErrorTypes(){return f}static get ErrorDetails(){return m}static get DefaultConfig(){return tr.defaultConfig?tr.defaultConfig:Jn}static set DefaultConfig(t){tr.defaultConfig=t}constructor(t={}){this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this._emitter=new Le,this._autoLevelCapping=void 0,this._maxHdcpLevel=null,this.abrController=void 0,this.bufferController=void 0,this.capLevelController=void 0,this.latencyController=void 0,this.levelController=void 0,this.streamController=void 0,this.audioTrackController=void 0,this.subtitleTrackController=void 0,this.emeController=void 0,this.cmcdController=void 0,this._media=null,this.url=null,function(t){if(self.console&&!0===t||"object"==typeof t){!function(t,...s){s.forEach((function(s){p[s]=t[s]?t[s].bind(t):function(t){const s=self.console[t];return s?s.bind(self.console,`[${t}] >`):g}(s)}))}(t,"debug","log","info","warn","error");try{p.log('Debug logs enabled for "Hls instance" in hls.js version 1.4.1')}catch(t){p=v}}else p=v}(t.debug||!1);const s=this.config=function(t,s){if((s.liveSyncDurationCount||s.liveMaxLatencyDurationCount)&&(s.liveSyncDuration||s.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(void 0!==s.liveMaxLatencyDurationCount&&(void 0===s.liveSyncDurationCount||s.liveMaxLatencyDurationCount<=s.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(void 0!==s.liveMaxLatencyDuration&&(void 0===s.liveSyncDuration||s.liveMaxLatencyDuration<=s.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');const i=Zn(t),e=["TimeOut","MaxRetry","RetryDelay","MaxRetryTimeout"];return["manifest","level","frag"].forEach((t=>{const n=`${"level"===t?"playlist":t}LoadPolicy`,r=void 0===s[n],h=[];e.forEach((e=>{const o=`${t}Loading${e}`,a=s[o];if(void 0!==a&&r){h.push(o);const t=i[n].default;switch(s[n]={default:t},e){case"TimeOut":t.maxLoadTimeMs=a,t.maxTimeToFirstByteMs=a;break;case"MaxRetry":t.errorRetry.maxNumRetry=a,t.timeoutRetry.maxNumRetry=a;break;case"RetryDelay":t.errorRetry.retryDelayMs=a,t.timeoutRetry.retryDelayMs=a;break;case"MaxRetryTimeout":t.errorRetry.maxRetryDelayMs=a,t.timeoutRetry.maxRetryDelayMs=a}}})),h.length&&y.warn(`hls.js config: "${h.join('", "')}" setting(s) are deprecated, use "${n}": ${JSON.stringify(s[n])}`)})),a(a({},i),s)}(tr.DefaultConfig,t);this.userConfig=t,this._autoLevelCapping=-1,s.progressive&&function(t){const s=t.loader;s!==Xn&&s!==Vn?(y.log("[config]: Custom loader detected, cannot enable progressive streaming"),t.progressive=!1):function(){if(self.fetch&&self.AbortController&&self.ReadableStream&&self.Request)try{return new self.ReadableStream({}),!0}catch(t){}return!1}()&&(t.loader=Xn,t.progressive=!0,t.enableSoftwareAES=!0,y.log("[config]: Progressive streaming enabled, using FetchLoader"))}(s);const{abrController:i,bufferController:e,capLevelController:n,errorController:r,fpsController:h}=s,o=new r(this),l=this.abrController=new i(this),c=this.bufferController=new e(this),u=this.capLevelController=new n(this),f=new h(this),m=new hs(this),w=new vs(this),b=s.contentSteeringController,T=b?new b(this):null,S=this.levelController=new Bs(this,T),E=new Ws(this),k=new ti(this.config),$=this.streamController=new Ie(this,E,k);u.setStreamController($),f.setStreamController($);const A=[m,S,$];T&&A.splice(1,0,T),this.networkControllers=A;const L=[l,c,u,f,w,E];this.audioTrackController=this.createController(s.audioTrackController,A);const M=s.audioStreamController;M&&A.push(new M(this,E,k)),this.subtitleTrackController=this.createController(s.subtitleTrackController,A);const D=s.subtitleStreamController;D&&A.push(new D(this,E,k)),this.createController(s.timelineController,L),k.emeController=this.emeController=this.createController(s.emeController,L),this.cmcdController=this.createController(s.cmcdController,L),this.latencyController=this.createController(ps,L),this.coreComponents=L,A.push(o);const x=o.onErrorOut;"function"==typeof x&&this.on(d.ERROR,x,o)}createController(t,s){if(t){const i=new t(this);return s&&s.push(i),i}return null}on(t,s,i=this){this._emitter.on(t,s,i)}once(t,s,i=this){this._emitter.once(t,s,i)}removeAllListeners(t){this._emitter.removeAllListeners(t)}off(t,s,i=this,e){this._emitter.off(t,s,i,e)}listeners(t){return this._emitter.listeners(t)}emit(t,s,i){return this._emitter.emit(t,s,i)}trigger(t,s){if(this.config.debug)return this.emit(t,t,s);try{return this.emit(t,t,s)}catch(s){y.error("An internal error happened while handling event "+t+'. Error message: "'+s.message+'". Here is a stacktrace:',s),this.trigger(d.ERROR,{type:f.OTHER_ERROR,details:m.INTERNAL_EXCEPTION,fatal:!1,event:t,error:s})}return!1}listenerCount(t){return this._emitter.listenerCount(t)}destroy(){y.log("destroy"),this.trigger(d.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach((t=>t.destroy())),this.networkControllers.length=0,this.coreComponents.forEach((t=>t.destroy())),this.coreComponents.length=0;const t=this.config;t.xhrSetup=t.fetchSetup=void 0,this.userConfig=null}attachMedia(t){y.log("attachMedia"),this._media=t,this.trigger(d.MEDIA_ATTACHING,{media:t})}detachMedia(){y.log("detachMedia"),this.trigger(d.MEDIA_DETACHING,void 0),this._media=null}loadSource(t){this.stopLoad();const s=this.media,i=this.url,e=this.url=h.buildAbsoluteURL(self.location.href,t,{alwaysNormalize:!0});y.log(`loadSource:${e}`),s&&i&&(i!==e||this.bufferController.hasSourceTypes())&&(this.detachMedia(),this.attachMedia(s)),this.trigger(d.MANIFEST_LOADING,{url:t})}startLoad(t=-1){y.log(`startLoad(${t})`),this.networkControllers.forEach((s=>{s.startLoad(t)}))}stopLoad(){y.log("stopLoad"),this.networkControllers.forEach((t=>{t.stopLoad()}))}swapAudioCodec(){y.log("swapAudioCodec"),this.streamController.swapAudioCodec()}recoverMediaError(){y.log("recoverMediaError");const t=this._media;this.detachMedia(),t&&this.attachMedia(t)}removeLevel(t,s=0){this.levelController.removeLevel(t,s)}get levels(){return this.levelController.levels||[]}get currentLevel(){return this.streamController.currentLevel}set currentLevel(t){y.log(`set currentLevel:${t}`),this.loadLevel=t,this.abrController.clearTimer(),this.streamController.immediateLevelSwitch()}get nextLevel(){return this.streamController.nextLevel}set nextLevel(t){y.log(`set nextLevel:${t}`),this.levelController.manualLevel=t,this.streamController.nextLevelSwitch()}get loadLevel(){return this.levelController.level}set loadLevel(t){y.log(`set loadLevel:${t}`),this.levelController.manualLevel=t}get nextLoadLevel(){return this.levelController.nextLoadLevel}set nextLoadLevel(t){this.levelController.nextLoadLevel=t}get firstLevel(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)}set firstLevel(t){y.log(`set firstLevel:${t}`),this.levelController.firstLevel=t}get startLevel(){return this.levelController.startLevel}set startLevel(t){y.log(`set startLevel:${t}`),-1!==t&&(t=Math.max(t,this.minAutoLevel)),this.levelController.startLevel=t}get capLevelToPlayerSize(){return this.config.capLevelToPlayerSize}set capLevelToPlayerSize(t){const s=!!t;s!==this.config.capLevelToPlayerSize&&(s?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=s)}get autoLevelCapping(){return this._autoLevelCapping}get bandwidthEstimate(){const{bwEstimator:t}=this.abrController;return t?t.getEstimate():NaN}get ttfbEstimate(){const{bwEstimator:t}=this.abrController;return t?t.getEstimateTTFB():NaN}set autoLevelCapping(t){this._autoLevelCapping!==t&&(y.log(`set autoLevelCapping:${t}`),this._autoLevelCapping=t)}get maxHdcpLevel(){return this._maxHdcpLevel}set maxHdcpLevel(t){ys.indexOf(t)>-1&&(this._maxHdcpLevel=t)}get autoLevelEnabled(){return-1===this.levelController.manualLevel}get manualLevel(){return this.levelController.manualLevel}get minAutoLevel(){const{levels:t,config:{minAutoBitrate:s}}=this;if(!t)return 0;const i=t.length;for(let e=0;e<i;e++)if(t[e].maxBitrate>=s)return e;return 0}get maxAutoLevel(){const{levels:t,autoLevelCapping:s,maxHdcpLevel:i}=this;let e;if(e=-1===s&&t&&t.length?t.length-1:s,i)for(let s=e;s--;){const e=t[s].attrs["HDCP-LEVEL"];if(e&&e<=i)return s}return e}get nextAutoLevel(){return Math.min(Math.max(this.abrController.nextAutoLevel,this.minAutoLevel),this.maxAutoLevel)}set nextAutoLevel(t){this.abrController.nextAutoLevel=Math.max(this.minAutoLevel,t)}get playingDate(){return this.streamController.currentProgramDateTime}get mainForwardBufferInfo(){return this.streamController.getMainFwdBufferInfo()}get audioTracks(){const t=this.audioTrackController;return t?t.audioTracks:[]}get audioTrack(){const t=this.audioTrackController;return t?t.audioTrack:-1}set audioTrack(t){const s=this.audioTrackController;s&&(s.audioTrack=t)}get subtitleTracks(){const t=this.subtitleTrackController;return t?t.subtitleTracks:[]}get subtitleTrack(){const t=this.subtitleTrackController;return t?t.subtitleTrack:-1}get media(){return this._media}set subtitleTrack(t){const s=this.subtitleTrackController;s&&(s.subtitleTrack=t)}get subtitleDisplay(){const t=this.subtitleTrackController;return!!t&&t.subtitleDisplay}set subtitleDisplay(t){const s=this.subtitleTrackController;s&&(s.subtitleDisplay=t)}get lowLatencyMode(){return this.config.lowLatencyMode}set lowLatencyMode(t){this.config.lowLatencyMode=t}get liveSyncPosition(){return this.latencyController.liveSyncPosition}get latency(){return this.latencyController.latency}get maxLatency(){return this.latencyController.maxLatency}get targetLatency(){return this.latencyController.targetLatency}get drift(){return this.latencyController.drift}get forceStartLoad(){return this.streamController.forceStartLoad}}tr.defaultConfig=void 0;export default tr;