@storyteller-platform/epub 0.6.2 → 0.7.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/README.md +919 -224
- package/dist/adapters/tmpfs.cjs +2 -1
- package/dist/adapters/tmpfs.js +2 -1
- package/dist/epubcheck.cjs +60 -0
- package/dist/epubcheck.d.cts +23 -0
- package/dist/epubcheck.d.ts +23 -0
- package/dist/epubcheck.js +36 -0
- package/dist/index.cjs +404 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +404 -3
- package/dist/upgrade.d.cts +155 -5
- package/dist/upgrade.d.ts +155 -5
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -550,12 +550,15 @@ ${JSON.stringify(element, null, 2)}`
|
|
|
550
550
|
return metadata;
|
|
551
551
|
}
|
|
552
552
|
/**
|
|
553
|
-
* Retrieve the identifier from the dc:identifier element
|
|
553
|
+
* Retrieve the first identifier from the dc:identifier element
|
|
554
554
|
* in the EPUB metadata.
|
|
555
555
|
*
|
|
556
556
|
* If there is no dc:identifier element, returns null.
|
|
557
557
|
*
|
|
558
558
|
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
559
|
+
*
|
|
560
|
+
* @deprecated Use {@link getUniqueIdentifier} instead to get the unique identifier,
|
|
561
|
+
* or {@link getIdentifiers} to get all identifiers.
|
|
559
562
|
*/
|
|
560
563
|
async getIdentifier() {
|
|
561
564
|
const metadata = await this.getMetadata();
|
|
@@ -569,6 +572,8 @@ ${JSON.stringify(element, null, 2)}`
|
|
|
569
572
|
* Otherwise creates a new element
|
|
570
573
|
*
|
|
571
574
|
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
575
|
+
*
|
|
576
|
+
* @deprecated Use {@link setUniqueIdentifier} instead.
|
|
572
577
|
*/
|
|
573
578
|
async setIdentifier(identifier) {
|
|
574
579
|
await this.replaceMetadata(({ type }) => type === "dc:identifier", {
|
|
@@ -577,6 +582,395 @@ ${JSON.stringify(element, null, 2)}`
|
|
|
577
582
|
value: identifier
|
|
578
583
|
});
|
|
579
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* Retrieve the identifier with the unique identifier id
|
|
587
|
+
* in the EPUB metadata.
|
|
588
|
+
*
|
|
589
|
+
* If there is no unique identifier id, returns the first dc:identifier element.
|
|
590
|
+
*
|
|
591
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
592
|
+
*/
|
|
593
|
+
async getUniqueIdentifier() {
|
|
594
|
+
const metadata = await this.getMetadata();
|
|
595
|
+
const uniqueId = await this.getUniqueIdentifierId();
|
|
596
|
+
if (!uniqueId) {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
const entry = metadata.find(
|
|
600
|
+
({ type, id }) => type === "dc:identifier" && id === uniqueId
|
|
601
|
+
);
|
|
602
|
+
return (entry == null ? void 0 : entry.value) ?? null;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Set the unique identifier id for the EPUB.
|
|
606
|
+
*
|
|
607
|
+
* Updates the existing dc:identifier element referenced by the unique identifier id if one exists.
|
|
608
|
+
* Otherwise creates a new element with the provided identifier, and sets the unique identifier id to the new element's id.
|
|
609
|
+
*
|
|
610
|
+
* Note: you likely shouldn't change the unique identifier id unless you are producing a new EPUB.
|
|
611
|
+
*
|
|
612
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
613
|
+
*/
|
|
614
|
+
async setUniqueIdentifier(identifier) {
|
|
615
|
+
await this.withPackage(async (packageElement) => {
|
|
616
|
+
const metadata = Epub.findXmlChildByName(
|
|
617
|
+
"metadata",
|
|
618
|
+
Epub.getXmlChildren(packageElement)
|
|
619
|
+
);
|
|
620
|
+
if (!metadata) {
|
|
621
|
+
throw new Error(
|
|
622
|
+
"Failed to parse EPUB: found no metadata element in package document"
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
let uniqueId = await this.getUniqueIdentifierId();
|
|
626
|
+
if (!uniqueId) {
|
|
627
|
+
const newUniqueId = nanoid();
|
|
628
|
+
packageElement[":@"] = {
|
|
629
|
+
...packageElement[":@"],
|
|
630
|
+
"@_unique-identifier": newUniqueId
|
|
631
|
+
};
|
|
632
|
+
uniqueId = newUniqueId;
|
|
633
|
+
}
|
|
634
|
+
const children = Epub.getXmlChildren(metadata);
|
|
635
|
+
const entry = Epub.findXmlChildByName(
|
|
636
|
+
"dc:identifier",
|
|
637
|
+
children,
|
|
638
|
+
(node) => {
|
|
639
|
+
var _a;
|
|
640
|
+
return ((_a = node[":@"]) == null ? void 0 : _a["@_id"]) === uniqueId;
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
if (entry) {
|
|
644
|
+
children.splice(
|
|
645
|
+
children.indexOf(entry),
|
|
646
|
+
1,
|
|
647
|
+
Epub.createXmlElement("dc:identifier", { id: uniqueId }, [
|
|
648
|
+
Epub.createXmlTextNode(identifier)
|
|
649
|
+
])
|
|
650
|
+
);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
children.push(
|
|
654
|
+
Epub.createXmlElement("dc:identifier", { id: uniqueId }, [
|
|
655
|
+
Epub.createXmlTextNode(identifier)
|
|
656
|
+
])
|
|
657
|
+
);
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Retrieve the id of the publication's unique identifier, as declared by the
|
|
662
|
+
* package element's `unique-identifier` attribute.
|
|
663
|
+
*
|
|
664
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
665
|
+
*/
|
|
666
|
+
async getUniqueIdentifierId() {
|
|
667
|
+
var _a;
|
|
668
|
+
const packageElement = await this.getPackageElement();
|
|
669
|
+
return ((_a = packageElement[":@"]) == null ? void 0 : _a["@_unique-identifier"]) ?? null;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Collect `dc:identifier` or `dc:source` entries, attaching the value and
|
|
673
|
+
* scheme of any refining `identifier-type` meta (spec D.3.8) and a legacy
|
|
674
|
+
* `opf:scheme` attribute. Values are not interpreted.
|
|
675
|
+
*
|
|
676
|
+
* `onRefinement` is invoked for every other meta refining a collected entry,
|
|
677
|
+
* so callers can surface element-specific refinements (e.g. `source-of` on a
|
|
678
|
+
* `dc:source`).
|
|
679
|
+
*/
|
|
680
|
+
static collectDcEntries(metadata, type, onRefinement) {
|
|
681
|
+
const entries = metadata.filter((entry) => entry.type === type && entry.value !== void 0).map((entry) => ({
|
|
682
|
+
// filtered above, so value is defined
|
|
683
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
684
|
+
value: entry.value,
|
|
685
|
+
...entry.id && { id: entry.id },
|
|
686
|
+
...entry.properties["opf:scheme"] && {
|
|
687
|
+
scheme: entry.properties["opf:scheme"]
|
|
688
|
+
}
|
|
689
|
+
}));
|
|
690
|
+
for (const meta of metadata) {
|
|
691
|
+
if (meta.type !== "meta" || meta.value === void 0) continue;
|
|
692
|
+
const property = meta.properties["property"];
|
|
693
|
+
const refines = meta.properties["refines"];
|
|
694
|
+
if (!property || !refines) continue;
|
|
695
|
+
const target = entries.find((t) => t.id === refines.slice(1));
|
|
696
|
+
if (!target) continue;
|
|
697
|
+
if (property === "identifier-type") {
|
|
698
|
+
target.identifierType = meta.value;
|
|
699
|
+
if (meta.properties["scheme"]) target.scheme = meta.properties["scheme"];
|
|
700
|
+
} else {
|
|
701
|
+
onRefinement == null ? void 0 : onRefinement(target, property, meta.value);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return entries;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Retrieve every `dc:identifier` entry, returned as found.
|
|
708
|
+
*
|
|
709
|
+
* Values are not interpreted. Any refining `identifier-type` meta (spec
|
|
710
|
+
* D.3.8) or legacy `opf:scheme` attribute is surfaced on the entry, but no
|
|
711
|
+
* parsing of the value itself is attempted. To read `dc:source` entries, use
|
|
712
|
+
* {@link getSources}.
|
|
713
|
+
*
|
|
714
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
715
|
+
*/
|
|
716
|
+
async getIdentifiers() {
|
|
717
|
+
const metadata = await this.getMetadata();
|
|
718
|
+
return Epub.collectDcEntries(metadata, "dc:identifier");
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Retrieve every `dc:source` entry, returned as found.
|
|
722
|
+
*
|
|
723
|
+
* Like {@link getIdentifiers}, values are not interpreted. In addition to a
|
|
724
|
+
* refining `identifier-type`, a refining `source-of` meta (spec D.3.11) is
|
|
725
|
+
* surfaced as `sourceOf`.
|
|
726
|
+
*
|
|
727
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcsource
|
|
728
|
+
*/
|
|
729
|
+
async getSources() {
|
|
730
|
+
const metadata = await this.getMetadata();
|
|
731
|
+
return Epub.collectDcEntries(
|
|
732
|
+
metadata,
|
|
733
|
+
"dc:source",
|
|
734
|
+
(source, property) => {
|
|
735
|
+
if (property === "source-of") {
|
|
736
|
+
source.isPageBreakSource = true;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Retrieve the `pageBreakSource` property (EPUB 3.4, spec D.2.9), the
|
|
743
|
+
* publication-level source for the source of its page break markers.
|
|
744
|
+
*
|
|
745
|
+
* This property replaces the refining `source-of="pagination"` meta (spec
|
|
746
|
+
* D.3.11), see {@link EpubSource.sourceOf}. If no `pageBreakSource` property is found,
|
|
747
|
+
* we fall back to finding a `dc:source` with a `source-of="pagination"` refinement.
|
|
748
|
+
*
|
|
749
|
+
* @link https://www.w3.org/TR/epub/#pageBreakSource
|
|
750
|
+
*/
|
|
751
|
+
async getPageBreakSource() {
|
|
752
|
+
const entry = await this.findMetadataItem(
|
|
753
|
+
(item) => item.type === "meta" && item.properties["property"] === "pageBreakSource" && !!item.value
|
|
754
|
+
);
|
|
755
|
+
if (entry) {
|
|
756
|
+
return {
|
|
757
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
758
|
+
value: entry.value,
|
|
759
|
+
id: entry.id,
|
|
760
|
+
identifierType: void 0,
|
|
761
|
+
scheme: void 0,
|
|
762
|
+
isPageBreakSource: true
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
const sources = await this.getSources();
|
|
766
|
+
const source = sources.find((source2) => source2.isPageBreakSource);
|
|
767
|
+
if (source) {
|
|
768
|
+
return source;
|
|
769
|
+
}
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Set the `pageBreakSource` property (EPUB 3.4, spec D.2.9), or remove it when
|
|
774
|
+
* passed null. Replaces an existing `pageBreakSource` meta if present.
|
|
775
|
+
*
|
|
776
|
+
* Pass `none` to indicate the pagination is unique to this publication.
|
|
777
|
+
*
|
|
778
|
+
* @link https://www.w3.org/TR/epub/#pageBreakSource
|
|
779
|
+
*/
|
|
780
|
+
async setPageBreakSource(value) {
|
|
781
|
+
if (value === null) {
|
|
782
|
+
await this.removeMetadata(
|
|
783
|
+
(item) => item.properties["property"] === "pageBreakSource"
|
|
784
|
+
);
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
await this.replaceMetadata(
|
|
788
|
+
(item) => item.properties["property"] === "pageBreakSource",
|
|
789
|
+
{ type: "meta", properties: { property: "pageBreakSource" }, value }
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Replace the publication's `dc:identifier` entries.
|
|
794
|
+
*
|
|
795
|
+
* This replaces ALL existing `dc:identifier` elements except the publication's
|
|
796
|
+
* unique identifier (the one referenced by the package element's
|
|
797
|
+
* `unique-identifier` attribute), which is always preserved and must not be
|
|
798
|
+
* included in the provided list. If included anyway, it is ignored. See
|
|
799
|
+
* {@link setUniqueIdentifier} to change it.
|
|
800
|
+
*
|
|
801
|
+
* Identifiers are placed in the order they are provided.
|
|
802
|
+
*
|
|
803
|
+
* `dc:source` entries are not touched, use {@link setSources} for those.
|
|
804
|
+
*
|
|
805
|
+
* When an entry has an `identifierType`, it is written in the refining form
|
|
806
|
+
* (a `meta` with `property="identifier-type"`, carrying the `scheme`
|
|
807
|
+
* attribute when provided). An entry with only a `scheme` is written using
|
|
808
|
+
* the legacy `opf:scheme` attribute.
|
|
809
|
+
*
|
|
810
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
811
|
+
*/
|
|
812
|
+
async setIdentifiers(identifiers) {
|
|
813
|
+
const uniqueId = await this.getUniqueIdentifierId();
|
|
814
|
+
await this.withPackage((packageElement) => {
|
|
815
|
+
var _a;
|
|
816
|
+
const metadata = Epub.findXmlChildByName(
|
|
817
|
+
"metadata",
|
|
818
|
+
Epub.getXmlChildren(packageElement)
|
|
819
|
+
);
|
|
820
|
+
if (!metadata)
|
|
821
|
+
throw new Error(
|
|
822
|
+
"Failed to parse EPUB: found no metadata element in package document"
|
|
823
|
+
);
|
|
824
|
+
const children = Epub.getXmlChildren(metadata);
|
|
825
|
+
const removedIds = /* @__PURE__ */ new Set();
|
|
826
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
827
|
+
const node = children[i];
|
|
828
|
+
if (Epub.isXmlTextNode(node) || Epub.getXmlElementName(node) !== "dc:identifier") {
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
const id = (_a = node[":@"]) == null ? void 0 : _a["@_id"];
|
|
832
|
+
if (id && id === uniqueId) {
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
if (id) {
|
|
836
|
+
removedIds.add(id);
|
|
837
|
+
}
|
|
838
|
+
children.splice(i, 1);
|
|
839
|
+
}
|
|
840
|
+
Epub.removeRefiningMetas(children, removedIds, ["identifier-type"]);
|
|
841
|
+
for (const identifier of identifiers) {
|
|
842
|
+
if (identifier.id && identifier.id === uniqueId) continue;
|
|
843
|
+
const id = identifier.id ?? (identifier.identifierType !== void 0 ? nanoid() : void 0);
|
|
844
|
+
children.push(
|
|
845
|
+
Epub.createXmlElement(
|
|
846
|
+
"dc:identifier",
|
|
847
|
+
{
|
|
848
|
+
...id && { id },
|
|
849
|
+
...identifier.scheme && identifier.identifierType === void 0 && {
|
|
850
|
+
"opf:scheme": identifier.scheme
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
[Epub.createXmlTextNode(identifier.value)]
|
|
854
|
+
)
|
|
855
|
+
);
|
|
856
|
+
if (identifier.identifierType !== void 0 && id) {
|
|
857
|
+
children.push(
|
|
858
|
+
Epub.createXmlElement(
|
|
859
|
+
"meta",
|
|
860
|
+
{
|
|
861
|
+
refines: `#${id}`,
|
|
862
|
+
property: "identifier-type",
|
|
863
|
+
...identifier.scheme && { scheme: identifier.scheme }
|
|
864
|
+
},
|
|
865
|
+
[Epub.createXmlTextNode(identifier.identifierType)]
|
|
866
|
+
)
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Remove `meta` refinements pointing at any of the given ids,
|
|
874
|
+
* restricted to the given `property` values as a cleanup step
|
|
875
|
+
* Mutates `children` in place.
|
|
876
|
+
*/
|
|
877
|
+
static removeRefiningMetas(children, ids, properties) {
|
|
878
|
+
var _a, _b, _c;
|
|
879
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
880
|
+
const node = children[i];
|
|
881
|
+
if (Epub.isXmlTextNode(node) || Epub.getXmlElementName(node) !== "meta") {
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
const property = (_a = node[":@"]) == null ? void 0 : _a["@_property"];
|
|
885
|
+
if (!property || !properties.includes(property)) continue;
|
|
886
|
+
const refines = (_c = (_b = node[":@"]) == null ? void 0 : _b["@_refines"]) == null ? void 0 : _c.slice(1);
|
|
887
|
+
if (refines && ids.has(refines)) {
|
|
888
|
+
children.splice(i, 1);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Replace the publication's `dc:source` entries.
|
|
894
|
+
*
|
|
895
|
+
* This replaces ALL existing `dc:source` elements (and their refining
|
|
896
|
+
* `identifier-type` / `source-of` metas). `dc:identifier` entries are not
|
|
897
|
+
* touched; use {@link setIdentifiers} for those. Pass an empty array to
|
|
898
|
+
* remove all sources.
|
|
899
|
+
*
|
|
900
|
+
* When an entry has an `identifierType`, it is written in the refining form.
|
|
901
|
+
* A `sourceOf` value is written as a refining `source-of` meta (spec D.3.11).
|
|
902
|
+
* An entry with only a `scheme` uses the legacy `opf:scheme` attribute.
|
|
903
|
+
*
|
|
904
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcsource
|
|
905
|
+
*/
|
|
906
|
+
async setSources(sources) {
|
|
907
|
+
await this.withPackage((packageElement) => {
|
|
908
|
+
var _a;
|
|
909
|
+
const metadata = Epub.findXmlChildByName(
|
|
910
|
+
"metadata",
|
|
911
|
+
Epub.getXmlChildren(packageElement)
|
|
912
|
+
);
|
|
913
|
+
if (!metadata)
|
|
914
|
+
throw new Error(
|
|
915
|
+
"Failed to parse EPUB: found no metadata element in package document"
|
|
916
|
+
);
|
|
917
|
+
const children = Epub.getXmlChildren(metadata);
|
|
918
|
+
const removedIds = /* @__PURE__ */ new Set();
|
|
919
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
920
|
+
const node = children[i];
|
|
921
|
+
if (Epub.isXmlTextNode(node) || Epub.getXmlElementName(node) !== "dc:source") {
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
const id = (_a = node[":@"]) == null ? void 0 : _a["@_id"];
|
|
925
|
+
if (id) {
|
|
926
|
+
removedIds.add(id);
|
|
927
|
+
}
|
|
928
|
+
children.splice(i, 1);
|
|
929
|
+
}
|
|
930
|
+
Epub.removeRefiningMetas(children, removedIds, [
|
|
931
|
+
"identifier-type",
|
|
932
|
+
"source-of"
|
|
933
|
+
]);
|
|
934
|
+
for (const source of sources) {
|
|
935
|
+
const needsId = source.identifierType !== void 0 || source.isPageBreakSource;
|
|
936
|
+
const id = source.id ?? (needsId ? nanoid() : void 0);
|
|
937
|
+
children.push(
|
|
938
|
+
Epub.createXmlElement(
|
|
939
|
+
"dc:source",
|
|
940
|
+
{
|
|
941
|
+
...id && { id },
|
|
942
|
+
...source.scheme && source.identifierType === void 0 && {
|
|
943
|
+
"opf:scheme": source.scheme
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
[Epub.createXmlTextNode(source.value)]
|
|
947
|
+
)
|
|
948
|
+
);
|
|
949
|
+
if (source.identifierType !== void 0 && id) {
|
|
950
|
+
children.push(
|
|
951
|
+
Epub.createXmlElement(
|
|
952
|
+
"meta",
|
|
953
|
+
{
|
|
954
|
+
refines: `#${id}`,
|
|
955
|
+
property: "identifier-type",
|
|
956
|
+
...source.scheme && { scheme: source.scheme }
|
|
957
|
+
},
|
|
958
|
+
[Epub.createXmlTextNode(source.identifierType)]
|
|
959
|
+
)
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
if (source.isPageBreakSource && id) {
|
|
963
|
+
children.push(
|
|
964
|
+
Epub.createXmlElement(
|
|
965
|
+
"meta",
|
|
966
|
+
{ refines: `#${id}`, property: "source-of" },
|
|
967
|
+
[Epub.createXmlTextNode("pagination")]
|
|
968
|
+
)
|
|
969
|
+
);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
}
|
|
580
974
|
/**
|
|
581
975
|
* Even "EPUB 3" publications sometimes still only use the
|
|
582
976
|
* EPUB 2 specification for identifying the cover image.
|
|
@@ -1257,7 +1651,14 @@ ${JSON.stringify(element, null, 2)}`
|
|
|
1257
1651
|
const creatorEntries = metadata.filter(
|
|
1258
1652
|
(entry) => entry.type === `dc:${type}`
|
|
1259
1653
|
);
|
|
1260
|
-
const creators =
|
|
1654
|
+
const creators = [];
|
|
1655
|
+
const creatorsById = /* @__PURE__ */ new Map();
|
|
1656
|
+
for (const entry of creatorEntries) {
|
|
1657
|
+
if (!entry.value) continue;
|
|
1658
|
+
const creator = { name: entry.value };
|
|
1659
|
+
creators.push(creator);
|
|
1660
|
+
if (entry.id) creatorsById.set(entry.id, creator);
|
|
1661
|
+
}
|
|
1261
1662
|
metadata.forEach((entry) => {
|
|
1262
1663
|
if (entry.type !== "meta" || entry.properties["property"] !== "file-as" && entry.properties["property"] !== "role" && entry.properties["property"] !== "alternate-script" || !entry.value) {
|
|
1263
1664
|
return;
|
|
@@ -1265,7 +1666,7 @@ ${JSON.stringify(element, null, 2)}`
|
|
|
1265
1666
|
const creatorIdref = entry.properties["refines"];
|
|
1266
1667
|
if (!creatorIdref) return;
|
|
1267
1668
|
const creatorId = creatorIdref.slice(1);
|
|
1268
|
-
const creator =
|
|
1669
|
+
const creator = creatorsById.get(creatorId);
|
|
1269
1670
|
if (!creator) return;
|
|
1270
1671
|
if (entry.properties["alternate-script"]) {
|
|
1271
1672
|
if (!entry.properties["xml:lang"]) return;
|
package/dist/upgrade.d.cts
CHANGED
|
@@ -87,6 +87,31 @@ interface DcSubject {
|
|
|
87
87
|
authority: string;
|
|
88
88
|
term: string;
|
|
89
89
|
}
|
|
90
|
+
interface EpubIdentifier {
|
|
91
|
+
value: string;
|
|
92
|
+
id?: string | undefined;
|
|
93
|
+
/** the value of a refining `identifier-type` meta, if present */
|
|
94
|
+
identifierType?: string | undefined;
|
|
95
|
+
/** the `scheme` of a refining `identifier-type` meta, or a legacy `opf:scheme` attribute */
|
|
96
|
+
scheme?: string | undefined;
|
|
97
|
+
}
|
|
98
|
+
interface EpubSource {
|
|
99
|
+
value: string;
|
|
100
|
+
id?: string | undefined;
|
|
101
|
+
/** the value of a refining `identifier-type` meta, if present */
|
|
102
|
+
identifierType?: string | undefined;
|
|
103
|
+
/** the `scheme` of a refining `identifier-type` meta, or a legacy `opf:scheme` attribute */
|
|
104
|
+
scheme?: string | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* whether this source has a `source-of="pagination"` refinement
|
|
107
|
+
* or of a `<meta property="pageBreakSource">` element
|
|
108
|
+
*
|
|
109
|
+
* as of EPUB 3.4 `source-of` is advised-deprecated in favour of the
|
|
110
|
+
* publication-level `pageBreakSource` property. if you want to
|
|
111
|
+
* be sure to get the source of pagination, use {@link Epub.getPageBreakSource}
|
|
112
|
+
*/
|
|
113
|
+
isPageBreakSource?: boolean | undefined;
|
|
114
|
+
}
|
|
90
115
|
interface AlternateScript {
|
|
91
116
|
name: string;
|
|
92
117
|
locale: Intl.Locale;
|
|
@@ -140,7 +165,7 @@ interface FromOptions {
|
|
|
140
165
|
* Read-only view of an EPUB
|
|
141
166
|
* Returned by Epub.using(MemoryAdapter).from(...) and by Epub.from(path, { readonly: true })
|
|
142
167
|
*/
|
|
143
|
-
type EpubReader = Pick<Epub, "storage" | "
|
|
168
|
+
type EpubReader = Pick<Epub, "storage" | "findMetadataItem" | "findAllMetadataItems" | "resolveHref" | "readFileContents" | "readItemContents" | "readXhtmlItemContents" | "discardAndClose" | Extract<keyof Epub, `get${string}`>> & Disposable;
|
|
144
169
|
/**
|
|
145
170
|
* Readonly Epub-instance backed by an in-memory zip handle
|
|
146
171
|
* Returned by `Epub.using(MemoryAdapter).from(...)`
|
|
@@ -366,7 +391,7 @@ declare class Epub {
|
|
|
366
391
|
*/
|
|
367
392
|
findMetadataItem(predicate: (entry: MetadataEntry) => boolean): Promise<{
|
|
368
393
|
id: string | undefined;
|
|
369
|
-
type: `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}
|
|
394
|
+
type: `?${string}` | `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}`;
|
|
370
395
|
properties: {
|
|
371
396
|
[k: string]: string;
|
|
372
397
|
};
|
|
@@ -378,7 +403,7 @@ declare class Epub {
|
|
|
378
403
|
*/
|
|
379
404
|
findAllMetadataItems(predicate: (entry: MetadataEntry) => boolean): Promise<{
|
|
380
405
|
id: string | undefined;
|
|
381
|
-
type: `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}
|
|
406
|
+
type: `?${string}` | `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}`;
|
|
382
407
|
properties: {
|
|
383
408
|
[k: string]: string;
|
|
384
409
|
};
|
|
@@ -398,12 +423,15 @@ declare class Epub {
|
|
|
398
423
|
*/
|
|
399
424
|
getMetadata(): Promise<EpubMetadata>;
|
|
400
425
|
/**
|
|
401
|
-
* Retrieve the identifier from the dc:identifier element
|
|
426
|
+
* Retrieve the first identifier from the dc:identifier element
|
|
402
427
|
* in the EPUB metadata.
|
|
403
428
|
*
|
|
404
429
|
* If there is no dc:identifier element, returns null.
|
|
405
430
|
*
|
|
406
431
|
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
432
|
+
*
|
|
433
|
+
* @deprecated Use {@link getUniqueIdentifier} instead to get the unique identifier,
|
|
434
|
+
* or {@link getIdentifiers} to get all identifiers.
|
|
407
435
|
*/
|
|
408
436
|
getIdentifier(): Promise<string | null>;
|
|
409
437
|
/**
|
|
@@ -413,8 +441,130 @@ declare class Epub {
|
|
|
413
441
|
* Otherwise creates a new element
|
|
414
442
|
*
|
|
415
443
|
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
444
|
+
*
|
|
445
|
+
* @deprecated Use {@link setUniqueIdentifier} instead.
|
|
416
446
|
*/
|
|
417
447
|
setIdentifier(identifier: string): Promise<void>;
|
|
448
|
+
/**
|
|
449
|
+
* Retrieve the identifier with the unique identifier id
|
|
450
|
+
* in the EPUB metadata.
|
|
451
|
+
*
|
|
452
|
+
* If there is no unique identifier id, returns the first dc:identifier element.
|
|
453
|
+
*
|
|
454
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
455
|
+
*/
|
|
456
|
+
getUniqueIdentifier(): Promise<string | null>;
|
|
457
|
+
/**
|
|
458
|
+
* Set the unique identifier id for the EPUB.
|
|
459
|
+
*
|
|
460
|
+
* Updates the existing dc:identifier element referenced by the unique identifier id if one exists.
|
|
461
|
+
* Otherwise creates a new element with the provided identifier, and sets the unique identifier id to the new element's id.
|
|
462
|
+
*
|
|
463
|
+
* Note: you likely shouldn't change the unique identifier id unless you are producing a new EPUB.
|
|
464
|
+
*
|
|
465
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
466
|
+
*/
|
|
467
|
+
setUniqueIdentifier(identifier: string): Promise<void>;
|
|
468
|
+
/**
|
|
469
|
+
* Retrieve the id of the publication's unique identifier, as declared by the
|
|
470
|
+
* package element's `unique-identifier` attribute.
|
|
471
|
+
*
|
|
472
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
473
|
+
*/
|
|
474
|
+
getUniqueIdentifierId(): Promise<string | null>;
|
|
475
|
+
/**
|
|
476
|
+
* Collect `dc:identifier` or `dc:source` entries, attaching the value and
|
|
477
|
+
* scheme of any refining `identifier-type` meta (spec D.3.8) and a legacy
|
|
478
|
+
* `opf:scheme` attribute. Values are not interpreted.
|
|
479
|
+
*
|
|
480
|
+
* `onRefinement` is invoked for every other meta refining a collected entry,
|
|
481
|
+
* so callers can surface element-specific refinements (e.g. `source-of` on a
|
|
482
|
+
* `dc:source`).
|
|
483
|
+
*/
|
|
484
|
+
private static collectDcEntries;
|
|
485
|
+
/**
|
|
486
|
+
* Retrieve every `dc:identifier` entry, returned as found.
|
|
487
|
+
*
|
|
488
|
+
* Values are not interpreted. Any refining `identifier-type` meta (spec
|
|
489
|
+
* D.3.8) or legacy `opf:scheme` attribute is surfaced on the entry, but no
|
|
490
|
+
* parsing of the value itself is attempted. To read `dc:source` entries, use
|
|
491
|
+
* {@link getSources}.
|
|
492
|
+
*
|
|
493
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
494
|
+
*/
|
|
495
|
+
getIdentifiers(): Promise<EpubIdentifier[]>;
|
|
496
|
+
/**
|
|
497
|
+
* Retrieve every `dc:source` entry, returned as found.
|
|
498
|
+
*
|
|
499
|
+
* Like {@link getIdentifiers}, values are not interpreted. In addition to a
|
|
500
|
+
* refining `identifier-type`, a refining `source-of` meta (spec D.3.11) is
|
|
501
|
+
* surfaced as `sourceOf`.
|
|
502
|
+
*
|
|
503
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcsource
|
|
504
|
+
*/
|
|
505
|
+
getSources(): Promise<EpubSource[]>;
|
|
506
|
+
/**
|
|
507
|
+
* Retrieve the `pageBreakSource` property (EPUB 3.4, spec D.2.9), the
|
|
508
|
+
* publication-level source for the source of its page break markers.
|
|
509
|
+
*
|
|
510
|
+
* This property replaces the refining `source-of="pagination"` meta (spec
|
|
511
|
+
* D.3.11), see {@link EpubSource.sourceOf}. If no `pageBreakSource` property is found,
|
|
512
|
+
* we fall back to finding a `dc:source` with a `source-of="pagination"` refinement.
|
|
513
|
+
*
|
|
514
|
+
* @link https://www.w3.org/TR/epub/#pageBreakSource
|
|
515
|
+
*/
|
|
516
|
+
getPageBreakSource(): Promise<EpubSource | null>;
|
|
517
|
+
/**
|
|
518
|
+
* Set the `pageBreakSource` property (EPUB 3.4, spec D.2.9), or remove it when
|
|
519
|
+
* passed null. Replaces an existing `pageBreakSource` meta if present.
|
|
520
|
+
*
|
|
521
|
+
* Pass `none` to indicate the pagination is unique to this publication.
|
|
522
|
+
*
|
|
523
|
+
* @link https://www.w3.org/TR/epub/#pageBreakSource
|
|
524
|
+
*/
|
|
525
|
+
setPageBreakSource(value: string | null): Promise<void>;
|
|
526
|
+
/**
|
|
527
|
+
* Replace the publication's `dc:identifier` entries.
|
|
528
|
+
*
|
|
529
|
+
* This replaces ALL existing `dc:identifier` elements except the publication's
|
|
530
|
+
* unique identifier (the one referenced by the package element's
|
|
531
|
+
* `unique-identifier` attribute), which is always preserved and must not be
|
|
532
|
+
* included in the provided list. If included anyway, it is ignored. See
|
|
533
|
+
* {@link setUniqueIdentifier} to change it.
|
|
534
|
+
*
|
|
535
|
+
* Identifiers are placed in the order they are provided.
|
|
536
|
+
*
|
|
537
|
+
* `dc:source` entries are not touched, use {@link setSources} for those.
|
|
538
|
+
*
|
|
539
|
+
* When an entry has an `identifierType`, it is written in the refining form
|
|
540
|
+
* (a `meta` with `property="identifier-type"`, carrying the `scheme`
|
|
541
|
+
* attribute when provided). An entry with only a `scheme` is written using
|
|
542
|
+
* the legacy `opf:scheme` attribute.
|
|
543
|
+
*
|
|
544
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier
|
|
545
|
+
*/
|
|
546
|
+
setIdentifiers(identifiers: EpubIdentifier[]): Promise<void>;
|
|
547
|
+
/**
|
|
548
|
+
* Remove `meta` refinements pointing at any of the given ids,
|
|
549
|
+
* restricted to the given `property` values as a cleanup step
|
|
550
|
+
* Mutates `children` in place.
|
|
551
|
+
*/
|
|
552
|
+
private static removeRefiningMetas;
|
|
553
|
+
/**
|
|
554
|
+
* Replace the publication's `dc:source` entries.
|
|
555
|
+
*
|
|
556
|
+
* This replaces ALL existing `dc:source` elements (and their refining
|
|
557
|
+
* `identifier-type` / `source-of` metas). `dc:identifier` entries are not
|
|
558
|
+
* touched; use {@link setIdentifiers} for those. Pass an empty array to
|
|
559
|
+
* remove all sources.
|
|
560
|
+
*
|
|
561
|
+
* When an entry has an `identifierType`, it is written in the refining form.
|
|
562
|
+
* A `sourceOf` value is written as a refining `source-of` meta (spec D.3.11).
|
|
563
|
+
* An entry with only a `scheme` uses the legacy `opf:scheme` attribute.
|
|
564
|
+
*
|
|
565
|
+
* @link https://www.w3.org/TR/epub-33/#sec-opf-dcsource
|
|
566
|
+
*/
|
|
567
|
+
setSources(sources: EpubSource[]): Promise<void>;
|
|
418
568
|
/**
|
|
419
569
|
* Even "EPUB 3" publications sometimes still only use the
|
|
420
570
|
* EPUB 2 specification for identifying the cover image.
|
|
@@ -1029,4 +1179,4 @@ declare class EpubFactory<A extends EpubStorageAdapterClass> {
|
|
|
1029
1179
|
upgrade(path: string, options?: Epub2UpgradeOptions): Promise<EpubInstanceFor<A>>;
|
|
1030
1180
|
}
|
|
1031
1181
|
|
|
1032
|
-
export { type AlternateScript as A, type Collection as C, type DcSubject as D, type ElementName as E, type Epub2UpgradeOptions, type FromOptions as F, type InMemoryEpubReader as I, type Landmark, type ManifestItem as M, type NavigationItem as N, type ParsedXml as P, type XmlElement as X, type XmlTextNode as a, type XmlNode as b, buildNavDocument, buildTocOl, type MetadataEntry as c, chooseNavHref, collectManifestProperties, type EpubMetadata as d, type
|
|
1182
|
+
export { type AlternateScript as A, type Collection as C, type DcSubject as D, type ElementName as E, type Epub2UpgradeOptions, type FromOptions as F, type InMemoryEpubReader as I, type Landmark, type ManifestItem as M, type NavigationItem as N, type ParsedXml as P, type XmlElement as X, type XmlTextNode as a, type XmlNode as b, buildNavDocument, buildTocOl, type MetadataEntry as c, chooseNavHref, collectManifestProperties, type EpubMetadata as d, type EpubIdentifier as e, extractGuideLandmarks, type EpubSource as f, fixFontMimeTypes, type DcCreator as g, type DublinCore as h, type NavigationList as i, type Navigation as j, type PackageElement as k, type EpubReader as l, EpubVersionError as m, EpubReadOnlyError as n, Epub as o, type EpubInstanceFor as p, EpubFactory as q, removeGuide, removeInvalidDcAttrs, removeNcx, removeSpineTocRef, setLastModified, setPackageVersion, upgradeAuthors, upgradeCover, upgradeDate, upgradeIdentifiers, upgradeLanguages, upgradeMeta, upgradePackageMetadata, upgradeTitle };
|