@prose-reader/streamer 1.275.0 → 1.276.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.
package/dist/index.js CHANGED
@@ -371,7 +371,45 @@ const w = {
371
371
  } catch (s) {
372
372
  throw w.error(s), s;
373
373
  }
374
- }, De = ({ archive: e, baseUrl: t }) => async () => {
374
+ }, De = ({ archive: e }) => async (t) => {
375
+ const i = e.records.find(
376
+ (n) => n.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
377
+ );
378
+ if (!i || i.dir)
379
+ return t;
380
+ const r = await (await i.blob()).text();
381
+ try {
382
+ const o = new b(r).childNamed("platform")?.childrenNamed("option")?.find((a) => a.attr.name === "fixed-layout")?.val || "false";
383
+ return {
384
+ ...t,
385
+ renditionLayout: o === "true" ? "pre-paginated" : t.renditionLayout
386
+ };
387
+ } catch (n) {
388
+ return console.error(
389
+ `Unable to parse com.apple.ibooks.display-options.xml for content
390
+ `,
391
+ r
392
+ ), console.error(n), t;
393
+ }
394
+ }, Me = async (e) => {
395
+ const t = {
396
+ renditionLayout: void 0
397
+ };
398
+ return await Promise.all(
399
+ e.records.map(async (i) => {
400
+ if (i.uri.endsWith("com.kobobooks.display-options.xml") && !i.dir) {
401
+ const n = new b(await i.string()).childNamed("platform")?.childNamed("option");
402
+ n?.attr?.name === "fixed-layout" && n.val === "true" && (t.renditionLayout = "pre-paginated");
403
+ }
404
+ })
405
+ ), t;
406
+ }, Ue = ({ archive: e }) => async (t) => {
407
+ const i = await Me(e);
408
+ return {
409
+ ...t,
410
+ renditionLayout: t.renditionLayout ?? i.renditionLayout
411
+ };
412
+ }, ze = ({ archive: e, baseUrl: t }) => async () => {
375
413
  const i = Object.values(e.records).filter((r) => !r.dir);
376
414
  return {
377
415
  filename: e.filename,
@@ -400,39 +438,21 @@ const w = {
400
438
  href: encodeURI(`${t}${r.uri}`)
401
439
  }))
402
440
  };
