asciidoctor-html 2.2.7 → 2.2.9

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.
@@ -3,7 +3,6 @@
3
3
  require_relative "highlightjs"
4
4
  require_relative "popovers"
5
5
  require_relative "sidebar"
6
- require_relative "scroll"
7
6
  require_relative "flip"
8
7
  require_relative "live"
9
8
 
@@ -12,7 +11,7 @@ module Asciidoctor
12
11
  # The template for the book layout
13
12
  module BookTemplate
14
13
  MENU_BTN = <<~HTML
15
- <button type="button" id="menu-btn" class="btn menu"
14
+ <button type="button" id="menu-btn" class="btn menu fadein"
16
15
  aria-expanded="false" aria-controls="sidebar">
17
16
  <i class="bi bi-list"></i>
18
17
  </button>
@@ -30,8 +29,11 @@ module Asciidoctor
30
29
  data-bs-target="##{id}"
31
30
  aria-expanded="#{active ? "true" : "false"}"
32
31
  aria-controls="#{id}">
33
- <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="caret" viewBox="0 0 16 16">
34
- <path d="M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z"/>
32
+ <svg xmlns="http://www.w3.org/2000/svg"
33
+ fill="currentColor"
34
+ class="caret"
35
+ viewBox="0 0 8 12">
36
+ <path d="M0 0 L8 6 L0 12 Z"/>
35
37
  </svg>
36
38
  </button>
37
39
  HTML
@@ -116,7 +118,7 @@ module Asciidoctor
116
118
  # - pagestyle: Symbol
117
119
  def self.main(opts)
118
120
  <<~HTML
119
- <main id="main" class="main">
121
+ <main id="main" class="main fadein">
120
122
  <div id="content-container" class="content-container dynamic-width" tabindex="0">
121
123
  #{chapheader opts[:chapheading], opts[:chapsubheading]}
122
124
  <div class="chaphead flip d-block">
@@ -168,7 +170,7 @@ module Asciidoctor
168
170
 
169
171
  def self.footer(authors)
170
172
  <<~HTML
171
- <footer class="footer">
173
+ <footer class="footer fadein">
172
174
  <div class="footer-content dynamic-width">
173
175
  <div class="footer-left">&#169; <span id="cr-year"></span> #{authors}</div>
174
176
  <div class="footer-right">Built with
@@ -212,6 +214,15 @@ module Asciidoctor
212
214
  #{highlightjs(opts)}
213
215
  <script>
214
216
  MathJax = {
217
+ options: {
218
+ enableMenu: false
219
+ },
220
+ startup: {
221
+ typeset: false,
222
+ pageReady() {
223
+ return MathJax.typesetPromise([document.getElementById('sidebar')]);
224
+ }
225
+ },
215
226
  tex: {
216
227
  inlineMath: {'[+]': [['$', '$']]}
217
228
  },
@@ -263,6 +274,14 @@ module Asciidoctor
263
274
  <body>
264
275
  #{sidebar(nav_items) if nav}
265
276
  <div id="page" class="#{page_classname}">
277
+ <div class="loading-overlay">
278
+ #{header opts[:title], opts[:short_title], opts[:chapheading], opts[:has_subnav]}
279
+ <div class="spinner-container">
280
+ <div class="spinner-border" role="status">
281
+ <span class="visually-hidden">Loading...</span>
282
+ </div>
283
+ </div>
284
+ </div>
266
285
  #{MENU_BTN if nav}
267
286
  #{header opts[:title], opts[:short_title], opts[:chapheading], opts[:has_subnav]}
268
287
  #{main content:, **opts}
@@ -274,8 +293,7 @@ module Asciidoctor
274
293
  #{Highlightjs::PLUGIN if opts[:langs]}
275
294
  #{Popovers::POPOVERS}
276
295
  #{Sidebar::TOGGLE if nav}
277
- #{Scroll::SCROLL}
278
- #{Flip::FLIP if nav}
296
+ #{Flip::FLIP}
279
297
  #{Live::LIVE if nav && opts[:has_live]}
280
298
  </script>
281
299
  #{opts[:at_body_end]}
@@ -15,18 +15,20 @@ module Asciidoctor
15
15
  };
16
16
 
17
17
  // Dictionary sect ID => [all sects until next sect with ID]
18
- const sectsById = { "page": []};
18
+ const sectsById = { 'page': []};
19
19
 
20
20
  const page = document.getElementById('page');
