rx-player 4.0.0-beta.0 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/.eslintrc.js +8 -0
  2. package/CHANGELOG.md +93 -0
  3. package/CONTRIBUTING.md +48 -168
  4. package/FILES.md +40 -92
  5. package/VERSION +1 -1
  6. package/dist/_esm5.processed/compat/browser_detection.d.ts +25 -12
  7. package/dist/_esm5.processed/compat/browser_detection.js +85 -38
  8. package/dist/_esm5.processed/compat/can_reuse_media_keys.js +2 -2
  9. package/dist/_esm5.processed/compat/eme/close_session.js +2 -2
  10. package/dist/_esm5.processed/compat/eme/load_session.js +1 -1
  11. package/dist/_esm5.processed/compat/event_listeners.js +1 -1
  12. package/dist/_esm5.processed/compat/has_issues_with_high_media_source_duration.d.ts +21 -0
  13. package/dist/_esm5.processed/compat/has_issues_with_high_media_source_duration.js +26 -0
  14. package/dist/_esm5.processed/config.d.ts +4 -0
  15. package/dist/_esm5.processed/core/adaptive/adaptive_representation_selector.js +9 -6
  16. package/dist/_esm5.processed/core/adaptive/buffer_based_chooser.d.ts +18 -1
  17. package/dist/_esm5.processed/core/adaptive/buffer_based_chooser.js +106 -25
  18. package/dist/_esm5.processed/core/adaptive/guess_based_chooser.js +6 -6
  19. package/dist/_esm5.processed/core/adaptive/network_analyzer.js +8 -5
  20. package/dist/_esm5.processed/core/adaptive/utils/representation_score_calculator.d.ts +19 -1
  21. package/dist/_esm5.processed/core/adaptive/utils/representation_score_calculator.js +1 -1
  22. package/dist/_esm5.processed/core/api/debug/buffer_graph.d.ts +28 -0
  23. package/dist/_esm5.processed/core/api/debug/buffer_graph.js +175 -0
  24. package/dist/_esm5.processed/core/api/debug/buffer_size_graph.d.ts +10 -0
  25. package/dist/_esm5.processed/core/api/debug/buffer_size_graph.js +104 -0
  26. package/dist/_esm5.processed/core/api/debug/constants.d.ts +2 -0
  27. package/dist/_esm5.processed/core/api/debug/constants.js +2 -0
  28. package/dist/_esm5.processed/core/api/debug/index.d.ts +2 -0
  29. package/dist/_esm5.processed/core/api/debug/index.js +2 -0
  30. package/dist/_esm5.processed/core/api/debug/modules/general_info.d.ts +3 -0
  31. package/dist/_esm5.processed/core/api/debug/modules/general_info.js +180 -0
  32. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_content.d.ts +4 -0
  33. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_content.js +121 -0
  34. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_size.d.ts +3 -0
  35. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_size.js +35 -0
  36. package/dist/_esm5.processed/core/api/debug/render.d.ts +3 -0
  37. package/dist/_esm5.processed/core/api/debug/render.js +32 -0
  38. package/dist/_esm5.processed/core/api/debug/utils.d.ts +39 -0
  39. package/dist/_esm5.processed/core/api/debug/utils.js +57 -0
  40. package/dist/_esm5.processed/core/api/playback_observer.js +4 -2
  41. package/dist/_esm5.processed/core/api/public_api.d.ts +60 -3
  42. package/dist/_esm5.processed/core/api/public_api.js +280 -60
  43. package/dist/_esm5.processed/core/api/track_management/media_element_tracks_store.js +10 -1
  44. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.d.ts +13 -1
  45. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.js +30 -15
  46. package/dist/_esm5.processed/core/api/track_management/tracks_store.d.ts +3 -1
  47. package/dist/_esm5.processed/core/api/track_management/tracks_store.js +67 -152
  48. package/dist/_esm5.processed/core/api/utils.d.ts +10 -0
  49. package/dist/_esm5.processed/core/api/utils.js +23 -3
  50. package/dist/_esm5.processed/core/decrypt/__tests__/__global__/utils.d.ts +27 -8
  51. package/dist/_esm5.processed/core/decrypt/__tests__/__global__/utils.js +28 -7
  52. package/dist/_esm5.processed/core/decrypt/attach_media_keys.js +1 -1
  53. package/dist/_esm5.processed/core/decrypt/content_decryptor.js +1 -1
  54. package/dist/_esm5.processed/core/decrypt/find_key_system.js +29 -6
  55. package/dist/_esm5.processed/core/decrypt/session_events_listener.js +42 -32
  56. package/dist/_esm5.processed/core/decrypt/utils/check_key_statuses.js +4 -0
  57. package/dist/_esm5.processed/core/decrypt/utils/clean_old_loaded_sessions.js +2 -0
  58. package/dist/_esm5.processed/core/decrypt/utils/loaded_sessions_store.js +5 -1
  59. package/dist/_esm5.processed/core/fetchers/cdn_prioritizer.d.ts +17 -8
  60. package/dist/_esm5.processed/core/fetchers/cdn_prioritizer.js +10 -6
  61. package/dist/_esm5.processed/core/fetchers/manifest/manifest_fetcher.js +5 -4
  62. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.d.ts +22 -5
  63. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.js +37 -21
  64. package/dist/_esm5.processed/core/fetchers/segment/task_prioritizer.js +21 -23
  65. package/dist/_esm5.processed/core/fetchers/utils/schedule_request.js +17 -7
  66. package/dist/_esm5.processed/core/init/directfile_content_initializer.js +2 -2
  67. package/dist/_esm5.processed/core/init/media_source_content_initializer.js +74 -41
  68. package/dist/_esm5.processed/core/init/types.d.ts +9 -1
  69. package/dist/_esm5.processed/core/init/utils/content_time_boundaries_observer.d.ts +28 -1
  70. package/dist/_esm5.processed/core/init/utils/content_time_boundaries_observer.js +24 -11
  71. package/dist/_esm5.processed/core/init/utils/create_media_source.js +3 -12
  72. package/dist/_esm5.processed/core/init/utils/end_of_stream.js +6 -3
  73. package/dist/_esm5.processed/core/init/utils/get_loaded_reference.js +2 -1
  74. package/dist/_esm5.processed/core/init/utils/initial_seek_and_play.js +9 -5
  75. package/dist/_esm5.processed/core/init/utils/initialize_content_decryption.js +2 -1
  76. package/dist/_esm5.processed/core/init/utils/media_source_duration_updater.d.ts +58 -0
  77. package/dist/_esm5.processed/core/init/utils/{media_duration_updater.js → media_source_duration_updater.js} +87 -86
  78. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.d.ts +36 -2
  79. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.js +83 -3
  80. package/dist/_esm5.processed/core/init/utils/stream_events_emitter/stream_events_emitter.js +6 -4
  81. package/dist/_esm5.processed/core/init/utils/throw_on_media_error.js +1 -1
  82. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.d.ts +18 -7
  83. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +38 -50
  84. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.d.ts +8 -0
  85. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +16 -2
  86. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.d.ts +8 -0
  87. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +12 -0
  88. package/dist/_esm5.processed/core/segment_buffers/implementations/types.d.ts +11 -4
  89. package/dist/_esm5.processed/core/segment_buffers/index.d.ts +2 -2
  90. package/dist/_esm5.processed/core/segment_buffers/segment_buffers_store.js +13 -9
  91. package/dist/_esm5.processed/core/stream/adaptation/adaptation_stream.js +30 -16
  92. package/dist/_esm5.processed/core/stream/adaptation/utils/create_representation_estimator.d.ts +47 -0
  93. package/dist/_esm5.processed/core/stream/adaptation/utils/create_representation_estimator.js +70 -0
  94. package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.js +41 -20
  95. package/dist/_esm5.processed/core/stream/period/period_stream.js +12 -11
  96. package/dist/_esm5.processed/core/stream/representation/representation_stream.js +37 -28
  97. package/dist/_esm5.processed/core/stream/representation/utils/append_segment_to_buffer.d.ts +4 -2
  98. package/dist/_esm5.processed/core/stream/representation/utils/append_segment_to_buffer.js +3 -3
  99. package/dist/_esm5.processed/core/stream/representation/utils/downloading_queue.js +16 -6
  100. package/dist/_esm5.processed/core/stream/representation/utils/push_init_segment.d.ts +3 -2
  101. package/dist/_esm5.processed/core/stream/representation/utils/push_init_segment.js +8 -8
  102. package/dist/_esm5.processed/core/stream/representation/utils/push_media_segment.d.ts +2 -2
  103. package/dist/_esm5.processed/core/stream/representation/utils/push_media_segment.js +2 -3
  104. package/dist/_esm5.processed/core/stream/utils/create_reload_request.js +1 -1
  105. package/dist/_esm5.processed/default_config.d.ts +41 -0
  106. package/dist/_esm5.processed/default_config.js +46 -2
  107. package/dist/_esm5.processed/errors/index.d.ts +2 -2
  108. package/dist/_esm5.processed/errors/media_error.d.ts +23 -1
  109. package/dist/_esm5.processed/errors/media_error.js +18 -5
  110. package/dist/_esm5.processed/experimental/features/debug_element.d.ts +8 -0
  111. package/dist/_esm5.processed/experimental/features/debug_element.js +10 -0
  112. package/dist/_esm5.processed/experimental/features/index.d.ts +1 -0
  113. package/dist/_esm5.processed/experimental/features/index.js +1 -0
  114. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/load_and_push_segment.d.ts +1 -1
  115. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/load_and_push_segment.js +8 -7
  116. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.js +7 -4
  117. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +24 -12
  118. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/index.js +0 -2
  119. package/dist/_esm5.processed/features/features_object.js +1 -0
  120. package/dist/_esm5.processed/features/initialize_features.js +13 -10
  121. package/dist/_esm5.processed/features/types.d.ts +3 -0
  122. package/dist/_esm5.processed/manifest/adaptation.d.ts +21 -2
  123. package/dist/_esm5.processed/manifest/adaptation.js +80 -1
  124. package/dist/_esm5.processed/manifest/manifest.js +2 -0
  125. package/dist/_esm5.processed/manifest/period.js +2 -2
  126. package/dist/_esm5.processed/manifest/representation.d.ts +33 -2
  127. package/dist/_esm5.processed/manifest/representation.js +32 -4
  128. package/dist/_esm5.processed/manifest/utils.js +1 -3
  129. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_adaptation_sets.js +105 -137
  130. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_representations.js +25 -5
  131. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/parse_from_document.d.ts +1 -1
  132. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/parse_from_document.js +1 -1
  133. package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.js +1 -0
  134. package/dist/_esm5.processed/public_types.d.ts +13 -3
  135. package/dist/_esm5.processed/tools/TextTrackRenderer/text_track_renderer.js +1 -1
  136. package/dist/_esm5.processed/transports/dash/add_segment_integrity_checks_to_loader.js +15 -11
  137. package/dist/_esm5.processed/transports/dash/low_latency_segment_loader.js +2 -2
  138. package/dist/_esm5.processed/transports/dash/manifest_parser.js +1 -1
  139. package/dist/_esm5.processed/transports/dash/segment_loader.js +4 -4
  140. package/dist/_esm5.processed/transports/local/segment_loader.js +13 -26
  141. package/dist/_esm5.processed/transports/smooth/isobmff/create_boxes.d.ts +4 -6
  142. package/dist/_esm5.processed/transports/smooth/isobmff/create_boxes.js +4 -6
  143. package/dist/_esm5.processed/transports/smooth/segment_loader.js +4 -4
  144. package/dist/_esm5.processed/transports/utils/call_custom_manifest_loader.js +3 -3
  145. package/dist/_esm5.processed/utils/cancellable_sleep.js +4 -10
  146. package/dist/_esm5.processed/utils/create_cancellable_promise.d.ts +26 -0
  147. package/dist/_esm5.processed/utils/create_cancellable_promise.js +52 -0
  148. package/dist/_esm5.processed/utils/is_null_or_undefined.d.ts +1 -1
  149. package/dist/_esm5.processed/utils/is_null_or_undefined.js +1 -1
  150. package/dist/_esm5.processed/utils/reference.js +6 -0
  151. package/dist/_esm5.processed/utils/request/xhr.js +1 -1
  152. package/dist/_esm5.processed/utils/task_canceller.d.ts +34 -15
  153. package/dist/_esm5.processed/utils/task_canceller.js +55 -22
  154. package/dist/mpd-parser.wasm +0 -0
  155. package/dist/rx-player.js +5424 -4712
  156. package/dist/rx-player.min.js +1 -1
  157. package/jest.config.js +1 -5
  158. package/package.json +44 -40
  159. package/scripts/build/constants.d.ts +1 -0
  160. package/scripts/build/generate_build.js +1 -1
  161. package/scripts/fast_demo_build.js +40 -40
  162. package/scripts/generate_full_demo.js +1 -1
  163. package/sonar-project.properties +1 -1
  164. package/src/compat/browser_detection.ts +105 -52
  165. package/src/compat/can_reuse_media_keys.ts +5 -2
  166. package/src/compat/eme/close_session.ts +2 -2
  167. package/src/compat/eme/load_session.ts +1 -1
  168. package/src/compat/event_listeners.ts +1 -1
  169. package/src/compat/has_issues_with_high_media_source_duration.ts +27 -0
  170. package/src/core/adaptive/__tests__/buffer_based_chooser.test.ts +147 -48
  171. package/src/core/adaptive/adaptive_representation_selector.ts +11 -6
  172. package/src/core/adaptive/buffer_based_chooser.ts +144 -26
  173. package/src/core/adaptive/guess_based_chooser.ts +9 -8
  174. package/src/core/adaptive/network_analyzer.ts +9 -4
  175. package/src/core/adaptive/utils/representation_score_calculator.ts +22 -2
  176. package/src/core/api/debug/buffer_graph.ts +247 -0
  177. package/src/core/api/debug/buffer_size_graph.ts +130 -0
  178. package/src/core/api/debug/constants.ts +2 -0
  179. package/src/core/api/debug/index.ts +3 -0
  180. package/src/core/api/debug/modules/general_info.ts +184 -0
  181. package/src/core/api/debug/modules/segment_buffer_content.ts +155 -0
  182. package/src/core/api/debug/modules/segment_buffer_size.ts +48 -0
  183. package/src/core/api/debug/render.ts +40 -0
  184. package/src/core/api/debug/utils.ts +103 -0
  185. package/src/core/api/playback_observer.ts +5 -2
  186. package/src/core/api/public_api.ts +334 -73
  187. package/src/core/api/track_management/media_element_tracks_store.ts +17 -8
  188. package/src/core/api/track_management/track_dispatcher.ts +37 -14
  189. package/src/core/api/track_management/tracks_store.ts +77 -167
  190. package/src/core/api/utils.ts +29 -3
  191. package/src/core/decrypt/__tests__/__global__/utils.ts +61 -40
  192. package/src/core/decrypt/attach_media_keys.ts +1 -1
  193. package/src/core/decrypt/content_decryptor.ts +1 -1
  194. package/src/core/decrypt/find_key_system.ts +25 -11
  195. package/src/core/decrypt/session_events_listener.ts +45 -39
  196. package/src/core/decrypt/utils/check_key_statuses.ts +6 -0
  197. package/src/core/decrypt/utils/clean_old_loaded_sessions.ts +2 -1
  198. package/src/core/decrypt/utils/loaded_sessions_store.ts +8 -1
  199. package/src/core/fetchers/cdn_prioritizer.ts +18 -9
  200. package/src/core/fetchers/manifest/manifest_fetcher.ts +5 -4
  201. package/src/core/fetchers/segment/segment_fetcher.ts +36 -14
  202. package/src/core/fetchers/segment/task_prioritizer.ts +25 -30
  203. package/src/core/fetchers/utils/schedule_request.ts +18 -7
  204. package/src/core/init/directfile_content_initializer.ts +2 -1
  205. package/src/core/init/media_source_content_initializer.ts +89 -50
  206. package/src/core/init/types.ts +9 -1
  207. package/src/core/init/utils/content_time_boundaries_observer.ts +48 -12
  208. package/src/core/init/utils/create_media_source.ts +4 -16
  209. package/src/core/init/utils/end_of_stream.ts +6 -3
  210. package/src/core/init/utils/get_loaded_reference.ts +2 -1
  211. package/src/core/init/utils/initial_seek_and_play.ts +9 -5
  212. package/src/core/init/utils/initialize_content_decryption.ts +2 -1
  213. package/src/core/init/utils/{media_duration_updater.ts → media_source_duration_updater.ts} +103 -110
  214. package/src/core/init/utils/rebuffering_controller.ts +115 -4
  215. package/src/core/init/utils/stream_events_emitter/stream_events_emitter.ts +6 -4
  216. package/src/core/init/utils/throw_on_media_error.ts +1 -1
  217. package/src/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.ts +63 -66
  218. package/src/core/segment_buffers/implementations/text/html/html_text_segment_buffer.ts +20 -2
  219. package/src/core/segment_buffers/implementations/text/native/native_text_segment_buffer.ts +16 -0
  220. package/src/core/segment_buffers/implementations/types.ts +16 -4
  221. package/src/core/segment_buffers/index.ts +2 -0
  222. package/src/core/segment_buffers/segment_buffers_store.ts +16 -13
  223. package/src/core/stream/adaptation/adaptation_stream.ts +33 -19
  224. package/src/core/stream/adaptation/utils/create_representation_estimator.ts +114 -0
  225. package/src/core/stream/orchestrator/stream_orchestrator.ts +42 -20
  226. package/src/core/stream/period/period_stream.ts +13 -11
  227. package/src/core/stream/representation/representation_stream.ts +49 -37
  228. package/src/core/stream/representation/utils/append_segment_to_buffer.ts +9 -4
  229. package/src/core/stream/representation/utils/downloading_queue.ts +16 -4
  230. package/src/core/stream/representation/utils/push_init_segment.ts +11 -6
  231. package/src/core/stream/representation/utils/push_media_segment.ts +3 -3
  232. package/src/core/stream/utils/create_reload_request.ts +1 -1
  233. package/src/default_config.ts +59 -11
  234. package/src/errors/__tests__/media_error.test.ts +6 -6
  235. package/src/errors/index.ts +4 -1
  236. package/src/errors/media_error.ts +67 -1
  237. package/src/experimental/features/__tests__/debug_element.test.ts +26 -0
  238. package/src/experimental/features/debug_element.ts +13 -0
  239. package/src/experimental/features/index.ts +1 -0
  240. package/src/experimental/tools/VideoThumbnailLoader/load_and_push_segment.ts +10 -7
  241. package/src/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.ts +7 -4
  242. package/src/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.ts +25 -10
  243. package/src/experimental/tools/mediaCapabilitiesProber/index.ts +0 -4
  244. package/src/features/__tests__/initialize_features.test.ts +11 -0
  245. package/src/features/features_object.ts +1 -0
  246. package/src/features/initialize_features.ts +15 -10
  247. package/src/features/types.ts +9 -0
  248. package/src/manifest/__tests__/manifest.test.ts +7 -7
  249. package/src/manifest/__tests__/period.test.ts +90 -45
  250. package/src/manifest/adaptation.ts +96 -1
  251. package/src/manifest/manifest.ts +4 -0
  252. package/src/manifest/period.ts +4 -2
  253. package/src/manifest/representation.ts +77 -5
  254. package/src/manifest/utils.ts +1 -3
  255. package/src/parsers/manifest/dash/common/parse_adaptation_sets.ts +116 -151
  256. package/src/parsers/manifest/dash/common/parse_representations.ts +21 -4
  257. package/src/parsers/manifest/dash/js-parser/parse_from_document.ts +1 -1
  258. package/src/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.ts +1 -0
  259. package/src/parsers/texttracks/ttml/parse_ttml.ts +1 -1
  260. package/src/public_types.ts +16 -1
  261. package/src/tools/TextTrackRenderer/text_track_renderer.ts +1 -1
  262. package/src/transports/dash/add_segment_integrity_checks_to_loader.ts +31 -22
  263. package/src/transports/dash/low_latency_segment_loader.ts +2 -2
  264. package/src/transports/dash/manifest_parser.ts +1 -1
  265. package/src/transports/dash/segment_loader.ts +4 -4
  266. package/src/transports/local/segment_loader.ts +14 -30
  267. package/src/transports/smooth/isobmff/create_boxes.ts +4 -6
  268. package/src/transports/smooth/segment_loader.ts +4 -4
  269. package/src/transports/utils/call_custom_manifest_loader.ts +3 -3
  270. package/src/typings/globals.d.ts +21 -19
  271. package/src/utils/cancellable_sleep.ts +5 -14
  272. package/src/utils/create_cancellable_promise.ts +69 -0
  273. package/src/utils/is_null_or_undefined.ts +1 -1
  274. package/src/utils/reference.ts +6 -0
  275. package/src/utils/request/xhr.ts +1 -1
  276. package/src/utils/task_canceller.ts +63 -34
  277. package/tsconfig.json +1 -1
  278. package/tsconfig.modules.json +1 -1
  279. package/dist/_esm5.processed/core/init/utils/media_duration_updater.d.ts +0 -56
  280. package/locked_reps.js +0 -46
  281. package/scripts/doc-generator/construct_table_of_contents.js +0 -76
  282. package/scripts/doc-generator/convert_MD_to_HMTL.js +0 -26
  283. package/scripts/doc-generator/create_documentation.js +0 -331
  284. package/scripts/doc-generator/create_documentation_page.js +0 -209
  285. package/scripts/doc-generator/create_page.js +0 -210
  286. package/scripts/doc-generator/generate_header_html.js +0 -147
  287. package/scripts/doc-generator/generate_page_html.js +0 -115
  288. package/scripts/doc-generator/generate_page_list_html.js +0 -92
  289. package/scripts/doc-generator/generate_sidebar_html.js +0 -85
  290. package/scripts/doc-generator/get_search_data_for_content.js +0 -137
  291. package/scripts/doc-generator/index.js +0 -34
  292. package/scripts/doc-generator/parse_doc_configs.js +0 -327
  293. package/scripts/doc-generator/scripts/lunr.js +0 -10
  294. package/scripts/doc-generator/scripts/script.js +0 -451
  295. package/scripts/doc-generator/styles/code.css +0 -99
  296. package/scripts/doc-generator/styles/style.css +0 -835
  297. package/scripts/doc-generator/utils.js +0 -74
