@storyteller-platform/align 0.1.26 → 0.1.28

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.
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var manifest_exports = {};
30
+ __export(manifest_exports, {
31
+ generateManifest: () => generateManifest
32
+ });
33
+ module.exports = __toCommonJS(manifest_exports);
34
+ var import_shared = require("@readium/shared");
35
+ var import_smil_clockvalue = __toESM(require("smil-clockvalue"), 1);
36
+ async function generateManifest(epub) {
37
+ const primaryLocale = await epub.getLanguage() ?? new Intl.Locale("en-US");
38
+ const creators = await epub.getCreators();
39
+ const authors = creators.filter((contributor) => contributor.role === "aut").map((author) => createContributor(author, primaryLocale));
40
+ const artists = creators.filter((contributor) => contributor.role === "art").map((author) => createContributor(author, primaryLocale));
41
+ const colorists = creators.filter((contributor) => contributor.role === "clr").map((author) => createContributor(author, primaryLocale));
42
+ const contributors = (await epub.getContributors()).map(
43
+ (author) => createContributor(author, primaryLocale)
44
+ );
45
+ const editors = creators.filter((contributor) => contributor.role === "clr").map((author) => createContributor(author, primaryLocale));
46
+ const illustrators = creators.filter((contributor) => contributor.role === "ill").map((author) => createContributor(author, primaryLocale));
47
+ const inkers = creators.filter((contributor) => contributor.role === "ink").map((author) => createContributor(author, primaryLocale));
48
+ const letterers = creators.filter((contributor) => contributor.role === "ltr").map((author) => createContributor(author, primaryLocale));
49
+ const narrators = creators.filter((contributor) => contributor.role === "nrt").map((author) => createContributor(author, primaryLocale));
50
+ const pencilers = creators.filter((contributor) => contributor.role === "pnc").map((author) => createContributor(author, primaryLocale));
51
+ const translators = creators.filter((contributor) => contributor.role === "trl").map((author) => createContributor(author, primaryLocale));
52
+ const publishers = creators.filter((contributor) => contributor.role === "pbl").map((author) => createContributor(author, primaryLocale));
53
+ const dcSubjects = await epub.getSubjects();
54
+ const subjects = dcSubjects.map((subject) => {
55
+ if (typeof subject === "string") {
56
+ return new import_shared.Subject({ name: new import_shared.LocalizedString(subject) });
57
+ }
58
+ return new import_shared.Subject({
59
+ name: new import_shared.LocalizedString(subject.value),
60
+ scheme: subject.authority,
61
+ code: subject.term
62
+ });
63
+ });
64
+ const collections = await epub.getCollections();
65
+ const belongsToCollections = collections.filter((collection) => collection.type === "set").map(
66
+ (collection) => new import_shared.Contributor({ name: new import_shared.LocalizedString(collection.name) })
67
+ );
68
+ const belongsToSeries = collections.filter((collection) => collection.type === "series").map(
69
+ (collection) => new import_shared.Contributor({
70
+ name: new import_shared.LocalizedString(collection.name),
71
+ ...collection.position !== void 0 && {
72
+ position: parseFloat(collection.position)
73
+ }
74
+ })
75
+ );
76
+ const title = await epub.getTitle();
77
+ const identifier = await epub.getIdentifier();
78
+ const subtitle = await epub.getSubtitle();
79
+ const description = await epub.getDescription();
80
+ const published = await epub.getPublicationDate();
81
+ const modified = await epub.getModifiedDate();
82
+ const layout = await epub.getLayout();
83
+ const dir = await epub.getBaseDirection();
84
+ const epubMetadata = await epub.getMetadata();
85
+ const vocab = await epub.getPackageVocabularyPrefixes();
86
+ const duration = epubMetadata.find(
87
+ ({ properties }) => properties["property"] === "media:duration"
88
+ )?.value;
89
+ const otherMetadata = epubMetadata.filter(
90
+ (meta) => (meta.properties["property"]?.split(":")[0] ?? "") in vocab
91
+ ).map((meta) => {
92
+ const [prefix, property] = meta.properties["property"].split(":");
93
+ const scheme = vocab[prefix];
94
+ return [`${scheme}#${property}`, meta.value];
95
+ });
96
+ const metadata = new import_shared.Metadata({
97
+ title: new import_shared.LocalizedString(title ?? ""),
98
+ conformsTo: [import_shared.Profile.EPUB],
99
+ ...identifier && { identifier },
100
+ ...subtitle && { subtitle: new import_shared.LocalizedString(subtitle) },
101
+ authors: new import_shared.Contributors(authors),
102
+ artists: new import_shared.Contributors(artists),
103
+ colorists: new import_shared.Contributors(colorists),
104
+ contributors: new import_shared.Contributors(contributors),
105
+ editors: new import_shared.Contributors(editors),
106
+ illustrators: new import_shared.Contributors(illustrators),
107
+ inkers: new import_shared.Contributors(inkers),
108
+ letterers: new import_shared.Contributors(letterers),
109
+ narrators: new import_shared.Contributors(narrators),
110
+ pencilers: new import_shared.Contributors(pencilers),
111
+ translators: new import_shared.Contributors(translators),
112
+ publishers: new import_shared.Contributors(publishers),
113
+ languages: [primaryLocale.toString()],
114
+ ...description && { description },
115
+ ...published && { published },
116
+ ...modified && { modified },
117
+ subjects: new import_shared.Subjects(subjects),
118
+ belongsToCollections: new import_shared.Contributors(belongsToCollections),
119
+ belongsToSeries: new import_shared.Contributors(belongsToSeries),
120
+ layout: layout === "reflowable" ? import_shared.Layout.reflowable : import_shared.Layout.fixed,
121
+ ...dir !== "auto" && {
122
+ readingProgression: dir === "ltr" ? import_shared.ReadingProgression.ltr : import_shared.ReadingProgression.rtl
123
+ },
124
+ // TODO: is this meant to be in milliseconds (as here) or seconds?
125
+ ...duration !== void 0 && { duration: (0, import_smil_clockvalue.default)(duration) },
126
+ otherMetadata: Object.fromEntries(otherMetadata)
127
+ });
128
+ const spine = await epub.getSpineItems();
129
+ const epubManifest = await epub.getManifest();
130
+ const readingOrder = await Promise.all(
131
+ spine.map(async (item) => {
132
+ const link = new import_shared.Link({
133
+ href: await epub.resolveHref(item.href, void 0, { toRoot: true }),
134
+ ...item.mediaType && { type: item.mediaType }
135
+ });
136
+ const manifestItem = epubManifest[item.id];
137
+ if (!manifestItem) return link;
138
+ if (!manifestItem.mediaOverlay) return link;
139
+ const mediaOverlayItem = epubManifest[manifestItem.mediaOverlay];
140
+ if (!mediaOverlayItem) return link;
141
+ return new import_shared.Link({
142
+ href: link.href,
143
+ type: link.mediaType.string,
144
+ alternates: new import_shared.Links([
145
+ new import_shared.Link({
146
+ href: `GND/${mediaOverlayItem.id}.json`,
147
+ type: "application/guided-navigation+json"
148
+ })
149
+ ])
150
+ });
151
+ })
152
+ );
153
+ const coverItem = await epub.getCoverImageItem();
154
+ const resources = await Promise.all(
155
+ Object.values(epubManifest).map(async (item) => {
156
+ const rels = /* @__PURE__ */ new Set();
157
+ if (item.id === coverItem?.id) {
158
+ rels.add("cover");
159
+ }
160
+ if (item.mediaType === "application/xhtml+xml") {
161
+ rels.add("content");
162
+ }
163
+ const otherMetadata2 = epubMetadata.filter((meta) => meta.properties["refines"] === `#${item.id}`).filter(
164
+ (meta) => (meta.properties["property"]?.split(":")[0] ?? "") in vocab
165
+ ).map((meta) => {
166
+ const prefix = meta.properties["property"].split(":")[0];
167
+ const scheme = vocab[prefix];
168
+ return [scheme, meta.value];
169
+ });
170
+ const link = new import_shared.Link({
171
+ href: await epub.resolveHref(item.href, void 0, { toRoot: true }),
172
+ ...item.mediaType && { type: item.mediaType },
173
+ rels,
174
+ properties: new import_shared.Properties(Object.fromEntries(otherMetadata2))
175
+ });
176
+ if (!item.mediaOverlay) return link;
177
+ const mediaOverlayItem = epubManifest[item.id];
178
+ if (!mediaOverlayItem) return link;
179
+ const refinedBy = epubMetadata.find(
180
+ ({ properties }) => properties["property"] === "media:duration" && properties["refines"] === `#${mediaOverlayItem.id}`
181
+ );
182
+ if (!refinedBy?.value) return link;
183
+ const duration2 = (0, import_smil_clockvalue.default)(refinedBy.value);
184
+ return new import_shared.Link({
185
+ href: link.href,
186
+ type: link.mediaType.string,
187
+ ...link.properties && { properties: link.properties },
188
+ duration: duration2
189
+ });
190
+ })
191
+ );
192
+ const epubToc = await epub.getTableOfContents({ resolveToRoot: true });
193
+ const toc = epubToc && createLinkTree(epubToc.children);
194
+ const epubLandmarks = await epub.getLandmarks({ resolveToRoot: true });
195
+ const landmarks = epubLandmarks && createLinkTree(epubLandmarks.children);
196
+ const epubPageList = await epub.getPageList({ resolveToRoot: true });
197
+ const pageList = epubPageList && createLinkTree(epubPageList.children);
198
+ const subcollections = /* @__PURE__ */ new Map();
199
+ if (landmarks) {
200
+ subcollections.set("landmarks", [
201
+ new import_shared.PublicationCollection({
202
+ links: new import_shared.Links(landmarks)
203
+ })
204
+ ]);
205
+ }
206
+ if (pageList) {
207
+ subcollections.set("pageList", [
208
+ new import_shared.PublicationCollection({
209
+ links: new import_shared.Links(pageList)
210
+ })
211
+ ]);
212
+ }
213
+ return new import_shared.Manifest({
214
+ context: ["https://readium.org/webpub-manifest/context.jsonld"],
215
+ metadata,
216
+ readingOrder: new import_shared.Links(readingOrder),
217
+ resources: new import_shared.Links(resources),
218
+ links: new import_shared.Links([
219
+ new import_shared.Link({
220
+ href: "manifest.json",
221
+ type: "application/webpub+json",
222
+ rels: /* @__PURE__ */ new Set(["self"])
223
+ })
224
+ ]),
225
+ ...toc && { toc: new import_shared.Links(toc) },
226
+ subcollections
227
+ });
228
+ }
229
+ function createContributor(dcCreator, primaryLocale) {
230
+ return new import_shared.Contributor({
231
+ name: new import_shared.LocalizedString(
232
+ Object.fromEntries([
233
+ [primaryLocale.toString(), dcCreator.name],
234
+ ...dcCreator.alternateScripts?.map((alt) => [
235
+ alt.locale.toString(),
236
+ alt.name
237
+ ]) ?? []
238
+ ])
239
+ ),
240
+ ...dcCreator.role && { roles: /* @__PURE__ */ new Set([dcCreator.role]) },
241
+ ...dcCreator.fileAs !== void 0 && {
242
+ sortAs: new import_shared.LocalizedString(dcCreator.fileAs)
243
+ }
244
+ });
245
+ }
246
+ function createLinkTree(navList) {
247
+ return navList.map(
248
+ (navItem) => new import_shared.Link({
249
+ title: navItem.title,
250
+ href: navItem.href ?? "#",
251
+ ...navItem.children && {
252
+ children: new import_shared.Links(createLinkTree(navItem.children))
253
+ }
254
+ })
255
+ );
256
+ }
257
+ // Annotate the CommonJS export names for ESM import in node:
258
+ 0 && (module.exports = {
259
+ generateManifest
260
+ });
@@ -0,0 +1,6 @@
1
+ import { Manifest } from '@readium/shared';
2
+ import { Epub } from '@storyteller-platform/epub';
3
+
4
+ declare function generateManifest(epub: Epub): Promise<Manifest>;
5
+
6
+ export { generateManifest };
@@ -0,0 +1,6 @@
1
+ import { Manifest } from '@readium/shared';
2
+ import { Epub } from '@storyteller-platform/epub';
3
+
4
+ declare function generateManifest(epub: Epub): Promise<Manifest>;
5
+
6
+ export { generateManifest };
@@ -0,0 +1,242 @@
1
+ import "../chunk-BIEQXUOY.js";
2
+ import {
3
+ Contributor,
4
+ Contributors,
5
+ Layout,
6
+ Link,
7
+ Links,
8
+ LocalizedString,
9
+ Manifest,
10
+ Metadata,
11
+ Profile,
12
+ Properties,
13
+ PublicationCollection,
14
+ ReadingProgression,
15
+ Subject,
16
+ Subjects
17
+ } from "@readium/shared";
18
+ import clockvalue from "smil-clockvalue";
19
+ async function generateManifest(epub) {
20
+ const primaryLocale = await epub.getLanguage() ?? new Intl.Locale("en-US");
21
+ const creators = await epub.getCreators();
22
+ const authors = creators.filter((contributor) => contributor.role === "aut").map((author) => createContributor(author, primaryLocale));
23
+ const artists = creators.filter((contributor) => contributor.role === "art").map((author) => createContributor(author, primaryLocale));
24
+ const colorists = creators.filter((contributor) => contributor.role === "clr").map((author) => createContributor(author, primaryLocale));
25
+ const contributors = (await epub.getContributors()).map(
26
+ (author) => createContributor(author, primaryLocale)
27
+ );
28
+ const editors = creators.filter((contributor) => contributor.role === "clr").map((author) => createContributor(author, primaryLocale));
29
+ const illustrators = creators.filter((contributor) => contributor.role === "ill").map((author) => createContributor(author, primaryLocale));
30
+ const inkers = creators.filter((contributor) => contributor.role === "ink").map((author) => createContributor(author, primaryLocale));
31
+ const letterers = creators.filter((contributor) => contributor.role === "ltr").map((author) => createContributor(author, primaryLocale));
32
+ const narrators = creators.filter((contributor) => contributor.role === "nrt").map((author) => createContributor(author, primaryLocale));
33
+ const pencilers = creators.filter((contributor) => contributor.role === "pnc").map((author) => createContributor(author, primaryLocale));
34
+ const translators = creators.filter((contributor) => contributor.role === "trl").map((author) => createContributor(author, primaryLocale));
35
+ const publishers = creators.filter((contributor) => contributor.role === "pbl").map((author) => createContributor(author, primaryLocale));
36
+ const dcSubjects = await epub.getSubjects();
37
+ const subjects = dcSubjects.map((subject) => {
38
+ if (typeof subject === "string") {
39
+ return new Subject({ name: new LocalizedString(subject) });
40
+ }
41
+ return new Subject({
42
+ name: new LocalizedString(subject.value),
43
+ scheme: subject.authority,
44
+ code: subject.term
45
+ });
46
+ });
47
+ const collections = await epub.getCollections();
48
+ const belongsToCollections = collections.filter((collection) => collection.type === "set").map(
49
+ (collection) => new Contributor({ name: new LocalizedString(collection.name) })
50
+ );
51
+ const belongsToSeries = collections.filter((collection) => collection.type === "series").map(
52
+ (collection) => new Contributor({
53
+ name: new LocalizedString(collection.name),
54
+ ...collection.position !== void 0 && {
55
+ position: parseFloat(collection.position)
56
+ }
57
+ })
58
+ );
59
+ const title = await epub.getTitle();
60
+ const identifier = await epub.getIdentifier();
61
+ const subtitle = await epub.getSubtitle();
62
+ const description = await epub.getDescription();
63
+ const published = await epub.getPublicationDate();
64
+ const modified = await epub.getModifiedDate();
65
+ const layout = await epub.getLayout();
66
+ const dir = await epub.getBaseDirection();
67
+ const epubMetadata = await epub.getMetadata();
68
+ const vocab = await epub.getPackageVocabularyPrefixes();
69
+ const duration = epubMetadata.find(
70
+ ({ properties }) => properties["property"] === "media:duration"
71
+ )?.value;
72
+ const otherMetadata = epubMetadata.filter(
73
+ (meta) => (meta.properties["property"]?.split(":")[0] ?? "") in vocab
74
+ ).map((meta) => {
75
+ const [prefix, property] = meta.properties["property"].split(":");
76
+ const scheme = vocab[prefix];
77
+ return [`${scheme}#${property}`, meta.value];
78
+ });
79
+ const metadata = new Metadata({
80
+ title: new LocalizedString(title ?? ""),
81
+ conformsTo: [Profile.EPUB],
82
+ ...identifier && { identifier },
83
+ ...subtitle && { subtitle: new LocalizedString(subtitle) },
84
+ authors: new Contributors(authors),
85
+ artists: new Contributors(artists),
86
+ colorists: new Contributors(colorists),
87
+ contributors: new Contributors(contributors),
88
+ editors: new Contributors(editors),
89
+ illustrators: new Contributors(illustrators),
90
+ inkers: new Contributors(inkers),
91
+ letterers: new Contributors(letterers),
92
+ narrators: new Contributors(narrators),
93
+ pencilers: new Contributors(pencilers),
94
+ translators: new Contributors(translators),
95
+ publishers: new Contributors(publishers),
96
+ languages: [primaryLocale.toString()],
97
+ ...description && { description },
98
+ ...published && { published },
99
+ ...modified && { modified },
100
+ subjects: new Subjects(subjects),
101
+ belongsToCollections: new Contributors(belongsToCollections),
102
+ belongsToSeries: new Contributors(belongsToSeries),
103
+ layout: layout === "reflowable" ? Layout.reflowable : Layout.fixed,
104
+ ...dir !== "auto" && {
105
+ readingProgression: dir === "ltr" ? ReadingProgression.ltr : ReadingProgression.rtl
106
+ },
107
+ // TODO: is this meant to be in milliseconds (as here) or seconds?
108
+ ...duration !== void 0 && { duration: clockvalue(duration) },
109
+ otherMetadata: Object.fromEntries(otherMetadata)
110
+ });
111
+ const spine = await epub.getSpineItems();
112
+ const epubManifest = await epub.getManifest();
113
+ const readingOrder = await Promise.all(
114
+ spine.map(async (item) => {
115
+ const link = new Link({
116
+ href: await epub.resolveHref(item.href, void 0, { toRoot: true }),
117
+ ...item.mediaType && { type: item.mediaType }
118
+ });
119
+ const manifestItem = epubManifest[item.id];
120
+ if (!manifestItem) return link;
121
+ if (!manifestItem.mediaOverlay) return link;
122
+ const mediaOverlayItem = epubManifest[manifestItem.mediaOverlay];
123
+ if (!mediaOverlayItem) return link;
124
+ return new Link({
125
+ href: link.href,
126
+ type: link.mediaType.string,
127
+ alternates: new Links([
128
+ new Link({
129
+ href: `GND/${mediaOverlayItem.id}.json`,
130
+ type: "application/guided-navigation+json"
131
+ })
132
+ ])
133
+ });
134
+ })
135
+ );
136
+ const coverItem = await epub.getCoverImageItem();
137
+ const resources = await Promise.all(
138
+ Object.values(epubManifest).map(async (item) => {
139
+ const rels = /* @__PURE__ */ new Set();
140
+ if (item.id === coverItem?.id) {
141
+ rels.add("cover");
142
+ }
143
+ if (item.mediaType === "application/xhtml+xml") {
144
+ rels.add("content");
145
+ }
146
+ const otherMetadata2 = epubMetadata.filter((meta) => meta.properties["refines"] === `#${item.id}`).filter(
147
+ (meta) => (meta.properties["property"]?.split(":")[0] ?? "") in vocab
148
+ ).map((meta) => {
149
+ const prefix = meta.properties["property"].split(":")[0];
150
+ const scheme = vocab[prefix];
151
+ return [scheme, meta.value];
152
+ });
153
+ const link = new Link({
154
+ href: await epub.resolveHref(item.href, void 0, { toRoot: true }),
155
+ ...item.mediaType && { type: item.mediaType },
156
+ rels,
157
+ properties: new Properties(Object.fromEntries(otherMetadata2))
158
+ });
159
+ if (!item.mediaOverlay) return link;
160
+ const mediaOverlayItem = epubManifest[item.id];
161
+ if (!mediaOverlayItem) return link;
162
+ const refinedBy = epubMetadata.find(
163
+ ({ properties }) => properties["property"] === "media:duration" && properties["refines"] === `#${mediaOverlayItem.id}`
164
+ );
165
+ if (!refinedBy?.value) return link;
166
+ const duration2 = clockvalue(refinedBy.value);
167
+ return new Link({
168
+ href: link.href,
169
+ type: link.mediaType.string,
170
+ ...link.properties && { properties: link.properties },
171
+ duration: duration2
172
+ });
173
+ })
174
+ );
175
+ const epubToc = await epub.getTableOfContents({ resolveToRoot: true });
176
+ const toc = epubToc && createLinkTree(epubToc.children);
177
+ const epubLandmarks = await epub.getLandmarks({ resolveToRoot: true });
178
+ const landmarks = epubLandmarks && createLinkTree(epubLandmarks.children);
179
+ const epubPageList = await epub.getPageList({ resolveToRoot: true });
180
+ const pageList = epubPageList && createLinkTree(epubPageList.children);
181
+ const subcollections = /* @__PURE__ */ new Map();
182
+ if (landmarks) {
183
+ subcollections.set("landmarks", [
184
+ new PublicationCollection({
185
+ links: new Links(landmarks)
186
+ })
187
+ ]);
188
+ }
189
+ if (pageList) {
190
+ subcollections.set("pageList", [
191
+ new PublicationCollection({
192
+ links: new Links(pageList)
193
+ })
194
+ ]);
195
+ }
196
+ return new Manifest({
197
+ context: ["https://readium.org/webpub-manifest/context.jsonld"],
198
+ metadata,
199
+ readingOrder: new Links(readingOrder),
200
+ resources: new Links(resources),
201
+ links: new Links([
202
+ new Link({
203
+ href: "manifest.json",
204
+ type: "application/webpub+json",
205
+ rels: /* @__PURE__ */ new Set(["self"])
206
+ })
207
+ ]),
208
+ ...toc && { toc: new Links(toc) },
209
+ subcollections
210
+ });
211
+ }
212
+ function createContributor(dcCreator, primaryLocale) {
213
+ return new Contributor({
214
+ name: new LocalizedString(
215
+ Object.fromEntries([
216
+ [primaryLocale.toString(), dcCreator.name],
217
+ ...dcCreator.alternateScripts?.map((alt) => [
218
+ alt.locale.toString(),
219
+ alt.name
220
+ ]) ?? []
221
+ ])
222
+ ),
223
+ ...dcCreator.role && { roles: /* @__PURE__ */ new Set([dcCreator.role]) },
224
+ ...dcCreator.fileAs !== void 0 && {
225
+ sortAs: new LocalizedString(dcCreator.fileAs)
226
+ }
227
+ });
228
+ }
229
+ function createLinkTree(navList) {
230
+ return navList.map(
231
+ (navItem) => new Link({
232
+ title: navItem.title,
233
+ href: navItem.href ?? "#",
234
+ ...navItem.children && {
235
+ children: new Links(createLinkTree(navItem.children))
236
+ }
237
+ })
238
+ );
239
+ }
240
+ export {
241
+ generateManifest
242
+ };
@@ -127,7 +127,8 @@ async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef) {
127
127
  });
