@storyteller-platform/align 0.1.57 → 0.1.58

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.
Files changed (118) hide show
  1. package/dist/align/align.cjs +38 -19
  2. package/dist/align/align.d.cts +12 -1
  3. package/dist/align/align.d.ts +12 -1
  4. package/dist/align/align.js +38 -19
  5. package/dist/align/ctc/Aligner.cjs +800 -0
  6. package/dist/align/ctc/Aligner.d.cts +56 -0
  7. package/dist/align/ctc/Aligner.d.ts +56 -0
  8. package/dist/align/ctc/Aligner.js +789 -0
  9. package/dist/align/ctc/align.cjs +189 -0
  10. package/dist/align/ctc/align.d.cts +14 -0
  11. package/dist/align/ctc/align.d.ts +14 -0
  12. package/dist/align/ctc/align.js +132 -0
  13. package/dist/{process/mime.cjs → align/ctc/emissions.cjs} +7 -20
  14. package/dist/align/ctc/emissions.d.cts +6 -0
  15. package/dist/align/ctc/emissions.d.ts +6 -0
  16. package/dist/align/ctc/emissions.js +7 -0
  17. package/dist/align/ctc/forcedAlign.cjs +273 -0
  18. package/dist/align/ctc/forcedAlign.d.cts +21 -0
  19. package/dist/align/ctc/forcedAlign.d.ts +21 -0
  20. package/dist/align/ctc/forcedAlign.js +248 -0
  21. package/dist/align/ctc/greedyDecode.cjs +61 -0
  22. package/dist/align/ctc/greedyDecode.d.cts +15 -0
  23. package/dist/align/ctc/greedyDecode.d.ts +15 -0
  24. package/dist/align/ctc/greedyDecode.js +37 -0
  25. package/dist/align/ctc/mediaOverlay.cjs +248 -0
  26. package/dist/align/ctc/mediaOverlay.d.cts +16 -0
  27. package/dist/align/ctc/mediaOverlay.d.ts +16 -0
  28. package/dist/align/ctc/mediaOverlay.js +224 -0
  29. package/dist/align/ctc/report.cjs +66 -0
  30. package/dist/align/ctc/report.d.cts +79 -0
  31. package/dist/align/ctc/report.d.ts +79 -0
  32. package/dist/align/ctc/report.js +42 -0
  33. package/dist/align/ctc/search.cjs +437 -0
  34. package/dist/align/ctc/search.d.cts +46 -0
  35. package/dist/align/ctc/search.d.ts +46 -0
  36. package/dist/align/ctc/search.js +412 -0
  37. package/dist/align/getSentenceRanges.cjs +9 -3
  38. package/dist/align/getSentenceRanges.d.cts +1 -0
  39. package/dist/align/getSentenceRanges.d.ts +1 -0
  40. package/dist/align/getSentenceRanges.js +9 -3
  41. package/dist/align/parse.cjs +17 -4
  42. package/dist/align/parse.d.cts +8 -4
  43. package/dist/align/parse.d.ts +8 -4
  44. package/dist/align/parse.js +19 -4
  45. package/dist/align/search.cjs +76 -23
  46. package/dist/align/search.d.cts +8 -4
  47. package/dist/align/search.d.ts +8 -4
  48. package/dist/align/search.js +76 -24
  49. package/dist/align/slugify.cjs +3 -2
  50. package/dist/align/slugify.d.cts +1 -1
  51. package/dist/align/slugify.d.ts +1 -1
  52. package/dist/align/slugify.js +3 -2
  53. package/dist/cli/bin.cjs +204 -114
  54. package/dist/cli/bin.js +194 -103
  55. package/dist/common/ffmpeg.cjs +10 -5
  56. package/dist/common/ffmpeg.js +10 -5
  57. package/dist/common/logging.cjs +33 -1
  58. package/dist/common/logging.js +33 -1
  59. package/dist/emit/emit.cjs +105 -0
  60. package/dist/emit/emit.d.cts +15 -0
  61. package/dist/emit/emit.d.ts +15 -0
  62. package/dist/emit/emit.js +86 -0
  63. package/dist/emit/fs.cjs +227 -0
  64. package/dist/emit/fs.d.cts +22 -0
  65. package/dist/emit/fs.d.ts +22 -0
  66. package/dist/emit/fs.js +162 -0
  67. package/dist/emit/parse.cjs +68 -0
  68. package/dist/emit/parse.d.cts +26 -0
  69. package/dist/emit/parse.d.ts +26 -0
  70. package/dist/emit/parse.js +58 -0
  71. package/dist/index.d.cts +1 -1
  72. package/dist/index.d.ts +1 -1
  73. package/dist/markup/model.cjs +0 -16
  74. package/dist/markup/model.d.cts +1 -1
  75. package/dist/markup/model.d.ts +1 -1
  76. package/dist/markup/model.js +0 -12
  77. package/dist/markup/parseDom.cjs +13 -14
  78. package/dist/markup/parseDom.d.cts +2 -2
  79. package/dist/markup/parseDom.d.ts +2 -2
  80. package/dist/markup/parseDom.js +13 -18
  81. package/dist/markup/resolvedPos.d.cts +1 -1
  82. package/dist/markup/resolvedPos.d.ts +1 -1
  83. package/dist/markup/segmentation.cjs +3 -1
  84. package/dist/markup/segmentation.js +3 -1
  85. package/dist/markup/serializeDom.cjs +1 -1
  86. package/dist/markup/serializeDom.d.cts +1 -1
  87. package/dist/markup/serializeDom.d.ts +1 -1
  88. package/dist/markup/serializeDom.js +1 -1
  89. package/dist/markup/transform.cjs +5 -2
  90. package/dist/markup/transform.d.cts +1 -1
  91. package/dist/markup/transform.d.ts +1 -1
  92. package/dist/markup/transform.js +5 -4
  93. package/dist/{model-CZ2mMHJO.d.cts → model-CeOMDDgt.d.cts} +3 -11
  94. package/dist/{model-CZ2mMHJO.d.ts → model-CeOMDDgt.d.ts} +3 -11
  95. package/dist/process/processAudiobook.cjs +12 -23
  96. package/dist/process/processAudiobook.js +14 -30
  97. package/dist/process/ranges.cjs +2 -2
  98. package/dist/process/ranges.js +2 -2
  99. package/dist/readium/guidedNavigation.cjs +8 -8
  100. package/dist/readium/guidedNavigation.js +8 -8
  101. package/dist/readium/manifest.cjs +5 -4
  102. package/dist/readium/manifest.js +5 -4
  103. package/dist/snapshot/ctc/snapshot.cjs +261 -0
  104. package/dist/snapshot/ctc/snapshot.d.cts +6 -0
  105. package/dist/snapshot/ctc/snapshot.d.ts +6 -0
  106. package/dist/snapshot/ctc/snapshot.js +200 -0
  107. package/dist/snapshot/parse.cjs +29 -16
  108. package/dist/snapshot/parse.d.cts +14 -10
  109. package/dist/snapshot/parse.d.ts +14 -10
  110. package/dist/snapshot/parse.js +32 -17
  111. package/dist/transcribe/parse.d.cts +6 -6
  112. package/dist/transcribe/parse.d.ts +6 -6
  113. package/dist/transcribe/transcribe.cjs +4 -2
  114. package/dist/transcribe/transcribe.js +4 -2
  115. package/package.json +6 -4
  116. package/dist/process/mime.d.cts +0 -3
  117. package/dist/process/mime.d.ts +0 -3
  118. package/dist/process/mime.js +0 -24
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var parse_exports = {};
20
+ __export(parse_exports, {
21
+ emitCommand: () => emitCommand,
22
+ emitParser: () => emitParser
23
+ });
24
+ module.exports = __toCommonJS(parse_exports);
25
+ var import_core = require("@optique/core");
26
+ var import_valueparser = require("@optique/run/valueparser");
27
+ var import_constants = require("@storyteller-platform/ghost-story/constants");
28
+ var import_parse = require("../common/parse.cjs");
29
+ const emitParser = (0, import_core.object)({
30
+ model: (0, import_core.withDefault)(
31
+ (0, import_core.option)("--model", "-m", (0, import_core.choice)(import_constants.WAV2VEC2_MODELS, { metavar: "MODEL" }), {
32
+ description: import_core.message`The wav2vec2 model to use`
33
+ }),
34
+ "onnx-community/mms-300m-1130-forced-aligner-ONNX"
35
+ ),
36
+ device: (0, import_core.withDefault)(
37
+ (0, import_core.option)("--device", "-d", (0, import_core.choice)(import_constants.WAV2VEC2_DEVICES, { metavar: "DEVICE" }), {
38
+ description: import_core.message`The device to run inference on`
39
+ }),
40
+ "auto"
41
+ ),
42
+ dtype: (0, import_core.withDefault)(
43
+ (0, import_core.option)("--dtype", (0, import_core.choice)(import_constants.WAV2VEC2_DTYPES, { metavar: "DTYPE" }), {
44
+ description: import_core.message`The data type to load the model with`
45
+ }),
46
+ "fp16"
47
+ )
48
+ });
49
+ const emitCommand = (0, import_core.command)(
50
+ "emit",
51
+ (0, import_core.merge)(
52
+ (0, import_core.object)({
53
+ action: (0, import_core.constant)("emit"),
54
+ input: (0, import_core.argument)(
55
+ (0, import_valueparser.path)({ type: "directory", mustExist: true, metavar: "INPUT" })
56
+ ),
57
+ output: (0, import_core.argument)((0, import_valueparser.path)({ metavar: "OUTPUT", type: "directory" }))
58
+ }),
59
+ emitParser,
60
+ import_parse.loggingParser
61
+ ),
62
+ { description: import_core.message`Transcribe a directory of audiobook files.` }
63
+ );
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ emitCommand,
67
+ emitParser
68
+ });
@@ -0,0 +1,26 @@
1
+ import * as _optique_core from '@optique/core';
2
+
3
+ declare const emitParser: _optique_core.Parser<"sync", {
4
+ readonly model: "Xenova/wav2vec2-base-960h" | "onnx-community/mms-300m-1130-forced-aligner-ONNX";
5
+ readonly device: "auto" | "cpu" | "webgpu" | "cuda";
6
+ readonly dtype: "fp32" | "fp16" | "q8";
7
+ }, {
8
+ readonly model: [_optique_core.ValueParserResult<"Xenova/wav2vec2-base-960h" | "onnx-community/mms-300m-1130-forced-aligner-ONNX"> | undefined] | undefined;
9
+ readonly device: [_optique_core.ValueParserResult<"auto" | "cpu" | "webgpu" | "cuda"> | undefined] | undefined;
10
+ readonly dtype: [_optique_core.ValueParserResult<"fp32" | "fp16" | "q8"> | undefined] | undefined;
11
+ }>;
12
+ declare const emitCommand: _optique_core.Parser<"sync", {
13
+ readonly action: "emit";
14
+ readonly input: string;
15
+ readonly output: string;
16
+ } & {
17
+ readonly model: "Xenova/wav2vec2-base-960h" | "onnx-community/mms-300m-1130-forced-aligner-ONNX";
18
+ readonly device: "auto" | "cpu" | "webgpu" | "cuda";
19
+ readonly dtype: "fp32" | "fp16" | "q8";
20
+ } & {
21
+ readonly noProgress: boolean;
22
+ readonly logLevel: "silent" | "debug" | "info" | "warn" | "error";
23
+ readonly time: boolean;
24
+ }, ["matched", string] | ["parsing", Record<string | symbol, unknown>] | undefined>;
25
+
26
+ export { emitCommand, emitParser };
@@ -0,0 +1,26 @@
1
+ import * as _optique_core from '@optique/core';
2
+
3
+ declare const emitParser: _optique_core.Parser<"sync", {
4
+ readonly model: "Xenova/wav2vec2-base-960h" | "onnx-community/mms-300m-1130-forced-aligner-ONNX";
5
+ readonly device: "auto" | "cpu" | "webgpu" | "cuda";
6
+ readonly dtype: "fp32" | "fp16" | "q8";
7
+ }, {
8
+ readonly model: [_optique_core.ValueParserResult<"Xenova/wav2vec2-base-960h" | "onnx-community/mms-300m-1130-forced-aligner-ONNX"> | undefined] | undefined;
9
+ readonly device: [_optique_core.ValueParserResult<"auto" | "cpu" | "webgpu" | "cuda"> | undefined] | undefined;
10
+ readonly dtype: [_optique_core.ValueParserResult<"fp32" | "fp16" | "q8"> | undefined] | undefined;
11
+ }>;
12
+ declare const emitCommand: _optique_core.Parser<"sync", {
13
+ readonly action: "emit";
14
+ readonly input: string;
15
+ readonly output: string;
16
+ } & {
17
+ readonly model: "Xenova/wav2vec2-base-960h" | "onnx-community/mms-300m-1130-forced-aligner-ONNX";
18
+ readonly device: "auto" | "cpu" | "webgpu" | "cuda";
19
+ readonly dtype: "fp32" | "fp16" | "q8";
20
+ } & {
21
+ readonly noProgress: boolean;
22
+ readonly logLevel: "silent" | "debug" | "info" | "warn" | "error";
23
+ readonly time: boolean;
24
+ }, ["matched", string] | ["parsing", Record<string | symbol, unknown>] | undefined>;
25
+
26
+ export { emitCommand, emitParser };
@@ -0,0 +1,58 @@
1
+ import "../chunk-BIEQXUOY.js";
2
+ import {
3
+ argument,
4
+ choice,
5
+ command,
6
+ constant,
7
+ merge,
8
+ message,
9
+ object,
10
+ option,
11
+ withDefault
12
+ } from "@optique/core";
13
+ import { path } from "@optique/run/valueparser";
14
+ import {
15
+ WAV2VEC2_DEVICES,
16
+ WAV2VEC2_DTYPES,
17
+ WAV2VEC2_MODELS
18
+ } from "@storyteller-platform/ghost-story/constants";
19
+ import { loggingParser } from "../common/parse.js";
20
+ const emitParser = object({
21
+ model: withDefault(
22
+ option("--model", "-m", choice(WAV2VEC2_MODELS, { metavar: "MODEL" }), {
23
+ description: message`The wav2vec2 model to use`
24
+ }),
25
+ "onnx-community/mms-300m-1130-forced-aligner-ONNX"
26
+ ),
27
+ device: withDefault(
28
+ option("--device", "-d", choice(WAV2VEC2_DEVICES, { metavar: "DEVICE" }), {
29
+ description: message`The device to run inference on`
30
+ }),
31
+ "auto"
32
+ ),
33
+ dtype: withDefault(
34
+ option("--dtype", choice(WAV2VEC2_DTYPES, { metavar: "DTYPE" }), {
35
+ description: message`The data type to load the model with`
36
+ }),
37
+ "fp16"
38
+ )
39
+ });
40
+ const emitCommand = command(
41
+ "emit",
42
+ merge(
43
+ object({
44
+ action: constant("emit"),
45
+ input: argument(
46
+ path({ type: "directory", mustExist: true, metavar: "INPUT" })
47
+ ),
48
+ output: argument(path({ metavar: "OUTPUT", type: "directory" }))
49
+ }),
50
+ emitParser,
51
+ loggingParser
52
+ ),
53
+ { description: message`Transcribe a directory of audiobook files.` }
54
+ );
55
+ export {
56
+ emitCommand,
57
+ emitParser
58
+ };
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { processAudiobook } from './process/processAudiobook.cjs';
2
2
  export { transcribe } from './transcribe/transcribe.cjs';