21
21
  const main = document.getElementById('main');
22
22
  const focusEl = document.getElementById('content-container');
23
+ const paginator = document.getElementById('paginator');
23
24
  const searchForm = document.getElementById('search-form');
24
25
  const chapheading = page.querySelector('.chapheading');
25
26
  const chaptitle = page.querySelector('.chaptitle');
26
27
 
27
28
  const nav = document.querySelectorAll('#sidebar nav > ul > li.active ul li');
28
29
 
29
- let currentId = "page";
30
+ let scrollTop = {}; // cache scroll position by id
31
+ let currentId = 'page';
30
32
  focusEl.querySelectorAll(':scope > .flip').forEach(el => {
31
33
  if(el.id) {
32
34
  el.dataset.prevPage = currentId;
@@ -59,7 +61,6 @@ module Asciidoctor
59
61
  }
60
62
 
61
63
  function updatePaginator(prev, next) {
62
- const paginator = document.querySelector('.paginator');
63
64
  if(!paginator) return;
64
65
  const nextPage = paginator.lastElementChild;
65
66
  const prevPage = paginator.firstElementChild;
@@ -92,13 +93,15 @@ module Asciidoctor
92
93
  }
93
94
  }
94
95
 
95
- function flip(e) {
96
- if(!page.classList.contains('multi')) {
97
- focusOnLoad();
98
- return;
99
- }
96
+ function getScrollEl() {
97
+ return page.classList.contains('presentation') ? main : page;
98
+ }
99
+
100
+ currentId = null;
100
101
 
102
+ async function flip(e) {
101
103
  e && e.preventDefault();
104
+ const scrollEl = getScrollEl();
102
105
 
103
106
  const href = location.hash;
104
107
  let id = href.substring(1);
@@ -117,61 +120,73 @@ module Asciidoctor
117
120
  id = 'page';
118
121
  }
119
122
 
123
+ const needsFlip = (currentId !== id);
124
+
120
125
  const isPresentation = page.classList.contains('presentation');
121
- document.querySelector('.breadcrumb').classList.toggle('d-block', id != 'page' && !isPresentation);
126
+ const isMulti = page.classList.contains('multi');
127
+ document.querySelector('.breadcrumb').classList.toggle('d-block', id != 'page' && isMulti && !isPresentation);
122
128
  document.querySelector('.chapauthors').classList.toggle('d-block', isPresentation);
123
129
 
124
- for(const key in sectsById) {
125
- if(key == id) {
126
- const firstSect = sectsById[key][0];
127
- const prev = firstSect.dataset.prevPage && sectsById[firstSect.dataset.prevPage][0];
128
- const next = firstSect.dataset.nextPage && sectsById[firstSect.dataset.nextPage][0];
129
- updatePaginator(prev, next);
130
- sectsById[key].forEach(el => el.classList.add('d-block'));
131
- } else {
132
- sectsById[key].forEach(el => el.classList.remove('d-block'));
130
+ let activeSects = [focusEl];
131
+ if(isMulti && needsFlip) {
132
+ page.classList.remove('loaded');
133
+ for(const key in sectsById) {
134
+ if(key == id) {
135
+ const firstSect = sectsById[key][0];
136
+ const prev = firstSect.dataset.prevPage && sectsById[firstSect.dataset.prevPage][0];
137
+ const next = firstSect.dataset.nextPage && sectsById[firstSect.dataset.nextPage][0];
138
+ updatePaginator(prev, next);
139
+ activeSects = sectsById[key];
140
+ activeSects.forEach(el => el.classList.add('d-block'));
141
+ } else {
142
+ sectsById[key].forEach(el => el.classList.remove('d-block'));
143
+ }
133
144
  }
134
145
  }
135
146
 
147
+ const typesetEls = paginator ? [...activeSects, paginator] : activeSects;
148
+ // MathJax needs displayed content to calculate auto line breaks.
149
+ await MathJax.startup.promise;
150
+ await MathJax.typesetPromise(typesetEls);
151
+ ADHT.nudgeMenuBtn();
152
+ page.classList.add('loaded');
153
+
136
154
  nav.forEach(el => {
137
155
  const a = el.querySelector('a');
138
156
  a && a.hash && el.classList.toggle('active', id == a.hash.substring(1));
139
157
  });
140
158
 
141
- ADHT.nudgeMenuBtn();
142
-
143
- const scrollEl = isPresentation ? main : page;
144
- if(target == section || target == page) {
159
+ if(target == section && page.classList.contains('multi') || target == page) {
145
160
  scrollEl.scrollTo({
146
- top: 0,
161
+ top: id in scrollTop ? scrollTop[id] : 0,
147
162
  left: 0,
148
163
  behavior: 'instant'
149
164
  });
150
165
  } else {
151
166
  const rect = target.getBoundingClientRect();
167
+ const containerRect = scrollEl.getBoundingClientRect();
152
168
  scrollEl.scrollTo({
153
- top: rect.top + scrollEl.scrollTop,
169
+ top: rect.top + scrollEl.scrollTop - containerRect.top,
154
170
  left: 0
155
171
  });
156
172
  }
157
173
 
158
174
  focusOnLoad();
159
175
  if(isPresentation) focusEl.dataset.flip = id;
176
+ currentId = id;
160
177
  }
161
178
 
162
- flip();
163
-
164
179
  const dropdownItems = document.querySelectorAll('#viewmode-actions .dropdown-item');
165
180
  const dropdownToggle = document.getElementById('btn-toggle');
166
181
  function changeViewmode(viewmode) {
167
182
  page.classList.toggle('multi', viewmode == 'multi' || viewmode == 'presentation');
168
183
  page.classList.toggle('presentation', viewmode == 'presentation');
169
184
  if(viewmode == 'single') {
170
- ADHT.nudgeMenuBtn();
171
185
  updatePaginator();
172
- } else {
173
- flip();
174
186
  }
187
+ currentId = null;
188
+ scrollTop = {};
189
+ flip();
175
190
  dropdownItems.forEach(el => {
176
191
  const isActive = (el.dataset.viewmode == viewmode);
177
192
  el.classList.toggle('active', isActive);
@@ -195,6 +210,21 @@ module Asciidoctor
195
210
  page.classList.contains('presentation') && changeViewmode('multi');
196
211
  }
197
212
  });
213
+ document.querySelectorAll('a').forEach(el => {
214
+ el.addEventListener('click', () => {
215
+ const scrollEl = getScrollEl();
216
+ if(currentId) {
217
+ scrollTop[currentId] = scrollEl.scrollTop;
218
+ }
219
+ });
220
+ });
221
+
222
+ const clickableHSelector = [2, 3, 4].map(v => `section[id] > h${v}:first-child`).join(', ');
223
+ document.querySelectorAll(clickableHSelector).forEach(el => {
224
+ el.addEventListener('click', function() {
225
+ location.hash = el.parentElement.id;
226
+ });
227
+ });
198
228
 
199
229
  dropdownItems && dropdownItems.forEach(link => link.addEventListener('click', function(e){
200
230
  e.preventDefault();
@@ -202,7 +232,7 @@ module Asciidoctor
202
232
  changeViewmode(viewmode);
203
233
  }));
204
234
 
205
- page.classList.add('loaded');
235
+ flip();
206
236
 
207
237
  ADHT.move = move;
208
238
  })();
@@ -42,7 +42,7 @@ module Asciidoctor
42
42
  blank = %(<span class="blank">&nbsp;</span>)
43
43
  html = [<<~HTML
44
44
  <div class="paginator-wrapper">
45
- <div class="paginator dynamic-width">
45
+ <div id="paginator" class="paginator dynamic-width fadein">
46
46
  HTML
47
47
  ]
48
48
  html << if prv
@@ -5,10 +5,10 @@ module Asciidoctor
5
5
  # Configure the popovers for footnotes and citations.
6
6
  module Popovers
7
7
  POPOVERS = <<~JS
8
- (function() {
8
+ (async function() {
9
9
  const popovers = []
10
- function initPopovers() {
11
- document.querySelectorAll('.btn-po[data-contentid]').forEach(el => {
10
+ async function initPopovers() {
11
+ for(const el of document.querySelectorAll('.btn-po[data-contentid]')) {
12
12
  const id = el.dataset.contentid;
13
13
  let content = document.getElementById(id);
14
14
  if(content) {
@@ -18,6 +18,7 @@ module Asciidoctor
18
18
  bibItem.removeChild(bibItem.firstChild); // remove the anchor
19
19
  content = bibItem.innerHTML;
20
20
  } else {
21
+ await MathJax.typesetPromise([content]);
21
22
  content = content.cloneNode(true);
22
23
  }
23
24
  popovers.push(new bootstrap.Popover(el, {
@@ -26,7 +27,7 @@ module Asciidoctor
26
27
  sanitize: false
27
28
  }));
28
29
  }
29
- });
30
+ }
30
31
  }
31
32
  addEventListener('click', e => {
32
33
  const match = e.target.closest('.btn-po[aria-describedby],.popover');
@@ -34,7 +35,10 @@ module Asciidoctor
34
35
  popovers.forEach(po => po.hide());
35
36
  }
36
37
  })
37
- MathJax.startup.promise.then(initPopovers);
38
+
39
+ await MathJax.startup.promise;
40
+ await initPopovers();
41
+
38
42
  // Enable tooltips
39
43
  document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(el => {
40
44
  bootstrap.Tooltip.getOrCreateInstance(el);
@@ -9,19 +9,14 @@ module Asciidoctor
9
9
  const menuBtn = document.getElementById('menu-btn');
10
10
  if(!menuBtn) return;
11
11
 
12
- const isPresentation = page.classList.contains('presentation')
13
- if(isPresentation) {
14
- menuBtn.getAnimations().forEach(anim => anim.cancel());
15
- return menuBtn;
16
- }
17
-
18
12
  const scrollbarWidth = page.offsetWidth - page.clientWidth;
19
13
 
20
14
  // Nudge menuBtn in case there is a scrollbar
21
- menuBtn.animate(
22
- { transform: 'translateX(' + (-scrollbarWidth) + 'px)' },
23
- { fill: 'forwards', duration: 150 }
24
- );
15
+ menuBtn.style.right = (scrollbarWidth + 12) + 'px';
16
+
17
+ if(menuBtn.classList.contains('fadein')) {
18
+ setTimeout(() => menuBtn.classList.remove('fadein'), 600);
19
+ }
25
20
 
26
21
  // Cache scrollbar width
27
22
  ADHT.scrollbarWidth = scrollbarWidth;
@@ -43,7 +38,7 @@ module Asciidoctor
43
38
  addEventListener('resize', hideSidebar);
44
39
  dismissBtn && dismissBtn.addEventListener('click', hideSidebar);
45
40
 
46
- const menuBtn = ADHT.nudgeMenuBtn();
41
+ const menuBtn = document.getElementById('menu-btn');
47
42
  if(!menuBtn) return;
48
43
  // Add click listener to toggle sidebar
49
44
  menuBtn.addEventListener('click', function() {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Html
5
- VERSION = "2.2.7"
5
+ VERSION = "2.2.9"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.7
4
+ version: 2.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravi Rajani
@@ -126,7 +126,6 @@ files:
126
126
  - lib/asciidoctor/html/pagination.rb
127
127
  - lib/asciidoctor/html/popovers.rb
128
128
  - lib/asciidoctor/html/ref_tree_processor.rb
129
- - lib/asciidoctor/html/scroll.rb
130
129
  - lib/asciidoctor/html/search.rb
131
130
  - lib/asciidoctor/html/sidebar.rb
132
131
  - lib/asciidoctor/html/subnav_block_macro.rb
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Asciidoctor
4
- module Html
5
- # Due to mobile dynamic viewport heights, we need custom code for
6
- # reliable anchor scrolling.
7
- module Scroll
8
- SCROLL = <<~JS
9
- (function() {
10
- let scrolledOnce = false;
11
- const page = document.getElementById('page');
12
- function scrollToElement(e) {
13
- if(page.classList.contains('multi')) return;
14
-
15
- e && e.preventDefault();
16
- scrolledOnce = true;
17
- const href = location.hash;
18
- const id = href.substring(1);
19
- const target = document.getElementById(id);
20
- if(!target) return;
21
-
22
- const rect = target.getBoundingClientRect();
23
- page.scrollTo({
24
- top: rect.top + page.scrollTop,
25
- left: 0
26
- });
27
- }
28
- addEventListener('load', function() {
29
- !scrolledOnce && scrollToElement();
30
- });
31
- addEventListener('hashchange', scrollToElement);
32
- const clickableHSelector = [2, 3, 4].map(v => `section[id] > h${v}:first-child`).join(', ');
33
- document.querySelectorAll(clickableHSelector).forEach(el => {
34
- el.addEventListener('click', function() {
35
- location.hash = el.parentElement.id;
36
- });
37
- });
38
- })();
39
- JS
40
- end
41
- end
42
- end