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

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
@@ -34139,10 +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) {
34143
- const response = await fetch(url.href, {
34144
- credentials: "same-origin"
34145
- });
34142
+ static async fromUrl(url, requestInit) {
34143
+ const response = await fetch(url.href, requestInit);
34146
34144
  const manifestJSON = await response.json();
34147
34145
  let publication = TaJsonDeserialize(manifestJSON, Publication);
34148
34146
  publication.manifestUrl = url;
@@ -34318,7 +34316,7 @@ var Publication = class extends import_publication.Publication {
34318
34316
  const decodedHref = decodeURI(href) ?? "";
34319
34317
  return this.positions?.filter((p) => decodedHref.includes(p.href));
34320
34318
  }
34321
- async autoGeneratePositions(getContentBytesLength = fetchContentBytesLength) {
34319
+ async autoGeneratePositions(requestInit, getContentBytesLength = fetchContentBytesLength) {
34322
34320
  let startPosition = 0;
34323
34321
  let totalContentLength = 0;
34324
34322
  const positions = [];
@@ -34337,7 +34335,7 @@ var Publication = class extends import_publication.Publication {
34337
34335
  startPosition = startPosition + 1;
34338
34336
  } else {
34339
34337
  let href = this.getAbsoluteHref(link.Href);
34340
- let length = await getContentBytesLength(href);
34338
+ let length = await getContentBytesLength(href, requestInit);
34341
34339
  link.contentLength = length;
34342
34340
  totalContentLength += length;
34343
34341
  let positionLength = 1024;
@@ -34381,17 +34379,17 @@ var Publication = class extends import_publication.Publication {
34381
34379
  }
34382
34380
  this.positions = positions;
34383
34381
  }
34384
- async fetchPositionsFromService(href) {
34385
- const result = await fetch(href);
34382
+ async fetchPositionsFromService(href, requestInit) {
34383
+ const result = await fetch(href, requestInit);
34386
34384
  const content = await result.json();
34387
34385
  this.positions = content.positions;
34388
34386
  }
34389
- async fetchWeightsFromService(href) {
34387
+ async fetchWeightsFromService(href, requestInit) {
34390
34388
  if (this.isFixedLayout) {
34391
34389
  console.warn("Not fetching weights from service for fixed layout publication.");
34392
34390
  return;
34393
34391
  }
34394
- const result = await fetch(href);
34392
+ const result = await fetch(href, requestInit);
34395
34393
  const weights = await result.json();
34396
34394
  if (this.readingOrder !== void 0) {
34397
34395
  this.readingOrder.forEach((link) => {
@@ -34403,8 +34401,8 @@ var Publication = class extends import_publication.Publication {
34403
34401
  Publication = __decorateClass([
34404
34402
  (0, import_ta_json_x2.JsonObject)()
34405
34403
  ], Publication);
34406
- var fetchContentBytesLength = async (href) => {
34407
- const r = await fetch(href);
34404
+ var fetchContentBytesLength = async (href, requestInit) => {
34405
+ const r = await fetch(href, requestInit);
34408
34406
  const b = await r.blob();
34409
34407
  return b.size;
34410
34408
  };
@@ -34637,7 +34635,7 @@ var Popup = class {
34637
34635
  absolute = absolute.substring(0, absolute.indexOf("#"));
34638
34636
  event.preventDefault();
34639
34637
  event.stopPropagation();
34640
- await fetch(absolute).then((r) => r.text()).then(async (data) => {
34638
+ await fetch(absolute, this.navigator.requestInit).then((r) => r.text()).then(async (data) => {
34641
34639
  const parser = new DOMParser();
34642
34640
  const doc = parser.parseFromString(data, "text/html");
34643
34641
  const element = doc.querySelector("#" + id2);
@@ -34687,7 +34685,7 @@ var Popup = class {
34687
34685
  const d2content = document.createElement("div");
34688
34686
  d2content.className = "d2-popover-content";
34689
34687
  d2wrapper.appendChild(d2content);
34690
- await fetch(absolute).then((r) => r.text()).then(async (data) => {
34688
+ await fetch(absolute, this.navigator.requestInit).then((r) => r.text()).then(async (data) => {
34691
34689
  d2content.innerHTML = data;
34692
34690
  let doc = this.navigator.iframes[0].contentDocument;
34693
34691
  if (doc) {
@@ -40977,7 +40975,7 @@ var MediaOverlayModule = class {
40977
40975
  const moUrlFull = moUrlObjFull.toString();
40978
40976
  let response;
40979
40977
  try {
40980
- response = await fetch(moUrlFull);
40978
+ response = await fetch(moUrlFull, this.delegate.requestInit);
40981
40979
  } catch (e) {
40982
40980
  console.error(e, moUrlFull);
40983
40981
  return;
@@ -42737,7 +42735,7 @@ var SearchModule = class {
42737
42735
  }
42738
42736
  if (tocItem) {
42739
42737
  let href = this.publication.getAbsoluteHref(tocItem.Href);
42740
- await fetch(href).then((r) => r.text()).then(async (data) => {
42738
+ await fetch(href, this.delegate.requestInit).then((r) => r.text()).then(async (data) => {
42741
42739
  let parser = new DOMParser();
42742
42740
  let doc = parser.parseFromString(data, "application/xhtml+xml");
42743
42741
  if (tocItem) {
@@ -43431,7 +43429,7 @@ var SampleReadEventHandler = class {
43431
43429
  // src/navigator/IFrameNavigator.ts
43432
43430
  var import_eventemitter3 = __toModule(require_eventemitter3());
43433
43431
  var IFrameNavigator = class extends import_eventemitter3.default {
43434
- constructor(settings, annotator = void 0, upLinkConfig = void 0, initialLastReadingPosition = void 0, publication, material, api, rights, tts, injectables, attributes, services, sample) {
43432
+ constructor(settings, annotator = void 0, upLinkConfig = void 0, initialLastReadingPosition = void 0, publication, material, api, rights, tts, injectables, attributes, services, sample, requestInit) {
43435
43433
  super();
43436
43434
  this.iframes = [];
43437
43435
  this.sideNavExpanded = false;
@@ -43529,6 +43527,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
43529
43527
  this.attributes = attributes || { margin: 0 };
43530
43528
  this.services = services;
43531
43529
  this.sample = sample;
43530
+ this.requestInit = requestInit;
43532
43531
  this.sampleReadEventHandler = new SampleReadEventHandler(this);
43533
43532
  }
43534
43533
  static async create(config2) {
@@ -44385,7 +44384,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44385
44384
  if (isSameOrigin) {
44386
44385
  this.iframes[0].src = this.currentChapterLink.href;
44387
44386
  } else {
44388
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content2) => {
44387
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44389
44388
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44390
44389
  });
44391
44390
  }
@@ -44406,7 +44405,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44406
44405
  if (isSameOrigin) {
44407
44406
  this.iframes[1].src = href;
44408
44407
  } else {
44409
- fetch(href).then((r) => r.text()).then(async (content2) => {
44408
+ fetch(href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44410
44409
  writeIframe2Doc.call(this, content2, href);
44411
44410
  this.currentSpreadLinks.right = {
44412
44411
  href
@@ -44435,7 +44434,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44435
44434
  if (isSameOrigin) {
44436
44435
  this.iframes[0].src = href;
44437
44436
  } else {
44438
- fetch(href).then((r) => r.text()).then(async (content2) => {
44437
+ fetch(href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44439
44438
  writeIframeDoc.call(this, content2, href);
44440
44439
  });
44441
44440
  }
@@ -44456,7 +44455,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44456
44455
  if (isSameOrigin) {
44457
44456
  this.iframes[1].src = this.currentChapterLink.href;
44458
44457
  } else {
44459
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content2) => {
44458
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44460
44459
  writeIframe2Doc.call(this, content2, this.currentChapterLink.href);
44461
44460
  });
44462
44461
  }
@@ -44475,7 +44474,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44475
44474
  if (isSameOrigin) {
44476
44475
  this.iframes[0].src = this.currentChapterLink.href;
44477
44476
  } else {
44478
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content2) => {
44477
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44479
44478
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44480
44479
  });
44481
44480
  }
@@ -44493,7 +44492,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44493
44492
  if (isSameOrigin) {
44494
44493
  this.iframes[0].src = this.currentChapterLink.href;
44495
44494
  } else {
44496
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content2) => {
44495
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content2) => {
44497
44496
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44498
44497
  });
44499
44498
  }
@@ -44526,7 +44525,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44526
44525
  }
44527
44526
  }
44528
44527
  } else {
44529
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44528
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44530
44529
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44531
44530
  });
44532
44531
  if (this.iframes.length === 2) {
@@ -44537,7 +44536,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44537
44536
  this.currentSpreadLinks.right = {
44538
44537
  href
44539
44538
  };
44540
- fetch(href).then((r) => r.text()).then(async (content) => {
44539
+ fetch(href, this.requestInit).then((r) => r.text()).then(async (content) => {
44541
44540
  writeIframe2Doc.call(this, content, href);
44542
44541
  });
44543
44542
  }
@@ -44560,14 +44559,14 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44560
44559
  this.iframes[1].src = this.currentChapterLink.href;
44561
44560
  }
44562
44561
  } else {
44563
- fetch(href).then((r) => r.text()).then(async (content) => {
44562
+ fetch(href, this.requestInit).then((r) => r.text()).then(async (content) => {
44564
44563
  writeIframeDoc.call(this, content, href);
44565
44564
  });
44566
44565
  if (this.iframes.length === 2) {
44567
44566
  this.currentSpreadLinks.right = {
44568
44567
  href: this.currentChapterLink.href
44569
44568
  };
44570
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44569
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44571
44570
  writeIframe2Doc.call(this, content, this.currentChapterLink.href);
44572
44571
  });
44573
44572
  }
@@ -44583,7 +44582,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44583
44582
  if (isSameOrigin) {
44584
44583
  this.iframes[1].src = this.currentChapterLink.href;
44585
44584
  } else {
44586
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44585
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44587
44586
  writeIframe2Doc.call(this, content, this.currentChapterLink.href);
44588
44587
  });
44589
44588
  }
@@ -44596,7 +44595,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44596
44595
  if (isSameOrigin) {
44597
44596
  this.iframes[0].src = this.currentChapterLink.href;
44598
44597
  } else {
44599
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44598
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44600
44599
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44601
44600
  });
44602
44601
  }
@@ -44608,7 +44607,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44608
44607
  if (isSameOrigin) {
44609
44608
  this.iframes[0].src = this.currentChapterLink.href;
44610
44609
  } else {
44611
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44610
+ fetch(this.currentChapterLink.href, this.requestInit).then((r) => r.text()).then(async (content) => {
44612
44611
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44613
44612
  });
44614
44613
  }
@@ -48317,9 +48316,16 @@ var D2Reader = class {
48317
48316
  const mainElement = findRequiredElement(document, "#D2Reader-Container");
48318
48317
  const headerMenu = findElement(document, "#headerMenu");
48319
48318
  const footerMenu = findElement(document, "#footerMenu");
48320
- const webPubManifestUrl = initialConfig.url;
48319
+ let webPubManifestUrl = initialConfig.url;
48320
+ let publication;
48321
+ if (initialConfig.publication) {
48322
+ publication = TaJsonDeserialize(initialConfig.publication, Publication);
48323
+ publication.manifestUrl = new URL(webPubManifestUrl);
48324
+ } else {
48325
+ publication = await Publication.fromUrl(webPubManifestUrl, initialConfig.requestInit);
48326
+ }
48321
48327
  const store = new LocalStorageStore({
48322
- prefix: webPubManifestUrl.href,
48328
+ prefix: publication.manifestUrl,
48323
48329
  useLocalStorage: initialConfig.useLocalStorage ?? false
48324
48330
  });
48325
48331
  const settingsStore = new LocalStorageStore({
@@ -48332,17 +48338,16 @@ var D2Reader = class {
48332
48338
  });
48333
48339
  const annotator = new LocalAnnotator({ store });
48334
48340
  const upLink = initialConfig.upLinkUrl ?? void 0;
48335
- const publication = await Publication.fromUrl(webPubManifestUrl);
48336
48341
  publication.sample = initialConfig.sample;
48337
48342
  rights = updateConfig(rights, publication);
48338
48343
  if (rights.autoGeneratePositions) {
48339
- await publication.autoGeneratePositions();
48344
+ await publication.autoGeneratePositions(initialConfig.requestInit);
48340
48345
  } else {
48341
48346
  if (initialConfig.services?.positions) {
48342
- await publication.fetchPositionsFromService(initialConfig.services?.positions.href);
48347
+ await publication.fetchPositionsFromService(initialConfig.services?.positions.href, initialConfig.requestInit);
48343
48348
  }
48344
48349
  if (initialConfig.services?.weight) {
48345
- await publication.fetchWeightsFromService(initialConfig.services?.weight.href);
48350
+ await publication.fetchWeightsFromService(initialConfig.services?.weight.href, initialConfig.requestInit);
48346
48351
  }
48347
48352
  }
48348
48353
  const layers = await LayerSettings.create({ store: layerStore });
@@ -48369,6 +48374,7 @@ var D2Reader = class {
48369
48374
  rights,
48370
48375
  tts: initialConfig.tts,
48371
48376
  sample: initialConfig.sample,
48377
+ requestInit: initialConfig.requestInit,
48372
48378
  injectables: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? initialConfig.injectablesFixed : initialConfig.injectables,
48373
48379
  attributes: initialConfig.attributes,
48374
48380
  services: initialConfig.services