@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/upgrade.d.ts
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyteller-platform/epub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
"readme:toc": "markdown-toc --maxdepth=5 --append='\n- [API Docs](#api-docs)' --bullets='-' -i readme-stub.md",
|
|
24
24
|
"readme:api": "typedoc",
|
|
25
25
|
"readme": "yarn readme:api && yarn readme:toc && cat readme-stub.md > README.md && tail -n +2 gen/README.md >> README.md",
|
|
26
|
-
"
|
|
27
|
-
"test
|
|
26
|
+
"install-epubcheck": "tsx scripts/install-epubcheck.ts",
|
|
27
|
+
"test": "yarn install-epubcheck && tsx -C @storyteller --test *.test.ts",
|
|
28
|
+
"test:watch": "yarn install-epubcheck && tsx -C @storyteller --test --watch *.test.ts",
|
|
28
29
|
"prepack": "yarn build"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
@@ -35,7 +36,6 @@
|
|
|
35
36
|
"@types/node": "^24.0.0",
|
|
36
37
|
"@types/yauzl-promise": "^4",
|
|
37
38
|
"@types/yazl": "^3",
|
|
38
|
-
"epubchecker": "^5.2.1",
|
|
39
39
|
"eslint": "^8.0.0",
|
|
40
40
|
"markdown-toc": "^1.2.0",
|
|
41
41
|
"remark-toc": "^9.0.0",
|