3
3
  export { markup } from './markup/markup.cjs';
4
- export { align } from './align/align.cjs';
4
+ export { AlignOptions, AudioFileReport, ChapterReport, Report, UnalignedAudioFileReport, UnalignedChapterReport, UnalignedNotFoundChapterReport, align } from './align/align.cjs';
5
5
  export { upgradeEpub } from './upgradeEpub/upgradeEpub.cjs';
6
6
  import '@storyteller-platform/ghost-story';
7
7
  import '@esfx/async-semaphore';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { processAudiobook } from './process/processAudiobook.js';
2
2
  export { transcribe } from './transcribe/transcribe.js';
3
3
  export { markup } from './markup/markup.js';
4
- export { align } from './align/align.js';
4
+ export { AlignOptions, AudioFileReport, ChapterReport, Report, UnalignedAudioFileReport, UnalignedChapterReport, UnalignedNotFoundChapterReport, align } from './align/align.js';
5
5
  export { upgradeEpub } from './upgradeEpub/upgradeEpub.js';
6
6
  import '@storyteller-platform/ghost-story';
7
7
  import '@esfx/async-semaphore';
@@ -21,11 +21,7 @@ __export(model_exports, {
21
21
  FootnoteNode: () => FootnoteNode,
22
22
  Mark: () => Mark,
23
23
  Node: () => Node,
24
- NoterefNode: () => NoterefNode,
25
24
  Root: () => Root,
26
- RubyNode: () => RubyNode,
27
- RubyParenthesisNode: () => RubyParenthesisNode,
28
- RubyTextNode: () => RubyTextNode,
29
25
  TextNode: () => TextNode,
30
26
  descendants: () => descendants
31
27
  });
