@storyteller-platform/epub 0.5.1 → 0.6.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.
@@ -1,4 +1,7 @@
1
1
  import { XMLParser, XMLBuilder } from 'fast-xml-parser';
2
+ import { EpubStorageAdapterClass, EpubStorageAdapter, EpubStorageKind, AdapterOptions } from './adapters/interface.cjs';
3
+ import './adapters/memory.cjs';
4
+ import './adapters/tmpfs.cjs';
2
5
 
3
6
  interface Landmark {
4
7
  href: string;
@@ -126,8 +129,29 @@ interface GuideItem {
126
129
  type: string;
127
130
  }
128
131
  type PackageElement = XmlElement<"package">;
132
+ interface FromOptions {
133
+ /**
134
+ * when true, mutation methods throw {@link EpubReadOnlyError} at runtime
135
+ * @default false
136
+ */
137
+ readonly?: boolean;
138
+ }
139
+ /**
140
+ * Read-only view of an EPUB
141
+ * Returned by Epub.using(MemoryAdapter).from(...) and by Epub.from(path, { readonly: true })
142
+ */
143
+ type EpubReader = Pick<Epub, "storage" | "getManifest" | "getVersion" | "getLayout" | "getBaseDirection" | "getMetadata" | "findMetadataItem" | "findAllMetadataItems" | "getIdentifier" | "getTitle" | "getSubtitle" | "getTitles" | "getLanguage" | "getPublicationDate" | "getModifiedDate" | "getDescription" | "getType" | "getCreators" | "getContributors" | "getSubjects" | "getCollections" | "getPackageVocabularyPrefixes" | "getCoverImageItem" | "getCoverImage" | "getSpineItems" | "getNcxTableOfContents" | "getGuideEntries" | "getTableOfContents" | "getLandmarks" | "getPageList" | "resolveHref" | "readFileContents" | "readItemContents" | "readXhtmlItemContents" | "getItemArchiveLength" | "discardAndClose"> & Disposable;
144
+ /**
145
+ * Readonly Epub-instance backed by an in-memory zip handle
146
+ * Returned by `Epub.using(MemoryAdapter).from(...)`
147
+ */
148
+ type InMemoryEpubReader = EpubReader & {
149
+ readonly storage: "in-memory";
150
+ };
129
151
  declare class EpubVersionError extends Error {
130
152
  }
153
+ declare class EpubReadOnlyError extends Error {
154
+ }
131
155
  /**
132
156
  * A single EPUB instance.
133
157
  *
@@ -156,8 +180,10 @@ declare class EpubVersionError extends Error {
156
180
  * @link https://www.w3.org/TR/epub-33/
157
181
  */
158
182
  declare class Epub {
159
- protected extractPath: string;
183
+ protected adapterClass: EpubStorageAdapterClass;
184
+ protected adapter: EpubStorageAdapter;
160
185
  protected inputPath: string | undefined;
186
+ protected readonlyOverride: boolean;
161
187
  static xmlParser: XMLParser;
162
188
  static xhtmlParser: XMLParser;
163
189
  static xmlBuilder: XMLBuilder;
@@ -229,34 +255,78 @@ declare class Epub {
229
255
  private manifest;
230
256
  private spine;
231
257
  private packageMutex;
232
- protected constructor(extractPath: string, inputPath: string | undefined);
233
258
  /**
234
- * Construct an Epub instance, optionally beginning
235
- * with the provided metadata.
259
+ * Storage backend kind in use for this instance
260
+ *
261
+ * Public so callers can declare type-level requirements via {@link InMemoryEpubReader}
262
+ * Orthogonal to the read-only / writable axis (controlled by `readonlyOverride`
263
+ * and the adapter's capability bag)
264
+ */
265
+ readonly storage: EpubStorageKind;
266
+ /**
267
+ * Prefer the static factories ({@link Epub.using}, {@link Epub.from},
268
+ * {@link Epub.create}, {@link Epub.upgrade}) over calling this constructor
269
+ * directly. It's public so {@link EpubFactory} can construct instances; nothing
270
+ * else should need to.
271
+ */
272
+ constructor(adapterClass: EpubStorageAdapterClass, adapter: EpubStorageAdapter, inputPath: string | undefined, readonlyOverride?: boolean);
273
+ /**
274
+ * Runtime guard for mutation methods
275
+ */
276
+ private assertWritable;
277
+ /**
278
+ * Construct a new EPUB on a writable backend, optionally seeded
279
+ * with the provided metadata. Equivalent to
280
+ * `Epub.using(TmpFsAdapter).create(...)`.
236
281
  *
237
282
  * @param dublinCore Core metadata terms
238
283
  * @param additionalMetadata An array of additional metadata entries
239
284
  */
240
- static create(path: string, { title, language, identifier, date, subjects, type, creators, contributors, }: DublinCore, additionalMetadata?: EpubMetadata): Promise<Epub>;
285
+ static create(path: string, dublinCore: DublinCore, additionalMetadata?: EpubMetadata): Promise<Epub>;
241
286
  /**
242
- * Construct an Epub instance by reading an existing EPUB
243
- * publication.
287
+ * Specify the storage backend to use for the EPUB
288
+ *
289
+ * The returned factory exposes `from`, `create`, and `upgrade`,
290
+ * which route through the supplied adapter.
244
291
  *
245
- * @param pathOrData Must be either a string representing the
246
- * path to an EPUB file on disk, or a Uint8Array representing
247
- * the data of the EPUB publication.
292
+ * @example
293
+ * ```ts
294
+ * using epub = await Epub.using(TmpFsAdapter).from(path)
295
+ * using reader = await Epub.using(MemoryAdapter).from(buffer, { cache: false })
296
+ * ```
248
297
  */
249
- static from(pathOrData: string | Uint8Array): Promise<Epub>;
298
+ static using<A extends EpubStorageAdapterClass>(adapterClass: A): EpubFactory<A>;
250
299
  /**
251
- * Open an EPUB publication and return an Epub instance.
300
+ * Open an existing EPUB publication, extracting it to a temp directory
301
+ * so writes can mutate the unpacked tree and rezip with `saveAndClose`.
302
+ *
303
+ * Pass `{ readonly: true }` to gate mutations at runtime.
304
+ *
305
+ * prefer `Epub.using(TmpFsAdapter).from(path)` (or
306
+ * `Epub.using(MemoryAdapter).from(path)` for read-only, in-memory access)
307
+ * @throws {EpubVersionError} when the archive is not a valid EPUB 3
252
308
  */
253
- private static open;
309
+ static from(pathOrData: string | Uint8Array): Promise<Epub>;
310
+ static from(pathOrData: string | Uint8Array, options: FromOptions & {
311
+ readonly: true;
312
+ }): Promise<EpubReader>;
313
+ static from(pathOrData: string | Uint8Array, options?: FromOptions): Promise<Epub | EpubReader>;
314
+ static assertEpub3(epub: Epub): Promise<void>;
254
315
  copy(path?: string): Promise<Epub>;
255
316
  private removeEntry;
317
+ /**
318
+ * Read raw bytes (or utf-8 text) from the underlying adapter
319
+ */
256
320
  private getFileData;
321
+ /**
322
+ * Length of the underlying archive entry for a manifest item, in bytes
323
+ * Necessary to compute the readium page count which is for COMPRESSED content
324
+ * @see {@link https://github.com/readium/architecture/issues/123}
325
+ */
326
+ getItemArchiveLength(id: string): Promise<number>;
257
327
  getRootfile(): Promise<string>;
258
328
  private getPackageDocument;
259
- private getPackageElement;
329
+ getPackageElement(): Promise<XmlElement<"package">>;
260
330
  /**
261
331
  * Safely modify the package document, without race conditions.
262
332
  *
@@ -269,7 +339,7 @@ declare class Epub {
269
339
  * it returns a new package document, that will be persisted, otherwise
270
340
  * it will be assumed that the package document was modified in place.
271
341
  */
272
- private withPackage;
342
+ withPackage(producer: ((packageElement: PackageElement) => void) | ((packageElement: PackageElement) => PackageElement) | ((packageElement: PackageElement) => Promise<PackageElement>) | ((packageElement: PackageElement) => Promise<void>)): Promise<void>;
273
343
  /**
274
344
  * Retrieve the manifest for the Epub.
275
345
  *
@@ -891,7 +961,55 @@ declare class Epub {
891
961
  */
892
962
  saveAndClose(): Promise<void>;
893
963
  /**
894
- * Upgrade an EPUB 2 publication to EPUB 3 in place, returning a new, valid Epub 3 instance.
964
+ * Upgrade an EPUB 2 publication to EPUB 3 in place, returning a new,
965
+ * valid Epub 3 instance. Equivalent to
966
+ * `Epub.using(TmpFsAdapter).upgrade(...)`.
967
+ */
968
+ static upgrade(path: string, options?: Epub2UpgradeOptions): Promise<Epub>;
969
+ [Symbol.dispose](): void;
970
+ }
971
+ /**
972
+ * Resolves to {@link Epub} for writable adapters, {@link EpubReader} for read-only ones.
973
+ *
974
+ * The conditional pivots on `capabilities.writable`, which must be a literal
975
+ * `true`/`false` on the adapter class (use `as const`) for inference to work.
976
+ */
977
+ type EpubInstanceFor<A extends EpubStorageAdapterClass> = A["capabilities"]["writable"] extends true ? Epub : EpubReader;
978
+ /**
979
+ * Adapter-bound factory returned by {@link Epub.using}.
980
+ *
981
+ * Mirrors the static factory surface (`from`, `create`, `upgrade`) but routes
982
+ * all I/O through the supplied adapter. Each method's signature degrades
983
+ * gracefully when the adapter doesn't support the operation: `create` and
984
+ * `upgrade` throw at runtime if the adapter is read-only or lacks `initEmpty`.
985
+ */
986
+ declare class EpubFactory<A extends EpubStorageAdapterClass> {
987
+ readonly adapterClass: A;
988
+ constructor(adapterClass: A);
989
+ /**
990
+ * Open an existing EPUB through this factory's adapter
991
+ *
992
+ * @throws {EpubVersionError} when the archive is not a valid EPUB 3
993
+ */
994
+ from(source: string | Uint8Array, options: FromOptions & {
995
+ readonly: true;
996
+ } & AdapterOptions<A>): Promise<EpubReader & {
997
+ storage: A["kind"];
998
+ }>;
999
+ from(source: string | Uint8Array, options?: FromOptions & AdapterOptions<A>): Promise<EpubInstanceFor<A> & {
1000
+ storage: A["kind"];
1001
+ }>;
1002
+ /**
1003
+ * Construct a new EPUB on this factory's adapter, optionally seeded
1004
+ * with the provided metadata. Requires a writable adapter that
1005
+ * implements `initEmpty` (today: {@link TmpFsAdapter}).
1006
+ *
1007
+ * @throws when the adapter is read-only or does not implement initEmpty
1008
+ */
1009
+ create(path: string, { title, language, identifier, date, subjects, type, creators, contributors, }: DublinCore, additionalMetadata?: EpubMetadata): Promise<EpubInstanceFor<A>>;
1010
+ /**
1011
+ * Upgrade an EPUB 2 publication to EPUB 3 in place using this
1012
+ * factory's adapter, returning a new, valid Epub 3 instance.
895
1013
  *
896
1014
  * Performs the following transformations:
897
1015
  * - upgrades OPF metadata to EPUB 3 conventions
@@ -901,9 +1019,14 @@ declare class Epub {
901
1019
  * - fixes common font MIME types
902
1020
  * - bumps the package version to 3.0
903
1021
  * - goes over each xhtml item and rewrites it using XMLParser to make sure the output is valid XHTML
1022
+ *
1023
+ * Requires a writable adapter. When {@link Upgrade.Epub2UpgradeOptions.outputPath}
1024
+ * is set, the source file is copied to that path on disk first; this
1025
+ * only makes sense for adapters whose `source` is a real fs path.
1026
+ *
1027
+ * @throws when the adapter is read-only
904
1028
  */
905
- static upgrade(path: string, options?: Epub2UpgradeOptions): Promise<Epub>;
906
- [Symbol.dispose](): void;
1029
+ upgrade(path: string, options?: Epub2UpgradeOptions): Promise<EpubInstanceFor<A>>;
907
1030
  }
908
1031
 
909
- export { type AlternateScript as A, type Collection as C, type DcSubject as D, type ElementName as E, type Epub2UpgradeOptions, 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 DcCreator as e, extractGuideLandmarks, type DublinCore as f, fixFontMimeTypes, type NavigationList as g, type Navigation as h, type PackageElement as i, EpubVersionError as j, Epub as k, removeGuide, removeInvalidDcAttrs, removeNcx, removeSpineTocRef, setLastModified, setPackageVersion, upgradeAuthors, upgradeCover, upgradeDate, upgradeIdentifiers, upgradeLanguages, upgradeMeta, upgradePackageMetadata, upgradeTitle };
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 DcCreator as e, extractGuideLandmarks, type DublinCore as f, fixFontMimeTypes, type NavigationList as g, type Navigation as h, type PackageElement as i, type EpubReader as j, EpubVersionError as k, EpubReadOnlyError as l, Epub as m, type EpubInstanceFor as n, EpubFactory as o, removeGuide, removeInvalidDcAttrs, removeNcx, removeSpineTocRef, setLastModified, setPackageVersion, upgradeAuthors, upgradeCover, upgradeDate, upgradeIdentifiers, upgradeLanguages, upgradeMeta, upgradePackageMetadata, upgradeTitle };
package/dist/upgrade.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { XMLParser, XMLBuilder } from 'fast-xml-parser';
2
+ import { EpubStorageAdapterClass, EpubStorageAdapter, EpubStorageKind, AdapterOptions } from './adapters/interface.js';
3
+ import './adapters/memory.js';
4
+ import './adapters/tmpfs.js';
2
5
 
3
6
  interface Landmark {
4
7
  href: string;
@@ -126,8 +129,29 @@ interface GuideItem {
126
129
  type: string;
127
130
  }
128
131
  type PackageElement = XmlElement<"package">;
132
+ interface FromOptions {
133
+ /**
134
+ * when true, mutation methods throw {@link EpubReadOnlyError} at runtime
135
+ * @default false
136
+ */
137
+ readonly?: boolean;
138
+ }
139
+ /**
140
+ * Read-only view of an EPUB
141
+ * Returned by Epub.using(MemoryAdapter).from(...) and by Epub.from(path, { readonly: true })
142
+ */
143
+ type EpubReader = Pick<Epub, "storage" | "getManifest" | "getVersion" | "getLayout" | "getBaseDirection" | "getMetadata" | "findMetadataItem" | "findAllMetadataItems" | "getIdentifier" | "getTitle" | "getSubtitle" | "getTitles" | "getLanguage" | "getPublicationDate" | "getModifiedDate" | "getDescription" | "getType" | "getCreators" | "getContributors" | "getSubjects" | "getCollections" | "getPackageVocabularyPrefixes" | "getCoverImageItem" | "getCoverImage" | "getSpineItems" | "getNcxTableOfContents" | "getGuideEntries" | "getTableOfContents" | "getLandmarks" | "getPageList" | "resolveHref" | "readFileContents" | "readItemContents" | "readXhtmlItemContents" | "getItemArchiveLength" | "discardAndClose"> & Disposable;
144
+ /**
145
+ * Readonly Epub-instance backed by an in-memory zip handle
146
+ * Returned by `Epub.using(MemoryAdapter).from(...)`
147
+ */
148
+ type InMemoryEpubReader = EpubReader & {
149
+ readonly storage: "in-memory";
150
+ };
129
151
  declare class EpubVersionError extends Error {
130
152
  }
153
+ declare class EpubReadOnlyError extends Error {
154
+ }
131
155
  /**
132
156
  * A single EPUB instance.
133
157
  *
@@ -156,8 +180,10 @@ declare class EpubVersionError extends Error {
156
180
  * @link https://www.w3.org/TR/epub-33/
157
181
  */
158
182
  declare class Epub {
159
- protected extractPath: string;
183
+ protected adapterClass: EpubStorageAdapterClass;
184
+ protected adapter: EpubStorageAdapter;
160
185
  protected inputPath: string | undefined;
186
+ protected readonlyOverride: boolean;
161
187
  static xmlParser: XMLParser;
162
188
  static xhtmlParser: XMLParser;
163
189
  static xmlBuilder: XMLBuilder;
@@ -229,34 +255,78 @@ declare class Epub {
229
255
  private manifest;
230
256
  private spine;
231
257
  private packageMutex;
232
- protected constructor(extractPath: string, inputPath: string | undefined);
233
258
  /**
234
- * Construct an Epub instance, optionally beginning
235
- * with the provided metadata.
259
+ * Storage backend kind in use for this instance
260
+ *
261
+ * Public so callers can declare type-level requirements via {@link InMemoryEpubReader}
262
+ * Orthogonal to the read-only / writable axis (controlled by `readonlyOverride`
263
+ * and the adapter's capability bag)
264
+ */
265
+ readonly storage: EpubStorageKind;
266
+ /**
267
+ * Prefer the static factories ({@link Epub.using}, {@link Epub.from},
268
+ * {@link Epub.create}, {@link Epub.upgrade}) over calling this constructor
269
+ * directly. It's public so {@link EpubFactory} can construct instances; nothing
270
+ * else should need to.
271
+ */
272
+ constructor(adapterClass: EpubStorageAdapterClass, adapter: EpubStorageAdapter, inputPath: string | undefined, readonlyOverride?: boolean);
273
+ /**
274
+ * Runtime guard for mutation methods
275
+ */
276
+ private assertWritable;
277
+ /**
278
+ * Construct a new EPUB on a writable backend, optionally seeded
279
+ * with the provided metadata. Equivalent to
280
+ * `Epub.using(TmpFsAdapter).create(...)`.
236
281
  *
237
282
  * @param dublinCore Core metadata terms
238
283
  * @param additionalMetadata An array of additional metadata entries
239
284
  */
240
- static create(path: string, { title, language, identifier, date, subjects, type, creators, contributors, }: DublinCore, additionalMetadata?: EpubMetadata): Promise<Epub>;
285
+ static create(path: string, dublinCore: DublinCore, additionalMetadata?: EpubMetadata): Promise<Epub>;
241
286
  /**
242
- * Construct an Epub instance by reading an existing EPUB
243
- * publication.
287
+ * Specify the storage backend to use for the EPUB
288
+ *
289
+ * The returned factory exposes `from`, `create`, and `upgrade`,
290
+ * which route through the supplied adapter.
244
291
  *
245
- * @param pathOrData Must be either a string representing the
246
- * path to an EPUB file on disk, or a Uint8Array representing
247
- * the data of the EPUB publication.
292
+ * @example
293
+ * ```ts
294
+ * using epub = await Epub.using(TmpFsAdapter).from(path)
295
+ * using reader = await Epub.using(MemoryAdapter).from(buffer, { cache: false })
296
+ * ```
248
297
  */
249
- static from(pathOrData: string | Uint8Array): Promise<Epub>;
298
+ static using<A extends EpubStorageAdapterClass>(adapterClass: A): EpubFactory<A>;
250
299
  /**
251
- * Open an EPUB publication and return an Epub instance.
300
+ * Open an existing EPUB publication, extracting it to a temp directory
301
+ * so writes can mutate the unpacked tree and rezip with `saveAndClose`.
302
+ *
303
+ * Pass `{ readonly: true }` to gate mutations at runtime.
304
+ *
305
+ * prefer `Epub.using(TmpFsAdapter).from(path)` (or
306
+ * `Epub.using(MemoryAdapter).from(path)` for read-only, in-memory access)
307
+ * @throws {EpubVersionError} when the archive is not a valid EPUB 3
252
308
  */
253
- private static open;
309
+ static from(pathOrData: string | Uint8Array): Promise<Epub>;
310
+ static from(pathOrData: string | Uint8Array, options: FromOptions & {
311
+ readonly: true;
312
+ }): Promise<EpubReader>;
313
+ static from(pathOrData: string | Uint8Array, options?: FromOptions): Promise<Epub | EpubReader>;
314
+ static assertEpub3(epub: Epub): Promise<void>;
254
315
  copy(path?: string): Promise<Epub>;
255
316
  private removeEntry;
317
+ /**
318
+ * Read raw bytes (or utf-8 text) from the underlying adapter
319
+ */
256
320
  private getFileData;
321
+ /**
322
+ * Length of the underlying archive entry for a manifest item, in bytes
323
+ * Necessary to compute the readium page count which is for COMPRESSED content
324
+ * @see {@link https://github.com/readium/architecture/issues/123}
325
+ */
326
+ getItemArchiveLength(id: string): Promise<number>;
257
327
  getRootfile(): Promise<string>;
258
328
  private getPackageDocument;
259
- private getPackageElement;
329
+ getPackageElement(): Promise<XmlElement<"package">>;
260
330
  /**
261
331
  * Safely modify the package document, without race conditions.
262
332
  *
@@ -269,7 +339,7 @@ declare class Epub {
269
339
  * it returns a new package document, that will be persisted, otherwise
270
340
  * it will be assumed that the package document was modified in place.
271
341
  */
272
- private withPackage;
342
+ withPackage(producer: ((packageElement: PackageElement) => void) | ((packageElement: PackageElement) => PackageElement) | ((packageElement: PackageElement) => Promise<PackageElement>) | ((packageElement: PackageElement) => Promise<void>)): Promise<void>;
273
343
  /**
274
344
  * Retrieve the manifest for the Epub.
275
345
  *
@@ -891,7 +961,55 @@ declare class Epub {
891
961
  */
892
962
  saveAndClose(): Promise<void>;
893
963
  /**
894
- * Upgrade an EPUB 2 publication to EPUB 3 in place, returning a new, valid Epub 3 instance.
964
+ * Upgrade an EPUB 2 publication to EPUB 3 in place, returning a new,
965
+ * valid Epub 3 instance. Equivalent to
966
+ * `Epub.using(TmpFsAdapter).upgrade(...)`.
967
+ */
968
+ static upgrade(path: string, options?: Epub2UpgradeOptions): Promise<Epub>;
969
+ [Symbol.dispose](): void;
970
+ }
971
+ /**
972
+ * Resolves to {@link Epub} for writable adapters, {@link EpubReader} for read-only ones.
973
+ *
974
+ * The conditional pivots on `capabilities.writable`, which must be a literal
975
+ * `true`/`false` on the adapter class (use `as const`) for inference to work.
976
+ */
977
+ type EpubInstanceFor<A extends EpubStorageAdapterClass> = A["capabilities"]["writable"] extends true ? Epub : EpubReader;
978
+ /**
979
+ * Adapter-bound factory returned by {@link Epub.using}.
980
+ *
981
+ * Mirrors the static factory surface (`from`, `create`, `upgrade`) but routes
982
+ * all I/O through the supplied adapter. Each method's signature degrades
983
+ * gracefully when the adapter doesn't support the operation: `create` and
984
+ * `upgrade` throw at runtime if the adapter is read-only or lacks `initEmpty`.
985
+ */
986
+ declare class EpubFactory<A extends EpubStorageAdapterClass> {
987
+ readonly adapterClass: A;
988
+ constructor(adapterClass: A);
989
+ /**
990
+ * Open an existing EPUB through this factory's adapter
991
+ *
992
+ * @throws {EpubVersionError} when the archive is not a valid EPUB 3
993
+ */
994
+ from(source: string | Uint8Array, options: FromOptions & {
995
+ readonly: true;
996
+ } & AdapterOptions<A>): Promise<EpubReader & {
997
+ storage: A["kind"];
998
+ }>;
999
+ from(source: string | Uint8Array, options?: FromOptions & AdapterOptions<A>): Promise<EpubInstanceFor<A> & {
1000
+ storage: A["kind"];
1001
+ }>;
1002
+ /**
1003
+ * Construct a new EPUB on this factory's adapter, optionally seeded
1004
+ * with the provided metadata. Requires a writable adapter that
1005
+ * implements `initEmpty` (today: {@link TmpFsAdapter}).
1006
+ *
1007
+ * @throws when the adapter is read-only or does not implement initEmpty
1008
+ */
1009
+ create(path: string, { title, language, identifier, date, subjects, type, creators, contributors, }: DublinCore, additionalMetadata?: EpubMetadata): Promise<EpubInstanceFor<A>>;
1010
+ /**
1011
+ * Upgrade an EPUB 2 publication to EPUB 3 in place using this
1012
+ * factory's adapter, returning a new, valid Epub 3 instance.
895
1013
  *
896
1014
  * Performs the following transformations:
897
1015
  * - upgrades OPF metadata to EPUB 3 conventions
@@ -901,9 +1019,14 @@ declare class Epub {
901
1019
  * - fixes common font MIME types
902
1020
  * - bumps the package version to 3.0
903
1021
  * - goes over each xhtml item and rewrites it using XMLParser to make sure the output is valid XHTML
1022
+ *
1023
+ * Requires a writable adapter. When {@link Upgrade.Epub2UpgradeOptions.outputPath}
1024
+ * is set, the source file is copied to that path on disk first; this
1025
+ * only makes sense for adapters whose `source` is a real fs path.
1026
+ *
1027
+ * @throws when the adapter is read-only
904
1028
  */
905
- static upgrade(path: string, options?: Epub2UpgradeOptions): Promise<Epub>;
906
- [Symbol.dispose](): void;
1029
+ upgrade(path: string, options?: Epub2UpgradeOptions): Promise<EpubInstanceFor<A>>;
907
1030
  }
908
1031
 
909
- export { type AlternateScript as A, type Collection as C, type DcSubject as D, type ElementName as E, type Epub2UpgradeOptions, 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 DcCreator as e, extractGuideLandmarks, type DublinCore as f, fixFontMimeTypes, type NavigationList as g, type Navigation as h, type PackageElement as i, EpubVersionError as j, Epub as k, removeGuide, removeInvalidDcAttrs, removeNcx, removeSpineTocRef, setLastModified, setPackageVersion, upgradeAuthors, upgradeCover, upgradeDate, upgradeIdentifiers, upgradeLanguages, upgradeMeta, upgradePackageMetadata, upgradeTitle };
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 DcCreator as e, extractGuideLandmarks, type DublinCore as f, fixFontMimeTypes, type NavigationList as g, type Navigation as h, type PackageElement as i, type EpubReader as j, EpubVersionError as k, EpubReadOnlyError as l, Epub as m, type EpubInstanceFor as n, EpubFactory as o, 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.5.1",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -47,6 +47,7 @@
47
47
  "typescript": "^5.9.2"
48
48
  },
49
49
  "dependencies": {
50
+ "@readium/shared": "^2.2.0",
50
51
  "@storyteller-platform/fs": "^0.1.4",
51
52
  "@storyteller-platform/path": "^0.1.2",
52
53
  "@zip.js/zip.js": "^2.0.0",