@internetarchive/bookreader 5.0.0-88-alpha.3 → 5.0.0-88-alpha.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/bookreader",
3
- "version": "5.0.0-88-alpha.3",
3
+ "version": "5.0.0-88-alpha.5",
4
4
  "description": "The Internet Archive BookReader.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,6 +39,7 @@
39
39
  "@internetarchive/icon-visual-adjustment": "^1.3.4",
40
40
  "@internetarchive/modal-manager": "^2.0.1",
41
41
  "@internetarchive/shared-resize-observer": "^0.2.0",
42
+ "interactjs": "^1.10.18",
42
43
  "jquery": "3.6.1",
43
44
  "jquery-colorbox": "1.6.4",
44
45
  "jquery-ui": "^1.12.1",
@@ -65,7 +66,6 @@
65
66
  "eslint-plugin-no-jquery": "^2.7.0",
66
67
  "eslint-plugin-testcafe": "^0.2.1",
67
68
  "http-server": "14.1.1",
68
- "interactjs": "^1.10.18",
69
69
  "iso-language-codes": "1.1.0",
70
70
  "jest": "29.7.0",
71
71
  "jest-environment-jsdom": "^29.7.0",
@@ -1,10 +1,10 @@
1
1
  // @ts-check
2
- import { customElement, property, query } from 'lit/decorators.js';
3
- import {LitElement, html} from 'lit';
2
+ import { property, query } from 'lit/decorators.js';
3
+ import { LitElement, html } from 'lit';
4
4
  import { styleMap } from 'lit/directives/style-map.js';
5
5
  import { ModeSmoothZoom } from './ModeSmoothZoom';
6
6
  import { arrChanged, genToArray, sum, throttle } from './utils';
7
- import { HTMLDimensionsCacher } from "./utils/HTMLDimensionsCacher";
7
+ import { HTMLDimensionsCacher } from './utils/HTMLDimensionsCacher';
8
8
  import { ScrollClassAdder } from './utils/ScrollClassAdder';
9
9
  import { ModeCoordinateSpace } from './ModeCoordinateSpace';
10
10
  /** @typedef {import('./BookModel').BookModel} BookModel */
@@ -17,7 +17,6 @@ import { ModeCoordinateSpace } from './ModeCoordinateSpace';
17
17
  // I _have_ to make this globally public, otherwise it won't let me call
18
18
  // it's constructor :/
19
19
  /** @implements {SmoothZoomable} */
