rx-player 4.0.0-beta.1 → 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 (169) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/CONTRIBUTING.md +48 -168
  3. package/FILES.md +40 -92
  4. package/VERSION +1 -1
  5. package/dist/_esm5.processed/compat/browser_detection.d.ts +3 -1
  6. package/dist/_esm5.processed/compat/browser_detection.js +7 -2
  7. package/dist/_esm5.processed/compat/eme/load_session.js +1 -1
  8. package/dist/_esm5.processed/compat/has_issues_with_high_media_source_duration.d.ts +21 -0
  9. package/dist/_esm5.processed/compat/has_issues_with_high_media_source_duration.js +26 -0
  10. package/dist/_esm5.processed/config.d.ts +2 -0
  11. package/dist/_esm5.processed/core/adaptive/adaptive_representation_selector.js +5 -4
  12. package/dist/_esm5.processed/core/adaptive/buffer_based_chooser.d.ts +18 -1
  13. package/dist/_esm5.processed/core/adaptive/buffer_based_chooser.js +106 -25
  14. package/dist/_esm5.processed/core/adaptive/guess_based_chooser.js +6 -6
  15. package/dist/_esm5.processed/core/adaptive/network_analyzer.js +8 -5
  16. package/dist/_esm5.processed/core/adaptive/utils/representation_score_calculator.d.ts +19 -1
  17. package/dist/_esm5.processed/core/adaptive/utils/representation_score_calculator.js +1 -1
  18. package/dist/_esm5.processed/core/api/debug/render.js +1 -1
  19. package/dist/_esm5.processed/core/api/playback_observer.js +1 -0
  20. package/dist/_esm5.processed/core/api/public_api.d.ts +54 -1
  21. package/dist/_esm5.processed/core/api/public_api.js +232 -35
  22. package/dist/_esm5.processed/core/api/track_management/media_element_tracks_store.js +10 -1
  23. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.d.ts +13 -1
  24. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.js +30 -15
  25. package/dist/_esm5.processed/core/api/track_management/tracks_store.d.ts +3 -1
  26. package/dist/_esm5.processed/core/api/track_management/tracks_store.js +67 -152
  27. package/dist/_esm5.processed/core/api/utils.d.ts +10 -0
  28. package/dist/_esm5.processed/core/api/utils.js +20 -0
  29. package/dist/_esm5.processed/core/decrypt/session_events_listener.js +7 -1
  30. package/dist/_esm5.processed/core/decrypt/utils/clean_old_loaded_sessions.js +2 -0
  31. package/dist/_esm5.processed/core/decrypt/utils/loaded_sessions_store.js +5 -1
  32. package/dist/_esm5.processed/core/init/directfile_content_initializer.js +1 -1
  33. package/dist/_esm5.processed/core/init/media_source_content_initializer.js +47 -10
  34. package/dist/_esm5.processed/core/init/types.d.ts +9 -1
  35. package/dist/_esm5.processed/core/init/utils/content_time_boundaries_observer.d.ts +28 -1
  36. package/dist/_esm5.processed/core/init/utils/content_time_boundaries_observer.js +22 -9
  37. package/dist/_esm5.processed/core/init/utils/media_source_duration_updater.d.ts +58 -0
  38. package/dist/_esm5.processed/core/init/utils/{media_duration_updater.js → media_source_duration_updater.js} +84 -87
  39. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.d.ts +36 -2
  40. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.js +82 -2
  41. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.d.ts +18 -7
  42. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +31 -40
  43. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.d.ts +8 -0
  44. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +12 -0
  45. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.d.ts +8 -0
  46. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +12 -0
  47. package/dist/_esm5.processed/core/segment_buffers/implementations/types.d.ts +11 -4
  48. package/dist/_esm5.processed/core/segment_buffers/index.d.ts +2 -2
  49. package/dist/_esm5.processed/core/stream/adaptation/utils/create_representation_estimator.d.ts +47 -0
  50. package/dist/_esm5.processed/core/stream/adaptation/utils/create_representation_estimator.js +70 -0
  51. package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.js +15 -8
  52. package/dist/_esm5.processed/core/stream/period/period_stream.js +1 -1
  53. package/dist/_esm5.processed/core/stream/representation/representation_stream.js +22 -13
  54. package/dist/_esm5.processed/core/stream/representation/utils/append_segment_to_buffer.d.ts +4 -2
  55. package/dist/_esm5.processed/core/stream/representation/utils/append_segment_to_buffer.js +2 -2
  56. package/dist/_esm5.processed/core/stream/representation/utils/push_init_segment.d.ts +3 -2
  57. package/dist/_esm5.processed/core/stream/representation/utils/push_init_segment.js +8 -8
  58. package/dist/_esm5.processed/core/stream/representation/utils/push_media_segment.d.ts +2 -2
  59. package/dist/_esm5.processed/core/stream/representation/utils/push_media_segment.js +2 -3
  60. package/dist/_esm5.processed/default_config.d.ts +25 -0
  61. package/dist/_esm5.processed/default_config.js +27 -2
  62. package/dist/_esm5.processed/errors/index.d.ts +2 -2
  63. package/dist/_esm5.processed/errors/media_error.d.ts +23 -1
  64. package/dist/_esm5.processed/errors/media_error.js +18 -5
  65. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/load_and_push_segment.d.ts +1 -1
  66. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/load_and_push_segment.js +8 -7
  67. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +17 -9
  68. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/index.js +0 -2
  69. package/dist/_esm5.processed/manifest/adaptation.d.ts +21 -2
  70. package/dist/_esm5.processed/manifest/adaptation.js +76 -1
  71. package/dist/_esm5.processed/manifest/manifest.js +1 -1
  72. package/dist/_esm5.processed/manifest/period.js +2 -2
  73. package/dist/_esm5.processed/manifest/representation.d.ts +33 -2
  74. package/dist/_esm5.processed/manifest/representation.js +21 -0
  75. package/dist/_esm5.processed/manifest/utils.js +1 -3
  76. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/parse_from_document.d.ts +1 -1
  77. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/parse_from_document.js +1 -1
  78. package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.js +1 -0
  79. package/dist/_esm5.processed/public_types.d.ts +13 -3
  80. package/dist/_esm5.processed/tools/TextTrackRenderer/text_track_renderer.js +1 -1
  81. package/dist/_esm5.processed/transports/smooth/isobmff/create_boxes.d.ts +4 -6
  82. package/dist/_esm5.processed/transports/smooth/isobmff/create_boxes.js +4 -6
  83. package/dist/_esm5.processed/utils/is_null_or_undefined.d.ts +1 -1
  84. package/dist/_esm5.processed/utils/is_null_or_undefined.js +1 -1
  85. package/dist/mpd-parser.wasm +0 -0
  86. package/dist/rx-player.js +4709 -4218
  87. package/dist/rx-player.min.js +1 -1
  88. package/package.json +42 -36
  89. package/scripts/build/generate_build.js +1 -1
  90. package/scripts/fast_demo_build.js +4 -3
  91. package/scripts/generate_full_demo.js +1 -1
  92. package/sonar-project.properties +1 -1
  93. package/src/compat/browser_detection.ts +7 -1
  94. package/src/compat/eme/load_session.ts +1 -1
  95. package/src/compat/has_issues_with_high_media_source_duration.ts +27 -0
  96. package/src/core/adaptive/__tests__/buffer_based_chooser.test.ts +147 -48
  97. package/src/core/adaptive/adaptive_representation_selector.ts +7 -4
  98. package/src/core/adaptive/buffer_based_chooser.ts +144 -26
  99. package/src/core/adaptive/guess_based_chooser.ts +9 -8
  100. package/src/core/adaptive/network_analyzer.ts +9 -4
  101. package/src/core/adaptive/utils/representation_score_calculator.ts +22 -2
  102. package/src/core/api/debug/render.ts +1 -1
  103. package/src/core/api/playback_observer.ts +1 -0
  104. package/src/core/api/public_api.ts +277 -44
  105. package/src/core/api/track_management/media_element_tracks_store.ts +17 -8
  106. package/src/core/api/track_management/track_dispatcher.ts +37 -14
  107. package/src/core/api/track_management/tracks_store.ts +77 -167
  108. package/src/core/api/utils.ts +26 -0
  109. package/src/core/decrypt/session_events_listener.ts +6 -1
  110. package/src/core/decrypt/utils/clean_old_loaded_sessions.ts +2 -1
  111. package/src/core/decrypt/utils/loaded_sessions_store.ts +8 -1
  112. package/src/core/init/directfile_content_initializer.ts +1 -0
  113. package/src/core/init/media_source_content_initializer.ts +52 -9
  114. package/src/core/init/types.ts +9 -1
  115. package/src/core/init/utils/content_time_boundaries_observer.ts +46 -10
  116. package/src/core/init/utils/{media_duration_updater.ts → media_source_duration_updater.ts} +100 -112
  117. package/src/core/init/utils/rebuffering_controller.ts +114 -3
  118. package/src/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.ts +56 -55
  119. package/src/core/segment_buffers/implementations/text/html/html_text_segment_buffer.ts +16 -0
  120. package/src/core/segment_buffers/implementations/text/native/native_text_segment_buffer.ts +16 -0
  121. package/src/core/segment_buffers/implementations/types.ts +16 -4
  122. package/src/core/segment_buffers/index.ts +2 -0
  123. package/src/core/stream/adaptation/utils/create_representation_estimator.ts +114 -0
  124. package/src/core/stream/orchestrator/stream_orchestrator.ts +16 -8
  125. package/src/core/stream/period/period_stream.ts +2 -1
  126. package/src/core/stream/representation/representation_stream.ts +34 -22
  127. package/src/core/stream/representation/utils/append_segment_to_buffer.ts +8 -3
  128. package/src/core/stream/representation/utils/push_init_segment.ts +11 -6
  129. package/src/core/stream/representation/utils/push_media_segment.ts +3 -3
  130. package/src/default_config.ts +29 -2
  131. package/src/errors/__tests__/media_error.test.ts +6 -6
  132. package/src/errors/index.ts +4 -1
  133. package/src/errors/media_error.ts +67 -1
  134. package/src/experimental/tools/VideoThumbnailLoader/load_and_push_segment.ts +10 -7
  135. package/src/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.ts +17 -6
  136. package/src/experimental/tools/mediaCapabilitiesProber/index.ts +0 -4
  137. package/src/manifest/__tests__/manifest.test.ts +7 -7
  138. package/src/manifest/__tests__/period.test.ts +90 -45
  139. package/src/manifest/adaptation.ts +89 -1
  140. package/src/manifest/manifest.ts +1 -1
  141. package/src/manifest/period.ts +4 -2
  142. package/src/manifest/representation.ts +67 -1
  143. package/src/manifest/utils.ts +1 -3
  144. package/src/parsers/manifest/dash/js-parser/parse_from_document.ts +1 -1
  145. package/src/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.ts +1 -0
  146. package/src/parsers/texttracks/ttml/parse_ttml.ts +1 -1
  147. package/src/public_types.ts +16 -1
  148. package/src/tools/TextTrackRenderer/text_track_renderer.ts +1 -1
  149. package/src/transports/smooth/isobmff/create_boxes.ts +4 -6
  150. package/src/typings/globals.d.ts +20 -20
  151. package/src/utils/is_null_or_undefined.ts +1 -1
  152. package/dist/_esm5.processed/core/init/utils/media_duration_updater.d.ts +0 -56
  153. package/scripts/doc-generator/construct_table_of_contents.js +0 -76
  154. package/scripts/doc-generator/convert_MD_to_HMTL.js +0 -26
  155. package/scripts/doc-generator/create_documentation.js +0 -331
  156. package/scripts/doc-generator/create_documentation_page.js +0 -209
  157. package/scripts/doc-generator/create_page.js +0 -210
  158. package/scripts/doc-generator/generate_header_html.js +0 -147
  159. package/scripts/doc-generator/generate_page_html.js +0 -115
  160. package/scripts/doc-generator/generate_page_list_html.js +0 -92
  161. package/scripts/doc-generator/generate_sidebar_html.js +0 -85
  162. package/scripts/doc-generator/get_search_data_for_content.js +0 -137
  163. package/scripts/doc-generator/index.js +0 -34
  164. package/scripts/doc-generator/parse_doc_configs.js +0 -327
  165. package/scripts/doc-generator/scripts/lunr.js +0 -10
  166. package/scripts/doc-generator/scripts/script.js +0 -451
  167. package/scripts/doc-generator/styles/code.css +0 -99
  168. package/scripts/doc-generator/styles/style.css +0 -835
  169. package/scripts/doc-generator/utils.js +0 -74
