@kolkrabbi/design-editor 0.1.0 → 0.3.0

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 (252) hide show
  1. package/README.md +42 -25
  2. package/dist/BufferResource-BfLgK37S.js +273 -0
  3. package/dist/CanvasPool-YNSF8hsR.js +30 -0
  4. package/dist/CanvasRenderer-Bl0rlqNq.js +2 -0
  5. package/dist/FederatedEventTarget-BJgROaRQ.js +975 -0
  6. package/dist/FilterSystem-BUrPNXx-.js +1323 -0
  7. package/dist/Geometry-C5s5KpWq.js +3805 -0
  8. package/dist/{OrbitControls-BAhLQ5d8.js → OrbitControls-Cql8Rn2i.js} +10305 -9058
  9. package/dist/RenderTargetSystem-oFwWv5IW.js +2889 -0
  10. package/dist/WebGLRenderer-CXxpVIx3.js +2 -0
  11. package/dist/WebGPURenderer-BwLEUYBa.js +2 -0
  12. package/dist/browserAll-CAzdTUbR.js +6 -0
  13. package/dist/canvasUtils-BoNfkAod.js +168 -0
  14. package/dist/chunk-3b4jIN3o.js +13 -0
  15. package/dist/design-editor.css +2 -2
  16. package/dist/design-editor.js +52017 -38760
  17. package/dist/getTextureBatchBindGroup-CNWhZRbV.js +19 -0
  18. package/dist/{host-IfZgcJFg.js → host-CVR9RL_W.js} +505 -556
  19. package/dist/{host-Cidlc8xP.js → host-be1CWhN1.js} +133 -85
  20. package/dist/init-jApIMi04.js +4 -0
  21. package/dist/phase-t_DhU5Nm.js +1719 -0
  22. package/dist/pipeline-CMpuPUaX.js +11995 -0
  23. package/dist/src-QwKcYKfv.js +4315 -0
  24. package/dist/webworkerAll-DEZhpG90.js +2 -0
  25. package/package.json +42 -31
  26. package/LICENSE +0 -21
  27. package/dist/favicon/favicon.svg +0 -12
  28. package/dist/fonts/Right-Grotesk/PPRightGrotesk-Black.woff2 +0 -0
  29. package/dist/fonts/Right-Grotesk/PPRightGrotesk-BlackItalic.woff2 +0 -0
  30. package/dist/fonts/Right-Grotesk/PPRightGrotesk-Bold.woff2 +0 -0
  31. package/dist/fonts/Right-Grotesk/PPRightGrotesk-BoldItalic.woff2 +0 -0
  32. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactBlack.woff2 +0 -0
  33. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactBlackItalic.woff2 +0 -0
  34. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactBold.woff2 +0 -0
  35. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactBoldItalic.woff2 +0 -0
  36. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactDark.woff2 +0 -0
  37. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactDarkItalic.woff2 +0 -0
  38. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactFine.woff2 +0 -0
  39. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactFineItalic.woff2 +0 -0
  40. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactLight.woff2 +0 -0
  41. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactLightItalic.woff2 +0 -0
  42. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactMedium.woff2 +0 -0
  43. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactMediumItalic.woff2 +0 -0
  44. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactRegular.woff2 +0 -0
  45. package/dist/fonts/Right-Grotesk/PPRightGrotesk-CompactRegularItalic.woff2 +0 -0
  46. package/dist/fonts/Right-Grotesk/PPRightGrotesk-Dark.woff2 +0 -0
  47. package/dist/fonts/Right-Grotesk/PPRightGrotesk-DarkItalic.woff2 +0 -0
  48. package/dist/fonts/Right-Grotesk/PPRightGrotesk-Fine.woff2 +0 -0
  49. package/dist/fonts/Right-Grotesk/PPRightGrotesk-FineItalic.woff2 +0 -0
  50. package/dist/fonts/Right-Grotesk/PPRightGrotesk-Light.woff2 +0 -0
  51. package/dist/fonts/Right-Grotesk/PPRightGrotesk-LightItalic.woff2 +0 -0
  52. package/dist/fonts/Right-Grotesk/PPRightGrotesk-Medium.woff2 +0 -0
  53. package/dist/fonts/Right-Grotesk/PPRightGrotesk-MediumItalic.woff2 +0 -0
  54. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowBlack.woff2 +0 -0
  55. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowBlackItalic.woff2 +0 -0
  56. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowBold.woff2 +0 -0
  57. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowBoldItalic.woff2 +0 -0
  58. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowDark.woff2 +0 -0
  59. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowDarkItalic.woff2 +0 -0
  60. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowFine.woff2 +0 -0
  61. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowFineItalic.woff2 +0 -0
  62. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowLight.woff2 +0 -0
  63. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowLightItalic.woff2 +0 -0
  64. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowMedium.woff2 +0 -0
  65. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowMediumItalic.woff2 +0 -0
  66. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowRegular.woff2 +0 -0
  67. package/dist/fonts/Right-Grotesk/PPRightGrotesk-NarrowRegularItalic.woff2 +0 -0
  68. package/dist/fonts/Right-Grotesk/PPRightGrotesk-Regular.woff2 +0 -0
  69. package/dist/fonts/Right-Grotesk/PPRightGrotesk-RegularItalic.woff2 +0 -0
  70. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialBlack.woff2 +0 -0
  71. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialBlackItalic.woff2 +0 -0
  72. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialBold.woff2 +0 -0
  73. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialBoldItalic.woff2 +0 -0
  74. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialDark.woff2 +0 -0
  75. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialDarkItalic.woff2 +0 -0
  76. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialFine.woff2 +0 -0
  77. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialFineItalic.woff2 +0 -0
  78. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialLight.woff2 +0 -0
  79. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialLightItalic.woff2 +0 -0
  80. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialMedium.woff2 +0 -0
  81. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialMediumItalic.woff2 +0 -0
  82. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialRegular.woff2 +0 -0
  83. package/dist/fonts/Right-Grotesk/PPRightGrotesk-SpatialRegularItalic.woff2 +0 -0
  84. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallBlack.woff2 +0 -0
  85. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallBlackItalic.woff2 +0 -0
  86. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallBold.woff2 +0 -0
  87. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallBoldItalic.woff2 +0 -0
  88. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallDark.woff2 +0 -0
  89. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallDarkItalic.woff2 +0 -0
  90. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallFine.woff2 +0 -0
  91. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallFineItalic.woff2 +0 -0
  92. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallLight.woff2 +0 -0
  93. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallLightItalic.woff2 +0 -0
  94. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallMedium.woff2 +0 -0
  95. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallMediumItalic.woff2 +0 -0
  96. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallRegular.woff2 +0 -0
  97. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TallRegularItalic.woff2 +0 -0
  98. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightBlack.woff2 +0 -0
  99. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightBlackItalic.woff2 +0 -0
  100. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightBold.woff2 +0 -0
  101. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightBoldItalic.woff2 +0 -0
  102. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightDark.woff2 +0 -0
  103. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightDarkItalic.woff2 +0 -0
  104. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightFine.woff2 +0 -0
  105. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightFineItalic.woff2 +0 -0
  106. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightLight.woff2 +0 -0
  107. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightLightItalic.woff2 +0 -0
  108. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightMedium.woff2 +0 -0
  109. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightMediumItalic.woff2 +0 -0
  110. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightRegular.woff2 +0 -0
  111. package/dist/fonts/Right-Grotesk/PPRightGrotesk-TightRegularItalic.woff2 +0 -0
  112. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideBlack.woff2 +0 -0
  113. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideBlackItalic.woff2 +0 -0
  114. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideBold.woff2 +0 -0
  115. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideBoldItalic.woff2 +0 -0
  116. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideDark.woff2 +0 -0
  117. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideDarkItalic.woff2 +0 -0
  118. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideFine.woff2 +0 -0
  119. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideFineItalic.woff2 +0 -0
  120. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideLight.woff2 +0 -0
  121. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideLightItalic.woff2 +0 -0
  122. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideMedium.woff2 +0 -0
  123. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideMediumItalic.woff2 +0 -0
  124. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideRegular.woff2 +0 -0
  125. package/dist/fonts/Right-Grotesk/PPRightGrotesk-WideRegularItalic.woff2 +0 -0
  126. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-Bold.woff2 +0 -0
  127. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-BoldItalic.woff2 +0 -0
  128. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-Dark.woff2 +0 -0
  129. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-Fine.woff2 +0 -0
  130. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-FineItalic.woff2 +0 -0
  131. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-Light.woff2 +0 -0
  132. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-Medium.woff2 +0 -0
  133. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-Regular.woff2 +0 -0
  134. package/dist/fonts/Right-Grotesk-Mono/PPRightGroteskMono-RegularItalic.woff2 +0 -0
  135. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-CompactLight.woff2 +0 -0
  136. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-CompactLightItalic.woff2 +0 -0
  137. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-CompactMedium.woff2 +0 -0
  138. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-CompactMediumItalic.woff2 +0 -0
  139. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-Regular.woff2 +0 -0
  140. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-RegularItalic.woff2 +0 -0
  141. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-SpatialBold.woff2 +0 -0
  142. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-SpatialBoldItalic.woff2 +0 -0
  143. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-SpatialLight.woff2 +0 -0
  144. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-SpatialLightItalic.woff2 +0 -0
  145. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-WideBold.woff2 +0 -0
  146. package/dist/fonts/Right-Grotesk-Text/PPRightGroteskText-WideBoldItalic.woff2 +0 -0
  147. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-Black.ttf +0 -0
  148. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-BlackItalic.ttf +0 -0
  149. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-Bold.ttf +0 -0
  150. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-BoldItalic.ttf +0 -0
  151. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactBlack.ttf +0 -0
  152. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactBlackItalic.ttf +0 -0
  153. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactBold.ttf +0 -0
  154. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactBoldItalic.ttf +0 -0
  155. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactDark.ttf +0 -0
  156. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactDarkItalic.ttf +0 -0
  157. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactFine.ttf +0 -0
  158. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactFineItalic.ttf +0 -0
  159. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactLight.ttf +0 -0
  160. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactLightItalic.ttf +0 -0
  161. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactMedium.ttf +0 -0
  162. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactMediumItalic.ttf +0 -0
  163. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactRegular.ttf +0 -0
  164. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-CompactRegularItalic.ttf +0 -0
  165. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-Dark.ttf +0 -0
  166. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-DarkItalic.ttf +0 -0
  167. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-Fine.ttf +0 -0
  168. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-FineItalic.ttf +0 -0
  169. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-Light.ttf +0 -0
  170. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-LightItalic.ttf +0 -0
  171. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-Medium.ttf +0 -0
  172. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-MediumItalic.ttf +0 -0
  173. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowBlack.ttf +0 -0
  174. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowBlackItalic.ttf +0 -0
  175. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowBold.ttf +0 -0
  176. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowBoldItalic.ttf +0 -0
  177. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowDark.ttf +0 -0
  178. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowDarkItalic.ttf +0 -0
  179. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowFine.ttf +0 -0
  180. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowFineItalic.ttf +0 -0
  181. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowLight.ttf +0 -0
  182. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowLightItalic.ttf +0 -0
  183. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowMedium.ttf +0 -0
  184. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowMediumItalic.ttf +0 -0
  185. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowRegular.ttf +0 -0
  186. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-NarrowRegularItalic.ttf +0 -0
  187. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-Regular.ttf +0 -0
  188. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-RegularItalic.ttf +0 -0
  189. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialBlack.ttf +0 -0
  190. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialBlackItalic.ttf +0 -0
  191. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialBold.ttf +0 -0
  192. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialBoldItalic.ttf +0 -0
  193. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialDark.ttf +0 -0
  194. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialDarkItalic.ttf +0 -0
  195. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialFine.ttf +0 -0
  196. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialFineItalic.ttf +0 -0
  197. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialLight.ttf +0 -0
  198. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialLightItalic.ttf +0 -0
  199. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialMedium.ttf +0 -0
  200. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialMediumItalic.ttf +0 -0
  201. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialRegular.ttf +0 -0
  202. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-SpatialRegularItalic.ttf +0 -0
  203. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallBlack.ttf +0 -0
  204. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallBlackItalic.ttf +0 -0
  205. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallBold.ttf +0 -0
  206. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallBoldItalic.ttf +0 -0
  207. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallDark.ttf +0 -0
  208. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallDarkItalic.ttf +0 -0
  209. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallFine.ttf +0 -0
  210. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallFineItalic.ttf +0 -0
  211. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallLight.ttf +0 -0
  212. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallLightItalic.ttf +0 -0
  213. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallMedium.ttf +0 -0
  214. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallMediumItalic.ttf +0 -0
  215. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallRegular.ttf +0 -0
  216. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TallRegularItalic.ttf +0 -0
  217. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightBlack.ttf +0 -0
  218. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightBlackItalic.ttf +0 -0
  219. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightBold.ttf +0 -0
  220. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightBoldItalic.ttf +0 -0
  221. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightDark.ttf +0 -0
  222. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightDarkItalic.ttf +0 -0
  223. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightFine.ttf +0 -0
  224. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightFineItalic.ttf +0 -0
  225. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightLight.ttf +0 -0
  226. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightLightItalic.ttf +0 -0
  227. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightMedium.ttf +0 -0
  228. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightMediumItalic.ttf +0 -0
  229. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightRegular.ttf +0 -0
  230. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-TightRegularItalic.ttf +0 -0
  231. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideBlack.ttf +0 -0
  232. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideBlackItalic.ttf +0 -0
  233. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideBold.ttf +0 -0
  234. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideBoldItalic.ttf +0 -0
  235. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideDark.ttf +0 -0
  236. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideDarkItalic.ttf +0 -0
  237. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideFine.ttf +0 -0
  238. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideFineItalic.ttf +0 -0
  239. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideLight.ttf +0 -0
  240. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideLightItalic.ttf +0 -0
  241. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideMedium.ttf +0 -0
  242. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideMediumItalic.ttf +0 -0
  243. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideRegular.ttf +0 -0
  244. package/dist/fonts/Right-Grotesk-ttf/PPRightGrotesk-WideRegularItalic.ttf +0 -0
  245. package/dist/fonts/TG/TGGullhamrarVF.ttf +0 -0
  246. package/dist/fonts/TG/TGMalromurRomanVF.ttf +0 -0
  247. package/dist/fonts/TG/TGRotVF.ttf +0 -0
  248. package/dist/fonts/jetbrains-mono/JetBrainsMono-Medium.woff2 +0 -0
  249. package/dist/fonts/jetbrains-mono/JetBrainsMono-MediumItalic.woff2 +0 -0
  250. package/dist/fonts/jetbrains-mono/JetBrainsMono-Regular.woff2 +0 -0
  251. package/dist/fonts/jetbrains-mono/JetBrainsMono-SemiBold.woff2 +0 -0
  252. package/dist/meshPalettes-BJODHYrY.js +0 -892