128
128
  let lastChapterSentence = -1;
129
129
  const chapterSentences = segmentation.filter((s) => s.text.match(/\S/));
130
- for (const par of import_epub.Epub.getXmlChildren(seq)) {
130
+ const pars = findAll("par", import_epub.Epub.getXmlChildren(seq));
131
+ for (const par of pars) {
131
132
  newSnapshot += `
132
133
  `;
133
134
  const text = import_epub.Epub.findXmlChildByName("text", import_epub.Epub.getXmlChildren(par));
@@ -219,6 +220,17 @@ function getTextSentenceIndexByIdFragment(textSrc) {
219
220
  const [fragment, sentenceId] = match;
220
221
  return { fragment, sentenceId: parseInt(sentenceId, 10) };
221
222
  }
223
+ function findAll(name, xml) {
224
+ const result = [];
225
+ for (const child of xml) {
226
+ if (import_epub.Epub.isXmlTextNode(child)) continue;
227
+ if (import_epub.Epub.getXmlElementName(child) === name) {
228
+ result.push(child);
229
+ }
230
+ result.push(...findAll(name, import_epub.Epub.getXmlChildren(child)));
231
+ }
232
+ return result;
233
+ }
222
234
  // Annotate the CommonJS export names for ESM import in node:
223
235
  0 && (module.exports = {
224
236
  createAlignmentSnapshot,
@@ -8,7 +8,9 @@ import {
8
8
  basename as posixBasename,
9
9
  extname as posixExtname
10
10
  } from "node:path/posix";
11
- import { Epub } from "@storyteller-platform/epub";
11
+ import {
12
+ Epub
13
+ } from "@storyteller-platform/epub";
12
14
  import { parseDom } from "../markup/parseDom.js";
13
15
  import { segmentChapter } from "../markup/segmentation.js";
14
16
  import { inlineFootnotes, liftText } from "../markup/transform.js";
@@ -65,7 +67,8 @@ async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef) {
65
67
  });
66
68
  let lastChapterSentence = -1;
67
69
  const chapterSentences = segmentation.filter((s) => s.text.match(/\S/));
68
- for (const par of Epub.getXmlChildren(seq)) {
70
+ const pars = findAll("par", Epub.getXmlChildren(seq));
71
+ for (const par of pars) {
69
72
  newSnapshot += `
70
73
  `;
71
74
  const text = Epub.findXmlChildByName("text", Epub.getXmlChildren(par));
@@ -157,6 +160,17 @@ function getTextSentenceIndexByIdFragment(textSrc) {
157
160
  const [fragment, sentenceId] = match;
158
161
  return { fragment, sentenceId: parseInt(sentenceId, 10) };
159
162
  }
163
+ function findAll(name, xml) {
164
+ const result = [];
165
+ for (const child of xml) {
166
+ if (Epub.isXmlTextNode(child)) continue;
167
+ if (Epub.getXmlElementName(child) === name) {
168
+ result.push(child);
169
+ }
170
+ result.push(...findAll(name, Epub.getXmlChildren(child)));
171
+ }
172
+ return result;
173
+ }
160
174
  export {
161
175
  createAlignmentSnapshot,
162
176
  snapshotAlignment
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,3 @@
1
+ declare module "smil-clockvalue" {
2
+ export default function clockvalue(input: string): number
3
+ }
@@ -0,0 +1,3 @@
1
+ declare module "smil-clockvalue" {
2
+ export default function clockvalue(input: string): number
3
+ }
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyteller-platform/align",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "description": "A library and CLI for automatically aligning audiobooks and EPUBs to produce Media Overlays",
5
5
  "author": "Shane Friedman",
6
6
  "license": "MIT",
@@ -59,13 +59,16 @@
59
59
  "@esfx/async-semaphore": "^1.0.0",
60
60
  "@optique/core": "^0.10.7",
61
61
  "@optique/run": "^0.10.7",
62
+ "@readium/shared": "patch:@readium/shared@npm%3A2.1.5#~/.yarn/patches/@readium-shared-npm-2.1.5-8d6f9d2432.patch",
62
63
  "@storyteller-platform/audiobook": "^0.3.10",
63
- "@storyteller-platform/epub": "^0.4.10",
64
+ "@storyteller-platform/epub": "^0.5.0",
64
65
  "@storyteller-platform/ghost-story": "^0.1.10",
65
66
  "@storyteller-platform/transliteration": "^3.1.2",
66
67
  "chalk": "^5.4.1",
68
+ "change-case": "^5.4.4",
67
69
  "cli-progress": "^3.12.0",
68
70
  "esbuild": "^0.27.3",
71
+ "fastest-levenshtein": "^1.0.16",
69
72
  "itertools": "^2.6.0",
70
73
  "locale-currency": "^1.0.0",
71
74
  "memoize": "^10.2.0",
@@ -73,7 +76,9 @@
73
76
  "pino": "^10.3.1",
74
77
  "pino-pretty": "^13.1.3",
75
78
  "runes2": "^1.1.4",
79
+ "smil-clockvalue": "^0.0.1",
76
80
  "to-words": "^5.3.0",
81
+ "yazl": "^3.3.1",
77
82
  "zod": "^4.3.6"
78
83
  },
79
84
  "devDependencies": {
@@ -82,6 +87,7 @@
82
87
  "@tsconfig/strictest": "^2.0.5",
83
88
  "@types/cli-progress": "^3",
84
89
  "@types/node": "^24.0.0",
90
+ "@types/yazl": "^3",
85
91
  "eslint": "^8.0.0",
86
92
  "node-addon-api": "^8.3.1",
87
93
  "node-gyp": "^11.2.0",