@@ -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
- }
@@ -1,210 +0,0 @@
1
- const { promisify } = require("util");
2
- const cheerio = require("cheerio");
3
- const fs = require("fs");
4
- const path = require("path");
5
- const buildSearchIndex = require("./build_search_index.js");
6
- const convertMDToHTML = require("./convert_MD_to_HMTL.js");
7
- const constructTableOfContents = require("./construct_table_of_contents.js");
8
- const constructHtml = require("./construct_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 URIs on this page
23
- cssUris,
24
- // Absolute path to the file that should be converted
25
- inputFile,
26
- // Function translating links in Markdown files to an URL form to the right file
27
- linkTranslator,
28
- // HTML string for the navbar (the header on the top of the page)
29
- navBarHtml,
30
- // Information relative to the next documentation page, `null` if none.
31
- nextPageInfo,
32
- // Absolute path where the generated page should be generated.
33
- outputFile,
34
- // Title of the corresponding HTML page
35
- pageTitle,
36
- // Information relative to the previous documentation page, `null` if none.
37
- prevPageInfo,
38
- // Relative JS URIs on this page
39
- scriptUris,
40
- // Array corresponding to the complete search index.
41
- // It will be completed with data present in this file.
42
- searchIndex,
43
- // HTML string for the sidebar
44
- sidebarHtml,
45
- }) {
46
- const rootUrl = toUriCompatibleRelativePath(
47
- path.resolve(baseOutDir),
48
- path.dirname(outputFile)
49
- );
50
- const outputUrlFromRoot = toUriCompatibleRelativePath(outputFile, baseOutDir);
51
-
52
- const outputDir = path.dirname(outputFile);
53
- let data;
54
- try {
55
- data = await promisify(fs.readFile)(inputFile, "utf8");
56
- } catch (err) {
57
- /* eslint-disable no-console */
58
- console.error("error reading file:", err);
59
- /* eslint-enable no-console */
60
- return;
61
- }
62
- const inputDir = path.dirname(inputFile);
63
- const { content, tocMd, nbTocElements } = constructTableOfContents(data);
64
-
65
- let contentHtml = await parseMD(content, inputDir, outputDir, linkTranslator);
66
- const indexForFile = buildSearchIndex(contentHtml);
67
- searchIndex.push({
68
- file: outputUrlFromRoot,
69
- index: indexForFile,
70
- });
71
- contentHtml += constructNextPreviousPage(prevPageInfo, nextPageInfo);
72
-
73
- const tocHtml = nbTocElements > 1 ?
74
- generateTocbarHtml(tocMd) :
75
- "";
76
- const html = constructHtml({
77
- contentHtml,
78
- cssUris,
79
- navBarHtml,
80
- rootUrl,
81
- scriptUris,
82
- sidebarHtml,
83
- title: pageTitle,
84
- tocHtml,
85
- });
86
-
87
- try {
88
- await promisify(fs.writeFile)(outputFile, html);
89
- } catch (err) {
90
- /* eslint-disable no-console */
91
- console.error("error writing file:", err);
92
- /* eslint-enable no-console */
93
- return;
94
- }
95
- };
96
-
97
-
98
- async function updateMediaTag(mediaTag, inputDir, outputDir) {
99
- if (!mediaTag.attr("src")) {
100
- return;
101
- }
102
- const inputFile = path.join(inputDir, mediaTag.attr("src"));
103
- const outputFile = path.join(outputDir, mediaTag.attr("src"));
104
- if (await promisify(fs.exists)(outputFile)) {
105
- return;
106
- }
107
- const outDir = path.dirname(outputFile);
108
- const doesOutDirExists = await promisify(fs.exists)(outDir);
109
- if (!doesOutDirExists) {
110
- try {
111
- await mkdirParent(outDir);
112
- } catch (err) {
113
- const srcMessage = (err ?? {}).message ?? "Unknown error";
114
- console.error(`Error: Could not create "${outDir}" directory: ${srcMessage}`);
115
- process.exit(1);
116
- }
117
- }
118
- const doesOutFileExist = await promisify(fs.exists)(outputFile);
119
- if (!doesOutFileExist) {
120
- await promisify(fs.copyFile)(inputFile, outputFile);
121
- }
122
- }
123
-
124
- function constructNextPreviousPage(prevPageInfo, nextPageInfo) {
125
- if (prevPageInfo === null && nextPageInfo === null) {
126
- return "";
127
- }
128
-
129
- const prevPageElt = createNextPrevElt(prevPageInfo, false);
130
- const nextPageElt = createNextPrevElt(nextPageInfo, true);
131
- return `<nav class="next-previous-page-wrapper" aria-label="Navigate between pages">` +
132
- prevPageElt +
133
- nextPageElt +
134
- `</nav>`;
135
-
136
- function createNextPrevElt(pageInfo, isNext) {
137
- const base = `<div class="next-or-previous-page${isNext ? " next-page" : ""}">`;
138
- if (pageInfo === null) {
139
- return base + "</div>";
140
- }
141
- return base +
142
- `<a class="next-or-previous-page-link" href="${pageInfo.link}">` +
143
- `<div class="next-or-previous-page-link-label">` +
144
- (isNext ? "Next" : "Previous") +
145
- "</div>" +
146
- `<div class="next-or-previous-page-link-name">${pageInfo.name}</div>` +
147
- "</a></div>";
148
- }
149
- }
150
-
151
- /**
152
- * Convert Markdown to HTML.
153
- * @param {string} data - Markdown to convert
154
- * @param {string} inputDir - Directory the Markdown file is in.
155
- * Can be used to copy image/video/audio files.
156
- * @param {string} outputDir - Directory the HTML file will be in.
157
- * Can be used to copy image/video/audio files.
158
- * @param {Function|null|undefined} linkTranslator - Allow to translate links
159
- * from markdown to HTML. Is given the orginal link in the markdown and should
160
- * return the converted link.
161
- * If null or undefined, the links won't be converted.
162
- * @returns {string}
163
- */
164
- async function parseMD(data, inputDir, outputDir, linkTranslator) {
165
- // TODO I don't understand Cheerio/Jquery here, that's plain ugly
166
- // use markdown-it plugin instead?
167
- const $ = cheerio.load(convertMDToHTML(data));
168
-
169
- if (linkTranslator) {
170
- $("a").each((_, elem) => {
171
- const href = $(elem).attr("href");
172
- if (
173
- typeof href === "string" &&
174
- !/^(?:[a-z]+:)/.test(href) &&
175
- href[0] !== "#"
176
- ) {
177
- $(elem).attr("href", linkTranslator(href));
178
- }
179
- });
180
- }
181
-
182
- const imgTags = $("img").toArray();
183
- for (let i = 0; i < imgTags.length; i++) {
184
- await updateMediaTag($(imgTags[i]), inputDir, outputDir);
185
- }
186
- const audioTags = $("audio").toArray();
187
- for (let i = 0; i < audioTags.length; i++) {
188
- await updateMediaTag($(audioTags[i]), inputDir, outputDir);
189
- }
190
- const videoTags = $("video").toArray();
191
- for (let i = 0; i < videoTags.length; i++) {
192
- await updateMediaTag($(videoTags[i]), inputDir, outputDir);
193
- }
194
- return $.html();
195
- }
196
-
197
- /**
198
- * Construct the table of contents part of the HTML page, containing various
199
- * links to the current documentation page.
200
- * @param {string} toc - Markdown for the table of contents under a list form.
201
- * @returns {string} - sidebar div tag
202
- */
203
- function generateTocbarHtml(tocMd) {
204
- const tocHtml = convertMDToHTML(tocMd);
205
- return "<div class=\"tocbar-wrapper\">" +
206
- "<div class=\"tocbar\">" +
207
- tocHtml +
208
- "</div>" +
209
- "</div>";
210
- }
@@ -1,147 +0,0 @@
1
- const path = require("path");
2
- const { encode } = require("html-entities");
3
- const {
4
- toUriCompatibleRelativePath,
5
- getGithubSvg,
6
- } = require("./utils");
7
-
8
- /**
9
- * Construct HTML element, as a string, which corresponds to the header for
10
- * the chosen documentation page.
11
- * @param {Object} config
12
- * @param {number} currentLinkIdx
13
- * @param {string} currentPath
14
- * @param {object} logoInfo
15
- * @returns {string}
16
- */
17
- function generateHeaderHtml(config, currentLinkIdx, currentPath, logoInfo) {
18
- const { versionInfo, links, linksRightIndex } = config;
19
- const hamburgerHtml = constructHamburgerMenuHtmlInHeaderBar();
20
- const logoHtml = constructLogoHtmlInHeaderBar(logoInfo);
21
- const currentDir = path.dirname(currentPath);
22
-
23
- const linksHtml = links.map((l, i) => {
24
- const customClass =
25
- i === linksRightIndex ? " first-right" :
26
- i === linksRightIndex - 1 ? " last-left" :
27
- "";
28
- switch (l.type) {
29
- case "local-doc": {
30
- const relativeUri = toUriCompatibleRelativePath(l.firstPage, currentDir);
31
- const activeClass = i === currentLinkIdx ? " navbar-active" : "";
32
- const cleanedHref = encode(relativeUri);
33
- return `<a class="navbar-item${activeClass}${customClass} hideable"` +
34
- `href="${cleanedHref}">${encode(l.displayName)}</a>`;
35
- }
36
- case "external-link": {
37
- const cleanedHref = encode(l.link);
38
- return `<a class="navbar-item${customClass} hideable"` +
39
- `href="${cleanedHref}">${encode(l.displayName)}</a>`;
40
- }
41
- case "github-link":
42
- return constructGithubLinkHtmlInHeaderBar(l.link, customClass);
43
- case "search":
44
- return constructSearchHtmlInHeaderBar(customClass);
45
- case "version":
46
- return constructVersionLinkHtmlInHeaderBar(versionInfo, customClass);
47
- }
48
- }).join("\n");
49
- return `<nav class="navbar-parent">` +
50
- `<div class="navbar-wrapper">` +
51
- `<div class="navbar-items">` +
52
- hamburgerHtml +
53
- logoHtml +
54
- linksHtml +
55
- "</div></div> </nav>";
56
- }
57
-
58
- function constructHamburgerMenuHtmlInHeaderBar() {
59
- return `<button aria-label="Open website index" class="hamburger-opener">` +
60
- `<svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true">` +
61
- `<path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" ` +
62
- `stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg>` +
63
- "</button>";
64
- }
65
-
66
- /**
67
- * Returns the HTML string corresponding to the current version number, if
68
- * available, and with the corresponding link, also if available.
69
- * @param {Object} versionInfo
70
- * @param {string} customClass
71
- * @returns {string}
72
- */
73
- function constructVersionLinkHtmlInHeaderBar(versionInfo, customClass) {
74
- if (
75
- versionInfo === undefined || versionInfo === null ||
76
- typeof versionInfo.version !== "string"
77
- ) {
78
- return "";
79
- }
80
- let element = "";
81
- let hasLink = false;
82
- const { version } = versionInfo;
83
- if (typeof versionInfo.link === "string") {
84
- hasLink = true;
85
- element += `<a class="navbar-item${customClass}"` +
86
- `href="${encode(versionInfo.link)}">`;
87
- } else {
88
- element += `<span class="navbar-item${customClass}">`;
89
- }
90
- element += `<span class="version-item">version: ${encode(version)}</span>`;
91
- element += hasLink ? "</a>" : "</span>";
92
- return element;
93
- }
94
-
95
- /**
96
- * Returns the HTML string corresponding to the link to the github repository,
97
- * through a SVG representing Github's logo.
98
- * @param {string} githubLnk
99
- * @param {string} customClass
100
- * @returns {string}
101
- */
102
- function constructGithubLinkHtmlInHeaderBar(githubLnk, customClass) {
103
- const cleanedHref = encode(githubLnk);
104
- return `<a aria-label="Link to repository" class="navbar-item${customClass} hideable" href="${cleanedHref}">` +
105
- getGithubSvg() +
106
- "</a>";
107
- }
108
-
109
- function constructSearchHtmlInHeaderBar(customClass) {
110
- return `<span class="navbar-item search-icon${customClass}">` +
111
- `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" ` +
112
- `viewBox="0 0 20 20">` +
113
- `<title>search</title>` +
114
- `<path d="M19 17l-5.15-5.15a7 7 0 1 0-2 2L17 19zM3.5 8A4.5 4.5 ` +
115
- `0 1 1 8 12.5 4.5 4.5 0 0 1 3.5 8z"/>` +
116
- `<script xmlns=""/></svg>` +
117
- `</span>`;
118
- }
119
-
120
- /**
121
- * Returns the HTML string corresponding to the logo of the current project, if
122
- * available, and with the corresponding link, also if available.
123
- * @param {Object|undefined} logoInfo
124
- * @returns {string}
125
- */
126
- function constructLogoHtmlInHeaderBar(logoInfo) {
127
- if (logoInfo === null || logoInfo === undefined) {
128
- return "";
129
- }
130
-
131
- let logoHtml = "";
132
- let hasLink = false;
133
- if (typeof logoInfo.link === "string") {
134
- hasLink = true;
135
- logoHtml += `<a href="${encode(logoInfo.link)}">`;
136
- }
137
- if (typeof logoInfo.url === "string") {
138
- logoHtml += `<img alt="Logo" class="navbar-item navbar-item-logo"` +
139
- ` src="${encode(logoInfo.url)}" />`;
140
- }
141
- if (hasLink) {
142
- logoHtml += "</a>";
143
- }
144
- return logoHtml;
145
- }
146
-
147
- module.exports = generateHeaderHtml;
@@ -1,115 +0,0 @@
1
- const { encode } = require("html-entities");
2
-
3
- /**
4
- * Generate HTML page for the given documentation.
5
- * @param {Object} args
6
- * @param {string} args.contentHtml - HTML content for the content of the
7
- * @param {Array.<string>} args.cssUrls - URLs to the CSS files that should
8
- * be imported.
9
- * @param {string|null|undefined} [args.faviconUrl] - Eventual URL to the
10
- * favicon.
11
- * `null` or `undefined` if unset.
12
- * @param {string} options.navBarHtml - HTML strinng for the Navbar (the
13
- * header).
14
- * @param {string} options.pageListHtml - HTML string for the complete list of
15
- * documentation pages with links.
16
- * @param {string} options.rootUrl - Relative URL for the root of the site.
17
- * This value is included in a custom script so it can be accessed from other
18
- * JavaScript files.
19
- * @param {Array.<string>} args.scriptUrls - URLs to the JS files that should
20
- * be imported.
21
- * @param {string} options.sidebarHtml - HTML string for the Sidebar.
22
- * @param {string} args.title - title of the page.
23
- * @param {string} options.tocHtml - HTML string for the Table of content.
24
- * `undefined` if your page has no table of contents.
25
- * @returns {string} - Whole HTML string for the documentation page.
26
- */
27
- function generatePageHtml(
28
- {
29
- contentHtml,
30
- cssUrls,
31
- faviconUrl,
32
- navBarHtml,
33
- pageListHtml,
34
- rootUrl,
35
- scriptUrls,
36
- sidebarHtml,
37
- title,
38
- tocHtml,
39
- }
40
- ) {
41
- const styles = constructStylesHtml(cssUrls);
42
- const scripts = constructScriptsHtml(scriptUrls);
43
- const faviconHtml = typeof faviconUrl === "string" ?
44
- `<link rel="icon" type="image/png" href="${encode(faviconUrl)}">` :
45
- "";
46
- const hamburgerHtml = constructHamburgerBarHtml(pageListHtml);
47
-
48
- return "<!DOCTYPE html><html lang=\"en\"><head>" +
49
- "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" +
50
- "<meta charset=\"utf-8\">" +
51
- styles +
52
- "<title>" + encode(title) + "</title>" +
53
- faviconHtml +
54
- "</head>" +
55
- "<body class=\"no-js\">" +
56
- `<script type="text/javascript">` +
57
- `document.body.className = "";` +
58
- `window.rootUrl = "${rootUrl}";` +
59
- "</script>" +
60
- "<div class=\"page-wrapper\">" +
61
- navBarHtml +
62
- sidebarHtml +
63
- "<div class=\"content-wrapper\">" +
64
- "<div class=\"content\">" +
65
- `<div id="search-wrapper">` +
66
- `<input type="search" name="search" id="searchbar" ` +
67
- `placeholder="Search in this documentation" class="active" />` +
68
- `<div id="search-results"></div>` +
69
- `</div>` +
70
- contentHtml +
71
- `</div>` +
72
- tocHtml +
73
- "</div>" +
74
- "</div>" +
75
- hamburgerHtml +
76
- scripts +
77
- "</body></html>";
78
- };
79
-
80
- function constructHamburgerBarHtml(pageListHtml) {
81
- return `<div class="hamburger-bar">` +
82
- `<div class="hamburger-header">` +
83
- `<span class="hamburger-title">Page List</span>` +
84
- `<button aria-label="Close website index" type="button" class="hamburger-bar-closer">` +
85
- `<svg viewBox="0 0 15 15" width="21" height="21">` +
86
- `<g stroke="black" stroke-width="1.2"><path d="M.75.75l13.5 13.5M14.25.75L.75 14.25"></path></g>` +
87
- `</svg></button>` +
88
- `</div>` +
89
- pageListHtml +
90
- "</div>";
91
- }
92
-
93
- /**
94
- * Returns links to CSS file as an HTML string to be included in the page.
95
- * @param {Array.<string>} cssUrls - URL to CSS files
96
- * @returns {string}
97
- */
98
- function constructStylesHtml(cssUrls) {
99
- return cssUrls.map(cssUrl =>
100
- `<link rel="stylesheet" href="${encode(cssUrl)}"/>`)
101
- .join("");
102
- }
103
-
104
- /**
105
- * @param {Array.<string>} scriptUrls - URL to scripts files
106
- * @returns {string}
107
- */
108
- function constructScriptsHtml(scriptUrls) {
109
- return scriptUrls.map(scriptUrl =>
110
- `<script type="text/javascript" src="${encode(scriptUrl)}" ` +
111
- `charset="utf-8"></script>`
112
- ).join("");
113
- }
114
-
115
- module.exports = generatePageHtml;