clean-jsdoc-theme 4.1.4 → 4.1.7

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 (67) hide show
  1. package/.eslintignore +4 -4
  2. package/.eslintrc.js +3 -3
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +43 -43
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +27 -27
  5. package/.github/dependabot.yml +9 -9
  6. package/.github/pull_request_template.md +16 -16
  7. package/.github/workflows/codeql.yml +72 -72
  8. package/.github/workflows/greetings.yml +16 -16
  9. package/.prettierignore +2 -2
  10. package/.prettierrc +5 -5
  11. package/.stylelintignore +3 -3
  12. package/.stylelintrc +23 -23
  13. package/.travis.yml +30 -30
  14. package/CHANGELOG.md +235 -235
  15. package/CODE_OF_CONDUCT.md +76 -76
  16. package/CODE_OF_CONDUCT_HINDI.md +46 -46
  17. package/CONTRIBUTING.md +24 -24
  18. package/LICENSE +21 -21
  19. package/README.md +456 -457
  20. package/SECURITY.md +21 -21
  21. package/helpers/down-arrow.js +9 -9
  22. package/jsdoc-config.json +61 -61
  23. package/minify.js +56 -52
  24. package/package.json +50 -50
  25. package/publish.js +1129 -1129
  26. package/static/scripts/core.js +656 -643
  27. package/static/scripts/core.min.js +23 -23
  28. package/static/scripts/resize.js +90 -90
  29. package/static/scripts/search.js +262 -289
  30. package/static/scripts/search.min.js +6 -11
  31. package/static/scripts/third-party/Apache-License-2.0.txt +202 -202
  32. package/static/scripts/third-party/fuse.js +8 -8
  33. package/static/scripts/third-party/hljs-line-num-original.js +365 -0
  34. package/static/scripts/third-party/hljs-line-num.js +1 -1
  35. package/static/scripts/third-party/hljs-original.js +5162 -5162
  36. package/static/scripts/third-party/popper.js +5 -5
  37. package/static/scripts/third-party/tippy.js +1 -1
  38. package/static/styles/clean-jsdoc-theme-base.css +969 -952
  39. package/static/styles/clean-jsdoc-theme-dark.css +407 -411
  40. package/static/styles/clean-jsdoc-theme-light.css +388 -392
  41. package/static/styles/clean-jsdoc-theme.min.css +1 -1
  42. package/tmpl/augments.tmpl +10 -10
  43. package/tmpl/container.tmpl +190 -190
  44. package/tmpl/details.tmpl +207 -207
  45. package/tmpl/example.tmpl +3 -3
  46. package/tmpl/examples.tmpl +40 -40
  47. package/tmpl/exceptions.tmpl +32 -32
  48. package/tmpl/icons.tmpl +72 -72
  49. package/tmpl/layout.tmpl +157 -155
  50. package/tmpl/mainpage.tmpl +10 -10
  51. package/tmpl/members.tmpl +42 -42
  52. package/tmpl/method.tmpl +139 -139
  53. package/tmpl/mobile-sidebar.tmpl +20 -20
  54. package/tmpl/navbar-actions.tmpl +18 -18
  55. package/tmpl/navbar-menu.tmpl +24 -24
  56. package/tmpl/navbar.tmpl +13 -13
  57. package/tmpl/params.tmpl +124 -124
  58. package/tmpl/properties.tmpl +109 -109
  59. package/tmpl/returns.tmpl +18 -18
  60. package/tmpl/search.tmpl +16 -16
  61. package/tmpl/sidebar-items.tmpl +23 -23
  62. package/tmpl/sidebar-title.tmpl +9 -9
  63. package/tmpl/sidebar.tmpl +8 -8
  64. package/tmpl/source.tmpl +12 -12
  65. package/tmpl/toc.tmpl +3 -3
  66. package/tmpl/tutorial.tmpl +19 -19
  67. package/tmpl/type.tmpl +6 -6