403
- }, Me = async (e) => {
404
- const t = {
405
- renditionLayout: void 0
406
- };
407
- return await Promise.all(
408
- e.records.map(async (i) => {
409
- if (i.uri.endsWith("com.kobobooks.display-options.xml") && !i.dir) {
410
- const n = new b(await i.string()).childNamed("platform")?.childNamed("option");
411
- n?.attr?.name === "fixed-layout" && n.val === "true" && (t.renditionLayout = "pre-paginated");
412
- }
413
- })
414
- ), t;
415
- }, Ue = ({ archive: e }) => async (t) => {
416
- const i = await Me(e);
417
- return {
418
- ...t,
419
- renditionLayout: t.renditionLayout ?? i.renditionLayout
420
- };
421
- }, ze = (e) => {
441
+ }, Be = (e) => {
422
442
  const t = e.descendantWithPath("head")?.childrenNamed("meta").find((i) => i.attr.name === "viewport");
423
443
  return !!(t && t.attr.name === "viewport");
424
- }, Be = (e) => e.reduce(async (t, i) => {
444
+ }, Xe = (e) => e.reduce(async (t, i) => {
425
445
  if (!await t || !de({
426
446
  mimeType: i.encodingFormat,
427
447
  uri: i.uri
428
448
  }))
429
449
  return !1;
430
450
  const n = i.dir ? null : await i.string();
431
- return n ? ze(new b(n)) : !1;
432
- }, Promise.resolve(!0)), Xe = ({ archive: e }) => async (t) => {
451
+ return n ? Be(new b(n)) : !1;
452
+ }, Promise.resolve(!0)), He = ({ archive: e }) => async (t) => {
433
453
  if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
434
454
  const r = await Q({ archive: e });
435
- if (await Be(r))
455
+ if (await Xe(r))
436
456
  return {
437
457
  ...t,
438
458
  spineItems: t.spineItems.map((s) => ({
@@ -443,13 +463,36 @@ const w = {
443
463
  };
444
464
  }
445
465
  return t;
466
+ }, Ve = ({ archive: e }) => async (t) => {
467
+ const i = e.records.find(
468
+ (s) => s.basename.toLowerCase() === "comicinfo.xml" && !s.dir
469
+ );
470
+ if (!i || i.dir)
471
+ return t;
472
+ const r = {
473
+ ...t,
474
+ spineItems: t.spineItems.filter((s) => !s.id.toLowerCase().endsWith("comicinfo.xml")).map((s, o, a) => ({
475
+ ...s,
476
+ progressionWeight: 1 / a.length
477
+ }))
478
+ }, n = await i.string();
479
+ try {
480
+ const o = new b(n).childNamed("Manga")?.val || "unknown";
481
+ return {
482
+ ...r,
483
+ readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
484
+ };
485
+ } catch (s) {
486
+ return console.error(`Unable to parse comicinfo.xml for content
487
+ `, n), console.error(s), r;
488
+ }
446
489
  }, M = (e, t) => {
447
490
  const i = e.split(/(\d+)/), r = t.split(/(\d+)/);
448
491
  for (let n = 0, s = i.length; n < s; n++)
449
492
  if (i[n] !== r[n])
450
493
  return i[n]?.match(/\d/) ? +(i[n] || "") - +(r[n] || "") : (i[n] || "").localeCompare(r[n] || "");
451
494
  return 1;
452
- }, He = ({ archive: e, baseUrl: t }) => async (i) => {
495
+ }, _e = ({ archive: e, baseUrl: t }) => async (i) => {
453
496
  if (i.nav) return i;
454
497
  const r = [...e.records].sort(
455
498
  (a, d) => M(a.uri, d.uri)
@@ -518,30 +561,7 @@ const w = {
518
561
  toc: o
519
562
  }
520
563
  };
521
- }, Ve = ({ archive: e }) => async (t) => {
522
- const i = e.records.find(
523
- (s) => s.basename.toLowerCase() === "comicinfo.xml" && !s.dir
524
- );
525
- if (!i || i.dir)
526
- return t;
527
- const r = {
528
- ...t,
529
- spineItems: t.spineItems.filter((s) => !s.id.toLowerCase().endsWith("comicinfo.xml")).map((s, o, a) => ({
530
- ...s,
531
- progressionWeight: 1 / a.length
532
- }))
533
- }, n = await i.string();
534
- try {
535
- const o = new b(n).childNamed("Manga")?.val || "unknown";
536
- return {
537
- ...r,
538
- readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
539
- };
540
- } catch (s) {
541
- return console.error(`Unable to parse comicinfo.xml for content
542
- `, n), console.error(s), r;
543
- }
544
- }, _e = (e) => e.records.some((t) => t.basename.endsWith(".opf")), qe = ({ archive: e }) => async (t) => _e(e) ? t : {
564
+ }, qe = (e) => e.records.some((t) => t.basename.endsWith(".opf")), Ge = ({ archive: e }) => async (t) => qe(e) ? t : {
545
565
  ...t,
546
566
  spineItems: t.spineItems.map((r) => {
547
567
  const n = e.records.find(
@@ -552,38 +572,18 @@ const w = {
552
572
  renditionLayout: s?.startsWith("image/") ? "pre-paginated" : r.renditionLayout
553
573
  };
554
574
  })
555
- }, Ge = ({ archive: e }) => async (t) => {
556
- const i = e.records.find(
557
- (n) => n.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
558
- );
559
- if (!i || i.dir)
560
- return t;
561
- const r = await (await i.blob()).text();
562
- try {
563
- const o = new b(r).childNamed("platform")?.childrenNamed("option")?.find((a) => a.attr.name === "fixed-layout")?.val || "false";
564
- return {
565
- ...t,
566
- renditionLayout: o === "true" ? "pre-paginated" : t.renditionLayout
567
- };
568
- } catch (n) {
569
- return console.error(
570
- `Unable to parse com.apple.ibooks.display-options.xml for content
571
- `,
572
- r
573
- ), console.error(n), t;
574
- }
575
575
  }, Ke = async (e, { baseUrl: t = "" } = {}) => {
576
576
  const i = [
577
577
  ke({ archive: e, baseUrl: t }),
578
578
  Ve({ archive: e }),
579
+ De({ archive: e }),
579
580
  Ge({ archive: e }),
580
- qe({ archive: e }),
581
- Xe({ archive: e }),
581
+ He({ archive: e }),
582
582
  Ue({ archive: e }),
583
- He({ archive: e, baseUrl: t })
583
+ _e({ archive: e, baseUrl: t })
584
584
  ];
585
585
  try {
586
- const r = De({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
586
+ const r = ze({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
587
587
  return w.log("Generated manifest", n), n;
588
588
  } catch (r) {
589
589
  throw w.error(r), r;