@@ -0,0 +1,4315 @@
1
+ import "./chunk-3b4jIN3o.js";
2
+ import { t as e } from "./design-editor.js";
3
+ //#region ../../node_modules/.pnpm/mediabunny@1.55.6/node_modules/mediabunny/dist/modules/src/misc.js
4
+ function t(e) {
5
+ if (!e) throw Error("Assertion failed.");
6
+ }
7
+ var n = (e) => {
8
+ let t = (e % 360 + 360) % 360;
9
+ if (t === 0 || t === 90 || t === 180 || t === 270) return t;
10
+ throw Error(`Invalid rotation ${e}.`);
11
+ }, r = (e) => e && e[e.length - 1], i = (e) => {
12
+ let t = 0;
13
+ for (; e.readBits(1) === 0 && t < 32;) t++;
14
+ if (t >= 32) throw Error("Invalid exponential-Golomb code.");
15
+ return (1 << t) - 1 + e.readBits(t);
16
+ }, a = (e, t, n, r) => {
17
+ for (let i = t; i < n; i++) {
18
+ let t = Math.floor(i / 8), a = e[t], o = 7 - (i & 7);
19
+ a &= ~(1 << o), a |= (r & 1 << n - i - 1) >> n - i - 1 << o, e[t] = a;
20
+ }
21
+ }, o = (e) => e.constructor === Uint8Array ? e : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : new Uint8Array(e), s = (e) => e.constructor === DataView ? e : ArrayBuffer.isView(e) ? new DataView(e.buffer, e.byteOffset, e.byteLength) : new DataView(e), c = /* #__PURE__ */ new TextEncoder(), l = {
22
+ bt709: 1,
23
+ bt470bg: 5,
24
+ smpte170m: 6,
25
+ bt2020: 9,
26
+ smpte432: 12
27
+ }, u = {
28
+ bt709: 1,
29
+ smpte170m: 6,
30
+ linear: 8,
31
+ "iec61966-2-1": 13,
32
+ pq: 16,
33
+ hlg: 18
34
+ }, d = {
35
+ rgb: 0,
36
+ bt709: 1,
37
+ bt470bg: 5,
38
+ smpte170m: 6,
39
+ "bt2020-ncl": 9
40
+ }, f = (e) => !e || e.primaries == null && e.transfer == null && e.matrix == null && e.fullRange == null, p = (e) => e instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer || ArrayBuffer.isView(e), m = class {
41
+ constructor() {
42
+ this.currentPromise = Promise.resolve(), this.pending = 0;
43
+ }
44
+ async acquire() {
45
+ let e, t = new Promise((t) => {
46
+ let n = !1;
47
+ e = () => {
48
+ n ||= (t(), this.pending--, !0);
49
+ };
50
+ }), n = this.currentPromise;
51
+ return this.currentPromise = t, this.pending++, await n, e;
52
+ }
53
+ }, h = (e, t, n) => {
54
+ let r = 0, i = e.length - 1, a = -1;
55
+ for (; r <= i;) {
56
+ let o = r + (i - r + 1) / 2 | 0;
57
+ n(e[o]) <= t ? (a = o, r = o + 1) : i = o - 1;
58
+ }
59
+ return a;
60
+ }, g = () => {
61
+ let e, t;
62
+ return {
63
+ promise: new Promise((n, r) => {
64
+ e = n, t = r;
65
+ }),
66
+ resolve: e,
67
+ reject: t
68
+ };
69
+ }, _ = (e) => {
70
+ throw Error(`Unexpected value: ${e}`);
71
+ }, v = (e, t, n) => {
72
+ let r = e.getUint8(t), i = e.getUint8(t + 1), a = e.getUint8(t + 2);
73
+ return n ? r | i << 8 | a << 16 : r << 16 | i << 8 | a;
74
+ }, y = (e, t, n) => Math.max(t, Math.min(n, e)), b = (e, t, n) => e + (t - e) * n, x = (e, t) => Math.round(e / t) * t, S = (e, t) => Math.round(e * t) / t, C = (e, t) => Math.floor(e * t) / t, ee = /^[a-z]{3}$/, te = (e) => ee.test(e), w = 1e6 * (1 + 2 ** -52), ne = class {
75
+ constructor() {
76
+ this.currentPromise = Promise.resolve();
77
+ }
78
+ call(e) {
79
+ return this.currentPromise = this.currentPromise.then(e);
80
+ }
81
+ }, re = null, ie = () => re === null ? re = typeof navigator < "u" && navigator.userAgent?.includes("Firefox") : re, T = null, ae = () => T === null ? T = !!(typeof navigator < "u" && (navigator.vendor?.includes("Google Inc") || /Chrome/.test(navigator.userAgent))) : T, oe = (e) => globalThis.isSecureContext !== void 0 && !globalThis.isSecureContext ? `${e} is not available in this environment; this may be because this page is running in an insecure context. Try serving your page over HTTPS or use localhost.` : `${e} is not available in this environment.`, se = (/* #__PURE__ */ (async () => {})()).constructor, E = (e) => e instanceof se || e instanceof Promise ? !0 : typeof e?.then == "function", ce = function* (e) {
82
+ for (let t in e) {
83
+ let n = e[t];
84
+ n !== void 0 && (yield {
85
+ key: t,
86
+ value: n
87
+ });
88
+ }
89
+ }, le = (e) => {
90
+ switch (e.toLowerCase()) {
91
+ case "image/jpeg":
92
+ case "image/jpg": return ".jpg";
93
+ case "image/png": return ".png";
94
+ case "image/gif": return ".gif";
95
+ case "image/webp": return ".webp";
96
+ case "image/bmp": return ".bmp";
97
+ case "image/svg+xml": return ".svg";
98
+ case "image/tiff": return ".tiff";
99
+ case "image/avif": return ".avif";
100
+ case "image/x-icon":
101
+ case "image/vnd.microsoft.icon": return ".ico";
102
+ default: return null;
103
+ }
104
+ }, ue = (e, t) => {
105
+ if (e.length !== t.length) return !1;
106
+ for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
107
+ return !0;
108
+ }, de = () => {
109
+ Symbol.dispose ??= Symbol("Symbol.dispose");
110
+ }, fe = (e) => typeof e == "number" && !Number.isNaN(e), pe = (e, t) => {
111
+ let n = -1, r = Infinity;
112
+ for (let i = 0; i < e.length; i++) {
113
+ let a = t(e[i]);
114
+ a < r && (r = a, n = i);
115
+ }
116
+ return n;
117
+ }, me = (e) => {
118
+ t(Number.isInteger(e.num)), t(Number.isInteger(e.den)), t(e.den !== 0);
119
+ let n = Math.abs(e.num), r = Math.abs(e.den);
120
+ for (; r !== 0;) {
121
+ let e = n % r;
122
+ n = r, r = e;
123
+ }
124
+ let i = n || 1;
125
+ return {
126
+ num: e.num / i,
127
+ den: e.den / i
128
+ };
129
+ }, D = (e, t) => {
130
+ if (typeof e != "object" || !e) throw TypeError(`${t} must be an object.`);
131
+ if (!Number.isInteger(e.left) || e.left < 0) throw TypeError(`${t}.left must be a non-negative integer.`);
132
+ if (!Number.isInteger(e.top) || e.top < 0) throw TypeError(`${t}.top must be a non-negative integer.`);
133
+ if (!Number.isInteger(e.width) || e.width < 0) throw TypeError(`${t}.width must be a non-negative integer.`);
134
+ if (!Number.isInteger(e.height) || e.height < 0) throw TypeError(`${t}.height must be a non-negative integer.`);
135
+ }, he = (e) => new Promise((t) => setTimeout(t, e)), ge = (e) => Array.isArray(e) ? e : [e], O = class {
136
+ constructor() {
137
+ this._listeners = /* @__PURE__ */ new Map();
138
+ }
139
+ on(e, t, n) {
140
+ this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
141
+ let r = {
142
+ fn: t,
143
+ once: n?.once ?? !1
144
+ };
145
+ return this._listeners.get(e).add(r), () => {
146
+ this._listeners.get(e)?.delete(r);
147
+ };
148
+ }
149
+ _emit(...e) {
150
+ let [t, n] = e, r = this._listeners.get(t);
151
+ if (r) for (let e of r) {
152
+ try {
153
+ e.fn(n);
154
+ } catch (e) {
155
+ console.error(e);
156
+ }
157
+ e.once && r.delete(e);
158
+ }
159
+ }
160
+ }, _e = (e) => typeof e == "object" && !!e && Object.getPrototypeOf(e) === Object.prototype && Object.values(e).every((e) => typeof e == "string"), k;
161
+ (function(e) {
162
+ e[e.Silent = 0] = "Silent", e[e.Errors = 1] = "Errors", e[e.Warnings = 2] = "Warnings", e[e.Info = 3] = "Info";
163
+ })(k ||= {});
164
+ var A = class e {
165
+ constructor() {}
166
+ static get level() {
167
+ return e._level;
168
+ }
169
+ static set level(t) {
170
+ if (t !== k.Silent && t !== k.Errors && t !== k.Warnings && t !== k.Info) throw TypeError("Invalid log level. Use one of the values of the LogLevel enum.");
171
+ e._level = t;
172
+ }
173
+ static get _emitter() {
174
+ return e._emitterInstance ??= new O();
175
+ }
176
+ static on(t, n, r) {
177
+ return e._emitter.on(t, n, r);
178
+ }
179
+ static _error(...t) {
180
+ e._emitter._emit("error", t), e._level >= k.Errors && console.error(...t);
181
+ }
182
+ static _warn(...t) {
183
+ e._emitter._emit("warn", t), e._level >= k.Warnings && console.warn(...t);
184
+ }
185
+ static _info(...t) {
186
+ e._emitter._emit("info", t), e._level >= k.Info && console.info(...t);
187
+ }
188
+ };
189
+ A._level = k.Info, A._emitterInstance = null;
190
+ //#endregion
191
+ //#region ../../node_modules/.pnpm/mediabunny@1.55.6/node_modules/mediabunny/dist/modules/src/metadata.js
192
+ var ve = class {
193
+ constructor(e, t) {
194
+ if (this.data = e, this.mimeType = t, !(e instanceof Uint8Array)) throw TypeError("data must be a Uint8Array.");
195
+ if (typeof t != "string") throw TypeError("mimeType must be a string.");
196
+ }
197
+ }, ye = class {
198
+ constructor(e, t, n, r) {
199
+ if (this.data = e, this.mimeType = t, this.name = n, this.description = r, !(e instanceof Uint8Array)) throw TypeError("data must be a Uint8Array.");
200
+ if (t !== void 0 && typeof t != "string") throw TypeError("mimeType, when provided, must be a string.");
201
+ if (n !== void 0 && typeof n != "string") throw TypeError("name, when provided, must be a string.");
202
+ if (r !== void 0 && typeof r != "string") throw TypeError("description, when provided, must be a string.");
203
+ }
204
+ }, be = (e) => {
205
+ if (!e || typeof e != "object") throw TypeError("tags must be an object.");
206
+ if (e.title !== void 0 && typeof e.title != "string") throw TypeError("tags.title, when provided, must be a string.");
207
+ if (e.description !== void 0 && typeof e.description != "string") throw TypeError("tags.description, when provided, must be a string.");
208
+ if (e.artist !== void 0 && typeof e.artist != "string") throw TypeError("tags.artist, when provided, must be a string.");
209
+ if (e.album !== void 0 && typeof e.album != "string") throw TypeError("tags.album, when provided, must be a string.");
210
+ if (e.albumArtist !== void 0 && typeof e.albumArtist != "string") throw TypeError("tags.albumArtist, when provided, must be a string.");
211
+ if (e.trackNumber !== void 0 && (!Number.isInteger(e.trackNumber) || e.trackNumber <= 0)) throw TypeError("tags.trackNumber, when provided, must be a positive integer.");
212
+ if (e.tracksTotal !== void 0 && (!Number.isInteger(e.tracksTotal) || e.tracksTotal <= 0)) throw TypeError("tags.tracksTotal, when provided, must be a positive integer.");
213
+ if (e.discNumber !== void 0 && (!Number.isInteger(e.discNumber) || e.discNumber <= 0)) throw TypeError("tags.discNumber, when provided, must be a positive integer.");
214
+ if (e.discsTotal !== void 0 && (!Number.isInteger(e.discsTotal) || e.discsTotal <= 0)) throw TypeError("tags.discsTotal, when provided, must be a positive integer.");
215
+ if (e.genre !== void 0 && typeof e.genre != "string") throw TypeError("tags.genre, when provided, must be a string.");
216
+ if (e.date !== void 0 && (!(e.date instanceof Date) || Number.isNaN(e.date.getTime()))) throw TypeError("tags.date, when provided, must be a valid Date.");
217
+ if (e.lyrics !== void 0 && typeof e.lyrics != "string") throw TypeError("tags.lyrics, when provided, must be a string.");
218
+ if (e.images !== void 0) {
219
+ if (!Array.isArray(e.images)) throw TypeError("tags.images, when provided, must be an array.");
220
+ for (let t of e.images) {
221
+ if (!t || typeof t != "object") throw TypeError("Each image in tags.images must be an object.");
222
+ if (!(t.data instanceof Uint8Array)) throw TypeError("Each image.data must be a Uint8Array.");
223
+ if (typeof t.mimeType != "string") throw TypeError("Each image.mimeType must be a string.");
224
+ if (![
225
+ "coverFront",
226
+ "coverBack",
227
+ "unknown"
228
+ ].includes(t.kind)) throw TypeError("Each image.kind must be 'coverFront', 'coverBack', or 'unknown'.");
229
+ }
230
+ }
231
+ if (e.comment !== void 0 && typeof e.comment != "string") throw TypeError("tags.comment, when provided, must be a string.");
232
+ if (e.raw !== void 0) {
233
+ if (!e.raw || typeof e.raw != "object") throw TypeError("tags.raw, when provided, must be an object.");
234
+ for (let t of Object.values(e.raw)) if (t !== null && typeof t != "string" && !(t instanceof Uint8Array) && !(t instanceof ve) && !(t instanceof ye) && !_e(t)) throw TypeError("Each value in tags.raw must be a string, Uint8Array, RichImageData, AttachedFile, Record<string, string>, or null.");
235
+ }
236
+ }, xe = (e) => {
237
+ if (!e || typeof e != "object") throw TypeError("disposition must be an object.");
238
+ if (e.default !== void 0 && typeof e.default != "boolean") throw TypeError("disposition.default must be a boolean.");
239
+ if (e.primary !== void 0 && typeof e.primary != "boolean") throw TypeError("disposition.primary must be a boolean.");
240
+ if (e.forced !== void 0 && typeof e.forced != "boolean") throw TypeError("disposition.forced must be a boolean.");
241
+ if (e.original !== void 0 && typeof e.original != "boolean") throw TypeError("disposition.original must be a boolean.");
242
+ if (e.commentary !== void 0 && typeof e.commentary != "boolean") throw TypeError("disposition.commentary must be a boolean.");
243
+ if (e.hearingImpaired !== void 0 && typeof e.hearingImpaired != "boolean") throw TypeError("disposition.hearingImpaired must be a boolean.");
244
+ if (e.visuallyImpaired !== void 0 && typeof e.visuallyImpaired != "boolean") throw TypeError("disposition.visuallyImpaired must be a boolean.");
245
+ }, j = class e {
246
+ constructor(e) {
247
+ this.bytes = e, this.pos = 0;
248
+ }
249
+ seekToByte(e) {
250
+ this.pos = 8 * e;
251
+ }
252
+ readBit() {
253
+ let e = Math.floor(this.pos / 8), t = this.bytes[e] ?? 0, n = 7 - (this.pos & 7), r = (t & 1 << n) >> n;
254
+ return this.pos++, r;
255
+ }
256
+ readBits(e) {
257
+ if (e === 1) return this.readBit();
258
+ let t = 0;
259
+ for (let n = 0; n < e; n++) t <<= 1, t |= this.readBit();
260
+ return t;
261
+ }
262
+ writeBits(e, t) {
263
+ let n = this.pos + e;
264
+ for (let e = this.pos; e < n; e++) {
265
+ let r = Math.floor(e / 8), i = this.bytes[r], a = 7 - (e & 7);
266
+ i &= ~(1 << a), i |= (t & 1 << n - e - 1) >> n - e - 1 << a, this.bytes[r] = i;
267
+ }
268
+ this.pos = n;
269
+ }
270
+ readAlignedByte() {
271
+ if (this.pos % 8 != 0) throw Error("Bitstream is not byte-aligned.");
272
+ let e = this.pos / 8, t = this.bytes[e] ?? 0;
273
+ return this.pos += 8, t;
274
+ }
275
+ skipBits(e) {
276
+ this.pos += e;
277
+ }
278
+ getBitsLeft() {
279
+ return this.bytes.length * 8 - this.pos;
280
+ }
281
+ clone() {
282
+ let t = new e(this.bytes);
283
+ return t.pos = this.pos, t;
284
+ }
285
+ }, Se = [
286
+ 96e3,
287
+ 88200,
288
+ 64e3,
289
+ 48e3,
290
+ 44100,
291
+ 32e3,
292
+ 24e3,
293
+ 22050,
294
+ 16e3,
295
+ 12e3,
296
+ 11025,
297
+ 8e3,
298
+ 7350
299
+ ], Ce = [
300
+ -1,
301
+ 1,
302
+ 2,
303
+ 3,
304
+ 4,
305
+ 5,
306
+ 6,
307
+ 8
308
+ ], we = (e) => {
309
+ let t = e.objectType === 5 || e.objectType === 29, n = e.objectType === 29, r = t ? e.outputSampleRate / 2 : e.outputSampleRate, i = n ? 1 : e.outputNumberOfChannels, a = Ce.indexOf(i);
310
+ if (a === -1) throw TypeError(`Unsupported number of channels: ${e.outputNumberOfChannels}`);
311
+ let o = 16;
312
+ e.objectType >= 32 && (o += 6), De(r) === 15 && (o += 24), t && (o += 9, De(e.outputSampleRate) === 15 && (o += 24));
313
+ let s = Math.ceil(o / 8), c = new Uint8Array(s), l = new j(c);
314
+ return Te(l, e.objectType), Ee(l, r), l.writeBits(4, a), t && (Ee(l, e.outputSampleRate), Te(l, 2)), l.writeBits(3, 0), c;
315
+ }, Te = (e, t) => {
316
+ t < 32 ? e.writeBits(5, t) : (e.writeBits(5, 31), e.writeBits(6, t - 32));
317
+ }, Ee = (e, t) => {
318
+ let n = De(t);
319
+ e.writeBits(4, n), n === 15 && e.writeBits(24, t);
320
+ }, De = (e) => {
321
+ let t = Se.indexOf(e);
322
+ return t === -1 ? 15 : t;
323
+ }, M;
324
+ (function(e) {
325
+ e[e.NON_IDR_SLICE = 1] = "NON_IDR_SLICE", e[e.SLICE_DPA = 2] = "SLICE_DPA", e[e.SLICE_DPB = 3] = "SLICE_DPB", e[e.SLICE_DPC = 4] = "SLICE_DPC", e[e.IDR = 5] = "IDR", e[e.SEI = 6] = "SEI", e[e.SPS = 7] = "SPS", e[e.PPS = 8] = "PPS", e[e.AUD = 9] = "AUD", e[e.SPS_EXT = 13] = "SPS_EXT";
326
+ })(M ||= {});
327
+ var Oe;
328
+ (function(e) {
329
+ e[e.RASL_N = 8] = "RASL_N", e[e.RASL_R = 9] = "RASL_R", e[e.BLA_W_LP = 16] = "BLA_W_LP", e[e.RSV_IRAP_VCL23 = 23] = "RSV_IRAP_VCL23", e[e.VPS_NUT = 32] = "VPS_NUT", e[e.SPS_NUT = 33] = "SPS_NUT", e[e.PPS_NUT = 34] = "PPS_NUT", e[e.AUD_NUT = 35] = "AUD_NUT", e[e.PREFIX_SEI_NUT = 39] = "PREFIX_SEI_NUT", e[e.SUFFIX_SEI_NUT = 40] = "SUFFIX_SEI_NUT";
330
+ })(Oe ||= {});
331
+ var ke = function* (e) {
332
+ let t = 0, n = -1;
333
+ for (; t < e.length - 2;) {
334
+ let r = e.indexOf(0, t);
335
+ if (r === -1 || r >= e.length - 2) break;
336
+ t = r;
337
+ let i = 0;
338
+ if (t + 3 < e.length && e[t + 1] === 0 && e[t + 2] === 0 && e[t + 3] === 1 ? i = 4 : e[t + 1] === 0 && e[t + 2] === 1 && (i = 3), i === 0) {
339
+ t++;
340
+ continue;
341
+ }
342
+ n !== -1 && t > n && (yield {
343
+ offset: n,
344
+ length: t - n
345
+ }), n = t + i, t = n;
346
+ }
347
+ n !== -1 && n < e.length && (yield {
348
+ offset: n,
349
+ length: e.length - n
350
+ });
351
+ }, Ae = function* (e, n) {
352
+ let r = 0, i = new DataView(e.buffer, e.byteOffset, e.byteLength);
353
+ for (; r + n <= e.length;) {
354
+ let e;
355
+ n === 1 ? e = i.getUint8(r) : n === 2 ? e = i.getUint16(r, !1) : n === 3 ? e = v(i, r, !1) : (t(n === 4), e = i.getUint32(r, !1)), r += n, yield {
356
+ offset: r,
357
+ length: e
358
+ }, r += e;
359
+ }
360
+ }, je = (e, t) => t.description ? Ae(e, (o(t.description)[4] & 3) + 1) : ke(e), Me = (e) => e & 31, Ne = (e) => {
361
+ let t = [], n = e.length;
362
+ for (let r = 0; r < n; r++) r + 2 < n && e[r] === 0 && e[r + 1] === 0 && e[r + 2] === 3 ? (t.push(0, 0), r += 2) : t.push(e[r]);
363
+ return new Uint8Array(t);
364
+ };
365
+ new Uint8Array([
366
+ 0,
367
+ 0,
368
+ 0,
369
+ 1
370
+ ]);
371
+ var Pe = (e, t) => t.description ? Ae(e, (o(t.description)[21] & 3) + 1) : ke(e), Fe = (e) => e >> 1 & 63, Ie;
372
+ (function(e) {
373
+ e[e.audAllowed = 0] = "audAllowed", e[e.beforeFirstVcl = 1] = "beforeFirstVcl", e[e.afterFirstVcl = 2] = "afterFirstVcl", e[e.eoBitstreamAllowed = 3] = "eoBitstreamAllowed", e[e.noMoreDataAllowed = 4] = "noMoreDataAllowed";
374
+ })(Ie ||= {});
375
+ var Le = function* (e) {
376
+ let n = new j(e), r = () => {
377
+ let e = 0;
378
+ for (let t = 0; t < 8; t++) {
379
+ let r = n.readAlignedByte();
380
+ if (e += (r & 127) * 2 ** (t * 7), !(r & 128)) break;
381
+ if (t === 7 && r & 128) return null;
382
+ }
383
+ return e > 2 ** 32 - 1 ? null : e;
384
+ };
385
+ for (; n.getBitsLeft() >= 8;) {
386
+ n.skipBits(1);
387
+ let i = n.readBits(4), a = n.readBits(1), o = n.readBits(1);
388
+ n.skipBits(1), a && n.skipBits(8);
389
+ let s;
390
+ if (o) {
391
+ let e = r();
392
+ if (e === null) return;
393
+ s = e;
394
+ } else s = Math.floor(n.getBitsLeft() / 8);
395
+ t(n.pos % 8 == 0), yield {
396
+ type: i,
397
+ data: e.subarray(n.pos / 8, n.pos / 8 + s)
398
+ }, n.skipBits(s * 8);
399
+ }
400
+ }, Re = (e) => {
401
+ let t = s(e), n = t.getUint8(9), r = t.getUint16(10, !0), i = t.getUint32(12, !0), a = t.getInt16(16, !0), o = t.getUint8(18), c = null;
402
+ return o && (c = e.subarray(19, 21 + n)), {
403
+ outputChannelCount: n,
404
+ preSkip: r,
405
+ inputSampleRate: i,
406
+ outputGain: a,
407
+ channelMappingFamily: o,
408
+ channelMappingTable: c
409
+ };
410
+ }, ze = (e, n, r) => {
411
+ switch (e) {
412
+ case "avc":
413
+ for (let e of je(r, n)) {
414
+ let t = r[e.offset], n = Me(t);
415
+ if (n >= M.NON_IDR_SLICE && n <= M.SLICE_DPC) return "delta";
416
+ if (n === M.IDR) return "key";
417
+ if (n === M.SEI && !ae()) {
418
+ let t = Ne(r.subarray(e.offset, e.offset + e.length)), n = 1;
419
+ do {
420
+ let e = 0;
421
+ for (;;) {
422
+ let r = t[n++];
423
+ if (r === void 0 || (e += r, r < 255)) break;
424
+ }
425
+ let r = 0;
426
+ for (;;) {
427
+ let e = t[n++];
428
+ if (e === void 0 || (r += e, e < 255)) break;
429
+ }
430
+ if (e === 6) {
431
+ let e = new j(t);
432
+ e.pos = 8 * n;
433
+ let r = i(e), a = e.readBits(1);
434
+ if (r === 0 && a === 1) return "key";
435
+ }
436
+ n += r;
437
+ } while (n < t.length - 1);
438
+ }
439
+ }
440
+ return "delta";
441
+ case "hevc":
442
+ for (let e of Pe(r, n)) {
443
+ let t = Fe(r[e.offset]);
444
+ if (t < Oe.BLA_W_LP) return "delta";
445
+ if (t <= Oe.RSV_IRAP_VCL23) return "key";
446
+ }
447
+ return "delta";
448
+ case "vp8": return r[0] & 1 ? "delta" : "key";
449
+ case "vp9": {
450
+ let e = new j(r);
451
+ if (e.readBits(2) !== 2) return null;
452
+ let t = e.readBits(1);
453
+ return (e.readBits(1) << 1) + t === 3 && e.skipBits(1), e.readBits(1) ? null : e.readBits(1) === 0 ? "key" : "delta";
454
+ }
455
+ case "av1": {
456
+ let e = !1;
457
+ for (let { type: t, data: n } of Le(r)) if (t === 1) {
458
+ let t = new j(n);
459
+ t.skipBits(4), e = !!t.readBits(1);
460
+ } else if (t === 3 || t === 6 || t === 7) {
461
+ if (e) return "key";
462
+ let t = new j(n);
463
+ return t.readBits(1) ? null : t.readBits(2) === 0 ? "key" : "delta";
464
+ }
465
+ return null;
466
+ }
467
+ case "prores": return "key";
468
+ default: _(e), t(!1);
469
+ }
470
+ }, Be;
471
+ (function(e) {
472
+ e[e.STREAMINFO = 0] = "STREAMINFO", e[e.VORBIS_COMMENT = 4] = "VORBIS_COMMENT", e[e.PICTURE = 6] = "PICTURE";
473
+ })(Be ||= {}), new Uint8Array([
474
+ 5,
475
+ 4,
476
+ 65,
477
+ 67,
478
+ 45,
479
+ 51
480
+ ]), new Uint8Array([
481
+ 5,
482
+ 4,
483
+ 69,
484
+ 65,
485
+ 67,
486
+ 51
487
+ ]);
488
+ //#endregion
489
+ //#region ../../node_modules/.pnpm/mediabunny@1.55.6/node_modules/mediabunny/dist/modules/src/codec.js
490
+ var N = [
491
+ "avc",
492
+ "hevc",
493
+ "vp9",
494
+ "av1",
495
+ "vp8",
496
+ "prores"
497
+ ], P = [
498
+ "pcm-s16",
499
+ "pcm-s16be",
500
+ "pcm-s24",
501
+ "pcm-s24be",
502
+ "pcm-s32",
503
+ "pcm-s32be",
504
+ "pcm-f32",
505
+ "pcm-f32be",
506
+ "pcm-f64",
507
+ "pcm-f64be",
508
+ "pcm-u8",
509
+ "pcm-s8",
510
+ "ulaw",
511
+ "alaw"
512
+ ], Ve = [
513
+ "aac",
514
+ "opus",
515
+ "mp3",
516
+ "vorbis",
517
+ "flac",
518
+ "ac3",
519
+ "eac3",
520
+ "dts"
521
+ ], F = [...Ve, ...P], I = ["webvtt"], He = [
522
+ {
523
+ maxMacroblocks: 99,
524
+ maxBitrate: 64e3,
525
+ maxDpbMbs: 396,
526
+ level: 10
527
+ },
528
+ {
529
+ maxMacroblocks: 396,
530
+ maxBitrate: 192e3,
531
+ maxDpbMbs: 900,
532
+ level: 11
533
+ },
534
+ {
535
+ maxMacroblocks: 396,
536
+ maxBitrate: 384e3,
537
+ maxDpbMbs: 2376,
538
+ level: 12
539
+ },
540
+ {
541
+ maxMacroblocks: 396,
542
+ maxBitrate: 768e3,
543
+ maxDpbMbs: 2376,
544
+ level: 13
545
+ },
546
+ {
547
+ maxMacroblocks: 396,
548
+ maxBitrate: 2e6,
549
+ maxDpbMbs: 2376,
550
+ level: 20
551
+ },
552
+ {
553
+ maxMacroblocks: 792,
554
+ maxBitrate: 4e6,
555
+ maxDpbMbs: 4752,
556
+ level: 21
557
+ },
558
+ {
559
+ maxMacroblocks: 1620,
560
+ maxBitrate: 4e6,
561
+ maxDpbMbs: 8100,
562
+ level: 22
563
+ },
564
+ {
565
+ maxMacroblocks: 1620,
566
+ maxBitrate: 1e7,
567
+ maxDpbMbs: 8100,
568
+ level: 30
569
+ },
570
+ {
571
+ maxMacroblocks: 3600,
572
+ maxBitrate: 14e6,
573
+ maxDpbMbs: 18e3,
574
+ level: 31
575
+ },
576
+ {
577
+ maxMacroblocks: 5120,
578
+ maxBitrate: 2e7,
579
+ maxDpbMbs: 20480,
580
+ level: 32
581
+ },
582
+ {
583
+ maxMacroblocks: 8192,
584
+ maxBitrate: 2e7,
585
+ maxDpbMbs: 32768,
586
+ level: 40
587
+ },
588
+ {
589
+ maxMacroblocks: 8192,
590
+ maxBitrate: 5e7,
591
+ maxDpbMbs: 32768,
592
+ level: 41
593
+ },
594
+ {
595
+ maxMacroblocks: 8704,
596
+ maxBitrate: 5e7,
597
+ maxDpbMbs: 34816,
598
+ level: 42
599
+ },
600
+ {
601
+ maxMacroblocks: 22080,
602
+ maxBitrate: 135e6,
603
+ maxDpbMbs: 110400,
604
+ level: 50
605
+ },
606
+ {
607
+ maxMacroblocks: 36864,
608
+ maxBitrate: 24e7,
609
+ maxDpbMbs: 184320,
610
+ level: 51
611
+ },
612
+ {
613
+ maxMacroblocks: 36864,
614
+ maxBitrate: 24e7,
615
+ maxDpbMbs: 184320,
616
+ level: 52
617
+ },
618
+ {
619
+ maxMacroblocks: 139264,
620
+ maxBitrate: 24e7,
621
+ maxDpbMbs: 696320,
622
+ level: 60
623
+ },
624
+ {
625
+ maxMacroblocks: 139264,
626
+ maxBitrate: 48e7,
627
+ maxDpbMbs: 696320,
628
+ level: 61
629
+ },
630
+ {
631
+ maxMacroblocks: 139264,
632
+ maxBitrate: 8e8,
633
+ maxDpbMbs: 696320,
634
+ level: 62
635
+ }
636
+ ], Ue = [
637
+ {
638
+ maxPictureSize: 36864,
639
+ maxBitrate: 128e3,
640
+ tier: "L",
641
+ level: 30
642
+ },
643
+ {
644
+ maxPictureSize: 122880,
645
+ maxBitrate: 15e5,
646
+ tier: "L",
647
+ level: 60
648
+ },
649
+ {
650
+ maxPictureSize: 245760,
651
+ maxBitrate: 3e6,
652
+ tier: "L",
653
+ level: 63
654
+ },
655
+ {
656
+ maxPictureSize: 552960,
657
+ maxBitrate: 6e6,
658
+ tier: "L",
659
+ level: 90
660
+ },
661
+ {
662
+ maxPictureSize: 983040,
663
+ maxBitrate: 1e7,
664
+ tier: "L",
665
+ level: 93
666
+ },
667
+ {
668
+ maxPictureSize: 2228224,
669
+ maxBitrate: 12e6,
670
+ tier: "L",
671
+ level: 120
672
+ },
673
+ {
674
+ maxPictureSize: 2228224,
675
+ maxBitrate: 3e7,
676
+ tier: "H",
677
+ level: 120
678
+ },
679
+ {
680
+ maxPictureSize: 2228224,
681
+ maxBitrate: 2e7,
682
+ tier: "L",
683
+ level: 123
684
+ },
685
+ {
686
+ maxPictureSize: 2228224,
687
+ maxBitrate: 5e7,
688
+ tier: "H",
689
+ level: 123
690
+ },
691
+ {
692
+ maxPictureSize: 8912896,
693
+ maxBitrate: 25e6,
694
+ tier: "L",
695
+ level: 150
696
+ },
697
+ {
698
+ maxPictureSize: 8912896,
699
+ maxBitrate: 1e8,
700
+ tier: "H",
701
+ level: 150
702
+ },
703
+ {
704
+ maxPictureSize: 8912896,
705
+ maxBitrate: 4e7,
706
+ tier: "L",
707
+ level: 153
708
+ },
709
+ {
710
+ maxPictureSize: 8912896,
711
+ maxBitrate: 16e7,
712
+ tier: "H",
713
+ level: 153
714
+ },
715
+ {
716
+ maxPictureSize: 8912896,
717
+ maxBitrate: 6e7,
718
+ tier: "L",
719
+ level: 156
720
+ },
721
+ {
722
+ maxPictureSize: 8912896,
723
+ maxBitrate: 24e7,
724
+ tier: "H",
725
+ level: 156
726
+ },
727
+ {
728
+ maxPictureSize: 35651584,
729
+ maxBitrate: 6e7,
730
+ tier: "L",
731
+ level: 180
732
+ },
733
+ {
734
+ maxPictureSize: 35651584,
735
+ maxBitrate: 24e7,
736
+ tier: "H",
737
+ level: 180
738
+ },
739
+ {
740
+ maxPictureSize: 35651584,
741
+ maxBitrate: 12e7,
742
+ tier: "L",
743
+ level: 183
744
+ },
745
+ {
746
+ maxPictureSize: 35651584,
747
+ maxBitrate: 48e7,
748
+ tier: "H",
749
+ level: 183
750
+ },
751
+ {
752
+ maxPictureSize: 35651584,
753
+ maxBitrate: 24e7,
754
+ tier: "L",
755
+ level: 186
756
+ },
757
+ {
758
+ maxPictureSize: 35651584,
759
+ maxBitrate: 8e8,
760
+ tier: "H",
761
+ level: 186
762
+ }
763
+ ], We = [
764
+ {
765
+ maxPictureSize: 36864,
766
+ maxBitrate: 2e5,
767
+ level: 10
768
+ },
769
+ {
770
+ maxPictureSize: 73728,
771
+ maxBitrate: 8e5,
772
+ level: 11
773
+ },
774
+ {
775
+ maxPictureSize: 122880,
776
+ maxBitrate: 18e5,
777
+ level: 20
778
+ },
779
+ {
780
+ maxPictureSize: 245760,
781
+ maxBitrate: 36e5,
782
+ level: 21
783
+ },
784
+ {
785
+ maxPictureSize: 552960,
786
+ maxBitrate: 72e5,
787
+ level: 30
788
+ },
789
+ {
790
+ maxPictureSize: 983040,
791
+ maxBitrate: 12e6,
792
+ level: 31
793
+ },
794
+ {
795
+ maxPictureSize: 2228224,
796
+ maxBitrate: 18e6,
797
+ level: 40
798
+ },
799
+ {
800
+ maxPictureSize: 2228224,
801
+ maxBitrate: 3e7,
802
+ level: 41
803
+ },
804
+ {
805
+ maxPictureSize: 8912896,
806
+ maxBitrate: 6e7,
807
+ level: 50
808
+ },
809
+ {
810
+ maxPictureSize: 8912896,
811
+ maxBitrate: 12e7,
812
+ level: 51
813
+ },
814
+ {
815
+ maxPictureSize: 8912896,
816
+ maxBitrate: 18e7,
817
+ level: 52
818
+ },
819
+ {
820
+ maxPictureSize: 35651584,
821
+ maxBitrate: 18e7,
822
+ level: 60
823
+ },
824
+ {
825
+ maxPictureSize: 35651584,
826
+ maxBitrate: 24e7,
827
+ level: 61
828
+ },
829
+ {
830
+ maxPictureSize: 35651584,
831
+ maxBitrate: 48e7,
832
+ level: 62
833
+ }
834
+ ], Ge = [
835
+ {
836
+ maxPictureSize: 147456,
837
+ maxBitrate: 15e5,
838
+ tier: "M",
839
+ level: 0
840
+ },
841
+ {
842
+ maxPictureSize: 278784,
843
+ maxBitrate: 3e6,
844
+ tier: "M",
845
+ level: 1
846
+ },
847
+ {
848
+ maxPictureSize: 665856,
849
+ maxBitrate: 6e6,
850
+ tier: "M",
851
+ level: 4
852
+ },
853
+ {
854
+ maxPictureSize: 1065024,
855
+ maxBitrate: 1e7,
856
+ tier: "M",
857
+ level: 5
858
+ },
859
+ {
860
+ maxPictureSize: 2359296,
861
+ maxBitrate: 12e6,
862
+ tier: "M",
863
+ level: 8
864
+ },
865
+ {
866
+ maxPictureSize: 2359296,
867
+ maxBitrate: 3e7,
868
+ tier: "H",
869
+ level: 8
870
+ },
871
+ {
872
+ maxPictureSize: 2359296,
873
+ maxBitrate: 2e7,
874
+ tier: "M",
875
+ level: 9
876
+ },
877
+ {
878
+ maxPictureSize: 2359296,
879
+ maxBitrate: 5e7,
880
+ tier: "H",
881
+ level: 9
882
+ },
883
+ {
884
+ maxPictureSize: 8912896,
885
+ maxBitrate: 3e7,
886
+ tier: "M",
887
+ level: 12
888
+ },
889
+ {
890
+ maxPictureSize: 8912896,
891
+ maxBitrate: 1e8,
892
+ tier: "H",
893
+ level: 12
894
+ },
895
+ {
896
+ maxPictureSize: 8912896,
897
+ maxBitrate: 4e7,
898
+ tier: "M",
899
+ level: 13
900
+ },
901
+ {
902
+ maxPictureSize: 8912896,
903
+ maxBitrate: 16e7,
904
+ tier: "H",
905
+ level: 13
906
+ },
907
+ {
908
+ maxPictureSize: 8912896,
909
+ maxBitrate: 6e7,
910
+ tier: "M",
911
+ level: 14
912
+ },
913
+ {
914
+ maxPictureSize: 8912896,
915
+ maxBitrate: 24e7,
916
+ tier: "H",
917
+ level: 14
918
+ },
919
+ {
920
+ maxPictureSize: 35651584,
921
+ maxBitrate: 6e7,
922
+ tier: "M",
923
+ level: 15
924
+ },
925
+ {
926
+ maxPictureSize: 35651584,
927
+ maxBitrate: 24e7,
928
+ tier: "H",
929
+ level: 15
930
+ },
931
+ {
932
+ maxPictureSize: 35651584,
933
+ maxBitrate: 6e7,
934
+ tier: "M",
935
+ level: 16
936
+ },
937
+ {
938
+ maxPictureSize: 35651584,
939
+ maxBitrate: 24e7,
940
+ tier: "H",
941
+ level: 16
942
+ },
943
+ {
944
+ maxPictureSize: 35651584,
945
+ maxBitrate: 1e8,
946
+ tier: "M",
947
+ level: 17
948
+ },
949
+ {
950
+ maxPictureSize: 35651584,
951
+ maxBitrate: 48e7,
952
+ tier: "H",
953
+ level: 17
954
+ },
955
+ {
956
+ maxPictureSize: 35651584,
957
+ maxBitrate: 16e7,
958
+ tier: "M",
959
+ level: 18
960
+ },
961
+ {
962
+ maxPictureSize: 35651584,
963
+ maxBitrate: 8e8,
964
+ tier: "H",
965
+ level: 18
966
+ },
967
+ {
968
+ maxPictureSize: 35651584,
969
+ maxBitrate: 16e7,
970
+ tier: "M",
971
+ level: 19
972
+ },
973
+ {
974
+ maxPictureSize: 35651584,
975
+ maxBitrate: 8e8,
976
+ tier: "H",
977
+ level: 19
978
+ }
979
+ ], L = [
980
+ "ap4x",
981
+ "ap4h",
982
+ "apch",
983
+ "apcn",
984
+ "apcs",
985
+ "apco"
986
+ ], R = [
987
+ "dtsc",
988
+ "dtsh",
989
+ "dtsl",
990
+ "dtse"
991
+ ], Ke = [
992
+ {
993
+ fourCc: "apco",
994
+ bitrate: 45e6,
995
+ alpha: !1
996
+ },
997
+ {
998
+ fourCc: "apcs",
999
+ bitrate: 102e6,
1000
+ alpha: !1
1001
+ },
1002
+ {
1003
+ fourCc: "apcn",
1004
+ bitrate: 147e6,
1005
+ alpha: !1
1006
+ },
1007
+ {
1008
+ fourCc: "apch",
1009
+ bitrate: 22e7,
1010
+ alpha: !1
1011
+ },
1012
+ {
1013
+ fourCc: "ap4h",
1014
+ bitrate: 33e7,
1015
+ alpha: !0
1016
+ },
1017
+ {
1018
+ fourCc: "ap4x",
1019
+ bitrate: 5e8,
1020
+ alpha: !0
1021
+ }
1022
+ ], qe = (e, t, n, i, a) => {
1023
+ if (e === "avc") {
1024
+ let e = Math.ceil(t / 16) * Math.ceil(n / 16), a = He.find((t) => e <= t.maxMacroblocks && i <= t.maxBitrate) ?? r(He), o = a ? a.level : 0;
1025
+ return `avc1.${"64".padStart(2, "0")}00${o.toString(16).padStart(2, "0")}`;
1026
+ } else if (e === "hevc") {
1027
+ let e = t * n, a = Ue.find((t) => e <= t.maxPictureSize && i <= t.maxBitrate) ?? r(Ue);
1028
+ return `hev1.1.6.${a.tier}${a.level}.B0`;
1029
+ } else if (e === "vp8") return "vp8";
1030
+ else if (e === "vp9") {
1031
+ let e = t * n;
1032
+ return `vp09.00.${(We.find((t) => e <= t.maxPictureSize && i <= t.maxBitrate) ?? r(We)).level.toString().padStart(2, "0")}.08`;
1033
+ } else if (e === "av1") {
1034
+ let e = t * n, a = Ge.find((t) => e <= t.maxPictureSize && i <= t.maxBitrate) ?? r(Ge);
1035
+ return `av01.0.${a.level.toString().padStart(2, "0")}${a.tier}.08`;
1036
+ } else if (e === "prores") {
1037
+ let e = (t * n / (1920 * 1080)) ** .95, r = Ke.filter((e) => e.alpha === a), o = r[0].fourCc, s = Infinity;
1038
+ for (let { fourCc: t, bitrate: n } of r) {
1039
+ let r = Math.abs(n * e - i);
1040
+ r < s && (s = r, o = t);
1041
+ }
1042
+ return o;
1043
+ } else _(e);
1044
+ throw TypeError(`Unhandled codec '${String(e)}'.`);
1045
+ }, Je = (e) => {
1046
+ let t = e.split(".");
1047
+ return [
1048
+ 1,
1049
+ 1,
1050
+ Number(t[1]),
1051
+ 2,
1052
+ 1,
1053
+ Number(t[2]),
1054
+ 3,
1055
+ 1,
1056
+ Number(t[3]),
1057
+ 4,
1058
+ 1,
1059
+ t[4] ? Number(t[4]) : 1
1060
+ ];
1061
+ }, Ye = (e) => {
1062
+ let t = e.split("."), n = Number(t[1]), r = t[2], i = Number(r.slice(0, -1)), a = (n << 5) + i, o = +(r.slice(-1) === "H"), s = Number(t[3]), c = s === 8 ? 0 : 1, l = +(s === 12), u = t[4] ? Number(t[4]) : 0, d = t[5] ? Number(t[5][0]) : 1, f = t[5] ? Number(t[5][1]) : 1, p = t[5] ? Number(t[5][2]) : 0;
1063
+ return [
1064
+ 129,
1065
+ a,
1066
+ (o << 7) + (c << 6) + (l << 5) + (u << 4) + (d << 3) + (f << 2) + p,
1067
+ 0
1068
+ ];
1069
+ }, Xe = 48e3, Ze = /^pcm-([usf])(\d+)(be)?$/, Qe = (e) => {
1070
+ if (t(P.includes(e)), e === "ulaw") return {
1071
+ dataType: "ulaw",
1072
+ sampleSize: 1,
1073
+ littleEndian: !0,
1074
+ silentValue: 255
1075
+ };
1076
+ if (e === "alaw") return {
1077
+ dataType: "alaw",
1078
+ sampleSize: 1,
1079
+ littleEndian: !0,
1080
+ silentValue: 213
1081
+ };
1082
+ let n = Ze.exec(e);
1083
+ t(n);
1084
+ let r;
1085
+ r = n[1] === "u" ? "unsigned" : n[1] === "s" ? "signed" : "float";
1086
+ let i = Number(n[2]) / 8, a = n[3] !== "be";
1087
+ return {
1088
+ dataType: r,
1089
+ sampleSize: i,
1090
+ littleEndian: a,
1091
+ silentValue: e === "pcm-u8" ? 2 ** 7 : 0
1092
+ };
1093
+ }, z = (e) => e.startsWith("avc1") || e.startsWith("avc3") ? "avc" : e.startsWith("hev1") || e.startsWith("hvc1") ? "hevc" : e === "vp8" ? "vp8" : e.startsWith("vp09") ? "vp9" : e.startsWith("av01") ? "av1" : L.includes(e) ? "prores" : e === "mp3" || e === "mp4a.69" || e === "mp4a.6B" || e === "mp4a.6b" || e === "mp4a.40.34" ? "mp3" : e.startsWith("mp4a.40.") || e === "mp4a.67" ? "aac" : e === "opus" ? "opus" : e === "vorbis" ? "vorbis" : e === "flac" ? "flac" : e === "ac-3" || e === "ac3" ? "ac3" : e === "ec-3" || e === "eac3" ? "eac3" : R.includes(e) ? "dts" : e === "ulaw" ? "ulaw" : e === "alaw" ? "alaw" : Ze.test(e) ? e : e === "webvtt" ? "webvtt" : null, $e = (e) => e === "avc" ? { avc: { format: "avc" } } : e === "hevc" ? { hevc: { format: "hevc" } } : {}, et = [
1094
+ "avc1",
1095
+ "avc3",
1096
+ "hev1",
1097
+ "hvc1",
1098
+ "vp8",
1099
+ "vp09",
1100
+ "av01",
1101
+ ...L
1102
+ ], tt = /^(avc1|avc3)\.[0-9a-fA-F]{6}$/, nt = /^(hev1|hvc1)\.(?:[ABC]?\d+)\.[0-9a-fA-F]{1,8}\.[LH]\d+(?:\.[0-9a-fA-F]{1,2}){0,6}$/, rt = /^vp09(?:\.\d{2}){3}(?:(?:\.\d{2}){5})?$/, it = /^av01\.\d\.\d{2}[MH]\.\d{2}(?:\.\d\.\d{3}\.\d{2}\.\d{2}\.\d{2}\.\d)?$/, at = (e, t) => {
1103
+ if (!e) throw TypeError("Video chunk metadata must be provided.");
1104
+ if (typeof e != "object") throw TypeError("Video chunk metadata must be an object.");
1105
+ if (!e.decoderConfig) throw TypeError("Video chunk metadata must include a decoder configuration.");
1106
+ if (typeof e.decoderConfig != "object") throw TypeError("Video chunk metadata decoder configuration must be an object.");
1107
+ if (typeof e.decoderConfig.codec != "string") throw TypeError("Video chunk metadata decoder configuration must specify a codec string.");
1108
+ if (!et.some((t) => e.decoderConfig.codec.startsWith(t))) throw TypeError("Video chunk metadata decoder configuration codec string must be a valid video codec string as specified in the Mediabunny Codec Registry.");
1109
+ if (!Number.isInteger(e.decoderConfig.codedWidth) || e.decoderConfig.codedWidth <= 0) throw TypeError("Video chunk metadata decoder configuration must specify a valid codedWidth (positive integer).");
1110
+ if (!Number.isInteger(e.decoderConfig.codedHeight) || e.decoderConfig.codedHeight <= 0) throw TypeError("Video chunk metadata decoder configuration must specify a valid codedHeight (positive integer).");
1111
+ if (e.decoderConfig.displayAspectWidth !== void 0 && (!Number.isInteger(e.decoderConfig.displayAspectWidth) || e.decoderConfig.displayAspectWidth <= 0)) throw TypeError("Video chunk metadata decoder configuration displayAspectWidth, when defined, must be a positive integer.");
1112
+ if (e.decoderConfig.displayAspectHeight !== void 0 && (!Number.isInteger(e.decoderConfig.displayAspectHeight) || e.decoderConfig.displayAspectHeight <= 0)) throw TypeError("Video chunk metadata decoder configuration displayAspectHeight, when defined, must be a positive integer.");
1113
+ if (e.decoderConfig.displayAspectWidth !== void 0 != (e.decoderConfig.displayAspectHeight !== void 0)) throw TypeError("Video chunk metadata decoder configuration must specify both displayAspectWidth and displayAspectHeight, or neither.");
1114
+ if (e.decoderConfig.description !== void 0 && !p(e.decoderConfig.description)) throw TypeError("Video chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.");
1115
+ if (e.decoderConfig.colorSpace !== void 0) {
1116
+ let { colorSpace: t } = e.decoderConfig;
1117
+ if (typeof t != "object") throw TypeError("Video chunk metadata decoder configuration colorSpace, when provided, must be an object.");
1118
+ let n = Object.keys(l);
1119
+ if (t.primaries != null && !n.includes(t.primaries)) throw TypeError(`Video chunk metadata decoder configuration colorSpace primaries, when defined, must be one of ${n.join(", ")}.`);
1120
+ let r = Object.keys(u);
1121
+ if (t.transfer != null && !r.includes(t.transfer)) throw TypeError(`Video chunk metadata decoder configuration colorSpace transfer, when defined, must be one of ${r.join(", ")}.`);
1122
+ let i = Object.keys(d);
1123
+ if (t.matrix != null && !i.includes(t.matrix)) throw TypeError(`Video chunk metadata decoder configuration colorSpace matrix, when defined, must be one of ${i.join(", ")}.`);
1124
+ if (t.fullRange != null && typeof t.fullRange != "boolean") throw TypeError("Video chunk metadata decoder configuration colorSpace fullRange, when defined, must be a boolean.");
1125
+ }
1126
+ if (e.decoderConfig.codec.startsWith("avc1") || e.decoderConfig.codec.startsWith("avc3")) {
1127
+ if (!tt.test(e.decoderConfig.codec)) throw TypeError("Video chunk metadata decoder configuration codec string for AVC must be a valid AVC codec string as specified in Section 3.4 of RFC 6381.");
1128
+ } else if (e.decoderConfig.codec.startsWith("hev1") || e.decoderConfig.codec.startsWith("hvc1")) {
1129
+ if (!nt.test(e.decoderConfig.codec)) throw TypeError("Video chunk metadata decoder configuration codec string for HEVC must be a valid HEVC codec string as specified in Section E.3 of ISO 14496-15.");
1130
+ } else if (e.decoderConfig.codec.startsWith("vp8")) {
1131
+ if (e.decoderConfig.codec !== "vp8") throw TypeError("Video chunk metadata decoder configuration codec string for VP8 must be \"vp8\".");
1132
+ } else if (e.decoderConfig.codec.startsWith("vp09")) {
1133
+ if (!rt.test(e.decoderConfig.codec)) throw TypeError("Video chunk metadata decoder configuration codec string for VP9 must be a valid VP9 codec string as specified in Section \"Codecs Parameter String\" of https://www.webmproject.org/vp9/mp4/.");
1134
+ } else if (e.decoderConfig.codec.startsWith("av01")) {
1135
+ if (!it.test(e.decoderConfig.codec)) throw TypeError("Video chunk metadata decoder configuration codec string for AV1 must be a valid AV1 codec string as specified in Section \"Codecs Parameter String\" of https://aomediacodec.github.io/av1-isobmff/.");
1136
+ } else if (L.some((t) => e.decoderConfig.codec.startsWith(t)) && !L.some((t) => e.decoderConfig.codec === t)) throw TypeError(`Video chunk metadata decoder configuration codec string for ProRes must be one of the valid ProRes four-character codes: ${L.join(", ")}.`);
1137
+ if (t !== null && z(e.decoderConfig.codec) !== t) throw TypeError(`Video chunk metadata decoder configuration codec string '${e.decoderConfig.codec}' does not fit to the track codec '${t}'.`);
1138
+ }, ot = [
1139
+ "mp4a",
1140
+ "mp3",
1141
+ "opus",
1142
+ "vorbis",
1143
+ "flac",
1144
+ "ulaw",
1145
+ "alaw",
1146
+ "pcm",
1147
+ "ac-3",
1148
+ "ec-3",
1149
+ "dts"
1150
+ ], st = (e, t) => {
1151
+ if (!e) throw TypeError("Audio chunk metadata must be provided.");
1152
+ if (typeof e != "object") throw TypeError("Audio chunk metadata must be an object.");
1153
+ if (!e.decoderConfig) throw TypeError("Audio chunk metadata must include a decoder configuration.");
1154
+ if (typeof e.decoderConfig != "object") throw TypeError("Audio chunk metadata decoder configuration must be an object.");
1155
+ if (typeof e.decoderConfig.codec != "string") throw TypeError("Audio chunk metadata decoder configuration must specify a codec string.");
1156
+ if (!ot.some((t) => e.decoderConfig.codec.startsWith(t))) throw TypeError("Audio chunk metadata decoder configuration codec string must be a valid audio codec string as specified in the Mediabunny Codec Registry.");
1157
+ if (!Number.isInteger(e.decoderConfig.sampleRate) || e.decoderConfig.sampleRate <= 0) throw TypeError("Audio chunk metadata decoder configuration must specify a valid sampleRate (positive integer).");
1158
+ if (!Number.isInteger(e.decoderConfig.numberOfChannels) || e.decoderConfig.numberOfChannels <= 0) throw TypeError("Audio chunk metadata decoder configuration must specify a valid numberOfChannels (positive integer).");
1159
+ if (e.decoderConfig.description !== void 0 && !p(e.decoderConfig.description)) throw TypeError("Audio chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.");
1160
+ if (e.decoderConfig.codec.startsWith("mp4a") && e.decoderConfig.codec !== "mp4a.69" && e.decoderConfig.codec !== "mp4a.6B" && e.decoderConfig.codec !== "mp4a.6b") {
1161
+ if (![
1162
+ "mp4a.40.2",
1163
+ "mp4a.40.02",
1164
+ "mp4a.40.5",
1165
+ "mp4a.40.05",
1166
+ "mp4a.40.29",
1167
+ "mp4a.67"
1168
+ ].includes(e.decoderConfig.codec)) throw TypeError("Audio chunk metadata decoder configuration codec string for AAC must be a valid AAC codec string as specified in https://www.w3.org/TR/webcodecs-aac-codec-registration/.");
1169
+ } else if (e.decoderConfig.codec.startsWith("mp3") || e.decoderConfig.codec.startsWith("mp4a")) {
1170
+ if (e.decoderConfig.codec !== "mp3" && e.decoderConfig.codec !== "mp4a.69" && e.decoderConfig.codec !== "mp4a.6B" && e.decoderConfig.codec !== "mp4a.6b") throw TypeError("Audio chunk metadata decoder configuration codec string for MP3 must be \"mp3\", \"mp4a.69\" or \"mp4a.6B\".");
1171
+ } else if (e.decoderConfig.codec.startsWith("opus")) {
1172
+ if (e.decoderConfig.codec !== "opus") throw TypeError("Audio chunk metadata decoder configuration codec string for Opus must be \"opus\".");
1173
+ if (e.decoderConfig.description && e.decoderConfig.description.byteLength < 18) throw TypeError("Audio chunk metadata decoder configuration description, when specified, is expected to be an Identification Header as specified in Section 5.1 of RFC 7845.");
1174
+ } else if (e.decoderConfig.codec.startsWith("vorbis")) {
1175
+ if (e.decoderConfig.codec !== "vorbis") throw TypeError("Audio chunk metadata decoder configuration codec string for Vorbis must be \"vorbis\".");
1176
+ if (!e.decoderConfig.description) throw TypeError("Audio chunk metadata decoder configuration for Vorbis must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-vorbis-codec-registration/.");
1177
+ } else if (e.decoderConfig.codec.startsWith("flac")) {
1178
+ if (e.decoderConfig.codec !== "flac") throw TypeError("Audio chunk metadata decoder configuration codec string for FLAC must be \"flac\".");
1179
+ if (!e.decoderConfig.description || e.decoderConfig.description.byteLength < 42) throw TypeError("Audio chunk metadata decoder configuration for FLAC must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-flac-codec-registration/.");
1180
+ } else if (e.decoderConfig.codec.startsWith("ac-3") || e.decoderConfig.codec.startsWith("ac3")) {
1181
+ if (e.decoderConfig.codec !== "ac-3") throw TypeError("Audio chunk metadata decoder configuration codec string for AC-3 must be \"ac-3\".");
1182
+ } else if (e.decoderConfig.codec.startsWith("ec-3") || e.decoderConfig.codec.startsWith("eac3")) {
1183
+ if (e.decoderConfig.codec !== "ec-3") throw TypeError("Audio chunk metadata decoder configuration codec string for EC-3 must be \"ec-3\".");
1184
+ } else if (e.decoderConfig.codec.startsWith("dts")) {
1185
+ if (!R.includes(e.decoderConfig.codec)) throw TypeError(`Audio chunk metadata decoder configuration codec string for DTS must be one of the following four-character codes: ${R.join(", ")}.`);
1186
+ } else if ((e.decoderConfig.codec.startsWith("pcm") || e.decoderConfig.codec.startsWith("ulaw") || e.decoderConfig.codec.startsWith("alaw")) && !P.includes(e.decoderConfig.codec)) throw TypeError(`Audio chunk metadata decoder configuration codec string for PCM must be one of the supported PCM codecs (${P.join(", ")}).`);
1187
+ if (t !== null && z(e.decoderConfig.codec) !== t) throw TypeError(`Audio chunk metadata decoder configuration codec string '${e.decoderConfig.codec}' does not fit to the track codec '${t}'.`);
1188
+ }, ct = (e) => {
1189
+ if (!e) throw TypeError("Subtitle metadata must be provided.");
1190
+ if (typeof e != "object") throw TypeError("Subtitle metadata must be an object.");
1191
+ if (!e.config) throw TypeError("Subtitle metadata must include a config object.");
1192
+ if (typeof e.config != "object") throw TypeError("Subtitle metadata config must be an object.");
1193
+ if (typeof e.config.description != "string") throw TypeError("Subtitle metadata config description must be a string.");
1194
+ }, lt = /* #__PURE__ */ new Uint8Array(), B = class e {
1195
+ constructor(e, t, n, r, i = -1, a, o) {
1196
+ if (this.data = e, this.type = t, this.timestamp = n, this.duration = r, this.sequenceNumber = i, e === lt && a === void 0) throw Error("Internal error: byteLength must be explicitly provided when constructing metadata-only packets.");
1197
+ if (a === void 0 && (a = e.byteLength), !(e instanceof Uint8Array)) throw TypeError("data must be a Uint8Array.");
1198
+ if (t !== "key" && t !== "delta") throw TypeError("type must be either \"key\" or \"delta\".");
1199
+ if (!Number.isFinite(n)) throw TypeError("timestamp must be a number.");
1200
+ if (!Number.isFinite(r) || r < 0) throw TypeError("duration must be a non-negative number.");
1201
+ if (!Number.isFinite(i)) throw TypeError("sequenceNumber must be a number.");
1202
+ if (!Number.isInteger(a) || a < 0) throw TypeError("byteLength must be a non-negative integer.");
1203
+ if (o !== void 0 && (typeof o != "object" || !o)) throw TypeError("sideData, when provided, must be an object.");
1204
+ if (o?.alpha !== void 0 && !(o.alpha instanceof Uint8Array)) throw TypeError("sideData.alpha, when provided, must be a Uint8Array.");
1205
+ if (o?.alphaByteLength !== void 0 && (!Number.isInteger(o.alphaByteLength) || o.alphaByteLength < 0)) throw TypeError("sideData.alphaByteLength, when provided, must be a non-negative integer.");
1206
+ this.byteLength = a, this.sideData = o ?? {}, this.sideData.alpha && this.sideData.alphaByteLength === void 0 && (this.sideData.alphaByteLength = this.sideData.alpha.byteLength);
1207
+ }
1208
+ get isMetadataOnly() {
1209
+ return this.data === lt;
1210
+ }
1211
+ get microsecondTimestamp() {
1212
+ return Math.trunc(w * this.timestamp);
1213
+ }
1214
+ get microsecondDuration() {
1215
+ return Math.trunc(w * this.duration);
1216
+ }
1217
+ toEncodedVideoChunk() {
1218
+ if (this.isMetadataOnly) throw TypeError("Metadata-only packets cannot be converted to a video chunk.");
1219
+ if (typeof EncodedVideoChunk > "u") throw Error("EncodedVideoChunk is not available in this environment.");
1220
+ return new EncodedVideoChunk({
1221
+ data: this.data,
1222
+ type: this.type,
1223
+ timestamp: this.microsecondTimestamp,
1224
+ duration: this.microsecondDuration
1225
+ });
1226
+ }
1227
+ alphaToEncodedVideoChunk(e = this.type) {
1228
+ if (!this.sideData.alpha) throw TypeError("This packet does not contain alpha side data.");
1229
+ if (this.isMetadataOnly) throw TypeError("Metadata-only packets cannot be converted to a video chunk.");
1230
+ if (typeof EncodedVideoChunk > "u") throw Error("EncodedVideoChunk is not available in this environment.");
1231
+ return new EncodedVideoChunk({
1232
+ data: this.sideData.alpha,
1233
+ type: e,
1234
+ timestamp: this.microsecondTimestamp,
1235
+ duration: this.microsecondDuration
1236
+ });
1237
+ }
1238
+ toEncodedAudioChunk() {
1239
+ if (this.isMetadataOnly) throw TypeError("Metadata-only packets cannot be converted to an audio chunk.");
1240
+ if (typeof EncodedAudioChunk > "u") throw Error("EncodedAudioChunk is not available in this environment.");
1241
+ return new EncodedAudioChunk({
1242
+ data: this.data,
1243
+ type: this.type,
1244
+ timestamp: this.microsecondTimestamp,
1245
+ duration: this.microsecondDuration
1246
+ });
1247
+ }
1248
+ static fromEncodedChunk(t, n) {
1249
+ if (!(t instanceof EncodedVideoChunk || t instanceof EncodedAudioChunk)) throw TypeError("chunk must be an EncodedVideoChunk or EncodedAudioChunk.");
1250
+ let r = new Uint8Array(t.byteLength);
1251
+ return t.copyTo(r), new e(r, t.type, t.timestamp / 1e6, (t.duration ?? 0) / 1e6, void 0, void 0, n);
1252
+ }
1253
+ clone(t) {
1254
+ if (t !== void 0 && (typeof t != "object" || !t)) throw TypeError("options, when provided, must be an object.");
1255
+ if (t?.data !== void 0 && !(t.data instanceof Uint8Array)) throw TypeError("options.data, when provided, must be a Uint8Array.");
1256
+ if (t?.type !== void 0 && t.type !== "key" && t.type !== "delta") throw TypeError("options.type, when provided, must be either \"key\" or \"delta\".");
1257
+ if (t?.timestamp !== void 0 && !Number.isFinite(t.timestamp)) throw TypeError("options.timestamp, when provided, must be a number.");
1258
+ if (t?.duration !== void 0 && !Number.isFinite(t.duration)) throw TypeError("options.duration, when provided, must be a number.");
1259
+ if (t?.sequenceNumber !== void 0 && !Number.isFinite(t.sequenceNumber)) throw TypeError("options.sequenceNumber, when provided, must be a number.");
1260
+ if (t?.sideData !== void 0 && (typeof t.sideData != "object" || t.sideData === null)) throw TypeError("options.sideData, when provided, must be an object.");
1261
+ return new e(t?.data ?? this.data, t?.type ?? this.type, t?.timestamp ?? this.timestamp, t?.duration ?? this.duration, t?.sequenceNumber ?? this.sequenceNumber, this.byteLength, t?.sideData ?? this.sideData);
1262
+ }
1263
+ }, V = class {
1264
+ constructor(e) {
1265
+ this.value = e;
1266
+ }
1267
+ }, H = class {
1268
+ constructor(e) {
1269
+ this.value = e;
1270
+ }
1271
+ }, ut = class {
1272
+ constructor(e) {
1273
+ this.value = e;
1274
+ }
1275
+ }, U = class {
1276
+ constructor(e) {
1277
+ this.value = e;
1278
+ }
1279
+ }, W;
1280
+ (function(e) {
1281
+ e[e.EBML = 440786851] = "EBML", e[e.EBMLVersion = 17030] = "EBMLVersion", e[e.EBMLReadVersion = 17143] = "EBMLReadVersion", e[e.EBMLMaxIDLength = 17138] = "EBMLMaxIDLength", e[e.EBMLMaxSizeLength = 17139] = "EBMLMaxSizeLength", e[e.DocType = 17026] = "DocType", e[e.DocTypeVersion = 17031] = "DocTypeVersion", e[e.DocTypeReadVersion = 17029] = "DocTypeReadVersion", e[e.Void = 236] = "Void", e[e.Segment = 408125543] = "Segment", e[e.SeekHead = 290298740] = "SeekHead", e[e.Seek = 19899] = "Seek", e[e.SeekID = 21419] = "SeekID", e[e.SeekPosition = 21420] = "SeekPosition", e[e.Duration = 17545] = "Duration", e[e.Info = 357149030] = "Info", e[e.TimestampScale = 2807729] = "TimestampScale", e[e.MuxingApp = 19840] = "MuxingApp", e[e.WritingApp = 22337] = "WritingApp", e[e.Tracks = 374648427] = "Tracks", e[e.TrackEntry = 174] = "TrackEntry", e[e.TrackNumber = 215] = "TrackNumber", e[e.TrackUID = 29637] = "TrackUID", e[e.TrackType = 131] = "TrackType", e[e.FlagEnabled = 185] = "FlagEnabled", e[e.FlagDefault = 136] = "FlagDefault", e[e.FlagForced = 21930] = "FlagForced", e[e.FlagOriginal = 21934] = "FlagOriginal", e[e.FlagHearingImpaired = 21931] = "FlagHearingImpaired", e[e.FlagVisualImpaired = 21932] = "FlagVisualImpaired", e[e.FlagCommentary = 21935] = "FlagCommentary", e[e.FlagLacing = 156] = "FlagLacing", e[e.Name = 21358] = "Name", e[e.Language = 2274716] = "Language", e[e.LanguageBCP47 = 2274717] = "LanguageBCP47", e[e.CodecID = 134] = "CodecID", e[e.CodecPrivate = 25506] = "CodecPrivate", e[e.CodecDelay = 22186] = "CodecDelay", e[e.SeekPreRoll = 22203] = "SeekPreRoll", e[e.DefaultDuration = 2352003] = "DefaultDuration", e[e.Video = 224] = "Video", e[e.PixelWidth = 176] = "PixelWidth", e[e.PixelHeight = 186] = "PixelHeight", e[e.DisplayWidth = 21680] = "DisplayWidth", e[e.DisplayHeight = 21690] = "DisplayHeight", e[e.DisplayUnit = 21682] = "DisplayUnit", e[e.AlphaMode = 21440] = "AlphaMode", e[e.Audio = 225] = "Audio", e[e.SamplingFrequency = 181] = "SamplingFrequency", e[e.Channels = 159] = "Channels", e[e.BitDepth = 25188] = "BitDepth", e[e.SimpleBlock = 163] = "SimpleBlock", e[e.BlockGroup = 160] = "BlockGroup", e[e.Block = 161] = "Block", e[e.BlockAdditions = 30113] = "BlockAdditions", e[e.BlockMore = 166] = "BlockMore", e[e.BlockAdditional = 165] = "BlockAdditional", e[e.BlockAddID = 238] = "BlockAddID", e[e.BlockDuration = 155] = "BlockDuration", e[e.ReferenceBlock = 251] = "ReferenceBlock", e[e.Cluster = 524531317] = "Cluster", e[e.Timestamp = 231] = "Timestamp", e[e.Cues = 475249515] = "Cues", e[e.CuePoint = 187] = "CuePoint", e[e.CueTime = 179] = "CueTime", e[e.CueTrackPositions = 183] = "CueTrackPositions", e[e.CueTrack = 247] = "CueTrack", e[e.CueClusterPosition = 241] = "CueClusterPosition", e[e.Colour = 21936] = "Colour", e[e.MatrixCoefficients = 21937] = "MatrixCoefficients", e[e.TransferCharacteristics = 21946] = "TransferCharacteristics", e[e.Primaries = 21947] = "Primaries", e[e.Range = 21945] = "Range", e[e.Projection = 30320] = "Projection", e[e.ProjectionType = 30321] = "ProjectionType", e[e.ProjectionPoseRoll = 30325] = "ProjectionPoseRoll", e[e.Attachments = 423732329] = "Attachments", e[e.AttachedFile = 24999] = "AttachedFile", e[e.FileDescription = 18046] = "FileDescription", e[e.FileName = 18030] = "FileName", e[e.FileMediaType = 18016] = "FileMediaType", e[e.FileData = 18012] = "FileData", e[e.FileUID = 18094] = "FileUID", e[e.Chapters = 272869232] = "Chapters", e[e.Tags = 307544935] = "Tags", e[e.Tag = 29555] = "Tag", e[e.Targets = 25536] = "Targets", e[e.TargetTypeValue = 26826] = "TargetTypeValue", e[e.TargetType = 25546] = "TargetType", e[e.TagTrackUID = 25541] = "TagTrackUID", e[e.TagEditionUID = 25545] = "TagEditionUID", e[e.TagChapterUID = 25540] = "TagChapterUID", e[e.TagAttachmentUID = 25542] = "TagAttachmentUID", e[e.SimpleTag = 26568] = "SimpleTag", e[e.TagName = 17827] = "TagName", e[e.TagLanguage = 17530] = "TagLanguage", e[e.TagString = 17543] = "TagString", e[e.TagBinary = 17541] = "TagBinary", e[e.ContentEncodings = 28032] = "ContentEncodings", e[e.ContentEncoding = 25152] = "ContentEncoding", e[e.ContentEncodingOrder = 20529] = "ContentEncodingOrder", e[e.ContentEncodingScope = 20530] = "ContentEncodingScope", e[e.ContentCompression = 20532] = "ContentCompression", e[e.ContentCompAlgo = 16980] = "ContentCompAlgo", e[e.ContentCompSettings = 16981] = "ContentCompSettings", e[e.ContentEncryption = 20533] = "ContentEncryption";
1282
+ })(W ||= {});
1283
+ var dt = [W.EBML, W.Segment], ft = [
1284
+ W.SeekHead,
1285
+ W.Info,
1286
+ W.Cluster,
1287
+ W.Tracks,
1288
+ W.Cues,
1289
+ W.Attachments,
1290
+ W.Chapters,
1291
+ W.Tags
1292
+ ];
1293
+ [...dt, ...ft];
1294
+ var pt = (e) => e < 256 ? 1 : e < 65536 ? 2 : e < 1 << 24 ? 3 : e < 2 ** 32 ? 4 : e < 2 ** 40 ? 5 : 6, mt = (e) => e < 1n << 8n ? 1 : e < 1n << 16n ? 2 : e < 1n << 24n ? 3 : e < 1n << 32n ? 4 : e < 1n << 40n ? 5 : e < 1n << 48n ? 6 : e < 1n << 56n ? 7 : 8, ht = (e) => e >= -64 && e < 64 ? 1 : e >= -8192 && e < 8192 ? 2 : e >= -1048576 && e < 1 << 20 ? 3 : e >= -134217728 && e < 1 << 27 ? 4 : e >= -(2 ** 34) && e < 2 ** 34 ? 5 : 6, gt = (e) => {
1295
+ if (e < 127) return 1;
1296
+ if (e < 16383) return 2;
1297
+ if (e < (1 << 21) - 1) return 3;
1298
+ if (e < (1 << 28) - 1) return 4;
1299
+ if (e < 2 ** 35 - 1) return 5;
1300
+ if (e < 2 ** 42 - 1) return 6;
1301
+ throw Error("EBML varint size not supported " + e);
1302
+ }, _t = class {
1303
+ constructor(e) {
1304
+ this.writer = e, this.helper = new Uint8Array(8), this.helperView = new DataView(this.helper.buffer), this.offsets = /* @__PURE__ */ new WeakMap(), this.dataOffsets = /* @__PURE__ */ new WeakMap();
1305
+ }
1306
+ writeByte(e) {
1307
+ this.helperView.setUint8(0, e), this.writer.write(this.helper.subarray(0, 1));
1308
+ }
1309
+ writeFloat32(e) {
1310
+ this.helperView.setFloat32(0, e, !1), this.writer.write(this.helper.subarray(0, 4));
1311
+ }
1312
+ writeFloat64(e) {
1313
+ this.helperView.setFloat64(0, e, !1), this.writer.write(this.helper);
1314
+ }
1315
+ writeUnsignedInt(e, t = pt(e)) {
1316
+ let n = 0;
1317
+ switch (t) {
1318
+ case 6: this.helperView.setUint8(n++, e / 2 ** 40 | 0);
1319
+ case 5: this.helperView.setUint8(n++, e / 2 ** 32 | 0);
1320
+ case 4: this.helperView.setUint8(n++, e >> 24);
1321
+ case 3: this.helperView.setUint8(n++, e >> 16);
1322
+ case 2: this.helperView.setUint8(n++, e >> 8);
1323
+ case 1:
1324
+ this.helperView.setUint8(n++, e);
1325
+ break;
1326
+ default: throw Error("Bad unsigned int size " + t);
1327
+ }
1328
+ this.writer.write(this.helper.subarray(0, n));
1329
+ }
1330
+ writeUnsignedBigInt(e, t = mt(e)) {
1331
+ let n = 0;
1332
+ for (let r = t - 1; r >= 0; r--) this.helperView.setUint8(n++, Number(e >> BigInt(r * 8) & 255n));
1333
+ this.writer.write(this.helper.subarray(0, n));
1334
+ }
1335
+ writeSignedInt(e, t = ht(e)) {
1336
+ e < 0 && (e += 2 ** (t * 8)), this.writeUnsignedInt(e, t);
1337
+ }
1338
+ writeVarInt(e, t = gt(e)) {
1339
+ let n = 0;
1340
+ switch (t) {
1341
+ case 1:
1342
+ this.helperView.setUint8(n++, 128 | e);
1343
+ break;
1344
+ case 2:
1345
+ this.helperView.setUint8(n++, 64 | e >> 8), this.helperView.setUint8(n++, e);
1346
+ break;
1347
+ case 3:
1348
+ this.helperView.setUint8(n++, 32 | e >> 16), this.helperView.setUint8(n++, e >> 8), this.helperView.setUint8(n++, e);
1349
+ break;
1350
+ case 4:
1351
+ this.helperView.setUint8(n++, 16 | e >> 24), this.helperView.setUint8(n++, e >> 16), this.helperView.setUint8(n++, e >> 8), this.helperView.setUint8(n++, e);
1352
+ break;
1353
+ case 5:
1354
+ this.helperView.setUint8(n++, 8 | e / 2 ** 32 & 7), this.helperView.setUint8(n++, e >> 24), this.helperView.setUint8(n++, e >> 16), this.helperView.setUint8(n++, e >> 8), this.helperView.setUint8(n++, e);
1355
+ break;
1356
+ case 6:
1357
+ this.helperView.setUint8(n++, 4 | e / 2 ** 40 & 3), this.helperView.setUint8(n++, e / 2 ** 32 | 0), this.helperView.setUint8(n++, e >> 24), this.helperView.setUint8(n++, e >> 16), this.helperView.setUint8(n++, e >> 8), this.helperView.setUint8(n++, e);
1358
+ break;
1359
+ default: throw Error("Bad EBML varint size " + t);
1360
+ }
1361
+ this.writer.write(this.helper.subarray(0, n));
1362
+ }
1363
+ writeAsciiString(e) {
1364
+ this.writer.write(new Uint8Array(e.split("").map((e) => e.charCodeAt(0))));
1365
+ }
1366
+ writeEBML(e) {
1367
+ if (e !== null) if (e instanceof Uint8Array) this.writer.write(e);
1368
+ else if (Array.isArray(e)) for (let t of e) this.writeEBML(t);
1369
+ else if (this.offsets.set(e, this.writer.getPos()), this.writeUnsignedInt(e.id), Array.isArray(e.data)) {
1370
+ let t = this.writer.getPos(), n = e.size === -1 ? 1 : e.size ?? 4;
1371
+ e.size === -1 ? this.writeByte(255) : this.writer.seek(this.writer.getPos() + n);
1372
+ let r = this.writer.getPos();
1373
+ if (this.dataOffsets.set(e, r), this.writeEBML(e.data), e.size !== -1) {
1374
+ let e = this.writer.getPos() - r, i = this.writer.getPos();
1375
+ this.writer.seek(t), this.writeVarInt(e, n), this.writer.seek(i);
1376
+ }
1377
+ } else if (typeof e.data == "number") {
1378
+ let t = e.size ?? pt(e.data);
1379
+ this.writeVarInt(t), this.writeUnsignedInt(e.data, t);
1380
+ } else if (typeof e.data == "bigint") {
1381
+ let t = e.size ?? mt(e.data);
1382
+ this.writeVarInt(t), this.writeUnsignedBigInt(e.data, t);
1383
+ } else if (typeof e.data == "string") this.writeVarInt(e.data.length), this.writeAsciiString(e.data);
1384
+ else if (e.data instanceof Uint8Array) this.writeVarInt(e.data.byteLength, e.size), this.writer.write(e.data);
1385
+ else if (e.data instanceof V) this.writeVarInt(4), this.writeFloat32(e.data.value);
1386
+ else if (e.data instanceof H) this.writeVarInt(8), this.writeFloat64(e.data.value);
1387
+ else if (e.data instanceof ut) {
1388
+ let t = e.size ?? ht(e.data.value);
1389
+ this.writeVarInt(t), this.writeSignedInt(e.data.value, t);
1390
+ } else if (e.data instanceof U) {
1391
+ let t = c.encode(e.data.value);
1392
+ this.writeVarInt(t.length), this.writer.write(t);
1393
+ } else _(e.data);
1394
+ }
1395
+ }, vt = {
1396
+ avc: "V_MPEG4/ISO/AVC",
1397
+ hevc: "V_MPEGH/ISO/HEVC",
1398
+ vp8: "V_VP8",
1399
+ vp9: "V_VP9",
1400
+ av1: "V_AV1",
1401
+ prores: "V_PRORES",
1402
+ aac: "A_AAC",
1403
+ mp3: "A_MPEG/L3",
1404
+ opus: "A_OPUS",
1405
+ vorbis: "A_VORBIS",
1406
+ flac: "A_FLAC",
1407
+ ac3: "A_AC3",
1408
+ eac3: "A_EAC3",
1409
+ dts: "A_DTS",
1410
+ "pcm-u8": "A_PCM/INT/LIT",
1411
+ "pcm-s16": "A_PCM/INT/LIT",
1412
+ "pcm-s16be": "A_PCM/INT/BIG",
1413
+ "pcm-s24": "A_PCM/INT/LIT",
1414
+ "pcm-s24be": "A_PCM/INT/BIG",
1415
+ "pcm-s32": "A_PCM/INT/LIT",
1416
+ "pcm-s32be": "A_PCM/INT/BIG",
1417
+ "pcm-f32": "A_PCM/FLOAT/IEEE",
1418
+ "pcm-f64": "A_PCM/FLOAT/IEEE",
1419
+ webvtt: "S_TEXT/WEBVTT"
1420
+ }, yt = (e) => {
1421
+ let t = (e.hasVideo ? "video/" : e.hasAudio ? "audio/" : "application/") + (e.isWebM ? "webm" : "x-matroska");
1422
+ if (e.codecStrings.length > 0) {
1423
+ let n = [...new Set(e.codecStrings.filter(Boolean))];
1424
+ t += `; codecs="${n.join(", ")}"`;
1425
+ }
1426
+ return t;
1427
+ }, bt = (e) => {
1428
+ let t = e.filePos, n = new j(Qt(e, 9));
1429
+ if (n.readBits(12) !== 4095 || (n.skipBits(1), n.readBits(2) !== 0)) return null;
1430
+ let r = n.readBits(1), i = n.readBits(2) + 1, a = n.readBits(4);
1431
+ if (a === 15) return null;
1432
+ n.skipBits(1);
1433
+ let o = n.readBits(3);
1434
+ if (o === 0) throw Error("ADTS frames with channel configuration 0 are not supported.");
1435
+ n.skipBits(1), n.skipBits(1), n.skipBits(1), n.skipBits(1);
1436
+ let s = n.readBits(13);
1437
+ n.skipBits(11);
1438
+ let c = n.readBits(2) + 1;
1439
+ if (c !== 1) throw Error("ADTS frames with more than one AAC frame are not supported.");
1440
+ let l = null;
1441
+ return r === 1 ? e.filePos -= 2 : l = n.readBits(16), {
1442
+ objectType: i,
1443
+ samplingFrequencyIndex: a,
1444
+ channelConfiguration: o,
1445
+ frameLength: s,
1446
+ numberOfAacFrames: c,
1447
+ crcCheck: l,
1448
+ startPos: t
1449
+ };
1450
+ }, xt = function(e, t, n) {
1451
+ if (t != null) {
1452
+ if (typeof t != "object" && typeof t != "function") throw TypeError("Object expected.");
1453
+ var r, i;
1454
+ if (n) {
1455
+ if (!Symbol.asyncDispose) throw TypeError("Symbol.asyncDispose is not defined.");
1456
+ r = t[Symbol.asyncDispose];
1457
+ }
1458
+ if (r === void 0) {
1459
+ if (!Symbol.dispose) throw TypeError("Symbol.dispose is not defined.");
1460
+ r = t[Symbol.dispose], n && (i = r);
1461
+ }
1462
+ if (typeof r != "function") throw TypeError("Object not disposable.");
1463
+ i && (r = function() {
1464
+ try {
1465
+ i.call(this);
1466
+ } catch (e) {
1467
+ return Promise.reject(e);
1468
+ }
1469
+ }), e.stack.push({
1470
+ value: t,
1471
+ dispose: r,
1472
+ async: n
1473
+ });
1474
+ } else n && e.stack.push({ async: !0 });
1475
+ return t;
1476
+ }, St = (function(e) {
1477
+ return function(t) {
1478
+ function n(n) {
1479
+ t.error = t.hasError ? new e(n, t.error, "An error was suppressed during disposal.") : n, t.hasError = !0;
1480
+ }
1481
+ var r, i = 0;
1482
+ function a() {
1483
+ for (; r = t.stack.pop();) try {
1484
+ if (!r.async && i === 1) return i = 0, t.stack.push(r), Promise.resolve().then(a);
1485
+ if (r.dispose) {
1486
+ var e = r.dispose.call(r.value);
1487
+ if (r.async) return i |= 2, Promise.resolve(e).then(a, function(e) {
1488
+ return n(e), a();
1489
+ });
1490
+ } else i |= 1;
1491
+ } catch (e) {
1492
+ n(e);
1493
+ }
1494
+ if (i === 1) return t.hasError ? Promise.reject(t.error) : Promise.resolve();
1495
+ if (t.hasError) throw t.error;
1496
+ }
1497
+ return a();
1498
+ };
1499
+ })(typeof SuppressedError == "function" ? SuppressedError : function(e, t, n) {
1500
+ var r = Error(n);
1501
+ return r.name = "SuppressedError", r.error = e, r.suppressed = t, r;
1502
+ });
1503
+ de();
1504
+ var Ct = -Infinity, wt = -Infinity, G = null;
1505
+ typeof FinalizationRegistry < "u" && (G = new FinalizationRegistry((e) => {
1506
+ let t = performance.now();
1507
+ e.type === "video" ? (t - Ct >= 1e3 && (A._error("A VideoSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your VideoSamples as soon as you're done using them."), Ct = t), typeof VideoFrame < "u" && e.data instanceof VideoFrame && e.data.close()) : (t - wt >= 1e3 && (A._error("An AudioSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your AudioSamples as soon as you're done using them."), wt = t), typeof AudioData < "u" && e.data instanceof AudioData && e.data.close());
1508
+ }));
1509
+ var K = class {
1510
+ constructor() {
1511
+ this._referenceCount = 0, this._lastAllocationBuffer = null;
1512
+ }
1513
+ }, Tt = [
1514
+ "I420",
1515
+ "I420P10",
1516
+ "I420P12",
1517
+ "I420A",
1518
+ "I420AP10",
1519
+ "I420AP12",
1520
+ "I422",
1521
+ "I422P10",
1522
+ "I422P12",
1523
+ "I422A",
1524
+ "I422AP10",
1525
+ "I422AP12",
1526
+ "I444",
1527
+ "I444P10",
1528
+ "I444P12",
1529
+ "I444A",
1530
+ "I444AP10",
1531
+ "I444AP12",
1532
+ "NV12",
1533
+ "RGBA",
1534
+ "RGBX",
1535
+ "BGRA",
1536
+ "BGRX"
1537
+ ], Et = new Set(Tt), q = class e {
1538
+ get codedWidth() {
1539
+ return this.visibleRect.width;
1540
+ }
1541
+ get codedHeight() {
1542
+ return this.visibleRect.height;
1543
+ }
1544
+ get displayWidth() {
1545
+ return this.rotation % 180 == 0 ? this.squarePixelWidth : this.squarePixelHeight;
1546
+ }
1547
+ get displayHeight() {
1548
+ return this.rotation % 180 == 0 ? this.squarePixelHeight : this.squarePixelWidth;
1549
+ }
1550
+ get microsecondTimestamp() {
1551
+ return Math.trunc(w * this.timestamp);
1552
+ }
1553
+ get microsecondDuration() {
1554
+ return Math.trunc(w * this.duration);
1555
+ }
1556
+ get hasAlpha() {
1557
+ return this.format && this.format.includes("A");
1558
+ }
1559
+ constructor(t, n) {
1560
+ if (this._closed = !1, t instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && t instanceof SharedArrayBuffer || ArrayBuffer.isView(t)) {
1561
+ if (!n || typeof n != "object") throw TypeError("init must be an object.");
1562
+ if (n.format === void 0 || !Et.has(n.format)) throw TypeError("init.format must be one of: " + Tt.join(", "));
1563
+ if (!Number.isInteger(n.codedWidth) || n.codedWidth <= 0) throw TypeError("init.codedWidth must be a positive integer.");
1564
+ if (!Number.isInteger(n.codedHeight) || n.codedHeight <= 0) throw TypeError("init.codedHeight must be a positive integer.");
1565
+ if (n.rotation !== void 0 && ![
1566
+ 0,
1567
+ 90,
1568
+ 180,
1569
+ 270
1570
+ ].includes(n.rotation)) throw TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");
1571
+ if (!Number.isFinite(n.timestamp)) throw TypeError("init.timestamp must be a number.");
1572
+ if (n.duration !== void 0 && (!Number.isFinite(n.duration) || n.duration < 0)) throw TypeError("init.duration, when provided, must be a non-negative number.");
1573
+ if (n.layout !== void 0) {
1574
+ if (!Array.isArray(n.layout)) throw TypeError("init.layout, when provided, must be an array.");
1575
+ for (let e of n.layout) {
1576
+ if (!e || typeof e != "object" || Array.isArray(e)) throw TypeError("Each entry in init.layout must be an object.");
1577
+ if (!Number.isInteger(e.offset) || e.offset < 0) throw TypeError("plane.offset must be a non-negative integer.");
1578
+ if (!Number.isInteger(e.stride) || e.stride < 0) throw TypeError("plane.stride must be a non-negative integer.");
1579
+ }
1580
+ }
1581
+ if (n.visibleRect !== void 0 && D(n.visibleRect, "init.visibleRect"), n.displayWidth !== void 0 && (!Number.isInteger(n.displayWidth) || n.displayWidth <= 0)) throw TypeError("init.displayWidth, when provided, must be a positive integer.");
1582
+ if (n.displayHeight !== void 0 && (!Number.isInteger(n.displayHeight) || n.displayHeight <= 0)) throw TypeError("init.displayHeight, when provided, must be a positive integer.");
1583
+ if (n.displayWidth !== void 0 != (n.displayHeight !== void 0)) throw TypeError("init.displayWidth and init.displayHeight must be either both provided or both omitted.");
1584
+ this.format = n.format, this.rotation = n.rotation ?? 0, this.timestamp = n.timestamp, this.duration = n.duration ?? 0;
1585
+ let e = n.layout ?? Ft(n.format, n.codedWidth, n.codedHeight), r = n.colorSpace ?? null;
1586
+ r === null && (r = this.format === "RGBA" || this.format === "RGBX" || this.format === "BGRA" || this.format === "BGRX" ? {
1587
+ primaries: "bt709",
1588
+ transfer: "iec61966-2-1",
1589
+ matrix: "rgb",
1590
+ fullRange: !0
1591
+ } : {
1592
+ primaries: "bt709",
1593
+ transfer: "bt709",
1594
+ matrix: "bt709",
1595
+ fullRange: !1
1596
+ }), this.visibleRect = {
1597
+ left: n.visibleRect?.left ?? 0,
1598
+ top: n.visibleRect?.top ?? 0,
1599
+ width: n.visibleRect?.width ?? n.codedWidth,
1600
+ height: n.visibleRect?.height ?? n.codedHeight
1601
+ }, n.displayWidth === void 0 ? (this.squarePixelWidth = this.visibleRect.width, this.squarePixelHeight = this.visibleRect.height) : (this.squarePixelWidth = this.rotation % 180 == 0 ? n.displayWidth : n.displayHeight, this.squarePixelHeight = this.rotation % 180 == 0 ? n.displayHeight : n.displayWidth), this._data = n._doNotCopy ? o(t) : o(t).slice(), this._layout = e, this.colorSpace = new jt(r);
1602
+ } else if (typeof VideoFrame < "u" && t instanceof VideoFrame) {
1603
+ if (n?.rotation !== void 0 && ![
1604
+ 0,
1605
+ 90,
1606
+ 180,
1607
+ 270
1608
+ ].includes(n.rotation)) throw TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");
1609
+ if (n?.timestamp !== void 0 && !Number.isFinite(n?.timestamp)) throw TypeError("init.timestamp, when provided, must be a number.");
1610
+ if (n?.duration !== void 0 && (!Number.isFinite(n.duration) || n.duration < 0)) throw TypeError("init.duration, when provided, must be a non-negative number.");
1611
+ n?.visibleRect !== void 0 && D(n.visibleRect, "init.visibleRect"), this._data = t, this._layout = null, this.format = t.format, this.visibleRect = {
1612
+ left: t.visibleRect?.x ?? 0,
1613
+ top: t.visibleRect?.y ?? 0,
1614
+ width: t.visibleRect?.width ?? t.codedWidth,
1615
+ height: t.visibleRect?.height ?? t.codedHeight
1616
+ }, this.rotation = n?.rotation ?? 0, this.squarePixelWidth = t.displayWidth, this.squarePixelHeight = t.displayHeight, this.timestamp = n?.timestamp ?? t.timestamp / 1e6, this.duration = n?.duration ?? (t.duration ?? 0) / 1e6, this.colorSpace = new jt(t.colorSpace);
1617
+ } else if (typeof HTMLImageElement < "u" && t instanceof HTMLImageElement || typeof SVGImageElement < "u" && t instanceof SVGImageElement || typeof ImageBitmap < "u" && t instanceof ImageBitmap || typeof HTMLVideoElement < "u" && t instanceof HTMLVideoElement || typeof HTMLCanvasElement < "u" && t instanceof HTMLCanvasElement || typeof OffscreenCanvas < "u" && t instanceof OffscreenCanvas) {
1618
+ if (!n || typeof n != "object") throw TypeError("init must be an object.");
1619
+ if (n.rotation !== void 0 && ![
1620
+ 0,
1621
+ 90,
1622
+ 180,
1623
+ 270
1624
+ ].includes(n.rotation)) throw TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");
1625
+ if (!Number.isFinite(n.timestamp)) throw TypeError("init.timestamp must be a number.");
1626
+ if (n.duration !== void 0 && (!Number.isFinite(n.duration) || n.duration < 0)) throw TypeError("init.duration, when provided, must be a non-negative number.");
1627
+ if (n.visibleRect !== void 0 && D(n.visibleRect, "init.visibleRect"), typeof VideoFrame < "u") return new e(new VideoFrame(t, {
1628
+ timestamp: Math.trunc(n.timestamp * w),
1629
+ duration: Math.trunc((n.duration ?? 0) * w) || void 0,
1630
+ visibleRect: n.visibleRect && {
1631
+ x: n.visibleRect.left,
1632
+ y: n.visibleRect.top,
1633
+ width: n.visibleRect.width,
1634
+ height: n.visibleRect.height
1635
+ }
1636
+ }), n);
1637
+ let r = 0, i = 0;
1638
+ if ("naturalWidth" in t ? (r = t.naturalWidth, i = t.naturalHeight) : "videoWidth" in t ? (r = t.videoWidth, i = t.videoHeight) : "width" in t && (r = Number(t.width), i = Number(t.height)), !r || !i) throw TypeError("Could not determine dimensions.");
1639
+ let a = n.visibleRect ?? {
1640
+ left: 0,
1641
+ top: 0,
1642
+ width: r,
1643
+ height: i
1644
+ }, o = new OffscreenCanvas(a.width, a.height), s = o.getContext("2d", {
1645
+ alpha: ie(),
1646
+ willReadFrequently: !0
1647
+ });
1648
+ if (!s) throw Error("OffscreenCanvas must have support for the '2d' context in order to create a VideoSample from this data.");
1649
+ s.drawImage(t, -a.left, -a.top), this._data = o, this._layout = null, this.format = "RGBX", this.visibleRect = {
1650
+ left: 0,
1651
+ top: 0,
1652
+ width: a.width,
1653
+ height: a.height
1654
+ }, this.squarePixelWidth = a.width, this.squarePixelHeight = a.height, this.rotation = n.rotation ?? 0, this.timestamp = n.timestamp, this.duration = n.duration ?? 0, this.colorSpace = new jt({
1655
+ matrix: "rgb",
1656
+ primaries: "bt709",
1657
+ transfer: "iec61966-2-1",
1658
+ fullRange: !0
1659
+ });
1660
+ } else if (t instanceof K) {
1661
+ if (!n || typeof n != "object") throw TypeError("init must be an object.");
1662
+ if (n.rotation !== void 0 && ![
1663
+ 0,
1664
+ 90,
1665
+ 180,
1666
+ 270
1667
+ ].includes(n.rotation)) throw TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");
1668
+ if (!Number.isFinite(n.timestamp)) throw TypeError("init.timestamp must be a number.");
1669
+ if (n.duration !== void 0 && (!Number.isFinite(n.duration) || n.duration < 0)) throw TypeError("init.duration, when provided, must be a non-negative number.");
1670
+ if (this._data = t, t._referenceCount++, this.format = t.getFormat(), this.format !== null && !Tt.includes(this.format)) throw TypeError("getFormat() must return a VideoSamplePixelFormat or null.");
1671
+ if (this.visibleRect = {
1672
+ left: 0,
1673
+ top: 0,
1674
+ width: t.getCodedWidth(),
1675
+ height: t.getCodedHeight()
1676
+ }, !Number.isInteger(this.visibleRect.width) || this.visibleRect.width <= 0) throw TypeError("getCodedWidth() must return a positive integer.");
1677
+ if (!Number.isInteger(this.visibleRect.height) || this.visibleRect.height <= 0) throw TypeError("getCodedHeight() must return a positive integer.");
1678
+ if (this.squarePixelWidth = t.getSquarePixelWidth(), !Number.isInteger(this.squarePixelWidth) || this.squarePixelWidth <= 0) throw TypeError("getSquarePixelWidth() must return a positive integer.");
1679
+ if (this.squarePixelHeight = t.getSquarePixelHeight(), !Number.isInteger(this.squarePixelHeight) || this.squarePixelHeight <= 0) throw TypeError("getSquarePixelHeight() must return a positive integer.");
1680
+ this.rotation = n.rotation ?? 0, this.timestamp = n.timestamp, this.duration = n.duration ?? 0, this.colorSpace = t.getColorSpace();
1681
+ } else throw TypeError("Invalid data type: Must be a BufferSource, CanvasImageSource, or VideoSampleResource.");
1682
+ this.encodeOptions = n?.encodeOptions ?? {}, this.pixelAspectRatio = me({
1683
+ num: this.squarePixelWidth * this.codedHeight,
1684
+ den: this.squarePixelHeight * this.codedWidth
1685
+ }), G?.register(this, {
1686
+ type: "video",
1687
+ data: this._data
1688
+ }, this);
1689
+ }
1690
+ clone() {
1691
+ if (this._closed) throw Error("VideoSample is closed.");
1692
+ return t(this._data !== null), this._data instanceof K ? new e(this._data, {
1693
+ timestamp: this.timestamp,
1694
+ duration: this.duration,
1695
+ rotation: this.rotation,
1696
+ encodeOptions: this.encodeOptions
1697
+ }) : Y(this._data) ? new e(this._data.clone(), {
1698
+ timestamp: this.timestamp,
1699
+ duration: this.duration,
1700
+ rotation: this.rotation,
1701
+ encodeOptions: this.encodeOptions
1702
+ }) : this._data instanceof Uint8Array ? (t(this._layout), new e(this._data, {
1703
+ format: this.format,
1704
+ layout: this._layout,
1705
+ codedWidth: this.codedWidth,
1706
+ codedHeight: this.codedHeight,
1707
+ timestamp: this.timestamp,
1708
+ duration: this.duration,
1709
+ colorSpace: this.colorSpace,
1710
+ rotation: this.rotation,
1711
+ visibleRect: this.visibleRect,
1712
+ displayWidth: this.displayWidth,
1713
+ displayHeight: this.displayHeight,
1714
+ encodeOptions: this.encodeOptions,
1715
+ _doNotCopy: !0
1716
+ })) : new e(this._data, {
1717
+ format: this.format,
1718
+ codedWidth: this.codedWidth,
1719
+ codedHeight: this.codedHeight,
1720
+ timestamp: this.timestamp,
1721
+ duration: this.duration,
1722
+ colorSpace: this.colorSpace,
1723
+ rotation: this.rotation,
1724
+ visibleRect: this.visibleRect,
1725
+ displayWidth: this.displayWidth,
1726
+ displayHeight: this.displayHeight,
1727
+ encodeOptions: this.encodeOptions
1728
+ });
1729
+ }
1730
+ close() {
1731
+ this._closed ||= (G?.unregister(this), this._data instanceof K ? (this._data._referenceCount--, this._data._referenceCount === 0 && this._data.close()) : Y(this._data) ? this._data.close() : this._data = null, !0);
1732
+ }
1733
+ allocationSize(e = {}) {
1734
+ if (Pt(e), this._closed) throw Error("VideoSample is closed.");
1735
+ if ((e.format ?? this.format) == null) throw Error("Cannot get allocation size when format is null.");
1736
+ return Y(this._data) ? this._data.allocationSize(e) : It(this, e).allocationSize;
1737
+ }
1738
+ async copyTo(n, r = {}) {
1739
+ if (!p(n)) throw TypeError("destination must be an ArrayBuffer or an ArrayBuffer view.");
1740
+ if (Pt(r), this._closed) throw Error("VideoSample is closed.");
1741
+ if ((r.format ?? this.format) == null) throw Error("Cannot copy video sample data when format is null.");
1742
+ if (t(this._data !== null), Y(this._data)) return this._data.copyTo(n, r);
1743
+ if (r.format && ![
1744
+ "RGBA",
1745
+ "RGBX",
1746
+ "BGRA",
1747
+ "BGRX"
1748
+ ].includes(this.format) && [
1749
+ "RGBA",
1750
+ "RGBX",
1751
+ "BGRA",
1752
+ "BGRX"
1753
+ ].includes(r.format)) if (this._data instanceof K) {
1754
+ let t = {
1755
+ stack: [],
1756
+ error: void 0,
1757
+ hasError: !1
1758
+ };
1759
+ try {
1760
+ let i = xt(t, await this._data.toRgbSample({
1761
+ timestamp: this.timestamp,
1762
+ duration: this.duration,
1763
+ rotation: this.rotation
1764
+ }, r.colorSpace ?? "srgb"), !1);
1765
+ if (!(i instanceof e)) throw TypeError("toRgbSample() must return a VideoSample.");
1766
+ if (![
1767
+ "RGBA",
1768
+ "RGBX",
1769
+ "BGRA",
1770
+ "BGRX"
1771
+ ].includes(i.format)) throw Error(`Sample returned by toRgbSample was expected to have an RGB format, got '${i.format}' instead.`);
1772
+ return await i.copyTo(n, r);
1773
+ } catch (e) {
1774
+ t.error = e, t.hasError = !0;
1775
+ } finally {
1776
+ St(t);
1777
+ }
1778
+ } else {
1779
+ if (typeof VideoFrame > "u") throw Error("For this sample, converting from a non-RGB to an RGB format requires VideoFrame to be defined.");
1780
+ let e = this.toVideoFrame(), t = await e.copyTo(n, r);
1781
+ return e.close(), t;
1782
+ }
1783
+ let i = It(this, r);
1784
+ t(this.format);
1785
+ let a = o(n);
1786
+ if (a.byteLength < i.allocationSize) throw TypeError(`Destination buffer too small. Required: ${i.allocationSize}, Available: ${a.byteLength}`);
1787
+ let s = X(this.format), c;
1788
+ if (this._data instanceof K) {
1789
+ let e = this._data.getDataPlanes();
1790
+ if (E(e) && (e = await e), !Array.isArray(e) || e.some((e) => !(e.data instanceof Uint8Array) || !Number.isInteger(e.stride) || e.stride < 0)) throw TypeError("getDataPlanes() must return an array of objects with a Uint8Array \"data\" property and a non-negative integer \"stride\" property.");
1791
+ c = e;
1792
+ } else if (this._data instanceof Uint8Array) t(this._layout), t(this._layout.length === s.length), c = this._layout.map((e, t) => {
1793
+ let n = Math.ceil(this.codedHeight / s[t].heightDivisor);
1794
+ return {
1795
+ data: this._data.subarray(e.offset, e.offset + e.stride * n),
1796
+ stride: e.stride
1797
+ };
1798
+ });
1799
+ else {
1800
+ let e = this._data.getContext("2d");
1801
+ t(e), c = [{
1802
+ data: o(e.getImageData(0, 0, this.codedWidth, this.codedHeight).data),
1803
+ stride: 4 * this.codedWidth
1804
+ }];
1805
+ }
1806
+ let l = [], u = s.length;
1807
+ for (let e = 0; e < u; e++) {
1808
+ let t = i.computedLayouts[e], n = c[e].stride, r = c[e].data, o = t.sourceTop * n;
1809
+ o += t.sourceLeftBytes;
1810
+ let s = t.destinationOffset, u = t.sourceWidthBytes, d = {
1811
+ offset: s,
1812
+ stride: t.destinationStride
1813
+ };
1814
+ for (let e = 0; e < t.sourceHeight; e++) {
1815
+ if (o + u > r.byteLength) throw Error("Source buffer OOB read.");
1816
+ if (s + u > a.byteLength) throw Error("Destination buffer OOB write.");
1817
+ let e = r.subarray(o, o + u);
1818
+ a.set(e, s), o += n, s += t.destinationStride;
1819
+ }
1820
+ l.push(d);
1821
+ }
1822
+ if (r.format !== void 0) {
1823
+ let e = this.format.startsWith("RGB") !== r.format.startsWith("RGB"), t = this.format.includes("X") && r.format.includes("A");
1824
+ if (e || t) for (let n = 0; n < i.allocationSize; n += 4) {
1825
+ if (e) {
1826
+ let e = a[n];
1827
+ a[n] = a[n + 2], a[n + 2] = e;
1828
+ }
1829
+ t && (a[n + 3] = 255);
1830
+ }
1831
+ }
1832
+ return l;
1833
+ }
1834
+ toVideoFrame() {
1835
+ if (this._closed) throw Error("VideoSample is closed.");
1836
+ if (t(this._data !== null), this._data instanceof K) {
1837
+ if (this.format === null) throw Error("Cannot convert a VideoSampleResource-backed VideoSample to VideoFrame if format is null.");
1838
+ let e = this._data.getDataPlanes();
1839
+ if (E(e)) throw Error("Cannot convert a VideoSampleResource-backed VideoSample to VideoFrame if getDataPlanes() returns a promise.");
1840
+ let t = e.reduce((e, t) => e + t.data.byteLength, 0), n = new Uint8Array(t), r = 0, i = [];
1841
+ for (let t of e) n.set(t.data, r), i.push(r), r += t.data.byteLength;
1842
+ return new VideoFrame(n, {
1843
+ format: this.format,
1844
+ layout: e.map((e, t) => ({
1845
+ offset: i[t],
1846
+ stride: e.stride
1847
+ })),
1848
+ codedWidth: this.codedWidth,
1849
+ codedHeight: this.codedHeight,
1850
+ timestamp: this.microsecondTimestamp,
1851
+ duration: this.microsecondDuration,
1852
+ colorSpace: this.colorSpace,
1853
+ visibleRect: this.visibleRect,
1854
+ displayWidth: this.squarePixelWidth,
1855
+ displayHeight: this.squarePixelHeight
1856
+ });
1857
+ } else if (Y(this._data)) return new VideoFrame(this._data, {
1858
+ timestamp: this.microsecondTimestamp,
1859
+ duration: this.microsecondDuration || void 0
1860
+ });
1861
+ else if (this._data instanceof Uint8Array) return t(this._layout), new VideoFrame(this._data, {
1862
+ format: this.format,
1863
+ codedWidth: this.codedWidth,
1864
+ codedHeight: this.codedHeight,
1865
+ layout: this._layout,
1866
+ timestamp: this.microsecondTimestamp,
1867
+ duration: this.microsecondDuration || void 0,
1868
+ colorSpace: this.colorSpace,
1869
+ visibleRect: this.visibleRect,
1870
+ displayWidth: this.squarePixelWidth,
1871
+ displayHeight: this.squarePixelHeight
1872
+ });
1873
+ else return new VideoFrame(this._data, {
1874
+ timestamp: this.microsecondTimestamp,
1875
+ duration: this.microsecondDuration || void 0
1876
+ });
1877
+ }
1878
+ draw(e, t, n, r, i, a, o, s, c) {
1879
+ let l = 0, u = 0, d = this.displayWidth, f = this.displayHeight, p = 0, m = 0, h = this.displayWidth, g = this.displayHeight;
1880
+ if (a === void 0 ? (p = t, m = n, r !== void 0 && (h = r, g = i)) : (l = t, u = n, d = r, f = i, p = a, m = o, s === void 0 ? (h = d, g = f) : (h = s, g = c)), !(typeof CanvasRenderingContext2D < "u" && e instanceof CanvasRenderingContext2D || typeof OffscreenCanvasRenderingContext2D < "u" && e instanceof OffscreenCanvasRenderingContext2D)) throw TypeError("context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.");
1881
+ if (!Number.isFinite(l)) throw TypeError("sx must be a number.");
1882
+ if (!Number.isFinite(u)) throw TypeError("sy must be a number.");
1883
+ if (!Number.isFinite(d) || d < 0) throw TypeError("sWidth must be a non-negative number.");
1884
+ if (!Number.isFinite(f) || f < 0) throw TypeError("sHeight must be a non-negative number.");
1885
+ if (!Number.isFinite(p)) throw TypeError("dx must be a number.");
1886
+ if (!Number.isFinite(m)) throw TypeError("dy must be a number.");
1887
+ if (!Number.isFinite(h) || h < 0) throw TypeError("dWidth must be a non-negative number.");
1888
+ if (!Number.isFinite(g) || g < 0) throw TypeError("dHeight must be a non-negative number.");
1889
+ if (this._closed) throw Error("VideoSample is closed.");
1890
+ ({sx: l, sy: u, sWidth: d, sHeight: f} = this._rotateSourceRegion(l, u, d, f, this.rotation));
1891
+ let _ = this.toCanvasImageSource();
1892
+ e.save();
1893
+ let v = p + h / 2, y = m + g / 2;
1894
+ e.translate(v, y), e.rotate(this.rotation * Math.PI / 180);
1895
+ let b = this.rotation % 180 == 0 ? 1 : h / g;
1896
+ e.scale(1 / b, b), e.drawImage(_, l, u, d, f, -h / 2, -g / 2, h, g), e.restore();
1897
+ }
1898
+ drawWithFit(e, t) {
1899
+ if (!(typeof CanvasRenderingContext2D < "u" && e instanceof CanvasRenderingContext2D || typeof OffscreenCanvasRenderingContext2D < "u" && e instanceof OffscreenCanvasRenderingContext2D)) throw TypeError("context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.");
1900
+ if (!t || typeof t != "object") throw TypeError("options must be an object.");
1901
+ if (![
1902
+ "fill",
1903
+ "contain",
1904
+ "cover"
1905
+ ].includes(t.fit)) throw TypeError("options.fit must be 'fill', 'contain', or 'cover'.");
1906
+ if (t.rotation !== void 0 && ![
1907
+ 0,
1908
+ 90,
1909
+ 180,
1910
+ 270
1911
+ ].includes(t.rotation)) throw TypeError("options.rotation, when provided, must be 0, 90, 180, or 270.");
1912
+ t.crop !== void 0 && Nt(t.crop, "options.");
1913
+ let n = e.canvas.width, r = e.canvas.height, i = t.rotation ?? this.rotation, [a, o] = i % 180 == 0 ? [this.squarePixelWidth, this.squarePixelHeight] : [this.squarePixelHeight, this.squarePixelWidth], s = t.crop;
1914
+ s &&= Mt(s, a, o);
1915
+ let c, l, u, d, { sx: f, sy: p, sWidth: m, sHeight: h } = this._rotateSourceRegion(t.crop?.left ?? 0, t.crop?.top ?? 0, t.crop?.width ?? a, t.crop?.height ?? o, i);
1916
+ if (t.fit === "fill") c = 0, l = 0, u = n, d = r;
1917
+ else {
1918
+ let [e, i] = t.crop ? [t.crop.width, t.crop.height] : [a, o], s = t.fit === "contain" ? Math.min(n / e, r / i) : Math.max(n / e, r / i);
1919
+ u = e * s, d = i * s, c = (n - u) / 2, l = (r - d) / 2;
1920
+ }
1921
+ e.save();
1922
+ let g = i % 180 == 0 ? 1 : u / d;
1923
+ e.translate(n / 2, r / 2), e.rotate(i * Math.PI / 180), e.scale(1 / g, g), e.translate(-n / 2, -r / 2), e.drawImage(this.toCanvasImageSource(), f, p, m, h, c, l, u, d), e.restore();
1924
+ }
1925
+ _rotateSourceRegion(e, t, n, r, i) {
1926
+ return i === 90 ? [e, t, n, r] = [
1927
+ t,
1928
+ this.squarePixelHeight - e - n,
1929
+ r,
1930
+ n
1931
+ ] : i === 180 ? [e, t] = [this.squarePixelWidth - e - n, this.squarePixelHeight - t - r] : i === 270 && ([e, t, n, r] = [
1932
+ this.squarePixelWidth - t - r,
1933
+ e,
1934
+ r,
1935
+ n
1936
+ ]), {
1937
+ sx: e,
1938
+ sy: t,
1939
+ sWidth: n,
1940
+ sHeight: r
1941
+ };
1942
+ }
1943
+ _drawWithFitAndMipmapping(e, t, n) {
1944
+ let r = e.width, i = e.height, [a, o] = n.rotation % 180 == 0 ? [this.squarePixelWidth, this.squarePixelHeight] : [this.squarePixelHeight, this.squarePixelWidth], s = n.crop ? n.crop.width : a, c = n.crop ? n.crop.height : o, l = 0;
1945
+ 2 * r < s && 2 * i < c && (l = Math.floor(Math.log2(Math.min(s / r, c / i))));
1946
+ let u = r * 2 ** l, d = i * 2 ** l, { canvas: f, context: p, isNew: m } = l > 0 ? At(u, d) : {
1947
+ canvas: e,
1948
+ context: t,
1949
+ isNew: n.targetIsFresh
1950
+ };
1951
+ p.imageSmoothingQuality = "high", n.fillBlack ? (p.fillStyle = "black", p.fillRect(0, 0, u, d)) : m || p.clearRect(0, 0, u, d), this.drawWithFit(p, {
1952
+ fit: n.fit,
1953
+ rotation: n.rotation,
1954
+ crop: n.crop
1955
+ }), p.globalCompositeOperation = "copy";
1956
+ for (let e = l; e > 1; e--) {
1957
+ let t = r * 2 ** e, n = i * 2 ** e;
1958
+ p.drawImage(f, 0, 0, t, n, 0, 0, t / 2, n / 2);
1959
+ }
1960
+ p.globalCompositeOperation = "source-over", l > 0 && (t.imageSmoothingQuality = "high", t.globalCompositeOperation = "copy", t.drawImage(f, 0, 0, 2 * r, 2 * i, 0, 0, r, i), t.globalCompositeOperation = "source-over");
1961
+ }
1962
+ toCanvasImageSource() {
1963
+ if (this._closed) throw Error("VideoSample is closed.");
1964
+ if (t(this._data !== null), this._data instanceof K || this._data instanceof Uint8Array) {
1965
+ let e = this.toVideoFrame();
1966
+ return queueMicrotask(() => e.close()), e;
1967
+ } else return this._data;
1968
+ }
1969
+ async transform(t) {
1970
+ if (!t || typeof t != "object") throw TypeError("options must be an object.");
1971
+ if (t.width !== void 0 && (!Number.isInteger(t.width) || t.width <= 0)) throw TypeError("options.width, when provided, must be a positive integer.");
1972
+ if (t.height !== void 0 && (!Number.isInteger(t.height) || t.height <= 0)) throw TypeError("options.height, when provided, must be a positive integer.");
1973
+ if (t.roundDimensionsTo !== void 0 && (!Number.isInteger(t.roundDimensionsTo) || t.roundDimensionsTo <= 0)) throw TypeError("options.roundDimensionsTo, when provided, must be a positive integer.");
1974
+ if (t.fit !== void 0 && ![
1975
+ "fill",
1976
+ "contain",
1977
+ "cover"
1978
+ ].includes(t.fit)) throw TypeError("options.fit, when provided, must be one of \"fill\", \"contain\", or \"cover\".");
1979
+ if (t.width !== void 0 && t.height !== void 0 && t.fit === void 0) throw TypeError("When both options.width and options.height are provided, options.fit must also be provided.");
1980
+ if (t.rotate !== void 0 && ![
1981
+ 0,
1982
+ 90,
1983
+ 180,
1984
+ 270
1985
+ ].includes(t.rotate)) throw TypeError("options.rotate, when provided, must be 0, 90, 180 or 270.");
1986
+ if (t.crop !== void 0 && Nt(t.crop, "options."), t.alpha !== void 0 && !["keep", "discard"].includes(t.alpha)) throw TypeError("options.alpha, when provided, must be 'keep' or 'discard'.");
1987
+ let r = n(this.rotation + (t.rotate ?? 0)), [i, a] = r % 180 == 0 ? [this.squarePixelWidth, this.squarePixelHeight] : [this.squarePixelHeight, this.squarePixelWidth], o = t.crop;
1988
+ o &&= Mt(o, i, a);
1989
+ let s = o ? o.width : i, c = o ? o.height : a, l = s / c, u, d;
1990
+ t.width !== void 0 && t.height === void 0 ? (u = t.width, d = u / l) : t.width === void 0 && t.height !== void 0 ? (d = t.height, u = d * l) : t.width !== void 0 && t.height !== void 0 ? (u = t.width, d = t.height) : (u = s, d = c), u = x(u, t.roundDimensionsTo ?? 1), d = x(d, t.roundDimensionsTo ?? 1);
1991
+ let f = {
1992
+ width: u,
1993
+ height: d,
1994
+ fit: t.fit ?? "fill",
1995
+ rotation: r,
1996
+ crop: o ?? {
1997
+ left: 0,
1998
+ top: 0,
1999
+ width: i,
2000
+ height: a
2001
+ },
2002
+ alpha: t.alpha ?? "keep"
2003
+ };
2004
+ for (let e of Dt) {
2005
+ let t = e(this, f);
2006
+ if (E(t) && (t = await t), t !== null) return t;
2007
+ }
2008
+ let { canvas: p, context: m, isNew: h } = At(f.width, f.height);
2009
+ return this._drawWithFitAndMipmapping(p, m, {
2010
+ fit: f.fit,
2011
+ rotation: f.rotation,
2012
+ crop: f.crop,
2013
+ targetIsFresh: h,
2014
+ fillBlack: f.alpha === "discard"
2015
+ }), new e(p, {
2016
+ timestamp: this.timestamp,
2017
+ duration: this.duration,
2018
+ rotation: 0
2019
+ });
2020
+ }
2021
+ setRotation(e) {
2022
+ if (![
2023
+ 0,
2024
+ 90,
2025
+ 180,
2026
+ 270
2027
+ ].includes(e)) throw TypeError("newRotation must be 0, 90, 180, or 270.");
2028
+ this.rotation = e;
2029
+ }
2030
+ setTimestamp(e) {
2031
+ if (!Number.isFinite(e)) throw TypeError("newTimestamp must be a number.");
2032
+ this.timestamp = e;
2033
+ }
2034
+ setDuration(e) {
2035
+ if (!Number.isFinite(e) || e < 0) throw TypeError("newDuration must be a non-negative number.");
2036
+ this.duration = e;
2037
+ }
2038
+ setEncodeOptions(e) {
2039
+ if (!e || typeof e != "object") throw TypeError("newEncodeOptions must be an object.");
2040
+ this.encodeOptions = e;
2041
+ }
2042
+ [Symbol.dispose]() {
2043
+ this.close();
2044
+ }
2045
+ }, Dt = [], Ot = 3, J = [], kt = 0, At = (e, t) => {
2046
+ for (let n of J) if (n.canvas.width === e && n.canvas.height === t) return n.age = kt++, {
2047
+ canvas: n.canvas,
2048
+ context: n.context,
2049
+ isNew: !1
2050
+ };
2051
+ let n;
2052
+ if (typeof OffscreenCanvas < "u") n = new OffscreenCanvas(e, t);
2053
+ else {
2054
+ if (typeof window > "u" || typeof document > "u") throw Error("Cannot transform VideoSamples in this environment. Either run in an environment with OffscreenCanvas or HTMLCanvasElement, or supply a custom VideoSample transformer using registerVideoSampleTransformer().");
2055
+ n = document.createElement("canvas"), n.width = e, n.height = t;
2056
+ }
2057
+ let r = n.getContext("2d", {
2058
+ alpha: !0,
2059
+ willReadFrequently: !1
2060
+ });
2061
+ if (!r) throw Error("The '2d' canvas context is required to transform VideoSamples. Register a custom transformer using registerVideoSampleTransformer to work around this limitation.");
2062
+ return J.length >= Ot && J.splice(pe(J, (e) => e.age), 1), J.push({
2063
+ canvas: n,
2064
+ context: r,
2065
+ age: kt++
2066
+ }), {
2067
+ canvas: n,
2068
+ context: r,
2069
+ isNew: !0
2070
+ };
2071
+ }, jt = class {
2072
+ constructor(e) {
2073
+ if (e !== void 0) {
2074
+ if (!e || typeof e != "object") throw TypeError("init.colorSpace, when provided, must be an object.");
2075
+ let t = Object.keys(l);
2076
+ if (e.primaries != null && !t.includes(e.primaries)) throw TypeError(`init.colorSpace.primaries, when provided, must be one of ${t.join(", ")}.`);
2077
+ let n = Object.keys(u);
2078
+ if (e.transfer != null && !n.includes(e.transfer)) throw TypeError(`init.colorSpace.transfer, when provided, must be one of ${n.join(", ")}.`);
2079
+ let r = Object.keys(d);
2080
+ if (e.matrix != null && !r.includes(e.matrix)) throw TypeError(`init.colorSpace.matrix, when provided, must be one of ${r.join(", ")}.`);
2081
+ if (e.fullRange != null && typeof e.fullRange != "boolean") throw TypeError("init.colorSpace.fullRange, when provided, must be a boolean.");
2082
+ }
2083
+ this.primaries = e?.primaries ?? null, this.transfer = e?.transfer ?? null, this.matrix = e?.matrix ?? null, this.fullRange = e?.fullRange ?? null;
2084
+ }
2085
+ toJSON() {
2086
+ return {
2087
+ primaries: this.primaries,
2088
+ transfer: this.transfer,
2089
+ matrix: this.matrix,
2090
+ fullRange: this.fullRange
2091
+ };
2092
+ }
2093
+ }, Y = (e) => typeof VideoFrame < "u" && e instanceof VideoFrame, Mt = (e, n, r) => {
2094
+ let i = Math.min(e.left, n), a = Math.min(e.top, r), o = Math.min(e.width, n - i), s = Math.min(e.height, r - a);
2095
+ return t(o >= 0), t(s >= 0), {
2096
+ left: i,
2097
+ top: a,
2098
+ width: o,
2099
+ height: s
2100
+ };
2101
+ }, Nt = (e, t) => {
2102
+ if (!e || typeof e != "object") throw TypeError(t + "crop, when provided, must be an object.");
2103
+ if (!Number.isInteger(e.left) || e.left < 0) throw TypeError(t + "crop.left must be a non-negative integer.");
2104
+ if (!Number.isInteger(e.top) || e.top < 0) throw TypeError(t + "crop.top must be a non-negative integer.");
2105
+ if (!Number.isInteger(e.width) || e.width < 0) throw TypeError(t + "crop.width must be a non-negative integer.");
2106
+ if (!Number.isInteger(e.height) || e.height < 0) throw TypeError(t + "crop.height must be a non-negative integer.");
2107
+ }, Pt = (e) => {
2108
+ if (!e || typeof e != "object") throw TypeError("options must be an object.");
2109
+ if (e.colorSpace !== void 0 && !["display-p3", "srgb"].includes(e.colorSpace)) throw TypeError("options.colorSpace, when provided, must be 'display-p3' or 'srgb'.");
2110
+ if (e.format !== void 0 && typeof e.format != "string") throw TypeError("options.format, when provided, must be a string.");
2111
+ if (e.layout !== void 0) {
2112
+ if (!Array.isArray(e.layout)) throw TypeError("options.layout, when provided, must be an array.");
2113
+ for (let t of e.layout) {
2114
+ if (!t || typeof t != "object") throw TypeError("Each entry in options.layout must be an object.");
2115
+ if (!Number.isInteger(t.offset) || t.offset < 0) throw TypeError("plane.offset must be a non-negative integer.");
2116
+ if (!Number.isInteger(t.stride) || t.stride < 0) throw TypeError("plane.stride must be a non-negative integer.");
2117
+ }
2118
+ }
2119
+ if (e.rect !== void 0) {
2120
+ if (!e.rect || typeof e.rect != "object") throw TypeError("options.rect, when provided, must be an object.");
2121
+ if (e.rect.x !== void 0 && (!Number.isInteger(e.rect.x) || e.rect.x < 0)) throw TypeError("options.rect.x, when provided, must be a non-negative integer.");
2122
+ if (e.rect.y !== void 0 && (!Number.isInteger(e.rect.y) || e.rect.y < 0)) throw TypeError("options.rect.y, when provided, must be a non-negative integer.");
2123
+ if (e.rect.width !== void 0 && (!Number.isInteger(e.rect.width) || e.rect.width < 0)) throw TypeError("options.rect.width, when provided, must be a non-negative integer.");
2124
+ if (e.rect.height !== void 0 && (!Number.isInteger(e.rect.height) || e.rect.height < 0)) throw TypeError("options.rect.height, when provided, must be a non-negative integer.");
2125
+ }
2126
+ }, Ft = (e, t, n) => {
2127
+ let r = X(e), i = [], a = 0;
2128
+ for (let e of r) {
2129
+ let r = Math.ceil(t / e.widthDivisor), o = Math.ceil(n / e.heightDivisor), s = r * e.sampleBytes, c = s * o;
2130
+ i.push({
2131
+ offset: a,
2132
+ stride: s
2133
+ }), a += c;
2134
+ }
2135
+ return i;
2136
+ }, X = (e) => {
2137
+ let n = (e, t, n, r, i) => {
2138
+ let a = [
2139
+ {
2140
+ sampleBytes: e,
2141
+ widthDivisor: 1,
2142
+ heightDivisor: 1
2143
+ },
2144
+ {
2145
+ sampleBytes: t,
2146
+ widthDivisor: n,
2147
+ heightDivisor: r
2148
+ },
2149
+ {
2150
+ sampleBytes: t,
2151
+ widthDivisor: n,
2152
+ heightDivisor: r
2153
+ }
2154
+ ];
2155
+ return i && a.push({
2156
+ sampleBytes: e,
2157
+ widthDivisor: 1,
2158
+ heightDivisor: 1
2159
+ }), a;
2160
+ };
2161
+ switch (e) {
2162
+ case "I420": return n(1, 1, 2, 2, !1);
2163
+ case "I420P10":
2164
+ case "I420P12": return n(2, 2, 2, 2, !1);
2165
+ case "I420A": return n(1, 1, 2, 2, !0);
2166
+ case "I420AP10":
2167
+ case "I420AP12": return n(2, 2, 2, 2, !0);
2168
+ case "I422": return n(1, 1, 2, 1, !1);
2169
+ case "I422P10":
2170
+ case "I422P12": return n(2, 2, 2, 1, !1);
2171
+ case "I422A": return n(1, 1, 2, 1, !0);
2172
+ case "I422AP10":
2173
+ case "I422AP12": return n(2, 2, 2, 1, !0);
2174
+ case "I444": return n(1, 1, 1, 1, !1);
2175
+ case "I444P10":
2176
+ case "I444P12": return n(2, 2, 1, 1, !1);
2177
+ case "I444A": return n(1, 1, 1, 1, !0);
2178
+ case "I444AP10":
2179
+ case "I444AP12": return n(2, 2, 1, 1, !0);
2180
+ case "NV12": return [{
2181
+ sampleBytes: 1,
2182
+ widthDivisor: 1,
2183
+ heightDivisor: 1
2184
+ }, {
2185
+ sampleBytes: 2,
2186
+ widthDivisor: 2,
2187
+ heightDivisor: 2
2188
+ }];
2189
+ case "RGBA":
2190
+ case "RGBX":
2191
+ case "BGRA":
2192
+ case "BGRX": return [{
2193
+ sampleBytes: 4,
2194
+ widthDivisor: 1,
2195
+ heightDivisor: 1
2196
+ }];
2197
+ default: _(e), t(!1);
2198
+ }
2199
+ }, It = (e, t) => {
2200
+ let n = {
2201
+ left: 0,
2202
+ top: 0,
2203
+ width: e.codedWidth,
2204
+ height: e.codedHeight
2205
+ }, r = t.rect, i = Lt(n, r, e.codedWidth, e.codedHeight, e.format), a = t.layout, o;
2206
+ if (!t.format || t.format === e.format) o = e.format;
2207
+ else if ([
2208
+ "RGBA",
2209
+ "RGBX",
2210
+ "BGRA",
2211
+ "BGRX"
2212
+ ].includes(t.format)) o = t.format;
2213
+ else throw Error("NotSupportedError: Invalid destination format.");
2214
+ return zt(i, o, a);
2215
+ }, Lt = (e, t, n, r, i) => {
2216
+ let a = { ...e };
2217
+ if (t !== void 0) {
2218
+ if (t.width === 0 || t.height === 0) throw TypeError("visibleRect dimensions cannot be zero.");
2219
+ if ((t.x || 0) + (t.width || 0) > n) throw TypeError("visibleRect exceeds codedWidth.");
2220
+ if ((t.y || 0) + (t.height || 0) > r) throw TypeError("visibleRect exceeds codedHeight.");
2221
+ a.x = t.x || 0, a.y = t.y || 0, a.width = t.width || 0, a.height = t.height || 0;
2222
+ }
2223
+ if (!Rt(i, a)) throw TypeError("visibleRect alignment is invalid for the format.");
2224
+ return a;
2225
+ }, Rt = (e, t) => {
2226
+ if (e === null) return !0;
2227
+ let n = X(e);
2228
+ for (let e = 0; e < n.length; e++) {
2229
+ let r = n[e], i = r.widthDivisor, a = r.heightDivisor;
2230
+ if ((t.x || 0) % i !== 0 || (t.y || 0) % a !== 0) return !1;
2231
+ }
2232
+ return !0;
2233
+ }, zt = (e, t, n) => {
2234
+ let r = X(t), i = r.length;
2235
+ if (n !== void 0 && n.length !== i) throw TypeError(`Layout must have ${i} planes.`);
2236
+ let a = 0, o = [], s = [];
2237
+ for (let t = 0; t < i; t++) {
2238
+ let i = r[t], c = i.sampleBytes, l = i.widthDivisor, u = i.heightDivisor, d = {
2239
+ destinationOffset: 0,
2240
+ destinationStride: 0,
2241
+ sourceTop: 0,
2242
+ sourceHeight: 0,
2243
+ sourceLeftBytes: 0,
2244
+ sourceWidthBytes: 0
2245
+ };
2246
+ if (d.sourceTop = Math.ceil(Math.trunc(e.y || 0) / u), d.sourceHeight = Math.ceil(Math.trunc(e.height || 0) / u), d.sourceLeftBytes = Math.floor(Math.trunc(e.x || 0) / l) * c, d.sourceWidthBytes = Math.floor(Math.trunc(e.width || 0) / l) * c, n !== void 0) {
2247
+ let e = n[t];
2248
+ if (e.stride < d.sourceWidthBytes) throw TypeError(`Stride for plane ${t} is too small.`);
2249
+ d.destinationOffset = e.offset, d.destinationStride = e.stride;
2250
+ } else d.destinationOffset = a, d.destinationStride = d.sourceWidthBytes;
2251
+ let f = d.destinationStride * d.sourceHeight + d.destinationOffset;
2252
+ if (f > 4294967295) throw TypeError("Allocation size exceeds limit.");
2253
+ s.push(f), a = Math.max(a, f);
2254
+ for (let e = 0; e < t; e++) {
2255
+ let n = o[e];
2256
+ if (!(s[t] <= n.destinationOffset || s[e] <= d.destinationOffset)) throw TypeError("Planes overlap.");
2257
+ }
2258
+ o.push(d);
2259
+ }
2260
+ return {
2261
+ allocationSize: a,
2262
+ computedLayouts: o
2263
+ };
2264
+ }, Bt = (e) => {
2265
+ if (!e || typeof e != "object") throw TypeError("Encoding config must be an object.");
2266
+ if (!N.includes(e.codec)) throw TypeError(`Invalid video codec '${e.codec}'. Must be one of: ${N.join(", ")}.`);
2267
+ let t = e.bitrate;
2268
+ if (e.quality === void 0 && t === void 0) throw TypeError("config.quality must be provided.");
2269
+ if (e.quality !== void 0 && t !== void 0) throw TypeError("config.quality and config.bitrate cannot both be provided.");
2270
+ if (e.quality !== void 0 && !(e.quality instanceof Z)) throw TypeError("config.quality, when provided, must be a Quality.");
2271
+ if (t !== void 0 && !(t instanceof Z) && (!Number.isInteger(t) || t <= 0)) throw TypeError("config.bitrate, when provided, must be a positive integer or a quality.");
2272
+ if (e.keyFrameInterval !== void 0 && (!Number.isFinite(e.keyFrameInterval) || e.keyFrameInterval < 0)) throw TypeError("config.keyFrameInterval, when provided, must be a non-negative number.");
2273
+ if (e.sizeChangeBehavior !== void 0 && ![
2274
+ "deny",
2275
+ "passThrough",
2276
+ "fill",
2277
+ "contain",
2278
+ "cover"
2279
+ ].includes(e.sizeChangeBehavior)) throw TypeError("config.sizeChangeBehavior, when provided, must be 'deny', 'passThrough', 'fill', 'contain' or 'cover'.");
2280
+ if (e.transform !== void 0) {
2281
+ if (typeof e.transform != "object" || !e.transform) throw TypeError("config.transform, when provided, must be an object.");
2282
+ if (e.transform.width !== void 0 && (!Number.isInteger(e.transform.width) || e.transform.width <= 0)) throw TypeError("config.transform.width, when provided, must be a positive integer.");
2283
+ if (e.transform.height !== void 0 && (!Number.isInteger(e.transform.height) || e.transform.height <= 0)) throw TypeError("config.transform.height, when provided, must be a positive integer.");
2284
+ if (e.transform.fit !== void 0 && ![
2285
+ "fill",
2286
+ "contain",
2287
+ "cover"
2288
+ ].includes(e.transform.fit)) throw TypeError("config.transform.fit, when provided, must be one of \"fill\", \"contain\", or \"cover\".");
2289
+ if (e.transform.width !== void 0 && e.transform.height !== void 0 && e.transform.fit === void 0 && ![
2290
+ "fill",
2291
+ "contain",
2292
+ "cover"
2293
+ ].includes(e.sizeChangeBehavior)) throw TypeError("When both config.transform.width and config.transform.height are provided, config.transform.fit must also be provided.");
2294
+ if (e.transform.fit !== void 0 && [
2295
+ "fill",
2296
+ "contain",
2297
+ "cover"
2298
+ ].includes(e.sizeChangeBehavior) && e.transform.fit !== e.sizeChangeBehavior) throw TypeError("config.transform.fit, when provided, cannot differ from config.sizeChangeBehavior when config.sizeChangeBehavior is 'fill', 'contain' or 'cover', as sizeChangeBehavior already determines the fitting algorithm.");
2299
+ if (e.transform.rotate !== void 0 && ![
2300
+ 0,
2301
+ 90,
2302
+ 180,
2303
+ 270
2304
+ ].includes(e.transform.rotate)) throw TypeError("config.transform.rotate, when provided, must be 0, 90, 180 or 270.");
2305
+ if (e.transform.crop !== void 0 && Nt(e.transform.crop, "config.transform."), e.transform.process !== void 0 && typeof e.transform.process != "function") throw TypeError("config.transform.process, when provided, must be a function.");
2306
+ if (e.transform.frameRate !== void 0 && (!Number.isFinite(e.transform.frameRate) || e.transform.frameRate <= 0)) throw TypeError("config.transform.frameRate, when provided, must be a finite positive number.");
2307
+ if (e.transform.force !== void 0 && typeof e.transform.force != "boolean") throw TypeError("config.transform.force, when provided, must be a boolean.");
2308
+ }
2309
+ if (e.onEncodedPacket !== void 0 && typeof e.onEncodedPacket != "function") throw TypeError("config.onEncodedPacket, when provided, must be a function.");
2310
+ if (e.onEncoderConfig !== void 0 && typeof e.onEncoderConfig != "function") throw TypeError("config.onEncoderConfig, when provided, must be a function.");
2311
+ if (e.onEncodedSample !== void 0 && typeof e.onEncodedSample != "function") throw TypeError("config.onEncodedSample, when provided, must be a function.");
2312
+ Vt(e.codec, e);
2313
+ }, Vt = (e, t) => {
2314
+ if (!t || typeof t != "object") throw TypeError("Encoding options must be an object.");
2315
+ if (t.alpha !== void 0 && !["discard", "keep"].includes(t.alpha)) throw TypeError("options.alpha, when provided, must be 'discard' or 'keep'.");
2316
+ let n = t.bitrateMode;
2317
+ if (n !== void 0 && !["constant", "variable"].includes(n)) throw TypeError("bitrateMode, when provided, must be 'constant' or 'variable'.");
2318
+ if (t.latencyMode !== void 0 && !["quality", "realtime"].includes(t.latencyMode)) throw TypeError("latencyMode, when provided, must be 'quality' or 'realtime'.");
2319
+ if (t.fullCodecString !== void 0 && typeof t.fullCodecString != "string") throw TypeError("fullCodecString, when provided, must be a string.");
2320
+ if (t.fullCodecString !== void 0 && z(t.fullCodecString) !== e) throw TypeError(`fullCodecString, when provided, must be a string that matches the specified codec (${e}).`);
2321
+ if (t.hardwareAcceleration !== void 0 && ![
2322
+ "no-preference",
2323
+ "prefer-hardware",
2324
+ "prefer-software"
2325
+ ].includes(t.hardwareAcceleration)) throw TypeError("hardwareAcceleration, when provided, must be 'no-preference', 'prefer-hardware' or 'prefer-software'.");
2326
+ if (t.scalabilityMode !== void 0 && typeof t.scalabilityMode != "string") throw TypeError("scalabilityMode, when provided, must be a string.");
2327
+ if (t.contentHint !== void 0 && typeof t.contentHint != "string") throw TypeError("contentHint, when provided, must be a string.");
2328
+ }, Ht = (e) => {
2329
+ let n = e.bitrateMode, r = e.quality._toVideoRateControl(e.codec, e.width, e.height, n), i = (t, n, r) => ({
2330
+ codec: e.fullCodecString ?? qe(e.codec, e.width, e.height, r, e.alpha === "keep"),
2331
+ width: e.width,
2332
+ height: e.height,
2333
+ displayWidth: e.squarePixelWidth,
2334
+ displayHeight: e.squarePixelHeight,
2335
+ bitrate: t,
2336
+ bitrateMode: n,
2337
+ alpha: e.alpha ?? "discard",
2338
+ framerate: e.framerate,
2339
+ latencyMode: e.latencyMode,
2340
+ hardwareAcceleration: e.hardwareAcceleration,
2341
+ scalabilityMode: e.scalabilityMode,
2342
+ contentHint: e.contentHint,
2343
+ ...$e(e.codec)
2344
+ }), a = [];
2345
+ return r.quantizer !== null && a.push({
2346
+ config: i(void 0, "quantizer", r.bitrate),
2347
+ quantizer: r.quantizer
2348
+ }), r.bitrateMode !== "quantizer" && a.push({
2349
+ config: i(r.bitrate, r.bitrateMode, r.bitrate),
2350
+ quantizer: null
2351
+ }), t(a.length > 0), a;
2352
+ }, Z = class {
2353
+ constructor(e) {
2354
+ if ((typeof e == "number" || typeof e == "string") && (e = { quality: e }), !e || typeof e != "object") throw TypeError("options must be an object.");
2355
+ if (e.bitrateMode !== void 0 && !["constant", "variable"].includes(e.bitrateMode)) throw TypeError("options.bitrateMode, when provided, must be 'constant' or 'variable'.");
2356
+ if ("quality" in e) {
2357
+ if (typeof e.quality == "string" ? !(e.quality in Ut) : typeof e.quality != "number" || Number.isNaN(e.quality)) throw TypeError("options.quality must be a number, or one of 'very-low', 'low', 'medium', 'high' or 'very-high'.");
2358
+ if (e.preferBitrate !== void 0 && typeof e.preferBitrate != "boolean") throw TypeError("options.preferBitrate, when provided, must be a boolean.");
2359
+ if ("bitrate" in e || "quantizer" in e) throw TypeError("options.quality cannot be combined with options.bitrate or options.quantizer.");
2360
+ this._quality = typeof e.quality == "string" ? Ut[e.quality] : e.quality, this._preferBitrate = e.preferBitrate ?? !1, this._bitrate = void 0, this._quantizer = void 0;
2361
+ } else {
2362
+ if (e.bitrate !== void 0 && (!Number.isInteger(e.bitrate) || e.bitrate <= 0)) throw TypeError("options.bitrate, when provided, must be a positive integer.");
2363
+ if (e.quantizer !== void 0 && (!Number.isInteger(e.quantizer) || e.quantizer < 0)) throw TypeError("options.quantizer, when provided, must be a non-negative integer.");
2364
+ if (e.bitrate === void 0 && e.quantizer === void 0) throw TypeError("At least one of options.bitrate or options.quantizer must be set.");
2365
+ if ("preferBitrate" in e) throw TypeError("options.preferBitrate can only be combined with options.quality.");
2366
+ this._quality = void 0, this._preferBitrate = !1, this._bitrate = e.bitrate, this._quantizer = e.quantizer;
2367
+ }
2368
+ this._bitrateMode = e.bitrateMode;
2369
+ }
2370
+ _toVideoRateControl(e, n, r, i) {
2371
+ let a = Wt[e], o = null, s = this._bitrateMode ?? i ?? "variable";
2372
+ if (this._quantizer !== void 0) if (!a) {
2373
+ if (this._bitrate === void 0) throw Error(`Codec '${e}' does not support quantizer-based encoding. Provide a bitrate in the Quality to define a fallback.`);
2374
+ } else if (this._quantizer < a.min || this._quantizer > a.max) {
2375
+ if (this._bitrate === void 0) throw Error(`Quantizer ${this._quantizer} is out of range for codec '${e}'; must be between ${a.min} and ${a.max}.`);
2376
+ } else o = this._quantizer, this._bitrate === void 0 && (s = "quantizer");
2377
+ else this._bitrate === void 0 && a && !this._preferBitrate && (t(this._quality !== void 0), o = y(Math.round(b(a.worst, a.best, this._quality)), a.min, a.max));
2378
+ let c;
2379
+ if (this._bitrate !== void 0) c = this._bitrate;
2380
+ else {
2381
+ let i = this._quality;
2382
+ i === void 0 && (t(o !== null && a), i = y((o - a.worst) / (a.best - a.worst), 0, 1)), c = Kt(e, n, r, Gt(i));
2383
+ }
2384
+ return {
2385
+ quantizer: o,
2386
+ bitrate: c,
2387
+ bitrateMode: s
2388
+ };
2389
+ }
2390
+ _toVideoBitrate(e, n, r) {
2391
+ return this._bitrate === void 0 ? (t(this._quality !== void 0), Kt(e, n, r, Gt(this._quality))) : this._bitrate;
2392
+ }
2393
+ _toAudioBitrate(e) {
2394
+ if (P.includes(e) || e === "flac") return;
2395
+ if (this._bitrate !== void 0) return this._bitrate;
2396
+ if (this._quality === void 0) throw Error("This Quality defines neither a quality level nor a bitrate and therefore cannot be used for audio encoding.");
2397
+ let t = Gt(this._quality), n = {
2398
+ aac: 128e3,
2399
+ opus: 64e3,
2400
+ mp3: 16e4,
2401
+ vorbis: 64e3,
2402
+ ac3: 384e3,
2403
+ eac3: 192e3,
2404
+ dts: 768e3
2405
+ }[e];
2406
+ if (!n) throw Error(`Unhandled codec: ${e}`);
2407
+ let r = n * t;
2408
+ return e === "aac" ? r = [
2409
+ 96e3,
2410
+ 128e3,
2411
+ 16e4,
2412
+ 192e3
2413
+ ].reduce((e, t) => Math.abs(t - r) < Math.abs(e - r) ? t : e) : e === "opus" || e === "vorbis" ? r = Math.max(6e3, r) : e === "mp3" && (r = [
2414
+ 8e3,
2415
+ 16e3,
2416
+ 24e3,
2417
+ 32e3,
2418
+ 4e4,
2419
+ 48e3,
2420
+ 64e3,
2421
+ 8e4,
2422
+ 96e3,
2423
+ 112e3,
2424
+ 128e3,
2425
+ 16e4,
2426
+ 192e3,
2427
+ 224e3,
2428
+ 256e3,
2429
+ 32e4
2430
+ ].reduce((e, t) => Math.abs(t - r) < Math.abs(e - r) ? t : e)), Math.round(r / 1e3) * 1e3;
2431
+ }
2432
+ }, Ut = {
2433
+ "very-low": 0,
2434
+ low: .25,
2435
+ medium: .5,
2436
+ high: .75,
2437
+ "very-high": 1
2438
+ }, Wt = {
2439
+ avc: {
2440
+ min: 0,
2441
+ max: 51,
2442
+ worst: 41,
2443
+ best: 16
2444
+ },
2445
+ hevc: {
2446
+ min: 0,
2447
+ max: 51,
2448
+ worst: 41,
2449
+ best: 16
2450
+ },
2451
+ vp9: {
2452
+ min: 0,
2453
+ max: 63,
2454
+ worst: 52,
2455
+ best: 20
2456
+ },
2457
+ av1: {
2458
+ min: 0,
2459
+ max: 255,
2460
+ worst: 208,
2461
+ best: 80
2462
+ }
2463
+ }, Gt = (e) => .3 * Math.exp(2.5538 * e), Kt = (e, t, n, r) => {
2464
+ let i = t * n, a = 3e6, o = a * (i / 2073600) ** .95 * {
2465
+ avc: 1,
2466
+ hevc: .6,
2467
+ vp9: .6,
2468
+ av1: .4,
2469
+ vp8: 1.2,
2470
+ prores: 22e7 / a
2471
+ }[e] * r;
2472
+ return Math.ceil(o / 1e3) * 1e3;
2473
+ }, qt = (e, n) => {
2474
+ if (e === "avc") return { avc: { quantizer: n } };
2475
+ if (e === "hevc") return { hevc: { quantizer: n } };
2476
+ if (e === "vp9") return { vp9: { quantizer: n } };
2477
+ if (e === "av1") return { av1: { quantizer: n } };
2478
+ t(!1);
2479
+ }, Jt = (e, t) => {
2480
+ if (e !== void 0) return e;
2481
+ if (t !== void 0) return t instanceof Z ? t : new Z({ bitrate: t });
2482
+ }, Yt = [], Xt = class e {
2483
+ constructor(e, t, n, r, i) {
2484
+ this.bytes = e, this.view = t, this.offset = n, this.start = r, this.end = i, this.bufferPos = r - n;
2485
+ }
2486
+ static tempFromBytes(t) {
2487
+ return new e(t, s(t), 0, 0, t.length);
2488
+ }
2489
+ get length() {
2490
+ return this.end - this.start;
2491
+ }
2492
+ get filePos() {
2493
+ return this.offset + this.bufferPos;
2494
+ }
2495
+ set filePos(e) {
2496
+ this.bufferPos = e - this.offset;
2497
+ }
2498
+ get remainingLength() {
2499
+ return Math.max(this.end - this.filePos, 0);
2500
+ }
2501
+ skip(e) {
2502
+ this.bufferPos += e;
2503
+ }
2504
+ slice(t, n = this.end - t) {
2505
+ if (t < this.start || t + n > this.end) throw RangeError("Slicing outside of original slice.");
2506
+ return new e(this.bytes, this.view, this.offset, t, t + n);
2507
+ }
2508
+ }, Zt = (e, t) => {
2509
+ if (e.filePos < e.start || e.filePos + t > e.end) throw RangeError(`Tried reading [${e.filePos}, ${e.filePos + t}), but slice is [${e.start}, ${e.end}). This is likely an internal error, please report it alongside the file that caused it.`);
2510
+ }, Qt = (e, t) => {
2511
+ Zt(e, t);
2512
+ let n = e.bytes.subarray(e.bufferPos, e.bufferPos + t);
2513
+ return e.bufferPos += t, n;
2514
+ }, $t = class {
2515
+ constructor(e) {
2516
+ this.mutex = new m(), this.trackTimestampInfo = /* @__PURE__ */ new WeakMap(), this.output = e;
2517
+ }
2518
+ onTrackClose(e) {}
2519
+ validateTimestamp(e, t, n) {
2520
+ if (t < 0) throw Error(`Timestamps must be non-negative (got ${t}s).`);
2521
+ let r = this.trackTimestampInfo.get(e);
2522
+ if (r) {
2523
+ if (n && (r.maxTimestampBeforeLastKeyPacket = r.maxTimestamp), r.maxTimestampBeforeLastKeyPacket !== null && t < r.maxTimestampBeforeLastKeyPacket) throw Error(`Timestamps cannot be smaller than the largest timestamp of the previous GOP (a GOP begins with a key packet and ends right before the next key packet). Got ${t}s, but largest timestamp is ${r.maxTimestampBeforeLastKeyPacket}s.`);
2524
+ r.maxTimestamp = Math.max(r.maxTimestamp, t);
2525
+ } else {
2526
+ if (!n) throw Error("First packet must be a key packet.");
2527
+ r = {
2528
+ maxTimestamp: t,
2529
+ maxTimestampBeforeLastKeyPacket: null
2530
+ }, this.trackTimestampInfo.set(e, r);
2531
+ }
2532
+ }
2533
+ }, en = /<(?:(\d{2}):)?(\d{2}):(\d{2}).(\d{3})>/g, tn = /(?:(\d{2}):)?(\d{2}):(\d{2}).(\d{3})/, nn = (e) => {
2534
+ let t = tn.exec(e);
2535
+ if (!t) throw Error("Expected match.");
2536
+ return 3600 * 1e3 * Number(t[1] || "0") + 60 * 1e3 * Number(t[2]) + 1e3 * Number(t[3]) + Number(t[4]);
2537
+ }, rn = (e) => {
2538
+ let t = Math.floor(e / (3600 * 1e3)), n = Math.floor(e % (3600 * 1e3) / (60 * 1e3)), r = Math.floor(e % (60 * 1e3) / 1e3), i = e % 1e3;
2539
+ return t.toString().padStart(2, "0") + ":" + n.toString().padStart(2, "0") + ":" + r.toString().padStart(2, "0") + "." + i.toString().padStart(3, "0");
2540
+ };
2541
+ e();
2542
+ var an = class {
2543
+ constructor(e, t) {
2544
+ if (this.finalized = !1, this.started = !1, this.pos = 0, this.trackedWrites = null, this.trackedStart = -1, this.trackedEnd = -1, e._writerAcquired) throw Error("Can't have multiple Writers for the same Target.");
2545
+ this.target = e, e._setMonotonicity(t), e._writerAcquired = !0;
2546
+ }
2547
+ start() {
2548
+ t(!this.started), this.target._start(), this.started = !0;
2549
+ }
2550
+ write(e) {
2551
+ t(this.started && !this.finalized), this.maybeTrackWrites(e), this.target._write(e, this.pos), this.pos += e.byteLength;
2552
+ }
2553
+ seek(e) {
2554
+ this.pos = e;
2555
+ }
2556
+ getPos() {
2557
+ return this.pos;
2558
+ }
2559
+ async flush() {
2560
+ return t(this.started && !this.finalized), this.target._flush();
2561
+ }
2562
+ async finalize() {
2563
+ t(this.started && !this.finalized), await this.target._finalize(), this.finalized = !0;
2564
+ }
2565
+ maybeTrackWrites(e) {
2566
+ if (!this.trackedWrites) return;
2567
+ let t = this.getPos();
2568
+ if (t < this.trackedStart) {
2569
+ if (t + e.byteLength <= this.trackedStart) return;
2570
+ e = e.subarray(this.trackedStart - t), t = 0;
2571
+ }
2572
+ let n = t + e.byteLength - this.trackedStart, r = this.trackedWrites.byteLength;
2573
+ for (; r < n;) r *= 2;
2574
+ if (r !== this.trackedWrites.byteLength) {
2575
+ let e = new Uint8Array(r);
2576
+ e.set(this.trackedWrites, 0), this.trackedWrites = e;
2577
+ }
2578
+ this.trackedWrites.set(e, t - this.trackedStart), this.trackedEnd = Math.max(this.trackedEnd, t + e.byteLength);
2579
+ }
2580
+ startTrackingWrites() {
2581
+ this.trackedWrites = new Uint8Array(2 ** 10), this.trackedStart = this.getPos(), this.trackedEnd = this.trackedStart;
2582
+ }
2583
+ stopTrackingWrites() {
2584
+ if (!this.trackedWrites) throw Error("Internal error: Can't get tracked writes since nothing was tracked.");
2585
+ let e = {
2586
+ data: this.trackedWrites.subarray(0, this.trackedEnd - this.trackedStart),
2587
+ start: this.trackedStart,
2588
+ end: this.trackedEnd
2589
+ };
2590
+ return this.trackedWrites = null, e;
2591
+ }
2592
+ }, Q = class extends O {
2593
+ constructor() {
2594
+ super(...arguments), this._writerAcquired = !1, this._monotonicity = null, this.onwrite = null;
2595
+ }
2596
+ _setMonotonicity(e) {
2597
+ this._monotonicity !== !1 && (this._monotonicity = e);
2598
+ }
2599
+ _dispatchWrite(e, t) {
2600
+ this.onwrite?.(e, t), this._emit("write", {
2601
+ start: e,
2602
+ end: t
2603
+ });
2604
+ }
2605
+ slice(e) {
2606
+ if (!Number.isInteger(e) || e < 0) throw TypeError("offset must be a non-negative integer.");
2607
+ return new ln(this, e);
2608
+ }
2609
+ }, on = 2 ** 16, sn = 2 ** 32, cn = class extends Q {
2610
+ constructor(e = {}) {
2611
+ if (super(), this.buffer = null, this._maxPos = 0, !e || typeof e != "object") throw TypeError("BufferTarget options, when provided, must be an object.");
2612
+ if (e.onFinalize !== void 0 && typeof e.onFinalize != "function") throw TypeError("options.onFinalize, when provided, must be a function.");
2613
+ if (this._options = e, this._supportsResize = "resize" in /* @__PURE__ */ new ArrayBuffer(0), this._supportsResize) try {
2614
+ this._buffer = new ArrayBuffer(on, { maxByteLength: sn });
2615
+ } catch {
2616
+ this._buffer = new ArrayBuffer(on), this._supportsResize = !1;
2617
+ }
2618
+ else this._buffer = new ArrayBuffer(on);
2619
+ this._bytes = new Uint8Array(this._buffer);
2620
+ }
2621
+ _ensureSize(e) {
2622
+ let t = this._buffer.byteLength;
2623
+ for (; t < e;) t *= 2;
2624
+ if (t !== this._buffer.byteLength) {
2625
+ if (t > sn) throw Error(`ArrayBuffer exceeded maximum size of ${sn} bytes. Please consider using another target.`);
2626
+ if (this._supportsResize) this._buffer.resize(t);
2627
+ else {
2628
+ let e = new ArrayBuffer(t), n = new Uint8Array(e);
2629
+ n.set(this._bytes, 0), this._buffer = e, this._bytes = n;
2630
+ }
2631
+ }
2632
+ }
2633
+ _start() {}
2634
+ _write(e, t) {
2635
+ this._ensureSize(t + e.byteLength), this._bytes.set(e, t), this._maxPos = Math.max(this._maxPos, t + e.byteLength), this._dispatchWrite(t, t + e.byteLength);
2636
+ }
2637
+ async _flush() {}
2638
+ async _finalize() {
2639
+ this.buffer = this._buffer.slice(0, this._maxPos), this._options.onFinalize && await this._options.onFinalize(this.buffer), this._emit("finalized");
2640
+ }
2641
+ async _close() {}
2642
+ _getSlice(e, t) {
2643
+ return this._bytes.slice(e, t);
2644
+ }
2645
+ }, ln = class extends Q {
2646
+ constructor(e, t) {
2647
+ super(), this._baseTarget = e, this._offset = t;
2648
+ }
2649
+ _start() {}
2650
+ _write(e, t) {
2651
+ this._baseTarget._write(e, this._offset + t), this._dispatchWrite(t, t + e.byteLength);
2652
+ }
2653
+ _flush() {
2654
+ return this._baseTarget._flush();
2655
+ }
2656
+ async _finalize() {
2657
+ this._emit("finalized");
2658
+ }
2659
+ async _close() {}
2660
+ _setMonotonicity(e) {
2661
+ super._setMonotonicity(e), this._baseTarget._setMonotonicity(e);
2662
+ }
2663
+ }, un = class {
2664
+ constructor(e, t) {
2665
+ if (this.rootPath = e, this.getTarget = t, typeof e != "string") throw TypeError("rootPath must be a string.");
2666
+ if (typeof t != "function") throw TypeError("getTarget must be a function.");
2667
+ }
2668
+ }, dn = -(2 ** 15), fn = 2 ** 15 - 1, pn = "Mediabunny", mn = 6, hn = 5, gn = {
2669
+ video: 1,
2670
+ audio: 2,
2671
+ subtitle: 17
2672
+ }, _n = class extends $t {
2673
+ constructor(e, t) {
2674
+ super(e), this.trackDatas = [], this.allTracksKnown = g(), this.segment = null, this.segmentInfo = null, this.seekHead = null, this.tracksElement = null, this.tagsElement = null, this.attachmentsElement = null, this.segmentDuration = null, this.cues = null, this.currentCluster = null, this.currentClusterStartMsTimestamp = null, this.currentClusterMaxMsTimestamp = null, this.trackDatasInCurrentCluster = /* @__PURE__ */ new Map(), this.startTimestamp = Infinity, this.endTimestamp = -Infinity, this.format = t;
2675
+ }
2676
+ async start() {
2677
+ let e = await this.mutex.acquire();
2678
+ this.writer = await this.output._getRootWriter(!!this.format._options.appendOnly), this.ebmlWriter = new _t(this.writer), this.writeEBMLHeader(), this.createSegmentInfo(), this.createCues(), await this.writer.flush();
2679
+ for (let e of this.output.tracks) e.isVideoTrack() && e.metadata.decoderConfig ? this.getVideoTrackData(e, e.metadata.primingPacket ?? null, { decoderConfig: e.metadata.decoderConfig }) : e.isAudioTrack() && e.metadata.decoderConfig && this.getAudioTrackData(e, e.metadata.primingPacket ?? null, { decoderConfig: e.metadata.decoderConfig });
2680
+ e();
2681
+ }
2682
+ writeEBMLHeader() {
2683
+ this.format._options.onEbmlHeader && this.writer.startTrackingWrites();
2684
+ let e = {
2685
+ id: W.EBML,
2686
+ data: [
2687
+ {
2688
+ id: W.EBMLVersion,
2689
+ data: 1
2690
+ },
2691
+ {
2692
+ id: W.EBMLReadVersion,
2693
+ data: 1
2694
+ },
2695
+ {
2696
+ id: W.EBMLMaxIDLength,
2697
+ data: 4
2698
+ },
2699
+ {
2700
+ id: W.EBMLMaxSizeLength,
2701
+ data: 8
2702
+ },
2703
+ {
2704
+ id: W.DocType,
2705
+ data: this.format instanceof Mn ? "webm" : "matroska"
2706
+ },
2707
+ {
2708
+ id: W.DocTypeVersion,
2709
+ data: 2
2710
+ },
2711
+ {
2712
+ id: W.DocTypeReadVersion,
2713
+ data: 2
2714
+ }
2715
+ ]
2716
+ };
2717
+ if (this.ebmlWriter.writeEBML(e), this.format._options.onEbmlHeader) {
2718
+ let { data: e, start: t } = this.writer.stopTrackingWrites();
2719
+ this.format._options.onEbmlHeader(e, t);
2720
+ }
2721
+ }
2722
+ maybeCreateSeekHead(e) {
2723
+ if (this.format._options.appendOnly) return;
2724
+ let t = new Uint8Array([
2725
+ 28,
2726
+ 83,
2727
+ 187,
2728
+ 107
2729
+ ]), n = new Uint8Array([
2730
+ 21,
2731
+ 73,
2732
+ 169,
2733
+ 102
2734
+ ]), r = new Uint8Array([
2735
+ 22,
2736
+ 84,
2737
+ 174,
2738
+ 107
2739
+ ]), i = new Uint8Array([
2740
+ 25,
2741
+ 65,
2742
+ 164,
2743
+ 105
2744
+ ]), a = new Uint8Array([
2745
+ 18,
2746
+ 84,
2747
+ 195,
2748
+ 103
2749
+ ]), o = {
2750
+ id: W.SeekHead,
2751
+ data: [
2752
+ {
2753
+ id: W.Seek,
2754
+ data: [{
2755
+ id: W.SeekID,
2756
+ data: t
2757
+ }, {
2758
+ id: W.SeekPosition,
2759
+ size: 5,
2760
+ data: e ? this.ebmlWriter.offsets.get(this.cues) - this.segmentDataOffset : 0
2761
+ }]
2762
+ },
2763
+ {
2764
+ id: W.Seek,
2765
+ data: [{
2766
+ id: W.SeekID,
2767
+ data: n
2768
+ }, {
2769
+ id: W.SeekPosition,
2770
+ size: 5,
2771
+ data: e ? this.ebmlWriter.offsets.get(this.segmentInfo) - this.segmentDataOffset : 0
2772
+ }]
2773
+ },
2774
+ {
2775
+ id: W.Seek,
2776
+ data: [{
2777
+ id: W.SeekID,
2778
+ data: r
2779
+ }, {
2780
+ id: W.SeekPosition,
2781
+ size: 5,
2782
+ data: e ? this.ebmlWriter.offsets.get(this.tracksElement) - this.segmentDataOffset : 0
2783
+ }]
2784
+ },
2785
+ this.attachmentsElement ? {
2786
+ id: W.Seek,
2787
+ data: [{
2788
+ id: W.SeekID,
2789
+ data: i
2790
+ }, {
2791
+ id: W.SeekPosition,
2792
+ size: 5,
2793
+ data: e ? this.ebmlWriter.offsets.get(this.attachmentsElement) - this.segmentDataOffset : 0
2794
+ }]
2795
+ } : null,
2796
+ this.tagsElement ? {
2797
+ id: W.Seek,
2798
+ data: [{
2799
+ id: W.SeekID,
2800
+ data: a
2801
+ }, {
2802
+ id: W.SeekPosition,
2803
+ size: 5,
2804
+ data: e ? this.ebmlWriter.offsets.get(this.tagsElement) - this.segmentDataOffset : 0
2805
+ }]
2806
+ } : null
2807
+ ]
2808
+ };
2809
+ this.seekHead = o;
2810
+ }
2811
+ createSegmentInfo() {
2812
+ let e = {
2813
+ id: W.Duration,
2814
+ data: new H(0)
2815
+ };
2816
+ this.segmentDuration = e;
2817
+ let t = {
2818
+ id: W.Info,
2819
+ data: [
2820
+ {
2821
+ id: W.TimestampScale,
2822
+ data: 1e6
2823
+ },
2824
+ {
2825
+ id: W.MuxingApp,
2826
+ data: pn
2827
+ },
2828
+ {
2829
+ id: W.WritingApp,
2830
+ data: pn
2831
+ },
2832
+ this.format._options.appendOnly ? null : e
2833
+ ]
2834
+ };
2835
+ this.segmentInfo = t;
2836
+ }
2837
+ createTracks() {
2838
+ let e = {
2839
+ id: W.Tracks,
2840
+ data: []
2841
+ };
2842
+ this.tracksElement = e;
2843
+ for (let n of this.trackDatas) {
2844
+ let r = vt[n.track.source._codec];
2845
+ t(r), n.type === "audio" && n.track.source._codec === "dts" && (n.info.decoderConfig.codec === "dtse" ? r = "A_DTS/EXPRESS" : n.info.decoderConfig.codec === "dtsl" && (r = "A_DTS/LOSSLESS"));
2846
+ let i = 0;
2847
+ if (n.type === "audio" && n.track.source._codec === "opus") {
2848
+ i = 1e6 * 80;
2849
+ let e = n.info.decoderConfig.description;
2850
+ if (e) {
2851
+ let t = Re(o(e));
2852
+ i = Math.round(1e9 * (t.preSkip / Xe));
2853
+ }
2854
+ }
2855
+ e.data.push({
2856
+ id: W.TrackEntry,
2857
+ data: [
2858
+ {
2859
+ id: W.TrackNumber,
2860
+ data: n.track.id
2861
+ },
2862
+ {
2863
+ id: W.TrackUID,
2864
+ data: n.track.id
2865
+ },
2866
+ {
2867
+ id: W.TrackType,
2868
+ data: gn[n.type]
2869
+ },
2870
+ n.track.metadata.disposition?.default === !1 ? {
2871
+ id: W.FlagDefault,
2872
+ data: 0
2873
+ } : null,
2874
+ n.track.metadata.disposition?.forced ? {
2875
+ id: W.FlagForced,
2876
+ data: 1
2877
+ } : null,
2878
+ n.track.metadata.disposition?.hearingImpaired ? {
2879
+ id: W.FlagHearingImpaired,
2880
+ data: 1
2881
+ } : null,
2882
+ n.track.metadata.disposition?.visuallyImpaired ? {
2883
+ id: W.FlagVisualImpaired,
2884
+ data: 1
2885
+ } : null,
2886
+ n.track.metadata.disposition?.original ? {
2887
+ id: W.FlagOriginal,
2888
+ data: 1
2889
+ } : null,
2890
+ n.track.metadata.disposition?.commentary ? {
2891
+ id: W.FlagCommentary,
2892
+ data: 1
2893
+ } : null,
2894
+ {
2895
+ id: W.FlagLacing,
2896
+ data: 0
2897
+ },
2898
+ {
2899
+ id: W.Language,
2900
+ data: n.track.metadata.languageCode ?? "und"
2901
+ },
2902
+ {
2903
+ id: W.CodecID,
2904
+ data: r
2905
+ },
2906
+ n.codecPrivate ? {
2907
+ id: W.CodecPrivate,
2908
+ data: o(n.codecPrivate)
2909
+ } : null,
2910
+ {
2911
+ id: W.CodecDelay,
2912
+ data: 0
2913
+ },
2914
+ {
2915
+ id: W.SeekPreRoll,
2916
+ data: i
2917
+ },
2918
+ n.track.metadata.name === void 0 ? null : {
2919
+ id: W.Name,
2920
+ data: new U(n.track.metadata.name)
2921
+ },
2922
+ n.type === "video" ? this.videoSpecificTrackInfo(n) : null,
2923
+ n.type === "audio" ? this.audioSpecificTrackInfo(n) : null,
2924
+ n.type === "subtitle" ? this.subtitleSpecificTrackInfo(n) : null
2925
+ ]
2926
+ });
2927
+ }
2928
+ }
2929
+ videoSpecificTrackInfo(e) {
2930
+ let { frameRate: t, rotation: r } = e.track.metadata, i = [t ? {
2931
+ id: W.DefaultDuration,
2932
+ data: 1e9 / t
2933
+ } : null], a = r ? n(-r) : 0, o = !!e.info.aspectRatio && e.info.aspectRatio.num * e.info.height !== e.info.aspectRatio.den * e.info.width, s = e.info.decoderConfig.colorSpace, c = {
2934
+ id: W.Video,
2935
+ data: [
2936
+ {
2937
+ id: W.PixelWidth,
2938
+ data: e.info.width
2939
+ },
2940
+ {
2941
+ id: W.PixelHeight,
2942
+ data: e.info.height
2943
+ },
2944
+ o ? {
2945
+ id: W.DisplayWidth,
2946
+ data: e.info.aspectRatio.num
2947
+ } : null,
2948
+ o ? {
2949
+ id: W.DisplayHeight,
2950
+ data: e.info.aspectRatio.den
2951
+ } : null,
2952
+ o ? {
2953
+ id: W.DisplayUnit,
2954
+ data: 3
2955
+ } : null,
2956
+ e.info.alphaMode ? {
2957
+ id: W.AlphaMode,
2958
+ data: 1
2959
+ } : null,
2960
+ f(s) ? null : {
2961
+ id: W.Colour,
2962
+ data: [
2963
+ {
2964
+ id: W.MatrixCoefficients,
2965
+ data: s?.matrix == null ? 2 : d[s.matrix]
2966
+ },
2967
+ {
2968
+ id: W.TransferCharacteristics,
2969
+ data: s?.transfer == null ? 2 : u[s.transfer]
2970
+ },
2971
+ {
2972
+ id: W.Primaries,
2973
+ data: s?.primaries == null ? 2 : l[s.primaries]
2974
+ },
2975
+ {
2976
+ id: W.Range,
2977
+ data: s?.fullRange == null ? 0 : s.fullRange ? 2 : 1
2978
+ }
2979
+ ]
2980
+ },
2981
+ a ? {
2982
+ id: W.Projection,
2983
+ data: [{
2984
+ id: W.ProjectionType,
2985
+ data: 0
2986
+ }, {
2987
+ id: W.ProjectionPoseRoll,
2988
+ data: new V((a + 180) % 360 - 180)
2989
+ }]
2990
+ } : null
2991
+ ]
2992
+ };
2993
+ return i.push(c), i;
2994
+ }
2995
+ audioSpecificTrackInfo(e) {
2996
+ let t = P.includes(e.track.source._codec) ? Qe(e.track.source._codec) : null;
2997
+ return [{
2998
+ id: W.Audio,
2999
+ data: [
3000
+ {
3001
+ id: W.SamplingFrequency,
3002
+ data: new V(e.info.sampleRate)
3003
+ },
3004
+ {
3005
+ id: W.Channels,
3006
+ data: e.info.numberOfChannels
3007
+ },
3008
+ t ? {
3009
+ id: W.BitDepth,
3010
+ data: 8 * t.sampleSize
3011
+ } : null
3012
+ ]
3013
+ }];
3014
+ }
3015
+ subtitleSpecificTrackInfo(e) {
3016
+ return [];
3017
+ }
3018
+ maybeCreateTags() {
3019
+ let e = [], t = (t, n) => {
3020
+ e.push({
3021
+ id: W.SimpleTag,
3022
+ data: [{
3023
+ id: W.TagName,
3024
+ data: new U(t)
3025
+ }, typeof n == "string" ? {
3026
+ id: W.TagString,
3027
+ data: new U(n)
3028
+ } : {
3029
+ id: W.TagBinary,
3030
+ data: n
3031
+ }]
3032
+ });
3033
+ }, n = this.output._metadataTags, r = /* @__PURE__ */ new Set();
3034
+ for (let { key: e, value: i } of ce(n)) switch (e) {
3035
+ case "title":
3036
+ t("TITLE", i), r.add("TITLE");
3037
+ break;
3038
+ case "description":
3039
+ t("DESCRIPTION", i), r.add("DESCRIPTION");
3040
+ break;
3041
+ case "artist":
3042
+ t("ARTIST", i), r.add("ARTIST");
3043
+ break;
3044
+ case "album":
3045
+ t("ALBUM", i), r.add("ALBUM");
3046
+ break;
3047
+ case "albumArtist":
3048
+ t("ALBUM_ARTIST", i), r.add("ALBUM_ARTIST");
3049
+ break;
3050
+ case "genre":
3051
+ t("GENRE", i), r.add("GENRE");
3052
+ break;
3053
+ case "comment":
3054
+ t("COMMENT", i), r.add("COMMENT");
3055
+ break;
3056
+ case "lyrics":
3057
+ t("LYRICS", i), r.add("LYRICS");
3058
+ break;
3059
+ case "date":
3060
+ t("DATE", i.toISOString().slice(0, 10)), r.add("DATE");
3061
+ break;
3062
+ case "trackNumber":
3063
+ t("PART_NUMBER", n.tracksTotal === void 0 ? i.toString() : `${i}/${n.tracksTotal}`), r.add("PART_NUMBER");
3064
+ break;
3065
+ case "discNumber":
3066
+ t("DISC", n.discsTotal === void 0 ? i.toString() : `${i}/${n.discsTotal}`), r.add("DISC");
3067
+ break;
3068
+ case "tracksTotal":
3069
+ case "discsTotal": break;
3070
+ case "images":
3071
+ case "raw": break;
3072
+ default: _(e);
3073
+ }
3074
+ if (n.raw) for (let e in n.raw) {
3075
+ let i = n.raw[e];
3076
+ i == null || r.has(e) || (typeof i == "string" || i instanceof Uint8Array) && t(e, i);
3077
+ }
3078
+ e.length !== 0 && (this.tagsElement = {
3079
+ id: W.Tags,
3080
+ data: [{
3081
+ id: W.Tag,
3082
+ data: [{
3083
+ id: W.Targets,
3084
+ data: [{
3085
+ id: W.TargetTypeValue,
3086
+ data: 50
3087
+ }, {
3088
+ id: W.TargetType,
3089
+ data: "MOVIE"
3090
+ }]
3091
+ }, ...e]
3092
+ }]
3093
+ });
3094
+ }
3095
+ maybeCreateAttachments() {
3096
+ let e = this.output._metadataTags, t = [], n = /* @__PURE__ */ new Set(), r = e.images ?? [];
3097
+ for (let e of r) {
3098
+ let r = e.name;
3099
+ r === void 0 && (r = (e.kind === "coverFront" ? "cover" : e.kind === "coverBack" ? "back" : "image") + (le(e.mimeType) ?? ""));
3100
+ let i;
3101
+ for (;;) {
3102
+ i = 0n;
3103
+ for (let e = 0; e < 8; e++) i <<= 8n, i |= BigInt(Math.floor(Math.random() * 256));
3104
+ if (i !== 0n && !n.has(i)) break;
3105
+ }
3106
+ n.add(i), t.push({
3107
+ id: W.AttachedFile,
3108
+ data: [
3109
+ e.description === void 0 ? null : {
3110
+ id: W.FileDescription,
3111
+ data: new U(e.description)
3112
+ },
3113
+ {
3114
+ id: W.FileName,
3115
+ data: new U(r)
3116
+ },
3117
+ {
3118
+ id: W.FileMediaType,
3119
+ data: e.mimeType
3120
+ },
3121
+ {
3122
+ id: W.FileData,
3123
+ data: e.data
3124
+ },
3125
+ {
3126
+ id: W.FileUID,
3127
+ data: i
3128
+ }
3129
+ ]
3130
+ });
3131
+ }
3132
+ for (let [n, i] of Object.entries(e.raw ?? {})) i instanceof ye && /^\d+$/.test(n) && (r.find((e) => e.mimeType === i.mimeType && ue(e.data, i.data)) || t.push({
3133
+ id: W.AttachedFile,
3134
+ data: [
3135
+ i.description === void 0 ? null : {
3136
+ id: W.FileDescription,
3137
+ data: new U(i.description)
3138
+ },
3139
+ {
3140
+ id: W.FileName,
3141
+ data: new U(i.name ?? "")
3142
+ },
3143
+ {
3144
+ id: W.FileMediaType,
3145
+ data: i.mimeType ?? ""
3146
+ },
3147
+ {
3148
+ id: W.FileData,
3149
+ data: i.data
3150
+ },
3151
+ {
3152
+ id: W.FileUID,
3153
+ data: BigInt(n)
3154
+ }
3155
+ ]
3156
+ }));
3157
+ t.length !== 0 && (this.attachmentsElement = {
3158
+ id: W.Attachments,
3159
+ data: t
3160
+ });
3161
+ }
3162
+ createSegment() {
3163
+ this.createTracks(), this.maybeCreateTags(), this.maybeCreateAttachments(), this.maybeCreateSeekHead(!1);
3164
+ let e = {
3165
+ id: W.Segment,
3166
+ size: this.format._options.appendOnly ? -1 : mn,
3167
+ data: [
3168
+ this.seekHead,
3169
+ this.segmentInfo,
3170
+ this.tracksElement,
3171
+ this.attachmentsElement,
3172
+ this.tagsElement
3173
+ ]
3174
+ };
3175
+ if (this.segment = e, this.format._options.onSegmentHeader && this.writer.startTrackingWrites(), this.ebmlWriter.writeEBML(e), this.format._options.onSegmentHeader) {
3176
+ let { data: e, start: t } = this.writer.stopTrackingWrites();
3177
+ this.format._options.onSegmentHeader(e, t);
3178
+ }
3179
+ }
3180
+ createCues() {
3181
+ this.cues = {
3182
+ id: W.Cues,
3183
+ data: []
3184
+ };
3185
+ }
3186
+ get segmentDataOffset() {
3187
+ return t(this.segment), this.ebmlWriter.dataOffsets.get(this.segment);
3188
+ }
3189
+ allTracksAreKnown() {
3190
+ for (let e of this.output.tracks) if (!e.source._closed && !this.trackDatas.some((t) => t.track === e)) return !1;
3191
+ return !0;
3192
+ }
3193
+ async getMimeType() {
3194
+ await this.allTracksKnown.promise;
3195
+ let e = this.trackDatas.map((e) => e.type === "video" || e.type === "audio" ? e.info.decoderConfig.codec : { webvtt: "wvtt" }[e.track.source._codec]);
3196
+ return yt({
3197
+ isWebM: this.format instanceof Mn,
3198
+ hasVideo: this.trackDatas.some((e) => e.type === "video"),
3199
+ hasAudio: this.trackDatas.some((e) => e.type === "audio"),
3200
+ codecStrings: e
3201
+ });
3202
+ }
3203
+ getVideoTrackData(e, n, r) {
3204
+ let i = this.trackDatas.find((t) => t.track === e);
3205
+ if (i) return i;
3206
+ at(r, e.source._codec), t(r), t(r.decoderConfig), t(r.decoderConfig.codedWidth !== void 0), t(r.decoderConfig.codedHeight !== void 0);
3207
+ let a = r.decoderConfig.displayAspectWidth, o = r.decoderConfig.displayAspectHeight, s = a === void 0 || o === void 0 ? null : me({
3208
+ num: a,
3209
+ den: o
3210
+ }), l = {
3211
+ track: e,
3212
+ type: "video",
3213
+ info: {
3214
+ width: r.decoderConfig.codedWidth,
3215
+ height: r.decoderConfig.codedHeight,
3216
+ aspectRatio: s,
3217
+ decoderConfig: r.decoderConfig,
3218
+ alphaMode: n ? !!n.sideData.alpha : null
3219
+ },
3220
+ chunkQueue: [],
3221
+ lastWrittenMsTimestamp: null,
3222
+ codecPrivate: r.decoderConfig.description ?? null,
3223
+ closed: !1
3224
+ };
3225
+ return e.source._codec === "vp9" ? l.codecPrivate = new Uint8Array(Je(l.info.decoderConfig.codec)) : e.source._codec === "av1" ? l.codecPrivate = new Uint8Array(Ye(l.info.decoderConfig.codec)) : e.source._codec === "prores" && (l.codecPrivate = c.encode(r.decoderConfig.codec)), this.trackDatas.push(l), this.trackDatas.sort((e, t) => e.track.id - t.track.id), this.allTracksAreKnown() && this.allTracksKnown.resolve(), l;
3226
+ }
3227
+ getAudioTrackData(e, n, r) {
3228
+ let i = this.trackDatas.find((t) => t.track === e);
3229
+ if (i) return i;
3230
+ st(r, e.source._codec), t(r), t(r.decoderConfig);
3231
+ let a = { ...r.decoderConfig }, o = !1;
3232
+ if (e.source._codec === "aac" && !a.description) {
3233
+ if (!n) throw Error("No AAC description provided; you must therefore provide a priming packet.");
3234
+ let e = bt(Xt.tempFromBytes(n.data));
3235
+ if (!e) throw Error("Couldn't parse ADTS header from the AAC packet. Make sure the packets are in ADTS format (as specified in ISO 13818-7) when not providing a description, or provide a description (must be an AudioSpecificConfig as specified in ISO 14496-3) and ensure the packets are raw AAC data.");
3236
+ let t = Se[e.samplingFrequencyIndex], r = Ce[e.channelConfiguration];
3237
+ if (t === void 0 || r === void 0) throw Error("Invalid ADTS frame header.");
3238
+ a.description = we({
3239
+ objectType: e.objectType,
3240
+ outputSampleRate: t,
3241
+ outputNumberOfChannels: r
3242
+ }), o = !0;
3243
+ }
3244
+ let s = {
3245
+ track: e,
3246
+ type: "audio",
3247
+ info: {
3248
+ numberOfChannels: r.decoderConfig.numberOfChannels,
3249
+ sampleRate: r.decoderConfig.sampleRate,
3250
+ decoderConfig: a,
3251
+ requiresAdtsStripping: o
3252
+ },
3253
+ chunkQueue: [],
3254
+ lastWrittenMsTimestamp: null,
3255
+ codecPrivate: a.description ?? null,
3256
+ closed: !1
3257
+ };
3258
+ return this.trackDatas.push(s), this.trackDatas.sort((e, t) => e.track.id - t.track.id), this.allTracksAreKnown() && this.allTracksKnown.resolve(), s;
3259
+ }
3260
+ getSubtitleTrackData(e, n) {
3261
+ let r = this.trackDatas.find((t) => t.track === e);
3262
+ if (r) return r;
3263
+ ct(n), t(n), t(n.config);
3264
+ let i = {
3265
+ track: e,
3266
+ type: "subtitle",
3267
+ info: { config: n.config },
3268
+ chunkQueue: [],
3269
+ lastWrittenMsTimestamp: null,
3270
+ codecPrivate: c.encode(n.config.description),
3271
+ closed: !1
3272
+ };
3273
+ return this.trackDatas.push(i), this.trackDatas.sort((e, t) => e.track.id - t.track.id), this.allTracksAreKnown() && this.allTracksKnown.resolve(), i;
3274
+ }
3275
+ async addEncodedVideoPacket(e, t, n) {
3276
+ let r = await this.mutex.acquire();
3277
+ try {
3278
+ let r = this.getVideoTrackData(e, t, n);
3279
+ r.info.alphaMode ??= !!t.sideData.alpha;
3280
+ let i = t.data;
3281
+ if (e.source._codec === "prores") {
3282
+ if (i.byteLength < 8) throw Error("ProRes packet too small, expected at least 8 bytes.");
3283
+ i = i.subarray(8);
3284
+ }
3285
+ let a = t.type === "key";
3286
+ this.validateTimestamp(r.track, t.timestamp, a);
3287
+ let o = t.timestamp, s = t.duration;
3288
+ e.metadata.frameRate !== void 0 && (o = S(o, e.metadata.frameRate), s = S(s, e.metadata.frameRate));
3289
+ let c = r.info.alphaMode ? t.sideData.alpha ?? null : null, l = this.createInternalChunk(i, o, s, t.type, c);
3290
+ e.source._codec === "vp9" && this.fixVP9ColorSpace(r, l), r.chunkQueue.push(l), await this.interleaveChunks();
3291
+ } finally {
3292
+ r();
3293
+ }
3294
+ }
3295
+ async addEncodedAudioPacket(e, t, n) {
3296
+ let r = await this.mutex.acquire();
3297
+ try {
3298
+ let r = this.getAudioTrackData(e, t, n), i = t.data;
3299
+ if (r.info.requiresAdtsStripping) {
3300
+ let e = bt(Xt.tempFromBytes(i));
3301
+ if (!e) throw Error("Expected ADTS frame, didn't get one.");
3302
+ let t = e.crcCheck === null ? 7 : 9;
3303
+ i = i.subarray(t);
3304
+ }
3305
+ let a = t.type === "key";
3306
+ this.validateTimestamp(r.track, t.timestamp, a);
3307
+ let o = this.createInternalChunk(i, t.timestamp, t.duration, t.type);
3308
+ r.chunkQueue.push(o), await this.interleaveChunks();
3309
+ } finally {
3310
+ r();
3311
+ }
3312
+ }
3313
+ async addSubtitleCue(e, t, n) {
3314
+ let r = await this.mutex.acquire();
3315
+ try {
3316
+ let r = this.getSubtitleTrackData(e, n);
3317
+ this.validateTimestamp(r.track, t.timestamp, !0);
3318
+ let i = t.text, a = Math.round(t.timestamp * 1e3);
3319
+ en.lastIndex = 0, i = i.replace(en, (e) => `<${rn(nn(e.slice(1, -1)) - a)}>`);
3320
+ let o = c.encode(i), s = `${t.settings ?? ""}\n${t.identifier ?? ""}\n${t.notes ?? ""}`, l = this.createInternalChunk(o, t.timestamp, t.duration, "key", s.trim() ? c.encode(s) : null);
3321
+ r.chunkQueue.push(l), await this.interleaveChunks();
3322
+ } finally {
3323
+ r();
3324
+ }
3325
+ }
3326
+ async interleaveChunks(e = !1) {
3327
+ if (!(!e && !this.allTracksAreKnown())) {
3328
+ outer: for (;;) {
3329
+ let t = null, n = Infinity;
3330
+ for (let r of this.trackDatas) {
3331
+ if (!e && r.chunkQueue.length === 0 && !r.closed) break outer;
3332
+ r.chunkQueue.length > 0 && r.chunkQueue[0].timestamp < n && (t = r, n = r.chunkQueue[0].timestamp);
3333
+ }
3334
+ if (!t) break;
3335
+ let r = t.chunkQueue.shift();
3336
+ this.writeBlock(t, r);
3337
+ }
3338
+ e || await this.writer.flush();
3339
+ }
3340
+ }
3341
+ fixVP9ColorSpace(e, t) {
3342
+ if (t.type !== "key" || !e.info.decoderConfig.colorSpace || !e.info.decoderConfig.colorSpace.matrix) return;
3343
+ let n = new j(t.data);
3344
+ n.skipBits(2);
3345
+ let r = n.readBits(1), i = (n.readBits(1) << 1) + r;
3346
+ if (i === 3 && n.skipBits(1), n.readBits(1) || n.readBits(1) !== 0 || (n.skipBits(2), n.readBits(24) !== 4817730)) return;
3347
+ i >= 2 && n.skipBits(1);
3348
+ let o = {
3349
+ rgb: 7,
3350
+ bt709: 2,
3351
+ bt470bg: 1,
3352
+ smpte170m: 3
3353
+ }[e.info.decoderConfig.colorSpace.matrix];
3354
+ a(t.data, n.pos, n.pos + 3, o);
3355
+ }
3356
+ createInternalChunk(e, t, n, r, i = null) {
3357
+ return {
3358
+ data: e,
3359
+ type: r,
3360
+ timestamp: t,
3361
+ duration: n,
3362
+ additions: i
3363
+ };
3364
+ }
3365
+ writeBlock(e, n) {
3366
+ this.segment || this.createSegment();
3367
+ let r = Math.round(1e3 * n.timestamp), i = this.trackDatas.every((t) => {
3368
+ if (e === t) return n.type === "key";
3369
+ let r = t.chunkQueue[0];
3370
+ return r ? r.type === "key" : t.closed;
3371
+ }), a = !1;
3372
+ if (!this.currentCluster) a = !0;
3373
+ else {
3374
+ t(this.currentClusterStartMsTimestamp !== null), t(this.currentClusterMaxMsTimestamp !== null);
3375
+ let e = r - this.currentClusterStartMsTimestamp;
3376
+ a = i && r > this.currentClusterMaxMsTimestamp && e >= 1e3 * (this.format._options.minimumClusterDuration ?? 1) || e > fn;
3377
+ }
3378
+ a && this.createNewCluster(r);
3379
+ let o = r - this.currentClusterStartMsTimestamp;
3380
+ if (o < dn) return;
3381
+ let s = new Uint8Array(4), c = new DataView(s.buffer);
3382
+ c.setUint8(0, 128 | e.track.id), c.setInt16(1, o, !1);
3383
+ let l = Math.round(1e3 * n.duration);
3384
+ if (n.additions || e.type === "subtitle") {
3385
+ let t = {
3386
+ id: W.BlockGroup,
3387
+ data: [
3388
+ {
3389
+ id: W.Block,
3390
+ data: [s, n.data]
3391
+ },
3392
+ n.type === "delta" ? {
3393
+ id: W.ReferenceBlock,
3394
+ data: new ut(e.lastWrittenMsTimestamp - r)
3395
+ } : null,
3396
+ n.additions ? {
3397
+ id: W.BlockAdditions,
3398
+ data: [{
3399
+ id: W.BlockMore,
3400
+ data: [{
3401
+ id: W.BlockAddID,
3402
+ data: 1
3403
+ }, {
3404
+ id: W.BlockAdditional,
3405
+ data: n.additions
3406
+ }]
3407
+ }]
3408
+ } : null,
3409
+ l > 0 ? {
3410
+ id: W.BlockDuration,
3411
+ data: l
3412
+ } : null
3413
+ ]
3414
+ };
3415
+ this.ebmlWriter.writeEBML(t);
3416
+ } else {
3417
+ c.setUint8(3, Number(n.type === "key") << 7);
3418
+ let e = {
3419
+ id: W.SimpleBlock,
3420
+ data: [s, n.data]
3421
+ };
3422
+ this.ebmlWriter.writeEBML(e);
3423
+ }
3424
+ this.startTimestamp = Math.min(this.startTimestamp, r), this.endTimestamp = Math.max(this.endTimestamp, r + l), e.lastWrittenMsTimestamp = r, this.trackDatasInCurrentCluster.has(e) || this.trackDatasInCurrentCluster.set(e, { firstMsTimestamp: r }), this.currentClusterMaxMsTimestamp = Math.max(this.currentClusterMaxMsTimestamp, r);
3425
+ }
3426
+ createNewCluster(e) {
3427
+ this.currentCluster && this.finalizeCurrentCluster(), this.format._options.onCluster && this.writer.startTrackingWrites(), this.currentCluster = {
3428
+ id: W.Cluster,
3429
+ size: this.format._options.appendOnly ? -1 : hn,
3430
+ data: [{
3431
+ id: W.Timestamp,
3432
+ data: e
3433
+ }]
3434
+ }, this.ebmlWriter.writeEBML(this.currentCluster), this.currentClusterStartMsTimestamp = e, this.currentClusterMaxMsTimestamp = e, this.trackDatasInCurrentCluster.clear();
3435
+ }
3436
+ finalizeCurrentCluster() {
3437
+ if (t(this.currentCluster), !this.format._options.appendOnly) {
3438
+ let e = this.writer.getPos() - this.ebmlWriter.dataOffsets.get(this.currentCluster), t = this.writer.getPos();
3439
+ this.writer.seek(this.ebmlWriter.offsets.get(this.currentCluster) + 4), this.ebmlWriter.writeVarInt(e, hn), this.writer.seek(t);
3440
+ }
3441
+ if (this.format._options.onCluster) {
3442
+ t(this.currentClusterStartMsTimestamp !== null);
3443
+ let { data: e, start: n } = this.writer.stopTrackingWrites();
3444
+ this.format._options.onCluster(e, n, this.currentClusterStartMsTimestamp / 1e3);
3445
+ }
3446
+ let e = this.ebmlWriter.offsets.get(this.currentCluster) - this.segmentDataOffset, n = /* @__PURE__ */ new Map();
3447
+ for (let [e, { firstMsTimestamp: t }] of this.trackDatasInCurrentCluster) n.has(t) || n.set(t, []), n.get(t).push(e);
3448
+ let r = [...n.entries()].sort((e, t) => e[0] - t[0]);
3449
+ for (let [n, i] of r) t(this.cues), this.cues.data.push({
3450
+ id: W.CuePoint,
3451
+ data: [{
3452
+ id: W.CueTime,
3453
+ data: n
3454
+ }, ...i.map((t) => ({
3455
+ id: W.CueTrackPositions,
3456
+ data: [{
3457
+ id: W.CueTrack,
3458
+ data: t.track.id
3459
+ }, {
3460
+ id: W.CueClusterPosition,
3461
+ data: e
3462
+ }]
3463
+ }))]
3464
+ });
3465
+ }
3466
+ async onTrackClose(e) {
3467
+ let t = await this.mutex.acquire(), n = this.trackDatas.find((t) => t.track === e);
3468
+ n && (n.closed = !0), this.allTracksAreKnown() && this.allTracksKnown.resolve(), await this.interleaveChunks(), t();
3469
+ }
3470
+ async finalize() {
3471
+ let e = await this.mutex.acquire();
3472
+ this.allTracksKnown.resolve();
3473
+ for (let e of this.trackDatas) e.closed = !0;
3474
+ if (this.segment || this.createSegment(), await this.interleaveChunks(!0), this.currentCluster && this.finalizeCurrentCluster(), t(this.cues), this.ebmlWriter.writeEBML(this.cues), !this.format._options.appendOnly) {
3475
+ let e = this.writer.getPos() - this.segmentDataOffset;
3476
+ this.writer.seek(this.ebmlWriter.offsets.get(this.segment) + 4), this.ebmlWriter.writeVarInt(e, mn);
3477
+ let n = this.startTimestamp === Infinity ? 0 : this.endTimestamp - this.startTimestamp;
3478
+ this.segmentDuration.data = new H(n), this.writer.seek(this.ebmlWriter.offsets.get(this.segmentDuration)), this.ebmlWriter.writeEBML(this.segmentDuration), t(this.seekHead), this.writer.seek(this.ebmlWriter.offsets.get(this.seekHead)), this.maybeCreateSeekHead(!0), this.ebmlWriter.writeEBML(this.seekHead);
3479
+ }
3480
+ e();
3481
+ }
3482
+ }, vn = function(e, t, n) {
3483
+ if (t != null) {
3484
+ if (typeof t != "object" && typeof t != "function") throw TypeError("Object expected.");
3485
+ var r, i;
3486
+ if (n) {
3487
+ if (!Symbol.asyncDispose) throw TypeError("Symbol.asyncDispose is not defined.");
3488
+ r = t[Symbol.asyncDispose];
3489
+ }
3490
+ if (r === void 0) {
3491
+ if (!Symbol.dispose) throw TypeError("Symbol.dispose is not defined.");
3492
+ r = t[Symbol.dispose], n && (i = r);
3493
+ }
3494
+ if (typeof r != "function") throw TypeError("Object not disposable.");
3495
+ i && (r = function() {
3496
+ try {
3497
+ i.call(this);
3498
+ } catch (e) {
3499
+ return Promise.reject(e);
3500
+ }
3501
+ }), e.stack.push({
3502
+ value: t,
3503
+ dispose: r,
3504
+ async: n
3505
+ });
3506
+ } else n && e.stack.push({ async: !0 });
3507
+ return t;
3508
+ }, yn = (function(e) {
3509
+ return function(t) {
3510
+ function n(n) {
3511
+ t.error = t.hasError ? new e(n, t.error, "An error was suppressed during disposal.") : n, t.hasError = !0;
3512
+ }
3513
+ var r, i = 0;
3514
+ function a() {
3515
+ for (; r = t.stack.pop();) try {
3516
+ if (!r.async && i === 1) return i = 0, t.stack.push(r), Promise.resolve().then(a);
3517
+ if (r.dispose) {
3518
+ var e = r.dispose.call(r.value);
3519
+ if (r.async) return i |= 2, Promise.resolve(e).then(a, function(e) {
3520
+ return n(e), a();
3521
+ });
3522
+ } else i |= 1;
3523
+ } catch (e) {
3524
+ n(e);
3525
+ }
3526
+ if (i === 1) return t.hasError ? Promise.reject(t.error) : Promise.resolve();
3527
+ if (t.hasError) throw t.error;
3528
+ }
3529
+ return a();
3530
+ };
3531
+ })(typeof SuppressedError == "function" ? SuppressedError : function(e, t, n) {
3532
+ var r = Error(n);
3533
+ return r.name = "SuppressedError", r.error = e, r.suppressed = t, r;
3534
+ }), bn = class {
3535
+ constructor() {
3536
+ this._connectedTrack = null, this._closingPromise = null, this._closed = !1;
3537
+ }
3538
+ _ensureValidAdd() {
3539
+ if (!this._connectedTrack) throw Error("Source is not connected to an output track.");
3540
+ if (this._connectedTrack.output.state === "canceled") throw Error("Output has been canceled.");
3541
+ if (this._connectedTrack.output.state === "finalizing" || this._connectedTrack.output.state === "finalized") throw Error("Output has been finalized.");
3542
+ if (this._connectedTrack.output.state === "pending") throw Error("Output has not started.");
3543
+ if (this._closed) throw Error("Source is closed.");
3544
+ }
3545
+ async _start() {}
3546
+ async _flushAndClose(e) {}
3547
+ close() {
3548
+ if (this._closingPromise) return;
3549
+ let e = this._connectedTrack;
3550
+ if (!e) throw Error("Cannot call close without connecting the source to an output track.");
3551
+ if (e.output.state === "pending") throw Error("Cannot call close before output has been started.");
3552
+ this._closingPromise = (async () => {
3553
+ await this._flushAndClose(!1), this._closed = !0, !(e.output.state === "finalizing" || e.output.state === "finalized") && e.output._muxer.onTrackClose(e);
3554
+ })();
3555
+ }
3556
+ async _flushOrWaitForOngoingClose(e) {
3557
+ return this._closingPromise ??= (async () => {
3558
+ await this._flushAndClose(e), this._closed = !0;
3559
+ })();
3560
+ }
3561
+ }, xn = class extends bn {
3562
+ constructor(e) {
3563
+ if (super(), this._connectedTrack = null, !N.includes(e)) throw TypeError(`Invalid video codec '${e}'. Must be one of: ${N.join(", ")}.`);
3564
+ this._codec = e;
3565
+ }
3566
+ }, Sn = (e, t) => {
3567
+ if (e.metadata.hasOnlyKeyPackets && t.type !== "key") throw Error("Cannot add non-key packets to a hasOnlyKeyPackets video track.");
3568
+ }, Cn = class {
3569
+ setError(e) {
3570
+ this.errorSet ||= (this.error = e, !0);
3571
+ }
3572
+ constructor(e, t) {
3573
+ this.source = e, this.encodingConfig = t, this.ensureEncoderPromise = null, this.encoderInitialized = !1, this.encoder = null, this.muxer = null, this.lastMultipleOfKeyFrameInterval = -1, this.emittedEncoderPackets = 0, this.codedWidth = null, this.codedHeight = null, this.outputWidth = null, this.outputHeight = null, this.frameRateLastSample = null, this.frameRateLastTimestamp = null, this.frameRateLastEndTimestamp = null, this.preciseTimings = [], this.customEncoder = null, this.customEncoderCallSerializer = new ne(), this.customEncoderQueueSize = 0, this.defaultEncodeOptions = {}, this.alphaEncoder = null, this.splitter = null, this.splitterCreationFailed = !1, this.alphaFrameQueue = [], this.error = null, this.errorSet = !1, this.lastMuxerPromise = Promise.resolve(), this.closed = !1;
3574
+ }
3575
+ async add(e, n, r) {
3576
+ let i = e;
3577
+ try {
3578
+ this.checkForEncoderError(), this.source._ensureValidAdd();
3579
+ let a = this.encodingConfig, o = a.sizeChangeBehavior ?? "deny", s = !1;
3580
+ if (this.codedWidth !== null && this.codedHeight !== null) {
3581
+ if ((e.codedWidth !== this.codedWidth || e.codedHeight !== this.codedHeight) && (s = !0, o === "deny")) throw Error(`Video sample size must remain constant. Expected ${this.codedWidth}x${this.codedHeight}, got ${e.codedWidth}x${e.codedHeight}. To allow the sample size to change over time, set \`sizeChangeBehavior\` to a value other than 'deny' in the encoding options.`);
3582
+ } else this.codedWidth = e.codedWidth, this.codedHeight = e.codedHeight;
3583
+ if (a.transform?.width !== void 0 || a.transform?.height !== void 0 || a.transform?.rotate !== void 0 || a.transform?.crop !== void 0 || a.transform?.force === !0 || s && o !== "passThrough") {
3584
+ let r = a.transform?.width, i = a.transform?.height, c = a.transform?.fit ?? "fill";
3585
+ s && o !== "passThrough" && (t(this.outputWidth), t(this.outputHeight), t(o !== "deny"), r = this.outputWidth, i = this.outputHeight, c = o);
3586
+ let l = await e.transform({
3587
+ width: r,
3588
+ height: i,
3589
+ roundDimensionsTo: 2,
3590
+ crop: a.transform?.crop,
3591
+ rotate: a.transform?.rotate,
3592
+ fit: c,
3593
+ alpha: a.alpha
3594
+ });
3595
+ (this.outputWidth === null || this.outputHeight === null) && (this.outputWidth = l.displayWidth, this.outputHeight = l.displayHeight), n && e.close(), e = l, n = !0;
3596
+ } else (this.outputWidth === null || this.outputHeight === null) && (this.outputWidth = e.codedWidth, this.outputHeight = e.codedHeight);
3597
+ let c = a.transform?.frameRate;
3598
+ if (c !== void 0) {
3599
+ let t = e.timestamp + e.duration, a = C(e.timestamp, c);
3600
+ if (this.frameRateLastSample !== null) if (a <= this.frameRateLastTimestamp) {
3601
+ this.frameRateLastSample.close(), this.frameRateLastSample = e.clone(), this.frameRateLastEndTimestamp = t;
3602
+ return;
3603
+ } else await this.padFrameRate(a, r);
3604
+ e === i && (e = e.clone(), n = !0), e.setTimestamp(a), e.setDuration(1 / c), this.frameRateLastSample?.close(), this.frameRateLastSample = e.clone(), this.frameRateLastTimestamp = a, this.frameRateLastEndTimestamp = t;
3605
+ }
3606
+ await this.processAndEncode(e, r);
3607
+ } finally {
3608
+ n && e.close();
3609
+ }
3610
+ }
3611
+ async processAndEncode(e, n) {
3612
+ let r = this.encodingConfig, i;
3613
+ if (r.transform?.process) {
3614
+ let t = r.transform.process(e);
3615
+ if (E(t) && (t = await t), t === null) return;
3616
+ Array.isArray(t) || (t = [t]);
3617
+ let n = [];
3618
+ try {
3619
+ for (let r of t) r instanceof q ? n.push(r) : typeof VideoFrame < "u" && r instanceof VideoFrame ? n.push(new q(r)) : n.push(new q(r, {
3620
+ timestamp: e.timestamp,
3621
+ duration: e.duration
3622
+ }));
3623
+ } catch (r) {
3624
+ for (let t of n) t !== e && t.close();
3625
+ for (let n of t) (n instanceof q && n !== e || typeof VideoFrame < "u" && n instanceof VideoFrame) && n.close();
3626
+ throw r;
3627
+ }
3628
+ i = n;
3629
+ } else i = [e];
3630
+ try {
3631
+ for (let e of i) {
3632
+ if (this.encoderInitialized || (this.ensureEncoderPromise || this.ensureEncoder(e), this.encoderInitialized || await this.ensureEncoderPromise), t(this.encoderInitialized), this.closed) break;
3633
+ let r = this.encodingConfig.keyFrameInterval ?? 2, i = Math.floor(e.timestamp / r), a = {
3634
+ ...this.defaultEncodeOptions,
3635
+ ...e.encodeOptions,
3636
+ ...n
3637
+ }, o = {
3638
+ ...a,
3639
+ keyFrame: a.keyFrame === void 0 ? r === 0 || i !== this.lastMultipleOfKeyFrameInterval : a.keyFrame
3640
+ };
3641
+ if (this.lastMultipleOfKeyFrameInterval = i, this.encodingConfig.onEncodedSample?.(e), this.customEncoder) {
3642
+ this.customEncoderQueueSize++;
3643
+ let t = e.clone(), n = this.customEncoderCallSerializer.call(() => this.customEncoder.encode(t, o)).catch((e) => this.setError(e)).finally(() => {
3644
+ this.customEncoderQueueSize--, t.close();
3645
+ });
3646
+ this.customEncoderQueueSize >= 4 && await n;
3647
+ } else {
3648
+ t(this.encoder);
3649
+ let n = e.toVideoFrame(), r = h(this.preciseTimings, n.timestamp, (e) => e.microsecondTimestamp), i = r === -1 ? null : this.preciseTimings[r];
3650
+ if (i && i.microsecondTimestamp === n.timestamp ? (i.timestamp !== e.timestamp && (i.timestampIsValid = !1), i.duration !== e.duration && (i.durationIsValid = !1)) : (this.preciseTimings.splice(r + 1, 0, {
3651
+ microsecondTimestamp: n.timestamp,
3652
+ timestamp: e.timestamp,
3653
+ duration: e.duration,
3654
+ timestampIsValid: !0,
3655
+ durationIsValid: !0
3656
+ }), this.preciseTimings.length > 128 && this.preciseTimings.shift()), !this.alphaEncoder) try {
3657
+ this.encoder.encode(n, o);
3658
+ } finally {
3659
+ n.close();
3660
+ }
3661
+ else if (n.format && !n.format.includes("A") || this.splitterCreationFailed) {
3662
+ this.alphaFrameQueue.push(null);
3663
+ try {
3664
+ this.encoder.encode(n, o);
3665
+ } finally {
3666
+ n.close();
3667
+ }
3668
+ } else {
3669
+ this.splitter ||= new Tn();
3670
+ let { colorFrame: e, alphaFrame: t } = await this.splitter.split(n);
3671
+ this.alphaFrameQueue.push(t);
3672
+ try {
3673
+ this.encoder.encode(e, o);
3674
+ } finally {
3675
+ e.close();
3676
+ }
3677
+ }
3678
+ this.encoder.encodeQueueSize >= 4 && await new Promise((e) => this.encoder.addEventListener("dequeue", e, { once: !0 }));
3679
+ }
3680
+ await this.lastMuxerPromise;
3681
+ }
3682
+ } finally {
3683
+ for (let t of i) t !== e && t.close();
3684
+ }
3685
+ }
3686
+ async padFrameRate(e, n) {
3687
+ let r = this.encodingConfig.transform.frameRate;
3688
+ t(this.frameRateLastSample);
3689
+ let i = Math.round((e - this.frameRateLastTimestamp) * r);
3690
+ for (let e = 1; e < i; e++) {
3691
+ let t = {
3692
+ stack: [],
3693
+ error: void 0,
3694
+ hasError: !1
3695
+ };
3696
+ try {
3697
+ let i = vn(t, this.frameRateLastSample.clone(), !1);
3698
+ i.setTimestamp(this.frameRateLastTimestamp + e / r), i.setDuration(1 / r), await this.processAndEncode(i, n);
3699
+ } catch (e) {
3700
+ t.error = e, t.hasError = !0;
3701
+ } finally {
3702
+ yn(t);
3703
+ }
3704
+ }
3705
+ }
3706
+ ensureEncoder(e) {
3707
+ this.ensureEncoderPromise = (async () => {
3708
+ let n = Jt(this.encodingConfig.quality, this.encodingConfig.bitrate);
3709
+ t(n !== void 0);
3710
+ let r = Ht({
3711
+ ...this.encodingConfig,
3712
+ quality: n,
3713
+ width: e.codedWidth,
3714
+ height: e.codedHeight,
3715
+ squarePixelWidth: e.squarePixelWidth,
3716
+ squarePixelHeight: e.squarePixelHeight,
3717
+ framerate: this.source._connectedTrack?.metadata.frameRate
3718
+ }), i = null, a;
3719
+ for (let e of r) {
3720
+ let t = e.config;
3721
+ if (this.encodingConfig.onEncoderConfig?.(t), a = Yt.find((e) => e.supports(this.encodingConfig.codec, t)), a) {
3722
+ i = e;
3723
+ break;
3724
+ }
3725
+ if (!(typeof VideoEncoder > "u")) {
3726
+ if (t.alpha = "discard", this.encodingConfig.alpha === "keep" && (t.latencyMode = "quality"), (t.width % 2 == 1 || t.height % 2 == 1) && (this.encodingConfig.codec === "avc" || this.encodingConfig.codec === "hevc")) throw Error(`The dimensions ${t.width}x${t.height} are not supported for codec '${this.encodingConfig.codec}'; both width and height must be even numbers. Make sure to round your dimensions to the nearest even number.`);
3727
+ try {
3728
+ if ((await VideoEncoder.isConfigSupported(t)).supported) {
3729
+ i = e;
3730
+ break;
3731
+ }
3732
+ } catch {}
3733
+ }
3734
+ }
3735
+ if (!i) {
3736
+ if (typeof VideoEncoder > "u") throw Error(oe("VideoEncoder"));
3737
+ let e = r[0].config, t = r.map(({ config: e, quantizer: t }) => t === null ? `${e.bitrate} bps` : `quantizer ${t}`);
3738
+ throw Error(`This specific encoder configuration (${e.codec}, ${t.join(" / ")}, ${e.width}x${e.height}, hardware acceleration: ${e.hardwareAcceleration ?? "no-preference"}) is not supported in this environment. Consider using another codec or changing your video parameters.`);
3739
+ }
3740
+ let o = i.config;
3741
+ if (i.quantizer !== null && (this.defaultEncodeOptions = qt(this.encodingConfig.codec, i.quantizer)), a) this.customEncoder = new a(), this.customEncoder.codec = this.encodingConfig.codec, this.customEncoder.config = o, this.customEncoder.onPacket = (e, t) => {
3742
+ if (!(e instanceof B)) throw TypeError("The first argument passed to onPacket must be an EncodedPacket.");
3743
+ if (t !== void 0 && (!t || typeof t != "object")) throw TypeError("The second argument passed to onPacket must be an object or undefined.");
3744
+ Sn(this.source._connectedTrack, e), this.encodingConfig.onEncodedPacket?.(e, t), this.lastMuxerPromise = this.muxer.addEncodedVideoPacket(this.source._connectedTrack, e, t).catch((e) => {
3745
+ this.setError(e);
3746
+ });
3747
+ }, this.customEncoder.onError = (e) => {
3748
+ this.setError(e);
3749
+ }, await this.customEncoder.init();
3750
+ else {
3751
+ let e = [], n = [], r = 0, i = 0, a = (e, t, n) => {
3752
+ let r = {};
3753
+ if (t) {
3754
+ let e = new Uint8Array(t.byteLength);
3755
+ t.copyTo(e), r.alpha = e;
3756
+ }
3757
+ let i = B.fromEncodedChunk(e, r), a = h(this.preciseTimings, e.timestamp, (e) => e.microsecondTimestamp), o = a === -1 ? null : this.preciseTimings[a], s = null;
3758
+ this.emittedEncoderPackets === 0 && i.type === "delta" && n?.decoderConfig && (s = ze(this.encodingConfig.codec, n.decoderConfig, i.data)), (o && o.microsecondTimestamp === e.timestamp || s !== null) && (i = i.clone({
3759
+ timestamp: o?.timestampIsValid ? o.timestamp : void 0,
3760
+ duration: o?.durationIsValid ? o.duration : void 0,
3761
+ type: s ?? void 0
3762
+ })), Sn(this.source._connectedTrack, i), this.encodingConfig.onEncodedPacket?.(i, n), this.lastMuxerPromise = this.muxer.addEncodedVideoPacket(this.source._connectedTrack, i, n).catch((e) => {
3763
+ this.setError(e);
3764
+ }), this.emittedEncoderPackets++;
3765
+ }, s = (/* @__PURE__ */ Error("Encoding error")).stack;
3766
+ if (this.encoder = new VideoEncoder({
3767
+ output: (o, s) => {
3768
+ if (!this.alphaEncoder) {
3769
+ a(o, null, s);
3770
+ return;
3771
+ }
3772
+ let c = this.alphaFrameQueue.shift();
3773
+ t(c !== void 0), c ? (this.alphaEncoder.encode(c, {
3774
+ ...this.defaultEncodeOptions,
3775
+ keyFrame: o.type === "key"
3776
+ }), i++, c.close(), e.push({
3777
+ chunk: o,
3778
+ meta: s
3779
+ })) : i === 0 ? a(o, null, s) : (n.push(r + i), e.push({
3780
+ chunk: o,
3781
+ meta: s
3782
+ }));
3783
+ },
3784
+ error: (e) => {
3785
+ e.stack = s, this.setError(e);
3786
+ }
3787
+ }), this.encoder.configure(o), this.encodingConfig.alpha === "keep") {
3788
+ let s = (/* @__PURE__ */ Error("Encoding error")).stack;
3789
+ this.alphaEncoder = new VideoEncoder({
3790
+ output: (o, s) => {
3791
+ i--;
3792
+ let c = e.shift();
3793
+ for (t(c !== void 0), a(c.chunk, o, c.meta), r++; n.length > 0 && n[0] === r;) {
3794
+ n.shift();
3795
+ let r = e.shift();
3796
+ t(r !== void 0), a(r.chunk, null, r.meta);
3797
+ }
3798
+ },
3799
+ error: (e) => {
3800
+ e.stack = s, this.setError(e);
3801
+ }
3802
+ }), this.alphaEncoder.configure(o);
3803
+ }
3804
+ }
3805
+ t(this.source._connectedTrack), this.muxer = this.source._connectedTrack.output._muxer, this.encoderInitialized = !0;
3806
+ })();
3807
+ }
3808
+ async flushAndClose(e) {
3809
+ try {
3810
+ if (!e && (this.checkForEncoderError(), this.frameRateLastSample)) {
3811
+ let e = this.encodingConfig.transform.frameRate, t = C(this.frameRateLastEndTimestamp, e);
3812
+ await this.padFrameRate(t);
3813
+ }
3814
+ this.closed = !0, e || (this.customEncoder ? this.customEncoderCallSerializer.call(() => this.customEncoder.flush()) : this.encoder && (await this.encoder.flush(), await this.alphaEncoder?.flush(), await he(25)));
3815
+ } finally {
3816
+ this.closed = !0, this.frameRateLastSample?.close(), this.frameRateLastSample = null, this.customEncoder ? await this.customEncoderCallSerializer.call(() => this.customEncoder.close()).catch((e) => this.setError(e)) : this.encoder && (this.encoder.state !== "closed" && this.encoder.close(), this.alphaEncoder && this.alphaEncoder.state !== "closed" && this.alphaEncoder.close(), this.alphaFrameQueue.forEach((e) => e?.close()), this.alphaFrameQueue.length = 0, this.splitter?.close());
3817
+ }
3818
+ e || this.checkForEncoderError();
3819
+ }
3820
+ getQueueSize() {
3821
+ return this.customEncoder ? this.customEncoderQueueSize : this.encoder?.encodeQueueSize ?? 0;
3822
+ }
3823
+ checkForEncoderError() {
3824
+ if (this.errorSet) throw this.error;
3825
+ }
3826
+ }, wn = null, Tn = class {
3827
+ constructor() {
3828
+ this.worker = null, this.pendingRequests = /* @__PURE__ */ new Map(), this.nextRequestId = 0;
3829
+ }
3830
+ split(e) {
3831
+ if (!this.worker) {
3832
+ if (!wn) {
3833
+ let e = new Blob([`(${En.toString()})()`], { type: "application/javascript" });
3834
+ wn = URL.createObjectURL(e);
3835
+ }
3836
+ this.worker = new Worker(wn), this.worker.addEventListener("message", (e) => {
3837
+ let t = e.data, n = this.pendingRequests.get(t.id);
3838
+ n && (this.pendingRequests.delete(t.id), "error" in t ? n.reject(Error(t.error)) : n.resolve({
3839
+ colorFrame: t.colorFrame,
3840
+ alphaFrame: t.alphaFrame
3841
+ }));
3842
+ }), this.worker.addEventListener("error", (e) => {
3843
+ let t = Error(e.message || "Color/alpha splitter worker error.");
3844
+ for (let e of this.pendingRequests.values()) e.reject(t);
3845
+ this.pendingRequests.clear();
3846
+ });
3847
+ }
3848
+ let t = this.nextRequestId++, n = g();
3849
+ return this.pendingRequests.set(t, n), this.worker.postMessage({
3850
+ id: t,
3851
+ sourceFrame: e
3852
+ }, { transfer: [e] }), n.promise;
3853
+ }
3854
+ close() {
3855
+ this.worker?.terminate(), this.worker = null;
3856
+ let e = /* @__PURE__ */ Error("Color/alpha splitter closed.");
3857
+ for (let t of this.pendingRequests.values()) t.reject(e);
3858
+ this.pendingRequests.clear();
3859
+ }
3860
+ }, En = () => {
3861
+ let e = null, t = Promise.resolve();
3862
+ self.addEventListener("message", (e) => {
3863
+ let { id: r, sourceFrame: i } = e.data;
3864
+ t = t.then(async () => {
3865
+ try {
3866
+ let { colorFrame: e, alphaFrame: t } = await n(i);
3867
+ self.postMessage({
3868
+ id: r,
3869
+ colorFrame: e,
3870
+ alphaFrame: t
3871
+ }, { transfer: [e, t] });
3872
+ } catch (e) {
3873
+ self.postMessage({
3874
+ id: r,
3875
+ error: e.message
3876
+ });
3877
+ } finally {
3878
+ i.close();
3879
+ }
3880
+ });
3881
+ });
3882
+ let n = async (t) => {
3883
+ let n = t.format;
3884
+ if (!n) throw Error("CPU color/alpha splitting requires a known VideoFrame format.");
3885
+ let a = t.allocationSize();
3886
+ if ((!e || e.byteLength !== a) && (e = new Uint8Array(a)), await t.copyTo(e), n === "RGBA" || n === "BGRA") return r(e, n, t);
3887
+ if (n === "I420A" || n === "I420AP10" || n === "I420AP12" || n === "I422A" || n === "I422AP10" || n === "I422AP12" || n === "I444A" || n === "I444AP10" || n === "I444AP12") return i(e, n, t);
3888
+ throw Error(`CPU color/alpha splitting does not support format '${n}'.`);
3889
+ }, r = (e, t, n) => {
3890
+ let r = n.visibleRect?.width ?? n.codedWidth, i = n.visibleRect?.height ?? n.codedHeight, a = r * i, o = a + Math.ceil(r / 2) * Math.ceil(i / 2) * 2, s = new Uint8Array(o);
3891
+ for (let t = 0, n = 3; t < a; t++, n += 4) s[t] = e[n];
3892
+ s.fill(128, a);
3893
+ let c = new VideoFrame(e, {
3894
+ format: t === "RGBA" ? "RGBX" : "BGRX",
3895
+ codedWidth: r,
3896
+ codedHeight: i,
3897
+ timestamp: n.timestamp,
3898
+ duration: n.duration ?? void 0
3899
+ }), l = {
3900
+ format: "I420",
3901
+ codedWidth: r,
3902
+ codedHeight: i,
3903
+ timestamp: n.timestamp,
3904
+ duration: n.duration ?? void 0,
3905
+ transfer: [s.buffer]
3906
+ };
3907
+ return {
3908
+ colorFrame: c,
3909
+ alphaFrame: new VideoFrame(s, l)
3910
+ };
3911
+ }, i = (e, t, n) => {
3912
+ let r = n.visibleRect?.width ?? n.codedWidth, i = n.visibleRect?.height ?? n.codedHeight, a = t.includes("P10"), o = t.includes("P12"), s = a || o ? 2 : 1, c, l;
3913
+ t.startsWith("I420") ? (c = Math.ceil(r / 2), l = Math.ceil(i / 2)) : t.startsWith("I422") ? (c = Math.ceil(r / 2), l = i) : (c = r, l = i);
3914
+ let u = r * i, d = c * l, f = u * s, p = d * s, m = u * s, h = f + p * 2, g = t.replace("A", ""), _ = Math.ceil(r / 2) * Math.ceil(i / 2), v = m + _ * s * 2, y = new Uint8Array(v), b = h;
3915
+ y.set(e.subarray(b, b + m), 0);
3916
+ let x = m, S = a ? 512 : o ? 2048 : 128;
3917
+ s === 1 ? y.fill(S, x) : new Uint16Array(y.buffer, x, 2 * _).fill(S);
3918
+ let C = a ? "I420P10" : o ? "I420P12" : "I420", ee = new VideoFrame(e.subarray(0, h), {
3919
+ format: g,
3920
+ codedWidth: r,
3921
+ codedHeight: i,
3922
+ timestamp: n.timestamp,
3923
+ duration: n.duration ?? void 0
3924
+ }), te = {
3925
+ format: C,
3926
+ codedWidth: r,
3927
+ codedHeight: i,
3928
+ timestamp: n.timestamp,
3929
+ duration: n.duration ?? void 0,
3930
+ transfer: [y.buffer]
3931
+ };
3932
+ return {
3933
+ colorFrame: ee,
3934
+ alphaFrame: new VideoFrame(y, te)
3935
+ };
3936
+ };
3937
+ }, Dn = class extends xn {
3938
+ constructor(e, t) {
3939
+ if (!(typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement) && !(typeof OffscreenCanvas < "u" && e instanceof OffscreenCanvas)) throw TypeError("canvas must be an HTMLCanvasElement or OffscreenCanvas.");
3940
+ Bt(t), super(t.codec), this._encoder = new Cn(this, t), this._canvas = e;
3941
+ }
3942
+ add(e, t = 0, n) {
3943
+ if (!Number.isFinite(e) || e < 0) throw TypeError("timestamp must be a non-negative number.");
3944
+ if (!Number.isFinite(t) || t < 0) throw TypeError("duration must be a non-negative number.");
3945
+ let r = new q(this._canvas, {
3946
+ timestamp: e,
3947
+ duration: t
3948
+ });
3949
+ return this._encoder.add(r, !0, n);
3950
+ }
3951
+ _flushAndClose(e) {
3952
+ return this._encoder.flushAndClose(e);
3953
+ }
3954
+ }, On = class extends bn {
3955
+ constructor(e) {
3956
+ if (super(), this._connectedTrack = null, !F.includes(e)) throw TypeError(`Invalid audio codec '${e}'. Must be one of: ${F.join(", ")}.`);
3957
+ this._codec = e;
3958
+ }
3959
+ }, kn = class extends bn {
3960
+ constructor(e) {
3961
+ if (super(), this._connectedTrack = null, !I.includes(e)) throw TypeError(`Invalid subtitle codec '${e}'. Must be one of: ${I.join(", ")}.`);
3962
+ this._codec = e;
3963
+ }
3964
+ }, An = class {
3965
+ getSupportedVideoCodecs() {
3966
+ return this.getSupportedCodecs().filter((e) => N.includes(e));
3967
+ }
3968
+ getSupportedAudioCodecs() {
3969
+ return this.getSupportedCodecs().filter((e) => F.includes(e));
3970
+ }
3971
+ getSupportedSubtitleCodecs() {
3972
+ return this.getSupportedCodecs().filter((e) => I.includes(e));
3973
+ }
3974
+ _codecUnsupportedHint(e) {
3975
+ return "";
3976
+ }
3977
+ _isFragmentedIsobmff() {
3978
+ return !1;
3979
+ }
3980
+ }, jn = class extends An {
3981
+ constructor(e = {}) {
3982
+ if (!e || typeof e != "object") throw TypeError("options must be an object.");
3983
+ if (e.appendOnly !== void 0 && typeof e.appendOnly != "boolean") throw TypeError("options.appendOnly, when provided, must be a boolean.");
3984
+ if (e.minimumClusterDuration !== void 0 && (!fe(e.minimumClusterDuration) || e.minimumClusterDuration < 0)) throw TypeError("options.minimumClusterDuration, when provided, must be a non-negative number.");
3985
+ if (e.onEbmlHeader !== void 0 && typeof e.onEbmlHeader != "function") throw TypeError("options.onEbmlHeader, when provided, must be a function.");
3986
+ if (e.onSegmentHeader !== void 0 && typeof e.onSegmentHeader != "function") throw TypeError("options.onHeader, when provided, must be a function.");
3987
+ if (e.onCluster !== void 0 && typeof e.onCluster != "function") throw TypeError("options.onCluster, when provided, must be a function.");
3988
+ super(), this._options = e;
3989
+ }
3990
+ _createMuxer(e) {
3991
+ return new _n(e, this);
3992
+ }
3993
+ get _name() {
3994
+ return "Matroska";
3995
+ }
3996
+ getSupportedTrackCounts() {
3997
+ return {
3998
+ video: {
3999
+ min: 0,
4000
+ max: 127
4001
+ },
4002
+ audio: {
4003
+ min: 0,
4004
+ max: 127
4005
+ },
4006
+ subtitle: {
4007
+ min: 0,
4008
+ max: 127
4009
+ },
4010
+ total: {
4011
+ min: 0,
4012
+ max: 127
4013
+ }
4014
+ };
4015
+ }
4016
+ get fileExtension() {
4017
+ return ".mkv";
4018
+ }
4019
+ get mimeType() {
4020
+ return "video/x-matroska";
4021
+ }
4022
+ getSupportedCodecs() {
4023
+ return [
4024
+ ...N,
4025
+ ...Ve,
4026
+ ...P.filter((e) => ![
4027
+ "pcm-s8",
4028
+ "pcm-f32be",
4029
+ "pcm-f64be",
4030
+ "ulaw",
4031
+ "alaw"
4032
+ ].includes(e)),
4033
+ ...I
4034
+ ];
4035
+ }
4036
+ get supportsVideoRotationMetadata() {
4037
+ return !1;
4038
+ }
4039
+ get supportsTimestampedMediaData() {
4040
+ return !0;
4041
+ }
4042
+ }, Mn = class extends jn {
4043
+ constructor(e) {
4044
+ super(e);
4045
+ }
4046
+ getSupportedCodecs() {
4047
+ return [
4048
+ ...N.filter((e) => [
4049
+ "vp8",
4050
+ "vp9",
4051
+ "av1"
4052
+ ].includes(e)),
4053
+ ...F.filter((e) => ["opus", "vorbis"].includes(e)),
4054
+ ...I
4055
+ ];
4056
+ }
4057
+ get _name() {
4058
+ return "WebM";
4059
+ }
4060
+ get fileExtension() {
4061
+ return ".webm";
4062
+ }
4063
+ get mimeType() {
4064
+ return "video/webm";
4065
+ }
4066
+ _codecUnsupportedHint(e) {
4067
+ return new jn().getSupportedCodecs().includes(e) ? " Switching to MKV will grant support for this codec." : "";
4068
+ }
4069
+ }, Nn = [
4070
+ "video",
4071
+ "audio",
4072
+ "subtitle"
4073
+ ], Pn = class e {
4074
+ constructor(e, t, n, r, i) {
4075
+ this.id = e, this.output = t, this.type = n, this.source = r, this.metadata = i;
4076
+ }
4077
+ isVideoTrack() {
4078
+ return this.type === "video";
4079
+ }
4080
+ isAudioTrack() {
4081
+ return this.type === "audio";
4082
+ }
4083
+ isSubtitleTrack() {
4084
+ return this.type === "subtitle";
4085
+ }
4086
+ canBePairedWith(t) {
4087
+ if (!(t instanceof e)) throw TypeError("other must be an OutputTrack.");
4088
+ if (this === t) return !1;
4089
+ let n = ge(this.metadata.group), r = ge(t.metadata.group);
4090
+ for (let e of n) if (this.type !== t.type && r.some((t) => e === t) || r.some((t) => e._pairedGroups.has(t))) return !0;
4091
+ return !1;
4092
+ }
4093
+ }, Fn = class extends Pn {
4094
+ constructor(e, t, n, r) {
4095
+ super(e, t, "video", n, r);
4096
+ }
4097
+ }, In = class extends Pn {
4098
+ constructor(e, t, n, r) {
4099
+ super(e, t, "audio", n, r);
4100
+ }
4101
+ }, Ln = class extends Pn {
4102
+ constructor(e, t, n, r) {
4103
+ super(e, t, "subtitle", n, r);
4104
+ }
4105
+ }, Rn = class e {
4106
+ constructor() {
4107
+ this._pairedGroups = /* @__PURE__ */ new Set();
4108
+ }
4109
+ pairWith(t) {
4110
+ if (!(t instanceof e)) throw TypeError("other must be an OutputTrackGroup.");
4111
+ if (this === t) throw TypeError("Cannot pair a group with itself.");
4112
+ this._pairedGroups.add(t), t._pairedGroups.add(this);
4113
+ }
4114
+ }, $ = (e) => {
4115
+ if (!e || typeof e != "object") throw TypeError("metadata must be an object.");
4116
+ if (e.languageCode !== void 0 && !te(e.languageCode)) throw TypeError("metadata.languageCode, when provided, must be a three-letter, ISO 639-2/T language code.");
4117
+ if (e.name !== void 0 && typeof e.name != "string") throw TypeError("metadata.name, when provided, must be a string.");
4118
+ if (e.disposition !== void 0 && xe(e.disposition), e.maximumPacketCount !== void 0 && (!Number.isInteger(e.maximumPacketCount) || e.maximumPacketCount < 0)) throw TypeError("metadata.maximumPacketCount, when provided, must be a non-negative integer.");
4119
+ if (e.group !== void 0 && !(e.group instanceof Rn) && (!Array.isArray(e.group) || e.group.some((e) => !(e instanceof Rn)))) throw TypeError("metadata.group, when provided, must be an OutputTrackGroup instance or an array of OutputTrackGroup instances.");
4120
+ }, zn = class extends O {
4121
+ get target() {
4122
+ let e = "Output.target cannot be used when using PathedTarget with an async callback. Use the 'target' event instead.";
4123
+ if (this._rootTargetPromise) throw TypeError(e);
4124
+ let t = this._getRootTarget();
4125
+ if (E(t)) throw TypeError(e);
4126
+ return t;
4127
+ }
4128
+ constructor(e) {
4129
+ if (super(), this.state = "pending", this.defaultTrackGroup = new Rn(), this.tracks = [], this._onFinalize = null, this._unfinalizedTargets = /* @__PURE__ */ new Set(), this._rootWriterPromise = null, this._startPromise = null, this._cancelPromise = null, this._finalizePromise = null, this._mutex = new m(), this._metadataTags = {}, this._rootTarget = null, this._rootTargetPromise = null, this._firstMediaStreamTimestamp = null, !e || typeof e != "object") throw TypeError("options must be an object.");
4130
+ if (!(e.format instanceof An)) throw TypeError("options.format must be an OutputFormat.");
4131
+ if (!(e.target instanceof Q || e.target instanceof un)) throw TypeError("options.target must be a Target or a PathedTarget.");
4132
+ if (e.target instanceof Q && this._rememberTarget(e.target), e.initTarget !== void 0 && !(e.initTarget instanceof Q) && typeof e.initTarget != "function") throw Error("options.initTarget, when provided, must be a Target or a function that returns or resolves to a Target.");
4133
+ if (e.onFinalize !== void 0 && typeof e.onFinalize != "function") throw TypeError("options.onFinalize, when provided, must be a function.");
4134
+ this.format = e.format, this._target = e.target, this._onFinalize = e.onFinalize ?? null, this._initTarget = e.initTarget ?? null, this._initTarget instanceof Q && this._rememberTarget(this._initTarget), this._muxer = e.format._createMuxer(this);
4135
+ }
4136
+ _getTargetValidated(e) {
4137
+ t(this._target instanceof un);
4138
+ let n = this._target.getTarget(e), r = (e) => {
4139
+ if (!(e instanceof Q)) throw TypeError("getTarget must return a Target.");
4140
+ return e;
4141
+ };
4142
+ return E(n) ? n.then(r) : r(n);
4143
+ }
4144
+ async _getTarget(e) {
4145
+ t(this._target instanceof un);
4146
+ let n = await this._getTargetValidated(e);
4147
+ return this._emit("target", {
4148
+ target: n,
4149
+ request: e,
4150
+ isRoot: e.isRoot
4151
+ }), this.state === "canceled" ? await n._close() : this._rememberTarget(n), n;
4152
+ }
4153
+ _rememberTarget(e) {
4154
+ this._unfinalizedTargets.add(e), e.on("finalized", () => this._unfinalizedTargets.delete(e), { once: !0 });
4155
+ }
4156
+ async _getInitTarget() {
4157
+ if (t(this._initTarget !== null), this._initTarget instanceof Q) return this._initTarget;
4158
+ let e = await this._initTarget();
4159
+ return this.state === "canceled" ? await e._close() : this._rememberTarget(e), e;
4160
+ }
4161
+ _hasInitTarget() {
4162
+ return this._initTarget !== null;
4163
+ }
4164
+ _getRootTarget() {
4165
+ if (this._rootTarget) return this._rootTarget;
4166
+ if (this._rootTargetPromise) return this._rootTargetPromise;
4167
+ if (this._target instanceof Q) return this._emit("target", {
4168
+ target: this._target,
4169
+ request: null,
4170
+ isRoot: !0
4171
+ }), this._rootTarget = this._target, this._target;
4172
+ let e = {
4173
+ path: this._target.rootPath,
4174
+ isRoot: !0,
4175
+ mimeType: this.format.mimeType
4176
+ }, t = this._getTargetValidated(e), n = (t) => (this.state === "canceled" ? t._close() : this._rememberTarget(t), this._emit("target", {
4177
+ target: t,
4178
+ request: e,
4179
+ isRoot: !0
4180
+ }), this._rootTarget = t, t);
4181
+ return E(t) ? this._rootTargetPromise = t.then(n) : n(t);
4182
+ }
4183
+ _getRootWriter(e) {
4184
+ return this._rootWriterPromise ??= (async () => {
4185
+ let t = await this._getRootTarget(), n = new an(t, typeof e == "boolean" ? e : e(t));
4186
+ return n.start(), n;
4187
+ })();
4188
+ }
4189
+ addVideoTrack(e, t = {}) {
4190
+ if (!(e instanceof xn)) throw TypeError("source must be a VideoSource.");
4191
+ if ($(t), t.rotation !== void 0 && ![
4192
+ 0,
4193
+ 90,
4194
+ 180,
4195
+ 270
4196
+ ].includes(t.rotation)) throw TypeError(`Invalid video rotation: ${t.rotation}. Has to be 0, 90, 180 or 270.`);
4197
+ if (!this.format.supportsVideoRotationMetadata && t.rotation) throw Error(`${this.format._name} does not support video rotation metadata.`);
4198
+ if (t.frameRate !== void 0 && (!Number.isFinite(t.frameRate) || t.frameRate <= 0)) throw TypeError(`Invalid video frame rate: ${t.frameRate}. Must be a positive number.`);
4199
+ if (t.decoderConfig !== void 0 && at({ decoderConfig: t.decoderConfig }, e._codec), t.primingPacket !== void 0) {
4200
+ if (!(t.primingPacket instanceof B)) throw TypeError("metadata.primingPacket, when provided, must be an EncodedPacket.");
4201
+ if (t.decoderConfig === void 0) throw TypeError("metadata.primingPacket can only be provided alongside metadata.decoderConfig.");
4202
+ }
4203
+ let n = { ...t };
4204
+ return n.group ??= this.defaultTrackGroup, this._addTrack(new Fn(this.tracks.length + 1, this, e, n));
4205
+ }
4206
+ addAudioTrack(e, t = {}) {
4207
+ if (!(e instanceof On)) throw TypeError("source must be an AudioSource.");
4208
+ if ($(t), t.decoderConfig !== void 0 && st({ decoderConfig: t.decoderConfig }, e._codec), t.primingPacket !== void 0) {
4209
+ if (!(t.primingPacket instanceof B)) throw TypeError("metadata.primingPacket, when provided, must be an EncodedPacket.");
4210
+ if (t.decoderConfig === void 0) throw TypeError("metadata.primingPacket can only be provided alongside metadata.decoderConfig.");
4211
+ }
4212
+ let n = { ...t };
4213
+ return n.group ??= this.defaultTrackGroup, this._addTrack(new In(this.tracks.length + 1, this, e, n));
4214
+ }
4215
+ addSubtitleTrack(e, t = {}) {
4216
+ if (!(e instanceof kn)) throw TypeError("source must be a SubtitleSource.");
4217
+ $(t);
4218
+ let n = { ...t };
4219
+ return n.group ??= this.defaultTrackGroup, this._addTrack(new Ln(this.tracks.length + 1, this, e, n));
4220
+ }
4221
+ setMetadataTags(e) {
4222
+ if (be(e), this.state !== "pending") throw Error("Cannot set metadata tags after output has been started or canceled.");
4223
+ this._metadataTags = e;
4224
+ }
4225
+ _addTrack(e) {
4226
+ if (this.state !== "pending") throw Error("Cannot add track after output has been started or canceled.");
4227
+ if (e.source._connectedTrack) throw Error("Source is already used for a track.");
4228
+ let t = this.format.getSupportedTrackCounts(), n = this.tracks.reduce((t, n) => t + +(n.type === e.type), 0), r = t[e.type].max;
4229
+ if (n === r) throw Error(r === 0 ? `${this.format._name} does not support ${e.type} tracks.` : `${this.format._name} does not support more than ${r} ${e.type} track${r === 1 ? "" : "s"}.`);
4230
+ let i = t.total.max;
4231
+ if (this.tracks.length === i) throw Error(`${this.format._name} does not support more than ${i} tracks${i === 1 ? "" : "s"} in total.`);
4232
+ if (e.isVideoTrack()) {
4233
+ let t = this.format.getSupportedVideoCodecs();
4234
+ if (t.length === 0) throw Error(`${this.format._name} does not support video tracks.` + this.format._codecUnsupportedHint(e.source._codec));
4235
+ if (!t.includes(e.source._codec)) throw Error(`Codec '${e.source._codec}' cannot be contained within ${this.format._name}. Supported video codecs are: ${t.map((e) => `'${e}'`).join(", ")}.` + this.format._codecUnsupportedHint(e.source._codec));
4236
+ } else if (e.isAudioTrack()) {
4237
+ let t = this.format.getSupportedAudioCodecs();
4238
+ if (t.length === 0) throw Error(`${this.format._name} does not support audio tracks.` + this.format._codecUnsupportedHint(e.source._codec));
4239
+ if (!t.includes(e.source._codec)) throw Error(`Codec '${e.source._codec}' cannot be contained within ${this.format._name}. Supported audio codecs are: ${t.map((e) => `'${e}'`).join(", ")}.` + this.format._codecUnsupportedHint(e.source._codec));
4240
+ } else if (e.isSubtitleTrack()) {
4241
+ let t = this.format.getSupportedSubtitleCodecs();
4242
+ if (t.length === 0) throw Error(`${this.format._name} does not support subtitle tracks.` + this.format._codecUnsupportedHint(e.source._codec));
4243
+ if (!t.includes(e.source._codec)) throw Error(`Codec '${e.source._codec}' cannot be contained within ${this.format._name}. Supported subtitle codecs are: ${t.map((e) => `'${e}'`).join(", ")}.` + this.format._codecUnsupportedHint(e.source._codec));
4244
+ }
4245
+ return this.tracks.push(e), e.source._connectedTrack = e, e;
4246
+ }
4247
+ hasEnoughTracks() {
4248
+ let e = this.format.getSupportedTrackCounts();
4249
+ for (let t of Nn) if (this.tracks.reduce((e, n) => e + +(n.type === t), 0) < e[t].min) return !1;
4250
+ let t = e.total.min;
4251
+ return !(this.tracks.length < t);
4252
+ }
4253
+ async start() {
4254
+ let e = this.format.getSupportedTrackCounts();
4255
+ for (let t of Nn) {
4256
+ let n = this.tracks.reduce((e, n) => e + +(n.type === t), 0), r = e[t].min;
4257
+ if (n < r) throw Error(r === e[t].max ? `${this.format._name} requires exactly ${r} ${t} track${r === 1 ? "" : "s"}.` : `${this.format._name} requires at least ${r} ${t} track${r === 1 ? "" : "s"}.`);
4258
+ }
4259
+ let t = e.total.min;
4260
+ if (this.tracks.length < t) throw Error(t === e.total.max ? `${this.format._name} requires exactly ${t} track${t === 1 ? "" : "s"}.` : `${this.format._name} requires at least ${t} track${t === 1 ? "" : "s"}.`);
4261
+ if (this.state === "canceled") throw Error("Output has been canceled.");
4262
+ return this._startPromise ? (A._warn("Output has already been started."), this._startPromise) : this._startPromise = (async () => {
4263
+ this.state = "started";
4264
+ let e = this._mutex.acquire();
4265
+ try {
4266
+ await this._muxer.start();
4267
+ let e = this.tracks.map((e) => e.source._start());
4268
+ await Promise.all(e);
4269
+ } finally {
4270
+ (await e)();
4271
+ }
4272
+ })();
4273
+ }
4274
+ getMimeType() {
4275
+ return this._muxer.getMimeType();
4276
+ }
4277
+ async cancel() {
4278
+ if (this._cancelPromise) return A._warn("Output has already been canceled."), this._cancelPromise;
4279
+ if (this.state === "finalizing" || this.state === "finalized") {
4280
+ this.state === "finalized" && A._warn("Output has already been finalized.");
4281
+ return;
4282
+ }
4283
+ return this._cancelPromise = (async () => {
4284
+ this.state = "canceled";
4285
+ let e = await this._mutex.acquire();
4286
+ try {
4287
+ let e = this.tracks.map((e) => e.source._flushOrWaitForOngoingClose(!0));
4288
+ await Promise.all(e), await Promise.all([...this._unfinalizedTargets].map((e) => e._close())), this._unfinalizedTargets.clear();
4289
+ } finally {
4290
+ e();
4291
+ }
4292
+ })();
4293
+ }
4294
+ async finalize() {
4295
+ if (this.state === "pending") throw Error("Cannot finalize before starting.");
4296
+ if (this.state === "canceled") throw Error("Cannot finalize after canceling.");
4297
+ return this._finalizePromise ? (A._warn("Output has already been finalized."), this._finalizePromise) : this._finalizePromise = (async () => {
4298
+ this.state = "finalizing";
4299
+ let e = await this._mutex.acquire();
4300
+ try {
4301
+ let e = this.tracks.map((e) => e.source._flushOrWaitForOngoingClose(!1));
4302
+ if (await Promise.all(e), await this._muxer.finalize(), this._rootWriterPromise) {
4303
+ let e = await this._rootWriterPromise;
4304
+ e.finalized || (await e.flush(), await e.finalize());
4305
+ }
4306
+ this._onFinalize && await this._onFinalize(), this.state = "finalized";
4307
+ } finally {
4308
+ await Promise.all([...this._unfinalizedTargets].map((e) => e._close().catch(() => {}))), this._unfinalizedTargets.clear(), e();
4309
+ }
4310
+ })();
4311
+ }
4312
+ }, Bn = Symbol.for("mediabunny loaded");
4313
+ globalThis[Bn] && A._error("[WARNING]\nMediabunny was loaded twice. This will likely cause Mediabunny not to work correctly. Check if multiple dependencies are importing different versions of Mediabunny, or if something is being bundled incorrectly."), globalThis[Bn] = !0;
4314
+ //#endregion
4315
+ export { cn as BufferTarget, Dn as CanvasSource, zn as Output, Mn as WebMOutputFormat };