@storyteller-platform/align 0.1.20 → 0.1.21
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 +16 -8
- package/dist/align/align.js +17 -9
- package/package.json +1 -1
package/dist/align/align.cjs
CHANGED
|
@@ -348,16 +348,24 @@ class Aligner {
|
|
|
348
348
|
};
|
|
349
349
|
}
|
|
350
350
|
narrowToAvailableBoundary(boundary) {
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
351
|
+
const available = [
|
|
352
|
+
-1,
|
|
353
|
+
...this.alignedChapters.toSorted((a, b) => a.startOffset - b.startOffset).flatMap(({ startOffset, endOffset }) => [startOffset, endOffset]),
|
|
354
|
+
Infinity
|
|
355
|
+
];
|
|
356
|
+
const withinBoundary = [];
|
|
357
|
+
for (let i = 0; i < available.length - 1; i += 2) {
|
|
358
|
+
const [start, end] = [available[i], available[i + 1]];
|
|
359
|
+
if (boundary.start <= start && boundary.end >= start || boundary.start <= end && boundary.end >= end) {
|
|
360
|
+
withinBoundary.push([
|
|
361
|
+
Math.max(boundary.start, start + 1),
|
|
362
|
+
Math.min(boundary.end, end - 1)
|
|
363
|
+
]);
|
|
358
364
|
}
|
|
359
365
|
}
|
|
360
|
-
|
|
366
|
+
const largestBoundary = (0, import_itertools.max)(withinBoundary, ([start, end]) => end - start);
|
|
367
|
+
if (!largestBoundary) return { start: boundary.start, end: boundary.end };
|
|
368
|
+
return { start: largestBoundary[0], end: largestBoundary[1] };
|
|
361
369
|
}
|
|
362
370
|
async alignBook(onProgress) {
|
|
363
371
|
const locale = this.languageOverride ?? await this.epub.getLanguage() ?? new Intl.Locale("en-US");
|
package/dist/align/align.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
6
6
|
import { dirname as autoDirname, join as autoJoin } from "node:path";
|
|
7
7
|
import { basename, dirname, parse, relative } from "node:path/posix";
|
|
8
|
-
import { enumerate } from "itertools";
|
|
8
|
+
import { enumerate, max } from "itertools";
|
|
9
9
|
import memoize from "memoize";
|
|
10
10
|
import { isAudioFile, lookupAudioMime } from "@storyteller-platform/audiobook";
|
|
11
11
|
import {
|
|
@@ -284,16 +284,24 @@ class Aligner {
|
|
|
284
284
|
};
|
|
285
285
|
}
|
|
286
286
|
narrowToAvailableBoundary(boundary) {
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
287
|
+
const available = [
|
|
288
|
+
-1,
|
|
289
|
+
...this.alignedChapters.toSorted((a, b) => a.startOffset - b.startOffset).flatMap(({ startOffset, endOffset }) => [startOffset, endOffset]),
|
|
290
|
+
Infinity
|
|
291
|
+
];
|
|
292
|
+
const withinBoundary = [];
|
|
293
|
+
for (let i = 0; i < available.length - 1; i += 2) {
|
|
294
|
+
const [start, end] = [available[i], available[i + 1]];
|
|
295
|
+
if (boundary.start <= start && boundary.end >= start || boundary.start <= end && boundary.end >= end) {
|
|
296
|
+
withinBoundary.push([
|
|
297
|
+
Math.max(boundary.start, start + 1),
|
|
298
|
+
Math.min(boundary.end, end - 1)
|
|
299
|
+
]);
|
|
294
300
|
}
|
|
295
301
|
}
|
|
296
|
-
|
|
302
|
+
const largestBoundary = max(withinBoundary, ([start, end]) => end - start);
|
|
303
|
+
if (!largestBoundary) return { start: boundary.start, end: boundary.end };
|
|
304
|
+
return { start: largestBoundary[0], end: largestBoundary[1] };
|
|
297
305
|
}
|
|
298
306
|
async alignBook(onProgress) {
|
|
299
307
|
const locale = this.languageOverride ?? await this.epub.getLanguage() ?? new Intl.Locale("en-US");
|
package/package.json
CHANGED