vobi_document 1.1.6 → 1.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.
package/dist/print.js CHANGED
@@ -155,6 +155,36 @@ var REPEAT_TABLE_HEADERS = `(function () {
155
155
  return ancestors;
156
156
  }
157
157
 
158
+ function isIgnorable(node) {
159
+ return node.nodeType === 8 || (node.nodeType === 3 && !node.textContent.trim());
160
+ }
161
+
162
+ function nextSignificantNode(node) {
163
+ var sibling = node.nextSibling;
164
+ while (sibling) {
165
+ if (!isIgnorable(sibling)) return sibling;
166
+ sibling = sibling.nextSibling;
167
+ }
168
+ return null;
169
+ }
170
+
171
+ function nodeAfter(node, limiter) {
172
+ if (limiter && node === limiter) return null;
173
+ var significant = nextSignificantNode(node);
174
+ if (significant) return significant;
175
+ var current = node;
176
+ while ((current = current.parentNode)) {
177
+ if (limiter && current === limiter) return null;
178
+ significant = nextSignificantNode(current);
179
+ if (significant) return significant;
180
+ }
181
+ return null;
182
+ }
183
+
184
+ function hasChildTag(el, tag) {
185
+ return Array.prototype.slice.call(el.children).some(function (child) { return child.tagName === tag; });
186
+ }
187
+
158
188
  class RepeatingTableHeaders extends window.Paged.Handler {
159
189
  constructor(chunker, polisher, caller) {
160
190
  super(chunker, polisher, caller);
@@ -176,7 +206,8 @@ var REPEAT_TABLE_HEADERS = `(function () {
176
206
  var thead = node.tagName === 'THEAD' ? node : findFirstAncestor(node, 'thead');
177
207
  if (thead) {
178
208
  var lastTheadNode = thead.hasChildNodes() ? thead.lastChild : thead;
179
- breakToken.node = this.nodeAfter(lastTheadNode, chunker.source);
209
+ var next = nodeAfter(lastTheadNode, chunker.source);
210
+ if (next) breakToken.node = next;
180
211
  }
181
212
  }
182
213
 
@@ -187,12 +218,16 @@ var REPEAT_TABLE_HEADERS = `(function () {
187
218
  if (!renderedTable || renderedTable.getAttribute('data-repeated-headers')) return;
188
219
  var sourceTable = self.chunker.source.querySelector("[data-ref='" + ref + "']");
189
220
  if (!sourceTable) return;
190
- var firstChild = renderedTable.firstChild;
191
- sourceTable.querySelectorAll('colgroup').forEach(function (colgroup) {
192
- renderedTable.insertBefore(colgroup.cloneNode(true), firstChild);
193
- });
221
+ if (!hasChildTag(renderedTable, 'COLGROUP')) {
222
+ var firstChild = renderedTable.firstChild;
223
+ sourceTable.querySelectorAll('colgroup').forEach(function (colgroup) {
224
+ renderedTable.insertBefore(colgroup.cloneNode(true), firstChild);
225
+ });
226
+ }
194
227
  var thead = sourceTable.querySelector('thead');
195
- if (thead) renderedTable.insertBefore(thead.cloneNode(true), renderedTable.firstChild);
228
+ if (thead && !hasChildTag(renderedTable, 'THEAD')) {
229
+ renderedTable.insertBefore(thead.cloneNode(true), renderedTable.firstChild);
230
+ }
196
231
  renderedTable.setAttribute('data-repeated-headers', 'true');
197
232
  });
198
233
  }