@storyteller-platform/align 0.1.19 → 0.1.20
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 +105 -44
- package/dist/align/align.d.cts +2 -0
- package/dist/align/align.d.ts +2 -0
- package/dist/align/align.js +108 -45
- package/dist/align/getSentenceRanges.cjs +116 -68
- package/dist/align/getSentenceRanges.d.cts +35 -5
- package/dist/align/getSentenceRanges.d.ts +35 -5
- package/dist/align/getSentenceRanges.js +113 -67
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/markup/markup.cjs +18 -1
- package/dist/markup/markup.d.cts +1 -1
- package/dist/markup/markup.d.ts +1 -1
- package/dist/markup/markup.js +18 -1
- package/dist/markup/serializeDom.cjs +80 -53
- package/dist/markup/serializeDom.d.cts +3 -4
- package/dist/markup/serializeDom.d.ts +3 -4
- package/dist/markup/serializeDom.js +79 -51
- package/package.json +2 -2
|
@@ -1,63 +1,91 @@
|
|
|
1
1
|
import "../chunk-BIEQXUOY.js";
|
|
2
2
|
import { Epub } from "@storyteller-platform/epub";
|
|
3
3
|
import { TextNode } from "./model.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function serializeDomNode(node) {
|
|
8
|
-
if (node instanceof TextNode) {
|
|
9
|
-
return Epub.createXmlTextNode(node.text);
|
|
4
|
+
class Serializer {
|
|
5
|
+
constructor(doc) {
|
|
6
|
+
this.doc = doc;
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const partitioned = nodes.reduce((acc, child) => {
|
|
19
|
-
const lastPartition = acc.at(-1);
|
|
20
|
-
if (!lastPartition) {
|
|
21
|
-
return [[child]];
|
|
22
|
-
}
|
|
23
|
-
const lastChild = lastPartition.at(-1);
|
|
24
|
-
if (!lastChild) {
|
|
25
|
-
return [...acc.slice(0, acc.length), [child]];
|
|
8
|
+
serializedIds = /* @__PURE__ */ new Set();
|
|
9
|
+
serialize() {
|
|
10
|
+
return this.doc.children.map((child) => this.serializeDomNode(child));
|
|
11
|
+
}
|
|
12
|
+
serializeDomNode(node) {
|
|
13
|
+
if (node instanceof TextNode) {
|
|
14
|
+
return Epub.createXmlTextNode(node.text);
|
|
26
15
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
let attrs = node.attrs;
|
|
17
|
+
const id = node.attrs["id"];
|
|
18
|
+
if (id) {
|
|
19
|
+
if (this.serializedIds.has(id)) {
|
|
20
|
+
const { id: _id, ...remaining } = node.attrs;
|
|
21
|
+
attrs = remaining;
|
|
22
|
+
} else {
|
|
23
|
+
this.serializedIds.add(id);
|
|
24
|
+
}
|
|
34
25
|
}
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
return Epub.createXmlElement(
|
|
27
|
+
node.tagName,
|
|
28
|
+
attrs,
|
|
29
|
+
this.serializeDomNodes(node.children)
|
|
30
|
+
);
|
|
40
31
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
serializeDomNodes(nodes) {
|
|
33
|
+
const partitioned = nodes.reduce((acc, child) => {
|
|
34
|
+
const lastPartition = acc.at(-1);
|
|
35
|
+
if (!lastPartition) {
|
|
36
|
+
return [[child]];
|
|
37
|
+
}
|
|
38
|
+
const lastChild = lastPartition.at(-1);
|
|
39
|
+
if (!lastChild) {
|
|
40
|
+
return [...acc.slice(0, acc.length), [child]];
|
|
41
|
+
}
|
|
42
|
+
const childFirstMark = child.marks[0];
|
|
43
|
+
const lastChildFirstMark = lastChild.marks[0];
|
|
44
|
+
if (childFirstMark === lastChildFirstMark || childFirstMark?.eq(lastChildFirstMark)) {
|
|
45
|
+
return [
|
|
46
|
+
...acc.slice(0, acc.length - 1),
|
|
47
|
+
[...lastPartition.slice(0, lastPartition.length), child]
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
return [...acc, [child]];
|
|
51
|
+
}, []);
|
|
52
|
+
const xmlChildren = [];
|
|
53
|
+
for (const partition of partitioned) {
|
|
54
|
+
xmlChildren.push(...this.serializePartition(partition));
|
|
55
|
+
}
|
|
56
|
+
return xmlChildren;
|
|
49
57
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
serializePartition(nodes) {
|
|
59
|
+
const firstChild = nodes[0];
|
|
60
|
+
if (!firstChild) return [];
|
|
61
|
+
const firstMark = firstChild.marks[0];
|
|
62
|
+
if (!firstMark) {
|
|
63
|
+
return nodes.map((child) => this.serializeDomNode(child));
|
|
64
|
+
}
|
|
65
|
+
let attrs = firstMark.attrs;
|
|
66
|
+
const id = firstMark.attrs["id"];
|
|
67
|
+
if (id) {
|
|
68
|
+
if (this.serializedIds.has(id)) {
|
|
69
|
+
const { id: _id, ...remaining } = firstMark.attrs;
|
|
70
|
+
attrs = remaining;
|
|
71
|
+
} else {
|
|
72
|
+
this.serializedIds.add(id);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
Epub.createXmlElement(
|
|
77
|
+
firstMark.tagName,
|
|
78
|
+
attrs,
|
|
79
|
+
this.serializeDomNodes(
|
|
80
|
+
nodes.map((node) => node.copy({ marks: node.marks.slice(1) }))
|
|
81
|
+
)
|
|
56
82
|
)
|
|
57
|
-
|
|
58
|
-
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function serializeDom(doc) {
|
|
87
|
+
return new Serializer(doc).serialize();
|
|
59
88
|
}
|
|
60
89
|
export {
|
|
61
|
-
serializeDom
|
|
62
|
-
serializeDomNode
|
|
90
|
+
serializeDom
|
|
63
91
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyteller-platform/align",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
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",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@storyteller-platform/audiobook": "^0.3.10",
|
|
63
63
|
"@storyteller-platform/epub": "^0.4.8",
|
|
64
64
|
"@storyteller-platform/ghost-story": "^0.1.7",
|
|
65
|
-
"@storyteller-platform/transliteration": "^3.1.
|
|
65
|
+
"@storyteller-platform/transliteration": "^3.1.2",
|
|
66
66
|
"chalk": "^5.4.1",
|
|
67
67
|
"cli-progress": "^3.12.0",
|
|
68
68
|
"esbuild": "^0.27.3",
|