@storyteller-platform/align 0.1.53 → 0.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/align/align.cjs +12 -8
- package/dist/align/align.d.cts +1 -1
- package/dist/align/align.d.ts +1 -1
- package/dist/align/align.js +19 -9
- package/dist/align/getSentenceRanges.cjs +3 -2
- package/dist/align/getSentenceRanges.d.cts +1 -1
- package/dist/align/getSentenceRanges.d.ts +1 -1
- package/dist/align/getSentenceRanges.js +3 -2
- package/dist/align/interpolateSentenceRanges.d.cts +1 -1
- package/dist/align/interpolateSentenceRanges.d.ts +1 -1
- package/dist/align/slugify.d.cts +2 -2
- package/dist/align/slugify.d.ts +2 -2
- package/dist/common/shell.cjs +1 -1
- package/dist/common/shell.js +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/markup/markup.cjs +11 -4
- package/dist/markup/markup.js +11 -4
- package/dist/markup/model.cjs +12 -0
- package/dist/markup/model.d.cts +1 -1
- package/dist/markup/model.d.ts +1 -1
- package/dist/markup/model.js +9 -0
- package/dist/markup/parseDom.cjs +9 -0
- package/dist/markup/parseDom.d.cts +1 -1
- package/dist/markup/parseDom.d.ts +1 -1
- package/dist/markup/parseDom.js +12 -0
- package/dist/markup/resolvedPos.d.cts +1 -1
- package/dist/markup/resolvedPos.d.ts +1 -1
- package/dist/markup/serializeDom.d.cts +1 -1
- package/dist/markup/serializeDom.d.ts +1 -1
- package/dist/markup/transform.cjs +23 -45
- package/dist/markup/transform.d.cts +2 -2
- package/dist/markup/transform.d.ts +2 -2
- package/dist/markup/transform.js +23 -43
- package/dist/{model-Bv3yPEdd.d.cts → model-CZ2mMHJO.d.cts} +7 -1
- package/dist/{model-Bv3yPEdd.d.ts → model-CZ2mMHJO.d.ts} +7 -1
- package/dist/readium/manifest.cjs +1 -1
- package/dist/readium/manifest.js +1 -1
- package/dist/snapshot/snapshot.cjs +6 -4
- package/dist/snapshot/snapshot.d.cts +1 -1
- package/dist/snapshot/snapshot.d.ts +1 -1
- package/dist/snapshot/snapshot.js +6 -4
- package/package.json +5 -4
- package/dist/markup/map.cjs +0 -261
- package/dist/markup/map.d.cts +0 -50
- package/dist/markup/map.d.ts +0 -50
- package/dist/markup/map.js +0 -236
|
@@ -24,7 +24,7 @@ __export(transform_exports, {
|
|
|
24
24
|
replaceFootnotes: () => replaceFootnotes
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(transform_exports);
|
|
27
|
-
var
|
|
27
|
+
var import_mapping = require("@storyteller-platform/mapping");
|
|
28
28
|
var import_model = require("./model.cjs");
|
|
29
29
|
var import_parseDom = require("./parseDom.cjs");
|
|
30
30
|
function addMark(root, from, to, mark) {
|
|
@@ -53,9 +53,8 @@ function addMarkToNode(node, pos, from, to, mark) {
|
|
|
53
53
|
return node.copy({ children });
|
|
54
54
|
}
|
|
55
55
|
function liftText(root) {
|
|
56
|
-
const mapping = new
|
|
56
|
+
const mapping = new import_mapping.Mapping();
|
|
57
57
|
let text = "";
|
|
58
|
-
let textLength = 0;
|
|
59
58
|
let lastTextEnd = 0;
|
|
60
59
|
(0, import_model.descendants)(root, (node, pos, parent, index) => {
|
|
61
60
|
if (node instanceof import_model.FootnoteNode) {
|
|
@@ -70,89 +69,68 @@ function liftText(root) {
|
|
|
70
69
|
if (node.isLeaf && parent.isBlock && index === parent.children.length - 1 && !text.endsWith("\n")) {
|
|
71
70
|
text += "\n";
|
|
72
71
|
}
|
|
73
|
-
return
|
|
72
|
+
return !(node instanceof import_model.RubyTextNode || node instanceof import_model.RubyParenthesisNode);
|
|
74
73
|
}
|
|
75
|
-
if (
|
|
76
|
-
mapping.
|
|
77
|
-
new import_map.StepMap([
|
|
78
|
-
mapping.map(lastTextEnd),
|
|
79
|
-
mapping.map(pos) - mapping.map(lastTextEnd),
|
|
80
|
-
0
|
|
81
|
-
])
|
|
82
|
-
);
|
|
74
|
+
if (pos - lastTextEnd) {
|
|
75
|
+
mapping.insertMap(lastTextEnd, pos - lastTextEnd, 0);
|
|
83
76
|
}
|
|
84
77
|
let result = node.text.replaceAll(/\n/g, " ");
|
|
85
|
-
if (text.endsWith("\n")) {
|
|
78
|
+
if (text.endsWith("\n") || text === "") {
|
|
86
79
|
const contentStart = result.match(/\S/u)?.index ?? result.length;
|
|
87
80
|
if (contentStart !== 0) {
|
|
88
81
|
result = result.slice(contentStart);
|
|
89
|
-
mapping.
|
|
90
|
-
new import_map.StepMap([mapping.map(lastTextEnd), contentStart, 0])
|
|
91
|
-
);
|
|
82
|
+
mapping.insertMap(pos, contentStart, 0);
|
|
92
83
|
}
|
|
93
84
|
}
|
|
94
85
|
lastTextEnd = pos + node.nodeSize;
|
|
95
86
|
const hasBlockSiblings = parent.children.some((child) => child.isBlock);
|
|
96
87
|
if (hasBlockSiblings && !result.match(/\S/)) {
|
|
97
88
|
if (result.length) {
|
|
98
|
-
mapping.
|
|
89
|
+
mapping.insertMap(pos, result.length, 0);
|
|
99
90
|
}
|
|
100
91
|
result = "";
|
|
101
92
|
}
|
|
102
93
|
if (parent.isBlock && index === parent.children.length - 1 && !(text + result).endsWith("\n")) {
|
|
103
94
|
result += "\n";
|
|
104
|
-
textLength--;
|
|
105
95
|
}
|
|
106
96
|
text += result;
|
|
107
|
-
textLength += result.length;
|
|
108
97
|
return true;
|
|
109
98
|
});
|
|
110
99
|
return { result: text, mapping };
|
|
111
100
|
}
|
|
112
101
|
function inlineFootnotes(root) {
|
|
113
102
|
const footnotePairs = (0, import_parseDom.findFootnotePairs)(root);
|
|
114
|
-
const mapping = new
|
|
103
|
+
const mapping = new import_mapping.Mapping();
|
|
115
104
|
let transformed = root;
|
|
105
|
+
let cursor = mapping.cursor();
|
|
116
106
|
for (const [noterefPos, footnotePos] of footnotePairs.entries()) {
|
|
117
107
|
const noteref = root.resolve(noterefPos).nodeAfter;
|
|
118
108
|
const footnote = root.resolve(footnotePos).nodeAfter;
|
|
119
109
|
if (!noteref || !(footnote instanceof import_model.Node)) continue;
|
|
120
|
-
transformed = transformed.replace(
|
|
121
|
-
mapping.
|
|
122
|
-
|
|
123
|
-
mapping.map(noterefPos),
|
|
124
|
-
noteref.nodeSize,
|
|
125
|
-
footnote.nodeSize
|
|
126
|
-
])
|
|
127
|
-
);
|
|
110
|
+
transformed = transformed.replace(cursor.map(noterefPos), footnote);
|
|
111
|
+
mapping.insertMap(noterefPos, noteref.nodeSize, footnote.nodeSize);
|
|
112
|
+
cursor = mapping.cursor();
|
|
128
113
|
transformed = transformed.replace(
|
|
129
|
-
|
|
114
|
+
cursor.map(footnotePos),
|
|
130
115
|
new import_model.Node(footnote.tagName)
|
|
131
116
|
);
|
|
132
|
-
mapping.
|
|
133
|
-
new import_map.StepMap([mapping.map(footnotePos), footnote.nodeSize, 1])
|
|
134
|
-
);
|
|
117
|
+
mapping.insertMap(footnotePos, footnote.nodeSize, 1);
|
|
135
118
|
}
|
|
136
119
|
return { root: transformed, footnotePairs, mapping };
|
|
137
120
|
}
|
|
138
121
|
function replaceFootnotes(original, root, footnotePairs, mapping) {
|
|
139
122
|
let transformed = root;
|
|
123
|
+
let cursor = mapping.cursor();
|
|
140
124
|
for (const [noterefPos, footnotePos] of footnotePairs.entries()) {
|
|
141
125
|
const noteref = original.resolve(noterefPos).nodeAfter;
|
|
142
|
-
const footnote = transformed.resolve(
|
|
126
|
+
const footnote = transformed.resolve(cursor.map(noterefPos)).nodeAfter;
|
|
143
127
|
if (!(noteref instanceof import_model.Node) || !(footnote instanceof import_model.Node)) continue;
|
|
144
|
-
transformed = transformed.replace(
|
|
145
|
-
mapping.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
])
|
|
151
|
-
);
|
|
152
|
-
transformed = transformed.replace(mapping.map(footnotePos), footnote);
|
|
153
|
-
mapping.appendMap(
|
|
154
|
-
new import_map.StepMap([mapping.map(footnotePos), 1, footnote.nodeSize])
|
|
155
|
-
);
|
|
128
|
+
transformed = transformed.replace(cursor.map(noterefPos), noteref);
|
|
129
|
+
mapping.insertMap(noterefPos, footnote.nodeSize, noteref.nodeSize);
|
|
130
|
+
cursor = mapping.cursor();
|
|
131
|
+
transformed = transformed.replace(cursor.map(footnotePos), footnote);
|
|
132
|
+
mapping.insertMap(footnotePos, 1, footnote.nodeSize);
|
|
133
|
+
cursor = mapping.cursor();
|
|
156
134
|
}
|
|
157
135
|
return transformed;
|
|
158
136
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Mapping } from '
|
|
2
|
-
import { R as Root, M as Mark } from '../model-
|
|
1
|
+
import { Mapping } from '@storyteller-platform/mapping';
|
|
2
|
+
import { R as Root, M as Mark } from '../model-CZ2mMHJO.cjs';
|
|
3
3
|
import '@storyteller-platform/epub';
|
|
4
4
|
|
|
5
5
|
declare function addMark(root: Root, from: number, to: number, mark: Mark): Root;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Mapping } from '
|
|
2
|
-
import { R as Root, M as Mark } from '../model-
|
|
1
|
+
import { Mapping } from '@storyteller-platform/mapping';
|
|
2
|
+
import { R as Root, M as Mark } from '../model-CZ2mMHJO.js';
|
|
3
3
|
import '@storyteller-platform/epub';
|
|
4
4
|
|
|
5
5
|
declare function addMark(root: Root, from: number, to: number, mark: Mark): Root;
|
package/dist/markup/transform.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import "../chunk-BIEQXUOY.js";
|
|
2
|
-
import { Mapping
|
|
2
|
+
import { Mapping } from "@storyteller-platform/mapping";
|
|
3
3
|
import {
|
|
4
4
|
FootnoteNode,
|
|
5
5
|
Node,
|
|
6
|
+
RubyParenthesisNode,
|
|
7
|
+
RubyTextNode,
|
|
6
8
|
TextNode,
|
|
7
9
|
descendants
|
|
8
10
|
} from "./model.js";
|
|
@@ -35,7 +37,6 @@ function addMarkToNode(node, pos, from, to, mark) {
|
|
|
35
37
|
function liftText(root) {
|
|
36
38
|
const mapping = new Mapping();
|
|
37
39
|
let text = "";
|
|
38
|
-
let textLength = 0;
|
|
39
40
|
let lastTextEnd = 0;
|
|
40
41
|
descendants(root, (node, pos, parent, index) => {
|
|
41
42
|
if (node instanceof FootnoteNode) {
|
|
@@ -50,41 +51,31 @@ function liftText(root) {
|
|
|
50
51
|
if (node.isLeaf && parent.isBlock && index === parent.children.length - 1 && !text.endsWith("\n")) {
|
|
51
52
|
text += "\n";
|
|
52
53
|
}
|
|
53
|
-
return
|
|
54
|
+
return !(node instanceof RubyTextNode || node instanceof RubyParenthesisNode);
|
|
54
55
|
}
|
|
55
|
-
if (
|
|
56
|
-
mapping.
|
|
57
|
-
new StepMap([
|
|
58
|
-
mapping.map(lastTextEnd),
|
|
59
|
-
mapping.map(pos) - mapping.map(lastTextEnd),
|
|
60
|
-
0
|
|
61
|
-
])
|
|
62
|
-
);
|
|
56
|
+
if (pos - lastTextEnd) {
|
|
57
|
+
mapping.insertMap(lastTextEnd, pos - lastTextEnd, 0);
|
|
63
58
|
}
|
|
64
59
|
let result = node.text.replaceAll(/\n/g, " ");
|
|
65
|
-
if (text.endsWith("\n")) {
|
|
60
|
+
if (text.endsWith("\n") || text === "") {
|
|
66
61
|
const contentStart = result.match(/\S/u)?.index ?? result.length;
|
|
67
62
|
if (contentStart !== 0) {
|
|
68
63
|
result = result.slice(contentStart);
|
|
69
|
-
mapping.
|
|
70
|
-
new StepMap([mapping.map(lastTextEnd), contentStart, 0])
|
|
71
|
-
);
|
|
64
|
+
mapping.insertMap(pos, contentStart, 0);
|
|
72
65
|
}
|
|
73
66
|
}
|
|
74
67
|
lastTextEnd = pos + node.nodeSize;
|
|
75
68
|
const hasBlockSiblings = parent.children.some((child) => child.isBlock);
|
|
76
69
|
if (hasBlockSiblings && !result.match(/\S/)) {
|
|
77
70
|
if (result.length) {
|
|
78
|
-
mapping.
|
|
71
|
+
mapping.insertMap(pos, result.length, 0);
|
|
79
72
|
}
|
|
80
73
|
result = "";
|
|
81
74
|
}
|
|
82
75
|
if (parent.isBlock && index === parent.children.length - 1 && !(text + result).endsWith("\n")) {
|
|
83
76
|
result += "\n";
|
|
84
|
-
textLength--;
|
|
85
77
|
}
|
|
86
78
|
text += result;
|
|
87
|
-
textLength += result.length;
|
|
88
79
|
return true;
|
|
89
80
|
});
|
|
90
81
|
return { result: text, mapping };
|
|
@@ -93,46 +84,35 @@ function inlineFootnotes(root) {
|
|
|
93
84
|
const footnotePairs = findFootnotePairs(root);
|
|
94
85
|
const mapping = new Mapping();
|
|
95
86
|
let transformed = root;
|
|
87
|
+
let cursor = mapping.cursor();
|
|
96
88
|
for (const [noterefPos, footnotePos] of footnotePairs.entries()) {
|
|
97
89
|
const noteref = root.resolve(noterefPos).nodeAfter;
|
|
98
90
|
const footnote = root.resolve(footnotePos).nodeAfter;
|
|
99
91
|
if (!noteref || !(footnote instanceof Node)) continue;
|
|
100
|
-
transformed = transformed.replace(
|
|
101
|
-
mapping.
|
|
102
|
-
|
|
103
|
-
mapping.map(noterefPos),
|
|
104
|
-
noteref.nodeSize,
|
|
105
|
-
footnote.nodeSize
|
|
106
|
-
])
|
|
107
|
-
);
|
|
92
|
+
transformed = transformed.replace(cursor.map(noterefPos), footnote);
|
|
93
|
+
mapping.insertMap(noterefPos, noteref.nodeSize, footnote.nodeSize);
|
|
94
|
+
cursor = mapping.cursor();
|
|
108
95
|
transformed = transformed.replace(
|
|
109
|
-
|
|
96
|
+
cursor.map(footnotePos),
|
|
110
97
|
new Node(footnote.tagName)
|
|
111
98
|
);
|
|
112
|
-
mapping.
|
|
113
|
-
new StepMap([mapping.map(footnotePos), footnote.nodeSize, 1])
|
|
114
|
-
);
|
|
99
|
+
mapping.insertMap(footnotePos, footnote.nodeSize, 1);
|
|
115
100
|
}
|
|
116
101
|
return { root: transformed, footnotePairs, mapping };
|
|
117
102
|
}
|
|
118
103
|
function replaceFootnotes(original, root, footnotePairs, mapping) {
|
|
119
104
|
let transformed = root;
|
|
105
|
+
let cursor = mapping.cursor();
|
|
120
106
|
for (const [noterefPos, footnotePos] of footnotePairs.entries()) {
|
|
121
107
|
const noteref = original.resolve(noterefPos).nodeAfter;
|
|
122
|
-
const footnote = transformed.resolve(
|
|
108
|
+
const footnote = transformed.resolve(cursor.map(noterefPos)).nodeAfter;
|
|
123
109
|
if (!(noteref instanceof Node) || !(footnote instanceof Node)) continue;
|
|
124
|
-
transformed = transformed.replace(
|
|
125
|
-
mapping.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
])
|
|
131
|
-
);
|
|
132
|
-
transformed = transformed.replace(mapping.map(footnotePos), footnote);
|
|
133
|
-
mapping.appendMap(
|
|
134
|
-
new StepMap([mapping.map(footnotePos), 1, footnote.nodeSize])
|
|
135
|
-
);
|
|
110
|
+
transformed = transformed.replace(cursor.map(noterefPos), noteref);
|
|
111
|
+
mapping.insertMap(noterefPos, footnote.nodeSize, noteref.nodeSize);
|
|
112
|
+
cursor = mapping.cursor();
|
|
113
|
+
transformed = transformed.replace(cursor.map(footnotePos), footnote);
|
|
114
|
+
mapping.insertMap(footnotePos, 1, footnote.nodeSize);
|
|
115
|
+
cursor = mapping.cursor();
|
|
136
116
|
}
|
|
137
117
|
return transformed;
|
|
138
118
|
}
|
|
@@ -68,6 +68,12 @@ declare class NoterefNode extends Node {
|
|
|
68
68
|
}
|
|
69
69
|
declare class FootnoteNode extends Node {
|
|
70
70
|
}
|
|
71
|
+
declare class RubyParenthesisNode extends Node {
|
|
72
|
+
}
|
|
73
|
+
declare class RubyTextNode extends Node {
|
|
74
|
+
}
|
|
75
|
+
declare class RubyNode extends Node {
|
|
76
|
+
}
|
|
71
77
|
declare class Mark {
|
|
72
78
|
tagName: ElementName;
|
|
73
79
|
attrs: Record<string, string>;
|
|
@@ -93,4 +99,4 @@ declare class TextNode {
|
|
|
93
99
|
}
|
|
94
100
|
declare function descendants(node: Root | Node, cb: (node: Node | TextNode, pos: number, parent: Node | Root, index: number) => boolean, pos?: number): void;
|
|
95
101
|
|
|
96
|
-
export { FootnoteNode as F, Mark as M, Node as N, Root as R, TextNode as T, ResolvedPos as a, NoterefNode as b,
|
|
102
|
+
export { FootnoteNode as F, Mark as M, Node as N, Root as R, TextNode as T, ResolvedPos as a, NoterefNode as b, RubyParenthesisNode as c, RubyTextNode as d, RubyNode as e, descendants as f };
|
|
@@ -68,6 +68,12 @@ declare class NoterefNode extends Node {
|
|
|
68
68
|
}
|
|
69
69
|
declare class FootnoteNode extends Node {
|
|
70
70
|
}
|
|
71
|
+
declare class RubyParenthesisNode extends Node {
|
|
72
|
+
}
|
|
73
|
+
declare class RubyTextNode extends Node {
|
|
74
|
+
}
|
|
75
|
+
declare class RubyNode extends Node {
|
|
76
|
+
}
|
|
71
77
|
declare class Mark {
|
|
72
78
|
tagName: ElementName;
|
|
73
79
|
attrs: Record<string, string>;
|
|
@@ -93,4 +99,4 @@ declare class TextNode {
|
|
|
93
99
|
}
|
|
94
100
|
declare function descendants(node: Root | Node, cb: (node: Node | TextNode, pos: number, parent: Node | Root, index: number) => boolean, pos?: number): void;
|
|
95
101
|
|
|
96
|
-
export { FootnoteNode as F, Mark as M, Node as N, Root as R, TextNode as T, ResolvedPos as a, NoterefNode as b,
|
|
102
|
+
export { FootnoteNode as F, Mark as M, Node as N, Root as R, TextNode as T, ResolvedPos as a, NoterefNode as b, RubyParenthesisNode as c, RubyTextNode as d, RubyNode as e, descendants as f };
|
|
@@ -79,7 +79,7 @@ async function generateReadiumManifest(epub, options = {}) {
|
|
|
79
79
|
})
|
|
80
80
|
);
|
|
81
81
|
const title = await epub.getTitle();
|
|
82
|
-
const identifier = await epub.
|
|
82
|
+
const identifier = await epub.getUniqueIdentifier() || (await epub.getIdentifiers())[0]?.value;
|
|
83
83
|
const subtitle = await epub.getSubtitle();
|
|
84
84
|
const description = await epub.getDescription();
|
|
85
85
|
const published = await epub.getPublicationDate();
|
package/dist/readium/manifest.js
CHANGED
|
@@ -62,7 +62,7 @@ async function generateReadiumManifest(epub, options = {}) {
|
|
|
62
62
|
})
|
|
63
63
|
);
|
|
64
64
|
const title = await epub.getTitle();
|
|
65
|
-
const identifier = await epub.
|
|
65
|
+
const identifier = await epub.getUniqueIdentifier() || (await epub.getIdentifiers())[0]?.value;
|
|
66
66
|
const subtitle = await epub.getSubtitle();
|
|
67
67
|
const description = await epub.getDescription();
|
|
68
68
|
const published = await epub.getPublicationDate();
|
|
@@ -72,6 +72,7 @@ var import_node_path = require("node:path");
|
|
|
72
72
|
var import_posix = require("node:path/posix");
|
|
73
73
|
var import_epub = require("@storyteller-platform/epub");
|
|
74
74
|
var import_ghost_story = require("@storyteller-platform/ghost-story");
|
|
75
|
+
var import_slugify = require("../align/slugify.cjs");
|
|
75
76
|
var import_parseDom = require("../markup/parseDom.cjs");
|
|
76
77
|
var import_segmentation = require("../markup/segmentation.cjs");
|
|
77
78
|
var import_transform = require("../markup/transform.cjs");
|
|
@@ -94,8 +95,9 @@ async function snapshotAlignment(epubPath, transcriptionsPath, outputPath) {
|
|
|
94
95
|
__callDispose(_stack, _error, _hasError);
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
|
-
async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef) {
|
|
98
|
+
async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef, transliterate) {
|
|
98
99
|
let newSnapshot = "";
|
|
100
|
+
const locale = await epub.getLanguage() ?? new Intl.Locale("en-US");
|
|
99
101
|
const manifest = await epub.getManifest();
|
|
100
102
|
const mediaOverlayItems = Object.values(manifest).map((item) => item.mediaOverlay).filter((mediaOverlayId) => !!mediaOverlayId).map((id) => manifest[id]);
|
|
101
103
|
const mediaOverlays = [];
|
|
@@ -145,14 +147,14 @@ async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef) {
|
|
|
145
147
|
);
|
|
146
148
|
if (result === null) continue;
|
|
147
149
|
const { fragment, sentenceId } = result;
|
|
148
|
-
const textSentence = chapterSentences[sentenceId]?.text;
|
|
150
|
+
const textSentence = chapterSentences[sentenceId]?.text.replace(/\n/, "");
|
|
149
151
|
if (!textSentence) continue;
|
|
150
152
|
lastChapterSentence = sentenceId;
|
|
151
153
|
if (textRef === "text-fragment") {
|
|
152
154
|
newSnapshot += `${fragment}
|
|
153
155
|
`;
|
|
154
156
|
}
|
|
155
|
-
newSnapshot += `Text: ${
|
|
157
|
+
newSnapshot += `Text: ${transliterate ? (await (0, import_slugify.slugify)(textSentence, locale)).result : textSentence}
|
|
156
158
|
`;
|
|
157
159
|
const audioSrc = audio[":@"]?.["@_src"];
|
|
158
160
|
if (!audioSrc) continue;
|
|
@@ -188,7 +190,7 @@ async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef) {
|
|
|
188
190
|
const transcriptionSentence = transcriptionWords.map(
|
|
189
191
|
(w, idx) => (0, import_ghost_story.startsWithSpacelessScript)(w) || idx === transcriptionWords.length - 1 ? w : `${w} `
|
|
190
192
|
).join("");
|
|
191
|
-
newSnapshot += `Audio: ${transcriptionSentence}
|
|
193
|
+
newSnapshot += `Audio: ${transliterate ? (await (0, import_slugify.slugify)(transcriptionSentence, locale)).result : transcriptionSentence}
|
|
192
194
|
`;
|
|
193
195
|
}
|
|
194
196
|
newSnapshot += `
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Epub } from '@storyteller-platform/epub';
|
|
2
2
|
|
|
3
3
|
declare function snapshotAlignment(epubPath: string, transcriptionsPath: string, outputPath: string): Promise<void>;
|
|
4
|
-
declare function createAlignmentSnapshot(epub: Epub, transcriptionFilepaths: string[], textRef: "id-fragment" | "text-fragment"): Promise<string>;
|
|
4
|
+
declare function createAlignmentSnapshot(epub: Epub, transcriptionFilepaths: string[], textRef: "id-fragment" | "text-fragment", transliterate?: boolean): Promise<string>;
|
|
5
5
|
|
|
6
6
|
export { createAlignmentSnapshot, snapshotAlignment };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Epub } from '@storyteller-platform/epub';
|
|
2
2
|
|
|
3
3
|
declare function snapshotAlignment(epubPath: string, transcriptionsPath: string, outputPath: string): Promise<void>;
|
|
4
|
-
declare function createAlignmentSnapshot(epub: Epub, transcriptionFilepaths: string[], textRef: "id-fragment" | "text-fragment"): Promise<string>;
|
|
4
|
+
declare function createAlignmentSnapshot(epub: Epub, transcriptionFilepaths: string[], textRef: "id-fragment" | "text-fragment", transliterate?: boolean): Promise<string>;
|
|
5
5
|
|
|
6
6
|
export { createAlignmentSnapshot, snapshotAlignment };
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
startsWithSpacelessScript
|
|
16
16
|
} from "@storyteller-platform/ghost-story";
|
|
17
|
+
import { slugify } from "../align/slugify.js";
|
|
17
18
|
import { parseDom } from "../markup/parseDom.js";
|
|
18
19
|
import { segmentChapter } from "../markup/segmentation.js";
|
|
19
20
|
import { inlineFootnotes, liftText } from "../markup/transform.js";
|
|
@@ -36,8 +37,9 @@ async function snapshotAlignment(epubPath, transcriptionsPath, outputPath) {
|
|
|
36
37
|
__callDispose(_stack, _error, _hasError);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef) {
|
|
40
|
+
async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef, transliterate) {
|
|
40
41
|
let newSnapshot = "";
|
|
42
|
+
const locale = await epub.getLanguage() ?? new Intl.Locale("en-US");
|
|
41
43
|
const manifest = await epub.getManifest();
|
|
42
44
|
const mediaOverlayItems = Object.values(manifest).map((item) => item.mediaOverlay).filter((mediaOverlayId) => !!mediaOverlayId).map((id) => manifest[id]);
|
|
43
45
|
const mediaOverlays = [];
|
|
@@ -87,14 +89,14 @@ async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef) {
|
|
|
87
89
|
);
|
|
88
90
|
if (result === null) continue;
|
|
89
91
|
const { fragment, sentenceId } = result;
|
|
90
|
-
const textSentence = chapterSentences[sentenceId]?.text;
|
|
92
|
+
const textSentence = chapterSentences[sentenceId]?.text.replace(/\n/, "");
|
|
91
93
|
if (!textSentence) continue;
|
|
92
94
|
lastChapterSentence = sentenceId;
|
|
93
95
|
if (textRef === "text-fragment") {
|
|
94
96
|
newSnapshot += `${fragment}
|
|
95
97
|
`;
|
|
96
98
|
}
|
|
97
|
-
newSnapshot += `Text: ${textSentence.
|
|
99
|
+
newSnapshot += `Text: ${transliterate ? (await slugify(textSentence, locale)).result : textSentence}
|
|
98
100
|
`;
|
|
99
101
|
const audioSrc = audio[":@"]?.["@_src"];
|
|
100
102
|
if (!audioSrc) continue;
|
|
@@ -130,7 +132,7 @@ async function createAlignmentSnapshot(epub, transcriptionFilepaths, textRef) {
|
|
|
130
132
|
const transcriptionSentence = transcriptionWords.map(
|
|
131
133
|
(w, idx) => startsWithSpacelessScript(w) || idx === transcriptionWords.length - 1 ? w : `${w} `
|
|
132
134
|
).join("");
|
|
133
|
-
newSnapshot += `Audio: ${transcriptionSentence}
|
|
135
|
+
newSnapshot += `Audio: ${transliterate ? (await slugify(transcriptionSentence, locale)).result : transcriptionSentence}
|
|
134
136
|
`;
|
|
135
137
|
}
|
|
136
138
|
newSnapshot += `
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyteller-platform/align",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
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",
|
|
@@ -70,10 +70,11 @@
|
|
|
70
70
|
"@optique/core": "^0.10.7",
|
|
71
71
|
"@optique/run": "^0.10.7",
|
|
72
72
|
"@readium/shared": "^2.2.0",
|
|
73
|
-
"@storyteller-platform/audiobook": "^0.
|
|
74
|
-
"@storyteller-platform/epub": "^0.
|
|
73
|
+
"@storyteller-platform/audiobook": "^0.5.0",
|
|
74
|
+
"@storyteller-platform/epub": "^0.7.0",
|
|
75
75
|
"@storyteller-platform/ghost-story": "^0.1.12",
|
|
76
|
-
"@storyteller-platform/
|
|
76
|
+
"@storyteller-platform/mapping": "0.1.3",
|
|
77
|
+
"@storyteller-platform/transliteration": "^4.0.6",
|
|
77
78
|
"chalk": "^5.4.1",
|
|
78
79
|
"change-case": "^5.4.4",
|
|
79
80
|
"cli-progress": "^3.12.0",
|