20
- @customElement('br-mode-1up')
21
20
  export class Mode1UpLit extends LitElement {
22
21
  /****************************************/
23
22
  /************** PROPERTIES **************/
@@ -86,13 +85,15 @@ export class Mode1UpLit extends LitElement {
86
85
  get worldStyle() {
87
86
  const wToR = this.coordSpace.worldUnitsToRenderedPixels;
88
87
  return {
89
- width: wToR(this.worldDimensions.width) + "px",
90
- height: wToR(this.worldDimensions.height) + "px",
88
+ width: wToR(this.worldDimensions.width) + 'px',
89
+ height: wToR(this.worldDimensions.height) + 'px',
91
90
  };
92
91
  }
93
92
 
94
93
  /** @type {HTMLElement} */
95
- get $container() { return this; }
94
+ get $container() {
95
+ return this;
96
+ }
96
97
 
97
98
  /** @type {HTMLElement} */
98
99
  @query('.br-mode-1up__visible-world')
@@ -128,10 +129,12 @@ export class Mode1UpLit extends LitElement {
128
129
  if (smooth) {
129
130
  this.style.scrollBehavior = 'smooth';
130
131
  }
131
- this.scrollTop = this.coordSpace.worldUnitsToVisiblePixels(this.pageTops[index] - this.SPACING_IN / 2);
132
+ this.scrollTop = this.coordSpace.worldUnitsToVisiblePixels(
133
+ this.pageTops[index] - this.SPACING_IN / 2,
134
+ );
132
135
  // TODO: Also h center?
133
136
  if (smooth) {
134
- setTimeout(() => this.style.scrollBehavior = '', 100);
137
+ setTimeout(() => (this.style.scrollBehavior = ''), 100);
135
138
  }
136
139
  }
137
140
 
@@ -194,7 +197,7 @@ export class Mode1UpLit extends LitElement {
194
197
  this.throttledUpdateRenderedPages();
195
198
  if (this.visiblePages.length) {
196
199
  // unclear why this is ever really happening
197
- this.br.displayedIndices = this.visiblePages.map(p => p.index);
200
+ this.br.displayedIndices = this.visiblePages.map((p) => p.index);
198
201
  this.br.updateFirstIndex(this.br.displayedIndices[0]);
199
202
  this.br._components.navbar.updateNavIndexThrottled();
200
203
  }
@@ -211,7 +214,9 @@ export class Mode1UpLit extends LitElement {
211
214
  }
212
215
 
213
216
  updatePages() {
214
- this.pages = genToArray(this.book.pagesIterator({ combineConsecutiveUnviewables: true }));
217
+ this.pages = genToArray(
218
+ this.book.pagesIterator({ combineConsecutiveUnviewables: true }),
219
+ );
215
220
  }
216
221
 
217
222
  /** @override */
@@ -242,50 +247,59 @@ export class Mode1UpLit extends LitElement {
242
247
 
243
248
  /** @override */
244
249
  render() {
245
- return html`
246
- <div class="br-mode-1up__world" style=${styleMap(this.worldStyle)}></div>
250
+ return html` <div
251
+ class="br-mode-1up__world"
252
+ style=${styleMap(this.worldStyle)}
253
+ ></div>
247
254
  <div class="br-mode-1up__visible-world">
248
- ${this.renderedPages.map(p => this.renderPage(p))}
255
+ ${this.renderedPages.map((p) => this.renderPage(p))}
249
256
  </div>`;
250
257
  }
251
258
 
252
259
  /** @param {PageModel} page */
253
260
  createPageContainer = (page) => {
254
- return this.pageContainerCache[page.index] || (
255
- this.pageContainerCache[page.index] = (
261
+ return (
262
+ this.pageContainerCache[page.index] ||
263
+ (this.pageContainerCache[page.index] =
256
264
  // @ts-ignore I know it's protected, TS! But Mode1Up and BookReader are friends.
257
- this.br._createPageContainer(page.index)
258
- )
265
+ this.br._createPageContainer(page.index))
259
266
  );
260
- }
267
+ };
261
268
 
262
269
  /** @param {PageModel} page */
263
270
  renderPage = (page) => {
264
271
  const wToR = this.coordSpace.worldUnitsToRenderedPixels;
265
272
  const wToV = this.coordSpace.worldUnitsToVisiblePixels;
266
- const containerWidth = this.coordSpace.visiblePixelsToWorldUnits(this.htmlDimensionsCacher.clientWidth);
273
+ const containerWidth = this.coordSpace.visiblePixelsToWorldUnits(
274
+ this.htmlDimensionsCacher.clientWidth,
275
+ );
267
276
 
268
277
  const width = wToR(page.widthInches);
269
278
  const height = wToR(page.heightInches);
270
- const left = Math.max(this.SPACING_IN, (containerWidth - page.widthInches) / 2);
279
+ const left = Math.max(
280
+ this.SPACING_IN,
281
+ (containerWidth - page.widthInches) / 2,
282
+ );
271
283
  const top = this.pageTops[page.index];
272
284
 
273
285
  const transform = `translate(${wToR(left)}px, ${wToR(top)}px)`;
274
- const pageContainerEl = this.createPageContainer(page)
275
- .update({
276
- dimensions: {
277
- width,
278
- height,
279
- top: 0,
280
- left: 0,
281
- },
282
- reduce: page.width / wToV(page.widthInches),
283
- }).$container[0];
286
+ const pageContainerEl = this.createPageContainer(page).update({
287
+ dimensions: {
288
+ width,
289
+ height,
290
+ top: 0,
291
+ left: 0,
292
+ },
293
+ reduce: page.width / wToV(page.widthInches),
294
+ }).$container[0];
284
295
 
285
296
  pageContainerEl.style.transform = transform;
286
- pageContainerEl.classList.toggle('BRpage-visible', this.visiblePages.includes(page));
297
+ pageContainerEl.classList.toggle(
298
+ 'BRpage-visible',
299
+ this.visiblePages.includes(page),
300
+ );
287
301
  return pageContainerEl;
288
- }
302
+ };
289
303
 
290
304
  /************** VIRTUAL SCROLLING LOGIC **************/
291
305
 
@@ -306,7 +320,7 @@ export class Mode1UpLit extends LitElement {
306
320
  left: vToW(scrollLeft),
307
321
  width: vToW(clientWidth),
308
322
  };
309
- }
323
+ };
310
324
 
311
325
  /**
312
326
  * @returns {PageModel[]}
@@ -314,20 +328,26 @@ export class Mode1UpLit extends LitElement {
314
328
  computeRenderedPages() {
315
329
  // Also render 1 page before/after
316
330
  // @ts-ignore TS doesn't understand the filtering out of null values
317
- return [
318
- this.visiblePages[0]?.prev,
319
- ...this.visiblePages,
320
- this.visiblePages[this.visiblePages.length - 1]?.next,
321
- ]
322
- .filter(p => p)
323
- // Never render more than 10 pages! Usually means something is wrong
324
- .slice(0, 10);
331
+ return (
332
+ [
333
+ this.visiblePages[0]?.prev,
334
+ ...this.visiblePages,
335
+ this.visiblePages[this.visiblePages.length - 1]?.next,
336
+ ]
337
+ .filter((p) => p)
338
+ // Never render more than 10 pages! Usually means something is wrong
339
+ .slice(0, 10)
340
+ );
325
341
  }
326
342
 
327
- throttledUpdateRenderedPages = throttle(() => {
328
- this.renderedPages = this.computeRenderedPages();
329
- this.requestUpdate();
330
- }, 100, null)
343
+ throttledUpdateRenderedPages = throttle(
344
+ () => {
345
+ this.renderedPages = this.computeRenderedPages();
346
+ this.requestUpdate();
347
+ },
348
+ 100,
349
+ null,
350
+ );
331
351
 
332
352
  /**
333
353
  * @param {PageModel[]} pages
@@ -350,21 +370,29 @@ export class Mode1UpLit extends LitElement {
350
370
  */
351
371
  computeDefaultScale(page) {
352
372
  // Default to real size if it fits, otherwise default to full width
353
- const containerWidthIn = this.coordSpace.renderedPixelsToWorldUnits(this.clientWidth);
354
- return Math.min(1, containerWidthIn / (page.widthInches + 2 * this.SPACING_IN)) || 1;
373
+ const containerWidthIn = this.coordSpace.renderedPixelsToWorldUnits(
374
+ this.clientWidth,
375
+ );
376
+ return (
377
+ Math.min(
378
+ 1,
379
+ containerWidthIn / (page.widthInches + 2 * this.SPACING_IN),
380
+ ) || 1
381
+ );
355
382
  }
356
383
 
357
384
  computeWorldDimensions() {
358
385
  return {
359
- width: Math.max(...this.pages.map(p => p.widthInches)) + 2 * this.SPACING_IN,
386
+ width:
387
+ Math.max(...this.pages.map((p) => p.widthInches)) + 2 * this.SPACING_IN,
360
388
  height:
361
- sum(this.pages.map(p => p.heightInches)) +
362
- (this.pages.length + 1) * this.SPACING_IN,
389
+ sum(this.pages.map((p) => p.heightInches)) +
390
+ (this.pages.length + 1) * this.SPACING_IN,
363
391
  };
364
392
  }
365
393
 
366
394
  computeVisiblePages() {
367
- return this.pages.filter(page => {
395
+ return this.pages.filter((page) => {
368
396
  const PT = this.pageTops[page.index];
369
397
  const PB = PT + page.heightInches;
370
398
 
@@ -377,12 +405,14 @@ export class Mode1UpLit extends LitElement {
377
405
  /************** INPUT HANDLERS **************/
378
406
 
379
407
  attachScrollListeners = () => {
380
- this.addEventListener("scroll", this.updateVisibleRegion);
408
+ this.addEventListener('scroll', this.updateVisibleRegion);
381
409
  this.scrollClassAdder.attach();
382
- }
410
+ };
383
411
 
384
412
  detachScrollListeners = () => {
385
- this.removeEventListener("scroll", this.updateVisibleRegion);
413
+ this.removeEventListener('scroll', this.updateVisibleRegion);
386
414
  this.scrollClassAdder.detach();
387
- }
415
+ };
388
416
  }
417
+
418
+ customElements.define('br-mode-1up', Mode1UpLit);
@@ -16,7 +16,6 @@ import { ModeCoordinateSpace } from './ModeCoordinateSpace';
16
16
  // I _have_ to make this globally public, otherwise it won't let me call
17
17
  // its constructor :/
18
18
  /** @implements {SmoothZoomable} */
19
- @customElement('br-mode-2up')
20
19
  export class Mode2UpLit extends LitElement {
21
20
  /****************************************/
22
21
  /************** PROPERTIES **************/
@@ -676,7 +675,6 @@ export class Mode2UpLit extends LitElement {
676
675
  }
677
676
  }
678
677
 
679
- @customElement('br-leaf-edges')
680
678
  export class LeafEdges extends LitElement {
681
679
  @property({ type: Number }) leftIndex = 0;
682
680
  @property({ type: Number }) rightIndex = 0;
@@ -774,3 +772,6 @@ export class LeafEdges extends LitElement {
774
772
  return Math.floor(this.leftIndex + (e.offsetX / this.offsetWidth) * (this.rightIndex - this.leftIndex + 1));
775
773
  }
776
774
  }
775
+
776
+ customElements.define('br-mode-2up', Mode2UpLit);
777
+ customElements.define('br-leaf-edges', LeafEdges);
@@ -191,7 +191,6 @@ BookReader.prototype._chaptersUpdateCurrent = function(
191
191
  }
192
192
  };
193
193
 
194
- @customElement('br-chapters-panel')
195
194
  export class BRChaptersPanel extends LitElement {
196
195
  /** @type {TocEntry[]} */
197
196
  @property({ type: Array })
@@ -214,9 +213,9 @@ export class BRChaptersPanel extends LitElement {
214
213
 
215
214
  render() {
216
215
  return html`
217
- <ol>
218
- ${this.contents.map(tocEntry => this.renderTOCEntry(tocEntry))}
219
- </ol>
216
+ <ol>
217
+ ${this.contents.map((tocEntry) => this.renderTOCEntry(tocEntry))}
218
+ </ol>
220
219
  `;
221
220
  }
222
221
 
@@ -225,26 +224,29 @@ export class BRChaptersPanel extends LitElement {
225
224
  */
226
225
  renderTOCEntry(tocEntry) {
227
226
  const chapterTitle = [tocEntry.label, tocEntry.title]
228
- .filter(x => x)
227
+ .filter((x) => x)
229
228
  .join(' ');
230
229
  const clickable = tocEntry.pageIndex != undefined;
231
230
  // note the click-tracking won't work...
232
- return html`
233
- <li
231
+ return html` <li
234
232
  class="
235
233
  BRtable-contents-el
236
234
  ${clickable ? 'clickable' : ''}
237
235
  ${tocEntry == this.currentChapter ? 'current' : ''}
238
236
  "
239
- style="${styleMap({marginLeft: (tocEntry.level - 1) * 10 + 'px'})}"
240
- data-event-click-tracking="${ifDefined(clickable ? "BRTOCPanel|GoToChapter" : undefined)}"
237
+ style="${styleMap({ marginLeft: (tocEntry.level - 1) * 10 + 'px' })}"
238
+ data-event-click-tracking="${ifDefined(
239
+ clickable ? 'BRTOCPanel|GoToChapter' : undefined,
240
+ )}"
241
241
  @click="${() => this.jumpToPage(tocEntry.pageIndex)}"
242
242
  >
243
243
  ${chapterTitle}
244
- ${tocEntry.pagenum ? html`
245
- <br />
246
- <span class="BRTOCElementPage">Page ${tocEntry.pagenum}</span>
247
- ` : nothing}
244
+ ${tocEntry.pagenum
245
+ ? html`
246
+ <br />
247
+ <span class="BRTOCElementPage">Page ${tocEntry.pagenum}</span>
248
+ `
249
+ : nothing}
248
250
  </li>`;
249
251
  }
250
252
 
@@ -281,17 +283,20 @@ export class BRChaptersPanel extends LitElement {
281
283
  }
282
284
 
283
285
  li.clickable:not(.current):hover {
284
- background-color: rgba(255,255,255, 0.05);
286
+ background-color: rgba(255, 255, 255, 0.05);
285
287
  }
286
288
 
287
289
  li.current {
288
- background-color: rgba(255,255,255,0.9);
290
+ background-color: rgba(255, 255, 255, 0.9);
289
291
  color: #333;
290
292
  }
291
293
 
292
294
  .BRTOCElementPage {
293
295
  font-size: 0.85em;
294
- opacity: .8;
295
- }`;
296
+ opacity: 0.8;
297
+ }
298
+ `;
296
299
  }
297
300
  }
301
+
302
+ customElements.define('br-chapters-panel', BRChaptersPanel);