@@ -1,331 +0,0 @@
1
- const { promisify } = require("util");
2
- const fs = require("fs");
3
- const path = require("path");
4
- const parseDocConfigs = require("./parse_doc_configs.js");
5
- const createDocumentationPage = require("./create_documentation_page.js");
6
- const generateHeaderHtml = require("./generate_header_html.js");
7
- const generatePageListHtml = require("./generate_page_list_html.js");
8
- const generateSidebarHtml = require("./generate_sidebar_html.js");
9
- const {
10
- mkdirParent,
11
- toUriCompatibleRelativePath,
12
- } = require("./utils.js");
13
-
14
- async function createDirIfDoesntExist(dir) {
15
- const doesCSSOutDirExists = await promisify(fs.exists)(dir);
16
- if (!doesCSSOutDirExists) {
17
- try {
18
- await mkdirParent(dir);
19
- } catch (err) {
20
- const srcMessage = (err ?? {}).message ?? "Unknown error";
21
- console.error(`Error: Could not create "${dir}" directory: ${srcMessage}`);
22
- process.exit(1);
23
- }
24
- }
25
- }
26
-
27
- /**
28
- * Create documentation for the directory given into the ouput directory given.
29
- * @param {string} baseInDir
30
- * @param {string} baseOutDir
31
- * @param {Object} [options={}]
32
- * @param {Function} [options.getPageTitle] - Callback returning the name of the
33
- * page, based on the name of a single markdown document.
34
- * If not set, the page title will just be the corresponding markdown's title.
35
- * @param {Array.<string>} [options.css] - Optional CSS files which will be
36
- * linked to each generated page.
37
- * Should be the path to each of those.
38
- * @param {string|undefined} [options.version] - String indicating the current
39
- * version of the documented application.
40
- * @returns {Promise} - Resolve when done
41
- */
42
- async function createDocumentation(
43
- baseInDir,
44
- baseOutDir,
45
- options = {},
46
- ) {
47
- const { css } = options;
48
-
49
- // Copy CSS files
50
- const cssOutputDir = path.join(path.resolve(baseOutDir), "styles");
51
- const cssOutputPaths = css.map(cssFilepath => {
52
- return path.join(cssOutputDir, path.basename(cssFilepath));
53
- });
54
-
55
- if (css.length > 0) {
56
- await createDirIfDoesntExist(cssOutputDir);
57
- await Promise.all(css.map(async (cssInput, i) => {
58
- await promisify(fs.copyFile)(cssInput, cssOutputPaths[i]);
59
- }));
60
- }
61
-
62
- // Copy JavaScript file
63
- const scriptOutputDir = path.join(path.resolve(baseOutDir), "scripts");
64
- const scripts = [
65
- path.join(__dirname, "scripts/lunr.js"),
66
- path.join(__dirname, "scripts/script.js"),
67
- ];
68
- const scriptOutputPaths = scripts.map(s =>
69
- path.join(scriptOutputDir, path.basename(s)));
70
-
71
- await createDirIfDoesntExist(scriptOutputDir);
72
- await Promise.all(scripts.map(async (s, i) => {
73
- await promisify(fs.copyFile)(s, scriptOutputPaths[i]);
74
- }));
75
-
76
- // Construct tree listing categories, pages, and relations between them.
77
- const config = await parseDocConfigs(baseInDir, baseOutDir, options.version);
78
-
79
- if (config.favicon !== undefined && typeof config.favicon.srcPath === "string") {
80
- await copyFileToOutputDir(config.favicon.srcPath, baseInDir, baseOutDir);
81
- }
82
- if (config.logo !== undefined && typeof config.logo.srcPath === "string") {
83
- await copyFileToOutputDir(config.logo.srcPath, baseInDir, baseOutDir);
84
- }
85
-
86
-
87
- // Construct a dictionary of markdown files to the corresponding output file.
88
- // This can be useful to redirect links to other converted markdowns.
89
- const fileDict = config.links.reduce((acc, linkInfo) => {
90
- if (linkInfo.type !== "local-doc") {
91
- return acc;
92
- }
93
- return linkInfo.pages.reduce((acc2, pageInfo) => {
94
- if (pageInfo.isPageGroup) {
95
- return pageInfo.pages.reduce((acc3, subPageInfo) => {
96
- acc3[subPageInfo.inputFile] = subPageInfo.outputFile;
97
- return acc3;
98
- }, acc2);
99
- } else {
100
- acc2[pageInfo.inputFile] = pageInfo.outputFile;
101
- }
102
- return acc2;
103
- }, acc);
104
- }, {});
105
-
106
- const searchIndex = [];
107
-
108
- // Create documentation pages
109
- for (let linkIdx = 0; linkIdx < config.links.length; linkIdx++) {
110
- const currentLink = config.links[linkIdx];
111
- if (currentLink.type !== "local-doc") {
112
- continue;
113
- }
114
- for (let pageIdx = 0; pageIdx < currentLink.pages.length; pageIdx++) {
115
- const currentPage = currentLink.pages[pageIdx];
116
- if (!currentPage.isPageGroup) {
117
- const { inputFile, outputFile } = currentPage;
118
- await prepareAndCreateDocumentationPage({
119
- baseOutDir,
120
- config,
121
- cssOutputPaths,
122
- fileDict,
123
- inputFile,
124
- linkIdx,
125
- outputFile,
126
- pageIdxs: [pageIdx],
127
- pageTitle: options.getPageTitle === undefined ?
128
- currentPage.displayName :
129
- options.getPageTitle(currentPage.displayName),
130
- scriptOutputPaths,
131
- searchIndex,
132
- });
133
- } else {
134
- for (
135
- let subPageIdx = 0;
136
- subPageIdx < currentPage.pages.length;
137
- subPageIdx++
138
- ) {
139
- const currentSubPage = currentPage.pages[subPageIdx];
140
- const { inputFile, outputFile } = currentSubPage;
141
- await prepareAndCreateDocumentationPage({
142
- baseOutDir,
143
- config,
144
- cssOutputPaths,
145
- fileDict,
146
- inputFile,
147
- linkIdx,
148
- outputFile,
149
- pageIdxs: [pageIdx, subPageIdx],
150
- pageTitle: options.getPageTitle === undefined ?
151
- currentSubPage.displayName :
152
- options.getPageTitle(currentSubPage.displayName),
153
- scriptOutputPaths,
154
- searchIndex,
155
- });
156
- }
157
- }
158
- }
159
- }
160
-
161
- try {
162
- const searchIndexLoc = path.join(path.resolve(baseOutDir), "searchIndex.json");
163
- await promisify(fs.writeFile)(searchIndexLoc, JSON.stringify(searchIndex));
164
- } catch (err) {
165
- const srcMessage = (err ?? {}).message ?? "Unknown error";
166
- console.error(`Error: Could not create search index file: ${srcMessage}`);
167
- }
168
- };
169
-
170
- async function prepareAndCreateDocumentationPage({
171
- baseOutDir,
172
- config,
173
- cssOutputPaths,
174
- fileDict,
175
- inputFile,
176
- linkIdx,
177
- outputFile,
178
- pageIdxs,
179
- pageTitle,
180
- scriptOutputPaths,
181
- searchIndex,
182
- }) {
183
- // Create output directory if it does not exist
184
- const outDir = path.dirname(outputFile);
185
- await createDirIfDoesntExist(outDir);
186
-
187
- let logoInfo = null;
188
- if (config.logo !== undefined) {
189
- logoInfo = {};
190
- if (config.logo !== undefined && typeof config.logo.link === "string") {
191
- logoInfo.link = config.logo.link;
192
- }
193
- if (config.logo !== undefined && typeof config.logo.srcPath === "string") {
194
- const fullPath = path.join(baseOutDir, config.logo.srcPath);
195
- logoInfo.url = toUriCompatibleRelativePath(fullPath, outDir);
196
- }
197
- }
198
- let faviconUrl = null;
199
- if (config.favicon !== undefined && typeof config.favicon.srcPath === "string") {
200
- const fullPath = path.join(baseOutDir, config.favicon.srcPath);
201
- faviconUrl = toUriCompatibleRelativePath(fullPath, outDir);
202
- }
203
- const pageListHtml = generatePageListHtml(config.links, linkIdx, pageIdxs, outputFile);
204
- const navBarHtml = generateHeaderHtml(config, linkIdx, outputFile, logoInfo);
205
- const pages = config.links[linkIdx].pages;
206
- const sidebarHtml = generateSidebarHtml(pages, pageIdxs, outputFile, logoInfo);
207
-
208
- let prevPageConfig = null;
209
- let nextPageConfig = null;
210
- if (pageIdxs.length > 1 && pageIdxs[1] > 0) {
211
- prevPageConfig = pages[pageIdxs[0]].pages[pageIdxs[1] - 1];
212
- } else if (pageIdxs[0] > 0) {
213
- prevPageConfig = pages[pageIdxs[0] - 1];
214
- }
215
- if (pageIdxs.length > 1 && pageIdxs[1] < pages[pageIdxs[0]].pages.length - 1) {
216
- nextPageConfig = pages[pageIdxs[0]].pages[pageIdxs[1] + 1];
217
- } else if (pageIdxs[0] < pages.length - 1) {
218
- nextPageConfig = pages[pageIdxs[0] + 1];
219
- }
220
- const prevPageInfo = prevPageConfig === null ?
221
- null :
222
- getRelativePageInfo(prevPageConfig, outputFile);
223
- const nextPageInfo = nextPageConfig === null ?
224
- null :
225
- getRelativePageInfo(nextPageConfig, outputFile);
226
-
227
- const cssUrls = cssOutputPaths
228
- .map(cssOutput => toUriCompatibleRelativePath(cssOutput, outDir));
229
- const scriptUrls = scriptOutputPaths
230
- .map(s => toUriCompatibleRelativePath(s, outDir));
231
-
232
- // add link translation to options
233
- const linkTranslator = linkTranslatorFactory(inputFile, outDir, fileDict);
234
- await createDocumentationPage({
235
- baseOutDir,
236
- cssUrls,
237
- faviconUrl,
238
- inputFile,
239
- linkTranslator,
240
- navBarHtml,
241
- nextPageInfo,
242
- outputFile,
243
- pageListHtml,
244
- pageTitle,
245
- prevPageInfo,
246
- scriptUrls,
247
- searchIndex,
248
- sidebarHtml,
249
- });
250
- }
251
-
252
- /**
253
- * Generate linkTranslator functions
254
- * @param {string} inputFile
255
- * @param {Object} fileDict
256
- * @returns {Function}
257
- */
258
- function linkTranslatorFactory(inputFile, outputDir, fileDict) {
259
- /**
260
- * Convert links to files that will be converted to the links of the
261
- * corresponding converted output files.
262
- * @param {string} link
263
- * @returns {string|undefined}
264
- */
265
- return (link) => {
266
- if (/^(?:[a-z]+:)/.test(link) || link[0] === "#") {
267
- return
268
- }
269
- const extname = path.extname(link);
270
- const indexOfAnchor = extname.indexOf("#");
271
-
272
- const anchor = indexOfAnchor > 0 ?
273
- extname.substring(indexOfAnchor) :
274
- "";
275
-
276
- const linkWithoutAnchor = link.substring(0, link.length - anchor.length);
277
- const completeLink = path.join(path.dirname(inputFile), linkWithoutAnchor);
278
- const normalizedLink = path.normalize(path.resolve(completeLink));
279
-
280
- const translation = fileDict[normalizedLink];
281
- if (translation === undefined) {
282
- console.warn("WARNING: Local link not found.\n",
283
- "File:", inputFile, "\n",
284
- "Link:", link, "\n");
285
- }
286
- return translation !== undefined ?
287
- toUriCompatibleRelativePath(translation, outputDir) + anchor :
288
- // TODO do something better?
289
- undefined;
290
- };
291
- }
292
-
293
- function getRelativePageInfo(
294
- pageConfig,
295
- currentPath
296
- ) {
297
- const {
298
- displayName: pDisplayName,
299
- outputFile: pOutputFile
300
- } = pageConfig.isPageGroup ?
301
- pageConfig.pages[0] :
302
- pageConfig;
303
-
304
- const relativeHref = toUriCompatibleRelativePath(pOutputFile, path.dirname(currentPath));
305
- return { name: pDisplayName, link: relativeHref };
306
- }
307
-
308
- async function copyFileToOutputDir(
309
- filePathFromInputDir,
310
- inputDir,
311
- outputDir
312
- ) {
313
- const inputPath = path.join(inputDir, filePathFromInputDir);
314
- const outputPath = path.join(outputDir, filePathFromInputDir);
315
- const doesOutDirExists = await promisify(fs.exists)(path.dirname(outputPath));
316
- if (!doesOutDirExists) {
317
- try {
318
- await mkdirParent(path.dirname(outputPath));
319
- } catch (err) {
320
- const srcMessage = (err ?? {}).message ?? "Unknown error";
321
- console.error(`Error: Could not create "${outputPath}" directory: ${srcMessage}`);
322
- process.exit(1);
323
- }
324
- }
325
- const doesOutFileExist = await promisify(fs.exists)(outputPath);
326
- if (!doesOutFileExist) {
327
- await promisify(fs.copyFile)(inputPath, outputPath);
328
- }
329
- }
330
-
331
- module.exports = createDocumentation;
@@ -1,209 +0,0 @@
1
- const { promisify } = require("util");
2
- const cheerio = require("cheerio");
3
- const fs = require("fs");
4
- const path = require("path");
5
- const getSearchDataForContent = require("./get_search_data_for_content.js");
6
- const convertMDToHTML = require("./convert_MD_to_HMTL.js");
7
- const constructTableOfContents = require("./construct_table_of_contents.js");
8
- const generatePageHtml = require("./generate_page_html.js");
9
- const {
10
- mkdirParent,
11
- toUriCompatibleRelativePath,
12
- } = require("./utils.js");
13
-
14
- /**
15
- * Create and write HTML page output file from the markdown input file.
16
- * @param {Object} options
17
- * @returns {Promise}
18
- */
19
- module.exports = async function createDocumentationPage({
20
- // Absolute path to the root dir where all outputed files will be
21
- baseOutDir,
22
- // Relative CSS URLs on this page
23
- cssUrls,
24
- // Eventual URL to the favicon
25
- faviconUrl,
26
- // Absolute path to the file that should be converted
27
- inputFile,
28
- // Function translating links in Markdown files to an URL form to the right file
29
- linkTranslator,
30
- // HTML string for the navbar (the header on the top of the page)
31
- navBarHtml,
32
- // Information relative to the next documentation page, `null` if none.
33
- nextPageInfo,
34
- // Absolute path where the generated page should be generated.
35
- outputFile,
36
- // HTML string for the complete list of documentation pages with links
37
- pageListHtml,
38
- // Title of the corresponding HTML page
39
- pageTitle,
40
- // Information relative to the previous documentation page, `null` if none.
41
- prevPageInfo,
42
- // Relative JS URLs on this page
43
- scriptUrls,
44
- // Array corresponding to the complete search index.
45
- // It will be completed with data present in this file.
46
- searchIndex,
47
- // HTML string for the sidebar
48
- sidebarHtml,
49
- }) {
50
- const rootUrl = toUriCompatibleRelativePath(
51
- path.resolve(baseOutDir),
52
- path.dirname(outputFile)
53
- );
54
- const outputUrlFromRoot = toUriCompatibleRelativePath(outputFile, baseOutDir);
55
-
56
- const outputDir = path.dirname(outputFile);
57
- let data;
58
- try {
59
- data = await promisify(fs.readFile)(inputFile, "utf8");
60
- } catch (err) {
61
- /* eslint-disable no-console */
62
- console.error("error reading file:", err);
63
- /* eslint-enable no-console */
64
- return;
65
- }
66
- const inputDir = path.dirname(inputFile);
67
- const { content, tocMd, nbTocElements } = constructTableOfContents(data);
68
-
69
- let contentHtml = await parseMD(content, inputDir, outputDir, linkTranslator);
70
- const searchData = getSearchDataForContent(contentHtml);
71
- searchIndex.push({
72
- file: outputUrlFromRoot,
73
- index: searchData,
74
- });
75
- contentHtml += constructNextPreviousPage(prevPageInfo, nextPageInfo);
76
-
77
- const tocHtml = nbTocElements > 1 ?
78
- constructTocBarHtml(tocMd) :
79
- "";
80
- const html = generatePageHtml({
81
- contentHtml,
82
- cssUrls,
83
- faviconUrl,
84
- navBarHtml,
85
- pageListHtml,
86
- rootUrl,
87
- scriptUrls,
88
- sidebarHtml,
89
- title: pageTitle,
90
- tocHtml,
91
- });
92
-
93
- try {
94
- await promisify(fs.writeFile)(outputFile, html);
95
- } catch (err) {
96
- /* eslint-disable no-console */
97
- console.error("error writing file:", err);
98
- /* eslint-enable no-console */
99
- return;
100
- }
101
- };
102
-
103
-
104
- async function updateMediaTag(mediaTag, inputDir, outputDir) {
105
- if (!mediaTag.attr("src")) {
106
- return;
107
- }
108
- const inputFile = path.join(inputDir, mediaTag.attr("src"));
109
- const outputFile = path.join(outputDir, mediaTag.attr("src"));
110
- if (await promisify(fs.exists)(outputFile)) {
111
- return;
112
- }
113
- const outDir = path.dirname(outputFile);
114
- const doesOutDirExists = await promisify(fs.exists)(outDir);
115
- if (!doesOutDirExists) {
116
- try {
117
- await mkdirParent(outDir);
118
- } catch (err) {
119
- const srcMessage = (err ?? {}).message ?? "Unknown error";
120
- console.error(`Error: Could not create "${outDir}" directory: ${srcMessage}`);
121
- process.exit(1);
122
- }
123
- }
124
- await promisify(fs.copyFile)(inputFile, outputFile);
125
- }
126
-
127
- function constructNextPreviousPage(prevPageInfo, nextPageInfo) {
128
- if (prevPageInfo === null && nextPageInfo === null) {
129
- return "";
130
- }
131
-
132
- const prevPageElt = createNextPrevElt(prevPageInfo, false);
133
- const nextPageElt = createNextPrevElt(nextPageInfo, true);
134
- return `<nav class="next-previous-page-wrapper" aria-label="Navigate between pages">` +
135
- prevPageElt +
136
- nextPageElt +
137
- `</nav>`;
138
-
139
- function createNextPrevElt(pageInfo, isNext) {
140
- const base = `<div class="next-or-previous-page${isNext ? " next-page" : ""}">`;
141
- if (pageInfo === null) {
142
- return base + "</div>";
143
- }
144
- return base +
145
- `<a class="next-or-previous-page-link" href="${pageInfo.link}">` +
146
- `<div class="next-or-previous-page-link-label">` +
147
- (isNext ? "Next" : "Previous") +
148
- "</div>" +
149
- `<div class="next-or-previous-page-link-name">${pageInfo.name}</div>` +
150
- "</a></div>";
151
- }
152
- }
153
-
154
- /**
155
- * Convert Markdown to HTML.
156
- * @param {string} data - Markdown to convert
157
- * @param {string} inputDir - Directory the Markdown file is in.
158
- * Can be used to copy image/video/audio files.
159
- * @param {string} outputDir - Directory the HTML file will be in.
160
- * Can be used to copy image/video/audio files.
161
- * @param {Function|null|undefined} linkTranslator - Allow to translate links
162
- * from markdown to HTML. Is given the orginal link in the markdown and should
163
- * return the converted link.
164
- * If null or undefined, the links won't be converted.
165
- * @returns {string}
166
- */
167
- async function parseMD(data, inputDir, outputDir, linkTranslator) {
168
- // TODO I don't understand Cheerio/Jquery here, that's plain ugly
169
- // use markdown-it plugin instead?
170
- const $ = cheerio.load(convertMDToHTML(data));
171
-
172
- if (linkTranslator) {
173
- $("a").each((_, elem) => {
174
- const href = $(elem).attr("href");
175
- if (typeof href === "string") {
176
- $(elem).attr("href", linkTranslator(href));
177
- }
178
- });
179
- }
180
-
181
- const imgTags = $("img").toArray();
182
- for (let i = 0; i < imgTags.length; i++) {
183
- await updateMediaTag($(imgTags[i]), inputDir, outputDir);
184
- }
185
- const audioTags = $("audio").toArray();
186
- for (let i = 0; i < audioTags.length; i++) {
187
- await updateMediaTag($(audioTags[i]), inputDir, outputDir);
188
- }
189
- const videoTags = $("video").toArray();
190
- for (let i = 0; i < videoTags.length; i++) {
191
- await updateMediaTag($(videoTags[i]), inputDir, outputDir);
192
- }
193
- return $.html();
194
- }
195
-
196
- /**
197
- * Construct the table of contents part of the HTML page, containing various
198
- * links to the current documentation page.
199
- * @param {string} toc - Markdown for the table of contents under a list form.
200
- * @returns {string} - sidebar div tag
201
- */
202
- function constructTocBarHtml(tocMd) {
203
- const tocHtml = convertMDToHTML(tocMd);
204
- return "<div class=\"tocbar-wrapper\">" +
205
- "<div class=\"tocbar\">" +
206
- tocHtml +
207
- "</div>" +
208
- "</div>";
209
- }