@@ -1,643 +1,656 @@
1
- /* global document */
2
- var accordionLocalStorageKey = 'accordion-id';
3
- var themeLocalStorageKey = 'theme';
4
- var fontSizeLocalStorageKey = 'font-size';
5
- var html = document.querySelector('html');
6
-
7
- var MAX_FONT_SIZE = 30;
8
- var MIN_FONT_SIZE = 10;
9
-
10
- // eslint-disable-next-line no-undef
11
- var localStorage = window.localStorage;
12
-
13
- function getTheme() {
14
- var body = document.body;
15
-
16
- return body.getAttribute('data-theme');
17
- }
18
-
19
- function updateTheme(theme) {
20
- var body = document.body;
21
- var svgUse = document.querySelectorAll('.theme-svg-use');
22
- var iconID = theme === 'dark' ? '#light-theme-icon' : '#dark-theme-icon';
23
-
24
- body.setAttribute('data-theme', theme);
25
- body.classList.remove('dark', 'light');
26
- body.classList.add(theme);
27
-
28
- svgUse.forEach(function(svg) {
29
- svg.setAttribute('xlink:href', iconID);
30
- });
31
-
32
- localStorage.setItem(themeLocalStorageKey, theme);
33
- }
34
-
35
- function toggleTheme() {
36
- var body = document.body;
37
- var theme = body.getAttribute('data-theme');
38
-
39
- var newTheme = theme === 'dark' ? 'light' : 'dark';
40
-
41
- updateTheme(newTheme);
42
- }
43
-
44
- (function() {
45
- var theme = getTheme();
46
-
47
- var themeStoredInLocalStorage = localStorage.getItem(themeLocalStorageKey);
48
-
49
- if (themeStoredInLocalStorage) {
50
- if (theme === themeStoredInLocalStorage) {
51
- return;
52
- }
53
-
54
- updateTheme(themeStoredInLocalStorage);
55
- } else {
56
- localStorage.setItem(themeLocalStorageKey, theme);
57
- }
58
- })();
59
-
60
- /**
61
- * Function to set accordion id to localStorage.
62
- * @param {string} id Accordion id
63
- */
64
- function setAccordionIdToLocalStorage(id) {
65
- /**
66
- * @type {object}
67
- */
68
- var ids = JSON.parse(localStorage.getItem(accordionLocalStorageKey));
69
-
70
- ids[id] = id;
71
- localStorage.setItem(accordionLocalStorageKey, JSON.stringify(ids));
72
- }
73
-
74
- /**
75
- * Function to remove accordion id from localStorage.
76
- * @param {string} id Accordion id
77
- */
78
- function removeAccordionIdFromLocalStorage(id) {
79
- /**
80
- * @type {object}
81
- */
82
- var ids = JSON.parse(localStorage.getItem(accordionLocalStorageKey));
83
-
84
- delete ids[id];
85
- localStorage.setItem(accordionLocalStorageKey, JSON.stringify(ids));
86
- }
87
-
88
- /**
89
- * Function to get all accordion ids from localStorage.
90
- *
91
- * @returns {object}
92
- */
93
- function getAccordionIdsFromLocalStorage() {
94
- /**
95
- * @type {object}
96
- */
97
- var ids = JSON.parse(localStorage.getItem(accordionLocalStorageKey));
98
-
99
- return ids || {};
100
- }
101
-
102
- function toggleAccordion(element) {
103
- var currentNode = element;
104
- var isCollapsed = currentNode.getAttribute('data-isopen') === 'false';
105
-
106
- if (isCollapsed) {
107
- currentNode.setAttribute('data-isopen', 'true');
108
- setAccordionIdToLocalStorage(currentNode.id);
109
- } else {
110
- currentNode.setAttribute('data-isopen', 'false');
111
- removeAccordionIdFromLocalStorage(currentNode.id);
112
- }
113
- }
114
-
115
- function initAccordion() {
116
- if (
117
- localStorage.getItem(accordionLocalStorageKey) === undefined ||
118
- localStorage.getItem(accordionLocalStorageKey) === null
119
- ) {
120
- localStorage.setItem(accordionLocalStorageKey, '{}');
121
- }
122
- var allAccordion = document.querySelectorAll('.sidebar-section-title');
123
- var ids = getAccordionIdsFromLocalStorage();
124
-
125
- allAccordion.forEach(function(item) {
126
- item.addEventListener('click', function() {
127
- toggleAccordion(item);
128
- });
129
- if (item.id in ids) {
130
- toggleAccordion(item);
131
- }
132
- });
133
- }
134
-
135
- function isSourcePage() {
136
- return Boolean(document.querySelector('#source-page'));
137
- }
138
-
139
- function bringElementIntoView(element, updateHistory = true) {
140
- // If element is null then we are not going further
141
- if (!element) {
142
- return;
143
- }
144
-
145
- var navbar = document.querySelector('.navbar-container');
146
- var body = document.querySelector('.main-content');
147
- var elementTop = element.getBoundingClientRect().top;
148
-
149
- var offset = 16;
150
-
151
- if (navbar) {
152
- offset += navbar.scrollHeight;
153
- }
154
-
155
- if (body) {
156
- body.scrollBy(0, elementTop - offset);
157
- }
158
-
159
- if (updateHistory) {
160
- // eslint-disable-next-line no-undef
161
- history.pushState(null, null, '#' + element.id);
162
- }
163
- }
164
-
165
- // eslint-disable-next-line no-unused-vars
166
- function bringLinkToView(event) {
167
- event.preventDefault();
168
- event.stopPropagation();
169
- var id = event.currentTarget.getAttribute('href');
170
-
171
- if (!id) {
172
- return;
173
- }
174
-
175
- var element = document.getElementById(id.slice(1));
176
-
177
- if (element) {
178
- bringElementIntoView(element);
179
- }
180
- }
181
-
182
- function bringIdToViewOnMount() {
183
- if (isSourcePage()) {
184
- return;
185
- }
186
-
187
- // eslint-disable-next-line no-undef
188
- var id = window.location.hash;
189
-
190
- if (id === '') {
191
- return;
192
- }
193
-
194
- var element = document.getElementById(id.slice(1));
195
-
196
- if (!element) {
197
- id = decodeURI(id);
198
- element = document.getElementById(id.slice(1));
199
- }
200
-
201
- if (element) {
202
- bringElementIntoView(element, false);
203
- }
204
- }
205
-
206
- function createAnchorElement(id) {
207
- var anchor = document.createElement('a');
208
-
209
- anchor.textContent = '#';
210
- anchor.href = '#' + id;
211
- anchor.classList.add('link-anchor');
212
- anchor.onclick = bringLinkToView;
213
-
214
- return anchor;
215
- }
216
-
217
- function addAnchor() {
218
- var main = document.querySelector('.main-content').querySelector('section');
219
-
220
- var h1 = main.querySelectorAll('h1');
221
- var h2 = main.querySelectorAll('h2');
222
- var h3 = main.querySelectorAll('h3');
223
- var h4 = main.querySelectorAll('h4');
224
-
225
- var targets = [h1, h2, h3, h4];
226
-
227
- targets.forEach(function(target) {
228
- target.forEach(function(heading) {
229
- var anchor = createAnchorElement(heading.id);
230
-
231
- heading.classList.add('has-anchor');
232
- heading.append(anchor);
233
- });
234
- });
235
- }
236
-
237
- /**
238
- *
239
- * @param {string} value
240
- */
241
- function copy(value) {
242
- const el = document.createElement('textarea');
243
-
244
- el.value = value;
245
- document.body.appendChild(el);
246
- el.select();
247
- document.execCommand('copy');
248
- document.body.removeChild(el);
249
- }
250
-
251
- function showTooltip(id) {
252
- var tooltip = document.getElementById(id);
253
-
254
- tooltip.classList.add('show-tooltip');
255
- setTimeout(function() {
256
- tooltip.classList.remove('show-tooltip');
257
- }, 3000);
258
- }
259
-
260
- /* eslint-disable-next-line */
261
- function copyFunction(id) {
262
- // selecting the pre element
263
- var code = document.getElementById(id);
264
-
265
- // selecting the ol.linenums
266
- var element = code.querySelector('.linenums');
267
-
268
- if (!element) {
269
- // selecting the code block
270
- element = code.querySelector('code');
271
- }
272
-
273
- // copy
274
- copy(element.innerText);
275
-
276
- // show tooltip
277
- showTooltip('tooltip-' + id);
278
- }
279
-
280
- function hideTocOnSourcePage() {
281
- if (isSourcePage()) {
282
- document.querySelector('.toc-container').style.display = 'none';
283
- }
284
- }
285
-
286
- function getPreTopBar(id, lang = '') {
287
- // tooltip
288
- var tooltip = '<div class="tooltip" id="tooltip-' + id + '">Copied!</div>';
289
-
290
- // template of copy to clipboard icon container
291
- var copyToClipboard =
292
- '<button aria-label="copy code" class="icon-button copy-code" onclick="copyFunction(\'' +
293
- id +
294
- '\')"><svg class="sm-icon" alt="click to copy"><use xlink:href="#copy-icon"></use></svg>' +
295
- tooltip +
296
- '</button>';
297
-
298
- var langNameDiv =
299
- '<div class="code-lang-name-container"><div class="code-lang-name">' +
300
- lang.toLocaleUpperCase() +
301
- '</div></div>';
302
-
303
- var topBar =
304
- '<div class="pre-top-bar-container">' +
305
- langNameDiv +
306
- copyToClipboard +
307
- '</div>';
308
-
309
- return topBar;
310
- }
311
-
312
- function getPreDiv() {
313
- var divElement = document.createElement('div');
314
-
315
- divElement.classList.add('pre-div');
316
-
317
- return divElement;
318
- }
319
-
320
- function processAllPre() {
321
- var targets = document.querySelectorAll('pre');
322
- var footer = document.querySelector('#PeOAagUepe');
323
- var navbar = document.querySelector('#VuAckcnZhf');
324
-
325
- var navbarHeight = 0;
326
- var footerHeight = 0;
327
-
328
- if (footer) {
329
- footerHeight = footer.getBoundingClientRect().height;
330
- }
331
-
332
- if (navbar) {
333
- navbarHeight = navbar.getBoundingClientRect().height;
334
- }
335
-
336
- // eslint-disable-next-line no-undef
337
- var preMaxHeight = window.innerHeight - navbarHeight - footerHeight - 250;
338
-
339
- targets.forEach(function(pre, idx) {
340
- var parent = pre.parentNode;
341
-
342
- if (parent && parent.getAttribute('data-skip-pre-process') === 'true') {
343
- return;
344
- }
345
-
346
- var div = getPreDiv();
347
- var id = 'ScDloZOMdL' + idx;
348
-
349
- var lang = pre.getAttribute('data-lang') || 'code';
350
- var topBar = getPreTopBar(id, lang);
351
-
352
- div.innerHTML = topBar;
353
-
354
- pre.style.maxHeight = preMaxHeight + 'px';
355
- pre.id = id;
356
- pre.parentNode.insertBefore(div, pre);
357
- div.appendChild(pre);
358
- });
359
- }
360
-
361
- function highlightAndBringLineIntoView() {
362
- // eslint-disable-next-line no-undef
363
- var lineNumber = window.location.hash.replace('#line', '');
364
-
365
- try {
366
- var selector = '[data-line-number="' + lineNumber + '"';
367
-
368
- var element = document.querySelector(selector);
369
-
370
- element.scrollIntoView();
371
- element.parentNode.classList.add('selected');
372
- } catch (error) {
373
- console.error(error);
374
- }
375
- }
376
-
377
- function getFontSize() {
378
- var currentFontSize = 16;
379
-
380
- try {
381
- currentFontSize = Number.parseInt(
382
- html.style.fontSize.split('px')[0],
383
- 10
384
- );
385
- } catch (error) {
386
- console.log(error);
387
- }
388
-
389
- return currentFontSize;
390
- }
391
-
392
- function updateFontSize(fontSize) {
393
- html.style.fontSize = fontSize + 'px';
394
- localStorage.setItem(fontSizeLocalStorageKey, fontSize);
395
- var fontSizeText = document.querySelector(
396
- '#b77a68a492f343baabea06fad81f651e'
397
- );
398
-
399
- if (fontSizeText) {
400
- fontSizeText.innerHTML = fontSize;
401
- }
402
- }
403
-
404
- (function() {
405
- var fontSize = getFontSize();
406
- var fontSizeInLocalStorage = localStorage.getItem(fontSizeLocalStorageKey);
407
-
408
- if (fontSizeInLocalStorage) {
409
- var n = Number.parseInt(fontSizeInLocalStorage, 10);
410
-
411
- if (n === fontSize) {
412
- return;
413
- }
414
- updateFontSize(n);
415
- } else {
416
- updateFontSize(fontSize);
417
- }
418
- })();
419
-
420
- // eslint-disable-next-line no-unused-vars
421
- function incrementFont(event) {
422
- var n = getFontSize();
423
-
424
- if (n < MAX_FONT_SIZE) {
425
- updateFontSize(n + 1);
426
- }
427
- }
428
-
429
- // eslint-disable-next-line no-unused-vars
430
- function decrementFont(event) {
431
- var n = getFontSize();
432
-
433
- if (n > MIN_FONT_SIZE) {
434
- updateFontSize(n - 1);
435
- }
436
- }
437
-
438
- function fontSizeTooltip() {
439
- var fontSize = getFontSize();
440
-
441
- return `
442
- <div class="font-size-tooltip">
443
- <button aria-label="decrease-font-size" class="icon-button ${
444
- fontSize >= MAX_FONT_SIZE ? 'disabled' : ''
445
- }" onclick="decrementFont(event)">
446
- <svg>
447
- <use xlink:href="#minus-icon"></use>
448
- </svg>
449
- </button>
450
- <div class="font-size-text" id="b77a68a492f343baabea06fad81f651e">
451
- ${fontSize}
452
- </div>
453
- <button aria-label="increase-font-size" class="icon-button ${
454
- fontSize <= MIN_FONT_SIZE ? 'disabled' : ''
455
- }" onclick="incrementFont(event)">
456
- <svg>
457
- <use xlink:href="#add-icon"></use>
458
- </svg>
459
- </button>
460
- <button class="icon-button" onclick="updateFontSize(16)">
461
- <svg>
462
- <use xlink:href="#reset-icon"></use>
463
- </svg>
464
- </button>
465
- </div>
466
-
467
- `;
468
- }
469
-
470
- function initTooltip() {
471
- // add tooltip to navbar item
472
- // eslint-disable-next-line no-undef
473
- tippy('.theme-toggle', {
474
- content: 'Toggle Theme',
475
- delay: 500
476
- });
477
-
478
- // eslint-disable-next-line no-undef
479
- tippy('.search-button', {
480
- content: 'Search',
481
- delay: 500
482
- });
483
-
484
- // eslint-disable-next-line no-undef
485
- tippy('.font-size', {
486
- content: 'Change font size',
487
- delay: 500
488
- });
489
-
490
- // eslint-disable-next-line no-undef
491
- tippy('.codepen-button', {
492
- content: 'Open code in CodePen',
493
- placement: 'left'
494
- });
495
-
496
- // eslint-disable-next-line no-undef
497
- tippy('.copy-code', {
498
- content: 'Copy this code',
499
- placement: 'left'
500
- });
501
-
502
- // eslint-disable-next-line no-undef
503
- tippy('.font-size', {
504
- content: fontSizeTooltip(),
505
- trigger: 'click',
506
- interactive: true,
507
- allowHTML: true,
508
- placement: 'left'
509
- });
510
- }
511
-
512
- function fixTable() {
513
- var tables = document.querySelectorAll('table');
514
- var table;
515
-
516
- // eslint-disable-next-line no-undef
517
- if (window.innerWidth > 900) {
518
- // Only fixing table if width is smaller than 900px
519
- return;
520
- }
521
-
522
- for (table of tables) {
523
- if (table.classList.contains('hljs-ln')) {
524
- // don't want to wrap code blocks.
525
- return;
526
- }
527
-
528
- var div = document.createElement('div');
529
-
530
- div.classList.add('table-div');
531
- table.parentNode.insertBefore(div, table);
532
- div.appendChild(table);
533
- }
534
- }
535
-
536
- function hideMobileMenu() {
537
- var mobileMenuContainer = document.querySelector('#mobile-sidebar');
538
- var target = document.querySelector('#mobile-menu');
539
- var svgUse = target.querySelector('use');
540
-
541
- if (mobileMenuContainer) {
542
- mobileMenuContainer.classList.remove('show');
543
- }
544
- if (target) {
545
- target.setAttribute('data-isopen', 'false');
546
- }
547
- if (svgUse) {
548
- svgUse.setAttribute('xlink:href', '#menu-icon');
549
- }
550
- }
551
-
552
- function showMobileMenu() {
553
- var mobileMenuContainer = document.querySelector('#mobile-sidebar');
554
- var target = document.querySelector('#mobile-menu');
555
- var svgUse = target.querySelector('use');
556
-
557
- if (mobileMenuContainer) {
558
- mobileMenuContainer.classList.add('show');
559
- }
560
- if (target) {
561
- target.setAttribute('data-isopen', 'true');
562
- }
563
- if (svgUse) {
564
- svgUse.setAttribute('xlink:href', '#close-icon');
565
- }
566
- }
567
-
568
- function onMobileMenuClick() {
569
- var target = document.querySelector('#mobile-menu');
570
- var isOpen = target.getAttribute('data-isopen') === 'true';
571
-
572
- if (isOpen) {
573
- hideMobileMenu();
574
- } else {
575
- showMobileMenu();
576
- }
577
- }
578
-
579
- function initMobileMenu() {
580
- var menu = document.querySelector('#mobile-menu');
581
-
582
- if (menu) {
583
- menu.addEventListener('click', onMobileMenuClick);
584
- }
585
- }
586
-
587
- function addHrefToSidebarTitle() {
588
- var titles = document.querySelectorAll('.sidebar-title-anchor');
589
-
590
- titles.forEach(function(title) {
591
- // eslint-disable-next-line no-undef
592
- title.setAttribute('href', baseURL);
593
- });
594
- }
595
-
596
- function onDomContentLoaded() {
597
- var themeButton = document.querySelectorAll('.theme-toggle');
598
-
599
- initMobileMenu();
600
-
601
- if (themeButton) {
602
- themeButton.forEach(function(button) {
603
- button.addEventListener('click', toggleTheme);
604
- });
605
- }
606
-
607
- // Highlighting code
608
-
609
- // eslint-disable-next-line no-undef
610
- hljs.addPlugin({
611
- 'after:highlightElement': function(obj) {
612
- // Replace 'code' with result.language when
613
- // we are able to cross check the correctness of
614
- // result.
615
- obj.el.parentNode.setAttribute('data-lang', 'code');
616
- }
617
- });
618
- // eslint-disable-next-line no-undef
619
- hljs.highlightAll();
620
- // eslint-disable-next-line no-undef
621
- hljs.initLineNumbersOnLoad({
622
- singleLine: true
623
- });
624
-
625
- // Highlight complete
626
-
627
- initAccordion();
628
- addAnchor();
629
- processAllPre();
630
- hideTocOnSourcePage();
631
- setTimeout(function() {
632
- bringIdToViewOnMount();
633
- if (isSourcePage()) {
634
- highlightAndBringLineIntoView();
635
- }
636
- }, 1000);
637
- initTooltip();
638
- fixTable();
639
- addHrefToSidebarTitle();
640
- }
641
-
642
- // eslint-disable-next-line no-undef
643
- window.addEventListener('DOMContentLoaded', onDomContentLoaded);
1
+ /* global document */
2
+ var accordionLocalStorageKey = 'accordion-id';
3
+ var themeLocalStorageKey = 'theme';
4
+ var fontSizeLocalStorageKey = 'font-size';
5
+ var html = document.querySelector('html');
6
+
7
+ var MAX_FONT_SIZE = 30;
8
+ var MIN_FONT_SIZE = 10;
9
+
10
+ // eslint-disable-next-line no-undef
11
+ var localStorage = window.localStorage;
12
+
13
+ function getTheme() {
14
+ var body = document.body;
15
+
16
+ return body.getAttribute('data-theme');
17
+ }
18
+
19
+ function updateTheme(theme) {
20
+ var body = document.body;
21
+ var svgUse = document.querySelectorAll('.theme-svg-use');
22
+ var iconID = theme === 'dark' ? '#light-theme-icon' : '#dark-theme-icon';
23
+
24
+ body.setAttribute('data-theme', theme);
25
+ body.classList.remove('dark', 'light');
26
+ body.classList.add(theme);
27
+
28
+ svgUse.forEach(function(svg) {
29
+ svg.setAttribute('xlink:href', iconID);
30
+ });
31
+
32
+ localStorage.setItem(themeLocalStorageKey, theme);
33
+ }
34
+
35
+ function toggleTheme() {
36
+ var body = document.body;
37
+ var theme = body.getAttribute('data-theme');
38
+
39
+ var newTheme = theme === 'dark' ? 'light' : 'dark';
40
+
41
+ updateTheme(newTheme);
42
+ }
43
+
44
+ (function() {
45
+ var theme = getTheme();
46
+
47
+ var themeStoredInLocalStorage = localStorage.getItem(themeLocalStorageKey);
48
+
49
+ if (themeStoredInLocalStorage) {
50
+ if (theme === themeStoredInLocalStorage) {
51
+ return;
52
+ }
53
+
54
+ updateTheme(themeStoredInLocalStorage);
55
+ } else {
56
+ localStorage.setItem(themeLocalStorageKey, theme);
57
+ }
58
+ })();
59
+
60
+ /**
61
+ * Function to set accordion id to localStorage.
62
+ * @param {string} id Accordion id
63
+ */
64
+ function setAccordionIdToLocalStorage(id) {
65
+ /**
66
+ * @type {object}
67
+ */
68
+ var ids = JSON.parse(localStorage.getItem(accordionLocalStorageKey));
69
+
70
+ ids[id] = id;
71
+ localStorage.setItem(accordionLocalStorageKey, JSON.stringify(ids));
72
+ }
73
+
74
+ /**
75
+ * Function to remove accordion id from localStorage.
76
+ * @param {string} id Accordion id
77
+ */
78
+ function removeAccordionIdFromLocalStorage(id) {
79
+ /**
80
+ * @type {object}
81
+ */
82
+ var ids = JSON.parse(localStorage.getItem(accordionLocalStorageKey));
83
+
84
+ delete ids[id];
85
+ localStorage.setItem(accordionLocalStorageKey, JSON.stringify(ids));
86
+ }
87
+
88
+ /**
89
+ * Function to get all accordion ids from localStorage.
90
+ *
91
+ * @returns {object}
92
+ */
93
+ function getAccordionIdsFromLocalStorage() {
94
+ /**
95
+ * @type {object}
96
+ */
97
+ var ids = JSON.parse(localStorage.getItem(accordionLocalStorageKey));
98
+
99
+ return ids || {};
100
+ }
101
+
102
+ function toggleAccordion(element) {
103
+ var currentNode = element;
104
+ var isCollapsed = currentNode.getAttribute('data-isopen') === 'false';
105
+
106
+ if (isCollapsed) {
107
+ currentNode.setAttribute('data-isopen', 'true');
108
+ setAccordionIdToLocalStorage(currentNode.id);
109
+ } else {
110
+ currentNode.setAttribute('data-isopen', 'false');
111
+ removeAccordionIdFromLocalStorage(currentNode.id);
112
+ }
113
+ }
114
+
115
+ function initAccordion() {
116
+ if (
117
+ localStorage.getItem(accordionLocalStorageKey) === undefined ||
118
+ localStorage.getItem(accordionLocalStorageKey) === null
119
+ ) {
120
+ localStorage.setItem(accordionLocalStorageKey, '{}');
121
+ }
122
+ var allAccordion = document.querySelectorAll('.sidebar-section-title');
123
+ var ids = getAccordionIdsFromLocalStorage();
124
+
125
+ allAccordion.forEach(function(item) {
126
+ item.addEventListener('click', function() {
127
+ toggleAccordion(item);
128
+ });
129
+ if (item.id in ids) {
130
+ toggleAccordion(item);
131
+ }
132
+ });
133
+ }
134
+
135
+ function isSourcePage() {
136
+ return Boolean(document.querySelector('#source-page'));
137
+ }
138
+
139
+ function bringElementIntoView(element, updateHistory = true) {
140
+ // If element is null then we are not going further
141
+ if (!element) {
142
+ return;
143
+ }
144
+
145
+ var navbar = document.querySelector('.navbar-container');
146
+ var body = document.querySelector('.main-content');
147
+ var elementTop = element.getBoundingClientRect().top;
148
+
149
+ var offset = 16;
150
+
151
+ if (navbar) {
152
+ offset += navbar.scrollHeight;
153
+ }
154
+
155
+ if (body) {
156
+ body.scrollBy(0, elementTop - offset);
157
+ }
158
+
159
+ if (updateHistory) {
160
+ // eslint-disable-next-line no-undef
161
+ history.pushState(null, null, '#' + element.id);
162
+ }
163
+ }
164
+
165
+ // eslint-disable-next-line no-unused-vars
166
+ function bringLinkToView(event) {
167
+ event.preventDefault();
168
+ event.stopPropagation();
169
+ var id = event.currentTarget.getAttribute('href');
170
+
171
+ if (!id) {
172
+ return;
173
+ }
174
+
175
+ var element = document.getElementById(id.slice(1));
176
+
177
+ if (element) {
178
+ bringElementIntoView(element);
179
+ }
180
+ }
181
+
182
+ function bringIdToViewOnMount() {
183
+ if (isSourcePage()) {
184
+ return;
185
+ }
186
+
187
+ // eslint-disable-next-line no-undef
188
+ var id = window.location.hash;
189
+
190
+ if (id === '') {
191
+ return;
192
+ }
193
+
194
+ var element = document.getElementById(id.slice(1));
195
+
196
+ if (!element) {
197
+ id = decodeURI(id);
198
+ element = document.getElementById(id.slice(1));
199
+ }
200
+
201
+ if (element) {
202
+ bringElementIntoView(element, false);
203
+ }
204
+ }
205
+
206
+ function createAnchorElement(id) {
207
+ var anchor = document.createElement('a');
208
+
209
+ anchor.textContent = '#';
210
+ anchor.href = '#' + id;
211
+ anchor.classList.add('link-anchor');
212
+ anchor.onclick = bringLinkToView;
213
+
214
+ return anchor;
215
+ }
216
+
217
+ function addAnchor() {
218
+ var main = document.querySelector('.main-content').querySelector('section');
219
+
220
+ var h1 = main.querySelectorAll('h1');
221
+ var h2 = main.querySelectorAll('h2');
222
+ var h3 = main.querySelectorAll('h3');
223
+ var h4 = main.querySelectorAll('h4');
224
+
225
+ var targets = [h1, h2, h3, h4];
226
+
227
+ targets.forEach(function(target) {
228
+ target.forEach(function(heading) {
229
+ var anchor = createAnchorElement(heading.id);
230
+
231
+ heading.classList.add('has-anchor');
232
+ heading.append(anchor);
233
+ });
234
+ });
235
+ }
236
+
237
+ /**
238
+ *
239
+ * @param {string} value
240
+ */
241
+ function copy(value) {
242
+ console.log(value);
243
+ const el = document.createElement('textarea');
244
+
245
+ el.value = value;
246
+ document.body.appendChild(el);
247
+ el.select();
248
+ document.execCommand('copy');
249
+ document.body.removeChild(el);
250
+ }
251
+
252
+ function showTooltip(id) {
253
+ var tooltip = document.getElementById(id);
254
+
255
+ tooltip.classList.add('show-tooltip');
256
+ setTimeout(function() {
257
+ tooltip.classList.remove('show-tooltip');
258
+ }, 3000);
259
+ }
260
+
261
+ /* eslint-disable-next-line */
262
+ function copyFunction(id) {
263
+ // selecting the pre element
264
+ var code = document.getElementById(id);
265
+
266
+ // selecting the ol.linenums
267
+ var element = code.querySelector('.linenums');
268
+
269
+ if (!element) {
270
+ // selecting the code block
271
+ element = code.querySelector('code');
272
+ }
273
+
274
+ // copy
275
+ copy(element.innerText.trim());
276
+
277
+ // show tooltip
278
+ showTooltip('tooltip-' + id);
279
+ }
280
+
281
+ function hideTocOnSourcePage() {
282
+ if (isSourcePage()) {
283
+ document.querySelector('.toc-container').style.display = 'none';
284
+ }
285
+ }
286
+
287
+ function getPreTopBar(id, lang = '') {
288
+ // tooltip
289
+ var tooltip = '<div class="tooltip" id="tooltip-' + id + '">Copied!</div>';
290
+
291
+ // template of copy to clipboard icon container
292
+ var copyToClipboard =
293
+ '<button aria-label="copy code" class="icon-button copy-code" onclick="copyFunction(\'' +
294
+ id +
295
+ '\')"><svg class="sm-icon" alt="click to copy"><use xlink:href="#copy-icon"></use></svg>' +
296
+ tooltip +
297
+ '</button>';
298
+
299
+ var langNameDiv =
300
+ '<div class="code-lang-name-container"><div class="code-lang-name">' +
301
+ lang.toLocaleUpperCase() +
302
+ '</div></div>';
303
+
304
+ var topBar =
305
+ '<div class="pre-top-bar-container">' +
306
+ langNameDiv +
307
+ copyToClipboard +
308
+ '</div>';
309
+
310
+ return topBar;
311
+ }
312
+
313
+ function getPreDiv() {
314
+ var divElement = document.createElement('div');
315
+
316
+ divElement.classList.add('pre-div');
317
+
318
+ return divElement;
319
+ }
320
+
321
+ function processAllPre() {
322
+ var targets = document.querySelectorAll('pre');
323
+ var footer = document.querySelector('#PeOAagUepe');
324
+ var navbar = document.querySelector('#VuAckcnZhf');
325
+
326
+ var navbarHeight = 0;
327
+ var footerHeight = 0;
328
+
329
+ if (footer) {
330
+ footerHeight = footer.getBoundingClientRect().height;
331
+ }
332
+
333
+ if (navbar) {
334
+ navbarHeight = navbar.getBoundingClientRect().height;
335
+ }
336
+
337
+ // eslint-disable-next-line no-undef
338
+ var preMaxHeight = window.innerHeight - navbarHeight - footerHeight - 250;
339
+
340
+ targets.forEach(function(pre, idx) {
341
+ var parent = pre.parentNode;
342
+
343
+ if (parent && parent.getAttribute('data-skip-pre-process') === 'true') {
344
+ return;
345
+ }
346
+
347
+ var div = getPreDiv();
348
+ var id = 'ScDloZOMdL' + idx;
349
+
350
+ var lang = pre.getAttribute('data-lang') || 'code';
351
+ var topBar = getPreTopBar(id, lang);
352
+
353
+ div.innerHTML = topBar;
354
+
355
+ pre.style.maxHeight = preMaxHeight + 'px';
356
+ pre.id = id;
357
+ pre.classList.add('prettyprint');
358
+ pre.parentNode.insertBefore(div, pre);
359
+ div.appendChild(pre);
360
+ });
361
+ }
362
+
363
+ function highlightAndBringLineIntoView() {
364
+ // eslint-disable-next-line no-undef
365
+ var lineNumber = window.location.hash.replace('#line', '');
366
+
367
+ try {
368
+ var selector = '[data-line-number="' + lineNumber + '"';
369
+
370
+ var element = document.querySelector(selector);
371
+
372
+ element.scrollIntoView();
373
+ element.parentNode.classList.add('selected');
374
+ } catch (error) {
375
+ console.error(error);
376
+ }
377
+ }
378
+
379
+ function getFontSize() {
380
+ var currentFontSize = 16;
381
+
382
+ try {
383
+ currentFontSize = Number.parseInt(
384
+ html.style.fontSize.split('px')[0],
385
+ 10
386
+ );
387
+ } catch (error) {
388
+ console.log(error);
389
+ }
390
+
391
+ return currentFontSize;
392
+ }
393
+
394
+ function updateFontSize(fontSize) {
395
+ html.style.fontSize = fontSize + 'px';
396
+ localStorage.setItem(fontSizeLocalStorageKey, fontSize);
397
+ var fontSizeText = document.querySelector(
398
+ '#b77a68a492f343baabea06fad81f651e'
399
+ );
400
+
401
+ if (fontSizeText) {
402
+ fontSizeText.innerHTML = fontSize;
403
+ }
404
+ }
405
+
406
+ (function() {
407
+ var fontSize = getFontSize();
408
+ var fontSizeInLocalStorage = localStorage.getItem(fontSizeLocalStorageKey);
409
+
410
+ if (fontSizeInLocalStorage) {
411
+ var n = Number.parseInt(fontSizeInLocalStorage, 10);
412
+
413
+ if (n === fontSize) {
414
+ return;
415
+ }
416
+ updateFontSize(n);
417
+ } else {
418
+ updateFontSize(fontSize);
419
+ }
420
+ })();
421
+
422
+ // eslint-disable-next-line no-unused-vars
423
+ function incrementFont(event) {
424
+ var n = getFontSize();
425
+
426
+ if (n < MAX_FONT_SIZE) {
427
+ updateFontSize(n + 1);
428
+ }
429
+ }
430
+
431
+ // eslint-disable-next-line no-unused-vars
432
+ function decrementFont(event) {
433
+ var n = getFontSize();
434
+
435
+ if (n > MIN_FONT_SIZE) {
436
+ updateFontSize(n - 1);
437
+ }
438
+ }
439
+
440
+ function fontSizeTooltip() {
441
+ var fontSize = getFontSize();
442
+
443
+ return `
444
+ <div class="font-size-tooltip">
445
+ <button aria-label="decrease-font-size" class="icon-button ${
446
+ fontSize >= MAX_FONT_SIZE ? 'disabled' : ''
447
+ }" onclick="decrementFont(event)">
448
+ <svg>
449
+ <use xlink:href="#minus-icon"></use>
450
+ </svg>
451
+ </button>
452
+ <div class="font-size-text" id="b77a68a492f343baabea06fad81f651e">
453
+ ${fontSize}
454
+ </div>
455
+ <button aria-label="increase-font-size" class="icon-button ${
456
+ fontSize <= MIN_FONT_SIZE ? 'disabled' : ''
457
+ }" onclick="incrementFont(event)">
458
+ <svg>
459
+ <use xlink:href="#add-icon"></use>
460
+ </svg>
461
+ </button>
462
+ <button class="icon-button" onclick="updateFontSize(16)">
463
+ <svg>
464
+ <use xlink:href="#reset-icon"></use>
465
+ </svg>
466
+ </button>
467
+ </div>
468
+
469
+ `;
470
+ }
471
+
472
+ function initTooltip() {
473
+ // add tooltip to navbar item
474
+ // eslint-disable-next-line no-undef
475
+ tippy('.theme-toggle', {
476
+ content: 'Toggle Theme',
477
+ delay: 500
478
+ });
479
+
480
+ // eslint-disable-next-line no-undef
481
+ tippy('.search-button', {
482
+ content: 'Search',
483
+ delay: 500
484
+ });
485
+
486
+ // eslint-disable-next-line no-undef
487
+ tippy('.font-size', {
488
+ content: 'Change font size',
489
+ delay: 500
490
+ });
491
+
492
+ // eslint-disable-next-line no-undef
493
+ tippy('.codepen-button', {
494
+ content: 'Open code in CodePen',
495
+ placement: 'left'
496
+ });
497
+
498
+ // eslint-disable-next-line no-undef
499
+ tippy('.copy-code', {
500
+ content: 'Copy this code',
501
+ placement: 'left'
502
+ });
503
+
504
+ // eslint-disable-next-line no-undef
505
+ tippy('.font-size', {
506
+ content: fontSizeTooltip(),
507
+ trigger: 'click',
508
+ interactive: true,
509
+ allowHTML: true,
510
+ placement: 'left'
511
+ });
512
+ }
513
+
514
+ function fixTable() {
515
+ var tables = document.querySelectorAll('table');
516
+ var table;
517
+
518
+ // eslint-disable-next-line no-undef
519
+ if (window.innerWidth > 900) {
520
+ // Only fixing table if width is smaller than 900px
521
+ return;
522
+ }
523
+
524
+ for (table of tables) {
525
+ if (table.classList.contains('hljs-ln')) {
526
+ // don't want to wrap code blocks.
527
+ return;
528
+ }
529
+
530
+ var div = document.createElement('div');
531
+
532
+ div.classList.add('table-div');
533
+ table.parentNode.insertBefore(div, table);
534
+ div.appendChild(table);
535
+ }
536
+ }
537
+
538
+ function hideMobileMenu() {
539
+ var mobileMenuContainer = document.querySelector('#mobile-sidebar');
540
+ var target = document.querySelector('#mobile-menu');
541
+ var svgUse = target.querySelector('use');
542
+
543
+ if (mobileMenuContainer) {
544
+ mobileMenuContainer.classList.remove('show');
545
+ }
546
+ if (target) {
547
+ target.setAttribute('data-isopen', 'false');
548
+ }
549
+ if (svgUse) {
550
+ svgUse.setAttribute('xlink:href', '#menu-icon');
551
+ }
552
+ }
553
+
554
+ function showMobileMenu() {
555
+ var mobileMenuContainer = document.querySelector('#mobile-sidebar');
556
+ var target = document.querySelector('#mobile-menu');
557
+ var svgUse = target.querySelector('use');
558
+
559
+ if (mobileMenuContainer) {
560
+ mobileMenuContainer.classList.add('show');
561
+ }
562
+ if (target) {
563
+ target.setAttribute('data-isopen', 'true');
564
+ }
565
+ if (svgUse) {
566
+ svgUse.setAttribute('xlink:href', '#close-icon');
567
+ }
568
+ }
569
+
570
+ function onMobileMenuClick() {
571
+ var target = document.querySelector('#mobile-menu');
572
+ var isOpen = target.getAttribute('data-isopen') === 'true';
573
+
574
+ if (isOpen) {
575
+ hideMobileMenu();
576
+ } else {
577
+ showMobileMenu();
578
+ }
579
+ }
580
+
581
+ function initMobileMenu() {
582
+ var menu = document.querySelector('#mobile-menu');
583
+
584
+ if (menu) {
585
+ menu.addEventListener('click', onMobileMenuClick);
586
+ }
587
+ }
588
+
589
+ function addHrefToSidebarTitle() {
590
+ var titles = document.querySelectorAll('.sidebar-title-anchor');
591
+
592
+ titles.forEach(function(title) {
593
+ // eslint-disable-next-line no-undef
594
+ title.setAttribute('href', baseURL);
595
+ });
596
+ }
597
+
598
+ function onDomContentLoaded() {
599
+ var themeButton = document.querySelectorAll('.theme-toggle');
600
+
601
+ initMobileMenu();
602
+
603
+ if (themeButton) {
604
+ themeButton.forEach(function(button) {
605
+ button.addEventListener('click', toggleTheme);
606
+ });
607
+ }
608
+
609
+ // Highlighting code
610
+
611
+ // eslint-disable-next-line no-undef
612
+ hljs.addPlugin({
613
+ 'after:highlightElement': function(obj) {
614
+ // Replace 'code' with result.language when
615
+ // we are able to cross check the correctness of
616
+ // result.
617
+ obj.el.parentNode.setAttribute('data-lang', 'code');
618
+ }
619
+ });
620
+ // eslint-disable-next-line no-undef
621
+ hljs.highlightAll();
622
+ // eslint-disable-next-line no-undef
623
+ hljs.initLineNumbersOnLoad({
624
+ singleLine: true
625
+ });
626
+
627
+ // Highlight complete
628
+
629
+ initAccordion();
630
+ addAnchor();
631
+ processAllPre();
632
+ hideTocOnSourcePage();
633
+ setTimeout(function() {
634
+ bringIdToViewOnMount();
635
+ if (isSourcePage()) {
636
+ highlightAndBringLineIntoView();
637
+ }
638
+ }, 1000);
639
+ initTooltip();
640
+ fixTable();
641
+ addHrefToSidebarTitle();
642
+ }
643
+
644
+ // eslint-disable-next-line no-undef
645
+ window.addEventListener('DOMContentLoaded', onDomContentLoaded);
646
+
647
+ console.log('Hash event added');
648
+
649
+ // eslint-disable-next-line no-undef
650
+ window.addEventListener('hashchange', (event) => {
651
+ const url = new URL(event.newURL);
652
+
653
+ if (url.hash !== '') {
654
+ bringIdToViewOnMount(url.hash);
655
+ }
656
+ });