@@ -234,16 +230,8 @@ class Node {
234
230
  }
235
231
  }
236
232
  }
237
- class NoterefNode extends Node {
238
- }
239
233
  class FootnoteNode extends Node {
240
234
  }
241
- class RubyParenthesisNode extends Node {
242
- }
243
- class RubyTextNode extends Node {
244
- }
245
- class RubyNode extends Node {
246
- }
247
235
  class Mark {
248
236
  constructor(tagName, attrs = {}) {
249
237
  this.tagName = tagName;
@@ -307,11 +295,7 @@ function descendants(node, cb, pos = 0) {
307
295
  FootnoteNode,
308
296
  Mark,
309
297
  Node,
310
- NoterefNode,
311
298
  Root,
312
- RubyNode,
313
- RubyParenthesisNode,
314
- RubyTextNode,
315
299
  TextNode,
316
300
  descendants
317
301
  });
@@ -1,2 +1,2 @@
1
1
  import '@storyteller-platform/epub';
2
- export { F as FootnoteNode, M as Mark, N as Node, b as NoterefNode, R as Root, e as RubyNode, c as RubyParenthesisNode, d as RubyTextNode, T as TextNode, f as descendants } from '../model-CZ2mMHJO.cjs';
2
+ export { F as FootnoteNode, M as Mark, N as Node, R as Root, T as TextNode, d as descendants } from '../model-CeOMDDgt.cjs';
@@ -1,2 +1,2 @@
1
1
  import '@storyteller-platform/epub';
2
- export { F as FootnoteNode, M as Mark, N as Node, b as NoterefNode, R as Root, e as RubyNode, c as RubyParenthesisNode, d as RubyTextNode, T as TextNode, f as descendants } from '../model-CZ2mMHJO.js';
2
+ export { F as FootnoteNode, M as Mark, N as Node, R as Root, T as TextNode, d as descendants } from '../model-CeOMDDgt.js';
@@ -203,16 +203,8 @@ class Node {
203
203
  }
204
204
  }
