@prose-reader/core 1.162.0 → 1.164.0

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.
@@ -2,7 +2,7 @@ import { Observable } from 'rxjs';
2
2
  import { ReaderSettingsManager } from '../../../settings/ReaderSettingsManager';
3
3
  import { Manifest } from '@prose-reader/shared';
4
4
  import { Context } from '../../../context/Context';
5
- export declare const loadMedias: ({ settings, item, context, }: {
5
+ export declare const loadAssets: ({ settings, item, context, }: {
6
6
  settings: ReaderSettingsManager;
7
7
  item: Manifest["items"][number];
8
8
  context: Context;
package/dist/index.js CHANGED
@@ -5567,7 +5567,7 @@ class DocumentRenderer extends DestroyableClass {
5567
5567
  if (this.renditionLayout === `pre-paginated`) {
5568
5568
  this.lastLayoutDims = {
5569
5569
  height: this.context.getPageSize().height,
5570
- width: this.context.getPageSize().width
5570
+ width: params.minimumWidth
5571
5571
  };
5572
5572
  } else {
5573
5573
  this.lastLayoutDims = {
@@ -6804,9 +6804,8 @@ const createReader = (inputSettings) => {
6804
6804
  const margin = 0;
6805
6805
  const marginTop = 0;
6806
6806
  const marginBottom = 0;
6807
- const isReflow = true;
6808
6807
  const containerElementWidth = dimensions.width;
6809
- const containerElementEvenWidth = containerElementWidth % 2 === 0 || isReflow ? containerElementWidth : containerElementWidth - 1;
6808
+ const containerElementEvenWidth = containerElementWidth;
6810
6809
  element.style.setProperty(`overflow`, `hidden`);
6811
6810
  element.style.height = `${dimensions.height - marginTop - marginBottom}px`;
6812
6811
  element.style.width = `${containerElementEvenWidth - 2 * margin}px`;
@@ -8358,21 +8357,46 @@ const renderReflowable = ({
8358
8357
  latestContentHeightWhenLoaded: newLatestContentHeightWhenLoaded
8359
8358
  };
8360
8359
  };
8361
- const loadMedias = ({
8360
+ const joinPath = (base, path) => {
8361
+ const isFileProtocol = base.startsWith("file://");
8362
+ const tempBase = isFileProtocol ? base.replace("file://", "http://") : base;
8363
+ const result = new URL(path, tempBase).toString();
8364
+ return isFileProtocol ? result.replace("http://", "file://") : result;
8365
+ };
8366
+ const getElementsWithAssets = (document2) => {
8367
+ const RESOURCE_ELEMENTS = [
8368
+ "img",
8369
+ // Images
8370
+ "video",
8371
+ // Video files
8372
+ "audio",
8373
+ // Audio files
8374
+ "source",
8375
+ // Source elements within video/audio
8376
+ "link",
8377
+ // Stylesheets and other linked resources
8378
+ "script"
8379
+ // JavaScript files
8380
+ ].join(",");
8381
+ return Array.from((document2 == null ? void 0 : document2.querySelectorAll(RESOURCE_ELEMENTS)) || []);
8382
+ };
8383
+ const loadAssets = ({
8362
8384
  settings,
8363
8385
  item,
8364
8386
  context
8365
8387
  }) => (stream) => stream.pipe(
8366
8388
  switchMap$1((frameElement) => {
8367
- var _a;
8368
- const images = ((_a = frameElement.contentDocument) == null ? void 0 : _a.getElementsByTagName("img")) || [];
8369
- const imageObservables = Array.from(images).map((img) => {
8370
- var _a2;
8371
- const originalSrc = img.getAttribute("src");
8389
+ const elementsWithAsset = getElementsWithAssets(
8390
+ frameElement.contentDocument
8391
+ );
8392
+ const assetsLoad$ = Array.from(elementsWithAsset).map((element) => {
8393
+ var _a;
8394
+ const originalSrc = element.getAttribute("src") || element.getAttribute("href");
8395
+ if (!originalSrc) return of(null);
8372
8396
  const spineItemUriParentPath = getParentPath(item.href);
8373
- const foundItem = (_a2 = context.manifest) == null ? void 0 : _a2.items.find(({ href }) => {
8374
- return `${spineItemUriParentPath}/${originalSrc}`.endsWith(
8375
- `${href}`
8397
+ const foundItem = (_a = context.manifest) == null ? void 0 : _a.items.find(({ href }) => {
8398
+ return `${joinPath(spineItemUriParentPath, originalSrc).toLowerCase()}`.endsWith(
8399
+ `${href.toLowerCase()}`
8376
8400
  );
8377
8401
  });
8378
8402
  if (!foundItem) return of(null);
@@ -8384,22 +8408,24 @@ const loadMedias = ({
8384
8408
  tap$1((blob) => {
8385
8409
  if (blob) {
8386
8410
  const blobUrl = URL.createObjectURL(blob);
8387
- img.src = blobUrl;
8411
+ if (element.hasAttribute("src")) {
8412
+ element.setAttribute("src", blobUrl);
8413
+ } else if (element.hasAttribute("href")) {
8414
+ element.setAttribute("href", blobUrl);
8415
+ }
8388
8416
  }
8389
8417
  })
8390
8418
  );
8391
8419
  });
8392
- return combineLatest(imageObservables).pipe(map$1(() => frameElement));
8420
+ return combineLatest(assetsLoad$).pipe(map$1(() => frameElement));
8393
8421
  })
8394
8422
  );
8395
8423
  const unloadMedias = (frameElement) => {
8396
- var _a;
8397
- const images = Array.from(
8398
- ((_a = frameElement == null ? void 0 : frameElement.contentDocument) == null ? void 0 : _a.getElementsByTagName("img")) || []
8399
- );
8400
- images.forEach((img) => {
8401
- if (img.src.startsWith("blob:")) {
8402
- URL.revokeObjectURL(img.src);
8424
+ const elementsWithAsset = getElementsWithAssets(frameElement == null ? void 0 : frameElement.contentDocument);
8425
+ elementsWithAsset.forEach((element) => {
8426
+ const url = element.getAttribute("src") || element.getAttribute("href");
8427
+ if (url == null ? void 0 : url.startsWith("blob:")) {
8428
+ URL.revokeObjectURL(url);
8403
8429
  }
8404
8430
  });
8405
8431
  };
@@ -8434,7 +8460,7 @@ class HtmlRenderer extends DocumentRenderer {
8434
8460
  this.containerElement.appendChild(frameElement2);
8435
8461
  }),
8436
8462
  waitForFrameLoad,
8437
- loadMedias({
8463
+ loadAssets({
8438
8464
  context: this.context,
8439
8465
  item: this.item,
8440
8466
  settings: this.settings