@d-i-t-a/reader 2.1.0-beta.3 → 2.1.0-beta.4

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/esm/index.js CHANGED
@@ -10118,9 +10118,9 @@ var require_source_map = __commonJS({
10118
10118
  }
10119
10119
  });
10120
10120
 
10121
- // (disabled):path
10121
+ // (disabled):node_modules/path/path.js
10122
10122
  var require_path = __commonJS({
10123
- "(disabled):path"() {
10123
+ "(disabled):node_modules/path/path.js"() {
10124
10124
  init_polyfills();
10125
10125
  }
10126
10126
  });
@@ -34139,8 +34139,8 @@ function TaJsonDeserialize(json, type) {
34139
34139
 
34140
34140
  // src/model/Publication.ts
34141
34141
  var Publication = class extends import_publication.Publication {
34142
- static async fromUrl(url, requestInit) {
34143
- const response = await fetch(url.href, requestInit);
34142
+ static async fromUrl(url, requestConfig) {
34143
+ const response = await fetch(url.href, requestConfig);
34144
34144
  const manifestJSON = await response.json();
34145
34145
  let publication = TaJsonDeserialize(manifestJSON, Publication);
34146
34146
  publication.manifestUrl = url;
@@ -34316,7 +34316,7 @@ var Publication = class extends import_publication.Publication {
34316
34316
  const decodedHref = decodeURI(href) ?? "";
34317
34317
  return this.positions?.filter((p) => decodedHref.includes(p.href));
34318
34318
  }
34319
- async autoGeneratePositions(requestInit, getContentBytesLength = fetchContentBytesLength) {
34319
+ async autoGeneratePositions(requestConfig, getContentBytesLength = fetchContentBytesLength) {
34320
34320
  let startPosition = 0;
34321
34321
  let totalContentLength = 0;
34322
34322
  const positions = [];
@@ -34335,7 +34335,7 @@ var Publication = class extends import_publication.Publication {
34335
34335
  startPosition = startPosition + 1;
34336
34336
  } else {
34337
34337
  let href = this.getAbsoluteHref(link.Href);
34338
- let length = await getContentBytesLength(href, requestInit);
34338
+ let length = await getContentBytesLength(href, requestConfig);
34339
34339
  link.contentLength = length;
34340
34340
  totalContentLength += length;
34341
34341
  let positionLength = 1024;
@@ -34379,17 +34379,17 @@ var Publication = class extends import_publication.Publication {
34379
34379
  }
34380
34380
  this.positions = positions;
34381
34381
  }
34382
- async fetchPositionsFromService(href, requestInit) {
34383
- const result = await fetch(href, requestInit);
34382
+ async fetchPositionsFromService(href, requestConfig) {
34383
+ const result = await fetch(href, requestConfig);
34384
34384
  const content = await result.json();
34385
34385
  this.positions = content.positions;
34386
34386
  }
34387
- async fetchWeightsFromService(href, requestInit) {
34387
+ async fetchWeightsFromService(href, requestConfig) {
34388
34388
  if (this.isFixedLayout) {
34389
34389
  console.warn("Not fetching weights from service for fixed layout publication.");
34390
34390
  return;
34391
34391
  }
34392
- const result = await fetch(href, requestInit);
34392
+ const result = await fetch(href, requestConfig);
34393
34393
  const weights = await result.json();
34394
34394
  if (this.readingOrder !== void 0) {
34395
34395
  this.readingOrder.forEach((link) => {
@@ -34401,8 +34401,8 @@ var Publication = class extends import_publication.Publication {
34401
34401
  Publication = __decorateClass([
34402
34402
  (0, import_ta_json_x2.JsonObject)()
34403
34403
  ], Publication);
34404
- var fetchContentBytesLength = async (href, requestInit) => {
34405
- const r = await fetch(href, requestInit);
34404
+ var fetchContentBytesLength = async (href, requestConfig) => {
34405
+ const r = await fetch(href, requestConfig);
34406
34406
  const b = await r.blob();
34407
34407
  return b.size;
34408
34408
  };
@@ -34635,7 +34635,7 @@ var Popup = class {
34635
34635
  absolute = absolute.substring(0, absolute.indexOf("#"));
34636
34636
  event.preventDefault();
34637
34637
  event.stopPropagation();
34638
- await fetch(absolute, this.navigator.requestInit).then((r) => r.text()).then(async (data) => {
34638
+ await fetch(absolute, this.navigator.requestConfig).then((r) => r.text()).then(async (data) => {
34639
34639
  const parser = new DOMParser();
34640
34640
  const doc = parser.parseFromString(data, "text/html");
34641
34641
  const element = doc.querySelector("#" + id2);
@@ -34685,7 +34685,7 @@ var Popup = class {
34685
34685
  const d2content = document.createElement("div");
34686
34686
  d2content.className = "d2-popover-content";
34687
34687
  d2wrapper.appendChild(d2content);
34688
- await fetch(absolute, this.navigator.requestInit).then((r) => r.text()).then(async (data) => {
34688
+ await fetch(absolute, this.navigator.requestConfig).then((r) => r.text()).then(async (data) => {
34689
34689
  d2content.innerHTML = data;
34690
34690
  let doc = this.navigator.iframes[0].contentDocument;
34691
34691
  if (doc) {
@@ -40975,7 +40975,7 @@ var MediaOverlayModule = class {
40975
40975
  const moUrlFull = moUrlObjFull.toString();
40976
40976
  let response;
40977
40977
  try {
40978
- response = await fetch(moUrlFull, this.delegate.requestInit);
40978
+ response = await fetch(moUrlFull, this.delegate.requestConfig);
40979
40979
  } catch (e) {
40980
40980
  console.error(e, moUrlFull);
40981
40981
  return;
@@ -42297,7 +42297,7 @@ async function searchDocDomSeek(searchInput, doc, href, title, fullWordSearch =
42297
42297
 
42298
42298
  // src/modules/search/SearchModule.ts
42299
42299
  var SearchModule = class {
42300
- constructor(delegate, publication, properties, highlighter, api, headerMenu) {
42300
+ constructor(delegate, publication, properties, highlighter, requestConfig, api, headerMenu) {
42301
42301
  this.currentChapterSearchResult = [];
42302
42302
  this.bookSearchResult = [];
42303
42303
  this.currentSearchHighlights = [];
@@ -42307,9 +42307,10 @@ var SearchModule = class {
42307
42307
  this.properties = properties;
42308
42308
  this.api = api;
42309
42309
  this.highlighter = highlighter;
42310
+ this.requestConfig = requestConfig;
42310
42311
  }
42311
42312
  static async create(config2) {
42312
- const search = new this(config2.delegate, config2.publication, config2, config2.highlighter, config2.api, config2.headerMenu);
42313
+ const search = new this(config2.delegate, config2.publication, config2, config2.highlighter, config2.requestConfig, config2.api, config2.headerMenu);
42313
42314
  await search.start();
42314
42315
  return search;
42315
42316
  }
@@ -42735,9 +42736,9 @@ var SearchModule = class {
42735
42736
  }
42736
42737
  if (tocItem) {
42737
42738
  let href = this.publication.getAbsoluteHref(tocItem.Href);
42738
- await fetch(href, this.delegate.requestInit).then((r) => r.text()).then(async (data) => {
42739
+ await fetch(href, this.requestConfig).then((r) => r.text()).then(async (data) => {
42739
42740
  let parser = new DOMParser();
42740
- let doc = parser.parseFromString(data, "application/xhtml+xml");
42741
+ let doc = parser.parseFromString(this.requestConfig?.encoded ? this.decodeBase64(data) : data, "application/xhtml+xml");
42741
42742
  if (tocItem) {
42742
42743
  searchDocDomSeek(term, doc, tocItem.Href, tocItem.Title).then((result) => {
42743
42744
  result.forEach((searchItem) => {
@@ -42753,6 +42754,16 @@ var SearchModule = class {
42753
42754
  }
42754
42755
  }
42755
42756
  }
42757
+ decodeBase64(base64) {
42758
+ const text = atob(base64);
42759
+ const length = text.length;
42760
+ const bytes = new Uint8Array(length);
42761
+ for (let i = 0; i < length; i++) {
42762
+ bytes[i] = text.charCodeAt(i);
42763
+ }
42764
+ const decoder = new TextDecoder();
42765
+ return decoder.decode(bytes);
42766
+ }
42756
42767
  async searchChapter(term) {
42757
42768
  let localSearchResultBook = [];
42758
42769
  const linkHref = this.publication.getAbsoluteHref(this.publication.readingOrder[this.delegate.currentResource() ?? 0].Href);
@@ -42762,9 +42773,9 @@ var SearchModule = class {
42762
42773
  }
42763
42774
  if (tocItem) {
42764
42775
  let href = this.publication.getAbsoluteHref(tocItem.Href);
42765
- await fetch(href).then((r) => r.text()).then(async (data) => {
42776
+ await fetch(href, this.requestConfig).then((r) => r.text()).then(async (data) => {
42766
42777
  let parser = new DOMParser();
42767
- let doc = parser.parseFromString(data, "application/xhtml+xml");
42778
+ let doc = parser.parseFromString(this.requestConfig?.encoded ? this.decodeBase64(data) : data, "application/xhtml+xml");
42768
42779
  if (tocItem) {
42769
42780
  searchDocDomSeek(term, doc, tocItem.Href, tocItem.Title).then((result) => {
42770
42781
  result.forEach((searchItem) => {
@@ -43429,11 +43440,10 @@ var SampleReadEventHandler = class {
43429
43440
  // src/navigator/IFrameNavigator.ts
43430
43441
  var import_eventemitter3 = __toModule(require_eventemitter3());
43431
43442
  var IFrameNavigator = class extends import_eventemitter3.default {
43432
- constructor(settings, annotator = void 0, upLinkConfig = void 0, initialLastReadingPosition = void 0, publication, material, api, rights, tts, injectables, attributes, services, sample, requestInit) {
43443
+ constructor(settings, annotator = void 0, upLinkConfig = void 0, initialLastReadingPosition = void 0, publication, api, rights, tts, injectables, attributes, services, sample, requestConfig) {
43433
43444
  super();
43434
43445
  this.iframes = [];
43435
43446
  this.sideNavExpanded = false;
43436
- this.material = false;
43437
43447
  this.currentChapterLink = { href: "" };
43438
43448
  this.currentSpreadLinks = {};
43439
43449
  this.upLink = void 0;
@@ -43504,7 +43514,6 @@ var IFrameNavigator = class extends import_eventemitter3.default {
43504
43514
  this.upLinkConfig = upLinkConfig;
43505
43515
  this.initialLastReadingPosition = initialLastReadingPosition;
43506
43516
  this.publication = publication;
43507
- this.material = material;
43508
43517
  this.api = api;
43509
43518
  this.rights = rights ?? {
43510
43519
  autoGeneratePositions: false,
@@ -43527,11 +43536,11 @@ var IFrameNavigator = class extends import_eventemitter3.default {
43527
43536
  this.attributes = attributes || { margin: 0 };
43528
43537
  this.services = services;
43529
43538
  this.sample = sample;
43530
- this.requestInit = requestInit;
43539
+ this.requestConfig = requestConfig;
43531
43540
  this.sampleReadEventHandler = new SampleReadEventHandler(this);
43532
43541
  }
43533
43542
  static async create(config2) {
43534
- const navigator2 = new this(config2.settings, config2.annotator || void 0, config2.upLink || void 0, config2.initialLastReadingPosition || void 0, config2.publication, config2.material, config2.api, config2.rights, config2.tts, config2.injectables, config2.attributes || { margin: 0 }, config2.services, config2.sample);
43543
+ const navigator2 = new this(config2.settings, config2.annotator || void 0, config2.upLink || void 0, config2.initialLastReadingPosition || void 0, config2.publication, config2.api, config2.rights, config2.tts, config2.injectables, config2.attributes || { margin: 0 }, config2.services, config2.sample);
43535
43544
  await navigator2.start(config2.mainElement, config2.headerMenu, config2.footerMenu);
43536
43545
  return new Promise((resolve) => resolve(navigator2));
43537
43546
  }
@@ -44384,7 +44393,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44384
44393
  if (isSameOrigin) {
44385
44394
  this.iframes[0].src = this.currentChapterLink.href;
44386
44395
  } else {
44387
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44396
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44388
44397
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44389
44398
  });
44390
44399
  }
@@ -44405,7 +44414,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44405
44414
  if (isSameOrigin) {
44406
44415
  this.iframes[1].src = href;
44407
44416
  } else {
44408
- fetch(href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44417
+ fetch(href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44409
44418
  writeIframe2Doc.call(this, content2, href);
44410
44419
  this.currentSpreadLinks.right = {
44411
44420
  href
@@ -44434,7 +44443,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44434
44443
  if (isSameOrigin) {
44435
44444
  this.iframes[0].src = href;
44436
44445
  } else {
44437
- fetch(href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44446
+ fetch(href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44438
44447
  writeIframeDoc.call(this, content2, href);
44439
44448
  });
44440
44449
  }
@@ -44455,7 +44464,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44455
44464
  if (isSameOrigin) {
44456
44465
  this.iframes[1].src = this.currentChapterLink.href;
44457
44466
  } else {
44458
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44467
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44459
44468
  writeIframe2Doc.call(this, content2, this.currentChapterLink.href);
44460
44469
  });
44461
44470
  }
@@ -44474,7 +44483,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44474
44483
  if (isSameOrigin) {
44475
44484
  this.iframes[0].src = this.currentChapterLink.href;
44476
44485
  } else {
44477
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44486
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44478
44487
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44479
44488
  });
44480
44489
  }
@@ -44492,7 +44501,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44492
44501
  if (isSameOrigin) {
44493
44502
  this.iframes[0].src = this.currentChapterLink.href;
44494
44503
  } else {
44495
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44504
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44496
44505
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44497
44506
  });
44498
44507
  }
@@ -44525,7 +44534,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44525
44534
  }
44526
44535
  }
44527
44536
  } else {
44528
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44537
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44529
44538
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44530
44539
  });
44531
44540
  if (this.iframes.length === 2) {
@@ -44536,7 +44545,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44536
44545
  this.currentSpreadLinks.right = {
44537
44546
  href
44538
44547
  };
44539
- fetch(href, this.requestInit).then((r) => r.text()).then(async (content) => {
44548
+ fetch(href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44540
44549
  writeIframe2Doc.call(this, content, href);
44541
44550
  });
44542
44551
  }
@@ -44559,14 +44568,14 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44559
44568
  this.iframes[1].src = this.currentChapterLink.href;
44560
44569
  }
44561
44570
  } else {
44562
- fetch(href, this.requestInit).then((r) => r.text()).then(async (content) => {
44571
+ fetch(href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44563
44572
  writeIframeDoc.call(this, content, href);
44564
44573
  });
44565
44574
  if (this.iframes.length === 2) {
44566
44575
  this.currentSpreadLinks.right = {
44567
44576
  href: this.currentChapterLink.href
44568
44577
  };
44569
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44578
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44570
44579
  writeIframe2Doc.call(this, content, this.currentChapterLink.href);
44571
44580
  });
44572
44581
  }
@@ -44582,7 +44591,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44582
44591
  if (isSameOrigin) {
44583
44592
  this.iframes[1].src = this.currentChapterLink.href;
44584
44593
  } else {
44585
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44594
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44586
44595
  writeIframe2Doc.call(this, content, this.currentChapterLink.href);
44587
44596
  });
44588
44597
  }
@@ -44595,7 +44604,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44595
44604
  if (isSameOrigin) {
44596
44605
  this.iframes[0].src = this.currentChapterLink.href;
44597
44606
  } else {
44598
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44607
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44599
44608
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44600
44609
  });
44601
44610
  }
@@ -44607,7 +44616,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44607
44616
  if (isSameOrigin) {
44608
44617
  this.iframes[0].src = this.currentChapterLink.href;
44609
44618
  } else {
44610
- fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44619
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44611
44620
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44612
44621
  });
44613
44622
  }
@@ -48322,7 +48331,7 @@ var D2Reader = class {
48322
48331
  publication = TaJsonDeserialize(initialConfig.publication, Publication);
48323
48332
  publication.manifestUrl = new URL(webPubManifestUrl);
48324
48333
  } else {
48325
- publication = await Publication.fromUrl(webPubManifestUrl, initialConfig.requestInit);
48334
+ publication = await Publication.fromUrl(webPubManifestUrl, initialConfig.requestConfig);
48326
48335
  }
48327
48336
  const store = new LocalStorageStore({
48328
48337
  prefix: publication.manifestUrl,
@@ -48341,13 +48350,13 @@ var D2Reader = class {
48341
48350
  publication.sample = initialConfig.sample;
48342
48351
  rights = updateConfig(rights, publication);
48343
48352
  if (rights.autoGeneratePositions) {
48344
- await publication.autoGeneratePositions(initialConfig.requestInit);
48353
+ await publication.autoGeneratePositions(initialConfig.requestConfig);
48345
48354
  } else {
48346
48355
  if (initialConfig.services?.positions) {
48347
- await publication.fetchPositionsFromService(initialConfig.services?.positions.href, initialConfig.requestInit);
48356
+ await publication.fetchPositionsFromService(initialConfig.services?.positions.href, initialConfig.requestConfig);
48348
48357
  }
48349
48358
  if (initialConfig.services?.weight) {
48350
- await publication.fetchWeightsFromService(initialConfig.services?.weight.href, initialConfig.requestInit);
48359
+ await publication.fetchWeightsFromService(initialConfig.services?.weight.href, initialConfig.requestConfig);
48351
48360
  }
48352
48361
  }
48353
48362
  const layers = await LayerSettings.create({ store: layerStore });
@@ -48355,7 +48364,6 @@ var D2Reader = class {
48355
48364
  store: settingsStore,
48356
48365
  initialUserSettings: initialConfig.userSettings,
48357
48366
  headerMenu,
48358
- material: initialConfig.material,
48359
48367
  api: initialConfig.api,
48360
48368
  injectables: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? initialConfig.injectablesFixed : initialConfig.injectables,
48361
48369
  layout: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? "fixed" : "reflowable"
@@ -48369,13 +48377,12 @@ var D2Reader = class {
48369
48377
  annotator,
48370
48378
  upLink,
48371
48379
  initialLastReadingPosition: initialConfig.lastReadingPosition,
48372
- material: initialConfig.material,
48373
48380
  api: initialConfig.api,
48374
48381
  rights,
48375
48382
  tts: initialConfig.tts,
48376
48383
  sample: initialConfig.sample,
48377
- requestInit: initialConfig.requestInit,
48378
- injectables: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? initialConfig.injectablesFixed : initialConfig.injectables,
48384
+ requestConfig: initialConfig.requestConfig,
48385
+ injectables: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? initialConfig.injectablesFixed ?? [] : initialConfig.injectables,
48379
48386
  attributes: initialConfig.attributes,
48380
48387
  services: initialConfig.services
48381
48388
  });
@@ -48420,7 +48427,8 @@ var D2Reader = class {
48420
48427
  headerMenu,
48421
48428
  delegate: navigator2,
48422
48429
  publication,
48423
- highlighter
48430
+ highlighter,
48431
+ requestConfig: initialConfig.requestConfig
48424
48432
  }, initialConfig.search)) : void 0;
48425
48433
  const definitionsModule = rights.enableDefinitions ? await DefinitionsModule.create(__spreadValues({
48426
48434
  delegate: navigator2,