205
205
  }
206
- class NoterefNode extends Node {
207
- }
208
206
  class FootnoteNode extends Node {
209
207
  }
210
- class RubyParenthesisNode extends Node {
211
- }
212
- class RubyTextNode extends Node {
213
- }
214
- class RubyNode extends Node {
215
- }
216
208
  class Mark {
217
209
  constructor(tagName, attrs = {}) {
218
210
  this.tagName = tagName;
@@ -275,11 +267,7 @@ export {
275
267
  FootnoteNode,
276
268
  Mark,
277
269
  Node,
278
- NoterefNode,
279
270
  Root,
280
- RubyNode,
281
- RubyParenthesisNode,
282
- RubyTextNode,
283
271
  TextNode,
284
272
  descendants
285
273
  };
@@ -57,13 +57,11 @@ class Parser {
57
57
  pos + 1
58
58
  );
59
59
  if (tagName === "a" && attrs["epub:type"] === "noteref") {
60
- const node = new import_model.NoterefNode(tagName, attrs, blockChildren, marks);
61
- const href = node.attrs["href"];
60
+ const href = attrs["href"];
62
61
  const fragment = href?.split("#")[1];
63
62
  if (fragment) {
64
63
  this.footnoteIds.add(fragment);
65
64
  }
66
- return node;
67
65
  }
68
66
  if (attrs["id"] && (FOOTNOTE_ROLES.includes(attrs["epub:type"] ?? "") || // Some footnotes aren't properly marked up with the
69
67
  // correct role
@@ -81,15 +79,6 @@ class Parser {
81
79
  );
82
80
  return footnoteNode;
83
81
  }
84
- if (tagName === "ruby") {
85
- return new import_model.RubyNode(tagName, attrs, blockChildren, marks);
86
- }
87
- if (tagName === "rt") {
88
- return new import_model.RubyTextNode(tagName, attrs, blockChildren, marks);
89
- }
90
- if (tagName === "rp") {
91
- return new import_model.RubyParenthesisNode(tagName, attrs, blockChildren, marks);
92
- }
93
82
  if (import_semantics.BLOCKS.includes(tagName)) {
94
83
  return new import_model.Node(tagName, attrs, blockChildren, marks);
95
84
  }
@@ -108,9 +97,19 @@ function findFootnotePairs(root) {
108
97
  const noterefs = /* @__PURE__ */ new Map();
109
98
  const pairs = /* @__PURE__ */ new Map();
110
99
  (0, import_model.descendants)(root, (node, pos) => {
111
- if (node instanceof import_model.NoterefNode) {
112
- const id = node.attrs["href"]?.split("#")[1];
100
+ const mark = node.marks.find((mark2) => mark2.tagName === "a");
101
+ if (mark) {
102
+ const id = mark.attrs["href"]?.split("#")[1];
113
103
  if (id) {
104
+ const $pos = root.resolve(pos);
105
+ let d = $pos.depth;
106
+ while (d > 0) {
107
+ const node2 = $pos.node(d);
108
+ if (node2 instanceof import_model.FootnoteNode) {
109
+ return false;
110
+ }
111
+ d--;
112
+ }
114
113
  noterefs.set(id, pos);
115
114
  }
116
115
  return false;
@@ -1,7 +1,7 @@
1
1
  import { ParsedXml } from '@storyteller-platform/epub';
2
- import { R as Root, N as Node } from '../model-CZ2mMHJO.cjs';
2
+ import { R as Root } from '../model-CeOMDDgt.cjs';
3
3
 
4
4
  declare function parseDom(xml: ParsedXml): Root;
5
- declare function findFootnotePairs(root: Root | Node): Map<number, number>;
5
+ declare function findFootnotePairs(root: Root): Map<number, number>;
6
6
 
7
7
  export { findFootnotePairs, parseDom };
@@ -1,7 +1,7 @@
1
1
  import { ParsedXml } from '@storyteller-platform/epub';
2
- import { R as Root, N as Node } from '../model-CZ2mMHJO.js';
2
+ import { R as Root } from '../model-CeOMDDgt.js';
3
3
 
4
4
  declare function parseDom(xml: ParsedXml): Root;
5
- declare function findFootnotePairs(root: Root | Node): Map<number, number>;
5
+ declare function findFootnotePairs(root: Root): Map<number, number>;
6
6
 
7
7
  export { findFootnotePairs, parseDom };
@@ -4,11 +4,7 @@ import {
4
4
  FootnoteNode,
5
5
  Mark,
6
6
  Node,
7
- NoterefNode,
8
7
  Root,
9
- RubyNode,
10
- RubyParenthesisNode,
11
- RubyTextNode,
12
8
  TextNode,
13
9
  descendants
14
10
  } from "./model.js";
@@ -45,13 +41,11 @@ class Parser {
45
41
  pos + 1
46
42
  );
47
43
  if (tagName === "a" && attrs["epub:type"] === "noteref") {
48
- const node = new NoterefNode(tagName, attrs, blockChildren, marks);
49
- const href = node.attrs["href"];
44
+ const href = attrs["href"];
50
45
  const fragment = href?.split("#")[1];
51
46
  if (fragment) {
52
47
  this.footnoteIds.add(fragment);
53
48
  }
54
- return node;
55
49
  }
56
50
  if (attrs["id"] && (FOOTNOTE_ROLES.includes(attrs["epub:type"] ?? "") || // Some footnotes aren't properly marked up with the
57
51
  // correct role
@@ -69,15 +63,6 @@ class Parser {
69
63
  );
70
64
  return footnoteNode;
71
65
  }
72
- if (tagName === "ruby") {
73
- return new RubyNode(tagName, attrs, blockChildren, marks);
74
- }
75
- if (tagName === "rt") {
76
- return new RubyTextNode(tagName, attrs, blockChildren, marks);
77
- }
78
- if (tagName === "rp") {
79
- return new RubyParenthesisNode(tagName, attrs, blockChildren, marks);
80
- }
81
66
  if (BLOCKS.includes(tagName)) {
82
67
  return new Node(tagName, attrs, blockChildren, marks);
83
68
  }
@@ -96,9 +81,19 @@ function findFootnotePairs(root) {
96
81
  const noterefs = /* @__PURE__ */ new Map();
97
82
  const pairs = /* @__PURE__ */ new Map();
98
83
  descendants(root, (node, pos) => {
99
- if (node instanceof NoterefNode) {
100
- const id = node.attrs["href"]?.split("#")[1];
84
+ const mark = node.marks.find((mark2) => mark2.tagName === "a");
85
+ if (mark) {
86
+ const id = mark.attrs["href"]?.split("#")[1];
101
87
  if (id) {
88
+ const $pos = root.resolve(pos);
89
+ let d = $pos.depth;
90
+ while (d > 0) {
91
+ const node2 = $pos.node(d);
92
+ if (node2 instanceof FootnoteNode) {
93
+ return false;
94
+ }
95
+ d--;
96
+ }
102
97
  noterefs.set(id, pos);
103
98
  }
104
99
  return false;
@@ -1,2 +1,2 @@
1
- export { a as ResolvedPos } from '../model-CZ2mMHJO.cjs';
1
+ export { a as ResolvedPos } from '../model-CeOMDDgt.cjs';
2
2
  import '@storyteller-platform/epub';
@@ -1,2 +1,2 @@
1
- export { a as ResolvedPos } from '../model-CZ2mMHJO.js';
1
+ export { a as ResolvedPos } from '../model-CeOMDDgt.js';
2
2
  import '@storyteller-platform/epub';
@@ -27,7 +27,9 @@ async function segmentChapter(text, options) {
27
27
  ...options.primaryLocale && {
28
28
  language: options.primaryLocale.language
29
29
  },
30
- enableEastAsianPostprocessing: true
30
+ // TODO: re-enable this, only disabled until we figure out
31
+ // why it's not working in the SEA!
32
+ enableEastAsianPostprocessing: false
31
33
  });
32
34
  return result.sentences;
33
35
  }
@@ -7,7 +7,9 @@ async function segmentChapter(text, options) {
7
7
  ...options.primaryLocale && {
8
8
  language: options.primaryLocale.language
9
9
  },
10
- enableEastAsianPostprocessing: true
10
+ // TODO: re-enable this, only disabled until we figure out
11
+ // why it's not working in the SEA!
12
+ enableEastAsianPostprocessing: false
11
13
  });
12
14
  return result.sentences;
13
15
  }
@@ -29,7 +29,7 @@ class Serializer {
29
29
  }
30
30
  serializedIds = /* @__PURE__ */ new Set();
31
31
  serialize() {
32
- return this.doc.children.map((child) => this.serializeDomNode(child));
32
+ return this.serializeDomNodes(this.doc.children);
33
33
  }
34
34
  serializeDomNode(node) {
35
35
  if (node instanceof import_model.TextNode) {
@@ -1,5 +1,5 @@
1
1
  import { ParsedXml } from '@storyteller-platform/epub';
2
- import { R as Root } from '../model-CZ2mMHJO.cjs';
2
+ import { R as Root } from '../model-CeOMDDgt.cjs';
3
3
 
4
4
  declare function serializeDom(doc: Root): ParsedXml;
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { ParsedXml } from '@storyteller-platform/epub';
2
- import { R as Root } from '../model-CZ2mMHJO.js';
2
+ import { R as Root } from '../model-CeOMDDgt.js';
3
3
 
4
4
  declare function serializeDom(doc: Root): ParsedXml;
5
5
 
@@ -7,7 +7,7 @@ class Serializer {
7
7
  }
8
8
  serializedIds = /* @__PURE__ */ new Set();
9
9
  serialize() {
10
- return this.doc.children.map((child) => this.serializeDomNode(child));
10
+ return this.serializeDomNodes(this.doc.children);
11
11
  }
12
12
  serializeDomNode(node) {
13
13
  if (node instanceof TextNode) {
@@ -69,7 +69,10 @@ function liftText(root) {
69
69
  if (node.isLeaf && parent.isBlock && index === parent.children.length - 1 && !text.endsWith("\n")) {
70
70
  text += "\n";
71
71
  }
72
- return !(node instanceof import_model.RubyTextNode || node instanceof import_model.RubyParenthesisNode);
72
+ return true;
73
+ }
74
+ if (node.marks.some((m) => m.tagName === "rp" || m.tagName === "rt")) {
75
+ return false;
73
76
  }
74
77
  if (pos - lastTextEnd) {
75
78
  mapping.insertMap(lastTextEnd, pos - lastTextEnd, 0);
@@ -124,7 +127,7 @@ function replaceFootnotes(original, root, footnotePairs, mapping) {
124
127
  for (const [noterefPos, footnotePos] of footnotePairs.entries()) {
125
128
  const noteref = original.resolve(noterefPos).nodeAfter;
126
129
  const footnote = transformed.resolve(cursor.map(noterefPos)).nodeAfter;
127
- if (!(noteref instanceof import_model.Node) || !(footnote instanceof import_model.Node)) continue;
130
+ if (!(noteref instanceof import_model.TextNode) || !(footnote instanceof import_model.Node)) continue;
128
131
  transformed = transformed.replace(cursor.map(noterefPos), noteref);
129
132
  mapping.insertMap(noterefPos, footnote.nodeSize, noteref.nodeSize);
130
133
  cursor = mapping.cursor();
@@ -1,5 +1,5 @@
1
1
  import { Mapping } from '@storyteller-platform/mapping';
2
- import { R as Root, M as Mark } from '../model-CZ2mMHJO.cjs';
2
+ import { R as Root, M as Mark } from '../model-CeOMDDgt.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
1
  import { Mapping } from '@storyteller-platform/mapping';
2
- import { R as Root, M as Mark } from '../model-CZ2mMHJO.js';
2
+ import { R as Root, M as Mark } from '../model-CeOMDDgt.js';
3
3
  import '@storyteller-platform/epub';
4
4
 
5
5
  declare function addMark(root: Root, from: number, to: number, mark: Mark): Root;
@@ -3,8 +3,6 @@ import { Mapping } from "@storyteller-platform/mapping";
3
3
  import {
4
4
  FootnoteNode,
5
5
  Node,
6
- RubyParenthesisNode,
7
- RubyTextNode,
8
6
  TextNode,
9
7
  descendants
10
8
  } from "./model.js";
@@ -51,7 +49,10 @@ function liftText(root) {
51
49
  if (node.isLeaf && parent.isBlock && index === parent.children.length - 1 && !text.endsWith("\n")) {
52
50
  text += "\n";
53
51
  }
54
- return !(node instanceof RubyTextNode || node instanceof RubyParenthesisNode);
52
+ return true;
53
+ }
54
+ if (node.marks.some((m) => m.tagName === "rp" || m.tagName === "rt")) {
55
+ return false;
55
56
  }
56
57
  if (pos - lastTextEnd) {
57
58
  mapping.insertMap(lastTextEnd, pos - lastTextEnd, 0);
@@ -106,7 +107,7 @@ function replaceFootnotes(original, root, footnotePairs, mapping) {
106
107
  for (const [noterefPos, footnotePos] of footnotePairs.entries()) {
107
108
  const noteref = original.resolve(noterefPos).nodeAfter;
108
109
  const footnote = transformed.resolve(cursor.map(noterefPos)).nodeAfter;
109
- if (!(noteref instanceof Node) || !(footnote instanceof Node)) continue;
110
+ if (!(noteref instanceof TextNode) || !(footnote instanceof Node)) continue;
110
111
  transformed = transformed.replace(cursor.map(noterefPos), noteref);
111
112
  mapping.insertMap(noterefPos, footnote.nodeSize, noteref.nodeSize);
112
113
  cursor = mapping.cursor();
@@ -32,7 +32,7 @@ declare class Root {
32
32
  index: number;
33
33
  offset: number;
34
34
  };
35
- replace(at: number, withNode: Node): Root;
35
+ replace(at: number, withNode: Node | TextNode): Root;
36
36
  cut(pos: number): Node | TextNode | null;
37
37
  resolve(pos: number): ResolvedPos;
38
38
  }
@@ -57,23 +57,15 @@ declare class Node {
57
57
  children?: (Node | TextNode)[];
58
58
  marks?: Mark[];
59
59
  }): Node;
60
- replace(at: number, withNode: Node): Node;
60
+ replace(at: number, withNode: Node | TextNode): Node;
61
61
  cut(pos: number): Node | TextNode | null;
62
62
  findIndex(pos: number): {
63
63
  index: number;
64
64
  offset: number;
65
65
  };
66
66
  }
67
- declare class NoterefNode extends Node {
68
- }
69
67
  declare class FootnoteNode extends Node {
70
68
  }
71
- declare class RubyParenthesisNode extends Node {
72
- }
73
- declare class RubyTextNode extends Node {
74
- }
75
- declare class RubyNode extends Node {
76
- }
77
69
  declare class Mark {
78
70
  tagName: ElementName;
79
71
  attrs: Record<string, string>;
@@ -99,4 +91,4 @@ declare class TextNode {
99
91
  }
100
92
  declare function descendants(node: Root | Node, cb: (node: Node | TextNode, pos: number, parent: Node | Root, index: number) => boolean, pos?: number): void;
101
93
 
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 };
94
+ export { FootnoteNode as F, Mark as M, Node as N, Root as R, TextNode as T, ResolvedPos as a, descendants as d };
@@ -32,7 +32,7 @@ declare class Root {
32
32
  index: number;
33
33
  offset: number;
34
34
  };
35
- replace(at: number, withNode: Node): Root;
35
+ replace(at: number, withNode: Node | TextNode): Root;
36
36
  cut(pos: number): Node | TextNode | null;
37
37
  resolve(pos: number): ResolvedPos;
38
38
  }
@@ -57,23 +57,15 @@ declare class Node {
57
57
  children?: (Node | TextNode)[];
58
58
  marks?: Mark[];
59
59
  }): Node;
60
- replace(at: number, withNode: Node): Node;
60
+ replace(at: number, withNode: Node | TextNode): Node;
61
61
  cut(pos: number): Node | TextNode | null;
62
62
  findIndex(pos: number): {
63
63
  index: number;
64
64
  offset: number;
65
65
  };
66
66
  }
67
- declare class NoterefNode extends Node {
68
- }
69
67
  declare class FootnoteNode extends Node {
70
68
  }
71
- declare class RubyParenthesisNode extends Node {
72
- }
73
- declare class RubyTextNode extends Node {
74
- }
75
- declare class RubyNode extends Node {
76
- }
77
69
  declare class Mark {
78
70
  tagName: ElementName;
79
71
  attrs: Record<string, string>;
@@ -99,4 +91,4 @@ declare class TextNode {
99
91
  }
100
92
  declare function descendants(node: Root | Node, cb: (node: Node | TextNode, pos: number, parent: Node | Root, index: number) => boolean, pos?: number): void;
101
93
 
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 };
94
+ export { FootnoteNode as F, Mark as M, Node as N, Root as R, TextNode as T, ResolvedPos as a, descendants as d };